UpSampling2D 类tf_keras.layers.UpSampling2D(
size=(2, 2), data_format=None, interpolation="nearest", **kwargs
)
用于 2D 输入的上采样层。
通过分别复制数据行和列 size[0] 次和 size[1] 次来实现。
示例
>>> input_shape = (2, 2, 1, 3)
>>> x = np.arange(np.prod(input_shape)).reshape(input_shape)
>>> print(x)
[[[[ 0 1 2]]
[[ 3 4 5]]]
[[[ 6 7 8]]
[[ 9 10 11]]]]
>>> y = tf.keras.layers.UpSampling2D(size=(1, 2))(x)
>>> print(y)
tf.Tensor(
[[[[ 0 1 2]
[ 0 1 2]]
[[ 3 4 5]
[ 3 4 5]]]
[[[ 6 7 8]
[ 6 7 8]]
[[ 9 10 11]
[ 9 10 11]]]], shape=(2, 2, 2, 3), dtype=int64)
参数
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'。"area", "bicubic", "bilinear", "gaussian", "lanczos3", "lanczos5", "mitchellcubic", "nearest"。输入形状
形状为 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, upsampled_rows, upsampled_cols, channels) - 如果 data_format 为 "channels_first":(batch_size, channels, upsampled_rows, upsampled_cols)