diff --git a/dcase_models/model/container.py b/dcase_models/model/container.py index f5c2a2f..d2f7642 100644 --- a/dcase_models/model/container.py +++ b/dcase_models/model/container.py @@ -4,8 +4,10 @@ from keras.optimizers import Adam from keras.callbacks import ModelCheckpoint,CSVLogger -from keras.models import model_from_json +from keras.models import model_from_json, Model import keras.backend as K +from keras.layers import Dense, Input + from ..utils.files import save_json from ..utils.metrics import evaluate_metrics @@ -214,3 +216,52 @@ def get_numer_of_parameters(self): trainable_count = int(np.sum([K.count_params(p) for p in set(models.trainable_weights)])) return trainable_count + def fine_tuning(self, layer_where_to_cut, new_number_of_classes=10, new_activation='softmax', + freeze_source_model=True, new_model=None): + """ + Create a new model for fine-tuning. Cut the model in the layer_where_to_cut layer + and add a new fully-connected layer. + + Parameters + ---------- + layer_where_to_cut : str or int + Name (str) of index (int) of the layer where cut the model. This layer + is included in the new model. + + new_number_of_classes : int + Number of units in the new fully-connected layer (number of classes) + + new_activation : str + Activitation of the new fully-connected layer + + freeze_source_model : bool + If True, the source model is set to not be trainable + + new_model : Keras Model + If is not None, this model is add after the cut model. This is useful if you + want add more than a fully-connected layer. + """ + # cut last layer + if type(layer_where_to_cut) == str: + last_layer = self.model.get_layer(layer_where_to_cut) + elif type(layer_where_to_cut) == int: + last_layer = self.model.layers[layer_where_to_cut] + else: + raise AttributeError("layer_where_to_cut has to be str or int type") + model_without_last_layer = Model(self.model.input, last_layer.output, name='source_model') + + # add a new fully connected layer + input_shape = self.model.layers[0].output_shape[1:] + x = Input(shape=input_shape, dtype='float32', name='input') + y = model_without_last_layer(x) + + if new_model is None: + y = Dense(new_number_of_classes, activation=new_activation, name='new_dense_layer')(y) + else: + y = new_model(y) + + # change self.model with fine_tuned model + self.model = Model(x, y) + + # freeze the source model if freeze_source_model is True + self.model.get_layer('source_model').trainable = not freeze_source_model diff --git a/dcase_models/model/models.py b/dcase_models/model/models.py index 849fc81..0a23365 100644 --- a/dcase_models/model/models.py +++ b/dcase_models/model/models.py @@ -65,7 +65,7 @@ def __init__(self, model=None, folder=None, metrics=['accuracy'], n_classes=10, # CONV 2 y = Conv2D(48, filter_size_cnn, padding='valid', activation='relu', name='conv2')(y) - y = MaxPooling2D(pool_size=(2,2), strides=None, padding='valid', name='maxpool2')(y) + y = MaxPooling2D(pool_size=(4,2), strides=None, padding='valid', name='maxpool2')(y) y = BatchNormalization(name='batchnorm2')(y) # CONV 3 diff --git a/tests/SB_CNN/ESC50/fold1/best_weights.hdf5 b/tests/SB_CNN/ESC50/fold1/best_weights.hdf5 new file mode 100644 index 0000000..d5c20c5 Binary files /dev/null and b/tests/SB_CNN/ESC50/fold1/best_weights.hdf5 differ diff --git a/tests/SB_CNN/ESC50/fold1/model.json b/tests/SB_CNN/ESC50/fold1/model.json new file mode 100644 index 0000000..a47e61c --- /dev/null +++ b/tests/SB_CNN/ESC50/fold1/model.json @@ -0,0 +1 @@ +"{\"class_name\": \"Model\", \"config\": {\"name\": \"model_1\", \"layers\": [{\"name\": \"input\", \"class_name\": \"InputLayer\", \"config\": {\"batch_input_shape\": [null, 64, 128], \"dtype\": \"float32\", \"sparse\": false, \"name\": \"input\"}, \"inbound_nodes\": []}, {\"name\": \"source_model\", \"class_name\": \"Model\", \"config\": {\"name\": \"source_model\", \"layers\": [{\"name\": \"input\", \"class_name\": \"InputLayer\", \"config\": {\"batch_input_shape\": [null, 64, 128], \"dtype\": \"float32\", \"sparse\": false, \"name\": \"input\"}, \"inbound_nodes\": []}, {\"name\": \"lambda\", \"class_name\": \"Lambda\", \"config\": {\"name\": \"lambda\", \"trainable\": true, \"function\": [\"4wEAAAAAAAAAAQAAAAQAAABTAAAAcwwAAAB0AKABfABkAaECUwApAk7p/////ykC2gFL2gtleHBh\\nbmRfZGltcykB2gF4qQByBQAAAPofLi4vZGNhc2VfbW9kZWxzL21vZGVsL21vZGVscy5wedoIPGxh\\nbWJkYT44AAAA8wAAAAA=\\n\", null, null], \"function_type\": \"lambda\", \"output_shape\": null, \"output_shape_type\": \"raw\", \"arguments\": {}}, \"inbound_nodes\": [[[\"input\", 0, 0, {}]]]}, {\"name\": \"conv1\", \"class_name\": \"Conv2D\", \"config\": {\"name\": \"conv1\", \"trainable\": true, \"filters\": 24, \"kernel_size\": [5, 5], \"strides\": [1, 1], \"padding\": \"valid\", \"data_format\": \"channels_last\", \"dilation_rate\": [1, 1], \"activation\": \"relu\", \"use_bias\": true, \"kernel_initializer\": {\"class_name\": \"VarianceScaling\", \"config\": {\"scale\": 1.0, \"mode\": \"fan_avg\", \"distribution\": \"uniform\", \"seed\": null}}, \"bias_initializer\": {\"class_name\": \"Zeros\", \"config\": {}}, \"kernel_regularizer\": null, \"bias_regularizer\": null, \"activity_regularizer\": null, \"kernel_constraint\": null, \"bias_constraint\": null}, \"inbound_nodes\": [[[\"lambda\", 0, 0, {}]]]}, {\"name\": \"maxpool1\", \"class_name\": \"MaxPooling2D\", \"config\": {\"name\": \"maxpool1\", \"trainable\": true, \"pool_size\": [2, 2], \"padding\": \"valid\", \"strides\": [2, 2], \"data_format\": \"channels_last\"}, \"inbound_nodes\": [[[\"conv1\", 0, 0, {}]]]}, {\"name\": \"batchnorm1\", \"class_name\": \"BatchNormalization\", \"config\": {\"name\": \"batchnorm1\", \"trainable\": true, \"axis\": -1, \"momentum\": 0.99, \"epsilon\": 0.001, \"center\": true, \"scale\": true, \"beta_initializer\": {\"class_name\": \"Zeros\", \"config\": {}}, \"gamma_initializer\": {\"class_name\": \"Ones\", \"config\": {}}, \"moving_mean_initializer\": {\"class_name\": \"Zeros\", \"config\": {}}, \"moving_variance_initializer\": {\"class_name\": \"Ones\", \"config\": {}}, \"beta_regularizer\": null, \"gamma_regularizer\": null, \"beta_constraint\": null, \"gamma_constraint\": null}, \"inbound_nodes\": [[[\"maxpool1\", 0, 0, {}]]]}, {\"name\": \"conv2\", \"class_name\": \"Conv2D\", \"config\": {\"name\": \"conv2\", \"trainable\": true, \"filters\": 48, \"kernel_size\": [5, 5], \"strides\": [1, 1], \"padding\": \"valid\", \"data_format\": \"channels_last\", \"dilation_rate\": [1, 1], \"activation\": \"relu\", \"use_bias\": true, \"kernel_initializer\": {\"class_name\": \"VarianceScaling\", \"config\": {\"scale\": 1.0, \"mode\": \"fan_avg\", \"distribution\": \"uniform\", \"seed\": null}}, \"bias_initializer\": {\"class_name\": \"Zeros\", \"config\": {}}, \"kernel_regularizer\": null, \"bias_regularizer\": null, \"activity_regularizer\": null, \"kernel_constraint\": null, \"bias_constraint\": null}, \"inbound_nodes\": [[[\"batchnorm1\", 0, 0, {}]]]}, {\"name\": \"maxpool2\", \"class_name\": \"MaxPooling2D\", \"config\": {\"name\": \"maxpool2\", \"trainable\": true, \"pool_size\": [4, 2], \"padding\": \"valid\", \"strides\": [4, 2], \"data_format\": \"channels_last\"}, \"inbound_nodes\": [[[\"conv2\", 0, 0, {}]]]}, {\"name\": \"batchnorm2\", \"class_name\": \"BatchNormalization\", \"config\": {\"name\": \"batchnorm2\", \"trainable\": true, \"axis\": -1, \"momentum\": 0.99, \"epsilon\": 0.001, \"center\": true, \"scale\": true, \"beta_initializer\": {\"class_name\": \"Zeros\", \"config\": {}}, \"gamma_initializer\": {\"class_name\": \"Ones\", \"config\": {}}, \"moving_mean_initializer\": {\"class_name\": \"Zeros\", \"config\": {}}, \"moving_variance_initializer\": {\"class_name\": \"Ones\", \"config\": {}}, \"beta_regularizer\": null, \"gamma_regularizer\": null, \"beta_constraint\": null, \"gamma_constraint\": null}, \"inbound_nodes\": [[[\"maxpool2\", 0, 0, {}]]]}, {\"name\": \"conv3\", \"class_name\": \"Conv2D\", \"config\": {\"name\": \"conv3\", \"trainable\": true, \"filters\": 48, \"kernel_size\": [5, 5], \"strides\": [1, 1], \"padding\": \"valid\", \"data_format\": \"channels_last\", \"dilation_rate\": [1, 1], \"activation\": \"relu\", \"use_bias\": true, \"kernel_initializer\": {\"class_name\": \"VarianceScaling\", \"config\": {\"scale\": 1.0, \"mode\": \"fan_avg\", \"distribution\": \"uniform\", \"seed\": null}}, \"bias_initializer\": {\"class_name\": \"Zeros\", \"config\": {}}, \"kernel_regularizer\": null, \"bias_regularizer\": null, \"activity_regularizer\": null, \"kernel_constraint\": null, \"bias_constraint\": null}, \"inbound_nodes\": [[[\"batchnorm2\", 0, 0, {}]]]}, {\"name\": \"batchnorm3\", \"class_name\": \"BatchNormalization\", \"config\": {\"name\": \"batchnorm3\", \"trainable\": true, \"axis\": -1, \"momentum\": 0.99, \"epsilon\": 0.001, \"center\": true, \"scale\": true, \"beta_initializer\": {\"class_name\": \"Zeros\", \"config\": {}}, \"gamma_initializer\": {\"class_name\": \"Ones\", \"config\": {}}, \"moving_mean_initializer\": {\"class_name\": \"Zeros\", \"config\": {}}, \"moving_variance_initializer\": {\"class_name\": \"Ones\", \"config\": {}}, \"beta_regularizer\": null, \"gamma_regularizer\": null, \"beta_constraint\": null, \"gamma_constraint\": null}, \"inbound_nodes\": [[[\"conv3\", 0, 0, {}]]]}, {\"name\": \"flatten\", \"class_name\": \"Flatten\", \"config\": {\"name\": \"flatten\", \"trainable\": true, \"data_format\": \"channels_last\"}, \"inbound_nodes\": [[[\"batchnorm3\", 0, 0, {}]]]}, {\"name\": \"dropout1\", \"class_name\": \"Dropout\", \"config\": {\"name\": \"dropout1\", \"trainable\": true, \"rate\": 0.5, \"noise_shape\": null, \"seed\": null}, \"inbound_nodes\": [[[\"flatten\", 0, 0, {}]]]}, {\"name\": \"dense1\", \"class_name\": \"Dense\", \"config\": {\"name\": \"dense1\", \"trainable\": true, \"units\": 64, \"activation\": \"relu\", \"use_bias\": true, \"kernel_initializer\": {\"class_name\": \"VarianceScaling\", \"config\": {\"scale\": 1.0, \"mode\": \"fan_avg\", \"distribution\": \"uniform\", \"seed\": null}}, \"bias_initializer\": {\"class_name\": \"Zeros\", \"config\": {}}, \"kernel_regularizer\": {\"class_name\": \"L1L2\", \"config\": {\"l1\": 0.0, \"l2\": 0.0010000000474974513}}, \"bias_regularizer\": {\"class_name\": \"L1L2\", \"config\": {\"l1\": 0.0, \"l2\": 0.0010000000474974513}}, \"activity_regularizer\": null, \"kernel_constraint\": null, \"bias_constraint\": null}, \"inbound_nodes\": [[[\"dropout1\", 0, 0, {}]]]}, {\"name\": \"dropout2\", \"class_name\": \"Dropout\", \"config\": {\"name\": \"dropout2\", \"trainable\": true, \"rate\": 0.5, \"noise_shape\": null, \"seed\": null}, \"inbound_nodes\": [[[\"dense1\", 0, 0, {}]]]}], \"input_layers\": [[\"input\", 0, 0]], \"output_layers\": [[\"dropout2\", 0, 0]]}, \"inbound_nodes\": [[[\"input\", 0, 0, {}]]]}, {\"name\": \"new_dense_layer\", \"class_name\": \"Dense\", \"config\": {\"name\": \"new_dense_layer\", \"trainable\": true, \"units\": 50, \"activation\": \"softmax\", \"use_bias\": true, \"kernel_initializer\": {\"class_name\": \"VarianceScaling\", \"config\": {\"scale\": 1.0, \"mode\": \"fan_avg\", \"distribution\": \"uniform\", \"seed\": null}}, \"bias_initializer\": {\"class_name\": \"Zeros\", \"config\": {}}, \"kernel_regularizer\": null, \"bias_regularizer\": null, \"activity_regularizer\": null, \"kernel_constraint\": null, \"bias_constraint\": null}, \"inbound_nodes\": [[[\"source_model\", 1, 0, {}]]]}], \"input_layers\": [[\"input\", 0, 0]], \"output_layers\": [[\"new_dense_layer\", 0, 0]]}, \"keras_version\": \"2.2.4\", \"backend\": \"tensorflow\"}" \ No newline at end of file diff --git a/tests/SB_CNN/ESC50/fold1/training.log b/tests/SB_CNN/ESC50/fold1/training.log new file mode 100644 index 0000000..0070618 --- /dev/null +++ b/tests/SB_CNN/ESC50/fold1/training.log @@ -0,0 +1,51 @@ +epoch,Acc,loss +0,0.03,7.502168061392648 +1,0.0625,6.382974977039155 +2,0.0925,5.609923143840971 +3,0.1225,4.946143490019299 +4,0.1275,4.51800890604655 +5,0.14,4.206934458414714 +6,0.17,3.9105675583794004 +7,0.1825,3.74058198928833 +8,0.185,3.5537690730321976 +9,0.1975,3.4097133327665783 +10,0.1975,3.3246297645568847 +11,0.2025,3.1981849284399124 +12,0.205,3.157173556373233 +13,0.2075,3.0660635684785387 +14,0.2125,3.041565242948986 +15,0.2225,2.971737453823998 +16,0.22,2.9743683887663344 +17,0.2275,2.918078219095866 +18,0.2225,2.9116986974080405 +19,0.22,2.8902962466648647 +20,0.23,2.8917558279491606 +21,0.225,2.869637153262184 +22,0.2325,2.869133186340332 +23,0.2425,2.8532540253230505 +24,0.2375,2.8584180604843867 +25,0.235,2.833264215106056 +26,0.235,2.8339362516857327 +27,0.2325,2.8220349543435232 +28,0.23,2.8212475331624347 +29,0.2225,2.8232532464890254 +30,0.2225,2.841775826045445 +31,0.225,2.803494078318278 +32,0.23,2.81758319627671 +33,0.23,2.8031206031072706 +34,0.2375,2.84076034228007 +35,0.2375,2.8026808257330034 +36,0.2375,2.798538010006859 +37,0.2275,2.8218897683279853 +38,0.2225,2.8118302486056375 +39,0.2325,2.812475911095029 +40,0.2325,2.794565626780192 +41,0.2325,2.832269555046445 +42,0.2225,2.8263108544122604 +43,0.22,2.812968007950556 +44,0.2175,2.815446391786848 +45,0.23,2.7967070988246374 +46,0.225,2.801809174673898 +47,0.2325,2.8028654884156725 +48,0.2375,2.802789167676653 +49,0.2325,2.8161884684789746 diff --git a/tests/SB_CNN/UrbanSound8k/fold1/best_weights.hdf5 b/tests/SB_CNN/UrbanSound8k/fold1/best_weights.hdf5 index 202a893..bede7e9 100644 Binary files a/tests/SB_CNN/UrbanSound8k/fold1/best_weights.hdf5 and b/tests/SB_CNN/UrbanSound8k/fold1/best_weights.hdf5 differ diff --git a/tests/SB_CNN/UrbanSound8k/fold1/model.json b/tests/SB_CNN/UrbanSound8k/fold1/model.json index 4e17b08..6cf6466 100644 --- a/tests/SB_CNN/UrbanSound8k/fold1/model.json +++ b/tests/SB_CNN/UrbanSound8k/fold1/model.json @@ -1 +1 @@ -"{\"class_name\": \"Model\", \"config\": {\"name\": \"model_1\", \"layers\": [{\"name\": \"input\", \"class_name\": \"InputLayer\", \"config\": {\"batch_input_shape\": [null, 64, 128], \"dtype\": \"float32\", \"sparse\": false, \"name\": \"input\"}, \"inbound_nodes\": []}, {\"name\": \"lambda\", \"class_name\": \"Lambda\", \"config\": {\"name\": \"lambda\", \"trainable\": true, \"function\": [\"4wEAAAAAAAAAAQAAAAQAAABTAAAAcwwAAAB0AKABfABkAaECUwApAk7p/////ykC2gFL2gtleHBh\\nbmRfZGltcykB2gF4qQByBQAAAPofLi4vZGNhc2VfbW9kZWxzL21vZGVsL21vZGVscy5wedoIPGxh\\nbWJkYT44AAAA8wAAAAA=\\n\", null, null], \"function_type\": \"lambda\", \"output_shape\": null, \"output_shape_type\": \"raw\", \"arguments\": {}}, \"inbound_nodes\": [[[\"input\", 0, 0, {}]]]}, {\"name\": \"conv1\", \"class_name\": \"Conv2D\", \"config\": {\"name\": \"conv1\", \"trainable\": true, \"filters\": 24, \"kernel_size\": [5, 5], \"strides\": [1, 1], \"padding\": \"valid\", \"data_format\": \"channels_last\", \"dilation_rate\": [1, 1], \"activation\": \"relu\", \"use_bias\": true, \"kernel_initializer\": {\"class_name\": \"VarianceScaling\", \"config\": {\"scale\": 1.0, \"mode\": \"fan_avg\", \"distribution\": \"uniform\", \"seed\": null}}, \"bias_initializer\": {\"class_name\": \"Zeros\", \"config\": {}}, \"kernel_regularizer\": null, \"bias_regularizer\": null, \"activity_regularizer\": null, \"kernel_constraint\": null, \"bias_constraint\": null}, \"inbound_nodes\": [[[\"lambda\", 0, 0, {}]]]}, {\"name\": \"maxpool1\", \"class_name\": \"MaxPooling2D\", \"config\": {\"name\": \"maxpool1\", \"trainable\": true, \"pool_size\": [2, 2], \"padding\": \"valid\", \"strides\": [2, 2], \"data_format\": \"channels_last\"}, \"inbound_nodes\": [[[\"conv1\", 0, 0, {}]]]}, {\"name\": \"batchnorm1\", \"class_name\": \"BatchNormalization\", \"config\": {\"name\": \"batchnorm1\", \"trainable\": true, \"axis\": -1, \"momentum\": 0.99, \"epsilon\": 0.001, \"center\": true, \"scale\": true, \"beta_initializer\": {\"class_name\": \"Zeros\", \"config\": {}}, \"gamma_initializer\": {\"class_name\": \"Ones\", \"config\": {}}, \"moving_mean_initializer\": {\"class_name\": \"Zeros\", \"config\": {}}, \"moving_variance_initializer\": {\"class_name\": \"Ones\", \"config\": {}}, \"beta_regularizer\": null, \"gamma_regularizer\": null, \"beta_constraint\": null, \"gamma_constraint\": null}, \"inbound_nodes\": [[[\"maxpool1\", 0, 0, {}]]]}, {\"name\": \"conv2\", \"class_name\": \"Conv2D\", \"config\": {\"name\": \"conv2\", \"trainable\": true, \"filters\": 48, \"kernel_size\": [5, 5], \"strides\": [1, 1], \"padding\": \"valid\", \"data_format\": \"channels_last\", \"dilation_rate\": [1, 1], \"activation\": \"relu\", \"use_bias\": true, \"kernel_initializer\": {\"class_name\": \"VarianceScaling\", \"config\": {\"scale\": 1.0, \"mode\": \"fan_avg\", \"distribution\": \"uniform\", \"seed\": null}}, \"bias_initializer\": {\"class_name\": \"Zeros\", \"config\": {}}, \"kernel_regularizer\": null, \"bias_regularizer\": null, \"activity_regularizer\": null, \"kernel_constraint\": null, \"bias_constraint\": null}, \"inbound_nodes\": [[[\"batchnorm1\", 0, 0, {}]]]}, {\"name\": \"maxpool2\", \"class_name\": \"MaxPooling2D\", \"config\": {\"name\": \"maxpool2\", \"trainable\": true, \"pool_size\": [2, 2], \"padding\": \"valid\", \"strides\": [2, 2], \"data_format\": \"channels_last\"}, \"inbound_nodes\": [[[\"conv2\", 0, 0, {}]]]}, {\"name\": \"batchnorm2\", \"class_name\": \"BatchNormalization\", \"config\": {\"name\": \"batchnorm2\", \"trainable\": true, \"axis\": -1, \"momentum\": 0.99, \"epsilon\": 0.001, \"center\": true, \"scale\": true, \"beta_initializer\": {\"class_name\": \"Zeros\", \"config\": {}}, \"gamma_initializer\": {\"class_name\": \"Ones\", \"config\": {}}, \"moving_mean_initializer\": {\"class_name\": \"Zeros\", \"config\": {}}, \"moving_variance_initializer\": {\"class_name\": \"Ones\", \"config\": {}}, \"beta_regularizer\": null, \"gamma_regularizer\": null, \"beta_constraint\": null, \"gamma_constraint\": null}, \"inbound_nodes\": [[[\"maxpool2\", 0, 0, {}]]]}, {\"name\": \"conv3\", \"class_name\": \"Conv2D\", \"config\": {\"name\": \"conv3\", \"trainable\": true, \"filters\": 48, \"kernel_size\": [5, 5], \"strides\": [1, 1], \"padding\": \"valid\", \"data_format\": \"channels_last\", \"dilation_rate\": [1, 1], \"activation\": \"relu\", \"use_bias\": true, \"kernel_initializer\": {\"class_name\": \"VarianceScaling\", \"config\": {\"scale\": 1.0, \"mode\": \"fan_avg\", \"distribution\": \"uniform\", \"seed\": null}}, \"bias_initializer\": {\"class_name\": \"Zeros\", \"config\": {}}, \"kernel_regularizer\": null, \"bias_regularizer\": null, \"activity_regularizer\": null, \"kernel_constraint\": null, \"bias_constraint\": null}, \"inbound_nodes\": [[[\"batchnorm2\", 0, 0, {}]]]}, {\"name\": \"batchnorm3\", \"class_name\": \"BatchNormalization\", \"config\": {\"name\": \"batchnorm3\", \"trainable\": true, \"axis\": -1, \"momentum\": 0.99, \"epsilon\": 0.001, \"center\": true, \"scale\": true, \"beta_initializer\": {\"class_name\": \"Zeros\", \"config\": {}}, \"gamma_initializer\": {\"class_name\": \"Ones\", \"config\": {}}, \"moving_mean_initializer\": {\"class_name\": \"Zeros\", \"config\": {}}, \"moving_variance_initializer\": {\"class_name\": \"Ones\", \"config\": {}}, \"beta_regularizer\": null, \"gamma_regularizer\": null, \"beta_constraint\": null, \"gamma_constraint\": null}, \"inbound_nodes\": [[[\"conv3\", 0, 0, {}]]]}, {\"name\": \"flatten\", \"class_name\": \"Flatten\", \"config\": {\"name\": \"flatten\", \"trainable\": true, \"data_format\": \"channels_last\"}, \"inbound_nodes\": [[[\"batchnorm3\", 0, 0, {}]]]}, {\"name\": \"dropout1\", \"class_name\": \"Dropout\", \"config\": {\"name\": \"dropout1\", \"trainable\": true, \"rate\": 0.5, \"noise_shape\": null, \"seed\": null}, \"inbound_nodes\": [[[\"flatten\", 0, 0, {}]]]}, {\"name\": \"dense1\", \"class_name\": \"Dense\", \"config\": {\"name\": \"dense1\", \"trainable\": true, \"units\": 64, \"activation\": \"relu\", \"use_bias\": true, \"kernel_initializer\": {\"class_name\": \"VarianceScaling\", \"config\": {\"scale\": 1.0, \"mode\": \"fan_avg\", \"distribution\": \"uniform\", \"seed\": null}}, \"bias_initializer\": {\"class_name\": \"Zeros\", \"config\": {}}, \"kernel_regularizer\": {\"class_name\": \"L1L2\", \"config\": {\"l1\": 0.0, \"l2\": 0.0010000000474974513}}, \"bias_regularizer\": {\"class_name\": \"L1L2\", \"config\": {\"l1\": 0.0, \"l2\": 0.0010000000474974513}}, \"activity_regularizer\": null, \"kernel_constraint\": null, \"bias_constraint\": null}, \"inbound_nodes\": [[[\"dropout1\", 0, 0, {}]]]}, {\"name\": \"dropout2\", \"class_name\": \"Dropout\", \"config\": {\"name\": \"dropout2\", \"trainable\": true, \"rate\": 0.5, \"noise_shape\": null, \"seed\": null}, \"inbound_nodes\": [[[\"dense1\", 0, 0, {}]]]}, {\"name\": \"out\", \"class_name\": \"Dense\", \"config\": {\"name\": \"out\", \"trainable\": true, \"units\": 10, \"activation\": \"softmax\", \"use_bias\": true, \"kernel_initializer\": {\"class_name\": \"VarianceScaling\", \"config\": {\"scale\": 1.0, \"mode\": \"fan_avg\", \"distribution\": \"uniform\", \"seed\": null}}, \"bias_initializer\": {\"class_name\": \"Zeros\", \"config\": {}}, \"kernel_regularizer\": {\"class_name\": \"L1L2\", \"config\": {\"l1\": 0.0, \"l2\": 0.0010000000474974513}}, \"bias_regularizer\": {\"class_name\": \"L1L2\", \"config\": {\"l1\": 0.0, \"l2\": 0.0010000000474974513}}, \"activity_regularizer\": null, \"kernel_constraint\": null, \"bias_constraint\": null}, \"inbound_nodes\": [[[\"dropout2\", 0, 0, {}]]]}], \"input_layers\": [[\"input\", 0, 0]], \"output_layers\": [[\"out\", 0, 0]]}, \"keras_version\": \"2.2.4\", \"backend\": \"tensorflow\"}" \ No newline at end of file +"{\"class_name\": \"Model\", \"config\": {\"name\": \"model_1\", \"layers\": [{\"name\": \"input\", \"class_name\": \"InputLayer\", \"config\": {\"batch_input_shape\": [null, 64, 128], \"dtype\": \"float32\", \"sparse\": false, \"name\": \"input\"}, \"inbound_nodes\": []}, {\"name\": \"lambda\", \"class_name\": \"Lambda\", \"config\": {\"name\": \"lambda\", \"trainable\": true, \"function\": [\"4wEAAAAAAAAAAQAAAAQAAABTAAAAcwwAAAB0AKABfABkAaECUwApAk7p/////ykC2gFL2gtleHBh\\nbmRfZGltcykB2gF4qQByBQAAAPofLi4vZGNhc2VfbW9kZWxzL21vZGVsL21vZGVscy5wedoIPGxh\\nbWJkYT44AAAA8wAAAAA=\\n\", null, null], \"function_type\": \"lambda\", \"output_shape\": null, \"output_shape_type\": \"raw\", \"arguments\": {}}, \"inbound_nodes\": [[[\"input\", 0, 0, {}]]]}, {\"name\": \"conv1\", \"class_name\": \"Conv2D\", \"config\": {\"name\": \"conv1\", \"trainable\": true, \"filters\": 24, \"kernel_size\": [5, 5], \"strides\": [1, 1], \"padding\": \"valid\", \"data_format\": \"channels_last\", \"dilation_rate\": [1, 1], \"activation\": \"relu\", \"use_bias\": true, \"kernel_initializer\": {\"class_name\": \"VarianceScaling\", \"config\": {\"scale\": 1.0, \"mode\": \"fan_avg\", \"distribution\": \"uniform\", \"seed\": null}}, \"bias_initializer\": {\"class_name\": \"Zeros\", \"config\": {}}, \"kernel_regularizer\": null, \"bias_regularizer\": null, \"activity_regularizer\": null, \"kernel_constraint\": null, \"bias_constraint\": null}, \"inbound_nodes\": [[[\"lambda\", 0, 0, {}]]]}, {\"name\": \"maxpool1\", \"class_name\": \"MaxPooling2D\", \"config\": {\"name\": \"maxpool1\", \"trainable\": true, \"pool_size\": [2, 2], \"padding\": \"valid\", \"strides\": [2, 2], \"data_format\": \"channels_last\"}, \"inbound_nodes\": [[[\"conv1\", 0, 0, {}]]]}, {\"name\": \"batchnorm1\", \"class_name\": \"BatchNormalization\", \"config\": {\"name\": \"batchnorm1\", \"trainable\": true, \"axis\": -1, \"momentum\": 0.99, \"epsilon\": 0.001, \"center\": true, \"scale\": true, \"beta_initializer\": {\"class_name\": \"Zeros\", \"config\": {}}, \"gamma_initializer\": {\"class_name\": \"Ones\", \"config\": {}}, \"moving_mean_initializer\": {\"class_name\": \"Zeros\", \"config\": {}}, \"moving_variance_initializer\": {\"class_name\": \"Ones\", \"config\": {}}, \"beta_regularizer\": null, \"gamma_regularizer\": null, \"beta_constraint\": null, \"gamma_constraint\": null}, \"inbound_nodes\": [[[\"maxpool1\", 0, 0, {}]]]}, {\"name\": \"conv2\", \"class_name\": \"Conv2D\", \"config\": {\"name\": \"conv2\", \"trainable\": true, \"filters\": 48, \"kernel_size\": [5, 5], \"strides\": [1, 1], \"padding\": \"valid\", \"data_format\": \"channels_last\", \"dilation_rate\": [1, 1], \"activation\": \"relu\", \"use_bias\": true, \"kernel_initializer\": {\"class_name\": \"VarianceScaling\", \"config\": {\"scale\": 1.0, \"mode\": \"fan_avg\", \"distribution\": \"uniform\", \"seed\": null}}, \"bias_initializer\": {\"class_name\": \"Zeros\", \"config\": {}}, \"kernel_regularizer\": null, \"bias_regularizer\": null, \"activity_regularizer\": null, \"kernel_constraint\": null, \"bias_constraint\": null}, \"inbound_nodes\": [[[\"batchnorm1\", 0, 0, {}]]]}, {\"name\": \"maxpool2\", \"class_name\": \"MaxPooling2D\", \"config\": {\"name\": \"maxpool2\", \"trainable\": true, \"pool_size\": [4, 2], \"padding\": \"valid\", \"strides\": [4, 2], \"data_format\": \"channels_last\"}, \"inbound_nodes\": [[[\"conv2\", 0, 0, {}]]]}, {\"name\": \"batchnorm2\", \"class_name\": \"BatchNormalization\", \"config\": {\"name\": \"batchnorm2\", \"trainable\": true, \"axis\": -1, \"momentum\": 0.99, \"epsilon\": 0.001, \"center\": true, \"scale\": true, \"beta_initializer\": {\"class_name\": \"Zeros\", \"config\": {}}, \"gamma_initializer\": {\"class_name\": \"Ones\", \"config\": {}}, \"moving_mean_initializer\": {\"class_name\": \"Zeros\", \"config\": {}}, \"moving_variance_initializer\": {\"class_name\": \"Ones\", \"config\": {}}, \"beta_regularizer\": null, \"gamma_regularizer\": null, \"beta_constraint\": null, \"gamma_constraint\": null}, \"inbound_nodes\": [[[\"maxpool2\", 0, 0, {}]]]}, {\"name\": \"conv3\", \"class_name\": \"Conv2D\", \"config\": {\"name\": \"conv3\", \"trainable\": true, \"filters\": 48, \"kernel_size\": [5, 5], \"strides\": [1, 1], \"padding\": \"valid\", \"data_format\": \"channels_last\", \"dilation_rate\": [1, 1], \"activation\": \"relu\", \"use_bias\": true, \"kernel_initializer\": {\"class_name\": \"VarianceScaling\", \"config\": {\"scale\": 1.0, \"mode\": \"fan_avg\", \"distribution\": \"uniform\", \"seed\": null}}, \"bias_initializer\": {\"class_name\": \"Zeros\", \"config\": {}}, \"kernel_regularizer\": null, \"bias_regularizer\": null, \"activity_regularizer\": null, \"kernel_constraint\": null, \"bias_constraint\": null}, \"inbound_nodes\": [[[\"batchnorm2\", 0, 0, {}]]]}, {\"name\": \"batchnorm3\", \"class_name\": \"BatchNormalization\", \"config\": {\"name\": \"batchnorm3\", \"trainable\": true, \"axis\": -1, \"momentum\": 0.99, \"epsilon\": 0.001, \"center\": true, \"scale\": true, \"beta_initializer\": {\"class_name\": \"Zeros\", \"config\": {}}, \"gamma_initializer\": {\"class_name\": \"Ones\", \"config\": {}}, \"moving_mean_initializer\": {\"class_name\": \"Zeros\", \"config\": {}}, \"moving_variance_initializer\": {\"class_name\": \"Ones\", \"config\": {}}, \"beta_regularizer\": null, \"gamma_regularizer\": null, \"beta_constraint\": null, \"gamma_constraint\": null}, \"inbound_nodes\": [[[\"conv3\", 0, 0, {}]]]}, {\"name\": \"flatten\", \"class_name\": \"Flatten\", \"config\": {\"name\": \"flatten\", \"trainable\": true, \"data_format\": \"channels_last\"}, \"inbound_nodes\": [[[\"batchnorm3\", 0, 0, {}]]]}, {\"name\": \"dropout1\", \"class_name\": \"Dropout\", \"config\": {\"name\": \"dropout1\", \"trainable\": true, \"rate\": 0.5, \"noise_shape\": null, \"seed\": null}, \"inbound_nodes\": [[[\"flatten\", 0, 0, {}]]]}, {\"name\": \"dense1\", \"class_name\": \"Dense\", \"config\": {\"name\": \"dense1\", \"trainable\": true, \"units\": 64, \"activation\": \"relu\", \"use_bias\": true, \"kernel_initializer\": {\"class_name\": \"VarianceScaling\", \"config\": {\"scale\": 1.0, \"mode\": \"fan_avg\", \"distribution\": \"uniform\", \"seed\": null}}, \"bias_initializer\": {\"class_name\": \"Zeros\", \"config\": {}}, \"kernel_regularizer\": {\"class_name\": \"L1L2\", \"config\": {\"l1\": 0.0, \"l2\": 0.0010000000474974513}}, \"bias_regularizer\": {\"class_name\": \"L1L2\", \"config\": {\"l1\": 0.0, \"l2\": 0.0010000000474974513}}, \"activity_regularizer\": null, \"kernel_constraint\": null, \"bias_constraint\": null}, \"inbound_nodes\": [[[\"dropout1\", 0, 0, {}]]]}, {\"name\": \"dropout2\", \"class_name\": \"Dropout\", \"config\": {\"name\": \"dropout2\", \"trainable\": true, \"rate\": 0.5, \"noise_shape\": null, \"seed\": null}, \"inbound_nodes\": [[[\"dense1\", 0, 0, {}]]]}, {\"name\": \"out\", \"class_name\": \"Dense\", \"config\": {\"name\": \"out\", \"trainable\": true, \"units\": 10, \"activation\": \"softmax\", \"use_bias\": true, \"kernel_initializer\": {\"class_name\": \"VarianceScaling\", \"config\": {\"scale\": 1.0, \"mode\": \"fan_avg\", \"distribution\": \"uniform\", \"seed\": null}}, \"bias_initializer\": {\"class_name\": \"Zeros\", \"config\": {}}, \"kernel_regularizer\": {\"class_name\": \"L1L2\", \"config\": {\"l1\": 0.0, \"l2\": 0.0010000000474974513}}, \"bias_regularizer\": {\"class_name\": \"L1L2\", \"config\": {\"l1\": 0.0, \"l2\": 0.0010000000474974513}}, \"activity_regularizer\": null, \"kernel_constraint\": null, \"bias_constraint\": null}, \"inbound_nodes\": [[[\"dropout2\", 0, 0, {}]]]}], \"input_layers\": [[\"input\", 0, 0]], \"output_layers\": [[\"out\", 0, 0]]}, \"keras_version\": \"2.2.4\", \"backend\": \"tensorflow\"}" \ No newline at end of file diff --git a/tests/SB_CNN/UrbanSound8k/fold1/training.log b/tests/SB_CNN/UrbanSound8k/fold1/training.log index 56a3710..63fd275 100644 --- a/tests/SB_CNN/UrbanSound8k/fold1/training.log +++ b/tests/SB_CNN/UrbanSound8k/fold1/training.log @@ -1,2 +1,51 @@ epoch,Acc,loss -0,0.37274774774774777,1.699947649133844 +0,0.5011261261261262,1.625269956128379 +1,0.5641891891891891,0.9095615333715344 +2,0.5382882882882883,0.6592631903369528 +3,0.6475225225225225,0.5378054776422538 +4,0.615990990990991,0.45968553130675266 +5,0.634009009009009,0.40013066320021323 +6,0.615990990990991,0.34847372230133294 +7,0.6047297297297297,0.32574788093586227 +8,0.6317567567567568,0.29824281140942016 +9,0.6396396396396397,0.28984973799992886 +10,0.6576576576576577,0.2697383113500653 +11,0.6599099099099099,0.24747480279681192 +12,0.6677927927927928,0.23570926859028385 +13,0.6621621621621622,0.23058883280578552 +14,0.6565315315315315,0.22353901275284027 +15,0.6148648648648649,0.22088419158085984 +16,0.6430180180180181,0.20951895634721013 +17,0.6587837837837838,0.20472049576036672 +18,0.6509009009009009,0.20235659638957929 +19,0.6216216216216216,0.19696752808227289 +20,0.6441441441441441,0.19281020245089248 +21,0.6554054054054054,0.18519578671444428 +22,0.6644144144144144,0.18536975776977144 +23,0.6632882882882883,0.17819096422371358 +24,0.6790540540540541,0.1783783993896159 +25,0.7195945945945946,0.17566641583201809 +26,0.6531531531531531,0.1705881541332971 +27,0.6587837837837838,0.1680015179478798 +28,0.6756756756756757,0.1707222356855035 +29,0.6891891891891891,0.16260425320969601 +30,0.6295045045045045,0.16192709432047014 +31,0.625,0.16247973666042115 +32,0.6993243243243243,0.1600518668575592 +33,0.6711711711711712,0.16237080583727562 +34,0.6858108108108109,0.149181927105589 +35,0.6846846846846847,0.1507985967160225 +36,0.6903153153153153,0.15788440619058122 +37,0.6835585585585585,0.15442013508954933 +38,0.6903153153153153,0.15324601805386037 +39,0.6722972972972973,0.14859362231250633 +40,0.6644144144144144,0.1469708662088436 +41,0.6835585585585585,0.14016205039376975 +42,0.668918918918919,0.1402520475641986 +43,0.704954954954955,0.14362826367939954 +44,0.6925675675675675,0.14815754861910668 +45,0.706081081081081,0.14206463133968517 +46,0.6813063063063063,0.14521905161286117 +47,0.6756756756756757,0.13778199592089807 +48,0.6925675675675675,0.13453787673250445 +49,0.6542792792792793,0.13277108727503392 diff --git a/tests/SB_CNN/UrbanSound8k_ft_ESC50/fold1/best_weights.hdf5 b/tests/SB_CNN/UrbanSound8k_ft_ESC50/fold1/best_weights.hdf5 new file mode 100644 index 0000000..5c8b23e Binary files /dev/null and b/tests/SB_CNN/UrbanSound8k_ft_ESC50/fold1/best_weights.hdf5 differ diff --git a/tests/SB_CNN/UrbanSound8k_ft_ESC50/fold1/model.json b/tests/SB_CNN/UrbanSound8k_ft_ESC50/fold1/model.json new file mode 100644 index 0000000..7f371d7 --- /dev/null +++ b/tests/SB_CNN/UrbanSound8k_ft_ESC50/fold1/model.json @@ -0,0 +1 @@ +"{\"class_name\": \"Model\", \"config\": {\"name\": \"model_1\", \"layers\": [{\"name\": \"input\", \"class_name\": \"InputLayer\", \"config\": {\"batch_input_shape\": [null, 64, 128], \"dtype\": \"float32\", \"sparse\": false, \"name\": \"input\"}, \"inbound_nodes\": []}, {\"name\": \"source_model\", \"class_name\": \"Model\", \"config\": {\"name\": \"source_model\", \"layers\": [{\"name\": \"input\", \"class_name\": \"InputLayer\", \"config\": {\"batch_input_shape\": [null, 64, 128], \"dtype\": \"float32\", \"sparse\": false, \"name\": \"input\"}, \"inbound_nodes\": []}, {\"name\": \"lambda\", \"class_name\": \"Lambda\", \"config\": {\"name\": \"lambda\", \"trainable\": true, \"function\": [\"4wEAAAAAAAAAAQAAAAQAAABTAAAAcwwAAAB0AKABfABkAaECUwApAk7p/////ykC2gFL2gtleHBh\\nbmRfZGltcykB2gF4qQByBQAAAPofLi4vZGNhc2VfbW9kZWxzL21vZGVsL21vZGVscy5wedoIPGxh\\nbWJkYT44AAAA8wAAAAA=\\n\", null, null], \"function_type\": \"lambda\", \"output_shape\": null, \"output_shape_type\": \"raw\", \"arguments\": {}}, \"inbound_nodes\": [[[\"input\", 0, 0, {}]]]}, {\"name\": \"conv1\", \"class_name\": \"Conv2D\", \"config\": {\"name\": \"conv1\", \"trainable\": true, \"filters\": 24, \"kernel_size\": [5, 5], \"strides\": [1, 1], \"padding\": \"valid\", \"data_format\": \"channels_last\", \"dilation_rate\": [1, 1], \"activation\": \"relu\", \"use_bias\": true, \"kernel_initializer\": {\"class_name\": \"VarianceScaling\", \"config\": {\"scale\": 1.0, \"mode\": \"fan_avg\", \"distribution\": \"uniform\", \"seed\": null}}, \"bias_initializer\": {\"class_name\": \"Zeros\", \"config\": {}}, \"kernel_regularizer\": null, \"bias_regularizer\": null, \"activity_regularizer\": null, \"kernel_constraint\": null, \"bias_constraint\": null}, \"inbound_nodes\": [[[\"lambda\", 0, 0, {}]]]}, {\"name\": \"maxpool1\", \"class_name\": \"MaxPooling2D\", \"config\": {\"name\": \"maxpool1\", \"trainable\": true, \"pool_size\": [2, 2], \"padding\": \"valid\", \"strides\": [2, 2], \"data_format\": \"channels_last\"}, \"inbound_nodes\": [[[\"conv1\", 0, 0, {}]]]}, {\"name\": \"batchnorm1\", \"class_name\": \"BatchNormalization\", \"config\": {\"name\": \"batchnorm1\", \"trainable\": true, \"axis\": -1, \"momentum\": 0.99, \"epsilon\": 0.001, \"center\": true, \"scale\": true, \"beta_initializer\": {\"class_name\": \"Zeros\", \"config\": {}}, \"gamma_initializer\": {\"class_name\": \"Ones\", \"config\": {}}, \"moving_mean_initializer\": {\"class_name\": \"Zeros\", \"config\": {}}, \"moving_variance_initializer\": {\"class_name\": \"Ones\", \"config\": {}}, \"beta_regularizer\": null, \"gamma_regularizer\": null, \"beta_constraint\": null, \"gamma_constraint\": null}, \"inbound_nodes\": [[[\"maxpool1\", 0, 0, {}]]]}, {\"name\": \"conv2\", \"class_name\": \"Conv2D\", \"config\": {\"name\": \"conv2\", \"trainable\": true, \"filters\": 48, \"kernel_size\": [5, 5], \"strides\": [1, 1], \"padding\": \"valid\", \"data_format\": \"channels_last\", \"dilation_rate\": [1, 1], \"activation\": \"relu\", \"use_bias\": true, \"kernel_initializer\": {\"class_name\": \"VarianceScaling\", \"config\": {\"scale\": 1.0, \"mode\": \"fan_avg\", \"distribution\": \"uniform\", \"seed\": null}}, \"bias_initializer\": {\"class_name\": \"Zeros\", \"config\": {}}, \"kernel_regularizer\": null, \"bias_regularizer\": null, \"activity_regularizer\": null, \"kernel_constraint\": null, \"bias_constraint\": null}, \"inbound_nodes\": [[[\"batchnorm1\", 0, 0, {}]]]}, {\"name\": \"maxpool2\", \"class_name\": \"MaxPooling2D\", \"config\": {\"name\": \"maxpool2\", \"trainable\": true, \"pool_size\": [2, 2], \"padding\": \"valid\", \"strides\": [2, 2], \"data_format\": \"channels_last\"}, \"inbound_nodes\": [[[\"conv2\", 0, 0, {}]]]}, {\"name\": \"batchnorm2\", \"class_name\": \"BatchNormalization\", \"config\": {\"name\": \"batchnorm2\", \"trainable\": true, \"axis\": -1, \"momentum\": 0.99, \"epsilon\": 0.001, \"center\": true, \"scale\": true, \"beta_initializer\": {\"class_name\": \"Zeros\", \"config\": {}}, \"gamma_initializer\": {\"class_name\": \"Ones\", \"config\": {}}, \"moving_mean_initializer\": {\"class_name\": \"Zeros\", \"config\": {}}, \"moving_variance_initializer\": {\"class_name\": \"Ones\", \"config\": {}}, \"beta_regularizer\": null, \"gamma_regularizer\": null, \"beta_constraint\": null, \"gamma_constraint\": null}, \"inbound_nodes\": [[[\"maxpool2\", 0, 0, {}]]]}, {\"name\": \"conv3\", \"class_name\": \"Conv2D\", \"config\": {\"name\": \"conv3\", \"trainable\": true, \"filters\": 48, \"kernel_size\": [5, 5], \"strides\": [1, 1], \"padding\": \"valid\", \"data_format\": \"channels_last\", \"dilation_rate\": [1, 1], \"activation\": \"relu\", \"use_bias\": true, \"kernel_initializer\": {\"class_name\": \"VarianceScaling\", \"config\": {\"scale\": 1.0, \"mode\": \"fan_avg\", \"distribution\": \"uniform\", \"seed\": null}}, \"bias_initializer\": {\"class_name\": \"Zeros\", \"config\": {}}, \"kernel_regularizer\": null, \"bias_regularizer\": null, \"activity_regularizer\": null, \"kernel_constraint\": null, \"bias_constraint\": null}, \"inbound_nodes\": [[[\"batchnorm2\", 0, 0, {}]]]}, {\"name\": \"batchnorm3\", \"class_name\": \"BatchNormalization\", \"config\": {\"name\": \"batchnorm3\", \"trainable\": true, \"axis\": -1, \"momentum\": 0.99, \"epsilon\": 0.001, \"center\": true, \"scale\": true, \"beta_initializer\": {\"class_name\": \"Zeros\", \"config\": {}}, \"gamma_initializer\": {\"class_name\": \"Ones\", \"config\": {}}, \"moving_mean_initializer\": {\"class_name\": \"Zeros\", \"config\": {}}, \"moving_variance_initializer\": {\"class_name\": \"Ones\", \"config\": {}}, \"beta_regularizer\": null, \"gamma_regularizer\": null, \"beta_constraint\": null, \"gamma_constraint\": null}, \"inbound_nodes\": [[[\"conv3\", 0, 0, {}]]]}, {\"name\": \"flatten\", \"class_name\": \"Flatten\", \"config\": {\"name\": \"flatten\", \"trainable\": true, \"data_format\": \"channels_last\"}, \"inbound_nodes\": [[[\"batchnorm3\", 0, 0, {}]]]}, {\"name\": \"dropout1\", \"class_name\": \"Dropout\", \"config\": {\"name\": \"dropout1\", \"trainable\": true, \"rate\": 0.5, \"noise_shape\": null, \"seed\": null}, \"inbound_nodes\": [[[\"flatten\", 0, 0, {}]]]}, {\"name\": \"dense1\", \"class_name\": \"Dense\", \"config\": {\"name\": \"dense1\", \"trainable\": true, \"units\": 64, \"activation\": \"relu\", \"use_bias\": true, \"kernel_initializer\": {\"class_name\": \"VarianceScaling\", \"config\": {\"scale\": 1.0, \"mode\": \"fan_avg\", \"distribution\": \"uniform\", \"seed\": null}}, \"bias_initializer\": {\"class_name\": \"Zeros\", \"config\": {}}, \"kernel_regularizer\": {\"class_name\": \"L1L2\", \"config\": {\"l1\": 0.0, \"l2\": 0.0010000000474974513}}, \"bias_regularizer\": {\"class_name\": \"L1L2\", \"config\": {\"l1\": 0.0, \"l2\": 0.0010000000474974513}}, \"activity_regularizer\": null, \"kernel_constraint\": null, \"bias_constraint\": null}, \"inbound_nodes\": [[[\"dropout1\", 0, 0, {}]]]}, {\"name\": \"dropout2\", \"class_name\": \"Dropout\", \"config\": {\"name\": \"dropout2\", \"trainable\": true, \"rate\": 0.5, \"noise_shape\": null, \"seed\": null}, \"inbound_nodes\": [[[\"dense1\", 0, 0, {}]]]}], \"input_layers\": [[\"input\", 0, 0]], \"output_layers\": [[\"dropout2\", 0, 0]]}, \"inbound_nodes\": [[[\"input\", 0, 0, {}]]]}, {\"name\": \"new_dense_layer\", \"class_name\": \"Dense\", \"config\": {\"name\": \"new_dense_layer\", \"trainable\": true, \"units\": 50, \"activation\": \"softmax\", \"use_bias\": true, \"kernel_initializer\": {\"class_name\": \"VarianceScaling\", \"config\": {\"scale\": 1.0, \"mode\": \"fan_avg\", \"distribution\": \"uniform\", \"seed\": null}}, \"bias_initializer\": {\"class_name\": \"Zeros\", \"config\": {}}, \"kernel_regularizer\": null, \"bias_regularizer\": null, \"activity_regularizer\": null, \"kernel_constraint\": null, \"bias_constraint\": null}, \"inbound_nodes\": [[[\"source_model\", 1, 0, {}]]]}], \"input_layers\": [[\"input\", 0, 0]], \"output_layers\": [[\"new_dense_layer\", 0, 0]]}, \"keras_version\": \"2.2.4\", \"backend\": \"tensorflow\"}" \ No newline at end of file diff --git a/tests/SB_CNN/UrbanSound8k_ft_ESC50/fold1/training.log b/tests/SB_CNN/UrbanSound8k_ft_ESC50/fold1/training.log new file mode 100644 index 0000000..8a8b319 --- /dev/null +++ b/tests/SB_CNN/UrbanSound8k_ft_ESC50/fold1/training.log @@ -0,0 +1,2 @@ +epoch,Acc,loss +0,0.0375,6.6985985401698525 diff --git a/tests/parameters.json b/tests/parameters.json index efc3236..403c451 100644 --- a/tests/parameters.json +++ b/tests/parameters.json @@ -12,7 +12,7 @@ "train" : { "early_stopping" : 30, - "epochs" : 1, + "epochs" : 50, "considered_improvement" : 0, "learning_rate" : 0.001, "batch_size" : 256, diff --git a/tests/test_fine_tuning.py b/tests/test_fine_tuning.py new file mode 100644 index 0000000..9b08213 --- /dev/null +++ b/tests/test_fine_tuning.py @@ -0,0 +1,79 @@ +import sys +import os +import glob +import numpy as np +import argparse + +sys.path.append('../') +from dcase_models.utils.files import load_json, mkdir_if_not_exists +from dcase_models.data.data_generator import * +from dcase_models.model.container import * +from dcase_models.model.models import * +from dcase_models.data.scaler import Scaler +from dcase_models.utils.misc import get_class_by_name + +os.environ["CUDA_VISIBLE_DEVICES"] = "1" + +parser = argparse.ArgumentParser(description='Test DataGenerator') +parser.add_argument('-sd', '--source_dataset', type=str, help='dataset used to train the model', default='UrbanSound8k') +parser.add_argument('-dd', '--destination_dataset', type=str, help='dataset used to train the new model', default='UrbanSound8k') +parser.add_argument('-m', '--model', type=str, help='model to use for the test', default='SB_CNN') +parser.add_argument('-f', '--fold', type=str, help='fold of the dataset', default='fold1') +args = parser.parse_args() + +params = load_json('parameters.json') + +# get destination dataset class +data_generator_class = get_class_by_name(globals(), args.destination_dataset, DataGenerator) +params_dataset = params["datasets"][args.destination_dataset] +data_generator = data_generator_class(params_dataset['audio_folder'], params_dataset['feature_folder'], params_dataset['annotations_folder'], + 'mel_spectrograms', params_dataset['folds'], params_dataset['label_list'], meta_file=params_dataset['metadata']) +data_generator.load_data() + +# get model class +model_container_class = get_class_by_name(globals(), args.model, DCASEModelContainer) +params_model = params["models"][args.model] + +# load data +fold_test = 'fold1' +X_train, Y_train, X_val, Y_val = data_generator.get_data_for_training(fold_test) +scaler = Scaler(normalizer=params_model['normalizer']) +scaler.fit(X_train) +X_train = scaler.transform(X_train) +X_val = scaler.transform(X_val) + +# paths +exp_folder_source = os.path.join(args.model, args.source_dataset) +exp_folder_source_fold = os.path.join(exp_folder_source, fold_test) + +exp_folder_destination = os.path.join(args.model, args.destination_dataset) +mkdir_if_not_exists(exp_folder_destination) +exp_folder_destination_fold = os.path.join(exp_folder_destination, fold_test) +mkdir_if_not_exists(exp_folder_destination_fold) + +# load source model +model_container = model_container_class(model=None, folder=exp_folder_source_fold) +model_container.model.summary() + +# fine-tune the model +model_container.fine_tuning(-2, new_number_of_classes=50, new_activation='softmax', freeze_source_model=True) +model_container.model.summary() + +# save new model as json +print('saving model to %s' % exp_folder_destination_fold) +model_container.save_model_json(exp_folder_destination_fold) + +# train new model +kwargs = params["train"] +train_arguments = params_model['train_arguments'] +model_container.train(X_train, Y_train, X_val, Y_val, weights_path=exp_folder_destination_fold, **train_arguments, **kwargs) + +# load best_weights +model_container.load_model_weights(exp_folder_destination_fold) + +# test model +X_test, Y_test = data_generator.get_data_for_testing(fold_test) +X_test = scaler.transform(X_test) +results = model_container.evaluate(X_test, Y_test) + +print('Accuracy in test fold: %f' % results['accuracy']) \ No newline at end of file diff --git a/tests/test_transfer_learning.py b/tests/test_transfer_learning.py new file mode 100644 index 0000000..70a99a0 --- /dev/null +++ b/tests/test_transfer_learning.py @@ -0,0 +1,80 @@ +import sys +import os +import glob +import numpy as np +import argparse + +sys.path.append('../') +from dcase_models.utils.files import load_json, mkdir_if_not_exists +from dcase_models.data.data_generator import * +from dcase_models.model.container import * +from dcase_models.model.models import * +from dcase_models.data.scaler import Scaler +from dcase_models.utils.misc import get_class_by_name + +os.environ["CUDA_VISIBLE_DEVICES"] = "1" + +parser = argparse.ArgumentParser(description='Test DataGenerator') +parser.add_argument('-sd', '--source_dataset', type=str, help='dataset used to train the model', default='UrbanSound8k') +parser.add_argument('-dd', '--destination_dataset', type=str, help='dataset used to train the new model', default='UrbanSound8k') +parser.add_argument('-m', '--model', type=str, help='model to use for the test', default='SB_CNN') +parser.add_argument('-f', '--fold', type=str, help='fold of the dataset', default='fold1') +args = parser.parse_args() + +params = load_json('parameters.json') + +# get destination dataset class +data_generator_class = get_class_by_name(globals(), args.destination_dataset, DataGenerator) +params_dataset = params["datasets"][args.destination_dataset] +data_generator = data_generator_class(params_dataset['audio_folder'], params_dataset['feature_folder'], params_dataset['annotations_folder'], + 'mel_spectrograms', params_dataset['folds'], params_dataset['label_list'], meta_file=params_dataset['metadata']) +data_generator.load_data() + +# get model class +model_container_class = get_class_by_name(globals(), args.model, DCASEModelContainer) +params_model = params["models"][args.model] + +# load data +fold_test = 'fold1' +X_train, Y_train, X_val, Y_val = data_generator.get_data_for_training(fold_test) +scaler = Scaler(normalizer=params_model['normalizer']) +scaler.fit(X_train) +X_train = scaler.transform(X_train) +X_val = scaler.transform(X_val) + +# paths of source model +exp_folder_source = os.path.join(args.model, args.source_dataset) +exp_folder_source_fold = os.path.join(exp_folder_source, fold_test) + +# paths of destination model +exp_folder_destination = os.path.join(args.model, args.destination_dataset) +mkdir_if_not_exists(exp_folder_destination) +exp_folder_destination_fold = os.path.join(exp_folder_destination, fold_test) +mkdir_if_not_exists(exp_folder_destination_fold) + +# load source model +model_container = model_container_class(model=None, folder=exp_folder_source_fold) +model_container.model.summary() + +# fine-tune the model +model_container.fine_tuning(-2, new_number_of_classes=50, new_activation='softmax', freeze_source_model=True) +model_container.model.summary() + +# save new model as json +print('saving model to %s' % exp_folder_destination_fold) +model_container.save_model_json(exp_folder_destination_fold) + +# train new model +kwargs = params["train"] +train_arguments = params_model['train_arguments'] +model_container.train(X_train, Y_train, X_val, Y_val, weights_path=exp_folder_destination_fold, **train_arguments, **kwargs) + +# load best_weights +model_container.load_model_weights(exp_folder_destination_fold) + +# test model +X_test, Y_test = data_generator.get_data_for_testing(fold_test) +X_test = scaler.transform(X_test) +results = model_container.evaluate(X_test, Y_test) + +print('Accuracy in test fold: %f' % results['accuracy']) \ No newline at end of file