Load Random Images From Folder (Soze)
Grab N Random Images From a Folder as One Batch (Seedable, So Your Grids Actually Reproduce)
- Image_Batch
- Mask_Batch
- Loaded_Count
- Filenames
- status
If you've ever wanted "give me a fresh random reference image every time this workflow runs" - or worse, "give me ten of them" - you've been hand-picking files like a caveman. Load Random Images From Folder is the civilized version: point it at a folder, tell it how many images you want, and it returns them as a single IMAGE batch with a matching MASK batch, ready for img2img, ControlNet conditioning, or whatever you're batching over.
The mechanism is pleasantly boring. It scans the folder for common image extensions (jpg, png, webp, bmp, gif, tiff...), picks N of them, and stacks them into one tensor. Crucially, it resizes every picked image to match the first one's dimensions so torch.cat doesn't explode on mixed sizes - the same convention ComfyUI's own batch loader uses, and the thing that makes this node actually usable in real pipelines instead of crashing the moment your folder has one landscape and one portrait in it.
The inputs that matter:
input_folder- absolute or relative path. Relative is relative to where you launch ComfyUI, which trips people up; when in doubt, use the absolute path.image_count- how many to pull, 1 to 1000.seed- here's the clever bit.0means nondeterministic: every run picks fresh images. Any other value seeds the RNG, so the same run picks the same images. The node also respects this in caching - with a real seed it's cacheable, with seed 0 it forces re-execution every prompt. That's exactly the behavior you want.allow_repeats- off by default, which means if you ask for more images than the folder holds, you get fewer back (with a note instatus), not duplicates. Turn it on to allow the same file twice.
Outputs: Image_Batch and Mask_Batch (one mask per image, derived from each file's alpha channel - images without alpha get a black/zero mask), plus Loaded_Count, a newline-joined Filenames string so you can see exactly what got picked, and a status string.
What it's for
Honestly, the killer use case is variety: random references feeding an img2img or a ControlNet pass so each generation is a different starting point, or random conditioning for batch testing. Combined with a real seed, you get reproducible random picks - set seed 1234, get images A, B, C; keep the seed, get A, B, C again. That's the difference between "random" and "random that I can debug."
Install
Standard Soze-pack install:
cd ComfyUI/custom_nodes
git clone https://github.com/SozeInc/ComfyUI_Soze.git
pip install -r ComfyUI_Soze/requirements.txt
Or grab ComfyUI Soze via ComfyUI Manager. No models, no API keys - this node is pure local file I/O.
Troubleshooting
The two things that actually bite: a typo'd or missing folder raises a clean FileNotFoundError with a status message saying exactly that, and a folder with zero matching image files does the same. Corrupt files get skipped and logged, and if every pick fails to load you get a hard error rather than a silent empty batch. If your masks all come back black, your images just don't have alpha channels - that's normal, not a bug.
Inputs (4)
| Name | Type | Default | Description |
|---|---|---|---|
| input_folder | STRING | Absolute or relative folder path. | |
| image_count | INT | 11–1000 | How many images to randomly select. |
| seedopt | INT | 00–18446744073709550000 | 0 = nondeterministic; any other value seeds the RNG for reproducible picks. |
| allow_repeatsopt | BOOLEAN | false | If True, the same image may be picked more than once when image_count exceeds the folder size. |
Outputs (5)
| Name | Type | Description |
|---|---|---|
| Image_Batch | IMAGE | — |
| Mask_Batch | MASK | — |
| Loaded_Count | INT | — |
| Filenames | STRING | — |
| status | STRING | — |