Windows下RCNN的使用
RCNN
RCNN存在着重复计算的问题(proposal的region有几千个,多数都是互相重叠,重叠部分会被多次重复提取feature),于是RBG借鉴Kaiming He的SPP-net的思路单枪匹马搞出了Fast-RCNN,跟RCNN最大区别就是Fast-RCNN将proposal的region映射到CNN的最后一层conv layer的feature map上,这样一张图片只需要提取一次feature,大大提高了速度,也由于流程的整合以及其他原因,在VOC2007上的mAP也提高到了68%。
探索是无止境的。Fast-RCNN的速度瓶颈在Region proposal上,于是RBG和Kaiming He一帮人将Region proposal也交给CNN来做,提出了Faster-RCNN。Fater-RCNN中的region proposal netwrok实质是一个Fast-RCNN,这个Fast-RCNN输入的region proposal的是固定的(把一张图片划分成n*n个区域,每个区域给出9个不同ratio和scale的proposal),输出的是对输入的固定proposal是属于背景还是前景的判断和对齐位置的修正(regression)。Region proposal network的输出再输入第二个Fast-RCNN做更精细的分类和Boundingbox的位置修正。Fater-RCNN速度更快了,而且用VGG net作为feature extractor时在VOC2007上mAP能到73%。
个人觉得制约RCNN框架内的方法精度提升的瓶颈是将dectection问题转化成了对图片局部区域的分类问题后,不能充分利用图片局部object在整个图片中的context信息。可能RBG也意识到了这一点,所以他最新的一篇文章YOLO(http://arxiv.org/abs/1506.02640)又回到了regression的方法下,这个方法效果很好,在VOC2007上mAP能到63.4%,而且速度非常快,能达到对视频的实时处理(油管视频:https://www.youtube.com/channel/UC7ev3hNVkx4DzZ3LO19oebg),虽然不如Fast-RCNN,但是比传统的实时方法精度提升了太多,而且我觉得还有提升空间。
安装
1.下载https://github.com/sergeyk/selective_search_ijcv_with_python运行demo编译必要的函数,
复制到<python>\Lib\site-packages\中重命名为selective_search_ijcv_with_python
2.下载ImageNet的RCNN的Caffe模型bvlc_reference_rcnn_ilsvrc13.caffemodel和deploy.prototxt
放到<caffe>\models\bvlc_reference_rcnn_ilsvrc13文件夹
3.将<caffe>\examples\images\fish-bike.jpg复制到<caffe>\Build\x64\Release\pycaffe
4.将caffe_ilsvrc12.tar.gz解压到caffe-windows\data\ilsvrc12
5.将ilsvrc_2012_mean.npy复制到caffe-windows\Build\x64\Release\pycaffe\caffe\imagenet
4.将caffe_ilsvrc12.tar.gz解压到caffe-windows\data\ilsvrc12
5.Cmd到<caffe>\Build\x64\Release\pycaffe目录运行下面代码(det_input.txt 为pycaffe中需要检测的图片名)
python detect.py
--crop_mode=selective_search
--pretrained_model=改成你自己的路径\models\bvlc_reference_rcnn_ilsvrc13\bvlc_reference_rcnn_ilsvrc13.caffemodel
--model_def=改成你自己的路径\models\bvlc_reference_rcnn_ilsvrc13\deploy.prototxt
--gpu
--raw_scale=
C:\Users\改成你自己\Desktop\det_input.txt
C:\Users\改成你自己\Desktop\det_output.h5
6.如果出现错误ValueError: 'axis' entry 2 is out of bounds [-2, 2)
依据https://github.com/BVLC/caffe/issues/2041
将<caffe>\Build\x64\Release\pycaffe\caffe\detector.py第86行的 out[self.outputs[0]].squeeze(axis=(2,3))
修改为 out[self.outputs[0]].squeeze()
7.运行下面python代码获取检测结果
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt df = pd.read_hdf('det_output.h5', 'df')
print(df.shape)
print(df.iloc[0])
with open('a\caffe-windows\data\ilsvrc12\det_synset_words.txt') as f:
labels_df = pd.DataFrame([
{
'synset_id': l.strip().split(' ')[0],
'name': ' '.join(l.strip().split(' ')[1:]).split(',')[0]
}
for l in f.readlines()
])
labels_df.sort_values(by='synset_id')# sort('synset_id')
predictions_df = pd.DataFrame(np.vstack(df.prediction.values), columns=labels_df['name'])
print(predictions_df.iloc[0]) max_s = predictions_df.max(0)
max_s = max_s.sort_values(ascending=False) # Find, print, and display the top detections: person and bicycle.
i = predictions_df[max_s.keys()[0]].argmax() #person
j = predictions_df[max_s.keys()[1]].argmax() #bicycle # Show top predictions for top detection.
f = pd.Series(df['prediction'].iloc[i], index=labels_df['name'])
print('Top detection:')
print(f.sort_values(ascending=False)[:5]) # Show top predictions for second-best detection.
f = pd.Series(df['prediction'].iloc[j], index=labels_df['name'])
print('Second-best detection:')
print(f.sort_values(ascending=False)[:5]) # Show top detection in red, second-best top detection in blue.
im = plt.imread('a\caffe-windows\examples\images\\fish-bike.jpg')
plt.imshow(im)
currentAxis = plt.gca() det = df.iloc[i]
coords = (det['xmin'], det['ymin']), det['xmax'] - det['xmin'], det['ymax'] - det['ymin']
currentAxis.add_patch(plt.Rectangle(*coords, fill=False, edgecolor='r', linewidth=5)) det = df.iloc[j]
coords = (det['xmin'], det['ymin']), det['xmax'] - det['xmin'], det['ymax'] - det['ymin']
currentAxis.add_patch(plt.Rectangle(*coords, fill=False, edgecolor='b', linewidth=5))
plt.show()

输出结果
Top detection:
name
person 1.835771
swimming trunks -1.150371
rubber eraser -1.231106
turtle -1.266038
plastic bag -1.303266
dtype: float32 Second-best detection:
name
bicycle 0.866110
unicycle -0.359140
scorpion -0.811621
lobster -0.982891
lamp -1.096809
dtype: float32
Windows下RCNN的使用的更多相关文章
- Windows下如何采用微软的Caffe配置Faster R-CNN
前言 比较简单的一篇博客.https://github.com/microsoft/caffe 微软的Caffe以在Windows下编译简单而受到了很多人的喜爱(包括我),只用改改prop配置然后无脑 ...
- 如何在Windows下用cpu模式跑通py-faster-rcnn 的demo.py
关键字:Windows.cpu模式.Python.faster-rcnn.demo.py 声明:本篇blog暂时未经二次实践验证,主要以本人第一次配置过程的经验写成.计划在7月底回家去电脑城借台机子试 ...
- Windows下用cpu模式跑通目标检测py-faster-rcnn 的demo.py
关键字:Windows.cpu模式.Python.faster-rcnn.demo.py 声明:原文发表在博客园,未经允许不得转载!!!本篇blog过程已经多名读者实践验证,有人反馈报错TypeErr ...
- Faster_Rcnn在windows下运行踩坑总结
Faster_Rcnn在windows下运行踩坑总结 20190524 今天又是元气满满的一天! 1.代码下载 2.编译 3.下载数据集 4.下载pre-train Model 5.运行train ...
- CNN:Windows下编译使用Caffe和Caffe2
用于检测的CNN分为基于回归网络的方法和基于区域+CNN网络的方法,其中基于回归网络的方法典型为YOLO9000,可以兼容使用VGG-Net框架.其中基于区域+CNN网络方法,大量使用了Caffe作为 ...
- 在windows下安装gulp —— 基于 Gulp 的前端集成解决方案(一)
相关连接导航 在windows下安装gulp —— 基于 Gulp 的前端集成解决方案(一) 执行 $Gulp 时发生了什么 —— 基于 Gulp 的前端集成解决方案(二) 常用 Gulp 插件汇总 ...
- 让 windows 下的命令行程序 cmd.exe 用起来更顺手
在 Windows 下使用 Larave 框架做开发,从 Composer 到 artisan 总是避免不了和 cmd.exe 打交道,系统默认的命令行界面却是不怎么好看,且每行显示的字符数是做了限制 ...
- Windows下Visual studio 2013 编译 Audacity
编译的Audacity版本为2.1.2,由于实在windows下编译,其源代码可以从Github上取得 git clone https://github.com/audacity/audacity. ...
- Windows下Nginx配置SSL实现Https访问(包含证书生成)
Vincent.李 Windows下Nginx配置SSL实现Https访问(包含证书生成) Windows下Nginx配置SSL实现Https访问(包含证书生成) 首先要说明为什么要实现https ...
随机推荐
- havok之内存管理
[现象记录] 1.往world和rb里都各自加入一个entityListener,当这个rb被remove掉之后, 会首先调用world里的listener的removecallback, 再调用rb ...
- SVN+Apache域用户认证配置方法_Windows(转,重新排版,部分内容更新优化)
欢迎和大家交流技术相关问题: 邮箱: jiangxinnju@163.com 博客园地址: http://www.cnblogs.com/jiangxinnju GitHub地址: https://g ...
- git: No refs in common and none specified; doing no
用gitolite新建项目,clone后首次push,可能会出现: $ git push No refs in common and none specified; doing nothing ...
- Android doc打开太慢
C:\Windows\System32\drivers\etc\HOSTS 127.0.0.1 fonts.googleapis.com 127.0.0.1 www.google.com 127.0. ...
- bzoj1211: prufer序列 | [HNOI2004]树的计数
题目大意: 告诉你树上每个节点的度数,让你构建出这样一棵树,问能够构建出树的种树 这里注意数量为0的情况,就是 当 n=1时,节点度数>0 n>1时,所有节点度数相加-n!=n-2 可以通 ...
- Java String.split()用法小结
在java.lang包中有String.split()方法,返回是一个数组 我在应用中用到一些,给大家总结一下,仅供大家参考: 1.如果用“.”作为分隔的话,必须是如下写法,String.split( ...
- 正则表达式 java
如果你曾经用过Perl或任何其他内建正则表达式支持的语言,你一定知道用正则表达式处理文本和匹配模式是多么简单.如果你不熟悉这个术语,那么"正则表达式"(Regular Expres ...
- JVM-程序编译与代码晚期(运行期)优化
晚期(运行期)优化 1.为了提高热点代码的执行效率,在运行时,虚拟机将会把这些代码编译成与本地平台相关的机器码,并进行各种层次的优化,完成这个任务的编译器称为即时编译器(Just In Time,JI ...
- 判断CAD图纸版本
判断CAD图纸版本Dwg文件版本 使用记事本打开DWG图纸文件,在最开始有6个字母和数字组合,即为图纸的版本号 AC1015:CAD2000版本: AC1018:CAD2004版本: AC1021:C ...
- 当一个activity中按钮过多时怎么办?
这几天看极客学院的视频,跟视频中的老师学到的一些小技巧~~ .setOnClickListener(this) 通过重写this(我猜的是重写),下面有onClicked() package exam ...