MCPcopy Create free account
hub / github.com/geekcomputers/Python / DropPath

Class DropPath

ML/src/python/neuralforge/nn/modules.py:106–119  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

104 return x * self.weight[None, :, None, None] + self.bias[None, :, None, None]
105
106class DropPath(nn.Module):
107 def __init__(self, drop_prob=0.0):
108 super().__init__()
109 self.drop_prob = drop_prob
110
111 def forward(self, x):
112 if self.drop_prob == 0.0 or not self.training:
113 return x
114 keep_prob = 1 - self.drop_prob
115 shape = (x.shape[0],) + (1,) * (x.ndim - 1)
116 random_tensor = keep_prob + torch.rand(shape, dtype=x.dtype, device=x.device)
117 random_tensor.floor_()
118 output = x.div(keep_prob) * random_tensor
119 return output
120
121class GlobalAvgPool2d(nn.Module):
122 def __init__(self):

Callers 2

__init__Method · 0.85
__init__Method · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected