def get_lr_metric(optimizer):
    """
    Function for returning the learning rate in the keras model.fit history, as if it were a metric.
    :param optimizer: a tensorflow optimizer instances
    :return: float32, the learning rate
    """

    def lr(y_true, y_pred):
        # return optimizer._decayed_lr(tf.float32)    # I use ._decayed_lr method instead of .lr
        return optimizer.lr

    return lr