text
stringlengths 0
5.54k
|
---|
custom_pipeline="speech_to_image_diffusion", |
speech_model=model, |
speech_processor=processor, |
torch_dtype=torch.float16, |
) |
diffuser_pipeline.enable_attention_slicing() |
diffuser_pipeline = diffuser_pipeline.to(device) |
output = diffuser_pipeline(speech_data) |
plt.imshow(output.images[0]) |
This example produces the following image: |
VQModel The VQ-VAE model was introduced in Neural Discrete Representation Learning by Aaron van den Oord, Oriol Vinyals and Koray Kavukcuoglu. The model is used in π€ Diffusers to decode latent representations into images. Unlike AutoencoderKL, the VQModel works in a quantized latent space. The abstract from the paper is: Learning useful representations without supervision remains a key challenge in machine learning. In this paper, we propose a simple yet powerful generative model that learns such discrete representations. Our model, the Vector Quantised-Variational AutoEncoder (VQ-VAE), differs from VAEs in two key ways: the encoder network outputs discrete, rather than continuous, codes; and the prior is learnt rather than static. In order to learn a discrete latent representation, we incorporate ideas from vector quantisation (VQ). Using the VQ method allows the model to circumvent issues of βposterior collapseβ β where the latents are ignored when they are paired with a powerful autoregressive decoder β typically observed in the VAE framework. Pairing these representations with an autoregressive prior, the model can generate high quality images, videos, and speech as well as doing high quality speaker conversion and unsupervised learning of phonemes, providing further evidence of the utility of the learnt representations. VQModel class diffusers.VQModel < source > ( in_channels: int = 3 out_channels: int = 3 down_block_types: Tuple = ('DownEncoderBlock2D',) up_block_types: Tuple = ('UpDecoderBlock2D',) block_out_channels: Tuple = (64,) layers_per_block: int = 1 act_fn: str = 'silu' latent_channels: int = 3 sample_size: int = 32 num_vq_embeddings: int = 256 norm_num_groups: int = 32 vq_embed_dim: Optional = None scaling_factor: float = 0.18215 norm_type: str = 'group' mid_block_add_attention = True lookup_from_codebook = False force_upcast = False ) Parameters in_channels (int, optional, defaults to 3) β Number of channels in the input image. out_channels (int, optional, defaults to 3) β Number of channels in the output. down_block_types (Tuple[str], optional, defaults to ("DownEncoderBlock2D",)) β |
Tuple of downsample block types. up_block_types (Tuple[str], optional, defaults to ("UpDecoderBlock2D",)) β |
Tuple of upsample block types. block_out_channels (Tuple[int], optional, defaults to (64,)) β |
Tuple of block output channels. layers_per_block (int, optional, defaults to 1) β Number of layers per block. act_fn (str, optional, defaults to "silu") β The activation function to use. latent_channels (int, optional, defaults to 3) β Number of channels in the latent space. sample_size (int, optional, defaults to 32) β Sample input size. num_vq_embeddings (int, optional, defaults to 256) β Number of codebook vectors in the VQ-VAE. norm_num_groups (int, optional, defaults to 32) β Number of groups for normalization layers. vq_embed_dim (int, optional) β Hidden dim of codebook vectors in the VQ-VAE. scaling_factor (float, optional, defaults to 0.18215) β |
The component-wise standard deviation of the trained latent space computed using the first batch of the |
training set. This is used to scale the latent space to have unit variance when training the diffusion |
model. The latents are scaled with the formula z = z * scaling_factor before being passed to the |
diffusion model. When decoding, the latents are scaled back to the original scale with the formula: z = 1 / scaling_factor * z. For more details, refer to sections 4.3.2 and D.1 of the High-Resolution Image |
Synthesis with Latent Diffusion Models paper. norm_type (str, optional, defaults to "group") β |
Type of normalization layer to use. Can be one of "group" or "spatial". A VQ-VAE model for decoding latent representations. This model inherits from ModelMixin. Check the superclass documentation for itβs generic methods implemented |
for all models (such as downloading or saving). forward < source > ( sample: FloatTensor return_dict: bool = True ) β VQEncoderOutput or tuple Parameters sample (torch.FloatTensor) β Input sample. return_dict (bool, optional, defaults to True) β |
Whether or not to return a models.vq_model.VQEncoderOutput instead of a plain tuple. Returns |
VQEncoderOutput or tuple |
If return_dict is True, a VQEncoderOutput is returned, otherwise a plain tuple |
is returned. |
The VQModel forward method. VQEncoderOutput class diffusers.models.vq_model.VQEncoderOutput < source > ( latents: FloatTensor ) Parameters latents (torch.FloatTensor of shape (batch_size, num_channels, height, width)) β |
The encoded output sample from the last layer of the model. Output of VQModel encoding method. |
Paint by Example Paint by Example: Exemplar-based Image Editing with Diffusion Models is by Binxin Yang, Shuyang Gu, Bo Zhang, Ting Zhang, Xuejin Chen, Xiaoyan Sun, Dong Chen, Fang Wen. The abstract from the paper is: Language-guided image editing has achieved great success recently. In this paper, for the first time, we investigate exemplar-guided image editing for more precise control. We achieve this goal by leveraging self-supervised training to disentangle and re-organize the source image and the exemplar. However, the naive approach will cause obvious fusing artifacts. We carefully analyze it and propose an information bottleneck and strong augmentations to avoid the trivial solution of directly copying and pasting the exemplar image. Meanwhile, to ensure the controllability of the editing process, we design an arbitrary shape mask for the exemplar image and leverage the classifier-free guidance to increase the similarity to the exemplar image. The whole framework involves a single forward of the diffusion model without any iterative optimization. We demonstrate that our method achieves an impressive performance and enables controllable editing on in-the-wild images with high fidelity. The original codebase can be found at Fantasy-Studio/Paint-by-Example, and you can try it out in a demo. Tips Paint by Example is supported by the official Fantasy-Studio/Paint-by-Example checkpoint. The checkpoint is warm-started from CompVis/stable-diffusion-v1-4 to inpaint partly masked images conditioned on example and reference images. 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. PaintByExamplePipeline class diffusers.PaintByExamplePipeline < source > ( vae: AutoencoderKL image_encoder: PaintByExampleImageEncoder unet: UNet2DConditionModel scheduler: Union safety_checker: StableDiffusionSafetyChecker feature_extractor: CLIPImageProcessor requires_safety_checker: bool = False ) Parameters vae (AutoencoderKL) β |
Variational Auto-Encoder (VAE) model to encode and decode images to and from latent representations. image_encoder (PaintByExampleImageEncoder) β |
Encodes the example input image. The unet is conditioned on the example image instead of a text prompt. tokenizer (CLIPTokenizer) β |
A CLIPTokenizer 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. safety_checker (StableDiffusionSafetyChecker) β |
Classification module that estimates whether generated images could be considered offensive or harmful. |
Please refer to the model card for more details |
about a modelβs potential harms. feature_extractor (CLIPImageProcessor) β |
A CLIPImageProcessor to extract features from generated images; used as inputs to the safety_checker. π§ͺ This is an experimental feature! Pipeline for image-guided image inpainting using Stable 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 > ( example_image: Union image: Union mask_image: Union height: Optional = None width: Optional = None num_inference_steps: int = 50 guidance_scale: float = 5.0 negative_prompt: Union = None num_images_per_prompt: Optional = 1 eta: float = 0.0 generator: Union = None latents: Optional = None output_type: Optional = 'pil' return_dict: bool = True callback: Optional = None callback_steps: int = 1 ) β StableDiffusionPipelineOutput or tuple Parameters example_image (torch.FloatTensor or PIL.Image.Image or List[PIL.Image.Image]) β |
An example image to guide image generation. image (torch.FloatTensor or PIL.Image.Image or List[PIL.Image.Image]) β |
Image or tensor representing an image batch to be inpainted (parts of the image are masked out with |
mask_image and repainted according to prompt). mask_image (torch.FloatTensor or PIL.Image.Image or List[PIL.Image.Image]) β |
Image or tensor representing an image batch to mask image. White pixels in the mask are repainted, |
while black pixels are preserved. If mask_image is a PIL image, it is converted to a single channel |
(luminance) before use. If itβs a tensor, it should contain one color channel (L) instead of 3, so the |
expected shape would be (B, H, W, 1). 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 7.5) β |
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. 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 StableDiffusionPipelineOutput 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. Returns |
StableDiffusionPipelineOutput or tuple |
If return_dict is True, StableDiffusionPipelineOutput is returned, |
otherwise a tuple is returned where the first element is a list with the generated images and the |
second element is a list of bools indicating whether the corresponding generated image contains |
βnot-safe-for-workβ (nsfw) content. |
The call function to the pipeline for generation. Example: Copied >>> import PIL |
>>> import requests |
>>> import torch |
>>> from io import BytesIO |
>>> from diffusers import PaintByExamplePipeline |
>>> def download_image(url): |
... response = requests.get(url) |
... return PIL.Image.open(BytesIO(response.content)).convert("RGB") |
>>> img_url = ( |
... "https://raw.githubusercontent.com/Fantasy-Studio/Paint-by-Example/main/examples/image/example_1.png" |
... ) |
>>> mask_url = ( |
... "https://raw.githubusercontent.com/Fantasy-Studio/Paint-by-Example/main/examples/mask/example_1.png" |
... ) |
>>> example_url = "https://raw.githubusercontent.com/Fantasy-Studio/Paint-by-Example/main/examples/reference/example_1.jpg" |
>>> init_image = download_image(img_url).resize((512, 512)) |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.