From a1b9997817494f2d2ac968c066f69ad228ce5f66 Mon Sep 17 00:00:00 2001 From: jingsongliu <45508593+jingsongliujing@users.noreply.github.com> Date: Fri, 14 Oct 2022 17:08:54 +0800 Subject: [PATCH] Update imread() read image way error (#47005) * update test_image.py * update test_image.py --- python/paddle/dataset/image.py | 2 +- python/paddle/dataset/tests/test_image.py | 42 ++++++++++++++--------- 2 files changed, 27 insertions(+), 17 deletions(-) diff --git a/python/paddle/dataset/image.py b/python/paddle/dataset/image.py index f2e993d706..1251b998a0 100644 --- a/python/paddle/dataset/image.py +++ b/python/paddle/dataset/image.py @@ -192,7 +192,7 @@ def load_image(file, is_color=True): # Here, use constant 1 and 0 # 1: COLOR, 0: GRAYSCALE flag = 1 if is_color else 0 - im = cv2.imread(file, flag) + im = cv2.imread(file.encode('utf-8').decode('utf-8'), flag) return im diff --git a/python/paddle/dataset/tests/test_image.py b/python/paddle/dataset/tests/test_image.py index 7b670548b4..61979b865f 100644 --- a/python/paddle/dataset/tests/test_image.py +++ b/python/paddle/dataset/tests/test_image.py @@ -11,35 +11,45 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. - +""" +Fliename: + test_image.py +Description: + This scipt test image resize,flip and chw. +""" + +import sys import unittest import numpy as np - -import paddle.dataset.image as image +from paddle.dataset import image __all__ = [] class Image(unittest.TestCase): + """ + This function is test image resize,flip and chw. + """ def test_resize_flip_chw(self): - # resize - im = image.load_image('cat.jpg') - im = image.resize_short(im, 256) - self.assertEqual(256, min(im.shape[:2])) - self.assertEqual(3, im.shape[2]) + """ resize """ + imgdir = sys.argv[0].replace('test_image.py', 'cat.jpg') + images = image.load_image(imgdir) + images = image.resize_short(images, 256) + self.assertEqual(256, min(images.shape[:2])) + self.assertEqual(3, images.shape[2]) # flip - im = image.left_right_flip(im) - im2 = np.flip(im, 1) - self.assertEqual(im.all(), im2.all()) + images = image.left_right_flip(images) + images2 = np.flip(images, 1) + self.assertEqual(images.all(), images2.all()) # to_chw - h, w, c = im.shape - im = image.to_chw(im) - self.assertEqual(c, im.shape[0]) - self.assertEqual(h, im.shape[1]) - self.assertEqual(w, im.shape[2]) + height, width, channel = images.shape + images = image.to_chw(images) + self.assertEqual(channel, images.shape[0]) + self.assertEqual(height, images.shape[1]) + self.assertEqual(width, images.shape[2]) if __name__ == '__main__': -- GitLab