【发布时间】:2018-02-07 09:31:38
【问题描述】:
似乎已经有几个线程/问题,但在我看来这并没有解决:
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.3 people have suggested 之前使用类似于 control_flow_ops.with_dependencies([up_opt], score) 的东西来实现这一点。这在 TF 1.3 中似乎不再可能了。
总之,我如何评估 Keras 2.0.6 中的 TF 1.3 指标?这似乎是一个非常重要的功能。
【问题讨论】:
-
你解决了吗?
标签: python tensorflow keras tensorflow-gpu keras-2