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.
- Host: GitHub
- URL: https://github.com/woctezuma/stable-diffusion-safety-checker
- Owner: woctezuma
- License: mit
- Created: 2023-12-04T10:05:43.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2024-12-02T21:26:53.000Z (5 months ago)
- Last Synced: 2024-12-02T22:27:38.629Z (5 months ago)
- Topics: 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
- Language: Python
- Homepage: https://github.com/Stability-AI/generative-models
- Size: 34.2 KB
- Stars: 6
- Watchers: 3
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
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 jsonfrom 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]: