From bdb0eead2b8233757a0bedbb8517b2f7432dbee5 Mon Sep 17 00:00:00 2001 From: LielinJiang <50691816+LielinJiang@users.noreply.github.com> Date: Mon, 6 Jun 2022 16:17:57 +0800 Subject: [PATCH] rm fluid api (#641) --- .../models/generators/generator_firstorder.py | 2 +- ppgan/models/starganv2_model.py | 1 - ppgan/models/wav2lip_hq_model.py | 6 ++---- ppgan/modules/first_order.py | 5 +++-- tools/fom_infer.py | 19 +++++++++---------- 5 files changed, 15 insertions(+), 18 deletions(-) diff --git a/ppgan/models/generators/generator_firstorder.py b/ppgan/models/generators/generator_firstorder.py index 72d1b2c..61f488b 100755 --- a/ppgan/models/generators/generator_firstorder.py +++ b/ppgan/models/generators/generator_firstorder.py @@ -251,7 +251,7 @@ class Transform: theta_part_a = theta[:, :, :, :2] theta_part_b = theta[:, :, :, 2:] - transformed = paddle.fluid.layers.matmul( + transformed = paddle.matmul( *broadcast(theta_part_a, coordinates)) + theta_part_b #M*p + m0 transformed = transformed.squeeze(-1) if self.tps: diff --git a/ppgan/models/starganv2_model.py b/ppgan/models/starganv2_model.py index f7d5e5e..3203264 100755 --- a/ppgan/models/starganv2_model.py +++ b/ppgan/models/starganv2_model.py @@ -2,7 +2,6 @@ # Users should be careful about adopting these functions in any commercial matters. # https://github.com/clovaai/stargan-v2#license -from paddle.fluid.layers.nn import soft_relu from .base_model import BaseModel from paddle import nn diff --git a/ppgan/models/wav2lip_hq_model.py b/ppgan/models/wav2lip_hq_model.py index 034e81f..5661b44 100644 --- a/ppgan/models/wav2lip_hq_model.py +++ b/ppgan/models/wav2lip_hq_model.py @@ -103,8 +103,7 @@ class Wav2LipModelHq(BaseModel): self.l1_loss = self.recon_loss(self.g, self.y) if self.disc_wt > 0.: - if isinstance(self.nets['netDH'], paddle.DataParallel - ): #paddle.fluid.dygraph.parallel.DataParallel) + if isinstance(self.nets['netDH'], paddle.DataParallel): self.perceptual_loss = self.nets[ 'netDH']._layers.perceptual_forward(self.g) else: @@ -175,8 +174,7 @@ class Wav2LipModelHq(BaseModel): self.eval_recon_losses.append(l1loss.numpy().item()) if self.disc_wt > 0.: - if isinstance(self.nets['netDH'], paddle.DataParallel - ): #paddle.fluid.dygraph.parallel.DataParallel) + if isinstance(self.nets['netDH'], paddle.DataParallel): perceptual_loss = self.nets[ 'netDH']._layers.perceptual_forward( self.g).numpy().item() diff --git a/ppgan/modules/first_order.py b/ppgan/modules/first_order.py index b6b113b..bf9bb90 100644 --- a/ppgan/modules/first_order.py +++ b/ppgan/modules/first_order.py @@ -468,7 +468,8 @@ class AntiAliasInterpolation2d(nn.Layer): inv_scale = 1 / self.scale int_inv_scale = int(inv_scale) assert (inv_scale == int_inv_scale) - #out = out[:, :, ::int_inv_scale, ::int_inv_scale] + # lite: fluid resize_nearest + # out = paddle.fluid.layers.resize_nearest(out, scale=self.scale) + out = out[:, :, ::int_inv_scale, ::int_inv_scale] # patch end - out = paddle.fluid.layers.resize_nearest(out, scale=self.scale) return out diff --git a/tools/fom_infer.py b/tools/fom_infer.py index e664ec3..6ad7d4e 100644 --- a/tools/fom_infer.py +++ b/tools/fom_infer.py @@ -5,7 +5,6 @@ import cv2 import imageio import time from tqdm import tqdm -import paddle.fluid as fluid import os from functools import reduce import paddle @@ -99,11 +98,11 @@ def main(): driving_paths = [driving_path] # 创建 config - kp_detector_config = paddle_infer.Config(os.path.join( - args.model_path, "kp_detector.pdmodel"), + kp_detector_config = paddle_infer.Config( + os.path.join(args.model_path, "kp_detector.pdmodel"), os.path.join(args.model_path, "kp_detector.pdiparams")) - generator_config = paddle_infer.Config(os.path.join( - args.model_path, "generator.pdmodel"), + generator_config = paddle_infer.Config( + os.path.join(args.model_path, "generator.pdmodel"), os.path.join(args.model_path, "generator.pdiparams")) if args.device == "gpu": kp_detector_config.enable_use_gpu(100, 0) @@ -194,11 +193,12 @@ def main(): generator_output_handle = generator_predictor.get_output_handle( generator_output_names[0]) output_data = generator_output_handle.copy_to_cpu() - loss = paddle.abs(paddle.to_tensor(output_data) - - paddle.to_tensor(driving_video[i])).mean().cpu().numpy() + loss = paddle.abs( + paddle.to_tensor(output_data) - + paddle.to_tensor(driving_video[i])).mean().cpu().numpy() test_loss.append(loss) output_data = np.transpose(output_data, [0, 2, 3, 1])[0] * 255.0 - + #Todo:add blazeface static model #frame = source_img.copy() #frame[left:right, up:bottom] = cv2.resize(output_data.astype(np.uint8), (bottom - up, right - left), cv2.INTER_AREA) @@ -210,8 +210,7 @@ def main(): fps=fps) metric_file = os.path.join(args.output_path, "metric.txt") log_file = open(metric_file, 'a') - loss_string = "Metric {}: {:.4f}".format( - "l1 loss", np.mean(test_loss)) + loss_string = "Metric {}: {:.4f}".format("l1 loss", np.mean(test_loss)) log_file.close() -- GitLab