Converting Tensor to np.array using K.eval() in Keras returns InvalidArgumentError

The loss function is compiled with the model. At compile time, y_true and y_pred are only placeholder tensors, so they do not have a value yet and can therefore not be evaluated. This is why you get the error message.

Your loss function should use Keras tensors, not the numpy arrays they evaluate to. If you need to use additional numpy arrays, convert them to tensors via the variable method of keras.backend (Keras Backend Documentation).

Edit:

You will still need to stay inside the Keras function space to make your loss work. If this is the concrete loss function that you want to implement, and assuming that your values are in {0,1}, you can try something like this:

import keras.backend as K

def custom_loss_function(y_true, y_pred):

    y_true = y_true*2 - K.ones_like(y_true) # re-codes values of y_true from {0,1} to {-1,+1}
    y_true = y_true*y_pred # makes the values that you are not interested in equal to zero
    classification_score = K.abs(K.sum(y_true))