def _meshgrid(height, width): # This function is the grid generator from eq. (1) in reference [1]. # It is equivalent to the following numpy code: # x_t, y_t = np.meshgrid(np.linspace(-1, 1, width), # np.linspace(-1, 1, height)) # ones = np.ones(np.prod(x_t.shape)) # grid = np.vstack([x_t.flatten(), y_t.flatten(), ones]) # It is implemented in Theano instead to support symbolic grid sizes. # Note: If the image size is known at layer construction time, we could # compute the meshgrid offline in numpy instead of doing it dynamically # in Theano. However, it hardly affected performance when we tried. x_t = T.dot(T.ones((height, 1)), _linspace(-1.0, 1.0, width).dimshuffle('x', 0)) y_t = T.dot(_linspace(-1.0, 1.0, height).dimshuffle(0, 'x'), T.ones((1, width))) x_t_flat = x_t.reshape((1, -1)) y_t_flat = y_t.reshape((1, -1)) ones = T.ones_like(x_t_flat) grid = T.concatenate([x_t_flat, y_t_flat, ones], axis=0) return grid
def get_output_for(self, inputs, **kwargs): inputs = autocrop(inputs, self.cropping) return T.concatenate(inputs, axis=self.axis)