Exemplo n.º 1
0
Arquivo: crop.py Projeto: zivzone/d2go
    def get_transform(self, image, annotations):
        """
        This function will modify instances to set the iscrowd flag to 1 for
        annotations not picked. It relies on the dataset mapper to filter those
        items out
        """
        assert isinstance(annotations, (list, tuple)), annotations
        assert all("bbox" in x for x in annotations), annotations
        assert all("bbox_mode" in x for x in annotations), annotations

        image_size = image.shape[:2]

        # filter out iscrowd
        annotations = [x for x in annotations if x.get("iscrowd", 0) == 0]
        if len(annotations) == 0:
            return NoOpTransform()

        sel_index = np.random.randint(len(annotations))
        # set iscrowd flag of other annotations to 1 so that they will be
        #   filtered out by the datset mapper (https://fburl.com/diffusion/fg64cb4h)
        for idx, instance in enumerate(annotations):
            if idx != sel_index:
                instance["iscrowd"] = 1
        instance = annotations[sel_index]

        bbox_xywh = BoxMode.convert(instance["bbox"], instance["bbox_mode"],
                                    BoxMode.XYWH_ABS)

        scale = np.random.uniform(*self.crop_scale)
        bbox_xywh = bu.scale_bbox_center(bbox_xywh, scale)
        bbox_xywh = bu.clip_box_xywh(bbox_xywh, image_size).int()

        return CropTransform(*bbox_xywh.tolist())
Exemplo n.º 2
0
Arquivo: crop.py Projeto: zivzone/d2go
 def get_transform(self, image):
     img_h, img_w = image.shape[:2]
     assert self.count < img_h and self.count < img_w
     assert img_h > self.count * 2
     assert img_w > self.count * 2
     box = [
         self.count, self.count, img_w - self.count * 2,
         img_h - self.count * 2
     ]
     return CropTransform(*box)
Exemplo n.º 3
0
Arquivo: crop.py Projeto: zivzone/d2go
    def get_transform(self, image: np.ndarray, boxes: np.ndarray):
        # boxes: 1 x 4 in xyxy format
        assert boxes.shape[0] == 1
        assert isinstance(image, np.ndarray)
        assert isinstance(boxes, np.ndarray)
        img_h, img_w = image.shape[0:2]

        box_xywh = bu.get_bbox_xywh_from_xyxy(boxes[0])
        if self.box_scale_factor != 1.0:
            box_xywh = bu.scale_bbox_center(box_xywh, self.box_scale_factor)
            box_xywh = bu.clip_box_xywh(box_xywh, [img_h, img_w])
        box_xywh = box_xywh.int().tolist()
        return CropTransform(*box_xywh, orig_w=img_w, orig_h=img_h)
Exemplo n.º 4
0
Arquivo: crop.py Projeto: zivzone/d2go
 def inverse(self) -> Transform:
     return CropTransform(self.x0, self.y0, self.w, self.h, self.org_w,
                          self.org_h)