1
1
"""
2
2
Nucleus Python Library.
3
3
4
- Data formats used:
5
-
6
- _____________________________________________________________________________________________________
7
-
8
- DatasetItem
9
-
10
- image_url | str | The URL containing the image for the given row of data.\n
11
- reference_id | str | An optional user-specified identifier to reference this given image.\n
12
- metadata | dict | All of column definitions for this item.
13
- | | The keys should match the user-specified column names,
14
- | | and the corresponding values will populate the cell under the column.\n
15
- _____________________________________________________________________________________________________
16
-
17
-
18
- Box2DGeometry:
19
-
20
- x | float | The distance, in pixels, between the left border of the bounding box
21
- | | and the left border of the image.\n
22
- y | float | The distance, in pixels, between the top border of the bounding box
23
- | | and the top border of the image.\n
24
- width | float | The width in pixels of the annotation.\n
25
- height | float | The height in pixels of the annotation.\n
26
-
27
- Box2DAnnotation:
28
-
29
- item_id | str | The internally-controlled item identifier to associate this annotation with.
30
- | | The reference_id field should be empty if this field is populated.\n
31
- reference_id | str | The user-specified reference identifier to associate this annotation with.\n
32
- | | The item_id field should be empty if this field is populated.
33
- label | str | The label for this annotation (e.g. car, pedestrian, bicycle).\n
34
- type | str | The type of this annotation. It should always be the box string literal.\n
35
- geometry | dict | Representation of the bounding box in the Box2DGeometry format.\n
36
- metadata | dict | An arbitrary metadata blob for the annotation.\n
37
-
38
- _____________________________________________________________________________________________________
39
-
40
- Box2DDetection:
41
-
42
- item_id | str | The internally-controlled item identifier to associate this annotation with.
43
- | | The reference_id field should be empty if this field is populated.\n
44
- reference_id | str | The user-specified reference identifier to associate this annotation with.
45
- | | The item_id field should be empty if this field is populated.\n
46
- label | str | The label for this annotation (e.g. car, pedestrian, bicycle).\n
47
- type | str | The type of this annotation. It should always be the box string literal.\n
48
- confidence | float | The optional confidence level of this annotation.
49
- | | It should be between 0 and 1 (inclusive).\n
50
- geometry | dict | Representation of the bounding box in the Box2DGeometry format.\n
51
- metadata | dict | An arbitrary metadata blob for the annotation.\n
4
+ For full documentation see: https://dashboard.scale.com/nucleus/docs/api?language=python
52
5
"""
53
6
import asyncio
54
7
import json
83
36
ANNOTATIONS_PROCESSED_KEY ,
84
37
AUTOTAGS_KEY ,
85
38
DATASET_ID_KEY ,
86
- DATASET_ITEM_IDS_KEY ,
87
39
DEFAULT_NETWORK_TIMEOUT_SEC ,
88
40
EMBEDDING_DIMENSION_KEY ,
89
41
EMBEDDINGS_URL_KEY ,
@@ -246,11 +198,8 @@ def get_dataset_items(self, dataset_id) -> List[DatasetItem]:
246
198
for item in dataset_items :
247
199
image_url = item .get ("original_image_url" )
248
200
metadata = item .get ("metadata" , None )
249
- item_id = item .get ("id" , None )
250
201
ref_id = item .get ("ref_id" , None )
251
- dataset_item = DatasetItem (
252
- image_url , ref_id , item_id , metadata
253
- )
202
+ dataset_item = DatasetItem (image_url , ref_id , metadata )
254
203
constructed_dataset_items .append (dataset_item )
255
204
elif error :
256
205
raise DatasetItemRetrievalError (message = error )
@@ -351,26 +300,19 @@ def delete_dataset(self, dataset_id: str) -> dict:
351
300
return self .make_request ({}, f"dataset/{ dataset_id } " , requests .delete )
352
301
353
302
@sanitize_string_args
354
- def delete_dataset_item (
355
- self , dataset_id : str , item_id : str = None , reference_id : str = None
356
- ) -> dict :
303
+ def delete_dataset_item (self , dataset_id : str , reference_id ) -> dict :
357
304
"""
358
305
Deletes a private dataset based on datasetId.
359
306
Returns an empty payload where response status `200` indicates
360
307
the dataset has been successfully deleted.
361
308
:param payload: { "name": str }
362
309
:return: { "dataset_id": str, "name": str }
363
310
"""
364
- if item_id :
365
- return self .make_request (
366
- {}, f"dataset/{ dataset_id } /{ item_id } " , requests .delete
367
- )
368
- else : # Assume reference_id is provided
369
- return self .make_request (
370
- {},
371
- f"dataset/{ dataset_id } /refloc/{ reference_id } " ,
372
- requests .delete ,
373
- )
311
+ return self .make_request (
312
+ {},
313
+ f"dataset/{ dataset_id } /refloc/{ reference_id } " ,
314
+ requests .delete ,
315
+ )
374
316
375
317
def populate_dataset (
376
318
self ,
@@ -1018,17 +960,13 @@ def create_slice(self, dataset_id: str, payload: dict) -> Slice:
1018
960
as a means of identifying items in the dataset.
1019
961
1020
962
"name" -- The human-readable name of the slice.
1021
-
1022
- "dataset_item_ids" -- An optional list of dataset item ids for the items in the slice
1023
-
1024
963
"reference_ids" -- An optional list of user-specified identifier for the items in the slice
1025
964
1026
965
:param
1027
966
dataset_id: id of the dataset
1028
967
payload:
1029
968
{
1030
969
"name": str,
1031
- "dataset_item_ids": List[str],
1032
970
"reference_ids": List[str],
1033
971
}
1034
972
:return: new Slice object
@@ -1054,14 +992,12 @@ def slice_info(self, slice_id: str) -> dict:
1054
992
1055
993
:param
1056
994
slice_id: id of the slice
1057
- id_type: the type of IDs you want in response (either "reference_id" or "dataset_item_id")
1058
- to identify the DatasetItems
1059
995
1060
996
:return:
1061
997
{
1062
998
"name": str,
1063
999
"dataset_id": str,
1064
- "dataset_item_ids ": List[str],
1000
+ "reference_ids ": List[str],
1065
1001
}
1066
1002
"""
1067
1003
response = self .make_request (
@@ -1113,35 +1049,25 @@ def delete_annotations(
1113
1049
def append_to_slice (
1114
1050
self ,
1115
1051
slice_id : str ,
1116
- dataset_item_ids : List [str ] = None ,
1117
- reference_ids : List [str ] = None ,
1052
+ reference_ids : List [str ],
1118
1053
) -> dict :
1119
1054
"""
1120
1055
Appends to a slice from items already present in a dataset.
1121
1056
The caller must exclusively use either datasetItemIds or reference_ids
1122
1057
as a means of identifying items in the dataset.
1123
1058
1124
1059
:param
1125
- dataset_item_ids: List[str],
1126
1060
reference_ids: List[str],
1127
1061
1128
1062
:return:
1129
1063
{
1130
1064
"slice_id": str,
1131
1065
}
1132
1066
"""
1133
- if dataset_item_ids and reference_ids :
1134
- raise Exception (
1135
- "You cannot specify both dataset_item_ids and reference_ids"
1136
- )
1137
1067
1138
- ids_to_append : Dict [str , Any ] = {}
1139
- if dataset_item_ids :
1140
- ids_to_append [DATASET_ITEM_IDS_KEY ] = dataset_item_ids
1141
- if reference_ids :
1142
- ids_to_append [REFERENCE_IDS_KEY ] = reference_ids
1143
-
1144
- response = self .make_request (ids_to_append , f"slice/{ slice_id } /append" )
1068
+ response = self .make_request (
1069
+ {REFERENCE_IDS_KEY : reference_ids }, f"slice/{ slice_id } /append"
1070
+ )
1145
1071
return response
1146
1072
1147
1073
def list_autotags (self , dataset_id : str ) -> List [str ]:
@@ -1194,7 +1120,7 @@ def create_custom_index(
1194
1120
1195
1121
:param
1196
1122
dataset_id: id of dataset that the custom index is being added to.
1197
- embeddings_urls: list of urls, each of which being a json mapping dataset_item_id -> embedding vector
1123
+ embeddings_urls: list of urls, each of which being a json mapping reference_id -> embedding vector
1198
1124
embedding_dim: the dimension of the embedding vectors, must be consistent for all embedding vectors in the index.
1199
1125
"""
1200
1126
return self .make_request (
0 commit comments