[英]Concatenate 3d tensors by cloning one tensor?
我有兩個張量:
a = tf.placeholder(tf.float32, [None, 20, 100])
b = tf.placeholder(tf.float32, [None, 1, 100])
我想將b
附加到a[i, 20, 100]
,以創建c
例如c
具有[None, 20, 200]
的形狀。
這似乎很簡單,但是我還沒有弄清楚如何使用tf.concat
來做到這tf.concat
:
tf.concat(0, [a, b]) -> Shapes (20, 100) and (1, 100) are not compatible
tf.concat(1, [a, b]) => shape=(?, 28, 100) which is not what I wanted
tf.concat(2, [a, b]) -> Shapes (?, 20) and (?, 1) are not compatible
我需要先重塑a
和b
然后再重塑嗎?
這可以使用tf.tile
來完成。 您將需要克隆沿着張尺寸1, 20
倍,使其與兼容的a
。 然后,沿維度2進行簡單的串聯將為您提供結果。
這是完整的代碼,
import tensorflow as tf
a = tf.placeholder(tf.float32, [None, 20, 100])
b = tf.placeholder(tf.float32, [None, 1, 100])
c = tf.tile(b, [1,20,1])
print c.get_shape()
# Output - (?, 20, 100)
d = tf.concat(2, [a,c])
print d.get_shape()
# Output - (?, 20, 200)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.