From 0024cfc595183f0ce2065bf26f227b7343eca7c9 Mon Sep 17 00:00:00 2001 From: Teng Xi Date: Wed, 3 Jun 2020 12:55:31 +0800 Subject: [PATCH] adapt PY2 PY3 (#326) --- demo/slimfacenet/dataloader/casia.py | 8 ++++++-- demo/slimfacenet/dataloader/lfw.py | 10 +++++++--- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/demo/slimfacenet/dataloader/casia.py b/demo/slimfacenet/dataloader/casia.py index cbec2a382dce3..064abc6113e6e 100644 --- a/demo/slimfacenet/dataloader/casia.py +++ b/demo/slimfacenet/dataloader/casia.py @@ -13,7 +13,11 @@ # See the License for the specific language governing permissions and # limitations under the License. import numpy as np -import imageio +import six +if six.PY2: + import scipy.misc as imgreader +else: + import imageio as imgreader import os import paddle from paddle import fluid @@ -54,7 +58,7 @@ def reader(self): target = self.label_list[index] try: - img = imageio.imread(img_path) + img = imgreader.imread(img_path) except: continue diff --git a/demo/slimfacenet/dataloader/lfw.py b/demo/slimfacenet/dataloader/lfw.py index 4812ba1a2e37d..e13fd513b9e6e 100644 --- a/demo/slimfacenet/dataloader/lfw.py +++ b/demo/slimfacenet/dataloader/lfw.py @@ -13,7 +13,11 @@ # See the License for the specific language governing permissions and # limitations under the License. import numpy as np -import imageio +import six +if six.PY2: + import scipy.misc as imgreader +else: + import imageio as imgreader import paddle from paddle import fluid @@ -32,10 +36,10 @@ def reader(self): return index = self.shuffle_idx.pop(0) - imgl = imageio.imread(self.imgl_list[index]) + imgl = imgreader.imread(self.imgl_list[index]) if len(imgl.shape) == 2: imgl = np.stack([imgl] * 3, 2) - imgr = imageio.imread(self.imgr_list[index]) + imgr = imgreader.imread(self.imgr_list[index]) if len(imgr.shape) == 2: imgr = np.stack([imgr] * 3, 2)