Skip to content

Instantly share code, notes, and snippets.

@john-adeojo
Created January 22, 2021 00:21
Show Gist options
  • Save john-adeojo/2da7e895553b6b8454f113a2d7a8169b to your computer and use it in GitHub Desktop.
Save john-adeojo/2da7e895553b6b8454f113a2d7a8169b to your computer and use it in GitHub Desktop.
Build Sequential Neural Network Keras
# Build sequential neural network
model = keras.models.Sequential() # Keras sequential model is composed of a single stack of layers connected sequentially
model.add(keras.layers.Input(shape=(784))) # Input layer is a 1D array (no parameters, first layer so specify input shape, not including batch size just size of instances)
model.add(keras.layers.Dense(300, activation="relu")) # Dense hidden layer with 300 neurons and ReLU activation fucntion ( each dense layer manages it's own weight matrix and bias vector)
model.add(keras.layers.Dense(100, activation="relu")) # Second Dense hidden layer of 100 neurons
model.add(keras.layers.Dense(10, activation="softmax")) # Final layer is a dense output layer of 10 neurons with softmax activation function (there are 10 exxclusive classes)
# Displays all the model's layers
model.summary()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment