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
Paper backup of files using QR codes

Generate paper backups for Linux. Currently command-linux Linux only. Takes any file, and outputs a "paper backup": a printable black-and-white pdf fu

Zachary Vance 27 Dec 28, 2022
【萝莉图片算法】高损图像压缩算法!?

【萝莉图片算法】高损图像压缩算法!? 我又发明出新算法了! 这次我发明的是新型高损图像压缩算法——萝莉图片算法!为什么是萝莉图片,这是因为它是使动用法,让图片变小所以是萝莉图片,大家一定要学好语文哦! 压缩效果 太神奇了!压缩率竟然高达99.97%! 与常见压缩算法对比 在图片最终大小为1KB的情况

黄巍 49 Oct 17, 2022
A sketch like(?) effect for images

lineArt A sketch like(?) effect for images How to run main.py [filename] [option {1,2}] option 1 retains colour option 2 gives gray image #results ori

1 Oct 28, 2021
Glyphtracer is an app for converting images of letters to a font

Glyphtracer takes an image that contains pictures of several letters. It recognizes all them and lets the user tag each letter to a Unicode code point. It then converts the images to vector form and

Jussi Pakkanen 38 Dec 24, 2022
A drop-in replacement for django's ImageField that provides a flexible, intuitive and easily-extensible interface for quickly creating new images from the one assigned to the field.

django-versatileimagefield A drop-in replacement for django's ImageField that provides a flexible, intuitive and easily-extensible interface for creat

Jonathan Ellenberger 490 Dec 13, 2022
A utility for quickly cropping large collections of images.

Crop Tool A utility for quickly cropping large collections of images. Inspired by Derrick Schultz's dataset-tools. Setup It's suggested that you use A

dusk (they/them) 6 Nov 14, 2021
A suite of useful tools based on 3D interactivity in napari

napari-threedee A suite of useful tools based on 3D interactivity in napari This napari plugin was generated with Cookiecutter using @napari's cookiec

11 Dec 14, 2022
Hacking github graph with a easy python script

Hacking-Github-Graph Hacking github graph with a easy python script Requirements git latest version installed. A text editor (eg: vs code, sublime tex

SENPAI LEGEND 1 Nov 01, 2021
Pixel Brush Processing Unit

Pixel Brush Processing Unit The Pixel Brush Processing Unit (PBPU for short) is a simple 4-Bit CPU I designed in Logisim while I was still in school a

Pixel Brush 2 Nov 03, 2022
A functional and efficient python implementation of the 3D version of Maxwell's equations

py-maxwell-fdfd Solving Maxwell's equations via A python implementation of the 3D curl-curl E-field equations. This code contains additional work to e

Nathan Zhao 12 Dec 11, 2022
🖼️ Draw Images or GIFs in your terminal

Drawitor Draw Images/GIFs in your terminal. Install pip install drawitor CLI Tool drawitor cat_dancing.gif Library The library is written in a simple

Eliaz Bobadilla 7 Dec 15, 2022
Combinatorial image generator for generative NFT art.

ImageGen Stitches multiple image layers together into one image. Run usage: stitch.py [-h] backgrounds_dir dinos_dir traits_dir texture_file

Dinosols NFT 19 Sep 16, 2022
LGVL helper script to batch and convert with lvgl offline image converter

script to batch and convert with lvgl offline image converter

Yohann 1 Oct 05, 2022
Design custom QR codes with this web app!

My-QR.Art This web app lets users design their own QR codes to any domain. It can be acessed on my-qr.art. You can find some more background info abou

Marien Raat 406 Dec 20, 2022
SGTL - Spectral Graph Theory Library

SGTL - Spectral Graph Theory Library SGTL is a python library of spectral graph theory methods. The library is still very new and so there are many fe

Peter Macgregor 6 Oct 01, 2022
This is a python project which detects color of an image when you double click on it.

This is a python project which detects color of an image when you double click on it. You have to press ESC button to close the pop-up Image window. There are mainly two library CV2 and Pandas that a

Yashwant Kumar Singh 0 Aug 16, 2022
Photini - A free, easy to use, digital photograph metadata (Exif, IPTC, XMP) editing application for Linux, Windows and MacOS.

A free, easy to use, digital photograph metadata (Exif, IPTC, XMP) editing application for Linux, Windows and MacOS. "Metadata" is said to mea

Jim Easterbrook 120 Dec 20, 2022
image-processing exercises.

image_processing Assignment 21 Checkered Board Create a chess table using numpy and opencv. view: Color Correction Reverse black and white colors with

Benyamin Zojaji 25 Dec 15, 2022
QR-Generator - An awesome QR Generator to create or customize your QR's

QR Generator An awesome QR Generator to create or customize your QR's! Table of

Tristán 1 Jan 28, 2022
display: a browser-based graphics server

display: a browser-based graphics server Installation Quick Start Usage Development A very lightweight display server for Torch. Best used as a remote

Szymon Jakubczak 205 Oct 17, 2022