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

📄 do_test_efficient.m

📁 一个学习自然场景类别的贝叶斯模型、基于“词袋”模型的目标分类。来源于Feifei Li的论文。是近年来的目标识别模型热点之一。
💻 M
📖 第 1 页 / 共 2 页
字号:
function do_test_efficient(config_file)   %% Function that takes a hand-trained parts and structure model and the%% interest points produced by running the part templates over the images,%% and finding the best configuration of them in each image.%% Based on method in the paper:%% Felzenszwalb, P. and Huttenlocher, D. "Pictorial Structures for Object%% Recognition", Intl. Journal of Computer Vision, 61(1), pp. 55-79, January 2005.        %% Does this for all images and then plots training and test separately.    %% Before running this, you must have run:%%    do_random_indices - to generate random_indices.mat file%%    do_preprocessing - to get the images that the operator will run on  %%    do_manual_train_parts_structure - to get the model and part%%                                      templates.%%    do_parts_filtering - to get interest points from part templates.  %% R.Fergus (fergus@csail.mit.edu) 03/10/05.  %%% debug switchDEBUG = 0;%%% base figure numberBASE_FIG_NUM = 500;%%% standard color orderingcols = {'r.' 'g.' 'b.' 'c.' 'm.' 'y.' 'k.'};cols2 = {'rx' 'gx' 'bx' 'cx' 'mx' 'yx' 'kx'};cols3 = {'ro' 'go' 'bo' 'co' 'mo' 'yo' 'ko'};cols4 = {'r' 'g' 'b' 'c' 'm' 'y' 'k'};%% Evaluate global configuration fileeval(config_file);%% Get list of file name of input images of positive class onlyimg_file_names = genFileNames({Global.Image_Dir_Name},[1:Categories.Total_Frames],RUN_DIR,Global.Image_File_Name,Global.Image_Extension,Global.Num_Zeros);%% Get list of output file namesip_file_names =  genFileNames({Global.Interest_Dir_Name},[1:Categories.Total_Frames],RUN_DIR,Global.Interest_File_Name,'.mat',Global.Num_Zeros);%% load up most recent model and take model from it.... %%% just take newest model in subdir.ind = length(dir([RUN_DIR,'/',Global.Model_Dir_Name,'/', Global.Model_File_Name,'*.mat']));        %%% construct model file namemodel_fname = [RUN_DIR,'/',Global.Model_Dir_Name,'/',Global.Model_File_Name,prefZeros(ind,Global.Num_Zeros),'.mat']%%% load up modelload(model_fname);%%% Get total number of imagesnImages = length(ip_file_names);%%% get # partsnParts = Learn.Num_Parts;if (~exist('bounding_box_efficient'))%%% precompute shape density variancefor b=2:Learn.Num_Parts  determinant_term(b) = -log(shape_var_x(b) * shape_var_y(b) * 2 * pi); end%%% round means to integer valuesshape_mean_x = round(shape_mean_x);shape_mean_y = round(shape_mean_y);%%% get absolute values of meansabs_mean_x = abs(shape_mean_x);abs_mean_y = abs(shape_mean_y);tic;for i = 1:nImages      %%% display progress  if (mod(i,10)==0)    fprintf('.%d',i);  end    %%% load up interest files   load(ip_file_names{i});      %%% get size of response_image  [imy,imx,tmp] = size(response_image);    %%% setup variables  overall_resp = zeros(imy,imx);  part_resp = zeros(imy,imx,nParts-1);  locations = cell(1,nParts-1);  for p=2:Learn.Num_Parts         %% Pad response_image with v.large costs (not Inf since it screws up     %% dist_transform_1d function). This is designed to ensure we don't     %% run out of image when we translate it 	         %% Also: (a) scale Appearance costs, giving weighting between shape and     %% appearance, and (b) negate everything since for distance transform, low is     %% good but probability map has good being high values_efficient     padded_response_image = padarray(-Recog.Shape_Appearance_Weighting*response_image(:,:,p),[abs_mean_y(p) abs_mean_x(p)],1e200,'both');                      	        %%% translate response image by mean of that part relative to the     %%% landmark     translated_response = padded_response_image([abs_mean_y(p)+shape_mean_y(p)+1:imy+(abs_mean_y(p)+shape_mean_y(p))],[abs_mean_x(p)+shape_mean_x(p)+1:imx+(abs_mean_x(p)+shape_mean_x(p))]);          %%% Now do distance transform, using variance as multiplication factor.     [part_resp(:,:,p-1),locations{p-1}] = dist_transform(translated_response,shape_var_x(p),shape_var_y(p));	    end  %% Now add in landmark response to sum of all other parts...  overall_resp = (-Recog.Shape_Appearance_Weighting * response_image(:,:,1)) + sum(part_resp,3);  %% Find minimum overall   [min_score,landmark_pos] = min(overall_resp(:));    %% Get landmark x,y location  [landmark_y, landmark_x] = ind2sub([imy imx],landmark_pos);  %% Get locations of other parts...  for p = 2:nParts    part_x(p-1) = locations{p-1}(landmark_y,landmark_x,1);    part_y(p-1) = locations{p-1}(landmark_y,landmark_x,2);  end	   %%% Overall best locations....  best_x = [landmark_x,part_x+shape_mean_x(2:end)'];  best_y = [landmark_y,part_y+shape_mean_y(2:end)'];    %%% plot stufff  if DEBUG        figure(BASE_FIG_NUM); clf;    im = imread(img_file_names{i});    imagesc(im); hold on;%       for p=1:nParts      plot(best_x(p),best_y(p),cols{p},'Markersize',20,'Linewidth',5);    end        figure(BASE_FIG_NUM+1); clf;    %%% landmark response    subplot(2,nParts,nParts+1);    imagesc(-overall_resp); caxis([-1 1]*Recog.Shape_Appearance_Weighting);    hold on; title('Overall probab.');    plot(landmark_x,landmark_y,'wx','Markersize',20,'Linewidth',5);      %%% get best overall reponse    q = -response_image(:,:,1);    [tmp,pos] = min(q(:));    [yy,xx] = ind2sub([imy imx],pos);   % plot(xx,yy,'ko','Markersize',20,'Linewidth',5);    colorbar;        subplot(2,nParts,1);    imagesc(response_image(:,:,1)); caxis([-1 1]); colorbar;    title(['Appearance probab., part 1']); hold on;    plot(xx,yy,'ko','Markersize',20,'Linewidth',5);        %%% non-landmark parts    for p=2:nParts    %%% get best overall reponse      q = -response_image(:,:,p);      [tmp,pos] = min(q(:));      [yy,xx] = ind2sub([imy imx],pos);         subplot(2,nParts,nParts+p)      imagesc(-part_resp(:,:,p-1)); hold on; caxis([-1 1]*Recog.Shape_Appearance_Weighting); colorbar;            plot(part_x,part_y,'wx','Markersize',20,'Linewidth',5);      plot(xx-shape_mean_x(p),yy-shape_mean_y(p),'ko','Markersize',20,'Linewidth',5);      title(['Distance transformed part ',num2str(p)]);      subplot(2,nParts,p);      imagesc(response_image(:,:,p)); hold on; caxis([-1 1]); colorbar;      plot(xx,yy,'ko','Markersize',20,'Linewidth',5);      title(['Appearance probab., part ',num2str(p)]);    end    %%% plot best     pause  end    %%% Collect statistics for plotting and ROC and RPC curves  best_locations_x(:,i) = best_x';  best_locations_y(:,i) = best_y';    %% now find min and max x and y  x_min = min(best_x);  y_min = min(best_y);  x_max = max(best_x);  y_max = max(best_y);  %% now compute bounding rectangle  bounding_box_efficient{i} = round([x_min,y_min,x_max-x_min,y_max-y_min])';  %% get score..  best_overall_score_efficient(i) = -min_score; %% negate to turn cost back into probability...   endtotal_time=toc;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Compute some performance metrics%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% get labels for test frameslabels_efficient = zeros(1,Categories.Total_Frames);for a=1:Categories.Number  labels_efficient(Categories.Test_Frames{a}) = [Categories.Labels(a)*ones(1,length(Categories.Test_Frames{a}))];end

⌨️ 快捷键说明

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