def test_generate_2d_neighbors_dilation2(self): inp = np.arange(16).reshape(1, 4, 4, 1).astype(np.float32) out = deepmac_meta_arch.generate_2d_neighbors(inp, dilation=2) self.assertEqual((8, 1, 4, 4, 1), out.shape) expected = np.array([0, 0, 0, 0, 2, 0, 8, 10]) self.assertAllEqual(out[:, 0, 0, 0, 0], expected)
def test_generate_2d_neighbors(self): inp = np.arange(16).reshape(4, 4).astype(np.float32) inp = tf.stack([inp, inp * 2], axis=2) out = deepmac_meta_arch.generate_2d_neighbors(inp, dilation=1) self.assertEqual((8, 4, 4, 2), out.shape) for i in range(2): expected = np.array([0, 1, 2, 4, 6, 8, 9, 10]) * (i + 1) self.assertAllEqual(out[:, 1, 1, i], expected) expected = np.array([1, 2, 3, 5, 7, 9, 10, 11]) * (i + 1) self.assertAllEqual(out[:, 1, 2, i], expected) expected = np.array([4, 5, 6, 8, 10, 12, 13, 14]) * (i + 1) self.assertAllEqual(out[:, 2, 1, i], expected) expected = np.array([5, 6, 7, 9, 11, 13, 14, 15]) * (i + 1) self.assertAllEqual(out[:, 2, 2, i], expected)
def test_generate_2d_neighbors_shape(self): inp = tf.zeros((13, 14, 3)) out = deepmac_meta_arch.generate_2d_neighbors(inp) self.assertEqual((8, 13, 14, 3), out.shape)