# HG changeset patch # User James Bergstra # Date 1225294729 14400 # Node ID 19ab9ce916e34e51d3326af2eb6f1e90b42ce979 # Parent c7ce66b4e8f4a69a30de9982536f22033f9b852d slightly more sophisticated system for finding the mnist data diff -r c7ce66b4e8f4 -r 19ab9ce916e3 datasets/MNIST.py --- a/datasets/MNIST.py Wed Oct 29 03:29:18 2008 -0400 +++ b/datasets/MNIST.py Wed Oct 29 11:38:49 2008 -0400 @@ -7,9 +7,7 @@ from ..amat import AMat -default_path = '/u/bergstrj/pub/data/mnist.amat' -"""the location of a file containing mnist data in .amat format""" - +from .config import MNIST_amat def head(n=10, path=None): """Load the first MNIST examples. @@ -19,10 +17,16 @@ is the label of the i'th row of x. """ - path = path if path is not None else default_path + path = MNIST_amat if path is None else path dat = AMat(path=path, head=n) + try: + assert dat.input.shape[0] == n + assert dat.target.shape[0] == n + except Exception , e: + raise Exception("failed to read MNIST data", (dat, e)) + return dat.input, numpy.asarray(dat.target, dtype='int64').reshape(dat.target.shape[0]) def train_valid_test(ntrain=50000, nvalid=10000, ntest=10000, path=None): diff -r c7ce66b4e8f4 -r 19ab9ce916e3 datasets/config.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/datasets/config.py Wed Oct 29 11:38:49 2008 -0400 @@ -0,0 +1,12 @@ +"""Configuration options for datasets + + +Especially, the locations of data files. +""" + +import os + +def env_get(key, default): + return default if os.getenv(key) is None else os.getenv(key) + +MNIST_amat = env_get('PYLEARN_MNIST_AMAT', '/u/bergstrj/pub/data/mnist.amat')