💡 [REQUEST] - Neural Style Transfer: use AvgPool2d
@sekyondaMeta is already working on this.
Since Apr 27, 2026.
- Dominant language
- Python
- Stars
- 9.3k
- Forks
- 4.4k
- Avg merge
- 1d 21h
- Merged PRs (30d)
- 4
Description
🚀 Describe the improvement or the new tutorial
Neural Style Transfer utilizes VGG network, which uses maximum pooling.
Although Original article suggests using average pooling instead for better results:
For image synthesis we found that replacing the maximum
pooling operation by average pooling yields slightly more
appealing results, which is why the images shown were generated with average pooling.
This is unsurprising, considering that max pooling may hide gradients of lower layers, while average pooling preserves them, so gradient descent for reconstructing image works better.
I confirm that it actually improves results.
Suggested changes
Replace that:
elif isinstance(layer, nn.MaxPool2d):
name = 'pool_{}'.format(i)
with that:
elif isinstance(layer, nn.MaxPool2d):
name = 'pool_{}'.format(i)
layer = nn.AvgPool2d(
kernel_size=layer.kernel_size,
stride=layer.stride,
padding=layer.padding,
ceil_mode=layer.ceil_mode)
Existing tutorials on this topic
https://docs.pytorch.org/tutorials/advanced/neural_style_tutorial.html
Additional context
No response
cc @albanD @jbschlosser
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.