Crash While Using AI Polygons
Erotemic opened this issue · 0 comments
Erotemic commented
Provide environment information
Same env as: #1334
What OS are you using?
Ubuntu 22.04
Describe the Bug
Output I get is:
I was creating a lot of postive and negative anchor points fairly quickly when this crash occurred
MD5 matches: /home/joncrall/.cache/gdown/https-COLON--SLASH--SLASH-github.com-SLASH-wkentaro-SLASH-labelme-SLASH-releases-SLASH-download-SLASH-sam-20230416-SLASH-sam_vit_h_4b8939.quantized.decoder.onnx
Traceback (most recent call last):
File "/home/joncrall/code/labelme/labelme/widgets/canvas.py", line 773, in paintEvent
points = self._ai_model.predict_polygon_from_points(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/joncrall/code/labelme/labelme/ai/models/segment_anything.py", line 64, in predict_polygon_from_points
polygon = _compute_polygon_from_points(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/joncrall/code/labelme/labelme/ai/models/segment_anything.py", line 172, in _compute_polygon_from_points
contour = max(contours, key=_get_contour_length)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
ValueError: max() arg is an empty sequence
Aborted (core dumped)
It looks like there should be some error handling when countours is empty here.
Expected Behavior
Not crashing.
To Reproduce
I wasn't able to reproduce with random clicks. There must have been something peculiar about the particular shape I made when the crash happened. If I can determine the shape that causes it, I will post back with more details. Either way, from the error we can determine that the assumption that the countours list is non-empty does not hold, and error handling should be added to the code at that point.