1
$\begingroup$

I am implementing a custom loss in keras, for example, a sum:

def custom_loss(y_true, y_pred):
    K.sum(y_true, y_pred)

Now, I want to normalize it by the batch size. Is it possible, to retrieve the batch size from y_true or y_pred?

$\endgroup$
2
$\begingroup$

I would say this highly depends on how you have your code set up. What type of model are you creating? Are you not setting batch-size as a global parameter? Can you not just use that? Also, assuming y_true is a numpy matrix, can you just use: y_true.shape[dimension_representing_batch_size] as a means of getting the size?

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.