def build_quasirandom_transforms(num_transforms, zoom_range, rotation_range, shear_range, translation_range, do_flip=True, allow_stretch=False):
    gen = ghalton.Halton(7)  # 7 dimensions to sample along
    uniform_samples = np.array(gen.get(num_transforms))

    tfs = []
    for s in uniform_samples:
        shift_x = icdf.uniform(s[0], *translation_range)
        shift_y = icdf.uniform(s[1], *translation_range)
        translation = (shift_x, shift_y)

        rotation = icdf.uniform(s[2], *rotation_range)
        shear = icdf.uniform(s[3], *shear_range)

        if do_flip:
            flip = icdf.bernoulli(s[4], p=0.5)
        else:
            flip = False

        log_zoom_range = [np.log(z) for z in zoom_range]
        if isinstance(allow_stretch, float):
            log_stretch_range = [-np.log(allow_stretch), np.log(allow_stretch)]
            zoom = np.exp(icdf.uniform(s[5], *log_zoom_range))
            stretch = np.exp(icdf.uniform(s[6], *log_stretch_range))
            zoom_x = zoom * stretch
            zoom_y = zoom / stretch
        elif allow_stretch is True:  # avoid bugs, f.e. when it is an integer
            zoom_x = np.exp(icdf.uniform(s[5], *log_zoom_range))
            zoom_y = np.exp(icdf.uniform(s[6], *log_zoom_range))
        else:
            zoom_x = zoom_y = np.exp(icdf.uniform(s[5], *log_zoom_range))
        # the range should be multiplicatively symmetric, so [1/1.1, 1.1] instead of [0.9, 1.1] makes more sense.

        tfs.append(data.build_augmentation_transform((zoom_x, zoom_y), rotation, shear, translation, flip))

    return tfs
Exemplo n.º 2
0
def build_quasirandom_transforms(num_transforms, zoom_range, rotation_range, shear_range, translation_range, do_flip=True, allow_stretch=False):
    gen = ghalton.Halton(7)  # 7 dimensions to sample along
    uniform_samples = np.array(gen.get(num_transforms))

    tfs = []
    for s in uniform_samples:
        shift_x = icdf.uniform(s[0], *translation_range)
        shift_y = icdf.uniform(s[1], *translation_range)
        translation = (shift_x, shift_y)

        rotation = icdf.uniform(s[2], *rotation_range)
        shear = icdf.uniform(s[3], *shear_range)

        if do_flip:
            flip = icdf.bernoulli(s[4], p=0.5)
        else:
            flip = False

        log_zoom_range = [np.log(z) for z in zoom_range]
        if isinstance(allow_stretch, float):
            log_stretch_range = [-np.log(allow_stretch), np.log(allow_stretch)]
            zoom = np.exp(icdf.uniform(s[5], *log_zoom_range))
            stretch = np.exp(icdf.uniform(s[6], *log_stretch_range))
            zoom_x = zoom * stretch
            zoom_y = zoom / stretch
        elif allow_stretch is True:  # avoid bugs, f.e. when it is an integer
            zoom_x = np.exp(icdf.uniform(s[5], *log_zoom_range))
            zoom_y = np.exp(icdf.uniform(s[6], *log_zoom_range))
        else:
            zoom_x = zoom_y = np.exp(icdf.uniform(s[5], *log_zoom_range))
        # the range should be multiplicatively symmetric, so [1/1.1, 1.1] instead of [0.9, 1.1] makes more sense.

        tfs.append(data.build_augmentation_transform((zoom_x, zoom_y), rotation, shear, translation, flip))

    return tfs
Exemplo n.º 3
0
def build_quasirandom_transforms(num_transforms,
                                 color_sigma,
                                 zoom_range,
                                 rotation_range,
                                 shear_range,
                                 translation_range,
                                 do_flip=True,
                                 allow_stretch=False,
                                 skip=0):
    gen = ghalton.Halton(10)
    uniform_samples = np.array(gen.get(num_transforms + skip))[skip:]

    tfs = []
    for s in uniform_samples:
        rotation = uniform(s[0], *rotation_range)
        shift_x = uniform(s[1], *translation_range)
        shift_y = uniform(s[2], *translation_range)
        translation = (shift_x, shift_y)

        # setting shear last because we're not using it at the moment
        shear = uniform(s[9], *shear_range)

        if do_flip:
            flip = bernoulli(s[8], p=0.5)
        else:
            flip = False

        log_zoom_range = [np.log(z) for z in zoom_range]
        if isinstance(allow_stretch, float):
            log_stretch_range = [-np.log(allow_stretch), np.log(allow_stretch)]
            zoom = np.exp(uniform(s[6], *log_zoom_range))
            stretch = np.exp(uniform(s[7], *log_stretch_range))
            zoom_x = zoom * stretch
            zoom_y = zoom / stretch
        elif allow_stretch is True:  # avoid bugs, f.e. when it is an integer
            zoom_x = np.exp(uniform(s[6], *log_zoom_range))
            zoom_y = np.exp(uniform(s[7], *log_zoom_range))
        else:
            zoom_x = zoom_y = np.exp(uniform(s[6], *log_zoom_range))
        # the range should be multiplicatively symmetric, so [1/1.1, 1.1] instead of [0.9, 1.1] makes more sense.

        tfs.append(
            data.build_augmentation_transform((zoom_x, zoom_y), rotation,
                                              shear, translation, flip))

    color_vecs = [
        normal(s[3:6], avg=0.0, std=color_sigma) for s in uniform_samples
    ]

    return tfs, color_vecs
Exemplo n.º 4
0
def build_quasirandom_transforms(
    num_transforms,
    color_sigma,
    zoom_range,
    rotation_range,
    shear_range,
    translation_range,
    do_flip=True,
    allow_stretch=False,
    skip=0,
):
    gen = ghalton.Halton(10)
    uniform_samples = np.array(gen.get(num_transforms + skip))[skip:]

    tfs = []
    for s in uniform_samples:
        rotation = uniform(s[0], *rotation_range)
        shift_x = uniform(s[1], *translation_range)
        shift_y = uniform(s[2], *translation_range)
        translation = (shift_x, shift_y)

        # setting shear last because we're not using it at the moment
        shear = uniform(s[9], *shear_range)

        if do_flip:
            flip = bernoulli(s[8], p=0.5)
        else:
            flip = False

        log_zoom_range = [np.log(z) for z in zoom_range]
        if isinstance(allow_stretch, float):
            log_stretch_range = [-np.log(allow_stretch), np.log(allow_stretch)]
            zoom = np.exp(uniform(s[6], *log_zoom_range))
            stretch = np.exp(uniform(s[7], *log_stretch_range))
            zoom_x = zoom * stretch
            zoom_y = zoom / stretch
        elif allow_stretch is True:  # avoid bugs, f.e. when it is an integer
            zoom_x = np.exp(uniform(s[6], *log_zoom_range))
            zoom_y = np.exp(uniform(s[7], *log_zoom_range))
        else:
            zoom_x = zoom_y = np.exp(uniform(s[6], *log_zoom_range))
        # the range should be multiplicatively symmetric, so [1/1.1, 1.1] instead of [0.9, 1.1] makes more sense.

        tfs.append(data.build_augmentation_transform((zoom_x, zoom_y), rotation, shear, translation, flip))

    color_vecs = [normal(s[3:6], avg=0.0, std=color_sigma) for s in uniform_samples]

    return tfs, color_vecs
def build_transforms(**kwargs):
    """
    kwargs are lists of possible values.
    e.g.: build_transforms(rotation=[0, 90, 180, 270], flip=[True, False])

    the names of the arguments are the same as for data.build_augmentation_transform.
    """
    transforms = []

    k = kwargs.keys()
    combinations = list(itertools.product(*kwargs.values()))
    combinations = [dict(zip(k, vals)) for vals in combinations]

    for comb in combinations:
        tf = data.build_augmentation_transform(**comb)
        transforms.append(tf)

    return transforms
Exemplo n.º 6
0
def build_transforms(**kwargs):
    """
    kwargs are lists of possible values.
    e.g.: build_transforms(rotation=[0, 90, 180, 270], flip=[True, False])

    the names of the arguments are the same as for data.build_augmentation_transform.
    """
    transforms = []

    k = kwargs.keys()
    combinations = list(itertools.product(*kwargs.values()))
    combinations = [dict(zip(k, vals)) for vals in combinations]

    for comb in combinations:
        tf = data.build_augmentation_transform(**comb)
        transforms.append(tf)

    return transforms
Exemplo n.º 7
0
def tf2(img):
    tf = tf1(img)
    tf_center, tf_uncenter = data.build_center_uncenter_transforms(img.shape)
    tf_rot = data.build_augmentation_transform(rotation=45)
    tf_rot = tf_uncenter + tf_rot + tf_center
    return tf + tf_rot
Exemplo n.º 8
0
def tf2(img):
    tf = tf1(img)
    tf_center, tf_uncenter = data.build_center_uncenter_transforms(img.shape)
    tf_rot = data.build_augmentation_transform(rotation=45)
    tf_rot = tf_uncenter + tf_rot + tf_center
    return tf + tf_rot