(x, drop_prob: float = 0., training: bool = False)
| 25 | |
| 26 | |
| 27 | def drop_path(x, drop_prob: float = 0., training: bool = False): |
| 28 | if drop_prob == 0. or not training: |
| 29 | return x |
| 30 | keep_prob = 1 - drop_prob |
| 31 | shape = (x.shape[0],) + (1,) * (x.ndim - 1) # work with diff dim tensors, not just 2D ConvNets |
| 32 | random_tensor = keep_prob + torch.rand(shape, dtype=x.dtype, device=x.device) |
| 33 | random_tensor.floor_() # binarize |
| 34 | output = x.div(keep_prob) * random_tensor |
| 35 | return output |
| 36 | |
| 37 | |
| 38 | class DropPath(nn.Module): |