I'm trying to implement DILATE loss function (https://github.com/vincent-leguen/DILATE) developed for PyTorch into a keras framework as custom loss function.
At the moment this is my code:
def my_loss_fn(y_true, y_pred):
y_true = y_true.numpy().reshape(-1, np.multiply(*y_true.shape[1:]), 1)
y_pred = y_pred.numpy().reshape(-1, np.multiply(*y_pred.shape[1:]), 1)
print(y_true.shape)
print(y_pred.shape)
targets = torch.from_numpy(y_true)
outputs = torch.from_numpy(y_pred)
from loss.dilate_loss import dilate_loss
alpha = 1.01
gamma = 1.01
device = 'cpu'
aaa = dilate_loss(targets,outputs,alpha, gamma, device)[0].numpy()
print(aaa)
dlt_loss = tf.cast(dilate_loss(targets,outputs,alpha, gamma, device)[0], tf.float32)
dlt = tf.cast(dlt_loss, tf.float32)
return dlt_loss
It calculates the value of the loss but I have error saying:
No gradients provided for any variable
How can I solve? Thanks