What is the difference between Keras and tf.keras in TensorFlow 1.1+?

后端 未结 4 1355
生来不讨喜
生来不讨喜 2020-12-24 11:32

Now that TensorFlow 1.1 supports the Keras API under tf.contrib.keras, which one should I use if I intend to use Keras with a TF backend?

Is the t

相关标签:
4条回答
  • 2020-12-24 12:05

    tf.keras (formerly tf.contrib.keras) is an implementation of keras 2 implemented exclusively with/for tensorflow. It is hosted on the tensorflow repo and has a distinct code base than the official repo (the last commit there in the tf-keras branch dates back from May 2017).

    As a rule of thumb, if your code use any tensorflow-specific code, say anything in tf.data.* for providing inputs or tf.summary.* for visualization in tensorboard, it is simpler to just use tf.keras. (Some may even recommend not using the reference Keras implementation with TF because of occasional problems it has with this toolkit).

    On the other hand, if you plan to actively maintain a framework-agnostic code, using keras' own package is your only choice.

    If you don't care much about being framework-agnostic but don't use tensorflow-specific code, I would probably advise to go with tf.keras and start using tensorflow-specific code, esp. tf.data which is a game-changer in my opinion.

    EDIT

    I attended a talk by Chollet on TF2 (couldn't find a recording online) in which he basically said that support for frameworks other than TF would eventually drop and future developments of Keras would happen exclusively in tf.keras.

    From what I can see, this is already happening, as Keras' commit stream is getting thin these days.

    It makes a lot of sense since, as of now, the only other popular DL framework is pytorch, which is not supported by Keras. Keeping Keras code "agnostic" to tensorflow -- the only major framework it is supporting -- makes less and less sense.

    So today, my answer would be to use tf.keras by default, and keep Keras for legacy projects that would be hard to migrate -- that is the future-proof choice for Keras.

    0 讨论(0)
  • 2020-12-24 12:10

    Recent François Chollet tweet suggests to use tf.keras.

    We recommend you switch your Keras code to tf.keras.

    Both Theano and CNTK are out of development. Meanwhile, as Keras backends, they represent less than 4% of Keras usage. The other 96% of users (of which more than half are already on tf.keras) are better served with tf.keras.

    Keras development will focus on tf.keras going forward.

    Importantly, we will seek to start developing tf.keras in its own standalone GitHub repository at keras-team/keras in order to make it much easier for 3rd party folks to contribute.

    0 讨论(0)
  • 2020-12-24 12:17

    If there will be two github repositories, how would you sync pull requests to tf.keras and this repository? Will there be someone applying changes in one repositority to another?

    The codebases will be different, so there will be no need to replicate pull requests. For API changes, you would send a PR to the API spec itself, and changes to the API spec would be replicated across all codebases.

    https://github.com/fchollet/keras/issues/5299#issuecomment-278166426

    0 讨论(0)
  • 2020-12-24 12:18

    Keras is best understood as an API specification, not as a specific codebase. In fact, going fowards there will be two separate implementations of the Keras spec: the internal TensorFlow one, available as tf.keras, written in pure TensorFlow and deeply compatible with all TensorFlow functionality, and the external multi-backend one supporting both Theano and TensorFlow (and likely even more backends in the future).

    https://blog.keras.io/introducing-keras-2.html

    0 讨论(0)
提交回复
热议问题