pytorch cifar10 dataset - cannot get first item
I have selected the CIFAR 10 dataset using the torchvision library:
trainset = torchvision.datasets.CIFAR10(root='./data', train=True,
                                        download=True, transform=transforms.ToTensor())

Then I try to select the first item in the dataset, which as I understand implements the get_item method of the dataset class:
trainset[0]

and I get
File &quot;env\lib\site-packages\torchvision\transforms\functional.py&quot;, 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

Any ideas why I would get this error?
Python 3.7.9, torch==1.9.0, torchvision==0.10.0

I was hitting this error too:
def get_transformations():
    return transforms.Compose([transforms.ToTensor()])

...

self.transforms = get_transformations()

...

# Load the image + augment
img = Image.open(img_path).convert(&quot;RGB&quot;)
img = self.transforms(img)

...

Original Traceback (most recent call last):
  File &quot;c:\2021-mcm-master\src\PyTorch-RCNN\ui-prediction\env\lib\site-packages\torch\utils\data\_utils\worker.py&quot;, line 287, in _worker_loop
    data = fetcher.fetch(index)
  File &quot;c:\2021-mcm-master\src\PyTorch-RCNN\ui-prediction\env\lib\site-packages\torch\utils\data\_utils\fetch.py&quot;, line 44, in fetch
    data = [self.dataset[idx] for idx in possibly_batched_index]
  File &quot;c:\2021-mcm-master\src\PyTorch-RCNN\ui-prediction\env\lib\site-packages\torch\utils\data\_utils\fetch.py&quot;, line 44, in &lt;listcomp&gt;
    data = [self.dataset[idx] for idx in possibly_batched_index]
  File &quot;c:\2021-mcm-master\src\PyTorch-RCNN\ui-prediction\src\screenshot_dataset.py&quot;, line 112, in __getitem__
    img = self.transforms(img)
  File &quot;c:\2021-mcm-master\src\PyTorch-RCNN\ui-prediction\env\lib\site-packages\torchvision\transforms\transforms.py&quot;, line 60, in __call__
    img = t(img)
  File &quot;c:\2021-mcm-master\src\PyTorch-RCNN\ui-prediction\env\lib\site-packages\torchvision\transforms\transforms.py&quot;, line 97, in __call__
    return F.to_tensor(pic)
  File &quot;c:\2021-mcm-master\src\PyTorch-RCNN\ui-prediction\env\lib\site-packages\torchvision\transforms\functional.py&quot;, 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

As @Phil suggested, downgrading Pillow from 8.3.0 to 8.2.0 solved the issue:
pip install pillow==8.2.0

