简体   繁体   English

如何使用 Keras 获得前 K 个预测

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM