ComfyUI Node

NNT Define Conv Layer

NNT Define Conv Layer — build the CNN half of the pack's CIFAR/MNIST workflows

By inventorado·Created 2 years ago·Updated 2 years ago· 69
NNT Define Conv Layer
  • LAYER_STACK
  • hyperparameters
  • layer_stack
conv_typeConv2d
out_channels64
kernel_size3
stride1
padding1
padding_modezeros
output_padding0
dilation1
groups1
use_biasTrue
activation_functionReLU
normalizationBatchNorm
norm_eps0.0000
norm_momentum0.100
norm_affineTrue
dropout_rate0.0
weight_initkaiming_normal
weight_init_gain1.41
weight_init_modefan_out
weight_init_nonlinearityrelu
num_copies1

If you're doing any image classification in the Neural Network Toolkit, this is the node you'll spend the most time in. NntDefineConvLayer appends a convolutional layer to your LAYER_STACK - with normalization, activation, dropout, weight init, and full kernel/stride/padding control all bundled in. It's what the pack's CIFAR10 and MNIST example workflows are made of.

The inputs that matter

  • conv_type (default Conv2d) - also Conv1d/Conv3d, the transposed variants for upsampling, and Unfold/Fold. For image work: Conv2d.
  • out_channels (default 64) - how many filters. Doubling per block (32 → 64 → 128) is the classic pattern.
  • kernel_size (default 3), stride (default 1), padding (default 1) - the geometry. kernel_size 3 with padding 1 keeps spatial dimensions the same; stride 2 downscales.
  • normalization (default BatchNorm) and norm_eps / norm_momentum / norm_affine - BatchNorm2d after a conv is standard. On small datasets feel free to flip it to None and see what happens; that comparison is half the educational value of this pack.
  • activation_function (default ReLU) and dropout_rate (default 0).
  • weight_init (default kaiming_normal) plus weight_init_gain/mode/nonlinearity - the deep-nerd knobs. Kaiming's default mode here is fan_out with ReLU, which matches the conv-use convention. Leave them alone until you're intentionally experimenting.
  • dilation (default 1) and groups (default 1) - dilated convs for wider receptive fields, grouped convs for depthwise-style tricks. Optional for the curious.
  • num_copies (default 1) - how many identical copies of this layer to stack. Handy for "add three of these."

Output: layer_stack (LIST) - chain into the next node, then NntCompileModel.

How it works

Same pattern as every NNT define node: it records a dict ({'type': 'Conv2d', 'out_channels': 64, ...}) onto the stack list. At compile time, NntCompileModel builds the real nn.Conv2d, infers in_channels from the shape tracking through the network, applies your init, then tacks on the norm, activation, and dropout in order. It also computes the output shape after each conv, which is how the pack can tell you whether your architecture lines up.

Common issues

  • Shape mismatch downstream - after a few strided/padded convs it's easy to land on an odd spatial size that a dense layer can't consume. Add an NntDefinePoolingLayer or NntDefineFlattenLayer before the dense block; the compile report tells you the shapes.
  • Conv1d vs Conv2d - pick the wrong dimension and nothing fits. Images → 2d; sequences → 1d.
  • output_padding - only relevant for ConvTranspose*; it's not a second padding input for normal convs. If you're not upsampling, leave it at 0.

Install

Pack-level install, nothing node-specific:

cd ComfyUI/custom_nodes
git clone https://github.com/inventorado/ComfyUI_NNT.git
cd ComfyUI_NNT
pip install -r requirements.txt

or ComfyUI Manager → "ComfyUI Neural Network Toolkit NNT". Restart, load NNT_conv_CIFAR10.json or NNT_conv_MNIST.json from the pack's workflows folder and you'll see this node doing most of the heavy lifting. Note those example workflows display text via ComfyUI-Jjk-Nodes - let Manager's "Install Missing Custom Nodes" grab it.

CategoryNNT Neural Network Toolkit/Layers

Inputs (23)

NameTypeDefaultDescription
conv_typeCOMBOConv2d8 options: Conv1d, Conv2d, Conv3d, ConvTranspose1d, ConvTranspose2d, ConvTranspose3d, +2
out_channelsINT641–2048
kernel_sizeINT31–15
strideINT11–8
paddingINT10–10
padding_modeCOMBOzeros4 options: zeros, reflect, replicate, circular
output_paddingINT00–2
dilationINT11–5
groupsINT11–2048
use_biasCOMBOTrue2 options: True, False
activation_functionCOMBOReLU28 options: None, ELU, GELU, GLU, Hardshrink, Hardsigmoid, +22
normalizationCOMBOBatchNorm10 options: None, BatchNorm1d, BatchNorm2d, BatchNorm3d, LayerNorm, InstanceNorm1d, +4
norm_epsFLOAT0.00001e-12–0.001
norm_momentumFLOAT0.1000.001–0.999
norm_affineCOMBOTrue2 options: True, False
dropout_rateFLOAT0.00–0.9
weight_initCOMBOkaiming_normal12 options: default, normal, uniform, xavier_normal, xavier_uniform, kaiming_normal, +6
weight_init_gainFLOAT1.410.01–10
weight_init_modeCOMBOfan_out2 options: fan_in, fan_out
weight_init_nonlinearityCOMBOrelu6 options: relu, leaky_relu, selu, tanh, linear, sigmoid
num_copiesINT11–100
LAYER_STACKoptLIST
hyperparametersoptDICT

Outputs (1)

NameTypeDescription
layer_stackLIST