pub struct ToBatch;Expand description
A struct for converting image data into batched tensor format.
This struct provides methods for validating input data and converting images into a batched tensor format suitable for processing in the OCR pipeline.
Implementations§
Source§impl ToBatch
impl ToBatch
Sourcepub fn validate_inputs(
&self,
imgs: &[Vec<f32>],
shapes: &[(usize, usize, usize)],
) -> Result<(), OCRError>
pub fn validate_inputs( &self, imgs: &[Vec<f32>], shapes: &[(usize, usize, usize)], ) -> Result<(), OCRError>
Validates the input images and their shapes.
This method checks that the images and shapes arrays have the same length, that all images have the correct number of elements for their shapes, and that all dimensions are greater than zero.
§Arguments
imgs- A slice of vectors of f32 values representing the images.shapes- A slice of tuples representing the shapes of the images (channels, height, width).
§Returns
A Result indicating success or an OCRError if validation fails.
Sourcepub fn apply(
&self,
imgs: &[Vec<f32>],
shapes: &[(usize, usize, usize)],
) -> Result<Vec<f32>, OCRError>
pub fn apply( &self, imgs: &[Vec<f32>], shapes: &[(usize, usize, usize)], ) -> Result<Vec<f32>, OCRError>
Applies the batch conversion to the input images and shapes.
This method validates the inputs, then converts the images into a batched tensor format. If all images have the same dimensions, it uses a more efficient contiguous copying method. Otherwise, it uses a method that handles mixed dimensions.
§Arguments
imgs- A slice of vectors of f32 values representing the images.shapes- A slice of tuples representing the shapes of the images (channels, height, width).
§Returns
A Result containing a vector of f32 values representing the batched tensor, or an OCRError if the operation fails.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for ToBatch
impl RefUnwindSafe for ToBatch
impl Send for ToBatch
impl Sync for ToBatch
impl Unpin for ToBatch
impl UnwindSafe for ToBatch
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<R, P> ReadPrimitive<R> for P
impl<R, P> ReadPrimitive<R> for P
Source§fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
ReadEndian::read_from_little_endian().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.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.