Monday, September 24, 2018

Keras deep learning training input

Keras allows you to use neural networks easily. It is very easy to try a deep learning prototype with Tensorflow or CNTK. The training starts with just one command like below.
Understanding what is "x_train" and "y_train" is a starting point.

x_train

x_train is multi-dimensional array including numerical elements of target contents. For example, when you train 1000 images with 85 * 128 pixels RGB, x_train should be a 4-dimensional array (1000, 85, 128, 3).
x_train datatype is normalized between 0 and 1 with float32 in this case. (RGB is described as 8 bit)



y_train

y_train is a 2-dimensional array that contains classification index. If you want to train a model that classifies 4 vehicle names by using 1000 images, y_train looks like a 2-dimensional array (1000, 4). Sample code to create y_train array is below
keras.utils.to_categorical(labels_encoded, 4) changes index array (1000) into binary matrix (1000, 4)

scikit-learn's fit is able to make the index in order. I was wondering how the order is defined? I found out it is alphabetical sequence, and capital is prioritized like below.

Code
Output

le.transoform(labels) changes from string index into numerical values