Skip to content

Commit 5d6c221

Browse files
authored
add raw export for object slice (#391)
* add export raw json funtionality for object slice * version + changelog * added docstring * black
1 parent 6399ccd commit 5d6c221

File tree

3 files changed

+37
-1
lines changed

3 files changed

+37
-1
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@ All notable changes to the [Nucleus Python Client](https://github.com/scaleapi/n
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8+
## [0.15.11](https://github.com/scaleapi/nucleus-python-client/releases/tag/v0.15.11) - 2023-09-15
9+
10+
### Added
11+
- Added `slice.export_raw_json()` functionality to support raw export of object slices (annotations, predictions, item and scene level data). Currently does not support image slices.
12+
13+
814
## [0.15.10](https://github.com/scaleapi/nucleus-python-client/releases/tag/v0.15.10) - 2023-07-20
915

1016
### Added

nucleus/slice.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
from nucleus.constants import EXPORT_FOR_TRAINING_KEY, EXPORTED_ROWS, ITEMS_KEY
1212
from nucleus.dataset_item import DatasetItem
1313
from nucleus.errors import NucleusAPIError
14+
from nucleus.prediction import Prediction
1415
from nucleus.prediction import from_json as prediction_from_json
1516
from nucleus.scene import Scene
1617
from nucleus.utils import (
@@ -458,6 +459,35 @@ def export_predictions(
458459
)
459460
return convert_export_payload(api_payload[EXPORTED_ROWS], True)
460461

462+
def export_raw_json(
463+
self,
464+
) -> List[Union[DatasetItem, Annotation, Prediction, Scene]]:
465+
"""Exports object slices in a raw JSON format. Note that it currently does not support item-level slices.
466+
467+
For each object or match in an object slice, this method exports the following information:
468+
- The item that contains the object.
469+
- The prediction and/or annotation (both, if the slice is based on IOU matches).
470+
- If the object is part of a scene, it includes scene-level attributes in the export.
471+
472+
Returns:
473+
An iterable where each element is a dictionary containing JSON-formatted data.
474+
::
475+
476+
List[{
477+
"item": DatasetItem (as JSON),
478+
"annotation": BoxAnnotation/CuboidAnnotation (as JSON)
479+
"prediction": BoxPrediction/CuboidPrediction (as JSON)
480+
"scene": Scene (as JSON)
481+
}
482+
}]
483+
"""
484+
api_payload = self._client.make_request(
485+
payload=None,
486+
route=f"slice/{self.id}/export_raw_json",
487+
requests_command=requests.get,
488+
)
489+
return api_payload
490+
461491
def export_predictions_generator(
462492
self, model
463493
) -> Iterable[Dict[str, Union[DatasetItem, Dict[str, List[Annotation]]]]]:

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ exclude = '''
2121

2222
[tool.poetry]
2323
name = "scale-nucleus"
24-
version = "0.15.10"
24+
version = "0.15.11"
2525
description = "The official Python client library for Nucleus, the Data Platform for AI"
2626
license = "MIT"
2727
authors = ["Scale AI Nucleus Team <nucleusapi@scaleapi.com>"]

0 commit comments

Comments
 (0)