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.
- 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
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
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
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.
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 imagesoutput.dir
: Directory for saving depth mapsdepth_measurement
: Choose between "relative" or "metric" depthrelative
: 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 scenesvkitti
: 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
The tool generates:
- Colored depth maps in
<output.dir>/images/
- Raw depth arrays in
<output.dir>/arrays/
- CSV file with depth statistics including:
- 5th percentile depth
- 95th percentile depth
- Mean depth
- Median depth
- Python 3.8+
- CUDA-capable GPU (recommended)
- Conda package manager
This project has two licensing components:
-
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.
-
This Project: The DepthMap workflow code (excluding the Depth-Anything model) is released under the MIT License. See the LICENSE file for details.