可变形状张量

时间:2016-10-06 01:03:05

标签: python tensorflow

我需要得到一个可变形状的张量,因为我不知道手前的矢量大小。到目前为止我试过了:

hashtag_len = tf.placeholder(tf.int32)
train_hashtag = tf.placeholder(tf.int32, shape=[hashtag_len])

但我收到错误TypeError: int() argument must be a string, a bytes-like object or a number, not 'Tensor'

我能想到的唯一另一种方法就是用足够的零填充向量,这样我就可以将预期的向量拟合到一个巨大的向量中。看起来像tensorflow应该有更好的方法来做到这一点。

2 个答案:

答案 0 :(得分:3)

如果您想要一个VECTOR,您应该执行以下操作:

train_hashtag = tf.placeholder(tf.int32, shape=[None])

此形状描述任意长度的矢量。

答案 1 :(得分:2)

使用

tf.placeholder(tf.int32)

创建任意形状的占位符