Mercurial > pylearn
comparison pylearn/formulas/nnet.py @ 1489:35a3a4e2d999
added formulas/nnet.py with inverse_max_pooling(...)
author | Emmanuel Bengio <bengioe@iro.umontreal.ca> |
---|---|
date | Wed, 27 Jul 2011 10:37:41 -0400 |
parents | |
children | 9d2323513092 |
comparison
equal
deleted
inserted
replaced
1488:440e1afe28a3 | 1489:35a3a4e2d999 |
---|---|
1 import theano | |
2 from theano import tensor | |
3 from theano.sandbox import neighbours | |
4 | |
5 import tags | |
6 | |
7 | |
8 @tags.tags('nnet', 'max pooling', 'inverse') | |
9 def inverse_max_pooling(max_pool_out,output_shape,pooling_shape=(2,2), | |
10 ignore_borders = True): | |
11 """ | |
12 Return a symbolic variable representing the inverse of a max pooling | |
13 on a given tensor. | |
14 | |
15 Parameters | |
16 ---------- | |
17 max_pool_out : 4D tensor | |
18 A Theano variable representing the output of a max pooling | |
19 output_shape : 4D shape | |
20 The shape of the input before pooling | |
21 pooling_shape : 2D shape | |
22 The shape of the pooling windows | |
23 ignore_borders : boolean | |
24 Will pad borders with zeros if true | |
25 """ | |
26 # flatten the input and repeat it | |
27 repeated_input = [max_pool_out.flatten()]*(pooling_shape[0]*pooling_shape[1]) | |
28 | |
29 # concatenate the repeated vectors into | |
30 # a 2D matrix in the format neibs2images wants | |
31 stacked_conv_neibs = T.stack(*repeated_input).T | |
32 | |
33 # then get back a stretched version of the stacked neighbours | |
34 stretch_unpooling_out = \ | |
35 neighbours.neibs2images(stacked_conv_neibs, | |
36 pooling_shape, | |
37 output_shape, | |
38 'ignore_borders' if ignore_borders else 'valid') | |
39 return stretch_unpooling_out |