(
config: Dict[str, Union[str, float, int]])
| 21 | |
| 22 | |
| 23 | def parse_config( |
| 24 | config: Dict[str, Union[str, float, int]]) -> Dict[ |
| 25 | str, Union[str, float, int]]: |
| 26 | valid_dataset = ['CIFAR10', 'CIFAR100', 'ImageNet', 'TinyImageNet'] |
| 27 | if config['dataset'] not in valid_dataset: |
| 28 | raise ValueError( |
| 29 | f"config.yaml: unknown dataset {config['dataset']}. " + |
| 30 | f"Must be one of {valid_dataset}") |
| 31 | valid_models = { |
| 32 | 'densenet201', 'densenet169', 'densenet161', |
| 33 | 'densenet121', 'densenet201Cifar', 'densenet169Cifar', 'densenet161Cifar', |
| 34 | 'densenet121Cifar', 'resnet18', 'resnet18Cifar', 'resnet34', 'resnet34Cifar', 'resnet50', 'resnet50Cifar', |
| 35 | 'resnet101', 'resnet101Cifar', 'resnet152', 'resnet152Cifar', 'swin_t', 'swin_s', 'swin_b', 'swin_l', |
| 36 | 'cct', 'focalnet', 'mobilenetv3', |
| 37 | } |
| 38 | if config['network'] not in valid_models: |
| 39 | raise ValueError( |
| 40 | f"config.yaml: unknown model {config['network']}." + |
| 41 | f"Must be one of {valid_models}") |
| 42 | |
| 43 | config['n_trials'] = smart_string_to_int( |
| 44 | config['n_trials'], |
| 45 | e='config.yaml: n_trials must be an int') |
| 46 | e = 'config.yaml: init_lr must be a float or list of floats' |
| 47 | if not isinstance(config['init_lr'], str): |
| 48 | if isinstance(config['init_lr'], list): |
| 49 | for i, lr in enumerate(config['init_lr']): |
| 50 | if config['init_lr'][i] != 'auto': |
| 51 | config['init_lr'][i] = smart_string_to_float(lr, e=e) |
| 52 | else: |
| 53 | config['init_lr'] = smart_string_to_float(config['init_lr'], e=e) |
| 54 | else: |
| 55 | if config['init_lr'] != 'auto': |
| 56 | raise ValueError(e) |
| 57 | if config['precision'] not in ['fp16', 'fp32']: |
| 58 | raise ValueError("'precision' must be either 'fp16' or 'fp32") |
| 59 | config['max_epochs'] = smart_string_to_int( |
| 60 | config['max_epochs'], |
| 61 | e='config.yaml: max_epochs must be an int') |
| 62 | config['early_stop_threshold'] = smart_string_to_float( |
| 63 | config['early_stop_threshold'], |
| 64 | e='config.yaml: early_stop_threshold must be a float') |
| 65 | config['early_stop_patience'] = smart_string_to_int( |
| 66 | config['early_stop_patience'], |
| 67 | e='config.yaml: early_stop_patience must be an int') |
| 68 | config['mini_batch_size'] = smart_string_to_int( |
| 69 | config['mini_batch_size'], |
| 70 | e='config.yaml: mini_batch_size must be an int') |
| 71 | config['num_workers'] = smart_string_to_int( |
| 72 | config['num_workers'], |
| 73 | e='config.yaml: num_works must be an int') |
| 74 | if config['loss'] != 'cross_entropy': |
| 75 | raise ValueError('config.yaml: loss must be cross_entropy') |
| 76 | for k, v in config['optimizer_kwargs'].items(): |
| 77 | if isinstance(v, list): |
| 78 | for i, val in enumerate(v): |
| 79 | config['optimizer_kwargs'][k][i] = smart_string_to_float(val) |
| 80 | else: |
no test coverage detected