DeepLearningwithPython
DeepLearningwithPython copied to clipboard
為何要對圖形中 0-255 的灰階像素值做 normalization (將灰階值數值範圍縮減到 [0 - 1])?
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
因为matplotlib的imshow函数,
根本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.