交叉熵是在分类任务中常用的一种损失函数,本文详细介绍了pytorch中是如何实现交叉熵的细节!!!
pytorch中的交叉熵函数为F.cross_entropy(input, target),本文以变化检测或语义分割中用到的数据模型为例:input的维度为[batchsize,classes,width,height],target的维度为[batchsize,width,height]。
- 随机生成模型数据
input = torch.rand([1, 2, 3, 3])
import numpy as np
target = np.random.randint(2, size=(1, 3, 3))
target = torch.from_numpy(target)
target = target.long()
print(target)
print(input)
# target
tensor([[[1, 1, 1],
[1, 1, 1],
[
1万+



被折叠的 条评论
为什么被折叠?



