3D卷积动作识别

Posted by TheMatrix on 2019-09-01

3D卷积动作识别已经越来越受到关注,参考

resnet50-3d动作识别

本文使用resnet50-3d作为网络标准,流程如下:

Create the Layer Graph

Create the layer graph variable to contain the network’s layers.

1
lgraph = layerGraph();

**Add the Layer Branches
Add the branches of the network to the layer graph. Each branch is a linear array of layers.

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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
tempLayers = [
image3dInputLayer([320 320 16 3],"Name","image3dinput")
convolution3dLayer([7 7 3],64,"Name","conv3d_1_1","Padding","same","Stride",[2 2 2])
batchNormalizationLayer("Name","batchnorm_2")
reluLayer("Name","relu_1")
maxPooling3dLayer([3 3 3],"Name","maxpool3d_1")];
lgraph = addLayers(lgraph,tempLayers);

tempLayers = [
convolution3dLayer([1 1 1],256,"Name","conv3d_1_3")
batchNormalizationLayer("Name","batchnorm_4")];
lgraph = addLayers(lgraph,tempLayers);

tempLayers = [
convolution3dLayer([1 1 1],64,"Name","conv3d_2")
batchNormalizationLayer("Name","batchnorm_1")
reluLayer("Name","relu_2")
convolution3dLayer([3 3 3],64,"Name","conv3d_1_2","Padding","same")
batchNormalizationLayer("Name","batchnorm_3")
reluLayer("Name","relu_3")
convolution3dLayer([1 1 1],256,"Name","conv3d_1_4")
batchNormalizationLayer("Name","batchnorm_5")];
lgraph = addLayers(lgraph,tempLayers);

tempLayers = [
additionLayer(2,"Name","addition_1")
reluLayer("Name","relu_4")];
lgraph = addLayers(lgraph,tempLayers);

tempLayers = [
convolution3dLayer([1 1 1],64,"Name","conv3d_1_5")
batchNormalizationLayer("Name","batchnorm_6")
reluLayer("Name","relu_5")
convolution3dLayer([3 3 3],64,"Name","conv3d_1_6","Padding","same")
batchNormalizationLayer("Name","batchnorm_7")
reluLayer("Name","relu_6")
convolution3dLayer([1 1 1],256,"Name","conv3d_1_7","Padding","same")
batchNormalizationLayer("Name","batchnorm_8")];
lgraph = addLayers(lgraph,tempLayers);

tempLayers = [
additionLayer(2,"Name","addition_2")
reluLayer("Name","relu_7")];
lgraph = addLayers(lgraph,tempLayers);

tempLayers = [
convolution3dLayer([1 1 1],64,"Name","conv3d_1_8")
batchNormalizationLayer("Name","batchnorm_9")
reluLayer("Name","relu_8")
convolution3dLayer([3 3 3],64,"Name","conv3d_1_9","Padding","same")
batchNormalizationLayer("Name","batchnorm_10")
reluLayer("Name","relu_9")
convolution3dLayer([1 1 1],256,"Name","conv3d_1_10")
batchNormalizationLayer("Name","batchnorm_11")];
lgraph = addLayers(lgraph,tempLayers);

tempLayers = [
additionLayer(2,"Name","addition_3")
reluLayer("Name","relu_10")];
lgraph = addLayers(lgraph,tempLayers);

tempLayers = [
convolution3dLayer([1 1 1],512,"Name","conv3d_1_14","Stride",[2 2 1])
batchNormalizationLayer("Name","batchnorm_15")];
lgraph = addLayers(lgraph,tempLayers);

tempLayers = [
convolution3dLayer([1 1 1],128,"Name","conv3d_1_11","Stride",[2 2 1])
batchNormalizationLayer("Name","batchnorm_12")
reluLayer("Name","relu_11")
convolution3dLayer([3 3 3],128,"Name","conv3d_1_12","Padding","same")
batchNormalizationLayer("Name","batchnorm_13")
reluLayer("Name","relu_12")
convolution3dLayer([1 1 1],512,"Name","conv3d_1_13")
batchNormalizationLayer("Name","batchnorm_14")];
lgraph = addLayers(lgraph,tempLayers);

tempLayers = [
additionLayer(2,"Name","addition_4")
reluLayer("Name","activation_13_relu_2")];
lgraph = addLayers(lgraph,tempLayers);

tempLayers = [
convolution3dLayer([1 1 1],128,"Name","conv3d_1_15")
batchNormalizationLayer("Name","batchnorm_16")
reluLayer("Name","relu_13")
convolution3dLayer([3 3 3],128,"Name","conv3d_1_16","Padding","same")
batchNormalizationLayer("Name","batchnorm_17")
reluLayer("Name","relu_14")
convolution3dLayer([1 1 1],512,"Name","conv3d_1_17")
batchNormalizationLayer("Name","batchnorm_18")];
lgraph = addLayers(lgraph,tempLayers);

tempLayers = [
additionLayer(2,"Name","addition_5")
reluLayer("Name","relu_15")];
lgraph = addLayers(lgraph,tempLayers);

tempLayers = [
convolution3dLayer([1 1 1],128,"Name","conv3d_1_18")
batchNormalizationLayer("Name","batchnorm_19")
reluLayer("Name","relu_16")
convolution3dLayer([3 3 3],128,"Name","conv3d_1_19","Padding","same")
batchNormalizationLayer("Name","batchnorm_20")
reluLayer("Name","relu_17")
convolution3dLayer([1 1 1],512,"Name","conv3d_1_20")
batchNormalizationLayer("Name","batchnorm_21")];
lgraph = addLayers(lgraph,tempLayers);

tempLayers = [
additionLayer(2,"Name","addition_6")
reluLayer("Name","relu_18")];
lgraph = addLayers(lgraph,tempLayers);

tempLayers = [
convolution3dLayer([1 1 1],128,"Name","conv3d_1_21")
batchNormalizationLayer("Name","batchnorm_22")
reluLayer("Name","relu_19")
convolution3dLayer([3 3 3],128,"Name","conv3d_1_22","Padding","same")
batchNormalizationLayer("Name","batchnorm_23")
reluLayer("Name","relu_20")
convolution3dLayer([1 1 1],512,"Name","conv3d_1_23")
batchNormalizationLayer("Name","batchnorm_24")];
lgraph = addLayers(lgraph,tempLayers);

tempLayers = [
additionLayer(2,"Name","addition_7")
reluLayer("Name","relu_21")];
lgraph = addLayers(lgraph,tempLayers);

tempLayers = [
convolution3dLayer([1 1 1],1024,"Name","conv3d_1_27","Stride",[2 2 1])
batchNormalizationLayer("Name","batchnorm_28")];
lgraph = addLayers(lgraph,tempLayers);

tempLayers = [
convolution3dLayer([1 1 1],256,"Name","conv3d_1_24","Stride",[2 2 1])
batchNormalizationLayer("Name","batchnorm_25")
reluLayer("Name","relu_22")
convolution3dLayer([3 3 3],256,"Name","conv3d_1_25","Padding","same")
batchNormalizationLayer("Name","batchnorm_26")
reluLayer("Name","relu_23")
convolution3dLayer([1 1 1],1024,"Name","conv3d_1_26")
batchNormalizationLayer("Name","batchnorm_27")];
lgraph = addLayers(lgraph,tempLayers);

tempLayers = [
additionLayer(2,"Name","addition_8")
reluLayer("Name","relu_24")];
lgraph = addLayers(lgraph,tempLayers);

tempLayers = [
convolution3dLayer([1 1 1],256,"Name","conv3d_1_28")
batchNormalizationLayer("Name","batchnorm_29")
reluLayer("Name","relu_25")
convolution3dLayer([3 3 3],256,"Name","conv3d_1_29","Padding","same")
batchNormalizationLayer("Name","batchnorm_30")
reluLayer("Name","relu_26")
convolution3dLayer([1 1 1],1024,"Name","conv3d_1_30")
batchNormalizationLayer("Name","batchnorm_31")];
lgraph = addLayers(lgraph,tempLayers);

tempLayers = [
additionLayer(2,"Name","addition_9")
reluLayer("Name","relu_27")];
lgraph = addLayers(lgraph,tempLayers);

tempLayers = [
convolution3dLayer([1 1 1],256,"Name","conv3d_1_31")
batchNormalizationLayer("Name","batchnorm_32")
reluLayer("Name","relu_28")
convolution3dLayer([3 3 3],256,"Name","conv3d_1_32","Padding","same")
batchNormalizationLayer("Name","batchnorm_33")
reluLayer("Name","relu_29")
convolution3dLayer([1 1 1],1024,"Name","conv3d_1_33")
batchNormalizationLayer("Name","batchnorm_34")];
lgraph = addLayers(lgraph,tempLayers);

tempLayers = [
additionLayer(2,"Name","addition_10")
reluLayer("Name","relu_30")];
lgraph = addLayers(lgraph,tempLayers);

tempLayers = [
convolution3dLayer([1 1 1],256,"Name","conv3d_1_34")
batchNormalizationLayer("Name","batchnorm_35")
reluLayer("Name","relu_31")
convolution3dLayer([3 3 3],256,"Name","conv3d_1_35","Padding","same")
batchNormalizationLayer("Name","batchnorm_36")
reluLayer("Name","relu_32")
convolution3dLayer([1 1 1],1024,"Name","conv3d_1_36")
batchNormalizationLayer("Name","batchnorm_37")];
lgraph = addLayers(lgraph,tempLayers);

tempLayers = [
additionLayer(2,"Name","addition_11")
reluLayer("Name","relu_33")];
lgraph = addLayers(lgraph,tempLayers);

tempLayers = [
convolution3dLayer([1 1 1],256,"Name","conv3d_1_37")
batchNormalizationLayer("Name","batchnorm_38")
reluLayer("Name","relu_34")
convolution3dLayer([3 3 3],256,"Name","conv3d_1_38","Padding","same")
batchNormalizationLayer("Name","batchnorm_39")
reluLayer("Name","relu_35")
convolution3dLayer([1 1 1],1024,"Name","conv3d_1_39")
batchNormalizationLayer("Name","batchnorm_40")];
lgraph = addLayers(lgraph,tempLayers);

tempLayers = [
additionLayer(2,"Name","addition_12")
reluLayer("Name","relu_36")];
lgraph = addLayers(lgraph,tempLayers);

tempLayers = [
convolution3dLayer([1 1 1],256,"Name","conv3d_1_40")
batchNormalizationLayer("Name","batchnorm_41")
reluLayer("Name","relu_37")
convolution3dLayer([3 3 3],256,"Name","conv3d_1_41","Padding","same")
batchNormalizationLayer("Name","batchnorm_42")
reluLayer("Name","relu_38")
convolution3dLayer([1 1 1],1024,"Name","conv3d_1_42")
batchNormalizationLayer("Name","batchnorm_43")];
lgraph = addLayers(lgraph,tempLayers);

tempLayers = [
additionLayer(2,"Name","addition_13")
reluLayer("Name","relu_39")];
lgraph = addLayers(lgraph,tempLayers);

tempLayers = [
convolution3dLayer([1 1 1],512,"Name","conv3d_1_43","Stride",[2 2 1])
batchNormalizationLayer("Name","batchnorm_44")
reluLayer("Name","relu_40")
convolution3dLayer([3 3 3],512,"Name","conv3d_1_44","Padding","same")
batchNormalizationLayer("Name","batchnorm_45")
reluLayer("Name","relu_41")
convolution3dLayer([1 1 1],2048,"Name","conv3d_1_45")
batchNormalizationLayer("Name","batchnorm_46")];
lgraph = addLayers(lgraph,tempLayers);

tempLayers = [
convolution3dLayer([1 1 1],2048,"Name","conv3d_1_46","Stride",[2 2 1])
batchNormalizationLayer("Name","batchnorm_47")];
lgraph = addLayers(lgraph,tempLayers);

tempLayers = [
additionLayer(2,"Name","addition_14")
reluLayer("Name","relu_42")];
lgraph = addLayers(lgraph,tempLayers);

tempLayers = [
convolution3dLayer([1 1 1],512,"Name","conv3d_1_47")
batchNormalizationLayer("Name","batchnorm_48")
reluLayer("Name","relu_43")
convolution3dLayer([3 3 3],512,"Name","conv3d_1_48","Padding","same")
batchNormalizationLayer("Name","batchnorm_49")
reluLayer("Name","relu_44")
convolution3dLayer([1 1 1],2048,"Name","conv3d_1_49")
batchNormalizationLayer("Name","batchnorm_50")];
lgraph = addLayers(lgraph,tempLayers);

tempLayers = [
additionLayer(2,"Name","addition_15")
reluLayer("Name","relu_45")];
lgraph = addLayers(lgraph,tempLayers);

tempLayers = [
convolution3dLayer([1 1 1],512,"Name","conv3d_1_50")
batchNormalizationLayer("Name","batchnorm_51")
reluLayer("Name","relu_46")
convolution3dLayer([3 3 3],512,"Name","conv3d_1_51","Padding","same")
batchNormalizationLayer("Name","batchnorm_52")
reluLayer("Name","relu_47")
convolution3dLayer([1 1 1],2048,"Name","conv3d_1_52")
batchNormalizationLayer("Name","batchnorm_53")];
lgraph = addLayers(lgraph,tempLayers);

tempLayers = [
additionLayer(2,"Name","addition_16")
reluLayer("Name","relu_48")
averagePooling3dLayer([20 20 6],"Name","avgpool3d","Stride",[20 20 6])
fullyConnectedLayer(7,"Name","fc")
softmaxLayer("Name","softmax")
classificationLayer("Name","classoutput")];
lgraph = addLayers(lgraph,tempLayers);

Connect the Layer Branches

Connect all the branches of the network to create the network’s graph.

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
lgraph = connectLayers(lgraph,"maxpool3d_1","conv3d_1_3");
lgraph = connectLayers(lgraph,"maxpool3d_1","conv3d_2");
lgraph = connectLayers(lgraph,"batchnorm_4","addition_1/in1");
lgraph = connectLayers(lgraph,"batchnorm_5","addition_1/in2");
lgraph = connectLayers(lgraph,"relu_4","conv3d_1_5");
lgraph = connectLayers(lgraph,"relu_4","addition_2/in1");
lgraph = connectLayers(lgraph,"batchnorm_8","addition_2/in2");
lgraph = connectLayers(lgraph,"relu_7","conv3d_1_8");
lgraph = connectLayers(lgraph,"relu_7","addition_3/in1");
lgraph = connectLayers(lgraph,"batchnorm_11","addition_3/in2");
lgraph = connectLayers(lgraph,"relu_10","conv3d_1_14");
lgraph = connectLayers(lgraph,"relu_10","conv3d_1_11");
lgraph = connectLayers(lgraph,"batchnorm_15","addition_4/in2");
lgraph = connectLayers(lgraph,"batchnorm_14","addition_4/in1");
lgraph = connectLayers(lgraph,"activation_13_relu_2","conv3d_1_15");
lgraph = connectLayers(lgraph,"activation_13_relu_2","addition_5/in2");
lgraph = connectLayers(lgraph,"batchnorm_18","addition_5/in1");
lgraph = connectLayers(lgraph,"relu_15","conv3d_1_18");
lgraph = connectLayers(lgraph,"relu_15","addition_6/in1");
lgraph = connectLayers(lgraph,"batchnorm_21","addition_6/in2");
lgraph = connectLayers(lgraph,"relu_18","conv3d_1_21");
lgraph = connectLayers(lgraph,"relu_18","addition_7/in2");
lgraph = connectLayers(lgraph,"batchnorm_24","addition_7/in1");
lgraph = connectLayers(lgraph,"relu_21","conv3d_1_27");
lgraph = connectLayers(lgraph,"relu_21","conv3d_1_24");
lgraph = connectLayers(lgraph,"batchnorm_28","addition_8/in2");
lgraph = connectLayers(lgraph,"batchnorm_27","addition_8/in1");
lgraph = connectLayers(lgraph,"relu_24","conv3d_1_28");
lgraph = connectLayers(lgraph,"relu_24","addition_9/in1");
lgraph = connectLayers(lgraph,"batchnorm_31","addition_9/in2");
lgraph = connectLayers(lgraph,"relu_27","conv3d_1_31");
lgraph = connectLayers(lgraph,"relu_27","addition_10/in1");
lgraph = connectLayers(lgraph,"batchnorm_34","addition_10/in2");
lgraph = connectLayers(lgraph,"relu_30","conv3d_1_34");
lgraph = connectLayers(lgraph,"relu_30","addition_11/in1");
lgraph = connectLayers(lgraph,"batchnorm_37","addition_11/in2");
lgraph = connectLayers(lgraph,"relu_33","conv3d_1_37");
lgraph = connectLayers(lgraph,"relu_33","addition_12/in1");
lgraph = connectLayers(lgraph,"batchnorm_40","addition_12/in2");
lgraph = connectLayers(lgraph,"relu_36","conv3d_1_40");
lgraph = connectLayers(lgraph,"relu_36","addition_13/in1");
lgraph = connectLayers(lgraph,"batchnorm_43","addition_13/in2");
lgraph = connectLayers(lgraph,"relu_39","conv3d_1_43");
lgraph = connectLayers(lgraph,"relu_39","conv3d_1_46");
lgraph = connectLayers(lgraph,"batchnorm_47","addition_14/in2");
lgraph = connectLayers(lgraph,"batchnorm_46","addition_14/in1");
lgraph = connectLayers(lgraph,"relu_42","conv3d_1_47");
lgraph = connectLayers(lgraph,"relu_42","addition_15/in1");
lgraph = connectLayers(lgraph,"batchnorm_50","addition_15/in2");
lgraph = connectLayers(lgraph,"relu_45","conv3d_1_50");
lgraph = connectLayers(lgraph,"relu_45","addition_16/in2");
lgraph = connectLayers(lgraph,"batchnorm_53","addition_16/in1");

Clean Up Helper Variable

clear tempLayers;

1
plot(lgraph);