Nodes/comfyui-fvmtools/Batch Load Image
ComfyUI Node

Batch Load Image

The 'next file in the folder' button ComfyUI never shipped

By ping1979ping·Created 7 months ago·Updated 5 days ago· 3
Batch Load Image
    • image
    • mask
    • source_path
    • pass_dir
    • fail_dir
    • filename
    • index
    • total
    • progress
    ◄directory►
    ◄pass_subdirkeep►
    ◄fail_subdirreject►
    ◄on_finishstop►
    ◄sort_byname►
    ◄include_subdirsfalse►
    ◄create_dirstrue►
    ◄trackerdefault►

    Stock ComfyUI gives you LoadImage, which loads one file you picked by hand, and a batch loader that loads everything into VRAM at once. Neither is what you want when you have 400 renders to triage. Batch Load Image is the missing third option: point it at a folder, queue the graph with a run count of 500, and each queue run hands out the next picture in line and remembers where it got to.

    What it actually does

    Every run, the node picks the next image file from directory, loads it the way LoadImage does - EXIF rotation applied, extra frames ignored, alpha channel inverted into the mask output, an all-zero mask (nothing masked) when the file has no alpha - and pushes it down the graph. Then it writes that filename into its progress list. When the folder runs out, it stops the run the same way Cancel does: quietly, no red graph.

    The important design decision is in the source, and it's the one thing you'll thank the author for later. Progress is stored as a set of finished filenames in .fvm_batch_state.json inside the source folder, not as a counter. That matters the moment Batch Save Image is set to move - the folder is shrinking under the loader's feet, and a counter-based loader would skip every other picture. Because it's a filename list, sorting is resumable across ComfyUI restarts too.

    Inputs that matter

    • directory - the folder to walk. Non-image files are ignored.
    • pass_subdir / fail_subdir (defaults keep / reject) - two subfolder names the node turns into absolute paths and hands downstream as pass_dir and fail_dir. Type the name once here and the rest of the graph inherits it.
    • tracker (default default) - the name of the progress marker. Give two loaders different tracker names and they can walk the same folder independently.
    • on_finish - stop ends the run when everything has been handed out; loop forgets the progress and starts over. sort_by picks name or modified order, include_subdirs walks subfolders (dot-folders and the pass/fail targets are always skipped, so sorted pictures never come back in - elegant, that), and create_dirs makes the two output folders for you.

    Outputs

    image and mask are the picture; source_path is the file it came from (wire it into Batch Save Image for move/copy, otherwise that node would have no idea which file to touch); filename, index, total and progress are for filenames, logs and your own sanity; pass_dir and fail_dir go straight into the router or saver. The node also shows a progress bar with absolute position and percentage, counted straight off disk, so it's populated before the first run. There's a Reset progress button next to it. Deleting .fvm_batch_state.json by hand does the same thing.

    A typical wiring, from the pack's own guide: loader image → Reality Check and/or Person Selector → Batch Router → Batch Save Image, with the loader's source_path and pass_dir/fail_dir feeding the saver directly.

    Install

    Standard custom-node install, and this one needs nothing extra:

    cd ComfyUI/custom_nodes
    git clone https://github.com/ping1979ping/comfyui-FVMtools
    

    Restart ComfyUI. ComfyUI Manager works too - search the pack title, comfyui-fvmtools. The batch nodes use only PIL, numpy and torch, all of which ComfyUI already ships; the pack's requirements.txt (insightface, onnxruntime-gpu, opencv-python) is for the face tools, not this one.

    Where people get burned

    The loader does not move or rename anything - it only reads. Until you wire a saver, running it twice over the same folder just shows you the same pictures again.

    loop sounds like an infinite animation loop and isn't. It has nothing to loop over once a move-mode saver has emptied the folder; the run just ends. Use it for a folder you keep refilling, not as a substitute for a real loop construct.

    If a picture keeps reappearing, you're probably pointing directory one level too high without include_subdirs, or you queued with a run count lower than the folder size and mistook a partial pass for a full one. Queue generously - 500 runs on a 400-image folder costs you nothing, since the node interrupts itself at the end.

    CategoryFVM Tools/Batch

    Inputs (8)

    NameTypeDefaultDescription
    directorySTRINGFolder to walk through. One image per queue run.
    pass_subdirSTRINGkeepSubfolder of the source directory for pictures that pass. Handed downstream as an absolute path.
    fail_subdirSTRINGrejectSubfolder for pictures that fail.
    on_finishCOMBOstopstop: end the run once every image has been handed out. loop: forget the progress and start over.
    sort_byCOMBOname2 options: name, modified
    include_subdirsBOOLEANfalseWalk subfolders too. The pass/reject folders and any other dot-folders are always skipped.
    create_dirsBOOLEANtrueCreate the pass/reject subfolders if missing.
    trackerSTRINGdefaultName of this run's progress marker. Use different names to walk one folder several times independently.

    Outputs (9)

    NameTypeDescription
    imageIMAGE—
    maskMASK—
    source_pathSTRING—
    pass_dirSTRING—
    fail_dirSTRING—
    filenameSTRING—
    indexINT—
    totalINT—
    progressSTRING—