似乎有要對這個已經有幾個線程/問題,但它不會出現,我認爲這已經得到解決:如何使用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度量?這似乎是一個相當重要的特徵。
沒有你設法解決這個問題? –