Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between keras and tf.keras?

I'm learning TensorFlow and Keras. I'd like to try https://www.amazon.com/Deep-Learning-Python-Francois-Chollet/dp/1617294438/, and it seems to be written in Keras.

Would it be fairly straightforward to convert code to tf.keras?

I'm not more interested in the portability of the code, rather than the true difference between the two.

like image 620
eugene Avatar asked Mar 15 '19 08:03

eugene


People also ask

Are TensorFlow and keras separate?

Now that TensorFlow 2.0 is released both keras and tf. keras are in sync, implying that keras and tf. keras are still separate projects; however, developers should start using tf.

Is keras better than TensorFlow?

Keras focuses on being easy to read and write and concise in its simplicity based on the architecture. In comparison, TensorFlow is very powerful but not nearly as easy to understand. When viewing the difference, TensorFlow is much more difficult to learn and understand. In datasets, Keras is better for smaller sets.

Should I import keras or TensorFlow keras?

User should always use from tensorflow import keras which will give them the public API. import keras will directly access the keras PIP package, which is not 100% same as the public API namespace. It will probably give you keras. Model/layers.

Do I need keras for TensorFlow?

You can use TensorFlow without Keras and you can use Keras with CNTK, Theano, or other machine learning libraries. While you can use Keras without TensorFlow, Keras is always going to need a backend; it's simply an interface rather than a major processing utility.


2 Answers

The difference between tf.keras and keras is the Tensorflow specific enhancement to the framework.

keras is an API specification that describes how a Deep Learning framework should implement certain part, related to the model definition and training. Is framework agnostic and supports different backends (Theano, Tensorflow, ...)

tf.keras is the Tensorflow specific implementation of the Keras API specification. It adds the framework the support for many Tensorflow specific features like: perfect support for tf.data.Dataset as input objects, support for eager execution, ...

In Tensorflow 2.0 tf.keras will be the default and I highly recommend to start working using tf.keras

like image 188
nessuno Avatar answered Sep 21 '22 14:09

nessuno


At this point tensorflow has pretty much entirely adopted the keras API and for a good reason - it's simple, easy to use and easy to learn, whereas "pure" tensorflow comes with a lot of boilerplate code. And yes, you can use tf.keras without any issues, though you might have to re-work your imports in the code. For instance

from keras.layers.pooling import MaxPooling2D

Would turn into:

from tensorflow.keras.layers import MaxPooling2D
like image 45
Alexander Ejbekov Avatar answered Sep 20 '22 14:09

Alexander Ejbekov