Shortcuts

Note

You are reading the documentation for MMOCR 0.x, which will soon be deprecated by the end of 2022. We recommend you upgrade to MMOCR 1.0 to enjoy fruitful new features and better performance brought by OpenMMLab 2.0. Check out the maintenance plan, changelog, code and documentation of MMOCR 1.0 for more details.

Source code for mmocr.datasets.ner_dataset

# Copyright (c) OpenMMLab. All rights reserved.
from mmdet.datasets.builder import DATASETS

from mmocr.core.evaluation.ner_metric import eval_ner_f1
from mmocr.datasets.base_dataset import BaseDataset


[docs]@DATASETS.register_module() class NerDataset(BaseDataset): """Custom dataset for named entity recognition tasks. Args: ann_file (txt): Annotation file path. loader (dict): Dictionary to construct loader to load annotation infos. pipeline (list[dict]): Processing pipeline. test_mode (bool, optional): If True, try...except will be turned off in __getitem__. """
[docs] def prepare_train_img(self, index): """Get training data and annotations after pipeline. Args: index (int): Index of data. Returns: dict: Training data and annotation after pipeline with new keys \ introduced by pipeline. """ ann_info = self.data_infos[index] return self.pipeline(ann_info)
[docs] def evaluate(self, results, metric=None, logger=None, **kwargs): """Evaluate the dataset. Args: results (list): Testing results of the dataset. metric (str | list[str]): Metrics to be evaluated. logger (logging.Logger | str | None): Logger used for printing related information during evaluation. Default: None. Returns: info (dict): A dict containing the following keys: 'acc', 'recall', 'f1-score'. """ gt_infos = list(self.data_infos) eval_results = eval_ner_f1(results, gt_infos) return eval_results
Read the Docs v: v0.6.3
Versions
latest
stable
v0.6.3
v0.6.2
v0.6.1
v0.6.0
v0.5.0
v0.4.1
v0.4.0
v0.3.0
v0.2.1
v0.2.0
v0.1.0
dev-1.x
Downloads
On Read the Docs
Project Home
Builds

Free document hosting provided by Read the Docs.