diff --git a/03.image_classification/README.en.md b/03.image_classification/README.en.md index a39f9021bcd5e06cbd83fde3fe79ac47344d607e..2ff186d82e92e8a52bf01a85891f25a8dbef1d43 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 d47699765b7a515c1ca30e567d96cdc549a52bf9..ccd0c3509e8ca81498ebaba66e89dcfc685b8070 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 92c5a531b8aff40a2863f1d9f7e90a17d639d1cd..f20658e7ccbdc8e7e290fa937d04ccbedfa9c9c8 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 4ab00b51e7587fd39b664f7c264a9c5edad343f7..6344f774e4cfbd98fb9dd2105e81af2b6dcf7707 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 4e86b445190e977ea24c18056874a24b344d29cb..b2dc6c9108c607ca56bae004e3cf22cc8fcba782 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