MCPcopy Create free account
hub / github.com/alinlab/SelfPatch / drop_path

Function drop_path

detection/backbone/vit_SelfPatch.py:27–35  ·  view source on GitHub ↗
(x, drop_prob: float = 0., training: bool = False)

Source from the content-addressed store, hash-verified

25
26
27def 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
38class DropPath(nn.Module):

Callers 1

forwardMethod · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected