| 26 | |
| 27 | |
| 28 | def convpool(X, W, b, poolsize=(2, 2)): |
| 29 | conv_out = conv2d(input=X, filters=W) |
| 30 | |
| 31 | # downsample each feature map individually, using maxpooling |
| 32 | pooled_out = pool.pool_2d( |
| 33 | input=conv_out, |
| 34 | ws=poolsize, |
| 35 | ignore_border=True |
| 36 | ) |
| 37 | |
| 38 | # add the bias term. Since the bias is a vector (1D array), we first |
| 39 | # reshape it to a tensor of shape (1, n_filters, 1, 1). Each bias will |
| 40 | # thus be broadcasted across mini-batches and feature map |
| 41 | # width & height |
| 42 | # return T.tanh(pooled_out + b.dimshuffle('x', 0, 'x', 'x')) |
| 43 | return relu(pooled_out + b.dimshuffle('x', 0, 'x', 'x')) |
| 44 | |
| 45 | |
| 46 | def init_filter(shape, poolsz): |