def predict_boxes_for_gt_classes(self, predictions, proposals): """ Returns: list[Tensor]: A list of Tensors of predicted boxes for GT classes in case of class-specific box head. Element i of the list has shape (Ri, B), where Ri is the number of predicted objects for image i and B is the box dimension (4 or 5) """ if not len(proposals): return [] scores, proposal_deltas = predictions proposal_boxes = [p.proposal_boxes for p in proposals] proposal_boxes = proposal_boxes[0].cat(proposal_boxes).tensor N, B = proposal_boxes.shape predict_boxes = apply_deltas_broadcast( self.box2box_transform, proposal_deltas, proposal_boxes ) # Nx(KxB) K = predict_boxes.shape[1] // B if K > 1: gt_classes = torch.cat([p.gt_classes for p in proposals], dim=0) # Some proposals are ignored or have a background class. Their gt_classes # cannot be used as index. gt_classes = gt_classes.clamp_(0, K - 1) predict_boxes = predict_boxes.view(N, K, B)[ torch.arange(N, dtype=torch.long, device=predict_boxes.device), gt_classes ] num_prop_per_image = [len(p) for p in proposals] return predict_boxes.split(num_prop_per_image)
def _predict_boxes(self): """ Returns: Tensor: A Tensors of predicted class-specific or class-agnostic boxes for all images in a batch. Element i has shape (Ri, K * B) or (Ri, B), where Ri is the number of predicted objects for image i and B is the box dimension (4 or 5) """ return apply_deltas_broadcast( self.box2box_transform, self.pred_proposal_deltas, self.proposals.tensor )
def predict_boxes(self, proposal_deltas, proposals): """ Returns: list[Tensor]: A list of Tensors of predicted class-specific or class-agnostic boxes for each image. Element i has shape (Ri, K * B) or (Ri, B), where Ri is the number of predicted objects for image i and B is the box dimension (4 or 5) """ if not len(proposals): return [] num_prop_per_image = [len(p) for p in proposals] proposal_boxes = [p.proposal_boxes for p in proposals] proposal_boxes = proposal_boxes[0].cat(proposal_boxes).tensor predict_boxes = apply_deltas_broadcast(self.box2box_transform, proposal_deltas, proposal_boxes) # Nx(KxB) return predict_boxes.split(num_prop_per_image)