作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
如何使用边缘值填充张量(尺寸为 WxHxC)?
例如:
[1, 2, 3]
[4, 5, 6]
[7, 8, 9]
变成:
[1, 1, 2, 3, 3]
[1, 1, 2, 3, 3]
[4, 4, 5, 6, 6]
[7, 7, 8, 9, 9]
[7, 7, 8, 9, 9]
最佳答案
使用tf.pad()
和模式“SYMMETRIC” - 它将反射(reflect)边缘上的值,但如果您只进行 1 深度填充,则相当于重复边缘值。如果需要更多填充,则必须重复该操作,但可以按指数进行(先 1,然后 2,然后 4,等等)。此代码(已测试):
import tensorflow as tf
a = tf.reshape( tf.constant( range( 1, 10 ) ), ( 3, 3 ) )
b = tf.pad( a, [ [ 1, 1 ], [ 1, 1 ] ], "SYMMETRIC" )
with tf.Session() as sess:
print( sess.run( b ) )
输出:
[[1 1 2 3 3]
[1 1 2 3 3]
[4 4 5 6 6]
[7 7 8 9 9]
[7 7 8 9 9]]
根据需要。
关于python - TensorFlow 如何用边缘值填充张量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50174962/
我是一名优秀的程序员,十分优秀!