tf.nn.conv2d() 函数详解

import tensorflow as tf
expand = tf.Variable(tf.truncated_normal([2,7,3,1]))
W = tf.Variable(tf.truncated_normal([2,3,1,8], stddev=0.1, seed=1), name='W')
conv = tf.nn.conv2d(
    expand,
    W,
    strides=[1, 1, 1, 1],  # 不同维度上的步长
    padding="VALID",  # 填充的方法,SAME或VALID,SAME表示添加全0填充,VALID表示不添加
    name="conv")
print(expand)  # shape = (2, 7, 3, 1)
print(W)       # shape = (2, 3, 1, 8)
print(conv)    # shape = (2, 6, 1, 8)
输入:

expand
[batch_size, height_1, width_1, channels]

batch_size 一个batch中样例的个数      2
height_1, 图片的高                                 7
width_1, 图片的宽                                  3
channels 通道数,也就是当前层的深度 1

W
[height_2, width_2, channels, output]

height_2, 过滤器filter的高                                                      2
width_2, 过滤器filter的宽                                                       3
channels, 通道数,和上面保持一致,也就是当前层的深度  1
output 输出的深度                                                                 8

输出:

conv
[batch_size, height_3, width_3, output]

batch_size, 一个batch中样例的个数,同上           2
height_3, 卷积结果的高度                                      6 = height_1 - height_2 + 1 = 7-2+1
width_3, 卷积结果的宽度                                       1 = width_1 - width_2 +1 = 3-3+1
output 输出的深度                                                  8

你可能感兴趣的:(tensorflow)