time | Calls | line |
---|
| | 1 | function example(options, input_format, save_loc)
|
| | 2 |
|
| | 3 | if nargin == 0
|
| | 4 | options = '';
|
| | 5 | end
|
| | 6 | if nargin <= 1
|
| | 7 | input_format = 0;
|
| | 8 | end
|
| | 9 | if (input_format ~= 0) && (input_format ~= 1)
|
| | 10 | error('input_format must be 0 or 1.');
|
| | 11 | end
|
| | 12 |
|
| | 13 | % To access read_config.m file in cnn directory
|
| | 14 | addpath(genpath('./cnn'));
|
| | 15 |
|
| | 16 | %% Train
|
| | 17 | % ------
|
| | 18 | config_file = 'config/mnist-demo-layer4.config';
|
| | 19 | net_config = read_config(config_file);
|
| | 20 | a = net_config.ht_input(1);
|
| | 21 | b = net_config.wd_input(1);
|
| | 22 | d = net_config.ch_input(1);
|
| | 23 |
|
| | 24 | % Read train data sets
|
| | 25 | load('data/mnist.mat', 'y', 'Z');
|
| | 26 | % Because sparse matrices stored in the provided mat file do not store zero columns in the end, we need to fill it.
|
| | 27 | Z = [full(Z) zeros(size(Z,1), a*b*d - size(Z,2))];
|
| | 28 |
|
| | 29 | % If input data format is row-wise, we rearrange data from row-wise to col-wise
|
| | 30 | if input_format == 0
|
| | 31 | Z = reshape(permute(reshape(Z, [],b,a,d), [1,3,2,4]), [], a*b*d);
|
| | 32 | end
|
| | 33 |
|
| | 34 | % Normalization
|
| | 35 | Z = Z / 255;
|
| | 36 |
|
| | 37 | % Zero mean
|
| | 38 | mean_tr = mean(Z);
|
| | 39 | Z = Z - mean_tr;
|
| | 40 |
|
| | 41 | seed = 111;
|
| | 42 |
|
| | 43 | profile on
|
2206.187 | 1 | 44 | model = cnn_train(y, Z, [], [], config_file, options, seed);
|
0.003 | 1 | 45 | profsave(profile('info'), save_loc)
|
Other subfunctions in this file are not included in this listing.