Skip to content

Commit

Permalink
.
Browse files Browse the repository at this point in the history
  • Loading branch information
dpkingma committed Jun 4, 2014
1 parent 4938fea commit b6bba65
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 9 deletions.
2 changes: 1 addition & 1 deletion data/cifar10.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import os

# from http://cs.nyu.edu/~roweis/data.html
path = os.path.dirname(__file__)+'/'
path = os.environ['ML_DATA_PATH']+'/cifar10/'

# Load the original images into numpy arrays
def load_numpy():
Expand Down
2 changes: 1 addition & 1 deletion data/freyface.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import os

# from http://cs.nyu.edu/~roweis/data.html
path = os.path.dirname(__file__)+'/frey_rawface.mat'
path = os.environ['ML_DATA_PATH']+'/freyface/frey_rawface.mat'

def load_numpy():
return scipy.io.loadmat(path)['ff'].T/256.
16 changes: 9 additions & 7 deletions data/lfw.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
import numpy as np
import os

path = os.path.dirname(__file__)+'/'
path = os.environ['ML_DATA_PATH']+'/lfw/'

# shape: (13233, 31, 23, 3)
def load_lfw_small():
data = np.load(path+'lfw_31x23.npy').swapaxes(1,3).swapaxes(2,3).reshape((-1, 31*23*3))
data = data.astype('float16')/256.
return data, (31, 23)
data = np.load(path+'lfw_31x23.npy').swapaxes(1,3).swapaxes(2,3).reshape((-1, 31*23*3))
data = data.astype('float16')/256.
labels = np.load(path+'lfw_labels.npy')
return data, labels, (31, 23)

def load_lfw_big():
data = np.load(path+'lfw_62x47.npy').swapaxes(1,3).swapaxes(2,3).reshape((-1, 62*47*3))
data = data.astype('float16')/256.
return data, (62, 47)
data = np.load(path+'lfw_62x47.npy').swapaxes(1,3).swapaxes(2,3).reshape((-1, 62*47*3))
data = data.astype('float16')/256.
labels = np.load(path+'lfw_labels.npy')
return data, labels, (62, 47)

1 change: 1 addition & 0 deletions data/lfw_generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
# 'big' images (scale factor 0.5)
lfw_people = fetch_lfw_people(color=True)
np.save('lfw_62x47', lfw_people.images.astype('uint8'))
np.save('lfw_labels', lfw_people.target)

# 'small' images (scale factor 0.25)
lfw_people2 = fetch_lfw_people(color=True, resize=0.25)
Expand Down
29 changes: 29 additions & 0 deletions data/svhn.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import numpy as np
import scipy.io
import os

# from http://cs.nyu.edu/~roweis/data.html
path = os.environ['ML_DATA_PATH']

def load_numpy(toFloat=True, binarize_y=False):
train = scipy.io.loadmat(path+'/svhn/train_32x32.mat')
train_x = train['X'].swapaxes(0,1).T.reshape((train['X'].shape[3], -1)).T
train_y = train['y'].reshape((-1)) - 1
test = scipy.io.loadmat(path+'/svhn/test_32x32.mat')
test_x = test['X'].swapaxes(0,1).T.reshape((test['X'].shape[3], -1)).T
test_y = test['y'].reshape((-1)) - 1
if toFloat:
train_x = train_x.astype('float16')/256.
test_x = test_x.astype('float16')/256.
if binarize_y:
train_y = binarize_labels(train_y)
test_y = binarize_labels(test_y)

return train_x, train_y, test_x, test_y

# Converts integer labels to binarized labels (1-of-K coding)
def binarize_labels(y, n_classes=10):
new_y = np.zeros((n_classes, y.shape[0]))
for i in range(y.shape[0]):
new_y[y[i], i] = 1
return new_y

0 comments on commit b6bba65

Please sign in to comment.