AttributeError: Caught AttributeError in DataLoader worker process 0

AttributeError: Caught AttributeError in DataLoader worker process 0

我进行了一些谷歌搜索,这个错误似乎经常出现,但我不确定如何解决它/我目前正在学习 PyTorch torchvision 教程 (https://pytorch.org/tutorials/intermediate/torchvision_tutorial.html) 进行分割。但是,我收到了名义上的错误:

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

我相信我已经完全按照教程进行操作,复制了他们的代码 - 因此,我有点不确定为什么会出现此错误。对于试图学习如何在计算机视觉中使用 ML 的初学者来说,弄清楚这里发生了什么特别困难。

我不知道这是否重要,但我 运行 Python3 在 Ubuntu。

非常感谢您的帮助! :)

我认为您在 PennFudanDataset

__getitem__ 函数中用 . 打错了 ,

您的版本:

        if self.transforms is not None:
            img, target = self.transforms(img.target)

教程:

        if self.transforms is not None:
            img, target = self.transforms(img, target)