Struct dfdx::nn::modules::DropoutOneIn
source · pub struct DropoutOneIn<const N: usize>;
Expand description
Does nothing as a Module, and calls dropout() as ModuleMut with probability 1.0 / N
.
To prevent programmer error, Module and ModuleMut are only implemented for specific tapes:
- Module requires that the input tensor has a NoneTape. i.e. that gradients are not being tracked.
- ModuleMut requires that the tensor has a OwnedTape. i.e. that the gradients are being tracked
That means the following will fail to compile:
ⓘ
let dropout: DropoutOneIn<2> = BuildModule::build(&dev);
let grads = dropout.alloc_grads();
dropout.forward(dev.zeros::<Rank1<5>>().trace(grads));
ⓘ
let mut dropout: DropoutOneIn<2> = Default::default();
dropout.forward_mut(dev.zeros::<Rank1<5>>());
Generics:
N
: p is set as1.0 / N
Examples:
let mut dropout: DropoutOneIn<2> = Default::default();
let grads = dropout.alloc_grads();
let x: Tensor<Rank2<2, 5>, f32, _> = dev.ones();
let r = dropout.forward_mut(x.trace(grads));
assert_eq!(r.array(), [[2.0, 2.0, 2.0, 0.0, 0.0], [2.0, 2.0, 0.0, 0.0, 2.0]]);
Trait Implementations§
source§impl<const N: usize> Clone for DropoutOneIn<N>
impl<const N: usize> Clone for DropoutOneIn<N>
source§fn clone(&self) -> DropoutOneIn<N>
fn clone(&self) -> DropoutOneIn<N>
Returns a copy of the value. Read more
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moresource§impl<const N: usize> Debug for DropoutOneIn<N>
impl<const N: usize> Debug for DropoutOneIn<N>
source§impl<const N: usize> Default for DropoutOneIn<N>
impl<const N: usize> Default for DropoutOneIn<N>
source§fn default() -> DropoutOneIn<N>
fn default() -> DropoutOneIn<N>
Returns the “default value” for a type. Read more