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)
| 26 | return new_ch |
| 27 | |
| 28 | def 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 | |
| 46 | class DropPath(nn.Module): |
| 47 | """ |