Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.
Path: blob/master/DOTA_devkit/results_ensemble.py
Views: 475
import os1import argparse2import shutil34def GetFileFromThisRootDir(dir,ext = None):5allfiles = []6needExtFilter = (ext != None)7for root,dirs,files in os.walk(dir):8for filespath in files:9filepath = os.path.join(root, filespath)10extension = os.path.splitext(filepath)[1][1:]11if needExtFilter and extension in ext:12allfiles.append(filepath)13elif not needExtFilter:14allfiles.append(filepath)15return allfiles1617def custombasename(fullname):18return os.path.basename(os.path.splitext(fullname)[0])1920def results_ensemble(srcpath_1, srcpath_2, dstpath):21"""22将srcpath_1,srcpath_2文件夹中的所有txt中的目标提取出来, 并叠加在一起存入 dstpath23"""24if os.path.exists(dstpath):25shutil.rmtree(dstpath) # delete output folderX26os.makedirs(dstpath)2728filelist_1 = GetFileFromThisRootDir(srcpath_1) # srcpath文件夹下的所有文件相对路径 eg:['Task1_??.txt', ..., '?.txt']29filelist_2 = GetFileFromThisRootDir(srcpath_2)30for index, fullname_1 in enumerate(filelist_1): # Task1_??.txt'31fullname_2 = filelist_2[index]32basename = custombasename(fullname_1) # 只留下文件名 eg:'Task1_??'33dstname = os.path.join(dstpath, basename + '.txt') # eg: ./.../Task1_plane.txt3435with open(dstname, 'a') as f_out:36# merge first txt37with open(fullname_1, 'r') as f1:38lines = f1.readlines()39for line in lines:40f_out.writelines(line)41# merge second txt42with open(fullname_2, 'r') as f2:43lines = f2.readlines()44for line in lines:45f_out.writelines(line)46pass4748def parse_args():49parser = argparse.ArgumentParser(description='model ensemble')50parser.add_argument('--srcpath_1', default='/OrientedRepPoints/tools/parse_pkl/evaluation_results/ORR_results/', help='srcpath_1')51parser.add_argument('--srcpath_2', default='/OrientedRepPoints/tools/parse_pkl/evaluation_results/ROI_results/', help='srcpath_2')52parser.add_argument('--dstpath', default='/OrientedRepPoints/tools/parse_pkl/evaluation_results/orientedreppoints_ROIRT_ensemble/', help='dstpath')53args = parser.parse_args()54return args5556def main():57args = parse_args()58srcpath_1 = args.srcpath_159srcpath_2 = args.srcpath_260dstpath = args.dstpath6162results_ensemble(srcpath_1, srcpath_2, dstpath)636465if __name__ == '__main__':66main()6768