Ejemplo n.º 1
0
    def __call__(self, results):
        img = results['img']
        orig_type = img.dtype
        anns = self._load_anns(results)
        aaa = len(anns)
        bbb = anns.copy()
        if np.random.choice([0, 1], p=[1 - self.aug_ratio, self.aug_ratio]):
            try:
                import instaboostfast as instaboost
            except ImportError:
                raise ImportError('Please run "pip install instaboostfast" '
                                  'to install instaboostfast first.')
            anns, img = instaboost.get_new_data(anns,
                                                img.astype(np.uint8),
                                                self.cfg,
                                                background=None)

        ####################
        #if len(anns) != aaa:
        #ccc = len(results['ann_info']['bboxes'])
        # if len(results['ann_info']['bboxes'])==0:
        # print(results['img_info'])
        # for ann in anns:
        #     print(ann['bbox'])  # clw modify
        # print()
        # for ann in bbb:
        #     print(ann['bbox'])
        # results['ann_info']['bboxes'] = np.empty([0, 4], dtype=np.float32)  # clw modify: fix bug of empty gt
        ######################

        results = self._parse_anns(results, anns, img.astype(orig_type))
        return results
Ejemplo n.º 2
0
 def __call__(self, results):
     img = results['img']
     anns = self._load_anns(results)
     if np.random.choice([0, 1], p=[1 - self.aug_ratio, self.aug_ratio]):
         try:
             import instaboostfast as instaboost
         except ImportError:
             raise ImportError('Please run "pip install instaboostfast" '
                               'to install instaboostfast first.')
         anns, img = instaboost.get_new_data(
             anns, img, self.cfg, background=None)
     results = self._parse_anns(results, anns, img)
     return results
Ejemplo n.º 3
0
def boost(img, target, img_id):

    anns = []
    height, width, channels = img.shape
    ori_target = deepcopy(target)
    try:
        for id in range(len(target)):
            item = target[id]
            ann = {}
            ann['bbox'] = [
                item[0] * width, item[1] * height, (item[2] - item[0]) * width,
                (item[3] - item[1]) * height
            ]
            ann['segmentation'] = find_seg(img_id, item[:4])
            if not ann['segmentation']:
                continue
            ann['category_id'] = id
            anns.append(ann)
        # print("t1",time.time()-t0)
        new_anns, new_img = get_new_data(
            anns, img, config=InstaBoostConfig(heatmap_flag=True))
        # print("t2",time.time()-t0)
        for id in range(len(target)):
            for ann in new_anns:
                if id == ann['category_id']:
                    target[id][0] = ann['bbox'][0] / float(width)
                    target[id][1] = ann['bbox'][1] / float(height)
                    target[id][2] = (ann['bbox'][0] +
                                     ann['bbox'][2]) / float(width)
                    target[id][3] = (ann['bbox'][1] +
                                     ann['bbox'][3]) / float(height)
        # print("t3",time.time()-t0)
    except:
        target = ori_target
        new_img = img
    # r = random.randint(1,10000)
    # cv2.imwrite("image/%d_ori.png"%r,img)
    # cv2.imwrite("image/%d_new.png"%r,new_img)

    return new_img, target