File size: 4,369 Bytes
84d92e1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
# VLM 3R Data Processing


## 04.22 更新
- 整理输出,以及批量下载
- 使用ScanQA 的QA对

### 批量下载数据

#### scannat 数据集下载
这个数据集里只有800个
```bash
cd preprocessing
# -o 设置输出的路径 
python download_from_scan_id_txt.py -o ../data/raw_data/scannet --ids_file ../data/qa/scan_id.txt --type .sens --type _vh_clean_2.0.010000.segs.json --type .aggregation.json --type _vh_clean_2.ply
```

如果需要某个特定的id的话
```bash
python download-scannetv2.py -o ../data/raw_data/scannet --type .sens --type _vh_clean_2 --type .0.010000.segs.json --type .aggregation.json --type _vh_clean_2.ply --id scene0000_01
```

#### 采样图像

```bash
# num_frames 可以设置4-8 
python export_sampled_frames.py \
    --scans_dir ../data/raw_data/scannet/scans \
    --output_dir ../data/processed_data/ScanNet \
    --train_val_splits_path ./Benchmark \
    --num_frames 4 \
    --max_workers 8 \
    --image_size 480 640
```


#### 生成voxel

```bash
python ScanNet200/preprocess_scannet200.py \
        --dataset_root ../data/raw_data/scannet/scans \
        --output_root ../data/processed_data/scannet/point_cloud \
        --label_map_file .ScanNet200/scannetv2-labels.combined.tsv \
        --train_val_splits_path ScanNet200/Tasks \
        --num_workers 4 \
        --voxel_size 0.01 \
        --normalize_pointcloud
```



## 04.09 更新

04.09 处理了scannet数据集中关于scene0000_00的metadata。
1和2 执行完了之后,直接拿VLM-3R-DATA中的数据筛选了关于scene0000_00对应的QA,我突然发现这个QA非常的复杂,有很多的种类,同时输入的是视频。


### 数据结构

#### 图像/视频数据
`data/processed_data/ScanNet/videos/train`

#### **voxel的数据** 
 
 在VLM-3R/vlm_3r_data_process/data/processed_data/ScanNet/point_cloud/train下

`scene0000_00_voxel_0.1.ply`后面的数据对应不同的voxel_size 
voxel的结构:

- 这 N 行数据中,每一行代表一个体素块(Voxel)。由于我们做了 np.hstack 拼接,每一行的 8 个数值分别代表:

- [:, 0:3] (X, Y, Z): 这是体素的空间坐标。经过前面的处理(通常是除以 voxel_size 后向下取整),这些坐标通常已经变成了离散的整数索引。你可以把它理解为 3D 空间中网格的行、列、层号(比如 [10, 5, -2]),而不是真实的物理米数。

- [:, 3:6] (R, G, B): 颜色通道。也就是这个体素块呈现的颜色(通常是 0-255 的整数)。如果一个体素格子里原本包含了多个真实点,由于前面我们使用了 np.unique(..., return_index=True),这里保留的是第一个落入该格子的点的颜色。

- [:, 6] (Label): 语义标签(Semantic ID)。比如 3 代表椅子,4 代表桌子。用于语义分割任务。对应的种类在`VLM-3R/vlm_3r_data_process/datasets/ScanNet200/scannet200_constants.py`

- [:, 7] (Instance): 实例 ID(Instance ID)。用于区分同类物体的不同个体。比如场景里有两把椅子,它们的 Label 都是 3,但 Instance ID 可能是 101 和 102。

### 读取voxel

```python

def read_custom_ply(filepath):
    """
    第一步:读取包含自定义 label 和 instance_id 的 PLY 文件
    """
    print(f"正在读取文件: {filepath}")
    with open(filepath, 'rb') as f:
        plydata = PlyData.read(f)
    
    vertex_data = plydata['vertex'].data
    
    # 提取各个字段
    x = vertex_data['x']
    y = vertex_data['y']
    z = vertex_data['z']
    r = vertex_data['red']
    g = vertex_data['green']
    b = vertex_data['blue']
    label = vertex_data['label']
    instance = vertex_data['instance_id']
    
    # 拼装回 N x 8 的矩阵
    voxel_pc = np.vstack((x, y, z, r, g, b, label, instance)).T
    return voxel_pc

```
可视化可以运行
```bash
python vis_data_my.py
```
![voxel_rgb.png](assert/voxel_rgb.png)

![semantic.png](assert/semantic.png)



如果这些都不符合要求执行修改voxel_size.
```bash
python datasets/ScanNet200/preprocess_scannet200.py \
        --dataset_root ./data/raw_data/scannet/scans \
        --output_root ./data/processed_data/ScanNet/point_cloud \
        --label_map_file ./data/raw_data/scannet/scannetv2-labels.combined.tsv \
        --train_val_splits_path datasets/ScanNet200/Tasks \
        --num_workers 4 \
        --voxel_size 0.1
```