Nodes/ComfyUI_HF_Inference/HF Image Classification
ComfyUI Node

HF Image Classification

A ViT, one text box, no model download

By bitaffinity·Created 2 years ago·Updated 2 years ago· 5
HF Image Classification
  • image
  • STRING
endpoint

The honest version first: HF Image Classification is the roughest node in the bitaffinity/ComfyUI_HF_Inference pack, and that's saying something for a pack that's one commit old. The idea is great - type a Hugging Face model ID, hand it an image, get back a label and a confidence score - but as shipped it has a bug you'll hit before you ever see a label. Read this one with eyes open.

What it's for

Image classification is the "what is this a picture of?" task. Point google/vit-base-patch16-224 (the README's suggested model) at any image and it'll return an ImageNet label - 1,000 classes, from "golden retriever" to "garbage truck" - with a score for each. In a generation workflow that's genuinely useful: verify your output actually matches your prompt, sort a batch of generated images by subject, or just have a model tell you what your latest abstract mess looks like to a machine.

The node's inputs are exactly two:

  • endpoint (STRING) - the HF model ID, e.g. google/vit-base-patch16-224, or a full URL.
  • image (IMAGE) - one image tensor from anywhere in your graph.

It POSTs the image to https://api-inference.huggingface.co/models/{endpoint} and the server returns a JSON list of {label, score} pairs. That list comes back through the node's STRING output socket - wire it into a text display node to actually read it.

The catch

Unlike the Segmentation node in the same pack - which correctly converts its image tensor to PNG bytes before sending - this one passes your IMAGE tensor straight into the HTTP client as the request body. requests calls bool() on it, and a normal batched tensor has more than one element, so you get a RuntimeError: Boolean value of Tensor with more than one element is ambiguous. In plain terms: as shipped, this node can't send your image at all.

That's why its comfy.icu page sits at zero impressions. If you want working cloud classification inside ComfyUI today, this node is a starting point, not a finished one - you'll be patching the serialization, and the obvious fix is to copy the PNG-encode step from the Segmentation node's code.

Installing it

Install is shared with the rest of the pack and genuinely painless, because the only Python dependency is requests:

git clone https://github.com/bitaffinity/ComfyUI_HF_Inference custom_nodes/ComfyUI_HF_Inference
cd custom_nodes/ComfyUI_HF_Inference
pip install -r requirements.txt

Restart ComfyUI (or let ComfyUI Manager install it after searching "ComfyUI_HF_Inference"). Then every node in the pack needs a token - a free Hugging Face token is fine - set as an environment variable:

HF_AUTH_TOKEN=hf_yourtokenhere python main.py

What to expect after you patch it

Even once it's sending images, you're on Hugging Face's serverless tier, which the README warns only supports models 10GB and under and "fails for random reasons on different models." The first call to a cold model can stall for a minute or two while HF boots a container; the pack waits out the reported load time and retries once, so the failure mode is a long pause, then an answer. If classification-in-the-graph is a thing you actually need, budget some time here - the concept is sound, the implementation just wants a little love.

CategoryHF_Inference/Image

Inputs (2)

NameTypeDefaultDescription
endpointSTRING
imageIMAGE

Outputs (1)

NameTypeDescription
STRINGSTRING