forked from PaddlePaddle/FastDeploy
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Model] add function for setting anchor rknpu2 (PaddlePaddle#1728)
* add function for setting anchor rknpu2 add more demo for rknpu2 fixed md error * Update config.h --------- Co-authored-by: DefTruth <[email protected]>
- Loading branch information
1 parent
a2141d0
commit 109d104
Showing
15 changed files
with
552 additions
and
97 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
// Copyright (c) 2022 PaddlePaddle Authors. All Rights Reserved. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
#include "fastdeploy/vision.h" | ||
|
||
void RKNPU2Infer(const std::string& model_file, const std::string& image_file) { | ||
auto option = fastdeploy::RuntimeOption(); | ||
option.UseRKNPU2(); | ||
|
||
auto format = fastdeploy::ModelFormat::RKNN; | ||
|
||
auto model = | ||
fastdeploy::vision::detection::RKYOLOV7(model_file, option, format); | ||
|
||
auto im = cv::imread(image_file); | ||
|
||
fastdeploy::vision::DetectionResult res; | ||
fastdeploy::TimeCounter tc; | ||
tc.Start(); | ||
if (!model.Predict(im, &res)) { | ||
std::cerr << "Failed to predict." << std::endl; | ||
return; | ||
} | ||
auto vis_im = fastdeploy::vision::VisDetection(im, res, 0.5); | ||
tc.End(); | ||
tc.PrintInfo("RKYOLOV5 in RKNN"); | ||
std::cout << res.Str() << std::endl; | ||
cv::imwrite("vis_result.jpg", vis_im); | ||
std::cout << "Visualized result saved in ./vis_result.jpg" << std::endl; | ||
} | ||
|
||
int main(int argc, char* argv[]) { | ||
if (argc < 3) { | ||
std::cout | ||
<< "Usage: infer_demo path/to/model_dir path/to/image run_option, " | ||
"e.g ./infer_model ./picodet_model_dir ./test.jpeg" | ||
<< std::endl; | ||
return -1; | ||
} | ||
|
||
RKNPU2Infer(argv[1], argv[2]); | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
// Copyright (c) 2022 PaddlePaddle Authors. All Rights Reserved. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
#include "fastdeploy/vision.h" | ||
|
||
void RKNPU2Infer(const std::string& model_file, const std::string& image_file) { | ||
auto option = fastdeploy::RuntimeOption(); | ||
option.UseRKNPU2(); | ||
|
||
auto format = fastdeploy::ModelFormat::RKNN; | ||
|
||
auto model = | ||
fastdeploy::vision::detection::RKYOLOX(model_file, option, format); | ||
|
||
auto im = cv::imread(image_file); | ||
|
||
fastdeploy::vision::DetectionResult res; | ||
fastdeploy::TimeCounter tc; | ||
tc.Start(); | ||
if (!model.Predict(im, &res)) { | ||
std::cerr << "Failed to predict." << std::endl; | ||
return; | ||
} | ||
auto vis_im = fastdeploy::vision::VisDetection(im, res, 0.5); | ||
tc.End(); | ||
tc.PrintInfo("RKYOLOV5 in RKNN"); | ||
std::cout << res.Str() << std::endl; | ||
cv::imwrite("vis_result.jpg", vis_im); | ||
std::cout << "Visualized result saved in ./vis_result.jpg" << std::endl; | ||
} | ||
|
||
int main(int argc, char* argv[]) { | ||
if (argc < 3) { | ||
std::cout | ||
<< "Usage: infer_demo path/to/model_dir path/to/image run_option, " | ||
"e.g ./infer_model ./picodet_model_dir ./test.jpeg" | ||
<< std::endl; | ||
return -1; | ||
} | ||
|
||
RKNPU2Infer(argv[1], argv[2]); | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
# Copyright (c) 2022 PaddlePaddle Authors. All Rights Reserved. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
import fastdeploy as fd | ||
import cv2 | ||
import os | ||
|
||
|
||
def parse_arguments(): | ||
import argparse | ||
import ast | ||
parser = argparse.ArgumentParser() | ||
parser.add_argument( | ||
"--model_file", required=True, help="Path of rknn model.") | ||
parser.add_argument( | ||
"--image", type=str, required=True, help="Path of test image file.") | ||
return parser.parse_args() | ||
|
||
|
||
if __name__ == "__main__": | ||
args = parse_arguments() | ||
|
||
model_file = args.model_file | ||
params_file = "" | ||
|
||
# 配置runtime,加载模型 | ||
runtime_option = fd.RuntimeOption() | ||
runtime_option.use_rknpu2() | ||
|
||
model = fd.vision.detection.RKYOLOV7( | ||
model_file, | ||
runtime_option=runtime_option, | ||
model_format=fd.ModelFormat.RKNN) | ||
|
||
# 预测图片分割结果 | ||
im = cv2.imread(args.image) | ||
result = model.predict(im) | ||
print(result) | ||
|
||
# 可视化结果 | ||
vis_im = fd.vision.vis_detection(im, result, score_threshold=0.5) | ||
cv2.imwrite("visualized_result.jpg", vis_im) | ||
print("Visualized result save in ./visualized_result.jpg") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
# Copyright (c) 2022 PaddlePaddle Authors. All Rights Reserved. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
import fastdeploy as fd | ||
import cv2 | ||
import os | ||
|
||
|
||
def parse_arguments(): | ||
import argparse | ||
import ast | ||
parser = argparse.ArgumentParser() | ||
parser.add_argument( | ||
"--model_file", required=True, help="Path of rknn model.") | ||
parser.add_argument( | ||
"--image", type=str, required=True, help="Path of test image file.") | ||
return parser.parse_args() | ||
|
||
|
||
if __name__ == "__main__": | ||
args = parse_arguments() | ||
|
||
model_file = args.model_file | ||
params_file = "" | ||
|
||
# 配置runtime,加载模型 | ||
runtime_option = fd.RuntimeOption() | ||
runtime_option.use_rknpu2() | ||
|
||
model = fd.vision.detection.RKYOLOX( | ||
model_file, | ||
runtime_option=runtime_option, | ||
model_format=fd.ModelFormat.RKNN) | ||
|
||
# 预测图片分割结果 | ||
im = cv2.imread(args.image) | ||
result = model.predict(im) | ||
print(result) | ||
|
||
# 可视化结果 | ||
vis_im = fd.vision.vis_detection(im, result, score_threshold=0.5) | ||
cv2.imwrite("visualized_result.jpg", vis_im) | ||
print("Visualized result save in ./visualized_result.jpg") |
Oops, something went wrong.