似乎有要对这个已经有几个线程/问题,但它不会出现,我认为这已经得到解决:如何使用TensorFlow指标在Keras
How can I use tensorflow metric function within keras models?
https://github.com/fchollet/keras/issues/6050
https://github.com/fchollet/keras/issues/3230
人们似乎遇到变量初始化或度量标准为0的问题。
我需要计算不同的细分指标,并希望在我的Keras模型中包含tf.metric.mean_iou。这是我已经能够拿出迄今最好的:
def mean_iou(y_true, y_pred):
score, up_opt = tf.metrics.mean_iou(y_true, y_pred, NUM_CLASSES)
K.get_session().run(tf.local_variables_initializer())
return score
model.compile(optimizer=adam, loss='categorical_crossentropy', metrics=[mean_iou])
此代码不抛出任何错误,但总是mean_iou返回0。我相信这是因为up_opt未评估。我已经看到,在TF 1.之前使用的东西沿着control_flow_ops.with_dependencies([up_opt],得分)的行来实现这一点。这在TF 1.3中似乎不可能了。
总之,如何评估Keras 2.0.6中的TF 1.3度量?这似乎是一个相当重要的特征。
没有你设法解决这个问题? –