Target and input must have the same number of elements.

Target and input must have the same number of elements._第1张图片

出现这个报错的原因是,交叉熵损失函数torch.nn.BCELoss()=F.binary_cross_entropy(),要求输入input和目标target 必须形状一致,并且都是浮点数 :

Input: (N, *)(N,∗) where *∗ means, any number of additional dimensions

Target: (N, *)(N,∗), same shape as the input

Output: scalar. If reduction is 'none', then (N, *)(N,∗), same shape as input.

上方的报错可见,目标是一维的,含元素个数655360。而输入是一维的,含元素个数327680。所以只要在网络中把二者元素个数改成一致即可。

 

你可能感兴趣的:(报错解决)