Error with COCOConveter

Hello, I was using COCOConverter to get annotation and keep getting the same error.
The error message seems like one of the annotations doesn’t have the right bbox value inside.
Is there any way to figure out which one has the issue?
cuz in my project, every data row looks well-annotated and it is almost impossible to figure out the wrong one.

!pip3 install labelbox[data]

from labelbox.data.annotation_types import Label, LabelList, ImageData, Point, ObjectAnnotation, Rectangle, Polygon
from labelbox.data.serialization import COCOConverter
from labelbox import Client

from google.colab import drive
drive.mount('/content/Google')

import json
import shutil
import os
LB_API_KEY = ""
client = Client(api_key=LB_API_KEY)
project = client.get_project('')

labels = project.label_generator()

image_path = './images/'

coco_labels = COCOConverter.serialize_instances(
    labels,
    image_root=image_path,
    ignore_existing_data=True)
/usr/local/lib/python3.7/dist-packages/labelbox/data/annotation_types/classification/classification.py:85: UserWarning: Dropdown classification is deprecated and will be removed in a future release
  warnings.warn("Dropdown classification is deprecated and will be "
35it [00:24,  2.05it/s]/usr/local/lib/python3.7/dist-packages/labelbox/data/serialization/coco/instance_dataset.py:37: ShapelyDeprecationWarning: Iteration over multi-part geometries is deprecated and will be removed in Shapely 2.0. Use the `geoms` property to access the constituent parts of a multi-part geometry.
  np.array(s.exterior.coords).ravel().tolist() for s in shapely
42it [00:27,  2.24it/s]/usr/local/lib/python3.7/dist-packages/labelbox/data/serialization/coco/instance_dataset.py:37: ShapelyDeprecationWarning: Iteration over multi-part geometries is deprecated and will be removed in Shapely 2.0. Use the `geoms` property to access the constituent parts of a multi-part geometry.
  np.array(s.exterior.coords).ravel().tolist() for s in shapely
55it [00:34,  1.83it/s]/usr/local/lib/python3.7/dist-packages/labelbox/data/serialization/coco/instance_dataset.py:37: ShapelyDeprecationWarning: Iteration over multi-part geometries is deprecated and will be removed in Shapely 2.0. Use the `geoms` property to access the constituent parts of a multi-part geometry.
  np.array(s.exterior.coords).ravel().tolist() for s in shapely
65it [00:44,  1.01it/s]/usr/local/lib/python3.7/dist-packages/labelbox/data/serialization/coco/instance_dataset.py:37: ShapelyDeprecationWarning: Iteration over multi-part geometries is deprecated and will be removed in Shapely 2.0. Use the `geoms` property to access the constituent parts of a multi-part geometry.
  np.array(s.exterior.coords).ravel().tolist() for s in shapely
69it [00:46,  1.46it/s]/usr/local/lib/python3.7/dist-packages/labelbox/data/serialization/coco/instance_dataset.py:37: ShapelyDeprecationWarning: Iteration over multi-part geometries is deprecated and will be removed in Shapely 2.0. Use the `geoms` property to access the constituent parts of a multi-part geometry.
  np.array(s.exterior.coords).ravel().tolist() for s in shapely
71it [00:49,  1.05s/it]/usr/local/lib/python3.7/dist-packages/labelbox/data/serialization/coco/instance_dataset.py:37: ShapelyDeprecationWarning: Iteration over multi-part geometries is deprecated and will be removed in Shapely 2.0. Use the `geoms` property to access the constituent parts of a multi-part geometry.
  np.array(s.exterior.coords).ravel().tolist() for s in shapely
112it [01:20,  1.48it/s]/usr/local/lib/python3.7/dist-packages/labelbox/data/serialization/coco/instance_dataset.py:37: ShapelyDeprecationWarning: Iteration over multi-part geometries is deprecated and will be removed in Shapely 2.0. Use the `geoms` property to access the constituent parts of a multi-part geometry.
  np.array(s.exterior.coords).ravel().tolist() for s in shapely
136it [01:36,  4.87it/s]/usr/local/lib/python3.7/dist-packages/labelbox/data/serialization/coco/instance_dataset.py:37: ShapelyDeprecationWarning: Iteration over multi-part geometries is deprecated and will be removed in Shapely 2.0. Use the `geoms` property to access the constituent parts of a multi-part geometry.
  np.array(s.exterior.coords).ravel().tolist() for s in shapely
464it [04:24,  2.55it/s]
---------------------------------------------------------------------------
_RemoteTraceback                          Traceback (most recent call last)
_RemoteTraceback: 
"""
Traceback (most recent call last):
  File "/usr/lib/python3.7/concurrent/futures/process.py", line 239, in _process_worker
    r = call_item.fn(*call_item.args, **call_item.kwargs)
  File "/usr/local/lib/python3.7/dist-packages/labelbox/data/serialization/coco/instance_dataset.py", line 113, in process_label
    categories[annotation.name]))
  File "/usr/local/lib/python3.7/dist-packages/labelbox/data/serialization/coco/instance_dataset.py", line 26, in mask_to_coco_object_annotation
    xmin, ymin, xmax, ymax = shapely.bounds
ValueError: not enough values to unpack (expected 4, got 0)
"""

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

ValueError                                Traceback (most recent call last)
<ipython-input-6-cb6f848644e4> in <module>()
      6     labels,
      7     image_root=image_path,
----> 8     ignore_existing_data=True)

4 frames
/usr/local/lib/python3.7/dist-packages/labelbox/data/serialization/coco/converter.py in serialize_instances(labels, image_root, ignore_existing_data, max_workers)
     59         return CocoInstanceDataset.from_common(labels=labels,
     60                                                image_root=image_root,
---> 61                                                max_workers=max_workers).dict()
     62 
     63     @staticmethod

/usr/local/lib/python3.7/dist-packages/labelbox/data/serialization/coco/instance_dataset.py in from_common(cls, labels, image_root, max_workers)
    145                 ]
    146                 results = [
--> 147                     future.result() for future in tqdm(as_completed(futures))
    148                 ]
    149         else:

/usr/local/lib/python3.7/dist-packages/labelbox/data/serialization/coco/instance_dataset.py in <listcomp>(.0)
    145                 ]
    146                 results = [
--> 147                     future.result() for future in tqdm(as_completed(futures))
    148                 ]
    149         else:

/usr/lib/python3.7/concurrent/futures/_base.py in result(self, timeout)
    426                 raise CancelledError()
    427             elif self._state == FINISHED:
--> 428                 return self.__get_result()
    429 
    430             self._condition.wait(timeout)

/usr/lib/python3.7/concurrent/futures/_base.py in __get_result(self)
    382     def __get_result(self):
    383         if self._exception:
--> 384             raise self._exception
    385         else:
    386             return self._result

ValueError: not enough values to unpack (expected 4, got 0)

And every time I run the block, it shows different errors.

/usr/local/lib/python3.7/dist-packages/labelbox/data/annotation_types/classification/classification.py:85: UserWarning: Dropdown classification is deprecated and will be removed in a future release
  warnings.warn("Dropdown classification is deprecated and will be "
32it [00:27,  2.27it/s]/usr/local/lib/python3.7/dist-packages/labelbox/data/serialization/coco/instance_dataset.py:37: ShapelyDeprecationWarning: Iteration over multi-part geometries is deprecated and will be removed in Shapely 2.0. Use the `geoms` property to access the constituent parts of a multi-part geometry.
  np.array(s.exterior.coords).ravel().tolist() for s in shapely
55it [00:41,  1.47it/s]/usr/local/lib/python3.7/dist-packages/labelbox/data/serialization/coco/instance_dataset.py:37: ShapelyDeprecationWarning: Iteration over multi-part geometries is deprecated and will be removed in Shapely 2.0. Use the `geoms` property to access the constituent parts of a multi-part geometry.
  np.array(s.exterior.coords).ravel().tolist() for s in shapely
66it [00:53,  1.09s/it]/usr/local/lib/python3.7/dist-packages/labelbox/data/serialization/coco/instance_dataset.py:37: ShapelyDeprecationWarning: Iteration over multi-part geometries is deprecated and will be removed in Shapely 2.0. Use the `geoms` property to access the constituent parts of a multi-part geometry.
  np.array(s.exterior.coords).ravel().tolist() for s in shapely
69it [00:56,  1.29it/s]/usr/local/lib/python3.7/dist-packages/labelbox/data/serialization/coco/instance_dataset.py:37: ShapelyDeprecationWarning: Iteration over multi-part geometries is deprecated and will be removed in Shapely 2.0. Use the `geoms` property to access the constituent parts of a multi-part geometry.
  np.array(s.exterior.coords).ravel().tolist() for s in shapely
71it [00:58,  1.10it/s]/usr/local/lib/python3.7/dist-packages/labelbox/data/serialization/coco/instance_dataset.py:37: ShapelyDeprecationWarning: Iteration over multi-part geometries is deprecated and will be removed in Shapely 2.0. Use the `geoms` property to access the constituent parts of a multi-part geometry.
  np.array(s.exterior.coords).ravel().tolist() for s in shapely
89it [01:20,  1.72s/it]/usr/local/lib/python3.7/dist-packages/labelbox/data/serialization/coco/instance_dataset.py:37: ShapelyDeprecationWarning: Iteration over multi-part geometries is deprecated and will be removed in Shapely 2.0. Use the `geoms` property to access the constituent parts of a multi-part geometry.
  np.array(s.exterior.coords).ravel().tolist() for s in shapely
/usr/local/lib/python3.7/dist-packages/labelbox/data/serialization/coco/instance_dataset.py:37: ShapelyDeprecationWarning: Iteration over multi-part geometries is deprecated and will be removed in Shapely 2.0. Use the `geoms` property to access the constituent parts of a multi-part geometry.
  np.array(s.exterior.coords).ravel().tolist() for s in shapely
/usr/local/lib/python3.7/dist-packages/labelbox/data/serialization/coco/instance_dataset.py:37: ShapelyDeprecationWarning: Iteration over multi-part geometries is deprecated and will be removed in Shapely 2.0. Use the `geoms` property to access the constituent parts of a multi-part geometry.
  np.array(s.exterior.coords).ravel().tolist() for s in shapely
---------------------------------------------------------------------------
_RemoteTraceback                          Traceback (most recent call last)
_RemoteTraceback: 
"""
Traceback (most recent call last):
  File "/usr/lib/python3.7/concurrent/futures/process.py", line 239, in _process_worker
    r = call_item.fn(*call_item.args, **call_item.kwargs)
  File "/usr/local/lib/python3.7/dist-packages/labelbox/data/serialization/coco/instance_dataset.py", line 113, in process_label
    categories[annotation.name]))
  File "/usr/local/lib/python3.7/dist-packages/labelbox/data/serialization/coco/instance_dataset.py", line 23, in mask_to_coco_object_annotation
    shapely = annotation.value.shapely.simplify(1).buffer(0)
  File "/usr/local/lib/python3.7/dist-packages/labelbox/data/annotation_types/geometry/geometry.py", line 20, in shapely
    return geom.shape(self.geometry)
  File "/usr/local/lib/python3.7/dist-packages/labelbox/data/annotation_types/geometry/mask.py", line 40, in geometry
    mask = self.draw(color=1)
  File "/usr/local/lib/python3.7/dist-packages/labelbox/data/annotation_types/geometry/mask.py", line 82, in draw
    mask = self.mask.value
  File "/usr/local/lib/python3.7/dist-packages/labelbox/data/annotation_types/data/raster.py", line 107, in value
    im_bytes = self.fetch_remote()
  File "/usr/local/lib/python3.7/dist-packages/google/api_core/retry.py", line 291, in retry_wrapped_func
    on_error=on_error,
  File "/usr/local/lib/python3.7/dist-packages/google/api_core/retry.py", line 189, in retry_target
    return target()
  File "/usr/local/lib/python3.7/dist-packages/labelbox/data/annotation_types/data/raster.py", line 125, in fetch_remote
    response.raise_for_status()
  File "/usr/local/lib/python3.7/dist-packages/requests/models.py", line 941, in raise_for_status
    raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 500 Server Error: Internal Server Error for url: https://api.labelbox.com/masks/feature/cl53jkfah002o3b6g84fshpdr?token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VySWQiOiJjbDQ3a2lrOTAyYTIwMDdiNDZlZHoycDBqIiwib3JnYW5pemF0aW9uSWQiOiJjbDQ3a2lrOGgyYTF6MDdiNDNsYmw5dXJsIiwiaWF0IjoxNjU3NzMxNDg2LCJleHAiOjE2NjAzMjM0ODZ9.VeZYJ3XtQU3bokcuQ1cWisR8Rrsu3FTwbnUF50Bvry8
"""

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

HTTPError                                 Traceback (most recent call last)
<ipython-input-6-c898318fc6d6> in <module>()
      6     labels,
      7     image_root=image_path,
----> 8     ignore_existing_data=True
      9 )

4 frames
/usr/lib/python3.7/concurrent/futures/_base.py in __get_result(self)
    382     def __get_result(self):
    383         if self._exception:
--> 384             raise self._exception
    385         else:
    386             return self._result

HTTPError: 500 Server Error: Internal Server Error for url: https://api.labelbox.com/masks/feature/cl53jkfah002o3b6g84fshpdr?token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VySWQiOiJjbDQ3a2lrOTAyYTIwMDdiNDZlZHoycDBqIiwib3JnYW5pemF0aW9uSWQiOiJjbDQ3a2lrOGgyYTF6MDdiNDNsYmw5dXJsIiwiaWF0IjoxNjU3NzMxNDg2LCJleHAiOjE2NjAzMjM0ODZ9.VeZYJ3XtQU3bokcuQ1cWisR8Rrsu3FTwbnUF50Bvry8

And every time I run the block. It shows different errors.
Now it shows 500 Internal server error.

/usr/local/lib/python3.7/dist-packages/labelbox/data/annotation_types/classification/classification.py:85: UserWarning: Dropdown classification is deprecated and will be removed in a future release
  warnings.warn("Dropdown classification is deprecated and will be "
32it [00:27,  2.27it/s]/usr/local/lib/python3.7/dist-packages/labelbox/data/serialization/coco/instance_dataset.py:37: ShapelyDeprecationWarning: Iteration over multi-part geometries is deprecated and will be removed in Shapely 2.0. Use the `geoms` property to access the constituent parts of a multi-part geometry.
  np.array(s.exterior.coords).ravel().tolist() for s in shapely
55it [00:41,  1.47it/s]/usr/local/lib/python3.7/dist-packages/labelbox/data/serialization/coco/instance_dataset.py:37: ShapelyDeprecationWarning: Iteration over multi-part geometries is deprecated and will be removed in Shapely 2.0. Use the `geoms` property to access the constituent parts of a multi-part geometry.
  np.array(s.exterior.coords).ravel().tolist() for s in shapely
66it [00:53,  1.09s/it]/usr/local/lib/python3.7/dist-packages/labelbox/data/serialization/coco/instance_dataset.py:37: ShapelyDeprecationWarning: Iteration over multi-part geometries is deprecated and will be removed in Shapely 2.0. Use the `geoms` property to access the constituent parts of a multi-part geometry.
  np.array(s.exterior.coords).ravel().tolist() for s in shapely
69it [00:56,  1.29it/s]/usr/local/lib/python3.7/dist-packages/labelbox/data/serialization/coco/instance_dataset.py:37: ShapelyDeprecationWarning: Iteration over multi-part geometries is deprecated and will be removed in Shapely 2.0. Use the `geoms` property to access the constituent parts of a multi-part geometry.
  np.array(s.exterior.coords).ravel().tolist() for s in shapely
71it [00:58,  1.10it/s]/usr/local/lib/python3.7/dist-packages/labelbox/data/serialization/coco/instance_dataset.py:37: ShapelyDeprecationWarning: Iteration over multi-part geometries is deprecated and will be removed in Shapely 2.0. Use the `geoms` property to access the constituent parts of a multi-part geometry.
  np.array(s.exterior.coords).ravel().tolist() for s in shapely
89it [01:20,  1.72s/it]/usr/local/lib/python3.7/dist-packages/labelbox/data/serialization/coco/instance_dataset.py:37: ShapelyDeprecationWarning: Iteration over multi-part geometries is deprecated and will be removed in Shapely 2.0. Use the `geoms` property to access the constituent parts of a multi-part geometry.
  np.array(s.exterior.coords).ravel().tolist() for s in shapely
/usr/local/lib/python3.7/dist-packages/labelbox/data/serialization/coco/instance_dataset.py:37: ShapelyDeprecationWarning: Iteration over multi-part geometries is deprecated and will be removed in Shapely 2.0. Use the `geoms` property to access the constituent parts of a multi-part geometry.
  np.array(s.exterior.coords).ravel().tolist() for s in shapely
/usr/local/lib/python3.7/dist-packages/labelbox/data/serialization/coco/instance_dataset.py:37: ShapelyDeprecationWarning: Iteration over multi-part geometries is deprecated and will be removed in Shapely 2.0. Use the `geoms` property to access the constituent parts of a multi-part geometry.
  np.array(s.exterior.coords).ravel().tolist() for s in shapely
---------------------------------------------------------------------------
_RemoteTraceback                          Traceback (most recent call last)
_RemoteTraceback: 
"""
Traceback (most recent call last):
  File "/usr/lib/python3.7/concurrent/futures/process.py", line 239, in _process_worker
    r = call_item.fn(*call_item.args, **call_item.kwargs)
  File "/usr/local/lib/python3.7/dist-packages/labelbox/data/serialization/coco/instance_dataset.py", line 113, in process_label
    categories[annotation.name]))
  File "/usr/local/lib/python3.7/dist-packages/labelbox/data/serialization/coco/instance_dataset.py", line 23, in mask_to_coco_object_annotation
    shapely = annotation.value.shapely.simplify(1).buffer(0)
  File "/usr/local/lib/python3.7/dist-packages/labelbox/data/annotation_types/geometry/geometry.py", line 20, in shapely
    return geom.shape(self.geometry)
  File "/usr/local/lib/python3.7/dist-packages/labelbox/data/annotation_types/geometry/mask.py", line 40, in geometry
    mask = self.draw(color=1)
  File "/usr/local/lib/python3.7/dist-packages/labelbox/data/annotation_types/geometry/mask.py", line 82, in draw
    mask = self.mask.value
  File "/usr/local/lib/python3.7/dist-packages/labelbox/data/annotation_types/data/raster.py", line 107, in value
    im_bytes = self.fetch_remote()
  File "/usr/local/lib/python3.7/dist-packages/google/api_core/retry.py", line 291, in retry_wrapped_func
    on_error=on_error,
  File "/usr/local/lib/python3.7/dist-packages/google/api_core/retry.py", line 189, in retry_target
    return target()
  File "/usr/local/lib/python3.7/dist-packages/labelbox/data/annotation_types/data/raster.py", line 125, in fetch_remote
    response.raise_for_status()
  File "/usr/local/lib/python3.7/dist-packages/requests/models.py", line 941, in raise_for_status
    raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 500 Server Error: Internal Server Error for url: https://api.labelbox.com/masks/feature/cl53jkfah002o3b6g84fshpdr?token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VySWQiOiJjbDQ3a2lrOTAyYTIwMDdiNDZlZHoycDBqIiwib3JnYW5pemF0aW9uSWQiOiJjbDQ3a2lrOGgyYTF6MDdiNDNsYmw5dXJsIiwiaWF0IjoxNjU3NzMxNDg2LCJleHAiOjE2NjAzMjM0ODZ9.VeZYJ3XtQU3bokcuQ1cWisR8Rrsu3FTwbnUF50Bvry8
"""

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

HTTPError                                 Traceback (most recent call last)
<ipython-input-6-c898318fc6d6> in <module>()
      6     labels,
      7     image_root=image_path,
----> 8     ignore_existing_data=True
      9 )

4 frames
/usr/lib/python3.7/concurrent/futures/_base.py in __get_result(self)
    382     def __get_result(self):
    383         if self._exception:
--> 384             raise self._exception
    385         else:
    386             return self._result

HTTPError: 500 Server Error: Internal Server Error for url: https://api.labelbox.com/masks/feature/cl53jkfah002o3b6g84fshpdr?token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VySWQiOiJjbDQ3a2lrOTAyYTIwMDdiNDZlZHoycDBqIiwib3JnYW5pemF0aW9uSWQiOiJjbDQ3a2lrOGgyYTF6MDdiNDNsYmw5dXJsIiwiaWF0IjoxNjU3NzMxNDg2LCJleHAiOjE2NjAzMjM0ODZ9.VeZYJ3XtQU3bokcuQ1cWisR8Rrsu3FTwbnUF50Bvry8

This is due to a geometry being invalid in one of the labels. There is some logic for cleaning up the geometries but I guess this particular case slipped through. Can you please send me the project id so that I can reproduce and patch the SDK?

The 500 error is transient. There is actually a bug in the SDK retry logic that I’ll patch as well.

Hello @msokoloff ,

Thanks for checking in. The project ID is cl52yt791kacp081o6b3f3x81.
I don’t see directly messaging here so I reply with the id.

Thanks for sharing the project id. The issue was an empty annotation. I made a PR that will prevent this from breaking the conversion. The changes will be available in the next release.

1 Like

Hey guys, i have this problem too, always this error:
Not enough values to unpack (expected 4, got 0)

How can i fix it? It’s really important to me

hey Amir, PM at Labelbox here :slight_smile:

are you still experiencing the issue? if yes, what’s your project ID?

hey you, thanks!..actually most of our project had this problem, for example this:

cl3nn4m141l1k07bmeai5fzya

what can we do? how to fix it for future project?

Any answer? I’m still wait to train our project bcz of labelbox, pls tell us what can we do?