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

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

问题描述

随着Keras成为TensorFlow的API,Keras代码有很多旧版本,例如

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数据集传递给tf.keras模型的.fit()方法,或者将tf.keras模型转换为具有tf.keras.estimator.model_to_estimator的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天全站免登陆