-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathall_acc_convert.py
113 lines (85 loc) · 2.81 KB
/
all_acc_convert.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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
'''
2024.5.12: convert accfile to list
'''
import os
from os.path import join
from pathlib import Path
import shutil
SAVE_WEIGHT_PATH = '/localssd/yinxia/CRGNetdata/'
def is_float(s):
try:
v = float(s)
return v
except ValueError:
return None
def convertAcc(file):
data = []
with open(file, 'r') as f:
flag=0
for idx, line in enumerate(f):
if 'Iter 5000' in line:
flag=1
continue
# start extract data
if flag==1:
linesplit = line.strip().split(' ')
# values = linesplit[::2]
for v in linesplit:
value = is_float(v)
if value is not None:
data.append(value)
# save
newfile = file[:-4]+'_acc.txt'
with open(newfile, 'w') as f:
for v in data:
f.writelines(f'{v} \n')
def convertAccTest(file):
data = []
with open(file, 'r') as f:
for idx, line in enumerate(f):
if '===>' in line:
# start extract data
linesplit = line.strip().split(' ')
# values = linesplit[::2]
for v in linesplit:
value = is_float(v)
if value is not None:
data.append(value)
if 'OA' in line:
data.append('')
# save
newfile = file[:-4]+'_acc.txt'
with open(newfile, 'w') as f:
for v in data:
f.writelines(f'{v} \n')
if __name__=="__main__":
# citylist = ['Vaihingen', 'Zurich']
# citylist = ['uavid',]
citylist = ['uavid','Zurich', 'Vaihingen', ]
for city in citylist:
ipath = fr'{SAVE_WEIGHT_PATH}/{city}'
filelist = [str(i) for i in Path(ipath).rglob(f'{city}*_log.txt')]
print(len(filelist))
for file in filelist:
convertAcc(file)
# copy all original files
newfile = file[:-4]+'_copy.txt'
shutil.copy(file, newfile)
citylist = ['uavid', 'Zurich', 'Vaihingen',]
for city in citylist:
ipath = fr'{SAVE_WEIGHT_PATH}/{city}'
filelist = [str(i) for i in Path(ipath).rglob(f'Test_{city}*.txt')]
print(len(filelist))
for file in filelist:
# delete duplicate files
if file.count('acc')>1 or (file.count('copy')>1):
os.remove(file)
if file.count('acc_copy')==1 or (file.count('copy_acc')==1):
os.remove(file)
if ('acc.txt' in file) or ('copy.txt' in file):
continue
convertAccTest(file)
# copy all original files
newfile = file[:-4]+'_copy.txt'
if not os.path.exists(newfile):
shutil.copy(file, newfile)