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
With the current version of TensorFlow, do we need to change every Keras code as?
from tensorflow.keras import models
We recommend the TensorFlow backend. So Keras is a skin (an API). TensorFlow has decided to include this skin inside itself as tf.keras. Since Keras provides APIs that TensorFlow has already implemented (unless CNTK and Theano overtake TensorFlow which is unlikely), tf.keras would keep up with Keras in terms of API diversity.
The tf.keras submodule was introduced in TensorFlow v1.10.0, the first step in integrating Keras directly within the TensorFlow package itself. The tf.keras package is/was separate from the keras package you would install via pip (i.e., pip install keras ).
From Keras repo.: Keras is a high-level neural networks API, written in Python and capable of running on top of TensorFlow, CNTK, or Theano. Before installing Keras, please install one of its backend engines: TensorFlow, Theano, or CNTK.
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.
You are mixing things up:
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.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.
Update: Keras will be abandoned in favor of tf.keras: https://twitter.com/fchollet/status/1174019423541157888
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