ComfyUI Node

Caption Generator

Turn a loaded model and a folder of images into actual text

By mediocreatmybest·Created about a year ago·Updated 12 months ago· 3
Caption Generator
  • model_pipeline
  • image_batches
  • captions
prepend_text
append_text
max_new_tokens75

Model Loader gets you a model. Caption Generator is where that model actually earns its keep - feed it a loaded pipeline and a batch of images, and it hands back captions, one per image, as plain text. If you're building a dataset for LoRA training, this is the node doing the heavy lifting between "folder of pictures" and "folder of pictures with .txt files sitting next to them."

How it works

It takes the MODEL pipeline object straight from Model Loader (or Debug Pipeline Node, if you routed it through there first) and runs it over image_batches - a list of image paths, normally handed up from Batch Processor rather than the raw output of Image Loader, since batching is what keeps a big folder from blowing past your VRAM in one shot. For each image it runs the model's captioning generation and returns the result as a STRING inside the captions list, in order.

The inputs and outputs that matter

  • model_pipeline (MODEL, required) - must come from Model Loader. Whatever model you loaded there is what writes these captions, which matters more than anything else in this node. A stock BLIP model produces the same generic, formulaic sentences that made the LoRA-training community give up on BLIP years ago; if the captions coming out of this node feel flat or repetitive, that's very likely the model upstream, not a setting here.
  • image_batches (LIST, required) - the images to caption.
  • prepend_text / append_text (optional, default "") - glued onto the front or back of every caption this node produces. This is the practical way to bake in a trigger word across an entire dataset without hand-editing every file afterward - the standard LoRA-training move of tagging a rare, consistent token onto every caption so the model learns to associate it with your subject or style.
  • max_new_tokens (optional, default 75, minimum 15) - the generation length cap in tokens. Raise it if captions are getting cut off mid-sentence; lower it if you want short, tag-like output. Worth knowing: this caps length, it doesn't improve quality - a small, older captioning model will still produce the same terse, generic sentence whether you give it 75 tokens or 300, it just won't use the extra room.

Output is captions (LIST), one entry per input image, in the same order - wire it into Caption Export to actually write the files, or through Debug Node first if you want to eyeball the text before committing it.

Installing it

Through ComfyUI Manager: search ComfyUI-Transformers-Pipeline, install, restart. By hand:

cd ComfyUI/custom_nodes
git clone https://github.com/mediocreatmybest/ComfyUI-Transformers-Pipeline

then restart. No separate download for this node itself - the actual model weights come down when Model Loader first runs, upstream of this one.

Common issues & troubleshooting

Captions are generic, repetitive, or slightly wrong. This is the model's ceiling, not a bug in this node. Raising max_new_tokens won't fix it. Swap the upstream model_name_or_path on Model Loader for something better - a BLIP2 variant, or better yet, use this pack's dedicated Florence-2 Node instead of this generic path entirely.

Nothing happens, or it errors immediately. Check that model_pipeline actually came from Model Loader with a task of image-to-text (or whatever matches what this node expects) - a mismatched task string upstream produces a pipeline object shaped for the wrong job.

Captions are cut off mid-sentence. Raise max_new_tokens above the default 75; the minimum is 15, there's no documented ceiling, so push it up until sentences finish.

Every caption has the wrong trigger word, or none at all. Check prepend_text/append_text - they default to empty strings, so nothing gets added unless you set them, and a typo here silently ends up baked into every single caption in your dataset.

CategoryTransformers Pipeline

Inputs (5)

NameTypeDefaultDescription
model_pipelineMODEL
image_batchesLIST
prepend_textoptSTRING
append_textoptSTRING
max_new_tokensoptINT75

Outputs (1)

NameTypeDescription
captionsLIST