Keras'set_session'不适用于Tensorflow 2.0 [英] Keras 'set_session' not available for Tensorflow 2.0

查看:359
本文介绍了Keras'set_session'不适用于Tensorflow 2.0的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尝试执行以下操作:

import tensorflow as tf
from keras.models import load_model, Model
from keras import backend as K

sess = tf.compat.v1.Session()
K.set_session(sess)

当我在Google Colab中运行此程序时,我得到:

When I run this in Google Colab I get:

RuntimeError: `set_session` is not available when using TensorFlow 2.0.

有人知道如何解决此问题吗?

Does anyone know how to fix this?

推荐答案

尝试使用tensorflow路径中的keras后端.您的代码给我一个错误,但这对我有用.

try using the keras backend from the tensorflow path. Your code gives me an error, but this works for me.

import tensorflow as tf
from tensorflow.keras.models import load_model, Model
from tensorflow.python.keras import backend as K

sess = tf.compat.v1.Session()
K.set_session(sess)

这篇关于Keras'set_session'不适用于Tensorflow 2.0的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆