-
Notifications
You must be signed in to change notification settings - Fork 458
/
crfrnn_demo.m
56 lines (40 loc) · 1.48 KB
/
crfrnn_demo.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
% This package contains code for the "CRF-RNN" semantic image segmentation method, published in the
% ICCV 2015 paper Conditional Random Fields as Recurrent Neural Networks. Our software is built on
% top of the Caffe deep learning library.
%
% Contact:
% Shuai Zheng (szheng@robots.ox.ac.uk), Sadeep Jayasumana (sadeep@robots.ox.ac.uk), Bernardino Romera-Paredes (bernard@robots.ox.ac.uk)
%
% Supervisor:
% Philip Torr (philip.torr@eng.ox.ac.uk)
%
% For more information about CRF-RNN please vist the project website http://crfasrnn.torr.vision.
%
caffe_path = '../caffe/';
model_def_file = 'TVG_CRFRNN_new_deploy.prototxt';
model_file = 'TVG_CRFRNN_COCO_VOC.caffemodel';
if exist(model_file, 'file') ~= 2
error('You need a network model file. Please download our default model by running ./download_trained_model.sh');
end
use_gpu = 1; % Set this to 0 if you don't have a GPU.
gpu_id = 0;% which gpu device id you are using?
addpath(fullfile(caffe_path, 'matlab'));
caffe.reset_all();
net = tvg_matcaffe_init(use_gpu, gpu_id, model_def_file, model_file);
im = imread('input.jpg');
[h, w, d] = size(im);
if (d ~= 3)
error('Error! Wrong depth.\n');
end
if (h > 500 || w > 500)
error('Error! Wrong image size.\n');
end
prepared_im = tvg_prepare_image_fixed(im);
inputData = {prepared_im};
scores = net.forward(inputData);
Q = scores{1};
[dumb, pred] = max(Q, [], 3);
pred = pred';
pred = pred(1:h, 1:w);
load map.mat
imwrite(pred, map, 'output.png', 'png');