- [Evaluation in MMEngine](#evaluation-in-mmengine)
- [Online evaluation](#online-evaluation)
- [Offline evaluation](#offline-evaluation)
- [Evaluation In MMSelfSup](#evaluation-in-mmselfsup)
- [Customize Evaluation](#customize-evaluation)
<!-- /TOC -->
## Evaluation in MMEngine
During model validation and testing, quantitative evaluation is often required. `Metric` and `Evaluator` have been implemented in MMEngine to perform this function. See [MMEngine Doc](https://mmengine.readthedocs.io/en/latest/design/evaluation.html).
Model evaluation is divided into online evaluation and offline evaluation.
### Online evaluation
Online evaluation is used in [`ValLoop`](https://github.com/open-mmlab/mmengine/blob/main/mmengine/runner/loops.py#L300) and [`TestLoop`](https://github.com/open-mmlab/mmengine/blob/main/mmengine/runner/loops.py#L373).
Take `ValLoop` for example:
```python
...
class ValLoop(BaseLoop):
...
def run(self) -> dict:
"""Launch validation."""
self.runner.call_hook('before_val')
self.runner.call_hook('before_val_epoch')
self.runner.model.eval()
for idx, data_batch in enumerate(self.dataloader):
Offline evaluation uses the predictions saved in a file. In this case, since there is no `Runner`, we need to build the `Evaluator` and call `offline_evaluate()` function.
During pretrain, validation and testing are not included, so it is no need to use evaluation.
During benchmark, the pre-trained models need other downstream tasks to evaluate the performance, e.g. classification, detection, segmentation, etc. It is recommended to run downstream tasks with other OpenMMLab repos, such as MMClassification or MMDetection, which have already implemented their own evaluation functionalities.
But MMSelfSup also implements some custom evaluation functionalities to support downstream tasks, shown as below:
It compute accuracy of knn classifier predictions, and is used in [KNN evaluation](https://github.com/open-mmlab/mmselfsup/blob/dev-1.x/tools/benchmarks/classification/knn_imagenet/test_knn.py#L179).