The sine activation function, which becomes useful recently, is missing in pytorch.nn. How to remedy this?
Hi @AlphaBetaGamma96 thanks a lot, but can this be used as an activation function directly by writing torch.sin in torch.nn?
You can just do,
you don’t have to initialize from
torch.nn, autograd will track the gradient.
but in the following code:
import torch.nn as nn
it doesn’t seem possible to replace nn.Sigmoid() with torch.sin(x) or sth similar directly?
If you want to define your model within a
nn.Sequential object, you can either
- re-define your model as an
nn.Moduleobject and you can use
torch.sin(x)like I stated above
- Define an
torch.sinand pass it to the
class Sin(nn.Module): def __init__(self): pass def forward(self, x): return torch.sin(x)
many thanks! I tried the 2nd method writing the same class only to get the following error message:
‘Sin’ object has no attribute ‘_parameters’
Try deleting the
class Sin(Module): def forward(self, input: Tensor) -> Tensor: return torch.sin(input)