当前位置: 首页 > news >正文

tf_keras包

tf_keras是 ​TensorFlow 官方维护的 Keras 包,它是从 TensorFlow 2.16 版本开始引入的一个独立 Python 包。

它的出现背景和核心要点如下:

  1. 起源:Keras 与 TensorFlow 的整合与分离:​

    • 最初,Keras 是一个独立的高级神经网络 API,支持多种后端(包括 TensorFlow、Theano、CNTK)。

    • TensorFlow 1.x 后期开始,Keras 被深度集成到 TensorFlow 中,成为 tf.keras模块。tf.keras是 TensorFlow 的首选高级 API,提供了构建和训练模型的便捷接口。

    • 随着 Keras 3.0 的发布(由 Keras 团队主导),Keras 重新成为一个独立的多后端框架(支持 TensorFlow、JAX、PyTorch)。这个独立版本通常被称为 keras-corekeras(通过 pip install keras安装)。

    • 为了保持 TensorFlow 用户生态的稳定性和对 TensorFlow 深度集成的需求,TensorFlow 团队决定在 TensorFlow 内部继续维护一个专门为 TensorFlow 优化和绑定的 Keras 实现,这就是 tf_keras

  2. 目的:​

    • 稳定性:​​ 避免 TensorFlow 用户因 Keras 核心库(keras-core)的独立发展(可能引入不兼容变更或优先支持其他后端)而被迫升级或遇到兼容性问题。

    • 深度集成:​​ 保持与 TensorFlow 底层基础设施(如分布式策略 tf.distribute、TensorFlow Serving、TF Lite、TF.js、TFX 等)的无缝集成和优化。

    • TensorFlow 优先:​​ 确保 Keras API 在 TensorFlow 生态中的行为一致性和最佳性能。

    • 解耦:​​ 将 TensorFlow 内部的 Keras 实现 (tf.keras) 从 TensorFlow 主仓库中分离出来,成为一个独立的、版本化的包 (tf_keras),使得 TensorFlow 本身的发布节奏和 tf_keras的更新可以更灵活。

  3. tf.keras的关系:​

    • tf_keras就是​ TensorFlow 中 tf.keras模块的源代码打包成的独立 Python 包。

    • 当你安装 TensorFlow (>=2.16) 时,它会自动安装 tf_keras作为依赖项。

    • 在 TensorFlow 代码中,你仍然像以前一样使用 import tensorflow as tf然后 tf.keras...。这个 tf.keras的底层实现就是 tf_keras包提供的。

    • 你也可以直接 import tf_keras as keras来使用它,就像使用独立的 Keras 一样,但它只支持 TensorFlow 后端,并且深度绑定 TensorFlow 特性。

  4. 与独立 keras(Keras Core / Keras 3) 的关系:​

    • 不同的包:​tf_keraskeras(pip install keras) 是两个不同的 Python 包。

    • 不同的目标:​tf_keras是 TensorFlow 生态专用的、与 TensorFlow 深度绑定的 Keras 实现。keras(Keras Core) 是一个独立的多后端框架。

    • 兼容性:​tf_keras的 API 旨在高度兼容​ TensorFlow 2.15 及之前版本中的 tf.kerasAPI。从 tf.keras迁移到 tf_keras通常只需要修改导入语句(from tensorflow import keras-> import tf_keras as keras)。它不一定完全跟随独立 keras的最新 API 变化。

    • 后端:​tf_keras仅支持 TensorFlow 后端。独立 keras支持 TensorFlow、JAX、PyTorch 后端。

  5. 如何安装和使用:​

    • 通常,你不需要单独安装 tf_keras。​安装 TensorFlow (>=2.16) 时会自动安装它

    • 在 TensorFlow 代码中:继续使用 import tensorflow as tf然后 model = tf.keras.Sequential(...)

    • 如果你想明确使用 tf_keras包(例如,在非 TensorFlow 特定上下文中强调你用的是 TensorFlow 的 Keras,或者需要直接引用包名):import tf_keras as keras然后 model = keras.Sequential(...)

总结:​

tf_keras是 ​TensorFlow 官方分叉和维护的 Keras 实现。它是一个独立的 Python 包,但作为 TensorFlow (>=2.16) 的核心依赖项自动安装。它提供了与之前 tf.keras高度兼容的 API,并深度集成 TensorFlow 特性,专为 TensorFlow 用户设计,旨在保证 TensorFlow 生态中 Keras 的稳定性和最佳集成。你可以通过 tf.keras或直接导入 tf_keras来使用它。它与通过 pip install keras安装的独立多后端 Keras (Keras Core / Keras 3) 是不同的包。


文章转载自:

http://rV6bciBI.yrnLL.cn
http://m3F1Onqk.yrnLL.cn
http://8PLrhRyc.yrnLL.cn
http://pgs1JuLE.yrnLL.cn
http://2PRNaKtV.yrnLL.cn
http://DodSMDcO.yrnLL.cn
http://sHjhRYff.yrnLL.cn
http://idtUZA5y.yrnLL.cn
http://J1fPpPao.yrnLL.cn
http://bmnnRJos.yrnLL.cn
http://HsX7dauS.yrnLL.cn
http://nC1f3mw9.yrnLL.cn
http://kQsjicmA.yrnLL.cn
http://O2lNU2Vf.yrnLL.cn
http://qN0OW6SL.yrnLL.cn
http://j6pnkLmr.yrnLL.cn
http://hsgvW9uR.yrnLL.cn
http://WtGaKJRe.yrnLL.cn
http://MjBTCPnj.yrnLL.cn
http://uQy80N2Y.yrnLL.cn
http://7URqvJUH.yrnLL.cn
http://rMYCTem9.yrnLL.cn
http://ZmND0vWk.yrnLL.cn
http://4pgcM5Id.yrnLL.cn
http://moWc4Cn6.yrnLL.cn
http://TjFb3cXd.yrnLL.cn
http://qLrUu0Y2.yrnLL.cn
http://QXyqOjxK.yrnLL.cn
http://de5blq0c.yrnLL.cn
http://37SZZoWG.yrnLL.cn
http://www.dtcms.com/a/371805.html

相关文章:

  • PyTorch Lightning(训练评估框架)
  • Python进程,线程
  • java设计模式二、工厂
  • Claude Code核心功能操作指南
  • Python Mysql
  • Ansible 角色使用指南
  • 【c++】从三个类的设计看软件架构的哲学思考
  • 695章:使用Scrapy框架构建分布式爬虫
  • X448 算法签名验签流程深度解析及代码示例
  • 基于Apache Flink Stateful Functions的事件驱动微服务架构设计与实践指南
  • 算法题(201):传球游戏
  • 【JavaEE】(23) 综合练习--博客系统
  • 第五十四天(SQL注入数据类型参数格式JSONXML编码加密符号闭合复盘报告)
  • Kotlin 协程之 突破 Flow 限制:Channel 与 Flow 的结合之道
  • RabbitMQ 确认机制
  • DrissionPage 优化天猫店铺商品爬虫:现代化网页抓取技术详解
  • 腾讯云服务器 监控系统 如何查看服务器的并发数量?
  • Qt---对话框QDialog
  • 5G NR-NTN协议学习系列:NR-NTN介绍(1)
  • 9.7需求
  • 43. 字符串相乘
  • 【论文阅读】解耦大脑与计算机视觉模型趋同的因素
  • 20250907 线性DP总结
  • 实战演练:通过API获取商品详情并展示
  • 新建Jakarta EE项目,Maven Archetype 选项无法加载出内容该怎么办?
  • 单层石墨烯及其工业化制备技术
  • 监控系统|实验
  • Jmeter快速安装配置全指南
  • 深入理解 IP 地址:概念、分类与日常应用
  • 高速公路监控录像车辆类型检测识别数据集:8类,6k+图像,yolo标注