-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathget_data.py
More file actions
33 lines (27 loc) · 782 Bytes
/
get_data.py
File metadata and controls
33 lines (27 loc) · 782 Bytes
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
32
33
import gzip
import matplotlib.pyplot as plt
import numpy as np
import pickle
import theano
import theano.tensor as T
def get_data():
with gzip.open('mnist.pkl.gz', 'rb') as f:
try:
train_set, valid_set, test_set = pickle.load(f)
except:
train_set, valid_set, test_set = pickle.load(f, encoding='latin1')
return train_set, valid_set, test_set
def display_img(arr):
arr = arr.reshape((28, 28))
plt.imshow(arr, cmap='Greys_r')
plt.show()
def get_xy(imgs, labels):
x = theano.shared(
value=np.asarray(imgs, dtype=theano.config.floatX),
borrow=True,
)
y = T.cast(theano.shared(
value=np.asarray(labels, dtype=theano.config.floatX),
borrow=True,
), 'int32')
return x, y