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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

DataLoader: "TypeError" when iterating on it #4152

Closed
calairoh opened this issue Jul 2, 2021 · 3 comments
Closed

DataLoader: "TypeError" when iterating on it #4152

calairoh opened this issue Jul 2, 2021 · 3 comments

Comments

@calairoh
Copy link

calairoh commented Jul 2, 2021

馃悰 Bug

When iterating on a DataLoader object I get TypeError: __array__() takes 1 positional argument but 2 were given.
It seems that there is problem with the fetch procedure that retrieve the next item from the DataLoader element.

It seems also that it's an error present only in the 0.10.0 version.
Passing to a previous version, 0.9.1 in my case, the problem disappers.

To Reproduce

Steps to reproduce the behavior:

  1. Create any DataLoader
  2. Iterate on it

Here a code snippet:

import torchvision
import torchvision.transforms as transforms
from torch.utils.data import DataLoader

batch_size = 64
transform = transforms.Compose([
   transforms.Resize((32, 32)),
   transforms.ToTensor(),
])

trainset = torchvision.datasets.MNIST(
   root='../dataset', train=True, download=True, transform=transform
)
trainloader = DataLoader(
   trainset, batch_size=batch_size, shuffle=True
)

for idx, data in enumerate(trainloader):
   print(idx)

Here the StackTrace I get:

Traceback (most recent call last):
 File "../src/test.py", line 18, in <module>
   for idx, data in enumerate(trainloader):
 File ..\venv\lib\site-packages\torch\utils\data\dataloader.py", line 521, in __next__
   data = self._next_data()
 File "..\venv\lib\site-packages\torch\utils\data\dataloader.py", line 561, in _next_data
   data = self._dataset_fetcher.fetch(index)  # may raise StopIteration
 File "..\venv\lib\site-packages\torch\utils\data\_utils\fetch.py", line 44, in fetch
   data = [self.dataset[idx] for idx in possibly_batched_index]
 File "..\venv\lib\site-packages\torch\utils\data\_utils\fetch.py", line 44, in <listcomp>
   data = [self.dataset[idx] for idx in possibly_batched_index]
 File "..\venv\lib\site-packages\torchvision\datasets\mnist.py", line 134, in __getitem__
   img = self.transform(img)
 File "..\venv\lib\site-packages\torchvision\transforms\transforms.py", line 60, in __call__
   img = t(img)
 File "..\venv\lib\site-packages\torchvision\transforms\transforms.py", line 97, in __call__
   return F.to_tensor(pic)
 File "..\venv\lib\site-packages\torchvision\transforms\functional.py", line 129, in to_tensor
   np.array(pic, mode_to_nptype.get(pic.mode, np.uint8), copy=True)
TypeError: __array__() takes 1 positional argument but 2 were given

Expected behavior

The execution of the iteration on the DataLoader

Environment

  • PyTorch / torchvision Version: 1.9.0 / 0.10.0
  • OS: Windows 10
  • How you installed PyTorch / torchvision (conda, pip, source): pip
  • Python version: 3.7.0
  • CUDA/cuDNN version: No CUDA
  • GPU models and configuration: No CUDA
@oke-aditya
Copy link
Contributor

Duplicate of #4146 I think. Can you specify the PIL version ?

@lxning
Copy link

lxning commented Jul 2, 2021

got same error for mnist eager mode, scripted mode, trace during TS upgrade to PT1.9.0+torchvision0.10.0+pillow8.3.0

@calairoh
Copy link
Author

calairoh commented Jul 3, 2021

PIL ver: 8.3.0
Yep, actually it seems the same problem of #4146.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants