Keras 3 API 文档 / 层 API / 重塑层 / UpSampling2D 层

UpSampling2D 层

[source]

UpSampling2D class

keras.layers.UpSampling2D(
    size=(2, 2), data_format=None, interpolation="nearest", **kwargs
)

二维输入的上采样层.

该实现使用插值调整大小,给定调整方法(由 interpolation 参数指定).使用 interpolation=nearest 来重复数据的行和列.

示例:

>>> 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 = keras.layers.UpSampling2D(size=(1, 2))(x)
>>> print(y)
[[[[ 0  1  2]
   [ 0  1  2]]
  [[ 3  4  5]
   [ 3  4  5]]]
 [[[ 6  7  8]
   [ 6  7  8]]
  [[ 9 10 11]
   [ 9 10 11]]]]

参数: size: 整数,或两个整数的元组. 行和列的上采样因子. data_format: 字符串, 可以是 "channels_last"(默认)或 "channels_first". 输入中维度的顺序. "channels_last" 对应输入形状 (batch_size, height, width, channels),而 "channels_first" 对应输入形状 (batch_size, channels, height, width). 如果未指定,使用在您的 Keras 配置文件中找到的 image_data_format 值,路径为 ~/.keras/keras.json(如果存在),否则为 "channels_last". 默认为 "channels_last". interpolation: 字符串,可以是 "bicubic""bilinear""lanczos3""lanczos5""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)