def test_box_gt_upload_ignore(dataset): annotation = BoxAnnotation(**TEST_BOX_ANNOTATIONS[0]) response = dataset.annotate(annotations=[annotation]) assert response["annotations_processed"] == 1 # Copy so we don't modify the original. annotation_update_params = dict(TEST_BOX_ANNOTATIONS[1]) annotation_update_params["annotation_id"] = TEST_BOX_ANNOTATIONS[0][ "annotation_id" ] annotation_update_params["reference_id"] = TEST_BOX_ANNOTATIONS[0][ "reference_id" ] annotation_update = BoxAnnotation(**annotation_update_params) # Default behavior is ignore. response = dataset.annotate(annotations=[annotation_update]) assert response["annotations_processed"] == 1 assert response["annotations_ignored"] == 1 response = dataset.refloc(annotation.reference_id)["annotations"]["box"] assert len(response) == 1 response_annotation = response[0] assert_box_annotation_matches_dict( response_annotation, TEST_BOX_ANNOTATIONS[0] )
def test_slice_create_and_export(dataset): # Dataset upload url = TEST_IMG_URLS[0] annotation_in_slice = BoxAnnotation(**TEST_BOX_ANNOTATIONS[0]) ds_items = [ DatasetItem( image_location=url, reference_id=reference_id_from_url(url), metadata={"test": "metadata"}, ), DatasetItem( image_location=url, reference_id="different_item", metadata={"test": "metadata"}, ), ] response = dataset.append(ds_items) assert ERROR_PAYLOAD not in response.json() # Slice creation slc = dataset.create_slice( name=TEST_SLICE_NAME, reference_ids=[item.reference_id for item in ds_items[:1]], ) dataset.annotate(annotations=[annotation_in_slice]) expected_box_annotation = copy.deepcopy(annotation_in_slice) expected_box_annotation.annotation_id = None expected_box_annotation.metadata = {} exported = slc.items_and_annotations() assert exported[0][ITEM_KEY] == ds_items[0] assert exported[0][ANNOTATIONS_KEY][BOX_TYPE][0] == expected_box_annotation
def test_box_gt_upload(dataset): annotation = BoxAnnotation(**TEST_BOX_ANNOTATIONS[0]) response = dataset.annotate(annotations=[annotation]) assert response["dataset_id"] == dataset.id assert response["annotations_processed"] == 1 assert response["annotations_ignored"] == 0 response = dataset.refloc(annotation.reference_id)["annotations"]["box"] assert len(response) == 1 response_annotation = response[0] assert_box_annotation_matches_dict(response_annotation, TEST_BOX_ANNOTATIONS[0])
def test_box_gt_deletion(dataset): annotation = BoxAnnotation(**TEST_BOX_ANNOTATIONS[0]) print(annotation) response = dataset.annotate(annotations=[annotation]) assert response["annotations_processed"] == 1 job = dataset.delete_annotations() job.sleep_until_complete() job_status = job.status() assert job_status["status"] == "Completed" assert job_status["job_id"] == job.id
def test_reprs(): # Have to define here in order to have access to all relevant objects def test_repr(test_object: any): assert eval(str(test_object)) == test_object [ test_repr(SegmentationAnnotation.from_json(_)) for _ in TEST_SEGMENTATION_ANNOTATIONS ] [test_repr(BoxAnnotation.from_json(_)) for _ in TEST_BOX_ANNOTATIONS] [ test_repr(PolygonAnnotation.from_json(_)) for _ in TEST_POLYGON_ANNOTATIONS ]
def test_mixed_annotation_upload(dataset): # First upload annotations semseg_annotations = [ SegmentationAnnotation.from_json(ann) for ann in TEST_SEGMENTATION_ANNOTATIONS ] bbox_annotations = [BoxAnnotation(**(ann)) for ann in TEST_BOX_ANNOTATIONS] annotations = bbox_annotations + semseg_annotations response = dataset.annotate(annotations=annotations) assert response["dataset_id"] == dataset.id assert response["annotations_processed"] == 10 assert response["annotations_ignored"] == 0 response_annotations = dataset.refloc( bbox_annotations[0].reference_id)["annotations"] assert len(response_annotations) == 2 assert len(response_annotations["box"]) == 1 assert "segmentation" in response_annotations