Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Give 99.28% accuracy on MNIST #3

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 22 additions & 8 deletions CNN.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,36 @@ def __init__(self):
def build_and_compile_model(self):
if self.modelbuilt:
return
# Add a Convolutional layer
self.model.add(tf.keras.layers.Conv2D(32, (3, 3), input_shape=(28, 28, 1), activation='relu'))
# Add a Max pooling layer
# Add a Convolutional layers and Max pooling layers
self.model.add(tf.keras.layers.Conv2D(32, 5, input_shape=(28, 28, 1), activation='relu'))
self.model.add(tf.keras.layers.MaxPool2D())
# Add the flattened layer

self.model.add(tf.keras.layers.Conv2D(64, 3,activation='relu'))
self.model.add(tf.keras.layers.MaxPool2D())

self.model.add(tf.keras.layers.Conv2D(128, 3,activation='relu'))
self.model.add(tf.keras.layers.MaxPool2D())

self.model.add(tf.keras.layers.Conv2D(256, 2,activation='relu'))
self.model.add(tf.keras.layers.MaxPool2D())

self.model.add(tf.keras.layers.Flatten())
# Add the hidden layer
self.model.add(tf.keras.layers.Dense(512, activation='relu'))
# Adding a dropout layer

# Add the hidden layers and Dropout
self.model.add(tf.keras.layers.Dense(50, activation='relu'))
self.model.add(tf.keras.layers.Dropout(0.2))

self.model.add(tf.keras.layers.Dense(25, activation='relu'))
self.model.add(tf.keras.layers.Dropout(0.2))

# Add the output layer
self.model.add(tf.keras.layers.Dense(10, activation='softmax'))
# Compiling the model
self.model.compile(optimizer="adam", loss="sparse_categorical_crossentropy", metrics=["accuracy"])
self.model.compile(optimizer="nadam", loss="sparse_categorical_crossentropy", metrics=["accuracy"])
self.modelbuilt = True



'''This function loads the Train/Test dataset, trains the model and evaluates it.
It prints the accuracy attained on the test set in the end'''
def train_and_evaluate_model(self):
Expand Down