title: Split data directory into training and test directory with sub directory structure preserved
body: <p>I am interested in using ImageDataGenerator in Keras for data augmentation. But it requires that training and validation directories with sub directories for classes be fed in separately as below (this is from Keras documentation). I have a single directory with 2 subdirectories for 2 classes (Data/Class1 and Data/Class2). How do I randomly split this into training and validation directories </p>
  
  <pre><code>    train_datagen = ImageDataGenerator(
      rescale=1./255,
      shear_range=0.2,
      zoom_range=0.2,
      horizontal_flip=True)
  
      test_datagen = ImageDataGenerator(rescale=1./255)
  
      train_generator = train_datagen.flow_from_directory(
      'data/train',
      target_size=(150, 150),
      batch_size=32,
      class_mode='binary')
  
     validation_generator = test_datagen.flow_from_directory(
      'data/validation',
      target_size=(150, 150),
      batch_size=32,
      class_mode='binary')
  
     model.fit_generator(
      train_generator,
      steps_per_epoch=2000,
      epochs=50,
      validation_data=validation_generator,
      validation_steps=800)
  </code></pre>
  
  <p>I am interested in re-running my algorithm  multiple times with random training and validation data splits.</p>