mirror of
https://github.com/PaddlePaddle/FastDeploy.git
synced 2025-10-06 00:57:33 +08:00
[Model] Modify SR (#674)
* first commit for yolov7 * pybind for yolov7 * CPP README.md * CPP README.md * modified yolov7.cc * README.md * python file modify * delete license in fastdeploy/ * repush the conflict part * README.md modified * README.md modified * file path modified * file path modified * file path modified * file path modified * file path modified * README modified * README modified * move some helpers to private * add examples for yolov7 * api.md modified * api.md modified * api.md modified * YOLOv7 * yolov7 release link * yolov7 release link * yolov7 release link * copyright * change some helpers to private * change variables to const and fix documents. * gitignore * Transfer some funtions to private member of class * Transfer some funtions to private member of class * Merge from develop (#9) * Fix compile problem in different python version (#26) * fix some usage problem in linux * Fix compile problem Co-authored-by: root <root@bjyz-sys-gpu-kongming3.bjyz.baidu.com> * Add PaddleDetetion/PPYOLOE model support (#22) * add ppdet/ppyoloe * Add demo code and documents * add convert processor to vision (#27) * update .gitignore * Added checking for cmake include dir * fixed missing trt_backend option bug when init from trt * remove un-need data layout and add pre-check for dtype * changed RGB2BRG to BGR2RGB in ppcls model * add model_zoo yolov6 c++/python demo * fixed CMakeLists.txt typos * update yolov6 cpp/README.md * add yolox c++/pybind and model_zoo demo * move some helpers to private * fixed CMakeLists.txt typos * add normalize with alpha and beta * add version notes for yolov5/yolov6/yolox * add copyright to yolov5.cc * revert normalize * fixed some bugs in yolox * fixed examples/CMakeLists.txt to avoid conflicts * add convert processor to vision * format examples/CMakeLists summary * Fix bug while the inference result is empty with YOLOv5 (#29) * Add multi-label function for yolov5 * Update README.md Update doc * Update fastdeploy_runtime.cc fix variable option.trt_max_shape wrong name * Update runtime_option.md Update resnet model dynamic shape setting name from images to x * Fix bug when inference result boxes are empty * Delete detection.py Co-authored-by: Jason <jiangjiajun@baidu.com> Co-authored-by: root <root@bjyz-sys-gpu-kongming3.bjyz.baidu.com> Co-authored-by: DefTruth <31974251+DefTruth@users.noreply.github.com> Co-authored-by: huangjianhui <852142024@qq.com> * first commit for yolor * for merge * Develop (#11) * Fix compile problem in different python version (#26) * fix some usage problem in linux * Fix compile problem Co-authored-by: root <root@bjyz-sys-gpu-kongming3.bjyz.baidu.com> * Add PaddleDetetion/PPYOLOE model support (#22) * add ppdet/ppyoloe * Add demo code and documents * add convert processor to vision (#27) * update .gitignore * Added checking for cmake include dir * fixed missing trt_backend option bug when init from trt * remove un-need data layout and add pre-check for dtype * changed RGB2BRG to BGR2RGB in ppcls model * add model_zoo yolov6 c++/python demo * fixed CMakeLists.txt typos * update yolov6 cpp/README.md * add yolox c++/pybind and model_zoo demo * move some helpers to private * fixed CMakeLists.txt typos * add normalize with alpha and beta * add version notes for yolov5/yolov6/yolox * add copyright to yolov5.cc * revert normalize * fixed some bugs in yolox * fixed examples/CMakeLists.txt to avoid conflicts * add convert processor to vision * format examples/CMakeLists summary * Fix bug while the inference result is empty with YOLOv5 (#29) * Add multi-label function for yolov5 * Update README.md Update doc * Update fastdeploy_runtime.cc fix variable option.trt_max_shape wrong name * Update runtime_option.md Update resnet model dynamic shape setting name from images to x * Fix bug when inference result boxes are empty * Delete detection.py Co-authored-by: Jason <jiangjiajun@baidu.com> Co-authored-by: root <root@bjyz-sys-gpu-kongming3.bjyz.baidu.com> Co-authored-by: DefTruth <31974251+DefTruth@users.noreply.github.com> Co-authored-by: huangjianhui <852142024@qq.com> * Yolor (#16) * Develop (#11) (#12) * Fix compile problem in different python version (#26) * fix some usage problem in linux * Fix compile problem Co-authored-by: root <root@bjyz-sys-gpu-kongming3.bjyz.baidu.com> * Add PaddleDetetion/PPYOLOE model support (#22) * add ppdet/ppyoloe * Add demo code and documents * add convert processor to vision (#27) * update .gitignore * Added checking for cmake include dir * fixed missing trt_backend option bug when init from trt * remove un-need data layout and add pre-check for dtype * changed RGB2BRG to BGR2RGB in ppcls model * add model_zoo yolov6 c++/python demo * fixed CMakeLists.txt typos * update yolov6 cpp/README.md * add yolox c++/pybind and model_zoo demo * move some helpers to private * fixed CMakeLists.txt typos * add normalize with alpha and beta * add version notes for yolov5/yolov6/yolox * add copyright to yolov5.cc * revert normalize * fixed some bugs in yolox * fixed examples/CMakeLists.txt to avoid conflicts * add convert processor to vision * format examples/CMakeLists summary * Fix bug while the inference result is empty with YOLOv5 (#29) * Add multi-label function for yolov5 * Update README.md Update doc * Update fastdeploy_runtime.cc fix variable option.trt_max_shape wrong name * Update runtime_option.md Update resnet model dynamic shape setting name from images to x * Fix bug when inference result boxes are empty * Delete detection.py Co-authored-by: Jason <jiangjiajun@baidu.com> Co-authored-by: root <root@bjyz-sys-gpu-kongming3.bjyz.baidu.com> Co-authored-by: DefTruth <31974251+DefTruth@users.noreply.github.com> Co-authored-by: huangjianhui <852142024@qq.com> Co-authored-by: Jason <jiangjiajun@baidu.com> Co-authored-by: root <root@bjyz-sys-gpu-kongming3.bjyz.baidu.com> Co-authored-by: DefTruth <31974251+DefTruth@users.noreply.github.com> Co-authored-by: huangjianhui <852142024@qq.com> * Develop (#13) * Fix compile problem in different python version (#26) * fix some usage problem in linux * Fix compile problem Co-authored-by: root <root@bjyz-sys-gpu-kongming3.bjyz.baidu.com> * Add PaddleDetetion/PPYOLOE model support (#22) * add ppdet/ppyoloe * Add demo code and documents * add convert processor to vision (#27) * update .gitignore * Added checking for cmake include dir * fixed missing trt_backend option bug when init from trt * remove un-need data layout and add pre-check for dtype * changed RGB2BRG to BGR2RGB in ppcls model * add model_zoo yolov6 c++/python demo * fixed CMakeLists.txt typos * update yolov6 cpp/README.md * add yolox c++/pybind and model_zoo demo * move some helpers to private * fixed CMakeLists.txt typos * add normalize with alpha and beta * add version notes for yolov5/yolov6/yolox * add copyright to yolov5.cc * revert normalize * fixed some bugs in yolox * fixed examples/CMakeLists.txt to avoid conflicts * add convert processor to vision * format examples/CMakeLists summary * Fix bug while the inference result is empty with YOLOv5 (#29) * Add multi-label function for yolov5 * Update README.md Update doc * Update fastdeploy_runtime.cc fix variable option.trt_max_shape wrong name * Update runtime_option.md Update resnet model dynamic shape setting name from images to x * Fix bug when inference result boxes are empty * Delete detection.py Co-authored-by: Jason <jiangjiajun@baidu.com> Co-authored-by: root <root@bjyz-sys-gpu-kongming3.bjyz.baidu.com> Co-authored-by: DefTruth <31974251+DefTruth@users.noreply.github.com> Co-authored-by: huangjianhui <852142024@qq.com> * documents * documents * documents * documents * documents * documents * documents * documents * documents * documents * documents * documents * Develop (#14) * Fix compile problem in different python version (#26) * fix some usage problem in linux * Fix compile problem Co-authored-by: root <root@bjyz-sys-gpu-kongming3.bjyz.baidu.com> * Add PaddleDetetion/PPYOLOE model support (#22) * add ppdet/ppyoloe * Add demo code and documents * add convert processor to vision (#27) * update .gitignore * Added checking for cmake include dir * fixed missing trt_backend option bug when init from trt * remove un-need data layout and add pre-check for dtype * changed RGB2BRG to BGR2RGB in ppcls model * add model_zoo yolov6 c++/python demo * fixed CMakeLists.txt typos * update yolov6 cpp/README.md * add yolox c++/pybind and model_zoo demo * move some helpers to private * fixed CMakeLists.txt typos * add normalize with alpha and beta * add version notes for yolov5/yolov6/yolox * add copyright to yolov5.cc * revert normalize * fixed some bugs in yolox * fixed examples/CMakeLists.txt to avoid conflicts * add convert processor to vision * format examples/CMakeLists summary * Fix bug while the inference result is empty with YOLOv5 (#29) * Add multi-label function for yolov5 * Update README.md Update doc * Update fastdeploy_runtime.cc fix variable option.trt_max_shape wrong name * Update runtime_option.md Update resnet model dynamic shape setting name from images to x * Fix bug when inference result boxes are empty * Delete detection.py Co-authored-by: root <root@bjyz-sys-gpu-kongming3.bjyz.baidu.com> Co-authored-by: DefTruth <31974251+DefTruth@users.noreply.github.com> Co-authored-by: huangjianhui <852142024@qq.com> Co-authored-by: Jason <jiangjiajun@baidu.com> Co-authored-by: root <root@bjyz-sys-gpu-kongming3.bjyz.baidu.com> Co-authored-by: DefTruth <31974251+DefTruth@users.noreply.github.com> Co-authored-by: huangjianhui <852142024@qq.com> Co-authored-by: Jason <928090362@qq.com> * add is_dynamic for YOLO series (#22) * modify ppmatting backend and docs * modify ppmatting docs * fix the PPMatting size problem * fix LimitShort's log * retrigger ci * modify PPMatting docs * modify the way for dealing with LimitShort * add python comments for external models * modify resnet c++ comments * modify C++ comments for external models * modify python comments and add result class comments * fix comments compile error * modify result.h comments * modify examples doc and code for SR models * code style * retrigger ci * python file code style * fix examples links * fix examples links * fix examples links Co-authored-by: Jason <jiangjiajun@baidu.com> Co-authored-by: root <root@bjyz-sys-gpu-kongming3.bjyz.baidu.com> Co-authored-by: DefTruth <31974251+DefTruth@users.noreply.github.com> Co-authored-by: huangjianhui <852142024@qq.com> Co-authored-by: Jason <928090362@qq.com>
This commit is contained in:
@@ -18,7 +18,7 @@
|
||||
|
||||
| 模型 | 参数大小 | 精度 | 备注 |
|
||||
|:----------------------------------------------------------------------------|:-------|:----- | :------ |
|
||||
| [BasicVSR](https://bj.bcebos.com/paddlehub/fastdeploy/BasicVSR_reds_x4.tgz) | 30.1MB | - |
|
||||
| [BasicVSR](https://bj.bcebos.com/paddlehub/fastdeploy/BasicVSR_reds_x4.tar) | 30.1MB | - |
|
||||
|
||||
**注意**:非常不建议在没有独立显卡的设备上运行该模型
|
||||
|
||||
|
@@ -20,8 +20,8 @@ const char sep = '\\';
|
||||
const char sep = '/';
|
||||
#endif
|
||||
|
||||
void CpuInfer(const std::string& model_dir,
|
||||
const std::string& video_file, int frame_num) {
|
||||
void CpuInfer(const std::string& model_dir, const std::string& video_file,
|
||||
int frame_num) {
|
||||
auto model_file = model_dir + sep + "model.pdmodel";
|
||||
auto params_file = model_dir + sep + "model.pdiparams";
|
||||
auto model = fastdeploy::vision::sr::BasicVSR(model_file, params_file);
|
||||
@@ -32,34 +32,36 @@ void CpuInfer(const std::string& model_dir,
|
||||
}
|
||||
// note: input/output shape is [b, n, c, h, w] (n = frame_nums; b=1(default))
|
||||
// b and n is dependent on export model shape
|
||||
// see https://github.com/PaddlePaddle/PaddleGAN/blob/develop/docs/zh_CN/tutorials/video_super_resolution.md
|
||||
// see
|
||||
// https://github.com/PaddlePaddle/PaddleGAN/blob/develop/docs/zh_CN/tutorials/video_super_resolution.md
|
||||
cv::VideoCapture capture;
|
||||
// change your save video path
|
||||
std::string video_out_name = "output.mp4";
|
||||
capture.open(video_file);
|
||||
if (!capture.isOpened())
|
||||
{
|
||||
std::cout<<"can not open video "<<std::endl;
|
||||
if (!capture.isOpened()) {
|
||||
std::cout << "can not open video " << std::endl;
|
||||
return;
|
||||
}
|
||||
// Get Video info :fps, frame count
|
||||
// it used 4.x version of opencv below
|
||||
// notice your opencv version and method of api.
|
||||
int video_fps = static_cast<int>(capture.get(cv::CAP_PROP_FPS));
|
||||
int video_frame_count = static_cast<int>(capture.get(cv::CAP_PROP_FRAME_COUNT));
|
||||
int video_frame_count =
|
||||
static_cast<int>(capture.get(cv::CAP_PROP_FRAME_COUNT));
|
||||
// Set fixed size for output frame, only for msvsr model
|
||||
int out_width = 1280;
|
||||
int out_height = 720;
|
||||
std::cout << "fps: " << video_fps << "\tframe_count: " << video_frame_count << std::endl;
|
||||
std::cout << "fps: " << video_fps << "\tframe_count: " << video_frame_count
|
||||
<< std::endl;
|
||||
|
||||
// Create VideoWriter for output
|
||||
cv::VideoWriter video_out;
|
||||
std::string video_out_path("./");
|
||||
video_out_path += video_out_name;
|
||||
int fcc = cv::VideoWriter::fourcc('m', 'p', '4', 'v');
|
||||
video_out.open(video_out_path, fcc, video_fps, cv::Size(out_width, out_height), true);
|
||||
if (!video_out.isOpened())
|
||||
{
|
||||
video_out.open(video_out_path, fcc, video_fps,
|
||||
cv::Size(out_width, out_height), true);
|
||||
if (!video_out.isOpened()) {
|
||||
std::cout << "create video writer failed!" << std::endl;
|
||||
return;
|
||||
}
|
||||
@@ -67,48 +69,44 @@ void CpuInfer(const std::string& model_dir,
|
||||
cv::Mat frame;
|
||||
int frame_id = 0;
|
||||
bool reach_end = false;
|
||||
while (capture.isOpened())
|
||||
{
|
||||
while (capture.isOpened()) {
|
||||
std::vector<cv::Mat> imgs;
|
||||
for (int i = 0; i < frame_num; i++)
|
||||
{
|
||||
for (int i = 0; i < frame_num; i++) {
|
||||
capture.read(frame);
|
||||
if (!frame.empty())
|
||||
{
|
||||
if (!frame.empty()) {
|
||||
imgs.push_back(frame);
|
||||
}else{
|
||||
} else {
|
||||
reach_end = true;
|
||||
}
|
||||
}
|
||||
if (reach_end)
|
||||
{
|
||||
if (reach_end) {
|
||||
break;
|
||||
}
|
||||
std::vector<cv::Mat> results;
|
||||
model.Predict(imgs, results);
|
||||
for (auto &item : results)
|
||||
{
|
||||
for (auto& item : results) {
|
||||
// cv::imshow("13",item);
|
||||
// cv::waitKey(30);
|
||||
video_out.write(item);
|
||||
std::cout << "Processing frame: "<< frame_id << std::endl;
|
||||
std::cout << "Processing frame: " << frame_id << std::endl;
|
||||
frame_id += 1;
|
||||
}
|
||||
}
|
||||
std::cout << "inference finished, output video saved at " << video_out_path << std::endl;
|
||||
std::cout << "inference finished, output video saved at " << video_out_path
|
||||
<< std::endl;
|
||||
capture.release();
|
||||
video_out.release();
|
||||
}
|
||||
|
||||
void GpuInfer(const std::string& model_dir,
|
||||
const std::string& video_file, int frame_num) {
|
||||
void GpuInfer(const std::string& model_dir, const std::string& video_file,
|
||||
int frame_num) {
|
||||
auto model_file = model_dir + sep + "model.pdmodel";
|
||||
auto params_file = model_dir + sep + "model.pdiparams";
|
||||
|
||||
auto option = fastdeploy::RuntimeOption();
|
||||
option.UseGpu();
|
||||
auto model = fastdeploy::vision::sr::BasicVSR(
|
||||
model_file, params_file, option);
|
||||
auto model =
|
||||
fastdeploy::vision::sr::BasicVSR(model_file, params_file, option);
|
||||
|
||||
if (!model.Initialized()) {
|
||||
std::cerr << "Failed to initialize." << std::endl;
|
||||
@@ -116,32 +114,34 @@ void GpuInfer(const std::string& model_dir,
|
||||
}
|
||||
// note: input/output shape is [b, n, c, h, w] (n = frame_nums; b=1(default))
|
||||
// b and n is dependent on export model shape
|
||||
// see https://github.com/PaddlePaddle/PaddleGAN/blob/develop/docs/zh_CN/tutorials/video_super_resolution.md
|
||||
// see
|
||||
// https://github.com/PaddlePaddle/PaddleGAN/blob/develop/docs/zh_CN/tutorials/video_super_resolution.md
|
||||
cv::VideoCapture capture;
|
||||
// change your save video path
|
||||
std::string video_out_name = "output.mp4";
|
||||
capture.open(video_file);
|
||||
if (!capture.isOpened())
|
||||
{
|
||||
std::cout<<"can not open video "<<std::endl;
|
||||
if (!capture.isOpened()) {
|
||||
std::cout << "can not open video " << std::endl;
|
||||
return;
|
||||
}
|
||||
// Get Video info :fps, frame count
|
||||
int video_fps = static_cast<int>(capture.get(cv::CAP_PROP_FPS));
|
||||
int video_frame_count = static_cast<int>(capture.get(cv::CAP_PROP_FRAME_COUNT));
|
||||
int video_frame_count =
|
||||
static_cast<int>(capture.get(cv::CAP_PROP_FRAME_COUNT));
|
||||
// Set fixed size for output frame, only for msvsr model
|
||||
int out_width = 1280;
|
||||
int out_height = 720;
|
||||
std::cout << "fps: " << video_fps << "\tframe_count: " << video_frame_count << std::endl;
|
||||
std::cout << "fps: " << video_fps << "\tframe_count: " << video_frame_count
|
||||
<< std::endl;
|
||||
|
||||
// Create VideoWriter for output
|
||||
cv::VideoWriter video_out;
|
||||
std::string video_out_path("./");
|
||||
video_out_path += video_out_name;
|
||||
int fcc = cv::VideoWriter::fourcc('m', 'p', '4', 'v');
|
||||
video_out.open(video_out_path, fcc, video_fps, cv::Size(out_width, out_height), true);
|
||||
if (!video_out.isOpened())
|
||||
{
|
||||
video_out.open(video_out_path, fcc, video_fps,
|
||||
cv::Size(out_width, out_height), true);
|
||||
if (!video_out.isOpened()) {
|
||||
std::cout << "create video writer failed!" << std::endl;
|
||||
return;
|
||||
}
|
||||
@@ -149,50 +149,48 @@ void GpuInfer(const std::string& model_dir,
|
||||
cv::Mat frame;
|
||||
int frame_id = 0;
|
||||
bool reach_end = false;
|
||||
while (capture.isOpened())
|
||||
{
|
||||
while (capture.isOpened()) {
|
||||
std::vector<cv::Mat> imgs;
|
||||
for (int i = 0; i < frame_num; i++)
|
||||
{
|
||||
for (int i = 0; i < frame_num; i++) {
|
||||
capture.read(frame);
|
||||
if (!frame.empty())
|
||||
{
|
||||
if (!frame.empty()) {
|
||||
imgs.push_back(frame);
|
||||
}else{
|
||||
} else {
|
||||
reach_end = true;
|
||||
}
|
||||
}
|
||||
if (reach_end)
|
||||
{
|
||||
if (reach_end) {
|
||||
break;
|
||||
}
|
||||
std::vector<cv::Mat> results;
|
||||
model.Predict(imgs, results);
|
||||
for (auto &item : results)
|
||||
{
|
||||
for (auto& item : results) {
|
||||
// cv::imshow("13",item);
|
||||
// cv::waitKey(30);
|
||||
video_out.write(item);
|
||||
std::cout << "Processing frame: "<< frame_id << std::endl;
|
||||
std::cout << "Processing frame: " << frame_id << std::endl;
|
||||
frame_id += 1;
|
||||
}
|
||||
}
|
||||
std::cout << "inference finished, output video saved at " << video_out_path << std::endl;
|
||||
std::cout << "inference finished, output video saved at " << video_out_path
|
||||
<< std::endl;
|
||||
capture.release();
|
||||
video_out.release();
|
||||
}
|
||||
|
||||
void TrtInfer(const std::string& model_dir,
|
||||
const std::string& video_file, int frame_num) {
|
||||
void TrtInfer(const std::string& model_dir, const std::string& video_file,
|
||||
int frame_num) {
|
||||
auto model_file = model_dir + sep + "model.pdmodel";
|
||||
auto params_file = model_dir + sep + "model.pdiparams";
|
||||
auto option = fastdeploy::RuntimeOption();
|
||||
option.UseGpu();
|
||||
option.UseTrtBackend();
|
||||
// use paddle-TRT
|
||||
option.UseTrtBackend();
|
||||
option.EnablePaddleTrtCollectShape();
|
||||
option.SetTrtInputShape("lrs", {1, 2, 3, 180, 320});
|
||||
option.EnablePaddleToTrt();
|
||||
auto model = fastdeploy::vision::sr::BasicVSR(
|
||||
model_file, params_file, option);
|
||||
auto model =
|
||||
fastdeploy::vision::sr::BasicVSR(model_file, params_file, option);
|
||||
|
||||
if (!model.Initialized()) {
|
||||
std::cerr << "Failed to initialize." << std::endl;
|
||||
@@ -201,35 +199,38 @@ void TrtInfer(const std::string& model_dir,
|
||||
|
||||
// note: input/output shape is [b, n, c, h, w] (n = frame_nums; b=1(default))
|
||||
// b and n is dependent on export model shape
|
||||
// see https://github.com/PaddlePaddle/PaddleGAN/blob/develop/docs/zh_CN/tutorials/video_super_resolution.md
|
||||
// see
|
||||
// https://github.com/PaddlePaddle/PaddleGAN/blob/develop/docs/zh_CN/tutorials/video_super_resolution.md
|
||||
cv::VideoCapture capture;
|
||||
// change your save video path
|
||||
std::string video_out_name = "output.mp4";
|
||||
capture.open(video_file);
|
||||
if (!capture.isOpened())
|
||||
{
|
||||
std::cout<<"can not open video "<<std::endl;
|
||||
if (!capture.isOpened()) {
|
||||
std::cout << "can not open video " << std::endl;
|
||||
return;
|
||||
}
|
||||
// Get Video info :fps, frame count
|
||||
int video_fps = static_cast<int>(capture.get(cv::CAP_PROP_FPS));
|
||||
int video_frame_count = static_cast<int>(capture.get(cv::CAP_PROP_FRAME_COUNT));
|
||||
int video_frame_count =
|
||||
static_cast<int>(capture.get(cv::CAP_PROP_FRAME_COUNT));
|
||||
// Set fixed size for output frame, only for msvsr model
|
||||
//Note that the resolution between the size and the original input is consistent when the model is exported,
|
||||
// Note that the resolution between the size and the original input is
|
||||
// consistent when the model is exported,
|
||||
// for example: [1,2,3,180,320], after 4x super separation [1,2,3,720,1080].
|
||||
//Therefore, it is very important to derive the model
|
||||
// Therefore, it is very important to derive the model
|
||||
int out_width = 1280;
|
||||
int out_height = 720;
|
||||
std::cout << "fps: " << video_fps << "\tframe_count: " << video_frame_count << std::endl;
|
||||
std::cout << "fps: " << video_fps << "\tframe_count: " << video_frame_count
|
||||
<< std::endl;
|
||||
|
||||
// Create VideoWriter for output
|
||||
cv::VideoWriter video_out;
|
||||
std::string video_out_path("./");
|
||||
video_out_path += video_out_name;
|
||||
int fcc = cv::VideoWriter::fourcc('m', 'p', '4', 'v');
|
||||
video_out.open(video_out_path, fcc, video_fps, cv::Size(out_width, out_height), true);
|
||||
if (!video_out.isOpened())
|
||||
{
|
||||
video_out.open(video_out_path, fcc, video_fps,
|
||||
cv::Size(out_width, out_height), true);
|
||||
if (!video_out.isOpened()) {
|
||||
std::cout << "create video writer failed!" << std::endl;
|
||||
return;
|
||||
}
|
||||
@@ -237,45 +238,41 @@ void TrtInfer(const std::string& model_dir,
|
||||
cv::Mat frame;
|
||||
int frame_id = 0;
|
||||
bool reach_end = false;
|
||||
while (capture.isOpened())
|
||||
{
|
||||
while (capture.isOpened()) {
|
||||
std::vector<cv::Mat> imgs;
|
||||
for (int i = 0; i < frame_num; i++)
|
||||
{
|
||||
for (int i = 0; i < frame_num; i++) {
|
||||
capture.read(frame);
|
||||
if (!frame.empty())
|
||||
{
|
||||
if (!frame.empty()) {
|
||||
imgs.push_back(frame);
|
||||
}else{
|
||||
} else {
|
||||
reach_end = true;
|
||||
}
|
||||
}
|
||||
if (reach_end)
|
||||
{
|
||||
if (reach_end) {
|
||||
break;
|
||||
}
|
||||
std::vector<cv::Mat> results;
|
||||
model.Predict(imgs, results);
|
||||
for (auto &item : results)
|
||||
{
|
||||
for (auto& item : results) {
|
||||
// cv::imshow("13",item);
|
||||
// cv::waitKey(30);
|
||||
video_out.write(item);
|
||||
std::cout << "Processing frame: "<< frame_id << std::endl;
|
||||
std::cout << "Processing frame: " << frame_id << std::endl;
|
||||
frame_id += 1;
|
||||
}
|
||||
}
|
||||
std::cout << "inference finished, output video saved at " << video_out_path << std::endl;
|
||||
std::cout << "inference finished, output video saved at " << video_out_path
|
||||
<< std::endl;
|
||||
capture.release();
|
||||
video_out.release();
|
||||
}
|
||||
|
||||
int main(int argc, char* argv[]) {
|
||||
if (argc < 4) {
|
||||
std::cout
|
||||
<< "Usage: infer_demo path/to/model_dir path/to/video frame number run_option, "
|
||||
"e.g ./infer_model ./vsr_model_dir ./person.mp4 0 2"
|
||||
<< std::endl;
|
||||
std::cout << "Usage: infer_demo path/to/model_dir path/to/video frame "
|
||||
"number run_option, "
|
||||
"e.g ./infer_model ./vsr_model_dir ./vsr_src.mp4 0 2"
|
||||
<< std::endl;
|
||||
std::cout << "The data type of run_option is int, 0: run with cpu; 1: run "
|
||||
"with gpu; 2: run with gpu and use tensorrt backend."
|
||||
<< std::endl;
|
||||
|
@@ -17,11 +17,11 @@ wget https://bj.bcebos.com/paddlehub/fastdeploy/BasicVSR_reds_x4.tar
|
||||
tar -xvf BasicVSR_reds_x4.tar
|
||||
wget https://bj.bcebos.com/paddlehub/fastdeploy/vsr_src.mp4
|
||||
# CPU推理
|
||||
python infer.py --model BasicVSR_reds_x4 --video person.mp4 --frame_num 2 --device cpu
|
||||
python infer.py --model BasicVSR_reds_x4 --video vsr_src.mp4 --frame_num 2 --device cpu
|
||||
# GPU推理
|
||||
python infer.py --model BasicVSR_reds_x4 --video person.mp4 --frame_num 2 --device gpu
|
||||
python infer.py --model BasicVSR_reds_x4 --video vsr_src.mp4 --frame_num 2 --device gpu
|
||||
# GPU上使用TensorRT推理 (注意:TensorRT推理第一次运行,有序列化模型的操作,有一定耗时,需要耐心等待)
|
||||
python infer.py --model BasicVSR_reds_x4 --video person.mp4 --frame_num 2 --device gpu --use_trt True
|
||||
python infer.py --model BasicVSR_reds_x4 --video vsr_src.mp4 --frame_num 2 --device gpu --use_trt True
|
||||
```
|
||||
|
||||
## BasicVSR Python接口
|
||||
|
@@ -30,6 +30,8 @@ def build_option(args):
|
||||
option.use_gpu()
|
||||
if args.use_trt:
|
||||
option.use_trt_backend()
|
||||
option.enable_paddle_trt_collect_shape()
|
||||
option.set_trt_input_shape("lrs", [1, 2, 3, 180, 320])
|
||||
option.enable_paddle_to_trt()
|
||||
return option
|
||||
|
||||
@@ -56,7 +58,7 @@ print(f"fps: {video_fps}\tframe_count: {video_frame_count}")
|
||||
# Create VideoWriter for output
|
||||
video_out_dir = "./"
|
||||
video_out_path = os.path.join(video_out_dir, video_out_name)
|
||||
fucc = cv2.VideoWriter_fourcc(*"mp4v")
|
||||
fucc = cv2.VideoWriter_fourcc(* "mp4v")
|
||||
video_out = cv2.VideoWriter(video_out_path, fucc, video_fps,
|
||||
(out_width, out_height), True)
|
||||
if not video_out.isOpened():
|
||||
|
@@ -18,7 +18,7 @@
|
||||
|
||||
| 模型 | 参数大小 | 精度 | 备注 |
|
||||
|:--------------------------------------------------------------------------------|:-------|:----- | :------ |
|
||||
| [EDVR](https://bj.bcebos.com/paddlehub/fastdeploy/EDVR_M_wo_tsa_SRx4.tgz) | 14.9MB | - |
|
||||
| [EDVR](https://bj.bcebos.com/paddlehub/fastdeploy/EDVR_M_wo_tsa_SRx4.tar) | 14.9MB | - |
|
||||
|
||||
**注意**:非常不建议在没有独立显卡的设备上运行该模型
|
||||
|
||||
|
@@ -25,11 +25,11 @@ wget https://bj.bcebos.com/paddlehub/fastdeploy/vsr_src.mp4
|
||||
|
||||
|
||||
# CPU推理
|
||||
./infer_demo EDVR_M_wo_tsa_SRx4 vsr_src.mp4 0 2
|
||||
./infer_demo EDVR_M_wo_tsa_SRx4 vsr_src.mp4 0 5
|
||||
# GPU推理
|
||||
./infer_demo EDVR_M_wo_tsa_SRx4 vsr_src.mp4 1 2
|
||||
./infer_demo EDVR_M_wo_tsa_SRx4 vsr_src.mp4 1 5
|
||||
# GPU上TensorRT推理
|
||||
./infer_demo EDVR_M_wo_tsa_SRx4 vsr_src.mp4 2 2
|
||||
./infer_demo EDVR_M_wo_tsa_SRx4 vsr_src.mp4 2 5
|
||||
```
|
||||
|
||||
以上命令只适用于Linux或MacOS, Windows下SDK的使用方式请参考:
|
||||
|
@@ -20,8 +20,8 @@ const char sep = '\\';
|
||||
const char sep = '/';
|
||||
#endif
|
||||
|
||||
void CpuInfer(const std::string& model_dir,
|
||||
const std::string& video_file, int frame_num) {
|
||||
void CpuInfer(const std::string& model_dir, const std::string& video_file,
|
||||
int frame_num) {
|
||||
auto model_file = model_dir + sep + "model.pdmodel";
|
||||
auto params_file = model_dir + sep + "model.pdiparams";
|
||||
auto model = fastdeploy::vision::sr::EDVR(model_file, params_file);
|
||||
@@ -32,34 +32,36 @@ void CpuInfer(const std::string& model_dir,
|
||||
}
|
||||
// note: input/output shape is [b, n, c, h, w] (n = frame_nums; b=1(default))
|
||||
// b and n is dependent on export model shape
|
||||
// see https://github.com/PaddlePaddle/PaddleGAN/blob/develop/docs/zh_CN/tutorials/video_super_resolution.md
|
||||
// see
|
||||
// https://github.com/PaddlePaddle/PaddleGAN/blob/develop/docs/zh_CN/tutorials/video_super_resolution.md
|
||||
cv::VideoCapture capture;
|
||||
// change your save video path
|
||||
std::string video_out_name = "output.mp4";
|
||||
capture.open(video_file);
|
||||
if (!capture.isOpened())
|
||||
{
|
||||
std::cout<<"can not open video "<<std::endl;
|
||||
if (!capture.isOpened()) {
|
||||
std::cout << "can not open video " << std::endl;
|
||||
return;
|
||||
}
|
||||
// Get Video info :fps, frame count
|
||||
// it used 4.x version of opencv below
|
||||
// notice your opencv version and method of api.
|
||||
int video_fps = static_cast<int>(capture.get(cv::CAP_PROP_FPS));
|
||||
int video_frame_count = static_cast<int>(capture.get(cv::CAP_PROP_FRAME_COUNT));
|
||||
int video_frame_count =
|
||||
static_cast<int>(capture.get(cv::CAP_PROP_FRAME_COUNT));
|
||||
// Set fixed size for output frame, only for msvsr model
|
||||
int out_width = 1280;
|
||||
int out_height = 720;
|
||||
std::cout << "fps: " << video_fps << "\tframe_count: " << video_frame_count << std::endl;
|
||||
std::cout << "fps: " << video_fps << "\tframe_count: " << video_frame_count
|
||||
<< std::endl;
|
||||
|
||||
// Create VideoWriter for output
|
||||
cv::VideoWriter video_out;
|
||||
std::string video_out_path("./");
|
||||
video_out_path += video_out_name;
|
||||
int fcc = cv::VideoWriter::fourcc('m', 'p', '4', 'v');
|
||||
video_out.open(video_out_path, fcc, video_fps, cv::Size(out_width, out_height), true);
|
||||
if (!video_out.isOpened())
|
||||
{
|
||||
video_out.open(video_out_path, fcc, video_fps,
|
||||
cv::Size(out_width, out_height), true);
|
||||
if (!video_out.isOpened()) {
|
||||
std::cout << "create video writer failed!" << std::endl;
|
||||
return;
|
||||
}
|
||||
@@ -67,42 +69,40 @@ void CpuInfer(const std::string& model_dir,
|
||||
cv::Mat frame;
|
||||
int frame_id = 0;
|
||||
std::vector<cv::Mat> imgs;
|
||||
while (capture.read(frame)){
|
||||
if (!frame.empty())
|
||||
{
|
||||
if(frame_id < frame_num){
|
||||
while (capture.read(frame)) {
|
||||
if (!frame.empty()) {
|
||||
if (frame_id < frame_num) {
|
||||
imgs.push_back(frame);
|
||||
frame_id ++;
|
||||
frame_id++;
|
||||
continue;
|
||||
}
|
||||
imgs.erase(imgs.begin());
|
||||
imgs.push_back(frame);
|
||||
}
|
||||
frame_id ++;
|
||||
frame_id++;
|
||||
std::vector<cv::Mat> results;
|
||||
model.Predict(imgs, results);
|
||||
for (auto &item : results)
|
||||
{
|
||||
for (auto& item : results) {
|
||||
// cv::imshow("13",item);
|
||||
// cv::waitKey(30);
|
||||
video_out.write(item);
|
||||
std::cout << "Processing frame: "<< frame_id << std::endl;
|
||||
std::cout << "Processing frame: " << frame_id << std::endl;
|
||||
}
|
||||
}
|
||||
std::cout << "inference finished, output video saved at " << video_out_path << std::endl;
|
||||
std::cout << "inference finished, output video saved at " << video_out_path
|
||||
<< std::endl;
|
||||
capture.release();
|
||||
video_out.release();
|
||||
}
|
||||
|
||||
void GpuInfer(const std::string& model_dir,
|
||||
const std::string& video_file, int frame_num) {
|
||||
void GpuInfer(const std::string& model_dir, const std::string& video_file,
|
||||
int frame_num) {
|
||||
auto model_file = model_dir + sep + "model.pdmodel";
|
||||
auto params_file = model_dir + sep + "model.pdiparams";
|
||||
|
||||
auto option = fastdeploy::RuntimeOption();
|
||||
option.UseGpu();
|
||||
auto model = fastdeploy::vision::sr::EDVR(
|
||||
model_file, params_file, option);
|
||||
auto model = fastdeploy::vision::sr::EDVR(model_file, params_file, option);
|
||||
|
||||
if (!model.Initialized()) {
|
||||
std::cerr << "Failed to initialize." << std::endl;
|
||||
@@ -110,32 +110,34 @@ void GpuInfer(const std::string& model_dir,
|
||||
}
|
||||
// note: input/output shape is [b, n, c, h, w] (n = frame_nums; b=1(default))
|
||||
// b and n is dependent on export model shape
|
||||
// see https://github.com/PaddlePaddle/PaddleGAN/blob/develop/docs/zh_CN/tutorials/video_super_resolution.md
|
||||
// see
|
||||
// https://github.com/PaddlePaddle/PaddleGAN/blob/develop/docs/zh_CN/tutorials/video_super_resolution.md
|
||||
cv::VideoCapture capture;
|
||||
// change your save video path
|
||||
std::string video_out_name = "output.mp4";
|
||||
capture.open(video_file);
|
||||
if (!capture.isOpened())
|
||||
{
|
||||
std::cout<<"can not open video "<<std::endl;
|
||||
if (!capture.isOpened()) {
|
||||
std::cout << "can not open video " << std::endl;
|
||||
return;
|
||||
}
|
||||
// Get Video info :fps, frame count
|
||||
int video_fps = static_cast<int>(capture.get(cv::CAP_PROP_FPS));
|
||||
int video_frame_count = static_cast<int>(capture.get(cv::CAP_PROP_FRAME_COUNT));
|
||||
int video_frame_count =
|
||||
static_cast<int>(capture.get(cv::CAP_PROP_FRAME_COUNT));
|
||||
// Set fixed size for output frame, only for msvsr model
|
||||
int out_width = 1280;
|
||||
int out_height = 720;
|
||||
std::cout << "fps: " << video_fps << "\tframe_count: " << video_frame_count << std::endl;
|
||||
std::cout << "fps: " << video_fps << "\tframe_count: " << video_frame_count
|
||||
<< std::endl;
|
||||
|
||||
// Create VideoWriter for output
|
||||
cv::VideoWriter video_out;
|
||||
std::string video_out_path("./");
|
||||
video_out_path += video_out_name;
|
||||
int fcc = cv::VideoWriter::fourcc('m', 'p', '4', 'v');
|
||||
video_out.open(video_out_path, fcc, video_fps, cv::Size(out_width, out_height), true);
|
||||
if (!video_out.isOpened())
|
||||
{
|
||||
video_out.open(video_out_path, fcc, video_fps,
|
||||
cv::Size(out_width, out_height), true);
|
||||
if (!video_out.isOpened()) {
|
||||
std::cout << "create video writer failed!" << std::endl;
|
||||
return;
|
||||
}
|
||||
@@ -143,44 +145,44 @@ void GpuInfer(const std::string& model_dir,
|
||||
cv::Mat frame;
|
||||
int frame_id = 0;
|
||||
std::vector<cv::Mat> imgs;
|
||||
while (capture.read(frame)){
|
||||
if (!frame.empty())
|
||||
{
|
||||
if(frame_id < frame_num){
|
||||
while (capture.read(frame)) {
|
||||
if (!frame.empty()) {
|
||||
if (frame_id < frame_num) {
|
||||
imgs.push_back(frame);
|
||||
frame_id ++;
|
||||
frame_id++;
|
||||
continue;
|
||||
}
|
||||
imgs.erase(imgs.begin());
|
||||
imgs.push_back(frame);
|
||||
}
|
||||
frame_id ++;
|
||||
frame_id++;
|
||||
std::vector<cv::Mat> results;
|
||||
model.Predict(imgs, results);
|
||||
for (auto &item : results)
|
||||
{
|
||||
for (auto& item : results) {
|
||||
// cv::imshow("13",item);
|
||||
// cv::waitKey(30);
|
||||
video_out.write(item);
|
||||
std::cout << "Processing frame: "<< frame_id << std::endl;
|
||||
std::cout << "Processing frame: " << frame_id << std::endl;
|
||||
}
|
||||
}
|
||||
std::cout << "inference finished, output video saved at " << video_out_path << std::endl;
|
||||
std::cout << "inference finished, output video saved at " << video_out_path
|
||||
<< std::endl;
|
||||
capture.release();
|
||||
video_out.release();
|
||||
}
|
||||
|
||||
void TrtInfer(const std::string& model_dir,
|
||||
const std::string& video_file, int frame_num) {
|
||||
void TrtInfer(const std::string& model_dir, const std::string& video_file,
|
||||
int frame_num) {
|
||||
auto model_file = model_dir + sep + "model.pdmodel";
|
||||
auto params_file = model_dir + sep + "model.pdiparams";
|
||||
auto option = fastdeploy::RuntimeOption();
|
||||
option.UseGpu();
|
||||
option.UseTrtBackend();
|
||||
// use paddle-TRT
|
||||
option.UseTrtBackend();
|
||||
option.EnablePaddleTrtCollectShape();
|
||||
option.SetTrtInputShape("x", {1, 5, 3, 180, 320});
|
||||
option.EnablePaddleToTrt();
|
||||
auto model = fastdeploy::vision::sr::EDVR(
|
||||
model_file, params_file, option);
|
||||
auto model = fastdeploy::vision::sr::EDVR(model_file, params_file, option);
|
||||
|
||||
if (!model.Initialized()) {
|
||||
std::cerr << "Failed to initialize." << std::endl;
|
||||
@@ -189,75 +191,77 @@ void TrtInfer(const std::string& model_dir,
|
||||
|
||||
// note: input/output shape is [b, n, c, h, w] (n = frame_nums; b=1(default))
|
||||
// b and n is dependent on export model shape
|
||||
// see https://github.com/PaddlePaddle/PaddleGAN/blob/develop/docs/zh_CN/tutorials/video_super_resolution.md
|
||||
// see
|
||||
// https://github.com/PaddlePaddle/PaddleGAN/blob/develop/docs/zh_CN/tutorials/video_super_resolution.md
|
||||
cv::VideoCapture capture;
|
||||
// change your save video path
|
||||
std::string video_out_name = "output.mp4";
|
||||
capture.open(video_file);
|
||||
if (!capture.isOpened())
|
||||
{
|
||||
std::cout<<"can not open video "<<std::endl;
|
||||
if (!capture.isOpened()) {
|
||||
std::cout << "can not open video " << std::endl;
|
||||
return;
|
||||
}
|
||||
// Get Video info :fps, frame count
|
||||
int video_fps = static_cast<int>(capture.get(cv::CAP_PROP_FPS));
|
||||
int video_frame_count = static_cast<int>(capture.get(cv::CAP_PROP_FRAME_COUNT));
|
||||
int video_frame_count =
|
||||
static_cast<int>(capture.get(cv::CAP_PROP_FRAME_COUNT));
|
||||
// Set fixed size for output frame, only for msvsr model
|
||||
//Note that the resolution between the size and the original input is consistent when the model is exported,
|
||||
// Note that the resolution between the size and the original input is
|
||||
// consistent when the model is exported,
|
||||
// for example: [1,2,3,180,320], after 4x super separation [1,2,3,720,1080].
|
||||
//Therefore, it is very important to derive the model
|
||||
// Therefore, it is very important to derive the model
|
||||
int out_width = 1280;
|
||||
int out_height = 720;
|
||||
std::cout << "fps: " << video_fps << "\tframe_count: " << video_frame_count << std::endl;
|
||||
std::cout << "fps: " << video_fps << "\tframe_count: " << video_frame_count
|
||||
<< std::endl;
|
||||
|
||||
// Create VideoWriter for output
|
||||
cv::VideoWriter video_out;
|
||||
std::string video_out_path("./");
|
||||
video_out_path += video_out_name;
|
||||
int fcc = cv::VideoWriter::fourcc('m', 'p', '4', 'v');
|
||||
video_out.open(video_out_path, fcc, video_fps, cv::Size(out_width, out_height), true);
|
||||
if (!video_out.isOpened())
|
||||
{
|
||||
video_out.open(video_out_path, fcc, video_fps,
|
||||
cv::Size(out_width, out_height), true);
|
||||
if (!video_out.isOpened()) {
|
||||
std::cout << "create video writer failed!" << std::endl;
|
||||
return;
|
||||
}
|
||||
// Capture all frames and do inference
|
||||
cv::Mat frame;
|
||||
int frame_id = 0;
|
||||
std::vector<cv::Mat> imgs;
|
||||
while (capture.read(frame)){
|
||||
if (!frame.empty())
|
||||
{
|
||||
if(frame_id < frame_num){
|
||||
imgs.push_back(frame);
|
||||
frame_id ++;
|
||||
continue;
|
||||
}
|
||||
imgs.erase(imgs.begin());
|
||||
imgs.push_back(frame);
|
||||
}
|
||||
frame_id ++;
|
||||
std::vector<cv::Mat> results;
|
||||
model.Predict(imgs, results);
|
||||
for (auto &item : results)
|
||||
{
|
||||
// cv::imshow("13",item);
|
||||
// cv::waitKey(30);
|
||||
video_out.write(item);
|
||||
std::cout << "Processing frame: "<< frame_id << std::endl;
|
||||
}
|
||||
std::vector<cv::Mat> imgs;
|
||||
while (capture.read(frame)) {
|
||||
if (!frame.empty()) {
|
||||
if (frame_id < frame_num) {
|
||||
imgs.push_back(frame);
|
||||
frame_id++;
|
||||
continue;
|
||||
}
|
||||
imgs.erase(imgs.begin());
|
||||
imgs.push_back(frame);
|
||||
}
|
||||
std::cout << "inference finished, output video saved at " << video_out_path << std::endl;
|
||||
frame_id++;
|
||||
std::vector<cv::Mat> results;
|
||||
model.Predict(imgs, results);
|
||||
for (auto& item : results) {
|
||||
// cv::imshow("13",item);
|
||||
// cv::waitKey(30);
|
||||
video_out.write(item);
|
||||
std::cout << "Processing frame: " << frame_id << std::endl;
|
||||
}
|
||||
}
|
||||
std::cout << "inference finished, output video saved at " << video_out_path
|
||||
<< std::endl;
|
||||
capture.release();
|
||||
video_out.release();
|
||||
}
|
||||
|
||||
int main(int argc, char* argv[]) {
|
||||
if (argc < 4) {
|
||||
std::cout
|
||||
<< "Usage: infer_demo path/to/model_dir path/to/video frame number run_option, "
|
||||
"e.g ./infer_model ./vsr_model_dir ./person.mp4 0 2"
|
||||
<< std::endl;
|
||||
std::cout << "Usage: infer_demo path/to/model_dir path/to/video frame "
|
||||
"number run_option, "
|
||||
"e.g ./infer_model ./vsr_model_dir ./vsr_src.mp4 0 5"
|
||||
<< std::endl;
|
||||
std::cout << "The data type of run_option is int, 0: run with cpu; 1: run "
|
||||
"with gpu; 2: run with gpu and use tensorrt backend."
|
||||
<< std::endl;
|
||||
|
@@ -17,11 +17,11 @@ wget https://bj.bcebos.com/paddlehub/fastdeploy/EDVR_M_wo_tsa_SRx4.tar
|
||||
tar -xvf EDVR_M_wo_tsa_SRx4.tar
|
||||
wget https://bj.bcebos.com/paddlehub/fastdeploy/vsr_src.mp4
|
||||
# CPU推理
|
||||
python infer.py --model EDVR_M_wo_tsa_SRx4 --video person.mp4 --frame_num 2 --device cpu
|
||||
python infer.py --model EDVR_M_wo_tsa_SRx4 --video vsr_src.mp4 --frame_num 5 --device cpu
|
||||
# GPU推理
|
||||
python infer.py --model EDVR_M_wo_tsa_SRx4 --video person.mp4 --frame_num 2 --device gpu
|
||||
python infer.py --model EDVR_M_wo_tsa_SRx4 --video vsr_src.mp4 --frame_num 5 --device gpu
|
||||
# GPU上使用TensorRT推理 (注意:TensorRT推理第一次运行,有序列化模型的操作,有一定耗时,需要耐心等待)
|
||||
python infer.py --model EDVR_M_wo_tsa_SRx4 --video person.mp4 --frame_num 2 --device gpu --use_trt True
|
||||
python infer.py --model EDVR_M_wo_tsa_SRx4 --video vsr_src.mp4 --frame_num 5 --device gpu --use_trt True
|
||||
```
|
||||
|
||||
## EDVR Python接口
|
||||
|
@@ -30,6 +30,8 @@ def build_option(args):
|
||||
option.use_gpu()
|
||||
if args.use_trt:
|
||||
option.use_trt_backend()
|
||||
option.enable_paddle_trt_collect_shape()
|
||||
option.set_trt_input_shape("x", [1, 5, 3, 180, 320])
|
||||
option.enable_paddle_to_trt()
|
||||
return option
|
||||
|
||||
@@ -56,7 +58,7 @@ print(f"fps: {video_fps}\tframe_count: {video_frame_count}")
|
||||
# Create VideoWriter for output
|
||||
video_out_dir = "./"
|
||||
video_out_path = os.path.join(video_out_dir, video_out_name)
|
||||
fucc = cv2.VideoWriter_fourcc(*"mp4v")
|
||||
fucc = cv2.VideoWriter_fourcc(* "mp4v")
|
||||
video_out = cv2.VideoWriter(video_out_path, fucc, video_fps,
|
||||
(out_width, out_height), True)
|
||||
if not video_out.isOpened():
|
||||
|
@@ -18,7 +18,7 @@
|
||||
|
||||
| 模型 | 参数大小 | 精度 | 备注 |
|
||||
|:----------------------------------------------------------------------------|:------|:----- | :------ |
|
||||
| [PP-MSVSR](https://bj.bcebos.com/paddlehub/fastdeploy/PP-MSVSR_reds_x4.tgz) | 8.8MB | - |
|
||||
| [PP-MSVSR](https://bj.bcebos.com/paddlehub/fastdeploy/PP-MSVSR_reds_x4.tar) | 8.8MB | - |
|
||||
|
||||
|
||||
## 详细部署文档
|
||||
|
@@ -20,8 +20,8 @@ const char sep = '\\';
|
||||
const char sep = '/';
|
||||
#endif
|
||||
|
||||
void CpuInfer(const std::string& model_dir,
|
||||
const std::string& video_file, int frame_num) {
|
||||
void CpuInfer(const std::string& model_dir, const std::string& video_file,
|
||||
int frame_num) {
|
||||
auto model_file = model_dir + sep + "model.pdmodel";
|
||||
auto params_file = model_dir + sep + "model.pdiparams";
|
||||
auto model = fastdeploy::vision::sr::PPMSVSR(model_file, params_file);
|
||||
@@ -32,34 +32,36 @@ void CpuInfer(const std::string& model_dir,
|
||||
}
|
||||
// note: input/output shape is [b, n, c, h, w] (n = frame_nums; b=1(default))
|
||||
// b and n is dependent on export model shape
|
||||
// see https://github.com/PaddlePaddle/PaddleGAN/blob/develop/docs/zh_CN/tutorials/video_super_resolution.md
|
||||
// see
|
||||
// https://github.com/PaddlePaddle/PaddleGAN/blob/develop/docs/zh_CN/tutorials/video_super_resolution.md
|
||||
cv::VideoCapture capture;
|
||||
// change your save video path
|
||||
std::string video_out_name = "output.mp4";
|
||||
capture.open(video_file);
|
||||
if (!capture.isOpened())
|
||||
{
|
||||
std::cout<<"can not open video "<<std::endl;
|
||||
if (!capture.isOpened()) {
|
||||
std::cout << "can not open video " << std::endl;
|
||||
return;
|
||||
}
|
||||
// Get Video info :fps, frame count
|
||||
// it used 4.x version of opencv below
|
||||
// notice your opencv version and method of api.
|
||||
int video_fps = static_cast<int>(capture.get(cv::CAP_PROP_FPS));
|
||||
int video_frame_count = static_cast<int>(capture.get(cv::CAP_PROP_FRAME_COUNT));
|
||||
int video_frame_count =
|
||||
static_cast<int>(capture.get(cv::CAP_PROP_FRAME_COUNT));
|
||||
// Set fixed size for output frame, only for msvsr model
|
||||
int out_width = 1280;
|
||||
int out_height = 720;
|
||||
std::cout << "fps: " << video_fps << "\tframe_count: " << video_frame_count << std::endl;
|
||||
std::cout << "fps: " << video_fps << "\tframe_count: " << video_frame_count
|
||||
<< std::endl;
|
||||
|
||||
// Create VideoWriter for output
|
||||
cv::VideoWriter video_out;
|
||||
std::string video_out_path("./");
|
||||
video_out_path += video_out_name;
|
||||
int fcc = cv::VideoWriter::fourcc('m', 'p', '4', 'v');
|
||||
video_out.open(video_out_path, fcc, video_fps, cv::Size(out_width, out_height), true);
|
||||
if (!video_out.isOpened())
|
||||
{
|
||||
video_out.open(video_out_path, fcc, video_fps,
|
||||
cv::Size(out_width, out_height), true);
|
||||
if (!video_out.isOpened()) {
|
||||
std::cout << "create video writer failed!" << std::endl;
|
||||
return;
|
||||
}
|
||||
@@ -67,51 +69,44 @@ void CpuInfer(const std::string& model_dir,
|
||||
cv::Mat frame;
|
||||
int frame_id = 0;
|
||||
bool reach_end = false;
|
||||
while (capture.isOpened())
|
||||
{
|
||||
while (capture.isOpened()) {
|
||||
std::vector<cv::Mat> imgs;
|
||||
for (int i = 0; i < frame_num; i++)
|
||||
{
|
||||
for (int i = 0; i < frame_num; i++) {
|
||||
capture.read(frame);
|
||||
if (!frame.empty())
|
||||
{
|
||||
if (!frame.empty()) {
|
||||
imgs.push_back(frame);
|
||||
}else{
|
||||
} else {
|
||||
reach_end = true;
|
||||
}
|
||||
}
|
||||
if (reach_end)
|
||||
{
|
||||
if (reach_end) {
|
||||
break;
|
||||
}
|
||||
std::vector<cv::Mat> results;
|
||||
model.Predict(imgs, results);
|
||||
for (auto &item : results)
|
||||
{
|
||||
for (auto& item : results) {
|
||||
// cv::imshow("13",item);
|
||||
// cv::waitKey(30);
|
||||
video_out.write(item);
|
||||
std::cout << "Processing frame: "<< frame_id << std::endl;
|
||||
std::cout << "Processing frame: " << frame_id << std::endl;
|
||||
frame_id += 1;
|
||||
}
|
||||
}
|
||||
std::cout << "inference finished, output video saved at " << video_out_path << std::endl;
|
||||
std::cout << "inference finished, output video saved at " << video_out_path
|
||||
<< std::endl;
|
||||
capture.release();
|
||||
video_out.release();
|
||||
}
|
||||
|
||||
void GpuInfer(const std::string& model_dir,
|
||||
const std::string& video_file, int frame_num) {
|
||||
void GpuInfer(const std::string& model_dir, const std::string& video_file,
|
||||
int frame_num) {
|
||||
auto model_file = model_dir + sep + "model.pdmodel";
|
||||
auto params_file = model_dir + sep + "model.pdiparams";
|
||||
|
||||
auto option = fastdeploy::RuntimeOption();
|
||||
// use paddle-TRT
|
||||
option.UseGpu();
|
||||
option.UseTrtBackend();
|
||||
option.EnablePaddleToTrt();
|
||||
auto model = fastdeploy::vision::sr::PPMSVSR(
|
||||
model_file, params_file, option);
|
||||
auto model = fastdeploy::vision::sr::PPMSVSR(model_file, params_file, option);
|
||||
|
||||
if (!model.Initialized()) {
|
||||
std::cerr << "Failed to initialize." << std::endl;
|
||||
@@ -119,32 +114,34 @@ void GpuInfer(const std::string& model_dir,
|
||||
}
|
||||
// note: input/output shape is [b, n, c, h, w] (n = frame_nums; b=1(default))
|
||||
// b and n is dependent on export model shape
|
||||
// see https://github.com/PaddlePaddle/PaddleGAN/blob/develop/docs/zh_CN/tutorials/video_super_resolution.md
|
||||
// see
|
||||
// https://github.com/PaddlePaddle/PaddleGAN/blob/develop/docs/zh_CN/tutorials/video_super_resolution.md
|
||||
cv::VideoCapture capture;
|
||||
// change your save video path
|
||||
std::string video_out_name = "output.mp4";
|
||||
capture.open(video_file);
|
||||
if (!capture.isOpened())
|
||||
{
|
||||
std::cout<<"can not open video "<<std::endl;
|
||||
if (!capture.isOpened()) {
|
||||
std::cout << "can not open video " << std::endl;
|
||||
return;
|
||||
}
|
||||
// Get Video info :fps, frame count
|
||||
int video_fps = static_cast<int>(capture.get(cv::CAP_PROP_FPS));
|
||||
int video_frame_count = static_cast<int>(capture.get(cv::CAP_PROP_FRAME_COUNT));
|
||||
int video_frame_count =
|
||||
static_cast<int>(capture.get(cv::CAP_PROP_FRAME_COUNT));
|
||||
// Set fixed size for output frame, only for msvsr model
|
||||
int out_width = 1280;
|
||||
int out_height = 720;
|
||||
std::cout << "fps: " << video_fps << "\tframe_count: " << video_frame_count << std::endl;
|
||||
std::cout << "fps: " << video_fps << "\tframe_count: " << video_frame_count
|
||||
<< std::endl;
|
||||
|
||||
// Create VideoWriter for output
|
||||
cv::VideoWriter video_out;
|
||||
std::string video_out_path("./");
|
||||
video_out_path += video_out_name;
|
||||
int fcc = cv::VideoWriter::fourcc('m', 'p', '4', 'v');
|
||||
video_out.open(video_out_path, fcc, video_fps, cv::Size(out_width, out_height), true);
|
||||
if (!video_out.isOpened())
|
||||
{
|
||||
video_out.open(video_out_path, fcc, video_fps,
|
||||
cv::Size(out_width, out_height), true);
|
||||
if (!video_out.isOpened()) {
|
||||
std::cout << "create video writer failed!" << std::endl;
|
||||
return;
|
||||
}
|
||||
@@ -152,48 +149,46 @@ void GpuInfer(const std::string& model_dir,
|
||||
cv::Mat frame;
|
||||
int frame_id = 0;
|
||||
bool reach_end = false;
|
||||
while (capture.isOpened())
|
||||
{
|
||||
while (capture.isOpened()) {
|
||||
std::vector<cv::Mat> imgs;
|
||||
for (int i = 0; i < frame_num; i++)
|
||||
{
|
||||
for (int i = 0; i < frame_num; i++) {
|
||||
capture.read(frame);
|
||||
if (!frame.empty())
|
||||
{
|
||||
if (!frame.empty()) {
|
||||
imgs.push_back(frame);
|
||||
}else{
|
||||
} else {
|
||||
reach_end = true;
|
||||
}
|
||||
}
|
||||
if (reach_end)
|
||||
{
|
||||
if (reach_end) {
|
||||
break;
|
||||
}
|
||||
std::vector<cv::Mat> results;
|
||||
model.Predict(imgs, results);
|
||||
for (auto &item : results)
|
||||
{
|
||||
for (auto& item : results) {
|
||||
// cv::imshow("13",item);
|
||||
// cv::waitKey(30);
|
||||
video_out.write(item);
|
||||
std::cout << "Processing frame: "<< frame_id << std::endl;
|
||||
std::cout << "Processing frame: " << frame_id << std::endl;
|
||||
frame_id += 1;
|
||||
}
|
||||
}
|
||||
std::cout << "inference finished, output video saved at " << video_out_path << std::endl;
|
||||
std::cout << "inference finished, output video saved at " << video_out_path
|
||||
<< std::endl;
|
||||
capture.release();
|
||||
video_out.release();
|
||||
}
|
||||
|
||||
void TrtInfer(const std::string& model_dir,
|
||||
const std::string& video_file, int frame_num) {
|
||||
void TrtInfer(const std::string& model_dir, const std::string& video_file,
|
||||
int frame_num) {
|
||||
auto model_file = model_dir + sep + "model.pdmodel";
|
||||
auto params_file = model_dir + sep + "model.pdiparams";
|
||||
auto option = fastdeploy::RuntimeOption();
|
||||
option.UseGpu();
|
||||
option.UseTrtBackend();
|
||||
auto model = fastdeploy::vision::sr::PPMSVSR(
|
||||
model_file, params_file, option);
|
||||
option.EnablePaddleTrtCollectShape();
|
||||
option.SetTrtInputShape("lqs", {1, 2, 3, 180, 320});
|
||||
option.EnablePaddleToTrt();
|
||||
auto model = fastdeploy::vision::sr::PPMSVSR(model_file, params_file, option);
|
||||
|
||||
if (!model.Initialized()) {
|
||||
std::cerr << "Failed to initialize." << std::endl;
|
||||
@@ -202,35 +197,38 @@ void TrtInfer(const std::string& model_dir,
|
||||
|
||||
// note: input/output shape is [b, n, c, h, w] (n = frame_nums; b=1(default))
|
||||
// b and n is dependent on export model shape
|
||||
// see https://github.com/PaddlePaddle/PaddleGAN/blob/develop/docs/zh_CN/tutorials/video_super_resolution.md
|
||||
// see
|
||||
// https://github.com/PaddlePaddle/PaddleGAN/blob/develop/docs/zh_CN/tutorials/video_super_resolution.md
|
||||
cv::VideoCapture capture;
|
||||
// change your save video path
|
||||
std::string video_out_name = "output.mp4";
|
||||
capture.open(video_file);
|
||||
if (!capture.isOpened())
|
||||
{
|
||||
std::cout<<"can not open video "<<std::endl;
|
||||
if (!capture.isOpened()) {
|
||||
std::cout << "can not open video " << std::endl;
|
||||
return;
|
||||
}
|
||||
// Get Video info :fps, frame count
|
||||
int video_fps = static_cast<int>(capture.get(cv::CAP_PROP_FPS));
|
||||
int video_frame_count = static_cast<int>(capture.get(cv::CAP_PROP_FRAME_COUNT));
|
||||
int video_frame_count =
|
||||
static_cast<int>(capture.get(cv::CAP_PROP_FRAME_COUNT));
|
||||
// Set fixed size for output frame, only for msvsr model
|
||||
//Note that the resolution between the size and the original input is consistent when the model is exported,
|
||||
// Note that the resolution between the size and the original input is
|
||||
// consistent when the model is exported,
|
||||
// for example: [1,2,3,180,320], after 4x super separation [1,2,3,720,1080].
|
||||
//Therefore, it is very important to derive the model
|
||||
// Therefore, it is very important to derive the model
|
||||
int out_width = 1280;
|
||||
int out_height = 720;
|
||||
std::cout << "fps: " << video_fps << "\tframe_count: " << video_frame_count << std::endl;
|
||||
std::cout << "fps: " << video_fps << "\tframe_count: " << video_frame_count
|
||||
<< std::endl;
|
||||
|
||||
// Create VideoWriter for output
|
||||
cv::VideoWriter video_out;
|
||||
std::string video_out_path("./");
|
||||
video_out_path += video_out_name;
|
||||
int fcc = cv::VideoWriter::fourcc('m', 'p', '4', 'v');
|
||||
video_out.open(video_out_path, fcc, video_fps, cv::Size(out_width, out_height), true);
|
||||
if (!video_out.isOpened())
|
||||
{
|
||||
video_out.open(video_out_path, fcc, video_fps,
|
||||
cv::Size(out_width, out_height), true);
|
||||
if (!video_out.isOpened()) {
|
||||
std::cout << "create video writer failed!" << std::endl;
|
||||
return;
|
||||
}
|
||||
@@ -238,45 +236,41 @@ void TrtInfer(const std::string& model_dir,
|
||||
cv::Mat frame;
|
||||
int frame_id = 0;
|
||||
bool reach_end = false;
|
||||
while (capture.isOpened())
|
||||
{
|
||||
while (capture.isOpened()) {
|
||||
std::vector<cv::Mat> imgs;
|
||||
for (int i = 0; i < frame_num; i++)
|
||||
{
|
||||
for (int i = 0; i < frame_num; i++) {
|
||||
capture.read(frame);
|
||||
if (!frame.empty())
|
||||
{
|
||||
if (!frame.empty()) {
|
||||
imgs.push_back(frame);
|
||||
}else{
|
||||
} else {
|
||||
reach_end = true;
|
||||
}
|
||||
}
|
||||
if (reach_end)
|
||||
{
|
||||
if (reach_end) {
|
||||
break;
|
||||
}
|
||||
std::vector<cv::Mat> results;
|
||||
model.Predict(imgs, results);
|
||||
for (auto &item : results)
|
||||
{
|
||||
for (auto& item : results) {
|
||||
// cv::imshow("13",item);
|
||||
// cv::waitKey(30);
|
||||
video_out.write(item);
|
||||
std::cout << "Processing frame: "<< frame_id << std::endl;
|
||||
std::cout << "Processing frame: " << frame_id << std::endl;
|
||||
frame_id += 1;
|
||||
}
|
||||
}
|
||||
std::cout << "inference finished, output video saved at " << video_out_path << std::endl;
|
||||
std::cout << "inference finished, output video saved at " << video_out_path
|
||||
<< std::endl;
|
||||
capture.release();
|
||||
video_out.release();
|
||||
}
|
||||
|
||||
int main(int argc, char* argv[]) {
|
||||
if (argc < 4) {
|
||||
std::cout
|
||||
<< "Usage: infer_demo path/to/model_dir path/to/video frame number run_option, "
|
||||
"e.g ./infer_model ./vsr_model_dir ./person.mp4 0 2"
|
||||
<< std::endl;
|
||||
std::cout << "Usage: infer_demo path/to/model_dir path/to/video frame "
|
||||
"number run_option, "
|
||||
"e.g ./infer_model ./vsr_model_dir ./vsr_src.mp4 0 2"
|
||||
<< std::endl;
|
||||
std::cout << "The data type of run_option is int, 0: run with cpu; 1: run "
|
||||
"with gpu; 2: run with gpu and use tensorrt backend."
|
||||
<< std::endl;
|
||||
|
@@ -17,11 +17,11 @@ wget https://bj.bcebos.com/paddlehub/fastdeploy/PP-MSVSR_reds_x4.tar
|
||||
tar -xvf PP-MSVSR_reds_x4.tar
|
||||
wget https://bj.bcebos.com/paddlehub/fastdeploy/vsr_src.mp4
|
||||
# CPU推理
|
||||
python infer.py --model PP-MSVSR_reds_x4 --video person.mp4 --frame_num 2 --device cpu
|
||||
python infer.py --model PP-MSVSR_reds_x4 --video vsr_src.mp4 --frame_num 2 --device cpu
|
||||
# GPU推理
|
||||
python infer.py --model PP-MSVSR_reds_x4 --video person.mp4 --frame_num 2 --device gpu
|
||||
python infer.py --model PP-MSVSR_reds_x4 --video vsr_src.mp4 --frame_num 2 --device gpu
|
||||
# GPU上使用TensorRT推理 (注意:TensorRT推理第一次运行,有序列化模型的操作,有一定耗时,需要耐心等待)
|
||||
python infer.py --model PP-MSVSR_reds_x4 --video person.mp4 --frame_num 2 --device gpu --use_trt True
|
||||
python infer.py --model PP-MSVSR_reds_x4 --video vsr_src.mp4 --frame_num 2 --device gpu --use_trt True
|
||||
```
|
||||
|
||||
## VSR Python接口
|
||||
|
@@ -30,6 +30,8 @@ def build_option(args):
|
||||
option.use_gpu()
|
||||
if args.use_trt:
|
||||
option.use_trt_backend()
|
||||
option.enable_paddle_trt_collect_shape()
|
||||
option.set_trt_input_shape("lqs", [1, 2, 3, 180, 320])
|
||||
option.enable_paddle_to_trt()
|
||||
return option
|
||||
|
||||
@@ -56,7 +58,7 @@ print(f"fps: {video_fps}\tframe_count: {video_frame_count}")
|
||||
# Create VideoWriter for output
|
||||
video_out_dir = "./"
|
||||
video_out_path = os.path.join(video_out_dir, video_out_name)
|
||||
fucc = cv2.VideoWriter_fourcc(*"mp4v")
|
||||
fucc = cv2.VideoWriter_fourcc(* "mp4v")
|
||||
video_out = cv2.VideoWriter(video_out_path, fucc, video_fps,
|
||||
(out_width, out_height), True)
|
||||
if not video_out.isOpened():
|
||||
|
15
fastdeploy/vision.h
Executable file → Normal file
15
fastdeploy/vision.h
Executable file → Normal file
@@ -15,9 +15,9 @@
|
||||
|
||||
#include "fastdeploy/core/config.h"
|
||||
#ifdef ENABLE_VISION
|
||||
#include "fastdeploy/vision/classification/contrib/resnet.h"
|
||||
#include "fastdeploy/vision/classification/contrib/yolov5cls.h"
|
||||
#include "fastdeploy/vision/classification/ppcls/model.h"
|
||||
#include "fastdeploy/vision/classification/contrib/resnet.h"
|
||||
#include "fastdeploy/vision/detection/contrib/nanodet_plus.h"
|
||||
#include "fastdeploy/vision/detection/contrib/scaledyolov4.h"
|
||||
#include "fastdeploy/vision/detection/contrib/yolor.h"
|
||||
@@ -29,33 +29,34 @@
|
||||
#include "fastdeploy/vision/detection/contrib/yolov7end2end_trt.h"
|
||||
#include "fastdeploy/vision/detection/contrib/yolox.h"
|
||||
#include "fastdeploy/vision/detection/ppdet/model.h"
|
||||
#include "fastdeploy/vision/facealign/contrib/face_landmark_1000.h"
|
||||
#include "fastdeploy/vision/facealign/contrib/pfld.h"
|
||||
#include "fastdeploy/vision/facealign/contrib/pipnet.h"
|
||||
#include "fastdeploy/vision/facedet/contrib/retinaface.h"
|
||||
#include "fastdeploy/vision/facedet/contrib/scrfd.h"
|
||||
#include "fastdeploy/vision/facedet/contrib/ultraface.h"
|
||||
#include "fastdeploy/vision/facedet/contrib/yolov5face.h"
|
||||
#include "fastdeploy/vision/facealign/contrib/pfld.h"
|
||||
#include "fastdeploy/vision/facealign/contrib/face_landmark_1000.h"
|
||||
#include "fastdeploy/vision/facealign/contrib/pipnet.h"
|
||||
#include "fastdeploy/vision/faceid/contrib/adaface.h"
|
||||
#include "fastdeploy/vision/faceid/contrib/arcface.h"
|
||||
#include "fastdeploy/vision/faceid/contrib/cosface.h"
|
||||
#include "fastdeploy/vision/faceid/contrib/insightface_rec.h"
|
||||
#include "fastdeploy/vision/faceid/contrib/partial_fc.h"
|
||||
#include "fastdeploy/vision/faceid/contrib/vpl.h"
|
||||
#include "fastdeploy/vision/headpose/contrib/fsanet.h"
|
||||
#include "fastdeploy/vision/keypointdet/pptinypose/pptinypose.h"
|
||||
#include "fastdeploy/vision/matting/contrib/modnet.h"
|
||||
#include "fastdeploy/vision/matting/contrib/rvm.h"
|
||||
#include "fastdeploy/vision/matting/ppmatting/ppmatting.h"
|
||||
#include "fastdeploy/vision/ocr/ppocr/classifier.h"
|
||||
#include "fastdeploy/vision/ocr/ppocr/dbdetector.h"
|
||||
#include "fastdeploy/vision/ocr/ppocr/utils/ocr_utils.h"
|
||||
#include "fastdeploy/vision/ocr/ppocr/ppocr_v2.h"
|
||||
#include "fastdeploy/vision/ocr/ppocr/ppocr_v3.h"
|
||||
#include "fastdeploy/vision/ocr/ppocr/recognizer.h"
|
||||
#include "fastdeploy/vision/ocr/ppocr/utils/ocr_utils.h"
|
||||
#include "fastdeploy/vision/segmentation/ppseg/model.h"
|
||||
#include "fastdeploy/vision/tracking/pptracking/model.h"
|
||||
#include "fastdeploy/vision/headpose/contrib/fsanet.h"
|
||||
#include "fastdeploy/vision/sr/ppsr/model.h"
|
||||
#include "fastdeploy/vision/tracking/pptracking/model.h"
|
||||
|
||||
#endif
|
||||
|
||||
#include "fastdeploy/vision/visualize/visualize.h"
|
||||
|
@@ -19,12 +19,12 @@ namespace vision {
|
||||
namespace sr {
|
||||
|
||||
BasicVSR::BasicVSR(const std::string& model_file,
|
||||
const std::string& params_file,
|
||||
const RuntimeOption& custom_option,
|
||||
const ModelFormat& model_format){
|
||||
const std::string& params_file,
|
||||
const RuntimeOption& custom_option,
|
||||
const ModelFormat& model_format) {
|
||||
// unsupported ORT backend
|
||||
valid_cpu_backends = {Backend::PDINFER};
|
||||
valid_gpu_backends = {Backend::PDINFER};
|
||||
valid_cpu_backends = {Backend::PDINFER, Backend::ORT, Backend::OPENVINO};
|
||||
valid_gpu_backends = {Backend::PDINFER, Backend::TRT, Backend::ORT};
|
||||
|
||||
runtime_option = custom_option;
|
||||
runtime_option.model_format = model_format;
|
||||
@@ -33,6 +33,6 @@ BasicVSR::BasicVSR(const std::string& model_file,
|
||||
|
||||
initialized = Initialize();
|
||||
}
|
||||
} // namespace sr
|
||||
} // namespace vision
|
||||
} // namespace fastdeploy
|
||||
} // namespace sr
|
||||
} // namespace vision
|
||||
} // namespace fastdeploy
|
@@ -19,7 +19,7 @@ namespace fastdeploy {
|
||||
namespace vision {
|
||||
namespace sr {
|
||||
|
||||
class FASTDEPLOY_DECL BasicVSR : public PPMSVSR{
|
||||
class FASTDEPLOY_DECL BasicVSR : public PPMSVSR {
|
||||
public:
|
||||
/**
|
||||
* Set path of model file and configuration file, and the configuration of runtime
|
||||
@@ -28,8 +28,7 @@ class FASTDEPLOY_DECL BasicVSR : public PPMSVSR{
|
||||
* @param[in] custom_option RuntimeOption for inference, the default will use cpu, and choose the backend defined in `valid_cpu_backends`
|
||||
* @param[in] model_format Model format of the loaded model, default is Paddle format
|
||||
*/
|
||||
BasicVSR(const std::string& model_file,
|
||||
const std::string& params_file,
|
||||
BasicVSR(const std::string& model_file, const std::string& params_file,
|
||||
const RuntimeOption& custom_option = RuntimeOption(),
|
||||
const ModelFormat& model_format = ModelFormat::PADDLE);
|
||||
/// model name contained BasicVSR
|
||||
|
@@ -18,13 +18,12 @@ namespace fastdeploy {
|
||||
namespace vision {
|
||||
namespace sr {
|
||||
|
||||
EDVR::EDVR(const std::string& model_file,
|
||||
const std::string& params_file,
|
||||
EDVR::EDVR(const std::string& model_file, const std::string& params_file,
|
||||
const RuntimeOption& custom_option,
|
||||
const ModelFormat& model_format){
|
||||
const ModelFormat& model_format) {
|
||||
// unsupported ORT backend
|
||||
valid_cpu_backends = {Backend::PDINFER};
|
||||
valid_gpu_backends = {Backend::PDINFER};
|
||||
valid_cpu_backends = {Backend::PDINFER, Backend::ORT, Backend::OPENVINO};
|
||||
valid_gpu_backends = {Backend::PDINFER, Backend::TRT, Backend::ORT};
|
||||
|
||||
runtime_option = custom_option;
|
||||
runtime_option.model_format = model_format;
|
||||
@@ -34,28 +33,31 @@ EDVR::EDVR(const std::string& model_file,
|
||||
initialized = Initialize();
|
||||
}
|
||||
|
||||
bool EDVR::Postprocess(std::vector<FDTensor>& infer_results, std::vector<cv::Mat>& results){
|
||||
bool EDVR::Postprocess(std::vector<FDTensor>& infer_results,
|
||||
std::vector<cv::Mat>& results) {
|
||||
// group to image
|
||||
// output_shape is [b, n, c, h, w] n = frame_nums b=1(default)
|
||||
// b and n is dependence export model shape
|
||||
// see https://github.com/PaddlePaddle/PaddleGAN/blob/develop/docs/zh_CN/tutorials/video_super_resolution.md
|
||||
// see
|
||||
// https://github.com/PaddlePaddle/PaddleGAN/blob/develop/docs/zh_CN/tutorials/video_super_resolution.md
|
||||
auto output_shape = infer_results[0].shape;
|
||||
// EDVR
|
||||
int h_ = output_shape[2];
|
||||
int w_ = output_shape[3];
|
||||
int c_ = output_shape[1];
|
||||
int frame_num = 1;
|
||||
float *out_data = static_cast<float *>(infer_results[0].Data());
|
||||
cv::Mat temp = cv::Mat::zeros(h_, w_, CV_32FC3); // RGB image
|
||||
float* out_data = static_cast<float*>(infer_results[0].Data());
|
||||
cv::Mat temp = cv::Mat::zeros(h_, w_, CV_32FC3); // RGB image
|
||||
int pix_num = h_ * w_;
|
||||
int frame_pix_num = pix_num * c_;
|
||||
for (int frame = 0; frame < frame_num; frame++) {
|
||||
int index = 0;
|
||||
for (int h = 0; h < h_; ++h) {
|
||||
for (int w = 0; w < w_; ++w) {
|
||||
temp.at<cv::Vec3f>(h, w) = {out_data[2 * pix_num + index + frame_pix_num * frame],
|
||||
out_data[pix_num + index + frame_pix_num * frame],
|
||||
out_data[index + frame_pix_num * frame]};
|
||||
temp.at<cv::Vec3f>(h, w) = {
|
||||
out_data[2 * pix_num + index + frame_pix_num * frame],
|
||||
out_data[pix_num + index + frame_pix_num * frame],
|
||||
out_data[index + frame_pix_num * frame]};
|
||||
index += 1;
|
||||
}
|
||||
}
|
||||
@@ -66,6 +68,6 @@ bool EDVR::Postprocess(std::vector<FDTensor>& infer_results, std::vector<cv::Mat
|
||||
}
|
||||
return true;
|
||||
}
|
||||
} // namespace sr
|
||||
} // namespace vision
|
||||
} // namespace fastdeploy
|
||||
} // namespace sr
|
||||
} // namespace vision
|
||||
} // namespace fastdeploy
|
@@ -19,8 +19,7 @@ namespace fastdeploy {
|
||||
namespace vision {
|
||||
namespace sr {
|
||||
|
||||
|
||||
class FASTDEPLOY_DECL EDVR : public PPMSVSR{
|
||||
class FASTDEPLOY_DECL EDVR : public PPMSVSR {
|
||||
public:
|
||||
/**
|
||||
* Set path of model file and configuration file, and the configuration of runtime
|
||||
@@ -29,8 +28,7 @@ class FASTDEPLOY_DECL EDVR : public PPMSVSR{
|
||||
* @param[in] custom_option RuntimeOption for inference, the default will use cpu, and choose the backend defined in `valid_cpu_backends`
|
||||
* @param[in] model_format Model format of the loaded model, default is Paddle format
|
||||
*/
|
||||
EDVR(const std::string& model_file,
|
||||
const std::string& params_file,
|
||||
EDVR(const std::string& model_file, const std::string& params_file,
|
||||
const RuntimeOption& custom_option = RuntimeOption(),
|
||||
const ModelFormat& model_format = ModelFormat::PADDLE);
|
||||
/// model name contained EDVR
|
||||
|
@@ -13,6 +13,6 @@
|
||||
// limitations under the License.
|
||||
|
||||
#pragma once
|
||||
#include "fastdeploy/vision/sr/ppsr/ppmsvsr.h"
|
||||
#include "fastdeploy/vision/sr/ppsr/edvr.h"
|
||||
#include "fastdeploy/vision/sr/ppsr/basicvsr.h"
|
||||
#include "fastdeploy/vision/sr/ppsr/edvr.h"
|
||||
#include "fastdeploy/vision/sr/ppsr/ppmsvsr.h"
|
||||
|
@@ -18,13 +18,12 @@ namespace fastdeploy {
|
||||
namespace vision {
|
||||
namespace sr {
|
||||
|
||||
PPMSVSR::PPMSVSR(const std::string& model_file,
|
||||
const std::string& params_file,
|
||||
PPMSVSR::PPMSVSR(const std::string& model_file, const std::string& params_file,
|
||||
const RuntimeOption& custom_option,
|
||||
const ModelFormat& model_format){
|
||||
const ModelFormat& model_format) {
|
||||
// unsupported ORT backend
|
||||
valid_cpu_backends = {Backend::PDINFER};
|
||||
valid_gpu_backends = {Backend::PDINFER};
|
||||
valid_cpu_backends = {Backend::PDINFER, Backend::ORT, Backend::OPENVINO};
|
||||
valid_gpu_backends = {Backend::PDINFER, Backend::TRT, Backend::ORT};
|
||||
|
||||
runtime_option = custom_option;
|
||||
runtime_option.model_format = model_format;
|
||||
@@ -34,10 +33,10 @@ PPMSVSR::PPMSVSR(const std::string& model_file,
|
||||
initialized = Initialize();
|
||||
}
|
||||
|
||||
bool PPMSVSR::Initialize(){
|
||||
bool PPMSVSR::Initialize() {
|
||||
if (!InitRuntime()) {
|
||||
FDERROR << "Failed to initialize fastdeploy backend." << std::endl;
|
||||
return false;
|
||||
FDERROR << "Failed to initialize fastdeploy backend." << std::endl;
|
||||
return false;
|
||||
}
|
||||
mean_ = {0., 0., 0.};
|
||||
scale_ = {1., 1., 1.};
|
||||
@@ -45,21 +44,20 @@ bool PPMSVSR::Initialize(){
|
||||
}
|
||||
|
||||
bool PPMSVSR::Preprocess(Mat* mat, std::vector<float>& output) {
|
||||
|
||||
BGR2RGB::Run(mat);
|
||||
Normalize::Run(mat, mean_, scale_, true);
|
||||
HWC2CHW::Run(mat);
|
||||
// Csat float
|
||||
float* ptr = static_cast<float *>(mat->Data());
|
||||
float* ptr = static_cast<float*>(mat->Data());
|
||||
size_t size = mat->Width() * mat->Height() * mat->Channels();
|
||||
output = std::vector<float>(ptr, ptr + size);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool PPMSVSR::Predict(std::vector<cv::Mat>& imgs, std::vector<cv::Mat>& results) {
|
||||
|
||||
// Theoretically, the more frame nums there are, the better the result will be,
|
||||
// but it will lead to a significant increase in memory
|
||||
bool PPMSVSR::Predict(std::vector<cv::Mat>& imgs,
|
||||
std::vector<cv::Mat>& results) {
|
||||
// Theoretically, the more frame nums there are, the better the result will
|
||||
// be, but it will lead to a significant increase in memory
|
||||
int frame_num = imgs.size();
|
||||
int rows = imgs[0].rows;
|
||||
int cols = imgs[0].cols;
|
||||
@@ -71,11 +69,12 @@ bool PPMSVSR::Predict(std::vector<cv::Mat>& imgs, std::vector<cv::Mat>& results)
|
||||
Mat mat(imgs[i]);
|
||||
std::vector<float> data_temp;
|
||||
Preprocess(&mat, data_temp);
|
||||
all_data_temp.insert(all_data_temp.end(), data_temp.begin(), data_temp.end());
|
||||
all_data_temp.insert(all_data_temp.end(), data_temp.begin(),
|
||||
data_temp.end());
|
||||
}
|
||||
// share memory in order to avoid memory copy, data type must be float32
|
||||
input_tensors[0].SetExternalData({1 ,frame_num , channels, rows, cols}, FDDataType::FP32,
|
||||
all_data_temp.data());
|
||||
input_tensors[0].SetExternalData({1, frame_num, channels, rows, cols},
|
||||
FDDataType::FP32, all_data_temp.data());
|
||||
input_tensors[0].shape = {1, frame_num, channels, rows, cols};
|
||||
input_tensors[0].name = InputInfoOfRuntime(0).name;
|
||||
std::vector<FDTensor> output_tensors;
|
||||
@@ -90,11 +89,13 @@ bool PPMSVSR::Predict(std::vector<cv::Mat>& imgs, std::vector<cv::Mat>& results)
|
||||
return true;
|
||||
}
|
||||
|
||||
bool PPMSVSR::Postprocess(std::vector<FDTensor>& infer_results, std::vector<cv::Mat>& results){
|
||||
bool PPMSVSR::Postprocess(std::vector<FDTensor>& infer_results,
|
||||
std::vector<cv::Mat>& results) {
|
||||
// group to image
|
||||
// output_shape is [b, n, c, h, w] n = frame_nums b=1(default)
|
||||
// b and n is dependence export model shape
|
||||
// see https://github.com/PaddlePaddle/PaddleGAN/blob/develop/docs/zh_CN/tutorials/video_super_resolution.md
|
||||
// see
|
||||
// https://github.com/PaddlePaddle/PaddleGAN/blob/develop/docs/zh_CN/tutorials/video_super_resolution.md
|
||||
auto output_shape = infer_results[0].shape;
|
||||
// PP-MSVSR
|
||||
int h_ = output_shape[3];
|
||||
@@ -102,17 +103,18 @@ bool PPMSVSR::Postprocess(std::vector<FDTensor>& infer_results, std::vector<cv::
|
||||
int c_ = output_shape[2];
|
||||
int frame_num = output_shape[1];
|
||||
|
||||
float *out_data = static_cast<float *>(infer_results[0].Data());
|
||||
cv::Mat temp = cv::Mat::zeros(h_, w_, CV_32FC3); // RGB image
|
||||
float* out_data = static_cast<float*>(infer_results[0].Data());
|
||||
cv::Mat temp = cv::Mat::zeros(h_, w_, CV_32FC3); // RGB image
|
||||
int pix_num = h_ * w_;
|
||||
int frame_pix_num = pix_num * c_;
|
||||
for (int frame = 0; frame < frame_num; frame++) {
|
||||
int index = 0;
|
||||
for (int h = 0; h < h_; ++h) {
|
||||
for (int w = 0; w < w_; ++w) {
|
||||
temp.at<cv::Vec3f>(h, w) = {out_data[2 * pix_num + index + frame_pix_num * frame],
|
||||
out_data[pix_num + index + frame_pix_num * frame],
|
||||
out_data[index + frame_pix_num * frame]};
|
||||
temp.at<cv::Vec3f>(h, w) = {
|
||||
out_data[2 * pix_num + index + frame_pix_num * frame],
|
||||
out_data[pix_num + index + frame_pix_num * frame],
|
||||
out_data[index + frame_pix_num * frame]};
|
||||
index += 1;
|
||||
}
|
||||
}
|
||||
@@ -123,6 +125,6 @@ bool PPMSVSR::Postprocess(std::vector<FDTensor>& infer_results, std::vector<cv::
|
||||
}
|
||||
return true;
|
||||
}
|
||||
} // namespace sr
|
||||
} // namespace vision
|
||||
} // namespace fastdeploy
|
||||
} // namespace sr
|
||||
} // namespace vision
|
||||
} // namespace fastdeploy
|
@@ -12,15 +12,14 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
#pragma once
|
||||
#include "fastdeploy/vision/common/processors/transform.h"
|
||||
#include "fastdeploy/fastdeploy_model.h"
|
||||
#include "fastdeploy/vision/common/processors/transform.h"
|
||||
|
||||
namespace fastdeploy {
|
||||
namespace vision {
|
||||
namespace sr {
|
||||
|
||||
|
||||
class FASTDEPLOY_DECL PPMSVSR:public FastDeployModel{
|
||||
class FASTDEPLOY_DECL PPMSVSR : public FastDeployModel {
|
||||
public:
|
||||
/**
|
||||
* Set path of model file and configuration file, and the configuration of runtime
|
||||
@@ -29,8 +28,7 @@ class FASTDEPLOY_DECL PPMSVSR:public FastDeployModel{
|
||||
* @param[in] custom_option RuntimeOption for inference, the default will use cpu, and choose the backend defined in `valid_cpu_backends`
|
||||
* @param[in] model_format Model format of the loaded model, default is Paddle format
|
||||
*/
|
||||
PPMSVSR(const std::string& model_file,
|
||||
const std::string& params_file,
|
||||
PPMSVSR(const std::string& model_file, const std::string& params_file,
|
||||
const RuntimeOption& custom_option = RuntimeOption(),
|
||||
const ModelFormat& model_format = ModelFormat::PADDLE);
|
||||
/// model name contained PP-MSVSR。
|
||||
|
@@ -13,58 +13,67 @@
|
||||
// limitations under the License.
|
||||
#include "fastdeploy/pybind/main.h"
|
||||
|
||||
namespace fastdeploy{
|
||||
void BindPPSR(pybind11::module &m) {
|
||||
pybind11::class_<vision::sr::PPMSVSR, FastDeployModel>(m, "PPMSVSR")
|
||||
.def(pybind11::init<std::string, std::string, RuntimeOption, ModelFormat>())
|
||||
.def("predict", [](vision::sr::PPMSVSR& self, std::vector<pybind11::array>& datas){
|
||||
std::vector<cv::Mat> inputs;
|
||||
for (auto& data: datas){
|
||||
auto mat = PyArrayToCvMat(data);
|
||||
inputs.push_back(mat);
|
||||
}
|
||||
std::vector<cv::Mat> res;
|
||||
std::vector<pybind11::array> res_pyarray;
|
||||
self.Predict(inputs, res);
|
||||
for (auto& img: res){
|
||||
auto ret = pybind11::array_t<unsigned char>({img.rows, img.cols, img.channels()}, img.data);
|
||||
res_pyarray.push_back(ret);
|
||||
}
|
||||
return res_pyarray;
|
||||
});
|
||||
pybind11::class_<vision::sr::EDVR, FastDeployModel>(m, "EDVR")
|
||||
.def(pybind11::init<std::string, std::string, RuntimeOption, ModelFormat>())
|
||||
.def("predict", [](vision::sr::EDVR& self, std::vector<pybind11::array>& datas){
|
||||
std::vector<cv::Mat> inputs;
|
||||
for (auto& data: datas){
|
||||
auto mat = PyArrayToCvMat(data);
|
||||
inputs.push_back(mat);
|
||||
}
|
||||
std::vector<cv::Mat> res;
|
||||
std::vector<pybind11::array> res_pyarray;
|
||||
self.Predict(inputs, res);
|
||||
for (auto& img: res){
|
||||
auto ret = pybind11::array_t<unsigned char>({img.rows, img.cols, img.channels()}, img.data);
|
||||
res_pyarray.push_back(ret);
|
||||
}
|
||||
return res_pyarray;
|
||||
});
|
||||
pybind11::class_<vision::sr::BasicVSR, FastDeployModel>(m, "BasicVSR")
|
||||
.def(pybind11::init<std::string, std::string, RuntimeOption, ModelFormat>())
|
||||
.def("predict", [](vision::sr::BasicVSR& self, std::vector<pybind11::array>& datas){
|
||||
std::vector<cv::Mat> inputs;
|
||||
for (auto& data: datas){
|
||||
auto mat = PyArrayToCvMat(data);
|
||||
inputs.push_back(mat);
|
||||
}
|
||||
std::vector<cv::Mat> res;
|
||||
std::vector<pybind11::array> res_pyarray;
|
||||
self.Predict(inputs, res);
|
||||
for (auto& img: res){
|
||||
auto ret = pybind11::array_t<unsigned char>({img.rows, img.cols, img.channels()}, img.data);
|
||||
res_pyarray.push_back(ret);
|
||||
}
|
||||
return res_pyarray;
|
||||
});
|
||||
namespace fastdeploy {
|
||||
void BindPPSR(pybind11::module& m) {
|
||||
pybind11::class_<vision::sr::PPMSVSR, FastDeployModel>(m, "PPMSVSR")
|
||||
.def(pybind11::init<std::string, std::string, RuntimeOption,
|
||||
ModelFormat>())
|
||||
.def("predict",
|
||||
[](vision::sr::PPMSVSR& self, std::vector<pybind11::array>& datas) {
|
||||
std::vector<cv::Mat> inputs;
|
||||
for (auto& data : datas) {
|
||||
auto mat = PyArrayToCvMat(data);
|
||||
inputs.push_back(mat);
|
||||
}
|
||||
std::vector<cv::Mat> res;
|
||||
std::vector<pybind11::array> res_pyarray;
|
||||
self.Predict(inputs, res);
|
||||
for (auto& img : res) {
|
||||
auto ret = pybind11::array_t<unsigned char>(
|
||||
{img.rows, img.cols, img.channels()}, img.data);
|
||||
res_pyarray.push_back(ret);
|
||||
}
|
||||
return res_pyarray;
|
||||
});
|
||||
pybind11::class_<vision::sr::EDVR, FastDeployModel>(m, "EDVR")
|
||||
.def(pybind11::init<std::string, std::string, RuntimeOption,
|
||||
ModelFormat>())
|
||||
.def("predict",
|
||||
[](vision::sr::EDVR& self, std::vector<pybind11::array>& datas) {
|
||||
std::vector<cv::Mat> inputs;
|
||||
for (auto& data : datas) {
|
||||
auto mat = PyArrayToCvMat(data);
|
||||
inputs.push_back(mat);
|
||||
}
|
||||
std::vector<cv::Mat> res;
|
||||
std::vector<pybind11::array> res_pyarray;
|
||||
self.Predict(inputs, res);
|
||||
for (auto& img : res) {
|
||||
auto ret = pybind11::array_t<unsigned char>(
|
||||
{img.rows, img.cols, img.channels()}, img.data);
|
||||
res_pyarray.push_back(ret);
|
||||
}
|
||||
return res_pyarray;
|
||||
});
|
||||
pybind11::class_<vision::sr::BasicVSR, FastDeployModel>(m, "BasicVSR")
|
||||
.def(pybind11::init<std::string, std::string, RuntimeOption,
|
||||
ModelFormat>())
|
||||
.def("predict",
|
||||
[](vision::sr::BasicVSR& self, std::vector<pybind11::array>& datas) {
|
||||
std::vector<cv::Mat> inputs;
|
||||
for (auto& data : datas) {
|
||||
auto mat = PyArrayToCvMat(data);
|
||||
inputs.push_back(mat);
|
||||
}
|
||||
std::vector<cv::Mat> res;
|
||||
std::vector<pybind11::array> res_pyarray;
|
||||
self.Predict(inputs, res);
|
||||
for (auto& img : res) {
|
||||
auto ret = pybind11::array_t<unsigned char>(
|
||||
{img.rows, img.cols, img.channels()}, img.data);
|
||||
res_pyarray.push_back(ret);
|
||||
}
|
||||
return res_pyarray;
|
||||
});
|
||||
}
|
||||
} // namespace fastdeploy
|
||||
|
@@ -16,10 +16,10 @@
|
||||
|
||||
namespace fastdeploy {
|
||||
|
||||
void BindPPSR(pybind11::module& m);
|
||||
void BindPPSR(pybind11::module& m);
|
||||
|
||||
void BindSR(pybind11::module& m) {
|
||||
auto sr_module = m.def_submodule("sr", "sr(super resolution) submodule");
|
||||
BindPPSR(sr_module);
|
||||
}
|
||||
void BindSR(pybind11::module& m) {
|
||||
auto sr_module = m.def_submodule("sr", "sr(super resolution) submodule");
|
||||
BindPPSR(sr_module);
|
||||
}
|
||||
} // namespace fastdeploy
|
||||
|
9
fastdeploy/vision/vision_pybind.cc
Executable file → Normal file
9
fastdeploy/vision/vision_pybind.cc
Executable file → Normal file
@@ -115,7 +115,8 @@ void BindVision(pybind11::module& m) {
|
||||
.def("__repr__", &vision::MattingResult::Str)
|
||||
.def("__str__", &vision::MattingResult::Str);
|
||||
|
||||
pybind11::class_<vision::KeyPointDetectionResult>(m, "KeyPointDetectionResult")
|
||||
pybind11::class_<vision::KeyPointDetectionResult>(m,
|
||||
"KeyPointDetectionResult")
|
||||
.def(pybind11::init())
|
||||
.def_readwrite("keypoints", &vision::KeyPointDetectionResult::keypoints)
|
||||
.def_readwrite("scores", &vision::KeyPointDetectionResult::scores)
|
||||
@@ -129,8 +130,10 @@ void BindVision(pybind11::module& m) {
|
||||
.def("__repr__", &vision::HeadPoseResult::Str)
|
||||
.def("__str__", &vision::HeadPoseResult::Str);
|
||||
|
||||
m.def("enable_flycv", &vision::EnableFlyCV, "Enable image preprocessing by FlyCV.");
|
||||
m.def("disable_flycv", &vision::DisableFlyCV, "Disable image preprocessing by FlyCV, change to use OpenCV.");
|
||||
m.def("enable_flycv", &vision::EnableFlyCV,
|
||||
"Enable image preprocessing by FlyCV.");
|
||||
m.def("disable_flycv", &vision::DisableFlyCV,
|
||||
"Disable image preprocessing by FlyCV, change to use OpenCV.");
|
||||
|
||||
BindDetection(m);
|
||||
BindClassification(m);
|
||||
|
Reference in New Issue
Block a user