Skip to content

Commit

Permalink
Experiment Scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
shubhtuls committed Sep 23, 2015
1 parent f2ae888 commit fd17158
Show file tree
Hide file tree
Showing 7 changed files with 92 additions and 39 deletions.
39 changes: 39 additions & 0 deletions 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
8 changes: 6 additions & 2 deletions mainPredict.m
Expand Up @@ -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
21 changes: 0 additions & 21 deletions mainRigidViewpoint.m

This file was deleted.

24 changes: 24 additions & 0 deletions 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
20 changes: 11 additions & 9 deletions 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
Expand Down Expand Up @@ -59,21 +59,22 @@
end
end
%keyboard;
similarityFeatName = params.similarityFeatName;'vggConv5';
similarityFeatName = params.similarityFeatName; %'vggConv5';
spatialFeat = ~isempty(strfind(similarityFeatName,'Pool')) || ~isempty(strfind(similarityFeatName,'Conv'));
spatialNormSmoothing = params.spatialNormSmoothing;

%% set-up optimization
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
Expand All @@ -89,6 +90,7 @@
else
for i=1:length(feat)
feat{i} = sigmoid(feat{i});
feat{i} = (feat{i}(:))';
end
end

Expand Down Expand Up @@ -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

Expand All @@ -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

Expand Down
4 changes: 2 additions & 2 deletions prettyPrintResults.m
Expand Up @@ -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
15 changes: 10 additions & 5 deletions 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
Expand All @@ -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
Expand All @@ -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);

Expand All @@ -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]);
Expand All @@ -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');
Expand Down

0 comments on commit fd17158

Please sign in to comment.