danielgatis / rembg

Rembg is a tool to remove images background
MIT License
16.45k stars 1.84k forks source link

[BUG] GPU doesn't work out of the box, workaround & benchmarks #483

Closed luke14free closed 1 year ago

luke14free commented 1 year ago

Describe the bug To run on the GPU you need to uninstall and re-install onnxruntime-gpu.

!pip install rembg[cli,gpu]
import onnxruntime as ort
ort.get_device()

Will return "CPU". But:

!pip install rembg[cli,gpu]
!pip uninstall onnxruntime-gpu --yes
!pip install onnxruntime-gpu

import onnxruntime as ort
ort.get_device()

Will return "GPU".

FYI to all of those interested, benchmarks on running on GPUs made us understand it's a bit useless to run on GPUs as improvements are quite marginal but costs will be quite higher (maybe parallel processing makes this more interesting, haven't tested much of this).

!wget https://raw.githubusercontent.com/danielgatis/rembg/master/examples/car-1.jpg
!mv car-1.jpg input.jpg

from rembg import remove

input_path = 'input.jpg'
output_path = 'output.png'

with open(input_path, 'rb') as i:
    with open(output_path, 'wb') as o:
        input = i.read()

then:

%%timeit
output = remove(input)

Results on Colab:

github-actions[bot] commented 1 year ago

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

github-actions[bot] commented 1 year ago

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

luke14free commented 1 year ago

FYI, to those in need of better GPU speed -> https://github.com/nadermx/backgroundremover works much better with execution speed down to 0.4s on GPUs.