Skip to main content

CTCLabelDecode

Struct CTCLabelDecode 

Source
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 operations
  • blank_index - The index of the blank token in the character vocabulary

Implementations§

Source§

impl CTCLabelDecode

Source

pub fn new(character_list: Option<&str>, use_space_char: bool) -> CTCLabelDecode

Creates a new CTCLabelDecode instance.

§Arguments
  • character_list - An optional string containing the character vocabulary. If None, a default alphanumeric character set is used.
  • use_space_char - Whether to include a space character in the vocabulary.
§Returns

A new CTCLabelDecode instance.

Source

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.

Source

pub fn get_blank_index(&self) -> usize

Gets the index of the blank token.

§Returns

The index of the blank token.

Source

pub fn get_character_list(&self) -> &[char]

Gets the character list used by this decoder.

§Returns

A slice containing the characters in the vocabulary.

Source

pub fn get_character_count(&self) -> usize

Gets the number of characters in the vocabulary.

§Returns

The number of characters in the vocabulary.

Source

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
Source

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:

  1. Removing blank tokens
  2. Removing consecutive duplicate characters
  3. Converting indices to characters
  4. 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§

Source§

impl Debug for CTCLabelDecode

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

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 more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<SS, SP> SupersetOf<SS> for SP
where SS: SubsetOf<SP>,

Source§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
Source§

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

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
Source§

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more