Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OSError: cannot write mode RGBA as JPEG #52

Open
rgaufman opened this issue May 10, 2023 · 1 comment
Open

OSError: cannot write mode RGBA as JPEG #52

rgaufman opened this issue May 10, 2023 · 1 comment

Comments

@rgaufman
Copy link

rgaufman commented May 10, 2023

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
Copy link

I tried to, it works thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants