Ejemplo n.º 1
0
 def test_format_keeps_tf_as_tf(self):
     vg = tf.random.uniform((3, 3, 3))
     vg_formatted = format_voxelgrid(vg,
                                     leading_dim=False,
                                     trailing_dim=False)
     self.assertFalse(isinstance(vg_formatted, np.ndarray))
     self.assertTrue(tf.is_tensor(vg_formatted))
     self.assertEqual((3, 3, 3), vg_formatted.shape)
     self.assertTrue(tf.reduce_all(vg == vg_formatted))
Ejemplo n.º 2
0
 def test_format_keeps_numpy_as_numpy(self):
     vg = np.random.random((3, 3, 3))
     vg_formatted = format_voxelgrid(vg,
                                     leading_dim=False,
                                     trailing_dim=False)
     self.assertTrue(isinstance(vg_formatted, np.ndarray))
     self.assertFalse(tf.is_tensor(vg_formatted))
     self.assertEqual((3, 3, 3), vg_formatted.shape)
     self.assertTrue((vg == vg_formatted).all())
def simulate_depth_image(vg):
    """Note: I have a more efficient way to do this now. See conversions.py"""
    vg = conversions.format_voxelgrid(vg, False, False)
    size = vg.shape[1]
    z_inds = tf.expand_dims(tf.expand_dims(tf.range(size), axis=-1), axis=-1)
    z_inds = tf.repeat(tf.repeat(z_inds, size, axis=1), size, axis=2)
    z_inds = tf.cast(z_inds, tf.float32)
    dists = z_inds * vg + size * tf.cast(vg == 0, tf.float32)
    return tf.reduce_min(dists, axis=0)
 def test_get_depth_map(self):
     vg = np.zeros((3, 3, 3))
     vg[1, 1, 1] = 1.0
     vg[2, 1, 1] = 1.0
     vg[1, 1, 0] = 1.0
     vg = tf.cast(vg, tf.float32)
     img = data_tools.simulate_depth_image(vg)
     vg_2_5D, _ = data_tools.simulate_2_5D_input(
         conversions.format_voxelgrid(vg, False, True).numpy())
     img_from_2_5D = data_tools.simulate_depth_image(vg_2_5D)
     self.assertTrue((img == img_from_2_5D).numpy().all())
Ejemplo n.º 5
0
    def test_format_adds_and_removes_tf_dims(self):
        vg_neither = tf.random.uniform((3, 3, 3))
        vg_leading = format_voxelgrid(vg_neither,
                                      leading_dim=True,
                                      trailing_dim=False)
        vg_trailing = format_voxelgrid(vg_neither,
                                       leading_dim=False,
                                       trailing_dim=True)
        vg_both = format_voxelgrid(vg_neither,
                                   leading_dim=True,
                                   trailing_dim=True)
        self.assertEqual((1, 3, 3, 3), vg_leading.shape)
        self.assertEqual((3, 3, 3, 1), vg_trailing.shape)
        self.assertEqual((1, 3, 3, 3, 1), vg_both.shape)

        for vg in [vg_neither, vg_leading, vg_trailing, vg_both]:
            self.assertEqual((3, 3, 3),
                             format_voxelgrid(vg, False, False).shape)
            self.assertEqual((1, 3, 3, 3),
                             format_voxelgrid(vg, True, False).shape)
            self.assertEqual((3, 3, 3, 1),
                             format_voxelgrid(vg, False, True).shape)
            self.assertEqual((1, 3, 3, 3, 1),
                             format_voxelgrid(vg, True, True).shape)