def run_safety_checker(self, image, device, dtype):
        """Runs the safety checker on the generated image."""
        if self.safety_checker is None:
            has_nsfw_concept = None
            return image, has_nsfw_concept

        if isinstance(self.safety_checker, StableDiffusionSafetyChecker):
            safety_checker_input = self.feature_extractor(self.numpy_to_pil(image), return_tensors="pt").to(device)
            image, has_nsfw_concept = self.safety_checker(
                images=image,
                clip_input=safety_checker_input.pixel_values.to(dtype),
            )
        else:
            images_np = self.numpy_to_pil(image)
            safety_checker_input = self.safety_checker.feature_extractor(images_np, return_tensors="pt").to(device)
            has_nsfw_concept = self.safety_checker(
                images=image,
                clip_input=safety_checker_input.pixel_values.to(dtype),
            )[1]

        return image, has_nsfw_concept
Runs the safety checker on the generated image.
examples/community/regional_prompting_stable_diffusion.py