From 7d759b6c0efcb58b5c7c6858d7dcbd2060992430 Mon Sep 17 00:00:00 2001 From: Gustaf Rydholm Date: Mon, 6 Jun 2022 23:03:20 +0200 Subject: Add lit conformer model --- text_recognizer/models/util.py | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 text_recognizer/models/util.py (limited to 'text_recognizer/models/util.py') diff --git a/text_recognizer/models/util.py b/text_recognizer/models/util.py new file mode 100644 index 0000000..cc0df3c --- /dev/null +++ b/text_recognizer/models/util.py @@ -0,0 +1,10 @@ +from typing import Union + +from torch import Tensor + + +def first_element(x: Tensor, element: Union[int, float], dim: int = 1) -> Tensor: + nonz = x == element + ind = ((nonz.cumsum(dim) == 1) & nonz).max(dim).indices + ind[ind == 0] = x.shape[dim] + return ind -- cgit v1.2.3-70-g09d2