【问题标题】:Tensorflow Module Import error: AttributeError: module 'tensorflow.python.ops.nn' has no attribute 'rnn_cell'Tensorflow 模块导入错误:AttributeError:模块“tensorflow.python.ops.nn”没有属性“rnn_cell”
【发布时间】:2017-12-20 02:56:05
【问题描述】:

在尝试传递我的 RNN 调用时,我调用了 tf.nn.rnn_cell 并收到以下错误:

AttributeError: module 'tensorflow.python.ops.nn' has no attribute 'rnn_cell'

这很奇怪,因为我确信我正确导入了所有内容:

from __future__ import print_function, division
from tensorflow.contrib import rnn
import numpy as np
import tensorflow as tf
import matplotlib.pyplot as plt

但是查看文档,在 tensorflow 版本之间发生了变化。

你们会推荐什么来解决这个问题?

行,我收到的错误是:

state_per_layer_list = tf.unstack(init_state, axis=0)
rnn_tuple_state = tuple(
    [tf.nn.rnn_cell.LSTMStateTuple(state_per_layer_list[idx][0], state_per_layer_list[idx][1])
     for idx in range(num_layers)]
)

具体来说:

tf.nn.rnn_cell

我正在使用 anaconda 3 来管理所有这些,所以所有的依赖关系都应该得到照顾。我已经尝试过使用张量形状解决该死的等级/形状错误,这需要很长时间才能解决。

提前干杯。

【问题讨论】:

    标签: python tensorflow python-import attributeerror rnn


    【解决方案1】:

    tf.nn.rnn_cell 替换为tf.contrib.rnn

    自 1.0 版起,rnn 作为 contrib 模块的一部分实现。

    更多信息可以在这里找到 https://www.tensorflow.org/api_guides/python/contrib.rnn

    【讨论】:

    • 欢呼声似乎解决了这个问题。您对如何处理以下问题有了一个想法: states_series, current_state = tf.nn.rnn(cell, inputs_series, initial_state=rnn_tuple_state)
    • 我收到一个错误,说没有属性 RNN:AttributeError: module 'tensorflow.python.ops.nn' has no attribute 'rnn'
    • 但是当我使用 contrib.rnn 我得到另一个错误说: TypeError: 'module' object is not callable
    • 试试这个tf.contrib.rnn.static_rnn
    • 干杯,这有点大惊小怪,我让它工作了。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-11-26
    • 2020-07-20
    • 1970-01-01
    • 2017-04-08
    • 2020-02-04
    • 2020-02-12
    相关资源
    最近更新 更多