NNT Define Pooling Layer
Shrink your tensors, 18 different ways
- LAYER_STACK
- LAYER_STACK
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_sizeandstride- these are string fields, and this is where NNT is clever: type2for 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- setTrueto 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.
Inputs (14)
| Name | Type | Default | Description |
|---|---|---|---|
| pooling_type | COMBO | MaxPool2d | 18 options: MaxPool1d, MaxPool2d, MaxPool3d, AvgPool1d, AvgPool2d, AvgPool3d, +12 |
| kernel_size | STRING | 2 | — |
| stride | STRING | 2 | — |
| padding | STRING | 0 | — |
| dilation | STRING | 1 | — |
| ceil_mode | COMBO | False | 2 options: True, False |
| return_indices | COMBO | False | 2 options: True, False |
| count_include_pad | COMBO | True | 2 options: True, False |
| output_size | STRING | 1 | — |
| fractional_factor | FLOAT | 1.51–3 | — |
| norm_type | FLOAT | 2.01–6 | — |
| flatten_output | COMBO | False | 2 options: True, False |
| num_copies | INT | 11–100 | — |
| LAYER_STACKopt | LIST | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| LAYER_STACK | LIST | — |