【问题标题】:Number of elements are too large元素数量太大
【发布时间】:2019-12-08 19:48:40
【问题描述】:

当我尝试使用 tensorflow 训练数据时出现此错误。

tensorflow/core/framework/op_kernel.cc:1651] OP_REQUIRES 失败于 gather_nd_op.cc:47:无效参数:params.NumElements() 太大 对于 int32 索引:2153378304 > 2147483647

相关代码是这样的,它对较小的数据集按预期工作。如何将其应用于更大的数据?

ml_df_collect = list()

similarity_input_placeholder = tf.placeholder(tf.string, shape=(None))
similarity_message_encodings = embed(similarity_input_placeholder)
with tf.Session() as session:
    session.run(tf.global_variables_initializer())
    session.run(tf.tables_initializer())
    message_embeddings_ = session.run(
        similarity_message_encodings,
        feed_dict={similarity_input_placeholder: messages},
    )
corr = np.inner(message_embeddings_, message_embeddings_)

ml_df_collect.append(corr)

【问题讨论】:

    标签: python tensorflow


    【解决方案1】:

    gather_nd 失败,因为张量对于int32 索引来说太大了。

    TensorFlow 文档指定 gather_nd 也可以接受 int64 索引 (https://www.tensorflow.org/api_docs/python/tf/gather_nd)。

    使用int64 而不是int32 作为索引张量可能是解决方案。

    【讨论】:

    • 如何指定 int64 类型而不是 32?
    • 这取决于其余代码的编写方式。例如,tf.constant([1], dtype=tf.int64)tf.placeholder(tf.int64) 产生 int64 张量。
    猜你喜欢
    • 2011-09-14
    • 2012-04-25
    • 1970-01-01
    • 2017-10-24
    • 1970-01-01
    • 2013-10-05
    • 2016-09-21
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多