From c01a83782d4edb9d5fdb5a89981b9a298daff506 Mon Sep 17 00:00:00 2001 From: shayaharon Date: Tue, 6 Jun 2023 12:01:47 +0300 Subject: [PATCH 1/7] failure verification --- .circleci/config.yml | 1 - src/super_gradients/training/dataloaders/dataloaders.py | 4 ++-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 00583749bb..a924fd0aab 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -808,7 +808,6 @@ workflows: - recipe_sanity_tests_pose_estimation: context: - slack - <<: *release_tag_filter - recipe_accuracy_tests: context: - slack diff --git a/src/super_gradients/training/dataloaders/dataloaders.py b/src/super_gradients/training/dataloaders/dataloaders.py index 8526bd73b4..0af216b32e 100644 --- a/src/super_gradients/training/dataloaders/dataloaders.py +++ b/src/super_gradients/training/dataloaders/dataloaders.py @@ -3,7 +3,7 @@ import hydra import numpy as np import torch -from omegaconf import OmegaConf, UnsupportedValueType +from omegaconf import OmegaConf from torch.utils.data import BatchSampler, DataLoader, TensorDataset, RandomSampler import super_gradients @@ -109,7 +109,7 @@ def _process_dataset_params(cfg, dataset_params, train: bool): cfg.val_dataset_params = OmegaConf.merge(cfg.val_dataset_params, dataset_params) return hydra.utils.instantiate(cfg.val_dataset_params) - except UnsupportedValueType: + except Exception: # noqa: F401 # This is somewhat ugly fallback for the case when the user provides overrides for the dataset params # that contains non-primitive types (E.g instantiated transforms). # In this case interpolation is not possible so we just override the default params with the user-provided ones. From 34cd6f64b791657761d7d0e23c8dbf5735deab43 Mon Sep 17 00:00:00 2001 From: shayaharon Date: Tue, 6 Jun 2023 14:38:48 +0300 Subject: [PATCH 2/7] added set_struct before merge --- src/super_gradients/training/dataloaders/dataloaders.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/super_gradients/training/dataloaders/dataloaders.py b/src/super_gradients/training/dataloaders/dataloaders.py index 0af216b32e..059772b8f3 100644 --- a/src/super_gradients/training/dataloaders/dataloaders.py +++ b/src/super_gradients/training/dataloaders/dataloaders.py @@ -3,7 +3,7 @@ import hydra import numpy as np import torch -from omegaconf import OmegaConf +from omegaconf import OmegaConf, UnsupportedValueType from torch.utils.data import BatchSampler, DataLoader, TensorDataset, RandomSampler import super_gradients @@ -103,13 +103,15 @@ def _process_dataset_params(cfg, dataset_params, train: bool): # For some reason this breaks interpolation :shrug: if train: + OmegaConf.set_struct(dataset_params, False) + OmegaConf.set_struct(cfg.train_dataset_params, False) cfg.train_dataset_params = OmegaConf.merge(cfg.train_dataset_params, dataset_params) return hydra.utils.instantiate(cfg.train_dataset_params) else: cfg.val_dataset_params = OmegaConf.merge(cfg.val_dataset_params, dataset_params) return hydra.utils.instantiate(cfg.val_dataset_params) - except Exception: # noqa: F401 + except UnsupportedValueType: # This is somewhat ugly fallback for the case when the user provides overrides for the dataset params # that contains non-primitive types (E.g instantiated transforms). # In this case interpolation is not possible so we just override the default params with the user-provided ones. From 9f09c77ace9cdec141e2edc624cec9e84b4c30b0 Mon Sep 17 00:00:00 2001 From: shayaharon Date: Tue, 6 Jun 2023 15:03:50 +0300 Subject: [PATCH 3/7] added set_struct before merge in val too --- src/super_gradients/training/dataloaders/dataloaders.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/super_gradients/training/dataloaders/dataloaders.py b/src/super_gradients/training/dataloaders/dataloaders.py index 059772b8f3..046130cb00 100644 --- a/src/super_gradients/training/dataloaders/dataloaders.py +++ b/src/super_gradients/training/dataloaders/dataloaders.py @@ -101,13 +101,14 @@ def _process_dataset_params(cfg, dataset_params, train: bool): # >>> dataset_params = OmegaConf.merge(default_dataset_params, dataset_params) # >>> return hydra.utils.instantiate(dataset_params) # For some reason this breaks interpolation :shrug: + OmegaConf.set_struct(dataset_params, False) if train: - OmegaConf.set_struct(dataset_params, False) OmegaConf.set_struct(cfg.train_dataset_params, False) cfg.train_dataset_params = OmegaConf.merge(cfg.train_dataset_params, dataset_params) return hydra.utils.instantiate(cfg.train_dataset_params) else: + OmegaConf.set_struct(cfg.val_dataset_params, False) cfg.val_dataset_params = OmegaConf.merge(cfg.val_dataset_params, dataset_params) return hydra.utils.instantiate(cfg.val_dataset_params) From b96e8fa44cc1c56536628096810fbac4b49dc23c Mon Sep 17 00:00:00 2001 From: shayaharon Date: Tue, 6 Jun 2023 15:05:03 +0300 Subject: [PATCH 4/7] release tag filter added back --- .circleci/config.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.circleci/config.yml b/.circleci/config.yml index a924fd0aab..00583749bb 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -808,6 +808,7 @@ workflows: - recipe_sanity_tests_pose_estimation: context: - slack + <<: *release_tag_filter - recipe_accuracy_tests: context: - slack From dea6958bf9577aaa0ff51fa064d8b28b4a57b149 Mon Sep 17 00:00:00 2001 From: shayaharon Date: Tue, 6 Jun 2023 15:34:43 +0300 Subject: [PATCH 5/7] return type fixed --- src/super_gradients/training/utils/checkpoint_utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/super_gradients/training/utils/checkpoint_utils.py b/src/super_gradients/training/utils/checkpoint_utils.py index e322cbb402..217c9c7ae1 100644 --- a/src/super_gradients/training/utils/checkpoint_utils.py +++ b/src/super_gradients/training/utils/checkpoint_utils.py @@ -127,7 +127,7 @@ def copy_ckpt_to_local_folder( return ckpt_file_full_local_path -def read_ckpt_state_dict(ckpt_path: str, device="cpu") -> collections.OrderedDict[str, torch.Tensor]: +def read_ckpt_state_dict(ckpt_path: str, device="cpu") -> collections.OrderedDict: """ Reads a checkpoint state dict from a given path or url From 638fab69f0046098038445dd9eb8405c90167b58 Mon Sep 17 00:00:00 2001 From: shayaharon Date: Tue, 6 Jun 2023 17:14:09 +0300 Subject: [PATCH 6/7] used merge_with with open_dict --- .../training/dataloaders/dataloaders.py | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/src/super_gradients/training/dataloaders/dataloaders.py b/src/super_gradients/training/dataloaders/dataloaders.py index 046130cb00..4e5e6ad236 100644 --- a/src/super_gradients/training/dataloaders/dataloaders.py +++ b/src/super_gradients/training/dataloaders/dataloaders.py @@ -3,7 +3,7 @@ import hydra import numpy as np import torch -from omegaconf import OmegaConf, UnsupportedValueType +from omegaconf import OmegaConf, UnsupportedValueType, DictConfig, open_dict from torch.utils.data import BatchSampler, DataLoader, TensorDataset, RandomSampler import super_gradients @@ -101,15 +101,19 @@ def _process_dataset_params(cfg, dataset_params, train: bool): # >>> dataset_params = OmegaConf.merge(default_dataset_params, dataset_params) # >>> return hydra.utils.instantiate(dataset_params) # For some reason this breaks interpolation :shrug: - OmegaConf.set_struct(dataset_params, False) - + if not isinstance(dataset_params, DictConfig): + dataset_params = OmegaConf.create(dataset_params) if train: - OmegaConf.set_struct(cfg.train_dataset_params, False) - cfg.train_dataset_params = OmegaConf.merge(cfg.train_dataset_params, dataset_params) + train_dataset_params = cfg.train_dataset_params + with open_dict(train_dataset_params): + train_dataset_params.merge_with(dataset_params) + cfg.train_dataset_params = train_dataset_params return hydra.utils.instantiate(cfg.train_dataset_params) else: - OmegaConf.set_struct(cfg.val_dataset_params, False) - cfg.val_dataset_params = OmegaConf.merge(cfg.val_dataset_params, dataset_params) + val_dataset_params = cfg.val_dataset_params + with open_dict(val_dataset_params): + val_dataset_params.merge_with(dataset_params) + cfg.val_dataset_params = val_dataset_params return hydra.utils.instantiate(cfg.val_dataset_params) except UnsupportedValueType: From 45af8c002d89f57eaa5a3c224aa4098d4689834b Mon Sep 17 00:00:00 2001 From: shayaharon Date: Wed, 7 Jun 2023 10:53:13 +0300 Subject: [PATCH 7/7] added test --- tests/unit_tests/detection_dataset_test.py | 40 ++++++++++++++++++++-- 1 file changed, 38 insertions(+), 2 deletions(-) diff --git a/tests/unit_tests/detection_dataset_test.py b/tests/unit_tests/detection_dataset_test.py index fda8597f3d..3103364359 100644 --- a/tests/unit_tests/detection_dataset_test.py +++ b/tests/unit_tests/detection_dataset_test.py @@ -1,13 +1,31 @@ import unittest from pathlib import Path +from typing import Dict -from super_gradients.training.dataloaders import coco2017_train_yolo_nas +from torch.utils.data import DataLoader +from super_gradients.training.dataloaders import coco2017_train_yolo_nas, get_data_loader from super_gradients.training.datasets import COCODetectionDataset from super_gradients.training.datasets.data_formats.default_formats import LABEL_CXCYWH from super_gradients.training.exceptions.dataset_exceptions import DatasetValidationException, ParameterMismatchException from super_gradients.training.transforms import DetectionMosaic, DetectionTargetsFormatTransform, DetectionPaddedRescale +class DummyCOCODetectionDatasetInheritor(COCODetectionDataset): + def __init__(self, json_file: str, subdir: str, dummy_field: int, *args, **kwargs): + super(DummyCOCODetectionDatasetInheritor, self).__init__(json_file=json_file, subdir=subdir, *args, **kwargs) + self.dummy_field = dummy_field + + +def dummy_coco2017_inheritor_train_yolo_nas(dataset_params: Dict = None, dataloader_params: Dict = None) -> DataLoader: + return get_data_loader( + config_name="coco_detection_yolo_nas_dataset_params", + dataset_cls=DummyCOCODetectionDatasetInheritor, + train=True, + dataset_params=dataset_params, + dataloader_params=dataloader_params, + ) + + class DetectionDatasetTest(unittest.TestCase): def setUp(self) -> None: self.mini_coco_data_dir = str(Path(__file__).parent.parent / "data" / "tinycoco") @@ -23,7 +41,6 @@ def test_normal_coco_dataset_creation(self): COCODetectionDataset(**train_dataset_params) def test_coco_dataset_creation_with_wrong_classes(self): - train_dataset_params = { "data_dir": self.mini_coco_data_dir, "subdir": "images/train2017", @@ -88,6 +105,25 @@ def test_coco_detection_dataset_override_with_objects(self): self.assertEqual(batch[0].shape[2], 384) self.assertEqual(batch[0].shape[3], 384) + def test_coco_detection_dataset_override_with_new_entries(self): + train_dataset_params = { + "data_dir": self.mini_coco_data_dir, + "input_dim": 384, + "transforms": [ + DetectionMosaic(input_dim=384), + DetectionPaddedRescale(input_dim=384, max_targets=10), + DetectionTargetsFormatTransform(max_targets=10, output_format=LABEL_CXCYWH), + ], + "dummy_field": 10, + } + train_dataloader_params = {"num_workers": 0} + dataloader = dummy_coco2017_inheritor_train_yolo_nas(dataset_params=train_dataset_params, dataloader_params=train_dataloader_params) + batch = next(iter(dataloader)) + print(batch[0].shape) + self.assertEqual(batch[0].shape[2], 384) + self.assertEqual(batch[0].shape[3], 384) + self.assertEqual(dataloader.dataset.dummy_field, 10) + if __name__ == "__main__": unittest.main()