I have created an autoencoder model with a dataset having 5 features.
From these features, the first 3 are numerical and the last 2 binary categorical. What I would like to do is create a custom loss function that takes into account both these types of data. What I have tried:
def custom_loss(y_true, y_pred):
return tf.math.add(
tf.keras.metrics.mean_squared_error(y_true[:,0:3], y_pred[:,0:3]) +
tf.keras.metrics.BinaryCrossentropy(y_true[:,3:5], y_pred[:,3:5])
)
However, this gets me this error:
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.
this also does not work without tf.math.add().
The custom loss is given here:
autoencoder.compile(optimizer='adam', loss = custom_loss)
How could this be implemented?