自己学习的总结,有不对的地方欢迎指正,感谢各位
一、损失函数:
1.简介:
Loss Function : torch.nn — PyTorch 2.2 documentationhttps://pytorch.org/docs/stable/nn.html#loss-functions
本节中主要讲了:
nn.L1Loss、nn.MSELoss、 nn.CrossEntropyLoss(链接可以直接跳转)
2.代码:
# 损失函数与反向传播
import torch
from torch.nn import L1Loss
from torch import nn
inputs = torch.tensor([1, 2, 3], dtype=torch.float32)
targets = torch.tensor([1, 2, 5], dtype=torch.float32)
print("inputs: " + str(inputs.shape)) # 格式显示
print("targets: " + str(targets.shape))
inputs = torch.reshape(inputs, (1, 1, 1, 3)) # batch_size, channel, 行, 列
targets = torch.