【问题标题】:Tensorflow: AttributeError: 'tuple' object has no attribute 'dtype'Tensorflow:AttributeError:'tuple'对象没有属性'dtype'
【发布时间】:2017-11-21 02:56:46
【问题描述】:

这是怎么回事?

代码:

def text_model(text, memory):
    import tensorflow as tf

    tf.logging.set_verbosity(tf.logging.INFO)

    # Text parsing.
    lastLayer = tf.convert_to_tensor([text, memory])
    for i in range(0, 200):
        thinking = tf.layers.dense(inputs = lastLayer, units = pow(10, 9), activation = tf.nn.relu)

        lastLayer = thinking, [32000, -1]
    response = tf.layers.dense(inputs = lastLayer, units = pow(10, 4), activation = tf.nn.relu)
    memory = tf.reshape(tf.convert_to_tensor([lastLayer, response]), [-1])

    return [response, memory]

textList = text_model([1], [1])

print(textList)

错误报告:

AttributeError: 'tuple' object has no attribute 'dtype'

遇到相同错误的其他人似乎在完全不同的情况下得到它。为什么在这种情况下会发生此错误,我该如何解决?

谢谢。 :)

【问题讨论】:

  • 请包含完整的回溯

标签: python tensorflow


【解决方案1】:

这一行将lastLayer 设置为一个元组:

lastLayer = thinking, [32000, -1]

当for 循环第二次执行时,它将尝试访问lastLayer 作为张量,但您已将其转换为元组。所以你得到了错误。

【讨论】:

    猜你喜欢
    • 2019-03-12
    • 1970-01-01
    • 2017-06-09
    • 1970-01-01
    • 2016-12-04
    • 1970-01-01
    • 2022-11-17
    • 1970-01-01
    • 2021-03-18
    相关资源
    最近更新 更多