Classify Image (ResNet18)
See what a classifier actually thinks, before and after you attack it
- model
- image
- top_k_results
The adversarial-attack trick only means something if you can check the classifier's answer before and after. That's this node's whole job: point it at the same ResNet18 model, give it an image, and it tells you the top predictions as plain text. It's the verification half of the bemoregt/ComfyUI_AdversarialAttack pack, and it's the honest way to tell whether the attack actually flipped a class or just made the noise.
What it is
ClassifyImage runs ResNet18 inference on any ComfyUI image and returns the top-K predictions as a ranked string. It's a terminal node - marked as an output node in the pack, so it sits at the end of a branch and you read its result rather than wiring anything out of it. The classic setup: two of these, one on the original image and one on the adversarial output, both fed from the same Load ResNet18 model, so you can compare verdicts side by side.
It's also a perfectly usable general ImageNet classifier on its own. If you've ever wanted to sanity-check what a ResNet thinks of your generation (or just test how confidently it misidentifies things), this is the easiest way to get that inside ComfyUI without leaving the graph.
How it works
Nothing exotic. The image gets resized to 224×224 (unless you turn resize_to_224 off), normalized with the standard ImageNet mean/std, pushed through the model, and softmaxed. The node then takes the top-K probabilities and formats each as a line like:
1. tabby cat (281): 92.34%
2. lynx (287): 3.11%
The class names come from the ImageNet label list the loaded model carries with it. The same result also prints to the console prefixed with [ClassifyImage], so you can read it even without a text-display node in the workflow.
The inputs
There are only four, and the only one you'll realistically touch is top_k (default 5, range 1–20) - how many predictions you want. The rest:
model- theRESNET_MODELoutput from Load ResNet18. It has to be the same model instance you feed the attack node, otherwise you're comparing two different brains.image- whatever you want classified: the original, the adversarial output, anything.resize_to_224- on by default, matching how the model was trained.
Its single output is top_k_results (STRING). Because it's an output node, the string shows up in the node's own UI; if you want it somewhere more visible, feed it into a display/text node.
Installation and gotchas
Same story as the rest of the pack - install once via ComfyUI Manager (search "ComfyUI_AdversarialAttack") or git clone https://github.com/bemoregt/ComfyUI_AdversarialAttack into custom_nodes/, restart, and you get all three nodes. Requirements are torch>=2.0 and torchvision>=0.15, which any working ComfyUI already has. The first time you use any node in the pack, Load ResNet18 downloads the ImageNet weights, so your first run needs internet.
Where people trip up: they try to wire the string into a Preview Image node and get confused when nothing shows. That's not what it is - it's text. And if you set Load ResNet18 to random instead of pretrained, the model knows nothing and this node will happily return gibberish class indices, so keep the loader on pretrained unless you have a reason not to. One more thing worth knowing: the whole pack runs on CPU by default, which is fine for a single classification here and there, but don't expect speed on a big batch.
Inputs (4)
| Name | Type | Default | Description |
|---|---|---|---|
| model | RESNET_MODEL | — | |
| image | IMAGE | — | |
| top_k | INT | 51–20 | — |
| resize_to_224 | BOOLEAN | true | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| top_k_results | STRING | — |