Python模型库keras中Keras application探索及实战

Keras是一个比较好用的Python深度学习库,其中keras-application包含了一些常用的深度学习模型,ResNet50网络/VGG16/VGG19/fine-tune inceptionV3/tensor上构建InceptionV3等,本文通过利用ResNet50网络进行ImageNet分类。

第一部分:环境准备

准备工作:win10+pycharm+python3+anaconda3

安装keras库,参考命令如下:

命令1(通过anaconda搜索满足当前环境的Keras):

anaconda search -t conda keras

命令2(选择一个满足条件的keras库):

anaconda show anaconda/keras

命令3(上面命令会返回这个安装命令):

conda install --channel https://conda.anaconda.org/anaconda keras

 

要分类的图为一头大象,测试是什么大象?

Young rescued elephant in Knysna Elephant Park, South Africa

第二部分:利用ResNet50网络进行ImageNet分类案例Demo

from keras.applications.resnet50 import ResNet50

from keras.preprocessing import image

from keras.applications.resnet50 import preprocess_input, decode_predictions

import numpy as np

model = ResNet50(weights='imagenet')  #这个地方要到亚马逊下载一个josn文件

img_path = 'image/elephant.jpg'    #找一张图片放到项目中

img = image.load_img(img_path, target_size=(224, 224))

x = image.img_to_array(img)

x = np.expand_dims(x, axis=0)

x = preprocess_input(x)

 

preds = model.predict(x)

# decode the results into a list of tuples (class, description, probability)

# (one such list for each sample in the batch)

print('Predicted:', decode_predictions(preds, top=3)[0])

文件位置:F:\TensorFlow\tensorFlow-study\keraApplications.py

第三部分:程序运行结果

通过IDEA的Run运行该程序,输出的结果如下所示:

Downloading data from https://s3.amazonaws.com/deep-learning-models/image-models/imagenet_class_index.json

8192/35363 [=====>........................] - ETA: 2s

24576/35363 [===================>..........] - ETA: 0s

40960/35363 [==================================] - 1s 31us/step

Predicted: [('n02504458', 'African_elephant', 0.90385997), ('n01871265', 'tusker', 0.074723713), ('n02504013', 'Indian_elephant', 0.01534137)]

第四部分:其它的案例

1、利用VGG16提取特征

2、从VGG19的任意中间层中抽取特征

3、在新类别上fine-tune inceptionV3

4、在定制的输入tensor上构建InceptionV3

第五部分:Keras-Application提供模型信息详细参数比较

参考网址:http://keras-cn.readthedocs.io/en/latest/other/application/

 

本地位置:F:\深度学习相关资料\keras\keras_weights

百度网盘位置:https://pan.baidu.com/s/1geHmOpH#list/path=%2F

第六部分:参考及关联网址

Eager Execution 使用入门:https://tensorflow.google.cn/get_started/eager

Keras官网:https://keras.io/

Keras中几个重要函数用法:https://blog.csdn.net/u012969412/article/details/70882296

Keras序贯模型:http://keras-cn.readthedocs.io/en/latest/getting_started/sequential_model/

Keras函数式模型:http://keras-cn.readthedocs.io/en/latest/getting_started/functional_API/

Keras模型:https://keras.io/models/model/

Keras预训练模型Application:http://keras-cn.readthedocs.io/en/latest/other/application/

Keras Application训练好的模型下载:

https://pan.baidu.com/s/1geHmOpH#list/path=%2F&parentPath=%2F

keras系列︱Application中五款已训练模型、VGG16框架(Sequential式、Model式)解读:https://blog.csdn.net/u011746554/article/details/74394211

keras中application模型可视化:https://blog.csdn.net/nima1994/article/details/80613588

Keras FAQ: Frequently Asked Keras Questions:https://keras.io/getting-started/faq/

Visual Geometry Group(网络深度评估):

http://www.robots.ox.ac.uk/~vgg/research/very_deep/

 

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: