Nodes/comfyui_AcademiaSD/๐Ÿ’พ Save Dataset Caption (.txt)
ComfyUI Node

๐Ÿ’พ Save Dataset Caption (.txt)

Write captions next to your training images, automatically

By AcademiaSDยทCreated about a year agoยทUpdated 4 days agoยท 76
๐Ÿ’พ Save Dataset Caption (.txt)
    • final_saved_text
    โ—„generated_captionโ€”โ–บ
    โ—„image_pathโ€”โ–บ
    โ—„extra_texttrigger_wordโ–บ
    โ—„text_positionStart (Prefix)โ–บ
    โ—„separator, โ–บ

    LoRA training runs on sidecar .txt files - one caption per image, same folder, same base name as the image. The tedious part isn't writing the captions, it's making sure the file lands exactly where the trainer expects it, with your trigger word in exactly the right place. This node is the last step of that pipeline: feed it a caption and an image path, and it writes the .txt file next to the image, with your trigger word tacked on as a prefix or suffix.

    How it works

    The design intent is a four-node chain: AcademiaSD VLModel (Down)Loader loads a vision model, a captioner generates the description, Batch Image Loader (Dataset) provides the image_path, and this node saves the result. It takes the generated_caption, optionally prepends or appends extra_text (your trigger word) separated by separator (default ", "), and writes the final string to image_path with the extension swapped to .txt. So C:\dataset\0001.jpg gets C:\dataset\0001.txt.

    That same final string is also returned as final_saved_text, so you can preview what hit disk without opening a text editor. And text_position ("Start (Prefix)" or "End (Suffix)") plus separator let you match whatever caption convention your trainer or dataset tooling expects - some setups want the trigger first, some last.

    The inputs that matter

    • generated_caption - the caption text, typically from a captioner node (the pack's own LLM Vision or a WD14 tagger).
    • image_path - from the batch loader; this decides where the .txt lands.
    • extra_text - your trigger word (defaults to the placeholder "trigger_word" - change it).
    • text_position and separator - placement and glue.

    Install

    Pack install as usual: ComfyUI Manager โ†’ "AcademiaSD", or git clone https://github.com/AcademiaSD/comfyui_AcademiaSD, restart. No extra dependencies.

    The traps

    The extra_text default is literally the string trigger_word, which is a placeholder the author left in. Run a batch without changing it and every caption file starts with "trigger_word, " - an easy way to pollute a whole dataset with one queue. Set it to your real trigger before running.

    Also: the node only writes when image_path exists on disk - if the batch loader's path is stale or the file was moved, it prints an error and returns the text without saving. Silent-ish, so check the console on your first batch. One more dataset-era tip worth remembering from the training playbook: caption what you want to vary, leave what should be fixed undescribed. This node handles the mechanics; the captioning strategy is still on you.

    CategoryAcademiaSD/Dataset

    Inputs (5)

    NameTypeDefaultDescription
    generated_captionSTRINGโ€”
    image_pathSTRINGโ€”
    extra_textSTRINGtrigger_wordโ€”
    text_positionCOMBOStart (Prefix)2 options: Start (Prefix), End (Suffix)
    separatorSTRING, โ€”

    Outputs (1)

    NameTypeDescription
    final_saved_textSTRINGโ€”