From 1facc4fcdc6fd95c9387284c17234786374ea932 Mon Sep 17 00:00:00 2001 From: Mathieu Beligon <mathieu@feedly.com> Date: Sat, 28 Mar 2020 17:28:11 -0400 Subject: [PATCH] [common] (minor) some changes around annotation correction --- ...onstruct_dataset_from_manual_annotation.py | 8 ------- ...t_twith_datasets_from_manual_annotation.py | 14 ++++++++++--- .../scripts/correct_annotations.py | 21 ++++++++++++++----- 3 files changed, 27 insertions(+), 16 deletions(-) diff --git a/common/research_common/scripts/construct_dataset_from_manual_annotation.py b/common/research_common/scripts/construct_dataset_from_manual_annotation.py index d3ab518..3178c91 100644 --- a/common/research_common/scripts/construct_dataset_from_manual_annotation.py +++ b/common/research_common/scripts/construct_dataset_from_manual_annotation.py @@ -3,8 +3,6 @@ from pathlib import Path from shutil import move, rmtree from zipfile import ZipFile -from research_common.constants import TWITCH_DSET_DIR, TWITCH_ROBOTS_VIEWS_DIR, TWITCH_DSET_ROBOTS_VIEWS_DIR - def construct_dataset_from_manual_annotations( source_images_directory: Path, source_annotations_directory: Path, destination_directory: Path @@ -29,9 +27,3 @@ def _unzip_all_in_directory(source_directory: Path, destination_directory: Path, for directory in destination_directory.glob("*"): if directory.is_dir(): rmtree(str(directory)) - - -if __name__ == "__main__": - construct_dataset_from_manual_annotations( - TWITCH_ROBOTS_VIEWS_DIR, TWITCH_DSET_DIR / "robots-views-annotations", TWITCH_DSET_ROBOTS_VIEWS_DIR, - ) diff --git a/common/research_common/scripts/construct_twith_datasets_from_manual_annotation.py b/common/research_common/scripts/construct_twith_datasets_from_manual_annotation.py index 44f6434..3989bba 100644 --- a/common/research_common/scripts/construct_twith_datasets_from_manual_annotation.py +++ b/common/research_common/scripts/construct_twith_datasets_from_manual_annotation.py @@ -1,4 +1,5 @@ -from shutil import copy, move, rmtree +from os import remove +from shutil import copy, move, rmtree, make_archive from research_common.constants import TWITCH_DSET_DIR, TWITCH_ROBOTS_VIEWS_DIR, TWITCH_DSET_ROBOTS_VIEWS_DIR from research_common.dataset.directory_roco_dataset import DirectoryROCODataset @@ -38,8 +39,9 @@ def _separate_twitch_videos(): move(str(annotation.xml_path), str(annotations_path / annotation.xml_path.name)) if list((TWITCH_DSET_ROBOTS_VIEWS_DIR / "image").glob("*")): raise Exception(f"Some images remains unmoved") - if list((TWITCH_DSET_ROBOTS_VIEWS_DIR / "image_annotation").glob("*")): - raise Exception(f"Some annotations remains unmoved") + for remaining_file in (TWITCH_DSET_ROBOTS_VIEWS_DIR / "image_annotation").glob("*"): + if remaining_file.name != ".DS_Store": + raise Exception(f"Some annotations remains unmoved") rmtree(str(TWITCH_DSET_ROBOTS_VIEWS_DIR / "image")) rmtree(str(TWITCH_DSET_ROBOTS_VIEWS_DIR / "image_annotation")) @@ -61,6 +63,12 @@ def _make_separate_reports(): if __name__ == "__main__": + + for zip_file in (TWITCH_DSET_DIR / "reviewed-robots-views-annotations").glob("*.zip"): + remove(str(zip_file)) + for chunk_dir in (TWITCH_DSET_DIR / "reviewed-robots-views-annotations").glob("chunk_*"): + make_archive(chunk_dir, "zip", chunk_dir) + _construct_mixed_twitch_dset() _correct_manual_annotations() _extract_runes_images() diff --git a/common/research_common/scripts/correct_annotations.py b/common/research_common/scripts/correct_annotations.py index 2dfb1a8..5b45d96 100644 --- a/common/research_common/scripts/correct_annotations.py +++ b/common/research_common/scripts/correct_annotations.py @@ -3,14 +3,25 @@ from pathlib import Path class AnnotationFileCorrector: - FINAL_ARMOR_NAME_PATTERN = re.compile(r"<name>(armor|amor)-(?P<color>\w{2,4})-(?P<num>\d)</name>", re.IGNORECASE) - ABV_ARMOR_NAME_PATTERN = re.compile(r"<name>a(?P<color>\w)(?P<num>\d)</name>", re.IGNORECASE) + FINAL_ARMOR_NAME_PATTERN = re.compile( + r"<name>(armor|amor|amror)-(?P<color>\w{2,4})-(?P<num>\d)</name>", re.IGNORECASE + ) + ABV_ARMOR_NAME_PATTERN = re.compile(r"<name>a{1,2}(?P<color>\w)(?P<num>\d)</name>", re.IGNORECASE) ABV_RUNES_PATTERN = re.compile(r"<name>r(?P<color>\w)</name>", re.IGNORECASE) ABV_BASE_PATTERN = re.compile(r"<name>b</name>", re.IGNORECASE) ABV_WATCHER_PATTERN = re.compile(r"<name>w</name>", re.IGNORECASE) - ABV_CAR_PATTERN = re.compile(r"<name>[cx]</name>", re.IGNORECASE) - - COLORS_MAP = {"r": "red", "red": "red", "b": "blue", "blue": "blue", "g": "grey", "grey": "grey", "gray": "grey"} + ABV_CAR_PATTERN = re.compile(r"<name>(c|x|robot)</name>", re.IGNORECASE) + + COLORS_MAP = { + "r": "red", + "red": "red", + "b": "blue", + "bleu": "blue", + "blue": "blue", + "g": "grey", + "grey": "grey", + "gray": "grey", + } def __init__(self, save_before: bool): self.save_before = save_before -- GitLab