@@ -15,7 +15,8 @@ def get_transforms(config, valid=False):
1515 """
1616 default_size = 224
1717 img_size = config .get ('img_size' , default_size )
18- aug = get_aug_from_config (config .get ('augmentations' , {}).get ('transforms' , []))
18+ config_aug = config .get ('augmentations' , {})
19+ aug = get_aug_from_config (config_aug .get ('transforms' , []))
1920
2021 return A .Compose ([
2122 A .Resize (img_size , img_size , always_apply = True ),
@@ -64,3 +65,36 @@ def get_aug_from_config(config):
6465 return getattr (A , name )(* args , ** config )
6566
6667
68+ # def get_aug_from_config2(config_aug):
69+ # """
70+ # A helper function to create image augmentation pipeline based on a given config_auguration.
71+
72+ # Parameters:
73+ # config_aug (str, list, or dict): A string, list of strings, or dictionary representing the augmentation pipeline.
74+
75+ # Returns:
76+ # aug (albumentations.augmentations.transforms): The constructed augmentation pipeline.
77+ # """
78+ # config_aug = copy.deepcopy(config_aug)
79+
80+ # if config_aug is None:
81+ # return A.NoOp()
82+
83+ # elif isinstance(config_aug, dict):
84+
85+ # compose = config_aug.get("compose", {
86+ # "name": "Sequential",
87+ # "p1": 1})
88+
89+ # transforms_inst = getattr(A, compose["name"])
90+ # transforms_inst(parse_transforms(config_aug.get("transforms", {})), p=compose["p1"])
91+
92+
93+ # def parse_transforms(transforms):
94+ # transforms_list = []
95+ # for trans in transforms:
96+ # name = list(trans.keys())[0]
97+ # params = trans.get(name, {})
98+ # transforms_list.append(getattr(A, name)(**params))
99+
100+ # return transforms_list
0 commit comments