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

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成 固定的大小,即可。。。简单 粗暴 但是,不解其惑 。。。。

 

 

...

时间: 2024-10-24 00:49:17

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

深度学习-faster rcnn运行demo出现错误

问题描述 faster rcnn运行demo出现错误 faster rcnn配置好之后运行 ./tools/demo.py出现如下错误:: Check failed: registry.count(type) == 1 (0 vs. 1) Unknown layer type: Python 解决方案 https://www.zhihu.com/question/38455242/answer/77002913 解决方案二: 两种可能: 1.makefile 文件下LIBRARIES += op

mysql 存储过程运行成功,但是call procedure 的时候却报错

问题描述 mysql 存储过程运行成功,但是call procedure 的时候却报错 BEGIN DECLARE i INT; SET i = 18672700000; WHILE i < num DO INSERT INTO userinfo ( Uid, Utype, Tmac, ACname, SSID, UTip, UTtype, ULtime, UOtime, POname, Portal, Appid ) VALUES ( i, '普通用户', '0C-37-DC-804', '0

C# 大数据导出word的假死报错的处理方法_C#教程

最近一个项目是一个基于winform的报告系统,根据一系列的查询参数计算出结果,最终生成一个格式规范的word文档,刚开始数据量不大(500行)数据以内,写入速度还能接受,但最近遇到一个问题就是当出现大量的数据行的时候,写入word的过程就变的非常慢,CPU直接拉到100%,本人机器配置已经算比较高的了,8G内存+i5CPU,依旧假死,该问题困扰了我几天,也问了google很多次,基本上给出的答案都是word本身就比较慢这样一类的答案,或者是非托管代码的优化,慢也就算了,至少可以通过进度条来交互

visual studio-VS2013在运行程序的时候,如果内存不够会报错吗?

问题描述 VS2013在运行程序的时候,如果内存不够会报错吗? 运行一个程序出来的结果和预想的有些出入,在考虑是不是运行的时候出现了内存不够的情况,却没提示? 解决方案 一般不会,如果是栈上的内存不够,编译的时候就会提示.如果是堆上的内存不够,一般会卡住,不会继续执行.栈上的内存一般几兆到几十兆.堆上一根据你的编译器,内存情况,一般几G吧,但是可以开启大内存. 解决方案二: 如果是int a[12];声明之后,调用a[15] = 1后,就可能造成程序崩溃,和预想的结果有出入,很可能是代码逻辑有问

java-JAVA-JHepWork数据拟合(curve fitting)报错:“/ is a folder”

问题描述 JAVA-JHepWork数据拟合(curve fitting)报错:"/ is a folder" import java.awt.Color; import java.util.*; import jhplot.*; import jhplot.stat.LinReg; public class ScanTest2 { public static void main(String[] args) { HPlot c1=new HPlot("cad");

oracle10g-利用sqoop把数据从Oracle导出到hive报错

问题描述 利用sqoop把数据从Oracle导出到hive报错 bash-4.1$ sqoop import --connect jdbc:oracle:thin:@192.168.1.169:1521:orcl --username HADOOP --password hadoop2015 --table CALC_UPAY_DATE_HADOOP_HDFS --split-by UPAYID --hive-import Warning: /usr/lib/sqoop/../accumulo

SQLserver2012里对数据表“选择前1000行”报错,请大神指教怎么修复呀?万分感谢!

问题描述 SQLserver2012里对数据表"选择前1000行"报错,请大神指教怎么修复呀 解决方案 解决方案二:安装有问题重装修复下解决方案三:修复或重装,或者去其它电脑上复制你缺少但我dll解决方案四:没安装完整,其实这个功能不用也无所谓吧,自己都可以写呀解决方案五:先备份数据库,然后修复安装数据库.或是把备份好的数据库恢复至另一台数据库中,看看是否有问题.十分不成,可以重新安装SQL.解决方案六:重新安装解决方案七:select*fromtablelimit1000;

android-请教各位一个问题:刚导入的安卓文件报错

问题描述 请教各位一个问题:刚导入的安卓文件报错 报错 之前报 Unable to resolve target 'android-17' 但是我project.properties里已经改成了17 但还是不行. 解决方案 你添加包的路径有问题 解决方案二: http://jingyan.baidu.com/article/d2b1d1027664d05c7e37d43e.html 解决方案三: 你看看包的构建路径有问题没,工程右键属性里面改变下sdk版本 解决方案四: 你sdk多下载几个版本,

请教运行&amp;amp;quot;glance-manage db_sync&amp;amp;quot; glance,报错

问题描述 环境:CENTOS6.564BIT,安装OPENSTACKICEHOUSE,在运行:su-s/bin/sh-c"glance-managedb_sync"glance时,报错如下:[root@controllerbin]#su-s/bin/sh-c"glance-managedb_sync"glance/usr/lib/python2.6/site-packages/glance/cmd/manage.py:41:DeprecationWarning:Th