set.py
2.32 KB
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
from distutils.dir_util import copy_tree
import shutil
import os
#.txt 경로 변경
def setTxt():
ftrain = open("/root/volume/custom/darknet/custom_data/Train.txt", mode="rt", encoding="utf-8")
ftest = open("/root/volume/custom/darknet/custom_data/Valid.txt", mode="rt", encoding="utf-8")
fTrain = open("/root/volume/custom/darknet/custom_data/train.txt", mode="wt", encoding="utf-8")
fTest = open("/root/volume/custom/darknet/custom_data/test.txt", mode="wt", encoding="utf-8")
line = ftrain.readline()
while line:
fTrain.write('custom_data/images' + line[3:])
line = ftrain.readline()
line = ftest.readline()
while line:
fTest.write('custom_data/images' + line[3:])
line = ftest.readline()
#txt 파일 라벨로 옮기기
def Move():
dir_list = os.listdir('/root/volume/custom/darknet/custom_data/images')
path = '/root/volume/custom/darknet/custom_data/images/'
for Dir in dir_list:
if os.path.isdir('/root/volume/custom/darknet/custom_data/labels/' + Dir) == False:
os.makedirs('/root/volume/custom/darknet/custom_data/labels/' + Dir)
for i in os.walk('/root/volume/custom/darknet/custom_data/images'):
for j in range(len(i[2])):
if i[2][j][-3:] == 'txt':
shutil.move(i[0] + '/' + i[2][j], '/root/volume/custom/darknet/custom_data/labels/' + i[0].split('/')[-1] + '/' + i[2][j])
def rename():
dir_list = os.listdir('/root/volume/custom/darknet/custom_data/labels')
for Dir in dir_list:
if 'raw' in Dir:
Str = Dir[:Dir.find('raw')] + 'labels' + Dir[Dir.find('raw') + 3:]
os.rename('/root/volume/custom/darknet/custom_data/labels/' + Dir, '/root/volume/custom/darknet/custom_data/labels/' + Str)
def check():
f = open('/root/volume/custom/darknet/31000_train.log', mode='rt', encoding='utf-8')
line = f.readline()
line = f.readline()
line = f.readline()
line = f.readline()
line = f.readline()
while line:
if line[0] == 'R' or line[0] == 'L':
line = f.readline()
continue
num = int(line[:line.find(':')])
if num % 1000 == 0 or (num < 2000 and num % 200 == 0):
print(line[:-1])
line = f.readline()
if __name__ == "__main__":
check()
#rename()
#Move()
#check()
#setTxt()