Implement BiRefNet and HAT Sharper models with background removal capabilities

- Added validation documentation for AI model tiers.
- Introduced `background.py` for background removal logic, including inference functions for alpha and foreground extraction.
- Created `onnx_birefnet.py` to handle BiRefNet model sessions and alpha inference.
- Developed tests for background models, ensuring proper dispatch and session reuse.
- Added tests for BiRefNet ONNX model to validate alpha output and error handling for invalid values.
- Implemented model export scripts for BiRefNet and HAT Sharper, ensuring proper weight compression and licensing.
- Created `deform_sampling.py` for deformable convolution operations used in BiRefNet.
- Added utility functions for compressing ONNX weights without altering graph arithmetic.
- Introduced a reference plane node for depth field adjustments in geometry processing.
This commit is contained in:
2026-09-10 20:50:44 +08:00
parent 8ae3c1d5b7
commit e8129fe495
70 changed files with 1890 additions and 1208 deletions

View File

@@ -22,7 +22,7 @@ class AiImageOperatorsTest(BlenderTestCase):
operator = operator_type()
operator.input_path = "input.png"
operator._image_target = SimpleNamespace(start_frame=4)
operator.model = "SAFMN_REAL_X4"
operator.model = "HAT_GAN_X4_SHARPER"
operator.max_input_size = 1024
context = SimpleNamespace(
scene=SimpleNamespace(anyimage_settings=SimpleNamespace(video_frames=7))
@@ -37,12 +37,12 @@ class AiImageOperatorsTest(BlenderTestCase):
):
request = operator.request(context)
require_model.assert_called_once_with("SAFMN_REAL_X4")
require_model.assert_called_once_with("HAT_GAN_X4_SHARPER")
self.assertEqual(
request,
{
"input": "input.png",
"model": "SAFMN_REAL_X4",
"model": "HAT_GAN_X4_SHARPER",
"device": "cuda",
"video_frames": 7,
"start_frame": 4,
@@ -108,12 +108,12 @@ class AiImageOperatorsTest(BlenderTestCase):
result = SimpleNamespace(directory=Path("result"))
operator = self.upscale.UpscaleImage()
operator._image_target = Mock()
operator.model = "SAFMN_REAL_X4"
operator.model = "HAT_GAN_X4_SHARPER"
with (
patch.object(
self.upscale,
"upscale_model_label",
return_value="SAFMN Real x4",
return_value="HAT Sharper",
),
):
message = operator.response(None, result)
@@ -122,4 +122,4 @@ class AiImageOperatorsTest(BlenderTestCase):
Path("result"),
frame_prefix="upscale.",
)
self.assertEqual(message, "Image is upscaled with SAFMN Real x4")
self.assertEqual(message, "Image is upscaled with HAT Sharper")