DiffusionUavLoc / README.md
happyPHD's picture
Upload folder using huggingface_hub
a6c1a9f verified
|
Raw History Blame Contribute Delete
13.2 kB

Batch Generation of Orthographic Images from 3DGS Models

This guide describes how to generate top-down orthographic images from trained 3D Gaussian Splatting (3DGS) models. The batch commands invoke render_ortho.py for each scene and preserve the original scene directory names.

Prerequisites

  • Bash on Linux.
  • The existing 3dgs Conda environment with the dependencies required by render_ortho.py, including CUDA and gsplat.
  • The rendering script located in the project directory.
  • A trained 3DGS model and cameras.json for each scene.

Input Directory Structure

<dataset>/train/3DGS/
├── <scene_id>/
│   └── model/
│       ├── cameras.json
│       └── point_cloud/
│           └── iteration_7000/
│               └── point_cloud.ply
└── ...

Rendering Configuration

Parameter Value
Image size 2048 × 2048 pixels
Center crop ratio 0.6
Model iteration 7000
Rendering device cuda:0
Processing mode Sequential, one scene at a time

1. Render the SUES 150 m Dataset

Run the following commands in a Bash terminal.

conda activate 3dgs

cd /media/liutao/A/demo/OCT

(
    # ==================== Parameter configuration ====================

    SRC="/media/liutao/A/demo/OCT/Datasets/150/train/3DGS"

    DST="/media/liutao/A/demo/OCT/Datasets/U1652/train/SUES150_Ortho"

    SCRIPT="/media/liutao/A/demo/OCT/3DGS重建/render_ortho.py"

    SIZE=2048
    CENTER_RATIO=0.6
    ITERATION=7000

    # ==================== Initialization ====================

    if [[ ! -d "$SRC" || ! -f "$SCRIPT" ]]; then
        echo "Input directory or rendering script not found"
        exit 1
    fi

    mkdir -p "$DST"

    shopt -s nullglob

    scenes=("$SRC"/*/)

    total=${#scenes[@]}
    current=0
    success=0
    skipped=0
    failed=0

    FAILED_LOG="$DST/failed.txt"

    > "$FAILED_LOG"

    trap 'echo "Batch interrupted. Completed scenes will be skipped on restart."; exit 130' INT

    echo "=================================================="
    echo "3DGS Batch Orthographic Rendering"
    echo "Input directory: $SRC"
    echo "Output directory: $DST"
    echo "Number of scenes: $total"
    echo "Output resolution: ${SIZE} × ${SIZE}"
    echo "Center crop ratio: $CENTER_RATIO"
    echo "=================================================="

    # ==================== Iterate over scenes ====================

    for scene_dir in "${scenes[@]}"; do

        scene=$(basename "$scene_dir")

        current=$((current + 1))

        ply="$scene_dir/model/point_cloud/iteration_${ITERATION}/point_cloud.ply"

        cameras="$scene_dir/model/cameras.json"

        out_dir="$DST/$scene"

        output="$out_dir/ortho.png"

        echo ""
        echo "=================================================="
        echo "[$current/$total] Current scene: $scene"
        echo "=================================================="

        # Check existing outputs to support resuming

        if [[ -f "$out_dir/.complete" && \
              -s "$output" && \
              -s "$out_dir/ortho.alpha.png" && \
              -s "$out_dir/ortho.json" ]]; then

            echo "Already completed; skipping"

            skipped=$((skipped + 1))

            continue
        fi

        # Check input files

        if [[ ! -f "$ply" || ! -f "$cameras" ]]; then

            echo "Missing PLY or cameras.json; skipping"

            echo "$scene: Missing input files" >> "$FAILED_LOG"

            failed=$((failed + 1))

            continue
        fi

        # Create the corresponding scene directory

        mkdir -p "$out_dir"

        rm -f "$out_dir/.complete"

        # ==================== Orthographic rendering ====================

        if python -u "$SCRIPT" \
            --ply "$ply" \
            --cameras "$cameras" \
            --output "$output" \
            --size "$SIZE" \
            --center-ratio "$CENTER_RATIO" \
            --device cuda:0 \
            > "$out_dir/render.log" 2>&1 \
            && [[ -s "$output" && \
                  -s "$out_dir/ortho.alpha.png" && \
                  -s "$out_dir/ortho.json" ]]; then

            touch "$out_dir/.complete"

            echo "Scene $scene rendered successfully"

            success=$((success + 1))

        else

            echo "Scene $scene rendering failed"

            echo "$scene: Rendering failed" >> "$FAILED_LOG"

            tail -n 15 "$out_dir/render.log"

            failed=$((failed + 1))

        fi

        echo "Successful: $success"
        echo "Skipped: $skipped"
        echo "Failed: $failed"

    done

    # ==================== Final summary ====================

    echo ""
    echo "=================================================="
    echo "All scenes processed"
    echo "=================================================="
    echo "Total scenes: $total"
    echo "Newly completed: $success"
    echo "Previously completed: $skipped"
    echo "Failed: $failed"
    echo "Output directory: $DST"
    echo "Failure log: $FAILED_LOG"
    echo "=================================================="
)

2. Render Multiple Dataset Groups

The following commands process the SUES 100 m, 200 m, 250 m, and 300 m datasets, followed by IRVL328.

conda activate 3dgs

cd /media/liutao/A/demo/OCT

(
    # ==================== Global configuration ====================

    BASE="/media/liutao/A/demo/OCT"

    SCRIPT="$BASE/3DGS重建/render_ortho.py"

    SIZE=2048
    CENTER_RATIO=0.6
    ITERATION=7000

    shopt -s nullglob

    trap 'echo "Batch interrupted. Completed scenes will be skipped on restart."; exit 130' INT

    if [[ ! -f "$SCRIPT" ]]; then
        echo "Rendering script not found: $SCRIPT"
        exit 1
    fi

    all_total=0
    all_success=0
    all_skipped=0
    all_failed=0

    # ==================== Iterate over dataset groups ====================

    for height in 100 200 250 300 IRVL328; do

        SRC="$BASE/Datasets/${height}/train/3DGS"

        DST="$BASE/Datasets/U1652/train/SUES${height}_Ortho"

        echo ""
        echo "=================================================="
        echo "Processing dataset group: ${height}"
        echo "=================================================="

        if [[ ! -d "$SRC" ]]; then
            echo "Input directory not found: $SRC"
            echo "Skipping current dataset group"
            continue
        fi

        mkdir -p "$DST"

        scenes=("$SRC"/*/)

        total=${#scenes[@]}
        current=0
        success=0
        skipped=0
        failed=0

        FAILED_LOG="$DST/failed.txt"

        > "$FAILED_LOG"

        echo "Input directory: $SRC"
        echo "Output directory: $DST"
        echo "Number of scenes: $total"
        echo "Output resolution: ${SIZE} × ${SIZE}"
        echo "Center crop ratio: $CENTER_RATIO"
        echo "=================================================="

        # ==================== Iterate over scenes ====================

        for scene_dir in "${scenes[@]}"; do

            scene=$(basename "$scene_dir")

            current=$((current + 1))

            ply="$scene_dir/model/point_cloud/iteration_${ITERATION}/point_cloud.ply"

            cameras="$scene_dir/model/cameras.json"

            out_dir="$DST/$scene"

            output="$out_dir/ortho.png"

            echo ""
            echo "=================================================="
            echo "Dataset group: ${height}"
            echo "[$current/$total] Current scene: $scene"
            echo "=================================================="

            # ==================== Resume completed scenes ====================

            if [[ -f "$out_dir/.complete" && \
                  -s "$output" && \
                  -s "$out_dir/ortho.alpha.png" && \
                  -s "$out_dir/ortho.json" ]]; then

                echo "Already completed; skipping"

                skipped=$((skipped + 1))

                continue
            fi

            # ==================== Check inputs ====================

            if [[ ! -f "$ply" || ! -f "$cameras" ]]; then

                echo "Missing PLY or cameras.json; skipping"

                echo "$scene: Missing input files" >> "$FAILED_LOG"

                failed=$((failed + 1))

                continue
            fi

            mkdir -p "$out_dir"

            rm -f "$out_dir/.complete"

            # ==================== Orthographic rendering ====================

            if python -u "$SCRIPT" \
                --ply "$ply" \
                --cameras "$cameras" \
                --output "$output" \
                --size "$SIZE" \
                --center-ratio "$CENTER_RATIO" \
                --device cuda:0 \
                > "$out_dir/render.log" 2>&1 \
                && [[ -s "$output" && \
                      -s "$out_dir/ortho.alpha.png" && \
                      -s "$out_dir/ortho.json" ]]; then

                touch "$out_dir/.complete"

                echo "Scene $scene rendered successfully"

                success=$((success + 1))

            else

                echo "Scene $scene rendering failed"

                echo "$scene: Rendering failed" >> "$FAILED_LOG"

                tail -n 15 "$out_dir/render.log"

                failed=$((failed + 1))

            fi

            echo "Group successful: $success"
            echo "Group skipped: $skipped"
            echo "Group failed: $failed"

        done

        # ==================== Current group summary ====================

        echo ""
        echo "=================================================="
        echo "Dataset group ${height} processed"
        echo "=================================================="
        echo "Total scenes: $total"
        echo "Newly completed: $success"
        echo "Previously completed: $skipped"
        echo "Failed: $failed"
        echo "Output directory: $DST"
        echo "Failure log: $FAILED_LOG"
        echo "=================================================="

        all_total=$((all_total + total))
        all_success=$((all_success + success))
        all_skipped=$((all_skipped + skipped))
        all_failed=$((all_failed + failed))

    done

    # ==================== Overall summary ====================

    echo ""
    echo "=================================================="
    echo "All dataset groups processed"
    echo "=================================================="
    echo "Total scenes: $all_total"
    echo "Newly completed: $all_success"
    echo "Previously completed: $all_skipped"
    echo "Failed: $all_failed"
    echo "=================================================="
)

Input and Output Paths

All paths below are relative to the project's Datasets/ directory.

Dataset group Input directory Output directory
SUES 150 m 150/train/3DGS U1652/train/SUES150_Ortho
SUES 100 m 100/train/3DGS U1652/train/SUES100_Ortho
SUES 200 m 200/train/3DGS U1652/train/SUES200_Ortho
SUES 250 m 250/train/3DGS U1652/train/SUES250_Ortho
SUES 300 m 300/train/3DGS U1652/train/SUES300_Ortho
IRVL328 IRVL328/train/3DGS U1652/train/SUESIRVL328_Ortho

The directory paths and naming convention are retained from the supplied commands. In particular, the original output path for IRVL328 uses the SUES prefix. The original non-English directory name in the rendering script path is retained because changing it would change the actual filesystem path.

3. Output Directory Structure

<output_directory>/
├── <scene_id>/
│   ├── ortho.png
│   ├── ortho.alpha.png
│   ├── ortho.json
│   ├── render.log
│   └── .complete
├── ...
└── failed.txt
File Description
ortho.png Rendered RGB orthographic image
ortho.alpha.png Alpha mask
ortho.json Rendering and projection metadata
render.log Per-scene rendering log
.complete Completion marker
failed.txt List of scenes that failed during the current run

4. Resuming and Error Handling

Press Ctrl+C to interrupt the batch. Run the same commands again to resume. A scene is skipped if its completion marker and all three nonempty output files exist.

Scenes with missing input files or rendering failures are recorded in failed.txt, and processing continues with the next scene. The failure log is reset when the corresponding dataset group is processed again.

Do not remove the completion markers, alpha masks, or metadata files before batch rendering is finished; the original resume logic relies on them.

Notes

  • The commands do not retrain or modify the original 3DGS models.
  • A center crop ratio of 0.6 is applied uniformly; this does not guarantee the same physical ground coverage across scenes.
  • The output images are orthographic renderings, not georeferenced mapping products unless a separate georeferencing procedure is applied.