python 使用新訓練好的模型進行分類


6、在python中使用已經訓練好的模型。

Caffe只提供封裝好的imagenet模型,給定一副圖像,直接計算出圖像的特征和進行預測。首先需要下載模型文件

Python代碼如下:

 

from caffe import imagenet
from matplotlib import pyplot
# Set the right path to your model file, pretrained model
# and the image you would like to classify.
MODEL_FILE = 'examples/imagenet_deploy.prototxt'
PRETRAINED = '/home/jiayq/Downloads/caffe_reference_imagenet_model’
IMAGE_FILE = '/home/jiayq/lena.png'
 
net = imagenet.ImageNetClassifier(MODEL_FILE, PRETRAINED) 
#預測
prediction = net.predict(IMAGE_FILE)
#繪制預測圖像
print 'prediction shape:', prediction.shape
pyplot.plot(prediction)
prediction shape: (1000,)
[<matplotlib.lines.Line2D at 0x8faf4d0>] #結果如圖所示


 

 

圖上的橫軸表示的label,縱軸表示在該類別上的概率,有圖我們看到,lena.jpg被分到了”sombrero”這組,結果還算准確。


免責聲明!

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



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