Skip to content

Commit 1c21287

Browse files
author
Claire Pajot
committed
Added export functionality + tests
1 parent c21d794 commit 1c21287

File tree

3 files changed

+24
-1
lines changed

3 files changed

+24
-1
lines changed

nucleus/dataset.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,6 @@ def annotate(
182182
route=f"dataset/{self.id}/annotate?async=1",
183183
)
184184
return AsyncJob.from_json(response, self._client)
185-
186185
return self._client.annotate_dataset(
187186
self.id, annotations, update=update, batch_size=batch_size
188187
)

nucleus/utils.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
BoxAnnotation,
1515
CuboidAnnotation,
1616
PolygonAnnotation,
17+
CategoryAnnotation,
1718
SegmentationAnnotation,
1819
)
1920

@@ -22,6 +23,7 @@
2223
ANNOTATIONS_KEY,
2324
BOX_TYPE,
2425
CUBOID_TYPE,
26+
CATEGORY_TYPE,
2527
ITEM_KEY,
2628
POLYGON_TYPE,
2729
REFERENCE_ID_KEY,
@@ -116,6 +118,11 @@ def convert_export_payload(api_payload):
116118
for cuboid in row[CUBOID_TYPE]:
117119
cuboid[REFERENCE_ID_KEY] = row[ITEM_KEY][REFERENCE_ID_KEY]
118120
annotations[CUBOID_TYPE].append(CuboidAnnotation.from_json(cuboid))
121+
for category in row[CATEGORY_TYPE]:
122+
category[REFERENCE_ID_KEY] = row[ITEM_KEY][REFERENCE_ID_KEY]
123+
annotations[CATEGORY_TYPE].append(
124+
CategoryAnnotation.from_json(category)
125+
)
119126
return_payload_row[ANNOTATIONS_KEY] = annotations
120127
return_payload.append(return_payload_row)
121128
return return_payload

tests/test_dataset.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,10 @@
1616
BoxAnnotation,
1717
PolygonAnnotation,
1818
SegmentationAnnotation,
19+
CategoryAnnotation,
1920
)
2021
from nucleus.constants import (
22+
CATEGORY_TYPE,
2123
DATASET_ID_KEY,
2224
ERROR_ITEMS,
2325
ERROR_PAYLOAD,
@@ -39,6 +41,7 @@
3941
TEST_IMG_URLS,
4042
TEST_POLYGON_ANNOTATIONS,
4143
TEST_SEGMENTATION_ANNOTATIONS,
44+
TEST_CATEGORY_ANNOTATIONS,
4245
DATASET_WITH_AUTOTAG,
4346
NUCLEUS_PYTEST_USER_ID,
4447
reference_id_from_url,
@@ -72,6 +75,13 @@ def test_repr(test_object: any):
7275
@pytest.fixture()
7376
def dataset(CLIENT):
7477
ds = CLIENT.create_dataset(TEST_DATASET_NAME)
78+
79+
response = ds.add_taxonomy(
80+
"[Pytest] Category Taxonomy 1",
81+
"category",
82+
[f"[Pytest] Category Label ${i}" for i in range((len(TEST_IMG_URLS)))],
83+
)
84+
7585
yield ds
7686

7787
response = CLIENT.delete_dataset(ds.id)
@@ -449,6 +459,9 @@ def test_append_and_export(dataset):
449459
polygon_annotation = PolygonAnnotation.from_json(
450460
TEST_POLYGON_ANNOTATIONS[0]
451461
)
462+
category_annotation = CategoryAnnotation.from_json(
463+
TEST_CATEGORY_ANNOTATIONS[0]
464+
)
452465

453466
ds_items = [
454467
DatasetItem(
@@ -465,6 +478,7 @@ def test_append_and_export(dataset):
465478
box_annotation,
466479
polygon_annotation,
467480
segmentation_annotation,
481+
category_annotation,
468482
]
469483
)
470484
# We don't export everything on segmentation annotations in order to speed up export.
@@ -486,6 +500,9 @@ def sort_labelmap(segmentation_annotation):
486500
exported[0][ANNOTATIONS_KEY][SEGMENTATION_TYPE]
487501
) == sort_labelmap(clear_fields(segmentation_annotation))
488502
assert exported[0][ANNOTATIONS_KEY][POLYGON_TYPE][0] == polygon_annotation
503+
assert (
504+
exported[0][ANNOTATIONS_KEY][CATEGORY_TYPE][0] == category_annotation
505+
)
489506

490507

491508
def test_export_embeddings(CLIENT):

0 commit comments

Comments
 (0)