Skip to content

Commit 2bfe3bc

Browse files
authored
98 standardize client integrations (#102)
1 parent f5df709 commit 2bfe3bc

5 files changed

Lines changed: 934 additions & 401 deletions

File tree

client/unit-tests/test_chariot.py

Lines changed: 112 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -134,51 +134,51 @@ def _test_obj_det_ds(velour_dataset):
134134
assert velour_datum.bbox == BoundingBox(500, 220, 530, 260)
135135

136136

137-
def test_chariot_parse_image_classification_annotation(img_clf_ds: str):
137+
def test__parse_image_classification_groundtruths(img_clf_ds: str):
138138
chariot_dataset = img_clf_ds
139-
item1 = chariot_integration.chariot_parse_image_classification_annotation(
139+
item1 = chariot_integration._parse_image_classification_groundtruths(
140140
chariot_dataset[0]
141141
)
142142
assert len(item1) == 1
143-
item2 = chariot_integration.chariot_parse_image_classification_annotation(
143+
item2 = chariot_integration._parse_image_classification_groundtruths(
144144
chariot_dataset[1]
145145
)
146146
assert len(item2) == 1
147147
velour_dataset = item1 + item2
148148
_test_img_clf_ds(velour_dataset=velour_dataset)
149149

150150

151-
def test_chariot_parse_image_segmentation_annotation(img_seg_ds: str):
151+
def test__parse_image_segmentation_groundtruths(img_seg_ds: str):
152152
chariot_dataset = img_seg_ds
153-
item1 = chariot_integration.chariot_parse_image_segmentation_annotation(
153+
item1 = chariot_integration._parse_image_segmentation_groundtruths(
154154
chariot_dataset[0]
155155
)
156156
assert len(item1) == 1
157-
item2 = chariot_integration.chariot_parse_image_segmentation_annotation(
157+
item2 = chariot_integration._parse_image_segmentation_groundtruths(
158158
chariot_dataset[1]
159159
)
160160
assert len(item2) == 1
161161
velour_dataset = item1 + item2
162162
_test_img_seg_ds(velour_dataset=velour_dataset)
163163

164164

165-
def test_chariot_parse_object_detection_annotation(obj_det_ds: str):
165+
def test__parse_object_detection_groundtruths(obj_det_ds: str):
166166
chariot_dataset = obj_det_ds
167167

168168
# Item 1 - Multiple objects of interest
169-
item1 = chariot_integration.chariot_parse_object_detection_annotation(
169+
item1 = chariot_integration._parse_object_detection_groundtruths(
170170
chariot_dataset[0]
171171
)
172172
assert len(item1) == 2
173173

174174
# Item 2 - Single object of interest
175-
item2 = chariot_integration.chariot_parse_object_detection_annotation(
175+
item2 = chariot_integration._parse_object_detection_groundtruths(
176176
chariot_dataset[1]
177177
)
178178
assert len(item2) == 1
179179

180180
# Item 3 - No object of interest
181-
item3 = chariot_integration.chariot_parse_object_detection_annotation(
181+
item3 = chariot_integration._parse_object_detection_groundtruths(
182182
chariot_dataset[2]
183183
)
184184
assert len(item3) == 0
@@ -187,7 +187,7 @@ def test_chariot_parse_object_detection_annotation(obj_det_ds: str):
187187
_test_obj_det_ds(velour_dataset=velour_dataset)
188188

189189

190-
def test_chariot_parse_dataset_version_manifest(
190+
def test__parse_dataset_version_manifest(
191191
img_clf_ds: str, img_seg_ds: str, obj_det_ds: str
192192
):
193193
@dataclass
@@ -205,7 +205,7 @@ class supported_task_types:
205205
# Image classification
206206
chariot_task_type.image_classification = True
207207
_test_img_clf_ds(
208-
chariot_integration.chariot_parse_dataset_annotations(
208+
chariot_integration._parse_chariot_annotations(
209209
img_clf_ds, chariot_task_type
210210
)
211211
)
@@ -214,7 +214,7 @@ class supported_task_types:
214214
# Image Semantic Segmentation
215215
chariot_task_type.image_segmentation = True
216216
_test_img_seg_ds(
217-
chariot_integration.chariot_parse_dataset_annotations(
217+
chariot_integration._parse_chariot_annotations(
218218
img_seg_ds, chariot_task_type
219219
)
220220
)
@@ -223,15 +223,58 @@ class supported_task_types:
223223
# Object Detection
224224
chariot_task_type.object_detection = True
225225
_test_obj_det_ds(
226-
chariot_integration.chariot_parse_dataset_annotations(
226+
chariot_integration._parse_chariot_annotations(
227227
obj_det_ds, chariot_task_type
228228
)
229229
)
230230
chariot_task_type.object_detection = False
231231

232232

233-
def test_chariot_detections_to_velour():
234-
dets = {
233+
def test_parse_chariot_image_classifications():
234+
try:
235+
chariot_integration.parse_chariot_image_classifications(None, None)
236+
except NotImplementedError:
237+
pass
238+
239+
240+
def test_parse_chariot_image_segmentations():
241+
try:
242+
chariot_integration.parse_chariot_image_segmentations(None, None)
243+
except NotImplementedError:
244+
pass
245+
246+
247+
def _test_parse_chariot_object_detections(
248+
chariot_detections, velour_detections
249+
):
250+
assert len(velour_detections) == 2
251+
assert [
252+
scored_label.label.key
253+
for det in velour_detections
254+
for scored_label in det.scored_labels
255+
] == ["class", "class"]
256+
assert set(
257+
[
258+
scored_label.label.value
259+
for det in velour_detections
260+
for scored_label in det.scored_labels
261+
]
262+
) == {"person", "car"}
263+
264+
for i, velour_det in enumerate(velour_detections):
265+
assert chariot_detections["detection_boxes"][i] == [
266+
velour_det.bbox.ymin,
267+
velour_det.bbox.xmin,
268+
velour_det.bbox.ymax,
269+
velour_det.bbox.xmax,
270+
]
271+
272+
assert velour_det.boundary is None
273+
274+
275+
def test_parse_chariot_object_detections():
276+
277+
chariot_detections = {
235278
"num_detections": 2,
236279
"detection_classes": [
237280
"person",
@@ -253,31 +296,61 @@ def test_chariot_detections_to_velour():
253296
],
254297
"detection_scores": ["0.99932003", "0.99895525"],
255298
}
299+
image = Image(uid="", width=10, height=100)
300+
301+
# Test unwrapped input
302+
velour_detections = chariot_integration.parse_chariot_object_detections(
303+
chariot_detections, image
304+
)
305+
_test_parse_chariot_object_detections(
306+
chariot_detections, velour_detections
307+
)
256308

257-
velour_dets = chariot_integration.chariot_detections_to_velour(
258-
dets, Image(uid="", width=10, height=100)
309+
# Test unwrapped det, image list
310+
velour_detections = chariot_integration.parse_chariot_object_detections(
311+
chariot_detections, [image]
312+
)
313+
_test_parse_chariot_object_detections(
314+
chariot_detections, velour_detections
259315
)
260316

261-
assert len(velour_dets) == 2
262-
assert [
263-
scored_label.label.key
264-
for det in velour_dets
265-
for scored_label in det.scored_labels
266-
] == ["class", "class"]
267-
assert set(
268-
[
269-
scored_label.label.value
270-
for det in velour_dets
271-
for scored_label in det.scored_labels
272-
]
273-
) == {"person", "car"}
317+
# Test det list, unwrapped image
318+
velour_detections = chariot_integration.parse_chariot_object_detections(
319+
[chariot_detections], image
320+
)
321+
_test_parse_chariot_object_detections(
322+
chariot_detections, velour_detections
323+
)
274324

275-
for i, velour_det in enumerate(velour_dets):
276-
assert dets["detection_boxes"][i] == [
277-
velour_det.bbox.ymin,
278-
velour_det.bbox.xmin,
279-
velour_det.bbox.ymax,
280-
velour_det.bbox.xmax,
281-
]
325+
# Test wrapped inputs
326+
velour_detections = chariot_integration.parse_chariot_object_detections(
327+
[chariot_detections], [image]
328+
)
329+
_test_parse_chariot_object_detections(
330+
chariot_detections, velour_detections
331+
)
282332

283-
assert velour_det.boundary is None
333+
# Test multiple inputs
334+
velour_detections = chariot_integration.parse_chariot_object_detections(
335+
[chariot_detections, chariot_detections], [image, image]
336+
)
337+
velour_detections = [velour_detections[0:2], velour_detections[2:4]]
338+
for image_detections in velour_detections:
339+
_test_parse_chariot_object_detections(
340+
chariot_detections, image_detections
341+
)
342+
343+
# Test mismatch size
344+
try:
345+
velour_detections = (
346+
chariot_integration.parse_chariot_object_detections(
347+
[chariot_detections, chariot_detections], [image, image]
348+
)
349+
)
350+
velour_detections = [velour_detections[0:2], velour_detections[2:4]]
351+
for image_detections in velour_detections:
352+
_test_parse_chariot_object_detections(
353+
chariot_detections, image_detections
354+
)
355+
except AssertionError as e:
356+
assert e.args[0] == "length mismatch"

0 commit comments

Comments
 (0)