Nodes/comfyui_AcademiaSD/๐Ÿ“‚ Batch Image Loader (Dataset)
ComfyUI Node

๐Ÿ“‚ Batch Image Loader (Dataset)

A batch image loader that speaks dataset โ€” index in, image and path out

By AcademiaSDยทCreated about a year agoยทUpdated 4 days agoยท 76
๐Ÿ“‚ Batch Image Loader (Dataset)
    • image
    • mask
    • image_path
    • filename_text
    โ—„folder_pathC:\Ruta\A\Tus\Imagenesโ–บ
    โ—„image_index0โ–บ
    โ—„filename_filterโ–บ

    Most ComfyUI image loaders make you pick a file by name. For dataset work - captioning folders, building LoRA training sets, batch-regenerating a directory - you don't want to name anything. You want to say "give me image 47" and move on. That's this node's whole job: you point it at a folder and feed it an index, and it hands back the image, plus the path and filename you'll need to keep captions in sync.

    How it works

    Give it a folder_path and an image_index, and it scans the directory for common image extensions (jpg, png, webp, bmp, tiff), sorts them alphabetically, and loads the one at your index. Two details make it feel dataset-native:

    • Circular indexing. The index is taken modulo the file count, so if you have 100 images and feed it 100, it wraps to 0 instead of erroring. Drive it from a loop counter and it can spin forever without breaking.
    • The index is not a filename. It's the position in the sorted file list. Rename your folder's files with padded numbers (0001.jpg, 0002.jpg...) and position matches intent.

    It also outputs a mask from the image's alpha channel (if it has one; otherwise a blank), which is handy for datasets with transparency.

    The outputs you'll actually wire

    • image (IMAGE) - goes to your sampler, captioner, or whatever's processing the batch.
    • image_path (STRING) - the absolute path. This is the one that matters for the pack's Save Dataset Caption (.txt) node, which uses it to drop a sidecar .txt next to the source image.
    • filename_text (STRING) - just the filename, no path.
    • mask (MASK) - alpha channel, or empty.

    The optional filename_filter string only matches files whose name contains it - useful for loading only a subset of a folder.

    Install

    Standard pack install: ComfyUI Manager โ†’ search "AcademiaSD", or git clone https://github.com/AcademiaSD/comfyui_AcademiaSD into custom_nodes/, restart. No extra dependencies - it's PIL and torch, both already in ComfyUI.

    Where people get burned

    The default folder_path value is literally C:\Ruta\A\Tus\Imagenes (Spanish for "path to your images") - a leftover the author never cleaned up. Leave it and the node doesn't crash; it prints a friendly message and returns a dummy 64x64 black image with a placeholder path. Which sounds harmless and is actually a great way to silently caption 400 black squares. Check that you've actually set the folder before you run a whole batch.

    Also worth knowing: the sort is plain alphabetical string sort, so image10.jpg sorts before image2.jpg. Pad your numbers. If you feed it an index and the folder has a file that's not an image, it's simply skipped from the count - the modulo math still lines up, but your mental model of "image 47" can drift if the folder has stray files.

    CategoryAcademiaSD/Dataset

    Inputs (3)

    NameTypeDefaultDescription
    folder_pathSTRINGC:\Ruta\A\Tus\Imagenesโ€”
    image_indexINT0โ€”
    filename_filteroptSTRINGโ€”

    Outputs (4)

    NameTypeDescription
    imageIMAGEโ€”
    maskMASKโ€”
    image_pathSTRINGโ€”
    filename_textSTRINGโ€”