def get_targets(self, sampling_results, gt_bboxes, gt_labels, rcnn_train_cfg, reference_labels, classes, concat=True):
    "Calculate the ground truth for all samples in a batch according to\n        the sampling_results.\n        Almost the same as the implementation in bbox_head, we passed\n        additional parameters pos_inds_list and neg_inds_list to\n        `_get_target_single` function.\n        Args:\n            sampling_results (List[obj:SamplingResults]): Assign results of\n                all images in a batch after sampling.\n            gt_bboxes (list[Tensor]): Gt_bboxes of all images in a batch,\n                each tensor has shape (num_gt, 4),  the last dimension 4\n                represents [tl_x, tl_y, br_x, br_y].\n            gt_labels (list[Tensor]): Gt_labels of all images in a batch,\n                each tensor has shape (num_gt,).\n            rcnn_train_cfg (obj:ConfigDict): `train_cfg` of RCNN.\n            concat (bool): Whether to concatenate the results of all\n                the images in a single batch.\n        Returns:\n            Tuple[Tensor]: Ground truth for proposals in a single image.\n            Containing the following list of Tensors:\n                - labels (list[Tensor],Tensor): Gt_labels for all\n                  proposals in a batch, each tensor in list has\n                  shape (num_proposals,) when `concat=False`, otherwise\n                  just a single tensor has shape (num_all_proposals,).\n                - label_weights (list[Tensor]): Labels_weights for\n                  all proposals in a batch, each tensor in list has\n                  shape (num_proposals,) when `concat=False`, otherwise\n                  just a single tensor has shape (num_all_proposals,).\n                - bbox_targets (list[Tensor],Tensor): Regression target\n                  for all proposals in a batch, each tensor in list\n                  has shape (num_proposals, 4) when `concat=False`,\n                  otherwise just a single tensor has shape\n                  (num_all_proposals, 4), the last dimension 4 represents\n                  [tl_x, tl_y, br_x, br_y].\n                - bbox_weights (list[tensor],Tensor): Regression weights for\n                  all proposals in a batch, each tensor in list has shape\n                  (num_proposals, 4) when `concat=False`, otherwise just a\n                  single tensor has shape (num_all_proposals, 4).\n                - dis_targets (list[tensor], Tensor): Gt_dis for all\n                  proposal in a batch, each tensor in list has\n                  shape (num_proposal,) when 'concat=False`, otherwise\n                  just a single tensor has shape (num_all_proposals,).\n        "
    pos_bboxes_list = [res.pos_bboxes for res in sampling_results]
    neg_bboxes_list = [res.neg_bboxes for res in sampling_results]
    pos_gt_bboxes_list = [res.pos_gt_bboxes for res in sampling_results]
    pos_gt_labels_list = [res.pos_gt_labels for res in sampling_results]
    (labels, label_weights, bbox_targets, bbox_weights) = multi_apply(self._get_target_single, pos_bboxes_list, neg_bboxes_list, pos_gt_bboxes_list, pos_gt_labels_list, cfg=rcnn_train_cfg)
    iou_calculator = dict(type='BboxOverlaps2D')
    iou_calculator = build_iou_calculator(iou_calculator)
    isolation_thr = 0.45
    dis_targets = []
    for (i, res) in enumerate(sampling_results):
        ref_grap_list = []
        ref_leav_list = []
        ref_grap_dis_list = []
        ref_leav_dis_list = []
        for (j, bbox) in enumerate(gt_bboxes[i]):
            if (self.dis_selector == 0):
                if (('grappolo' in classes[gt_labels[i][j]]) and (gt_labels[i][j] != reference_labels['grappolo_vite'])):
                    ref_grap_dis_list.append(bbox)
                elif ((('foglia' in classes[gt_labels[i][j]]) or (classes[gt_labels[i][j]] == 'malattia_esca') or (classes[gt_labels[i][j]] == 'virosi_pinot_grigio')) and (gt_labels[i][j] != reference_labels['foglia_vite'])):
                    ref_leav_dis_list.append(bbox)
            elif (self.dis_selector == 1):
                if (gt_labels[i][j] == reference_labels['grappolo_vite']):
                    ref_grap_list.append(bbox)
                elif (gt_labels[i][j] == reference_labels['foglia_vite']):
                    ref_leav_list.append(bbox)
            elif (self.dis_selector == 2):
                if (gt_labels[i][j] == reference_labels['grappolo_vite']):
                    ref_grap_list.append(bbox)
                elif (gt_labels[i][j] == reference_labels['foglia_vite']):
                    ref_leav_list.append(bbox)
                elif ('grappolo' in classes[gt_labels[i][j]]):
                    ref_grap_dis_list.append(bbox)
                elif (('foglia' in classes[gt_labels[i][j]]) or (classes[gt_labels[i][j]] == 'malattia_esca') or (classes[gt_labels[i][j]] == 'virosi_pinot_grigio')):
                    ref_leav_dis_list.append(bbox)
            "\n                if 'grappolo' in classes[gt_labels[i][j]] and gt_labels[i][j] != reference_labels['grappolo_vite']:\n                    ref_grap_dis_list.append(bbox)\n                elif (('foglia' in classes[gt_labels[i][j]] or classes[gt_labels[i][j]] == 'malattia_esca'                    or classes[gt_labels[i][j]] == 'virosi_pinot_grigio')\n                    and gt_labels[i][j] != reference_labels['foglia_vite']):\n                        ref_leav_dis_list.append(bbox)\n                "
        if (len(ref_grap_list) > 0):
            ref_grap_tensor = torch.cat(ref_grap_list)
            ref_grap_tensor = torch.reshape(ref_grap_tensor, (len(ref_grap_list), 4))
        if (len(ref_leav_list) > 0):
            ref_leav_tensor = torch.cat(ref_leav_list)
            ref_leav_tensor = torch.reshape(ref_leav_tensor, (len(ref_leav_list), 4))
        if (len(ref_grap_dis_list) > 0):
            ref_grap_dis_tensor = torch.cat(ref_grap_dis_list)
            ref_grap_dis_tensor = torch.reshape(ref_grap_dis_tensor, (len(ref_grap_dis_list), 4))
        if (len(ref_leav_dis_list) > 0):
            ref_leav_dis_tensor = torch.cat(ref_leav_dis_list)
            ref_leav_dis_tensor = torch.reshape(ref_leav_dis_tensor, (len(ref_leav_dis_list), 4))
        num_pos = res.pos_bboxes.size(0)
        num_neg = res.neg_bboxes.size(0)
        num_samples = (num_pos + num_neg)
        dis_tensor = res.pos_bboxes.new_full((num_samples,), (- 1), dtype=torch.long)
        dis_list = []
        for (j, bbox) in enumerate(res.pos_bboxes):
            bbox = bbox.unsqueeze(0)
            if (res.pos_gt_labels[j] == reference_labels['grappolo_vite']):
                if (self.dis_selector == 0):
                    dis_list.append((- 1))
                elif ((self.dis_selector == 1) or (self.dis_selector == 2)):
                    if (len(ref_grap_dis_list) > 0):
                        overlaps = iou_calculator(ref_grap_dis_tensor, bbox, mode='iof')
                        overlaps = (overlaps < isolation_thr)
                        if overlaps.all():
                            dis_list.append(0)
                        else:
                            dis_list.append(1)
                    else:
                        dis_list.append(0)
            elif (res.pos_gt_labels[j] == reference_labels['foglia_vite']):
                if (self.dis_selector == 0):
                    dis_list.append((- 1))
                elif ((self.dis_selector == 1) or (self.dis_selector == 2)):
                    if (len(ref_leav_dis_list) > 0):
                        overlaps = iou_calculator(ref_leav_dis_tensor, bbox, mode='iof')
                        overlaps = (overlaps < isolation_thr)
                        if overlaps.all():
                            dis_list.append(0)
                        else:
                            dis_list.append(1)
                    else:
                        dis_list.append(0)
            elif (('grappolo' in classes[res.pos_gt_labels[j]]) and (res.pos_gt_labels[j] != reference_labels['grappolo_vite'])):
                if (self.dis_selector == 1):
                    dis_list.append((- 1))
                elif (self.dis_selector == 0):
                    if (len(ref_grap_list) > 0):
                        overlaps = iou_calculator(bbox, ref_grap_tensor, mode='iof')
                        overlaps = (overlaps < isolation_thr)
                        if overlaps.all():
                            dis_list.append(0)
                        else:
                            dis_list.append(1)
                    else:
                        dis_list.append(0)
                elif (self.dis_selector == 2):
                    if (len(ref_grap_list) > 0):
                        overlaps = iou_calculator(bbox, ref_grap_tensor, mode='iof')
                        overlaps = (overlaps < isolation_thr)
                        if overlaps.all():
                            dis_list.append(2)
                        else:
                            dis_list.append(3)
                    else:
                        dis_list.append(2)
            elif ((('foglia' in classes[res.pos_gt_labels[j]]) or (classes[res.pos_gt_labels[j]] == 'malattia_esca') or (classes[res.pos_gt_labels[j]] == 'virosi_pinot_grigio')) and (res.pos_gt_labels[j] != reference_labels['foglia_vite'])):
                if (self.dis_selector == 1):
                    dis_list.append((- 1))
                elif (self.dis_selector == 0):
                    if (len(ref_leav_list) > 0):
                        overlaps = iou_calculator(bbox, ref_leav_tensor, mode='iof')
                        overlaps = (overlaps < isolation_thr)
                        if overlaps.all():
                            dis_list.append(0)
                        else:
                            dis_list.append(1)
                    else:
                        dis_list.append(0)
                elif (self.dis_selector == 2):
                    if (len(ref_leav_list) > 0):
                        overlaps = iou_calculator(bbox, ref_leav_tensor, mode='iof')
                        overlaps = (overlaps < isolation_thr)
                        if overlaps.all():
                            dis_list.append(2)
                        else:
                            dis_list.append(3)
                    else:
                        dis_list.append(2)
        dis_tensor[:num_pos] = torch.tensor(dis_list)
        dis_targets.append(dis_tensor)
    if concat:
        labels = torch.cat(labels, 0)
        label_weights = torch.cat(label_weights, 0)
        bbox_targets = torch.cat(bbox_targets, 0)
        bbox_weights = torch.cat(bbox_weights, 0)
        dis_targets = torch.cat(dis_targets, 0)
    return (labels, label_weights, bbox_targets, bbox_weights, dis_targets)
Calculate the ground truth for all samples in a batch according to
the sampling_results.
Almost the same as the implementation in bbox_head, we passed
additional parameters pos_inds_list and neg_inds_list to
`_get_target_single` function.
Args:
    sampling_results (List[obj:SamplingResults]): Assign results of
        all images in a batch after sampling.
    gt_bboxes (list[Tensor]): Gt_bboxes of all images in a batch,
        each tensor has shape (num_gt, 4),  the last dimension 4
        represents [tl_x, tl_y, br_x, br_y].
    gt_labels (list[Tensor]): Gt_labels of all images in a batch,
        each tensor has shape (num_gt,).
    rcnn_train_cfg (obj:ConfigDict): `train_cfg` of RCNN.
    concat (bool): Whether to concatenate the results of all
        the images in a single batch.
Returns:
    Tuple[Tensor]: Ground truth for proposals in a single image.
    Containing the following list of Tensors:
        - labels (list[Tensor],Tensor): Gt_labels for all
          proposals in a batch, each tensor in list has
          shape (num_proposals,) when `concat=False`, otherwise
          just a single tensor has shape (num_all_proposals,).
        - label_weights (list[Tensor]): Labels_weights for
          all proposals in a batch, each tensor in list has
          shape (num_proposals,) when `concat=False`, otherwise
          just a single tensor has shape (num_all_proposals,).
        - bbox_targets (list[Tensor],Tensor): Regression target
          for all proposals in a batch, each tensor in list
          has shape (num_proposals, 4) when `concat=False`,
          otherwise just a single tensor has shape
          (num_all_proposals, 4), the last dimension 4 represents
          [tl_x, tl_y, br_x, br_y].
        - bbox_weights (list[tensor],Tensor): Regression weights for
          all proposals in a batch, each tensor in list has shape
          (num_proposals, 4) when `concat=False`, otherwise just a
          single tensor has shape (num_all_proposals, 4).
        - dis_targets (list[tensor], Tensor): Gt_dis for all
          proposal in a batch, each tensor in list has
          shape (num_proposal,) when 'concat=False`, otherwise
          just a single tensor has shape (num_all_proposals,).
def get_targets(self, sampling_results, gt_bboxes, gt_labels, rcnn_train_cfg, reference_labels, classes, concat=True):
    "Calculate the ground truth for all samples in a batch according to\n        the sampling_results.\n        Almost the same as the implementation in bbox_head, we passed\n        additional parameters pos_inds_list and neg_inds_list to\n        `_get_target_single` function.\n        Args:\n            sampling_results (List[obj:SamplingResults]): Assign results of\n                all images in a batch after sampling.\n            gt_bboxes (list[Tensor]): Gt_bboxes of all images in a batch,\n                each tensor has shape (num_gt, 4),  the last dimension 4\n                represents [tl_x, tl_y, br_x, br_y].\n            gt_labels (list[Tensor]): Gt_labels of all images in a batch,\n                each tensor has shape (num_gt,).\n            rcnn_train_cfg (obj:ConfigDict): `train_cfg` of RCNN.\n            concat (bool): Whether to concatenate the results of all\n                the images in a single batch.\n        Returns:\n            Tuple[Tensor]: Ground truth for proposals in a single image.\n            Containing the following list of Tensors:\n                - labels (list[Tensor],Tensor): Gt_labels for all\n                  proposals in a batch, each tensor in list has\n                  shape (num_proposals,) when `concat=False`, otherwise\n                  just a single tensor has shape (num_all_proposals,).\n                - label_weights (list[Tensor]): Labels_weights for\n                  all proposals in a batch, each tensor in list has\n                  shape (num_proposals,) when `concat=False`, otherwise\n                  just a single tensor has shape (num_all_proposals,).\n                - bbox_targets (list[Tensor],Tensor): Regression target\n                  for all proposals in a batch, each tensor in list\n                  has shape (num_proposals, 4) when `concat=False`,\n                  otherwise just a single tensor has shape\n                  (num_all_proposals, 4), the last dimension 4 represents\n                  [tl_x, tl_y, br_x, br_y].\n                - bbox_weights (list[tensor],Tensor): Regression weights for\n                  all proposals in a batch, each tensor in list has shape\n                  (num_proposals, 4) when `concat=False`, otherwise just a\n                  single tensor has shape (num_all_proposals, 4).\n                - dis_targets (list[tensor], Tensor): Gt_dis for all\n                  proposal in a batch, each tensor in list has\n                  shape (num_proposal,) when 'concat=False`, otherwise\n                  just a single tensor has shape (num_all_proposals,).\n        "
    pos_bboxes_list = [res.pos_bboxes for res in sampling_results]
    neg_bboxes_list = [res.neg_bboxes for res in sampling_results]
    pos_gt_bboxes_list = [res.pos_gt_bboxes for res in sampling_results]
    pos_gt_labels_list = [res.pos_gt_labels for res in sampling_results]
    (labels, label_weights, bbox_targets, bbox_weights) = multi_apply(self._get_target_single, pos_bboxes_list, neg_bboxes_list, pos_gt_bboxes_list, pos_gt_labels_list, cfg=rcnn_train_cfg)
    iou_calculator = dict(type='BboxOverlaps2D')
    iou_calculator = build_iou_calculator(iou_calculator)
    isolation_thr = 0.45
    dis_targets = []
    for (i, res) in enumerate(sampling_results):
        ref_grap_list = []
        ref_leav_list = []
        ref_grap_dis_list = []
        ref_leav_dis_list = []
        for (j, bbox) in enumerate(gt_bboxes[i]):
            if (self.dis_selector == 0):
                if (('grappolo' in classes[gt_labels[i][j]]) and (gt_labels[i][j] != reference_labels['grappolo_vite'])):
                    ref_grap_dis_list.append(bbox)
                elif ((('foglia' in classes[gt_labels[i][j]]) or (classes[gt_labels[i][j]] == 'malattia_esca') or (classes[gt_labels[i][j]] == 'virosi_pinot_grigio')) and (gt_labels[i][j] != reference_labels['foglia_vite'])):
                    ref_leav_dis_list.append(bbox)
            elif (self.dis_selector == 1):
                if (gt_labels[i][j] == reference_labels['grappolo_vite']):
                    ref_grap_list.append(bbox)
                elif (gt_labels[i][j] == reference_labels['foglia_vite']):
                    ref_leav_list.append(bbox)
            elif (self.dis_selector == 2):
                if (gt_labels[i][j] == reference_labels['grappolo_vite']):
                    ref_grap_list.append(bbox)
                elif (gt_labels[i][j] == reference_labels['foglia_vite']):
                    ref_leav_list.append(bbox)
                elif ('grappolo' in classes[gt_labels[i][j]]):
                    ref_grap_dis_list.append(bbox)
                elif (('foglia' in classes[gt_labels[i][j]]) or (classes[gt_labels[i][j]] == 'malattia_esca') or (classes[gt_labels[i][j]] == 'virosi_pinot_grigio')):
                    ref_leav_dis_list.append(bbox)
            "\n                if 'grappolo' in classes[gt_labels[i][j]] and gt_labels[i][j] != reference_labels['grappolo_vite']:\n                    ref_grap_dis_list.append(bbox)\n                elif (('foglia' in classes[gt_labels[i][j]] or classes[gt_labels[i][j]] == 'malattia_esca'                    or classes[gt_labels[i][j]] == 'virosi_pinot_grigio')\n                    and gt_labels[i][j] != reference_labels['foglia_vite']):\n                        ref_leav_dis_list.append(bbox)\n                "
        if (len(ref_grap_list) > 0):
            ref_grap_tensor = torch.cat(ref_grap_list)
            ref_grap_tensor = torch.reshape(ref_grap_tensor, (len(ref_grap_list), 4))
        if (len(ref_leav_list) > 0):
            ref_leav_tensor = torch.cat(ref_leav_list)
            ref_leav_tensor = torch.reshape(ref_leav_tensor, (len(ref_leav_list), 4))
        if (len(ref_grap_dis_list) > 0):
            ref_grap_dis_tensor = torch.cat(ref_grap_dis_list)
            ref_grap_dis_tensor = torch.reshape(ref_grap_dis_tensor, (len(ref_grap_dis_list), 4))
        if (len(ref_leav_dis_list) > 0):
            ref_leav_dis_tensor = torch.cat(ref_leav_dis_list)
            ref_leav_dis_tensor = torch.reshape(ref_leav_dis_tensor, (len(ref_leav_dis_list), 4))
        num_pos = res.pos_bboxes.size(0)
        num_neg = res.neg_bboxes.size(0)
        num_samples = (num_pos + num_neg)
        dis_tensor = res.pos_bboxes.new_full((num_samples,), (- 1), dtype=torch.long)
        dis_list = []
        for (j, bbox) in enumerate(res.pos_bboxes):
            bbox = bbox.unsqueeze(0)
            if (res.pos_gt_labels[j] == reference_labels['grappolo_vite']):
                if (self.dis_selector == 0):
                    dis_list.append((- 1))
                elif ((self.dis_selector == 1) or (self.dis_selector == 2)):
                    if (len(ref_grap_dis_list) > 0):
                        overlaps = iou_calculator(ref_grap_dis_tensor, bbox, mode='iof')
                        overlaps = (overlaps < isolation_thr)
                        if overlaps.all():
                            dis_list.append(0)
                        else:
                            dis_list.append(1)
                    else:
                        dis_list.append(0)
            elif (res.pos_gt_labels[j] == reference_labels['foglia_vite']):
                if (self.dis_selector == 0):
                    dis_list.append((- 1))
                elif ((self.dis_selector == 1) or (self.dis_selector == 2)):
                    if (len(ref_leav_dis_list) > 0):
                        overlaps = iou_calculator(ref_leav_dis_tensor, bbox, mode='iof')
                        overlaps = (overlaps < isolation_thr)
                        if overlaps.all():
                            dis_list.append(0)
                        else:
                            dis_list.append(1)
                    else:
                        dis_list.append(0)
            elif (('grappolo' in classes[res.pos_gt_labels[j]]) and (res.pos_gt_labels[j] != reference_labels['grappolo_vite'])):
                if (self.dis_selector == 1):
                    dis_list.append((- 1))
                elif (self.dis_selector == 0):
                    if (len(ref_grap_list) > 0):
                        overlaps = iou_calculator(bbox, ref_grap_tensor, mode='iof')
                        overlaps = (overlaps < isolation_thr)
                        if overlaps.all():
                            dis_list.append(0)
                        else:
                            dis_list.append(1)
                    else:
                        dis_list.append(0)
                elif (self.dis_selector == 2):
                    if (len(ref_grap_list) > 0):
                        overlaps = iou_calculator(bbox, ref_grap_tensor, mode='iof')
                        overlaps = (overlaps < isolation_thr)
                        if overlaps.all():
                            dis_list.append(2)
                        else:
                            dis_list.append(3)
                    else:
                        dis_list.append(2)
            elif ((('foglia' in classes[res.pos_gt_labels[j]]) or (classes[res.pos_gt_labels[j]] == 'malattia_esca') or (classes[res.pos_gt_labels[j]] == 'virosi_pinot_grigio')) and (res.pos_gt_labels[j] != reference_labels['foglia_vite'])):
                if (self.dis_selector == 1):
                    dis_list.append((- 1))
                elif (self.dis_selector == 0):
                    if (len(ref_leav_list) > 0):
                        overlaps = iou_calculator(bbox, ref_leav_tensor, mode='iof')
                        overlaps = (overlaps < isolation_thr)
                        if overlaps.all():
                            dis_list.append(0)
                        else:
                            dis_list.append(1)
                    else:
                        dis_list.append(0)
                elif (self.dis_selector == 2):
                    if (len(ref_leav_list) > 0):
                        overlaps = iou_calculator(bbox, ref_leav_tensor, mode='iof')
                        overlaps = (overlaps < isolation_thr)
                        if overlaps.all():
                            dis_list.append(2)
                        else:
                            dis_list.append(3)
                    else:
                        dis_list.append(2)
        dis_tensor[:num_pos] = torch.tensor(dis_list)
        dis_targets.append(dis_tensor)
    if concat:
        labels = torch.cat(labels, 0)
        label_weights = torch.cat(label_weights, 0)
        bbox_targets = torch.cat(bbox_targets, 0)
        bbox_weights = torch.cat(bbox_weights, 0)
        dis_targets = torch.cat(dis_targets, 0)
    return (labels, label_weights, bbox_targets, bbox_weights, dis_targets)