criterion = nn.CrossEntropyLoss()
for i in range(10):
_, output = torch.max(model(x_train_tensor[i]), 0)
error: RuntimeError: Dimension out of range (expected to be in range of [-1, 0], but got 1)
how can i fix it?
Maybe you misunderstood about
You need not take max and pass the index to the loss.
nn.CrossEntropyLoss() expects a 2D array of logits where each row belongs to values predicted for a particular item.
if i need classify two classes[ex. true, false], which loss function should be used? can you suggest for me?
You can use either
nn.BCELoss(), your network shall have one output node with Sigmoid output activation.
nn.CrossEntropyLoss(), your network shall have two output node without any activation.
if my DNN model’s last layer use Relu activation function, BCELoss function can not use?
I think, you should change the final node’s activation to Sigmoid if you are planning to use nn.BCELoss().
0 <= nn.ReLU(output) <= inf and BCELoss expects probability (0 to 1).