def test_transform_thin_plate_spline_shift(self): from lasagne.layers import InputLayer, TPSTransformerLayer from theano.tensor import constant batchsize = 5 num_control_points = 16 dest_offset = np.ones(shape=(batchsize, 2*num_control_points)) l_in = InputLayer((batchsize, 3, 28, 28)) l_loc = InputLayer((batchsize, 2*num_control_points)) layer = TPSTransformerLayer( l_in, l_loc, control_points=num_control_points ) image = np.zeros(shape=(28, 28)) image[[0, -1], :] = 1 image[:, [0, -1]] = 1 inputs = np.tile(image, (batchsize, 3, 1, 1)) shifted_input = np.ones(shape=(28, 28)) shifted_input[:13, :13] = 0 shifted_input[13, :13] = 0.50000271 shifted_input[:13, 13] = 0.50000271 shifted_input[13, 13] = 0.75000271 shifted_input = np.tile(shifted_input, (batchsize, 3, 1, 1)) outputs = layer.get_output_for([constant(inputs), constant(dest_offset)]).eval() np.testing.assert_allclose(shifted_input, outputs, atol=1e-5)
def test_transform_thin_plate_spline_identity(self): from lasagne.layers import InputLayer, TPSTransformerLayer from lasagne.utils import floatX from theano.tensor import constant batchsize = 5 num_control_points = 16 dest_offset = np.zeros(shape=(batchsize, 2 * num_control_points)) l_in = InputLayer((batchsize, 3, 28, 28)) l_loc = InputLayer((batchsize, 2 * num_control_points)) layer = TPSTransformerLayer(l_in, l_loc, control_points=num_control_points) inputs = floatX(np.arange(np.prod(l_in.shape)).reshape(l_in.shape)) outputs = layer.get_output_for( [constant(inputs), constant(dest_offset)]).eval() np.testing.assert_allclose(inputs, outputs, atol=1e-5)
def test_transform_thin_plate_spline_identity(self): from lasagne.layers import InputLayer, TPSTransformerLayer from lasagne.utils import floatX from theano.tensor import constant batchsize = 5 num_control_points = 16 dest_offset = np.zeros(shape=(batchsize, 2*num_control_points)) l_in = InputLayer((batchsize, 3, 28, 28)) l_loc = InputLayer((batchsize, 2*num_control_points)) layer = TPSTransformerLayer( l_in, l_loc, control_points=num_control_points ) inputs = floatX(np.arange(np.prod(l_in.shape)).reshape(l_in.shape)) outputs = layer.get_output_for([constant(inputs), constant(dest_offset)]).eval() np.testing.assert_allclose(inputs, outputs, atol=5e-4)