[Fix] Fix format error in `test.py` when metric returns `np.ndarray` (#441)

* Update test.py

Fix the output format error when metric-options is specified

* Update tools/test.py

Co-authored-by: Ma Zerun <mzr1996@163.com>

* Update test.py

delete "," after round(out, 2)

* Update test.py

delete else

* Update tools/test.py

Co-authored-by: Ma Zerun <mzr1996@163.com>

Co-authored-by: Ma Zerun <mzr1996@163.com>
pull/471/head
Shane Zhao 2021-09-29 11:51:19 +08:00 committed by GitHub
parent 90496b4687
commit e166ee7c0c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 8 additions and 1 deletions

View File

@ -2,6 +2,7 @@
import argparse
import os
import warnings
from numbers import Number
import mmcv
import numpy as np
@ -186,7 +187,13 @@ def main():
args.metric_options)
results.update(eval_results)
for k, v in eval_results.items():
print(f'\n{k} : {v:.2f}')
if isinstance(v, np.ndarray):
v = [round(out, 2) for out in v.tolist()]
elif isinstance(v, Number):
v = round(v, 2)
else:
raise ValueError(f'Unsupport metric type: {type(v)}')
print(f'\n{k} : {v}')
if args.out:
if 'none' not in args.out_items:
scores = np.vstack(outputs)