Skip to content

Commit cc962a5

Browse files
author
Matt Sokoloff
committed
more robust handling of exports
1 parent 73fd5f7 commit cc962a5

File tree

2 files changed

+30
-8
lines changed

2 files changed

+30
-8
lines changed

labelbox/data/serialization/labelbox_v1/converter.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,16 @@ def deserialize_video(json_data: Iterable[Dict[str, Any]],
2929
Returns:
3030
LabelGenerator containing the video data.
3131
"""
32-
label_generator = (LBV1Label(**example).to_common()
33-
for example in LBV1VideoIterator(json_data, client))
32+
33+
def label_generator():
34+
for example in LBV1VideoIterator(json_data, client):
35+
if example['Label']:
36+
if 'frames' not in example['Label']:
37+
raise ValueError(
38+
"Use `LBV1Converter.deserialize` to process non-video data"
39+
)
40+
yield LBV1Label(**example).to_common()
41+
3442
return LabelGenerator(data=label_generator)
3543

3644
@staticmethod
@@ -50,7 +58,9 @@ def label_generator():
5058
raise ValueError(
5159
"Use `LBV1Converter.deserialize_video` to process video"
5260
)
53-
yield LBV1Label(**example).to_common()
61+
if example['Label']:
62+
# Don't construct empty dict
63+
yield LBV1Label(**example).to_common()
5464

5565
return LabelGenerator(data=label_generator())
5666

labelbox/schema/project.py

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -173,13 +173,17 @@ def video_label_generator(self, timeout_seconds=60):
173173
Returns:
174174
LabelGenerator for accessing labels for each video
175175
"""
176+
_check_converter_import()
176177
json_data = self.export_labels(download=True,
177178
timeout_seconds=timeout_seconds)
178-
if 'frames' not in json_data[0]['Label']:
179+
is_video = [
180+
'frames' in row['Label'] for row in json_data if row['Label']
181+
]
182+
if len(is_video) and not all(is_video):
179183
raise ValueError(
180-
"frames key not found in the first label. Cannot export video data."
181-
)
182-
_check_converter_import()
184+
"Found non-video data rows in export. "
185+
"Use project.export_labels() to export projects with mixed data types. "
186+
"Or use project.label_generator() for text and imagery data.")
183187
return LBV1Converter.deserialize_video(json_data, self.client)
184188

185189
def label_generator(self, timeout_seconds=60):
@@ -189,9 +193,17 @@ def label_generator(self, timeout_seconds=60):
189193
Returns:
190194
LabelGenerator for accessing labels for each text or image
191195
"""
196+
_check_converter_import()
192197
json_data = self.export_labels(download=True,
193198
timeout_seconds=timeout_seconds)
194-
_check_converter_import()
199+
is_video = [
200+
'frames' in row['Label'] for row in json_data if row['Label']
201+
]
202+
if len(is_video) and not any(is_video):
203+
raise ValueError(
204+
"Found video data rows in export. "
205+
"Use project.export_labels() to export projects with mixed data types. "
206+
"Or use project.video_label_generator() for video data.")
195207
return LBV1Converter.deserialize(json_data)
196208

197209
def export_labels(self, download=False, timeout_seconds=60):

0 commit comments

Comments
 (0)