Permalink
Browse files

Fix train coeffs

  • Loading branch information...
Abel Gonzalez
Abel Gonzalez committed May 15, 2017
1 parent 214cf9d commit 731810de93737cd817a6403904377423fa0f6e22
@@ -91,11 +91,8 @@
'numPrtClasses',imdb.numClassesPrt,'numOuts',numOuts);
-t1 = tic();
%%% Train
calvinn.train();
-times(3,1) = toc(t1);
-
%%% Test
@@ -108,19 +105,16 @@
% Setup again imdb --> for testing we need all images (without parts too)
ONparams.test = 1;
[imdb, idxPartGlobal2idxClass] = setupImdbPartDetection(@ImdbOffsetNet, trainName, testName, net, ONparams);
-
-
+
nnOpts.misc.numOuts = numOuts;
nnOpts.misc.idxPartGlobal2idxClass = idxPartGlobal2idxClass(2:end);
-calvinnObjAppCls = CalvinNN(netObjAppCls, imdb, nnOpts);
-
-calvinnObjAppCls.mergeObjAppClswOffsetNet('offsetNet', calvinn.net, 'numOuts', max(numOuts));
-t2 = tic;
-stats = calvinnObjAppCls.test;
-times(3,2) = toc(t2);
-
-save([nnOpts.expDir 'stats.mat'], 'stats','-v7.3');
+% calvinnObjAppCls = CalvinNN(netObjAppCls, imdb, nnOpts);
+%
+% calvinnObjAppCls.mergeObjAppClswOffsetNet('offsetNet', calvinn.net, 'numOuts', max(numOuts));
+% stats = calvinnObjAppCls.test;
+%
+% save([nnOpts.expDir '/stats.mat'], 'stats','-v7.3');
%%% Train coefficients if necessary
@@ -29,10 +29,9 @@ function evalPartAndObjectDetection(testName, stats, nnOpts)
currBoxes = cell(testCount, 1);
currScores = cell(testCount, 1);
for i=1:testCount
-
-
+
if isfield(nnOpts,'CM')
- currNetBoxes = stats.results(i).boxesPrt;
+ currNetBoxes = stats.results(i).boxesPrt{cI+1};
currNetScores = stats.results(i).scoresPrt{cI+1};
% Assume stats has ON info if nnOpts has coefficients field
@@ -94,14 +93,53 @@ function evalPartAndObjectDetection(testName, stats, nnOpts)
currBoxes = cell(testCount, 1);
currScores = cell(testCount, 1);
for i=1:testCount
- % Get regressed boxes and refit them to the image
- currBoxes{i} = stats.results(i).boxesRegressedPrt{cI+1};
- currBoxes{i}(:,1) = max(currBoxes{i}(:,1), 1);
- currBoxes{i}(:,2) = max(currBoxes{i}(:,2), 1);
- currBoxes{i}(:,3) = min(currBoxes{i}(:,3), imSizes(i,2));
- currBoxes{i}(:,4) = min(currBoxes{i}(:,4), imSizes(i,1));
-
- currScores{i} = stats.results(i).scoresRegressedPrt{cI+1};
+ if isfield(nnOpts,'CM')
+ currNetBoxes = stats.results(i).boxesRegressedPrt{cI+1};
+ currNetBoxes(:,1) = max(currNetBoxes(:,1), 1);
+ currNetBoxes(:,2) = max(currNetBoxes(:,2), 1);
+ currNetBoxes(:,3) = min(currNetBoxes(:,3), imSizes(i,2));
+ currNetBoxes(:,4) = min(currNetBoxes(:,4), imSizes(i,1));
+ currNetScores = stats.results(i).scoresPrt{cI+1};
+
+ % Assume stats has ON info if nnOpts has coefficients field
+ scoresObjDets = stats.results(i).objDetsScores{cI};
+ dispWindows = stats.results(i).dispWindows{cI};
+ presenceScores = stats.results(i).presenceScores{cI};
+
+ % Only consider those displaced windows the ones that
+ windowWeights = repmat(scoresObjDets,numel(presenceScores)...
+ /numel(scoresObjDets),1).*presenceScores;
+
+ scoreFromDispWindows = scoreBoxesWithDispWindowsUnsorted(dispWindows, currNetBoxes, windowWeights);
+
+ newScoresNet = (1-nnOpts.CM(cI))*currNetScores + ...
+ nnOpts.CM(cI)*scoreFromDispWindows;
+
+ boxes = currNetBoxes;
+ scores = newScoresNet;
+
+ % Sort, get detections > thresh and perform NMS
+ [currNetScoresT, sI] = sort(scores, 'descend');
+ currNetBoxesT = boxes(sI,:);
+
+ goodI = currNetScoresT > minDetectionScore;
+ currScoresT = currNetScoresT(goodI, :);
+ currBoxesT= currNetBoxesT(goodI, :);
+
+ [~, goodBoxesI] = BoxNMS(currBoxesT);
+ currBoxes{i} = currBoxesT(goodBoxesI, :);
+ currScores{i} = currScoresT(goodBoxesI);
+
+ else
+ % Get regressed boxes and refit them to the image
+ currBoxes{i} = stats.results(i).boxesRegressedPrt{cI+1};
+ currBoxes{i}(:,1) = max(currBoxes{i}(:,1), 1);
+ currBoxes{i}(:,2) = max(currBoxes{i}(:,2), 1);
+ currBoxes{i}(:,3) = min(currBoxes{i}(:,3), imSizes(i,2));
+ currBoxes{i}(:,4) = min(currBoxes{i}(:,4), imSizes(i,1));
+
+ currScores{i} = stats.results(i).scoresRegressedPrt{cI+1};
+ end
end
[currBoxes, fileIdx] = Cell2Matrix(gather(currBoxes));
@@ -65,13 +65,8 @@
batchData{idx} = 'presenceTargets'; idx = idx + 1;
batchData{idx} = reshape(presenceTargets', 1,1,size(presenceTargets,2), size(presenceTargets,1)); idx = idx + 1;
batchData{idx} = 'oriImSize'; idx = idx + 1;
- batchData{idx} = oriImSize; idx = idx + 1;
-
-% batchData{idx} = 'instanceWeights'; idx = idx + 1;
-% batchData{idx} = []; %idx = idx + 1;
-%
-
-
+ batchData{idx} = oriImSize;
+
else
% Test set. Get all boxes
[boxesPrt, keysPrt] = obj.SampleAllBoxesFromGstructPrt(gStruct);
@@ -21,7 +21,8 @@
ONparams = [];
else
% Consider only images with at least one part when training OffsetNet
- if ~ONparams.test
+ % or when training coefficients
+ if ~ONparams.test || ONparams.trainCoeffs
trainIms = imdbTrain.image_ids(unique(imdbTrain.mapping(:,4)));
testIms = imdbTest.image_ids(unique(imdbTest.mapping(:,4)));
end
@@ -9,7 +9,7 @@
imdbTest = trash.imdb;
clear trash;
% Use images with at least one part
-testIms = imdbTest.image_ids(unique(imdbTest.mapping(:,4)));
+testIms = imdbTest.image_ids;(unique(imdbTest.mapping(:,4)));
% get image sizes
testCount = length(testIms);
@@ -49,8 +49,8 @@
scoreFromDispWindows = scoreBoxesWithDispWindowsUnsorted(dispWindows, currNetBoxes, windowWeights);
- newScoresNet = (1-coeffs(cI))*currNetScores + ...
- coeffs(cI)*scoreFromDispWindows;
+ newScoresNet = (1-coeffs(kk))*currNetScores + ...
+ coeffs(kk)*scoreFromDispWindows;
boxes = currNetBoxes;
scores = newScoresNet;
@@ -20,11 +20,7 @@ function convertNetworkToOffsetNet(obj, varargin)
addParameter(p, 'numOuts','0');
parse(p, varargin{:});
-lastConvPoolName = p.Results.lastConvPoolName;
-firstFCName = p.Results.firstFCName;
-secondFCName = p.Results.secondFCName;
finalFCName = p.Results.finalFCName;
-numObjClasses = p.Results.numObjClasses;
numPrtClasses = p.Results.numPrtClasses;
numOuts = p.Results.numOuts;
View
@@ -9,16 +9,12 @@ function setup()
% Define paths
root = fileparts(mfilename('fullpath'));
matconvnetFolder = fullfile(root, 'matconvnet', 'matlab');
-matconvnetFcnFolder = fullfile(root, 'matconvnet-fcn');
matconvnetCalvinFolder = fullfile(root, 'matconvnet-calvin');
% Add matconvnet
addpath(matconvnetFolder);
vl_setupnn();
-% Add matconvnet-fcn
-addpath(matconvnetFcnFolder);
-
% Add matconvnet-calvin
addpath(genpath(matconvnetCalvinFolder));

0 comments on commit 731810d

Please sign in to comment.