mnist dataset — this is a bunch of handwritten images as shown in the picture below.
We can get 99.06 accuracy % using CNN (Convolutionary neural Network) with functional model. The reason for using the functional model is to keep it simple when connecting layers.
| tr> |
Test data: strong > Used to test the model for training the model.
Train data: Used to train our model.
| tr> |
Because the model output can be any digits from 0 to 9., we need 10 classes at the output. To draw an output for 10 classes, use the
keras.utils.to_categorical function, which will have 10 columns. Of those 10 columns, only one value will be one and the other 9 will be zero, and that one output value will denote the class of the digit.
The dataset is now ready, so let`s move on to the cnn model:
layer1 — a Conv2d layer that convolves the image using 32 filters of each size (3 * 3).
layer2 is again a Conv2D layer, which is also used to collapse the image and uses 64 filters of each size (3 * 3).
layer3 — this is the MaxPooling2D layer that picks the maximum value from the size matrix (3 * 3).
layer4 shows a drop rate of 0.5.
layer5 flattens the output received from layer4, and this anti-aliasing output is passed to layer6.
layer6 — it is a hidden layer of a neural network containing 250 neurons.
layer7 — this is an output layer with 10 neurons for 10 output classes using the softmax function.
First, we made a model object as shown in the lines above, where [inpx] — this is the entrance to the model, and layer7 — this is the output of the model. We compiled the model using the required optimizer, loss function and printed the precision, and in the latter case, model.fit was called with parameters such as x_train (means image vectors), y_train (means label), number of epochs, and batch size. Using the x_train fitting function, the y_train dataset is fed to a model with a specific batch size.
Since you are interested in learning more about designing data visualizations (by virtue of the fact that you’re reading this book), then chances are good that you have been the reader of other peop...
A Practical Approach to Computer Algorithms Using Python® and C# Rod Stephens started out as a mathematician, but while studying at MIT, he discovered how much fun algorithms are. He took every al...
While there is no arguing about the staying power of the cloud model and the benefits it can bring to any organization or government, mainstream adoption depends on several key variables falling into ...
Python for Programmers: with Big Data and Artificial Intelligence Case Studies This book, written for programmers with a high-level experience in another language, uses how-to instructions to teach...