From 78b3139d1ad4d6f25a38ae02fdbefd959a6ac530 Mon Sep 17 00:00:00 2001 From: Steffen Date: Fri, 19 Mar 2021 18:05:17 +0100 Subject: [PATCH] CCS intergration dataloader --- multi_run.py | 25 ++++++++++++++----------- util/module_mixins.py | 8 +++++++- 2 files changed, 21 insertions(+), 12 deletions(-) diff --git a/multi_run.py b/multi_run.py index d273f91..3e274fd 100644 --- a/multi_run.py +++ b/multi_run.py @@ -10,27 +10,30 @@ import itertools if __name__ == '__main__': # Set new values - hparams_dict = dict(seed=[69], + hparams_dict = dict(seed=range(10), model_name=['VisualTransformer'], data_name=['CCSLibrosaDatamodule'], - batch_size=[5], + batch_size=[50], max_epochs=[200], + variable_length=[False], + sample_segment_len=[40], + sample_hop_len=[15], random_apply_chance=[0.5], # trial.suggest_float('random_apply_chance', 0.1, 0.5, step=0.1), - loudness_ratio=[0.3], # trial.suggest_float('loudness_ratio', 0.0, 0.5, step=0.1), + loudness_ratio=[0], # trial.suggest_float('loudness_ratio', 0.0, 0.5, step=0.1), shift_ratio=[0.3], # trial.suggest_float('shift_ratio', 0.0, 0.5, step=0.1), noise_ratio=[0.3], # trial.suggest_float('noise_ratio', 0.0, 0.5, step=0.1), mask_ratio=[0.3], # trial.suggest_float('mask_ratio', 0.0, 0.5, step=0.1), - lr=[1e-2], # trial.suggest_uniform('lr', 1e-3, 3e-3), + lr=[1e-3], # trial.suggest_uniform('lr', 1e-3, 3e-3), dropout=[0.2], # trial.suggest_float('dropout', 0.0, 0.3, step=0.05), - lat_dim=[48], # 2 ** trial.suggest_int('lat_dim', 1, 5, step=1), - mlp_dim=[30], # 2 ** trial.suggest_int('mlp_dim', 1, 5, step=1), - head_dim=[12], # 2 ** trial.suggest_int('head_dim', 1, 5, step=1), + lat_dim=[32], # 2 ** trial.suggest_int('lat_dim', 1, 5, step=1), + mlp_dim=[16], # 2 ** trial.suggest_int('mlp_dim', 1, 5, step=1), + head_dim=[6], # 2 ** trial.suggest_int('head_dim', 1, 5, step=1), patch_size=[12], # trial.suggest_int('patch_size', 6, 12, step=3), attn_depth=[12], # trial.suggest_int('attn_depth', 2, 14, step=4), - heads=[12], # trial.suggest_int('heads', 2, 16, step=2), + heads=[6], # trial.suggest_int('heads', 2, 16, step=2), scheduler=['LambdaLR'], # trial.suggest_categorical('scheduler', [None, 'LambdaLR']), lr_scheduler_parameter=[0.95], # [0.98], - embedding_size=[64], # trial.suggest_int('embedding_size', 12, 64, step=12), + embedding_size=[30], # trial.suggest_int('embedding_size', 12, 64, step=12), loss=['ce_loss'], sampler=['WeightedRandomSampler'], # rial.suggest_categorical('sampler', [None, 'WeightedRandomSampler']), @@ -41,7 +44,7 @@ if __name__ == '__main__': permutations_dicts = [dict(zip(keys, v)) for v in itertools.product(*values)] for permutations_dict in tqdm(permutations_dicts, total=len(permutations_dicts)): # Parse comandline args, read config and get model - cmd_args, *data_model_seed = parse_comandline_args_add_defaults( + cmd_args, found_data_class, found_model_class, found_seed = parse_comandline_args_add_defaults( '_parameters.ini', overrides=permutations_dict) hparams = dict(**cmd_args) @@ -51,6 +54,6 @@ if __name__ == '__main__': # RUN # --------------------------------------- print(f'Running Loop, parameters are: {permutations_dict}') - run_lightning_loop(hparams, *data_model_seed) + run_lightning_loop(hparams, found_data_class, found_model_class, seed=found_seed) print(f'Done, parameters were: {permutations_dict}') pass diff --git a/util/module_mixins.py b/util/module_mixins.py index d1e1aee..bfcd46d 100644 --- a/util/module_mixins.py +++ b/util/module_mixins.py @@ -59,7 +59,13 @@ class ValMixin: [torch.argmax(x.mean(dim=0)) if x.shape[0] > 1 else torch.argmax(x) for x in sorted_y.values()] ).squeeze() y_one_hot = torch.nn.functional.one_hot(y_max, num_classes=self.params.n_classes).float() - self.metrics.update(y_one_hot, torch.stack(tuple(sorted_batch_y.values())).long()) + target_y = torch.stack(tuple(sorted_batch_y.values())).long() + if y_one_hot.ndim == 1: + y_one_hot = y_one_hot.unsqueeze(0) + if target_y.ndim == 1: + target_y = target_y.unsqueeze(0) + + self.metrics.update(y_one_hot, target_y) val_loss = self.ce_loss(y, batch_y.long())