diff deep/convolutional_dae/scdae.py @ 301:be45e7db7cd4

Fix last-minute bugs in the code.
author Arnaud Bergeron <abergeron@gmail.com>
date Mon, 29 Mar 2010 18:14:30 -0400
parents a222af1d0598
children ef28cbb5f464
line wrap: on
line diff
--- a/deep/convolutional_dae/scdae.py	Mon Mar 29 17:54:01 2010 -0400
+++ b/deep/convolutional_dae/scdae.py	Mon Mar 29 18:14:30 2010 -0400
@@ -40,12 +40,12 @@
         old_size = size
     return LayerStack(layers)
 
-def scdae_net(in_size, num_in, filter_sizes, num_filts, subsamplings,
+def scdae_net(in_size, filter_sizes, num_filts, subsamplings,
               corruptions, layer_sizes, out_size, dtype):
     rl1 = ReshapeLayer((None,)+in_size)
-    ls = scdae(num_in, filter_sizes, num_filts, subsamplings, 
+    ls = scdae(filter_sizes, num_filts, subsamplings, 
                corruptions, dtype)
-    x = T.tensor4()
+    x = T.ftensor4()
     ls.build(x, input_shape=(1,)+in_size)
     outs = numpy.prod(ls.output_shape)
     rl2 = ReshapeLayer((None, outs))
@@ -57,7 +57,7 @@
 def build_funcs(batch_size, img_size, filter_sizes, num_filters, subs,
                 noise, mlp_sizes, out_size, dtype, pretrain_lr, train_lr):
     
-    n = scdae_net((1,)+img_size, batch_size, filter_sizes, num_filters, subs,
+    n = scdae_net((1,)+img_size, filter_sizes, num_filters, subs,
                   noise, mlp_sizes, out_size, dtype)
 
     n.save('start.net')
@@ -73,7 +73,7 @@
         up = trainers.get_updates(net.params, net.cost, alpha)
         return theano.function([x, y], net.cost, updates=up)
 
-    n.build(x, y, input_shape=(bsize, 1)+img_size)
+    n.build(x, y, input_shape=(batch_size, numpy.prod(img_size)))
     pretrain_funcs_opt = [pretrainfunc(l, pretrain_lr) for l in n.layers[1].layers]
     trainf_opt = trainfunc(n, train_lr)
     evalf_opt = theano.function([x, y], errors.class_error(n.output, y))
@@ -186,16 +186,20 @@
     
     return series
 
+class PrintSeries(object):
+    def append(self, idx, v):
+        print idx, v
+
 if __name__ == '__main__':
     from ift6266 import datasets
     from sgd_opt import sgd_opt
     import sys, time
     
     batch_size = 100
-    dset = datasets.mnist()
+    dset = datasets.nist_digits(1000)
 
     pretrain_funcs, trainf, evalf, net = build_funcs(
-        img_size = (28, 28),
+        img_size = (32, 32),
         batch_size=batch_size, filter_sizes=[(5,5), (3,3)],
         num_filters=[4, 4], subs=[(2,2), (2,2)], noise=[0.2, 0.2],
         mlp_sizes=[500], out_size=10, dtype=numpy.float32,
@@ -209,7 +213,7 @@
     print "pretraining ...",
     sys.stdout.flush()
     start = time.time()
-    do_pretrain(pretrain_fs, 2500, DummySeries())
+    do_pretrain(pretrain_fs, 1000, PrintSeries())
     end = time.time()
     print "done (in", end-start, "s)"