写python代码案例_keras topN显示,自编写代码案例

本文展示了如何使用自定义代码解析Keras模型的预测结果,以MNIST数据集为例,创建了一个简单的模型并进行预测。同时,还提供了去噪自编码器的实现,并使用了早停策略进行训练。
摘要由CSDN通过智能技术生成

对于使用已经训练好的模型,比如VGG,RESNET等,keras都自带了一个keras.applications.imagenet_utils.decode_predictions的方法,有很多限制:

def decode_predictions(preds, top=5):

"""Decodes the prediction of an ImageNet model.

# Arguments

preds: Numpy tensor encoding a batch of predictions.

top: Integer, how many top-guesses to return.

# Returns

A list of lists of top class prediction tuples

`(class_name, class_description, score)`.

One list of tuples per sample in batch input.

# Raises

ValueError: In case of invalid shape of the `pred` array

(must be 2D).

"""

global CLASS_INDEX

if len(preds.shape) != 2 or preds.shape[1] != 1000:

raise ValueError('`decode_predictions` expects '

'a batch of predictions '

'(i.e. a 2D array of shape (s

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值