class_docstr: ### Image in-painting class
class_docstr_tok: ["#","#","#","Image","in-painting","class"]
docstr: :param dest_path: is the path to store the generated images
  :param orig_img: is the image to transform
  :param strength: specifies how much of the original image should not be preserved
  :param batch_size: is the number of images to generate in a batch
  :param prompt: is the prompt to generate images with
  :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","orig_img",":","is","the","image","to","transform",":","param","strength",":","specifies","how","much","of","the","original","image","should","not","be","preserved",":","param","batch_size",":","is","the","number","of","images","to","generate","in","a","batch",":","param","prompt",":","is","the","prompt","to","generate","images","with",":","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,
      orig_img: str,
      strength: float,
      batch_size: int = 3,
      prompt: str,
      uncond_scale: float = 5.0,
      mask: Optional[torch.Tensor] = None,
  ):
      """
      :param dest_path: is the path to store the generated images
      :param orig_img: is the image to transform
      :param strength: specifies how much of the original image should not be preserved
      :param batch_size: is the number of images to generate in a batch
      :param prompt: is the prompt to generate images with
      :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)$
      """
      # Make a batch of prompts
      prompts = batch_size * [prompt]
      # Load image
      orig_image = load_img(orig_img).to(self.device)
      # Encode the image in the latent space and make `batch_size` copies of it
      orig = self.model.autoencoder_encode(orig_image).repeat(
          batch_size, 1, 1, 1
      )
      # If `mask` is not provided,
      # we set a sample mask to preserve the bottom half of the image
      if mask is None:
          mask = torch.zeros_like(orig, device=self.device)
          mask[:, :, mask.shape[2] // 2 :, :] = 1.0
      else:
          mask = mask.to(self.device)
      # Noise diffuse the original image
      orig_noise = torch.randn(orig.shape, device=self.device)
  
      # Get the number of steps to diffuse the original
      assert (
          0.0 <= strength <= 1.0
      ), "can only work with strength in [0.0, 1.0]"
      t_index = int(strength * self.ddim_steps)
  
      # 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)
          # Add noise to the original image
          x = self.sampler.q_sample(orig, t_index, noise=orig_noise)
          # Reconstruct from the noisy image, while preserving the masked area
          x = self.sampler.paint(
              x,
              cond,
              t_index,
              orig=orig,
              mask=mask,
              orig_noise=orig_noise,
              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, "paint_")
  
file_path: annotated_deep_learning_paper_implementations/labml_nn/diffusion/stable_diffusion/scripts/in_paint.py
imports: import argparse
  from pathlib import Path
  from typing import Optional
  import torch
  from labml import lab, monit
  from labml_nn.diffusion.stable_diffusion.latent_diffusion import LatentDiffusion
  from labml_nn.diffusion.stable_diffusion.sampler import DiffusionSampler
  from labml_nn.diffusion.stable_diffusion.sampler.ddim import DDIMSampler
  from labml_nn.diffusion.stable_diffusion.util import load_model, save_images, load_img, set_seed
label_desc: Use image node_id 2 for calling the InPaint obj's underlying member method code with example usage: obj.__call__() without return types