📄 main_model_load_save.m
字号:
function r_out = main_model_load_save (dir_name,level,varargin)% FUNCTION r_out = main_model_save_load (dir_name,level,varargin)%% This function runs through a directory of images (or previous% layers responses), using main_model function. We can also save% particular layer's responses in a specified directory. This save% function will be useful when we want to take responses from% different layers to compute classifier performances.%% Input arguements% "dir_name": name of the directory where the stimulus images or% previous layers responses are stores.% "level": specifies which layers to compute. For example,% [0,1,1] means start from the second layer upto third.% "varargin": determines which layer responses to save and the name% of the directory. For example,% varargin{1} = [0 0 1] means to save the third layer.% varargin{2} = 'this_direct' means to save in a directory % called 'this_direct'. Sub-directories will be% created that correspond to the layer names in% 'LayerX" format.% % The output r_out will be usually zero (because of memory issue),% unless C2b layer is included in the level.%% Modified June 2006.%% Modified Sept 2006:% We no longer load the stim_size. d = dir([dir_name '/r_i*.mat']);%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% MAIN PART OF THE PROGRAM% get filters.[f,s,o] = init_filt_oper (level);% Break up the filters and save in small files.%for i = 1:length(fieldnames(f))% f_alone = getfield(f, ['f' num2str(i)]);% s_alone = getfield(s, ['f' num2str(i)]);% m_alone = getfield(s, ['m' num2str(i)]);% save(['Filt_f' num2str(i)],'f_alone');% save(['Filt_s' num2str(i)],'s_alone','m_alone');%end%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%disp(['Running on ' num2str(length(d)) ' images: ' dir_name]);r_out = [];tic;for i = 1:length(d) % Display progress for each stimulus. if mod(i,10) == 0 fprintf('*'); else fprintf('.'); end if mod(i,50) == 0 fprintf('\n'); end drawnow; % load stimulus or response from the previous layer. load([dir_name '/' d(i).name]); r_prev = r; start_level = find(level>0); clear resp; %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % MAIN PART OF THE PROGRAM % run the model from the start level resp = main_model (r_prev,f,s,o,start_level(1)); %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % Since we can not return all responses (too many), let's just % return the last layer's response. This step can be skipped if % we are going to save the responses anyway. if 0%length(level) == 4 % Output only if C2b. r_last = getfield(resp, ['r' num2str(length(level))]); r_out(:,i) = squeeze(aux_get_all_resp(r_last))'; end % Save the responses if instructed by the varargin if length (varargin) > 0 save_flag = varargin{1}; save_dir = varargin{2}; % Make directories to save responses if ~exist(save_dir, 'dir') mkdir(save_dir); end % Different directories for different layer responses % Save for each stimulu. num_zero = length(num2str(length(d))); save_file = repmat('0', [1 num_zero-length(num2str(i))]); save_file = ['r_i' save_file num2str(i)]; for j = find(save_flag>0) dn = [save_dir '/Layer' num2str(j)]; % Directory name if ~exist(dn, 'dir') mkdir(dn); end r = getfield(resp, ['r' num2str(j)]); save([dn '/' save_file], 'r'); end endendfprintf('\n');elap_time = toc;disp(['It took ' num2str(elap_time/60) ' mins: ' ... num2str(elap_time/length(d)) ' sec/image.']);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -