function script_faster_rcnn_demo()
close all; clc; clear mex; clear is_valid_handle; % to clear init_key
run(fullfile(fileparts(fileparts(mfilename('fullpath'))), 'startup'));
%% -------------------- CONFIG --------------------
opts.caffe_version = 'caffe_faster_rcnn';
opts.gpu_id = auto_select_gpu;
active_caffe_mex(opts.gpu_id, opts.caffe_version); opts.per_nms_topN = 6000;
opts.nms_overlap_thres = 0.7;
opts.after_nms_topN = 300;
opts.use_gpu = true; opts.test_scales = 600; %% -------------------- INIT_MODEL --------------------
% model_dir = fullfile(pwd, 'output', 'faster_rcnn_final', 'faster_rcnn_VOC0712_vgg_16layers'); %% VGG-16
model_dir = fullfile(pwd, 'output', 'faster_rcnn_final', 'faster_rcnn_VOC0712_ZF'); %% ZF
proposal_detection_model = load_proposal_detection_model(model_dir); proposal_detection_model.conf_proposal.test_scales = opts.test_scales;
proposal_detection_model.conf_detection.test_scales = opts.test_scales;
if opts.use_gpu
proposal_detection_model.conf_proposal.image_means = gpuArray(proposal_detection_model.conf_proposal.image_means);
proposal_detection_model.conf_detection.image_means = gpuArray(proposal_detection_model.conf_detection.image_means);
end % caffe.init_log(fullfile(pwd, 'caffe_log'));
% proposal net
rpn_net = caffe.Net(proposal_detection_model.proposal_net_def, 'test');
rpn_net.copy_from(proposal_detection_model.proposal_net);
% fast rcnn net
fast_rcnn_net = caffe.Net(proposal_detection_model.detection_net_def, 'test');
fast_rcnn_net.copy_from(proposal_detection_model.detection_net); % set gpu/cpu
if opts.use_gpu
caffe.set_mode_gpu();
else
caffe.set_mode_cpu();
end %% -------------------- WARM UP --------------------
% the first run will be slower; use an empty image to warm up for j = 1:2 % we warm up 2 times
im = uint8(ones(375, 500, 3)*128);
if opts.use_gpu
im = gpuArray(im);
end
[boxes, scores] = proposal_im_detect(proposal_detection_model.conf_proposal, rpn_net, im);
aboxes = boxes_filter([boxes, scores], opts.per_nms_topN, opts.nms_overlap_thres, opts.after_nms_topN, opts.use_gpu);
if proposal_detection_model.is_share_feature
[boxes, scores] = fast_rcnn_conv_feat_detect(proposal_detection_model.conf_detection, fast_rcnn_net, im, ...
rpn_net.blobs(proposal_detection_model.last_shared_output_blob_name), ...
aboxes(:, 1:4), opts.after_nms_topN);
else
[boxes, scores] = fast_rcnn_im_detect(proposal_detection_model.conf_detection, fast_rcnn_net, im, ...
aboxes(:, 1:4), opts.after_nms_topN);
end
end %% -------------------- TESTING --------------------
% im_names = {'001763.jpg', '004545.jpg', '000542.jpg', '000456.jpg', '001150.jpg'};
% these images can be downloaded with fetch_faster_rcnn_final_model.m
image_path = '/media/wangxiao/Elements/image_segment_backup/ImagesData223/Pedestrian/172.19.199.223/';
file1 = dir(image_path); for ii = 3:size(file1, 1)
new_path1 = [image_path, file1(ii).name, '/'];
file2 = dir(new_path1);
for jj = 3:size(file2, 1)
new_path2 = [new_path1, file2(jj).name, '/'];
file3 = dir(new_path2);
for kk = 3:size(file3, 1)
im = imread([new_path2, file3(kk).name]);
running_time = [];
% for j = 1:length(im_names)
% im = imread(fullfile(pwd, im_names{j})); if opts.use_gpu
im = gpuArray(im);
end % test proposal
th = tic();
[boxes, scores] = proposal_im_detect(proposal_detection_model.conf_proposal, rpn_net, im);
t_proposal = toc(th);
th = tic();
aboxes = boxes_filter([boxes, scores], opts.per_nms_topN, opts.nms_overlap_thres, opts.after_nms_topN, opts.use_gpu);
t_nms = toc(th); % test detection
th = tic();
if proposal_detection_model.is_share_feature
[boxes, scores] = fast_rcnn_conv_feat_detect(proposal_detection_model.conf_detection, fast_rcnn_net, im, ...
rpn_net.blobs(proposal_detection_model.last_shared_output_blob_name), ...
aboxes(:, 1:4), opts.after_nms_topN);
else
[boxes, scores] = fast_rcnn_im_detect(proposal_detection_model.conf_detection, fast_rcnn_net, im, ...
aboxes(:, 1:4), opts.after_nms_topN);
end
t_detection = toc(th); % fprintf('%s (%dx%d): time %.3fs (resize+conv+proposal: %.3fs, nms+regionwise: %.3fs)\n', im_names{j}, ...
% size(im, 2), size(im, 1), t_proposal + t_nms + t_detection, t_proposal, t_nms+t_detection);
% running_time(end+1) = t_proposal + t_nms + t_detection; % visualize
classes = proposal_detection_model.classes;
boxes_cell = cell(length(classes), 1);
thres = 0.6;
for i = 1:length(boxes_cell)
boxes_cell{i} = [boxes(:, (1+(i-1)*4):(i*4)), scores(:, i)];
boxes_cell{i} = boxes_cell{i}(nms(boxes_cell{i}, 0.3), :); I = boxes_cell{i}(:, 5) >= thres;
boxes_cell{i} = boxes_cell{i}(I, :);
end
figure(j); [location, label, score] = output(im, boxes_cell, classes, 'voc');
if (score==0)
continue;
else
disp(file3(kk).name);
save(['./mat results/' file3(kk).name '.mat' ], 'location', 'label', 'score', 'im');
end showboxes(im, boxes_cell, classes, 'voc');
pause(0.1);
end
end
end % fprintf('mean time: %.3fs\n', mean(running_time)); caffe.reset_all();
clear mex; end -------------------------------------------------------
--------------------------------------------------------- function proposal_detection_model = load_proposal_detection_model(model_dir)
ld = load(fullfile(model_dir, 'model'));
proposal_detection_model = ld.proposal_detection_model;
clear ld; proposal_detection_model.proposal_net_def ...
= fullfile(model_dir, proposal_detection_model.proposal_net_def);
proposal_detection_model.proposal_net ...
= fullfile(model_dir, proposal_detection_model.proposal_net);
proposal_detection_model.detection_net_def ...
= fullfile(model_dir, proposal_detection_model.detection_net_def);
proposal_detection_model.detection_net ...
= fullfile(model_dir, proposal_detection_model.detection_net); end function aboxes = boxes_filter(aboxes, per_nms_topN, nms_overlap_thres, after_nms_topN, use_gpu)
% to speed up nms
if per_nms_topN > 0
aboxes = aboxes(1:min(length(aboxes), per_nms_topN), :);
end
% do nms
if nms_overlap_thres > 0 && nms_overlap_thres < 1
aboxes = aboxes(nms(aboxes, nms_overlap_thres, use_gpu), :);
end
if after_nms_topN > 0
aboxes = aboxes(1:min(length(aboxes), after_nms_topN), :);
end
end

matlab命令窗口,显示: 刚开始都是正常的,如下:

fast_rcnn startup done
GPU 1: free memory 3824902144
Use GPU 1
Warning: Specified caffe folder (/home/wangxiao/Downloads/faster_rcnn-master/experiments/external/caffe/matlab/caffe_faster_rcnn)
is not exist, change to default one (/home/wangxiao/Downloads/faster_rcnn-master/experiments/external/caffe/matlab)
> In active_caffe_mex at 19
  In ori_demo at 7
20150301095338.jpg
20150301095445.jpg
20150301095535.jpg
20150301095543.jpg
20150301095603.jpg
20150301095613.jpg
20150301095617.jpg
20150301095632.jpg
20150301095635.jpg
20150301095646.jpg
20150301095656.jpg
20150301095659.jpg
20150301095711.jpg
20150301095714.jpg
20150301095717.jpg
20150301095720.jpg
20150301095723.jpg
20150301095726.jpg
20150301095729.jpg
20150301095734.jpg
20150301095741.jpg
20150301095750.jpg

Index exceeds matrix dimensions.

Error in ori_demo (line 114)
        boxes_cell{i} = [boxes(:, (1+(i-1)*4):(i*4)), scores(:, i)];
 

但是,跑着跑着就出问题了,索引超过矩阵维度是什么鬼??只好硬着头皮一句一句的调试了,fuck 。。。。

但是,搞不定啊。。只知道了一个:非极大值抑制(NMS) 

为什么会出错呢??? 之前跑的好好地啊。。。提示超过矩阵范围的那一句是作者自己写的。。。怎么会错呢?怎么会错?怎么会?怎么?怎? ?

不搞了,先把原始的图像,整理成一个文件夹在做处理:

clc; close all;

path = '/media/wangxiao/Elements/image_segment_backup/';
savePath = '/media/wangxiao/Elements/wang xiao/additional_data/';
camera = dir(path); txt_path = '/media/wangxiao/Elements/wang xiao/';
txt_file = fopen([txt_path, 'log_file.txt'], 'a'); for i = 3:length(camera)
disp(['camera ', num2str(i-2), '---']);
fprintf(txt_file, '%s \n ', num2str(i-2));
path2 = [path, camera(i).name, '/'];
file1 = dir(path2);
for ii = 5:size(file1, 1)
disp([' ', file1(ii).name, '---']);
fprintf(txt_file, '%s \n', file1(ii).name);
new_path = [path2, file1(ii).name, '/'];
file2 = dir(new_path);
for j = 3:size(file2, 1)
disp([' ', file2(j).name, '---']);
fprintf(txt_file, '%s \n', file2(j).name);
new_path2 = [new_path, file2(j).name, '/'];
file3 = dir(new_path2);
for k = 3:size(file3, 1)
disp([' ', file3(k).name, '---']);
fprintf(txt_file, '%s \n', file3(k).name);
new_path3 = [new_path2, file3(k).name , '/'];
file4 = dir(new_path3);
for r = 3:size(file4, 1)
disp([' ', file4(r).name, '---']);
fprintf(txt_file, '%s \n', file4(r).name);
new_path4 = [new_path3, file4(r).name, '/'];
file5 = dir(new_path4);
for w = 3:size(file5, 1)
if (imread([new_path4, file5(w).name]))
im = imread([new_path4, file5(w).name]);
imshow(im);
imwrite(im, [savePath, file5(w).name]);
else
continue; end
end
end
end
end
end
end fclose(txt_file);

找到原因了,妈的,原来是因为,输入图像的大小不一致导致的,奇怪了,只要加一句: im = imresize(im, [127 127]); 将输入的图像统一resize成 固定的大小,即可。。。简单 粗暴 但是,不解其惑 。。。。

...

Faster RCNN 运行自己的数据,刚开始正常,后来就报错: Index exceeds matrix dimensions. Error in ori_demo (line 114) boxes_cell{i} = [boxes(:, (1+(i-1)*4):(i*4)), scores(:, i)];的更多相关文章

  1. caffe学习三:使用Faster RCNN训练自己的数据

    本文假设你已经完成了安装,并可以运行demo.py 不会安装且用PASCAL VOC数据集的请看另来两篇博客. caffe学习一:ubuntu16.04下跑Faster R-CNN demo (基于c ...

  2. 使用idea 在springboot添加本地jar包的方法本地运行有效,一旦需要打jar就会报错,这就需要在

    https://blog.csdn.net/huxiaodong1994/article/details/80702278 1.首先在与src同级的目录下新建一个lib目录,然后将本地jar包放在li ...

  3. 选iphone5可以正常编译运行 , 但是5s和6和6s都会编译报错

    选iphone5可以正常编译运行   但是5s和6和6s都会编译报错 iphone6编译报错iphone5s编译报错 解决办法是,Build settings里面把Architectures里面的$( ...

  4. 前端ajax用post方式提交json数据给后端时,网络报错 415

    项目框架:spring+springmvc+mybatis 问题描述:前端ajax用post方式提交json数据给后端时,网络报错 415 前端异常信息:Failed to load resource ...

  5. faster rcnn 源码学习-------数据读入及RoIDataLayer相关模块解读

    参考博客:::https://www.cnblogs.com/Dzhen/p/6845852.html 非常全面的解读参考:::https://blog.csdn.net/DaVinciL/artic ...

  6. python3 + Tensorflow + Faster R-CNN训练自己的数据

    之前实现过faster rcnn, 但是因为各种原因,有需要实现一次,而且发现许多博客都不全面.现在发现了一个比较全面的博客.自己根据这篇博客实现的也比较顺利.在此记录一下(照搬). 原博客:http ...

  7. python运行报错:urllib2.URLError: <urlopen error [Errno 10061] >

    Traceback (most recent call last): File "F:\adt-bundle-windows-x86_64-20140702\eclipse\workspac ...

  8. 连接数据后,当执行查询语句报错:ORA-01219: 数据库未打开: 仅允许在固定表/视图中查询

    参考博客:http://blog.csdn.net/lanchengxiaoxiao/article/details/40982771 1.在cmd窗口通过sqlplus连接数据库 C:\Users\ ...

  9. react-native学习(RN)--之Window环境下搭建环境配置,以及初始化建立react-native项目,(真机和模拟器运行的相关错误解决办法,android打包报错)

    react-native以后会更火的 一.安装java 二.安装Android Studio 三.安装react-native需要的Android studio额外部分 四.安装nodeJS  五.安 ...

随机推荐

  1. 一道面试题,简单模拟spring ioc

    自己实现的,程序写的土了点,很多情况没去考虑,主要是复习理解怎么使用反射来实现spring 的依赖注入. package dom4jtest; import java.lang.reflect.Inv ...

  2. linux 用户、组,修改文件权限

    文件权限 -rwxrw-r‐-1 root root 1213 Feb 2 09:39 abc - 10个字符确定不同用户能对文件干什么 - 第一个字符代表文件(-).目录(d),链接(l) - 其余 ...

  3. ImageLoder配置以及使用(个人阅读使用)

    http://blog.csdn.net/vipzjyno1/article/details/23206387 在gradle添加: compile 'com.nostra13.universalim ...

  4. 高效的iOS宏定义

    iOS开发过程中使用一些常用的宏可以提高开发效率,提高代码的重用性:将这些宏放到一个头文件里然后再放到工程中的-Prefix.pch文件中(或者直接放到-Prefix.pch中)直接可以使用,灰常方便 ...

  5. DDOS攻击原理及防护方法论

      从 07年的爱沙尼亚DDOS信息战,到今年广西南宁30个网吧遭受到DDOS勒索,再到新浪网遭受DDOS攻击无法提供对外服务500多分钟. DDOS愈演愈烈,攻击事件明显增多,攻击流量也明显增大,形 ...

  6. mysql 批量创建表

    使用存储过程 BEGIN    DECLARE `@i` int(11);    DECLARE `@sqlstr` varchar(2560); SET `@i`=0; WHILE `@i` < ...

  7. Java 嵌套作用域

    在C/C++中,当一个块处于另一个块作用域内的时候,内层定义的变量会把外层的变量隐藏, 遵循所谓的就近原则. 在Java中,在内层定义与外层同名的变量是禁止的! 如下: int i = 0; for( ...

  8. Varnost slovenskih GSM omrežij III

    V torek smo pisali tudi o tem, da Si.Mobil v svojem omrežju dovoli uporabo A5/0 (nešifriranega preno ...

  9. 定时同步时间与crontab

    date 月日时分年.秒date -s可以直接设置系统时间 比如将系统时间设定成1996年6月10日的命令如下.#date -s 06/10/96将系统时间设定成下午1点12分0秒的命令如下.#dat ...

  10. 七、CCScene

    CCScene一般情况是游戏里面的根节点,称之为"场景",运行游戏时需要通过CCDirector启动第一个场景.当然,游戏稍微复杂一点的话,可能会包含很多个场景,这就涉及到场景的切 ...