pedropro / TACO

🌮 Trash Annotations in Context Dataset Toolkit

Home Page:http://tacodataset.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

OSError: cannot write mode RGBA as JPEG

rgaufman opened this issue · comments

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]

I tried to, it works thanks