diff options
author | Gustaf Rydholm <gustaf.rydholm@gmail.com> | 2022-09-27 23:16:33 +0200 |
---|---|---|
committer | Gustaf Rydholm <gustaf.rydholm@gmail.com> | 2022-09-27 23:16:33 +0200 |
commit | 626cf824526b00b18043315322f86789278939fa (patch) | |
tree | fffd36187cdc056011a2db2cb2b3016a4f720886 /text_recognizer/models/metrics/cer.py | |
parent | 9c7dbb9ca70858b870f74ecf595d3169f0cbc711 (diff) |
Refactor metrics
Diffstat (limited to 'text_recognizer/models/metrics/cer.py')
-rw-r--r-- | text_recognizer/models/metrics/cer.py | 23 |
1 files changed, 0 insertions, 23 deletions
diff --git a/text_recognizer/models/metrics/cer.py b/text_recognizer/models/metrics/cer.py deleted file mode 100644 index 238ecc3..0000000 --- a/text_recognizer/models/metrics/cer.py +++ /dev/null @@ -1,23 +0,0 @@ -"""Character Error Rate (CER).""" -from typing import Sequence - -import torch -import torchmetrics - - -class CharacterErrorRate(torchmetrics.CharErrorRate): - """Character error rate metric, allowing for tokens to be ignored.""" - - def __init__(self, ignore_tokens: Sequence[int], *args): - super().__init__(*args) - self.ignore_tokens = set(ignore_tokens) - - def update(self, preds: torch.Tensor, targets: torch.Tensor) -> None: - preds_l = [ - [t for t in pred if t not in self.ignore_tokens] for pred in preds.tolist() - ] - targets_l = [ - [t for t in target if t not in self.ignore_tokens] - for target in targets.tolist() - ] - super().update(preds_l, targets_l) |