[BUG] Could not use model in custom dir on Win10 with cli command
Mikachu2333 opened this issue · 2 comments
Mikachu2333 commented
Sum
I decide to use u2net_human_seg.onnx
on my custom dir with Python embedded
(in order to make a portable package) and meet problem.
To Reproduce
Steps to reproduce the behavior:
- Download python embedded via https://www.python.org/ftp/python/3.12.3/python-3.12.3-embed-amd64.zip
- Unzip the file and go to the dir
- Replace the
python312._pth
file's line 5 from#import site
toimport site
- Download get-pip.py and use
python.exe
in dir to run it. (A folder will be create as the rusult which located nearpython.exe
in the dir namedScripts
) - Use
pip.exe
inScripts
dir to installrembg
- Download
u2net_human_seg.onnx
and place it to theScripts
dir - Open powershell in
Scripts
dir and run the command as follow
Command1 (Error)
Use relative path.
./rembg.exe i -m u2net_custom -x '{"model_path": "./u2net_human_seg.onnx"}' "123.jpg" "123_u.jpg"
Command2 (Error)
Use absolute path.
./rembg.exe i -m u2net_custom -x '{"model_path": "D:\\Temp\\rembg-embedded\\python-3.12.3-embed-amd64\\Scripts\\u2net_human_seg.onnx"}' "123.jpg" "123_u.jpg"
Command3 (Error)
Change quotation marks
1
./rembg.exe i -m u2net_custom -x "{"model_path": "./u2net_human_seg.onnx"}" "123.jpg" "123_u.jpg"
2
./rembg.exe i -m u2net_custom -x "{model_path: ./u2net_human_seg.onnx}" "123.jpg" "123_u.jpg"
3
./rembg.exe i -m u2net_custom -x "{'model_path': './u2net_human_seg.onnx'}" "123.jpg" "123_u.jpg"
Command3 (Error)
Use equal sign
1
./rembg.exe i -m u2net_custom -x "{"model_path"="./u2net_human_seg.onnx"}" "123.jpg" "123_u.jpg"
2
./rembg.exe i -m u2net_custom -x="{"model_path": "./u2net_human_seg.onnx"}" "123.jpg" "123_u.jpg"
Error msg
Traceback (most recent call last):
File "<frozen runpy>", line 198, in _run_module_as_main
File "<frozen runpy>", line 88, in _run_code
File "D:\Temp\rembg-embedded\python-3.12.3-embed-amd64\Scripts\rembg.exe\__main__.py", line 4, in <module>
File "D:\Temp\rembg-embedded\python-3.12.3-embed-amd64\Lib\site-packages\rembg\cli.py", line 16, in <module>
_main()
File "D:\Temp\rembg-embedded\python-3.12.3-embed-amd64\Lib\site-packages\click\core.py", line 1157, in __call__
return self.main(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "D:\Temp\rembg-embedded\python-3.12.3-embed-amd64\Lib\site-packages\click\core.py", line 1078, in main
rv = self.invoke(ctx)
^^^^^^^^^^^^^^^^
File "D:\Temp\rembg-embedded\python-3.12.3-embed-amd64\Lib\site-packages\click\core.py", line 1688, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "D:\Temp\rembg-embedded\python-3.12.3-embed-amd64\Lib\site-packages\click\core.py", line 1434, in invoke
return ctx.invoke(self.callback, **ctx.params)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "D:\Temp\rembg-embedded\python-3.12.3-embed-amd64\Lib\site-packages\click\core.py", line 783, in invoke
return __callback(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "D:\Temp\rembg-embedded\python-3.12.3-embed-amd64\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:\Temp\rembg-embedded\python-3.12.3-embed-amd64\Lib\site-packages\rembg\session_factory.py", line 44, in new_session
return session_class(model_name, sess_opts, providers, *args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "D:\Temp\rembg-embedded\python-3.12.3-embed-amd64\Lib\site-packages\rembg\sessions\u2net_custom.py", line 43, in __init__
raise ValueError("model_path is required")
Expected behavior
Run successfully without any error.
System and Python info
Windows 10, 22H2, 19045.4291
Python 3.12.3 (embedded)
Rembg version
v2.0.57 (latest)
Additional info
- I tried #629 and what readme.md support to do but nothing happened.
- I insert code in
u2net_custom.py
, line 37 (after comments) to show kwargs and args, and, I see nothing aboutmodel_path
as if this kwarg has been delete when program transform the args info.
Code:
for v in args:#testonly
print ('Optional argument (args): ', v)
for k, v in kwargs.items():#testonly
print ('Optional argument %s (kwargs): %s' % (k, v))
Show:
Optional argument alpha_matting (kwargs): False
Optional argument alpha_matting_foreground_threshold (kwargs): 240
Optional argument alpha_matting_background_threshold (kwargs): 10
Optional argument alpha_matting_erode_size (kwargs): 10
Optional argument only_mask (kwargs): False
Optional argument post_process_mask (kwargs): False
Optional argument bgcolor (kwargs): (0, 0, 0, 0)
github-actions commented
This issue is stale because it has been open for 30 days with no activity.
github-actions commented
This issue was closed because it has been inactive for 14 days since being marked as stale.