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

Fixed bugs related to sum #693

Merged
merged 3 commits into from
Nov 30, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 15 additions & 5 deletions rembg/sessions/sam.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import os
from copy import deepcopy
from typing import Dict, List, Tuple
from typing import List

import cv2
import numpy as np
Expand Down Expand Up @@ -105,9 +105,10 @@ def __init__(
valid_providers = []
available_providers = ort.get_available_providers()

for provider in providers or []:
if provider in available_providers:
valid_providers.append(provider)
if providers:
for provider in providers or []:
if provider in available_providers:
valid_providers.append(provider)
Copy link
Contributor Author

@fa0311 fa0311 Nov 29, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added if providers: like other models.
This was causing unintended fallbacks.

new_session(model_name="sam", providers=["CUDAExecutionProvider","CPUExecutionProvider"])
2024-11-29 13:14:59.2810429 [E:onnxruntime:Default, provider_bridge_ort.cc:1848 onnxruntime::TryGetProviderInfo_TensorRT] D:\a\_work\1\s\onnxruntime\core\session\provider_bridge_ort.cc:1539 onnxruntime::ProviderLibrary::Get [ONNXRuntimeError] : 1 : FAIL : LoadLibrary failed with error 126 "" when trying to load "c:\Users\yuki\Documents\School\2024\background-erase\.venv\lib\site-packages\onnxruntime\capi\onnxruntime_providers_tensorrt.dll"

*************** EP Error ***************
EP Error D:\a\_work\1\s\onnxruntime\python\onnxruntime_pybind_state.cc:507 onnxruntime::python::RegisterTensorRTPluginsAsCustomOps 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 ['CUDAExecutionProvider', 'CPUExecutionProvider', 'TensorrtExecutionProvider', 'CUDAExecutionProvider', 'CPUExecutionProvider']
Falling back to ['CUDAExecutionProvider', 'CPUExecutionProvider'] and retrying.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This appears to have changed with this commit: 6f1dd31

else:
valid_providers.extend(available_providers)

Expand Down Expand Up @@ -142,7 +143,16 @@ def predict(
Returns:
List[PILImage]: A list of masks generated by the decoder.
"""
prompt = kwargs.get("sam_prompt", "{}")
prompt = kwargs.get(
"sam_prompt",
[
{
"type": "point",
"label": 1,
"data": [int(img.width / 2), int(img.height / 2)],
}
],
)
Comment on lines +146 to +155
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added default prompt
This simply selects the center of the image.
The existing one simply causes a validation error, but better than that.

schema = {
"type": "array",
"items": {
Expand Down