Hello I am currently learning from the Transfer learning tutorial provided on the Pytorch webside.
I ran into this error while trying to train the model.
https://pytorch.org/tutorials/beginner/transfer_learning_tutorial.html
RuntimeError Traceback (most recent call last)
in
5 model_ft.fc = nn.Linear(num_ftrs, 2)
6
----> 7 model_ft = model_ft.to(device)
8
9 criterion = nn.CrossEntropyLoss()
~/venvs/p_donov/lib/python3.8/site-packages/torch/nn/modules/module.py in to(self, *args, **kwargs)
605 return t.to(device, dtype if t.is_floating_point() else None, non_blocking)
606
β 607 return self._apply(convert)
608
609 def register_backward_hook(
~/venvs/p_donov/lib/python3.8/site-packages/torch/nn/modules/module.py in _apply(self, fn)
352 def _apply(self, fn):
353 for module in self.children():
β 354 module._apply(fn)
355
356 def compute_should_use_set_data(tensor, tensor_applied):
~/venvs/p_donov/lib/python3.8/site-packages/torch/nn/modules/module.py in _apply(self, fn)
374 # with torch.no_grad():
375 with torch.no_grad():
β 376 param_applied = fn(param)
377 should_use_set_data = compute_should_use_set_data(param, param_applied)
378 if should_use_set_data:
~/venvs/p_donov/lib/python3.8/site-packages/torch/nn/modules/module.py in convert(t)
603 if convert_to_format is not None and t.dim() == 4:
604 return t.to(device, dtype if t.is_floating_point() else None, non_blocking, memory_format=convert_to_format)
β 605 return t.to(device, dtype if t.is_floating_point() else None, non_blocking)
606
607 return self._apply(convert)
RuntimeError: CUDA error: device-side assert triggered
It is clearly an indexing error. I tried to run in only on my cpu and i run only once. Afterwards was coming this error msg:
IndexError Traceback (most recent call last)
in
----> 1 model_ft = train_model(model_ft, criterion, optimizer_ft, exp_lr_scheduler,
2 num_epochs=25)
in train_model(model, criterion, optimizer, scheduler, num_epochs)
32 outputs = model(inputs)
33 _, preds = torch.max(outputs, 1)
β> 34 loss = criterion(outputs, labels)
35
36 # backward + optimize only if in training phase
~/venvs/p_donov/lib/python3.8/site-packages/torch/nn/modules/module.py in _call_impl(self, *input, **kwargs)
720 result = self._slow_forward(*input, **kwargs)
721 else:
β 722 result = self.forward(*input, **kwargs)
723 for hook in itertools.chain(
724 _global_forward_hooks.values(),
~/venvs/p_donov/lib/python3.8/site-packages/torch/nn/modules/loss.py in forward(self, input, target)
945
946 def forward(self, input: Tensor, target: Tensor) β Tensor:
β 947 return F.cross_entropy(input, target, weight=self.weight,
948 ignore_index=self.ignore_index, reduction=self.reduction)
949
~/venvs/p_donov/lib/python3.8/site-packages/torch/nn/functional.py in cross_entropy(input, target, weight, size_average, ignore_index, reduce, reduction)
2420 if size_average is not None or reduce is not None:
2421 reduction = _Reduction.legacy_get_string(size_average, reduce)
β 2422 return nll_loss(log_softmax(input, 1), target, weight, None, ignore_index, None, reduction)
2423
2424
~/venvs/p_donov/lib/python3.8/site-packages/torch/nn/functional.py in nll_loss(input, target, weight, size_average, ignore_index, reduce, reduction)
2216 .format(input.size(0), target.size(0)))
2217 if dim == 2:
β 2218 ret = torch._C._nn.nll_loss(input, target, weight, _Reduction.get_enum(reduction), ignore_index)
2219 elif dim == 4:
2220 ret = torch._C._nn.nll_loss2d(input, target, weight, _Reduction.get_enum(reduction), ignore_index)
IndexError: Target 2 is out of bounds.