Rembg is a tool to remove images background.

Overview

Rembg

Downloads Downloads Downloads License

Rembg is a tool to remove images background. That is it.

*** If you want to remove background from videos try this this fork: https://github.com/ecsplendid/rembg-greenscreen ***

Requirements

How to install torch/torchvision

Go to https://pytorch.org and scrool down to INSTALL PYTORCH section and follow the instructions.

For example:

PyTorch Build: Stable (1.7.1)
Your OS: Windows
Package: Pip
Language: Python
CUDA: None

The install cmd is:

pip install torch==1.7.1+cpu torchvision==0.8.2+cpu -f https://download.pytorch.org/whl/torch_stable.html

Installation

Install it from pypi

pip install rembg

Usage as a cli

Remove the background from a remote image

curl -s http://input.png | rembg > output.png

Remove the background from a local file

rembg -o path/to/output.png path/to/input.png

Remove the background from all images in a folder

rembg -p path/to/input path/to/output

Add a custom model

Copy the custom-model.pth file to ~/.u2net and run:

curl -s http://input.png | rembg -m custom-model > output.png

Usage as a server

Start the server

rembg-server

Open your browser to

http://localhost:5000?url=http://image.png

Also you can send the file as a FormData (multipart/form-data):

Usage as a library

Example 1: Read from stdin and write to stdout

In app.py

import sys
from rembg.bg import remove

sys.stdout.buffer.write(remove(sys.stdin.buffer.read()))

Then run

cat input.png | python app.py > out.png

Example 2: Using PIL

In app.py

from rembg.bg import remove
import numpy as np
import io
from PIL import Image

input_path = 'input.png'
output_path = 'out.png'

f = np.fromfile(input_path)
result = remove(f)
img = Image.open(io.BytesIO(result)).convert("RGBA")
img.save(output_path)

Then run

python app.py

Usage as a docker

Just run

curl -s http://input.png | docker run -i -v ~/.u2net:/root/.u2net danielgatis/rembg:latest > output.png

Advance usage

Sometimes it is possible to achieve better results by turning on alpha matting. Example:

curl -s http://input.png | rembg -a -ae 15 > output.png
Original Without alpha matting With alpha matting (-a -ae 15)

References

Backers

Love rembg? Help me keep it alive by donating funds to cover project expenses!
[Become a backer]

Sponsors

Become a sponsor and get your logo here on our Github page.
[Become a sponsor]

License

Copyright (c) 2020-present Daniel Gatis

Licensed under MIT License

Comments
  • Error ModuleNotFoundError: No module named 'pymatting_aot.aot'

    Error ModuleNotFoundError: No module named 'pymatting_aot.aot'

    Hello, I have centos 8 server.

    This is the error after running the command rembg -o input_image output_image

    Failed to import ahead-of-time-compiled modules. This is expected on first import. Compiling modules and trying again (this might take a minute). Traceback (most recent call last): File "/usr/local/lib/python3.8/site-packages/pymatting_aot/cc.py", line 21, in import pymatting_aot.aot ModuleNotFoundError: No module named 'pymatting_aot.aot'

    During handling of the above exception, another exception occurred:

    Traceback (most recent call last): File "/usr/local/bin/rembg", line 5, in from rembg.cmd.cli import main File "/usr/local/lib/python3.8/site-packages/rembg/cmd/cli.py", line 7, in from ..bg import remove File "/usr/local/lib/python3.8/site-packages/rembg/bg.py", line 6, in from pymatting.alpha.estimate_alpha_cf import estimate_alpha_cf File "/usr/local/lib/python3.8/site-packages/pymatting/init.py", line 2, in import pymatting_aot.cc File "/usr/local/lib/python3.8/site-packages/pymatting_aot/cc.py", line 28, in compile_modules() File "/usr/local/lib/python3.8/site-packages/pymatting_aot/cc.py", line 16, in compile_modules cc.compile() File "/usr/local/lib64/python3.8/site-packages/numba/core/compiler_lock.py", line 32, in _acquire_compile_lock return func(*args, **kwargs) File "/usr/local/lib64/python3.8/site-packages/numba/pycc/cc.py", line 217, in compile objects += self._compile_mixins(build_dir) File "/usr/local/lib64/python3.8/site-packages/numba/pycc/cc.py", line 187, in _compile_mixins objects = self._toolchain.compile_objects(sources, build_dir, File "/usr/local/lib64/python3.8/site-packages/numba/pycc/platform.py", line 137, in compile_objects objects = self._compiler.compile(sources, File "/usr/local/lib64/python3.8/site-packages/numpy/distutils/ccompiler.py", line 90, in m = lambda self, *args, **kw: func(self, *args, **kw) File "/usr/local/lib64/python3.8/site-packages/numpy/distutils/ccompiler.py", line 356, in CCompiler_compile pool.map(single_compile, build_items) File "/usr/lib64/python3.8/multiprocessing/pool.py", line 364, in map return self._map_async(func, iterable, mapstar, chunksize).get() File "/usr/lib64/python3.8/multiprocessing/pool.py", line 768, in get raise self._value File "/usr/lib64/python3.8/multiprocessing/pool.py", line 125, in worker result = (True, func(*args, **kwds)) File "/usr/lib64/python3.8/multiprocessing/pool.py", line 48, in mapstar return list(map(*args)) File "/usr/local/lib64/python3.8/site-packages/numpy/distutils/ccompiler.py", line 321, in single_compile self._compile(obj, src, ext, cc_args, extra_postargs, pp_opts) File "/usr/local/lib64/python3.8/site-packages/numpy/distutils/ccompiler.py", line 90, in m = lambda self, *args, **kw: func(self, *args, **kw) File "/usr/local/lib64/python3.8/site-packages/numpy/distutils/unixccompiler.py", line 54, in UnixCCompiler__compile raise CompileError(msg) distutils.errors.CompileError: Command "gcc -pthread -Wno-unused-result -Wsign-compare -DDYNAMIC_ANNOTATIONS_ENABLED=1 -DNDEBUG -O2 -g -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -Wp,-D_GLIBCXX_ASSERTIONS -fexceptions -fstack-protector-strong -grecord-gcc-switches -m64 -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection -D_GNU_SOURCE -fPIC -fwrapv -O2 -g -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -Wp,-D_GLIBCXX_ASSERTIONS -fexceptions -fstack-protector-strong -grecord-gcc-switches -m64 -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection -D_GNU_SOURCE -fPIC -fwrapv -O2 -g -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -Wp,-D_GLIBCXX_ASSERTIONS -fexceptions -fstack-protector-strong -grecord-gcc-switches -m64 -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection -D_GNU_SOURCE -fPIC -fwrapv -fPIC -DPYCC_MODULE_NAME=aot -DPYCC_USE_NRT=1 -I/usr/include/python3.8 -I/usr/local/lib64/python3.8/site-packages/numpy/core/include -c /usr/local/lib64/python3.8/site-packages/numba/cext/utils.c -o /tmp/pycc-build-aot-gz0f8q5m/usr/local/lib64/python3.8/site-packages/numba/cext/utils.o" failed with exit status 1

    This is the command I have used to install rembg

    python3.8 -m pip install --upgrade pip

    [root@ ]# python3.8 -m pip install rembg

    Processing /root/.cache/pip/wheels/c4/52/be/f93ed10eb3209e691a9226d0ba337172ef19e38a0014892198/rembg-1.0.15-cp38-none-any.whl Requirement already satisfied: pillow==8.0.1 in /usr/local/lib64/python3.8/site-packages (from rembg) (8.0.1) Requirement already satisfied: numpy==1.19.4 in /usr/local/lib64/python3.8/site-packages (from rembg) (1.19.4) Requirement already satisfied: requests==2.24.0 in /usr/local/lib/python3.8/site-packages (from rembg) (2.24.0) Requirement already satisfied: scipy==1.5.4 in /usr/local/lib64/python3.8/site-packages (from rembg) (1.5.4) Requirement already satisfied: scikit-image==0.17.2 in /usr/local/lib64/python3.8/site-packages (from rembg) (0.17.2) Requirement already satisfied: waitress==1.4.4 in /usr/local/lib/python3.8/site-packages (from rembg) (1.4.4) Requirement already satisfied: pymatting==1.1.1 in /usr/local/lib/python3.8/site-packages (from rembg) (1.1.1) Requirement already satisfied: tqdm==4.51.0 in /usr/local/lib/python3.8/site-packages (from rembg) (4.51.0) Requirement already satisfied: flask==1.1.2 in /usr/local/lib/python3.8/site-packages (from rembg) (1.1.2) Requirement already satisfied: torchvision==0.8.1 in /usr/local/lib64/python3.8/site-packages (from rembg) (0.8.1) Requirement already satisfied: torch==1.7.0 in /usr/local/lib64/python3.8/site-packages (from rembg) (1.7.0) Requirement already satisfied: urllib3!=1.25.0,!=1.25.1,<1.26,>=1.21.1 in /usr/local/lib/python3.8/site-packages (from requests==2.24.0->rembg) (1.25.11) Requirement already satisfied: certifi>=2017.4.17 in /usr/local/lib/python3.8/site-packages (from requests==2.24.0->rembg) (2020.11.8) Requirement already satisfied: chardet<4,>=3.0.2 in /usr/local/lib/python3.8/site-packages (from requests==2.24.0->rembg) (3.0.4) Requirement already satisfied: idna<3,>=2.5 in /usr/local/lib/python3.8/site-packages (from requests==2.24.0->rembg) (2.10) Requirement already satisfied: tifffile>=2019.7.26 in /usr/local/lib/python3.8/site-packages (from scikit-image==0.17.2->rembg) (2020.10.1) Requirement already satisfied: matplotlib!=3.0.0,>=2.0.0 in /usr/local/lib64/python3.8/site-packages (from scikit-image==0.17.2->rembg) (3.3.3) Requirement already satisfied: networkx>=2.0 in /usr/local/lib/python3.8/site-packages (from scikit-image==0.17.2->rembg) (2.5) Requirement already satisfied: imageio>=2.3.0 in /usr/local/lib/python3.8/site-packages (from scikit-image==0.17.2->rembg) (2.9.0) Requirement already satisfied: PyWavelets>=1.1.1 in /usr/local/lib64/python3.8/site-packages (from scikit-image==0.17.2->rembg) (1.1.1) Requirement already satisfied: numba!=0.49.0 in /usr/local/lib64/python3.8/site-packages (from pymatting==1.1.1->rembg) (0.51.2) Requirement already satisfied: Jinja2>=2.10.1 in /usr/local/lib/python3.8/site-packages (from flask==1.1.2->rembg) (2.11.2) Requirement already satisfied: click>=5.1 in /usr/local/lib/python3.8/site-packages (from flask==1.1.2->rembg) (7.1.2) Requirement already satisfied: itsdangerous>=0.24 in /usr/local/lib/python3.8/site-packages (from flask==1.1.2->rembg) (1.1.0) Requirement already satisfied: Werkzeug>=0.15 in /usr/local/lib/python3.8/site-packages (from flask==1.1.2->rembg) (1.0.1) Requirement already satisfied: dataclasses in /usr/local/lib/python3.8/site-packages (from torch==1.7.0->rembg) (0.6) Requirement already satisfied: future in /usr/local/lib/python3.8/site-packages (from torch==1.7.0->rembg) (0.18.2) Requirement already satisfied: typing-extensions in /usr/local/lib/python3.8/site-packages (from torch==1.7.0->rembg) (3.7.4.3) Requirement already satisfied: kiwisolver>=1.0.1 in /usr/local/lib64/python3.8/site-packages (from matplotlib!=3.0.0,>=2.0.0->scikit-image==0.17.2->rembg) (1.3.1) Requirement already satisfied: pyparsing!=2.0.4,!=2.1.2,!=2.1.6,>=2.0.3 in /usr/local/lib/python3.8/site-packages (from matplotlib!=3.0.0,>=2.0.0->scikit-image==0.17.2->rembg) (2.4.7) Requirement already satisfied: python-dateutil>=2.1 in /usr/local/lib/python3.8/site-packages (from matplotlib!=3.0.0,>=2.0.0->scikit-image==0.17.2->rembg) (2.8.1) Requirement already satisfied: cycler>=0.10 in /usr/local/lib/python3.8/site-packages (from matplotlib!=3.0.0,>=2.0.0->scikit-image==0.17.2->rembg) (0.10.0) Requirement already satisfied: decorator>=4.3.0 in /usr/local/lib/python3.8/site-packages (from networkx>=2.0->scikit-image==0.17.2->rembg) (4.4.2) Requirement already satisfied: llvmlite<0.35,>=0.34.0.dev0 in /usr/local/lib64/python3.8/site-packages (from numba!=0.49.0->pymatting==1.1.1->rembg) (0.34.0) Requirement already satisfied: setuptools in /usr/lib/python3.8/site-packages (from numba!=0.49.0->pymatting==1.1.1->rembg) (41.6.0) Requirement already satisfied: MarkupSafe>=0.23 in /usr/local/lib64/python3.8/site-packages (from Jinja2>=2.10.1->flask==1.1.2->rembg) (1.1.1) Requirement already satisfied: six>=1.5 in /usr/local/lib/python3.8/site-packages (from python-dateutil>=2.1->matplotlib!=3.0.0,>=2.0.0->scikit-image==0.17.2->rembg) (1.15.0) Installing collected packages: rembg Successfully installed rembg-1.0.15

    Please suggest

    opened by arnold408 24
  • Why is CUDA not *much* faster then CPU?

    Why is CUDA not *much* faster then CPU?

    I ran rembg -o 01.PNG 01.JPG on a system with CUDA support and on a system without CUDA support. It's a 2784x1856 JPG with 3.32 MB. CUDA is 11 seconds, CPU is 14 seconds. CUDA is actually used as the check in https://github.com/danielgatis/rembg/blob/master/src/rembg/u2net/detect.py#L92 is successful. Can you explain that to me please?

    opened by coveritytest 22
  • exec from a php file

    exec from a php file

    Hello,

    Thank you so much for this great tool. I have a php website using CodeIgniter.

    When I execute the code below from a php file at the root of my website, it"s working fine. When I execute it in the codeIgniter 'application' folder (what I need), it doesn't work. Any file is returned.

    I have tried with python as well

    $rembgpy = '/my_path/app.py'; $in = '/my_path/lanterne.jpg'; $out = '/mypath/new_lanterne.png';

    exec("rembg -o '$out' '$in'");

    exec("cat '$in' | python3.6 '$rembgpy' > '$out' ");

    Do you have any idea ? (In codeIgniter, python is working for other python program)

    Thank you very much Aude

    opened by latrille-bot 17
  • Trying to get it to work

    Trying to get it to work

    I am on Windows 11. While I did read that it runs with 3.9, does that mean this will not work with a later version? I tried to run with 3.10, 3.9.13 but always getting the following error and not sure what to do: image

    opened by bullmoose20 13
  • requests.exceptions.ConnectionError: HTTPSConnectionPool(host='docs.google.com', port=443)

    requests.exceptions.ConnectionError: HTTPSConnectionPool(host='docs.google.com', port=443)

    Traceback (most recent call last): File "/Users/apple/.pyenv/versions/3.8.6/bin/rembg", line 8, in sys.exit(main()) File "/Users/apple/.pyenv/versions/3.8.6/lib/python3.8/site-packages/rembg/cmd/cli.py", line 122, in main remove( File "/Users/apple/.pyenv/versions/3.8.6/lib/python3.8/site-packages/rembg/bg.py", line 87, in remove model = get_model(model_name) File "/Users/apple/.pyenv/versions/3.8.6/lib/python3.8/site-packages/rembg/bg.py", line 76, in get_model return detect.load_model(model_name="u2net") File "/Users/apple/.pyenv/versions/3.8.6/lib/python3.8/site-packages/rembg/u2net/detect.py", line 83, in load_model download_file_from_google_drive( File "/Users/apple/.pyenv/versions/3.8.6/lib/python3.8/site-packages/rembg/u2net/detect.py", line 28, in download_file_from_google_drive response = session.get(URL, params={"id": id}, stream=True) File "/Users/apple/.pyenv/versions/3.8.6/lib/python3.8/site-packages/requests/sessions.py", line 543, in get return self.request('GET', url, **kwargs) File "/Users/apple/.pyenv/versions/3.8.6/lib/python3.8/site-packages/requests/sessions.py", line 530, in request resp = self.send(prep, **send_kwargs) File "/Users/apple/.pyenv/versions/3.8.6/lib/python3.8/site-packages/requests/sessions.py", line 643, in send r = adapter.send(request, **kwargs) File "/Users/apple/.pyenv/versions/3.8.6/lib/python3.8/site-packages/requests/adapters.py", line 516, in send raise ConnectionError(e, request=request) requests.exceptions.ConnectionError: HTTPSConnectionPool(host='docs.google.com', port=443): Max retries exceeded with url: /uc?export=download&id=1ao1ovG1Qtx4b7EoskHXmi2E9rp5CHLcZ (Caused by NewConnectionError('<urllib3.connection.HTTPSConnection object at 0x136a4b460>: Failed to establish a new connection: [Errno 60] Operation timed out'))

    opened by hallywang 13
  • [BUG] [ONNXRuntimeError] : 3 : NO_SUCHFILE : Load model from /root/.u2net/u2net.onnx failed:Load model /root/.u2net/u2net.onnx failed. File doesn't exist

    [BUG] [ONNXRuntimeError] : 3 : NO_SUCHFILE : Load model from /root/.u2net/u2net.onnx failed:Load model /root/.u2net/u2net.onnx failed. File doesn't exist

    Describe the bug Access denied with the following error:

    Too many users have viewed or downloaded this file recently. Please
    try accessing the file again later. If the file you are trying to
    access is particularly large or is shared with many people, it may
    take up to 24 hours to be able to view or download the file. If you
    still can't access a file after 24 hours, contact your domain
    administrator. 
    

    You may still be able to access the file from the browser:

     https://drive.google.com/uc?id=1tCU5MM1LhRgGou5OpmpjBQbSrYIUoYab 
    

    To Reproduce Steps to reproduce the behavior: from rembg import remove from PIL import Image for input_path in glob.glob('/content/multi_class_input/*.jpg'): output_path = input_path.replace('input','output') input = Image.open(input_path) output = remove(input) output.save(output_path)

    Expected behavior output foreground png

    Images Input images to reproduce.

    OS Version: iOS 22

    Rembg version: v2.0.21

    Additional context Add any other context about the problem here.

    bug 
    opened by Sahar-DataScience 10
  • [BUG] get dependency versioning conflict when trying to install for gpu

    [BUG] get dependency versioning conflict when trying to install for gpu

    Describe the bug When trying to run pip install rembg[gpu] I get

    ERROR: Cannot install rembg[gpu]==2.0.24 and rembg[gpu]==2.0.25 because these package versions have conflicting dependencies.
    
    The conflict is caused by:
        rembg[gpu] 2.0.25 depends on onnxruntime-gpu==1.12.1; extra == "gpu"
        rembg[gpu] 2.0.24 depends on onnxruntime-gpu==1.12.1; extra == "gpu"
    
    To fix this you could try to:
    1. loosen the range of package versions you've specified
    2. remove package versions to allow pip attempt to solve the dependency conflict
    

    To Reproduce python version 3.10.6 pip version 22.2.2 using venv

    run pip install rembg[gpu] get

      Using cached rembg-2.0.25-py3-none-any.whl (12 kB)
    Collecting scikit-image==0.19.3
      Using cached scikit_image-0.19.3-cp310-cp310-macosx_12_0_arm64.whl (12.5 MB)
    Collecting numpy==1.21.6
      Using cached numpy-1.21.6-cp310-cp310-macosx_11_0_arm64.whl (12.4 MB)
    Collecting watchdog==2.1.9
      Using cached watchdog-2.1.9-cp310-cp310-macosx_11_0_arm64.whl (88 kB)
    Collecting aiohttp==3.8.1
      Using cached aiohttp-3.8.1-cp310-cp310-macosx_11_0_arm64.whl (552 kB)
    Collecting click==8.1.3
      Using cached click-8.1.3-py3-none-any.whl (96 kB)
    Collecting gdown==4.5.1
      Using cached gdown-4.5.1.tar.gz (14 kB)
      Installing build dependencies ... done
      Getting requirements to build wheel ... done
      Preparing metadata (pyproject.toml) ... done
    Collecting tqdm==4.64.0
      Using cached tqdm-4.64.0-py2.py3-none-any.whl (78 kB)
    Collecting asyncer==0.0.1
      Using cached asyncer-0.0.1-py3-none-any.whl (8.1 kB)
    Collecting opencv-python-headless==4.6.0.66
      Using cached opencv_python_headless-4.6.0.66-cp37-abi3-macosx_11_0_arm64.whl (30.0 MB)
    Collecting python-multipart==0.0.5
      Using cached python-multipart-0.0.5.tar.gz (32 kB)
      Preparing metadata (setup.py) ... done
    Collecting scipy==1.7.3
      Using cached scipy-1.7.3-1-cp310-cp310-macosx_12_0_arm64.whl (27.0 MB)
    Collecting imagehash==4.2.1
      Using cached ImageHash-4.2.1.tar.gz (812 kB)
      Preparing metadata (setup.py) ... done
    Collecting fastapi==0.80.0
      Using cached fastapi-0.80.0-py3-none-any.whl (54 kB)
    Collecting pillow==9.2.0
      Using cached Pillow-9.2.0-cp310-cp310-macosx_11_0_arm64.whl (2.8 MB)
    Collecting pymatting==1.1.8
      Using cached PyMatting-1.1.8-py3-none-any.whl (47 kB)
    Collecting uvicorn==0.18.3
      Using cached uvicorn-0.18.3-py3-none-any.whl (57 kB)
    Collecting filetype==1.1.0
      Using cached filetype-1.1.0-py2.py3-none-any.whl (17 kB)
    Collecting onnxruntime==1.12.1
      Using cached onnxruntime-1.12.1-cp310-cp310-macosx_11_0_arm64.whl (5.3 MB)
    Collecting rembg[gpu]
      Using cached rembg-2.0.24-py3-none-any.whl (12 kB)
    ERROR: Cannot install rembg[gpu]==2.0.24 and rembg[gpu]==2.0.25 because these package versions have conflicting dependencies.
    
    The conflict is caused by:
        rembg[gpu] 2.0.25 depends on onnxruntime-gpu==1.12.1; extra == "gpu"
        rembg[gpu] 2.0.24 depends on onnxruntime-gpu==1.12.1; extra == "gpu"
    
    To fix this you could try to:
    1. loosen the range of package versions you've specified
    2. remove package versions to allow pip attempt to solve the dependency conflict
    
    ERROR: ResolutionImpossible: for help visit https://pip.pypa.io/en/latest/topics/dependency-resolution/#dealing-with-dependency-conflicts
    

    Expected behavior should not have a versioning conflict

    Images Input images to reproduce.

    OS Version: MacOS 12.5.1

    Rembg version: v2.0.25

    bug 
    opened by DanielNill 10
  • sudo: rembg:command not found

    sudo: rembg:command not found

    What a wonderful work! I am sorry to bother you,but I have a question in "sudo: rembg:command not found". I have installed rembg,but when I use "rembg -o /home/zc/transformed.png /home/zc/PycharmProjects/pythonProject/modeltest.png",nothing happened.What should I do?How can I operate?

    I would very appreciate if you could help me. Thank you!

    opened by tks-reply 9
  • How to convert custom .pth Model to .onnx?

    How to convert custom .pth Model to .onnx?

    Hey, first of all thanks for sharing your great work!

    As described in the docs I trained a custom model based on the U²Net architecture to remove specific backgrounds and the results were fine but it seems like you cut off custom model support in 3b18bad8587016011fc1ea27d229213ab173a31b. Are you planing to add this again in future? Could you please give an insight how you converted the u2net .pth-models to the .onnx ones?

    Thanks!

    opened by endh1337 8
  • Upgrade torchvision version

    Upgrade torchvision version

    I got an error for installing rembg

    ERROR: Could not find a version that satisfies the requirement torchvision==0.8.1 (from rembg) (from versions: 0.1.6, 0.1.7, 0.1.8, 0.1.9, 0.2.0, 0.2.1, 0.2.2, 0.2.2.post2, 0.2.2.post3, 0.5.0) ERROR: No matching distribution found for torchvision==0.8.1 (from rembg)

    opened by ibrahimnsu15 8
  • Error when using alpha mating

    Error when using alpha mating

    When I try to use alpha mating on a image it throws following error message:

    image

    According documentation it should work well.

    Installation over pip3: Python 3.8.10 pip3 20.0.2 ubuntu 20.04

    opened by a-tonchev 7
  • Install error

    Install error

    Hi, Im running python 3.8.0 and when I try to install I get the below error, I have updated pip and wheel. I have tried locating the log files but they get deleted soon as the attempt fails so I'm unable to open them. I'm on Windows 10

    `C:\Users{user}>pip install rembg==2.0.30 Collecting rembg==2.0.30 Using cached rembg-2.0.30-py3-none-any.whl (13 kB) Collecting click~=8.1.3 Using cached click-8.1.3-py3-none-any.whl (96 kB) Collecting pillow~=9.3.0 Using cached Pillow-9.3.0-cp38-cp38-win32.whl (2.2 MB) Collecting pooch~=1.6.0 Using cached pooch-1.6.0-py3-none-any.whl (56 kB) Collecting uvicorn~=0.20.0 Using cached uvicorn-0.20.0-py3-none-any.whl (56 kB) Collecting numpy~=1.23.5 Using cached numpy-1.23.5-cp38-cp38-win32.whl (12.2 MB) Collecting fastapi~=0.87.0 Using cached fastapi-0.87.0-py3-none-any.whl (55 kB) Collecting watchdog~=2.1.9 Using cached watchdog-2.1.9-py3-none-win32.whl (78 kB) Collecting scikit-image~=0.19.3 Using cached scikit_image-0.19.3-cp38-cp38-win32.whl (11.3 MB) Collecting onnxruntime~=1.13.1 Using cached onnxruntime-1.13.1-cp38-cp38-win32.whl (5.1 MB) Collecting python-multipart~=0.0.5 Using cached python-multipart-0.0.5.tar.gz (32 kB) Preparing metadata (setup.py) ... done Collecting opencv-python-headless~=4.6.0.66 Using cached opencv_python_headless-4.6.0.66-cp36-abi3-win32.whl (26.1 MB) Collecting tqdm~=4.64.1 Using cached tqdm-4.64.1-py2.py3-none-any.whl (78 kB) Collecting scipy~=1.9.3 Using cached scipy-1.9.3.tar.gz (42.1 MB) Installing build dependencies ... done Getting requirements to build wheel ... done Installing backend dependencies ... done Preparing metadata (pyproject.toml) ... error error: subprocess-exited-with-error

    × Preparing metadata (pyproject.toml) did not run successfully. │ exit code: 1 ╰─> [21 lines of output] + meson setup --prefix=c:\users{user}\appdata\local\programs\python\python38-32 C:\Users{user}\AppData\Local\Temp\pip-install-huoo9sjr\scipy_32a0cf31ae834d2187aa93ebc5e60a97 C:\Users{user}\AppData\Local\Temp\pip-install-huoo9sjr\scipy_32a0cf31ae834d2187aa93ebc5e60a97.mesonpy-l7t23cq7\build --native-file=C:\Users{user}\AppData\Local\Temp\pip-install-huoo9sjr\scipy_32a0cf31ae834d2187aa93ebc5e60a97.mesonpy-native-file.ini -Ddebug=false -Doptimization=2 The Meson build system Version: 1.0.0 Source dir: C:\Users{user}\AppData\Local\Temp\pip-install-huoo9sjr\scipy_32a0cf31ae834d2187aa93ebc5e60a97 Build dir: C:\Users{user}\AppData\Local\Temp\pip-install-huoo9sjr\scipy_32a0cf31ae834d2187aa93ebc5e60a97.mesonpy-l7t23cq7\build Build type: native build Project name: SciPy Project version: 1.9.3 WARNING: Failed to activate VS environment: Could not find C:\Program Files (x86)\Microsoft Visual Studio\Installer\vswhere.exe

      ..\..\meson.build:1:0: ERROR: Unknown compiler(s): [['icl'], ['cl'], ['cc'], ['gcc'], ['clang'], ['clang-cl'], ['pgcc']]
      The following exception(s) were encountered:
      Running `icl ""` gave "[WinError 2] The system cannot find the file specified"
      Running `cl /?` gave "[WinError 2] The system cannot find the file specified"
      Running `cc --version` gave "[WinError 2] The system cannot find the file specified"
      Running `gcc --version` gave "[WinError 2] The system cannot find the file specified"
      Running `clang --version` gave "[WinError 2] The system cannot find the file specified"
      Running `clang-cl /?` gave "[WinError 2] The system cannot find the file specified"
      Running `pgcc --version` gave "[WinError 2] The system cannot find the file specified"
    
      A full log can be found at C:\Users\{user}\AppData\Local\Temp\pip-install-huoo9sjr\scipy_32a0cf31ae834d2187aa93ebc5e60a97\.mesonpy-l7t23cq7\build\meson-logs\meson-log.txt
      [end of output]
    

    note: This error originates from a subprocess, and is likely not a problem with pip. error: metadata-generation-failed

    × Encountered error while generating package metadata. ╰─> See above for output.

    note: This is an issue with the package mentioned above, not pip. hint: See above for details.`

    opened by Digby26 1
  • Background image removal using pth / converting from .pth to .onnx

    Background image removal using pth / converting from .pth to .onnx

    Hi there!

    I was using rembg to remove the backgrounds from many images at once, which I got to work using u2net.onnx as you provided in rembg. These images are images of clothing. However, on images with white clothing, the u2net and u2netp models leave large shadows behind each of the items of clothing, and leave gaps in between the item where it was even brighter. In addition, it fails to remove between hair.

    I did some research and found this model on the u2net page: https://github.com/dennisbappert/u-2-net-portrait This seems to be what I need, but the download page gives a .pth model.

    My two questions are: how can I adjust the loss threshold to account for white clothes, and how can I convert this model from .pth to .onnx and use it within my code so that I can see if it works better than u2net?

    Thanks in advance!

    opened by KDubZz 0
  • Failed to create TensorrtExecutionProvider (CUDA) #183

    Failed to create TensorrtExecutionProvider (CUDA) #183

    Describe the bug I run remb as part of a container on a lamdalabs instance, so I have access to an a100.

    To Reproduce My install setup includes apt-get update && apt-get install libgl1 -y && apt-get install libglib2.0-0 -y conda install cudatoolkit

    and I also have a docker base image with pytorch 1.13 and cuda 11.6, so those are also given I install remb with in my requirements with rembg[gpu] @ git+https://github.com/samiede/rembg.git

    Expected behavior

    I run rembg and can do so on GPU

    Rembg version: v2.0.21

    What actually happens I get

    2022-12-19 13:17:56.146554627 [W:onnxruntime:Default, onnxruntime_pybind_state.cc:552 CreateExecutionProviderInstance] Failed to create TensorrtExecutionProvider. Please reference https://onnxruntime.ai/docs/execution-providers/TensorRT-ExecutionProvider.html#requirements to ensure all dependencies are met.
    

    and the execution runs on the CPU

    bug 
    opened by samiede 0
  • Non-Programmer needs help - ONNXRuntimeError

    Non-Programmer needs help - ONNXRuntimeError

    I am on WIN 10 and Python 3.9 is installed. pip install rembg[gpu] - no errors The Models Files are all in .u2net directory and the onnxruntime_providers_tensorrt.dll is in the right directory

    `C:\Users\MyName>rembg i E:\haare.jpg E:\haare-maske.jpg Traceback (most recent call last): File "C:\Users\MyName\AppData\Local\Programs\Python\Python39\lib\runpy.py", line 197, in _run_module_as_main return _run_code(code, main_globals, None, File "C:\Users\MyName\AppData\Local\Programs\Python\Python39\lib\runpy.py", line 87, in run_code exec(code, run_globals) File "C:\Users\MyName\AppData\Local\Programs\Python\Python39\Scripts\rembg.exe_main.py", line 7, in File "C:\Users\MyName\AppData\Local\Programs\Python\Python39\lib\site-packages\click\core.py", line 1130, in call return self.main(*args, **kwargs) File "C:\Users\MyName\AppData\Local\Programs\Python\Python39\lib\site-packages\click\core.py", line 1055, in main rv = self.invoke(ctx) File "C:\Users\MyName\AppData\Local\Programs\Python\Python39\lib\site-packages\click\core.py", line 1657, in invoke return _process_result(sub_ctx.command.invoke(sub_ctx)) File "C:\Users\MyName\AppData\Local\Programs\Python\Python39\lib\site-packages\click\core.py", line 1404, in invoke return ctx.invoke(self.callback, **ctx.params) File "C:\Users\MyName\AppData\Local\Programs\Python\Python39\lib\site-packages\click\core.py", line 760, in invoke return __callback(*args, **kwargs) File "C:\Users\MyName\AppData\Local\Programs\Python\Python39\lib\site-packages\rembg\cli.py", line 97, in i output.write(remove(input.read(), session=new_session(model), **kwargs)) File "C:\Users\MyName\AppData\Local\Programs\Python\Python39\lib\site-packages\rembg\session_factory.py", line 66, in new_session ort.InferenceSession( File "C:\Users\MyName\AppData\Local\Programs\Python\Python39\lib\site-packages\onnxruntime\capi\onnxruntime_inference_collection.py", line 347, in init self._create_inference_session(providers, provider_options, disabled_optimizers) File "C:\Users\MyName\AppData\Local\Programs\Python\Python39\lib\site-packages\onnxruntime\capi\onnxruntime_inference_collection.py", line 395, in _create_inference_session sess.initialize_session(providers, provider_options, disabled_optimizers) RuntimeError: D:\a_work\1\s\onnxruntime\core\session\provider_bridge_ort.cc:1029 onnxruntime::ProviderLibrary::Get [ONNXRuntimeError] : 1 : FAIL : LoadLibrary failed with error 126 "" when trying to load "C:\Users\MyName\AppData\Local\Programs\Python\Python39\lib\site-packages\onnxruntime\capi\onnxruntime_providers_tensorrt.dll"

    C:\Users\MyName> `

    A "small" Tip or an installation guide for dummies would be fantastic!

    Many greetings Hans

    OS Version: WIN 10

    Rembg version: v2.0.21

    Python 3.9

    Nvidia GTX 1070 Latest Studio Driver

    bug 
    opened by hansnolte 0
  • [BUG] - http server return 422 Unprocessable Entity

    [BUG] - http server return 422 Unprocessable Entity

    Describe the bug I would like to use the server as you have in your first tuto video (I guess). Maybe I miss something or do not understand something. Can you help ?

    To Reproduce

    rembg is working properly with i and p on my machine. If I run the server:

    rembg s
    

    get the output:

    INFO:     Started server process [29484]
    INFO:     Waiting for application startup.
    INFO:     Application startup complete.
    INFO:     Uvicorn running on http://0.0.0.0:5000 (Press CTRL+C to quit)
    INFO:     127.0.0.1:54521 - "GET / HTTP/1.1" 422 Unprocessable Entity
    

    If I open http://127.0.0.1:5000/ or http://localhost:5000/ I see this line only:

    {"detail":[{"loc":["query","url"],"msg":"field required","type":"value_error.missing"}]}

    The http://localhost:5000/docs seems to work

    INFO:     127.0.0.1:54643 - "GET /docs HTTP/1.1" 200 OK
    INFO:     127.0.0.1:54643 - "GET /openapi.json HTTP/1.1" 200 OK
    

    Should be able to change the parameters on this page ? Because I cannot.

    Expected behavior I expect to have a site like yours:

    2022-12-16 14-25-58

    OS Version: Windows 10

    Rembg version: rembg 2.0.29

    bug 
    opened by DGrv 2
  • How to fix installation failure if script was previously installed on MacOS Ventura M2

    How to fix installation failure if script was previously installed on MacOS Ventura M2

          Using cached rembg-2.0.24-py3-none-any.whl (12 kB)
      ERROR: Cannot install rembg==2.0.24 and rembg==2.0.25 because these package versions have conflicting dependencies.
      
      The conflict is caused by:
          rembg 2.0.25 depends on numpy==1.21.6
          rembg 2.0.24 depends on numpy==1.21.6
      
      To fix this you could try to:
      1. loosen the range of package versions you've specified
      2. remove package versions to allow pip attempt to solve the dependency conflict
      
      ERROR: ResolutionImpossible: for help visit https://pip.pypa.io/en/latest/topics/dependency-resolution/#dealing-with-dependency-conflicts
    
    bug 
    opened by inglesuniversal 1
Releases(v2.0.30)
Owner
Daniel Gatis
Daniel Gatis
A GUI-based (PyQt5) tool used to design 2D linkage mechanism.

Pyslvs-UI A GUI-based (PyQt5) tool used to design 2D linkage mechanism. Planar Linkages Simulation Python-Solvespace: Kernel from Solvespace with Cyth

Yuan Chang 141 Dec 13, 2022
Extracts dominating colors from an image and presents them as a palette.

ColorPalette A simple web app to extract dominant colors from an image. Demo Live View it live at : https://colorpalettedemo.herokuapp.com/ You can de

Mayank Nader 214 Dec 29, 2022
CropImage is a simple toolkit for image cropping, detecting and cropping main body from pictures.

CropImage is a simple toolkit for image cropping, detecting and cropping main body from pictures. Support face and saliency detection.

Haofan Wang 15 Dec 22, 2022
Make your master artistic punk avatar through machine learning world famous paintings

Master-art-punk Make your master artistic punk avatar through machine learning world famous paintings. 通过机器学习世界名画制作属于你的大师级艺术朋克头像 Nowadays, NFT is beco

蒋虎成 23 Jan 04, 2022
A ray tracing render implemented using Taichi language.

A ray tracing render implemented using Taichi language.

Mingrui Zhang 45 Oct 23, 2022
Semi-hash-based Image Generator

pixel-planet Semi-hash-based Image Generator Utilizable for NFTs Generation Process Input is salted and hashed Colors (background, planet, stars) are

Bill Ni 3 Sep 01, 2022
HyperBlend is a new type of hyperspectral image simulator based on Blender.

HyperBlend version 0.1.0 This is the HyperBlend leaf spectra simulator developed in Spectral Laboratory of University of Jyväskylä. You can use and mo

SILMAE 2 Jun 20, 2022
Nutrify - take a photo of food and learn about it

Nutrify - take a photo of food and learn about it Work in progress. To make this a thing, we're going to need lots of food images... Start uploading y

Daniel Bourke 93 Dec 30, 2022
Image Compression GUI APP Python: PyQt5

Image Compression GUI APP Image Compression GUI APP Python: PyQt5 Use : f5 or debug or simply run it on your ids(vscode , pycham, anaconda etc.) socia

Sourabh Dhalia 1 May 21, 2022
Draw a torus passing through three given points.

PyTorusThreePoints Draw a torus passing through three given points. Usage import numpy as np import pyvista as pv from torus_three_points.main import

2 Nov 19, 2021
MyPaint is a simple drawing and painting program that works well with Wacom-style graphics tablets.

MyPaint A fast and dead-simple painting app for artists Features Infinite canvas Extremely configurable brushes Distraction-free fullscreen mode Exten

MyPaint 2.3k Jan 01, 2023
Remove Background from Image With Python

Install Library pypi $ pip3 install xremovebg

krypton 4 May 26, 2022
A Python3 library to generate dynamic SVGs

The Python library for generating dynamic SVGs using Python3

1 Dec 23, 2021
Conversion of Image, video, text into ASCII format

asciju Python package that converts image to ascii Free software: MIT license

Aju Tamang 11 Aug 22, 2022
This script is for photographers to do timeslice with one click.

One Click TimeSlice Tool What is this for This is for photographers who want to create TimeSlice pictures without installing PS plugins. Before using

Xi Zhao 13 Sep 23, 2022
ImageStrike是一款用于CTF中图片隐写的综合利用工具

🎈 简介 ImageStrike是一款使用PyQT5开发,用于CTF中图片隐写的综合利用工具

zR00t1 133 Dec 27, 2022
Fast batch image resizer and rotator for JPEG and PNG images.

imgp is a command line image resizer and rotator for JPEG and PNG images.

Terminator X 921 Dec 25, 2022
Generates images of calendar month tables and can paste them onto suitable photos.

📆 calendizer README Generates images of calendar month tables and can paste them onto suitable photos. A quick way to make your own calendar for prin

Sean Ryan 2 Dec 14, 2022
Labelme is a graphical image annotation tool, It is written in Python and uses Qt for its graphical interface

Image Polygonal Annotation with Python (polygon, rectangle, circle, line, point and image-level flag annotation).

Kentaro Wada 9.6k Jan 09, 2023
Graphical tool to make photo collage posters

PhotoCollage Graphical tool to make photo collage posters PhotoCollage allows you to create photo collage posters. It assembles the input photographs

Adrien Vergé 350 Jan 02, 2023