machine-learning - How to use K.get_session in Tensorflow 2.0 or how to migrate it?
问题描述
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()
RuntimeError: get_session
is not available when using TensorFlow 2.0.
解决方案
Tensorflow 2.0 不再直接公开 backend.get_session,但代码仍然存在并为 tf1 公开。
https://github.com/tensorflow/tensorflow/blob/r2.0/tensorflow/python/keras/backend.py#L465
您可以将其与 tf1 兼容接口一起使用:
sess = tf.compat.v1.keras.backend.get_session()
或者使用内部路径导入 tenforflow 后端:
import tensorflow.python.keras.backend as K
sess = K.get_session()
推荐阅读
- c++ - 如何检查成员函数或自由函数是否适用于确切的给定类型(不是它的任何基类)?
- firebase - 如何将新数据从实时数据库推送到 Cloud Firestore?
- python - Selenium Chrome WebDriver 不使用代理
- rust - 为什么我可以在结构的类型参数中编写函数类型?
- django - Django 错误报告,不同的外键作为 URL 参数将导致详细视图不执行
- javascript - 将 axios 响应(数组数组)映射到 typescript 接口
- ruby-on-rails - 在 netlify-status 500 上部署的站点上获取失败,cors 错误,未捕获(承诺中)语法错误
- python - 在 Python 的特定列中将任何奇数值舍入为偶数值
- javascript - 如何使用 webpack4 在浏览器 devtool 中禁用显示 webpack:// 目录?
- android - android studio,播放资产交付,访问资产文件错误