Keras之inception_v3使用

1、安装

必要:tensorflow,Keraspython

首次运行须要安装:git

1)下载模型权重   inception_v3_weights_tf_dim_ordering_tf_kernels.h5  github

路径见前一篇app

2)安装h5pyide

pip install h5pycode

3)安装PILorm

 遇到pip没法安装,以pillow替代,见Stack Overflowblog

 

2、参数说明

 

分类结果:

ImageNet的1000种object,对应模型分类结果的1000 classes:ip

text: imagenet 1000 class id to human readable labels

https://github.com/cjyanyi/keras_deep_learning_tutorial/blob/master/imagenet1000_clsid_to_human.txtget

 

3、代码示例

import numpy as np
from keras.preprocessing import image
from keras.applications import inception_v3

   img = image.load_img("xxx.jpg", target_size=(299, 299))
   input_image = image.img_to_array(img)
   input_image /= 255.
   input_image -= 0.5
   input_image *= 2.
   # Add a 4th dimension for batch size (Keras)
   input_image = np.expand_dims(input_image, axis=0)

    # Run the image through the NN
    predictions = model.predict(input_image)

    # Convert the predictions into text
    predicted_classes = inception_v3.decode_predictions(predictions, top=1)
    imagenet_id, name, confidence = predicted_classes[0][0]
    print("This is a {} with {:-4}% confidence!".format(name, confidence * 100))

  

input_image 是一个默认大小:1*299*299*3  的4维向量(列表) 

相关文章
相关标签/搜索