Nodes/Image Processing Suite for ComfyUI/Dataset Loader (Images + Captions)
ComfyUI Node

Dataset Loader (Images + Captions)

Dataset Loader — images and their captions, loaded as matching lists for training prep

By marcoc2·Created 2 years ago·Updated 5 months ago· 1
Dataset Loader (Images + Captions)
    • images
    • paths
    • filenames
    • captions
    directory
    target_width512
    target_height512
    image_load_cap0
    start_index0

    Training data needs two things per image: the pixels and the caption. DatasetLoader is the node that loads both together. Point it at a dataset directory and it returns four aligned lists - images, paths, filenames, and captions - which is precisely what you need when you're building a dataset-preview graph, spot-checking captions before a LoRA run, or shuffling data through a prep pipeline.

    The caption part is what makes it more than a folder loader. For every image it looks for a matching .txt file with the same base name in a captions subfolder - image_001.png pairs with captions/image_001.txt. That's the standard dataset layout used across the training ecosystem, so a folder that's already prepared for OneTrainer or similar will load here with zero reorganization. That matters: as the lora-training doc in our KB hammers home, caption quality is one of the biggest levers on training quality, and a node that lets you actually see what your captions say before you commit to a run is worth its weight.

    How it works

    It scans the directory with a priority search: root first, then original_dataset, then cropped_images subfolders - a nod to common dataset-prep folder structures where the cleaned set lives one level down. It sorts the files, applies your start_index skip and image_load_cap, and processes each one: the image gets centered onto a canvas of your target size (transparent canvas, so letterboxing stays as alpha), and the caption is read from the matching .txt file if it exists.

    The size handling mirrors the pack's other loaders: target_width/target_height of 0 means "inherit from the first image," and everything is centered rather than stretched so proportions survive.

    Inputs and outputs

    • directory - the dataset root. Raw string, no picker.
    • target_width / target_height - canvas size (0 = first image's size).
    • image_load_cap - 0 loads all, or cap to N for testing.
    • start_index - skip the first N.

    Outputs (all lists, index-aligned): images, paths, filenames, captions. Missing caption files yield empty strings rather than errors, so you can spot uncaptioned images easily.

    Installing it

    Part of the AnotherUtils pack:

    cd ComfyUI/custom_nodes
    git clone https://github.com/marcoc2/ComfyUI-AnotherUtils.git
    

    Restart ComfyUI, or install via ComfyUI Manager (search "AnotherUtils"). No extra dependencies or model downloads.

    Gotchas

    The caption lookup is strict: caption must be a .txt in a captions subfolder with the exact base name. If your folder stores captions inline in PNG metadata (the way FolderImageAndExtractPrompt reads them), this node won't find them - different tool for that job. Also, the transparency-padded canvas means images that aren't square get transparent borders, and if a downstream node ignores alpha you'll see black or checkerboard artifacts in those borders.

    Watch the caption encoding too - it reads UTF-8. If your captions were saved in another encoding, non-ASCII characters will come through garbled. And remember this is a prep and inspect tool, not the training loop itself; you're using it to verify your dataset lines up before you hand it to a trainer.

    CategoryAnotherUtils/loaders

    Inputs (5)

    NameTypeDefaultDescription
    directorySTRING
    target_widthINT5120–81920 = use first image width
    target_heightINT5120–81920 = use first image height
    image_load_capINT00–99990 = load all images
    start_indexINT00–9999Skip first N images

    Outputs (4)

    NameTypeDescription
    imagesIMAGE
    pathsSTRING
    filenamesSTRING
    captionsSTRING