caffe 使用python测试ImageNet classification
2014-12-27 10:32
330 查看
环境:ubutun 14.04 caffe
1.首先要确保caffe已经编译成功,如果没有可以参考:
http://blog.csdn.net/huangshanchun/article/details/41276901
首先安装pip和python-dev (系统默认有python环境的, 不过我们需要的使python-dev)
然后执行如下命令安装编译caffe python wrapper 所需要的额外包
在执行上述命令时, 会报错导致不能完全安装所有需要的包(我这里就安装出错了)。 可以按照官方建议安装anaconda包。 在anaconda官网下载.sh文件,执行,最后添加bin目录到环境变量即可。
2.
如果有问题参考:http://blog.csdn.net/huangshanchun/article/details/42083985
3. 下载model后放到相应的位置,但是你要知道具体路径(编程时候要用)
bvlc_reference_caffenet.caffemodel
下载地址:
http://dl.caffe.berkeleyvision.org/
4.执行这个命令后
测试代码:
参考文献:
http://nbviewer.ipython.org/github/BVLC/caffe/blob/master/examples/classification.ipynb
1.首先要确保caffe已经编译成功,如果没有可以参考:
http://blog.csdn.net/huangshanchun/article/details/41276901
首先安装pip和python-dev (系统默认有python环境的, 不过我们需要的使python-dev)
sudo apt-get install python-dev python-pip
然后执行如下命令安装编译caffe python wrapper 所需要的额外包
sudo pip install -r /path/to/caffe/python/requirements.txt
在执行上述命令时, 会报错导致不能完全安装所有需要的包(我这里就安装出错了)。 可以按照官方建议安装anaconda包。 在anaconda官网下载.sh文件,执行,最后添加bin目录到环境变量即可。
2.
执行命令:ipython qtconsole --pylab=inline
如果有问题参考:http://blog.csdn.net/huangshanchun/article/details/42083985
3. 下载model后放到相应的位置,但是你要知道具体路径(编程时候要用)
bvlc_reference_caffenet.caffemodel
下载地址:
http://dl.caffe.berkeleyvision.org/
4.执行这个命令后
ipython qtconsole --pylab=inline
测试代码:
import matplotlib.pyplot as plt %matplotlib inline caffe_root = '/home/hsc/caffe-master/' #caffe主目录 sys.path.append(caffe_root+'python') import caffe model_file = caffe_root+'/models/bvlc_reference_caffenet/deploy.prototxt' pretrained = caffe_root+'/models/bvlc_reference_caffenet/bvlc_reference_caffenet.caffemodel' image_file = caffe_root+'examples/images/cat.jpg' npload = caffe_root+ 'python/caffe/imagenet/ilsvrc_2012_mean.npy' import caffe net = caffe.Classifier(model_file, pretrained,maaaaean=np.load(npload),channel_swap=(2,1,0),raw_scale=255,image_dims=(256, 256)) net.set_phase_test() net.set_mode_gpu()#如果没有gpu net.set_mode_cpu() input_image = caffe.io.load_image(image_file) plt.imshow(input_image) <span style="color:#FF0000;">#下面程序在出现In[2]再执行</span> prediction = net.predict([input_image]) # predict takes any number of images, and formats them for the Caffe net automatically print 'prediction shape:', prediction[0].shape plt.plot(prediction[0]) print 'predicted class:', prediction[0].argmax() prediction = net.predict([input_image], oversample=False) print 'prediction shape:', prediction[0].shape plt.plot(prediction[0]) print 'predicted class:', prediction[0].argmax()程序中所给的文件路径都都需要给自己不同做出修改。
参考文献:
http://nbviewer.ipython.org/github/BVLC/caffe/blob/master/examples/classification.ipynb
相关文章推荐
- caffe 使能python接口使用draw_net.py绘制网络结构图过程
- caffe (10) 使用python测试多张图片统计分类结果
- 使用自己的数据集训练和测试"caffenet"
- caffe python net_spec/使用
- Caffe下python环境的编译和使用draw_net.py绘制lenet网络结构图
- 使用caffe的Python接口进行训练测试
- 使用caffe 的 python接口测试数据,选定GPU编号
- 【神经网络与深度学习】【python开发】caffe-windows使能python接口使用draw_net.py绘制网络结构图过程
- caffe 使能python接口使用draw_net.py绘制网络结构图过程
- caffe的python接口中的draw_net.py使用时,错误提示及解决办法
- VB.Net程序代码:Hashtable与ListView结合使用测试例子
- 使用 Windows CE .NET 测试工具包 (CETK) 构建和测试设备
- 使用MailMessage和SmtpClient类实现asp.net的邮件发送(有详细注释并已测试通过)
- 针对ASP.NET页面实时进行GZIP压缩优化的几款压缩模块的使用简介及应用测试(转载)
- asp.net 导出Excel方法测试使用
- .Net中Freetextbox_1.6.3的使用与ftb.imagegallery.aspx安全修正
- 使用ASP.NET Image Generation生成图片缩略图及水印
- 梅花雨时间控件在asp.net中的使用,平台为2005(注:未在有模板的情形下进行测试)
- [转]针对ASP.NET页面实时进行GZIP压缩优化的几款压缩模块的使用简介及应用测试!(附源码)
- 使用selenim作为项目测试框架,适用asp.net c# 网站测试