Keras之inception_v3使用


一、安裝

必要:tensorflow,Keras

首次運行需要安裝:

1)下載模型權重   inception_v3_weights_tf_dim_ordering_tf_kernels.h5  

路徑見前一篇

2)安裝h5py

pip install h5py

3)安裝PIL

 遇到pip無法安裝,以pillow替代,見Stack Overflow

 

二、參數說明

 

分類結果:

ImageNet的1000種object,對應模型分類結果的1000 classes:

text: imagenet 1000 class id to human readable labels

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

 

三、代碼示例

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維向量(列表) 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM