Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/286.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/tensorflow/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 填充是否包含用于新高度和新宽度计算公式的数字?_Python_Tensorflow_Deep Learning_Padding - Fatal编程技术网

Python 填充是否包含用于新高度和新宽度计算公式的数字?

Python 填充是否包含用于新高度和新宽度计算公式的数字?,python,tensorflow,deep-learning,padding,Python,Tensorflow,Deep Learning,Padding,我试图在TensorFlow中建立卷积层。实际上是为了回答下面的测验。他们给了我们实现新高度和新宽度的公式。但我不知道填充的数字是什么,因为我认为padding='SAME'或padding='VALID'不包含数字 新高度=(输入高度-过滤器高度+2*p)/S+1 新宽度=(输入宽度-过滤器宽度+2*p)/S+1 相同填充表示输出特征映射的大小与输入特征映射的大小相同(假设步幅为1)。例如,如果输入为Nin,大小为28×28,那么在输出中,您希望得到大小为28×28的所有特征映射 另一方面,V

我试图在TensorFlow中建立卷积层。实际上是为了回答下面的测验。他们给了我们实现新高度和新宽度的公式。但我不知道填充的数字是什么,因为我认为padding='SAME'或padding='VALID'不包含数字

新高度=(输入高度-过滤器高度+2*p)/S+1

新宽度=(输入宽度-过滤器宽度+2*p)/S+1


相同填充表示输出特征映射的大小与输入特征映射的大小相同(假设步幅为1)。例如,如果输入为Nin,大小为28×28,那么在输出中,您希望得到大小为28×28的所有特征映射

另一方面,VALID填充意味着输出特征映射的大小减小。例如,如果输入为Nin,其大小为28x28,步长为1,过滤器大小为3x3,则输出Nout特征映射将分别为[{(28-3)/1}+1=26]26x26

要推导输出,公式为:
{(输入大小-过滤器大小)/stride}+1


因此,从上面的公式中,您可以看到输出特征图的大小与步幅成反比(步幅值越高,输出特征图越小)

可能重复我刚开始检查了这个问题,但我不知道如何回答我的问题。。。
# `tf.nn.conv2d` requires the input be 4D (batch_size, height, width, depth)
# (1, 4, 4, 1)
x = np.array([
    [0, 1, 0.5, 10],
    [2, 2.5, 1, -8],
    [4, 0, 5, 6],
    [15, 1, 2, 3]], dtype=np.float32).reshape((1, 4, 4, 1))
X = tf.constant(x)

def conv2d(input):
# Filter (weights and bias)
# The shape of the filter weight is (height, width, input_depth,    
   output_depth)
# The shape of the filter bias is (output_depth,)
# TODO: Define the filter weights `F_W` and filter bias `F_b`.
# NOTE: Remember to wrap them in `tf.Variable`, they are trainable 
        parameters after all.
F_W = ????
F_b = ????

# TODO: Set the stride for each dimension (batch_size, height, width, depth)
strides = ????
# TODO: set the padding, either 'VALID' or 'SAME'.
padding = ?

# `tf.nn.conv2d` does not include the bias computation so we have to add it   
ourselves after.

return tf.nn.conv2d(input, F_W, strides, padding) + F_b

out = conv2d(X)