[Model] add style transfer model (#922)

* add style transfer model

* add examples for generation model

* add unit test

* add speed comparison

* add speed comparison

* add variable for constant

* add preprocessor and postprocessor

* add preprocessor and postprocessor

* fix

* fix according to review

Co-authored-by: DefTruth <31974251+DefTruth@users.noreply.github.com>
This commit is contained in:
chenjian
2023-01-03 10:47:08 +08:00
committed by GitHub
parent f72846c717
commit 87bcb5df21
23 changed files with 966 additions and 1 deletions

View File

@@ -0,0 +1,43 @@
import cv2
import os
import fastdeploy as fd
def parse_arguments():
import argparse
import ast
parser = argparse.ArgumentParser()
parser.add_argument("--model", required=True, help="Name of the model.")
parser.add_argument(
"--image", type=str, required=True, help="Path of test image file.")
parser.add_argument(
"--device",
type=str,
default='cpu',
help="Type of inference device, support 'cpu' or 'gpu'.")
return parser.parse_args()
def build_option(args):
option = fd.RuntimeOption()
if args.device.lower() == "gpu":
option.use_gpu()
else:
option.set_paddle_mkldnn(False)
return option
args = parse_arguments()
# 配置runtime加载模型
runtime_option = build_option(args)
fd.download_model(name=args.model, path='./', format='paddle')
model_file = os.path.join(args.model, "model.pdmodel")
params_file = os.path.join(args.model, "model.pdiparams")
model = fd.vision.generation.AnimeGAN(
model_file, params_file, runtime_option=runtime_option)
# 预测图片并保存结果
im = cv2.imread(args.image)
result = model.predict(im)
cv2.imwrite('style_transfer_result.png', result)