Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Weather Data Image Classification notebook shows "IndexError: Target 4 is out of bounds" #236

Open
typex1 opened this issue Oct 16, 2023 · 1 comment
Labels
bug Something isn't working

Comments

@typex1
Copy link

typex1 commented Oct 16, 2023

Link to the notebook
Weather Data Image Classification notebook

What aspects of the notebook do not work?

For the following code cell in section "5. Fine-tune the pre-trained model on the labelled weather data"
print('Training of Model:') model_ft = train_model(model_ft, criterion, optimizer_ft,model_checkpoint=0,num_epochs=epochs)
I get the following error:

`---------------------------------------------------------------------------
IndexError Traceback (most recent call last)
Cell In[26], line 2
1 print('Training of Model:')
----> 2 model_ft = train_model(model_ft, criterion, optimizer_ft,model_checkpoint=0,num_epochs=epochs)

Cell In[12], line 35, in train_model(model, criterion, optimizer, model_checkpoint, early_stop, num_epochs)
33 _, preds = torch.max(output, 1)
34 # calculate the batch loss
---> 35 loss = criterion(output, target)
36 # backward pass: compute gradient of the loss with respect to model parameters
37 loss.backward()

File ~/.conda/envs/cv/lib/python3.9/site-packages/torch/nn/modules/module.py:1194, in Module._call_impl(self, *input, **kwargs)
1190 # If we don't have any hooks, we want to skip the rest of the logic in
1191 # this function, and just call forward.
1192 if not (self._backward_hooks or self._forward_hooks or self._forward_pre_hooks or _global_backward_hooks
1193 or _global_forward_hooks or _global_forward_pre_hooks):
-> 1194 return forward_call(*input, **kwargs)
1195 # Do not call functions when jit is used
1196 full_backward_hooks, non_full_backward_hooks = [], []

File ~/.conda/envs/cv/lib/python3.9/site-packages/torch/nn/modules/loss.py:1174, in CrossEntropyLoss.forward(self, input, target)
1173 def forward(self, input: Tensor, target: Tensor) -> Tensor:
-> 1174 return F.cross_entropy(input, target, weight=self.weight,
1175 ignore_index=self.ignore_index, reduction=self.reduction,
1176 label_smoothing=self.label_smoothing)

File ~/.conda/envs/cv/lib/python3.9/site-packages/torch/nn/functional.py:3026, in cross_entropy(input, target, weight, size_average, ignore_index, reduce, reduction, label_smoothing)
3024 if size_average is not None or reduce is not None:
3025 reduction = _Reduction.legacy_get_string(size_average, reduce)
-> 3026 return torch._C._nn.cross_entropy_loss(input, target, weight, _Reduction.get_enum(reduction), ignore_index, label_smoothing)

IndexError: Target 4 is out of bounds.`

@typex1 typex1 added the bug Something isn't working label Oct 16, 2023
@MicheleMonclova
Copy link

This looks like a Pytorch issue that may be in the code.
did you see this: https://discuss.pytorch.org/t/indexerror-target-4-is-out-of-bounds/99172

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants