Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
| import keras | |
| from keras.datasets import mnist | |
| from keras.models import Sequential | |
| from keras.layers import Conv2D, AvgPool2D, Flatten, Dense | |
| from keras.optimizers import Adam | |
| from keras.utils import to_categorical | |
| from keras.utils.vis_utils import plot_model |
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
| (train_x, train_y), (test_x, test_y) = mnist.load_data() |
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
| print("The size of train_x is: {}".format(train_x.shape)) | |
| print("The size of train_y is: {}".format(train_y.shape)) | |
| print("The size of test_x is: {}".format(test_x.shape)) | |
| print("The size of test_y is: {}".format(test_y.shape)) |
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
| train_x = train_x.reshape(train_x.shape[0], 28, 28, 1) | |
| test_x = test_x.reshape(test_x.shape[0], 28, 28, 1) |
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
| train_x = train_x/255.0 | |
| test_x = test_x/255.0 |
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
| train_y = to_categorical(train_y, num_classes=10) | |
| test_y = to_categorical(test_y, num_classes=10) |
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
| # Instanciate an empty model | |
| model = Sequential() | |
| # Adding a Convolution Layer C1 | |
| # Input shape = N = (28 x 28) | |
| # No. of filters = 6 | |
| # Filter size = f = (5 x 5) | |
| # Padding = P = 0 | |
| # Strides = S = 1 | |
| # Size of each feature map in C1 is (N-f+2P)/S +1 = 28-5+1 = 24 |
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
| model.compile(loss='categorical_crossentropy', optimizer=Adam(), metrics=['accuracy']) | |
| model.fit(train_x, train_y, batch_size=128, epochs=20, verbose=1, validation_data=(test_x, test_y)) |
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
| score = model.evaluate(test_x, test_y) | |
| print('Test Loss:', score[0]) | |
| print('Test accuracy:', score[1]) |
OlderNewer