def test_tf_batch_map_offsets(): np.random.seed(42) input = np.random.random((4, 100, 100)) offsets = np.random.random((4, 100, 100, 2)) * 2 sp_mapped_vals = sp_batch_map_offsets(input, offsets) tf_mapped_vals = tf_batch_map_offsets(K.variable(input), K.variable(offsets)) assert np.allclose(sp_mapped_vals, K.eval(tf_mapped_vals), atol=1e-5)
def call(self, x): inputs_shape = tf.shape(input=x) # super(ConvOffset2D, self).build(inputs_shape) offset = super(ConvOffset2D, self).call(x) # offset = slim.conv2d(x,self.filters*2,(3,3),padding='SAME') offset = self._to_bc_h_w_2(offset, inputs_shape) x = self._to_bc_h_w(x, inputs_shape) x_offset = tf_batch_map_offsets(x, offset) x_offset = self._to_b_h_w_c(x_offset, inputs_shape) return x_offset
def test_tf_batch_map_offsets_grad(): np.random.seed(42) input = np.random.random((4, 100, 100)) offsets = np.random.random((4, 100, 100, 2)) * 2 input = K.variable(input) offsets = K.variable(offsets) tf_mapped_vals = tf_batch_map_offsets(input, offsets) grad = K.gradients(tf_mapped_vals, input)[0] grad = K.eval(grad) assert not np.allclose(grad, 0)