From 5472729f5ed66075ac51b3cace2c45a4761ba663 Mon Sep 17 00:00:00 2001 From: Starbeamrainbowlabs Date: Fri, 3 Mar 2023 22:37:36 +0000 Subject: [PATCH] dlr: fixup argmax & y_true/y_pred --- .../src/lib/ai/components/MetricMeanIoU.py | 1 - .../lib/ai/components/MetricSensitivity.py | 27 ------------------- .../lib/ai/components/MetricSpecificity.py | 3 +-- 3 files changed, 1 insertion(+), 30 deletions(-) diff --git a/aimodel/src/lib/ai/components/MetricMeanIoU.py b/aimodel/src/lib/ai/components/MetricMeanIoU.py index b1b2dfb..1fa2947 100644 --- a/aimodel/src/lib/ai/components/MetricMeanIoU.py +++ b/aimodel/src/lib/ai/components/MetricMeanIoU.py @@ -14,7 +14,6 @@ def one_hot_mean_iou(y_true, y_pred, classes=2): """ y_pred = tf.math.argmax(y_pred, axis=-1) - y_true = tf.math.argmax(y_true, axis=-1) y_true = tf.cast(y_true, dtype=tf.float32) y_pred = tf.cast(y_pred, dtype=tf.float32) diff --git a/aimodel/src/lib/ai/components/MetricSensitivity.py b/aimodel/src/lib/ai/components/MetricSensitivity.py index ce9f359..be435e9 100644 --- a/aimodel/src/lib/ai/components/MetricSensitivity.py +++ b/aimodel/src/lib/ai/components/MetricSensitivity.py @@ -4,36 +4,9 @@ import tensorflow as tf def sensitivity(y_true, y_pred): y_pred = tf.math.argmax(y_pred, axis=-1) - y_true = tf.math.argmax(y_true, axis=-1) y_true = tf.cast(y_true, dtype=tf.float32) y_pred = tf.cast(y_pred, dtype=tf.float32) recall = tf.keras.metrics.Recall() recall.update_state(y_true, y_pred) return recall.result() - -class MetricSensitivity(tf.keras.metrics.Metric): - """An implementation of the sensitivity. - Also known as Recall. In other words, how many of the true positives were accurately predicted. - @source - Args: - smooth (float): The batch size (currently unused). - """ - - def __init__(self, name="sensitivity", **kwargs): - super(MetricSensitivity, self).__init__(name=name) - - self.recall = tf.keras.metrics.Recall(**kwargs) - - def call(self, y_true, y_pred): - ground_truth = tf.cast(y_true, dtype=tf.float32) - prediction = tf.cast(y_pred, dtype=tf.float32) - - return self.recall(y_true, y_pred) - - def get_config(self): - config = super(MetricSensitivity, self).get_config() - config.update({ - - }) - return config diff --git a/aimodel/src/lib/ai/components/MetricSpecificity.py b/aimodel/src/lib/ai/components/MetricSpecificity.py index e2fa021..e5fb9c8 100644 --- a/aimodel/src/lib/ai/components/MetricSpecificity.py +++ b/aimodel/src/lib/ai/components/MetricSpecificity.py @@ -3,7 +3,7 @@ import math import tensorflow as tf -def specificity(y_pred, y_true): +def specificity(y_true, y_pred): """An implementation of the specificity. In other words, a measure of how many of the true negatives were accurately predicted @source https://datascience.stackexchange.com/a/40746/86851 @@ -14,7 +14,6 @@ def specificity(y_pred, y_true): Specificity score """ y_pred = tf.math.argmax(y_pred, axis=-1) - y_true = tf.math.argmax(y_true, axis=-1) y_true = tf.cast(y_true, dtype=tf.float32) y_pred = tf.cast(y_pred, dtype=tf.float32)