class_docstr: Pipeline for text-guided image inpainting using Stable Diffusion. *This is an experimental feature*.
  
  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.)
  
  In addition the pipeline inherits the following loading methods:
      - *Textual-Inversion*: [`loaders.TextualInversionLoaderMixin.load_textual_inversion`]
      - *LoRA*: [`loaders.LoraLoaderMixin.load_lora_weights`]
      - *Ckpt*: [`loaders.FromSingleFileMixin.from_single_file`]
  
  as well as the following saving methods:
      - *LoRA*: [`loaders.LoraLoaderMixin.save_lora_weights`]
  
  Args:
      vae ([`AutoencoderKL`]):
          Variational Auto-Encoder (VAE) Model to encode and decode images to and from latent representations.
      text_encoder ([`CLIPTextModel`]):
          Frozen text-encoder. Stable Diffusion uses the text portion of
          [CLIP](https://huggingface.co/docs/transformers/model_doc/clip#transformers.CLIPTextModel), 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`].
      safety_checker ([`StableDiffusionSafetyChecker`]):
          Classification module that estimates whether generated images could be considered offensive or harmful.
          Please, refer to the [model card](https://huggingface.co/runwayml/stable-diffusion-v1-5) for details.
      feature_extractor ([`CLIPImageProcessor`]):
          Model that extracts features from generated images to be used as inputs for the `safety_checker`.
class_docstr_tok: ["Pipeline","for","text-guided","image","inpainting","using","Stable","Diffusion",".","*","This","is","an","experimental","feature","*",".","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",".",")","In","addition","the","pipeline","inherits","the","following","loading","methods",":","-","*","Textual-Inversion","*",":","[","`","loaders.TextualInversionLoaderMixin.load_textual_inversion","`","]","-","*","LoRA","*",":","[","`","loaders.LoraLoaderMixin.load_lora_weights","`","]","-","*","Ckpt","*",":","[","`","loaders.FromSingleFileMixin.from_single_file","`","]","as","well","as","the","following","saving","methods",":","-","*","LoRA","*",":","[","`","loaders.LoraLoaderMixin.save_lora_weights","`","]","Args",":","vae","(","[","`","AutoencoderKL","`","]",")",":","Variational","Auto-Encoder","(","VAE",")","Model","to","encode","and","decode","images","to","and","from","latent","representations",".","text_encoder","(","[","`","CLIPTextModel","`","]",")",":","Frozen","text-encoder",".","Stable","Diffusion","uses","the","text","portion","of","[","CLIP","]","(","https",":","\/\/huggingface.co\/docs\/transformers\/model_doc\/clip","#","transformers.CLIPTextModel",")",",","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","`","]",".","safety_checker","(","[","`","StableDiffusionSafetyChecker","`","]",")",":","Classification","module","that","estimates","whether","generated","images","could","be","considered","offensive","or","harmful",".","Please",",","refer","to","the","[","model","card","]","(","https",":","\/\/huggingface.co\/runwayml\/stable-diffusion-v1-5",")","for","details",".","feature_extractor","(","[","`","CLIPImageProcessor","`","]",")",":","Model","that","extracts","features","from","generated","images","to","be","used","as","inputs","for","the","`","safety_checker","`","."]
code: def run_safety_checker(self, image, device, dtype):
      if self.safety_checker is None:
          has_nsfw_concept = None
      else:
          if torch.is_tensor(image):
              feature_extractor_input = (
                  self.image_processor.postprocess(
                      image, output_type="pil"
                  )
              )
          else:
              feature_extractor_input = (
                  self.image_processor.numpy_to_pil(image)
              )
          safety_checker_input = self.feature_extractor(
              feature_extractor_input, return_tensors="pt"
          ).to(device)
          image, has_nsfw_concept = self.safety_checker(
              images=image,
              clip_input=safety_checker_input.pixel_values.to(dtype),
          )
      return image, has_nsfw_concept
  
imports: import inspect
  from typing import Any, Callable, Dict, List, Optional, Union
  import numpy
  import PIL.Image
  import torch
  from packaging import version
  from transformers import CLIPImageProcessor, CLIPTextModel, CLIPTokenizer
  from ....configuration_utils import FrozenDict
  from ....image_processor import VaeImageProcessor
  from ....loaders import FromSingleFileMixin, LoraLoaderMixin, TextualInversionLoaderMixin
  from ....models import AutoencoderKL, UNet2DConditionModel
  from ....models.lora import adjust_lora_scale_text_encoder
  from ....schedulers import KarrasDiffusionSchedulers
  from ....utils import PIL_INTERPOLATION, USE_PEFT_BACKEND, deprecate, logging, scale_lora_layers, unscale_lora_layers
  from ....utils.torch_utils import randn_tensor
  from ...pipeline_utils import DiffusionPipeline
  from ...stable_diffusion import StableDiffusionPipelineOutput
  from ...stable_diffusion.safety_checker import StableDiffusionSafetyChecker
label_desc: Use image node_id 4 for calling the StableDiffusionInpaintPipelineLegacy obj's underlying member method code with example usage: obj.run_safety_checker(image, device, dtype) and returns: image,  has_nsfw_concept