I don't know how to convert the PyTorch method adaptive_avg_pool2d to Keras or TensorFlow. Anyone can help?
PyTorch mehod is
adaptive_avg_pool2d(14,[14])
I tried to use the average pooling, the reshape the tensor in Keras, but got the error:
ValueError: total size of new array must be unchanged
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 usenn.AdaptiveAvgPool2d((5,7)).If you want a global average pooling layer, you can use
nn.AdaptiveAvgPool2d(1). In Keras you can just useGlobalAveragePooling2D.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 thepool_size,stride, andpaddingparameters depending on how you want the output shape. If you need help with the calculations, check this page of CS231n course.