-
Notifications
You must be signed in to change notification settings - Fork 729
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
[ORT][TRT] support FaceFusion #445
Merged
Merged
Changes from 28 commits
Commits
Show all changes
55 commits
Select commit
Hold shift + click to select a range
b220b02
face_68landmarks implement.
wangzijian1010 2470295
add face_68landmarks
wangzijian1010 18e1746
face_68landmarks test code
wangzijian1010 bbd5f21
add exec name
wangzijian1010 64b147e
face recognizer code implement
wangzijian1010 58d768e
add face recognizer in models
wangzijian1010 9a16a3b
add test code for face recognizer
wangzijian1010 3f78db1
add test code of face_swap face_restoration and face_fusion_pipeline
wangzijian1010 65a117d
update code
wangzijian1010 3625cbf
update code
wangzijian1010 e3c3e51
face_fusion_pipeline implement
wangzijian1010 c9bf80a
update code
wangzijian1010 6ce44fb
face restoration code implement
wangzijian1010 9139d87
face swap code implement
wangzijian1010 21485ae
add three models
wangzijian1010 6d23780
update opencv.cmake
wangzijian1010 7dc9491
update code
wangzijian1010 4746f46
update code
wangzijian1010 df217f5
add face_restoration test code
wangzijian1010 e919d36
add face_swap test code
wangzijian1010 54b4d55
add face_pipeline test code
wangzijian1010 30147c0
delete useless code
wangzijian1010 906a622
add test example pic
wangzijian1010 8b97c25
rename interface func
wangzijian1010 af8c775
update code
wangzijian1010 7d5dfce
Put all some component functions in the utils file.
wangzijian1010 fc044e6
Clean up duplicate and redundant function implementations and definit…
wangzijian1010 fba2ba0
update code
wangzijian1010 2bc1639
delete redefine func
wangzijian1010 abdc895
clean code
wangzijian1010 6a8fb88
update code
wangzijian1010 f732259
update tensorrt model of facefusion
wangzijian1010 2b080ed
tensorrt facefusion code
wangzijian1010 bd7b240
multi thread facerestoration test
wangzijian1010 02302f4
The implementation and test code of multi-threaded trt_face_restorati…
wangzijian1010 97758d0
init face_68landmarks multi thread code
wangzijian1010 2b14209
update code
wangzijian1010 b6c1214
init face_68landmarks multi thread code and test code
wangzijian1010 466a206
Added support for CUDA #TODO to modify the on switch of Test and the …
wangzijian1010 dd5f8b3
The implementation of the packaging file for the NMS CUDA Version.
wangzijian1010 f594a2f
CUDA NMS Kernel implement
wangzijian1010 d6b1515
Update the CMake file to add CUDA dependencies.
wangzijian1010 ce0a360
Add code to replace the original implementation code of NMS with the …
wangzijian1010 4cb5743
update cmake to add cuda
wangzijian1010 84de52c
update code to use cuda func
wangzijian1010 5941260
warp func of postprocess and cuda code
wangzijian1010 db34f72
update code
wangzijian1010 8d142c7
fix code
wangzijian1010 f839e44
fix code
wangzijian1010 cd3170b
rename TaskName ##TODO rename
wangzijian1010 620ee30
update code
wangzijian1010 bb0f71f
update code
wangzijian1010 8d0292a
face restoration cuda code implement
wangzijian1010 d1151be
face restoration cuda wrapper code implement
wangzijian1010 51d8d2f
face restoration cuda version code
wangzijian1010 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 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 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 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,35 @@ | ||
// | ||
// Created by wangzijian on 11/1/24. | ||
// | ||
#include "lite/lite.h" | ||
|
||
static void test_default() | ||
{ | ||
#ifdef ENABLE_ONNXRUNTIME | ||
std::string onnx_path = "../../../examples/hub/onnx/cv/2dfan4.onnx"; | ||
std::string test_img_path = "../../../examples/lite/resources/test_lite_facefusion_pipeline_source.jpg"; | ||
|
||
// 1. Test Default Engine ONNXRuntime | ||
lite::cv::faceid::Face_68Landmarks *face68Landmarks = new lite::cv::faceid::Face_68Landmarks(onnx_path); | ||
|
||
lite::types::BoundingBoxType<float, float> bbox; | ||
bbox.x1 = 487; | ||
bbox.y1 = 236; | ||
bbox.x2 = 784; | ||
bbox.y2 = 624; | ||
|
||
cv::Mat img_bgr = cv::imread(test_img_path); | ||
std::vector<cv::Point2f> face_landmark_5of68; | ||
face68Landmarks->detect(img_bgr, bbox, face_landmark_5of68); | ||
|
||
std::cout<<"face id detect done!"<<std::endl; | ||
|
||
delete face68Landmarks; | ||
#endif | ||
} | ||
|
||
int main(__unused int argc, __unused char *argv[]) | ||
{ | ||
test_default(); | ||
return 0; | ||
} |
This file contains 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,39 @@ | ||
// | ||
// Created by wangzijian on 11/5/24. | ||
// | ||
#include "lite/lite.h" | ||
|
||
static void test_default() | ||
{ | ||
#ifdef ENABLE_ONNXRUNTIME | ||
std::string onnx_path = "../../../examples/hub/onnx/cv/arcface_w600k_r50.onnx"; | ||
std::string test_img_path = "../../../examples/lite/resources/test_lite_facefusion_pipeline_source.jpg"; | ||
|
||
// 1. Test Default Engine ONNXRuntime | ||
lite::cv::faceid::Face_Recognizer *face_recognizer = new lite::cv::faceid::Face_Recognizer(onnx_path); | ||
|
||
std::vector<cv::Point2f> face_landmark_5 = { | ||
cv::Point2f(568.2485f, 398.9512f), | ||
cv::Point2f(701.7346f, 399.64795f), | ||
cv::Point2f(634.2213f, 482.92694f), | ||
cv::Point2f(583.5656f, 543.10187f), | ||
cv::Point2f(684.52405f, 543.125f) | ||
}; | ||
cv::Mat img_bgr = cv::imread(test_img_path); | ||
|
||
std::vector<float> source_image_embeding; | ||
|
||
face_recognizer->detect(img_bgr,face_landmark_5,source_image_embeding); | ||
|
||
|
||
std::cout<<"face id detect done!"<<std::endl; | ||
|
||
delete face_recognizer; | ||
#endif | ||
} | ||
|
||
int main(__unused int argc, __unused char *argv[]) | ||
{ | ||
test_default(); | ||
return 0; | ||
} |
This file contains 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,38 @@ | ||
// | ||
// Created by wangzijian on 11/7/24. | ||
// | ||
#include "lite/lite.h" | ||
|
||
static void test_default() | ||
{ | ||
#ifdef ENABLE_ONNXRUNTIME | ||
std::string onnx_path = "../../../examples/hub/onnx/cv/gfpgan_1.4.onnx"; | ||
std::string test_img_path = "../../../examples/lite/resources/test_lite_facefusion_pipeline_source.jpg"; | ||
std::string save_img_path = "../../../examples/lite/resources/test_lite_facefusion_pipeline_target.jpg"; | ||
|
||
// 1. Test Default Engine ONNXRuntime | ||
lite::cv::face::restoration::GFPGAN *face_restoration = new lite::cv::face::restoration::GFPGAN(onnx_path); | ||
|
||
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); | ||
|
||
face_restoration->detect(img_bgr,face_landmark_5,save_img_path); | ||
|
||
|
||
std::cout<<"face restoration detect done!"<<std::endl; | ||
|
||
delete face_restoration; | ||
#endif | ||
} | ||
|
||
int main(__unused int argc, __unused char *argv[]) | ||
{ | ||
test_default(); | ||
return 0; | ||
} |
This file contains 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,55 @@ | ||
// | ||
// Created by wangzijian on 11/5/24. | ||
// | ||
#include "lite/lite.h" | ||
|
||
static void test_default() | ||
{ | ||
#ifdef ENABLE_ONNXRUNTIME | ||
std::string face_swap_onnx_path = "../../../examples/hub/onnx/cv/inswapper_128.onnx"; | ||
std::string face_detect_onnx_path = "../../../examples/hub/onnx/cv/yoloface_8n.onnx"; | ||
std::string face_landmarks_68 = "../../../examples/hub/onnx/cv/2dfan4.onnx"; | ||
std::string face_recognizer_onnx_path = "../../../examples/hub/onnx/cv/arcface_w600k_r50.onnx";; | ||
|
||
std::string source_image_path = "../../../examples/lite/resources/test_lite_facefusion_pipeline_source.jpg"; | ||
std::string target_image_path = "../../../examples/lite/resources/test_lite_facefusion_pipeline_target.jpg"; | ||
|
||
lite::cv::face::detect::YOLOV8Face *yolov8_face = new lite::cv::face::detect::YOLOV8Face(face_detect_onnx_path); | ||
lite::cv::faceid::Face_68Landmarks *face68Landmarks = new lite::cv::faceid::Face_68Landmarks(face_landmarks_68); | ||
lite::cv::faceid::Face_Recognizer *face_recognizer = new lite::cv::faceid::Face_Recognizer(face_recognizer_onnx_path); | ||
lite::cv::face::swap::InSwapper *face_swap = new lite::cv::face::swap::InSwapper(face_swap_onnx_path); | ||
|
||
|
||
std::vector<lite::types::Boxf> detected_boxes; | ||
cv::Mat img_bgr = cv::imread(source_image_path); | ||
yolov8_face->detect(img_bgr, detected_boxes); | ||
int position = 0; // 0号位置的脸部 | ||
auto test_bounding_box = detected_boxes[0]; | ||
std::vector<cv::Point2f> face_landmark_5of68; | ||
face68Landmarks->detect(img_bgr, test_bounding_box, face_landmark_5of68); | ||
std::vector<float> source_image_embeding; | ||
face_recognizer->detect(img_bgr,face_landmark_5of68,source_image_embeding); | ||
|
||
// 上面是source的 现在下面是target的 | ||
std::vector<lite::types::Boxf> target_detected_boxes; | ||
cv::Mat target_img_bgr = cv::imread(target_image_path); | ||
yolov8_face->detect(target_img_bgr, target_detected_boxes); | ||
auto target_test_bounding_box = target_detected_boxes[0]; | ||
std::vector<cv::Point2f> target_face_landmark_5of68; | ||
face68Landmarks->detect(target_img_bgr, target_test_bounding_box,target_face_landmark_5of68); | ||
|
||
cv::Mat face_swap_image; | ||
face_swap->detect(target_img_bgr,source_image_embeding,target_face_landmark_5of68,face_swap_image); | ||
|
||
delete yolov8_face; | ||
delete face68Landmarks; | ||
delete face_swap; | ||
delete face_recognizer; | ||
#endif | ||
} | ||
|
||
int main(__unused int argc, __unused char *argv[]) | ||
{ | ||
test_default(); | ||
return 0; | ||
} |
This file contains 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,45 @@ | ||
// | ||
// Created by wangzijian on 11/7/24. | ||
// | ||
#include "lite/lite.h" | ||
static void test_default() | ||
{ | ||
#ifdef ENABLE_ONNXRUNTIME | ||
std::string face_swap_onnx_path = "../../../examples/hub/onnx/cv/inswapper_128.onnx"; | ||
std::string face_detect_onnx_path = "../../../examples/hub/onnx/cv/yoloface_8n.onnx"; | ||
std::string face_landmarks_68 = "../../../examples/hub/onnx/cv/2dfan4.onnx"; | ||
std::string face_recognizer_onnx_path = "../../../examples/hub/onnx/cv/arcface_w600k_r50.onnx"; | ||
std::string face_restoration_onnx_path = "../../../examples/hub/onnx/cv/gfpgan_1.4.onnx"; | ||
|
||
auto pipeLine = lite::cv::face::swap::facefusion::PipeLine( | ||
face_detect_onnx_path, | ||
face_landmarks_68, | ||
face_recognizer_onnx_path, | ||
face_swap_onnx_path, | ||
face_restoration_onnx_path | ||
); | ||
|
||
std::string source_image_path = "../../../examples/lite/resources/test_lite_facefusion_pipeline_source.jpg"; | ||
std::string target_image_path = "../../../examples/lite/resources/test_lite_facefusion_pipeline_target.jpg"; | ||
std::string save_image_path = "../../../examples/logs/test_lite_facefusion_pipeline_result.jpg"; | ||
|
||
|
||
// 写一个测试时间的代码 | ||
auto start = std::chrono::high_resolution_clock::now(); | ||
|
||
|
||
|
||
pipeLine.detect(source_image_path,target_image_path,save_image_path); | ||
auto end = std::chrono::high_resolution_clock::now(); | ||
std::chrono::duration<double> diff = end-start; | ||
std::cout << "Time: " << diff.count() << " s\n"; | ||
|
||
|
||
#endif | ||
} | ||
|
||
int main() | ||
{ | ||
|
||
test_default(); | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains 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
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.
这几个新增了类都属于FaceFusion系列,建议改成FaceFusion68Landmarks, FaceFusionRecognizer, FaceFusionSwap, FaceFusionRestoration, FaceFusionPipeline的风格。本仓库class名称采用驼峰法风格,不采用下划线。