示例#1
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()
示例#2
0
 def merge(self, to_file=None):
     for dataset in self.files[1:]:
         if not isinstance(dataset, dict):
             dataset = cvtools.load_json(dataset)
         self.update_img_ann_ids(dataset['images'], dataset['annotations'])
     if to_file:
         self.save(save=to_file)
     return self.merge_coco
示例#3
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)
示例#4
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]
示例#5
0
 def __init__(self, files):
     if not isinstance(files, (list, tuple)):
         raise TypeError('files must be a list, but got {}'.format(
             type(files)))
     assert len(files) > 1, 'least 2 files must be provided!'
     self.files = files
     if isinstance(self.files[0], dict):
         self.merge_coco = copy.deepcopy(self.files[0])
     else:
         self.merge_coco = cvtools.load_json(self.files[0])
     self.img_ids = [
         img_info['id'] for img_info in self.merge_coco['images']
     ]
     self.ann_ids = [
         img_info['id'] for img_info in self.merge_coco['annotations']
     ]
示例#6
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
示例#7
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)