Advertisement

TypeError: the following are legacy tf.layers Layers

阅读量:

在TensorFlow2框架中调用tf.compat.v1.nn.rnn_cell.BasicLSTMCell()时遇到了异常情况:

复制代码
    TypeError: The following are legacy tf.layers.Layers:
    
    
    
    To use keras as a framework (for instance using the Network, Model, or Sequential classes), please use the tf.keras.layers implementation instead. (Or, if writing custom layers, subclass from tf.keras.layers rather than tf.layers)
    
    
    AI写代码python
    
    运行

出现这一情况的原因在于所采用的BasicLSTMCell()并未继承自keras.layers模块,而当前模型是基于keras框架进行构建的,因此无法调用其他框架中的类。
推荐采用以下方式作为替代:

复制代码
    tf.keras.layers.LSTMCell()
    
    
    AI写代码python
    
    运行
`

全部评论 (0)

还没有任何评论哟~