CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
hukaixuan19970627

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.

GitHub Repository: hukaixuan19970627/yolov5_obb
Path: blob/master/DOTA_devkit/results_ensemble.py
Views: 475
1
import os
2
import argparse
3
import shutil
4
5
def GetFileFromThisRootDir(dir,ext = None):
6
allfiles = []
7
needExtFilter = (ext != None)
8
for root,dirs,files in os.walk(dir):
9
for filespath in files:
10
filepath = os.path.join(root, filespath)
11
extension = os.path.splitext(filepath)[1][1:]
12
if needExtFilter and extension in ext:
13
allfiles.append(filepath)
14
elif not needExtFilter:
15
allfiles.append(filepath)
16
return allfiles
17
18
def custombasename(fullname):
19
return os.path.basename(os.path.splitext(fullname)[0])
20
21
def results_ensemble(srcpath_1, srcpath_2, dstpath):
22
"""
23
将srcpath_1,srcpath_2文件夹中的所有txt中的目标提取出来, 并叠加在一起存入 dstpath
24
"""
25
if os.path.exists(dstpath):
26
shutil.rmtree(dstpath) # delete output folderX
27
os.makedirs(dstpath)
28
29
filelist_1 = GetFileFromThisRootDir(srcpath_1) # srcpath文件夹下的所有文件相对路径 eg:['Task1_??.txt', ..., '?.txt']
30
filelist_2 = GetFileFromThisRootDir(srcpath_2)
31
for index, fullname_1 in enumerate(filelist_1): # Task1_??.txt'
32
fullname_2 = filelist_2[index]
33
basename = custombasename(fullname_1) # 只留下文件名 eg:'Task1_??'
34
dstname = os.path.join(dstpath, basename + '.txt') # eg: ./.../Task1_plane.txt
35
36
with open(dstname, 'a') as f_out:
37
# merge first txt
38
with open(fullname_1, 'r') as f1:
39
lines = f1.readlines()
40
for line in lines:
41
f_out.writelines(line)
42
# merge second txt
43
with open(fullname_2, 'r') as f2:
44
lines = f2.readlines()
45
for line in lines:
46
f_out.writelines(line)
47
pass
48
49
def parse_args():
50
parser = argparse.ArgumentParser(description='model ensemble')
51
parser.add_argument('--srcpath_1', default='/OrientedRepPoints/tools/parse_pkl/evaluation_results/ORR_results/', help='srcpath_1')
52
parser.add_argument('--srcpath_2', default='/OrientedRepPoints/tools/parse_pkl/evaluation_results/ROI_results/', help='srcpath_2')
53
parser.add_argument('--dstpath', default='/OrientedRepPoints/tools/parse_pkl/evaluation_results/orientedreppoints_ROIRT_ensemble/', help='dstpath')
54
args = parser.parse_args()
55
return args
56
57
def main():
58
args = parse_args()
59
srcpath_1 = args.srcpath_1
60
srcpath_2 = args.srcpath_2
61
dstpath = args.dstpath
62
63
results_ensemble(srcpath_1, srcpath_2, dstpath)
64
65
66
if __name__ == '__main__':
67
main()
68