Skip to content

Latest commit

 

History

History
30 lines (21 loc) · 988 Bytes

File metadata and controls

30 lines (21 loc) · 988 Bytes

Using code examples from keras.io

Code examples documented on keras.io will work fine with tf.keras, but you need to change the imports.

For example, consider this keras.io code:

from keras.layers import Dense
output_layer = Dense(10)

🚩You must change the imports like this (tf.keras):

from tensorflow.keras.layers import Dense
output_layer = Dense(10)

Or, simply use full paths, if you prefer:

# This is more verbose, but can easily see which packages to use,
# and to avoid confusion between standard classes and custom classes.
from tensorflow import keras
output_layer = keras.layers.Dense(10)

This is more verbose, but can easily see which packages to use and to avoid confusion, between standard classes and custom classes.

In production code, I (author of this book) prefer the previous approach. Many people also use from tensorflow.keras import layers followed by layers.Dense(10).