/stable-diffusion-safety-checker

Python package to apply the Safety Checker from Stable Diffusion.

Primary LanguagePythonMIT LicenseMIT

Stable Diffusion Safety Checker

The goal of this repository is to run the safety checker from Stable Diffusion.

Requirements

  • Install the latest version of Python 3.
  • Install the required packages:
!pip install git+https://github.com/woctezuma/stable-diffusion-safety-checker.git

Usage

  • Run the main script with:
!python -m safety_checker.check_safety -h

Example

Download the balloon image dataset.

fname = "balloon_dataset.zip"
!curl -OL https://github.com/matterport/Mask_RCNN/releases/download/v2.1/{fname}
!unzip -q {fname}

Run the script:

!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:

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 hosted by LAION-AI.

References