I'm now learning tensorflow and keras and I see all tutorials have these two imports:
import tensorflow as tf
from tensorflow import keras
Based on my understanding of python import, I thought the second line was an extra, since if we have already imported tensorflow in the first line, then we shall have imported every module in tensorflow. Just like if we have
import math
then we shouldd have math.log(), math.sqrt() available.
However, if I comment
from tensorflow import keras
then this line of code
model = tf.keras.Sequential([keras.layers.Dense(units=1, input_shape=[1])])
would return NameErrorTraceback (most recent call last)
<ipython-input-3-740ba65f0ade> in <module>()
----> 1 model = tf.keras.Sequential([keras.layers.Dense(units=1, input_shape=[1])])
NameError: name 'keras' is not defined
Why can't we directly use tf.keras if we only have import tensorflow as tf? What's special about this import compared to the import in import math?
Thanks