Skip to content

Instantly share code, notes, and snippets.

@securetorobert
Created October 1, 2020 17:09
Show Gist options
  • Save securetorobert/c981241377b0ba0dd1c871ceb13b97e2 to your computer and use it in GitHub Desktop.
Save securetorobert/c981241377b0ba0dd1c871ceb13b97e2 to your computer and use it in GitHub Desktop.
LeNet with a normalization layer
# Create the input vector for images
inputs = Input((WIDTH, HEIGHT))
# The first layer is the preprocessing layer, which is bound to the input vector
x = Normalize()(inputs)
# Implement LeNet
x = tf.layers.Conv2D(filters=6, kernel_size=(5,5), strides=1, activation='tanh', input_shape=(HEIGHT, HEIGHT, NUM_CHANNELS))(x)
x = tf.layers.AveragePooling2D(pool_size=(2,2))(x)
x = tf.layers.Conv2D(filters=16, kernel_size=(5,5), strides=1, activation='tanh')(x)
x = tf.layers.AveragePooling2D(pool_size=(2,2))(x)
x = tf.layers.Flatten()(x)
x = tf.layers.Dense(120)(x)
x = tf.layers.Dense(84)(x)
# Create an output layer for classifying the 10 digits
outputs = tf.layers.Dense(NCLASSES, activation='softmax')(x)
# Instantiate the model
model = Model(inputs, outputs)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment