I am trying to use Keras to implement the work done in A General and Adaptive Robust Loss Function. The author provides tensorflow code that works the hard details. I am just trying to use his prebuilt function in Keras.
His custom loss function is learning a parameter 'alpha' that controls the shape of the loss function. I would like to track 'alpha' in addition to the loss during training.
I am somewhat familiar with Keras custom loss functions and using wrappers, but I am not entirely sure how to use callbacks to track 'alpha'. Below is how I would choose to naively construct the loss function in Keras. However I am not sure how I would then access the 'alpha' to track.
From the provided tensorflow code, the function lossfun(x) returns a tuple.
def lossfun(x,
alpha_lo=0.001,
alpha_hi=1.999,
alpha_init=None,
scale_lo=1e-5,
scale_init=1.,
**kwargs):
"""
Returns:
A tuple of the form (`loss`, `alpha`, `scale`).
"""
def customAdaptiveLoss():
def wrappedloss(y_true,y_pred):
loss, alpha, scale = lossfun((y_true-y_pred)) #Author's function
return loss
return wrappedloss
Model.compile(optimizer = optimizers.Adam(0.001),
loss = customAdaptiveLoss,)
Again, what I am hoping to do is track the variable 'alpha' during training.