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.7k stars 558 forks source link

Intermittently, an image will yield the error: "cannot identify image file" #38

Closed Nantris closed 2 years ago

Nantris commented 2 years ago
Traceback (most recent call last):
  File "/home/me/.local/bin/backgroundremover", line 8, in <module>
    sys.exit(main())
  File "/home/me/.local/lib/python3.10/site-packages/backgroundremover/cmd/cli.py", line 241, in main
    remove(
  File "/home/me/.local/lib/python3.10/site-packages/backgroundremover/bg.py", line 183, in remove
    img = Image.open(io.BytesIO(data)).convert("RGB")
  File "/home/me/.local/lib/python3.10/site-packages/PIL/Image.py", line 2958, in open
    raise UnidentifiedImageError(
PIL.UnidentifiedImageError: cannot identify image file <_io.BytesIO object at 0x7fd279fa6520>

I wonder what could cause this? It's caused by the same set of images on every run (reproducible.) The resulting file size is 0 bytes.

PS: Thanks for sharing this awesome project!

Nantris commented 2 years ago

Example: 20

Admittedly there's not much background to remove here - but I'm trying to do bulk processing so I don't always know the format of the images.

On a related note, is there anything like a configurable confidence threshold or something to prevent outcomes like below?

1

7

2

Nantris commented 2 years ago

Interestingly, backgroundremover.app is able to handle the file without crashing - although it suffers from other problems:

demo

Nantris commented 2 years ago

Adding a border to the images seems to help the algorithm avoid this.