Nodes/Sage Utils/Load Dataset From Folder
ComfyUI Node

Load Dataset From Folder

Turn a folder of images and captions into a batch ComfyUI can chew on

By arcum42·Created 2 years ago·Updated 28 days ago· 33
Load Dataset From Folder
    • images
    • filenames
    • captions
    dataset_path
    prefix
    suffix
    separator

    Most ComfyUI users never need a dataset loader. They're generating, not training. But the moment you want to evaluate something over a batch - test a LoRA across a folder of subjects, preview what an upscale or a style transfer does to a set of images, or prep data for a training run - you discover that loading images one at a time and captions by hand is misery. Load Dataset From Folder is the node that turns a folder of images plus their .txt caption files into three batch outputs, in one shot.

    It's the "training" category node in Sage Utils, but don't let that scare you off. Its real usefulness is any workflow that wants a whole dataset in the graph at once.

    How it works

    Point dataset_path at a folder. The node scans for .png, .jpg, .jpeg, and .webp images, and for each one looks for a same-named .txt caption file (your photo.png pairs with photo.txt). It then:

    • batches the images into one images output,
    • gives you the matching filenames,
    • and collects the captions into a captions output.

    The optional prefix and suffix inputs let you modify every caption as it loads - the classic use is prefixing your LoRA trigger word, so prefix = "mychar" turns every caption into "mychar a woman walking…" without you editing a hundred files. A separator (default a space) controls the glue between prefix/suffix and the caption text.

    It also validates before running: if the path isn't a directory, or the folder has no supported images, it tells you instead of silently failing. That's a thoughtful touch for a node you'll point at filesystems.

    The inputs that matter

    • dataset_path - the folder. The only required input.
    • prefix / suffix - added to every caption (default empty).
    • separator - the join string, default " ".

    Outputs: images (IMAGE batch), filenames (STRING), captions (STRING).

    Wiring it up

    The natural pattern: images goes to a batch-processing branch (an upscaler, a sampler for img2img previews), while captions feeds a text display or a caption-relevant node so you can see what the graph "knows" about each image. For training-adjacent work, this is the same folder layout the major trainers expect - images plus matching caption files - so what you load here is directly comparable to a dataset you'd hand to ai-toolkit or kohya.

    Installing

    It ships in Sage Utils (training nodes are enabled by default in this pack):

    cd ComfyUI/custom_nodes
    git clone https://github.com/arcum42/ComfyUI_SageUtils.git
    cd ComfyUI_SageUtils && pip install -r requirements.txt
    

    Restart ComfyUI, or use ComfyUI Manager and search "Sage Utils."

    Where people trip

    Caption pairing is the classic gotcha: the node looks for a .txt file with the same base name as the image. photo.pngphoto.txt. If your captions are named captions.txt (one giant file) or stored in a subfolder, they won't match - this expects one caption file per image. Also, keep the folder to supported image extensions; stray .gif or .heic files just get skipped, which is usually what you want. And a reminder from the training world: caption quality is the whole game, so the prefix/suffix inputs are worth using deliberately rather than as an afterthought.

    CategorySage Utils/train

    Inputs (4)

    NameTypeDefaultDescription
    dataset_pathSTRINGPath to the folder containing image files and optional caption text files.
    prefixoptSTRINGOptional text prefix to prepend to each caption.
    suffixoptSTRINGOptional text suffix to append to each caption.
    separatoroptSTRING Separator used when concatenating prefix/suffix with caption text.

    Outputs (3)

    NameTypeDescription
    imagesIMAGEOutput value for images.
    filenamesSTRINGOutput value for filenames.
    captionsSTRINGOutput value for captions.