|
38 | 38 |
|
39 | 39 | import json |
40 | 40 | import os |
| 41 | +import tempfile |
41 | 42 |
|
42 | 43 | import numpy as np |
43 | 44 | import pandas as pd |
|
65 | 66 | "RaceHorses_416x240_30": 140000, |
66 | 67 | } |
67 | 68 |
|
68 | | -TMP_EVAL_FILE = "tmp_eval.json" |
69 | | -TMP_ANCH_FILE = "tmp_anch.json" |
70 | | - |
71 | 69 | NS_SEQ_PREFIX = "ns_" # Prefix of non-scaled sequences |
72 | 70 |
|
73 | 71 |
|
@@ -117,16 +115,24 @@ def compute_per_class_mAP(seq_root_names, items): |
117 | 115 | "annotations": classwise_annotation, |
118 | 116 | } |
119 | 117 |
|
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) |
122 | 122 |
|
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) |
125 | 126 |
|
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) |
127 | 129 |
|
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) |
130 | 136 |
|
131 | 137 | return summary |
132 | 138 |
|
|
0 commit comments