[SD Advanced Tutorial]How to automatically fix faces and hands

[SD Advanced Tutorial]How to automatically fix faces and hands

AI  Learning Assistant No 1
AI Learning Assistant No 1
August 21st, 2023

After Detailer (adetailer) is a Stable Diffusion Automatic11111 web-UI extension that automates inpainting and more. It saves you time and is great for quickly fixing common issues like garbled faces. In this post, you will learn how it works, how to use it, and some common use cases.


We will use AUTOMATIC1111 Stable Diffusion GUI. You can use this GUI on WindowsMac, or Google Colab.

Check out the Quick Start Guide if you are new to Stable Diffusion.

Installing After Detailer extension

Google Colab

Using After Detailer in our Google Colab notebook is easy. All you need to do is select the ADetailer option in the Extensions section.

Windows or Mac

Follow these steps to install the Regional Prompter extension in AUTOMATIC1111.

  1. Start AUTOMATIC1111 Web-UI normally.

2. Navigate to the Extension Page.

3. Click the Install from URL tab.

4. Enter the following URL in the URL for extension’s git repository field.

https://github.com/Bing-su/adetailer 5. Wait for the confirmation message that the installation is complete.

6. Restart Web-UI.

Inpaint to fix faces

Before learning how to use After Detailer, it is helpful to go through what you would do without it.

Problems with generating small faces

Let’s say you generate a full-body image of a person. Because you are using a v1 model, you should not set the resolution too high (too much larger than 512 pixels). Otherwise, you will have duplicate persons.

Model: Realistic Vision v2


A woman sitting on a giant ice cream, which is adorned with vibrant colors, delightful, and rainbow sprinkles. sweetness and joy, happiness, enchanting fusion, imagination and a fantastical world,fantasy, high contrast, ink strokes, explosions, over exposure, purple and red tone impression , abstract, negative space Negative prompt: underage, immature, disfigured, deformed, ugly Size: 512×768

Because the face is small and the resolution is low, there are not many pixels covering the face. The VAE does not have enough pixels to generate a good face. So the face is garbled.

What you would normally do is send the image to Inpainting using the Send to inpaint button.

In the Inpaint tab, draw a mask around the garbled face.

Use the following settings:

  • Mask mode: Inpaint masked
  • Masked content: Original
  • Inpaint area: Only masked
  • Denoising strength: 0.5

Press Generate.

You will see the face fixed nicely. The inpaint only masked option is especially important because it uses the whole resolution (512×768) to regenerate the masked area. Effectively, it regenerates the face at a much higher resolution and then scales it back down to the original resolution. That’s why the face now looks much better.

Automatic inpainting with After Detailer

After Detailer automates this process and more. What it does is use a face recognition model to detect the face and create the inpaint mask automatically.

The extension then performs inpainting with only the masked area, like what was done in the last section. The result is:

So it is essentially a time saver extension.

Using After Detailer

Use in Txt2img

To use After Detailer in txt2img, expand the ADetailer.

Select Enable ADetailer.

Select the face_yolo8n.pt model in the ADetailer model dropdown menu.

That’s all you need to do to use the basic function of restoring the face.

Press Generate. You get the following image. The reason you don’t get exactly the same face as manual inpainting is that the inpainting masks are drawn differently.

Use in img2img

You can also use After Detailer with image-to-image. The benefit is you can restore faces and add details to the whole image at the same time.

In the txt2img page, send an image to the img2img page using the Send to img2img button. The generation parameters, such as the prompt and the negative prompt, should be automatically populated.

Set denoising strength (of img2img, not ADetailer) to a low value, e.g. 0.1.

Enable After Detailer in the ADetailer section.

Hit Generate. More details are added to the image!

Adjust denoising strength to control the level of details added.

You can also use ADetailer in the inpaint tab. If the masked area is changed.

ADetailer parameters explained

Now you know the basic function, let’s learn some extra parameters to fine-tune its function.

Detection model

Select the detection model in the ADetailer model dropdown menu. The models are divided into a few different groups:

  • Face_xxxx: Detect and redraw faces
  • Hand_xxxx: Detect and redraw hands
  • Person_xxxx: Detect and redraw a whole person
  • Mediapipe_face_xxxxx: Detect and redraw faces

The most useful ones are the face_yolo and person_yolo models. The YOLO (You Only Look Once) models are good at detecting faces and objects, and inpainting works well.





However, because more pixels are needed for inpainting the whole person, the face was not inpainted as much detail as when using the face model. It is usually not a good idea to inpaint a large area. If you have an image like this, you are better off inpainting the foot, the skirt,… etc, manually one at a time.

Mediapipe_face is hit or miss. They don’t do too well when the faces are garbled, which is why we need them in the first place…

The hand models are for redrawing hands. But don’t put too much hope on this one because Stable Diffusion is still not good at drawing hands, no matter how many times it redraws them.

Finally, you may wonder about the difference between the YOLO 8n and 8s models. The 8n model is faster but is about 3 times smaller than the 8s model (hence less powerful). I find the 8n model does a good job. Switch to the 8s model if After Detailer has difficulty detecting faces.

Finally, you can use up to two detection models each time. Just switch to the 2nd tab and select an additional model.

Now it detects the face followed by the hand. It then inpaints to fix both one at a time.

Using a different prompt in inpainting

Using a different prompt allows you to, for example, change the face after inpainting. Put in the prompts and negatives for inpainting in the ADetailer section below.

One common trick is to use multiple celebrity names to dial in the look you want. For example, I want the face to be a blend of two actresses.

(Emma Watson:0.8), Ana de Armas Keyword weight was used to reduce the effect of Emma Watson, who is usually more powerful.

Adjust the inpainting denoising strength (The one in ADetailer, NOT txt2img) to dial in the effect. Now you get the new blended look!

If you see an inconsistent style on the face, use the celebrity names AND the original prompt instead of using the names alone.

You may wonder why couldn’t you use the celebrity names in the original prompt. You surely can, but because of the association effect, you will inadvertently get objects and styles associated with these powerful names.

Finally, you can use LoRA in the prompt too. Below is the face inpainted with Tifa Lockhart LoRA.



The default values work well, but here is what they meant.

Detection model confidence threshold: Remember the box around the face with a number on top? The number is called the confidence score. 0.8 means the model is 80% confident that this is a face. The threshold is the minimum confidence score needed. If you set it to 0.9, a face with a confidence score 0.8 would not be considered. Keep it low at 0.3. Lower it if you have issues detecting the face. Increase it if you detect too many.

Mask min/max area ratio: The minimum and the maximum area of the detected mask allowed. For example, if you set the min area ratio to 0.1, the extension will reject the detections with masks smaller than 10% of the size of the image. Increase the min if you detect unwanted small objects.

Mask Preprocessing

You usually don’t need to change them.

These are for moving and resizing the mask before inpainting. For best results, enable “Save mask previews” in Settings > ADetailer to understand how the masks are changed. A mask preview image will be saved for each detection.

Mask x/y offset: Move the mask in the x/y direction, in pixels.

Mask erosion (-) / dilation (+): Reduce/Enlarge the mask.

Mask Merge mode:

  • None: Inpaint each mask.
  • Merge: Merge the masks and then inpaint.
  • Merge and invert: Inpaint the unmasked area.


The most important setting in the Inpainting section is the Inpaint denoising strength. It controls the denoising strength used in automatic inpainting. Increase to make more changes. Decrease to change less.

You almost always want to use Inpaint only masked for inpainting faces.

You can optimally define image widthheightCFG scale, and number of sampling steps used in inpainting. But the defaults are ok.

Using ADetailer with ControlNet

ControlNet is an indispensable tool to precisely control image generation. Check out the ControlNet article if you are unfamiliar with it. To use ADetailer with ControlNet, you must have ControlNet installed on your AUTOMATIC1111.

You can select the ControlNet model in the last section.

ControlNet Openpose

Use the ControlNet Oopenpose model to inpaint the person with the same pose. Use the openpose model with the person_yolo detection model.

For example, without any ControlNet enabled and with high denoising strength (0.74), the pose is likely to change in a way that is inconsistent with the global image. See the example below.

With ControlNet Openpose enabled, the girl’s pose is kept the same after inpainting.

ControlNet Tile

Enable ControlNet Tile to have inpainting better follows the original image.

Below is the result without and with ControlNet Tile.

Without ControlNet Tile

With ControlNet Tile

Enable ControlNet Tile if you want inpainting to be guided by the original content.

ControlNet inpaint

ControlNet inpaint model (control_xxxx_inpaint) with global_inpaint_harmonious preprocessor improves the consistency between the inpainted area and the rest of the image.

For example, it is disastrous to set the inpainting denoising strength to 1 (the maximum) in After Detailer.

The inpainting process has too much freedom to change the masked area and has messed up.

This problem can be resolved by turning on the ControlNet inpainting model and the global_inpaint_harmonious preprocessor.

Use global_inpaint_harmonious when you want to set the inpainting denoising strength high. Adjust the value slightly or change the seed to get a different generation.

ControlNet Line art

ControlNet line art lets the inpainting process follows the general outline of the original image.


After Detailer with ControlNet Line art.

Use ControlNet line art if you want the inpainted image to follow the outline of the original content.

ADetailer vs face restoration

Both ADetialer and the face restoration option can be used to fix garbled faces. After Detailer uses inpainting at a higher resolution and scales it back down to fix a face. Face restoration uses another AI model, such as CodeFormer and GFGAN, to restore the face.

Using inpainting (such as using ADetailer) is preferred because

  • The face restoration model could produce a style that is inconsistent with your Stable Diffusion model.
  • You can further direct the inpainting by modifying the prompt and ControlNet.

When to use ADetailer

There’s nothing you can do in ADetailer that you can’t do manually. ADetailer automates the following process.

  1. Send the image to inpainting
  2. Create inpaint mask
  3. Setup ControlNet (Optional)
  4. Generate inpaint

The most valuable aspect of using this extension is automation so that you can use create multiple images with the same settings (batch size larger than 1). This is tedious to do with a manual workflow.

So that’s it. I hope you’ve enjoyed this tutorial. Let me know if you have any comments or feedback in the comments below.


When using ADetailer with img2img, there are two denoising strengths to set. The denoising strength of img2img sets the value for the whole image. The inpaint denoising strength in ADetailer sets the denoising strength for inpainting.

You can optionally turn on saving the result of the detection model in Settings > ADetailer. It will save an additional image with the detected area and the confidence scores.

Reprinted from View Original
Collection Navigation
# 1 [SD Advanced Tutoria]How to fix parameters?
# 2 [SD Advanced Tutorial]How to automatically fix faces and hands
# 3 [SD Advanced Tutorial]How to run SDXL models
# 4 [SD Advanced Tutorial]Speed up Stable Diffusion
# 5 [SD Advanced Tutorial]3 ways to control lighting in Stable Diffusion
# 6 [SD Advanced Tutorial]Video to video with Stable Diffusion
# 7 [SD Advanced Tutorial]3 methods to upscale images in SD
# 8 [SD Advanced Tutorial]Control image composition in SD
# 9 [SD Advanced Tutorial]How to generate animals in SD
# 10 [SD Advanced Tutorial]How to make a video with SD
# 11 [SD Advanced Tutorial]How to generate realistic people in SD
# 12 [SD Advanced Tutorial]Stable Diffusion SDXL Beta Model
# 13 [SD Advanced Tutorial]SD Samplers: A Comprehensive Guide
# 14 [SD Advanced Tutorial]Midjourney vs SD: Which one should you pick?
# 15 [SD Advanced Tutorial]What is hypernetwork
# 16 [SD Advanced Tutorial]AUTOMATIC1111: A Beginner’s Guide
# 17 [SD Advanced Tutoria]What are LoRA models and how to use them in AUTOMATIC1111
# 18 [SD Advanced Tutoria]ControlNet v1.1: A complete guide
# 19 [SD Advanced Tutoria]How to remove extra limbs with Stable Diffusion inpainting
# 20 [SD Advanced Tutoria]Stable Diffusion prompt: a definitive guide
# 21 [SD Advanced Tutoria]Instruct Pix2Pix: Edit and stylize photos with text
# 22 [SD Advanced Tutoria]How to use outpainting to extend images
# 23 [SD Advanced Tutoria]ChatGPT: How to generate prompts for Stable Diffusion
# 24 [SD Advanced Tutoria]How to run Stable Diffusion on Google Colab (AUTOMATIC1111)
# 25 [SD Advanced Tutoria]Stable Diffusion Installation Tutorial (Mac M1/M2)
# 26 [SD Advanced Tutoria]How to use negative prompts?
# 27 [SD Advanced Tutoria]How does negative prompt work?
# 28 [SD Advanced Tutoria]How does Stable Diffusion work?
# 29 [SD Advanced Tutoria]Stable Diffusion Workflow
# 30 [SD Advanced Tutoria]Depth-to-image in SD 2
# 31 [SD Advanced Tutoria]How to install SD on Windows
# 32 [SD Advanced Tutoria]How to use embeddings in Stable Diffusion
# 33 [SD Advanced Tutoria]How to install Stable Diffusion 2.1 in AUTOMATIC1111 GUI
# 34 [SD Advanced Tutoria]How to cartoonize photo with Stable Diffusion
# 35 [SD Advanced Tutoria]How to use Dreambooth to put anything in Stable Diffusion (Colab notebook)
# 36 [SD Advanced Tutoria]How to use VAE to improve eyes and faces
# 37 [SD Advanced Tutoria]Turn amateur into professional with img2img
# 38 [SD Advanced Tutoria]How to use AI image upscaler to improve details
# 39 [SD Advanced Tutoria]How to run Stable Diffusion 2.0 and a first look
# 40 [SD Advanced Tutoria]A Beginner's Guide to SD Models
# 41 [SD Advanced Tutoria]How to stylize images using Stable Diffusion AI
# 42 [SD Advanced Tutoria]Basic information of Stable Diffusion
# 43 [SD Advanced Tutoria]Top Free Stable Diffusion AI Image Generator Sites
# 44 [SD Advanced Tutoria]Image AI generates fashion ideas
# 45 [SD Advanced Tutoria]Make an Animated GIF Using SD
# 46 [SD Advanced Tutoria]Common Problems in AI
# 47 [SD Advanced Tutoria]Change prompt word parameters
# 48 [SD Advanced Tutoria]AI removes unwanted objects
# 49 [SD Advanced Tutoria]Fine-tune AI images with tips
# 50 [SD Advanced Tutoria]What is Stable Diffusion?


no dataCoffee time! Feel free to comment