pub struct GroupNorm { /* private fields */ }Expand description
Group Normalization (Wu & He, 2018).
Divides channels into groups and normalizes within each group.
Unlike BatchNorm, GroupNorm is independent of batch size, making it
suitable for small batch training (e.g., object detection, segmentation).
§Shape
- Input:
(N, C, *)where C must be divisible bynum_groups - Output: Same as input
§Example
ⓘ
use aprender::nn::{GroupNorm, Module};
use aprender::autograd::Tensor;
let norm = GroupNorm::new(32, 256); // 32 groups, 256 channels
let x = Tensor::randn(&[4, 256, 14, 14]);
let y = norm.forward(&x);Implementations§
Source§impl GroupNorm
impl GroupNorm
Sourcepub fn with_eps(num_groups: usize, num_channels: usize, eps: f32) -> Self
pub fn with_eps(num_groups: usize, num_channels: usize, eps: f32) -> Self
Create GroupNorm with custom epsilon.
Sourcepub fn without_affine(num_groups: usize, num_channels: usize) -> Self
pub fn without_affine(num_groups: usize, num_channels: usize) -> Self
Create GroupNorm without learnable parameters.
Sourcepub fn num_groups(&self) -> usize
pub fn num_groups(&self) -> usize
Get number of groups.
Sourcepub fn num_channels(&self) -> usize
pub fn num_channels(&self) -> usize
Get number of channels.
Trait Implementations§
Source§impl Module for GroupNorm
impl Module for GroupNorm
Source§fn parameters_mut(&mut self) -> Vec<&mut Tensor>
fn parameters_mut(&mut self) -> Vec<&mut Tensor>
Get mutable references to all learnable parameters. Read more
Source§fn refresh_caches(&mut self)
fn refresh_caches(&mut self)
Refresh any cached computations after parameters have been modified. Read more
Source§fn num_parameters(&self) -> usize
fn num_parameters(&self) -> usize
Get the number of learnable parameters.
Auto Trait Implementations§
impl Freeze for GroupNorm
impl !RefUnwindSafe for GroupNorm
impl Send for GroupNorm
impl Sync for GroupNorm
impl Unpin for GroupNorm
impl UnsafeUnpin for GroupNorm
impl !UnwindSafe for GroupNorm
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> 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 more