From 1ba879beadc33e84ff3d5c62ee5ac188027d7638 Mon Sep 17 00:00:00 2001 From: wanghaoshuang Date: Wed, 12 Jul 2017 14:38:03 +0800 Subject: [PATCH] Use PIL to read image in palette mode --- python/paddle/v2/dataset/tests/vocseg_test.py | 2 +- python/paddle/v2/dataset/voc_seg.py | 10 +++++++--- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/python/paddle/v2/dataset/tests/vocseg_test.py b/python/paddle/v2/dataset/tests/vocseg_test.py index 1a773fa18b2..8217ff45b13 100644 --- a/python/paddle/v2/dataset/tests/vocseg_test.py +++ b/python/paddle/v2/dataset/tests/vocseg_test.py @@ -21,7 +21,7 @@ class TestVOC(unittest.TestCase): sum = 0 label = 0 for l in reader(): - self.assertEqual(l[0].size, l[1].size) + self.assertEqual(l[0].size, 3 * l[1].size) sum += 1 return sum diff --git a/python/paddle/v2/dataset/voc_seg.py b/python/paddle/v2/dataset/voc_seg.py index 595ab41cd80..0df4423ff04 100644 --- a/python/paddle/v2/dataset/voc_seg.py +++ b/python/paddle/v2/dataset/voc_seg.py @@ -20,14 +20,16 @@ with segmentation has been increased from 7,062 to 9,993. """ import tarfile +import io import numpy as np from common import download from paddle.v2.image import * +from PIL import Image __all__ = ['train', 'test', 'val'] VOC_URL = 'http://host.robots.ox.ac.uk/pascal/VOC/voc2012/\ - VOCtrainval_11-May-2012.tar' +VOCtrainval_11-May-2012.tar' VOC_MD5 = '6cd6e144f989b92b3379bac3b3de84fd' SET_FILE = 'VOCdevkit/VOC2012/ImageSets/Segmentation/{}.txt' @@ -51,8 +53,10 @@ def reader_creator(filename, sub_name): label_file = LABEL_FILE.format(line) data = tarobject.extractfile(name2mem[data_file]).read() label = tarobject.extractfile(name2mem[label_file]).read() - data = load_image_bytes(data) - label = load_image_bytes(label) + data = Image.open(io.BytesIO(data)) + label = Image.open(io.BytesIO(label)) + data = np.array(data) + label = np.array(label) yield data, label return reader -- GitLab