bili上李沐大神的d2l中的损失函数的理解
def loss(inputs, targets):
? ? return F.cross_entropy(inputs, targets, reduction='none')
如果inputs時(shí)4維度,? 首先是對(duì)inputs的第二維度上進(jìn)行取最大值的下標(biāo),效果就是輸出結(jié)果就會(huì)降一個(gè)維度 ? 也就是 ? 第一個(gè)維度是bath_size ? 不變
第二 ?三維度的值發(fā)生改變 ? 假如輸入的第二個(gè)維度是21,則第二三維度的值就在0~21之間 ? ?這個(gè)挺好用的 ? 哈哈哈
以下代碼可以驗(yàn)證這個(gè)說(shuō)法:
import torch
import torchvision
from torch import nn
from torch.nn import functional as F
from d2l import torch as d2l
X = torch.rand(size=(64,21,320,480))
Y = torch.rand(size=(64,21,320,480))
print(X.shape)
print(Y.shape)
def loss(inputs, targets):
? ? return F.cross_entropy(inputs, targets, reduction='none')
output = loss(X, Y)
print(output.shape)
總結(jié)
以上是生活随笔為你收集整理的bili上李沐大神的d2l中的损失函数的理解的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: amoled下载_AMOLED的完整形式
- 下一篇: Dev 与 Ops 互怼 | 科普一下