Nodes/CRT-Nodes/Image Loader Crawl Batch (CRT)
ComfyUI Node

Image Loader Crawl Batch (CRT)

Grab a deterministic window of images from a folder, seed by seed

By PGCRT·Created 2 years ago·Updated a day ago· 132
Image Loader Crawl Batch (CRT)
    • images
    • file_names
    • file_paths
    • batch_count
    • total_images
    • sidecar_txt_prompt
    folder_path
    batch_count1
    seed0
    megapixels1.00
    No resizefalse
    crawl_subfoldersfalse
    remove_extensionfalse
    print_indextrue

    Loading one image is easy; crawling through a folder a batch at a time, deterministically, so that seed 5 gives you a different window than seed 3 - that's the annoying part of dataset-driven rendering. Image Loader Crawl Batch (CRT) does exactly that, and it's a quiet workhorse of the CRT pack's batch workflow.

    The name says it: it "crawls" a folder and loads batch_count images at once. The trick is how it picks them. The starting image is (seed × batch_count) % total_images, and it loads batch_count consecutive images from there, wrapping around the folder when it hits the end. Change the seed, change the window. Same seed, same window, every time - which is exactly what you want when you're pairing image batches with seeds for reproducible renders.

    How it works

    Point it at a folder, and it lists the images (natural-sorted, so img2.png sorts before img10.png - the kind of thing naive sort gets wrong), then:

    • loads the window of images at batch_count resolution,
    • resizes each to your target megapixels with Lanczos, preserving aspect ratio,
    • and if the batch has mixed aspect ratios, center-crops everything to the average aspect ratio so they stack into one tensor.

    Outputs are images (the batch tensor), file_names and file_paths (newline-joined strings, one per image - handy for saving sidecar metadata or naming outputs), batch_count, and total_images (so downstream nodes know how many windows exist). It can also recurse into subfolders via crawl_subfolders, and remove_extension strips file extensions from the returned names.

    There's a genuinely thoughtful bit under the hood: it prefetches the next seed's window in a background thread while the current one is being processed, so your resize/load work overlaps with GPU inference instead of stalling the pipeline. It keeps only one future batch cached, so memory stays bounded on long runs.

    The inputs that matter

    • folder_path - the directory. Empty or missing → a blank batch and an error string in file_names, so watch for that.
    • batch_count - images per load (1–128).
    • seed - the window selector. This is the knob you'll sweep.
    • megapixels - target resolution; 1.0 is a good default for most work.
    • print_index - logs each selected file and index to the console. Leave it on while debugging, off for clean logs.

    Where it fits

    It's the image side of the CRT batch loop. Load a window of images → feed them to CRT's KSampler Batch (which encodes them and samples variations per item) → sweep the seed and every run picks a fresh set of images with fresh prompts. If you're rendering through a Z-Image or Flux batch pipeline, this is the loader that keeps the folder→latent pipeline automatic.

    Install and gotchas

    Pack install, same as everything else in CRT-Nodes:

    cd ComfyUI/custom_nodes
    git clone https://github.com/PGCRT/CRT-Nodes.git
    pip install -r requirements.txt
    

    or ComfyUI Manager → "CRT-Nodes". It honors sidecar .txt files (same name, .txt extension) - worth knowing if your dataset carries prompt files beside images. Real gotchas: mixed aspect ratios get center-cropped, not padded, so wildly different ARs in one folder mean content loss at the edges - keep batches roughly uniform. And the seed math means a batch with total_images smaller than your window just wraps and repeats, so set batch_count below the folder size unless repetition is the plan.

    CategoryCRT/Load

    Inputs (8)

    NameTypeDefaultDescription
    folder_pathSTRING
    batch_countINT11–128Number of images to load. Window starts at seed × batch_count and wraps around the folder.
    seedINT00–18446744073709550000Selects the starting image: index = (seed × batch_count) % total_images.
    megapixelsFLOAT1.000.1–16Target resolution in megapixels. Ignored when No resize is enabled.
    No resizeBOOLEANfalseBypass resampling. Mixed-size batches are center-padded to the largest image.
    crawl_subfoldersBOOLEANfalse
    remove_extensionBOOLEANfalse
    print_indexBOOLEANtruePrint each selected file index and name to the console.

    Outputs (6)

    NameTypeDescription
    imagesIMAGE
    file_namesSTRING
    file_pathsSTRING
    batch_countINT
    total_imagesINT
    sidecar_txt_promptSTRING