def get_output_for(self, input, **kwargs):
input_shape = input.shape
if self.dilation[0] > 1:
# pad such that the time axis length is divisible by the dilation factor
pad_w = (self.dilation[0] - input_shape[2] % self.dilation[0]) % self.dilation[0]
input = T.concatenate((input, T.zeros((input_shape[0], input_shape[1], pad_w, input_shape[3]), input.dtype)), axis=2)
# rearrange data to fold the time axis into the minibatch dimension
input = input.reshape((input_shape[0], input_shape[1], -1, self.dilation[0], input_shape[3]))
input = input.transpose(0, 3, 1, 2, 4)
input = input.reshape((-1,) + tuple(input.shape[2:]))
output = super(TimeDilatedMaxPool2DLayer, self).get_output_for(input, **kwargs)
if self.dilation[0] > 1:
# restore the time axis from the minibatch dimension
output = output.reshape((input_shape[0], self.dilation[0]) + tuple(output.shape[1:]))
output = output.transpose(0, 2, 3, 1, 4)
output = output.reshape((input_shape[0], output.shape[1], -1, output.shape[4]))
# remove the padding
output = output[:, :, :output.shape[2] - pad_w]
return output
评论列表
文章目录