Nodes/Facefusion_comfyui/FF: Deep Swap Face (DFM)
ComfyUI Node

FF: Deep Swap Face (DFM)

FF Deep Swap Face (DFM)

By huygiatrng·Created 10 months ago·Updated about a month ago· 98
FF: Deep Swap Face (DFM)
  • target_image
  • IMAGE
dfm_model
morph100
face_detector_modelscrfd
face_selector_modeone
face_position0
sort_orderlarge-small
score_threshold0.30
face_mask_blur0.30
face_mask_padding0,0,0,0

Every other node in the Facefusion_comfyui pack works the same way: you hand it a source face, a target face, and a generic swapper model (inswapper, hyperswap, whatever) does the swap on the spot. DeepSwapFaceImage is the one that refuses to play that game. There's no source image input at all, because the face is already baked into the model.

This is the ComfyUI port of FaceFusion's "deep swapper": support for DeepFaceLive .dfm models. A .dfm is an identity-specific model - you (or someone) trained it on one person's face for hours in DeepFaceLab, exported it, and now it is that face. Feed it any target image and it maps that trained identity onto whatever face it detects. No source image, no reference match, no embedding computed at runtime. That makes it the odd node you reach for when you have a DFM you trust and want to run it inside a ComfyUI graph instead of firing up DeepFaceLive.

That's also the honest trade-off: generic swap models handle anyone, DFMs handle exactly one person and generally do it better because they were trained for it. If you don't already own DFM models, this node is useless to you - the dropdown literally shows [no .dfm models found] until you add some. Skip it and use FF: Advanced Swap Face instead. If you do own them, this is the cleanest way to use them in a workflow.

How it works

The node detects faces in your target, then runs the selected DFM model over each detected face. Detection is the same InsightFace-family backend the rest of the pack uses (scrfd by default, with retinaface, yolo_face, yunet, and many available). The .dfm model does the actual pixel-level swap - no source needed, which is the whole point.

To make a model show up:

# from your ComfyUI directory
cd custom_nodes/Facefusion_comfyui
mkdir -p models/deep_swapper
# drop your .dfm file(s) in here - subfolders are fine

Then restart ComfyUI. The files are scanned at startup, so a model you drop in without a restart won't appear.

The inputs that matter

  • target_image - the only image input. Single images and batches both work, and you get back the same shape you sent in.
  • dfm_model - your DFM pick. Reads from models/deep_swapper/.
  • morph (0–100, default 100) - passed straight to the model. Only DFM models trained with a morph input (AMP-type models) use it; the README is explicit that everyone else safely ignores it. When it works, lower values blend the result back toward the target's own face - a nice safety valve if a swap comes out looking nothing like anyone. Leave it at 100 until you hit a model that cares.
  • face_selector_mode (one/many) plus face_position and sort_order - pick which face in a group shot gets swapped. one + position 0 + large-small (the default) grabs the biggest face; switch to many to hit everyone.
  • score_threshold (0.3) - if the node swears there's no face, drop this to 0.3–0.4 territory and re-check your lighting.
  • face_mask_blur (0.3) and face_mask_padding (0,0,0,0) - edge blending and mask padding; the defaults are fine for most swaps.

Output is a single IMAGE tensor, ready for Preview or Save, and the batch handling means you can feed a whole folder through a Load Image Batch node.

Installing the pack

cd ComfyUI/custom_nodes
git clone https://github.com/huygiatrng/Facefusion_comfyui.git
cd Facefusion_comfyui
pip install -r requirements.txt

Or just search "Facefusion_comfyui" in ComfyUI Manager and restart. First run auto-downloads the detection ONNX models (~200MB) - the .dfm models are the one thing it can't fetch for you.

Gotchas

The most common failure by far is the placeholder dropdown: [no .dfm models found] means the model scan didn't find your files - wrong folder, no restart, or a .dfm that didn't survive the copy. Second is the same ONNX flakiness that hits the whole pack: on Windows, a half-downloaded or file-locked model can throw onnxruntime load errors (system error 13). Deleting the file in models/ and letting it re-download fixes it. And if you're hitting memory limits with a batch, trim the face count with face_selector_mode: one rather than stacking more at once - this node has none of the pixel-boost levers the other swapper nodes get.

One honest warning: DFM models are trained likenesses of real people, and the InsightFace detection backbone this pack depends on ships non-commercial weights. Fine for personal and research use; don't build a product on it without reading the licenses first.

CategoryFaceFusion

Inputs (10)

NameTypeDefaultDescription
target_imageIMAGE
dfm_modelCOMBO1 options: [no .dfm models found]
morphINT1000–100
face_detector_modelCOMBOscrfd5 options: scrfd, retinaface, yolo_face, yunet, many
face_selector_modeCOMBOone2 options: one, many
face_positionINT00–100
sort_orderCOMBOlarge-small8 options: large-small, small-large, left-right, right-left, top-bottom, bottom-top, +2
score_thresholdFLOAT0.300–1
face_mask_blurFLOAT0.300–1
face_mask_paddingSTRING0,0,0,0

Outputs (1)

NameTypeDescription
IMAGEIMAGE