tensorflow.metrics.mean_iou()
currently averages over the iou
of each class. I want to get the iou
of only foreground in for my binary semantic segmentation problem.
I tried using weights
as tf.constant([0.0, 1.0])
but that tf.constant([0.01, 0.99])
but the mean_iou
looks still overflowed as following:
(500, 1024, 1024, 1)
119/5000 [..............................] - ETA: 4536s - loss: 0.3897 - mean_iou: -789716217654962048.0000 - acc: 0.9335
I am using this as metrics
for keras fit_generator
as following:
def mean_iou(y_true, y_pred):
y_pred = tf.to_int32(y_pred > 0.5)
score, up_opt = tf.metrics.mean_iou(y_true, y_pred, 2, weights = tf.constant([0.01, 0.99]))
keras.get_session().run(tf.local_variables_initializer())
with tf.control_dependencies([up_opt]):
score = tf.identity(score)
return score
I will really appreciate any help as I have tried many things, even calculating loss myself using just keras.backend
functions but nothing looks correct.