Load Random Image 🦬
Grab a random image (or ten) from a folder and feed the batch into your graph
- image
- mask
- image_path
Load Random Image is the utility that makes img2img variation loops actually work. Point it at a folder, it picks a random image (or a seeded batch), loads it as an IMAGE tensor, and hands you the path it chose. If you've ever built a workflow that should run over a dataset but had to hand-swap a Load Image node each time, this is the node you were missing.
It's from Sokes Nodes 🦬, a grab-bag pack that's clearly built by someone who runs image workflows for a living - the loader and its sibling Image Picker cover both "random every run" and "pick one deliberately."
How it works
Under the hood it globs the folder for image files, validates each one (corrupt files get skipped rather than crashing your run), then selects based on your inputs. Selection is seedable: same folder + same seed = same pick, which makes it reproducible for testing. If sort is on, it does a natural sort (so img2 sorts before img10 - nice) and then uses the seed as an offset into the list. With sorting off, it shuffles and takes the first N.
Three inputs do the heavy lifting:
- folder_path - multiline, so you can put multiple paths, one per line, and it'll search them all. You can also use
*wildcards. - n_images - how many to load as a batch. The sneaky special value: -1 means "grab the last image", after a natural sort - handy for "most recent render in this folder."
- seed - reproducibility for the random pick.
Outputs are image (IMAGE batch), mask (MASK, from the alpha channel if the image has one, otherwise all-ones), and image_path (a LIST of the actual file paths it loaded).
Install
Standard Sokes Nodes 🦬 install: ComfyUI Manager → search "ComfyUI Sokes Nodes" → Install → restart.
cd ComfyUI/custom_nodes
git clone https://github.com/m-sokes/ComfyUI-Sokes-Nodes.git
pip install -r requirements.txt
The Pillow dependency in requirements.txt does the image loading; nothing heavy.
Gotchas
Where people get burned:
- Mixed-size batches. If the folder has images of different dimensions, the node warns but loads them anyway, and downstream nodes (VAE encode, img2img) will choke on a mismatched batch. Keep your source folder uniform, or it bites.
export_with_alphaonly matters for RGBA files. If no image in the selection actually has an alpha channel, it quietly outputs RGB and prints a note. It's not broken - there's just no alpha to export.- Empty or bad folder = a default black 64×64 image, not an error. That's either convenient or maddening depending on how much you trust your folder path. Double-check the path if everything comes out black.
The sweet spot for this node: batch img2img style-consistency sweeps over a reference set, or feeding random source images into an IP-Adapter / ControlNet pipeline to stress-test a prompt. Set n_images to the count you want, wire image into your sampler, and let the seed do the rest.
Inputs (7)
| Name | Type | Default | Description |
|---|---|---|---|
| folder_path | STRING | — | |
| filename_optional | STRING | — | |
| search_subfolders | BOOLEAN | false | — |
| n_images | INT | 1-1–100 | — |
| seed | INT | 00–18446744073709550000 | — |
| sort | BOOLEAN | false | — |
| export_with_alpha | BOOLEAN | false | — |
Outputs (3)
| Name | Type | Description |
|---|---|---|
| image | IMAGE | — |
| mask | MASK | — |
| image_path | LIST | — |