Nodes//Nougan Save Caption (Match Image/Video Name) πŸ’Ύ
ComfyUI Node

Nougan Save Caption (Match Image/Video Name) πŸ’Ύ

The node that gets .txt files into your dataset folder

By WinnouganΒ·Created 3 months agoΒ·Updated about 16 hours agoΒ· 10
Nougan Save Caption (Match Image/Video Name) πŸ’Ύ
    • saved_path
    β—„textβ€”β–Ί
    β—„image_pathβ€”β–Ί
    β—„save_locationβ–Ύβ–Ί
    β—„custom_folderβ–Ί
    β—„extensiontxtβ–Ί
    β—„overwritetrueβ–Ί

    Captioning a dataset is a solved problem right up until the last step. JoyCaption writes a lovely paragraph, WD14 spits out a wall of booru tags, and then you're copy-pasting each result into a new text file named after its image, because that's what every trainer expects to find: 044.jpeg sitting next to 044.txt.

    That last step is what this node does, and it's the step people ask about - "if I want to use JoyCaption, how do I quickly get the .txt files in my dataset folder?" The usual answer is a batch script or a standalone tagger app. If you already caption in ComfyUI, this pair is the zero-glue version.

    How it works

    It's small, which is why it's reliable. You give it text and a path. It takes the basename of that path, drops the extension, and writes your text to <same name>.<extension> - next to the image, or in a folder you name. If the destination folder doesn't exist, it creates it. The text is whitespace-stripped and written as UTF-8 with no trailing newline, so the file is exactly your caption and nothing else.

    The important design choice: the filename comes from the same path the loader produced in that same run, so caption and filename can never drift out of sync - the failure mode of every "generate captions, rename them later" pipeline. The node is also an always-run output node, so ComfyUI's cache never skips it: the graph may decide the sampler doesn't need to re-run, but the caption still gets written.

    text and image_path are both forceInput - sockets, not text boxes. You can't type a static caption into this node. To test your wiring before pointing a VLM at the folder, feed text from a primitive string or the pack's own Text Box node.

    The inputs

    • text - the caption. Any node that outputs a STRING works: JoyCaption, WD14, Florence-2, or ComfyUI's built-in text-generation node. The pack ships a ready-made graph for exactly this at workflow/Winnougan_Captioner_WF.json.
    • image_path - wire the path output of Nougan Load Image Batch From Folder here. Not filename. path carries the directory; filename is just the stem.
    • save_location - next to image writes into the image's own folder (what a trainer dataset wants); custom folder writes to custom_folder instead.
    • custom_folder - only read when save_location is custom folder. Created if missing. Left empty while set to custom folder is a hard error, not a silent no-op.
    • extension - defaults to txt. A leading dot is fine, so .caption does what you'd expect.
    • overwrite - overwrite existing replaces files; skip if exists leaves existing captions alone.

    One output, saved_path (STRING): the path of the file that was written, or the one that was skipped. It also shows up on the node.

    The workflow you're actually building

    Wire it as a loop and you get in-graph dataset captioning: loader β†’ captioner β†’ this node, with the loader's path going into image_path and the captioner's text going into text. One Run, whole folder. That's the plumbing that turns "you can caption images in ComfyUI" from something people mention in comment threads into something you leave running overnight.

    The captions themselves still decide whether your LoRA is good. Auto-captioning is a first pass, not a finished dataset - VLMs reliably botch multi-subject attribution and invent small details, and manual captioning remains the gold standard for a small set. What this node buys you is the ability to re-run the whole pass after you fix your prompt, instead of hand-editing forty files.

    Install

    cd ComfyUI/custom_nodes
    git clone https://github.com/Winnougan/Nougan_Nodes
    # restart ComfyUI
    

    Or search Nougan in ComfyUI Manager. MIT-licensed, and these two dataset nodes declare no extra dependencies - a few lines of Python and Pillow, nothing to download. Boot should print [Nougan] βœ… Folder Batch Loader + Save Caption loaded (2 nodes). The pack guards each family in its own try/except, so a broken heavier family can't take this one down with it.

    Where it bites

    Captions come out named wrong. image_path isn't connected to the loader's path output. Most common mistake with the pair, and the reason the docs bold it.

    You re-ran it and the captions didn't change. overwrite is on skip if exists. The node still returns saved_path and looks perfectly happy - the "Skipped (already exists)" line only appears in the terminal. Check the console before assuming the run did what you wanted.

    save_location is 'custom folder' but custom_folder is empty. Set the folder or switch back to next to image. While you're testing a new caption prompt, custom folder is the right choice anyway: it keeps junk captions out of the dataset you're about to train on.

    One image produced no file. The captioner errored upstream, which stops the chain before the saver runs - that's the loader's auto-run quitting for this session, by design. Fix it and re-run from the current index.

    Categoryimage/batch

    Inputs (6)

    NameTypeDefaultDescription
    textSTRINGβ€”
    image_pathSTRINGβ€”
    save_locationCOMBO2 options: next to image, custom folder
    custom_folderSTRINGβ€”
    extensionSTRINGtxtβ€”
    overwriteBOOLEANtrueβ€”

    Outputs (1)

    NameTypeDescription
    saved_pathSTRINGβ€”