Nodes/Comfyui_CXH_joy_caption/CXH_IC_lora_reversal
ComfyUI Node

CXH_IC_lora_reversal

The caption reverser that doubles your IC-LoRA dataset

By StartHua·Created 2 years ago·Updated 2 years ago· 624
CXH_IC_lora_reversal
    • caption
    dir1
    dir2
    text_dir
    save_dir
    slic_start[image1]
    slic_end[image2]
    format
    text1
    text2
    templateRealistic style, [cloth-on], the image pair highlights a transformation from a female model wearing the cloth to its clothing sample photo. [image1] a female model is wearing a cloth with {caption} [image2] the clothing sample photo of what the model is wearing in [image1] with {caption}
    directionright
    match_image_sizetrue

    Here's the trick this pack is quietly built around: IC-LoRA captioning only writes captions in one direction ("here's the garment, here's it being worn"). CXH_IC_lora_reversal manufactures the reverse - captions that describe the same pair going the other way ("here's the model wearing it, here's the garment") - without re-running the vision model at all. You get a second, direction-reversed training set for free, which materially helps a LoRA generalize rather than just memorizing one arrangement.

    It's a text-processing node wearing a caption node's clothes. No model input, no image captioning happens - it reads the captions you already generated, flips the framing, and writes new pairs.

    How it works

    For each image in dir1, it needs:

    1. The paired image in dir2 (same filename),
    2. An existing caption .txt in text_dir (same base filename).

    It reads the existing caption, slices out the segment between slic_start (default [image1]) and slic_end (default [image2]) - i.e. the actual model-written description - and feeds it into a reversed template whose default reads: Realistic style, [cloth-on], the image pair highlights a transformation from a female model wearing the cloth to its clothing sample photo. [image1] a female model is wearing a cloth with {caption} [image2] the clothing sample photo of what the model is wearing in [image1] with {caption}.

    The rewritten caption plus a re-stitched image pair (same direction/match_image_size logic as the other IC nodes) land in save_dir. If the output file already exists, it skips - so re-runs are cheap and resume-friendly.

    Inputs

    • dir1, dir2 - the image pair folders.
    • text_dir - where the source .txt captions live.
    • save_dir - reversed output goes here.
    • slic_start, slic_end - the markers around the caption you want to reuse; default to [image1] and [image2], matching the templates used by the captioning nodes.
    • text1, text2, template, direction, match_image_size, format.
    • Output: caption (STRING) - last processed caption; real output is on disk.

    Installing

    Pack install - ComfyUI Manager (search "Comfyui_CXH_joy_caption") or:

    cd ComfyUI/custom_nodes
    git clone https://github.com/StartHua/Comfyui_CXH_joy_caption
    cd Comfyui_CXH_joy_caption
    python -m pip install -r requirements.txt
    

    No model downloads - this node never touches a model.

    Gotchas

    • Missing pair or missing .txt → skipped silently. It prints "Second image not found" but there's no error dialog. Check your file counts.
    • The slice assumes your source captions contain [image1] and [image2] markers. If your captioner ran with a template that omitted them, .index() raises an error. Use the pack's own IC caption nodes upstream so the markers exist.
    • Skipping existing files is the resume feature - but if you changed the template, stale files won't be regenerated. Clear save_dir when you change anything.
    CategoryFlorence2

    Inputs (12)

    NameTypeDefaultDescription
    dir1STRING
    dir2STRING
    text_dirSTRING
    save_dirSTRING
    slic_startSTRING[image1]
    slic_endSTRING[image2]
    formatCOMBO2 options: png, jpg
    text1STRING
    text2STRING
    templateSTRINGRealistic style, [cloth-on], the image pair highlights a transformation from a female model wearing the cloth to its clothing sample photo. [image1] a female model is wearing a cloth with {caption} [image2] the clothing sample photo of what the model is wearing in [image1] with {caption}
    directionCOMBOright4 options: right, down, left, up
    match_image_sizeBOOLEANtrue

    Outputs (1)

    NameTypeDescription
    captionSTRING