title: mixed action loss (custom) function in TensorFlow gives nan (NaN) at training
body: <p>I am testing <strong>custom</strong> losses that combine classification and regression (YOLO's loss for example).
  alas, TensorFlow gives nan (NaN) at training...
  I've tried people's advice from here and anywhere but still, no fix.</p>
  
  <p>here is my code:</p>
  
  <pre><code>def S_loss(y_true, y_pred):
      Gnoobj = 0.5
      Gcoord = 5.
      mask = y_pred[..., 0] &gt; 0
      w_pred = tf.boolean_mask(y_pred[..., 1], mask)
      w_true = tf.boolean_mask(y_true[..., 1], mask)
      h_pred = tf.boolean_mask(y_pred[..., 2], mask)
      h_true = tf.boolean_mask(y_true[..., 2], mask)
      wmse = mean_squared_error(w_true, w_pred)
      hmse = mean_squared_error(h_true, h_pred)
      mse = wmse + hmse
      binary = binary_crossentropy(y_true[..., 0], y_pred[..., 0])
      return Gcoord * mse + Gnoobj * binary
  </code></pre>
  
  <p>thanks for any help!</p>