Mercurial > pylearn
comparison datasets/MNIST.py @ 505:74b3e65f5f24
added smallNorb dataset, switched to PYLEARN_DATA_ROOT
author | James Bergstra <bergstrj@iro.umontreal.ca> |
---|---|
date | Wed, 29 Oct 2008 17:09:04 -0400 |
parents | 19ab9ce916e3 |
children | 58810b63292b |
comparison
equal
deleted
inserted
replaced
504:19ab9ce916e3 | 505:74b3e65f5f24 |
---|---|
1 """ | 1 """ |
2 Various routines to load/access MNIST data. | 2 Various routines to load/access MNIST data. |
3 """ | 3 """ |
4 from __future__ import absolute_import | 4 from __future__ import absolute_import |
5 | 5 |
6 import os | |
6 import numpy | 7 import numpy |
7 | 8 |
8 from ..amat import AMat | 9 from ..amat import AMat |
9 | 10 from .config import data_root |
10 from .config import MNIST_amat | |
11 | 11 |
12 def head(n=10, path=None): | 12 def head(n=10, path=None): |
13 """Load the first MNIST examples. | 13 """Load the first MNIST examples. |
14 | 14 |
15 Returns two matrices: x, y. x has N rows of 784 columns. Each row of x represents the | 15 Returns two matrices: x, y. x has N rows of 784 columns. Each row of x represents the |
16 28x28 grey-scale pixels in raster order. y is a vector of N integers. Each element y[i] | 16 28x28 grey-scale pixels in raster order. y is a vector of N integers. Each element y[i] |
17 is the label of the i'th row of x. | 17 is the label of the i'th row of x. |
18 | 18 |
19 """ | 19 """ |
20 path = MNIST_amat if path is None else path | 20 path = os.path.join(data_root(), 'mnist','mnist.amat') if path is None else path |
21 | 21 |
22 dat = AMat(path=path, head=n) | 22 dat = AMat(path=path, head=n) |
23 | 23 |
24 try: | 24 try: |
25 assert dat.input.shape[0] == n | 25 assert dat.input.shape[0] == n |