Skip to content

armgit / rembg

Public Imported from GitHub
0

Rembg is a tool to remove images background

Fixed download pretrained model file

ioryb9c0deb4a3d3
diff --git a/rembg/detect.py b/rembg/detect.py
index c7d5e7d..bc0cc18 100644
--- a/rembg/detect.py
+++ b/rembg/detect.py
@@ -27,9 +27,9 @@ def ort_session(model_name: str) -> ort.InferenceSession:
home = os.getenv("U2NET_HOME", os.path.join("~", ".u2net"))
path = Path(home).expanduser() / f"{model_name}.onnx"
path.parents[0].mkdir(parents=True, exist_ok=True)
- hashing = hashlib.new("md5", path.read_bytes(), usedforsecurity=False)
-
- if not (path.exists() and hashing.hexdigest() == md5):
+ if path.exists():
+ hashing = hashlib.new("md5", path.read_bytes(), usedforsecurity=False)
+ if not path.exists() or hashing.hexdigest() != md5:
with redirect_stdout(sys.stderr):
gdown.download(url, str(path), use_cookies=False)