changeset 504:19ab9ce916e3

slightly more sophisticated system for finding the mnist data
author James Bergstra <bergstrj@iro.umontreal.ca>
date Wed, 29 Oct 2008 11:38:49 -0400
parents c7ce66b4e8f4
children 74b3e65f5f24
files datasets/MNIST.py datasets/config.py
diffstat 2 files changed, 20 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- 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):
--- /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')