Skip to content Skip to sidebar Skip to footer

Image Preprocessing In Convolutional Neural Network Yields Lower Accuracy In Keras Vs Tflearn

I'm trying to convert this tflearn DCNN sample (using image preprocessing and augmemtation) to keras: Tflearn sample: import tflearn from tflearn.data_utils import shuffle, to_cate

Solution 1:

In your Keras model, you have forgotten to normalize the validation data as well. You can do this either by using datagen.mean and datagen.std computed over the training data:

# normalize test data; add a small constant to avoid division by zero,
# you can alternatively use `keras.backend.epsilon()`
X_test = (X_test - datagen.mean) / (datagen.std + 1e-8) 

or you can use the datagen.standardize() method to normalize test data:

X_test = datagen.standardize(X_test)

Look at this question on SO for more info: How does data normalization work in keras during prediction?

Don't forget that you should normalize test data by the statistics computed over the training data. NEVER EVER normalize test data by its own statistics.

Caveat: It seems that standardize alters its argument as well... yes, you can confirm this in the source code.


Post a Comment for "Image Preprocessing In Convolutional Neural Network Yields Lower Accuracy In Keras Vs Tflearn"