Skip to content
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

[Model] Modify SR #674

Merged
merged 125 commits into from
Nov 25, 2022
Merged
Show file tree
Hide file tree
Changes from 122 commits
Commits
Show all changes
125 commits
Select commit Hold shift + click to select a range
1684b05
first commit for yolov7
ziqi-jin Jul 13, 2022
71c00d9
pybind for yolov7
ziqi-jin Jul 14, 2022
21ab2f9
CPP README.md
ziqi-jin Jul 14, 2022
d63e862
CPP README.md
ziqi-jin Jul 14, 2022
7b3b0e2
modified yolov7.cc
ziqi-jin Jul 14, 2022
d039e80
README.md
ziqi-jin Jul 15, 2022
a34a815
python file modify
ziqi-jin Jul 18, 2022
eb010a8
merge test
ziqi-jin Jul 18, 2022
39f64f2
delete license in fastdeploy/
ziqi-jin Jul 18, 2022
d071b37
repush the conflict part
ziqi-jin Jul 18, 2022
d5026ca
README.md modified
ziqi-jin Jul 18, 2022
fb376ad
README.md modified
ziqi-jin Jul 18, 2022
4b8737c
file path modified
ziqi-jin Jul 18, 2022
ce922a0
file path modified
ziqi-jin Jul 18, 2022
6e00b82
file path modified
ziqi-jin Jul 18, 2022
8c359fb
file path modified
ziqi-jin Jul 18, 2022
906c730
file path modified
ziqi-jin Jul 18, 2022
80c1223
README modified
ziqi-jin Jul 18, 2022
6072757
README modified
ziqi-jin Jul 18, 2022
2c6e6a4
move some helpers to private
ziqi-jin Jul 18, 2022
48136f0
add examples for yolov7
ziqi-jin Jul 18, 2022
6feca92
api.md modified
ziqi-jin Jul 18, 2022
ae70d4f
api.md modified
ziqi-jin Jul 18, 2022
f591b85
api.md modified
ziqi-jin Jul 18, 2022
f0def41
YOLOv7
ziqi-jin Jul 18, 2022
15b9160
yolov7 release link
ziqi-jin Jul 18, 2022
4706e8c
yolov7 release link
ziqi-jin Jul 18, 2022
dc83584
yolov7 release link
ziqi-jin Jul 18, 2022
086debd
copyright
ziqi-jin Jul 18, 2022
4f980b9
change some helpers to private
ziqi-jin Jul 18, 2022
2e61c95
Merge branch 'develop' into develop
ziqi-jin Jul 19, 2022
80beadf
change variables to const and fix documents.
ziqi-jin Jul 19, 2022
8103772
Merge branch 'PaddlePaddle:develop' into develop
ziqi-jin Jul 19, 2022
f5f7a86
gitignore
ziqi-jin Jul 19, 2022
e6cec25
Transfer some funtions to private member of class
ziqi-jin Jul 19, 2022
e25e4f2
Transfer some funtions to private member of class
ziqi-jin Jul 19, 2022
e8a8439
Merge from develop (#9)
ziqi-jin Jul 20, 2022
a182893
first commit for yolor
ziqi-jin Jul 20, 2022
3aa015f
for merge
ziqi-jin Jul 20, 2022
d6b98aa
Develop (#11)
ziqi-jin Jul 20, 2022
871cfc6
Merge branch 'yolor' into develop
ziqi-jin Jul 20, 2022
013921a
Yolor (#16)
ziqi-jin Jul 21, 2022
7a5a6d9
Merge branch 'PaddlePaddle:develop' into develop
ziqi-jin Jul 21, 2022
c996117
Merge branch 'PaddlePaddle:develop' into develop
ziqi-jin Jul 22, 2022
0aefe32
Merge branch 'PaddlePaddle:develop' into develop
ziqi-jin Jul 26, 2022
2330414
Merge branch 'PaddlePaddle:develop' into develop
ziqi-jin Jul 26, 2022
4660161
Merge branch 'PaddlePaddle:develop' into develop
ziqi-jin Jul 27, 2022
033c18e
Merge branch 'PaddlePaddle:develop' into develop
ziqi-jin Jul 28, 2022
6c94d65
Merge branch 'PaddlePaddle:develop' into develop
ziqi-jin Jul 28, 2022
85fb256
Merge branch 'PaddlePaddle:develop' into develop
ziqi-jin Jul 29, 2022
90ca4cb
add is_dynamic for YOLO series (#22)
ziqi-jin Jul 29, 2022
f6a4ed2
Merge branch 'PaddlePaddle:develop' into develop
ziqi-jin Aug 1, 2022
3682091
Merge branch 'PaddlePaddle:develop' into develop
ziqi-jin Aug 3, 2022
ca1e110
Merge remote-tracking branch 'upstream/develop' into develop
ziqi-jin Aug 8, 2022
93ba6a6
Merge branch 'PaddlePaddle:develop' into develop
ziqi-jin Aug 9, 2022
767842e
Merge branch 'PaddlePaddle:develop' into develop
ziqi-jin Aug 10, 2022
cc32733
Merge branch 'PaddlePaddle:develop' into develop
ziqi-jin Aug 10, 2022
2771a3b
Merge branch 'PaddlePaddle:develop' into develop
ziqi-jin Aug 11, 2022
a1e29ac
Merge branch 'PaddlePaddle:develop' into develop
ziqi-jin Aug 11, 2022
5ecc6fe
Merge branch 'PaddlePaddle:develop' into develop
ziqi-jin Aug 11, 2022
2780588
Merge branch 'PaddlePaddle:develop' into develop
ziqi-jin Aug 12, 2022
c00be81
Merge branch 'PaddlePaddle:develop' into develop
ziqi-jin Aug 15, 2022
9082178
Merge branch 'PaddlePaddle:develop' into develop
ziqi-jin Aug 15, 2022
4b14f56
Merge branch 'PaddlePaddle:develop' into develop
ziqi-jin Aug 15, 2022
4876b82
Merge branch 'PaddlePaddle:develop' into develop
ziqi-jin Aug 16, 2022
9cebb1f
Merge branch 'PaddlePaddle:develop' into develop
ziqi-jin Aug 18, 2022
d1e3b29
Merge branch 'PaddlePaddle:develop' into develop
ziqi-jin Aug 19, 2022
69cf0d2
Merge branch 'PaddlePaddle:develop' into develop
ziqi-jin Aug 22, 2022
2ff10e1
Merge branch 'PaddlePaddle:develop' into develop
ziqi-jin Aug 23, 2022
a673a2c
Merge branch 'PaddlePaddle:develop' into develop
ziqi-jin Aug 25, 2022
832d777
Merge branch 'PaddlePaddle:develop' into develop
ziqi-jin Aug 25, 2022
e513eac
Merge branch 'PaddlePaddle:develop' into develop
ziqi-jin Aug 29, 2022
ded2054
Merge branch 'PaddlePaddle:develop' into develop
ziqi-jin Sep 1, 2022
19db925
modify ppmatting backend and docs
ziqi-jin Sep 1, 2022
15be4a6
modify ppmatting docs
ziqi-jin Sep 1, 2022
3a5b93a
fix the PPMatting size problem
ziqi-jin Sep 3, 2022
f765853
Merge branch 'PaddlePaddle:develop' into develop
ziqi-jin Sep 3, 2022
c2332b0
fix LimitShort's log
ziqi-jin Sep 3, 2022
950f948
retrigger ci
ziqi-jin Sep 4, 2022
64a13c9
modify PPMatting docs
ziqi-jin Sep 4, 2022
09c073d
modify the way for dealing with LimitShort
ziqi-jin Sep 6, 2022
99969b6
Merge branch 'develop' into develop
jiangjiajun Sep 6, 2022
cf248de
Merge branch 'PaddlePaddle:develop' into develop
ziqi-jin Sep 8, 2022
9d4a4c9
Merge branch 'PaddlePaddle:develop' into develop
ziqi-jin Sep 13, 2022
622fbf7
Merge branch 'PaddlePaddle:develop' into develop
ziqi-jin Sep 15, 2022
d1cf1ad
Merge branch 'PaddlePaddle:develop' into develop
ziqi-jin Sep 19, 2022
ff9a07e
Merge branch 'PaddlePaddle:develop' into develop
ziqi-jin Sep 21, 2022
2707b03
Merge branch 'PaddlePaddle:develop' into develop
ziqi-jin Sep 22, 2022
896d1d9
Merge branch 'PaddlePaddle:develop' into develop
ziqi-jin Oct 8, 2022
25ee7e2
Merge branch 'PaddlePaddle:develop' into develop
ziqi-jin Oct 12, 2022
79068d3
Merge branch 'PaddlePaddle:develop' into develop
ziqi-jin Oct 17, 2022
74b3ee0
Merge branch 'PaddlePaddle:develop' into develop
ziqi-jin Oct 21, 2022
a75c0c4
add python comments for external models
ziqi-jin Oct 21, 2022
985d273
modify resnet c++ comments
ziqi-jin Oct 21, 2022
e32a25c
modify C++ comments for external models
ziqi-jin Oct 21, 2022
8a73af6
modify python comments and add result class comments
ziqi-jin Oct 21, 2022
2aa7939
Merge branch 'develop' into doc_python
jiangjiajun Oct 22, 2022
887c53a
Merge branch 'develop' into doc_python
jiangjiajun Oct 23, 2022
963b9b9
Merge branch 'PaddlePaddle:develop' into develop
ziqi-jin Oct 24, 2022
337e8c0
fix comments compile error
ziqi-jin Oct 24, 2022
d1d6890
modify result.h comments
ziqi-jin Oct 24, 2022
67234dd
Merge branch 'develop' into doc_python
jiangjiajun Oct 24, 2022
440e2a9
Merge branch 'PaddlePaddle:develop' into develop
ziqi-jin Oct 24, 2022
ac35141
Merge branch 'doc_python' into develop
ziqi-jin Oct 24, 2022
3d83785
Merge branch 'PaddlePaddle:develop' into develop
ziqi-jin Oct 24, 2022
363a485
Merge branch 'PaddlePaddle:develop' into develop
ziqi-jin Oct 25, 2022
dc44eac
Merge branch 'PaddlePaddle:develop' into develop
ziqi-jin Oct 26, 2022
07717b4
Merge branch 'PaddlePaddle:develop' into develop
ziqi-jin Oct 26, 2022
33b4c62
Merge branch 'PaddlePaddle:develop' into develop
ziqi-jin Oct 27, 2022
f911f3b
Merge branch 'PaddlePaddle:develop' into develop
ziqi-jin Nov 1, 2022
ebb9365
Merge branch 'PaddlePaddle:develop' into develop
ziqi-jin Nov 2, 2022
0ac31bd
Merge branch 'PaddlePaddle:develop' into develop
ziqi-jin Nov 7, 2022
661a1ef
Merge branch 'PaddlePaddle:develop' into develop
ziqi-jin Nov 11, 2022
b7fbc70
Merge branch 'PaddlePaddle:develop' into develop
ziqi-jin Nov 14, 2022
710e7ea
Merge branch 'PaddlePaddle:develop' into develop
ziqi-jin Nov 17, 2022
4d2a1e3
Merge branch 'PaddlePaddle:develop' into develop
ziqi-jin Nov 22, 2022
45e97f1
Merge branch 'PaddlePaddle:develop' into develop
ziqi-jin Nov 22, 2022
d685f9d
modify examples doc and code for SR models
ziqi-jin Nov 22, 2022
6f58722
code style
ziqi-jin Nov 22, 2022
52e6b21
retrigger ci
ziqi-jin Nov 23, 2022
f2e7223
python file code style
ziqi-jin Nov 23, 2022
0f46b6c
fix examples links
ziqi-jin Nov 24, 2022
553338d
fix examples links
ziqi-jin Nov 25, 2022
e316a5e
Merge branch 'sr_pr' of github.com:ziqi-jin/FastDeploy into sr_pr
ziqi-jin Nov 25, 2022
1d8f4d4
fix examples links
ziqi-jin Nov 25, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion examples/vision/sr/basicvsr/cpp/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ cmake .. -DFASTDEPLOY_INSTALL_DIR=${PWD}/fastdeploy-linux-x64-x.x.x
make -j

# 下载BasicVSR模型文件和测试视频
wget https://bj.bcebos.com/paddlehub/fastdeploy/BasicVSR_reds_x4.tar
wget https://bj.bcebos.com/paddlehub/fastdeploy/BasicVSR_reds_x4.tgz
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tar

tar -xvf BasicVSR_reds_x4.tar
wget https://bj.bcebos.com/paddlehub/fastdeploy/vsr_src.mp4

Expand Down
163 changes: 80 additions & 83 deletions examples/vision/sr/basicvsr/cpp/infer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -32,167 +32,165 @@ 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;
}
// Capture all frames and do inference
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;
return;
}
// 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;
}
// Capture all frames and do inference
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;
Expand All @@ -201,81 +199,80 @@ 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;
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;
Expand Down
8 changes: 4 additions & 4 deletions examples/vision/sr/basicvsr/python/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@ git clone https://github.com/PaddlePaddle/FastDeploy.git
cd FastDeploy/examples/vision/sr/basicvsr/python

# 下载BasicVSR模型文件和测试视频
wget https://bj.bcebos.com/paddlehub/fastdeploy/BasicVSR_reds_x4.tar
wget https://bj.bcebos.com/paddlehub/fastdeploy/BasicVSR_reds_x4.tgz
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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接口
Expand Down
4 changes: 3 additions & 1 deletion examples/vision/sr/basicvsr/python/infer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -56,7 +58,7 @@ def build_option(args):
# 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():
Expand Down
Loading