pytorch 错误:
1.ValueError: Using a target size (torch.Size([442])) that is different to the input size (torch.Size([442, 1])) is deprecated. Please ensure they have the same size.
报错信息说输入的尺寸和目标尺寸不同,导致的错误。
在前馈函数中 添加x = x.squeeze(-1) 达到降维就可以解决该问题。
2.UserWarning: size_average and reduce args will be deprecated, please use reduction=‘sum’ instead. warnings.warn(warning.format(ret))
这是pytorch版本迭代引出的问题, 修改如下
criterion = torch.nn.BCELoss(size_average=True)
#改为:
criterion = torch.nn.BCELoss(reduction='mean')
criterion = torch.nn.BCELoss(size_average=False)
#改为:
criterion = torch.nn.BCELoss(reduction='sum')
#其它loss_function更改方法类似