From f0ae2fd029c1010e70004b6ef505f70fb49c7541 Mon Sep 17 00:00:00 2001 From: siesto1elemento Date: Thu, 12 Sep 2024 17:53:44 +0530 Subject: [PATCH] fix for adding multiple attributes --- cvat/apps/dataset_manager/formats/LibriVox.py | 28 ++++++++++++++----- .../dataset_manager/formats/VCTK_Corpus.py | 28 ++++++++++++++----- cvat/apps/dataset_manager/formats/VoxCeleb.py | 28 ++++++++++++++----- .../apps/dataset_manager/formats/Voxpopuli.py | 28 ++++++++++++++----- .../dataset_manager/formats/common_voice.py | 28 ++++++++++++++----- .../dataset_manager/formats/librispeech.py | 28 ++++++++++++++----- cvat/apps/dataset_manager/formats/tedlium.py | 28 ++++++++++++++----- 7 files changed, 147 insertions(+), 49 deletions(-) diff --git a/cvat/apps/dataset_manager/formats/LibriVox.py b/cvat/apps/dataset_manager/formats/LibriVox.py index 8dce61a43284..ad6abd78e59e 100644 --- a/cvat/apps/dataset_manager/formats/LibriVox.py +++ b/cvat/apps/dataset_manager/formats/LibriVox.py @@ -42,7 +42,26 @@ def load_anno(file_object, annotations): language_id_to_locale_mapping = {0: "en"} language_id = int(record.get("language", 0)) - spec_id = label_data._get_attribute_id(label_id, record.get("attribute_1_name")) + attributes = [] + + for i in range(1, len(headers)): + attribute_name_key = f"attribute_{i}_name" + attribute_value_key = f"attribute_{i}_value" + + if attribute_name_key in record and attribute_value_key in record: + attribute_name = record.get(attribute_name_key) + attribute_value = record.get(attribute_value_key) + + if attribute_name and attribute_value: + + spec_id = label_data._get_attribute_id(label_id, attribute_name) + + attributes.append( + { + "spec_id": spec_id, + "value": attribute_value, + } + ) shapes_data = [ { @@ -62,12 +81,7 @@ def load_anno(file_object, annotations): "emotion": record.get("emotion", ""), "rotation": 0.0, "label_id": label_id, - "attributes": [ - { - "spec_id": spec_id, - "value": record.get("attribute_1_value", ""), - } - ], + "attributes": attributes, } ] diff --git a/cvat/apps/dataset_manager/formats/VCTK_Corpus.py b/cvat/apps/dataset_manager/formats/VCTK_Corpus.py index af938773ebbb..fa17a33647ca 100644 --- a/cvat/apps/dataset_manager/formats/VCTK_Corpus.py +++ b/cvat/apps/dataset_manager/formats/VCTK_Corpus.py @@ -42,7 +42,26 @@ def load_anno(file_object, annotations): language_id_to_locale_mapping = {0: "en"} language_id = int(record.get("language", 0)) - spec_id = label_data._get_attribute_id(label_id, record.get("attribute_1_name")) + attributes = [] + + for i in range(1, len(headers)): + attribute_name_key = f"attribute_{i}_name" + attribute_value_key = f"attribute_{i}_value" + + if attribute_name_key in record and attribute_value_key in record: + attribute_name = record.get(attribute_name_key) + attribute_value = record.get(attribute_value_key) + + if attribute_name and attribute_value: + + spec_id = label_data._get_attribute_id(label_id, attribute_name) + + attributes.append( + { + "spec_id": spec_id, + "value": attribute_value, + } + ) shapes_data = [ { @@ -62,12 +81,7 @@ def load_anno(file_object, annotations): "emotion": record.get("emotion", ""), "rotation": 0.0, "label_id": label_id, - "attributes": [ - { - "spec_id": spec_id, - "value": record.get("attribute_1_value", ""), - } - ], + "attributes": attributes, } ] diff --git a/cvat/apps/dataset_manager/formats/VoxCeleb.py b/cvat/apps/dataset_manager/formats/VoxCeleb.py index 3a0228b59814..b924612c32ab 100644 --- a/cvat/apps/dataset_manager/formats/VoxCeleb.py +++ b/cvat/apps/dataset_manager/formats/VoxCeleb.py @@ -42,7 +42,26 @@ def load_anno(file_object, annotations): language_id_to_locale_mapping = {0: "en"} language_id = int(record.get("language", 0)) - spec_id = label_data._get_attribute_id(label_id, record.get("attribute_1_name")) + attributes = [] + + for i in range(1, len(headers)): + attribute_name_key = f"attribute_{i}_name" + attribute_value_key = f"attribute_{i}_value" + + if attribute_name_key in record and attribute_value_key in record: + attribute_name = record.get(attribute_name_key) + attribute_value = record.get(attribute_value_key) + + if attribute_name and attribute_value: + + spec_id = label_data._get_attribute_id(label_id, attribute_name) + + attributes.append( + { + "spec_id": spec_id, + "value": attribute_value, + } + ) shapes_data = [ { @@ -62,12 +81,7 @@ def load_anno(file_object, annotations): "emotion": record.get("emotion", ""), "rotation": 0.0, "label_id": label_id, - "attributes": [ - { - "spec_id": spec_id, - "value": record.get("attribute_1_value", ""), - } - ], + "attributes": attributes, } ] diff --git a/cvat/apps/dataset_manager/formats/Voxpopuli.py b/cvat/apps/dataset_manager/formats/Voxpopuli.py index e31c549177a2..69954e4f5e7a 100644 --- a/cvat/apps/dataset_manager/formats/Voxpopuli.py +++ b/cvat/apps/dataset_manager/formats/Voxpopuli.py @@ -42,7 +42,26 @@ def load_anno(file_object, annotations): language_id_to_locale_mapping = {0: "en"} language_id = int(record.get("language", 0)) - spec_id = label_data._get_attribute_id(label_id, record.get("attribute_1_name")) + attributes = [] + + for i in range(1, len(headers)): + attribute_name_key = f"attribute_{i}_name" + attribute_value_key = f"attribute_{i}_value" + + if attribute_name_key in record and attribute_value_key in record: + attribute_name = record.get(attribute_name_key) + attribute_value = record.get(attribute_value_key) + + if attribute_name and attribute_value: + + spec_id = label_data._get_attribute_id(label_id, attribute_name) + + attributes.append( + { + "spec_id": spec_id, + "value": attribute_value, + } + ) shapes_data = [ { @@ -62,12 +81,7 @@ def load_anno(file_object, annotations): "emotion": record.get("emotion", ""), "rotation": 0.0, "label_id": label_id, - "attributes": [ - { - "spec_id": spec_id, - "value": record.get("attribute_1_value", ""), - } - ], + "attributes": attributes, } ] diff --git a/cvat/apps/dataset_manager/formats/common_voice.py b/cvat/apps/dataset_manager/formats/common_voice.py index d0cd4cb47361..eebeb8f189ac 100644 --- a/cvat/apps/dataset_manager/formats/common_voice.py +++ b/cvat/apps/dataset_manager/formats/common_voice.py @@ -42,7 +42,26 @@ def load_anno(file_object, annotations): language_id_to_locale_mapping = {0: "en"} language_id = int(record.get("language", 0)) - spec_id = label_data._get_attribute_id(label_id, record.get("attribute_1_name")) + attributes = [] + + for i in range(1, len(headers)): + attribute_name_key = f"attribute_{i}_name" + attribute_value_key = f"attribute_{i}_value" + + if attribute_name_key in record and attribute_value_key in record: + attribute_name = record.get(attribute_name_key) + attribute_value = record.get(attribute_value_key) + + if attribute_name and attribute_value: + + spec_id = label_data._get_attribute_id(label_id, attribute_name) + + attributes.append( + { + "spec_id": spec_id, + "value": attribute_value, + } + ) shapes_data = [ { @@ -62,12 +81,7 @@ def load_anno(file_object, annotations): "emotion": record.get("emotion", ""), "rotation": 0.0, "label_id": label_id, - "attributes": [ - { - "spec_id": spec_id, - "value": record.get("attribute_1_value", ""), - } - ], + "attributes": attributes, } ] diff --git a/cvat/apps/dataset_manager/formats/librispeech.py b/cvat/apps/dataset_manager/formats/librispeech.py index 76cb51c68ee4..0b3383f2c294 100644 --- a/cvat/apps/dataset_manager/formats/librispeech.py +++ b/cvat/apps/dataset_manager/formats/librispeech.py @@ -39,7 +39,26 @@ def load_anno(file_object, annotations): label_name = record.get("label") label_id = label_data._get_label_id(label_name) - spec_id = label_data._get_attribute_id(label_id, record.get("attribute_1_name")) + attributes = [] + + for i in range(1, len(headers)): + attribute_name_key = f"attribute_{i}_name" + attribute_value_key = f"attribute_{i}_value" + + if attribute_name_key in record and attribute_value_key in record: + attribute_name = record.get(attribute_name_key) + attribute_value = record.get(attribute_value_key) + + if attribute_name and attribute_value: + + spec_id = label_data._get_attribute_id(label_id, attribute_name) + + attributes.append( + { + "spec_id": spec_id, + "value": attribute_value, + } + ) language_id_to_locale_mapping = {0: "en"} language_id = int(record.get("language", 0)) @@ -62,12 +81,7 @@ def load_anno(file_object, annotations): "emotion": record.get("emotion", ""), "rotation": 0.0, "label_id": label_id, - "attributes": [ - { - "spec_id": spec_id, - "value": record.get("attribute_1_value", ""), - } - ], + "attributes": attributes, } ] diff --git a/cvat/apps/dataset_manager/formats/tedlium.py b/cvat/apps/dataset_manager/formats/tedlium.py index 00cae3fed7c0..91facd51887e 100644 --- a/cvat/apps/dataset_manager/formats/tedlium.py +++ b/cvat/apps/dataset_manager/formats/tedlium.py @@ -42,7 +42,26 @@ def load_anno(file_object, annotations): language_id_to_locale_mapping = {0: "en"} language_id = int(record.get("language", 0)) - spec_id = label_data._get_attribute_id(label_id, record.get("attribute_1_name")) + attributes = [] + + for i in range(1, len(headers)): + attribute_name_key = f"attribute_{i}_name" + attribute_value_key = f"attribute_{i}_value" + + if attribute_name_key in record and attribute_value_key in record: + attribute_name = record.get(attribute_name_key) + attribute_value = record.get(attribute_value_key) + + if attribute_name and attribute_value: + + spec_id = label_data._get_attribute_id(label_id, attribute_name) + + attributes.append( + { + "spec_id": spec_id, + "value": attribute_value, + } + ) shapes_data = [ { @@ -62,12 +81,7 @@ def load_anno(file_object, annotations): "emotion": record.get("emotion", ""), "rotation": 0.0, "label_id": label_id, - "attributes": [ - { - "spec_id": spec_id, - "value": record.get("attribute_1_value", ""), - } - ], + "attributes": attributes, } ]