📄 do_test_efficient.m
字号:
%%% now get scores of test imagesvalues_efficient = -Inf * ones(1,Categories.Total_Frames);for a=1:Categories.Number values_efficient(Categories.Test_Frames{a}) = best_overall_score_efficient(Categories.Test_Frames{a});end%%% since all training images are given -Inf score, weed out to avoid%%% skewing ROC curvegood_ind = find(~isinf(values_efficient));values_efficient2 = values_efficient(good_ind); labels_efficient2 = labels_efficient(good_ind);%%% Now compute object present/absent peformance using ROC curve[roc_curve_efficient,roc_op_efficient,roc_area_efficient,roc_threshold_efficient] = roc([values_efficient2;labels_efficient2]');%%% Now do localization performance. This will be measured only on +ve%categories, since all proposed detections on -ve data are definately%false alarms. Note that the ground_truth_locations_{category_name} files%produced by do_preprocessing.m must exist in RUN_DIR.%% load up %%% first rescale proposed bounding box...for a=1:length(bounding_box_efficient) %%% Enlarge proposed bounding box by Recog.Manual_Bounding_Box_Efficient_Scaling %%% first get centroid centroid_x = bounding_box_efficient{a}(1,:) + bounding_box_efficient{a}(3,:)/2; centroid_y = bounding_box_efficient{a}(2,:) + bounding_box_efficient{a}(4,:)/2; %%% repoistion new top left corner bounding_box_efficient{a}(1,:) = centroid_x - bounding_box_efficient{a}(3,:)/2*Recog.Manual_Bounding_Box_Scaling; bounding_box_efficient{a}(2,:) = centroid_y - bounding_box_efficient{a}(4,:)/2*Recog.Manual_Bounding_Box_Scaling; %%% adjust width and height bounding_box_efficient{a}(3,:) = bounding_box_efficient{a}(3,:) * Recog.Manual_Bounding_Box_Scaling; bounding_box_efficient{a}(4,:) = bounding_box_efficient{a}(4,:) * Recog.Manual_Bounding_Box_Scaling; endlocalization_labels_efficient = zeros(1,Categories.Total_Frames);gt_boxes = cell(1,Categories.Total_Frames);total_number_instances = 0;for a=1:Categories.Number if (Categories.Labels(a)==1) fname = [RUN_DIR,'/',Global.Ground_Truth_Name,'_',Categories.Name{a},'.mat']; if (exist(fname)) load(fname); %%% get relavent boxes gt_boxes(Categories.Test_Frames{a}) = gt_bounding_boxes(:,Categories.Test_Frames{a}); %%% record total number of instances total_number_instances = total_number_instances + sum(cellfun('size',gt_boxes,2)); else error([fname,' does not exist']); end %% find correct localizations localization_labels_efficient(Categories.Test_Frames{a}) = test_localization(gt_boxes(Categories.Test_Frames{a}),bounding_box_efficient(Categories.Test_Frames{a}),Recog); else %% all putative detection on negatively labelled images are %% automatically false alarms.... localization_labels_efficient(Categories.Test_Frames{a}) = zeros(1,length(Categories.Test_Frames{a})); end end%% Now compute recall_prescision curve[rpc_curve_efficient,rpc_ap_efficient,rpc_area_efficient,rpc_threshold_efficient] = recall_precision_curve([values_efficient;localization_labels_efficient]',total_number_instances);%%% Now save to modelsave(model_fname,'best_locations_x','best_locations_y','best_overall_score_efficient','bounding_box_efficient','gt_boxes','roc_curve_efficient','roc_area_efficient','roc_op_efficient','roc_threshold_efficient','rpc_curve_efficient','rpc_ap_efficient','rpc_area_efficient','rpc_threshold_efficient','values_efficient','localization_labels_efficient','labels_efficient','-append');fprintf('\nFinished running parts and structure model, using efficient methods, over images\n');fprintf('Total number of images: %d, mean time per image: %f secs\n',Categories.Total_Frames,total_time/Categories.Total_Frames);end %% end of computing results section%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Plotting section%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% We will use figures from FIGURE_BASE to FIGURE_BASE + 4;%% clear them ready for plotting action...for a=BASE_FIG_NUM:BASE_FIG_NUM+2 figure(a); %clf;endfigure(BASE_FIG_NUM);q=get(BASE_FIG_NUM,'UserData');if isempty(q) plot(roc_curve_efficient(:,1),roc_curve_efficient(:,2),cols4{1}); hold on; set(BASE_FIG_NUM,'UserData',1);else q=q+1; plot(roc_curve_efficient(:,1),roc_curve_efficient(:,2),cols4{rem(q-1,7)+1}); hold on; set(BASE_FIG_NUM,'UserData',q);endaxis([0 1 0 1]); axis square; grid on;xlabel('P_{fa}'); ylabel('P_d'); title(['ROC Curve, Area: ',num2str(roc_area_efficient),' OpP: ',num2str(roc_op_efficient)]);figure(BASE_FIG_NUM+1);q=get(BASE_FIG_NUM+1,'UserData');if isempty(q) plot(rpc_curve_efficient(:,1),rpc_curve_efficient(:,2),cols4{1}); hold on; set(BASE_FIG_NUM+1,'UserData',1);else q=q+1; plot(rpc_curve_efficient(:,1),rpc_curve_efficient(:,2),cols4{rem(q-1,7)+1}); hold on; set(BASE_FIG_NUM+1,'UserData',q);endaxis([0 1 0 1]); axis square; grid on;xlabel('Recall'); ylabel('Precision'); title('RPC Curves');%% first decide on plotting orderif strcmp(Plot.Example_Mode,'ordered') %%% just go in orginial order of images plot_order = sort(Categories.All_Test_Frames);elseif strcmp(Plot.Example_Mode,'alternate') %%% using random order but alternating between images of different %%% classes... ind = ones(Categories.Number,max(cellfun('length',Categories.Test_Frames))); tmp = length(Categories.Test_Frames{1}); ind(1,1:tmp)=[1:tmp]; for a=2:Categories.Number tmp = length(Categories.Test_Frames{a}); offset=sum(cellfun('length',Categories.Test_Frames(1:a-1))); ind(a,1:tmp) = [1:tmp]+offset; end plot_order = Categories.All_Test_Frames(ind(:)); elseif strcmp(Plot.Example_Mode,'random') %%% using order given in random_indices.mat plot_order = Categories.All_Test_Frames;elseif strcmp(Plot.Example_Mode,'best') %%% plot ordered by score [tmp2,ind] =(sort(-best_overall_score_efficient(Categories.All_Test_Frames))); plot_order = Categories.All_Test_Frames(ind);elseif strcmp(Plot.Example_Mode,'worst') %%% plot ordered by score on worst topic [tmp2,ind] =(sort(best_overall_score_efficient(Categories.All_Test_Frames))); plot_order = Categories.All_Test_Frames(ind); elseif strcmp(Plot.Example_Mode,'borderline') %%% ordering by how close they are to the topic_thresholds... [tmp2,ind] = sort(abs(best_overall_score_efficient(Categories.All_Test_Frames)-roc_threshold_efficient)); plot_order = Categories.All_Test_Frames(ind); else error('Unknown type of Plot.Example_Mode');end %% now setup figure and run loop plotting imagesfigure(BASE_FIG_NUM+2);nImage_Per_Figure = prod(Plot.Number_Per_Figure);for a=1:nImage_Per_Figure:length(Categories.All_Test_Frames) clf; %% clear figure for b=1:nImage_Per_Figure %%% actual index index = plot_order(a+b-1); %%% get correct subplot subplot(Plot.Number_Per_Figure(1),Plot.Number_Per_Figure(2),b); %%% load image im=imread(img_file_names{index}); %%% show image imagesc(im); hold on; %%% if grayscale, then adjust colormap if (size(im,3)==1) colormap(gray); end %%% load up interest_point file load(ip_file_names{index}); %%% now mark in best hypothesis for b=1:Learn.Num_Parts plot(best_locations_x(b,index),best_locations_y(b,index),cols2{b},'Markersize',20,'Linewidth',8); end if (~isempty(gt_boxes{index})) %%% show ground_truth bounding box rectangle('Position',gt_boxes{index},'EdgeColor','b','Linewidth',2); if (localization_labels_efficient(index)==1) %% correct localization rectangle('Position',bounding_box_efficient{index},'EdgeColor','g','Linewidth',2); else %% incorrect rectangle('Position',bounding_box_efficient{index},'EdgeColor','r','Linewidth',2); end end h=title(['Image: ',num2str(index),' Best match score: ',num2str(best_overall_score_efficient(index))]); if (labels_efficient(index)==1) set(h,'Color','g'); else set(h,'Color','r'); end end pause end
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -