Permalink
Browse files

a simple demo to check building and test time

  • Loading branch information...
1 parent 5416ea4 commit 6d8a2574869a908d2f1e55008db2fcbfc272a657 @liyi14 liyi14 committed Jun 19, 2016
View
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
View
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
View
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
View
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
View
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
View
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
View
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
@@ -0,0 +1,73 @@
+function script_rfcn_demo()
+
+clc;
+clear mex;
+clear is_valid_handle; % to clear init_key
+run(fullfile(fileparts(fileparts(mfilename('fullpath'))), 'startup'));
+%% -------------------- CONFIG --------------------
+opts.caffe_version = 'caffe_rfcn';
+opts.gpu_id = auto_select_gpu;
+opts.use_gpu = true;
+opts.max_rois_num_in_gpu = 5000;
+active_caffe_mex(opts.gpu_id, opts.caffe_version);
+classes = {'aeroplane', 'bicycle', 'bird', 'boat', 'bottle', 'bus', 'car', 'cat', 'chair',...
+ 'cow', 'diningtable', 'dog', 'horse', 'motorbike', 'person', 'pottedplant', ...
+ 'sheep', 'sofa', 'train', 'tvmonitor'};
+
+demo_dir = fullfile(pwd, 'data', 'demo');
+
+% conf
+
+conf = rfcn_config_ohem('image_means',...
+ fullfile(pwd, 'models', 'pre_trained_models', 'ResNet-101L', 'mean_image'));
+
+%% -------------------- INIT MODEL -----------------
+rfcn_net_def = fullfile(pwd, 'models', 'rfcn_prototxts', 'ResNet-101L_OHEM_res3a', 'test.prototxt');
+rfcn_net = fullfile(pwd, 'output', 'rfcn_demo', ...
+ 'rfcn_VOC0712_ResNet101_OHEM_rpn_resnet101','final');
+
+caffe_net = caffe.Net(rfcn_net_def, 'test');
+caffe_net.copy_from(rfcn_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);
+ proposals = uint8(repmat([1,1,400,275], [2000, 1]));
+ proposals = proposals+100*rand(size(proposals));
+ [boxes, scores] = rfcn_im_detect(conf, caffe_net, im, proposals, opts.max_rois_num_in_gpu);
+end
+
+%% -------------------- TESTING --------------------
+im_names = {'000037', '000054', '000553', '000576', '001852', '002597', '004030'};
+running_time = zeros(length(im_names), 1);
+for j = 1:length(im_names)
+ im = imread(fullfile(demo_dir, [im_names{j}, '.jpg']));
+ proposals = load(fullfile(demo_dir, [im_names{j}, '_boxes.mat']));
+ proposals = single(proposals.boxes);
+ tic
+ [boxes, scores] = rfcn_im_detect(conf, caffe_net, im, proposals, opts.max_rois_num_in_gpu);
+ th = toc;
+ fprintf('%s, (%dx%d): time %.3fs\n', im_names{j}, size(im, 1), size(im, 2), th);
+ running_time(j) = th;
+ 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);
+ showboxes(im, boxes_cell, classes, 'voc');
+ pause(0.1);
+end
+fprintf('mean time: %.3fs\n', mean(running_time));
+end
View
@@ -30,5 +30,5 @@ function startup()
mkdir_if_missing(fullfile(curdir, 'models'));
- fprintf('fast_rcnn startup done\n');
+ fprintf('rfcn startup done\n');
end

0 comments on commit 6d8a257

Please sign in to comment.