-
Notifications
You must be signed in to change notification settings - Fork 0
/
result2csv_json.py
65 lines (51 loc) · 1.83 KB
/
result2csv_json.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
#result→csv
#コマンドラインで指定↓
#dir(デフォルト:result_json)
#csvfile(デフォルト:result.csv)
import os
from pathlib import Path
import json
import pandas as pd
def main(dir, csvfile):
"""メイン
Args:
dir(string):
csvfile
"""
type = ["bbox", "segm"]
val = ["AP", "AP50", "AP75", "AR1", "AR10", "AR100"]
col_list = ["filename"]
for i in range(2):
for j in range(3):
col = type[i] + val[j]
col_list.append(col)
df = pd.DataFrame(columns=col_list)
#ファイル一覧取得
file_name_list = [f for f in os.listdir(dir) if f.endswith(".json")]
file_path_list = [str(Path(dir).joinpath(f)) for f in file_name_list]
i = 0
for f in file_path_list:
with open(f, 'r') as jsonfile:
dic_result = json.load(jsonfile)
df.at[i,"filename"] = file_name_list[i].replace(".json", "")
for m in range(2):
for n in range(3):
col = type[m] + val[n]
#df.at[i, col] = round(dic_result[type[m]][val[n]],2)
df.at[i, col] = dic_result[type[m]][val[n]]
i += 1
jsonfile.close
print(df)
df.to_csv(str(Path(dir).joinpath("result.csv")), index = False)
if __name__ == "__main__":
import argparse
parser = argparse.ArgumentParser(
description='result_json to csvfile.',
formatter_class=argparse.ArgumentDefaultsHelpFormatter)
parser.add_argument('--dir', help='Directory of input files', default='result_json', type=str)
parser.add_argument('--csvfile', help='result csv file', default='result.csv', type=str)
args = parser.parse_args()
try:
main(args.dir, args.csvfile)
except Exception as e:
print(e)