-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmodify_coco.py
47 lines (39 loc) · 962 Bytes
/
modify_coco.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
import os
folder = "./test"
#person
#bike
#car
#motor
#bus
#train
#truck
#traffic light
#traffic sign
good = {}
good[0] = 0
good[1] = 1
good[2] = 2
good[3] = 3
good[5] = 4
good[6] = 5
good[7] = 6
good[9] = 7
good[11] = 8
for root, dirs, files in os.walk(folder):
listf = files
for x in listf:
file = open(os.path.join(folder,x),"r")
file2 = open( os.path.join(folder,x) + "2", "w")
lines = file.readlines()
for line in lines:
splitted = line.split(" ")
#print (splitted)
if int(splitted[0]) in good.keys():
file2.write(str(good[int(splitted[0])]) + " ")
for i in range(len(splitted)-2):
file2.write(splitted[i+1]+" ")
file2.write(splitted[len(splitted)-1])
file.close()
file2.close()
os.remove(os.path.join(folder,x))
os.rename( os.path.join(folder,x) + "2", os.path.join(folder,x))