Skip to content

Commit 31165da

Browse files
chyomin06fracape
authored andcommitted
[fix] run multiple gen_mpeg_cttc_csv.py in parallel
1 parent 425062e commit 31165da

1 file changed

Lines changed: 16 additions & 10 deletions

File tree

scripts/metrics/compute_per_class_map.py

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838

3939
import json
4040
import os
41+
import tempfile
4142

4243
import numpy as np
4344
import pandas as pd
@@ -65,9 +66,6 @@
6566
"RaceHorses_416x240_30": 140000,
6667
}
6768

68-
TMP_EVAL_FILE = "tmp_eval.json"
69-
TMP_ANCH_FILE = "tmp_anch.json"
70-
7169
NS_SEQ_PREFIX = "ns_" # Prefix of non-scaled sequences
7270

7371

@@ -117,16 +115,24 @@ def compute_per_class_mAP(seq_root_names, items):
117115
"annotations": classwise_annotation,
118116
}
119117

120-
with open(TMP_EVAL_FILE, "w") as f:
121-
json.dump(classwise_instances_results, f, indent=4)
118+
eval_fd, eval_path = tempfile.mkstemp(prefix="tmp_eval_", suffix=".json")
119+
anch_fd, anch_path = tempfile.mkstemp(prefix="tmp_anch_", suffix=".json")
120+
os.close(eval_fd)
121+
os.close(anch_fd)
122122

123-
with open(TMP_ANCH_FILE, "w") as f:
124-
json.dump(classwise_gt_data, f, indent=4)
123+
try:
124+
with open(eval_path, "w") as f:
125+
json.dump(classwise_instances_results, f, indent=4)
125126

126-
summary = coco_evaluation(TMP_ANCH_FILE, TMP_EVAL_FILE)
127+
with open(anch_path, "w") as f:
128+
json.dump(classwise_gt_data, f, indent=4)
127129

128-
os.remove(TMP_EVAL_FILE)
129-
os.remove(TMP_ANCH_FILE)
130+
summary = coco_evaluation(anch_path, eval_path)
131+
finally:
132+
if os.path.exists(eval_path):
133+
os.remove(eval_path)
134+
if os.path.exists(anch_path):
135+
os.remove(anch_path)
130136

131137
return summary
132138

0 commit comments

Comments
 (0)