nadermx / backgroundremover

Background Remover lets you Remove Background from images and video using AI with a simple command line interface that is free and open source.
https://www.backgroundremoverai.com
MIT License
6.46k stars 538 forks source link

Error: Trimap did not contain foreground values #4

Closed byteshiva closed 2 years ago

byteshiva commented 2 years ago

failing out while removing background image

uname -a 
5.8.0-3-amd64 #1 SMP Debian 5.8.14-1~mx19+2 (2020-10-25) x86_64 GNU/Linux
backgroundremover -i ./final_sign.jpeg -a  -ae 15 -o final_sig4.png 

final_sig4.png
[W NNPACK.cpp:80] Could not initialize NNPACK! Reason: Unsupported hardware.
Traceback (most recent call last):
  File "/home/xyz/.asdf/installs/python/3.8.0/bin/backgroundremover", line 8, in <module>
    sys.exit(main())
  File "/home/xyz/.asdf/installs/python/3.8.0/lib/python3.8/site-packages/backgroundremover/cmd/cli.py", line 241, in main
    remove(
  File "/home/xyz/.asdf/installs/python/3.8.0/lib/python3.8/site-packages/backgroundremover/bg.py", line 187, in remove
    cutout = alpha_matting_cutout(
  File "/home/xyz/.asdf/installs/python/3.8.0/lib/python3.8/site-packages/backgroundremover/bg.py", line 147, in alpha_matting_cutout
    alpha = estimate_alpha_cf(img_normalized, trimap_normalized)
  File "/home/xyz/.asdf/installs/python/3.8.0/lib/python3.8/site-packages/pymatting/alpha/estimate_alpha_cf.py", line 51, in estimate_alpha_cf
    is_fg, is_bg, is_known, is_unknown = trimap_split(trimap)
  File "/home/xyz/.asdf/installs/python/3.8.0/lib/python3.8/site-packages/pymatting/util/util.py", line 495, in trimap_split
    raise ValueError(
ValueError: Trimap did not contain foreground values (values >= 0.900000)
nadermx commented 2 years ago

Does this work without the -a -ae 15, so backgroundremover -i ./final_sign.jpeg -o final_sig4.png Did you install python3.8-dev?

byteshiva commented 2 years ago

I'm unable to get right python3.8-dev for mxlinux? Also how about delivering nadermx / backgroundremover in Dockerfile.

https://pkgs.org/search/?q=python3.8-dev

byteshiva commented 2 years ago

Does this work without the -a -ae 15, so backgroundremover -i ./final_sign.jpeg -o final_sig4.png Did you install python3.8-dev?

backgroundremover -i ./final_sign.jpeg -o final_sig4.png 

RuntimeError: module compiled against API version 0xe but this version of numpy is 0xd
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 "/home/xyz/.asdf/installs/python/3.8.0/lib/python3.8/site-packages/pymatting_aot/cc.py", line 36, in <module>
    import pymatting_aot.aot
ImportError: numpy.core.multiarray failed to import

During handling of the above exception, another exception occurred:

RuntimeError: module compiled against API version 0xe but this version of numpy is 0xd
Traceback (most recent call last):
  File "/home/xyz/.asdf/installs/python/3.8.0/lib/python3.8/site-packages/pymatting_aot/cc.py", line 36, in <module>
    import pymatting_aot.aot
ImportError: numpy.core.multiarray failed to import

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/xyz/.asdf/installs/python/3.8.0/bin/backgroundremover", line 5, in <module>
    from backgroundremover.cmd.cli import main
  File "/home/xyz/.asdf/installs/python/3.8.0/lib/python3.8/site-packages/backgroundremover/cmd/cli.py", line 5, in <module>
    from .. import utilities
  File "/home/xyz/.asdf/installs/python/3.8.0/lib/python3.8/site-packages/backgroundremover/utilities.py", line 10, in <module>
    from .bg import DEVICE, Net, iter_frames, remove_many
  File "/home/xyz/.asdf/installs/python/3.8.0/lib/python3.8/site-packages/backgroundremover/bg.py", line 6, in <module>
    from pymatting.alpha.estimate_alpha_cf import estimate_alpha_cf
  File "/home/xyz/.asdf/installs/python/3.8.0/lib/python3.8/site-packages/pymatting/__init__.py", line 2, in <module>
    import pymatting_aot.cc
  File "/home/xyz/.asdf/installs/python/3.8.0/lib/python3.8/site-packages/pymatting_aot/cc.py", line 56, in <module>
    import pymatting_aot.aot
ImportError: numpy.core.multiarray failed to import
nadermx commented 2 years ago

I haven't thought about docker as I don't use it, but over some time I could try and figure it out. I'm seeing this stackoverflow question, https://stackoverflow.com/questions/20518632/importerror-numpy-core-multiarray-failed-to-import

one of the soltuions says

pip install --upgrade pip
pip install -U numpy

It seems it might be a version of either pip or numpy, perhaps try some of those solutions? I've only had the time to test this on ubunutu.

byteshiva commented 2 years ago

I think its python virtualenv might reduce the dependency errors.

backgroundremover -i ./final_sign.jpeg -o final_sig4.png  << this works now.

but when these attributes -a -ae 15 are added it's throwing error.

nadermx commented 2 years ago

The same error?

byteshiva commented 2 years ago

Please note I had installed rembg and other similar tools, Maybe it had some conflicting libraries. Now it works fine.

$ backgroundremover -i ./tm1.png -a -ae 15 -o oyt.png 
oyt.png
[W NNPACK.cpp:80] Could not initialize NNPACK! Reason: Unsupported hardware.
PERFORMANCE WARNING:
Thresholded incomplete Cholesky decomposition failed due to insufficient positive-definiteness of matrix A with parameters:
    discard_threshold = 1.000000e-04
    shift = 0.000000e+00
Try decreasing discard_threshold or start with a larger shift
$ backgroundremover -i ./final_sign.jpeg  -ae 15 -o final_sign_out.png
final_sign_out.png
[W NNPACK.cpp:80] Could not initialize NNPACK! Reason: Unsupported hardware.
nadermx commented 2 years ago

Awesome, glad to hear. Yeah virtual enviroment is key for most python projects. I may update the readme to install it in it's own virtual env, just incase. I'll consider this issue closed.