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

GPU not used,CPU running full #682

Open
sasachen opened this issue Oct 24, 2024 · 5 comments
Open

GPU not used,CPU running full #682

sasachen opened this issue Oct 24, 2024 · 5 comments
Labels
bug Something isn't working

Comments

@sasachen
Copy link

wen running u2netp GPU not used,CPU running full

import torch
from PIL import Image

from config.conf import PROJECT_ROOT
from server.rembg.rembg import new_session, remove

rembg_module = Rembg().load_image_net()

image = url_to_PIL_array(image_url)

new_img = rembg_module.process(image)

class Rembg:
model = {
"U2NET": "u2net",
"U2NETP": "u2netp",
"U2NET_HUMAN_SEG": "u2net_human_seg",
"U2NET_CLOTH_SEG": "u2net_cloth_seg",
"SILUETA": "silueta",
"ISNET-GENERAL-USE": "isnet-general-use",
"ISNET-ANIME": "isnet-anime",
"SAM": "sam",
}

def __init__(self):
    self.net = None

def load_image_net(self, model="u2netp"):
    device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
    cache = PROJECT_ROOT + "/package/rembg/"
    net = new_session(model, cache=cache, device=device)
    self.net = net
    return self

def resize_image(self, image):
    image = image.convert('RGB')
    model_input_size = (1024, 1024)
    image = image.resize(model_input_size, Image.BILINEAR)
    return image

def process(self, image):
    new_im = remove(
        image,
        alpha_matting=True,
        session=self.net,
        only_mask=False,
    )
    return new_im
    # return [new_orig_image, new_im]

GPU
image

@sasachen sasachen added the bug Something isn't working label Oct 24, 2024
@Goki-0324
Copy link

I have same issues.
Don't know how to fix it.

@xy3xy3
Copy link

xy3xy3 commented Nov 9, 2024

I have same issues. Don't know how to fix it.

me too.

@xy3xy3
Copy link

xy3xy3 commented Nov 9, 2024

from rembg import remove
import cv2
import onnxruntime as ort

print(ort.get_available_providers())
exit()

python 3.12
pip install onnxruntime-gpu
pip install "rembg[gpu,cli]" # for library + cli
pip install opencv-python

GPU is not avaliable.However,cuda is ok.

PS > python use_rembg.py      
['AzureExecutionProvider', 'CPUExecutionProvider']
PS> nvidia-smi
Sat Nov  9 22:02:30 2024       
+-----------------------------------------------------------------------------------------+
| NVIDIA-SMI 560.94                 Driver Version: 560.94         CUDA Version: 12.6     |
|-----------------------------------------+------------------------+----------------------+
| GPU  Name                  Driver-Model | Bus-Id          Disp.A | Volatile Uncorr. ECC |
| Fan  Temp   Perf          Pwr:Usage/Cap |           Memory-Usage | GPU-Util  Compute M. |
|                                         |                        |               MIG M. |
|=========================================+========================+======================|
|   0  NVIDIA GeForce RTX 3060 ...  WDDM  |   00000000:01:00.0 Off |                  N/A |
| N/A   56C    P8             10W /  115W |     226MiB /   6144MiB |      0%      Default |
|                                         |                        |                  N/A |
+-----------------------------------------+------------------------+----------------------+

+-----------------------------------------------------------------------------------------+
| Processes:                                                                              |
|  GPU   GI   CI        PID   Type   Process name                              GPU Memory |
|        ID   ID                                                               Usage      |
|=========================================================================================|
|    0   N/A  N/A      5540    C+G   D:\Program Files\Tencent\QQNT\QQ.exe        N/A      |
|    0   N/A  N/A     16676    C+G   D:\Program Files\Tencent\QQNT\QQ.exe        N/A      |
+-----------------------------------------------------------------------------------------+
PS D:\Proj\sqc\数字人\绿幕背景换图> nvcc -V
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2024 NVIDIA Corporation
Built on Thu_Sep_12_02:55:00_Pacific_Daylight_Time_2024
Cuda compilation tools, release 12.6, V12.6.77
Build cuda_12.6.r12.6/compiler.34841621_0
PS > 

@sasachen
Copy link
Author

I have same issues. Don't know how to fix it.

me too.

try thanks
https://huggingface.co/briaai/RMBG-1.4
https://huggingface.co/briaai/RMBG-2.0

@fa0311
Copy link
Contributor

fa0311 commented Nov 29, 2024

In my case, reinstalling solved the issue.

pip uninstall rembg
pip uninstall onnxruntime
pip install rembg[gpu]

env: cuda 12.6 + cuDNN 9.5.1

Also note that onnxruntime-gpu >= 19 supports only cuda 12.x.

https://onnxruntime.ai/docs/execution-providers/CUDA-ExecutionProvider.html

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

4 participants