RuntimeError: The size of tensor a (2) must match the size of tensor b (5) at non-singleton dimension 0
在跑一个网络训练的时候,使用nn.CosineEmbeddingLoss时遇到该报错。
我的输入两个大小维度是一致的,都是[5,5],为两个矩阵。
loss计算过程是当作第一个维度为batch的,所以这里的loss会出问题。
最后用.view(1,-1)解决问题,把第一维变为batchsize的1。