示例#1
0
 def __init__(self,
              target_size=(512, 512),
              interpolation=cv2.INTER_LINEAR,
              border_mode=cv2.BORDER_CONSTANT,
              border_value=0,
              keep_aspect_ratio=True,
              always_apply=False, p=1,
              aug_p=0,
              shift_limit=0.2,
              scale_limit=0.2,
              rotate_limit=30,
              shift_limit_x=None,
              shift_limit_y=None
              ):
     super(RoITanhPolarWarp, self).__init__(always_apply, p)
     if isinstance(target_size, str):
         target_size = eval(target_size)
     self.target_size = target_size
     self.interpolation = interpolation
     self.border_mode = border_mode
     self.border_value = border_value
     self.keep_aspect_ratio = keep_aspect_ratio
     self.shift_limit_x = to_tuple(
         shift_limit_x if shift_limit_x is not None else shift_limit)
     self.shift_limit_y = to_tuple(
         shift_limit_y if shift_limit_y is not None else shift_limit)
     self.scale_limit = to_tuple(scale_limit, bias=1.0)
     self.rotate_limit = to_tuple(rotate_limit)
     self.aug_p = aug_p
示例#2
0
 def __init__(self, limit=90, interpolation=cv2.INTER_LINEAR,
              border_mode=cv2.BORDER_REFLECT_101, border_value=255, always_apply=False, p=.5):
     super().__init__(always_apply, p)
     self.limit = to_tuple(limit)
     self.interpolation = interpolation
     self.border_mode = border_mode
     self.border_value = border_value
示例#3
0
    def __init__(self,
                 scale_limit,
                 axis='both',
                 interpolation='bicubic',
                 always_apply=False,
                 p=0.5):
        super(RandomScale, self).__init__(always_apply, p)

        self.scale_limit = to_tuple(scale_limit)
        # post-processing to fix values if only a single number was passed
        self.axis = axis
        if self.scale_limit[0] == -self.scale_limit[1]:
            self.scale_limit = tuple(
                [self.scale_limit[0] + 1, self.scale_limit[1] + 1])
        if interpolation == 'bicubic':
            self.interpolation = BICUBIC
        elif interpolation == 'bilinear':
            self.interpolation = BILINEAR
        elif interpolation == 'lanczos':
            self.interpolation = LANCZOS
        elif interpolation == 'nearest':
            self.interpolation = NEAREST
        elif interpolation == 'hamming':
            self.interpolation = HAMMING
        else:
            raise ValueError(
                'The interpolation argument is not one of: ' +
                '["bicubic", "bilinear", "hamming", "lanczos", "nearest"]')
示例#4
0
    def __init__(self, limit=90, border_mode='reflect', cval=0.0,
                 always_apply=False, p=0.5):
        super(Rotate, self).__init__(always_apply, p)

        self.limit = to_tuple(limit)
        self.border_mode = border_mode
        self.cval = cval
示例#5
0
 def __init__(self,
              shift_limit=0.0625,
              scale_limit=0.1,
              rotate_limit=45,
              interpolation=cv2.INTER_LINEAR,
              border_mode=cv2.BORDER_REFLECT_101,
              value=None,
              mask_value=None,
              always_apply=False,
              p=0.5):
     super(ShiftScaleRotate, self).__init__(always_apply, p)
     self.shift_limit = to_tuple(shift_limit)
     self.scale_limit = to_tuple(scale_limit, bias=1.0)
     self.rotate_limit = to_tuple(rotate_limit)
     self.interpolation = interpolation
     self.border_mode = border_mode
     self.value = value
     self.mask_value = mask_value
def test_to_tuple():
    assert to_tuple(10) == (-10, 10)
    assert to_tuple(0.5) == (-0.5, 0.5)
    assert to_tuple((-20, 20)) == (-20, 20)
    assert to_tuple([-20, 20]) == (-20, 20)
    assert to_tuple(100, low=30) == (30, 100)
    assert to_tuple(10, bias=1) == (-9, 11)
    assert to_tuple(100, bias=2) == (-98, 102)
示例#7
0
 def get_transform_init_args(self):
     return {
         'shift_limit': self.shift_limit,
         'scale_limit': to_tuple(self.scale_limit, bias=-1.0),
         'rotate_limit': self.rotate_limit,
         'interpolation': self.interpolation,
         'border_mode': self.border_mode,
         'value': self.value,
         'mask_value': self.mask_value
     }
示例#8
0
 def __init__(self,
              scale_limit=0.1,
              interpolation=0,
              always_apply=False,
              p=0.5):
     super(RandomScale, self).__init__(always_apply, p)
     if type(scale_limit) == float:
         scale_limit = [scale_limit, scale_limit, scale_limit]
     self.scale_limit = [to_tuple(sl, bias=1.0) for sl in scale_limit]
     self.interpolation = interpolation
示例#9
0
 def __init__(self,
              max_angle=2.0,
              interpolation=0,
              always_apply=False,
              p=0.25):
     super(RandomRotate, self).__init__(always_apply, p)
     if type(max_angle) == int:
         max_angle = [max_angle, max_angle, max_angle]
     self.max_angle = [to_tuple(sl, bias=0) for sl in max_angle]
     self.interpolation = interpolation
 def __init__(self,
              always_apply=False,
              p=0.5,
              limit=2.0,
              n_class=13,
              n_camera=4):
     super(RandomDepthShift, self).__init__(always_apply, p)
     self.limit = to_tuple(limit)
     self.n_class = n_class
     self.n_camera = n_camera
示例#11
0
 def __init__(self,
              shift_limit=2,
              interpolation=0,
              always_apply=False,
              p=0.75):
     super(RandomShift, self).__init__(always_apply, p)
     if type(shift_limit) == int:
         shift_limit = [shift_limit, shift_limit, shift_limit]
     self.shift_limit = [to_tuple(sl, bias=0) for sl in shift_limit]
     self.interpolation = interpolation
示例#12
0
 def get_transform_init_args_names(self):
     return {
         "target_size": self.target_size,
         "interpolation": self.interpolation,
         "border_mode": self.border_mode,
         "border_value": self.border_value,
         "keep_aspect_ratio": self.keep_aspect_ratio,
         "shift_limit_x": self.shift_limit_x,
         "shift_limit_y": self.shift_limit_y,
         "scale_limit": to_tuple(self.scale_limit, bias=-1.0),
         "rotate_limit": self.rotate_limit,
         "interpolation": self.interpolation,
         "border_mode": self.border_mode,
         "aug_p": self.aug_p,
     }
示例#13
0
 def __init__(
     self,
     height,
     width,
     bbox_jitter=0.1,
     expansion_ratio=1.4,
     min_crop_size=200,
     min_area=100,
     always_resize=False,
     always_apply=False,
     p=0.5,
 ):
     super(ZoomIn, self).__init__(always_apply, p)
     self.height = height
     self.width = width
     self.bbox_jitter = to_tuple(bbox_jitter)
     self.expansion_ratio = expansion_ratio
     self.min_crop_size = min_crop_size
     self.min_area = min_area
     self.always_resize = always_resize
示例#14
0
 def get_transform_init_args(self):
     return {
         "interpolation": self.interpolation,
         "scale_limit": to_tuple(self.scale_limit[0], bias=-1.0)[1]
     }
示例#15
0
 def get_transform_init_args(self):
     return {
         "interpolation": self.interpolation,
         "max_angle": to_tuple(self.max_angle[0], bias=0)[1]
     }
示例#16
0
def test_to_tuple():
    assert to_tuple(10) == (-10, 10)
    assert to_tuple(0.5) == (-0.5, 0.5)
    assert to_tuple((-20, 20)) == (-20, 20)
    assert to_tuple(100, low=30) == (30, 100)
示例#17
0
def test_to_tuple():
    assert to_tuple(10) == (-10, 10)
    assert to_tuple(0.5) == (-0.5, 0.5)
    assert to_tuple((-20, 20)) == (-20, 20)
    assert to_tuple([-20, 20]) == (-20, 20)
    assert to_tuple(100, low=30) == (30, 100)
示例#18
0
 def __init__(self, always_apply=False, p=1.0):
     super(RandomBlur, self).__init__(always_apply, p)
     self.blur_limit = to_tuple(15, 3)
     self.motion_limit = to_tuple(10, 3)