pub struct DropPath {
pub drop_prob: f64,
/* private fields */
}Expand description
DropPath (Stochastic Depth) regularization.
Randomly drops entire paths in residual networks during training. At test time, paths are always kept but scaled by (1 - drop_prob).
§Example
use tensorlogic_train::DropPath;
use scirs2_core::ndarray::Array2;
use scirs2_core::random::{StdRng, SeedableRng};
let drop_path = DropPath::new(0.1).unwrap(); // 10% drop probability
let mut rng = StdRng::seed_from_u64(42);
let residual = Array2::ones((4, 8));
// Training mode: randomly drop
let output = drop_path.apply(&residual.view(), true, &mut rng).unwrap();
// Inference mode: scale by keep probability
let output_test = drop_path.apply(&residual.view(), false, &mut rng).unwrap();Fields§
§drop_prob: f64Probability of dropping the path (0.0 to 1.0).
Implementations§
Source§impl DropPath
impl DropPath
Sourcepub fn new(drop_prob: f64) -> TrainResult<Self>
pub fn new(drop_prob: f64) -> TrainResult<Self>
Sourcepub fn apply(
&self,
path: &ArrayView2<'_, f64>,
training: bool,
rng: &mut StdRng,
) -> TrainResult<Array2<f64>>
pub fn apply( &self, path: &ArrayView2<'_, f64>, training: bool, rng: &mut StdRng, ) -> TrainResult<Array2<f64>>
Sourcepub fn apply_batch(
&self,
paths: &ArrayView2<'_, f64>,
training: bool,
rng: &mut StdRng,
) -> TrainResult<Array2<f64>>
pub fn apply_batch( &self, paths: &ArrayView2<'_, f64>, training: bool, rng: &mut StdRng, ) -> TrainResult<Array2<f64>>
Sourcepub fn keep_probability(&self) -> f64
pub fn keep_probability(&self) -> f64
Get the keep probability.
Sourcepub fn set_drop_prob(&mut self, drop_prob: f64) -> TrainResult<()>
pub fn set_drop_prob(&mut self, drop_prob: f64) -> TrainResult<()>
Set new drop probability.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for DropPath
impl RefUnwindSafe for DropPath
impl Send for DropPath
impl Sync for DropPath
impl Unpin for DropPath
impl UnwindSafe for DropPath
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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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