I have some Problems when i following a tutorial about autoencoder in youtube.
Here is my code
import torch
import torch.nn as nn
import torch.optim as optim
from torchvision import datasets, transforms
import matplotlib.pyplot as plt
transform = transforms.ToTensor()
mnist_data = datasets.MNIST(root='./data',train=True, download=True, transform=True)
data_loader = torch.utils.data.DataLoader(dataset=mnist_data,batch_size=64,shuffle=True)
dataiter = iter(data_loader)
images, labels = next(dataiter)
print(torch.min(images), torch.max(images))
and i got this problems
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
~\AppData\Local\Temp\ipykernel_9516\372505004.py in <module>
1 dataiter = iter(data_loader)
----> 2 images, labels = next(dataiter)
3 print(torch.min(images), torch.max(images))
~\anaconda3\lib\site-packages\torch\utils\data\dataloader.py in __next__(self)
626 # TODO(https://github.com/pytorch/pytorch/issues/76750)
627 self._reset() # type: ignore[call-arg]
--> 628 data = self._next_data()
629 self._num_yielded += 1
630 if self._dataset_kind == _DatasetKind.Iterable and \
~\anaconda3\lib\site-packages\torch\utils\data\dataloader.py in _next_data(self)
669 def _next_data(self):
670 index = self._next_index() # may raise StopIteration
--> 671 data = self._dataset_fetcher.fetch(index) # may raise StopIteration
672 if self._pin_memory:
673 data = _utils.pin_memory.pin_memory(data, self._pin_memory_device)
~\anaconda3\lib\site-packages\torch\utils\data\_utils\fetch.py in fetch(self, possibly_batched_index)
56 data = self.dataset.__getitems__(possibly_batched_index)
57 else:
---> 58 data = [self.dataset[idx] for idx in possibly_batched_index]
59 else:
60 data = self.dataset[possibly_batched_index]
~\anaconda3\lib\site-packages\torch\utils\data\_utils\fetch.py in <listcomp>(.0)
56 data = self.dataset.__getitems__(possibly_batched_index)
57 else:
---> 58 data = [self.dataset[idx] for idx in possibly_batched_index]
59 else:
60 data = self.dataset[possibly_batched_index]
~\anaconda3\lib\site-packages\torchvision\datasets\mnist.py in __getitem__(self, index)
143
144 if self.transform is not None:
--> 145 img = self.transform(img)
146
147 if self.target_transform is not None:
TypeError: 'bool' object is not callable
i wonder why this happened and how to due with this. Tks for help me!