Skip to content

Commit 77beeb5

Browse files
author
Anthony Krivonos
authored
Add create_slice_by_ids (#383)
1 parent 18696eb commit 77beeb5

File tree

4 files changed

+58
-1
lines changed

4 files changed

+58
-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.4](https://github.com/scaleapi/nucleus-python-client/releases/tag/v0.15.4) - 2023-03-21
9+
10+
### Changed
11+
- Added `create_slice_by_ids` to create slices from dataset item, scene, and object IDs
12+
13+
814
## [0.15.3](https://github.com/scaleapi/nucleus-python-client/releases/tag/v0.15.3) - 2023-03-02
915

1016
### Changed

nucleus/constants.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
DATASET_ID_KEY = "dataset_id"
3939
DATASET_IS_SCENE_KEY = "is_scene"
4040
DATASET_ITEM_ID_KEY = "dataset_item_id"
41+
DATASET_ITEM_IDS_KEY = "dataset_item_ids"
4142
DATASET_ITEMS_KEY = "dataset_items"
4243
DATASET_LENGTH_KEY = "length"
4344
DATASET_MODEL_RUNS_KEY = "model_run_ids"
@@ -104,6 +105,7 @@
104105
PAGE_TOKEN_KEY = "pageToken"
105106
NEXT_TOKEN_KEY = "nextPageToken"
106107
OVERWRITE_KEY = "overwrite"
108+
OBJECT_IDS_KEY = "object_ids"
107109
P1_KEY = "p1"
108110
P2_KEY = "p2"
109111
POINTCLOUD_KEY = "pointcloud"
@@ -120,6 +122,7 @@
120122
SCALE_TASK_INFO_KEY = "scale_task_info"
121123
SCENE_KEY = "scene"
122124
SCENES_KEY = "scenes"
125+
SCENE_IDS_KEY = "scene_ids"
123126
SERIALIZED_REQUEST_KEY = "serialized_request"
124127
SEGMENTATIONS_KEY = "segmentations"
125128
SLICE_ID_KEY = "slice_id"

nucleus/dataset.py

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
BACKFILL_JOB_KEY,
3636
DATASET_ID_KEY,
3737
DATASET_IS_SCENE_KEY,
38+
DATASET_ITEM_IDS_KEY,
3839
DATASET_ITEMS_KEY,
3940
DEFAULT_ANNOTATION_UPDATE_MODE,
4041
EMBEDDING_DIMENSION_KEY,
@@ -47,8 +48,10 @@
4748
KEEP_HISTORY_KEY,
4849
MESSAGE_KEY,
4950
NAME_KEY,
51+
OBJECT_IDS_KEY,
5052
REFERENCE_IDS_KEY,
5153
REQUEST_ID_KEY,
54+
SCENE_IDS_KEY,
5255
SLICE_ID_KEY,
5356
TRACK_REFERENCE_IDS_KEY,
5457
TRACKS_KEY,
@@ -895,6 +898,51 @@ def create_slice(
895898
)
896899
return Slice(response[SLICE_ID_KEY], self._client)
897900

901+
def create_slice_by_ids(
902+
self,
903+
name: str,
904+
dataset_item_ids: Optional[List[str]] = None,
905+
scene_ids: Optional[List[str]] = None,
906+
annotation_ids: Optional[List[str]] = None,
907+
prediction_ids: Optional[List[str]] = None,
908+
) -> Slice:
909+
"""Creates a :class:`Slice` of dataset items, scenes, annotations, or predictions within a dataset by their IDs.
910+
911+
.. note::
912+
Dataset item, scene, and object (annotation or prediction) IDs may not be mixed.
913+
However, when creating an object slice, both annotation and prediction IDs may be supplied.
914+
915+
Parameters:
916+
name: A human-readable name for the slice.
917+
dataset_item_ids: List of internal IDs of dataset items to add to the slice::
918+
scene_ids: List of internal IDs of scenes to add to the slice::
919+
annotation_ids: List of internal IDs of Annotations to add to the slice::
920+
prediction_ids: List of internal IDs of Predictions to add to the slice::
921+
922+
Returns:
923+
:class:`Slice`: The newly constructed slice item.
924+
"""
925+
if (
926+
not dataset_item_ids
927+
and not scene_ids
928+
and not annotation_ids
929+
and not prediction_ids
930+
):
931+
raise Exception("Must provide at least one list of internal IDs")
932+
payload = {
933+
NAME_KEY: name,
934+
DATASET_ITEM_IDS_KEY: dataset_item_ids
935+
if dataset_item_ids
936+
else None,
937+
SCENE_IDS_KEY: scene_ids if scene_ids else None,
938+
OBJECT_IDS_KEY: [*(annotation_ids or []), *(prediction_ids or [])]
939+
or None,
940+
}
941+
response = self._client.make_request(
942+
payload, f"dataset/{self.id}/create_slice"
943+
)
944+
return Slice(response[SLICE_ID_KEY], self._client)
945+
898946
def build_slice(
899947
self,
900948
name: str,

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.3"
24+
version = "0.15.4"
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)