6
6
TEST_BOX_ANNOTATIONS ,
7
7
TEST_POLYGON_ANNOTATIONS ,
8
8
TEST_CATEGORY_ANNOTATIONS ,
9
+ TEST_MULTICATEGORY_ANNOTATIONS ,
9
10
TEST_SEGMENTATION_ANNOTATIONS ,
10
11
reference_id_from_url ,
11
12
assert_box_annotation_matches_dict ,
12
13
assert_polygon_annotation_matches_dict ,
13
14
assert_category_annotation_matches_dict ,
15
+ assert_multicategory_annotation_matches_dict ,
14
16
assert_segmentation_annotation_matches_dict ,
15
17
)
16
18
17
19
from nucleus import (
18
20
BoxAnnotation ,
19
21
PolygonAnnotation ,
20
22
CategoryAnnotation ,
23
+ MultiCategoryAnnotation ,
21
24
SegmentationAnnotation ,
22
25
DatasetItem ,
23
26
Segment ,
@@ -64,6 +67,14 @@ def dataset(CLIENT):
64
67
"category" ,
65
68
[f"[Pytest] Category Label ${ i } " for i in range ((len (TEST_IMG_URLS )))],
66
69
)
70
+ response = ds .add_taxonomy (
71
+ "[Pytest] MultiCategory Taxonomy 1" ,
72
+ "multicategory" ,
73
+ [
74
+ f"[Pytest] MultiCategory Label ${ i } "
75
+ for i in range ((len (TEST_IMG_URLS ) + 1 ))
76
+ ],
77
+ )
67
78
yield ds
68
79
69
80
response = CLIENT .delete_dataset (ds .id )
@@ -73,6 +84,7 @@ def dataset(CLIENT):
73
84
def test_box_gt_upload (dataset ):
74
85
annotation = BoxAnnotation (** TEST_BOX_ANNOTATIONS [0 ])
75
86
response = dataset .annotate (annotations = [annotation ])
87
+ print (response )
76
88
77
89
assert response ["dataset_id" ] == dataset .id
78
90
assert response ["annotations_processed" ] == 1
@@ -127,6 +139,28 @@ def test_category_gt_upload(dataset):
127
139
)
128
140
129
141
142
+ def test_multicategory_gt_upload (dataset ):
143
+ annotation = MultiCategoryAnnotation .from_json (
144
+ TEST_MULTICATEGORY_ANNOTATIONS [0 ]
145
+ )
146
+ response = dataset .annotate (annotations = [annotation ])
147
+
148
+ assert response ["dataset_id" ] == dataset .id
149
+ assert response ["annotations_processed" ] == 1
150
+ assert response ["annotations_ignored" ] == 0
151
+ print ("HERE" )
152
+ response = dataset .refloc (annotation .reference_id )["annotations" ][
153
+ "multicategory"
154
+ ]
155
+ print ("RESPONSE: " , response )
156
+ # TODO: Weirdness here also in the response from refloc?
157
+ assert len (response ) == 1
158
+ response_annotation = response [0 ]
159
+ assert_multicategory_annotation_matches_dict (
160
+ response_annotation , TEST_MULTICATEGORY_ANNOTATIONS [0 ]
161
+ )
162
+
163
+
130
164
def test_single_semseg_gt_upload (dataset ):
131
165
annotation = SegmentationAnnotation .from_json (
132
166
TEST_SEGMENTATION_ANNOTATIONS [0 ]
@@ -206,6 +240,7 @@ def test_mixed_annotation_upload(dataset):
206
240
response_annotations = dataset .refloc (bbox_annotations [0 ].reference_id )[
207
241
"annotations"
208
242
]
243
+ print (response_annotations )
209
244
assert len (response_annotations ) == 2
210
245
assert len (response_annotations ["box" ]) == 1
211
246
assert "segmentation" in response_annotations
@@ -392,34 +427,120 @@ def test_category_gt_upload_ignore(dataset):
392
427
response_annotation , TEST_CATEGORY_ANNOTATIONS [0 ]
393
428
)
394
429
395
- @pytest .mark .integration
396
- def test_box_gt_deletion (dataset ):
397
- annotation = BoxAnnotation (** TEST_BOX_ANNOTATIONS [0 ])
398
430
399
- print (annotation )
431
+ def test_multicategory_gt_upload_update (dataset ):
432
+ annotation = MultiCategoryAnnotation .from_json (
433
+ TEST_MULTICATEGORY_ANNOTATIONS [0 ]
434
+ )
435
+ response = dataset .annotate (annotations = [annotation ])
400
436
401
- response = dataset . annotate ( annotations = [ annotation ])
437
+ assert response [ "annotations_processed" ] == 1
402
438
403
- assert response ["annotations_processed" ] == 1
439
+ # Copy so we don't modify the original.
440
+ annotation_update_params = dict (TEST_MULTICATEGORY_ANNOTATIONS [1 ])
441
+ annotation_update_params ["reference_id" ] = TEST_MULTICATEGORY_ANNOTATIONS [
442
+ 0
443
+ ]["reference_id" ]
404
444
405
- job = dataset .delete_annotations ()
406
- job .sleep_until_complete ()
407
- job_status = job .status ()
408
- assert job_status ["status" ] == "Completed"
409
- assert job_status ["job_id" ] == job .id
445
+ annotation_update = MultiCategoryAnnotation .from_json (
446
+ annotation_update_params
447
+ )
448
+ response = dataset .annotate (annotations = [annotation_update ], update = True )
410
449
411
- @pytest .mark .integration
412
- def test_category_gt_deletion (dataset ):
413
- annotation = CategoryAnnotation .from_json (TEST_CATEGORY_ANNOTATIONS [0 ])
450
+ assert response ["annotations_processed" ] == 1
451
+ assert response ["annotations_ignored" ] == 0
414
452
415
- print (annotation )
453
+ response = dataset .refloc (annotation .reference_id )["annotations" ][
454
+ "multicategory"
455
+ ]
456
+ assert len (response ) == 1
457
+ response_annotation = response [0 ]
458
+ assert_multicategory_annotation_matches_dict (
459
+ response_annotation , annotation_update_params
460
+ )
416
461
417
- response = dataset .annotate (annotations = [annotation ])
418
462
419
- assert response ["annotations_processed" ] == 1
463
+ def test_multicategory_gt_upload_ignore (dataset ):
464
+ annotation = MultiCategoryAnnotation .from_json (
465
+ TEST_MULTICATEGORY_ANNOTATIONS [0 ]
466
+ )
467
+ response = dataset .annotate (annotations = [annotation ])
468
+
469
+ assert response ["annotations_processed" ] == 1
470
+
471
+ # Copy so we don't modify the original.
472
+ annotation_update_params = dict (TEST_MULTICATEGORY_ANNOTATIONS [1 ])
473
+ annotation_update_params ["reference_id" ] = TEST_MULTICATEGORY_ANNOTATIONS [
474
+ 0
475
+ ]["reference_id" ]
476
+
477
+ annotation_update = MultiCategoryAnnotation .from_json (
478
+ annotation_update_params
479
+ )
480
+ # Default behavior is ignore.
481
+ response = dataset .annotate (annotations = [annotation_update ])
482
+
483
+ assert response ["annotations_processed" ] == 0
484
+ assert response ["annotations_ignored" ] == 1
485
+
486
+ response = dataset .refloc (annotation .reference_id )["annotations" ][
487
+ "multicategory"
488
+ ]
489
+ assert len (response ) == 1
490
+ response_annotation = response [0 ]
491
+ assert_multicategory_annotation_matches_dict (
492
+ response_annotation , TEST_MULTICATEGORY_ANNOTATIONS [0 ]
493
+ )
494
+
495
+
496
+ @pytest .mark .integration
497
+ def test_box_gt_deletion (dataset ):
498
+ annotation = BoxAnnotation (** TEST_BOX_ANNOTATIONS [0 ])
499
+
500
+ print (annotation )
501
+
502
+ response = dataset .annotate (annotations = [annotation ])
503
+
504
+ assert response ["annotations_processed" ] == 1
505
+
506
+ job = dataset .delete_annotations ()
507
+ job .sleep_until_complete ()
508
+ job_status = job .status ()
509
+ assert job_status ["status" ] == "Completed"
510
+ assert job_status ["job_id" ] == job .job_id
511
+
512
+
513
+ @pytest .mark .integration
514
+ def test_category_gt_deletion (dataset ):
515
+ annotation = CategoryAnnotation .from_json (TEST_CATEGORY_ANNOTATIONS [0 ])
516
+
517
+ print (annotation )
518
+
519
+ response = dataset .annotate (annotations = [annotation ])
520
+
521
+ assert response ["annotations_processed" ] == 1
522
+
523
+ job = dataset .delete_annotations ()
524
+ job .sleep_until_complete ()
525
+ job_status = job .status ()
526
+ assert job_status ["status" ] == "Completed"
527
+ assert job_status ["job_id" ] == job .job_id
528
+
529
+
530
+ @pytest .mark .integration
531
+ def test_multicategory_gt_deletion (dataset ):
532
+ annotation = MultiCategoryAnnotation .from_json (
533
+ TEST_MULTICATEGORY_ANNOTATIONS [0 ]
534
+ )
535
+
536
+ print (annotation )
537
+
538
+ response = dataset .annotate (annotations = [annotation ])
539
+
540
+ assert response ["annotations_processed" ] == 1
420
541
421
- job = dataset .delete_annotations ()
422
- job .sleep_until_complete ()
423
- job_status = job .status ()
424
- assert job_status ["status" ] == "Completed"
425
- assert job_status ["job_id" ] == job .id
542
+ job = dataset .delete_annotations ()
543
+ job .sleep_until_complete ()
544
+ job_status = job .status ()
545
+ assert job_status ["status" ] == "Completed"
546
+ assert job_status ["job_id" ] == job .job_id
0 commit comments