labelmeai / labelme

Image Polygonal Annotation with Python (polygon, rectangle, circle, line, point and image-level flag annotation).
https://labelme.io
Other
13.11k stars 3.37k forks source link

Running labelme2coco.py on Rectangle Annotations Sometimes Results in a ValueError in PIL: "y1 must be greater than or equal to y0" #1437

Open baku1101 opened 3 months ago

baku1101 commented 3 months ago

Provide environment information

❯ which python; python --version; python -m pip list | grep labelme
/home/watanabe/work/YOLOX/pyenv/bin/python
Python 3.12.3
labelme                   5.4.1
labelme2coco              0.2.6

What OS are you using?

Arch Linux on WSL2

Describe the Bug

I've partially identified the cause and have been able to proceed with the execution. However, I'd like to inquire about more detailed investigations and better solutions. Below is the error message I encountered during execution:

❯ ./labelme2coco.py val val4coco --labels class.txt 
Creating dataset: val4coco
Generating dataset from: val/PXL_20211110_054923449.json
Traceback (most recent call last):
  File "/home/watanabe/work/YOLOX/datasets/labelme/examples/instance_segmentation/./labelme2coco.py", line 203, in <module>
    main()
  File "/home/watanabe/work/YOLOX/datasets/labelme/examples/instance_segmentation/./labelme2coco.py", line 121, in main
    mask = labelme.utils.shape_to_mask(img.shape[:2], points, shape_type)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/watanabe/work/YOLOX/pyenv/lib/python3.12/site-packages/labelme/utils/shape.py", line 30, in shape_to_mask
    draw.rectangle(xy, outline=1, fill=1)
  File "/home/watanabe/work/YOLOX/pyenv/lib/python3.12/site-packages/PIL/ImageDraw.py", line 316, in rectangle
    self.draw.draw_rectangle(xy, fill, 1)
ValueError: y1 must be greater than or equal to y0

It appears that this issue is caused by the addition of assertions in a recent version update of Pillow. In my environment, Pillow version 10.3.0 did not work, but downgrading to version 9.1 resolved the issue and the behavior was as expected.

❯ pip install pillow 
Requirement already satisfied: pillow in /home/watanabe/work/YOLOX/pyenv/lib/python3.12/site-packages (10.3.0)
pip install pillow==9.1 

Expected Behavior

No response

To Reproduce

No response