ComfyUI Node

Caption Image Loader

The caption loader that turns a folder into a training set

By marcoc2·Created 2 years ago·Updated 5 months ago· 1
Caption Image Loader
    • caption
    directory
    selected_basename

    If you've ever built a training dataset by hand, you know the soul-crushing part isn't generating images - it's pairing every file with its text caption. Caption Image Loader from the AnotherUtils pack automates exactly that pairing, and it's the kind of small node you stop noticing because it just works. It reads a caption for whatever image you've selected from a folder, and hands it to your workflow as a plain string. That's it. Which is the point: in a dataset pipeline, "boring and reliable" beats "clever."

    The pack (marcoc2/ComfyUI-AnotherUtils, "Image Processing Suite for ComfyUI" by marcoags) frames it as part of a batch-friendly dataset-prep story. It expects a specific folder layout: a root directory holding the images, plus a captions subfolder with one .txt per image, named after the image's basename. So img_001.png gets its text from captions/img_001.txt. If you've seen the Load Images (Original Size) or FolderImageLoader nodes from the same pack, they share the convention.

    How it works

    Set directory to that root folder. A small JS extension that ships with the pack adds a browse UI to the node - it calls a ComfyUI API route (/another_utils/list_images) that lists the images in the folder, shows you tiny thumbnails, and lets you pick one. That selection lands in the selected_basename field. When the workflow runs, the node looks up <directory>/captions/<selected_basename>.txt, reads it, strips whitespace, and returns it.

    Nothing fancy under the hood: plain open(), UTF-8, .strip(). It's the same approach every other pack's caption loader uses, but the built-in file picker is what makes it usable by hand rather than by guesswork.

    The inputs that matter

    • directory (required) - root containing images and the captions subfolder.
    • selected_basename (optional) - which image you're reading the caption for. Leave empty and it returns an empty string.

    The single output, caption, is a STRING - wire it into a CLIP Text Encode, an SDXL style selector, or straight into a text file saver. It pairs naturally with the pack's image loaders: load the image, load its caption, feed both to an image-editing or caption-repair workflow.

    Install

    Via ComfyUI Manager (search AnotherUtils), or:

    cd ComfyUI/custom_nodes
    git clone https://github.com/marcoc2/ComfyUI-AnotherUtils.git
    

    Then restart ComfyUI. This node has zero extra dependencies - no model files, no pip installs. (Other parts of the pack auto-download YOLO/SAM2 weights, but this loader never touches them.)

    Common issues

    The node is silent-by-design, which is also its main trap: if the caption file is missing or unreadable it returns an empty string rather than erroring. You'll see [CaptionImageLoader] Caption file not found: ... in your console log, but the workflow won't stop. If you're getting blank captions, check that the folder really has a captions subfolder and that the .txt basename exactly matches the image's basename (case matters on Linux). A missing directory does raise a ValueError, so that one's easy to spot. And if the folder is huge, the first browse can be slow - the thumbnails are generated on the fly, not cached.

    CategoryAnotherUtils/loaders

    Inputs (2)

    NameTypeDefaultDescription
    directorySTRING
    selected_basenameoptSTRING

    Outputs (1)

    NameTypeDescription
    captionSTRING