Skip to content

armgit / rembg

Public Imported from GitHub
0

Rembg is a tool to remove images background

add workaround

Daniel Gatise894cffd98b2
diff --git a/rembg/session_factory.py b/rembg/session_factory.py
index be80bb1..e1a227c 100644
--- a/rembg/session_factory.py
+++ b/rembg/session_factory.py
@@ -40,6 +40,10 @@ def new_session(model_name: str = "u2net", *args, **kwargs) -> BaseSession:
sess_opts = ort.SessionOptions()
+ # Workaround for birefnet not working with default graph optimization level
+ # https://github.com/microsoft/onnxruntime/issues/26261
+ sess_opts.graph_optimization_level = ort.GraphOptimizationLevel.ORT_ENABLE_BASIC
+
if "OMP_NUM_THREADS" in os.environ:
threads = int(os.environ["OMP_NUM_THREADS"])
sess_opts.inter_op_num_threads = threads
diff --git a/tests/test_remove.py b/tests/test_remove.py
index 5d44599..6e7ee75 100644
--- a/tests/test_remove.py
+++ b/tests/test_remove.py
@@ -38,14 +38,13 @@ def test_remove():
"isnet-general-use",
"isnet-anime",
"sam",
- # birefnet is not working :(
- # "birefnet-general",
- # "birefnet-general-lite",
- # "birefnet-portrait",
- # "birefnet-dis",
- # "birefnet-hrsod",
- # "birefnet-cod",
- # "birefnet-massive"
+ "birefnet-general",
+ "birefnet-general-lite",
+ "birefnet-portrait",
+ "birefnet-dis",
+ "birefnet-hrsod",
+ "birefnet-cod",
+ "birefnet-massive"
]:
for picture in ["anime-girl-1", "car-1", "cloth-1", "plants-1"]:
image_path = Path(here / "fixtures" / f"{picture}.jpg")