这个是从代码层面,详细了解损失函数!
CrossEntropyLoss
import torch import torch.nn as nn # 实际中遇到的 outputs = torch.tensor([[0.5870, 0.4130], [0.6517, 0.3483], [0.4455, 0.5545], [0.4786, 0.5214]], requires_grad=True) y_train_tensor = torch.tensor([0, 0, 1, 1]) print(outputs) print(y_train_tensor) # 使用 CrossEntropyLoss 计算损失 criterion = nn.CrossEntropyLoss() loss = criterion(outputs, y_train_tensor) print('Outputs:', outputs) print('Labels:', y_train_tensor) print('Loss:', loss)
,
标签:函数,outputs,代码,torch,损失,CrossEntropyLoss,train,print,tensor From: https://www.cnblogs.com/mxleader/p/18220796