ComfyUI Node

NNT Define Pooling Layer

Shrink your tensors, 18 different ways

By inventorado·Created 2 years ago·Updated 2 years ago· 69
NNT Define Pooling Layer
  • LAYER_STACK
  • LAYER_STACK
pooling_typeMaxPool2d
kernel_size2
stride2
padding0
dilation1
ceil_modeFalse
return_indicesFalse
count_include_padTrue
output_size1
fractional_factor1.5
norm_type2.0
flatten_outputFalse
num_copies1

Convolutional layers make your feature maps bigger and deeper; pooling is what shrinks them back down. In the Neural Network Toolkit, NNT Define Pooling Layer is the downsampling workhorse, and it covers the whole PyTorch pooling family - 18 variants from plain MaxPool2d to the rarely-seen FractionalMaxPool2d and LPPool1d. If you've seen a CNN architecture diagram with those little "max pool 2×2" boxes, this is the node that draws the box.

What it actually does

Like every define node in the pack, it appends a layer description to a LAYER_STACK list that NntCompileModel later turns into real PyTorch modules. Max pooling slides a window over the feature map and keeps the max value in each window - aggressive, translation-tolerant, the classic pick for vision. Average pooling keeps the mean instead, which is smoother and often used right before the classification head. Adaptive pooling ignores kernel sizes entirely and just outputs whatever spatial size you ask for. Fractional and LP pooling are niche; you'll likely never touch them, but they're there if a paper asks for them.

Inputs that matter

  • pooling_type - the dropdown: MaxPool1d/2d/3d, AvgPool1d/2d/3d, AdaptiveMaxPool*, AdaptiveAvgPool*, MaxUnpool*, FractionalMaxPool2d, LPPool1d/2d. Pick by the dimensionality of your data.
  • kernel_size and stride - these are string fields, and this is where NNT is clever: type 2 for a 2D window of 2×2, or (2, 2) to be explicit, or (2, 2, 2) for a 3D pool. The node parses whichever you give it based on the pooling type's dimensionality.
  • flatten_output - set True to flatten the tensor right after pooling, which is the standard bridge into a dense classifier.
  • num_copies - how many identical copies of this pool layer to append. Handy for the common "pool 2×2, then pool 2×2 again" stacking; crank it and skip the second node.

The rest are per-type toggles: ceil_mode and return_indices (MaxPool), count_include_pad (AvgPool), output_size (Adaptive), fractional_factor (Fractional), norm_type (LP). dilation and padding are there for MaxPool variants that support them.

The honest gotcha

The README and the pack's own framing are clear: this is a work in progress. In the current version, the compile-to-Sequential path builds MaxPool2d and AvgPool2d directly; the 1d/3d, adaptive, unpool, fractional, and LP variants are defined and appear in the generated model script, but not all of them are guaranteed to materialize as compiled layers yet. If you're reaching for anything beyond the 2D max/avg pair, use NntCompileModel's "Only create script" mode first to see what actually gets built before you burn an afternoon on a 3D pooling architecture.

Installing NNT

This is one node in inventorado/ComfyUI_NNT. Install via ComfyUI Manager (search "ComfyUI Neural Network Toolkit") or manually:

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

That dependency list is a full scientific stack - torch, numpy, scikit-learn, pandas, seaborn, shap - so the first install is chunky and occasionally collides with an existing environment; restart ComfyUI afterward. Example CNN workflows (MNIST, CIFAR10) ship in the pack's workflows/ folder and use ComfyUI-Jjk-Nodes for text output, so let Manager grab those as well.

CategoryNNT Neural Network Toolkit/Layers

Inputs (14)

NameTypeDefaultDescription
pooling_typeCOMBOMaxPool2d18 options: MaxPool1d, MaxPool2d, MaxPool3d, AvgPool1d, AvgPool2d, AvgPool3d, +12
kernel_sizeSTRING2
strideSTRING2
paddingSTRING0
dilationSTRING1
ceil_modeCOMBOFalse2 options: True, False
return_indicesCOMBOFalse2 options: True, False
count_include_padCOMBOTrue2 options: True, False
output_sizeSTRING1
fractional_factorFLOAT1.51–3
norm_typeFLOAT2.01–6
flatten_outputCOMBOFalse2 options: True, False
num_copiesINT11–100
LAYER_STACKoptLIST

Outputs (1)

NameTypeDescription
LAYER_STACKLIST