dlr: fixup argmax & y_true/y_pred

This commit is contained in:
Starbeamrainbowlabs 2023-03-03 22:37:36 +00:00
parent bc734a29c6
commit 5472729f5e
Signed by: sbrl
GPG key ID: 1BE5172E637709C2
3 changed files with 1 additions and 30 deletions

View file

@ -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)

View file

@ -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

View file

@ -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)