这是因为torch.nn.MSELoss()默认返回的是每个样本的MSE值之和,并且在计算总体损失时通常会将其除以样本数量来得到平均损失。在代码中,loss = criterion(y_pred.squeeze(), Y_train.squeeze())语句计算了y_pred和Y_train之间的MSE损失,然后通过调用item()方法获取了该批次训练样本的平均MSE损失。如果希望获取该批...
CATCH_RETURN_Tensor( autoopts =torch::nn::functional::MSELossFuncOptions(); ApplyReduction(opts, reduction); res =ResultTensor(torch::nn::functional::mse_loss(*input, *target, opts)); ) } If this is indeed incorrect, I would be happy to submit a fix in a PR, but am still figuring...