Skip to content

Instantly share code, notes, and snippets.

@sdcubber
Created September 15, 2018 13:56
Show Gist options
  • Save sdcubber/df8533bd890859223340ded0edc6e835 to your computer and use it in GitHub Desktop.
Save sdcubber/df8533bd890859223340ded0edc6e835 to your computer and use it in GitHub Desktop.
# Sequential API: define a model, add linear stack of layers
sequential_network = models.Sequential()
sequential_network.add(layers.Dense(512, activation='relu', input_shape=(28 * 28, ), name='input'))
sequential_network.add(layers.Dense(256, activation='relu', name='dense_layer'))
sequential_network.add(layers.Dense(10, activation='softmax', name='output'))
# Functional API: tie layers together in a potentially complex DAG, wrap in a keras Model
input_layer = keras.layers.Input((28*28, ))
dense_layer = keras.layers.Dense(512, activation='relu')(input_layer)
dense_layer = keras.layers.Dense(256, activation='relu')(dense_layer)
output_layer = keras.layers.Dense(10, activation='softmax')(dense_layer)
functional_network = keras.models.Model(inputs=input_layer, outputs=output_layer)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment