'TimeDistributed(GlobalAveragePooling2D()) vs TimeDistributed(Flatten())

For the image classification task, I first built a CNN model that gave a higher accuracy when I used GlobalAveragePooling2D() than Flatten().

Now i want to add LSTM layers to my model, TimeDistributed(Flatten()) before the LSTM layers works fine but when i replace it with TimeDistributed(GlobalAveragePooling2D()) i got the error :

Input 0 of layer "global_average_pooling2d" is incompatible with the layer: expected ndim=4, found ndim=3. Full shape received: (None, 7, 1280)

how can fix this error ?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source