-
Notifications
You must be signed in to change notification settings - Fork 783
GFPGAN Speed UP PR #473
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
wangzijian1010
wants to merge
30
commits into
xlite-dev:main
Choose a base branch
from
wangzijian1010:start_0601
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
GFPGAN Speed UP PR #473
Changes from 5 commits
Commits
Show all changes
30 commits
Select commit
Hold shift + click to select a range
e4db511
perf(trt): GPU-fuse face-restoration paste_back (39ms->2.4ms) + bench…
wangzijian1010 421c054
perf(trt): cache static mask + GPU-fuse face-restoration preprocess (…
wangzijian1010 7c122bb
docs(readme): add Benchmark section for the GPU-optimized face-restor…
wangzijian1010 965e37b
docs(readme): reframe Benchmark as a pipeline-wide GPU-optimization e…
wangzijian1010 deb9f94
docs(readme): make Benchmark a flat per-algorithm table
wangzijian1010 68c2cd5
Update README.md
DefTruth e07415c
refactor: drop MNN/NCNN/TNN backends, keep ORT (reference) + TRT (pro…
wangzijian1010 fadba05
docs(readme): reframe around extreme-GPU-inference + FaceFusion flagship
wangzijian1010 24f8efe
feat(facefusion): out-of-box CLI runner + quickstart for the flagship…
wangzijian1010 0014e40
fix(facefusion): fail fast with clear errors instead of segfaulting
wangzijian1010 e590a7b
feat(facefusion): per-stage pipeline profiling + whole-pipeline bench…
wangzijian1010 eca2d23
fix(trt): stop unbounded GPU/host memory growth in the facefusion pip…
wangzijian1010 159eac6
feat(facefusion): in-memory Mat-in/Mat-out pipeline API + compute-onl…
wangzijian1010 83c7acc
perf(trt): GPU-fuse the face-swap paste-back (swap 16.9 -> 9.4ms)
wangzijian1010 7603793
perf(trt): GPU-fuse the face-detect (yoloface) preprocess (detect 9.6…
wangzijian1010 15aa2ca
tools: mixed-precision GFPGAN FP16 engine builder for TRT 10.1
wangzijian1010 8acca60
fix(trt): isolate ROI in yoloface letterbox padding (BORDER_ISOLATED)
wangzijian1010 1090755
perf/cleanup(trt): hoist per-frame constants out of the face-swap hot…
wangzijian1010 5885953
feat(facefusion): split pipeline into prepare_source() + process() (s…
wangzijian1010 d535d8a
perf(trt): fold restoration postprocess RGB->BGR + uint8->float into …
wangzijian1010 75ec4de
perf(trt): GPU-resident NPP warp for face-restoration preprocess (dev…
wangzijian1010 c842356
perf(facefusion): ship mixed-precision GFPGAN by default (clean FP16,…
wangzijian1010 6af7f38
perf(trt): DeviceFrame brick 1 — restoration uploads input frame once…
wangzijian1010 dc44469
perf(trt): DeviceFrame brick 2 — fold restoration's blend_frame into …
wangzijian1010 f5d50d9
perf(trt): DeviceFrame brick 3 — weld the swap->restoration seam (no …
wangzijian1010 dc2a4a5
perf(trt): DeviceFrame brick 4 — restoration crop stays on device (po…
wangzijian1010 ab10242
perf(trt): DeviceFrame brick 5 — swap input device-resident via one s…
wangzijian1010 23c4932
Update README.md
DefTruth a9495d6
docs: reframe README/quickstart around the device-resident pipeline +…
wangzijian1010 2019bd6
Update README.md
DefTruth File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,110 @@ | ||
| // | ||
| // End-to-end benchmark for the GFPGAN face-restoration stage (Phase 0). | ||
| // Usage: | ||
| // lite_face_restoration_bench [engine_path] [test_img] [iters] [warmup] [csv] | ||
| // Defaults point at a gfpgan engine + a test image on the remote 4090; override via argv. | ||
| // | ||
| // It first runs a CPU-vs-GPU paste_back equivalence check, then a compute-only | ||
| // latency/throughput benchmark of restore() with per-stage aggregation | ||
| // (preprocess / infer / postprocess / paste_back). Disk I/O (imwrite) is kept | ||
| // out of the timed loop; one result image is saved afterwards for visual checking. | ||
| // | ||
| #include "lite/lite.h" | ||
| #include "lite/bench/profiler.h" | ||
|
|
||
| #ifdef ENABLE_TENSORRT | ||
| #include "lite/trt/cv/trt_face_restoration.h" | ||
| #include "lite/ort/cv/face_utils.h" | ||
| #include "lite/trt/kernel/paste_back_manager.h" | ||
|
|
||
| // A/B numerical check: per-pixel difference between the GPU fused paste_back and the | ||
| // CPU reference, on the same real inputs (real affine + real crop). | ||
| static void check_paste_back_equivalence(const cv::Mat &frame, | ||
| std::vector<cv::Point2f> &lmk5) { | ||
| // Run the real warp to obtain the real affine + real 512 crop (uint8), then to float (as in the pipeline) | ||
| cv::Mat crop_u8, affine; | ||
| std::tie(crop_u8, affine) = | ||
| face_utils::warp_face_by_face_landmark_5(frame, lmk5, face_utils::FFHQ_512); | ||
| cv::Mat crop_f; | ||
| crop_u8.convertTo(crop_f, CV_32FC3); | ||
| cv::Mat mask = face_utils::create_static_box_mask({512, 512}); | ||
|
|
||
| cv::Mat out_cpu = launch_paste_back(frame, crop_f, mask, affine); | ||
| PasteBackGPU gpu; | ||
| cv::Mat out_gpu = gpu.paste_back(frame, crop_f, mask, affine, nullptr); | ||
|
|
||
| cv::Mat diff; | ||
| cv::absdiff(out_cpu, out_gpu, diff); | ||
| cv::Scalar mean_diff = cv::mean(diff); | ||
| double max_diff = 0.0; | ||
| cv::minMaxLoc(diff.reshape(1), nullptr, &max_diff); | ||
| std::cout << "[check] paste_back CPU vs GPU max|diff|=" << max_diff | ||
| << " mean|diff|(B,G,R)=" << mean_diff[0] << "," << mean_diff[1] | ||
| << "," << mean_diff[2] << " (uint8 pixel values, smaller = closer)" << std::endl; | ||
| } | ||
| #endif | ||
|
|
||
| int main(__unused int argc, __unused char *argv[]) { | ||
| #ifdef ENABLE_TENSORRT | ||
| std::string engine_path = | ||
| argc > 1 ? argv[1] : "/root/autodl-tmp/gfpgan_proj/gfpgan_fp32.engine"; | ||
| std::string test_img_path = | ||
| argc > 2 ? argv[2] : "../../../examples/lite/resources/test_lite_face_restoration.jpg"; | ||
| int iters = argc > 3 ? std::atoi(argv[3]) : 50; | ||
| int warmup = argc > 4 ? std::atoi(argv[4]) : 10; | ||
| std::string csv_path = argc > 5 ? argv[5] : "bench_face_restoration.csv"; | ||
|
|
||
| // Fixed 5-point landmarks (same as test_lite_face_restoration.cpp); the benchmark only | ||
| // cares about timing, so whether they exactly match the image does not affect the numbers. | ||
| std::vector<cv::Point2f> face_landmark_5 = { | ||
| cv::Point2f(569.092041f, 398.845886f), | ||
| cv::Point2f(701.891724f, 399.156677f), | ||
| cv::Point2f(634.767212f, 482.927216f), | ||
| cv::Point2f(584.270996f, 543.294617f), | ||
| cv::Point2f(684.877991f, 543.067078f)}; | ||
|
|
||
| cv::Mat img_bgr = cv::imread(test_img_path); | ||
| if (img_bgr.empty()) { | ||
| std::cerr << "[bench] cannot read test image: " << test_img_path << std::endl; | ||
| return 1; | ||
| } | ||
|
|
||
| std::cout << "[bench] engine=" << engine_path << "\n[bench] img=" | ||
| << test_img_path << " (" << img_bgr.cols << "x" << img_bgr.rows | ||
| << ")\n[bench] warmup=" << warmup << " iters=" << iters << std::endl; | ||
|
|
||
| // Numerical correctness check (CPU vs GPU paste_back) before benchmarking | ||
| check_paste_back_equivalence(img_bgr, face_landmark_5); | ||
|
|
||
| trtcv::TRTFaceFusionFaceRestoration restorer(engine_path); | ||
| const std::string tmp_out = "/tmp/bench_restoration_out.jpg"; | ||
|
|
||
| // Warmup (first runs include lazy engine/context init and cudnn autotune; excluded from stats) | ||
| for (int i = 0; i < warmup; ++i) { | ||
| restorer.restore(img_bgr, face_landmark_5, nullptr); | ||
| } | ||
|
|
||
| // Timed: restore() does not write to disk; the profiler collects per-stage timings | ||
| // (preprocess/infer/postprocess/paste_back) and the end-to-end TOTAL. imwrite is moved | ||
| // out of the loop; one image is saved at the end for visual verification. | ||
| lite::bench::Profiler prof; | ||
| cv::Mat dst; | ||
| for (int i = 0; i < iters; ++i) { | ||
| lite::bench::CpuTimer t; | ||
| t.start(); | ||
| dst = restorer.restore(img_bgr, face_landmark_5, &prof); | ||
| prof.tick(t.stop_ms()); | ||
| } | ||
|
|
||
| prof.report("GFPGAN face restoration (compute-only, no disk I/O)"); | ||
| prof.to_csv(csv_path); | ||
|
|
||
| if (!dst.empty()) { | ||
| cv::imwrite(tmp_out, dst); | ||
| std::cout << "[bench] sample result (saved once, outside the loop): " << tmp_out << std::endl; | ||
| } | ||
| #else | ||
| std::cerr << "This benchmark requires ENABLE_TENSORRT=ON." << std::endl; | ||
| #endif | ||
| return 0; | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
benchmark部分建议使用最新的tensorrt,以及cuda 13+