VAE Image Processor¶
The VaeImageProcessor
provides a unified API for StableDiffusionPipeline
to prepare image inputs for VAE encoding and post-processing outputs once they're decoded. This includes transformations such as resizing, normalization, and conversion between PIL Image, MindSpore, and NumPy arrays.
All pipelines with VaeImageProcessor
accept PIL Image, MindSpore tensor, or NumPy arrays as image inputs and return outputs based on the output_type
argument by the user. You can pass encoded image latents directly to the pipeline and return latents from the pipeline as a specific output with the output_type
argument (for example output_type="latent"
). This allows you to take the generated latents from one pipeline and pass it to another pipeline as input without leaving the latent space. It also makes it much easier to use multiple pipelines together by passing MindSpore tensors directly between different pipelines.
mindone.diffusers.image_processor.VaeImageProcessor
¶
Bases: ConfigMixin
Image processor for VAE.
PARAMETER | DESCRIPTION |
---|---|
do_resize |
Whether to downscale the image's (height, width) dimensions to multiples of
TYPE:
|
vae_scale_factor |
VAE scale factor. If
TYPE:
|
resample |
Resampling filter to use when resizing the image.
TYPE:
|
do_normalize |
Whether to normalize the image to [-1,1].
TYPE:
|
do_binarize |
Whether to binarize the image to 0/1.
TYPE:
|
do_convert_rgb |
Whether to convert the images to RGB format.
TYPE:
|
do_convert_grayscale |
Whether to convert the images to grayscale format.
TYPE:
|
Source code in mindone/diffusers/image_processor.py
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 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 673 674 675 676 677 678 679 680 681 682 683 |
|
mindone.diffusers.image_processor.VaeImageProcessor.apply_overlay(mask, init_image, image, crop_coords=None)
¶
overlay the inpaint output to the original image
Source code in mindone/diffusers/image_processor.py
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 |
|
mindone.diffusers.image_processor.VaeImageProcessor.binarize(image)
¶
Create a mask.
PARAMETER | DESCRIPTION |
---|---|
image |
The image input, should be a PIL image.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Image
|
|
Source code in mindone/diffusers/image_processor.py
408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 |
|
mindone.diffusers.image_processor.VaeImageProcessor.blur(image, blur_factor=4)
staticmethod
¶
Applies Gaussian blur to an image.
Source code in mindone/diffusers/image_processor.py
182 183 184 185 186 187 188 189 |
|
mindone.diffusers.image_processor.VaeImageProcessor.convert_to_grayscale(image)
staticmethod
¶
Converts a PIL image to grayscale format.
Source code in mindone/diffusers/image_processor.py
173 174 175 176 177 178 179 180 |
|
mindone.diffusers.image_processor.VaeImageProcessor.convert_to_rgb(image)
staticmethod
¶
Converts a PIL image to RGB format.
Source code in mindone/diffusers/image_processor.py
164 165 166 167 168 169 170 171 |
|
mindone.diffusers.image_processor.VaeImageProcessor.denormalize(images)
staticmethod
¶
Denormalize an image array to [0,1].
Source code in mindone/diffusers/image_processor.py
157 158 159 160 161 162 |
|
mindone.diffusers.image_processor.VaeImageProcessor.get_crop_region(mask_image, width, height, pad=0)
staticmethod
¶
Finds a rectangular region that contains all masked ares in an image, and expands region to match the aspect ratio of the original image; for example, if user drew mask in a 128x32 region, and the dimensions for processing are 512x512, the region will be expanded to 128x128.
PARAMETER | DESCRIPTION |
---|---|
mask_image |
Mask image.
TYPE:
|
width |
Width of the image to be processed.
TYPE:
|
height |
Height of the image to be processed.
TYPE:
|
pad |
Padding to be added to the crop region. Defaults to 0.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
tuple
|
(x1, y1, x2, y2) represent a rectangular region that contains all masked ares in an image and |
matches the original aspect ratio. |
Source code in mindone/diffusers/image_processor.py
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 |
|
mindone.diffusers.image_processor.VaeImageProcessor.get_default_height_width(image, height=None, width=None)
¶
This function return the height and width that are downscaled to the next integer multiple of
vae_scale_factor
.
PARAMETER | DESCRIPTION |
---|---|
image(`PIL.Image.Image`, |
The image input, can be a PIL image, numpy array or mindspore tensor. if it is a numpy array, should have
shape
TYPE:
|
height |
The height in preprocessed image. If
TYPE:
|
width |
The width in preprocessed. If
TYPE:
|
Source code in mindone/diffusers/image_processor.py
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 |
|
mindone.diffusers.image_processor.VaeImageProcessor.ms_to_numpy(images)
staticmethod
¶
Convert a MindSpore tensor to a NumPy image.
Source code in mindone/diffusers/image_processor.py
142 143 144 145 146 147 148 |
|
mindone.diffusers.image_processor.VaeImageProcessor.normalize(images)
staticmethod
¶
Normalize an image array to [-1,1].
Source code in mindone/diffusers/image_processor.py
150 151 152 153 154 155 |
|
mindone.diffusers.image_processor.VaeImageProcessor.numpy_to_ms(images)
staticmethod
¶
Convert a NumPy image to a MindSpore tensor.
Source code in mindone/diffusers/image_processor.py
131 132 133 134 135 136 137 138 139 140 |
|
mindone.diffusers.image_processor.VaeImageProcessor.numpy_to_pil(images)
staticmethod
¶
Convert a numpy image or a batch of images to a PIL image.
Source code in mindone/diffusers/image_processor.py
103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 |
|
mindone.diffusers.image_processor.VaeImageProcessor.pil_to_numpy(images)
staticmethod
¶
Convert a PIL image or a list of PIL images to NumPy arrays.
Source code in mindone/diffusers/image_processor.py
119 120 121 122 123 124 125 126 127 128 129 |
|
mindone.diffusers.image_processor.VaeImageProcessor.postprocess(image, output_type='pil', do_denormalize=None)
¶
Postprocess the image output from tensor to output_type
.
PARAMETER | DESCRIPTION |
---|---|
image |
The image input, should be a mindspore tensor with shape
TYPE:
|
output_type |
The output type of the image, can be one of
TYPE:
|
do_denormalize |
Whether to denormalize the image to [0,1]. If
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Union[Image, ndarray, Tensor]
|
|
Source code in mindone/diffusers/image_processor.py
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 |
|
mindone.diffusers.image_processor.VaeImageProcessor.preprocess(image, height=None, width=None, resize_mode='default', crops_coords=None)
¶
Preprocess the image input.
PARAMETER | DESCRIPTION |
---|---|
image |
The image input, accepted formats are PIL images, NumPy arrays, MindSpore tensors; Also accept list of supported formats.
TYPE:
|
height |
The height in preprocessed image. If
TYPE:
|
width |
The width in preprocessed. If
TYPE:
|
resize_mode |
The resize mode, can be one of
TYPE:
|
crops_coords |
The crop coordinates for each image in the batch. If
TYPE:
|
Source code in mindone/diffusers/image_processor.py
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 |
|
mindone.diffusers.image_processor.VaeImageProcessor.resize(image, height, width, resize_mode='default')
¶
Resize image.
PARAMETER | DESCRIPTION |
---|---|
image |
The image input, can be a PIL image, numpy array or mindspore tensor.
TYPE:
|
height |
The height to resize to.
TYPE:
|
width |
The width to resize to.
TYPE:
|
resize_mode |
The resize mode to use, can be one of
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Union[Image, ndarray, Tensor]
|
|
Source code in mindone/diffusers/image_processor.py
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 |
|
mindone.diffusers.image_processor.PixArtImageProcessor
¶
Bases: VaeImageProcessor
Image processor for PixArt image resize and crop.
PARAMETER | DESCRIPTION |
---|---|
do_resize |
Whether to downscale the image's (height, width) dimensions to multiples of
TYPE:
|
vae_scale_factor |
VAE scale factor. If
TYPE:
|
resample |
Resampling filter to use when resizing the image.
TYPE:
|
do_normalize |
Whether to normalize the image to [-1,1].
TYPE:
|
do_binarize |
Whether to binarize the image to 0/1.
TYPE:
|
do_convert_rgb |
Whether to convert the images to RGB format.
TYPE:
|
do_convert_grayscale |
Whether to convert the images to grayscale format.
TYPE:
|
Source code in mindone/diffusers/image_processor.py
780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 |
|
mindone.diffusers.image_processor.PixArtImageProcessor.classify_height_width_bin(height, width, ratios)
staticmethod
¶
Returns binned height and width.
Source code in mindone/diffusers/image_processor.py
821 822 823 824 825 826 827 |
|
mindone.diffusers.image_processor.IPAdapterMaskProcessor
¶
Bases: VaeImageProcessor
Image processor for IP Adapter image masks.
PARAMETER | DESCRIPTION |
---|---|
do_resize |
Whether to downscale the image's (height, width) dimensions to multiples of
TYPE:
|
vae_scale_factor |
VAE scale factor. If
TYPE:
|
resample |
Resampling filter to use when resizing the image.
TYPE:
|
do_normalize |
Whether to normalize the image to [-1,1].
TYPE:
|
do_binarize |
Whether to binarize the image to 0/1.
TYPE:
|
do_convert_grayscale |
Whether to convert the images to grayscale format.
TYPE:
|
Source code in mindone/diffusers/image_processor.py
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 |
|
mindone.diffusers.image_processor.IPAdapterMaskProcessor.downsample(mask, batch_size, num_queries, value_embed_dim)
staticmethod
¶
Downsamples the provided mask tensor to match the expected dimensions for scaled dot-product attention. If the aspect ratio of the mask does not match the aspect ratio of the output image, a warning is issued.
PARAMETER | DESCRIPTION |
---|---|
mask |
The input mask tensor generated with
TYPE:
|
batch_size |
The batch size.
TYPE:
|
num_queries |
The number of queries.
TYPE:
|
value_embed_dim |
The dimensionality of the value embeddings.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
|
Source code in mindone/diffusers/image_processor.py
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 |
|