Marigold Pipelines for Computer Vision Tasks¶
Marigold was proposed in Repurposing Diffusion-Based Image Generators for Monocular Depth Estimation, a CVPR 2024 Oral paper by Bingxin Ke, Anton Obukhov, Shengyu Huang, Nando Metzger, Rodrigo Caye Daudt, and Konrad Schindler. The idea is to repurpose the rich generative prior of Text-to-Image Latent Diffusion Models (LDMs) for traditional computer vision tasks. Initially, this idea was explored to fine-tune Stable Diffusion for Monocular Depth Estimation, as shown in the teaser above. Later, - Tianfu Wang trained the first Latent Consistency Model (LCM) of Marigold, which unlocked fast single-step inference; - Kevin Qu extended the approach to Surface Normals Estimation; - Anton Obukhov contributed the pipelines and documentation into diffusers (enabled and supported by YiYi Xu and Sayak Paul).
The abstract from the paper is:
Monocular depth estimation is a fundamental computer vision task. Recovering 3D depth from a single image is geometrically ill-posed and requires scene understanding, so it is not surprising that the rise of deep learning has led to a breakthrough. The impressive progress of monocular depth estimators has mirrored the growth in model capacity, from relatively modest CNNs to large Transformer architectures. Still, monocular depth estimators tend to struggle when presented with images with unfamiliar content and layout, since their knowledge of the visual world is restricted by the data seen during training, and challenged by zero-shot generalization to new domains. This motivates us to explore whether the extensive priors captured in recent generative diffusion models can enable better, more generalizable depth estimation. We introduce Marigold, a method for affine-invariant monocular depth estimation that is derived from Stable Diffusion and retains its rich prior knowledge. The estimator can be fine-tuned in a couple of days on a single GPU using only synthetic training data. It delivers state-of-the-art performance across a wide range of datasets, including over 20% performance gains in specific cases. Project page: https://marigoldmonodepth.github.io.
Available Pipelines¶
Each pipeline supports one Computer Vision task, which takes an input RGB image as input and produces a prediction of the modality of interest, such as a depth map of the input image. Currently, the following tasks are implemented:
Pipeline | Predicted Modalities |
---|---|
MarigoldDepthPipeline | Depth, Disparity |
MarigoldNormalsPipeline | Surface normals |
Available Checkpoints¶
The original checkpoints can be found under the PRS-ETH Hugging Face organization.
Tip
Make sure to check out the Schedulers guide to learn how to explore the tradeoff between scheduler speed and quality, and see the reuse components across pipelines section to learn how to efficiently load the same components into multiple pipelines. Also, to know more about reducing the memory usage of this pipeline, refer to the ["Reduce memory usage"] section here.
Warning
Marigold pipelines were designed and tested only with DDIMScheduler
and LCMScheduler
.
Depending on the scheduler, the number of inference steps required to get reliable predictions varies, and there is no universal value that works best across schedulers.
Because of that, the default value of num_inference_steps
in the __call__
method of the pipeline is set to None
(see the API reference).
Unless set explicitly, its value will be taken from the checkpoint configuration model_index.json
.
This is done to ensure high-quality predictions when calling the pipeline with just the image
argument.
mindone.diffusers.MarigoldDepthPipeline
¶
Bases: DiffusionPipeline
Pipeline for monocular depth estimation using the Marigold method: https://marigoldmonodepth.github.io.
This model inherits from [DiffusionPipeline
]. Check the superclass documentation for the generic methods the
library implements for all the pipelines (such as downloading or saving, running on a particular device, etc.)
PARAMETER | DESCRIPTION |
---|---|
unet |
Conditional U-Net to denoise the depth latent, conditioned on image latent.
TYPE:
|
vae |
Variational Auto-Encoder (VAE) Model to encode and decode images and predictions to and from latent representations.
TYPE:
|
scheduler |
A scheduler to be used in combination with
TYPE:
|
text_encoder |
Text-encoder, for empty text embedding.
TYPE:
|
tokenizer |
CLIP tokenizer.
TYPE:
|
prediction_type |
Type of predictions made by the model.
TYPE:
|
scale_invariant |
A model property specifying whether the predicted depth maps are scale-invariant. This value must be set in
the model config. When used together with the
TYPE:
|
shift_invariant |
A model property specifying whether the predicted depth maps are shift-invariant. This value must be set in
the model config. When used together with the
TYPE:
|
default_denoising_steps |
The minimum number of denoising diffusion steps that are required to produce a prediction of reasonable
quality with the given model. This value must be set in the model config. When the pipeline is called
without explicitly setting
TYPE:
|
default_processing_resolution |
The recommended value of the
TYPE:
|
Source code in mindone/diffusers/pipelines/marigold/pipeline_marigold_depth.py
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 |
|
mindone.diffusers.MarigoldDepthPipeline.__call__(image, num_inference_steps=None, ensemble_size=1, processing_resolution=None, match_input_resolution=True, resample_method_input='bilinear', resample_method_output='bilinear', batch_size=1, ensembling_kwargs=None, latents=None, generator=None, output_type='np', output_uncertainty=False, output_latent=False, return_dict=False)
¶
Function invoked when calling the pipeline.
PARAMETER | DESCRIPTION |
---|---|
num_inference_steps |
Number of denoising diffusion steps during inference. The default value
TYPE:
|
ensemble_size |
Number of ensemble predictions. Recommended values are 5 and higher for better precision, or 1 for faster inference.
TYPE:
|
processing_resolution |
Effective processing resolution. When set to
TYPE:
|
match_input_resolution |
When enabled, the output prediction is resized to match the input dimensions. When disabled, the longer
side of the output will equal to
TYPE:
|
resample_method_input |
Resampling method used to resize input images to
TYPE:
|
resample_method_output |
Resampling method used to resize output predictions to match the input resolution. The accepted values
are
TYPE:
|
batch_size |
Batch size; only matters when setting
TYPE:
|
latents |
Latent noise tensors to replace the random initialization. These can be taken from the previous function call's output.
TYPE:
|
generator |
Random number generator object to ensure reproducibility.
TYPE:
|
output_type |
Preferred format of the output's
TYPE:
|
output_uncertainty |
When enabled, the output's
TYPE:
|
output_latent |
When enabled, the output's
TYPE:
|
return_dict |
Whether or not to return a [
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
[ |
Source code in mindone/diffusers/pipelines/marigold/pipeline_marigold_depth.py
323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 |
|
mindone.diffusers.MarigoldDepthPipeline.ensemble_depth(depth, scale_invariant=True, shift_invariant=True, output_uncertainty=False, reduction='median', regularizer_strength=0.02, max_iter=2, tol=0.001, max_res=1024)
staticmethod
¶
Ensembles the depth maps represented by the depth
tensor with expected shape (B, 1, H, W)
, where B is the
number of ensemble members for a given prediction of size (H x W)
. Even though the function is designed for
depth maps, it can also be used with disparity maps as long as the input tensor values are non-negative. The
alignment happens when the predictions have one or more degrees of freedom, that is when they are either
affine-invariant (scale_invariant=True
and shift_invariant=True
), or just scale-invariant (only
scale_invariant=True
). For absolute predictions (scale_invariant=False
and shift_invariant=False
)
alignment is skipped and only ensembling is performed.
PARAMETER | DESCRIPTION |
---|---|
depth |
Input ensemble depth maps.
TYPE:
|
scale_invariant |
Whether to treat predictions as scale-invariant.
TYPE:
|
shift_invariant |
Whether to treat predictions as shift-invariant.
TYPE:
|
output_uncertainty |
Whether to output uncertainty map.
TYPE:
|
reduction |
Reduction method used to ensemble aligned predictions. The accepted values are:
TYPE:
|
regularizer_strength |
Strength of the regularizer that pulls the aligned predictions to the unit range from 0 to 1.
TYPE:
|
max_iter |
Maximum number of the alignment solver steps. Refer to
TYPE:
|
tol |
Alignment solver tolerance. The solver stops when the tolerance is reached.
TYPE:
|
max_res |
Resolution at which the alignment is performed;
TYPE:
|
Source code in mindone/diffusers/pipelines/marigold/pipeline_marigold_depth.py
641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 |
|
mindone.diffusers.MarigoldNormalsPipeline
¶
Bases: DiffusionPipeline
Pipeline for monocular normals estimation using the Marigold method: https://marigoldmonodepth.github.io.
This model inherits from [DiffusionPipeline
]. Check the superclass documentation for the generic methods the
library implements for all the pipelines (such as downloading or saving, running on a particular device, etc.)
PARAMETER | DESCRIPTION |
---|---|
unet |
Conditional U-Net to denoise the normals latent, conditioned on image latent.
TYPE:
|
vae |
Variational Auto-Encoder (VAE) Model to encode and decode images and predictions to and from latent representations.
TYPE:
|
scheduler |
A scheduler to be used in combination with
TYPE:
|
text_encoder |
Text-encoder, for empty text embedding.
TYPE:
|
tokenizer |
CLIP tokenizer.
TYPE:
|
prediction_type |
Type of predictions made by the model.
TYPE:
|
use_full_z_range |
Whether the normals predicted by this model utilize the full range of the Z dimension, or only its positive half.
TYPE:
|
default_denoising_steps |
The minimum number of denoising diffusion steps that are required to produce a prediction of reasonable
quality with the given model. This value must be set in the model config. When the pipeline is called
without explicitly setting
TYPE:
|
default_processing_resolution |
The recommended value of the
TYPE:
|
Source code in mindone/diffusers/pipelines/marigold/pipeline_marigold_normals.py
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 |
|
mindone.diffusers.MarigoldNormalsPipeline.__call__(image, num_inference_steps=None, ensemble_size=1, processing_resolution=None, match_input_resolution=True, resample_method_input='bilinear', resample_method_output='bilinear', batch_size=1, ensembling_kwargs=None, latents=None, generator=None, output_type='np', output_uncertainty=False, output_latent=False, return_dict=False)
¶
Function invoked when calling the pipeline.
PARAMETER | DESCRIPTION |
---|---|
num_inference_steps |
Number of denoising diffusion steps during inference. The default value
TYPE:
|
ensemble_size |
Number of ensemble predictions. Recommended values are 5 and higher for better precision, or 1 for faster inference.
TYPE:
|
processing_resolution |
Effective processing resolution. When set to
TYPE:
|
match_input_resolution |
When enabled, the output prediction is resized to match the input dimensions. When disabled, the longer
side of the output will equal to
TYPE:
|
resample_method_input |
Resampling method used to resize input images to
TYPE:
|
resample_method_output |
Resampling method used to resize output predictions to match the input resolution. The accepted values
are
TYPE:
|
batch_size |
Batch size; only matters when setting
TYPE:
|
latents |
Latent noise tensors to replace the random initialization. These can be taken from the previous function call's output.
TYPE:
|
generator |
Random number generator object to ensure reproducibility.
TYPE:
|
output_type |
Preferred format of the output's
TYPE:
|
output_uncertainty |
When enabled, the output's
TYPE:
|
output_latent |
When enabled, the output's
TYPE:
|
return_dict |
Whether or not to return a [
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
[ |
Source code in mindone/diffusers/pipelines/marigold/pipeline_marigold_normals.py
307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 |
|
mindone.diffusers.MarigoldNormalsPipeline.ensemble_normals(normals, output_uncertainty, reduction='closest')
staticmethod
¶
Ensembles the normals maps represented by the normals
tensor with expected shape (B, 3, H, W)
, where B is
the number of ensemble members for a given prediction of size (H x W)
.
PARAMETER | DESCRIPTION |
---|---|
normals |
Input ensemble normals maps.
TYPE:
|
output_uncertainty |
Whether to output uncertainty map.
TYPE:
|
reduction |
Reduction method used to ensemble aligned predictions. The accepted values are:
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Tensor
|
A tensor of aligned and ensembled normals maps with shape |
Optional[Tensor]
|
uncertainties of shape |
Source code in mindone/diffusers/pipelines/marigold/pipeline_marigold_normals.py
628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 |
|
mindone.diffusers.pipelines.marigold.pipeline_marigold_depth.MarigoldDepthOutput
dataclass
¶
Bases: BaseOutput
Output class for Marigold monocular depth prediction pipeline.
PARAMETER | DESCRIPTION |
---|---|
prediction |
Predicted depth maps with values in the range [0, 1]. The shape is always \(numimages imes 1 imes height imes width\), regardless of whether the images were passed as a 4D array or a list.
TYPE:
|
uncertainty |
Uncertainty maps computed from the ensemble, with values in the range [0, 1]. The shape is \(numimages imes 1 imes height imes width\).
TYPE:
|
latent |
Latent features corresponding to the predictions, compatible with the
TYPE:
|
Source code in mindone/diffusers/pipelines/marigold/pipeline_marigold_depth.py
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
|
mindone.diffusers.pipelines.marigold.pipeline_marigold_normals.MarigoldNormalsOutput
dataclass
¶
Bases: BaseOutput
Output class for Marigold monocular normals prediction pipeline.
PARAMETER | DESCRIPTION |
---|---|
prediction |
Predicted normals with values in the range [-1, 1]. The shape is always \(numimages imes 3 imes height imes width\), regardless of whether the images were passed as a 4D array or a list.
TYPE:
|
uncertainty |
Uncertainty maps computed from the ensemble, with values in the range [0, 1]. The shape is \(numimages imes 1 imes height imes width\).
TYPE:
|
latent |
Latent features corresponding to the predictions, compatible with the
TYPE:
|
Source code in mindone/diffusers/pipelines/marigold/pipeline_marigold_normals.py
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
|