Nodes/ComfyUI_CaptionThis/Florence2 Caption Images Under Directory ๐Ÿ‘
ComfyUI Node

Florence2 Caption Images Under Directory ๐Ÿ‘

Batch-caption a folder fast

By MieMieeeeeยทCreated about a year agoยทUpdated 10 months agoยท 127
Florence2 Caption Images Under Directory ๐Ÿ‘
  • model
  • log
โ—„directoryX://path/to/filesโ–บ
โ—„taskmore_detailed_captionโ–บ
โ—„seed42โ–บ
โ—„max_new_tokens1024โ–บ
โ—„num_beams3โ–บ
โ—„do_sampletrueโ–บ
โ—„keep_model_loadedtrueโ–บ
โ—„save_to_new_directoryfalseโ–บ
โ—„save_directoryโ–บ

Point this at a folder and it captions every image in it with Florence-2, writing each caption to a .txt file next to its image. That image.png / image.txt pairing is the standard LoRA dataset layout every trainer expects - so this is the node you use to prep a training set without hand-writing a hundred captions. And because Florence-2 is tiny and quick, it's the fast option when you've got a big folder to get through.

Why this is the one for big datasets

Captioning is one of the highest-leverage steps in LoRA training, and it's also the most tedious. This node hands the tedium to a small, fast vision model. Florence-2 vs the alternatives: it's much lighter than a 7B captioner like Janus or JoyCaption, so on a large folder it just gets through the work faster. It's also the community's standard answer to "don't use BLIP" - BLIP captions are formulaic junk and have been for years; Florence-2 or JoyCaption, or by hand.

The default task (more_detailed_caption) writes natural-language paragraphs, which is what modern LLM-encoder bases (Flux, Qwen-Image, Z-Image) want to be trained on. If you're training an anime base in the Illustrious/Pony line, that world wants Danbooru comma-tags instead - set task to tags, though a dedicated WD14 tagger is still the sharper tool there.

One training rule to keep in mind before you batch: caption what should stay variable, leave what should be permanent undescribed. An auto-captioner describes everything it sees, so treat the generated .txt files as a strong first draft - skim them and prune the lines describing the features you want your LoRA to lock in.

The inputs that matter

  • model - from Florence2 Model Loader.
  • directory - the folder to caption. The default X://path/to/files is a placeholder; swap in a real path.
  • task - same seven options as the single-image node (caption, detailed_caption, more_detailed_caption, tags, mixed, extra_mixed, analyze). more_detailed_caption for prose, tags for comma tags. This choice applies to every image in the folder.
  • save_to_new_directory (off) and save_directory (optional) - by default the .txt files land next to the source images. Turn save_to_new_directory on and set save_directory to write them somewhere separate and keep your originals clean.

num_beams (3), do_sample (on), max_new_tokens (1024), seed and keep_model_loaded behave exactly like the single-image node.

The output is log (a STRING) - a progress report, not the captions (those go to the .txt files). Wire it into a ShowText node if you want to watch it work.

How to install it

Part of ComfyUI-CaptionThis:

  • ComfyUI Manager (recommended): search CaptionThis, Install, restart.
  • Manual: cd ComfyUI/custom_nodes && git clone https://github.com/MieMieeeee/ComfyUI-CaptionThis, then restart.

Florence-2 weights download from HuggingFace on first run (or set HF_ENDPOINT=https://hf-mirror.com for the mirror). See the Florence2 Model Loader page for variant and precision details.

Common issues & troubleshooting

Nothing gets captioned. You left the X://path/to/files placeholder in the directory field, or the path is wrong. Point it at a real folder of images.

It errors before processing a single file. That's the loader, not this node - usually flash_attention_2 chosen without the flash-attn package, or a precision mismatch. On the Florence2 Model Loader, set attention to sdpa, and try fp32 if you see NaN/garbage output.

Captions over-describe the subject. Expected - the model describes everything. Review the .txt files and prune the lines covering features you want your LoRA to treat as fixed.

Category๐Ÿ‘ Florence2Caption

Inputs (10)

NameTypeDefaultDescription
modelMIE_FLORENCE2_MODELโ€”
directorySTRINGX://path/to/filesโ€”
taskCOMBOmore_detailed_caption7 options: caption, detailed_caption, more_detailed_caption, tags, mixed, extra_mixed, +1
seedINT421โ€“18446744073709550000โ€”
max_new_tokensINT10241โ€“4096โ€”
num_beamsINT31โ€“64โ€”
do_sampleBOOLEANtrueโ€”
keep_model_loadedBOOLEANtrueโ€”
save_to_new_directoryBOOLEANfalseโ€”
save_directoryoptSTRINGโ€”

Outputs (1)

NameTypeDescription
logSTRINGโ€”