def test_per_pixel_conditional_conv_depth3(self): # From the paper https://arxiv.org/abs/2003.05664 out = deepmac_meta_arch.per_pixel_conditional_conv( tf.zeros((10, 32, 32, 10)), tf.zeros((10, 169)), 8, 3) self.assertEqual(out.shape, (10, 32, 32, 1))
def test_per_pixel_conditional_conv_depth2(self): num_params = ( 7 * 9 + 9 + # layer 1 9 + 1) # layer 2 out = deepmac_meta_arch.per_pixel_conditional_conv( tf.zeros((10, 32, 32, 7)), tf.zeros((10, num_params)), 9, 2) self.assertEqual(out.shape, (10, 32, 32, 1))
def test_per_pixel_conditional_conv_shape(self, num_input_channels, instance_embedding_dim, channels, depth): out = deepmac_meta_arch.per_pixel_conditional_conv( tf.zeros((10, 32, 32, num_input_channels)), tf.zeros((10, instance_embedding_dim)), channels, depth) self.assertEqual(out.shape, (10, 32, 32, 1))
def test_per_pixel_conditional_conv_value_depth2_single(self): input_tensor = tf.constant(np.array([2])) input_tensor = tf.reshape(input_tensor, (1, 1, 1, 1)) instance_embedding = tf.constant(np.array([-2, 3, 100, 5])) instance_embedding = tf.reshape(instance_embedding, (1, 4)) out = deepmac_meta_arch.per_pixel_conditional_conv(input_tensor, instance_embedding, channels=1, depth=2) expected_output = np.array([5]) expected_output = np.reshape(expected_output, (1, 1, 1, 1)) self.assertAllClose(expected_output, out)
def test_per_pixel_conditional_conv_value_depth1(self): input_tensor = tf.constant(np.array([1, 2, 3])) input_tensor = tf.reshape(input_tensor, (1, 1, 1, 3)) instance_embedding = tf.constant(np.array([1, 10, 100, 1000])) instance_embedding = tf.reshape(instance_embedding, (1, 4)) out = deepmac_meta_arch.per_pixel_conditional_conv(input_tensor, instance_embedding, channels=3, depth=1) expected_output = np.array([1321]) expected_output = np.reshape(expected_output, (1, 1, 1, 1)) self.assertAllClose(expected_output, out)
def test_per_pixel_conditional_conv_value_depth2_identity(self): input_tensor = tf.constant(np.array([1, 2])) input_tensor = tf.reshape(input_tensor, (1, 1, 1, 2)) instance_embedding = tf.constant( np.array([1, 0, 0, 1, 1, -3, 5, 100, -9])) instance_embedding = tf.reshape(instance_embedding, (1, 9)) out = deepmac_meta_arch.per_pixel_conditional_conv(input_tensor, instance_embedding, channels=2, depth=2) expected_output = np.array([1]) expected_output = np.reshape(expected_output, (1, 1, 1, 1)) self.assertAllClose(expected_output, out)
def test_per_pixel_conditional_conv_depth1(self): out = deepmac_meta_arch.per_pixel_conditional_conv( tf.zeros((10, 32, 32, 7)), tf.zeros((10, 8)), 7, 1) self.assertEqual(out.shape, (10, 32, 32, 1))
def test_per_pixel_conditional_conv_depth1_error(self): with self.assertRaises(ValueError): _ = deepmac_meta_arch.per_pixel_conditional_conv( tf.zeros((10, 32, 32, 7)), tf.zeros((10, 8)), 99, 1)
def test_per_pixel_conditional_conv_error(self): with self.assertRaises(ValueError): deepmac_meta_arch.per_pixel_conditional_conv( tf.zeros((10, 32, 32, 8)), tf.zeros((10, 2)), 8, 3)