'TypeError: cross_entropy_loss(): argument 'input' (position 1) must be Tensor, not tuple

I am getting this error>> TypeError: cross_entropy_loss(): argument 'input' (position 1) must be Tensor, not tuple

I tried different ways to convert tuple into tensor, however I could not manage to solve the problem. could anyone help me please.

this is the config code that includes the main args_setting.

enter image description here

this is the training code

enter image description here

and this is the model of NN

enter image description here

finally this is the error

enter image description here

thank you in advance.



Solution 1:[1]

If you want that those numbers of class_weights be a tensor, you should simply use a

class_weights = torch.tensor([0.02, 1.02])

I recommend you to see this link to know about creating tensors

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 khashayar ehteshami