Nodes/ComfyUI-mnemic-nodes/πŸ–ΌοΈ+πŸ“ Load Text-Image Pair (Single)
ComfyUI Node

πŸ–ΌοΈ+πŸ“ Load Text-Image Pair (Single)

Load One Image-and-Caption Pair at a Time, Straight From Your Training Folder

By MNeMoNiCuZΒ·Created 3 years agoΒ·Updated a day agoΒ· 105
πŸ–ΌοΈ+πŸ“ Load Text-Image Pair (Single)
  • image_input
  • image_single
  • string_single
  • image_path_single
  • image_filename_single
  • total_count
β—„seed0β–Ί
β—„folder_pathβ–Ί
β—„text_inputβ€”β–Ί
β—„text_format_extensiontxtβ–Ί

LoRA datasets are not clever. A folder of 0001.png + 0001.txt pairs is the whole convention, and every trainer - kohya, ai-toolkit, OneTrainer - just walks it looking for a text file with the same basename as the image. πŸ–ΌοΈ+πŸ“ Load Text-Image Pair (Single) reads that same folder inside ComfyUI, one pair per run, so you can feed a real caption from your dataset into a test generation instead of retyping it.

Why you'd want that: the fastest way to sanity-check a dataset is to generate with the captions themselves. If 0007.txt is "a woman in a red coat, overcast street, 35mm" and the model can't do anything with that, the training run is going to be a waste of six hours. This node hands you image and caption as separate outputs so you can look at both in one pass.

How it works

Point folder_path at the dataset directory and the node scans it: images are .png, .jpg, .jpeg, .bmp and .webp; captions are whatever text_format_extension says (default txt, but .caption works too). It pairs by basename, sorts alphabetically, and skips any image without a matching caption file - silently, which is worth knowing. Then seed is a modulo index, not a seed: seed % total_count picks the pair, so seed 0 is the first pair, seed 12 the thirteenth, and it wraps politely.

total_count comes out as its own output, so you can see how many usable pairs the folder actually has. If that number is smaller than you expected, you have unpaired files.

Both image_input and text_input are optional and take priority over the folder entirely. Connect both and the node just passes them through (the image, the text as a string, total_count = batch size) - which makes it a handy "flatten a batch to one item" node as well as a dataset reader.

Inputs and outputs

You set seed (with control_after_generate on increment to walk the folder run by run) and folder_path, plus optionally text_format_extension. Outputs are image_single, string_single, image_path_single, image_filename_single, and total_count. The path and filename outputs are the ones people forget - wire image_filename_single into a Save Image prefix and every output image names the pair it came from.

Install

ComfyUI Manager, search "ComfyUI-mnemic-nodes", restart. Or:

cd ComfyUI/custom_nodes
git clone https://github.com/MNeMoNiCuZ/ComfyUI-mnemic-nodes

No model downloads. The pack's dependencies (transformers, opencv-python, tiktoken, piexif, imageio) get installed with it; none of them are needed by this particular node.

Common issues

It returns nothing. Either the folder has no matched pairs, or folder_path is wrong. Absolute paths are the safe choice - a relative path isn't resolved against ComfyUI/input here the way you might hope.

Zero-byte or black images. The node .convert("RGB")s every image, so a paletted PNG or a 16-bit TIFF is fine, but a corrupt file just prints to the console and the run continues.

Captions are being ignored. Check the extension. text_format_extension defaults to txt without a dot; pass caption not .caption.

You wanted the whole dataset at once. That's the sibling node, πŸ–ΌοΈ+πŸ“ Load Text-Image Pairs (List). This one is deliberately built to be fast and stateless - it opens and decodes one pair per execution rather than caching the set.

Category⚑ MNeMiC Nodes

Inputs (5)

NameTypeDefaultDescription
seedINT00–18446744073709550000Index of the pair to load, starting at 0. Increments every run by default to step through the folder.
folder_pathSTRINGPath to a folder containing image and text files with matching basenames. This is used only if image_input and text_input are not connected.
image_inputoptIMAGEA single image or a list/batch of images. This input has priority over the folder_path.
text_inputoptSTRINGA single text string or a list of strings. This input has priority over the folder_path.
text_format_extensionoptSTRINGtxtThe file extension for the text files to look for (without the dot).

Outputs (5)

NameTypeDescription
image_singleIMAGEThe single image selected by the seed.
string_singleSTRINGThe text string that is paired with the selected image.
image_path_singleSTRINGThe full absolute path of the selected image.
image_filename_singleSTRINGThe filename (without extension) of the selected image.
total_countINTThe total number of pairs found in the dataset.