【问题标题】:Tensorflow Split Using Feed Dict Input Dimension使用 Feed Dict 输入维度拆分 Tensorflow
【发布时间】:2016-11-08 17:01:48
【问题描述】:

我正在尝试根据使用 feed_dict 输入的输入的维度来 tf.split 一个张量(每个批次的输入变化的维度)。目前我一直收到一个错误,说张量不能用“维度”分割。有没有办法获取维度的值并使用它进行拆分?

谢谢!

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)

【问题讨论】:

  • 错误信息是什么?你能打印出seq_lensdocument_embedding 的值吗?
  • TypeError: Expected int for argument 'num_split' not Dimension(None).
  • get_shape().shape[1] 怎么样?

标签: python nlp tensorflow recurrent-neural-network word-embedding


【解决方案1】:

tf.splitnum_split 参数采用 python 整数。但是,document_embedding.get_shape() 返回一个 TensorShapedocument_embedding.get_shape()[1] 给出一个 Dimension 实例,因此您会收到一条错误消息“无法使用维度拆分”。

试试timestep_ds = document_embedding.get_shape().as_list()[1],这条语句应该给你一个python整数。

这里是tf.splittf.Tensor.get_shape 的一些相关文档

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-12-21
    • 1970-01-01
    • 1970-01-01
    • 2017-08-18
    • 2018-04-27
    • 2020-05-24
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多