MCPcopy Create free account
hub / github.com/Project-MONAI/MONAI / drop_path

Method drop_path

monai/networks/layers/drop_path.py:36–44  ·  view source on GitHub ↗
(self, x, drop_prob: float = 0.0, training: bool = False, scale_by_keep: bool = True)

Source from the content-addressed store, hash-verified

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)

Callers 3

forwardMethod · 0.95
forward_part2Method · 0.80
forwardMethod · 0.80

Calls 1

new_emptyMethod · 0.80

Tested by

no test coverage detected