Skip to content

Commit 4893f71

Browse files
committed
merge of video_label_generator and label_generator to be single fn
1 parent cdc42c8 commit 4893f71

File tree

1 file changed

+10
-34
lines changed

1 file changed

+10
-34
lines changed

labelbox/schema/project.py

Lines changed: 10 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -221,41 +221,14 @@ def export_queued_data_rows(self,
221221
self.uid)
222222
time.sleep(sleep_time)
223223

224-
def video_label_generator(self, timeout_seconds=600, **kwargs):
225-
"""
226-
Download video annotations
227-
228-
Returns:
229-
LabelGenerator for accessing labels for each video
230-
"""
231-
_check_converter_import()
232-
json_data = self.export_labels(download=True,
233-
timeout_seconds=timeout_seconds,
234-
**kwargs)
235-
# assert that the instance this would fail is only if timeout runs out
236-
assert isinstance(
237-
json_data,
238-
List), "Unable to successfully get labels. Please try again"
239-
if json_data is None:
240-
raise TimeoutError(
241-
f"Unable to download labels in {timeout_seconds} seconds."
242-
"Please try again or contact support if the issue persists.")
243-
is_video = [
244-
'frames' in row['Label'] for row in json_data if row['Label']
245-
]
246-
if len(is_video) and not all(is_video):
247-
raise ValueError(
248-
"Found non-video data rows in export. "
249-
"Use project.export_labels() to export projects with mixed data types. "
250-
"Or use project.label_generator() for text and imagery data.")
251-
return LBV1Converter.deserialize_video(json_data, self.client)
252-
253224
def label_generator(self, timeout_seconds=600, **kwargs):
254225
"""
255-
Download text and image annotations
226+
Download text and image annotations, or video annotations.
227+
228+
For a mixture of text/image and video, use project.export_labels()
256229
257230
Returns:
258-
LabelGenerator for accessing labels for each text or image
231+
LabelGenerator for accessing labels
259232
"""
260233
_check_converter_import()
261234
json_data = self.export_labels(download=True,
@@ -272,11 +245,14 @@ def label_generator(self, timeout_seconds=600, **kwargs):
272245
is_video = [
273246
'frames' in row['Label'] for row in json_data if row['Label']
274247
]
275-
if len(is_video) and any(is_video):
248+
249+
if len(is_video) and not all(is_video) and any(is_video):
276250
raise ValueError(
277-
"Found video data rows in export. "
251+
"Found mixed data types of video and text/image. "
278252
"Use project.export_labels() to export projects with mixed data types. "
279-
"Or use project.video_label_generator() for video data.")
253+
)
254+
if len(is_video) and all(is_video):
255+
return LBV1Converter.deserialize_video(json_data, self.client)
280256
return LBV1Converter.deserialize(json_data)
281257

282258
def export_labels(self,

0 commit comments

Comments
 (0)