Keras Tutorial Error: NameError: name 'layers' is not defined
07:58 15 Jul 2018

I am trying to follow this Keras tutorial, but I encounter the following error when compiling using the command python3 test.py:

Traceback (most recent call last):
  File "test.py", line 13, in 
    layers.Dense(64, activation='sigmoid')
NameError: name 'layers' is not defined

My code is as follows:

import tensorflow as tf
from tensorflow import keras

model = keras.Sequential()
# Adds a densely-connected layer with 64 units to the model:
model.add(keras.layers.Dense(64, activation='relu'))
# Add another:
model.add(keras.layers.Dense(64, activation='relu'))
# Add a softmax layer with 10 output units:
model.add(keras.layers.Dense(10, activation='softmax'))

# Create a sigmoid layer:
layers.Dense(64, activation='sigmoid')

# A linear layer with L1 regularization of factor 0.01 applied to the kernel matrix:
layers.Dense(64, kernel_regularizer=keras.regularizers.l1(0.01))
# A linear layer with L2 regularization of factor 0.01 applied to the bias vector:
layers.Dense(64, bias_regularizer=keras.regularizers.l2(0.01))

# A linear layer with a kernel initialized to a random orthogonal matrix:
layers.Dense(64, kernel_initializer='orthogonal')

Python version: 3.6.6

Operating System: MacOS High Sierra

I am also doing this all in the command line (tensorflow)$ environment.

python python-3.x tensorflow keras keras-layer