From 92d65ed48888137c7e7e470fac305c88fe679289 Mon Sep 17 00:00:00 2001 From: qingqing01 Date: Tue, 25 Apr 2017 15:05:34 +0800 Subject: [PATCH] follow comments --- 03.image_classification/README.en.md | 6 ++++++ 03.image_classification/README.md | 4 ++++ 03.image_classification/index.en.html | 6 ++++++ 03.image_classification/index.html | 4 ++++ 03.image_classification/train.py | 6 ++++++ 5 files changed, 26 insertions(+) diff --git a/03.image_classification/README.en.md b/03.image_classification/README.en.md index a39f902..2ff186d 100644 --- a/03.image_classification/README.en.md +++ b/03.image_classification/README.en.md @@ -491,7 +491,13 @@ def load_image(file): im = Image.open(file) im = im.resize((32, 32), Image.ANTIALIAS) im = np.array(im).astype(np.float32) + # The storage order of the loaded image is W(widht), + # H(height), C(channel). PaddlePaddle requires + # the CHW order, so transpose them. im = im.transpose((2, 0, 1)) # CHW + # In the training phase, the channel order of CIFAR + # image is B(Blue), G(green), R(Red). But PIL open + # image in RGB mode. It must swap the channel order. im = im[(2, 1, 0),:,:] # BGR im = im.flatten() im = im / 255.0 diff --git a/03.image_classification/README.md b/03.image_classification/README.md index d476997..ccd0c35 100644 --- a/03.image_classification/README.md +++ b/03.image_classification/README.md @@ -483,7 +483,11 @@ def load_image(file): im = Image.open(file) im = im.resize((32, 32), Image.ANTIALIAS) im = np.array(im).astype(np.float32) + # PIL打开图片存储顺序为H(高度),W(宽度),C(通道)。 + # PaddlePaddle要求数据顺序为CHW,所以需要转换顺序。 im = im.transpose((2, 0, 1)) # CHW + # CIFAR训练图片通道顺序为B(蓝),G(绿),R(红), + # 而PIL打开图片默认通道顺序为RGB,因为需要交换通道。 im = im[(2, 1, 0),:,:] # BGR im = im.flatten() im = im / 255.0 diff --git a/03.image_classification/index.en.html b/03.image_classification/index.en.html index 92c5a53..f20658e 100644 --- a/03.image_classification/index.en.html +++ b/03.image_classification/index.en.html @@ -533,7 +533,13 @@ def load_image(file): im = Image.open(file) im = im.resize((32, 32), Image.ANTIALIAS) im = np.array(im).astype(np.float32) + # The storage order of the loaded image is W(widht), + # H(height), C(channel). PaddlePaddle requires + # the CHW order, so transpose them. im = im.transpose((2, 0, 1)) # CHW + # In the training phase, the channel order of CIFAR + # image is B(Blue), G(green), R(Red). But PIL open + # image in RGB mode. It must swap the channel order. im = im[(2, 1, 0),:,:] # BGR im = im.flatten() im = im / 255.0 diff --git a/03.image_classification/index.html b/03.image_classification/index.html index 4ab00b5..6344f77 100644 --- a/03.image_classification/index.html +++ b/03.image_classification/index.html @@ -525,7 +525,11 @@ def load_image(file): im = Image.open(file) im = im.resize((32, 32), Image.ANTIALIAS) im = np.array(im).astype(np.float32) + # PIL打开图片存储顺序为H(高度),W(宽度),C(通道)。 + # PaddlePaddle要求数据顺序为CHW,所以需要转换顺序。 im = im.transpose((2, 0, 1)) # CHW + # CIFAR训练图片通道顺序为B(蓝),G(绿),R(红), + # 而PIL打开图片默认通道顺序为RGB,因为需要交换通道。 im = im[(2, 1, 0),:,:] # BGR im = im.flatten() im = im / 255.0 diff --git a/03.image_classification/train.py b/03.image_classification/train.py index 4e86b44..b2dc6c9 100644 --- a/03.image_classification/train.py +++ b/03.image_classification/train.py @@ -98,7 +98,13 @@ def main(): im = Image.open(file) im = im.resize((32, 32), Image.ANTIALIAS) im = np.array(im).astype(np.float32) + # The storage order of the loaded image is W(widht), + # H(height), C(channel). PaddlePaddle requires + # the CHW order, so transpose them. im = im.transpose((2, 0, 1)) # CHW + # In the training phase, the channel order of CIFAR + # image is B(Blue), G(green), R(Red). But PIL open + # image in RGB mode. It must swap the channel order. im = im[(2, 1, 0), :, :] # BGR im = im.flatten() im = im / 255.0 -- GitLab