title: Not understanding normalization when using ImageDataGenerator
body: <p>Im trying to build a simple image classifier using Keras with Tensorflow as backend. However im having a very hard time understanding how nomalization is done in Keras.</p>
  
  <p>It is my understanding that in Machine Learning you calculate the mean and std of the training + validation set and then reuse the mean and std when normalizing the test set and when doing prediction on new data. So whit this in mind I will explain what Im not understanding in each part of Keras. </p>
  
  <pre><code>train_datagen = ImageDataGenerator(rescale=1./255, samplewise_center=True, samplewise_std_normalization=True, shear_range=0.2, zoom_range=0.2)
  test_datagen = ImageDataGenerator(rescale=1./255, samplewise_center=True, samplewise_std_normalization=True)
  batch_size = 1024
  train_generator = train_datagen.flow(X_train, one_hot_train_labels, batch_size=batch_size, shuffle=True)
  validation_generator = test_datagen.flow(X_valid, one_hot_valid_labels, batch_size=batch_size)
  </code></pre>
  
  <p>First questions are with regards to <code>ImageDataGenerator</code>.
  In the <a href="https://keras.io/preprocessing/image/" rel="nofollow noreferrer">documentation</a> it says that the <code>flow</code> function normalizes the data, then I have tree questions regarding this:</p>
  
  <ol>
  <li>What is the effect of <code>samplewise_std_normalization</code> and <code>samplewise_center</code> if it is the flow function that does the normalization?</li>
  <li>Why use rescale if I also do normalization?</li>
  <li><p>How can Keras do normalization on augmentad data that is generated at runtime so the mean and std is not know before start?</p>
  
  <p>result = model.evaluate(X_test, one_hot_test_labels)</p></li>
  </ol>
  
  <p>When we run <code>evaluate</code> I have one question:</p>
  
  <ol>
  <li><p>How is the normalization handled here? I dont have access to the mean and std so I cant apply them to also the testing set?</p>
  
  <p>predict_softmaxs = model.predict(np.array(resized_images))</p></li>
  </ol>
  
  <p>When I run <code>predict</code> I have one question:</p>
  
  <ol>
  <li>Again I dont have access to the mean and std so I cant apply it to the prediction image?</li>
  </ol>