mirror of
https://github.com/sbrl/research-rainfallradar
synced 2024-11-24 18:23:01 +00:00
dlr: fixup argmax & y_true/y_pred
This commit is contained in:
parent
bc734a29c6
commit
5472729f5e
3 changed files with 1 additions and 30 deletions
|
@ -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_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_true = tf.cast(y_true, dtype=tf.float32)
|
||||||
y_pred = tf.cast(y_pred, dtype=tf.float32)
|
y_pred = tf.cast(y_pred, dtype=tf.float32)
|
||||||
|
|
||||||
|
|
|
@ -4,36 +4,9 @@ import tensorflow as tf
|
||||||
|
|
||||||
def sensitivity(y_true, y_pred):
|
def sensitivity(y_true, y_pred):
|
||||||
y_pred = tf.math.argmax(y_pred, axis=-1)
|
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_true = tf.cast(y_true, dtype=tf.float32)
|
||||||
y_pred = tf.cast(y_pred, dtype=tf.float32)
|
y_pred = tf.cast(y_pred, dtype=tf.float32)
|
||||||
|
|
||||||
recall = tf.keras.metrics.Recall()
|
recall = tf.keras.metrics.Recall()
|
||||||
recall.update_state(y_true, y_pred)
|
recall.update_state(y_true, y_pred)
|
||||||
return recall.result()
|
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
|
|
||||||
|
|
|
@ -3,7 +3,7 @@ import math
|
||||||
import tensorflow as tf
|
import tensorflow as tf
|
||||||
|
|
||||||
|
|
||||||
def specificity(y_pred, y_true):
|
def specificity(y_true, y_pred):
|
||||||
"""An implementation of the specificity.
|
"""An implementation of the specificity.
|
||||||
In other words, a measure of how many of the true negatives were accurately predicted
|
In other words, a measure of how many of the true negatives were accurately predicted
|
||||||
@source https://datascience.stackexchange.com/a/40746/86851
|
@source https://datascience.stackexchange.com/a/40746/86851
|
||||||
|
@ -14,7 +14,6 @@ def specificity(y_pred, y_true):
|
||||||
Specificity score
|
Specificity score
|
||||||
"""
|
"""
|
||||||
y_pred = tf.math.argmax(y_pred, axis=-1)
|
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_true = tf.cast(y_true, dtype=tf.float32)
|
||||||
y_pred = tf.cast(y_pred, dtype=tf.float32)
|
y_pred = tf.cast(y_pred, dtype=tf.float32)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue