Last active
November 8, 2018 15:27
-
-
Save piyush2896/75916748fc73a5bbab0f5c7f5e5bdab3 to your computer and use it in GitHub Desktop.
lenet code (slightly modified) for https://predictiveprogrammer.com/famous-convolutional-neural-network-architectures-1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from keras import layers | |
from keras.models import Model | |
def lenet_5(in_shape=(32,32,1), n_classes=10, opt='sgd'): | |
in_layer = layers.Input(in_shape) | |
conv1 = layers.Conv2D(filters=20, kernel_size=5, | |
padding='same', activation='relu')(in_layer) | |
pool1 = layers.MaxPool2D()(conv1) | |
conv2 = layers.Conv2D(filters=50, kernel_size=5, | |
padding='same', activation='relu')(pool1) | |
pool2 = layers.MaxPool2D()(conv2) | |
flatten = layers.Flatten()(pool2) | |
dense1 = layers.Dense(500, activation='relu')(flatten) | |
preds = layers.Dense(n_classes, activation='softmax')(dense1) | |
model = Model(in_layer, preds) | |
model.compile(loss="categorical_crossentropy", optimizer=opt, | |
metrics=["accuracy"]) | |
return model | |
if __name__ == '__main__': | |
model = lenet_5() | |
print(model.summary()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment