Extensions/comfyui_face_parsing
ComfyUI Extension

comfyui_face_parsing

This is a set of custom nodes for ComfyUI. The nodes utilize the a/face parsing model to provide detailed segmantation of face. To improve face segmantation accuracy, a/yolov8 face model is used to first extract face from an image. There are also auxiliary nodes for image and mask processing. A guided filter is also provided for skin smoothing.

By Ryuukeisyou·Created 3 years ago·Updated about a year ago· 194
Ryuukeisyou/comfyui_face_parsing
Nodes31
On cloudLocal install
Categoryface_parsing
Stars194
Updatedabout a year ago

Nodes (31)

BBoxDecompose(FaceParsing)

Crack a bounding box open into its four numbers

face_parsing
BBoxDetect(FaceParsing)

FaceBBoxDetect's more tunable sibling

face_parsing
BBoxDetectorLoader(FaceParsing)

Load the YOLO face-finder before you parse anything

face_parsing
BBoxListItemSelect(FaceParsing)

Pull one face's box out of a multi-face detection

face_parsing
BBoxResize(FaceParsing)

Keep a bounding box valid after you resize the image

face_parsing
ColorAdjust(FaceParsing)

A straightforward brightness/contrast/saturation node, tucked into a face-parsing pack

face_parsing
FaceBBoxDetect(FaceParsing)

Find the face(s), padded and ready to crop

face_parsing
FaceParse(FaceParsing)

The node that actually segments the face

face_parsing
FaceParsingModelLoader(FaceParsing)

Pull in the model that actually reads faces

face_parsing
FaceParsingProcessorLoader(FaceParsing)

The boring node FaceParse can't run without

face_parsing
FaceParsingResultsParser(FaceParsing)

Turn the segmentation into the exact mask you want

face_parsing
GuidedFilter(FaceParsing)

The skin-smoothing node, and the one opencv actually cares about

face_parsing
ImageCropWithBBox(FaceParsing)

The plain crop node this whole pack runs on

face_parsing
ImageCropWithBBoxList(FaceParsing)

Crop every detected face in one go

face_parsing
ImageInsertWithBBox(FaceParsing)

Paste the processed face back where it came from

face_parsing
ImageListSelect(FaceParsing)

Pull one image out of a batch by index

face_parsing
ImagePadWithBBox(FaceParsing)

Pad a crop out to a target size without losing the box's position

face_parsing
ImageResizeCalculator(FaceParsing)

Work out the right resize numbers before you resize anything

face_parsing
ImageResizeWithBBox(FaceParsing)

Resize an image to a detected face box

face_parsing
ImageSize(FaceParsing)

Read an image's width and height as numbers

face_parsing
MaskBatchComposite(FaceParsing)

Collapse a batch of masks into one

face_parsing
MaskBlackOut(FaceParsing)

Wipe out a strip of a mask from one edge

face_parsing
MaskBorderDissolveAdvanced(FaceParsing)

Feather each edge independently

face_parsing
MaskBorderDissolve(FaceParsing)

Feather a mask's edge evenly

face_parsing
MaskComposite(FaceParsing)

Combine two masks with a boolean or arithmetic op

face_parsing
MaskCropWithBBox(FaceParsing)

Crop a mask down to a bounding box

face_parsing
MaskInsertWithBBox(FaceParsing)

Paste a cropped mask back at full scale

face_parsing
MaskListComposite(FaceParsing)

Collapse a list of masks into one

face_parsing
MaskListSelect(FaceParsing)

The same index-pick trick, for masks

face_parsing
MaskToBBox(FaceParsing)

Turn a mask into a bounding box

face_parsing
MaskToBBoxList(FaceParsing)

Turn any mask into bounding boxes this pack understands

face_parsing
Readme

Introduction

This is a set of custom nodes for ComfyUI. The nodes utilize the face parsing model to parse face and provide detailed segmantation. To improve face segmantation accuracy, yolov8 face model is used to first extract face from an image.

There are also auxiliary nodes for image and mask processing. A guided filter is also provided for skin smoothing.

If you encounter any problems, feel free to open an issue. I'll try to fix it when I'm not busy. Besides, if you like the nodes, please give a star, thanks!

Installation

Just clone the repo https://github.com/Ryuukeisyou/comfyui_face_parsing.git into ComfyUI's "custom_nodes" directory.

On first run, some required files will be downloaded to ComfyUI's "models/face_parsing/" folder and "models/ultralytics/bbox" folder. If you have difficulty connecting to Huggingface, you can try mannually:

  1. Download the .json and .safetensors files from the face parsing model repo and save them to the "models/face_parsing/" folder.
  2. Download the face_yolov8m.pt from the Bingsu/adetailer repo and save it to "models/ultralytics/bbox" folder.

Requirements

See requirements.txt. Specially, opencv-contrib-python is needed for guided filter. If you have other versions of opencv e.g. opencv-python-headless installed after open-contrib-python, you may need to uninstall opencv-contrib-python and reinstall it again. Note: If you don't need guided filter, you can just forget about opencv-contrib-python, as it is often conflicted by other opencv versions.

Workflow

a demo work flow is shown below.

<img src="demo/workflow.png"> <table> <tr> <th>Original</th> <th>Processed</th> </tr> <!-- Line 1: Compare --> <tr> <td><img src="demo/original.jpg" height="256" width="256"></td> <td><img src="demo/processed.png" height="256" width="256"></td> </tr> </table>

The image bellow contains the workflow which can be loaded into ComfyUI.

<img src="demo/processed.png" height="256" width="256">