pub struct DropBlock {
pub block_size: usize,
pub drop_prob: f64,
/* private fields */
}Expand description
DropBlock regularization.
Drops contiguous blocks of activations in convolutional feature maps. This is more effective than standard dropout for CNNs because it forces the network to learn more distributed representations.
Fields§
§block_size: usizeSize of the block to drop (e.g., 7 for 7x7 blocks)
drop_prob: f64Probability that a block center will be chosen for dropping
Implementations§
Source§impl DropBlock
impl DropBlock
Sourcepub fn new(block_size: usize, drop_prob: f64) -> TrainResult<Self>
pub fn new(block_size: usize, drop_prob: f64) -> TrainResult<Self>
Create a new DropBlock regularizer.
§Arguments
block_size- Size of the block to drop (must be odd and >= 1)drop_prob- Probability of dropping a block (0.0 to 1.0)
§Returns
A new DropBlock instance or an error if parameters are invalid.
§Example
use tensorlogic_train::DropBlock;
let dropblock = DropBlock::new(7, 0.1).unwrap();Sourcepub fn set_drop_prob(&mut self, drop_prob: f64) -> TrainResult<()>
pub fn set_drop_prob(&mut self, drop_prob: f64) -> TrainResult<()>
Set the drop probability (useful for scheduling).
§Arguments
drop_prob- New drop probability (0.0 to 1.0)
Sourcepub fn apply(
&self,
activations: &ArrayView2<'_, f64>,
training: bool,
rng: &mut StdRng,
) -> TrainResult<Array2<f64>>
pub fn apply( &self, activations: &ArrayView2<'_, f64>, training: bool, rng: &mut StdRng, ) -> TrainResult<Array2<f64>>
Apply DropBlock to activations.
§Arguments
activations- Input activation map (height × width)training- Whether in training mode (drops blocks) or inference mode (no dropping)rng- Random number generator
§Returns
Activation map with blocks dropped (if training) or unchanged (if inference)
§Algorithm
- Sample Bernoulli mask for each position (potential block centers)
- Expand each selected center to a block of size block_size × block_size
- Zero out the selected blocks
- Normalize by keep_prob to maintain expected value
Trait Implementations§
Auto Trait Implementations§
impl Freeze for DropBlock
impl RefUnwindSafe for DropBlock
impl Send for DropBlock
impl Sync for DropBlock
impl Unpin for DropBlock
impl UnwindSafe for DropBlock
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