class_docstr: ### Text to image class
class_docstr_tok: ["#","#","#","Text","to","image","class"]
docstr: :param dest_path: is the path to store the generated images
  :param batch_size: is the number of images to generate in a batch
  :param prompt: is the prompt to generate images with
  :param h: is the height of the image
  :param w: is the width of the image
  :param uncond_scale: is the unconditional guidance scale $s$. This is used for
      $\epsilon_  heta(x_t, c) = s\epsilon_       ext{cond}(x_t, c) + (s - 1)\epsilon_    ext{cond}(x_t, c_u)$
docstr_tok: [":","param","dest_path",":","is","the","path","to","store","the","generated","images",":","param","batch_size",":","is","the","number","of","images","to","generate","in","a","batch",":","param","prompt",":","is","the","prompt","to","generate","images","with",":","param","h",":","is","the","height","of","the","image",":","param","w",":","is","the","width","of","the","image",":","param","uncond_scale",":","is","the","unconditional","guidance","scale","$","s","$",".","This","is","used","for","$","\\epsilon_","heta","(","x_t",",","c",")","=","s\\epsilon_","ext","{","cond","}","(","x_t",",","c",")","+","(","s","-","1",")","\\epsilon_","ext","{","cond","}","(","x_t",",","c_u",")","$"]
code: def __call__(
      self,
      *,
      dest_path: str,
      batch_size: int = 3,
      prompt: str,
      h: int = 512,
      w: int = 512,
      uncond_scale: float = 7.5,
  ):
      """
      :param dest_path: is the path to store the generated images
      :param batch_size: is the number of images to generate in a batch
      :param prompt: is the prompt to generate images with
      :param h: is the height of the image
      :param w: is the width of the image
      :param uncond_scale: is the unconditional guidance scale $s$. This is used for
          $\epsilon_\theta(x_t, c) = s\epsilon_\text{cond}(x_t, c) + (s - 1)\epsilon_\text{cond}(x_t, c_u)$
      """
      # Number of channels in the image
      c = 4
      # Image to latent space resolution reduction
      f = 8
  
      # Make a batch of prompts
      prompts = batch_size * [prompt]
  
      # AMP auto casting
      with torch.cuda.amp.autocast():
          # In unconditional scaling is not $1$ get the embeddings for empty prompts (no conditioning).
          if uncond_scale != 1.0:
              un_cond = self.model.get_text_conditioning(
                  batch_size * [""]
              )
          else:
              un_cond = None
          # Get the prompt embeddings
          cond = self.model.get_text_conditioning(prompts)
          # [Sample in the latent space](../sampler/index.html).
          # `x` will be of shape `[batch_size, c, h / f, w / f]`
          x = self.sampler.sample(
              cond=cond,
              shape=[batch_size, c, h // f, w // f],
              uncond_scale=uncond_scale,
              uncond_cond=un_cond,
          )
          # Decode the image from the [autoencoder](../model/autoencoder.html)
          images = self.model.autoencoder_decode(x)
  
      # Save images
      save_images(images, dest_path, "txt_")
  
file_path: annotated_deep_learning_paper_implementations/labml_nn/diffusion/stable_diffusion/scripts/text_to_image.py
imports: import argparse
  import os
  from pathlib import Path
  import torch
  from labml import lab, monit
  from labml_nn.diffusion.stable_diffusion.latent_diffusion import LatentDiffusion
  from labml_nn.diffusion.stable_diffusion.sampler.ddim import DDIMSampler
  from labml_nn.diffusion.stable_diffusion.sampler.ddpm import DDPMSampler
  from labml_nn.diffusion.stable_diffusion.util import load_model, save_images, set_seed
label_desc: Use image node_id 2 for calling the Txt2Img obj's underlying member method code with example usage: obj.__call__() without return types