MCPcopy Create free account
hub / github.com/Sirwenhao/Deep-Learning-Notes / drop_path

Function drop_path

CV/Pytorch_classification/EfficientNet/model.py:28–44  ·  view source on GitHub ↗

Drop paths (Stochastic Depth) per sample (when applied in main path of residual blocks). "Deep Networks with Stochastic Depth", https://arxiv.org/pdf/1603.09382.pdf This function is taken from the rwightman. It can be seen here: https://github.com/rwightman/pytorch-image-models

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

Source from the content-addressed store, hash-verified

26 return new_ch
27
28def drop_path(x, drop_prob: float= 0., training: bool = False):
29 """
30 Drop paths (Stochastic Depth) per sample (when applied in main path of residual blocks).
31 "Deep Networks with Stochastic Depth", https://arxiv.org/pdf/1603.09382.pdf
32
33 This function is taken from the rwightman.
34 It can be seen here:
35 https://github.com/rwightman/pytorch-image-models/blob/master/timm/models/layers/drop.py#L140
36 """
37 if drop_prob == 0. or not training:
38 return x
39 keep_prob = 1 - drop_prob
40 shape = (x.shape[0], ) + (1, ) * (x.dim - 1) # work with diff dim tensors, not just 2D ConvNets
41 random_tensor = keep_prob + torch.rand(shape, dtype=x.dtype, device=x.device)
42 random_tensor.floor_() # binaize
43 output = x.div(keep_prob) * random_tensor
44 return output
45
46class DropPath(nn.Module):
47 """

Callers 1

forwardMethod · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected