Hi, I have this code:
class Decoder(nn.ConvTranspose1d):
"""A decoder layer that consists of ConvTranspose1d.
Arguments
---------
*args : tuple
**kwargs : dict
Arguments passed through to nn.ConvTranspose1d
Example
-------
>>> x = torch.randn(2, 100, 1000)
>>> decoder = Decoder(kernel_size=4, in_channels=100, out_channels=1)
>>> h = decoder(x)
>>> h.shape
torch.Size([2, 1003])
"""
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
def forward(self, x):
"""Return the decoded output.
Arguments
---------
x : torch.Tensor
Input tensor with dimensionality [B, N, L].
where, B = Batchsize,
N = number of filters
L = time points
Returns
-------
out : torch.Tensor
The decoded outputs.
"""
if x.dim() not in [2, 3]:
print("heeehee")
x = super().forward(x if x.dim() == 3 else torch.unsqueeze(x, 1))
if torch.squeeze(x).dim() == 1:
x = torch.squeeze(x, dim=1)
else:
x = torch.squeeze(x)
return x
decoder = Decoder(100, 100, 4)
torch.jit.script(decoder)
And I’m getting this error:
RuntimeError:
'Tensor' object has no attribute or method 'forward'.:
File "/var/folders/7p/pb1c1byn4j7b1ryyh67rh9gc0000gp/T/ipykernel_34769/3603230582.py", line 42
print("heeehee")
x = super().forward(x if x.dim() == 3 else torch.unsqueeze(x, 1))
~~~~~~~~~~~~~ <--- HERE
Why does TorchScript say super()
is a Tensor?
Thanks!