Skip to content

Commit e35d823

Browse files
authored
[DE-4419] Add more thorough docstring on scene_and_annotation_generator (#440)
* add in track grouping logic explanation in docs * the formatter got me again * i think its a line length issue?
1 parent 389275c commit e35d823

File tree

1 file changed

+26
-8
lines changed

1 file changed

+26
-8
lines changed

nucleus/dataset.py

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -997,9 +997,9 @@ def create_slice_by_ids(
997997
raise Exception("Must provide at least one list of internal IDs")
998998
payload = {
999999
NAME_KEY: name,
1000-
DATASET_ITEM_IDS_KEY: dataset_item_ids
1001-
if dataset_item_ids
1002-
else None,
1000+
DATASET_ITEM_IDS_KEY: (
1001+
dataset_item_ids if dataset_item_ids else None
1002+
),
10031003
SCENE_IDS_KEY: scene_ids if scene_ids else None,
10041004
OBJECT_IDS_KEY: [*(annotation_ids or []), *(prediction_ids or [])]
10051005
or None,
@@ -1449,16 +1449,34 @@ def items_and_annotations(
14491449
)
14501450
return convert_export_payload(api_payload[EXPORTED_ROWS])
14511451

1452-
def scene_and_annotation_generator(self, page_size=10):
1453-
"""Provides a generator of all DatasetItems and Annotations in the dataset grouped by scene.
1452+
def scene_and_annotation_generator(self, page_size: int = 10):
1453+
"""Provides a generator of all Scenes and Annotations in the dataset grouped by scene.
14541454
1455+
Args:
1456+
page_size: Number of scenes to fetch per page. Default is 10.
14551457
14561458
Returns:
1457-
Generator where each element is a nested dict (representing a JSON) structured in the following way:
1459+
Generator where each element is a nested dict containing scene and annotation information of the dataset structured as a JSON.
1460+
1461+
Track grouping is slightly more complicated and is done in the following order:
1462+
1. If track_id is defined in the annotations table, use it as the track id.
1463+
2. If track_reference_id is defined in the metadata field of the annotations table, use it as the track id.
1464+
3. If track_id is defined in the metadata field of the annotations table, use it as the track id.
1465+
4. If track_id is not defined and annotation_id is defined, use annotation_id as track id.
1466+
5. If annotation_id grouping is unsuccessful such that the annotation id is unique across all frames in the scene for all annotations, throw an error that the annotation format is incompatible.
1467+
6. If there is no track or annotation id, throw an error that the annotation format is incompatible.
1468+
1469+
If you use the generator and discover that no scenes were generated, check the response error message for more information. It is likely that the annotations are not in the correct format.
14581470
1471+
::
14591472
Iterable[{
1460-
"file_location": str,
1461-
"metadata": Dict[str, Any],
1473+
"scene": {
1474+
"id": str,
1475+
"reference_id": str,
1476+
"metadata": Dict[str, Any]
1477+
"type": str,
1478+
"fileLocation": str,
1479+
}
14621480
"annotations": {
14631481
"{trackId}": {
14641482
"label": str,

0 commit comments

Comments
 (0)