Sign up
Log in
Sign up
Log in
Home
Blog

OctoAI’s Adetailer automatically fixes faces and hands

Blog Author - Janisha Anand
Blog Author - Andrew Reusch

Mar 27, 2024

4 minutes
GenAI image of lady in coffee shop that used Adetailer to fix facial and hand details

Introducing After Detailer (Adetailer) by Octo AI: the ultimate solution for automating inpainting and more. This powerful tool not only saves you valuable time but also swiftly addresses common issues like distorted faces and hands. In this guide, we'll delve into how After Detailer operates, its usage, and various practical scenarios where it shines.

Traditionally, to enhance a small, low-resolution face, one would resort to inpainting by meticulously creating and applying a mask, followed by adjusting denoising strength in inpaint mask mode. This process essentially reconstructs the face at a significantly higher resolution before scaling it down to match the original. The result? A vastly improved appearance.

However, Octo AI's Adetailer revolutionizes this workflow by automating the entire process and more. Leveraging advanced face recognition models, it seamlessly detects faces and hands, generating inpaint masks automatically. Subsequently, it calls upon an SDXL API with tailored inpainting parameters, yielding impressive results. Furthermore, the Adetailer API offers flexibility by enabling users to specify the maximum number of detections. For instance, if an image contains five individuals but you only wish to focus on two faces, you can easily achieve this by utilizing the max_num_detections parameter. Notably, the API prioritizes and rectifies faces based on their confidence score and bounding box dimensions.

The versatility of Octo AI's Adetailer API extends further through its support for various detection models. Whether targeting faces, hands, or people, users can choose from an array of options such as face_yolov8n, hand_yolov8n, face_full_mediapipe, face_short_mediapipe, face_mesh_mediapipe, and eyes_mesh_mediapipe, tailoring the after-detailing process to specific needs and preferences.

Adetailer can be accessed through OctoAI’s Adetailer API. It works with both SDXL and SD1.5 models and seamlessly harmonizes with style presets, checkpoints, and LoRAs when utilized, thereby amplifying its adaptability and functionality.

In this post, we will guide you through the utilization of the Adetailer functionality within the OctoAI Adetailer API. Furthermore, we will utilize the new max_num_detection parameter to restrict the number of face detections in an image, particularly when dealing with multiple faces that need correction.

Solution walkthrough

Let's begin with an image of a woman in a coffee shop shown below. You may notice that the woman's eyes in this image appear somewhat misaligned and distorted. We'll address this issue by employing OctoAI's Adetailer API and adjusting the settings of the 'strength' parameter.

curl -X POST -H "Content-Type: application/json" -H "Authorization: Bearer $OCTOAI_TOKEN" -d @filename.json https://image.octoai.run/adetailer
{
    "prompt": "photorealistic, award winning, 8K HDR, best quality, breathtaking",
    "negative_prompt": "worst quality, bad face, drawing, unrealistic, ugly face, animated",
    "cfg_scale": 6,
    "sampler": "DPM_2_ANCESTRAL", 
    "steps": 60,
    "checkpoint": "RealVisXL",
    "inpainting_base_model": "sdxl",
    "style_preset": "base",
    "detector": "face_yolov8n", 
    "strength": 0.5,
    "init_image": "BASE64"
}

Below are the results with RealVisXL checkpoint (SDXL) using faceyolov8n detector model with varying strengths (0.2, 0.5, 0.8 - left to right).

Upon examination, when employing a lower strength value (below 0.5), facial features such as the lips and overall facial structure appear corrected; however, the misalignment of the eyes persists. Conversely, with a higher strength value (above 0.5), significant alterations occur in the jawline structure, and the model introduces an additional facial structure beneath the chin. In our analysis, we found optimal results were achieved with a strength value of 0.5. We advise adjusting the strength parameter according to your specific requirements.

Images with several subjects

Next, let's proceed with an image featuring multiple individuals and apply OctoAI's Adetailer API to it. Below is an image depicting five women walking in a park, each of whom requires facial correction. We will experiment with the max_num_detections parameter to evaluate its influence on the output.

curl -X POST -H "Content-Type: application/json" -H "Authorization: Bearer $OCTOAI_TOKEN" -d @filename.json https://image.octoai.run/adetailer
{
    "prompt": "photorealistic, award winning, 8K HDR, best quality, breathtaking",
    "negative_prompt": "worst quality, bad face, drawing, unrealistic, ugly face, animated",
    "cfg_scale": 6,
    "sampler": "DPM_2_ANCESTRAL", 
    "steps": 60,
    "checkpoint": "RealVisXL",
    "inpainting_base_model": "sdxl",
    "style_preset": "base",
    "detector": "face_yolov8n", 
    "strength": 0.5,
    "max_num_detections":3,
    "init_image": "BASE64"
}

Below are the results with RealVisXL checkpoint (SDXL) using faceyolov8n detector model with no max_num_detections set to varying max_num_detections set (None, 3, 1 - left to right).

When the max_num_detections parameter is left unset, the OctoAI’s Adetailer API detects all objects meeting the confidence score criteria (in our case, 0.3) and inpaints all detections. However, when max_num_detections is set, both the detections and inpaintings are limited. The objects to be inpainted are determined by a combination of the confidence score and the size of the bounding box. As illustrated in the rightmost image, where max_num_detections is set to 1, OctoAI's Adetailer API inpaints only the leftmost face, which is also the largest face in the image.

We recommend utilizing the max_num_strength parameter when working with images featuring multiple faces or hands, particularly if you wish to concentrate on fixing only the primary subjects. This approach can help save costs by limiting subsequent SDXL API calls for inpainting all subjects in the image.

This blog showcases just a few facets of OctoAI’s Adetailer feature. Adetailer offers endless potential - whether in entertainment, marketing agencies, or fashion and retail sectors, it can help fix personalized avatars, advertisements, and brand ambassador representations. To learn more, refer to our documentation.

Get started with Adetailer on OctoAI Media Gen Solution today

Sign up and try Adetailer for free on the OctoAI Media Gen Solution. Join us on Discord to engage with the team and our community. We’ll use the Discord channel to share about upcoming features, promotions and competitions. Stay tuned to learn more, and I look forward to see the applications and imagery you build using OctoAI Media Gen Solution.