Which one is the recommended (or more future-proof) way to use Keras?
What are the advantages/disadvantages of each?
I guess there are more differences than simply saving one pip install
step and writing tensorflow.python.keras
instead of keras
.
Keras is a neural network library while TensorFlow is the open-source library for a number of various tasks in machine learning. TensorFlow provides both high-level and low-level APIs while Keras provides only high-level APIs.
Conclusion (TL;DR) if you are not doing some research purpose work or developing some special kind of neural network, then go for Keras (trust me, I am a Keras fan!!). And it's super easy to quickly build even very complex models in Keras.
To start using Keras, simply install TensorFlow 2. Keras/TensorFlow are compatible with: Python 3.7–3.10.
Both Keras and TensorFlow have training models, so there is no difference there. In terms of speed, TensorFlow is made to be fast and operate at a high performance. Therefore, it is much easier and more effective to scale TensorFlow. For Keras, while being written for simplicity it did lose some speed and performance.
tensorflow.python.keras
is just a bundle of keras with a single backend inside tensorflow
package. This allows you to start using keras by installing just pip install tensorflow
.
keras
package contains full keras library with three supported backends: tensorflow, theano and CNTK. If you even wish to switch between backends, you should choose keras
package. This approach is also more flexible because it allows to install keras updates independently from tensorflow (which may not be easy to update, for example, because the next version may require a different version of CUDA driver) or vice versa. For this reason, I prefer to install keras
as another package.
In terms of API, there is no difference right now, but keras will probably be integrated more tightly into tensorflow in the future. So there is a chance there will be tensorflow-only features in keras, but even in this case it's not a blocker to use keras
package.
UPDATE
As of Keras 2.3.0 release, Francois Chollet announced that users should switch towards tf.keras instead of plain Keras. Therefore, the change to tf.keras instead of keras should be made by all users.
Small update of 2019-10:
With the release of version 2.3.0, team Keras announced the following:
This is also the last major release of multi-backend Keras. Going forward, we recommend that users consider switching their Keras code to tf.keras in TensorFlow 2.0. It implements the same Keras 2.3.0 API (so switching should be as easy as changing the Keras import statements), but it has many advantages for TensorFlow users, such as support for eager execution, distribution, TPU training, and generally far better integration between low-level TensorFlow and high-level concepts like Layer and Model. It is also better maintained.
Development will focus on tf.keras going forward. We will keep maintaining multi-backend Keras over the next 6 months, but we will only be merging bug fixes. API changes will not be ported.
So by now, tf.keras
seems to be the way to go.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With