### Install Dependencies Source: https://github.com/robot0321/depthregularizedgs/blob/main/README.md Set up the environment using the provided YAML file or install the rasterizer and PyTorch3D manually. ```bash ## (Option 1) 3DGS dependencies + depth rasterizer conda env create --file environment.yml conda activate DepthRegularizedGS ## (Option 2) If you already install the dependencies for 3DGS, just install the new (depth) rasterizer and pytorch3d pip install -e submodules/diff-gaussian-rasterization-depth-acc pip install pytorch3d ``` -------------------------------- ### Task Producer Configuration Example Source: https://context7.com/robot0321/depthregularizedgs/llms.txt Example configuration for `task_producer.py`, showing how to define scenes, shot counts, methods, and random seeds for experiments. Also lists method IDs used in `task_consumer.py`. ```python SCENES = ["fern", "flower", "fortress", "horns", "leaves", "orchids", "room", "trex"] SHOTS = [2, 3, 5] METHODS = [1, 2] # 1=baseline, 2=DRGS SEED_IDS = [0, 1, 2, 3, 4] # Method IDs in task_consumer.py: # 1: NeRF-LLFF + 3DGS baseline # 2: NeRF-LLFF + DRGS (ours) # 11: MipNeRF360 + 3DGS baseline # 12: MipNeRF360 + DRGS (ours) # 21: DTU + 3DGS baseline # 22: DTU + DRGS (ours) # 31: NeRF-Synthetic + 3DGS baseline # 32: NeRF-Synthetic + DRGS (ours) ``` -------------------------------- ### Initialize and Manage Scenes Source: https://context7.com/robot0321/depthregularizedgs/llms.txt Setup scene parameters, access camera viewpoints, and manage model loading iterations. ```python from scene import Scene, GaussianModel from arguments import ModelParams # Initialize scene with model parameters gaussians = GaussianModel(sh_degree=3) scene = Scene(model_params, gaussians, load_iteration=None, shuffle=True) # Access cameras train_cameras = scene.getTrainCameras(scale=1.0) test_cameras = scene.getTestCameras(scale=1.0) # Get scene extent for densification cameras_extent = scene.cameras_extent # Save point cloud at specific iteration scene.save(iteration=30000) # Load pre-trained model scene = Scene(model_params, gaussians, load_iteration=30000, shuffle=False) print(f"Loaded iteration: {scene.loaded_iter}") ``` -------------------------------- ### Initialize and Manage GaussianModel Source: https://context7.com/robot0321/depthregularizedgs/llms.txt Create and configure the 3D Gaussian point cloud model for training. ```python from scene.gaussian_model import GaussianModel from arguments import OptimizationParams # Initialize model with spherical harmonics degree gaussians = GaussianModel(sh_degree=3) # Create from point cloud data from utils.graphics_utils import BasicPointCloud pcd = BasicPointCloud(points=xyz_array, colors=rgb_array, normals=None) spatial_lr_scale = 1.0 gaussians.create_from_pcd(pcd, spatial_lr_scale) # Setup training with optimization parameters opt = OptimizationParams(parser).extract(args) gaussians.training_setup(opt) # Access model properties positions = gaussians.get_xyz # [N, 3] 3D positions opacities = gaussians.get_opacity # [N, 1] opacity values scales = gaussians.get_scaling # [N, 3] scale factors rotations = gaussians.get_rotation # [N, 4] rotation quaternions features = gaussians.get_features # [N, C, SH] spherical harmonic features ``` -------------------------------- ### Execute Rendering via CLI Source: https://context7.com/robot0321/depthregularizedgs/llms.txt Command-line interface for rendering test and training views from a trained model. ```bash # Render test and train views from trained model python render.py \ -m ./output/baseline/method2 \ --iteration 30000 # Render only test views python render.py \ -m ./output/baseline/method2 \ --iteration 30000 \ --skip_train # Render only train views python render.py \ -m ./output/baseline/method2 \ --iteration 30000 \ --skip_test ``` -------------------------------- ### Run Experiments with task_consumer.py Source: https://github.com/robot0321/depthregularizedgs/blob/main/README.md Execute experiments sequentially using the task list generated by `task_producer.py`. Specify the task list file and the GPU to use. Results are saved in the EXPERIMENT_PATH folder. For multi-GPU execution, generate separate task lists for each GPU. ```bash python scripts/task_consumer.py --tasklist ./scripts/all_tasks.txt --gpu 0 ``` -------------------------------- ### Configure and Produce Experiment Tasks Source: https://context7.com/robot0321/depthregularizedgs/llms.txt Sets up parameters for large-scale experiments by editing variables in `task_producer.py` and then generates a task list file. This prepares for running experiments across multiple scenes, shot counts, and methods. ```bash # Step 1: Configure experiments in task_producer.py # Edit SCENES, SHOTS, METHODS, SEED_IDS variables python scripts/task_producer.py ``` -------------------------------- ### Run Experiments with Task Consumer Source: https://context7.com/robot0321/depthregularizedgs/llms.txt Executes the generated experiment tasks using the `task_consumer.py` script. Specify the task list and the GPU to use. Multiple terminals can be used to run on different GPUs. ```bash python scripts/task_consumer.py \ --tasklist ./scripts/all_tasks.txt \ --gpu 0 ``` ```bash python scripts/task_consumer.py --tasklist ./scripts/all_tasks1.txt --gpu 0 python scripts/task_consumer.py --tasklist ./scripts/all_tasks2.txt --gpu 1 ``` -------------------------------- ### Configure Model Parameters Source: https://context7.com/robot0321/depthregularizedgs/llms.txt Initialize dataset loading parameters using the ModelParams class. ```python from arguments import ModelParams, PipelineParams, OptimizationParams from argparse import ArgumentParser parser = ArgumentParser() lp = ModelParams(parser) # Available parameters: # --source_path (-s): Path to dataset folder # --model_path (-m): Output model directory # --images (-i): Subfolder for images (default: "images") # --resolution (-r): Resolution scale (-1 for auto) # --white_background (-w): Use white background (for 360 datasets) # --data_device: Device for data (default: "cuda") # --eval: Enable train/test split evaluation # --seed: Random seed for reproducibility # --kshot: Number of training images for few-shot (default: 1000 = full) args = parser.parse_args() model_params = lp.extract(args) ``` -------------------------------- ### Configure Optimization Parameters Source: https://context7.com/robot0321/depthregularizedgs/llms.txt Set training hyperparameters such as learning rates and densification settings via OptimizationParams. ```python from arguments import OptimizationParams from argparse import ArgumentParser parser = ArgumentParser() op = OptimizationParams(parser) # Key parameters: # --iterations: Total training iterations (default: 30000) # --min_iters: Minimum iterations before early stopping (default: 1500) # --position_lr_init: Initial position learning rate (default: 0.00016) # --position_lr_final: Final position learning rate (default: 0.0000016) # --feature_lr: Feature learning rate (default: 0.0025) # --opacity_lr: Opacity learning rate (default: 0.05) # --scaling_lr: Scaling learning rate (default: 0.005) # --rotation_lr: Rotation learning rate (default: 0.001) # --lambda_dssim: DSSIM loss weight (default: 0.2) # --densify_from_iter: Start densification iteration (default: 100) # --densify_until_iter: Stop densification iteration (default: 15000) # --densification_interval: Densification interval (default: 100) # --densify_grad_threshold: Gradient threshold for densification (default: 0.0002) args = parser.parse_args() opt_params = op.extract(args) ``` -------------------------------- ### Clone the Repository Source: https://github.com/robot0321/depthregularizedgs/blob/main/README.md Clone the repository recursively to include all necessary submodules. ```bash git clone https://github.com/robot0321/DepthRegularizedGS.git --recursive ``` -------------------------------- ### Generate Train/Test Split for Datasets Source: https://context7.com/robot0321/depthregularizedgs/llms.txt Generates training and testing splits for various scene types (NeRF-LLFF, MipNeRF360, NeRF-Synthetic). Use the appropriate --dset flag based on your dataset's characteristics. ```bash python scripts/select_samples.py \ --dset nerfllff \ --path ./data/my_scene ``` ```bash python scripts/select_samples.py \ --dset mipnerf360 \ --path ./data/my_scene ``` ```bash python scripts/select_samples.py \ --dset nerfsynthetic \ --path ./data/my_scene ``` -------------------------------- ### Train the Model Source: https://github.com/robot0321/depthregularizedgs/blob/main/README.md Execute training for either the baseline 3DGS model or the depth-regularized version. ```bash ## Example: ## = ./data/nerf_llff_fewshot_resize/fern ## = ./output/baseline ## For original 3DGS (method1), python train.py -s --eval --port 6311 --model_path /method1 --resolution 1 --kshot 5 --seed 3 ## For our DepthRegularization (method2), add --depth and --usedepthReg arguments python train.py -s --eval --port 6312 --model_path /method2 --resolution 1 --kshot 5 --seed 3 --depth --usedepthReg ``` -------------------------------- ### Select Training Samples Source: https://github.com/robot0321/depthregularizedgs/blob/main/README.md Generate train/test splits based on the specified dataset type. ```bash python scripts/select_samples.py --dset nerfllff --path ./ ## e.g ./data/nerf_llff_fewshot_resize/fern ## output: train.ply & test.ply in split_visualization/ folder and split_index.json ``` -------------------------------- ### Manage Gaussian Model Persistence and Training Source: https://context7.com/robot0321/depthregularizedgs/llms.txt Operations for saving/loading point clouds and performing densification during training. ```python # Save/load model gaussians.save_ply("./output/point_cloud.ply") gaussians.load_ply("./output/point_cloud.ply") # Densification and pruning during training gaussians.densify_and_prune( max_grad=0.0002, # Gradient threshold min_opacity=0.005, # Minimum opacity threshold extent=cameras_extent, # Scene extent max_screen_size=20 # Maximum screen-space size ) ``` -------------------------------- ### Train 3D Gaussian Models Source: https://context7.com/robot0321/depthregularizedgs/llms.txt Execute training for baseline 3DGS or the DRGS method using depth regularization flags. ```bash # Original 3DGS training (baseline) python train.py \ -s ./data/nerf_llff_fewshot_resize/fern \ --eval \ --port 6311 \ --model_path ./output/baseline/method1 \ --resolution 1 \ --kshot 5 \ --seed 3 # DRGS with depth regularization (our method) python train.py \ -s ./data/nerf_llff_fewshot_resize/fern \ --eval \ --port 6312 \ --model_path ./output/baseline/method2 \ --resolution 1 \ --kshot 5 \ --seed 3 \ --depth \ --usedepthReg ``` -------------------------------- ### Evaluate Model Metrics Source: https://context7.com/robot0321/depthregularizedgs/llms.txt Compute PSNR, SSIM, and LPIPS metrics using CLI or programmatic interfaces. ```bash # Evaluate single model python metrics.py \ -m ./output/baseline/method2 # Evaluate multiple models python metrics.py \ -m ./output/baseline/method1 \ ./output/baseline/method2 \ ./output/baseline/method3 ``` ```python # Programmatic metrics computation from utils.loss_utils import ssim from utils.image_utils import psnr from lpipsPyTorch import lpips import torch # Load rendered and ground truth images as tensors [1, 3, H, W] render_tensor = torch.load("render.pt").cuda() gt_tensor = torch.load("gt.pt").cuda() # Compute metrics ssim_value = ssim(render_tensor, gt_tensor) psnr_value = psnr(render_tensor, gt_tensor) lpips_value = lpips(render_tensor, gt_tensor, net_type='vgg') print(f"SSIM: {ssim_value:.6f}") print(f"PSNR: {psnr_value:.2f}") print(f"LPIPS: {lpips_value:.6f}") ``` -------------------------------- ### Convert Image Filenames Source: https://github.com/robot0321/depthregularizedgs/blob/main/README.md Standardize image filenames in the dataset folder using the provided conversion script. ```bash python scripts/convertImagename.py --imgfolder .//images ## e.g. ./data/nerf_llff_fewshot_resize/fern/images ``` -------------------------------- ### Generate Experiments with task_producer.py Source: https://github.com/robot0321/depthregularizedgs/blob/main/README.md Use this script to generate a list of experiments by modifying SCENES, SHOTS, METHODS, and SEED_IDS. The output is saved to `scripts/all_tasks.txt`. ```bash ## Before run this script, check the values of SCENES, SHOTS, METHODS, and SEED_IDS in the script. ## Note: the ids in METHODS are described in `scripts/task_consumer.py` python scripts/task_producer.py ``` -------------------------------- ### Run COLMAP Reconstruction Source: https://github.com/robot0321/depthregularizedgs/blob/main/README.md Perform automatic reconstruction and convert the resulting model to text format for further processing. ```bash colmap automatic_reconstructor --workspace_path ./ --image_path .//images --camera_model SIMPLE_PINHOLE --single_camera 1 --dense 0 --num_threads 8 mkdir .//sparse_txt colmap model_converter --input_path .//sparse/0 --output_path .//sparse_txt --output_type TXT ``` -------------------------------- ### Run COLMAP Reconstruction Source: https://context7.com/robot0321/depthregularizedgs/llms.txt Automates the process of reconstructing a 3D scene from images using COLMAP. Ensure images are in the specified image path and configure camera model parameters as needed. ```bash colmap automatic_reconstructor \ --workspace_path ./data/my_scene \ --image_path ./data/my_scene/images \ --camera_model SIMPLE_PINHOLE \ --single_camera 1 \ --dense 0 \ --num_threads 8 ``` -------------------------------- ### Summarize Experiment Results with task_reducer.py Source: https://github.com/robot0321/depthregularizedgs/blob/main/README.md This script summarizes experiment results into `metric_mean.txt`. Replace `` with the actual method ID to generate the summary file in the corresponding method directory within EXPERIMENT_PATH. ```bash python scripts/task_reducer.py --method ``` -------------------------------- ### Perform Differentiable Rendering Source: https://context7.com/robot0321/depthregularizedgs/llms.txt Render RGB images and depth maps from 3D Gaussians using a specified camera viewpoint. ```python from gaussian_renderer import render from scene import Scene, GaussianModel import torch # Setup rendering gaussians = GaussianModel(sh_degree=3) scene = Scene(model_params, gaussians) bg_color = [1, 1, 1] if white_background else [0, 0, 0] background = torch.tensor(bg_color, dtype=torch.float32, device="cuda") # Get a camera viewpoint viewpoint_cam = scene.getTrainCameras()[0] # Render the scene render_pkg = render( viewpoint_camera=viewpoint_cam, pc=gaussians, pipe=pipeline_params, bg_color=background, scaling_modifier=1.0 ) # Extract outputs rendered_image = render_pkg["render"] # [3, H, W] RGB image depth_map = render_pkg["depth"] # [1, H, W] depth accumulation = render_pkg["acc"] # [1, H, W] alpha accumulation visibility_filter = render_pkg["visibility_filter"] # Boolean mask radii = render_pkg["radii"] # Screen-space radii viewspace_points = render_pkg["viewspace_points"] # 2D projected points # Save rendered image import torchvision torchvision.utils.save_image(rendered_image, "render.png") ``` -------------------------------- ### Citation BibTeX Entry Source: https://github.com/robot0321/depthregularizedgs/blob/main/README.md BibTeX entry for the paper 'Depth-regularized optimization for 3d gaussian splatting in few-shot images'. ```bibtex @article{chung2023depth, title={Depth-regularized optimization for 3d gaussian splatting in few-shot images}, author={Chung, Jaeyoung and Oh, Jeongtaek and Lee, Kyoung Mu}, journal={arXiv preprint arXiv:2311.13398}, year={2023} } ``` -------------------------------- ### Summarize Experiment Results Source: https://context7.com/robot0321/depthregularizedgs/llms.txt Aggregates and summarizes the results from the conducted experiments using `task_reducer.py`. Use the `--method` flag to specify which method's results to summarize. ```bash python scripts/task_reducer.py --method 1 # Baseline 3DGS python scripts/task_reducer.py --method 2 # DRGS (ours) ``` -------------------------------- ### Apply Loss Functions and Depth Regularization Source: https://context7.com/robot0321/depthregularizedgs/llms.txt Implement standard training losses and edge-aware depth regularization for depth-regularized Gaussian Splatting. ```python from utils.loss_utils import l1_loss, l2_loss, ssim, image2canny, nearMean_map import torch # Basic losses rgb_loss = l1_loss(rendered_image, gt_image) depth_loss = l2_loss(rendered_depth, gt_depth) # SSIM loss (for combined loss) ssim_loss = 1.0 - ssim(rendered_image, gt_image) # Combined loss as used in training lambda_dssim = 0.2 total_loss = (1.0 - lambda_dssim) * l1_loss(rendered_image, gt_image) + \ lambda_dssim * (1.0 - ssim(rendered_image, gt_image)) # Edge-aware depth regularization (DRGS specific) # Extract Canny edges from rendered image canny_mask = image2canny(rendered_image.permute(1, 2, 0), thres1=50, thres2=150) # Compute near-mean depth map for regularization depth_mask = (rendered_depth > 0).detach() near_depth_mean = nearMean_map(rendered_depth, canny_mask * depth_mask, kernelsize=3) depth_reg_loss = l2_loss(near_depth_mean, rendered_depth * depth_mask) ``` -------------------------------- ### Convert COLMAP Binary to Text Source: https://context7.com/robot0321/depthregularizedgs/llms.txt Converts the sparse reconstruction output from COLMAP's binary format to a text-based format, which is often easier to process programmatically. ```bash mkdir ./data/my_scene/sparse_txt colmap model_converter \ --input_path ./data/my_scene/sparse/0 \ --output_path ./data/my_scene/sparse_txt \ --output_type TXT ``` -------------------------------- ### Colorize Depth Maps with Mask (Auto Range) Source: https://context7.com/robot0321/depthregularizedgs/llms.txt Converts a batch of depth maps into colorized visualizations using a jet colormap. Automatically computes the minimum and maximum valid depth values for scaling. Invalid regions are set to the specified background color. ```python from render import depth_colorize_with_mask import numpy as np import cv2 # depth_array: [B, H, W] numpy array with depth values (0 for invalid) depth_array = rendered_depth.cpu().numpy() # Colorize depth with automatic min/max colorized = depth_colorize_with_mask( depthlist=depth_array, background=(0, 0, 0), # Background color for invalid regions dmindmax=None # Auto-compute min/max from valid depths ) # Output: [B, H, W, 3] array with values in [0, 1] ``` -------------------------------- ### Colorize Depth Maps with Mask (Fixed Range) Source: https://context7.com/robot0321/depthregularizedgs/llms.txt Converts depth maps to colorized visualizations using a fixed depth range. This is useful for consistent comparisons across different depth maps or scenes. Invalid regions are set to the specified background color. ```python # Colorize with fixed depth range colorized = depth_colorize_with_mask( depthlist=depth_array, background=(1, 1, 1), dmindmax=(0.5, 10.0) # Fixed near/far range ) ``` -------------------------------- ### Save Colorized Depth Image Source: https://context7.com/robot0321/depthregularizedgs/llms.txt Saves a colorized depth map as a PNG image file. Converts the normalized [0, 1] colorized array to an 8-bit unsigned integer format and uses OpenCV for writing the image, ensuring correct color channel order (BGR). ```python # Save as image depth_image = (colorized[0] * 255).astype(np.uint8) cv2.imwrite("depth_colored.png", depth_image[:, :, ::-1]) # BGR for cv2 ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.