About how to run rembg using a self trained model on Windows
LINHYYY opened this issue · 2 comments
When I trained my U2net model and wanted to use it to run Rembg, I initially used the method described by the author in README.md
rembg i -m u2net_custom -x '{"model_path": "~/.u2net/u2net.onnx"}' path/to/input.png path/to/output.png
But I encountered the following error:
Traceback (most recent call last):
File "D:\Anaconda3\envs\rembg\lib\runpy.py", line 197, in _run_module_as_main
return _run_code(code, main_globals, None,
File "D:\Anaconda3\envs\rembg\lib\runpy.py", line 87, in run_code
exec(code, run_globals)
File "D:\Anaconda3\envs\rembg\Scripts\rembg.exe_main.py", line 4, in
from rembg.cli import main
File "D:\Anaconda3\envs\rembg\lib\site-packages\rembg\cli.py", line 16, in
_main()
File "D:\Anaconda3\envs\rembg\lib\site-packages\click\core.py", line 1157, in call
return self.main(*args, **kwargs)
File "D:\Anaconda3\envs\rembg\lib\site-packages\click\core.py", line 1078, in main
rv = self.invoke(ctx)
File "D:\Anaconda3\envs\rembg\lib\site-packages\click\core.py", line 1688, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File "D:\Anaconda3\envs\rembg\lib\site-packages\click\core.py", line 1434, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "D:\Anaconda3\envs\rembg\lib\site-packages\click\core.py", line 783, in invoke
return __callback(*args, **kwargs)
File "D:\Anaconda3\envs\rembg\lib\site-packages\rembg\commands\i_command.py", line 108, in i_command
output.write(remove(input.read(), session=new_session(model, **kwargs), **kwargs))
File "D:\Anaconda3\envs\rembg\lib\site-packages\rembg\session_factory.py", line 44, in new_session
return session_class(model_name, sess_opts, providers, *args, **kwargs)
File "D:\Anaconda3\envs\rembg\lib\site-packages\rembg\sessions\u2net_custom.py", line 39, in init
raise ValueError("model_path is required")
ValueError: model_path is required
I have found that this issue has also been mentioned in many issues, such as:issues #629 issues #636
It seems to be caused by the inconsistency between Linux system commands and Windows system commands. The author mentioned Linux commands in README.md, but after my attempts, I found that the correct command for Windows is:
rembg i -m u2net_custom -x "{\"model_path\": \"C:/your model path/your model name.onnx\"}" ./images/input.jpg ./images/output.jpg
I have successfully used the model I trained myself, it need to pay attention to the '\' '/' issue between the model path and the image path. I hope it can help people who are also facing this problem.
This issue is stale because it has been open for 30 days with no activity.
This issue was closed because it has been inactive for 14 days since being marked as stale.