Files
FastDeploy/examples/vision/generation/anemigan/cpp
chenjian 87bcb5df21 [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>
2023-01-03 10:47:08 +08:00
..

AnimeGAN C++部署示例

本目录下提供infer.cc快速完成AnimeGAN在CPU/GPU部署的示例。

在部署前,需确认以下两个步骤

以Linux上AnimeGAN推理为例在本目录执行如下命令即可完成编译测试支持此模型需保证FastDeploy版本1.0.2以上(x.x.x>=1.0.2)

mkdir build
cd build
# 下载FastDeploy预编译库用户可在上文提到的`FastDeploy预编译库`中自行选择合适的版本使用
wget https://bj.bcebos.com/fastdeploy/release/cpp/fastdeploy-linux-x64-x.x.x.tgz
tar xvf fastdeploy-linux-x64-x.x.x.tgz
cmake .. -DFASTDEPLOY_INSTALL_DIR=${PWD}/fastdeploy-linux-x64-x.x.x
make -j

# 下载准备好的模型文件和测试图片
wget https://bj.bcebos.com/paddlehub/fastdeploy/style_transfer_testimg.jpg
wget https://bj.bcebos.com/paddlehub/fastdeploy/animegan_v1_hayao_60_v1.0.0.tgz
tar xvfz animegan_v1_hayao_60_v1.0.0.tgz

# CPU推理
./infer_demo --model animegan_v1_hayao_60 --image style_transfer_testimg.jpg  --device cpu
# GPU推理
./infer_demo --model animegan_v1_hayao_60 --image style_transfer_testimg.jpg  --device gpu

以上命令只适用于Linux或MacOS, Windows下SDK的使用方式请参考:

AnimeGAN C++接口

AnimeGAN类

fastdeploy::vision::generation::AnimeGAN(
        const string& model_file,
        const string& params_file = "",
        const RuntimeOption& runtime_option = RuntimeOption(),
        const ModelFormat& model_format = ModelFormat::PADDLE)

AnimeGAN模型加载和初始化其中model_file为导出的Paddle模型结构文件params_file为模型参数文件。

参数

  • model_file(str): 模型文件路径
  • params_file(str): 参数文件路径
  • runtime_option(RuntimeOption): 后端推理配置默认为None即采用默认配置
  • model_format(ModelFormat): 模型格式默认为Paddle格式

Predict函数

bool AnimeGAN::Predict(cv::Mat& image, cv::Mat* result)

模型预测入口,输入图像输出风格迁移后的结果。

参数

  • image: 输入数据注意需为HWCBGR格式
  • result: 风格转换后的图像BGR格式

BatchPredict函数

bool AnimeGAN::BatchPredict(const std::vector<cv::Mat>& images, std::vector<cv::Mat>* results);

模型预测入口,输入一组图像并输出风格迁移后的结果。

参数

  • images: 输入数据一组图像数据注意需为HWCBGR格式
  • results: 风格转换后的一组图像BGR格式