I'm not sure if I understood your question, but in PyTorch, you pass the spatial dimensions to AdaptiveAvgPool2d
. For instance, if you want to have an output sized 5x7, you can use nn.AdaptiveAvgPool2d((5,7))
.
If you want a global average pooling layer, you can use nn.AdaptiveAvgPool2d(1)
. In Keras you can just use GlobalAveragePooling2D
.
For other output sizes in Keras, you need to use AveragePooling2D
, but you can't specify the output shape directly. You need to calculate/define the pool_size
, stride
, and padding
parameters depending on how you want the output shape. If you need help with the calculations, check this page of CS231n course.