码迷,mamicode.com
首页 > 编程语言 > 详细

python 使用新训练好的模型进行分类

时间:2015-08-05 20:22:00      阅读:602      评论:0      收藏:0      [点我收藏+]

标签:

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”这组,结果还算准确。

python 使用新训练好的模型进行分类

标签:

原文地址:http://www.cnblogs.com/airlove/p/4705603.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!