Mercurial > pylearn
annotate pylearn/datasets/shapeset1.py @ 617:5120bf7c4694
More complete version of shapeset1 dataset.
author | lamblinp@ip03.m |
---|---|
date | Sat, 17 Jan 2009 19:06:21 -0500 |
parents | 16f91ca016b1 |
children | 8aef46b42cb5 |
rev | line source |
---|---|
509 | 1 """ |
2 Routines to load/access Shapeset1 | |
3 """ | |
4 | |
5 from __future__ import absolute_import | |
6 | |
7 import os | |
8 import numpy | |
9 | |
563
16f91ca016b1
* added NStages as a stopper (moved from hpu/conv)
desjagui@atchoum.iro.umontreal.ca
parents:
537
diff
changeset
|
10 from ..io.amat import AMat |
509 | 11 from .config import data_root |
617
5120bf7c4694
More complete version of shapeset1 dataset.
lamblinp@ip03.m
parents:
563
diff
changeset
|
12 from .dataset import Dataset |
509 | 13 |
14 def _head(path, n): | |
15 dat = AMat(path=path, head=n) | |
16 | |
17 try: | |
18 assert dat.input.shape[0] == n | |
19 assert dat.target.shape[0] == n | |
20 except Exception , e: | |
21 raise Exception("failed to read %i lines from file %s" % (n, path)) | |
22 | |
23 return dat.input, numpy.asarray(dat.target, dtype='int64').reshape(dat.target.shape[0]) | |
24 | |
25 | |
26 def head_train(n=10000): | |
27 """Load the first Shapeset1 training examples. | |
28 | |
617
5120bf7c4694
More complete version of shapeset1 dataset.
lamblinp@ip03.m
parents:
563
diff
changeset
|
29 Returns two matrices: x, y. |
5120bf7c4694
More complete version of shapeset1 dataset.
lamblinp@ip03.m
parents:
563
diff
changeset
|
30 x has N rows of 1024 columns. |
5120bf7c4694
More complete version of shapeset1 dataset.
lamblinp@ip03.m
parents:
563
diff
changeset
|
31 Each row of x represents the 32x32 grey-scale pixels in raster order. |
5120bf7c4694
More complete version of shapeset1 dataset.
lamblinp@ip03.m
parents:
563
diff
changeset
|
32 y is a vector of N integers between 0 and 2. |
5120bf7c4694
More complete version of shapeset1 dataset.
lamblinp@ip03.m
parents:
563
diff
changeset
|
33 Each element y[i] is the label of the i'th row of x. |
509 | 34 """ |
35 path = os.path.join(data_root(), 'shapeset1','shapeset1_1cspo_2_3.10000.train.shape.amat') | |
36 return _head(path, n) | |
37 | |
38 def head_valid(n=5000): | |
39 """Load the first Shapeset1 validation examples. | |
40 | |
617
5120bf7c4694
More complete version of shapeset1 dataset.
lamblinp@ip03.m
parents:
563
diff
changeset
|
41 Returns two matrices: x, y. |
5120bf7c4694
More complete version of shapeset1 dataset.
lamblinp@ip03.m
parents:
563
diff
changeset
|
42 x has N rows of 1024 columns. |
5120bf7c4694
More complete version of shapeset1 dataset.
lamblinp@ip03.m
parents:
563
diff
changeset
|
43 Each row of x represents the 32x32 grey-scale pixels in raster order. |
5120bf7c4694
More complete version of shapeset1 dataset.
lamblinp@ip03.m
parents:
563
diff
changeset
|
44 y is a vector of N integers between 0 and 2. |
5120bf7c4694
More complete version of shapeset1 dataset.
lamblinp@ip03.m
parents:
563
diff
changeset
|
45 Each element y[i] is the label of the i'th row of x. |
509 | 46 """ |
47 path = os.path.join(data_root(), 'shapeset1','shapeset1_1cspo_2_3.5000.valid.shape.amat') | |
48 return _head(path, n) | |
49 | |
50 def head_test(n=5000): | |
51 """Load the first Shapeset1 testing examples. | |
52 | |
617
5120bf7c4694
More complete version of shapeset1 dataset.
lamblinp@ip03.m
parents:
563
diff
changeset
|
53 Returns two matrices: x, y. |
5120bf7c4694
More complete version of shapeset1 dataset.
lamblinp@ip03.m
parents:
563
diff
changeset
|
54 x has N rows of 1024 columns. |
5120bf7c4694
More complete version of shapeset1 dataset.
lamblinp@ip03.m
parents:
563
diff
changeset
|
55 Each row of x represents the 32x32 grey-scale pixels in raster order. |
5120bf7c4694
More complete version of shapeset1 dataset.
lamblinp@ip03.m
parents:
563
diff
changeset
|
56 y is a vector of N integers between 0 and 2. |
5120bf7c4694
More complete version of shapeset1 dataset.
lamblinp@ip03.m
parents:
563
diff
changeset
|
57 Each element y[i] is the label of the i'th row of x. |
509 | 58 """ |
59 path = os.path.join(data_root(), 'shapeset1','shapeset1_1cspo_2_3.5000.test.shape.amat') | |
60 return _head(path, n) | |
61 | |
62 def train_valid_test(ntrain=10000, nvalid=5000, ntest=5000): | |
617
5120bf7c4694
More complete version of shapeset1 dataset.
lamblinp@ip03.m
parents:
563
diff
changeset
|
63 train_x, train_y = head_train(n=ntrain) |
5120bf7c4694
More complete version of shapeset1 dataset.
lamblinp@ip03.m
parents:
563
diff
changeset
|
64 valid_x, valid_y = head_valid(n=nvalid) |
5120bf7c4694
More complete version of shapeset1 dataset.
lamblinp@ip03.m
parents:
563
diff
changeset
|
65 test_x, test_y = head_test(n=test) |
5120bf7c4694
More complete version of shapeset1 dataset.
lamblinp@ip03.m
parents:
563
diff
changeset
|
66 |
5120bf7c4694
More complete version of shapeset1 dataset.
lamblinp@ip03.m
parents:
563
diff
changeset
|
67 rval = Dataset() |
5120bf7c4694
More complete version of shapeset1 dataset.
lamblinp@ip03.m
parents:
563
diff
changeset
|
68 rval.train = Dataset.Obj(x = train_x, y = train_y) |
5120bf7c4694
More complete version of shapeset1 dataset.
lamblinp@ip03.m
parents:
563
diff
changeset
|
69 rval.valid = Dataset.Obj(x = valid_x, y = valid_y) |
5120bf7c4694
More complete version of shapeset1 dataset.
lamblinp@ip03.m
parents:
563
diff
changeset
|
70 rval.test = Dataset.Obj(x = test_x, y = test_y) |
5120bf7c4694
More complete version of shapeset1 dataset.
lamblinp@ip03.m
parents:
563
diff
changeset
|
71 |
5120bf7c4694
More complete version of shapeset1 dataset.
lamblinp@ip03.m
parents:
563
diff
changeset
|
72 rval.n_classes = 3 |
5120bf7c4694
More complete version of shapeset1 dataset.
lamblinp@ip03.m
parents:
563
diff
changeset
|
73 rval.img_shape = (32, 32) |
5120bf7c4694
More complete version of shapeset1 dataset.
lamblinp@ip03.m
parents:
563
diff
changeset
|
74 |
5120bf7c4694
More complete version of shapeset1 dataset.
lamblinp@ip03.m
parents:
563
diff
changeset
|
75 return rval |
509 | 76 |
77 |