(self,
                         anchors_dict,
                         gt_boxes,
                         anchors_mask=None,
                         gt_classes=None,
                         gt_names=None,
                         importance=None)
return targets_dict
this function assign target individally for each class.
        recommend for multi-class network.
this function assign target individally for each class.
        recommend for multi-class network.
this function assign target individally for each class . recommend for multi - class network .
def assign_per_class(self,
                         anchors_dict,
                         gt_boxes,
                         anchors_mask=None,
                         gt_classes=None,
                         gt_names=None,
                         importance=None):
        """this function assign target individally for each class.
        recommend for multi-class network.
        """

        def box_encoding_fn(boxes, anchors):
            return self._box_coder.encode(boxes, anchors)

        targets_list = []
        anchor_loc_idx = 0
        anchor_gene_idx = 0
        for class_name, anchor_dict in anchors_dict.items():

            def similarity_fn(anchors, gt_boxes):
                anchors_rbv = anchors[:, [0, 1, 3, 4, 6]]
                gt_boxes_rbv = gt_boxes[:, [0, 1, 3, 4, 6]]
                return self._sim_calcs[anchor_gene_idx].compare(
                    anchors_rbv, gt_boxes_rbv)

            mask = np.array([c == class_name for c in gt_names],
                            dtype=np.bool_)
            feature_map_size = anchor_dict["anchors"].shape[:3]
            num_loc = anchor_dict["anchors"].shape[-2]
            if anchors_mask is not None:
                anchors_mask = anchors_mask.reshape(-1)
                a_range = self.anchors_range(class_name)
                anchors_mask_class = anchors_mask[a_range[0]:a_range[1]].reshape(-1)
                prune_anchor_fn = lambda _: np.where(anchors_mask_class)[0]
            else:
                prune_anchor_fn = None
            # print(f"num of {class_name}:", np.sum(mask))
            targets = create_target_np(
                anchor_dict["anchors"].reshape(-1, self.box_ndim),
                gt_boxes[mask],
                similarity_fn,
                box_encoding_fn,
                prune_anchor_fn=prune_anchor_fn,
                gt_classes=gt_classes[mask],
                matched_threshold=anchor_dict["matched_thresholds"],
                unmatched_threshold=anchor_dict["unmatched_thresholds"],
                positive_fraction=self._positive_fraction,
                rpn_batch_size=self._sample_size,
                norm_by_num_examples=False,
                box_code_size=self.box_coder.code_size,
                gt_importance=importance)
            # print(f"num of positive:", np.sum(targets["labels"] == self.classes.index(class_name) + 1))
            anchor_loc_idx += num_loc
            targets_list.append(targets)
            anchor_gene_idx += 1

        targets_dict = {
            "labels": [t["labels"] for t in targets_list],
            "bbox_targets": [t["bbox_targets"] for t in targets_list],
            "importance": [t["importance"] for t in targets_list],
        }
        targets_dict["bbox_targets"] = np.concatenate([
            v.reshape(-1, self.box_coder.code_size)
            for v in targets_dict["bbox_targets"]
        ],
                                                      axis=0)
        targets_dict["bbox_targets"] = targets_dict["bbox_targets"].reshape(
            -1, self.box_coder.code_size)
        targets_dict["labels"] = np.concatenate(
            [v.reshape(-1) for v in targets_dict["labels"]],
            axis=0)
        targets_dict["importance"] = np.concatenate(
            [v.reshape(-1) for v in targets_dict["importance"]],
            axis=0)
        targets_dict["labels"] = targets_dict["labels"].reshape(-1)
        targets_dict["importance"] = targets_dict["importance"].reshape(-1)

        return targets_dict
def assign_per_class ( self , anchors_dict , gt_boxes , anchors_mask = None , gt_classes = None , gt_names = None , importance = None ) : def box_encoding_fn ( boxes , anchors ) : return self . _box_coder . encode ( boxes , anchors ) targets_list = [ ] anchor_loc_idx = 0 anchor_gene_idx = 0 for class_name , anchor_dict in anchors_dict . items ( ) : def similarity_fn ( anchors , gt_boxes ) : anchors_rbv = anchors [ : , [ 0 , 1 , 3 , 4 , 6 ] ] gt_boxes_rbv = gt_boxes [ : , [ 0 , 1 , 3 , 4 , 6 ] ] return self . _sim_calcs [ anchor_gene_idx ] . compare ( anchors_rbv , gt_boxes_rbv ) mask = np . array ( [ c == class_name for c in gt_names ] , dtype = np . bool_ ) feature_map_size = anchor_dict [ "anchors" ] . shape [ : 3 ] num_loc = anchor_dict [ "anchors" ] . shape [ - 2 ] if anchors_mask is not None : anchors_mask = anchors_mask . reshape ( - 1 ) a_range = self . anchors_range ( class_name ) anchors_mask_class = anchors_mask [ a_range [ 0 ] : a_range [ 1 ] ] . reshape ( - 1 ) prune_anchor_fn = lambda _ : np . where ( anchors_mask_class ) [ 0 ] else : prune_anchor_fn = None # print(f"num of {class_name}:", np.sum(mask)) targets = create_target_np ( anchor_dict [ "anchors" ] . reshape ( - 1 , self . box_ndim ) , gt_boxes [ mask ] , similarity_fn , box_encoding_fn , prune_anchor_fn = prune_anchor_fn , gt_classes = gt_classes [ mask ] , matched_threshold = anchor_dict [ "matched_thresholds" ] , unmatched_threshold = anchor_dict [ "unmatched_thresholds" ] , positive_fraction = self . _positive_fraction , rpn_batch_size = self . _sample_size , norm_by_num_examples = False , box_code_size = self . box_coder . code_size , gt_importance = importance ) # print(f"num of positive:", np.sum(targets["labels"] == self.classes.index(class_name) + 1)) anchor_loc_idx += num_loc targets_list . append ( targets ) anchor_gene_idx += 1 targets_dict = { "labels" : [ t [ "labels" ] for t in targets_list ] , "bbox_targets" : [ t [ "bbox_targets" ] for t in targets_list ] , "importance" : [ t [ "importance" ] for t in targets_list ] , } targets_dict [ "bbox_targets" ] = np . concatenate ( [ v . reshape ( - 1 , self . box_coder . code_size ) for v in targets_dict [ "bbox_targets" ] ] , axis = 0 ) targets_dict [ "bbox_targets" ] = targets_dict [ "bbox_targets" ] . reshape ( - 1 , self . box_coder . code_size ) targets_dict [ "labels" ] = np . concatenate ( [ v . reshape ( - 1 ) for v in targets_dict [ "labels" ] ] , axis = 0 ) targets_dict [ "importance" ] = np . concatenate ( [ v . reshape ( - 1 ) for v in targets_dict [ "importance" ] ] , axis = 0 ) targets_dict [ "labels" ] = targets_dict [ "labels" ] . reshape ( - 1 ) targets_dict [ "importance" ] = targets_dict [ "importance" ] . reshape ( - 1 ) return targets_dict