stable-diffusion stable-diffusion-diffusers text-to-image

Safe Stable Diffusion Model Card

Safe Stable Diffusion is a latent text-to-image diffusion model capable of generating photo-realistic images given any text input. Safe Stable Diffusion is driven by the goal of suppressing inappropriate images other large Diffusion models generate, often unexpectedly.

Safe Stable Diffusion shares weights with the Stable Diffusion v1.5. For more information please have a look at Stable Diffusion v1.5 and 🤗's Stable Diffusion blog.

Currently, you can use this with the ml-research GitHub repository and soon it will be available with the 🧨Diffusers library. Check this Pull Request for updates.

Original GitHub Repository

  1. Download this model with either one of these checkpoints:

  2. Install the Safe Latent Diffusion Libray.

    $ pip install git+https://github.com/ml-research/safe-latent-diffusion.git 
    
  3. And load the SLD pipline as follows.

    from sld import SLDPipeline
    device='cuda'
    #####################
    # Path to your local clone of the weights
    ckpt_path = ''
    ####################
    pipe = SLDPipeline.from_pretrained(
        ckpt_path,
    ).to(device)    
    

Definition of <i>inappropriate</i> content

What is considered inappropriate imagery may differ based on context, setting, cultural and social predisposition as well as individual factors and is overall highly subjective. In this work we base our definition of inappropriate content on the work of Gebru <i> et al.</i>:

[data that] if viewed directly, might be offensive, insulting, threatening, or might otherwise cause anxiety.

--<cite>Gebru, Timnit, et al. "Datasheets for datasets," (2021)</cite>

Specifically, we consider images from the following categories: hate, harassment, violence, self-harm, sexual content, shocking images, illegal activity. Note that inappropriateness is not limited to these concepts, varies between cultures, and constantly evolves.

Model Details

Uses

We distinguish between the following.

Direct Use

The model is intended for research purposes only. Possible research areas and tasks include

Excluded uses are described below.

Misuse, Malicious Use, and Out-of-Scope Use

_Note: This section is taken from the DALLE-MINI model card, but applies in the same way to Safe Stable Diffusion.

The model should not be used to intentionally create or disseminate images that create hostile or alienating environments for people. This includes generating images that people would foreseeably find disturbing, distressing, or offensive; or content that propagates historical or current stereotypes.

Out-of-Scope Use

The model was not trained to be factual or true representations of people or events, and therefore using the model to generate such content is out-of-scope for the abilities of this model. Furthermore, the default safety concept only reduces the amount of content related to the aforementioned categories: hate, harassment, violence, self-harm, sexual content, shocking images, illegal activity. Mitigating otherwise inappropriate material is out of scope for this model and requires changes to the safety concept. Furthermore, the approach relies on the representations of those concepts learned by the model to identify and correct corresponding content. Cases were the model itself fails to correlate an image with our textual definition of inappropriateness are out of scope.

Misuse and Malicious Use

Using the model to generate content that is cruel to individuals is a misuse of this model. This includes, but is not limited to:

Limitations and Bias

Limitations

Bias

While the capabilities of image generation models are impressive, they can also reinforce or exacerbate social biases. Stable Diffusion v1 was trained on subsets of LAION-2B(en), which consists of images that are primarily limited to English descriptions. Texts and images from communities and cultures that use other languages are likely to be insufficiently accounted for. This affects the overall output of the model, as white and western cultures are often set as the default. Further, the ability of the model to generate content with non-English prompts is significantly worse than with English-language prompts. Additionally, the models' notion of inappropriateness and definitions of the included concepts are equally biased towards their perception in western, english

Safety Module

The intended use of this model is with the Safety Checker in Diffusers. This checker works by checking model outputs against known hard-coded NSFW concepts. The concepts are intentionally hidden to reduce the likelihood of reverse-engineering this filter. Specifically, the checker compares the class probability of harmful concepts in the embedding space of the CLIPTextModel after generation of the images. The concepts are passed into the model with the generated image and compared to a hand-engineered weight for each NSFW concept.

Training

Training Data The model developers used the following dataset for training the model:

Training Procedure For the training procedure of the underlying Stable Diffusion v1.5 check its model card.

Safe Stable diffusion does not perform any additional training and only performs extensive evaluation of the Stable Diffusion v1.4 model.

Evaluation Results

Evaluation of inappropriateness mitigation using the I2P Benchmark and the Stable Diffusion v1.4 checkpoint.

Category Stable Diffusion SLD-Weak SLD-Medium SLD-Strong SLD-Max
Hate 0.40 0.27 0.20 0.15 0.09
Harassment 0.34 0.24 0.17 0.13 0.09
Violence 0.43 0.36 0.23 0.17 0.14
Self-harm 0.40 0.27 0.16 0.10 0.07
Sexual 0.35 0.23 0.14 0.09 0.06
Shocking 0.52 0.41 0.30 0.20 0.13
Illegal activity 0.34 0.23 0.14 0.09 0.06
Overall 0.39 0.29 0.19 0.13 0.09

Table shows probabilities of generating inappropriate content on I2P prompts. SLD-Configurations refer to the following hyper-parameters:

Config sld_warmup_steps sld_guidance_scale sld_threshold sld_momentum_scale sld_mom_beta
Hyp-Weak 15 200 0.0 0.0 -
Hyp-Medium 10 1000 0.01 0.3 0.4
Hyp-Strong 7 2000 0.025 0.5 0.7
Hyp-Max 0 5000 1.0 0.5 0.7

Evaluated using 10 images for each I2G prompt.

Environmental Impact

Safe Stable Diffusion Estimated Emissions For evaluation and development of our approach we estimate the following CO2 emissions using the Machine Learning Impact calculator presented in Lacoste et al. (2019). The hardware, runtime, and compute region were utilized to estimate the carbon impact.

Citation

@article{schramowski2022safe,
      title={Safe Latent Diffusion: Mitigating Inappropriate Degeneration in Diffusion Models}, 
      author={Patrick Schramowski and Manuel Brack and Björn Deiseroth and Kristian Kersting},
      year={2022},
      journal={arXiv preprint arXiv:2211.05105}
}

This model card was written by: Manuel Brack and is based on the Stable Diffusion v1.5 model card.