目录
- 3D Gaussian splatting 01: 环境搭建
- 3D Gaussian splatting 02: 快速评估
- 3D Gaussian splatting 03: 用户数据训练和结果查看
- 3D Gaussian splatting 04: 代码阅读-提取相机位姿和稀疏点云
- 3D Gaussian splatting 05: 代码阅读-训练整体流程
- 3D Gaussian splatting 06: 代码阅读-训练参数
- 3D Gaussian splatting 07: 代码阅读-训练载入数据和保存结果
- 3D Gaussian splatting 08: 代码阅读-渲染
训练载入数据
在 train.py 中载入数据对应的方法调用栈如下, 因为convert.py预处理使用的是colmap, 读取数据最终调用的是 readColmapSceneInfo 方法- Scene(dataset, gaussians)
- └─sceneLoadTypeCallbacks["Colmap"](args.source_path, args.images, args.depths, args.eval, args.train_test_exp)
- └─readColmapSceneInfo(path, images, depths, eval, train_test_exp, llffhold=8)
复制代码 读取流程是
- 从 images.bin, cameras.bin 读取相机参数和每一帧的位姿
- 区分训练集和测试集
- 从 points3D.bin 读取3D点云
- def read_points3D_binary(path_to_model_file):
- """
- see: src/base/reconstruction.cc
- void Reconstruction::ReadPoints3DBinary(const std::string& path)
- void Reconstruction::WritePoints3DBinary(const std::string& path)
- """
- with open(path_to_model_file, "rb") as fid:
- num_points = read_next_bytes(fid, 8, "Q")[0]
- # 创建未初始化的 n * 3 数组, 随机值
- xyzs = np.empty((num_points, 3))
- rgbs = np.empty((num_points, 3))
- errors = np.empty((num_points, 1))
- for p_id in range(num_points):
- binary_point_line_properties = read_next_bytes(
- fid, num_bytes=43, format_char_sequence="QdddBBBd")
- xyz = np.array(binary_point_line_properties[1:4])
- rgb = np.array(binary_point_line_properties[4:7])
- error = np.array(binary_point_line_properties[7])
- track_length = read_next_bytes(
- fid, num_bytes=8, format_char_sequence="Q")[0]
- track_elems = read_next_bytes(
- fid, num_bytes=8*track_length,
- format_char_sequence="ii"*track_length)
- xyzs[p_id] = xyz
- rgbs[p_id] = rgb
- errors[p_id] = error
- return xyzs, rgbs, errors
复制代码 里面用到的read_next_bytes方法, 读取一段二进制字节, 使用struct.unpack按指定的格式, 转为对应的变量
[code]def read_next_bytes(fid, num_bytes, format_char_sequence, endian_character=" |