https://github.com/MarcBS/SR-Clustering
Tip revision: 64387d01330498c22c6989bc4fed1b3daf70fffa authored by Marc Bolaños on 17 May 2017, 11:13:02 UTC
Minor plot setting changed
Minor plot setting changed
Tip revision: 64387d0
rcnn_load_model_new.m
function rcnn_model = rcnn_load_model_new(rcnn_model_or_file, use_gpu, device_id)
% rcnn_model = rcnn_load_model(rcnn_model_or_file, use_gpu)
% Takes an rcnn_model structure and loads the associated Caffe
% CNN into memory. Since this is nasty global state that is carried
% around, a randomly generated 'key' (or handle) is returned.
% Before making calls to caffe it's a good idea to check that
% rcnn_model.cnn.key is the same as caffe('get_init_key').
% AUTORIGHTS
% ---------------------------------------------------------
% Copyright (c) 2014, Ross Girshick
%
% This file is part of the R-CNN code and is available
% under the terms of the Simplified BSD License provided in
% LICENSE. Please retain this notice and LICENSE if you use
% this file (or any portion of it) in your project.
% ---------------------------------------------------------
if isstr(rcnn_model_or_file)
assert(exist(rcnn_model_or_file, 'file') ~= 0);
ld = load(rcnn_model_or_file);
rcnn_model = ld.rcnn_model; clear ld;
else
rcnn_model = rcnn_model_or_file;
end
assert(exist(rcnn_model.cnn.binary_file, 'file')>0, 'Missing cnn binary file: please run data/fetch_lsda7k_model.sh');
assert(exist(rcnn_model.cnn.definition_file, 'file')>0, 'Missing definition file -- update repo');
%%% MODIFIED BY MARC BOLAÑOS %%%
%% OLD VERSION
% rcnn_model.cnn.init_key = ...
% caffe('init', rcnn_model.cnn.definition_file, rcnn_model.cnn.binary_file);
% if exist('use_gpu', 'var') && ~use_gpu
% caffe('set_mode_cpu');
% else
% caffe('set_mode_gpu');
% if exist('device_id', 'var')
% caffe('set_device',device_id);
% else
% caffe('set_device',0);
% end
% end
% caffe('set_phase_test');
% rcnn_model.cnn.layers = caffe('get_weights');
%% NEW VERSION 2
rcnn_model.cnn.init_key = ...
caffe('init', rcnn_model.cnn.definition_file, rcnn_model.cnn.binary_file, 'test');
if exist('use_gpu', 'var') && ~use_gpu
caffe('set_mode_cpu');
else
caffe('set_mode_gpu');
if exist('device_id', 'var')
caffe('set_device',device_id);
else
caffe('set_device',0);
end
end
%caffe('set_phase_test');
rcnn_model.cnn.layers = caffe('get_weights');
%% NEW VERSION
% if exist('use_gpu', 'var') && ~use_gpu
% caffe.set_mode_cpu();
% else
% caffe.set_mode_gpu();
% if exist('device_id', 'var')
% caffe.set_device(model.gpu_id);
% else
% caffe.set_device(0);
% end
% end
% caffe.reset_all();
%
% net = caffe.Net(rcnn_model.cnn.definition_file, rcnn_model.cnn.binary_file, 'test');