Commit 43b3c006 authored by acivgin1's avatar acivgin1
Browse files

switch to new VoxelGenerator

parent 9d9e9b85
...@@ -31,7 +31,8 @@ class DatasetTemplate(torch_data.Dataset): ...@@ -31,7 +31,8 @@ class DatasetTemplate(torch_data.Dataset):
self.root_path, self.dataset_cfg.DATA_AUGMENTOR, self.class_names, logger=self.logger self.root_path, self.dataset_cfg.DATA_AUGMENTOR, self.class_names, logger=self.logger
) if self.training else None ) if self.training else None
self.data_processor = DataProcessor( self.data_processor = DataProcessor(
self.dataset_cfg.DATA_PROCESSOR, point_cloud_range=self.point_cloud_range, training=self.training self.dataset_cfg.DATA_PROCESSOR, point_cloud_range=self.point_cloud_range,
training=self.training, num_point_features=self.point_feature_encoder.num_point_features
) )
self.grid_size = self.data_processor.grid_size self.grid_size = self.data_processor.grid_size
......
from functools import partial from functools import partial
import cumm.tensorview as tv
import numpy as np import numpy as np
from skimage import transform from skimage import transform
from spconv.utils import Point2VoxelCPU3d as VoxelGenerator
from ...utils import box_utils, common_utils from ...utils import box_utils, common_utils
class DataProcessor(object): class DataProcessor(object):
def __init__(self, processor_configs, point_cloud_range, training): def __init__(self, processor_configs, point_cloud_range, training, num_point_features):
self.point_cloud_range = point_cloud_range self.point_cloud_range = point_cloud_range
self.training = training self.training = training
self.num_point_features = num_point_features
self.mode = 'train' if training else 'test' self.mode = 'train' if training else 'test'
self.grid_size = self.voxel_size = None self.grid_size = self.voxel_size = None
self.data_processor_queue = [] self.data_processor_queue = []
...@@ -46,16 +49,12 @@ class DataProcessor(object): ...@@ -46,16 +49,12 @@ class DataProcessor(object):
def transform_points_to_voxels(self, data_dict=None, config=None, voxel_generator=None): def transform_points_to_voxels(self, data_dict=None, config=None, voxel_generator=None):
if data_dict is None: if data_dict is None:
try:
from spconv.utils import VoxelGeneratorV2 as VoxelGenerator
except:
from spconv.utils import VoxelGenerator
voxel_generator = VoxelGenerator( voxel_generator = VoxelGenerator(
voxel_size=config.VOXEL_SIZE, vsize_xyz=config.VOXEL_SIZE,
point_cloud_range=self.point_cloud_range, coors_range_xyz=self.point_cloud_range,
max_num_points=config.MAX_POINTS_PER_VOXEL, num_point_features=self.num_point_features,
max_voxels=config.MAX_NUMBER_OF_VOXELS[self.mode] max_num_points_per_voxel=config.MAX_POINTS_PER_VOXEL,
max_num_voxels=config.MAX_NUMBER_OF_VOXELS[self.mode]
) )
grid_size = (self.point_cloud_range[3:6] - self.point_cloud_range[0:3]) / np.array(config.VOXEL_SIZE) grid_size = (self.point_cloud_range[3:6] - self.point_cloud_range[0:3]) / np.array(config.VOXEL_SIZE)
self.grid_size = np.round(grid_size).astype(np.int64) self.grid_size = np.round(grid_size).astype(np.int64)
...@@ -63,12 +62,12 @@ class DataProcessor(object): ...@@ -63,12 +62,12 @@ class DataProcessor(object):
return partial(self.transform_points_to_voxels, voxel_generator=voxel_generator) return partial(self.transform_points_to_voxels, voxel_generator=voxel_generator)
points = data_dict['points'] points = data_dict['points']
voxel_output = voxel_generator.generate(points) voxel_output = voxel_generator.point_to_voxel(tv.from_numpy(points))
if isinstance(voxel_output, dict): tv_voxels, tv_coordinates, tv_num_points = voxel_output
voxels, coordinates, num_points = \ # make copy with numpy(), since numpy_view() will disappear as soon as the generator is deleted
voxel_output['voxels'], voxel_output['coordinates'], voxel_output['num_points_per_voxel'] voxels = tv_voxels.numpy()
else: coordinates = tv_coordinates.numpy()
voxels, coordinates, num_points = voxel_output num_points = tv_num_points.numpy()
if not data_dict['use_lead_xyz']: if not data_dict['use_lead_xyz']:
voxels = voxels[..., 3:] # remove xyz in voxels(N, 3) voxels = voxels[..., 3:] # remove xyz in voxels(N, 3)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment