Keras图像增强 - 为图像宽度/高度偏移范围指定多个值

问题描述 投票:0回答:1

我正在使用Keras数据增强进行图像分类。我想为width_shift_range和height_shift_range指定多个值。例如,我想在一个训练课程中增加具有移位范围的倍数值的图像,例如0.2,0.4,0.6。有没有办法做到这一点。

在此先感谢您的帮助。

deep-learning keras
1个回答
2
投票

您不需要为width_shift_range(resp.height_shift_range)指定多个值。它基本上做的是它从区间x(resp.[-width_shift_range, width_shift_range])中的均匀分布中绘制随机数[-height_shift_range, height_shift_range],并应用与x成比例的相移图像的平移乘以相应的图像宽度(相应的高度)。

这是来自random_shiftkeras函数:

def random_shift(x, wrg, hrg, row_axis=1, col_axis=2, channel_axis=0,
                 fill_mode='nearest', cval=0.):

    # wrg: Width shift range, as a float fraction of the width.
    # hrg: Height shift range, as a float fraction of the height.

    h, w = x.shape[row_axis], x.shape[col_axis]
    tx = np.random.uniform(-hrg, hrg) * h
    ty = np.random.uniform(-wrg, wrg) * w
    translation_matrix = np.array([[1, 0, tx],
                                   [0, 1, ty],
                                   [0, 0, 1]])

    transform_matrix = translation_matrix  # no need to do offset
    x = apply_transform(x, transform_matrix, channel_axis, fill_mode, cval)
    return x

结论:如果你想要在0.2,0.4和0.6范围转换之间变换,你只需要使用0.6,你可以在区间[-x,x],id est中绘制最大值。

© www.soinside.com 2019 - 2024. All rights reserved.