Pixel-Perfect Depth

repository·main·Indexed 22 days ago

https://github.com/gangweix/pixel-perfect-depth

A monocular depth estimation model using pixel-space diffusion transformers to produce high-quality, flying-pixel-free point clouds without a VAE. The repository includes tools for depth estimation on images and video, point cloud generation via MoGe, a two-stage training pipeline (pre-training and fine-tuning), and a Gradio-based web interface for MoGe inference.

Tokens
1.7K
Snippets
9
Records
13
Agent score
77%

What's inside Pixel-Perfect Depth

  1. Train Pixel-Perfect Depth (Two-stage pipeline)

    main

    Training follows a two-stage curriculum:

    1. Stage 1: Pre-training (512×512 resolution on Hypersim dataset).
    2. Stage 2: Fine-tuning (1024×768 resolution on a mixture of five datasets).

    Use the main.py script with the appropriate configuration files.

    # Stage 1: Pre-training
    python main.py --cfg_file ppd/configs/train_pretrain.yaml pl_trainer.devices=8
    
    # Stage 2: Fine-tuning
    python main.py --cfg_file ppd/configs/train_finetune.yaml pl_trainer.devices=8
  2. Install and prepare Pixel-Perfect Depth

    main

    To set up the environment, clone the repository and install the required dependencies via pip. You must also download specific pretrained model weights and place them in the checkpoints/ directory to run the model.

    Required Checkpoints:

    • ppd.pth (Pixel-Perfect Depth model)
    • depth_anything_v2_vitl.pth OR moge2.pt (Dependency model)
    • moge2.pt (Required specifically for point cloud generation)
    • ppvd.pth (Required for video depth estimation)
    • pi3.safetensors (Required for video depth estimation)
    git clone https://github.com/gangweix/pixel-perfect-depth
    cd pixel-perfect-depth
    pip install -r requirements.txt
  3. Understand the MoGe Inference Pipeline

    main

    The MoGe pipeline transforms a 2D image into 3D geometry. The process involves:

    1. Preprocessing: Resizing the input image based on a max_size constraint.
    2. GPU Inference: Running the model to produce points (3D coordinates), depth (distance map), mask (validity mask), and optionally normal (surface normals).
    3. Post-processing:
      • Cleaning the mask using utils3d.numpy.depth_edge if remove_edge is enabled.
      • Generating 3D meshes (.glb) and point clouds (.ply, .glb) using trimesh and utils3d.
      • Exporting high-fidelity depth and point data as .exr files.
    4. Geometry Extraction: Calculating Field of View (FOV) from the model's intrinsics.
  4. Run PPD via the main entrypoint

    main

    The main.py script serves as the primary entrypoint for the Pixel-Perfect Depth (PPD) application. It uses a configuration system (cfg) and command-line arguments (args) to dispatch execution to a specific entry function defined by the --entry argument.

    When running the script, the application initializes logging and prints the current experiment name (cfg.exp_name) if it is the main process. The actual logic executed depends on which entry function is passed via the CLI.

    # Typical usage pattern via CLI (assuming an entry point named 'run_inference')
    python main.py --entry run_inference
  5. MoGe Output Files and Formats

    main

    The inference pipeline generates several files for 3D visualization and data analysis. These are typically stored in a temporary directory:

    FileFormatDescription
    mesh.glbGLBA textured 3D mesh with UV mapping and PBR materials.
    pointcloud.plyPLYA point cloud file including vertex normals.
    pointcloud.glbGLBA point cloud file including normals.
    depth.exrEXRHigh-precision floating-point depth map.
    points.exrEXRHigh-precision floating-point 3D point data (RGB encoded).
    mask.pngPNGA binary mask of the valid depth areas.
    normal.exrEXR(If supported) High-precision surface normal map.
  6. Run the MoGe Web Demo CLI

    main

    The app.py script provides a Gradio-based web interface to interact with the MoGe model. You can run the demo with various configuration options via the command line.

    Options:

    • --share: Enables a public Gradio share link.
    • --pretrained: Specifies the name or path of a pre-trained model.
    • --version: Specifies the model version (e.g., v1, v2). Defaults to v2.
    • --fp16: Enables FP16 (half-precision) inference for faster execution and lower VRAM usage.
    python ppd/moge/scripts/app.py --share --pretrained Ruicheng/moge-2-vitl-normal --version v2 --fp16