Skip to content

Commit

Permalink
fix unittest
Browse files Browse the repository at this point in the history
  • Loading branch information
dreamerlin committed Jan 25, 2021
1 parent 4a2a424 commit 8b0b623
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 31 deletions.
10 changes: 3 additions & 7 deletions mmaction/core/evaluation/eval_hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,13 @@ class EvalHook(Hook):
``top1_acc``, ``top5_acc``, ``mean_class_accuracy``,
``mean_average_precision``, ``mmit_mean_average_precision``
for action recognition dataset (RawframeDataset and VideoDataset).
<<<<<<< HEAD
``AR@AN``, ``auc`` for action localization dataset.
(ActivityNetDataset). ``[email protected]@100``, ``AR@100``,
``[email protected]`` for spatio-temporal action detection dataset
(AVADataset). Default: `top1_acc`.
=======
``AR@AN``, ``auc`` for action localization dataset
(ActivityNetDataset). If ``save_best`` is ``auto``, the first key
(AVADataset). If ``save_best`` is ``auto``, the first key
of the returned ``OrderedDict`` result will be used. The interval
of ``CheckpointHook`` should device EvalHook. Default: None.
>>>>>>> polish again
of ``CheckpointHook`` should be divisible by that of EvalHook.
Default: 'top1_acc'.
rule (str | None, optional): Comparison rule for best score. If set to
None, it will infer a reasonable rule. Keys such as 'acc', 'top'
.etc will be inferred by 'greater' rule. Keys contain 'loss' will
Expand Down
42 changes: 18 additions & 24 deletions tests/test_runtime/test_eval_hook.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,12 +138,11 @@ def test_eval_hook():
runner.register_hook(eval_hook)
runner.run([loader], [('train', 1)], 8)

real_path = osp.join(tmpdir, 'epoch_4.pth')
link_path = osp.join(tmpdir, 'best_acc_epoch_4.pth')
ckpt_path = osp.join(tmpdir, 'best_acc_epoch_4.pth')

assert runner.meta['hook_msgs']['best_ckpt'] == osp.realpath(
real_path)
assert osp.exists(link_path)
ckpt_path)
assert osp.exists(ckpt_path)
assert runner.meta['hook_msgs']['best_score'] == 7

# total_epochs = 8, return the best acc and corresponding epoch
Expand All @@ -160,12 +159,11 @@ def test_eval_hook():
runner.register_hook(eval_hook)
runner.run([loader], [('train', 1)], 8)

real_path = osp.join(tmpdir, 'epoch_4.pth')
link_path = osp.join(tmpdir, 'best_acc_epoch_4.pth')
ckpt_path = osp.join(tmpdir, 'best_acc_epoch_4.pth')

assert runner.meta['hook_msgs']['best_ckpt'] == osp.realpath(
real_path)
assert osp.exists(link_path)
ckpt_path)
assert osp.exists(ckpt_path)
assert runner.meta['hook_msgs']['best_score'] == 7

# total_epochs = 8, return the best score and corresponding epoch
Expand All @@ -180,12 +178,11 @@ def test_eval_hook():
runner.register_hook(eval_hook)
runner.run([loader], [('train', 1)], 8)

real_path = osp.join(tmpdir, 'epoch_4.pth')
link_path = osp.join(tmpdir, 'best_score_epoch_4.pth')
ckpt_path = osp.join(tmpdir, 'best_score_epoch_4.pth')

assert runner.meta['hook_msgs']['best_ckpt'] == osp.realpath(
real_path)
assert osp.exists(link_path)
ckpt_path)
assert osp.exists(ckpt_path)
assert runner.meta['hook_msgs']['best_score'] == 7

# total_epochs = 8, return the best score using less compare func
Expand All @@ -200,12 +197,11 @@ def test_eval_hook():
runner.register_hook(eval_hook)
runner.run([loader], [('train', 1)], 8)

real_path = osp.join(tmpdir, 'epoch_6.pth')
link_path = osp.join(tmpdir, 'best_acc_epoch_6.pth')
ckpt_path = osp.join(tmpdir, 'best_acc_epoch_6.pth')

assert runner.meta['hook_msgs']['best_ckpt'] == osp.realpath(
real_path)
assert osp.exists(link_path)
ckpt_path)
assert osp.exists(ckpt_path)
assert runner.meta['hook_msgs']['best_score'] == -3

# Test the EvalHook when resume happend
Expand All @@ -219,12 +215,11 @@ def test_eval_hook():
runner.register_hook(eval_hook)
runner.run([loader], [('train', 1)], 2)

real_path = osp.join(tmpdir, 'epoch_2.pth')
link_path = osp.join(tmpdir, 'best_acc_epoch_2.pth')
ckpt_path = osp.join(tmpdir, 'best_acc_epoch_2.pth')

assert runner.meta['hook_msgs']['best_ckpt'] == osp.realpath(
real_path)
assert osp.exists(link_path)
ckpt_path)
assert osp.exists(ckpt_path)
assert runner.meta['hook_msgs']['best_score'] == 4

resume_from = osp.join(tmpdir, 'latest.pth')
Expand All @@ -237,12 +232,11 @@ def test_eval_hook():
runner.resume(resume_from)
runner.run([loader], [('train', 1)], 8)

real_path = osp.join(tmpdir, 'epoch_4.pth')
link_path = osp.join(tmpdir, 'best_acc_epoch_4.pth')
ckpt_path = osp.join(tmpdir, 'best_acc_epoch_4.pth')

assert runner.meta['hook_msgs']['best_ckpt'] == osp.realpath(
real_path)
assert osp.exists(link_path)
ckpt_path)
assert osp.exists(ckpt_path)
assert runner.meta['hook_msgs']['best_score'] == 7


Expand Down

0 comments on commit 8b0b623

Please sign in to comment.