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

#1000 Cityscapes AutoLabelling dataset

Merged
Ghost merged 1 commits into Deci-AI:master from deci-ai:feature/ALG-1373_cityscapes_auto_label
@@ -403,6 +403,7 @@ class Datasets:
     PASCAL_AUG_2012_SEGMENTATION_DATASET = "PascalAUG2012SegmentationDataSet"
     PASCAL_AUG_2012_SEGMENTATION_DATASET = "PascalAUG2012SegmentationDataSet"
     PASCAL_VOC_2012_SEGMENTATION_DATASET = "PascalVOC2012SegmentationDataSet"
     PASCAL_VOC_2012_SEGMENTATION_DATASET = "PascalVOC2012SegmentationDataSet"
     CITYSCAPES_DATASET = "CityscapesDataset"
     CITYSCAPES_DATASET = "CityscapesDataset"
+    CITYSCAPES_CONCAT_DATASET = "CityscapesConcatDataset"
     MAPILLARY_DATASET = "MapillaryDataset"
     MAPILLARY_DATASET = "MapillaryDataset"
     SUPERVISELY_PERSONS_DATASET = "SuperviselyPersonsDataset"
     SUPERVISELY_PERSONS_DATASET = "SuperviselyPersonsDataset"
     PASCAL_VOC_AND_AUG_UNIFIED_DATASET = "PascalVOCAndAUGUnifiedDataset"
     PASCAL_VOC_AND_AUG_UNIFIED_DATASET = "PascalVOCAndAUGUnifiedDataset"
Discard
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
  1. # Instructions:
  2. # 0. Make sure that the data is stored in dataset_params.dataset_dir or add "dataset_params.data_dir=<PATH-TO-DATASET>" at the end of the command below (feel free to check ReadMe)
  3. # 1. Prepare the Cityscapes AutoLabelling dataset as described in `src/super_gradients/training/datasets/Dataset_Setup_Instructions.md`.
  4. # 2. Move to the project root (where you will find the ReadMe and src folder)
  5. # 3. Run the command:
  6. # DDRNet39: python -m super_gradients.train_from_recipe --config-name=cityscapes_ddrnet architecture=ddrnet_39
  7. # Note: add "checkpoint_params.checkpoint_path=<ddrnet39-backbone-pretrained-path>" to use pretrained backbone
  8. #
  9. # Validation mIoU - Cityscapes, training time:
  10. # DDRNet39: input-size: [1024, 2048] mIoU: 85.17 4 X RTX A5000, 38 H
  11. #
  12. # Pretrained checkpoints:
  13. # Backbones- downloaded from the author's official repo.
  14. # https://deci-pretrained-models.s3.amazonaws.com/ddrnet/imagenet_pt_backbones/ddrnet39_bb_imagenet.pth
  15. #
  16. # Network checkpoints:
  17. # DDRNet39: https://sghub.deci.ai/models/ddrnet_39_cityscapes.pth
  18. #
  19. # Learning rate and batch size parameters, using 4 RTX A5000 with DDP:
  20. # DDRNet39: input-size: [1024, 1024] initial_lr: 0.0075 batch-size: 6 * 4gpus = 24
  21. #
  22. # Comments:
  23. # * Pretrained backbones were used.
  24. defaults:
  25. - training_hyperparams: cityscapes_default_train_params
  26. - dataset_params: cityscapes_al_dataset_params
  27. - checkpoint_params: default_checkpoint_params
  28. - _self_
  29. - variable_setup
  30. architecture: ddrnet_39
  31. dataset_params:
  32. train_dataloader_params:
  33. batch_size: 6
  34. val_dataloader_params:
  35. batch_size: 3
  36. train_dataset_params:
  37. transforms:
  38. - SegColorJitter:
  39. brightness: 0.5
  40. contrast: 0.5
  41. saturation: 0.5
  42. - SegRandomFlip:
  43. prob: 0.5
  44. - SegRandomRescale:
  45. scales: [ 0.5, 2. ]
  46. - SegPadShortToCropSize:
  47. crop_size: [ 1024, 1024 ]
  48. fill_mask: 19
  49. - SegCropImageAndMask:
  50. crop_size: [ 1024, 1024 ]
  51. mode: random
  52. training_hyperparams:
  53. max_epochs: 200
  54. initial_lr: 0.0075 # batch size 24
  55. loss:
  56. dice_ce_edge_loss:
  57. num_classes: 19
  58. ignore_index: 19
  59. num_aux_heads: 1
  60. num_detail_heads: 0
  61. weights: [ 1., 0.4 ]
  62. dice_ce_weights: [ 1., 1. ]
  63. ce_edge_weights: [ .5, .5 ]
  64. edge_kernel: 5
  65. sync_bn: True
  66. arch_params:
  67. num_classes: 19
  68. use_aux_heads: True
  69. load_checkpoint: False
  70. checkpoint_params:
  71. load_checkpoint: ${load_checkpoint}
  72. checkpoint_path: ???
  73. load_backbone: True
  74. strict_load: no_key_matching
  75. experiment_name: ${architecture}_cityscapes_al
  76. multi_gpu: DDP
  77. num_gpus: 4
Discard
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
  1. # Cityscapes AutoLabelled dataset were introduced by NVIDIA research group.
  2. # paper:
  3. # Hierarchical Multi-Scale Attention for Semantic Segmentation", https://arxiv.org/abs/2005.10821
  4. # Official repo:
  5. # https://github.com/NVIDIA/semantic-segmentation
  6. #
  7. # AutoLabelled refer to the refinement of the Cityscapes coarse data and pseudo labels generation using their suggested
  8. # Hierarchical multi-scale attention model.
  9. #
  10. # For dataset preparation instruction please follow:
  11. # https://github.com/Deci-AI/super-gradients/blob/master/src/super_gradients/training/datasets/Dataset_Setup_Instructions.md
  12. train_dataset_params:
  13. root_dir: /data/cityscapes
  14. labels_csv_path: lists/labels.csv
  15. list_files:
  16. - lists/train.lst
  17. - lists/auto_labelling.lst
  18. cache_labels: False
  19. cache_images: False
  20. transforms:
  21. val_dataset_params:
  22. root_dir: /data/cityscapes
  23. list_file: lists/val.lst
  24. labels_csv_path: lists/labels.csv
  25. cache_labels: False
  26. cache_images: False
  27. transforms:
  28. train_dataloader_params:
  29. dataset: CityscapesConcatDataset
  30. shuffle: True
  31. batch_size: 8
  32. num_workers: 8
  33. drop_last: True # drop the last incomplete batch, if dataset size is not divisible by the batch size
  34. val_dataloader_params:
  35. dataset: CityscapesDataset
  36. batch_size: 8
  37. num_workers: 8
  38. drop_last: False
Discard
@@ -203,7 +203,8 @@ data_set = YoloDarknetFormatDetectionDataset(data_dir='<path-to>/data_dir', imag
       ├── test.lst
       ├── test.lst
       ├── train.lst
       ├── train.lst
       ├── trainval.lst
       ├── trainval.lst
-      └── val.lst
+      ├── val.lst
+      └── auto_labelling.lst
 ```
 ```
 
 
 2. c. Move Metadata folder to the Cityscapes folder
 2. c. Move Metadata folder to the Cityscapes folder
@@ -224,6 +225,45 @@ from super_gradients.training.datasets import CityscapesDataset
 train_set = CityscapesDataset(root_dir='.../root_dir', list_file='lists/train.lst', labels_csv_path='lists/labels.csv', ...)
 train_set = CityscapesDataset(root_dir='.../root_dir', list_file='lists/train.lst', labels_csv_path='lists/labels.csv', ...)
 ```
 ```
 
 
+4. AutoLabelling dataset [Optional]
+
+Cityscapes AutoLabelled dataset were introduced by NVIDIA research group
+in the [paper](https://arxiv.org/abs/2005.10821):
+"Hierarchical Multi-Scale Attention for Semantic Segmentation".
+
+AutoLabelled refer to the refinement of the Cityscapes coarse data and pseudo
+labels generation using their suggested Hierarchical multi-scale attention model.
+
+* To download the AutoLabelled labels please refer to the original 
+[repo](https://github.com/NVIDIA/semantic-segmentation#downloadprepare-data).
+Unzip and rename the folder to `AutoLabelling` as described bellow.
+
+* Download the coarse RGB images from cityscapes official site, 
+leftImg8bit_train_extra: https://www.cityscapes-dataset.com/file-handling/?packageID=4
+
+```
+  root_dir (in recipe default to /data/cityscapes)
+      ├─── gtFine
+      │       ├── test
+      │       │     └── ...
+      │       ├─── train
+      │       │     └── ...
+      │       └─── val
+      │             └── ...
+      ├─── leftImg8bit
+      │       ├── test
+      │       │     └── ...
+      │       ├─── train
+      │       │     └── ...
+      │       └─── val
+      │             └── ...
+      ├─── AutoLabelling
+      │       └─── train_extra
+      │             └── ...
+      └─── leftImg8bit
+              └─── train_extra
+                    └── ...
+```
 
 
  </details>
  </details>
 
 
Discard
@@ -16,7 +16,7 @@ from super_gradients.training.datasets.segmentation_datasets.pascal_voc_segmenta
     PascalAUG2012SegmentationDataSet,
     PascalAUG2012SegmentationDataSet,
     PascalVOCAndAUGUnifiedDataset,
     PascalVOCAndAUGUnifiedDataset,
 )
 )
-from super_gradients.training.datasets.segmentation_datasets.cityscape_segmentation import CityscapesDataset
+from super_gradients.training.datasets.segmentation_datasets.cityscape_segmentation import CityscapesDataset, CityscapesConcatDataset
 from super_gradients.training.datasets.segmentation_datasets.coco_segmentation import CoCoSegmentationDataSet
 from super_gradients.training.datasets.segmentation_datasets.coco_segmentation import CoCoSegmentationDataSet
 from super_gradients.training.datasets.segmentation_datasets.supervisely_persons_segmentation import SuperviselyPersonsDataset
 from super_gradients.training.datasets.segmentation_datasets.supervisely_persons_segmentation import SuperviselyPersonsDataset
 from super_gradients.training.datasets.pose_estimation_datasets import COCOKeypointsDataset
 from super_gradients.training.datasets.pose_estimation_datasets import COCOKeypointsDataset
@@ -30,6 +30,7 @@ __all__ = [
     "DirectoryDataSet",
     "DirectoryDataSet",
     "SegmentationDataSet",
     "SegmentationDataSet",
     "CityscapesDataset",
     "CityscapesDataset",
+    "CityscapesConcatDataset",
     "PascalVOC2012SegmentationDataSet",
     "PascalVOC2012SegmentationDataSet",
     "PascalAUG2012SegmentationDataSet",
     "PascalAUG2012SegmentationDataSet",
     "PascalVOCAndAUGUnifiedDataset",
     "PascalVOCAndAUGUnifiedDataset",
Discard
@@ -1,4 +1,4 @@
-from super_gradients.training.datasets.segmentation_datasets.cityscape_segmentation import CityscapesDataset
+from super_gradients.training.datasets.segmentation_datasets.cityscape_segmentation import CityscapesDataset, CityscapesConcatDataset
 from super_gradients.training.datasets.segmentation_datasets.coco_segmentation import CoCoSegmentationDataSet
 from super_gradients.training.datasets.segmentation_datasets.coco_segmentation import CoCoSegmentationDataSet
 from super_gradients.training.datasets.segmentation_datasets.mapillary_dataset import MapillaryDataset
 from super_gradients.training.datasets.segmentation_datasets.mapillary_dataset import MapillaryDataset
 from super_gradients.training.datasets.segmentation_datasets.pascal_voc_segmentation import (
 from super_gradients.training.datasets.segmentation_datasets.pascal_voc_segmentation import (
@@ -15,6 +15,7 @@ __all__ = [
     "PascalAUG2012SegmentationDataSet",
     "PascalAUG2012SegmentationDataSet",
     "PascalVOC2012SegmentationDataSet",
     "PascalVOC2012SegmentationDataSet",
     "CityscapesDataset",
     "CityscapesDataset",
+    "CityscapesConcatDataset",
     "SuperviselyPersonsDataset",
     "SuperviselyPersonsDataset",
     "PascalVOCAndAUGUnifiedDataset",
     "PascalVOCAndAUGUnifiedDataset",
     "MapillaryDataset",
     "MapillaryDataset",
Discard
@@ -1,14 +1,14 @@
+from typing import List
 import os
 import os
 import cv2
 import cv2
 import numpy as np
 import numpy as np
 from PIL import Image, ImageColor
 from PIL import Image, ImageColor
+from torch.utils.data import ConcatDataset
 
 
 from super_gradients.common.object_names import Datasets
 from super_gradients.common.object_names import Datasets
 from super_gradients.common.registry.registry import register_dataset
 from super_gradients.common.registry.registry import register_dataset
 from super_gradients.training.datasets.segmentation_datasets.segmentation_dataset import SegmentationDataSet
 from super_gradients.training.datasets.segmentation_datasets.segmentation_dataset import SegmentationDataSet
 
 
-# TODO - ADD COARSE DATA - right now cityscapes dataset includes fine annotations. It's optional to use extra coarse
-#  annotations.
 
 
 # label for background and labels to ignore during training and evaluation.
 # label for background and labels to ignore during training and evaluation.
 CITYSCAPES_IGNORE_LABEL = 19
 CITYSCAPES_IGNORE_LABEL = 19
@@ -75,7 +75,7 @@ class CityscapesDataset(SegmentationDataSet):
 
 
     def __init__(self, root_dir: str, list_file: str, labels_csv_path: str, **kwargs):
     def __init__(self, root_dir: str, list_file: str, labels_csv_path: str, **kwargs):
         """
         """
-        :param root:            Absolute path to root directory of the dataset.
+        :param root_dir:        Absolute path to root directory of the dataset.
         :param list_file:       List file that contains names of images to load, line format: <image_path> <label_path>. The path is relative to root.
         :param list_file:       List file that contains names of images to load, line format: <image_path> <label_path>. The path is relative to root.
         :param labels_csv_path: Path to csv file, with labels metadata and mapping. The path is relative to root.
         :param labels_csv_path: Path to csv file, with labels metadata and mapping. The path is relative to root.
         :param kwargs:          Any hyper params required for the dataset, i.e img_size, crop_size, cache_images
         :param kwargs:          Any hyper params required for the dataset, i.e img_size, crop_size, cache_images
@@ -148,3 +148,39 @@ class CityscapesDataset(SegmentationDataSet):
         out = SegmentationDataSet.target_transform(target)
         out = SegmentationDataSet.target_transform(target)
         out[out == 255] = CITYSCAPES_IGNORE_LABEL
         out[out == 255] = CITYSCAPES_IGNORE_LABEL
         return out
         return out
+
+
+@register_dataset(Datasets.CITYSCAPES_CONCAT_DATASET)
+class CityscapesConcatDataset(ConcatDataset):
+    """
+    Support building a Cityscapes dataset which includes multiple group of samples from several list files.
+    i.e to initiate a trainval dataset:
+    >>> trainval_set = CityscapesConcatDataset(
+    >>>    root_dir='/data', list_files=['lists/train.lst', 'lists/val.lst'], labels_csv_path='lists/labels.csv', ...
+    >>> )
+
+    i.e to initiate a combination of the train-set with AutoLabelling-set:
+    >>> train_al_set = CityscapesConcatDataset(
+    >>>    root_dir='/data', list_files=['lists/train.lst', 'lists/auto_labelling.lst'], labels_csv_path='lists/labels.csv', ...
+    >>> )
+    """
+
+    def __init__(self, root_dir: str, list_files: List[str], labels_csv_path: str, **kwargs):
+        """
+        :param root_dir:        Absolute path to root directory of the dataset.
+        :param list_files:      List of list files that contains names of images to load,
+                                line format: <image_path> <label_path>. The path is relative to root.
+        :param labels_csv_path: Path to csv file, with labels metadata and mapping. The path is relative to root.
+        :param kwargs:          Any hyper params required for the dataset, i.e img_size, crop_size, cache_images
+        """
+        super().__init__(
+            datasets=[
+                CityscapesDataset(
+                    root_dir=root_dir,
+                    list_file=list_file,
+                    labels_csv_path=labels_csv_path,
+                    **kwargs,
+                )
+                for list_file in list_files
+            ]
+        )
Discard
@@ -1,8 +1,9 @@
 import unittest
 import unittest
+from typing import Type
 
 
 import pkg_resources
 import pkg_resources
 import yaml
 import yaml
-from torch.utils.data import DataLoader
+from torch.utils.data import DataLoader, Dataset
 
 
 from super_gradients.training.dataloaders.dataloaders import (
 from super_gradients.training.dataloaders.dataloaders import (
     cityscapes_train,
     cityscapes_train,
@@ -15,30 +16,46 @@ from super_gradients.training.dataloaders.dataloaders import (
     cityscapes_regseg48_train,
     cityscapes_regseg48_train,
     cityscapes_ddrnet_val,
     cityscapes_ddrnet_val,
     cityscapes_stdc_seg75_train,
     cityscapes_stdc_seg75_train,
+    get,
 )
 )
-from super_gradients.training.datasets.segmentation_datasets.cityscape_segmentation import CityscapesDataset
+from super_gradients.training.datasets.segmentation_datasets.cityscape_segmentation import CityscapesDataset, CityscapesConcatDataset
 
 
 
 
 class CityscapesDatasetTest(unittest.TestCase):
 class CityscapesDatasetTest(unittest.TestCase):
-    def setUp(self) -> None:
+    def _cityscapes_dataset_params(self):
         default_config_path = pkg_resources.resource_filename("super_gradients.recipes", "dataset_params/cityscapes_dataset_params.yaml")
         default_config_path = pkg_resources.resource_filename("super_gradients.recipes", "dataset_params/cityscapes_dataset_params.yaml")
         with open(default_config_path, "r") as file:
         with open(default_config_path, "r") as file:
-            self.recipe = yaml.safe_load(file)
+            dataset_params = yaml.safe_load(file)
+        return dataset_params
 
 
-    def dataloader_tester(self, dl: DataLoader):
+    def _cityscapes_al_dataset_params(self):
+        default_config_path = pkg_resources.resource_filename("super_gradients.recipes", "dataset_params/cityscapes_al_dataset_params.yaml")
+        with open(default_config_path, "r") as file:
+            dataset_params = yaml.safe_load(file)
+        return dataset_params
+
+    def dataloader_tester(self, dl: DataLoader, dataset_cls: Type[Dataset] = CityscapesDataset):
         self.assertTrue(isinstance(dl, DataLoader))
         self.assertTrue(isinstance(dl, DataLoader))
-        self.assertTrue(isinstance(dl.dataset, CityscapesDataset))
+        self.assertTrue(isinstance(dl.dataset, dataset_cls))
         it = iter(dl)
         it = iter(dl)
         for _ in range(10):
         for _ in range(10):
             next(it)
             next(it)
 
 
     def test_train_dataset_creation(self):
     def test_train_dataset_creation(self):
-        train_dataset = CityscapesDataset(**self.recipe["train_dataset_params"])
+        dataset_params = self._cityscapes_dataset_params()
+        train_dataset = CityscapesDataset(**dataset_params["train_dataset_params"])
+        for i in range(10):
+            image, mask = train_dataset[i]
+
+    def test_al_train_dataset_creation(self):
+        dataset_params = self._cityscapes_al_dataset_params()
+        train_dataset = CityscapesConcatDataset(**dataset_params["train_dataset_params"])
         for i in range(10):
         for i in range(10):
             image, mask = train_dataset[i]
             image, mask = train_dataset[i]
 
 
     def test_val_dataset_creation(self):
     def test_val_dataset_creation(self):
-        val_dataset = CityscapesDataset(**self.recipe["val_dataset_params"])
+        dataset_params = self._cityscapes_dataset_params()
+        val_dataset = CityscapesDataset(**dataset_params["val_dataset_params"])
         for i in range(10):
         for i in range(10):
             image, mask = val_dataset[i]
             image, mask = val_dataset[i]
 
 
@@ -46,6 +63,16 @@ class CityscapesDatasetTest(unittest.TestCase):
         dl_train = cityscapes_train()
         dl_train = cityscapes_train()
         self.dataloader_tester(dl_train)
         self.dataloader_tester(dl_train)
 
 
+    def test_cityscapes_al_train_dataloader(self):
+        dataset_params = self._cityscapes_al_dataset_params()
+        # Same dataloader creation as in `train_from_recipe`
+        dl_train = get(
+            name=None,
+            dataset_params=dataset_params["train_dataset_params"],
+            dataloader_params=dataset_params["train_dataloader_params"],
+        )
+        self.dataloader_tester(dl_train, dataset_cls=CityscapesConcatDataset)
+
     def test_cityscapes_val_dataloader(self):
     def test_cityscapes_val_dataloader(self):
         dl_val = cityscapes_val()
         dl_val = cityscapes_val()
         self.dataloader_tester(dl_val)
         self.dataloader_tester(dl_val)
Discard