我正在尝试。使用feed_dict根据输入的维度拆分张量(输入的维度随每批处理而变化)。目前我一直得到一个错误,说张量不能与"维度"分割。是否有一种方法可以获得维度的值并使用它进行分割?
谢谢!
input_d = tf.placeholder(tf.int32, [None, None], name="input_d")
# toy feed dict
feed = {
input_d: [[20,30,40,50,60],[2,3,4,5,-1]] # document
}
W_embeddings = tf.get_variable(shape=[vocab_size, embedding_dim],
initializer=tf.random_uniform_initializer(-0.01, 0.01),
name="W_embeddings")
document_embedding = tf.gather(W_embeddings, input_d)
timesteps_d = document_embedding.get_shape()[1]
doc_input = tf.split(1, timesteps_d, document_embedding)
tf.split
接受一个python整数作为num_split
参数。然而,document_embedding.get_shape()
返回一个TensorShape
, document_embedding.get_shape()[1]
给出一个Dimension
实例,因此你得到一个错误说"不能与一个维度分裂"。
试试timestep_ds = document_embedding.get_shape().as_list()[1]
,这个语句应该会给你一个python整数。
这里有一些关于tf的相关文档。split and tf. tensor_get_shape