0

Currently in tensorflow 2.0, Keras can be imported by both tensorflow.keras and tensorflow.python.keras. What's the difference and how should I choose from these two imports?

from tensorflow.keras import *
from tensorflow.python.keras import *

From my understanding, tensorflow.python.keras is pretty much the same as the python package Keras, while tensorflow.keras is implemented by TensorFlow which might be more compatible with TF, but do not have all packages as in Keras such as Layer, InputSpec, etc.

One other issue is that for some IDEs like PyCharm, they cannot find or auto-complete packages from tensorflow.keras, and the temporary solution is to use tensorflow.python.keras instead. (from tensorflow issue)

0

3 Answers 3

1

In TensorFlow 2.0, tf.keras is recommended. This version is stable now.

Sign up to request clarification or add additional context in comments.

Comments

0

tensorflow.keras and tensorflow.python.keras are exactly the same package, what tells you that they are different?

You are not supposed to use tensorflow.python imports directly, as per this answer: https://stackoverflow.com/a/47306203/6108843

2 Comments

Sorry I forgot to mention that I am using tensorflow 2.0. In 2.0, some packages in keras are missing such as tensorflow.keras.layers.InputSpec. And if they are exactly the same, why does tensorflow keep both of them?
@junhuizh The answer to that is available in the other answer I linked: stackoverflow.com/a/47306203/6108843
0

As of the latest version of Tensorflow, it is recommended to use tensorflow.keras This is likely due to depreciation since TF is evolving rapidly.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.