Last active
November 5, 2021 09:38
-
-
Save conormm/e1dd2ee37733f4817e09a41d625d9e7f to your computer and use it in GitHub Desktop.
This file contains hidden or 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.datasets import mnist | |
from keras.models import Sequential | |
from keras.layers.core import Dense, Dropout, Activation | |
from keras.utils import np_utils | |
import numpy as np | |
l1_nodes = 200 | |
l2_nodes = 100 | |
final_layer_nodes = 10 | |
(X_train, y_train), (X_test, y_test) = mnist.load_data() | |
X_train = X_train.reshape(60000, 784).astype("float32") | |
X_test = X_test.reshape(10000, 784).astype("float32") | |
X_train /= 255 | |
X_test /= 255 | |
Y_train = np_utils.to_categorical(y_train, nb_classes) | |
Y_test = np_utils.to_categorical(y_test, nb_classes) | |
# model | |
model = Sequential() | |
model.add(Dense(units=l1_nodes, input_shape=(784, ), activation="relu")) | |
model.add(Dense(units=l2_nodes, input_shape=(l1_nodes, ), activation="relu", )) | |
model.add(Dense(units=final_layer_nodes, input_shape=(l2_nodes, ))) | |
model.add(Activation("softmax")) | |
model.compile(loss='categorical_crossentropy', | |
optimizer='sgd', | |
metrics=["accuracy"]) | |
model.fit(X_train, Y_train, | |
batch_size=100, | |
epochs=4, | |
verbose=1, | |
validation_data=(X_test, Y_test)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment