Load Dataset Item At Index
Feed a whole folder through ComfyUI, one image at a time
- image
- caption
- save_prefix
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 graphcaption- the text from the.txtfile (whitespace-stripped)save_prefix- afolder/stemstring 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 ofComfyUI/input/, populated from what's actually on disk. Drop your dataset inComfyUI/input/my_dataset/and it shows up in the list.index- an integer from 0 to 999999 with acontrol_after_generatewidget underneath. Set it toincrement, 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.txtwith nophoto.*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.
Inputs (2)
| Name | Type | Default | Description |
|---|---|---|---|
| folder | COMBO | 1 options: 3d | |
| index | INT | 00–999999 | — |
Outputs (3)
| Name | Type | Description |
|---|---|---|
| image | IMAGE | — |
| caption | STRING | — |
| save_prefix | STRING | — |