forked from Lifearafter/Federated_Learning_Forge
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mnist.py
31 lines (29 loc) · 965 Bytes
/
mnist.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import random
import torchvision
import torchvision.transforms
from torchvision import datasets as dataset
import numpy as np
from PIL import Image
import os as os
DATA_ROOT = os.getcwd() + "/data/mnist"
print(DATA_ROOT)
trainset = dataset.MNIST(root = DATA_ROOT + "/data", train = True, download=True, transform=None)
testset = dataset.MNIST(root = DATA_ROOT + "/data", train = False, download=True, transform=None)
'''
trainset = FastMNIST('data/MNIST', train = True, download=True )
testset = FastMNIST('data/MNIST', train = False, download=True )
return trainset, testset
'''
path = os.path.join(os.getcwd(), 'MNIST_PNG')
if (not os.path.exists(path)):
os.mkdir(path)
os.chdir(path)
f = open('numbers.txt', 'w')
for i in range(51):
x = random.randint(0, 10000)
im = testset[x][0]
im_value = testset[x][1]
fileName = str(i) + "_MNISTIMG.png"
im.save(fileName)
f.write(str(im_value) + "\n")
print("Randomizing Images DONE!")