From fd17158cf775e25e0f015141bef2eb4c04d0b606 Mon Sep 17 00:00:00 2001 From: Shubham Tulsiani Date: Tue, 22 Sep 2015 22:12:17 -0700 Subject: [PATCH] Experiment Scripts --- mainExperiment.m | 39 ++++++++++++++++++++++++++++++ mainPredict.m | 8 ++++-- mainRigidViewpoint.m | 21 ---------------- mainViewpoint.m | 24 ++++++++++++++++++ optimization/optimizePredictions.m | 20 ++++++++------- prettyPrintResults.m | 4 +-- regressToPose.m | 15 ++++++++---- 7 files changed, 92 insertions(+), 39 deletions(-) create mode 100644 mainExperiment.m delete mode 100644 mainRigidViewpoint.m create mode 100644 mainViewpoint.m diff --git a/mainExperiment.m b/mainExperiment.m new file mode 100644 index 0000000..9c0c568 --- /dev/null +++ b/mainExperiment.m @@ -0,0 +1,39 @@ +function [perfAblations] = mainExperiment() +%MAINEXPERIMENT Summary of this function goes here +% Detailed explanation goes here +globals; +params = getParams(); +classInds = [6 14 12 17]; %bus, motorbike, dog, sheep +nClasses = length(classInds); +usePascalViews = [0 0 1 1]; %evaluation using pascal3d or pascal voc labels + +%% Run SCT vs GC Experiment +perfAblations = zeros(5,nClasses); + +params.features = 'vggJoint16'; +perfAblations(1,:) = mainViewpoint(classInds, usePascalViews); %% prints accuracy for bus, motorbike, dog, sheep respectively + +params.features = 'vggCommon16'; +perfAblations(2,:) = mainViewpoint(classInds, usePascalViews); %% prints accuracy for bus, motorbike, dog, sheep respectively + +%% Run experiment for various similarity features + +params.similarityFeatName = 'vggConv5'; +for c = 1:nClasses + [~,optAcc] = optimizePredictions(pascalIndexClass(classInds(c),'pascal'),0,usePascalViews(c),1,0,0); + perfAblations(3,c) = optAcc; +end + +params.spatialNormSmoothing = 0; +for c = 1:nClasses + [~,optAcc] = optimizePredictions(pascalIndexClass(classInds(c),'pascal'),0,usePascalViews(c),1,0,0); + perfAblations(4,c) = optAcc; +end + +params.similarityFeatName = 'vggFc7'; +for c = 1:nClasses + [~,optAcc] = optimizePredictions(pascalIndexClass(classInds(c),'pascal'),0,usePascalViews(c),1,0,0); + perfAblations(5,c) = optAcc; +end + +end \ No newline at end of file diff --git a/mainPredict.m b/mainPredict.m index 2ce4851..d3a1a1b 100644 --- a/mainPredict.m +++ b/mainPredict.m @@ -3,14 +3,18 @@ % Detailed explanation goes here %% predictions for SCT -generatePoseFeatures('vggJoint16','vggJoint16',224,[6 12 14 17],0,0,[7 9 2 10]); +generatePoseFeatures('vggJoint16','vggJoint16',224,[6 12 14 17],2,0,[7 8 2 10]); caffe.reset_all(); %% predictions for GC -generatePoseFeatures('vggCommon16','vggCommon16',224,[6 12 14 17],0,0); +generatePoseFeatures('vggCommon16','vggCommon16',224,[6 12 14 17],2,0); caffe.reset_all(); %% add VGG conv5 feature computation here +generatePoseFeatures('vggConv5','vgg',224,[6 12 14 17],2,0); +caffe.reset_all(); +generatePoseFeatures('vggFc7','vgg',224,[6 12 14 17],2,0); +caffe.reset_all(); end \ No newline at end of file diff --git a/mainRigidViewpoint.m b/mainRigidViewpoint.m deleted file mode 100644 index f5dd340..0000000 --- a/mainRigidViewpoint.m +++ /dev/null @@ -1,21 +0,0 @@ -%% Define Classes -classes = {'aeroplane','bicycle','bird','boat','bottle','bus','car','cat','chair','cow','diningtable','dog','horse','motorbike','person','plant','sheep','sofa','train','tvmonitor'}; -%classInds = [1 2 4 5 6 7 9 11 14 18 19 20]; -%classInds = [1 2 4 5 6 7 9]; -%classInds = [1 2 6 7 9 14]; -%classInds = [1 2 4 5 6 7 9 11 14 18 19 20]; -%classInds = [1 2 4 5 6 7 9 14 18 19 20]; -%classInds = [12 17]; -classInds = [6 14]; -numClasses = size(classInds,2); - -%% Iterate over pose predictions -errors = zeros(numClasses,1); -medErrors = zeros(numClasses,1); -for c = 1:numClasses - class = classes{classInds(c)}; - disp(class); - [err,medErr] = regressToPose(class); - errors(c,:)=err;medErrors(c,:) = medErr; -end -prettyPrintResults(errors,medErrors); diff --git a/mainViewpoint.m b/mainViewpoint.m new file mode 100644 index 0000000..66e0a40 --- /dev/null +++ b/mainViewpoint.m @@ -0,0 +1,24 @@ +function errors = mainViewpoint(classInds, usePascalViews) + %% Define Classes + classes = {'aeroplane','bicycle','bird','boat','bottle','bus','car','cat','chair','cow','diningtable','dog','horse','motorbike','person','plant','sheep','sofa','train','tvmonitor'}; + %classInds = [1 2 4 5 6 7 9 11 14 18 19 20]; + %classInds = [1 2 4 5 6 7 9]; + %classInds = [1 2 6 7 9 14]; + %classInds = [1 2 4 5 6 7 9 11 14 18 19 20]; + %classInds = [1 2 4 5 6 7 9 14 18 19 20]; + %classInds = [12 17]; + + numClasses = size(classInds,2); + + %% Iterate over pose predictions + errors = zeros(numClasses,1); + medErrors = zeros(numClasses,1); + for c = 1:numClasses + class = classes{classInds(c)}; + disp(class); + [err,medErr] = regressToPose(class, usePascalViews(c)); + errors(c,:)=err; + medErrors(c,:) = medErr; + end + prettyPrintResults(errors,medErrors); +end \ No newline at end of file diff --git a/optimization/optimizePredictions.m b/optimization/optimizePredictions.m index a315e6f..bf1f5b0 100644 --- a/optimization/optimizePredictions.m +++ b/optimization/optimizePredictions.m @@ -1,4 +1,4 @@ -function [preds] = optimizePredictions(class,useSaved,evalPascalViews,useMirror,useSoftAssignment,azimuthOnly) +function [preds,testAccuracyOpt] = optimizePredictions(class,useSaved,evalPascalViews,useMirror,useSoftAssignment,azimuthOnly) %OPTIMIZEPREDICTIONS Summary of this function goes here % Detailed explanation goes here % useSaved is 0/1 : 1 means it uses @@ -59,7 +59,7 @@ end end %keyboard; -similarityFeatName = params.similarityFeatName;'vggConv5'; +similarityFeatName = params.similarityFeatName; %'vggConv5'; spatialFeat = ~isempty(strfind(similarityFeatName,'Pool')) || ~isempty(strfind(similarityFeatName,'Conv')); spatialNormSmoothing = params.spatialNormSmoothing; @@ -67,13 +67,14 @@ formulationDir = fullfile(cachedir,['optimizationInit' params.vpsDataset],params.features); mkdirOptional(formulationDir); if(useSaved && exist(fullfile(formulationDir,[class '.mat']),'file')) - load(fullfile(formulationDir,[class '.mat'])) + load(fullfile(formulationDir,[class '.mat'])); else fg = fspecial('gaussian',[5 5],1); - load(fullfile(cachedir,['rcnnPredsVps' params.vpsDataset],similarityFeatName,class)); + var = load(fullfile(cachedir,['rcnnPredsVps' params.vpsDataset],similarityFeatName,class)); %load(fullfile(cachedir,['rcnnPredsVps' params.vpsDataset],'vggSimilarityCommon16',class)); - feat = feat(goodInds); + feat = var.featStruct{1};feat = feat(goodInds); if(useMirror) + featMirror = var.featStructMirror{1}; featMirror = featMirror(goodInds); feat = vertcat(feat,featMirror); end @@ -89,6 +90,7 @@ else for i=1:length(feat) feat{i} = sigmoid(feat{i}); + feat{i} = (feat{i}(:))'; end end @@ -162,8 +164,8 @@ end [testErrsOpt] = evaluatePredictionError({preds},testLabels,encoding,0); - testAccuracyOpt = sum(testErrsOpt<=30)/numel(testErrsOpt) - testMedErrorOpt = median(testErrsOpt) + testAccuracyOpt = sum(testErrsOpt<=30)/numel(testErrsOpt); + testMedErrorOpt = median(testErrsOpt); disp(numFlips); end @@ -183,9 +185,9 @@ %% eval left/right/frontal if(evalPascalViews) [accLabels,~,isCorrectLabels] = evaluatePascalViews(testLabels(:,3),data.test.views); - accLabels + %accLabels [accOpt,isGoodOpt,isCorrectOpt] = evaluatePascalViews(preds(:,3),data.test.views); - accOpt + testAccuracyOpt = accOpt; evaluatePascalViews(testPredsAec{1}(:,3),data.test.views) end diff --git a/prettyPrintResults.m b/prettyPrintResults.m index 83761c2..4d963b7 100644 --- a/prettyPrintResults.m +++ b/prettyPrintResults.m @@ -7,9 +7,9 @@ numClasses = size(errors,1); for col = 1:numCol for c = 1:numClasses - fprintf('%2.2f (%2.2f) \n',errors(c,col),medErrors(c,col)); + fprintf('%2.2f\n',errors(c,col)); end - fprintf('%2.2f (%2.2f) \n\n\n',mean(errors(:,col)),mean(medErrors(:,col))); + %fprintf('%2.2f (%2.2f) \n\n\n',mean(errors(:,col)),mean(medErrors(:,col))); end end diff --git a/regressToPose.m b/regressToPose.m index b2f78e0..34540bf 100644 --- a/regressToPose.m +++ b/regressToPose.m @@ -1,4 +1,4 @@ -function [testErrors,testMedErrors,testErrs,testData,testPreds,testLabels] = regressToPose(class) +function [testErrors,testMedErrors,testErrs,testData,testPreds,testLabels] = regressToPose(class, evalPascalViews) %[testErrors,testMedErrors] = regressToPose(class) % uses the training/val/test sets specified in parameters and % regresses to pose and returns error @@ -14,7 +14,7 @@ %data = load(fullfile(cachedir,'splitSets',class)); data = load(fullfile(cachedir,'evalSets',class)); -[trainLabels,valLabels,testLabels,trainFeats,valFeats,testFeats] = generateEvalSetData(data); +[~,~,testLabels,~,~,testFeats] = generateEvalSetData(data); %% TESTING switch params.optMethod @@ -36,6 +36,9 @@ %keyboard; testErrs = evaluatePredictionError(testPreds,testLabels,encoding,0); +if(evalPascalViews) + [accPascalViews] = evaluatePascalViews(testPreds(:,3),data.test.views); +end %[valErrs,bestValPred] = evaluatePredictionError(valPreds,valLabels,encoding,0); %[trainErrs,bestTrainPred] = evaluatePredictionError(trainPred,trainLabels,encoding,0); @@ -44,9 +47,6 @@ testErrors = [];testMedErrors=[]; %testErrs = [valErrs;testErrs]; -testErrors(1) = mean(testErrors); -testMedErrors(1) = median(testErrors); - % plot(sort(valErrs),[1:length(valErrs)]./length(valErrs),'r');hold on; % plot([0 180],[0 1],'k'); % grid on;xlim([0 180]);ylim([0 1]); @@ -56,7 +56,12 @@ testErrors(1) = sum(testErrs<=30)/numel(testErrs); testMedErrors(1) = median(testErrs); +if(evalPascalViews) + [accPascalViews] = evaluatePascalViews(testPreds(:,3),data.test.views); + testErrors(1) = accPascalViews; +end testData = data.test; + %[errSort,IDX] = sort(testErrs,'ascend'); %plot(errSort,[1:length(errSort)]/length(errSort));pause();close all; %visualizePredictions(class,testPreds{1},data.test,encoding,testErrs,'image');