How to turn off the NSFW filter in Stable Diffusion

When the Stable Diffusion AI image generator creates pictures, it sometimes flags ordinary outputs as Not Safe For Work (NSFW). If you use the software at home on your personal computer you may disable the NSFW filter.

When you clone the Stable Diffusion GitHub repository, the txt2img.py file should appear in the scripts directory. If it is not there, clone the repository again from https://github.com/CompVis/stable-diffusion.git

  • Open the scripts/txt2img.py file in a text editor
  • Add a new first line to the check_safety function to immediately return the original image and an empty string without checking. Leave the rest of the function as is, as it will not be executed.
def check_safety(x_image):    return x_image, ' '
    safety_checker_input = ...

Join the Conversation

4 Comments

    1. Hi Gotra,
      My “scripts” directory has the txt2img.py file. Please see the screen shot in the updated post. I hope this helps.

  1. txt2img.py is not in the file list on my installation.
    C:\Users\username\stable-diffusion-webui\scripts
    Any other place to make this change?

Leave a comment

Your email address will not be published. Required fields are marked *