pub struct Residual<F>(pub F);
Expand description
A residual connection around F
: F(x) + x
,
as introduced in Deep Residual Learning for Image Recognition.
Generics
F
: The underlying module to do a skip connection around.
Examples
let module: Residual<ReLU> = Default::default();
let x = Tensor1D::new([-2.0, -1.0, 0.0, 1.0, 2.0]);
let y = module.forward(x);
assert_eq!(y.data(), &[-2.0, -1.0, 0.0, 2.0, 4.0]);
Tuple Fields
0: F
Trait Implementations
sourceimpl<F: CanUpdateWithGradients> CanUpdateWithGradients for Residual<F>
impl<F: CanUpdateWithGradients> CanUpdateWithGradients for Residual<F>
sourcefn update<G: GradientProvider>(
&mut self,
grads: &mut G,
unused: &mut UnusedTensors
)
fn update<G: GradientProvider>(
&mut self,
grads: &mut G,
unused: &mut UnusedTensors
)
Pass through to F
’s CanUpdateWithGradients.
sourceimpl<F: LoadFromNpz> LoadFromNpz for Residual<F>
impl<F: LoadFromNpz> LoadFromNpz for Residual<F>
sourceimpl<T, F> Module<T> for Residual<F> where
T: Tensor<Dtype = f32>,
F: Module<T, Output = T>,
impl<T, F> Module<T> for Residual<F> where
T: Tensor<Dtype = f32>,
F: Module<T, Output = T>,
sourcefn forward(&self, x: T) -> Self::Output
fn forward(&self, x: T) -> Self::Output
Calls forward on F
and then adds x
to the result: F(x) + x
sourcefn forward_mut(&mut self, input: Input) -> Self::Output
fn forward_mut(&mut self, input: Input) -> Self::Output
Pass an Input
through the unit and produce Self::Output.
Can be implemented for multiple Input
types. Read more
sourceimpl<F: ResetParams> ResetParams for Residual<F>
impl<F: ResetParams> ResetParams for Residual<F>
sourcefn reset_params<R: Rng>(&mut self, rng: &mut R)
fn reset_params<R: Rng>(&mut self, rng: &mut R)
Pass through to F
’s ResetParams.
Auto Trait Implementations
impl<F> RefUnwindSafe for Residual<F> where
F: RefUnwindSafe,
impl<F> Send for Residual<F> where
F: Send,
impl<F> Sync for Residual<F> where
F: Sync,
impl<F> Unpin for Residual<F> where
F: Unpin,
impl<F> UnwindSafe for Residual<F> where
F: UnwindSafe,
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more