Define losses for RPN and R-CNN
You are planning to train an object detection model that utilizes both the RPN and R-CNN components. To be able to train it, you will need to define the loss function for each component.
You remember that the RPN component classifies whether a region contains an object and predicts the bounding box coordinates for the proposed regions.The R-CNN component classifies the object into one of multiple classes while also predicting the final bounding box coordinates.
torch
, torch.nn
as nn
have been imported.
This exercise is part of the course
Deep Learning for Images with PyTorch
Exercise instructions
- Define the RPN classification loss function and assign it to
rpn_cls_criterion
. - Define the RPN regression loss function and assign it to
rpn_reg_criterion
. - Define the R-CNN classification loss function and assign it to
rcnn_cls_criterion
. - Define the R-CNN regression loss function using and assign it to
rcnn_reg_criterion
.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
# Implement the RPN classification loss function
rpn_cls_criterion = ____
# Implement the RPN regression loss function
rpn_reg_criterion = ____
# Implement the R-CNN classification Loss function
rcnn_cls_criterion = ____
# Implement the R-CNN regression loss function
rcnn_reg_criterion = ____