text stringlengths 0 5.54k |
|---|
A BertTokenizer to tokenize text. unet (UNet2DConditionModel) โ |
A UNet2DConditionModel to denoise the encoded image latents. scheduler (SchedulerMixin) โ |
A scheduler to be used in combination with unet to denoise the encoded image latents. Can be one of |
DDIMScheduler, LMSDiscreteScheduler, or PNDMScheduler. Pipeline for text-to-image generation using latent diffusion. 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.). __call__ < source > ( prompt: Union height: Optional = None width: Optional = None num_inference_steps: Optional = 50 guidance_scale: Optional = 1.0 eta: Optional = 0.0 generator: Union = None latents: Optional = None output_ty... |
The prompt or prompts to guide the image generation. 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 50) โ |
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 1.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. generator (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. 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. Returns |
ImagePipelineOutput or tuple |
If return_dict is True, ImagePipelineOutput is returned, otherwise a tuple is |
returned where the first element is a list with the generated images. |
The call function to the pipeline for generation. Example: Copied >>> from diffusers import DiffusionPipeline |
>>> # load model and scheduler |
>>> ldm = DiffusionPipeline.from_pretrained("CompVis/ldm-text2im-large-256") |
>>> # run pipeline in inference (sample random noise and denoise) |
>>> prompt = "A painting of a squirrel eating a burger" |
>>> images = ldm([prompt], num_inference_steps=50, eta=0.3, guidance_scale=6).images |
>>> # save images |
>>> for idx, image in enumerate(images): |
... image.save(f"squirrel-{idx}.png") LDMSuperResolutionPipeline class diffusers.LDMSuperResolutionPipeline < source > ( vqvae: VQModel unet: UNet2DModel scheduler: Union ) Parameters vqvae (VQModel) โ |
Vector-quantized (VQ) model to encode and decode images to and from latent representations. unet (UNet2DModel) โ |
A UNet2DModel to denoise the encoded image. scheduler (SchedulerMixin) โ |
A scheduler to be used in combination with unet to denoise the encoded image latens. Can be one of |
DDIMScheduler, LMSDiscreteScheduler, EulerDiscreteScheduler, |
EulerAncestralDiscreteScheduler, DPMSolverMultistepScheduler, or PNDMScheduler. A pipeline for image super-resolution using latent diffusion. 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.). __call__ < source > ( image: Union = None batch_size: Optional = 1 num_inference_steps: Optional = 100 eta: Optional = 0.0 generator: Union = None output_type: Optional = 'pil' return_dict: bool = True ) โ ImagePipelineOutput ... |
Image or tensor representing an image batch to be used as the starting point for the process. batch_size (int, optional, defaults to 1) โ |
Number of images to generate. num_inference_steps (int, optional, defaults to 100) โ |
The number of denoising steps. More denoising steps usually lead to a higher quality image at the |
expense of slower inference. 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. 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. Returns |
ImagePipelineOutput or tuple |
If return_dict is True, ImagePipelineOutput is returned, otherwise a tuple is |
returned where the first element is a list with the generated images |
The call function to the pipeline for generation. Example: Copied >>> import requests |
>>> from PIL import Image |
>>> from io import BytesIO |
>>> from diffusers import LDMSuperResolutionPipeline |
>>> import torch |
>>> # load model and scheduler |
>>> pipeline = LDMSuperResolutionPipeline.from_pretrained("CompVis/ldm-super-resolution-4x-openimages") |
>>> pipeline = pipeline.to("cuda") |
>>> # let's download an image |
>>> url = ( |
... "https://user-images.githubusercontent.com/38061659/199705896-b48e17b8-b231-47cd-a270-4ffa5a93fa3e.png" |
... ) |
>>> response = requests.get(url) |
>>> low_res_img = Image.open(BytesIO(response.content)).convert("RGB") |
>>> low_res_img = low_res_img.resize((128, 128)) |
>>> # run pipeline in inference (sample random noise and denoise) |
>>> upscaled_image = pipeline(low_res_img, num_inference_steps=100, eta=1).images[0] |
>>> # save image |
>>> upscaled_image.save("ldm_generated_image.png") ImagePipelineOutput class diffusers.ImagePipelineOutput < source > ( images: Union ) Parameters images (List[PIL.Image.Image] or np.ndarray) โ |
List of denoised PIL images of length batch_size or NumPy array of shape (batch_size, height, width, num_channels). Output class for image pipelines. |
Overview ๐ค Diffusers provides a collection of training scripts for you to train your own diffusion models. You can find all of our training scripts in diffusers/examples. Each training script is: Self-contained: the training script does not depend on any local files, and all packages required to run the script are ins... |
cd diffusers |
pip install . Then navigate to the folder of the training script (for example, DreamBooth) and install the requirements.txt file. Some training scripts have a specific requirement file for SDXL, LoRA or Flax. If youโre using one of these scripts, make sure you install its corresponding requirements file. Copied cd ex... |
pip install -r requirements.txt |
# to train SDXL with DreamBooth |
pip install -r requirements_sdxl.txt To speedup training and reduce memory-usage, we recommend: using PyTorch 2.0 or higher to automatically use scaled dot product attention during training (you donโt need to make any changes to the training code) installing xFormers to enable memory-efficient attention |
Kandinsky The Kandinsky models are a series of multilingual text-to-image generation models. The Kandinsky 2.0 model uses two multilingual text encoders and concatenates those results for the UNet. Kandinsky 2.1 changes the architecture to include an image prior model (CLIP) to generate a mapping between tex... |
#!pip install -q diffusers transformers accelerate Kandinsky 2.1 and 2.2 usage is very similar! The only difference is Kandinsky 2.2 doesnโt accept prompt as an input when decoding the latents. Instead, Kandinsky 2.2 only accepts image_embeds during decoding. Kandinsky 3 has a more concise architecture and it doesnโt ... |
<hfoptions id="text-to-image"> |
<hfoption id="Kandinsky 2.1"> |
Copied from diffusers import KandinskyPriorPipeline, KandinskyPipeline |
import torch |
prior_pipeline = KandinskyPriorPipeline.from_pretrained("kandinsky-community/kandinsky-2-1-prior", torch_dtype=torch.float16).to("cuda") |
pipeline = KandinskyPipeline.from_pretrained("kandinsky-community/kandinsky-2-1", torch_dtype=torch.float16).to("cuda") |
prompt = "A alien cheeseburger creature eating itself, claymation, cinematic, moody lighting" |
negative_prompt = "low quality, bad quality" # optional to include a negative prompt, but results are usually better |
image_embeds, negative_image_embeds = prior_pipeline(prompt, negative_prompt, guidance_scale=1.0).to_tuple() Now pass all the prompts and embeddings to the KandinskyPipeline to generate an image: Copied image = pipeline(prompt, image_embeds=image_embeds, negative_prompt=negative_prompt, negative_image_embeds=negative... |
image |
</hfoption> |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.