解决YOLO3 训练出现Couldn't open file: .names train.txt valid.txt

YOLO3 训练自己的数据

数据处理后,生成train和valid以及data

traintxt = '../dataset/random_save-2020-04-15-17-46-54.train.txt'
validtxt = '../dataset/random_save-2020-04-15-17-46-54.valid.txt'

dataFile = ''
dataFile += 'class=5\r\n'
dataFile += f"train=.{traintxt.split('..')[1]}\r\n"
dataFile += f"valid=.{validtxt.split('..')[1]}\r\n"
dataFile += f'names=./dataset/names_{task_name}.names\r\n'
dataFile += f'backup=./output/random\r\n'
dataFile += f'eval=coco\r\n'

with open(f'../dataset/random_{task_name}.data', 'w+') as F:
    F.write(dataFile)
print(f'data  ../dataset/random_{task_name}.data')

dataFile = ''
dataFile += 'cat\r\n'
dataFile += 'dog\r\n'
dataFile += 'horse\r\n'
dataFile += 'tiger\r\n'
dataFile += 'bear\r\n'
with open(f'../dataset/names_{task_name}.names', 'w+') as F:
    F.write(dataFile)
print(f'names  ../dataset/names_{task_name}.names')

出现问题如下

yolov3-tiny-5clf
layer     filters    size              input                output
    0 conv     16  3 x 3 / 1   608 x 608 x   3   ->   608 x 608 x  16  0.319 BFLOPs
    1 max          2 x 2 / 2   608 x 608 x  16   ->   304 x 304 x  16
    2 conv     32  3 x 3 / 1   304 x 304 x  16   ->   304 x 304 x  32  0.852 BFLOPs
    3 max          2 x 2 / 2   304 x 304 x  32   ->   152 x 152 x  32
    4 conv     64  3 x 3 / 1   152 x 152 x  32   ->   152 x 152 x  64  0.852 BFLOPs
    5 max          2 x 2 / 2   152 x 152 x  64   ->    76 x  76 x  64
    6 conv    128  3 x 3 / 1    76 x  76 x  64   ->    76 x  76 x 128  0.852 BFLOPs
    7 max          2 x 2 / 2    76 x  76 x 128   ->    38 x  38 x 128
    8 conv    256  3 x 3 / 1    38 x  38 x 128   ->    38 x  38 x 256  0.852 BFLOPs
    9 max          2 x 2 / 2    38 x  38 x 256   ->    19 x  19 x 256
   10 conv    512  3 x 3 / 1    19 x  19 x 256   ->    19 x  19 x 512  0.852 BFLOPs
   11 max          2 x 2 / 1    19 x  19 x 512   ->    19 x  19 x 512
   12 conv   1024  3 x 3 / 1    19 x  19 x 512   ->    19 x  19 x1024  3.407 BFLOPs
   13 conv    256  1 x 1 / 1    19 x  19 x1024   ->    19 x  19 x 256  0.189 BFLOPs
   14 conv    512  3 x 3 / 1    19 x  19 x 256   ->    19 x  19 x 512  0.852 BFLOPs
   15 conv     30  1 x 1 / 1    19 x  19 x 512   ->    19 x  19 x  30  0.011 BFLOPs
   16 yolo
   17 route  13
   18 conv    128  1 x 1 / 1    19 x  19 x 256   ->    19 x  19 x 128  0.024 BFLOPs
   19 upsample            2x    19 x  19 x 128   ->    38 x  38 x 128
   20 route  19 8
   21 conv    256  3 x 3 / 1    38 x  38 x 384   ->    38 x  38 x 256  2.555 BFLOPs
   22 conv     30  1 x 1 / 1    38 x  38 x 256   ->    38 x  38 x  30  0.022 BFLOPs
   23 yolo
Learning Rate: 0.001, Momentum: 0.9, Decay: 0.0005
Couldn't open file: ../dataset/random_save-2020-04-15-17-46-54.train.txt

???

(base) xx@xxx:~/projects/object$ ls ./dataset/random_save-2020-04-15-17-46-54.train.txt -lh
-rw-rw-r-- 1 xxx xxx 2.1K 4月  22 15:43 ./dataset/random_save-2020-04-15-17-46-54.train.txt

文件确定是有的。那么问题在哪呢???

diff一下

(base) xx@xxx:~/projects/object$ diff dataset/random_Save-2020-04-15-17-46-54.data dataset/random_save-2020-04-15-17-46-54.data 
1,6c1,6
< class=5
< train=./dataset/random_Save-2020-04-15-17-46-54.train.txt
< valid=./dataset/random_Save-2020-04-15-17-46-54.valid.txt
< names=./dataset/names_Save-2020-04-15-17-46-54.names
< backup=./output/random
< eval=coco
---
> class=5
> train=./dataset/random_save-2020-04-15-17-46-54.train.txt
> valid=./dataset/random_save-2020-04-15-17-46-54.valid.txt
> names=./dataset/names_save-2020-04-15-17-46-54.names
> backup=./output/random
> eval=coco

发现两个文件没有一行是一样的!!!ghost inside?
那么回到首页,仔细看了这两个文件生成的,"\r\n"?

解决办法,把所有的 \r\n 替换成\n

traintxt = '../dataset/random_save-2020-04-15-17-46-54.train.txt'
validtxt = '../dataset/random_save-2020-04-15-17-46-54.valid.txt'

dataFile = ''
dataFile += 'class=5\n'
dataFile += f"train=.{traintxt.split('..')[1]}\n"
dataFile += f"valid=.{validtxt.split('..')[1]}\n"
dataFile += f'names=./dataset/names_{task_name}.names\n'
dataFile += f'backup=./output/random\n'
dataFile += f'eval=coco\n'

with open(f'../dataset/random_{task_name}.data', 'w+') as F:
    F.write(dataFile)
print(f'data  ../dataset/random_{task_name}.data')

dataFile = ''
dataFile += 'cat\n'
dataFile += 'dog\n'
dataFile += 'horse\n'
dataFile += 'tiger\n'
dataFile += 'bear\n'
with open(f'../dataset/names_{task_name}.names', 'w+') as F:
    F.write(dataFile)
print(f'names  ../dataset/names_{task_name}.names')

END

你可能感兴趣的:(AI)