Nodes/ComfyUI_M3Net/M3Net Model Loader
ComfyUI Node

M3Net Model Loader

The M3Net loader with two dropdown options and one weight file

By leeguandong·Created 2 years ago·Updated 2 years ago· 12
M3Net Model Loader
    • m3net
    m3netM3Net-S

    If you opened this because a shared workflow has an M3Net_Interface node with an input you can't fill, this is the other half of the pack. M3Net_ModelLoader is the boring half - it builds and loads the model and hands you an M3NET object that the Interface node eats. There's exactly one input and one output, so the whole skill is knowing where the weights go and not tripping over the pack's one real quirk.

    What it does

    The pack wraps M3Net, an academic salient object detection network from I2-Multimedia-Lab - "Multilevel, Mixed and Multistage Attention Network for Salient Object Detection" - repurposed by the pack author (leeguandong) as a background remover for e-commerce product shots. The loader is where you pick which variant to run:

    • M3Net-S (default) - a Swin-Transformer backbone.
    • M3Net-R - a ResNet backbone.

    Both variants run at 384×384. The loader instantiates the architecture you chose, loads the checkpoint into it, moves it to the GPU, flips it to eval mode, and returns the whole thing as a single m3net output. Wire that into the m3net input of an M3Net_Interface node and you're done - you never touch the model object directly.

    The quirk: the dropdown is half real

    Here's where people get burned. The code builds a different network for S versus R, but the weight path is hardcoded to weights/M3Net-S.pth no matter which option you pick. So:

    • Select M3Net-S and it loads the S weights into the Swin network. Works.
    • Select M3Net-R and it builds the ResNet version, then tries to load the Swin-format weights into it. The state dicts don't match, and load_state_dict throws a RuntimeError before you ever see an image.

    The practical fix: whatever checkpoint you actually want, save it as weights/M3Net-S.pth. Download the R weights, rename the file, run with the R option selected - the architecture will still be ResNet, but at least the keys line up. It's a clumsy workaround, but it's the one that works.

    Weights, and the Baidu pan friction

    The checkpoint does not ship in the repo (.gitignore excludes *.pth) and there's no HuggingFace link. The README points at Baidu pan (百度网盘) downloads - two pre-trained weights (R and S) plus pre-calculated saliency maps, and the author's own "general" e-commerce-tuned weight with the extraction code vi01. Drop the file into:

    ComfyUI/custom_nodes/ComfyUI_M3Net/weights/M3Net-S.pth
    

    If the file is missing, the loader fails with a FileNotFoundError for that path. Baidu pan can be slow and captcha-heavy outside China; if a mirror is what you're hunting for, you're not alone.

    Install

    Two ways, same result:

    cd ComfyUI/custom_nodes
    git clone https://github.com/leeguandong/ComfyUI_M3Net.git
    

    then restart ComfyUI. The README says ComfyUI Manager support was "on the way" - by the time you read this it may be searchable in Manager as ComfyUI_M3Net. Either way, the pack has no requirements.txt, so Manager won't auto-install anything extra. The code imports timm internally; if ComfyUI's console shows ModuleNotFoundError: No module named 'timm' on startup, install it into ComfyUI's Python environment (pip install timm or via Manager's "Install Missing Custom Nodes" prompt) and restart.

    Troubleshooting, short list

    • FileNotFoundError: weights/M3Net-S.pth - you haven't downloaded the checkpoint yet. See above.
    • RuntimeError: Error(s) in loading state_dict - you selected M3Net-R without renaming the weights. Rename to M3Net-S.pth.
    • ModuleNotFoundError: timm - see install above.
    • This loader alone won't error on a CPU machine (it degrades to cpu), but the Interface node hardcodes .cuda() - so a GPU is effectively required for the pack to do anything. Budget for that before you go further.

    One honest note: this is a niche wrapper around an academic model, not a maintained competitor to BiRefNet (which ComfyUI ships natively) or InSPyReNet. If a downloaded workflow makes you use it, the above gets you running. If you're choosing a background remover, read the M3Net Interface article first.

    Categorym3net

    Inputs (1)

    NameTypeDefaultDescription
    m3netCOMBOM3Net-S2 options: M3Net-R, M3Net-S

    Outputs (1)

    NameTypeDescription
    m3netM3NET