ComfyUI Node

Ptn Conv 2d

The single convolutional layer node

By HowToSD·Created about a year ago·Updated about a year ago· 7
Ptn Conv 2d
    • PTMODEL
    in_channels1
    out_channels1
    kernel_size3
    stride1
    paddingsame
    dilation1
    groups1
    biastrue
    padding_mode

    Ptn Conv 2d is a single 2D convolution layer exposed as a node in the HowToSD/ComfyUI-Pt-Wrapper pack. Give it input and output channel counts, a kernel size, and a stride, and it returns a PTMODEL that slides a learned filter bank over your (batch, channels, height, width) tensors. It's the fundamental building block of image models - if you're assembling a CNN by hand instead of grabbing the pre-built Ptn Conv Model, this is the layer you'll stack.

    Why you'd reach for it

    Convolutions are how image models find spatial structure: a small kernel looks at a local neighborhood, learns a feature detector, and shares that detector across the whole image. The single-layer node matters for two reasons. First, composition - chain a few of these (with batch norm and activations between them) into a custom network, and you've designed your own architecture. Second, the last layer of many image classifiers is a convolution tuned down to one channel, or you want just one conv on top of an existing feature map. The author's "build a model from scratch" workflow is basically this node plus a few friends, chained.

    How it works

    It's nn.Conv2d wrapped with sensible defaults. kernel_size, stride, padding, and dilation are text fields that accept either an integer ("3") or a tuple ("(3, 5)"), so you can have asymmetric kernels. padding also accepts the strings "same" and "valid" directly, which PyTorch interprets as "preserve spatial size" and "no padding" - the default is "same", which means with stride 1 your feature maps keep their size. padding_mode picks how padding values are filled (zeros, reflect, replicate, circular). The output is a PTMODEL layer to assemble into a network; it rebuilds on every graph run.

    The inputs

    • in_channels / out_channels - channels in, channels out. Match in_channels to whatever the previous layer emitted.
    • kernel_size (default "3") - filter size; "3" or "(3, 5)".
    • stride (default "1") - how far the kernel steps.
    • padding (default "same") - "same", "valid", or a number.
    • dilation (default "1") - spacing between kernel elements (dilated convs expand the receptive field).
    • groups (default 1) - split channels into groups processed separately (depthwise convs use groups = in_channels).
    • bias (default on) - add a learnable bias.
    • padding_mode - how padding fills (zeros default).

    Output: PTMODEL.

    Installing the pack

    In the "Training" category of the pack. Install via ComfyUI Manager (search "ComfyUI-Pt-Wrapper") or:

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

    Restart ComfyUI. The pack's requirements.txt brings in transformers, datasets, peft, scikit-learn, gensim and more; no model downloads at install.

    Common issues

    • Channel mismatch - in_channels must equal the previous layer's out_channels, or the forward pass errors. Double-check when chaining.
    • String parse errors - kernel/stride/padding/dilation must be valid literals: "3" or "(3, 3)", never "3, 3".
    • "same" padding gotchas - with "same" and stride 2, PyTorch computes padding automatically and output size halves; with odd kernels the padding is uneven. Verify output shape with Pt Show Size if spatial sizes matter downstream.
    • Community is thin - this is a single-author educational pack with nearly zero r/comfyui or r/StableDiffusion footprint. The repo's node reference and model-training docs are your best help.
    CategoryTraining

    Inputs (9)

    NameTypeDefaultDescription
    in_channelsINT11–1000000
    out_channelsINT11–1000000
    kernel_sizeSTRING3
    strideSTRING1
    paddingSTRINGsame
    dilationSTRING1
    groupsINT11–1000000
    biasBOOLEANtrue
    padding_modeCOMBO4 options: zeros, reflect, replicate, circular

    Outputs (1)

    NameTypeDescription
    PTMODELPTMODEL