Nodes/Diffusion_pipe_in_ComfyUI/遮罩数据集路径
ComfyUI Node

遮罩数据集路径

White stays, black goes, gray trains

By TianDongL·Created 11 months ago·Updated 7 months ago· 69
遮罩数据集路径
    • input_path
    dataset_path
    mask_path

    Normal LoRA training treats every pixel of your training images as equally valuable. Sometimes that's wrong. If your images have busy backgrounds, watermarks, or a subject that's half out of frame, you want the trainer to ignore all that and focus on the thing you actually care about. That's what MaskDatasetPathNode is for: it pairs your training images with a matching folder of masks, so the loss only counts what you've left white.

    This is a relatively recent addition to the pack (the README logs "support mask training" in the Nov 2025 update), and it plugs straight into the same dataset pipeline as the plain GeneralDatasetPathNode.

    How it works

    You give it two folders: dataset_path, full of training images, and mask_path, full of masks. The node checks both folders exist (it prints a warning to the console if either is missing) and returns an input_path config dict - {"path": ..., "mask_path": ...} - that you wire into a GeneralDatasetConfig node, exactly like any other dataset path node.

    The naming rule matters: each mask file must match its image's filename. image_001.jpg pairs with image_001.png (or whatever the mask extension is). If the names don't line up, the trainer can't pair them and your masking silently does nothing.

    The mask semantics come straight from the author's tooltip: white = train, black = masked out, gray = train partially. So a pure subject-isolation mask is mostly white with black background. The gray middle ground is the interesting bit - it's effectively a soft weight on how strongly those pixels count toward the loss, which is useful when your subject edge is soft or you want the background to barely register rather than disappear entirely.

    The inputs that matter

    Only two, both required:

    • dataset_path - the folder of training images.
    • mask_path - the folder of mask images, same filenames as the training images.

    Output: input_path, into GeneralDatasetConfig.

    Install

    Standard for this pack - ComfyUI Manager (search "Diffusion_pipe_in_ComfyUI") or:

    cd ComfyUI/custom_nodes
    git clone --recurse-submodules https://github.com/TianDongL/Diffusion_pipe_in_ComfyUI.git
    cd Diffusion_pipe_in_ComfyUI
    git submodule init && git submodule update
    pip install -r requirements.txt
    

    Linux/WSL2 only - on plain Windows this pack won't train at all.

    Where people get burned

    Three classics. First, filename mismatches: the mask system is filename-driven, so if you batch-renamed your images and not your masks, you'll train on unmasked data and never know. Second, missing the gray semantics - people paint all-black backgrounds and wonder why the subject edges look cut. A little gray feathering at the boundary trains smoother than a hard black/white edge. Third, pointing the mask path at the wrong folder entirely; the node warns in the console but happily returns a config anyway, so skim the logs on your first run. Masked training is genuinely one of the strongest tools for fixing a dataset with noisy backgrounds - it's worth doing the masking right.

    CategoryDiffusion-Pipe/dataset

    Inputs (2)

    NameTypeDefaultDescription
    dataset_pathSTRING训练图像路径 - 包含训练图片的文件夹
    mask_pathSTRING遮罩图像路径 - 白色训练,黑色遮蔽,灰色部分训练。遮罩文件名需与训练图片匹配

    Outputs (1)

    NameTypeDescription
    input_pathinput_path