参考import os import pdb import csv import numpy as np import cv2 import torch import…
- User
参考import os import pdb
import csv
import numpy as np import cv2 import torch import pandas as pd from tqdm import tqdm import scipy.io from spconv.pytorch.utils import PointToVoxel from dv import AedatFile import numpy as np import multiprocessing os.environ["CUDA_VISIBLE_DEVICES"] = "0"
def transform_points_to_voxels(data_dict={}, voxel_generator=None, device=torch.device("cuda:0")): """ 将点云转换为voxel,调用spconv的VoxelGeneratorV2 """ points = data_dict['points'] # 将points打乱 shuffle_idx = np.random.permutation(points.shape[0]) points = points[shuffle_idx] data_dict['points'] = points
code# 使用spconv生成voxel输出 points = torch.as_tensor(data_dict['points']).to(device) voxel_output = voxel_generator(points) # 假设一份点云数据是N*4,那么经过pillar生成后会得到三份数据 # voxels代表了每个生成的voxel数据,维度是[M, 5, 4] # coordinates代表了每个生成的voxel所在的zyx轴坐标,维度是[M,3] # num_points代表了每个生成的voxel中有多少个有效的点维度是[m,],因为不满5会被0填充 voxels, coordinates, num_points = voxel_output voxels = voxels.to(device) coordinates = coordinates.to(device) num_points = num_points.to(device) # 选event数量在前5000的voxel 8000 from(4k+,6k+) # print(torch.where(num_points>=16)[0].shape) if num_points.shape[0] < save_voxel: features = voxels[:, :, 3] coor = coordinates[:, :] else: _, voxels_idx = torch.topk(num_points, save_voxel) # 将每个voxel的1024个p拼接作为voxel初始特征 16 features = voxels[voxels_idx][:, :, 3] # 前5000个voxel的三维坐标 coor = coordinates[voxels_idx] # 将y.x.t改为t,x,y coor[:, [0, 1, 2]] = coor[:, [2, 1, 0]] return coor, featuresif name == 'main': save_voxel = 5000 use_mode = 'frame_exposure_time' device = torch.device("cuda:0") # data_path = r"/home/ioe/xxxxx/EventTracking/COESOT/train" data_path = r"/data2/local_userdata/heyuting/datasets/COESOT/test" save_path = r"/data2/local_userdata/heyuting/datasets/COESOT/test" # save_path = r"/home/ioe/xxxxx/COESOT/train" video_files = os.listdir(data_path) dvs_img_interval = 1 voxel_generator = PointToVoxel( # 给定每个voxel的长宽高 [0.05, 0.05, 0.1] vsize_xyz=[50, 10, 10], # [0.2, 0.25, 0.16] # [50, 10, 10] [50, 35, 26] 因此坐标范围(20,20,20) (20, 34/35, 26) # 给定点云的范围 [ 0. -40. -3. 70.4 40. 1. ] coors_range_xyz=[0, 0, 0, 1000, 345, 259], # 给定每个点云的特征维度,这里是x,y,z,r 其中r是激光雷达反射强度 # 346x260 t,x,y num_point_features=4, # 最多选取多少个voxel,训练16000,推理40000 max_num_voxels=16000, # 16000 # 给定每个pillar中有采样多少个点,不够则补0 因此我将neg voxel改为-1; max_num_points_per_voxel=16, # 1024 device=device )
- Assistant