Conv2D 理解
import tensorflow as tf
# The inputs are 28x28 RGB images with `channels_last` and the batch
# size is 4.
input_shape = (4, 28, 28, 3)
x = tf.random.normal(input_shape)
y = tf.keras.layers.Conv2D(
20, 5, activation='relu',padding='valid',strides=4, input_shape=input_shape)(x)
print(y.shape)
当padding 用 valid 时候,输出的尺寸为,(原来矩阵长-卷积核长度+1)/stride
(28-5+1)/4=6
(4, 6, 6, 20)
当padding 用 same 时候,输出的尺寸为,(原来矩阵长)/stride
28/4=7
import tensorflow as tf
# The inputs are 28x28 RGB images with `channels_last` and the batch
# size is 4.
input_shape = (4, 28, 28, 3)
x = tf.random.normal(input_shape)
y = tf.keras.layers.Conv2D(
20, 5, activation='relu',padding='same',strides=4, input_shape=input_shape)(x)
print(y.shape)
(4, 7, 7, 20)