Keras metric produces unexpected values
问题 With some help from a previous question I devised the following implementation of IoU: def iou(y_pred_batch, y_true_batch): intersection = tf.zeros(()) union = tf.zeros(()) y_pred_batch = np.argmax(y_pred_batch, axis=-1) y_true_batch = np.argmax(y_true_batch, axis=-1) for i in range(num_classes): iTensor = tf.to_int64(tf.fill(y_pred_batch.shape, i)) intersection = tf.add(intersection, tf.to_float(tf.count_nonzero(tf.logical_and(K.equal(y_true_batch, y_pred_batch), K.equal(y_true_batch,