NNT Define Conv Layer
NNT Define Conv Layer — build the CNN half of the pack's CIFAR/MNIST workflows
- LAYER_STACK
- hyperparameters
- layer_stack
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_size3 withpadding1 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
Noneand 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) plusweight_init_gain/mode/nonlinearity- the deep-nerd knobs. Kaiming's default mode here isfan_outwith 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.
Inputs (23)
| Name | Type | Default | Description |
|---|---|---|---|
| conv_type | COMBO | Conv2d | 8 options: Conv1d, Conv2d, Conv3d, ConvTranspose1d, ConvTranspose2d, ConvTranspose3d, +2 |
| out_channels | INT | 641–2048 | — |
| kernel_size | INT | 31–15 | — |
| stride | INT | 11–8 | — |
| padding | INT | 10–10 | — |
| padding_mode | COMBO | zeros | 4 options: zeros, reflect, replicate, circular |
| output_padding | INT | 00–2 | — |
| dilation | INT | 11–5 | — |
| groups | INT | 11–2048 | — |
| use_bias | COMBO | True | 2 options: True, False |
| activation_function | COMBO | ReLU | 28 options: None, ELU, GELU, GLU, Hardshrink, Hardsigmoid, +22 |
| normalization | COMBO | BatchNorm | 10 options: None, BatchNorm1d, BatchNorm2d, BatchNorm3d, LayerNorm, InstanceNorm1d, +4 |
| norm_eps | FLOAT | 0.00001e-12–0.001 | — |
| norm_momentum | FLOAT | 0.1000.001–0.999 | — |
| norm_affine | COMBO | True | 2 options: True, False |
| dropout_rate | FLOAT | 0.00–0.9 | — |
| weight_init | COMBO | kaiming_normal | 12 options: default, normal, uniform, xavier_normal, xavier_uniform, kaiming_normal, +6 |
| weight_init_gain | FLOAT | 1.410.01–10 | — |
| weight_init_mode | COMBO | fan_out | 2 options: fan_in, fan_out |
| weight_init_nonlinearity | COMBO | relu | 6 options: relu, leaky_relu, selu, tanh, linear, sigmoid |
| num_copies | INT | 11–100 | — |
| LAYER_STACKopt | LIST | — | |
| hyperparametersopt | DICT | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| layer_stack | LIST | — |