Ptn Avg Pool 2d
Shrink spatial dimensions the boring, reliable way
- PTMODEL
Ptn Avg Pool 2d is a single average-pooling layer in the model-building half of the HowToSD/ComfyUI-Pt-Wrapper pack. Feed it a (batch, channels, height, width) tensor and it slides a window across the spatial dimensions, replacing each window with its average. With the defaults (kernel 2, stride 2, no padding) a 28×28 image comes out 14×14, so the whole spatial plane gets cut in half. It's the polite sibling of max pooling: instead of grabbing the loudest value in each window, it averages everything, which smooths the signal and keeps more information.
Why you'd reach for it
In image-classification pipelines this pack is built for (Fashion-MNIST, CIFAR-10, your own folder of images), pooling is how you progressively shrink feature maps between convolutional layers - fewer pixels means fewer parameters downstream and some resistance to overfitting and small translations. AvgPool is the gentle choice: it's the standard "reduce dimensionality without discarding information" layer. It also gets used at the end of a conv net to flatten each channel to a single average before the final classification layer, which is a cheap way to summarize a feature map. You'll almost always see it chained inside a Ptn Chained Model or as part of a Ptn Conv Model's hidden structure rather than standing alone.
How it works
It's nn.AvgPool2d wrapped as a node. Kernel, stride, and padding are all text fields rather than sliders, and here's the subtle bit: they accept either a single integer (2) or a tuple ((2, 2)) so you can pool height and width by different amounts. The node outputs a PTMODEL, not a tensor - it's a layer you assemble into a network, not something that computes directly. It rebuilds on every run (the pack marks these model nodes with IS_CHANGED → NaN), so you can tweak parameters and hit Run; the new layer replaces the old.
The inputs
- kernel_size (default
"2") - window size."3"or"(2, 3)"both work. - stride (default
"2") - how far the window steps each time. Equal to kernel size by default, so windows don't overlap. - padding (default
"0") - zero-padding added to the input before pooling.
Output: PTMODEL, wired into a Ptn Chained Model, Ptn Model With Closure, or straight into a training node.
Installing the pack
Ptn Avg Pool 2d is part of the "Training" category of the pack, the Ptn-* family of model and loss building blocks. 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 is a serious list - transformers, datasets, peft, accelerate, scikit-learn, gensim, sentencepiece - so the first install takes a while. No model files download at install; example-workflow datasets pull on demand.
Common issues
- String parsing errors - kernel/stride/padding must be valid Python literal syntax:
"2","(2, 2)", but not"2, 2"(that's a tuple-looking string that fails to parse as an int). - Dimension math - if the spatial size isn't cleanly divisible by the kernel, you get a runtime error or uneven output. With stride 2 and kernel 2, keep input sizes even, or add padding.
- Don't expect the output shape you forgot to check - verify with Pt Show Size after building the chain; averaging collapses the spatial dims faster than people expect.
- Solo project reality - Pt-Wrapper is a single-author educational pack with almost no discussion on r/comfyui. If a pooling setup misbehaves, the author's node reference docs and the training-guide docs are where the answers live.
Inputs (3)
| Name | Type | Default | Description |
|---|---|---|---|
| kernel_size | STRING | 2 | — |
| stride | STRING | 2 | — |
| padding | STRING | 0 | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| PTMODEL | PTMODEL | — |