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 models | |
from keras import layers | |
network = models.Sequential() | |
network.add(layers.Dense(512, activation='relu', input_shape=(28 * 28, ))) | |
network.add(layers.Dense(10, activation='softmax')) |
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
network.compile(optimizer='rmsprop', | |
loss='categorical_crossentropy', | |
metrics = ['accuracy']) |
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
# Preprocessing training data | |
train_images = train_images.reshape((60000, 28*28)) | |
train_images = train_images.astype('float32') / 255 | |
# Preprocessing test data | |
test_images = test_images.reshape((10000, 28 * 28)) | |
test_images = test_images.astype('float32') / 225 |
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.utils import to_categorical | |
train_labels = to_categorical(train_labels) | |
test_labels = to_categorical(test_labels) |
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
# Fit the model to its training data | |
# Epochs = 5 | |
# Batch Size = 128 | |
network.fit(train_images, train_labels, epochs=5, batch_size=128) |
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
# Calculate Test loss and Test Accuracy | |
test_loss, test_acc = network.evaluate(test_images, test_labels) | |
# Print Test loss and Test Accuracy | |
print(f"Test Loss: {test_loss}\nTest Accuracy : {test_acc * 100} %") |
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 ann_visualizer.visualize import ann_viz | |
ann_viz(network, title="MNIST network", filename="MNIST.gv") |
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
OlderNewer