x = tf.reshape(x, [1,3,4,1]) avg_pool_2d = tf.keras.layers.AveragePooling2D(pool_size=(2,2), strides=(2,2), padding='valid') avg_pool_2d(x) <tf.Tensor:shape=(1,1,2,1), dtype=float32, numpy= array([[[3.5], [5.5]]], dtype=float32)> 例如,对于strides=(1, 1)和pa...
前: y = tf.compat.v1.layers.average_pooling2d(x, pool_size=2, strides=2) 后: 要使用 TF1 函数层迁移代码,请使用 Keras 函数 API: x = tf.keras.Input((28,28,1)) y = tf.keras.layers.AveragePooling2D(pool_size=2, strides=2)(x) model = tf.keras.Model(x, y)...
x = tf.random.normal(input_shape) y = tf.keras.layers.GlobalAveragePooling2D()(x) print(y.shape) (2,3) 输入形状: 如果data_format='channels_last':形状为(batch_size, rows, cols, channels)的 4D 张量。 如果data_format='channels_first':形状为(batch_size, channels, rows, cols)的 4D ...