title: Using a `tf.Tensor` as a Python `bool` is not allowed in Graph execution - when I do not use it as a bool
body: <p>That is the issue I am getting, but I don't use it as a bool anywhere. Or at least not where I can find. I have read similar questions, they were resolved because there was in fact an instance where it is being treated as a bool. However, I have not used it si a bool.</p>
  <p>Functions:</p>
  <pre><code>def compile_cnn(model, loss = None, optimizer = None):
  
      # Compile the CNN using the specified loss function
      model.compile(loss=loss, optimizer=optimizer)
  
      # return the compiled model
      return model
  </code></pre>
  <p>Custom Keras Loss functions:</p>
  <pre><code>def contrastive_loss(label, embedding, margin = 0.4):
  
      # Assign the label
      y = label
  
      # Assign the embeddings
      p1 = embedding[0]
      p2 = embedding[1]
  
      # Get the euclean distance    
      d = tf.norm(p1 - p2, axis=-1)
  
      if y == 0:
          return (1/2) * math.sqrt(d)
      else:
          return (1/2) * math.sqrt(max(0, (margin-d)))
  </code></pre>
  <p>Calling Code:</p>
  <pre><code># We use Adam as optimizer
  optimizer = keras.optimizers.Adam() 
  
  # Compile the model with the contrastive loss function
  cont_loss_model = compile_cnn(model, contrastive_loss, optimizer)
  </code></pre>
  <p>Here is the full error message as requested.</p>
  <pre><code> C:\Users\User\anaconda3\lib\site-packages\tensorflow\python\keras\engine\training.py:806 train_function  *
          return step_function(self, iterator)
      C:\Users\User\Documents\Uni\2020\IFN680\Assignment 2\SiameseNetwork.py:88 contrastive_loss  *
          return (1/2) * tf.math.sqrt(max(0, (margin-d)))
      C:\Users\User\anaconda3\lib\site-packages\tensorflow\python\framework\ops.py:877 __bool__  **
          self._disallow_bool_casting()
      C:\Users\User\anaconda3\lib\site-packages\tensorflow\python\framework\ops.py:486 _disallow_bool_casting
          self._disallow_when_autograph_enabled(
      C:\Users\User\anaconda3\lib\site-packages\tensorflow\python\framework\ops.py:472 _disallow_when_autograph_enabled
          raise errors.OperatorNotAllowedInGraphError(
  
      OperatorNotAllowedInGraphError: using a `tf.Tensor` as a Python `bool` is not allowed: AutoGraph did convert this function. This might indicate you are trying to use an unsupported feature.
  
  enter code here
  </code></pre>
  <p>enter code here</p>