[英]How to get top K predictions using Keras
I finished training a model with Keras, but I have a problem that I can't get the top K results.我用 Keras 完成了一个模型的训练,但我有一个问题,我无法获得前 K 个结果。 I know there is a function called
tf.nn.top_k
in tensorflow, but how can I use it in Keras?我知道
tf.nn.top_k
中有一个名为tf.nn.top_k
的函数,但是我如何在 Keras 中使用它?
You can try with the below code.您可以尝试使用以下代码。
y_preds = self.model.predict(x)
y_preds = np.argsort(y_preds, axis=1)[:,-n:]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.