title: Keras callback causes error : You must feed a value for placeholder tensor 'conv2d_1_input' with dtype float
body: <p>im new to tensorflow and keras and deep learning scene.
  i tried to make a simple neural network to recognize emotion in fer2013 database and keep running into this error after training the first epoch</p>
  
  <blockquote>
  <pre><code>File "main.py", line 92, in &lt;module&gt;
      train(image_data, label_data, conv_arch, dense, dropout, epochs, batch_size, validation_split, patience)
  File "main.py", line 38, in train
      hist = model.fit(image_data, label_data, epochs=epochs, batch_size=batch_size, validation_split=validation_split, callbacks=callbacks, shuffle=True, verbose=1)
  File "/Users/rifkibramantyo/anaconda2/envs/tensorflow/lib/python2.7/site-packages/keras/models.py", line 965, in fit
      validation_steps=validation_steps)
  File "/Users/rifkibramantyo/anaconda2/envs/tensorflow/lib/python2.7/site-packages/keras/engine/training.py", line 1669, in fit
      validation_steps=validation_steps)
  File "/Users/rifkibramantyo/anaconda2/envs/tensorflow/lib/python2.7/site-packages/keras/engine/training.py", line 1226, in _fit_loop
      callbacks.on_epoch_end(epoch, epoch_logs)
  File "/Users/rifkibramantyo/anaconda2/envs/tensorflow/lib/python2.7/site-packages/keras/callbacks.py", line 76, in on_epoch_end
      callback.on_epoch_end(epoch, logs)
  File "/Users/rifkibramantyo/anaconda2/envs/tensorflow/lib/python2.7/site-packages/keras/callbacks.py", line 786, in on_epoch_end
      result = self.sess.run([self.merged], feed_dict=feed_dict)
  File "/Users/rifkibramantyo/anaconda2/envs/tensorflow/lib/python2.7/site-packages/tensorflow/python/client/session.py", line 767, in run
      run_metadata_ptr)
  File "/Users/rifkibramantyo/anaconda2/envs/tensorflow/lib/python2.7/site-packages/tensorflow/python/client/session.py", line 965, in _run
      feed_dict_string, options, run_metadata)
  File "/Users/rifkibramantyo/anaconda2/envs/tensorflow/lib/python2.7/site-packages/tensorflow/python/client/session.py", line 1015, in _do_run
      target_list, options, run_metadata)
  File "/Users/rifkibramantyo/anaconda2/envs/tensorflow/lib/python2.7/site-packages/tensorflow/python/client/session.py", line 1035, in _do_call
      raise type(e)(node_def, op, message)
  tensorflow.python.framework.errors_impl.InvalidArgumentError: You must feed a value for placeholder tensor 'conv2d_1_input' with dtype float
       [[Node: conv2d_1_input = Placeholder[dtype=DT_FLOAT, shape=[], _device="/job:localhost/replica:0/task:0/cpu:0"]()]]
  
  Caused by op u'conv2d_1_input', defined at:
    File "main.py", line 92, in &lt;module&gt;
      train(image_data, label_data, conv_arch, dense, dropout, epochs, batch_size, validation_split, patience)
    File "main.py", line 25, in train
      model = create_model(image_data, label_data, conv_arch=conv_arch, dense=dense, dropout=dropout)
    File "/Users/rifkibramantyo/tensorflow/variance/src/deepCNN.py", line 22, in create_model
      model.add(Conv2D(conv_arch[0][0], kernel_size=(3, 3), strides=3, padding='same', activation='relu', data_format='channels_first', input_shape=(1, image_data_train.shape[2], image_data_train.shape[3])))
    File "/Users/rifkibramantyo/anaconda2/envs/tensorflow/lib/python2.7/site-packages/keras/models.py", line 463, in add
      name=layer.name + '_input')
    File "/Users/rifkibramantyo/anaconda2/envs/tensorflow/lib/python2.7/site-packages/keras/engine/topology.py", line 1455, in Input
      input_tensor=tensor)
    File "/Users/rifkibramantyo/anaconda2/envs/tensorflow/lib/python2.7/site-packages/keras/legacy/interfaces.py", line 91, in wrapper
      return func(*args, **kwargs)
    File "/Users/rifkibramantyo/anaconda2/envs/tensorflow/lib/python2.7/site-packages/keras/engine/topology.py", line 1364, in __init__
      name=self.name)
    File "/Users/rifkibramantyo/anaconda2/envs/tensorflow/lib/python2.7/site-packages/keras/backend/tensorflow_backend.py", line 504, in placeholder
      x = tf.placeholder(dtype, shape=shape, name=name)
    File "/Users/rifkibramantyo/anaconda2/envs/tensorflow/lib/python2.7/site-packages/tensorflow/python/ops/array_ops.py", line 1520, in placeholder
      name=name)
    File "/Users/rifkibramantyo/anaconda2/envs/tensorflow/lib/python2.7/site-packages/tensorflow/python/ops/gen_array_ops.py", line 2149, in _placeholder
      name=name)
    File "/Users/rifkibramantyo/anaconda2/envs/tensorflow/lib/python2.7/site-packages/tensorflow/python/framework/op_def_library.py", line 763, in apply_op
      op_def=op_def)
    File "/Users/rifkibramantyo/anaconda2/envs/tensorflow/lib/python2.7/site-packages/tensorflow/python/framework/ops.py", line 2395, in create_op
      original_op=self._default_original_op, op_def=op_def)
    File "/Users/rifkibramantyo/anaconda2/envs/tensorflow/lib/python2.7/site-packages/tensorflow/python/framework/ops.py", line 1264, in __init__
      self._traceback = _extract_stack()
  
  InvalidArgumentError (see above for traceback): You must feed a value for placeholder tensor 'conv2d_1_input' with dtype float
     [[Node: conv2d_1_input = Placeholder[dtype=DT_FLOAT, shape=[], _device="/job:localhost/replica:0/task:0/cpu:0"]()]] 
  </code></pre>
  </blockquote>
  
  <p>I tried to fiddle with the code and the error disappears when I remove the callback array on <code>main.py</code>? Did I format the callbacks wrong?</p>
  
  <p>Here's the source code</p>
  
  <p><strong>main.py</strong></p>
  
  <pre><code>from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  
  from datetime import datetime
  
  import numpy as np
  from keras.callbacks import EarlyStopping, TensorBoard
  from keras.utils import plot_model
  from keras import backend as K
  
  from deepCNN import *
  from log import *
  
  K.set_learning_phase(1)
  
  def load_test_data():
      image_data_fname = '../data/data_images_Training.npy'
      label_data_fname = '../data/data_labels_Training.npy'
      image_data = np.load(image_data_fname)
      label_data = np.load(label_data_fname)
      return image_data, label_data
  
  def train(image_data, label_data, conv_arch, dense, dropout, epochs, batch_size, validation_split, patience):
      model = create_model(image_data, label_data, conv_arch=conv_arch, dense=dense, dropout=dropout)
      plot_model(model, to_file="graph.png")
      # define callbacks
      callbacks = []
      if patience != 0:
          early_stopping = EarlyStopping(monitor='val_loss', patience=patience, verbose=1)
          tensor_board = TensorBoard(log_dir='../logs', histogram_freq=1, write_graph=True, write_grads=False, write_images=False, embeddings_freq=0, embeddings_layer_names=None, embeddings_metadata=None)
          callbacks.append(early_stopping)
          callbacks.append(tensor_board)
  
      start_time = datetime.now()
      print('Training....\n')
  
      hist = model.fit(image_data, label_data, epochs=epochs, batch_size=batch_size, validation_split=validation_split, callbacks=callbacks, shuffle=True, verbose=1)
      end_time = datetime.now()
  
      # model result:
      train_val_accuracy = hist.history
      train_acc = train_val_accuracy['acc']
      val_acc = train_val_accuracy['val_acc']
      print('          Done!')
      print('     Train acc: ', train_acc[-1])
      print('Validation acc: ', val_acc[-1])
      print(' Overfit ratio: ', val_acc[-1] / train_acc[-1])
  
      my_log(model, start_time, end_time,
             batch_size=batch_size,
             epochs=epochs,
             conv_arch=conv_arch,
             dense=dense,
             dropout=dropout,
             image_data_shape=image_data.shape,
             train_acc=train_acc,
             val_acc=val_acc,
             dirpath=result_location)
  
  
  if __name__ == '__main__':
      image_data, label_data = load_test_data()
  
      result_location = '../data/results/'
  
      arr_conv_arch = [[(32, 1), (64, 0), (128, 0)],
                       [(32, 0), (64, 1), (128, 0)],
                       [(32, 0), (64, 0), (128, 1)],
                       [(32, 2), (64, 0), (128, 0)],
                       [(32, 3), (64, 0), (128, 0)],
                       [(32, 1), (64, 1), (128, 1)],
                       [(32, 2), (64, 2), (128, 1)],
                       [(32, 3), (64, 2), (128, 1)],
                       [(32, 3), (64, 3), (128, 3)]]
      arr_dense = [[64, 2], (256,2),(256,4),(512,2),(512,4)]
      arr_dropouts = [0.2, 0.3, 0.4, 0.5]
      arr_epochs = [1, 10, 40]
      arr_batch_size = [50, 256]
      validation_split = 0.2
      patience = 5
  
      #train(image_data, label_data, arr_conv_arch[8], arr_dense[0], arr_dropouts[0], 1, arr_batch_size[0], validation_split, patience)
      #train(image_data, label_data, arr_conv_arch[1], arr_dense[1], arr_dropouts[0], arr_epochs[0], arr_batch_size[0], validation_split, patience)
  
      for conv_arch in arr_conv_arch:
              for dense in arr_dense:
                  for dropout in arr_dropouts:
                      for epochs in arr_epochs:
                          for batch_size in arr_batch_size:
                              print_architecture(image_data.shape, label_data.shape, batch_size, dropout, epochs, conv_arch, dense)
                              train(image_data, label_data, conv_arch, dense, dropout, epochs, batch_size, validation_split, patience)
  </code></pre>
  
  <p><strong>deepCNN.py</strong></p>
  
  <pre><code>from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  
  import os
  
  # disable some warnings
  os.environ['TF_CPP_MIN_LOG_LEVEL'] = '2'
  
  from keras.layers import Conv2D, MaxPooling2D
  from keras.layers import Dropout, Flatten, Dense
  from keras.models import Sequential
  from keras.layers.core import K
  
  K.set_learning_phase(1)
  
  def create_model(image_data_train, label_data_train, conv_arch=[(32, 1)], dense=[32, 1], dropout=0.5):
      image_data_train = image_data_train.astype('float32')
  
      # Define model:
      model = Sequential()
      model.add(Conv2D(conv_arch[0][0], kernel_size=(3, 3), strides=3, padding='same', activation='relu', data_format='channels_first', input_shape=(1, image_data_train.shape[2], image_data_train.shape[3])))
  
      if (conv_arch[0][1] - 1) != 0:
          for i in range(conv_arch[0][1] - 1):
              model.add(Conv2D(conv_arch[0][0], kernel_size=(3, 3), strides=1, padding='same', activation='relu'))
          model.add(MaxPooling2D(pool_size=2))
  
      if conv_arch[1][1] != 0:
          for i in range(conv_arch[1][1]):
              model.add(Conv2D(conv_arch[1][0], kernel_size=(3, 3), strides=1, padding='same', activation='relu'))
          model.add(MaxPooling2D(pool_size=2))
  
      if conv_arch[2][1] != 0:
          for i in range(conv_arch[2][1]):
              model.add(Conv2D(conv_arch[2][0], kernel_size=(3, 3), strides=1, padding='same', activation='relu'))
          model.add(MaxPooling2D(pool_size=2))
  
      # Print data shape through network for debugging
      for z in range(len(model.layers)):
          print("{} : {} --&gt; {}".format(z, model.layers[z].input_shape, model.layers[z].output_shape))
  
      model.add(Flatten())  # this converts 3D feature maps to 1D feature vectors
  
      if dense[1] != 0:
          for i in range(dense[1]):
              model.add(Dense(dense[0], activation='relu'))
              if dropout:
                  model.add(Dropout(dropout))
  
      prediction = model.add(Dense(label_data_train.shape[1], activation='softmax'))
  
      # optimizer:
      model.compile(loss='categorical_crossentropy', optimizer='adam', metrics=['accuracy'])
  
      return model
  </code></pre>
  
  <p><strong>log.py</strong></p>
  
  <pre><code>import os
  
  import pandas as pd
  
  
  def print_architecture(image_data_shape, label_data_shape, batch_size, dropout, epochs, conv_arch, dense):
      print(' image data shape: ', image_data_shape)  # (n_sample, 1, 48, 48)
      print(' label data shape: ', label_data_shape)  # (n_sample, n_categories)
      print('      img size: ', image_data_shape[2], image_data_shape[3])
      print('    batch size: ', batch_size)
      print('        epochs: ', epochs)
      print('       dropout: ', dropout)
      print('conv architect: ', conv_arch)
      print('neural network: ', dense)
  
  
  def time_difference(start, end):
      return '{}_min_{}_sec'.format(end.time().minute - start.time().minute,
                                    end.time().second - start.time().second)
  
  
  def save_config(formatted_val_acc, start_time, config, dirpath='../data/results/'):
      with open(dirpath + formatted_val_acc + '-' + 'config_log.txt', 'a') as f:
          f.write(start_time.isoformat() + '\n')
          f.write(str(config) + '\n')
  
  
  def save_model(formatted_val_acc, start_time, json_string, dirpath='../data/results/'):
      with open(dirpath + formatted_val_acc + '-' + start_time.isoformat() + '_model.txt', 'w') as f:
          f.write(json_string)
  
  
  def save_result(start_time, end_time, train_acc, val_acc, conv_arch, batch_size, epochs, dense, dropout, dirpath='../data/results/'):
      with open(dirpath + 'result_log.txt', 'a') as f:
          f.write(start_time.isoformat() + ' -&gt; ' + end_time.isoformat() + '\n')
          f.write('  batch size: ' + str(batch_size) +
                  '\n    epochs: ' + str(epochs) +
                  '\n   dropout: ' + str(dropout) +
                  '\n      conv: ' + str(conv_arch) +
                  '\n     dense: ' + str(dense) +
                  '\n  - Train acc: ' + str(train_acc[-1]) +
                  '\n  - Val acc: ' + str(val_acc[-1]) +
                  '\n  - Ratio: ' + str(val_acc[-1] / train_acc[-1]) + '\n\n')
  
  
  # def append_to_result_log(text):
  #     with open('../data/results/result_log.txt', 'a') as f:
  #         f.write('\n' + text + '\n')
  
  
  def my_log(model, start_time, end_time, batch_size, epochs, conv_arch, dense, dropout, image_data_shape, train_acc, val_acc, dirpath):
      if (val_acc[-1] &gt; 0.5):
          formatted_val_acc = "{:.4f}".format(val_acc[-1])
          model.save_weights('../data/weights/{}-{}'.format(formatted_val_acc, start_time))
          save_model(formatted_val_acc, start_time, model.to_json(), dirpath)
          save_config(formatted_val_acc, start_time, model.get_config(), dirpath)
      save_result(start_time, end_time, train_acc, val_acc, conv_arch, batch_size, epochs, dense, dropout, dirpath)
      save_as_csv(start_time, end_time, train_acc, val_acc, conv_arch, batch_size, epochs, dense, dropout, image_data_shape, dirpath)
  
  
  def save_as_csv(start_time, end_time, train_acc, val_acc, conv_arch, batch_size, epochs, dense, dropout, image_data_shape, dirpath):
      data = {
          'start_time': start_time,
          'end_time': end_time,
          'duration': time_difference(start_time, end_time),
          'batch_size': batch_size,
          'epochs': epochs,
          'conv_arch': conv_arch,
          'dense': dense,
          'dropout': dropout,
          'image_width': image_data_shape[2],
          'image_height': image_data_shape[3],
          'train_acc': train_acc,
          'val_acc': val_acc
      }
      df = pd.DataFrame(dict([(k, pd.Series(v)) for k, v in data.iteritems()]))
  
      filepath = dirpath + 'results.csv'
      if not os.path.isfile(filepath):
          df.to_csv(filepath, index=False, sep='#', escapechar='^', header='column_names')
      else:  # else it exists so append without writing the header
          df.to_csv(filepath, index=False, sep='#', escapechar='^', mode='a', header=False)
  </code></pre>