图像背后的理论减去 0.5 然后乘以 2


with tf.name_scope(scope, 'eval_image', [image, height, width]):
if image.dtype != tf.float32:
image = tf.image.convert_image_dtype(image, dtype=tf.float32)
if height and width:
# Resize the image to the specified height and width.
image = tf.expand_dims(image, 0)
image = tf.image.resize_bilinear(image, [height, width],
align_corners=False)
image = tf.squeeze(image, [0])
image = tf.subtract(image, 0.5)
image = tf.multiply(image, 2.0)
return image

当我们在将图像发送到神经网络(更具体地说,GoogLeNet(之前进行图像预处理时,他们为什么要编写代码:

image = tf.subtract(image, 0.5)
image = tf.multiply(image, 2.0)

这背后的理论是什么?为什么我们需要这个程序。 如果我尝试检查它的外观,请使用:

plt.imshow(image)

图像无法显示。

他们这样做是为了将图像从 [0,1] 重新缩放到 [-1,1]。他们希望所有图像都采用相同的格式,因此他们需要此步骤。

减法和乘法是为了在 -1 和 1 之间缩放图像。

相关内容

最新更新