-
Notifications
You must be signed in to change notification settings - Fork 2
/
change_labelnum2.py
80 lines (73 loc) · 2.51 KB
/
change_labelnum2.py
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
from ntpath import join
import os
import shutil
from tqdm import tqdm
targetDir=r"D:\FLIR_ADAS_v2\images_rgb_val\label_val"
targetDir2=r"D:\FLIR_ADAS_v2\images_rgb_val\rgb_val_label"
file_list=os.listdir(targetDir)
txt_list=[]
fail=0
num=0
for file in file_list:
if '.txt' in file:
txt_list.append(file)
for txt_file in tqdm(txt_list):
target_path = targetDir + "\\" + txt_file
target_path2 = targetDir2 + "\\" + txt_file
targetTXT = open(target_path, 'r')
line=targetTXT.readlines()
for word in line:
label_Number=word.split(' ')[0]
words=word.split(' ')[1:]
if label_Number == '3' : #car 1
f='1 '+' '.join(words)
newfile=open(target_path2,'a')
newfile.write(f)
newfile.close()
elif label_Number == '1' : #person 0
f='0 '+' '.join(words)
newfile=open(target_path2,'a')
newfile.write(f)
newfile.close()
elif label_Number == '6': #vehicle 2
f='2 '+' '.join(words)
newfile=open(target_path2,'a')
newfile.write(f)
newfile.close()
elif label_Number == '8':
f='2 '+' '.join(words)
newfile=open(target_path2,'a')
newfile.write(f)
newfile.close()
elif label_Number == '79':
f='2 '+' '.join(words)
newfile=open(target_path2,'a')
newfile.write(f)
newfile.close()
elif label_Number == '2': #bicycle 3
f='3 '+' '.join(words)
newfile=open(target_path2,'a')
newfile.write(f)
newfile.close()
elif label_Number == '4': #bicycle 3
f='3 '+' '.join(words)
newfile=open(target_path2,'a')
newfile.write(f)
newfile.close()
elif label_Number == '10': #traffic light 5
# f= word.replace('10 ','5 ')
f='5 '+' '.join(words)
newfile=open(target_path2,'a')
newfile.write(f)
newfile.close()
elif label_Number == '12': #traffic sign 6
f='6 '+' '.join(words)
newfile=open(target_path2,'a')
newfile.write(f)
newfile.close()
else :
f='7 '+' '.join(words)
newfile=open(target_path2,'a')
newfile.write(f)
newfile.close()
print(fail)