From 5748b68e6ae6eb12092d194d85600335624c507f Mon Sep 17 00:00:00 2001 From: wangna11BD <79366697+wangna11BD@users.noreply.github.com> Date: Wed, 11 Aug 2021 20:18:40 +0800 Subject: [PATCH] add resize in lapstyle predictor (#391) --- ppgan/apps/lapstyle_predictor.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/ppgan/apps/lapstyle_predictor.py b/ppgan/apps/lapstyle_predictor.py index 5ea8cd4..828f752 100644 --- a/ppgan/apps/lapstyle_predictor.py +++ b/ppgan/apps/lapstyle_predictor.py @@ -51,6 +51,7 @@ def img_read(content_img_path, style_image_path): content_img = cv.cvtColor(content_img, cv.COLOR_GRAY2RGB) else: content_img = cv.cvtColor(content_img, cv.COLOR_BGR2RGB) + h, w, c = content_img.shape content_img = Image.fromarray(content_img) content_img = content_img.resize((512, 512), Image.BILINEAR) content_img = np.array(content_img) @@ -67,7 +68,7 @@ def img_read(content_img_path, style_image_path): content_img = paddle.unsqueeze(content_img, axis=0) style_img = paddle.unsqueeze(style_img, axis=0) - return content_img, style_img + return content_img, style_img, h, w def tensor_resample(tensor, dst_size, mode='bilinear'): @@ -161,8 +162,8 @@ class LapStylePredictor(BasePredictor): self.net_rev_2.eval() def run(self, content_img_path): - content_img, style_img = img_read(content_img_path, - self.style_image_path) + content_img, style_img, h, w = img_read(content_img_path, + self.style_image_path) content_img_visual = tensor2img(content_img, min_max=(0., 1.)) content_img_visual = cv.cvtColor(content_img_visual, cv.COLOR_RGB2BGR) cv.imwrite(os.path.join(self.output, 'content.png'), content_img_visual) @@ -197,6 +198,7 @@ class LapStylePredictor(BasePredictor): stylized = stylized_rev_second stylized_visual = tensor2img(stylized, min_max=(0., 1.)) stylized_visual = cv.cvtColor(stylized_visual, cv.COLOR_RGB2BGR) + stylized_visual = cv.resize(stylized_visual, (w, h)) cv.imwrite(os.path.join(self.output, 'stylized.png'), stylized_visual) print('Model LapStyle output images path:', self.output) -- GitLab