From 4e7147b674867e60a542975d957e61a1f662052f Mon Sep 17 00:00:00 2001 From: zhong-al <74470739+zhong-al@users.noreply.github.com> Date: Wed, 4 Dec 2024 16:36:56 -0500 Subject: [PATCH 1/2] Add param for cvat2slowfast image output --- README.md | 2 +- src/kabr_tools/cvat2slowfast.py | 12 +++++++++--- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 6228bec..d26f71f 100644 --- a/README.md +++ b/README.md @@ -170,6 +170,6 @@ player --folder path_to_folder [--save] [--imshow] ``` -cvat2slowfast --miniscene path_to_mini_scenes --dataset dataset_name --classes path_to_classes_json [--old2new path_to_old2new_json] +cvat2slowfast --miniscene path_to_mini_scenes --dataset dataset_name --classes path_to_classes_json [--old2new path_to_old2new_json] [--no_images] ``` diff --git a/src/kabr_tools/cvat2slowfast.py b/src/kabr_tools/cvat2slowfast.py index 3255f93..224ac86 100644 --- a/src/kabr_tools/cvat2slowfast.py +++ b/src/kabr_tools/cvat2slowfast.py @@ -11,7 +11,7 @@ def cvat2slowfast(path_to_mini_scenes: str, path_to_new_dataset: str, - label2number: dict, old2new: Optional[dict]) -> None: + label2number: dict, old2new: Optional[dict], no_images: bool) -> None: """ Convert CVAT annotations to the dataset in Charades format. @@ -20,6 +20,7 @@ def cvat2slowfast(path_to_mini_scenes: str, path_to_new_dataset: str, path_to_new_dataset - str. Path to the folder to output dataset files. label2number - dict. Mapping of ethogram labels to integers. old2new - dict [optional]. Mapping of old ethogram labels to new ethogram labels. + no_images - bool. Flag to stop image output. """ if not os.path.exists(path_to_new_dataset): os.makedirs(path_to_new_dataset) @@ -38,7 +39,7 @@ def cvat2slowfast(path_to_mini_scenes: str, path_to_new_dataset: str, charades_df = pd.DataFrame(data=headers) video_id = 1 folder_name = 1 - flag = False + flag = not no_images for i, folder in enumerate(natsorted(os.listdir(path_to_mini_scenes))): if os.path.exists(f"{path_to_mini_scenes}/{folder}/actions"): @@ -178,6 +179,11 @@ def parse_args() -> argparse.Namespace: help="path to old to new ethogram labels json", required=False ) + local_parser.add_argument( + "--no_images", + action="store_true", + help="flag to stop image output" + ) return local_parser.parse_args() @@ -194,7 +200,7 @@ def main() -> None: else: old2new = None - cvat2slowfast(args.miniscene, args.dataset, label2number, old2new) + cvat2slowfast(args.miniscene, args.dataset, label2number, old2new, args.no_images) if __name__ == "__main__": From 9335a0feebea28e77899bdcd2da122d3c0ce19f1 Mon Sep 17 00:00:00 2001 From: zhong-al <74470739+zhong-al@users.noreply.github.com> Date: Tue, 10 Dec 2024 16:13:08 -0500 Subject: [PATCH 2/2] Update arg parse checks --- tests/test_cvat2slowfast.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tests/test_cvat2slowfast.py b/tests/test_cvat2slowfast.py index 674837c..ec98c87 100644 --- a/tests/test_cvat2slowfast.py +++ b/tests/test_cvat2slowfast.py @@ -65,6 +65,7 @@ def test_parse_arg_min(self): # check default argument values self.assertEqual(args.old2new, None) + self.assertTrue(not args.no_images) # run cvat2slowfast run() @@ -75,7 +76,8 @@ def test_parse_arg_full(self): "--miniscene", self.miniscene, "--dataset", self.dataset, "--classes", self.classes, - "--old2new", self.old2new] + "--old2new", self.old2new, + "--no_images"] args = cvat2slowfast.parse_args() # check parsed argument values @@ -83,6 +85,7 @@ def test_parse_arg_full(self): self.assertEqual(args.dataset, self.dataset) self.assertEqual(args.classes, self.classes) self.assertEqual(args.old2new, self.old2new) + self.assertTrue(args.no_images) # run cvat2slowfast run()