(x, drop_prob: float = 0.0, training: bool = False)
| 7 | |
| 8 | |
| 9 | def drop_path(x, drop_prob: float = 0.0, training: bool = False): |
| 10 | if drop_prob == 0.0 or not training: |
| 11 | return x |
| 12 | keep_prob = 1 - drop_prob |
| 13 | shape = (x.shape[0],) + (1,) * (x.ndim - 1) # work with diff dim tensors, not just 2D ConvNets |
| 14 | random_tensor = x.new_empty(shape).bernoulli_(keep_prob) |
| 15 | if keep_prob > 0.0: |
| 16 | random_tensor.div_(keep_prob) |
| 17 | output = x * random_tensor |
| 18 | return output |
| 19 | |
| 20 | |
| 21 | class DropPath(nn.Module): |