admin管理员组

文章数量:1642517

In this example:

  • Input width = 13
  • Filter width = 6
  • Stride = 5

Notes:

  • "VALID" only ever drops the right-most columns (or bottom-most rows).
  • "SAME" tries to pad evenly left and right, but if the amount of columns to be added is odd, it will add the extra column to the right, as is the case in this example (the same logic applies vertically: there may be an extra row of zeros at the bottom).

测试

用mnist里的一张图片测试‘SAME’和‘VALID’的区别:

import tensorflow as tf 
import numpy as np
from tensorflow.examples.tutorials.mnist import input_data

mnist = input_data.read_data_sets("./MNIST_data/", one_hot=True)

xs = tf.placeholder(tf.float32, [None, 784])
ys = tf.placeholder(tf.float32, [None, 10])

x = tf.reshape(xs, [-1, 28, 28, 1])
conv1 = tf.layers.conv2d(inputs=x, use_bias=True, filters=3, kernel_size=[3,3], strides=2, padding='SAME')
conv2 = tf.layers.conv2d(inputs=x, use_bias=True, filters=3, kernel_size=[3,3], strides=2, padding='VALID')

sess = tf.Session()
init = tf.global_variables_initializer()
sess.run(init)

batch_xs, batch_ys = mnist.train.next_batch(1)
print("SAME", np.shape(sess.run(conv1, feed_dict={xs:batch_xs, ys:batch_ys})))
print("VALID", np.shape(sess.run(conv2, feed_dict={xs:batch_xs, ys:batch_ys})))

结果如下:

Over!

本文标签: 区别paddingValid