Tutorial. Using vectors or matrices as input to the neural network

Wednesday, December 06, 2017

App

Posted by Yoshiyuki Kobayashi

In addition to images, Neural Network Console also supports vector and matrix inputs.
This tutorial explains how to input vector and matrix data.

How to input vectors (entering directly in a dataset CSV file)

You can directly enter vectors in dataset CSV files of Neural Network Console.

For example, to use a five-dimensional vector, create five rows, x__0 to x__4 (variable name x, double underscores, vector element index 0 to 4), as shown below, and enter the element values in the cells.



Example: Dataset CSV where x is a five-dimensional vector

Neural Network Console contains Fisher’s iris dataset created in this format.
Windows Version
\samples\sample_dataset\iris_flower_dataset\

Cloud Version
iris_flower_dataset.iris_flower_dataset_training_delo

Data prepared as vectors can be input to the neural network by inserting an input layer with its size set to the number of vector elements when the network structure is designed.



Using an input layer with size set to 5 to input vectors with five elements

This method makes it easy to use small datasets for vectors that are less than around 100 dimensions and with less than 100,000 data samples. But, the disadvantage is that if the dataset becomes too large, the size of the dataset CSV file will be enormous. Moreover, the data may not even fit in the memory depending on the size of the data.

In such a case, you can use another method in which a CSV file is created for each data sample (a vector is expressed as a one-column matrix). This is explained later.

How to input matrices (creating a CSV file for each data sample)

This section explains how to create a CSV file in which matrix data is written for each data sample. As an example for explanation, let’s look at a case in which acceleration sensor signals expressed by three-axis (XYZ) acceleration × 16 samples are input into a neural network.



Illustration of input acceleration sensor signals

The above acceleration sensor signals can be expressed in matrix format as shown below. To use matrix data in Neural Network Console, we need to create matrix data CSV files (data CSV files), as shown below, for each data sample.



Example of a data CSV file

After creating the data CSV files, we need to create a dataset CSV file by entering the names of the data CSV files in the cells, in the same manner as the handling of images.



Example of a dataset CSV file for handling data CSV files

Files such as ./train/0.csv are the individual data CSV files that we created earlier. Data prepared as matrices can be input to the neural network by inserting an input layer with its size set to the number of rows and columns when the network structure is designed. In this example, the size is 16,3 because there are 16 rows and 3 columns.



Using an input layer with size set to 16,3 to input matrices with 16 rows and 3 columns