AttributeError: module 'tensorflow_core._api.v2.nn' has no attribute 'rnn_cell' tensorflow版本兼容问题-解决

 

 该问题是在tfv2环境下跑了tfv1的代码致使的,只需把v1的用法替换成v2留出的兼容用法便可:python

tf.compat.v1.nn.rnn_cell.RNNCell代替tf.nn.rnn_cell.RNNCellapi

参考:https://tensorflow.google.cn/api_docs/python/tf/compat/v1/nn/rnn_cell/RNNCell?hl=engoogle

也能够这样,使2.0的环境可以运行1.0的代码:spa

import tensorflow.compat.v1 as tfcode

tf.disable_v2_behavior()blog

相关文章
相关标签/搜索