Nodes/zhangp365/ComfyUI-utils-nodes/detector for the NSFW
ComfyUI Node

detector for the NSFW

An in-graph NudeNet content filter for ComfyUI

By zhangp365·Created 2 years ago·Updated 5 months ago· 134
detector for the NSFW
  • image
  • alternative_image
  • output_image
  • detect_result
  • filtered_image
detect_size320
provider
model_name
buttocks_exposed0.70
female_breast_exposed0.70
female_genitalia_exposed0.50
anus_exposed0.70
male_genitalia_exposed0.50

If you're running generation as a service - anything where a stranger's prompt turns into an image that gets saved, shown, or shipped somewhere - you eventually need an automated "does this need to be blocked" check. DetectorForNSFW is that check, built straight into your ComfyUI graph instead of a separate microservice you have to stand up and maintain. It's adapted from NudeNet, a small, well-known open-source nudity detector, wired into a node with per-category confidence sliders you can tune yourself. Worth knowing going in: the same author also maintains ComfyUI-PuLID-Flux, a widely-used Flux identity port, so this isn't a first-time repo - it's someone who ships and keeps shipping.

How it actually decides

The node ships with a bundled 10MB ONNX model (320n.onnx) that runs on CPU, CUDA, or ROCM - pick whichever provider matches your box. detect_size (320 or 640) has to match the model you're running; 320 is the default bundled one. If you want a bigger, more accurate model, NudeNet publishes alternates on Hugging Face (zhangsongbo365/nudenet_onnx) - drop the file in models/nsfw and set model_name and detect_size to match.

Detection isn't one blanket "NSFW or not" toggle. It scores five separate categories - buttocks_exposed, female_breast_exposed, female_genitalia_exposed, anus_exposed, male_genitalia_exposed - each with its own confidence threshold (0.05 steps, defaults between 0.5 and 0.7). Lower the number and you filter more aggressively; set any one to 1 and you've effectively turned off filtering for that category alone. That granularity is the actual point of using this over a blunt classifier - you can, say, allow topless but block everything below the belt, or the reverse.

The outputs, and what each does

Wire in image (required) and optionally an alternative_image. Three things come out: output_image is your original image, or the alternative/blank image if it tripped a threshold - this is the swap-in-a-placeholder output for a pipeline that has to keep running regardless. detect_result is the raw detection as a JSON string, handy if you want to log what got flagged and why rather than just pass/fail. filtered_image only contains images that passed - and per the author's own note, if you feed a single flagged image into a SaveImage node downstream of filtered_image, it raises an exception rather than silently saving nothing. That's a deliberate hard-stop for batch jobs where you'd rather crash loudly than quietly ship something you shouldn't.

Install and the one real caveat

ComfyUI Manager: search "ComfyUI-utils-nodes." Or manually:

cd ComfyUI/custom_nodes
git clone https://github.com/zhangp365/ComfyUI-utils-nodes

Restart ComfyUI. No heavy dependency here - this node doesn't need TensorFlow (that's the other face-analysis node in this pack); it's onnxruntime, and the default model is small enough that you're not waiting on a big first-run download.

The one thing worth setting expectations on: NudeNet-family detectors - and this node's inference code is lifted directly from NudeNet - are trained mostly on photographic content. In the wild, people report the same underlying detection approach doing fine on realistic images but getting noticeably shakier on anime and stylized art: missing obvious stuff, or flagging body parts that aren't actually there. If your pipeline is anime-leaning, don't treat this as a silent, bulletproof gate - spot-check its calls against your actual output before trusting the thresholds blind. The author's own claim, from testing, is that it beats classifier-style models like Falconsai's NSFW detector for filtering effect - that's their opinion, not an independent benchmark, but it lines up with why detection-based approaches (which localize where the exposure is) tend to generalize better than single-label classifiers.

Categoryutils/filter

Inputs (10)

NameTypeDefaultDescription
imageIMAGE
detect_sizeCOMBO3202 options: 640, 320
providerCOMBO3 options: CPU, CUDA, ROCM
model_nameoptCOMBO1 options:
alternative_imageoptIMAGE
buttocks_exposedoptFLOAT0.700–1
female_breast_exposedoptFLOAT0.700–1
female_genitalia_exposedoptFLOAT0.500–1
anus_exposedoptFLOAT0.700–1
male_genitalia_exposedoptFLOAT0.500–1

Outputs (3)

NameTypeDescription
output_imageIMAGE
detect_resultSTRING
filtered_imageIMAGE