forked from shenwei1231/DeepContour
-
Notifications
You must be signed in to change notification settings - Fork 0
/
matcaffe_init.m
60 lines (54 loc) · 1.63 KB
/
matcaffe_init.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
57
58
59
60
function matcaffe_init(use_gpu, model_def_file, model_file, gpu_id)
% matcaffe_init(model_def_file, model_file, use_gpu)
% Initilize matcaffe wrapper
if nargin < 1
% By default use CPU
use_gpu = 0;
end
% if nargin < 2 || isempty(model_def_file)
% % By default use imagenet_deploy
% model_def_file = '../../examples/car/car_deploy.prototxt';
% end
% if nargin < 3 || isempty(model_file)
% % By default use caffe reference model
% model_file = '../../examples/car/caffe_car_train_iter_80000';
% end
if caffe2('is_initialized') == 0
if exist(model_file, 'file') == 0
% NOTE: you'll have to get the pre-trained ILSVRC network
error('You need a network model file');
end
if ~exist(model_def_file,'file')
% NOTE: you'll have to get network definition
error('You need the network prototxt definition');
end
caffe2('init', model_def_file, model_file)
else
caffe2('reset');
if exist(model_file, 'file') == 0
% NOTE: you'll have to get the pre-trained ILSVRC network
error('You need a network model file');
end
if ~exist(model_def_file,'file')
% NOTE: you'll have to get network definition
error('You need the network prototxt definition');
end
caffe2('init', model_def_file, model_file)
end
fprintf('Done with init\n');
% set to use GPU or CPU
if use_gpu
fprintf('Using GPU Mode\n');
caffe2('set_mode_gpu');
else
fprintf('Using CPU Mode\n');
caffe2('set_mode_cpu');
end
fprintf('Done with set_mode\n');
% put into test mode
caffe2('set_phase_test');
fprintf('Done with set_phase_test\n');
if use_gpu
fprintf('choose gpu\n');
caffe2('set_device', gpu_id);
end