title: TypeError: Using a `tf.Tensor` as a Python `bool` is not allowed. when writing a custom metric function in keras
body: <p>Keras version: <code>2.2.4</code></p>
  
  <p>Tensorflow version: <code>1.14.0</code></p>
  
  <p>TypeError: Using a <code>tf.Tensor</code> as a Python <code>bool</code> is not allowed. Use <code>if t is not None:</code> instead of <code>if t:</code> to test if a tensor is defined, and use TensorFlow ops such as tf.cond to execute subgraphs conditioned on the value of a tensor.</p>
  
  <p>I am trying to write a custom metric function in Keras and couldn't get through because of the above error. Please find the below code blocks I am using.</p>
  
  <pre><code>def IOU(y_true, y_pred):
      intersections = 0
      unions = 0
      gt = y_true
      pred = y_pred
  
      # Compute interection of predicted (pred) and ground truth (gt) bounding boxes
      diff_width = np.minimum(gt[:,0] + gt[:,2], pred[:,0] + pred[:,2]) - np.maximum(gt[:,0], pred[:,0])
      diff_height = np.minimum(gt[:,1] + gt[:,3], pred[:,1] + pred[:,3]) - np.maximum(gt[:,1], pred[:,1])
      intersection = diff_width * diff_height
  
      # Compute union
      area_gt = gt[:,2] * gt[:,3]
      area_pred = pred[:,2] * pred[:,3]
      union = area_gt + area_pred - intersection
  
      # Compute intersection and union over multiple boxes
      for j, _ in enumerate(union):
        if union[j] &gt; 0 and intersection[j] &gt; 0 and union[j] &gt;= intersection[j]:
          intersections += intersection[j]
          unions += union[j]
  
      # Compute IOU. Use epsilon to prevent division by zero
      iou = np.round(intersections / (unions + epsilon()), 4)
      return iou
  
  model = create_model() 
  
  model.compile(loss="mean_squared_error", optimizer="adam", metrics=[IOU])
  
  model.fit(X_train,y_train, 
            validation_data=(X_val, y_val),
            epochs=EPOCHS,
            batch_size=32,
            verbose=1)
  </code></pre>
  
  <p>Please help me in writing a custom metric function in keras, by accessing <code>y_true</code> and <code>y_pred</code>. Thanks in advance.</p>