I am trying to find test accuracy using the confusion matrix in UNet Model.
But keep getting an error of y_true and y_pred are not defined even though they are already defined globally.
Here:
global y_true
global y_pred
def dice_coeff(y_true, y_pred):
smooth = 1.
# Flatten
y_true_f = tf.reshape(y_true, [-1])
y_pred_f = tf.reshape(y_pred, [-1])
intersection = tf.reduce_sum(y_true_f * y_pred_f)
score = (2. * intersection + smooth) / (tf.reduce_sum(y_true_f) + tf.reduce_sum(y_pred_f) + smooth)
def dice_loss(y_true, y_pred):
loss = 1 - dice_coeff(y_true, y_pred)
return loss
def bce_dice_loss(y_true, y_pred):
loss = losses.binary_crossentropy(y_true, y_pred) + dice_loss(y_true, y_pred)
return loss
And I am getting the error in this code as y_true and y_pred are not defined.
from sklearn.metrics import confusion_matrix
cm = confusion_matrix(y_true,y_pred)
Can anyone suggest how to overcome this error or is there any other way to find the model prediction accuracy?