keras预训练模型的加载


from keras.applications import ResNet50,VGG16,InceptionV3,MobileNet
from keras.preprocessing import image
from keras.applications.resnet50 import preprocess_input, decode_predictions
import numpy as np

res_path = 'G:\\python_work1\\learn\\weights\\keras_h5\\resnet50_weights_tf_dim_ordering_tf_kernels_notop.h5'
vgg_path = 'G:\\python_work1\\learn\\weights\\keras_h5\\vgg16_weights_tf_dim_ordering_tf_kernels.h5'
inc_path = 'G:\\python_work1\\learn\\weights\\keras_h5\\inception_v3_weights_tf_dim_ordering_tf_kernels (1).h5'
mbs_path = 'G:\\python_work1\\learn\\weights\\keras_h5\\mobilenet_1_0_224_tf.h5'

#不包含最后的分类层的时候要让include_top = False,权重文件也要选不带top的
#当报错 original_keras_version = f.attrs['keras_version'].decode('utf8'),可能是h5py版本太高,重新安装2.10版本的

res = ResNet50(weights=res_path,include_top = False)
res.summary()


vgg = VGG16(weights =  vgg_path)
vgg.summary()


inc = InceptionV3(weights = inc_path)
inc.summary()


mbs = MobileNet(weights = mbs_path)
mbs.summary()

这里加载4种模型ResNet50,VGG16,InceptionV3,MobileNet,上面那些路径就是你自己把权重文件下载到自己电脑里的路径,根据自己的情况改

下载权重文件的时候要注意下载正确的权重文件:

        1.注意文件名尾部是否带notop,如果有说明没有分类头

        2.注意文件名的中间是‘tf’还是‘th’,'tf'代表tensorflow后端,'th'代表theano后端

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值