Skip to content

Commit

Permalink
Add clip\clamp activation (qubvel#518)
Browse files Browse the repository at this point in the history
  • Loading branch information
Vozf authored Nov 26, 2021
1 parent a288d33 commit 4f94380
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions segmentation_models_pytorch/base/modules.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,15 @@ def forward(self, x):
return torch.argmax(x, dim=self.dim)


class Clamp(nn.Module):
def __init__(self, min=0, max=1):
super().__init__()
self.min, self.max = min, max

def forward(self, x):
return torch.clamp(x, self.min, self.max)


class Activation(nn.Module):

def __init__(self, name, **params):
Expand All @@ -95,6 +104,8 @@ def __init__(self, name, **params):
self.activation = ArgMax(**params)
elif name == 'argmax2d':
self.activation = ArgMax(dim=1, **params)
elif name == 'clamp':
self.activation = Clamp(**params)
elif callable(name):
self.activation = name(**params)
else:
Expand Down

0 comments on commit 4f94380

Please sign in to comment.