栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Python

keras预训练模型的加载

Python 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

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后端

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/870332.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号