pytorch模型中的前进步骤问题

Problem with forward step in pytorch model

回溯说:

* Epoch 1/20
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-24-4f0f868c6227> in <module>()
      1 max_epochs = 20
      2 optim = torch.optim.Adam(model.parameters(), lr=1e-3)
----> 3 train(model, optim, bce_loss, max_epochs, data_tr, data_val)

2 frames
/usr/local/lib/python3.6/dist-packages/torch/nn/modules/module.py in _call_impl(self, *input, **kwargs)
    725             result = self._slow_forward(*input, **kwargs)
    726         else:
--> 727             result = self.forward(*input, **kwargs)
    728         for hook in itertools.chain(
    729                 _global_forward_hooks.values(),

TypeError: forward() takes 2 positional arguments but 3 were given 

但是在我的网络的火车部分我没有传递超过两个参数(包括自我参数) 这是 link to my code

也许问题不在训练中

您的模型有子模块,您(隐含地)使用多个参数调用 forward

x = self.dec_conv3(self.unpool3(x, indices3))

您的 unpool 只是 MaxPool 层 - 它们不需要两个输入参数。