Custom loss functions - PyTorch Forums
discuss.pytorch.org › t › custom-loss-functionsJun 12, 2020 · Reading the docs and the forums, it seems that there are two ways to define a custom loss function: Extending Function and implementing forward and backward … Hello @ptrblck, I am using a custom contrastive loss function as def loss_contrastive(euclidean_distance, label_batch): margin = 100 loss = torch.mean( (label_batch) * torch.pow(euclidean_distance, 2) + (1-label_batch) * torch.pow(torch.clamp(margin - euclidean_distance, min=0.0), 2)) However, I get ...