当前位置: 首页 > 工具软件 > better_errors > 使用案例 >

【Tensorflow 2】解决tensorflow.python.framework.errors_impl.UnknownError: [_Derived_] Fail to find the

谢承
2023-12-01

1 问题

环境

Deepin 20 OS linux系统
Tensorflow2.0
Python3.6
GPU Rtx 2070
cuda 10.0
cudnn 10.0

在使用双向LSTM时

tf.keras.layers.Bidirectional(tf.keras.layers.LSTM(64)),

报以下错误信息

tensorflow.python.framework.errors_impl.UnknownError: [Derived] Fail to find the dnn implementation.
[[{{node CudnnRNN}}]]
[[bi_complex_lstm/bidirectional/forward_lstm/StatefulPartitionedCall]] [Op:__inference_keras_scratch_graph_34502]
Function call stack:

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)
 类似资料: