Nudify with Stable Diffusion

This guide will only cover installation for Windows, but the process is very similar for Linux
(Sorry Mac plebs - try this install guide)

I recommend not attempting unless you meet these specs:

  • 16GB RAM
  • 4GB VRAM

Not meeting theses recommendations will result in incredibly slow image generation and potential 'out of memory' crashes

Installation Guide

Setting Up a Conda Environment

It is good practice to install inside a conda virtual environment to prevent python conflicts
But it is NOT NESSESARY so if you don't want to worry about Conda skip to the next step

To create a conda environment you must first install Miniconda. We will be using Miniconda rather than Anaconda because it is more lightweight and does not come with pre-installed packages, though feel free to use Anaconda if you want.

First you must download and install the 'Miniconda3 Windows 64-bit' package
https://docs.conda.io/projects/miniconda/en/latest/

Once you have run through the installer you need to open 'Anaconda Prompt (miniconda3)'
You can find this by searching for it in the Windows search bar

To create the conda environment you must run these commands:

  1. conda create --name Stable-Diffusion
  2. conda install python=3.10.6
  3. conda install -c anaconda git

Now you have a functioning conda environment to perform the next steps inside

Just remember that to work inside this environment you MUST open the anaconda prompt and use the command
conda activate Stable-Diffusion
Otherwise you will not be able to launch the program

Installing Stable Diffusion

Now you have a conda environment set up you're ready proceed with installing Stable Diffusion
The best web-ui for Stable Diffusion is made by AUTOMATIC1111 on GitHub, it is what we will be using to nudify

To download stable diffusion you need to run the command
git clone https://github.com/AUTOMATIC1111/stable-diffusion-webui.git
This will download into the directory 'C:\Users\%username%\stable-diffusion-webui'

Now to finally install it you run these commands if using Conda

  1. cd C:\Users\%username%\stable-diffusion-webui
  2. webui-user.bat

Otherwise just run the webui-user.bat file

This should install all dependencies and launch the web-ui

Nudifying

Basics

The basic process of nudifying involves using the inpaint option in the 'img2img' tab of the web-ui to paint a mask over the clothes that you want to remove from the image, then generating images untill you get a desired result

But in reality it is much more complex and can be fine tuned to produce incredibly realistic results

Inpainting Models

To create a good nudify you need a model that is designed specifically for inpaiting
The a large collection of models can be found at Civitai, a great place to find nsfw Stable Diffusion Models and LoRAs
When looking for models ensure that you filter out everything except 'checkpoint' models

I recommend these models, but feel I suggest playing around with others to find what you like best:

  • Uber Realistic Porn Merge
  • LazyMix+
  • Realistic Vision

When downloading a new model assure that you select the inpainting version and the file name ends in 'inpainting'
If the model is not an inpainting model you can convert it to one using this guide from Reddit

LoRAs

LoRAs are like small checkpoint models that can help pin point what you want the generated image to look like
An example of this is Uber Realistic Booty and Vag which helps create better looking lower bodies, which most models are not very good at

To use a LoRA you need to click the LoRA tab and choose a LoRA that you want to use, it will then add it to the prompt. Before generating an image you need to check it's Civitai page to check if it has a trigger word or set of trigger words, meaning you need to include at least one of those words in your prompt to trigger the LoRA

When the LoRA is in your prompt it will be formatted like this: <lora:loraname:weight>
The weight is an number that specifies how much the LoRA will impact the final product; greater value = greater impact

I encourage you to visit Civitai and filter by LoRAs and search for yourself to find LoRAs that you want to use

Prompts

Prompts are not as important as you may think when nudifying, for the most part you can rely on the model to nudify without any prompts at all

The syntax for prompts does not require commas between individual prompts, this only makes it easier for humans to read

The basic prompts and negatives that I use are:
positive: woman, nude
negative: hand, finger, sfw, jeans, denim, clothes, dress, skirt, clothing, underwear, bra, bikini, panties, dress, 3d, 3d render, blurry, canvas frame, cartoon, deformed, disfigured, gross, mutant, ugly, jewelry, piercing

A situation where you require a more specific prompt may be when nudifiying someone with smaller tits, as most models are quite bad at this
Being specific as to what you want and don't want usually achieves a good result, an example of this is:
positive: miniscule breasts
negative: large breasts, medium breasts, small breasts

When prompting you may need to change the weight of an individual prompt
To do this you highlight the text that you want to change the weight of then press: ctrl + up/down arrow
This weight works the same way as LoRA weight; heigher numberical value = greater impact

Settings

Settings are very important when nudifying and can be the difference between a good result and an alien

You will likely only need to set these settings when you launch Stable Diffusion and not while nudifying as other values will mess up your result

Setting Value Purpose
Resize mode Resize and fill So that the output is the same resolution as input
Mask mode Inpaint masked Inpaint is what to modify rather than what to keep
Inpaint area Only masked Only modify the inpainted pixels
Batch size 1 Number of images to generate per batch, increases memory usage

These settings can be changed depending on what you want

Setting Recommended Value Purpose
Mask blur 3 Changes how much the edge of the mask is blurred before generating the image
Masked content fill In depth reasoning here
Only masked padding, pixels 50-150 Specifies how many pixels to the side of the mask will be used as reference for generation, helps with skin colour, imperfections and shadows
Sampling method DPM++ 2M Karras Algorithm used to remove noise during generation, has relatively small impact on result
Sampling Steps 30 Number of iterations from random noise to an image, higher number better quality but takes longer
Width & Height 512 & 512 Resolution of image, anything other than 512 takes longer but is higher quality, only go higher if you have a powerful GPU or are willing to wait longer
Batch count 5 How many batches to generate, only change batch count not size as it can cause you to run out of memory
CFG scale 7 How closely to follow your prompts
Denoise strength 1 Lower values mean result is more similar to original input. more info
Seed -1 -1 is random generation seed, using the same seed for generation will result in the same image (batch count increments seed by +1 per image)

Inpainting

Inpainting is when you paint a mask over the clothes in an image
To inpaint you need to upload an image and select the brush size that you want

When inpainting it is generally a good idea to inpaint slightly more than you need to remove so that you don't have fragments of the clothes remaining that will require another batch to fix. You can also inpaint over shadows and imperfections that would not be there without clothes to attempt to remove them

Be careful when inpainting around important parts of the image that may not be able to be recreated such as faces

Additional Info

Improved Performance

The most limiting factor when using Stable Diffusion is the amount of VRAM that your GPU has

The best way to improve the performance of stable diffusion is to use xFormers
This can be done by:

  1. right click webui-user.bat at C:\Users\%username%\stable-diffusion-webui
  2. click 'edit'
  3. where it says 'COMMANDLINE_ARGS=' add: --xformers
  4. save and close

This will launch Stable Diffusion using xFormers. The only con of using xFormers is that it alters the generation process, meaning that if someone gives you the exact steps to recreate an image, you will not be able to perfectly recreate it.
But this isn't very important for nudifying and the improved performance is more important than the ability to recreate your result

ControlNet

ControlNet is very useful for nailing the proportions or pose of the subject in an image.

The ControlNet Github tells you how to install the extension for Stable Diffusion

Once you have ControlNet installed you need models for ControlNet, these can be found on Civitai or Hugging Face another very good resource for Stable Diffusion

For nudifying I recommend using either the openpose or depth models

Now that you have a model you need to choose the ControlNet settings
ControlNet can be found in a dropdown at the bottom of the web-ui

You should use these settings

Setting Value Purpose
Enable yes This will enable ControlNet
Low VRAM no Only enable this if you have low VRAM
Preprocessor depends on model If using depth model use depth_midas as this handles humans the best. If using openpose use any openpose preprocessor, find what you like best
Control weight 0.65 How influential ControlNet is over the result
Control mode Balanced How important ControlNet is compared to prompt

Contact Me

If you require assistance or want information added you can find me:
[email protected]
https://github.com/Average-Degen/

Edit Report
Pub: 02 Sep 2023 03:08 UTC
Edit: 07 Sep 2023 12:13 UTC
Views: 6071