我使用Keras数据增强来进行图像分类。我想为width_shift_range和height_shift_range指定多个值。例如,我希望在一次培训中使用移位范围(如0.2、0.4、0.6 )的倍数值来增强图像。有没有办法这么做。
提前感谢您的帮助。
发布于 2018-03-01 16:26:09
您不需要为width_shift_range
指定多个值(resp )。height_shift_range
)。它基本上是从区间x
中的均匀分布中画出一个随机数[-width_shift_range, width_shift_range]
(resp )。[-height_shift_range, height_shift_range]
),并应用与x
成比例的位移乘以相应的图像宽度的图像的平移(resp )。高度)。
这是来自random_shift
的角化函数
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
结论:取最大值,因为你要画出区间-x,x,id,如果你想要变化在0.2,0.4和0.6之间,只需使用0.6。
https://stackoverflow.com/questions/49047861
复制相似问题