1212
1313from .annotation import (
1414 Annotation ,
15- CuboidAnnotation ,
1615 check_all_mask_paths_remote ,
16+ check_all_frame_paths_remote ,
1717)
1818from .constants import (
1919 DATASET_ITEM_IDS_KEY ,
2323 DATASET_SLICES_KEY ,
2424 DEFAULT_ANNOTATION_UPDATE_MODE ,
2525 EXPORTED_ROWS ,
26+ FRAMES ,
2627 NAME_KEY ,
2728 REFERENCE_IDS_KEY ,
2829 REQUEST_ID_KEY ,
30+ SCENES ,
2931 UPDATE_KEY ,
32+ URL ,
3033)
3134from .dataset_item import (
3235 DatasetItem ,
@@ -167,9 +170,6 @@ def annotate(
167170 "ignored_items": int,
168171 }
169172 """
170- if any ((isinstance (ann , CuboidAnnotation ) for ann in annotations )):
171- raise NotImplementedError ("Cuboid annotations not yet supported" )
172-
173173 check_all_mask_paths_remote (annotations )
174174
175175 if asynchronous :
@@ -248,14 +248,53 @@ def append(
248248 batch_size = batch_size ,
249249 )
250250
251+ def upload_scenes (
252+ self ,
253+ payload : dict ,
254+ update : Optional [bool ] = False ,
255+ asynchronous : bool = False ,
256+ ) -> Union [dict , AsyncJob ]:
257+ """
258+ Uploads scenes with given frames to the dataset
259+
260+ Parameters:
261+ :param payload: dictionary containing scenes to be uploaded
262+ :param update: if True, overwrite scene on collision
263+ :param aynchronous: if True, return a job object representing asynchronous ingestion job
264+ :return:
265+ {
266+ 'dataset_id': str,
267+ 'new_scenes': int,
268+ }
269+ """
270+ if asynchronous :
271+ for scene in payload [SCENES ]:
272+ for frame in scene [FRAMES ]:
273+ check_all_frame_paths_remote (frame [URL ])
274+ request_id = serialize_and_write_to_presigned_url (
275+ [payload ], self .id , self ._client
276+ )
277+ response = self ._client .make_request (
278+ payload = {REQUEST_ID_KEY : request_id , UPDATE_KEY : update },
279+ route = f"{ self .id } /upload_scenes?async=1" ,
280+ )
281+ return AsyncJob .from_json (response , self ._client )
282+
283+ # TODO: create client method for sync scene upload
284+ response = self ._client .make_request (
285+ payload = payload ,
286+ route = f"{ self .id } /upload_scenes" ,
287+ )
288+ return response
289+
251290 def iloc (self , i : int ) -> dict :
252291 """
253292 Returns Dataset Item Info By Dataset Item Number.
254293 :param i: absolute number of dataset item for the given dataset.
255294 :return:
256295 {
257296 "item": DatasetItem,
258- "annotations": List[Union[BoxAnnotation, PolygonAnnotation]],
297+ "annotations": List[Union[BoxAnnotation, PolygonAnnotation, CuboidAnnotation, SegmentationAnnotation ]],
259298 }
260299 """
261300 response = self ._client .dataitem_iloc (self .id , i )
@@ -268,7 +307,7 @@ def refloc(self, reference_id: str) -> dict:
268307 :return:
269308 {
270309 "item": DatasetItem,
271- "annotations": List[Union[BoxAnnotation, PolygonAnnotation]],
310+ "annotations": List[Union[BoxAnnotation, PolygonAnnotation, CuboidAnnotation, SegmentationAnnotation ]],
272311 }
273312 """
274313 response = self ._client .dataitem_ref_id (self .id , reference_id )
@@ -281,7 +320,7 @@ def loc(self, dataset_item_id: str) -> dict:
281320 :return:
282321 {
283322 "item": DatasetItem,
284- "annotations": List[Union[BoxAnnotation, PolygonAnnotation]],
323+ "annotations": List[Union[BoxAnnotation, PolygonAnnotation, CuboidAnnotation, SegmentationAnnotation ]],
285324 }
286325 """
287326 response = self ._client .dataitem_loc (self .id , dataset_item_id )
0 commit comments