-
Notifications
You must be signed in to change notification settings - Fork 5
/
caffe_save_net_test.m
132 lines (107 loc) · 4.61 KB
/
caffe_save_net_test.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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
%% Description:
% Test for caffe_save_net function
%% Parameters:
%% Execution:
clear all;
% --- Building the net
net_filename = 'net_poke_test_auto';
net_header.name = 'TestNet';
% --- Data
lay_indx = 1;
net_descr{lay_indx} = caffe_layer_data_def( 'hdf5', 1); %Train
net_descr{lay_indx}.hdf5_data_param.batch_size = 256;
lay_indx = lay_indx + 1;
net_descr{lay_indx} = caffe_layer_data_def( 'hdf5', 0); %Validation
net_descr{lay_indx}.hdf5_data_param.batch_size = 153;
% --- Conv 0
lay_indx = lay_indx + 1;
block_indx = 0;
net_descr{lay_indx} = caffe_layer_conv_def( block_indx );
net_descr{lay_indx}.bottom = 'data';
net_descr{lay_indx}.convolution_param.num_output = 64;
net_descr{lay_indx}.convolution_param.kernel_h = 1;
net_descr{lay_indx}.convolution_param.kernel_w = 2;
net_descr{lay_indx}.convolution_param.stride_h = 1;
net_descr{lay_indx}.convolution_param.stride_w = 1;
lay_indx = lay_indx + 1;
net_descr{lay_indx} = caffe_layer_relu_def( block_indx, net_descr{lay_indx-1}.name );
lay_indx = lay_indx + 1;
net_descr{lay_indx} = caffe_layer_pool_def( block_indx );
net_descr{lay_indx}.pooling_param.kernel_h = 1;
net_descr{lay_indx}.pooling_param.kernel_w = 2;
net_descr{lay_indx}.pooling_param.stride_h = 1;
net_descr{lay_indx}.pooling_param.stride_w = 2;
% --- Conv 1
lay_indx = lay_indx + 1;
block_indx = block_indx + 1;
net_descr{lay_indx} = caffe_layer_conv_def( block_indx );
net_descr{lay_indx}.bottom = sprintf('pool%d', block_indx - 1);
net_descr{lay_indx}.convolution_param.num_output = 128;
net_descr{lay_indx}.convolution_param.kernel_h = 1;
net_descr{lay_indx}.convolution_param.kernel_w = 2;
net_descr{lay_indx}.convolution_param.stride_h = 1;
net_descr{lay_indx}.convolution_param.stride_w = 1;
lay_indx = lay_indx + 1;
net_descr{lay_indx} = caffe_layer_relu_def( block_indx, net_descr{lay_indx-1}.name );
lay_indx = lay_indx + 1;
net_descr{lay_indx} = caffe_layer_pool_def( block_indx );lay_indx = lay_indx + 1;
net_descr{lay_indx} = caffe_layer_relu_def( block_indx, net_descr{lay_indx-1}.name );
lay_indx = lay_indx + 1;
net_descr{lay_indx} = caffe_layer_drop_def( block_indx );
net_descr{lay_indx}.pooling_param.kernel_h = 1;
net_descr{lay_indx}.pooling_param.kernel_w = 2;
net_descr{lay_indx}.pooling_param.stride_h = 1;
net_descr{lay_indx}.pooling_param.stride_w = 2;
% --- Conv 2
lay_indx = lay_indx + 1;
block_indx = block_indx + 1;
net_descr{lay_indx} = caffe_layer_conv_def( block_indx );
net_descr{lay_indx}.bottom = sprintf('pool%d', block_indx - 1);
net_descr{lay_indx}.convolution_param.num_output = 128;
net_descr{lay_indx}.convolution_param.kernel_h = 1;
net_descr{lay_indx}.convolution_param.kernel_w = 2;
net_descr{lay_indx}.convolution_param.stride_h = 1;
net_descr{lay_indx}.convolution_param.stride_w = 1;
lay_indx = lay_indx + 1;
net_descr{lay_indx} = caffe_layer_relu_def( block_indx, net_descr{lay_indx-1}.name );
lay_indx = lay_indx + 1;
net_descr{lay_indx} = caffe_layer_pool_def( block_indx );
net_descr{lay_indx}.pooling_param.kernel_h = 1;
net_descr{lay_indx}.pooling_param.kernel_w = 2;
net_descr{lay_indx}.pooling_param.stride_h = 1;
net_descr{lay_indx}.pooling_param.stride_w = 2;
% --- Conv 3
lay_indx = lay_indx + 1;
block_indx = block_indx + 1;
net_descr{lay_indx} = caffe_layer_conv_def( block_indx );
net_descr{lay_indx}.bottom = sprintf('pool%d', block_indx - 1);
net_descr{lay_indx}.convolution_param.num_output = 128;
net_descr{lay_indx}.convolution_param.kernel_h = 57;
net_descr{lay_indx}.convolution_param.kernel_w = 1;
net_descr{lay_indx}.convolution_param.stride_h = 1;
net_descr{lay_indx}.convolution_param.stride_w = 1;
lay_indx = lay_indx + 1;
net_descr{lay_indx} = caffe_layer_relu_def( block_indx, net_descr{lay_indx-1}.name );
% --- FC 4
lay_indx = lay_indx + 1;
block_indx = block_indx + 1;
net_descr{lay_indx} = caffe_layer_fc_def( block_indx );
net_descr{lay_indx}.bottom = sprintf('conv%d', block_indx - 1);
net_descr{lay_indx}.inner_product_param.num_output = 256;
lay_indx = lay_indx + 1;
net_descr{lay_indx} = caffe_layer_relu_def( block_indx, net_descr{lay_indx-1}.name );
lay_indx = lay_indx + 1;
net_descr{lay_indx} = caffe_layer_drop_def( block_indx );
% --- FC 5
lay_indx = lay_indx + 1;
block_indx = block_indx + 1;
net_descr{lay_indx} = caffe_layer_fc_def( block_indx );
net_descr{lay_indx}.bottom = sprintf('fc%d', block_indx - 1);
net_descr{lay_indx}.inner_product_param.num_output = 256;
% --- Accuracy & Loss
lay_indx = lay_indx + 1;
net_descr{lay_indx} = caffe_layer_accuracy_def( net_descr{lay_indx - 1}.top );
lay_indx = lay_indx + 1;
net_descr{lay_indx} = caffe_layer_loss_def( net_descr{lay_indx - 2}.top );
%% Saving the whole thing
caffe_save_net( net_filename, net_header, net_descr );