我应该使用独立的 Keras 库还是 tf.keras? [英] Should I use the standalone Keras library or tf.keras?

查看:36
本文介绍了我应该使用独立的 Keras 库还是 tf.keras?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

随着 Keras 成为 TensorFlow 的 API,有很多旧版本的 Keras 代码,例如 https://github.com/keiserlab/keras-neural-graph-fingerprint/blob/master/examples.py

As Keras becomes an API for TensorFlow, there are lots of old versions of Keras code, such as https://github.com/keiserlab/keras-neural-graph-fingerprint/blob/master/examples.py

from keras import models

使用当前版本的 TensorFlow,我们是否需要将每个 Keras 代码更改为?

With the current version of TensorFlow, do we need to change every Keras code as?

from tensorflow.keras import models

推荐答案

你把事情搞混了:

  • Keras (https://keras.io/) 是一个独立于 TensorFlow 的库,它指定了一个高用于构建和训练神经网络的级 API,并且能够使用多个后端之一(其中包括 TensorFlow)进行低级张量计算.
  • tf.keras (https://www.tensorflow.org/guide/keras) 在 TensorFlow 中实现了 Keras API 规范.此外,tf.keras API 经过优化,可以与其他 TensorFlow 模块很好地协同工作:您可以将 tf.data 数据集传递给 .fit()<例如,tf.keras 模型的/code> 方法,或使用 tf.keras.estimator.model_to_estimator 将 tf.keras 模型转换为 TensorFlow 估计器.目前,tf.keras API 是在 TensorFlow 中构建模型时要查找的高级 API,未来将继续与其他 TensorFlow 功能集成.
  • Keras (https://keras.io/) is a library independent from TensorFlow, which specifies a high-level API for building and training neural networks and is capable of using one of multiple backends (among which, TensorFlow) for low-level tensor computation.
  • tf.keras (https://www.tensorflow.org/guide/keras) implements the Keras API specification within TensorFlow. In addition, the tf.keras API is optimized to work well with other TensorFlow modules: you can pass a tf.data Dataset to the .fit() method of a tf.keras model, for instance, or convert a tf.keras model to a TensorFlow estimator with tf.keras.estimator.model_to_estimator. Currently, the tf.keras API is the high-level API to look for when building models within TensorFlow, and the integration with other TensorFlow features will continue in the future.

所以回答您的问题:不,您不需要将 Keras 代码转换为 tf.keras 代码.Keras 代码使用 Keras 库,甚至可能运行在与 TensorFlow 不同的后端之上,并且将来会继续正常工作.更重要的是,不要在同一个脚本中混用 Keras 和 tf.keras 对象,因为这可能会产生不兼容,例如 在这个问题中.

So to answer your question: no, you don't need to convert Keras code to tf.keras code. Keras code uses the Keras library, potentially even runs on top of a different backend than TensorFlow, and will continue to work just fine in the future. Even more, it's important to not just mix up Keras and tf.keras objects within the same script, since this might produce incompatabilities, as you can see for example in this question.

更新:Keras 将被 tf.keras 所取代:https://twitter.com/fchollet/status/1174019423541157888

Update: Keras will be abandoned in favor of tf.keras: https://twitter.com/fchollet/status/1174019423541157888

这篇关于我应该使用独立的 Keras 库还是 tf.keras?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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