Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

eliminate duplication

  • Loading branch information...
commit a65bf16908821b32828ab18859be4aeb78f02332 1 parent abd499f
Joseph Perla authored
View
6 sample_images.py
@@ -81,7 +81,7 @@ def sample(images, num_samples, size=(8,8), norm=(0.1, 0.9)):
output = d
return output
-def load_mnist_images(filename):
+def read_mnist_file(filename):
"""Accepts filename.
Reads in MNIST data.
Returns 3-tuple of training, validation, and test set.
@@ -99,7 +99,7 @@ def get_mnist_data(filename, test=lambda l: True, train=True, num_samples=1000):
Only reads mnist data from a special pickled mnist file.
Returns array of images with shape (784, num_images).
"""
- training, valid, testing = load_mnist_images(filename)
+ training, valid, testing = read_mnist_file(filename)
if train:
t = np.array([e for e,l in izip(training[0], training[1]) if test(l)])
v = np.array([e for e,l in izip(valid[0], valid[1]) if test(l)])
@@ -119,6 +119,6 @@ def get_mnist_data(filename, test=lambda l: True, train=True, num_samples=1000):
return patches, labels
if __name__=='__main__':
- train, valid, test = load_mnist_images('data/mnist.pkl.gz')
+ train, valid, test = read_mnist_file('data/mnist.pkl.gz')
display_network.display_network('mnist.png', train[0].T[:,:100])
View
13 softmax/softmax.py
@@ -114,10 +114,9 @@ def softmax_predict(softmax_model, data):
if __name__=='__main__':
num_examples = 60000
-
- train, valid, test = sample_images.load_mnist_images('../data/mnist.pkl.gz')
- data = train[0].T[:,:num_examples]
- labels = train[1][:num_examples]
+ data, labels = sample_images.get_mnist_data('../data/mnist.pkl.gz',
+ train=True,
+ num_examples=num_examples)
print len(labels)
@@ -140,8 +139,10 @@ def softmax_predict(softmax_model, data):
# test on the test data
- test_data = test[0].T
- test_labels = test[1]
+ test_data, test_labels = sample_images.get_mnist_data('../data/mnist.pkl.gz',
+ train=False,
+ num_examples=1e10)
+
predicted_labels = softmax_predict(trained, test_data)
assert len(predicted_labels) == len(test_labels)
View
9 train_sparse_autoencoder_on_mnist.py
@@ -19,11 +19,10 @@
# Get the data
num_samples = 10000
- #num_samples = 10000
- train, valid, test = sample_images.load_mnist_images('data/mnist.pkl.gz')
- images = train[0].T
- patches = images[:,:num_samples]
- assert patches.shape == (784, num_samples)
+ patches, _ = sample_images.get_mnist_data('../data/mnist.pkl.gz',
+ train=True,
+ num_examples=num_samples)
+
# set up L-BFGS args
theta = sparse_autoencoder.initialize_params(hidden_size, visible_size)
Please sign in to comment.
Something went wrong with that request. Please try again.