Suk*_*mar 3 keras tensorflow tf.keras tensorflow2.0
我正在尝试实现一个 GlobalMaxPooling2D 层。我有一个 10x10x128 输入,希望将其简化为形状为 1x1x128 的 3D 张量。我尝试使用 keepdims=True,但它会抛出一个
TypeError: ('Keyword argument not understood:', 'keepdims')
Run Code Online (Sandbox Code Playgroud)
我也尝试添加 data_format 但没有效果(这是默认的“channel_last”)。这是 GlobalMaxPooling2D 的代码
ug = layers.GlobalMaxPooling2D(data_format='channel_last',keepdims=True)(inputs)
Run Code Online (Sandbox Code Playgroud)
输入变量是 2D 转换操作的输出:
conv4 = layers.Conv2D(filters=128, kernel_size=3, strides=1, padding='valid', activation='relu', name='conv4')(conv3)
Run Code Online (Sandbox Code Playgroud)
由于这个 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)
Run Code Online (Sandbox Code Playgroud)
从 开始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)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
7892 次 |
| 最近记录: |