Nodes/ComfyUI-Pt-Wrapper/Ptn Resnet Model
ComfyUI Node

Ptn Resnet Model

A real ResNet you can train, built from a few boxes

By HowToSD·Created about a year ago·Updated about a year ago· 7
Ptn Resnet Model
    • PTMODEL
    input_dim(3,28,28)
    output_dim10
    num_blocks2

    This is the node that makes the pack's headline demo work: a real, trainable ResNet, built entirely from ComfyUI boxes. You configure three numbers and out comes a PTMODEL - a proper convolutional classifier you can train on your own images inside the graph, no architecture code in sight.

    Ptn Resnet Model lives in the "Training" corner of ComfyUI-Pt-Wrapper (HowToSD's 200-node no-code PyTorch pack, the spin-off of ComfyUI-Data-Analysis). The README's flagship is a ResNet on CIFAR-10 hitting 94% validation accuracy, and the dog-vs-cat classifier uses the same node. If the pack has a "just try this first" experience, it's this node plus image prep plus a training loop.

    How it works. It builds a ResNet-style network with three channel stages - 64, 128, 256 - where num_blocks controls how many residual blocks each stage gets. A residual block is the ResNet trick: the layer learns the change to its input and adds it back, which is what lets these networks train deep without vanishing gradients. The node uses IS_CHANGED returning NaN, so it always rebuilds rather than caching - you get a fresh model each run, which is what you want during training.

    The three inputs:

    • input_dim - a string, in the literal format "(C,H,W)". Default (3,28,28), i.e. 3-channel, 28×28 - MNIST-shaped. The CIFAR-10 example uses (3,32,32). Type it exactly with the parentheses, or you'll get a parse error.
    • output_dim - number of output features = number of classes in your classifier. Default 10 (MNIST/CIFAR-10 digit/class count). This is your class count.
    • num_blocks - residual blocks per stage (default 2). More blocks = deeper model = more capacity and more VRAM. Start at 2; go up only if underfitting.

    Output is PTMODEL, which you wire into the pack's training nodes.

    Where people get burned. The string parsing for input_dim is the classic fumble - 3,28,28 without parens, or (28,28,3) (channels last), and the node refuses or builds the wrong shape. Match your actual data: an image that's 512×512 wants (3,512,512), which will be slow and VRAM-heavy - that's not a bug, that's a big image. And the model expects channels-first tensors, which is exactly what Pt From Image Transpose produces; wire that node in front, or your "images" are in the wrong layout. Also be realistic: output_dim is class count, not batch size - setting it to your dataset size is a fun way to build a model that can never train.

    Install: ComfyUI Manager → "ComfyUI-Pt-Wrapper", or:

    cd ComfyUI/custom_nodes
    git clone https://github.com/HowToSD/ComfyUI-Pt-Wrapper
    

    then restart. The heavy requirements (transformers, sklearn, sentencepiece, pinned gensim) install once at setup. No pretrained weights ship with the pack - this node builds from scratch, so your training run does the learning.

    Troubleshooting: "invalid literal / parse error" on input_dim - the parens-and-commas format is mandatory. Training loss stuck high - check image prep (channels-first via Pt From Image Transpose) and that output_dim matches your label count. OOM - your input resolution is too big for the depth you chose; shrink the image or drop num_blocks.

    CategoryTraining

    Inputs (3)

    NameTypeDefaultDescription
    input_dimSTRING(3,28,28)
    output_dimINT101–1000000
    num_blocksINT21–100

    Outputs (1)

    NameTypeDescription
    PTMODELPTMODEL