NameError: name 'keras' is not defined


how do i fix this

Please look at the way Dense is referenced keeping in mind that keras is not imported.
Do brush up on python before moving forward.

1 Like

Use tf.keras.layers.Dense(…)
or you may just import keras from tensorflow by adding the line above before the code-
from tensorflow import keras

1 Like

Hey guys,

I have similar issue. I tried to import keras correctly using

from tensorflow import keras

in the first section, or adding tf before keras mention in Dense call in the section number 2:

model = tf.keras.Sequential(
        [tf.keras.layers.Dense(units=1, input_shape=[1])]
    )

the issue with grader still persist:

There was a problem compiling the code from your notebook. Details:
name ‘keras’ is not defined

Any help would be highly appreciated

1 Like

The grader might just pick certain cells. So, unless you import keras from tensorflow inside one of the graded functions, odds are good that it won’t work. Why not use tf.keras ?

1 Like