Skip to content

Commit 58811cf

Browse files
Drew KaulDrew Kaul
authored andcommitted
add integration test for 3d dataset creation and cuboid upload
1 parent 21d9add commit 58811cf

File tree

2 files changed

+93
-0
lines changed

2 files changed

+93
-0
lines changed

tests/helpers.py

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
TEST_MODEL_NAME = "[PyTest] Test Model"
1010
TEST_MODEL_RUN = "[PyTest] Test Model Run"
1111
TEST_DATASET_NAME = "[PyTest] Test Dataset"
12+
TEST_DATASET_3D_NAME = "[PyTest] Test Dataset 3D"
1213
TEST_SLICE_NAME = "[PyTest] Test Slice"
1314
TEST_PROJECT_ID = "60b699d70f139e002dd31bfc"
1415

@@ -21,6 +22,10 @@
2122
"https://homepages.cae.wisc.edu/~ece533/images/cat.png",
2223
]
2324

25+
TEST_POINTCLOUD_URLS = [
26+
"https://scale-us-attachments.s3.us-west-2.amazonaws.com/select/examples/kitti_example_frame.json",
27+
]
28+
2429
TEST_DATASET_ITEMS = [
2530
DatasetItem(TEST_IMG_URLS[0], "1"),
2631
DatasetItem(TEST_IMG_URLS[1], "2"),
@@ -72,6 +77,28 @@ def reference_id_from_url(url):
7277
for i in range(len(TEST_IMG_URLS))
7378
]
7479

80+
TEST_CUBOID_ANNOTATIONS = [
81+
{
82+
"label": f"[Pytest] Cuboid Annotation ${i}",
83+
"geometry": {
84+
"position": {
85+
"x": 50 * i + 10,
86+
"y": 60 * i + 10,
87+
"z": 70 * i + 10,
88+
},
89+
"dimensions": {
90+
"x": 10 * i,
91+
"y": 20 * i,
92+
"z": 30 * i,
93+
},
94+
"yaw": 5 * i,
95+
},
96+
"reference_id": reference_id_from_url(TEST_POINTCLOUD_URLS[i]),
97+
"annotation_id": f"[Pytest] Cuboid Annotation Annotation Id{i}",
98+
}
99+
for i in range(len(TEST_POINTCLOUD_URLS))
100+
]
101+
75102

76103
TEST_MASK_URL = "https://raw.githubusercontent.com/scaleapi/nucleus-python-client/master/tests/testdata/000000000285.png"
77104

@@ -157,6 +184,29 @@ def assert_polygon_annotation_matches_dict(
157184
assert instance_pt.y == dict_pt["y"]
158185

159186

187+
def assert_cuboid_annotation_matches_dict(
188+
annotation_instance, annotation_dict
189+
):
190+
assert annotation_instance.label == annotation_dict["label"]
191+
assert (
192+
annotation_instance.annotation_id == annotation_dict["annotation_id"]
193+
)
194+
for instance_pt, dict_pt in zip(
195+
annotation_instance.position, annotation_dict["geometry"]["position"]
196+
):
197+
assert instance_pt.x == dict_pt["x"]
198+
assert instance_pt.y == dict_pt["y"]
199+
assert instance_pt.z == dict_pt["z"]
200+
for instance_pt, dict_pt in zip(
201+
annotation_instance.dimensions,
202+
annotation_dict["geometry"]["dimensions"],
203+
):
204+
assert instance_pt.x == dict_pt["x"]
205+
assert instance_pt.y == dict_pt["y"]
206+
assert instance_pt.z == dict_pt["z"]
207+
assert annotation_instance.yaw == annotation_dict["geometry"]["yaw"]
208+
209+
160210
def assert_segmentation_annotation_matches_dict(
161211
annotation_instance, annotation_dict
162212
):

tests/test_annotation.py

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,24 @@
22

33
from .helpers import (
44
TEST_DATASET_NAME,
5+
TEST_DATASET_3D_NAME,
56
TEST_IMG_URLS,
7+
TEST_POINTCLOUD_URLS,
68
TEST_BOX_ANNOTATIONS,
79
TEST_POLYGON_ANNOTATIONS,
10+
TEST_CUBOID_ANNOTATIONS,
811
TEST_SEGMENTATION_ANNOTATIONS,
912
reference_id_from_url,
1013
assert_box_annotation_matches_dict,
1114
assert_polygon_annotation_matches_dict,
15+
assert_cuboid_annotation_matches_dict,
1216
assert_segmentation_annotation_matches_dict,
1317
)
1418

1519
from nucleus import (
1620
BoxAnnotation,
1721
PolygonAnnotation,
22+
CuboidAnnotation,
1823
SegmentationAnnotation,
1924
DatasetItem,
2025
Segment,
@@ -61,6 +66,26 @@ def dataset(CLIENT):
6166
assert response == {"message": "Beginning dataset deletion..."}
6267

6368

69+
@pytest.fixture()
70+
def dataset_3d(CLIENT):
71+
ds = CLIENT.create_dataset(TEST_DATASET_3D_NAME)
72+
ds_items = []
73+
for url in TEST_POINTCLOUD_URLS:
74+
ds_items.append(
75+
DatasetItem(
76+
image_location=url,
77+
reference_id=reference_id_from_url(url),
78+
)
79+
)
80+
81+
response = ds.append(ds_items)
82+
assert ERROR_PAYLOAD not in response.json()
83+
yield ds
84+
85+
response = CLIENT.delete_dataset(ds.id)
86+
assert response == {"message": "Beginning dataset deletion..."}
87+
88+
6489
def test_box_gt_upload(dataset):
6590
annotation = BoxAnnotation(**TEST_BOX_ANNOTATIONS[0])
6691
response = dataset.annotate(annotations=[annotation])
@@ -95,6 +120,24 @@ def test_polygon_gt_upload(dataset):
95120
)
96121

97122

123+
def test_cuboid_gt_upload(dataset_3d):
124+
annotation = CuboidAnnotation.from_json(TEST_CUBOID_ANNOTATIONS[0])
125+
response = dataset_3d.annotate(annotations=[annotation])
126+
127+
assert response["dataset_id"] == dataset_3d.id
128+
assert response["annotations_processed"] == 1
129+
assert response["annotations_ignored"] == 0
130+
131+
response = dataset_3d.refloc(annotation.reference_id)["annotations"][
132+
"cuboid"
133+
]
134+
assert len(response) == 1
135+
response_annotation = response[0]
136+
assert_cuboid_annotation_matches_dict(
137+
response_annotation, TEST_CUBOID_ANNOTATIONS[0]
138+
)
139+
140+
98141
def test_single_semseg_gt_upload(dataset):
99142
annotation = SegmentationAnnotation.from_json(
100143
TEST_SEGMENTATION_ANNOTATIONS[0]

0 commit comments

Comments
 (0)