ComfyUI Node

Save Dataset Item

Save dataset files with exact names — no _00001_ suffix, ever

By sintspiden·Created 6 months ago·Updated 6 months ago· 0
Save Dataset Item
  • image
    save_prefixoutput/item
    caption

    Here's the thing ComfyUI's default Save Image node does that quietly ruins dataset runs: it appends a counter to your filename. image_001 becomes image_001_00001_.png. Great for not overwriting your gens, catastrophic when you're trying to produce image_001.png plus image_001.txt in an exact layout your trainer expects to pair by stem.

    Save Dataset Item is the fix. It saves with exactly the name you give it - no counter, no dedupe, no surprises - and it's built to be the tail end of the same loop the pack's Load Dataset Item At Index starts. That's the entire pitch, and for dataset work it's the right one.

    How it works

    The save_prefix input is a path relative to ComfyUI/output/. Pass my_dataset/image_001 and you get ComfyUI/output/my_dataset/image_001.png - subdirectories are created on the fly, so you can batch-write a whole folder structure without pre-creating anything. Both payload inputs are optional: connect image and it saves a .png, connect caption and it saves a .txt, connect both and you get the pair. Connect neither and it raises "At least one of image or caption must be connected" - it won't silently write an empty file.

    Two details worth knowing:

    • The image is always saved as PNG. If your source was a JPG or WebP, it's re-encoded losslessly - no quality loss, but don't expect the original file format to survive.
    • Like every ComfyUI PNG, the saved file carries the workflow embedded as PNG text chunks (workflow + prompt). Drag it back onto the canvas later and the whole pipeline that made it comes back. That's the ecosystem's "the image is the project file" convention working in your favor - useful when a dataset sample looks wrong and you want to see exactly what produced it.

    The node also sanitizes the prefix (strips .. and stray slashes), so a bad value can't escape output/ and write somewhere it shouldn't. Small thing, but nice to see from a tiny pack.

    The inputs that matter

    • save_prefix - the output path, required, defaulting to output/item. This is what you'll actually set, usually by wiring the save_prefix output of Load Dataset Item At Index straight into it.
    • image (optional) - the pixels to write.
    • caption (optional) - the text. Note this one has forceInput enabled: it's a socket you must wire, not a text box you can type into. People get stuck on this - there's no widget, so if you want a static caption you need a string/primitive node feeding it.

    It has no outputs - it's an output node, one of those the engine always executes on a run. You wire the rest of your graph into it, and it's the last stop.

    Installation and the workflow

    Same pack, same story as its sibling: install via ComfyUI Manager (search "ComfyUI-DatasetGenerator") or

    cd ComfyUI/custom_nodes
    git clone https://github.com/sintspiden/ComfyUI-DatasetGenerator
    

    then restart. It shows up under the dataset category, and there are no dependencies beyond ComfyUI itself - no downloads, no models, nothing to break.

    The canonical loop: Load Dataset Item At Index → run your processing (Florence2 captioning, img2img, upscaling, whatever) → Save Dataset Item, threading save_prefix straight across. Set the loader's index to increment, queue once per dataset item, and you walk out with a tidy, correctly-named, correctly-paired dataset folder - exactly the shape LoRA trainers and a good captioning pass want. It's a small, low-key pack from a solo author, and this is the node that makes the whole thing click.

    Categorydataset

    Inputs (3)

    NameTypeDefaultDescription
    save_prefixSTRINGoutput/item
    imageoptIMAGE
    captionoptSTRING

    Outputs (0)

    No outputs