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!
版权声明:本文标题:padding='SAME'和'VALID'的区别 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://www.elefans.com/xitong/1729340190a1197442.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论