之前步骤都是在window准备好的,给图片打标签,将xml转txt等,现在在linux训练
执行训练命令:
./darknet detector train cfg/yolov3-mouth.data cfg/yolov3-tiny-mouth.cfg
出现如下错误:不能加载图片和txt文件
wl@ubuntu:/mnt/hgfs/kshare/darknet/darknet-master$ ./darknet detector train cfg/yolov3-mouth.data cfg/yolov3-tiny-mouth.cfg
yolov3-tiny-mouth
batch: Using default '1'
subdivisions: Using default '1'
layer filters size input output
0 conv 16 3 x 3 / 1 416 x 416 x 3 -> 416 x 416 x 16 0.150 BFLOPs
1 max 2 x 2 / 2 416 x 416 x 16 -> 208 x 208 x 16
2 conv 32 3 x 3 / 1 208 x 208 x 16 -> 208 x 208 x 32 0.399 BFLOPs
3 max 2 x 2 / 2 208 x 208 x 32 -> 104 x 104 x 32
4 conv 64 3 x 3 / 1 104 x 104 x 32 -> 104 x 104 x 64 0.399 BFLOPs
5 max 2 x 2 / 2 104 x 104 x 64 -> 52 x 52 x 64
6 conv 128 3 x 3 / 1 52 x 52 x 64 -> 52 x 52 x 128 0.399 BFLOPs
7 max 2 x 2 / 2 52 x 52 x 128 -> 26 x 26 x 128
8 conv 256 3 x 3 / 1 26 x 26 x 128 -> 26 x 26 x 256 0.399 BFLOPs
9 max 2 x 2 / 2 26 x 26 x 256 -> 13 x 13 x 256
10 conv 512 3 x 3 / 1 13 x 13 x 256 -> 13 x 13 x 512 0.399 BFLOPs
11 max 2 x 2 / 1 13 x 13 x 512 -> 13 x 13 x 512
12 conv 1024 3 x 3 / 1 13 x 13 x 512 -> 13 x 13 x1024 1.595 BFLOPs
13 conv 256 1 x 1 / 1 13 x 13 x1024 -> 13 x 13 x 256 0.089 BFLOPs
14 conv 512 3 x 3 / 1 13 x 13 x 256 -> 13 x 13 x 512 0.399 BFLOPs
15 conv 18 1 x 1 / 1 13 x 13 x 512 -> 13 x 13 x 18 0.003 BFLOPs
16 yolo
17 route 13
18 conv 128 1 x 1 / 1 13 x 13 x 256 -> 13 x 13 x 128 0.011 BFLOPs
19 upsample 2x 13 x 13 x 128 -> 26 x 26 x 128
20 route 19 8
21 conv 256 3 x 3 / 1 26 x 26 x 384 -> 26 x 26 x 256 1.196 BFLOPs
22 conv 18 1 x 1 / 1 26 x 26 x 256 -> 26 x 26 x 18 0.006 BFLOPs
23 yolo
Learning Rate: 0.001, Momentum: 0.9, Decay: 0.0005
Resizing
512
"annot load image "/mnt/hgfs/kshare/darknet/darknet-master/data/image/SCUT-FBP-244.jpg
STB Reason: can't fopen
我猜测可能是路径不对,但我用opencv又可以读取路径所在的文件,那有些奇怪了,又来有把图片放到darknet下的data目录下,也一样的出现这问题,搞了两个小时,无语了。
后来github上查找,原来原因是我在window下生成的txt文件,是如下图解释:
原来是在window生成txt文件,换行都是 \r\n 来结束,而linux是\n结束,而我是在window生成的txt,在linux下训练,导致图片路径加载不对,那需要解决把\r\n替换成\n
解决方法: 在linux 下用命令使用"cat -A [Filename]" 查看,如下图所示,看到的为一个Windows形式的换行符,\r对应符号^M,\n对应符号$. 结果如下:
wl@ubuntu:/mnt/hgfs/kshare/darknet/darknet-master$ cat -A data/mouth_train.txt
/mnt/hgfs/kshare/darknet/darknet-master/data/image/SCUT-FBP-170.jpg^M$
/mnt/hgfs/kshare/darknet/darknet-master/data/image/SCUT-FBP-171.jpg^M$
/mnt/hgfs/kshare/darknet/darknet-master/data/image/SCUT-FBP-172.jpg^M$
/mnt/hgfs/kshare/darknet/darknet-master/data/image/SCUT-FBP-173.jpg^M$
/mnt/hgfs/kshare/darknet/darknet-master/data/image/SCUT-FBP-174.jpg^M$
/mnt/hgfs/kshare/darknet/darknet-master/data/image/SCUT-FBP-175.jpg^M$
/mnt/hgfs/kshare/darknet/darknet-master/data/image/SCUT-FBP-176.jpg^M$
/mnt/hgfs/kshare/darknet/darknet-master/data/image/SCUT-FBP-177.jpg^M$
/mnt/hgfs/kshare/darknet/darknet-master/data/image/SCUT-FBP-178.jpg^M$
再使用命令将 \r\n转换成\n, 使用命令如下:
wl@ubuntu:/mnt/hgfs/kshare/darknet/darknet-master$ sed -i 's/\r//g' data/mouth_test.txt
wl@ubuntu:/mnt/hgfs/kshare/darknet/darknet-master$ sed -i 's/\r//g' data/mouth_test.txt
再执行训练命令,终于可以了:
wl@ubuntu:/mnt/hgfs/kshare/darknet/darknet-master$ ./darknet detector train cfg/yolov3-mouth.data cfg/yolov3-tiny-mouth.cfg
yolov3-tiny-mouth
batch: Using default '1'
subdivisions: Using default '1'
layer filters size input output
0 conv 16 3 x 3 / 1 416 x 416 x 3 -> 416 x 416 x 16 0.150 BFLOPs
1 max 2 x 2 / 2 416 x 416 x 16 -> 208 x 208 x 16
2 conv 32 3 x 3 / 1 208 x 208 x 16 -> 208 x 208 x 32 0.399 BFLOPs
3 max 2 x 2 / 2 208 x 208 x 32 -> 104 x 104 x 32
4 conv 64 3 x 3 / 1 104 x 104 x 32 -> 104 x 104 x 64 0.399 BFLOPs
5 max 2 x 2 / 2 104 x 104 x 64 -> 52 x 52 x 64
6 conv 128 3 x 3 / 1 52 x 52 x 64 -> 52 x 52 x 128 0.399 BFLOPs
7 max 2 x 2 / 2 52 x 52 x 128 -> 26 x 26 x 128
8 conv 256 3 x 3 / 1 26 x 26 x 128 -> 26 x 26 x 256 0.399 BFLOPs
9 max 2 x 2 / 2 26 x 26 x 256 -> 13 x 13 x 256
10 conv 512 3 x 3 / 1 13 x 13 x 256 -> 13 x 13 x 512 0.399 BFLOPs
11 max 2 x 2 / 1 13 x 13 x 512 -> 13 x 13 x 512
12 conv 1024 3 x 3 / 1 13 x 13 x 512 -> 13 x 13 x1024 1.595 BFLOPs
13 conv 256 1 x 1 / 1 13 x 13 x1024 -> 13 x 13 x 256 0.089 BFLOPs
14 conv 512 3 x 3 / 1 13 x 13 x 256 -> 13 x 13 x 512 0.399 BFLOPs
15 conv 18 1 x 1 / 1 13 x 13 x 512 -> 13 x 13 x 18 0.003 BFLOPs
16 yolo
17 route 13
18 conv 128 1 x 1 / 1 13 x 13 x 256 -> 13 x 13 x 128 0.011 BFLOPs
19 upsample 2x 13 x 13 x 128 -> 26 x 26 x 128
20 route 19 8
21 conv 256 3 x 3 / 1 26 x 26 x 384 -> 26 x 26 x 256 1.196 BFLOPs
22 conv 18 1 x 1 / 1 26 x 26 x 256 -> 26 x 26 x 18 0.006 BFLOPs
23 yolo
Learning Rate: 0.001, Momentum: 0.9, Decay: 0.0005
Resizing
352
Loaded: 0.099826 seconds
Region 16 Avg IOU: -nan, Class: -nan, Obj: -nan, No Obj: 0.508808, .5R: -nan, .75R: -nan, count: 0
Region 23 Avg IOU: 0.172283, Class: 0.671358, Obj: 0.755280, No Obj: 0.487993, .5R: 0.000000, .75R: 0.000000, count: 1
1: 254.888275, 254.888275 avg, 0.000000 rate, 9.877372 seconds, 1 images
Loaded: 0.000069 seconds
Region 16 Avg IOU: -nan, Class: -nan, Obj: -nan, No Obj: 0.508524, .5R: -nan, .75R: -nan, count: 0
Region 23 Avg IOU: 0.098354, Class: 0.338703, Obj: 0.193994, No Obj: 0.488208, .5R: 0.000000, .75R: 0.000000, count: 1
2: 260.959106, 255.495361 avg, 0.000000 rate, 2.503628 seconds, 2 images
Loaded: 0.000075 seconds
Region 16 Avg IOU: -nan, Class: -nan, Obj: -nan, No Obj: 0.510984, .5R: -nan, .75R: -nan, count: 0
Region 23 Avg IOU: 0.284477, Class: 0.340647, Obj: 0.187216, No Obj: 0.490305, .5R: 0.000000, .75R: 0.000000, count: 1
3: 256.483185, 255.594147 avg, 0.000000 rate, 2.478287 seconds, 3 images
Loaded: 0.018822 seconds
Region 16 Avg IOU: 0.163654, Class: 0.443973, Obj: 0.593278, No Obj: 0.511138, .5R: 0.000000, .75R: 0.000000, count: 1
Region 23 Avg IOU: -nan, Class: -nan, Obj: -nan, No Obj: 0.492911, .5R: -nan, .75R: -nan, count: 0
4: 264.743774, 256.509094 avg, 0.000000 rate, 2.654358 seconds, 4 images
Loaded: 0.000085 seconds
Region 16 Avg IOU: -nan, Class: -nan, Obj: -nan, No Obj: 0.507896, .5R: -nan, .75R: -nan, count: 0
Region 23 Avg IOU: 0.174168, Class: 0.560516, Obj: 0.354948, No Obj: 0.493261, .5R: 0.000000, .75R: 0.000000, count: 1
5: 262.642822, 257.122467 avg, 0.000000 rate, 2.555897 seconds, 5 images
Loaded: 0.000080 seconds
Region 16 Avg IOU: 0.070988, Class: 0.595818, Obj: 0.754916, No Obj: 0.509035, .5R: 0.000000, .75R: 0.000000, count: 1
Region 23 Avg IOU: -nan, Class: -nan, Obj: -nan, No Obj: 0.491065, .5R: -nan, .75R: -nan, count: 0
6: 267.453857, 258.155609 avg, 0.000000 rate, 2.463075 seconds, 6 images
Loaded: 0.000143 seconds