MCPcopy Create free account
hub / github.com/OpenDriveLab/ReSim / drop_path

Function drop_path

SwissArmyTransformer/examples/yolos/models/layers/drop.py:140–157  ·  view source on GitHub ↗

Drop paths (Stochastic Depth) per sample (when applied in main path of residual blocks). This is the same as the DropConnect impl I created for EfficientNet, etc networks, however, the original name is misleading as 'Drop Connect' is a different form of dropout in a separate paper... Se

(x, drop_prob: float = 0., training: bool = False)

Source from the content-addressed store, hash-verified

138
139
140def drop_path(x, drop_prob: float = 0., training: bool = False):
141 """Drop paths (Stochastic Depth) per sample (when applied in main path of residual blocks).
142
143 This is the same as the DropConnect impl I created for EfficientNet, etc networks, however,
144 the original name is misleading as 'Drop Connect' is a different form of dropout in a separate paper...
145 See discussion: https://github.com/tensorflow/tpu/issues/494#issuecomment-532968956 ... I've opted for
146 changing the layer and argument names to 'drop path' rather than mix DropConnect as a layer name and use
147 'survival rate' as the argument.
148
149 """
150 if drop_prob == 0. or not training:
151 return x
152 keep_prob = 1 - drop_prob
153 shape = (x.shape[0],) + (1,) * (x.ndim - 1) # work with diff dim tensors, not just 2D ConvNets
154 random_tensor = keep_prob + torch.rand(shape, dtype=x.dtype, device=x.device)
155 random_tensor.floor_() # binarize
156 output = x.div(keep_prob) * random_tensor
157 return output
158
159
160class DropPath(nn.Module):

Callers 1

forwardMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected