Nodes/ComfyUI_Emojiiii_Custom_Nodes/Caption(反推提示词)
ComfyUI Node

Caption(反推提示词)

Auto-caption every image in a folder — JoyCaption living inside ComfyUI

By emojiiii·Created 2 years ago·Updated 2 years ago· 0
Caption(反推提示词)
  • joy_model
  • default_image_dir
  • STRING
image_dir
promptA descriptive caption for this image
max_new_tokens300
temperature0.50

The Chinese display name says it all: 反推提示词, "reverse-engineer the prompt." Point this node at a folder full of images and it writes a natural-language caption next to each one - a .txt file beside every .jpg or .png - while also handing you the whole batch of captions as one STRING output. It's the original JoyCaption (the pre-alpha generation), running locally with zero API calls and zero keys.

Why bother? Because captioning is the single highest-leverage step in LoRA training after picking the dataset, and JoyCaption is still the community favorite for natural-language captions on Flux and other LLM-encoder models. BLIP is the classic trap here - formulaic, inaccurate, deprecated for years. This node is the "get it done without hand-writing 40 files" path, and for natural-language captioning it's a real step up from the tagger crowd.

How it works

Under the hood it's the classic JoyCaption stack: a SigLIP vision encoder pulls features from the image, a small two-layer MLP ("ImageAdapter") maps them into the token-embedding space, and then Llama 3.1 8B generates the caption autoregressively with those image tokens prepended. top_k=10 is fixed in the code; the temperature slider does what it says. The folder walk is recursive and covers .jpg, .jpeg, .png, .bmp, and .webp.

The inputs that matter

  • image_dir - the folder you're captioning. This is the one that'll bite you: it must be a directory. The code's single-image-file branch references a variable that only exists inside the folder loop, so a plain file path crashes with an unbound-name error. Folders work great.
  • joy_model - the JOY_MODEL output of the pack's CaptionDownload node. It carries the paths to the text model, the SigLIP encoder, and the adapter, so wire those two together and forget it.
  • prompt - the system-style instruction, default A descriptive caption for this image. JoyCaption leans on this, so if you want captions phrased for training, this is where you say so.
  • max_new_tokens (default 300) and temperature (default 0.5) - the knobs. Lower temperature = more predictable output; 300 tokens is plenty for a training caption.

Optional default_image_dir is a wildcard that lets another node feed the directory in, so you can chain from a folder-picker node instead of typing a path.

Install and what it costs

The README is a stub - just acknowledgements - so install is the standard drill: ComfyUI Manager, search ComfyUI_Emojiiii_Custom_Nodes, or clone it yourself:

cd ComfyUI/custom_nodes
git clone https://github.com/emojiiii/ComfyUI_Emojiiii_Custom_Nodes

Then restart ComfyUI. Dependencies are huggingface_hub, transformers, opencv, and bitsandbytes - the last only matters if you pick the 4-bit Llama in CaptionDownload, which you should. The actual models (several GB) download through CaptionDownload, not here.

Where people get burned

  • It writes into your folder. Each run overwrites <image>.txt beside the image. Point it at a training set with hand-written captions and it'll clobber them - back up first.
  • Models reload every run. There's no caching; each execution re-loads SigLIP and Llama onto the device. The first run after download is slow, and every subsequent run pays a warm-up tax.
  • VRAM. 4-bit Llama on a 8–12 GB card is workable; the full fp16 variant is a memory sink. Default to the 4-bit option and keep device_map="auto" happy.

The pack is small and lightly maintained (essentially a September 2024 snapshot), so treat the node as "works, but you're on your own." For a folder of images needing training captions in one pass, though, it's hard to beat - this is the anti-BLIP.

Categoryemojiiii/caption

Inputs (6)

NameTypeDefaultDescription
image_dirSTRING
joy_modelJOY_MODEL
promptSTRINGA descriptive caption for this image
max_new_tokensINT30010–1000
temperatureFLOAT0.500–1
default_image_diropt*

Outputs (1)

NameTypeDescription
STRINGSTRING