DeepLearningwithPython icon indicating copy to clipboard operation
DeepLearningwithPython copied to clipboard

為何要對圖形中 0-255 的灰階像素值做 normalization (將灰階值數值範圍縮減到 [0 - 1])?

Open renewang opened this issue 7 years ago • 1 comments

9/22 第二次讀書會(Chapter 2)現場提問

"A First Look at a Neural Network" note book 中,為何要將所有的灰階像素除以 255?(code example 如下)?

train_images = train_images.reshape((60000, 28 * 28))
train_images = train_images.astype('float32') / 255

test_images = test_images.reshape((10000, 28 * 28))
test_images = test_images.astype('float32') / 255

renewang avatar Sep 28 '18 06:09 renewang

因为matplotlib的imshow函数, image 根本imshow函数文档,当你的图片矩阵类型是unit8的时候,像素范围是0-255,但是你读取图片是以double类型的话,当大于1时就会被显示成白色,不能有效表达图片信息,这是因为imshow()显示图像时对double型是认为在0~1范围内。 The RGB(A) values should be in the range [0 .. 1] for floats or [0 .. 255] for integers.

thouger avatar Oct 24 '18 08:10 thouger