Keras 2 API 文件 / 層 API / 形狀重塑層 / UpSampling2D 層

UpSampling2D 層

[來源]

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)

參數

  • size:整數或兩個整數的元組。列和欄的上採樣因子。
  • data_format:字串,可以是 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'。
  • interpolation:字串,可以是 "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)