resolvent
crossentropyloss (predicted value, label)
the required input dimensions are:
-
- when there is batch, the predicted value dimension is 2 and the size is
[batch]_ When size, n]
-
- , the dimension of label is 1, and the size is
[batch]_ Size]
-
- when there is no batch, the dimension of the predicted value is 2, the size is
[M, n]
-
- , the dimension of the label is 1, and the size is
[M]
Problem analysis
One case can illustrate:
import torch
import torch.nn as nn
import numpy as np
a = torch.tensor(np.random.random((30, 5)))
b = torch.tensor(np.random.randint(0, 4, (30))).long()
loss = nn.CrossEntropyLoss()
print("a的维度:", a.size()) # torch.Size([30, 5])
print("b的维度:", b.size()) # torch.Size([30])
print(loss(a, b)) # tensor(1.6319, dtype=torch.float64)
Read More:
- [Solved] RuntimeError: 1only batches of spatial targets supported (non-empty 3D tensors) but got targets of s
- [Solved] Pytorch3d Error: RuntimeError: Not compiled with GPU support.
- Error in Tensorflow using variables: List of Tensors when single Tensor expected
- [Solved] Runtimeerror during dcgan training: found dtype long but expected float
- RuntimeError: Integer division of tensors using div or / is no longer supported, and in a future rel
- [Solved] There are test failures. Please refer to D:\Java_study\springboot\springboot-sugon-3\target\surefire-reports for the individual test results.
- CCS Error: gmake: Target ‘all‘ not remade because of errors.
- [Solved] CMake Error Cannot specify link libraries for target “variational“ which is not built by this projec
- How to Solve Element Error: target is not existed: .page-component__scroll .el-scrollbar__wrap
- target is multiclass but average=’binary’. please choose another average setting.
- SAP RETAIL Automatic replenishment WRP1R transaction code error: Forecast values for determining target stock do not exist –
- RuntimeError: Exporting the operator uniform to ONNX opset version 12 is not supported.
- [Solved] Disconnected from the target VM, address : ‘127.0.0.1:6847’ , transport : ‘socket’
- Error in invoking target [How to Solve]
- stm32cubeAI “validation on target “ ERROR [How to Solve]
- [Solved] Pytorch Error: RuntimeError: Trying to backward through the graph a second time
- Go build package error: TARGET_OS_MAC & IOMasterPort
- Eclipse Godson Error: Makefile:recipe for target ‘clean‘ failed
- [Solved] TensorFlow Error: ‘Tensor‘ object does not support item assignment
- [Solved] RK3399 Compile UBOOT Error: No rule to make target , needed by