Skip to content

Fixed some minor bugs #24

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

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
12 changes: 12 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
fsc_data/data/images_1
fsc_data/data/images_3
fsc_data/inf_result
fsc_data/video

data_info_pre_test/*

gps_logger
ckpts/occformer_nusc_r50.pth
Visual/*
prediction/*
single_view_test_nus/*
110 changes: 110 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Python Debugger: Current File with Arguments",
"type": "debugpy",
"request": "launch",
"program": "${file}",
"console": "integratedTerminal",
"args": [
"${command:pickArgs}"
]
},
{
"name": "Debug test.pys",
"type": "debugpy",
"request": "launch",
"program": "${workspaceFolder}/tools/test.py", // 请确保路径正确
"console": "integratedTerminal",
"args": [
"./projects/configs/occformer_nusc/occformer_nusc_r50_256x704.py",
"./ckpts/occformer_nusc_r50.pth",
"--eval=bbox",
"--pred-save=/home2/wzc/OccFormer/fsc_data/inf_result/prediction",
"--cfg-options", "data.test.ann_file=/home2/wzc/OccFormer/fsc_data/data/infos/data_info_0_40.pkl"
],
"env": {
"PYTHONPATH": "${workspaceFolder}" // 可选,设置 Python 路径
},
"justMyCode": false // 允许调试库代码
},
{
"name": "Debug prepare_video_infos.py",
"type": "debugpy",
"request": "launch",
"program": "${workspaceFolder}/projects/mmdet3d_plugin/tools/prepare_video_infos.py",
"console": "integratedTerminal",
"args": [
"--src-path", "/home2/wzc/UniAD/data/occformer_infos/nuscenes_infos_temporal_val.pkl",
"--dst-path", "/home2/wzc/UniAD/data/occformer_infos/nuscenes_infos_temporal_val_visualize.pkl",
"--data-path", "/home2/wzc/UniAD/data/nuscenes"
],
"env": {
"PYTHONPATH": "${workspaceFolder}"
},
"justMyCode": false
},
{
"name": "Debug visualize_nusc_video.py",
"type": "debugpy",
"request": "launch",
"program": "${workspaceFolder}/projects/mmdet3d_plugin/visualize/visualize_nusc_video.py",
"console": "integratedTerminal",
"args": [
"/home2/wzc/OccFormer/single_view_test_nus/prediction",
"/home2/wzc/OccFormer/single_view_test_nus/visual",
"--scene-name", "scene-0012"
],
"env": {
"PYTHONPATH": "${workspaceFolder}"
},
"justMyCode": false,
// "preLaunchTask": "Run with xvfb",
},
{
"name": "Debug create_data.py",
"type": "debugpy",
"request": "launch",
"program": "${workspaceFolder}/tools/create_data.py",
"console": "integratedTerminal",
"args": [
"nuscenes",
"--root-path", "/home2/wzc/UniAD/data/nuscenes",
"--out-dir", "/home2/wzc/OccFormer/data_info_pre_test",
"--extra-tag", "nuscenes",
"--version", "v1.0",
"--canbus", "/home2/wzc/UniAD/data/nuscenes"
],
"env": {
"PYTHONPATH": "${workspaceFolder}"
},
"justMyCode": false
},
{
"name": "Debug dist_test.sh",
"type": "debugpy",
"request": "launch",
"program": "${workspaceFolder}/tools/test.py", // 请确保路径正确
"console": "integratedTerminal",
"args": [
"--nproc_per_node=1", // 设置 GPU 数量,这里设为1进行调试
"--master_port=29503", // 保持与 dist_test.sh 中的默认端口一致
"projects/configs/occformer_nusc/occformer_nusc_r50_256x704.py",
"/home2/wzc/OccFormer/ckpts/occformer_nusc_r50.pth",
"--launcher", "pytorch",
"--deterministic",
"--eval", "bbox",
"--pred-save", "/home2/wzc/OccFormer/fsc_data/inf_result/prediction",
"--cfg-options", "data.test.ann_file=/home2/wzc/OccFormer/fsc_data/data/infos/data_info_1.pkl"
],
"env": {
"PYTHONPATH": "${workspaceFolder}" // 可选,设置 Python 路径
},
"justMyCode": false // 允许调试库代码
},
]
}
20 changes: 20 additions & 0 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
// {
// "label": "Run with xvfb",
// "type": "shell",
// "command": "xvfb-run",
// "args": [
// "python",
// "${workspaceFolder}/projects/mmdet3d_plugin/visualize/visualize_nusc_video.py",
// "/home2/wzc/OccFormer/single_view_test/prediction",
// "/home2/wzc/OccFormer/single_view_test/visual",
// "--scene-name", "scene-0012"
// ],
// "problemMatcher": []
// }
]
}
138 changes: 138 additions & 0 deletions blender_code/vocel_to_3D_final.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
#如下代码的运行结果只是赋予不同物体不同的颜色,材质名称是依次命名为了"Material_{i}"

import bpy
import pickle
from mathutils import Vector

# 读取 .pkl 文件
file_path = '/Users/wangzhicheng/Desktop/FSD/Blender_3D/prediction/scene-0003/1533201470448696.pkl'
with open(file_path, 'rb') as file:
data = pickle.load(file)

# 体素参数
voxel_data = data['pred_voxels'] # (256, 256, 32)
voxel_size = (0.4, 0.4, 0.25) # 每个体素的实际大小 (x, y, z)
origin = (-51.2, -51.2, -5) # 场景的原点 (对应 voxel 的 (0, 0, 0))

# # 创建材质
# materials = []
# for i in range(17):
# mat = bpy.data.materials.new(name=f"Material_{i}")
# mat.diffuse_color = (i / 17, (17 - i) / 17, i / 34, 1)
# materials.append(mat)

# 物体类别和它们对应的颜色 (RGBA)
class_colors = [
[255, 120, 50, 255], # barrier orange
[255, 192, 203, 255], # bicycle pink
[255, 255, 0, 255], # bus yellow
[ 0, 150, 245, 255], # car blue
[ 0, 255, 255, 255], # construction_vehicle cyan
[255, 127, 0, 255], # motorcycle dark orange
[255, 0, 0, 255], # pedestrian red
[255, 240, 150, 255], # traffic_cone light yellow
[135, 60, 0, 255], # trailer brown
[160, 32, 240, 255], # truck purple
[255, 0, 255, 255], # driveable_surface dark pink
[139, 137, 137, 255], # other_flat dark red
[ 75, 0, 75, 255], # sidewalk dark purple
[150, 240, 80, 255], # terrain light green
[230, 230, 250, 255], # manmade white
[ 0, 175, 0, 255], # vegetation green
]

# 创建材质并设置颜色
materials = []
for i, color in enumerate(class_colors):
mat = bpy.data.materials.new(name=f"Material_{i}")
mat.diffuse_color = (color[0] / 255, color[1] / 255, color[2] / 255, color[3] / 255)
materials.append(mat)


#-----------------------------------方法1:直接生成一个网格对象,而不是单独添加立方体-------------------------
# 优化:批量创建体素网格
verts = []
faces = []
face_materials = [] # 存储每个面的材质
cube_count = 0

for x in range(len(voxel_data)):
for y in range(len(voxel_data[0])):
for z in range(len(voxel_data[0][0])):
value = voxel_data[x][y][z]
if value != 0 and 0 <= value-1 < len(materials): # 忽略值为 0 的体素
voxel_center = Vector(( # 计算体素中心的世界坐标
origin[0] + x * voxel_size[0] + voxel_size[0] / 2,
origin[1] + y * voxel_size[1] + voxel_size[1] / 2,
origin[2] + z * voxel_size[2] + voxel_size[2] / 2,
))

# 添加顶点 (立方体每个角点)
idx = len(verts)
size = Vector(voxel_size) / 2
verts.extend([ #添加立方体的 8 个顶点到 verts 列表中
voxel_center + Vector((-size.x, -size.y, -size.z)),
voxel_center + Vector(( size.x, -size.y, -size.z)),
voxel_center + Vector(( size.x, size.y, -size.z)),
voxel_center + Vector((-size.x, size.y, -size.z)),
voxel_center + Vector((-size.x, -size.y, size.z)),
voxel_center + Vector(( size.x, -size.y, size.z)),
voxel_center + Vector(( size.x, size.y, size.z)),
voxel_center + Vector((-size.x, size.y, size.z)),
])
# 添加面 (立方体的 6 个面)
faces.extend([ #为每个立方体添加 6 个面到 faces 列表中
(idx, idx+1, idx+2, idx+3),
(idx+4, idx+5, idx+6, idx+7),
(idx, idx+1, idx+5, idx+4),
(idx+1, idx+2, idx+6, idx+5),
(idx+2, idx+3, idx+7, idx+6),
(idx+3, idx, idx+4, idx+7),
])
# 为每个面分配材质
face_materials.extend([value-1] * 6) # 每个面使用同样的材质

cube_count += 1

# 创建网格对象
mesh = bpy.data.meshes.new("VoxelMesh") #创建一个新的网格对象(空网格)
mesh.from_pydata(verts, [], faces) #使用先前生成的顶点和面数据来填充网格对象
obj = bpy.data.objects.new("VoxelObject", mesh) #创建一个新的对象,将网格对象与新对象关联
bpy.context.collection.objects.link(obj) #将新对象链接到当前场景的集合中

# 将所有的材质添加到对象的材质槽中。这里你逐个将materials列表中的材质添加到网格对象obj的data.materials属性中
for i, mat in enumerate(materials):
obj.data.materials.append(mat)

# 为每个面分配对应的材质
for i, face in enumerate(mesh.polygons):
face.material_index = face_materials[i]

print(f"Generated {cube_count} cubes.")


#-----------------------------------方法2:单独添加立方体(软件会由于voxel过多直接卡死)-------------------------
# # 遍历体素数据,生成立方体
# for x in range(len(voxel_data)):
# for y in range(len(voxel_data[0])):
# for z in range(len(voxel_data[0][0])):
# value = voxel_data[x][y][z]
# if value != 0: # 忽略值为 0 的体素
# # 计算体素中心的世界坐标
# voxel_center = (
# origin[0] + x * voxel_size[0] + voxel_size[0] / 2,
# origin[1] + y * voxel_size[1] + voxel_size[1] / 2,
# origin[2] + z * voxel_size[2] + voxel_size[2] / 2,
# )

# # 添加立方体
# bpy.ops.mesh.primitive_cube_add(
# size=1,
# location=voxel_center,
# )

# # 缩放立方体到正确的体素大小
# bpy.context.object.scale = (voxel_size[0] / 2, voxel_size[1] / 2, voxel_size[2] / 2)

# # 分配材质
# bpy.context.object.data.materials.append(materials[value])
Loading