forked from BVLC/caffe
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added matcaffe_init to easy reuse of caffe initialization
- Loading branch information
Showing
3 changed files
with
54 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
function matcaffe_init(use_gpu, model_def_file, model_file) | ||
% 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/imagenet/imagenet_deploy.prototxt'; | ||
end | ||
if nargin < 3 || isempty(model_file) | ||
% By default use caffe reference model | ||
model_file = '../../examples/imagenet/caffe_reference_imagenet_model'; | ||
end | ||
|
||
|
||
if caffe('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 | ||
caffe('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'); | ||
caffe('set_mode_gpu'); | ||
else | ||
fprintf('Using CPU Mode\n'); | ||
caffe('set_mode_cpu'); | ||
end | ||
fprintf('Done with set_mode\n'); | ||
|
||
% put into test mode | ||
caffe('set_phase_test'); | ||
fprintf('Done with set_phase_test\n'); |