In the forward
function of your DropoutLayer
, when you enter the else
branch, there is no return. Therefore the following layer (flatten
) will have no input. However, as emphasized in the comments, that's not the actual problem.
The actual problem is that you are passing a numpy array to your Flatten
layer. A Minimal code to reproduce the problem would be :
nn.Flatten()(np.random.randn(5,5))
>>> TypeError: flatten() takes at most 1 argument (2 given)
However, I cannot explain why this layer behaves like that on a numpy tensor, the behavior of the flatten
function being much more understandable. I don't know what additional operations the layer performs.
torch.flatten(np.random.randn(5,5))
>>> TypeError: flatten(): argument 'input' (position 1) must be Tensor, not numpy.ndarray
Why this error is raised by your code is because in the forward pass, you create a numpy tensor, perform some operations, and return it instead of returning a tensor. If I may, you don't even touch the actual input tensor (in the first branch)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…