您当前的位置: 首页 >  Python

Better Bench

暂无认证

  • 4浏览

    0关注

    695博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

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

Better Bench 发布时间:2021-03-08 22:57:58 ,浏览量:4

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)
关注
打赏
1665674626
查看更多评论
立即登录/注册

微信扫码登录

0.1764s