What's wrong with my code?

import torch
import torchvision
from torchvision import transforms, datasets

train = datasets.MNIST("", train=True, download=True,
transform=transforms.Compose([transforms.ToTensor()]))

test = datasets.MNIST("", train=False, download=True,
transform=transforms.Compose([transforms.ToTensor()]))

import torch
from torchvision import datasets
import torchvision.transforms as tf

train_dataset = datasets.MNIST('./data', train=True, download=True, transform=tf.ToTensor())
test_dataset = datasets.MNIST('./data', train=False, download=True, transform=tf.ToTensor())

it works, thank you so much!

okay it worked once and when i tried to run it again it stopped working

Can you share what the error was, i believe its to do with the data already existing when you run it the second time (try deleting the data dir) and running again.

yeah I deleted the data and the error diappeared. thanks!

the error keeps appearing when I try to use the data, I think it has something to do with some of the downloads failing. am I right?

is it possible to download the dataset simply as a ZIP or something?

There should not an error. Can you share what the error is?

\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\torchvision\datasets\mnist.py:498: UserWarning: The given NumPy array is not writeable, and PyTorch does not support non-writeable tensors. This means you can write to the underlying (supposedly non-writeable) NumPy array using the tensor. You may want to copy the array to protect its data or make it writeable before converting it to a tensor. This type of warning will be suppressed for the rest of this program. (Triggered internally at …\torch\csrc\utils\tensor_numpy.cpp:180.)
return torch.from_numpy(parsed.astype(m[2], copy=False)).view(*s)

In my opinion you can safely ignore this warning when loading the dataset.