mr2.nn.DropPath

class mr2.nn.DropPath[source]

Bases: Module

Drop path or stochastic depth.

Drops full samples from batch with probability droprate. Should be used in the main path of a Resblock.

References

[HUANG16]

Huang, G., Sun, Y., Liu, Z., Sedra, D., & Weinberger, K. Q. Deep networks with stochastic depth. ECCV 2016. https://link.springer.com/chapter/10.1007/978-3-319-46493-0_39

__init__(droprate: float = 0.0, scale_by_keep: bool = False) → None[source]

Initialize the DropPath module.

Parameters:
  • droprate (float, default: 0.0) – Drop probability in [0, 1]. A value of 1 drops all samples during training.

  • scale_by_keep (bool, default: False) – If True, the kept samples are scaled by \(1/(1-droprate)\). During training, a droprate of 1 gives zero output regardless of this setting.

Raises:

ValueError – If droprate is outside [0, 1].

__call__(x: Tensor) → Tensor[source]

Apply DropPath.

Parameters:

x (Tensor) – Input tensor

Returns:

Tensor with batch samples randomly dropped

forward(x: Tensor) → Tensor[source]

Apply DropPath.