Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] Could not use model in custom dir on Win10 with cli command #636

Closed
Mikachu2333 opened this issue May 24, 2024 · 4 comments
Closed
Labels
bug Something isn't working stale

Comments

@Mikachu2333
Copy link

Mikachu2333 commented May 24, 2024

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:

  1. Download python embedded via https://www.python.org/ftp/python/3.12.3/python-3.12.3-embed-amd64.zip
  2. Unzip the file and go to the dir
  3. Replace the python312._pth file's line 5 from #import site to import site
  4. Download get-pip.py and use python.exe in dir to run it. (A folder will be create as the rusult which located near python.exe in the dir named Scripts)
  5. Use pip.exe in Scripts dir to install rembg
  6. Download u2net_human_seg.onnx and place it to the Scripts dir
  7. 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

  1. I tried [BUG] custom model on windows  #629 and what readme.md support to do but nothing happened.
  2. I insert code in u2net_custom.py , line 37 (after comments) to show kwargs and args, and, I see nothing about model_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)
@Mikachu2333 Mikachu2333 added the bug Something isn't working label May 24, 2024
Copy link

This issue is stale because it has been open for 30 days with no activity.

@github-actions github-actions bot added the stale label Jun 24, 2024
Copy link

github-actions bot commented Jul 8, 2024

This issue was closed because it has been inactive for 14 days since being marked as stale.

@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Jul 8, 2024
@LINHYYY
Copy link

LINHYYY commented Sep 29, 2024

I also encountered this problem, it seems to be caused by the inconsistency between Linux system commands and Windows system commands. After trying, the correct usage 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, but I need to pay attention to the '' '/' issue between the model path and the image path. I hope you can help me

@Mikachu2333
Copy link
Author

Thanks a thousand of time!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working stale
Projects
None yet
Development

No branches or pull requests

2 participants