随机图片路径
Random image plus its caption, straight from a folder
- image
- mask
- text_content
RandomImagePathNode is the workhorse of the Mango Random pack. You give it a folder, it picks an image from it, loads it into an IMAGE tensor, and - this is the useful part - also loads a matching mask and any sidecar text file that shares the image's filename. That makes it a one-stop node for pulling random image + caption pairs out of a dataset, which is a surprisingly common need in style-reference and fine-tuning workflows.
It filters to real image extensions - .jpg, .jpeg, .png, .bmp, .tiff, .webp - and it recurses through subfolders. Then two modes, labeled in Chinese like the whole pack: 完全随机 (fully random) or 顺序循环 (sequential cycle). The cycle mode is the smarter one here: it sorts files with a natural sort key, so img2.png comes after img10.png instead of after img19.png, and walks them in order, wrapping around. Great for chewing through a folder in a sensible sequence.
Inputs and outputs
- directory_path - required, a real absolute path. Not a valid directory →
NotADirectoryError; no image files inside →FileNotFoundError. - sort_mode and seed - the mode dropdown and an INT seed. Here's the gotcha the source exposes: in random mode the seed is ignored. The code calls
random.choice(files)without ever seeding, unlike the pack's other nodes. Don't rely on the seed to reproduce a pick from this node - it won't. - image (IMAGE) - the loaded picture, converted to RGB floats, EXIF-rotation applied automatically.
- mask (MASK) - the alpha channel for PNGs with transparency; for everything else, a solid white mask. So RGBA images give you a real mask, JPGs give you a no-op one.
- text_content (STRING) - the contents of a same-named
.txtsidecar (photo.png→photo.txt). Missing file → the literal stringNo corresponding text file found.
How to install
Standard pack. ComfyUI Manager: search "Mango Random Nodes", Install, restart. Or:
cd ComfyUI/custom_nodes
git clone https://github.com/mango-rgb/ComfyUI-Mango-Random-node
then restart. No model files. This node does pull in real dependencies though: it imports PIL and numpy for image loading, which any ComfyUI install already has.
Common issues
Beyond the ignored-seed quirk, the usual suspects: point it at a curated folder or you'll be walking a giant tree on every run (it recurses). The mask output is white for opaque images, so don't assume a mask means transparency. And the text sidecar is a convention, not magic - if you want captions, the .txt files have to exist and match the image basenames.
It's the node in this pack you'd actually build a dataset-browsing workflow around. One node, three outputs - image, mask, caption - and you're sampling a folder of reference material without ever opening a file picker.
Inputs (3)
| Name | Type | Default | Description |
|---|---|---|---|
| directory_path | STRING | — | |
| sort_mode | COMBO | 2 options: 完全随机, 顺序循环 | |
| seed | INT | 00–18446744073709550000 | — |
Outputs (3)
| Name | Type | Description |
|---|---|---|
| image | IMAGE | — |
| mask | MASK | — |
| text_content | STRING | — |