Exemple #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)
Exemple #2
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
Exemple #3
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)
Exemple #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)
Exemple #5
0
        ## Generate proposals for points in pointcloud
        pointcloud = coco.imgToPc[img_id]
        for point in pointcloud['points']:
            rois = get_im_proposals(point,
                                    sizes=(128, 256, 512, 1024),
                                    aspect_ratios=(0.5, 1, 2),
                                    layout=['center', 'top', 'left', 'right'],
                                    beta=8,
                                    include_depth=args.include_depth)
            proposals = np.append(proposals, np.array(rois), axis=0)

        ## Clip the boxes to image boundaries
        img_width = img_info['width']
        img_height = img_info['height']
        proposals = clip_boxes_to_image(proposals, img_height, img_width)

        # # Plot the proposal boxes
        # img_path = os.path.join(args.imgs_dir, img_info['file_name'])
        # img = cv2.imread(img_path)
        # plotted_image = draw_xyxy_bbox(img, proposals.tolist(), lineWidth=2)
        # plotted_image = cv2.cvtColor(plotted_image, cv2.COLOR_BGR2RGB)
        # ax = plt.subplot(111)
        # ax.imshow(plotted_image)
        # save_fig('temp.pdf')
        # input('here')
        # plt.clf()

        boxes.append(proposals)
        scores.append(np.zeros((proposals.shape[0]), dtype=np.float32))
        ids.append(img_id)