Does Stable Diffusion Allow NSFW Art?

There seems to be a bit of confusion lately about the topic of nudity when using Stable Diffusion for AI art generation. Stability AI, the company behind it’s creation and release, are cracking down on lewdness. So are you able to make Not Safe for Work (NSFW) content using Stable Diffusion? I want to clarify what Stability AI’s stance is and what you can or can’t create using their models.

Does Stable Diffusion Allow for NSFW Image Generation?

If you were hoping to make adult-oriented or risque art content with Stable Diffusion, don’t fret. Yes, you can use Stable Diffusion for NSFW content…but you’ll have to use a local install.

Any confusion you had on the topic may have been caused by Stability AI’s V2.0 model release. Let’s go over that situation and then I’ll tell you how to get started on your naughty art endeavors if you haven’t tried Stable Diffusion yet.

Stability AI’s Stance on NSFW

Stability AI is the company behind Stable Diffusion. Not only did they train the source models, they also operate an online service for AI art generation called Dream Studio. With their web-based service, you can pay per generation to create images using Stable Diffusion without needing your own computer hardware; their service runs on their own servers.

However, because their service runs on their own servers, Stability AI has the right to impose whatever content guidelines they wish. And their official stance has always been that NSFW content is not allowed on their web service. This is nothing new.

What is new happens to be restrictions on the latest v2.0 model that Stability AI has released…

Censorship in Stable Diffusion v2.0

There are several significant changes to Stable Diffusion with the v2.0 model. Most of them are not very appealing to the current open-source AI art community. One of those changes was that NSFW training datasets were completely removed. This means v2.0 is simply not capable of generating nude or lewd content.

I’m not here to argue whether people should or should not be generating nude or sexual images with AI. What you make for your own use is your own business in my opinion…just don’t bother me with it and we’re good. So with that being said, let me show you how to access Stable Diffusion with NSFW features still intact.

How to Bypass Censorship in Stable Diffusion

There are a few ways to bypass the filters in Stable Diffusion (at least, in the earlier versions that still had the additional training data). The 3 methods will review are:

  1. Use a local install on your own computer
  2. Remove the NSFW filter line of code in the BAT file
  3. Use a custom NSFW model

1. Local Installation

In order to use Stable Diffusion for generating nude content, you will need to install it on your own computer. This really isn’t very hard, and I have a guide here on how to do it. There are also a number of graphical interfaces available so you don’t have to operate it from a command prompt terminal. But there are some key components you’ll need to get it running on your computer and for it to generate NSFW content. You will need:

  • A GPU (also known as a graphics card) with at least 6 GB of VRAM. The more VRAM you have, the better it will run.
  • Your GPU needs to be a Nvidia brand. Nvidia is the only GPU processor that runs on CUDA architecture (that just refers to how they are physically constructed), and you need CUDA to run the AI models.
  • Either Version 1.4 or 1.5 of Stable Diffusion. While the naughty content was removed for v2.0, these models are not like software that gets updated and then you’re stuck with the new version. On the contrary, each version is it’s own “program” in it’s own right and you can have multiple “installed” on the same computer.

2. Remove the NSFW Filter in V1.4 or V1.5

Most of the available GUIs (graphical user interfaces) for Stable Diffusion automatically disable the NSFW filter, giving you free range to generate nude content as soon as you start up the model.

However, if you are downloading Stable Diffusion for command-line use or with a GUI (graphical user interface) that does not have the filter disabled by default, then you will need to make an edit to the BAT file.

Here is a tutorial on how to edit this. I did not write this following portion and I do not take credit for it:

Note: This is assuming you are using the Stable-Diffusion repo from here: https://github.com/CompVis/stable-diffusion. If using a fork (or a later version of it), the line number might be different so just search for the one I mention below. They may also have been already removed in a fork. Also, where I say delete the lines, it might be better to just comment them out by putting a # in front of the line, to avoid changing the line numbers of the rest of the code (therefore making it easier to find the others mentioned).

Disabling the Safety Checks:

  • Open the “scripts” folder and make a backup copy of txt2img.py
  • Open txt2img.py, and find the line (might be line 309) that says:

x_checked_image, has_nsfw_concept = check_safety(x_samples_ddim)

  • Replace it with this (make sure to keep the indenting the same as before):

x_checked_image = x_samples_ddim

Optional: Stopping the safety models from even loading to save Vram (thanks NotMyMain007)

  • In txt2img.py, find and delete the three separate lines (might be 26, 27, 28) that say:

safety_model_id = “CompVis/stable-diffusion-safety-checker”

safety_feature_extractor = AutoFeatureExtractor.from_pretrained(safety_model_id)

safety_checker = StableDiffusionSafetyChecker.from_pretrained(safety_model_id)

(Source)

3. Use a Custom Model

Now, just because the base model of Stable Diffusion can technically generate nude content does not mean it’s going to be high quality content. But let’s be real…the internet and most of modern technology (including the home camera and VHS) only saw innovation and mainstream appeal because they were used for…ahem…NSFW activities.

So it’s no surprise to learn that multiple models have been specifically trained by AI art enthusiasts to provide better anatomical output images when emulating the human form. What I’m trying to say nicely is that there are already a lot of NSFW models for Stable Diffusion on the internet. And because you can have many different models on your computer at the same time, you are welcome to try as many as you like.

I highly recommend that, whatever models you test, that you download them in the SafeTensors format for safety reasons. You can learn more about SafeTensors, Pickle files, and download safety in this article.

Here are a few NSFW models (that are available in SafeTensors) that you can try, though:

  • Hassanblend (this is a merging and custom training of several models, with the intent of creating photorealistic portraits with nude capabilities)
  • SamDoesSexy (for NSFW digital painting styles)
  • Attractive Women (this model is a blend of SD v1.5 and F222 in the creator’s attempt to make portraits that look more passable thanks to F222 but with the stylistic capacity of v1.5 retained. This models female portraiture does look well composed, but not necessarily photorealistic)
  • Elldreth’s Retro Mix (this model is aimed at producing realistic digital painting portraits)
  • PFG (from the demo images I’ve seen, it can do digital painting and anime-esque styles of nude portraits)
  • Deliberate (a model for anatomical and realistic human figures that works with photorealistic, game rendering, and digital art styles)

Conclusion

The benefit of open-sourced AI software is that it’s harder for large companies and social gatekeepers to control. The concern about censorship goes beyond the ability to generate adult content. Censoring one aspect of AI art could easily lead to harsher and more stringent limits on it’s use in the future.

Thanks for reading! If you found this article helpful, here are a few others you may like: