Gaussian Wild 运行自己的数据集

Gaussian-wild

文件目录

sacre_coeur/
├── dense/
│ ├── images/
│ ├── sparse/不需要/0/
│ ├── stereo/非必需

├──sacre.tsv

需要自己写一个生成tsv文件的代码

import os

def read_cameras_text(cameras_txt_path):
    """
    从 COLMAP 的 cameras.txt 中读取相机信息
    """
    cameras = {}
    if not os.path.exists(cameras_txt_path):
        raise FileNotFoundError(f"{cameras_txt_path} 不存在,请检查路径。")

    with open(cameras_txt_path, "r", encoding="utf-8") as f:
        for line in f:
            line = line.strip()
            # 跳过注释和空行
            if line.startswith("#") or len(line) == 0:
                continue
            elems = line.split()
            camera_id = int(elems[0])
            model = elems[1]
            width = int(elems[2])
            height = int(elems[3])
            params = list(map(float, elems[4:]))

            cameras[camera_id] = {
                "model": model,
                "width": width,
                "height": height,
                "params": params
            }
    return cameras


def read_images_text(images_txt_path):
    """
    从 COLMAP 的 images.txt 中读取图像信息(位姿等)
    """
    images = []
    if not os.path.exists(images_txt_path):
        raise FileNotFoundError(f"{images_txt_path} 不存在,请检查路径。")

    with open(images_txt_path, "r", encoding="utf-8") as f:
        lines = f.readlines()

    idx = 0
    while idx < len(lines):
        line = lines[idx].strip()
        # 跳过注释和空行
        if line.startswith("#") or len(line) == 0:
            idx += 1
            continue

        # 解析图像的第一行
        elems = line.split()
        image_id = int(elems[0])
        # qw, qx, qy, qz
        q = list(map(float, elems[1:5]))
        # tx, ty, tz
        t = list(map(float, elems[5:8]))
        camera_id = int(elems[8])
        # 剩余部分是图像文件名
        image_name = " ".join(elems[9:])

        images.append({
            "image_id": image_id,
            "q": q,
            "t": t,
            "camera_id": camera_id,
            "image_name": image_name
        })

        idx += 1
        # 跳过下一行 (2D特征点信息)
        if idx < len(lines):
            idx += 1

    return images


def generate_tsv_file(cameras, images, output_path):
    """
    生成符合 GSW 需求的 TSV 文件,包含最关键的三列:
      - filename:  对应原本的 image_name
      - id:        对应原本的 image_id
      - split:     表示训练/测试集 (如果没有区分需求,可一律设为train)
    
    其余信息可按需保留:
      camera_id, width, height, model, params, q, t
    """
    with open(output_path, "w", encoding="utf-8") as fid:
        # 注意列顺序:GSW会用到 filename / id / split
        fid.write("filename\tid\tsplit\tcamera_id\twidth\theight\tmodel\tparams\tq\tt\n")
        for img in images:
            cam = cameras[img["camera_id"]]
            cam_params_str = " ".join(map(str, cam["params"]))
            q_str = " ".join(map(str, img["q"]))
            t_str = " ".join(map(str, img["t"]))

            # 如果不区分 train/test,可全部写成 "train"
            # 或者你也可以根据某种逻辑判断是 "train" 还是 "test"
            split_str = "train"

            row = (
                f"{img['image_name']}\t"    # filename
                f"{img['image_id']}\t"      # id
                f"{split_str}\t"           # split
                f"{img['camera_id']}\t"
                f"{cam['width']}\t"
                f"{cam['height']}\t"
                f"{cam['model']}\t"
                f"{cam_params_str}\t"
                f"{q_str}\t"
                f"{t_str}\n"
            )
            fid.write(row)


if __name__ == "__main__":
    # 假设你的txt文件在 <current_directory>/sparse/ 下
    current_directory = os.path.dirname(os.path.abspath(__file__))
    colmap_data_path = os.path.join(current_directory, "sparse")

    cameras_txt_path = os.path.join(colmap_data_path, "cameras.txt")
    images_txt_path = os.path.join(colmap_data_path, "images.txt")

    # 生成的 TSV,直接放在当前脚本同级目录下
    output_tsv_path = os.path.join(current_directory, "images.tsv")

    # 读取相机与图像信息
    cameras_dict = read_cameras_text(cameras_txt_path)
    images_list = read_images_text(images_txt_path)

    # 生成 TSV (包含 filename, id, split 等列)
    generate_tsv_file(cameras_dict, images_list, output_tsv_path)

    print(f"TSV 文件已生成: {output_tsv_path}")

之后要将tsv文件放到root_dir所在目录的上级目录

之后我们要把自己的datasets伪装成官方的数据集来运行

写了个自动化的bash指令来运行全部程序

#!/bin/bash

# 设置场景名称和路径
SCENE_NAME="sacre_coeur"
DATA_NAME="tum" #在这里修改为自己的数据集
SOURCE_PATH="/root/autodl-fs/Gaussian-Wild/data/${DATA_NAME}/dense"  
MODEL_PATH="outputs/${DATA_NAME}/model"


# 创建输出目录
mkdir -p ${MODEL_PATH}

# 训练
echo "Starting training for ${SCENE_NAME}..."
CUDA_VISIBLE_DEVICES=0 python ./train.py \
    --source_path ${SOURCE_PATH} \
    --scene_name ${SCENE_NAME} \
    --model_path ${MODEL_PATH} \
    --eval \
    --resolution 2 \
    --iterations 10000

# 渲染结果
echo "Rendering training and testing results..."
CUDA_VISIBLE_DEVICES=0 python ./render.py \
    --model_path ${MODEL_PATH}

# # 渲染多视角视频
# echo "Rendering multi-view video..."
# CUDA_VISIBLE_DEVICES=0 python ./render.py \
#     --model_path ${MODEL_PATH} \
#     --skip_train \
#     --skip_test \
#     --render_multiview_vedio

# # 渲染外观调整效果
# echo "Rendering appearance tuning..."
# CUDA_VISIBLE_DEVICES=0 python ./render.py \
#     --model_path ${MODEL_PATH} \
#     --skip_train \
#     --skip_test \
#     --render_interpolate

# # 评估右半部分
# echo "Evaluating right half metrics..."
# CUDA_VISIBLE_DEVICES=0 python ./metrics_half.py \
#     --model_path ${MODEL_PATH}

# # 评估全图像
# echo "Evaluating full image metrics..."
# CUDA_VISIBLE_DEVICES=0 python ./metrics.py \
#     --model_path ${MODEL_PATH}

echo "All tasks completed!"
<think>好的,我现在需要帮助用户了解如何使用3D Gaussian Splatting方法在mipnerf数据集上进行实现和设置。首先,我需要回顾一下3D Gaussian Splatting的基本原理,确保自己理解正确。这种方法主要用于3D场景重建和新视角合成,通过高斯分布来表示场景中的点,并进行可微渲染优化。接下来,我得考虑如何将它与mipnerf数据集结合起来,可能需要数据预处理步骤,比如将mipnerf的数据格式转换为适合3D Gaussian Splatting的输入。 然后,我应该检查官方实现是否有支持mipnerf的配置或者需要用户自行调整。用户可能需要安装特定的依赖项,比如PyTorch、CUDA等,以及可能的可视化工具。另外,训练参数的设置也很重要,比如学习率、迭代次数,这些可能需要根据数据集的特点进行调整。 还需要考虑数据集的路径配置问题,用户可能需要修改配置文件中的数据集路径,或者编写自定义的数据加载器。此外,训练完成后,如何评估模型性能,比如使用PSNR、SSIM等指标,以及如何渲染新视角的图片,这些步骤都需要详细说明。 用户可能遇到的问题包括环境配置错误、数据格式不匹配、训练过程中的内存不足等,我需要提前想到这些并提供解决方案。比如建议使用更高显存的GPU,或者调整批量大小。最后,生成相关问题时要围绕实现细节、优化方法和应用场景展开,确保覆盖用户可能的后续疑问。</think>### 使用3D Gaussian Splatting运行mipnerf数据集的实现指南 #### 1. 环境配置 - **基础依赖**: 需要安装PyTorch、CUDA、Python 3.8+等工具,推荐使用Anaconda创建虚拟环境: ```bash conda create -n gsplat python=3.8 conda activate gsplat pip install torch torchvision torchaudio --extra-index-url https://download.pytorch.org/whl/cu116 ``` - **扩展库**: 安装3D Gaussian Splatting官方实现库[^1]: ```bash git clone https://github.com/graphdeco-inria/gaussian-splatting cd gaussian-splatting pip install -r requirements.txt ``` #### 2. 数据集准备 - **mipnerf数据格式转换**: - mipnerf数据集通常采用`nerfstudio`格式,需转换为COLMAP格式 - 使用官方提供的转换脚本: ```python python convert_mipnerf_to_colmap.py --input_dir /path/to/mipnerf --output_dir /data/colmap ``` - 验证生成的文件结构: ``` data/colmap/ ├── images/ # 所有训练图像 ├── sparse/0/ # COLMAP稀疏点云 └── cameras.json # 相机参数 ``` #### 3. 训练配置 - **参数设置**(以`train.json`为例): ```json { "data_path": "/data/colmap", "iterations": 30000, "position_lr": 0.00016, "feature_lr": 0.0025, "opacity_lr": 0.05, "scaling_lr": 0.005, "rotation_lr": 0.001, "lambda_dssim": 0.2 } ``` - **启动训练**: ```bash python train.py -s /data/colmap -m /output_model --config train.json ``` #### 4. 可视化与评估 - **实时预览**: ```bash python viewer.py --model /output_model ``` - **定量评估**: ```python python evaluate.py --model /output_model --dataset /test_data ``` 输出指标包括PSNR、SSIM、LPIPS等[^2] #### 5. 常见问题解决 - **显存不足**: 调整`batch_size`参数或使用`--resolution 2`降低输入分辨率 - **点云初始化失败**: 检查COLMAP重建质量,确保有足够特征点匹配 - **渲染伪影**: 尝试增加高斯密度约束权重`--lambda_density 0.01`
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值