>>> from torch import tensor >>> import torch.nn as nn >>> t1=tensor([[0.23],[0.33]]) >>> t2=tensor([[1.0],[1.0]]) >>> criterion = nn.CrossEntropyLoss() >>> criterion(t1,t2) tensor(-0.) >>> criterion(t1,t2).item() -0.0
>>> criterion = nn.CrossEntropyLoss().cuda() >>> t1=t1.cuda() >>> t2=t2.cuda() >>> criterion(t1,t2) tensor(-0., device='cuda:0') >>> criterion(t1,t2).item() -0.0
CrossEntropyLoss
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)