Register
Login
Resources
Docs Blog Datasets Glossary Case Studies Tutorials & Webinars
Product
Data Engine LLMs Platform Enterprise
Pricing Explore
Connect to our Discord channel

#556 Improve PascalVOC detection error msg

Merged
Ghost merged 1 commits into Deci-AI:master from deci-ai:hotfix/SG-000-improve_dectionDS_not_found
@@ -102,7 +102,7 @@ class DetectionDataset(Dataset):
 
 
         self.data_dir = data_dir
         self.data_dir = data_dir
         if not Path(data_dir).exists():
         if not Path(data_dir).exists():
-            raise FileNotFoundError(f"Please make sure to download the data in the data directory ({self.data_dir}).")
+            raise FileNotFoundError(f"data_dir={data_dir} not found. Please make sure that data_dir points toward your dataset.")
 
 
         # Number of images that are avalaible(regardless of ignored images)
         # Number of images that are avalaible(regardless of ignored images)
         self.n_available_samples = self._setup_data_source()
         self.n_available_samples = self._setup_data_source()
Discard
@@ -45,12 +45,12 @@ class PascalVOCDetectionDataset(DetectionDataset):
 
 
         :return: List of tuples made of (img_path,target_path)
         :return: List of tuples made of (img_path,target_path)
         """
         """
-        img_files_folder = self.data_dir + self.images_sub_directory
+        img_files_folder = os.path.join(self.data_dir, self.images_sub_directory)
         if not Path(img_files_folder).exists():
         if not Path(img_files_folder).exists():
             raise FileNotFoundError(
             raise FileNotFoundError(
-                f"{self.data_dir} does not include {self.images_sub_directory}. "
-                f"Please make sure that f{self.data_dir} refers to PascalVOC dataset and that "
-                "it was downloaded using PascalVOCDetectionDataSetV2.download()"
+                f"{img_files_folder} not found...\n"
+                f"Please make sure that f{self.data_dir} points toward your PascalVOC dataset folder.\n"
+                f"If you don't have it locally, you can set PascalVOCDetectionDataset(..., download=True)"
             )
             )
 
 
         img_files = glob.glob(img_files_folder + "*.jpg")
         img_files = glob.glob(img_files_folder + "*.jpg")
Discard
@@ -1,3 +1,4 @@
+import tempfile
 import unittest
 import unittest
 
 
 import super_gradients
 import super_gradients
@@ -13,59 +14,56 @@ class DatasetIntegrationTest(unittest.TestCase):
         self.batch_size = 64
         self.batch_size = 64
         self.max_samples_per_plot = 16
         self.max_samples_per_plot = 16
         self.n_plot = 1
         self.n_plot = 1
-        transforms = [DetectionMosaic(input_dim=(640, 640), prob=0.8),
-                      DetectionPaddedRescale(input_dim=(640, 640), max_targets=120),
-                      DetectionTargetsFormatTransform(output_format=DetectionTargetsFormat.XYXY_LABEL)]
-
-        self.pascal_class_inclusion_lists = [['aeroplane', 'bicycle'],
-                                             ['bird', 'boat', 'bottle', 'bus'],
-                                             ['pottedplant'],
-                                             ['person']]
-        self.pascal_base_config = dict(data_dir='/home/louis.dupont/data/pascal_unified_coco_format/',
-                                       images_sub_directory='images/train2012/',
-                                       input_dim=(640, 640),
-                                       transforms=transforms)
-
-        self.coco_class_inclusion_lists = [['airplane', 'bicycle'],
-                                           ['bird', 'boat', 'bottle', 'bus'],
-                                           ['potted plant'],
-                                           ['person']]
-        self.dataset_coco_base_config = dict(data_dir="/data/coco",
-                                             subdir="images/val2017",
-                                             json_file="instances_val2017.json",
-                                             input_dim=(640, 640),
-                                             transforms=transforms,)
+        transforms = [
+            DetectionMosaic(input_dim=(640, 640), prob=0.8),
+            DetectionPaddedRescale(input_dim=(640, 640), max_targets=120),
+            DetectionTargetsFormatTransform(output_format=DetectionTargetsFormat.XYXY_LABEL),
+        ]
+
+        self.test_dir = tempfile.TemporaryDirectory().name
+        PascalVOCDetectionDataset.download(self.test_dir)
+        self.pascal_class_inclusion_lists = [["aeroplane", "bicycle"], ["bird", "boat", "bottle", "bus"], ["pottedplant"], ["person"]]
+        self.pascal_base_config = dict(data_dir=self.test_dir, images_sub_directory="images/train2012/", input_dim=(640, 640), transforms=transforms)
+
+        self.coco_class_inclusion_lists = [["airplane", "bicycle"], ["bird", "boat", "bottle", "bus"], ["potted plant"], ["person"]]
+        self.dataset_coco_base_config = dict(
+            data_dir="/data/coco",
+            subdir="images/val2017",
+            json_file="instances_val2017.json",
+            input_dim=(640, 640),
+            transforms=transforms,
+        )
 
 
     def test_multiple_pascal_dataset_subclass_before_transforms(self):
     def test_multiple_pascal_dataset_subclass_before_transforms(self):
         """Run test_pascal_dataset_subclass on multiple inclusion lists"""
         """Run test_pascal_dataset_subclass on multiple inclusion lists"""
         for class_inclusion_list in self.pascal_class_inclusion_lists:
         for class_inclusion_list in self.pascal_class_inclusion_lists:
-            dataset = PascalVOCDetectionDataset(class_inclusion_list=class_inclusion_list,
-                                                max_num_samples=self.max_samples_per_plot * self.n_plot,
-                                                **self.pascal_base_config)
+            dataset = PascalVOCDetectionDataset(
+                class_inclusion_list=class_inclusion_list, max_num_samples=self.max_samples_per_plot * self.n_plot, **self.pascal_base_config
+            )
             dataset.plot(max_samples_per_plot=self.max_samples_per_plot, n_plots=self.n_plot, plot_transformed_data=False)
             dataset.plot(max_samples_per_plot=self.max_samples_per_plot, n_plots=self.n_plot, plot_transformed_data=False)
 
 
     def test_multiple_pascal_dataset_subclass_after_transforms(self):
     def test_multiple_pascal_dataset_subclass_after_transforms(self):
         """Run test_pascal_dataset_subclass on multiple inclusion lists"""
         """Run test_pascal_dataset_subclass on multiple inclusion lists"""
         for class_inclusion_list in self.pascal_class_inclusion_lists:
         for class_inclusion_list in self.pascal_class_inclusion_lists:
-            dataset = PascalVOCDetectionDataset(class_inclusion_list=class_inclusion_list,
-                                                max_num_samples=self.max_samples_per_plot * self.n_plot,
-                                                **self.pascal_base_config)
+            dataset = PascalVOCDetectionDataset(
+                class_inclusion_list=class_inclusion_list, max_num_samples=self.max_samples_per_plot * self.n_plot, **self.pascal_base_config
+            )
             dataset.plot(max_samples_per_plot=self.max_samples_per_plot, n_plots=self.n_plot, plot_transformed_data=True)
             dataset.plot(max_samples_per_plot=self.max_samples_per_plot, n_plots=self.n_plot, plot_transformed_data=True)
 
 
     def test_multiple_coco_dataset_subclass_before_transforms(self):
     def test_multiple_coco_dataset_subclass_before_transforms(self):
         """Check subclass on multiple inclusions before transform"""
         """Check subclass on multiple inclusions before transform"""
         for class_inclusion_list in self.coco_class_inclusion_lists:
         for class_inclusion_list in self.coco_class_inclusion_lists:
-            dataset = COCODetectionDataset(class_inclusion_list=class_inclusion_list,
-                                           max_num_samples=self.max_samples_per_plot * self.n_plot,
-                                           **self.dataset_coco_base_config)
+            dataset = COCODetectionDataset(
+                class_inclusion_list=class_inclusion_list, max_num_samples=self.max_samples_per_plot * self.n_plot, **self.dataset_coco_base_config
+            )
             dataset.plot(max_samples_per_plot=self.max_samples_per_plot, n_plots=self.n_plot, plot_transformed_data=False)
             dataset.plot(max_samples_per_plot=self.max_samples_per_plot, n_plots=self.n_plot, plot_transformed_data=False)
 
 
     def test_multiple_coco_dataset_subclass_after_transforms(self):
     def test_multiple_coco_dataset_subclass_after_transforms(self):
         """Check subclass on multiple inclusions after transform"""
         """Check subclass on multiple inclusions after transform"""
         for class_inclusion_list in self.coco_class_inclusion_lists:
         for class_inclusion_list in self.coco_class_inclusion_lists:
-            dataset = COCODetectionDataset(class_inclusion_list=class_inclusion_list,
-                                           max_num_samples=self.max_samples_per_plot * self.n_plot,
-                                           **self.dataset_coco_base_config)
+            dataset = COCODetectionDataset(
+                class_inclusion_list=class_inclusion_list, max_num_samples=self.max_samples_per_plot * self.n_plot, **self.dataset_coco_base_config
+            )
             dataset.plot(max_samples_per_plot=self.max_samples_per_plot, n_plots=self.n_plot, plot_transformed_data=True)
             dataset.plot(max_samples_per_plot=self.max_samples_per_plot, n_plots=self.n_plot, plot_transformed_data=True)
 
 
     def test_subclass_non_existing_class(self):
     def test_subclass_non_existing_class(self):
@@ -86,5 +84,5 @@ class DatasetIntegrationTest(unittest.TestCase):
             self.assertEqual(len(sampled_dataset), min(max_num_samples, len(full_dataset)))
             self.assertEqual(len(sampled_dataset), min(max_num_samples, len(full_dataset)))
 
 
 
 
-if __name__ == '__main__':
+if __name__ == "__main__":
     unittest.main()
     unittest.main()
Discard