Skip to content

Depth map estimation tool using Depth-Anything-V2. Generate accurate depth maps from images with support for both relative and metric depth measurements.

License

Notifications You must be signed in to change notification settings

Luis-Kr/DepthMap

Repository files navigation

DepthMap

A Python workflow for depth map estimation using Depth-Anything. This tool processes images to generate depth maps using the Depth-Anything-V2 model, providing both visual depth maps and numerical depth data. It automatically handles model downloading, environment setup, and provides an easy-to-use interface for batch processing images.

Features

  • Automatic download of pre-trained Depth-Anything-V2 models (large version only)
  • Batch processing of images
  • Outputs both visual depth maps and raw depth data
  • Statistical analysis of depth values
  • CSV export of depth statistics

Installation

Make sure you have Conda installed. If not, download it from Miniconda

To set up the project, follow these steps:

# Clone the repository
git clone https://github.com/Luis-Kr/DepthMap.git

# Navigate into the directory
cd DepthMap

# Run setup script (this will download large models >2GB)
python setup.py

Usage

Run the depth estimation with default settings:

# Activate the conda environment
conda activate depthmap

# Run the main script to create the depth maps with the default configurations
python -m DepthMap.main

Mac-specific issues (Apple Silicon)

I case the error message Unexpected error: The operator 'aten::upsample_bicubic2d.out' is not currently implemented for the MPS device appears when running the script. This occurs because PyTorch's Metal Performance Shaders (MPS) backend for Apple Silicon doesn't yet support all operations. To work around this:

# Set this environment variable before running
export PYTORCH_ENABLE_MPS_FALLBACK=1

# Or: alternatively, you can add this line to your .zshrc or .bash_profile file to make it persistent across terminal sessions:
echo 'export PYTORCH_ENABLE_MPS_FALLBACK=1' >> ~/.zshrc #same applies for .bash_profile
source ~/.zshrc

Note: Using this fallback will cause these specific operations to run on CPU instead of GPU, which may result in slightly slower performance.

Configuration

The default configuration can be found in config/main.yaml. You can override any of these settings via command line:

  • input_folder: Directory containing input images
  • output.dir: Directory for saving depth maps
  • depth_measurement: Choose between "relative" or "metric" depth
    • relative: Provides relative depth values (better for general use)
    • metric: Fine-tuned version that attempts to predict actual depth in meters
  • encoder: Model encoder type (currently only "vitl" supported)
  • dataset: For metric depth, choose between:
    • hypersim: Optimized for indoor scenes
    • vkitti: Optimized for outdoor scenes
  • max_depth: Maximum depth (in meters) to be expected in the input image (only for metric depth)

Example with multiple parameters:

python -m DepthMap.main \
    input_folder=my_images \
    output.dir=results \
    depth_measurement=metric \
    dataset=hypersim \
    max_depth=10

Output

The tool generates:

  1. Colored depth maps in <output.dir>/images/
  2. Raw depth arrays in <output.dir>/arrays/
  3. CSV file with depth statistics including:
    • 5th percentile depth
    • 95th percentile depth
    • Mean depth
    • Median depth

Requirements

  • Python 3.8+
  • CUDA-capable GPU (recommended)
  • Conda package manager

License

This project has two licensing components:

  1. Depth-Anything Model: The Depth-Anything model is governed by its own license terms. You must comply with the Depth-Anything License for any use of the model.

  2. This Project: The DepthMap workflow code (excluding the Depth-Anything model) is released under the MIT License. See the LICENSE file for details.

About

Depth map estimation tool using Depth-Anything-V2. Generate accurate depth maps from images with support for both relative and metric depth measurements.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages