pub struct Normalization { /* private fields */ }Expand description
Per-channel (x - mean) / std on 0–255 pixel values, in RGB order.
It applies to the colour channels of the destination; an alpha channel
always maps as NormalizationPreset::Unsigned. A Grey destination uses
the first channel’s coefficients.
Implementations§
Source§impl Normalization
impl Normalization
Sourcepub const fn preset(p: NormalizationPreset) -> Self
pub const fn preset(p: NormalizationPreset) -> Self
The coefficients of a named preset.
Sourcepub const fn imagenet() -> Self
pub const fn imagenet() -> Self
ImageNet mean [123.675, 116.28, 103.53], std [58.395, 57.12, 57.375].
Sourcepub fn mean_std(mean: &[f32], std: &[f32]) -> Result<Self>
pub fn mean_std(mean: &[f32], std: &[f32]) -> Result<Self>
Explicit coefficients on the 0–255 scale: one value (every channel) or three (RGB).
§Errors
Error::InvalidArgument for another count, a non-finite mean, or
a std that is not finite and positive.
use edgefirst_tensor::Normalization;
assert_eq!(Normalization::mean_std(&[0.0], &[255.0]).unwrap(), Normalization::unsigned());
assert!(Normalization::mean_std(&[0.0], &[0.0]).is_err());
assert!(Normalization::mean_std(&[0.0], &[-1.0]).is_err());Sourcepub fn unit_mean_std(mean: &[f32], std: &[f32], scale: f64) -> Result<Self>
pub fn unit_mean_std(mean: &[f32], std: &[f32], scale: f64) -> Result<Self>
Coefficients on the 0–1 scale, as Hugging Face and torchvision write
them; scaled by scale (usually 255) onto the 0–255 scale in f64.
§Errors
As for mean_std.
use edgefirst_tensor::Normalization;
let n = Normalization::unit_mean_std(&[0.5], &[0.5], 255.0).unwrap();
assert_eq!(n, Normalization::signed());Sourcepub fn std(&self) -> [f32; 3]
pub fn std(&self) -> [f32; 3]
The per-channel standard deviation, RGB order, on the 0–255 scale.
Sourcepub fn as_preset(&self) -> Option<NormalizationPreset>
pub fn as_preset(&self) -> Option<NormalizationPreset>
The preset with exactly these coefficients, if any.
Trait Implementations§
Source§impl Clone for Normalization
impl Clone for Normalization
impl Copy for Normalization
Source§impl Debug for Normalization
impl Debug for Normalization
Source§impl Default for Normalization
impl Default for Normalization
Source§impl From<NormalizationPreset> for Normalization
impl From<NormalizationPreset> for Normalization
Source§fn from(p: NormalizationPreset) -> Self
fn from(p: NormalizationPreset) -> Self
Source§impl PartialEq for Normalization
impl PartialEq for Normalization
impl StructuralPartialEq for Normalization
Auto Trait Implementations§
impl Freeze for Normalization
impl RefUnwindSafe for Normalization
impl Send for Normalization
impl Sync for Normalization
impl Unpin for Normalization
impl UnsafeUnpin for Normalization
impl UnwindSafe for Normalization
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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 more