Permalink
Browse files

Standardized cls and det examples

  • Loading branch information...
nightrome committed Sep 23, 2016
1 parent 09a926c commit 30ea8e960f4b2743ded42369cbfd9319d6220535
View
@@ -7,13 +7,6 @@
% Add folders to path
setup();
% Settings
expNameAppend = 'testRelease';
global glBaseFolder;
global MYDATADIR;
MYDATADIR = [fullfile(glBaseFolder, 'Datasets', 'VOC2010'), '/'];
% Download dataset
downloadVOC2010();
@@ -1,20 +1,32 @@
% function calvinNNClassification
% function calvinNNClassification()
%
% Copyright by Holger Caesar, 2016
% User inputs
global MYDATADIR % Directory of datasets
assert(~isempty(MYDATADIR));
% Global variables
global glDatasetFolder glFeaturesFolder;
assert(~isempty(glDatasetFolder) && ~isempty(glFeaturesFolder));
%%% Settings
% Dataset
vocYear = 2010;
trainName = 'train';
testName = 'val';
% Task
nnOpts.lossFnObjective = 'hinge';
% Specify paths
vocName = sprintf('VOC%d', vocYear);
datasetDir = [fullfile(glDatasetFolder, vocName), '/'];
outputFolder = fullfile(glFeaturesFolder, 'CNN-Models', 'CLS', vocName, sprintf('%s-testRelease', vocName));
netPath = fullfile(glFeaturesFolder, 'CNN-Models', 'matconvnet', 'imagenet-vgg-verydeep-16.mat');
% Setup dataset specific options and check validity
setupDataOpts(vocYear, testName, datasetDir);
global DATAopts;
assert(~isempty(DATAopts), 'Error: Dataset not initialized properly!');
% Task-specific
nnOpts.testFn = @testClassification;
nnOpts.lossFnObjective = 'hinge';
nnOpts.derOutputs = {'objective', single(1)};
targetImSize = [224, 224];
% Disable Fast R-CNN (default is on)
nnOpts.fastRcnn = false;
@@ -30,29 +42,30 @@
nnOpts.momentum = 0.9;
nnOpts.numEpochs = 16;
nnOpts.learningRate = [repmat(1e-3, 12, 1); repmat(1e-4, 4, 1)];
nnOpts.misc.netPath = fullfile(MYDATADIR, '..', 'MatconvnetModels', 'imagenet-vgg-verydeep-16.mat');
nnOpts.misc.netPath = netPath;
nnOpts.gpus = SelectIdleGpu();
nnOpts.expDir = [outputFolder, '/'];
% Setup data opts
setupDataOpts(vocYear, testName);
global DATAopts; % Database specific paths
nnOpts.expDir = [DATAopts.resdir, 'Matconvnet-Calvin', '/', 'cls', '/'];
% Start logging
logFile = 'log.txt';
diary(fullfile(outputFolder, logFile));
%%% Setup
% Start from pretrained network
net = load(nnOpts.misc.netPath);
% Setup imdb
imdb = setupImdbClassification(trainName, testName, net);
imdb.targetImSize = targetImSize;
imdb.targetImSize = [224, 224];
% Create calvinNN CNN class
calvinn = CalvinNN(net, imdb, nnOpts);
% Train
%%% Train
calvinn.train();
% Test
%%% Test
stats = calvinn.test();
% Eval
%%% Eval
evalClassification(imdb, stats, nnOpts);
@@ -2,21 +2,28 @@
%
% Copyright by Holger Caesar, 2016
% User inputs
global MYDATADIR % Directory of datasets
assert(~isempty(MYDATADIR));
% Global variables
global glDatasetFolder glFeaturesFolder;
assert(~isempty(glDatasetFolder) && ~isempty(glFeaturesFolder));
%%% Settings
% Dataset
vocYear = 2010;
trainName = 'train';
testName = 'val';
setupDataOpts(vocYear, testName);
global DATAopts; % Database specific paths
% Specify paths
vocName = sprintf('VOC%d', vocYear);
datasetDir = [fullfile(glDatasetFolder, vocName), '/'];
outputFolder = fullfile(glFeaturesFolder, 'CNN-Models', 'FRCN', vocName, sprintf('%s-testRelease', vocName));
netPath = fullfile(glFeaturesFolder, 'CNN-Models', 'matconvnet', 'imagenet-vgg-verydeep-16.mat');
% Setup dataset specific options and check validity
setupDataOpts(vocYear, testName, datasetDir);
global DATAopts;
assert(~isempty(DATAopts), 'Error: Dataset not initialized properly!');
nnOpts.expDir = [DATAopts.resdir, 'Matconvnet-Calvin', '/', 'det', '/'];
% Detection-specific
% Task-specific
nnOpts.testFn = @testDetection;
nnOpts.misc.overlapNms = 0.3;
nnOpts.derOutputs = {'objective', 1, 'regressObjective', 1};
@@ -28,9 +35,15 @@
nnOpts.momentum = 0.9;
nnOpts.numEpochs = 16;
nnOpts.learningRate = [repmat(1e-3, 12, 1); repmat(1e-4, 4, 1)];
nnOpts.misc.netPath = fullfile(calvin_root(), 'data', 'Features', 'CNN-Models', 'matconvnet', 'imagenet-vgg-verydeep-16.mat');
nnOpts.misc.netPath = netPath;
nnOpts.expDir = [expDir, '/'];
nnOpts.gpus = SelectIdleGpu();
% Start logging
logFile = 'log.txt';
diary(fullfile(outputFolder, logFile));
%%% Setup
% Start from pretrained network
net = load(nnOpts.misc.netPath);
@@ -41,11 +54,11 @@
% By default, network is transformed into fast-rcnn with bbox regression
calvinn = CalvinNN(net, imdb, nnOpts);
% Train
%%% Train
calvinn.train();
% Test
%%% Test
stats = calvinn.test();
% Eval
%%% Eval
evalDetection(testName, imdb, stats, nnOpts);
@@ -1,9 +1,9 @@
function[] = setupDataOpts(vocYear, testName)
function setupDataOpts(vocYear, testName, datasetDir)
global MYDATADIR DATAopts;
global DATAopts;
% Setup VOC data
devkitroot = [MYDATADIR, 'VOCdevkit', '/'];
devkitroot = [datasetDir, 'VOCdevkit', '/'];
DATAopts.year = vocYear;
DATAopts.dataset = sprintf('VOC%d', DATAopts.year);
DATAopts.datadir = [devkitroot, DATAopts.dataset, '/'];

0 comments on commit 30ea8e9

Please sign in to comment.