def __call__(self, data, label, gt, seg_gt, seg_gt_to_compare):
        #-----------------------------------------------------------------------
        # Initialize the data vector and other variables
        #-----------------------------------------------------------------------
        if not self.initialized:
            self.initialize()

        vec = np.zeros((self.vheight, self.vwidth), dtype=np.float32)

        #-----------------------------------------------------------------------
        # For every box compute the best match and all the matches above 0.5
        # Jaccard overlap
        #-----------------------------------------------------------------------
        overlaps = {}
        for box in gt.boxes:
            box_arr = box2array(box, self.img_size)
            overlaps[box] = compute_overlap(box_arr, self.anchors_arr, 0.5)

        #-----------------------------------------------------------------------
        # Set up the training vector resolving conflicts in favor of a better
        # match
        #-----------------------------------------------------------------------
        vec[:, self.num_classes] = 1  # background class
        vec[:, self.num_classes + 1] = 0  # x offset
        vec[:, self.num_classes + 2] = 0  # y offset
        vec[:, self.num_classes + 3] = 0  # log width scale
        vec[:, self.num_classes + 4] = 0  # log height scale

        matches = {}
        for box in gt.boxes:
            for overlap in overlaps[box].good:
                anchor = self.anchors[overlap.idx]

                process_overlap(overlap, box, anchor, matches,
                                self.num_classes, vec)

        matches = {}
        for box in gt.boxes:
            overlap = overlaps[box].best
            if not overlap:
                continue
            anchor = self.anchors[overlap.idx]
            process_overlap(overlap, box, anchor, matches, self.num_classes,
                            vec)

        return data, vec, gt, seg_gt, seg_gt_to_compare
Example #2
0
    def __call__(self, data, label, gt):
        if not self.initialized:
            self.initialize()
        vec = np.zeros((self.vheight, self.vwidth), dtype=np.float32)
        overlaps = {}
        for box in gt.boxes:
            # box = 0~1
            box_arr = box2array(
                box, self.img_size
            )  # Convert proportional center-width bounds to absolute min-max bounds
            # box_arr = (0~300, 0~300)
            # gt_box xmin, xmax, ymin, ymax
            overlaps[box] = compute_overlap(box_arr, self.anchors_arr, 0.4)

        vec[:, self.num_classes] = 1.  # background
        vec[:, self.num_classes + 1] = 0.  # x offset
        vec[:, self.num_classes + 2] = 0.  # y offset
        vec[:, self.num_classes + 3] = 0.  # log width scale
        vec[:, self.num_classes + 4] = 0.  # log height scale

        matches = {}
        for box in gt.boxes:
            for overlap in overlaps[box].good:
                anchor = self.anchors[overlap.idx]
                process_overlap(overlap, box, anchor, matches,
                                self.num_classes, vec)

        matches = {}
        for box in gt.boxes:
            overlap = overlaps[box].best
            if not overlap:
                continue
            anchor = self.anchors[overlap.idx]
            process_overlap(overlap, box, anchor, matches, self.num_classes,
                            vec)

        return data, vec, gt.filename