コード例 #1
0
    def test_pointcloud_to_voxel_grid_shapes(self):
        start_locations = [(-5, -5, -5), (0, 0, 0), (2.5, 2.5, 2.5)]
        end_locations = [(0, 0, 0), (10, 10, 10), (3, 3, 3)]
        grid_cell_sizes = [(0.5, 0.5, 0.5), (0.1, 0.1, 0.1), (0.5, 0.5, 0.5)]
        feature_dims = [3, 5, 10]

        expected_output_shapes = [(10, 10, 10, 3), (100, 100, 100, 5),
                                  (1, 1, 1, 10)]

        # For each test case we want to check if the output shape matches
        for test_case in range(3):
            points = tf.constant([[0.1, 0.1, 0.1]], tf.float32)
            features = tf.constant([list(range(feature_dims[test_case]))],
                                   tf.float32)

            voxel_grid, segment_ids, _ = voxel_utils.pointcloud_to_voxel_grid(
                points=points,
                features=features,
                grid_cell_size=grid_cell_sizes[test_case],
                start_location=start_locations[test_case],
                end_location=end_locations[test_case])

            self.assertEqual(voxel_grid.shape,
                             tuple(expected_output_shapes[test_case]))
            self.assertEqual(segment_ids.shape, (1, ))
コード例 #2
0
 def test_pointcloud_to_voxel_grid(self):
     points = self.get_sample_points()
     grid_cell_size = (20, 20, 20)
     start_location = (-20, -20, -20)
     end_location = (20, 20, 20)
     features = tf.constant(
         [[10.0, 12.0, 2.0, 1.0], [2.0, 10.0, 9.0, 0.0],
          [1.0, 11.0, 11.0, 1.0], [0.01, 1.01, 11.0, 0.0],
          [0.01, 0.01, 10.0, 1.0], [-1.0, 1.0, 11.0, 0.0],
          [11.0, 11.0, 1.0, 1.0], [11.0, 12.0, -1.0, 0.0],
          [0.01, 0.01, 11.0, 1.0], [0.01, 0.01, 11.0, 0.0]],
         dtype=tf.float32)
     voxel_features, _, _ = voxel_utils.pointcloud_to_voxel_grid(
         points=points,
         features=features,
         grid_cell_size=grid_cell_size,
         start_location=start_location,
         end_location=end_location)
     np_voxel_features = voxel_features.numpy()
     # [-20:0, -20:0, -20:0]
     self.assertAllClose(np_voxel_features[0, 0, 0, :],
                         [0.0, 0.0, 0.0, 0.0])
     # [-20:0, -20:0, 0:20]
     self.assertAllClose(np_voxel_features[0, 0, 1, :],
                         [0.0, 0.0, 0.0, 0.0])
     # [-20:0, 0:20, -20:0]
     self.assertAllClose(np_voxel_features[0, 1, 0, :],
                         [0.0, 0.0, 0.0, 0.0])
     # [-20:0, 20:0, 0:20]
     self.assertAllClose(np_voxel_features[0, 1, 1, :],
                         [-1.0, 1.0, 11.0, 0.0])
     # [0:20, -20:0, -20:0]
     self.assertAllClose(np_voxel_features[1, 0, 0, :],
                         [0.0, 0.0, 0.0, 0.0])
     # [0:20, -20:0, 0:20]
     self.assertAllClose(np_voxel_features[1, 0, 1, :],
                         [0.0, 0.0, 0.0, 0.0])
     # [0:20, 0:20, -20:0]
     self.assertAllClose(np_voxel_features[1, 1, 0, :],
                         [11.0, 12.0, -1.0, 0.0])
     # [0:20, 20:0, 0:20]
     self.assertAllClose(np_voxel_features[1, 1, 1, :],
                         [24.04 / 8.0, 45.04 / 8.0, 66.0 / 8.0, 5.0 / 8.0])
コード例 #3
0
 def test_pointcloud_to_voxel_grid_placement(self):
     points = tf.constant(
         [[0.5, 0.5, 0.5], [0.25, 0.25, 0.25], [1.6, 1.6, 1.6],
          [1.75, 1.75, 1.75], [1.9, 1.9, 1.9], [2.1, 2.1, 2.1],
          [2.3, 2.35, 2.37]],
         dtype=tf.float32)
     features = tf.constant(
         [[100, 110, 120], [120, 130, 140], [1, 2, 3], [2, 3, 4], [3, 4, 5],
          [1000, 500, 250], [200, 300, 150]],
         dtype=tf.float32)
     grid_cell_size = (1, 1, 1)
     start_location = (0, 0, 0)
     end_location = (10, 10, 10)
     voxel_features, segment_ids, _ = voxel_utils.pointcloud_to_voxel_grid(
         points=points,
         features=features,
         grid_cell_size=grid_cell_size,
         start_location=start_location,
         end_location=end_location)
     per_point_values = voxel_utils.voxels_to_points(
         voxel_features, segment_ids)
     np_voxel_features = voxel_features.numpy()
     np_segment_ids = segment_ids.numpy()
     np_per_point_values = per_point_values.numpy()
     # Check voxel grid values
     self.assertAllClose(np_voxel_features[0, 0, 0, :], [110, 120, 130])
     self.assertAllClose(np_voxel_features[1, 1, 1, :], [2, 3, 4])
     self.assertAllClose(np_voxel_features[2, 2, 2, :], [600, 400, 200])
     # Check values after mapping back to points
     self.assertAllClose(np_per_point_values[0, :], (110.0, 120.0, 130.0))
     self.assertAllClose(np_per_point_values[1, :], (110.0, 120.0, 130.0))
     self.assertAllClose(np_per_point_values[2, :], (2.0, 3.0, 4.0))
     self.assertAllClose(np_per_point_values[3, :], (2.0, 3.0, 4.0))
     self.assertAllClose(np_per_point_values[4, :], (2.0, 3.0, 4.0))
     self.assertAllClose(np_per_point_values[5, :], (600.0, 400.0, 200.0))
     self.assertAllClose(np_per_point_values[6, :], (600.0, 400.0, 200.0))
     # Check segment ids match what they should
     # Locations: [0, 0, 0] == 0, [1, 1, 1] == 111, [2, 2, 2] == 222
     self.assertAllEqual([0, 0, 111, 111, 111, 222, 222], np_segment_ids)