diff 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
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/transformations/pipeline.py	Wed Jan 27 17:35:37 2010 -0500
@@ -0,0 +1,51 @@
+from __future__ import with_statement
+
+import sys, os
+import numpy
+import filetensor as ft
+import random
+
+BATCH_SIZE = 100
+
+#import <modules> and stuff them in mods below
+
+mods = []
+
+# DANGER: HIGH VOLTAGE -- DO NOT EDIT BELOW THIS LINE
+# -----------------------------------------------------------
+
+train_data = open('/data/lisa/data/nist/by_class/all/all_train_data.ft', 'rb')
+
+dim = tuple(ft._read_header(train_data)[3])
+
+res_data = numpy.empty(dim)
+
+all_settings = ['complexity']
+
+for mod in mods:
+    all_settings += mod.get_settings_names()
+
+params = numpy.empty(((dim[0]/BATCH_SIZE)+1, len(all_settings)))
+
+for i in xrange(0, dim[0], BATCH_SIZE):
+    train_data.seek(0)
+    imgs = ft.read(train_data, slice(i, i+BATCH_SIZE))
+    
+    complexity = random.random()
+    p = i/BATCH_SIZE
+    j = 1
+    for mod in mods:
+        par = mod.regenerate_parameters(complexity)
+        params[p, j:j+len(par)] = par
+        j += len(par)
+    
+    for k in range(imgs.shape[0]):
+        c = imgs[k]
+        for mod in mods:
+            c = mod.transform_image(c)
+        res_data[i+k] = c
+
+with open(sys.argv[1], 'wb') as f:
+    ft.write(f, res_data)
+
+numpy.save(sys.argv[2], params)