Skip to content

armgit / rembg

Public Imported from GitHub
0

Rembg is a tool to remove images background

Allow providers to be passed as argument to BaseSession

Thomas8b6a509fff17
diff --git a/rembg/sessions/base.py b/rembg/sessions/base.py
index 2e2bcd5..a511349 100644
--- a/rembg/sessions/base.py
+++ b/rembg/sessions/base.py
@@ -13,20 +13,23 @@ class BaseSession:
def __init__(self, model_name: str, sess_opts: ort.SessionOptions, *args, **kwargs):
"""Initialize an instance of the BaseSession class."""
self.model_name = model_name
-
- device_type = ort.get_device()
- if (
- device_type == "GPU"
- and "CUDAExecutionProvider" in ort.get_available_providers()
- ):
- providers = ["CUDAExecutionProvider", "CPUExecutionProvider"]
- elif (
- device_type[0:3] == "GPU"
- and "ROCMExecutionProvider" in ort.get_available_providers()
- ):
- providers = ["ROCMExecutionProvider", "CPUExecutionProvider"]
+
+ if "providers" in kwargs and isinstance(kwargs["providers"], list):
+ providers = kwargs.pop("providers")
else:
- providers = ["CPUExecutionProvider"]
+ device_type = ort.get_device()
+ if (
+ device_type == "GPU"
+ and "CUDAExecutionProvider" in ort.get_available_providers()
+ ):
+ providers = ["CUDAExecutionProvider", "CPUExecutionProvider"]
+ elif (
+ device_type[0:3] == "GPU"
+ and "ROCMExecutionProvider" in ort.get_available_providers()
+ ):
+ providers = ["ROCMExecutionProvider", "CPUExecutionProvider"]
+ else:
+ providers = ["CPUExecutionProvider"]
self.inner_session = ort.InferenceSession(
str(self.__class__.download_models(*args, **kwargs)),