text
stringlengths
0
5.54k
data_type = torch.float16
prior = PriorTransformer.from_pretrained(prior_model_id, subfolder="prior", torch_dtype=data_type)
prior_text_model_id = "openai/clip-vit-large-patch14"
prior_tokenizer = CLIPTokenizer.from_pretrained(prior_text_model_id)
prior_text_model = CLIPTextModelWithProjection.from_pretrained(prior_text_model_id, torch_dtype=data_type)
prior_scheduler = UnCLIPScheduler.from_pretrained(prior_model_id, subfolder="prior_scheduler")
prior_scheduler = DDPMScheduler.from_config(prior_scheduler.config)
stable_unclip_model_id = "stabilityai/stable-diffusion-2-1-unclip-small"
pipe = StableUnCLIPPipeline.from_pretrained(
stable_unclip_model_id,
torch_dtype=data_type,
variant="fp16",
prior_tokenizer=prior_tokenizer,
prior_text_encoder=prior_text_model,
prior=prior,
prior_scheduler=prior_scheduler,
)
pipe = pipe.to("cuda")
wave_prompt = "dramatic wave, the Oceans roar, Strong wave spiral across the oceans as the waves unfurl into roaring crests; perfect wave form; perfect wave shape; dramatic wave shape; wave shape unbelievable; wave; wave shape spectacular"
image = pipe(prompt=wave_prompt).images[0]
image For text-to-image we use stabilityai/stable-diffusion-2-1-unclip-small as it was trained on CLIP ViT-L/14 embedding, the same as the Karlo model prior. stabilityai/stable-diffusion-2-1-unclip was trained on OpenCLIP ViT-H, so we don’t recommend its use. Text guided Image-to-Image Variation Copied from diffuser...
from diffusers.utils import load_image
import torch
pipe = StableUnCLIPImg2ImgPipeline.from_pretrained(
"stabilityai/stable-diffusion-2-1-unclip", torch_dtype=torch.float16, variation="fp16"
)
pipe = pipe.to("cuda")
url = "https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main/stable_unclip/tarsila_do_amaral.png"
init_image = load_image(url)
images = pipe(init_image).images
images[0].save("variation_image.png") Optionally, you can also pass a prompt to pipe such as: Copied prompt = "A fantasy landscape, trending on artstation"
image = pipe(init_image, prompt=prompt).images[0]
image 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. StableUnCLIPPipeline class diffusers.StableUnCLIPPipeline < s...
A CLIPTokenizer. prior_text_encoder (CLIPTextModelWithProjection) β€”
Frozen CLIPTextModelWithProjection text-encoder. prior (PriorTransformer) β€”
The canonincal unCLIP prior to approximate the image embedding from the text embedding. prior_scheduler (KarrasDiffusionSchedulers) β€”
Scheduler used in the prior denoising process. image_normalizer (StableUnCLIPImageNormalizer) β€”
Used to normalize the predicted image embeddings before the noise is applied and un-normalize the image
embeddings after the noise has been applied. image_noising_scheduler (KarrasDiffusionSchedulers) β€”
Noise schedule for adding noise to the predicted image embeddings. The amount of noise to add is determined
by the noise_level. tokenizer (CLIPTokenizer) β€”
A CLIPTokenizer. text_encoder (CLIPTextModel) β€”
Frozen CLIPTextModel text-encoder. unet (UNet2DConditionModel) β€”
A UNet2DConditionModel to denoise the encoded image latents. scheduler (KarrasDiffusionSchedulers) β€”
A scheduler to be used in combination with unet to denoise the encoded image latents. vae (AutoencoderKL) β€”
Variational Auto-Encoder (VAE) Model to encode and decode images to and from latent representations. Pipeline for text-to-image generation using stable unCLIP. This model inherits from DiffusionPipeline. Check the superclass documentation for the generic methods
implemented for all pipelines (downloading, saving, running on a particular device, etc.). The pipeline also inherits the following loading methods: load_textual_inversion() for loading textual inversion embeddings load_lora_weights() for loading LoRA weights save_lora_weights() for saving LoRA weights __call__ < sou...
The prompt or prompts to guide image generation. If not defined, you need to pass prompt_embeds. height (int, optional, defaults to self.unet.config.sample_size * self.vae_scale_factor) β€”
The height in pixels of the generated image. width (int, optional, defaults to self.unet.config.sample_size * self.vae_scale_factor) β€”
The width in pixels of the generated image. num_inference_steps (int, optional, defaults to 20) β€”
The number of denoising steps. More denoising steps usually lead to a higher quality image at the
expense of slower inference. guidance_scale (float, optional, defaults to 10.0) β€”
A higher guidance scale value encourages the model to generate images closely linked to the text
prompt at the expense of lower image quality. Guidance scale is enabled when guidance_scale > 1. negative_prompt (str or List[str], optional) β€”
The prompt or prompts to guide what to not include in image generation. If not defined, you need to
pass negative_prompt_embeds instead. Ignored when not using guidance (guidance_scale < 1). num_images_per_prompt (int, optional, defaults to 1) β€”
The number of images to generate per prompt. eta (float, optional, defaults to 0.0) β€”
Corresponds to parameter eta (Ξ·) from the DDIM paper. Only applies
to the DDIMScheduler, and is ignored in other schedulers. generator (torch.Generator or List[torch.Generator], optional) β€”
A torch.Generator to make
generation deterministic. latents (torch.FloatTensor, optional) β€”
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 is generated by sampling using the supplied random generator. prompt_embeds (torch.FloatTensor, optional) β€”
Pre-generated text embeddings. Can be used to easily tweak text inputs (prompt weighting). If not
provided, text embeddings are generated from the prompt input argument. negative_prompt_embeds (torch.FloatTensor, optional) β€”
Pre-generated negative text embeddings. Can be used to easily tweak text inputs (prompt weighting). If
not provided, negative_prompt_embeds are generated from the negative_prompt input argument. output_type (str, optional, defaults to "pil") β€”
The output format of the generated image. Choose between PIL.Image or np.array. return_dict (bool, optional, defaults to True) β€”
Whether or not to return a ImagePipelineOutput instead of a plain tuple. callback (Callable, optional) β€”
A function that calls every callback_steps steps during inference. The function is called with the
following arguments: callback(step: int, timestep: int, latents: torch.FloatTensor). callback_steps (int, optional, defaults to 1) β€”
The frequency at which the callback function is called. If not specified, the callback is called at
every step. cross_attention_kwargs (dict, optional) β€”
A kwargs dictionary that if specified is passed along to the AttentionProcessor as defined in
self.processor. noise_level (int, optional, defaults to 0) β€”
The amount of noise to add to the image embeddings. A higher noise_level increases the variance in
the final un-noised images. See StableUnCLIPPipeline.noise_image_embeddings() for more details. prior_num_inference_steps (int, optional, defaults to 25) β€”
The number of denoising steps in the prior denoising process. More denoising steps usually lead to a
higher quality image at the expense of slower inference. prior_guidance_scale (float, optional, defaults to 4.0) β€”
A higher guidance scale value encourages the model to generate images closely linked to the text
prompt at the expense of lower image quality. Guidance scale is enabled when guidance_scale > 1. prior_latents (torch.FloatTensor, optional) β€”
Pre-generated noisy latents sampled from a Gaussian distribution, to be used as inputs for image
embedding generation in the prior denoising process. Can be used to tweak the same generation with
different prompts. If not provided, a latents tensor is generated by sampling using the supplied random
generator. clip_skip (int, optional) β€”
Number of layers to be skipped from CLIP while computing the prompt embeddings. A value of 1 means that
the output of the pre-final layer will be used for computing the prompt embeddings. Returns
ImagePipelineOutput or tuple
~ pipeline_utils.ImagePipelineOutput if return_dict is True, otherwise a tuple. When returning