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

AttributeError: module 'onnxruntime' has no attribute 'SessionOptions' #706

Open
hermitguo opened this issue Jan 13, 2025 · 2 comments
Open
Labels
bug Something isn't working

Comments

@hermitguo
Copy link

hermitguo commented Jan 13, 2025

Describe the bug
When running rembg i /home/ubuntu/Pictures/test2.jpg ~/test1.png, the following error occurs

AttributeError: module 'onnxruntime' has no attribute 'SessionOptions'

Note: Laptop configuration
Intel® Core™ Ultra 5 125H, Intel® ARC™ Graphics
To Reproduce
Steps to reproduce the behavior:

  1. Go to '...'

1.install
`pip install rembg # for library
pip install "rembg[cli]" # for library + cli

pip install rembg[cpu] # for library
pip install "rembg[cpu,cli]" # for library + cli
pip install "rembg[gpu]" # for library
pip install "rembg[gpu,cli]" # for library + cli`

`ubuntu@servers:$ source /opt/pyenv/envpy3.12/bin/activate
(envpy3.12) ubuntu@servers:
$
(envpy3.12) ubuntu@servers:~$ ls -lha /opt/pyenv/envpy3.12/lib/python3.12/site-packages/onnxruntime/capi

drwxrwxr-x 2 ubuntu ubuntu 4.0K Jan 13 17:27 .
drwxrwxr-x 3 ubuntu ubuntu 4.0K Jan 13 17:27 ..
-rwxrwxr-x 1 ubuntu ubuntu 733M Jan 13 11:33 libonnxruntime_providers_cuda.so
-rwxrwxr-x 1 ubuntu ubuntu 695K Jan 13 11:33 libonnxruntime_providers_tensorrt.so`
download:
~/.u2net/u2net.onnx

~/.bashrc
export LD_LIBRARY_PATH=/opt/pyenv/envpy3.12/lib/python3.12/site-packages/onnxruntime/capi/:$LD_LIBRARY_PATH
source ~/.bashrc
ldconfig -v

run
rembg i /home/ubuntu/Pictures/test2.jpg ~/test1.png
2025-01-13 17:26:28.808988636 [E:onnxruntime:Default, provider_bridge_ort.cc:1848 TryGetProviderInfo_TensorRT] /onnxruntime_src/onnxruntime/core/session/provider_bridge_ort.cc:1539 onnxruntime::Provider& onnxruntime::ProviderLibrary::Get() [ONNXRuntimeError] : 1 : FAIL : Failed to load library libonnxruntime_providers_tensorrt.so with error: libcublas.so.12: cannot open shared object file: No such file or directory

*************** EP Error ***************
EP Error /onnxruntime_src/onnxruntime/python/onnxruntime_pybind_state.cc:507 void onnxruntime::python::RegisterTensorRTPluginsAsCustomOps(PySessionOptions&, const onnxruntime::ProviderOptions&) Please install TensorRT libraries as mentioned in the GPU requirements page, make sure they're in the PATH or LD_LIBRARY_PATH, and that your GPU is supported.
when using ['TensorrtExecutionProvider', 'CUDAExecutionProvider', 'CPUExecutionProvider']
Falling back to ['CUDAExecutionProvider', 'CPUExecutionProvider'] and retrying.


2025-01-13 17:26:28.917768137 [E:onnxruntime:Default, provider_bridge_ort.cc:1862 TryGetProviderInfo_CUDA] /onnxruntime_src/onnxruntime/core/session/provider_bridge_ort.cc:1539 onnxruntime::Provider& onnxruntime::ProviderLibrary::Get() [ONNXRuntimeError] : 1 : FAIL : Failed to load library libonnxruntime_providers_cuda.so with error: libcublasLt.so.12: cannot open shared object file: No such file or directory
2. uninstall
pip uninstall rembg pip uninstall onnxruntime

3.install
pip install rembg[gpu] onnxruntime-gpu
4. run
(envpy3.12) ubuntu@servers:/opt/tools/rembg$ rembg i test.webp test.png Traceback (most recent call last): File "/opt/tools/rembg/rembg.py", line 1, in <module> from rembg.cli import main File "/opt/tools/rembg/rembg/__init__.py", line 5, in <module> from .bg import remove File "/opt/tools/rembg/rembg/bg.py", line 22, in <module> from .session_factory import new_session File "/opt/tools/rembg/rembg/session_factory.py", line 6, in <module> from .sessions import sessions_class File "/opt/tools/rembg/rembg/sessions/__init__.py", line 5, in <module> from .base import BaseSession File "/opt/tools/rembg/rembg/sessions/base.py", line 10, in <module> class BaseSession: File "/opt/tools/rembg/rembg/sessions/base.py", line 16, in BaseSession sess_opts: ort.SessionOptions, ^^^^^^^^^^^^^^^^^^ AttributeError: module 'onnxruntime' has no attribute 'SessionOptions'

docker compose also doesn't work properly.
rembg

  1. See error
    AttributeError: module 'onnxruntime' has no attribute 'SessionOptions'`
    Expected behavior
    A clear and concise description of what you expected to happen.

Images
rembg i test.webp test.png

OS Version:
ubuntu24.04

Rembg version:
v2.0.21

Additional context
Add any other context about the problem here.

@hermitguo hermitguo added the bug Something isn't working label Jan 13, 2025
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 Feb 13, 2025
@ShyamCrossShore
Copy link

Describe the bug When running rembg i /home/ubuntu/Pictures/test2.jpg ~/test1.png, the following error occurs

AttributeError: module 'onnxruntime' has no attribute 'SessionOptions'

Note: Laptop configuration Intel® Core™ Ultra 5 125H, Intel® ARC™ Graphics To Reproduce Steps to reproduce the behavior:

  1. Go to '...'

1.install `pip install rembg # for library pip install "rembg[cli]" # for library + cli

pip install rembg[cpu] # for library pip install "rembg[cpu,cli]" # for library + cli pip install "rembg[gpu]" # for library pip install "rembg[gpu,cli]" # for library + cli`

`ubuntu@servers:$ source /opt/pyenv/envpy3.12/bin/activate (envpy3.12) ubuntu@servers:$ (envpy3.12) ubuntu@servers:~$ ls -lha /opt/pyenv/envpy3.12/lib/python3.12/site-packages/onnxruntime/capi

drwxrwxr-x 2 ubuntu ubuntu 4.0K Jan 13 17:27 . drwxrwxr-x 3 ubuntu ubuntu 4.0K Jan 13 17:27 .. -rwxrwxr-x 1 ubuntu ubuntu 733M Jan 13 11:33 libonnxruntime_providers_cuda.so -rwxrwxr-x 1 ubuntu ubuntu 695K Jan 13 11:33 libonnxruntime_providers_tensorrt.so` download: ~/.u2net/u2net.onnx

~/.bashrc export LD_LIBRARY_PATH=/opt/pyenv/envpy3.12/lib/python3.12/site-packages/onnxruntime/capi/:$LD_LIBRARY_PATH source ~/.bashrc ldconfig -v

run rembg i /home/ubuntu/Pictures/test2.jpg ~/test1.png 2025-01-13 17:26:28.808988636 [E:onnxruntime:Default, provider_bridge_ort.cc:1848 TryGetProviderInfo_TensorRT] /onnxruntime_src/onnxruntime/core/session/provider_bridge_ort.cc:1539 onnxruntime::Provider& onnxruntime::ProviderLibrary::Get() [ONNXRuntimeError] : 1 : FAIL : Failed to load library libonnxruntime_providers_tensorrt.so with error: libcublas.so.12: cannot open shared object file: No such file or directory

*************** EP Error *************** EP Error /onnxruntime_src/onnxruntime/python/onnxruntime_pybind_state.cc:507 void onnxruntime::python::RegisterTensorRTPluginsAsCustomOps(PySessionOptions&, const onnxruntime::ProviderOptions&) Please install TensorRT libraries as mentioned in the GPU requirements page, make sure they're in the PATH or LD_LIBRARY_PATH, and that your GPU is supported. when using ['TensorrtExecutionProvider', 'CUDAExecutionProvider', 'CPUExecutionProvider'] Falling back to ['CUDAExecutionProvider', 'CPUExecutionProvider'] and retrying.

2025-01-13 17:26:28.917768137 [E:onnxruntime:Default, provider_bridge_ort.cc:1862 TryGetProviderInfo_CUDA] /onnxruntime_src/onnxruntime/core/session/provider_bridge_ort.cc:1539 onnxruntime::Provider& onnxruntime::ProviderLibrary::Get() [ONNXRuntimeError] : 1 : FAIL : Failed to load library libonnxruntime_providers_cuda.so with error: libcublasLt.so.12: cannot open shared object file: No such file or directory 2. uninstall pip uninstall rembg pip uninstall onnxruntime

3.install pip install rembg[gpu] onnxruntime-gpu 4. run (envpy3.12) ubuntu@servers:/opt/tools/rembg$ rembg i test.webp test.png Traceback (most recent call last): File "/opt/tools/rembg/rembg.py", line 1, in <module> from rembg.cli import main File "/opt/tools/rembg/rembg/__init__.py", line 5, in <module> from .bg import remove File "/opt/tools/rembg/rembg/bg.py", line 22, in <module> from .session_factory import new_session File "/opt/tools/rembg/rembg/session_factory.py", line 6, in <module> from .sessions import sessions_class File "/opt/tools/rembg/rembg/sessions/__init__.py", line 5, in <module> from .base import BaseSession File "/opt/tools/rembg/rembg/sessions/base.py", line 10, in <module> class BaseSession: File "/opt/tools/rembg/rembg/sessions/base.py", line 16, in BaseSession sess_opts: ort.SessionOptions, ^^^^^^^^^^^^^^^^^^ AttributeError: module 'onnxruntime' has no attribute 'SessionOptions'

docker compose also doesn't work properly. rembg

  1. See error
    AttributeError: module 'onnxruntime' has no attribute 'SessionOptions'`
    Expected behavior
    A clear and concise description of what you expected to happen.

Images rembg i test.webp test.png

OS Version: ubuntu24.04

Rembg version: v2.0.21

Additional context Add any other context about the problem here.

#707 check my solution it my work for you

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

No branches or pull requests

2 participants