pedropro / TACO

🌮 Trash Annotations in Context Dataset Toolkit
http://tacodataset.org
MIT License
603 stars 201 forks source link

OSError: cannot write mode RGBA as JPEG #52

Open rgaufman opened 1 year ago

rgaufman commented 1 year ago

I'm trying to download the unofficial training set and getting this:

$ python3 download.py --dataset_path ./data/annotations_unofficial.json
Note. If for any reason the connection is broken. Just call me again and I will start where I left.
Traceback (most recent call last):......] - 26/3831
  File "/opt/homebrew/lib/python3.11/site-packages/PIL/JpegImagePlugin.py", line 640, in _save
    rawmode = RAWMODE[im.mode]
              ~~~~~~~^^^^^^^^^
KeyError: 'RGBA'

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/Users/hackeron/Garbage-Detection/faster-rcnn/TACO/download.py", line 49, in <module>
    img.save(file_path)
  File "/opt/homebrew/lib/python3.11/site-packages/PIL/Image.py", line 2432, in save
    save_handler(self, fp, filename)
  File "/opt/homebrew/lib/python3.11/site-packages/PIL/JpegImagePlugin.py", line 643, in _save
    raise OSError(msg) from e
OSError: cannot write mode RGBA as JPEG

As a temporary workaround I edited JpegImagePlugin.py to ignore RGBA images:

def _save(im, fp, filename):
    if im.width == 0 or im.height == 0:
        msg = "cannot write empty image as JPEG"
        raise ValueError(msg)

    try:
        if im.mode == 'RGBA':
            return
        rawmode = RAWMODE[im.mode]
Fsanchess commented 8 months ago

I tried to, it works thanks