Geting batch size in keras custom loss
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?