class_docstr: Pipeline for text-to-image generation using Retrieval Augmented Diffusion.
  
  This model inherits from [`DiffusionPipeline`]. Check the superclass documentation for the generic methods the
  library implements for all the pipelines (such as downloading or saving, running on a particular device, etc.)
  
  Args:
      vae ([`AutoencoderKL`]):
          Variational Auto-Encoder (VAE) Model to encode and decode images to and from latent representations.
      clip ([`CLIPModel`]):
          Frozen CLIP model. Retrieval Augmented Diffusion uses the CLIP model, specifically the
          [clip-vit-large-patch14](https://huggingface.co/openai/clip-vit-large-patch14) variant.
      tokenizer (`CLIPTokenizer`):
          Tokenizer of class
          [CLIPTokenizer](https://huggingface.co/docs/transformers/v4.21.0/en/model_doc/clip#transformers.CLIPTokenizer).
      unet ([`UNet2DConditionModel`]): Conditional U-Net architecture 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`].
      feature_extractor ([`CLIPFeatureExtractor`]):
          Model that extracts features from generated images to be used as inputs for the `safety_checker`.
class_docstr_tok: ["Pipeline","for","text-to-image","generation","using","Retrieval","Augmented","Diffusion",".","This","model","inherits","from","[","`","DiffusionPipeline","`","]",".","Check","the","superclass","documentation","for","the","generic","methods","the","library","implements","for","all","the","pipelines","(","such","as","downloading","or","saving",",","running","on","a","particular","device",",","etc",".",")","Args",":","vae","(","[","`","AutoencoderKL","`","]",")",":","Variational","Auto-Encoder","(","VAE",")","Model","to","encode","and","decode","images","to","and","from","latent","representations",".","clip","(","[","`","CLIPModel","`","]",")",":","Frozen","CLIP","model",".","Retrieval","Augmented","Diffusion","uses","the","CLIP","model",",","specifically","the","[","clip-vit-large-patch14","]","(","https",":","\/\/huggingface.co\/openai\/clip-vit-large-patch14",")","variant",".","tokenizer","(","`","CLIPTokenizer","`",")",":","Tokenizer","of","class","[","CLIPTokenizer","]","(","https",":","\/\/huggingface.co\/docs\/transformers\/v4.21.0\/en\/model_doc\/clip","#","transformers.CLIPTokenizer",")",".","unet","(","[","`","UNet2DConditionModel","`","]",")",":","Conditional","U-Net","architecture","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","`","]",".","feature_extractor","(","[","`","CLIPFeatureExtractor","`","]",")",":","Model","that","extracts","features","from","generated","images","to","be","used","as","inputs","for","the","`","safety_checker","`","."]
code: def _encode_image(self, retrieved_images, batch_size):
      if len(retrieved_images[0]) == 0:
          return None
      for i in range(len(retrieved_images)):
          retrieved_images[i] = normalize_images(retrieved_images[i])
          retrieved_images[i] = preprocess_images(
              retrieved_images[i], self.feature_extractor
          ).to(self.clip.device, dtype=self.clip.dtype)
      _, c, h, w = retrieved_images[0].shape
  
      retrieved_images = torch.reshape(
          torch.cat(retrieved_images, dim=0), (-1, c, h, w)
      )
      image_embeddings = self.clip.get_image_features(retrieved_images)
      image_embeddings = image_embeddings / torch.linalg.norm(
          image_embeddings, dim=-1, keepdim=True
      )
      _, d = image_embeddings.shape
      image_embeddings = torch.reshape(
          image_embeddings, (batch_size, -1, d)
      )
      return image_embeddings
  
imports: import inspect
  from typing import Callable, List, Optional, Union
  import torch
  from PIL import Image
  from retriever import Retriever, normalize_images, preprocess_images
  from transformers import CLIPFeatureExtractor, CLIPModel, CLIPTokenizer
  from diffusers import AutoencoderKL, DDIMScheduler, DiffusionPipeline, DPMSolverMultistepScheduler, EulerAncestralDiscreteScheduler, EulerDiscreteScheduler, ImagePipelineOutput, LMSDiscreteScheduler, PNDMScheduler, UNet2DConditionModel, logging
  from diffusers.image_processor import VaeImageProcessor
  from diffusers.utils import is_accelerate_available, randn_tensor
label_desc: Use image node_id 13 for calling the RDMPipeline obj's underlying member method code with example usage: obj._encode_image(retrieved_images, batch_size) and returns: image_embeddings, None