(self, x, drop_prob: float = 0.0, training: bool = False, scale_by_keep: bool = True)
| 34 | raise ValueError("Drop path prob should be between 0 and 1.") |
| 35 | |
| 36 | def drop_path(self, x, drop_prob: float = 0.0, training: bool = False, scale_by_keep: bool = True): |
| 37 | if drop_prob == 0.0 or not training: |
| 38 | return x |
| 39 | keep_prob = 1 - drop_prob |
| 40 | shape = (x.shape[0],) + (1,) * (x.ndim - 1) |
| 41 | random_tensor = x.new_empty(shape).bernoulli_(keep_prob) |
| 42 | if keep_prob > 0.0 and scale_by_keep: |
| 43 | random_tensor.div_(keep_prob) |
| 44 | return x * random_tensor |
| 45 | |
| 46 | def forward(self, x): |
| 47 | return self.drop_path(x, self.drop_prob, self.training, self.scale_by_keep) |
no test coverage detected