Region Proposal Network¶
-
class
faster_rcnn.faster_rcnn.
RPN
[source]¶ Generate region proposals, shares computation with the object detection network.
-
anchor_scales
¶ list – The scale of each anchor on particular point on feature maps.
-
anchor_target_layer
¶ faster_rcnn.rpn_msr.anchor_target_layer.AnchorTargerLayer
– Calculate network target base on anchors and ground truth boxes.
-
bbox_conv
¶ torch.nn.module
– Proposals coordinate refine predictor
-
conv1
¶ torch.nn.module
– Probability that anchors contains object predictor
-
cross_entropy
¶ int – Cross entropy loss.
-
features
¶ torch.nn.module
– Backbone network, that share computation with object detection network
-
loss_box
¶ int – Box coordinate refine loss.
-
proposal_layer
¶ faster_rcnn.rpn_msr.proposal_layer.ProposalLayer
– Create proposals base on generated anchors and bbox refine values.
-
score_conv
¶ TYPE – Description
-
_computer_forward
(im_data)[source]¶ Calculate forward
Parameters: im_data ( torch.tensor
) – image as tensorReturns: Return feature map, proposal boxes refine values w.r.t to each anchors, probability that anchors is foreground Return type: ( torch.tensor
,torch.tensor
,torch.tensor
)
-
forward
(im_data, im_info, gt_boxes=None, gt_boxes_index=[])[source]¶ Forward
Parameters: - im_data (TYPE) – Description
- im_info (TYPE) – Description
- gt_boxes (None, optional) – Description
- gt_boxes_index (list, optional) – Description
Returns: Return the features map and list of rois.
Return type: tuple(features, rois)
-
AnchorTargerLayer¶
-
class
faster_rcnn.rpn_msr.anchor_target_layer.
AnchorTargerLayer
(feat_stride, anchor_scales, is_cuda=True)[source]¶ Calculate target for RPN network
-
is_cuda
¶ bool – Using GPU or not
-
__init__
(feat_stride, anchor_scales, is_cuda=True)[source]¶ Summary
Parameters: - feat_stride (class::numpy.array) –
The Ratio between original image size and the convolutional feature (feature maps), Used to calculate anchors from a point in convolutional feature into the original image.
Example: np.array([16. ,])
- anchor_scales (class::numpy.array) – Description
- is_cuda (bool, optional) – Description
- feat_stride (class::numpy.array) –
-
_create_anchors
(feature_height, feature_width)[source]¶ Create all anchors given features height, width.
Parameters: - feature_height (int) – feature map height
- feature_width (int) – feature map width
Returns: Anchors
Return type: numpy.array
-
_filter_outside_anchors
(all_anchors, im_height, im_width)[source]¶ Remove outside anchors from generated anchors
Parameters: - all_anchors (
numpy.array
) – All generated anchors - im_height (int) – Origin image height.
- im_width (int) – Origin image width
Returns: Return all inside anchors and its indexes
Return type: tuple(inside_anchors, index_of_inside_anchors)
- all_anchors (
-
calculate_target
(inside_anchors, batch_size, inside_anchor_indexes, batch_boxes, batch_boxes_index)[source]¶ Calculate bbox_targets and layer
Notes
Create empty label array.- label:>>> label.shape (A, batch_size)
For each batch, there are A anchors and G batch boxes:current_batch_overlaps: overlaps between anchors and boxes>>> current_batch_overlaps.shape (A, G)
argmax_overlaps : List index of boxes, that have largest overlap w.r.t each Anchor.>>> argmax_overlaps.shape (A, 1)
max_overlaps : List of largest overlap values between boxes w.r.t each Anchor.>>> max_overlaps.shape (A, 1)
Set current batch label values:>>> labels[i, max_overlaps < cfg.TRAIN.RPN_NEGATIVE_OVERLAP] = 0 >>> labels[i, max_overlaps >= cfg.TRAIN.RPN_POSITIVE_OVERLAP] = 1
Parameters: - inside_anchors (
numpy.array
) – List all anchors that lay inside the original images. Shape: [number_of_anchor * 4] - batch_size (int) – Current batch size
- inside_anchor_indexes (
numpy.array
) – Indexes of inside anchors. Shape: [number_of_anchor * 1] - batch_boxes (
numpy.array
) –list all ground truth boxes across all the images in batch example:
>>> batch_boxes [[ 48.57142857 465.71428571 537.14285714 1774.28571429] [ 220. 1065.71428571 382.85714286 1771.42857143] [ 326.76056338 315.49295775 394.36619718 580.28169014] [ 76.05633803 290.14084507 242.25352113 788.73239437] [ 11.26760563 8.45070423 585.91549296 1769.01408451] [ 178.125 221.875 287.5 975. ] [ 321.875 334.375 434.375 984.375 ]]
- batch_boxes_index (list[Int]) – Batch index where image belong to.Example:There 3 images in current batch, and 6 boxes inside that 3 images. Look at the batch_boxes_index we know:First 3 boxes belong to first image.Next 2 boxes belong to second image.Last box belong to last image.
>>> [0, 0, 0, 1, 1, 2]
Returns: Return caculated labels , and bbox_targers
Return type: (
numpy.array((A, batch_size))
,numpy.array((batch_size, A, 4))
)- inside_anchors (
-
forward
(rpn_cls_score, gt_boxes, batch_boxes_index, im_info)[source]¶ Generate all anchors, then filter anchors that lays outside original images. Calculate target base on overlaps values and bbox regression.
Parameters: - rpn_cls_score (
torch.Tensor
) – The probability of each anchor contains object center - gt_boxes (
numpy.array
) – List all ground truth boxes across all the images in batch - batch_boxes_index (
numpy.array
) – Batch index where image belong to. - im_info (
torch.Tensor([[im_height, im_width]])
) – Original Image size
Returns: Return labels, bbox_targets, bbox_inside_weights, bbox_outside_weights
Return type: (
torch.Tensor
,torch.Tensor
,torch.Tensor
,torch.Tensor
)- rpn_cls_score (
-
ProposalLayer¶
-
class
faster_rcnn.rpn_msr.proposal_layer.
ProposalLayer
(_feat_stride=[16], anchor_scales=[8, 16, 32])[source]¶ -
__init__
(_feat_stride=[16], anchor_scales=[8, 16, 32])[source]¶ x.__init__(…) initializes x; see help(type(x)) for signature
-
forward
(scores, bbox_deltas, im_info, cfg_key)[source]¶ Summary
Notes
for each (H, W) location igenerate A anchor boxes centered on cell iapply predicted bbox deltas at cell i to each of the A anchorsclip predicted boxes to imageremove predicted boxes with either height or width < thresholdsort all (proposal, score) pairs by score from highest to lowesttake top pre_nms_topN proposals before NMSapply NMS with threshold 0.7 to remaining proposalstake after_nms_topN proposals after NMSreturn the top proposals (-> RoIs top, scores top)Parameters: - scores (TYPE) – Description
- bbox_deltas (TYPE) – Description
- im_info (TYPE) – Description
- cfg_key (TYPE) – Description
Returns: Description
Return type: TYPE
-