Skip to content

Instantly share code, notes, and snippets.

@khakhlyuk
Created December 6, 2019 16:10
Show Gist options
  • Select an option

  • Save khakhlyuk/0e0e360849a7067dddfb9db9cd49e256 to your computer and use it in GitHub Desktop.

Select an option

Save khakhlyuk/0e0e360849a7067dddfb9db9cd49e256 to your computer and use it in GitHub Desktop.
Lambda Layer Pytorch
class Lambda(nn.Module):
def __init__(self, func):
super().__init__()
self.func = func
def forward(self, x):
return self.func(x)
# use
Lambda(lambda x: x.view(x.size(0), -1))
Lambda(lambda x: F.Relu(x[:, :, ::2, ::2]))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment