Nodes/ComfyUI-DatasetGenerator/Load Dataset Item At Index
ComfyUI Node

Load Dataset Item At Index

Feed a whole folder through ComfyUI, one image at a time

By sintspiden·Created 6 months ago·Updated 6 months ago· 0
Load Dataset Item At Index
    • image
    • caption
    • save_prefix
    folder
    index0

    The pack is called "DatasetGenerator," but let's be clear about one thing up front: this node doesn't generate a thing. What it does is arguably more useful - it turns a folder of image + caption pairs into something a ComfyUI workflow can chew through one item at a time. If you've ever tried to caption 200 images with Florence2 or JoyCaption and ended up manually dragging files into Load Image on repeat, you know exactly why that's worth having.

    This is pure plumbing, the unglamorous kind that sits between your data and your pixels. The control_after_generate mechanic here is the whole game, so it's worth getting right.

    How it works

    The node reads a subfolder of ComfyUI/input/ and treats the .txt caption files as the canonical list of items - it's the captions, not the images, that define your dataset, and they're sorted alphabetically. For each caption file it looks up the matching image by filename stem: photo.txt pairs with photo.png, photo.jpg, .jpeg, or .webp. Then it hands you three things:

    • image - the image as a tensor, ready to wire into your generation graph
    • caption - the text from the .txt file (whitespace-stripped)
    • save_prefix - a folder/stem string that's built to be fed straight into the pack's sibling, Save Dataset Item

    That third output is the clever bit. Because the node knows exactly which item you loaded, it can hand you the exact filename you should save under. The round trip is deliberate: Load in, process, Save out with the same stem, and your folder stays cleanly paired.

    The inputs that matter

    Only two, and one of them is a dropdown:

    • folder - a subfolder of ComfyUI/input/, populated from what's actually on disk. Drop your dataset in ComfyUI/input/my_dataset/ and it shows up in the list.
    • index - an integer from 0 to 999999 with a control_after_generate widget underneath. Set it to increment, leave it at 0, and each run advances to the next item automatically.

    That second input is the whole trick. Queue as many jobs as you have items, set the control to increment, and the graph walks your dataset start to finish while you go make coffee. If you name files with zero-padding (image_001, image_002 …), the alphabetical sort keeps them in the order you expect.

    Installation

    Grab the pack via ComfyUI Manager (search "ComfyUI-DatasetGenerator") or:

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

    Restart ComfyUI and the node appears under the dataset category. Good news for a change: there are no extra dependencies - no torch extension, no model download, nothing. The whole pack is plain Python over what ComfyUI already ships, so installation is genuinely painless.

    Where people trip

    The node is strict about its contract, and it tells you exactly why when it fails:

    • "No .txt caption files found" - your folder has images but no captions. This node's job is pairing, so captions are mandatory. If you're re-rendering images without text, this is the wrong tool; caption-first is the whole design.
    • "Index out of range" - you queued more jobs than items. Queue your item count, not a round number.
    • "No matching image found" - a caption file exists but no image shares its stem. The pair-by-stem rule means photo.txt with no photo.* image is an error, not a silent skip.

    One thing that surprises people: the folder dropdown is built from disk when the node loads, so a brand-new folder won't appear until you refresh or restart. Not a bug - just a refresh. Minor, but it's the kind of thing that eats ten minutes.

    It's a small, no-reputation pack from a solo author, and honestly that's fine - the source is clean, it does exactly one thing, and for batch-captioning or batch-cleaning an existing dataset toward a LoRA (where curation is 80% of the outcome), it removes the most tedious part of the loop.

    Categorydataset

    Inputs (2)

    NameTypeDefaultDescription
    folderCOMBO1 options: 3d
    indexINT00–999999

    Outputs (3)

    NameTypeDescription
    imageIMAGE
    captionSTRING
    save_prefixSTRING