更新时间:2023-12-02 14:35:04
您正在混淆:
tf.keras
( https://www.tensorflow.org/guide/keras )在TensorFlow中实现Keras API规范.此外,tf.keras
API已进行优化以与其他TensorFlow模块配合使用:例如,您可以将tf.data
数据集传递给tf.keras
模型的.fit()
方法,或者将tf.keras
模型转换为具有tf.keras.estimator.model_to_estimator
的TensorFlow估算器.当前,tf.keras
API是在TensorFlow中构建模型时要寻找的高级API,并且将来会继续与其他TensorFlow功能集成.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.因此回答您的问题:不,您不需要将Keras代码转换为tf.keras代码. Keras代码使用Keras库,甚至可能在与TensorFlow不同的后端上运行,并且将来会继续正常运行.更重要的是,不仅要在同一脚本中混合Keras和tf.keras
对象,还很重要,因为这可能会产生不兼容性,例如,您可以看到
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.
更新:将废弃Keras,转而使用tf.keras: https ://twitter.com/fchollet/status/1174019423541157888
Update: Keras will be abandoned in favor of tf.keras: https://twitter.com/fchollet/status/1174019423541157888