pub struct CTCLabelDecode { /* private fields */ }Expand description
A decoder for CTC (Connectionist Temporal Classification) based text recognition models.
This struct extends BaseRecLabelDecode to provide specialized decoding for CTC models,
which include a blank token that needs to be handled specially during decoding.
§Fields
base- The base decoder that handles character mapping and basic decoding operationsblank_index- The index of the blank token in the character vocabulary
Implementations§
Source§impl CTCLabelDecode
impl CTCLabelDecode
Sourcepub fn from_string_list(
character_list: Option<&[String]>,
use_space_char: bool,
has_explicit_blank: bool,
) -> CTCLabelDecode
pub fn from_string_list( character_list: Option<&[String]>, use_space_char: bool, has_explicit_blank: bool, ) -> CTCLabelDecode
Creates a new CTCLabelDecode instance from a list of strings.
§Arguments
character_list- An optional slice of strings containing the character vocabulary. Only the first character of each string is used. If None, a default alphanumeric character set is used.use_space_char- Whether to include a space character in the vocabulary.has_explicit_blank- Whether the character list already includes a blank token.
§Returns
A new CTCLabelDecode instance.
Sourcepub fn get_blank_index(&self) -> usize
pub fn get_blank_index(&self) -> usize
Sourcepub fn get_character_list(&self) -> &[char]
pub fn get_character_list(&self) -> &[char]
Gets the character list used by this decoder.
§Returns
A slice containing the characters in the vocabulary.
Sourcepub fn get_character_count(&self) -> usize
pub fn get_character_count(&self) -> usize
Gets the number of characters in the vocabulary.
§Returns
The number of characters in the vocabulary.
Sourcepub fn apply_with_positions(
&self,
pred: &ArrayBase<OwnedRepr<f32>, Dim<[usize; 3]>>,
) -> (Vec<String>, Vec<f32>, Vec<Vec<f32>>, Vec<Vec<usize>>, Vec<usize>)
pub fn apply_with_positions( &self, pred: &ArrayBase<OwnedRepr<f32>, Dim<[usize; 3]>>, ) -> (Vec<String>, Vec<f32>, Vec<Vec<f32>>, Vec<Vec<usize>>, Vec<usize>)
Applies the CTC decoder to a tensor of model predictions with character position tracking.
This method handles the special requirements of CTC decoding and additionally tracks the timestep positions of each character for word box generation.
§Arguments
pred- A 3D tensor containing the model predictions.
§Returns
A tuple containing:
- A vector of decoded text strings
- A vector of confidence scores for each text string
- A vector of character positions (normalized 0.0-1.0) for each text string
- A vector of column indices for each character in each text string
- A vector of sequence lengths (total columns) for each text string
Sourcepub fn apply(
&self,
pred: &ArrayBase<OwnedRepr<f32>, Dim<[usize; 3]>>,
) -> (Vec<String>, Vec<f32>)
pub fn apply( &self, pred: &ArrayBase<OwnedRepr<f32>, Dim<[usize; 3]>>, ) -> (Vec<String>, Vec<f32>)
Applies the CTC decoder to a tensor of model predictions.
This method handles the special requirements of CTC decoding:
- Removing blank tokens
- Removing consecutive duplicate characters
- Converting indices to characters
- Calculating confidence scores
§Arguments
pred- A 3D tensor containing the model predictions.
§Returns
A tuple containing:
- A vector of decoded text strings
- A vector of confidence scores for each text string
Trait Implementations§
Auto Trait Implementations§
impl Freeze for CTCLabelDecode
impl RefUnwindSafe for CTCLabelDecode
impl Send for CTCLabelDecode
impl Sync for CTCLabelDecode
impl Unpin for CTCLabelDecode
impl UnwindSafe for CTCLabelDecode
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.