text
stringlengths
0
5.54k
Tips
Safe Stable Diffusion may also be used with weights of Stable Diffusion.
Run Safe Stable Diffusion
Safe Stable Diffusion can be tested very easily with the StableDiffusionPipelineSafe, and the "AIML-TUDA/stable-diffusion-safe" checkpoint exactly in the same way it is shown in the Conditional Image Generation Guide.
Interacting with the Safety Concept
To check and edit the currently used safety concept, use the safety_concept property of StableDiffusionPipelineSafe:
Copied
>>> from diffusers import StableDiffusionPipelineSafe
>>> pipeline = StableDiffusionPipelineSafe.from_pretrained("AIML-TUDA/stable-diffusion-safe")
>>> pipeline.safety_concept
For each image generation the active concept is also contained in StableDiffusionSafePipelineOutput.
Using pre-defined safety configurations
You may use the 4 configurations defined in the Safe Latent Diffusion paper as follows:
Copied
>>> from diffusers import StableDiffusionPipelineSafe
>>> from diffusers.pipelines.stable_diffusion_safe import SafetyConfig
>>> pipeline = StableDiffusionPipelineSafe.from_pretrained("AIML-TUDA/stable-diffusion-safe")
>>> prompt = "the four horsewomen of the apocalypse, painting by tom of finland, gaston bussiere, craig mullins, j. c. leyendecker"
>>> out = pipeline(prompt=prompt, **SafetyConfig.MAX)
The following configurations are available: SafetyConfig.WEAK, SafetyConfig.MEDIUM, SafetyConfig.STRONG, and SafetyConfig.MAX.
How to load and use different schedulers
The safe stable diffusion pipeline uses PNDMScheduler scheduler by default. But diffusers provides many other schedulers that can be used with the stable diffusion pipeline such as DDIMScheduler, LMSDiscreteScheduler, EulerDiscreteScheduler, EulerAncestralDiscreteScheduler etc.
To use a different scheduler, you can either change it via the ConfigMixin.from_config() method or pass the scheduler argument to the from_pretrained method of the pipeline. For example, to use the EulerDiscreteScheduler, you can do the following:
Copied
>>> from diffusers import StableDiffusionPipelineSafe, EulerDiscreteScheduler
>>> pipeline = StableDiffusionPipelineSafe.from_pretrained("AIML-TUDA/stable-diffusion-safe")
>>> pipeline.scheduler = EulerDiscreteScheduler.from_config(pipeline.scheduler.config)
>>> # or
>>> euler_scheduler = EulerDiscreteScheduler.from_pretrained("AIML-TUDA/stable-diffusion-safe", subfolder="scheduler")
>>> pipeline = StableDiffusionPipelineSafe.from_pretrained(
... "AIML-TUDA/stable-diffusion-safe", scheduler=euler_scheduler
... )
StableDiffusionSafePipelineOutput
class diffusers.pipelines.stable_diffusion_safe.StableDiffusionSafePipelineOutput
<
source
>
(
images: typing.Union[typing.List[PIL.Image.Image], numpy.ndarray]
nsfw_content_detected: typing.Optional[typing.List[bool]]
unsafe_images: typing.Union[typing.List[PIL.Image.Image], numpy.ndarray, NoneType]
applied_safety_concept: typing.Optional[str]
)
Parameters
images (List[PIL.Image.Image] or np.ndarray) —
List of denoised PIL images of length batch_size or numpy array of shape (batch_size, height, width, num_channels). PIL images or numpy array present the denoised images of the diffusion pipeline.
nsfw_content_detected (List[bool]) —
List of flags denoting whether the corresponding generated image likely represents “not-safe-for-work”
(nsfw) content, or None if safety checking could not be performed.
images (List[PIL.Image.Image] or np.ndarray) —
List of denoised PIL images that were flagged by the safety checker any may contain “not-safe-for-work”
(nsfw) content, or None if no safety check was performed or no images were flagged.
applied_safety_concept (str) —
The safety concept that was applied for safety guidance, or None if safety guidance was disabled
Output class for Safe Stable Diffusion pipelines.
__call__
(
*args