GitHub - prs-eth/Marigold: [CVPR 2024 - Oral, Best Paper Award Candidate] Marigold: Repurposing Diffusion-Based Image Generators for Monocular Depth Estimation (original) (raw)

Marigold Computer Vision

This project implements Marigold, a Computer Vision method for estimating image characteristics. Initially proposed for extracting high-resolution depth maps in our CVPR 2024 paper "Repurposing Diffusion-Based Image Generators for Monocular Depth Estimation", we extended the method to other modalities as described in our follow-up paper "Marigold: Affordable Adaptation of Diffusion-Based Image Generators for Image Analysis".

Marigold: Affordable Adaptation of Diffusion-Based Image Generators for Image Analysis

Website Paper Depth Demo Normals Demo Intrinsics Demo Depth Model Normals Model Intrinsics Appearance Model Intrinsics Lighting Model Diffusers Tutorial

Team:Bingxin Ke,Kevin Qu,Tianfu Wang Nando Metzger,Shengyu Huang,Bo Li,Anton Obukhov,Konrad Schindler

We present Marigold, a family of conditional generative models and a fine-tuning protocol that extracts the knowledge from pretrained latent diffusion models like Stable Diffusion and adapts them for dense image analysis tasks, including monocular depth estimation, surface normal prediction, and intrinsic decomposition. Marigold requires minimal modification of the pre-trained latent diffusion model's architecture, trains with small synthetic datasets on a single GPU over a few days, and demonstrates state-of-the-art zero-shot generalization.

teaser_all

Website Paper Hugging Face Space Hugging Face Model Open In Colab

In CVPR 2024 (Oral, Best Paper Award Candidate)
Team:Bingxin Ke,Anton Obukhov,Shengyu Huang,Nando Metzger,Rodrigo Caye Daudt,Konrad Schindler

We present Marigold, a diffusion model, and an associated fine-tuning protocol for monocular depth estimation. Its core principle is to leverage the rich visual knowledge stored in modern generative image models. Our model, derived from Stable Diffusion and fine-tuned with synthetic data, can zero-shot transfer to unseen data, offering state-of-the-art monocular depth estimation results.

teaser_depth

๐Ÿ“ข News

2025-05-15: Released code and a checkpoint of Marigold Intrinsic Image Decomposition predicting Albedo, diffuse Shading, and non-diffuse Residual (Marigold-IID-Lighting v1.1).
2025-05-15: Released code and a checkpoint of Marigold Intrinsic Image Decomposition predicting Albedo, Roughness, and Metallicity (Marigold-IID-Appearance v1.1).
2025-05-15: Released code and a checkpoint of Marigold Surface Normals Estimation (v1.1).
2025-05-15: Released an updated checkpoint of Marigold Depth (v1.1), trained with updated noise scheduler settings (zero-SNR and trailing timestamps), and augmentations.
2024-05-28: Training code is released.
2024-05-27: Marigold pipelines are merged into the diffusers core starting v0.28.0 release!
2024-03-23: Added a Latent Consistency Model (LCM) checkpoint.
2024-03-04: The paper is accepted at CVPR 2024.
2023-12-22: Contributed to Diffusers community pipeline.
2023-12-19: Updated license to Apache License, Version 2.0.
2023-12-08: Added the first interactive Hugging Face Space Demo of depth estimation.
2023-12-05: Added a Google Colab
2023-12-04: Added an arXiv paper and inference code (this repository).

๐Ÿš€ Usage

We offer several ways to interact with Marigold:

  1. A family of free online interactive demos: (kudos to the HF team for the GPU grants)
  2. Marigold pipelines are part of - a one-stop shop for diffusion ๐Ÿงจ!
  3. Run the demo locally (requires a GPU and an nvidia-docker2, see Installation Guide):docker run -it -p 7860:7860 --platform=linux/amd64 --gpus all registry.hf.space/prs-eth-marigold:latest python app.py
  4. Extended demo on a Google Colab:
  5. If you just want to see the examples, visit our gallery:
  6. Finally, local development instructions with this codebase are given below.

๐Ÿ› ๏ธ Setup

The inference code was tested on:

๐Ÿชง A Note for Windows users

We recommend running the code in WSL2:

  1. Install WSL following installation guide.
  2. Install CUDA support for WSL following installation guide.
  3. Find your drives in /mnt/<drive letter>/; check WSL FAQ for more details. Navigate to the working directory of choice.

๐Ÿ“ฆ Repository

Clone the repository (requires git):

git clone https://github.com/prs-eth/Marigold.git cd Marigold

๐Ÿ’ป Dependencies

Install the dependencies:

python -m venv venv/marigold source venv/marigold/bin/activate pip install -r requirements.txt

Keep the environment activated before running the inference script. Activate the environment again after restarting the terminal session.

๐Ÿƒ Testing on your images

๐Ÿ“ท Prepare images

Use selected images from our paper:

bash script/download_sample_data.sh

Or place your images in a directory, for example, under input/in-the-wild_example, and run the following inference command.

๐Ÿš€ Run inference (for practical usage)

Depth

python script/depth/run.py
--checkpoint prs-eth/marigold-depth-v1-1
--input_rgb_dir input/in-the-wild_example
--output_dir output/in-the-wild_example
--fp16

Normals

python script/normals/run.py
--checkpoint prs-eth/marigold-normals-v1-1
--input_rgb_dir input/in-the-wild_example
--output_dir output/in-the-wild_example
--fp16

IID (appearance model)

python script/iid/run.py
--checkpoint prs-eth/marigold-iid-appearance-v1-1
--input_rgb_dir input/in-the-wild_example
--output_dir output/in-the-wild_example
--fp16

IID (lighting model)

python script/iid/run.py
--checkpoint prs-eth/marigold-iid-lighting-v1-1
--input_rgb_dir input/in-the-wild_example
--output_dir output/in-the-wild_example
--fp16

โš™๏ธ Inference settings

The default settings are optimized for the best results. However, the behavior of the code can be customized:

๐ŸŽฎ Run inference (for academic comparisons)

These settings correspond to our paper. For academic comparison, please run with the settings below (if you only want to do fast inference on your own images, you can set --ensemble_size 1).

Depth

python script/depth/run.py
--checkpoint prs-eth/marigold-depth-v1-1
--denoise_steps 1
--ensemble_size 10
--input_rgb_dir input/in-the-wild_example
--output_dir output/in-the-wild_example

Normals

python script/normals/run.py
--checkpoint prs-eth/marigold-normals-v1-1
--denoise_steps 4
--ensemble_size 10
--input_rgb_dir input/in-the-wild_example
--output_dir output/in-the-wild_example

IID (appearance model)

python script/iid/run.py
--checkpoint prs-eth/marigold-iid-appearance-v1-1
--denoise_steps 4
--ensemble_size 1
--input_rgb_dir input/in-the-wild_example
--output_dir output/in-the-wild_example

IID (lighting model)

python script/iid/run.py
--checkpoint prs-eth/marigold-iid-lighting-v1-1
--denoise_steps 4
--ensemble_size 1
--input_rgb_dir input/in-the-wild_example
--output_dir output/in-the-wild_example

Depth (the original CVPR version)

python script/depth/run.py
--checkpoint prs-eth/marigold-depth-v1-0
--denoise_steps 50
--ensemble_size 10
--input_rgb_dir input/in-the-wild_example
--output_dir output/in-the-wild_example

You can find all results in the output directory. Enjoy!

โฌ‡ Checkpoint cache

By default, the checkpoint (depth, normals, iid) is stored in the Hugging Face cache. The HF_HOME environment variable defines its location and can be overridden, e.g.:

export HF_HOME=$(pwd)/cache

Alternatively, use the following script to download the checkpoint weights locally:

bash script/download_weights.sh marigold-depth-v1-1 # depth checkpoint bash script/download_weights.sh marigold-normals-v1-1 # normals checkpoint bash script/download_weights.sh marigold-iid-appearance-v1-1 # iid appearance checkpoint bash script/download_weights.sh marigold-iid-lighting-v1-1 # iid lighting checkpoint

bash script/download_weights.sh marigold-depth-v1-0 # CVPR depth checkpoint

At inference, specify the checkpoint path:

Depth

python script/depth/run.py
--checkpoint checkpoint/marigold-depth-v1-1
--denoise_steps 4
--ensemble_size 1
--input_rgb_dir input/in-the-wild_example
--output_dir output/in-the-wild_example

Normals

python script/normals/run.py
--checkpoint checkpoint/marigold-normals-v1-1
--denoise_steps 4
--ensemble_size 1
--input_rgb_dir input/in-the-wild_example
--output_dir output/in-the-wild_example

IID (appearance model)

python script/iid/run.py
--checkpoint checkpoint/marigold-iid-appearance-v1-1
--denoise_steps 4
--ensemble_size 1
--input_rgb_dir input/in-the-wild_example
--output_dir output/in-the-wild_example

IID (lighting model)

python script/iid/run.py
--checkpoint checkpoint/marigold-iid-lighting-v1-1
--denoise_steps 4
--ensemble_size 1
--input_rgb_dir input/in-the-wild_example
--output_dir output/in-the-wild_example

๐Ÿฆฟ Evaluation on test datasets

Install additional dependencies:

pip install -r requirements+.txt -r requirements.txt

Set data directory variable (also needed in evaluation scripts) and download the evaluation datasets (depth, normals) into the corresponding subfolders:

export BASE_DATA_DIR= # Set target data directory

Depth

wget -r -np -nH --cut-dirs=4 -R "index.html*" -P ${BASE_DATA_DIR} https://share.phys.ethz.ch/~pf/bingkedata/marigold/evaluation_dataset/

Normals

wget -r -np -nH --cut-dirs=4 -R "index.html*" -P ${BASE_DATA_DIR} https://share.phys.ethz.ch/~pf/bingkedata/marigold/marigold_normals/evaluation_dataset.zip unzip BASEDATADIR/evaluationdataset.zipโˆ’d{BASE_DATA_DIR}/evaluation_dataset.zip -d BASEDโ€‹ATADโ€‹IR/evaluationdโ€‹ataset.zipโˆ’d{BASE_DATA_DIR}/ rm -f ${BASE_DATA_DIR}/evaluation_dataset.zip

For download instructions of the intrinsic image decomposition test data, please refer to iid-appearance instructions and iid-lighting instructions.

Run inference and evaluation scripts, for example:

Depth

bash script/depth/eval/11_infer_nyu.sh # Run inference bash script/depth/eval/12_eval_nyu.sh # Evaluate predictions

Normals

bash script/normals/eval/11_infer_scannet.sh # Run inference bash script/normals/eval/12_eval_scannet.sh # Evaluate predictions

IID

bash script/iid/eval/11_infer_appearance_interiorverse.sh # Run inference bash script/iid/eval/12_eval_appearance_interiorverse.sh # Evaluate predictions

bash script/iid/eval/21_infer_lighting_hypersim.sh # Run inference bash script/iid/eval/22_eval_lighting_hypersim.sh # Evaluate predictions

Depth (the original CVPR version)

bash script/depth/eval_old/11_infer_nyu.sh # Run inference bash script/depth/eval_old/12_eval_nyu.sh # Evaluate predictions

Note: although the seed has been set, the results might still be slightly different on different hardware.

๐Ÿ‹๏ธ Training

Based on the previously created environment, install extended requirements:

pip install -r requirements++.txt -r requirements+.txt -r requirements.txt

Set environment parameters for the data directory:

export BASE_DATA_DIR=YOUR_DATA_DIR # directory of training data export BASE_CKPT_DIR=YOUR_CHECKPOINT_DIR # directory of pretrained checkpoint

Download Stable Diffusion v2 checkpoint into ${BASE_CKPT_DIR} (backup link)

Prepare for training data

Depth

Prepare for Hypersim and Virtual KITTI 2 datasets and save into ${BASE_DATA_DIR}. Please refer to this README for Hypersim preprocessing.

Normals

Prepare for Hypersim, Interiorverse and Sintel datasets and save into ${BASE_DATA_DIR}. Please refer to this README for Hypersim preprocessing, this README for Interiorverse and this README for Sintel.

Intrinsic Image Decomposition

Appearance model: Prepare for Interiorverse dataset and save into ${BASE_DATA_DIR}. Please refer to this README for Interiorverse preprocessing.

Lighting model: Prepare for Hypersim dataset and save into ${BASE_DATA_DIR}. Please refer to this README for Hypersim preprocessing.

Run training script

Depth

python script/depth/train.py --config config/train_marigold_depth.yaml

Normals

python script/normals/train.py --config config/train_marigold_normals.yaml

IID (appearance model)

python script/iid/train.py --config config/train_marigold_iid_appearance.yaml

IID (lighting model)

python script/iid/train.py --config config/train_marigold_iid_lighting.yaml

Resume from a checkpoint, e.g.:

Depth

python script/depth/train.py --resume_run output/marigold_base/checkpoint/latest

Normals

python script/normals/train.py --resume_run output/train_marigold_normals/checkpoint/latest

IID (appearance model)

python script/iid/train.py --resume_run output/train_marigold_iid_appearance/checkpoint/latest

IID (lighting model)

python script/iid/train.py --resume_run output/train_marigold_iid_lighting/checkpoint/latest

Compose checkpoint:

Only the U-Net and scheduler config are updated during training. They are saved in the training directory. To use the inference pipeline with your training result:

Note: Although random seeds have been set, the training result might be slightly different on different hardwares. It's recommended to train without interruption.

โœ๏ธ Contributing

Please refer to this instruction.

๐Ÿค” Troubleshooting

Problem Solution
(Windows) Invalid DOS bash script on WSL Run dos2unix <script_name> to convert script format
(Windows) error on WSL: Could not load library libcudnn_cnn_infer.so.8. Error: libcuda.so: cannot open shared object file: No such file or directory Run export LD_LIBRARY_PATH=/usr/lib/wsl/lib:$LD_LIBRARY_PATH
Training takes a long time to start Use folders for data instead of tar files (modification in config files is required).

๐ŸŽ“ Citation

Please cite our papers:

@InProceedings{ke2023repurposing, title={Repurposing Diffusion-Based Image Generators for Monocular Depth Estimation}, author={Bingxin Ke and Anton Obukhov and Shengyu Huang and Nando Metzger and Rodrigo Caye Daudt and Konrad Schindler}, booktitle = {Proceedings of the IEEE/CVF Conference on Computer Vision and Pattern Recognition (CVPR)}, year={2024} }

@misc{ke2025marigold, title={Marigold: Affordable Adaptation of Diffusion-Based Image Generators for Image Analysis}, author={Bingxin Ke and Kevin Qu and Tianfu Wang and Nando Metzger and Shengyu Huang and Bo Li and Anton Obukhov and Konrad Schindler}, year={2025}, eprint={2505.09358}, archivePrefix={arXiv}, primaryClass={cs.CV} }

๐ŸŽซ License

This code of this work is licensed under the Apache License, Version 2.0 (as defined in the LICENSE).

The models are licensed under RAIL++-M License (as defined in the LICENSE-MODEL)

By downloading and using the code and model you agree to the terms in LICENSE and LICENSE-MODEL respectively.