Tensorflow模块导入错误:AttributeError:模块'tensorflow.python.ops.nn'没有属性'rnn_cell'

时间:2017-12-20 02:56:06

标签: python tensorflow python-import attributeerror rnn

尝试通过我的RNN呼叫时,我调用tf.nn.rnn_cell并收到以下错误:

class ViewController: UIViewController {

    func playAgain() {
        print("Play Again")
    }

    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        if segue.identifier == "showScore" {
            if let dvc = segue.destination as? DisplayScoreController {
                // assign closure to goPlayAgain property
                // of destination view controller to dismiss
                // the destination and call playAgain()
                dvc.goPlayAgain = {
                    self.dismiss(animated: true, completion: nil)
                    self.playAgain()
                }
            }
        }
    }

}

class DisplayScoreController: UIViewController {

    // property to hold closure which dismisses this
    // view controller and calls playAgain() in
    // ViewController   
    var goPlayAgain: (() -> ())?

    // Time to return to ViewController and call playAgain()       
    @IBAction func done(_ sender: UIButton) {
        self.goPlayAgain?()
    }

}

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

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

但是看看文档,事情已经在tensorflow版本之间移动了。

你们都建议你解决这个问题?

Line,我收到错误:

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

具体来说:

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)]
)

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

提前干杯。

1 个答案:

答案 0 :(得分:3)

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

从版本1.0开始,rnn作为contrib模块的一部分实现。

可在此处找到更多信息 https://www.tensorflow.org/api_guides/python/contrib.rnn