Nodes/ComfyUI-ZFRNodes/Caption Generator
ComfyUI Node

Caption Generator

Caption an entire folder for LoRA training without leaving ComfyUI

By zfrsgtcu·Created 3 months ago·Updated 13 days ago· 32
Caption Generator
    • captions_json
    • log
    • count
    providerollama
    api_key
    base_urlhttp://127.0.0.1:11434
    model(set a model)
    batch_size3
    temperature0.40
    top_p0.90
    num_ctx8192
    seed0
    thinkfalse
    system_promptYou are an expert dataset caption writer for Flux 2 LoRA training. Your task is to analyze each image provided and generate precise, detailed, training-ready captions that follow Flux 2 prompting conventions. Rules: Describe exactly what you see. No assumptions, no additions. Always specify the ethnicity, physical appearance, skin tone, age range, and clothing of any person visible. Describe the location, environment, architecture, lighting, time of day, and weather conditions in detail. Use natural, descriptive English. No artistic jargon, no abstract terms. Captions must be specific and factual — avoid vague words like "beautiful", "stunning", "amazing". Do not mention the image quality, resolution, or camera settings unless clearly visible. Write in a single paragraph per image. Output must be a valid JSON array. No explanations, no extra text outside the JSON. Output format: [ { "image_name": "filename.jpg", "prompt_text": "detailed caption here" } ] Below are the Flux 2 prompting guidelines you must follow:
    user_promptWrite a training caption for each image. Use the exact image_name given.
    folder_path
    max_images0
    write_txttrue
    output_txt_folder

    Captioning is the most boring step of LoRA training and also one of the ones that decides how good the result is. This node is from the ZFRNodes pack - the same small collection that brings you the story-frame generators - and it exists to do exactly one job: point it at a folder of images, and it sends each one to a vision LLM and writes a cat_01.txt next to cat_01.jpg, the exact file layout every LoRA trainer expects. No graph wiring, no separate Ollama node, no pasting captions into a text file by hand. You run it, you get a captioned dataset.

    There's some context worth knowing before you reach for it. For modern LLM-encoded bases (Flux, Z-Image, Klein) natural-language captions are the default, and the community favorite is usually JoyCaption. This node is the "use whatever model you already run" alternative: it talks to your local Ollama or a paid API, and it's the one node in this pack that calls an LLM all by itself (the story-generating nodes need the separate stavsap/comfyui-ollama node instead).

    How it works

    Deliberately no IMAGE wire in or out - it reads straight from disk through its own folder_path. It lists the folder's images, base64-encodes each one (shrinking anything over 1024px so the request doesn't explode), and sends them in small batches (batch_size, default 3) so you don't blow the model's context window. The default system_prompt ships tuned for Flux 2 LoRA training: describe exactly what's visible, always specify ethnicity/clothing/environment/lighting, avoid vague words like "beautiful". It's fully editable if you want a different captioning style.

    The clever bit is filename safety. The node tells the model exactly which filenames are in the batch and demands a JSON array of {image_name, prompt_text} back - but then doesn't trust the names the model returns. It matches captions to real files strictly by order, so a hallucinated or mistyped filename can never mislabel an image.

    The inputs that actually matter

    • folder_path - filled by the same folder picker the pack uses everywhere, or paste a path.
    • provider - ollama (default) or openai / deepseek / google / openrouter / anthropic.
    • model - Ollama users hit "Refresh models" to fill this; API users type a model name.
    • api_key - required for every non-Ollama provider (the node logs a clear message if it's missing).
    • max_images - cap how many to caption (0 = all), handy while testing.

    Outputs: captions_json (all captions as one JSON array, good for a preview node), log, and count. In practice you set folder_path, provider, and model, and go.

    Install

    Same pack either way: search ComfyUI-ZFRNodes in ComfyUI Manager, or

    cd /path/to/ComfyUI/custom_nodes
    git clone https://github.com/zfrsgtcu/ComfyUI-ZFRNodes.git
    

    Then, for the captioner specifically: pip install ollama if you use the ollama provider, or pip install requests for any API provider (most ComfyUI installs already have requests). Restart ComfyUI fully - a browser refresh isn't enough because the node's UI comes from a frontend script.

    Common issues

    • Log says "Set a model first" - you haven't picked one; Ollama users click "Refresh models".
    • Log says the provider needs an api_key - that's by design for non-Ollama providers, not a bug.
    • "JSON parse failed" - small models sometimes answer with prose instead of the array. Check the log, drop batch_size to 1, or use a vision-capable model.
    • Multiple people in one image - every captioner gets attributions wrong here, not just this one. Auto-caption the bulk, but audit a small set by hand.

    One thing to keep in mind with any LLM captioner: it's arbitrary Python that talks to the network by design, and this exact category has been weaponized before. This pack is MIT, one small dev, and the source is right there on GitHub - that's the check you should do before trusting any captioning node.

    Categoryzfr-nodes

    Inputs (16)

    NameTypeDefaultDescription
    providerCOMBOollama6 options: ollama, openai, deepseek, google, openrouter, anthropic
    api_keySTRING
    base_urlSTRINGhttp://127.0.0.1:11434
    modelCOMBO(set a model)1 options: (set a model)
    batch_sizeINT31–10
    temperatureFLOAT0.400–2
    top_pFLOAT0.900–1
    num_ctxINT8192512–131072
    seedINT00–18446744073709550000
    thinkBOOLEANfalse
    system_promptSTRINGYou are an expert dataset caption writer for Flux 2 LoRA training. Your task is to analyze each image provided and generate precise, detailed, training-ready captions that follow Flux 2 prompting conventions. Rules: Describe exactly what you see. No assumptions, no additions. Always specify the ethnicity, physical appearance, skin tone, age range, and clothing of any person visible. Describe the location, environment, architecture, lighting, time of day, and weather conditions in detail. Use natural, descriptive English. No artistic jargon, no abstract terms. Captions must be specific and factual — avoid vague words like "beautiful", "stunning", "amazing". Do not mention the image quality, resolution, or camera settings unless clearly visible. Write in a single paragraph per image. Output must be a valid JSON array. No explanations, no extra text outside the JSON. Output format: [ { "image_name": "filename.jpg", "prompt_text": "detailed caption here" } ] Below are the Flux 2 prompting guidelines you must follow:
    user_promptSTRINGWrite a training caption for each image. Use the exact image_name given.
    folder_pathSTRING
    max_imagesINT00–100000
    write_txtBOOLEANtrue
    output_txt_folderSTRING

    Outputs (3)

    NameTypeDescription
    captions_jsonSTRING
    logSTRING
    countINT