gpt4 book ai didi

tensorflow - 凯拉斯 GlobalMaxPooling2D 类型错误 : ('Keyword argument not understood:' , 'keepdims' )

转载 作者:行者123 更新时间:2023-12-04 14:06:28 29 4
gpt4 key购买 nike

我正在尝试实现一个 GlobalMaxPooling2D 层。我有一个 10x10x128 输入,并希望将其缩减为形状为 1x1x128 的 3D 张量。我尝试使用 keepdims=True,但它抛出一个

TypeError: ('Keyword argument not understood:', 'keepdims')

我也尝试过添加 data_format 但无济于事(这是默认的“channel_last”)。这是 GlobalMaxPooling2D 的代码

ug = layers.GlobalMaxPooling2D(data_format='channel_last',keepdims=True)(inputs)

输入变量是二维转换操作的输出:

conv4 = layers.Conv2D(filters=128, kernel_size=3, strides=1, padding='valid', activation='relu', name='conv4')(conv3)

我是因为这个 Conv 层还是在调用 GlobalMaxPooling2D 层时弄乱了某个地方?有没有办法从 GlobalMaxPooling2D 层获得 1x1x128 的输出?

最佳答案

对于 tf < 2.6 , 你可以这样做

import tensorflow as tf; print(tf.__version__)

input_shape = (1, 10, 10, 128)
x = tf.random.normal(input_shape)
y = tf.keras.layers.GlobalMaxPool2D()(x)
z = tf.keras.layers.Reshape((1, 1, input_shape[-1]))(y)

print(x.shape)
print(y.shape)
print(z.shape)
2.5.0
(1, 10, 10, 128)
(1, 128)
(1, 1, 1, 128)

来自tf > = 2.6 , 你可以使用 keepdims参数。

!pip install tensorflow==2.6.0rc0 -q

import tensorflow as tf; print(tf.__version__)

input_shape = (1, 10, 10, 128)
x = tf.random.normal(input_shape)
y = tf.keras.layers.GlobalMaxPool2D(keepdims=True)(x)

print(x.shape)
print(y.shape)

2.6.0-rc0
(1, 10, 10, 128)
(1, 1, 1, 128)

关于tensorflow - 凯拉斯 GlobalMaxPooling2D 类型错误 : ('Keyword argument not understood:' , 'keepdims' ),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68287879/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com