open-mmlab / mmocr

OpenMMLab Text Detection, Recognition and Understanding Toolbox
https://mmocr.readthedocs.io/en/dev-1.x/
Apache License 2.0
4.3k stars 745 forks source link

When testing my model with tools/test.py, my config will be messed up by the "--save-preds" option. #2052

Closed shiyunalex closed 4 months ago

shiyunalex commented 4 months ago

Motivation

To improve the test tool, when testing model with tools/test.py and "--save-preds" option.

Modification

When the test_evaluator config is a dict and --save-preds is in tools/test.py's option, the runner cannot correctly buid the evaluator.For example: My config file

test_evaluator = dict(
    type='MultiDatasetsEvaluator',
    metrics=[
        dict(
            type='WordMetric',
            mode=['exact', 'ignore_case', 'ignore_case_symbol']),
        dict(type='CharMetric')
    ],
    dataset_prefixes=None)

My test script

python tools/test.py \
work_dirs/master_resnet31_12e.py \
work_dirs/best_ocr_rec_1_recog_char_f1_epoch_980.pth \
--save-preds

the --save-preds option will concat the evaluator with a DumpResults instance in a wrong way,the new evaluator is like:

test_evaluator = [
dict(type='MultiDatasetsEvaluator',
    metrics=[
        dict(
            type='WordMetric',
            mode=['exact', 'ignore_case', 'ignore_case_symbol']),
        dict(type='CharMetric')
    ],
    dataset_prefixes=None),
dict(
    type='DumpResults',
    out_file_path='my_work_dir')
]

This new test_evaluator cannot be built by program.

After updating the tools/test.py, using the same config and test scripts, the new test_evaluator will be:

test_evaluator = [
dict(type='MultiDatasetsEvaluator',
    metrics=[
        dict(
            type='WordMetric',
            mode=['exact', 'ignore_case', 'ignore_case_symbol']),
        dict(type='CharMetric'),
        dict(
            type='DumpResults',
            out_file_path='my_work_dir')
    ],
    dataset_prefixes=None)
]

This new test_evaluator can be built correctly by program.

Checklist

Before PR:

After PR:

CLAassistant commented 4 months ago

CLA assistant check
All committers have signed the CLA.