What is the difference between Keras and tf.keras in TensorFlow 1.1+?
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.
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
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.