zl程序教程

您现在的位置是:首页 >  其它

当前栏目

【Tensorflow+keras】解决 Fail to find the dnn implementation.

解决 to The Tensorflow Find Keras fail implementation
2023-09-14 09:12:40 时间

1 引言

(1)环境

Tensorflow 2.0
Python 3.6

(2)问题

from tensorflow.keras import *
from tensorflow.keras.layers import Bidirectional,LSTM

在使用Bidirectional(LSTM )时,报错 [Derived] Fail to find the dnn implementation.

2 解决

因为在Tensorflow2.0中使用keras的API时,该版本的keras已经不支持直接使用Bidirectional(LSTM ),三种解决办法。
(1)第一种方法
继续使用在Tensorflow2.0的keras API,用兼容的替代的写法

from tensorflow.keras import *
from tensorflow.keras.layers import Bidirectional

Bidirectional(tf.keras.layers.RNN(tf.keras.layers.LSTMCell(n_BiLSTM_1),return_sequences=True))

(2)第二种方法
使用支持该方法的原装Keras:2.1.6

# 安装
pip install keras ==2.1.6
# 使用
from keras.layers import Bidirectional,LSTM

(3)第三种方法
继续使用在Tensorflow2.0的keras API,但加入表示兼容的代码

from tensorflow.keras.layers import Bidirectional,LSTM
from tensorflow.compat.v1 import ConfigProto
from tensorflow.compat.v1 import InteractiveSession

config = ConfigProto()
config.gpu_options.allow_growth = True
session = InteractiveSession(config=config)