title: Tensorflow model with custom loss function gets no training done
body: <p>I created a custom loss function as below:</p>
  <pre><code>import tensorflow.keras.backend as K
  def custom_loss(y_true, y_pred):
      y_true = K.cast(y_true, tf.float32)
      y_pred = K.cast(y_pred, tf.float32)
  
      mask = K.sign(y_true) * K.sign(y_pred)
      mask = ((mask * -1) + 1) / 2
      losses = K.abs(y_true * mask)
  
      return K.sum(losses)
  </code></pre>
  <p>However, when I try to train the model using this loss function, I get no training done.
  The model works normally with other loss functions such as mse and mae, and I've tried all learning rates and model complexities.</p>
  <p>Below is how I know no training is being done.</p>
  <pre><code>model = get_compiled_model()
  print(model.predict(train_x)[:10])
  model.fit(train_x, train_y, epochs=5, verbose=1)
  print(model.predict(train_x)[:10])
  model.fit(train_x, train_y, epochs=5, verbose=1)
  print(model.predict(train_x)[:10])
  </code></pre>
  <pre><code>[[0.19206487]
   [0.19201839]
   [0.19199933]
   [0.19199185]
   [0.19206186]
   [0.19208357]
   [0.1920282 ]
   [0.19203594]
   [0.1919941 ]
   [0.19202243]]
  Epoch 1/5
  1/1 [==============================] - 0s 1ms/step - loss: 0.0179
  Epoch 2/5
  1/1 [==============================] - 0s 2ms/step - loss: 0.0179
  Epoch 3/5
  1/1 [==============================] - 0s 1ms/step - loss: 0.0179
  Epoch 4/5
  1/1 [==============================] - 0s 1ms/step - loss: 0.0179
  Epoch 5/5
  1/1 [==============================] - 0s 2ms/step - loss: 0.0179
  [[0.19206487]
   [0.19201839]
   [0.19199933]
   [0.19199185]
   [0.19206186]
   [0.19208357]
   [0.1920282 ]
   [0.19203594]
   [0.1919941 ]
   [0.19202243]]
  Epoch 1/5
  1/1 [==============================] - 0s 1ms/step - loss: 0.0179
  Epoch 2/5
  1/1 [==============================] - 0s 2ms/step - loss: 0.0179
  Epoch 3/5
  1/1 [==============================] - 0s 2ms/step - loss: 0.0179
  Epoch 4/5
  1/1 [==============================] - 0s 951us/step - loss: 0.0179
  Epoch 5/5
  1/1 [==============================] - 0s 1ms/step - loss: 0.0179
  [[0.19206487]
   [0.19201839]
   [0.19199933]
   [0.19199185]
   [0.19206186]
   [0.19208357]
   [0.1920282 ]
   [0.19203594]
   [0.1919941 ]
   [0.19202243]]
  </code></pre>
  <p>The 2d array in the code above is the first 10 predictions of the model, and it does not change in the slightest even with 5 epochs of training.</p>
  <p>My intuition tells me something is wrong with the loss function, but I have no idea what.</p>
  <p>The model looks like as follows</p>
  <pre><code>def get_compiled_model():
    model = tf.keras.Sequential([
      tf.keras.layers.Dense(10, input_dim=2*training_size+1, activation='softmax'),
      tf.keras.layers.Dense(10, activation='softmax'),
      tf.keras.layers.Dense(1, activation='tanh')
    ])
  
    opt = tf.keras.optimizers.Adam(learning_rate=0.0005)
    model.compile(optimizer=opt,
                  loss=custom_loss,
                  metrics=[])
    return model
  </code></pre>