Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

infer_dit result in V100 #3

Open
arasika opened this issue Feb 28, 2025 · 2 comments
Open

infer_dit result in V100 #3

arasika opened this issue Feb 28, 2025 · 2 comments

Comments

@arasika
Copy link

arasika commented Feb 28, 2025

I ran the infer_dit.py script with the arguments -d DIT_CARLA and --best_vae, which generated many .npy files. When I attempted to visualize these .npy files, the resulting images were not as expected. It looks like BEV not occ. Could you help me understand what might have gone wrong or how I can improve the visualization?

Image

` # 1.load 16 .npy files and get voxel size (16,128, 128, 8)===========
for file_name in npy_files:
file_path = os.path.join(folder_path, file_name)
data = np.fromfile(file_path, dtype=np.int8).reshape((128, 128, 8))
data_list.append(data)

voxels = np.stack(data_list, axis=0)

# save (16,128, 128) point with color to .ply ===========
x = torch.arange(voxels.shape[0])  # 16
y = torch.arange(voxels.shape[1])  # 128
z = torch.arange(voxels.shape[2])  # 128
xx, yy, zz = torch.meshgrid(x, y, z, indexing='ij')
voxel_color = voxels[...,0].flatten()
indices = np.where(voxel_color == 6)
voxel_color = np.delete(voxel_color, indices, axis=0)
colors = np.array([
    [1.0, 0.0, 0.0],    # 红色
    [0.0, 1.0, 0.0],    # 绿色
    [0.0, 0.0, 1.0],    # 蓝色
    [1.0, 1.0, 0.0],    # 黄色
    [1.0, 0.0, 1.0],    # 粉红色
    [0.0, 1.0, 1.0],    # 青色
    [0.5, 0.5, 0.5],    # 灰色
    [1.0, 0.5, 0.0],    # 橙色
    [0.5, 1.0, 0.0],    # 浅绿色
    [0.0, 0.5, 1.0]     # 浅蓝色
])
mapped_colors = colors[voxel_color % 10] 
points = np.vstack([xx.flatten(), yy.flatten(), zz.flatten()]).T 
points = np.delete(points, indices, axis=0)
point_cloud = o3d.geometry.PointCloud()
point_cloud.points = o3d.utility.Vector3dVector(points)
point_cloud.colors = o3d.utility.Vector3dVector(mapped_colors)
o3d.io.write_point_cloud(base_path+"ply/"+str(path_id)+".ply", point_cloud)`
@bian-hengwei
Copy link
Collaborator

Hi, you may try the following method for visualization:

def get_mesh_open3d(voxel_map, shape, ignore, color_map, voxel_size, ignores=None):
    x, y, z = np.meshgrid(np.arange(shape[0]), np.arange(shape[1]), np.arange(shape[2]))
    positions = np.stack([y, x, z], axis=-1).reshape(-1, 3)

    mask = voxel_map.reshape(-1) != ignore

    if ignores is not None:
        for val in ignores:
            mask &= voxel_map.reshape(-1) != val

    positions = positions[mask]
    colors = np.array([color_map[voxel_map.reshape(-1)[i]] for i in np.where(mask)[0]]) / 255.0

    pcd = o3d.geometry.PointCloud()
    pcd.points = o3d.utility.Vector3dVector(positions * voxel_size)
    pcd.colors = o3d.utility.Vector3dVector(colors[:, ::-1])  # RGB to BGR

    voxel_grid = o3d.geometry.VoxelGrid.create_from_point_cloud(pcd, voxel_size=voxel_size)

    mesh = o3d.geometry.TriangleMesh()
    voxels = voxel_grid.get_voxels()
    for voxel in voxels:
        cube = o3d.geometry.TriangleMesh.create_box(width=voxel_size, height=voxel_size, depth=voxel_size)
        cube.paint_uniform_color(voxel.color)
        cube.translate(voxel.grid_index * voxel_size)
        mesh += cube

    vertices = np.asarray(mesh.vertices)
    faces = np.asarray(mesh.triangles)
    colors = np.asarray(mesh.vertex_colors)

    trimesh_mesh = trimesh.Trimesh(vertices=vertices, faces=faces, vertex_colors=colors)
    return trimesh_mesh, pyrender.Mesh.from_trimesh(trimesh_mesh, smooth=False)

@arasika
Copy link
Author

arasika commented Feb 28, 2025

Thank you! I've successfully obtained the result.

Image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants