from keras import backend as K

def my_loss(y_true, y_pred):
    return K.mean(K.square(y_pred - y_true), axis=-1)
model.compile(loss=my_loss, optimizer='SGD', metrics=['accuracy'])
средневзвешенное значение тензора