Skip to content

Commit 90bccb3

Browse files
author
ZHANG Zhiwei
committed
add display function
1 parent 66ef05e commit 90bccb3

File tree

3 files changed

+23
-16
lines changed

3 files changed

+23
-16
lines changed

openunreid/apis/test.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -220,11 +220,9 @@ def final_test(cfg, model, cmc_topk=(1, 5, 10)):
220220
)
221221
all_cmc.append(cmc)
222222
all_mAP.append(mAP)
223-
print("\n")
224-
print("Mean AP: {:4.1%}".format(np.mean(all_mAP)))
225-
print("CMC Scores:")
226-
for k in cmc_topk:
227-
print(" top-{:<4}{:12.1%}".format(k, np.mean(all_cmc, axis=0)[k - 1]))
223+
224+
225+
display(cfg, all_mAP, all_cmc, cmc_topk)
228226

229227
end_time = time.monotonic()
230228
print("Testing time: ", timedelta(seconds=end_time - start_time))

openunreid/core/metrics/rank.py

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55

66
import numpy as np
77

8+
from openunreid.utils.logger import display
9+
810
try:
911
from .rank_cylib.rank_cy import evaluate_cy
1012

@@ -202,16 +204,7 @@ def evaluate_rank(
202204
distmat, q_pids, g_pids, q_camids, g_camids, max_rank, use_metric_cuhk03
203205
)
204206

205-
if verbose and cfg.TRAIN.num_repeat == 10:
206-
print("\n")
207-
print("Mean AP: {:4.1%}".format(map))
208-
print("CMC Scores:")
209-
for k in cmc_topk:
210-
print(" top-{:<4}{:12.1%}".format(k, cmc[k - 1]))
211-
else:
212-
print("\n")
213-
print("CMC Scores:")
214-
for k in cmc_topk:
215-
print(" top-{:<4}{:12.1%}".format(k, cmc[k - 1]))
207+
if verbose:
208+
display(cfg, map, cmc, cmc_topk)
216209

217210
return cmc, map

openunreid/utils/logger.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import os
22
import sys
33

4+
import numpy as np
5+
46
from .dist_utils import get_dist_info, synchronize
57
from .file_utils import mkdir_if_missing
68

@@ -42,3 +44,17 @@ def close(self):
4244
self.console.close()
4345
if self.file is not None:
4446
self.file.close()
47+
48+
49+
def display(cfg, map, cmc, cmc_topk=(1, 5, 10)):
50+
if cfg.TRAIN.num_repeat == 10:
51+
print("\n")
52+
print("Mean AP: {:4.1%}".format(np.mean(map)))
53+
print("CMC Scores:")
54+
for k in cmc_topk:
55+
print(" top-{:<4}{:12.1%}".format(k, np.mean(cmc, axis=0)[k - 1]))
56+
else:
57+
print("\n")
58+
print("CMC Scores:")
59+
for k in cmc_topk:
60+
print(" top-{:<4}{:12.1%}".format(k, np.mean(cmc, axis=0)[k - 1]))

0 commit comments

Comments
 (0)