Pytorch DataLoader output is not iterable

chess2021: <p>I am following some tutorials online about Pytorch and it seems at some point I do not get the expected output although I follow everything step by step.</p>
<pre><code class="lang-auto">import torch
import torchvision
from torchvision import datasets, transforms
Train = datasets.MNIST("", train=True, download=True, transform=transforms.Compose([transforms.ToTensor()]))
Test = datasets.MNIST("", train=False, download=True, transform=transforms.Compose([transforms.ToTensor()]))
trainset = torch.utils.data.DataLoader(Train, batch_size= 10, shuffle=True)
testset = torch.utils.data.DataLoader(Test, batch_size= 10, shuffle=True)

But then when I try to loop through trainset I receive the following error:

    for ii in trainset:
        print(ii)
        break

    TypeError: __array__() takes 1 positional argument but 2 were given
</code></pre>
<p>Can anyone tell me why do I get this error and how I can fix it?</p>

InnovArul: <p>I am able to execute the code as it is, without any error.<br>
I am not sure why you are facing this error. Perhaps the error is in any other line than this one?</p>

chess2021: <p>Thank you. This is the entire code. Do you think I should downgrade or upgrade any package:<br>
This is the list of packages installed in my environment:</p>
<blockquote>
<p>argon2-cffi<br>
async-generator<br>
attrs<br>
backcall<br>
bleach<br>
certifi==2021.5.30<br>
cffi<br>
colorama<br>
debugpy==1.3.0<br>
decorator<br>
defusedxml<br>
entrypoints==0.3<br>
importlib-metadata<br>
ipykernel==6.0.0<br>
ipython==7.25.0<br>
ipython-genutils<br>
ipywidgets<br>
jedi==0.18.0<br>
Jinja2<br>
joblib==1.0.1<br>
jsonschema<br>
jupyter<br>
jupyter-client<br>
jupyter-console<br>
jupyter-core<br>
jupyterlab-pygments<br>
jupyterlab-widgets<br>
MarkupSafe<br>
matplotlib-inline==0.1.2<br>
mistune<br>
nbclient<br>
nbconvert<br>
nbformat<br>
nest-asyncio<br>
notebook<br>
numpy==1.21.0<br>
packaging<br>
pandas==1.2.5<br>
pandocfilters<br>
parso==0.8.2<br>
pickleshare<br>
Pillow==8.3.0<br>
prometheus-client<br>
prompt-toolkit==3.0.19<br>
pycparser<br>
Pygments<br>
pyparsing<br>
pyrsistent<br>
python-dateutil<br>
pytz==2021.1<br>
pywin32==301<br>
pywinpty==1.1.3<br>
pyzmq==22.1.0<br>
qtconsole==5.1.1<br>
QtPy==1.9.0<br>
scikit-learn==0.24.2<br>
scipy==1.7.0<br>
Send2Trash==1.7.1<br>
sip==4.19.13<br>
six<br>
sklearn==0.0<br>
terminado==0.10.1<br>
testpath<br>
threadpoolctl==2.1.0<br>
torch==1.9.0<br>
torchaudio==0.9.0<br>
torchvision==0.10.0<br>
tornado<br>
traitlets<br>
typing-extensions==3.10.0.0<br>
wcwidth<br>
webencodings==0.5.1<br>
widgetsnbextension<br>
wincertstore==0.2<br>
zipp</p>
</blockquote>

InnovArul: <p>I do not see any suspicious packages that could cause this.<br>
Do you have any other code in your file other than following lines?</p>
<pre><code class="lang-auto">import torch
import torchvision
from torchvision import datasets, transforms
Train = datasets.MNIST("", train=True, download=True, transform=transforms.Compose([transforms.ToTensor()]))
Test = datasets.MNIST("", train=False, download=True, transform=transforms.Compose([transforms.ToTensor()]))
trainset = torch.utils.data.DataLoader(Train, batch_size= 10, shuffle=True)
testset = torch.utils.data.DataLoader(Test, batch_size= 10, shuffle=True)

for ii in trainset:
    print(ii)
    break

</code></pre>

ptrblck: <p>You are most likely facing the <code>PIL/Pillow</code> issue as described <a href="https://discuss.pytorch.org/t/quickstart-tutorial-array-takes-1-positional-argument-but-2-were-given/125550/2">here </a>, which was breaking the numpy interaction in 8.3.0 and was already fixed in 8.3.1 after <a class="mention" href="/u/tom">@tom</a>’s <a href="https://github.com/python-pillow/Pillow/pull/5572">fix</a> was merged.</p>