Reputation: 172
I have done some googling, and this error seems to commonly appear but I am unsure about how to solve it/ I am currently doing the PyTorch torchvision tutorial (https://pytorch.org/tutorials/intermediate/torchvision_tutorial.html) for segmentation. However, I am getting thrown the titular error:
Traceback (most recent call last):
File "main.py", line 139, in <module>
main()
File "main.py", line 131, in main
print_freq=10)
File "/engine.py", line 26, in train_one_epoch
for images, targets in metric_logger.log_every(data_loader, print_freq, header):
File "/utils.py", line 180, in log_every
for obj in iterable:
File "/usr/local/lib/python3.6/dist-packages/torch/utils/data/dataloader.py", line 521, in __next__
data = self._next_data()
File "/usr/local/lib/python3.6/dist-packages/torch/utils/data/dataloader.py", line 1203, in _next_data
return self._process_data(data)
File "/usr/local/lib/python3.6/dist-packages/torch/utils/data/dataloader.py", line 1229, in _process_data
data.reraise()
File "/usr/local/lib/python3.6/dist-packages/torch/_utils.py", line 425, in reraise
raise self.exc_type(msg)
AttributeError: Caught AttributeError in DataLoader worker process 0.
Original Traceback (most recent call last):
File "/usr/local/lib/python3.6/dist-packages/torch/utils/data/_utils/worker.py", line 287, in _worker_loop
data = fetcher.fetch(index)
File "/usr/local/lib/python3.6/dist-packages/torch/utils/data/_utils/fetch.py", line 44, in fetch
data = [self.dataset[idx] for idx in possibly_batched_index]
File "/usr/local/lib/python3.6/dist-packages/torch/utils/data/_utils/fetch.py", line 44, in <listcomp>
data = [self.dataset[idx] for idx in possibly_batched_index]
File "/usr/local/lib/python3.6/dist-packages/torch/utils/data/dataset.py", line 311, in __getitem__
return self.dataset[self.indices[idx]]
File "main.py", line 64, in __getitem__
img, target = self.transforms(img.target)
File "/usr/local/lib/python3.6/dist-packages/PIL/Image.py", line 546, in __getattr__
raise AttributeError(name)
AttributeError: target
I believe I have followed the tutorial completely, copying their code - I'm a bit unsure, therefore, why this error is arising. For a beginner who's trying to learn how to use ML in computer vision it's especially difficult to figure out what's going on here.
I don't know if this is important, but I'm running Python3 on Ubuntu.
Many thanks in advance for your help! :)
Upvotes: 0
Views: 11388
Reputation: 137
I think you mistyped the ,
with .
in __getitem__
function of PennFudanDataset
Your version:
if self.transforms is not None:
img, target = self.transforms(img.target)
Tutorial:
if self.transforms is not None:
img, target = self.transforms(img, target)
Upvotes: 3