[SOPHGO] Add PaddleDetection YOLOv8 example (#1165)

sophon yolov8s example

Co-authored-by: Jason <jiangjiajun@baidu.com>
This commit is contained in:
Zilong Xing
2023-01-30 11:47:07 +08:00
committed by GitHub
parent 294607fc4a
commit a709fe4813
8 changed files with 131 additions and 5 deletions

View File

@@ -14,6 +14,8 @@ include_directories(${FastDeploy_INCLUDE_DIRS})
add_executable(infer_ppyoloe ${PROJECT_SOURCE_DIR}/infer_ppyoloe.cc)
add_executable(infer_picodet ${PROJECT_SOURCE_DIR}/infer_picodet.cc)
add_executable(infer_yolov8 ${PROJECT_SOURCE_DIR}/infer_yolov8.cc)
# 添加FastDeploy库依赖
target_link_libraries(infer_ppyoloe ${FASTDEPLOY_LIBS})
target_link_libraries(infer_picodet ${FASTDEPLOY_LIBS})
target_link_libraries(infer_yolov8 ${FASTDEPLOY_LIBS})

View File

@@ -1,6 +1,6 @@
# PaddleDetection C++部署示例
本目录下提供`infer_ppyoloe.cc``infer_picodet.cc`快速完成PP-YOLOE模型和PicoDet模型在SOPHGO BM1684x板子上加速部署的示例。
本目录下提供`infer_ppyoloe.cc`,`infer_yolov8.cc``infer_picodet.cc`快速完成PP-YOLOE模型,YOLOV8模型和PicoDet模型在SOPHGO BM1684x板子上加速部署的示例。
在部署前,需确认以下两个步骤:
@@ -19,6 +19,7 @@
├── image # 存放图片的文件夹
├── infer_ppyoloe.cc
├── infer_picodet.cc
├── infer_yolov8.cc
└── model # 存放模型文件的文件夹
```

View File

@@ -0,0 +1,59 @@
// 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 <sys/time.h>
#include <iostream>
#include <string>
#include "fastdeploy/vision.h"
void SophgoInfer(const std::string& model_dir, const std::string& image_file) {
auto model_file = model_dir + "/compilation.bmodel";
auto params_file = "";
auto config_file = model_dir + "/infer_cfg.yml";
auto option = fastdeploy::RuntimeOption();
option.UseSophgo();
auto format = fastdeploy::ModelFormat::SOPHGO;
auto model = fastdeploy::vision::detection::PaddleYOLOv8(model_file, params_file, config_file, option, format);
model.GetPostprocessor().ApplyDecodeAndNMS();
auto im = cv::imread(image_file);
fastdeploy::vision::DetectionResult res;
if (!model.Predict(im, &res)) {
std::cerr << "Failed to predict." << std::endl;
return;
}
std::cout << res.Str() << std::endl;
auto vis_im = fastdeploy::vision::VisDetection(im, res);
cv::imwrite("infer_sophgo.jpg", vis_im);
std::cout << "Visualized result saved in ./infer_sophgo.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 ./yolov8_model_dir ./test.jpeg"
<< std::endl;
return -1;
}
SophgoInfer(argv[1], argv[2]);
return 0;
}