Skip to content

Commit

Permalink
[Model] add function for setting anchor rknpu2 (PaddlePaddle#1728)
Browse files Browse the repository at this point in the history
* 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
Zheng-Bicheng and DefTruth authored Apr 4, 2023
1 parent a2141d0 commit 109d104
Show file tree
Hide file tree
Showing 15 changed files with 552 additions and 97 deletions.
13 changes: 9 additions & 4 deletions examples/vision/detection/rkyolo/cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,15 @@ project(rknpu2_test)

set(CMAKE_CXX_STANDARD 14)

# 指定下载解压后的fastdeploy库路径
option(FASTDEPLOY_INSTALL_DIR "Path of downloaded fastdeploy sdk.")
include(${FASTDEPLOY_INSTALL_DIR}/FastDeploy.cmake)
# 添加FastDeploy依赖头文件
include_directories(${FASTDEPLOY_INCS})
add_executable(infer_rkyolo infer_rkyolo.cc)
target_link_libraries(infer_rkyolo ${FASTDEPLOY_LIBS})

add_executable(infer_rkyolov5 infer_rkyolov5.cc)
target_link_libraries(infer_rkyolov5 ${FASTDEPLOY_LIBS})

add_executable(infer_rkyolov7 infer_rkyolov7.cc)
target_link_libraries(infer_rkyolov7 ${FASTDEPLOY_LIBS})

add_executable(infer_rkyolox infer_rkyolox.cc)
target_link_libraries(infer_rkyolox ${FASTDEPLOY_LIBS})
16 changes: 15 additions & 1 deletion examples/vision/detection/rkyolo/cpp/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,21 @@ wget https://gitee.com/paddlepaddle/PaddleDetection/raw/release/2.4/demo/0000000
cd build
cmake .. -DFASTDEPLOY_INSTALL_DIR=${PWD}/fastdeploy-linux-x64-x.x.x
make -j8
./infer_rkyolo /path/to/model 000000014439.jpg

# infer yolov5
wget https://bj.bcebos.com/paddlehub/fastdeploy/rknpu2/yolov5-s-relu.zip
unzip yolov5-s-relu.zip
./infer_rkyolov5 yolov5-s-relu/yolov5s_relu_tk2_RK3588_i8.rknn 000000014439.jpg

# infer yolov7
wget https://bj.bcebos.com/paddlehub/fastdeploy/rknpu2/yolov7-tiny.zip
unzip yolov7-tiny.zip
./infer_rkyolov7 yolov7-tiny/yolov7-tiny_tk2_RK3588_i8.rknn 000000014439.jpg

# infer yolox
wget https://bj.bcebos.com/paddlehub/fastdeploy/rknpu2/yolox-s.zip
unzip yolox-s.zip
./infer_rkyolox yolox-s/yoloxs_tk2_RK3588_i8.rknn 000000014439.jpg
```

## common problem
Expand Down
13 changes: 12 additions & 1 deletion examples/vision/detection/rkyolo/cpp/README_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,18 @@ wget https://gitee.com/paddlepaddle/PaddleDetection/raw/release/2.4/demo/0000000
cd build
cmake .. -DFASTDEPLOY_INSTALL_DIR=${PWD}/fastdeploy-linux-x64-x.x.x
make -j8
./infer_rkyolo /path/to/model 000000014439.jpg

wget https://bj.bcebos.com/paddlehub/fastdeploy/rknpu2/yolov5-s-relu.zip
unzip yolov5-s-relu.zip
./infer_rkyolov5 yolov5-s-relu/yolov5s_relu_tk2_RK3588_i8.rknn 000000014439.jpg

wget https://bj.bcebos.com/paddlehub/fastdeploy/rknpu2/yolov7-tiny.zip
unzip yolov7-tiny.zip
./infer_rkyolov7 yolov7-tiny/yolov7-tiny_tk2_RK3588_i8.rknn 000000014439.jpg

wget https://bj.bcebos.com/paddlehub/fastdeploy/rknpu2/yolox-s.zip
unzip yolox-s.zip
./infer_rkyolox yolox-s/yoloxs_tk2_RK3588_i8.rknn 000000014439.jpg
```

## 常见问题
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ void RKNPU2Infer(const std::string& model_file, const std::string& image_file) {

auto format = fastdeploy::ModelFormat::RKNN;

auto model = fastdeploy::vision::detection::RKYOLOV5(
model_file, option,format);
auto model =
fastdeploy::vision::detection::RKYOLOV5(model_file, option, format);

auto im = cv::imread(image_file);

Expand All @@ -31,7 +31,7 @@ void RKNPU2Infer(const std::string& model_file, const std::string& image_file) {
std::cerr << "Failed to predict." << std::endl;
return;
}
auto vis_im = fastdeploy::vision::VisDetection(im, res,0.5);
auto vis_im = fastdeploy::vision::VisDetection(im, res, 0.5);
tc.End();
tc.PrintInfo("RKYOLOV5 in RKNN");
std::cout << res.Str() << std::endl;
Expand All @@ -52,4 +52,3 @@ int main(int argc, char* argv[]) {

return 0;
}

54 changes: 54 additions & 0 deletions examples/vision/detection/rkyolo/cpp/infer_rkyolov7.cc
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;
}
54 changes: 54 additions & 0 deletions examples/vision/detection/rkyolo/cpp/infer_rkyolox.cc
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;
}
25 changes: 18 additions & 7 deletions examples/vision/detection/rkyolo/python/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,29 @@ Two steps before deployment
This directory provides examples that `infer.py` fast finishes the deployment of Picodet on RKNPU. The script is as follows

```bash
# Download the example code for deployment
git clone https://github.com/PaddlePaddle/FastDeploy.git
cd FastDeploy/examples/vision/detection/rkyolo/python

# Download images
# download picture
wget https://gitee.com/paddlepaddle/PaddleDetection/raw/release/2.4/demo/000000014439.jpg

# copy model
cp -r ./model /path/to/FastDeploy/examples/vision/detection/rkyolo/python

# Inference
python3 infer.py --model_file /path/to/model --image /path/to/000000014439.jpg
# infer yolov5
wget https://bj.bcebos.com/paddlehub/fastdeploy/rknpu2/yolov5-s-relu.zip
unzip yolov5-s-relu.zip
python3 infer_rkyolov5.py --model_file yolov5-s-relu/yolov5s_relu_tk2_RK3588_i8.rknn \
--image 000000014439.jpg

# infer yolov7
wget https://bj.bcebos.com/paddlehub/fastdeploy/rknpu2/yolov7-tiny.zip
unzip yolov7-tiny.zip
python3 infer_rkyolov7.py --model_file yolov7-tiny/yolov7-tiny_tk2_RK3588_i8.rknn \
--image 000000014439.jpg

# infer yolox
wget https://bj.bcebos.com/paddlehub/fastdeploy/rknpu2/yolox-s.zip
unzip yolox-s.zip
python3 infer_rkyolox.py --model_file yolox-s/yoloxs_tk2_RK3588_i8.rknn \
--image 000000014439.jpg
```

## common problem
Expand Down
25 changes: 18 additions & 7 deletions examples/vision/detection/rkyolo/python/README_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,29 @@
本目录下提供`infer.py`快速完成Picodet在RKNPU上部署的示例。执行如下脚本即可完成

```bash
# 下载部署示例代码
git clone https://github.com/PaddlePaddle/FastDeploy.git
cd FastDeploy/examples/vision/detection/rkyolo/python

# 下载图片
# download picture
wget https://gitee.com/paddlepaddle/PaddleDetection/raw/release/2.4/demo/000000014439.jpg

# copy model
cp -r ./model /path/to/FastDeploy/examples/vision/detection/rkyolo/python

# 推理
python3 infer.py --model_file /path/to/model --image /path/to/000000014439.jpg
# infer yolov5
wget https://bj.bcebos.com/paddlehub/fastdeploy/rknpu2/yolov5-s-relu.zip
unzip yolov5-s-relu.zip
python3 infer_rkyolov5.py --model_file yolov5-s-relu/yolov5s_relu_tk2_RK3588_i8.rknn \
--image 000000014439.jpg

# infer yolov7
wget https://bj.bcebos.com/paddlehub/fastdeploy/rknpu2/yolov7-tiny.zip
unzip yolov7-tiny.zip
python3 infer_rkyolov7.py --model_file yolov7-tiny/yolov7-tiny_tk2_RK3588_i8.rknn \
--image 000000014439.jpg

# infer yolox
wget https://bj.bcebos.com/paddlehub/fastdeploy/rknpu2/yolox-s.zip
unzip yolox-s.zip
python3 infer_rkyolox.py --model_file yolox-s/yoloxs_tk2_RK3588_i8.rknn \
--image 000000014439.jpg
```

## 常见问题
Expand Down
53 changes: 53 additions & 0 deletions examples/vision/detection/rkyolo/python/infer_rkyolov7.py
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")
53 changes: 53 additions & 0 deletions examples/vision/detection/rkyolo/python/infer_rkyolox.py
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")
Loading

0 comments on commit 109d104

Please sign in to comment.