From c74ea18b73979d27ee621db7b66f5e25baa45fda Mon Sep 17 00:00:00 2001 From: Gabefire <33893811+Gabefire@users.noreply.github.com> Date: Wed, 11 Sep 2024 11:13:31 -0500 Subject: [PATCH 01/11] started unit test --- .../serialization/ndjson/test_checklist.py | 20 - .../ndjson/test_classification.py | 114 +- .../serialization/ndjson/test_conversation.py | 234 ++-- .../serialization/ndjson/test_data_gen.py | 59 +- .../data/serialization/ndjson/test_dicom.py | 212 ++- .../serialization/ndjson/test_document.py | 332 ++++- .../ndjson/test_export_video_objects.py | 1164 ++++++++--------- .../serialization/ndjson/test_free_text.py | 139 +- .../serialization/ndjson/test_global_key.py | 118 +- 9 files changed, 1340 insertions(+), 1052 deletions(-) diff --git a/libs/labelbox/tests/data/serialization/ndjson/test_checklist.py b/libs/labelbox/tests/data/serialization/ndjson/test_checklist.py index c4b47427a..ebcde0ea4 100644 --- a/libs/labelbox/tests/data/serialization/ndjson/test_checklist.py +++ b/libs/labelbox/tests/data/serialization/ndjson/test_checklist.py @@ -35,13 +35,6 @@ def test_serialization_min(): res.pop("uuid") assert res == expected - deserialized = NDJsonConverter.deserialize([res]) - res = next(deserialized) - for i, annotation in enumerate(res.annotations): - annotation.extra.pop("uuid") - assert annotation.value == label.annotations[i].value - assert annotation.name == label.annotations[i].name - def test_serialization_with_classification(): label = Label( @@ -117,10 +110,6 @@ def test_serialization_with_classification(): res.pop("uuid") assert res == expected - deserialized = NDJsonConverter.deserialize([res]) - res = next(deserialized) - assert label.model_dump(exclude_none=True) == label.model_dump(exclude_none=True) - def test_serialization_with_classification_double_nested(): label = Label( @@ -200,11 +189,6 @@ def test_serialization_with_classification_double_nested(): res.pop("uuid") assert res == expected - deserialized = NDJsonConverter.deserialize([res]) - res = next(deserialized) - res.annotations[0].extra.pop("uuid") - assert label.model_dump(exclude_none=True) == label.model_dump(exclude_none=True) - def test_serialization_with_classification_double_nested_2(): label = Label( @@ -278,7 +262,3 @@ def test_serialization_with_classification_double_nested_2(): res = next(serialized) res.pop("uuid") assert res == expected - - deserialized = NDJsonConverter.deserialize([res]) - res = next(deserialized) - assert label.model_dump(exclude_none=True) == label.model_dump(exclude_none=True) diff --git a/libs/labelbox/tests/data/serialization/ndjson/test_classification.py b/libs/labelbox/tests/data/serialization/ndjson/test_classification.py index 00a684b20..efb3f0cf7 100644 --- a/libs/labelbox/tests/data/serialization/ndjson/test_classification.py +++ b/libs/labelbox/tests/data/serialization/ndjson/test_classification.py @@ -1,21 +1,119 @@ import json +from labelbox.data.annotation_types.classification.classification import ( + Checklist, + Radio, + Text, +) from labelbox.data.serialization.ndjson.converter import NDJsonConverter +from labelbox.types import ( + Label, + ClassificationAnnotation, + ClassificationAnswer, + GenericDataRowData, +) +from labelbox.data.mixins import CustomMetric + def test_classification(): - with open('tests/data/assets/ndjson/classification_import.json', - 'r') as file: + with open("tests/data/assets/ndjson/classification_import.json", "r") as file: data = json.load(file) - res = list(NDJsonConverter.deserialize(data)) - res = list(NDJsonConverter.serialize(res)) + + label = Label( + data=GenericDataRowData( + uid="ckrb1sf1i1g7i0ybcdc6oc8ct", + ), + annotations=[ + ClassificationAnnotation( + feature_schema_id="ckrb1sfjx099a0y914hl319ie", + extra={"uuid": "f6879f59-d2b5-49c2-aceb-d9e8dc478673"}, + value=Radio( + answer=ClassificationAnswer( + custom_metrics=[ + CustomMetric(name="customMetric1", value=0.5), + CustomMetric(name="customMetric2", value=0.3), + ], + confidence=0.8, + feature_schema_id="ckrb1sfl8099g0y91cxbd5ftb", + ), + ), + ), + ClassificationAnnotation( + feature_schema_id="ckrb1sfkn099c0y910wbo0p1a", + extra={"uuid": "d009925d-91a3-4f67-abd9-753453f5a584"}, + value=Checklist( + answer=[ + ClassificationAnswer( + custom_metrics=[ + CustomMetric(name="customMetric1", value=0.5), + CustomMetric(name="customMetric2", value=0.3), + ], + confidence=0.82, + feature_schema_id="ckrb1sfl8099e0y919v260awv", + ) + ], + ), + ), + ClassificationAnnotation( + feature_schema_id="ckrb1sfkn099c0y910wbo0p1a", + extra={"uuid": "78ff6a23-bebe-475c-8f67-4c456909648f"}, + value=Text(answer="a value"), + ), + ], + ) + + res = list(NDJsonConverter.serialize([label])) assert res == data def test_classification_with_name(): - with open('tests/data/assets/ndjson/classification_import_name_only.json', - 'r') as file: + with open( + "tests/data/assets/ndjson/classification_import_name_only.json", "r" + ) as file: data = json.load(file) - res = list(NDJsonConverter.deserialize(data)) - res = list(NDJsonConverter.serialize(res)) + label = Label( + data=GenericDataRowData( + uid="ckrb1sf1i1g7i0ybcdc6oc8ct", + ), + annotations=[ + ClassificationAnnotation( + name="classification a", + extra={"uuid": "f6879f59-d2b5-49c2-aceb-d9e8dc478673"}, + value=Radio( + answer=ClassificationAnswer( + custom_metrics=[ + CustomMetric(name="customMetric1", value=0.5), + CustomMetric(name="customMetric2", value=0.3), + ], + confidence=0.99, + name="choice 1", + ), + ), + ), + ClassificationAnnotation( + name="classification b", + extra={"uuid": "d009925d-91a3-4f67-abd9-753453f5a584"}, + value=Checklist( + answer=[ + ClassificationAnswer( + custom_metrics=[ + CustomMetric(name="customMetric1", value=0.5), + CustomMetric(name="customMetric2", value=0.3), + ], + confidence=0.945, + name="choice 2", + ) + ], + ), + ), + ClassificationAnnotation( + name="classification c", + extra={"uuid": "150d60de-30af-44e4-be20-55201c533312"}, + value=Text(answer="a value"), + ), + ], + ) + + res = list(NDJsonConverter.serialize([label])) assert res == data diff --git a/libs/labelbox/tests/data/serialization/ndjson/test_conversation.py b/libs/labelbox/tests/data/serialization/ndjson/test_conversation.py index 4d2a0416c..4d995a9ef 100644 --- a/libs/labelbox/tests/data/serialization/ndjson/test_conversation.py +++ b/libs/labelbox/tests/data/serialization/ndjson/test_conversation.py @@ -3,131 +3,183 @@ import pytest import labelbox.types as lb_types from labelbox.data.serialization.ndjson.converter import NDJsonConverter - -radio_ndjson = [{ - 'dataRow': { - 'globalKey': 'my_global_key' - }, - 'name': 'radio', - 'answer': { - 'name': 'first_radio_answer' - }, - 'messageId': '0' -}] +from labelbox.data.mixins import CustomMetric + +radio_ndjson = [ + { + "dataRow": {"globalKey": "my_global_key"}, + "name": "radio", + "answer": {"name": "first_radio_answer"}, + "messageId": "0", + } +] radio_label = [ lb_types.Label( - data=lb_types.ConversationData(global_key='my_global_key'), + data=lb_types.ConversationData(global_key="my_global_key"), annotations=[ lb_types.ClassificationAnnotation( - name='radio', - value=lb_types.Radio(answer=lb_types.ClassificationAnswer( - name="first_radio_answer")), - message_id="0") - ]) + name="radio", + value=lb_types.Radio( + answer=lb_types.ClassificationAnswer(name="first_radio_answer") + ), + message_id="0", + ) + ], + ) ] -checklist_ndjson = [{ - 'dataRow': { - 'globalKey': 'my_global_key' - }, - 'name': 'checklist', - 'answer': [ - { - 'name': 'first_checklist_answer' - }, - { - 'name': 'second_checklist_answer' - }, - ], - 'messageId': '2' -}] +checklist_ndjson = [ + { + "dataRow": {"globalKey": "my_global_key"}, + "name": "checklist", + "answer": [ + {"name": "first_checklist_answer"}, + {"name": "second_checklist_answer"}, + ], + "messageId": "2", + } +] checklist_label = [ - lb_types.Label(data=lb_types.ConversationData(global_key='my_global_key'), - annotations=[ - lb_types.ClassificationAnnotation( - name='checklist', - message_id="2", - value=lb_types.Checklist(answer=[ - lb_types.ClassificationAnswer( - name="first_checklist_answer"), - lb_types.ClassificationAnswer( - name="second_checklist_answer") - ])) - ]) + lb_types.Label( + data=lb_types.ConversationData(global_key="my_global_key"), + annotations=[ + lb_types.ClassificationAnnotation( + name="checklist", + message_id="2", + value=lb_types.Checklist( + answer=[ + lb_types.ClassificationAnswer(name="first_checklist_answer"), + lb_types.ClassificationAnswer(name="second_checklist_answer"), + ] + ), + ) + ], + ) ] -free_text_ndjson = [{ - 'dataRow': { - 'globalKey': 'my_global_key' - }, - 'name': 'free_text', - 'answer': 'sample text', - 'messageId': '0' -}] +free_text_ndjson = [ + { + "dataRow": {"globalKey": "my_global_key"}, + "name": "free_text", + "answer": "sample text", + "messageId": "0", + } +] free_text_label = [ - lb_types.Label(data=lb_types.ConversationData(global_key='my_global_key'), - annotations=[ - lb_types.ClassificationAnnotation( - name='free_text', - message_id="0", - value=lb_types.Text(answer="sample text")) - ]) + lb_types.Label( + data=lb_types.ConversationData(global_key="my_global_key"), + annotations=[ + lb_types.ClassificationAnnotation( + name="free_text", + message_id="0", + value=lb_types.Text(answer="sample text"), + ) + ], + ) ] @pytest.mark.parametrize( "label, ndjson", - [[radio_label, radio_ndjson], [checklist_label, checklist_ndjson], - [free_text_label, free_text_ndjson]]) + [ + [radio_label, radio_ndjson], + [checklist_label, checklist_ndjson], + [free_text_label, free_text_ndjson], + ], +) def test_message_based_radio_classification(label, ndjson): serialized_label = list(NDJsonConverter().serialize(label)) - serialized_label[0].pop('uuid') + serialized_label[0].pop("uuid") assert serialized_label == ndjson - deserialized_label = list(NDJsonConverter().deserialize(ndjson)) - deserialized_label[0].annotations[0].extra.pop('uuid') - assert deserialized_label[0].model_dump(exclude_none=True) == label[0].model_dump(exclude_none=True) +def test_conversation_entity_import(): + with open("tests/data/assets/ndjson/conversation_entity_import.json", "r") as file: + data = json.load(file) + + label = lb_types.Label( + data=lb_types.GenericDataRowData( + uid="cl6xnv9h61fv0085yhtoq06ht", + ), + annotations=[ + lb_types.ObjectAnnotation( + custom_metrics=[ + CustomMetric(name="customMetric1", value=0.5), + CustomMetric(name="customMetric2", value=0.3), + ], + confidence=0.53, + name="some-text-entity", + feature_schema_id="cl6xnuwt95lqq07330tbb3mfd", + extra={"uuid": "5ad9c52f-058d-49c8-a749-3f20b84f8cd4"}, + value=lb_types.ConversationEntity( + start=67, end=128, message_id="some-message-id" + ), + ) + ], + ) -@pytest.mark.parametrize("filename", [ - "tests/data/assets/ndjson/conversation_entity_import.json", - "tests/data/assets/ndjson/conversation_entity_without_confidence_import.json" -]) -def test_conversation_entity_import(filename: str): - with open(filename, 'r') as file: + res = list(NDJsonConverter.serialize([label])) + assert res == data + + +def test_conversation_entity_import_without_confidence(): + with open( + "tests/data/assets/ndjson/conversation_entity_without_confidence_import.json", + "r", + ) as file: data = json.load(file) - res = list(NDJsonConverter.deserialize(data)) - res = list(NDJsonConverter.serialize(res)) + label = lb_types.Label( + uid=None, + data=lb_types.GenericDataRowData( + uid="cl6xnv9h61fv0085yhtoq06ht", + ), + annotations=[ + lb_types.ObjectAnnotation( + name="some-text-entity", + feature_schema_id="cl6xnuwt95lqq07330tbb3mfd", + extra={"uuid": "5ad9c52f-058d-49c8-a749-3f20b84f8cd4"}, + value=lb_types.ConversationEntity( + start=67, end=128, extra={}, message_id="some-message-id" + ), + ) + ], + ) + + res = list(NDJsonConverter.serialize([label])) assert res == data def test_benchmark_reference_label_flag_enabled(): - label = lb_types.Label(data=lb_types.ConversationData(global_key='my_global_key'), - annotations=[ - lb_types.ClassificationAnnotation( - name='free_text', - message_id="0", - value=lb_types.Text(answer="sample text")) - ], - is_benchmark_reference=True - ) + label = lb_types.Label( + data=lb_types.ConversationData(global_key="my_global_key"), + annotations=[ + lb_types.ClassificationAnnotation( + name="free_text", + message_id="0", + value=lb_types.Text(answer="sample text"), + ) + ], + is_benchmark_reference=True, + ) res = list(NDJsonConverter.serialize([label])) assert res[0]["isBenchmarkReferenceLabel"] def test_benchmark_reference_label_flag_disabled(): - label = lb_types.Label(data=lb_types.ConversationData(global_key='my_global_key'), - annotations=[ - lb_types.ClassificationAnnotation( - name='free_text', - message_id="0", - value=lb_types.Text(answer="sample text")) - ], - is_benchmark_reference=False - ) + label = lb_types.Label( + data=lb_types.ConversationData(global_key="my_global_key"), + annotations=[ + lb_types.ClassificationAnnotation( + name="free_text", + message_id="0", + value=lb_types.Text(answer="sample text"), + ) + ], + is_benchmark_reference=False, + ) res = list(NDJsonConverter.serialize([label])) assert not res[0].get("isBenchmarkReferenceLabel") diff --git a/libs/labelbox/tests/data/serialization/ndjson/test_data_gen.py b/libs/labelbox/tests/data/serialization/ndjson/test_data_gen.py index 186c75223..d870d9618 100644 --- a/libs/labelbox/tests/data/serialization/ndjson/test_data_gen.py +++ b/libs/labelbox/tests/data/serialization/ndjson/test_data_gen.py @@ -1,55 +1,26 @@ -from copy import copy -import pytest import labelbox.types as lb_types from labelbox.data.serialization import NDJsonConverter -from labelbox.data.serialization.ndjson.objects import NDDicomSegments, NDDicomSegment, NDDicomLine -""" -Data gen prompt test data -""" -prompt_text_annotation = lb_types.PromptClassificationAnnotation( - feature_schema_id="ckrb1sfkn099c0y910wbo0p1a", - name="test", - value=lb_types.PromptText(answer="the answer to the text questions right here"), - ) -prompt_text_ndjson = { +def test_serialize_label(): + prompt_text_annotation = lb_types.PromptClassificationAnnotation( + feature_schema_id="ckrb1sfkn099c0y910wbo0p1a", + name="test", + extra={"uuid": "test"}, + value=lb_types.PromptText(answer="the answer to the text questions right here"), + ) + + prompt_text_ndjson = { "answer": "the answer to the text questions right here", "name": "test", "schemaId": "ckrb1sfkn099c0y910wbo0p1a", - "dataRow": { - "id": "ckrb1sf1i1g7i0ybcdc6oc8ct" - }, + "dataRow": {"id": "ckrb1sf1i1g7i0ybcdc6oc8ct"}, + "uuid": "test", } -data_gen_label = lb_types.Label( - data={"uid": "ckrb1sf1i1g7i0ybcdc6oc8ct"}, - annotations=[prompt_text_annotation] -) - -""" -Prompt annotation test -""" - -def test_serialize_label(): + data_gen_label = lb_types.Label( + data={"uid": "ckrb1sf1i1g7i0ybcdc6oc8ct"}, annotations=[prompt_text_annotation] + ) serialized_label = next(NDJsonConverter().serialize([data_gen_label])) - # Remove uuid field since this is a random value that can not be specified also meant for relationships - del serialized_label["uuid"] - assert serialized_label == prompt_text_ndjson - -def test_deserialize_label(): - deserialized_label = next(NDJsonConverter().deserialize([prompt_text_ndjson])) - if hasattr(deserialized_label.annotations[0], 'extra'): - # Extra fields are added to deserialized label by default need removed to match - deserialized_label.annotations[0].extra = {} - assert deserialized_label.model_dump(exclude_none=True) == data_gen_label.model_dump(exclude_none=True) - - -def test_serialize_deserialize_label(): - serialized = list(NDJsonConverter.serialize([data_gen_label])) - deserialized = next(NDJsonConverter.deserialize(serialized)) - if hasattr(deserialized.annotations[0], 'extra'): - # Extra fields are added to deserialized label by default need removed to match - deserialized.annotations[0].extra = {} - assert deserialized.model_dump(exclude_none=True) == data_gen_label.model_dump(exclude_none=True) + assert serialized_label == prompt_text_ndjson diff --git a/libs/labelbox/tests/data/serialization/ndjson/test_dicom.py b/libs/labelbox/tests/data/serialization/ndjson/test_dicom.py index e69c21bae..e6ccba3b7 100644 --- a/libs/labelbox/tests/data/serialization/ndjson/test_dicom.py +++ b/libs/labelbox/tests/data/serialization/ndjson/test_dicom.py @@ -1,129 +1,114 @@ from copy import copy import pytest -import base64 import labelbox.types as lb_types from labelbox.data.serialization import NDJsonConverter -from labelbox.data.serialization.ndjson.objects import NDDicomSegments, NDDicomSegment, NDDicomLine +from labelbox.data.serialization.ndjson.objects import ( + NDDicomSegments, + NDDicomSegment, + NDDicomLine, +) + """ Polyline test data """ dicom_polyline_annotations = [ - lb_types.DICOMObjectAnnotation(uuid="78a8a027-9089-420c-8348-6099eb77e4aa", - name="dicom_polyline", - frame=2, - value=lb_types.Line(points=[ - lb_types.Point(x=680, y=100), - lb_types.Point(x=100, y=190), - lb_types.Point(x=190, y=220) - ]), - segment_index=0, - keyframe=True, - group_key=lb_types.GroupKey.AXIAL) + lb_types.DICOMObjectAnnotation( + uuid="78a8a027-9089-420c-8348-6099eb77e4aa", + name="dicom_polyline", + frame=2, + value=lb_types.Line( + points=[ + lb_types.Point(x=680, y=100), + lb_types.Point(x=100, y=190), + lb_types.Point(x=190, y=220), + ] + ), + segment_index=0, + keyframe=True, + group_key=lb_types.GroupKey.AXIAL, + ) ] -polyline_label = lb_types.Label(data=lb_types.DicomData(uid="test-uid"), - annotations=dicom_polyline_annotations) +polyline_label = lb_types.Label( + data=lb_types.DicomData(uid="test-uid"), annotations=dicom_polyline_annotations +) polyline_annotation_ndjson = { - 'classifications': [], - 'dataRow': { - 'id': 'test-uid' - }, - 'name': - 'dicom_polyline', - 'groupKey': - 'axial', - 'segments': [{ - 'keyframes': [{ - 'frame': 2, - 'line': [ - { - 'x': 680.0, - 'y': 100.0 - }, - { - 'x': 100.0, - 'y': 190.0 - }, + "classifications": [], + "dataRow": {"id": "test-uid"}, + "name": "dicom_polyline", + "groupKey": "axial", + "segments": [ + { + "keyframes": [ { - 'x': 190.0, - 'y': 220.0 - }, - ], - 'classifications': [], - }] - }], + "frame": 2, + "line": [ + {"x": 680.0, "y": 100.0}, + {"x": 100.0, "y": 190.0}, + {"x": 190.0, "y": 220.0}, + ], + "classifications": [], + } + ] + } + ], } polyline_with_global_key = lb_types.Label( data=lb_types.DicomData(global_key="test-global-key"), - annotations=dicom_polyline_annotations) + annotations=dicom_polyline_annotations, +) polyline_annotation_ndjson_with_global_key = copy(polyline_annotation_ndjson) -polyline_annotation_ndjson_with_global_key['dataRow'] = { - 'globalKey': 'test-global-key' -} +polyline_annotation_ndjson_with_global_key["dataRow"] = {"globalKey": "test-global-key"} """ Video test data """ -instance_uri_1 = 'https://storage.labelbox.com/cjhfn5y6s0pk507024nz1ocys%2F1d60856c-59b7-3060-2754-83f7e93e0d01-1?Expires=1666901963361&KeyName=labelbox-assets-key-3&Signature=t-2s2DB4YjFuWEFak0wxYqfBfZA' -instance_uri_5 = 'https://storage.labelbox.com/cjhfn5y6s0pk507024nz1ocys1%2F1d60856c-59b7-3060-2754-83f7e93e0d01-1?Expires=1666901963361&KeyName=labelbox-assets-key-3&Signature=t-2s2DB4YjFuWEFak0wxYqfBfZA' +instance_uri_1 = "https://storage.labelbox.com/cjhfn5y6s0pk507024nz1ocys%2F1d60856c-59b7-3060-2754-83f7e93e0d01-1?Expires=1666901963361&KeyName=labelbox-assets-key-3&Signature=t-2s2DB4YjFuWEFak0wxYqfBfZA" +instance_uri_5 = "https://storage.labelbox.com/cjhfn5y6s0pk507024nz1ocys1%2F1d60856c-59b7-3060-2754-83f7e93e0d01-1?Expires=1666901963361&KeyName=labelbox-assets-key-3&Signature=t-2s2DB4YjFuWEFak0wxYqfBfZA" frames = [ lb_types.MaskFrame(index=1, instance_uri=instance_uri_1), - lb_types.MaskFrame(index=5, instance_uri=instance_uri_5) + lb_types.MaskFrame(index=5, instance_uri=instance_uri_5), ] instances = [ lb_types.MaskInstance(color_rgb=(0, 0, 255), name="mask1"), lb_types.MaskInstance(color_rgb=(0, 255, 0), name="mask2"), - lb_types.MaskInstance(color_rgb=(255, 0, 0), name="mask3") + lb_types.MaskInstance(color_rgb=(255, 0, 0), name="mask3"), ] -video_mask_annotation = lb_types.VideoMaskAnnotation(frames=frames, - instances=instances) +video_mask_annotation = lb_types.VideoMaskAnnotation(frames=frames, instances=instances) video_mask_annotation_ndjson = { - 'dataRow': { - 'id': 'test-uid' - }, - 'masks': { - 'frames': [{ - 'index': 1, - 'instanceURI': instance_uri_1 - }, { - 'index': 5, - 'instanceURI': instance_uri_5 - }], - 'instances': [ - { - 'colorRGB': (0, 0, 255), - 'name': 'mask1' - }, - { - 'colorRGB': (0, 255, 0), - 'name': 'mask2' - }, - { - 'colorRGB': (255, 0, 0), - 'name': 'mask3' - }, - ] + "dataRow": {"id": "test-uid"}, + "masks": { + "frames": [ + {"index": 1, "instanceURI": instance_uri_1}, + {"index": 5, "instanceURI": instance_uri_5}, + ], + "instances": [ + {"colorRGB": (0, 0, 255), "name": "mask1"}, + {"colorRGB": (0, 255, 0), "name": "mask2"}, + {"colorRGB": (255, 0, 0), "name": "mask3"}, + ], }, } -video_mask_annotation_ndjson_with_global_key = copy( - video_mask_annotation_ndjson) -video_mask_annotation_ndjson_with_global_key['dataRow'] = { - 'globalKey': 'test-global-key' +video_mask_annotation_ndjson_with_global_key = copy(video_mask_annotation_ndjson) +video_mask_annotation_ndjson_with_global_key["dataRow"] = { + "globalKey": "test-global-key" } -video_mask_label = lb_types.Label(data=lb_types.VideoData(uid="test-uid"), - annotations=[video_mask_annotation]) +video_mask_label = lb_types.Label( + data=lb_types.VideoData(uid="test-uid"), annotations=[video_mask_annotation] +) video_mask_label_with_global_key = lb_types.Label( data=lb_types.VideoData(global_key="test-global-key"), - annotations=[video_mask_annotation]) + annotations=[video_mask_annotation], +) """ DICOM Mask test data """ @@ -132,30 +117,35 @@ name="dicom_mask", group_key=lb_types.GroupKey.AXIAL, frames=frames, - instances=instances) + instances=instances, +) -dicom_mask_label = lb_types.Label(data=lb_types.DicomData(uid="test-uid"), - annotations=[dicom_mask_annotation]) +dicom_mask_label = lb_types.Label( + data=lb_types.DicomData(uid="test-uid"), annotations=[dicom_mask_annotation] +) dicom_mask_label_with_global_key = lb_types.Label( data=lb_types.DicomData(global_key="test-global-key"), - annotations=[dicom_mask_annotation]) + annotations=[dicom_mask_annotation], +) dicom_mask_annotation_ndjson = copy(video_mask_annotation_ndjson) -dicom_mask_annotation_ndjson['groupKey'] = 'axial' -dicom_mask_annotation_ndjson_with_global_key = copy( - dicom_mask_annotation_ndjson) -dicom_mask_annotation_ndjson_with_global_key['dataRow'] = { - 'globalKey': 'test-global-key' +dicom_mask_annotation_ndjson["groupKey"] = "axial" +dicom_mask_annotation_ndjson_with_global_key = copy(dicom_mask_annotation_ndjson) +dicom_mask_annotation_ndjson_with_global_key["dataRow"] = { + "globalKey": "test-global-key" } """ Tests """ labels = [ - polyline_label, polyline_with_global_key, dicom_mask_label, - dicom_mask_label_with_global_key, video_mask_label, - video_mask_label_with_global_key + polyline_label, + polyline_with_global_key, + dicom_mask_label, + dicom_mask_label_with_global_key, + video_mask_label, + video_mask_label_with_global_key, ] ndjsons = [ polyline_annotation_ndjson, @@ -175,35 +165,9 @@ def test_deserialize_nd_dicom_segments(): assert isinstance(nd_dicom_segments.segments[0].keyframes[0], NDDicomLine) -@pytest.mark.parametrize('label, ndjson', labels_ndjsons) +@pytest.mark.parametrize("label, ndjson", labels_ndjsons) def test_serialize_label(label, ndjson): serialized_label = next(NDJsonConverter().serialize([label])) if "uuid" in serialized_label: - serialized_label.pop('uuid') + serialized_label.pop("uuid") assert serialized_label == ndjson - - -@pytest.mark.parametrize('label, ndjson', labels_ndjsons) -def test_deserialize_label(label, ndjson): - deserialized_label = next(NDJsonConverter().deserialize([ndjson])) - if hasattr(deserialized_label.annotations[0], 'extra'): - deserialized_label.annotations[0].extra = {} - for i, annotation in enumerate(deserialized_label.annotations): - if hasattr(annotation, "frames"): - assert annotation.frames == label.annotations[i].frames - if hasattr(annotation, "value"): - assert annotation.value == label.annotations[i].value - - - -@pytest.mark.parametrize('label', labels) -def test_serialize_deserialize_label(label): - serialized = list(NDJsonConverter.serialize([label])) - deserialized = list(NDJsonConverter.deserialize(serialized)) - if hasattr(deserialized[0].annotations[0], 'extra'): - deserialized[0].annotations[0].extra = {} - for i, annotation in enumerate(deserialized[0].annotations): - if hasattr(annotation, "frames"): - assert annotation.frames == label.annotations[i].frames - if hasattr(annotation, "value"): - assert annotation.value == label.annotations[i].value diff --git a/libs/labelbox/tests/data/serialization/ndjson/test_document.py b/libs/labelbox/tests/data/serialization/ndjson/test_document.py index cdfbbbb88..87f587496 100644 --- a/libs/labelbox/tests/data/serialization/ndjson/test_document.py +++ b/libs/labelbox/tests/data/serialization/ndjson/test_document.py @@ -1,6 +1,17 @@ import json +from labelbox.data.mixins import CustomMetric import labelbox.types as lb_types from labelbox.data.serialization.ndjson.converter import NDJsonConverter +from labelbox.types import ( + Label, + GenericDataRowData, + ObjectAnnotation, + RectangleUnit, + Point, + DocumentRectangle, + DocumentEntity, + DocumentTextSelection, +) bbox_annotation = lb_types.ObjectAnnotation( name="bounding_box", # must match your ontology feature's name @@ -8,26 +19,30 @@ start=lb_types.Point(x=42.799, y=86.498), # Top left end=lb_types.Point(x=141.911, y=303.195), # Bottom right page=1, - unit=lb_types.RectangleUnit.POINTS)) + unit=lb_types.RectangleUnit.POINTS, + ), +) bbox_labels = [ - lb_types.Label(data=lb_types.DocumentData(global_key='test-global-key'), - annotations=[bbox_annotation]) + lb_types.Label( + data=lb_types.DocumentData(global_key="test-global-key"), + annotations=[bbox_annotation], + ) +] +bbox_ndjson = [ + { + "bbox": { + "height": 216.697, + "left": 42.799, + "top": 86.498, + "width": 99.112, + }, + "classifications": [], + "dataRow": {"globalKey": "test-global-key"}, + "name": "bounding_box", + "page": 1, + "unit": "POINTS", + } ] -bbox_ndjson = [{ - 'bbox': { - 'height': 216.697, - 'left': 42.799, - 'top': 86.498, - 'width': 99.112, - }, - 'classifications': [], - 'dataRow': { - 'globalKey': 'test-global-key' - }, - 'name': 'bounding_box', - 'page': 1, - 'unit': 'POINTS' -}] def round_dict(data): @@ -47,34 +62,283 @@ def test_pdf(): """ Tests a pdf file with bbox annotations only """ - with open('tests/data/assets/ndjson/pdf_import.json', 'r') as f: + with open("tests/data/assets/ndjson/pdf_import.json", "r") as f: data = json.load(f) - res = list(NDJsonConverter.deserialize(data)) - res = list(NDJsonConverter.serialize(res)) + labels = [ + Label( + uid=None, + data=GenericDataRowData( + uid="cl6xnv9h61fv0085yhtoq06ht", + ), + annotations=[ + ObjectAnnotation( + custom_metrics=[ + CustomMetric(name="customMetric1", value=0.5), + CustomMetric(name="customMetric2", value=0.3), + ], + confidence=0.53, + name="boxy", + feature_schema_id="cl6xnuwt95lqq07330tbb3mfd", + extra={ + "uuid": "5ad9c52f-058d-49c8-a749-3f20b84f8cd4", + }, + value=DocumentRectangle( + start=Point(x=32.45, y=162.73), + end=Point(x=134.11, y=550.9), + page=4, + unit=RectangleUnit.POINTS, + ), + ), + ObjectAnnotation( + name="boxy", + feature_schema_id="cl6xnuwt95lqq07330tbb3mfd", + extra={ + "uuid": "20eeef88-0294-49b4-a815-86588476bc6f", + }, + value=DocumentRectangle( + start=Point(x=251.42, y=223.26), + end=Point(x=438.2, y=680.3), + page=7, + unit=RectangleUnit.POINTS, + ), + ), + ObjectAnnotation( + custom_metrics=[ + CustomMetric(name="customMetric1", value=0.5), + CustomMetric(name="customMetric2", value=0.3), + ], + confidence=0.99, + name="boxy", + feature_schema_id="cl6xnuwt95lqq07330tbb3mfd", + extra={ + "uuid": "641a8944-3938-409c-b4eb-dea354ed06e5", + }, + value=DocumentRectangle( + start=Point(x=218.17, y=32.52), + end=Point(x=328.73, y=264.25), + page=6, + unit=RectangleUnit.POINTS, + ), + ), + ObjectAnnotation( + custom_metrics=[ + CustomMetric(name="customMetric1", value=0.5), + CustomMetric(name="customMetric2", value=0.3), + ], + confidence=0.89, + name="boxy", + feature_schema_id="cl6xnuwt95lqq07330tbb3mfd", + extra={ + "uuid": "ebe4da7d-08b3-480a-8d15-26552b7f011c", + }, + value=DocumentRectangle( + start=Point(x=4.25, y=117.39), + end=Point(x=169.08, y=574.3100000000001), + page=7, + unit=RectangleUnit.POINTS, + ), + ), + ObjectAnnotation( + name="boxy", + feature_schema_id="cl6xnuwt95lqq07330tbb3mfd", + extra={ + "uuid": "35c41855-575f-42cc-a2f9-1f06237e9b63", + }, + value=DocumentRectangle( + start=Point(x=217.28, y=82.13), + end=Point(x=299.71000000000004, y=361.89), + page=8, + unit=RectangleUnit.POINTS, + ), + ), + ObjectAnnotation( + name="boxy", + feature_schema_id="cl6xnuwt95lqq07330tbb3mfd", + extra={ + "uuid": "1b009654-bc17-42a2-8a71-160e7808c403", + }, + value=DocumentRectangle( + start=Point(x=83.34, y=298.12), + end=Point(x=83.72, y=501.95000000000005), + page=3, + unit=RectangleUnit.POINTS, + ), + ), + ], + ), + Label( + data=GenericDataRowData( + uid="ckrb1sf1i1g7i0ybcdc6oc8ct", + ), + annotations=[ + ObjectAnnotation( + name="named_entity", + feature_schema_id="cl6xnuwt95lqq07330tbb3mfd", + extra={ + "uuid": "f6879f59-d2b5-49c2-aceb-d9e8dc478673", + }, + value=DocumentEntity( + text_selections=[ + DocumentTextSelection( + token_ids=[ + "3f984bf3-1d61-44f5-b59a-9658a2e3440f", + "3bf00b56-ff12-4e52-8cc1-08dbddb3c3b8", + "6e1c3420-d4b7-4c5a-8fd6-ead43bf73d80", + "87a43d32-af76-4a1d-b262-5c5f4d5ace3a", + "e8606e8a-dfd9-4c49-a635-ad5c879c75d0", + "67c7c19e-4654-425d-bf17-2adb8cf02c30", + "149c5e80-3e07-49a7-ab2d-29ddfe6a38fa", + "b0e94071-2187-461e-8e76-96c58738a52c", + ], + group_id="2f4336f4-a07e-4e0a-a9e1-5629b03b719b", + page=1, + ) + ] + ), + ) + ], + ), + ] + + res = list(NDJsonConverter.serialize(labels)) assert [round_dict(x) for x in res] == [round_dict(x) for x in data] - f.close() def test_pdf_with_name_only(): """ Tests a pdf file with bbox annotations only """ - with open('tests/data/assets/ndjson/pdf_import_name_only.json', 'r') as f: + with open("tests/data/assets/ndjson/pdf_import_name_only.json", "r") as f: data = json.load(f) - res = list(NDJsonConverter.deserialize(data)) - res = list(NDJsonConverter.serialize(res)) + + labels = [ + Label( + data=GenericDataRowData( + uid="cl6xnv9h61fv0085yhtoq06ht", + ), + annotations=[ + ObjectAnnotation( + custom_metrics=[ + CustomMetric(name="customMetric1", value=0.5), + CustomMetric(name="customMetric2", value=0.3), + ], + confidence=0.99, + name="boxy", + feature_schema_id=None, + extra={ + "uuid": "5ad9c52f-058d-49c8-a749-3f20b84f8cd4", + }, + value=DocumentRectangle( + start=Point(x=32.45, y=162.73), + end=Point(x=134.11, y=550.9), + page=4, + unit=RectangleUnit.POINTS, + ), + ), + ObjectAnnotation( + name="boxy", + extra={ + "uuid": "20eeef88-0294-49b4-a815-86588476bc6f", + }, + value=DocumentRectangle( + start=Point(x=251.42, y=223.26), + end=Point(x=438.2, y=680.3), + page=7, + unit=RectangleUnit.POINTS, + ), + ), + ObjectAnnotation( + name="boxy", + extra={ + "uuid": "641a8944-3938-409c-b4eb-dea354ed06e5", + }, + value=DocumentRectangle( + start=Point(x=218.17, y=32.52), + end=Point(x=328.73, y=264.25), + page=6, + unit=RectangleUnit.POINTS, + ), + ), + ObjectAnnotation( + custom_metrics=[ + CustomMetric(name="customMetric1", value=0.5), + CustomMetric(name="customMetric2", value=0.3), + ], + confidence=0.74, + name="boxy", + extra={ + "uuid": "ebe4da7d-08b3-480a-8d15-26552b7f011c", + }, + value=DocumentRectangle( + start=Point(x=4.25, y=117.39), + end=Point(x=169.08, y=574.3100000000001), + page=7, + unit=RectangleUnit.POINTS, + ), + ), + ObjectAnnotation( + name="boxy", + extra={ + "uuid": "35c41855-575f-42cc-a2f9-1f06237e9b63", + }, + value=DocumentRectangle( + start=Point(x=217.28, y=82.13), + end=Point(x=299.71000000000004, y=361.89), + page=8, + unit=RectangleUnit.POINTS, + ), + ), + ObjectAnnotation( + name="boxy", + extra={ + "uuid": "1b009654-bc17-42a2-8a71-160e7808c403", + }, + value=DocumentRectangle( + start=Point(x=83.34, y=298.12), + end=Point(x=83.72, y=501.95000000000005), + page=3, + unit=RectangleUnit.POINTS, + ), + ), + ], + ), + Label( + data=GenericDataRowData( + uid="ckrb1sf1i1g7i0ybcdc6oc8ct", + ), + annotations=[ + ObjectAnnotation( + name="named_entity", + extra={ + "uuid": "f6879f59-d2b5-49c2-aceb-d9e8dc478673", + }, + value=DocumentEntity( + text_selections=[ + DocumentTextSelection( + token_ids=[ + "3f984bf3-1d61-44f5-b59a-9658a2e3440f", + "3bf00b56-ff12-4e52-8cc1-08dbddb3c3b8", + "6e1c3420-d4b7-4c5a-8fd6-ead43bf73d80", + "87a43d32-af76-4a1d-b262-5c5f4d5ace3a", + "e8606e8a-dfd9-4c49-a635-ad5c879c75d0", + "67c7c19e-4654-425d-bf17-2adb8cf02c30", + "149c5e80-3e07-49a7-ab2d-29ddfe6a38fa", + "b0e94071-2187-461e-8e76-96c58738a52c", + ], + group_id="2f4336f4-a07e-4e0a-a9e1-5629b03b719b", + page=1, + ) + ] + ), + ) + ], + ), + ] + res = list(NDJsonConverter.serialize(labels)) assert [round_dict(x) for x in res] == [round_dict(x) for x in data] - f.close() def test_pdf_bbox_serialize(): serialized = list(NDJsonConverter.serialize(bbox_labels)) - serialized[0].pop('uuid') + serialized[0].pop("uuid") assert serialized == bbox_ndjson - - -def test_pdf_bbox_deserialize(): - deserialized = list(NDJsonConverter.deserialize(bbox_ndjson)) - deserialized[0].annotations[0].extra = {} - assert deserialized[0].annotations[0].value == bbox_labels[0].annotations[0].value - assert deserialized[0].annotations[0].name == bbox_labels[0].annotations[0].name \ No newline at end of file diff --git a/libs/labelbox/tests/data/serialization/ndjson/test_export_video_objects.py b/libs/labelbox/tests/data/serialization/ndjson/test_export_video_objects.py index c85b48234..1ab678cde 100644 --- a/libs/labelbox/tests/data/serialization/ndjson/test_export_video_objects.py +++ b/libs/labelbox/tests/data/serialization/ndjson/test_export_video_objects.py @@ -6,621 +6,585 @@ def video_bbox_label(): return Label( - uid='cl1z52xwh00050fhcmfgczqvn', + uid="cl1z52xwh00050fhcmfgczqvn", data=VideoData( uid="cklr9mr4m5iao0rb6cvxu4qbn", - file_path=None, - frames=None, - url= - "https://storage.labelbox.com/ckcz6bubudyfi0855o1dt1g9s%2F26403a22-604a-a38c-eeff-c2ed481fb40a-cat.mp4?Expires=1651677421050&KeyName=labelbox-assets-key-3&Signature=vF7gMyfHzgZdfbB8BHgd88Ws-Ms" + url="https://storage.labelbox.com/ckcz6bubudyfi0855o1dt1g9s%2F26403a22-604a-a38c-eeff-c2ed481fb40a-cat.mp4?Expires=1651677421050&KeyName=labelbox-assets-key-3&Signature=vF7gMyfHzgZdfbB8BHgd88Ws-Ms", ), annotations=[ - VideoObjectAnnotation(name='bbox toy', - feature_schema_id='ckz38ofop0mci0z9i9w3aa9o4', - extra={ - 'value': 'bbox_toy', - 'instanceURI': None, - 'color': '#1CE6FF', - 'feature_id': 'cl1z52xw700000fhcayaqy0ev' - }, - value=Rectangle(extra={}, - start=Point(extra={}, - x=70.0, - y=46.0), - end=Point(extra={}, - x=454.0, - y=295.0)), - classifications=[], - frame=1, - keyframe=True), - VideoObjectAnnotation(name='bbox toy', - feature_schema_id='ckz38ofop0mci0z9i9w3aa9o4', - extra={ - 'value': 'bbox_toy', - 'instanceURI': None, - 'color': '#1CE6FF', - 'feature_id': 'cl1z52xw700000fhcayaqy0ev' - }, - value=Rectangle(extra={}, - start=Point(extra={}, - x=70.0, - y=42.5), - end=Point(extra={}, - x=427.25, - y=308.25)), - classifications=[], - frame=2, - keyframe=False), - VideoObjectAnnotation(name='bbox toy', - feature_schema_id='ckz38ofop0mci0z9i9w3aa9o4', - extra={ - 'value': 'bbox_toy', - 'instanceURI': None, - 'color': '#1CE6FF', - 'feature_id': 'cl1z52xw700000fhcayaqy0ev' - }, - value=Rectangle(extra={}, - start=Point(extra={}, - x=70.0, - y=39.0), - end=Point(extra={}, - x=400.5, - y=321.5)), - classifications=[], - frame=3, - keyframe=False), - VideoObjectAnnotation(name='bbox toy', - feature_schema_id='ckz38ofop0mci0z9i9w3aa9o4', - extra={ - 'value': 'bbox_toy', - 'instanceURI': None, - 'color': '#1CE6FF', - 'feature_id': 'cl1z52xw700000fhcayaqy0ev' - }, - value=Rectangle(extra={}, - start=Point(extra={}, - x=70.0, - y=35.5), - end=Point(extra={}, - x=373.75, - y=334.75)), - classifications=[], - frame=4, - keyframe=False), - VideoObjectAnnotation(name='bbox toy', - feature_schema_id='ckz38ofop0mci0z9i9w3aa9o4', - extra={ - 'value': 'bbox_toy', - 'instanceURI': None, - 'color': '#1CE6FF', - 'feature_id': 'cl1z52xw700000fhcayaqy0ev' - }, - value=Rectangle(extra={}, - start=Point(extra={}, - x=70.0, - y=32.0), - end=Point(extra={}, - x=347.0, - y=348.0)), - classifications=[], - frame=5, - keyframe=True), - VideoObjectAnnotation(name='bbox toy', - feature_schema_id='ckz38ofop0mci0z9i9w3aa9o4', - extra={ - 'value': 'bbox_toy', - 'instanceURI': None, - 'color': '#1CE6FF', - 'feature_id': 'cl1z52xw700000fhcayaqy0ev' - }, - value=Rectangle(extra={}, - start=Point(extra={}, - x=70.0, - y=132.0), - end=Point(extra={}, - x=283.0, - y=348.0)), - classifications=[], - frame=9, - keyframe=True), - VideoObjectAnnotation(name='bbox toy', - feature_schema_id='ckz38ofop0mci0z9i9w3aa9o4', - extra={ - 'value': 'bbox_toy', - 'instanceURI': None, - 'color': '#1CE6FF', - 'feature_id': 'cl1z52xw700000fhcayaqy0ev' - }, - value=Rectangle(extra={}, - start=Point(extra={}, - x=70.0, - y=122.333), - end=Point(extra={}, - x=295.5, - y=348.0)), - classifications=[], - frame=10, - keyframe=False), - VideoObjectAnnotation(name='bbox toy', - feature_schema_id='ckz38ofop0mci0z9i9w3aa9o4', - extra={ - 'value': 'bbox_toy', - 'instanceURI': None, - 'color': '#1CE6FF', - 'feature_id': 'cl1z52xw700000fhcayaqy0ev' - }, - value=Rectangle(extra={}, - start=Point(extra={}, - x=70.0, - y=112.667), - end=Point(extra={}, - x=308.0, - y=348.0)), - classifications=[], - frame=11, - keyframe=False), - VideoObjectAnnotation(name='bbox toy', - feature_schema_id='ckz38ofop0mci0z9i9w3aa9o4', - extra={ - 'value': 'bbox_toy', - 'instanceURI': None, - 'color': '#1CE6FF', - 'feature_id': 'cl1z52xw700000fhcayaqy0ev' - }, - value=Rectangle(extra={}, - start=Point(extra={}, - x=70.0, - y=103.0), - end=Point(extra={}, - x=320.5, - y=348.0)), - classifications=[], - frame=12, - keyframe=False), - VideoObjectAnnotation(name='bbox toy', - feature_schema_id='ckz38ofop0mci0z9i9w3aa9o4', - extra={ - 'value': 'bbox_toy', - 'instanceURI': None, - 'color': '#1CE6FF', - 'feature_id': 'cl1z52xw700000fhcayaqy0ev' - }, - value=Rectangle(extra={}, - start=Point(extra={}, - x=70.0, - y=93.333), - end=Point(extra={}, - x=333.0, - y=348.0)), - classifications=[], - frame=13, - keyframe=False), - VideoObjectAnnotation(name='bbox toy', - feature_schema_id='ckz38ofop0mci0z9i9w3aa9o4', - extra={ - 'value': 'bbox_toy', - 'instanceURI': None, - 'color': '#1CE6FF', - 'feature_id': 'cl1z52xw700000fhcayaqy0ev' - }, - value=Rectangle(extra={}, - start=Point(extra={}, - x=70.0, - y=83.667), - end=Point(extra={}, - x=345.5, - y=348.0)), - classifications=[], - frame=14, - keyframe=False), - VideoObjectAnnotation(name='bbox toy', - feature_schema_id='ckz38ofop0mci0z9i9w3aa9o4', - extra={ - 'value': 'bbox_toy', - 'instanceURI': None, - 'color': '#1CE6FF', - 'feature_id': 'cl1z52xw700000fhcayaqy0ev' - }, - value=Rectangle(extra={}, - start=Point(extra={}, - x=70.0, - y=74.0), - end=Point(extra={}, - x=358.0, - y=348.0)), - classifications=[], - frame=15, - keyframe=True), - VideoObjectAnnotation(name='bbox toy', - feature_schema_id='ckz38ofop0mci0z9i9w3aa9o4', - extra={ - 'value': 'bbox_toy', - 'instanceURI': None, - 'color': '#1CE6FF', - 'feature_id': 'cl1z52xw700000fhcayaqy0ev' - }, - value=Rectangle(extra={}, - start=Point(extra={}, - x=70.0, - y=66.833), - end=Point(extra={}, - x=387.333, - y=348.0)), - classifications=[], - frame=16, - keyframe=False), - VideoObjectAnnotation(name='bbox toy', - feature_schema_id='ckz38ofop0mci0z9i9w3aa9o4', - extra={ - 'value': 'bbox_toy', - 'instanceURI': None, - 'color': '#1CE6FF', - 'feature_id': 'cl1z52xw700000fhcayaqy0ev' - }, - value=Rectangle(extra={}, - start=Point(extra={}, - x=70.0, - y=59.667), - end=Point(extra={}, - x=416.667, - y=348.0)), - classifications=[], - frame=17, - keyframe=False), - VideoObjectAnnotation(name='bbox toy', - feature_schema_id='ckz38ofop0mci0z9i9w3aa9o4', - extra={ - 'value': 'bbox_toy', - 'instanceURI': None, - 'color': '#1CE6FF', - 'feature_id': 'cl1z52xw700000fhcayaqy0ev' - }, - value=Rectangle(extra={}, - start=Point(extra={}, - x=70.0, - y=52.5), - end=Point(extra={}, - x=446.0, - y=348.0)), - classifications=[], - frame=18, - keyframe=False), - VideoObjectAnnotation(name='bbox toy', - feature_schema_id='ckz38ofop0mci0z9i9w3aa9o4', - extra={ - 'value': 'bbox_toy', - 'instanceURI': None, - 'color': '#1CE6FF', - 'feature_id': 'cl1z52xw700000fhcayaqy0ev' - }, - value=Rectangle(extra={}, - start=Point(extra={}, - x=70.0, - y=45.333), - end=Point(extra={}, - x=475.333, - y=348.0)), - classifications=[], - frame=19, - keyframe=False), - VideoObjectAnnotation(name='bbox toy', - feature_schema_id='ckz38ofop0mci0z9i9w3aa9o4', - extra={ - 'value': 'bbox_toy', - 'instanceURI': None, - 'color': '#1CE6FF', - 'feature_id': 'cl1z52xw700000fhcayaqy0ev' - }, - value=Rectangle(extra={}, - start=Point(extra={}, - x=70.0, - y=38.167), - end=Point(extra={}, - x=504.667, - y=348.0)), - classifications=[], - frame=20, - keyframe=False), - VideoObjectAnnotation(name='bbox toy', - feature_schema_id='ckz38ofop0mci0z9i9w3aa9o4', - extra={ - 'value': 'bbox_toy', - 'instanceURI': None, - 'color': '#1CE6FF', - 'feature_id': 'cl1z52xw700000fhcayaqy0ev' - }, - value=Rectangle(extra={}, - start=Point(extra={}, - x=70.0, - y=31.0), - end=Point(extra={}, - x=534.0, - y=348.0)), - classifications=[], - frame=21, - keyframe=True), - VideoObjectAnnotation(name='bbox toy', - feature_schema_id='ckz38ofop0mci0z9i9w3aa9o4', - extra={ - 'value': 'bbox_toy', - 'instanceURI': None, - 'color': '#1CE6FF', - 'feature_id': 'cl1z52xw700000fhcayaqy0ev' - }, - value=Rectangle(extra={}, - start=Point(extra={}, - x=70.0, - y=29.5), - end=Point(extra={}, - x=543.0, - y=348.0)), - classifications=[], - frame=22, - keyframe=False), - VideoObjectAnnotation(name='bbox toy', - feature_schema_id='ckz38ofop0mci0z9i9w3aa9o4', - extra={ - 'value': 'bbox_toy', - 'instanceURI': None, - 'color': '#1CE6FF', - 'feature_id': 'cl1z52xw700000fhcayaqy0ev' - }, - value=Rectangle(extra={}, - start=Point(extra={}, - x=70.0, - y=28.0), - end=Point(extra={}, - x=552.0, - y=348.0)), - classifications=[], - frame=23, - keyframe=False), - VideoObjectAnnotation(name='bbox toy', - feature_schema_id='ckz38ofop0mci0z9i9w3aa9o4', - extra={ - 'value': 'bbox_toy', - 'instanceURI': None, - 'color': '#1CE6FF', - 'feature_id': 'cl1z52xw700000fhcayaqy0ev' - }, - value=Rectangle(extra={}, - start=Point(extra={}, - x=70.0, - y=26.5), - end=Point(extra={}, - x=561.0, - y=348.0)), - classifications=[], - frame=24, - keyframe=False), - VideoObjectAnnotation(name='bbox toy', - feature_schema_id='ckz38ofop0mci0z9i9w3aa9o4', - extra={ - 'value': 'bbox_toy', - 'instanceURI': None, - 'color': '#1CE6FF', - 'feature_id': 'cl1z52xw700000fhcayaqy0ev' - }, - value=Rectangle(extra={}, - start=Point(extra={}, - x=70.0, - y=25.0), - end=Point(extra={}, - x=570.0, - y=348.0)), - classifications=[], - frame=25, - keyframe=False), - VideoObjectAnnotation(name='bbox toy', - feature_schema_id='ckz38ofop0mci0z9i9w3aa9o4', - extra={ - 'value': 'bbox_toy', - 'instanceURI': None, - 'color': '#1CE6FF', - 'feature_id': 'cl1z52xw700000fhcayaqy0ev' - }, - value=Rectangle(extra={}, - start=Point(extra={}, - x=70.0, - y=23.5), - end=Point(extra={}, - x=579.0, - y=348.0)), - classifications=[], - frame=26, - keyframe=False), - VideoObjectAnnotation(name='bbox toy', - feature_schema_id='ckz38ofop0mci0z9i9w3aa9o4', - extra={ - 'value': 'bbox_toy', - 'instanceURI': None, - 'color': '#1CE6FF', - 'feature_id': 'cl1z52xw700000fhcayaqy0ev' - }, - value=Rectangle(extra={}, - start=Point(extra={}, - x=70.0, - y=22.0), - end=Point(extra={}, - x=588.0, - y=348.0)), - classifications=[], - frame=27, - keyframe=False), - VideoObjectAnnotation(name='bbox toy', - feature_schema_id='ckz38ofop0mci0z9i9w3aa9o4', - extra={ - 'value': 'bbox_toy', - 'instanceURI': None, - 'color': '#1CE6FF', - 'feature_id': 'cl1z52xw700000fhcayaqy0ev' - }, - value=Rectangle(extra={}, - start=Point(extra={}, - x=70.0, - y=20.5), - end=Point(extra={}, - x=597.0, - y=348.0)), - classifications=[], - frame=28, - keyframe=False), - VideoObjectAnnotation(name='bbox toy', - feature_schema_id='ckz38ofop0mci0z9i9w3aa9o4', - extra={ - 'value': 'bbox_toy', - 'instanceURI': None, - 'color': '#1CE6FF', - 'feature_id': 'cl1z52xw700000fhcayaqy0ev' - }, - value=Rectangle(extra={}, - start=Point(extra={}, - x=70.0, - y=19.0), - end=Point(extra={}, - x=606.0, - y=348.0)), - classifications=[], - frame=29, - keyframe=True) - ], - extra={ - 'Created By': - 'jtso@labelbox.com', - 'Project Name': - 'Pictor Video', - 'Created At': - '2022-04-14T15:11:19.000Z', - 'Updated At': - '2022-04-14T15:11:21.064Z', - 'Seconds to Label': - 0.0, - 'Agreement': - -1.0, - 'Benchmark Agreement': - -1.0, - 'Benchmark ID': - None, - 'Dataset Name': - 'cat', - 'Reviews': [], - 'View Label': - 'https://editor.labelbox.com?project=ckz38nsfd0lzq109bhq73est1&label=cl1z52xwh00050fhcmfgczqvn', - 'Has Open Issues': - 0.0, - 'Skipped': - False, - 'media_type': - 'video', - 'Data Split': - None - }) - - -def video_serialized_bbox_label(): - return { - 'uuid': - 'b24e672b-8f79-4d96-bf5e-b552ca0820d5', - 'dataRow': { - 'id': 'cklr9mr4m5iao0rb6cvxu4qbn' - }, - 'schemaId': - 'ckz38ofop0mci0z9i9w3aa9o4', - 'name': - 'bbox toy', - 'classifications': [], - 'segments': [{ - 'keyframes': [{ - 'frame': 1, - 'bbox': { - 'top': 46.0, - 'left': 70.0, - 'height': 249.0, - 'width': 384.0 + VideoObjectAnnotation( + name="bbox toy", + feature_schema_id="ckz38ofop0mci0z9i9w3aa9o4", + extra={ + "value": "bbox_toy", + "instanceURI": None, + "color": "#1CE6FF", + "feature_id": "cl1z52xw700000fhcayaqy0ev", + "uuid": "b24e672b-8f79-4d96-bf5e-b552ca0820d5", }, - 'classifications': [] - }, { - 'frame': 5, - 'bbox': { - 'top': 32.0, - 'left': 70.0, - 'height': 316.0, - 'width': 277.0 + value=Rectangle( + extra={}, + start=Point(extra={}, x=70.0, y=46.0), + end=Point(extra={}, x=454.0, y=295.0), + ), + classifications=[], + frame=1, + keyframe=True, + ), + VideoObjectAnnotation( + name="bbox toy", + feature_schema_id="ckz38ofop0mci0z9i9w3aa9o4", + extra={ + "value": "bbox_toy", + "instanceURI": None, + "color": "#1CE6FF", + "feature_id": "cl1z52xw700000fhcayaqy0ev", }, - 'classifications': [] - }] - }, { - 'keyframes': [{ - 'frame': 9, - 'bbox': { - 'top': 132.0, - 'left': 70.0, - 'height': 216.0, - 'width': 213.0 + value=Rectangle( + extra={}, + start=Point(extra={}, x=70.0, y=42.5), + end=Point(extra={}, x=427.25, y=308.25), + ), + classifications=[], + frame=2, + keyframe=False, + ), + VideoObjectAnnotation( + name="bbox toy", + feature_schema_id="ckz38ofop0mci0z9i9w3aa9o4", + extra={ + "value": "bbox_toy", + "instanceURI": None, + "color": "#1CE6FF", + "feature_id": "cl1z52xw700000fhcayaqy0ev", }, - 'classifications': [] - }, { - 'frame': 15, - 'bbox': { - 'top': 74.0, - 'left': 70.0, - 'height': 274.0, - 'width': 288.0 + value=Rectangle( + extra={}, + start=Point(extra={}, x=70.0, y=39.0), + end=Point(extra={}, x=400.5, y=321.5), + ), + classifications=[], + frame=3, + keyframe=False, + ), + VideoObjectAnnotation( + name="bbox toy", + feature_schema_id="ckz38ofop0mci0z9i9w3aa9o4", + extra={ + "value": "bbox_toy", + "instanceURI": None, + "color": "#1CE6FF", + "feature_id": "cl1z52xw700000fhcayaqy0ev", }, - 'classifications': [] - }, { - 'frame': 21, - 'bbox': { - 'top': 31.0, - 'left': 70.0, - 'height': 317.0, - 'width': 464.0 + value=Rectangle( + extra={}, + start=Point(extra={}, x=70.0, y=35.5), + end=Point(extra={}, x=373.75, y=334.75), + ), + classifications=[], + frame=4, + keyframe=False, + ), + VideoObjectAnnotation( + name="bbox toy", + feature_schema_id="ckz38ofop0mci0z9i9w3aa9o4", + extra={ + "value": "bbox_toy", + "instanceURI": None, + "color": "#1CE6FF", + "feature_id": "cl1z52xw700000fhcayaqy0ev", }, - 'classifications': [] - }, { - 'frame': 29, - 'bbox': { - 'top': 19.0, - 'left': 70.0, - 'height': 329.0, - 'width': 536.0 + value=Rectangle( + extra={}, + start=Point(extra={}, x=70.0, y=32.0), + end=Point(extra={}, x=347.0, y=348.0), + ), + classifications=[], + frame=5, + keyframe=True, + ), + VideoObjectAnnotation( + name="bbox toy", + feature_schema_id="ckz38ofop0mci0z9i9w3aa9o4", + extra={ + "value": "bbox_toy", + "instanceURI": None, + "color": "#1CE6FF", + "feature_id": "cl1z52xw700000fhcayaqy0ev", }, - 'classifications': [] - }] - }] - } - - -def test_serialize_video_objects(): - label = video_bbox_label() - serialized_labels = NDJsonConverter.serialize([label]) - label = next(serialized_labels) - - manual_label = video_serialized_bbox_label() - - for key in label.keys(): - # ignore uuid because we randomize if there was none - if key != "uuid": - assert label[key] == manual_label[key] + value=Rectangle( + extra={}, + start=Point(extra={}, x=70.0, y=132.0), + end=Point(extra={}, x=283.0, y=348.0), + ), + classifications=[], + frame=9, + keyframe=True, + ), + VideoObjectAnnotation( + name="bbox toy", + feature_schema_id="ckz38ofop0mci0z9i9w3aa9o4", + extra={ + "value": "bbox_toy", + "instanceURI": None, + "color": "#1CE6FF", + "feature_id": "cl1z52xw700000fhcayaqy0ev", + }, + value=Rectangle( + extra={}, + start=Point(extra={}, x=70.0, y=122.333), + end=Point(extra={}, x=295.5, y=348.0), + ), + classifications=[], + frame=10, + keyframe=False, + ), + VideoObjectAnnotation( + name="bbox toy", + feature_schema_id="ckz38ofop0mci0z9i9w3aa9o4", + extra={ + "value": "bbox_toy", + "instanceURI": None, + "color": "#1CE6FF", + "feature_id": "cl1z52xw700000fhcayaqy0ev", + }, + value=Rectangle( + extra={}, + start=Point(extra={}, x=70.0, y=112.667), + end=Point(extra={}, x=308.0, y=348.0), + ), + classifications=[], + frame=11, + keyframe=False, + ), + VideoObjectAnnotation( + name="bbox toy", + feature_schema_id="ckz38ofop0mci0z9i9w3aa9o4", + extra={ + "value": "bbox_toy", + "instanceURI": None, + "color": "#1CE6FF", + "feature_id": "cl1z52xw700000fhcayaqy0ev", + }, + value=Rectangle( + extra={}, + start=Point(extra={}, x=70.0, y=103.0), + end=Point(extra={}, x=320.5, y=348.0), + ), + classifications=[], + frame=12, + keyframe=False, + ), + VideoObjectAnnotation( + name="bbox toy", + feature_schema_id="ckz38ofop0mci0z9i9w3aa9o4", + extra={ + "value": "bbox_toy", + "instanceURI": None, + "color": "#1CE6FF", + "feature_id": "cl1z52xw700000fhcayaqy0ev", + }, + value=Rectangle( + extra={}, + start=Point(extra={}, x=70.0, y=93.333), + end=Point(extra={}, x=333.0, y=348.0), + ), + classifications=[], + frame=13, + keyframe=False, + ), + VideoObjectAnnotation( + name="bbox toy", + feature_schema_id="ckz38ofop0mci0z9i9w3aa9o4", + extra={ + "value": "bbox_toy", + "instanceURI": None, + "color": "#1CE6FF", + "feature_id": "cl1z52xw700000fhcayaqy0ev", + }, + value=Rectangle( + extra={}, + start=Point(extra={}, x=70.0, y=83.667), + end=Point(extra={}, x=345.5, y=348.0), + ), + classifications=[], + frame=14, + keyframe=False, + ), + VideoObjectAnnotation( + name="bbox toy", + feature_schema_id="ckz38ofop0mci0z9i9w3aa9o4", + extra={ + "value": "bbox_toy", + "instanceURI": None, + "color": "#1CE6FF", + "feature_id": "cl1z52xw700000fhcayaqy0ev", + }, + value=Rectangle( + extra={}, + start=Point(extra={}, x=70.0, y=74.0), + end=Point(extra={}, x=358.0, y=348.0), + ), + classifications=[], + frame=15, + keyframe=True, + ), + VideoObjectAnnotation( + name="bbox toy", + feature_schema_id="ckz38ofop0mci0z9i9w3aa9o4", + extra={ + "value": "bbox_toy", + "instanceURI": None, + "color": "#1CE6FF", + "feature_id": "cl1z52xw700000fhcayaqy0ev", + }, + value=Rectangle( + extra={}, + start=Point(extra={}, x=70.0, y=66.833), + end=Point(extra={}, x=387.333, y=348.0), + ), + classifications=[], + frame=16, + keyframe=False, + ), + VideoObjectAnnotation( + name="bbox toy", + feature_schema_id="ckz38ofop0mci0z9i9w3aa9o4", + extra={ + "value": "bbox_toy", + "instanceURI": None, + "color": "#1CE6FF", + "feature_id": "cl1z52xw700000fhcayaqy0ev", + }, + value=Rectangle( + extra={}, + start=Point(extra={}, x=70.0, y=59.667), + end=Point(extra={}, x=416.667, y=348.0), + ), + classifications=[], + frame=17, + keyframe=False, + ), + VideoObjectAnnotation( + name="bbox toy", + feature_schema_id="ckz38ofop0mci0z9i9w3aa9o4", + extra={ + "value": "bbox_toy", + "instanceURI": None, + "color": "#1CE6FF", + "feature_id": "cl1z52xw700000fhcayaqy0ev", + }, + value=Rectangle( + extra={}, + start=Point(extra={}, x=70.0, y=52.5), + end=Point(extra={}, x=446.0, y=348.0), + ), + classifications=[], + frame=18, + keyframe=False, + ), + VideoObjectAnnotation( + name="bbox toy", + feature_schema_id="ckz38ofop0mci0z9i9w3aa9o4", + extra={ + "value": "bbox_toy", + "instanceURI": None, + "color": "#1CE6FF", + "feature_id": "cl1z52xw700000fhcayaqy0ev", + }, + value=Rectangle( + extra={}, + start=Point(extra={}, x=70.0, y=45.333), + end=Point(extra={}, x=475.333, y=348.0), + ), + classifications=[], + frame=19, + keyframe=False, + ), + VideoObjectAnnotation( + name="bbox toy", + feature_schema_id="ckz38ofop0mci0z9i9w3aa9o4", + extra={ + "value": "bbox_toy", + "instanceURI": None, + "color": "#1CE6FF", + "feature_id": "cl1z52xw700000fhcayaqy0ev", + }, + value=Rectangle( + extra={}, + start=Point(extra={}, x=70.0, y=38.167), + end=Point(extra={}, x=504.667, y=348.0), + ), + classifications=[], + frame=20, + keyframe=False, + ), + VideoObjectAnnotation( + name="bbox toy", + feature_schema_id="ckz38ofop0mci0z9i9w3aa9o4", + extra={ + "value": "bbox_toy", + "instanceURI": None, + "color": "#1CE6FF", + "feature_id": "cl1z52xw700000fhcayaqy0ev", + }, + value=Rectangle( + extra={}, + start=Point(extra={}, x=70.0, y=31.0), + end=Point(extra={}, x=534.0, y=348.0), + ), + classifications=[], + frame=21, + keyframe=True, + ), + VideoObjectAnnotation( + name="bbox toy", + feature_schema_id="ckz38ofop0mci0z9i9w3aa9o4", + extra={ + "value": "bbox_toy", + "instanceURI": None, + "color": "#1CE6FF", + "feature_id": "cl1z52xw700000fhcayaqy0ev", + }, + value=Rectangle( + extra={}, + start=Point(extra={}, x=70.0, y=29.5), + end=Point(extra={}, x=543.0, y=348.0), + ), + classifications=[], + frame=22, + keyframe=False, + ), + VideoObjectAnnotation( + name="bbox toy", + feature_schema_id="ckz38ofop0mci0z9i9w3aa9o4", + extra={ + "value": "bbox_toy", + "instanceURI": None, + "color": "#1CE6FF", + "feature_id": "cl1z52xw700000fhcayaqy0ev", + }, + value=Rectangle( + extra={}, + start=Point(extra={}, x=70.0, y=28.0), + end=Point(extra={}, x=552.0, y=348.0), + ), + classifications=[], + frame=23, + keyframe=False, + ), + VideoObjectAnnotation( + name="bbox toy", + feature_schema_id="ckz38ofop0mci0z9i9w3aa9o4", + extra={ + "value": "bbox_toy", + "instanceURI": None, + "color": "#1CE6FF", + "feature_id": "cl1z52xw700000fhcayaqy0ev", + }, + value=Rectangle( + extra={}, + start=Point(extra={}, x=70.0, y=26.5), + end=Point(extra={}, x=561.0, y=348.0), + ), + classifications=[], + frame=24, + keyframe=False, + ), + VideoObjectAnnotation( + name="bbox toy", + feature_schema_id="ckz38ofop0mci0z9i9w3aa9o4", + extra={ + "value": "bbox_toy", + "instanceURI": None, + "color": "#1CE6FF", + "feature_id": "cl1z52xw700000fhcayaqy0ev", + }, + value=Rectangle( + extra={}, + start=Point(extra={}, x=70.0, y=25.0), + end=Point(extra={}, x=570.0, y=348.0), + ), + classifications=[], + frame=25, + keyframe=False, + ), + VideoObjectAnnotation( + name="bbox toy", + feature_schema_id="ckz38ofop0mci0z9i9w3aa9o4", + extra={ + "value": "bbox_toy", + "instanceURI": None, + "color": "#1CE6FF", + "feature_id": "cl1z52xw700000fhcayaqy0ev", + }, + value=Rectangle( + extra={}, + start=Point(extra={}, x=70.0, y=23.5), + end=Point(extra={}, x=579.0, y=348.0), + ), + classifications=[], + frame=26, + keyframe=False, + ), + VideoObjectAnnotation( + name="bbox toy", + feature_schema_id="ckz38ofop0mci0z9i9w3aa9o4", + extra={ + "value": "bbox_toy", + "instanceURI": None, + "color": "#1CE6FF", + "feature_id": "cl1z52xw700000fhcayaqy0ev", + }, + value=Rectangle( + extra={}, + start=Point(extra={}, x=70.0, y=22.0), + end=Point(extra={}, x=588.0, y=348.0), + ), + classifications=[], + frame=27, + keyframe=False, + ), + VideoObjectAnnotation( + name="bbox toy", + feature_schema_id="ckz38ofop0mci0z9i9w3aa9o4", + extra={ + "value": "bbox_toy", + "instanceURI": None, + "color": "#1CE6FF", + "feature_id": "cl1z52xw700000fhcayaqy0ev", + }, + value=Rectangle( + extra={}, + start=Point(extra={}, x=70.0, y=20.5), + end=Point(extra={}, x=597.0, y=348.0), + ), + classifications=[], + frame=28, + keyframe=False, + ), + VideoObjectAnnotation( + name="bbox toy", + feature_schema_id="ckz38ofop0mci0z9i9w3aa9o4", + extra={ + "value": "bbox_toy", + "instanceURI": None, + "color": "#1CE6FF", + "feature_id": "cl1z52xw700000fhcayaqy0ev", + }, + value=Rectangle( + extra={}, + start=Point(extra={}, x=70.0, y=19.0), + end=Point(extra={}, x=606.0, y=348.0), + ), + classifications=[], + frame=29, + keyframe=True, + ), + ], + extra={ + "Created By": "jtso@labelbox.com", + "Project Name": "Pictor Video", + "Created At": "2022-04-14T15:11:19.000Z", + "Updated At": "2022-04-14T15:11:21.064Z", + "Seconds to Label": 0.0, + "Agreement": -1.0, + "Benchmark Agreement": -1.0, + "Benchmark ID": None, + "Dataset Name": "cat", + "Reviews": [], + "View Label": "https://editor.labelbox.com?project=ckz38nsfd0lzq109bhq73est1&label=cl1z52xwh00050fhcmfgczqvn", + "Has Open Issues": 0.0, + "Skipped": False, + "media_type": "video", + "Data Split": None, + }, + ) - assert len(label['segments']) == 2 - assert len(label['segments'][0]['keyframes']) == 2 - assert len(label['segments'][1]['keyframes']) == 4 - # #converts back only the keyframes. should be the sum of all prev segments - deserialized_labels = NDJsonConverter.deserialize([label]) - label = next(deserialized_labels) - assert len(label.annotations) == 6 +def video_serialized_bbox_label(): + return { + "uuid": "b24e672b-8f79-4d96-bf5e-b552ca0820d5", + "dataRow": {"id": "cklr9mr4m5iao0rb6cvxu4qbn"}, + "schemaId": "ckz38ofop0mci0z9i9w3aa9o4", + "name": "bbox toy", + "classifications": [], + "segments": [ + { + "keyframes": [ + { + "frame": 1, + "bbox": { + "top": 46.0, + "left": 70.0, + "height": 249.0, + "width": 384.0, + }, + "classifications": [], + }, + { + "frame": 5, + "bbox": { + "top": 32.0, + "left": 70.0, + "height": 316.0, + "width": 277.0, + }, + "classifications": [], + }, + ] + }, + { + "keyframes": [ + { + "frame": 9, + "bbox": { + "top": 132.0, + "left": 70.0, + "height": 216.0, + "width": 213.0, + }, + "classifications": [], + }, + { + "frame": 15, + "bbox": { + "top": 74.0, + "left": 70.0, + "height": 274.0, + "width": 288.0, + }, + "classifications": [], + }, + { + "frame": 21, + "bbox": { + "top": 31.0, + "left": 70.0, + "height": 317.0, + "width": 464.0, + }, + "classifications": [], + }, + { + "frame": 29, + "bbox": { + "top": 19.0, + "left": 70.0, + "height": 329.0, + "width": 536.0, + }, + "classifications": [], + }, + ] + }, + ], + } -def test_confidence_is_ignored(): +def test_serialize_video_objects(): label = video_bbox_label() serialized_labels = NDJsonConverter.serialize([label]) label = next(serialized_labels) - label["confidence"] = 0.453 - label['segments'][0]["confidence"] = 0.453 - deserialized_labels = NDJsonConverter.deserialize([label]) - label = next(deserialized_labels) - for annotation in label.annotations: - assert annotation.confidence is None + assert label == video_serialized_bbox_label() diff --git a/libs/labelbox/tests/data/serialization/ndjson/test_free_text.py b/libs/labelbox/tests/data/serialization/ndjson/test_free_text.py index aaa84953a..349be13a8 100644 --- a/libs/labelbox/tests/data/serialization/ndjson/test_free_text.py +++ b/libs/labelbox/tests/data/serialization/ndjson/test_free_text.py @@ -1,5 +1,10 @@ from labelbox.data.annotation_types.annotation import ClassificationAnnotation -from labelbox.data.annotation_types.classification.classification import Checklist, ClassificationAnswer, Radio, Text +from labelbox.data.annotation_types.classification.classification import ( + Checklist, + ClassificationAnswer, + Radio, + Text, +) from labelbox.data.annotation_types.data.text import TextData from labelbox.data.annotation_types.label import Label @@ -7,34 +12,27 @@ def test_serialization(): - label = Label(uid="ckj7z2q0b0000jx6x0q2q7q0d", - data=TextData( - uid="bkj7z2q0b0000jx6x0q2q7q0d", - text="This is a test", - ), - annotations=[ - ClassificationAnnotation(name="free_text_annotation", - value=Text(confidence=0.5, - answer="text_answer")) - ]) + label = Label( + uid="ckj7z2q0b0000jx6x0q2q7q0d", + data=TextData( + uid="bkj7z2q0b0000jx6x0q2q7q0d", + text="This is a test", + ), + annotations=[ + ClassificationAnnotation( + name="free_text_annotation", + value=Text(confidence=0.5, answer="text_answer"), + ) + ], + ) serialized = NDJsonConverter.serialize([label]) res = next(serialized) - assert res['confidence'] == 0.5 - assert res['name'] == "free_text_annotation" - assert res['answer'] == "text_answer" - assert res['dataRow']['id'] == "bkj7z2q0b0000jx6x0q2q7q0d" - - deserialized = NDJsonConverter.deserialize([res]) - res = next(deserialized) - - annotation = res.annotations[0] - - annotation_value = annotation.value - assert type(annotation_value) is Text - assert annotation_value.answer == "text_answer" - assert annotation_value.confidence == 0.5 + assert res["confidence"] == 0.5 + assert res["name"] == "free_text_annotation" + assert res["answer"] == "text_answer" + assert res["dataRow"]["id"] == "bkj7z2q0b0000jx6x0q2q7q0d" def test_nested_serialization(): @@ -47,57 +45,50 @@ def test_nested_serialization(): annotations=[ ClassificationAnnotation( name="nested test", - value=Checklist(answer=[ - ClassificationAnswer( - name="first_answer", - confidence=0.9, - classifications=[ - ClassificationAnnotation( - name="sub_radio_question", - value=Radio(answer=ClassificationAnswer( - name="first_sub_radio_answer", - confidence=0.8, - classifications=[ - ClassificationAnnotation( - name="nested answer", - value=Text( - answer="nested answer", - confidence=0.7, - )) - ]))) - ]) - ]), + value=Checklist( + answer=[ + ClassificationAnswer( + name="first_answer", + confidence=0.9, + classifications=[ + ClassificationAnnotation( + name="sub_radio_question", + value=Radio( + answer=ClassificationAnswer( + name="first_sub_radio_answer", + confidence=0.8, + classifications=[ + ClassificationAnnotation( + name="nested answer", + value=Text( + answer="nested answer", + confidence=0.7, + ), + ) + ], + ) + ), + ) + ], + ) + ] + ), ) - ]) + ], + ) serialized = NDJsonConverter.serialize([label]) res = next(serialized) - assert res['dataRow']['id'] == "bkj7z2q0b0000jx6x0q2q7q0d" - answer = res['answer'][0] - assert answer['confidence'] == 0.9 - assert answer['name'] == "first_answer" - classification = answer['classifications'][0] - nested_classification_answer = classification['answer'] - assert nested_classification_answer['confidence'] == 0.8 - assert nested_classification_answer['name'] == "first_sub_radio_answer" - sub_classification = nested_classification_answer['classifications'][0] - assert sub_classification['name'] == "nested answer" - assert sub_classification['answer'] == "nested answer" - assert sub_classification['confidence'] == 0.7 - - deserialized = NDJsonConverter.deserialize([res]) - res = next(deserialized) - annotation = res.annotations[0] - answer = annotation.value.answer[0] - assert answer.confidence == 0.9 - assert answer.name == "first_answer" - - classification_answer = answer.classifications[0].value.answer - assert classification_answer.confidence == 0.8 - assert classification_answer.name == "first_sub_radio_answer" - - sub_classification_answer = classification_answer.classifications[0].value - assert type(sub_classification_answer) is Text - assert sub_classification_answer.answer == "nested answer" - assert sub_classification_answer.confidence == 0.7 + assert res["dataRow"]["id"] == "bkj7z2q0b0000jx6x0q2q7q0d" + answer = res["answer"][0] + assert answer["confidence"] == 0.9 + assert answer["name"] == "first_answer" + classification = answer["classifications"][0] + nested_classification_answer = classification["answer"] + assert nested_classification_answer["confidence"] == 0.8 + assert nested_classification_answer["name"] == "first_sub_radio_answer" + sub_classification = nested_classification_answer["classifications"][0] + assert sub_classification["name"] == "nested answer" + assert sub_classification["answer"] == "nested answer" + assert sub_classification["confidence"] == 0.7 diff --git a/libs/labelbox/tests/data/serialization/ndjson/test_global_key.py b/libs/labelbox/tests/data/serialization/ndjson/test_global_key.py index 6de2dcc51..7d6e9fdc3 100644 --- a/libs/labelbox/tests/data/serialization/ndjson/test_global_key.py +++ b/libs/labelbox/tests/data/serialization/ndjson/test_global_key.py @@ -1,68 +1,72 @@ -import json -import pytest - -from labelbox.data.serialization.ndjson.classification import NDRadio - from labelbox.data.serialization.ndjson.converter import NDJsonConverter -from labelbox.data.serialization.ndjson.objects import NDLine - - -def round_dict(data): - if isinstance(data, dict): - for key in data: - if isinstance(data[key], float): - data[key] = int(data[key]) - elif isinstance(data[key], dict): - data[key] = round_dict(data[key]) - elif isinstance(data[key], (list, tuple)): - data[key] = [round_dict(r) for r in data[key]] +from labelbox.types import ( + GenericDataRowData, + Label, + ClassificationAnnotation, + Radio, + ClassificationAnswer, +) - return data +def test_generic_data_row_global_key_included(): + expected = [ + { + "answer": {"schemaId": "ckrb1sfl8099g0y91cxbd5ftb"}, + "dataRow": {"globalKey": "ckrb1sf1i1g7i0ybcdc6oc8ct"}, + "schemaId": "ckrb1sfjx099a0y914hl319ie", + "uuid": "f6879f59-d2b5-49c2-aceb-d9e8dc478673", + } + ] -@pytest.mark.parametrize('filename', [ - 'tests/data/assets/ndjson/classification_import_global_key.json', - 'tests/data/assets/ndjson/metric_import_global_key.json', - 'tests/data/assets/ndjson/polyline_import_global_key.json', - 'tests/data/assets/ndjson/text_entity_import_global_key.json', - 'tests/data/assets/ndjson/conversation_entity_import_global_key.json', -]) -def test_many_types(filename: str): - with open(filename, 'r') as f: - data = json.load(f) - res = list(NDJsonConverter.deserialize(data)) - res = list(NDJsonConverter.serialize(res)) - assert res == data - f.close() + label = Label( + data=GenericDataRowData( + global_key="ckrb1sf1i1g7i0ybcdc6oc8ct", + ), + annotations=[ + ClassificationAnnotation( + feature_schema_id="ckrb1sfjx099a0y914hl319ie", + extra={"uuid": "f6879f59-d2b5-49c2-aceb-d9e8dc478673"}, + value=Radio( + answer=ClassificationAnswer( + feature_schema_id="ckrb1sfl8099g0y91cxbd5ftb", + ), + ), + ) + ], + ) + res = list(NDJsonConverter.serialize([label])) -def test_image(): - with open('tests/data/assets/ndjson/image_import_global_key.json', - 'r') as f: - data = json.load(f) - res = list(NDJsonConverter.deserialize(data)) - res = list(NDJsonConverter.serialize(res)) - for r in res: - r.pop('classifications', None) - assert [round_dict(x) for x in res] == [round_dict(x) for x in data] - f.close() + assert res == expected -def test_pdf(): - with open('tests/data/assets/ndjson/pdf_import_global_key.json', 'r') as f: - data = json.load(f) - res = list(NDJsonConverter.deserialize(data)) - res = list(NDJsonConverter.serialize(res)) - assert [round_dict(x) for x in res] == [round_dict(x) for x in data] - f.close() +def test_dict_data_row_global_key_included(): + expected = [ + { + "answer": {"schemaId": "ckrb1sfl8099g0y91cxbd5ftb"}, + "dataRow": {"globalKey": "ckrb1sf1i1g7i0ybcdc6oc8ct"}, + "schemaId": "ckrb1sfjx099a0y914hl319ie", + "uuid": "f6879f59-d2b5-49c2-aceb-d9e8dc478673", + } + ] + label = Label( + data={ + "global_key": "ckrb1sf1i1g7i0ybcdc6oc8ct", + }, + annotations=[ + ClassificationAnnotation( + feature_schema_id="ckrb1sfjx099a0y914hl319ie", + extra={"uuid": "f6879f59-d2b5-49c2-aceb-d9e8dc478673"}, + value=Radio( + answer=ClassificationAnswer( + feature_schema_id="ckrb1sfl8099g0y91cxbd5ftb", + ), + ), + ) + ], + ) -def test_video(): - with open('tests/data/assets/ndjson/video_import_global_key.json', - 'r') as f: - data = json.load(f) + res = list(NDJsonConverter.serialize([label])) - res = list(NDJsonConverter.deserialize(data)) - res = list(NDJsonConverter.serialize(res)) - assert res == [data[2], data[0], data[1], data[3], data[4], data[5]] - f.close() + assert res == expected From bed0a54e3dc127f99cc36520248977ac9868ae15 Mon Sep 17 00:00:00 2001 From: Gabefire <33893811+Gabefire@users.noreply.github.com> Date: Wed, 11 Sep 2024 11:20:57 -0500 Subject: [PATCH 02/11] removed a few assets --- .../classification_import_global_key.json | 54 ------------------- ...conversation_entity_import_global_key.json | 25 --------- .../ndjson/metric_import_global_key.json | 10 ---- .../ndjson/polyline_import_global_key.json | 36 ------------- .../ndjson/text_entity_import_global_key.json | 26 --------- 5 files changed, 151 deletions(-) delete mode 100644 libs/labelbox/tests/data/assets/ndjson/classification_import_global_key.json delete mode 100644 libs/labelbox/tests/data/assets/ndjson/conversation_entity_import_global_key.json delete mode 100644 libs/labelbox/tests/data/assets/ndjson/metric_import_global_key.json delete mode 100644 libs/labelbox/tests/data/assets/ndjson/polyline_import_global_key.json delete mode 100644 libs/labelbox/tests/data/assets/ndjson/text_entity_import_global_key.json diff --git a/libs/labelbox/tests/data/assets/ndjson/classification_import_global_key.json b/libs/labelbox/tests/data/assets/ndjson/classification_import_global_key.json deleted file mode 100644 index 4de15e217..000000000 --- a/libs/labelbox/tests/data/assets/ndjson/classification_import_global_key.json +++ /dev/null @@ -1,54 +0,0 @@ -[ - { - "answer": { - "schemaId": "ckrb1sfl8099g0y91cxbd5ftb", - "confidence": 0.8, - "customMetrics": [ - { - "name": "customMetric1", - "value": 0.5 - }, - { - "name": "customMetric2", - "value": 0.3 - } - ] - }, - "schemaId": "ckrb1sfl8099g0y91cxbd5ftb", - "dataRow": { - "globalKey": "05e8ee85-072e-4eb2-b30a-501dee9b0d9d" - }, - "uuid": "f6879f59-d2b5-49c2-aceb-d9e8dc478673" - }, - { - "answer": [ - { - "schemaId": "ckrb1sfl8099e0y919v260awv", - "confidence": 0.82, - "customMetrics": [ - { - "name": "customMetric1", - "value": 0.5 - }, - { - "name": "customMetric2", - "value": 0.3 - } - ] - } - ], - "schemaId": "ckrb1sfkn099c0y910wbo0p1a", - "dataRow": { - "globalKey": "05e8ee85-072e-4eb2-b30a-501dee9b0d9d" - }, - "uuid": "d009925d-91a3-4f67-abd9-753453f5a584" - }, - { - "answer": "a value", - "schemaId": "ckrb1sfkn099c0y910wbo0p1a", - "dataRow": { - "globalKey": "05e8ee85-072e-4eb2-b30a-501dee9b0d9d" - }, - "uuid": "ee70fd88-9f88-48dd-b760-7469ff479b71" - } -] \ No newline at end of file diff --git a/libs/labelbox/tests/data/assets/ndjson/conversation_entity_import_global_key.json b/libs/labelbox/tests/data/assets/ndjson/conversation_entity_import_global_key.json deleted file mode 100644 index 83a95e5bf..000000000 --- a/libs/labelbox/tests/data/assets/ndjson/conversation_entity_import_global_key.json +++ /dev/null @@ -1,25 +0,0 @@ -[{ - "location": { - "start": 67, - "end": 128 - }, - "messageId": "some-message-id", - "uuid": "5ad9c52f-058d-49c8-a749-3f20b84f8cd4", - "dataRow": { - "globalKey": "05e8ee85-072e-4eb2-b30a-501dee9b0d9d" - }, - "name": "some-text-entity", - "schemaId": "cl6xnuwt95lqq07330tbb3mfd", - "classifications": [], - "confidence": 0.53, - "customMetrics": [ - { - "name": "customMetric1", - "value": 0.5 - }, - { - "name": "customMetric2", - "value": 0.3 - } - ] -}] diff --git a/libs/labelbox/tests/data/assets/ndjson/metric_import_global_key.json b/libs/labelbox/tests/data/assets/ndjson/metric_import_global_key.json deleted file mode 100644 index 31be5a4c7..000000000 --- a/libs/labelbox/tests/data/assets/ndjson/metric_import_global_key.json +++ /dev/null @@ -1,10 +0,0 @@ -[ - { - "uuid": "a22bbf6e-b2da-4abe-9a11-df84759f7672", - "aggregation": "ARITHMETIC_MEAN", - "dataRow": { - "globalKey": "05e8ee85-072e-4eb2-b30a-501dee9b0d9d" - }, - "metricValue": 0.1 - } -] \ No newline at end of file diff --git a/libs/labelbox/tests/data/assets/ndjson/polyline_import_global_key.json b/libs/labelbox/tests/data/assets/ndjson/polyline_import_global_key.json deleted file mode 100644 index d6a9eecbd..000000000 --- a/libs/labelbox/tests/data/assets/ndjson/polyline_import_global_key.json +++ /dev/null @@ -1,36 +0,0 @@ -[ - { - "line": [ - { - "x": 2534.353, - "y": 249.471 - }, - { - "x": 2429.492, - "y": 182.092 - }, - { - "x": 2294.322, - "y": 221.962 - } - ], - "uuid": "5ad9c52f-058d-49c8-a749-3f20b84f8cd4", - "dataRow": { - "globalKey": "05e8ee85-072e-4eb2-b30a-501dee9b0d9d" - }, - "name": "some-line", - "schemaId": "cl6xnuwt95lqq07330tbb3mfd", - "classifications": [], - "confidence": 0.58, - "customMetrics": [ - { - "name": "customMetric1", - "value": 0.5 - }, - { - "name": "customMetric2", - "value": 0.3 - } - ] - } -] \ No newline at end of file diff --git a/libs/labelbox/tests/data/assets/ndjson/text_entity_import_global_key.json b/libs/labelbox/tests/data/assets/ndjson/text_entity_import_global_key.json deleted file mode 100644 index 1f26d8dc8..000000000 --- a/libs/labelbox/tests/data/assets/ndjson/text_entity_import_global_key.json +++ /dev/null @@ -1,26 +0,0 @@ -[ - { - "location": { - "start": 67, - "end": 128 - }, - "uuid": "5ad9c52f-058d-49c8-a749-3f20b84f8cd4", - "dataRow": { - "globalKey": "05e8ee85-072e-4eb2-b30a-501dee9b0d9d" - }, - "name": "some-text-entity", - "schemaId": "cl6xnuwt95lqq07330tbb3mfd", - "classifications": [], - "confidence": 0.53, - "customMetrics": [ - { - "name": "customMetric1", - "value": 0.5 - }, - { - "name": "customMetric2", - "value": 0.3 - } - ] - } -] \ No newline at end of file From 0b6f705b4bf45fb97c0c22c405486aa113be4ee4 Mon Sep 17 00:00:00 2001 From: Gabefire <33893811+Gabefire@users.noreply.github.com> Date: Wed, 11 Sep 2024 11:13:31 -0500 Subject: [PATCH 03/11] started unit test --- .../serialization/ndjson/test_checklist.py | 20 - .../ndjson/test_classification.py | 114 +- .../serialization/ndjson/test_conversation.py | 234 ++-- .../serialization/ndjson/test_data_gen.py | 59 +- .../data/serialization/ndjson/test_dicom.py | 212 ++- .../serialization/ndjson/test_document.py | 332 ++++- .../ndjson/test_export_video_objects.py | 1164 ++++++++--------- .../serialization/ndjson/test_free_text.py | 139 +- .../serialization/ndjson/test_global_key.py | 118 +- 9 files changed, 1340 insertions(+), 1052 deletions(-) diff --git a/libs/labelbox/tests/data/serialization/ndjson/test_checklist.py b/libs/labelbox/tests/data/serialization/ndjson/test_checklist.py index c4b47427a..ebcde0ea4 100644 --- a/libs/labelbox/tests/data/serialization/ndjson/test_checklist.py +++ b/libs/labelbox/tests/data/serialization/ndjson/test_checklist.py @@ -35,13 +35,6 @@ def test_serialization_min(): res.pop("uuid") assert res == expected - deserialized = NDJsonConverter.deserialize([res]) - res = next(deserialized) - for i, annotation in enumerate(res.annotations): - annotation.extra.pop("uuid") - assert annotation.value == label.annotations[i].value - assert annotation.name == label.annotations[i].name - def test_serialization_with_classification(): label = Label( @@ -117,10 +110,6 @@ def test_serialization_with_classification(): res.pop("uuid") assert res == expected - deserialized = NDJsonConverter.deserialize([res]) - res = next(deserialized) - assert label.model_dump(exclude_none=True) == label.model_dump(exclude_none=True) - def test_serialization_with_classification_double_nested(): label = Label( @@ -200,11 +189,6 @@ def test_serialization_with_classification_double_nested(): res.pop("uuid") assert res == expected - deserialized = NDJsonConverter.deserialize([res]) - res = next(deserialized) - res.annotations[0].extra.pop("uuid") - assert label.model_dump(exclude_none=True) == label.model_dump(exclude_none=True) - def test_serialization_with_classification_double_nested_2(): label = Label( @@ -278,7 +262,3 @@ def test_serialization_with_classification_double_nested_2(): res = next(serialized) res.pop("uuid") assert res == expected - - deserialized = NDJsonConverter.deserialize([res]) - res = next(deserialized) - assert label.model_dump(exclude_none=True) == label.model_dump(exclude_none=True) diff --git a/libs/labelbox/tests/data/serialization/ndjson/test_classification.py b/libs/labelbox/tests/data/serialization/ndjson/test_classification.py index 00a684b20..efb3f0cf7 100644 --- a/libs/labelbox/tests/data/serialization/ndjson/test_classification.py +++ b/libs/labelbox/tests/data/serialization/ndjson/test_classification.py @@ -1,21 +1,119 @@ import json +from labelbox.data.annotation_types.classification.classification import ( + Checklist, + Radio, + Text, +) from labelbox.data.serialization.ndjson.converter import NDJsonConverter +from labelbox.types import ( + Label, + ClassificationAnnotation, + ClassificationAnswer, + GenericDataRowData, +) +from labelbox.data.mixins import CustomMetric + def test_classification(): - with open('tests/data/assets/ndjson/classification_import.json', - 'r') as file: + with open("tests/data/assets/ndjson/classification_import.json", "r") as file: data = json.load(file) - res = list(NDJsonConverter.deserialize(data)) - res = list(NDJsonConverter.serialize(res)) + + label = Label( + data=GenericDataRowData( + uid="ckrb1sf1i1g7i0ybcdc6oc8ct", + ), + annotations=[ + ClassificationAnnotation( + feature_schema_id="ckrb1sfjx099a0y914hl319ie", + extra={"uuid": "f6879f59-d2b5-49c2-aceb-d9e8dc478673"}, + value=Radio( + answer=ClassificationAnswer( + custom_metrics=[ + CustomMetric(name="customMetric1", value=0.5), + CustomMetric(name="customMetric2", value=0.3), + ], + confidence=0.8, + feature_schema_id="ckrb1sfl8099g0y91cxbd5ftb", + ), + ), + ), + ClassificationAnnotation( + feature_schema_id="ckrb1sfkn099c0y910wbo0p1a", + extra={"uuid": "d009925d-91a3-4f67-abd9-753453f5a584"}, + value=Checklist( + answer=[ + ClassificationAnswer( + custom_metrics=[ + CustomMetric(name="customMetric1", value=0.5), + CustomMetric(name="customMetric2", value=0.3), + ], + confidence=0.82, + feature_schema_id="ckrb1sfl8099e0y919v260awv", + ) + ], + ), + ), + ClassificationAnnotation( + feature_schema_id="ckrb1sfkn099c0y910wbo0p1a", + extra={"uuid": "78ff6a23-bebe-475c-8f67-4c456909648f"}, + value=Text(answer="a value"), + ), + ], + ) + + res = list(NDJsonConverter.serialize([label])) assert res == data def test_classification_with_name(): - with open('tests/data/assets/ndjson/classification_import_name_only.json', - 'r') as file: + with open( + "tests/data/assets/ndjson/classification_import_name_only.json", "r" + ) as file: data = json.load(file) - res = list(NDJsonConverter.deserialize(data)) - res = list(NDJsonConverter.serialize(res)) + label = Label( + data=GenericDataRowData( + uid="ckrb1sf1i1g7i0ybcdc6oc8ct", + ), + annotations=[ + ClassificationAnnotation( + name="classification a", + extra={"uuid": "f6879f59-d2b5-49c2-aceb-d9e8dc478673"}, + value=Radio( + answer=ClassificationAnswer( + custom_metrics=[ + CustomMetric(name="customMetric1", value=0.5), + CustomMetric(name="customMetric2", value=0.3), + ], + confidence=0.99, + name="choice 1", + ), + ), + ), + ClassificationAnnotation( + name="classification b", + extra={"uuid": "d009925d-91a3-4f67-abd9-753453f5a584"}, + value=Checklist( + answer=[ + ClassificationAnswer( + custom_metrics=[ + CustomMetric(name="customMetric1", value=0.5), + CustomMetric(name="customMetric2", value=0.3), + ], + confidence=0.945, + name="choice 2", + ) + ], + ), + ), + ClassificationAnnotation( + name="classification c", + extra={"uuid": "150d60de-30af-44e4-be20-55201c533312"}, + value=Text(answer="a value"), + ), + ], + ) + + res = list(NDJsonConverter.serialize([label])) assert res == data diff --git a/libs/labelbox/tests/data/serialization/ndjson/test_conversation.py b/libs/labelbox/tests/data/serialization/ndjson/test_conversation.py index 4d2a0416c..4d995a9ef 100644 --- a/libs/labelbox/tests/data/serialization/ndjson/test_conversation.py +++ b/libs/labelbox/tests/data/serialization/ndjson/test_conversation.py @@ -3,131 +3,183 @@ import pytest import labelbox.types as lb_types from labelbox.data.serialization.ndjson.converter import NDJsonConverter - -radio_ndjson = [{ - 'dataRow': { - 'globalKey': 'my_global_key' - }, - 'name': 'radio', - 'answer': { - 'name': 'first_radio_answer' - }, - 'messageId': '0' -}] +from labelbox.data.mixins import CustomMetric + +radio_ndjson = [ + { + "dataRow": {"globalKey": "my_global_key"}, + "name": "radio", + "answer": {"name": "first_radio_answer"}, + "messageId": "0", + } +] radio_label = [ lb_types.Label( - data=lb_types.ConversationData(global_key='my_global_key'), + data=lb_types.ConversationData(global_key="my_global_key"), annotations=[ lb_types.ClassificationAnnotation( - name='radio', - value=lb_types.Radio(answer=lb_types.ClassificationAnswer( - name="first_radio_answer")), - message_id="0") - ]) + name="radio", + value=lb_types.Radio( + answer=lb_types.ClassificationAnswer(name="first_radio_answer") + ), + message_id="0", + ) + ], + ) ] -checklist_ndjson = [{ - 'dataRow': { - 'globalKey': 'my_global_key' - }, - 'name': 'checklist', - 'answer': [ - { - 'name': 'first_checklist_answer' - }, - { - 'name': 'second_checklist_answer' - }, - ], - 'messageId': '2' -}] +checklist_ndjson = [ + { + "dataRow": {"globalKey": "my_global_key"}, + "name": "checklist", + "answer": [ + {"name": "first_checklist_answer"}, + {"name": "second_checklist_answer"}, + ], + "messageId": "2", + } +] checklist_label = [ - lb_types.Label(data=lb_types.ConversationData(global_key='my_global_key'), - annotations=[ - lb_types.ClassificationAnnotation( - name='checklist', - message_id="2", - value=lb_types.Checklist(answer=[ - lb_types.ClassificationAnswer( - name="first_checklist_answer"), - lb_types.ClassificationAnswer( - name="second_checklist_answer") - ])) - ]) + lb_types.Label( + data=lb_types.ConversationData(global_key="my_global_key"), + annotations=[ + lb_types.ClassificationAnnotation( + name="checklist", + message_id="2", + value=lb_types.Checklist( + answer=[ + lb_types.ClassificationAnswer(name="first_checklist_answer"), + lb_types.ClassificationAnswer(name="second_checklist_answer"), + ] + ), + ) + ], + ) ] -free_text_ndjson = [{ - 'dataRow': { - 'globalKey': 'my_global_key' - }, - 'name': 'free_text', - 'answer': 'sample text', - 'messageId': '0' -}] +free_text_ndjson = [ + { + "dataRow": {"globalKey": "my_global_key"}, + "name": "free_text", + "answer": "sample text", + "messageId": "0", + } +] free_text_label = [ - lb_types.Label(data=lb_types.ConversationData(global_key='my_global_key'), - annotations=[ - lb_types.ClassificationAnnotation( - name='free_text', - message_id="0", - value=lb_types.Text(answer="sample text")) - ]) + lb_types.Label( + data=lb_types.ConversationData(global_key="my_global_key"), + annotations=[ + lb_types.ClassificationAnnotation( + name="free_text", + message_id="0", + value=lb_types.Text(answer="sample text"), + ) + ], + ) ] @pytest.mark.parametrize( "label, ndjson", - [[radio_label, radio_ndjson], [checklist_label, checklist_ndjson], - [free_text_label, free_text_ndjson]]) + [ + [radio_label, radio_ndjson], + [checklist_label, checklist_ndjson], + [free_text_label, free_text_ndjson], + ], +) def test_message_based_radio_classification(label, ndjson): serialized_label = list(NDJsonConverter().serialize(label)) - serialized_label[0].pop('uuid') + serialized_label[0].pop("uuid") assert serialized_label == ndjson - deserialized_label = list(NDJsonConverter().deserialize(ndjson)) - deserialized_label[0].annotations[0].extra.pop('uuid') - assert deserialized_label[0].model_dump(exclude_none=True) == label[0].model_dump(exclude_none=True) +def test_conversation_entity_import(): + with open("tests/data/assets/ndjson/conversation_entity_import.json", "r") as file: + data = json.load(file) + + label = lb_types.Label( + data=lb_types.GenericDataRowData( + uid="cl6xnv9h61fv0085yhtoq06ht", + ), + annotations=[ + lb_types.ObjectAnnotation( + custom_metrics=[ + CustomMetric(name="customMetric1", value=0.5), + CustomMetric(name="customMetric2", value=0.3), + ], + confidence=0.53, + name="some-text-entity", + feature_schema_id="cl6xnuwt95lqq07330tbb3mfd", + extra={"uuid": "5ad9c52f-058d-49c8-a749-3f20b84f8cd4"}, + value=lb_types.ConversationEntity( + start=67, end=128, message_id="some-message-id" + ), + ) + ], + ) -@pytest.mark.parametrize("filename", [ - "tests/data/assets/ndjson/conversation_entity_import.json", - "tests/data/assets/ndjson/conversation_entity_without_confidence_import.json" -]) -def test_conversation_entity_import(filename: str): - with open(filename, 'r') as file: + res = list(NDJsonConverter.serialize([label])) + assert res == data + + +def test_conversation_entity_import_without_confidence(): + with open( + "tests/data/assets/ndjson/conversation_entity_without_confidence_import.json", + "r", + ) as file: data = json.load(file) - res = list(NDJsonConverter.deserialize(data)) - res = list(NDJsonConverter.serialize(res)) + label = lb_types.Label( + uid=None, + data=lb_types.GenericDataRowData( + uid="cl6xnv9h61fv0085yhtoq06ht", + ), + annotations=[ + lb_types.ObjectAnnotation( + name="some-text-entity", + feature_schema_id="cl6xnuwt95lqq07330tbb3mfd", + extra={"uuid": "5ad9c52f-058d-49c8-a749-3f20b84f8cd4"}, + value=lb_types.ConversationEntity( + start=67, end=128, extra={}, message_id="some-message-id" + ), + ) + ], + ) + + res = list(NDJsonConverter.serialize([label])) assert res == data def test_benchmark_reference_label_flag_enabled(): - label = lb_types.Label(data=lb_types.ConversationData(global_key='my_global_key'), - annotations=[ - lb_types.ClassificationAnnotation( - name='free_text', - message_id="0", - value=lb_types.Text(answer="sample text")) - ], - is_benchmark_reference=True - ) + label = lb_types.Label( + data=lb_types.ConversationData(global_key="my_global_key"), + annotations=[ + lb_types.ClassificationAnnotation( + name="free_text", + message_id="0", + value=lb_types.Text(answer="sample text"), + ) + ], + is_benchmark_reference=True, + ) res = list(NDJsonConverter.serialize([label])) assert res[0]["isBenchmarkReferenceLabel"] def test_benchmark_reference_label_flag_disabled(): - label = lb_types.Label(data=lb_types.ConversationData(global_key='my_global_key'), - annotations=[ - lb_types.ClassificationAnnotation( - name='free_text', - message_id="0", - value=lb_types.Text(answer="sample text")) - ], - is_benchmark_reference=False - ) + label = lb_types.Label( + data=lb_types.ConversationData(global_key="my_global_key"), + annotations=[ + lb_types.ClassificationAnnotation( + name="free_text", + message_id="0", + value=lb_types.Text(answer="sample text"), + ) + ], + is_benchmark_reference=False, + ) res = list(NDJsonConverter.serialize([label])) assert not res[0].get("isBenchmarkReferenceLabel") diff --git a/libs/labelbox/tests/data/serialization/ndjson/test_data_gen.py b/libs/labelbox/tests/data/serialization/ndjson/test_data_gen.py index 186c75223..d870d9618 100644 --- a/libs/labelbox/tests/data/serialization/ndjson/test_data_gen.py +++ b/libs/labelbox/tests/data/serialization/ndjson/test_data_gen.py @@ -1,55 +1,26 @@ -from copy import copy -import pytest import labelbox.types as lb_types from labelbox.data.serialization import NDJsonConverter -from labelbox.data.serialization.ndjson.objects import NDDicomSegments, NDDicomSegment, NDDicomLine -""" -Data gen prompt test data -""" -prompt_text_annotation = lb_types.PromptClassificationAnnotation( - feature_schema_id="ckrb1sfkn099c0y910wbo0p1a", - name="test", - value=lb_types.PromptText(answer="the answer to the text questions right here"), - ) -prompt_text_ndjson = { +def test_serialize_label(): + prompt_text_annotation = lb_types.PromptClassificationAnnotation( + feature_schema_id="ckrb1sfkn099c0y910wbo0p1a", + name="test", + extra={"uuid": "test"}, + value=lb_types.PromptText(answer="the answer to the text questions right here"), + ) + + prompt_text_ndjson = { "answer": "the answer to the text questions right here", "name": "test", "schemaId": "ckrb1sfkn099c0y910wbo0p1a", - "dataRow": { - "id": "ckrb1sf1i1g7i0ybcdc6oc8ct" - }, + "dataRow": {"id": "ckrb1sf1i1g7i0ybcdc6oc8ct"}, + "uuid": "test", } -data_gen_label = lb_types.Label( - data={"uid": "ckrb1sf1i1g7i0ybcdc6oc8ct"}, - annotations=[prompt_text_annotation] -) - -""" -Prompt annotation test -""" - -def test_serialize_label(): + data_gen_label = lb_types.Label( + data={"uid": "ckrb1sf1i1g7i0ybcdc6oc8ct"}, annotations=[prompt_text_annotation] + ) serialized_label = next(NDJsonConverter().serialize([data_gen_label])) - # Remove uuid field since this is a random value that can not be specified also meant for relationships - del serialized_label["uuid"] - assert serialized_label == prompt_text_ndjson - -def test_deserialize_label(): - deserialized_label = next(NDJsonConverter().deserialize([prompt_text_ndjson])) - if hasattr(deserialized_label.annotations[0], 'extra'): - # Extra fields are added to deserialized label by default need removed to match - deserialized_label.annotations[0].extra = {} - assert deserialized_label.model_dump(exclude_none=True) == data_gen_label.model_dump(exclude_none=True) - - -def test_serialize_deserialize_label(): - serialized = list(NDJsonConverter.serialize([data_gen_label])) - deserialized = next(NDJsonConverter.deserialize(serialized)) - if hasattr(deserialized.annotations[0], 'extra'): - # Extra fields are added to deserialized label by default need removed to match - deserialized.annotations[0].extra = {} - assert deserialized.model_dump(exclude_none=True) == data_gen_label.model_dump(exclude_none=True) + assert serialized_label == prompt_text_ndjson diff --git a/libs/labelbox/tests/data/serialization/ndjson/test_dicom.py b/libs/labelbox/tests/data/serialization/ndjson/test_dicom.py index e69c21bae..e6ccba3b7 100644 --- a/libs/labelbox/tests/data/serialization/ndjson/test_dicom.py +++ b/libs/labelbox/tests/data/serialization/ndjson/test_dicom.py @@ -1,129 +1,114 @@ from copy import copy import pytest -import base64 import labelbox.types as lb_types from labelbox.data.serialization import NDJsonConverter -from labelbox.data.serialization.ndjson.objects import NDDicomSegments, NDDicomSegment, NDDicomLine +from labelbox.data.serialization.ndjson.objects import ( + NDDicomSegments, + NDDicomSegment, + NDDicomLine, +) + """ Polyline test data """ dicom_polyline_annotations = [ - lb_types.DICOMObjectAnnotation(uuid="78a8a027-9089-420c-8348-6099eb77e4aa", - name="dicom_polyline", - frame=2, - value=lb_types.Line(points=[ - lb_types.Point(x=680, y=100), - lb_types.Point(x=100, y=190), - lb_types.Point(x=190, y=220) - ]), - segment_index=0, - keyframe=True, - group_key=lb_types.GroupKey.AXIAL) + lb_types.DICOMObjectAnnotation( + uuid="78a8a027-9089-420c-8348-6099eb77e4aa", + name="dicom_polyline", + frame=2, + value=lb_types.Line( + points=[ + lb_types.Point(x=680, y=100), + lb_types.Point(x=100, y=190), + lb_types.Point(x=190, y=220), + ] + ), + segment_index=0, + keyframe=True, + group_key=lb_types.GroupKey.AXIAL, + ) ] -polyline_label = lb_types.Label(data=lb_types.DicomData(uid="test-uid"), - annotations=dicom_polyline_annotations) +polyline_label = lb_types.Label( + data=lb_types.DicomData(uid="test-uid"), annotations=dicom_polyline_annotations +) polyline_annotation_ndjson = { - 'classifications': [], - 'dataRow': { - 'id': 'test-uid' - }, - 'name': - 'dicom_polyline', - 'groupKey': - 'axial', - 'segments': [{ - 'keyframes': [{ - 'frame': 2, - 'line': [ - { - 'x': 680.0, - 'y': 100.0 - }, - { - 'x': 100.0, - 'y': 190.0 - }, + "classifications": [], + "dataRow": {"id": "test-uid"}, + "name": "dicom_polyline", + "groupKey": "axial", + "segments": [ + { + "keyframes": [ { - 'x': 190.0, - 'y': 220.0 - }, - ], - 'classifications': [], - }] - }], + "frame": 2, + "line": [ + {"x": 680.0, "y": 100.0}, + {"x": 100.0, "y": 190.0}, + {"x": 190.0, "y": 220.0}, + ], + "classifications": [], + } + ] + } + ], } polyline_with_global_key = lb_types.Label( data=lb_types.DicomData(global_key="test-global-key"), - annotations=dicom_polyline_annotations) + annotations=dicom_polyline_annotations, +) polyline_annotation_ndjson_with_global_key = copy(polyline_annotation_ndjson) -polyline_annotation_ndjson_with_global_key['dataRow'] = { - 'globalKey': 'test-global-key' -} +polyline_annotation_ndjson_with_global_key["dataRow"] = {"globalKey": "test-global-key"} """ Video test data """ -instance_uri_1 = 'https://storage.labelbox.com/cjhfn5y6s0pk507024nz1ocys%2F1d60856c-59b7-3060-2754-83f7e93e0d01-1?Expires=1666901963361&KeyName=labelbox-assets-key-3&Signature=t-2s2DB4YjFuWEFak0wxYqfBfZA' -instance_uri_5 = 'https://storage.labelbox.com/cjhfn5y6s0pk507024nz1ocys1%2F1d60856c-59b7-3060-2754-83f7e93e0d01-1?Expires=1666901963361&KeyName=labelbox-assets-key-3&Signature=t-2s2DB4YjFuWEFak0wxYqfBfZA' +instance_uri_1 = "https://storage.labelbox.com/cjhfn5y6s0pk507024nz1ocys%2F1d60856c-59b7-3060-2754-83f7e93e0d01-1?Expires=1666901963361&KeyName=labelbox-assets-key-3&Signature=t-2s2DB4YjFuWEFak0wxYqfBfZA" +instance_uri_5 = "https://storage.labelbox.com/cjhfn5y6s0pk507024nz1ocys1%2F1d60856c-59b7-3060-2754-83f7e93e0d01-1?Expires=1666901963361&KeyName=labelbox-assets-key-3&Signature=t-2s2DB4YjFuWEFak0wxYqfBfZA" frames = [ lb_types.MaskFrame(index=1, instance_uri=instance_uri_1), - lb_types.MaskFrame(index=5, instance_uri=instance_uri_5) + lb_types.MaskFrame(index=5, instance_uri=instance_uri_5), ] instances = [ lb_types.MaskInstance(color_rgb=(0, 0, 255), name="mask1"), lb_types.MaskInstance(color_rgb=(0, 255, 0), name="mask2"), - lb_types.MaskInstance(color_rgb=(255, 0, 0), name="mask3") + lb_types.MaskInstance(color_rgb=(255, 0, 0), name="mask3"), ] -video_mask_annotation = lb_types.VideoMaskAnnotation(frames=frames, - instances=instances) +video_mask_annotation = lb_types.VideoMaskAnnotation(frames=frames, instances=instances) video_mask_annotation_ndjson = { - 'dataRow': { - 'id': 'test-uid' - }, - 'masks': { - 'frames': [{ - 'index': 1, - 'instanceURI': instance_uri_1 - }, { - 'index': 5, - 'instanceURI': instance_uri_5 - }], - 'instances': [ - { - 'colorRGB': (0, 0, 255), - 'name': 'mask1' - }, - { - 'colorRGB': (0, 255, 0), - 'name': 'mask2' - }, - { - 'colorRGB': (255, 0, 0), - 'name': 'mask3' - }, - ] + "dataRow": {"id": "test-uid"}, + "masks": { + "frames": [ + {"index": 1, "instanceURI": instance_uri_1}, + {"index": 5, "instanceURI": instance_uri_5}, + ], + "instances": [ + {"colorRGB": (0, 0, 255), "name": "mask1"}, + {"colorRGB": (0, 255, 0), "name": "mask2"}, + {"colorRGB": (255, 0, 0), "name": "mask3"}, + ], }, } -video_mask_annotation_ndjson_with_global_key = copy( - video_mask_annotation_ndjson) -video_mask_annotation_ndjson_with_global_key['dataRow'] = { - 'globalKey': 'test-global-key' +video_mask_annotation_ndjson_with_global_key = copy(video_mask_annotation_ndjson) +video_mask_annotation_ndjson_with_global_key["dataRow"] = { + "globalKey": "test-global-key" } -video_mask_label = lb_types.Label(data=lb_types.VideoData(uid="test-uid"), - annotations=[video_mask_annotation]) +video_mask_label = lb_types.Label( + data=lb_types.VideoData(uid="test-uid"), annotations=[video_mask_annotation] +) video_mask_label_with_global_key = lb_types.Label( data=lb_types.VideoData(global_key="test-global-key"), - annotations=[video_mask_annotation]) + annotations=[video_mask_annotation], +) """ DICOM Mask test data """ @@ -132,30 +117,35 @@ name="dicom_mask", group_key=lb_types.GroupKey.AXIAL, frames=frames, - instances=instances) + instances=instances, +) -dicom_mask_label = lb_types.Label(data=lb_types.DicomData(uid="test-uid"), - annotations=[dicom_mask_annotation]) +dicom_mask_label = lb_types.Label( + data=lb_types.DicomData(uid="test-uid"), annotations=[dicom_mask_annotation] +) dicom_mask_label_with_global_key = lb_types.Label( data=lb_types.DicomData(global_key="test-global-key"), - annotations=[dicom_mask_annotation]) + annotations=[dicom_mask_annotation], +) dicom_mask_annotation_ndjson = copy(video_mask_annotation_ndjson) -dicom_mask_annotation_ndjson['groupKey'] = 'axial' -dicom_mask_annotation_ndjson_with_global_key = copy( - dicom_mask_annotation_ndjson) -dicom_mask_annotation_ndjson_with_global_key['dataRow'] = { - 'globalKey': 'test-global-key' +dicom_mask_annotation_ndjson["groupKey"] = "axial" +dicom_mask_annotation_ndjson_with_global_key = copy(dicom_mask_annotation_ndjson) +dicom_mask_annotation_ndjson_with_global_key["dataRow"] = { + "globalKey": "test-global-key" } """ Tests """ labels = [ - polyline_label, polyline_with_global_key, dicom_mask_label, - dicom_mask_label_with_global_key, video_mask_label, - video_mask_label_with_global_key + polyline_label, + polyline_with_global_key, + dicom_mask_label, + dicom_mask_label_with_global_key, + video_mask_label, + video_mask_label_with_global_key, ] ndjsons = [ polyline_annotation_ndjson, @@ -175,35 +165,9 @@ def test_deserialize_nd_dicom_segments(): assert isinstance(nd_dicom_segments.segments[0].keyframes[0], NDDicomLine) -@pytest.mark.parametrize('label, ndjson', labels_ndjsons) +@pytest.mark.parametrize("label, ndjson", labels_ndjsons) def test_serialize_label(label, ndjson): serialized_label = next(NDJsonConverter().serialize([label])) if "uuid" in serialized_label: - serialized_label.pop('uuid') + serialized_label.pop("uuid") assert serialized_label == ndjson - - -@pytest.mark.parametrize('label, ndjson', labels_ndjsons) -def test_deserialize_label(label, ndjson): - deserialized_label = next(NDJsonConverter().deserialize([ndjson])) - if hasattr(deserialized_label.annotations[0], 'extra'): - deserialized_label.annotations[0].extra = {} - for i, annotation in enumerate(deserialized_label.annotations): - if hasattr(annotation, "frames"): - assert annotation.frames == label.annotations[i].frames - if hasattr(annotation, "value"): - assert annotation.value == label.annotations[i].value - - - -@pytest.mark.parametrize('label', labels) -def test_serialize_deserialize_label(label): - serialized = list(NDJsonConverter.serialize([label])) - deserialized = list(NDJsonConverter.deserialize(serialized)) - if hasattr(deserialized[0].annotations[0], 'extra'): - deserialized[0].annotations[0].extra = {} - for i, annotation in enumerate(deserialized[0].annotations): - if hasattr(annotation, "frames"): - assert annotation.frames == label.annotations[i].frames - if hasattr(annotation, "value"): - assert annotation.value == label.annotations[i].value diff --git a/libs/labelbox/tests/data/serialization/ndjson/test_document.py b/libs/labelbox/tests/data/serialization/ndjson/test_document.py index cdfbbbb88..87f587496 100644 --- a/libs/labelbox/tests/data/serialization/ndjson/test_document.py +++ b/libs/labelbox/tests/data/serialization/ndjson/test_document.py @@ -1,6 +1,17 @@ import json +from labelbox.data.mixins import CustomMetric import labelbox.types as lb_types from labelbox.data.serialization.ndjson.converter import NDJsonConverter +from labelbox.types import ( + Label, + GenericDataRowData, + ObjectAnnotation, + RectangleUnit, + Point, + DocumentRectangle, + DocumentEntity, + DocumentTextSelection, +) bbox_annotation = lb_types.ObjectAnnotation( name="bounding_box", # must match your ontology feature's name @@ -8,26 +19,30 @@ start=lb_types.Point(x=42.799, y=86.498), # Top left end=lb_types.Point(x=141.911, y=303.195), # Bottom right page=1, - unit=lb_types.RectangleUnit.POINTS)) + unit=lb_types.RectangleUnit.POINTS, + ), +) bbox_labels = [ - lb_types.Label(data=lb_types.DocumentData(global_key='test-global-key'), - annotations=[bbox_annotation]) + lb_types.Label( + data=lb_types.DocumentData(global_key="test-global-key"), + annotations=[bbox_annotation], + ) +] +bbox_ndjson = [ + { + "bbox": { + "height": 216.697, + "left": 42.799, + "top": 86.498, + "width": 99.112, + }, + "classifications": [], + "dataRow": {"globalKey": "test-global-key"}, + "name": "bounding_box", + "page": 1, + "unit": "POINTS", + } ] -bbox_ndjson = [{ - 'bbox': { - 'height': 216.697, - 'left': 42.799, - 'top': 86.498, - 'width': 99.112, - }, - 'classifications': [], - 'dataRow': { - 'globalKey': 'test-global-key' - }, - 'name': 'bounding_box', - 'page': 1, - 'unit': 'POINTS' -}] def round_dict(data): @@ -47,34 +62,283 @@ def test_pdf(): """ Tests a pdf file with bbox annotations only """ - with open('tests/data/assets/ndjson/pdf_import.json', 'r') as f: + with open("tests/data/assets/ndjson/pdf_import.json", "r") as f: data = json.load(f) - res = list(NDJsonConverter.deserialize(data)) - res = list(NDJsonConverter.serialize(res)) + labels = [ + Label( + uid=None, + data=GenericDataRowData( + uid="cl6xnv9h61fv0085yhtoq06ht", + ), + annotations=[ + ObjectAnnotation( + custom_metrics=[ + CustomMetric(name="customMetric1", value=0.5), + CustomMetric(name="customMetric2", value=0.3), + ], + confidence=0.53, + name="boxy", + feature_schema_id="cl6xnuwt95lqq07330tbb3mfd", + extra={ + "uuid": "5ad9c52f-058d-49c8-a749-3f20b84f8cd4", + }, + value=DocumentRectangle( + start=Point(x=32.45, y=162.73), + end=Point(x=134.11, y=550.9), + page=4, + unit=RectangleUnit.POINTS, + ), + ), + ObjectAnnotation( + name="boxy", + feature_schema_id="cl6xnuwt95lqq07330tbb3mfd", + extra={ + "uuid": "20eeef88-0294-49b4-a815-86588476bc6f", + }, + value=DocumentRectangle( + start=Point(x=251.42, y=223.26), + end=Point(x=438.2, y=680.3), + page=7, + unit=RectangleUnit.POINTS, + ), + ), + ObjectAnnotation( + custom_metrics=[ + CustomMetric(name="customMetric1", value=0.5), + CustomMetric(name="customMetric2", value=0.3), + ], + confidence=0.99, + name="boxy", + feature_schema_id="cl6xnuwt95lqq07330tbb3mfd", + extra={ + "uuid": "641a8944-3938-409c-b4eb-dea354ed06e5", + }, + value=DocumentRectangle( + start=Point(x=218.17, y=32.52), + end=Point(x=328.73, y=264.25), + page=6, + unit=RectangleUnit.POINTS, + ), + ), + ObjectAnnotation( + custom_metrics=[ + CustomMetric(name="customMetric1", value=0.5), + CustomMetric(name="customMetric2", value=0.3), + ], + confidence=0.89, + name="boxy", + feature_schema_id="cl6xnuwt95lqq07330tbb3mfd", + extra={ + "uuid": "ebe4da7d-08b3-480a-8d15-26552b7f011c", + }, + value=DocumentRectangle( + start=Point(x=4.25, y=117.39), + end=Point(x=169.08, y=574.3100000000001), + page=7, + unit=RectangleUnit.POINTS, + ), + ), + ObjectAnnotation( + name="boxy", + feature_schema_id="cl6xnuwt95lqq07330tbb3mfd", + extra={ + "uuid": "35c41855-575f-42cc-a2f9-1f06237e9b63", + }, + value=DocumentRectangle( + start=Point(x=217.28, y=82.13), + end=Point(x=299.71000000000004, y=361.89), + page=8, + unit=RectangleUnit.POINTS, + ), + ), + ObjectAnnotation( + name="boxy", + feature_schema_id="cl6xnuwt95lqq07330tbb3mfd", + extra={ + "uuid": "1b009654-bc17-42a2-8a71-160e7808c403", + }, + value=DocumentRectangle( + start=Point(x=83.34, y=298.12), + end=Point(x=83.72, y=501.95000000000005), + page=3, + unit=RectangleUnit.POINTS, + ), + ), + ], + ), + Label( + data=GenericDataRowData( + uid="ckrb1sf1i1g7i0ybcdc6oc8ct", + ), + annotations=[ + ObjectAnnotation( + name="named_entity", + feature_schema_id="cl6xnuwt95lqq07330tbb3mfd", + extra={ + "uuid": "f6879f59-d2b5-49c2-aceb-d9e8dc478673", + }, + value=DocumentEntity( + text_selections=[ + DocumentTextSelection( + token_ids=[ + "3f984bf3-1d61-44f5-b59a-9658a2e3440f", + "3bf00b56-ff12-4e52-8cc1-08dbddb3c3b8", + "6e1c3420-d4b7-4c5a-8fd6-ead43bf73d80", + "87a43d32-af76-4a1d-b262-5c5f4d5ace3a", + "e8606e8a-dfd9-4c49-a635-ad5c879c75d0", + "67c7c19e-4654-425d-bf17-2adb8cf02c30", + "149c5e80-3e07-49a7-ab2d-29ddfe6a38fa", + "b0e94071-2187-461e-8e76-96c58738a52c", + ], + group_id="2f4336f4-a07e-4e0a-a9e1-5629b03b719b", + page=1, + ) + ] + ), + ) + ], + ), + ] + + res = list(NDJsonConverter.serialize(labels)) assert [round_dict(x) for x in res] == [round_dict(x) for x in data] - f.close() def test_pdf_with_name_only(): """ Tests a pdf file with bbox annotations only """ - with open('tests/data/assets/ndjson/pdf_import_name_only.json', 'r') as f: + with open("tests/data/assets/ndjson/pdf_import_name_only.json", "r") as f: data = json.load(f) - res = list(NDJsonConverter.deserialize(data)) - res = list(NDJsonConverter.serialize(res)) + + labels = [ + Label( + data=GenericDataRowData( + uid="cl6xnv9h61fv0085yhtoq06ht", + ), + annotations=[ + ObjectAnnotation( + custom_metrics=[ + CustomMetric(name="customMetric1", value=0.5), + CustomMetric(name="customMetric2", value=0.3), + ], + confidence=0.99, + name="boxy", + feature_schema_id=None, + extra={ + "uuid": "5ad9c52f-058d-49c8-a749-3f20b84f8cd4", + }, + value=DocumentRectangle( + start=Point(x=32.45, y=162.73), + end=Point(x=134.11, y=550.9), + page=4, + unit=RectangleUnit.POINTS, + ), + ), + ObjectAnnotation( + name="boxy", + extra={ + "uuid": "20eeef88-0294-49b4-a815-86588476bc6f", + }, + value=DocumentRectangle( + start=Point(x=251.42, y=223.26), + end=Point(x=438.2, y=680.3), + page=7, + unit=RectangleUnit.POINTS, + ), + ), + ObjectAnnotation( + name="boxy", + extra={ + "uuid": "641a8944-3938-409c-b4eb-dea354ed06e5", + }, + value=DocumentRectangle( + start=Point(x=218.17, y=32.52), + end=Point(x=328.73, y=264.25), + page=6, + unit=RectangleUnit.POINTS, + ), + ), + ObjectAnnotation( + custom_metrics=[ + CustomMetric(name="customMetric1", value=0.5), + CustomMetric(name="customMetric2", value=0.3), + ], + confidence=0.74, + name="boxy", + extra={ + "uuid": "ebe4da7d-08b3-480a-8d15-26552b7f011c", + }, + value=DocumentRectangle( + start=Point(x=4.25, y=117.39), + end=Point(x=169.08, y=574.3100000000001), + page=7, + unit=RectangleUnit.POINTS, + ), + ), + ObjectAnnotation( + name="boxy", + extra={ + "uuid": "35c41855-575f-42cc-a2f9-1f06237e9b63", + }, + value=DocumentRectangle( + start=Point(x=217.28, y=82.13), + end=Point(x=299.71000000000004, y=361.89), + page=8, + unit=RectangleUnit.POINTS, + ), + ), + ObjectAnnotation( + name="boxy", + extra={ + "uuid": "1b009654-bc17-42a2-8a71-160e7808c403", + }, + value=DocumentRectangle( + start=Point(x=83.34, y=298.12), + end=Point(x=83.72, y=501.95000000000005), + page=3, + unit=RectangleUnit.POINTS, + ), + ), + ], + ), + Label( + data=GenericDataRowData( + uid="ckrb1sf1i1g7i0ybcdc6oc8ct", + ), + annotations=[ + ObjectAnnotation( + name="named_entity", + extra={ + "uuid": "f6879f59-d2b5-49c2-aceb-d9e8dc478673", + }, + value=DocumentEntity( + text_selections=[ + DocumentTextSelection( + token_ids=[ + "3f984bf3-1d61-44f5-b59a-9658a2e3440f", + "3bf00b56-ff12-4e52-8cc1-08dbddb3c3b8", + "6e1c3420-d4b7-4c5a-8fd6-ead43bf73d80", + "87a43d32-af76-4a1d-b262-5c5f4d5ace3a", + "e8606e8a-dfd9-4c49-a635-ad5c879c75d0", + "67c7c19e-4654-425d-bf17-2adb8cf02c30", + "149c5e80-3e07-49a7-ab2d-29ddfe6a38fa", + "b0e94071-2187-461e-8e76-96c58738a52c", + ], + group_id="2f4336f4-a07e-4e0a-a9e1-5629b03b719b", + page=1, + ) + ] + ), + ) + ], + ), + ] + res = list(NDJsonConverter.serialize(labels)) assert [round_dict(x) for x in res] == [round_dict(x) for x in data] - f.close() def test_pdf_bbox_serialize(): serialized = list(NDJsonConverter.serialize(bbox_labels)) - serialized[0].pop('uuid') + serialized[0].pop("uuid") assert serialized == bbox_ndjson - - -def test_pdf_bbox_deserialize(): - deserialized = list(NDJsonConverter.deserialize(bbox_ndjson)) - deserialized[0].annotations[0].extra = {} - assert deserialized[0].annotations[0].value == bbox_labels[0].annotations[0].value - assert deserialized[0].annotations[0].name == bbox_labels[0].annotations[0].name \ No newline at end of file diff --git a/libs/labelbox/tests/data/serialization/ndjson/test_export_video_objects.py b/libs/labelbox/tests/data/serialization/ndjson/test_export_video_objects.py index c85b48234..1ab678cde 100644 --- a/libs/labelbox/tests/data/serialization/ndjson/test_export_video_objects.py +++ b/libs/labelbox/tests/data/serialization/ndjson/test_export_video_objects.py @@ -6,621 +6,585 @@ def video_bbox_label(): return Label( - uid='cl1z52xwh00050fhcmfgczqvn', + uid="cl1z52xwh00050fhcmfgczqvn", data=VideoData( uid="cklr9mr4m5iao0rb6cvxu4qbn", - file_path=None, - frames=None, - url= - "https://storage.labelbox.com/ckcz6bubudyfi0855o1dt1g9s%2F26403a22-604a-a38c-eeff-c2ed481fb40a-cat.mp4?Expires=1651677421050&KeyName=labelbox-assets-key-3&Signature=vF7gMyfHzgZdfbB8BHgd88Ws-Ms" + url="https://storage.labelbox.com/ckcz6bubudyfi0855o1dt1g9s%2F26403a22-604a-a38c-eeff-c2ed481fb40a-cat.mp4?Expires=1651677421050&KeyName=labelbox-assets-key-3&Signature=vF7gMyfHzgZdfbB8BHgd88Ws-Ms", ), annotations=[ - VideoObjectAnnotation(name='bbox toy', - feature_schema_id='ckz38ofop0mci0z9i9w3aa9o4', - extra={ - 'value': 'bbox_toy', - 'instanceURI': None, - 'color': '#1CE6FF', - 'feature_id': 'cl1z52xw700000fhcayaqy0ev' - }, - value=Rectangle(extra={}, - start=Point(extra={}, - x=70.0, - y=46.0), - end=Point(extra={}, - x=454.0, - y=295.0)), - classifications=[], - frame=1, - keyframe=True), - VideoObjectAnnotation(name='bbox toy', - feature_schema_id='ckz38ofop0mci0z9i9w3aa9o4', - extra={ - 'value': 'bbox_toy', - 'instanceURI': None, - 'color': '#1CE6FF', - 'feature_id': 'cl1z52xw700000fhcayaqy0ev' - }, - value=Rectangle(extra={}, - start=Point(extra={}, - x=70.0, - y=42.5), - end=Point(extra={}, - x=427.25, - y=308.25)), - classifications=[], - frame=2, - keyframe=False), - VideoObjectAnnotation(name='bbox toy', - feature_schema_id='ckz38ofop0mci0z9i9w3aa9o4', - extra={ - 'value': 'bbox_toy', - 'instanceURI': None, - 'color': '#1CE6FF', - 'feature_id': 'cl1z52xw700000fhcayaqy0ev' - }, - value=Rectangle(extra={}, - start=Point(extra={}, - x=70.0, - y=39.0), - end=Point(extra={}, - x=400.5, - y=321.5)), - classifications=[], - frame=3, - keyframe=False), - VideoObjectAnnotation(name='bbox toy', - feature_schema_id='ckz38ofop0mci0z9i9w3aa9o4', - extra={ - 'value': 'bbox_toy', - 'instanceURI': None, - 'color': '#1CE6FF', - 'feature_id': 'cl1z52xw700000fhcayaqy0ev' - }, - value=Rectangle(extra={}, - start=Point(extra={}, - x=70.0, - y=35.5), - end=Point(extra={}, - x=373.75, - y=334.75)), - classifications=[], - frame=4, - keyframe=False), - VideoObjectAnnotation(name='bbox toy', - feature_schema_id='ckz38ofop0mci0z9i9w3aa9o4', - extra={ - 'value': 'bbox_toy', - 'instanceURI': None, - 'color': '#1CE6FF', - 'feature_id': 'cl1z52xw700000fhcayaqy0ev' - }, - value=Rectangle(extra={}, - start=Point(extra={}, - x=70.0, - y=32.0), - end=Point(extra={}, - x=347.0, - y=348.0)), - classifications=[], - frame=5, - keyframe=True), - VideoObjectAnnotation(name='bbox toy', - feature_schema_id='ckz38ofop0mci0z9i9w3aa9o4', - extra={ - 'value': 'bbox_toy', - 'instanceURI': None, - 'color': '#1CE6FF', - 'feature_id': 'cl1z52xw700000fhcayaqy0ev' - }, - value=Rectangle(extra={}, - start=Point(extra={}, - x=70.0, - y=132.0), - end=Point(extra={}, - x=283.0, - y=348.0)), - classifications=[], - frame=9, - keyframe=True), - VideoObjectAnnotation(name='bbox toy', - feature_schema_id='ckz38ofop0mci0z9i9w3aa9o4', - extra={ - 'value': 'bbox_toy', - 'instanceURI': None, - 'color': '#1CE6FF', - 'feature_id': 'cl1z52xw700000fhcayaqy0ev' - }, - value=Rectangle(extra={}, - start=Point(extra={}, - x=70.0, - y=122.333), - end=Point(extra={}, - x=295.5, - y=348.0)), - classifications=[], - frame=10, - keyframe=False), - VideoObjectAnnotation(name='bbox toy', - feature_schema_id='ckz38ofop0mci0z9i9w3aa9o4', - extra={ - 'value': 'bbox_toy', - 'instanceURI': None, - 'color': '#1CE6FF', - 'feature_id': 'cl1z52xw700000fhcayaqy0ev' - }, - value=Rectangle(extra={}, - start=Point(extra={}, - x=70.0, - y=112.667), - end=Point(extra={}, - x=308.0, - y=348.0)), - classifications=[], - frame=11, - keyframe=False), - VideoObjectAnnotation(name='bbox toy', - feature_schema_id='ckz38ofop0mci0z9i9w3aa9o4', - extra={ - 'value': 'bbox_toy', - 'instanceURI': None, - 'color': '#1CE6FF', - 'feature_id': 'cl1z52xw700000fhcayaqy0ev' - }, - value=Rectangle(extra={}, - start=Point(extra={}, - x=70.0, - y=103.0), - end=Point(extra={}, - x=320.5, - y=348.0)), - classifications=[], - frame=12, - keyframe=False), - VideoObjectAnnotation(name='bbox toy', - feature_schema_id='ckz38ofop0mci0z9i9w3aa9o4', - extra={ - 'value': 'bbox_toy', - 'instanceURI': None, - 'color': '#1CE6FF', - 'feature_id': 'cl1z52xw700000fhcayaqy0ev' - }, - value=Rectangle(extra={}, - start=Point(extra={}, - x=70.0, - y=93.333), - end=Point(extra={}, - x=333.0, - y=348.0)), - classifications=[], - frame=13, - keyframe=False), - VideoObjectAnnotation(name='bbox toy', - feature_schema_id='ckz38ofop0mci0z9i9w3aa9o4', - extra={ - 'value': 'bbox_toy', - 'instanceURI': None, - 'color': '#1CE6FF', - 'feature_id': 'cl1z52xw700000fhcayaqy0ev' - }, - value=Rectangle(extra={}, - start=Point(extra={}, - x=70.0, - y=83.667), - end=Point(extra={}, - x=345.5, - y=348.0)), - classifications=[], - frame=14, - keyframe=False), - VideoObjectAnnotation(name='bbox toy', - feature_schema_id='ckz38ofop0mci0z9i9w3aa9o4', - extra={ - 'value': 'bbox_toy', - 'instanceURI': None, - 'color': '#1CE6FF', - 'feature_id': 'cl1z52xw700000fhcayaqy0ev' - }, - value=Rectangle(extra={}, - start=Point(extra={}, - x=70.0, - y=74.0), - end=Point(extra={}, - x=358.0, - y=348.0)), - classifications=[], - frame=15, - keyframe=True), - VideoObjectAnnotation(name='bbox toy', - feature_schema_id='ckz38ofop0mci0z9i9w3aa9o4', - extra={ - 'value': 'bbox_toy', - 'instanceURI': None, - 'color': '#1CE6FF', - 'feature_id': 'cl1z52xw700000fhcayaqy0ev' - }, - value=Rectangle(extra={}, - start=Point(extra={}, - x=70.0, - y=66.833), - end=Point(extra={}, - x=387.333, - y=348.0)), - classifications=[], - frame=16, - keyframe=False), - VideoObjectAnnotation(name='bbox toy', - feature_schema_id='ckz38ofop0mci0z9i9w3aa9o4', - extra={ - 'value': 'bbox_toy', - 'instanceURI': None, - 'color': '#1CE6FF', - 'feature_id': 'cl1z52xw700000fhcayaqy0ev' - }, - value=Rectangle(extra={}, - start=Point(extra={}, - x=70.0, - y=59.667), - end=Point(extra={}, - x=416.667, - y=348.0)), - classifications=[], - frame=17, - keyframe=False), - VideoObjectAnnotation(name='bbox toy', - feature_schema_id='ckz38ofop0mci0z9i9w3aa9o4', - extra={ - 'value': 'bbox_toy', - 'instanceURI': None, - 'color': '#1CE6FF', - 'feature_id': 'cl1z52xw700000fhcayaqy0ev' - }, - value=Rectangle(extra={}, - start=Point(extra={}, - x=70.0, - y=52.5), - end=Point(extra={}, - x=446.0, - y=348.0)), - classifications=[], - frame=18, - keyframe=False), - VideoObjectAnnotation(name='bbox toy', - feature_schema_id='ckz38ofop0mci0z9i9w3aa9o4', - extra={ - 'value': 'bbox_toy', - 'instanceURI': None, - 'color': '#1CE6FF', - 'feature_id': 'cl1z52xw700000fhcayaqy0ev' - }, - value=Rectangle(extra={}, - start=Point(extra={}, - x=70.0, - y=45.333), - end=Point(extra={}, - x=475.333, - y=348.0)), - classifications=[], - frame=19, - keyframe=False), - VideoObjectAnnotation(name='bbox toy', - feature_schema_id='ckz38ofop0mci0z9i9w3aa9o4', - extra={ - 'value': 'bbox_toy', - 'instanceURI': None, - 'color': '#1CE6FF', - 'feature_id': 'cl1z52xw700000fhcayaqy0ev' - }, - value=Rectangle(extra={}, - start=Point(extra={}, - x=70.0, - y=38.167), - end=Point(extra={}, - x=504.667, - y=348.0)), - classifications=[], - frame=20, - keyframe=False), - VideoObjectAnnotation(name='bbox toy', - feature_schema_id='ckz38ofop0mci0z9i9w3aa9o4', - extra={ - 'value': 'bbox_toy', - 'instanceURI': None, - 'color': '#1CE6FF', - 'feature_id': 'cl1z52xw700000fhcayaqy0ev' - }, - value=Rectangle(extra={}, - start=Point(extra={}, - x=70.0, - y=31.0), - end=Point(extra={}, - x=534.0, - y=348.0)), - classifications=[], - frame=21, - keyframe=True), - VideoObjectAnnotation(name='bbox toy', - feature_schema_id='ckz38ofop0mci0z9i9w3aa9o4', - extra={ - 'value': 'bbox_toy', - 'instanceURI': None, - 'color': '#1CE6FF', - 'feature_id': 'cl1z52xw700000fhcayaqy0ev' - }, - value=Rectangle(extra={}, - start=Point(extra={}, - x=70.0, - y=29.5), - end=Point(extra={}, - x=543.0, - y=348.0)), - classifications=[], - frame=22, - keyframe=False), - VideoObjectAnnotation(name='bbox toy', - feature_schema_id='ckz38ofop0mci0z9i9w3aa9o4', - extra={ - 'value': 'bbox_toy', - 'instanceURI': None, - 'color': '#1CE6FF', - 'feature_id': 'cl1z52xw700000fhcayaqy0ev' - }, - value=Rectangle(extra={}, - start=Point(extra={}, - x=70.0, - y=28.0), - end=Point(extra={}, - x=552.0, - y=348.0)), - classifications=[], - frame=23, - keyframe=False), - VideoObjectAnnotation(name='bbox toy', - feature_schema_id='ckz38ofop0mci0z9i9w3aa9o4', - extra={ - 'value': 'bbox_toy', - 'instanceURI': None, - 'color': '#1CE6FF', - 'feature_id': 'cl1z52xw700000fhcayaqy0ev' - }, - value=Rectangle(extra={}, - start=Point(extra={}, - x=70.0, - y=26.5), - end=Point(extra={}, - x=561.0, - y=348.0)), - classifications=[], - frame=24, - keyframe=False), - VideoObjectAnnotation(name='bbox toy', - feature_schema_id='ckz38ofop0mci0z9i9w3aa9o4', - extra={ - 'value': 'bbox_toy', - 'instanceURI': None, - 'color': '#1CE6FF', - 'feature_id': 'cl1z52xw700000fhcayaqy0ev' - }, - value=Rectangle(extra={}, - start=Point(extra={}, - x=70.0, - y=25.0), - end=Point(extra={}, - x=570.0, - y=348.0)), - classifications=[], - frame=25, - keyframe=False), - VideoObjectAnnotation(name='bbox toy', - feature_schema_id='ckz38ofop0mci0z9i9w3aa9o4', - extra={ - 'value': 'bbox_toy', - 'instanceURI': None, - 'color': '#1CE6FF', - 'feature_id': 'cl1z52xw700000fhcayaqy0ev' - }, - value=Rectangle(extra={}, - start=Point(extra={}, - x=70.0, - y=23.5), - end=Point(extra={}, - x=579.0, - y=348.0)), - classifications=[], - frame=26, - keyframe=False), - VideoObjectAnnotation(name='bbox toy', - feature_schema_id='ckz38ofop0mci0z9i9w3aa9o4', - extra={ - 'value': 'bbox_toy', - 'instanceURI': None, - 'color': '#1CE6FF', - 'feature_id': 'cl1z52xw700000fhcayaqy0ev' - }, - value=Rectangle(extra={}, - start=Point(extra={}, - x=70.0, - y=22.0), - end=Point(extra={}, - x=588.0, - y=348.0)), - classifications=[], - frame=27, - keyframe=False), - VideoObjectAnnotation(name='bbox toy', - feature_schema_id='ckz38ofop0mci0z9i9w3aa9o4', - extra={ - 'value': 'bbox_toy', - 'instanceURI': None, - 'color': '#1CE6FF', - 'feature_id': 'cl1z52xw700000fhcayaqy0ev' - }, - value=Rectangle(extra={}, - start=Point(extra={}, - x=70.0, - y=20.5), - end=Point(extra={}, - x=597.0, - y=348.0)), - classifications=[], - frame=28, - keyframe=False), - VideoObjectAnnotation(name='bbox toy', - feature_schema_id='ckz38ofop0mci0z9i9w3aa9o4', - extra={ - 'value': 'bbox_toy', - 'instanceURI': None, - 'color': '#1CE6FF', - 'feature_id': 'cl1z52xw700000fhcayaqy0ev' - }, - value=Rectangle(extra={}, - start=Point(extra={}, - x=70.0, - y=19.0), - end=Point(extra={}, - x=606.0, - y=348.0)), - classifications=[], - frame=29, - keyframe=True) - ], - extra={ - 'Created By': - 'jtso@labelbox.com', - 'Project Name': - 'Pictor Video', - 'Created At': - '2022-04-14T15:11:19.000Z', - 'Updated At': - '2022-04-14T15:11:21.064Z', - 'Seconds to Label': - 0.0, - 'Agreement': - -1.0, - 'Benchmark Agreement': - -1.0, - 'Benchmark ID': - None, - 'Dataset Name': - 'cat', - 'Reviews': [], - 'View Label': - 'https://editor.labelbox.com?project=ckz38nsfd0lzq109bhq73est1&label=cl1z52xwh00050fhcmfgczqvn', - 'Has Open Issues': - 0.0, - 'Skipped': - False, - 'media_type': - 'video', - 'Data Split': - None - }) - - -def video_serialized_bbox_label(): - return { - 'uuid': - 'b24e672b-8f79-4d96-bf5e-b552ca0820d5', - 'dataRow': { - 'id': 'cklr9mr4m5iao0rb6cvxu4qbn' - }, - 'schemaId': - 'ckz38ofop0mci0z9i9w3aa9o4', - 'name': - 'bbox toy', - 'classifications': [], - 'segments': [{ - 'keyframes': [{ - 'frame': 1, - 'bbox': { - 'top': 46.0, - 'left': 70.0, - 'height': 249.0, - 'width': 384.0 + VideoObjectAnnotation( + name="bbox toy", + feature_schema_id="ckz38ofop0mci0z9i9w3aa9o4", + extra={ + "value": "bbox_toy", + "instanceURI": None, + "color": "#1CE6FF", + "feature_id": "cl1z52xw700000fhcayaqy0ev", + "uuid": "b24e672b-8f79-4d96-bf5e-b552ca0820d5", }, - 'classifications': [] - }, { - 'frame': 5, - 'bbox': { - 'top': 32.0, - 'left': 70.0, - 'height': 316.0, - 'width': 277.0 + value=Rectangle( + extra={}, + start=Point(extra={}, x=70.0, y=46.0), + end=Point(extra={}, x=454.0, y=295.0), + ), + classifications=[], + frame=1, + keyframe=True, + ), + VideoObjectAnnotation( + name="bbox toy", + feature_schema_id="ckz38ofop0mci0z9i9w3aa9o4", + extra={ + "value": "bbox_toy", + "instanceURI": None, + "color": "#1CE6FF", + "feature_id": "cl1z52xw700000fhcayaqy0ev", }, - 'classifications': [] - }] - }, { - 'keyframes': [{ - 'frame': 9, - 'bbox': { - 'top': 132.0, - 'left': 70.0, - 'height': 216.0, - 'width': 213.0 + value=Rectangle( + extra={}, + start=Point(extra={}, x=70.0, y=42.5), + end=Point(extra={}, x=427.25, y=308.25), + ), + classifications=[], + frame=2, + keyframe=False, + ), + VideoObjectAnnotation( + name="bbox toy", + feature_schema_id="ckz38ofop0mci0z9i9w3aa9o4", + extra={ + "value": "bbox_toy", + "instanceURI": None, + "color": "#1CE6FF", + "feature_id": "cl1z52xw700000fhcayaqy0ev", }, - 'classifications': [] - }, { - 'frame': 15, - 'bbox': { - 'top': 74.0, - 'left': 70.0, - 'height': 274.0, - 'width': 288.0 + value=Rectangle( + extra={}, + start=Point(extra={}, x=70.0, y=39.0), + end=Point(extra={}, x=400.5, y=321.5), + ), + classifications=[], + frame=3, + keyframe=False, + ), + VideoObjectAnnotation( + name="bbox toy", + feature_schema_id="ckz38ofop0mci0z9i9w3aa9o4", + extra={ + "value": "bbox_toy", + "instanceURI": None, + "color": "#1CE6FF", + "feature_id": "cl1z52xw700000fhcayaqy0ev", }, - 'classifications': [] - }, { - 'frame': 21, - 'bbox': { - 'top': 31.0, - 'left': 70.0, - 'height': 317.0, - 'width': 464.0 + value=Rectangle( + extra={}, + start=Point(extra={}, x=70.0, y=35.5), + end=Point(extra={}, x=373.75, y=334.75), + ), + classifications=[], + frame=4, + keyframe=False, + ), + VideoObjectAnnotation( + name="bbox toy", + feature_schema_id="ckz38ofop0mci0z9i9w3aa9o4", + extra={ + "value": "bbox_toy", + "instanceURI": None, + "color": "#1CE6FF", + "feature_id": "cl1z52xw700000fhcayaqy0ev", }, - 'classifications': [] - }, { - 'frame': 29, - 'bbox': { - 'top': 19.0, - 'left': 70.0, - 'height': 329.0, - 'width': 536.0 + value=Rectangle( + extra={}, + start=Point(extra={}, x=70.0, y=32.0), + end=Point(extra={}, x=347.0, y=348.0), + ), + classifications=[], + frame=5, + keyframe=True, + ), + VideoObjectAnnotation( + name="bbox toy", + feature_schema_id="ckz38ofop0mci0z9i9w3aa9o4", + extra={ + "value": "bbox_toy", + "instanceURI": None, + "color": "#1CE6FF", + "feature_id": "cl1z52xw700000fhcayaqy0ev", }, - 'classifications': [] - }] - }] - } - - -def test_serialize_video_objects(): - label = video_bbox_label() - serialized_labels = NDJsonConverter.serialize([label]) - label = next(serialized_labels) - - manual_label = video_serialized_bbox_label() - - for key in label.keys(): - # ignore uuid because we randomize if there was none - if key != "uuid": - assert label[key] == manual_label[key] + value=Rectangle( + extra={}, + start=Point(extra={}, x=70.0, y=132.0), + end=Point(extra={}, x=283.0, y=348.0), + ), + classifications=[], + frame=9, + keyframe=True, + ), + VideoObjectAnnotation( + name="bbox toy", + feature_schema_id="ckz38ofop0mci0z9i9w3aa9o4", + extra={ + "value": "bbox_toy", + "instanceURI": None, + "color": "#1CE6FF", + "feature_id": "cl1z52xw700000fhcayaqy0ev", + }, + value=Rectangle( + extra={}, + start=Point(extra={}, x=70.0, y=122.333), + end=Point(extra={}, x=295.5, y=348.0), + ), + classifications=[], + frame=10, + keyframe=False, + ), + VideoObjectAnnotation( + name="bbox toy", + feature_schema_id="ckz38ofop0mci0z9i9w3aa9o4", + extra={ + "value": "bbox_toy", + "instanceURI": None, + "color": "#1CE6FF", + "feature_id": "cl1z52xw700000fhcayaqy0ev", + }, + value=Rectangle( + extra={}, + start=Point(extra={}, x=70.0, y=112.667), + end=Point(extra={}, x=308.0, y=348.0), + ), + classifications=[], + frame=11, + keyframe=False, + ), + VideoObjectAnnotation( + name="bbox toy", + feature_schema_id="ckz38ofop0mci0z9i9w3aa9o4", + extra={ + "value": "bbox_toy", + "instanceURI": None, + "color": "#1CE6FF", + "feature_id": "cl1z52xw700000fhcayaqy0ev", + }, + value=Rectangle( + extra={}, + start=Point(extra={}, x=70.0, y=103.0), + end=Point(extra={}, x=320.5, y=348.0), + ), + classifications=[], + frame=12, + keyframe=False, + ), + VideoObjectAnnotation( + name="bbox toy", + feature_schema_id="ckz38ofop0mci0z9i9w3aa9o4", + extra={ + "value": "bbox_toy", + "instanceURI": None, + "color": "#1CE6FF", + "feature_id": "cl1z52xw700000fhcayaqy0ev", + }, + value=Rectangle( + extra={}, + start=Point(extra={}, x=70.0, y=93.333), + end=Point(extra={}, x=333.0, y=348.0), + ), + classifications=[], + frame=13, + keyframe=False, + ), + VideoObjectAnnotation( + name="bbox toy", + feature_schema_id="ckz38ofop0mci0z9i9w3aa9o4", + extra={ + "value": "bbox_toy", + "instanceURI": None, + "color": "#1CE6FF", + "feature_id": "cl1z52xw700000fhcayaqy0ev", + }, + value=Rectangle( + extra={}, + start=Point(extra={}, x=70.0, y=83.667), + end=Point(extra={}, x=345.5, y=348.0), + ), + classifications=[], + frame=14, + keyframe=False, + ), + VideoObjectAnnotation( + name="bbox toy", + feature_schema_id="ckz38ofop0mci0z9i9w3aa9o4", + extra={ + "value": "bbox_toy", + "instanceURI": None, + "color": "#1CE6FF", + "feature_id": "cl1z52xw700000fhcayaqy0ev", + }, + value=Rectangle( + extra={}, + start=Point(extra={}, x=70.0, y=74.0), + end=Point(extra={}, x=358.0, y=348.0), + ), + classifications=[], + frame=15, + keyframe=True, + ), + VideoObjectAnnotation( + name="bbox toy", + feature_schema_id="ckz38ofop0mci0z9i9w3aa9o4", + extra={ + "value": "bbox_toy", + "instanceURI": None, + "color": "#1CE6FF", + "feature_id": "cl1z52xw700000fhcayaqy0ev", + }, + value=Rectangle( + extra={}, + start=Point(extra={}, x=70.0, y=66.833), + end=Point(extra={}, x=387.333, y=348.0), + ), + classifications=[], + frame=16, + keyframe=False, + ), + VideoObjectAnnotation( + name="bbox toy", + feature_schema_id="ckz38ofop0mci0z9i9w3aa9o4", + extra={ + "value": "bbox_toy", + "instanceURI": None, + "color": "#1CE6FF", + "feature_id": "cl1z52xw700000fhcayaqy0ev", + }, + value=Rectangle( + extra={}, + start=Point(extra={}, x=70.0, y=59.667), + end=Point(extra={}, x=416.667, y=348.0), + ), + classifications=[], + frame=17, + keyframe=False, + ), + VideoObjectAnnotation( + name="bbox toy", + feature_schema_id="ckz38ofop0mci0z9i9w3aa9o4", + extra={ + "value": "bbox_toy", + "instanceURI": None, + "color": "#1CE6FF", + "feature_id": "cl1z52xw700000fhcayaqy0ev", + }, + value=Rectangle( + extra={}, + start=Point(extra={}, x=70.0, y=52.5), + end=Point(extra={}, x=446.0, y=348.0), + ), + classifications=[], + frame=18, + keyframe=False, + ), + VideoObjectAnnotation( + name="bbox toy", + feature_schema_id="ckz38ofop0mci0z9i9w3aa9o4", + extra={ + "value": "bbox_toy", + "instanceURI": None, + "color": "#1CE6FF", + "feature_id": "cl1z52xw700000fhcayaqy0ev", + }, + value=Rectangle( + extra={}, + start=Point(extra={}, x=70.0, y=45.333), + end=Point(extra={}, x=475.333, y=348.0), + ), + classifications=[], + frame=19, + keyframe=False, + ), + VideoObjectAnnotation( + name="bbox toy", + feature_schema_id="ckz38ofop0mci0z9i9w3aa9o4", + extra={ + "value": "bbox_toy", + "instanceURI": None, + "color": "#1CE6FF", + "feature_id": "cl1z52xw700000fhcayaqy0ev", + }, + value=Rectangle( + extra={}, + start=Point(extra={}, x=70.0, y=38.167), + end=Point(extra={}, x=504.667, y=348.0), + ), + classifications=[], + frame=20, + keyframe=False, + ), + VideoObjectAnnotation( + name="bbox toy", + feature_schema_id="ckz38ofop0mci0z9i9w3aa9o4", + extra={ + "value": "bbox_toy", + "instanceURI": None, + "color": "#1CE6FF", + "feature_id": "cl1z52xw700000fhcayaqy0ev", + }, + value=Rectangle( + extra={}, + start=Point(extra={}, x=70.0, y=31.0), + end=Point(extra={}, x=534.0, y=348.0), + ), + classifications=[], + frame=21, + keyframe=True, + ), + VideoObjectAnnotation( + name="bbox toy", + feature_schema_id="ckz38ofop0mci0z9i9w3aa9o4", + extra={ + "value": "bbox_toy", + "instanceURI": None, + "color": "#1CE6FF", + "feature_id": "cl1z52xw700000fhcayaqy0ev", + }, + value=Rectangle( + extra={}, + start=Point(extra={}, x=70.0, y=29.5), + end=Point(extra={}, x=543.0, y=348.0), + ), + classifications=[], + frame=22, + keyframe=False, + ), + VideoObjectAnnotation( + name="bbox toy", + feature_schema_id="ckz38ofop0mci0z9i9w3aa9o4", + extra={ + "value": "bbox_toy", + "instanceURI": None, + "color": "#1CE6FF", + "feature_id": "cl1z52xw700000fhcayaqy0ev", + }, + value=Rectangle( + extra={}, + start=Point(extra={}, x=70.0, y=28.0), + end=Point(extra={}, x=552.0, y=348.0), + ), + classifications=[], + frame=23, + keyframe=False, + ), + VideoObjectAnnotation( + name="bbox toy", + feature_schema_id="ckz38ofop0mci0z9i9w3aa9o4", + extra={ + "value": "bbox_toy", + "instanceURI": None, + "color": "#1CE6FF", + "feature_id": "cl1z52xw700000fhcayaqy0ev", + }, + value=Rectangle( + extra={}, + start=Point(extra={}, x=70.0, y=26.5), + end=Point(extra={}, x=561.0, y=348.0), + ), + classifications=[], + frame=24, + keyframe=False, + ), + VideoObjectAnnotation( + name="bbox toy", + feature_schema_id="ckz38ofop0mci0z9i9w3aa9o4", + extra={ + "value": "bbox_toy", + "instanceURI": None, + "color": "#1CE6FF", + "feature_id": "cl1z52xw700000fhcayaqy0ev", + }, + value=Rectangle( + extra={}, + start=Point(extra={}, x=70.0, y=25.0), + end=Point(extra={}, x=570.0, y=348.0), + ), + classifications=[], + frame=25, + keyframe=False, + ), + VideoObjectAnnotation( + name="bbox toy", + feature_schema_id="ckz38ofop0mci0z9i9w3aa9o4", + extra={ + "value": "bbox_toy", + "instanceURI": None, + "color": "#1CE6FF", + "feature_id": "cl1z52xw700000fhcayaqy0ev", + }, + value=Rectangle( + extra={}, + start=Point(extra={}, x=70.0, y=23.5), + end=Point(extra={}, x=579.0, y=348.0), + ), + classifications=[], + frame=26, + keyframe=False, + ), + VideoObjectAnnotation( + name="bbox toy", + feature_schema_id="ckz38ofop0mci0z9i9w3aa9o4", + extra={ + "value": "bbox_toy", + "instanceURI": None, + "color": "#1CE6FF", + "feature_id": "cl1z52xw700000fhcayaqy0ev", + }, + value=Rectangle( + extra={}, + start=Point(extra={}, x=70.0, y=22.0), + end=Point(extra={}, x=588.0, y=348.0), + ), + classifications=[], + frame=27, + keyframe=False, + ), + VideoObjectAnnotation( + name="bbox toy", + feature_schema_id="ckz38ofop0mci0z9i9w3aa9o4", + extra={ + "value": "bbox_toy", + "instanceURI": None, + "color": "#1CE6FF", + "feature_id": "cl1z52xw700000fhcayaqy0ev", + }, + value=Rectangle( + extra={}, + start=Point(extra={}, x=70.0, y=20.5), + end=Point(extra={}, x=597.0, y=348.0), + ), + classifications=[], + frame=28, + keyframe=False, + ), + VideoObjectAnnotation( + name="bbox toy", + feature_schema_id="ckz38ofop0mci0z9i9w3aa9o4", + extra={ + "value": "bbox_toy", + "instanceURI": None, + "color": "#1CE6FF", + "feature_id": "cl1z52xw700000fhcayaqy0ev", + }, + value=Rectangle( + extra={}, + start=Point(extra={}, x=70.0, y=19.0), + end=Point(extra={}, x=606.0, y=348.0), + ), + classifications=[], + frame=29, + keyframe=True, + ), + ], + extra={ + "Created By": "jtso@labelbox.com", + "Project Name": "Pictor Video", + "Created At": "2022-04-14T15:11:19.000Z", + "Updated At": "2022-04-14T15:11:21.064Z", + "Seconds to Label": 0.0, + "Agreement": -1.0, + "Benchmark Agreement": -1.0, + "Benchmark ID": None, + "Dataset Name": "cat", + "Reviews": [], + "View Label": "https://editor.labelbox.com?project=ckz38nsfd0lzq109bhq73est1&label=cl1z52xwh00050fhcmfgczqvn", + "Has Open Issues": 0.0, + "Skipped": False, + "media_type": "video", + "Data Split": None, + }, + ) - assert len(label['segments']) == 2 - assert len(label['segments'][0]['keyframes']) == 2 - assert len(label['segments'][1]['keyframes']) == 4 - # #converts back only the keyframes. should be the sum of all prev segments - deserialized_labels = NDJsonConverter.deserialize([label]) - label = next(deserialized_labels) - assert len(label.annotations) == 6 +def video_serialized_bbox_label(): + return { + "uuid": "b24e672b-8f79-4d96-bf5e-b552ca0820d5", + "dataRow": {"id": "cklr9mr4m5iao0rb6cvxu4qbn"}, + "schemaId": "ckz38ofop0mci0z9i9w3aa9o4", + "name": "bbox toy", + "classifications": [], + "segments": [ + { + "keyframes": [ + { + "frame": 1, + "bbox": { + "top": 46.0, + "left": 70.0, + "height": 249.0, + "width": 384.0, + }, + "classifications": [], + }, + { + "frame": 5, + "bbox": { + "top": 32.0, + "left": 70.0, + "height": 316.0, + "width": 277.0, + }, + "classifications": [], + }, + ] + }, + { + "keyframes": [ + { + "frame": 9, + "bbox": { + "top": 132.0, + "left": 70.0, + "height": 216.0, + "width": 213.0, + }, + "classifications": [], + }, + { + "frame": 15, + "bbox": { + "top": 74.0, + "left": 70.0, + "height": 274.0, + "width": 288.0, + }, + "classifications": [], + }, + { + "frame": 21, + "bbox": { + "top": 31.0, + "left": 70.0, + "height": 317.0, + "width": 464.0, + }, + "classifications": [], + }, + { + "frame": 29, + "bbox": { + "top": 19.0, + "left": 70.0, + "height": 329.0, + "width": 536.0, + }, + "classifications": [], + }, + ] + }, + ], + } -def test_confidence_is_ignored(): +def test_serialize_video_objects(): label = video_bbox_label() serialized_labels = NDJsonConverter.serialize([label]) label = next(serialized_labels) - label["confidence"] = 0.453 - label['segments'][0]["confidence"] = 0.453 - deserialized_labels = NDJsonConverter.deserialize([label]) - label = next(deserialized_labels) - for annotation in label.annotations: - assert annotation.confidence is None + assert label == video_serialized_bbox_label() diff --git a/libs/labelbox/tests/data/serialization/ndjson/test_free_text.py b/libs/labelbox/tests/data/serialization/ndjson/test_free_text.py index aaa84953a..349be13a8 100644 --- a/libs/labelbox/tests/data/serialization/ndjson/test_free_text.py +++ b/libs/labelbox/tests/data/serialization/ndjson/test_free_text.py @@ -1,5 +1,10 @@ from labelbox.data.annotation_types.annotation import ClassificationAnnotation -from labelbox.data.annotation_types.classification.classification import Checklist, ClassificationAnswer, Radio, Text +from labelbox.data.annotation_types.classification.classification import ( + Checklist, + ClassificationAnswer, + Radio, + Text, +) from labelbox.data.annotation_types.data.text import TextData from labelbox.data.annotation_types.label import Label @@ -7,34 +12,27 @@ def test_serialization(): - label = Label(uid="ckj7z2q0b0000jx6x0q2q7q0d", - data=TextData( - uid="bkj7z2q0b0000jx6x0q2q7q0d", - text="This is a test", - ), - annotations=[ - ClassificationAnnotation(name="free_text_annotation", - value=Text(confidence=0.5, - answer="text_answer")) - ]) + label = Label( + uid="ckj7z2q0b0000jx6x0q2q7q0d", + data=TextData( + uid="bkj7z2q0b0000jx6x0q2q7q0d", + text="This is a test", + ), + annotations=[ + ClassificationAnnotation( + name="free_text_annotation", + value=Text(confidence=0.5, answer="text_answer"), + ) + ], + ) serialized = NDJsonConverter.serialize([label]) res = next(serialized) - assert res['confidence'] == 0.5 - assert res['name'] == "free_text_annotation" - assert res['answer'] == "text_answer" - assert res['dataRow']['id'] == "bkj7z2q0b0000jx6x0q2q7q0d" - - deserialized = NDJsonConverter.deserialize([res]) - res = next(deserialized) - - annotation = res.annotations[0] - - annotation_value = annotation.value - assert type(annotation_value) is Text - assert annotation_value.answer == "text_answer" - assert annotation_value.confidence == 0.5 + assert res["confidence"] == 0.5 + assert res["name"] == "free_text_annotation" + assert res["answer"] == "text_answer" + assert res["dataRow"]["id"] == "bkj7z2q0b0000jx6x0q2q7q0d" def test_nested_serialization(): @@ -47,57 +45,50 @@ def test_nested_serialization(): annotations=[ ClassificationAnnotation( name="nested test", - value=Checklist(answer=[ - ClassificationAnswer( - name="first_answer", - confidence=0.9, - classifications=[ - ClassificationAnnotation( - name="sub_radio_question", - value=Radio(answer=ClassificationAnswer( - name="first_sub_radio_answer", - confidence=0.8, - classifications=[ - ClassificationAnnotation( - name="nested answer", - value=Text( - answer="nested answer", - confidence=0.7, - )) - ]))) - ]) - ]), + value=Checklist( + answer=[ + ClassificationAnswer( + name="first_answer", + confidence=0.9, + classifications=[ + ClassificationAnnotation( + name="sub_radio_question", + value=Radio( + answer=ClassificationAnswer( + name="first_sub_radio_answer", + confidence=0.8, + classifications=[ + ClassificationAnnotation( + name="nested answer", + value=Text( + answer="nested answer", + confidence=0.7, + ), + ) + ], + ) + ), + ) + ], + ) + ] + ), ) - ]) + ], + ) serialized = NDJsonConverter.serialize([label]) res = next(serialized) - assert res['dataRow']['id'] == "bkj7z2q0b0000jx6x0q2q7q0d" - answer = res['answer'][0] - assert answer['confidence'] == 0.9 - assert answer['name'] == "first_answer" - classification = answer['classifications'][0] - nested_classification_answer = classification['answer'] - assert nested_classification_answer['confidence'] == 0.8 - assert nested_classification_answer['name'] == "first_sub_radio_answer" - sub_classification = nested_classification_answer['classifications'][0] - assert sub_classification['name'] == "nested answer" - assert sub_classification['answer'] == "nested answer" - assert sub_classification['confidence'] == 0.7 - - deserialized = NDJsonConverter.deserialize([res]) - res = next(deserialized) - annotation = res.annotations[0] - answer = annotation.value.answer[0] - assert answer.confidence == 0.9 - assert answer.name == "first_answer" - - classification_answer = answer.classifications[0].value.answer - assert classification_answer.confidence == 0.8 - assert classification_answer.name == "first_sub_radio_answer" - - sub_classification_answer = classification_answer.classifications[0].value - assert type(sub_classification_answer) is Text - assert sub_classification_answer.answer == "nested answer" - assert sub_classification_answer.confidence == 0.7 + assert res["dataRow"]["id"] == "bkj7z2q0b0000jx6x0q2q7q0d" + answer = res["answer"][0] + assert answer["confidence"] == 0.9 + assert answer["name"] == "first_answer" + classification = answer["classifications"][0] + nested_classification_answer = classification["answer"] + assert nested_classification_answer["confidence"] == 0.8 + assert nested_classification_answer["name"] == "first_sub_radio_answer" + sub_classification = nested_classification_answer["classifications"][0] + assert sub_classification["name"] == "nested answer" + assert sub_classification["answer"] == "nested answer" + assert sub_classification["confidence"] == 0.7 diff --git a/libs/labelbox/tests/data/serialization/ndjson/test_global_key.py b/libs/labelbox/tests/data/serialization/ndjson/test_global_key.py index 6de2dcc51..7d6e9fdc3 100644 --- a/libs/labelbox/tests/data/serialization/ndjson/test_global_key.py +++ b/libs/labelbox/tests/data/serialization/ndjson/test_global_key.py @@ -1,68 +1,72 @@ -import json -import pytest - -from labelbox.data.serialization.ndjson.classification import NDRadio - from labelbox.data.serialization.ndjson.converter import NDJsonConverter -from labelbox.data.serialization.ndjson.objects import NDLine - - -def round_dict(data): - if isinstance(data, dict): - for key in data: - if isinstance(data[key], float): - data[key] = int(data[key]) - elif isinstance(data[key], dict): - data[key] = round_dict(data[key]) - elif isinstance(data[key], (list, tuple)): - data[key] = [round_dict(r) for r in data[key]] +from labelbox.types import ( + GenericDataRowData, + Label, + ClassificationAnnotation, + Radio, + ClassificationAnswer, +) - return data +def test_generic_data_row_global_key_included(): + expected = [ + { + "answer": {"schemaId": "ckrb1sfl8099g0y91cxbd5ftb"}, + "dataRow": {"globalKey": "ckrb1sf1i1g7i0ybcdc6oc8ct"}, + "schemaId": "ckrb1sfjx099a0y914hl319ie", + "uuid": "f6879f59-d2b5-49c2-aceb-d9e8dc478673", + } + ] -@pytest.mark.parametrize('filename', [ - 'tests/data/assets/ndjson/classification_import_global_key.json', - 'tests/data/assets/ndjson/metric_import_global_key.json', - 'tests/data/assets/ndjson/polyline_import_global_key.json', - 'tests/data/assets/ndjson/text_entity_import_global_key.json', - 'tests/data/assets/ndjson/conversation_entity_import_global_key.json', -]) -def test_many_types(filename: str): - with open(filename, 'r') as f: - data = json.load(f) - res = list(NDJsonConverter.deserialize(data)) - res = list(NDJsonConverter.serialize(res)) - assert res == data - f.close() + label = Label( + data=GenericDataRowData( + global_key="ckrb1sf1i1g7i0ybcdc6oc8ct", + ), + annotations=[ + ClassificationAnnotation( + feature_schema_id="ckrb1sfjx099a0y914hl319ie", + extra={"uuid": "f6879f59-d2b5-49c2-aceb-d9e8dc478673"}, + value=Radio( + answer=ClassificationAnswer( + feature_schema_id="ckrb1sfl8099g0y91cxbd5ftb", + ), + ), + ) + ], + ) + res = list(NDJsonConverter.serialize([label])) -def test_image(): - with open('tests/data/assets/ndjson/image_import_global_key.json', - 'r') as f: - data = json.load(f) - res = list(NDJsonConverter.deserialize(data)) - res = list(NDJsonConverter.serialize(res)) - for r in res: - r.pop('classifications', None) - assert [round_dict(x) for x in res] == [round_dict(x) for x in data] - f.close() + assert res == expected -def test_pdf(): - with open('tests/data/assets/ndjson/pdf_import_global_key.json', 'r') as f: - data = json.load(f) - res = list(NDJsonConverter.deserialize(data)) - res = list(NDJsonConverter.serialize(res)) - assert [round_dict(x) for x in res] == [round_dict(x) for x in data] - f.close() +def test_dict_data_row_global_key_included(): + expected = [ + { + "answer": {"schemaId": "ckrb1sfl8099g0y91cxbd5ftb"}, + "dataRow": {"globalKey": "ckrb1sf1i1g7i0ybcdc6oc8ct"}, + "schemaId": "ckrb1sfjx099a0y914hl319ie", + "uuid": "f6879f59-d2b5-49c2-aceb-d9e8dc478673", + } + ] + label = Label( + data={ + "global_key": "ckrb1sf1i1g7i0ybcdc6oc8ct", + }, + annotations=[ + ClassificationAnnotation( + feature_schema_id="ckrb1sfjx099a0y914hl319ie", + extra={"uuid": "f6879f59-d2b5-49c2-aceb-d9e8dc478673"}, + value=Radio( + answer=ClassificationAnswer( + feature_schema_id="ckrb1sfl8099g0y91cxbd5ftb", + ), + ), + ) + ], + ) -def test_video(): - with open('tests/data/assets/ndjson/video_import_global_key.json', - 'r') as f: - data = json.load(f) + res = list(NDJsonConverter.serialize([label])) - res = list(NDJsonConverter.deserialize(data)) - res = list(NDJsonConverter.serialize(res)) - assert res == [data[2], data[0], data[1], data[3], data[4], data[5]] - f.close() + assert res == expected From 5e168f700c94fbe22ecfda5da53dedb0ee41c083 Mon Sep 17 00:00:00 2001 From: Gabefire <33893811+Gabefire@users.noreply.github.com> Date: Wed, 11 Sep 2024 11:20:57 -0500 Subject: [PATCH 04/11] removed a few assets --- .../classification_import_global_key.json | 54 ------------------- ...conversation_entity_import_global_key.json | 25 --------- .../ndjson/metric_import_global_key.json | 10 ---- .../ndjson/polyline_import_global_key.json | 36 ------------- .../ndjson/text_entity_import_global_key.json | 26 --------- 5 files changed, 151 deletions(-) delete mode 100644 libs/labelbox/tests/data/assets/ndjson/classification_import_global_key.json delete mode 100644 libs/labelbox/tests/data/assets/ndjson/conversation_entity_import_global_key.json delete mode 100644 libs/labelbox/tests/data/assets/ndjson/metric_import_global_key.json delete mode 100644 libs/labelbox/tests/data/assets/ndjson/polyline_import_global_key.json delete mode 100644 libs/labelbox/tests/data/assets/ndjson/text_entity_import_global_key.json diff --git a/libs/labelbox/tests/data/assets/ndjson/classification_import_global_key.json b/libs/labelbox/tests/data/assets/ndjson/classification_import_global_key.json deleted file mode 100644 index 4de15e217..000000000 --- a/libs/labelbox/tests/data/assets/ndjson/classification_import_global_key.json +++ /dev/null @@ -1,54 +0,0 @@ -[ - { - "answer": { - "schemaId": "ckrb1sfl8099g0y91cxbd5ftb", - "confidence": 0.8, - "customMetrics": [ - { - "name": "customMetric1", - "value": 0.5 - }, - { - "name": "customMetric2", - "value": 0.3 - } - ] - }, - "schemaId": "ckrb1sfl8099g0y91cxbd5ftb", - "dataRow": { - "globalKey": "05e8ee85-072e-4eb2-b30a-501dee9b0d9d" - }, - "uuid": "f6879f59-d2b5-49c2-aceb-d9e8dc478673" - }, - { - "answer": [ - { - "schemaId": "ckrb1sfl8099e0y919v260awv", - "confidence": 0.82, - "customMetrics": [ - { - "name": "customMetric1", - "value": 0.5 - }, - { - "name": "customMetric2", - "value": 0.3 - } - ] - } - ], - "schemaId": "ckrb1sfkn099c0y910wbo0p1a", - "dataRow": { - "globalKey": "05e8ee85-072e-4eb2-b30a-501dee9b0d9d" - }, - "uuid": "d009925d-91a3-4f67-abd9-753453f5a584" - }, - { - "answer": "a value", - "schemaId": "ckrb1sfkn099c0y910wbo0p1a", - "dataRow": { - "globalKey": "05e8ee85-072e-4eb2-b30a-501dee9b0d9d" - }, - "uuid": "ee70fd88-9f88-48dd-b760-7469ff479b71" - } -] \ No newline at end of file diff --git a/libs/labelbox/tests/data/assets/ndjson/conversation_entity_import_global_key.json b/libs/labelbox/tests/data/assets/ndjson/conversation_entity_import_global_key.json deleted file mode 100644 index 83a95e5bf..000000000 --- a/libs/labelbox/tests/data/assets/ndjson/conversation_entity_import_global_key.json +++ /dev/null @@ -1,25 +0,0 @@ -[{ - "location": { - "start": 67, - "end": 128 - }, - "messageId": "some-message-id", - "uuid": "5ad9c52f-058d-49c8-a749-3f20b84f8cd4", - "dataRow": { - "globalKey": "05e8ee85-072e-4eb2-b30a-501dee9b0d9d" - }, - "name": "some-text-entity", - "schemaId": "cl6xnuwt95lqq07330tbb3mfd", - "classifications": [], - "confidence": 0.53, - "customMetrics": [ - { - "name": "customMetric1", - "value": 0.5 - }, - { - "name": "customMetric2", - "value": 0.3 - } - ] -}] diff --git a/libs/labelbox/tests/data/assets/ndjson/metric_import_global_key.json b/libs/labelbox/tests/data/assets/ndjson/metric_import_global_key.json deleted file mode 100644 index 31be5a4c7..000000000 --- a/libs/labelbox/tests/data/assets/ndjson/metric_import_global_key.json +++ /dev/null @@ -1,10 +0,0 @@ -[ - { - "uuid": "a22bbf6e-b2da-4abe-9a11-df84759f7672", - "aggregation": "ARITHMETIC_MEAN", - "dataRow": { - "globalKey": "05e8ee85-072e-4eb2-b30a-501dee9b0d9d" - }, - "metricValue": 0.1 - } -] \ No newline at end of file diff --git a/libs/labelbox/tests/data/assets/ndjson/polyline_import_global_key.json b/libs/labelbox/tests/data/assets/ndjson/polyline_import_global_key.json deleted file mode 100644 index d6a9eecbd..000000000 --- a/libs/labelbox/tests/data/assets/ndjson/polyline_import_global_key.json +++ /dev/null @@ -1,36 +0,0 @@ -[ - { - "line": [ - { - "x": 2534.353, - "y": 249.471 - }, - { - "x": 2429.492, - "y": 182.092 - }, - { - "x": 2294.322, - "y": 221.962 - } - ], - "uuid": "5ad9c52f-058d-49c8-a749-3f20b84f8cd4", - "dataRow": { - "globalKey": "05e8ee85-072e-4eb2-b30a-501dee9b0d9d" - }, - "name": "some-line", - "schemaId": "cl6xnuwt95lqq07330tbb3mfd", - "classifications": [], - "confidence": 0.58, - "customMetrics": [ - { - "name": "customMetric1", - "value": 0.5 - }, - { - "name": "customMetric2", - "value": 0.3 - } - ] - } -] \ No newline at end of file diff --git a/libs/labelbox/tests/data/assets/ndjson/text_entity_import_global_key.json b/libs/labelbox/tests/data/assets/ndjson/text_entity_import_global_key.json deleted file mode 100644 index 1f26d8dc8..000000000 --- a/libs/labelbox/tests/data/assets/ndjson/text_entity_import_global_key.json +++ /dev/null @@ -1,26 +0,0 @@ -[ - { - "location": { - "start": 67, - "end": 128 - }, - "uuid": "5ad9c52f-058d-49c8-a749-3f20b84f8cd4", - "dataRow": { - "globalKey": "05e8ee85-072e-4eb2-b30a-501dee9b0d9d" - }, - "name": "some-text-entity", - "schemaId": "cl6xnuwt95lqq07330tbb3mfd", - "classifications": [], - "confidence": 0.53, - "customMetrics": [ - { - "name": "customMetric1", - "value": 0.5 - }, - { - "name": "customMetric2", - "value": 0.3 - } - ] - } -] \ No newline at end of file From ff9877c6d18fec1b390ecc8eadad7a5788aec565 Mon Sep 17 00:00:00 2001 From: Gabefire <33893811+Gabefire@users.noreply.github.com> Date: Wed, 11 Sep 2024 12:45:23 -0500 Subject: [PATCH 05/11] finished more unit tests --- .../data/assets/ndjson/image_import.json | 779 +---------------- .../ndjson/image_import_global_key.json | 823 ------------------ .../assets/ndjson/image_import_name_only.json | 810 +---------------- .../assets/ndjson/pdf_import_global_key.json | 155 ---- .../ndjson/video_import_global_key.json | 166 ---- .../data/serialization/ndjson/test_image.py | 267 ++++-- .../data/serialization/ndjson/test_metric.py | 19 +- 7 files changed, 281 insertions(+), 2738 deletions(-) delete mode 100644 libs/labelbox/tests/data/assets/ndjson/image_import_global_key.json delete mode 100644 libs/labelbox/tests/data/assets/ndjson/pdf_import_global_key.json delete mode 100644 libs/labelbox/tests/data/assets/ndjson/video_import_global_key.json diff --git a/libs/labelbox/tests/data/assets/ndjson/image_import.json b/libs/labelbox/tests/data/assets/ndjson/image_import.json index 91563b8ae..75fe36e44 100644 --- a/libs/labelbox/tests/data/assets/ndjson/image_import.json +++ b/libs/labelbox/tests/data/assets/ndjson/image_import.json @@ -8,16 +8,17 @@ "confidence": 0.851, "customMetrics": [ { - "name": "customMetric1", - "value": 0.4 + "name": "customMetric1", + "value": 0.4 } ], "bbox": { - "top": 1352, - "left": 2275, - "height": 350, - "width": 139 - } + "top": 1352.0, + "left": 2275.0, + "height": 350.0, + "width": 139.0 + }, + "classifications": [] }, { "uuid": "751fc725-f7b6-48ed-89b0-dd7d94d08af6", @@ -28,20 +29,17 @@ "confidence": 0.834, "customMetrics": [ { - "name": "customMetric1", - "value": 0.3 + "name": "customMetric1", + "value": 0.3 } ], "mask": { - "instanceURI": "https://storage.labelbox.com/ckqcx1czn06830y61gh9v02cs%2F3e729327-f038-f66c-186e-45e921ef9717-1?Expires=1626806874672&KeyName=labelbox-assets-key-3&Signature=YsUOGKrsqmAZ68vT9BlPJOaRyLY", - "colorRGB": [ - 255, - 0, - 0 - ] - } + "instanceURI": "https://storage.labelbox.com/ckqcx1czn06830y61gh9v02cs%2F3e729327-f038-f66c-186e-45e921ef9717-1?Expires=1626806874672&KeyName=labelbox-assets-key-3&Signature=YsUOGKrsqmAZ68vT9BlPJOaRyLY" + }, + "classifications": [] }, { + "classifications": [], "uuid": "43d719ac-5d7f-4aea-be00-2ebfca0900fd", "schemaId": "ckrazcuec16oi0z66dzrd8pfl", "dataRow": { @@ -50,762 +48,39 @@ "confidence": 0.986, "customMetrics": [ { - "name": "customMetric1", - "value": 0.9 + "name": "customMetric1", + "value": 0.9 } ], "polygon": [ { - "x": 1118, - "y": 935 - }, - { - "x": 1117, - "y": 935 - }, - { - "x": 1116, - "y": 935 - }, - { - "x": 1115, - "y": 935 - }, - { - "x": 1114, - "y": 935 - }, - { - "x": 1113, - "y": 935 - }, - { - "x": 1112, - "y": 935 - }, - { - "x": 1111, - "y": 935 - }, - { - "x": 1110, - "y": 935 - }, - { - "x": 1109, - "y": 935 - }, - { - "x": 1108, - "y": 935 - }, - { - "x": 1108, - "y": 934 - }, - { - "x": 1107, - "y": 934 - }, - { - "x": 1106, - "y": 934 - }, - { - "x": 1105, - "y": 934 - }, - { - "x": 1105, - "y": 933 - }, - { - "x": 1104, - "y": 933 - }, - { - "x": 1103, - "y": 933 - }, - { - "x": 1103, - "y": 932 - }, - { - "x": 1102, - "y": 932 - }, - { - "x": 1101, - "y": 932 - }, - { - "x": 1100, - "y": 932 - }, - { - "x": 1099, - "y": 932 - }, - { - "x": 1098, - "y": 932 - }, - { - "x": 1097, - "y": 932 - }, - { - "x": 1097, - "y": 931 - }, - { - "x": 1096, - "y": 931 - }, - { - "x": 1095, - "y": 931 - }, - { - "x": 1094, - "y": 931 - }, - { - "x": 1093, - "y": 931 - }, - { - "x": 1092, - "y": 931 - }, - { - "x": 1091, - "y": 931 - }, - { - "x": 1090, - "y": 931 - }, - { - "x": 1090, - "y": 930 - }, - { - "x": 1089, - "y": 930 - }, - { - "x": 1088, - "y": 930 - }, - { - "x": 1087, - "y": 930 - }, - { - "x": 1087, - "y": 929 - }, - { - "x": 1086, - "y": 929 - }, - { - "x": 1085, - "y": 929 - }, - { - "x": 1084, - "y": 929 - }, - { - "x": 1084, - "y": 928 - }, - { - "x": 1083, - "y": 928 - }, - { - "x": 1083, - "y": 927 - }, - { - "x": 1082, - "y": 927 - }, - { - "x": 1081, - "y": 927 - }, - { - "x": 1081, - "y": 926 - }, - { - "x": 1080, - "y": 926 - }, - { - "x": 1080, - "y": 925 - }, - { - "x": 1079, - "y": 925 - }, - { - "x": 1078, - "y": 925 - }, - { - "x": 1078, - "y": 924 - }, - { - "x": 1077, - "y": 924 - }, - { - "x": 1076, - "y": 924 - }, - { - "x": 1076, - "y": 923 - }, - { - "x": 1075, - "y": 923 - }, - { - "x": 1074, - "y": 923 - }, - { - "x": 1073, - "y": 923 - }, - { - "x": 1073, - "y": 922 - }, - { - "x": 1072, - "y": 922 - }, - { - "x": 1071, - "y": 922 - }, - { - "x": 1070, - "y": 922 - }, - { - "x": 1070, - "y": 921 - }, - { - "x": 1069, - "y": 921 - }, - { - "x": 1068, - "y": 921 - }, - { - "x": 1067, - "y": 921 - }, - { - "x": 1066, - "y": 921 - }, - { - "x": 1065, - "y": 921 - }, - { - "x": 1064, - "y": 921 - }, - { - "x": 1063, - "y": 921 - }, - { - "x": 1062, - "y": 921 - }, - { - "x": 1061, - "y": 921 - }, - { - "x": 1060, - "y": 921 - }, - { - "x": 1059, - "y": 921 - }, - { - "x": 1058, - "y": 921 - }, - { - "x": 1058, - "y": 920 - }, - { - "x": 1057, - "y": 920 - }, - { - "x": 1057, - "y": 919 - }, - { - "x": 1056, - "y": 919 - }, - { - "x": 1057, - "y": 918 - }, - { - "x": 1057, - "y": 918 - }, - { - "x": 1057, - "y": 917 - }, - { - "x": 1058, - "y": 916 - }, - { - "x": 1058, - "y": 916 - }, - { - "x": 1059, - "y": 915 - }, - { - "x": 1059, - "y": 915 - }, - { - "x": 1060, - "y": 914 - }, - { - "x": 1060, - "y": 914 - }, - { - "x": 1061, - "y": 913 - }, - { - "x": 1061, - "y": 913 - }, - { - "x": 1062, - "y": 912 - }, - { - "x": 1063, - "y": 912 - }, - { - "x": 1063, - "y": 912 - }, - { - "x": 1064, - "y": 911 - }, - { - "x": 1064, - "y": 911 - }, - { - "x": 1065, - "y": 910 - }, - { - "x": 1066, - "y": 910 - }, - { - "x": 1066, - "y": 910 - }, - { - "x": 1067, - "y": 909 - }, - { - "x": 1068, - "y": 909 - }, - { - "x": 1068, - "y": 909 - }, - { - "x": 1069, - "y": 908 - }, - { - "x": 1070, - "y": 908 - }, - { - "x": 1071, - "y": 908 - }, - { - "x": 1072, - "y": 908 - }, - { - "x": 1072, - "y": 908 - }, - { - "x": 1073, - "y": 907 - }, - { - "x": 1074, - "y": 907 - }, - { - "x": 1075, - "y": 907 - }, - { - "x": 1076, - "y": 907 - }, - { - "x": 1077, - "y": 907 - }, - { - "x": 1078, - "y": 907 - }, - { - "x": 1079, - "y": 907 - }, - { - "x": 1080, - "y": 907 - }, - { - "x": 1081, - "y": 907 - }, - { - "x": 1082, - "y": 907 - }, - { - "x": 1083, - "y": 907 - }, - { - "x": 1084, - "y": 907 - }, - { - "x": 1085, - "y": 907 - }, - { - "x": 1086, - "y": 907 - }, - { - "x": 1087, - "y": 907 - }, - { - "x": 1088, - "y": 907 - }, - { - "x": 1089, - "y": 907 - }, - { - "x": 1090, - "y": 907 - }, - { - "x": 1091, - "y": 907 - }, - { - "x": 1091, - "y": 908 - }, - { - "x": 1092, - "y": 908 - }, - { - "x": 1093, - "y": 908 - }, - { - "x": 1094, - "y": 908 - }, - { - "x": 1095, - "y": 908 - }, - { - "x": 1095, - "y": 909 - }, - { - "x": 1096, - "y": 909 - }, - { - "x": 1097, - "y": 909 - }, - { - "x": 1097, - "y": 910 - }, - { - "x": 1098, - "y": 910 - }, - { - "x": 1099, - "y": 910 - }, - { - "x": 1099, - "y": 911 - }, - { - "x": 1100, - "y": 911 - }, - { - "x": 1101, - "y": 911 - }, - { - "x": 1101, - "y": 912 - }, - { - "x": 1102, - "y": 912 - }, - { - "x": 1103, - "y": 912 - }, - { - "x": 1103, - "y": 913 - }, - { - "x": 1104, - "y": 913 - }, - { - "x": 1104, - "y": 914 - }, - { - "x": 1105, - "y": 914 - }, - { - "x": 1105, - "y": 915 - }, - { - "x": 1106, - "y": 915 - }, - { - "x": 1107, - "y": 915 - }, - { - "x": 1107, - "y": 916 - }, - { - "x": 1108, - "y": 916 - }, - { - "x": 1108, - "y": 917 - }, - { - "x": 1109, - "y": 917 - }, - { - "x": 1109, - "y": 918 - }, - { - "x": 1110, - "y": 918 - }, - { - "x": 1110, - "y": 919 - }, - { - "x": 1111, - "y": 919 - }, - { - "x": 1111, - "y": 920 - }, - { - "x": 1112, - "y": 920 - }, - { - "x": 1112, - "y": 921 - }, - { - "x": 1113, - "y": 921 - }, - { - "x": 1113, - "y": 922 - }, - { - "x": 1114, - "y": 922 - }, - { - "x": 1114, - "y": 923 - }, - { - "x": 1115, - "y": 923 - }, - { - "x": 1115, - "y": 924 - }, - { - "x": 1115, - "y": 925 - }, - { - "x": 1116, - "y": 925 - }, - { - "x": 1116, - "y": 926 - }, - { - "x": 1117, - "y": 926 - }, - { - "x": 1117, - "y": 927 - }, - { - "x": 1117, - "y": 928 - }, - { - "x": 1118, - "y": 928 - }, - { - "x": 1118, - "y": 929 - }, - { - "x": 1119, - "y": 929 - }, - { - "x": 1119, - "y": 930 - }, - { - "x": 1120, - "y": 930 - }, - { - "x": 1120, - "y": 931 - }, - { - "x": 1120, - "y": 932 - }, - { - "x": 1120, - "y": 932 - }, - { - "x": 1119, - "y": 933 - }, - { - "x": 1119, - "y": 934 + "x": 10.0, + "y": 20.0 }, { - "x": 1119, - "y": 934 + "x": 15.0, + "y": 20.0 }, { - "x": 1118, - "y": 935 + "x": 20.0, + "y": 25.0 }, { - "x": 1118, - "y": 935 + "x": 10.0, + "y": 20.0 } ] }, { + "classifications": [], "uuid": "b98f3a45-3328-41a0-9077-373a8177ebf2", "schemaId": "ckrazcuec16om0z66bhhh4tp7", "dataRow": { "id": "ckrazctum0z8a0ybc0b0o0g0v" }, "point": { - "x": 2122, - "y": 1457 + "x": 2122.0, + "y": 1457.0 } } ] \ No newline at end of file diff --git a/libs/labelbox/tests/data/assets/ndjson/image_import_global_key.json b/libs/labelbox/tests/data/assets/ndjson/image_import_global_key.json deleted file mode 100644 index 591e40cf6..000000000 --- a/libs/labelbox/tests/data/assets/ndjson/image_import_global_key.json +++ /dev/null @@ -1,823 +0,0 @@ -[ - { - "uuid": "b862c586-8614-483c-b5e6-82810f70cac0", - "schemaId": "ckrazcueb16og0z6609jj7y3y", - "dataRow": { - "globalKey": "05e8ee85-072e-4eb2-b30a-501dee9b0d9d" - }, - "confidence": 0.851, - "bbox": { - "top": 1352, - "left": 2275, - "height": 350, - "width": 139 - }, - "customMetrics": [ - { - "name": "customMetric1", - "value": 0.5 - }, - { - "name": "customMetric2", - "value": 0.3 - } - ] - }, - { - "uuid": "751fc725-f7b6-48ed-89b0-dd7d94d08af6", - "schemaId": "ckrazcuec16ok0z66f956apb7", - "dataRow": { - "globalKey": "05e8ee85-072e-4eb2-b30a-501dee9b0d9d" - }, - "confidence": 0.834, - "customMetrics": [ - { - "name": "customMetric1", - "value": 0.5 - }, - { - "name": "customMetric2", - "value": 0.3 - } - ], - "mask": { - "instanceURI": "https://storage.labelbox.com/ckqcx1czn06830y61gh9v02cs%2F3e729327-f038-f66c-186e-45e921ef9717-1?Expires=1626806874672&KeyName=labelbox-assets-key-3&Signature=YsUOGKrsqmAZ68vT9BlPJOaRyLY", - "colorRGB": [ - 255, - 0, - 0 - ] - } - }, - { - "uuid": "43d719ac-5d7f-4aea-be00-2ebfca0900fd", - "schemaId": "ckrazcuec16oi0z66dzrd8pfl", - "dataRow": { - "globalKey": "05e8ee85-072e-4eb2-b30a-501dee9b0d9d" - }, - "confidence": 0.986, - "customMetrics": [ - { - "name": "customMetric1", - "value": 0.5 - }, - { - "name": "customMetric2", - "value": 0.3 - } - ], - "polygon": [ - { - "x": 1118, - "y": 935 - }, - { - "x": 1117, - "y": 935 - }, - { - "x": 1116, - "y": 935 - }, - { - "x": 1115, - "y": 935 - }, - { - "x": 1114, - "y": 935 - }, - { - "x": 1113, - "y": 935 - }, - { - "x": 1112, - "y": 935 - }, - { - "x": 1111, - "y": 935 - }, - { - "x": 1110, - "y": 935 - }, - { - "x": 1109, - "y": 935 - }, - { - "x": 1108, - "y": 935 - }, - { - "x": 1108, - "y": 934 - }, - { - "x": 1107, - "y": 934 - }, - { - "x": 1106, - "y": 934 - }, - { - "x": 1105, - "y": 934 - }, - { - "x": 1105, - "y": 933 - }, - { - "x": 1104, - "y": 933 - }, - { - "x": 1103, - "y": 933 - }, - { - "x": 1103, - "y": 932 - }, - { - "x": 1102, - "y": 932 - }, - { - "x": 1101, - "y": 932 - }, - { - "x": 1100, - "y": 932 - }, - { - "x": 1099, - "y": 932 - }, - { - "x": 1098, - "y": 932 - }, - { - "x": 1097, - "y": 932 - }, - { - "x": 1097, - "y": 931 - }, - { - "x": 1096, - "y": 931 - }, - { - "x": 1095, - "y": 931 - }, - { - "x": 1094, - "y": 931 - }, - { - "x": 1093, - "y": 931 - }, - { - "x": 1092, - "y": 931 - }, - { - "x": 1091, - "y": 931 - }, - { - "x": 1090, - "y": 931 - }, - { - "x": 1090, - "y": 930 - }, - { - "x": 1089, - "y": 930 - }, - { - "x": 1088, - "y": 930 - }, - { - "x": 1087, - "y": 930 - }, - { - "x": 1087, - "y": 929 - }, - { - "x": 1086, - "y": 929 - }, - { - "x": 1085, - "y": 929 - }, - { - "x": 1084, - "y": 929 - }, - { - "x": 1084, - "y": 928 - }, - { - "x": 1083, - "y": 928 - }, - { - "x": 1083, - "y": 927 - }, - { - "x": 1082, - "y": 927 - }, - { - "x": 1081, - "y": 927 - }, - { - "x": 1081, - "y": 926 - }, - { - "x": 1080, - "y": 926 - }, - { - "x": 1080, - "y": 925 - }, - { - "x": 1079, - "y": 925 - }, - { - "x": 1078, - "y": 925 - }, - { - "x": 1078, - "y": 924 - }, - { - "x": 1077, - "y": 924 - }, - { - "x": 1076, - "y": 924 - }, - { - "x": 1076, - "y": 923 - }, - { - "x": 1075, - "y": 923 - }, - { - "x": 1074, - "y": 923 - }, - { - "x": 1073, - "y": 923 - }, - { - "x": 1073, - "y": 922 - }, - { - "x": 1072, - "y": 922 - }, - { - "x": 1071, - "y": 922 - }, - { - "x": 1070, - "y": 922 - }, - { - "x": 1070, - "y": 921 - }, - { - "x": 1069, - "y": 921 - }, - { - "x": 1068, - "y": 921 - }, - { - "x": 1067, - "y": 921 - }, - { - "x": 1066, - "y": 921 - }, - { - "x": 1065, - "y": 921 - }, - { - "x": 1064, - "y": 921 - }, - { - "x": 1063, - "y": 921 - }, - { - "x": 1062, - "y": 921 - }, - { - "x": 1061, - "y": 921 - }, - { - "x": 1060, - "y": 921 - }, - { - "x": 1059, - "y": 921 - }, - { - "x": 1058, - "y": 921 - }, - { - "x": 1058, - "y": 920 - }, - { - "x": 1057, - "y": 920 - }, - { - "x": 1057, - "y": 919 - }, - { - "x": 1056, - "y": 919 - }, - { - "x": 1057, - "y": 918 - }, - { - "x": 1057, - "y": 918 - }, - { - "x": 1057, - "y": 917 - }, - { - "x": 1058, - "y": 916 - }, - { - "x": 1058, - "y": 916 - }, - { - "x": 1059, - "y": 915 - }, - { - "x": 1059, - "y": 915 - }, - { - "x": 1060, - "y": 914 - }, - { - "x": 1060, - "y": 914 - }, - { - "x": 1061, - "y": 913 - }, - { - "x": 1061, - "y": 913 - }, - { - "x": 1062, - "y": 912 - }, - { - "x": 1063, - "y": 912 - }, - { - "x": 1063, - "y": 912 - }, - { - "x": 1064, - "y": 911 - }, - { - "x": 1064, - "y": 911 - }, - { - "x": 1065, - "y": 910 - }, - { - "x": 1066, - "y": 910 - }, - { - "x": 1066, - "y": 910 - }, - { - "x": 1067, - "y": 909 - }, - { - "x": 1068, - "y": 909 - }, - { - "x": 1068, - "y": 909 - }, - { - "x": 1069, - "y": 908 - }, - { - "x": 1070, - "y": 908 - }, - { - "x": 1071, - "y": 908 - }, - { - "x": 1072, - "y": 908 - }, - { - "x": 1072, - "y": 908 - }, - { - "x": 1073, - "y": 907 - }, - { - "x": 1074, - "y": 907 - }, - { - "x": 1075, - "y": 907 - }, - { - "x": 1076, - "y": 907 - }, - { - "x": 1077, - "y": 907 - }, - { - "x": 1078, - "y": 907 - }, - { - "x": 1079, - "y": 907 - }, - { - "x": 1080, - "y": 907 - }, - { - "x": 1081, - "y": 907 - }, - { - "x": 1082, - "y": 907 - }, - { - "x": 1083, - "y": 907 - }, - { - "x": 1084, - "y": 907 - }, - { - "x": 1085, - "y": 907 - }, - { - "x": 1086, - "y": 907 - }, - { - "x": 1087, - "y": 907 - }, - { - "x": 1088, - "y": 907 - }, - { - "x": 1089, - "y": 907 - }, - { - "x": 1090, - "y": 907 - }, - { - "x": 1091, - "y": 907 - }, - { - "x": 1091, - "y": 908 - }, - { - "x": 1092, - "y": 908 - }, - { - "x": 1093, - "y": 908 - }, - { - "x": 1094, - "y": 908 - }, - { - "x": 1095, - "y": 908 - }, - { - "x": 1095, - "y": 909 - }, - { - "x": 1096, - "y": 909 - }, - { - "x": 1097, - "y": 909 - }, - { - "x": 1097, - "y": 910 - }, - { - "x": 1098, - "y": 910 - }, - { - "x": 1099, - "y": 910 - }, - { - "x": 1099, - "y": 911 - }, - { - "x": 1100, - "y": 911 - }, - { - "x": 1101, - "y": 911 - }, - { - "x": 1101, - "y": 912 - }, - { - "x": 1102, - "y": 912 - }, - { - "x": 1103, - "y": 912 - }, - { - "x": 1103, - "y": 913 - }, - { - "x": 1104, - "y": 913 - }, - { - "x": 1104, - "y": 914 - }, - { - "x": 1105, - "y": 914 - }, - { - "x": 1105, - "y": 915 - }, - { - "x": 1106, - "y": 915 - }, - { - "x": 1107, - "y": 915 - }, - { - "x": 1107, - "y": 916 - }, - { - "x": 1108, - "y": 916 - }, - { - "x": 1108, - "y": 917 - }, - { - "x": 1109, - "y": 917 - }, - { - "x": 1109, - "y": 918 - }, - { - "x": 1110, - "y": 918 - }, - { - "x": 1110, - "y": 919 - }, - { - "x": 1111, - "y": 919 - }, - { - "x": 1111, - "y": 920 - }, - { - "x": 1112, - "y": 920 - }, - { - "x": 1112, - "y": 921 - }, - { - "x": 1113, - "y": 921 - }, - { - "x": 1113, - "y": 922 - }, - { - "x": 1114, - "y": 922 - }, - { - "x": 1114, - "y": 923 - }, - { - "x": 1115, - "y": 923 - }, - { - "x": 1115, - "y": 924 - }, - { - "x": 1115, - "y": 925 - }, - { - "x": 1116, - "y": 925 - }, - { - "x": 1116, - "y": 926 - }, - { - "x": 1117, - "y": 926 - }, - { - "x": 1117, - "y": 927 - }, - { - "x": 1117, - "y": 928 - }, - { - "x": 1118, - "y": 928 - }, - { - "x": 1118, - "y": 929 - }, - { - "x": 1119, - "y": 929 - }, - { - "x": 1119, - "y": 930 - }, - { - "x": 1120, - "y": 930 - }, - { - "x": 1120, - "y": 931 - }, - { - "x": 1120, - "y": 932 - }, - { - "x": 1120, - "y": 932 - }, - { - "x": 1119, - "y": 933 - }, - { - "x": 1119, - "y": 934 - }, - { - "x": 1119, - "y": 934 - }, - { - "x": 1118, - "y": 935 - }, - { - "x": 1118, - "y": 935 - } - ] - }, - { - "uuid": "b98f3a45-3328-41a0-9077-373a8177ebf2", - "schemaId": "ckrazcuec16om0z66bhhh4tp7", - "dataRow": { - "globalKey": "05e8ee85-072e-4eb2-b30a-501dee9b0d9d" - }, - "point": { - "x": 2122, - "y": 1457 - } - } -] \ No newline at end of file diff --git a/libs/labelbox/tests/data/assets/ndjson/image_import_name_only.json b/libs/labelbox/tests/data/assets/ndjson/image_import_name_only.json index 82be4cdab..466a03594 100644 --- a/libs/labelbox/tests/data/assets/ndjson/image_import_name_only.json +++ b/libs/labelbox/tests/data/assets/ndjson/image_import_name_only.json @@ -1,826 +1,86 @@ [ { "uuid": "b862c586-8614-483c-b5e6-82810f70cac0", - "name": "box a", + "name": "ckrazcueb16og0z6609jj7y3y", "dataRow": { "id": "ckrazctum0z8a0ybc0b0o0g0v" }, - "bbox": { - "top": 1352, - "left": 2275, - "height": 350, - "width": 139 - }, - "confidence": 0.854, + "classifications": [], + "confidence": 0.851, "customMetrics": [ { "name": "customMetric1", - "value": 0.5 - }, - { - "name": "customMetric2", - "value": 0.7 + "value": 0.4 } - ] + ], + "bbox": { + "top": 1352.0, + "left": 2275.0, + "height": 350.0, + "width": 139.0 + } }, { "uuid": "751fc725-f7b6-48ed-89b0-dd7d94d08af6", - "name": "mask a", + "name": "ckrazcuec16ok0z66f956apb7", "dataRow": { "id": "ckrazctum0z8a0ybc0b0o0g0v" }, - "mask": { - "instanceURI": "https://storage.labelbox.com/ckqcx1czn06830y61gh9v02cs%2F3e729327-f038-f66c-186e-45e921ef9717-1?Expires=1626806874672&KeyName=labelbox-assets-key-3&Signature=YsUOGKrsqmAZ68vT9BlPJOaRyLY", - "colorRGB": [ - 255, - 0, - 0 - ] - }, - "confidence": 0.685, + "classifications": [], + "confidence": 0.834, "customMetrics": [ { "name": "customMetric1", - "value": 0.4 - }, - { - "name": "customMetric2", - "value": 0.9 + "value": 0.3 } - ] + ], + "mask": { + "instanceURI": "https://storage.labelbox.com/ckqcx1czn06830y61gh9v02cs%2F3e729327-f038-f66c-186e-45e921ef9717-1?Expires=1626806874672&KeyName=labelbox-assets-key-3&Signature=YsUOGKrsqmAZ68vT9BlPJOaRyLY" + } }, { + "classifications": [], "uuid": "43d719ac-5d7f-4aea-be00-2ebfca0900fd", - "name": "polygon a", + "name": "ckrazcuec16oi0z66dzrd8pfl", "dataRow": { "id": "ckrazctum0z8a0ybc0b0o0g0v" }, - "confidence": 0.71, + "confidence": 0.986, "customMetrics": [ { "name": "customMetric1", - "value": 0.1 + "value": 0.9 } ], "polygon": [ { - "x": 1118, - "y": 935 - }, - { - "x": 1117, - "y": 935 - }, - { - "x": 1116, - "y": 935 - }, - { - "x": 1115, - "y": 935 - }, - { - "x": 1114, - "y": 935 - }, - { - "x": 1113, - "y": 935 - }, - { - "x": 1112, - "y": 935 - }, - { - "x": 1111, - "y": 935 - }, - { - "x": 1110, - "y": 935 - }, - { - "x": 1109, - "y": 935 - }, - { - "x": 1108, - "y": 935 - }, - { - "x": 1108, - "y": 934 - }, - { - "x": 1107, - "y": 934 - }, - { - "x": 1106, - "y": 934 - }, - { - "x": 1105, - "y": 934 - }, - { - "x": 1105, - "y": 933 - }, - { - "x": 1104, - "y": 933 - }, - { - "x": 1103, - "y": 933 - }, - { - "x": 1103, - "y": 932 - }, - { - "x": 1102, - "y": 932 - }, - { - "x": 1101, - "y": 932 - }, - { - "x": 1100, - "y": 932 - }, - { - "x": 1099, - "y": 932 - }, - { - "x": 1098, - "y": 932 - }, - { - "x": 1097, - "y": 932 - }, - { - "x": 1097, - "y": 931 - }, - { - "x": 1096, - "y": 931 - }, - { - "x": 1095, - "y": 931 - }, - { - "x": 1094, - "y": 931 - }, - { - "x": 1093, - "y": 931 - }, - { - "x": 1092, - "y": 931 - }, - { - "x": 1091, - "y": 931 - }, - { - "x": 1090, - "y": 931 - }, - { - "x": 1090, - "y": 930 - }, - { - "x": 1089, - "y": 930 - }, - { - "x": 1088, - "y": 930 - }, - { - "x": 1087, - "y": 930 - }, - { - "x": 1087, - "y": 929 - }, - { - "x": 1086, - "y": 929 - }, - { - "x": 1085, - "y": 929 - }, - { - "x": 1084, - "y": 929 - }, - { - "x": 1084, - "y": 928 - }, - { - "x": 1083, - "y": 928 - }, - { - "x": 1083, - "y": 927 - }, - { - "x": 1082, - "y": 927 - }, - { - "x": 1081, - "y": 927 - }, - { - "x": 1081, - "y": 926 - }, - { - "x": 1080, - "y": 926 - }, - { - "x": 1080, - "y": 925 - }, - { - "x": 1079, - "y": 925 - }, - { - "x": 1078, - "y": 925 - }, - { - "x": 1078, - "y": 924 - }, - { - "x": 1077, - "y": 924 - }, - { - "x": 1076, - "y": 924 - }, - { - "x": 1076, - "y": 923 - }, - { - "x": 1075, - "y": 923 - }, - { - "x": 1074, - "y": 923 - }, - { - "x": 1073, - "y": 923 - }, - { - "x": 1073, - "y": 922 - }, - { - "x": 1072, - "y": 922 - }, - { - "x": 1071, - "y": 922 - }, - { - "x": 1070, - "y": 922 - }, - { - "x": 1070, - "y": 921 - }, - { - "x": 1069, - "y": 921 - }, - { - "x": 1068, - "y": 921 - }, - { - "x": 1067, - "y": 921 - }, - { - "x": 1066, - "y": 921 - }, - { - "x": 1065, - "y": 921 - }, - { - "x": 1064, - "y": 921 - }, - { - "x": 1063, - "y": 921 - }, - { - "x": 1062, - "y": 921 - }, - { - "x": 1061, - "y": 921 - }, - { - "x": 1060, - "y": 921 - }, - { - "x": 1059, - "y": 921 - }, - { - "x": 1058, - "y": 921 - }, - { - "x": 1058, - "y": 920 - }, - { - "x": 1057, - "y": 920 - }, - { - "x": 1057, - "y": 919 - }, - { - "x": 1056, - "y": 919 - }, - { - "x": 1057, - "y": 918 - }, - { - "x": 1057, - "y": 918 - }, - { - "x": 1057, - "y": 917 - }, - { - "x": 1058, - "y": 916 - }, - { - "x": 1058, - "y": 916 - }, - { - "x": 1059, - "y": 915 - }, - { - "x": 1059, - "y": 915 - }, - { - "x": 1060, - "y": 914 - }, - { - "x": 1060, - "y": 914 - }, - { - "x": 1061, - "y": 913 - }, - { - "x": 1061, - "y": 913 - }, - { - "x": 1062, - "y": 912 - }, - { - "x": 1063, - "y": 912 - }, - { - "x": 1063, - "y": 912 - }, - { - "x": 1064, - "y": 911 - }, - { - "x": 1064, - "y": 911 - }, - { - "x": 1065, - "y": 910 - }, - { - "x": 1066, - "y": 910 - }, - { - "x": 1066, - "y": 910 - }, - { - "x": 1067, - "y": 909 - }, - { - "x": 1068, - "y": 909 - }, - { - "x": 1068, - "y": 909 - }, - { - "x": 1069, - "y": 908 - }, - { - "x": 1070, - "y": 908 - }, - { - "x": 1071, - "y": 908 - }, - { - "x": 1072, - "y": 908 - }, - { - "x": 1072, - "y": 908 - }, - { - "x": 1073, - "y": 907 - }, - { - "x": 1074, - "y": 907 - }, - { - "x": 1075, - "y": 907 - }, - { - "x": 1076, - "y": 907 - }, - { - "x": 1077, - "y": 907 - }, - { - "x": 1078, - "y": 907 - }, - { - "x": 1079, - "y": 907 - }, - { - "x": 1080, - "y": 907 - }, - { - "x": 1081, - "y": 907 - }, - { - "x": 1082, - "y": 907 - }, - { - "x": 1083, - "y": 907 - }, - { - "x": 1084, - "y": 907 - }, - { - "x": 1085, - "y": 907 - }, - { - "x": 1086, - "y": 907 - }, - { - "x": 1087, - "y": 907 - }, - { - "x": 1088, - "y": 907 - }, - { - "x": 1089, - "y": 907 - }, - { - "x": 1090, - "y": 907 - }, - { - "x": 1091, - "y": 907 - }, - { - "x": 1091, - "y": 908 - }, - { - "x": 1092, - "y": 908 - }, - { - "x": 1093, - "y": 908 - }, - { - "x": 1094, - "y": 908 - }, - { - "x": 1095, - "y": 908 - }, - { - "x": 1095, - "y": 909 - }, - { - "x": 1096, - "y": 909 - }, - { - "x": 1097, - "y": 909 - }, - { - "x": 1097, - "y": 910 - }, - { - "x": 1098, - "y": 910 - }, - { - "x": 1099, - "y": 910 + "x": 10.0, + "y": 20.0 }, { - "x": 1099, - "y": 911 + "x": 15.0, + "y": 20.0 }, { - "x": 1100, - "y": 911 + "x": 20.0, + "y": 25.0 }, { - "x": 1101, - "y": 911 - }, - { - "x": 1101, - "y": 912 - }, - { - "x": 1102, - "y": 912 - }, - { - "x": 1103, - "y": 912 - }, - { - "x": 1103, - "y": 913 - }, - { - "x": 1104, - "y": 913 - }, - { - "x": 1104, - "y": 914 - }, - { - "x": 1105, - "y": 914 - }, - { - "x": 1105, - "y": 915 - }, - { - "x": 1106, - "y": 915 - }, - { - "x": 1107, - "y": 915 - }, - { - "x": 1107, - "y": 916 - }, - { - "x": 1108, - "y": 916 - }, - { - "x": 1108, - "y": 917 - }, - { - "x": 1109, - "y": 917 - }, - { - "x": 1109, - "y": 918 - }, - { - "x": 1110, - "y": 918 - }, - { - "x": 1110, - "y": 919 - }, - { - "x": 1111, - "y": 919 - }, - { - "x": 1111, - "y": 920 - }, - { - "x": 1112, - "y": 920 - }, - { - "x": 1112, - "y": 921 - }, - { - "x": 1113, - "y": 921 - }, - { - "x": 1113, - "y": 922 - }, - { - "x": 1114, - "y": 922 - }, - { - "x": 1114, - "y": 923 - }, - { - "x": 1115, - "y": 923 - }, - { - "x": 1115, - "y": 924 - }, - { - "x": 1115, - "y": 925 - }, - { - "x": 1116, - "y": 925 - }, - { - "x": 1116, - "y": 926 - }, - { - "x": 1117, - "y": 926 - }, - { - "x": 1117, - "y": 927 - }, - { - "x": 1117, - "y": 928 - }, - { - "x": 1118, - "y": 928 - }, - { - "x": 1118, - "y": 929 - }, - { - "x": 1119, - "y": 929 - }, - { - "x": 1119, - "y": 930 - }, - { - "x": 1120, - "y": 930 - }, - { - "x": 1120, - "y": 931 - }, - { - "x": 1120, - "y": 932 - }, - { - "x": 1120, - "y": 932 - }, - { - "x": 1119, - "y": 933 - }, - { - "x": 1119, - "y": 934 - }, - { - "x": 1119, - "y": 934 - }, - { - "x": 1118, - "y": 935 - }, - { - "x": 1118, - "y": 935 + "x": 10.0, + "y": 20.0 } ] }, { + "classifications": [], "uuid": "b98f3a45-3328-41a0-9077-373a8177ebf2", - "name": "point a", + "name": "ckrazcuec16om0z66bhhh4tp7", "dataRow": { "id": "ckrazctum0z8a0ybc0b0o0g0v" }, - "confidence": 0.77, - "customMetrics": [ - { - "name": "customMetric2", - "value": 1.2 - } - ], "point": { - "x": 2122, - "y": 1457 + "x": 2122.0, + "y": 1457.0 } } ] \ No newline at end of file diff --git a/libs/labelbox/tests/data/assets/ndjson/pdf_import_global_key.json b/libs/labelbox/tests/data/assets/ndjson/pdf_import_global_key.json deleted file mode 100644 index f4b4894f6..000000000 --- a/libs/labelbox/tests/data/assets/ndjson/pdf_import_global_key.json +++ /dev/null @@ -1,155 +0,0 @@ -[{ - "uuid": "5ad9c52f-058d-49c8-a749-3f20b84f8cd4", - "dataRow": { - "globalKey": "05e8ee85-072e-4eb2-b30a-501dee9b0d9d" - }, - "name": "boxy", - "schemaId": "cl6xnuwt95lqq07330tbb3mfd", - "classifications": [], - "page": 4, - "unit": "POINTS", - "confidence": 0.53, - "customMetrics": [ - { - "name": "customMetric1", - "value": 0.5 - }, - { - "name": "customMetric2", - "value": 0.3 - } - ], - "bbox": { - "top": 162.73, - "left": 32.45, - "height": 388.16999999999996, - "width": 101.66000000000001 - } -}, { - "uuid": "20eeef88-0294-49b4-a815-86588476bc6f", - "dataRow": { - "globalKey": "05e8ee85-072e-4eb2-b30a-501dee9b0d9d" - }, - "name": "boxy", - "schemaId": "cl6xnuwt95lqq07330tbb3mfd", - "classifications": [], - "page": 7, - "unit": "POINTS", - "bbox": { - "top": 223.26, - "left": 251.42, - "height": 457.03999999999996, - "width": 186.78 - } -}, { - "uuid": "641a8944-3938-409c-b4eb-dea354ed06e5", - "dataRow": { - "globalKey": "05e8ee85-072e-4eb2-b30a-501dee9b0d9d" - }, - "name": "boxy", - "schemaId": "cl6xnuwt95lqq07330tbb3mfd", - "classifications": [], - "page": 6, - "unit": "POINTS", - "confidence": 0.99, - "customMetrics": [ - { - "name": "customMetric1", - "value": 0.5 - }, - { - "name": "customMetric2", - "value": 0.3 - } - ], - "bbox": { - "top": 32.52, - "left": 218.17, - "height": 231.73, - "width": 110.56000000000003 - } -}, { - "uuid": "ebe4da7d-08b3-480a-8d15-26552b7f011c", - "dataRow": { - "globalKey": "05e8ee85-072e-4eb2-b30a-501dee9b0d9d" - }, - "name": "boxy", - "schemaId": "cl6xnuwt95lqq07330tbb3mfd", - "classifications": [], - "page": 7, - "unit": "POINTS", - "confidence": 0.89, - "customMetrics": [ - { - "name": "customMetric1", - "value": 0.5 - }, - { - "name": "customMetric2", - "value": 0.3 - } - ], - "bbox": { - "top": 117.39, - "left": 4.25, - "height": 456.9200000000001, - "width": 164.83 - } -}, { - "uuid": "35c41855-575f-42cc-a2f9-1f06237e9b63", - "dataRow": { - "globalKey": "05e8ee85-072e-4eb2-b30a-501dee9b0d9d" - }, - "name": "boxy", - "schemaId": "cl6xnuwt95lqq07330tbb3mfd", - "classifications": [], - "page": 8, - "unit": "POINTS", - "bbox": { - "top": 82.13, - "left": 217.28, - "height": 279.76, - "width": 82.43000000000004 - } -}, { - "uuid": "1b009654-bc17-42a2-8a71-160e7808c403", - "dataRow": { - "globalKey": "05e8ee85-072e-4eb2-b30a-501dee9b0d9d" - }, - "name": "boxy", - "schemaId": "cl6xnuwt95lqq07330tbb3mfd", - "classifications": [], - "page": 3, - "unit": "POINTS", - "bbox": { - "top": 298.12, - "left": 83.34, - "height": 203.83000000000004, - "width": 0.37999999999999545 - } -}, -{ - "uuid": "f6879f59-d2b5-49c2-aceb-d9e8dc478673", - "dataRow": { - "globalKey": "05e8ee85-072e-4eb2-b30a-501dee9b0d9d" - }, - "name": "named_entity", - "classifications": [], - "textSelections": [ - { - "groupId": "2f4336f4-a07e-4e0a-a9e1-5629b03b719b", - "tokenIds": [ - "3f984bf3-1d61-44f5-b59a-9658a2e3440f", - "3bf00b56-ff12-4e52-8cc1-08dbddb3c3b8", - "6e1c3420-d4b7-4c5a-8fd6-ead43bf73d80", - "87a43d32-af76-4a1d-b262-5c5f4d5ace3a", - "e8606e8a-dfd9-4c49-a635-ad5c879c75d0", - "67c7c19e-4654-425d-bf17-2adb8cf02c30", - "149c5e80-3e07-49a7-ab2d-29ddfe6a38fa", - "b0e94071-2187-461e-8e76-96c58738a52c" - ], - "page": 1 - } - ] -} -] \ No newline at end of file diff --git a/libs/labelbox/tests/data/assets/ndjson/video_import_global_key.json b/libs/labelbox/tests/data/assets/ndjson/video_import_global_key.json deleted file mode 100644 index 11e0753d9..000000000 --- a/libs/labelbox/tests/data/assets/ndjson/video_import_global_key.json +++ /dev/null @@ -1,166 +0,0 @@ -[{ - "answer": { - "schemaId": "ckrb1sfl8099g0y91cxbd5ftb" - }, - "schemaId": "ckrb1sfjx099a0y914hl319ie", - "dataRow": { - "globalKey": "05e8ee85-072e-4eb2-b30a-501dee9b0d9d" - }, - "uuid": "f6879f59-d2b5-49c2-aceb-d9e8dc478673", - "frames": [{ - "start": 30, - "end": 35 - }, { - "start": 50, - "end": 51 - }] -}, { - "answer": [{ - "schemaId": "ckrb1sfl8099e0y919v260awv" - }], - "schemaId": "ckrb1sfkn099c0y910wbo0p1a", - "dataRow": { - "globalKey": "05e8ee85-072e-4eb2-b30a-501dee9b0d9d" - }, - "uuid": "d009925d-91a3-4f67-abd9-753453f5a584", - "frames": [{ - "start": 0, - "end": 5 - }] -}, { - "answer": "a value", - "schemaId": "ckrb1sfkn099c0y910wbo0p1a", - "dataRow": { - "globalKey": "05e8ee85-072e-4eb2-b30a-501dee9b0d9d" - }, - "uuid": "3b302706-37ec-4f72-ab2e-757d8bd302b9" -}, { - "classifications": [], - "schemaId": - "cl5islwg200gfci6g0oitaypu", - "dataRow": { - "globalKey": "05e8ee85-072e-4eb2-b30a-501dee9b0d9d" - }, - "uuid": - "6f7c835a-0139-4896-b73f-66a6baa89e94", - "segments": [{ - "keyframes": [{ - "frame": 1, - "line": [{ - "x": 10.0, - "y": 10.0 - }, { - "x": 100.0, - "y": 100.0 - }, { - "x": 50.0, - "y": 30.0 - }], - "classifications": [] - }, { - "frame": 5, - "line": [{ - "x": 15.0, - "y": 10.0 - }, { - "x": 50.0, - "y": 100.0 - }, { - "x": 50.0, - "y": 30.0 - }], - "classifications": [] - }] - }, { - "keyframes": [{ - "frame": 8, - "line": [{ - "x": 100.0, - "y": 10.0 - }, { - "x": 50.0, - "y": 100.0 - }, { - "x": 50.0, - "y": 30.0 - }], - "classifications": [] - }] - }] -}, { - "classifications": [], - "schemaId": - "cl5it7ktp00i5ci6gf80b1ysd", - "dataRow": { - "globalKey": "05e8ee85-072e-4eb2-b30a-501dee9b0d9d" - }, - "uuid": - "f963be22-227b-4efe-9be4-2738ed822216", - "segments": [{ - "keyframes": [{ - "frame": 1, - "point": { - "x": 10.0, - "y": 10.0 - }, - "classifications": [] - }] - }, { - "keyframes": [{ - "frame": 5, - "point": { - "x": 50.0, - "y": 50.0 - }, - "classifications": [] - }, { - "frame": 10, - "point": { - "x": 10.0, - "y": 50.0 - }, - "classifications": [] - }] - }] -}, { - "classifications": [], - "schemaId": - "cl5iw0roz00lwci6g5jni62vs", - "dataRow": { - "globalKey": "05e8ee85-072e-4eb2-b30a-501dee9b0d9d" - }, - "uuid": - "13b2ee0e-2355-4336-8b83-d74d09e3b1e7", - "segments": [{ - "keyframes": [{ - "frame": 1, - "bbox": { - "top": 10.0, - "left": 5.0, - "height": 100.0, - "width": 150.0 - }, - "classifications": [] - }, { - "frame": 5, - "bbox": { - "top": 30.0, - "left": 5.0, - "height": 50.0, - "width": 150.0 - }, - "classifications": [] - }] - }, { - "keyframes": [{ - "frame": 10, - "bbox": { - "top": 300.0, - "left": 200.0, - "height": 400.0, - "width": 150.0 - }, - "classifications": [] - }] - }] -}] diff --git a/libs/labelbox/tests/data/serialization/ndjson/test_image.py b/libs/labelbox/tests/data/serialization/ndjson/test_image.py index e36ce6f50..baf5d3d92 100644 --- a/libs/labelbox/tests/data/serialization/ndjson/test_image.py +++ b/libs/labelbox/tests/data/serialization/ndjson/test_image.py @@ -1,9 +1,17 @@ import json +from labelbox.data.mixins import CustomMetric import numpy as np import cv2 from labelbox.data.serialization.ndjson.converter import NDJsonConverter -from labelbox.data.annotation_types import Mask, Label, ObjectAnnotation, ImageData, MaskData +from labelbox.data.annotation_types import ( + Mask, + Label, + ObjectAnnotation, + ImageData, + MaskData, +) +from labelbox.types import GenericDataRowData, Rectangle, Polygon, Point def round_dict(data): @@ -20,85 +28,228 @@ def round_dict(data): def test_image(): - with open('tests/data/assets/ndjson/image_import.json', 'r') as file: + with open("tests/data/assets/ndjson/image_import.json", "r") as file: data = json.load(file) - res = list(NDJsonConverter.deserialize(data)) - res = list(NDJsonConverter.serialize(res)) - - for r in res: - r.pop('classifications', None) - assert [round_dict(x) for x in res] == [round_dict(x) for x in data] + labels = [ + Label( + data=GenericDataRowData( + uid="ckrazctum0z8a0ybc0b0o0g0v", + ), + annotations=[ + ObjectAnnotation( + custom_metrics=[CustomMetric(name="customMetric1", value=0.4)], + confidence=0.851, + feature_schema_id="ckrazcueb16og0z6609jj7y3y", + extra={ + "uuid": "b862c586-8614-483c-b5e6-82810f70cac0", + }, + value=Rectangle( + start=Point(extra={}, x=2275.0, y=1352.0), + end=Point(extra={}, x=2414.0, y=1702.0), + ), + ), + ObjectAnnotation( + custom_metrics=[CustomMetric(name="customMetric1", value=0.3)], + confidence=0.834, + feature_schema_id="ckrazcuec16ok0z66f956apb7", + extra={ + "uuid": "751fc725-f7b6-48ed-89b0-dd7d94d08af6", + }, + value=Mask( + mask=MaskData( + url="https://storage.labelbox.com/ckqcx1czn06830y61gh9v02cs%2F3e729327-f038-f66c-186e-45e921ef9717-1?Expires=1626806874672&KeyName=labelbox-assets-key-3&Signature=YsUOGKrsqmAZ68vT9BlPJOaRyLY", + ), + color=[255, 0, 0], + ), + ), + ObjectAnnotation( + custom_metrics=[CustomMetric(name="customMetric1", value=0.9)], + confidence=0.986, + feature_schema_id="ckrazcuec16oi0z66dzrd8pfl", + extra={ + "uuid": "43d719ac-5d7f-4aea-be00-2ebfca0900fd", + }, + value=Polygon( + points=[ + Point(x=10.0, y=20.0), + Point(x=15.0, y=20.0), + Point(x=20.0, y=25.0), + Point(x=10.0, y=20.0), + ], + ), + ), + ObjectAnnotation( + feature_schema_id="ckrazcuec16om0z66bhhh4tp7", + extra={ + "uuid": "b98f3a45-3328-41a0-9077-373a8177ebf2", + }, + value=Point(x=2122.0, y=1457.0), + ), + ], + ) + ] + + res = list(NDJsonConverter.serialize(labels)) + del res[1]["mask"]["colorRGB"] # JSON does not support tuples + assert res == data def test_image_with_name_only(): - with open('tests/data/assets/ndjson/image_import_name_only.json', - 'r') as file: + with open("tests/data/assets/ndjson/image_import_name_only.json", "r") as file: data = json.load(file) - res = list(NDJsonConverter.deserialize(data)) - res = list(NDJsonConverter.serialize(res)) - for r in res: - r.pop('classifications', None) - assert [round_dict(x) for x in res] == [round_dict(x) for x in data] + labels = [ + Label( + data=GenericDataRowData( + uid="ckrazctum0z8a0ybc0b0o0g0v", + ), + annotations=[ + ObjectAnnotation( + custom_metrics=[CustomMetric(name="customMetric1", value=0.4)], + confidence=0.851, + name="ckrazcueb16og0z6609jj7y3y", + extra={ + "uuid": "b862c586-8614-483c-b5e6-82810f70cac0", + }, + value=Rectangle( + start=Point(extra={}, x=2275.0, y=1352.0), + end=Point(extra={}, x=2414.0, y=1702.0), + ), + ), + ObjectAnnotation( + custom_metrics=[CustomMetric(name="customMetric1", value=0.3)], + confidence=0.834, + name="ckrazcuec16ok0z66f956apb7", + extra={ + "uuid": "751fc725-f7b6-48ed-89b0-dd7d94d08af6", + }, + value=Mask( + mask=MaskData( + url="https://storage.labelbox.com/ckqcx1czn06830y61gh9v02cs%2F3e729327-f038-f66c-186e-45e921ef9717-1?Expires=1626806874672&KeyName=labelbox-assets-key-3&Signature=YsUOGKrsqmAZ68vT9BlPJOaRyLY", + ), + color=[255, 0, 0], + ), + ), + ObjectAnnotation( + custom_metrics=[CustomMetric(name="customMetric1", value=0.9)], + confidence=0.986, + name="ckrazcuec16oi0z66dzrd8pfl", + extra={ + "uuid": "43d719ac-5d7f-4aea-be00-2ebfca0900fd", + }, + value=Polygon( + points=[ + Point(x=10.0, y=20.0), + Point(x=15.0, y=20.0), + Point(x=20.0, y=25.0), + Point(x=10.0, y=20.0), + ], + ), + ), + ObjectAnnotation( + name="ckrazcuec16om0z66bhhh4tp7", + extra={ + "uuid": "b98f3a45-3328-41a0-9077-373a8177ebf2", + }, + value=Point(x=2122.0, y=1457.0), + ), + ], + ) + ] + + res = list(NDJsonConverter.serialize(labels)) + del res[1]["mask"]["colorRGB"] # JSON does not support tuples + assert res == data def test_mask(): - data = [{ - "uuid": "b862c586-8614-483c-b5e6-82810f70cac0", - "schemaId": "ckrazcueb16og0z6609jj7y3y", - "dataRow": { - "id": "ckrazctum0z8a0ybc0b0o0g0v" - }, - "mask": { - "png": - "iVBORw0KGgoAAAANSUhEUgAAAAoAAAAKCAAAAACoWZBhAAAAMklEQVR4nD3MuQ3AQADDMOqQ/Vd2ijytaSiZLAcYuyLEYYYl9cvrlGftTHvsYl+u/3EDv0QLI8Z7FlwAAAAASUVORK5CYII=" + data = [ + { + "uuid": "b862c586-8614-483c-b5e6-82810f70cac0", + "schemaId": "ckrazcueb16og0z6609jj7y3y", + "dataRow": {"id": "ckrazctum0z8a0ybc0b0o0g0v"}, + "mask": { + "png": "iVBORw0KGgoAAAANSUhEUgAAAAIAAAACCAAAAABX3VL4AAAADklEQVR4nGNgYGBkZAAAAAsAA+RRQXwAAAAASUVORK5CYII=" + }, + "confidence": 0.8, + "customMetrics": [{"name": "customMetric1", "value": 0.4}], + "classifications": [], }, - "confidence": 0.8, - "customMetrics": [{ - "name": "customMetric1", - "value": 0.4 - }], - }, { - "uuid": "751fc725-f7b6-48ed-89b0-dd7d94d08af6", - "schemaId": "ckrazcuec16ok0z66f956apb7", - "dataRow": { - "id": "ckrazctum0z8a0ybc0b0o0g0v" + { + "uuid": "751fc725-f7b6-48ed-89b0-dd7d94d08af6", + "schemaId": "ckrazcuec16ok0z66f956apb7", + "dataRow": {"id": "ckrazctum0z8a0ybc0b0o0g0v"}, + "mask": { + "instanceURI": "https://storage.labelbox.com/ckqcx1czn06830y61gh9v02cs%2F3e729327-f038-f66c-186e-45e921ef9717-1?Expires=1626806874672&KeyName=labelbox-assets-key-3&Signature=YsUOGKrsqmAZ68vT9BlPJOaRyLY", + "colorRGB": (255, 0, 0), + }, + "classifications": [], }, - "mask": { - "instanceURI": - "https://storage.labelbox.com/ckqcx1czn06830y61gh9v02cs%2F3e729327-f038-f66c-186e-45e921ef9717-1?Expires=1626806874672&KeyName=labelbox-assets-key-3&Signature=YsUOGKrsqmAZ68vT9BlPJOaRyLY", - "colorRGB": [255, 0, 0] - } - }] - res = list(NDJsonConverter.deserialize(data)) - res = list(NDJsonConverter.serialize(res)) - for r in res: - r.pop('classifications', None) - - assert [round_dict(x) for x in res] == [round_dict(x) for x in data] + ] + + mask_numpy = np.array([[[1, 1, 0], [1, 0, 1]], [[1, 1, 1], [1, 1, 1]]]) + mask_numpy = mask_numpy.astype(np.uint8) + + labels = [ + Label( + data=GenericDataRowData( + uid="ckrazctum0z8a0ybc0b0o0g0v", + ), + annotations=[ + ObjectAnnotation( + custom_metrics=[CustomMetric(name="customMetric1", value=0.4)], + confidence=0.8, + feature_schema_id="ckrazcueb16og0z6609jj7y3y", + extra={ + "uuid": "b862c586-8614-483c-b5e6-82810f70cac0", + }, + value=Mask( + mask=MaskData(arr=mask_numpy), + color=(1, 1, 1), + ), + ), + ObjectAnnotation( + feature_schema_id="ckrazcuec16ok0z66f956apb7", + extra={ + "uuid": "751fc725-f7b6-48ed-89b0-dd7d94d08af6", + }, + value=Mask( + extra={}, + mask=MaskData( + url="https://storage.labelbox.com/ckqcx1czn06830y61gh9v02cs%2F3e729327-f038-f66c-186e-45e921ef9717-1?Expires=1626806874672&KeyName=labelbox-assets-key-3&Signature=YsUOGKrsqmAZ68vT9BlPJOaRyLY", + ), + color=(255, 0, 0), + ), + ), + ], + ) + ] + res = list(NDJsonConverter.serialize(labels)) + + assert res == data def test_mask_from_arr(): mask_arr = np.round(np.zeros((32, 32))).astype(np.uint8) mask_arr = cv2.rectangle(mask_arr, (5, 5), (10, 10), (1, 1), -1) - label = Label(annotations=[ - ObjectAnnotation(feature_schema_id="1" * 25, - value=Mask(mask=MaskData.from_2D_arr(arr=mask_arr), - color=(1, 1, 1))) - ], - data=ImageData(uid="0" * 25)) + label = Label( + annotations=[ + ObjectAnnotation( + feature_schema_id="1" * 25, + value=Mask(mask=MaskData.from_2D_arr(arr=mask_arr), color=(1, 1, 1)), + ) + ], + data=ImageData(uid="0" * 25), + ) res = next(NDJsonConverter.serialize([label])) res.pop("uuid") assert res == { "classifications": [], "schemaId": "1" * 25, - "dataRow": { - "id": "0" * 25 - }, + "dataRow": {"id": "0" * 25}, "mask": { - "png": - "iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAAAAABWESUoAAAAHklEQVR4nGNgGAKAEYn8j00BEyETBoOCUTAKhhwAAJW+AQwvpePVAAAAAElFTkSuQmCC" - } + "png": "iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAAAAABWESUoAAAAHklEQVR4nGNgGAKAEYn8j00BEyETBoOCUTAKhhwAAJW+AQwvpePVAAAAAElFTkSuQmCC" + }, } diff --git a/libs/labelbox/tests/data/serialization/ndjson/test_metric.py b/libs/labelbox/tests/data/serialization/ndjson/test_metric.py index 6508b73af..eb76635a0 100644 --- a/libs/labelbox/tests/data/serialization/ndjson/test_metric.py +++ b/libs/labelbox/tests/data/serialization/ndjson/test_metric.py @@ -4,31 +4,32 @@ def test_metric(): - with open('tests/data/assets/ndjson/metric_import.json', 'r') as file: + with open("tests/data/assets/ndjson/metric_import.json", "r") as file: data = json.load(file) label_list = list(NDJsonConverter.deserialize(data)) + from pprint import pprint + + pprint(label_list) reserialized = list(NDJsonConverter.serialize(label_list)) assert reserialized == data def test_custom_scalar_metric(): - with open('tests/data/assets/ndjson/custom_scalar_import.json', - 'r') as file: + with open("tests/data/assets/ndjson/custom_scalar_import.json", "r") as file: data = json.load(file) label_list = list(NDJsonConverter.deserialize(data)) reserialized = list(NDJsonConverter.serialize(label_list)) - assert json.dumps(reserialized, - sort_keys=True) == json.dumps(data, sort_keys=True) + assert json.dumps(reserialized, sort_keys=True) == json.dumps(data, sort_keys=True) def test_custom_confusion_matrix_metric(): - with open('tests/data/assets/ndjson/custom_confusion_matrix_import.json', - 'r') as file: + with open( + "tests/data/assets/ndjson/custom_confusion_matrix_import.json", "r" + ) as file: data = json.load(file) label_list = list(NDJsonConverter.deserialize(data)) reserialized = list(NDJsonConverter.serialize(label_list)) - assert json.dumps(reserialized, - sort_keys=True) == json.dumps(data, sort_keys=True) + assert json.dumps(reserialized, sort_keys=True) == json.dumps(data, sort_keys=True) From a55046651333bdcf8757c8230297e6502b527148 Mon Sep 17 00:00:00 2001 From: Gabefire <33893811+Gabefire@users.noreply.github.com> Date: Thu, 12 Sep 2024 20:36:15 -0500 Subject: [PATCH 06/11] formatted --- .../serialization/ndjson/test_checklist.py | 395 ++++++++++-------- 1 file changed, 220 insertions(+), 175 deletions(-) diff --git a/libs/labelbox/tests/data/serialization/ndjson/test_checklist.py b/libs/labelbox/tests/data/serialization/ndjson/test_checklist.py index ebcde0ea4..5850d86c6 100644 --- a/libs/labelbox/tests/data/serialization/ndjson/test_checklist.py +++ b/libs/labelbox/tests/data/serialization/ndjson/test_checklist.py @@ -1,5 +1,9 @@ from labelbox.data.annotation_types.annotation import ClassificationAnnotation -from labelbox.data.annotation_types.classification.classification import Checklist, ClassificationAnswer, Radio +from labelbox.data.annotation_types.classification.classification import ( + Checklist, + ClassificationAnswer, + Radio, +) from labelbox.data.annotation_types.data.text import TextData from labelbox.data.annotation_types.label import Label @@ -16,19 +20,15 @@ def test_serialization_min(): annotations=[ ClassificationAnnotation( name="checkbox_question_geo", - value=Checklist( - answer=[ClassificationAnswer(name="first_answer")]), + value=Checklist(answer=[ClassificationAnswer(name="first_answer")]), ) - ]) + ], + ) expected = { - 'name': 'checkbox_question_geo', - 'dataRow': { - 'id': 'bkj7z2q0b0000jx6x0q2q7q0d' - }, - 'answer': [{ - 'name': 'first_answer' - }] + "name": "checkbox_question_geo", + "dataRow": {"id": "bkj7z2q0b0000jx6x0q2q7q0d"}, + "answer": [{"name": "first_answer"}], } serialized = NDJsonConverter.serialize([label]) res = next(serialized) @@ -47,61 +47,76 @@ def test_serialization_with_classification(): ClassificationAnnotation( name="checkbox_question_geo", confidence=0.5, - value=Checklist(answer=[ - ClassificationAnswer( - name="first_answer", - confidence=0.1, - classifications=[ - ClassificationAnnotation( - name="sub_radio_question", - value=Radio(answer=ClassificationAnswer( - name="first_sub_radio_answer", - confidence=0.31))), - ClassificationAnnotation( - name="sub_chck_question", - value=Checklist(answer=[ - ClassificationAnswer( - name="second_subchk_answer", - confidence=0.41), - ClassificationAnswer( - name="third_subchk_answer", - confidence=0.42), - ],)) - ]), - ])) - ]) + value=Checklist( + answer=[ + ClassificationAnswer( + name="first_answer", + confidence=0.1, + classifications=[ + ClassificationAnnotation( + name="sub_radio_question", + value=Radio( + answer=ClassificationAnswer( + name="first_sub_radio_answer", + confidence=0.31, + ) + ), + ), + ClassificationAnnotation( + name="sub_chck_question", + value=Checklist( + answer=[ + ClassificationAnswer( + name="second_subchk_answer", + confidence=0.41, + ), + ClassificationAnswer( + name="third_subchk_answer", + confidence=0.42, + ), + ], + ), + ), + ], + ), + ] + ), + ) + ], + ) expected = { - 'confidence': - 0.5, - 'name': - 'checkbox_question_geo', - 'dataRow': { - 'id': 'bkj7z2q0b0000jx6x0q2q7q0d' - }, - 'answer': [{ - 'confidence': - 0.1, - 'name': - 'first_answer', - 'classifications': [{ - 'name': 'sub_radio_question', - 'answer': { - 'confidence': 0.31, - 'name': 'first_sub_radio_answer', - } - }, { - 'name': - 'sub_chck_question', - 'answer': [{ - 'confidence': 0.41, - 'name': 'second_subchk_answer', - }, { - 'confidence': 0.42, - 'name': 'third_subchk_answer', - }] - }] - }] + "confidence": 0.5, + "name": "checkbox_question_geo", + "dataRow": {"id": "bkj7z2q0b0000jx6x0q2q7q0d"}, + "answer": [ + { + "confidence": 0.1, + "name": "first_answer", + "classifications": [ + { + "name": "sub_radio_question", + "answer": { + "confidence": 0.31, + "name": "first_sub_radio_answer", + }, + }, + { + "name": "sub_chck_question", + "answer": [ + { + "confidence": 0.41, + "name": "second_subchk_answer", + }, + { + "confidence": 0.42, + "name": "third_subchk_answer", + }, + ], + }, + ], + } + ], } serialized = NDJsonConverter.serialize([label]) @@ -122,66 +137,80 @@ def test_serialization_with_classification_double_nested(): ClassificationAnnotation( name="checkbox_question_geo", confidence=0.5, - value=Checklist(answer=[ - ClassificationAnswer( - name="first_answer", - confidence=0.1, - classifications=[ - ClassificationAnnotation( - name="sub_radio_question", - value=Radio(answer=ClassificationAnswer( - name="first_sub_radio_answer", - confidence=0.31, - classifications=[ - ClassificationAnnotation( - name="sub_chck_question", - value=Checklist(answer=[ - ClassificationAnswer( - name="second_subchk_answer", - confidence=0.41), - ClassificationAnswer( - name="third_subchk_answer", - confidence=0.42), - ],)) - ]))), - ]), - ])) - ]) + value=Checklist( + answer=[ + ClassificationAnswer( + name="first_answer", + confidence=0.1, + classifications=[ + ClassificationAnnotation( + name="sub_radio_question", + value=Radio( + answer=ClassificationAnswer( + name="first_sub_radio_answer", + confidence=0.31, + classifications=[ + ClassificationAnnotation( + name="sub_chck_question", + value=Checklist( + answer=[ + ClassificationAnswer( + name="second_subchk_answer", + confidence=0.41, + ), + ClassificationAnswer( + name="third_subchk_answer", + confidence=0.42, + ), + ], + ), + ) + ], + ) + ), + ), + ], + ), + ] + ), + ) + ], + ) expected = { - 'confidence': - 0.5, - 'name': - 'checkbox_question_geo', - 'dataRow': { - 'id': 'bkj7z2q0b0000jx6x0q2q7q0d' - }, - 'answer': [{ - 'confidence': - 0.1, - 'name': - 'first_answer', - 'classifications': [{ - 'name': 'sub_radio_question', - 'answer': { - 'confidence': - 0.31, - 'name': - 'first_sub_radio_answer', - 'classifications': [{ - 'name': - 'sub_chck_question', - 'answer': [{ - 'confidence': 0.41, - 'name': 'second_subchk_answer', - }, { - 'confidence': 0.42, - 'name': 'third_subchk_answer', - }] - }] - } - }] - }] + "confidence": 0.5, + "name": "checkbox_question_geo", + "dataRow": {"id": "bkj7z2q0b0000jx6x0q2q7q0d"}, + "answer": [ + { + "confidence": 0.1, + "name": "first_answer", + "classifications": [ + { + "name": "sub_radio_question", + "answer": { + "confidence": 0.31, + "name": "first_sub_radio_answer", + "classifications": [ + { + "name": "sub_chck_question", + "answer": [ + { + "confidence": 0.41, + "name": "second_subchk_answer", + }, + { + "confidence": 0.42, + "name": "third_subchk_answer", + }, + ], + } + ], + }, + } + ], + } + ], } serialized = NDJsonConverter.serialize([label]) res = next(serialized) @@ -200,62 +229,78 @@ def test_serialization_with_classification_double_nested_2(): annotations=[ ClassificationAnnotation( name="sub_radio_question", - value=Radio(answer=ClassificationAnswer( - name="first_sub_radio_answer", - confidence=0.31, - classifications=[ - ClassificationAnnotation( - name="sub_chck_question", - value=Checklist(answer=[ - ClassificationAnswer( - name="second_subchk_answer", - confidence=0.41, - classifications=[ - ClassificationAnnotation( - name="checkbox_question_geo", - value=Checklist(answer=[ - ClassificationAnswer( - name="first_answer", - confidence=0.1), - ])) - ]), - ClassificationAnswer(name="third_subchk_answer", - confidence=0.42), - ])) - ]))), - ]) + value=Radio( + answer=ClassificationAnswer( + name="first_sub_radio_answer", + confidence=0.31, + classifications=[ + ClassificationAnnotation( + name="sub_chck_question", + value=Checklist( + answer=[ + ClassificationAnswer( + name="second_subchk_answer", + confidence=0.41, + classifications=[ + ClassificationAnnotation( + name="checkbox_question_geo", + value=Checklist( + answer=[ + ClassificationAnswer( + name="first_answer", + confidence=0.1, + ), + ] + ), + ) + ], + ), + ClassificationAnswer( + name="third_subchk_answer", confidence=0.42 + ), + ] + ), + ) + ], + ) + ), + ), + ], + ) expected = { - 'name': 'sub_radio_question', - 'answer': { - 'confidence': - 0.31, - 'name': - 'first_sub_radio_answer', - 'classifications': [{ - 'name': - 'sub_chck_question', - 'answer': [{ - 'confidence': - 0.41, - 'name': - 'second_subchk_answer', - 'classifications': [{ - 'name': 'checkbox_question_geo', - 'answer': [{ - 'confidence': 0.1, - 'name': 'first_answer', - }] - }] - }, { - 'confidence': 0.42, - 'name': 'third_subchk_answer', - }] - }] + "name": "sub_radio_question", + "answer": { + "confidence": 0.31, + "name": "first_sub_radio_answer", + "classifications": [ + { + "name": "sub_chck_question", + "answer": [ + { + "confidence": 0.41, + "name": "second_subchk_answer", + "classifications": [ + { + "name": "checkbox_question_geo", + "answer": [ + { + "confidence": 0.1, + "name": "first_answer", + } + ], + } + ], + }, + { + "confidence": 0.42, + "name": "third_subchk_answer", + }, + ], + } + ], }, - 'dataRow': { - 'id': 'bkj7z2q0b0000jx6x0q2q7q0d' - } + "dataRow": {"id": "bkj7z2q0b0000jx6x0q2q7q0d"}, } serialized = NDJsonConverter.serialize([label]) From 04ead86fcc233aa34c7d69bb984a55bada40c490 Mon Sep 17 00:00:00 2001 From: Gabefire <33893811+Gabefire@users.noreply.github.com> Date: Thu, 12 Sep 2024 20:48:44 -0500 Subject: [PATCH 07/11] reformatted files --- .../serialization/ndjson/test_checklist.py | 7 ++-- .../ndjson/test_classification.py | 4 ++- .../serialization/ndjson/test_conversation.py | 16 ++++++--- .../serialization/ndjson/test_data_gen.py | 7 ++-- .../data/serialization/ndjson/test_dicom.py | 19 +++++++--- .../data/serialization/ndjson/test_image.py | 36 ++++++++++++++----- .../data/serialization/ndjson/test_metric.py | 12 +++++-- 7 files changed, 75 insertions(+), 26 deletions(-) diff --git a/libs/labelbox/tests/data/serialization/ndjson/test_checklist.py b/libs/labelbox/tests/data/serialization/ndjson/test_checklist.py index 5850d86c6..59f568c75 100644 --- a/libs/labelbox/tests/data/serialization/ndjson/test_checklist.py +++ b/libs/labelbox/tests/data/serialization/ndjson/test_checklist.py @@ -20,7 +20,9 @@ def test_serialization_min(): annotations=[ ClassificationAnnotation( name="checkbox_question_geo", - value=Checklist(answer=[ClassificationAnswer(name="first_answer")]), + value=Checklist( + answer=[ClassificationAnswer(name="first_answer")] + ), ) ], ) @@ -256,7 +258,8 @@ def test_serialization_with_classification_double_nested_2(): ], ), ClassificationAnswer( - name="third_subchk_answer", confidence=0.42 + name="third_subchk_answer", + confidence=0.42, ), ] ), diff --git a/libs/labelbox/tests/data/serialization/ndjson/test_classification.py b/libs/labelbox/tests/data/serialization/ndjson/test_classification.py index efb3f0cf7..dcff8c377 100644 --- a/libs/labelbox/tests/data/serialization/ndjson/test_classification.py +++ b/libs/labelbox/tests/data/serialization/ndjson/test_classification.py @@ -17,7 +17,9 @@ def test_classification(): - with open("tests/data/assets/ndjson/classification_import.json", "r") as file: + with open( + "tests/data/assets/ndjson/classification_import.json", "r" + ) as file: data = json.load(file) label = Label( diff --git a/libs/labelbox/tests/data/serialization/ndjson/test_conversation.py b/libs/labelbox/tests/data/serialization/ndjson/test_conversation.py index 4d995a9ef..ddfae26a4 100644 --- a/libs/labelbox/tests/data/serialization/ndjson/test_conversation.py +++ b/libs/labelbox/tests/data/serialization/ndjson/test_conversation.py @@ -21,7 +21,9 @@ lb_types.ClassificationAnnotation( name="radio", value=lb_types.Radio( - answer=lb_types.ClassificationAnswer(name="first_radio_answer") + answer=lb_types.ClassificationAnswer( + name="first_radio_answer" + ) ), message_id="0", ) @@ -50,8 +52,12 @@ message_id="2", value=lb_types.Checklist( answer=[ - lb_types.ClassificationAnswer(name="first_checklist_answer"), - lb_types.ClassificationAnswer(name="second_checklist_answer"), + lb_types.ClassificationAnswer( + name="first_checklist_answer" + ), + lb_types.ClassificationAnswer( + name="second_checklist_answer" + ), ] ), ) @@ -96,7 +102,9 @@ def test_message_based_radio_classification(label, ndjson): def test_conversation_entity_import(): - with open("tests/data/assets/ndjson/conversation_entity_import.json", "r") as file: + with open( + "tests/data/assets/ndjson/conversation_entity_import.json", "r" + ) as file: data = json.load(file) label = lb_types.Label( diff --git a/libs/labelbox/tests/data/serialization/ndjson/test_data_gen.py b/libs/labelbox/tests/data/serialization/ndjson/test_data_gen.py index d870d9618..999e1bda5 100644 --- a/libs/labelbox/tests/data/serialization/ndjson/test_data_gen.py +++ b/libs/labelbox/tests/data/serialization/ndjson/test_data_gen.py @@ -7,7 +7,9 @@ def test_serialize_label(): feature_schema_id="ckrb1sfkn099c0y910wbo0p1a", name="test", extra={"uuid": "test"}, - value=lb_types.PromptText(answer="the answer to the text questions right here"), + value=lb_types.PromptText( + answer="the answer to the text questions right here" + ), ) prompt_text_ndjson = { @@ -19,7 +21,8 @@ def test_serialize_label(): } data_gen_label = lb_types.Label( - data={"uid": "ckrb1sf1i1g7i0ybcdc6oc8ct"}, annotations=[prompt_text_annotation] + data={"uid": "ckrb1sf1i1g7i0ybcdc6oc8ct"}, + annotations=[prompt_text_annotation], ) serialized_label = next(NDJsonConverter().serialize([data_gen_label])) diff --git a/libs/labelbox/tests/data/serialization/ndjson/test_dicom.py b/libs/labelbox/tests/data/serialization/ndjson/test_dicom.py index e6ccba3b7..762891aa2 100644 --- a/libs/labelbox/tests/data/serialization/ndjson/test_dicom.py +++ b/libs/labelbox/tests/data/serialization/ndjson/test_dicom.py @@ -31,7 +31,8 @@ ] polyline_label = lb_types.Label( - data=lb_types.DicomData(uid="test-uid"), annotations=dicom_polyline_annotations + data=lb_types.DicomData(uid="test-uid"), + annotations=dicom_polyline_annotations, ) polyline_annotation_ndjson = { @@ -62,7 +63,9 @@ ) polyline_annotation_ndjson_with_global_key = copy(polyline_annotation_ndjson) -polyline_annotation_ndjson_with_global_key["dataRow"] = {"globalKey": "test-global-key"} +polyline_annotation_ndjson_with_global_key["dataRow"] = { + "globalKey": "test-global-key" +} """ Video test data """ @@ -79,7 +82,9 @@ lb_types.MaskInstance(color_rgb=(255, 0, 0), name="mask3"), ] -video_mask_annotation = lb_types.VideoMaskAnnotation(frames=frames, instances=instances) +video_mask_annotation = lb_types.VideoMaskAnnotation( + frames=frames, instances=instances +) video_mask_annotation_ndjson = { "dataRow": {"id": "test-uid"}, @@ -96,7 +101,9 @@ }, } -video_mask_annotation_ndjson_with_global_key = copy(video_mask_annotation_ndjson) +video_mask_annotation_ndjson_with_global_key = copy( + video_mask_annotation_ndjson +) video_mask_annotation_ndjson_with_global_key["dataRow"] = { "globalKey": "test-global-key" } @@ -131,7 +138,9 @@ dicom_mask_annotation_ndjson = copy(video_mask_annotation_ndjson) dicom_mask_annotation_ndjson["groupKey"] = "axial" -dicom_mask_annotation_ndjson_with_global_key = copy(dicom_mask_annotation_ndjson) +dicom_mask_annotation_ndjson_with_global_key = copy( + dicom_mask_annotation_ndjson +) dicom_mask_annotation_ndjson_with_global_key["dataRow"] = { "globalKey": "test-global-key" } diff --git a/libs/labelbox/tests/data/serialization/ndjson/test_image.py b/libs/labelbox/tests/data/serialization/ndjson/test_image.py index baf5d3d92..e6add1481 100644 --- a/libs/labelbox/tests/data/serialization/ndjson/test_image.py +++ b/libs/labelbox/tests/data/serialization/ndjson/test_image.py @@ -38,7 +38,9 @@ def test_image(): ), annotations=[ ObjectAnnotation( - custom_metrics=[CustomMetric(name="customMetric1", value=0.4)], + custom_metrics=[ + CustomMetric(name="customMetric1", value=0.4) + ], confidence=0.851, feature_schema_id="ckrazcueb16og0z6609jj7y3y", extra={ @@ -50,7 +52,9 @@ def test_image(): ), ), ObjectAnnotation( - custom_metrics=[CustomMetric(name="customMetric1", value=0.3)], + custom_metrics=[ + CustomMetric(name="customMetric1", value=0.3) + ], confidence=0.834, feature_schema_id="ckrazcuec16ok0z66f956apb7", extra={ @@ -64,7 +68,9 @@ def test_image(): ), ), ObjectAnnotation( - custom_metrics=[CustomMetric(name="customMetric1", value=0.9)], + custom_metrics=[ + CustomMetric(name="customMetric1", value=0.9) + ], confidence=0.986, feature_schema_id="ckrazcuec16oi0z66dzrd8pfl", extra={ @@ -96,7 +102,9 @@ def test_image(): def test_image_with_name_only(): - with open("tests/data/assets/ndjson/image_import_name_only.json", "r") as file: + with open( + "tests/data/assets/ndjson/image_import_name_only.json", "r" + ) as file: data = json.load(file) labels = [ @@ -106,7 +114,9 @@ def test_image_with_name_only(): ), annotations=[ ObjectAnnotation( - custom_metrics=[CustomMetric(name="customMetric1", value=0.4)], + custom_metrics=[ + CustomMetric(name="customMetric1", value=0.4) + ], confidence=0.851, name="ckrazcueb16og0z6609jj7y3y", extra={ @@ -118,7 +128,9 @@ def test_image_with_name_only(): ), ), ObjectAnnotation( - custom_metrics=[CustomMetric(name="customMetric1", value=0.3)], + custom_metrics=[ + CustomMetric(name="customMetric1", value=0.3) + ], confidence=0.834, name="ckrazcuec16ok0z66f956apb7", extra={ @@ -132,7 +144,9 @@ def test_image_with_name_only(): ), ), ObjectAnnotation( - custom_metrics=[CustomMetric(name="customMetric1", value=0.9)], + custom_metrics=[ + CustomMetric(name="customMetric1", value=0.9) + ], confidence=0.986, name="ckrazcuec16oi0z66dzrd8pfl", extra={ @@ -198,7 +212,9 @@ def test_mask(): ), annotations=[ ObjectAnnotation( - custom_metrics=[CustomMetric(name="customMetric1", value=0.4)], + custom_metrics=[ + CustomMetric(name="customMetric1", value=0.4) + ], confidence=0.8, feature_schema_id="ckrazcueb16og0z6609jj7y3y", extra={ @@ -238,7 +254,9 @@ def test_mask_from_arr(): annotations=[ ObjectAnnotation( feature_schema_id="1" * 25, - value=Mask(mask=MaskData.from_2D_arr(arr=mask_arr), color=(1, 1, 1)), + value=Mask( + mask=MaskData.from_2D_arr(arr=mask_arr), color=(1, 1, 1) + ), ) ], data=ImageData(uid="0" * 25), diff --git a/libs/labelbox/tests/data/serialization/ndjson/test_metric.py b/libs/labelbox/tests/data/serialization/ndjson/test_metric.py index eb76635a0..45ac09283 100644 --- a/libs/labelbox/tests/data/serialization/ndjson/test_metric.py +++ b/libs/labelbox/tests/data/serialization/ndjson/test_metric.py @@ -16,12 +16,16 @@ def test_metric(): def test_custom_scalar_metric(): - with open("tests/data/assets/ndjson/custom_scalar_import.json", "r") as file: + with open( + "tests/data/assets/ndjson/custom_scalar_import.json", "r" + ) as file: data = json.load(file) label_list = list(NDJsonConverter.deserialize(data)) reserialized = list(NDJsonConverter.serialize(label_list)) - assert json.dumps(reserialized, sort_keys=True) == json.dumps(data, sort_keys=True) + assert json.dumps(reserialized, sort_keys=True) == json.dumps( + data, sort_keys=True + ) def test_custom_confusion_matrix_metric(): @@ -32,4 +36,6 @@ def test_custom_confusion_matrix_metric(): label_list = list(NDJsonConverter.deserialize(data)) reserialized = list(NDJsonConverter.serialize(label_list)) - assert json.dumps(reserialized, sort_keys=True) == json.dumps(data, sort_keys=True) + assert json.dumps(reserialized, sort_keys=True) == json.dumps( + data, sort_keys=True + ) From b2a85cd377766b6811f89938d76332bee6937f2f Mon Sep 17 00:00:00 2001 From: Gabe <33893811+Gabefire@users.noreply.github.com> Date: Thu, 12 Sep 2024 20:57:58 -0500 Subject: [PATCH 08/11] Update test_metric.py --- libs/labelbox/tests/data/serialization/ndjson/test_metric.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/libs/labelbox/tests/data/serialization/ndjson/test_metric.py b/libs/labelbox/tests/data/serialization/ndjson/test_metric.py index 45ac09283..45c5c67bf 100644 --- a/libs/labelbox/tests/data/serialization/ndjson/test_metric.py +++ b/libs/labelbox/tests/data/serialization/ndjson/test_metric.py @@ -8,9 +8,6 @@ def test_metric(): data = json.load(file) label_list = list(NDJsonConverter.deserialize(data)) - from pprint import pprint - - pprint(label_list) reserialized = list(NDJsonConverter.serialize(label_list)) assert reserialized == data From 1ca21a208d498bf9159db06934d5200fa5958205 Mon Sep 17 00:00:00 2001 From: Gabefire <33893811+Gabefire@users.noreply.github.com> Date: Fri, 13 Sep 2024 11:07:36 -0500 Subject: [PATCH 09/11] fixed --- .../tests/data/serialization/ndjson/test_conversation.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/libs/labelbox/tests/data/serialization/ndjson/test_conversation.py b/libs/labelbox/tests/data/serialization/ndjson/test_conversation.py index ddfae26a4..561f9ce86 100644 --- a/libs/labelbox/tests/data/serialization/ndjson/test_conversation.py +++ b/libs/labelbox/tests/data/serialization/ndjson/test_conversation.py @@ -1,5 +1,8 @@ import json +from labelbox.data.annotation_types.data.generic_data_row_data import ( + GenericDataRowData, +) import pytest import labelbox.types as lb_types from labelbox.data.serialization.ndjson.converter import NDJsonConverter @@ -108,7 +111,7 @@ def test_conversation_entity_import(): data = json.load(file) label = lb_types.Label( - data=lb_types.GenericDataRowData( + data=GenericDataRowData( uid="cl6xnv9h61fv0085yhtoq06ht", ), annotations=[ @@ -140,7 +143,7 @@ def test_conversation_entity_import_without_confidence(): data = json.load(file) label = lb_types.Label( uid=None, - data=lb_types.GenericDataRowData( + data=GenericDataRowData( uid="cl6xnv9h61fv0085yhtoq06ht", ), annotations=[ From 7cd3925875aa3d2e82ad926bbbf92003dded8c4c Mon Sep 17 00:00:00 2001 From: Gabefire <33893811+Gabefire@users.noreply.github.com> Date: Fri, 13 Sep 2024 11:19:10 -0500 Subject: [PATCH 10/11] fixed --- .../tests/data/serialization/ndjson/test_classification.py | 4 +++- .../labelbox/tests/data/serialization/ndjson/test_document.py | 4 +++- .../tests/data/serialization/ndjson/test_global_key.py | 4 +++- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/libs/labelbox/tests/data/serialization/ndjson/test_classification.py b/libs/labelbox/tests/data/serialization/ndjson/test_classification.py index dcff8c377..82adce99c 100644 --- a/libs/labelbox/tests/data/serialization/ndjson/test_classification.py +++ b/libs/labelbox/tests/data/serialization/ndjson/test_classification.py @@ -5,13 +5,15 @@ Radio, Text, ) +from labelbox.data.annotation_types.data.generic_data_row_data import ( + GenericDataRowData, +) from labelbox.data.serialization.ndjson.converter import NDJsonConverter from labelbox.types import ( Label, ClassificationAnnotation, ClassificationAnswer, - GenericDataRowData, ) from labelbox.data.mixins import CustomMetric diff --git a/libs/labelbox/tests/data/serialization/ndjson/test_document.py b/libs/labelbox/tests/data/serialization/ndjson/test_document.py index 87f587496..a0897ad9f 100644 --- a/libs/labelbox/tests/data/serialization/ndjson/test_document.py +++ b/libs/labelbox/tests/data/serialization/ndjson/test_document.py @@ -1,10 +1,12 @@ import json +from labelbox.data.annotation_types.data.generic_data_row_data import ( + GenericDataRowData, +) from labelbox.data.mixins import CustomMetric import labelbox.types as lb_types from labelbox.data.serialization.ndjson.converter import NDJsonConverter from labelbox.types import ( Label, - GenericDataRowData, ObjectAnnotation, RectangleUnit, Point, diff --git a/libs/labelbox/tests/data/serialization/ndjson/test_global_key.py b/libs/labelbox/tests/data/serialization/ndjson/test_global_key.py index 7d6e9fdc3..d104a691e 100644 --- a/libs/labelbox/tests/data/serialization/ndjson/test_global_key.py +++ b/libs/labelbox/tests/data/serialization/ndjson/test_global_key.py @@ -1,6 +1,8 @@ +from labelbox.data.annotation_types.data.generic_data_row_data import ( + GenericDataRowData, +) from labelbox.data.serialization.ndjson.converter import NDJsonConverter from labelbox.types import ( - GenericDataRowData, Label, ClassificationAnnotation, Radio, From d9a45841f641224967f31ad42b5ef36d99e19b73 Mon Sep 17 00:00:00 2001 From: Gabefire <33893811+Gabefire@users.noreply.github.com> Date: Fri, 13 Sep 2024 11:28:44 -0500 Subject: [PATCH 11/11] last fix --- libs/labelbox/tests/data/serialization/ndjson/test_image.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/libs/labelbox/tests/data/serialization/ndjson/test_image.py b/libs/labelbox/tests/data/serialization/ndjson/test_image.py index e6add1481..d67acb9c3 100644 --- a/libs/labelbox/tests/data/serialization/ndjson/test_image.py +++ b/libs/labelbox/tests/data/serialization/ndjson/test_image.py @@ -1,4 +1,7 @@ import json +from labelbox.data.annotation_types.data.generic_data_row_data import ( + GenericDataRowData, +) from labelbox.data.mixins import CustomMetric import numpy as np import cv2 @@ -11,7 +14,7 @@ ImageData, MaskData, ) -from labelbox.types import GenericDataRowData, Rectangle, Polygon, Point +from labelbox.types import Rectangle, Polygon, Point def round_dict(data):