def generate_batched_random_point_clouds(size=100000, voxel_size=0.2, batch_size=2): batch = [] for i in range(batch_size): batch.append(generate_random_point_cloud(size, voxel_size)) return sparse_collate_fn(batch)
def pcd_uv_to_sparsetensor(pcd, u_u0, v_v0, mask_valid, f=500.0, voxel_size=0.01, mask_side=None, num_points=100000): if mask_side is not None: mask_valid = mask_valid & mask_side pcd_valid = pcd[mask_valid] u_u0_valid = u_u0[mask_valid][:, np.newaxis] / f v_v0_valid = v_v0[mask_valid][:, np.newaxis] / f block_ = np.concatenate([pcd_valid, u_u0_valid, v_v0_valid], axis=1) block = np.zeros_like(block_) block[:, :] = block_[:, :] pc_ = np.round(block_[:, :3] / voxel_size) pc_ -= pc_.min(0, keepdims=1) feat_ = block # transfer point cloud to voxels inds = sparse_quantize(pc_, feat_, return_index=True, return_invs=False) if len(inds) > num_points: inds = np.random.choice(inds, num_points, replace=False) pc = pc_[inds] feat = feat_[inds] lidar = SparseTensor(feat, pc) feed_dict = [{'lidar': lidar}] inputs = sparse_collate_fn(feed_dict) return inputs
def collate_fn(inputs): outputs = sparse_collate_fn(inputs) pts_batch = [] pred_obb_batch = [] for input in inputs: if not len(input['pred_obb_batch']) < 2: pts_batch += input['pts_batch'] pred_obb_batch.append(np.array(input['pred_obb_batch'])) outputs['pts_batch'] = pts_batch outputs['pred_obb_batch'] = pred_obb_batch return outputs
def pcd_to_sparsetensor(pcd, mask_valid, voxel_size=0.01, num_points=100000): pcd_valid = pcd[mask_valid] block_ = pcd_valid block = np.zeros_like(block_) block[:, :3] = block_[:, :3] pc_ = np.round(block_[:, :3] / voxel_size) pc_ -= pc_.min(0, keepdims=1) feat_ = block # transfer point cloud to voxels inds = sparse_quantize(pc_, feat_, return_index=True, return_invs=False) if len(inds) > num_points: inds = np.random.choice(inds, num_points, replace=False) pc = pc_[inds] feat = feat_[inds] lidar = SparseTensor(feat, pc) feed_dict = [{'lidar': lidar}] inputs = sparse_collate_fn(feed_dict) return inputs
def collate_fn(inputs): return sparse_collate_fn(inputs)