1616from torchvision .datasets import MNIST
1717from torchvision import transforms
1818
19+
1920def download_mnist_dataset (destination_dir ):
2021 # Ensure the destination directory exists
2122 if not os .path .exists (destination_dir ):
2223 os .makedirs (destination_dir )
2324
2425 # Define transformations
25- transform = transforms .Compose ([
26- transforms .ToTensor (),
27- transforms .Normalize ((0.1307 ,), (0.3081 ,))
28- ])
26+ transform = transforms .Compose (
27+ [transforms .ToTensor (), transforms .Normalize ((0.1307 ,), (0.3081 ,))]
28+ )
2929
3030 # Download the training data
31- train_set = MNIST (root = destination_dir , train = True , download = True , transform = transform )
31+ train_set = MNIST (
32+ root = destination_dir , train = True , download = True , transform = transform
33+ )
3234
3335 # Download the test data
34- test_set = MNIST (root = destination_dir , train = False , download = True , transform = transform )
36+ test_set = MNIST (
37+ root = destination_dir , train = False , download = True , transform = transform
38+ )
3539
3640 print (f"MNIST dataset downloaded in { destination_dir } " )
3741
42+
3843# Specify the directory where you
3944script_dir = os .path .dirname (os .path .abspath (__file__ ))
4045destination_dir = script_dir + "/mnist_datasets"
4146
42- download_mnist_dataset (destination_dir )
47+ download_mnist_dataset (destination_dir )
0 commit comments