-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGet_Data.py
30 lines (28 loc) · 1 KB
/
Get_Data.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
import gzip
import numpy as np
class Show:
def showImageNumber(batchSize):
f = gzip.open('train-images-idx3-ubyte.gz','r')
image_size = 28
f.read(16)
buf = f.read(image_size * image_size * batchSize)
data = np.frombuffer(buf, dtype=np.uint8).astype(np.float32)
data = data.reshape(batchSize, image_size, image_size, 1)
image = np.asarray(data)
a=list()
for i in range(len(image)):
a.append(image[i].flatten())
return a
class Label:
def rOneHot(batchSize):
f = gzip.open('train-labels-idx1-ubyte.gz','r')
f.read(8)
labelValue=list()
for i in range(batchSize):
buf = f.read(1)
labels = np.frombuffer(buf, dtype=np.uint8).astype(np.int64)
labelValue.append(labels[0])
labelValue=np.array(labelValue)
oneHot = np.zeros((labelValue.size, labelValue.max() + 1))
oneHot[np.arange(labelValue.size), labelValue] = 1
return oneHot