comparison datasets/gzpklfile.py @ 246:2024368a8d3d

merge
author Xavier Glorot <glorotxa@iro.umontreal.ca>
date Tue, 16 Mar 2010 12:14:10 -0400
parents 4cfd0eb438af
children 966272e7f14b
comparison
equal deleted inserted replaced
245:0de14b2034c6 246:2024368a8d3d
1 import gzip
2 try:
3 import cPickle as pickle
4 except ImportError:
5 import pickle
6
7 from dataset import DataSet
8 from dsetiter import DataIterator
9 from itertools import izip
10
11 class ArrayFile(object):
12 def __init__(self, ary):
13 self.ary = ary
14 self.pos = 0
15
16 def read(self, num):
17 res = self.ary[self.pos:self.pos+num]
18 self.pos += num
19 return res
20
21 class GzpklDataSet(DataSet):
22 def __init__(self, fname):
23 self._fname = fname
24 self._train = 0
25 self._valid = 1
26 self._test = 2
27
28 def _load(self):
29 f = gzip.open(self._fname, 'rb')
30 try:
31 self.datas = pickle.load(f)
32 finally:
33 f.close()
34
35 def _return_it(self, batchsz, bufsz, id):
36 if not hasattr(self, 'datas'):
37 self._load()
38 return izip(DataIterator([ArrayFile(self.datas[id][0])], batchsz, bufsz),
39 DataIterator([ArrayFile(self.datas[id][1])], batchsz, bufsz))