问题描述:
在forward中明明正确数量的参数,却报错:forward() takes 2 positional arguments but 3 were given;
问题分析:
使用nn.Sequential()定义的网络,只接受单输入
例如:
self.backbone=nn.Sequential(nn.lstm(input_size=20, hidden_size=40, num_layers=2),
nn.linear(in_features=40, out_features=2))
def forward(self, input):
h0 = torch.randn(hidden_layers, batch_size, hidden)
c0 = torch.randn(hidden_layers, batch_size, hidden)
output, _ = self.backbone(input) (对)文章来源:https://www.toymoban.com/news/detail-509891.html
output, _ = self.backbone(input, (h0, c0) (错误,因为nn.Sequential()定义的网络,只接受单输入)文章来源地址https://www.toymoban.com/news/detail-509891.html
到了这里,关于forward() takes 2 positional arguments but 3 were given的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!