ERROR: 02_pytorch_classification --> error in 8.5 Training and Testing for multi-class Pytorch model #146
-
In section 8.5, (multi-class classification model), this section produces an error message `# Fit the model Set number of epochsepochs = 100 Put data to target deviceX_blob_train, y_blob_train = X_blob_train.to(device), y_blob_train.to(device) for epoch in range(epochs):
` The error is: Expected floating point type for target with class probabilities, got Long I'm on OSX, Pytorch '1.12.1' RuntimeError Traceback (most recent call last) ~/opt/anaconda3/envs/MachineLearning/lib/python3.8/site-packages/torch/nn/modules/module.py in _call_impl(self, *input, **kwargs) ~/opt/anaconda3/envs/MachineLearning/lib/python3.8/site-packages/torch/nn/modules/loss.py in forward(self, input, target) ~/opt/anaconda3/envs/MachineLearning/lib/python3.8/site-packages/torch/nn/functional.py in cross_entropy(input, target, weight, size_average, ignore_index, reduce, reduction, label_smoothing) RuntimeError: Expected floating point type for target with class probabilities, got Long |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
The loss don't receive y_pred, instead use y_logit |
Beta Was this translation helpful? Give feedback.
-
|
Beta Was this translation helpful? Give feedback.
loss = loss_fn(y_logits, y_blob_train)
acc = accuracy_fn(y_true=y_blob_train, y_pred=y_pred)