Residual Connections#
- class vision_architectures.utils.residuals.Residual(*args, **kwargs)[source]#
Bases:
ModuleA simple residual connection.
This has been saved as an nn.Module so that it can always be converted to a stochastic version if required.
- class vision_architectures.utils.residuals.StochasticDepthResidual(survival_prob=1.0, dropout_type='layer')[source]#
Bases:
ResidualThis class can be wrapped around a list of modules to randomly drop some of them during training.
- __init__(survival_prob=1.0, dropout_type='layer')[source]#
Initializes the StochasticDepthResidual module.
Use
dropout_type="layer"for most occasions as that implements true stochastic depth dropout as per SOTA papers. Use dropout_type=”neuron” only if you want to drop individual neurons.- Parameters:
survival_prob (
float) – Prbability that every layer / neuron will survive the residual connection. Defaults to 1.0.dropout_type (
Literal['layer','neuron']) – Defaults to “layer”.
- forward(new_value, old_value)[source]#
Drops the new value with a certain probability and scales the remaining value before adding it to the old value. See
Residualfor more details.- Parameters:
new_value (
Tensor) – New value to be added.old_value (
Tensor) – Old value to be added to.
- Returns:
Value after performing stochastic depth and adding the new value to the old value.
- vision_architectures.utils.residuals.add_stochastic_depth_dropout(module, *args, **kwargs)[source]#
Converts all instances of
Residualin a module toStochasticDepthResidual.
- vision_architectures.utils.residuals.remove_stochastic_depth_dropout(module, *args, **kwargs)[source]#
Converts all instances of
StochasticDepthResidualin a module toResidual.