-
Notifications
You must be signed in to change notification settings - Fork 0
/
run.m
73 lines (57 loc) · 2.01 KB
/
run.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
function ludo(varargin)
% First attempt: default options, best result early stop epoch 19
% Load imdb file
imdb = load('imdb.mat');
%imdb = load('MatConvNet/data/cifar/imdb.mat');
% Load neural net
net = eboy_nn_init_v2();
% Set training parameters
trainOpts.batchSize = 100 ;
trainOpts.numEpochs = 60 ;
trainOpts.continue = true ;
trainOpts.gpus = [] ;
%trainOpts.learningRate = 0.001 ;
trainOpts.expDir = 'log_ludov2_1/' ;
trainOpts = vl_argparse(trainOpts, varargin);
% Call training function in MatConvNet
[net,info] = cnn_train(net, imdb, @getBatch, trainOpts) ;
% Save imdb mean in net
net.meta.dataMean = imdb.meta.dataMean;
% Save the result for later use
save('log_ludov2_1/eboy_nn.mat', '-struct', 'net') ;
% -------------------------------------------------------------------------
% Part 4.4: visualize the learned filters
% -------------------------------------------------------------------------
% figure(2) ; clf ; colormap gray ;
% vl_imarraysc(squeeze(net.layers{1}.weights{1}),'spacing',2)
% axis equal ; title('filters in the first layer') ;
% -------------------------------------------------------------------------
% Part 4.5: apply the model
% -------------------------------------------------------------------------
% % Load the CNN learned before
net = load('log/eboy_nn.mat') ;
% %net = load('data/chars-experiment/charscnn-jit.mat') ;
%
% % Load the sentence
% [im,cmap] = imread('data/sentence-lato.png') ;
% if isempty(cmap)
% im = im2single(im) ;
% else
% im = im2single(ind2gray(p,cmap)) ;
% end
% im = 256 * (im - net.imageMean) ;
% % Apply the CNN to the larger image
% res = vl_simplenn(net, im) ;
%
% % Visualize the results
% figure(3) ; clf ;
% decodeCharacters(net, imdb, im, res) ;
% --------------------------------------------------------------------
function [im, labels] = getBatch(imdb, batch)
% --------------------------------------------------------------------
im = imdb.images.data(:,:,:,batch) ;
im = 256 * im;
%im = reshape(im, 50, 30, 3, []);
labels = imdb.images.label(1,batch);
end
end