From e0a5ae8674d982a2b8ed1009db32a9bad49f9277 Mon Sep 17 00:00:00 2001 From: tomrink <rink@ssec.wisc.edu> Date: Wed, 19 May 2021 11:00:56 -0500 Subject: [PATCH] minor... --- modules/deeplearning/icing_cnn.py | 46 +++++++++++++++++-------------- 1 file changed, 25 insertions(+), 21 deletions(-) diff --git a/modules/deeplearning/icing_cnn.py b/modules/deeplearning/icing_cnn.py index aee3e3b5..8f33d0c3 100644 --- a/modules/deeplearning/icing_cnn.py +++ b/modules/deeplearning/icing_cnn.py @@ -150,6 +150,8 @@ class IcingIntensityNN: self.test_recall = None self.test_precision = None self.test_confusion_matrix = None + self.test_f1score = None + self.test_mcc = None self.test_true_pos = None self.test_true_neg = None self.test_false_pos = None @@ -483,6 +485,8 @@ class IcingIntensityNN: self.test_auc = tf.keras.metrics.AUC(name='test_auc') self.test_recall = tf.keras.metrics.Recall(name='test_recall') self.test_precision = tf.keras.metrics.Precision(name='test_precision') + self.test_f1score = tfa.metrics.F1Score(2, threshold=0.5, name='test_f1score') + self.test_mcc = tfa.metrics.MatthewsCorrelationCoefficient(2, name='test_mcc') self.test_true_neg = tf.keras.metrics.TrueNegatives(name='test_true_neg') self.test_true_pos = tf.keras.metrics.TruePositives(name='test_true_pos') self.test_false_neg = tf.keras.metrics.FalseNegatives(name='test_false_neg') @@ -542,6 +546,8 @@ class IcingIntensityNN: self.test_true_pos(labels, pred) self.test_false_neg(labels, pred) self.test_false_pos(labels, pred) + self.test_f1score(labels, pred) + self.test_mcc(labels, pred) def predict(self, mini_batch): inputs = [mini_batch[0]] @@ -562,6 +568,22 @@ class IcingIntensityNN: self.test_false_neg(labels, pred) self.test_false_pos(labels, pred) + def reset_test_metrics(self): + self.test_loss.reset_states() + self.test_accuracy.reset_states() + self.test_auc.reset_states() + self.test_recall.reset_states() + self.test_precision.reset_states() + self.test_f1score.reset_states() + self.test_mcc.reset_states() + self.test_true_neg.reset_states() + self.test_true_pos.reset_states() + self.test_false_neg.reset_states() + self.test_false_pos.reset_states() + + def do_metrics(self): + pass + def do_training(self, ckpt_dir=None): if ckpt_dir is None: @@ -602,16 +624,7 @@ class IcingIntensityNN: tf.summary.scalar('num_train_steps', step, step=step) tf.summary.scalar('num_epochs', epoch, step=step) - self.test_loss.reset_states() - self.test_accuracy.reset_states() - self.test_auc.reset_states() - self.test_recall.reset_states() - self.test_precision.reset_states() - self.test_true_neg.reset_states() - self.test_true_pos.reset_states() - self.test_false_neg.reset_states() - self.test_false_pos.reset_states() - + self.reset_test_metrics() for data0_tst, label_tst in self.test_dataset: tst_ds = tf.data.Dataset.from_tensor_slices((data0_tst, label_tst)) tst_ds = tst_ds.batch(BATCH_SIZE) @@ -653,16 +666,7 @@ class IcingIntensityNN: print('End of Epoch: ', epoch+1, 'elapsed time: ', (t1-t0)) total_time += (t1-t0) - self.test_loss.reset_states() - self.test_accuracy.reset_states() - self.test_auc.reset_states() - self.test_recall.reset_states() - self.test_precision.reset_states() - self.test_true_neg.reset_states() - self.test_true_pos.reset_states() - self.test_false_neg.reset_states() - self.test_false_pos.reset_states() - + self.reset_test_metrics() for data0, label in self.test_dataset: ds = tf.data.Dataset.from_tensor_slices((data0, label)) ds = ds.batch(BATCH_SIZE) @@ -681,7 +685,7 @@ class IcingIntensityNN: mcc = ((tp*tn) - (fp*fn))/np.sqrt((tp+fp)*(tp+fn)*(tn+fp)*(tn+fn)) print('loss, acc, recall, precision, auc, f1, mcc: ', self.test_loss.result().numpy(), self.test_accuracy.result().numpy(), - recall, precsn, self.test_auc.result().numpy(), f1, mcc) + recall, precsn, self.test_auc.result().numpy(), f1, self.test_f1score.result().numpy(), mcc, self.test_mcc.result().numpy()) print('--------------------------------------------------') ckpt_manager.save() -- GitLab