How to generate NSFW images with Stable Diffusion


Stable Diffusion NSFW: How To Make NSFW Images In Stable Diffusion
Credit: Stability.ai

Wondering how to generate NSFW images in Stable Diffusion? We will show you, so you don't need to worry about filters or censorship.

As good as DALL-E (especially the new DALL-E 3) and MidJourney are, Stable Diffusion probably ranks among the best AI image generators. Unlike the other two, it is completely free to use. You can play with it as much as you like, generating all your wild ideas, including NSFW ones. There is a catch, however.

If you are accessing Stable Diffusion via Hugging Face or the DreamStudio web app, you will not be able to generate NSFW Images as these tools have NSFW filters. So, how do you make NSFW images using Stable Diffusion?

Well, that's exactly what we are going to tell you in this post. Let’s get into it and take a look.

How to generate NSFW images with Stable Diffusion (2023)

If you have a GPU with at least 6GB of VRAM, you can make NSFW images in Stable Diffusion locally on your PC. The steps may seem a bit complicated, but it's actually easy to follow and you can get it done with a little effort.

Here is what you need to do.

  • Download and install the latest Anaconda Distribution here. Also, download and install the latest Git here.
  • Go to this link and select the Files and versions tab. Download the sd-v1-4.ckpt file. You may need to create a Huggingface account to download it. The file is more than 4GB, so while you wait, go get a coffee.
  • Download the unfiltered script from this GitHub repository. To download, click on Code (green button) and select Download ZIP.
  • Open the unzipped file and navigate to stable-diffusion-unfiltered-main/models/ldm. Create a folder called "stable-diffusion-v1" there. Rename sd-v1-4.ckpt file we downloaded to "model.ckpt", and copy it into the folder (stable-diffusion-v1) you've made.
  • Open up the Anaconda cmd prompt and navigate to the "stable-diffusion-unfiltered-main" folder.
  • Run the following commands:
    • conda env create -f environment.yaml
    • conda activate ldm
    • python scripts/txt2img.py --prompt "Elon Musk as an alien" --H 512 --W 512 --seed 27 --n_iter 2 --ddim_steps 50
  • For custom images, replace the Elon Musk statement with the image you wish to create.

To create a new image you have to repeat steps 6 through 7. You can adjust the height and width of the image by changing the numbers next to H and W. However, to get higher-resolution images, you will need 10 or 12 GB of VRAM.

Generate Stable Diffusion NSFW images using Google Colab

If you don't have a powerful GPU, don't worry. You can make NSFW images In Stable Diffusion using Google Colab Pro or Plus.

By default, Colab notebooks rely on the original Stable Diffusion which comes with NSFW filters. By simply replacing all instances linking to the original script with the script that has no safety filters, you can easily achieve generate NSFW images.

Here is how to generate NSFW images using Google Colab:

  • Go to this Google Colab Notebook.
  • Click on the magnifying glass icon on the left pane.
  • Copy-paste !git clone https://github.com/CompVis/stable-diffusion.git into the Find textbox.
  • Copy-paste !git clone https://github.com/chemistzombie/stable-diffusion-unfiltered.git into the Replace with textbox.
  • Click on Replace all and then select Ok to confirm.

That's all you need to do. Now you can run each block of code to generate images. If you need detailed instructions about that, read how to access Stable Diffusion using Google Colab.

The new script disables the NSFW filter as well as unnecessary watermarking. As a result, GPU memory is conserved by not loading the safety models, and valuable time is saved by not having to scan for NSFW content.

Go ahead, make art. And in case you are hit by the Stable Diffusion runtime error or the "model failed to load, exiting error" while generating NSFW images, check out our fixes.

For more articles like this, take a look at our Tech and How To page.