如何在pytorch中修复'str'对象没有属性'seek'错误?

时间:2019-10-10 08:41:14

标签: python pytorch

我正在尝试实现这段代码https://github.com/eriklindernoren/PyTorch-YOLOv3,并使用自己的数据集对其进行训练,但在尝试对其进行验证时,我总是遇到以下错误

---- Evaluating Model ----
Detecting objects:   0%|                                                                                                                                                              | 0/1 [00:00<?, ?it/s]Traceback (most recent call last):
  File "train.py", line 160, in <module>
    batch_size=8,
  File "/home/harshvardhan/PyTorch-YOLOv3/test.py", line 36, in evaluate
    for batch_size, (imgs, targets) in enumerate(tqdm.tqdm(dataloader, desc="Detecting objects")):
  File "/home/harshvardhan/.conda/envs/pytorch/lib/python3.6/site-packages/tqdm/std.py", line 1081, in __iter__
    for obj in iterable:
  File "/home/harshvardhan/.conda/envs/pytorch/lib/python3.6/site-packages/torch/utils/data/dataloader.py", line 819, in __next__
    return self._process_data(data)
  File "/home/harshvardhan/.conda/envs/pytorch/lib/python3.6/site-packages/torch/utils/data/dataloader.py", line 846, in _process_data
    data.reraise()
  File "/home/harshvardhan/.conda/envs/pytorch/lib/python3.6/site-packages/torch/_utils.py", line 369, in reraise
    raise self.exc_type(msg)
AttributeError: Caught AttributeError in DataLoader worker process 0.
Original Traceback (most recent call last):
  File "/home/harshvardhan/.conda/envs/pytorch/lib/python3.6/site-packages/PIL/Image.py", line 2770, in open
    fp.seek(0)
AttributeError: 'str' object has no attribute 'seek'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/harshvardhan/.conda/envs/pytorch/lib/python3.6/site-packages/torch/utils/data/_utils/worker.py", line 178, in _worker_loop
    data = fetcher.fetch(index)
  File "/home/harshvardhan/.conda/envs/pytorch/lib/python3.6/site-packages/torch/utils/data/_utils/fetch.py", line 44, in fetch
    data = [self.dataset[idx] for idx in possibly_batched_index]
  File "/home/harshvardhan/.conda/envs/pytorch/lib/python3.6/site-packages/torch/utils/data/_utils/fetch.py", line 44, in <listcomp>
    data = [self.dataset[idx] for idx in possibly_batched_index]
  File "/home/harshvardhan/PyTorch-YOLOv3/utils/datasets.py", line 86, in __getitem__
    img = transforms.ToTensor()(Image.open(img_path).convert('RGB'))
  File "/home/harshvardhan/.conda/envs/pytorch/lib/python3.6/site-packages/PIL/Image.py", line 2772, in open
    fp = io.BytesIO(fp.read())
AttributeError: 'str' object has no attribute 'read'

0 个答案:

没有答案