An open API service indexing awesome lists of open source software.

https://github.com/woctezuma/stable-diffusion-safety-checker

Python package to apply the Safety Checker from Stable Diffusion.
https://github.com/woctezuma/stable-diffusion-safety-checker

colab colab-notebook colaboratory deep-learning diffusers diffusion google-colab google-colab-notebook google-colaboratory nsfw nsfw-classifier nsfw-detection nsfw-detector nsfw-recognition safety safety-check safety-checker safety-checks stable-diffusion transformers

Last synced: 5 months ago
JSON representation

Python package to apply the Safety Checker from Stable Diffusion.

Awesome Lists containing this project

README

        

# Stable Diffusion Safety Checker

The goal of this repository is to run the [safety checker][huggingface-safety-checker] from [Stable Diffusion][huggingface-stable-diffusion].

## Requirements

- Install the latest version of [Python 3][python-download-url].
- Install the required packages:

```bash
!pip install git+https://github.com/woctezuma/stable-diffusion-safety-checker.git
```

## Usage

- Run the main script with:

```bash
!python -m safety_checker.check_safety -h
```

- Alternatively, run [`safety_checker.ipynb`][colab-notebook-safety-checker].
[![Open In Colab][colab-badge]][colab-notebook-safety-checker]

## Example

Download the `balloon` image dataset.
```bash
fname = "balloon_dataset.zip"
!curl -OL https://github.com/matterport/Mask_RCNN/releases/download/v2.1/{fname}
!unzip -q {fname}
```

Run the script:
```bash
!python -m safety_checker.check_safety \
--input balloon \
--batch 8 \
--resize 256 \
--keep-ratio \
--output bad_concepts.json \
--scores bad_concepts_scores.pth \
--list img_list.json \
--verbose
```

Check the results:

```python
import json

from pathlib import Path

with Path("bad_concepts.json").open(encoding='utf8') as f:
results = json.load(f)
```

The IDs of the "bad concepts" are clarified on [this page][bad-concepts] hosted by LAION-AI.

## References

- [`feature-extractor`][feature-extractor]: similar code to extract image features,
- [`discord-members-metadata`][data-discord]: profiles pictures scraped from a specific Discord guild's members.

[huggingface-safety-checker]:
[huggingface-stable-diffusion]:

[python-download-url]:
[bad-concepts]:

[feature-extractor]:
[data-discord]:

[colab-notebook-safety-checker]:
[colab-badge]: