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?
Data Science Stack Exchange is a question and answer site for Data science professionals, Machine Learning specialists, and those interested in learning more about the field. It only takes a minute to sign up.Sign up to join this community
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?