Normalizing image data before training - LSTM version

1 minute read

Published:

Intro

Repeating my previous testing, this time using the LSTM version of my model.

Below are results from three different image preprocessing methods, each trained five times with five different weight initializations and five different batch randomizations. Lines are the mean of the five runs, with error bars showing one standard deviation. ‘test’ in the plots below is actually the results on validation data generated using Keras’s validation_split argument to the fit method.

Methods and Results

First is my initial code with no normalization, just dividing by 255 to get values from 0.0 to 1.0.

# After loading images from multiple directories into the list 'images'
images = np.array(images)
images = images.astype(np.float) / 255.0

No Image Normalization

Second is centering the mean on zero, separately for each color band.

# After loading images from multiple directories into the list 'images'
images = np.array(images)
images = images.astype(np.float)
images[:,:,:,0] -= np.mean(images[:,:,:,0])
images[:,:,:,1] -= np.mean(images[:,:,:,1])
images[:,:,:,2] -= np.mean(images[:,:,:,2])

Mean Subtraction

Third is the above plus dividing each color band by its standard deviation.

# After loading images from multiple directories into the list 'images'
images = np.array(images)
images = images.astype(np.float)
images[:,:,:,0] -= np.mean(images[:,:,:,0])
images[:,:,:,1] -= np.mean(images[:,:,:,1])
images[:,:,:,2] -= np.mean(images[:,:,:,2])
images[:,:,:,0] /= np.std(images[:,:,:,0])
images[:,:,:,1] /= np.std(images[:,:,:,1])
images[:,:,:,2] /= np.std(images[:,:,:,2])

With Normalization

The code used to run these experiments was this commit. I manually changed the lines listed above for the three separate runs. Total number of training samples was approximately 7000.

Conclusions

Normalization works about the same in LSTMs as it does with a Fully Connected layer, although there is a lot more variability with an LSTM.

Models

Future

  • Repeat the above with a GRU layer in place of the LSTM.