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.
Per DQN Loss¶
- pl_bolts.losses.rl.per_dqn_loss(batch, batch_weights, net, target_net, gamma=0.99)[source]
Calculates the mse loss with the priority weights of the batch from the PER buffer.
- Parameters
- Return type
- Returns
loss and batch_weights