|
| 1 | +from nucleus.annotation import SegmentationAnnotation |
| 2 | +from tests.helpers import ( |
| 3 | + TEST_LOCAL_MASK_URL, |
| 4 | + TEST_SEGMENTATION_ANNOTATIONS, |
| 5 | + assert_segmentation_annotation_matches_dict, |
| 6 | +) |
| 7 | + |
| 8 | + |
| 9 | +def test_single_local_semseg_gt_upload(dataset): |
| 10 | + annotation = SegmentationAnnotation.from_json( |
| 11 | + TEST_SEGMENTATION_ANNOTATIONS[0] |
| 12 | + ) |
| 13 | + annotation.mask_url = TEST_LOCAL_MASK_URL |
| 14 | + response = dataset.annotate(annotations=[annotation]) |
| 15 | + |
| 16 | + assert response["dataset_id"] == dataset.id |
| 17 | + assert response["annotations_processed"] == 1 |
| 18 | + assert response["annotations_ignored"] == 0 |
| 19 | + |
| 20 | + response_annotation = dataset.refloc(annotation.reference_id)[ |
| 21 | + "annotations" |
| 22 | + ]["segmentation"][0] |
| 23 | + assert_segmentation_annotation_matches_dict( |
| 24 | + response_annotation, TEST_SEGMENTATION_ANNOTATIONS[0] |
| 25 | + ) |
| 26 | + |
| 27 | + |
| 28 | +def test_single_semseg_gt_upload(dataset): |
| 29 | + annotation = SegmentationAnnotation.from_json( |
| 30 | + TEST_SEGMENTATION_ANNOTATIONS[0] |
| 31 | + ) |
| 32 | + response = dataset.annotate(annotations=[annotation]) |
| 33 | + assert response["dataset_id"] == dataset.id |
| 34 | + assert response["annotations_processed"] == 1 |
| 35 | + assert response["annotations_ignored"] == 0 |
| 36 | + |
| 37 | + response_annotation = dataset.refloc(annotation.reference_id)[ |
| 38 | + "annotations" |
| 39 | + ]["segmentation"][0] |
| 40 | + assert_segmentation_annotation_matches_dict( |
| 41 | + response_annotation, TEST_SEGMENTATION_ANNOTATIONS[0] |
| 42 | + ) |
| 43 | + |
| 44 | + |
| 45 | +def test_batch_semseg_gt_upload(dataset): |
| 46 | + annotations = [ |
| 47 | + SegmentationAnnotation.from_json(ann) |
| 48 | + for ann in TEST_SEGMENTATION_ANNOTATIONS |
| 49 | + ] |
| 50 | + response = dataset.annotate(annotations=annotations) |
| 51 | + assert response["dataset_id"] == dataset.id |
| 52 | + assert response["annotations_processed"] == 5 |
| 53 | + assert response["annotations_ignored"] == 0 |
| 54 | + |
| 55 | + |
| 56 | +def test_batch_semseg_gt_upload_ignore(dataset): |
| 57 | + # First upload annotations |
| 58 | + annotations = [ |
| 59 | + SegmentationAnnotation.from_json(ann) |
| 60 | + for ann in TEST_SEGMENTATION_ANNOTATIONS |
| 61 | + ] |
| 62 | + response = dataset.annotate(annotations=annotations) |
| 63 | + assert response["dataset_id"] == dataset.id |
| 64 | + assert response["annotations_processed"] == 5 |
| 65 | + assert response["annotations_ignored"] == 0 |
| 66 | + |
| 67 | + # When we re-upload, expect them to be ignored |
| 68 | + response = dataset.annotate(annotations=annotations) |
| 69 | + assert response["dataset_id"] == dataset.id |
| 70 | + assert response["annotations_processed"] == 0 |
| 71 | + assert response["annotations_ignored"] == 5 |
| 72 | + |
| 73 | + |
| 74 | +def test_batch_semseg_gt_upload_update(dataset): |
| 75 | + # First upload annotations |
| 76 | + annotations = [ |
| 77 | + SegmentationAnnotation.from_json(ann) |
| 78 | + for ann in TEST_SEGMENTATION_ANNOTATIONS |
| 79 | + ] |
| 80 | + response = dataset.annotate(annotations=annotations) |
| 81 | + assert response["dataset_id"] == dataset.id |
| 82 | + assert response["annotations_processed"] == 5 |
| 83 | + assert response["annotations_ignored"] == 0 |
| 84 | + |
| 85 | + # When we re-upload, expect uploads to be processed |
| 86 | + response = dataset.annotate(annotations=annotations, update=True) |
| 87 | + assert response["dataset_id"] == dataset.id |
| 88 | + assert response["annotations_processed"] == 5 |
| 89 | + assert response["annotations_ignored"] == 0 |
0 commit comments