509
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
diff
changeset
|
1 """
|
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
diff
changeset
|
2 Routines to load/access Shapeset1
|
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
diff
changeset
|
3 """
|
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
diff
changeset
|
4
|
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
diff
changeset
|
5 from __future__ import absolute_import
|
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
diff
changeset
|
6
|
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
diff
changeset
|
7 import os
|
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
diff
changeset
|
8 import numpy
|
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
diff
changeset
|
9
|
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
diff
changeset
|
10 from ..amat import AMat
|
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
diff
changeset
|
11 from .config import data_root
|
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
diff
changeset
|
12
|
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
diff
changeset
|
13 def _head(path, n):
|
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
diff
changeset
|
14 dat = AMat(path=path, head=n)
|
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
diff
changeset
|
15
|
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
diff
changeset
|
16 try:
|
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
diff
changeset
|
17 assert dat.input.shape[0] == n
|
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
diff
changeset
|
18 assert dat.target.shape[0] == n
|
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
diff
changeset
|
19 except Exception , e:
|
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
diff
changeset
|
20 raise Exception("failed to read %i lines from file %s" % (n, path))
|
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
diff
changeset
|
21
|
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
diff
changeset
|
22 return dat.input, numpy.asarray(dat.target, dtype='int64').reshape(dat.target.shape[0])
|
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
diff
changeset
|
23
|
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
diff
changeset
|
24
|
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
diff
changeset
|
25 def head_train(n=10000):
|
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
diff
changeset
|
26 """Load the first Shapeset1 training examples.
|
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
diff
changeset
|
27
|
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
diff
changeset
|
28 Returns two matrices: x, y. x has N rows of 1024 columns. Each row of x represents the
|
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
diff
changeset
|
29 32x32 grey-scale pixels in raster order. y is a vector of N integers. Each element y[i]
|
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
diff
changeset
|
30 is the label of the i'th row of x.
|
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
diff
changeset
|
31
|
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
diff
changeset
|
32 """
|
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
diff
changeset
|
33 path = os.path.join(data_root(), 'shapeset1','shapeset1_1cspo_2_3.10000.train.shape.amat')
|
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
diff
changeset
|
34 return _head(path, n)
|
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
diff
changeset
|
35
|
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
diff
changeset
|
36 def head_valid(n=5000):
|
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
diff
changeset
|
37 """Load the first Shapeset1 validation examples.
|
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
diff
changeset
|
38
|
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
diff
changeset
|
39 Returns two matrices: x, y. x has N rows of 1024 columns. Each row of x represents the
|
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
diff
changeset
|
40 32x32 grey-scale pixels in raster order. y is a vector of N integers. Each element y[i]
|
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
diff
changeset
|
41 is the label of the i'th row of x.
|
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
diff
changeset
|
42
|
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
diff
changeset
|
43 """
|
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
diff
changeset
|
44 path = os.path.join(data_root(), 'shapeset1','shapeset1_1cspo_2_3.5000.valid.shape.amat')
|
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
diff
changeset
|
45 return _head(path, n)
|
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
diff
changeset
|
46
|
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
diff
changeset
|
47 def head_test(n=5000):
|
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
diff
changeset
|
48 """Load the first Shapeset1 testing examples.
|
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
diff
changeset
|
49
|
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
diff
changeset
|
50 Returns two matrices: x, y. x has N rows of 1024 columns. Each row of x represents the
|
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
diff
changeset
|
51 32x32 grey-scale pixels in raster order. y is a vector of N integers. Each element y[i]
|
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
diff
changeset
|
52 is the label of the i'th row of x.
|
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
diff
changeset
|
53
|
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
diff
changeset
|
54 """
|
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
diff
changeset
|
55 path = os.path.join(data_root(), 'shapeset1','shapeset1_1cspo_2_3.5000.test.shape.amat')
|
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
diff
changeset
|
56 return _head(path, n)
|
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
diff
changeset
|
57
|
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
diff
changeset
|
58 def train_valid_test(ntrain=10000, nvalid=5000, ntest=5000):
|
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
diff
changeset
|
59 return head_train(n=ntrain), head_valid(n=nvalid), head_test(n=ntest)
|
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
diff
changeset
|
60
|
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
diff
changeset
|
61
|