Skip to content

Instantly share code, notes, and snippets.

@Sentient07
Last active January 11, 2017 21:39
Show Gist options
  • Save Sentient07/e74f48e82d0e184a49f46827be90ac1f to your computer and use it in GitHub Desktop.
Save Sentient07/e74f48e82d0e184a49f46827be90ac1f to your computer and use it in GitHub Desktop.
Failing test for variable stride
import theano
from theano import tensor as T
from theano.tensor.signal.pool import pool_2d
import numpy as np
def spp_pooling(data, out_dimension, data_shape):
input_size = data_shape[2:]
pooled_data_list = []
for pool_dim in out_dimension:
pool_size = tuple((i + pool_dim -1) // pool_dim for i in input_size)
stride_size = tuple((i // pool_dim) for i in input_size)
pooled_part = pool_2d(data, pool_size, ignore_border=True, stride=stride_size, padding=(0, 0), mode='max')
pooled_part = pooled_part.flatten(3)
pooled_data_list.append(pooled_part)
return T.concatenate(pooled_data_list, axis=2)
# ran_input = np.random.random((1,3,4,4))
# x = theano.shared(ran_input)
y = T.tensor4()
inp_shape = y.shape
data_shape = (1,2,4,4)
z = spp_pooling(y, [2], inp_shape)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment