-
-
Notifications
You must be signed in to change notification settings - Fork 65
/
train_id_net_res_market_align.m
executable file
·42 lines (41 loc) · 2.01 KB
/
train_id_net_res_market_align.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
function train_id_net_vgg16(varargin)
% -------------------------------------------------------------------------
% Part 4.1: prepare the datagpu_c
% -------------------------------------------------------------------------
imdb = load('./url_data.mat') ;
imdb = imdb.imdb;
%imdb.images.set(1:10000) = 3;
% -------------------------------------------------------------------------
% Part 4.2: initialize a CNN architecture
% -------------------------------------------------------------------------
net = resnet52_market_stn_alignment();
net.conserveMemory = true;
net.meta.normalization.averageImage = reshape([105.6920,99.1345,97.9152],1,1,3);
% -------------------------------------------------------------------------
% Part 4.3: train and evaluate the CNN
% -------------------------------------------------------------------------
opts.train.averageImage = net.meta.normalization.averageImage;
opts.train.batchSize = 32;
opts.train.continue = true ;
opts.train.gpus = 1; %gpu id
opts.train.prefetch = false ;
opts.train.expDir = './data/resnet52_stn_align_baseline_initial0.8_drop_0.9_1e-5_batch32' ;
opts.train.derOutputs = {'objective', 0,'objective_local',1};
opts.train.momentum = 0.9;
opts.train.nesterovUpdate = true;
opts.train.learningRate = [0.1*ones(1,30),0.01*ones(1,10)] ;
opts.train.weightDecay = 0.0005;
opts.train.numEpochs = numel(opts.train.learningRate) ;
[opts, ~] = vl_argparse(opts.train, varargin) ;
% Call training function in MatConvNet
[net,info] = cnn_train_dag2(net, imdb, @getBatch,opts) ;
% --------------------------------------------------------------------
function inputs = getBatch(imdb,batch,opts)
% --------------------------------------------------------------------
im_url = imdb.images.data(batch) ;
im = vl_imreadjpeg(im_url,'Pack','Resize',[224,224],'Flip',...
'CropLocation','random','CropSize',[0.875,1],...
'Interpolation', 'bicubic','NumThreads',8);
labels = imdb.images.label(batch) ;
oim = bsxfun(@minus,im{1},opts.averageImage);
inputs = {'data',gpuArray(oim),'label',labels,'label_local',labels};