MCPcopy
hub / github.com/hustvl/Vim / get_ground_truth

Method get_ground_truth

det/projects/TensorMask/tensormask/arch.py:503–631  ·  view source on GitHub ↗

Args: anchors (list[list[Boxes]]): a list of N=#image elements. Each is a list of #feature level Boxes. The Boxes contains anchors of this image on the specific feature level. unit_lengths (list[list[Tensor]]): a list of N=#image eleme

(self, anchors, unit_lengths, indexes, targets)

Source from the content-addressed store, hash-verified

501
502 @torch.no_grad()
503 def get_ground_truth(self, anchors, unit_lengths, indexes, targets):
504 """
505 Args:
506 anchors (list[list[Boxes]]): a list of N=#image elements. Each is a
507 list of #feature level Boxes. The Boxes contains anchors of
508 this image on the specific feature level.
509 unit_lengths (list[list[Tensor]]): a list of N=#image elements. Each is a
510 list of #feature level Tensor. The tensor contains unit lengths for anchors of
511 this image on the specific feature level.
512 indexes (list[list[Tensor]]): a list of N=#image elements. Each is a
513 list of #feature level Tensor. The tensor contains the 5D index of
514 each anchor, the second dimension means (L, N, H, W, A), where L
515 is level, I is image, H is height, W is width, and A is anchor.
516 targets (list[Instances]): a list of N `Instances`s. The i-th
517 `Instances` contains the ground-truth per-instance annotations
518 for the i-th input image. Specify `targets` during training only.
519
520 Returns:
521 gt_class_info (Tensor, Tensor): A pair of two tensors for classification.
522 The first one is an integer tensor of shape (R, #classes) storing ground-truth
523 labels for each anchor. R is the total number of anchors in the batch.
524 The second one is an integer tensor of shape (R,), to indicate which
525 anchors are valid for loss computation, which anchors are not.
526 gt_delta_info (Tensor, Tensor): A pair of two tensors for boxes.
527 The first one, of shape (F, 4). F=#foreground anchors.
528 The last dimension represents ground-truth box2box transform
529 targets (dx, dy, dw, dh) that map each anchor to its matched ground-truth box.
530 Only foreground anchors have values in this tensor. Could be `None` if F=0.
531 The second one, of shape (R,), is an integer tensor indicating which anchors
532 are foreground ones used for box regression. Could be `None` if F=0.
533 gt_mask_info (list[list[Tensor]], list[list[Tensor]]): A pair of two lists for masks.
534 The first one is a list of P=#feature level elements. Each is a
535 list of A=#anchor tensors. Each tensor contains the ground truth
536 masks of the same size and for the same feature level. Could be `None`.
537 The second one is a list of P=#feature level elements. Each is a
538 list of A=#anchor tensors. Each tensor contains the location of the ground truth
539 masks of the same size and for the same feature level. The second dimension means
540 (N, H, W), where N is image, H is height, and W is width. Could be `None`.
541 num_fg (int): F=#foreground anchors, used later for loss normalization.
542 """
543 gt_classes = []
544 gt_deltas = []
545 gt_masks = [[[] for _ in range(self.num_anchors)] for _ in range(self.num_levels)]
546 gt_mask_inds = [[[] for _ in range(self.num_anchors)] for _ in range(self.num_levels)]
547
548 anchors = [Boxes.cat(anchors_i) for anchors_i in anchors]
549 unit_lengths = [cat(unit_lengths_i) for unit_lengths_i in unit_lengths]
550 indexes = [cat(indexes_i) for indexes_i in indexes]
551
552 num_fg = 0
553 for i, (anchors_im, unit_lengths_im, indexes_im, targets_im) in enumerate(
554 zip(anchors, unit_lengths, indexes, targets)
555 ):
556 # Initialize all
557 gt_classes_i = torch.full_like(
558 unit_lengths_im, self.num_classes, dtype=torch.int64, device=self.device
559 )
560 # Ground truth classes

Callers 1

forwardMethod · 0.95

Calls 5

catFunction · 0.90
_assignment_ruleFunction · 0.85
catMethod · 0.45
get_deltasMethod · 0.45
crop_and_resizeMethod · 0.45

Tested by

no test coverage detected