diff --git a/examples/multimodal/stable_diffusion/cpp/README.md b/examples/multimodal/stable_diffusion/cpp/README.md index 880315744..06d085feb 100644 --- a/examples/multimodal/stable_diffusion/cpp/README.md +++ b/examples/multimodal/stable_diffusion/cpp/README.md @@ -1 +1,12 @@ # StableDiffusion C++部署示例 + +在部署前,需确认以下两个步骤 + +- 1. 软硬件环境满足要求,参考[FastDeploy环境要求](../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) +- 2. 根据开发环境,下载预编译部署库和samples代码,参考[FastDeploy预编译库](../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) + +本目录下提供`*_infer.cc`快速完成StableDiffusion各任务的C++部署示例。 + +## Inpaint任务 + +StableDiffusion Inpaint任务是一个根据提示文本补全图片的任务,具体而言就是用户给定提示文本,原始图片以及原始图片的mask图片,该任务输出补全后的图片。 diff --git a/examples/multimodal/stable_diffusion/cpp/main.cc b/examples/multimodal/stable_diffusion/cpp/main.cc index 5f0e4d5d6..9036df935 100644 --- a/examples/multimodal/stable_diffusion/cpp/main.cc +++ b/examples/multimodal/stable_diffusion/cpp/main.cc @@ -12,12 +12,12 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "dpm_solver_multistep_scheduler.h" +#include "./dpm_solver_multistep_scheduler.h" +#include "./pipeline_stable_diffusion_inpaint.h" #include "fastdeploy/utils/perf.h" #include "fastdeploy/vision/common/processors/mat.h" #include "opencv2/highgui/highgui.hpp" #include "opencv2/imgproc/imgproc.hpp" -#include "pipeline_stable_diffusion_inpaint.h" #include #include #include @@ -68,7 +68,7 @@ std::unique_ptr CreateRuntime( runtime_option.SetTrtInputShape(it->first, min_shape, opt_shape, max_shape); } - runtime_option.SetTrtCacheFile(""); + runtime_option.SetTrtCacheFile("paddle.trt"); runtime_option.EnablePaddleTrtCollectShape(); runtime_option.DisablePaddleTrtOPs(disable_paddle_trt_ops); if (use_fp16) { @@ -183,9 +183,12 @@ int main() { paddlenlp::fast_tokenizer::tokenizers_impl::ClipFastTokenizer tokenizer( "clip/vocab.json", "clip/merges.txt", /* max_length = */ max_length); fastdeploy::StableDiffusionInpaintPipeline pipe( - std::move(vae_encoder_runtime), std::move(vae_decoder_runtime), - std::move(text_encoder_runtime), std::move(unet_runtime), - /* scheduler = */ std::move(dpm), tokenizer); + /* vae_encoder = */ std::move(vae_encoder_runtime), + /* vae_decoder = */ std::move(vae_decoder_runtime), + /* text_encoder = */ std::move(text_encoder_runtime), + /* unet = */ std::move(unet_runtime), + /* scheduler = */ std::move(dpm), + /* tokenizer = */ tokenizer); // 7. Read images auto image = cv::imread("overture-creations.png"); @@ -197,8 +200,19 @@ int main() { std::vector outputs; fastdeploy::TimeCounter tc; tc.Start(); - pipe.Predict(prompts, image, mask_image, &outputs, /* height = */ 512, - /* width = */ 512, /* num_inference_steps = */ 50); + pipe.Predict(prompts, image, mask_image, &outputs, + /* height = */ 512, + /* width = */ 512, + /* num_inference_steps = */ 50, + /* guidance_scale = */ 7.5, + /* negative_prompt = */ {}, + /* num_images_per_prompt = */ 1, + /* eta = */ 1.0, + /* max_length = */ max_length, + /* latents = */ nullptr, + /* output_cv_mat = */ true, + /* callback = */ nullptr, + /* callback_steps = */ 1); tc.End(); tc.PrintInfo(); fastdeploy::vision::FDMat mat = fastdeploy::vision::FDMat::Create(outputs[0]);