class_docstr: Pipeline for text-guided image-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.).
  
  Args:
      feature_extractor ([`CLIPImageProcessor`]):
          Feature extractor for image pre-processing before being encoded.
      image_encoder ([`CLIPVisionModelWithProjection`]):
          CLIP vision model for encoding images.
      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 (`~transformers.CLIPTokenizer`):
          A [`~transformers.CLIPTokenizer`)].
      text_encoder ([`~transformers.CLIPTextModel`]):
          Frozen [`~transformers.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.
class_docstr_tok: ["Pipeline","for","text-guided","image-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.",")",".","Args",":","feature_extractor","(","[","`","CLIPImageProcessor","`","]",")",":","Feature","extractor","for","image","pre-processing","before","being","encoded",".","image_encoder","(","[","`","CLIPVisionModelWithProjection","`","]",")",":","CLIP","vision","model","for","encoding","images",".","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","(","`","~transformers.CLIPTokenizer","`",")",":","A","[","`","~transformers.CLIPTokenizer","`",")","]",".","text_encoder","(","[","`","~transformers.CLIPTextModel","`","]",")",":","Frozen","[","`","~transformers.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","."]
code: def _encode_image(
      self,
      image,
      device,
      batch_size,
      num_images_per_prompt,
      do_classifier_free_guidance,
      noise_level,
      generator,
      image_embeds,
  ):
      dtype = next(self.image_encoder.parameters()).dtype
  
      if isinstance(image, PIL.Image.Image):
          # the image embedding should repeated so it matches the total batch size of the prompt
          repeat_by = batch_size
      else:
          # assume the image input is already properly batched and just needs to be repeated so
          # it matches the num_images_per_prompt.
          #
          # NOTE(will) this is probably missing a few number of side cases. I.e. batched/non-batched
          # `image_embeds`. If those happen to be common use cases, let's think harder about
          # what the expected dimensions of inputs should be and how we handle the encoding.
          repeat_by = num_images_per_prompt
  
      if image_embeds is None:
          if not isinstance(image, torch.Tensor):
              image = self.feature_extractor(
                  images=image, return_tensors="pt"
              ).pixel_values
  
          image = image.to(device=device, dtype=dtype)
          image_embeds = self.image_encoder(image).image_embeds
  
      image_embeds = self.noise_image_embeddings(
          image_embeds=image_embeds,
          noise_level=noise_level,
          generator=generator,
      )
  
      # duplicate image embeddings for each generation per prompt, using mps friendly method
      image_embeds = image_embeds.unsqueeze(1)
      bs_embed, seq_len, _ = image_embeds.shape
      image_embeds = image_embeds.repeat(1, repeat_by, 1)
      image_embeds = image_embeds.view(
          bs_embed * repeat_by, seq_len, -1
      )
      image_embeds = image_embeds.squeeze(1)
  
      if do_classifier_free_guidance:
          negative_prompt_embeds = torch.zeros_like(image_embeds)
  
          # For classifier free guidance, we need to do two forward passes.
          # Here we concatenate the unconditional and text embeddings into a single batch
          # to avoid doing two forward passes
          image_embeds = torch.cat(
              [negative_prompt_embeds, image_embeds]
          )
  
      return image_embeds
  
imports: import inspect
  from typing import Any, Callable, Dict, List, Optional, Union
  import PIL.Image
  import torch
  from transformers import CLIPImageProcessor, CLIPTextModel, CLIPTokenizer, CLIPVisionModelWithProjection
  from ...image_processor import VaeImageProcessor
  from ...loaders import LoraLoaderMixin, TextualInversionLoaderMixin
  from ...models import AutoencoderKL, UNet2DConditionModel
  from ...models.embeddings import get_timestep_embedding
  from ...models.lora import adjust_lora_scale_text_encoder
  from ...schedulers import KarrasDiffusionSchedulers
  from ...utils import USE_PEFT_BACKEND, deprecate, logging, replace_example_docstring, scale_lora_layers, unscale_lora_layers
  from ...utils.torch_utils import randn_tensor
  from ..pipeline_utils import DiffusionPipeline, ImagePipelineOutput
  from .stable_unclip_image_normalizer import StableUnCLIPImageNormalizer
label_desc: Use image node_id 5 for calling the StableUnCLIPImg2ImgPipeline obj's underlying member method code with example usage: obj._encode_image(image, device, batch_size, num_images_per_prompt, do_classifier_free_guidance, noise_level, generator, image_embeds) and returns: image_embeds