ZeroPadding2D 类tf_keras.layers.ZeroPadding2D(padding=(1, 1), data_format=None, **kwargs)
用于2D输入(例如图像)的零填充层。
此层可以在图像张量的顶部、底部、左侧和右侧添加零行和零列。
示例
>>> input_shape = (1, 1, 2, 2)
>>> x = np.arange(np.prod(input_shape)).reshape(input_shape)
>>> print(x)
[[[[0 1]
[2 3]]]]
>>> y = tf.keras.layers.ZeroPadding2D(padding=1)(x)
>>> print(y)
tf.Tensor(
[[[[0 0]
[0 0]
[0 0]
[0 0]]
[[0 0]
[0 1]
[2 3]
[0 0]]
[[0 0]
[0 0]
[0 0]
[0 0]]]], shape=(1, 3, 4, 2), dtype=int64)
参数
(height_symmetric_pad, width_symmetric_pad)。((top_pad, bottom_pad), (left_pad, right_pad))channels_last(默认)或 channels_first。输入维度中的排序方式。channels_last 对应于形状为 (batch_size, height, width, channels) 的输入,而 channels_first 对应于形状为 (batch_size, channels, height, width) 的输入。未指定时,将使用您的 TF-Keras 配置文件 ~/.keras/keras.json 中的 image_data_format 值(如果存在),否则默认为 'channels_last'。默认为 'channels_last'。输入形状
形状为 4D 张量: - 如果 data_format 为 "channels_last":(batch_size, rows, cols, channels) - 如果 data_format 为 "channels_first":(batch_size, channels, rows, cols)
输出形状
4D张量,形状为:- 如果 data_format 是 "channels_last":(batch_size, padded_rows, padded_cols, channels) - 如果 data_format 是 "channels_first":(batch_size, channels, padded_rows, padded_cols)