Use my own model path when using as a library #506
Replies: 2 comments
-
To use rembg with a locally stored U2NET model, one approach is to set the model path using the environment variable U2NET_PATH. This will direct rembg to utilize the U2NET model at the specified local path instead of downloading it again from the Internet. You can set environment variables in Python using the os module. Here's an example of how you can modify your code to include this:
Please replace 'path/to/your/local/model' with the actual local path to your U2NET model. Remember, if the path changes or the program is restarted, you will need to reset it. Also make sure that the local U2NET model is compatible with the rembg version you’re currently using. Note: The path needs to point to the .pth file directly. Also, check if your environment has write permissions to the folder where the model file exists because rembg might do some caching operations. |
Beta Was this translation helpful? Give feedback.
-
according to #568 (comment) i would recommend getting a reference to your project directory first and then build the path from there.
|
Beta Was this translation helpful? Give feedback.
-
Hi guys!
I'm a big fan of rembg. However, every time I use it, I have to download the U2NET model from GitHub, which adds some delay. I'd love to specify a local path for the model to avoid downloading it repeatedly, but I'm not sure how to do this when using rembg as a library.
I installed rembg using pip and I'm currently on last version.
Here's the code I'm using:
Any guidance on this would be greatly appreciated. Thanks in advance!
Beta Was this translation helpful? Give feedback.
All reactions