title: having error on model.fit_generator()
body: <p>I am trying to detect traffic lights. I have images with 3 labels so I put my training data and validation data into 3 subfolders under train and validation. I am facing an error at model.fit_generator() when I` run the program. Other things are working fine.  </p>
  
  <p>`    </p>
  
  <pre><code>import os
  
  from keras.layers import Dense, Dropout, Flatten, MaxPooling2D, 
  Convolution2D
  from keras.models import Sequential
  from keras.preprocessing.image import ImageDataGenerator
  import keras
  from keras.optimizers import Adam
  
  NUM_CHANNELS = 3
  IMAGE_WIDTH = 224 # Original: 455
  IMAGE_HEIGHT = 224 # Original: 256
  NUM_CLASSES = 3
  base_script_name = os.path.splitext(__file__)[0]
  filepath=base_script_name + "-{epoch:02d}-val_acc-{val_acc:.2f}.hdf5"
  
  def get_generator(directory, train):
  if train:
  datagen = ImageDataGenerator(
    rescale=1./255,
    shear_range=0.2,
    zoom_range=0.2,
    horizontal_flip=True)
  else:
  datagen = ImageDataGenerator(rescale=1./255)
  return datagen.flow_from_directory(
  directory=directory,
  target_size=(IMAGE_WIDTH, IMAGE_HEIGHT),
  batch_size=8,
  class_mode='categorical')
  
  model = Sequential([
  Convolution2D(16, 3, 3, border_mode='same', subsample=(2, 2), input_shape=
  (IMAGE_WIDTH, IMAGE_HEIGHT, NUM_CLASSES), activation='relu'),
  MaxPooling2D(pool_size=(3, 3)),
  Dropout(0.2),
  
  Convolution2D(32, 3, 3, border_mode='same', activation='relu'),
  MaxPooling2D(pool_size=(3, 3)),
  Dropout(0.2),
  
  Convolution2D(64, 3, 3, border_mode='same', activation='relu'),
  MaxPooling2D(pool_size=(2, 2)),
  Dropout(0.2),
  
  Flatten(),
  Dense(128, activation='tanh'),
  Dropout(0.3),
  Dense(NUM_CLASSES, activation='softmax'),
  ])
  model.summary()
  
  directory = '/home/nishat/traffic_light/nexar/try/data/'
  train_generator = get_generator(directory+'/train', True)
  validation_generator = get_generator(directory+'valid', False)
  
  model.compile(optimizer=Adam(lr=0.0003), loss='categorical_crossentropy', 
  metrics=['accuracy'])
  
  # Callbacks
  checkpoint = keras.callbacks.ModelCheckpoint(filepath, monitor='val_acc', 
  verbose=1, save_best_only=False, mode='auto')
  tensorboard = keras.callbacks.TensorBoard(log_dir='./tensorboar', 
  histogram_freq=0, write_graph=True, write_images=True)
  callbacks = [checkpoint, tensorboard]
  
  model.fit_generator(
  train_generator,
  samples_per_epoch=train_generator.shape,
  nb_epoch=200,
  validation_data=validation_generator,
  nb_val_samples=validation_generator.shape,
  callbacks=callbacks,
  )
  
  model.evaluate_generator(validation_generator, 
  val_samples=len(validation_generator.filenames))`
  </code></pre>
  
  <p><strong>I am getting an error like this:</strong></p>
  
  <pre><code>Found 16791 images belonging to 3 classes.
  Found 1868 images belonging to 3 classes.
  Traceback (most recent call last):
  
    File "&lt;ipython-input-1-303a170ea444&gt;", line 1, in &lt;module&gt;
      runfile('/home/nishat/traffic_light/nexar/try/train.py', wdir='/home/nishat/traffic_light/nexar/try')
  
    File "/home/nishat/anaconda3/lib/python3.6/site-packages/spyder/utils/site/sitecustomize.py", line 866, in runfile
      execfile(filename, namespace)
  
    File "/home/nishat/anaconda3/lib/python3.6/site-packages/spyder/utils/site/sitecustomize.py", line 102, in execfile
      exec(compile(f.read(), filename, 'exec'), namespace)
  
    File "/home/nishat/traffic_light/nexar/try/train.py", line 69, in &lt;module&gt;
      samples_per_epoch=train_generator.shape,
  
  AttributeError: 'DirectoryIterator' object has no attribute 'shape'
  </code></pre>
  
  <p><strong>If anyone can suggest me where I need to change my code, I will be really grateful. Thanks</strong></p>