Keras custom loss function returns Value Error

  keras, python, tensorflow

Hello I am using a custom loss function in google TFT model.

https://github.com/google-research/google-research/tree/master/tft

def custom_loss(y_actual,y_pred):
   
        tupl = np.shape(y_actual)
        flag = tf.compat.v1.math.is_nan(y_actual)
        y_actual = y_actual[tf.compat.v1.math.logical_not(flag)]
        y_pred = y_pred[tf.compat.v1.math.logical_not(flag)]
        tensordiff = tf.compat.v1.math.reduce_sum(tf.compat.v1.math.square(y_actual-y_pred))

        if len(tupl) >= 2:
          
          tensordiff /= tupl[0]
          
        if len(tupl) >= 3:
          
          tensordiff /= tupl[1]
         
        if len(tupl) >= 4:
         
          tensordiff /= tupl[2]
        
        return tensordiff

I am able to run the code and train the model with a standard loss functions but when I use my custom loss function I get

/usr/local/lib/python3.7/dist-packages/tensorflow/python/framework/tensor_util.py:445 make_tensor_proto
        raise ValueError("None values not supported.")

    ValueError: None values not supported.

Any ideas on how to fix this?

Source: Python Questions

LEAVE A COMMENT