ComfyUI Node

Minimax_H3_Face_Cut

Find the faces, crop them, and leave the latent alone

By supElement·Created 3 months ago·Updated 4 days ago· 36
Minimax_H3_Face_Cut
  • vae
  • latent
  • images
  • info
  • crop_images
  • face_pack
  • masks
  • shot_info
  • identity_refs
◄face_model▾►
◄yolo_threshold0.30►
◄yolo_batch16►
◄shot_threshold40.0►
◄upscale_modelNone►
◄pre_blur0.0►
◄res512►
◄expand20►
◄skip_ratio0.80►
◄sec_modelNone►
◄sec_threshold0.30►
◄max_identities6►
◄unload_main_modelstrue►
◄sr_batch4►
◄enable_cachetrue►
◄clear_cachefalse►

Small faces in video generation come out smeared, and no checkpoint fix exists - a face that occupies 60 pixels of a 960-wide frame has nowhere to spend latent budget. The standard answer is the detailing loop: detect, crop, upscale, re-render, paste back. Minimax_H3_Face_Cut is the detect-and-crop half, built for H3's chunked long-video output rather than for a single still.

You'd reach for it when you've got a finished H3 clip - long, chunked, and mostly good - whose faces are the weak part. It is step one of three: Cut → Face_Resample → Face_Blend. It doesn't repaint anything. It hands the other two nodes something they can work with.

How it works

Three passes, in order, and the order is the point.

Shot detection first. PySceneDetect (content detector, pure CPU, no model) cuts the video into shots. Faces get cropped per shot, not per frame, so the crop window doesn't teleport when the camera cuts. If scenedetect isn't installed, the node warns and degrades to running detection without shot segmentation rather than erroring - a dependency that fails soft.

YOLO detection second. A YOLO face model boxes every face in every frame, batched. Detections in tracking gaps are folded back into existing tracks before new identities are considered, which is what stops two people crossing from shattering one identity into three.

Optional identity tracking third. With sec_model set to SeC-4B weights, the bundled engine does multi-person identity arbitration on pixel masks (boxes as a fallback), then bridges residual gaps by in-track interpolation. With sec_model on None you get single-face mode: the largest face per frame, no mask, no tracking.

Then each face gets a window: expanded by expand percent, smoothed across frames, cropped, and upscaled to a uniform res × res square. That uniformity is what lets the next two nodes treat a whole video as a stack of rows instead of a special case per frame.

Inputs that matter

Required and worth understanding:

  • face_model - the YOLO weights, from ComfyUI/models/elementEasy/. Nothing selected means it errors out immediately. Accepts .pt/.pth/.onnx/.engine/.torchscript.
  • vae - only used in latent mode. If you wire images (recommended), it's ignored entirely.
  • res (512) and expand (20) - the crop canvas size and the margin around the detected box. Bigger expand gives the model context to keep the face consistent; too big and you're resampling hair and wall for no reason.
  • yolo_threshold (0.3) - lower it if faces are being missed.
  • skip_ratio (0.8) - a face already at least this fraction of res is left alone and produces no output row. Sensible default; it's why crop_images can have fewer rows than frames.
  • upscale_model - optional SR from ComfyUI/models/upscale_models/. Use an ESRGAN/RealESRGAN-type image upscaler; face-restoration models (GFPGAN, CodeFormer) are the wrong tool here, since Face_Resample is doing the restoration. Faces under 192px get one SR pass, then a bicubic resize to exact size.
  • sec_model / sec_threshold / max_identities - the identity-tracking trio. None = single face.

The two you'll tune for your card are unload_main_models (on, and you want it on with 12–16GB - it moves H3/VAE/CLIP out of VRAM before the crop/SR stage, and SR models load via spandrel outside ComfyUI's scheduler, so a resident main model will push you over) and sr_batch (4 at 16GB, 8–16 at 24GB+; it changes speed and VRAM peak, never results).

Outputs: crop_images (uniform crops, all frames kept) → Face_Resample. face_pack (the geometry ledger) → Face_Resample and Face_Blend. masks → Face_Blend directly, bypassing Resample. shot_info → the parameter node only, never into a geometry port. identity_refs → eyeball it before running Resample, because a wrong anchor means the wrong identity gets repaired.

Install

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

Manager route: search ComfyUI_MinimaxH3_AutoContext. Then put models where the node looks - YOLO into models/elementEasy/, SeC-4B (fp16 recommended) into models/sams/, SR into models/upscale_models/ - and restart so the dropdowns refresh. The author's model downloads live at huggingface.co/cglearned/Minimax_H3_Face_Cut.

Two dependencies the README doesn't spell out. The requirements file ships scenedetect but not ultralytics, and the YOLO detector imports it lazily at runtime - so Face_Cut installs cleanly and then dies with an ImportError on first run until you pip install ultralytics. It's AGPL-3.0, which matters if you're shipping commercially. The bundled SeC engine also wants transformers>=4.49 (Qwen2.5-VL support), which the requirements file leaves to you.

Common issues

A sudden slowdown with no OOM on a 16GB card. Windows spills VRAM overflow into "shared GPU memory" silently. Keep unload_main_models on, drop sr_batch to 2.

SR failed to load. It falls back to lanczos automatically. If you're getting colour blotches on small faces, swap to a RealESRGAN_x4plus-type model; if they persist, they're coming from VAE round-trips downstream - lower the step count.

UNCOVERED warning. No face in that frame range at all; it passes through untouched. If that's wrong, yolo_threshold is too high.

Masks all zero. Normal in single-face mode. In multi-identity mode, check the SeC log lines above.

Changed the model, VAE, SeC weights or the code and nothing updated. Tick clear_cache, or delete ComfyUI/output/cache/node_<node id>/. clear_cache only clears this node's own directory - Face_Resample invalidates its crop-row cache on content hash automatically, but node-id changes mean deleting each directory by hand.

CategoryMinimaxH3_AutoContext/FaceFix

Inputs (20)

NameTypeDefaultDescription
face_modelCOMBOYOLO face model (ComfyUI/models/elementEasy) 人脸检测模型
vaeVAEVideo VAE (latent mode only; ignored in images mode) 视频 VAE (仅 latent 模式使用, images 模式忽略)
yolo_thresholdFLOAT0.300.05–0.9YOLO detection confidence threshold YOLO 检测置信度阈值
yolo_batchINT161–128YOLO detection batch size (frames per forward pass). Use 4~8 on low-VRAM GPUs to avoid OOM; raise to 32~64 on high-VRAM GPUs for speed. Results are identical regardless of batch size YOLO 检测批大小 (每次前向的帧数)。低显存卡 (8~12GB) 建议降到 4~8 防 OOM;高显存卡可升到 32~64 提速。批大小不影响检测结果
shot_thresholdFLOAT40.05–100PySceneDetect ContentDetector threshold (higher = fewer cuts). PySceneDetect ContentDetector 阈值 (越高切点越少)。
upscale_modelCOMBONoneOptional upscale model (ComfyUI/models/upscale_models) for face crops. None = bicubic only. 可选放大模型 (upscale_models 目录), None = 仅 bicubic (原行为)。
pre_blurFLOAT0.00–8Gaussian blur (sigma, source-window px) applied to each crop BEFORE SR/bicubic upscale; 0 = off. Softens source noise & interpolation jaggies 放大/SR 前对裁剪窗口施加高斯模糊 (σ, 源窗口像素); 0 = 关闭
resINT512256–2048Canvas side length 画布边长
expandINT200–100Crop window margin % around the detected face box 围绕检测面部外框的裁剪窗口余量%
skip_ratioFLOAT0.800.3–1Skip resampling when face >= res x this 脸够大时跳过重采样
sec_modelCOMBONoneSeC-4B weights in ComfyUI/models/sams (fp16 recommended). None = single-face mode (one face per frame); picking a weight enables multi-person identity models/sams 下的 SeC-4B 权重 (建议 fp16)。None = 单脸模式 (每帧单脸);
sec_thresholdFLOAT0.300.1–0.8IoU/overlap threshold to claim a YOLO box to an identity (multi_sec only) 检测框认领给某身份的重叠率阈值 (仅 multi_sec 模式)
max_identitiesINT61–12Max tracked identities per shot unit 每个镜头单元最多追踪身份个数
unload_main_modelsBOOLEANtrueUnload H3/VAE/CLIP from VRAM after detection & SeC tracking, before the crop/SR stage (recommended on 12~16GB cards 检测与 SeC 追踪完成后、裁剪/SR 放大前,把 H3 主模型/VAE/CLIP 移出显存 (12~16GB 显存建议开启;SR 模型经 spandrel 直进显存、不受 ComfyUI 模型管理调度
sr_batchINT41–16Frames per SR forward pass for crop upscale. Peak VRAM scales with this; 4 on 16GB, 8~16 on 24GB+. Does not affect results, only speed/VRAM 裁剪放大阶段每次 SR 前向的帧数。显存峰值随此值增大;16GB 用 4,24GB+ 可 8~16。不影响结果,只影响速度与显存
enable_cacheBOOLEANtrueClear manually after changing model/VAE/SeC weights or CODE (use clear_cache) 更换模型/VAE/SeC 权重或修改代码后请勾 clear_cache
clear_cacheBOOLEANfalseDelete this node's cache directory before running 运行前删除本节点的缓存目录
latentoptLATENTOptional. Required in latent mode (no images connected). In images mode: NOT unpacked / NOT validated / NOT hashed / NOT decoded — completely untouched (audio ledger is provided via Face_Resample audio port) 可选。latent 模式 (未连 images) 必须提供。images 模式下完全不处理 (不解包/不校验/不 hash/不解码) — 音频账本由 Face_Resample 的 audio 端口提供
imagesoptIMAGEOptional external detection source: when connected, shot detection / detection / SeC / crop run on these frames at NATIVE size 可选外部检测画面: 连接后 分镜检测/检测/SeC/裁剪 直接作用于这些帧
infooptDICTMain sampler info (h3_runtime), optional 主采样 info (可选)

Outputs (5)

NameTypeDescription
crop_imagesIMAGEUniform res^2 crops (row order = subtrack order, ALL frames kept) 所有待采样子轨的统一 res² 裁剪 (全部帧保留)
face_packDICTSubtrack geometry pack (masks also kept inside for legacy wiring) 子轨几何包 (mask 同时保留在包内, 兼容旧接线)
masksMASKSeC masks [rows,res,res], rows 1:1 with crop_images/canvas rows, 1=face SeC mask [行数,res,res], 行与 crop_images/画布 1:1 对齐, 1=人脸
shot_infoDICTShot map for Minimax_H3_AutoContext_parameter: shots/cuts/fps 供 parameter 节点分配分段提示词的镜头表 (shots/cuts/fps)
identity_refsIMAGEOne identity-verified anchor crop per track (row order = track id). PRE-CHECK this BEFORE running Face_Resample — wrong ref = wrong identity repair 每个身份一张已验证锚定参考 (行序=身份id)。请在运行 Face_Resample 之前用它预检 — 参考错 = 修脸身份错