错误:
ImportError: cannot import name 'VoxelGenerator' from 'spconv.utils
官方给的解释
-
VoxelGenerator has been replaced by
spconv.pytorch.utils.PointToVoxel
(torch API) or Point2VoxelGPU[1-4]d/Point2VoxelCPU[1-4]d (tv.Tensor API).网络上有很多的提到该错误但并没有彻底去解决,都是copy党
-
笔者给出两种解决办法
-
办法1:
-
将from spconv.utils import VoxelGeneratorV2 as VoxelGenerator
-
改为
-
import spconv.pytorch as spconv
from spconv.utils import Point2VoxelCPU3d as VoxelGenerator -
def transform_points_to_voxels(self, data_dict=None, config=None, voxel_generator=None): if data_dict is None: try: #from spconv.utils import VoxelGeneratorV2 as VoxelGenerator import spconv.pytorch as spconv from spconv.utils import Point2VoxelCPU3d as VoxelGenerator #from spconv.pytorch.utils import PointToVoxel except: from spconv.utils import Point2VoxelCPU3d as VoxelGenerator #from spconv.utils import VoxelGenerator #vsize_xyz: List[float[3]], coors_range_xyz: List[ #float[6]], num_point_features: int, max_num_voxels: int, max_num_points_per_voxel: int voxel_generator = VoxelGenerator( vsize_xyz=config.VOXEL_SIZE, coors_range_xyz=self.point_cloud_range, max_num_points_per_voxel=config.MAX_POINTS_PER_VOXEL, num_point_features=config.NUM_POINT_FEATURES, 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) self.grid_size = np.round(grid_size).astype(np.int64) self.voxel_size = config.VOXEL_SIZE return partial(self.transform_points_to_voxels, voxel_generator=voxel_generator)
提醒一句,新手的请注意
-
num_point_features=config.NUM_POINT_FEATURES, 这一行代码再原yaml文件里,是有这个数据的,把它复制一下在yaml里面就可以了
-
-
办法2:
-
将from spconv.utils import VoxelGeneratorV2 as VoxelGeneratorfrom
改为
spconv.pytorch.utils import PointToVoxel
二者效果一致,都可以使用
-
另外,笔者配置SSD环境sponcv为2.3.6;python 为3.7;