From 6ccb8b52c479a005df8096ee4bda72acf70870a6 Mon Sep 17 00:00:00 2001 From: mitul23 Date: Wed, 18 May 2022 11:49:31 -0600 Subject: [PATCH 1/5] modifed metric for multilabel hyperpara optimization --- decavision/model_training/tfrecords_image_classifier.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/decavision/model_training/tfrecords_image_classifier.py b/decavision/model_training/tfrecords_image_classifier.py index 670e272..8bc23dc 100644 --- a/decavision/model_training/tfrecords_image_classifier.py +++ b/decavision/model_training/tfrecords_image_classifier.py @@ -42,7 +42,10 @@ def __init__(self, self.tfrecords_folder = tfrecords_folder self.use_TPU, self.use_GPU = utils.check_PU() self.multilabel = multilabel - self.metric = 'accuracy' + if multilabel: + self.metric = training_utils.f1_score + else: + self.metric = 'accuracy' if self.use_TPU and batch_size % 8: print( 'Batch size {} is not multiple of 8, required for TPU'.format(batch_size)) @@ -312,12 +315,12 @@ def _create_model(self, activation, hidden_size, dropout, l2_lambda): predictions = tf.keras.layers.Activation( 'sigmoid', name='preds')(x) # Output activation loss = 'binary_crossentropy' - metrics = [self.metric, training_utils.f1_score] + metrics = ["accuracy", training_utils.f1_score] else: predictions = tf.keras.layers.Activation( 'softmax', name='preds')(x) # Output activation loss = 'categorical_crossentropy' - metrics = [self.metric] + metrics = ["accuracy"] return tf.keras.Model(inputs=base_model.input, outputs=predictions, name=self.transfer_model), base_model_last_block, loss, metrics From 928d9e250d96a287638dcca8f84daa121e001326 Mon Sep 17 00:00:00 2001 From: Yan Gobeil Date: Thu, 19 May 2022 13:33:13 -0400 Subject: [PATCH 2/5] fix logging and saving of results --- decavision/model_training/tfrecords_image_classifier.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/decavision/model_training/tfrecords_image_classifier.py b/decavision/model_training/tfrecords_image_classifier.py index 8bc23dc..816986b 100644 --- a/decavision/model_training/tfrecords_image_classifier.py +++ b/decavision/model_training/tfrecords_image_classifier.py @@ -469,6 +469,7 @@ def hyperparameter_optimization(self, num_iterations=20, n_random_starts=10, pat logging.StreamHandler() ] ) + logging.getLogger('googleapiclient.discovery_cache').setLevel(logging.ERROR) # declare the hyperparameters search space dim_epochs = skopt.space.Integer(low=1, high=6, name='epochs') dim_hidden_size = skopt.space.Integer( @@ -566,10 +567,8 @@ def fitness(epochs, hidden_size, learning_rate, learning_rate_fine_tuning, dropo if save_results: with open('hyperparameters_dimensions.pickle', 'wb') as f: - dill.dump(dimensions, f) - with open('hyperparameters_search.pickle', 'wb') as f: dill.dump(search_result.x, f) - print("Hyperparameter search saved!") + print("Hyperparameter results saved!") # build results dictionary results_dict = {dimensions[i].name: search_result.x[i] From 7add8300e64bc70f2a71fcc641bfa0249c3d85ce Mon Sep 17 00:00:00 2001 From: mitul23 Date: Thu, 19 May 2022 14:20:13 -0600 Subject: [PATCH 3/5] change f1_score from custom to default --- decavision/model_training/tfrecords_image_classifier.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/decavision/model_training/tfrecords_image_classifier.py b/decavision/model_training/tfrecords_image_classifier.py index 8bc23dc..ef7072b 100644 --- a/decavision/model_training/tfrecords_image_classifier.py +++ b/decavision/model_training/tfrecords_image_classifier.py @@ -43,7 +43,7 @@ def __init__(self, self.use_TPU, self.use_GPU = utils.check_PU() self.multilabel = multilabel if multilabel: - self.metric = training_utils.f1_score + self.metric = "f1_score" else: self.metric = 'accuracy' if self.use_TPU and batch_size % 8: From e7890ffd532578e4d3ebd11ced07dc6e57725c2c Mon Sep 17 00:00:00 2001 From: mitul23 Date: Fri, 20 May 2022 13:56:37 -0600 Subject: [PATCH 4/5] amended docstring --- decavision/model_training/tfrecords_image_classifier.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/decavision/model_training/tfrecords_image_classifier.py b/decavision/model_training/tfrecords_image_classifier.py index c18af55..5398fba 100644 --- a/decavision/model_training/tfrecords_image_classifier.py +++ b/decavision/model_training/tfrecords_image_classifier.py @@ -333,7 +333,7 @@ def fit(self, save_model=None, export_model=None, patience=0, to the pretrained model, with potentially an extra combination of Dense, Dropout and Batchnorm. Only added layers are trained, unless there is some fine tuning, in which case a second round of training is done with the last block of the pretrained model unfrozen. Training can be stopped if - no sufficient improvement in accuracy. + no sufficient improvement in accuracy or f1-score (in case of multilabel classification). If one of the Efficientnet Bs is used, the model includes a layer that normalizes the pixels. This processing step is not included in the other models so it has to be done on the data separately. From 9364b98d0ac81a0cb88e150b2c8108c3c3c7b8e9 Mon Sep 17 00:00:00 2001 From: Yan Gobeil Date: Tue, 24 May 2022 10:33:14 -0400 Subject: [PATCH 5/5] update version of package --- setup.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/setup.py b/setup.py index e289fc7..fab58e3 100644 --- a/setup.py +++ b/setup.py @@ -7,7 +7,7 @@ setuptools.setup( name="decavision", - version="1.4.0", + version="1.4.1", author="Décathlon Canada", author_email="sportvisionapi@decathlon.com", description="A package to easily train powerful image classification models using colab's free TPUs.", @@ -16,6 +16,9 @@ in Google colab notebooks. You can find the full documentation [here](https://decavision-doc.herokuapp.com/) + ## Version 1.4.1 + Fix hyperparameter optimization for multilabel + ## Version 1.4.0 Added multilabel classification