1. 首页
  2. 数据库
  3. 其它
  4. nn.CrossEntropyLoss()

nn.CrossEntropyLoss()

上传者: 2021-02-01 12:22:07上传 PDF文件 30.74KB 热度 15次
用于多分类,直接写标签序号就可以:0,1,2. 预测需要维度与标签长度一致。 import torch import torch.nn as nn import math criterion = nn.CrossEntropyLoss() output = torch.randn(3, 5, requires_grad=True) label = torch.empty(3, dtype=torch.long).random_(5) loss = criterion(output, label) print(网络输出为3个5类:) print(output) print(要计算loss
下载地址
用户评论