class_docstr: Pipeline for generating latent representation of a 3D asset and rendering with the NeRF method from an image.
  
  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:
      prior ([`PriorTransformer`]):
          The canonincal unCLIP prior to approximate the image embedding from the text embedding.
      image_encoder ([`~transformers.CLIPVisionModel`]):
          Frozen image-encoder.
      image_processor ([`~transformers.CLIPImageProcessor`]):
           A `CLIPImageProcessor` to process images.
      scheduler ([`HeunDiscreteScheduler`]):
          A scheduler to be used in combination with the `prior` model to generate image embedding.
      shap_e_renderer ([`ShapERenderer`]):
          Shap-E renderer projects the generated latents into parameters of a MLP to create 3D objects with the NeRF
          rendering method.
class_docstr_tok: ["Pipeline","for","generating","latent","representation","of","a","3D","asset","and","rendering","with","the","NeRF","method","from","an","image",".","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",":","prior","(","[","`","PriorTransformer","`","]",")",":","The","canonincal","unCLIP","prior","to","approximate","the","image","embedding","from","the","text","embedding",".","image_encoder","(","[","`","~transformers.CLIPVisionModel","`","]",")",":","Frozen","image-encoder",".","image_processor","(","[","`","~transformers.CLIPImageProcessor","`","]",")",":","A","`","CLIPImageProcessor","`","to","process","images",".","scheduler","(","[","`","HeunDiscreteScheduler","`","]",")",":","A","scheduler","to","be","used","in","combination","with","the","`","prior","`","model","to","generate","image","embedding",".","shap_e_renderer","(","[","`","ShapERenderer","`","]",")",":","Shap-E","renderer","projects","the","generated","latents","into","parameters","of","a","MLP","to","create","3D","objects","with","the","NeRF","rendering","method","."]
code: def _encode_image(
      self,
      image,
      device,
      num_images_per_prompt,
      do_classifier_free_guidance,
  ):
      if isinstance(image, List) and isinstance(image[0], torch.Tensor):
          image = (
              torch.cat(image, axis=0)
              if image[0].ndim == 4
              else torch.stack(image, axis=0)
          )
  
      if not isinstance(image, torch.Tensor):
          image = (
              self.image_processor(image, return_tensors="pt")
              .pixel_values[0]
              .unsqueeze(0)
          )
  
      image = image.to(dtype=self.image_encoder.dtype, device=device)
  
      image_embeds = self.image_encoder(image)["last_hidden_state"]
      image_embeds = image_embeds[
          :, 1:, :
      ].contiguous()  # batch_size, dim, 256
  
      image_embeds = image_embeds.repeat_interleave(
          num_images_per_prompt, dim=0
      )
  
      if do_classifier_free_guidance:
          negative_image_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_image_embeds, image_embeds]
          )
  
      return image_embeds
  
file_path: llmga/llmga/diffusers/src/diffusers/pipelines/shap_e/pipeline_shap_e_img2img.py
imports: from dataclasses import dataclass
  from typing import List, Optional, Union
  import numpy
  import PIL.Image
  import torch
  from transformers import CLIPImageProcessor, CLIPVisionModel
  from ...models import PriorTransformer
  from ...schedulers import HeunDiscreteScheduler
  from ...utils import BaseOutput, logging, replace_example_docstring
  from ...utils.torch_utils import randn_tensor
  from ..pipeline_utils import DiffusionPipeline
  from .renderer import ShapERenderer
label_desc: Use image node_id 3 for calling the ShapEImg2ImgPipeline obj's underlying member method code with example usage: obj._encode_image(image, device, num_images_per_prompt, do_classifier_free_guidance) and returns: image_embeds