comparison transformations/pipeline.py @ 10:faacc76d21c2

Basic new pipeline script for the images tranforms (includes bonus patched filetensor module from pylearn.io)
author Arnaud Bergeron <abergeron@gmail.com>
date Wed, 27 Jan 2010 17:35:37 -0500
parents
children f6b6c74bb82f
comparison
equal deleted inserted replaced
9:64dac4aabc04 10:faacc76d21c2
1 from __future__ import with_statement
2
3 import sys, os
4 import numpy
5 import filetensor as ft
6 import random
7
8 BATCH_SIZE = 100
9
10 #import <modules> and stuff them in mods below
11
12 mods = []
13
14 # DANGER: HIGH VOLTAGE -- DO NOT EDIT BELOW THIS LINE
15 # -----------------------------------------------------------
16
17 train_data = open('/data/lisa/data/nist/by_class/all/all_train_data.ft', 'rb')
18
19 dim = tuple(ft._read_header(train_data)[3])
20
21 res_data = numpy.empty(dim)
22
23 all_settings = ['complexity']
24
25 for mod in mods:
26 all_settings += mod.get_settings_names()
27
28 params = numpy.empty(((dim[0]/BATCH_SIZE)+1, len(all_settings)))
29
30 for i in xrange(0, dim[0], BATCH_SIZE):
31 train_data.seek(0)
32 imgs = ft.read(train_data, slice(i, i+BATCH_SIZE))
33
34 complexity = random.random()
35 p = i/BATCH_SIZE
36 j = 1
37 for mod in mods:
38 par = mod.regenerate_parameters(complexity)
39 params[p, j:j+len(par)] = par
40 j += len(par)
41
42 for k in range(imgs.shape[0]):
43 c = imgs[k]
44 for mod in mods:
45 c = mod.transform_image(c)
46 res_data[i+k] = c
47
48 with open(sys.argv[1], 'wb') as f:
49 ft.write(f, res_data)
50
51 numpy.save(sys.argv[2], params)