当前位置:   article > 正文

keras预训练模型的加载_from keras.applications import

from keras.applications import
  1. from keras.applications import ResNet50,VGG16,InceptionV3,MobileNet
  2. from keras.preprocessing import image
  3. from keras.applications.resnet50 import preprocess_input, decode_predictions
  4. import numpy as np
  5. res_path = 'G:\\python_work1\\learn\\weights\\keras_h5\\resnet50_weights_tf_dim_ordering_tf_kernels_notop.h5'
  6. vgg_path = 'G:\\python_work1\\learn\\weights\\keras_h5\\vgg16_weights_tf_dim_ordering_tf_kernels.h5'
  7. inc_path = 'G:\\python_work1\\learn\\weights\\keras_h5\\inception_v3_weights_tf_dim_ordering_tf_kernels (1).h5'
  8. mbs_path = 'G:\\python_work1\\learn\\weights\\keras_h5\\mobilenet_1_0_224_tf.h5'
  9. #不包含最后的分类层的时候要让include_top = False,权重文件也要选不带top的
  10. #当报错 original_keras_version = f.attrs['keras_version'].decode('utf8'),可能是h5py版本太高,重新安装2.10版本的
  11. res = ResNet50(weights=res_path,include_top = False)
  12. res.summary()
  13. vgg = VGG16(weights = vgg_path)
  14. vgg.summary()
  15. inc = InceptionV3(weights = inc_path)
  16. inc.summary()
  17. mbs = MobileNet(weights = mbs_path)
  18. mbs.summary()

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

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

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

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

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/不正经/article/detail/103892?site
推荐阅读
相关标签
  

闽ICP备14008679号