From e97873a0a1c5dae5646ffd61e3c944521adb4990 Mon Sep 17 00:00:00 2001 From: NatanBagrov Date: Fri, 16 Feb 2024 12:42:07 +0200 Subject: [PATCH] allow flexibility to provide absolute path to annotations --- .../datasets/detection_datasets/coco_format_detection.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/super_gradients/training/datasets/detection_datasets/coco_format_detection.py b/src/super_gradients/training/datasets/detection_datasets/coco_format_detection.py index b24cd4e80c..0e5b7448e5 100644 --- a/src/super_gradients/training/datasets/detection_datasets/coco_format_detection.py +++ b/src/super_gradients/training/datasets/detection_datasets/coco_format_detection.py @@ -44,7 +44,7 @@ def __init__( ): """ :param data_dir: Where the data is stored. - :param json_annotation_file: Name of the coco json file. Path relative to data_dir. + :param json_annotation_file: Name of the coco json file. Path can be either absolute, or relative to data_dir. :param images_dir: Name of the directory that includes all the images. Path relative to data_dir. :param with_crowd: Add the crowd groundtruths to __getitem__ :param class_ids_to_ignore: List of class ids to ignore in the dataset. By default, doesnt ignore any class. @@ -82,7 +82,10 @@ def _setup_data_source(self) -> int: Parse COCO annotation file :return: Number of images in annotation JSON """ - annotation_file_path = os.path.join(self.data_dir, self.json_annotation_file) + if os.path.isabs(self.json_annotation_file): + annotation_file_path = self.json_annotation_file + else: + annotation_file_path = os.path.join(self.data_dir, self.json_annotation_file) if not os.path.exists(annotation_file_path): raise ValueError("Could not find annotation file under " + str(annotation_file_path))