深度學習入門-框架keras-5keras卷積層介紹

Conv1D

keras.layers.Conv1D(filters, kernel_size, strides=1, padding='valid', dilation_rate=1, activation=None, use_bias=True, kernel_initializer='glorot_uniform', bias_initializer='zeros', kernel_regularizer=None, bias_regularizer=None, activity_regularizer=None, kernel_constraint=None, bias_constraint=None)

1D 卷積層 (例如時序卷積)。
該層創建了一個卷積核,該卷積核以單個空間(或時間)維上的層輸入進行卷積, 以生成輸出張量。如果use_bias爲True, 則會創建一個偏置向量並將其添加到輸出中。 最後,如果 activation 不是 None,它也會應用於輸出。
參數

  • filters: 整數,輸出空間的維度 (即卷積中濾波器的輸出數量)。
  • kernel_size: 一個整數,或者單個整數表示的元組或列表, 指明 1D 卷積窗口的長度。
  • strides: 一個整數,或者單個整數表示的元組或列表, 指明卷積的步長。 指定任何 stride 值 != 1 與指定 dilation_rate 值 != 1 兩者不兼容。
  • padding: “valid”, “causal” 或 “same” 之一 (大小寫敏感) “valid” 表示「不填充」。 “same” 表示填充輸入以使輸出具有與原始輸入相同的長度。 “causal” 表示因果(膨脹)卷積, 例如,output[t] 不依賴於 input[t+1:], 在模型不應違反時間順序的時間數據建模時非常有用。
  • dilation_rate: 一個整數,或者單個整數表示的元組或列表,指定用於膨脹卷積的膨脹率。 當前,指定任何 dilation_rate 值 != 1 與指定 stride 值 != 1 兩者不兼容。
  • activation: 要使用的激活函數。 如果你不指定,則不使用激活函數 (即線性激活: a(x) = x)。
  • use_bias: 布爾值,該層是否使用偏置向量。
  • kernel_initializer: kernel 權值矩陣的初始化器 (詳見 initializers)。
  • bias_initializer: 偏置向量的初始化器 (詳見 initializers)。
  • kernel_regularizer: 運用到 kernel 權值矩陣的正則化函數 (詳見 regularizer)。
  • bias_regularizer: 運用到偏置向量的正則化函數 (詳見 regularizer)。
  • activity_regularizer: 運用到層輸出(它的激活值)的正則化函數 (詳見 regularizer)。
  • kernel_constraint: 運用到 kernel 權值矩陣的約束函數 (詳見 constraints)。
  • bias_constraint: 運用到偏置向量的約束函數 (詳見 constraints)。

輸入尺寸
3D 張量 ,尺寸爲 (batch_size, steps, input_dim)。
輸出尺寸
3D 張量,尺寸爲 (batch_size, new_steps, filters)。 由於填充或窗口按步長滑動,steps 值可能已更改。

Conv2D

keras.layers.Conv2D(filters, kernel_size, strides=(1, 1), padding='valid', data_format=None, dilation_rate=(1, 1), activation=None, use_bias=True, kernel_initializer='glorot_uniform', bias_initializer='zeros', kernel_regularizer=None, bias_regularizer=None, activity_regularizer=None, kernel_constraint=None, bias_constraint=None)

2D 卷積層 (例如對圖像的空間卷積)。

該層創建了一個卷積核, 該卷積覈對層輸入進行卷積,以生成輸出張量。 如果 use_bias 爲 True,則會創建一個偏置向量並將其添加到輸出中。 最後,如果 activation 不是 None,它也會應用於輸出。

參數

  • filters: 整數,輸出空間的維度 (即卷積中濾波器的輸出數量)。
  • kernel_size: 一個整數,或者 2 個整數表示的元組或列表, 指明 2D 卷積窗口的寬度和高度。 可以是一個整數,爲所有空間維度指定相同的值。
  • strides: 一個整數,或者 2 個整數表示的元組或列表, 指明卷積沿寬度和高度方向的步長。 可以是一個整數,爲所有空間維度指定相同的值。 指定任何 stride 值 != 1 與指定 dilation_rate 值 != 1 兩者不兼容。
  • padding: “valid” 或 “same” (大小寫敏感)。
  • data_format: 字符串, channels_last(默認) 或 channels_first之一,表示輸入中維度的順序。 channels_last對應輸入尺寸爲 (batch, height, width, channels)channels_first對應輸入尺寸爲(batch, channels, height, width)。 它默認爲從 Keras 配置文件 ~/.keras/keras.json 中 找到的 image_data_format 值。 如果你從未設置它,將使用 “channels_last”。
  • dilation_rate: 一個整數或 2 個整數的元組或列表, 指定膨脹卷積的膨脹率。 可以是一個整數,爲所有空間維度指定相同的值。 當前,指定任何 dilation_rate 值 != 1 與 指定 stride 值 != 1 兩者不兼容。
  • activation: 要使用的激活函數 (詳見 activations)。 如果你不指定,則不使用激活函數 (即線性激活: a(x) = x)。
  • use_bias: 布爾值,該層是否使用偏置向量。
  • kernel_initializer: kernel 權值矩陣的初始化器 (詳見 initializers)。
  • bias_initializer: 偏置向量的初始化器 (詳見 initializers)。
  • kernel_regularizer: 運用到 kernel 權值矩陣的正則化函數 (詳見 regularizer)。
  • bias_regularizer: 運用到偏置向量的正則化函數 (詳見 regularizer)。
  • activity_regularizer: 運用到層輸出(它的激活值)的正則化函數 (詳見 regularizer)。
  • kernel_constraint: 運用到 kernel 權值矩陣的約束函數 (詳見 constraints)。
  • bias_constraint: 運用到偏置向量的約束函數 (詳見 constraints)。

輸入尺寸
如果 data_format=‘channels_first’, 輸入 4D 張量,尺寸爲 (samples, channels, rows, cols)。
如果 data_format=‘channels_last’, 輸入 4D 張量,尺寸爲 (samples, rows, cols, channels)
輸出尺寸
如果 data_format=‘channels_first’, 輸出 4D 張量,尺寸爲(samples, filters, new_rows, new_cols)
如果data_format='channels_last', 輸出 4D 張量,尺寸爲(samples, new_rows, new_cols, filters)
由於填充的原因, rows 和 cols 值可能已更改。

Conv3D

keras.layers.Conv3D(filters, kernel_size, strides=(1, 1, 1), padding='valid', data_format=None, dilation_rate=(1, 1, 1), activation=None, use_bias=True, kernel_initializer='glorot_uniform', bias_initializer='zeros', kernel_regularizer=None, bias_regularizer=None, activity_regularizer=None, kernel_constraint=None, bias_constraint=None)

3D 卷積層 (例如立體空間卷積)。

該層創建了一個卷積核, 該卷積覈對層輸入進行卷積, 以生成輸出張量。 如果 use_bias 爲 True, 則會創建一個偏置向量並將其添加到輸出中。 最後,如果 activation 不是 None,它也會應用於輸出。

參數

  • filters: 整數,輸出空間的維度 (即卷積中濾波器的輸出數量)。
  • kernel_size: 一個整數,或者 3 個整數表示的元組或列表, 指明 3D 卷積窗口的深度、高度和寬度。 可以是一個整數,爲所有空間維度指定相同的值。
  • strides: 一個整數,或者 3 個整數表示的元組或列表, 指明卷積沿每一個空間維度的步長。 可以是一個整數,爲所有空間維度指定相同的步長值。 指定任何 stride 值 != 1 與指定 dilation_rate 值 != 1 兩者不兼容。
  • padding: “valid” 或 “same” (大小寫敏感)。
  • data_format: 字符串, channels_last (默認) 或 channels_first 之一, 表示輸入中維度的順序。channels_last 對應輸入尺寸爲 (batch, spatial_dim1, spatial_dim2, spatial_dim3, channels), channels_first 對應輸入尺寸爲 (batch, channels, spatial_dim1, spatial_dim2, spatial_dim3)。 它默認爲從 Keras 配置文件 ~/.keras/keras.json 中 找到的 image_data_format 值。 如果你從未設置它,將使用 “channels_last”。
  • dilation_rate: 一個整數或 3 個整數的元組或列表, 指定膨脹卷積的膨脹率。 可以是一個整數,爲所有空間維度指定相同的值。 當前,指定任何 dilation_rate 值 != 1 與 指定 stride 值 != 1 兩者不兼容。
    activation: 要使用的激活函數 (詳見 activations)。 如果你不指定,則不使用激活函數 (即線性激活: a(x) = x)。
  • use_bias: 布爾值,該層是否使用偏置向量。
  • kernel_initializer: kernel 權值矩陣的初始化器 (詳見 initializers)。
  • bias_initializer: 偏置向量的初始化器 (詳見 initializers)。
  • kernel_regularizer: 運用到 kernel 權值矩陣的正則化函數 (詳見 regularizer)。
  • bias_regularizer: 運用到偏置向量的正則化函數 (詳見 regularizer)。
  • activity_regularizer: 運用到層輸出(它的激活值)的正則化函數 (詳見 regularizer)。
  • kernel_constraint: 運用到 kernel 權值矩陣的約束函數 (詳見 constraints)。
  • bias_constraint: 運用到偏置向量的約束函數 (詳見 constraints)。

輸入尺寸
如果 data_format=‘channels_first’, 輸入 5D 張量,尺寸爲 (samples, channels, conv_dim1, conv_dim2, conv_dim3)。
如果 data_format=‘channels_last’, 輸入 5D 張量,尺寸爲 (samples, conv_dim1, conv_dim2, conv_dim3, channels)。

輸出尺寸
如果 data_format=‘channels_first’, 輸出 5D 張量,尺寸爲 (samples, filters, new_conv_dim1, new_conv_dim2, new_conv_dim3)。
如果 data_format=‘channels_last’, 輸出 5D 張量,尺寸爲 (samples, new_conv_dim1, new_conv_dim2, new_conv_dim3, filters)。
由於填充的原因, new_conv_dim1, new_conv_dim2 和 new_conv_dim3 值可能已更改。

SeparableConv1D

keras.layers.SeparableConv1D(filters, kernel_size, strides=1, padding='valid', data_format=None, dilation_rate=1, depth_multiplier=1, activation=None, use_bias=True, depthwise_initializer='glorot_uniform', pointwise_initializer='glorot_uniform', bias_initializer='zeros', depthwise_regularizer=None, pointwise_regularizer=None, bias_regularizer=None, activity_regularizer=None, depthwise_constraint=None, pointwise_constraint=None, bias_constraint=None)

深度方向的可分離 1D 卷積。

原理和rgb照片拆分成三個單色通道一樣。根據對單通道進行卷積,再組合起來,實現通道與區域的分離
可分離的卷積的操作包括,首先執行深度方向的空間卷積 (分別作用於每個輸入通道),緊接一個將所得輸出通道 混合在一起的逐點卷積。depth_multiplier 參數控 制深度步驟中每個輸入通道生成多少個輸出通道。

直觀地說,可分離的卷積可以理解爲一種將卷積核分解成兩個較小的卷積核的方法,或者作爲 Inception 塊的 一個極端版本。
參數

  • filters: 整數,輸出空間的維度 (即卷積中濾波器的輸出數量)。
  • kernel_size: 一個整數,或者單個整數表示的元組或列表, 指明 1D 卷積窗口的長度。
  • strides: 一個整數,或者單個整數表示的元組或列表, 指明卷積的步長。 指定任何 stride 值 != 1 與指定 dilation_rate 值 != 1 兩者不兼容。
  • padding: “valid” 或 “same” (大小寫敏感)。
  • data_format: 字符串, channels_last (默認) 或 channels_first 之一,表示輸入中維度的順序。 channels_last 對應輸入尺寸爲 (batch, height, width, channels), channels_first 對應輸入尺寸爲 (batch, channels, height, width)。 它默認爲從 Keras 配置文件 ~/.keras/keras.json 中 找到的 image_data_format 值。 如果你從未設置它,將使用 “channels_last”。
  • dilation_rate: 一個整數,或者單個整數表示的元組或列表, 爲使用擴張(空洞)卷積指明擴張率。 目前,指定任何 dilation_rate 值 != 1 與指定任何 stride 值 != 1 兩者不兼容。
  • depth_multiplier: 每個輸入通道的深度方向卷積輸出通道的數量。 深度方向卷積輸出通道的總數將等於 filterss_in * depth_multiplier。
  • activation: 要使用的激活函數 (詳見 activations)。 如果你不指定,則不使用激活函數 (即線性激活: a(x) = x)。
  • use_bias: 布爾值,該層是否使用偏置向量。
  • depthwise_initializer: 運用到深度方向的核矩陣的初始化器 (詳見 initializers)。
  • pointwise_initializer: 運用到逐點核矩陣的初始化器 (詳見 initializers)。
  • bias_initializer: 偏置向量的初始化器 (詳見 initializers)。
  • depthwise_regularizer: 運用到深度方向的核矩陣的正則化函數 (詳見 regularizer)。
  • pointwise_regularizer: 運用到逐點核矩陣的正則化函數 (詳見 regularizer)。
  • bias_regularizer: 運用到偏置向量的正則化函數 (詳見 regularizer)。
  • activity_regularizer: 運用到層輸出(它的激活值)的正則化函數 (詳見 regularizer)。
  • depthwise_constraint: 運用到深度方向的核矩陣的約束函數 (詳見 constraints)。
  • pointwise_constraint: 運用到逐點核矩陣的約束函數 (詳見 constraints)。
  • bias_constraint: 運用到偏置向量的約束函數 (詳見 constraints)。

輸入尺寸

如果 data_format=‘channels_first’, 輸入 3D 張量,尺寸爲 (batch, channels, steps)。
如果 data_format=‘channels_last’, 輸入 3D 張量,尺寸爲 (batch, steps, channels)。
輸出尺寸

如果 data_format=‘channels_first’, 輸出 3D 張量,尺寸爲 (batch, filters, new_steps)。
如果 data_format=‘channels_last’, 輸出 3D 張量,尺寸爲 (batch, new_steps, filters)。

SeparableConv2D

keras.layers.SeparableConv2D(filters, kernel_size, strides=(1, 1), padding='valid', data_format=None, dilation_rate=(1, 1), depth_multiplier=1, activation=None, use_bias=True, depthwise_initializer='glorot_uniform', pointwise_initializer='glorot_uniform', bias_initializer='zeros', depthwise_regularizer=None, pointwise_regularizer=None, bias_regularizer=None, activity_regularizer=None, depthwise_constraint=None, pointwise_constraint=None, bias_constraint=None)

深度方向的可分離 2D 卷積。

可分離的卷積的操作包括,首先執行深度方向的空間卷積 (分別作用於每個輸入通道),緊接一個將所得輸出通道 混合在一起的逐點卷積。depth_multiplier 參數控 制深度步驟中每個輸入通道生成多少個輸出通道。

直觀地說,可分離的卷積可以理解爲一種將卷積核分解成 兩個較小的卷積核的方法,或者作爲 Inception 塊的 一個極端版本。

Conv2DTranspose

keras.layers.Conv2DTranspose(filters, kernel_size, strides=(1, 1), padding='valid', data_format=None, activation=None, use_bias=True, kernel_initializer='glorot_uniform', bias_initializer='zeros', kernel_regularizer=None, bias_regularizer=None, activity_regularizer=None, kernel_constraint=None, bias_constraint=None)

轉置卷積層 (有時被成爲反捲積)。

鏈接:https://blog.csdn.net/qq_38906523/article/details/80520950

對轉置卷積的需求一般來自希望使用 與正常卷積相反方向的變換, 即,將具有卷積輸出尺寸的東西 轉換爲具有卷積輸入尺寸的東西, 同時保持與所述卷積相容的連通性模式。

當使用該層作爲模型第一層時,需要提供 input_shape 參數 (整數元組,不包含樣本表示的軸),例如, input_shape=(128, 128, 3) 表示 128x128 RGB 圖像, 在 data_format=“channels_last” 時。

Cropping1D

keras.layers.Cropping1D(cropping=(1, 1))

1D 輸入的裁剪層(例如時間序列)。

它沿着時間維度(第 1 個軸)裁剪。

參數
cropping: 整數或整數元組(長度爲 2)。 在裁剪維度(第 1 個軸)的開始和結束位置 應該裁剪多少個單位。 如果只提供了一個整數,那麼這兩個位置將使用 相同的值。
輸入尺寸
3D 張量,尺寸爲 (batch, axis_to_crop, features)。
輸出尺寸
3D 張量,尺寸爲 (batch, cropped_axis, features)。

Cropping2D

keras.layers.Cropping2D(cropping=((0, 0), (0, 0)), data_format=None)

2D 輸入的裁剪層(例如圖像)。
它沿着空間維度裁剪,即寬度和高度。
參數

  • cropping: 整數,或 2 個整數的元組,或 2 個整數的 2 個元組。
    如果爲整數: 將對寬度和高度應用相同的對稱裁剪。如果爲 2 個整數的元組: 解釋爲對高度和寬度的兩個不同的對稱裁剪值: (symmetric_height_crop, symmetric_width_crop)
    如果爲 2 個整數的 2 個元組: 解釋爲 ((top_crop, bottom_crop), (left_crop, right_crop))
  • data_format: 字符串, channels_last (默認) 或 channels_first 之一, 表示輸入中維度的順序。channels_last 對應輸入尺寸爲 (batch, height, width, channels), channels_first 對應輸入尺寸爲 (batch, channels, height, width)。 它默認爲從 Keras 配置文件 ~/.keras/keras.json 中 找到的 image_data_format 值。 如果你從未設置它,將使用 “channels_last”。
    輸出尺寸
    如果 data_format=‘channels_first’, 輸出 4D 張量,尺寸爲 (batch, filters, new_rows, new_cols)。
    由於填充的原因, rows 和 cols 值可能已更改。

輸入尺寸
如果 data_format 爲 “channels_last”, 輸入 4D 張量,尺寸爲 (batch, rows, cols, channels)。
如果 data_format 爲 “channels_first”, 輸入 4D 張量,尺寸爲 (batch, channels, rows, cols)。
輸出尺寸
如果 data_format 爲 “channels_last”, 輸出 4D 張量,尺寸爲 (batch, cropped_rows, cropped_cols, channels)
如果 data_format 爲 “channels_first”, 輸出 4D 張量,尺寸爲 (batch, channels, cropped_rows, cropped_cols)。
例子


# 裁剪輸入的 2D 圖像或特徵圖
model = Sequential()
model.add(Cropping2D(cropping=((2, 2), (4, 4)),
                     input_shape=(28, 28, 3)))
# 現在 model.output_shape == (None, 24, 20, 3)
model.add(Conv2D(64, (3, 3), padding='same'))
model.add(Cropping2D(cropping=((2, 2), (2, 2))))
# 現在 model.output_shape == (None, 20, 16. 64)

Cropping3D

keras.layers.Cropping3D(cropping=((1, 1), (1, 1), (1, 1)), data_format=None)

3D 數據的裁剪層(例如空間或時空)。

參數

  • cropping: 整數,或 3 個整數的元組,或 2 個整數的 3 個元組。
  • 如果爲整數: 將對深度、高度和寬度應用相同的對稱裁剪。
  • 如果爲 3 個整數的元組: 解釋爲對深度、高度和高度的 3 個不同的對稱裁剪值: (symmetric_dim1_crop, symmetric_dim2_crop, symmetric_dim3_crop)。
  • 如果爲 2 個整數的 3 個元組: 解釋爲 ((left_dim1_crop, right_dim1_crop), (left_dim2_crop, right_dim2_crop), (left_dim3_crop, right_dim3_crop))。
  • data_format: 字符串, channels_last (默認) 或 channels_first 之一, 表示輸入中維度的順序。channels_last 對應輸入尺寸爲 (batch, spatial_dim1, spatial_dim2, spatial_dim3, channels), channels_first 對應輸入尺寸爲 (batch, channels, spatial_dim1, spatial_dim2, spatial_dim3)。 它默認爲從 Keras 配置文件 ~/.keras/keras.json 中 找到的 image_data_format 值。 如果你從未設置它,將使用 “channels_last”。
    輸入尺寸
    如果 data_format 爲 “channels_last”, 輸入 5D 張量,尺寸爲 (batch, first_axis_to_crop, second_axis_to_crop, third_axis_to_crop, depth)。
    如果 data_format 爲 “channels_first”, 輸入 5D 張量,尺寸爲 (batch, depth, first_axis_to_crop, second_axis_to_crop, third_axis_to_crop)。
    輸出尺寸
    如果 data_format 爲 “channels_last”, 輸出 5D 張量,尺寸爲 (batch, first_cropped_axis, second_cropped_axis, third_cropped_axis, depth)
    如果 data_format 爲 “channels_first”, 輸出 5D 張量,尺寸爲 (batch, depth, first_cropped_axis, second_cropped_axis, third_cropped_axis)。

UpSampling1D

放大圖像

keras.layers.UpSampling1D(size=2)

1D 輸入的上採樣層。(另有下采樣層:圖像的上採樣(upsampling)與下采樣(subsampled),用於縮小圖像)
放大圖像(或稱爲上採樣(upsampling)或圖像插值(interpolating))的主要目的是放大原圖像,從而可以顯示在更高分辨率的顯示設備上。對圖像的縮放操作並不能帶來更多關於該圖像的信息, 因此圖像的質量將不可避免地受到影響。然而,確實有一些縮放方法能夠增加圖像的信息,從而使得縮放後的圖像質量超過原圖質量的。
沿着時間軸重複每個時間步 size 次。
參數
size: 整數。上採樣因子。
輸入尺寸
3D 張量,尺寸爲 (batch, steps, features)。
輸出尺寸
3D 張量,尺寸爲 (batch, upsampled_steps, features)。

UpSampling2D

keras.layers.UpSampling2D(size=(2, 2), data_format=None)

2D 輸入的上採樣層。
沿着數據的行和列分別重複 size[0] 和 size[1] 次。
參數
size: 整數,或 2 個整數的元組。 行和列的上採樣因子。
data_format: 字符串, channels_last (默認) 或 channels_first 之一, 表示輸入中維度的順序。channels_last 對應輸入尺寸爲 (batch, height, width, channels), channels_first 對應輸入尺寸爲 (batch, channels, height, width)。 它默認爲從 Keras 配置文件 ~/.keras/keras.json 中 找到的 image_data_format 值。 如果你從未設置它,將使用 “channels_last”。

輸入尺寸
如果 data_format 爲 “channels_last”, 輸入 4D 張量,尺寸爲 (batch, rows, cols, channels)。
如果 data_format 爲 “channels_first”, 輸入 4D 張量,尺寸爲 (batch, channels, rows, cols)。
輸出尺寸
如果 data_format 爲 “channels_last”, 輸出 4D 張量,尺寸爲 (batch, upsampled_rows, upsampled_cols, channels)。
如果 data_format 爲 “channels_first”, 輸出 4D 張量,尺寸爲 (batch, channels, upsampled_rows, upsampled_cols)。
[source]

UpSampling3D

keras.layers.UpSampling3D(size=(2, 2, 2), data_format=None)

3D 輸入的上採樣層。

沿着數據的第 1、2、3 維度分別重複 size[0]、size[1] 和 size[2] 次。

參數
size: 整數,或 3 個整數的元組。 dim1, dim2 和 dim3 的上採樣因子。
data_format: 字符串, channels_last (默認) 或 channels_first 之一, 表示輸入中維度的順序。channels_last 對應輸入尺寸爲 (batch, spatial_dim1, spatial_dim2, spatial_dim3, channels), channels_first 對應輸入尺寸爲 (batch, channels, spatial_dim1, spatial_dim2, spatial_dim3)。 它默認爲從 Keras 配置文件 ~/.keras/keras.json 中 找到的 image_data_format 值。 如果你從未設置它,將使用 “channels_last”。

輸入尺寸
如果 data_format 爲 “channels_last”, 輸入 5D 張量,尺寸爲 (batch, dim1, dim2, dim3, channels)。
如果 data_format 爲 “channels_first”, 輸入 5D 張量,尺寸爲 (batch, channels, dim1, dim2, dim3)。
輸出尺寸
如果 data_format 爲 “channels_last”, 輸出 5D 張量,尺寸爲 (batch, upsampled_dim1, upsampled_dim2, upsampled_dim3, channels)。
如果 data_format 爲 “channels_first”, 輸出 5D 張量,尺寸爲 (batch, channels, upsampled_dim1, upsampled_dim2, upsampled_dim3)。

ZeroPadding1D

首尾端填充0,控制卷積以後向量的長度

keras.layers.ZeroPadding1D(padding=1)

1D 輸入的零填充層(例如,時間序列)。
對1D輸入的首尾端(如時域序列)填充0,以控制卷積以後向量的長度
參數
padding: 整數,或長度爲 2 的整數元組,或字典。
如果爲整數: 在填充維度(第一個軸)的開始和結束處添加多少個零。
長度爲 2 的整數元組: 在填充維度的開始和結尾處添加多少個零 ((left_pad, right_pad))。
輸入尺寸
3D 張量,尺寸爲 (batch, axis_to_pad, features)。
輸出尺寸
3D 張量,尺寸爲 (batch, padded_axis, features)。

ZeroPadding2D

keras.layers.ZeroPadding2D(padding=(1, 1), data_format=None)

2D 輸入的零填充層(例如圖像)。
對2D輸入(如圖片)的邊界填充0,以控制卷積以後特徵圖的大小
該圖層可以在圖像張量的頂部、底部、左側和右側添加零表示的行和列。

參數
padding: 整數,或 2 個整數的元組,或 2 個整數的 2 個元組。
如果爲整數:將對寬度和高度運用相同的對稱填充。
如果爲 2 個整數的元組:
如果爲整數:: 解釋爲高度和高度的 2 個不同的對稱裁剪值: (symmetric_height_pad, symmetric_width_pad)。
如果爲 2 個整數的 2 個元組: 解釋爲 ((top_pad, bottom_pad), (left_pad, right_pad))。
data_format: 字符串, channels_last (默認) 或 channels_first 之一, 表示輸入中維度的順序。channels_last 對應輸入尺寸爲 (batch, height, width, channels), channels_first 對應輸入尺寸爲 (batch, channels, height, width)。 它默認爲從 Keras 配置文件 ~/.keras/keras.json 中 找到的 image_data_format 值。 如果你從未設置它,將使用 “channels_last”。

輸入尺寸
如果 data_format 爲 “channels_last”, 輸入 4D 張量,尺寸爲 (batch, rows, cols, channels)。
如果 data_format 爲 “channels_first”, 輸入 4D 張量,尺寸爲 (batch, channels, rows, cols)。
輸出尺寸
如果 data_format 爲 “channels_last”, 輸出 4D 張量,尺寸爲 (batch, padded_rows, padded_cols, channels)。
如果 data_format 爲 “channels_first”, 輸出 4D 張量,尺寸爲 (batch, channels, padded_rows, padded_cols)。

ZeroPadding3D

keras.layers.ZeroPadding3D(padding=(1, 1, 1), data_format=None)

3D 數據的零填充層(空間或時空)。
將數據的三個維度上填充0
參數
padding: 整數,或 3 個整數的元組,或 2 個整數的 3 個元組。
如果爲整數:將對深度、高度和寬度運用相同的對稱填充。
如果爲 3 個整數的元組: 解釋爲深度、高度和寬度的三個不同的對稱填充值: (symmetric_dim1_pad, symmetric_dim2_pad, symmetric_dim3_pad).
如果爲 2 個整數的 3 個元組:解釋爲 ((left_dim1_pad, right_dim1_pad), (left_dim2_pad, right_dim2_pad), (left_dim3_pad, right_dim3_pad))
data_format: 字符串, channels_last (默認) 或 channels_first 之一, 表示輸入中維度的順序。channels_last 對應輸入尺寸爲 (batch, spatial_dim1, spatial_dim2, spatial_dim3, channels), channels_first 對應輸入尺寸爲 (batch, channels, spatial_dim1, spatial_dim2, spatial_dim3)。 它默認爲從 Keras 配置文件 ~/.keras/keras.json 中 找到的 image_data_format 值。 如果你從未設置它,將使用 “channels_last”。
輸入尺寸

如果 data_format 爲 “channels_last”, 輸入 5D 張量,尺寸爲 (batch, first_axis_to_pad, second_axis_to_pad, third_axis_to_pad, depth)。
如果 data_format 爲 “channels_first”, 輸入 5D 張量,尺寸爲 (batch, depth, first_axis_to_pad, second_axis_to_pad, third_axis_to_pad)。
輸出尺寸

如果 data_format 爲 “channels_last”, 輸出 5D 張量,尺寸爲 (batch, first_padded_axis, second_padded_axis, third_axis_to_pad, depth)。
如果 data_format 爲 “channels_first”, 輸出 5D 張量,尺寸爲 (batch, depth, first_padded_axis, second_padded_axis, third_axis_to_pad)。

MaxPooling1D

keras.layers.MaxPooling1D(pool_size=2, strides=None, padding='valid')

對於時序數據的最大池化。

參數
pool_size: 整數,最大池化的窗口大小。
strides: 整數,或者是 None。作爲縮小比例的因數。 例如,2 會使得輸入張量縮小一半。 如果是 None,那麼默認值是 pool_size。
padding: “valid” 或者 “same” (區分大小寫)。
輸入尺寸
尺寸是 (batch_size, steps, features) 的 3D 張量。
輸出尺寸
尺寸是 (batch_size, downsampled_steps, features) 的 3D 張量。

MaxPooling2D

keras.layers.MaxPooling2D(pool_size=(2, 2), strides=None, padding='valid', data_format=None)

對於空域數據的最大池化。
參數
pool_size: 整數,或者 2 個整數元組,(垂直方向,水平方向)縮小比例的因數。(2,2)會把輸入張量的兩個維度都縮小一半。 如果只使用一個整數,那麼兩個維度都會使用同樣的窗口長度。
strides: 整數,整數元組或者是 None。 步長值。 如果是 None,那麼默認值是 pool_size。
padding: “valid” 或者 “same” (區分大小寫)。
data_format: 一個字符串,channels_last (默認值)或者 channels_first。 輸入張量中的維度順序。 channels_last 代表尺寸是 (batch, height, width, channels) 的輸入張量,而 channels_first 代表尺寸是 (batch, channels, height, width) 的輸入張量。 默認值根據 Keras 配置文件 ~/.keras/keras.json 中的 image_data_format 值來設置。 如果還沒有設置過,那麼默認值就是 “channels_last”。
輸入尺寸
如果 data_format=‘channels_last’: 尺寸是 (batch_size, rows, cols, channels) 的 4D 張量
如果 data_format=‘channels_first’: 尺寸是 (batch_size, channels, rows, cols) 的 4D 張量
輸出尺寸
如果 data_format=‘channels_last’: 尺寸是 (batch_size, pooled_rows, pooled_cols, channels) 的 4D 張量
如果 data_format=‘channels_first’: 尺寸是 (batch_size, channels, pooled_rows, pooled_cols) 的 4D 張量

MaxPooling3D

keras.layers.MaxPooling3D(pool_size=(2, 2, 2), strides=None, padding='valid', data_format=None)

對於 3D(空域,或時空域)數據的最大池化。
參數
pool_size: 3 個整數的元組,縮小(維度 1,維度 2,維度 3)比例的因數。 (2, 2, 2) 會把 3D 輸入張量的每個維度縮小一半。
strides: 3 個整數的元組,或者是 None。步長值。
padding: “valid” 或者 “same”(區分大小寫)。
data_format: 一個字符串,channels_last (默認值)或者 channels_first。 輸入張量中的維度順序。 channels_last 代表尺寸是 (batch, spatial_dim1, spatial_dim2, spatial_dim3, channels) 的輸入張量, 而 channels_first 代表尺寸是 (batch, channels, spatial_dim1, spatial_dim2, spatial_dim3) 的輸入張量。 默認值根據 Keras 配置文件 ~/.keras/keras.json 中的 image_data_format 值來設置。 如果還沒有設置過,那麼默認值就是 “channels_last”。
輸入尺寸
如果 data_format=‘channels_last’: 尺寸是 (batch_size, spatial_dim1, spatial_dim2, spatial_dim3, channels) 的 5D 張量
如果 data_format=‘channels_first’: 尺寸是 (batch_size, channels, spatial_dim1, spatial_dim2, spatial_dim3) 的 5D 張量
輸出尺寸
如果 data_format=‘channels_last’: 尺寸是 (batch_size, pooled_dim1, pooled_dim2, pooled_dim3, channels) 的 5D 張量
如果 data_format=‘channels_first’: 尺寸是 (batch_size, channels, pooled_dim1, pooled_dim2, pooled_dim3) 的 5D 張量

AveragePooling1D

keras.layers.AveragePooling1D(pool_size=2, strides=None, padding='valid')

對於時序數據的平均池化。
參數
pool_size: 整數,平均池化的窗口大小。
strides: 整數,或者是 None。作爲縮小比例的因數。 例如,2 會使得輸入張量縮小一半。 如果是 None,那麼默認值是 pool_size。
padding: “valid” 或者 “same” (區分大小寫)。
輸入尺寸
尺寸是 (batch_size, steps, features) 的 3D 張量。
輸出尺寸
尺寸是 (batch_size, downsampled_steps, features) 的 3D 張量。

AveragePooling2D

keras.layers.AveragePooling2D(pool_size=(2, 2), strides=None, padding='valid', data_format=None)

對於空域數據的平均池化。
參數
pool_size: 整數,或者 2 個整數元組,(垂直方向,水平方向)縮小比例的因數。(2,2)會把輸入張量的兩個維度都縮小一半。 如果只使用一個整數,那麼兩個維度都會使用同樣的窗口長度。
strides: 整數,整數元組或者是 None。 步長值。 如果是 None,那麼默認值是 pool_size。
padding: “valid” 或者 “same” (區分大小寫)。
data_format: 一個字符串,channels_last (默認值)或者 channels_first。 輸入張量中的維度順序。 channels_last 代表尺寸是 (batch, height, width, channels) 的輸入張量,而 channels_first 代表尺寸是 (batch, channels, height, width) 的輸入張量。 默認值根據 Keras 配置文件 ~/.keras/keras.json 中的 image_data_format 值來設置。 如果還沒有設置過,那麼默認值就是 “channels_last”。
輸入尺寸
如果 data_format=‘channels_last’: 尺寸是 (batch_size, rows, cols, channels) 的 4D 張量
如果 data_format=‘channels_first’: 尺寸是 (batch_size, channels, rows, cols) 的 4D 張量
輸出尺寸
如果 data_format=‘channels_last’: 尺寸是 (batch_size, pooled_rows, pooled_cols, channels) 的 4D 張量
如果 data_format=‘channels_first’: 尺寸是 (batch_size, channels, pooled_rows, pooled_cols) 的 4D 張量

AveragePooling3D

keras.layers.AveragePooling3D(pool_size=(2, 2, 2), strides=None, padding='valid', data_format=None)

對於 3D (空域,或者時空域)數據的平均池化。
參數
pool_size: 3 個整數的元組,縮小(維度 1,維度 2,維度 3)比例的因數。 (2, 2, 2) 會把 3D 輸入張量的每個維度縮小一半。
strides: 3 個整數的元組,或者是 None。步長值。
padding: “valid” 或者 “same”(區分大小寫)。
data_format: 一個字符串,channels_last (默認值)或者 channels_first。 輸入張量中的維度順序。 channels_last 代表尺寸是 (batch, spatial_dim1, spatial_dim2, spatial_dim3, channels) 的輸入張量, 而 channels_first 代表尺寸是 (batch, channels, spatial_dim1, spatial_dim2, spatial_dim3) 的輸入張量。 默認值根據 Keras 配置文件 ~/.keras/keras.json 中的 image_data_format 值來設置。 如果還沒有設置過,那麼默認值就是 “channels_last”。
輸入尺寸
如果 data_format=‘channels_last’: 尺寸是 (batch_size, spatial_dim1, spatial_dim2, spatial_dim3, channels) 的 5D 張量
如果 data_format=‘channels_first’: 尺寸是 (batch_size, channels, spatial_dim1, spatial_dim2, spatial_dim3) 的 5D 張量
輸出尺寸
如果 data_format=‘channels_last’: 尺寸是 (batch_size, pooled_dim1, pooled_dim2, pooled_dim3, channels) 的 5D 張量
如果 data_format=‘channels_first’: 尺寸是 (batch_size, channels, pooled_dim1, pooled_dim2, pooled_dim3) 的 5D 張量

GlobalMaxPooling1D

keras.layers.GlobalMaxPooling1D()

對於時序數據的全局最大池化。
輸入尺寸
尺寸是 (batch_size, steps, features) 的 3D 張量。
輸出尺寸
尺寸是 (batch_size, features) 的 2D 張量。

GlobalAveragePooling1D

keras.layers.GlobalAveragePooling1D()

對於時序數據的全局平均池化。
輸入尺寸
尺寸是 (batch_size, steps, features) 的 3D 張量。
輸出尺寸
尺寸是 (batch_size, features) 的 2D 張量。
[source]
GlobalMaxPooling2D
keras.layers.GlobalMaxPooling2D(data_format=None)
對於空域數據的全局最大池化。
參數
data_format: 一個字符串,channels_last (默認值)或者 channels_first。 輸入張量中的維度順序。 channels_last 代表尺寸是 (batch, height, width, channels) 的輸入張量,而 channels_first 代表尺寸是 (batch, channels, height, width) 的輸入張量。 默認值根據 Keras 配置文件 ~/.keras/keras.json 中的 image_data_format 值來設置。 如果還沒有設置過,那麼默認值就是 “channels_last”。
輸入尺寸
如果 data_format=‘channels_last’: 尺寸是 (batch_size, rows, cols, channels) 的 4D 張量
如果 data_format=‘channels_first’: 尺寸是 (batch_size, channels, rows, cols) 的 4D 張量
輸出尺寸
尺寸是 (batch_size, channels) 的 2D 張量

GlobalAveragePooling2D

keras.layers.GlobalAveragePooling2D(data_format=None)

對於空域數據的全局平均池化。
參數
data_format: 一個字符串,channels_last (默認值)或者 channels_first。 輸入張量中的維度順序。 channels_last 代表尺寸是 (batch, height, width, channels) 的輸入張量,而 channels_first 代表尺寸是 (batch, channels, height, width) 的輸入張量。 默認值根據 Keras 配置文件 ~/.keras/keras.json 中的 image_data_format 值來設置。 如果還沒有設置過,那麼默認值就是 “channels_last”。
輸入尺寸

如果 data_format=‘channels_last’: 尺寸是 (batch_size, rows, cols, channels) 的 4D 張量
如果 data_format=‘channels_first’: 尺寸是 (batch_size, channels, rows, cols) 的 4D 張量
輸出尺寸

尺寸是 (batch_size, channels) 的 2D 張量

GlobalMaxPooling3D

keras.layers.GlobalMaxPooling3D(data_format=None)

對於 3D 數據的全局最大池化。
參數
data_format: 一個字符串,channels_last (默認值)或者 channels_first。 輸入張量中的維度順序。 channels_last 代表尺寸是 (batch, spatial_dim1, spatial_dim2, spatial_dim3, channels) 的輸入張量,而 channels_first 代表尺寸是 (batch, channels, spatial_dim1, spatial_dim2, spatial_dim3) 的輸入張量。 默認值根據 Keras 配置文件 ~/.keras/keras.json 中的 image_data_format 值來設置。 如果還沒有設置過,那麼默認值就是 “channels_last”。
輸入尺寸
如果 data_format=‘channels_last’: 尺寸是 (batch_size, spatial_dim1, spatial_dim2, spatial_dim3, channels) 的 5D 張量
如果 data_format=‘channels_first’: 尺寸是 (batch_size, channels, spatial_dim1, spatial_dim2, spatial_dim3) 的 5D 張量
輸出尺寸
尺寸是 (batch_size, channels) 的 2D 張量

GlobalAveragePooling3D

keras.layers.GlobalAveragePooling3D(data_format=None)

對於 3D 數據的全局平均池化。
參數
data_format: 一個字符串,channels_last (默認值)或者 channels_first。 輸入張量中的維度順序。 channels_last 代表尺寸是 (batch, spatial_dim1, spatial_dim2, spatial_dim3, channels) 的輸入張量,而 channels_first 代表尺寸是 (batch, channels, spatial_dim1, spatial_dim2, spatial_dim3) 的輸入張量。 默認值根據 Keras 配置文件 ~/.keras/keras.json 中的 image_data_format 值來設置。 如果還沒有設置過,那麼默認值就是 “channels_last”。
輸入尺寸
如果 data_format=‘channels_last’: 尺寸是 (batch_size, spatial_dim1, spatial_dim2, spatial_dim3, channels) 的 5D 張量
如果 data_format=‘channels_first’: 尺寸是 (batch_size, channels, spatial_dim1, spatial_dim2, spatial_dim3) 的 5D 張量
輸出尺寸
尺寸是 (batch_size, channels) 的 2D 張量

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章