Add LambdaLayer
This commit is contained in:
parent
e61ae73749
commit
8227525c82
@ -1 +1,3 @@
|
||||
"""ProtoTorch modules."""
|
||||
|
||||
from .utils import LambdaLayer
|
||||
|
16
prototorch/modules/utils.py
Normal file
16
prototorch/modules/utils.py
Normal file
@ -0,0 +1,16 @@
|
||||
"""ProtoTorch utility modules."""
|
||||
|
||||
import torch
|
||||
|
||||
|
||||
class LambdaLayer(torch.nn.Module):
|
||||
def __init__(self, fn, name=None):
|
||||
super().__init__()
|
||||
self.fn = fn
|
||||
self.name = name or fn.__name__ # lambda fns get <lambda>
|
||||
|
||||
def forward(self, *args, **kwargs):
|
||||
return self.fn(*args, **kwargs)
|
||||
|
||||
def extra_repr(self):
|
||||
return self.name
|
Loading…
Reference in New Issue
Block a user