问题
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.
回答1:
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
回答2:
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
来源:https://stackoverflow.com/questions/55178230/what-is-the-difference-between-keras-and-tf-keras