-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcomponents_clmr.py
171 lines (151 loc) · 5.31 KB
/
components_clmr.py
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
from copy import deepcopy
###############################################################
########### GENERIC COMPONENTS ###########
###############################################################
# Training parameters
num_epochs = 200
early_stopping_patience = 5
early_stopping_metric = "Accuracy"
epochs_keys_init = 10
batch_size = 64
# Data transforms
mert_data_transform = {
"name": "ResamplerDataTransform",
"args": {
"input_sample_rate": 22050,
"output_sample_rate": 22050,
},
}
mert_data_transform_vocalset = {
"name": "ResamplerDataTransform",
"args": {
"input_sample_rate": 44100,
"output_sample_rate": 22050,
},
}
mert_data_transform_nsynth = {
"name": "ResamplerDataTransform",
"args": {
"input_sample_rate": 16000,
"output_sample_rate": 22050,
},
}
# Train models
train_model = {
"name": "TorchClmrClassIncrementalModel",
"args": {
"encoder": {
"name": "ClmrEncoder",
"args": {
"pretrained": True,
},
},
"frozen_encoder": True,
},
}
train_model_l2center = {
"name": "TorchEmbeddingModel",
"args": {
"encoder": {
"name": "ClmrEncoder",
"args": {
"pretrained": True,
},
},
"frozen_encoder": True,
"average_hidden": False,
},
}
# Trainers
trainer = {
"name": "ClassIncrementalLearningTrainer",
"args": {
"tasks": None,
"num_epochs": num_epochs,
"batch_size": batch_size,
"early_stopping_patience": early_stopping_patience,
"early_stopping_metric": early_stopping_metric,
"train_data_source": None,
"val_data_source": None,
"train_data_transform": mert_data_transform,
"val_data_transform": mert_data_transform,
"train_model": None,
"metrics_config": None,
"experiment_tracker": {"name": "TensorboardExperimentTracker"},
"model_saver": {"name": "MusicGenreClassificationModelSaver"},
"looper": {
"name": "MusicGenreClassificationLooper",
"args": {
"criteria": {"name": "TorchCrossEntropyCriteria"},
"optimizer": {"name": "TorchAdamOptimizer"},
},
},
},
}
oracle_trainer = deepcopy(trainer)
oracle_trainer["name"] = "ContinualLearningTrainer"
oracle_trainer["args"]["tasks"] = ["all"]
continual_learning_trainer = deepcopy(trainer)
continual_learning_trainer["args"]["train_model"] = train_model
## Replay
continual_learning_replay_trainer = deepcopy(trainer)
continual_learning_replay_trainer["name"] = "ReplayContinualLearningTrainer"
continual_learning_replay_trainer["args"]["train_model"] = train_model
continual_learning_replay_trainer["args"]["num_memories"] = 100
## Replay
continual_learning_icarl_trainer = deepcopy(trainer)
continual_learning_icarl_trainer["name"] = "iCaRLContinualLearningTrainer"
continual_learning_icarl_trainer["args"]["train_model"] = train_model
continual_learning_icarl_trainer["args"]["num_memories"] = 100
continual_learning_icarl_trainer["args"]["looper"] = {
"name": "iCaRLMusicGenreClassificationLooper",
"args": {
"criteria": {"name": "TorchCrossEntropyCriteria"},
"optimizer": {"name": "TorchAdamOptimizer"},
"T": 2.0,
},
}
## GEM
continual_learning_gem_trainer = deepcopy(trainer)
continual_learning_gem_trainer["name"] = "GemContinualLearningTrainer"
continual_learning_gem_trainer["args"]["looper"]["name"] = "GemMusicGenreClassificationLooper"
continual_learning_gem_trainer["args"]["looper"]["args"]["optimizer"] = {
"name": "GemOptimizer",
"args": {"num_memories": 100, "memory_strength": 0.5},
}
continual_learning_gem_trainer["args"]["train_model"] = train_model
## EWC
continual_learning_ewc_trainer = deepcopy(trainer)
continual_learning_ewc_trainer["name"] = "EwcContinualLearningTrainer"
continual_learning_ewc_trainer["args"]["looper"]["name"] = "EwcMusicGenreClassificationLooper"
continual_learning_ewc_trainer["args"]["looper"]["args"]["optimizer"] = {
"name": "EwcOptimizer",
"args": {"ewc_lambda": 0.1},
}
continual_learning_ewc_trainer["args"]["train_model"] = train_model
## Embedding center
continual_learning_l2center_trainer = deepcopy(trainer)
continual_learning_l2center_trainer["name"] = "ContinualLearningTrainerL2Center"
continual_learning_l2center_trainer["args"]["train_model"] = train_model_l2center
continual_learning_l2center_trainer["args"]["looper"] = {
"name": "MusicContinualLearningEmbeddingLooper",
}
# Evaluators
evaluator = {
"name": "ClassIncrementalLearningEvaluator",
"args": {
"tasks": None,
"model": train_model,
"model_saver": {"name": "MusicGenreClassificationModelSaver"},
"data_source": None,
"data_transform": mert_data_transform,
"metrics_config": None,
"experiment_tracker": {"name": "DataframeExperimentTracker"},
},
}
oracle_evaluator = deepcopy(evaluator)
oracle_evaluator["name"] = "ClassIncrementalLearningOracleEvaluator"
oracle_evaluator["args"]["tasks"] = ["all"]
continual_learning_evaluator_l2center = deepcopy(evaluator)
continual_learning_evaluator_l2center["args"]["model"] = train_model_l2center
continual_learning_evaluator_l2center["name"] = "ClassIncrementalLearningL2CenterEvaluator"