Argmax() Returns only Zeros

Hello, CrossEntropyLoss Returns 2 values in tensor. i want these tensors to return 0 or 1 as classes.

But.

for i in range(len(y_test)):
print(y_val[i].argmax().item())

argmax().item() only returns zeros.

How can i retunr zero or 1 out of these tensors?

for i in range(10):
print(y_val[i])

tensor([ 4.0784, -4.6333])
tensor([ 3.4433, -3.3892])
tensor([ 2.8473, -2.9989])
tensor([ 1.4762, -1.3092])
tensor([ 4.6216, -5.5956])
tensor([ 2.1936, -1.9820])
tensor([ 2.4091, -1.7561])
tensor([ 4.1027, -3.2408])
tensor([ 2.3697, -2.1431])
tensor([ 2.7150, -2.2833])

Hi Tornike!

The problem is not argmax() – some other part of your code is not
giving the values you expect for y_val. They are not reasonable
results from CrossEntropyLoss (if that’s what you are expecting).

In the examples you printed out the [0] element is positive, and the
[1] element is negative, so the maximum value is the [0] element.
argmax() is correctly returning 0 – the index of the maximum element.

Best.

K. Frank

1 Like