在Tensorflow中,有一个处理图像的函数random_channel_shift。其源代码如下:
def random_channel_shift(x, intensity_range, channel_axis=0):
"""Performs a random channel shift.
# Arguments
x: Input tensor. Must be 3D.
intensity_range: Transformation intensity.
channel_axis: Index of axis for channels in the input tensor.
# Returns
Numpy image tensor.
"""
intensity = np.random.uniform(-intensity_range, intensity_range)
return apply_channel_shift(x, intensity, channel_axis=channel_axis)
代码非常简单,就是生成以一个随机数(注意是一个随机数),然后调用apply_channel_shift。我的理解是应该针对图像的每一个对应元素生成一个随机数,而不是用一个相当于固定数的随机数去处理。在网络上有写好的random_channel_shift:
def random_channel_shift(x, intensity