微调网络,通常我们有一个初始化的模型参数文件,这里是不同于training from scratch,scrachtch指的是我们训练一个新的网络,在训练过程中,这些参数都被随机初始化,而fine-tuning,是我们可以在ImageNet上1000类分类训练好的参数的基础上,根据我们的分类识别任务进行特定的微调
这里我以一个车的识别为例,假设我们有1种车需要识别,我的任务对象是车,现在有ImageNet的模型参数文件,在这里使用的网络模型是CaffeNet,是一个小型的网络,其实别的网络如GoogleNet也是一样的原理。那么这个任务的变化可以表示为:
任务:分类 类别数目:1000(ImageNet上1000类的分类任务)——> 1(自己的特定数据集的分类任务车)
那么在网络的微调中,我们的整个流程分为以下几步:
1
2
3
4
5
6
7 11. 依然是准备好我们的训练数据和测试数据
22. 计算数据集的均值文件,因为集中特定领域的图像均值文件会跟ImageNet上比较General的数据的均值不太一样
33. 修改网络最后一层的输出类别,并且需要加快最后一层的参数学习速率
44. 调整Solver的配置参数,通常学习速率和步长,迭代次数都要适当减少
55. 启动训练,并且需要加载pretrained模型的参数
6
7
1.准备数据集
这一点就不用说了,准备两个txt文件,放成list的形式,可以参考caffe下的example,图像路径之后一个空格之后跟着类别的ID,如下,这里记住ID必须从0开始,要连续,否则会出错,loss不下降,按照要求写就OK。
这个是训练的图像label,测试的也同理
1
2
3 11. 创建lmdb文件,使用caffe下的convert_imageset 工具,具体命令如下:
2
3
1
2
3 1./build/tools/convert_imageset /media/***/801328a5-39c6-4e08-b070-19fc662a5236/resnet/caffe/data/cartest/ data/cartest/carlist.txt data/cartest/train_car_lmdb -resize_width=227 -resize_height=227 -check_size -shuffle true
2
3
其中第一个参数是基地址路径用来拼接的,第二个是label的文件,第三个是生成的数据库文件支持leveldb或者lmdb,接着是resize的大小,最后是否随机图片顺序
计算均值,使用caffe下的convert_imageset 工具,具体命令
1
2
3 1./build/tools/compute_image_mean /media/***/801328a5-39c6-4e08-b070-19fc662a5236/resnet/caffe/data/cartest/train_car_lmdb/ data/carmean.binaryproto
2
3
第一个参数是基地址路径用来拼接的,第二个是lmdb文件,第三个是生成的均值文件carmean.binaryproto
3.调整网络层参数
参照Caffe上的例程,我用的是CaffeNet,首先在输入层data层,修改我们的source 和 meanfile, 根据之前生成的lmdb 和mean.binaryproto修改即可。
最后输出层是fc8,
1.首先修改名字,这样预训练模型赋值的时候这里就会因为名字不匹配从而重新训练,也就达成了我们适应新任务的目的。
2.调整学习速率,因为最后一层是重新学习,因此需要有更快的学习速率相比较其他层,因此我们将,weight和bias的学习速率加快10倍。
修改./models/bvlc_reference_caffenet/train_cal_resnet_lily.prototxt中 train和test对应的相关路径
1
2
3
4 1mean_file: "/media/***/801328a5-39c6-4e08-b070-19fc662a5236/resnet/caffe/data/cartest/carmean.binaryproto
2source: "/media/***/801328a5-39c6-4e08-b070-19fc662a5236/resnet/caffe/data/cartest/train_car_lmdb"
3
4
修改./models/bvlc_reference_caffenet/solver_resnet_lily.prototxt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 1net: "models/bvlc_reference_caffenet/train_val_resnet_lily.prototxt"
2test_iter: 100
3test_interval: 1000
4base_lr: 0.001
5lr_policy: "step"
6gamma: 0.1
7stepsize: 20000
8display: 20
9max_iter: 50000
10momentum: 0.9
11weight_decay: 0.0005
12snapshot: 10000
13snapshot_prefix: "models/bvlc_reference_caffenet/caffenet_resnet_model_lily"
14solver_mode: GPU
15
16
原来是fc8,记得把跟fc8连接的名字都要修改掉,修改修改./models/bvlc_reference_caffenet/train_val_resnet_lily.prototxt 后如下
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 1layer {
2 name: "fc8_comp_model"
3 type: "InnerProduct"
4 bottom: "fc7"
5 top: "fc8_comp_model"
6 param {
7 lr_mult: 1
8 decay_mult: 1
9 }
10 param {
11 lr_mult: 2
12 decay_mult: 0
13 }
14 inner_product_param {
15 num_output: 1000
16 weight_filler {
17 type: "gaussian"
18 std: 0.01
19 }
20 bias_filler {
21 type: "constant"
22 value: 0
23 }
24 }
25}
26layer {
27 name: "accuracy"
28 type: "Accuracy"
29 bottom: "fc8_comp_model"
30 bottom: "label"
31 top: "accuracy"
32 include {
33 phase: TEST
34 }
35}
36layer {
37 name: "loss"
38 type: "SoftmaxWithLoss"
39 bottom: "fc8_comp_model"
40 bottom: "label"
41 top: "loss"
42}
43
44
主要的调整有:test_iter从1000改为了100,因为数据量减少了,base_lr从0.01变成了0.001,这个很重要,微调时的基本学习速率不能太大,学习策略没有改变,步长从原来的100000变成了20000,最大的迭代次数也从450000变成了50000,动量和权重衰减项都没有修改,依然是GPU模型,网络模型文件和快照的路径根据自己修改
train_val_resnet_lily.prototxt完整文件为:
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
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406 1name: "CaffeNet"
2layer {
3 name: "data"
4 type: "Data"
5 top: "data"
6 top: "label"
7 include {
8 phase: TRAIN
9 }
10 transform_param {
11 mirror: true
12 crop_size: 227
13 mean_file: "/media/***/801328a5-39c6-4e08-b070-19fc662a5236/resnet/caffe/data/cartest/carmean.binaryproto"
14 }
15# mean pixel / channel-wise mean instead of mean image
16# transform_param {
17# crop_size: 227
18# mean_value: 104
19# mean_value: 117
20# mean_value: 123
21# mirror: true
22# }
23 data_param {
24 source: "/media/***/801328a5-39c6-4e08-b070-19fc662a5236/resnet/caffe/data/cartest/train_car_lmdb"
25 batch_size: 256
26 backend: LMDB
27 }
28}
29layer {
30 name: "data"
31 type: "Data"
32 top: "data"
33 top: "label"
34 include {
35 phase: TEST
36 }
37 transform_param {
38 mirror: false
39 crop_size: 227
40 mean_file: "/media/***/801328a5-39c6-4e08-b070-19fc662a5236/resnet/caffe/data/cartest/carmean.binaryproto"
41 }
42# mean pixel / channel-wise mean instead of mean image
43# transform_param {
44# crop_size: 227
45# mean_value: 104
46# mean_value: 117
47# mean_value: 123
48# mirror: false
49# }
50 data_param {
51 source: "/media/***/801328a5-39c6-4e08-b070-19fc662a5236/resnet/caffe/data/cartest/train_car_lmdb"
52 batch_size: 50
53 backend: LMDB
54 }
55}
56layer {
57 name: "conv1"
58 type: "Convolution"
59 bottom: "data"
60 top: "conv1"
61 param {
62 lr_mult: 1
63 decay_mult: 1
64 }
65 param {
66 lr_mult: 2
67 decay_mult: 0
68 }
69 convolution_param {
70 num_output: 96
71 kernel_size: 11
72 stride: 4
73 weight_filler {
74 type: "gaussian"
75 std: 0.01
76 }
77 bias_filler {
78 type: "constant"
79 value: 0
80 }
81 }
82}
83layer {
84 name: "relu1"
85 type: "ReLU"
86 bottom: "conv1"
87 top: "conv1"
88}
89layer {
90 name: "pool1"
91 type: "Pooling"
92 bottom: "conv1"
93 top: "pool1"
94 pooling_param {
95 pool: MAX
96 kernel_size: 3
97 stride: 2
98 }
99}
100layer {
101 name: "norm1"
102 type: "LRN"
103 bottom: "pool1"
104 top: "norm1"
105 lrn_param {
106 local_size: 5
107 alpha: 0.0001
108 beta: 0.75
109 }
110}
111layer {
112 name: "conv2"
113 type: "Convolution"
114 bottom: "norm1"
115 top: "conv2"
116 param {
117 lr_mult: 1
118 decay_mult: 1
119 }
120 param {
121 lr_mult: 2
122 decay_mult: 0
123 }
124 convolution_param {
125 num_output: 256
126 pad: 2
127 kernel_size: 5
128 group: 2
129 weight_filler {
130 type: "gaussian"
131 std: 0.01
132 }
133 bias_filler {
134 type: "constant"
135 value: 1
136 }
137 }
138}
139layer {
140 name: "relu2"
141 type: "ReLU"
142 bottom: "conv2"
143 top: "conv2"
144}
145layer {
146 name: "pool2"
147 type: "Pooling"
148 bottom: "conv2"
149 top: "pool2"
150 pooling_param {
151 pool: MAX
152 kernel_size: 3
153 stride: 2
154 }
155}
156layer {
157 name: "norm2"
158 type: "LRN"
159 bottom: "pool2"
160 top: "norm2"
161 lrn_param {
162 local_size: 5
163 alpha: 0.0001
164 beta: 0.75
165 }
166}
167layer {
168 name: "conv3"
169 type: "Convolution"
170 bottom: "norm2"
171 top: "conv3"
172 param {
173 lr_mult: 1
174 decay_mult: 1
175 }
176 param {
177 lr_mult: 2
178 decay_mult: 0
179 }
180 convolution_param {
181 num_output: 384
182 pad: 1
183 kernel_size: 3
184 weight_filler {
185 type: "gaussian"
186 std: 0.01
187 }
188 bias_filler {
189 type: "constant"
190 value: 0
191 }
192 }
193}
194layer {
195 name: "relu3"
196 type: "ReLU"
197 bottom: "conv3"
198 top: "conv3"
199}
200layer {
201 name: "conv4"
202 type: "Convolution"
203 bottom: "conv3"
204 top: "conv4"
205 param {
206 lr_mult: 1
207 decay_mult: 1
208 }
209 param {
210 lr_mult: 2
211 decay_mult: 0
212 }
213 convolution_param {
214 num_output: 384
215 pad: 1
216 kernel_size: 3
217 group: 2
218 weight_filler {
219 type: "gaussian"
220 std: 0.01
221 }
222 bias_filler {
223 type: "constant"
224 value: 1
225 }
226 }
227}
228layer {
229 name: "relu4"
230 type: "ReLU"
231 bottom: "conv4"
232 top: "conv4"
233}
234layer {
235 name: "conv5"
236 type: "Convolution"
237 bottom: "conv4"
238 top: "conv5"
239 param {
240 lr_mult: 1
241 decay_mult: 1
242 }
243 param {
244 lr_mult: 2
245 decay_mult: 0
246 }
247 convolution_param {
248 num_output: 256
249 pad: 1
250 kernel_size: 3
251 group: 2
252 weight_filler {
253 type: "gaussian"
254 std: 0.01
255 }
256 bias_filler {
257 type: "constant"
258 value: 1
259 }
260 }
261}
262layer {
263 name: "relu5"
264 type: "ReLU"
265 bottom: "conv5"
266 top: "conv5"
267}
268layer {
269 name: "pool5"
270 type: "Pooling"
271 bottom: "conv5"
272 top: "pool5"
273 pooling_param {
274 pool: MAX
275 kernel_size: 3
276 stride: 2
277 }
278}
279layer {
280 name: "fc6"
281 type: "InnerProduct"
282 bottom: "pool5"
283 top: "fc6"
284 param {
285 lr_mult: 1
286 decay_mult: 1
287 }
288 param {
289 lr_mult: 2
290 decay_mult: 0
291 }
292 inner_product_param {
293 num_output: 4096
294 weight_filler {
295 type: "gaussian"
296 std: 0.005
297 }
298 bias_filler {
299 type: "constant"
300 value: 1
301 }
302 }
303}
304layer {
305 name: "relu6"
306 type: "ReLU"
307 bottom: "fc6"
308 top: "fc6"
309}
310layer {
311 name: "drop6"
312 type: "Dropout"
313 bottom: "fc6"
314 top: "fc6"
315 dropout_param {
316 dropout_ratio: 0.5
317 }
318}
319layer {
320 name: "fc7"
321 type: "InnerProduct"
322 bottom: "fc6"
323 top: "fc7"
324 param {
325 lr_mult: 1
326 decay_mult: 1
327 }
328 param {
329 lr_mult: 2
330 decay_mult: 0
331 }
332 inner_product_param {
333 num_output: 4096
334 weight_filler {
335 type: "gaussian"
336 std: 0.005
337 }
338 bias_filler {
339 type: "constant"
340 value: 1
341 }
342 }
343}
344layer {
345 name: "relu7"
346 type: "ReLU"
347 bottom: "fc7"
348 top: "fc7"
349}
350layer {
351 name: "drop7"
352 type: "Dropout"
353 bottom: "fc7"
354 top: "fc7"
355 dropout_param {
356 dropout_ratio: 0.5
357 }
358}
359layer {
360 name: "fc8_comp_model"
361 type: "InnerProduct"
362 bottom: "fc7"
363 top: "fc8_comp_model"
364 param {
365 lr_mult: 1
366 decay_mult: 1
367 }
368 param {
369 lr_mult: 2
370 decay_mult: 0
371 }
372 inner_product_param {
373 num_output: 1000
374 weight_filler {
375 type: "gaussian"
376 std: 0.01
377 }
378 bias_filler {
379 type: "constant"
380 value: 0
381 }
382 }
383}
384layer {
385 name: "accuracy"
386 type: "Accuracy"
387 bottom: "fc8_comp_model"
388 bottom: "label"
389 top: "accuracy"
390 include {
391 phase: TEST
392 }
393}
394layer {
395 name: "loss"
396 type: "SoftmaxWithLoss"
397 bottom: "fc8_comp_model"
398 bottom: "label"
399 top: "loss"
400}
401
402
403训练的指令如下:
404./build/tools/caffe train --solver ./models/bvlc_reference_caffenet/solver_resnet_lily.prototxt --weights ./models/bvlc_reference_caffenet/bvlc_reference_caffenet.caffemodel --gpu 0
405
406
测试指令:
1
2
3 1python ./python/classify02.py --model_def ./models/bvlc_reference_caffenet/train_val_test_resnet_lily.prototxt --pretrained_model ./models/bvlc_reference_caffenet/caffenet_resnet_model_lily_iter_50000.caffemodel --labels_file ./data/cartest/cartest.txt --center_only ./data/cartest/JPEGImages/crk201706301341.jpg foo
2
3
注意这里的train_val_test_resnet_lily.prototxt文件与训练时的文件train_val_resnet_lily.prototxt文件是不一样的。
train_val_resnet_lily.prototxt文件为:
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
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316 1name: "train_resnet_lily"
2
3layer {
4 name: "data"
5 type: "Input"
6 top: "data"
7 input_param { shape: { dim: 1 dim: 3 dim: 227 dim: 227 } }
8}
9
10layer {
11 name: "conv1"
12 type: "Convolution"
13 bottom: "data"
14 top: "conv1"
15 param {
16 lr_mult: 1
17 decay_mult: 1
18 }
19 param {
20 lr_mult: 2
21 decay_mult: 0
22 }
23 convolution_param {
24 num_output: 96
25 kernel_size: 11
26 stride: 4
27 weight_filler {
28 type: "gaussian"
29 std: 0.01
30 }
31 bias_filler {
32 type: "constant"
33 value: 0
34 }
35 }
36}
37layer {
38 name: "relu1"
39 type: "ReLU"
40 bottom: "conv1"
41 top: "conv1"
42}
43layer {
44 name: "pool1"
45 type: "Pooling"
46 bottom: "conv1"
47 top: "pool1"
48 pooling_param {
49 pool: MAX
50 kernel_size: 3
51 stride: 2
52 }
53}
54layer {
55 name: "norm1"
56 type: "LRN"
57 bottom: "pool1"
58 top: "norm1"
59 lrn_param {
60 local_size: 5
61 alpha: 0.0001
62 beta: 0.75
63 }
64}
65layer {
66 name: "conv2"
67 type: "Convolution"
68 bottom: "norm1"
69 top: "conv2"
70 param {
71 lr_mult: 1
72 decay_mult: 1
73 }
74 param {
75 lr_mult: 2
76 decay_mult: 0
77 }
78 convolution_param {
79 num_output: 256
80 pad: 2
81 kernel_size: 5
82 group: 2
83 weight_filler {
84 type: "gaussian"
85 std: 0.01
86 }
87 bias_filler {
88 type: "constant"
89 value: 1
90 }
91 }
92}
93layer {
94 name: "relu2"
95 type: "ReLU"
96 bottom: "conv2"
97 top: "conv2"
98}
99layer {
100 name: "pool2"
101 type: "Pooling"
102 bottom: "conv2"
103 top: "pool2"
104 pooling_param {
105 pool: MAX
106 kernel_size: 3
107 stride: 2
108 }
109}
110layer {
111 name: "norm2"
112 type: "LRN"
113 bottom: "pool2"
114 top: "norm2"
115 lrn_param {
116 local_size: 5
117 alpha: 0.0001
118 beta: 0.75
119 }
120}
121layer {
122 name: "conv3"
123 type: "Convolution"
124 bottom: "norm2"
125 top: "conv3"
126 param {
127 lr_mult: 1
128 decay_mult: 1
129 }
130 param {
131 lr_mult: 2
132 decay_mult: 0
133 }
134 convolution_param {
135 num_output: 384
136 pad: 1
137 kernel_size: 3
138 weight_filler {
139 type: "gaussian"
140 std: 0.01
141 }
142 bias_filler {
143 type: "constant"
144 value: 0
145 }
146 }
147}
148layer {
149 name: "relu3"
150 type: "ReLU"
151 bottom: "conv3"
152 top: "conv3"
153}
154layer {
155 name: "conv4"
156 type: "Convolution"
157 bottom: "conv3"
158 top: "conv4"
159 param {
160 lr_mult: 1
161 decay_mult: 1
162 }
163 param {
164 lr_mult: 2
165 decay_mult: 0
166 }
167 convolution_param {
168 num_output: 384
169 pad: 1
170 kernel_size: 3
171 group: 2
172 }
173}
174layer {
175 name: "relu4"
176 type: "ReLU"
177 bottom: "conv4"
178 top: "conv4"
179}
180layer {
181 name: "conv5"
182 type: "Convolution"
183 bottom: "conv4"
184 top: "conv5"
185 param {
186 lr_mult: 1
187 decay_mult: 1
188 }
189 param {
190 lr_mult: 2
191 decay_mult: 0
192 }
193 convolution_param {
194 num_output: 256
195 pad: 1
196 kernel_size: 3
197 group: 2
198
199 }
200}
201layer {
202 name: "relu5"
203 type: "ReLU"
204 bottom: "conv5"
205 top: "conv5"
206}
207layer {
208 name: "pool5"
209 type: "Pooling"
210 bottom: "conv5"
211 top: "pool5"
212 pooling_param {
213 pool: MAX
214 kernel_size: 3
215 stride: 2
216 }
217}
218layer {
219 name: "fc6"
220 type: "InnerProduct"
221 bottom: "pool5"
222 top: "fc6"
223 param {
224 lr_mult: 1
225 decay_mult: 1
226 }
227 param {
228 lr_mult: 2
229 decay_mult: 0
230 }
231 inner_product_param {
232 num_output: 4096
233 weight_filler {
234 type: "gaussian"
235 std: 0.005
236 }
237 bias_filler {
238 type: "constant"
239 value: 1
240 }
241 }
242}
243layer {
244 name: "relu6"
245 type: "ReLU"
246 bottom: "fc6"
247 top: "fc6"
248}
249layer {
250 name: "drop6"
251 type: "Dropout"
252 bottom: "fc6"
253 top: "fc6"
254 dropout_param {
255 dropout_ratio: 0.5
256 }
257}
258layer {
259 name: "fc7"
260 type: "InnerProduct"
261 bottom: "fc6"
262 top: "fc7"
263 param {
264 lr_mult: 1
265 decay_mult: 1
266 }
267 param {
268 lr_mult: 2
269 decay_mult: 0
270 }
271 inner_product_param {
272 num_output: 4096
273
274 }
275}
276layer {
277 name: "relu7"
278 type: "ReLU"
279 bottom: "fc7"
280 top: "fc7"
281}
282layer {
283 name: "drop7"
284 type: "Dropout"
285 bottom: "fc7"
286 top: "fc7"
287 dropout_param {
288 dropout_ratio: 0.5
289 }
290}
291layer {
292 name: "fc8_comp_model"
293 type: "InnerProduct"
294 bottom: "fc7"
295 top: "fc8_comp_model"
296 param {
297 lr_mult: 1
298 decay_mult: 1
299 }
300 param {
301 lr_mult: 2
302 decay_mult: 0
303 }
304 inner_product_param {
305 num_output: 1000
306
307 }
308}
309layer {
310 name: "prob"
311 type: "Softmax"
312 bottom: "fc8_comp_model"
313 top: "prob"
314}
315
316
报错及解决方案
在最后一步测试的时候运行报错
报错:
1
2
3
4
5
6
7
8
9 1File "python/classify.py", line 138, in <module>
2 main(sys.argv)
3 File "python/classify.py", line 110, in main
4 channel_swap=channel_swap)
5 File "/media/futurus/801328a5-39c6-4e08-b070-19fc662a5236/resnet/caffe/python/caffe/classifier.py", line 29, in __init__
6 in_ = self.inputs[0]
7IndexError: list index out of range
8
9
参考解决方案;
加入:
1
2
3
4
5
6
7
8
9
10 1net: "train_resnet_lily"
2input: "data"
3input_shape {
4 dim: 10
5 dim: 3
6 dim: 224
7 dim: 224
8}
9
10
加入之后 又报了其他错误:
1
2
3
4
5
6 1[libprotobuf ERROR google/protobuf/text_format.cc:274] Error parsing text-format caffe.NetParameter: 1:4: Message type "caffe.NetParameter" has no field named "net".
2F0125 11:48:14.708683 42586 upgrade_proto.cpp:88] Check failed: ReadProtoFromTextFile(param_file, param) Failed to parse NetParameter file: ./models/bvlc_reference_caffenet/train_val_test_resnet_lily.prototxt
3*** Check failure stack trace: ***
4Aborted (core dumped)
5
6
根据网友的博客修改加入为
1
2
3
4
5
6
7
8 1net: "train_resnet_lily"
2input: "data"
3input_dim: 10
4input_dim: 3
5input_dim: 224
6input_dim: 224
7
8
测试还不不行,还是报错。
最终解决方案如下,运行通过。加入
1
2
3
4
5
6
7
8
9 1name: "train_resnet_lily"
2layer {
3 name: "data"
4 type: "Input"
5 top: "data"
6 input_param { shape: { dim: 1 dim: 3 dim: 227 dim: 227 } }
7}
8
9