Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Fix] bugfix/avoid-runner-iter-in-vis-hook-test-mode (#3596)
## Motivation The current `SegVisualizationHook` implements the `_after_iter` method, which is invoked during the validation and testing pipelines. However, when in [test_mode](https://github.com/open-mmlab/mmsegmentation/blob/main/mmseg/engine/hooks/visualization_hook.py#L97), the implementation attempts to access `runner.iter`. This attribute is defined in the [`mmengine` codebase](https://github.com/open-mmlab/mmengine/blob/main/mmengine/runner/runner.py#L538) and is designed to return `train_loop.iter`. Accessing this property during testing can be problematic, particularly in scenarios where the model is being evaluated post-training, without initiating a training loop. This can lead to a crash if the implementation tries to build a training dataset for which the annotation file is unavailable at the time of evaluation. Thus, it is crucial to avoid relying on this property in test mode. ## Modification To resolve this issue, the proposal is to replace the `_after_iter` method with `after_val_iter` and `after_test_iter` methods, modifying their behavior accordingly. Specifically, when in testing mode, the implementation should utilize a `test_index` counter instead of accessing `runner.iter`. This adjustment will circumvent the issue of accessing `train_loop.iter` during test mode, ensuring the process does not attempt to access or build a training dataset, thereby preventing potential crashes due to missing annotation files.
- Loading branch information