示例#1
0
    def __init__(self, gts, results, num_coors=4):
        """

        Args:
            gts (str or COCO): DOTA-COCO兼容格式, img_info中必须含crop字段
            results (str or dict): 子图检测结果,保存在文件中,
                results:
                {
                    image_id: dets,  # image_id必须是anns中有效的id
                    image_id: dets,
                    ...
                }
                dets:
                {
                    类别:[[位置坐标,得分], [...], ...],     # np.array
                    类别: [[位置坐标,得分], [...], ...],
                    ...
                },
                位置坐标支持左上角右下角两个点表示和四个点的表示方式
            num_coors (int): 4表示左上角右下角box, 8表示四个点的box
        """
        assert num_coors in (4, 8), "不支持的检测位置表示"
        self.coco = gts
        self.results = results
        if cvtools.is_str(gts):
            self.coco = cvtools.COCO(gts)
        if cvtools.is_str(results):
            self.results = cvtools.load_pkl(results)
        self.num_coors = num_coors
        self.img_to_results = {}    # merge返回结果保存
示例#2
0
 def __init__(self, anns_file, num_coors=4):
     assert num_coors in (4, 8), "不支持的检测位置表示"
     self.coco = anns_file
     if cvtools.is_str(anns_file):
         self.coco = cvtools.COCO(anns_file)
     self.results = defaultdict()    # 动态创建嵌套字典
     self.num_coors = num_coors
示例#3
0
def test_MergeCropDetResults():
    ann_file = current_path + '/data/DOTA/dota_crop_1024.json'
    results = current_path + '/out/DOTA/dets.pkl'

    gt = cvtools.COCO2Dets(ann_file)
    gt.convert(to_file=results)

    dets = MergeCropDetResults(ann_file, results)
    merge_dets = dets.merge()

    original_ann_file = current_path + '/data/DOTA/dota_x1y1wh_polygon.json'
    coco = cvtools.COCO(original_ann_file)

    gt_bboxes = []
    gt_labels = []
    det_results = []
    for img_id, img_info in coco.imgs.items():
        ann_ids = coco.getAnnIds(imgIds=[img_id])
        anns = coco.loadAnns(ann_ids)
        gt_bboxes.append(np.array([ann['bbox'] for ann in anns]))
        gt_labels.append(np.array([ann['category_id'] for ann in anns]))
        bboxes, labels, _ = merge_dets[img_info['file_name']]
        dets = [[] for _ in range(len(coco.cats))]
        for cls, bbox in zip(labels, bboxes):
            dets[cls].append(bbox)
        for cls, det in enumerate(dets):
            dets[cls] = np.array(det)
        det_results.append(dets)
示例#4
0
 def __init__(self,
              img_prefix=None,
              ann_file=None,
              iof_th=0.7,
              small_prop=0.5,
              max_objs=100,
              overlap=0.1,
              size_th=1333):
     assert 1.0 >= iof_th >= 0.5
     self.img_prefix = img_prefix
     if ann_file is not None:
         self.ann_file = ann_file
         self.coco_dataset = cvtools.load_json(ann_file)
         self.COCO = cvtools.COCO(ann_file)
         self.catToAnns = defaultdict(list)
         if 'annotations' in self.coco_dataset:
             for ann in self.coco_dataset['annotations']:
                 self.catToAnns[ann['category_id']].append(ann)
     self.iof_th = iof_th
     self.small_prop = small_prop
     self.max_objs = max_objs
     self.overlap = overlap
     self.size_th = size_th
     self.imgs = list()
     self.img_to_objs = list()
示例#5
0
 def __init__(self, img_prefix, ann_file=None):
     self.img_prefix = img_prefix
     if ann_file is not None:
         self.ann_file = ann_file
         self.coco_dataset = cvtools.load_json(ann_file)
         self.COCO = cvtools.COCO(ann_file)
         self.catToAnns = defaultdict(list)
         if 'annotations' in self.coco_dataset:
             for ann in self.coco_dataset['annotations']:
                 self.catToAnns[ann['category_id']].append(ann)
示例#6
0
 def __init__(self, img_prefix, ann_file):
     super(CocoDatasetForCrop, self).__init__()
     self.img_prefix = img_prefix
     self.ann_file = ann_file
     self.crop_dataset = cvtools.load_json(ann_file)
     self.COCO = cvtools.COCO(ann_file)
     image_ids = self.COCO.getImgIds()
     image_ids.sort()
     self.roidb = self.COCO.loadImgs(image_ids)
     if cvtools._DEBUG:
         self.roidb = self.roidb[:cvtools._NUM_DATA]
示例#7
0
    def __init__(self,
                 img_prefix=None,
                 ann_file=None,
                 width_size=1920,
                 height_size=1080,
                 overlap=0.):
        self.img_prefix = img_prefix
        if ann_file is not None:
            self.ann_file = ann_file
            self.coco_dataset = cvtools.load_json(ann_file)
            self.COCO = cvtools.COCO(ann_file)
            self.catToAnns = defaultdict(list)
            if 'annotations' in self.coco_dataset:
                for ann in self.coco_dataset['annotations']:
                    self.catToAnns[ann['category_id']].append(ann)

        assert 1920 >= width_size >= 800 and 1080 >= height_size >= 800 and 0.5 >= overlap >= 0.
        self.width_size = int(width_size)
        self.height_size = int(height_size)
        self.overlap = overlap
示例#8
0
 def __init__(self, ann_file, crop_ann_file, results=None, num_coors=4):
     assert num_coors in (4, 8), "不支持的检测位置表示"
     self.num_coors = num_coors
     self.coco = cvtools.COCO(ann_file)
     self.anns = self.coco.anns
     self.calc_ious = (bbox_overlaps
                       if self.num_coors == 4 else poly_overlaps)
     if self.num_coors == 4:
         self.nms = cvtools.py_cpu_nms
     else:
         self.nms = poly_nms.poly_gpu_nms
     self.results = results
     if cvtools.is_str(crop_ann_file):
         if results is None:
             gt = cvtools.COCO2Dets(crop_ann_file)
             self.results = gt.convert()
         else:
             self.results = crop_ann_file
     dets = MergeCropDetResults(crop_ann_file, self.results, self.num_coors)
     self.merge_dets = dets.merge(self.nms)
示例#9
0
 def __init__(self, ann_file):
     self.ann_file = ann_file
     self.coco_dataset = cvtools.load_json(ann_file)
     self.COCO = cvtools.COCO(ann_file)