示例#1
0
 def _add_proposals_from_file(self, roidb, proposal_file, min_proposal_size,
                              top_k, crowd_thresh):
     """Add proposals from a proposals file to an roidb."""
     logger.info('Loading proposals from: {}'.format(proposal_file))
     with open(proposal_file, 'r') as f:
         proposals = pickle.load(f)
     id_field = 'indexes' if 'indexes' in proposals else 'ids'  # compat fix
     _sort_proposals(proposals, id_field)
     box_list = []
     for i, entry in enumerate(roidb):
         if i % 2500 == 0:
             logger.info(' {:d}/{:d}'.format(i + 1, len(roidb)))
         boxes = proposals['boxes'][i]
         # Sanity check that these boxes are for the correct image id
         assert entry['id'] == proposals[id_field][i]
         # Remove duplicate boxes and very small boxes and then take top k
         boxes = box_utils.clip_boxes_to_image(boxes, entry['height'],
                                               entry['width'])
         keep = box_utils.unique_boxes(boxes)
         boxes = boxes[keep, :]
         keep = box_utils.filter_small_boxes(boxes, min_proposal_size)
         boxes = boxes[keep, :]
         if top_k > 0:
             boxes = boxes[:top_k, :]
         box_list.append(boxes)
     _merge_proposal_boxes_into_roidb(roidb, box_list)
     if crowd_thresh > 0:
         _filter_crowd_proposals(roidb, crowd_thresh)
示例#2
0
 def _add_proposals_from_file(
     self, roidb, proposal_file, min_proposal_size, top_k, crowd_thresh
 ):
     """Add proposals from a proposals file to an roidb."""
     logger.info('Loading proposals from: {}'.format(proposal_file))
     with open(proposal_file, 'r') as f:
         proposals = pickle.load(f)
     id_field = 'indexes' if 'indexes' in proposals else 'ids'  # compat fix
     _sort_proposals(proposals, id_field)
     box_list = []
     for i, entry in enumerate(roidb):
         if i % 2500 == 0:
             logger.info(' {:d}/{:d}'.format(i + 1, len(roidb)))
         boxes = proposals['boxes'][i]
         # Sanity check that these boxes are for the correct image id
         assert entry['id'] == proposals[id_field][i]
         # Remove duplicate boxes and very small boxes and then take top k
         boxes = box_utils.clip_boxes_to_image(
             boxes, entry['height'], entry['width']
         )
         keep = box_utils.unique_boxes(boxes)
         boxes = boxes[keep, :]
         keep = box_utils.filter_small_boxes(boxes, min_proposal_size)
         boxes = boxes[keep, :]
         if top_k > 0:
             boxes = boxes[:top_k, :]
         box_list.append(boxes)
     _merge_proposal_boxes_into_roidb(roidb, box_list)
     if crowd_thresh > 0:
         _filter_crowd_proposals(roidb, crowd_thresh)
示例#3
0
def prep_proposal_file(proposal_file, output_dir, min_proposal_size=2, top_k=-1):
    rois = load_proposal_file(proposal_file, output_dir)
    boxes = rois['boxes']
    scores = rois['scores']
    boxes_out = []
    for img,img_boxes in enumerate(boxes):
        img_scores = scores[img]
        img_boxes = box_utils.clip_boxes_to_image(img_boxes, 1080, 1920)  # TODO: remove this dirty hack!
        keep = box_utils.unique_boxes(img_boxes)
        img_boxes =img_boxes[keep, :]
        img_scores = img_scores[keep]
        keep = box_utils.filter_small_boxes(img_boxes, min_proposal_size)
        img_boxes =img_boxes[keep, :]
        img_scores = img_scores[keep]
        
        if top_k > 0:           
            img_boxes =img_boxes[:top_k]
            img_scores = img_scores[:top_k]
        
        box_cache = []
        for sc, entry in enumerate(img_boxes):
            entry = np.append(entry, img_scores[sc])
            box_cache.append(entry)
        
        boxes_out.append(np.array(box_cache))
    
    return boxes_out
示例#4
0
    def _add_proposals_from_file(
        self, roidb, proposal_file, min_proposal_size, top_k, crowd_thresh
    ):
        """Add proposals from a proposals file to an roidb."""
        logger.info('Loading proposals from: {}'.format(proposal_file))
        proposals = load_object(proposal_file)

        id_field = 'indexes' if 'indexes' in proposals else 'ids'  # compat fix
        _sort_proposals(proposals, id_field)
        box_list = []
        depths_list = []
        for i, entry in enumerate(roidb):
            depth_exists = 0
            depths = None
            if i % 2500 == 0:
                logger.info(' {:d}/{:d}'.format(i + 1, len(roidb)))
            boxes = proposals['boxes'][i]
            
            if boxes.shape[1] == 5:
                ## Proposals contain depth information in the fifth column
                depth_exists = 1
                depths = boxes[:,4]
                boxes = boxes[:,:4]

            # Sanity check that these boxes are for the correct image id
            assert entry['id'] == proposals[id_field][i]
            # Remove duplicate boxes and very small boxes and then take top k
            boxes = box_utils.clip_boxes_to_image(
                boxes, entry['height'], entry['width']
            )
            keep = box_utils.unique_boxes(boxes)
            boxes = boxes[keep, :]
            if depth_exists:
                depths = depths[keep]
            keep = box_utils.filter_small_boxes(boxes, min_proposal_size)
            boxes = boxes[keep, :]
            if depth_exists:
                depths = depths[keep]
            if top_k > 0:
                boxes = boxes[:top_k, :]
                if depth_exists:
                    depths = depths[:top_k]
            box_list.append(boxes)
            if depth_exists:
                depths_list.append(depths)
        _merge_proposal_boxes_into_roidb(roidb, box_list, depths_list)
        if crowd_thresh > 0:
            _filter_crowd_proposals(roidb, crowd_thresh)
示例#5
0
    def _add_proposals_from_file(self, roidb, proposal_file, min_proposal_size,
                                 top_k, crowd_thresh):
        """Add proposals from a proposals file to an roidb."""
        logger.info('Loading proposals from: {}'.format(proposal_file))
        proposals = load_object(proposal_file)

        id_field = 'indexes' if 'indexes' in proposals else 'ids'  # compat fix

        # _remove_proposals_not_in_roidb(proposals, roidb, id_field)
        _sort_proposals(proposals, id_field)
        box_list = []
        score_list = []
        total_roi = 0
        up_1024 = 0
        up_2048 = 0
        up_3072 = 0
        up_4096 = 0
        for i, entry in enumerate(roidb):
            if i % 2500 == 0:
                logger.info(' {:d}/{:d}'.format(i + 1, len(roidb)))
            boxes = proposals['boxes'][i]
            scores = proposals['scores'][i]
            # Sanity check that these boxes are for the correct image id
            assert entry['id'] == proposals[id_field][i]
            # Remove duplicate boxes and very small boxes and then take top k
            # boxes = box_utils.clip_boxes_to_image(
            # boxes, entry['height'], entry['width']
            # )
            assert (boxes[:, 0] >= 0).all()
            assert (boxes[:, 1] >= 0).all()
            assert (boxes[:, 2] >= boxes[:, 0]).all()
            assert (boxes[:, 3] >= boxes[:, 1]).all()
            assert (boxes[:, 2] < entry['width']).all(), entry['image']
            assert (boxes[:, 3] < entry['height']).all(), entry['image']

            keep = box_utils.unique_boxes(boxes)
            boxes = boxes[keep, :]
            scores = scores[keep]
            keep = box_utils.filter_small_boxes(boxes, min_proposal_size)
            boxes = boxes[keep, :]
            scores = scores[keep]

            # sort by confidence
            sorted_ind = np.argsort(-scores.flatten())
            boxes = boxes[sorted_ind, :]
            scores = scores[sorted_ind, :]

            if top_k > 0:
                boxes = boxes[:top_k, :]
                scores = scores[:top_k]

            total_roi += boxes.shape[0]
            if boxes.shape[0] > 1024:
                up_1024 += 1
            if boxes.shape[0] > 2048:
                up_2048 += 1
            if boxes.shape[0] > 3072:
                up_3072 += 1
            if boxes.shape[0] > 4096:
                up_4096 += 1

            box_list.append(boxes)
            score_list.append(scores)

        print('total_roi: ', total_roi, ' ave roi: ',
              total_roi / len(box_list))
        print('up_1024: ', up_1024)
        print('up_2048: ', up_2048)
        print('up_3072: ', up_3072)
        print('up_4096: ', up_4096)

        _merge_proposal_boxes_into_roidb(roidb, box_list, score_list)
        if crowd_thresh > 0:
            _filter_crowd_proposals(roidb, crowd_thresh)