I'm just started to learn Tensorflow and I have found an example in Tensorflow 1.x that I think it is very difficult to migrate to Tensorflow 2.x, so I have decided to use it in its original version.
You can find the code on this github: Omniglot Character Set Classification Using Prototypical Network
I want to change the Flatten layer with a Global average pooling layer to this code:
def get_embeddings(support_set, h_dim, z_dim, reuse=False):
net = convolution_block(support_set, h_dim)
net = convolution_block(net, h_dim)
net = convolution_block(net, h_dim)
net = convolution_block(net, z_dim)
net = tf.compat.v1.layers.flatten(net)
return net
On Tensorflow 2.x, I know that the function I want to use is GlobalAveragePooling2D , but I can't find a function with the same name on Tensorflow 1.x. I have found this AveragePooling2D .
Is AveragePooling2D the same a GlobalAveragePooling2D?
if you can't access to GlobalAveragePooling2D , remember that you can do it simply defining your own lambda layer to do the same operation
x = np.random.uniform(0,1, (2,224,224,3)).astype('float32')
GlobalAveragePooling2D()(x)
# the same as
Lambda(lambda x: tf.reduce_mean(x, axis=[1,2]))(x)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.