示例#1
0
 def _handle_max_angle(cls, max_angle):
     if max_angle is None:
         return 40, 40, 10
     if isinstance(max_angle, (list, tuple)):
         assert len(max_angle) == 3, (
             "Expected parameter '%s' with type tuple or list to have exactly three "
             "entries, but got %d." % ("max_angle", len(max_angle)))
         assert all([_is_number(v) for v in max_angle]), (
             "Expected parameter '%s' with type tuple or list to only contain "
             "numbers, got %s." % (
                 "max_angle",
                 [type(v) for v in max_angle],
             ))
         return max_angle
     elif isinstance(max_angle, dict):
         assert 'x' in max_angle or 'y' in max_angle or 'z' in max_angle, (
             "Expected max_angle dictionary to contain at "
             "least key \"x\" or key \"y\" or key \"z\". Found neither of them."
         )
         return tuple((check_number_param(max_angle.get('x', 0),
                                          name="max_angle['x']"),
                       check_number_param(max_angle.get('y', 0),
                                          name="max_angle['y']"),
                       check_number_param(max_angle.get('z', 0),
                                          name="max_angle['z']")))
     else:
         raise TypeError("Expected max_angle to be dictionary, but got %s" %
                         type(max_angle).__name__)
示例#2
0
 def __init__(self, hue_prob, hue_delta, color_channel="RGB"):
     super(RandomHue, self).__init__()
     self.hue_prob = check_number_param(hue_prob, 'hue_prob')
     self.hue_delta = check_number_param(hue_delta, 'hue_delta')
     assert isinstance(color_channel,
                       str), ("Expected parameter '%s' with type str, "
                              "got %s." %
                              ("color_channel", type(color_channel)))
     self.color_channel = color_channel
示例#3
0
 def __init__(self,
              target_size,
              random_offset=False,
              img_border_value=0,
              seg_border_value=0,
              backend=None):
     super(KeepAspectResize, self).__init__(backend=backend)
     self.target_size = check_number_param(target_size,
                                           name="target_size",
                                           list_or_tuple=True)
     self.random_offset = random_offset
     self.img_border_value = check_number_param(img_border_value,
                                                name="img_border_value")
     self.seg_border_value = check_number_param(seg_border_value,
                                                name="sef_border_value")
示例#4
0
 def _handle_scale(cls, scale_range):
     if scale_range is None:
         return 0.8, 1.1
     elif isinstance(scale_range, (tuple, list)):
         return check_number_param(scale_range, name="scale_range")
     elif isinstance(scale_range, dict):
         assert 'min' in scale_range and 'max' in scale_range, (
             "Expected scale_range dictionary to contain at "
             "key \"min\" and key \"max\", but not Found.")
         return check_number_param(
             (scale_range.get('min'), scale_range.get('max')),
             name="scale_range")
     else:
         raise TypeError(
             "Expected scale_range to be dictionary, but got %s" %
             type(scale_range).__name__)
示例#5
0
 def _handle_angle(cls, angle_range):
     if angle_range is None:
         return -30, 30
     elif isinstance(angle_range, (tuple, list)):
         return check_number_param(angle_range, name="angle_range")
     elif isinstance(angle_range, dict):
         assert 'min' in angle_range or 'max' in angle_range, (
             "Expected angle_range dictionary to contain at "
             "least key \"min\" or key \"max\". Found neither of them.")
         return check_number_param(
             (angle_range.get('min', 0), angle_range.get('max', 0)),
             name="angle_range")
     else:
         raise TypeError(
             "Expected angle_range to be dictionary, but got %s" %
             type(angle_range).__name__)
示例#6
0
    def __init__(self,
                 target_size,
                 max_sum=None,
                 max_angle=None,
                 img_border_value=0,
                 seg_border_value=0,
                 backend=None):
        super(Affine, self).__init__(backend=backend)

        self.target_size = check_number_param(target_size,
                                              name="target_size",
                                              list_or_tuple=True)
        self.img_border_value = check_number_param(img_border_value,
                                                   name="img_border_value")
        self.seg_border_value = check_number_param(seg_border_value,
                                                   name="seg_border_value")
        self.max_angle = np.asarray(self._handle_max_angle(max_angle),
                                    dtype=np.float32)
        self.max_sum = float(max_sum) if max_sum is not None else 80.
示例#7
0
    def __init__(self,
                 target_size,
                 angle_range=None,
                 scale_range=None,
                 offset_center=True,
                 img_border_value=0,
                 seg_border_value=0,
                 backend=None):
        super(Rotation, self).__init__(backend=backend)
        self.angle_range = self._handle_angle(angle_range)
        self.scale_range = self._handle_scale(scale_range)
        self.target_size = check_number_param(target_size,
                                              name='target_size',
                                              list_or_tuple=True)

        self.offset_center = offset_center
        self.img_border_value = check_number_param(img_border_value,
                                                   name="img_border_value")
        self.seg_border_value = check_number_param(seg_border_value,
                                                   name="seg_border_value")
示例#8
0
 def __init__(self, prob, delta=32.):
     super(RandomBrightness, self).__init__()
     self.prob = check_number_param(prob, 'prob')
     self.delta = check_number_param(delta, 'delta')
示例#9
0
 def __init__(self, prob, lower=0.6, upper=1.2):
     super(RandomContrast, self).__init__()
     self.prob = check_number_param(prob, "prob")
     self.lower = check_number_param(lower, "lower")
     self.upper = check_number_param(upper, "upper")
示例#10
0
 def __init__(self, crop_size, backend=None):
     super(ResizeAndCrop, self).__init__(backend=backend)
     self.crop_size = check_number_param(crop_size,
                                         name="crop_size",
                                         list_or_tuple=True)