【error】ImportError: cannot import name 'rnn_cell'

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/ccbrid/article/details/84854328

报错信息:【error】ImportError: cannot import name 'rnn_cell'

出错句:from tensorflow.python.ops import rnn_cell

检查过程:

>>>import tensorflow as tf

>>>tf.__version__

得到本机版本为'1.0.1'

错误原因:

tensorflow1.0以上的版本有很多API函数变化,如其中tf.nn.rnn_cell命名空间中的很多函数都发生了命名空间的变化,如转移到了tf.contrib.rnn.core_rnn_cell。

tensorflow1.0版本之后,rnn_cell 不再在 tensorflow.python.ops 中,在tensorflow文档中查找你会发现rnn_cell在1.0之前的版本,比如tf.nn.rnn_cell such as doc 0.11 or doc 0.12

而在1.0及以上的版本rnn_cell通常是这样存放的tensorflow/contrib/rnn/python/ops/rnn_cell.py 或者 tensorflow/python/ops/rnn_cell.impl.py。

改正方法:

1)出错句改为"from tensorflow.contrib.rnn.python.ops import rnn_cell"

2)或重新安装tensorflow:

gpu设备安装:pip install tensorflow-gpu==0.12.1

cpu设备安装:pip install tensorflow==0.12.1

参考网址:

https://stackoverflow.com/questions/43307660/importerror-cannot-import-name-rnn-cell

https://blog.csdn.net/sparkexpert/article/details/71513976

猜你喜欢

转载自blog.csdn.net/ccbrid/article/details/84854328
今日推荐