-
Notifications
You must be signed in to change notification settings - Fork 68
Closed
Description
Labelbox Version
3.38.0
Description:
I have a project for annotating the timeline of videos. After labelling, most videos have annotations, but some videos were skipped. Exporting the annotations then fails:
import labelbox as lb
API_KEY='...'
lb_client = lb.Client(api_key=API_KEY)
project = next(lb_client.get_projects(where=lb.Project.name == 'foo'))
label_generator = project.label_generator()---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
Input In [107], in <cell line: 6>()
1 # This fails with skipped videos (no annotations).
2 # label_generator cannot tell the media type from the raw json label data.
3 # It checks if there is a `frames` key in the annotations to determine if it is video.
4 # The `frames` key is missing if a video was skipped (no frame annotated).
----> 6 label_generator = project.label_generator()
7 for label in label_generator:
8 for ann in label.annotations:
File ~/miniconda3/envs/python3.8/lib/python3.8/site-packages/labelbox/schema/project.py:282, in Project.label_generator(self, timeout_seconds, **kwargs)
277 is_video = [
278 'frames' in row['Label'] for row in json_data if row['Label']
279 ]
281 if len(is_video) and not all(is_video) and any(is_video):
--> 282 raise ValueError(
283 "Found mixed data types of video and text/image. "
284 "Use project.export_labels() to export projects with mixed data types. "
285 )
286 if len(is_video) and all(is_video):
287 return LBV1Converter.deserialize_video(json_data, self.client)
ValueError: Found mixed data types of video and text/image. Use project.export_labels() to export projects with mixed data types.
The initial annotations response contains no information about the media type. Instead it is checked if the annotations contain a 'frames' key and if the corresponding value is a list. However, skipped videos do not have this attribute.
Workaround
Only export annotations for those video that have them.
from labelbox.data.serialization import LBV1Converter
json_data = project.export_labels(download=True)
def has_annotations(row_json):
if 'frames' in row_json['Label']:
return True
else:
return False
json_data = filter(has_annotations, json_data)
result = [r for r in LBV1Converter.deserialize_video(json_data, lb_client)]Metadata
Metadata
Assignees
Labels
No labels