title: Keras model.fit() giving out TypeError: 'NoneType' object is not callable
body: <p>I am trying to experiment with Keras to implement Siamese Network to implement one-shot face recognition model. But I am running into an error incomprehensible to me, some help is requested.</p>
  <p>The model which I am using is an encoder model which takes in <code>(299,299,3)</code> images (anchor image, positive image as well as a negative image) and outputs the <code>1000</code> dimensional encoded vector of each image. This is similar to the InceptionV3 model with the classification head. I am also using a custom triplet loss function for the same. My model is as below:</p>
  <pre class="lang-py prettyprint-override"><code>class SiameseNet(tf.keras.layers.Layer):
  
    def __init__(self, model):
      self.model = model  # This is the image feature extraction model (similar to InceptionV3)
      super().__init__()
  
    def call(self, feat):
      feats = self.model(feat[0])
      nfeats = self.model(feat[1])
  
      return [feats, nfeats]
  </code></pre>
  <p>and the loss function is as below</p>
  <pre class="lang-py prettyprint-override"><code>def triplet_loss(y_true, y_pred, alpha=1e-2):
    return max(tf.reduce_sum((y_pred[0]-y_true)**2 - (y_pred[0]-y_pred[1])**2) + alpha, 0)
  </code></pre>
  <p>There are three arrays named <code>images</code> (anchor images) and <code>negatives</code> (negative images) both with shape <code>(500,299,299,3)</code> (where 500 is the number of training examples) and <code>positives</code> (positive image features) with shape <code>(500,1000)</code>. All these are numpy arrays.</p>
  <p>My model code is as shown below</p>
  <pre class="lang-py prettyprint-override"><code>image_input = tf.keras.layers.Input(shape=(299,299,3), name='image_input')
  negative_input = tf.keras.layers.Input(shape=(299,299,3), name='negative_input')
  
  siamese = SiameseNet(image_features_extract_model)([image_input, negative_input])
  
  model = tf.keras.Model(inputs=[image_input, negative_input], outputs=siamese)
  
  model.compile(optimizer=tf.keras.optimizers.Adam(), loss=triplet_loss, metrics=['accuracy'])
  </code></pre>
  <p>The compilation works fine with the output</p>
  <pre class="lang-py prettyprint-override"><code>Model: &quot;functional_3&quot;
  __________________________________________________________________________________________________
  Layer (type)                    Output Shape         Param #     Connected to                     
  ==================================================================================================
  image_input (InputLayer)        [(None, 299, 299, 3) 0                                            
  __________________________________________________________________________________________________
  negative_input (InputLayer)     [(None, 299, 299, 3) 0                                            
  __________________________________________________________________________________________________
  siamese_net (SiameseNet)        [(None, 1000), (None 23851784    image_input[0][0]                
                                                                   negative_input[0][0]             
  ==================================================================================================
  Total params: 23,851,784
  Trainable params: 23,817,352
  Non-trainable params: 34,432
  </code></pre>
  <p>but while running</p>
  <pre class="lang-py prettyprint-override"><code>model.fit([images, negatives], positives, epochs=10, batch_size=8, verbose=2)
  </code></pre>
  <p>I get the following error which I require help with</p>
  <pre class="lang-py prettyprint-override"><code>Epoch 1/10
  ---------------------------------------------------------------------------
  TypeError                                 Traceback (most recent call last)
  &lt;ipython-input-16-83443f79d005&gt; in &lt;module&gt;()
  ----&gt; 1 model.fit([images, negatives], positives, epochs=10, batch_size=8, verbose=2)
        2 # model.fit(train, epochs=10, verbose=2)
  
  3 frames
  /usr/local/lib/python3.6/dist-packages/tensorflow/python/keras/engine/training.py in _method_wrapper(self, *args, **kwargs)
      106   def _method_wrapper(self, *args, **kwargs):
      107     if not self._in_multi_worker_mode():  # pylint: disable=protected-access
  --&gt; 108       return method(self, *args, **kwargs)
      109 
      110     # Running inside `run_distribute_coordinator` already.
  
  /usr/local/lib/python3.6/dist-packages/tensorflow/python/keras/engine/training.py in fit(self, x, y, batch_size, epochs, verbose, callbacks, validation_split, validation_data, shuffle, class_weight, sample_weight, initial_epoch, steps_per_epoch, validation_steps, validation_batch_size, validation_freq, max_queue_size, workers, use_multiprocessing)
     1096                 batch_size=batch_size):
     1097               callbacks.on_train_batch_begin(step)
  -&gt; 1098               tmp_logs = train_function(iterator)
     1099               if data_handler.should_sync:
     1100                 context.async_wait()
  
  /usr/local/lib/python3.6/dist-packages/tensorflow/python/eager/def_function.py in __call__(self, *args, **kwds)
      778       else:
      779         compiler = &quot;nonXla&quot;
  --&gt; 780         result = self._call(*args, **kwds)
      781 
      782       new_tracing_count = self._get_tracing_count()
  
  /usr/local/lib/python3.6/dist-packages/tensorflow/python/eager/def_function.py in _call(self, *args, **kwds)
      805       # In this case we have created variables on the first call, so we run the
      806       # defunned version which is guaranteed to never create variables.
  --&gt; 807       return self._stateless_fn(*args, **kwds)  # pylint: disable=not-callable
      808     elif self._stateful_fn is not None:
      809       # Release the lock early so that multiple threads can perform the call
  
  TypeError: 'NoneType' object is not callable
  </code></pre>
  <p>I am running the code on Google Colab on a CPU.<br />
  Please help me out with this problem. Thanks.</p>