Losses¶
This package lists common losses across research domains (This is a work in progress. If you have any losses you want to contribute, please submit a PR!)
Note
this module is a work in progress
Your Loss¶
We’re cleaning up many of our losses, but in the meantime, submit a PR to add your loss here!
Object Detection¶
These are common losses used in object detection.
GIoU Loss¶

pl_bolts.losses.object_detection.
giou_loss
(preds, target)[source] Calculates the generalized intersection over union loss.
It has been proposed in Generalized Intersection over Union: A Metric and A Loss for Bounding Box Regression.
 Parameters
Example
>>> import torch >>> from pl_bolts.losses.object_detection import giou_loss >>> preds = torch.tensor([[100, 100, 200, 200]]) >>> target = torch.tensor([[150, 150, 250, 250]]) >>> giou_loss(preds, target) tensor([[1.0794]])
 Return type
 Returns
GIoU loss in an NxM tensor containing the pairwise GIoU loss for every element in preds and target, where N is the number of prediction bounding boxes and M is the number of target bounding boxes
IoU Loss¶

pl_bolts.losses.object_detection.
iou_loss
(preds, target)[source] Calculates the intersection over union loss.
 Parameters
Example
>>> import torch >>> from pl_bolts.losses.object_detection import iou_loss >>> preds = torch.tensor([[100, 100, 200, 200]]) >>> target = torch.tensor([[150, 150, 250, 250]]) >>> iou_loss(preds, target) tensor([[0.8571]])
 Return type
 Returns
IoU loss
Reinforcement Learning¶
These are common losses used in RL.
DQN Loss¶

pl_bolts.losses.rl.
dqn_loss
(batch, net, target_net, gamma=0.99)[source] Calculates the mse loss using a mini batch from the replay buffer
Double DQN Loss¶

pl_bolts.losses.rl.
double_dqn_loss
(batch, net, target_net, gamma=0.99)[source] Calculates the mse loss using a mini batch from the replay buffer. This uses an improvement to the original DQN loss by using the double dqn. This is shown by using the actions of the train network to pick the value from the target network. This code is heavily commented in order to explain the process clearly