The dataset we will be using

MivoCloud
2 min readOct 2, 2018

--

Step 2 — Importing the MNIST Dataset

The dataset we will be using in this tutorial is called the MNIST dataset, and it is a classic in the machine learning KVM VPS in US Oregon community. This dataset is made up of images of handwritten digits, 28x28 pixels in size. Here are some examples of the digits included in the dataset:

Let’s create a Python program to work with this dataset. We will use one file for all of our work in this tutorial. Create a new file called main.py:

  • touch main.py

Now open this file Cloud Hosting in Europe in your text editor of choice and add this line of code to the file to import the TensorFlow library:

main.py

import tensorflow as tf

Add the following lines of code to your file to import the MNIST dataset and store the image data in the variable mnist:

main.py

from tensorflow.examples.tutorials.mnist import input_data
mnist = input_data.read_data_sets("MNIST_data/", one_hot=True) # y labels are oh-encoded

When reading in the data, we are using one-hot-encoding to represent the labels (the actual digit drawn, e.g. “3”) of the images. One-hot-encoding uses a vector of binary values to represent numeric or categorical values. As our labels are for the digits 0–9, the vector contains ten values, one for each possible digit Hourly VPS in Europe. One of these values is set to 1, to represent the digit at that index of the vector, and the rest are set to 0. For example, the digit 3 is represented using the vector [0, 0, 0, 1, 0, 0, 0, 0, 0, 0]. As the value at index 3 is stored as 1, the vector therefore represents the digit 3.

To represent the actual images themselves, the 28x28 pixels are flattened into a 1D vector which is 784 pixels in size. Each of the 784 pixels making up the image is stored as a value between 0 and 255. This determines the grayscale of the pixel, as our images are presented in black and white only. So a black pixel is represented SSD Cloud Hosting in Romania by 255, and a white pixel by 0, with the various shades of gray somewhere in between.

We can use the mnist variable to find out the size of the dataset we have just imported. Looking at the num_examples for each of the three subsets, we can determine that the dataset has been split into 55,000 images for training, 5000 for validation, and 10,000 for testing. Add the following lines to your file:

main.py

n_train = mnist.train.num_examples # 55,000
n_validation = mnist.validation.num_examples # 5000
n_test = mnist.test.num_examples # 10,000

Now Dedicated Server in Moldova that we have our data imported, it’s time to think about the neural network.

\

--

--

MivoCloud
MivoCloud

Written by MivoCloud

Sales of servers, hosting and cloud vps

No responses yet