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/tools/TestJson2VocClassTxt.py
Views: 475
"""1Yolov5-obb检测结果Json 文件转Voc Class Txt2--json_path 输入的json文件路径3--save_path 输出文件夹路径4"""56import os7import json8from tqdm import tqdm9import argparse10import shutil1112parser = argparse.ArgumentParser()13parser.add_argument('--json_path', default='runs/val/exp/last_predictions.json',type=str, help="input: coco format(json)")14parser.add_argument('--save_path', default='runs/val/exp/last_predictions_Txt', type=str, help="specify where to save the output dir of labels")15arg = parser.parse_args()1617# For DOTA-v2.018dotav2_classnames = [ 'plane', 'baseball-diamond', 'bridge', 'ground-track-field', 'small-vehicle', 'large-vehicle', 'ship',19'tennis-court', 'basketball-court', 'storage-tank', 'soccer-ball-field', 'roundabout', 'harbor',20'swimming-pool', 'helicopter', 'container-crane', 'airport', 'helipad']21# For DOTA-v1.522dotav15_classnames = ['plane', 'baseball-diamond', 'bridge', 'ground-track-field', 'small-vehicle', 'large-vehicle', 'ship', 'tennis-court',23'basketball-court', 'storage-tank', 'soccer-ball-field', 'roundabout', 'harbor', 'swimming-pool', 'helicopter', 'container-crane']24# For DOTA-v1.025datav1_classnames = ['plane', 'baseball-diamond', 'bridge', 'ground-track-field', 'small-vehicle', 'large-vehicle', 'ship', 'tennis-court',26'basketball-court', 'storage-tank', 'soccer-ball-field', 'roundabout', 'harbor', 'swimming-pool', 'helicopter']2728DOTA_CLASSES = dotav15_classnames29if __name__ == '__main__':30json_file = arg.json_path # COCO Object Instance 类型的标注31ana_txt_save_path = arg.save_path # 保存的路径3233data = json.load(open(json_file, 'r'))34if os.path.exists(ana_txt_save_path):35shutil.rmtree(ana_txt_save_path) # delete output folderX36os.makedirs(ana_txt_save_path)3738for data_dict in data:39img_name = data_dict["file_name"]40score = data_dict["score"]41poly = data_dict["poly"]42classname = DOTA_CLASSES[data_dict["category_id"]-1] # COCO's category_id start from 1, not 04344lines = "%s %s %s %s %s %s %s %s %s %s\n" % (img_name, score, poly[0],poly[1],poly[2],poly[3],poly[4],poly[5],poly[6],poly[7])45with open(str(ana_txt_save_path + '/Task1_' + classname) + '.txt', 'a') as f:46f.writelines(lines)47pass48print("Done!")4950