44import requests
55
66from nucleus .annotation import Annotation
7- from nucleus .constants import EXPORTED_ROWS , ITEMS_KEY
7+ from nucleus .constants import EXPORT_FOR_TRAINING_KEY , EXPORTED_ROWS , ITEMS_KEY
88from nucleus .dataset_item import DatasetItem
99from nucleus .errors import NucleusAPIError
1010from nucleus .job import AsyncJob
1111from nucleus .utils import (
1212 KeyErrorDict ,
1313 convert_export_payload ,
14- format_dataset_item_response ,
1514 format_scale_task_info_response ,
1615 paginate_generator ,
1716)
@@ -203,13 +202,15 @@ def items_and_annotation_generator(
203202 }
204203 }]
205204 """
206- for item in self .items_generator ():
207- yield format_dataset_item_response (
208- self ._client .dataitem_ref_id (
209- dataset_id = self .dataset_id ,
210- reference_id = item .reference_id ,
211- )
212- )
205+ json_generator = paginate_generator (
206+ client = self ._client ,
207+ endpoint = f"slice/{ self .id } /exportForTrainingPage" ,
208+ result_key = EXPORT_FOR_TRAINING_KEY ,
209+ page_size = 100000 ,
210+ )
211+ for data in json_generator :
212+ for ia in convert_export_payload ([data ], has_predictions = False ):
213+ yield ia
213214
214215 def items_and_annotations (
215216 self ,
@@ -256,7 +257,7 @@ def export_predictions(
256257
257258 List[{
258259 "item": DatasetItem,
259- "predicions ": {
260+ "predictions ": {
260261 "box": List[BoxAnnotation],
261262 "polygon": List[PolygonAnnotation],
262263 "cuboid": List[CuboidAnnotation],
@@ -272,6 +273,40 @@ def export_predictions(
272273 )
273274 return convert_export_payload (api_payload [EXPORTED_ROWS ], True )
274275
276+ def export_predictions_generator (
277+ self , model
278+ ) -> Iterable [Dict [str , Union [DatasetItem , Dict [str , List [Annotation ]]]]]:
279+ """Provides a list of all DatasetItems and Predictions in the Slice for the given Model.
280+
281+ Parameters:
282+ model (Model): the nucleus model objects representing the model for which to export predictions.
283+
284+ Returns:
285+ Iterable where each element is a dict containing the DatasetItem
286+ and all of its associated Predictions, grouped by type (e.g. box).
287+ ::
288+
289+ List[{
290+ "item": DatasetItem,
291+ "predictions": {
292+ "box": List[BoxAnnotation],
293+ "polygon": List[PolygonAnnotation],
294+ "cuboid": List[CuboidAnnotation],
295+ "segmentation": List[SegmentationAnnotation],
296+ "category": List[CategoryAnnotation],
297+ }
298+ }]
299+ """
300+ json_generator = paginate_generator (
301+ client = self ._client ,
302+ endpoint = f"slice/{ self .id } /{ model .id } /exportForTrainingPage" ,
303+ result_key = EXPORT_FOR_TRAINING_KEY ,
304+ page_size = 100000 ,
305+ )
306+ for data in json_generator :
307+ for ip in convert_export_payload ([data ], has_predictions = True ):
308+ yield ip
309+
275310 def export_scale_task_info (self ):
276311 """Fetches info for all linked Scale tasks of items/scenes in the slice.
277312
0 commit comments