卷积层的输出:
如果 W2 或者 H2 计算得到不为整数:
not an integer, indicating that the neurons don’t “fit” neatly and symmetrically across the input.
Therefore, this setting of the hyperparameters is considered to be invalid, and a ConvNet library could
throw an exception or zero pad the rest to make it fit, or crop the input to make it fit, or something. >>
使用 tf.nn.conv2d 或 tf.layers.conv2d 作为卷积函数,当不为整时根据 padding ”取值(默认为 valid”)由下计算:
上述公式池化也适用。
比如 DQN 解决 Flappy bird 中的 DQN 网络,其中卷积和池化用到的函数 padding=”same”,可依次得到每后一层的 size。 >>
再比较下 tf.nn.conv2d 或 tf.layers.conv2d 两个函数,拿上图第一层卷积为例,先定义输入
input = tf.placeholder(tf.float32, shape=[None, 80, 80, 4])
若使用 tf.nn.conv2d:
kernel = tf.truncated_normal([8, 8, 4, 32], stddev = 0.01)
h1 = tf.nn.conv2d(input, kernel, strides = [1, 4, 4, 1], padding = "SAME")
h_conv1 = tf.nn.relu(h1)
若使用 tf.layers.conv2d:
h_conv1 = tf.layers.conv2d(input, 32, 8, strides=4, padding = "SAME", activation=tf.nn.relu) 或补全:
h_conv1 = tf.layers.conv2d(input, 32, (8, 8), strides=(4, 4), padding = "SAME", activation=tf.nn.relu)
评论0