在使用pytorch训练模型时报,以下错误:
RuntimeError: non-empty 3D or 4D input tensor expected but got ndim: 4
当把一个空的张量传递给池化层时,就会引发该错误
pool = nn.MaxPool2d(2)
y = torch.tensor([[[[]]]])
out = pool(y)
RuntimeError: non-empty 3D or 4D input tensor expected but got ndim: 4
因此检查传递到池化层的张量,确保非空