title: Why does the keras model compile but the fit_generator command throws a 'model not compiled runtime error'?
body: <p>I've set up a custom CNN with K-fold cross-validation in keras with tensorflow back-end. 
  The model.compile() function is called before starting the training, but the model.fit_generator() function call results in an runtime error: "You must compile your model before using it."</p>
  
  <p>I do data augmentation with ImageDataGenerator and use the fit_generator function for training.</p>
  
  <p>The only related issue I've found up untill now had to do with the tensorflow <a href="https://github.com/tensorflow/tensorflow/issues/18287" rel="noreferrer">eager execution</a> feature which seems to not be enabled in Keras. </p>
  
  <p>Here is the code:</p>
  
  <p>model definition:</p>
  
  <pre><code>model = Sequential()
  model.add(Conv2D(24, (5, 5), 
            strides=(1, 1), 
            padding="valid", 
            data_format="channels_last",
            activation='relu', 
            use_bias=True,
            ))#out=96
  model.add(Dropout(.25))
  model.add(MaxPooling2D(pool_size=(2, 2)))#out=48
  model.add(Conv2D(32, (3, 3), 
            strides=(1, 1), 
            padding="valid", 
            data_format="channels_last",
            activation='relu', 
            use_bias=True,
            ))#out=46
  model.add(MaxPooling2D(pool_size=(2, 2)))#out=23
  model.add(Conv2D(48, (3, 3), 
            strides=(1, 1), 
            padding="valid", 
            data_format="channels_last",
            activation='relu', 
            use_bias=True,
            ))#out=21
  model.add(MaxPooling2D(pool_size=(2, 2)))#padding???
  model.add(Flatten())
  model.add(Dense(3, activation='softmax'))
  </code></pre>
  
  <p>...here would be the data initialization...</p>
  
  <p>setting up the ImageGenerator:</p>
  
  <pre><code>datagen_training = ImageDataGenerator(
              rotation_range = 20,
              width_shift_range = 0.3,
              height_shift_range=0.3,
              zoom_range=0.2,
              fill_mode = "constant",
              cval = 0,
              vertical_flip = True,
              validation_split = 0.2
              )
  datagen_training.fit(data)
  </code></pre>
  
  <p>model setup and training:</p>
  
  <pre><code>rmsprop = optimizers.RMSprop(lr=0.001)#docu says to only tune the learning rate
  kf = KFold(n_splits=FOLDS, shuffle = True, random_state=78945)
  model.compile(rmsprop, loss = losses.categorical_crossentropy, metrics=[metrics.categorical_accuracy])
  acc_hist = []
  while True:
      history = object()
      for train_idx, val_idx in kf.split(data, labels):
          x_train, y_train = data[train_idx], labels[train_idx]
          x_val, y_val = data[val_idx], labels[val_idx]
          data_iterator = datagen_training.flow(x_train, y_train, batch_size=BATCH_SIZE)
          history = model.fit_generator(data_iterator, steps_per_epoch=len(x_train) // BATCH_SIZE, epochs=1)
      acc_hist.append(history.history['categorical_accuracy'][0])
      #stop if accuracy doesn't change within 3 epochs
      if stopping_criterion_met:
          break
  </code></pre>