⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 init_filt_oper.m

📁 Standard model object recognition matlab code
💻 M
字号:
function [f,s,all_oper] = init_filt_oper (level)% FUNCTION [f,s,all_oper] = init_filt_oper (level)%% This function pre-computes all the necessary filters and gets the% definition of operations to be used in each layer/levels.  The% levels is a variable length vector that determines the% layer/level of model computation.  For example,%  If level = [1], filters up to S1.%  If level = [1 1], filters for S1 and C1.%  etc., etc., etc.%% Filters for the bypass (denoted with "b", usually) are also% computed here.%% Hence, level indicates [S1 C1 S2b C2b S2 C2 S3 C3 VTU].%% For simplicitiy, the program will only work for computing:%  Only upto C1     : [1 1],%  Bypass route only: [1 1 1 1] or [0 0 1 1],%  Main route only  : [1 1 0 0 1 1...] or [0 0 0 0 1 1...],%  Both routes      : [1 1 1 1 1 1...] or [0 0 1 1 1 1...].% Program may produce errors or errorneous results for other cases.%% Note that for scale-mixing filter, we assume some dummy stimulus% size, but the correct size is used in comp_mix_scale.m%% The resulting filter, along with some major parameters, will be% saved in a file named Filt_128x128.mat (128x128 is stim_size).% Be careful, because it may overwrite the existing filter file.% Define all operations in each layer.global all_quanta;all_quanta = [0 0 0 0 0 0 0 0 0];% It's all normdp and sftmax!global all_oper;all_oper = ['normsp'; 'fulmax'; ...  % S1, C1: V1, simple/complex      'normdp'; 'sftmax'; ... % S2b, C2b: bypass route      'normdp'; 'sftmax'; ... % S2, C2: V4      'normdp'; 'sftmax'; ... % S3, C3: PIT      'normdp']; % VTU: AITglobal learn_file; % which features to load?% Example learn_file's.%learn_file = cell(9,1);%learn_file{3} = './Data/f_S2b_natural_img.mat';%learn_file{5} = './Data/f_S2_natural_img.mat';%learn_file{7} = './Data/f_S3_natural_img.mat';%learn_file{9} = './Data/f_S4_natural_img.mat';% Do some quick error checks.stat = aux_error_check(level);% In case there are some different number of features than defined% in init_filter_def, keep a record with num_feat.num_feat = zeros(length(level),1);f = [];s = [];% This global variable is the name of filter file that can be used% between different sessions.global filt_file_use;% Check if a saved filter exists.if length(filt_file_use)>0  filt_file      = filt_file_use;  filt_file_save = filt_file_use;else  filt_file      = 'Filt.mat'; % Default name.  filt_file_save = 'Filt.mat';endIsMatch = check_filt_file (level, filt_file);if IsMatch  load(filt_file);  disp(['Re-using filter ' filt_file '.']);else  disp(['Saving filter ' filt_file '.']);  for i = 1:length(level)    disp(['   Setting up filters for Layer ' num2str(i)]);    f_tmp = 0;    s_tmp = 0;    m_tmp = 0;    if level(i) > 0    switch i      case(1)	f_tmp = filt_get_S1;      case(2)	f_tmp = filt_get_C1;      case({3, 5, 7, 9}) % S2b, S2 and S3 (S4)	[a,b,c,d]   = init_filter_def(i);	num_feat(i) = max(b(4,:));	f_tmp = filt_get_S_layer(learn_file{i},a,b(4,1),c);      case({4, 6, 8}) % C2b, C2 and C3	[a,b,c,d]   = init_filter_def(i);	num_feat(i) = num_feat(i-1);	f_tmp = filt_get_C_layer(b(1:3,:),c);	m_tmp = d;	s_tmp = filt_scalemixing (m_tmp,num_feat(i));	      otherwise	error('Layer undefined.');    end    end    f = setfield(f, ['f' num2str(i)], f_tmp);    s = setfield(s, ['f' num2str(i)], s_tmp);    s = setfield(s, ['m' num2str(i)], m_tmp);  end  disp('   Saving.');  % Now loop thru the filters, and set un-used filters (level(i)==0)  % to null, because in main_model.m, the loop will look at if the  % current filter is defined.  for i = 1:length(level)    if level(i)==0      f = setfield(f, ['f' num2str(i)], []);      s = setfield(s, ['f' num2str(i)], []);      s = setfield(s, ['m' num2str(i)], []);    end  end  % This will overwrite the file with the same name.  Be careful.  % The global variables are saved under different names, to avoid  % warning during check_filt_file routine.  o_save = all_oper;  q_save = all_quanta;  l_save = learn_file;  save(filt_file_save,'f','s','level','o_save','l_save','q_save');  disp(['Done setting up ' filt_file '.']);endfunction IsMatch = check_filt_file (lvl, filt_file);% FUNCTION IsMatch = check_filt_file (lvl, filt_file);%% Check if a saved filter exists.global all_quanta all_oper learn_file;if exist(filt_file, 'file')  % Note we are not comparing learn_file.  load (filt_file);  is_level = strcmp(num2str(lvl),num2str(level));  is_quant = strcmp(num2str(all_quanta),num2str(q_save));  is_oper  = strcmp(all_oper,o_save);  %is_learn = strcmp(this_learn,l_save);  IsMatch  = is_level & is_quant & is_oper;else  IsMatch  = 0;end

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -