DeepFakeDefender_Sampler
This node tells you whether an image is a deepfake — and sorts the batch for you
- image
- net
- transform_val
- string
- above
- below
This is the half of the pack that actually earns its keep. DeepFakeDefender_Loader sits around holding a model; this node scores your images, prints a verdict per image, and splits the batch into "looks fake" and "looks real" piles automatically. If you've ever needed to sort a folder of downloaded faces into suspect and clean before you let them anywhere near a training run, this is the tool.
The model behind it is the 1st-place solution to the Global Multimedia Deepfake Detection competition (Image Track) - a seven-expert ensemble of ConvNeXt-Tiny and EfficientNet backbones running on EMA weights. This sampler is just the inference front end: it resizes, runs the ensemble, averages the experts' probabilities, and compares the result against your threshold.
What it does step by step
For each image in the batch, the node:
- Upscales or downscales it to your
crop_width×crop_height(nearest-exact, center-cropped). - Applies the preprocessing pipeline that came out of the Loader's
transform_valsocket - ImageNet normalization, resized to the model's native 512×512. - Runs the ensemble and gets a single number: the probability the image is a deepfake, 0–1.
- Prints that prediction to the console (in English and Chinese, if you care) and routes the image to one of two output piles.
The inputs that matter
- image - your input, an
IMAGEtensor. Batches are handled, so you can feed multiple faces at once. - net and transform_val - both come from
DeepFakeDefender_Loader. Yes,transform_valis typed asMODEL; it's actually a torchvision transform pipeline. Wire it anyway. - threshold - the decision boundary, default
0.5. Above it → classified deepfake, below → real. Raise it if you want fewer false alarms (more likely to call a fake "real"), lower it if you'd rather flag everything suspicious. This is the one knob you'll actually tune. - crop_width / crop_height - default 512×512, which matches the model's native input. The README says cropping the image first gives a "slight improvement in accuracy." Leave them at 512 unless you have a reason.
The three outputs
- string - the text verdict, one line per image with its deepfake probability.
- above - the
IMAGEoutput of images above threshold (i.e., flagged as deepfake). - below - the images below threshold (judged real).
That's the genuinely nice part: wire above into one preview and below into another and you get visual sorting for free, no Python.
The trap
If a bucket comes up empty - say every image is real, so nothing lands in above - the node does not give you an empty tensor. It returns a 512×512 white image with the text "No image's prediction is above the X" drawn on it. Sounds harmless, until a downstream node chokes on a grayscale-looking image you didn't expect. If you're looping the output, check for that placeholder or keep it in mind when you see a white frame appear in your preview.
Also note the split uses <= for below and > for above, so a prediction exactly at threshold counts as "real."
Install & gotchas
Same pack as the Loader, so the install is identical:
cd ComfyUI/custom_nodes
git clone https://github.com/smthemex/ComfyUI_DeepFakeDefenders.git
Model weights (weight.pth + ema.state) must be downloaded from the README's Google Drive / Baidu links into ComfyUI/models/DeepFakeDefender/ - nothing auto-downloads. Two things worth knowing before you build a workflow on this:
- It's CUDA-only. The loader forces
.cuda(), so CPU-only and Apple Silicon installs will fail at the Loader, not here. timmis needed but isn't in the requirements file (which is entirely commented out). If imports fail,pip install timm.- The whole thing is CC BY-NC 4.0 - fine to tinker with, not for commercial use without checking the license.
Is it a silver bullet for deepfake detection? No - the author's own example images include false calls, and no threshold makes a classifier perfect. But as a free, local, batch-sorting first pass, it's surprisingly practical.
Inputs (6)
| Name | Type | Default | Description |
|---|---|---|---|
| image | IMAGE | — | |
| net | MODEL | — | |
| transform_val | MODEL | — | |
| threshold | FLOAT | 0.50001e-9–0.999999999 | — |
| crop_width | INT | 512256–4096 | — |
| crop_height | INT | 512256–4096 | — |
Outputs (3)
| Name | Type | Description |
|---|---|---|
| string | STRING | — |
| above | IMAGE | — |
| below | IMAGE | — |