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,
) -> Self
pub fn from_string_list( character_list: Option<&[String]>, use_space_char: bool, has_explicit_blank: bool, ) -> Self
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(&self, pred: &Tensor3D) -> (Vec<String>, Vec<f32>)
pub fn apply(&self, pred: &Tensor3D) -> (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
Mutably borrows from an owned value. Read more
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>
Converts
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>
Converts
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>
The inverse inclusion map: attempts to construct
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
Checks if
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
Use with care! Same as
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
The inclusion map: converts
self to the equivalent element of its superset.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>
The inverse inclusion map: attempts to construct
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
Checks if
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
Use with care! Same as
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
The inclusion map: converts
self to the equivalent element of its superset.