|
| 1 | + |
| 2 | + |
| 3 | +datasetName = 'ILSVRCvalSet'; |
| 4 | +load('imagenet_toolkit/ILSVRC2014_devkit/evaluation/cache_groundtruth.mat'); |
| 5 | +load('imagenet_toolkit/ILSVRC2014_devkit/data/meta_clsloc.mat'); |
| 6 | +datasetPath = 'dataset/ILSVRC2012'; |
| 7 | +load([datasetPath '/imageListVal.mat']); |
| 8 | +load('sizeImg_ILSVRC2014.mat'); |
| 9 | + |
| 10 | +% datasetName = 'ILSVRCtestSet'; |
| 11 | +% datasetPath = '/data/vision/torralba/deeplearning/imagenet_toolkit'; |
| 12 | +% load([datasetPath '/imageListTest.mat']); |
| 13 | + |
| 14 | + |
| 15 | +nImgs = size(imageList,1); |
| 16 | + |
| 17 | +ground_truth_file='imagenet_toolkit/ILSVRC2014_devkit/data/ILSVRC2014_clsloc_validation_ground_truth.txt'; |
| 18 | +gt_labels = dlmread(ground_truth_file); |
| 19 | + |
| 20 | +categories_gt = []; |
| 21 | +categoryIDMap = containers.Map(); |
| 22 | +for i=1:numel(synsets) |
| 23 | + categories_gt{synsets(i).ILSVRC2014_ID,1} = synsets(i).words; |
| 24 | + categories_gt{synsets(i).ILSVRC2014_ID,2} = synsets(i).WNID; |
| 25 | + categoryIDMap(synsets(i).WNID) = i; |
| 26 | +end |
| 27 | + |
| 28 | + |
| 29 | + |
| 30 | +%% network to evaluate |
| 31 | +% backpropa-heatmap |
| 32 | +%netName = 'caffeNet_imagenet'; |
| 33 | +%netName = 'googlenetBVLC_imagenet'; |
| 34 | +%netName = 'VGG16_imagenet'; |
| 35 | + |
| 36 | +% CAM-based network |
| 37 | +%netName = 'NIN'; |
| 38 | +%netName = 'CAM_imagenetCNNaveSumDeep'; |
| 39 | +%netName = 'CAM_googlenetBVLC_imagenet';% the direct output |
| 40 | +netName = 'CAM_googlenetBVLCshrink_imagenet'; |
| 41 | +%netName = 'CAM_googlenetBVLCshrink_imagenet_maxpool'; |
| 42 | +%netName = 'CAM_VGG16_imagenet'; |
| 43 | +%netName = 'CAM_alexnet'; |
| 44 | + |
| 45 | +load('categoriesImageNet.mat'); |
| 46 | + |
| 47 | +visualizationPointer = 0; |
| 48 | + |
| 49 | +topCategoryNum = 5; |
| 50 | +predictionResult_bbox1 = zeros(nImgs, topCategoryNum*5); |
| 51 | +predictionResult_bbox2 = zeros(nImgs, topCategoryNum*5); |
| 52 | +predictionResult_bboxCombine = zeros(nImgs, topCategoryNum*5); |
| 53 | + |
| 54 | +if matlabpool('size')==0 |
| 55 | + try |
| 56 | + matlabpool |
| 57 | + catch e |
| 58 | + end |
| 59 | +end |
| 60 | + |
| 61 | +heatMapFolder = ['heatMap-' datasetName '-' netName]; |
| 62 | +bbox_threshold = [20, 100, 110]; |
| 63 | +curParaThreshold = [num2str(bbox_threshold(1)) ' ' num2str(bbox_threshold(2)) ' ' num2str(bbox_threshold(3))]; |
| 64 | +parfor i=1:size(imageList,1) |
| 65 | + curImgIDX = i; |
| 66 | + |
| 67 | + height_original = sizeFull_imageList(curImgIDX,1);%tmp.Height; |
| 68 | + weight_original = sizeFull_imageList(curImgIDX,2);%tmp.Width; |
| 69 | + |
| 70 | + [a b c] = fileparts(imageList{curImgIDX,1}); |
| 71 | + curPath_fullSizeImg = ['/data/vision/torralba/deeplearning/imagenet_toolkit/ILSVRC2012_img_val/' b c]; |
| 72 | + curMatFile = [heatMapFolder '/' b '.mat']; |
| 73 | + [heatMapSet, value_category, IDX_category] = loadHeatMap( curMatFile); |
| 74 | + |
| 75 | + curResult_bbox1 = []; |
| 76 | + curResult_bbox2 = []; |
| 77 | + curResult_bboxCombine = []; |
| 78 | + for j=1:5 |
| 79 | + curHeatMapFile = [heatMapFolder '/top' num2str(j) '/' b '.jpg']; |
| 80 | + |
| 81 | + curBBoxFile = [heatMapFolder '/top' num2str(j) '/' b '_default.txt']; |
| 82 | + %curBBoxFileGraphcut = [heatMapFolder '/top' num2str(j) '/' b '_graphcut.txt']; |
| 83 | + curCategory = categories{IDX_category(j),1}; |
| 84 | + %imwrite(curHeatMap, ['result_bbox/heatmap_tmp' b randString '.jpg']); |
| 85 | + if ~exist(curBBoxFile) |
| 86 | + %system(['/data/vision/torralba/deeplearning/package/bbox_hui/final ' curHeatMapFile ' ' curBBoxFile]); |
| 87 | + |
| 88 | + system(['/data/vision/torralba/deeplearning/package/bbox_hui_new/./dt_box ' curHeatMapFile ' ' curParaThreshold ' ' curBBoxFile]); |
| 89 | + end |
| 90 | + curPredictCategory = categories{IDX_category(j),1}; |
| 91 | + curPredictCategoryID = categories{IDX_category(j),1}(1:9); |
| 92 | + curPredictCategoryGTID = categoryIDMap(curPredictCategoryID); |
| 93 | + |
| 94 | + |
| 95 | + boxData = dlmread(curBBoxFile); |
| 96 | + boxData_formulate = [boxData(1:4:end)' boxData(2:4:end)' boxData(1:4:end)'+boxData(3:4:end)' boxData(2:4:end)'+boxData(4:4:end)']; |
| 97 | + boxData_formulate = [min(boxData_formulate(:,1),boxData_formulate(:,3)),min(boxData_formulate(:,2),boxData_formulate(:,4)),max(boxData_formulate(:,1),boxData_formulate(:,3)),max(boxData_formulate(:,2),boxData_formulate(:,4))]; |
| 98 | + |
| 99 | +% try |
| 100 | +% boxDataGraphcut = dlmread(curBBoxFileGraphcut); |
| 101 | +% boxData_formulateGraphcut = [boxDataGraphcut(1:4:end)' boxDataGraphcut(2:4:end)' boxDataGraphcut(1:4:end)'+boxDataGraphcut(3:4:end)' boxDataGraphcut(2:4:end)'+boxDataGraphcut(4:4:end)']; |
| 102 | +% catch exception |
| 103 | +% boxDataGraphcut = dlmread(curBBoxFile); |
| 104 | +% boxData_formulateGraphcut = [boxDataGraphcut(1:4:end)' boxDataGraphcut(2:4:end)' boxDataGraphcut(1:4:end)'+boxDataGraphcut(3:4:end)' boxDataGraphcut(2:4:end)'+boxDataGraphcut(4:4:end)']; |
| 105 | +% boxData_formulateGraphcut = boxData_formulateGraphcut(1,:); |
| 106 | +% end |
| 107 | + |
| 108 | + bbox = boxData_formulate(1,:); |
| 109 | + curPredictTuple = [curPredictCategoryGTID bbox(1) bbox(2) bbox(3) bbox(4)]; |
| 110 | + curResult_bbox1 = [curResult_bbox1 curPredictTuple]; |
| 111 | + curResult_bboxCombine = [curResult_bboxCombine curPredictTuple]; |
| 112 | + |
| 113 | + bbox = boxData_formulate(2,:); |
| 114 | + %bbox = boxData_formulateGraphcut(1,:); |
| 115 | + curPredictTuple = [curPredictCategoryGTID bbox(1) bbox(2) bbox(3) bbox(4)]; |
| 116 | + curResult_bbox2 = [curResult_bbox2 curPredictTuple]; |
| 117 | + |
| 118 | + curResult_bboxCombine = [curResult_bboxCombine curPredictTuple]; |
| 119 | + if visualizationPointer == 1 |
| 120 | + |
| 121 | + curHeatMap = imread(curHeatMapFile); |
| 122 | + curHeatMap = imresize(curHeatMap,[height_original weight_original]); |
| 123 | + |
| 124 | + subplot(1,2,1),hold off, imshow(curPath_fullSizeImg); |
| 125 | + hold on |
| 126 | + curBox = boxData_formulate(1,:); |
| 127 | + rectangle('Position',[curBox(1) curBox(2) curBox(3)-curBox(1) curBox(4)-curBox(2)],'EdgeColor',[1 0 0]); |
| 128 | + subplot(1,2,2),imagesc(curHeatMap); |
| 129 | + title(curCategory); |
| 130 | + waitforbuttonpress |
| 131 | + end |
| 132 | + end |
| 133 | + |
| 134 | + predictionResult_bbox1(i, :) = curResult_bbox1; |
| 135 | + predictionResult_bbox2(i, :) = curResult_bbox2; |
| 136 | + predictionResult_bboxCombine(i,:) = curResult_bboxCombine(1:topCategoryNum*5); |
| 137 | + disp([netName ' processing ' b]) |
| 138 | +end |
| 139 | + |
| 140 | + |
| 141 | +addpath('imagenet_toolkit/ILSVRC2014_devkit/evaluation'); |
| 142 | +disp([netName '--------bbox1' ]); |
| 143 | +[cls_error, clsloc_error] = simpleEvaluation(predictionResult_bbox1); |
| 144 | +disp([(1:5)',clsloc_error,cls_error]); |
| 145 | + |
| 146 | +disp([netName '--------bbox2' ]); |
| 147 | +[cls_error, clsloc_error] = simpleEvaluation(predictionResult_bbox2); |
| 148 | +disp([(1:5)',clsloc_error,cls_error]); |
| 149 | + |
| 150 | +disp([netName '--------bboxCombine' ]); |
| 151 | +[cls_error, clsloc_error] = simpleEvaluation(predictionResult_bboxCombine); |
| 152 | +disp([(1:5)',clsloc_error,cls_error]); |
0 commit comments