VisualCloze¶
VisualCloze: A Universal Image Generation Framework via Visual In-Context Learning is an innovative in-context learning based universal image generation framework that offers key capabilities: 1. Support for various in-domain tasks 2. Generalization to unseen tasks through in-context learning 3. Unify multiple tasks into one step and generate both target image and intermediate results 4. Support reverse-engineering conditions from target images
Overview¶
The abstract from the paper is:
Recent progress in diffusion models significantly advances various image generation tasks. However, the current mainstream approach remains focused on building task-specific models, which have limited efficiency when supporting a wide range of different needs. While universal models attempt to address this limitation, they face critical challenges, including generalizable task instruction, appropriate task distributions, and unified architectural design. To tackle these challenges, we propose VisualCloze, a universal image generation framework, which supports a wide range of in-domain tasks, generalization to unseen ones, unseen unification of multiple tasks, and reverse generation. Unlike existing methods that rely on language-based task instruction, leading to task ambiguity and weak generalization, we integrate visual in-context learning, allowing models to identify tasks from visual demonstrations. Meanwhile, the inherent sparsity of visual task distributions hampers the learning of transferable knowledge across tasks. To this end, we introduce Graph200K, a graph-structured dataset that establishes various interrelated tasks, enhancing task density and transferable knowledge. Furthermore, we uncover that our unified image generation formulation shared a consistent objective with image infilling, enabling us to leverage the strong generative priors of pre-trained infilling models without modifying the architectures. The codes, dataset, and models are available at https://visualcloze.github.io.
Inference¶
Model loading¶
VisualCloze is a two-stage cascade pipeline, containing VisualClozeGenerationPipeline
and VisualClozeUpsamplingPipeline
.
- In VisualClozeGenerationPipeline
, each image is downsampled before concatenating images into a grid layout, avoiding excessively high resolutions. VisualCloze releases two models suitable for diffusers, i.e., VisualClozePipeline-384 and VisualClozePipeline-512, which downsample images to resolutions of 384 and 512, respectively.
- VisualClozeUpsamplingPipeline
uses SDEdit to enable high-resolution image synthesis.
The VisualClozePipeline
integrates both stages to support convenient end-to-end sampling, while also allowing users to utilize each pipeline independently as needed.
Input Specifications¶
Task and Content Prompts¶
- Task prompt: Required to describe the generation task intention
- Content prompt: Optional description or caption of the target image
- When content prompt is not needed, pass
None
- For batch inference, pass
List[str|None]
Image Input Format¶
- Format:
List[List[Image|None]]
- Structure:
- All rows except the last represent in-context examples
- Last row represents the current query (target image set to
None
) - For batch inference, pass
List[List[List[Image|None]]]
Resolution Control¶
- Default behavior:
- Initial generation in the first stage: area of \({pipe.resolution}^2\)
- Upsampling in the second stage: 3x factor
- Custom resolution: Adjust using
upsampling_height
andupsampling_width
parameters
Examples¶
For comprehensive examples covering a wide range of tasks, please refer to the Online Demo and GitHub Repository. Below are simple examples for three cases: mask-to-image conversion, edge detection, and subject-driven generation.
Example for mask2image¶
import mindspore as ms
from mindone.diffusers import VisualClozePipeline
from mindone.diffusers.utils import load_image
import numpy as np
pipe = VisualClozePipeline.from_pretrained("VisualCloze/VisualClozePipeline-384", resolution=384, mindspore_dtype=ms.bfloat16)
# Load in-context images (make sure the paths are correct and accessible)
image_paths = [
# in-context examples
[
load_image('https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/diffusers/visualcloze/visualcloze_mask2image_incontext-example-1_mask.jpg'),
load_image('https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/diffusers/visualcloze/visualcloze_mask2image_incontext-example-1_image.jpg'),
],
# query with the target image
[
load_image('https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/diffusers/visualcloze/visualcloze_mask2image_query_mask.jpg'),
None, # No image needed for the target image
],
]
# Task and content prompt
task_prompt = "In each row, a logical task is demonstrated to achieve [IMAGE2] an aesthetically pleasing photograph based on [IMAGE1] sam 2-generated masks with rich color coding."
content_prompt = """Majestic photo of a golden eagle perched on a rocky outcrop in a mountainous landscape.
The eagle is positioned in the right foreground, facing left, with its sharp beak and keen eyes prominently visible.
Its plumage is a mix of dark brown and golden hues, with intricate feather details.
The background features a soft-focus view of snow-capped mountains under a cloudy sky, creating a serene and grandiose atmosphere.
The foreground includes rugged rocks and patches of green moss. Photorealistic, medium depth of field,
soft natural lighting, cool color palette, high contrast, sharp focus on the eagle, blurred background,
tranquil, majestic, wildlife photography."""
# Run the pipeline
image_result = pipe(
task_prompt=task_prompt,
content_prompt=content_prompt,
image=image_paths,
upsampling_width=1344,
upsampling_height=768,
upsampling_strength=0.4,
guidance_scale=30,
num_inference_steps=30,
max_sequence_length=512,
generator=np.random.Generator(np.random.PCG64(seed=0))
)[0][0][0]
# Save the resulting image
image_result.save("visualcloze.png")
Example for edge-detection¶
import mindspore as ms
from mindone.diffusers import VisualClozePipeline
from mindone.diffusers.utils import load_image
import numpy as np
pipe = VisualClozePipeline.from_pretrained("VisualCloze/VisualClozePipeline-384", resolution=384, mindspore_dtype=ms.bfloat16)
# Load in-context images (make sure the paths are correct and accessible)
image_paths = [
# in-context examples
[
load_image('https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/diffusers/visualcloze/visualcloze_edgedetection_incontext-example-1_image.jpg'),
load_image('https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/diffusers/visualcloze/visualcloze_edgedetection_incontext-example-1_edge.jpg'),
],
[
load_image('https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/diffusers/visualcloze/visualcloze_edgedetection_incontext-example-2_image.jpg'),
load_image('https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/diffusers/visualcloze/visualcloze_edgedetection_incontext-example-2_edge.jpg'),
],
# query with the target image
[
load_image('https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/diffusers/visualcloze/visualcloze_edgedetection_query_image.jpg'),
None, # No image needed for the target image
],
]
# Task and content prompt
task_prompt = "Each row illustrates a pathway from [IMAGE1] a sharp and beautifully composed photograph to [IMAGE2] edge map with natural well-connected outlines using a clear logical task."
content_prompt = ""
# Run the pipeline
image_result = pipe(
task_prompt=task_prompt,
content_prompt=content_prompt,
image=image_paths,
upsampling_width=864,
upsampling_height=1152,
upsampling_strength=0.4,
guidance_scale=30,
num_inference_steps=30,
max_sequence_length=512,
generator=np.random.Generator(np.random.PCG64(seed=0))
)[0][0][0]
# Save the resulting image
image_result.save("visualcloze.png")
Example for subject-driven generation¶
import mindspore as ms
from mindone.diffusers import VisualClozePipeline
from mindone.diffusers.utils import load_image
import numpy as np
pipe = VisualClozePipeline.from_pretrained("VisualCloze/VisualClozePipeline-384", resolution=384, mindspore_dtype=ms.bfloat16)
# Load in-context images (make sure the paths are correct and accessible)
image_paths = [
# in-context examples
[
load_image('https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/diffusers/visualcloze/visualcloze_subjectdriven_incontext-example-1_reference.jpg'),
load_image('https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/diffusers/visualcloze/visualcloze_subjectdriven_incontext-example-1_depth.jpg'),
load_image('https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/diffusers/visualcloze/visualcloze_subjectdriven_incontext-example-1_image.jpg'),
],
[
load_image('https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/diffusers/visualcloze/visualcloze_subjectdriven_incontext-example-2_reference.jpg'),
load_image('https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/diffusers/visualcloze/visualcloze_subjectdriven_incontext-example-2_depth.jpg'),
load_image('https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/diffusers/visualcloze/visualcloze_subjectdriven_incontext-example-2_image.jpg'),
],
# query with the target image
[
load_image('https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/diffusers/visualcloze/visualcloze_subjectdriven_query_reference.jpg'),
load_image('https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/diffusers/visualcloze/visualcloze_subjectdriven_query_depth.jpg'),
None, # No image needed for the target image
],
]
# Task and content prompt
task_prompt = """Each row describes a process that begins with [IMAGE1] an image containing the key object,
[IMAGE2] depth map revealing gray-toned spatial layers and results in
[IMAGE3] an image with artistic qualitya high-quality image with exceptional detail."""
content_prompt = """A vintage porcelain collector's item. Beneath a blossoming cherry tree in early spring,
this treasure is photographed up close, with soft pink petals drifting through the air and vibrant blossoms framing the scene."""
# Run the pipeline
image_result = pipe(
task_prompt=task_prompt,
content_prompt=content_prompt,
image=image_paths,
upsampling_width=1024,
upsampling_height=1024,
upsampling_strength=0.2,
guidance_scale=30,
num_inference_steps=30,
max_sequence_length=512,
generator=np.random.Generator(np.random.PCG64(seed=0))
)[0][0][0]
# Save the resulting image
image_result.save("visualcloze.png")
Utilize each pipeline independently¶
import mindspore as ms
from mindone.diffusers import VisualClozeGenerationPipeline, FluxFillPipeline as VisualClozeUpsamplingPipeline
from mindone.diffusers.utils import load_image
from PIL import Image
import numpy as np
pipe = VisualClozeGenerationPipeline.from_pretrained(
"VisualCloze/VisualClozePipeline-384", resolution=384, mindspore_dtype=ms.bfloat16
)
image_paths = [
# in-context examples
[
load_image(
"https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/diffusers/visualcloze/visualcloze_mask2image_incontext-example-1_mask.jpg"
),
load_image(
"https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/diffusers/visualcloze/visualcloze_mask2image_incontext-example-1_image.jpg"
),
],
# query with the target image
[
load_image(
"https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/diffusers/visualcloze/visualcloze_mask2image_query_mask.jpg"
),
None, # No image needed for the target image
],
]
task_prompt = "In each row, a logical task is demonstrated to achieve [IMAGE2] an aesthetically pleasing photograph based on [IMAGE1] sam 2-generated masks with rich color coding."
content_prompt = "Majestic photo of a golden eagle perched on a rocky outcrop in a mountainous landscape. The eagle is positioned in the right foreground, facing left, with its sharp beak and keen eyes prominently visible. Its plumage is a mix of dark brown and golden hues, with intricate feather details. The background features a soft-focus view of snow-capped mountains under a cloudy sky, creating a serene and grandiose atmosphere. The foreground includes rugged rocks and patches of green moss. Photorealistic, medium depth of field, soft natural lighting, cool color palette, high contrast, sharp focus on the eagle, blurred background, tranquil, majestic, wildlife photography."
# Stage 1: Generate initial image
image = pipe(
task_prompt=task_prompt,
content_prompt=content_prompt,
image=image_paths,
guidance_scale=30,
num_inference_steps=30,
max_sequence_length=512,
generator=np.random.Generator(np.random.PCG64(seed=0)),
)[0][0][0]
# Stage 2 (optional): Upsample the generated image
pipe_upsample = VisualClozeUpsamplingPipeline.from_pipe(pipe)
mask_image = Image.new("RGB", image.size, (255, 255, 255))
image = pipe_upsample(
image=image,
mask_image=mask_image,
prompt=content_prompt,
width=1344,
height=768,
strength=0.4,
guidance_scale=30,
num_inference_steps=30,
max_sequence_length=512,
generator=np.random.Generator(np.random.PCG64(seed=0)),
)[0][0]
image.save("visualcloze.png")
mindone.diffusers.VisualClozePipeline
¶
Bases: DiffusionPipeline
, FluxLoraLoaderMixin
, FromSingleFileMixin
, TextualInversionLoaderMixin
The VisualCloze pipeline for image generation with visual context. Reference: https://github.com/lzyhha/VisualCloze/tree/main. This pipeline is designed to generate images based on visual in-context examples.
PARAMETER | DESCRIPTION |
---|---|
transformer
|
Conditional Transformer (MMDiT) architecture to denoise the encoded image latents.
TYPE:
|
scheduler
|
A scheduler to be used in combination with
TYPE:
|
vae
|
Variational Auto-Encoder (VAE) Model to encode and decode images to and from latent representations.
TYPE:
|
text_encoder
|
CLIP, specifically the clip-vit-large-patch14 variant.
TYPE:
|
text_encoder_2
|
T5, specifically the google/t5-v1_1-xxl variant.
TYPE:
|
tokenizer
|
Tokenizer of class CLIPTokenizer.
TYPE:
|
tokenizer_2
|
Second Tokenizer of class T5TokenizerFast.
TYPE:
|
resolution
|
The resolution of each image when concatenating images from the query and in-context examples.
TYPE:
|
Source code in mindone/diffusers/pipelines/visualcloze/pipeline_visualcloze_combined.py
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 |
|
mindone.diffusers.VisualClozePipeline.__call__(task_prompt=None, content_prompt=None, image=None, upsampling_height=None, upsampling_width=None, num_inference_steps=50, sigmas=None, guidance_scale=30.0, num_images_per_prompt=1, generator=None, latents=None, prompt_embeds=None, pooled_prompt_embeds=None, output_type='pil', return_dict=True, joint_attention_kwargs=None, callback_on_step_end=None, callback_on_step_end_tensor_inputs=['latents'], max_sequence_length=512, upsampling_strength=1.0)
¶
Function invoked when calling the VisualCloze pipeline for generation.
PARAMETER | DESCRIPTION |
---|---|
task_prompt
|
The prompt or prompts to define the task intention.
TYPE:
|
content_prompt
|
The prompt or prompts to define the content or caption of the target image to be generated.
TYPE:
|
image
|
TYPE:
|
upsampling_height
|
The height in pixels of the generated image (i.e., output image) after upsampling via SDEdit. By
default, the image is upsampled by a factor of three, and the base resolution is determined by the
resolution parameter of the pipeline. When only one of
TYPE:
|
upsampling_width
|
The width in pixels of the generated image (i.e., output image) after upsampling via SDEdit. By
default, the image is upsampled by a factor of three, and the base resolution is determined by the
resolution parameter of the pipeline. When only one of
TYPE:
|
num_inference_steps
|
The number of denoising steps. More denoising steps usually lead to a higher quality image at the expense of slower inference.
TYPE:
|
sigmas
|
Custom sigmas to use for the denoising process with schedulers which support a
TYPE:
|
guidance_scale
|
Guidance scale as defined in Classifier-Free Diffusion
Guidance.
TYPE:
|
num_images_per_prompt
|
The number of images to generate per prompt.
TYPE:
|
generator
|
One or a list of torch generator(s) to make generation deterministic.
TYPE:
|
latents
|
Pre-generated noisy latents, sampled from a Gaussian distribution, to be used as inputs for image
generation. Can be used to tweak the same generation with different prompts. If not provided, a latents
tensor will ge generated by sampling using the supplied random
TYPE:
|
prompt_embeds
|
Pre-generated text embeddings. Can be used to easily tweak text inputs, e.g. prompt weighting. If not
provided, text embeddings will be generated from
TYPE:
|
pooled_prompt_embeds
|
Pre-generated pooled text embeddings. Can be used to easily tweak text inputs, e.g. prompt weighting.
If not provided, pooled text embeddings will be generated from
TYPE:
|
output_type
|
The output format of the generate image. Choose between
PIL:
TYPE:
|
return_dict
|
Whether or not to return a [
TYPE:
|
joint_attention_kwargs
|
A kwargs dictionary that if specified is passed along to the
TYPE:
|
callback_on_step_end
|
A function that calls at the end of each denoising steps during the inference. The function is called
with the following arguments:
TYPE:
|
callback_on_step_end_tensor_inputs
|
The list of tensor inputs for the
TYPE:
|
max_sequence_length
|
Maximum sequence length to use with the
TYPE:
|
upsampling_strength
|
Indicates extent to transform the reference
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
[ |
|
is True, otherwise a |
|
images. |
Source code in mindone/diffusers/pipelines/visualcloze/pipeline_visualcloze_combined.py
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 |
|
mindone.diffusers.VisualClozeGenerationPipeline
¶
Bases: DiffusionPipeline
, FluxLoraLoaderMixin
, FromSingleFileMixin
, TextualInversionLoaderMixin
The VisualCloze pipeline for image generation with visual context. Reference: https://github.com/lzyhha/VisualCloze/tree/main This pipeline is designed to generate images based on visual in-context examples.
PARAMETER | DESCRIPTION |
---|---|
transformer
|
Conditional Transformer (MMDiT) architecture to denoise the encoded image latents.
TYPE:
|
scheduler
|
A scheduler to be used in combination with
TYPE:
|
vae
|
Variational Auto-Encoder (VAE) Model to encode and decode images to and from latent representations.
TYPE:
|
text_encoder
|
CLIP, specifically the clip-vit-large-patch14 variant.
TYPE:
|
text_encoder_2
|
T5, specifically the google/t5-v1_1-xxl variant.
TYPE:
|
tokenizer
|
Tokenizer of class CLIPTokenizer.
TYPE:
|
tokenizer_2
|
Second Tokenizer of class T5TokenizerFast.
TYPE:
|
resolution
|
The resolution of each image when concatenating images from the query and in-context examples.
TYPE:
|
Source code in mindone/diffusers/pipelines/visualcloze/pipeline_visualcloze_generation.py
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 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 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 |
|
mindone.diffusers.VisualClozeGenerationPipeline.__call__(task_prompt=None, content_prompt=None, image=None, num_inference_steps=50, sigmas=None, guidance_scale=30.0, num_images_per_prompt=1, generator=None, latents=None, prompt_embeds=None, pooled_prompt_embeds=None, output_type='pil', return_dict=False, joint_attention_kwargs=None, callback_on_step_end=None, callback_on_step_end_tensor_inputs=['latents'], max_sequence_length=512)
¶
Function invoked when calling the VisualCloze pipeline for generation.
PARAMETER | DESCRIPTION |
---|---|
task_prompt
|
The prompt or prompts to define the task intention.
TYPE:
|
content_prompt
|
The prompt or prompts to define the content or caption of the target image to be generated.
TYPE:
|
image
|
TYPE:
|
num_inference_steps
|
The number of denoising steps. More denoising steps usually lead to a higher quality image at the expense of slower inference.
TYPE:
|
sigmas
|
Custom sigmas to use for the denoising process with schedulers which support a
TYPE:
|
guidance_scale
|
Guidance scale as defined in Classifier-Free Diffusion
Guidance.
TYPE:
|
num_images_per_prompt
|
The number of images to generate per prompt.
TYPE:
|
generator
|
One or a list of numpy generator(s) to make generation deterministic.
TYPE:
|
latents
|
Pre-generated noisy latents, sampled from a Gaussian distribution, to be used as inputs for image
generation. Can be used to tweak the same generation with different prompts. If not provided, a latents
tensor will ge generated by sampling using the supplied random
TYPE:
|
prompt_embeds
|
Pre-generated text embeddings. Can be used to easily tweak text inputs, e.g. prompt weighting. If not
provided, text embeddings will be generated from
TYPE:
|
pooled_prompt_embeds
|
Pre-generated pooled text embeddings. Can be used to easily tweak text inputs, e.g. prompt weighting.
If not provided, pooled text embeddings will be generated from
TYPE:
|
output_type
|
The output format of the generate image. Choose between
PIL:
TYPE:
|
return_dict
|
Whether or not to return a [
TYPE:
|
joint_attention_kwargs
|
A kwargs dictionary that if specified is passed along to the
TYPE:
|
callback_on_step_end
|
A function that calls at the end of each denoising steps during the inference. The function is called
with the following arguments:
TYPE:
|
callback_on_step_end_tensor_inputs
|
The list of tensor inputs for the
TYPE:
|
max_sequence_length
|
Maximum sequence length to use with the
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
[ |
|
is True, otherwise a |
|
images. |
Source code in mindone/diffusers/pipelines/visualcloze/pipeline_visualcloze_generation.py
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 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 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 |
|
mindone.diffusers.VisualClozeGenerationPipeline.disable_vae_slicing()
¶
Disable sliced VAE decoding. If enable_vae_slicing
was previously enabled, this method will go back to
computing decoding in one step.
Source code in mindone/diffusers/pipelines/visualcloze/pipeline_visualcloze_generation.py
512 513 514 515 516 517 |
|
mindone.diffusers.VisualClozeGenerationPipeline.disable_vae_tiling()
¶
Disable tiled VAE decoding. If enable_vae_tiling
was previously enabled, this method will go back to
computing decoding in one step.
Source code in mindone/diffusers/pipelines/visualcloze/pipeline_visualcloze_generation.py
527 528 529 530 531 532 |
|
mindone.diffusers.VisualClozeGenerationPipeline.enable_vae_slicing()
¶
Enable sliced VAE decoding. When this option is enabled, the VAE will split the input tensor in slices to compute decoding in several steps. This is useful to save some memory and allow larger batch sizes.
Source code in mindone/diffusers/pipelines/visualcloze/pipeline_visualcloze_generation.py
505 506 507 508 509 510 |
|
mindone.diffusers.VisualClozeGenerationPipeline.enable_vae_tiling()
¶
Enable tiled VAE decoding. When this option is enabled, the VAE will split the input tensor into tiles to compute decoding and encoding in several steps. This is useful for saving a large amount of memory and to allow processing larger images.
Source code in mindone/diffusers/pipelines/visualcloze/pipeline_visualcloze_generation.py
519 520 521 522 523 524 525 |
|
mindone.diffusers.VisualClozeGenerationPipeline.encode_prompt(layout_prompt, task_prompt, content_prompt, num_images_per_prompt=1, prompt_embeds=None, pooled_prompt_embeds=None, max_sequence_length=512, lora_scale=None)
¶
PARAMETER | DESCRIPTION |
---|---|
layout_prompt
|
The prompt or prompts to define the number of in-context examples and the number of images involved in the task.
TYPE:
|
task_prompt
|
The prompt or prompts to define the task intention.
TYPE:
|
content_prompt
|
The prompt or prompts to define the content or caption of the target image to be generated.
TYPE:
|
num_images_per_prompt
|
number of images that should be generated per prompt
TYPE:
|
prompt_embeds
|
Pre-generated text embeddings. Can be used to easily tweak text inputs, e.g. prompt weighting. If not
provided, text embeddings will be generated from
TYPE:
|
pooled_prompt_embeds
|
Pre-generated pooled text embeddings. Can be used to easily tweak text inputs, e.g. prompt weighting.
If not provided, pooled text embeddings will be generated from
TYPE:
|
lora_scale
|
A lora scale that will be applied to all LoRA layers of the text encoder if LoRA layers are loaded.
TYPE:
|
Source code in mindone/diffusers/pipelines/visualcloze/pipeline_visualcloze_generation.py
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 |
|