如何在Tensorflow 2.0中使用K.get_session或如何迁移它? [英] How to use K.get_session in Tensorflow 2.0 or how to migrate it?

查看:333
本文介绍了如何在Tensorflow 2.0中使用K.get_session或如何迁移它?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

def __init__(self, **kwargs):
    self.__dict__.update(self._defaults) # set up default values
    self.__dict__.update(kwargs) # and update with user overrides
    self.class_names = self._get_class()
    self.anchors = self._get_anchors()
    self.sess = K.get_session()

运行时错误:使用TensorFlow 2.0时 get_session 不可用

RuntimeError: get_session is not available when using TensorFlow 2.0.

推荐答案

Tensorflow 2.0不再直接公开backend.get_session,但是代码仍然存在并为tf1公开。

Tensorflow 2.0 does not expose the backend.get_session directly any more but the code still there and expose for tf1.

https://github.com/tensorflow/tensorflow/blob/r2.0/tensorflow/python/keras/backend.py#L465

您可以将其与tf1兼容的接口一起使用:

You can use it with tf1 compatible interface:

sess = tf.compat.v1.keras.backend.get_session()

带有内部路径的rt tenforflow后端:

Or import tenforflow backend with internal path:

import tensorflow.python.keras.backend as K
sess = K.get_session()

这篇关于如何在Tensorflow 2.0中使用K.get_session或如何迁移它?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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