|
+
+
+## **地域交流**
+
+* **Slack**:Join our [Slack community](https://join.slack.com/t/fastdeployworkspace/shared_invite/zt-1jznah134-3rxY~ytRb8rcPqkn9g~PDg) and chat with other community members about ideas
+
+* **WeChat**: QRコードをスキャンしてアンケートに回答すると、テクニカルコミュニティに参加でき、コミュニティの開発者と導入時の問題点や解決策について議論することができます。
+
+
|
+
+
+## **Обмен сообществами**
+
+* **Slack**:Join our [Slack community](https://join.slack.com/t/fastdeployworkspace/shared_invite/zt-1jznah134-3rxY~ytRb8rcPqkn9g~PDg) and chat with other community members about ideas
+
+* **WeChat**: Отсканируйте QR-код и заполните анкету, чтобы присоединиться к техническому сообществу и обсудить болевые точки развертывания и решения с разработчиками сообщества
+
+
+
+
+
+## Каталог
+
+* **🖥️Развертывание на стороне сервера**
+
+ * [Python SDK Quick Start](#fastdeploy-quick-start-python)
+ * [C++ SDK Quick Start](#fastdeploy-quick-start-cpp)
+ * [Список поддержки моделей на стороне сервера](#fastdeploy-server-models)
+
+* **📲 Мобильные и конечные развертывания**
+
+ * [Список поддержки конечных моделей](#fastdeploy-edge-models)
+
+* **🌐 Развертывание веб и апплетов**
+
+ * [Список поддержки веб-моделей](#fastdeploy-web-models)
+* [Acknowledge](#fastdeploy-acknowledge)
+* [License](#fastdeploy-license)
+
+## 🖥️ Развертывание на стороне сервера
+
+
+
+
+
+ Быстрый старт Python SDK (нажмите для получения подробной информации)
+
+#### Быстрая установка
+
+##### Предварительные зависимости
+
+- CUDA >= 11.2、cuDNN >= 8.0、Python >= 3.6
+- OS: Linux x86_64/macOS/Windows 10
+
+##### Установка версии GPU
+
+```bash
+pip install numpy opencv-python fastdeploy-gpu-python -f https://www.paddlepaddle.org.cn/whl/fastdeploy.html
+```
+
+##### [установка Conda (рекомендуется)](docs/cn/build_and_install/download_prebuilt_libraries.md)
+
+```bash
+conda config --add channels conda-forge && conda install cudatoolkit=11.2 cudnn=8.2
+```
+
+##### Установка CPU процессора
+
+```bash
+pip install numpy opencv-python fastdeploy-python -f https://www.paddlepaddle.org.cn/whl/fastdeploy.html
+```
+
+#### Пример умозаключения в Python
+
+* Подготовка модели и изображений
+
+```bash
+wget https://bj.bcebos.com/paddlehub/fastdeploy/ppyoloe_crn_l_300e_coco.tgz
+tar xvf ppyoloe_crn_l_300e_coco.tgz
+wget https://gitee.com/paddlepaddle/PaddleDetection/raw/release/2.4/demo/000000014439.jpg
+```
+
+* Проверка результатов вывода
+
+```python
+# GPU/TensorRT Справочник по развертыванию examples/vision/detection/paddledetection/python
+import cv2
+import fastdeploy.vision as vision
+
+model = vision.detection.PPYOLOE("ppyoloe_crn_l_300e_coco/model.pdmodel",
+ "ppyoloe_crn_l_300e_coco/model.pdiparams",
+ "ppyoloe_crn_l_300e_coco/infer_cfg.yml")
+im = cv2.imread("000000014439.jpg")
+result = model.predict(im.copy())
+print(result)
+
+vis_im = vision.vis_detection(im, result, score_threshold=0.5)
+cv2.imwrite("vis_image.jpg", vis_im)
+
+```
+
+
+
+
+
+
+
+ C++ SDK Quick Start (нажмите для получения подробной информации)
+
+
+#### Установка
+
+Обратитесь к документации [C++ prebuilt libraries download](docs/cn/build_and_install/download_prebuilt_libraries.md)
+
+#### Пример вывода в C++
+
+* Подготовка моделей и фотографий
+
+```bash
+wget https://bj.bcebos.com/paddlehub/fastdeploy/ppyoloe_crn_l_300e_coco.tgz
+tar xvf ppyoloe_crn_l_300e_coco.tgz
+wget https://gitee.com/paddlepaddle/PaddleDetection/raw/release/2.4/demo/000000014439.jpg
+```
+
+* Результаты рассуждений при тестировании
+
+```C++
+// GPU/TensorRT Ссылка на развертывание examples/vision/detection/paddledetection/cpp
+#include "fastdeploy/vision.h"
+
+int main(int argc, char* argv[]) {
+ namespace vision = fastdeploy::vision;
+ auto model = vision::detection::PPYOLOE("ppyoloe_crn_l_300e_coco/model.pdmodel",
+ "ppyoloe_crn_l_300e_coco/model.pdiparams",
+ "ppyoloe_crn_l_300e_coco/infer_cfg.yml");
+ auto im = cv::imread("000000014439.jpg");
+
+ vision::DetectionResult res;
+ model.Predict(&im, &res);
+
+ auto vis_im = vision::Visualize::VisDetection(im, res, 0.5);
+ cv::imwrite("vis_image.jpg", vis_im);
+ return 0;
+}
+```
+
+
+
+Дополнительные примеры развертывания см. в разделе [Примеры развертывания модели] (examples).
+
+
+
+### Список поддержки моделей на стороне сервера🔥🔥🔥🔥🔥
+
+Описание символов: (1) ✅: Уже поддерживается; (2) ❔:Текущий; (3) N/A:В настоящее время не поддерживается;
+
+ Список поддержки моделей на стороне сервера (нажмите, чтобы уменьшить)
+
+
+
+## 📲 Мобильное и конечное развертывание 🔥🔥🔥🔥
+
+
+
+### Список поддержки конечных моделей
+ Список поддержки конечных моделей (нажмите, чтобы уменьшить)
+
+
+
+
+## Acknowledge
+
+Для создания и загрузки SDK в этом проекте используются бесплатные и открытые возможности в [EasyEdge](https://ai.baidu.com/easyedge/app/openSource), за что мы хотели бы поблагодарить вас.
+
+## License
+
+
+
+FastDeploy следует [протоколу Apache-2.0 с открытым исходным кодом](. /LICENSE).
diff --git a/docs/docs_i18n/README_हिन्दी.md b/docs/docs_i18n/README_हिन्दी.md
new file mode 100644
index 000000000..46113bee8
--- /dev/null
+++ b/docs/docs_i18n/README_हिन्दी.md
@@ -0,0 +1,334 @@
+[English](../../README_EN.md) | [简体中文](../../README_CN.md) | हिन्दी | [日本語](./README_日本語.md) | [한국인](./README_한국어.md) | [Pу́сский язы́к](.//README_Ру́сский_язы́к.md)
+
+
+
+
+
+
+
+**⚡️फास्टडिप्लोय**एक एआई अनुमान तैनाती उपकरण है जो **सभी परिदृश्य**, **उपयोग करने में आसान और लचीला** और **बेहद कुशल** है। एक📦**आउट-ऑफ-द-बॉक्स** **क्लाउड-एज** परिनियोजन अनुभव प्रदान करता है, 🔥150+ से अधिक **टेक्स्ट**, **विजन**, **स्पीच** और **क्रॉस-मोडल** मॉडल का समर्थन करता है, और 🔚 **एंड-टू-एंड** अनुमान प्रदर्शन अनुकूलन को लागू करता है। डेवलपर्स की जरूरतों को पूरा करने के लिए छवि वर्गीकरण, ऑब्जेक्ट डिटेक्शन, छवि विभाजन, चेहरे का पता लगाने, चेहरे की पहचान, मुख्य बिंदु का पता लगाने, कटआउट, ओसीआर, एनएलपी, टीटीएस और अन्य कार्यों सहित **बहु-परिदृश्य, बहु-हार्डवेयर, बहु-मंच** उद्योग की तैनाती की जरूरत है।
+| [Image Classification](examples/vision/classification) | [Object Detection](examples/vision/detection) | [Semantic Segmentation](examples/vision/segmentation/paddleseg) | [Potrait Segmentation](examples/vision/segmentation/paddleseg) |
+|:----------------------------------------------------------------------------------------------------------------------------------------------:|:----------------------------------------------------------------------------------------------------------------------------------------------:|:------------------------------------------------------------------------------------------------------------------------------------------------:|:------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------:|
+| | | | |
+| [**Image Matting**](examples/vision/matting) | [**Real-Time Matting**](examples/vision/matting) | [**OCR**](examples/vision/ocr) | [**Face Alignment**](examples/vision/facealign) |
+| | | | |
+| [**Pose Estimation**](examples/vision/keypointdetection) | [**Behavior Recognition**](https://github.com/PaddlePaddle/FastDeploy/issues/6) | [**NLP**](examples/text) | [**Speech**](examples/audio/pp-tts) |
+| | | |
|
+
+
+## **सामुदायिक संचार**
+
+* **Slack**:Join our [Slack community](https://join.slack.com/t/fastdeployworkspace/shared_invite/zt-1jznah134-3rxY~ytRb8rcPqkn9g~PDg) and chat with other community members about ideas
+
+* **वीचैट**: क्यूआर कोड स्कैन करें, तकनीकी समुदाय में शामिल होने के लिए प्रश्नावली भरें, और सामुदायिक डेवलपर्स के साथ तैनाती के दर्द बिंदुओं और समाधानों पर चर्चा करें
+
+
+
+
+
+## डायरेक्टरी
+
+* **🖥️ सर्वर-साइड परिनियोजन**
+
+ * [Python SDK एक त्वरित शुरुआत है](#fastdeploy-quick-start-python)
+ * [C++ SDK एक त्वरित शुरुआत है](#fastdeploy-quick-start-cpp)
+ * [सर्वर-साइड मॉडल समर्थन सूची](#fastdeploy-server-models)
+
+* **📲 मोबाइल और एंड-साइड परिनियोजन**
+
+ * [एंड-साइड मॉडल समर्थन सूची](#fastdeploy-edge-models)
+
+* **🌐 और एप्लेट तैनाती**
+
+ * [Web-साइड मॉडल समर्थन सूची](#fastdeploy-web-models)
+* [Acknowledge](#fastdeploy-acknowledge)
+* [License](#fastdeploy-license)
+
+## 🖥️ सर्वर-साइड परिनियोजन
+
+
+
+
+
+पायथन एसडीके क्विक स्टार्ट (विवरण के लिए यहां क्लिक करें)
+
+#### त्वरित स्थापना
+
+##### पूर्व-निर्भरता
+
+- CUDA >= 11.2、cuDNN >= 8.0、Python >= 3.6
+- OS: Linux x86_64/macOS/Windows 10
+
+##### संस्करण स्थापित करें
+
+```bash
+pip install numpy opencv-python fastdeploy-gpu-python -f https://www.paddlepaddle.org.cn/whl/fastdeploy.html
+```
+
+##### [Conda स्थापना (अनुशंसित) ](docs/cn/build_and_install/download_prebuilt_libraries.md)
+
+```bash
+conda config --add channels conda-forge && conda install cudatoolkit=11.2 cudnn=8.2
+```
+
+##### CPU संस्करण स्थापित करें
+
+```bash
+pip install numpy opencv-python fastdeploy-python -f https://www.paddlepaddle.org.cn/whl/fastdeploy.html
+```
+
+#### Python अनुमान उदाहरण
+
+* मॉडल और चित्र तैयार करें
+
+```bash
+wget https://bj.bcebos.com/paddlehub/fastdeploy/ppyoloe_crn_l_300e_coco.tgz
+tar xvf ppyoloe_crn_l_300e_coco.tgz
+wget https://gitee.com/paddlepaddle/PaddleDetection/raw/release/2.4/demo/000000014439.jpg
+```
+
+* परीक्षण अनुमान परिणाम
+
+```python
+# GPU/TensorRT तैनाती संदर्भ examples/vision/detection/paddledetection/python
+import cv2
+import fastdeploy.vision as vision
+
+model = vision.detection.PPYOLOE("ppyoloe_crn_l_300e_coco/model.pdmodel",
+ "ppyoloe_crn_l_300e_coco/model.pdiparams",
+ "ppyoloe_crn_l_300e_coco/infer_cfg.yml")
+im = cv2.imread("000000014439.jpg")
+result = model.predict(im.copy())
+print(result)
+
+vis_im = vision.vis_detection(im, result, score_threshold=0.5)
+cv2.imwrite("vis_image.jpg", vis_im)
+
+```
+
+
+
+
+
+
+
+ C++ SDK त्वरित प्रारंभ (विवरण के लिए यहां क्लिक करें)
+
+
+#### संस्थापन
+
+C++ SDK त्वरित प्रारंभ (विवरण के लिए क्लिक करें)(docs/cn/build_and_install/download_prebuilt_libraries.md)文档
+
+#### C++ अनुमान उदाहरण
+
+* मॉडल और चित्र तैयार करें
+
+```bash
+wget https://bj.bcebos.com/paddlehub/fastdeploy/ppyoloe_crn_l_300e_coco.tgz
+tar xvf ppyoloe_crn_l_300e_coco.tgz
+wget https://gitee.com/paddlepaddle/PaddleDetection/raw/release/2.4/demo/000000014439.jpg
+```
+
+* अनुमान परिणामों का परीक्षण करें
+
+```C++
+// GPU/TensorRTपरिनियोजन संदर्भ examples/vision/detection/paddledetection/cpp
+#include "fastdeploy/vision.h"
+
+int main(int argc, char* argv[]) {
+ namespace vision = fastdeploy::vision;
+ auto model = vision::detection::PPYOLOE("ppyoloe_crn_l_300e_coco/model.pdmodel",
+ "ppyoloe_crn_l_300e_coco/model.pdiparams",
+ "ppyoloe_crn_l_300e_coco/infer_cfg.yml");
+ auto im = cv::imread("000000014439.jpg");
+
+ vision::DetectionResult res;
+ model.Predict(&im, &res);
+
+ auto vis_im = vision::Visualize::VisDetection(im, res, 0.5);
+ cv::imwrite("vis_image.jpg", vis_im);
+ return 0;
+}
+```
+
+
+
+अधिक परिनियोजन उदाहरणों के लिए, कृपया मॉडल परिनियोजन उदाहरण देखें(examples) .
+
+
+
+### सर्वर-साइड मॉडल समर्थन सूची 🔥🔥🔥🔥🔥
+
+प्रतीक विवरण: (1) ✅: पहले से समर्थित; (2) ❔:गति पर ; (3) N/A: समर्थित नहीं;
+
+ सर्वर-साइड मॉडल समर्थन सूची (ढहने के लिए क्लिक करें)
+
+
+
+
+## Acknowledge
+
+यह परियोजना SDK पीढ़ी और डाउनलोड हम [EasyEdge](https://ai.baidu.com/easyedge/app/openSource) में मुक्त और खुली क्षमताओं का उपयोग करने के लिए आभारी हैं।
+
+## License
+
+
+
+FastDeploy निम्नानुसार है [Apache-2.0 खुला स्रोत लाइसेंस](./LICENSE)。
diff --git a/docs/docs_i18n/README_한국어.md b/docs/docs_i18n/README_한국어.md
new file mode 100644
index 000000000..f9ca96d1e
--- /dev/null
+++ b/docs/docs_i18n/README_한국어.md
@@ -0,0 +1,335 @@
+[English](../../README_EN.md) | [简体中文](../../README_CN.md) | [हिन्दी](./README_हिन्दी.md) | [日本語](./README_日本語.md) | 한국인 | [Pу́сский язы́к](.//README_Ру́сский_язы́к.md)
+
+
+
+
+
+
|
+
+
+## **지역 사회 교류**
+
+* **Slack**:Join our [Slack community](https://join.slack.com/t/fastdeployworkspace/shared_invite/zt-1jznah134-3rxY~ytRb8rcPqkn9g~PDg) and chat with other community members about ideas
+
+* **위챗**: QR 코드를 스캔하고 설문지를 기입하여 기술 커뮤니티에 가입하며 커뮤니티 개발자와 함께 배치의 통점과 방안을 토론한다
+
+
+
+
+
+## 목록
+
+* **🖥️ 서버측 배포**
+
+ * [Python SDK 빠른 시작](#fastdeploy-quick-start-python)
+ * [C++ SDK 시작](#fastdeploy-quick-start-cpp)
+ * [서비스 모델 지원 목록](#fastdeploy-server-models)
+
+* **📲 모바일 및 측면 배치**
+
+ * [측면 모델 지원 목록](#fastdeploy-edge-models)
+
+* **🌐 웹과 애플릿 배포**
+
+ * [웹 쪽 모델 지원 목록](#fastdeploy-web-models)
+* [Acknowledge](#fastdeploy-acknowledge)
+* [License](#fastdeploy-license)
+
+## 🖥️ 서비스 배포
+
+
+
+
+
+파이썬 SDK 빠른 시작 (자세한내용은 클릭)
+
+더 많은 배치 사례를 참고하시기 바랍니다 [모델 배포 예제](examples).
+
+
+
+### 서비스 모델 지원 목록🔥🔥🔥🔥🔥
+
+부호 설명: (1) ✅: 지원 되여 있어야 한다; (2) ❔:진행 중이다; (3) N/A:지원되지 않습니다;
+
+ 서비스 모델 지원 목록 (누르면 축소 가능)
|
-## 👬 Community
- - **Slack**:Join our [Slack community](https://join.slack.com/t/fastdeployworkspace/shared_invite/zt-1jznah134-3rxY~ytRb8rcPqkn9g~PDg) and chat with other community members about ideas.
- - **WeChat**:Scan the QR code below using WeChat, follow the PaddlePaddle official account and fill out the questionnaire to join the WeChat group.
+## 📣 Recent updates
+- 💥 **Live Preview: Dec 12 - Dec 30, China Standard Time, 20:30,** FastDeploy has joined hands with ten hardware vendor partners to launch the deployment month `The Complete Guide to Deploying Industrial Grade AI Models`.
+ - Scan the QR code below using WeChat, follow the PaddlePaddle official account and fill out the questionnaire to join the WeChat group
-
-
-
+
+
+
## Contents
@@ -318,6 +319,16 @@ Notes: ✅: already supported; ❔: to be supported in the future; N/A: Not Ava
| OCR | [PaddleOCR/PP-OCRv3](./examples/application/js/web_demo/src/pages/cv/ocr) | ✅ |
+
+## 👬 Community
+
+ - **Slack**:Join our [Slack community](https://join.slack.com/t/fastdeployworkspace/shared_invite/zt-1jznah134-3rxY~ytRb8rcPqkn9g~PDg) and chat with other community members about ideas.
+
+ - **WeChat**:Scan the QR code below using WeChat, follow the PaddlePaddle official account and fill out the questionnaire to join the WeChat group.
+
+
|
-## **社区交流**
+## 📣 最新消息
-* **Slack**:Join our [Slack community](https://join.slack.com/t/fastdeployworkspace/shared_invite/zt-1jznah134-3rxY~ytRb8rcPqkn9g~PDg) and chat with other community members about ideas
-
-* **微信**:扫描二维码,填写问卷加入技术社区,与社区开发者探讨部署的痛点与方案
+- **💥直播预告:2022.12.12 ~ 2022.12.30日每晚20:30,联合十家硬件厂商伙伴,推出部署月《产业级AI模型部署全攻略》**。微信扫描下方二维码,关注公众号并填写问卷后进入官方交流群,与行业精英共同探讨AI部署话题。
-
+
+
## 目录
* **🖥️ 服务器端部署**
@@ -322,6 +321,16 @@ int main(int argc, char* argv[]) {
+## **社区交流**
+
+* **Slack**:Join our [Slack community](https://join.slack.com/t/fastdeployworkspace/shared_invite/zt-1jznah134-3rxY~ytRb8rcPqkn9g~PDg) and chat with other community members about ideas
+
+* **微信**:扫描二维码,填写问卷加入技术社区,与社区开发者探讨部署的痛点与方案
+
+
+
+
+
From d6d7df4472d7715a686835772ed65e05ef686ca8 Mon Sep 17 00:00:00 2001
From: leiqing <54695910+leiqing1@users.noreply.github.com>
Date: Tue, 13 Dec 2022 17:14:27 +0800
Subject: [PATCH 38/77] Update README_EN.md
---
README_EN.md | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/README_EN.md b/README_EN.md
index 58711bc06..820f8b047 100755
--- a/README_EN.md
+++ b/README_EN.md
@@ -1,4 +1,4 @@
-English | [简体中文](README_CN.md) | [हिन्दी](./docs/docs_i18n/README_हिन्दी.md) | [日本語](./docs/docs_i18n/README_日本語.md) | [한국인](./docs/docs_i18n/README_한국어.md) | [Pу́сский язы́к](./docs/docs_i18n/README_Ру́сский_язы́к.md)
+English | [简体中文](README_CN.md) | [हिन्दी](./docs/docs_i18n/README_हिन्दी.md) | [日本語](./docs/docs_i18n/README_日本語.md) | [한국인](./docs/docs_i18n/README_한국어.md) | [Pу́сский язы́к](./docs/docs_i18n/README_Ру́сский_язы́к.md)

From c64b24e4f2dd7add6980b4274da7b637790c44ed Mon Sep 17 00:00:00 2001
From: leiqing <54695910+leiqing1@users.noreply.github.com>
Date: Tue, 13 Dec 2022 17:15:20 +0800
Subject: [PATCH 39/77] Update README_EN.md
---
README_EN.md | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/README_EN.md b/README_EN.md
index 820f8b047..3abffec44 100755
--- a/README_EN.md
+++ b/README_EN.md
@@ -1,4 +1,4 @@
-English | [简体中文](README_CN.md) | [हिन्दी](./docs/docs_i18n/README_हिन्दी.md) | [日本語](./docs/docs_i18n/README_日本語.md) | [한국인](./docs/docs_i18n/README_한국어.md) | [Pу́сский язы́к](./docs/docs_i18n/README_Ру́сский_язы́к.md)
+English | [简体中文](README_CN.md) | [हिन्दी](./docs/docs_i18n/README_हिन्दी.md) | [日本語](./docs/docs_i18n/README_日本語.md) | [한국인](./docs/docs_i18n/README_한국어.md) | [Pу́сский язы́к](./docs/docs_i18n/README_Ру́сский_язы́к.md)

From 0a13cbf2fc30901a105d6eb1ba480b533d10c10e Mon Sep 17 00:00:00 2001
From: leiqing <54695910+leiqing1@users.noreply.github.com>
Date: Tue, 13 Dec 2022 17:16:06 +0800
Subject: [PATCH 40/77] Update README_CN.md
---
README_CN.md | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/README_CN.md b/README_CN.md
index 9e90fbeab..4c7f1bdc2 100755
--- a/README_CN.md
+++ b/README_CN.md
@@ -1,4 +1,4 @@
-[English](README_EN.md) | 简体中文 | [हिन्दी](./docs/docs_i18n/README_हिन्दी.md) | [日本語](./docs/docs_i18n/README_日本語.md) | [한국인](./docs/docs_i18n/README_한국어.md) | [Pу́сский язы́к](./docs/docs_i18n/README_Ру́сский_язы́к.md)
+[English](README_EN.md) | 简体中文 | [हिन्दी](./docs/docs_i18n/README_हिन्दी.md) | [日本語](./docs/docs_i18n/README_日本語.md) | [한국인](./docs/docs_i18n/README_한국어.md) | [Pу́сский язы́к](./docs/docs_i18n/README_Ру́сский_язы́к.md)

From 760b79d31b8b4f92ab4b08e92ae7fff95f00e7a2 Mon Sep 17 00:00:00 2001
From: Jason
Date: Tue, 13 Dec 2022 20:17:59 +0800
Subject: [PATCH 41/77] Update README_CN.md
---
README_CN.md | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/README_CN.md b/README_CN.md
index 4c7f1bdc2..2cbf2ff45 100755
--- a/README_CN.md
+++ b/README_CN.md
@@ -117,7 +117,7 @@ model = vision.detection.PPYOLOE("ppyoloe_crn_l_300e_coco/model.pdmodel",
"ppyoloe_crn_l_300e_coco/model.pdiparams",
"ppyoloe_crn_l_300e_coco/infer_cfg.yml")
im = cv2.imread("000000014439.jpg")
-result = model.predict(im.copy())
+result = model.predict(im)
print(result)
vis_im = vision.vis_detection(im, result, score_threshold=0.5)
@@ -162,7 +162,7 @@ int main(int argc, char* argv[]) {
auto im = cv::imread("000000014439.jpg");
vision::DetectionResult res;
- model.Predict(&im, &res);
+ model.Predict(im, &res);
auto vis_im = vision::Visualize::VisDetection(im, res, 0.5);
cv::imwrite("vis_image.jpg", vis_im);
From 92484bdbf26ed715372018d479e63ff4c42c7466 Mon Sep 17 00:00:00 2001
From: Jason
Date: Tue, 13 Dec 2022 20:29:28 +0800
Subject: [PATCH 42/77] Update README_CN.md
---
docs/README_CN.md | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/docs/README_CN.md b/docs/README_CN.md
index 5fb8b2127..a0b7b51d0 100644
--- a/docs/README_CN.md
+++ b/docs/README_CN.md
@@ -19,7 +19,7 @@
- [Runtime Python使用示例](cn/quick_start/runtime/python.md)
- [Runtime C++使用示例](cn/quick_start/runtime/cpp.md)
-## API文档(进行中)
+## API文档
- [Python API文档](https://www.paddlepaddle.org.cn/fastdeploy-api-doc/python/html/)
- [C++ API文档](https://www.paddlepaddle.org.cn/fastdeploy-api-doc/cpp/html/)
From cab0e5f9cb777edc22725e4f05a4fc69b4dbdea3 Mon Sep 17 00:00:00 2001
From: Jason
Date: Tue, 13 Dec 2022 21:56:25 +0800
Subject: [PATCH 43/77] Update README.md
---
examples/vision/detection/paddledetection/serving/README.md | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/examples/vision/detection/paddledetection/serving/README.md b/examples/vision/detection/paddledetection/serving/README.md
index 008fe4f8e..d6a38c8d4 100644
--- a/examples/vision/detection/paddledetection/serving/README.md
+++ b/examples/vision/detection/paddledetection/serving/README.md
@@ -75,7 +75,7 @@ I0928 04:51:15.826578 206 http_server.cc:167] Started Metrics Service at 0.0.0.0
wget https://gitee.com/paddlepaddle/PaddleDetection/raw/release/2.4/demo/000000014439.jpg
#安装客户端依赖
-python3 -m pip install tritonclient\[all\]
+python3 -m pip install tritonclient[all]
# 发送请求
python3 paddledet_grpc_client.py
From f601d076e4121824c05d8ede9ef22e3d895a48ab Mon Sep 17 00:00:00 2001
From: yunyaoXYY <109218879+yunyaoXYY@users.noreply.github.com>
Date: Wed, 14 Dec 2022 10:08:31 +0800
Subject: [PATCH 44/77] [Other] Improve some PPOCR API comments. (#875)
* Fix links in readme
* Fix links in readme
* Update PPOCRv2/v3 examples
* Update auto compression configs
* Add neww quantization support for paddleclas model
* Update quantized Yolov6s model download link
* Improve PPOCR comments
---
fastdeploy/vision/ocr/ppocr/classifier.h | 14 ++++++++++++--
fastdeploy/vision/ocr/ppocr/cls_postprocessor.h | 4 ++--
fastdeploy/vision/ocr/ppocr/cls_preprocessor.h | 4 ++--
fastdeploy/vision/ocr/ppocr/det_preprocessor.h | 2 +-
fastdeploy/vision/ocr/ppocr/rec_postprocessor.h | 4 ++--
fastdeploy/vision/ocr/ppocr/rec_preprocessor.h | 4 ++--
fastdeploy/vision/ocr/ppocr/recognizer.h | 10 +++++++++-
7 files changed, 30 insertions(+), 12 deletions(-)
diff --git a/fastdeploy/vision/ocr/ppocr/classifier.h b/fastdeploy/vision/ocr/ppocr/classifier.h
index 5a4ed02a0..cd035e269 100755
--- a/fastdeploy/vision/ocr/ppocr/classifier.h
+++ b/fastdeploy/vision/ocr/ppocr/classifier.h
@@ -43,11 +43,21 @@ class FASTDEPLOY_DECL Classifier : public FastDeployModel {
const ModelFormat& model_format = ModelFormat::PADDLE);
/// Get model's name
std::string ModelName() const { return "ppocr/ocr_cls"; }
- virtual bool Predict(const cv::Mat& img, int32_t* cls_label, float* cls_score);
+
+ /** \brief Predict the input image and get OCR classification model cls_result.
+ *
+ * \param[in] img The input image data, comes from cv::imread(), is a 3-D array with layout HWC, BGR format.
+ * \param[in] cls_label The label result of cls model will be written in to this param.
+ * \param[in] cls_score The score result of cls model will be written in to this param.
+ * \return true if the prediction is successed, otherwise false.
+ */
+ virtual bool Predict(const cv::Mat& img,
+ int32_t* cls_label, float* cls_score);
/** \brief BatchPredict the input image and get OCR classification model cls_result.
*
* \param[in] images The list of input image data, comes from cv::imread(), is a 3-D array with layout HWC, BGR format.
- * \param[in] cls_results The output of OCR classification model cls_result will be writen to this structure.
+ * \param[in] cls_labels The label results of cls model will be written in to this vector.
+ * \param[in] cls_scores The score results of cls model will be written in to this vector.
* \return true if the prediction is successed, otherwise false.
*/
virtual bool BatchPredict(const std::vector& images,
diff --git a/fastdeploy/vision/ocr/ppocr/cls_postprocessor.h b/fastdeploy/vision/ocr/ppocr/cls_postprocessor.h
index a755e1294..d9702e1a1 100644
--- a/fastdeploy/vision/ocr/ppocr/cls_postprocessor.h
+++ b/fastdeploy/vision/ocr/ppocr/cls_postprocessor.h
@@ -28,8 +28,8 @@ class FASTDEPLOY_DECL ClassifierPostprocessor {
/** \brief Process the result of runtime and fill to ClassifyResult structure
*
* \param[in] tensors The inference result from runtime
- * \param[in] cls_labels The output result of classification
- * \param[in] cls_scores The output result of classification
+ * \param[in] cls_labels The output label results of classification model
+ * \param[in] cls_scores The output score results of classification model
* \return true if the postprocess successed, otherwise false
*/
bool Run(const std::vector& tensors,
diff --git a/fastdeploy/vision/ocr/ppocr/cls_preprocessor.h b/fastdeploy/vision/ocr/ppocr/cls_preprocessor.h
index ed75d55b2..8c1c81611 100644
--- a/fastdeploy/vision/ocr/ppocr/cls_preprocessor.h
+++ b/fastdeploy/vision/ocr/ppocr/cls_preprocessor.h
@@ -26,8 +26,8 @@ class FASTDEPLOY_DECL ClassifierPreprocessor {
public:
/** \brief Process the input image and prepare input tensors for runtime
*
- * \param[in] images The input image data list, all the elements are returned by cv::imread()
- * \param[in] outputs The output tensors which will feed in runtime
+ * \param[in] images The input data list, all the elements are FDMat
+ * \param[in] outputs The output tensors which will be fed into runtime
* \return true if the preprocess successed, otherwise false
*/
bool Run(std::vector* images, std::vector* outputs);
diff --git a/fastdeploy/vision/ocr/ppocr/det_preprocessor.h b/fastdeploy/vision/ocr/ppocr/det_preprocessor.h
index d66e785d3..705f19c7b 100644
--- a/fastdeploy/vision/ocr/ppocr/det_preprocessor.h
+++ b/fastdeploy/vision/ocr/ppocr/det_preprocessor.h
@@ -26,7 +26,7 @@ class FASTDEPLOY_DECL DBDetectorPreprocessor {
public:
/** \brief Process the input image and prepare input tensors for runtime
*
- * \param[in] images The input image data list, all the elements are returned by cv::imread()
+ * \param[in] images The input data list, all the elements are FDMat
* \param[in] outputs The output tensors which will feed in runtime
* \param[in] batch_det_img_info_ptr The output of preprocess
* \return true if the preprocess successed, otherwise false
diff --git a/fastdeploy/vision/ocr/ppocr/rec_postprocessor.h b/fastdeploy/vision/ocr/ppocr/rec_postprocessor.h
index 711ae3a01..5f9aa70f2 100644
--- a/fastdeploy/vision/ocr/ppocr/rec_postprocessor.h
+++ b/fastdeploy/vision/ocr/ppocr/rec_postprocessor.h
@@ -35,8 +35,8 @@ class FASTDEPLOY_DECL RecognizerPostprocessor {
/** \brief Process the result of runtime and fill to RecognizerResult
*
* \param[in] tensors The inference result from runtime
- * \param[in] texts The output result of recognizer
- * \param[in] rec_scores The output result of recognizer
+ * \param[in] texts The output text results of recognizer
+ * \param[in] rec_scores The output score results of recognizer
* \return true if the postprocess successed, otherwise false
*/
bool Run(const std::vector& tensors,
diff --git a/fastdeploy/vision/ocr/ppocr/rec_preprocessor.h b/fastdeploy/vision/ocr/ppocr/rec_preprocessor.h
index 1dad75870..c6c942468 100644
--- a/fastdeploy/vision/ocr/ppocr/rec_preprocessor.h
+++ b/fastdeploy/vision/ocr/ppocr/rec_preprocessor.h
@@ -26,8 +26,8 @@ class FASTDEPLOY_DECL RecognizerPreprocessor {
public:
/** \brief Process the input image and prepare input tensors for runtime
*
- * \param[in] images The input image data list, all the elements are returned by cv::imread()
- * \param[in] outputs The output tensors which will feed in runtime
+ * \param[in] images The input data list, all the elements are FDMat
+ * \param[in] outputs The output tensors which will be fed into runtime
* \return true if the preprocess successed, otherwise false
*/
bool Run(std::vector* images, std::vector* outputs);
diff --git a/fastdeploy/vision/ocr/ppocr/recognizer.h b/fastdeploy/vision/ocr/ppocr/recognizer.h
index 8a5f5bc70..bba8a4447 100755
--- a/fastdeploy/vision/ocr/ppocr/recognizer.h
+++ b/fastdeploy/vision/ocr/ppocr/recognizer.h
@@ -45,11 +45,19 @@ class FASTDEPLOY_DECL Recognizer : public FastDeployModel {
const ModelFormat& model_format = ModelFormat::PADDLE);
/// Get model's name
std::string ModelName() const { return "ppocr/ocr_rec"; }
+ /** \brief Predict the input image and get OCR recognition model result.
+ *
+ * \param[in] img The input image data, comes from cv::imread(), is a 3-D array with layout HWC, BGR format.
+ * \param[in] text The text result of rec model will be written into this parameter.
+ * \param[in] rec_score The sccore result of rec model will be written into this parameter.
+ * \return true if the prediction is successed, otherwise false.
+ */
virtual bool Predict(const cv::Mat& img, std::string* text, float* rec_score);
/** \brief BatchPredict the input image and get OCR recognition model result.
*
* \param[in] images The list of input image data, comes from cv::imread(), is a 3-D array with layout HWC, BGR format.
- * \param[in] rec_results The output of OCR recognition model result will be writen to this structure.
+ * \param[in] texts The list of text results of rec model will be written into this vector.
+ * \param[in] rec_scores The list of sccore result of rec model will be written into this vector.
* \return true if the prediction is successed, otherwise false.
*/
virtual bool BatchPredict(const std::vector& images,
From de72162af9a5bed221e1ec3034f8affe5410bcdb Mon Sep 17 00:00:00 2001
From: WJJ1995
Date: Wed, 14 Dec 2022 10:14:29 +0800
Subject: [PATCH 45/77] [Serving] Fixed preprocess&&postprocess in YOLOv5
Serving (#874)
* add onnx_ort_runtime demo
* rm in requirements
* support batch eval
* fixed MattingResults bug
* move assignment for DetectionResult
* integrated x2paddle
* add model convert readme
* update readme
* re-lint
* add processor api
* Add MattingResult Free
* change valid_cpu_backends order
* add ppocr benchmark
* mv bs from 64 to 32
* fixed quantize.md
* fixed quantize bugs
* Add Monitor for benchmark
* update mem monitor
* Set trt_max_batch_size default 1
* fixed ocr benchmark bug
* support yolov5 in serving
* Fixed yolov5 serving
* Fixed postprocess
Co-authored-by: Jason
---
.../serving/models/postprocess/1/model.py | 1 -
.../serving/models/postprocess/1/model.py | 36 +++++--------------
.../serving/models/preprocess/1/model.py | 33 ++++++-----------
3 files changed, 19 insertions(+), 51 deletions(-)
mode change 100644 => 100755 examples/vision/classification/paddleclas/serving/models/postprocess/1/model.py
diff --git a/examples/vision/classification/paddleclas/serving/models/postprocess/1/model.py b/examples/vision/classification/paddleclas/serving/models/postprocess/1/model.py
old mode 100644
new mode 100755
index b328b249b..0ab7dcdc4
--- a/examples/vision/classification/paddleclas/serving/models/postprocess/1/model.py
+++ b/examples/vision/classification/paddleclas/serving/models/postprocess/1/model.py
@@ -84,7 +84,6 @@ class TritonPythonModel:
be the same as `requests`
"""
responses = []
- # print("num:", len(requests), flush=True)
for request in requests:
infer_outputs = pb_utils.get_input_tensor_by_name(
request, self.input_names[0])
diff --git a/examples/vision/detection/yolov5/serving/models/postprocess/1/model.py b/examples/vision/detection/yolov5/serving/models/postprocess/1/model.py
index 30a744b68..7c608db43 100644
--- a/examples/vision/detection/yolov5/serving/models/postprocess/1/model.py
+++ b/examples/vision/detection/yolov5/serving/models/postprocess/1/model.py
@@ -61,31 +61,7 @@ class TritonPythonModel:
dtype = pb_utils.triton_string_to_numpy(output_config["data_type"])
self.output_dtype.append(dtype)
print("postprocess output names:", self.output_names)
-
- def yolov5_postprocess(self, infer_outputs, im_infos):
- """
- Parameters
- ----------
- infer_outputs : numpy.array
- Contains the batch of inference results
- im_infos : numpy.array(b'{}')
- Returns
- -------
- numpy.array
- yolov5 postprocess result
- """
- results = []
- for i_batch in range(len(im_infos)):
- new_infer_output = infer_outputs[i_batch:i_batch + 1]
- new_im_info = im_infos[i_batch].decode('utf-8').replace("'", '"')
- new_im_info = json.loads(new_im_info)
-
- result = fd.vision.detection.YOLOv5.postprocess(
- [new_infer_output, ], new_im_info)
-
- r_str = fd.vision.utils.fd_result_to_json(result)
- results.append(r_str)
- return np.array(results, dtype=np.object)
+ self.postprocessor_ = fd.vision.detection.YOLOv5Postprocessor()
def execute(self, requests):
"""`execute` must be implemented in every Python model. `execute`
@@ -107,7 +83,6 @@ class TritonPythonModel:
be the same as `requests`
"""
responses = []
- # print("num:", len(requests), flush=True)
for request in requests:
infer_outputs = pb_utils.get_input_tensor_by_name(
request, self.input_names[0])
@@ -115,10 +90,15 @@ class TritonPythonModel:
self.input_names[1])
infer_outputs = infer_outputs.as_numpy()
im_infos = im_infos.as_numpy()
+ for i in range(im_infos.shape[0]):
+ im_infos[i] = json.loads(im_infos[i].decode('utf-8').replace(
+ "'", '"'))
- results = self.yolov5_postprocess(infer_outputs, im_infos)
+ results = self.postprocessor_.run([infer_outputs], im_infos)
+ r_str = fd.vision.utils.fd_result_to_json(results)
+ r_np = np.array(r_str, dtype=np.object)
- out_tensor = pb_utils.Tensor(self.output_names[0], results)
+ out_tensor = pb_utils.Tensor(self.output_names[0], r_np)
inference_response = pb_utils.InferenceResponse(
output_tensors=[out_tensor, ])
responses.append(inference_response)
diff --git a/examples/vision/detection/yolov5/serving/models/preprocess/1/model.py b/examples/vision/detection/yolov5/serving/models/preprocess/1/model.py
index cd22aa37b..cf4f7e8e8 100644
--- a/examples/vision/detection/yolov5/serving/models/preprocess/1/model.py
+++ b/examples/vision/detection/yolov5/serving/models/preprocess/1/model.py
@@ -61,21 +61,7 @@ class TritonPythonModel:
dtype = pb_utils.triton_string_to_numpy(output_config["data_type"])
self.output_dtype.append(dtype)
print("preprocess output names:", self.output_names)
-
- def yolov5_preprocess(self, input_data):
- """
- According to Triton input, the preprocessing results of YoloV5 model are obtained.
- """
- im_infos = []
- pre_outputs = []
- for i_batch in input_data:
- pre_output, im_info = fd.vision.detection.YOLOv5.preprocess(
- i_batch)
- pre_outputs.append(pre_output)
- im_infos.append(im_info)
- im_infos = np.array(im_infos, dtype=np.object)
- pre_outputs = np.concatenate(pre_outputs, axis=0)
- return pre_outputs, im_infos
+ self.preprocessor_ = fd.vision.detection.YOLOv5Preprocessor()
def execute(self, requests):
"""`execute` must be implemented in every Python model. `execute`
@@ -97,18 +83,21 @@ class TritonPythonModel:
be the same as `requests`
"""
responses = []
- # print("num:", len(requests), flush=True)
for request in requests:
data = pb_utils.get_input_tensor_by_name(request,
self.input_names[0])
data = data.as_numpy()
- outputs = self.yolov5_preprocess(data)
- output_tensors = []
- for idx, output in enumerate(outputs):
- output_tensors.append(
- pb_utils.Tensor(self.output_names[idx], output))
+ outputs, im_infos = self.preprocessor_.run(data)
+
+ # YOLOv5 preprocess has two output
+ dlpack_tensor = outputs[0].to_dlpack()
+ output_tensor_0 = pb_utils.Tensor.from_dlpack(self.output_names[0],
+ dlpack_tensor)
+ output_tensor_1 = pb_utils.Tensor(
+ self.output_names[1], np.array(
+ im_infos, dtype=np.object))
inference_response = pb_utils.InferenceResponse(
- output_tensors=output_tensors)
+ output_tensors=[output_tensor_0, output_tensor_1])
responses.append(inference_response)
return responses
From d8bbc8c8c417ac849041d7e720bee079ed7d53ad Mon Sep 17 00:00:00 2001
From: yeliang2258 <30516196+yeliang2258@users.noreply.github.com>
Date: Wed, 14 Dec 2022 10:23:44 +0800
Subject: [PATCH 46/77] [Doc] Add KunlunXin XPU supported models (#868)
* add xpu supported models
* update cn doc
* update EN and CN doc
---
README_CN.md | 138 +++++++++++++++++++++++++--------------------------
README_EN.md | 138 +++++++++++++++++++++++++--------------------------
2 files changed, 138 insertions(+), 138 deletions(-)
diff --git a/README_CN.md b/README_CN.md
index 2cbf2ff45..28ef9f0b4 100755
--- a/README_CN.md
+++ b/README_CN.md
@@ -186,75 +186,75 @@ int main(int argc, char* argv[]) {
-| 任务场景 | 模型 | Linux | Linux | Win | Win | Mac | Mac | Linux | Linux | Linux | Linux | Linux |
-|:----------------------:|:--------------------------------------------------------------------------------------------:|:------------------------------------------------:|:----------:|:-------:|:----------:|:-------:|:-------:|:-----------:|:---------------:|:-------------:|:-------------:|:-------:|
-| --- | --- | X86 CPU | NVIDIA GPU | X86 CPU | NVIDIA GPU | X86 CPU | Arm CPU | AArch64 CPU | 飞腾D2000 aarch64 | NVIDIA Jetson | Graphcore IPU | Serving |
-| Classification | [PaddleClas/ResNet50](./examples/vision/classification/paddleclas) | [✅](./examples/vision/classification/paddleclas) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
-| Classification | [TorchVison/ResNet](examples/vision/classification/resnet) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ❔ |
-| Classification | [ltralytics/YOLOv5Cls](examples/vision/classification/yolov5cls) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ❔ |
-| Classification | [PaddleClas/PP-LCNet](./examples/vision/classification/paddleclas) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
-| Classification | [PaddleClas/PP-LCNetv2](./examples/vision/classification/paddleclas) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
-| Classification | [PaddleClas/EfficientNet](./examples/vision/classification/paddleclas) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
-| Classification | [PaddleClas/GhostNet](./examples/vision/classification/paddleclas) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
-| Classification | [PaddleClas/MobileNetV1](./examples/vision/classification/paddleclas) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
-| Classification | [PaddleClas/MobileNetV2](./examples/vision/classification/paddleclas) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
-| Classification | [PaddleClas/MobileNetV3](./examples/vision/classification/paddleclas) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
-| Classification | [PaddleClas/ShuffleNetV2](./examples/vision/classification/paddleclas) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
-| Classification | [PaddleClas/SqueeezeNetV1.1](./examples/vision/classification/paddleclas) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
-| Classification | [PaddleClas/Inceptionv3](./examples/vision/classification/paddleclas) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ |
-| Classification | [PaddleClas/PP-HGNet](./examples/vision/classification/paddleclas) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
-| Detection | [PaddleDetection/PP-YOLOE](./examples/vision/detection/paddledetection) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ |
-| Detection | [PaddleDetection/PicoDet](./examples/vision/detection/paddledetection) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ |
-| Detection | [PaddleDetection/YOLOX](./examples/vision/detection/paddledetection) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ |
-| Detection | [PaddleDetection/YOLOv3](./examples/vision/detection/paddledetection) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ |
-| Detection | [PaddleDetection/PP-YOLO](./examples/vision/detection/paddledetection) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ |
-| Detection | [PaddleDetection/PP-YOLOv2](./examples/vision/detection/paddledetection) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ |
-| Detection | [PaddleDetection/Faster-RCNN](./examples/vision/detection/paddledetection) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ |
-| Detection | [PaddleDetection/Mask-RCNN](./examples/vision/detection/paddledetection) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ |
-| Detection | [Megvii-BaseDetection/YOLOX](./examples/vision/detection/yolox) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ❔ |
-| Detection | [WongKinYiu/YOLOv7](./examples/vision/detection/yolov7) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ❔ |
-| Detection | [WongKinYiu/YOLOv7end2end_trt](./examples/vision/detection/yolov7end2end_trt) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | ❔ | ❔ |
-| Detection | [WongKinYiu/YOLOv7end2end_ort_](./examples/vision/detection/yolov7end2end_ort) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ❔ |
-| Detection | [meituan/YOLOv6](./examples/vision/detection/yolov6) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ❔ |
-| Detection | [ultralytics/YOLOv5](./examples/vision/detection/yolov5) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ |
-| Detection | [WongKinYiu/YOLOR](./examples/vision/detection/yolor) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | ❔ | ❔ |
-| Detection | [WongKinYiu/ScaledYOLOv4](./examples/vision/detection/scaledyolov4) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ❔ |
-| Detection | [ppogg/YOLOv5Lite](./examples/vision/detection/yolov5lite) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ❔ |
-| Detection | [RangiLyu/NanoDetPlus](./examples/vision/detection/nanodet_plus) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ❔ |
-| KeyPoint | [PaddleDetection/TinyPose](./examples/vision/keypointdetection/tiny_pose) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ❔ |
-| KeyPoint | [PaddleDetection/PicoDet + TinyPose](./examples/vision/keypointdetection/det_keypoint_unite) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ❔ |
-| HeadPose | [omasaht/headpose](examples/vision/headpose) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | ❔ | ❔ |
-| Tracking | [PaddleDetection/PP-Tracking](examples/vision/tracking/pptracking) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ❔ |
-| OCR | [PaddleOCR/PP-OCRv2](./examples/vision/ocr) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | ❔ | ❔ |
-| OCR | [PaddleOCR/PP-OCRv3](./examples/vision/ocr) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ |
-| Segmentation | [PaddleSeg/PP-LiteSeg](./examples/vision/segmentation/paddleseg) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | ❔ | ❔ |
-| Segmentation | [PaddleSeg/PP-HumanSegLite](./examples/vision/segmentation/paddleseg) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | ❔ | ❔ |
-| Segmentation | [PaddleSeg/HRNet](./examples/vision/segmentation/paddleseg) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | ❔ | ❔ |
-| Segmentation | [PaddleSeg/PP-HumanSegServer](./examples/vision/segmentation/paddleseg) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | ❔ | ❔ |
-| Segmentation | [PaddleSeg/Unet](./examples/vision/segmentation/paddleseg) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | ❔ | ❔ |
-| Segmentation | [PaddleSeg/Deeplabv3](./examples/vision/segmentation/paddleseg) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | ❔ | ❔ |
-| FaceDetection | [biubug6/RetinaFace](./examples/vision/facedet/retinaface) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ❔ |
-| FaceDetection | [Linzaer/UltraFace](./examples/vision/facedet/ultraface) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ❔ |
-| FaceDetection | [deepcam-cn/YOLOv5Face](./examples/vision/facedet/yolov5face) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ❔ |
-| FaceDetection | [insightface/SCRFD](./examples/vision/facedet/scrfd) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ❔ |
-| FaceAlign | [Hsintao/PFLD](examples/vision/facealign/pfld) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ❔ |
-| FaceAlign | [Single430FaceLandmark1000](./examples/vision/facealign/face_landmark_1000) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | ❔ | ❔ |
-| FaceAlign | [jhb86253817/PIPNet](./examples/vision/facealign) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | ❔ | ❔ |
-| FaceRecognition | [insightface/ArcFace](./examples/vision/faceid/insightface) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ❔ |
-| FaceRecognition | [insightface/CosFace](./examples/vision/faceid/insightface) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ❔ |
-| FaceRecognition | [insightface/PartialFC](./examples/vision/faceid/insightface) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ❔ |
-| FaceRecognition | [insightface/VPL](./examples/vision/faceid/insightface) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ❔ |
-| Matting | [ZHKKKe/MODNet](./examples/vision/matting/modnet) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | ❔ | ❔ |
-| Matting | [PeterL1n/RobustVideoMatting]() | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | ❔ | ❔ |
-| Matting | [PaddleSeg/PP-Matting](./examples/vision/matting/ppmatting) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ❔ |
-| Matting | [PaddleSeg/PP-HumanMatting](./examples/vision/matting/modnet) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ❔ |
-| Matting | [PaddleSeg/ModNet](./examples/vision/matting/modnet) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ❔ |
-| Video Super-Resolution | [PaddleGAN/BasicVSR](./) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | ❔ | ❔ |
-| Video Super-Resolution | [PaddleGAN/EDVR](./examples/vision/sr/edvr) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | ❔ | ❔ |
-| Video Super-Resolution | [PaddleGAN/PP-MSVSR](./examples/vision/sr/ppmsvsr) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | ❔ | ❔ |
-| Information Extraction | [PaddleNLP/UIE](./examples/text/uie) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | ❔ | |
-| NLP | [PaddleNLP/ERNIE-3.0](./examples/text/ernie-3.0) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ❔ | ❔ | ✅ |
-| Speech | [PaddleSpeech/PP-TTS](./examples/audio/pp-tts) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ❔ | -- | ✅ |
+| 任务场景 | 模型 | Linux | Linux | Win | Win | Mac | Mac | Linux | Linux | Linux | Linux | Linux | Linux |
+|:----------------------:|:--------------------------------------------------------------------------------------------:|:------------------------------------------------:|:----------:|:-------:|:----------:|:-------:|:-------:|:-----------:|:---------------:|:-------------:|:-------------:|:-------:|:-------:|
+| --- | --- | X86 CPU | NVIDIA GPU | X86 CPU | NVIDIA GPU | X86 CPU | Arm CPU | AArch64 CPU | 飞腾D2000 aarch64 | NVIDIA Jetson | Graphcore IPU | KunlunXin XPU | Serving |
+| Classification | [PaddleClas/ResNet50](./examples/vision/classification/paddleclas) | [✅](./examples/vision/classification/paddleclas) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
+| Classification | [TorchVison/ResNet](examples/vision/classification/resnet) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | ❔ |
+| Classification | [ltralytics/YOLOv5Cls](examples/vision/classification/yolov5cls) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | ❔ |
+| Classification | [PaddleClas/PP-LCNet](./examples/vision/classification/paddleclas) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
+| Classification | [PaddleClas/PP-LCNetv2](./examples/vision/classification/paddleclas) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
+| Classification | [PaddleClas/EfficientNet](./examples/vision/classification/paddleclas) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
+| Classification | [PaddleClas/GhostNet](./examples/vision/classification/paddleclas) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
+| Classification | [PaddleClas/MobileNetV1](./examples/vision/classification/paddleclas) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
+| Classification | [PaddleClas/MobileNetV2](./examples/vision/classification/paddleclas) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
+| Classification | [PaddleClas/MobileNetV3](./examples/vision/classification/paddleclas) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
+| Classification | [PaddleClas/ShuffleNetV2](./examples/vision/classification/paddleclas) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
+| Classification | [PaddleClas/SqueeezeNetV1.1](./examples/vision/classification/paddleclas) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
+| Classification | [PaddleClas/Inceptionv3](./examples/vision/classification/paddleclas) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | ✅ |
+| Classification | [PaddleClas/PP-HGNet](./examples/vision/classification/paddleclas) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
+| Detection | [PaddleDetection/PP-YOLOE](./examples/vision/detection/paddledetection) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | ✅ |
+| Detection | [PaddleDetection/PicoDet](./examples/vision/detection/paddledetection) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | ✅ |
+| Detection | [PaddleDetection/YOLOX](./examples/vision/detection/paddledetection) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | ✅ |
+| Detection | [PaddleDetection/YOLOv3](./examples/vision/detection/paddledetection) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | ✅ |
+| Detection | [PaddleDetection/PP-YOLO](./examples/vision/detection/paddledetection) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | ✅ |
+| Detection | [PaddleDetection/PP-YOLOv2](./examples/vision/detection/paddledetection) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | ✅ |
+| Detection | [PaddleDetection/Faster-RCNN](./examples/vision/detection/paddledetection) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | ✅ |
+| Detection | [PaddleDetection/Mask-RCNN](./examples/vision/detection/paddledetection) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | ✅ |
+| Detection | [Megvii-BaseDetection/YOLOX](./examples/vision/detection/yolox) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | ❔ |
+| Detection | [WongKinYiu/YOLOv7](./examples/vision/detection/yolov7) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | ❔ |
+| Detection | [WongKinYiu/YOLOv7end2end_trt](./examples/vision/detection/yolov7end2end_trt) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | ❔ | ❔ | ❔ |
+| Detection | [WongKinYiu/YOLOv7end2end_ort_](./examples/vision/detection/yolov7end2end_ort) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ❔ | ❔ |
+| Detection | [meituan/YOLOv6](./examples/vision/detection/yolov6) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | ❔ |
+| Detection | [ultralytics/YOLOv5](./examples/vision/detection/yolov5) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | ✅ |
+| Detection | [WongKinYiu/YOLOR](./examples/vision/detection/yolor) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | ❔ | ❔ | ❔ |
+| Detection | [WongKinYiu/ScaledYOLOv4](./examples/vision/detection/scaledyolov4) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ❔ | ❔ |
+| Detection | [ppogg/YOLOv5Lite](./examples/vision/detection/yolov5lite) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ? | ❔ |❔ |
+| Detection | [RangiLyu/NanoDetPlus](./examples/vision/detection/nanodet_plus) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ❔ | ❔ |
+| KeyPoint | [PaddleDetection/TinyPose](./examples/vision/keypointdetection/tiny_pose) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | ❔ |
+| KeyPoint | [PaddleDetection/PicoDet + TinyPose](./examples/vision/keypointdetection/det_keypoint_unite) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | ❔ |
+| HeadPose | [omasaht/headpose](examples/vision/headpose) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | ❔ | ❔ | ❔ |
+| Tracking | [PaddleDetection/PP-Tracking](examples/vision/tracking/pptracking) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ❔ | ❔ |
+| OCR | [PaddleOCR/PP-OCRv2](./examples/vision/ocr) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | ❔ | ✅ | ❔ |
+| OCR | [PaddleOCR/PP-OCRv3](./examples/vision/ocr) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | ✅ |
+| Segmentation | [PaddleSeg/PP-LiteSeg](./examples/vision/segmentation/paddleseg) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | ❔ | ✅ | ❔ |
+| Segmentation | [PaddleSeg/PP-HumanSegLite](./examples/vision/segmentation/paddleseg) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | ❔ | ✅ | ❔ |
+| Segmentation | [PaddleSeg/HRNet](./examples/vision/segmentation/paddleseg) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | ❔ | ✅ | ❔ |
+| Segmentation | [PaddleSeg/PP-HumanSegServer](./examples/vision/segmentation/paddleseg) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | ❔ | ✅ | ❔ |
+| Segmentation | [PaddleSeg/Unet](./examples/vision/segmentation/paddleseg) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | ✅ | ✅ | ❔ |
+| Segmentation | [PaddleSeg/Deeplabv3](./examples/vision/segmentation/paddleseg) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | ❔ | ✅ | ❔ |
+| FaceDetection | [biubug6/RetinaFace](./examples/vision/facedet/retinaface) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ❔ | ❔ |
+| FaceDetection | [Linzaer/UltraFace](./examples/vision/facedet/ultraface) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ❔ | ❔ |
+| FaceDetection | [deepcam-cn/YOLOv5Face](./examples/vision/facedet/yolov5face) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ❔ | ❔ |
+| FaceDetection | [insightface/SCRFD](./examples/vision/facedet/scrfd) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ❔ | ❔ |
+| FaceAlign | [Hsintao/PFLD](examples/vision/facealign/pfld) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ❔ |❔ |
+| FaceAlign | [Single430/FaceLandmark1000](./examples/vision/facealign/face_landmark_1000) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | ❔ | ❔ | ❔ |
+| FaceAlign | [jhb86253817/PIPNet](./examples/vision/facealign) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | ❔ | ❔ |❔ |
+| FaceRecognition | [insightface/ArcFace](./examples/vision/faceid/insightface) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ❔ | ❔ |
+| FaceRecognition | [insightface/CosFace](./examples/vision/faceid/insightface) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ❔ | ❔ |
+| FaceRecognition | [insightface/PartialFC](./examples/vision/faceid/insightface) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ❔ | ❔ |
+| FaceRecognition | [insightface/VPL](./examples/vision/faceid/insightface) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ❔ | ❔ |
+| Matting | [ZHKKKe/MODNet](./examples/vision/matting/modnet) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | ❔ | ❔ |❔ |
+| Matting | [PeterL1n/RobustVideoMatting]() | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | ❔ | ❔ | ❔ |
+| Matting | [PaddleSeg/PP-Matting](./examples/vision/matting/ppmatting) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | ❔ |
+| Matting | [PaddleSeg/PP-HumanMatting](./examples/vision/matting/modnet) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ |❔ |
+| Matting | [PaddleSeg/ModNet](./examples/vision/matting/modnet) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ❔ | ❔ |
+| Video Super-Resolution | [PaddleGAN/BasicVSR](./) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | ❔ | ❔ | ❔ |
+| Video Super-Resolution | [PaddleGAN/EDVR](./examples/vision/sr/edvr) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | ❔ | ❔ | ❔ |
+| Video Super-Resolution | [PaddleGAN/PP-MSVSR](./examples/vision/sr/ppmsvsr) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | ❔ | ❔ | ❔ |
+| Information Extraction | [PaddleNLP/UIE](./examples/text/uie) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | ❔ | ❔ | |
+| NLP | [PaddleNLP/ERNIE-3.0](./examples/text/ernie-3.0) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ❔ | ❔ | ✅ | ✅ |
+| Speech | [PaddleSpeech/PP-TTS](./examples/audio/pp-tts) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ❔ | -- |❔ | ✅ |
diff --git a/README_EN.md b/README_EN.md
index 3abffec44..d6f5d1405 100755
--- a/README_EN.md
+++ b/README_EN.md
@@ -186,75 +186,75 @@ Notes: ✅: already supported; ❔: to be supported in the future; N/A: Not Ava
-| Task | Model | Linux | Linux | Win | Win | Mac | Mac | Linux | Linux | Linux | Linux | Linux |
-|:----------------------:|:--------------------------------------------------------------------------------------------:|:------------------------------------------------:|:------------------------:|:------------------------:|:------------------------:|:-----------------------:|:---------------------:|:--------------------------:| :----------------: |:---------------------------:|:---------------------------:|:-------:|
-| --- | --- | X86 CPU | NVIDIA GPU | Intel CPU | NVIDIA GPU | Intel CPU | Arm CPU | AArch64 CPU | Phytium D2000CPU | NVIDIA Jetson | Graphcore IPU | Serving |
-| Classification | [PaddleClas/ResNet50](./examples/vision/classification/paddleclas) | [✅](./examples/vision/classification/paddleclas) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
-| Classification | [TorchVison/ResNet](examples/vision/classification/resnet) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ❔ |
-| Classification | [ltralytics/YOLOv5Cls](examples/vision/classification/yolov5cls) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ❔ |
-| Classification | [PaddleClas/PP-LCNet](./examples/vision/classification/paddleclas) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
-| Classification | [PaddleClas/PP-LCNetv2](./examples/vision/classification/paddleclas) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
-| Classification | [PaddleClas/EfficientNet](./examples/vision/classification/paddleclas) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
-| Classification | [PaddleClas/GhostNet](./examples/vision/classification/paddleclas) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
-| Classification | [PaddleClas/MobileNetV1](./examples/vision/classification/paddleclas) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
-| Classification | [PaddleClas/MobileNetV2](./examples/vision/classification/paddleclas) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
-| Classification | [PaddleClas/MobileNetV3](./examples/vision/classification/paddleclas) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
-| Classification | [PaddleClas/ShuffleNetV2](./examples/vision/classification/paddleclas) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
-| Classification | [PaddleClas/SqueeezeNetV1.1](./examples/vision/classification/paddleclas) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
-| Classification | [PaddleClas/Inceptionv3](./examples/vision/classification/paddleclas) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ |
-| Classification | [PaddleClas/PP-HGNet](./examples/vision/classification/paddleclas) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
-| Detection | [PaddleDetection/PP-YOLOE](./examples/vision/detection/paddledetection) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ |
-| Detection | [PaddleDetection/PicoDet](./examples/vision/detection/paddledetection) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ |
-| Detection | [PaddleDetection/YOLOX](./examples/vision/detection/paddledetection) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ |
-| Detection | [PaddleDetection/YOLOv3](./examples/vision/detection/paddledetection) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ |
-| Detection | [PaddleDetection/PP-YOLO](./examples/vision/detection/paddledetection) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ |
-| Detection | [PaddleDetection/PP-YOLOv2](./examples/vision/detection/paddledetection) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ |
-| Detection | [PaddleDetection/Faster-RCNN](./examples/vision/detection/paddledetection) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ |
-| Detection | [PaddleDetection/Mask-RCNN](./examples/vision/detection/paddledetection) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ |
-| Detection | [Megvii-BaseDetection/YOLOX](./examples/vision/detection/yolox) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ❔ |
-| Detection | [WongKinYiu/YOLOv7](./examples/vision/detection/yolov7) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ❔ |
-| Detection | [WongKinYiu/YOLOv7end2end_trt](./examples/vision/detection/yolov7end2end_trt) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | ❔ | ❔ |
-| Detection | [WongKinYiu/YOLOv7end2end_ort_](./examples/vision/detection/yolov7end2end_ort) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ❔ |
-| Detection | [meituan/YOLOv6](./examples/vision/detection/yolov6) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ❔ |
-| Detection | [ultralytics/YOLOv5](./examples/vision/detection/yolov5) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ |
-| Detection | [WongKinYiu/YOLOR](./examples/vision/detection/yolor) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | ❔ | ❔ |
-| Detection | [WongKinYiu/ScaledYOLOv4](./examples/vision/detection/scaledyolov4) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ❔ |
-| Detection | [ppogg/YOLOv5Lite](./examples/vision/detection/yolov5lite) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ❔ |
-| Detection | [RangiLyu/NanoDetPlus](./examples/vision/detection/nanodet_plus) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ❔ |
-| KeyPoint | [PaddleDetection/TinyPose](./examples/vision/keypointdetection/tiny_pose) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ❔ |
-| KeyPoint | [PaddleDetection/PicoDet + TinyPose](./examples/vision/keypointdetection/det_keypoint_unite) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ❔ |
-| HeadPose | [omasaht/headpose](examples/vision/headpose) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | ❔ | ❔ |
-| Tracking | [PaddleDetection/PP-Tracking](examples/vision/tracking/pptracking) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ❔ |
-| OCR | [PaddleOCR/PP-OCRv2](./examples/vision/ocr) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | ❔ | ❔ |
-| OCR | [PaddleOCR/PP-OCRv3](./examples/vision/ocr) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ |
-| Segmentation | [PaddleSeg/PP-LiteSeg](./examples/vision/segmentation/paddleseg) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | ❔ | ❔ |
-| Segmentation | [PaddleSeg/PP-HumanSegLite](./examples/vision/segmentation/paddleseg) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | ❔ | ❔ |
-| Segmentation | [PaddleSeg/HRNet](./examples/vision/segmentation/paddleseg) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | ❔ | ❔ |
-| Segmentation | [PaddleSeg/PP-HumanSegServer](./examples/vision/segmentation/paddleseg) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | ❔ | ❔ |
-| Segmentation | [PaddleSeg/Unet](./examples/vision/segmentation/paddleseg) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | ❔ | ❔ |
-| Segmentation | [PaddleSeg/Deeplabv3](./examples/vision/segmentation/paddleseg) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | ❔ | ❔ |
-| FaceDetection | [biubug6/RetinaFace](./examples/vision/facedet/retinaface) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ❔ |
-| FaceDetection | [Linzaer/UltraFace](./examples/vision/facedet/ultraface) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ❔ |
-| FaceDetection | [deepcam-cn/YOLOv5Face](./examples/vision/facedet/yolov5face) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ❔ |
-| FaceDetection | [insightface/SCRFD](./examples/vision/facedet/scrfd) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ❔ |
-| FaceAlign | [Hsintao/PFLD](examples/vision/facealign/pfld) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ❔ |
-| FaceAlign | [Single430FaceLandmark1000](./examples/vision/facealign/face_landmark_1000) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | ❔ | ❔ |
-| FaceAlign | [jhb86253817/PIPNet](./examples/vision/facealign) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | ❔ | ❔ |
-| FaceRecognition | [insightface/ArcFace](./examples/vision/faceid/insightface) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ❔ |
-| FaceRecognition | [insightface/CosFace](./examples/vision/faceid/insightface) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ❔ |
-| FaceRecognition | [insightface/PartialFC](./examples/vision/faceid/insightface) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ❔ |
-| FaceRecognition | [insightface/VPL](./examples/vision/faceid/insightface) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ❔ |
-| Matting | [ZHKKKe/MODNet](./examples/vision/matting/modnet) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | ❔ | ❔ |
-| Matting | [PeterL1n/RobustVideoMatting]() | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | ❔ | ❔ |
-| Matting | [PaddleSeg/PP-Matting](./examples/vision/matting/ppmatting) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ❔ |
-| Matting | [PaddleSeg/PP-HumanMatting](./examples/vision/matting/modnet) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ❔ |
-| Matting | [PaddleSeg/ModNet](./examples/vision/matting/modnet) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ❔ |
-| Video Super-Resolution | [PaddleGAN/BasicVSR](./) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | ❔ | ❔ |
-| Video Super-Resolution | [PaddleGAN/EDVR](./examples/vision/sr/edvr) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | ❔ | ❔ |
-| Video Super-Resolution | [PaddleGAN/PP-MSVSR](./examples/vision/sr/ppmsvsr) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | ❔ | ❔ |
-| Information Extraction | [PaddleNLP/UIE](./examples/text/uie) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | ❔ | |
-| NLP | [PaddleNLP/ERNIE-3.0](./examples/text/ernie-3.0) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ❔ | ❔ | ✅ |
-| Speech | [PaddleSpeech/PP-TTS](./examples/audio/pp-tts) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ❔ | -- | ✅ |
+| Task | Model | Linux | Linux | Win | Win | Mac | Mac | Linux | Linux | Linux | Linux | Linux | Linux |
+|:----------------------:|:--------------------------------------------------------------------------------------------:|:------------------------------------------------:|:------------------------:|:------------------------:|:------------------------:|:-----------------------:|:---------------------:|:--------------------------:| :----------------: |:---------------------------:|:---------------------------:|:-------:|:-------:|
+| --- | --- | X86 CPU | NVIDIA GPU | Intel CPU | NVIDIA GPU | Intel CPU | Arm CPU | AArch64 CPU | Phytium D2000CPU | NVIDIA Jetson | Graphcore IPU | KunlunXin XPU |Serving |
+| Classification | [PaddleClas/ResNet50](./examples/vision/classification/paddleclas) | [✅](./examples/vision/classification/paddleclas) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
+| Classification | [TorchVison/ResNet](examples/vision/classification/resnet) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | ❔ |
+| Classification | [ltralytics/YOLOv5Cls](examples/vision/classification/yolov5cls) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | ❔ |
+| Classification | [PaddleClas/PP-LCNet](./examples/vision/classification/paddleclas) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
+| Classification | [PaddleClas/PP-LCNetv2](./examples/vision/classification/paddleclas) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
+| Classification | [PaddleClas/EfficientNet](./examples/vision/classification/paddleclas) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
+| Classification | [PaddleClas/GhostNet](./examples/vision/classification/paddleclas) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
+| Classification | [PaddleClas/MobileNetV1](./examples/vision/classification/paddleclas) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
+| Classification | [PaddleClas/MobileNetV2](./examples/vision/classification/paddleclas) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
+| Classification | [PaddleClas/MobileNetV3](./examples/vision/classification/paddleclas) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
+| Classification | [PaddleClas/ShuffleNetV2](./examples/vision/classification/paddleclas) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
+| Classification | [PaddleClas/SqueeezeNetV1.1](./examples/vision/classification/paddleclas) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
+| Classification | [PaddleClas/Inceptionv3](./examples/vision/classification/paddleclas) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | ✅ |
+| Classification | [PaddleClas/PP-HGNet](./examples/vision/classification/paddleclas) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
+| Detection | [PaddleDetection/PP-YOLOE](./examples/vision/detection/paddledetection) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | ✅ |
+| Detection | [PaddleDetection/PicoDet](./examples/vision/detection/paddledetection) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | ✅ |
+| Detection | [PaddleDetection/YOLOX](./examples/vision/detection/paddledetection) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | ✅ |
+| Detection | [PaddleDetection/YOLOv3](./examples/vision/detection/paddledetection) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | ✅ |
+| Detection | [PaddleDetection/PP-YOLO](./examples/vision/detection/paddledetection) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | ✅ |
+| Detection | [PaddleDetection/PP-YOLOv2](./examples/vision/detection/paddledetection) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | ✅ |
+| Detection | [PaddleDetection/Faster-RCNN](./examples/vision/detection/paddledetection) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | ✅ |
+| Detection | [PaddleDetection/Mask-RCNN](./examples/vision/detection/paddledetection) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | ✅ |
+| Detection | [Megvii-BaseDetection/YOLOX](./examples/vision/detection/yolox) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | ❔ |
+| Detection | [WongKinYiu/YOLOv7](./examples/vision/detection/yolov7) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | ❔ |
+| Detection | [WongKinYiu/YOLOv7end2end_trt](./examples/vision/detection/yolov7end2end_trt) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | ❔ | ❔ | ❔ |
+| Detection | [WongKinYiu/YOLOv7end2end_ort_](./examples/vision/detection/yolov7end2end_ort) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ❔ | ❔ |
+| Detection | [meituan/YOLOv6](./examples/vision/detection/yolov6) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | ❔ |
+| Detection | [ultralytics/YOLOv5](./examples/vision/detection/yolov5) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | ✅ |
+| Detection | [WongKinYiu/YOLOR](./examples/vision/detection/yolor) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | ❔ | ❔ | ❔ |
+| Detection | [WongKinYiu/ScaledYOLOv4](./examples/vision/detection/scaledyolov4) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ❔ | ❔ |
+| Detection | [ppogg/YOLOv5Lite](./examples/vision/detection/yolov5lite) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ❔ | ❔ |
+| Detection | [RangiLyu/NanoDetPlus](./examples/vision/detection/nanodet_plus) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ❔ | ❔ |
+| KeyPoint | [PaddleDetection/TinyPose](./examples/vision/keypointdetection/tiny_pose) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | ❔ |
+| KeyPoint | [PaddleDetection/PicoDet + TinyPose](./examples/vision/keypointdetection/det_keypoint_unite) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | ❔ |
+| HeadPose | [omasaht/headpose](examples/vision/headpose) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | ❔ | ❔ | ❔ |
+| Tracking | [PaddleDetection/PP-Tracking](examples/vision/tracking/pptracking) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ❔ | ❔ |
+| OCR | [PaddleOCR/PP-OCRv2](./examples/vision/ocr) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | ❔ | ✅ | ❔ |
+| OCR | [PaddleOCR/PP-OCRv3](./examples/vision/ocr) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | ✅ |
+| Segmentation | [PaddleSeg/PP-LiteSeg](./examples/vision/segmentation/paddleseg) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | ❔ | ✅ | ❔ |
+| Segmentation | [PaddleSeg/PP-HumanSegLite](./examples/vision/segmentation/paddleseg) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | ❔ | ✅ | ❔ |
+| Segmentation | [PaddleSeg/HRNet](./examples/vision/segmentation/paddleseg) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | ❔ | ✅ | ❔ |
+| Segmentation | [PaddleSeg/PP-HumanSegServer](./examples/vision/segmentation/paddleseg) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | ❔ | ✅ | ❔ |
+| Segmentation | [PaddleSeg/Unet](./examples/vision/segmentation/paddleseg) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | ❔ | ✅ | ❔ |
+| Segmentation | [PaddleSeg/Deeplabv3](./examples/vision/segmentation/paddleseg) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | ❔ | ✅ | ❔ |
+| FaceDetection | [biubug6/RetinaFace](./examples/vision/facedet/retinaface) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ❔ | ❔ |
+| FaceDetection | [Linzaer/UltraFace](./examples/vision/facedet/ultraface) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ❔ | ❔ |
+| FaceDetection | [deepcam-cn/YOLOv5Face](./examples/vision/facedet/yolov5face) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ❔ | ❔ |
+| FaceDetection | [insightface/SCRFD](./examples/vision/facedet/scrfd) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ❔ | ❔ |
+| FaceAlign | [Hsintao/PFLD](examples/vision/facealign/pfld) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ❔ | ❔ |
+| FaceAlign | [Single430FaceLandmark1000](./examples/vision/facealign/face_landmark_1000) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | ❔ | ❔ | ❔ |
+| FaceAlign | [jhb86253817/PIPNet](./examples/vision/facealign) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | ❔ | ❔ | ❔ |
+| FaceRecognition | [insightface/ArcFace](./examples/vision/faceid/insightface) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ❔ | ❔ |
+| FaceRecognition | [insightface/CosFace](./examples/vision/faceid/insightface) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ❔ | ❔ |
+| FaceRecognition | [insightface/PartialFC](./examples/vision/faceid/insightface) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ❔ | ❔ |
+| FaceRecognition | [insightface/VPL](./examples/vision/faceid/insightface) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ❔ | ❔ |
+| Matting | [ZHKKKe/MODNet](./examples/vision/matting/modnet) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | ❔ | ❔ | ❔ |
+| Matting | [PeterL1n/RobustVideoMatting]() | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | ❔ | ❔ | ❔ |
+| Matting | [PaddleSeg/PP-Matting](./examples/vision/matting/ppmatting) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | ❔ |
+| Matting | [PaddleSeg/PP-HumanMatting](./examples/vision/matting/modnet) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | ❔ |
+| Matting | [PaddleSeg/ModNet](./examples/vision/matting/modnet) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ❔ | ❔ |
+| Video Super-Resolution | [PaddleGAN/BasicVSR](./) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | ❔ | ❔ | ❔ |
+| Video Super-Resolution | [PaddleGAN/EDVR](./examples/vision/sr/edvr) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | ❔ | ❔ | ❔ |
+| Video Super-Resolution | [PaddleGAN/PP-MSVSR](./examples/vision/sr/ppmsvsr) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | ❔ | ❔ | ❔ |
+| Information Extraction | [PaddleNLP/UIE](./examples/text/uie) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | ❔ | ❔ | |
+| NLP | [PaddleNLP/ERNIE-3.0](./examples/text/ernie-3.0) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ❔ | ❔ | ✅ | ✅ |
+| Speech | [PaddleSpeech/PP-TTS](./examples/audio/pp-tts) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ❔ | -- | ❔ | ✅ |
From c4852a84404a99b6d855572fd047951b4a8ea7e6 Mon Sep 17 00:00:00 2001
From: Winter <1558270516@qq.com>
Date: Wed, 14 Dec 2022 12:53:38 +0800
Subject: [PATCH 47/77] [Android] Change text package name (#866)
* [Android]add VoiceAssistant.
* Create VoiceAssistantDemo
* Update and rename VoiceAssistantDemo to VoiceAssistantDemo.md
* Update VoiceAssistantDemo.md
* Delete VoiceAssistantDemo.md
* [Android]1.delete about core folder.
2.build and configure bdasr_V3_20210628_cfe8c44.aar file.
* change app/build.gradle etc.
* Update build.gradle
* change package name.
Co-authored-by: DefTruth <31974251+DefTruth@users.noreply.github.com>
---
.../applications/VoiceAssistantMainActivity.java | 3 +--
.../applications/VoiceAssistantWelcomeActivity.java | 2 +-
2 files changed, 2 insertions(+), 3 deletions(-)
rename java/android/app/src/main/java/com/baidu/paddle/fastdeploy/app/examples/{ernie => text}/applications/VoiceAssistantMainActivity.java (98%)
rename java/android/app/src/main/java/com/baidu/paddle/fastdeploy/app/examples/{ernie => text}/applications/VoiceAssistantWelcomeActivity.java (93%)
diff --git a/java/android/app/src/main/java/com/baidu/paddle/fastdeploy/app/examples/ernie/applications/VoiceAssistantMainActivity.java b/java/android/app/src/main/java/com/baidu/paddle/fastdeploy/app/examples/text/applications/VoiceAssistantMainActivity.java
similarity index 98%
rename from java/android/app/src/main/java/com/baidu/paddle/fastdeploy/app/examples/ernie/applications/VoiceAssistantMainActivity.java
rename to java/android/app/src/main/java/com/baidu/paddle/fastdeploy/app/examples/text/applications/VoiceAssistantMainActivity.java
index cd1592502..8b96cea31 100644
--- a/java/android/app/src/main/java/com/baidu/paddle/fastdeploy/app/examples/ernie/applications/VoiceAssistantMainActivity.java
+++ b/java/android/app/src/main/java/com/baidu/paddle/fastdeploy/app/examples/text/applications/VoiceAssistantMainActivity.java
@@ -1,4 +1,4 @@
-package com.baidu.paddle.fastdeploy.app.examples.ernie.applications;
+package com.baidu.paddle.fastdeploy.app.examples.text.applications;
import static com.baidu.paddle.fastdeploy.ui.Utils.isNetworkAvailable;
@@ -32,7 +32,6 @@ import com.baidu.speech.asr.SpeechConstant;
import org.json.JSONObject;
import java.util.ArrayList;
-import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
diff --git a/java/android/app/src/main/java/com/baidu/paddle/fastdeploy/app/examples/ernie/applications/VoiceAssistantWelcomeActivity.java b/java/android/app/src/main/java/com/baidu/paddle/fastdeploy/app/examples/text/applications/VoiceAssistantWelcomeActivity.java
similarity index 93%
rename from java/android/app/src/main/java/com/baidu/paddle/fastdeploy/app/examples/ernie/applications/VoiceAssistantWelcomeActivity.java
rename to java/android/app/src/main/java/com/baidu/paddle/fastdeploy/app/examples/text/applications/VoiceAssistantWelcomeActivity.java
index f81c1c0ca..5dbf8a7ac 100644
--- a/java/android/app/src/main/java/com/baidu/paddle/fastdeploy/app/examples/ernie/applications/VoiceAssistantWelcomeActivity.java
+++ b/java/android/app/src/main/java/com/baidu/paddle/fastdeploy/app/examples/text/applications/VoiceAssistantWelcomeActivity.java
@@ -1,4 +1,4 @@
-package com.baidu.paddle.fastdeploy.app.examples.ernie.applications;
+package com.baidu.paddle.fastdeploy.app.examples.text.applications;
import android.app.Activity;
import android.content.Intent;
From 2bdf40a5470427504f82b19fe2bccc06a3a895ae Mon Sep 17 00:00:00 2001
From: Jason
Date: Wed, 14 Dec 2022 13:55:49 +0800
Subject: [PATCH 48/77] Update README.md
---
tutorials/intel_gpu/README.md | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/tutorials/intel_gpu/README.md b/tutorials/intel_gpu/README.md
index 7c641f512..41c022fa0 100644
--- a/tutorials/intel_gpu/README.md
+++ b/tutorials/intel_gpu/README.md
@@ -11,7 +11,7 @@ FastDeploy provides two examples for these situations in this directory
## Fixed input shape
-While deploying a computer vision model, it includes 3 steps
+While deploying a compute vision model, it includes 3 steps
- Input a image data, after the preprocessing steps, we get the `tensors` which will be feed to the deeplearning model
- Inference the model by Runtime with the input `tensors`, and get the output `tensors`
- Postprocessing the output `tensors`, and get the final results we need, e.g `DetectionResult`, `SegmentationResult`
From 9b7cc1fb32a772082c99eb6cc030034152b0a7bd Mon Sep 17 00:00:00 2001
From: zhoushunjie
Date: Wed, 14 Dec 2022 08:36:10 +0000
Subject: [PATCH 49/77] Fix uie python results bug
---
python/fastdeploy/text/uie/__init__.py | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/python/fastdeploy/text/uie/__init__.py b/python/fastdeploy/text/uie/__init__.py
index 642adc882..00ed67a90 100644
--- a/python/fastdeploy/text/uie/__init__.py
+++ b/python/fastdeploy/text/uie/__init__.py
@@ -86,7 +86,8 @@ class UIEModel(FastDeployModel):
for result in results:
uie_result = dict()
for key, uie_results in result.items():
+ uie_result[key] = list()
for uie_res in uie_results:
- uie_result[key] = uie_res.get_dict()
+ uie_result[key].append(uie_res.get_dict())
new_results += [uie_result]
return new_results
From 2e342a35ba336bbf3b058501fcc3570260f2a67e Mon Sep 17 00:00:00 2001
From: DefTruth <31974251+DefTruth@users.noreply.github.com>
Date: Wed, 14 Dec 2022 16:43:02 +0800
Subject: [PATCH 50/77] [Bug Fix] Fix gflags download timeout (#878)
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
* [Doc] Add docs_i18n
* [cmake] fix gflags timeout
* Delete README_Ру́сский_язы́к.md
* Delete README_한국어.md
* Create README_Ру́сский_язы́к.md
* Delete README_Ру́сский_язы́к.md
* Update CMakeLists.txt
Co-authored-by: Jason <928090362@qq.com>
---
CMakeLists.txt | 1 -
cmake/gflags.cmake | 81 +++++++++++++++++++++++-----------------------
2 files changed, 41 insertions(+), 41 deletions(-)
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 667951e71..c02e887a5 100755
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -589,7 +589,6 @@ install(
DESTINATION ${CMAKE_INSTALL_PREFIX}
)
-
install(
DIRECTORY ${PROJECT_SOURCE_DIR}/examples
DESTINATION ${CMAKE_INSTALL_PREFIX}
diff --git a/cmake/gflags.cmake b/cmake/gflags.cmake
index bf20cc2ab..37ee2c4de 100644
--- a/cmake/gflags.cmake
+++ b/cmake/gflags.cmake
@@ -14,9 +14,6 @@
INCLUDE(ExternalProject)
-if(NOT GIT_URL)
- SET(GIT_URL "https://github.com")
-endif()
if(THIRD_PARTY_PATH)
SET(GFLAGS_PREFIX_DIR ${THIRD_PARTY_PATH}/gflags)
SET(GFLAGS_INSTALL_DIR ${THIRD_PARTY_PATH}/install/gflags)
@@ -26,8 +23,16 @@ else()
SET(GFLAGS_INSTALL_DIR ${FASTDEPLOY_INSTALL_DIR}/installed_fastdeploy/cmake/gflags)
endif()
SET(GFLAGS_INCLUDE_DIR "${GFLAGS_INSTALL_DIR}/include" CACHE PATH "gflags include directory." FORCE)
-set(GFLAGS_REPOSITORY ${GIT_URL}/gflags/gflags.git)
-set(GFLAGS_TAG "v2.2.2")
+set(GFLAGS_SOURCE_FILE ${GFLAGS_PREFIX_DIR}/src/gflags.tgz CACHE PATH "gflags source file." FORCE)
+
+set(GFLAGS_URL_PREFIX "https://bj.bcebos.com/fastdeploy/third_libs")
+set(GFLAGS_URL ${GFLAGS_URL_PREFIX}/gflags.tgz)
+set(GFLAGS_CACHE_FILE ${CMAKE_CURRENT_LIST_DIR}/gflags.tgz)
+if(EXISTS ${GFLAGS_CACHE_FILE})
+ set(GFLAGS_URL ${GFLAGS_CACHE_FILE} CACHE PATH "gflags cache file." FORCE)
+ set(GFLAGS_SOURCE_FILE ${GFLAGS_CACHE_FILE} CACHE PATH "gflags source file." FORCE)
+endif()
+
IF(WIN32)
set(GFLAGS_LIBRARIES "${GFLAGS_INSTALL_DIR}/lib/gflags_static.lib" CACHE FILEPATH "GFLAGS_LIBRARIES" FORCE)
ELSE(WIN32)
@@ -40,45 +45,41 @@ INCLUDE_DIRECTORIES(${GFLAGS_INCLUDE_DIR})
if(ANDROID)
ExternalProject_Add(
- extern_gflags
- ${EXTERNAL_PROJECT_LOG_ARGS}
- ${SHALLOW_CLONE}
- GIT_REPOSITORY ${GFLAGS_REPOSITORY}
- GIT_TAG ${GFLAGS_TAG}
- PREFIX ${GFLAGS_PREFIX_DIR}
- UPDATE_COMMAND ""
- BUILD_COMMAND ${BUILD_COMMAND}
- INSTALL_COMMAND ${INSTALL_COMMAND}
- CMAKE_ARGS -DCMAKE_TOOLCHAIN_FILE=${CMAKE_TOOLCHAIN_FILE}
- -DANDROID_ABI=${ANDROID_ABI}
- -DANDROID_NDK=${ANDROID_NDK}
- -DANDROID_PLATFORM=${ANDROID_PLATFORM}
- -DANDROID_STL=c++_static
- -DANDROID_TOOLCHAIN=${ANDROID_TOOLCHAIN}
- -DCMAKE_CXX_FLAGS=${CMAKE_CXX_FLAGS}
- -DCMAKE_CXX_FLAGS_RELEASE=${CMAKE_CXX_FLAGS_RELEASE}
- -DCMAKE_CXX_FLAGS_DEBUG=${CMAKE_CXX_FLAGS_DEBUG}
- -DCMAKE_C_FLAGS=${CMAKE_C_FLAGS}
- -DCMAKE_C_FLAGS_DEBUG=${CMAKE_C_FLAGS_DEBUG}
- -DCMAKE_C_FLAGS_RELEASE=${CMAKE_C_FLAGS_RELEASE}
- -DBUILD_STATIC_LIBS=ON
- -DCMAKE_INSTALL_PREFIX=${GFLAGS_INSTALL_DIR}
- -DCMAKE_POSITION_INDEPENDENT_CODE=ON
- -DBUILD_TESTING=OFF
- -DCMAKE_BUILD_TYPE=${THIRD_PARTY_BUILD_TYPE}
- ${EXTERNAL_OPTIONAL_ARGS}
- CMAKE_CACHE_ARGS -DCMAKE_INSTALL_PREFIX:PATH=${GFLAGS_INSTALL_DIR}
- -DCMAKE_POSITION_INDEPENDENT_CODE:BOOL=ON
- -DCMAKE_BUILD_TYPE:STRING=${THIRD_PARTY_BUILD_TYPE}
- BUILD_BYPRODUCTS ${GFLAGS_LIBRARIES}
- )
+ extern_gflags
+ ${EXTERNAL_PROJECT_LOG_ARGS}
+ URL ${GFLAGS_URL}
+ PREFIX ${GFLAGS_PREFIX_DIR}
+ UPDATE_COMMAND ""
+ BUILD_COMMAND ${BUILD_COMMAND}
+ INSTALL_COMMAND ${INSTALL_COMMAND}
+ CMAKE_ARGS -DCMAKE_TOOLCHAIN_FILE=${CMAKE_TOOLCHAIN_FILE}
+ -DANDROID_ABI=${ANDROID_ABI}
+ -DANDROID_NDK=${ANDROID_NDK}
+ -DANDROID_PLATFORM=${ANDROID_PLATFORM}
+ -DANDROID_STL=c++_static
+ -DANDROID_TOOLCHAIN=${ANDROID_TOOLCHAIN}
+ -DCMAKE_CXX_FLAGS=${CMAKE_CXX_FLAGS}
+ -DCMAKE_CXX_FLAGS_RELEASE=${CMAKE_CXX_FLAGS_RELEASE}
+ -DCMAKE_CXX_FLAGS_DEBUG=${CMAKE_CXX_FLAGS_DEBUG}
+ -DCMAKE_C_FLAGS=${CMAKE_C_FLAGS}
+ -DCMAKE_C_FLAGS_DEBUG=${CMAKE_C_FLAGS_DEBUG}
+ -DCMAKE_C_FLAGS_RELEASE=${CMAKE_C_FLAGS_RELEASE}
+ -DBUILD_STATIC_LIBS=ON
+ -DCMAKE_INSTALL_PREFIX=${GFLAGS_INSTALL_DIR}
+ -DCMAKE_POSITION_INDEPENDENT_CODE=ON
+ -DBUILD_TESTING=OFF
+ -DCMAKE_BUILD_TYPE=${THIRD_PARTY_BUILD_TYPE}
+ ${EXTERNAL_OPTIONAL_ARGS}
+ CMAKE_CACHE_ARGS -DCMAKE_INSTALL_PREFIX:PATH=${GFLAGS_INSTALL_DIR}
+ -DCMAKE_POSITION_INDEPENDENT_CODE:BOOL=ON
+ -DCMAKE_BUILD_TYPE:STRING=${THIRD_PARTY_BUILD_TYPE}
+ BUILD_BYPRODUCTS ${GFLAGS_LIBRARIES}
+)
else()
ExternalProject_Add(
extern_gflags
${EXTERNAL_PROJECT_LOG_ARGS}
- ${SHALLOW_CLONE}
- GIT_REPOSITORY ${GFLAGS_REPOSITORY}
- GIT_TAG ${GFLAGS_TAG}
+ URL ${GFLAGS_URL}
PREFIX ${GFLAGS_PREFIX_DIR}
UPDATE_COMMAND ""
BUILD_COMMAND ${BUILD_COMMAND}
From 3db057f918e952bd6497e7ed82f56a597522574b Mon Sep 17 00:00:00 2001
From: Jason
Date: Wed, 14 Dec 2022 16:45:46 +0800
Subject: [PATCH 51/77] =?UTF-8?q?Update=20=E6=8A=A5=E5=91=8Aissue.md?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.github/ISSUE_TEMPLATE/报告issue.md | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/.github/ISSUE_TEMPLATE/报告issue.md b/.github/ISSUE_TEMPLATE/报告issue.md
index 7cc400ace..a5d48a530 100644
--- a/.github/ISSUE_TEMPLATE/报告issue.md
+++ b/.github/ISSUE_TEMPLATE/报告issue.md
@@ -27,5 +27,7 @@ assignees: ''
*********************************************
-请按照此issue模板进行提问,这会大大减少工程师与你确认使用环境,编译过程中的基础信息时间
+开源不易,工程师每天有大量研发工作,请直接按此issue模版进行提问
+
+这会大大减少工程师与你确认使用环境,编译过程中的基础信息时间
*********************************************
From e7c244054bc624999e2cc5b02b75417ad4ba2919 Mon Sep 17 00:00:00 2001
From: Jason
Date: Wed, 14 Dec 2022 16:46:28 +0800
Subject: [PATCH 52/77] =?UTF-8?q?Update=20=E6=8A=A5=E5=91=8Aissue.md?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.github/ISSUE_TEMPLATE/报告issue.md | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/.github/ISSUE_TEMPLATE/报告issue.md b/.github/ISSUE_TEMPLATE/报告issue.md
index a5d48a530..be93cd251 100644
--- a/.github/ISSUE_TEMPLATE/报告issue.md
+++ b/.github/ISSUE_TEMPLATE/报告issue.md
@@ -7,6 +7,12 @@ assignees: ''
---
+*********************************************
+开源不易,工程师每天有大量研发工作,请直接按此issue模版进行提问
+
+这会大大减少工程师与你确认使用环境,编译过程中的基础信息时间
+*********************************************
+
## 环境
- FastDeploy版本: 说明具体的版本,如fastdeploy-linux-gpu-0.8.0
From 376fdbfe2c40d966416638dfa30a6bb092468461 Mon Sep 17 00:00:00 2001
From: huangjianhui <852142024@qq.com>
Date: Wed, 14 Dec 2022 17:25:58 +0800
Subject: [PATCH 53/77] [Other] Update old Api to new ones (#861)
* Update keypointdetection result docs
* Update im.copy() to im in examples
* Update new Api, fastdeploy::vision::Visualize to fastdeploy::vision
* Update SwapBackgroundSegmentation && SwapBackgroundMatting to SwapBackground
* Update README_CN.md
* Update README_CN.md
---
README_CN.md | 2 +-
.../vision/detection/nanodet_plus/cpp/infer.cc | 9 +++------
.../vision/detection/scaledyolov4/cpp/infer.cc | 9 +++------
examples/vision/detection/yolor/cpp/infer.cc | 9 +++------
examples/vision/detection/yolov5/cpp/infer.cc | 9 +++------
.../vision/detection/yolov5/quantize/cpp/infer.cc | 3 +--
examples/vision/detection/yolov5lite/cpp/infer.cc | 9 +++------
examples/vision/detection/yolov6/cpp/infer.cc | 9 +++------
.../vision/detection/yolov6/quantize/cpp/infer.cc | 3 +--
examples/vision/detection/yolov7/cpp/infer.cc | 9 +++------
.../vision/detection/yolov7/quantize/cpp/infer.cc | 3 +--
.../detection/yolov7end2end_ort/cpp/infer.cc | 9 +++------
.../detection/yolov7end2end_trt/cpp/infer.cc | 11 ++++-------
examples/vision/detection/yolox/cpp/infer.cc | 9 +++------
examples/vision/facedet/retinaface/cpp/infer.cc | 9 +++------
examples/vision/facedet/scrfd/cpp/infer.cc | 9 +++------
examples/vision/facedet/scrfd/rknpu2/cpp/infer.cc | 2 +-
examples/vision/facedet/ultraface/cpp/infer.cc | 9 +++------
examples/vision/facedet/yolov5face/cpp/infer.cc | 9 +++------
examples/vision/matting/modnet/cpp/infer.cc | 15 ++++++---------
examples/vision/matting/modnet/python/infer.py | 2 +-
examples/vision/matting/ppmatting/cpp/infer.cc | 15 ++++++---------
examples/vision/matting/ppmatting/python/infer.py | 2 +-
examples/vision/matting/rvm/python/infer.py | 4 ++--
24 files changed, 64 insertions(+), 115 deletions(-)
diff --git a/README_CN.md b/README_CN.md
index 28ef9f0b4..9cb3ecf6c 100755
--- a/README_CN.md
+++ b/README_CN.md
@@ -164,7 +164,7 @@ int main(int argc, char* argv[]) {
vision::DetectionResult res;
model.Predict(im, &res);
- auto vis_im = vision::Visualize::VisDetection(im, res, 0.5);
+ auto vis_im = vision::VisDetection(im, res, 0.5);
cv::imwrite("vis_image.jpg", vis_im);
return 0;
}
diff --git a/examples/vision/detection/nanodet_plus/cpp/infer.cc b/examples/vision/detection/nanodet_plus/cpp/infer.cc
index 8443639cc..ec0bbee98 100644
--- a/examples/vision/detection/nanodet_plus/cpp/infer.cc
+++ b/examples/vision/detection/nanodet_plus/cpp/infer.cc
@@ -22,7 +22,6 @@ void CpuInfer(const std::string& model_file, const std::string& image_file) {
}
auto im = cv::imread(image_file);
- auto im_bak = im.clone();
fastdeploy::vision::DetectionResult res;
if (!model.Predict(&im, &res)) {
@@ -30,7 +29,7 @@ void CpuInfer(const std::string& model_file, const std::string& image_file) {
return;
}
std::cout << res.Str() << std::endl;
- auto vis_im = fastdeploy::vision::Visualize::VisDetection(im_bak, res);
+ auto vis_im = fastdeploy::vision::VisDetection(im, res);
cv::imwrite("vis_result.jpg", vis_im);
std::cout << "Visualized result saved in ./vis_result.jpg" << std::endl;
}
@@ -46,7 +45,6 @@ void GpuInfer(const std::string& model_file, const std::string& image_file) {
}
auto im = cv::imread(image_file);
- auto im_bak = im.clone();
fastdeploy::vision::DetectionResult res;
if (!model.Predict(&im, &res)) {
@@ -55,7 +53,7 @@ void GpuInfer(const std::string& model_file, const std::string& image_file) {
}
std::cout << res.Str() << std::endl;
- auto vis_im = fastdeploy::vision::Visualize::VisDetection(im_bak, res);
+ auto vis_im = fastdeploy::vision::VisDetection(im, res);
cv::imwrite("vis_result.jpg", vis_im);
std::cout << "Visualized result saved in ./vis_result.jpg" << std::endl;
}
@@ -73,7 +71,6 @@ void TrtInfer(const std::string& model_file, const std::string& image_file) {
}
auto im = cv::imread(image_file);
- auto im_bak = im.clone();
fastdeploy::vision::DetectionResult res;
if (!model.Predict(&im, &res)) {
@@ -82,7 +79,7 @@ void TrtInfer(const std::string& model_file, const std::string& image_file) {
}
std::cout << res.Str() << std::endl;
- auto vis_im = fastdeploy::vision::Visualize::VisDetection(im_bak, res);
+ auto vis_im = fastdeploy::vision::VisDetection(im, res);
cv::imwrite("vis_result.jpg", vis_im);
std::cout << "Visualized result saved in ./vis_result.jpg" << std::endl;
}
diff --git a/examples/vision/detection/scaledyolov4/cpp/infer.cc b/examples/vision/detection/scaledyolov4/cpp/infer.cc
index 7d912b223..683156cc9 100644
--- a/examples/vision/detection/scaledyolov4/cpp/infer.cc
+++ b/examples/vision/detection/scaledyolov4/cpp/infer.cc
@@ -22,7 +22,6 @@ void CpuInfer(const std::string& model_file, const std::string& image_file) {
}
auto im = cv::imread(image_file);
- auto im_bak = im.clone();
fastdeploy::vision::DetectionResult res;
if (!model.Predict(&im, &res)) {
@@ -31,7 +30,7 @@ void CpuInfer(const std::string& model_file, const std::string& image_file) {
}
std::cout << res.Str() << std::endl;
- auto vis_im = fastdeploy::vision::Visualize::VisDetection(im_bak, res);
+ auto vis_im = fastdeploy::vision::VisDetection(im, res);
cv::imwrite("vis_result.jpg", vis_im);
std::cout << "Visualized result saved in ./vis_result.jpg" << std::endl;
}
@@ -47,7 +46,6 @@ void GpuInfer(const std::string& model_file, const std::string& image_file) {
}
auto im = cv::imread(image_file);
- auto im_bak = im.clone();
fastdeploy::vision::DetectionResult res;
if (!model.Predict(&im, &res)) {
@@ -56,7 +54,7 @@ void GpuInfer(const std::string& model_file, const std::string& image_file) {
}
std::cout << res.Str() << std::endl;
- auto vis_im = fastdeploy::vision::Visualize::VisDetection(im_bak, res);
+ auto vis_im = fastdeploy::vision::VisDetection(im, res);
cv::imwrite("vis_result.jpg", vis_im);
std::cout << "Visualized result saved in ./vis_result.jpg" << std::endl;
}
@@ -74,7 +72,6 @@ void TrtInfer(const std::string& model_file, const std::string& image_file) {
}
auto im = cv::imread(image_file);
- auto im_bak = im.clone();
fastdeploy::vision::DetectionResult res;
if (!model.Predict(&im, &res)) {
@@ -83,7 +80,7 @@ void TrtInfer(const std::string& model_file, const std::string& image_file) {
}
std::cout << res.Str() << std::endl;
- auto vis_im = fastdeploy::vision::Visualize::VisDetection(im_bak, res);
+ auto vis_im = fastdeploy::vision::VisDetection(im, res);
cv::imwrite("vis_result.jpg", vis_im);
std::cout << "Visualized result saved in ./vis_result.jpg" << std::endl;
}
diff --git a/examples/vision/detection/yolor/cpp/infer.cc b/examples/vision/detection/yolor/cpp/infer.cc
index 0fe8913d4..bacc18b40 100644
--- a/examples/vision/detection/yolor/cpp/infer.cc
+++ b/examples/vision/detection/yolor/cpp/infer.cc
@@ -22,7 +22,6 @@ void CpuInfer(const std::string& model_file, const std::string& image_file) {
}
auto im = cv::imread(image_file);
- auto im_bak = im.clone();
fastdeploy::vision::DetectionResult res;
if (!model.Predict(&im, &res)) {
@@ -31,7 +30,7 @@ void CpuInfer(const std::string& model_file, const std::string& image_file) {
}
std::cout << res.Str() << std::endl;
- auto vis_im = fastdeploy::vision::Visualize::VisDetection(im_bak, res);
+ auto vis_im = fastdeploy::vision::VisDetection(im, res);
cv::imwrite("vis_result.jpg", vis_im);
std::cout << "Visualized result saved in ./vis_result.jpg" << std::endl;
}
@@ -46,7 +45,6 @@ void GpuInfer(const std::string& model_file, const std::string& image_file) {
}
auto im = cv::imread(image_file);
- auto im_bak = im.clone();
fastdeploy::vision::DetectionResult res;
if (!model.Predict(&im, &res)) {
@@ -55,7 +53,7 @@ void GpuInfer(const std::string& model_file, const std::string& image_file) {
}
std::cout << res.Str() << std::endl;
- auto vis_im = fastdeploy::vision::Visualize::VisDetection(im_bak, res);
+ auto vis_im = fastdeploy::vision::VisDetection(im, res);
cv::imwrite("vis_result.jpg", vis_im);
std::cout << "Visualized result saved in ./vis_result.jpg" << std::endl;
}
@@ -72,7 +70,6 @@ void TrtInfer(const std::string& model_file, const std::string& image_file) {
}
auto im = cv::imread(image_file);
- auto im_bak = im.clone();
fastdeploy::vision::DetectionResult res;
if (!model.Predict(&im, &res)) {
@@ -81,7 +78,7 @@ void TrtInfer(const std::string& model_file, const std::string& image_file) {
}
std::cout << res.Str() << std::endl;
- auto vis_im = fastdeploy::vision::Visualize::VisDetection(im_bak, res);
+ auto vis_im = fastdeploy::vision::VisDetection(im, res);
cv::imwrite("vis_result.jpg", vis_im);
std::cout << "Visualized result saved in ./vis_result.jpg" << std::endl;
}
diff --git a/examples/vision/detection/yolov5/cpp/infer.cc b/examples/vision/detection/yolov5/cpp/infer.cc
index a7ac1fe81..1c3907918 100644
--- a/examples/vision/detection/yolov5/cpp/infer.cc
+++ b/examples/vision/detection/yolov5/cpp/infer.cc
@@ -22,7 +22,6 @@ void CpuInfer(const std::string& model_file, const std::string& image_file) {
}
auto im = cv::imread(image_file);
- auto im_bak = im.clone();
fastdeploy::vision::DetectionResult res;
if (!model.Predict(&im, &res)) {
@@ -31,7 +30,7 @@ void CpuInfer(const std::string& model_file, const std::string& image_file) {
}
std::cout << res.Str() << std::endl;
- auto vis_im = fastdeploy::vision::Visualize::VisDetection(im_bak, res);
+ auto vis_im = fastdeploy::vision::VisDetection(im, res);
cv::imwrite("vis_result.jpg", vis_im);
std::cout << "Visualized result saved in ./vis_result.jpg" << std::endl;
}
@@ -46,7 +45,6 @@ void GpuInfer(const std::string& model_file, const std::string& image_file) {
}
auto im = cv::imread(image_file);
- auto im_bak = im.clone();
fastdeploy::vision::DetectionResult res;
if (!model.Predict(&im, &res)) {
@@ -55,7 +53,7 @@ void GpuInfer(const std::string& model_file, const std::string& image_file) {
}
std::cout << res.Str() << std::endl;
- auto vis_im = fastdeploy::vision::Visualize::VisDetection(im_bak, res);
+ auto vis_im = fastdeploy::vision::VisDetection(im, res);
cv::imwrite("vis_result.jpg", vis_im);
std::cout << "Visualized result saved in ./vis_result.jpg" << std::endl;
}
@@ -72,7 +70,6 @@ void TrtInfer(const std::string& model_file, const std::string& image_file) {
}
auto im = cv::imread(image_file);
- auto im_bak = im.clone();
fastdeploy::vision::DetectionResult res;
if (!model.Predict(&im, &res)) {
@@ -81,7 +78,7 @@ void TrtInfer(const std::string& model_file, const std::string& image_file) {
}
std::cout << res.Str() << std::endl;
- auto vis_im = fastdeploy::vision::Visualize::VisDetection(im_bak, res);
+ auto vis_im = fastdeploy::vision::VisDetection(im, res);
cv::imwrite("vis_result.jpg", vis_im);
std::cout << "Visualized result saved in ./vis_result.jpg" << std::endl;
}
diff --git a/examples/vision/detection/yolov5/quantize/cpp/infer.cc b/examples/vision/detection/yolov5/quantize/cpp/infer.cc
index e429b2aad..1addf1507 100644
--- a/examples/vision/detection/yolov5/quantize/cpp/infer.cc
+++ b/examples/vision/detection/yolov5/quantize/cpp/infer.cc
@@ -29,7 +29,6 @@ void InitAndInfer(const std::string& model_dir, const std::string& image_file,
assert(model.Initialized());
auto im = cv::imread(image_file);
- auto im_bak = im.clone();
fastdeploy::vision::DetectionResult res;
if (!model.Predict(&im, &res)) {
@@ -39,7 +38,7 @@ void InitAndInfer(const std::string& model_dir, const std::string& image_file,
std::cout << res.Str() << std::endl;
- auto vis_im = fastdeploy::vision::Visualize::VisDetection(im_bak, res);
+ auto vis_im = fastdeploy::vision::VisDetection(im, res);
cv::imwrite("vis_result.jpg", vis_im);
std::cout << "Visualized result saved in ./vis_result.jpg" << std::endl;
}
diff --git a/examples/vision/detection/yolov5lite/cpp/infer.cc b/examples/vision/detection/yolov5lite/cpp/infer.cc
index ac32bca93..0a3f7b81b 100644
--- a/examples/vision/detection/yolov5lite/cpp/infer.cc
+++ b/examples/vision/detection/yolov5lite/cpp/infer.cc
@@ -22,7 +22,6 @@ void CpuInfer(const std::string& model_file, const std::string& image_file) {
}
auto im = cv::imread(image_file);
- auto im_bak = im.clone();
fastdeploy::vision::DetectionResult res;
if (!model.Predict(&im, &res)) {
@@ -31,7 +30,7 @@ void CpuInfer(const std::string& model_file, const std::string& image_file) {
}
std::cout << res.Str() << std::endl;
- auto vis_im = fastdeploy::vision::Visualize::VisDetection(im_bak, res);
+ auto vis_im = fastdeploy::vision::VisDetection(im, res);
cv::imwrite("vis_result.jpg", vis_im);
std::cout << "Visualized result saved in ./vis_result.jpg" << std::endl;
}
@@ -47,7 +46,6 @@ void GpuInfer(const std::string& model_file, const std::string& image_file) {
}
auto im = cv::imread(image_file);
- auto im_bak = im.clone();
fastdeploy::vision::DetectionResult res;
if (!model.Predict(&im, &res)) {
@@ -56,7 +54,7 @@ void GpuInfer(const std::string& model_file, const std::string& image_file) {
}
std::cout << res.Str() << std::endl;
- auto vis_im = fastdeploy::vision::Visualize::VisDetection(im_bak, res);
+ auto vis_im = fastdeploy::vision::VisDetection(im, res);
cv::imwrite("vis_result.jpg", vis_im);
std::cout << "Visualized result saved in ./vis_result.jpg" << std::endl;
}
@@ -74,7 +72,6 @@ void TrtInfer(const std::string& model_file, const std::string& image_file) {
}
auto im = cv::imread(image_file);
- auto im_bak = im.clone();
fastdeploy::vision::DetectionResult res;
if (!model.Predict(&im, &res)) {
@@ -83,7 +80,7 @@ void TrtInfer(const std::string& model_file, const std::string& image_file) {
}
std::cout << res.Str() << std::endl;
- auto vis_im = fastdeploy::vision::Visualize::VisDetection(im_bak, res);
+ auto vis_im = fastdeploy::vision::VisDetection(im, res);
cv::imwrite("vis_result.jpg", vis_im);
std::cout << "Visualized result saved in ./vis_result.jpg" << std::endl;
}
diff --git a/examples/vision/detection/yolov6/cpp/infer.cc b/examples/vision/detection/yolov6/cpp/infer.cc
index 72b2e7bed..dbca64f40 100644
--- a/examples/vision/detection/yolov6/cpp/infer.cc
+++ b/examples/vision/detection/yolov6/cpp/infer.cc
@@ -22,7 +22,6 @@ void CpuInfer(const std::string& model_file, const std::string& image_file) {
}
auto im = cv::imread(image_file);
- auto im_bak = im.clone();
fastdeploy::vision::DetectionResult res;
if (!model.Predict(&im, &res)) {
@@ -31,7 +30,7 @@ void CpuInfer(const std::string& model_file, const std::string& image_file) {
}
std::cout << res.Str() << std::endl;
- auto vis_im = fastdeploy::vision::Visualize::VisDetection(im_bak, res);
+ auto vis_im = fastdeploy::vision::VisDetection(im, res);
cv::imwrite("vis_result.jpg", vis_im);
std::cout << "Visualized result saved in ./vis_result.jpg" << std::endl;
}
@@ -46,7 +45,6 @@ void GpuInfer(const std::string& model_file, const std::string& image_file) {
}
auto im = cv::imread(image_file);
- auto im_bak = im.clone();
fastdeploy::vision::DetectionResult res;
if (!model.Predict(&im, &res)) {
@@ -55,7 +53,7 @@ void GpuInfer(const std::string& model_file, const std::string& image_file) {
}
std::cout << res.Str() << std::endl;
- auto vis_im = fastdeploy::vision::Visualize::VisDetection(im_bak, res);
+ auto vis_im = fastdeploy::vision::VisDetection(im, res);
cv::imwrite("vis_result.jpg", vis_im);
std::cout << "Visualized result saved in ./vis_result.jpg" << std::endl;
}
@@ -72,7 +70,6 @@ void TrtInfer(const std::string& model_file, const std::string& image_file) {
}
auto im = cv::imread(image_file);
- auto im_bak = im.clone();
fastdeploy::vision::DetectionResult res;
if (!model.Predict(&im, &res)) {
@@ -81,7 +78,7 @@ void TrtInfer(const std::string& model_file, const std::string& image_file) {
}
std::cout << res.Str() << std::endl;
- auto vis_im = fastdeploy::vision::Visualize::VisDetection(im_bak, res);
+ auto vis_im = fastdeploy::vision::VisDetection(im, res);
cv::imwrite("vis_result.jpg", vis_im);
std::cout << "Visualized result saved in ./vis_result.jpg" << std::endl;
}
diff --git a/examples/vision/detection/yolov6/quantize/cpp/infer.cc b/examples/vision/detection/yolov6/quantize/cpp/infer.cc
index b40200962..adda977f3 100644
--- a/examples/vision/detection/yolov6/quantize/cpp/infer.cc
+++ b/examples/vision/detection/yolov6/quantize/cpp/infer.cc
@@ -29,7 +29,6 @@ void InitAndInfer(const std::string& model_dir, const std::string& image_file,
assert(model.Initialized());
auto im = cv::imread(image_file);
- auto im_bak = im.clone();
fastdeploy::vision::DetectionResult res;
if (!model.Predict(&im, &res)) {
@@ -39,7 +38,7 @@ void InitAndInfer(const std::string& model_dir, const std::string& image_file,
std::cout << res.Str() << std::endl;
- auto vis_im = fastdeploy::vision::Visualize::VisDetection(im_bak, res);
+ auto vis_im = fastdeploy::vision::VisDetection(im, res);
cv::imwrite("vis_result.jpg", vis_im);
std::cout << "Visualized result saved in ./vis_result.jpg" << std::endl;
}
diff --git a/examples/vision/detection/yolov7/cpp/infer.cc b/examples/vision/detection/yolov7/cpp/infer.cc
index cf79a16ad..5fd848b8e 100644
--- a/examples/vision/detection/yolov7/cpp/infer.cc
+++ b/examples/vision/detection/yolov7/cpp/infer.cc
@@ -22,7 +22,6 @@ void CpuInfer(const std::string& model_file, const std::string& image_file) {
}
auto im = cv::imread(image_file);
- auto im_bak = im.clone();
fastdeploy::vision::DetectionResult res;
if (!model.Predict(&im, &res)) {
@@ -31,7 +30,7 @@ void CpuInfer(const std::string& model_file, const std::string& image_file) {
}
std::cout << res.Str() << std::endl;
- auto vis_im = fastdeploy::vision::Visualize::VisDetection(im_bak, res);
+ auto vis_im = fastdeploy::vision::VisDetection(im, res);
cv::imwrite("vis_result.jpg", vis_im);
std::cout << "Visualized result saved in ./vis_result.jpg" << std::endl;
}
@@ -46,7 +45,6 @@ void GpuInfer(const std::string& model_file, const std::string& image_file) {
}
auto im = cv::imread(image_file);
- auto im_bak = im.clone();
fastdeploy::vision::DetectionResult res;
if (!model.Predict(&im, &res)) {
@@ -55,7 +53,7 @@ void GpuInfer(const std::string& model_file, const std::string& image_file) {
}
std::cout << res.Str() << std::endl;
- auto vis_im = fastdeploy::vision::Visualize::VisDetection(im_bak, res);
+ auto vis_im = fastdeploy::vision::VisDetection(im, res);
cv::imwrite("vis_result.jpg", vis_im);
std::cout << "Visualized result saved in ./vis_result.jpg" << std::endl;
}
@@ -72,7 +70,6 @@ void TrtInfer(const std::string& model_file, const std::string& image_file) {
}
auto im = cv::imread(image_file);
- auto im_bak = im.clone();
fastdeploy::vision::DetectionResult res;
if (!model.Predict(&im, &res)) {
@@ -81,7 +78,7 @@ void TrtInfer(const std::string& model_file, const std::string& image_file) {
}
std::cout << res.Str() << std::endl;
- auto vis_im = fastdeploy::vision::Visualize::VisDetection(im_bak, res);
+ auto vis_im = fastdeploy::vision::VisDetection(im, res);
cv::imwrite("vis_result.jpg", vis_im);
std::cout << "Visualized result saved in ./vis_result.jpg" << std::endl;
}
diff --git a/examples/vision/detection/yolov7/quantize/cpp/infer.cc b/examples/vision/detection/yolov7/quantize/cpp/infer.cc
index 0eda80b6c..9ae42b582 100644
--- a/examples/vision/detection/yolov7/quantize/cpp/infer.cc
+++ b/examples/vision/detection/yolov7/quantize/cpp/infer.cc
@@ -29,7 +29,6 @@ void InitAndInfer(const std::string& model_dir, const std::string& image_file,
assert(model.Initialized());
auto im = cv::imread(image_file);
- auto im_bak = im.clone();
fastdeploy::vision::DetectionResult res;
if (!model.Predict(&im, &res)) {
@@ -39,7 +38,7 @@ void InitAndInfer(const std::string& model_dir, const std::string& image_file,
std::cout << res.Str() << std::endl;
- auto vis_im = fastdeploy::vision::Visualize::VisDetection(im_bak, res);
+ auto vis_im = fastdeploy::vision::VisDetection(im, res);
cv::imwrite("vis_result.jpg", vis_im);
std::cout << "Visualized result saved in ./vis_result.jpg" << std::endl;
}
diff --git a/examples/vision/detection/yolov7end2end_ort/cpp/infer.cc b/examples/vision/detection/yolov7end2end_ort/cpp/infer.cc
index a0e70544a..5c9df2816 100644
--- a/examples/vision/detection/yolov7end2end_ort/cpp/infer.cc
+++ b/examples/vision/detection/yolov7end2end_ort/cpp/infer.cc
@@ -22,7 +22,6 @@ void CpuInfer(const std::string& model_file, const std::string& image_file) {
}
auto im = cv::imread(image_file);
- auto im_bak = im.clone();
fastdeploy::vision::DetectionResult res;
if (!model.Predict(&im, &res)) {
@@ -31,7 +30,7 @@ void CpuInfer(const std::string& model_file, const std::string& image_file) {
}
std::cout << res.Str() << std::endl;
- auto vis_im = fastdeploy::vision::Visualize::VisDetection(im_bak, res);
+ auto vis_im = fastdeploy::vision::VisDetection(im, res);
cv::imwrite("vis_result.jpg", vis_im);
std::cout << "Visualized result saved in ./vis_result.jpg" << std::endl;
}
@@ -47,7 +46,6 @@ void GpuInfer(const std::string& model_file, const std::string& image_file) {
}
auto im = cv::imread(image_file);
- auto im_bak = im.clone();
fastdeploy::vision::DetectionResult res;
if (!model.Predict(&im, &res)) {
@@ -56,7 +54,7 @@ void GpuInfer(const std::string& model_file, const std::string& image_file) {
}
std::cout << res.Str() << std::endl;
- auto vis_im = fastdeploy::vision::Visualize::VisDetection(im_bak, res);
+ auto vis_im = fastdeploy::vision::VisDetection(im, res);
cv::imwrite("vis_result.jpg", vis_im);
std::cout << "Visualized result saved in ./vis_result.jpg" << std::endl;
}
@@ -74,7 +72,6 @@ void TrtInfer(const std::string& model_file, const std::string& image_file) {
}
auto im = cv::imread(image_file);
- auto im_bak = im.clone();
fastdeploy::vision::DetectionResult res;
if (!model.Predict(&im, &res)) {
@@ -83,7 +80,7 @@ void TrtInfer(const std::string& model_file, const std::string& image_file) {
}
std::cout << res.Str() << std::endl;
- auto vis_im = fastdeploy::vision::Visualize::VisDetection(im_bak, res);
+ auto vis_im = fastdeploy::vision::VisDetection(im, res);
cv::imwrite("vis_result.jpg", vis_im);
std::cout << "Visualized result saved in ./vis_result.jpg" << std::endl;
}
diff --git a/examples/vision/detection/yolov7end2end_trt/cpp/infer.cc b/examples/vision/detection/yolov7end2end_trt/cpp/infer.cc
index 1c7a17d37..4f7a2f791 100644
--- a/examples/vision/detection/yolov7end2end_trt/cpp/infer.cc
+++ b/examples/vision/detection/yolov7end2end_trt/cpp/infer.cc
@@ -22,7 +22,6 @@ void CpuInfer(const std::string& model_file, const std::string& image_file) {
}
auto im = cv::imread(image_file);
- auto im_bak = im.clone();
fastdeploy::vision::DetectionResult res;
if (!model.Predict(&im, &res)) {
@@ -31,7 +30,7 @@ void CpuInfer(const std::string& model_file, const std::string& image_file) {
}
std::cout << res.Str() << std::endl;
- auto vis_im = fastdeploy::vision::Visualize::VisDetection(im_bak, res);
+ auto vis_im = fastdeploy::vision::VisDetection(im, res);
cv::imwrite("vis_result.jpg", vis_im);
std::cout << "Visualized result saved in ./vis_result.jpg" << std::endl;
}
@@ -47,7 +46,6 @@ void GpuInfer(const std::string& model_file, const std::string& image_file) {
}
auto im = cv::imread(image_file);
- auto im_bak = im.clone();
fastdeploy::vision::DetectionResult res;
if (!model.Predict(&im, &res)) {
@@ -56,7 +54,7 @@ void GpuInfer(const std::string& model_file, const std::string& image_file) {
}
std::cout << res.Str() << std::endl;
- auto vis_im = fastdeploy::vision::Visualize::VisDetection(im_bak, res);
+ auto vis_im = fastdeploy::vision::VisDetection(im, res);
cv::imwrite("vis_result.jpg", vis_im);
std::cout << "Visualized result saved in ./vis_result.jpg" << std::endl;
}
@@ -74,7 +72,6 @@ void TrtInfer(const std::string& model_file, const std::string& image_file) {
}
auto im = cv::imread(image_file);
- auto im_bak = im.clone();
fastdeploy::vision::DetectionResult res;
if (!model.Predict(&im, &res)) {
@@ -83,7 +80,7 @@ void TrtInfer(const std::string& model_file, const std::string& image_file) {
}
std::cout << res.Str() << std::endl;
- auto vis_im = fastdeploy::vision::Visualize::VisDetection(im_bak, res);
+ auto vis_im = fastdeploy::vision::VisDetection(im, res);
cv::imwrite("vis_result.jpg", vis_im);
std::cout << "Visualized result saved in ./vis_result.jpg" << std::endl;
}
@@ -107,4 +104,4 @@ int main(int argc, char* argv[]) {
TrtInfer(argv[1], argv[2]);
}
return 0;
-}
\ No newline at end of file
+}
diff --git a/examples/vision/detection/yolox/cpp/infer.cc b/examples/vision/detection/yolox/cpp/infer.cc
index 2eeaccbf8..836ab7e63 100644
--- a/examples/vision/detection/yolox/cpp/infer.cc
+++ b/examples/vision/detection/yolox/cpp/infer.cc
@@ -22,7 +22,6 @@ void CpuInfer(const std::string& model_file, const std::string& image_file) {
}
auto im = cv::imread(image_file);
- auto im_bak = im.clone();
fastdeploy::vision::DetectionResult res;
if (!model.Predict(&im, &res)) {
@@ -31,7 +30,7 @@ void CpuInfer(const std::string& model_file, const std::string& image_file) {
}
std::cout << res.Str() << std::endl;
- auto vis_im = fastdeploy::vision::Visualize::VisDetection(im_bak, res);
+ auto vis_im = fastdeploy::vision::VisDetection(im, res);
cv::imwrite("vis_result.jpg", vis_im);
std::cout << "Visualized result saved in ./vis_result.jpg" << std::endl;
}
@@ -46,7 +45,6 @@ void GpuInfer(const std::string& model_file, const std::string& image_file) {
}
auto im = cv::imread(image_file);
- auto im_bak = im.clone();
fastdeploy::vision::DetectionResult res;
if (!model.Predict(&im, &res)) {
@@ -55,7 +53,7 @@ void GpuInfer(const std::string& model_file, const std::string& image_file) {
}
std::cout << res.Str() << std::endl;
- auto vis_im = fastdeploy::vision::Visualize::VisDetection(im_bak, res);
+ auto vis_im = fastdeploy::vision::VisDetection(im, res);
cv::imwrite("vis_result.jpg", vis_im);
std::cout << "Visualized result saved in ./vis_result.jpg" << std::endl;
}
@@ -72,7 +70,6 @@ void TrtInfer(const std::string& model_file, const std::string& image_file) {
}
auto im = cv::imread(image_file);
- auto im_bak = im.clone();
fastdeploy::vision::DetectionResult res;
if (!model.Predict(&im, &res)) {
@@ -81,7 +78,7 @@ void TrtInfer(const std::string& model_file, const std::string& image_file) {
}
std::cout << res.Str() << std::endl;
- auto vis_im = fastdeploy::vision::Visualize::VisDetection(im_bak, res);
+ auto vis_im = fastdeploy::vision::VisDetection(im, res);
cv::imwrite("vis_result.jpg", vis_im);
std::cout << "Visualized result saved in ./vis_result.jpg" << std::endl;
}
diff --git a/examples/vision/facedet/retinaface/cpp/infer.cc b/examples/vision/facedet/retinaface/cpp/infer.cc
index a1fd27b6e..f125e4ba7 100644
--- a/examples/vision/facedet/retinaface/cpp/infer.cc
+++ b/examples/vision/facedet/retinaface/cpp/infer.cc
@@ -22,7 +22,6 @@ void CpuInfer(const std::string& model_file, const std::string& image_file) {
}
auto im = cv::imread(image_file);
- auto im_bak = im.clone();
fastdeploy::vision::FaceDetectionResult res;
if (!model.Predict(&im, &res)) {
@@ -31,7 +30,7 @@ void CpuInfer(const std::string& model_file, const std::string& image_file) {
}
std::cout << res.Str() << std::endl;
- auto vis_im = fastdeploy::vision::Visualize::VisFaceDetection(im_bak, res);
+ auto vis_im = fastdeploy::vision::VisFaceDetection(im, res);
cv::imwrite("vis_result.jpg", vis_im);
std::cout << "Visualized result saved in ./vis_result.jpg" << std::endl;
}
@@ -46,7 +45,6 @@ void GpuInfer(const std::string& model_file, const std::string& image_file) {
}
auto im = cv::imread(image_file);
- auto im_bak = im.clone();
fastdeploy::vision::FaceDetectionResult res;
if (!model.Predict(&im, &res)) {
@@ -55,7 +53,7 @@ void GpuInfer(const std::string& model_file, const std::string& image_file) {
}
std::cout << res.Str() << std::endl;
- auto vis_im = fastdeploy::vision::Visualize::VisFaceDetection(im_bak, res);
+ auto vis_im = fastdeploy::vision::VisFaceDetection(im, res);
cv::imwrite("vis_result.jpg", vis_im);
std::cout << "Visualized result saved in ./vis_result.jpg" << std::endl;
}
@@ -72,7 +70,6 @@ void TrtInfer(const std::string& model_file, const std::string& image_file) {
}
auto im = cv::imread(image_file);
- auto im_bak = im.clone();
fastdeploy::vision::FaceDetectionResult res;
if (!model.Predict(&im, &res)) {
@@ -81,7 +78,7 @@ void TrtInfer(const std::string& model_file, const std::string& image_file) {
}
std::cout << res.Str() << std::endl;
- auto vis_im = fastdeploy::vision::Visualize::VisFaceDetection(im_bak, res);
+ auto vis_im = fastdeploy::vision::VisFaceDetection(im, res);
cv::imwrite("vis_result.jpg", vis_im);
std::cout << "Visualized result saved in ./vis_result.jpg" << std::endl;
}
diff --git a/examples/vision/facedet/scrfd/cpp/infer.cc b/examples/vision/facedet/scrfd/cpp/infer.cc
index c804218ee..c09403741 100644
--- a/examples/vision/facedet/scrfd/cpp/infer.cc
+++ b/examples/vision/facedet/scrfd/cpp/infer.cc
@@ -22,7 +22,6 @@ void CpuInfer(const std::string& model_file, const std::string& image_file) {
}
auto im = cv::imread(image_file);
- auto im_bak = im.clone();
fastdeploy::vision::FaceDetectionResult res;
if (!model.Predict(&im, &res)) {
@@ -31,7 +30,7 @@ void CpuInfer(const std::string& model_file, const std::string& image_file) {
}
std::cout << res.Str() << std::endl;
- auto vis_im = fastdeploy::vision::Visualize::VisFaceDetection(im_bak, res);
+ auto vis_im = fastdeploy::vision::VisFaceDetection(im, res);
cv::imwrite("vis_result.jpg", vis_im);
std::cout << "Visualized result saved in ./vis_result.jpg" << std::endl;
}
@@ -46,7 +45,6 @@ void GpuInfer(const std::string& model_file, const std::string& image_file) {
}
auto im = cv::imread(image_file);
- auto im_bak = im.clone();
fastdeploy::vision::FaceDetectionResult res;
if (!model.Predict(&im, &res)) {
@@ -55,7 +53,7 @@ void GpuInfer(const std::string& model_file, const std::string& image_file) {
}
std::cout << res.Str() << std::endl;
- auto vis_im = fastdeploy::vision::Visualize::VisFaceDetection(im_bak, res);
+ auto vis_im = fastdeploy::vision::VisFaceDetection(im, res);
cv::imwrite("vis_result.jpg", vis_im);
std::cout << "Visualized result saved in ./vis_result.jpg" << std::endl;
}
@@ -72,7 +70,6 @@ void TrtInfer(const std::string& model_file, const std::string& image_file) {
}
auto im = cv::imread(image_file);
- auto im_bak = im.clone();
fastdeploy::vision::FaceDetectionResult res;
if (!model.Predict(&im, &res)) {
@@ -81,7 +78,7 @@ void TrtInfer(const std::string& model_file, const std::string& image_file) {
}
std::cout << res.Str() << std::endl;
- auto vis_im = fastdeploy::vision::Visualize::VisFaceDetection(im_bak, res);
+ auto vis_im = fastdeploy::vision::VisFaceDetection(im, res);
cv::imwrite("vis_result.jpg", vis_im);
std::cout << "Visualized result saved in ./vis_result.jpg" << std::endl;
}
diff --git a/examples/vision/facedet/scrfd/rknpu2/cpp/infer.cc b/examples/vision/facedet/scrfd/rknpu2/cpp/infer.cc
index 4ac3496f5..e009d2ead 100644
--- a/examples/vision/facedet/scrfd/rknpu2/cpp/infer.cc
+++ b/examples/vision/facedet/scrfd/rknpu2/cpp/infer.cc
@@ -58,7 +58,7 @@ void RKNPU2Infer(const std::string& model_dir, const std::string& image_file) {
std::cerr << "Failed to predict." << std::endl;
return;
}
- auto vis_im = fastdeploy::vision::Visualize::VisFaceDetection(im, res);
+ auto vis_im = fastdeploy::vision::VisFaceDetection(im, res);
tc.End();
tc.PrintInfo("SCRFD in RKNN");
diff --git a/examples/vision/facedet/ultraface/cpp/infer.cc b/examples/vision/facedet/ultraface/cpp/infer.cc
index b45bb3b0b..b50674e1d 100644
--- a/examples/vision/facedet/ultraface/cpp/infer.cc
+++ b/examples/vision/facedet/ultraface/cpp/infer.cc
@@ -22,7 +22,6 @@ void CpuInfer(const std::string& model_file, const std::string& image_file) {
}
auto im = cv::imread(image_file);
- auto im_bak = im.clone();
fastdeploy::vision::FaceDetectionResult res;
if (!model.Predict(&im, &res)) {
@@ -31,7 +30,7 @@ void CpuInfer(const std::string& model_file, const std::string& image_file) {
}
std::cout << res.Str() << std::endl;
- auto vis_im = fastdeploy::vision::Visualize::VisFaceDetection(im_bak, res);
+ auto vis_im = fastdeploy::vision::VisFaceDetection(im, res);
cv::imwrite("vis_result.jpg", vis_im);
std::cout << "Visualized result saved in ./vis_result.jpg" << std::endl;
}
@@ -46,7 +45,6 @@ void GpuInfer(const std::string& model_file, const std::string& image_file) {
}
auto im = cv::imread(image_file);
- auto im_bak = im.clone();
fastdeploy::vision::FaceDetectionResult res;
if (!model.Predict(&im, &res)) {
@@ -55,7 +53,7 @@ void GpuInfer(const std::string& model_file, const std::string& image_file) {
}
std::cout << res.Str() << std::endl;
- auto vis_im = fastdeploy::vision::Visualize::VisFaceDetection(im_bak, res);
+ auto vis_im = fastdeploy::vision::VisFaceDetection(im, res);
cv::imwrite("vis_result.jpg", vis_im);
std::cout << "Visualized result saved in ./vis_result.jpg" << std::endl;
}
@@ -72,7 +70,6 @@ void TrtInfer(const std::string& model_file, const std::string& image_file) {
}
auto im = cv::imread(image_file);
- auto im_bak = im.clone();
fastdeploy::vision::FaceDetectionResult res;
if (!model.Predict(&im, &res)) {
@@ -81,7 +78,7 @@ void TrtInfer(const std::string& model_file, const std::string& image_file) {
}
std::cout << res.Str() << std::endl;
- auto vis_im = fastdeploy::vision::Visualize::VisFaceDetection(im_bak, res);
+ auto vis_im = fastdeploy::vision::VisFaceDetection(im, res);
cv::imwrite("vis_result.jpg", vis_im);
std::cout << "Visualized result saved in ./vis_result.jpg" << std::endl;
}
diff --git a/examples/vision/facedet/yolov5face/cpp/infer.cc b/examples/vision/facedet/yolov5face/cpp/infer.cc
index 418834e1e..ecdcfcd0c 100644
--- a/examples/vision/facedet/yolov5face/cpp/infer.cc
+++ b/examples/vision/facedet/yolov5face/cpp/infer.cc
@@ -22,7 +22,6 @@ void CpuInfer(const std::string& model_file, const std::string& image_file) {
}
auto im = cv::imread(image_file);
- auto im_bak = im.clone();
fastdeploy::vision::FaceDetectionResult res;
if (!model.Predict(&im, &res)) {
@@ -31,7 +30,7 @@ void CpuInfer(const std::string& model_file, const std::string& image_file) {
}
std::cout << res.Str() << std::endl;
- auto vis_im = fastdeploy::vision::Visualize::VisFaceDetection(im_bak, res);
+ auto vis_im = fastdeploy::vision::VisFaceDetection(im, res);
cv::imwrite("vis_result.jpg", vis_im);
std::cout << "Visualized result saved in ./vis_result.jpg" << std::endl;
}
@@ -46,7 +45,6 @@ void GpuInfer(const std::string& model_file, const std::string& image_file) {
}
auto im = cv::imread(image_file);
- auto im_bak = im.clone();
fastdeploy::vision::FaceDetectionResult res;
if (!model.Predict(&im, &res)) {
@@ -55,7 +53,7 @@ void GpuInfer(const std::string& model_file, const std::string& image_file) {
}
std::cout << res.Str() << std::endl;
- auto vis_im = fastdeploy::vision::Visualize::VisFaceDetection(im_bak, res);
+ auto vis_im = fastdeploy::vision::VisFaceDetection(im, res);
cv::imwrite("vis_result.jpg", vis_im);
std::cout << "Visualized result saved in ./vis_result.jpg" << std::endl;
}
@@ -72,7 +70,6 @@ void TrtInfer(const std::string& model_file, const std::string& image_file) {
}
auto im = cv::imread(image_file);
- auto im_bak = im.clone();
fastdeploy::vision::FaceDetectionResult res;
if (!model.Predict(&im, &res)) {
@@ -81,7 +78,7 @@ void TrtInfer(const std::string& model_file, const std::string& image_file) {
}
std::cout << res.Str() << std::endl;
- auto vis_im = fastdeploy::vision::Visualize::VisFaceDetection(im_bak, res);
+ auto vis_im = fastdeploy::vision::VisFaceDetection(im, res);
cv::imwrite("vis_result.jpg", vis_im);
std::cout << "Visualized result saved in ./vis_result.jpg" << std::endl;
}
diff --git a/examples/vision/matting/modnet/cpp/infer.cc b/examples/vision/matting/modnet/cpp/infer.cc
index fe1ebc910..aa280eddd 100644
--- a/examples/vision/matting/modnet/cpp/infer.cc
+++ b/examples/vision/matting/modnet/cpp/infer.cc
@@ -23,7 +23,6 @@ void CpuInfer(const std::string& model_file, const std::string& image_file,
}
model.size = {256, 256};
auto im = cv::imread(image_file);
- auto im_bak = im.clone();
cv::Mat bg = cv::imread(background_file);
fastdeploy::vision::MattingResult res;
@@ -32,9 +31,9 @@ void CpuInfer(const std::string& model_file, const std::string& image_file,
return;
}
- auto vis_im = fastdeploy::vision::VisMatting(im_bak, res);
+ auto vis_im = fastdeploy::vision::VisMatting(im, res);
auto vis_im_with_bg =
- fastdeploy::vision::Visualize::SwapBackgroundMatting(im_bak, bg, res);
+ fastdeploy::vision::SwapBackground(im, bg, res);
cv::imwrite("visualized_result.jpg", vis_im_with_bg);
cv::imwrite("visualized_result_fg.jpg", vis_im);
std::cout << "Visualized result save in ./visualized_result_replaced_bg.jpg "
@@ -54,7 +53,6 @@ void GpuInfer(const std::string& model_file, const std::string& image_file,
model.size = {256, 256};
auto im = cv::imread(image_file);
- auto im_bak = im.clone();
cv::Mat bg = cv::imread(background_file);
fastdeploy::vision::MattingResult res;
@@ -63,9 +61,9 @@ void GpuInfer(const std::string& model_file, const std::string& image_file,
return;
}
- auto vis_im = fastdeploy::vision::VisMatting(im_bak, res);
+ auto vis_im = fastdeploy::vision::VisMatting(im, res);
auto vis_im_with_bg =
- fastdeploy::vision::Visualize::SwapBackgroundMatting(im_bak, bg, res);
+ fastdeploy::vision::SwapBackground(im, bg, res);
cv::imwrite("visualized_result.jpg", vis_im_with_bg);
cv::imwrite("visualized_result_fg.jpg", vis_im);
std::cout << "Visualized result save in ./visualized_result_replaced_bg.jpg "
@@ -86,7 +84,6 @@ void TrtInfer(const std::string& model_file, const std::string& image_file,
}
model.size = {256, 256};
auto im = cv::imread(image_file);
- auto im_bak = im.clone();
cv::Mat bg = cv::imread(background_file);
fastdeploy::vision::MattingResult res;
@@ -95,9 +92,9 @@ void TrtInfer(const std::string& model_file, const std::string& image_file,
return;
}
- auto vis_im = fastdeploy::vision::VisMatting(im_bak, res);
+ auto vis_im = fastdeploy::vision::VisMatting(im, res);
auto vis_im_with_bg =
- fastdeploy::vision::Visualize::SwapBackgroundMatting(im_bak, bg, res);
+ fastdeploy::vision::SwapBackground(im, bg, res);
cv::imwrite("visualized_result.jpg", vis_im_with_bg);
cv::imwrite("visualized_result_fg.jpg", vis_im);
std::cout << "Visualized result save in ./visualized_result_replaced_bg.jpg "
diff --git a/examples/vision/matting/modnet/python/infer.py b/examples/vision/matting/modnet/python/infer.py
index abb9be037..37c749010 100644
--- a/examples/vision/matting/modnet/python/infer.py
+++ b/examples/vision/matting/modnet/python/infer.py
@@ -56,7 +56,7 @@ result = model.predict(im)
print(result)
# 可视化结果
vis_im = fd.vision.vis_matting_alpha(im, result)
-vis_im_with_bg = fd.vision.swap_background_matting(im, bg, result)
+vis_im_with_bg = fd.vision.swap_background(im, bg, result)
cv2.imwrite("visualized_result_fg.jpg", vis_im)
cv2.imwrite("visualized_result_replaced_bg.jpg", vis_im_with_bg)
print(
diff --git a/examples/vision/matting/ppmatting/cpp/infer.cc b/examples/vision/matting/ppmatting/cpp/infer.cc
index 304e4239a..2acb2a8ca 100644
--- a/examples/vision/matting/ppmatting/cpp/infer.cc
+++ b/examples/vision/matting/ppmatting/cpp/infer.cc
@@ -35,16 +35,15 @@ void CpuInfer(const std::string& model_dir, const std::string& image_file,
}
auto im = cv::imread(image_file);
- auto im_bak = im.clone();
cv::Mat bg = cv::imread(background_file);
fastdeploy::vision::MattingResult res;
if (!model.Predict(&im, &res)) {
std::cerr << "Failed to predict." << std::endl;
return;
}
- auto vis_im = fastdeploy::vision::VisMatting(im_bak, res);
+ auto vis_im = fastdeploy::vision::VisMatting(im, res);
auto vis_im_with_bg =
- fastdeploy::vision::Visualize::SwapBackgroundMatting(im_bak, bg, res);
+ fastdeploy::vision::SwapBackground(im, bg, res);
cv::imwrite("visualized_result.jpg", vis_im_with_bg);
cv::imwrite("visualized_result_fg.jpg", vis_im);
std::cout << "Visualized result save in ./visualized_result_replaced_bg.jpg "
@@ -69,16 +68,15 @@ void GpuInfer(const std::string& model_dir, const std::string& image_file,
}
auto im = cv::imread(image_file);
- auto im_bak = im.clone();
cv::Mat bg = cv::imread(background_file);
fastdeploy::vision::MattingResult res;
if (!model.Predict(&im, &res)) {
std::cerr << "Failed to predict." << std::endl;
return;
}
- auto vis_im = fastdeploy::vision::VisMatting(im_bak, res);
+ auto vis_im = fastdeploy::vision::VisMatting(im, res);
auto vis_im_with_bg =
- fastdeploy::vision::Visualize::SwapBackgroundMatting(im_bak, bg, res);
+ fastdeploy::vision::SwapBackground(im, bg, res);
cv::imwrite("visualized_result.jpg", vis_im_with_bg);
cv::imwrite("visualized_result_fg.jpg", vis_im);
std::cout << "Visualized result save in ./visualized_result_replaced_bg.jpg "
@@ -104,16 +102,15 @@ void TrtInfer(const std::string& model_dir, const std::string& image_file,
}
auto im = cv::imread(image_file);
- auto im_bak = im.clone();
cv::Mat bg = cv::imread(background_file);
fastdeploy::vision::MattingResult res;
if (!model.Predict(&im, &res)) {
std::cerr << "Failed to predict." << std::endl;
return;
}
- auto vis_im = fastdeploy::vision::VisMatting(im_bak, res);
+ auto vis_im = fastdeploy::vision::VisMatting(im, res);
auto vis_im_with_bg =
- fastdeploy::vision::Visualize::SwapBackgroundMatting(im_bak, bg, res);
+ fastdeploy::vision::SwapBackground(im, bg, res);
cv::imwrite("visualized_result.jpg", vis_im_with_bg);
cv::imwrite("visualized_result_fg.jpg", vis_im);
std::cout << "Visualized result save in ./visualized_result_replaced_bg.jpg "
diff --git a/examples/vision/matting/ppmatting/python/infer.py b/examples/vision/matting/ppmatting/python/infer.py
index 32a81eca7..89913cd11 100644
--- a/examples/vision/matting/ppmatting/python/infer.py
+++ b/examples/vision/matting/ppmatting/python/infer.py
@@ -60,7 +60,7 @@ result = model.predict(im)
print(result)
# 可视化结果
vis_im = fd.vision.vis_matting(im, result)
-vis_im_with_bg = fd.vision.swap_background_matting(im, bg, result)
+vis_im_with_bg = fd.vision.swap_background(im, bg, result)
cv2.imwrite("visualized_result_fg.jpg", vis_im)
cv2.imwrite("visualized_result_replaced_bg.jpg", vis_im_with_bg)
print(
diff --git a/examples/vision/matting/rvm/python/infer.py b/examples/vision/matting/rvm/python/infer.py
index fcde64fb2..0e9eb6b21 100755
--- a/examples/vision/matting/rvm/python/infer.py
+++ b/examples/vision/matting/rvm/python/infer.py
@@ -86,7 +86,7 @@ if args.video is not None:
break
result = model.predict(frame)
vis_im = fd.vision.vis_matting(frame, result)
- vis_im_with_bg = fd.vision.swap_background_matting(frame, bg, result)
+ vis_im_with_bg = fd.vision.swap_background(frame, bg, result)
alpha.write(vis_im)
composition.write(vis_im_with_bg)
cv2.waitKey(30)
@@ -104,7 +104,7 @@ if args.image is not None:
print(result)
# 可视化结果
vis_im = fd.vision.vis_matting(im, result)
- vis_im_with_bg = fd.vision.swap_background_matting(im, bg, result)
+ vis_im_with_bg = fd.vision.swap_background(im, bg, result)
cv2.imwrite("visualized_result_fg.jpg", vis_im)
cv2.imwrite("visualized_result_replaced_bg.jpg", vis_im_with_bg)
print(
From 0cdaef890f27ce6555955461c6cd8f50ffe0347e Mon Sep 17 00:00:00 2001
From: Jason
Date: Wed, 14 Dec 2022 18:54:50 +0800
Subject: [PATCH 54/77] Update use_sdk_on_windows.md
---
docs/cn/faq/use_sdk_on_windows.md | 2 ++
1 file changed, 2 insertions(+)
diff --git a/docs/cn/faq/use_sdk_on_windows.md b/docs/cn/faq/use_sdk_on_windows.md
index 7209d50bb..0683e8d04 100644
--- a/docs/cn/faq/use_sdk_on_windows.md
+++ b/docs/cn/faq/use_sdk_on_windows.md
@@ -1,3 +1,5 @@
+[English](../../en/faq/use_sdk_on_windows.md) | 中文
+
# 在 Windows 使用 FastDeploy C++ SDK
## 目录
From 41d94a355baa91052d25b205c11a52f2cf5f4c6a Mon Sep 17 00:00:00 2001
From: Jason
Date: Wed, 14 Dec 2022 18:55:15 +0800
Subject: [PATCH 55/77] Update use_sdk_on_windows.md
---
docs/en/faq/use_sdk_on_windows.md | 2 ++
1 file changed, 2 insertions(+)
diff --git a/docs/en/faq/use_sdk_on_windows.md b/docs/en/faq/use_sdk_on_windows.md
index 367f6e1df..7826d2e42 100644
--- a/docs/en/faq/use_sdk_on_windows.md
+++ b/docs/en/faq/use_sdk_on_windows.md
@@ -1,3 +1,5 @@
+English | [中文](../../en/faq/use_sdk_on_windows.md)
+
# Using the FastDeploy C++ SDK on Windows Platform
## Contents
From f852d515e06f865ba6319e5716f64bd96ce07348 Mon Sep 17 00:00:00 2001
From: Jason
Date: Wed, 14 Dec 2022 18:55:37 +0800
Subject: [PATCH 56/77] Update use_sdk_on_windows.md
---
docs/en/faq/use_sdk_on_windows.md | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/docs/en/faq/use_sdk_on_windows.md b/docs/en/faq/use_sdk_on_windows.md
index 7826d2e42..315e5ef6a 100644
--- a/docs/en/faq/use_sdk_on_windows.md
+++ b/docs/en/faq/use_sdk_on_windows.md
@@ -1,4 +1,4 @@
-English | [中文](../../en/faq/use_sdk_on_windows.md)
+English | [中文](../../cn/faq/use_sdk_on_windows.md)
# Using the FastDeploy C++ SDK on Windows Platform
From fb56700fa625dc0eb92bdf47d962605444e3497a Mon Sep 17 00:00:00 2001
From: Jason
Date: Wed, 14 Dec 2022 18:57:56 +0800
Subject: [PATCH 57/77] Update use_sdk_on_linux.md
---
docs/en/faq/use_sdk_on_linux.md | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/docs/en/faq/use_sdk_on_linux.md b/docs/en/faq/use_sdk_on_linux.md
index 4dcffb3a4..2c1cf551d 100644
--- a/docs/en/faq/use_sdk_on_linux.md
+++ b/docs/en/faq/use_sdk_on_linux.md
@@ -1,3 +1,5 @@
+English | [中文](../../cn/faq/use_sdk_on_linux.md)
+
# C++ Deployment on Linux
1. After compilation, and execute the binary file, throw error `error while loading shared libraries`
@@ -13,4 +15,4 @@ FastDeploy provides a shell scripts to help export the libraries path to `LD_LIB
source /Downloads/fastdeploy-linux-x64-1.0.0/fastdeploy_init.sh
```
-And now you can execute the binary file again.
\ No newline at end of file
+And now you can execute the binary file again.
From 136cd47e02aa041e8ce4cbdd938a905f1a1f3bfa Mon Sep 17 00:00:00 2001
From: Jason
Date: Wed, 14 Dec 2022 18:58:33 +0800
Subject: [PATCH 58/77] Update use_sdk_on_linux.md
---
docs/cn/faq/use_sdk_on_linux.md | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/docs/cn/faq/use_sdk_on_linux.md b/docs/cn/faq/use_sdk_on_linux.md
index aba472ecc..0ceb5ca0c 100644
--- a/docs/cn/faq/use_sdk_on_linux.md
+++ b/docs/cn/faq/use_sdk_on_linux.md
@@ -1,3 +1,6 @@
+[English](../../en/faq/use_sdk_on_linux.md) | 中文
+
+
# Linux上C++部署
1. 编译完成运行,提示找不到.so文件
@@ -10,4 +13,4 @@
source /Downloads/fastdeploy-linux-x64-1.0.0/fastdeploy_init.sh
```
-再重新执行即可。 注意此命令执行后仅在当前的命令环境中生效(切换一个新的终端窗口,或关闭窗口重新打开后会无效),如若需要在系统中持续生效,可将这些环境变量加入到`~/.bashrc`文件中。
\ No newline at end of file
+再重新执行即可。 注意此命令执行后仅在当前的命令环境中生效(切换一个新的终端窗口,或关闭窗口重新打开后会无效),如若需要在系统中持续生效,可将这些环境变量加入到`~/.bashrc`文件中。
From a5d865625f49ebb98e3d5d6fd04fbb6c2ad13b46 Mon Sep 17 00:00:00 2001
From: Jason
Date: Wed, 14 Dec 2022 18:59:42 +0800
Subject: [PATCH 59/77] Update use_sdk_on_linux.md
---
docs/en/faq/use_sdk_on_linux.md | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/docs/en/faq/use_sdk_on_linux.md b/docs/en/faq/use_sdk_on_linux.md
index 2c1cf551d..653389f43 100644
--- a/docs/en/faq/use_sdk_on_linux.md
+++ b/docs/en/faq/use_sdk_on_linux.md
@@ -9,7 +9,7 @@ When we execute the binary file, it requires the dependent libraries can be foun
./infer_ppyoloe_demo: error while loading shared libraries: libonnxruntime.so.1.12.0: cannot open shared object file: No such file or directory
```
-FastDeploy provides a shell scripts to help export the libraries path to `LD_LIBRARY_PATH`, execute the follwing command
+FastDeploy provides a shell scripts to help export the libraries path to `LD_LIBRARY_PATH`, execute the following command
```
source /Downloads/fastdeploy-linux-x64-1.0.0/fastdeploy_init.sh
From ce4867d14e7abf8516262ef6066661da6f552d74 Mon Sep 17 00:00:00 2001
From: CoolCola <49013063+CoolKbh@users.noreply.github.com>
Date: Wed, 14 Dec 2022 19:14:43 +0800
Subject: [PATCH 60/77] [Model] Support YOLOv7-face Model (#651)
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
* 测试
* delete test
* add yolov7-face
* fit vision.h
* add yolov7-face test
* fit: yolov7-face infer.cc
* fit
* fit Yolov7-face Cmakelist
* fit yolov7Face.cc
* add yolov7-face pybind
* add yolov7-face python infer
* feat yolov7-face pybind
* feat yolov7-face format error
* feat yolov7face_pybind error
* feat add yolov7face-pybind to facedet-pybind
* same as before
* same sa before
* feat __init__.py
* add yolov7face.py
* feat yolov7face.h ignore ","
* feat .py
* fit yolov7face.py
* add yolov7face test teadme file
* add test file
* fit postprocess
* delete remain annotation
* fit preview
* fit yolov7facepreprocessor
* fomat code
* fomat code
* fomat code
* fit format error and confthreshold and nmsthres
* fit confthreshold and nmsthres
* fit test-yolov7-face
* fit test_yolov7face
* fit review
* fit ci error
Co-authored-by: kongbohua
Co-authored-by: CoolCola <49013063+kongbohua@users.noreply.github.com>
---
.../facedet/yolov7face/cpp/CMakeLists.txt | 14 ++
.../vision/facedet/yolov7face/cpp/README.md | 90 ++++++++++
.../vision/facedet/yolov7face/cpp/infer.cc | 105 +++++++++++
.../facedet/yolov7face/python/README.md | 87 +++++++++
.../vision/facedet/yolov7face/python/infer.py | 51 ++++++
fastdeploy/vision.h | 1 +
fastdeploy/vision/facedet/facedet_pybind.cc | 2 +
.../facedet/yolov7-face/postprocessor.cc | 101 +++++++++++
.../facedet/yolov7-face/postprocessor.h | 68 +++++++
.../facedet/yolov7-face/preprocessor.cc | 120 +++++++++++++
.../vision/facedet/yolov7-face/preprocessor.h | 100 +++++++++++
.../vision/facedet/yolov7-face/yolov7face.cc | 88 ++++++++++
.../vision/facedet/yolov7-face/yolov7face.h | 81 +++++++++
.../facedet/yolov7-face/yolov7face_pybind.cc | 87 +++++++++
python/fastdeploy/vision/facedet/__init__.py | 1 +
.../vision/facedet/contrib/yolov7face.py | 166 ++++++++++++++++++
tests/models/test_yolov7face.py | 142 +++++++++++++++
17 files changed, 1304 insertions(+)
create mode 100644 examples/vision/facedet/yolov7face/cpp/CMakeLists.txt
create mode 100644 examples/vision/facedet/yolov7face/cpp/README.md
create mode 100644 examples/vision/facedet/yolov7face/cpp/infer.cc
create mode 100644 examples/vision/facedet/yolov7face/python/README.md
create mode 100644 examples/vision/facedet/yolov7face/python/infer.py
create mode 100644 fastdeploy/vision/facedet/yolov7-face/postprocessor.cc
create mode 100644 fastdeploy/vision/facedet/yolov7-face/postprocessor.h
create mode 100644 fastdeploy/vision/facedet/yolov7-face/preprocessor.cc
create mode 100644 fastdeploy/vision/facedet/yolov7-face/preprocessor.h
create mode 100644 fastdeploy/vision/facedet/yolov7-face/yolov7face.cc
create mode 100644 fastdeploy/vision/facedet/yolov7-face/yolov7face.h
create mode 100644 fastdeploy/vision/facedet/yolov7-face/yolov7face_pybind.cc
create mode 100644 python/fastdeploy/vision/facedet/contrib/yolov7face.py
create mode 100644 tests/models/test_yolov7face.py
diff --git a/examples/vision/facedet/yolov7face/cpp/CMakeLists.txt b/examples/vision/facedet/yolov7face/cpp/CMakeLists.txt
new file mode 100644
index 000000000..4ec242a44
--- /dev/null
+++ b/examples/vision/facedet/yolov7face/cpp/CMakeLists.txt
@@ -0,0 +1,14 @@
+PROJECT(infer_demo C CXX)
+CMAKE_MINIMUM_REQUIRED (VERSION 3.10)
+
+# Specifies the path to the fastdeploy library after you have downloaded it
+option(FASTDEPLOY_INSTALL_DIR "Path of downloaded fastdeploy sdk.")
+
+include(../../../../../FastDeploy.cmake)
+
+# Add the FastDeploy dependency header
+include_directories(${FASTDEPLOY_INCS})
+
+add_executable(infer_demo ${PROJECT_SOURCE_DIR}/infer.cc)
+# Add the FastDeploy library dependency
+target_link_libraries(infer_demo ${FASTDEPLOY_LIBS})
diff --git a/examples/vision/facedet/yolov7face/cpp/README.md b/examples/vision/facedet/yolov7face/cpp/README.md
new file mode 100644
index 000000000..3b68ff41c
--- /dev/null
+++ b/examples/vision/facedet/yolov7face/cpp/README.md
@@ -0,0 +1,90 @@
+# YOLOv7Face C++部署示例
+
+本目录下提供`infer.cc`快速完成YOLOv7Face在CPU/GPU,以及GPU上通过TensorRT加速部署的示例。
+
+在部署前,需确认以下两个步骤
+
+- 1. 软硬件环境满足要求,参考[FastDeploy环境要求](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md)
+- 2. 根据开发环境,下载预编译部署库和samples代码,参考[FastDeploy预编译库](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md)
+
+以Linux上CPU推理为例,在本目录执行如下命令即可完成编译测试
+
+```bash
+mkdir build
+cd build
+# 下载FastDeploy预编译库,用户可在上文提到的`FastDeploy预编译库`中自行选择合适的版本使用
+wget https://bj.bcebos.com/fastdeploy/release/cpp/fastdeploy-linux-x64-x.x.x.tgz # x.x.x > 1.0.2
+tar xvf fastdeploy-linux-x64-x.x.x.tgz # x.x.x > 1.0.2
+cmake .. -DFASTDEPLOY_INSTALL_DIR=${PWD}/fastdeploy-linux-x64-x.x.x # x.x.x > 1.0.2
+make -j
+
+#下载官方转换好的YOLOv7Face模型文件和测试图片
+wget https://raw.githubusercontent.com/DefTruth/lite.ai.toolkit/main/examples/lite/resources/test_lite_face_detector_3.jpg
+wget https://bj.bcebos.com/paddlehub/fastdeploy/yolov7-lite-e.onnx
+wget https://bj.bcebos.com/paddlehub/fastdeploy/yolov7-tiny-face.onnx
+
+#使用yolov7-tiny-face.onnx模型
+# CPU推理
+./infer_demo yolov7-tiny-face.onnx test_lite_face_detector_3.jpg 0
+# GPU推理
+./infer_demo yolov7-tiny-face.onnx test_lite_face_detector_3.jpg 1
+# GPU上TensorRT推理
+./infer_demo yolov7-tiny-face.onnx test_lite_face_detector_3.jpg 2
+
+#使用yolov7-lite-e.onnx模型
+# CPU推理
+./infer_demo yolov7-lite-e.onnx test_lite_face_detector_3.jpg 0
+# GPU推理
+./infer_demo yolov7-lite-e.onnx test_lite_face_detector_3.jpg 1
+# GPU上TensorRT推理
+./infer_demo yolov7-lite-e.onnx test_lite_face_detector_3.jpg 2
+```
+
+运行完成可视化结果如下图所示
+
+
+
+以上命令只适用于Linux或MacOS, Windows下SDK的使用方式请参考:
+- [如何在Windows中使用FastDeploy C++ SDK](../../../../../docs/cn/faq/use_sdk_on_windows.md)
+
+## YOLOv7Face C++接口
+
+### YOLOv7Face类
+
+```c++
+fastdeploy::vision::facedet::YOLOv7Face(
+ const string& model_file,
+ const string& params_file = "",
+ const RuntimeOption& runtime_option = RuntimeOption(),
+ const ModelFormat& model_format = ModelFormat::ONNX)
+```
+
+YOLOv7Face模型加载和初始化,其中model_file为导出的ONNX模型格式。
+
+**参数**
+
+> * **model_file**(str): 模型文件路径
+> * **params_file**(str): 参数文件路径,当模型格式为ONNX时,此参数传入空字符串即可
+> * **runtime_option**(RuntimeOption): 后端推理配置,默认为None,即采用默认配置
+> * **model_format**(ModelFormat): 模型格式,默认为ONNX格式
+
+#### Predict函数
+
+> ```c++
+> YOLOv7Face::Predict(cv::Mat* im, FaceDetectionResult* result,
+> float conf_threshold = 0.3,
+> float nms_iou_threshold = 0.5)
+> ```
+>
+> 模型预测接口,输入图像直接输出检测结果。
+>
+> **参数**
+>
+> > * **im**: 输入图像,注意需为HWC,BGR格式
+> > * **result**: 检测结果,包括检测框,各个框的置信度, FaceDetectionResult说明参考[视觉模型预测结果](../../../../../docs/api/vision_results/)
+> > * **conf_threshold**: 检测框置信度过滤阈值
+> > * **nms_iou_threshold**: NMS处理过程中iou阈值
+
+- [模型介绍](../../)
+- [Python部署](../python)
+- [视觉模型预测结果](../../../../../docs/api/vision_results/)
diff --git a/examples/vision/facedet/yolov7face/cpp/infer.cc b/examples/vision/facedet/yolov7face/cpp/infer.cc
new file mode 100644
index 000000000..973b65be3
--- /dev/null
+++ b/examples/vision/facedet/yolov7face/cpp/infer.cc
@@ -0,0 +1,105 @@
+// 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 CpuInfer(const std::string& model_file, const std::string& image_file) {
+ auto model = fastdeploy::vision::facedet::YOLOv7Face(model_file);
+ if (!model.Initialized()) {
+ std::cerr << "Failed to initialize." << std::endl;
+ return;
+ }
+
+ auto im = cv::imread(image_file);
+
+ fastdeploy::vision::FaceDetectionResult 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::VisFaceDetection(im, res);
+ cv::imwrite("vis_result.jpg", vis_im);
+ std::cout << "Visualized result saved in ./vis_result.jpg" << std::endl;
+}
+
+void GpuInfer(const std::string& model_file, const std::string& image_file) {
+ auto option = fastdeploy::RuntimeOption();
+ option.UseGpu();
+ auto model = fastdeploy::vision::facedet::YOLOv7Face(model_file, "", option);
+ if (!model.Initialized()) {
+ std::cerr << "Failed to initialize." << std::endl;
+ return;
+ }
+
+ auto im = cv::imread(image_file);
+
+ fastdeploy::vision::FaceDetectionResult 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::VisFaceDetection(im, res);
+ cv::imwrite("vis_result.jpg", vis_im);
+ std::cout << "Visualized result saved in ./vis_result.jpg" << std::endl;
+}
+
+void TrtInfer(const std::string& model_file, const std::string& image_file) {
+ auto option = fastdeploy::RuntimeOption();
+ option.UseGpu();
+ option.UseTrtBackend();
+ option.SetTrtInputShape("images", {1, 3, 640, 640});
+ auto model = fastdeploy::vision::facedet::YOLOv7Face(model_file, "", option);
+ if (!model.Initialized()) {
+ std::cerr << "Failed to initialize." << std::endl;
+ return;
+ }
+
+ auto im = cv::imread(image_file);
+
+ fastdeploy::vision::FaceDetectionResult 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::VisFaceDetection(im, res);
+ 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 < 4) {
+ std::cout << "Usage: infer_demo path/to/model path/to/image run_option, "
+ "e.g ./infer_model yolov5s-face.onnx ./test.jpeg 0"
+ << 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;
+ return -1;
+ }
+
+ if (std::atoi(argv[3]) == 0) {
+ CpuInfer(argv[1], argv[2]);
+ } else if (std::atoi(argv[3]) == 1) {
+ GpuInfer(argv[1], argv[2]);
+ } else if (std::atoi(argv[3]) == 2) {
+ TrtInfer(argv[1], argv[2]);
+ }
+ return 0;
+}
diff --git a/examples/vision/facedet/yolov7face/python/README.md b/examples/vision/facedet/yolov7face/python/README.md
new file mode 100644
index 000000000..0c4dd0f57
--- /dev/null
+++ b/examples/vision/facedet/yolov7face/python/README.md
@@ -0,0 +1,87 @@
+# YOLOv7Face Python部署示例
+
+在部署前,需确认以下两个步骤
+
+- 1. 软硬件环境满足要求,参考[FastDeploy环境要求](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md)
+- 2. FastDeploy Python whl包安装,参考[FastDeploy Python安装](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md)
+
+本目录下提供`infer.py`快速完成YOLOv7Face在CPU/GPU,以及GPU上通过TensorRT加速部署的示例。执行如下脚本即可完成
+
+```bash
+#下载部署示例代码
+git clone https://github.com/PaddlePaddle/FastDeploy.git
+cd examples/vision/facedet/yolov7face/python/
+
+#下载YOLOv7Face模型文件和测试图片
+wget https://raw.githubusercontent.com/DefTruth/lite.ai.toolkit/main/examples/lite/resources/test_lite_face_detector_3.jpg
+wget https://bj.bcebos.com/paddlehub/fastdeploy/yolov7-lite-e.onnx
+
+#使用yolov7-tiny-face.onnx模型
+# CPU推理
+python infer.py --model yolov7-tiny-face.onnx --image test_lite_face_detector_3.jpg --device cpu
+# GPU推理
+python infer.py --model yolov7-tiny-face.onnx --image test_lite_face_detector_3.jpg --device gpu
+# GPU上使用TensorRT推理
+python infer.py --model yolov7-tiny-face.onnx --image test_lite_face_detector_3.jpg --device gpu --use_trt True
+
+#使用yolov7-lite-e.onnx模型
+# CPU推理
+python infer.py --model yolov7-lite-e.onnx --image test_lite_face_detector_3.jpg --device cpu
+# GPU推理
+python infer.py --model yolov7-lite-e.onnx --image test_lite_face_detector_3.jpg --device gpu
+# GPU上使用TensorRT推理
+python infer.py --model yolov7-lite-e.onnx --image test_lite_face_detector_3.jpg --device gpu --use_trt True
+```
+
+运行完成可视化结果如下图所示
+
+
+
+## YOLOv7Face Python接口
+
+```python
+fastdeploy.vision.facedet.YOLOv7Face(model_file, params_file=None, runtime_option=None, model_format=ModelFormat.ONNX)
+```
+
+YOLOv7Face模型加载和初始化,其中model_file为导出的ONNX模型格式
+
+**参数**
+
+> * **model_file**(str): 模型文件路径
+> * **params_file**(str): 参数文件路径,当模型格式为ONNX格式时,此参数无需设定
+> * **runtime_option**(RuntimeOption): 后端推理配置,默认为None,即采用默认配置
+> * **model_format**(ModelFormat): 模型格式,默认为ONNX
+
+### predict函数
+
+> ```python
+> YOLOv7Face.predict(image_data, conf_threshold=0.3, nms_iou_threshold=0.5)
+> ```
+>
+> 模型预测结口,输入图像直接输出检测结果。
+>
+> **参数**
+>
+> > * **image_data**(np.ndarray): 输入数据,注意需为HWC,BGR格式
+> > * **conf_threshold**(float): 检测框置信度过滤阈值
+> > * **nms_iou_threshold**(float): NMS处理过程中iou阈值
+
+> **返回**
+>
+> > 返回`fastdeploy.vision.FaceDetectionResult`结构体,结构体说明参考文档[视觉模型预测结果](../../../../../docs/api/vision_results/)
+
+### 类成员属性
+#### 预处理参数
+用户可按照自己的实际需求,修改下列预处理参数,从而影响最终的推理和部署效果
+
+> > * **size**(list[int]): 通过此参数修改预处理过程中resize的大小,包含两个整型元素,表示[width, height], 默认值为[640, 640]
+> > * **padding_value**(list[float]): 通过此参数可以修改图片在resize时候做填充(padding)的值, 包含三个浮点型元素, 分别表示三个通道的值, 默认值为[114, 114, 114]
+> > * **is_no_pad**(bool): 通过此参数让图片是否通过填充的方式进行resize, `is_no_pad=True` 表示不使用填充的方式,默认值为`is_no_pad=False`
+> > * **is_mini_pad**(bool): 通过此参数可以将resize之后图像的宽高这是为最接近`size`成员变量的值, 并且满足填充的像素大小是可以被`stride`成员变量整除的。默认值为`is_mini_pad=False`
+> > * **stride**(int): 配合`is_mini_pad`成员变量使用, 默认值为`stride=32`
+
+## 其它文档
+
+- [YOLOv7Face 模型介绍](..)
+- [YOLOv7Face C++部署](../cpp)
+- [模型预测结果说明](../../../../../docs/api/vision_results/)
diff --git a/examples/vision/facedet/yolov7face/python/infer.py b/examples/vision/facedet/yolov7face/python/infer.py
new file mode 100644
index 000000000..d06b507ee
--- /dev/null
+++ b/examples/vision/facedet/yolov7face/python/infer.py
@@ -0,0 +1,51 @@
+import fastdeploy as fd
+import cv2
+
+
+def parse_arguments():
+ import argparse
+ import ast
+ parser = argparse.ArgumentParser()
+ parser.add_argument(
+ "--model", required=True, help="Path of yolov7face onnx model.")
+ parser.add_argument(
+ "--image", required=True, help="Path of test image file.")
+ parser.add_argument(
+ "--device",
+ type=str,
+ default='cpu',
+ help="Type of inference device, support 'cpu' or 'gpu'.")
+ parser.add_argument(
+ "--use_trt",
+ type=ast.literal_eval,
+ default=False,
+ help="Wether to use tensorrt.")
+ return parser.parse_args()
+
+
+def build_option(args):
+ option = fd.RuntimeOption()
+
+ if args.device.lower() == "gpu":
+ option.use_gpu()
+
+ if args.use_trt:
+ option.use_trt_backend()
+ option.set_trt_input_shape("images", [1, 3, 640, 640])
+ return option
+
+
+args = parse_arguments()
+
+# Configure runtime and load the model
+runtime_option = build_option(args)
+model = fd.vision.facedet.YOLOv7Face(args.model, runtime_option=runtime_option)
+
+# Predict image detection results
+im = cv2.imread(args.image)
+result = model.predict(im)
+print(result)
+# Visualization of prediction Results
+vis_im = fd.vision.vis_face_detection(im, result)
+cv2.imwrite("visualized_result.jpg", vis_im)
+print("Visualized result save in ./visualized_result.jpg")
diff --git a/fastdeploy/vision.h b/fastdeploy/vision.h
index 5ccaeb2dd..732f9e7a5 100644
--- a/fastdeploy/vision.h
+++ b/fastdeploy/vision.h
@@ -37,6 +37,7 @@
#include "fastdeploy/vision/facedet/contrib/scrfd.h"
#include "fastdeploy/vision/facedet/contrib/ultraface.h"
#include "fastdeploy/vision/facedet/contrib/yolov5face.h"
+#include "fastdeploy/vision/facedet/yolov7-face/yolov7face.h"
#include "fastdeploy/vision/faceid/contrib/adaface.h"
#include "fastdeploy/vision/faceid/contrib/arcface.h"
#include "fastdeploy/vision/faceid/contrib/cosface.h"
diff --git a/fastdeploy/vision/facedet/facedet_pybind.cc b/fastdeploy/vision/facedet/facedet_pybind.cc
index 3d9a812af..e5a62542d 100644
--- a/fastdeploy/vision/facedet/facedet_pybind.cc
+++ b/fastdeploy/vision/facedet/facedet_pybind.cc
@@ -19,6 +19,7 @@ namespace fastdeploy {
void BindRetinaFace(pybind11::module& m);
void BindUltraFace(pybind11::module& m);
void BindYOLOv5Face(pybind11::module& m);
+void BindYOLOv7Face(pybind11::module& m);
void BindSCRFD(pybind11::module& m);
void BindFaceDet(pybind11::module& m) {
@@ -26,6 +27,7 @@ void BindFaceDet(pybind11::module& m) {
BindRetinaFace(facedet_module);
BindUltraFace(facedet_module);
BindYOLOv5Face(facedet_module);
+ BindYOLOv7Face(facedet_module);
BindSCRFD(facedet_module);
}
} // namespace fastdeploy
diff --git a/fastdeploy/vision/facedet/yolov7-face/postprocessor.cc b/fastdeploy/vision/facedet/yolov7-face/postprocessor.cc
new file mode 100644
index 000000000..e2c92a6d1
--- /dev/null
+++ b/fastdeploy/vision/facedet/yolov7-face/postprocessor.cc
@@ -0,0 +1,101 @@
+// 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/facedet/yolov7-face/postprocessor.h"
+#include "fastdeploy/vision/utils/utils.h"
+
+namespace fastdeploy {
+
+namespace vision {
+
+namespace facedet {
+
+Yolov7FacePostprocessor::Yolov7FacePostprocessor() {
+ conf_threshold_ = 0.5;
+ nms_threshold_ = 0.45;
+ max_wh_ = 7680.0;
+}
+
+bool Yolov7FacePostprocessor::Run(const std::vector& infer_result,
+ std::vector* results,
+ const std::vector>>& ims_info) {
+ int batch = infer_result[0].shape[0];
+
+ results->resize(batch);
+
+ for (size_t bs = 0; bs < batch; ++bs) {
+ (*results)[bs].Clear();
+ (*results)[bs].Reserve(infer_result[0].shape[1]);
+ if (infer_result[0].dtype != FDDataType::FP32) {
+ FDERROR << "Only support post process with float32 data." << std::endl;
+ return false;
+ }
+ const float* data = reinterpret_cast(infer_result[0].Data()) + bs * infer_result[0].shape[1] * infer_result[0].shape[2];
+ for (size_t i = 0; i < infer_result[0].shape[1]; ++i) {
+ int s = i * infer_result[0].shape[2];
+ float confidence = data[s + 4];
+ const float* reg_cls_ptr = data + s;
+ const float* class_score = data + s + 5;
+ confidence *= (*class_score);
+ // filter boxes by conf_threshold
+ if (confidence <= conf_threshold_) {
+ continue;
+ }
+ float x = reg_cls_ptr[0];
+ float y = reg_cls_ptr[1];
+ float w = reg_cls_ptr[2];
+ float h = reg_cls_ptr[3];
+
+ // convert from [x, y, w, h] to [x1, y1, x2, y2]
+ (*results)[bs].boxes.emplace_back(std::array{
+ (x - w / 2.f), (y - h / 2.f), (x + w / 2.f), (y + h / 2.f)});
+ (*results)[bs].scores.push_back(confidence);
+ }
+
+ if ((*results)[bs].boxes.size() == 0) {
+ return true;
+ }
+
+ utils::NMS(&((*results)[bs]), nms_threshold_);
+
+ // scale the boxes to the origin image shape
+ auto iter_out = ims_info[bs].find("output_shape");
+ auto iter_ipt = ims_info[bs].find("input_shape");
+ FDASSERT(iter_out != ims_info[bs].end() && iter_ipt != ims_info[bs].end(),
+ "Cannot find input_shape or output_shape from im_info.");
+ float out_h = iter_out->second[0];
+ float out_w = iter_out->second[1];
+ float ipt_h = iter_ipt->second[0];
+ float ipt_w = iter_ipt->second[1];
+ float scale = std::min(out_h / ipt_h, out_w / ipt_w);
+ for (size_t i = 0; i < (*results)[bs].boxes.size(); ++i) {
+ float pad_h = (out_h - ipt_h * scale) / 2;
+ float pad_w = (out_w - ipt_w * scale) / 2;
+ // clip box
+ (*results)[bs].boxes[i][0] = std::max(((*results)[bs].boxes[i][0] - pad_w) / scale, 0.0f);
+ (*results)[bs].boxes[i][1] = std::max(((*results)[bs].boxes[i][1] - pad_h) / scale, 0.0f);
+ (*results)[bs].boxes[i][2] = std::max(((*results)[bs].boxes[i][2] - pad_w) / scale, 0.0f);
+ (*results)[bs].boxes[i][3] = std::max(((*results)[bs].boxes[i][3] - pad_h) / scale, 0.0f);
+ (*results)[bs].boxes[i][0] = std::min((*results)[bs].boxes[i][0], ipt_w - 1.0f);
+ (*results)[bs].boxes[i][1] = std::min((*results)[bs].boxes[i][1], ipt_h - 1.0f);
+ (*results)[bs].boxes[i][2] = std::min((*results)[bs].boxes[i][2], ipt_w - 1.0f);
+ (*results)[bs].boxes[i][3] = std::min((*results)[bs].boxes[i][3], ipt_h - 1.0f);
+ }
+ }
+ return true;
+}
+
+} // namespace detection
+} // namespace vision
+} // namespace fastdeploy
diff --git a/fastdeploy/vision/facedet/yolov7-face/postprocessor.h b/fastdeploy/vision/facedet/yolov7-face/postprocessor.h
new file mode 100644
index 000000000..4a1b0d852
--- /dev/null
+++ b/fastdeploy/vision/facedet/yolov7-face/postprocessor.h
@@ -0,0 +1,68 @@
+// 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.
+
+#pragma once
+#include "fastdeploy/vision/common/processors/transform.h"
+#include "fastdeploy/vision/common/result.h"
+
+namespace fastdeploy {
+
+namespace vision {
+
+namespace facedet {
+
+class FASTDEPLOY_DECL Yolov7FacePostprocessor{
+ public:
+ /*! @brief Postprocessor object for YOLOv7Face serials model.
+ */
+ Yolov7FacePostprocessor();
+
+ /** \brief Process the result of runtime and fill to FaceDetectionResult structure
+ *
+ * \param[in] infer_result The inference result from runtime
+ * \param[in] results The output result of detection
+ * \param[in] ims_info The shape info list, record input_shape and output_shape
+ * \return true if the postprocess successed, otherwise false
+ */
+ bool Run(const std::vector& infer_result,
+ std::vector* results,
+ const std::vector>>& ims_info);
+
+ /// Set conf_threshold, default 0.5
+ void SetConfThreshold(const float& conf_threshold) {
+ conf_threshold_ = conf_threshold;
+ }
+
+ /// Get conf_threshold, default 0.5
+ float GetConfThreshold() const { return conf_threshold_; }
+
+ /// Set nms_threshold, default 0.45
+ void SetNMSThreshold(const float& nms_threshold) {
+ nms_threshold_ = nms_threshold;
+ }
+
+ /// Get nms_threshold, default 0.45
+ float GetNMSThreshold() const { return nms_threshold_; }
+
+ protected:
+ float conf_threshold_;
+ float nms_threshold_;
+ bool multi_label_;
+ float max_wh_;
+};
+
+} // namespace facedet
+} // namespace vision
+} // namespace fastdeploy
diff --git a/fastdeploy/vision/facedet/yolov7-face/preprocessor.cc b/fastdeploy/vision/facedet/yolov7-face/preprocessor.cc
new file mode 100644
index 000000000..83301d76d
--- /dev/null
+++ b/fastdeploy/vision/facedet/yolov7-face/preprocessor.cc
@@ -0,0 +1,120 @@
+// 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/facedet/yolov7-face/preprocessor.h"
+#include "fastdeploy/function/concat.h"
+#include "fastdeploy/vision/common/processors/mat.h"
+
+namespace fastdeploy {
+
+namespace vision {
+
+namespace facedet {
+
+Yolov7FacePreprocessor::Yolov7FacePreprocessor() {
+ size_ = {640, 640};
+ padding_color_value_ = {114.0, 114.0, 114.0};
+ is_mini_pad_ = false;
+ is_no_pad_ = false;
+ is_scale_up_ = false;
+ stride_ = 32;
+ max_wh_ = 7680.0;
+}
+
+bool Yolov7FacePreprocessor::Run(std::vector* images, std::vector* outputs,
+ std::vector>>* ims_info) {
+ if (images->size() == 0) {
+ FDERROR << "The size of input images should be greater than 0." << std::endl;
+ return false;
+ }
+ ims_info->resize(images->size());
+ outputs->resize(1);
+ std::vector tensors(images->size());
+ for (size_t i = 0; i < images->size(); i++) {
+ if (!Preprocess(&(*images)[i], &tensors[i], &(*ims_info)[i])) {
+ FDERROR << "Failed to preprocess input image." << std::endl;
+ return false;
+ }
+ }
+
+ if (tensors.size() == 1) {
+ (*outputs)[0] = std::move(tensors[0]);
+ } else {
+ function::Concat(tensors, &((*outputs)[0]), 0);
+ }
+ return true;
+}
+
+bool Yolov7FacePreprocessor::Preprocess(FDMat* mat, FDTensor* output,
+ std::map>* im_info){
+ // Record the shape of image and the shape of preprocessed image
+ (*im_info)["input_shape"] = {static_cast(mat->Height()),
+ static_cast(mat->Width())};
+
+ // yolov7-face's preprocess steps
+ // 1. letterbox
+ // 2. convert_and_permute(swap_rb=true)
+ LetterBox(mat);
+ std::vector alpha = {1.0f / 255.0f, 1.0f / 255.0f, 1.0f / 255.0f};
+ std::vector beta = {0.0f, 0.0f, 0.0f};
+ ConvertAndPermute::Run(mat, alpha, beta, true);
+
+ // Record output shape of preprocessed image
+ (*im_info)["output_shape"] = {static_cast(mat->Height()),
+ static_cast(mat->Width())};
+
+ mat->ShareWithTensor(output);
+ output->ExpandDim(0); // reshape to n, h, w, c
+ return true;
+}
+
+void Yolov7FacePreprocessor::LetterBox(FDMat* mat) {
+ float scale =
+ std::min(size_[1] * 1.0 / mat->Height(), size_[0] * 1.0 / mat->Width());
+ if (!is_scale_up_) {
+ scale = std::min(scale, 1.0f);
+ }
+
+ int resize_h = int(round(mat->Height() * scale));
+ int resize_w = int(round(mat->Width() * scale));
+
+ int pad_w = size_[0] - resize_w;
+ int pad_h = size_[1] - resize_h;
+ if (is_mini_pad_) {
+ pad_h = pad_h % stride_;
+ pad_w = pad_w % stride_;
+ } else if (is_no_pad_) {
+ pad_h = 0;
+ pad_w = 0;
+ resize_h = size_[1];
+ resize_w = size_[0];
+ }
+ Resize::Run(mat, resize_w, resize_h);
+
+ if (pad_h > 0 || pad_w > 0) {
+ float half_h = pad_h * 1.0 / 2;
+ int top = int(round(half_h - 0.1));
+ int bottom = int(round(half_h + 0.1));
+ float half_w = pad_w * 1.0 / 2;
+ int left = int(round(half_w - 0.1));
+ int right = int(round(half_w + 0.1));
+ Pad::Run(mat, top, bottom, left, right, padding_color_value_);
+ }
+}
+
+} // namespace facedet
+
+} // namespace vision
+
+} // namespacefastdeploy
\ No newline at end of file
diff --git a/fastdeploy/vision/facedet/yolov7-face/preprocessor.h b/fastdeploy/vision/facedet/yolov7-face/preprocessor.h
new file mode 100644
index 000000000..4bd8644b7
--- /dev/null
+++ b/fastdeploy/vision/facedet/yolov7-face/preprocessor.h
@@ -0,0 +1,100 @@
+// 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.
+
+#pragma once
+#include "fastdeploy/vision/common/processors/transform.h"
+#include "fastdeploy/vision/common/result.h"
+
+namespace fastdeploy {
+
+namespace vision {
+
+namespace facedet {
+
+class FASTDEPLOY_DECL Yolov7FacePreprocessor{
+ public:
+ /** \brief Create a preprocessor instance for YOLOv7Face serials model
+ */
+ Yolov7FacePreprocessor();
+
+ /** \brief Process the input image and prepare input tensors for runtime
+ *
+ * \param[in] images The input image data list, all the elements are returned by cv::imread()
+ * \param[in] outputs The output tensors which will feed in runtime
+ * \param[in] ims_info The shape info list, record input_shape and output_shape
+ * \ret
+ */
+ bool Run(std::vector* images, std::vector* outputs,
+ std::vector>>* ims_info);
+
+ /// Set target size, tuple of (width, height), default size = {640, 640}
+ void SetSize(const std::vector& size) { size_ = size; }
+
+ /// Get target size, tuple of (width, height), default size = {640, 640}
+ std::vector GetSize() const { return size_; }
+
+ /// Set padding value, size should be the same as channels
+ void SetPaddingColorValue(const std::vector& padding_color_value) {
+ padding_color_value_ = padding_color_value;
+ }
+
+ /// Get padding value, size should be the same as channels
+ std::vector GetPaddingColorValue() const {
+ return padding_color_value_;
+ }
+
+ /// Set is_scale_up, if is_scale_up is false, the input image only
+ /// can be zoom out, the maximum resize scale cannot exceed 1.0, default true
+ void SetScaleUp(bool is_scale_up) {
+ is_scale_up_ = is_scale_up;
+ }
+
+ /// Get is_scale_up, default true
+ bool GetScaleUp() const { return is_scale_up_; }
+
+ protected:
+ bool Preprocess(FDMat * mat, FDTensor* output,
+ std::map>* im_info);
+
+ void LetterBox(FDMat* mat);
+
+ // target size, tuple of (width, height), default size = {640, 640}
+ std::vector size_;
+
+ // padding value, size should be the same as channels
+ std::vector padding_color_value_;
+
+ // only pad to the minimum rectange which height and width is times of stride
+ bool is_mini_pad_;
+
+ // while is_mini_pad = false and is_no_pad = true,
+ // will resize the image to the set size
+ bool is_no_pad_;
+
+ // if is_scale_up is false, the input image only can be zoom out,
+ // the maximum resize scale cannot exceed 1.0
+ bool is_scale_up_;
+
+ // padding stride, for is_mini_pad
+ int stride_;
+
+ // for offseting the boxes by classes when using NMS
+ float max_wh_;
+};
+
+} // namespace facedet
+
+} // namespace vision
+
+} // namespace fastdeploy
diff --git a/fastdeploy/vision/facedet/yolov7-face/yolov7face.cc b/fastdeploy/vision/facedet/yolov7-face/yolov7face.cc
new file mode 100644
index 000000000..7c2906f39
--- /dev/null
+++ b/fastdeploy/vision/facedet/yolov7-face/yolov7face.cc
@@ -0,0 +1,88 @@
+// 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/facedet/yolov7-face/yolov7face.h"
+#include "fastdeploy/utils/perf.h"
+#include "fastdeploy/vision/utils/utils.h"
+
+namespace fastdeploy{
+
+namespace vision{
+
+namespace facedet{
+
+YOLOv7Face::YOLOv7Face(const std::string& model_file,
+ const std::string& params_file,
+ const RuntimeOption& custom_option,
+ const ModelFormat& model_format) {
+ if (model_format == ModelFormat::ONNX) {
+ valid_cpu_backends = {Backend::ORT};
+ valid_gpu_backends = {Backend::ORT, Backend::TRT};
+ } else {
+ valid_cpu_backends = {Backend::PDINFER, Backend::ORT};
+ valid_gpu_backends = {Backend::PDINFER, Backend::ORT, Backend::TRT};
+ }
+ runtime_option = custom_option;
+ runtime_option.model_format = model_format;
+ runtime_option.model_file = model_file;
+ runtime_option.params_file = params_file;
+ initialized = Initialize();
+}
+
+bool YOLOv7Face::Initialize(){
+ if (!InitRuntime()){
+ FDERROR << "Failed to initialize fastdeploy backend." << std::endl;
+ return false;
+ }
+ return true;
+}
+
+bool YOLOv7Face::Predict(const cv::Mat& im, FaceDetectionResult* result){
+ std::vector results;
+ if (!BatchPredict({im}, &results)) {
+ return false;
+ }
+ *result = std::move(results[0]);
+ return true;
+}
+
+bool YOLOv7Face::BatchPredict(const std::vector& images,
+ std::vector* results){
+ std::vector fd_images = WrapMat(images);
+ FDASSERT(images.size() == 1, "Only support batch = 1 now.");
+ std::vector>> ims_info;
+ if (!preprocessor_.Run(&fd_images, &reused_input_tensors_, &ims_info)) {
+ FDERROR << "Failed to preprocess the input image." << std::endl;
+ return false;
+ }
+
+ reused_input_tensors_[0].name = InputInfoOfRuntime(0).name;
+ if (!Infer(reused_input_tensors_, &reused_output_tensors_)) {
+ FDERROR << "Failed to inference by runtime." << std::endl;
+ return false;
+ }
+
+ if (!postprocessor_.Run(reused_output_tensors_, results, ims_info)){
+ FDERROR << "Failed to postprocess the inference results by runtime." << std::endl;
+ return false;
+ }
+
+ return true;
+}
+
+} // namespace facedet
+
+} // namespace vision
+
+} // namespace fastdeploy
\ No newline at end of file
diff --git a/fastdeploy/vision/facedet/yolov7-face/yolov7face.h b/fastdeploy/vision/facedet/yolov7-face/yolov7face.h
new file mode 100644
index 000000000..6410fe590
--- /dev/null
+++ b/fastdeploy/vision/facedet/yolov7-face/yolov7face.h
@@ -0,0 +1,81 @@
+// 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.
+
+#pragma once
+#include "fastdeploy/fastdeploy_model.h"
+#include "fastdeploy/vision/common/processors/transform.h"
+#include "fastdeploy/vision/common/result.h"
+#include "fastdeploy/vision/facedet/yolov7-face/preprocessor.h"
+#include "fastdeploy/vision/facedet/yolov7-face/postprocessor.h"
+
+namespace fastdeploy {
+
+namespace vision {
+
+namespace facedet {
+/*! @brief YOLOv7Face model object used when to load a YOLOv7Face model exported by YOLOv7Face.
+ */
+class FASTDEPLOY_DECL YOLOv7Face: public FastDeployModel{
+ public:
+ /** \brief Set path of model file and the configuration of runtime.
+ *
+ * \param[in] model_file Path of model file, e.g ./yolov7face.onnx
+ * \param[in] params_file Path of parameter file, e.g ppyoloe/model.pdiparams, if the model format is ONNX, this parameter will be ignored
+ * \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 ONNX format
+ */
+ YOLOv7Face(const std::string& model_file, const std::string& params_file = "",
+ const RuntimeOption& custom_option = RuntimeOption(),
+ const ModelFormat& model_format = ModelFormat::ONNX);
+
+ std::string ModelName() {return "yolov7-face";}
+
+ /** \brief Predict the detection result for an input image
+ *
+ * \param[in] img The input image data, comes from cv::imread(), is a 3-D array with layout HWC, BGR format
+ * \param[in] result The output detection result will be writen to this structure
+ * \return true if the prediction successed, otherwise false
+ */
+ virtual bool Predict(const cv::Mat& im, FaceDetectionResult* result);
+
+ /** \brief Predict the detection results for a batch of input images
+ *
+ * \param[in] imgs, The input image list, each element comes from cv::imread()
+ * \param[in] results The output detection result list
+ * \return true if the prediction successed, otherwise false
+ */
+ virtual bool BatchPredict(const std::vector& images,
+ std::vector* results);
+
+ /// Get preprocessor reference of YOLOv7Face
+ virtual Yolov7FacePreprocessor& GetPreprocessor() {
+ return preprocessor_;
+ }
+
+ /// Get postprocessor reference of YOLOv7Face
+ virtual Yolov7FacePostprocessor& GetPostprocessor() {
+ return postprocessor_;
+ }
+
+ protected:
+ bool Initialize();
+ Yolov7FacePreprocessor preprocessor_;
+ Yolov7FacePostprocessor postprocessor_;
+};
+
+} // namespace facedet
+
+} // namespace vision
+
+} // namespace fastdeploy
diff --git a/fastdeploy/vision/facedet/yolov7-face/yolov7face_pybind.cc b/fastdeploy/vision/facedet/yolov7-face/yolov7face_pybind.cc
new file mode 100644
index 000000000..c0c99d425
--- /dev/null
+++ b/fastdeploy/vision/facedet/yolov7-face/yolov7face_pybind.cc
@@ -0,0 +1,87 @@
+// 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/pybind/main.h"
+
+namespace fastdeploy {
+void BindYOLOv7Face(pybind11::module& m) {
+ pybind11::class_(
+ m, "Yolov7FacePreprocessor")
+ .def(pybind11::init<>())
+ .def("run", [](vision::facedet::Yolov7FacePreprocessor& self, std::vector& im_list) {
+ std::vector images;
+ for (size_t i = 0; i < im_list.size(); ++i) {
+ images.push_back(vision::WrapMat(PyArrayToCvMat(im_list[i])));
+ }
+ std::vector outputs;
+ std::vector>> ims_info;
+ if (!self.Run(&images, &outputs, &ims_info)) {
+ throw std::runtime_error("Failed to preprocess the input data in PaddleClasPreprocessor.");
+ }
+ for (size_t i = 0; i < outputs.size(); ++i) {
+ outputs[i].StopSharing();
+ }
+ return make_pair(outputs, ims_info);
+ })
+ .def_property("size", &vision::facedet::Yolov7FacePreprocessor::GetSize, &vision::facedet::Yolov7FacePreprocessor::SetSize)
+ .def_property("padding_color_value", &vision::facedet::Yolov7FacePreprocessor::GetPaddingColorValue, &vision::facedet::Yolov7FacePreprocessor::SetPaddingColorValue)
+ .def_property("is_scale_up", &vision::facedet::Yolov7FacePreprocessor::GetScaleUp, &vision::facedet::Yolov7FacePreprocessor::SetScaleUp);
+
+ pybind11::class_(
+ m, "YOLOv7FacePostprocessor")
+ .def(pybind11::init<>())
+ .def("run", [](vision::facedet::Yolov7FacePostprocessor& self, std::vector& inputs,
+ const std::vector>>& ims_info) {
+ std::vector results;
+ if (!self.Run(inputs, &results, ims_info)) {
+ throw std::runtime_error("Failed to postprocess the runtime result in Yolov7Postprocessor.");
+ }
+ return results;
+ })
+ .def("run", [](vision::facedet::Yolov7FacePostprocessor& self, std::vector& input_array,
+ const std::vector>>& ims_info) {
+ std::vector results;
+ std::vector inputs;
+ PyArrayToTensorList(input_array, &inputs, /*share_buffer=*/true);
+ if (!self.Run(inputs, &results, ims_info)) {
+ throw std::runtime_error("Failed to postprocess the runtime result in YOLOv7Postprocessor.");
+ }
+ return results;
+ })
+ .def_property("conf_threshold", &vision::facedet::Yolov7FacePostprocessor::GetConfThreshold, &vision::facedet::Yolov7FacePostprocessor::SetConfThreshold)
+ .def_property("nms_threshold", &vision::facedet::Yolov7FacePostprocessor::GetNMSThreshold, &vision::facedet::Yolov7FacePostprocessor::SetNMSThreshold);
+
+ pybind11::class_(m, "YOLOv7Face")
+ .def(pybind11::init())
+ .def("predict",
+ [](vision::facedet::YOLOv7Face& self, pybind11::array& data) {
+ auto mat = PyArrayToCvMat(data);
+ vision::FaceDetectionResult res;
+ self.Predict(mat, &res);
+ return res;
+ })
+ .def("batch_predict", [](vision::facedet::YOLOv7Face& self, std::vector& data) {
+ std::vector images;
+ for (size_t i = 0; i < data.size(); ++i) {
+ images.push_back(PyArrayToCvMat(data[i]));
+ }
+ std::vector results;
+ self.BatchPredict(images, &results);
+ return results;
+ })
+ .def_property_readonly("preprocessor", &vision::facedet::YOLOv7Face::GetPreprocessor)
+ .def_property_readonly("postprocessor", &vision::facedet::YOLOv7Face::GetPostprocessor);
+}
+} // namespace fastdeploy
diff --git a/python/fastdeploy/vision/facedet/__init__.py b/python/fastdeploy/vision/facedet/__init__.py
index c9fa01b60..869657a3c 100644
--- a/python/fastdeploy/vision/facedet/__init__.py
+++ b/python/fastdeploy/vision/facedet/__init__.py
@@ -14,6 +14,7 @@
from __future__ import absolute_import
from .contrib.yolov5face import YOLOv5Face
+from .contrib.yolov7face import *
from .contrib.retinaface import RetinaFace
from .contrib.scrfd import SCRFD
from .contrib.ultraface import UltraFace
diff --git a/python/fastdeploy/vision/facedet/contrib/yolov7face.py b/python/fastdeploy/vision/facedet/contrib/yolov7face.py
new file mode 100644
index 000000000..262533b3a
--- /dev/null
+++ b/python/fastdeploy/vision/facedet/contrib/yolov7face.py
@@ -0,0 +1,166 @@
+# 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.
+
+from __future__ import absolute_import
+import logging
+from .... import FastDeployModel, ModelFormat
+from .... import c_lib_wrap as C
+
+
+class Yolov7FacePreprocessor:
+ def __init__(self):
+ """Create a preprocessor for Yolov7Face
+ """
+ self._preprocessor = C.vision.facedet.Yolov7Preprocessor()
+
+ def run(self, input_ims):
+ """Preprocess input images for Yolov7Face
+
+ :param: input_ims: (list of numpy.ndarray)The input image
+ :return: list of FDTensor
+ """
+ return self._preprocessor.run(input_ims)
+
+ @property
+ def size(self):
+ """
+ Argument for image preprocessing step, the preprocess image size, tuple of (width, height), default size = [640, 640]
+ """
+ return self._preprocessor.size
+
+ @property
+ def padding_color_value(self):
+ """
+ padding value for preprocessing, default [114.0, 114.0, 114.0]
+ """
+ # padding value, size should be the same as channels
+ return self._preprocessor.padding_color_value
+
+ @property
+ def is_scale_up(self):
+ """
+ is_scale_up for preprocessing, the input image only can be zoom out, the maximum resize scale cannot exceed 1.0, default true
+ """
+ return self._preprocessor.is_scale_up
+
+ @size.setter
+ def size(self, wh):
+ assert isinstance(wh, (list, tuple)),\
+ "The value to set `size` must be type of tuple or list."
+ assert len(wh) == 2,\
+ "The value to set `size` must contatins 2 elements means [width, height], but now it contains {} elements.".format(
+ len(wh))
+ self._preprocessor.size = wh
+
+ @padding_color_value.setter
+ def padding_color_value(self, value):
+ assert isinstance(
+ value, list
+ ), "The value to set `padding_color_value` must be type of list."
+ self._preprocessor.padding_color_value = value
+
+ @is_scale_up.setter
+ def is_scale_up(self, value):
+ assert isinstance(
+ value,
+ bool), "The value to set `is_scale_up` must be type of bool."
+ self._preprocessor.is_scale_up = value
+
+
+class Yolov7FacePostprocessor:
+ def __init__(self):
+ """Create a postprocessor for Yolov7Face
+ """
+ self._postprocessor = C.vision.facedet.Yolov7FacePostprocessor()
+
+ def run(self, runtime_results, ims_info):
+ """Postprocess the runtime results for Yolov7Face
+
+ :param: runtime_results: (list of FDTensor)The output FDTensor results from runtime
+ :param: ims_info: (list of dict)Record input_shape and output_shape
+ :return: list of DetectionResult(If the runtime_results is predict by batched samples, the length of this list equals to the batch size)
+ """
+ return self._postprocessor.run(runtime_results, ims_info)
+
+ @property
+ def conf_threshold(self):
+ """
+ confidence threshold for postprocessing, default is 0.5
+ """
+ return self._postprocessor.conf_threshold
+
+ @property
+ def nms_threshold(self):
+ """
+ nms threshold for postprocessing, default is 0.45
+ """
+ return self._postprocessor.nms_threshold
+
+ @conf_threshold.setter
+ def conf_threshold(self, conf_threshold):
+ assert isinstance(conf_threshold, float),\
+ "The value to set `conf_threshold` must be type of float."
+ self._postprocessor.conf_threshold = conf_threshold
+
+ @nms_threshold.setter
+ def nms_threshold(self, nms_threshold):
+ assert isinstance(nms_threshold, float),\
+ "The value to set `nms_threshold` must be type of float."
+ self._postprocessor.nms_threshold = nms_threshold
+
+
+class YOLOv7Face(FastDeployModel):
+ def __init__(self,
+ model_file,
+ params_file="",
+ runtime_option=None,
+ model_format=ModelFormat.ONNX):
+ """Load a YOLOv7Face model exported by YOLOv7Face.
+
+ :param model_file: (str)Path of model file, e.g ./yolov7face.onnx
+ :param params_file: (str)Path of parameters file, e.g yolox/model.pdiparams, if the model_fomat is ModelFormat.ONNX, this param will be ignored, can be set as empty string
+ :param runtime_option: (fastdeploy.RuntimeOption)RuntimeOption for inference this model, if it's None, will use the default backend on CPU
+ :param model_format: (fastdeploy.ModelForamt)Model format of the loaded model
+ """
+ super(YOLOv7Face, self).__init__(runtime_option)
+
+ self._model = C.vision.facedet.YOLOv7Face(
+ model_file, params_file, self._runtime_option, model_format)
+
+ assert self.initialized, "YOLOv7Face initialize failed."
+
+ def batch_predict(self, images):
+ """Classify a batch of input image
+
+ :param im: (list of numpy.ndarray) The input image list, each element is a 3-D array with layout HWC, BGR format
+ :return list of DetectionResult
+ """
+
+ return self._model.batch_predict(images)
+
+ @property
+ def preprocessor(self):
+ """Get YOLOv7Preprocessor object of the loaded model
+
+ :return YOLOv7Preprocessor
+ """
+ return self._model.preprocessor
+
+ @property
+ def postprocessor(self):
+ """Get YOLOv7Postprocessor object of the loaded model
+
+ :return YOLOv7Postprocessor
+ """
+ return self._model.postprocessor
diff --git a/tests/models/test_yolov7face.py b/tests/models/test_yolov7face.py
new file mode 100644
index 000000000..8589d708c
--- /dev/null
+++ b/tests/models/test_yolov7face.py
@@ -0,0 +1,142 @@
+# 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.
+
+from fastdeploy import ModelFormat
+import fastdeploy as fd
+import cv2
+import os
+import pickle
+import numpy as np
+import runtime_config as rc
+
+
+def test_detection_yolov7face():
+ model_url = "https://bj.bcebos.com/paddlehub/fastdeploy/yolov7-lite-e.onnx"
+ input_url1 = "https://gitee.com/paddlepaddle/PaddleDetection/raw/release/2.4/demo/000000014439.jpg"
+ input_url2 = "https://gitee.com/paddlepaddle/PaddleDetection/raw/release/2.4/demo/000000570688.jpg"
+ result_url1 = "https://bj.bcebos.com/paddlehub/fastdeploy/yolov7face_result1.pkl"
+ result_url2 = "https://bj.bcebos.com/paddlehub/fastdeploy/yolov7face_result2.pkl"
+ fd.download(model_url, "resources")
+ fd.download(input_url1, "resources")
+ fd.download(input_url2, "resources")
+ fd.download(result_url1, "resources")
+ fd.download(result_url2, "resources")
+
+ model_file = "resources/yolov7-lite-e.onnx"
+ model = fd.vision.facedet.YOLOv7Face(
+ model_file, runtime_option=rc.test_option)
+ model.postprocessor.conf_threshold = 0.3
+
+ with open("resources/yolov7face_result1.pkl", "rb") as f:
+ expect1 = pickle.load(f)
+
+ with open("resources/yolov7face_result2.pkl", "rb") as f:
+ expect2 = pickle.load(f)
+
+ im1 = cv2.imread("./resources/000000014439.jpg")
+ im2 = cv2.imread("./resources/000000570688.jpg")
+
+ for i in range(3):
+ # test single predict
+ result1 = model.predict(im1)
+ result2 = model.predict(im2)
+
+ diff_boxes_1 = np.fabs(
+ np.array(result1.boxes) - np.array(expect1["boxes"]))
+ diff_boxes_2 = np.fabs(
+ np.array(result2.boxes) - np.array(expect2["boxes"]))
+
+ diff_scores_1 = np.fabs(
+ np.array(result1.scores) - np.array(expect1["scores"]))
+ diff_scores_2 = np.fabs(
+ np.array(result2.scores) - np.array(expect2["scores"]))
+
+ assert diff_boxes_1.max(
+ ) < 1e-03, "There's difference in detection boxes 1."
+ assert diff_scores_1.max(
+ ) < 1e-04, "There's difference in detection score 1."
+
+ assert diff_boxes_2.max(
+ ) < 1e-03, "There's difference in detection boxes 2."
+ assert diff_scores_2.max(
+ ) < 1e-04, "There's difference in detection score 2."
+
+ # test batch predict
+ results = model.batch_predict([im1, im2])
+ result1 = results[0]
+ result2 = results[1]
+
+ diff_boxes_1 = np.fabs(
+ np.array(result1.boxes) - np.array(expect1["boxes"]))
+ diff_boxes_2 = np.fabs(
+ np.array(result2.boxes) - np.array(expect2["boxes"]))
+
+ diff_scores_1 = np.fabs(
+ np.array(result1.scores) - np.array(expect1["scores"]))
+ diff_scores_2 = np.fabs(
+ np.array(result2.scores) - np.array(expect2["scores"]))
+ assert diff_boxes_1.max(
+ ) < 1e-03, "There's difference in detection boxes 1."
+ assert diff_scores_1.max(
+ ) < 1e-04, "There's difference in detection score 1."
+
+ assert diff_boxes_2.max(
+ ) < 1e-03, "There's difference in detection boxes 2."
+ assert diff_scores_2.max(
+ ) < 1e-04, "There's difference in detection score 2."
+
+
+def test_detection_yolov7face_runtime():
+ model_url = "https://bj.bcebos.com/paddlehub/fastdeploy/yolov7-lite-e.onnx"
+ input_url1 = "https://gitee.com/paddlepaddle/PaddleDetection/raw/release/2.4/demo/000000014439.jpg"
+ result_url1 = "https://bj.bcebos.com/paddlehub/fastdeploy/yolov7_result1.pkl"
+ fd.download(model_url, "resources")
+ fd.download(input_url1, "resources")
+ fd.download(result_url1, "resources")
+
+ model_file = "resources/yolov7-lite-e.onnx"
+
+ preprocessor = fd.vision.detection.Yolov7FacePreprocessor()
+ postprocessor = fd.vision.detection.YOLOv7FacePostprocessor()
+
+ rc.test_option.set_model_path(model_file, model_format=ModelFormat.ONNX)
+ rc.test_option.use_openvino_backend()
+ runtime = fd.Runtime(rc.test_option)
+
+ with open("resources/yolov7_result1.pkl", "rb") as f:
+ expect1 = pickle.load(f)
+
+ im1 = cv2.imread("resources/000000014439.jpg")
+
+ for i in range(3):
+ # test runtime
+ input_tensors, ims_info = preprocessor.run([im1.copy()])
+ output_tensors = runtime.infer({"images": input_tensors[0]})
+ results = postprocessor.run(output_tensors, ims_info)
+ result1 = results[0]
+
+ diff_boxes_1 = np.fabs(
+ np.array(result1.boxes) - np.array(expect1["boxes"]))
+ diff_scores_1 = np.fabs(
+ np.array(result1.scores) - np.array(expect1["scores"]))
+
+ assert diff_boxes_1.max(
+ ) < 1e-03, "There's difference in detection boxes 1."
+ assert diff_scores_1.max(
+ ) < 1e-04, "There's difference in detection score 1."
+
+
+if __name__ == "__main__":
+ test_detection_yolov7face()
+ test_detection_yolov7face_runtime()
From ada54bfd471b564f77ce57498d6dd997000b4080 Mon Sep 17 00:00:00 2001
From: huangjianhui <852142024@qq.com>
Date: Wed, 14 Dec 2022 19:18:53 +0800
Subject: [PATCH 61/77] [Other]Update python && cpp multi_thread examples
(#876)
* Refactor PaddleSeg with preprocessor && postprocessor
* Fix bugs
* Delete redundancy code
* Modify by comments
* Refactor according to comments
* Add batch evaluation
* Add single test script
* Add ppliteseg single test script && fix eval(raise) error
* fix bug
* Fix evaluation segmentation.py batch predict
* Fix segmentation evaluation bug
* Fix evaluation segmentation bugs
* Update segmentation result docs
* Update old predict api and DisableNormalizeAndPermute
* Update resize segmentation label map with cv::INTER_NEAREST
* Add Model Clone function for PaddleClas && PaddleDet && PaddleSeg
* Add multi thread demo
* Add python model clone function
* Add multi thread python && C++ example
* Fix bug
* Update python && cpp multi_thread examples
* Add cpp && python directory
* Add README.md for examples
* Delete redundant code
Co-authored-by: Jason
---
fastdeploy/vision/vision_pybind.cc | 65 +++++++++++++++
tutorials/multi_thread/cpp/CMakeLists.txt | 14 ++++
tutorials/multi_thread/cpp/README.md | 79 +++++++++++++++++++
.../{ => multi_thread/cpp}/multi_thread.cc | 66 ++++++++++++----
tutorials/multi_thread/python/README.md | 77 ++++++++++++++++++
.../python/multi_thread_process.py} | 72 +++++++++++------
6 files changed, 334 insertions(+), 39 deletions(-)
create mode 100644 tutorials/multi_thread/cpp/CMakeLists.txt
create mode 100644 tutorials/multi_thread/cpp/README.md
rename tutorials/{ => multi_thread/cpp}/multi_thread.cc (64%)
create mode 100644 tutorials/multi_thread/python/README.md
rename tutorials/{multi_thread.py => multi_thread/python/multi_thread_process.py} (59%)
diff --git a/fastdeploy/vision/vision_pybind.cc b/fastdeploy/vision/vision_pybind.cc
index 55312d1a3..cecd4f7c3 100644
--- a/fastdeploy/vision/vision_pybind.cc
+++ b/fastdeploy/vision/vision_pybind.cc
@@ -37,6 +37,21 @@ void BindVision(pybind11::module& m) {
.def(pybind11::init())
.def_readwrite("data", &vision::Mask::data)
.def_readwrite("shape", &vision::Mask::shape)
+ .def(pybind11::pickle(
+ [](const vision::Mask &m) {
+ return pybind11::make_tuple(m.data, m.shape);
+ },
+ [](pybind11::tuple t) {
+ if (t.size() != 2)
+ throw std::runtime_error("vision::Mask pickle with invalid state!");
+
+ vision::Mask m;
+ m.data = t[0].cast>();
+ m.shape = t[1].cast>();
+
+ return m;
+ }
+ ))
.def("__repr__", &vision::Mask::Str)
.def("__str__", &vision::Mask::Str);
@@ -44,6 +59,21 @@ void BindVision(pybind11::module& m) {
.def(pybind11::init())
.def_readwrite("label_ids", &vision::ClassifyResult::label_ids)
.def_readwrite("scores", &vision::ClassifyResult::scores)
+ .def(pybind11::pickle(
+ [](const vision::ClassifyResult &c) {
+ return pybind11::make_tuple(c.label_ids, c.scores);
+ },
+ [](pybind11::tuple t) {
+ if (t.size() != 2)
+ throw std::runtime_error("vision::ClassifyResult pickle with invalid state!");
+
+ vision::ClassifyResult c;
+ c.label_ids = t[0].cast>();
+ c.scores = t[1].cast>();
+
+ return c;
+ }
+ ))
.def("__repr__", &vision::ClassifyResult::Str)
.def("__str__", &vision::ClassifyResult::Str);
@@ -54,6 +84,24 @@ void BindVision(pybind11::module& m) {
.def_readwrite("label_ids", &vision::DetectionResult::label_ids)
.def_readwrite("masks", &vision::DetectionResult::masks)
.def_readwrite("contain_masks", &vision::DetectionResult::contain_masks)
+ .def(pybind11::pickle(
+ [](const vision::DetectionResult &d) {
+ return pybind11::make_tuple(d.boxes, d.scores, d.label_ids, d.masks, d.contain_masks);
+ },
+ [](pybind11::tuple t) {
+ if (t.size() != 5)
+ throw std::runtime_error("vision::DetectionResult pickle with Invalid state!");
+
+ vision::DetectionResult d;
+ d.boxes = t[0].cast>>();
+ d.scores = t[1].cast>();
+ d.label_ids = t[2].cast>();
+ d.masks = t[3].cast>();
+ d.contain_masks = t[4].cast();
+
+ return d;
+ }
+ ))
.def("__repr__", &vision::DetectionResult::Str)
.def("__str__", &vision::DetectionResult::Str);
@@ -104,6 +152,23 @@ void BindVision(pybind11::module& m) {
.def_readwrite("score_map", &vision::SegmentationResult::score_map)
.def_readwrite("shape", &vision::SegmentationResult::shape)
.def_readwrite("contain_score_map", &vision::SegmentationResult::contain_score_map)
+ .def(pybind11::pickle(
+ [](const vision::SegmentationResult &s) {
+ return pybind11::make_tuple(s.label_map, s.score_map, s.shape, s.contain_score_map);
+ },
+ [](pybind11::tuple t) {
+ if (t.size() != 4)
+ throw std::runtime_error("vision::SegmentationResult pickle with Invalid state!");
+
+ vision::SegmentationResult s;
+ s.label_map = t[0].cast>();
+ s.score_map = t[1].cast>();
+ s.shape = t[2].cast>();
+ s.contain_score_map = t[3].cast();
+
+ return s;
+ }
+ ))
.def("__repr__", &vision::SegmentationResult::Str)
.def("__str__", &vision::SegmentationResult::Str);
diff --git a/tutorials/multi_thread/cpp/CMakeLists.txt b/tutorials/multi_thread/cpp/CMakeLists.txt
new file mode 100644
index 000000000..d6882f897
--- /dev/null
+++ b/tutorials/multi_thread/cpp/CMakeLists.txt
@@ -0,0 +1,14 @@
+PROJECT(multi_thread_demo C CXX)
+CMAKE_MINIMUM_REQUIRED (VERSION 3.10)
+
+# 指定下载解压后的fastdeploy库路径
+option(FASTDEPLOY_INSTALL_DIR "Path of downloaded fastdeploy sdk.")
+
+include(${FASTDEPLOY_INSTALL_DIR}/FastDeploy.cmake)
+
+# 添加FastDeploy依赖头文件
+include_directories(${FASTDEPLOY_INCS})
+
+add_executable(multi_thread_demo ${PROJECT_SOURCE_DIR}/multi_thread.cc)
+# 添加FastDeploy库依赖
+target_link_libraries(multi_thread_demo ${FASTDEPLOY_LIBS} pthread)
diff --git a/tutorials/multi_thread/cpp/README.md b/tutorials/multi_thread/cpp/README.md
new file mode 100644
index 000000000..066340467
--- /dev/null
+++ b/tutorials/multi_thread/cpp/README.md
@@ -0,0 +1,79 @@
+# PaddleClas C++部署示例
+
+本目录下提供`infer.cc`快速完成PaddleClas系列模型在CPU/GPU,以及GPU上通过TensorRT加速部署的示例。
+
+在部署前,需确认以下两个步骤
+
+- 1. 软硬件环境满足要求,参考[FastDeploy环境要求](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md)
+- 2. 根据开发环境,下载预编译部署库和samples代码,参考[FastDeploy预编译库](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md)
+
+以Linux上ResNet50_vd推理为例,在本目录执行如下命令即可完成编译测试,支持此模型需保证FastDeploy版本0.7.0以上(x.x.x>=0.7.0)
+
+```bash
+mkdir build
+cd build
+# 下载FastDeploy预编译库,用户可在上文提到的`FastDeploy预编译库`中自行选择合适的版本使用
+wget https://bj.bcebos.com/fastdeploy/release/cpp/fastdeploy-linux-x64-x.x.x.tgz
+tar xvf fastdeploy-linux-x64-x.x.x.tgz
+cmake .. -DFASTDEPLOY_INSTALL_DIR=${PWD}/fastdeploy-linux-x64-x.x.x
+make -j
+
+# 下载ResNet50_vd模型文件和测试图片
+wget https://bj.bcebos.com/paddlehub/fastdeploy/ResNet50_vd_infer.tgz
+tar -xvf ResNet50_vd_infer.tgz
+wget https://gitee.com/paddlepaddle/PaddleClas/raw/release/2.4/deploy/images/ImageNet/ILSVRC2012_val_00000010.jpeg
+
+
+# CPU推理
+./infer_demo ResNet50_vd_infer ILSVRC2012_val_00000010.jpeg 0
+# GPU推理
+./infer_demo ResNet50_vd_infer ILSVRC2012_val_00000010.jpeg 1
+# GPU上TensorRT推理
+./infer_demo ResNet50_vd_infer ILSVRC2012_val_00000010.jpeg 2
+```
+
+以上命令只适用于Linux或MacOS, Windows下SDK的使用方式请参考:
+- [如何在Windows中使用FastDeploy C++ SDK](../../../../../docs/cn/faq/use_sdk_on_windows.md)
+
+## PaddleClas C++接口
+
+### PaddleClas类
+
+```c++
+fastdeploy::vision::classification::PaddleClasModel(
+ const string& model_file,
+ const string& params_file,
+ const string& config_file,
+ const RuntimeOption& runtime_option = RuntimeOption(),
+ const ModelFormat& model_format = ModelFormat::PADDLE)
+```
+
+PaddleClas模型加载和初始化,其中model_file, params_file为训练模型导出的Paddle inference文件,具体请参考其文档说明[模型导出](https://github.com/PaddlePaddle/PaddleClas/blob/release/2.4/docs/zh_CN/inference_deployment/export_model.md#2-%E5%88%86%E7%B1%BB%E6%A8%A1%E5%9E%8B%E5%AF%BC%E5%87%BA)
+
+**参数**
+
+> * **model_file**(str): 模型文件路径
+> * **params_file**(str): 参数文件路径
+> * **config_file**(str): 推理部署配置文件
+> * **runtime_option**(RuntimeOption): 后端推理配置,默认为None,即采用默认配置
+> * **model_format**(ModelFormat): 模型格式,默认为Paddle格式
+
+#### Predict函数
+
+> ```c++
+> PaddleClasModel::Predict(cv::Mat* im, ClassifyResult* result, int topk = 1)
+> ```
+>
+> 模型预测接口,输入图像直接输出检测结果。
+>
+> **参数**
+>
+> > * **im**: 输入图像,注意需为HWC,BGR格式
+> > * **result**: 分类结果,包括label_id,以及相应的置信度, ClassifyResult说明参考[视觉模型预测结果](../../../../../docs/api/vision_results/)
+> > * **topk**(int):返回预测概率最高的topk个分类结果,默认为1
+
+
+- [模型介绍](../../)
+- [Python部署](../python)
+- [视觉模型预测结果](../../../../../docs/api/vision_results/)
+- [如何切换模型推理后端引擎](../../../../../docs/cn/faq/how_to_change_backend.md)
diff --git a/tutorials/multi_thread.cc b/tutorials/multi_thread/cpp/multi_thread.cc
similarity index 64%
rename from tutorials/multi_thread.cc
rename to tutorials/multi_thread/cpp/multi_thread.cc
index 6cc01b5d3..9c9d0ec5a 100644
--- a/tutorials/multi_thread.cc
+++ b/tutorials/multi_thread/cpp/multi_thread.cc
@@ -6,21 +6,44 @@ const char sep = '\\';
const char sep = '/';
#endif
-void predict(fastdeploy::vision::classification::PaddleClasModel *model, int thread_id, const std::string& image_file) {
- auto im = cv::imread(image_file);
+void Predict(fastdeploy::vision::classification::PaddleClasModel *model, int thread_id, const std::vector& images) {
+ for (auto const &image_file : images) {
+ auto im = cv::imread(image_file);
- fastdeploy::vision::ClassifyResult res;
- if (!model->Predict(im, &res)) {
- std::cerr << "Failed to predict." << std::endl;
- return;
+ fastdeploy::vision::ClassifyResult res;
+ if (!model->Predict(im, &res)) {
+ std::cerr << "Failed to predict." << std::endl;
+ return;
+ }
+
+ // print res
+ std::cout << "Thread Id: " << thread_id << std::endl;
+ std::cout << res.Str() << std::endl;
}
-
- // print res
- std::cout << "Thread Id: " << thread_id << std::endl;
- std::cout << res.Str() << std::endl;
}
-void CpuInfer(const std::string& model_dir, const std::string& image_file, int thread_num) {
+void GetImageList(std::vector>* image_list, const std::string& image_file_path, int thread_num){
+ std::vector images;
+ cv::glob(image_file_path, images, false);
+ // number of image files in images folder
+ size_t count = images.size();
+ size_t num = count / thread_num;
+ for (int i = 0; i < thread_num; i++) {
+ std::vector temp_list;
+ if (i == thread_num - 1) {
+ for (size_t j = i*num; j < count; j++){
+ temp_list.push_back(images[j]);
+ }
+ } else {
+ for (size_t j = 0; j < num; j++){
+ temp_list.push_back(images[i * num + j]);
+ }
+ }
+ (*image_list)[i] = temp_list;
+ }
+}
+
+void CpuInfer(const std::string& model_dir, const std::string& image_file_path, int thread_num) {
auto model_file = model_dir + sep + "inference.pdmodel";
auto params_file = model_dir + sep + "inference.pdiparams";
auto config_file = model_dir + sep + "inference_cls.yaml";
@@ -39,9 +62,12 @@ void CpuInfer(const std::string& model_dir, const std::string& image_file, int t
models.emplace_back(std::move(model.Clone()));
}
+ std::vector> image_list(thread_num);
+ GetImageList(&image_list, image_file_path, thread_num);
+
std::vector threads;
for (int i = 0; i < thread_num; ++i) {
- threads.emplace_back(predict, models[i].get(), i, image_file);
+ threads.emplace_back(Predict, models[i].get(), i, image_list[i]);
}
for (int i = 0; i < thread_num; ++i) {
@@ -49,7 +75,7 @@ void CpuInfer(const std::string& model_dir, const std::string& image_file, int t
}
}
-void GpuInfer(const std::string& model_dir, const std::string& image_file, int thread_num) {
+void GpuInfer(const std::string& model_dir, const std::string& image_file_path, int thread_num) {
auto model_file = model_dir + sep + "inference.pdmodel";
auto params_file = model_dir + sep + "inference.pdiparams";
auto config_file = model_dir + sep + "inference_cls.yaml";
@@ -68,9 +94,12 @@ void GpuInfer(const std::string& model_dir, const std::string& image_file, int t
models.emplace_back(std::move(model.Clone()));
}
+ std::vector> image_list(thread_num);
+ GetImageList(&image_list, image_file_path, thread_num);
+
std::vector threads;
for (int i = 0; i < thread_num; ++i) {
- threads.emplace_back(predict, models[i].get(), i, image_file);
+ threads.emplace_back(Predict, models[i].get(), i, image_list[i]);
}
for (int i = 0; i < thread_num; ++i) {
@@ -78,7 +107,7 @@ void GpuInfer(const std::string& model_dir, const std::string& image_file, int t
}
}
-void TrtInfer(const std::string& model_dir, const std::string& image_file, int thread_num) {
+void TrtInfer(const std::string& model_dir, const std::string& image_file_path, int thread_num) {
auto model_file = model_dir + sep + "inference.pdmodel";
auto params_file = model_dir + sep + "inference.pdiparams";
auto config_file = model_dir + sep + "inference_cls.yaml";
@@ -99,9 +128,12 @@ void TrtInfer(const std::string& model_dir, const std::string& image_file, int t
models.emplace_back(std::move(model.Clone()));
}
+ std::vector> image_list(thread_num);
+ GetImageList(&image_list, image_file_path, thread_num);
+
std::vector threads;
for (int i = 0; i < thread_num; ++i) {
- threads.emplace_back(predict, models[i].get(), i, image_file);
+ threads.emplace_back(Predict, models[i].get(), i, image_list[i]);
}
for (int i = 0; i < thread_num; ++i) {
@@ -112,7 +144,7 @@ void TrtInfer(const std::string& model_dir, const std::string& image_file, int t
int main(int argc, char **argv) {
if (argc < 5) {
std::cout << "Usage: infer_demo path/to/model path/to/image run_option thread_num, "
- "e.g ./infer_demo ./ResNet50_vd ./test.jpeg 0 3"
+ "e.g ./multi_thread_demo ./ResNet50_vd ./test.jpeg 0 3"
<< 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."
diff --git a/tutorials/multi_thread/python/README.md b/tutorials/multi_thread/python/README.md
new file mode 100644
index 000000000..9d17e6f65
--- /dev/null
+++ b/tutorials/multi_thread/python/README.md
@@ -0,0 +1,77 @@
+# PaddleClas模型 Python部署示例
+
+在部署前,需确认以下两个步骤
+
+- 1. 软硬件环境满足要求,参考[FastDeploy环境要求](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md)
+- 2. FastDeploy Python whl包安装,参考[FastDeploy Python安装](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md)
+
+本目录下提供`infer.py`快速完成ResNet50_vd在CPU/GPU,以及GPU上通过TensorRT加速部署的示例。执行如下脚本即可完成
+
+```bash
+#下载部署示例代码
+git clone https://github.com/PaddlePaddle/FastDeploy.git
+cd FastDeploy/examples/vision/classification/paddleclas/python
+
+# 下载ResNet50_vd模型文件和测试图片
+wget https://bj.bcebos.com/paddlehub/fastdeploy/ResNet50_vd_infer.tgz
+tar -xvf ResNet50_vd_infer.tgz
+wget https://gitee.com/paddlepaddle/PaddleClas/raw/release/2.4/deploy/images/ImageNet/ILSVRC2012_val_00000010.jpeg
+
+# CPU推理
+python infer.py --model ResNet50_vd_infer --image ILSVRC2012_val_00000010.jpeg --device cpu --topk 1
+# GPU推理
+python infer.py --model ResNet50_vd_infer --image ILSVRC2012_val_00000010.jpeg --device gpu --topk 1
+# GPU上使用TensorRT推理 (注意:TensorRT推理第一次运行,有序列化模型的操作,有一定耗时,需要耐心等待)
+python infer.py --model ResNet50_vd_infer --image ILSVRC2012_val_00000010.jpeg --device gpu --use_trt True --topk 1
+# IPU推理(注意:IPU推理首次运行会有序列化模型的操作,有一定耗时,需要耐心等待)
+python infer.py --model ResNet50_vd_infer --image ILSVRC2012_val_00000010.jpeg --device ipu --topk 1
+```
+
+运行完成后返回结果如下所示
+```bash
+ClassifyResult(
+label_ids: 153,
+scores: 0.686229,
+)
+```
+
+## PaddleClasModel Python接口
+
+```python
+fd.vision.classification.PaddleClasModel(model_file, params_file, config_file, runtime_option=None, model_format=ModelFormat.PADDLE)
+```
+
+PaddleClas模型加载和初始化,其中model_file, params_file为训练模型导出的Paddle inference文件,具体请参考其文档说明[模型导出](https://github.com/PaddlePaddle/PaddleClas/blob/release/2.4/docs/zh_CN/inference_deployment/export_model.md#2-%E5%88%86%E7%B1%BB%E6%A8%A1%E5%9E%8B%E5%AF%BC%E5%87%BA)
+
+**参数**
+
+> * **model_file**(str): 模型文件路径
+> * **params_file**(str): 参数文件路径
+> * **config_file**(str): 推理部署配置文件
+> * **runtime_option**(RuntimeOption): 后端推理配置,默认为None,即采用默认配置
+> * **model_format**(ModelFormat): 模型格式,默认为Paddle格式
+
+### predict函数
+
+> ```python
+> PaddleClasModel.predict(input_image, topk=1)
+> ```
+>
+> 模型预测结口,输入图像直接输出分类topk结果。
+>
+> **参数**
+>
+> > * **input_image**(np.ndarray): 输入数据,注意需为HWC,BGR格式
+> > * **topk**(int):返回预测概率最高的topk个分类结果,默认为1
+
+> **返回**
+>
+> > 返回`fastdeploy.vision.ClassifyResult`结构体,结构体说明参考文档[视觉模型预测结果](../../../../../docs/api/vision_results/)
+
+
+## 其它文档
+
+- [PaddleClas 模型介绍](..)
+- [PaddleClas C++部署](../cpp)
+- [模型预测结果说明](../../../../../docs/api/vision_results/)
+- [如何切换模型推理后端引擎](../../../../../docs/cn/faq/how_to_change_backend.md)
diff --git a/tutorials/multi_thread.py b/tutorials/multi_thread/python/multi_thread_process.py
similarity index 59%
rename from tutorials/multi_thread.py
rename to tutorials/multi_thread/python/multi_thread_process.py
index 27d3b3331..edeee6a06 100644
--- a/tutorials/multi_thread.py
+++ b/tutorials/multi_thread/python/multi_thread_process.py
@@ -4,6 +4,7 @@ import fastdeploy as fd
import cv2
import os
import psutil
+from multiprocessing import Pool
def parse_arguments():
@@ -31,6 +32,13 @@ def parse_arguments():
default=False,
help="Wether to use tensorrt.")
parser.add_argument("--thread_num", type=int, default=1, help="thread num")
+ parser.add_argument(
+ "--use_multi_process",
+ type=ast.literal_eval,
+ default=False,
+ help="Wether to use multi process.")
+ parser.add_argument(
+ "--process_num", type=int, default=1, help="process num")
return parser.parse_args()
@@ -71,7 +79,7 @@ def build_option(args):
def predict(model, img_list, topk):
result_list = []
- # 预测图片分类结果
+ # predict classification result
for image in img_list:
im = cv2.imread(image)
result = model.predict(im, topk)
@@ -79,6 +87,13 @@ def predict(model, img_list, topk):
return result_list
+def process_predict(image):
+ # predict classification result
+ im = cv2.imread(image)
+ result = model.predict(im, args.topk)
+ return result
+
+
class WrapperThread(Thread):
def __init__(self, func, args):
super(WrapperThread, self).__init__()
@@ -95,9 +110,8 @@ class WrapperThread(Thread):
if __name__ == '__main__':
args = parse_arguments()
- thread_num = args.thread_num
imgs_list = get_image_list(args.image_path)
- # 配置runtime,加载模型
+ # configure runtime and load model
runtime_option = build_option(args)
model_file = os.path.join(args.model, "inference.pdmodel")
@@ -105,24 +119,38 @@ if __name__ == '__main__':
config_file = os.path.join(args.model, "inference_cls.yaml")
model = fd.vision.classification.PaddleClasModel(
model_file, params_file, config_file, runtime_option=runtime_option)
- threads = []
- image_num_each_thread = int(len(imgs_list) / thread_num)
- for i in range(thread_num):
- if i == thread_num - 1:
- t = WrapperThread(
- predict,
- args=(model, imgs_list[i * image_num_each_thread:], i))
- else:
- t = WrapperThread(
- predict,
- args=(model.clone(), imgs_list[i * image_num_each_thread:(
- i + 1) * image_num_each_thread - 1], i))
- threads.append(t)
- t.start()
+ if args.use_multi_process:
+ results = []
+ process_num = args.process_num
+ with Pool(process_num) as pool:
+ results = pool.map(process_predict, imgs_list)
+ for result in results:
+ print(result)
+ else:
+ threads = []
+ thread_num = args.thread_num
+ image_num_each_thread = int(len(imgs_list) / thread_num)
+ # unless you want independent model in each thread, actually model.clone()
+ # is the same as model when creating thead because of the existence of
+ # GIL(Global Interpreter Lock) in python. In addition, model.clone() will consume
+ # additional memory to store independent member variables
+ for i in range(thread_num):
+ if i == thread_num - 1:
+ t = WrapperThread(
+ predict,
+ args=(model.clone(), imgs_list[i * image_num_each_thread:],
+ args.topk))
+ else:
+ t = WrapperThread(
+ predict,
+ args=(model.clone(), imgs_list[i * image_num_each_thread:(
+ i + 1) * image_num_each_thread - 1], args.topk))
+ threads.append(t)
+ t.start()
- for i in range(thread_num):
- threads[i].join()
+ for i in range(thread_num):
+ threads[i].join()
- for i in range(thread_num):
- for result in threads[i].get_result():
- print('thread:', i, ', result: ', result)
+ for i in range(thread_num):
+ for result in threads[i].get_result():
+ print('thread:', i, ', result: ', result)
From 9b4dc941b1db5d753981105496158451cfa6e966 Mon Sep 17 00:00:00 2001
From: Jason
Date: Wed, 14 Dec 2022 19:23:03 +0800
Subject: [PATCH 62/77] Create README_CN.md
---
tutorials/README_CN.md | 6 ++++++
1 file changed, 6 insertions(+)
create mode 100644 tutorials/README_CN.md
diff --git a/tutorials/README_CN.md b/tutorials/README_CN.md
new file mode 100644
index 000000000..707e0a31a
--- /dev/null
+++ b/tutorials/README_CN.md
@@ -0,0 +1,6 @@
+# 教程
+
+本目录下提供一些FastDeploy使用的教程。对于常见的模型部署,请直接参阅[FastDeploy/examples](../examples)下的代码示例。
+
+- Intel独立显卡/集成显卡部署 [见intel_gpu](intel_gpu)
+- 模型多线程调用 [见multi_thread](multi_thread)
From 574acfe3f1513fae3d9463fa3153ca7fc91ad046 Mon Sep 17 00:00:00 2001
From: Jason
Date: Wed, 14 Dec 2022 19:23:47 +0800
Subject: [PATCH 63/77] Update README_CN.md
---
tutorials/README_CN.md | 3 +++
1 file changed, 3 insertions(+)
diff --git a/tutorials/README_CN.md b/tutorials/README_CN.md
index 707e0a31a..771bb8934 100644
--- a/tutorials/README_CN.md
+++ b/tutorials/README_CN.md
@@ -1,3 +1,6 @@
+[English](README.md) | 中文
+
+
# 教程
本目录下提供一些FastDeploy使用的教程。对于常见的模型部署,请直接参阅[FastDeploy/examples](../examples)下的代码示例。
From 8a3aede30555e20ea59a4709b1fe288c9153ec94 Mon Sep 17 00:00:00 2001
From: Jason
Date: Wed, 14 Dec 2022 19:24:55 +0800
Subject: [PATCH 64/77] Create README.md
---
tutorials/README.md | 13 +++++++++++++
1 file changed, 13 insertions(+)
create mode 100644 tutorials/README.md
diff --git a/tutorials/README.md b/tutorials/README.md
new file mode 100644
index 000000000..2d114e9d0
--- /dev/null
+++ b/tutorials/README.md
@@ -0,0 +1,13 @@
+English | [中文](README_CN.md)
+
+
+# Tutorials
+
+
+
+This directory provides some tutorials for FastDeploy. For other model deployment, please refer to the example [FastDeploy/examples](../examples) directly.
+
+
+-Intel independent graphics card/integrated graphics card deployment [see intel_gpu](intel_gpu)
+
+-Model multithreaded call [see multi_thread](multi_thread)
From 3fad8199282dc7d5a3a22e558d0209c24bfff04a Mon Sep 17 00:00:00 2001
From: leiqing <54695910+leiqing1@users.noreply.github.com>
Date: Thu, 15 Dec 2022 11:29:35 +0800
Subject: [PATCH 65/77] Update README.md
---
README.md | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/README.md b/README.md
index b1dd06cd5..e8f014f6f 120000
--- a/README.md
+++ b/README.md
@@ -1 +1 @@
-README_EN.md
+README_CN.md
From 3164af65a4d8783df8848690234c351ab20c72b3 Mon Sep 17 00:00:00 2001
From: totorolin <97090522+totorolin@users.noreply.github.com>
Date: Thu, 15 Dec 2022 11:46:13 +0800
Subject: [PATCH 66/77] [Model] Support PaddleYOLO YOLOv5 YOLOv6 YOLOv7 RTMDet
models (#857)
* Add files via upload
* Add files via upload
* Add files via upload
* Add files via upload
* Add files via upload
* Add files via upload
* Add files via upload
* Add files via upload
* Add files via upload
* Add files via upload
* Add files via upload
* Add files via upload
* Add files via upload
* Add files via upload
* Add files via upload
* Add files via upload
Co-authored-by: DefTruth <31974251+DefTruth@users.noreply.github.com>
---
.../detection/paddledetection/README.md | 19 ++-
.../paddledetection/cpp/CMakeLists.txt | 15 ++
.../detection/paddledetection/cpp/README.md | 4 +-
.../paddledetection/cpp/infer_rtmdet.cc | 129 ++++++++++++++++++
.../paddledetection/cpp/infer_yolov5.cc | 129 ++++++++++++++++++
.../paddledetection/cpp/infer_yolov6.cc | 129 ++++++++++++++++++
.../paddledetection/cpp/infer_yolov7.cc | 128 +++++++++++++++++
.../paddledetection/python/README.md | 4 +
.../paddledetection/python/infer_rtmdet.py | 59 ++++++++
.../paddledetection/python/infer_yolov5.py | 59 ++++++++
.../paddledetection/python/infer_yolov6.py | 59 ++++++++
.../paddledetection/python/infer_yolov7.py | 59 ++++++++
fastdeploy/vision/detection/ppdet/model.h | 64 +++++++++
.../vision/detection/ppdet/ppdet_pybind.cc | 16 +++
.../vision/detection/ppdet/__init__.py | 100 ++++++++++++++
15 files changed, 968 insertions(+), 5 deletions(-)
create mode 100644 examples/vision/detection/paddledetection/cpp/infer_rtmdet.cc
create mode 100644 examples/vision/detection/paddledetection/cpp/infer_yolov5.cc
create mode 100644 examples/vision/detection/paddledetection/cpp/infer_yolov6.cc
create mode 100644 examples/vision/detection/paddledetection/cpp/infer_yolov7.cc
create mode 100644 examples/vision/detection/paddledetection/python/infer_rtmdet.py
create mode 100644 examples/vision/detection/paddledetection/python/infer_yolov5.py
create mode 100644 examples/vision/detection/paddledetection/python/infer_yolov6.py
create mode 100644 examples/vision/detection/paddledetection/python/infer_yolov7.py
diff --git a/examples/vision/detection/paddledetection/README.md b/examples/vision/detection/paddledetection/README.md
index 575b305bb..ae4ba494c 100644
--- a/examples/vision/detection/paddledetection/README.md
+++ b/examples/vision/detection/paddledetection/README.md
@@ -16,6 +16,10 @@
- [FasterRCNN系列模型](https://github.com/PaddlePaddle/PaddleDetection/tree/release/2.4/configs/faster_rcnn)
- [MaskRCNN系列模型](https://github.com/PaddlePaddle/PaddleDetection/tree/release/2.4/configs/mask_rcnn)
- [SSD系列模型](https://github.com/PaddlePaddle/PaddleDetection/tree/release/2.5/configs/ssd)
+- [YOLOv5系列模型](https://github.com/PaddlePaddle/PaddleYOLO/tree/release/2.5/configs/yolov5)
+- [YOLOv6系列模型](https://github.com/PaddlePaddle/PaddleYOLO/tree/release/2.5/configs/yolov6)
+- [YOLOv7系列模型](https://github.com/PaddlePaddle/PaddleYOLO/tree/release/2.5/configs/yolov7)
+- [RTMDet系列模型](https://github.com/PaddlePaddle/PaddleYOLO/tree/release/2.5/configs/rtmdet)
## 导出部署模型
@@ -44,9 +48,18 @@
| [yolox_s_300e_coco](https://bj.bcebos.com/paddlehub/fastdeploy/yolox_s_300e_coco.tgz) | 35MB | Box AP 40.4% | |
| [faster_rcnn_r50_vd_fpn_2x_coco](https://bj.bcebos.com/paddlehub/fastdeploy/faster_rcnn_r50_vd_fpn_2x_coco.tgz) | 160MB | Box AP 40.8%| 暂不支持TensorRT |
| [mask_rcnn_r50_1x_coco](https://bj.bcebos.com/paddlehub/fastdeploy/mask_rcnn_r50_1x_coco.tgz) | 128M | Box AP 37.4%, Mask AP 32.8%| 暂不支持TensorRT、ORT |
-| [ssd_mobilenet_v1_300_120e_voc](https://bj.bcebos.com/paddlehub/fastdeploy/ssd_mobilenet_v1_300_120e_voc.tgz) | 21.7M | Box AP 73.8%| 暂不支持TensorRT、ORT |
-| [ssd_vgg16_300_240e_voc](https://bj.bcebos.com/paddlehub/fastdeploy/ssd_vgg16_300_240e_voc.tgz) | 97.7M | Box AP 77.8%| 暂不支持TensorRT、ORT |
-| [ssdlite_mobilenet_v1_300_coco](https://bj.bcebos.com/paddlehub/fastdeploy/ssdlite_mobilenet_v1_300_coco.tgz) | 24.4M | | 暂不支持TensorRT、ORT |
+| [ssd_mobilenet_v1_300_120e_voc](https://bj.bcebos.com/paddlehub/fastdeploy/ssd_mobilenet_v1_300_120e_voc.tgz) | 24.9M | Box AP 73.8%| 暂不支持TensorRT、ORT |
+| [ssd_vgg16_300_240e_voc](https://bj.bcebos.com/paddlehub/fastdeploy/ssd_vgg16_300_240e_voc.tgz) | 106.5M | Box AP 77.8%| 暂不支持TensorRT、ORT |
+| [ssdlite_mobilenet_v1_300_coco](https://bj.bcebos.com/paddlehub/fastdeploy/ssdlite_mobilenet_v1_300_coco.tgz) | 29.1M | | 暂不支持TensorRT、ORT |
+| [rtmdet_l_300e_coco](https://bj.bcebos.com/paddlehub/fastdeploy/rtmdet_l_300e_coco.tgz) | 224M | Box AP 51.2%| |
+| [rtmdet_s_300e_coco](https://bj.bcebos.com/paddlehub/fastdeploy/rtmdet_s_300e_coco.tgz) | 42M | Box AP 44.5%| |
+| [yolov5_l_300e_coco](https://bj.bcebos.com/paddlehub/fastdeploy/yolov5_l_300e_coco.tgz) | 183M | Box AP 48.9%| |
+| [yolov5_s_300e_coco](https://bj.bcebos.com/paddlehub/fastdeploy/yolov5_s_300e_coco.tgz) | 31M | Box AP 37.6%| |
+| [yolov6_l_300e_coco](https://bj.bcebos.com/paddlehub/fastdeploy/yolov6_l_300e_coco.tgz) | 229M | Box AP 51.0%| |
+| [yolov6_s_400e_coco](https://bj.bcebos.com/paddlehub/fastdeploy/yolov6_s_400e_coco.tgz) | 68M | Box AP 43.4%| |
+| [yolov7_l_300e_coco](https://bj.bcebos.com/paddlehub/fastdeploy/yolov7_l_300e_coco.tgz) | 145M | Box AP 51.0%| |
+| [yolov7_x_300e_coco](https://bj.bcebos.com/paddlehub/fastdeploy/yolov7_x_300e_coco.tgz) | 277M | Box AP 53.0%| |
+
## 详细部署文档
- [Python部署](python)
diff --git a/examples/vision/detection/paddledetection/cpp/CMakeLists.txt b/examples/vision/detection/paddledetection/cpp/CMakeLists.txt
index 9bbbdf32e..9382931a1 100644
--- a/examples/vision/detection/paddledetection/cpp/CMakeLists.txt
+++ b/examples/vision/detection/paddledetection/cpp/CMakeLists.txt
@@ -29,3 +29,18 @@ target_link_libraries(infer_ppyolo_demo ${FASTDEPLOY_LIBS})
add_executable(infer_mask_rcnn_demo ${PROJECT_SOURCE_DIR}/infer_mask_rcnn.cc)
target_link_libraries(infer_mask_rcnn_demo ${FASTDEPLOY_LIBS})
+
+add_executable(infer_ssd_demo ${PROJECT_SOURCE_DIR}/infer_ssd.cc)
+target_link_libraries(infer_ssd_demo ${FASTDEPLOY_LIBS})
+
+add_executable(infer_yolov5_demo ${PROJECT_SOURCE_DIR}/infer_yolov5.cc)
+target_link_libraries(infer_yolov5_demo ${FASTDEPLOY_LIBS})
+
+add_executable(infer_yolov6_demo ${PROJECT_SOURCE_DIR}/infer_yolov6.cc)
+target_link_libraries(infer_yolov6_demo ${FASTDEPLOY_LIBS})
+
+add_executable(infer_yolov7_demo ${PROJECT_SOURCE_DIR}/infer_yolov7.cc)
+target_link_libraries(infer_yolov7_demo ${FASTDEPLOY_LIBS})
+
+add_executable(infer_rtmdet_demo ${PROJECT_SOURCE_DIR}/infer_rtmdet.cc)
+target_link_libraries(infer_rtmdet_demo ${FASTDEPLOY_LIBS})
diff --git a/examples/vision/detection/paddledetection/cpp/README.md b/examples/vision/detection/paddledetection/cpp/README.md
index 63df0365a..d9217ab1e 100644
--- a/examples/vision/detection/paddledetection/cpp/README.md
+++ b/examples/vision/detection/paddledetection/cpp/README.md
@@ -1,6 +1,6 @@
# PaddleDetection C++部署示例
-本目录下提供`infer_xxx.cc`快速完成PaddleDetection模型包括PPYOLOE/PicoDet/YOLOX/YOLOv3/PPYOLO/FasterRCNN在CPU/GPU,以及GPU上通过TensorRT加速部署的示例。
+本目录下提供`infer_xxx.cc`快速完成PaddleDetection模型包括PPYOLOE/PicoDet/YOLOX/YOLOv3/PPYOLO/FasterRCNN/YOLOv5/YOLOv6/YOLOv7/RTMDet在CPU/GPU,以及GPU上通过TensorRT加速部署的示例。
在部署前,需确认以下两个步骤
@@ -41,7 +41,7 @@ tar xvf ppyoloe_crn_l_300e_coco.tgz
### 模型类
-PaddleDetection目前支持6种模型系列,类名分别为`PPYOLOE`, `PicoDet`, `PaddleYOLOX`, `PPYOLO`, `FasterRCNN`,所有类名的构造函数和预测函数在参数上完全一致,本文档以PPYOLOE为例讲解API
+PaddleDetection目前支持6种模型系列,类名分别为`PPYOLOE`, `PicoDet`, `PaddleYOLOX`, `PPYOLO`, `FasterRCNN`,`SSD`,`PaddleYOLOv5`,`PaddleYOLOv6`,`PaddleYOLOv7`,`RTMDet`所有类名的构造函数和预测函数在参数上完全一致,本文档以PPYOLOE为例讲解API
```c++
fastdeploy::vision::detection::PPYOLOE(
const string& model_file,
diff --git a/examples/vision/detection/paddledetection/cpp/infer_rtmdet.cc b/examples/vision/detection/paddledetection/cpp/infer_rtmdet.cc
new file mode 100644
index 000000000..6262353ff
--- /dev/null
+++ b/examples/vision/detection/paddledetection/cpp/infer_rtmdet.cc
@@ -0,0 +1,129 @@
+// 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"
+
+#ifdef WIN32
+const char sep = '\\';
+#else
+const char sep = '/';
+#endif
+
+void CpuInfer(const std::string& model_dir, const std::string& image_file) {
+ auto model_file = model_dir + sep + "model.pdmodel";
+ auto params_file = model_dir + sep + "model.pdiparams";
+ auto config_file = model_dir + sep + "infer_cfg.yml";
+ auto option = fastdeploy::RuntimeOption();
+ option.UseCpu();
+ auto model = fastdeploy::vision::detection::RTMDet(model_file, params_file,
+ config_file, option);
+ if (!model.Initialized()) {
+ std::cerr << "Failed to initialize." << std::endl;
+ return;
+ }
+
+ auto im = cv::imread(image_file);
+ auto im_bak = im.clone();
+
+ 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_bak, res, 0.5);
+ cv::imwrite("vis_result.jpg", vis_im);
+ std::cout << "Visualized result saved in ./vis_result.jpg" << std::endl;
+}
+
+void GpuInfer(const std::string& model_dir, const std::string& image_file) {
+ auto model_file = model_dir + sep + "model.pdmodel";
+ auto params_file = model_dir + sep + "model.pdiparams";
+ auto config_file = model_dir + sep + "infer_cfg.yml";
+
+ auto option = fastdeploy::RuntimeOption();
+ option.UseGpu();
+ auto model = fastdeploy::vision::detection::RTMDet(model_file, params_file,
+ config_file, option);
+ if (!model.Initialized()) {
+ std::cerr << "Failed to initialize." << std::endl;
+ return;
+ }
+
+ auto im = cv::imread(image_file);
+ auto im_bak = im.clone();
+
+ 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_bak, res, 0.5);
+ cv::imwrite("vis_result.jpg", vis_im);
+ std::cout << "Visualized result saved in ./vis_result.jpg" << std::endl;
+}
+
+void TrtInfer(const std::string& model_dir, const std::string& image_file) {
+ auto model_file = model_dir + sep + "model.pdmodel";
+ auto params_file = model_dir + sep + "model.pdiparams";
+ auto config_file = model_dir + sep + "infer_cfg.yml";
+
+ auto option = fastdeploy::RuntimeOption();
+ option.UseGpu();
+ option.UseTrtBackend();
+ auto model = fastdeploy::vision::detection::RTMDet(model_file, params_file,
+ config_file, option);
+ if (!model.Initialized()) {
+ std::cerr << "Failed to initialize." << std::endl;
+ return;
+ }
+
+ 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, 0.5);
+ 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 < 4) {
+ std::cout
+ << "Usage: infer_demo path/to/model_dir path/to/image run_option, "
+ "e.g ./infer_model ./ppyolo_dirname ./test.jpeg 0"
+ << std::endl;
+ std::cout << "The data type of run_option is int, 0: run with cpu; 1: run "
+ "with gpu."
+ << std::endl;
+ return -1;
+ }
+
+ if (std::atoi(argv[3]) == 0) {
+ CpuInfer(argv[1], argv[2]);
+ } else if (std::atoi(argv[3]) == 1) {
+ GpuInfer(argv[1], argv[2]);
+ } else if(std::atoi(argv[3]) == 2){
+ TrtInfer(argv[1], argv[2]);
+ }
+ return 0;
+}
diff --git a/examples/vision/detection/paddledetection/cpp/infer_yolov5.cc b/examples/vision/detection/paddledetection/cpp/infer_yolov5.cc
new file mode 100644
index 000000000..c33441b7d
--- /dev/null
+++ b/examples/vision/detection/paddledetection/cpp/infer_yolov5.cc
@@ -0,0 +1,129 @@
+// 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"
+
+#ifdef WIN32
+const char sep = '\\';
+#else
+const char sep = '/';
+#endif
+
+void CpuInfer(const std::string& model_dir, const std::string& image_file) {
+ auto model_file = model_dir + sep + "model.pdmodel";
+ auto params_file = model_dir + sep + "model.pdiparams";
+ auto config_file = model_dir + sep + "infer_cfg.yml";
+ auto option = fastdeploy::RuntimeOption();
+ option.UseCpu();
+ auto model = fastdeploy::vision::detection::PaddleYOLOv5(model_file, params_file,
+ config_file, option);
+ if (!model.Initialized()) {
+ std::cerr << "Failed to initialize." << std::endl;
+ return;
+ }
+
+ auto im = cv::imread(image_file);
+ auto im_bak = im.clone();
+
+ 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_bak, res, 0.5);
+ cv::imwrite("vis_result.jpg", vis_im);
+ std::cout << "Visualized result saved in ./vis_result.jpg" << std::endl;
+}
+
+void GpuInfer(const std::string& model_dir, const std::string& image_file) {
+ auto model_file = model_dir + sep + "model.pdmodel";
+ auto params_file = model_dir + sep + "model.pdiparams";
+ auto config_file = model_dir + sep + "infer_cfg.yml";
+
+ auto option = fastdeploy::RuntimeOption();
+ option.UseGpu();
+ auto model = fastdeploy::vision::detection::PaddleYOLOv5(model_file, params_file,
+ config_file, option);
+ if (!model.Initialized()) {
+ std::cerr << "Failed to initialize." << std::endl;
+ return;
+ }
+
+ auto im = cv::imread(image_file);
+ auto im_bak = im.clone();
+
+ 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_bak, res, 0.5);
+ cv::imwrite("vis_result.jpg", vis_im);
+ std::cout << "Visualized result saved in ./vis_result.jpg" << std::endl;
+}
+
+void TrtInfer(const std::string& model_dir, const std::string& image_file) {
+ auto model_file = model_dir + sep + "model.pdmodel";
+ auto params_file = model_dir + sep + "model.pdiparams";
+ auto config_file = model_dir + sep + "infer_cfg.yml";
+
+ auto option = fastdeploy::RuntimeOption();
+ option.UseGpu();
+ option.UseTrtBackend();
+ auto model = fastdeploy::vision::detection::PaddleYOLOv5(model_file, params_file,
+ config_file, option);
+ if (!model.Initialized()) {
+ std::cerr << "Failed to initialize." << std::endl;
+ return;
+ }
+
+ 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, 0.5);
+ 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 < 4) {
+ std::cout
+ << "Usage: infer_demo path/to/model_dir path/to/image run_option, "
+ "e.g ./infer_model ./ppyolo_dirname ./test.jpeg 0"
+ << std::endl;
+ std::cout << "The data type of run_option is int, 0: run with cpu; 1: run "
+ "with gpu."
+ << std::endl;
+ return -1;
+ }
+
+ if (std::atoi(argv[3]) == 0) {
+ CpuInfer(argv[1], argv[2]);
+ } else if (std::atoi(argv[3]) == 1) {
+ GpuInfer(argv[1], argv[2]);
+ } else if(std::atoi(argv[3]) == 2){
+ TrtInfer(argv[1], argv[2]);
+ }
+ return 0;
+}
diff --git a/examples/vision/detection/paddledetection/cpp/infer_yolov6.cc b/examples/vision/detection/paddledetection/cpp/infer_yolov6.cc
new file mode 100644
index 000000000..8b7405ff6
--- /dev/null
+++ b/examples/vision/detection/paddledetection/cpp/infer_yolov6.cc
@@ -0,0 +1,129 @@
+// 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"
+
+#ifdef WIN32
+const char sep = '\\';
+#else
+const char sep = '/';
+#endif
+
+void CpuInfer(const std::string& model_dir, const std::string& image_file) {
+ auto model_file = model_dir + sep + "model.pdmodel";
+ auto params_file = model_dir + sep + "model.pdiparams";
+ auto config_file = model_dir + sep + "infer_cfg.yml";
+ auto option = fastdeploy::RuntimeOption();
+ option.UseCpu();
+ auto model = fastdeploy::vision::detection::PaddleYOLOv6(model_file, params_file,
+ config_file, option);
+ if (!model.Initialized()) {
+ std::cerr << "Failed to initialize." << std::endl;
+ return;
+ }
+
+ auto im = cv::imread(image_file);
+ auto im_bak = im.clone();
+
+ 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_bak, res, 0.5);
+ cv::imwrite("vis_result.jpg", vis_im);
+ std::cout << "Visualized result saved in ./vis_result.jpg" << std::endl;
+}
+
+void GpuInfer(const std::string& model_dir, const std::string& image_file) {
+ auto model_file = model_dir + sep + "model.pdmodel";
+ auto params_file = model_dir + sep + "model.pdiparams";
+ auto config_file = model_dir + sep + "infer_cfg.yml";
+
+ auto option = fastdeploy::RuntimeOption();
+ option.UseGpu();
+ auto model = fastdeploy::vision::detection::PaddleYOLOv6(model_file, params_file,
+ config_file, option);
+ if (!model.Initialized()) {
+ std::cerr << "Failed to initialize." << std::endl;
+ return;
+ }
+
+ auto im = cv::imread(image_file);
+ auto im_bak = im.clone();
+
+ 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_bak, res, 0.5);
+ cv::imwrite("vis_result.jpg", vis_im);
+ std::cout << "Visualized result saved in ./vis_result.jpg" << std::endl;
+}
+
+void TrtInfer(const std::string& model_dir, const std::string& image_file) {
+ auto model_file = model_dir + sep + "model.pdmodel";
+ auto params_file = model_dir + sep + "model.pdiparams";
+ auto config_file = model_dir + sep + "infer_cfg.yml";
+
+ auto option = fastdeploy::RuntimeOption();
+ option.UseGpu();
+ option.UseTrtBackend();
+ auto model = fastdeploy::vision::detection::PaddleYOLOv6(model_file, params_file,
+ config_file, option);
+ if (!model.Initialized()) {
+ std::cerr << "Failed to initialize." << std::endl;
+ return;
+ }
+
+ 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, 0.5);
+ 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 < 4) {
+ std::cout
+ << "Usage: infer_demo path/to/model_dir path/to/image run_option, "
+ "e.g ./infer_model ./ppyolo_dirname ./test.jpeg 0"
+ << std::endl;
+ std::cout << "The data type of run_option is int, 0: run with cpu; 1: run "
+ "with gpu."
+ << std::endl;
+ return -1;
+ }
+
+ if (std::atoi(argv[3]) == 0) {
+ CpuInfer(argv[1], argv[2]);
+ } else if (std::atoi(argv[3]) == 1) {
+ GpuInfer(argv[1], argv[2]);
+ } else if(std::atoi(argv[3]) == 2){
+ TrtInfer(argv[1], argv[2]);
+ }
+ return 0;
+}
diff --git a/examples/vision/detection/paddledetection/cpp/infer_yolov7.cc b/examples/vision/detection/paddledetection/cpp/infer_yolov7.cc
new file mode 100644
index 000000000..e13f5f545
--- /dev/null
+++ b/examples/vision/detection/paddledetection/cpp/infer_yolov7.cc
@@ -0,0 +1,128 @@
+// 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"
+
+#ifdef WIN32
+const char sep = '\\';
+#else
+const char sep = '/';
+#endif
+
+void CpuInfer(const std::string& model_dir, const std::string& image_file) {
+ auto model_file = model_dir + sep + "model.pdmodel";
+ auto params_file = model_dir + sep + "model.pdiparams";
+ auto config_file = model_dir + sep + "infer_cfg.yml";
+ auto option = fastdeploy::RuntimeOption();
+ option.UseCpu();
+ auto model = fastdeploy::vision::detection::PaddleYOLOv7(model_file, params_file,
+ config_file, option);
+ if (!model.Initialized()) {
+ std::cerr << "Failed to initialize." << std::endl;
+ return;
+ }
+
+ auto im = cv::imread(image_file);
+ auto im_bak = im.clone();
+
+ 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_bak, res, 0.5);
+ cv::imwrite("vis_result.jpg", vis_im);
+ std::cout << "Visualized result saved in ./vis_result.jpg" << std::endl;
+}
+
+void GpuInfer(const std::string& model_dir, const std::string& image_file) {
+ auto model_file = model_dir + sep + "model.pdmodel";
+ auto params_file = model_dir + sep + "model.pdiparams";
+ auto config_file = model_dir + sep + "infer_cfg.yml";
+
+ auto option = fastdeploy::RuntimeOption();
+ option.UseGpu();
+ auto model = fastdeploy::vision::detection::PaddleYOLOv7(model_file, params_file,config_file, option);
+ if (!model.Initialized()) {
+ std::cerr << "Failed to initialize." << std::endl;
+ return;
+ }
+
+ auto im = cv::imread(image_file);
+ auto im_bak = im.clone();
+
+ 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_bak, res, 0.5);
+ cv::imwrite("vis_result.jpg", vis_im);
+ std::cout << "Visualized result saved in ./vis_result.jpg" << std::endl;
+}
+
+void TrtInfer(const std::string& model_dir, const std::string& image_file) {
+ auto model_file = model_dir + sep + "model.pdmodel";
+ auto params_file = model_dir + sep + "model.pdiparams";
+ auto config_file = model_dir + sep + "infer_cfg.yml";
+
+ auto option = fastdeploy::RuntimeOption();
+ option.UseGpu();
+ option.UseTrtBackend();
+ auto model = fastdeploy::vision::detection::PaddleYOLOv7(model_file, params_file,
+ config_file, option);
+ if (!model.Initialized()) {
+ std::cerr << "Failed to initialize." << std::endl;
+ return;
+ }
+
+ 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, 0.5);
+ 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 < 4) {
+ std::cout
+ << "Usage: infer_demo path/to/model_dir path/to/image run_option, "
+ "e.g ./infer_model ./ppyolo_dirname ./test.jpeg 0"
+ << std::endl;
+ std::cout << "The data type of run_option is int, 0: run with cpu; 1: run "
+ "with gpu."
+ << std::endl;
+ return -1;
+ }
+
+ if (std::atoi(argv[3]) == 0) {
+ CpuInfer(argv[1], argv[2]);
+ } else if (std::atoi(argv[3]) == 1) {
+ GpuInfer(argv[1], argv[2]);
+ } else if(std::atoi(argv[3]) == 2){
+ TrtInfer(argv[1], argv[2]);
+ }
+ return 0;
+}
diff --git a/examples/vision/detection/paddledetection/python/README.md b/examples/vision/detection/paddledetection/python/README.md
index 7747ca071..993c1695d 100644
--- a/examples/vision/detection/paddledetection/python/README.md
+++ b/examples/vision/detection/paddledetection/python/README.md
@@ -41,6 +41,10 @@ fastdeploy.vision.detection.PPYOLO(model_file, params_file, config_file, runtime
fastdeploy.vision.detection.FasterRCNN(model_file, params_file, config_file, runtime_option=None, model_format=ModelFormat.PADDLE)
fastdeploy.vision.detection.MaskRCNN(model_file, params_file, config_file, runtime_option=None, model_format=ModelFormat.PADDLE)
fastdeploy.vision.detection.SSD(model_file, params_file, config_file, runtime_option=None, model_format=ModelFormat.PADDLE)
+fastdeploy.vision.detection.PaddleYOLOv5(model_file, params_file, config_file, runtime_option=None, model_format=ModelFormat.PADDLE)
+fastdeploy.vision.detection.PaddleYOLOv6(model_file, params_file, config_file, runtime_option=None, model_format=ModelFormat.PADDLE)
+fastdeploy.vision.detection.PaddleYOLOv7(model_file, params_file, config_file, runtime_option=None, model_format=ModelFormat.PADDLE)
+fastdeploy.vision.detection.RTMDet(model_file, params_file, config_file, runtime_option=None, model_format=ModelFormat.PADDLE)
```
PaddleDetection模型加载和初始化,其中model_file, params_file为导出的Paddle部署模型格式, config_file为PaddleDetection同时导出的部署配置yaml文件
diff --git a/examples/vision/detection/paddledetection/python/infer_rtmdet.py b/examples/vision/detection/paddledetection/python/infer_rtmdet.py
new file mode 100644
index 000000000..ec4c6cda8
--- /dev/null
+++ b/examples/vision/detection/paddledetection/python/infer_rtmdet.py
@@ -0,0 +1,59 @@
+import fastdeploy as fd
+import cv2
+import os
+
+
+def parse_arguments():
+ import argparse
+ import ast
+ parser = argparse.ArgumentParser()
+ parser.add_argument(
+ "--model_dir",
+ required=True,
+ help="Path of PaddleDetection model directory")
+ parser.add_argument(
+ "--image", required=True, help="Path of test image file.")
+ parser.add_argument(
+ "--device",
+ type=str,
+ default='cpu',
+ help="Type of inference device, support 'cpu' or 'gpu'.")
+ parser.add_argument(
+ "--use_trt",
+ type=ast.literal_eval,
+ default=False,
+ help="Wether to use tensorrt.")
+ return parser.parse_args()
+
+
+def build_option(args):
+ option = fd.RuntimeOption()
+
+ if args.device.lower() == "gpu":
+ option.use_gpu()
+
+ if args.use_trt:
+ option.use_trt_backend()
+ return option
+
+
+args = parse_arguments()
+
+model_file = os.path.join(args.model_dir, "model.pdmodel")
+params_file = os.path.join(args.model_dir, "model.pdiparams")
+config_file = os.path.join(args.model_dir, "infer_cfg.yml")
+
+# 配置runtime,加载模型
+runtime_option = build_option(args)
+model = fd.vision.detection.RTMDet(
+ model_file, params_file, config_file, runtime_option=runtime_option)
+
+# 预测图片检测结果
+im = cv2.imread(args.image)
+result = model.predict(im.copy())
+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")
diff --git a/examples/vision/detection/paddledetection/python/infer_yolov5.py b/examples/vision/detection/paddledetection/python/infer_yolov5.py
new file mode 100644
index 000000000..ea6c764e2
--- /dev/null
+++ b/examples/vision/detection/paddledetection/python/infer_yolov5.py
@@ -0,0 +1,59 @@
+import fastdeploy as fd
+import cv2
+import os
+
+
+def parse_arguments():
+ import argparse
+ import ast
+ parser = argparse.ArgumentParser()
+ parser.add_argument(
+ "--model_dir",
+ required=True,
+ help="Path of PaddleDetection model directory")
+ parser.add_argument(
+ "--image", required=True, help="Path of test image file.")
+ parser.add_argument(
+ "--device",
+ type=str,
+ default='cpu',
+ help="Type of inference device, support 'cpu' or 'gpu'.")
+ parser.add_argument(
+ "--use_trt",
+ type=ast.literal_eval,
+ default=False,
+ help="Wether to use tensorrt.")
+ return parser.parse_args()
+
+
+def build_option(args):
+ option = fd.RuntimeOption()
+
+ if args.device.lower() == "gpu":
+ option.use_gpu()
+
+ if args.use_trt:
+ option.use_trt_backend()
+ return option
+
+
+args = parse_arguments()
+
+model_file = os.path.join(args.model_dir, "model.pdmodel")
+params_file = os.path.join(args.model_dir, "model.pdiparams")
+config_file = os.path.join(args.model_dir, "infer_cfg.yml")
+
+# 配置runtime,加载模型
+runtime_option = build_option(args)
+model = fd.vision.detection.PaddleYOLOv5(
+ model_file, params_file, config_file, runtime_option=runtime_option)
+
+# 预测图片检测结果
+im = cv2.imread(args.image)
+result = model.predict(im.copy())
+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")
diff --git a/examples/vision/detection/paddledetection/python/infer_yolov6.py b/examples/vision/detection/paddledetection/python/infer_yolov6.py
new file mode 100644
index 000000000..81dfab331
--- /dev/null
+++ b/examples/vision/detection/paddledetection/python/infer_yolov6.py
@@ -0,0 +1,59 @@
+import fastdeploy as fd
+import cv2
+import os
+
+
+def parse_arguments():
+ import argparse
+ import ast
+ parser = argparse.ArgumentParser()
+ parser.add_argument(
+ "--model_dir",
+ required=True,
+ help="Path of PaddleDetection model directory")
+ parser.add_argument(
+ "--image", required=True, help="Path of test image file.")
+ parser.add_argument(
+ "--device",
+ type=str,
+ default='cpu',
+ help="Type of inference device, support 'cpu' or 'gpu'.")
+ parser.add_argument(
+ "--use_trt",
+ type=ast.literal_eval,
+ default=False,
+ help="Wether to use tensorrt.")
+ return parser.parse_args()
+
+
+def build_option(args):
+ option = fd.RuntimeOption()
+
+ if args.device.lower() == "gpu":
+ option.use_gpu()
+
+ if args.use_trt:
+ option.use_trt_backend()
+ return option
+
+
+args = parse_arguments()
+
+model_file = os.path.join(args.model_dir, "model.pdmodel")
+params_file = os.path.join(args.model_dir, "model.pdiparams")
+config_file = os.path.join(args.model_dir, "infer_cfg.yml")
+
+# 配置runtime,加载模型
+runtime_option = build_option(args)
+model = fd.vision.detection.PaddleYOLOv6(
+ model_file, params_file, config_file, runtime_option=runtime_option)
+
+# 预测图片检测结果
+im = cv2.imread(args.image)
+result = model.predict(im.copy())
+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")
diff --git a/examples/vision/detection/paddledetection/python/infer_yolov7.py b/examples/vision/detection/paddledetection/python/infer_yolov7.py
new file mode 100644
index 000000000..d06332e02
--- /dev/null
+++ b/examples/vision/detection/paddledetection/python/infer_yolov7.py
@@ -0,0 +1,59 @@
+import fastdeploy as fd
+import cv2
+import os
+
+
+def parse_arguments():
+ import argparse
+ import ast
+ parser = argparse.ArgumentParser()
+ parser.add_argument(
+ "--model_dir",
+ required=True,
+ help="Path of PaddleDetection model directory")
+ parser.add_argument(
+ "--image", required=True, help="Path of test image file.")
+ parser.add_argument(
+ "--device",
+ type=str,
+ default='cpu',
+ help="Type of inference device, support 'cpu' or 'gpu'.")
+ parser.add_argument(
+ "--use_trt",
+ type=ast.literal_eval,
+ default=False,
+ help="Wether to use tensorrt.")
+ return parser.parse_args()
+
+
+def build_option(args):
+ option = fd.RuntimeOption()
+
+ if args.device.lower() == "gpu":
+ option.use_gpu()
+
+ if args.use_trt:
+ option.use_trt_backend()
+ return option
+
+
+args = parse_arguments()
+
+model_file = os.path.join(args.model_dir, "model.pdmodel")
+params_file = os.path.join(args.model_dir, "model.pdiparams")
+config_file = os.path.join(args.model_dir, "infer_cfg.yml")
+
+# 配置runtime,加载模型
+runtime_option = build_option(args)
+model = fd.vision.detection.PaddleYOLOv7(
+ model_file, params_file, config_file, runtime_option=runtime_option)
+
+# 预测图片检测结果
+im = cv2.imread(args.image)
+result = model.predict(im.copy())
+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")
diff --git a/fastdeploy/vision/detection/ppdet/model.h b/fastdeploy/vision/detection/ppdet/model.h
index 44f574435..5175bc4e6 100755
--- a/fastdeploy/vision/detection/ppdet/model.h
+++ b/fastdeploy/vision/detection/ppdet/model.h
@@ -177,6 +177,70 @@ class FASTDEPLOY_DECL SSD : public PPDetBase {
virtual std::string ModelName() const { return "PaddleDetection/SSD"; }
};
+class FASTDEPLOY_DECL PaddleYOLOv5 : public PPDetBase {
+ public:
+ PaddleYOLOv5(const std::string& model_file, const std::string& params_file,
+ const std::string& config_file,
+ const RuntimeOption& custom_option = RuntimeOption(),
+ const ModelFormat& model_format = ModelFormat::PADDLE)
+ : PPDetBase(model_file, params_file, config_file, custom_option,
+ model_format) {
+ valid_cpu_backends = {Backend::ORT,Backend::PDINFER};
+ valid_gpu_backends = {Backend::ORT, Backend::PDINFER, Backend::TRT};
+ initialized = Initialize();
+ }
+
+ virtual std::string ModelName() const { return "PaddleDetection/YOLOv5"; }
+};
+
+class FASTDEPLOY_DECL PaddleYOLOv6 : public PPDetBase {
+ public:
+ PaddleYOLOv6(const std::string& model_file, const std::string& params_file,
+ const std::string& config_file,
+ const RuntimeOption& custom_option = RuntimeOption(),
+ const ModelFormat& model_format = ModelFormat::PADDLE)
+ : PPDetBase(model_file, params_file, config_file, custom_option,
+ model_format) {
+ valid_cpu_backends = {Backend::OPENVINO, Backend::ORT,Backend::PDINFER};
+ valid_gpu_backends = {Backend::ORT, Backend::PDINFER, Backend::TRT};
+ initialized = Initialize();
+ }
+
+ virtual std::string ModelName() const { return "PaddleDetection/YOLOv6"; }
+};
+
+class FASTDEPLOY_DECL PaddleYOLOv7 : public PPDetBase {
+ public:
+ PaddleYOLOv7(const std::string& model_file, const std::string& params_file,
+ const std::string& config_file,
+ const RuntimeOption& custom_option = RuntimeOption(),
+ const ModelFormat& model_format = ModelFormat::PADDLE)
+ : PPDetBase(model_file, params_file, config_file, custom_option,
+ model_format) {
+ valid_cpu_backends = {Backend::ORT,Backend::PDINFER};
+ valid_gpu_backends = {Backend::ORT, Backend::PDINFER, Backend::TRT};
+ initialized = Initialize();
+ }
+
+ virtual std::string ModelName() const { return "PaddleDetection/YOLOv7"; }
+};
+
+class FASTDEPLOY_DECL RTMDet : public PPDetBase {
+ public:
+ RTMDet(const std::string& model_file, const std::string& params_file,
+ const std::string& config_file,
+ const RuntimeOption& custom_option = RuntimeOption(),
+ const ModelFormat& model_format = ModelFormat::PADDLE)
+ : PPDetBase(model_file, params_file, config_file, custom_option,
+ model_format) {
+ valid_cpu_backends = {Backend::OPENVINO, Backend::ORT, Backend::PDINFER};
+ valid_gpu_backends = {Backend::ORT, Backend::PDINFER, Backend::TRT};
+ initialized = Initialize();
+ }
+
+ virtual std::string ModelName() const { return "PaddleDetection/RTMDet"; }
+};
+
} // namespace detection
} // namespace vision
} // namespace fastdeploy
diff --git a/fastdeploy/vision/detection/ppdet/ppdet_pybind.cc b/fastdeploy/vision/detection/ppdet/ppdet_pybind.cc
index e55561cdc..09c89dfce 100644
--- a/fastdeploy/vision/detection/ppdet/ppdet_pybind.cc
+++ b/fastdeploy/vision/detection/ppdet/ppdet_pybind.cc
@@ -115,5 +115,21 @@ void BindPPDet(pybind11::module& m) {
pybind11::class_(m, "SSD")
.def(pybind11::init());
+
+ pybind11::class_(m, "PaddleYOLOv5")
+ .def(pybind11::init());
+
+ pybind11::class_(m, "PaddleYOLOv6")
+ .def(pybind11::init());
+
+ pybind11::class_(m, "PaddleYOLOv7")
+ .def(pybind11::init());
+
+ pybind11::class_(m, "RTMDet")
+ .def(pybind11::init());
}
} // namespace fastdeploy
diff --git a/python/fastdeploy/vision/detection/ppdet/__init__.py b/python/fastdeploy/vision/detection/ppdet/__init__.py
index 2e84e8ce0..45734eef0 100644
--- a/python/fastdeploy/vision/detection/ppdet/__init__.py
+++ b/python/fastdeploy/vision/detection/ppdet/__init__.py
@@ -401,3 +401,103 @@ class SSD(PPYOLOE):
clone_model = SSDClone(self._model.clone())
return clone_model
+
+
+class PaddleYOLOv5(PPYOLOE):
+ def __init__(self,
+ model_file,
+ params_file,
+ config_file,
+ runtime_option=None,
+ model_format=ModelFormat.PADDLE):
+ """Load a YOLOv5 model exported by PaddleDetection.
+
+ :param model_file: (str)Path of model file, e.g yolov5/model.pdmodel
+ :param params_file: (str)Path of parameters file, e.g yolov5/model.pdiparams, if the model_fomat is ModelFormat.ONNX, this param will be ignored, can be set as empty string
+ :param config_file: (str)Path of configuration file for deployment, e.g ppyoloe/infer_cfg.yml
+ :param runtime_option: (fastdeploy.RuntimeOption)RuntimeOption for inference this model, if it's None, will use the default backend on CPU
+ :param model_format: (fastdeploy.ModelForamt)Model format of the loaded model
+ """
+
+ super(PPYOLOE, self).__init__(runtime_option)
+
+ assert model_format == ModelFormat.PADDLE, "PaddleYOLOv5 model only support model format of ModelFormat.Paddle now."
+ self._model = C.vision.detection.PaddleYOLOv5(
+ model_file, params_file, config_file, self._runtime_option,
+ model_format)
+ assert self.initialized, "PaddleYOLOv5 model initialize failed."
+
+
+class PaddleYOLOv6(PPYOLOE):
+ def __init__(self,
+ model_file,
+ params_file,
+ config_file,
+ runtime_option=None,
+ model_format=ModelFormat.PADDLE):
+ """Load a YOLOv6 model exported by PaddleDetection.
+
+ :param model_file: (str)Path of model file, e.g yolov6/model.pdmodel
+ :param params_file: (str)Path of parameters file, e.g yolov6/model.pdiparams, if the model_fomat is ModelFormat.ONNX, this param will be ignored, can be set as empty string
+ :param config_file: (str)Path of configuration file for deployment, e.g ppyoloe/infer_cfg.yml
+ :param runtime_option: (fastdeploy.RuntimeOption)RuntimeOption for inference this model, if it's None, will use the default backend on CPU
+ :param model_format: (fastdeploy.ModelForamt)Model format of the loaded model
+ """
+
+ super(PPYOLOE, self).__init__(runtime_option)
+
+ assert model_format == ModelFormat.PADDLE, "PaddleYOLOv6 model only support model format of ModelFormat.Paddle now."
+ self._model = C.vision.detection.PaddleYOLOv6(
+ model_file, params_file, config_file, self._runtime_option,
+ model_format)
+ assert self.initialized, "PaddleYOLOv6 model initialize failed."
+
+
+class PaddleYOLOv7(PPYOLOE):
+ def __init__(self,
+ model_file,
+ params_file,
+ config_file,
+ runtime_option=None,
+ model_format=ModelFormat.PADDLE):
+ """Load a YOLOv7 model exported by PaddleDetection.
+
+ :param model_file: (str)Path of model file, e.g yolov7/model.pdmodel
+ :param params_file: (str)Path of parameters file, e.g yolov7/model.pdiparams, if the model_fomat is ModelFormat.ONNX, this param will be ignored, can be set as empty string
+ :param config_file: (str)Path of configuration file for deployment, e.g ppyoloe/infer_cfg.yml
+ :param runtime_option: (fastdeploy.RuntimeOption)RuntimeOption for inference this model, if it's None, will use the default backend on CPU
+ :param model_format: (fastdeploy.ModelForamt)Model format of the loaded model
+ """
+
+ super(PPYOLOE, self).__init__(runtime_option)
+
+ assert model_format == ModelFormat.PADDLE, "PaddleYOLOv7 model only support model format of ModelFormat.Paddle now."
+ self._model = C.vision.detection.PaddleYOLOv7(
+ model_file, params_file, config_file, self._runtime_option,
+ model_format)
+ assert self.initialized, "PaddleYOLOv7 model initialize failed."
+
+
+class RTMDet(PPYOLOE):
+ def __init__(self,
+ model_file,
+ params_file,
+ config_file,
+ runtime_option=None,
+ model_format=ModelFormat.PADDLE):
+ """Load a RTMDet model exported by PaddleDetection.
+
+ :param model_file: (str)Path of model file, e.g rtmdet/model.pdmodel
+ :param params_file: (str)Path of parameters file, e.g rtmdet/model.pdiparams, if the model_fomat is ModelFormat.ONNX, this param will be ignored, can be set as empty string
+ :param config_file: (str)Path of configuration file for deployment, e.g ppyoloe/infer_cfg.yml
+ :param runtime_option: (fastdeploy.RuntimeOption)RuntimeOption for inference this model, if it's None, will use the default backend on CPU
+ :param model_format: (fastdeploy.ModelForamt)Model format of the loaded model
+ """
+
+ super(PPYOLOE, self).__init__(runtime_option)
+
+ assert model_format == ModelFormat.PADDLE, "RTMDet model only support model format of ModelFormat.Paddle now."
+ self._model = C.vision.detection.RTMDet(
+ model_file, params_file, config_file, self._runtime_option,
+ model_format)
+ assert self.initialized, "RTMDet model initialize failed."
\ No newline at end of file
From e4b1581593e4368100306abf002fb53480239bed Mon Sep 17 00:00:00 2001
From: huangjianhui <852142024@qq.com>
Date: Thu, 15 Dec 2022 14:53:44 +0800
Subject: [PATCH 67/77] [Doc] Update multi_thread docs in tutorials (#886)
* Refactor PaddleSeg with preprocessor && postprocessor
* Fix bugs
* Delete redundancy code
* Modify by comments
* Refactor according to comments
* Add batch evaluation
* Add single test script
* Add ppliteseg single test script && fix eval(raise) error
* fix bug
* Fix evaluation segmentation.py batch predict
* Fix segmentation evaluation bug
* Fix evaluation segmentation bugs
* Update segmentation result docs
* Update old predict api and DisableNormalizeAndPermute
* Update resize segmentation label map with cv::INTER_NEAREST
* Add Model Clone function for PaddleClas && PaddleDet && PaddleSeg
* Add multi thread demo
* Add python model clone function
* Add multi thread python && C++ example
* Fix bug
* Update python && cpp multi_thread examples
* Add cpp && python directory
* Add README.md for examples
* Delete redundant code
* Create README_CN.md
* Rename README_CN.md to README.md
* Update README.md
* Update README.md
Co-authored-by: Jason
---
tutorials/multi_thread/README.md | 96 +++++++++++++++++++++++++
tutorials/multi_thread/cpp/README.md | 66 ++++-------------
tutorials/multi_thread/python/README.md | 83 ++++++++-------------
3 files changed, 136 insertions(+), 109 deletions(-)
create mode 100644 tutorials/multi_thread/README.md
diff --git a/tutorials/multi_thread/README.md b/tutorials/multi_thread/README.md
new file mode 100644
index 000000000..00bc7251c
--- /dev/null
+++ b/tutorials/multi_thread/README.md
@@ -0,0 +1,96 @@
+[English](README.md) | 中文
+
+# FastDeploy模型多线程或多进程预测的使用
+
+FastDeploy针对python和cpp开发者,提供了以下多线程或多进程的示例
+
+- [python多线程以及多进程预测的使用示例](python)
+- [cpp多线程预测的使用示例](cpp)
+
+## 多线程预测时克隆模型
+
+针对一个视觉模型的推理包含3个环节
+- 输入图像,图像经过预处理,最终得到要输入给模型Runtime的Tensor,即preprocess阶段
+- 模型Runtime接收Tensor,进行推理,得到Runtime的输出Tensor,即infer阶段
+- 对Runtime的输出Tensor做后处理,得到最后的结构化信息,如DetectionResult, SegmentationResult等等,即postprocess阶段
+
+针对以上preprocess、infer、postprocess三个阶段,FastDeploy分别抽象出了三个对应的类,即Preprocessor、Runtime、PostProcessor
+
+在多线程调用FastDeploy中的模型进行并行推理的时候,要考虑几个问题
+- Preprocessor、Runtime、Postprocessor三个类能否分别支持并行处理
+- 在支持多线程并发的前提下,能否最大限度的减少内存或显存占用
+
+FastDeploy采用分别拷贝多个对象的方式,进行多线程推理,即每个线程都有一份独立的Preprocessor、Runtime、PostProcessor的实例化的对象。而为了减少内存的占用,对于Runtime的拷贝则采用共享模型权重的方式进行拷贝。因此,虽然复制了多个对象,但对于模型权重和参数在内存或显存中只有一份。
+以此减少拷贝多个对象带来的内存占用。
+
+FastDeploy提供如下接口,来进行模型的clone(以PaddleClas为例)
+
+- Python: `PaddleClasModel.clone()`
+- C++: `PaddleClasModel::Clone()`
+
+
+### Python
+```
+import fastdeploy as fd
+option = fd.RuntimeOption()
+model = fd.vision.classification.PaddleClasModel(model_file,
+ params_file,
+ config_file,
+ runtime_option=option)
+model2 = model.clone()
+im = cv2.imread(image)
+res = model.predict(im)
+```
+
+### C++
+```
+auto model = fastdeploy::vision::classification::PaddleClasModel(model_file,
+ params_file,
+ config_file,
+ option);
+auto model2 = model.Clone();
+auto im = cv::imread(image_file);
+fastdeploy::vision::ClassifyResult res;
+model->Predict(im, &res)
+```
+
+>> **注意**:其他模型类似API接口可查阅[官方C++文档](https://www.paddlepaddle.org.cn/fastdeploy-api-doc/cpp/html/index.html)以及[官方Python文档](https://www.paddlepaddle.org.cn/fastdeploy-api-doc/python/html/index.html)
+
+## Python多线程以及多进程
+
+Python由于语言的限制即GIL锁的存在,在计算密集型的场景下,多线程无法充分利用硬件的性能。因此,Python上提供多进程和多线程两种示例。其异同点如下:
+
+### FastDeploy模型多进程与多线程推理的比较
+
+| | 资源占用 | 计算密集型 | I/O密集型 | 进程或线程间通信 |
+|:-------|:------|:----------|:----------|:----------|
+| 多进程 | 大 | 快 | 快 | 慢|
+| 多线程 | 小 | 慢 | 较快 |快|
+
+>> **注意**:以上分析相对理论,实际上Python针对不同的计算任务也做出了一定的优化,像是numpy类的计算已经可以做到并行计算,同时由于多进程间的result汇总涉及到进程间通信,而且往往有时候很难鉴别该任务是计算密集型还是I/O密集型,所以一切都需要根据任务进行测试而定。
+
+
+## C++多线程
+
+C++的多线程,兼具了占用资源少,速度快的特点。因此,是使用多线程推理的最佳选择
+
+### C++ 多线程Clone与不Clone内存占用对比
+
+硬件:Intel(R) Xeon(R) Gold 6271C CPU @ 2.60GHz
+模型:ResNet50_vd_infer
+后端:CPU OPENVINO后端推理引擎
+
+单进程内初始化多个模型,内存占用
+| 模型数 | model.Clone()后 | Clone后model->predict()后 | 不Clone模型初始化后| 不Clone后model->predict()后 |
+|:--- |:----- |:----- |:----- |:----- |
+|1|322M |325M |322M|325M|
+|2|322M|325M|559M|560M|
+|3|322M|325M|771M|771M|
+
+模型多线程预测内存占用
+| 线程数 | model.Clone()后 | Clone后model->predict()后 | 不Clone模型初始化后| 不Clone后model->predict()后 |
+|:--- |:----- |:----- |:----- |:----- |
+|1|322M |337M |322M|337M|
+|2|322M|343M|548M|566M|
+|3|322M|347M|752M|784M|
+
diff --git a/tutorials/multi_thread/cpp/README.md b/tutorials/multi_thread/cpp/README.md
index 066340467..086d71d86 100644
--- a/tutorials/multi_thread/cpp/README.md
+++ b/tutorials/multi_thread/cpp/README.md
@@ -1,11 +1,11 @@
-# PaddleClas C++部署示例
+# PaddleClas C++多线程部署示例
-本目录下提供`infer.cc`快速完成PaddleClas系列模型在CPU/GPU,以及GPU上通过TensorRT加速部署的示例。
+本目录下提供`multi_thread.cc`快速完成PaddleClas系列模型在CPU/GPU,以及GPU上通过TensorRT加速多线程部署的示例。
在部署前,需确认以下两个步骤
-- 1. 软硬件环境满足要求,参考[FastDeploy环境要求](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md)
-- 2. 根据开发环境,下载预编译部署库和samples代码,参考[FastDeploy预编译库](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md)
+- 1. 软硬件环境满足要求,参考[FastDeploy环境要求](../../../docs/cn/build_and_install/download_prebuilt_libraries.md)
+- 2. 根据开发环境,下载预编译部署库和samples代码,参考[FastDeploy预编译库](../../../docs/cn/build_and_install/download_prebuilt_libraries.md)
以Linux上ResNet50_vd推理为例,在本目录执行如下命令即可完成编译测试,支持此模型需保证FastDeploy版本0.7.0以上(x.x.x>=0.7.0)
@@ -24,56 +24,14 @@ tar -xvf ResNet50_vd_infer.tgz
wget https://gitee.com/paddlepaddle/PaddleClas/raw/release/2.4/deploy/images/ImageNet/ILSVRC2012_val_00000010.jpeg
-# CPU推理
-./infer_demo ResNet50_vd_infer ILSVRC2012_val_00000010.jpeg 0
-# GPU推理
-./infer_demo ResNet50_vd_infer ILSVRC2012_val_00000010.jpeg 1
-# GPU上TensorRT推理
-./infer_demo ResNet50_vd_infer ILSVRC2012_val_00000010.jpeg 2
+# CPU多线程推理
+./infer_demo ResNet50_vd_infer ILSVRC2012_val_00000010.jpeg 0 1
+# GPU多线程推理
+./infer_demo ResNet50_vd_infer ILSVRC2012_val_00000010.jpeg 1 1
+# GPU上TensorRT多线程推理
+./infer_demo ResNet50_vd_infer ILSVRC2012_val_00000010.jpeg 2 1
```
+>> **注意**: 最后一位数字表示线程数
以上命令只适用于Linux或MacOS, Windows下SDK的使用方式请参考:
-- [如何在Windows中使用FastDeploy C++ SDK](../../../../../docs/cn/faq/use_sdk_on_windows.md)
-
-## PaddleClas C++接口
-
-### PaddleClas类
-
-```c++
-fastdeploy::vision::classification::PaddleClasModel(
- const string& model_file,
- const string& params_file,
- const string& config_file,
- const RuntimeOption& runtime_option = RuntimeOption(),
- const ModelFormat& model_format = ModelFormat::PADDLE)
-```
-
-PaddleClas模型加载和初始化,其中model_file, params_file为训练模型导出的Paddle inference文件,具体请参考其文档说明[模型导出](https://github.com/PaddlePaddle/PaddleClas/blob/release/2.4/docs/zh_CN/inference_deployment/export_model.md#2-%E5%88%86%E7%B1%BB%E6%A8%A1%E5%9E%8B%E5%AF%BC%E5%87%BA)
-
-**参数**
-
-> * **model_file**(str): 模型文件路径
-> * **params_file**(str): 参数文件路径
-> * **config_file**(str): 推理部署配置文件
-> * **runtime_option**(RuntimeOption): 后端推理配置,默认为None,即采用默认配置
-> * **model_format**(ModelFormat): 模型格式,默认为Paddle格式
-
-#### Predict函数
-
-> ```c++
-> PaddleClasModel::Predict(cv::Mat* im, ClassifyResult* result, int topk = 1)
-> ```
->
-> 模型预测接口,输入图像直接输出检测结果。
->
-> **参数**
->
-> > * **im**: 输入图像,注意需为HWC,BGR格式
-> > * **result**: 分类结果,包括label_id,以及相应的置信度, ClassifyResult说明参考[视觉模型预测结果](../../../../../docs/api/vision_results/)
-> > * **topk**(int):返回预测概率最高的topk个分类结果,默认为1
-
-
-- [模型介绍](../../)
-- [Python部署](../python)
-- [视觉模型预测结果](../../../../../docs/api/vision_results/)
-- [如何切换模型推理后端引擎](../../../../../docs/cn/faq/how_to_change_backend.md)
+- [如何在Windows中使用FastDeploy C++ SDK](../../../docs/cn/faq/use_sdk_on_windows.md)
\ No newline at end of file
diff --git a/tutorials/multi_thread/python/README.md b/tutorials/multi_thread/python/README.md
index 9d17e6f65..508d5c7e0 100644
--- a/tutorials/multi_thread/python/README.md
+++ b/tutorials/multi_thread/python/README.md
@@ -1,31 +1,45 @@
-# PaddleClas模型 Python部署示例
+# PaddleClas模型 Python多线程/进程部署示例
在部署前,需确认以下两个步骤
-- 1. 软硬件环境满足要求,参考[FastDeploy环境要求](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md)
-- 2. FastDeploy Python whl包安装,参考[FastDeploy Python安装](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md)
+- 1. 软硬件环境满足要求,参考[FastDeploy环境要求](../../../docs/cn/build_and_install/download_prebuilt_libraries.md)
+- 2. FastDeploy Python whl包安装,参考[FastDeploy Python安装](../../../docs/cn/build_and_install/download_prebuilt_libraries.md)
+
+本目录下提供`multi_thread_process.py`快速完成ResNet50_vd在CPU/GPU,以及GPU上通过TensorRT加速部署的多线程/进程示例。执行如下脚本即可完成
-本目录下提供`infer.py`快速完成ResNet50_vd在CPU/GPU,以及GPU上通过TensorRT加速部署的示例。执行如下脚本即可完成
```bash
#下载部署示例代码
git clone https://github.com/PaddlePaddle/FastDeploy.git
-cd FastDeploy/examples/vision/classification/paddleclas/python
+cd FastDeploy/tutorials/multi_thread/python
# 下载ResNet50_vd模型文件和测试图片
wget https://bj.bcebos.com/paddlehub/fastdeploy/ResNet50_vd_infer.tgz
tar -xvf ResNet50_vd_infer.tgz
wget https://gitee.com/paddlepaddle/PaddleClas/raw/release/2.4/deploy/images/ImageNet/ILSVRC2012_val_00000010.jpeg
-# CPU推理
-python infer.py --model ResNet50_vd_infer --image ILSVRC2012_val_00000010.jpeg --device cpu --topk 1
-# GPU推理
-python infer.py --model ResNet50_vd_infer --image ILSVRC2012_val_00000010.jpeg --device gpu --topk 1
-# GPU上使用TensorRT推理 (注意:TensorRT推理第一次运行,有序列化模型的操作,有一定耗时,需要耐心等待)
-python infer.py --model ResNet50_vd_infer --image ILSVRC2012_val_00000010.jpeg --device gpu --use_trt True --topk 1
-# IPU推理(注意:IPU推理首次运行会有序列化模型的操作,有一定耗时,需要耐心等待)
-python infer.py --model ResNet50_vd_infer --image ILSVRC2012_val_00000010.jpeg --device ipu --topk 1
+
+# CPU多线程推理
+python infer.py --model ResNet50_vd_infer --image_path ILSVRC2012_val_00000010.jpeg --device cpu --topk 1 --thread_num 1
+# CPU多进程推理
+python infer.py --model ResNet50_vd_infer --image_path ILSVRC2012_val_00000010.jpeg --device cpu --topk 1 --use_multi_process True --process_num 1
+
+# GPU多线程推理
+python infer.py --model ResNet50_vd_infer --image_path ILSVRC2012_val_00000010.jpeg --device gpu --topk 1 --thread_num 1
+# GPU多进程推理
+python infer.py --model ResNet50_vd_infer --image_path ILSVRC2012_val_00000010.jpeg --device gpu --topk 1 --use_multi_process True --process_num 1
+
+# GPU上使用TensorRT多线程推理 (注意:TensorRT推理第一次运行,有序列化模型的操作,有一定耗时,需要耐心等待)
+python infer.py --model ResNet50_vd_infer --image_path ILSVRC2012_val_00000010.jpeg --device gpu --use_trt True --topk 1 --thread_num 1
+# GPU上使用TensorRT多进程推理 (注意:TensorRT推理第一次运行,有序列化模型的操作,有一定耗时,需要耐心等待)
+python infer.py --model ResNet50_vd_infer --image_path ILSVRC2012_val_00000010.jpeg --device gpu --use_trt True --topk 1 --use_multi_process True --process_num 1
+
+# IPU多线程推理(注意:IPU推理首次运行会有序列化模型的操作,有一定耗时,需要耐心等待)
+python infer.py --model ResNet50_vd_infer --image_path ILSVRC2012_val_00000010.jpeg --device ipu --topk 1 --thread_num 1
+# IPU多进程推理(注意:IPU推理首次运行会有序列化模型的操作,有一定耗时,需要耐心等待)
+python infer.py --model ResNet50_vd_infer --image_path ILSVRC2012_val_00000010.jpeg --device ipu --topk 1 --use_multi_process True --process_num 1
```
+>> **注意**: `--image_path` 可以输入图片文件夹的路径
运行完成后返回结果如下所示
```bash
@@ -33,45 +47,4 @@ ClassifyResult(
label_ids: 153,
scores: 0.686229,
)
-```
-
-## PaddleClasModel Python接口
-
-```python
-fd.vision.classification.PaddleClasModel(model_file, params_file, config_file, runtime_option=None, model_format=ModelFormat.PADDLE)
-```
-
-PaddleClas模型加载和初始化,其中model_file, params_file为训练模型导出的Paddle inference文件,具体请参考其文档说明[模型导出](https://github.com/PaddlePaddle/PaddleClas/blob/release/2.4/docs/zh_CN/inference_deployment/export_model.md#2-%E5%88%86%E7%B1%BB%E6%A8%A1%E5%9E%8B%E5%AF%BC%E5%87%BA)
-
-**参数**
-
-> * **model_file**(str): 模型文件路径
-> * **params_file**(str): 参数文件路径
-> * **config_file**(str): 推理部署配置文件
-> * **runtime_option**(RuntimeOption): 后端推理配置,默认为None,即采用默认配置
-> * **model_format**(ModelFormat): 模型格式,默认为Paddle格式
-
-### predict函数
-
-> ```python
-> PaddleClasModel.predict(input_image, topk=1)
-> ```
->
-> 模型预测结口,输入图像直接输出分类topk结果。
->
-> **参数**
->
-> > * **input_image**(np.ndarray): 输入数据,注意需为HWC,BGR格式
-> > * **topk**(int):返回预测概率最高的topk个分类结果,默认为1
-
-> **返回**
->
-> > 返回`fastdeploy.vision.ClassifyResult`结构体,结构体说明参考文档[视觉模型预测结果](../../../../../docs/api/vision_results/)
-
-
-## 其它文档
-
-- [PaddleClas 模型介绍](..)
-- [PaddleClas C++部署](../cpp)
-- [模型预测结果说明](../../../../../docs/api/vision_results/)
-- [如何切换模型推理后端引擎](../../../../../docs/cn/faq/how_to_change_backend.md)
+```
\ No newline at end of file
From 6e79df40d987236e4bde34eb5a76b41784e32248 Mon Sep 17 00:00:00 2001
From: WJJ1995
Date: Thu, 15 Dec 2022 17:23:27 +0800
Subject: [PATCH 68/77] [Model] Update YOLOv5 from 6.0 to 7.0 version (#890)
* add onnx_ort_runtime demo
* rm in requirements
* support batch eval
* fixed MattingResults bug
* move assignment for DetectionResult
* integrated x2paddle
* add model convert readme
* update readme
* re-lint
* add processor api
* Add MattingResult Free
* change valid_cpu_backends order
* add ppocr benchmark
* mv bs from 64 to 32
* fixed quantize.md
* fixed quantize bugs
* Add Monitor for benchmark
* update mem monitor
* Set trt_max_batch_size default 1
* fixed ocr benchmark bug
* support yolov5 in serving
* Fixed yolov5 serving
* Fixed postprocess
* update yolov5 to 7.0
Co-authored-by: Jason
---
examples/vision/detection/README.md | 2 +-
examples/vision/detection/yolov5/README.md | 20 +++++++++-----------
2 files changed, 10 insertions(+), 12 deletions(-)
diff --git a/examples/vision/detection/README.md b/examples/vision/detection/README.md
index 3273ff602..522a4d79e 100644
--- a/examples/vision/detection/README.md
+++ b/examples/vision/detection/README.md
@@ -12,7 +12,7 @@ FastDeploy目前支持如下目标检测模型部署
| [PaddleDetection/FasterRCNN](./paddledetection) | FasterRCNN系列模型 | Paddle | [Release/2.4](https://github.com/PaddlePaddle/PaddleDetection/tree/release/2.4) |
| [WongKinYiu/YOLOv7](./yolov7) | YOLOv7、YOLOv7-X等系列模型 | ONNX | [Release/v0.1](https://github.com/WongKinYiu/yolov7/tree/v0.1) |
| [RangiLyu/NanoDetPlus](./nanodet_plus) | NanoDetPlus 系列模型 | ONNX | [Release/v1.0.0-alpha-1](https://github.com/RangiLyu/nanodet/tree/v1.0.0-alpha-1) |
-| [ultralytics/YOLOv5](./yolov5) | YOLOv5 系列模型 | ONNX | [Release/v6.0](https://github.com/ultralytics/yolov5/tree/v6.0) |
+| [ultralytics/YOLOv5](./yolov5) | YOLOv5 系列模型 | ONNX | [Release/v7.0](https://github.com/ultralytics/yolov5/tree/v7.0) |
| [ppogg/YOLOv5-Lite](./yolov5lite) | YOLOv5-Lite 系列模型 | ONNX | [Release/v1.4](https://github.com/ppogg/YOLOv5-Lite/releases/tag/v1.4) |
| [meituan/YOLOv6](./yolov6) | YOLOv6 系列模型 | ONNX | [Release/0.1.0](https://github.com/meituan/YOLOv6/releases/tag/0.1.0) |
| [WongKinYiu/YOLOR](./yolor) | YOLOR 系列模型 | ONNX | [Release/weights](https://github.com/WongKinYiu/yolor/releases/tag/weights) |
diff --git a/examples/vision/detection/yolov5/README.md b/examples/vision/detection/yolov5/README.md
index 076ae01ce..095c8071d 100644
--- a/examples/vision/detection/yolov5/README.md
+++ b/examples/vision/detection/yolov5/README.md
@@ -1,8 +1,8 @@
# YOLOv5准备部署模型
-- YOLOv5 v6.0部署模型实现来自[YOLOv5](https://github.com/ultralytics/yolov5/tree/v6.0),和[基于COCO的预训练模型](https://github.com/ultralytics/yolov5/releases/tag/v6.0)
- - (1)[官方库](https://github.com/ultralytics/yolov5/releases/tag/v6.0)提供的*.onnx可直接进行部署;
- - (2)开发者基于自己数据训练的YOLOv5 v6.0模型,可使用[YOLOv5](https://github.com/ultralytics/yolov5)中的`export.py`导出ONNX文件后,完成部署。
+- YOLOv5 v7.0部署模型实现来自[YOLOv5](https://github.com/ultralytics/yolov5/tree/v7.0),和[基于COCO的预训练模型](https://github.com/ultralytics/yolov5/releases/tag/v7.0)
+ - (1)[官方库](https://github.com/ultralytics/yolov5/releases/tag/v7.0)提供的*.onnx可直接进行部署;
+ - (2)开发者基于自己数据训练的YOLOv5 v7.0模型,可使用[YOLOv5](https://github.com/ultralytics/yolov5)中的`export.py`导出ONNX文件后,完成部署。
## 下载预训练ONNX模型
@@ -10,13 +10,11 @@
为了方便开发者的测试,下面提供了YOLOv5导出的各系列模型,开发者可直接下载使用。(下表中模型的精度来源于源官方库)
| 模型 | 大小 | 精度 |
|:---------------------------------------------------------------- |:----- |:----- |
-| [YOLOv5n](https://bj.bcebos.com/paddlehub/fastdeploy/yolov5n.onnx) | 7.5MB | 28.4% |
-| [YOLOv5s](https://bj.bcebos.com/paddlehub/fastdeploy/yolov5s.onnx) | 28.9MB | 37.2% |
-| [YOLOv5m](https://bj.bcebos.com/paddlehub/fastdeploy/yolov5m.onnx) | 84.7MB | 45.2% |
-| [YOLOv5l](https://bj.bcebos.com/paddlehub/fastdeploy/yolov5l.onnx) | 186.2MB | 48.8% |
-| [YOLOv5x](https://bj.bcebos.com/paddlehub/fastdeploy/yolov5x.onnx) | 346.9MB | 50.7% |
-
-
+| [YOLOv5n](https://bj.bcebos.com/paddlehub/fastdeploy/yolov5n.onnx) | 7.6MB | 28.0% |
+| [YOLOv5s](https://bj.bcebos.com/paddlehub/fastdeploy/yolov5s.onnx) | 28MB | 37.4% |
+| [YOLOv5m](https://bj.bcebos.com/paddlehub/fastdeploy/yolov5m.onnx) | 82MB | 45.4% |
+| [YOLOv5l](https://bj.bcebos.com/paddlehub/fastdeploy/yolov5l.onnx) | 178MB | 49.0% |
+| [YOLOv5x](https://bj.bcebos.com/paddlehub/fastdeploy/yolov5x.onnx) | 332MB | 50.7% |
## 详细部署文档
@@ -27,4 +25,4 @@
## 版本说明
-- 本版本文档和代码基于[YOLOv5 v6.0](https://github.com/ultralytics/yolov5/tree/v6.0) 编写
+- 本版本文档和代码基于[YOLOv5 v7.0](https://github.com/ultralytics/yolov5/tree/v7.0) 编写
From 5be839b322b6adf46329933361b22b4984c42ef8 Mon Sep 17 00:00:00 2001
From: yeliang2258 <30516196+yeliang2258@users.noreply.github.com>
Date: Thu, 15 Dec 2022 21:17:14 +0800
Subject: [PATCH 69/77] [Backend] Add KunlunXin XPU deploy support (#747)
* add xpu support
* fix docs
* update code
* update doc
* update code
* update yolov5
* update cmake
* add int64_t data support
* fix
* update download links
* add en doc
* update code
* update xpu options
* update doc
* update doc
* update doc
* update lib links
* update doc
* update code
* update lite xpu link
* update xpu lib
* update doc
* update en doc
---
CMakeLists.txt | 20 ++-
FastDeploy.cmake.in | 5 +
cmake/summary.cmake | 2 +
docs/README_CN.md | 1 +
docs/README_EN.md | 5 +-
docs/cn/build_and_install/README.md | 8 +-
docs/cn/build_and_install/a311d.md | 3 +-
docs/cn/build_and_install/rv1126.md | 7 +-
docs/cn/build_and_install/xpu.md | 75 +++++++++
docs/en/build_and_install/README.md | 5 +
docs/en/build_and_install/a311d.md | 105 ++++++++++++
docs/en/build_and_install/rv1126.md | 105 ++++++++++++
docs/en/build_and_install/xpu.md | 78 +++++++++
.../classification/paddleclas/cpp/README.md | 4 +
.../classification/paddleclas/cpp/infer.cc | 30 +++-
.../paddleclas/python/README.md | 2 +
.../classification/paddleclas/python/infer.py | 3 +
.../detection/yolov5/cpp/CMakeLists.txt | 4 +
.../vision/detection/yolov5/cpp/README.md | 24 ++-
examples/vision/detection/yolov5/cpp/infer.cc | 2 +-
.../yolov5/cpp/infer_paddle_model.cc | 154 ++++++++++++++++++
.../vision/detection/yolov5/python/README.md | 11 +-
.../vision/detection/yolov5/python/infer.py | 21 ++-
fastdeploy/backends/lite/lite_backend.cc | 56 +++++--
fastdeploy/backends/lite/lite_backend.h | 9 +
fastdeploy/core/fd_type.cc | 6 +
fastdeploy/core/fd_type.h | 2 +-
fastdeploy/fastdeploy_model.cc | 33 +++-
fastdeploy/fastdeploy_model.h | 4 +
fastdeploy/pybind/runtime.cc | 17 +-
fastdeploy/runtime.cc | 35 +++-
fastdeploy/runtime.h | 41 +++++
.../vision/classification/ppcls/model.cc | 1 +
.../detection/contrib/rknpu2/postprocessor.h | 5 +-
.../vision/detection/contrib/rknpu2/utils.h | 2 +-
.../vision/detection/contrib/yolov5/yolov5.cc | 1 +
fastdeploy/vision/detection/ppdet/model.h | 6 +-
python/fastdeploy/runtime.py | 28 ++++
python/setup.py | 8 +-
39 files changed, 870 insertions(+), 58 deletions(-)
mode change 100644 => 100755 docs/README_CN.md
mode change 100644 => 100755 docs/README_EN.md
create mode 100755 docs/cn/build_and_install/xpu.md
mode change 100644 => 100755 docs/en/build_and_install/README.md
create mode 100755 docs/en/build_and_install/a311d.md
create mode 100755 docs/en/build_and_install/rv1126.md
create mode 100755 docs/en/build_and_install/xpu.md
mode change 100644 => 100755 examples/vision/classification/paddleclas/cpp/README.md
mode change 100644 => 100755 examples/vision/classification/paddleclas/cpp/infer.cc
mode change 100644 => 100755 examples/vision/classification/paddleclas/python/README.md
mode change 100644 => 100755 examples/vision/classification/paddleclas/python/infer.py
mode change 100644 => 100755 examples/vision/detection/yolov5/cpp/CMakeLists.txt
mode change 100644 => 100755 examples/vision/detection/yolov5/cpp/README.md
mode change 100644 => 100755 examples/vision/detection/yolov5/cpp/infer.cc
create mode 100755 examples/vision/detection/yolov5/cpp/infer_paddle_model.cc
mode change 100644 => 100755 examples/vision/detection/yolov5/python/README.md
mode change 100644 => 100755 examples/vision/detection/yolov5/python/infer.py
mode change 100644 => 100755 fastdeploy/pybind/runtime.cc
mode change 100644 => 100755 fastdeploy/runtime.cc
diff --git a/CMakeLists.txt b/CMakeLists.txt
index c02e887a5..0bcfa4084 100755
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -40,7 +40,7 @@ if(NOT MSVC)
add_definitions(-D_GLIBCXX_USE_CXX11_ABI=1)
endif(NOT MSVC)
-if(UNIX AND (NOT APPLE) AND (NOT ANDROID) AND (NOT ENABLE_TIMVX))
+if(UNIX AND (NOT APPLE) AND (NOT ANDROID) AND (NOT WITH_TIMVX))
include(${PROJECT_SOURCE_DIR}/cmake/patchelf.cmake)
endif()
@@ -64,7 +64,8 @@ option(ENABLE_LITE_BACKEND "Whether to enable paddle lite backend." OFF)
option(ENABLE_VISION "Whether to enable vision models usage." OFF)
option(ENABLE_TEXT "Whether to enable text models usage." OFF)
option(ENABLE_FLYCV "Whether to enable flycv to boost image preprocess." OFF)
-option(ENABLE_TIMVX "Whether to compile for TIMVX deploy." OFF)
+option(WITH_TIMVX "Whether to compile for TIMVX deploy." OFF)
+option(WITH_XPU "Whether to compile for KunlunXin XPU deploy." OFF)
option(WITH_TESTING "Whether to compile with unittest." OFF)
############################# Options for Android cross compiling #########################
option(WITH_OPENCV_STATIC "Use OpenCV static lib for Android." OFF)
@@ -138,10 +139,23 @@ set(HEAD_DIR "${PROJECT_SOURCE_DIR}/${CSRCS_DIR_NAME}")
include_directories(${HEAD_DIR})
include_directories(${CMAKE_CURRENT_BINARY_DIR})
-if (ENABLE_TIMVX)
+if (WITH_TIMVX)
include(${PROJECT_SOURCE_DIR}/cmake/timvx.cmake)
endif()
+if (WITH_XPU)
+ if(NOT ENABLE_LITE_BACKEND)
+ message(WARNING "While compiling with -DWITH_XPU=ON, will force to set -DENABLE_LITE_BACKEND=ON")
+ set(ENABLE_LITE_BACKEND ON)
+ endif()
+ if(NOT CMAKE_HOST_SYSTEM_PROCESSOR MATCHES "x86_64")
+ message(FATAL_ERROR "XPU is only supported on Linux x64 platform")
+ endif()
+ if(NOT PADDLELITE_URL)
+ set(PADDLELITE_URL "https://bj.bcebos.com/fastdeploy/third_libs/lite-linux-x64-xpu-20221215.tgz")
+ endif()
+endif()
+
if(ANDROID OR IOS)
if(ENABLE_ORT_BACKEND)
diff --git a/FastDeploy.cmake.in b/FastDeploy.cmake.in
index fd0ea847a..d8c0df3d6 100755
--- a/FastDeploy.cmake.in
+++ b/FastDeploy.cmake.in
@@ -27,6 +27,7 @@ set(OPENCV_DIRECTORY "@OPENCV_DIRECTORY@")
set(ORT_DIRECTORY "@ORT_DIRECTORY@")
set(OPENVINO_DIRECTORY "@OPENVINO_DIRECTORY@")
set(RKNN2_TARGET_SOC "@RKNN2_TARGET_SOC@")
+set(WITH_XPU @WITH_XPU@)
set(FASTDEPLOY_LIBS "")
set(FASTDEPLOY_INCS "")
@@ -237,6 +238,10 @@ if(ENABLE_PADDLE_FRONTEND)
list(APPEND FASTDEPLOY_LIBS ${PADDLE2ONNX_LIB})
endif()
+if(WITH_XPU)
+ list(APPEND FASTDEPLOY_LIBS -lpthread -lrt -ldl)
+endif()
+
remove_duplicate_libraries(FASTDEPLOY_LIBS)
# Print compiler information
diff --git a/cmake/summary.cmake b/cmake/summary.cmake
index 7a729484e..fc5c246ba 100755
--- a/cmake/summary.cmake
+++ b/cmake/summary.cmake
@@ -37,6 +37,8 @@ function(fastdeploy_summary)
message(STATUS " ENABLE_POROS_BACKEND : ${ENABLE_POROS_BACKEND}")
message(STATUS " ENABLE_TRT_BACKEND : ${ENABLE_TRT_BACKEND}")
message(STATUS " ENABLE_OPENVINO_BACKEND : ${ENABLE_OPENVINO_BACKEND}")
+ message(STATUS " WITH_TIMVX : ${WITH_TIMVX}")
+ message(STATUS " WITH_XPU : ${WITH_XPU}")
if(ENABLE_ORT_BACKEND)
message(STATUS " ONNXRuntime version : ${ONNXRUNTIME_VERSION}")
endif()
diff --git a/docs/README_CN.md b/docs/README_CN.md
old mode 100644
new mode 100755
index a0b7b51d0..ec0267f45
--- a/docs/README_CN.md
+++ b/docs/README_CN.md
@@ -8,6 +8,7 @@
- [GPU部署环境编译安装](cn/build_and_install/gpu.md)
- [CPU部署环境编译安装](cn/build_and_install/cpu.md)
- [IPU部署环境编译安装](cn/build_and_install/ipu.md)
+- [昆仑芯XPU部署环境编译安装](cn/build_and_install/xpu.md)
- [Jetson部署环境编译安装](cn/build_and_install/jetson.md)
- [Android平台部署环境编译安装](cn/build_and_install/android.md)
- [服务化部署镜像编译安装](../serving/docs/zh_CN/compile.md)
diff --git a/docs/README_EN.md b/docs/README_EN.md
old mode 100644
new mode 100755
index c4f9adfa3..ed257c59b
--- a/docs/README_EN.md
+++ b/docs/README_EN.md
@@ -8,6 +8,7 @@
- [Build and Install FastDeploy Library on GPU Platform](en/build_and_install/gpu.md)
- [Build and Install FastDeploy Library on CPU Platform](en/build_and_install/cpu.md)
- [Build and Install FastDeploy Library on IPU Platform](en/build_and_install/ipu.md)
+- [Build and Install FastDeploy Library on KunlunXin XPU Platform](en/build_and_install/xpu.md)
- [Build and Install FastDeploy Library on Nvidia Jetson Platform](en/build_and_install/jetson.md)
- [Build and Install FastDeploy Library on Android Platform](en/build_and_install/android.md)
- [Build and Install FastDeploy Serving Deployment Image](../serving/docs/EN/compile-en.md)
@@ -19,10 +20,10 @@
- [A Quick Start on Runtime Python](en/quick_start/runtime/python.md)
- [A Quick Start on Runtime C++](en/quick_start/runtime/cpp.md)
-## API
+## API
- [Python API](https://baidu-paddle.github.io/fastdeploy-api/python/html/)
-- [C++ API](https://baidu-paddle.github.io/fastdeploy-api/cpp/html/)
+- [C++ API](https://baidu-paddle.github.io/fastdeploy-api/cpp/html/)
- [Android Java API](../java/android)
## Performance Optimization
diff --git a/docs/cn/build_and_install/README.md b/docs/cn/build_and_install/README.md
index 7ec07c7b8..221852d2c 100755
--- a/docs/cn/build_and_install/README.md
+++ b/docs/cn/build_and_install/README.md
@@ -13,6 +13,7 @@
- [Android平台部署环境](android.md)
- [瑞芯微RV1126部署环境](rv1126.md)
- [晶晨A311D部署环境](a311d.md)
+- [昆仑芯XPU部署环境](xpu.md)
## FastDeploy编译选项说明
@@ -20,10 +21,11 @@
| 选项 | 说明 |
|:------------------------|:--------------------------------------------------------------------------|
| ENABLE_ORT_BACKEND | 默认OFF, 是否编译集成ONNX Runtime后端(CPU/GPU上推荐打开) |
-| ENABLE_PADDLE_BACKEND | 默认OFF,是否编译集成Paddle Inference后端(CPU/GPU上推荐打开) |
-| ENABLE_LITE_BACKEND | 默认OFF,是否编译集成Paddle Lite后端(编译Android库时需要设置为ON) |
+| ENABLE_PADDLE_BACKEND | 默认OFF,是否编译集成Paddle Inference后端(CPU/GPU上推荐打开) |
+| ENABLE_LITE_BACKEND | 默认OFF,是否编译集成Paddle Lite后端(编译Android库时需要设置为ON) |
| ENABLE_RKNPU2_BACKEND | 默认OFF,是否编译集成RKNPU2后端(RK3588/RK3568/RK3566上推荐打开) |
-| WITH_TIMVX | 默认OFF,需要在RV1126/RV1109/A311D上部署时,需设置为ON |
+| WITH_XPU | 默认OFF,当在昆仑芯XPU上部署时,需设置为ON |
+| WITH_TIMVX | 默认OFF,需要在RV1126/RV1109/A311D上部署时,需设置为ON |
| ENABLE_TRT_BACKEND | 默认OFF,是否编译集成TensorRT后端(GPU上推荐打开) |
| ENABLE_OPENVINO_BACKEND | 默认OFF,是否编译集成OpenVINO后端(CPU上推荐打开) |
| ENABLE_VISION | 默认OFF,是否编译集成视觉模型的部署模块 |
diff --git a/docs/cn/build_and_install/a311d.md b/docs/cn/build_and_install/a311d.md
index 4b3773f0d..20dde7046 100755
--- a/docs/cn/build_and_install/a311d.md
+++ b/docs/cn/build_and_install/a311d.md
@@ -9,7 +9,8 @@ FastDeploy 基于 Paddle-Lite 后端支持在晶晨 NPU 上进行部署推理。
|编译选项|默认值|说明|备注|
|:---|:---|:---|:---|
|ENABLE_LITE_BACKEND|OFF|编译A311D部署库时需要设置为ON| - |
-|WITH_TIMVX|OFF|编译A311D部署库时需要设置为ON| - |
+|WITH_TIMVX|OFF|编译A311D部署库时需要设置为ON| - |
+|TARGET_ABI|NONE|编译RK库时需要设置为arm64| - |
更多编译选项请参考[FastDeploy编译选项说明](./README.md)
diff --git a/docs/cn/build_and_install/rv1126.md b/docs/cn/build_and_install/rv1126.md
index ff0050715..f3643f070 100755
--- a/docs/cn/build_and_install/rv1126.md
+++ b/docs/cn/build_and_install/rv1126.md
@@ -8,8 +8,9 @@ FastDeploy基于 Paddle-Lite 后端支持在瑞芯微(Rockchip)Soc 上进行
相关编译选项说明如下:
|编译选项|默认值|说明|备注|
|:---|:---|:---|:---|
-|ENABLE_LITE_BACKEND|OFF|编译RK库时需要设置为ON| - |
-|WITH_TIMVX|OFF|编译RK库时需要设置为ON| - |
+|ENABLE_LITE_BACKEND|OFF|编译RK库时需要设置为ON| - |
+|WITH_TIMVX|OFF|编译RK库时需要设置为ON| - |
+|TARGET_ABI|NONE|编译RK库时需要设置为armhf| - |
更多编译选项请参考[FastDeploy编译选项说明](./README.md)
@@ -86,7 +87,7 @@ dmesg | grep Galcore
wget https://paddlelite-demo.bj.bcebos.com/devices/generic/PaddleLite-generic-demo.tar.gz
tar -xf PaddleLite-generic-demo.tar.gz
```
-2. 使用 `uname -a` 查看 `Linux Kernel` 版本,确定为 `Linux` 系统 4.19.111 版本,
+2. 使用 `uname -a` 查看 `Linux Kernel` 版本,确定为 `Linux` 系统 4.19.111 版本
3. 将 `PaddleLite-generic-demo/libs/PaddleLite/linux/armhf/lib/verisilicon_timvx/viv_sdk_6_4_6_5/lib/1126/4.19.111/` 路径下的 `galcore.ko` 上传至开发板。
4. 登录开发板,命令行输入 `sudo rmmod galcore` 来卸载原始驱动,输入 `sudo insmod galcore.ko` 来加载传上设备的驱动。(是否需要 sudo 根据开发板实际情况,部分 adb 链接的设备请提前 adb root)。此步骤如果操作失败,请跳转至方法 2。
diff --git a/docs/cn/build_and_install/xpu.md b/docs/cn/build_and_install/xpu.md
new file mode 100755
index 000000000..014eb804d
--- /dev/null
+++ b/docs/cn/build_and_install/xpu.md
@@ -0,0 +1,75 @@
+# 昆仑芯 XPU 部署环境编译安装
+
+FastDeploy 基于 Paddle-Lite 后端支持在昆仑芯 XPU 上进行部署推理。
+更多详细的信息请参考:[PaddleLite部署示例](https://www.paddlepaddle.org.cn/lite/develop/demo_guides/kunlunxin_xpu.html#xpu)。
+
+本文档介绍如何编译基于 PaddleLite 的 C++ FastDeploy 编译库。
+
+相关编译选项说明如下:
+|编译选项|默认值|说明|备注|
+|:---|:---|:---|:---|
+| WITH_XPU| OFF | 需要在XPU上部署时需要设置为ON | - |
+| ENABLE_ORT_BACKEND | OFF | 是否编译集成ONNX Runtime后端 | - |
+| ENABLE_PADDLE_BACKEND | OFF | 是否编译集成Paddle Inference后端 | - |
+| ENABLE_OPENVINO_BACKEND | OFF | 是否编译集成OpenVINO后端 | - |
+| ENABLE_VISION | OFF | 是否编译集成视觉模型的部署模块 | - |
+| ENABLE_TEXT | OFF | 是否编译集成文本NLP模型的部署模块 | - |
+
+第三方库依赖指定(不设定如下参数,会自动下载预编译库)
+| 选项 | 说明 |
+| :---------------------- | :--------------------------------------------------------------------------------------------- |
+| ORT_DIRECTORY | 当开启ONNX Runtime后端时,用于指定用户本地的ONNX Runtime库路径;如果不指定,编译过程会自动下载ONNX Runtime库 |
+| OPENCV_DIRECTORY | 当ENABLE_VISION=ON时,用于指定用户本地的OpenCV库路径;如果不指定,编译过程会自动下载OpenCV库 |
+| OPENVINO_DIRECTORY | 当开启OpenVINO后端时, 用于指定用户本地的OpenVINO库路径;如果不指定,编译过程会自动下载OpenVINO库 |
+更多编译选项请参考[FastDeploy编译选项说明](./README.md)
+
+## 基于 PaddleLite 的 C++ FastDeploy 库编译
+- OS: Linux
+- gcc/g++: version >= 8.2
+- cmake: version >= 3.15
+此外更推荐开发者自行安装,编译时通过`-DOPENCV_DIRECTORY`来指定环境中的OpenCV(如若不指定-DOPENCV_DIRECTORY,会自动下载FastDeploy提供的预编译的OpenCV,但在**Linux平台**无法支持Video的读取,以及imshow等可视化界面功能)
+```
+sudo apt-get install libopencv-dev
+```
+编译命令如下:
+```bash
+# Download the latest source code
+git clone https://github.com/PaddlePaddle/FastDeploy.git
+cd FastDeploy
+mkdir build && cd build
+
+# CMake configuration with KunlunXin xpu toolchain
+cmake -DWITH_XPU=ON \
+ -DWITH_GPU=OFF \ # 不编译 GPU
+ -DENABLE_ORT_BACKEND=ON \ # 可选择开启 ORT 后端
+ -DENABLE_PADDLE_BACKEND=ON \ # 可选择开启 Paddle 后端
+ -DCMAKE_INSTALL_PREFIX=fastdeploy-xpu \
+ -DENABLE_VISION=ON \ # 是否编译集成视觉模型的部署模块,可选择开启
+ -DOPENCV_DIRECTORY=/usr/lib/x86_64-linux-gnu/cmake/opencv4 \
+ ..
+
+# Build FastDeploy KunlunXin XPU C++ SDK
+make -j8
+make install
+```
+编译完成之后,会生成 fastdeploy-xpu 目录,表示基于 PadddleLite 的 FastDeploy 库编译完成。
+
+## Python 编译
+编译命令如下:
+```bash
+git clone https://github.com/PaddlePaddle/FastDeploy.git
+cd FastDeploy/python
+export WITH_XPU=ON
+export WITH_GPU=OFF
+export ENABLE_ORT_BACKEND=ON
+export ENABLE_PADDLE_BACKEND=ON
+export ENABLE_VISION=ON
+# OPENCV_DIRECTORY可选,不指定会自动下载FastDeploy提供的预编译OpenCV库
+export OPENCV_DIRECTORY=/usr/lib/x86_64-linux-gnu/cmake/opencv4
+
+python setup.py build
+python setup.py bdist_wheel
+```
+编译完成即会在 `FastDeploy/python/dist` 目录下生成编译后的 `wheel` 包,直接 pip install 即可
+
+编译过程中,如若修改编译参数,为避免带来缓存影响,可删除 `FastDeploy/python` 目录下的 `build` 和 `.setuptools-cmake-build` 两个子目录后再重新编译
diff --git a/docs/en/build_and_install/README.md b/docs/en/build_and_install/README.md
old mode 100644
new mode 100755
index 4beaaeec8..0958c3778
--- a/docs/en/build_and_install/README.md
+++ b/docs/en/build_and_install/README.md
@@ -12,6 +12,9 @@ English | [中文](../../cn/build_and_install/README.md)
- [Build and Install on IPU Platform](ipu.md)
- [Build and Install on Nvidia Jetson Platform](jetson.md)
- [Build and Install on Android Platform](android.md)
+- [Build and Install on RV1126 Platform](rv1126.md)
+- [Build and Install on A311D Platform](a311d.md)
+- [Build and Install on KunlunXin XPU Platform](xpu.md)
## Build options
@@ -25,6 +28,8 @@ English | [中文](../../cn/build_and_install/README.md)
| ENABLE_VISION | Default OFF,whether to enable vision models deployment module |
| ENABLE_TEXT | Default OFF,whether to enable text models deployment module |
| WITH_GPU | Default OFF, if build on GPU, this need to be ON |
+| WITH_XPU | Default OFF,if deploy on KunlunXin XPU,this need to be ON |
+| WITH_TIMVX | Default OFF,if deploy on RV1126/RV1109/A311D,this need to be ON |
| CUDA_DIRECTORY | Default /usr/local/cuda, if build on GPU, this defines the path of CUDA(>=11.2) |
| TRT_DIRECTORY | If build with ENABLE_TRT_BACKEND=ON, this defines the path of TensorRT(>=8.4) |
| ORT_DIRECTORY | [Optional] If build with ENABLE_ORT_BACKEND=ON, this flag defines the path of ONNX Runtime, but if this flag is not set, it will download ONNX Runtime library automatically |
diff --git a/docs/en/build_and_install/a311d.md b/docs/en/build_and_install/a311d.md
new file mode 100755
index 000000000..872c1b93c
--- /dev/null
+++ b/docs/en/build_and_install/a311d.md
@@ -0,0 +1,105 @@
+# How to Build A311D Deployment Environment
+
+FastDeploy supports AI deployment on Rockchip Soc based on Paddle-Lite backend. For more detailed information, please refer to: [PaddleLite Deployment Example](https://www.paddlepaddle.org.cn/lite/develop/demo_guides/verisilicon_timvx.html).
+
+This document describes how to compile the PaddleLite-based C++ FastDeploy cross-compilation library.
+
+The relevant compilation options are described as follows:
+|Compile Options|Default Values|Description|Remarks|
+|:---|:---|:---|:---|
+|ENABLE_LITE_BACKEND|OFF|It needs to be set to ON when compiling the A311D library| - |
+|WITH_TIMVX|OFF|It needs to be set to ON when compiling the A311D library| - |
+|TARGET_ABI|NONE|It needs to be set to arm64 when compiling the A311D library| - |
+
+For more compilation options, please refer to [Description of FastDeploy compilation options](./README.md)
+
+## Cross-compilation environment construction
+
+### Host Environment Requirements
+- os:Ubuntu == 16.04
+- cmake: version >= 3.10.0
+
+### Building the compilation environment
+You can enter the FastDeploy/tools/timvx directory and use the following command to install:
+```bash
+cd FastDeploy/tools/timvx
+bash install.sh
+```
+You can also install it with the following commands:
+```bash
+ # 1. Install basic software
+apt update
+apt-get install -y --no-install-recommends \
+ gcc g++ git make wget python unzip
+
+# 2. Install arm gcc toolchains
+apt-get install -y --no-install-recommends \
+ g++-arm-linux-gnueabi gcc-arm-linux-gnueabi \
+ g++-arm-linux-gnueabihf gcc-arm-linux-gnueabihf \
+ gcc-aarch64-linux-gnu g++-aarch64-linux-gnu
+
+# 3. Install cmake 3.10 or above
+wget -c https://mms-res.cdn.bcebos.com/cmake-3.10.3-Linux-x86_64.tar.gz && \
+ tar xzf cmake-3.10.3-Linux-x86_64.tar.gz && \
+ mv cmake-3.10.3-Linux-x86_64 /opt/cmake-3.10 && \
+ ln -s /opt/cmake-3.10/bin/cmake /usr/bin/cmake && \
+ ln -s /opt/cmake-3.10/bin/ccmake /usr/bin/ccmake
+```
+
+## FastDeploy cross-compilation library compilation based on PaddleLite
+After setting up the cross-compilation environment, the compilation command is as follows:
+```bash
+# Download the latest source code
+git clone https://github.com/PaddlePaddle/FastDeploy.git
+cd FastDeploy
+mkdir build && cd build
+
+# CMake configuration with A311D toolchain
+cmake -DCMAKE_TOOLCHAIN_FILE=./../cmake/toolchain.cmake \
+ -DWITH_TIMVX=ON \
+ -DTARGET_ABI=arm64 \
+ -DCMAKE_INSTALL_PREFIX=fastdeploy-tmivx \
+ -DENABLE_VISION=ON \ # 是否编译集成视觉模型的部署模块,可选择开启
+ -Wno-dev ..
+
+# Build FastDeploy A311D C++ SDK
+make -j8
+make install
+```
+After the compilation is complete, the fastdeploy-tmivx directory will be generated, indicating that the FastDeploy library based on PadddleLite TIM-VX has been compiled.
+
+## Prepare the Soc environment
+Before deployment, ensure that the version of the driver galcore.so of the Verisilicon Linux Kernel NPU meets the requirements. Before deployment, please log in to the development board, and enter the following command through the command line to query the NPU driver version. The recommended version of the Rockchip driver is: 6.4.4.3
+```bash
+dmesg | grep Galcore
+```
+If the current version does not comply with the above, please read the following content carefully to ensure that the underlying NPU driver environment is correct.
+
+There are two ways to modify the current NPU driver version:
+1. Manually replace the NPU driver version. (recommend)
+2. flash the machine, and flash the firmware that meets the requirements of the NPU driver version.
+
+### Manually replace the NPU driver version
+1. Use the following command to download and decompress the PaddleLite demo, which provides ready-made driver files
+```bash
+wget https://paddlelite-demo.bj.bcebos.com/devices/generic/PaddleLite-generic-demo.tar.gz
+tar -xf PaddleLite-generic-demo.tar.gz
+```
+2. Use `uname -a` to check `Linux Kernel` version, it is determined to be version 4.19.111.
+3. Upload `galcore.ko` under `PaddleLite-generic-demo/libs/PaddleLite/linux/arm64/lib/verisilicon_timvx/viv_sdk_6_4_4_3/lib/a311d/4.9.113` path to the development board.
+4. Log in to the development board, enter `sudo rmmod galcore` on the command line to uninstall the original driver, and enter `sudo insmod galcore.ko` to load the uploaded device driver. (Whether sudo is needed depends on the actual situation of the development board. For some adb-linked devices, please adb root in advance). If this step fails, go to method 2.
+5. Enter `dmesg | grep Galcore` in the development board to query the NPU driver version, and it is determined to be: 6.4.4.3
+
+### flash
+According to the specific development board model, ask the development board seller or the official website customer service for the firmware and flashing method corresponding to the 6.4.4.3 version of the NPU driver.
+
+For more details, please refer to: [PaddleLite prepares the device environment](https://www.paddlepaddle.org.cn/lite/develop/demo_guides/verisilicon_timvx.html#zhunbeishebeihuanjing)
+
+## Deployment example based on FastDeploy on A311D
+1. For deploying the PaddleClas classification model on A311D, please refer to: [C++ deployment example of PaddleClas classification model on A311D](../../../examples/vision/classification/paddleclas/a311d/README.md)
+
+2. For deploying PPYOLOE detection model on A311D, please refer to: [C++ deployment example of PPYOLOE detection model on A311D](../../../examples/vision/detection/paddledetection/a311d/README.md)
+
+3. For deploying YOLOv5 detection model on A311D, please refer to: [C++ Deployment Example of YOLOv5 Detection Model on A311D](../../../examples/vision/detection/yolov5/a311d/README.md)
+
+4. For deploying PP-LiteSeg segmentation model on A311D, please refer to: [C++ Deployment Example of PP-LiteSeg Segmentation Model on A311D](../../../examples/vision/segmentation/paddleseg/a311d/README.md)
diff --git a/docs/en/build_and_install/rv1126.md b/docs/en/build_and_install/rv1126.md
new file mode 100755
index 000000000..a56535363
--- /dev/null
+++ b/docs/en/build_and_install/rv1126.md
@@ -0,0 +1,105 @@
+# How to Build RV1126 Deployment Environment
+
+FastDeploy supports AI deployment on Rockchip Soc based on Paddle-Lite backend. For more detailed information, please refer to: [PaddleLite Deployment Example](https://www.paddlepaddle.org.cn/lite/develop/demo_guides/verisilicon_timvx.html).
+
+This document describes how to compile the PaddleLite-based C++ FastDeploy cross-compilation library.
+
+The relevant compilation options are described as follows:
+|Compile Options|Default Values|Description|Remarks|
+|:---|:---|:---|:---|
+|ENABLE_LITE_BACKEND|OFF|It needs to be set to ON when compiling the RK library| - |
+|WITH_TIMVX|OFF|It needs to be set to ON when compiling the RK library| - |
+|TARGET_ABI|NONE|It needs to be set to armhf when compiling the RK library| - |
+
+For more compilation options, please refer to [Description of FastDeploy compilation options](./README.md)
+
+## Cross-compilation environment construction
+
+### Host Environment Requirements
+- os:Ubuntu == 16.04
+- cmake: version >= 3.10.0
+
+### Building the compilation environment
+You can enter the FastDeploy/tools/timvx directory and use the following command to install:
+```bash
+cd FastDeploy/tools/timvx
+bash install.sh
+```
+You can also install it with the following commands:
+```bash
+ # 1. Install basic software
+apt update
+apt-get install -y --no-install-recommends \
+ gcc g++ git make wget python unzip
+
+# 2. Install arm gcc toolchains
+apt-get install -y --no-install-recommends \
+ g++-arm-linux-gnueabi gcc-arm-linux-gnueabi \
+ g++-arm-linux-gnueabihf gcc-arm-linux-gnueabihf \
+ gcc-aarch64-linux-gnu g++-aarch64-linux-gnu
+
+# 3. Install cmake 3.10 or above
+wget -c https://mms-res.cdn.bcebos.com/cmake-3.10.3-Linux-x86_64.tar.gz && \
+ tar xzf cmake-3.10.3-Linux-x86_64.tar.gz && \
+ mv cmake-3.10.3-Linux-x86_64 /opt/cmake-3.10 && \
+ ln -s /opt/cmake-3.10/bin/cmake /usr/bin/cmake && \
+ ln -s /opt/cmake-3.10/bin/ccmake /usr/bin/ccmake
+```
+
+## FastDeploy cross-compilation library compilation based on PaddleLite
+After setting up the cross-compilation environment, the compilation command is as follows:
+```bash
+# Download the latest source code
+git clone https://github.com/PaddlePaddle/FastDeploy.git
+cd FastDeploy
+mkdir build && cd build
+
+# CMake configuration with RK toolchain
+cmake -DCMAKE_TOOLCHAIN_FILE=./../cmake/toolchain.cmake \
+ -DWITH_TIMVX=ON \
+ -DTARGET_ABI=armhf \
+ -DCMAKE_INSTALL_PREFIX=fastdeploy-tmivx \
+ -DENABLE_VISION=ON \ # 是否编译集成视觉模型的部署模块,可选择开启
+ -Wno-dev ..
+
+# Build FastDeploy RV1126 C++ SDK
+make -j8
+make install
+```
+After the compilation is complete, the fastdeploy-tmivx directory will be generated, indicating that the FastDeploy library based on PadddleLite TIM-VX has been compiled.
+
+## Prepare the Soc environment
+Before deployment, ensure that the version of the driver galcore.so of the Verisilicon Linux Kernel NPU meets the requirements. Before deployment, please log in to the development board, and enter the following command through the command line to query the NPU driver version. The recommended version of the Rockchip driver is: 6.4.6.5
+```bash
+dmesg | grep Galcore
+```
+If the current version does not comply with the above, please read the following content carefully to ensure that the underlying NPU driver environment is correct.
+
+There are two ways to modify the current NPU driver version:
+1. Manually replace the NPU driver version. (recommend)
+2. flash the machine, and flash the firmware that meets the requirements of the NPU driver version.
+
+### Manually replace the NPU driver version
+1. Use the following command to download and decompress the PaddleLite demo, which provides ready-made driver files
+```bash
+wget https://paddlelite-demo.bj.bcebos.com/devices/generic/PaddleLite-generic-demo.tar.gz
+tar -xf PaddleLite-generic-demo.tar.gz
+```
+2. Use `uname -a` to check `Linux Kernel` version, it is determined to be version 4.19.111.
+3. Upload `galcore.ko` under `PaddleLite-generic-demo/libs/PaddleLite/linux/armhf/lib/verisilicon_timvx/viv_sdk_6_4_6_5/lib/1126/4.19.111/` path to the development board.
+4. Log in to the development board, enter `sudo rmmod galcore` on the command line to uninstall the original driver, and enter `sudo insmod galcore.ko` to load the uploaded device driver. (Whether sudo is needed depends on the actual situation of the development board. For some adb-linked devices, please adb root in advance). If this step fails, go to method 2.
+5. Enter `dmesg | grep Galcore` in the development board to query the NPU driver version, and it is determined to be: 6.4.6.5
+
+### flash
+According to the specific development board model, ask the development board seller or the official website customer service for the firmware and flashing method corresponding to the 6.4.6.5 version of the NPU driver.
+
+For more details, please refer to: [PaddleLite prepares the device environment](https://www.paddlepaddle.org.cn/lite/develop/demo_guides/verisilicon_timvx.html#zhunbeishebeihuanjing)
+
+## Deployment example based on FastDeploy on RV1126
+1. For deploying the PaddleClas classification model on RV1126, please refer to: [C++ deployment example of PaddleClas classification model on RV1126](../../../examples/vision/classification/paddleclas/rv1126/README.md)
+
+2. For deploying PPYOLOE detection model on RV1126, please refer to: [C++ deployment example of PPYOLOE detection model on RV1126](../../../examples/vision/detection/paddledetection/rv1126/README.md)
+
+3. For deploying YOLOv5 detection model on RV1126, please refer to: [C++ Deployment Example of YOLOv5 Detection Model on RV1126](../../../examples/vision/detection/yolov5/rv1126/README.md)
+
+4. For deploying PP-LiteSeg segmentation model on RV1126, please refer to: [C++ Deployment Example of PP-LiteSeg Segmentation Model on RV1126](../../../examples/vision/segmentation/paddleseg/rv1126/README.md)
diff --git a/docs/en/build_and_install/xpu.md b/docs/en/build_and_install/xpu.md
new file mode 100755
index 000000000..403837e5d
--- /dev/null
+++ b/docs/en/build_and_install/xpu.md
@@ -0,0 +1,78 @@
+# How to Build KunlunXin XPU Deployment Environment
+
+FastDeploy supports deployment AI on KunlunXin XPU based on Paddle-Lite backend. For more detailed information, please refer to: [PaddleLite Deployment Example](https://www.paddlepaddle.org.cn/lite/develop/demo_guides/kunlunxin_xpu.html#xpu)。
+
+This document describes how to compile the C++ FastDeploy library based on PaddleLite.
+
+The relevant compilation options are described as follows:
+|Compile Options|Default Values|Description|Remarks|
+|:---|:---|:---|:---|
+| ENABLE_LITE_BACKEND | OFF | It needs to be set to ON when compiling the RK library| - |
+| WITH_XPU | OFF | It needs to be set to ON when compiling the KunlunXin XPU library| - |
+| ENABLE_ORT_BACKEND | OFF | whether to intergrate ONNX Runtime backend | - |
+| ENABLE_PADDLE_BACKEND | OFF | whether to intergrate Paddle Inference backend | - |
+| ENABLE_OPENVINO_BACKEND | OFF | whether to intergrate OpenVINO backend | - |
+| ENABLE_VISION | OFF | whether to intergrate vision models | - |
+| ENABLE_TEXT | OFF | whether to intergrate text models | - |
+
+The configuration for third libraries(Optional, if the following option is not defined, the prebuilt third libraries will download automaticly while building FastDeploy).
+| Option | Description |
+| :---------------------- | :--------------------------------------------------------------------------------------------- |
+| ORT_DIRECTORY | While ENABLE_ORT_BACKEND=ON, use ORT_DIRECTORY to specify your own ONNX Runtime library path. |
+| OPENCV_DIRECTORY | While ENABLE_VISION=ON, use OPENCV_DIRECTORY to specify your own OpenCV library path. |
+| OPENVINO_DIRECTORY | While ENABLE_OPENVINO_BACKEND=ON, use OPENVINO_DIRECTORY to specify your own OpenVINO library path. |
+
+For more compilation options, please refer to [Description of FastDeploy compilation options](./README.md)
+
+## C++ FastDeploy library compilation based on PaddleLite
+- OS: Linux
+- gcc/g++: version >= 8.2
+- cmake: version >= 3.15
+
+It it recommend install OpenCV library manually, and define `-DOPENCV_DIRECTORY` to set path of OpenCV library(If the flag is not defined, a prebuilt OpenCV library will be downloaded automaticly while building FastDeploy, but the prebuilt OpenCV cannot support reading video file or other function e.g `imshow`)
+```
+sudo apt-get install libopencv-dev
+```
+
+The compilation command is as follows:
+```bash
+# Download the latest source code
+git clone https://github.com/PaddlePaddle/FastDeploy.git
+cd FastDeploy
+mkdir build && cd build
+
+# CMake configuration with KunlunXin xpu toolchain
+cmake -DWITH_XPU=ON \
+ -DWITH_GPU=OFF \
+ -DENABLE_ORT_BACKEND=ON \
+ -DENABLE_PADDLE_BACKEND=ON \
+ -DCMAKE_INSTALL_PREFIX=fastdeploy-xpu \
+ -DENABLE_VISION=ON \
+ -DOPENCV_DIRECTORY=/usr/lib/x86_64-linux-gnu/cmake/opencv4 \
+ ..
+
+# Build FastDeploy KunlunXin XPU C++ SDK
+make -j8
+make install
+```
+After the compilation is complete, the fastdeploy-xpu directory will be generated, indicating that the PadddleLite-based FastDeploy library has been compiled.
+
+## Python compile
+The compilation command is as follows:
+```bash
+git clone https://github.com/PaddlePaddle/FastDeploy.git
+cd FastDeploy/python
+export WITH_XPU=ON
+export WITH_GPU=OFF
+export ENABLE_ORT_BACKEND=ON
+export ENABLE_PADDLE_BACKEND=ON
+export ENABLE_VISION=ON
+# The OPENCV_DIRECTORY is optional, if not exported, a prebuilt OpenCV library will be downloaded
+export OPENCV_DIRECTORY=/usr/lib/x86_64-linux-gnu/cmake/opencv4
+
+python setup.py build
+python setup.py bdist_wheel
+```
+After the compilation is completed, the compiled `wheel` package will be generated in the `FastDeploy/python/dist` directory, just pip install it directly
+
+During the compilation process, if you modify the compilation parameters, in order to avoid the cache impact, you can delete the two subdirectories `build` and `.setuptools-cmake-build` under the `FastDeploy/python` directory and then recompile.
diff --git a/examples/vision/classification/paddleclas/cpp/README.md b/examples/vision/classification/paddleclas/cpp/README.md
old mode 100644
new mode 100755
index 066340467..dff76da18
--- a/examples/vision/classification/paddleclas/cpp/README.md
+++ b/examples/vision/classification/paddleclas/cpp/README.md
@@ -30,6 +30,10 @@ wget https://gitee.com/paddlepaddle/PaddleClas/raw/release/2.4/deploy/images/Ima
./infer_demo ResNet50_vd_infer ILSVRC2012_val_00000010.jpeg 1
# GPU上TensorRT推理
./infer_demo ResNet50_vd_infer ILSVRC2012_val_00000010.jpeg 2
+# IPU推理
+./infer_demo ResNet50_vd_infer ILSVRC2012_val_00000010.jpeg 3
+# KunlunXin XPU推理
+./infer_demo ResNet50_vd_infer ILSVRC2012_val_00000010.jpeg 4
```
以上命令只适用于Linux或MacOS, Windows下SDK的使用方式请参考:
diff --git a/examples/vision/classification/paddleclas/cpp/infer.cc b/examples/vision/classification/paddleclas/cpp/infer.cc
old mode 100644
new mode 100755
index bdd87ecdc..244accfa7
--- a/examples/vision/classification/paddleclas/cpp/infer.cc
+++ b/examples/vision/classification/paddleclas/cpp/infer.cc
@@ -96,6 +96,32 @@ void IpuInfer(const std::string& model_dir, const std::string& image_file) {
std::cout << res.Str() << std::endl;
}
+void XpuInfer(const std::string& model_dir, const std::string& image_file) {
+ auto model_file = model_dir + sep + "inference.pdmodel";
+ auto params_file = model_dir + sep + "inference.pdiparams";
+ auto config_file = model_dir + sep + "inference_cls.yaml";
+
+ auto option = fastdeploy::RuntimeOption();
+ option.UseXpu();
+ auto model = fastdeploy::vision::classification::PaddleClasModel(
+ model_file, params_file, config_file, option);
+ if (!model.Initialized()) {
+ std::cerr << "Failed to initialize." << std::endl;
+ return;
+ }
+
+ auto im = cv::imread(image_file);
+
+ fastdeploy::vision::ClassifyResult res;
+ if (!model.Predict(im, &res)) {
+ std::cerr << "Failed to predict." << std::endl;
+ return;
+ }
+
+ // print res
+ std::cout << res.Str() << std::endl;
+}
+
void TrtInfer(const std::string& model_dir, const std::string& image_file) {
auto model_file = model_dir + sep + "inference.pdmodel";
auto params_file = model_dir + sep + "inference.pdiparams";
@@ -128,7 +154,7 @@ int main(int argc, char* argv[]) {
"e.g ./infer_demo ./ResNet50_vd ./test.jpeg 0"
<< 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."
+ "with gpu; 2: run with gpu and use tensorrt backend; 3: run with ipu; 4: run with xpu."
<< std::endl;
return -1;
}
@@ -141,6 +167,8 @@ int main(int argc, char* argv[]) {
TrtInfer(argv[1], argv[2]);
} else if (std::atoi(argv[3]) == 3) {
IpuInfer(argv[1], argv[2]);
+ } else if (std::atoi(argv[3]) == 4) {
+ XpuInfer(argv[1], argv[2]);
}
return 0;
}
diff --git a/examples/vision/classification/paddleclas/python/README.md b/examples/vision/classification/paddleclas/python/README.md
old mode 100644
new mode 100755
index 9d17e6f65..5a1baff7f
--- a/examples/vision/classification/paddleclas/python/README.md
+++ b/examples/vision/classification/paddleclas/python/README.md
@@ -25,6 +25,8 @@ python infer.py --model ResNet50_vd_infer --image ILSVRC2012_val_00000010.jpeg -
python infer.py --model ResNet50_vd_infer --image ILSVRC2012_val_00000010.jpeg --device gpu --use_trt True --topk 1
# IPU推理(注意:IPU推理首次运行会有序列化模型的操作,有一定耗时,需要耐心等待)
python infer.py --model ResNet50_vd_infer --image ILSVRC2012_val_00000010.jpeg --device ipu --topk 1
+# XPU推理
+python infer.py --model ResNet50_vd_infer --image ILSVRC2012_val_00000010.jpeg --device xpu --topk 1
```
运行完成后返回结果如下所示
diff --git a/examples/vision/classification/paddleclas/python/infer.py b/examples/vision/classification/paddleclas/python/infer.py
old mode 100644
new mode 100755
index 0b2d35a21..3c150533c
--- a/examples/vision/classification/paddleclas/python/infer.py
+++ b/examples/vision/classification/paddleclas/python/infer.py
@@ -35,6 +35,9 @@ def build_option(args):
if args.device.lower() == "ipu":
option.use_ipu()
+ if args.device.lower() == "xpu":
+ option.use_xpu()
+
if args.use_trt:
option.use_trt_backend()
return option
diff --git a/examples/vision/detection/yolov5/cpp/CMakeLists.txt b/examples/vision/detection/yolov5/cpp/CMakeLists.txt
old mode 100644
new mode 100755
index 93540a7e8..2b3f8c54f
--- a/examples/vision/detection/yolov5/cpp/CMakeLists.txt
+++ b/examples/vision/detection/yolov5/cpp/CMakeLists.txt
@@ -12,3 +12,7 @@ include_directories(${FASTDEPLOY_INCS})
add_executable(infer_demo ${PROJECT_SOURCE_DIR}/infer.cc)
# 添加FastDeploy库依赖
target_link_libraries(infer_demo ${FASTDEPLOY_LIBS})
+
+add_executable(infer_paddle_demo ${PROJECT_SOURCE_DIR}/infer_paddle_model.cc)
+# 添加FastDeploy库依赖
+target_link_libraries(infer_paddle_demo ${FASTDEPLOY_LIBS})
diff --git a/examples/vision/detection/yolov5/cpp/README.md b/examples/vision/detection/yolov5/cpp/README.md
old mode 100644
new mode 100755
index ece3826a5..581f1c49b
--- a/examples/vision/detection/yolov5/cpp/README.md
+++ b/examples/vision/detection/yolov5/cpp/README.md
@@ -12,16 +12,33 @@
```bash
mkdir build
cd build
-# 下载FastDeploy预编译库,用户可在上文提到的`FastDeploy预编译库`中自行选择合适的版本使用
+# 下载 FastDeploy 预编译库,用户可在上文提到的`FastDeploy预编译库`中自行选择合适的版本使用
wget https://bj.bcebos.com/fastdeploy/release/cpp/fastdeploy-linux-x64-x.x.x.tgz
tar xvf fastdeploy-linux-x64-x.x.x.tgz
cmake .. -DFASTDEPLOY_INSTALL_DIR=${PWD}/fastdeploy-linux-x64-x.x.x
make -j
-#下载官方转换好的yolov5模型文件和测试图片
-wget https://bj.bcebos.com/paddlehub/fastdeploy/yolov5s.onnx
+#下载官方转换好的 yolov5 Paddle 模型文件和测试图片
+wget https://bj.bcebos.com/paddlehub/fastdeploy/yolov5s_infer.tar
+tar -xvf yolov5s_infer.tar
wget https://gitee.com/paddlepaddle/PaddleDetection/raw/release/2.4/demo/000000014439.jpg
+# CPU推理
+./infer_paddle_demo yolov5s_infer 000000014439.jpg 0
+# GPU推理
+./infer_paddle_demo yolov5s_infer 000000014439.jpg 1
+# GPU上TensorRT推理
+./infer_paddle_demo yolov5s_infer 000000014439.jpg 2
+# XPU推理
+./infer_paddle_demo yolov5s_infer 000000014439.jpg 3
+```
+
+上述的模型为 Paddle 模型的推理,如果想要做 ONNX 模型的推理,可以按照如下步骤:
+```bash
+# 1. 下载官方转换好的 yolov5 ONNX 模型文件和测试图片
+wget https://bj.bcebos.com/paddlehub/fastdeploy/yolov5s.onnx
+wget https://gitee.com/paddlepaddle/PaddleDetection/raw/release/2.4/demo/000000014439.jpg
+
# CPU推理
./infer_demo yolov5s.onnx 000000014439.jpg 0
# GPU推理
@@ -29,7 +46,6 @@ wget https://gitee.com/paddlepaddle/PaddleDetection/raw/release/2.4/demo/0000000
# GPU上TensorRT推理
./infer_demo yolov5s.onnx 000000014439.jpg 2
```
-
运行完成可视化结果如下图所示
diff --git a/examples/vision/detection/yolov5/cpp/infer.cc b/examples/vision/detection/yolov5/cpp/infer.cc
old mode 100644
new mode 100755
index 1c3907918..fb20686de
--- a/examples/vision/detection/yolov5/cpp/infer.cc
+++ b/examples/vision/detection/yolov5/cpp/infer.cc
@@ -102,4 +102,4 @@ int main(int argc, char* argv[]) {
TrtInfer(argv[1], argv[2]);
}
return 0;
-}
+}
\ No newline at end of file
diff --git a/examples/vision/detection/yolov5/cpp/infer_paddle_model.cc b/examples/vision/detection/yolov5/cpp/infer_paddle_model.cc
new file mode 100755
index 000000000..d5692ce7c
--- /dev/null
+++ b/examples/vision/detection/yolov5/cpp/infer_paddle_model.cc
@@ -0,0 +1,154 @@
+// 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"
+#ifdef WIN32
+const char sep = '\\';
+#else
+const char sep = '/';
+#endif
+
+void CpuInfer(const std::string& model_dir, const std::string& image_file) {
+ auto model_file = model_dir + sep + "model.pdmodel";
+ auto params_file = model_dir + sep + "model.pdiparams";
+ fastdeploy::RuntimeOption option;
+ option.UseCpu();
+ auto model = fastdeploy::vision::detection::YOLOv5(
+ model_file, params_file, option, fastdeploy::ModelFormat::PADDLE);
+ if (!model.Initialized()) {
+ std::cerr << "Failed to initialize." << std::endl;
+ return;
+ }
+
+ 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("vis_result.jpg", vis_im);
+ std::cout << "Visualized result saved in ./vis_result.jpg" << std::endl;
+}
+
+void GpuInfer(const std::string& model_dir, const std::string& image_file) {
+ 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::detection::YOLOv5(
+ model_file, params_file, option, fastdeploy::ModelFormat::PADDLE);
+ if (!model.Initialized()) {
+ std::cerr << "Failed to initialize." << std::endl;
+ return;
+ }
+
+ 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("vis_result.jpg", vis_im);
+ std::cout << "Visualized result saved in ./vis_result.jpg" << std::endl;
+}
+
+void TrtInfer(const std::string& model_dir, const std::string& image_file) {
+ auto model_file = model_dir + sep + "model.pdmodel";
+ auto params_file = model_dir + sep + "model.pdiparams";
+ auto option = fastdeploy::RuntimeOption();
+ option.UseGpu();
+ option.UseTrtBackend();
+ option.SetTrtInputShape("images", {1, 3, 640, 640});
+ auto model = fastdeploy::vision::detection::YOLOv5(
+ model_file, params_file, option, fastdeploy::ModelFormat::PADDLE);
+
+ if (!model.Initialized()) {
+ std::cerr << "Failed to initialize." << std::endl;
+ return;
+ }
+
+ 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::Visualize::VisDetection(im, res);
+ cv::imwrite("vis_result.jpg", vis_im);
+ std::cout << "Visualized result saved in ./vis_result.jpg" << std::endl;
+}
+
+void XpuInfer(const std::string& model_dir, const std::string& image_file) {
+ auto model_file = model_dir + sep + "model.pdmodel";
+ auto params_file = model_dir + sep + "model.pdiparams";
+ fastdeploy::RuntimeOption option;
+ option.UseXpu();
+ auto model = fastdeploy::vision::detection::YOLOv5(
+ model_file, params_file, option, fastdeploy::ModelFormat::PADDLE);
+
+ if (!model.Initialized()) {
+ std::cerr << "Failed to initialize." << std::endl;
+ return;
+ }
+
+ 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("vis_result.jpg", vis_im);
+ std::cout << "Visualized result saved in ./vis_result.jpg" << std::endl;
+}
+
+int main(int argc, char* argv[]) {
+ if (argc < 4) {
+ std::cout << "Usage: infer_demo path/to/model path/to/image run_option, "
+ "e.g ./infer_model ./yolov5s_infer ./test.jpeg 0"
+ << 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; 3: run with KunlunXin XPU."
+ << std::endl;
+ return -1;
+ }
+
+ if (std::atoi(argv[3]) == 0) {
+ CpuInfer(argv[1], argv[2]);
+ } else if (std::atoi(argv[3]) == 1) {
+ GpuInfer(argv[1], argv[2]);
+ } else if (std::atoi(argv[3]) == 2) {
+ TrtInfer(argv[1], argv[2]);
+ } else if (std::atoi(argv[3]) == 3) {
+ XpuInfer(argv[1], argv[2]);
+ }
+ return 0;
+}
diff --git a/examples/vision/detection/yolov5/python/README.md b/examples/vision/detection/yolov5/python/README.md
old mode 100644
new mode 100755
index 4f47b3084..83f6ed781
--- a/examples/vision/detection/yolov5/python/README.md
+++ b/examples/vision/detection/yolov5/python/README.md
@@ -13,15 +13,18 @@ git clone https://github.com/PaddlePaddle/FastDeploy.git
cd examples/vision/detection/yolov5/python/
#下载yolov5模型文件和测试图片
-wget https://bj.bcebos.com/paddlehub/fastdeploy/yolov5s.onnx
+wget https://bj.bcebos.com/paddlehub/fastdeploy/yolov5s_infer.tar
+tar -xf yolov5s_infer.tar
wget https://gitee.com/paddlepaddle/PaddleDetection/raw/release/2.4/demo/000000014439.jpg
# CPU推理
-python infer.py --model yolov5s.onnx --image 000000014439.jpg --device cpu
+python infer.py --model yolov5s_infer --image 000000014439.jpg --device cpu
# GPU推理
-python infer.py --model yolov5s.onnx --image 000000014439.jpg --device gpu
+python infer.py --model yolov5s_infer --image 000000014439.jpg --device gpu
# GPU上使用TensorRT推理
-python infer.py --model yolov5s.onnx --image 000000014439.jpg --device gpu --use_trt True
+python infer.py --model yolov5s_infer --image 000000014439.jpg --device gpu --use_trt True
+# XPU推理
+python infer.py --model yolov5s_infer --image 000000014439.jpg --device xpu
```
运行完成可视化结果如下图所示
diff --git a/examples/vision/detection/yolov5/python/infer.py b/examples/vision/detection/yolov5/python/infer.py
old mode 100644
new mode 100755
index 462740e9c..b155af0ed
--- a/examples/vision/detection/yolov5/python/infer.py
+++ b/examples/vision/detection/yolov5/python/infer.py
@@ -1,20 +1,20 @@
import fastdeploy as fd
import cv2
+import os
def parse_arguments():
import argparse
import ast
parser = argparse.ArgumentParser()
- parser.add_argument(
- "--model", default=None, help="Path of yolov5 onnx model.")
+ parser.add_argument("--model", default=None, help="Path of yolov5 model.")
parser.add_argument(
"--image", default=None, help="Path of test image file.")
parser.add_argument(
"--device",
type=str,
default='cpu',
- help="Type of inference device, support 'cpu' or 'gpu'.")
+ help="Type of inference device, support 'cpu' or 'gpu' or 'xpu'.")
parser.add_argument(
"--use_trt",
type=ast.literal_eval,
@@ -25,6 +25,8 @@ def parse_arguments():
def build_option(args):
option = fd.RuntimeOption()
+ if args.device.lower() == "xpu":
+ option.use_xpu()
if args.device.lower() == "gpu":
option.use_gpu()
@@ -37,14 +39,15 @@ def build_option(args):
args = parse_arguments()
-if args.model is None:
- model = fd.download_model(name='YOLOv5s')
-else:
- model = args.model
-
# 配置runtime,加载模型
runtime_option = build_option(args)
-model = fd.vision.detection.YOLOv5(model, runtime_option=runtime_option)
+model_file = os.path.join(args.model, "model.pdmodel")
+params_file = os.path.join(args.model, "model.pdiparams")
+model = fd.vision.detection.YOLOv5(
+ model_file,
+ params_file,
+ runtime_option=runtime_option,
+ model_format=fd.ModelFormat.PADDLE)
# 预测图片检测结果
if args.image is None:
diff --git a/fastdeploy/backends/lite/lite_backend.cc b/fastdeploy/backends/lite/lite_backend.cc
index 7e3e09f8d..20afa5e28 100755
--- a/fastdeploy/backends/lite/lite_backend.cc
+++ b/fastdeploy/backends/lite/lite_backend.cc
@@ -43,24 +43,33 @@ void LiteBackend::BuildOption(const LiteBackendOption& option) {
option_ = option;
std::vector valid_places;
if (option_.enable_int8) {
- valid_places.push_back(
+ if(option_.enable_xpu) {
+ valid_places.push_back(
+ paddle::lite_api::Place{TARGET(kXPU), PRECISION(kInt8)});
+ } else {
+ valid_places.push_back(
paddle::lite_api::Place{TARGET(kARM), PRECISION(kInt8)});
+ }
FDINFO << "Lite::Backend enable_int8 option is ON ! Lite::Backend will "
<< "inference with int8 precision!" << std::endl;
}
if (option_.enable_fp16) {
- paddle::lite_api::MobileConfig check_fp16_config;
- // Determine whether the device supports the FP16
- // instruction set (or whether it is an arm device
- // of the armv8.2 architecture)
- supported_fp16_ = check_fp16_config.check_fp16_valid();
- if (supported_fp16_) {
+ if(option_.enable_xpu){
valid_places.push_back(
- paddle::lite_api::Place{TARGET(kARM), PRECISION(kFP16)});
- FDINFO << "Your device is supported fp16 ! Lite::Backend will "
- << "inference with fp16 precision!" << std::endl;
+ paddle::lite_api::Place{TARGET(kXPU), PRECISION(kFP16)});
} else {
- FDWARNING << "This device is not supported fp16, will skip fp16 option.";
+ paddle::lite_api::MobileConfig check_fp16_config;
+ // Determine whether the device supports the FP16
+ // instruction set (or whether it is an arm device
+ // of the armv8.2 architecture)
+ supported_fp16_ = check_fp16_config.check_fp16_valid();
+ if (supported_fp16_) {
+ valid_places.push_back(
+ paddle::lite_api::Place{TARGET(kARM), PRECISION(kFP16)});
+ FDINFO << "The device supports FP16, Lite::Backend will inference with FP16 precision." << std::endl;
+ } else {
+ FDWARNING << "The device doesn't support FP16, will fallback to FP32.";
+ }
}
}
if (!option_.nnadapter_subgraph_partition_config_path.empty()) {
@@ -81,8 +90,24 @@ void LiteBackend::BuildOption(const LiteBackendOption& option) {
valid_places.push_back(
paddle::lite_api::Place{TARGET(kARM), PRECISION(kInt8)});
}
- valid_places.push_back(
+
+ if(option_.enable_xpu){
+ valid_places.push_back(
+ paddle::lite_api::Place{TARGET(kXPU), PRECISION(kFloat)});
+ valid_places.push_back(
+ paddle::lite_api::Place{TARGET(kX86), PRECISION(kFloat)});
+ config_.set_xpu_dev_per_thread(option_.device_id);
+ config_.set_xpu_workspace_l3_size_per_thread(option_.xpu_l3_workspace_size);
+ config_.set_xpu_l3_cache_method(option_.xpu_l3_workspace_size, option_.xpu_locked);
+ config_.set_xpu_conv_autotune(option_.xpu_autotune, option_.xpu_autotune_file);
+ config_.set_xpu_multi_encoder_method(option_.xpu_precision, option_.xpu_adaptive_seqlen);
+ if (option_.xpu_enable_multi_stream) {
+ config_.enable_xpu_multi_stream();
+ }
+ } else {
+ valid_places.push_back(
paddle::lite_api::Place{TARGET(kARM), PRECISION(kFloat)});
+ }
config_.set_valid_places(valid_places);
if (option_.threads > 0) {
config_.set_threads(option_.threads);
@@ -160,7 +185,9 @@ bool LiteBackend::InitFromPaddle(const std::string& model_file,
auto shape = tensor->shape();
info.shape.assign(shape.begin(), shape.end());
info.name = output_names[i];
- info.dtype = LiteDataTypeToFD(tensor->precision());
+ if(!option_.enable_xpu){
+ info.dtype = LiteDataTypeToFD(tensor->precision());
+ }
outputs_desc_.emplace_back(info);
}
@@ -239,6 +266,9 @@ bool LiteBackend::Infer(std::vector& inputs,
outputs->resize(outputs_desc_.size());
for (size_t i = 0; i < outputs_desc_.size(); ++i) {
auto tensor = predictor_->GetOutput(i);
+ if(outputs_desc_[i].dtype != LiteDataTypeToFD(tensor->precision())){
+ outputs_desc_[i].dtype = LiteDataTypeToFD(tensor->precision());
+ }
(*outputs)[i].Resize(tensor->shape(), outputs_desc_[i].dtype,
outputs_desc_[i].name);
memcpy((*outputs)[i].MutableData(), tensor->data(),
diff --git a/fastdeploy/backends/lite/lite_backend.h b/fastdeploy/backends/lite/lite_backend.h
index 279acf5df..0221f507f 100755
--- a/fastdeploy/backends/lite/lite_backend.h
+++ b/fastdeploy/backends/lite/lite_backend.h
@@ -45,6 +45,15 @@ struct LiteBackendOption {
// Such as fp16, different device target (kARM/kXPU/kNPU/...)
std::string nnadapter_subgraph_partition_config_path = "";
bool enable_timvx = false;
+ bool enable_xpu = false;
+ int device_id = 0;
+ int xpu_l3_workspace_size = 0xfffc00;
+ bool xpu_locked = false;
+ bool xpu_autotune = true;
+ std::string xpu_autotune_file = "";
+ std::string xpu_precision = "int16";
+ bool xpu_adaptive_seqlen = false;
+ bool xpu_enable_multi_stream = false;
};
// Convert data type from paddle lite to fastdeploy
diff --git a/fastdeploy/core/fd_type.cc b/fastdeploy/core/fd_type.cc
index ba3319dbc..3624b732d 100755
--- a/fastdeploy/core/fd_type.cc
+++ b/fastdeploy/core/fd_type.cc
@@ -62,6 +62,9 @@ std::string Str(const Device& d) {
case Device::TIMVX:
out = "Device::TIMVX";
break;
+ case Device::XPU:
+ out = "Device::XPU";
+ break;
default:
out = "Device::UNKOWN";
}
@@ -82,6 +85,9 @@ std::ostream& operator<<(std::ostream& out,const Device& d){
case Device::TIMVX:
out << "Device::TIMVX";
break;
+ case Device::XPU:
+ out << "Device::XPU";
+ break;
default:
out << "Device::UNKOWN";
}
diff --git a/fastdeploy/core/fd_type.h b/fastdeploy/core/fd_type.h
index ba18d8e36..d39c56fdf 100755
--- a/fastdeploy/core/fd_type.h
+++ b/fastdeploy/core/fd_type.h
@@ -22,7 +22,7 @@
namespace fastdeploy {
-enum FASTDEPLOY_DECL Device { CPU, GPU, RKNPU, IPU, TIMVX};
+enum FASTDEPLOY_DECL Device { CPU, GPU, RKNPU, IPU, TIMVX, XPU};
FASTDEPLOY_DECL std::string Str(const Device& d);
diff --git a/fastdeploy/fastdeploy_model.cc b/fastdeploy/fastdeploy_model.cc
index ad8c1329d..4d7a8e364 100755
--- a/fastdeploy/fastdeploy_model.cc
+++ b/fastdeploy/fastdeploy_model.cc
@@ -51,6 +51,7 @@ bool FastDeployModel::InitRuntimeWithSpecifiedBackend() {
bool use_ipu = (runtime_option.device == Device::IPU);
bool use_rknpu = (runtime_option.device == Device::RKNPU);
bool use_timvx = (runtime_option.device == Device::TIMVX);
+ bool use_xpu = (runtime_option.device == Device::XPU);
if (use_gpu) {
if (!IsSupported(valid_gpu_backends, runtime_option.backend)) {
@@ -67,6 +68,11 @@ bool FastDeployModel::InitRuntimeWithSpecifiedBackend() {
FDERROR << "The valid timvx backends of model " << ModelName() << " are " << Str(valid_timvx_backends) << ", " << runtime_option.backend << " is not supported." << std::endl;
return false;
}
+ } else if (use_xpu) {
+ if (!IsSupported(valid_xpu_backends, runtime_option.backend)) {
+ FDERROR << "The valid xpu backends of model " << ModelName() << " are " << Str(valid_xpu_backends) << ", " << runtime_option.backend << " is not supported." << std::endl;
+ return false;
+ }
} else if(use_ipu) {
if (!IsSupported(valid_ipu_backends, runtime_option.backend)) {
FDERROR << "The valid ipu backends of model " << ModelName() << " are " << Str(valid_ipu_backends) << ", " << runtime_option.backend << " is not supported." << std::endl;
@@ -102,6 +108,8 @@ bool FastDeployModel::InitRuntimeWithSpecifiedDevice() {
return CreateRKNPUBackend();
} else if (runtime_option.device == Device::TIMVX) {
return CreateTimVXBackend();
+ } else if (runtime_option.device == Device::XPU) {
+ return CreateXPUBackend();
} else if (runtime_option.device == Device::IPU) {
#ifdef WITH_IPU
return CreateIpuBackend();
@@ -111,7 +119,7 @@ bool FastDeployModel::InitRuntimeWithSpecifiedDevice() {
return false;
#endif
}
- FDERROR << "Only support CPU/GPU/IPU/RKNPU/TIMVX now." << std::endl;
+ FDERROR << "Only support CPU/GPU/IPU/RKNPU/TIMVX/XPU now." << std::endl;
return false;
}
@@ -225,6 +233,29 @@ bool FastDeployModel::CreateTimVXBackend() {
return false;
}
+bool FastDeployModel::CreateXPUBackend() {
+ if (valid_xpu_backends.size() == 0) {
+ FDERROR << "There's no valid xpu backends for model: " << ModelName()
+ << std::endl;
+ return false;
+ }
+
+ for (size_t i = 0; i < valid_xpu_backends.size(); ++i) {
+ if (!IsBackendAvailable(valid_xpu_backends[i])) {
+ continue;
+ }
+ runtime_option.backend = valid_xpu_backends[i];
+ runtime_ = std::unique_ptr(new Runtime());
+ if (!runtime_->Init(runtime_option)) {
+ return false;
+ }
+ runtime_initialized_ = true;
+ return true;
+ }
+ FDERROR << "Found no valid backend for model: " << ModelName() << std::endl;
+ return false;
+}
+
bool FastDeployModel::CreateIpuBackend() {
if (valid_ipu_backends.size() == 0) {
FDERROR << "There's no valid ipu backends for model: " << ModelName()
diff --git a/fastdeploy/fastdeploy_model.h b/fastdeploy/fastdeploy_model.h
index 5a6efba09..5c8809196 100755
--- a/fastdeploy/fastdeploy_model.h
+++ b/fastdeploy/fastdeploy_model.h
@@ -45,6 +45,9 @@ class FASTDEPLOY_DECL FastDeployModel {
/** Model's valid timvx backends. This member defined all the timvx backends have successfully tested for the model
*/
std::vector valid_timvx_backends = {};
+ /** Model's valid KunlunXin xpu backends. This member defined all the KunlunXin xpu backends have successfully tested for the model
+ */
+ std::vector valid_xpu_backends = {};
/** Model's valid hardware backends. This member defined all the gpu backends have successfully tested for the model
*/
std::vector valid_rknpu_backends = {};
@@ -143,6 +146,7 @@ class FASTDEPLOY_DECL FastDeployModel {
bool CreateIpuBackend();
bool CreateRKNPUBackend();
bool CreateTimVXBackend();
+ bool CreateXPUBackend();
std::shared_ptr runtime_;
bool runtime_initialized_ = false;
diff --git a/fastdeploy/pybind/runtime.cc b/fastdeploy/pybind/runtime.cc
old mode 100644
new mode 100755
index 75767c665..d0cb0b5f8
--- a/fastdeploy/pybind/runtime.cc
+++ b/fastdeploy/pybind/runtime.cc
@@ -23,6 +23,7 @@ void BindRuntime(pybind11::module& m) {
.def("use_gpu", &RuntimeOption::UseGpu)
.def("use_cpu", &RuntimeOption::UseCpu)
.def("use_rknpu2", &RuntimeOption::UseRKNPU2)
+ .def("use_xpu", &RuntimeOption::UseXpu)
.def("set_external_stream", &RuntimeOption::SetExternalStream)
.def("set_cpu_thread_num", &RuntimeOption::SetCpuThreadNum)
.def("use_paddle_backend", &RuntimeOption::UsePaddleBackend)
@@ -100,7 +101,21 @@ void BindRuntime(pybind11::module& m) {
.def_readwrite("ipu_available_memory_proportion",
&RuntimeOption::ipu_available_memory_proportion)
.def_readwrite("ipu_enable_half_partial",
- &RuntimeOption::ipu_enable_half_partial);
+ &RuntimeOption::ipu_enable_half_partial)
+ .def_readwrite("xpu_l3_workspace_size",
+ &RuntimeOption::xpu_l3_workspace_size)
+ .def_readwrite("xpu_locked",
+ &RuntimeOption::xpu_locked)
+ .def_readwrite("xpu_autotune",
+ &RuntimeOption::xpu_autotune)
+ .def_readwrite("xpu_autotune_file",
+ &RuntimeOption::xpu_autotune_file)
+ .def_readwrite("xpu_precision",
+ &RuntimeOption::xpu_precision)
+ .def_readwrite("xpu_adaptive_seqlen",
+ &RuntimeOption::xpu_adaptive_seqlen)
+ .def_readwrite("xpu_enable_multi_stream",
+ &RuntimeOption::xpu_enable_multi_stream);
pybind11::class_(m, "TensorInfo")
.def_readwrite("name", &TensorInfo::name)
diff --git a/fastdeploy/runtime.cc b/fastdeploy/runtime.cc
old mode 100644
new mode 100755
index 1a51cebea..565c10607
--- a/fastdeploy/runtime.cc
+++ b/fastdeploy/runtime.cc
@@ -236,7 +236,26 @@ void RuntimeOption::UseRKNPU2(fastdeploy::rknpu2::CpuName rknpu2_name,
void RuntimeOption::UseTimVX() {
enable_timvx = true;
device = Device::TIMVX;
- UseLiteBackend();
+}
+
+void RuntimeOption::UseXpu(int xpu_id,
+ int l3_workspace_size,
+ bool locked,
+ bool autotune,
+ const std::string &autotune_file,
+ const std::string &precision,
+ bool adaptive_seqlen,
+ bool enable_multi_stream) {
+ enable_xpu = true;
+ device_id = xpu_id;
+ xpu_l3_workspace_size = l3_workspace_size;
+ xpu_locked=locked;
+ xpu_autotune=autotune;
+ xpu_autotune_file=autotune_file;
+ xpu_precision = precision;
+ xpu_adaptive_seqlen=adaptive_seqlen;
+ xpu_enable_multi_stream=enable_multi_stream;
+ device = Device::XPU;
}
void RuntimeOption::SetExternalStream(void* external_stream) {
@@ -532,8 +551,8 @@ bool Runtime::Init(const RuntimeOption& _option) {
FDINFO << "Runtime initialized with Backend::OPENVINO in "
<< Str(option.device) << "." << std::endl;
} else if (option.backend == Backend::LITE) {
- FDASSERT(option.device == Device::CPU || option.device == Device::TIMVX,
- "Backend::LITE only supports Device::CPU/Device::TIMVX.");
+ FDASSERT(option.device == Device::CPU || option.device == Device::TIMVX || option.device == Device::XPU,
+ "Backend::LITE only supports Device::CPU/Device::TIMVX/Device::XPU.");
CreateLiteBackend();
FDINFO << "Runtime initialized with Backend::LITE in " << Str(option.device)
<< "." << std::endl;
@@ -784,6 +803,16 @@ void Runtime::CreateLiteBackend() {
lite_option.nnadapter_subgraph_partition_config_path =
option.lite_nnadapter_subgraph_partition_config_path;
lite_option.enable_timvx = option.enable_timvx;
+ lite_option.enable_xpu = option.enable_xpu;
+ lite_option.device_id = option.device_id;
+ lite_option.xpu_l3_workspace_size = option.xpu_l3_workspace_size;
+ lite_option.xpu_locked = option.xpu_locked;
+ lite_option.xpu_autotune = option.xpu_autotune;
+ lite_option.xpu_autotune_file = option.xpu_autotune_file;
+ lite_option.xpu_precision = option.xpu_precision;
+ lite_option.xpu_adaptive_seqlen = option.xpu_adaptive_seqlen;
+ lite_option.xpu_enable_multi_stream = option.xpu_enable_multi_stream;
+
FDASSERT(option.model_format == ModelFormat::PADDLE,
"LiteBackend only support model format of ModelFormat::PADDLE");
backend_ = utils::make_unique();
diff --git a/fastdeploy/runtime.h b/fastdeploy/runtime.h
index 9c22c929f..064be2fce 100755
--- a/fastdeploy/runtime.h
+++ b/fastdeploy/runtime.h
@@ -102,6 +102,37 @@ struct FASTDEPLOY_DECL RuntimeOption {
/// Use TimVX to inference
void UseTimVX();
+ ///
+ /// \brief Turn on XPU.
+ ///
+ /// \param xpu_id the XPU card to use (default is 0).
+ /// \param l3_workspace_size The size of the video memory allocated by the l3
+ /// cache, the maximum is 16M.
+ /// \param locked Whether the allocated L3 cache can be locked. If false,
+ /// it means that the L3 cache is not locked, and the allocated L3
+ /// cache can be shared by multiple models, and multiple models
+ /// sharing the L3 cache will be executed sequentially on the card.
+ /// \param autotune Whether to autotune the conv operator in the model. If
+ /// true, when the conv operator of a certain dimension is executed
+ /// for the first time, it will automatically search for a better
+ /// algorithm to improve the performance of subsequent conv operators
+ /// of the same dimension.
+ /// \param autotune_file Specify the path of the autotune file. If
+ /// autotune_file is specified, the algorithm specified in the
+ /// file will be used and autotune will not be performed again.
+ /// \param precision Calculation accuracy of multi_encoder
+ /// \param adaptive_seqlen Is the input of multi_encoder variable length
+ /// \param enable_multi_stream Whether to enable the multi stream of xpu.
+ ///
+ void UseXpu(int xpu_id = 0,
+ int l3_workspace_size = 0xfffc00,
+ bool locked = false,
+ bool autotune = true,
+ const std::string& autotune_file = "",
+ const std::string& precision = "int16",
+ bool adaptive_seqlen = false,
+ bool enable_multi_stream = false);
+
void SetExternalStream(void* external_stream);
/*
@@ -354,6 +385,7 @@ struct FASTDEPLOY_DECL RuntimeOption {
std::string lite_optimized_model_dir = "";
std::string lite_nnadapter_subgraph_partition_config_path = "";
bool enable_timvx = false;
+ bool enable_xpu = false;
// ======Only for Trt Backend=======
std::map> trt_max_shape;
@@ -386,6 +418,15 @@ struct FASTDEPLOY_DECL RuntimeOption {
fastdeploy::rknpu2::CoreMask rknpu2_core_mask_ =
fastdeploy::rknpu2::CoreMask::RKNN_NPU_CORE_AUTO;
+ // ======Only for XPU Backend=======
+ int xpu_l3_workspace_size = 0xfffc00;
+ bool xpu_locked = false;
+ bool xpu_autotune = true;
+ std::string xpu_autotune_file = "";
+ std::string xpu_precision = "int16";
+ bool xpu_adaptive_seqlen = false;
+ bool xpu_enable_multi_stream = false;
+
std::string model_file = ""; // Path of model file
std::string params_file = ""; // Path of parameters file, can be empty
// format of input model
diff --git a/fastdeploy/vision/classification/ppcls/model.cc b/fastdeploy/vision/classification/ppcls/model.cc
index 5065bbfc2..e1b8d5249 100755
--- a/fastdeploy/vision/classification/ppcls/model.cc
+++ b/fastdeploy/vision/classification/ppcls/model.cc
@@ -29,6 +29,7 @@ PaddleClasModel::PaddleClasModel(const std::string& model_file,
Backend::LITE};
valid_gpu_backends = {Backend::ORT, Backend::PDINFER, Backend::TRT};
valid_timvx_backends = {Backend::LITE};
+ valid_xpu_backends = {Backend::LITE};
valid_ipu_backends = {Backend::PDINFER};
} else if (model_format == ModelFormat::ONNX) {
valid_cpu_backends = {Backend::ORT, Backend::OPENVINO};
diff --git a/fastdeploy/vision/detection/contrib/rknpu2/postprocessor.h b/fastdeploy/vision/detection/contrib/rknpu2/postprocessor.h
index 238c1c465..6dcda3b77 100755
--- a/fastdeploy/vision/detection/contrib/rknpu2/postprocessor.h
+++ b/fastdeploy/vision/detection/contrib/rknpu2/postprocessor.h
@@ -72,10 +72,11 @@ class FASTDEPLOY_DECL RKYOLOPostprocessor {
}
// Set Anchor
- void SetAnchor(std::vector anchors,int anchor_per_branch){
+ void SetAnchor(std::vector anchors, int anchor_per_branch) {
anchors_ = anchors;
anchor_per_branch_ = anchor_per_branch;
- };
+ }
+
private:
std::vector anchors_ = {10, 13, 16, 30, 33, 23, 30, 61, 62,
45, 59, 119, 116, 90, 156, 198, 373, 326};
diff --git a/fastdeploy/vision/detection/contrib/rknpu2/utils.h b/fastdeploy/vision/detection/contrib/rknpu2/utils.h
index 1d28b5f0e..1fa533082 100644
--- a/fastdeploy/vision/detection/contrib/rknpu2/utils.h
+++ b/fastdeploy/vision/detection/contrib/rknpu2/utils.h
@@ -31,4 +31,4 @@ int NMS(int valid_count, std::vector& output_locations,
} // namespace detection
} // namespace vision
-} // namespace fastdeploy
\ No newline at end of file
+} // namespace fastdeploy
diff --git a/fastdeploy/vision/detection/contrib/yolov5/yolov5.cc b/fastdeploy/vision/detection/contrib/yolov5/yolov5.cc
index 92d53dd10..d1bb31f22 100755
--- a/fastdeploy/vision/detection/contrib/yolov5/yolov5.cc
+++ b/fastdeploy/vision/detection/contrib/yolov5/yolov5.cc
@@ -27,6 +27,7 @@ YOLOv5::YOLOv5(const std::string& model_file, const std::string& params_file,
} else {
valid_cpu_backends = {Backend::PDINFER, Backend::ORT, Backend::LITE};
valid_gpu_backends = {Backend::PDINFER, Backend::ORT, Backend::TRT};
+ valid_xpu_backends = {Backend::LITE};
valid_timvx_backends = {Backend::LITE};
}
runtime_option = custom_option;
diff --git a/fastdeploy/vision/detection/ppdet/model.h b/fastdeploy/vision/detection/ppdet/model.h
index 5175bc4e6..090c99de7 100755
--- a/fastdeploy/vision/detection/ppdet/model.h
+++ b/fastdeploy/vision/detection/ppdet/model.h
@@ -185,7 +185,7 @@ class FASTDEPLOY_DECL PaddleYOLOv5 : public PPDetBase {
const ModelFormat& model_format = ModelFormat::PADDLE)
: PPDetBase(model_file, params_file, config_file, custom_option,
model_format) {
- valid_cpu_backends = {Backend::ORT,Backend::PDINFER};
+ valid_cpu_backends = {Backend::ORT, Backend::PDINFER};
valid_gpu_backends = {Backend::ORT, Backend::PDINFER, Backend::TRT};
initialized = Initialize();
}
@@ -201,7 +201,7 @@ class FASTDEPLOY_DECL PaddleYOLOv6 : public PPDetBase {
const ModelFormat& model_format = ModelFormat::PADDLE)
: PPDetBase(model_file, params_file, config_file, custom_option,
model_format) {
- valid_cpu_backends = {Backend::OPENVINO, Backend::ORT,Backend::PDINFER};
+ valid_cpu_backends = {Backend::OPENVINO, Backend::ORT, Backend::PDINFER};
valid_gpu_backends = {Backend::ORT, Backend::PDINFER, Backend::TRT};
initialized = Initialize();
}
@@ -217,7 +217,7 @@ class FASTDEPLOY_DECL PaddleYOLOv7 : public PPDetBase {
const ModelFormat& model_format = ModelFormat::PADDLE)
: PPDetBase(model_file, params_file, config_file, custom_option,
model_format) {
- valid_cpu_backends = {Backend::ORT,Backend::PDINFER};
+ valid_cpu_backends = {Backend::ORT, Backend::PDINFER};
valid_gpu_backends = {Backend::ORT, Backend::PDINFER, Backend::TRT};
initialized = Initialize();
}
diff --git a/python/fastdeploy/runtime.py b/python/fastdeploy/runtime.py
index 6461da66d..f9334efbf 100755
--- a/python/fastdeploy/runtime.py
+++ b/python/fastdeploy/runtime.py
@@ -245,6 +245,34 @@ class RuntimeOption:
return
return self._option.use_gpu(device_id)
+ def use_xpu(self,
+ device_id=0,
+ l3_workspace_size=16 * 1024 * 1024,
+ locked=False,
+ autotune=True,
+ autotune_file="",
+ precision="int16",
+ adaptive_seqlen=False,
+ enable_multi_stream=False):
+ """Inference with XPU
+
+ :param device_id: (int)The index of XPU will be used for inference, default 0
+ :param l3_workspace_size: (int)The size of the video memory allocated by the l3 cache, the maximum is 16M, default 16M
+ :param locked: (bool)Whether the allocated L3 cache can be locked. If false, it means that the L3 cache is not locked,
+ and the allocated L3 cache can be shared by multiple models, and multiple models
+ :param autotune: (bool)Whether to autotune the conv operator in the model.
+ If true, when the conv operator of a certain dimension is executed for the first time,
+ it will automatically search for a better algorithm to improve the performance of subsequent conv operators of the same dimension.
+ :param autotune_file: (str)Specify the path of the autotune file. If autotune_file is specified,
+ the algorithm specified in the file will be used and autotune will not be performed again.
+ :param precision: (str)Calculation accuracy of multi_encoder
+ :param adaptive_seqlen: (bool)adaptive_seqlen Is the input of multi_encoder variable length
+ :param enable_multi_stream: (bool)Whether to enable the multi stream of xpu.
+ """
+ return self._option.use_xpu(device_id, l3_workspace_size, locked,
+ autotune, autotune_file, precision,
+ adaptive_seqlen, enable_multi_stream)
+
def use_cpu(self):
"""Inference with CPU
"""
diff --git a/python/setup.py b/python/setup.py
index b4dc111c6..19a857678 100755
--- a/python/setup.py
+++ b/python/setup.py
@@ -65,11 +65,13 @@ setup_configs["ENABLE_POROS_BACKEND"] = os.getenv("ENABLE_POROS_BACKEND",
"OFF")
setup_configs["ENABLE_TRT_BACKEND"] = os.getenv("ENABLE_TRT_BACKEND", "OFF")
setup_configs["ENABLE_LITE_BACKEND"] = os.getenv("ENABLE_LITE_BACKEND", "OFF")
+setup_configs["PADDLELITE_URL"] = os.getenv("PADDLELITE_URL", "OFF")
setup_configs["ENABLE_VISION"] = os.getenv("ENABLE_VISION", "OFF")
setup_configs["ENABLE_FLYCV"] = os.getenv("ENABLE_FLYCV", "OFF")
setup_configs["ENABLE_TEXT"] = os.getenv("ENABLE_TEXT", "OFF")
setup_configs["WITH_GPU"] = os.getenv("WITH_GPU", "OFF")
setup_configs["WITH_IPU"] = os.getenv("WITH_IPU", "OFF")
+setup_configs["WITH_XPU"] = os.getenv("WITH_XPU", "OFF")
setup_configs["BUILD_ON_JETSON"] = os.getenv("BUILD_ON_JETSON", "OFF")
setup_configs["TRT_DIRECTORY"] = os.getenv("TRT_DIRECTORY", "UNDEFINED")
setup_configs["CUDA_DIRECTORY"] = os.getenv("CUDA_DIRECTORY",
@@ -78,10 +80,12 @@ setup_configs["LIBRARY_NAME"] = PACKAGE_NAME
setup_configs["PY_LIBRARY_NAME"] = PACKAGE_NAME + "_main"
setup_configs["OPENCV_DIRECTORY"] = os.getenv("OPENCV_DIRECTORY", "")
setup_configs["ORT_DIRECTORY"] = os.getenv("ORT_DIRECTORY", "")
-setup_configs["PADDLEINFERENCE_DIRECTORY"] = os.getenv("PADDLEINFERENCE_DIRECTORY", "")
+setup_configs["PADDLEINFERENCE_DIRECTORY"] = os.getenv(
+ "PADDLEINFERENCE_DIRECTORY", "")
setup_configs["RKNN2_TARGET_SOC"] = os.getenv("RKNN2_TARGET_SOC", "")
-if setup_configs["RKNN2_TARGET_SOC"] != "" or setup_configs["BUILD_ON_JETSON"] != "OFF":
+if setup_configs["RKNN2_TARGET_SOC"] != "" or setup_configs[
+ "BUILD_ON_JETSON"] != "OFF":
REQUIRED_PACKAGES = REQUIRED_PACKAGES.replace("opencv-python", "")
if setup_configs["WITH_GPU"] == "ON" or setup_configs[
From 0990ab9b50f13109bbd82b1299d37eb75301e2ec Mon Sep 17 00:00:00 2001
From: Jason
Date: Thu, 15 Dec 2022 21:17:59 +0800
Subject: [PATCH 70/77] Revert "[Backend] Add KunlunXin XPU deploy support"
(#893)
Revert "[Backend] Add KunlunXin XPU deploy support (#747)"
This reverts commit 5be839b322b6adf46329933361b22b4984c42ef8.
---
CMakeLists.txt | 20 +--
FastDeploy.cmake.in | 5 -
cmake/summary.cmake | 2 -
docs/README_CN.md | 1 -
docs/README_EN.md | 5 +-
docs/cn/build_and_install/README.md | 8 +-
docs/cn/build_and_install/a311d.md | 3 +-
docs/cn/build_and_install/rv1126.md | 7 +-
docs/cn/build_and_install/xpu.md | 75 ---------
docs/en/build_and_install/README.md | 5 -
docs/en/build_and_install/a311d.md | 105 ------------
docs/en/build_and_install/rv1126.md | 105 ------------
docs/en/build_and_install/xpu.md | 78 ---------
.../classification/paddleclas/cpp/README.md | 4 -
.../classification/paddleclas/cpp/infer.cc | 30 +---
.../paddleclas/python/README.md | 2 -
.../classification/paddleclas/python/infer.py | 3 -
.../detection/yolov5/cpp/CMakeLists.txt | 4 -
.../vision/detection/yolov5/cpp/README.md | 24 +--
examples/vision/detection/yolov5/cpp/infer.cc | 2 +-
.../yolov5/cpp/infer_paddle_model.cc | 154 ------------------
.../vision/detection/yolov5/python/README.md | 11 +-
.../vision/detection/yolov5/python/infer.py | 21 +--
fastdeploy/backends/lite/lite_backend.cc | 56 ++-----
fastdeploy/backends/lite/lite_backend.h | 9 -
fastdeploy/core/fd_type.cc | 6 -
fastdeploy/core/fd_type.h | 2 +-
fastdeploy/fastdeploy_model.cc | 33 +---
fastdeploy/fastdeploy_model.h | 4 -
fastdeploy/pybind/runtime.cc | 17 +-
fastdeploy/runtime.cc | 35 +---
fastdeploy/runtime.h | 41 -----
.../vision/classification/ppcls/model.cc | 1 -
.../detection/contrib/rknpu2/postprocessor.h | 5 +-
.../vision/detection/contrib/rknpu2/utils.h | 2 +-
.../vision/detection/contrib/yolov5/yolov5.cc | 1 -
fastdeploy/vision/detection/ppdet/model.h | 6 +-
python/fastdeploy/runtime.py | 28 ----
python/setup.py | 8 +-
39 files changed, 58 insertions(+), 870 deletions(-)
mode change 100755 => 100644 docs/README_CN.md
mode change 100755 => 100644 docs/README_EN.md
delete mode 100755 docs/cn/build_and_install/xpu.md
mode change 100755 => 100644 docs/en/build_and_install/README.md
delete mode 100755 docs/en/build_and_install/a311d.md
delete mode 100755 docs/en/build_and_install/rv1126.md
delete mode 100755 docs/en/build_and_install/xpu.md
mode change 100755 => 100644 examples/vision/classification/paddleclas/cpp/README.md
mode change 100755 => 100644 examples/vision/classification/paddleclas/cpp/infer.cc
mode change 100755 => 100644 examples/vision/classification/paddleclas/python/README.md
mode change 100755 => 100644 examples/vision/classification/paddleclas/python/infer.py
mode change 100755 => 100644 examples/vision/detection/yolov5/cpp/CMakeLists.txt
mode change 100755 => 100644 examples/vision/detection/yolov5/cpp/README.md
mode change 100755 => 100644 examples/vision/detection/yolov5/cpp/infer.cc
delete mode 100755 examples/vision/detection/yolov5/cpp/infer_paddle_model.cc
mode change 100755 => 100644 examples/vision/detection/yolov5/python/README.md
mode change 100755 => 100644 examples/vision/detection/yolov5/python/infer.py
mode change 100755 => 100644 fastdeploy/pybind/runtime.cc
mode change 100755 => 100644 fastdeploy/runtime.cc
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 0bcfa4084..c02e887a5 100755
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -40,7 +40,7 @@ if(NOT MSVC)
add_definitions(-D_GLIBCXX_USE_CXX11_ABI=1)
endif(NOT MSVC)
-if(UNIX AND (NOT APPLE) AND (NOT ANDROID) AND (NOT WITH_TIMVX))
+if(UNIX AND (NOT APPLE) AND (NOT ANDROID) AND (NOT ENABLE_TIMVX))
include(${PROJECT_SOURCE_DIR}/cmake/patchelf.cmake)
endif()
@@ -64,8 +64,7 @@ option(ENABLE_LITE_BACKEND "Whether to enable paddle lite backend." OFF)
option(ENABLE_VISION "Whether to enable vision models usage." OFF)
option(ENABLE_TEXT "Whether to enable text models usage." OFF)
option(ENABLE_FLYCV "Whether to enable flycv to boost image preprocess." OFF)
-option(WITH_TIMVX "Whether to compile for TIMVX deploy." OFF)
-option(WITH_XPU "Whether to compile for KunlunXin XPU deploy." OFF)
+option(ENABLE_TIMVX "Whether to compile for TIMVX deploy." OFF)
option(WITH_TESTING "Whether to compile with unittest." OFF)
############################# Options for Android cross compiling #########################
option(WITH_OPENCV_STATIC "Use OpenCV static lib for Android." OFF)
@@ -139,23 +138,10 @@ set(HEAD_DIR "${PROJECT_SOURCE_DIR}/${CSRCS_DIR_NAME}")
include_directories(${HEAD_DIR})
include_directories(${CMAKE_CURRENT_BINARY_DIR})
-if (WITH_TIMVX)
+if (ENABLE_TIMVX)
include(${PROJECT_SOURCE_DIR}/cmake/timvx.cmake)
endif()
-if (WITH_XPU)
- if(NOT ENABLE_LITE_BACKEND)
- message(WARNING "While compiling with -DWITH_XPU=ON, will force to set -DENABLE_LITE_BACKEND=ON")
- set(ENABLE_LITE_BACKEND ON)
- endif()
- if(NOT CMAKE_HOST_SYSTEM_PROCESSOR MATCHES "x86_64")
- message(FATAL_ERROR "XPU is only supported on Linux x64 platform")
- endif()
- if(NOT PADDLELITE_URL)
- set(PADDLELITE_URL "https://bj.bcebos.com/fastdeploy/third_libs/lite-linux-x64-xpu-20221215.tgz")
- endif()
-endif()
-
if(ANDROID OR IOS)
if(ENABLE_ORT_BACKEND)
diff --git a/FastDeploy.cmake.in b/FastDeploy.cmake.in
index d8c0df3d6..fd0ea847a 100755
--- a/FastDeploy.cmake.in
+++ b/FastDeploy.cmake.in
@@ -27,7 +27,6 @@ set(OPENCV_DIRECTORY "@OPENCV_DIRECTORY@")
set(ORT_DIRECTORY "@ORT_DIRECTORY@")
set(OPENVINO_DIRECTORY "@OPENVINO_DIRECTORY@")
set(RKNN2_TARGET_SOC "@RKNN2_TARGET_SOC@")
-set(WITH_XPU @WITH_XPU@)
set(FASTDEPLOY_LIBS "")
set(FASTDEPLOY_INCS "")
@@ -238,10 +237,6 @@ if(ENABLE_PADDLE_FRONTEND)
list(APPEND FASTDEPLOY_LIBS ${PADDLE2ONNX_LIB})
endif()
-if(WITH_XPU)
- list(APPEND FASTDEPLOY_LIBS -lpthread -lrt -ldl)
-endif()
-
remove_duplicate_libraries(FASTDEPLOY_LIBS)
# Print compiler information
diff --git a/cmake/summary.cmake b/cmake/summary.cmake
index fc5c246ba..7a729484e 100755
--- a/cmake/summary.cmake
+++ b/cmake/summary.cmake
@@ -37,8 +37,6 @@ function(fastdeploy_summary)
message(STATUS " ENABLE_POROS_BACKEND : ${ENABLE_POROS_BACKEND}")
message(STATUS " ENABLE_TRT_BACKEND : ${ENABLE_TRT_BACKEND}")
message(STATUS " ENABLE_OPENVINO_BACKEND : ${ENABLE_OPENVINO_BACKEND}")
- message(STATUS " WITH_TIMVX : ${WITH_TIMVX}")
- message(STATUS " WITH_XPU : ${WITH_XPU}")
if(ENABLE_ORT_BACKEND)
message(STATUS " ONNXRuntime version : ${ONNXRUNTIME_VERSION}")
endif()
diff --git a/docs/README_CN.md b/docs/README_CN.md
old mode 100755
new mode 100644
index ec0267f45..a0b7b51d0
--- a/docs/README_CN.md
+++ b/docs/README_CN.md
@@ -8,7 +8,6 @@
- [GPU部署环境编译安装](cn/build_and_install/gpu.md)
- [CPU部署环境编译安装](cn/build_and_install/cpu.md)
- [IPU部署环境编译安装](cn/build_and_install/ipu.md)
-- [昆仑芯XPU部署环境编译安装](cn/build_and_install/xpu.md)
- [Jetson部署环境编译安装](cn/build_and_install/jetson.md)
- [Android平台部署环境编译安装](cn/build_and_install/android.md)
- [服务化部署镜像编译安装](../serving/docs/zh_CN/compile.md)
diff --git a/docs/README_EN.md b/docs/README_EN.md
old mode 100755
new mode 100644
index ed257c59b..c4f9adfa3
--- a/docs/README_EN.md
+++ b/docs/README_EN.md
@@ -8,7 +8,6 @@
- [Build and Install FastDeploy Library on GPU Platform](en/build_and_install/gpu.md)
- [Build and Install FastDeploy Library on CPU Platform](en/build_and_install/cpu.md)
- [Build and Install FastDeploy Library on IPU Platform](en/build_and_install/ipu.md)
-- [Build and Install FastDeploy Library on KunlunXin XPU Platform](en/build_and_install/xpu.md)
- [Build and Install FastDeploy Library on Nvidia Jetson Platform](en/build_and_install/jetson.md)
- [Build and Install FastDeploy Library on Android Platform](en/build_and_install/android.md)
- [Build and Install FastDeploy Serving Deployment Image](../serving/docs/EN/compile-en.md)
@@ -20,10 +19,10 @@
- [A Quick Start on Runtime Python](en/quick_start/runtime/python.md)
- [A Quick Start on Runtime C++](en/quick_start/runtime/cpp.md)
-## API
+## API
- [Python API](https://baidu-paddle.github.io/fastdeploy-api/python/html/)
-- [C++ API](https://baidu-paddle.github.io/fastdeploy-api/cpp/html/)
+- [C++ API](https://baidu-paddle.github.io/fastdeploy-api/cpp/html/)
- [Android Java API](../java/android)
## Performance Optimization
diff --git a/docs/cn/build_and_install/README.md b/docs/cn/build_and_install/README.md
index 221852d2c..7ec07c7b8 100755
--- a/docs/cn/build_and_install/README.md
+++ b/docs/cn/build_and_install/README.md
@@ -13,7 +13,6 @@
- [Android平台部署环境](android.md)
- [瑞芯微RV1126部署环境](rv1126.md)
- [晶晨A311D部署环境](a311d.md)
-- [昆仑芯XPU部署环境](xpu.md)
## FastDeploy编译选项说明
@@ -21,11 +20,10 @@
| 选项 | 说明 |
|:------------------------|:--------------------------------------------------------------------------|
| ENABLE_ORT_BACKEND | 默认OFF, 是否编译集成ONNX Runtime后端(CPU/GPU上推荐打开) |
-| ENABLE_PADDLE_BACKEND | 默认OFF,是否编译集成Paddle Inference后端(CPU/GPU上推荐打开) |
-| ENABLE_LITE_BACKEND | 默认OFF,是否编译集成Paddle Lite后端(编译Android库时需要设置为ON) |
+| ENABLE_PADDLE_BACKEND | 默认OFF,是否编译集成Paddle Inference后端(CPU/GPU上推荐打开) |
+| ENABLE_LITE_BACKEND | 默认OFF,是否编译集成Paddle Lite后端(编译Android库时需要设置为ON) |
| ENABLE_RKNPU2_BACKEND | 默认OFF,是否编译集成RKNPU2后端(RK3588/RK3568/RK3566上推荐打开) |
-| WITH_XPU | 默认OFF,当在昆仑芯XPU上部署时,需设置为ON |
-| WITH_TIMVX | 默认OFF,需要在RV1126/RV1109/A311D上部署时,需设置为ON |
+| WITH_TIMVX | 默认OFF,需要在RV1126/RV1109/A311D上部署时,需设置为ON |
| ENABLE_TRT_BACKEND | 默认OFF,是否编译集成TensorRT后端(GPU上推荐打开) |
| ENABLE_OPENVINO_BACKEND | 默认OFF,是否编译集成OpenVINO后端(CPU上推荐打开) |
| ENABLE_VISION | 默认OFF,是否编译集成视觉模型的部署模块 |
diff --git a/docs/cn/build_and_install/a311d.md b/docs/cn/build_and_install/a311d.md
index 20dde7046..4b3773f0d 100755
--- a/docs/cn/build_and_install/a311d.md
+++ b/docs/cn/build_and_install/a311d.md
@@ -9,8 +9,7 @@ FastDeploy 基于 Paddle-Lite 后端支持在晶晨 NPU 上进行部署推理。
|编译选项|默认值|说明|备注|
|:---|:---|:---|:---|
|ENABLE_LITE_BACKEND|OFF|编译A311D部署库时需要设置为ON| - |
-|WITH_TIMVX|OFF|编译A311D部署库时需要设置为ON| - |
-|TARGET_ABI|NONE|编译RK库时需要设置为arm64| - |
+|WITH_TIMVX|OFF|编译A311D部署库时需要设置为ON| - |
更多编译选项请参考[FastDeploy编译选项说明](./README.md)
diff --git a/docs/cn/build_and_install/rv1126.md b/docs/cn/build_and_install/rv1126.md
index f3643f070..ff0050715 100755
--- a/docs/cn/build_and_install/rv1126.md
+++ b/docs/cn/build_and_install/rv1126.md
@@ -8,9 +8,8 @@ FastDeploy基于 Paddle-Lite 后端支持在瑞芯微(Rockchip)Soc 上进行
相关编译选项说明如下:
|编译选项|默认值|说明|备注|
|:---|:---|:---|:---|
-|ENABLE_LITE_BACKEND|OFF|编译RK库时需要设置为ON| - |
-|WITH_TIMVX|OFF|编译RK库时需要设置为ON| - |
-|TARGET_ABI|NONE|编译RK库时需要设置为armhf| - |
+|ENABLE_LITE_BACKEND|OFF|编译RK库时需要设置为ON| - |
+|WITH_TIMVX|OFF|编译RK库时需要设置为ON| - |
更多编译选项请参考[FastDeploy编译选项说明](./README.md)
@@ -87,7 +86,7 @@ dmesg | grep Galcore
wget https://paddlelite-demo.bj.bcebos.com/devices/generic/PaddleLite-generic-demo.tar.gz
tar -xf PaddleLite-generic-demo.tar.gz
```
-2. 使用 `uname -a` 查看 `Linux Kernel` 版本,确定为 `Linux` 系统 4.19.111 版本
+2. 使用 `uname -a` 查看 `Linux Kernel` 版本,确定为 `Linux` 系统 4.19.111 版本,
3. 将 `PaddleLite-generic-demo/libs/PaddleLite/linux/armhf/lib/verisilicon_timvx/viv_sdk_6_4_6_5/lib/1126/4.19.111/` 路径下的 `galcore.ko` 上传至开发板。
4. 登录开发板,命令行输入 `sudo rmmod galcore` 来卸载原始驱动,输入 `sudo insmod galcore.ko` 来加载传上设备的驱动。(是否需要 sudo 根据开发板实际情况,部分 adb 链接的设备请提前 adb root)。此步骤如果操作失败,请跳转至方法 2。
diff --git a/docs/cn/build_and_install/xpu.md b/docs/cn/build_and_install/xpu.md
deleted file mode 100755
index 014eb804d..000000000
--- a/docs/cn/build_and_install/xpu.md
+++ /dev/null
@@ -1,75 +0,0 @@
-# 昆仑芯 XPU 部署环境编译安装
-
-FastDeploy 基于 Paddle-Lite 后端支持在昆仑芯 XPU 上进行部署推理。
-更多详细的信息请参考:[PaddleLite部署示例](https://www.paddlepaddle.org.cn/lite/develop/demo_guides/kunlunxin_xpu.html#xpu)。
-
-本文档介绍如何编译基于 PaddleLite 的 C++ FastDeploy 编译库。
-
-相关编译选项说明如下:
-|编译选项|默认值|说明|备注|
-|:---|:---|:---|:---|
-| WITH_XPU| OFF | 需要在XPU上部署时需要设置为ON | - |
-| ENABLE_ORT_BACKEND | OFF | 是否编译集成ONNX Runtime后端 | - |
-| ENABLE_PADDLE_BACKEND | OFF | 是否编译集成Paddle Inference后端 | - |
-| ENABLE_OPENVINO_BACKEND | OFF | 是否编译集成OpenVINO后端 | - |
-| ENABLE_VISION | OFF | 是否编译集成视觉模型的部署模块 | - |
-| ENABLE_TEXT | OFF | 是否编译集成文本NLP模型的部署模块 | - |
-
-第三方库依赖指定(不设定如下参数,会自动下载预编译库)
-| 选项 | 说明 |
-| :---------------------- | :--------------------------------------------------------------------------------------------- |
-| ORT_DIRECTORY | 当开启ONNX Runtime后端时,用于指定用户本地的ONNX Runtime库路径;如果不指定,编译过程会自动下载ONNX Runtime库 |
-| OPENCV_DIRECTORY | 当ENABLE_VISION=ON时,用于指定用户本地的OpenCV库路径;如果不指定,编译过程会自动下载OpenCV库 |
-| OPENVINO_DIRECTORY | 当开启OpenVINO后端时, 用于指定用户本地的OpenVINO库路径;如果不指定,编译过程会自动下载OpenVINO库 |
-更多编译选项请参考[FastDeploy编译选项说明](./README.md)
-
-## 基于 PaddleLite 的 C++ FastDeploy 库编译
-- OS: Linux
-- gcc/g++: version >= 8.2
-- cmake: version >= 3.15
-此外更推荐开发者自行安装,编译时通过`-DOPENCV_DIRECTORY`来指定环境中的OpenCV(如若不指定-DOPENCV_DIRECTORY,会自动下载FastDeploy提供的预编译的OpenCV,但在**Linux平台**无法支持Video的读取,以及imshow等可视化界面功能)
-```
-sudo apt-get install libopencv-dev
-```
-编译命令如下:
-```bash
-# Download the latest source code
-git clone https://github.com/PaddlePaddle/FastDeploy.git
-cd FastDeploy
-mkdir build && cd build
-
-# CMake configuration with KunlunXin xpu toolchain
-cmake -DWITH_XPU=ON \
- -DWITH_GPU=OFF \ # 不编译 GPU
- -DENABLE_ORT_BACKEND=ON \ # 可选择开启 ORT 后端
- -DENABLE_PADDLE_BACKEND=ON \ # 可选择开启 Paddle 后端
- -DCMAKE_INSTALL_PREFIX=fastdeploy-xpu \
- -DENABLE_VISION=ON \ # 是否编译集成视觉模型的部署模块,可选择开启
- -DOPENCV_DIRECTORY=/usr/lib/x86_64-linux-gnu/cmake/opencv4 \
- ..
-
-# Build FastDeploy KunlunXin XPU C++ SDK
-make -j8
-make install
-```
-编译完成之后,会生成 fastdeploy-xpu 目录,表示基于 PadddleLite 的 FastDeploy 库编译完成。
-
-## Python 编译
-编译命令如下:
-```bash
-git clone https://github.com/PaddlePaddle/FastDeploy.git
-cd FastDeploy/python
-export WITH_XPU=ON
-export WITH_GPU=OFF
-export ENABLE_ORT_BACKEND=ON
-export ENABLE_PADDLE_BACKEND=ON
-export ENABLE_VISION=ON
-# OPENCV_DIRECTORY可选,不指定会自动下载FastDeploy提供的预编译OpenCV库
-export OPENCV_DIRECTORY=/usr/lib/x86_64-linux-gnu/cmake/opencv4
-
-python setup.py build
-python setup.py bdist_wheel
-```
-编译完成即会在 `FastDeploy/python/dist` 目录下生成编译后的 `wheel` 包,直接 pip install 即可
-
-编译过程中,如若修改编译参数,为避免带来缓存影响,可删除 `FastDeploy/python` 目录下的 `build` 和 `.setuptools-cmake-build` 两个子目录后再重新编译
diff --git a/docs/en/build_and_install/README.md b/docs/en/build_and_install/README.md
old mode 100755
new mode 100644
index 0958c3778..4beaaeec8
--- a/docs/en/build_and_install/README.md
+++ b/docs/en/build_and_install/README.md
@@ -12,9 +12,6 @@ English | [中文](../../cn/build_and_install/README.md)
- [Build and Install on IPU Platform](ipu.md)
- [Build and Install on Nvidia Jetson Platform](jetson.md)
- [Build and Install on Android Platform](android.md)
-- [Build and Install on RV1126 Platform](rv1126.md)
-- [Build and Install on A311D Platform](a311d.md)
-- [Build and Install on KunlunXin XPU Platform](xpu.md)
## Build options
@@ -28,8 +25,6 @@ English | [中文](../../cn/build_and_install/README.md)
| ENABLE_VISION | Default OFF,whether to enable vision models deployment module |
| ENABLE_TEXT | Default OFF,whether to enable text models deployment module |
| WITH_GPU | Default OFF, if build on GPU, this need to be ON |
-| WITH_XPU | Default OFF,if deploy on KunlunXin XPU,this need to be ON |
-| WITH_TIMVX | Default OFF,if deploy on RV1126/RV1109/A311D,this need to be ON |
| CUDA_DIRECTORY | Default /usr/local/cuda, if build on GPU, this defines the path of CUDA(>=11.2) |
| TRT_DIRECTORY | If build with ENABLE_TRT_BACKEND=ON, this defines the path of TensorRT(>=8.4) |
| ORT_DIRECTORY | [Optional] If build with ENABLE_ORT_BACKEND=ON, this flag defines the path of ONNX Runtime, but if this flag is not set, it will download ONNX Runtime library automatically |
diff --git a/docs/en/build_and_install/a311d.md b/docs/en/build_and_install/a311d.md
deleted file mode 100755
index 872c1b93c..000000000
--- a/docs/en/build_and_install/a311d.md
+++ /dev/null
@@ -1,105 +0,0 @@
-# How to Build A311D Deployment Environment
-
-FastDeploy supports AI deployment on Rockchip Soc based on Paddle-Lite backend. For more detailed information, please refer to: [PaddleLite Deployment Example](https://www.paddlepaddle.org.cn/lite/develop/demo_guides/verisilicon_timvx.html).
-
-This document describes how to compile the PaddleLite-based C++ FastDeploy cross-compilation library.
-
-The relevant compilation options are described as follows:
-|Compile Options|Default Values|Description|Remarks|
-|:---|:---|:---|:---|
-|ENABLE_LITE_BACKEND|OFF|It needs to be set to ON when compiling the A311D library| - |
-|WITH_TIMVX|OFF|It needs to be set to ON when compiling the A311D library| - |
-|TARGET_ABI|NONE|It needs to be set to arm64 when compiling the A311D library| - |
-
-For more compilation options, please refer to [Description of FastDeploy compilation options](./README.md)
-
-## Cross-compilation environment construction
-
-### Host Environment Requirements
-- os:Ubuntu == 16.04
-- cmake: version >= 3.10.0
-
-### Building the compilation environment
-You can enter the FastDeploy/tools/timvx directory and use the following command to install:
-```bash
-cd FastDeploy/tools/timvx
-bash install.sh
-```
-You can also install it with the following commands:
-```bash
- # 1. Install basic software
-apt update
-apt-get install -y --no-install-recommends \
- gcc g++ git make wget python unzip
-
-# 2. Install arm gcc toolchains
-apt-get install -y --no-install-recommends \
- g++-arm-linux-gnueabi gcc-arm-linux-gnueabi \
- g++-arm-linux-gnueabihf gcc-arm-linux-gnueabihf \
- gcc-aarch64-linux-gnu g++-aarch64-linux-gnu
-
-# 3. Install cmake 3.10 or above
-wget -c https://mms-res.cdn.bcebos.com/cmake-3.10.3-Linux-x86_64.tar.gz && \
- tar xzf cmake-3.10.3-Linux-x86_64.tar.gz && \
- mv cmake-3.10.3-Linux-x86_64 /opt/cmake-3.10 && \
- ln -s /opt/cmake-3.10/bin/cmake /usr/bin/cmake && \
- ln -s /opt/cmake-3.10/bin/ccmake /usr/bin/ccmake
-```
-
-## FastDeploy cross-compilation library compilation based on PaddleLite
-After setting up the cross-compilation environment, the compilation command is as follows:
-```bash
-# Download the latest source code
-git clone https://github.com/PaddlePaddle/FastDeploy.git
-cd FastDeploy
-mkdir build && cd build
-
-# CMake configuration with A311D toolchain
-cmake -DCMAKE_TOOLCHAIN_FILE=./../cmake/toolchain.cmake \
- -DWITH_TIMVX=ON \
- -DTARGET_ABI=arm64 \
- -DCMAKE_INSTALL_PREFIX=fastdeploy-tmivx \
- -DENABLE_VISION=ON \ # 是否编译集成视觉模型的部署模块,可选择开启
- -Wno-dev ..
-
-# Build FastDeploy A311D C++ SDK
-make -j8
-make install
-```
-After the compilation is complete, the fastdeploy-tmivx directory will be generated, indicating that the FastDeploy library based on PadddleLite TIM-VX has been compiled.
-
-## Prepare the Soc environment
-Before deployment, ensure that the version of the driver galcore.so of the Verisilicon Linux Kernel NPU meets the requirements. Before deployment, please log in to the development board, and enter the following command through the command line to query the NPU driver version. The recommended version of the Rockchip driver is: 6.4.4.3
-```bash
-dmesg | grep Galcore
-```
-If the current version does not comply with the above, please read the following content carefully to ensure that the underlying NPU driver environment is correct.
-
-There are two ways to modify the current NPU driver version:
-1. Manually replace the NPU driver version. (recommend)
-2. flash the machine, and flash the firmware that meets the requirements of the NPU driver version.
-
-### Manually replace the NPU driver version
-1. Use the following command to download and decompress the PaddleLite demo, which provides ready-made driver files
-```bash
-wget https://paddlelite-demo.bj.bcebos.com/devices/generic/PaddleLite-generic-demo.tar.gz
-tar -xf PaddleLite-generic-demo.tar.gz
-```
-2. Use `uname -a` to check `Linux Kernel` version, it is determined to be version 4.19.111.
-3. Upload `galcore.ko` under `PaddleLite-generic-demo/libs/PaddleLite/linux/arm64/lib/verisilicon_timvx/viv_sdk_6_4_4_3/lib/a311d/4.9.113` path to the development board.
-4. Log in to the development board, enter `sudo rmmod galcore` on the command line to uninstall the original driver, and enter `sudo insmod galcore.ko` to load the uploaded device driver. (Whether sudo is needed depends on the actual situation of the development board. For some adb-linked devices, please adb root in advance). If this step fails, go to method 2.
-5. Enter `dmesg | grep Galcore` in the development board to query the NPU driver version, and it is determined to be: 6.4.4.3
-
-### flash
-According to the specific development board model, ask the development board seller or the official website customer service for the firmware and flashing method corresponding to the 6.4.4.3 version of the NPU driver.
-
-For more details, please refer to: [PaddleLite prepares the device environment](https://www.paddlepaddle.org.cn/lite/develop/demo_guides/verisilicon_timvx.html#zhunbeishebeihuanjing)
-
-## Deployment example based on FastDeploy on A311D
-1. For deploying the PaddleClas classification model on A311D, please refer to: [C++ deployment example of PaddleClas classification model on A311D](../../../examples/vision/classification/paddleclas/a311d/README.md)
-
-2. For deploying PPYOLOE detection model on A311D, please refer to: [C++ deployment example of PPYOLOE detection model on A311D](../../../examples/vision/detection/paddledetection/a311d/README.md)
-
-3. For deploying YOLOv5 detection model on A311D, please refer to: [C++ Deployment Example of YOLOv5 Detection Model on A311D](../../../examples/vision/detection/yolov5/a311d/README.md)
-
-4. For deploying PP-LiteSeg segmentation model on A311D, please refer to: [C++ Deployment Example of PP-LiteSeg Segmentation Model on A311D](../../../examples/vision/segmentation/paddleseg/a311d/README.md)
diff --git a/docs/en/build_and_install/rv1126.md b/docs/en/build_and_install/rv1126.md
deleted file mode 100755
index a56535363..000000000
--- a/docs/en/build_and_install/rv1126.md
+++ /dev/null
@@ -1,105 +0,0 @@
-# How to Build RV1126 Deployment Environment
-
-FastDeploy supports AI deployment on Rockchip Soc based on Paddle-Lite backend. For more detailed information, please refer to: [PaddleLite Deployment Example](https://www.paddlepaddle.org.cn/lite/develop/demo_guides/verisilicon_timvx.html).
-
-This document describes how to compile the PaddleLite-based C++ FastDeploy cross-compilation library.
-
-The relevant compilation options are described as follows:
-|Compile Options|Default Values|Description|Remarks|
-|:---|:---|:---|:---|
-|ENABLE_LITE_BACKEND|OFF|It needs to be set to ON when compiling the RK library| - |
-|WITH_TIMVX|OFF|It needs to be set to ON when compiling the RK library| - |
-|TARGET_ABI|NONE|It needs to be set to armhf when compiling the RK library| - |
-
-For more compilation options, please refer to [Description of FastDeploy compilation options](./README.md)
-
-## Cross-compilation environment construction
-
-### Host Environment Requirements
-- os:Ubuntu == 16.04
-- cmake: version >= 3.10.0
-
-### Building the compilation environment
-You can enter the FastDeploy/tools/timvx directory and use the following command to install:
-```bash
-cd FastDeploy/tools/timvx
-bash install.sh
-```
-You can also install it with the following commands:
-```bash
- # 1. Install basic software
-apt update
-apt-get install -y --no-install-recommends \
- gcc g++ git make wget python unzip
-
-# 2. Install arm gcc toolchains
-apt-get install -y --no-install-recommends \
- g++-arm-linux-gnueabi gcc-arm-linux-gnueabi \
- g++-arm-linux-gnueabihf gcc-arm-linux-gnueabihf \
- gcc-aarch64-linux-gnu g++-aarch64-linux-gnu
-
-# 3. Install cmake 3.10 or above
-wget -c https://mms-res.cdn.bcebos.com/cmake-3.10.3-Linux-x86_64.tar.gz && \
- tar xzf cmake-3.10.3-Linux-x86_64.tar.gz && \
- mv cmake-3.10.3-Linux-x86_64 /opt/cmake-3.10 && \
- ln -s /opt/cmake-3.10/bin/cmake /usr/bin/cmake && \
- ln -s /opt/cmake-3.10/bin/ccmake /usr/bin/ccmake
-```
-
-## FastDeploy cross-compilation library compilation based on PaddleLite
-After setting up the cross-compilation environment, the compilation command is as follows:
-```bash
-# Download the latest source code
-git clone https://github.com/PaddlePaddle/FastDeploy.git
-cd FastDeploy
-mkdir build && cd build
-
-# CMake configuration with RK toolchain
-cmake -DCMAKE_TOOLCHAIN_FILE=./../cmake/toolchain.cmake \
- -DWITH_TIMVX=ON \
- -DTARGET_ABI=armhf \
- -DCMAKE_INSTALL_PREFIX=fastdeploy-tmivx \
- -DENABLE_VISION=ON \ # 是否编译集成视觉模型的部署模块,可选择开启
- -Wno-dev ..
-
-# Build FastDeploy RV1126 C++ SDK
-make -j8
-make install
-```
-After the compilation is complete, the fastdeploy-tmivx directory will be generated, indicating that the FastDeploy library based on PadddleLite TIM-VX has been compiled.
-
-## Prepare the Soc environment
-Before deployment, ensure that the version of the driver galcore.so of the Verisilicon Linux Kernel NPU meets the requirements. Before deployment, please log in to the development board, and enter the following command through the command line to query the NPU driver version. The recommended version of the Rockchip driver is: 6.4.6.5
-```bash
-dmesg | grep Galcore
-```
-If the current version does not comply with the above, please read the following content carefully to ensure that the underlying NPU driver environment is correct.
-
-There are two ways to modify the current NPU driver version:
-1. Manually replace the NPU driver version. (recommend)
-2. flash the machine, and flash the firmware that meets the requirements of the NPU driver version.
-
-### Manually replace the NPU driver version
-1. Use the following command to download and decompress the PaddleLite demo, which provides ready-made driver files
-```bash
-wget https://paddlelite-demo.bj.bcebos.com/devices/generic/PaddleLite-generic-demo.tar.gz
-tar -xf PaddleLite-generic-demo.tar.gz
-```
-2. Use `uname -a` to check `Linux Kernel` version, it is determined to be version 4.19.111.
-3. Upload `galcore.ko` under `PaddleLite-generic-demo/libs/PaddleLite/linux/armhf/lib/verisilicon_timvx/viv_sdk_6_4_6_5/lib/1126/4.19.111/` path to the development board.
-4. Log in to the development board, enter `sudo rmmod galcore` on the command line to uninstall the original driver, and enter `sudo insmod galcore.ko` to load the uploaded device driver. (Whether sudo is needed depends on the actual situation of the development board. For some adb-linked devices, please adb root in advance). If this step fails, go to method 2.
-5. Enter `dmesg | grep Galcore` in the development board to query the NPU driver version, and it is determined to be: 6.4.6.5
-
-### flash
-According to the specific development board model, ask the development board seller or the official website customer service for the firmware and flashing method corresponding to the 6.4.6.5 version of the NPU driver.
-
-For more details, please refer to: [PaddleLite prepares the device environment](https://www.paddlepaddle.org.cn/lite/develop/demo_guides/verisilicon_timvx.html#zhunbeishebeihuanjing)
-
-## Deployment example based on FastDeploy on RV1126
-1. For deploying the PaddleClas classification model on RV1126, please refer to: [C++ deployment example of PaddleClas classification model on RV1126](../../../examples/vision/classification/paddleclas/rv1126/README.md)
-
-2. For deploying PPYOLOE detection model on RV1126, please refer to: [C++ deployment example of PPYOLOE detection model on RV1126](../../../examples/vision/detection/paddledetection/rv1126/README.md)
-
-3. For deploying YOLOv5 detection model on RV1126, please refer to: [C++ Deployment Example of YOLOv5 Detection Model on RV1126](../../../examples/vision/detection/yolov5/rv1126/README.md)
-
-4. For deploying PP-LiteSeg segmentation model on RV1126, please refer to: [C++ Deployment Example of PP-LiteSeg Segmentation Model on RV1126](../../../examples/vision/segmentation/paddleseg/rv1126/README.md)
diff --git a/docs/en/build_and_install/xpu.md b/docs/en/build_and_install/xpu.md
deleted file mode 100755
index 403837e5d..000000000
--- a/docs/en/build_and_install/xpu.md
+++ /dev/null
@@ -1,78 +0,0 @@
-# How to Build KunlunXin XPU Deployment Environment
-
-FastDeploy supports deployment AI on KunlunXin XPU based on Paddle-Lite backend. For more detailed information, please refer to: [PaddleLite Deployment Example](https://www.paddlepaddle.org.cn/lite/develop/demo_guides/kunlunxin_xpu.html#xpu)。
-
-This document describes how to compile the C++ FastDeploy library based on PaddleLite.
-
-The relevant compilation options are described as follows:
-|Compile Options|Default Values|Description|Remarks|
-|:---|:---|:---|:---|
-| ENABLE_LITE_BACKEND | OFF | It needs to be set to ON when compiling the RK library| - |
-| WITH_XPU | OFF | It needs to be set to ON when compiling the KunlunXin XPU library| - |
-| ENABLE_ORT_BACKEND | OFF | whether to intergrate ONNX Runtime backend | - |
-| ENABLE_PADDLE_BACKEND | OFF | whether to intergrate Paddle Inference backend | - |
-| ENABLE_OPENVINO_BACKEND | OFF | whether to intergrate OpenVINO backend | - |
-| ENABLE_VISION | OFF | whether to intergrate vision models | - |
-| ENABLE_TEXT | OFF | whether to intergrate text models | - |
-
-The configuration for third libraries(Optional, if the following option is not defined, the prebuilt third libraries will download automaticly while building FastDeploy).
-| Option | Description |
-| :---------------------- | :--------------------------------------------------------------------------------------------- |
-| ORT_DIRECTORY | While ENABLE_ORT_BACKEND=ON, use ORT_DIRECTORY to specify your own ONNX Runtime library path. |
-| OPENCV_DIRECTORY | While ENABLE_VISION=ON, use OPENCV_DIRECTORY to specify your own OpenCV library path. |
-| OPENVINO_DIRECTORY | While ENABLE_OPENVINO_BACKEND=ON, use OPENVINO_DIRECTORY to specify your own OpenVINO library path. |
-
-For more compilation options, please refer to [Description of FastDeploy compilation options](./README.md)
-
-## C++ FastDeploy library compilation based on PaddleLite
-- OS: Linux
-- gcc/g++: version >= 8.2
-- cmake: version >= 3.15
-
-It it recommend install OpenCV library manually, and define `-DOPENCV_DIRECTORY` to set path of OpenCV library(If the flag is not defined, a prebuilt OpenCV library will be downloaded automaticly while building FastDeploy, but the prebuilt OpenCV cannot support reading video file or other function e.g `imshow`)
-```
-sudo apt-get install libopencv-dev
-```
-
-The compilation command is as follows:
-```bash
-# Download the latest source code
-git clone https://github.com/PaddlePaddle/FastDeploy.git
-cd FastDeploy
-mkdir build && cd build
-
-# CMake configuration with KunlunXin xpu toolchain
-cmake -DWITH_XPU=ON \
- -DWITH_GPU=OFF \
- -DENABLE_ORT_BACKEND=ON \
- -DENABLE_PADDLE_BACKEND=ON \
- -DCMAKE_INSTALL_PREFIX=fastdeploy-xpu \
- -DENABLE_VISION=ON \
- -DOPENCV_DIRECTORY=/usr/lib/x86_64-linux-gnu/cmake/opencv4 \
- ..
-
-# Build FastDeploy KunlunXin XPU C++ SDK
-make -j8
-make install
-```
-After the compilation is complete, the fastdeploy-xpu directory will be generated, indicating that the PadddleLite-based FastDeploy library has been compiled.
-
-## Python compile
-The compilation command is as follows:
-```bash
-git clone https://github.com/PaddlePaddle/FastDeploy.git
-cd FastDeploy/python
-export WITH_XPU=ON
-export WITH_GPU=OFF
-export ENABLE_ORT_BACKEND=ON
-export ENABLE_PADDLE_BACKEND=ON
-export ENABLE_VISION=ON
-# The OPENCV_DIRECTORY is optional, if not exported, a prebuilt OpenCV library will be downloaded
-export OPENCV_DIRECTORY=/usr/lib/x86_64-linux-gnu/cmake/opencv4
-
-python setup.py build
-python setup.py bdist_wheel
-```
-After the compilation is completed, the compiled `wheel` package will be generated in the `FastDeploy/python/dist` directory, just pip install it directly
-
-During the compilation process, if you modify the compilation parameters, in order to avoid the cache impact, you can delete the two subdirectories `build` and `.setuptools-cmake-build` under the `FastDeploy/python` directory and then recompile.
diff --git a/examples/vision/classification/paddleclas/cpp/README.md b/examples/vision/classification/paddleclas/cpp/README.md
old mode 100755
new mode 100644
index dff76da18..066340467
--- a/examples/vision/classification/paddleclas/cpp/README.md
+++ b/examples/vision/classification/paddleclas/cpp/README.md
@@ -30,10 +30,6 @@ wget https://gitee.com/paddlepaddle/PaddleClas/raw/release/2.4/deploy/images/Ima
./infer_demo ResNet50_vd_infer ILSVRC2012_val_00000010.jpeg 1
# GPU上TensorRT推理
./infer_demo ResNet50_vd_infer ILSVRC2012_val_00000010.jpeg 2
-# IPU推理
-./infer_demo ResNet50_vd_infer ILSVRC2012_val_00000010.jpeg 3
-# KunlunXin XPU推理
-./infer_demo ResNet50_vd_infer ILSVRC2012_val_00000010.jpeg 4
```
以上命令只适用于Linux或MacOS, Windows下SDK的使用方式请参考:
diff --git a/examples/vision/classification/paddleclas/cpp/infer.cc b/examples/vision/classification/paddleclas/cpp/infer.cc
old mode 100755
new mode 100644
index 244accfa7..bdd87ecdc
--- a/examples/vision/classification/paddleclas/cpp/infer.cc
+++ b/examples/vision/classification/paddleclas/cpp/infer.cc
@@ -96,32 +96,6 @@ void IpuInfer(const std::string& model_dir, const std::string& image_file) {
std::cout << res.Str() << std::endl;
}
-void XpuInfer(const std::string& model_dir, const std::string& image_file) {
- auto model_file = model_dir + sep + "inference.pdmodel";
- auto params_file = model_dir + sep + "inference.pdiparams";
- auto config_file = model_dir + sep + "inference_cls.yaml";
-
- auto option = fastdeploy::RuntimeOption();
- option.UseXpu();
- auto model = fastdeploy::vision::classification::PaddleClasModel(
- model_file, params_file, config_file, option);
- if (!model.Initialized()) {
- std::cerr << "Failed to initialize." << std::endl;
- return;
- }
-
- auto im = cv::imread(image_file);
-
- fastdeploy::vision::ClassifyResult res;
- if (!model.Predict(im, &res)) {
- std::cerr << "Failed to predict." << std::endl;
- return;
- }
-
- // print res
- std::cout << res.Str() << std::endl;
-}
-
void TrtInfer(const std::string& model_dir, const std::string& image_file) {
auto model_file = model_dir + sep + "inference.pdmodel";
auto params_file = model_dir + sep + "inference.pdiparams";
@@ -154,7 +128,7 @@ int main(int argc, char* argv[]) {
"e.g ./infer_demo ./ResNet50_vd ./test.jpeg 0"
<< 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; 3: run with ipu; 4: run with xpu."
+ "with gpu; 2: run with gpu and use tensorrt backend."
<< std::endl;
return -1;
}
@@ -167,8 +141,6 @@ int main(int argc, char* argv[]) {
TrtInfer(argv[1], argv[2]);
} else if (std::atoi(argv[3]) == 3) {
IpuInfer(argv[1], argv[2]);
- } else if (std::atoi(argv[3]) == 4) {
- XpuInfer(argv[1], argv[2]);
}
return 0;
}
diff --git a/examples/vision/classification/paddleclas/python/README.md b/examples/vision/classification/paddleclas/python/README.md
old mode 100755
new mode 100644
index 5a1baff7f..9d17e6f65
--- a/examples/vision/classification/paddleclas/python/README.md
+++ b/examples/vision/classification/paddleclas/python/README.md
@@ -25,8 +25,6 @@ python infer.py --model ResNet50_vd_infer --image ILSVRC2012_val_00000010.jpeg -
python infer.py --model ResNet50_vd_infer --image ILSVRC2012_val_00000010.jpeg --device gpu --use_trt True --topk 1
# IPU推理(注意:IPU推理首次运行会有序列化模型的操作,有一定耗时,需要耐心等待)
python infer.py --model ResNet50_vd_infer --image ILSVRC2012_val_00000010.jpeg --device ipu --topk 1
-# XPU推理
-python infer.py --model ResNet50_vd_infer --image ILSVRC2012_val_00000010.jpeg --device xpu --topk 1
```
运行完成后返回结果如下所示
diff --git a/examples/vision/classification/paddleclas/python/infer.py b/examples/vision/classification/paddleclas/python/infer.py
old mode 100755
new mode 100644
index 3c150533c..0b2d35a21
--- a/examples/vision/classification/paddleclas/python/infer.py
+++ b/examples/vision/classification/paddleclas/python/infer.py
@@ -35,9 +35,6 @@ def build_option(args):
if args.device.lower() == "ipu":
option.use_ipu()
- if args.device.lower() == "xpu":
- option.use_xpu()
-
if args.use_trt:
option.use_trt_backend()
return option
diff --git a/examples/vision/detection/yolov5/cpp/CMakeLists.txt b/examples/vision/detection/yolov5/cpp/CMakeLists.txt
old mode 100755
new mode 100644
index 2b3f8c54f..93540a7e8
--- a/examples/vision/detection/yolov5/cpp/CMakeLists.txt
+++ b/examples/vision/detection/yolov5/cpp/CMakeLists.txt
@@ -12,7 +12,3 @@ include_directories(${FASTDEPLOY_INCS})
add_executable(infer_demo ${PROJECT_SOURCE_DIR}/infer.cc)
# 添加FastDeploy库依赖
target_link_libraries(infer_demo ${FASTDEPLOY_LIBS})
-
-add_executable(infer_paddle_demo ${PROJECT_SOURCE_DIR}/infer_paddle_model.cc)
-# 添加FastDeploy库依赖
-target_link_libraries(infer_paddle_demo ${FASTDEPLOY_LIBS})
diff --git a/examples/vision/detection/yolov5/cpp/README.md b/examples/vision/detection/yolov5/cpp/README.md
old mode 100755
new mode 100644
index 581f1c49b..ece3826a5
--- a/examples/vision/detection/yolov5/cpp/README.md
+++ b/examples/vision/detection/yolov5/cpp/README.md
@@ -12,33 +12,16 @@
```bash
mkdir build
cd build
-# 下载 FastDeploy 预编译库,用户可在上文提到的`FastDeploy预编译库`中自行选择合适的版本使用
+# 下载FastDeploy预编译库,用户可在上文提到的`FastDeploy预编译库`中自行选择合适的版本使用
wget https://bj.bcebos.com/fastdeploy/release/cpp/fastdeploy-linux-x64-x.x.x.tgz
tar xvf fastdeploy-linux-x64-x.x.x.tgz
cmake .. -DFASTDEPLOY_INSTALL_DIR=${PWD}/fastdeploy-linux-x64-x.x.x
make -j
-#下载官方转换好的 yolov5 Paddle 模型文件和测试图片
-wget https://bj.bcebos.com/paddlehub/fastdeploy/yolov5s_infer.tar
-tar -xvf yolov5s_infer.tar
-wget https://gitee.com/paddlepaddle/PaddleDetection/raw/release/2.4/demo/000000014439.jpg
-
-
-# CPU推理
-./infer_paddle_demo yolov5s_infer 000000014439.jpg 0
-# GPU推理
-./infer_paddle_demo yolov5s_infer 000000014439.jpg 1
-# GPU上TensorRT推理
-./infer_paddle_demo yolov5s_infer 000000014439.jpg 2
-# XPU推理
-./infer_paddle_demo yolov5s_infer 000000014439.jpg 3
-```
-
-上述的模型为 Paddle 模型的推理,如果想要做 ONNX 模型的推理,可以按照如下步骤:
-```bash
-# 1. 下载官方转换好的 yolov5 ONNX 模型文件和测试图片
+#下载官方转换好的yolov5模型文件和测试图片
wget https://bj.bcebos.com/paddlehub/fastdeploy/yolov5s.onnx
wget https://gitee.com/paddlepaddle/PaddleDetection/raw/release/2.4/demo/000000014439.jpg
+
# CPU推理
./infer_demo yolov5s.onnx 000000014439.jpg 0
# GPU推理
@@ -46,6 +29,7 @@ wget https://gitee.com/paddlepaddle/PaddleDetection/raw/release/2.4/demo/0000000
# GPU上TensorRT推理
./infer_demo yolov5s.onnx 000000014439.jpg 2
```
+
运行完成可视化结果如下图所示
diff --git a/examples/vision/detection/yolov5/cpp/infer.cc b/examples/vision/detection/yolov5/cpp/infer.cc
old mode 100755
new mode 100644
index fb20686de..1c3907918
--- a/examples/vision/detection/yolov5/cpp/infer.cc
+++ b/examples/vision/detection/yolov5/cpp/infer.cc
@@ -102,4 +102,4 @@ int main(int argc, char* argv[]) {
TrtInfer(argv[1], argv[2]);
}
return 0;
-}
\ No newline at end of file
+}
diff --git a/examples/vision/detection/yolov5/cpp/infer_paddle_model.cc b/examples/vision/detection/yolov5/cpp/infer_paddle_model.cc
deleted file mode 100755
index d5692ce7c..000000000
--- a/examples/vision/detection/yolov5/cpp/infer_paddle_model.cc
+++ /dev/null
@@ -1,154 +0,0 @@
-// 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"
-#ifdef WIN32
-const char sep = '\\';
-#else
-const char sep = '/';
-#endif
-
-void CpuInfer(const std::string& model_dir, const std::string& image_file) {
- auto model_file = model_dir + sep + "model.pdmodel";
- auto params_file = model_dir + sep + "model.pdiparams";
- fastdeploy::RuntimeOption option;
- option.UseCpu();
- auto model = fastdeploy::vision::detection::YOLOv5(
- model_file, params_file, option, fastdeploy::ModelFormat::PADDLE);
- if (!model.Initialized()) {
- std::cerr << "Failed to initialize." << std::endl;
- return;
- }
-
- 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("vis_result.jpg", vis_im);
- std::cout << "Visualized result saved in ./vis_result.jpg" << std::endl;
-}
-
-void GpuInfer(const std::string& model_dir, const std::string& image_file) {
- 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::detection::YOLOv5(
- model_file, params_file, option, fastdeploy::ModelFormat::PADDLE);
- if (!model.Initialized()) {
- std::cerr << "Failed to initialize." << std::endl;
- return;
- }
-
- 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("vis_result.jpg", vis_im);
- std::cout << "Visualized result saved in ./vis_result.jpg" << std::endl;
-}
-
-void TrtInfer(const std::string& model_dir, const std::string& image_file) {
- auto model_file = model_dir + sep + "model.pdmodel";
- auto params_file = model_dir + sep + "model.pdiparams";
- auto option = fastdeploy::RuntimeOption();
- option.UseGpu();
- option.UseTrtBackend();
- option.SetTrtInputShape("images", {1, 3, 640, 640});
- auto model = fastdeploy::vision::detection::YOLOv5(
- model_file, params_file, option, fastdeploy::ModelFormat::PADDLE);
-
- if (!model.Initialized()) {
- std::cerr << "Failed to initialize." << std::endl;
- return;
- }
-
- 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::Visualize::VisDetection(im, res);
- cv::imwrite("vis_result.jpg", vis_im);
- std::cout << "Visualized result saved in ./vis_result.jpg" << std::endl;
-}
-
-void XpuInfer(const std::string& model_dir, const std::string& image_file) {
- auto model_file = model_dir + sep + "model.pdmodel";
- auto params_file = model_dir + sep + "model.pdiparams";
- fastdeploy::RuntimeOption option;
- option.UseXpu();
- auto model = fastdeploy::vision::detection::YOLOv5(
- model_file, params_file, option, fastdeploy::ModelFormat::PADDLE);
-
- if (!model.Initialized()) {
- std::cerr << "Failed to initialize." << std::endl;
- return;
- }
-
- 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("vis_result.jpg", vis_im);
- std::cout << "Visualized result saved in ./vis_result.jpg" << std::endl;
-}
-
-int main(int argc, char* argv[]) {
- if (argc < 4) {
- std::cout << "Usage: infer_demo path/to/model path/to/image run_option, "
- "e.g ./infer_model ./yolov5s_infer ./test.jpeg 0"
- << 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; 3: run with KunlunXin XPU."
- << std::endl;
- return -1;
- }
-
- if (std::atoi(argv[3]) == 0) {
- CpuInfer(argv[1], argv[2]);
- } else if (std::atoi(argv[3]) == 1) {
- GpuInfer(argv[1], argv[2]);
- } else if (std::atoi(argv[3]) == 2) {
- TrtInfer(argv[1], argv[2]);
- } else if (std::atoi(argv[3]) == 3) {
- XpuInfer(argv[1], argv[2]);
- }
- return 0;
-}
diff --git a/examples/vision/detection/yolov5/python/README.md b/examples/vision/detection/yolov5/python/README.md
old mode 100755
new mode 100644
index 83f6ed781..4f47b3084
--- a/examples/vision/detection/yolov5/python/README.md
+++ b/examples/vision/detection/yolov5/python/README.md
@@ -13,18 +13,15 @@ git clone https://github.com/PaddlePaddle/FastDeploy.git
cd examples/vision/detection/yolov5/python/
#下载yolov5模型文件和测试图片
-wget https://bj.bcebos.com/paddlehub/fastdeploy/yolov5s_infer.tar
-tar -xf yolov5s_infer.tar
+wget https://bj.bcebos.com/paddlehub/fastdeploy/yolov5s.onnx
wget https://gitee.com/paddlepaddle/PaddleDetection/raw/release/2.4/demo/000000014439.jpg
# CPU推理
-python infer.py --model yolov5s_infer --image 000000014439.jpg --device cpu
+python infer.py --model yolov5s.onnx --image 000000014439.jpg --device cpu
# GPU推理
-python infer.py --model yolov5s_infer --image 000000014439.jpg --device gpu
+python infer.py --model yolov5s.onnx --image 000000014439.jpg --device gpu
# GPU上使用TensorRT推理
-python infer.py --model yolov5s_infer --image 000000014439.jpg --device gpu --use_trt True
-# XPU推理
-python infer.py --model yolov5s_infer --image 000000014439.jpg --device xpu
+python infer.py --model yolov5s.onnx --image 000000014439.jpg --device gpu --use_trt True
```
运行完成可视化结果如下图所示
diff --git a/examples/vision/detection/yolov5/python/infer.py b/examples/vision/detection/yolov5/python/infer.py
old mode 100755
new mode 100644
index b155af0ed..462740e9c
--- a/examples/vision/detection/yolov5/python/infer.py
+++ b/examples/vision/detection/yolov5/python/infer.py
@@ -1,20 +1,20 @@
import fastdeploy as fd
import cv2
-import os
def parse_arguments():
import argparse
import ast
parser = argparse.ArgumentParser()
- parser.add_argument("--model", default=None, help="Path of yolov5 model.")
+ parser.add_argument(
+ "--model", default=None, help="Path of yolov5 onnx model.")
parser.add_argument(
"--image", default=None, help="Path of test image file.")
parser.add_argument(
"--device",
type=str,
default='cpu',
- help="Type of inference device, support 'cpu' or 'gpu' or 'xpu'.")
+ help="Type of inference device, support 'cpu' or 'gpu'.")
parser.add_argument(
"--use_trt",
type=ast.literal_eval,
@@ -25,8 +25,6 @@ def parse_arguments():
def build_option(args):
option = fd.RuntimeOption()
- if args.device.lower() == "xpu":
- option.use_xpu()
if args.device.lower() == "gpu":
option.use_gpu()
@@ -39,15 +37,14 @@ def build_option(args):
args = parse_arguments()
+if args.model is None:
+ model = fd.download_model(name='YOLOv5s')
+else:
+ model = args.model
+
# 配置runtime,加载模型
runtime_option = build_option(args)
-model_file = os.path.join(args.model, "model.pdmodel")
-params_file = os.path.join(args.model, "model.pdiparams")
-model = fd.vision.detection.YOLOv5(
- model_file,
- params_file,
- runtime_option=runtime_option,
- model_format=fd.ModelFormat.PADDLE)
+model = fd.vision.detection.YOLOv5(model, runtime_option=runtime_option)
# 预测图片检测结果
if args.image is None:
diff --git a/fastdeploy/backends/lite/lite_backend.cc b/fastdeploy/backends/lite/lite_backend.cc
index 20afa5e28..7e3e09f8d 100755
--- a/fastdeploy/backends/lite/lite_backend.cc
+++ b/fastdeploy/backends/lite/lite_backend.cc
@@ -43,33 +43,24 @@ void LiteBackend::BuildOption(const LiteBackendOption& option) {
option_ = option;
std::vector valid_places;
if (option_.enable_int8) {
- if(option_.enable_xpu) {
- valid_places.push_back(
- paddle::lite_api::Place{TARGET(kXPU), PRECISION(kInt8)});
- } else {
- valid_places.push_back(
+ valid_places.push_back(
paddle::lite_api::Place{TARGET(kARM), PRECISION(kInt8)});
- }
FDINFO << "Lite::Backend enable_int8 option is ON ! Lite::Backend will "
<< "inference with int8 precision!" << std::endl;
}
if (option_.enable_fp16) {
- if(option_.enable_xpu){
+ paddle::lite_api::MobileConfig check_fp16_config;
+ // Determine whether the device supports the FP16
+ // instruction set (or whether it is an arm device
+ // of the armv8.2 architecture)
+ supported_fp16_ = check_fp16_config.check_fp16_valid();
+ if (supported_fp16_) {
valid_places.push_back(
- paddle::lite_api::Place{TARGET(kXPU), PRECISION(kFP16)});
+ paddle::lite_api::Place{TARGET(kARM), PRECISION(kFP16)});
+ FDINFO << "Your device is supported fp16 ! Lite::Backend will "
+ << "inference with fp16 precision!" << std::endl;
} else {
- paddle::lite_api::MobileConfig check_fp16_config;
- // Determine whether the device supports the FP16
- // instruction set (or whether it is an arm device
- // of the armv8.2 architecture)
- supported_fp16_ = check_fp16_config.check_fp16_valid();
- if (supported_fp16_) {
- valid_places.push_back(
- paddle::lite_api::Place{TARGET(kARM), PRECISION(kFP16)});
- FDINFO << "The device supports FP16, Lite::Backend will inference with FP16 precision." << std::endl;
- } else {
- FDWARNING << "The device doesn't support FP16, will fallback to FP32.";
- }
+ FDWARNING << "This device is not supported fp16, will skip fp16 option.";
}
}
if (!option_.nnadapter_subgraph_partition_config_path.empty()) {
@@ -90,24 +81,8 @@ void LiteBackend::BuildOption(const LiteBackendOption& option) {
valid_places.push_back(
paddle::lite_api::Place{TARGET(kARM), PRECISION(kInt8)});
}
-
- if(option_.enable_xpu){
- valid_places.push_back(
- paddle::lite_api::Place{TARGET(kXPU), PRECISION(kFloat)});
- valid_places.push_back(
- paddle::lite_api::Place{TARGET(kX86), PRECISION(kFloat)});
- config_.set_xpu_dev_per_thread(option_.device_id);
- config_.set_xpu_workspace_l3_size_per_thread(option_.xpu_l3_workspace_size);
- config_.set_xpu_l3_cache_method(option_.xpu_l3_workspace_size, option_.xpu_locked);
- config_.set_xpu_conv_autotune(option_.xpu_autotune, option_.xpu_autotune_file);
- config_.set_xpu_multi_encoder_method(option_.xpu_precision, option_.xpu_adaptive_seqlen);
- if (option_.xpu_enable_multi_stream) {
- config_.enable_xpu_multi_stream();
- }
- } else {
- valid_places.push_back(
+ valid_places.push_back(
paddle::lite_api::Place{TARGET(kARM), PRECISION(kFloat)});
- }
config_.set_valid_places(valid_places);
if (option_.threads > 0) {
config_.set_threads(option_.threads);
@@ -185,9 +160,7 @@ bool LiteBackend::InitFromPaddle(const std::string& model_file,
auto shape = tensor->shape();
info.shape.assign(shape.begin(), shape.end());
info.name = output_names[i];
- if(!option_.enable_xpu){
- info.dtype = LiteDataTypeToFD(tensor->precision());
- }
+ info.dtype = LiteDataTypeToFD(tensor->precision());
outputs_desc_.emplace_back(info);
}
@@ -266,9 +239,6 @@ bool LiteBackend::Infer(std::vector& inputs,
outputs->resize(outputs_desc_.size());
for (size_t i = 0; i < outputs_desc_.size(); ++i) {
auto tensor = predictor_->GetOutput(i);
- if(outputs_desc_[i].dtype != LiteDataTypeToFD(tensor->precision())){
- outputs_desc_[i].dtype = LiteDataTypeToFD(tensor->precision());
- }
(*outputs)[i].Resize(tensor->shape(), outputs_desc_[i].dtype,
outputs_desc_[i].name);
memcpy((*outputs)[i].MutableData(), tensor->data(),
diff --git a/fastdeploy/backends/lite/lite_backend.h b/fastdeploy/backends/lite/lite_backend.h
index 0221f507f..279acf5df 100755
--- a/fastdeploy/backends/lite/lite_backend.h
+++ b/fastdeploy/backends/lite/lite_backend.h
@@ -45,15 +45,6 @@ struct LiteBackendOption {
// Such as fp16, different device target (kARM/kXPU/kNPU/...)
std::string nnadapter_subgraph_partition_config_path = "";
bool enable_timvx = false;
- bool enable_xpu = false;
- int device_id = 0;
- int xpu_l3_workspace_size = 0xfffc00;
- bool xpu_locked = false;
- bool xpu_autotune = true;
- std::string xpu_autotune_file = "";
- std::string xpu_precision = "int16";
- bool xpu_adaptive_seqlen = false;
- bool xpu_enable_multi_stream = false;
};
// Convert data type from paddle lite to fastdeploy
diff --git a/fastdeploy/core/fd_type.cc b/fastdeploy/core/fd_type.cc
index 3624b732d..ba3319dbc 100755
--- a/fastdeploy/core/fd_type.cc
+++ b/fastdeploy/core/fd_type.cc
@@ -62,9 +62,6 @@ std::string Str(const Device& d) {
case Device::TIMVX:
out = "Device::TIMVX";
break;
- case Device::XPU:
- out = "Device::XPU";
- break;
default:
out = "Device::UNKOWN";
}
@@ -85,9 +82,6 @@ std::ostream& operator<<(std::ostream& out,const Device& d){
case Device::TIMVX:
out << "Device::TIMVX";
break;
- case Device::XPU:
- out << "Device::XPU";
- break;
default:
out << "Device::UNKOWN";
}
diff --git a/fastdeploy/core/fd_type.h b/fastdeploy/core/fd_type.h
index d39c56fdf..ba18d8e36 100755
--- a/fastdeploy/core/fd_type.h
+++ b/fastdeploy/core/fd_type.h
@@ -22,7 +22,7 @@
namespace fastdeploy {
-enum FASTDEPLOY_DECL Device { CPU, GPU, RKNPU, IPU, TIMVX, XPU};
+enum FASTDEPLOY_DECL Device { CPU, GPU, RKNPU, IPU, TIMVX};
FASTDEPLOY_DECL std::string Str(const Device& d);
diff --git a/fastdeploy/fastdeploy_model.cc b/fastdeploy/fastdeploy_model.cc
index 4d7a8e364..ad8c1329d 100755
--- a/fastdeploy/fastdeploy_model.cc
+++ b/fastdeploy/fastdeploy_model.cc
@@ -51,7 +51,6 @@ bool FastDeployModel::InitRuntimeWithSpecifiedBackend() {
bool use_ipu = (runtime_option.device == Device::IPU);
bool use_rknpu = (runtime_option.device == Device::RKNPU);
bool use_timvx = (runtime_option.device == Device::TIMVX);
- bool use_xpu = (runtime_option.device == Device::XPU);
if (use_gpu) {
if (!IsSupported(valid_gpu_backends, runtime_option.backend)) {
@@ -68,11 +67,6 @@ bool FastDeployModel::InitRuntimeWithSpecifiedBackend() {
FDERROR << "The valid timvx backends of model " << ModelName() << " are " << Str(valid_timvx_backends) << ", " << runtime_option.backend << " is not supported." << std::endl;
return false;
}
- } else if (use_xpu) {
- if (!IsSupported(valid_xpu_backends, runtime_option.backend)) {
- FDERROR << "The valid xpu backends of model " << ModelName() << " are " << Str(valid_xpu_backends) << ", " << runtime_option.backend << " is not supported." << std::endl;
- return false;
- }
} else if(use_ipu) {
if (!IsSupported(valid_ipu_backends, runtime_option.backend)) {
FDERROR << "The valid ipu backends of model " << ModelName() << " are " << Str(valid_ipu_backends) << ", " << runtime_option.backend << " is not supported." << std::endl;
@@ -108,8 +102,6 @@ bool FastDeployModel::InitRuntimeWithSpecifiedDevice() {
return CreateRKNPUBackend();
} else if (runtime_option.device == Device::TIMVX) {
return CreateTimVXBackend();
- } else if (runtime_option.device == Device::XPU) {
- return CreateXPUBackend();
} else if (runtime_option.device == Device::IPU) {
#ifdef WITH_IPU
return CreateIpuBackend();
@@ -119,7 +111,7 @@ bool FastDeployModel::InitRuntimeWithSpecifiedDevice() {
return false;
#endif
}
- FDERROR << "Only support CPU/GPU/IPU/RKNPU/TIMVX/XPU now." << std::endl;
+ FDERROR << "Only support CPU/GPU/IPU/RKNPU/TIMVX now." << std::endl;
return false;
}
@@ -233,29 +225,6 @@ bool FastDeployModel::CreateTimVXBackend() {
return false;
}
-bool FastDeployModel::CreateXPUBackend() {
- if (valid_xpu_backends.size() == 0) {
- FDERROR << "There's no valid xpu backends for model: " << ModelName()
- << std::endl;
- return false;
- }
-
- for (size_t i = 0; i < valid_xpu_backends.size(); ++i) {
- if (!IsBackendAvailable(valid_xpu_backends[i])) {
- continue;
- }
- runtime_option.backend = valid_xpu_backends[i];
- runtime_ = std::unique_ptr(new Runtime());
- if (!runtime_->Init(runtime_option)) {
- return false;
- }
- runtime_initialized_ = true;
- return true;
- }
- FDERROR << "Found no valid backend for model: " << ModelName() << std::endl;
- return false;
-}
-
bool FastDeployModel::CreateIpuBackend() {
if (valid_ipu_backends.size() == 0) {
FDERROR << "There's no valid ipu backends for model: " << ModelName()
diff --git a/fastdeploy/fastdeploy_model.h b/fastdeploy/fastdeploy_model.h
index 5c8809196..5a6efba09 100755
--- a/fastdeploy/fastdeploy_model.h
+++ b/fastdeploy/fastdeploy_model.h
@@ -45,9 +45,6 @@ class FASTDEPLOY_DECL FastDeployModel {
/** Model's valid timvx backends. This member defined all the timvx backends have successfully tested for the model
*/
std::vector valid_timvx_backends = {};
- /** Model's valid KunlunXin xpu backends. This member defined all the KunlunXin xpu backends have successfully tested for the model
- */
- std::vector valid_xpu_backends = {};
/** Model's valid hardware backends. This member defined all the gpu backends have successfully tested for the model
*/
std::vector valid_rknpu_backends = {};
@@ -146,7 +143,6 @@ class FASTDEPLOY_DECL FastDeployModel {
bool CreateIpuBackend();
bool CreateRKNPUBackend();
bool CreateTimVXBackend();
- bool CreateXPUBackend();
std::shared_ptr runtime_;
bool runtime_initialized_ = false;
diff --git a/fastdeploy/pybind/runtime.cc b/fastdeploy/pybind/runtime.cc
old mode 100755
new mode 100644
index d0cb0b5f8..75767c665
--- a/fastdeploy/pybind/runtime.cc
+++ b/fastdeploy/pybind/runtime.cc
@@ -23,7 +23,6 @@ void BindRuntime(pybind11::module& m) {
.def("use_gpu", &RuntimeOption::UseGpu)
.def("use_cpu", &RuntimeOption::UseCpu)
.def("use_rknpu2", &RuntimeOption::UseRKNPU2)
- .def("use_xpu", &RuntimeOption::UseXpu)
.def("set_external_stream", &RuntimeOption::SetExternalStream)
.def("set_cpu_thread_num", &RuntimeOption::SetCpuThreadNum)
.def("use_paddle_backend", &RuntimeOption::UsePaddleBackend)
@@ -101,21 +100,7 @@ void BindRuntime(pybind11::module& m) {
.def_readwrite("ipu_available_memory_proportion",
&RuntimeOption::ipu_available_memory_proportion)
.def_readwrite("ipu_enable_half_partial",
- &RuntimeOption::ipu_enable_half_partial)
- .def_readwrite("xpu_l3_workspace_size",
- &RuntimeOption::xpu_l3_workspace_size)
- .def_readwrite("xpu_locked",
- &RuntimeOption::xpu_locked)
- .def_readwrite("xpu_autotune",
- &RuntimeOption::xpu_autotune)
- .def_readwrite("xpu_autotune_file",
- &RuntimeOption::xpu_autotune_file)
- .def_readwrite("xpu_precision",
- &RuntimeOption::xpu_precision)
- .def_readwrite("xpu_adaptive_seqlen",
- &RuntimeOption::xpu_adaptive_seqlen)
- .def_readwrite("xpu_enable_multi_stream",
- &RuntimeOption::xpu_enable_multi_stream);
+ &RuntimeOption::ipu_enable_half_partial);
pybind11::class_(m, "TensorInfo")
.def_readwrite("name", &TensorInfo::name)
diff --git a/fastdeploy/runtime.cc b/fastdeploy/runtime.cc
old mode 100755
new mode 100644
index 565c10607..1a51cebea
--- a/fastdeploy/runtime.cc
+++ b/fastdeploy/runtime.cc
@@ -236,26 +236,7 @@ void RuntimeOption::UseRKNPU2(fastdeploy::rknpu2::CpuName rknpu2_name,
void RuntimeOption::UseTimVX() {
enable_timvx = true;
device = Device::TIMVX;
-}
-
-void RuntimeOption::UseXpu(int xpu_id,
- int l3_workspace_size,
- bool locked,
- bool autotune,
- const std::string &autotune_file,
- const std::string &precision,
- bool adaptive_seqlen,
- bool enable_multi_stream) {
- enable_xpu = true;
- device_id = xpu_id;
- xpu_l3_workspace_size = l3_workspace_size;
- xpu_locked=locked;
- xpu_autotune=autotune;
- xpu_autotune_file=autotune_file;
- xpu_precision = precision;
- xpu_adaptive_seqlen=adaptive_seqlen;
- xpu_enable_multi_stream=enable_multi_stream;
- device = Device::XPU;
+ UseLiteBackend();
}
void RuntimeOption::SetExternalStream(void* external_stream) {
@@ -551,8 +532,8 @@ bool Runtime::Init(const RuntimeOption& _option) {
FDINFO << "Runtime initialized with Backend::OPENVINO in "
<< Str(option.device) << "." << std::endl;
} else if (option.backend == Backend::LITE) {
- FDASSERT(option.device == Device::CPU || option.device == Device::TIMVX || option.device == Device::XPU,
- "Backend::LITE only supports Device::CPU/Device::TIMVX/Device::XPU.");
+ FDASSERT(option.device == Device::CPU || option.device == Device::TIMVX,
+ "Backend::LITE only supports Device::CPU/Device::TIMVX.");
CreateLiteBackend();
FDINFO << "Runtime initialized with Backend::LITE in " << Str(option.device)
<< "." << std::endl;
@@ -803,16 +784,6 @@ void Runtime::CreateLiteBackend() {
lite_option.nnadapter_subgraph_partition_config_path =
option.lite_nnadapter_subgraph_partition_config_path;
lite_option.enable_timvx = option.enable_timvx;
- lite_option.enable_xpu = option.enable_xpu;
- lite_option.device_id = option.device_id;
- lite_option.xpu_l3_workspace_size = option.xpu_l3_workspace_size;
- lite_option.xpu_locked = option.xpu_locked;
- lite_option.xpu_autotune = option.xpu_autotune;
- lite_option.xpu_autotune_file = option.xpu_autotune_file;
- lite_option.xpu_precision = option.xpu_precision;
- lite_option.xpu_adaptive_seqlen = option.xpu_adaptive_seqlen;
- lite_option.xpu_enable_multi_stream = option.xpu_enable_multi_stream;
-
FDASSERT(option.model_format == ModelFormat::PADDLE,
"LiteBackend only support model format of ModelFormat::PADDLE");
backend_ = utils::make_unique();
diff --git a/fastdeploy/runtime.h b/fastdeploy/runtime.h
index 064be2fce..9c22c929f 100755
--- a/fastdeploy/runtime.h
+++ b/fastdeploy/runtime.h
@@ -102,37 +102,6 @@ struct FASTDEPLOY_DECL RuntimeOption {
/// Use TimVX to inference
void UseTimVX();
- ///
- /// \brief Turn on XPU.
- ///
- /// \param xpu_id the XPU card to use (default is 0).
- /// \param l3_workspace_size The size of the video memory allocated by the l3
- /// cache, the maximum is 16M.
- /// \param locked Whether the allocated L3 cache can be locked. If false,
- /// it means that the L3 cache is not locked, and the allocated L3
- /// cache can be shared by multiple models, and multiple models
- /// sharing the L3 cache will be executed sequentially on the card.
- /// \param autotune Whether to autotune the conv operator in the model. If
- /// true, when the conv operator of a certain dimension is executed
- /// for the first time, it will automatically search for a better
- /// algorithm to improve the performance of subsequent conv operators
- /// of the same dimension.
- /// \param autotune_file Specify the path of the autotune file. If
- /// autotune_file is specified, the algorithm specified in the
- /// file will be used and autotune will not be performed again.
- /// \param precision Calculation accuracy of multi_encoder
- /// \param adaptive_seqlen Is the input of multi_encoder variable length
- /// \param enable_multi_stream Whether to enable the multi stream of xpu.
- ///
- void UseXpu(int xpu_id = 0,
- int l3_workspace_size = 0xfffc00,
- bool locked = false,
- bool autotune = true,
- const std::string& autotune_file = "",
- const std::string& precision = "int16",
- bool adaptive_seqlen = false,
- bool enable_multi_stream = false);
-
void SetExternalStream(void* external_stream);
/*
@@ -385,7 +354,6 @@ struct FASTDEPLOY_DECL RuntimeOption {
std::string lite_optimized_model_dir = "";
std::string lite_nnadapter_subgraph_partition_config_path = "";
bool enable_timvx = false;
- bool enable_xpu = false;
// ======Only for Trt Backend=======
std::map> trt_max_shape;
@@ -418,15 +386,6 @@ struct FASTDEPLOY_DECL RuntimeOption {
fastdeploy::rknpu2::CoreMask rknpu2_core_mask_ =
fastdeploy::rknpu2::CoreMask::RKNN_NPU_CORE_AUTO;
- // ======Only for XPU Backend=======
- int xpu_l3_workspace_size = 0xfffc00;
- bool xpu_locked = false;
- bool xpu_autotune = true;
- std::string xpu_autotune_file = "";
- std::string xpu_precision = "int16";
- bool xpu_adaptive_seqlen = false;
- bool xpu_enable_multi_stream = false;
-
std::string model_file = ""; // Path of model file
std::string params_file = ""; // Path of parameters file, can be empty
// format of input model
diff --git a/fastdeploy/vision/classification/ppcls/model.cc b/fastdeploy/vision/classification/ppcls/model.cc
index e1b8d5249..5065bbfc2 100755
--- a/fastdeploy/vision/classification/ppcls/model.cc
+++ b/fastdeploy/vision/classification/ppcls/model.cc
@@ -29,7 +29,6 @@ PaddleClasModel::PaddleClasModel(const std::string& model_file,
Backend::LITE};
valid_gpu_backends = {Backend::ORT, Backend::PDINFER, Backend::TRT};
valid_timvx_backends = {Backend::LITE};
- valid_xpu_backends = {Backend::LITE};
valid_ipu_backends = {Backend::PDINFER};
} else if (model_format == ModelFormat::ONNX) {
valid_cpu_backends = {Backend::ORT, Backend::OPENVINO};
diff --git a/fastdeploy/vision/detection/contrib/rknpu2/postprocessor.h b/fastdeploy/vision/detection/contrib/rknpu2/postprocessor.h
index 6dcda3b77..238c1c465 100755
--- a/fastdeploy/vision/detection/contrib/rknpu2/postprocessor.h
+++ b/fastdeploy/vision/detection/contrib/rknpu2/postprocessor.h
@@ -72,11 +72,10 @@ class FASTDEPLOY_DECL RKYOLOPostprocessor {
}
// Set Anchor
- void SetAnchor(std::vector anchors, int anchor_per_branch) {
+ void SetAnchor(std::vector anchors,int anchor_per_branch){
anchors_ = anchors;
anchor_per_branch_ = anchor_per_branch;
- }
-
+ };
private:
std::vector anchors_ = {10, 13, 16, 30, 33, 23, 30, 61, 62,
45, 59, 119, 116, 90, 156, 198, 373, 326};
diff --git a/fastdeploy/vision/detection/contrib/rknpu2/utils.h b/fastdeploy/vision/detection/contrib/rknpu2/utils.h
index 1fa533082..1d28b5f0e 100644
--- a/fastdeploy/vision/detection/contrib/rknpu2/utils.h
+++ b/fastdeploy/vision/detection/contrib/rknpu2/utils.h
@@ -31,4 +31,4 @@ int NMS(int valid_count, std::vector& output_locations,
} // namespace detection
} // namespace vision
-} // namespace fastdeploy
+} // namespace fastdeploy
\ No newline at end of file
diff --git a/fastdeploy/vision/detection/contrib/yolov5/yolov5.cc b/fastdeploy/vision/detection/contrib/yolov5/yolov5.cc
index d1bb31f22..92d53dd10 100755
--- a/fastdeploy/vision/detection/contrib/yolov5/yolov5.cc
+++ b/fastdeploy/vision/detection/contrib/yolov5/yolov5.cc
@@ -27,7 +27,6 @@ YOLOv5::YOLOv5(const std::string& model_file, const std::string& params_file,
} else {
valid_cpu_backends = {Backend::PDINFER, Backend::ORT, Backend::LITE};
valid_gpu_backends = {Backend::PDINFER, Backend::ORT, Backend::TRT};
- valid_xpu_backends = {Backend::LITE};
valid_timvx_backends = {Backend::LITE};
}
runtime_option = custom_option;
diff --git a/fastdeploy/vision/detection/ppdet/model.h b/fastdeploy/vision/detection/ppdet/model.h
index 090c99de7..5175bc4e6 100755
--- a/fastdeploy/vision/detection/ppdet/model.h
+++ b/fastdeploy/vision/detection/ppdet/model.h
@@ -185,7 +185,7 @@ class FASTDEPLOY_DECL PaddleYOLOv5 : public PPDetBase {
const ModelFormat& model_format = ModelFormat::PADDLE)
: PPDetBase(model_file, params_file, config_file, custom_option,
model_format) {
- valid_cpu_backends = {Backend::ORT, Backend::PDINFER};
+ valid_cpu_backends = {Backend::ORT,Backend::PDINFER};
valid_gpu_backends = {Backend::ORT, Backend::PDINFER, Backend::TRT};
initialized = Initialize();
}
@@ -201,7 +201,7 @@ class FASTDEPLOY_DECL PaddleYOLOv6 : public PPDetBase {
const ModelFormat& model_format = ModelFormat::PADDLE)
: PPDetBase(model_file, params_file, config_file, custom_option,
model_format) {
- valid_cpu_backends = {Backend::OPENVINO, Backend::ORT, Backend::PDINFER};
+ valid_cpu_backends = {Backend::OPENVINO, Backend::ORT,Backend::PDINFER};
valid_gpu_backends = {Backend::ORT, Backend::PDINFER, Backend::TRT};
initialized = Initialize();
}
@@ -217,7 +217,7 @@ class FASTDEPLOY_DECL PaddleYOLOv7 : public PPDetBase {
const ModelFormat& model_format = ModelFormat::PADDLE)
: PPDetBase(model_file, params_file, config_file, custom_option,
model_format) {
- valid_cpu_backends = {Backend::ORT, Backend::PDINFER};
+ valid_cpu_backends = {Backend::ORT,Backend::PDINFER};
valid_gpu_backends = {Backend::ORT, Backend::PDINFER, Backend::TRT};
initialized = Initialize();
}
diff --git a/python/fastdeploy/runtime.py b/python/fastdeploy/runtime.py
index f9334efbf..6461da66d 100755
--- a/python/fastdeploy/runtime.py
+++ b/python/fastdeploy/runtime.py
@@ -245,34 +245,6 @@ class RuntimeOption:
return
return self._option.use_gpu(device_id)
- def use_xpu(self,
- device_id=0,
- l3_workspace_size=16 * 1024 * 1024,
- locked=False,
- autotune=True,
- autotune_file="",
- precision="int16",
- adaptive_seqlen=False,
- enable_multi_stream=False):
- """Inference with XPU
-
- :param device_id: (int)The index of XPU will be used for inference, default 0
- :param l3_workspace_size: (int)The size of the video memory allocated by the l3 cache, the maximum is 16M, default 16M
- :param locked: (bool)Whether the allocated L3 cache can be locked. If false, it means that the L3 cache is not locked,
- and the allocated L3 cache can be shared by multiple models, and multiple models
- :param autotune: (bool)Whether to autotune the conv operator in the model.
- If true, when the conv operator of a certain dimension is executed for the first time,
- it will automatically search for a better algorithm to improve the performance of subsequent conv operators of the same dimension.
- :param autotune_file: (str)Specify the path of the autotune file. If autotune_file is specified,
- the algorithm specified in the file will be used and autotune will not be performed again.
- :param precision: (str)Calculation accuracy of multi_encoder
- :param adaptive_seqlen: (bool)adaptive_seqlen Is the input of multi_encoder variable length
- :param enable_multi_stream: (bool)Whether to enable the multi stream of xpu.
- """
- return self._option.use_xpu(device_id, l3_workspace_size, locked,
- autotune, autotune_file, precision,
- adaptive_seqlen, enable_multi_stream)
-
def use_cpu(self):
"""Inference with CPU
"""
diff --git a/python/setup.py b/python/setup.py
index 19a857678..b4dc111c6 100755
--- a/python/setup.py
+++ b/python/setup.py
@@ -65,13 +65,11 @@ setup_configs["ENABLE_POROS_BACKEND"] = os.getenv("ENABLE_POROS_BACKEND",
"OFF")
setup_configs["ENABLE_TRT_BACKEND"] = os.getenv("ENABLE_TRT_BACKEND", "OFF")
setup_configs["ENABLE_LITE_BACKEND"] = os.getenv("ENABLE_LITE_BACKEND", "OFF")
-setup_configs["PADDLELITE_URL"] = os.getenv("PADDLELITE_URL", "OFF")
setup_configs["ENABLE_VISION"] = os.getenv("ENABLE_VISION", "OFF")
setup_configs["ENABLE_FLYCV"] = os.getenv("ENABLE_FLYCV", "OFF")
setup_configs["ENABLE_TEXT"] = os.getenv("ENABLE_TEXT", "OFF")
setup_configs["WITH_GPU"] = os.getenv("WITH_GPU", "OFF")
setup_configs["WITH_IPU"] = os.getenv("WITH_IPU", "OFF")
-setup_configs["WITH_XPU"] = os.getenv("WITH_XPU", "OFF")
setup_configs["BUILD_ON_JETSON"] = os.getenv("BUILD_ON_JETSON", "OFF")
setup_configs["TRT_DIRECTORY"] = os.getenv("TRT_DIRECTORY", "UNDEFINED")
setup_configs["CUDA_DIRECTORY"] = os.getenv("CUDA_DIRECTORY",
@@ -80,12 +78,10 @@ setup_configs["LIBRARY_NAME"] = PACKAGE_NAME
setup_configs["PY_LIBRARY_NAME"] = PACKAGE_NAME + "_main"
setup_configs["OPENCV_DIRECTORY"] = os.getenv("OPENCV_DIRECTORY", "")
setup_configs["ORT_DIRECTORY"] = os.getenv("ORT_DIRECTORY", "")
-setup_configs["PADDLEINFERENCE_DIRECTORY"] = os.getenv(
- "PADDLEINFERENCE_DIRECTORY", "")
+setup_configs["PADDLEINFERENCE_DIRECTORY"] = os.getenv("PADDLEINFERENCE_DIRECTORY", "")
setup_configs["RKNN2_TARGET_SOC"] = os.getenv("RKNN2_TARGET_SOC", "")
-if setup_configs["RKNN2_TARGET_SOC"] != "" or setup_configs[
- "BUILD_ON_JETSON"] != "OFF":
+if setup_configs["RKNN2_TARGET_SOC"] != "" or setup_configs["BUILD_ON_JETSON"] != "OFF":
REQUIRED_PACKAGES = REQUIRED_PACKAGES.replace("opencv-python", "")
if setup_configs["WITH_GPU"] == "ON" or setup_configs[
From 2d998223ac443cfd308766bef20f7c803fc3537e Mon Sep 17 00:00:00 2001
From: Jason
Date: Fri, 16 Dec 2022 11:22:30 +0800
Subject: [PATCH 71/77] [Backend] Add KunlunXin XPU deploy support (#894)
Revert "Revert "[Backend] Add KunlunXin XPU deploy support" (#893)"
This reverts commit 0990ab9b50f13109bbd82b1299d37eb75301e2ec.
---
CMakeLists.txt | 20 ++-
FastDeploy.cmake.in | 5 +
cmake/summary.cmake | 2 +
docs/README_CN.md | 1 +
docs/README_EN.md | 5 +-
docs/cn/build_and_install/README.md | 8 +-
docs/cn/build_and_install/a311d.md | 3 +-
docs/cn/build_and_install/rv1126.md | 7 +-
docs/cn/build_and_install/xpu.md | 75 +++++++++
docs/en/build_and_install/README.md | 5 +
docs/en/build_and_install/a311d.md | 105 ++++++++++++
docs/en/build_and_install/rv1126.md | 105 ++++++++++++
docs/en/build_and_install/xpu.md | 78 +++++++++
.../classification/paddleclas/cpp/README.md | 4 +
.../classification/paddleclas/cpp/infer.cc | 30 +++-
.../paddleclas/python/README.md | 2 +
.../classification/paddleclas/python/infer.py | 3 +
.../detection/yolov5/cpp/CMakeLists.txt | 4 +
.../vision/detection/yolov5/cpp/README.md | 24 ++-
examples/vision/detection/yolov5/cpp/infer.cc | 2 +-
.../yolov5/cpp/infer_paddle_model.cc | 154 ++++++++++++++++++
.../vision/detection/yolov5/python/README.md | 11 +-
.../vision/detection/yolov5/python/infer.py | 21 ++-
fastdeploy/backends/lite/lite_backend.cc | 56 +++++--
fastdeploy/backends/lite/lite_backend.h | 9 +
fastdeploy/core/fd_type.cc | 6 +
fastdeploy/core/fd_type.h | 2 +-
fastdeploy/fastdeploy_model.cc | 33 +++-
fastdeploy/fastdeploy_model.h | 4 +
fastdeploy/pybind/runtime.cc | 17 +-
fastdeploy/runtime.cc | 35 +++-
fastdeploy/runtime.h | 41 +++++
.../vision/classification/ppcls/model.cc | 1 +
.../detection/contrib/rknpu2/postprocessor.h | 5 +-
.../vision/detection/contrib/rknpu2/utils.h | 2 +-
.../vision/detection/contrib/yolov5/yolov5.cc | 1 +
fastdeploy/vision/detection/ppdet/model.h | 6 +-
python/fastdeploy/runtime.py | 28 ++++
python/setup.py | 8 +-
39 files changed, 870 insertions(+), 58 deletions(-)
mode change 100644 => 100755 docs/README_CN.md
mode change 100644 => 100755 docs/README_EN.md
create mode 100755 docs/cn/build_and_install/xpu.md
mode change 100644 => 100755 docs/en/build_and_install/README.md
create mode 100755 docs/en/build_and_install/a311d.md
create mode 100755 docs/en/build_and_install/rv1126.md
create mode 100755 docs/en/build_and_install/xpu.md
mode change 100644 => 100755 examples/vision/classification/paddleclas/cpp/README.md
mode change 100644 => 100755 examples/vision/classification/paddleclas/cpp/infer.cc
mode change 100644 => 100755 examples/vision/classification/paddleclas/python/README.md
mode change 100644 => 100755 examples/vision/classification/paddleclas/python/infer.py
mode change 100644 => 100755 examples/vision/detection/yolov5/cpp/CMakeLists.txt
mode change 100644 => 100755 examples/vision/detection/yolov5/cpp/README.md
mode change 100644 => 100755 examples/vision/detection/yolov5/cpp/infer.cc
create mode 100755 examples/vision/detection/yolov5/cpp/infer_paddle_model.cc
mode change 100644 => 100755 examples/vision/detection/yolov5/python/README.md
mode change 100644 => 100755 examples/vision/detection/yolov5/python/infer.py
mode change 100644 => 100755 fastdeploy/pybind/runtime.cc
mode change 100644 => 100755 fastdeploy/runtime.cc
diff --git a/CMakeLists.txt b/CMakeLists.txt
index c02e887a5..0bcfa4084 100755
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -40,7 +40,7 @@ if(NOT MSVC)
add_definitions(-D_GLIBCXX_USE_CXX11_ABI=1)
endif(NOT MSVC)
-if(UNIX AND (NOT APPLE) AND (NOT ANDROID) AND (NOT ENABLE_TIMVX))
+if(UNIX AND (NOT APPLE) AND (NOT ANDROID) AND (NOT WITH_TIMVX))
include(${PROJECT_SOURCE_DIR}/cmake/patchelf.cmake)
endif()
@@ -64,7 +64,8 @@ option(ENABLE_LITE_BACKEND "Whether to enable paddle lite backend." OFF)
option(ENABLE_VISION "Whether to enable vision models usage." OFF)
option(ENABLE_TEXT "Whether to enable text models usage." OFF)
option(ENABLE_FLYCV "Whether to enable flycv to boost image preprocess." OFF)
-option(ENABLE_TIMVX "Whether to compile for TIMVX deploy." OFF)
+option(WITH_TIMVX "Whether to compile for TIMVX deploy." OFF)
+option(WITH_XPU "Whether to compile for KunlunXin XPU deploy." OFF)
option(WITH_TESTING "Whether to compile with unittest." OFF)
############################# Options for Android cross compiling #########################
option(WITH_OPENCV_STATIC "Use OpenCV static lib for Android." OFF)
@@ -138,10 +139,23 @@ set(HEAD_DIR "${PROJECT_SOURCE_DIR}/${CSRCS_DIR_NAME}")
include_directories(${HEAD_DIR})
include_directories(${CMAKE_CURRENT_BINARY_DIR})
-if (ENABLE_TIMVX)
+if (WITH_TIMVX)
include(${PROJECT_SOURCE_DIR}/cmake/timvx.cmake)
endif()
+if (WITH_XPU)
+ if(NOT ENABLE_LITE_BACKEND)
+ message(WARNING "While compiling with -DWITH_XPU=ON, will force to set -DENABLE_LITE_BACKEND=ON")
+ set(ENABLE_LITE_BACKEND ON)
+ endif()
+ if(NOT CMAKE_HOST_SYSTEM_PROCESSOR MATCHES "x86_64")
+ message(FATAL_ERROR "XPU is only supported on Linux x64 platform")
+ endif()
+ if(NOT PADDLELITE_URL)
+ set(PADDLELITE_URL "https://bj.bcebos.com/fastdeploy/third_libs/lite-linux-x64-xpu-20221215.tgz")
+ endif()
+endif()
+
if(ANDROID OR IOS)
if(ENABLE_ORT_BACKEND)
diff --git a/FastDeploy.cmake.in b/FastDeploy.cmake.in
index fd0ea847a..d8c0df3d6 100755
--- a/FastDeploy.cmake.in
+++ b/FastDeploy.cmake.in
@@ -27,6 +27,7 @@ set(OPENCV_DIRECTORY "@OPENCV_DIRECTORY@")
set(ORT_DIRECTORY "@ORT_DIRECTORY@")
set(OPENVINO_DIRECTORY "@OPENVINO_DIRECTORY@")
set(RKNN2_TARGET_SOC "@RKNN2_TARGET_SOC@")
+set(WITH_XPU @WITH_XPU@)
set(FASTDEPLOY_LIBS "")
set(FASTDEPLOY_INCS "")
@@ -237,6 +238,10 @@ if(ENABLE_PADDLE_FRONTEND)
list(APPEND FASTDEPLOY_LIBS ${PADDLE2ONNX_LIB})
endif()
+if(WITH_XPU)
+ list(APPEND FASTDEPLOY_LIBS -lpthread -lrt -ldl)
+endif()
+
remove_duplicate_libraries(FASTDEPLOY_LIBS)
# Print compiler information
diff --git a/cmake/summary.cmake b/cmake/summary.cmake
index 7a729484e..fc5c246ba 100755
--- a/cmake/summary.cmake
+++ b/cmake/summary.cmake
@@ -37,6 +37,8 @@ function(fastdeploy_summary)
message(STATUS " ENABLE_POROS_BACKEND : ${ENABLE_POROS_BACKEND}")
message(STATUS " ENABLE_TRT_BACKEND : ${ENABLE_TRT_BACKEND}")
message(STATUS " ENABLE_OPENVINO_BACKEND : ${ENABLE_OPENVINO_BACKEND}")
+ message(STATUS " WITH_TIMVX : ${WITH_TIMVX}")
+ message(STATUS " WITH_XPU : ${WITH_XPU}")
if(ENABLE_ORT_BACKEND)
message(STATUS " ONNXRuntime version : ${ONNXRUNTIME_VERSION}")
endif()
diff --git a/docs/README_CN.md b/docs/README_CN.md
old mode 100644
new mode 100755
index a0b7b51d0..ec0267f45
--- a/docs/README_CN.md
+++ b/docs/README_CN.md
@@ -8,6 +8,7 @@
- [GPU部署环境编译安装](cn/build_and_install/gpu.md)
- [CPU部署环境编译安装](cn/build_and_install/cpu.md)
- [IPU部署环境编译安装](cn/build_and_install/ipu.md)
+- [昆仑芯XPU部署环境编译安装](cn/build_and_install/xpu.md)
- [Jetson部署环境编译安装](cn/build_and_install/jetson.md)
- [Android平台部署环境编译安装](cn/build_and_install/android.md)
- [服务化部署镜像编译安装](../serving/docs/zh_CN/compile.md)
diff --git a/docs/README_EN.md b/docs/README_EN.md
old mode 100644
new mode 100755
index c4f9adfa3..ed257c59b
--- a/docs/README_EN.md
+++ b/docs/README_EN.md
@@ -8,6 +8,7 @@
- [Build and Install FastDeploy Library on GPU Platform](en/build_and_install/gpu.md)
- [Build and Install FastDeploy Library on CPU Platform](en/build_and_install/cpu.md)
- [Build and Install FastDeploy Library on IPU Platform](en/build_and_install/ipu.md)
+- [Build and Install FastDeploy Library on KunlunXin XPU Platform](en/build_and_install/xpu.md)
- [Build and Install FastDeploy Library on Nvidia Jetson Platform](en/build_and_install/jetson.md)
- [Build and Install FastDeploy Library on Android Platform](en/build_and_install/android.md)
- [Build and Install FastDeploy Serving Deployment Image](../serving/docs/EN/compile-en.md)
@@ -19,10 +20,10 @@
- [A Quick Start on Runtime Python](en/quick_start/runtime/python.md)
- [A Quick Start on Runtime C++](en/quick_start/runtime/cpp.md)
-## API
+## API
- [Python API](https://baidu-paddle.github.io/fastdeploy-api/python/html/)
-- [C++ API](https://baidu-paddle.github.io/fastdeploy-api/cpp/html/)
+- [C++ API](https://baidu-paddle.github.io/fastdeploy-api/cpp/html/)
- [Android Java API](../java/android)
## Performance Optimization
diff --git a/docs/cn/build_and_install/README.md b/docs/cn/build_and_install/README.md
index 7ec07c7b8..221852d2c 100755
--- a/docs/cn/build_and_install/README.md
+++ b/docs/cn/build_and_install/README.md
@@ -13,6 +13,7 @@
- [Android平台部署环境](android.md)
- [瑞芯微RV1126部署环境](rv1126.md)
- [晶晨A311D部署环境](a311d.md)
+- [昆仑芯XPU部署环境](xpu.md)
## FastDeploy编译选项说明
@@ -20,10 +21,11 @@
| 选项 | 说明 |
|:------------------------|:--------------------------------------------------------------------------|
| ENABLE_ORT_BACKEND | 默认OFF, 是否编译集成ONNX Runtime后端(CPU/GPU上推荐打开) |
-| ENABLE_PADDLE_BACKEND | 默认OFF,是否编译集成Paddle Inference后端(CPU/GPU上推荐打开) |
-| ENABLE_LITE_BACKEND | 默认OFF,是否编译集成Paddle Lite后端(编译Android库时需要设置为ON) |
+| ENABLE_PADDLE_BACKEND | 默认OFF,是否编译集成Paddle Inference后端(CPU/GPU上推荐打开) |
+| ENABLE_LITE_BACKEND | 默认OFF,是否编译集成Paddle Lite后端(编译Android库时需要设置为ON) |
| ENABLE_RKNPU2_BACKEND | 默认OFF,是否编译集成RKNPU2后端(RK3588/RK3568/RK3566上推荐打开) |
-| WITH_TIMVX | 默认OFF,需要在RV1126/RV1109/A311D上部署时,需设置为ON |
+| WITH_XPU | 默认OFF,当在昆仑芯XPU上部署时,需设置为ON |
+| WITH_TIMVX | 默认OFF,需要在RV1126/RV1109/A311D上部署时,需设置为ON |
| ENABLE_TRT_BACKEND | 默认OFF,是否编译集成TensorRT后端(GPU上推荐打开) |
| ENABLE_OPENVINO_BACKEND | 默认OFF,是否编译集成OpenVINO后端(CPU上推荐打开) |
| ENABLE_VISION | 默认OFF,是否编译集成视觉模型的部署模块 |
diff --git a/docs/cn/build_and_install/a311d.md b/docs/cn/build_and_install/a311d.md
index 4b3773f0d..20dde7046 100755
--- a/docs/cn/build_and_install/a311d.md
+++ b/docs/cn/build_and_install/a311d.md
@@ -9,7 +9,8 @@ FastDeploy 基于 Paddle-Lite 后端支持在晶晨 NPU 上进行部署推理。
|编译选项|默认值|说明|备注|
|:---|:---|:---|:---|
|ENABLE_LITE_BACKEND|OFF|编译A311D部署库时需要设置为ON| - |
-|WITH_TIMVX|OFF|编译A311D部署库时需要设置为ON| - |
+|WITH_TIMVX|OFF|编译A311D部署库时需要设置为ON| - |
+|TARGET_ABI|NONE|编译RK库时需要设置为arm64| - |
更多编译选项请参考[FastDeploy编译选项说明](./README.md)
diff --git a/docs/cn/build_and_install/rv1126.md b/docs/cn/build_and_install/rv1126.md
index ff0050715..f3643f070 100755
--- a/docs/cn/build_and_install/rv1126.md
+++ b/docs/cn/build_and_install/rv1126.md
@@ -8,8 +8,9 @@ FastDeploy基于 Paddle-Lite 后端支持在瑞芯微(Rockchip)Soc 上进行
相关编译选项说明如下:
|编译选项|默认值|说明|备注|
|:---|:---|:---|:---|
-|ENABLE_LITE_BACKEND|OFF|编译RK库时需要设置为ON| - |
-|WITH_TIMVX|OFF|编译RK库时需要设置为ON| - |
+|ENABLE_LITE_BACKEND|OFF|编译RK库时需要设置为ON| - |
+|WITH_TIMVX|OFF|编译RK库时需要设置为ON| - |
+|TARGET_ABI|NONE|编译RK库时需要设置为armhf| - |
更多编译选项请参考[FastDeploy编译选项说明](./README.md)
@@ -86,7 +87,7 @@ dmesg | grep Galcore
wget https://paddlelite-demo.bj.bcebos.com/devices/generic/PaddleLite-generic-demo.tar.gz
tar -xf PaddleLite-generic-demo.tar.gz
```
-2. 使用 `uname -a` 查看 `Linux Kernel` 版本,确定为 `Linux` 系统 4.19.111 版本,
+2. 使用 `uname -a` 查看 `Linux Kernel` 版本,确定为 `Linux` 系统 4.19.111 版本
3. 将 `PaddleLite-generic-demo/libs/PaddleLite/linux/armhf/lib/verisilicon_timvx/viv_sdk_6_4_6_5/lib/1126/4.19.111/` 路径下的 `galcore.ko` 上传至开发板。
4. 登录开发板,命令行输入 `sudo rmmod galcore` 来卸载原始驱动,输入 `sudo insmod galcore.ko` 来加载传上设备的驱动。(是否需要 sudo 根据开发板实际情况,部分 adb 链接的设备请提前 adb root)。此步骤如果操作失败,请跳转至方法 2。
diff --git a/docs/cn/build_and_install/xpu.md b/docs/cn/build_and_install/xpu.md
new file mode 100755
index 000000000..014eb804d
--- /dev/null
+++ b/docs/cn/build_and_install/xpu.md
@@ -0,0 +1,75 @@
+# 昆仑芯 XPU 部署环境编译安装
+
+FastDeploy 基于 Paddle-Lite 后端支持在昆仑芯 XPU 上进行部署推理。
+更多详细的信息请参考:[PaddleLite部署示例](https://www.paddlepaddle.org.cn/lite/develop/demo_guides/kunlunxin_xpu.html#xpu)。
+
+本文档介绍如何编译基于 PaddleLite 的 C++ FastDeploy 编译库。
+
+相关编译选项说明如下:
+|编译选项|默认值|说明|备注|
+|:---|:---|:---|:---|
+| WITH_XPU| OFF | 需要在XPU上部署时需要设置为ON | - |
+| ENABLE_ORT_BACKEND | OFF | 是否编译集成ONNX Runtime后端 | - |
+| ENABLE_PADDLE_BACKEND | OFF | 是否编译集成Paddle Inference后端 | - |
+| ENABLE_OPENVINO_BACKEND | OFF | 是否编译集成OpenVINO后端 | - |
+| ENABLE_VISION | OFF | 是否编译集成视觉模型的部署模块 | - |
+| ENABLE_TEXT | OFF | 是否编译集成文本NLP模型的部署模块 | - |
+
+第三方库依赖指定(不设定如下参数,会自动下载预编译库)
+| 选项 | 说明 |
+| :---------------------- | :--------------------------------------------------------------------------------------------- |
+| ORT_DIRECTORY | 当开启ONNX Runtime后端时,用于指定用户本地的ONNX Runtime库路径;如果不指定,编译过程会自动下载ONNX Runtime库 |
+| OPENCV_DIRECTORY | 当ENABLE_VISION=ON时,用于指定用户本地的OpenCV库路径;如果不指定,编译过程会自动下载OpenCV库 |
+| OPENVINO_DIRECTORY | 当开启OpenVINO后端时, 用于指定用户本地的OpenVINO库路径;如果不指定,编译过程会自动下载OpenVINO库 |
+更多编译选项请参考[FastDeploy编译选项说明](./README.md)
+
+## 基于 PaddleLite 的 C++ FastDeploy 库编译
+- OS: Linux
+- gcc/g++: version >= 8.2
+- cmake: version >= 3.15
+此外更推荐开发者自行安装,编译时通过`-DOPENCV_DIRECTORY`来指定环境中的OpenCV(如若不指定-DOPENCV_DIRECTORY,会自动下载FastDeploy提供的预编译的OpenCV,但在**Linux平台**无法支持Video的读取,以及imshow等可视化界面功能)
+```
+sudo apt-get install libopencv-dev
+```
+编译命令如下:
+```bash
+# Download the latest source code
+git clone https://github.com/PaddlePaddle/FastDeploy.git
+cd FastDeploy
+mkdir build && cd build
+
+# CMake configuration with KunlunXin xpu toolchain
+cmake -DWITH_XPU=ON \
+ -DWITH_GPU=OFF \ # 不编译 GPU
+ -DENABLE_ORT_BACKEND=ON \ # 可选择开启 ORT 后端
+ -DENABLE_PADDLE_BACKEND=ON \ # 可选择开启 Paddle 后端
+ -DCMAKE_INSTALL_PREFIX=fastdeploy-xpu \
+ -DENABLE_VISION=ON \ # 是否编译集成视觉模型的部署模块,可选择开启
+ -DOPENCV_DIRECTORY=/usr/lib/x86_64-linux-gnu/cmake/opencv4 \
+ ..
+
+# Build FastDeploy KunlunXin XPU C++ SDK
+make -j8
+make install
+```
+编译完成之后,会生成 fastdeploy-xpu 目录,表示基于 PadddleLite 的 FastDeploy 库编译完成。
+
+## Python 编译
+编译命令如下:
+```bash
+git clone https://github.com/PaddlePaddle/FastDeploy.git
+cd FastDeploy/python
+export WITH_XPU=ON
+export WITH_GPU=OFF
+export ENABLE_ORT_BACKEND=ON
+export ENABLE_PADDLE_BACKEND=ON
+export ENABLE_VISION=ON
+# OPENCV_DIRECTORY可选,不指定会自动下载FastDeploy提供的预编译OpenCV库
+export OPENCV_DIRECTORY=/usr/lib/x86_64-linux-gnu/cmake/opencv4
+
+python setup.py build
+python setup.py bdist_wheel
+```
+编译完成即会在 `FastDeploy/python/dist` 目录下生成编译后的 `wheel` 包,直接 pip install 即可
+
+编译过程中,如若修改编译参数,为避免带来缓存影响,可删除 `FastDeploy/python` 目录下的 `build` 和 `.setuptools-cmake-build` 两个子目录后再重新编译
diff --git a/docs/en/build_and_install/README.md b/docs/en/build_and_install/README.md
old mode 100644
new mode 100755
index 4beaaeec8..0958c3778
--- a/docs/en/build_and_install/README.md
+++ b/docs/en/build_and_install/README.md
@@ -12,6 +12,9 @@ English | [中文](../../cn/build_and_install/README.md)
- [Build and Install on IPU Platform](ipu.md)
- [Build and Install on Nvidia Jetson Platform](jetson.md)
- [Build and Install on Android Platform](android.md)
+- [Build and Install on RV1126 Platform](rv1126.md)
+- [Build and Install on A311D Platform](a311d.md)
+- [Build and Install on KunlunXin XPU Platform](xpu.md)
## Build options
@@ -25,6 +28,8 @@ English | [中文](../../cn/build_and_install/README.md)
| ENABLE_VISION | Default OFF,whether to enable vision models deployment module |
| ENABLE_TEXT | Default OFF,whether to enable text models deployment module |
| WITH_GPU | Default OFF, if build on GPU, this need to be ON |
+| WITH_XPU | Default OFF,if deploy on KunlunXin XPU,this need to be ON |
+| WITH_TIMVX | Default OFF,if deploy on RV1126/RV1109/A311D,this need to be ON |
| CUDA_DIRECTORY | Default /usr/local/cuda, if build on GPU, this defines the path of CUDA(>=11.2) |
| TRT_DIRECTORY | If build with ENABLE_TRT_BACKEND=ON, this defines the path of TensorRT(>=8.4) |
| ORT_DIRECTORY | [Optional] If build with ENABLE_ORT_BACKEND=ON, this flag defines the path of ONNX Runtime, but if this flag is not set, it will download ONNX Runtime library automatically |
diff --git a/docs/en/build_and_install/a311d.md b/docs/en/build_and_install/a311d.md
new file mode 100755
index 000000000..872c1b93c
--- /dev/null
+++ b/docs/en/build_and_install/a311d.md
@@ -0,0 +1,105 @@
+# How to Build A311D Deployment Environment
+
+FastDeploy supports AI deployment on Rockchip Soc based on Paddle-Lite backend. For more detailed information, please refer to: [PaddleLite Deployment Example](https://www.paddlepaddle.org.cn/lite/develop/demo_guides/verisilicon_timvx.html).
+
+This document describes how to compile the PaddleLite-based C++ FastDeploy cross-compilation library.
+
+The relevant compilation options are described as follows:
+|Compile Options|Default Values|Description|Remarks|
+|:---|:---|:---|:---|
+|ENABLE_LITE_BACKEND|OFF|It needs to be set to ON when compiling the A311D library| - |
+|WITH_TIMVX|OFF|It needs to be set to ON when compiling the A311D library| - |
+|TARGET_ABI|NONE|It needs to be set to arm64 when compiling the A311D library| - |
+
+For more compilation options, please refer to [Description of FastDeploy compilation options](./README.md)
+
+## Cross-compilation environment construction
+
+### Host Environment Requirements
+- os:Ubuntu == 16.04
+- cmake: version >= 3.10.0
+
+### Building the compilation environment
+You can enter the FastDeploy/tools/timvx directory and use the following command to install:
+```bash
+cd FastDeploy/tools/timvx
+bash install.sh
+```
+You can also install it with the following commands:
+```bash
+ # 1. Install basic software
+apt update
+apt-get install -y --no-install-recommends \
+ gcc g++ git make wget python unzip
+
+# 2. Install arm gcc toolchains
+apt-get install -y --no-install-recommends \
+ g++-arm-linux-gnueabi gcc-arm-linux-gnueabi \
+ g++-arm-linux-gnueabihf gcc-arm-linux-gnueabihf \
+ gcc-aarch64-linux-gnu g++-aarch64-linux-gnu
+
+# 3. Install cmake 3.10 or above
+wget -c https://mms-res.cdn.bcebos.com/cmake-3.10.3-Linux-x86_64.tar.gz && \
+ tar xzf cmake-3.10.3-Linux-x86_64.tar.gz && \
+ mv cmake-3.10.3-Linux-x86_64 /opt/cmake-3.10 && \
+ ln -s /opt/cmake-3.10/bin/cmake /usr/bin/cmake && \
+ ln -s /opt/cmake-3.10/bin/ccmake /usr/bin/ccmake
+```
+
+## FastDeploy cross-compilation library compilation based on PaddleLite
+After setting up the cross-compilation environment, the compilation command is as follows:
+```bash
+# Download the latest source code
+git clone https://github.com/PaddlePaddle/FastDeploy.git
+cd FastDeploy
+mkdir build && cd build
+
+# CMake configuration with A311D toolchain
+cmake -DCMAKE_TOOLCHAIN_FILE=./../cmake/toolchain.cmake \
+ -DWITH_TIMVX=ON \
+ -DTARGET_ABI=arm64 \
+ -DCMAKE_INSTALL_PREFIX=fastdeploy-tmivx \
+ -DENABLE_VISION=ON \ # 是否编译集成视觉模型的部署模块,可选择开启
+ -Wno-dev ..
+
+# Build FastDeploy A311D C++ SDK
+make -j8
+make install
+```
+After the compilation is complete, the fastdeploy-tmivx directory will be generated, indicating that the FastDeploy library based on PadddleLite TIM-VX has been compiled.
+
+## Prepare the Soc environment
+Before deployment, ensure that the version of the driver galcore.so of the Verisilicon Linux Kernel NPU meets the requirements. Before deployment, please log in to the development board, and enter the following command through the command line to query the NPU driver version. The recommended version of the Rockchip driver is: 6.4.4.3
+```bash
+dmesg | grep Galcore
+```
+If the current version does not comply with the above, please read the following content carefully to ensure that the underlying NPU driver environment is correct.
+
+There are two ways to modify the current NPU driver version:
+1. Manually replace the NPU driver version. (recommend)
+2. flash the machine, and flash the firmware that meets the requirements of the NPU driver version.
+
+### Manually replace the NPU driver version
+1. Use the following command to download and decompress the PaddleLite demo, which provides ready-made driver files
+```bash
+wget https://paddlelite-demo.bj.bcebos.com/devices/generic/PaddleLite-generic-demo.tar.gz
+tar -xf PaddleLite-generic-demo.tar.gz
+```
+2. Use `uname -a` to check `Linux Kernel` version, it is determined to be version 4.19.111.
+3. Upload `galcore.ko` under `PaddleLite-generic-demo/libs/PaddleLite/linux/arm64/lib/verisilicon_timvx/viv_sdk_6_4_4_3/lib/a311d/4.9.113` path to the development board.
+4. Log in to the development board, enter `sudo rmmod galcore` on the command line to uninstall the original driver, and enter `sudo insmod galcore.ko` to load the uploaded device driver. (Whether sudo is needed depends on the actual situation of the development board. For some adb-linked devices, please adb root in advance). If this step fails, go to method 2.
+5. Enter `dmesg | grep Galcore` in the development board to query the NPU driver version, and it is determined to be: 6.4.4.3
+
+### flash
+According to the specific development board model, ask the development board seller or the official website customer service for the firmware and flashing method corresponding to the 6.4.4.3 version of the NPU driver.
+
+For more details, please refer to: [PaddleLite prepares the device environment](https://www.paddlepaddle.org.cn/lite/develop/demo_guides/verisilicon_timvx.html#zhunbeishebeihuanjing)
+
+## Deployment example based on FastDeploy on A311D
+1. For deploying the PaddleClas classification model on A311D, please refer to: [C++ deployment example of PaddleClas classification model on A311D](../../../examples/vision/classification/paddleclas/a311d/README.md)
+
+2. For deploying PPYOLOE detection model on A311D, please refer to: [C++ deployment example of PPYOLOE detection model on A311D](../../../examples/vision/detection/paddledetection/a311d/README.md)
+
+3. For deploying YOLOv5 detection model on A311D, please refer to: [C++ Deployment Example of YOLOv5 Detection Model on A311D](../../../examples/vision/detection/yolov5/a311d/README.md)
+
+4. For deploying PP-LiteSeg segmentation model on A311D, please refer to: [C++ Deployment Example of PP-LiteSeg Segmentation Model on A311D](../../../examples/vision/segmentation/paddleseg/a311d/README.md)
diff --git a/docs/en/build_and_install/rv1126.md b/docs/en/build_and_install/rv1126.md
new file mode 100755
index 000000000..a56535363
--- /dev/null
+++ b/docs/en/build_and_install/rv1126.md
@@ -0,0 +1,105 @@
+# How to Build RV1126 Deployment Environment
+
+FastDeploy supports AI deployment on Rockchip Soc based on Paddle-Lite backend. For more detailed information, please refer to: [PaddleLite Deployment Example](https://www.paddlepaddle.org.cn/lite/develop/demo_guides/verisilicon_timvx.html).
+
+This document describes how to compile the PaddleLite-based C++ FastDeploy cross-compilation library.
+
+The relevant compilation options are described as follows:
+|Compile Options|Default Values|Description|Remarks|
+|:---|:---|:---|:---|
+|ENABLE_LITE_BACKEND|OFF|It needs to be set to ON when compiling the RK library| - |
+|WITH_TIMVX|OFF|It needs to be set to ON when compiling the RK library| - |
+|TARGET_ABI|NONE|It needs to be set to armhf when compiling the RK library| - |
+
+For more compilation options, please refer to [Description of FastDeploy compilation options](./README.md)
+
+## Cross-compilation environment construction
+
+### Host Environment Requirements
+- os:Ubuntu == 16.04
+- cmake: version >= 3.10.0
+
+### Building the compilation environment
+You can enter the FastDeploy/tools/timvx directory and use the following command to install:
+```bash
+cd FastDeploy/tools/timvx
+bash install.sh
+```
+You can also install it with the following commands:
+```bash
+ # 1. Install basic software
+apt update
+apt-get install -y --no-install-recommends \
+ gcc g++ git make wget python unzip
+
+# 2. Install arm gcc toolchains
+apt-get install -y --no-install-recommends \
+ g++-arm-linux-gnueabi gcc-arm-linux-gnueabi \
+ g++-arm-linux-gnueabihf gcc-arm-linux-gnueabihf \
+ gcc-aarch64-linux-gnu g++-aarch64-linux-gnu
+
+# 3. Install cmake 3.10 or above
+wget -c https://mms-res.cdn.bcebos.com/cmake-3.10.3-Linux-x86_64.tar.gz && \
+ tar xzf cmake-3.10.3-Linux-x86_64.tar.gz && \
+ mv cmake-3.10.3-Linux-x86_64 /opt/cmake-3.10 && \
+ ln -s /opt/cmake-3.10/bin/cmake /usr/bin/cmake && \
+ ln -s /opt/cmake-3.10/bin/ccmake /usr/bin/ccmake
+```
+
+## FastDeploy cross-compilation library compilation based on PaddleLite
+After setting up the cross-compilation environment, the compilation command is as follows:
+```bash
+# Download the latest source code
+git clone https://github.com/PaddlePaddle/FastDeploy.git
+cd FastDeploy
+mkdir build && cd build
+
+# CMake configuration with RK toolchain
+cmake -DCMAKE_TOOLCHAIN_FILE=./../cmake/toolchain.cmake \
+ -DWITH_TIMVX=ON \
+ -DTARGET_ABI=armhf \
+ -DCMAKE_INSTALL_PREFIX=fastdeploy-tmivx \
+ -DENABLE_VISION=ON \ # 是否编译集成视觉模型的部署模块,可选择开启
+ -Wno-dev ..
+
+# Build FastDeploy RV1126 C++ SDK
+make -j8
+make install
+```
+After the compilation is complete, the fastdeploy-tmivx directory will be generated, indicating that the FastDeploy library based on PadddleLite TIM-VX has been compiled.
+
+## Prepare the Soc environment
+Before deployment, ensure that the version of the driver galcore.so of the Verisilicon Linux Kernel NPU meets the requirements. Before deployment, please log in to the development board, and enter the following command through the command line to query the NPU driver version. The recommended version of the Rockchip driver is: 6.4.6.5
+```bash
+dmesg | grep Galcore
+```
+If the current version does not comply with the above, please read the following content carefully to ensure that the underlying NPU driver environment is correct.
+
+There are two ways to modify the current NPU driver version:
+1. Manually replace the NPU driver version. (recommend)
+2. flash the machine, and flash the firmware that meets the requirements of the NPU driver version.
+
+### Manually replace the NPU driver version
+1. Use the following command to download and decompress the PaddleLite demo, which provides ready-made driver files
+```bash
+wget https://paddlelite-demo.bj.bcebos.com/devices/generic/PaddleLite-generic-demo.tar.gz
+tar -xf PaddleLite-generic-demo.tar.gz
+```
+2. Use `uname -a` to check `Linux Kernel` version, it is determined to be version 4.19.111.
+3. Upload `galcore.ko` under `PaddleLite-generic-demo/libs/PaddleLite/linux/armhf/lib/verisilicon_timvx/viv_sdk_6_4_6_5/lib/1126/4.19.111/` path to the development board.
+4. Log in to the development board, enter `sudo rmmod galcore` on the command line to uninstall the original driver, and enter `sudo insmod galcore.ko` to load the uploaded device driver. (Whether sudo is needed depends on the actual situation of the development board. For some adb-linked devices, please adb root in advance). If this step fails, go to method 2.
+5. Enter `dmesg | grep Galcore` in the development board to query the NPU driver version, and it is determined to be: 6.4.6.5
+
+### flash
+According to the specific development board model, ask the development board seller or the official website customer service for the firmware and flashing method corresponding to the 6.4.6.5 version of the NPU driver.
+
+For more details, please refer to: [PaddleLite prepares the device environment](https://www.paddlepaddle.org.cn/lite/develop/demo_guides/verisilicon_timvx.html#zhunbeishebeihuanjing)
+
+## Deployment example based on FastDeploy on RV1126
+1. For deploying the PaddleClas classification model on RV1126, please refer to: [C++ deployment example of PaddleClas classification model on RV1126](../../../examples/vision/classification/paddleclas/rv1126/README.md)
+
+2. For deploying PPYOLOE detection model on RV1126, please refer to: [C++ deployment example of PPYOLOE detection model on RV1126](../../../examples/vision/detection/paddledetection/rv1126/README.md)
+
+3. For deploying YOLOv5 detection model on RV1126, please refer to: [C++ Deployment Example of YOLOv5 Detection Model on RV1126](../../../examples/vision/detection/yolov5/rv1126/README.md)
+
+4. For deploying PP-LiteSeg segmentation model on RV1126, please refer to: [C++ Deployment Example of PP-LiteSeg Segmentation Model on RV1126](../../../examples/vision/segmentation/paddleseg/rv1126/README.md)
diff --git a/docs/en/build_and_install/xpu.md b/docs/en/build_and_install/xpu.md
new file mode 100755
index 000000000..403837e5d
--- /dev/null
+++ b/docs/en/build_and_install/xpu.md
@@ -0,0 +1,78 @@
+# How to Build KunlunXin XPU Deployment Environment
+
+FastDeploy supports deployment AI on KunlunXin XPU based on Paddle-Lite backend. For more detailed information, please refer to: [PaddleLite Deployment Example](https://www.paddlepaddle.org.cn/lite/develop/demo_guides/kunlunxin_xpu.html#xpu)。
+
+This document describes how to compile the C++ FastDeploy library based on PaddleLite.
+
+The relevant compilation options are described as follows:
+|Compile Options|Default Values|Description|Remarks|
+|:---|:---|:---|:---|
+| ENABLE_LITE_BACKEND | OFF | It needs to be set to ON when compiling the RK library| - |
+| WITH_XPU | OFF | It needs to be set to ON when compiling the KunlunXin XPU library| - |
+| ENABLE_ORT_BACKEND | OFF | whether to intergrate ONNX Runtime backend | - |
+| ENABLE_PADDLE_BACKEND | OFF | whether to intergrate Paddle Inference backend | - |
+| ENABLE_OPENVINO_BACKEND | OFF | whether to intergrate OpenVINO backend | - |
+| ENABLE_VISION | OFF | whether to intergrate vision models | - |
+| ENABLE_TEXT | OFF | whether to intergrate text models | - |
+
+The configuration for third libraries(Optional, if the following option is not defined, the prebuilt third libraries will download automaticly while building FastDeploy).
+| Option | Description |
+| :---------------------- | :--------------------------------------------------------------------------------------------- |
+| ORT_DIRECTORY | While ENABLE_ORT_BACKEND=ON, use ORT_DIRECTORY to specify your own ONNX Runtime library path. |
+| OPENCV_DIRECTORY | While ENABLE_VISION=ON, use OPENCV_DIRECTORY to specify your own OpenCV library path. |
+| OPENVINO_DIRECTORY | While ENABLE_OPENVINO_BACKEND=ON, use OPENVINO_DIRECTORY to specify your own OpenVINO library path. |
+
+For more compilation options, please refer to [Description of FastDeploy compilation options](./README.md)
+
+## C++ FastDeploy library compilation based on PaddleLite
+- OS: Linux
+- gcc/g++: version >= 8.2
+- cmake: version >= 3.15
+
+It it recommend install OpenCV library manually, and define `-DOPENCV_DIRECTORY` to set path of OpenCV library(If the flag is not defined, a prebuilt OpenCV library will be downloaded automaticly while building FastDeploy, but the prebuilt OpenCV cannot support reading video file or other function e.g `imshow`)
+```
+sudo apt-get install libopencv-dev
+```
+
+The compilation command is as follows:
+```bash
+# Download the latest source code
+git clone https://github.com/PaddlePaddle/FastDeploy.git
+cd FastDeploy
+mkdir build && cd build
+
+# CMake configuration with KunlunXin xpu toolchain
+cmake -DWITH_XPU=ON \
+ -DWITH_GPU=OFF \
+ -DENABLE_ORT_BACKEND=ON \
+ -DENABLE_PADDLE_BACKEND=ON \
+ -DCMAKE_INSTALL_PREFIX=fastdeploy-xpu \
+ -DENABLE_VISION=ON \
+ -DOPENCV_DIRECTORY=/usr/lib/x86_64-linux-gnu/cmake/opencv4 \
+ ..
+
+# Build FastDeploy KunlunXin XPU C++ SDK
+make -j8
+make install
+```
+After the compilation is complete, the fastdeploy-xpu directory will be generated, indicating that the PadddleLite-based FastDeploy library has been compiled.
+
+## Python compile
+The compilation command is as follows:
+```bash
+git clone https://github.com/PaddlePaddle/FastDeploy.git
+cd FastDeploy/python
+export WITH_XPU=ON
+export WITH_GPU=OFF
+export ENABLE_ORT_BACKEND=ON
+export ENABLE_PADDLE_BACKEND=ON
+export ENABLE_VISION=ON
+# The OPENCV_DIRECTORY is optional, if not exported, a prebuilt OpenCV library will be downloaded
+export OPENCV_DIRECTORY=/usr/lib/x86_64-linux-gnu/cmake/opencv4
+
+python setup.py build
+python setup.py bdist_wheel
+```
+After the compilation is completed, the compiled `wheel` package will be generated in the `FastDeploy/python/dist` directory, just pip install it directly
+
+During the compilation process, if you modify the compilation parameters, in order to avoid the cache impact, you can delete the two subdirectories `build` and `.setuptools-cmake-build` under the `FastDeploy/python` directory and then recompile.
diff --git a/examples/vision/classification/paddleclas/cpp/README.md b/examples/vision/classification/paddleclas/cpp/README.md
old mode 100644
new mode 100755
index 066340467..dff76da18
--- a/examples/vision/classification/paddleclas/cpp/README.md
+++ b/examples/vision/classification/paddleclas/cpp/README.md
@@ -30,6 +30,10 @@ wget https://gitee.com/paddlepaddle/PaddleClas/raw/release/2.4/deploy/images/Ima
./infer_demo ResNet50_vd_infer ILSVRC2012_val_00000010.jpeg 1
# GPU上TensorRT推理
./infer_demo ResNet50_vd_infer ILSVRC2012_val_00000010.jpeg 2
+# IPU推理
+./infer_demo ResNet50_vd_infer ILSVRC2012_val_00000010.jpeg 3
+# KunlunXin XPU推理
+./infer_demo ResNet50_vd_infer ILSVRC2012_val_00000010.jpeg 4
```
以上命令只适用于Linux或MacOS, Windows下SDK的使用方式请参考:
diff --git a/examples/vision/classification/paddleclas/cpp/infer.cc b/examples/vision/classification/paddleclas/cpp/infer.cc
old mode 100644
new mode 100755
index bdd87ecdc..244accfa7
--- a/examples/vision/classification/paddleclas/cpp/infer.cc
+++ b/examples/vision/classification/paddleclas/cpp/infer.cc
@@ -96,6 +96,32 @@ void IpuInfer(const std::string& model_dir, const std::string& image_file) {
std::cout << res.Str() << std::endl;
}
+void XpuInfer(const std::string& model_dir, const std::string& image_file) {
+ auto model_file = model_dir + sep + "inference.pdmodel";
+ auto params_file = model_dir + sep + "inference.pdiparams";
+ auto config_file = model_dir + sep + "inference_cls.yaml";
+
+ auto option = fastdeploy::RuntimeOption();
+ option.UseXpu();
+ auto model = fastdeploy::vision::classification::PaddleClasModel(
+ model_file, params_file, config_file, option);
+ if (!model.Initialized()) {
+ std::cerr << "Failed to initialize." << std::endl;
+ return;
+ }
+
+ auto im = cv::imread(image_file);
+
+ fastdeploy::vision::ClassifyResult res;
+ if (!model.Predict(im, &res)) {
+ std::cerr << "Failed to predict." << std::endl;
+ return;
+ }
+
+ // print res
+ std::cout << res.Str() << std::endl;
+}
+
void TrtInfer(const std::string& model_dir, const std::string& image_file) {
auto model_file = model_dir + sep + "inference.pdmodel";
auto params_file = model_dir + sep + "inference.pdiparams";
@@ -128,7 +154,7 @@ int main(int argc, char* argv[]) {
"e.g ./infer_demo ./ResNet50_vd ./test.jpeg 0"
<< 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."
+ "with gpu; 2: run with gpu and use tensorrt backend; 3: run with ipu; 4: run with xpu."
<< std::endl;
return -1;
}
@@ -141,6 +167,8 @@ int main(int argc, char* argv[]) {
TrtInfer(argv[1], argv[2]);
} else if (std::atoi(argv[3]) == 3) {
IpuInfer(argv[1], argv[2]);
+ } else if (std::atoi(argv[3]) == 4) {
+ XpuInfer(argv[1], argv[2]);
}
return 0;
}
diff --git a/examples/vision/classification/paddleclas/python/README.md b/examples/vision/classification/paddleclas/python/README.md
old mode 100644
new mode 100755
index 9d17e6f65..5a1baff7f
--- a/examples/vision/classification/paddleclas/python/README.md
+++ b/examples/vision/classification/paddleclas/python/README.md
@@ -25,6 +25,8 @@ python infer.py --model ResNet50_vd_infer --image ILSVRC2012_val_00000010.jpeg -
python infer.py --model ResNet50_vd_infer --image ILSVRC2012_val_00000010.jpeg --device gpu --use_trt True --topk 1
# IPU推理(注意:IPU推理首次运行会有序列化模型的操作,有一定耗时,需要耐心等待)
python infer.py --model ResNet50_vd_infer --image ILSVRC2012_val_00000010.jpeg --device ipu --topk 1
+# XPU推理
+python infer.py --model ResNet50_vd_infer --image ILSVRC2012_val_00000010.jpeg --device xpu --topk 1
```
运行完成后返回结果如下所示
diff --git a/examples/vision/classification/paddleclas/python/infer.py b/examples/vision/classification/paddleclas/python/infer.py
old mode 100644
new mode 100755
index 0b2d35a21..3c150533c
--- a/examples/vision/classification/paddleclas/python/infer.py
+++ b/examples/vision/classification/paddleclas/python/infer.py
@@ -35,6 +35,9 @@ def build_option(args):
if args.device.lower() == "ipu":
option.use_ipu()
+ if args.device.lower() == "xpu":
+ option.use_xpu()
+
if args.use_trt:
option.use_trt_backend()
return option
diff --git a/examples/vision/detection/yolov5/cpp/CMakeLists.txt b/examples/vision/detection/yolov5/cpp/CMakeLists.txt
old mode 100644
new mode 100755
index 93540a7e8..2b3f8c54f
--- a/examples/vision/detection/yolov5/cpp/CMakeLists.txt
+++ b/examples/vision/detection/yolov5/cpp/CMakeLists.txt
@@ -12,3 +12,7 @@ include_directories(${FASTDEPLOY_INCS})
add_executable(infer_demo ${PROJECT_SOURCE_DIR}/infer.cc)
# 添加FastDeploy库依赖
target_link_libraries(infer_demo ${FASTDEPLOY_LIBS})
+
+add_executable(infer_paddle_demo ${PROJECT_SOURCE_DIR}/infer_paddle_model.cc)
+# 添加FastDeploy库依赖
+target_link_libraries(infer_paddle_demo ${FASTDEPLOY_LIBS})
diff --git a/examples/vision/detection/yolov5/cpp/README.md b/examples/vision/detection/yolov5/cpp/README.md
old mode 100644
new mode 100755
index ece3826a5..581f1c49b
--- a/examples/vision/detection/yolov5/cpp/README.md
+++ b/examples/vision/detection/yolov5/cpp/README.md
@@ -12,16 +12,33 @@
```bash
mkdir build
cd build
-# 下载FastDeploy预编译库,用户可在上文提到的`FastDeploy预编译库`中自行选择合适的版本使用
+# 下载 FastDeploy 预编译库,用户可在上文提到的`FastDeploy预编译库`中自行选择合适的版本使用
wget https://bj.bcebos.com/fastdeploy/release/cpp/fastdeploy-linux-x64-x.x.x.tgz
tar xvf fastdeploy-linux-x64-x.x.x.tgz
cmake .. -DFASTDEPLOY_INSTALL_DIR=${PWD}/fastdeploy-linux-x64-x.x.x
make -j
-#下载官方转换好的yolov5模型文件和测试图片
-wget https://bj.bcebos.com/paddlehub/fastdeploy/yolov5s.onnx
+#下载官方转换好的 yolov5 Paddle 模型文件和测试图片
+wget https://bj.bcebos.com/paddlehub/fastdeploy/yolov5s_infer.tar
+tar -xvf yolov5s_infer.tar
wget https://gitee.com/paddlepaddle/PaddleDetection/raw/release/2.4/demo/000000014439.jpg
+# CPU推理
+./infer_paddle_demo yolov5s_infer 000000014439.jpg 0
+# GPU推理
+./infer_paddle_demo yolov5s_infer 000000014439.jpg 1
+# GPU上TensorRT推理
+./infer_paddle_demo yolov5s_infer 000000014439.jpg 2
+# XPU推理
+./infer_paddle_demo yolov5s_infer 000000014439.jpg 3
+```
+
+上述的模型为 Paddle 模型的推理,如果想要做 ONNX 模型的推理,可以按照如下步骤:
+```bash
+# 1. 下载官方转换好的 yolov5 ONNX 模型文件和测试图片
+wget https://bj.bcebos.com/paddlehub/fastdeploy/yolov5s.onnx
+wget https://gitee.com/paddlepaddle/PaddleDetection/raw/release/2.4/demo/000000014439.jpg
+
# CPU推理
./infer_demo yolov5s.onnx 000000014439.jpg 0
# GPU推理
@@ -29,7 +46,6 @@ wget https://gitee.com/paddlepaddle/PaddleDetection/raw/release/2.4/demo/0000000
# GPU上TensorRT推理
./infer_demo yolov5s.onnx 000000014439.jpg 2
```
-
运行完成可视化结果如下图所示
diff --git a/examples/vision/detection/yolov5/cpp/infer.cc b/examples/vision/detection/yolov5/cpp/infer.cc
old mode 100644
new mode 100755
index 1c3907918..fb20686de
--- a/examples/vision/detection/yolov5/cpp/infer.cc
+++ b/examples/vision/detection/yolov5/cpp/infer.cc
@@ -102,4 +102,4 @@ int main(int argc, char* argv[]) {
TrtInfer(argv[1], argv[2]);
}
return 0;
-}
+}
\ No newline at end of file
diff --git a/examples/vision/detection/yolov5/cpp/infer_paddle_model.cc b/examples/vision/detection/yolov5/cpp/infer_paddle_model.cc
new file mode 100755
index 000000000..d5692ce7c
--- /dev/null
+++ b/examples/vision/detection/yolov5/cpp/infer_paddle_model.cc
@@ -0,0 +1,154 @@
+// 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"
+#ifdef WIN32
+const char sep = '\\';
+#else
+const char sep = '/';
+#endif
+
+void CpuInfer(const std::string& model_dir, const std::string& image_file) {
+ auto model_file = model_dir + sep + "model.pdmodel";
+ auto params_file = model_dir + sep + "model.pdiparams";
+ fastdeploy::RuntimeOption option;
+ option.UseCpu();
+ auto model = fastdeploy::vision::detection::YOLOv5(
+ model_file, params_file, option, fastdeploy::ModelFormat::PADDLE);
+ if (!model.Initialized()) {
+ std::cerr << "Failed to initialize." << std::endl;
+ return;
+ }
+
+ 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("vis_result.jpg", vis_im);
+ std::cout << "Visualized result saved in ./vis_result.jpg" << std::endl;
+}
+
+void GpuInfer(const std::string& model_dir, const std::string& image_file) {
+ 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::detection::YOLOv5(
+ model_file, params_file, option, fastdeploy::ModelFormat::PADDLE);
+ if (!model.Initialized()) {
+ std::cerr << "Failed to initialize." << std::endl;
+ return;
+ }
+
+ 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("vis_result.jpg", vis_im);
+ std::cout << "Visualized result saved in ./vis_result.jpg" << std::endl;
+}
+
+void TrtInfer(const std::string& model_dir, const std::string& image_file) {
+ auto model_file = model_dir + sep + "model.pdmodel";
+ auto params_file = model_dir + sep + "model.pdiparams";
+ auto option = fastdeploy::RuntimeOption();
+ option.UseGpu();
+ option.UseTrtBackend();
+ option.SetTrtInputShape("images", {1, 3, 640, 640});
+ auto model = fastdeploy::vision::detection::YOLOv5(
+ model_file, params_file, option, fastdeploy::ModelFormat::PADDLE);
+
+ if (!model.Initialized()) {
+ std::cerr << "Failed to initialize." << std::endl;
+ return;
+ }
+
+ 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::Visualize::VisDetection(im, res);
+ cv::imwrite("vis_result.jpg", vis_im);
+ std::cout << "Visualized result saved in ./vis_result.jpg" << std::endl;
+}
+
+void XpuInfer(const std::string& model_dir, const std::string& image_file) {
+ auto model_file = model_dir + sep + "model.pdmodel";
+ auto params_file = model_dir + sep + "model.pdiparams";
+ fastdeploy::RuntimeOption option;
+ option.UseXpu();
+ auto model = fastdeploy::vision::detection::YOLOv5(
+ model_file, params_file, option, fastdeploy::ModelFormat::PADDLE);
+
+ if (!model.Initialized()) {
+ std::cerr << "Failed to initialize." << std::endl;
+ return;
+ }
+
+ 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("vis_result.jpg", vis_im);
+ std::cout << "Visualized result saved in ./vis_result.jpg" << std::endl;
+}
+
+int main(int argc, char* argv[]) {
+ if (argc < 4) {
+ std::cout << "Usage: infer_demo path/to/model path/to/image run_option, "
+ "e.g ./infer_model ./yolov5s_infer ./test.jpeg 0"
+ << 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; 3: run with KunlunXin XPU."
+ << std::endl;
+ return -1;
+ }
+
+ if (std::atoi(argv[3]) == 0) {
+ CpuInfer(argv[1], argv[2]);
+ } else if (std::atoi(argv[3]) == 1) {
+ GpuInfer(argv[1], argv[2]);
+ } else if (std::atoi(argv[3]) == 2) {
+ TrtInfer(argv[1], argv[2]);
+ } else if (std::atoi(argv[3]) == 3) {
+ XpuInfer(argv[1], argv[2]);
+ }
+ return 0;
+}
diff --git a/examples/vision/detection/yolov5/python/README.md b/examples/vision/detection/yolov5/python/README.md
old mode 100644
new mode 100755
index 4f47b3084..83f6ed781
--- a/examples/vision/detection/yolov5/python/README.md
+++ b/examples/vision/detection/yolov5/python/README.md
@@ -13,15 +13,18 @@ git clone https://github.com/PaddlePaddle/FastDeploy.git
cd examples/vision/detection/yolov5/python/
#下载yolov5模型文件和测试图片
-wget https://bj.bcebos.com/paddlehub/fastdeploy/yolov5s.onnx
+wget https://bj.bcebos.com/paddlehub/fastdeploy/yolov5s_infer.tar
+tar -xf yolov5s_infer.tar
wget https://gitee.com/paddlepaddle/PaddleDetection/raw/release/2.4/demo/000000014439.jpg
# CPU推理
-python infer.py --model yolov5s.onnx --image 000000014439.jpg --device cpu
+python infer.py --model yolov5s_infer --image 000000014439.jpg --device cpu
# GPU推理
-python infer.py --model yolov5s.onnx --image 000000014439.jpg --device gpu
+python infer.py --model yolov5s_infer --image 000000014439.jpg --device gpu
# GPU上使用TensorRT推理
-python infer.py --model yolov5s.onnx --image 000000014439.jpg --device gpu --use_trt True
+python infer.py --model yolov5s_infer --image 000000014439.jpg --device gpu --use_trt True
+# XPU推理
+python infer.py --model yolov5s_infer --image 000000014439.jpg --device xpu
```
运行完成可视化结果如下图所示
diff --git a/examples/vision/detection/yolov5/python/infer.py b/examples/vision/detection/yolov5/python/infer.py
old mode 100644
new mode 100755
index 462740e9c..b155af0ed
--- a/examples/vision/detection/yolov5/python/infer.py
+++ b/examples/vision/detection/yolov5/python/infer.py
@@ -1,20 +1,20 @@
import fastdeploy as fd
import cv2
+import os
def parse_arguments():
import argparse
import ast
parser = argparse.ArgumentParser()
- parser.add_argument(
- "--model", default=None, help="Path of yolov5 onnx model.")
+ parser.add_argument("--model", default=None, help="Path of yolov5 model.")
parser.add_argument(
"--image", default=None, help="Path of test image file.")
parser.add_argument(
"--device",
type=str,
default='cpu',
- help="Type of inference device, support 'cpu' or 'gpu'.")
+ help="Type of inference device, support 'cpu' or 'gpu' or 'xpu'.")
parser.add_argument(
"--use_trt",
type=ast.literal_eval,
@@ -25,6 +25,8 @@ def parse_arguments():
def build_option(args):
option = fd.RuntimeOption()
+ if args.device.lower() == "xpu":
+ option.use_xpu()
if args.device.lower() == "gpu":
option.use_gpu()
@@ -37,14 +39,15 @@ def build_option(args):
args = parse_arguments()
-if args.model is None:
- model = fd.download_model(name='YOLOv5s')
-else:
- model = args.model
-
# 配置runtime,加载模型
runtime_option = build_option(args)
-model = fd.vision.detection.YOLOv5(model, runtime_option=runtime_option)
+model_file = os.path.join(args.model, "model.pdmodel")
+params_file = os.path.join(args.model, "model.pdiparams")
+model = fd.vision.detection.YOLOv5(
+ model_file,
+ params_file,
+ runtime_option=runtime_option,
+ model_format=fd.ModelFormat.PADDLE)
# 预测图片检测结果
if args.image is None:
diff --git a/fastdeploy/backends/lite/lite_backend.cc b/fastdeploy/backends/lite/lite_backend.cc
index 7e3e09f8d..20afa5e28 100755
--- a/fastdeploy/backends/lite/lite_backend.cc
+++ b/fastdeploy/backends/lite/lite_backend.cc
@@ -43,24 +43,33 @@ void LiteBackend::BuildOption(const LiteBackendOption& option) {
option_ = option;
std::vector valid_places;
if (option_.enable_int8) {
- valid_places.push_back(
+ if(option_.enable_xpu) {
+ valid_places.push_back(
+ paddle::lite_api::Place{TARGET(kXPU), PRECISION(kInt8)});
+ } else {
+ valid_places.push_back(
paddle::lite_api::Place{TARGET(kARM), PRECISION(kInt8)});
+ }
FDINFO << "Lite::Backend enable_int8 option is ON ! Lite::Backend will "
<< "inference with int8 precision!" << std::endl;
}
if (option_.enable_fp16) {
- paddle::lite_api::MobileConfig check_fp16_config;
- // Determine whether the device supports the FP16
- // instruction set (or whether it is an arm device
- // of the armv8.2 architecture)
- supported_fp16_ = check_fp16_config.check_fp16_valid();
- if (supported_fp16_) {
+ if(option_.enable_xpu){
valid_places.push_back(
- paddle::lite_api::Place{TARGET(kARM), PRECISION(kFP16)});
- FDINFO << "Your device is supported fp16 ! Lite::Backend will "
- << "inference with fp16 precision!" << std::endl;
+ paddle::lite_api::Place{TARGET(kXPU), PRECISION(kFP16)});
} else {
- FDWARNING << "This device is not supported fp16, will skip fp16 option.";
+ paddle::lite_api::MobileConfig check_fp16_config;
+ // Determine whether the device supports the FP16
+ // instruction set (or whether it is an arm device
+ // of the armv8.2 architecture)
+ supported_fp16_ = check_fp16_config.check_fp16_valid();
+ if (supported_fp16_) {
+ valid_places.push_back(
+ paddle::lite_api::Place{TARGET(kARM), PRECISION(kFP16)});
+ FDINFO << "The device supports FP16, Lite::Backend will inference with FP16 precision." << std::endl;
+ } else {
+ FDWARNING << "The device doesn't support FP16, will fallback to FP32.";
+ }
}
}
if (!option_.nnadapter_subgraph_partition_config_path.empty()) {
@@ -81,8 +90,24 @@ void LiteBackend::BuildOption(const LiteBackendOption& option) {
valid_places.push_back(
paddle::lite_api::Place{TARGET(kARM), PRECISION(kInt8)});
}
- valid_places.push_back(
+
+ if(option_.enable_xpu){
+ valid_places.push_back(
+ paddle::lite_api::Place{TARGET(kXPU), PRECISION(kFloat)});
+ valid_places.push_back(
+ paddle::lite_api::Place{TARGET(kX86), PRECISION(kFloat)});
+ config_.set_xpu_dev_per_thread(option_.device_id);
+ config_.set_xpu_workspace_l3_size_per_thread(option_.xpu_l3_workspace_size);
+ config_.set_xpu_l3_cache_method(option_.xpu_l3_workspace_size, option_.xpu_locked);
+ config_.set_xpu_conv_autotune(option_.xpu_autotune, option_.xpu_autotune_file);
+ config_.set_xpu_multi_encoder_method(option_.xpu_precision, option_.xpu_adaptive_seqlen);
+ if (option_.xpu_enable_multi_stream) {
+ config_.enable_xpu_multi_stream();
+ }
+ } else {
+ valid_places.push_back(
paddle::lite_api::Place{TARGET(kARM), PRECISION(kFloat)});
+ }
config_.set_valid_places(valid_places);
if (option_.threads > 0) {
config_.set_threads(option_.threads);
@@ -160,7 +185,9 @@ bool LiteBackend::InitFromPaddle(const std::string& model_file,
auto shape = tensor->shape();
info.shape.assign(shape.begin(), shape.end());
info.name = output_names[i];
- info.dtype = LiteDataTypeToFD(tensor->precision());
+ if(!option_.enable_xpu){
+ info.dtype = LiteDataTypeToFD(tensor->precision());
+ }
outputs_desc_.emplace_back(info);
}
@@ -239,6 +266,9 @@ bool LiteBackend::Infer(std::vector& inputs,
outputs->resize(outputs_desc_.size());
for (size_t i = 0; i < outputs_desc_.size(); ++i) {
auto tensor = predictor_->GetOutput(i);
+ if(outputs_desc_[i].dtype != LiteDataTypeToFD(tensor->precision())){
+ outputs_desc_[i].dtype = LiteDataTypeToFD(tensor->precision());
+ }
(*outputs)[i].Resize(tensor->shape(), outputs_desc_[i].dtype,
outputs_desc_[i].name);
memcpy((*outputs)[i].MutableData(), tensor->data(),
diff --git a/fastdeploy/backends/lite/lite_backend.h b/fastdeploy/backends/lite/lite_backend.h
index 279acf5df..0221f507f 100755
--- a/fastdeploy/backends/lite/lite_backend.h
+++ b/fastdeploy/backends/lite/lite_backend.h
@@ -45,6 +45,15 @@ struct LiteBackendOption {
// Such as fp16, different device target (kARM/kXPU/kNPU/...)
std::string nnadapter_subgraph_partition_config_path = "";
bool enable_timvx = false;
+ bool enable_xpu = false;
+ int device_id = 0;
+ int xpu_l3_workspace_size = 0xfffc00;
+ bool xpu_locked = false;
+ bool xpu_autotune = true;
+ std::string xpu_autotune_file = "";
+ std::string xpu_precision = "int16";
+ bool xpu_adaptive_seqlen = false;
+ bool xpu_enable_multi_stream = false;
};
// Convert data type from paddle lite to fastdeploy
diff --git a/fastdeploy/core/fd_type.cc b/fastdeploy/core/fd_type.cc
index ba3319dbc..3624b732d 100755
--- a/fastdeploy/core/fd_type.cc
+++ b/fastdeploy/core/fd_type.cc
@@ -62,6 +62,9 @@ std::string Str(const Device& d) {
case Device::TIMVX:
out = "Device::TIMVX";
break;
+ case Device::XPU:
+ out = "Device::XPU";
+ break;
default:
out = "Device::UNKOWN";
}
@@ -82,6 +85,9 @@ std::ostream& operator<<(std::ostream& out,const Device& d){
case Device::TIMVX:
out << "Device::TIMVX";
break;
+ case Device::XPU:
+ out << "Device::XPU";
+ break;
default:
out << "Device::UNKOWN";
}
diff --git a/fastdeploy/core/fd_type.h b/fastdeploy/core/fd_type.h
index ba18d8e36..d39c56fdf 100755
--- a/fastdeploy/core/fd_type.h
+++ b/fastdeploy/core/fd_type.h
@@ -22,7 +22,7 @@
namespace fastdeploy {
-enum FASTDEPLOY_DECL Device { CPU, GPU, RKNPU, IPU, TIMVX};
+enum FASTDEPLOY_DECL Device { CPU, GPU, RKNPU, IPU, TIMVX, XPU};
FASTDEPLOY_DECL std::string Str(const Device& d);
diff --git a/fastdeploy/fastdeploy_model.cc b/fastdeploy/fastdeploy_model.cc
index ad8c1329d..4d7a8e364 100755
--- a/fastdeploy/fastdeploy_model.cc
+++ b/fastdeploy/fastdeploy_model.cc
@@ -51,6 +51,7 @@ bool FastDeployModel::InitRuntimeWithSpecifiedBackend() {
bool use_ipu = (runtime_option.device == Device::IPU);
bool use_rknpu = (runtime_option.device == Device::RKNPU);
bool use_timvx = (runtime_option.device == Device::TIMVX);
+ bool use_xpu = (runtime_option.device == Device::XPU);
if (use_gpu) {
if (!IsSupported(valid_gpu_backends, runtime_option.backend)) {
@@ -67,6 +68,11 @@ bool FastDeployModel::InitRuntimeWithSpecifiedBackend() {
FDERROR << "The valid timvx backends of model " << ModelName() << " are " << Str(valid_timvx_backends) << ", " << runtime_option.backend << " is not supported." << std::endl;
return false;
}
+ } else if (use_xpu) {
+ if (!IsSupported(valid_xpu_backends, runtime_option.backend)) {
+ FDERROR << "The valid xpu backends of model " << ModelName() << " are " << Str(valid_xpu_backends) << ", " << runtime_option.backend << " is not supported." << std::endl;
+ return false;
+ }
} else if(use_ipu) {
if (!IsSupported(valid_ipu_backends, runtime_option.backend)) {
FDERROR << "The valid ipu backends of model " << ModelName() << " are " << Str(valid_ipu_backends) << ", " << runtime_option.backend << " is not supported." << std::endl;
@@ -102,6 +108,8 @@ bool FastDeployModel::InitRuntimeWithSpecifiedDevice() {
return CreateRKNPUBackend();
} else if (runtime_option.device == Device::TIMVX) {
return CreateTimVXBackend();
+ } else if (runtime_option.device == Device::XPU) {
+ return CreateXPUBackend();
} else if (runtime_option.device == Device::IPU) {
#ifdef WITH_IPU
return CreateIpuBackend();
@@ -111,7 +119,7 @@ bool FastDeployModel::InitRuntimeWithSpecifiedDevice() {
return false;
#endif
}
- FDERROR << "Only support CPU/GPU/IPU/RKNPU/TIMVX now." << std::endl;
+ FDERROR << "Only support CPU/GPU/IPU/RKNPU/TIMVX/XPU now." << std::endl;
return false;
}
@@ -225,6 +233,29 @@ bool FastDeployModel::CreateTimVXBackend() {
return false;
}
+bool FastDeployModel::CreateXPUBackend() {
+ if (valid_xpu_backends.size() == 0) {
+ FDERROR << "There's no valid xpu backends for model: " << ModelName()
+ << std::endl;
+ return false;
+ }
+
+ for (size_t i = 0; i < valid_xpu_backends.size(); ++i) {
+ if (!IsBackendAvailable(valid_xpu_backends[i])) {
+ continue;
+ }
+ runtime_option.backend = valid_xpu_backends[i];
+ runtime_ = std::unique_ptr(new Runtime());
+ if (!runtime_->Init(runtime_option)) {
+ return false;
+ }
+ runtime_initialized_ = true;
+ return true;
+ }
+ FDERROR << "Found no valid backend for model: " << ModelName() << std::endl;
+ return false;
+}
+
bool FastDeployModel::CreateIpuBackend() {
if (valid_ipu_backends.size() == 0) {
FDERROR << "There's no valid ipu backends for model: " << ModelName()
diff --git a/fastdeploy/fastdeploy_model.h b/fastdeploy/fastdeploy_model.h
index 5a6efba09..5c8809196 100755
--- a/fastdeploy/fastdeploy_model.h
+++ b/fastdeploy/fastdeploy_model.h
@@ -45,6 +45,9 @@ class FASTDEPLOY_DECL FastDeployModel {
/** Model's valid timvx backends. This member defined all the timvx backends have successfully tested for the model
*/
std::vector valid_timvx_backends = {};
+ /** Model's valid KunlunXin xpu backends. This member defined all the KunlunXin xpu backends have successfully tested for the model
+ */
+ std::vector valid_xpu_backends = {};
/** Model's valid hardware backends. This member defined all the gpu backends have successfully tested for the model
*/
std::vector valid_rknpu_backends = {};
@@ -143,6 +146,7 @@ class FASTDEPLOY_DECL FastDeployModel {
bool CreateIpuBackend();
bool CreateRKNPUBackend();
bool CreateTimVXBackend();
+ bool CreateXPUBackend();
std::shared_ptr runtime_;
bool runtime_initialized_ = false;
diff --git a/fastdeploy/pybind/runtime.cc b/fastdeploy/pybind/runtime.cc
old mode 100644
new mode 100755
index 75767c665..d0cb0b5f8
--- a/fastdeploy/pybind/runtime.cc
+++ b/fastdeploy/pybind/runtime.cc
@@ -23,6 +23,7 @@ void BindRuntime(pybind11::module& m) {
.def("use_gpu", &RuntimeOption::UseGpu)
.def("use_cpu", &RuntimeOption::UseCpu)
.def("use_rknpu2", &RuntimeOption::UseRKNPU2)
+ .def("use_xpu", &RuntimeOption::UseXpu)
.def("set_external_stream", &RuntimeOption::SetExternalStream)
.def("set_cpu_thread_num", &RuntimeOption::SetCpuThreadNum)
.def("use_paddle_backend", &RuntimeOption::UsePaddleBackend)
@@ -100,7 +101,21 @@ void BindRuntime(pybind11::module& m) {
.def_readwrite("ipu_available_memory_proportion",
&RuntimeOption::ipu_available_memory_proportion)
.def_readwrite("ipu_enable_half_partial",
- &RuntimeOption::ipu_enable_half_partial);
+ &RuntimeOption::ipu_enable_half_partial)
+ .def_readwrite("xpu_l3_workspace_size",
+ &RuntimeOption::xpu_l3_workspace_size)
+ .def_readwrite("xpu_locked",
+ &RuntimeOption::xpu_locked)
+ .def_readwrite("xpu_autotune",
+ &RuntimeOption::xpu_autotune)
+ .def_readwrite("xpu_autotune_file",
+ &RuntimeOption::xpu_autotune_file)
+ .def_readwrite("xpu_precision",
+ &RuntimeOption::xpu_precision)
+ .def_readwrite("xpu_adaptive_seqlen",
+ &RuntimeOption::xpu_adaptive_seqlen)
+ .def_readwrite("xpu_enable_multi_stream",
+ &RuntimeOption::xpu_enable_multi_stream);
pybind11::class_(m, "TensorInfo")
.def_readwrite("name", &TensorInfo::name)
diff --git a/fastdeploy/runtime.cc b/fastdeploy/runtime.cc
old mode 100644
new mode 100755
index 1a51cebea..565c10607
--- a/fastdeploy/runtime.cc
+++ b/fastdeploy/runtime.cc
@@ -236,7 +236,26 @@ void RuntimeOption::UseRKNPU2(fastdeploy::rknpu2::CpuName rknpu2_name,
void RuntimeOption::UseTimVX() {
enable_timvx = true;
device = Device::TIMVX;
- UseLiteBackend();
+}
+
+void RuntimeOption::UseXpu(int xpu_id,
+ int l3_workspace_size,
+ bool locked,
+ bool autotune,
+ const std::string &autotune_file,
+ const std::string &precision,
+ bool adaptive_seqlen,
+ bool enable_multi_stream) {
+ enable_xpu = true;
+ device_id = xpu_id;
+ xpu_l3_workspace_size = l3_workspace_size;
+ xpu_locked=locked;
+ xpu_autotune=autotune;
+ xpu_autotune_file=autotune_file;
+ xpu_precision = precision;
+ xpu_adaptive_seqlen=adaptive_seqlen;
+ xpu_enable_multi_stream=enable_multi_stream;
+ device = Device::XPU;
}
void RuntimeOption::SetExternalStream(void* external_stream) {
@@ -532,8 +551,8 @@ bool Runtime::Init(const RuntimeOption& _option) {
FDINFO << "Runtime initialized with Backend::OPENVINO in "
<< Str(option.device) << "." << std::endl;
} else if (option.backend == Backend::LITE) {
- FDASSERT(option.device == Device::CPU || option.device == Device::TIMVX,
- "Backend::LITE only supports Device::CPU/Device::TIMVX.");
+ FDASSERT(option.device == Device::CPU || option.device == Device::TIMVX || option.device == Device::XPU,
+ "Backend::LITE only supports Device::CPU/Device::TIMVX/Device::XPU.");
CreateLiteBackend();
FDINFO << "Runtime initialized with Backend::LITE in " << Str(option.device)
<< "." << std::endl;
@@ -784,6 +803,16 @@ void Runtime::CreateLiteBackend() {
lite_option.nnadapter_subgraph_partition_config_path =
option.lite_nnadapter_subgraph_partition_config_path;
lite_option.enable_timvx = option.enable_timvx;
+ lite_option.enable_xpu = option.enable_xpu;
+ lite_option.device_id = option.device_id;
+ lite_option.xpu_l3_workspace_size = option.xpu_l3_workspace_size;
+ lite_option.xpu_locked = option.xpu_locked;
+ lite_option.xpu_autotune = option.xpu_autotune;
+ lite_option.xpu_autotune_file = option.xpu_autotune_file;
+ lite_option.xpu_precision = option.xpu_precision;
+ lite_option.xpu_adaptive_seqlen = option.xpu_adaptive_seqlen;
+ lite_option.xpu_enable_multi_stream = option.xpu_enable_multi_stream;
+
FDASSERT(option.model_format == ModelFormat::PADDLE,
"LiteBackend only support model format of ModelFormat::PADDLE");
backend_ = utils::make_unique();
diff --git a/fastdeploy/runtime.h b/fastdeploy/runtime.h
index 9c22c929f..064be2fce 100755
--- a/fastdeploy/runtime.h
+++ b/fastdeploy/runtime.h
@@ -102,6 +102,37 @@ struct FASTDEPLOY_DECL RuntimeOption {
/// Use TimVX to inference
void UseTimVX();
+ ///
+ /// \brief Turn on XPU.
+ ///
+ /// \param xpu_id the XPU card to use (default is 0).
+ /// \param l3_workspace_size The size of the video memory allocated by the l3
+ /// cache, the maximum is 16M.
+ /// \param locked Whether the allocated L3 cache can be locked. If false,
+ /// it means that the L3 cache is not locked, and the allocated L3
+ /// cache can be shared by multiple models, and multiple models
+ /// sharing the L3 cache will be executed sequentially on the card.
+ /// \param autotune Whether to autotune the conv operator in the model. If
+ /// true, when the conv operator of a certain dimension is executed
+ /// for the first time, it will automatically search for a better
+ /// algorithm to improve the performance of subsequent conv operators
+ /// of the same dimension.
+ /// \param autotune_file Specify the path of the autotune file. If
+ /// autotune_file is specified, the algorithm specified in the
+ /// file will be used and autotune will not be performed again.
+ /// \param precision Calculation accuracy of multi_encoder
+ /// \param adaptive_seqlen Is the input of multi_encoder variable length
+ /// \param enable_multi_stream Whether to enable the multi stream of xpu.
+ ///
+ void UseXpu(int xpu_id = 0,
+ int l3_workspace_size = 0xfffc00,
+ bool locked = false,
+ bool autotune = true,
+ const std::string& autotune_file = "",
+ const std::string& precision = "int16",
+ bool adaptive_seqlen = false,
+ bool enable_multi_stream = false);
+
void SetExternalStream(void* external_stream);
/*
@@ -354,6 +385,7 @@ struct FASTDEPLOY_DECL RuntimeOption {
std::string lite_optimized_model_dir = "";
std::string lite_nnadapter_subgraph_partition_config_path = "";
bool enable_timvx = false;
+ bool enable_xpu = false;
// ======Only for Trt Backend=======
std::map> trt_max_shape;
@@ -386,6 +418,15 @@ struct FASTDEPLOY_DECL RuntimeOption {
fastdeploy::rknpu2::CoreMask rknpu2_core_mask_ =
fastdeploy::rknpu2::CoreMask::RKNN_NPU_CORE_AUTO;
+ // ======Only for XPU Backend=======
+ int xpu_l3_workspace_size = 0xfffc00;
+ bool xpu_locked = false;
+ bool xpu_autotune = true;
+ std::string xpu_autotune_file = "";
+ std::string xpu_precision = "int16";
+ bool xpu_adaptive_seqlen = false;
+ bool xpu_enable_multi_stream = false;
+
std::string model_file = ""; // Path of model file
std::string params_file = ""; // Path of parameters file, can be empty
// format of input model
diff --git a/fastdeploy/vision/classification/ppcls/model.cc b/fastdeploy/vision/classification/ppcls/model.cc
index 5065bbfc2..e1b8d5249 100755
--- a/fastdeploy/vision/classification/ppcls/model.cc
+++ b/fastdeploy/vision/classification/ppcls/model.cc
@@ -29,6 +29,7 @@ PaddleClasModel::PaddleClasModel(const std::string& model_file,
Backend::LITE};
valid_gpu_backends = {Backend::ORT, Backend::PDINFER, Backend::TRT};
valid_timvx_backends = {Backend::LITE};
+ valid_xpu_backends = {Backend::LITE};
valid_ipu_backends = {Backend::PDINFER};
} else if (model_format == ModelFormat::ONNX) {
valid_cpu_backends = {Backend::ORT, Backend::OPENVINO};
diff --git a/fastdeploy/vision/detection/contrib/rknpu2/postprocessor.h b/fastdeploy/vision/detection/contrib/rknpu2/postprocessor.h
index 238c1c465..6dcda3b77 100755
--- a/fastdeploy/vision/detection/contrib/rknpu2/postprocessor.h
+++ b/fastdeploy/vision/detection/contrib/rknpu2/postprocessor.h
@@ -72,10 +72,11 @@ class FASTDEPLOY_DECL RKYOLOPostprocessor {
}
// Set Anchor
- void SetAnchor(std::vector anchors,int anchor_per_branch){
+ void SetAnchor(std::vector anchors, int anchor_per_branch) {
anchors_ = anchors;
anchor_per_branch_ = anchor_per_branch;
- };
+ }
+
private:
std::vector anchors_ = {10, 13, 16, 30, 33, 23, 30, 61, 62,
45, 59, 119, 116, 90, 156, 198, 373, 326};
diff --git a/fastdeploy/vision/detection/contrib/rknpu2/utils.h b/fastdeploy/vision/detection/contrib/rknpu2/utils.h
index 1d28b5f0e..1fa533082 100644
--- a/fastdeploy/vision/detection/contrib/rknpu2/utils.h
+++ b/fastdeploy/vision/detection/contrib/rknpu2/utils.h
@@ -31,4 +31,4 @@ int NMS(int valid_count, std::vector& output_locations,
} // namespace detection
} // namespace vision
-} // namespace fastdeploy
\ No newline at end of file
+} // namespace fastdeploy
diff --git a/fastdeploy/vision/detection/contrib/yolov5/yolov5.cc b/fastdeploy/vision/detection/contrib/yolov5/yolov5.cc
index 92d53dd10..d1bb31f22 100755
--- a/fastdeploy/vision/detection/contrib/yolov5/yolov5.cc
+++ b/fastdeploy/vision/detection/contrib/yolov5/yolov5.cc
@@ -27,6 +27,7 @@ YOLOv5::YOLOv5(const std::string& model_file, const std::string& params_file,
} else {
valid_cpu_backends = {Backend::PDINFER, Backend::ORT, Backend::LITE};
valid_gpu_backends = {Backend::PDINFER, Backend::ORT, Backend::TRT};
+ valid_xpu_backends = {Backend::LITE};
valid_timvx_backends = {Backend::LITE};
}
runtime_option = custom_option;
diff --git a/fastdeploy/vision/detection/ppdet/model.h b/fastdeploy/vision/detection/ppdet/model.h
index 5175bc4e6..090c99de7 100755
--- a/fastdeploy/vision/detection/ppdet/model.h
+++ b/fastdeploy/vision/detection/ppdet/model.h
@@ -185,7 +185,7 @@ class FASTDEPLOY_DECL PaddleYOLOv5 : public PPDetBase {
const ModelFormat& model_format = ModelFormat::PADDLE)
: PPDetBase(model_file, params_file, config_file, custom_option,
model_format) {
- valid_cpu_backends = {Backend::ORT,Backend::PDINFER};
+ valid_cpu_backends = {Backend::ORT, Backend::PDINFER};
valid_gpu_backends = {Backend::ORT, Backend::PDINFER, Backend::TRT};
initialized = Initialize();
}
@@ -201,7 +201,7 @@ class FASTDEPLOY_DECL PaddleYOLOv6 : public PPDetBase {
const ModelFormat& model_format = ModelFormat::PADDLE)
: PPDetBase(model_file, params_file, config_file, custom_option,
model_format) {
- valid_cpu_backends = {Backend::OPENVINO, Backend::ORT,Backend::PDINFER};
+ valid_cpu_backends = {Backend::OPENVINO, Backend::ORT, Backend::PDINFER};
valid_gpu_backends = {Backend::ORT, Backend::PDINFER, Backend::TRT};
initialized = Initialize();
}
@@ -217,7 +217,7 @@ class FASTDEPLOY_DECL PaddleYOLOv7 : public PPDetBase {
const ModelFormat& model_format = ModelFormat::PADDLE)
: PPDetBase(model_file, params_file, config_file, custom_option,
model_format) {
- valid_cpu_backends = {Backend::ORT,Backend::PDINFER};
+ valid_cpu_backends = {Backend::ORT, Backend::PDINFER};
valid_gpu_backends = {Backend::ORT, Backend::PDINFER, Backend::TRT};
initialized = Initialize();
}
diff --git a/python/fastdeploy/runtime.py b/python/fastdeploy/runtime.py
index 6461da66d..f9334efbf 100755
--- a/python/fastdeploy/runtime.py
+++ b/python/fastdeploy/runtime.py
@@ -245,6 +245,34 @@ class RuntimeOption:
return
return self._option.use_gpu(device_id)
+ def use_xpu(self,
+ device_id=0,
+ l3_workspace_size=16 * 1024 * 1024,
+ locked=False,
+ autotune=True,
+ autotune_file="",
+ precision="int16",
+ adaptive_seqlen=False,
+ enable_multi_stream=False):
+ """Inference with XPU
+
+ :param device_id: (int)The index of XPU will be used for inference, default 0
+ :param l3_workspace_size: (int)The size of the video memory allocated by the l3 cache, the maximum is 16M, default 16M
+ :param locked: (bool)Whether the allocated L3 cache can be locked. If false, it means that the L3 cache is not locked,
+ and the allocated L3 cache can be shared by multiple models, and multiple models
+ :param autotune: (bool)Whether to autotune the conv operator in the model.
+ If true, when the conv operator of a certain dimension is executed for the first time,
+ it will automatically search for a better algorithm to improve the performance of subsequent conv operators of the same dimension.
+ :param autotune_file: (str)Specify the path of the autotune file. If autotune_file is specified,
+ the algorithm specified in the file will be used and autotune will not be performed again.
+ :param precision: (str)Calculation accuracy of multi_encoder
+ :param adaptive_seqlen: (bool)adaptive_seqlen Is the input of multi_encoder variable length
+ :param enable_multi_stream: (bool)Whether to enable the multi stream of xpu.
+ """
+ return self._option.use_xpu(device_id, l3_workspace_size, locked,
+ autotune, autotune_file, precision,
+ adaptive_seqlen, enable_multi_stream)
+
def use_cpu(self):
"""Inference with CPU
"""
diff --git a/python/setup.py b/python/setup.py
index b4dc111c6..19a857678 100755
--- a/python/setup.py
+++ b/python/setup.py
@@ -65,11 +65,13 @@ setup_configs["ENABLE_POROS_BACKEND"] = os.getenv("ENABLE_POROS_BACKEND",
"OFF")
setup_configs["ENABLE_TRT_BACKEND"] = os.getenv("ENABLE_TRT_BACKEND", "OFF")
setup_configs["ENABLE_LITE_BACKEND"] = os.getenv("ENABLE_LITE_BACKEND", "OFF")
+setup_configs["PADDLELITE_URL"] = os.getenv("PADDLELITE_URL", "OFF")
setup_configs["ENABLE_VISION"] = os.getenv("ENABLE_VISION", "OFF")
setup_configs["ENABLE_FLYCV"] = os.getenv("ENABLE_FLYCV", "OFF")
setup_configs["ENABLE_TEXT"] = os.getenv("ENABLE_TEXT", "OFF")
setup_configs["WITH_GPU"] = os.getenv("WITH_GPU", "OFF")
setup_configs["WITH_IPU"] = os.getenv("WITH_IPU", "OFF")
+setup_configs["WITH_XPU"] = os.getenv("WITH_XPU", "OFF")
setup_configs["BUILD_ON_JETSON"] = os.getenv("BUILD_ON_JETSON", "OFF")
setup_configs["TRT_DIRECTORY"] = os.getenv("TRT_DIRECTORY", "UNDEFINED")
setup_configs["CUDA_DIRECTORY"] = os.getenv("CUDA_DIRECTORY",
@@ -78,10 +80,12 @@ setup_configs["LIBRARY_NAME"] = PACKAGE_NAME
setup_configs["PY_LIBRARY_NAME"] = PACKAGE_NAME + "_main"
setup_configs["OPENCV_DIRECTORY"] = os.getenv("OPENCV_DIRECTORY", "")
setup_configs["ORT_DIRECTORY"] = os.getenv("ORT_DIRECTORY", "")
-setup_configs["PADDLEINFERENCE_DIRECTORY"] = os.getenv("PADDLEINFERENCE_DIRECTORY", "")
+setup_configs["PADDLEINFERENCE_DIRECTORY"] = os.getenv(
+ "PADDLEINFERENCE_DIRECTORY", "")
setup_configs["RKNN2_TARGET_SOC"] = os.getenv("RKNN2_TARGET_SOC", "")
-if setup_configs["RKNN2_TARGET_SOC"] != "" or setup_configs["BUILD_ON_JETSON"] != "OFF":
+if setup_configs["RKNN2_TARGET_SOC"] != "" or setup_configs[
+ "BUILD_ON_JETSON"] != "OFF":
REQUIRED_PACKAGES = REQUIRED_PACKAGES.replace("opencv-python", "")
if setup_configs["WITH_GPU"] == "ON" or setup_configs[
From 6060f4060b935c9a41db916e6c87ce1afd05cba5 Mon Sep 17 00:00:00 2001
From: DefTruth <31974251+DefTruth@users.noreply.github.com>
Date: Fri, 16 Dec 2022 13:29:56 +0800
Subject: [PATCH 72/77] [Bug Fix] fix lite int64 datatype convert (#892)
Co-authored-by: Jason
---
fastdeploy/backends/lite/lite_backend.cc | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/fastdeploy/backends/lite/lite_backend.cc b/fastdeploy/backends/lite/lite_backend.cc
index 20afa5e28..c2a783ea4 100755
--- a/fastdeploy/backends/lite/lite_backend.cc
+++ b/fastdeploy/backends/lite/lite_backend.cc
@@ -249,12 +249,12 @@ bool LiteBackend::Infer(std::vector& inputs,
reinterpret_cast(const_cast(
inputs[i].CpuData())));
} else if (inputs[i].dtype == FDDataType::INT64) {
-#ifdef __aarch64__
+#if (defined(__aarch64__) || defined(__x86_64__) || defined(_M_X64) || defined(_M_ARM64))
tensor->CopyFromCpu(
reinterpret_cast(const_cast(
inputs[i].CpuData())));
#else
- FDASSERT(false, "FDDataType::INT64 is not support for Arm v7 now!");
+ FDASSERT(false, "FDDataType::INT64 is not support for x86/armv7 now!");
#endif
} else {
FDASSERT(false, "Unexpected data type of %d.", inputs[i].dtype);
From 1798ad69ed3ddf2b6eda064cc5ff161df10712ad Mon Sep 17 00:00:00 2001
From: leiqing <54695910+leiqing1@users.noreply.github.com>
Date: Sun, 18 Dec 2022 12:08:25 +0800
Subject: [PATCH 73/77] update readme in other languages (#903)
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
* Delete README_한국어.md
* Delete README_Ру́сский_язы́к.md
* Delete README_हिन्दी.md
* Create README_Pу́сский язы́к.md
* Create README_हिन्दी.md
* Create README_한국인.md
---
.../{README_Ру́сский_язы́к.md => README_Pу́сский язы́к.md} | 0
docs/docs_i18n/README_हिन्दी.md | 2 +-
docs/docs_i18n/{README_한국어.md => README_한국인.md} | 0
3 files changed, 1 insertion(+), 1 deletion(-)
rename docs/docs_i18n/{README_Ру́сский_язы́к.md => README_Pу́сский язы́к.md} (100%)
rename docs/docs_i18n/{README_한국어.md => README_한국인.md} (100%)
diff --git a/docs/docs_i18n/README_Ру́сский_язы́к.md b/docs/docs_i18n/README_Pу́сский язы́к.md
similarity index 100%
rename from docs/docs_i18n/README_Ру́сский_язы́к.md
rename to docs/docs_i18n/README_Pу́сский язы́к.md
diff --git a/docs/docs_i18n/README_हिन्दी.md b/docs/docs_i18n/README_हिन्दी.md
index 46113bee8..62ce1a886 100644
--- a/docs/docs_i18n/README_हिन्दी.md
+++ b/docs/docs_i18n/README_हिन्दी.md
@@ -1,4 +1,4 @@
-[English](../../README_EN.md) | [简体中文](../../README_CN.md) | हिन्दी | [日本語](./README_日本語.md) | [한국인](./README_한국어.md) | [Pу́сский язы́к](.//README_Ру́сский_язы́к.md)
+ [English](../../README_EN.md) | [简体中文](../../README_CN.md) | हिन्दी | [日本語](./README_日本語.md) | [한국인](./README_한국어.md) | [Pу́сский язы́к](.//README_Ру́сский_язы́к.md)

diff --git a/docs/docs_i18n/README_한국어.md b/docs/docs_i18n/README_한국인.md
similarity index 100%
rename from docs/docs_i18n/README_한국어.md
rename to docs/docs_i18n/README_한국인.md
From 95beb2bbf65654d03b65360ec10f815d918817a7 Mon Sep 17 00:00:00 2001
From: Zheng_Bicheng <58363586+Zheng-Bicheng@users.noreply.github.com>
Date: Mon, 19 Dec 2022 10:03:18 +0800
Subject: [PATCH 74/77] [RKNPU2] RKYOLO Support FP32 return value (#898)
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
* RKNPU2 Backend兼容其他模型的量化
fd_tensor正式移除zp和scale的量化参数
* 更新FP32返回值的RKYOLO
* 更新rkyolov5支持fp32格式
* 更新rkyolov5支持fp32格式
* 更新YOLOv5速度文档
Co-authored-by: DefTruth <31974251+DefTruth@users.noreply.github.com>
---
docs/cn/faq/rknpu2/rknpu2.md | 1 +
.../detection/rkyolo/cpp/infer_rkyolo.cc | 6 +-
.../backends/rknpu/rknpu2/rknpu2_backend.cc | 48 +++++------
fastdeploy/core/fd_tensor.cc | 10 ---
fastdeploy/core/fd_tensor.h | 4 -
.../detection/contrib/rknpu2/postprocessor.cc | 81 +++++++++----------
.../detection/contrib/rknpu2/postprocessor.h | 16 ++--
.../detection/contrib/rknpu2/preprocessor.cc | 18 -----
.../detection/contrib/rknpu2/preprocessor.h | 1 -
.../vision/detection/contrib/rknpu2/rkyolo.cc | 9 +--
10 files changed, 76 insertions(+), 118 deletions(-)
diff --git a/docs/cn/faq/rknpu2/rknpu2.md b/docs/cn/faq/rknpu2/rknpu2.md
index 0e1f920d6..c3a424af4 100644
--- a/docs/cn/faq/rknpu2/rknpu2.md
+++ b/docs/cn/faq/rknpu2/rknpu2.md
@@ -15,6 +15,7 @@ ONNX模型不能直接调用RK芯片中的NPU进行运算,需要把ONNX模型
| 任务场景 | 模型 | 模型版本(表示已经测试的版本) | ARM CPU/RKNN速度(ms) |
|------------------|-------------------|-------------------------------|--------------------|
| Detection | Picodet | Picodet-s | 162/112 |
+| Detection | RKYOLOV5 | YOLOV5-S-Relu(int8) | -/57 |
| Segmentation | Unet | Unet-cityscapes | -/- |
| Segmentation | PP-LiteSeg | PP_LiteSeg_T_STDC1_cityscapes | -/- |
| Segmentation | PP-HumanSegV2Lite | portrait | 53/50 |
diff --git a/examples/vision/detection/rkyolo/cpp/infer_rkyolo.cc b/examples/vision/detection/rkyolo/cpp/infer_rkyolo.cc
index 86ba7f985..3433c1f41 100644
--- a/examples/vision/detection/rkyolo/cpp/infer_rkyolo.cc
+++ b/examples/vision/detection/rkyolo/cpp/infer_rkyolo.cc
@@ -25,12 +25,16 @@ void RKNPU2Infer(const std::string& model_file, const std::string& image_file) {
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;
}
- std::cout << res.Str() << std::endl;
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;
}
diff --git a/fastdeploy/backends/rknpu/rknpu2/rknpu2_backend.cc b/fastdeploy/backends/rknpu/rknpu2/rknpu2_backend.cc
index 8046fd87a..ac9429450 100644
--- a/fastdeploy/backends/rknpu/rknpu2/rknpu2_backend.cc
+++ b/fastdeploy/backends/rknpu/rknpu2/rknpu2_backend.cc
@@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
#include "fastdeploy/backends/rknpu/rknpu2/rknpu2_backend.h"
-
+#include "fastdeploy/utils/perf.h"
namespace fastdeploy {
RKNPU2Backend::~RKNPU2Backend() {
// Release memory uniformly here
@@ -190,7 +190,6 @@ bool RKNPU2Backend::GetModelInputOutputInfos() {
FDERROR << "rknpu2_backend only support input format is NHWC or UNDEFINED" << std::endl;
}
- DumpTensorAttr(input_attrs_[i]);
// copy input_attrs_ to input tensor info
std::string temp_name = input_attrs_[i].name;
@@ -199,16 +198,13 @@ bool RKNPU2Backend::GetModelInputOutputInfos() {
for (int j = 0; j < input_attrs_[i].n_dims; j++) {
temp_shape[j] = (int)input_attrs_[i].dims[j];
}
- FDDataType temp_dtype =
- fastdeploy::RKNPU2Backend::RknnTensorTypeToFDDataType(
- input_attrs_[i].type);
+ FDDataType temp_dtype = fastdeploy::RKNPU2Backend::RknnTensorTypeToFDDataType(input_attrs_[i].type);
TensorInfo temp_input_info = {temp_name, temp_shape, temp_dtype};
inputs_desc_[i] = temp_input_info;
}
// Get detailed output parameters
- output_attrs_ =
- (rknn_tensor_attr*)malloc(sizeof(rknn_tensor_attr) * io_num.n_output);
+ output_attrs_ = (rknn_tensor_attr*)malloc(sizeof(rknn_tensor_attr) * io_num.n_output);
memset(output_attrs_, 0, io_num.n_output * sizeof(rknn_tensor_attr));
outputs_desc_.resize(io_num.n_output);
@@ -225,19 +221,13 @@ bool RKNPU2Backend::GetModelInputOutputInfos() {
return false;
}
- // If the output dimension is 3, the runtime will automatically change it to 4.
+ // If the output dimension is 3, the runtime will automatically change it to 4.
// Obviously, this is wrong, and manual correction is required here.
int n_dims = output_attrs_[i].n_dims;
if((n_dims == 4) && (output_attrs_[i].dims[3] == 1)){
n_dims--;
- FDWARNING << "The output["
- << i
- << "].shape[3] is 1, remove this dim."
- << std::endl;
}
- DumpTensorAttr(output_attrs_[i]);
-
// copy output_attrs_ to output tensor
std::string temp_name = output_attrs_[i].name;
std::vector temp_shape{};
@@ -246,9 +236,8 @@ bool RKNPU2Backend::GetModelInputOutputInfos() {
temp_shape[j] = (int)output_attrs_[i].dims[j];
}
- FDDataType temp_dtype =
- fastdeploy::RKNPU2Backend::RknnTensorTypeToFDDataType(
- output_attrs_[i].type);
+ // The data type of output data is changed to FP32
+ FDDataType temp_dtype = FDDataType::FP32;
TensorInfo temp_input_info = {temp_name, temp_shape, temp_dtype};
outputs_desc_[i] = temp_input_info;
}
@@ -265,11 +254,12 @@ bool RKNPU2Backend::GetModelInputOutputInfos() {
void RKNPU2Backend::DumpTensorAttr(rknn_tensor_attr& attr) {
printf("index=%d, name=%s, n_dims=%d, dims=[%d, %d, %d, %d], "
"n_elems=%d, size=%d, fmt=%s, type=%s, "
- "qnt_type=%s, zp=%d, scale=%f\n",
+ "qnt_type=%s, zp=%d, scale=%f, pass_through=%d",
attr.index, attr.name, attr.n_dims, attr.dims[0], attr.dims[1],
attr.dims[2], attr.dims[3], attr.n_elems, attr.size,
get_format_string(attr.fmt), get_type_string(attr.type),
- get_qnt_type_string(attr.qnt_type), attr.zp, attr.scale);
+ get_qnt_type_string(attr.qnt_type), attr.zp, attr.scale,
+ attr.pass_through);
}
TensorInfo RKNPU2Backend::GetInputInfo(int index) {
@@ -320,7 +310,12 @@ bool RKNPU2Backend::Infer(std::vector& inputs,
input_attrs_[i].type = input_type;
input_attrs_[i].size = inputs[0].Nbytes();
input_attrs_[i].size_with_stride = inputs[0].Nbytes();
- input_attrs_[i].pass_through = 0;
+ if(input_attrs_[i].type == RKNN_TENSOR_FLOAT16 ||
+ input_attrs_[i].type == RKNN_TENSOR_FLOAT32){
+ FDINFO << "The input model is not a quantitative model. "
+ "Close the normalize operation." << std::endl;
+ }
+
input_mems_[i] = rknn_create_mem(ctx, inputs[i].Nbytes());
if (input_mems_[i] == nullptr) {
FDERROR << "rknn_create_mem input_mems_ error." << std::endl;
@@ -345,11 +340,13 @@ bool RKNPU2Backend::Infer(std::vector& inputs,
FDERROR << "rknn_create_mem output_mems_ error." << std::endl;
return false;
}
- if(output_attrs_[i].type == RKNN_TENSOR_FLOAT16){
- output_attrs_[i].type = RKNN_TENSOR_FLOAT32;
- }
+
+ // The data type of output data is changed to FP32
+ output_attrs_[i].type = RKNN_TENSOR_FLOAT32;
+
// default output type is depend on model, this requires float32 to compute top5
ret = rknn_set_io_mem(ctx, output_mems_[i], &output_attrs_[i]);
+
// set output memory and attribute
if (ret != RKNN_SUCC) {
FDERROR << "output tensor memory rknn_set_io_mem fail! ret=" << ret
@@ -360,7 +357,7 @@ bool RKNPU2Backend::Infer(std::vector& inputs,
this->infer_init = true;
}
-
+
// Copy input data to input tensor memory
for (uint32_t i = 0; i < io_num.n_input; i++) {
uint32_t width = input_attrs_[i].dims[2];
@@ -376,7 +373,6 @@ bool RKNPU2Backend::Infer(std::vector& inputs,
return false;
}
}
-
// run rknn
ret = rknn_run(ctx, nullptr);
@@ -395,8 +391,6 @@ bool RKNPU2Backend::Infer(std::vector& inputs,
}
(*outputs)[i].Resize(temp_shape, outputs_desc_[i].dtype,
outputs_desc_[i].name);
- std::vector output_scale = {output_attrs_[i].scale};
- (*outputs)[i].SetQuantizationInfo(output_attrs_[i].zp, output_scale);
memcpy((*outputs)[i].MutableData(), (float*)output_mems_[i]->virt_addr,
(*outputs)[i].Nbytes());
}
diff --git a/fastdeploy/core/fd_tensor.cc b/fastdeploy/core/fd_tensor.cc
index 484e03913..e84535ac9 100644
--- a/fastdeploy/core/fd_tensor.cc
+++ b/fastdeploy/core/fd_tensor.cc
@@ -138,11 +138,6 @@ void FDTensor::Resize(const std::vector& new_shape) {
external_data_ptr = nullptr;
}
-void FDTensor::SetQuantizationInfo(int32_t zero_point,std::vector& scale){
- quantized_parameter_.first = zero_point;
- quantized_parameter_.second = scale;
-}
-
void FDTensor::Resize(const std::vector& new_shape,
const FDDataType& data_type,
const std::string& tensor_name,
@@ -455,9 +450,4 @@ FDTensor& FDTensor::operator=(FDTensor&& other) {
return *this;
}
-const std::pair>
-FDTensor::GetQuantizationInfo() const{
- return quantized_parameter_;
-}
-
} // namespace fastdeploy
diff --git a/fastdeploy/core/fd_tensor.h b/fastdeploy/core/fd_tensor.h
index e3e373c43..c6e1ed5cb 100644
--- a/fastdeploy/core/fd_tensor.h
+++ b/fastdeploy/core/fd_tensor.h
@@ -25,10 +25,6 @@
namespace fastdeploy {
struct FASTDEPLOY_DECL FDTensor {
- // These two parameters are general parameters of quantitative model.
- std::pair> quantized_parameter_ = {0, {0}};
- void SetQuantizationInfo(int32_t zero_point, std::vector& scale);
- const std::pair> GetQuantizationInfo() const;
// std::vector data;
void* buffer_ = nullptr;
diff --git a/fastdeploy/vision/detection/contrib/rknpu2/postprocessor.cc b/fastdeploy/vision/detection/contrib/rknpu2/postprocessor.cc
index bf8be2727..581cac2e8 100755
--- a/fastdeploy/vision/detection/contrib/rknpu2/postprocessor.cc
+++ b/fastdeploy/vision/detection/contrib/rknpu2/postprocessor.cc
@@ -11,7 +11,6 @@
// 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/detection/contrib/rknpu2/postprocessor.h"
#include "fastdeploy/vision/utils/utils.h"
@@ -38,17 +37,16 @@ bool RKYOLOPostprocessor::Run(const std::vector& tensors,
int grid_h = height_ / stride;
int grid_w = width_ / stride;
int* anchor = &(anchors_.data()[i * 2 * anchor_per_branch_]);
- if (tensors[i].dtype == FDDataType::INT8 ||
- tensors[i].dtype == FDDataType::UINT8) {
- auto quantization_info = tensors[i].GetQuantizationInfo();
- validCount =
- validCount + ProcessInt8((int8_t*)tensors[i].Data() + skip_address,
- anchor, grid_h, grid_w, stride,
- filterBoxes, boxesScore, classId,
- conf_threshold_, quantization_info.first,
- quantization_info.second[0]);
+ if (tensors[i].dtype == FDDataType::FP32) {
+ validCount = validCount +
+ ProcessFP16((float*)tensors[i].Data() + skip_address,
+ anchor, grid_h, grid_w, stride, filterBoxes,
+ boxesScore, classId, conf_threshold_);
} else {
- FDERROR << "RKYOLO Only Support INT8 Model" << std::endl;
+ FDERROR << "RKYOLO Only Support FP32 Model."
+ << "But the result's type is "
+ << Str(tensors[i].dtype)
+ << std::endl;
}
}
@@ -69,7 +67,7 @@ bool RKYOLOPostprocessor::Run(const std::vector& tensors,
NMS(validCount, filterBoxes, classId, indexArray, nms_threshold_, false);
} else if (anchor_per_branch_ == 1) {
NMS(validCount, filterBoxes, classId, indexArray, nms_threshold_, true);
- }else{
+ } else {
FDERROR << "anchor_per_branch_ only support 3 or 1." << std::endl;
return false;
}
@@ -107,60 +105,57 @@ bool RKYOLOPostprocessor::Run(const std::vector& tensors,
return true;
}
-int RKYOLOPostprocessor::ProcessInt8(int8_t* input, int* anchor, int grid_h,
+int RKYOLOPostprocessor::ProcessFP16(float* input, int* anchor, int grid_h,
int grid_w, int stride,
std::vector& boxes,
std::vector& boxScores,
- std::vector& classId, float threshold,
- int32_t zp, float scale) {
+ std::vector& classId,
+ float threshold) {
+
int validCount = 0;
int grid_len = grid_h * grid_w;
- float thres = threshold;
- auto thres_i8 = QntF32ToAffine(thres, zp, scale);
+ // float thres_sigmoid = threshold;
for (int a = 0; a < anchor_per_branch_; a++) {
for (int i = 0; i < grid_h; i++) {
for (int j = 0; j < grid_w; j++) {
- int8_t box_confidence =
- input[(prob_box_size * a + 4) * grid_len + i * grid_w + j];
- if (box_confidence >= thres_i8) {
- int offset = (prob_box_size * a) * grid_len + i * grid_w + j;
- int8_t* in_ptr = input + offset;
+ float box_confidence =
+ input[(prob_box_size_ * a + 4) * grid_len + i * grid_w + j];
+ if (box_confidence >= threshold) {
+ int offset = (prob_box_size_ * a) * grid_len + i * grid_w + j;
+ float* in_ptr = input + offset;
- int8_t maxClassProbs = in_ptr[5 * grid_len];
+ float maxClassProbs = in_ptr[5 * grid_len];
int maxClassId = 0;
- for (int k = 1; k < obj_class_num; ++k) {
- int8_t prob = in_ptr[(5 + k) * grid_len];
+ for (int k = 1; k < obj_class_num_; ++k) {
+ float prob = in_ptr[(5 + k) * grid_len];
if (prob > maxClassProbs) {
maxClassId = k;
maxClassProbs = prob;
}
}
-
- float box_conf_f32 = DeqntAffineToF32(box_confidence, zp, scale);
- float class_prob_f32 = DeqntAffineToF32(maxClassProbs, zp, scale);
+ float box_conf_f32 = (box_confidence);
+ float class_prob_f32 = (maxClassProbs);
float limit_score = 0;
if (anchor_per_branch_ == 1) {
- limit_score = box_conf_f32 * class_prob_f32;
- } else {
limit_score = class_prob_f32;
+ } else {
+ limit_score = box_conf_f32 * class_prob_f32;
}
- //printf("limit score: %f\n", limit_score);
+ // printf("limit score: %f", limit_score);
if (limit_score > conf_threshold_) {
float box_x, box_y, box_w, box_h;
if (anchor_per_branch_ == 1) {
- box_x = DeqntAffineToF32(*in_ptr, zp, scale);
- box_y = DeqntAffineToF32(in_ptr[grid_len], zp, scale);
- box_w = DeqntAffineToF32(in_ptr[2 * grid_len], zp, scale);
- box_h = DeqntAffineToF32(in_ptr[3 * grid_len], zp, scale);
- box_w = exp(box_w) * stride;
- box_h = exp(box_h) * stride;
+ box_x = *in_ptr;
+ box_y = (in_ptr[grid_len]);
+ box_w = exp(in_ptr[2 * grid_len]) * stride;
+ box_h = exp(in_ptr[3 * grid_len]) * stride;
} else {
- box_x = DeqntAffineToF32(*in_ptr, zp, scale) * 2.0 - 0.5;
- box_y = DeqntAffineToF32(in_ptr[grid_len], zp, scale) * 2.0 - 0.5;
- box_w = DeqntAffineToF32(in_ptr[2 * grid_len], zp, scale) * 2.0;
- box_h = DeqntAffineToF32(in_ptr[3 * grid_len], zp, scale) * 2.0;
- box_w = box_w * box_w;
- box_h = box_h * box_h;
+ box_x = *in_ptr * 2.0 - 0.5;
+ box_y = (in_ptr[grid_len]) * 2.0 - 0.5;
+ box_w = (in_ptr[2 * grid_len]) * 2.0;
+ box_h = (in_ptr[3 * grid_len]) * 2.0;
+ box_w *= box_w;
+ box_h *= box_h;
}
box_x = (box_x + j) * (float)stride;
box_y = (box_y + i) * (float)stride;
diff --git a/fastdeploy/vision/detection/contrib/rknpu2/postprocessor.h b/fastdeploy/vision/detection/contrib/rknpu2/postprocessor.h
index 6dcda3b77..b65479415 100755
--- a/fastdeploy/vision/detection/contrib/rknpu2/postprocessor.h
+++ b/fastdeploy/vision/detection/contrib/rknpu2/postprocessor.h
@@ -85,12 +85,12 @@ class FASTDEPLOY_DECL RKYOLOPostprocessor {
int width_ = 0;
int anchor_per_branch_ = 0;
- // Process Int8 Model
- int ProcessInt8(int8_t* input, int* anchor, int grid_h, int grid_w,
- int stride, std::vector& boxes,
- std::vector& boxScores, std::vector& classId,
- float threshold, int32_t zp, float scale);
-
+ int ProcessFP16(float *input, int *anchor, int grid_h,
+ int grid_w, int stride,
+ std::vector &boxes,
+ std::vector &boxScores,
+ std::vector &classId,
+ float threshold);
// Model
int QuickSortIndiceInverse(std::vector& input, int left, int right,
std::vector& indices);
@@ -100,8 +100,8 @@ class FASTDEPLOY_DECL RKYOLOPostprocessor {
std::vector scale_;
float nms_threshold_ = 0.45;
float conf_threshold_ = 0.25;
- int prob_box_size = 85;
- int obj_class_num = 80;
+ int prob_box_size_ = 85;
+ int obj_class_num_ = 80;
int obj_num_bbox_max_size = 200;
};
diff --git a/fastdeploy/vision/detection/contrib/rknpu2/preprocessor.cc b/fastdeploy/vision/detection/contrib/rknpu2/preprocessor.cc
index 068004346..a5ce8849e 100755
--- a/fastdeploy/vision/detection/contrib/rknpu2/preprocessor.cc
+++ b/fastdeploy/vision/detection/contrib/rknpu2/preprocessor.cc
@@ -30,16 +30,11 @@ RKYOLOPreprocessor::RKYOLOPreprocessor() {
}
void RKYOLOPreprocessor::LetterBox(FDMat* mat) {
- std::cout << "mat->Height() = " << mat->Height() << std::endl;
- std::cout << "mat->Width() = " << mat->Width() << std::endl;
-
float scale =
std::min(size_[1] * 1.0 / mat->Height(), size_[0] * 1.0 / mat->Width());
- std::cout << "RKYOLOPreprocessor scale_ = " << scale << std::endl;
if (!is_scale_up_) {
scale = std::min(scale, 1.0f);
}
- std::cout << "RKYOLOPreprocessor scale_ = " << scale << std::endl;
scale_.push_back(scale);
int resize_h = int(round(mat->Height() * scale));
@@ -74,19 +69,6 @@ void RKYOLOPreprocessor::LetterBox(FDMat* mat) {
}
bool RKYOLOPreprocessor::Preprocess(FDMat* mat, FDTensor* output) {
- // process after image load
- // float ratio = std::min(size_[1] * 1.0f / static_cast(mat->Height()),
- // size_[0] * 1.0f / static_cast(mat->Width()));
- // if (std::fabs(ratio - 1.0f) > 1e-06) {
- // int interp = cv::INTER_AREA;
- // if (ratio > 1.0) {
- // interp = cv::INTER_LINEAR;
- // }
- // int resize_h = int(mat->Height() * ratio);
- // int resize_w = int(mat->Width() * ratio);
- // Resize::Run(mat, resize_w, resize_h, -1, -1, interp);
- // }
-
// RKYOLO's preprocess steps
// 1. letterbox
// 2. convert_and_permute(swap_rb=true)
diff --git a/fastdeploy/vision/detection/contrib/rknpu2/preprocessor.h b/fastdeploy/vision/detection/contrib/rknpu2/preprocessor.h
index e6ecfe452..ad08dd751 100755
--- a/fastdeploy/vision/detection/contrib/rknpu2/preprocessor.h
+++ b/fastdeploy/vision/detection/contrib/rknpu2/preprocessor.h
@@ -18,7 +18,6 @@
namespace fastdeploy {
namespace vision {
-
namespace detection {
/*! @brief Preprocessor object for YOLOv5 serials model.
*/
diff --git a/fastdeploy/vision/detection/contrib/rknpu2/rkyolo.cc b/fastdeploy/vision/detection/contrib/rknpu2/rkyolo.cc
index 524afcef1..49f5804af 100644
--- a/fastdeploy/vision/detection/contrib/rknpu2/rkyolo.cc
+++ b/fastdeploy/vision/detection/contrib/rknpu2/rkyolo.cc
@@ -60,11 +60,6 @@ bool RKYOLO::BatchPredict(const std::vector& images,
FDERROR << "Failed to preprocess the input image." << std::endl;
return false;
}
- auto pad_hw_values_ = preprocessor_.GetPadHWValues();
- postprocessor_.SetPadHWValues(preprocessor_.GetPadHWValues());
- std::cout << "preprocessor_ scale_ = " << preprocessor_.GetScale()[0]
- << std::endl;
- postprocessor_.SetScale(preprocessor_.GetScale());
reused_input_tensors_[0].name = InputInfoOfRuntime(0).name;
if (!Infer(reused_input_tensors_, &reused_output_tensors_)) {
@@ -72,12 +67,14 @@ bool RKYOLO::BatchPredict(const std::vector& images,
return false;
}
+ auto pad_hw_values_ = preprocessor_.GetPadHWValues();
+ postprocessor_.SetPadHWValues(preprocessor_.GetPadHWValues());
+ postprocessor_.SetScale(preprocessor_.GetScale());
if (!postprocessor_.Run(reused_output_tensors_, results)) {
FDERROR << "Failed to postprocess the inference results by runtime."
<< std::endl;
return false;
}
-
return true;
}
From 81eaeddbd0f37ce479bfd9069c9fa96b77b7a0e6 Mon Sep 17 00:00:00 2001
From: Wang Xinyu
Date: Mon, 19 Dec 2022 10:14:17 +0800
Subject: [PATCH 75/77] [Streamer] Basic framework, YAML parser, ppyoloe demo
and video decoder demo (#863)
* support trt installed in sys dir
* streamer init
* link elements and run
* create source bin
* add config
* restruct dirs
* set property
* link elements
* integrate perf
* add bbox parser
* parse yaml to string, video decoder
* use try pull for decoder and nits
* streamer ppyoloe cpp
* update readme
* video decoder cpp dir
* add cn readme
* update readme
* cmake nits
* refactor perf measurement
---
CMakeLists.txt | 20 ++-
FastDeploy.cmake.in | 19 ++-
streamer/CMakeLists.txt | 52 +++++++
streamer/README.md | 1 +
streamer/README_CN.md | 45 ++++++
streamer/README_EN.md | 44 ++++++
streamer/examples/ppyoloe/cpp/CMakeLists.txt | 30 ++++
streamer/examples/ppyoloe/cpp/README.md | 1 +
streamer/examples/ppyoloe/cpp/README_CN.md | 44 ++++++
streamer/examples/ppyoloe/cpp/README_EN.md | 44 ++++++
streamer/examples/ppyoloe/cpp/main.cc | 22 +++
.../examples/ppyoloe/cpp/nvinfer_config.txt | 23 +++
.../examples/ppyoloe/cpp/streamer_cfg.yml | 46 ++++++
.../examples/video_decoder/cpp/CMakeLists.txt | 30 ++++
streamer/examples/video_decoder/cpp/README.md | 1 +
.../examples/video_decoder/cpp/README_CN.md | 20 +++
.../examples/video_decoder/cpp/README_EN.md | 20 +++
streamer/examples/video_decoder/cpp/main.cc | 43 ++++++
.../video_decoder/cpp/streamer_cfg.yml | 19 +++
streamer/src/app/base_app.cc | 135 +++++++++++++++++
streamer/src/app/base_app.h | 86 +++++++++++
streamer/src/app/video_analytics.cc | 21 +++
streamer/src/app/video_analytics.h | 33 ++++
streamer/src/app/video_decoder.cc | 69 +++++++++
streamer/src/app/video_decoder.h | 41 +++++
streamer/src/app/yaml_parser.cc | 125 ++++++++++++++++
streamer/src/app/yaml_parser.h | 58 +++++++
streamer/src/deepstream/bbox_parser.cc | 76 ++++++++++
streamer/src/fd_streamer.cc | 56 +++++++
streamer/src/fd_streamer.h | 52 +++++++
streamer/src/gstreamer/perf.cc | 114 ++++++++++++++
streamer/src/gstreamer/perf.h | 29 ++++
streamer/src/gstreamer/types.h | 60 ++++++++
streamer/src/gstreamer/utils.cc | 141 ++++++++++++++++++
streamer/src/gstreamer/utils.h | 28 ++++
35 files changed, 1635 insertions(+), 13 deletions(-)
create mode 100644 streamer/CMakeLists.txt
create mode 120000 streamer/README.md
create mode 100644 streamer/README_CN.md
create mode 100644 streamer/README_EN.md
create mode 100644 streamer/examples/ppyoloe/cpp/CMakeLists.txt
create mode 120000 streamer/examples/ppyoloe/cpp/README.md
create mode 100644 streamer/examples/ppyoloe/cpp/README_CN.md
create mode 100644 streamer/examples/ppyoloe/cpp/README_EN.md
create mode 100644 streamer/examples/ppyoloe/cpp/main.cc
create mode 100644 streamer/examples/ppyoloe/cpp/nvinfer_config.txt
create mode 100644 streamer/examples/ppyoloe/cpp/streamer_cfg.yml
create mode 100644 streamer/examples/video_decoder/cpp/CMakeLists.txt
create mode 120000 streamer/examples/video_decoder/cpp/README.md
create mode 100644 streamer/examples/video_decoder/cpp/README_CN.md
create mode 100644 streamer/examples/video_decoder/cpp/README_EN.md
create mode 100644 streamer/examples/video_decoder/cpp/main.cc
create mode 100644 streamer/examples/video_decoder/cpp/streamer_cfg.yml
create mode 100644 streamer/src/app/base_app.cc
create mode 100644 streamer/src/app/base_app.h
create mode 100644 streamer/src/app/video_analytics.cc
create mode 100644 streamer/src/app/video_analytics.h
create mode 100644 streamer/src/app/video_decoder.cc
create mode 100644 streamer/src/app/video_decoder.h
create mode 100644 streamer/src/app/yaml_parser.cc
create mode 100644 streamer/src/app/yaml_parser.h
create mode 100644 streamer/src/deepstream/bbox_parser.cc
create mode 100644 streamer/src/fd_streamer.cc
create mode 100644 streamer/src/fd_streamer.h
create mode 100644 streamer/src/gstreamer/perf.cc
create mode 100644 streamer/src/gstreamer/perf.h
create mode 100644 streamer/src/gstreamer/types.h
create mode 100644 streamer/src/gstreamer/utils.cc
create mode 100644 streamer/src/gstreamer/utils.h
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 0bcfa4084..04954acb1 100755
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -362,14 +362,20 @@ if(ENABLE_TRT_BACKEND)
endif()
if(NOT BUILD_ON_JETSON)
if(NOT TRT_DIRECTORY)
- message(FATAL_ERROR "While -DENABLE_TRT_BACKEND=ON, must define -DTRT_DIRECTORY, e.g -DTRT_DIRECTORY=/Downloads/TensorRT-8.4")
+ set(TRT_INC_DIR /usr/include/x86_64-linux-gnu/)
+ set(TRT_LIB_DIR /usr/lib/x86_64-linux-gnu/)
endif()
endif()
- set(TRT_INC_DIR /usr/include/aarch64-linux-gnu/)
- set(TRT_LIB_DIR /usr/lib/aarch64-linux-gnu/)
- if(NOT BUILD_ON_JETSON)
- set(TRT_INC_DIR ${TRT_DIRECTORY}/include)
- set(TRT_LIB_DIR ${TRT_DIRECTORY}/lib)
+ if(BUILD_ON_JETSON)
+ set(TRT_INC_DIR /usr/include/aarch64-linux-gnu/)
+ set(TRT_LIB_DIR /usr/lib/aarch64-linux-gnu/)
+ else()
+ set(TRT_INC_DIR /usr/include/x86_64-linux-gnu/)
+ set(TRT_LIB_DIR /usr/lib/x86_64-linux-gnu/)
+ if(TRT_DIRECTORY)
+ set(TRT_INC_DIR ${TRT_DIRECTORY}/include)
+ set(TRT_LIB_DIR ${TRT_DIRECTORY}/lib)
+ endif()
endif()
add_definitions(-DENABLE_TRT_BACKEND)
@@ -382,7 +388,7 @@ if(ENABLE_TRT_BACKEND)
list(APPEND DEPEND_LIBS ${TRT_INFER_LIB} ${TRT_ONNX_LIB} ${TRT_PLUGIN_LIB})
list(APPEND ALL_DEPLOY_SRCS ${DEPLOY_OP_CUDA_KERNEL_SRCS})
- if(NOT BUILD_ON_JETSON)
+ if(NOT BUILD_ON_JETSON AND TRT_DIRECTORY)
if(NOT EXISTS "${CMAKE_CURRENT_BINARY_DIR}/third_libs/install/tensorrt")
file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/third_libs/install/tensorrt")
endif()
diff --git a/FastDeploy.cmake.in b/FastDeploy.cmake.in
index d8c0df3d6..17f83eb69 100755
--- a/FastDeploy.cmake.in
+++ b/FastDeploy.cmake.in
@@ -141,13 +141,19 @@ if(WITH_GPU)
if (ENABLE_TRT_BACKEND)
if(BUILD_ON_JETSON)
- find_library(TRT_INFER_LIB nvinfer /usr/include/aarch64-linux-gnu/)
- find_library(TRT_ONNX_LIB nvonnxparser /usr/include/aarch64-linux-gnu/)
- find_library(TRT_PLUGIN_LIB nvinfer_plugin /usr/include/aarch64-linux-gnu/)
+ find_library(TRT_INFER_LIB nvinfer /usr/lib/aarch64-linux-gnu/)
+ find_library(TRT_ONNX_LIB nvonnxparser /usr/lib/aarch64-linux-gnu/)
+ find_library(TRT_PLUGIN_LIB nvinfer_plugin /usr/lib/aarch64-linux-gnu/)
else()
- find_library(TRT_INFER_LIB nvinfer ${CMAKE_CURRENT_LIST_DIR}/third_libs/install/tensorrt/lib NO_DEFAULT_PATH)
- find_library(TRT_ONNX_LIB nvonnxparser ${CMAKE_CURRENT_LIST_DIR}/third_libs/install/tensorrt/lib NO_DEFAULT_PATH)
- find_library(TRT_PLUGIN_LIB nvinfer_plugin ${CMAKE_CURRENT_LIST_DIR}/third_libs/install/tensorrt/lib NO_DEFAULT_PATH)
+ if(TRT_DIRECTORY)
+ find_library(TRT_INFER_LIB nvinfer ${CMAKE_CURRENT_LIST_DIR}/third_libs/install/tensorrt/lib NO_DEFAULT_PATH)
+ find_library(TRT_ONNX_LIB nvonnxparser ${CMAKE_CURRENT_LIST_DIR}/third_libs/install/tensorrt/lib NO_DEFAULT_PATH)
+ find_library(TRT_PLUGIN_LIB nvinfer_plugin ${CMAKE_CURRENT_LIST_DIR}/third_libs/install/tensorrt/lib NO_DEFAULT_PATH)
+ else()
+ find_library(TRT_INFER_LIB nvinfer /usr/lib/x86_64-linux-gnu/)
+ find_library(TRT_ONNX_LIB nvonnxparser /usr/lib/x86_64-linux-gnu/)
+ find_library(TRT_PLUGIN_LIB nvinfer_plugin /usr/lib/x86_64-linux-gnu/)
+ endif()
endif()
list(APPEND FASTDEPLOY_LIBS ${TRT_INFER_LIB} ${TRT_ONNX_LIB} ${TRT_PLUGIN_LIB})
endif()
@@ -275,6 +281,7 @@ message(STATUS " ENABLE_VISION : ${ENABLE_VISION}")
message(STATUS " ENABLE_TEXT : ${ENABLE_TEXT}")
if(WITH_GPU)
message(STATUS " CUDA_DIRECTORY : ${CUDA_DIRECTORY}")
+ message(STATUS " TRT_DIRECTORY : ${TRT_DIRECTORY}")
endif()
if(OPENCV_DIRECTORY)
message(STATUS " OPENCV_DIRECTORY : ${OPENCV_DIRECTORY}")
diff --git a/streamer/CMakeLists.txt b/streamer/CMakeLists.txt
new file mode 100644
index 000000000..c5c7c2bd8
--- /dev/null
+++ b/streamer/CMakeLists.txt
@@ -0,0 +1,52 @@
+# 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.
+
+PROJECT(fd_streamer C CXX)
+CMAKE_MINIMUM_REQUIRED (VERSION 3.10)
+
+option(FASTDEPLOY_INSTALL_DIR "Path of downloaded fastdeploy sdk.")
+option(ENABLE_DEEPSTREAM "Enable NVIDIA DeepStream SDK" ON)
+
+file(GLOB_RECURSE ALL_STREAMER_SRCS ${PROJECT_SOURCE_DIR}/src/*.cc)
+file(GLOB_RECURSE DEEPSTREAM_SRCS ${PROJECT_SOURCE_DIR}/src/deepstream/*.cc)
+list(REMOVE_ITEM ALL_STREAMER_SRCS ${DEEPSTREAM_SRCS})
+
+set(DEPEND_LIBS "")
+
+find_package(PkgConfig REQUIRED)
+pkg_check_modules(GSTAPP gstreamer-app-1.0 REQUIRED)
+include_directories(${GSTAPP_INCLUDE_DIRS})
+list(APPEND DEPEND_LIBS ${GSTAPP_LIBRARIES})
+
+include(${FASTDEPLOY_INSTALL_DIR}/FastDeploy.cmake)
+include_directories(${FASTDEPLOY_INCS})
+include_directories(${PROJECT_SOURCE_DIR}/src/)
+
+if(ENABLE_DEEPSTREAM)
+ add_definitions(-DENABLE_DEEPSTREAM)
+ include_directories(${CUDA_DIRECTORY}/include)
+ include_directories(/opt/nvidia/deepstream/deepstream/sources/includes/)
+ link_directories(/opt/nvidia/deepstream/deepstream/lib/)
+ list(APPEND ALL_STREAMER_SRCS ${DEEPSTREAM_SRCS})
+ list(APPEND DEPEND_LIBS nvdsgst_meta nvds_meta)
+else()
+ message(FATAL_ERROR "Currently, DeepStream is required, we will make it optional later.")
+endif()
+
+# Link the yaml-cpp in system path, because deepstream also depends on yaml-cpp,
+# If we link multiple yaml-cpp libs, strange error will occur.
+list(APPEND DEPEND_LIBS yaml-cpp)
+
+add_library(fd_streamer SHARED ${ALL_STREAMER_SRCS})
+target_link_libraries(fd_streamer ${FASTDEPLOY_LIBS} ${DEPEND_LIBS})
diff --git a/streamer/README.md b/streamer/README.md
new file mode 120000
index 000000000..f18766817
--- /dev/null
+++ b/streamer/README.md
@@ -0,0 +1 @@
+README_EN.md
\ No newline at end of file
diff --git a/streamer/README_CN.md b/streamer/README_CN.md
new file mode 100644
index 000000000..fcf40bf6e
--- /dev/null
+++ b/streamer/README_CN.md
@@ -0,0 +1,45 @@
+简体中文 | [English](README_EN.md)
+
+# FastDeploy Streamer
+
+## 简介
+
+FastDeploy Streamer(FDStreamer)是一个AI多媒体流处理框架,以Pipeline的形式编排AI推理、音视频解码、编码、推流等功能,
+赋能AI应用的端到端优化和部署。
+
+目前FDStreamer只适配了NVIDIA GPU/Jetson平台,更多硬件和平台的支持敬请期待。
+
+## 准备环境
+
+### Jetson
+- DeepStream 6.1+
+
+### x86 GPU
+
+手动安装DeepStream 6.1.1及其依赖项,或使用以下docker:
+```
+docker pull nvcr.io/nvidia/deepstream:6.1.1-devel
+```
+
+## 编译和运行
+
+1. [编译FastDeploy](../../docs/cn/build_and_install), 或直接下载[FastDeploy预编译库](../../docs/cn/build_and_install/download_prebuilt_libraries.md)
+
+2. 编译Streamer
+```
+cd FastDeploy/streamer/
+mkdir build && cd build/
+
+# 下载FastDeploy预编译库,用户可在上文提到的`FastDeploy预编译库`中自行选择合适的版本使用
+wget https://bj.bcebos.com/fastdeploy/release/cpp/fastdeploy-linux-x64-x.x.x.tgz
+tar xvf fastdeploy-linux-x64-x.x.x.tgz
+cmake .. -DFASTDEPLOY_INSTALL_DIR=${PWD}/fastdeploy-linux-x64-x.x.x
+make -j
+```
+
+3. 编译和运行Example
+
+| Example | 简介 |
+|:--|:--|
+| [PP-YOLOE](./examples/ppyoloe) | 多路视频接入,PP-YOLOE目标检测,NVTracker跟踪,硬编解码,写入mp4文件 |
+| [Video Decoder](./examples/video_decoder) | 视频硬解码 |
diff --git a/streamer/README_EN.md b/streamer/README_EN.md
new file mode 100644
index 000000000..16aea26c9
--- /dev/null
+++ b/streamer/README_EN.md
@@ -0,0 +1,44 @@
+English | [简体中文](README_CN.md)
+
+# FastDeploy Streamer
+
+## Introduction
+
+FastDeploy Streamer (FDStreamer) is an AI multimedia stream processing framework that arranges functions such as AI inference, audio and video decoding, encoding, and streaming in the form of pipeline, to enable end-to-end optimization and deployment of AI applications.
+
+Currently FDStreamer is only compatible with NVIDIA GPU/Jetson platform, please look forward to more hardware and platform support.
+
+## Environment
+
+### Jetson
+- DeepStream 6.1+
+
+### x86 GPU
+
+Install DeepStream 6.1.1 and dependencies manually,or use below docker:
+```
+docker pull nvcr.io/nvidia/deepstream:6.1.1-devel
+```
+
+## Build
+
+1. [Build FastDeploy](../../docs/en/build_and_install), or download [FastDeploy prebuilt libraries](../../docs/en/build_and_install/download_prebuilt_libraries.md)
+
+2. Build Streamer
+```
+cd FastDeploy/streamer/
+mkdir build && cd build/
+
+# Download FastDeploy prebuilt libraries, please check `FastDeploy prebuilt libraries` above.
+wget https://bj.bcebos.com/fastdeploy/release/cpp/fastdeploy-linux-x64-x.x.x.tgz
+tar xvf fastdeploy-linux-x64-x.x.x.tgz
+cmake .. -DFASTDEPLOY_INSTALL_DIR=${PWD}/fastdeploy-linux-x64-x.x.x
+make -j
+```
+
+3. Build and Run Example
+
+| Example | Brief |
+|:--|:--|
+| [PP-YOLOE](./examples/ppyoloe) | Multiple input videos, PP-YOLOE object detection, NvTracker, Hardware codec, writing to mp4 file |
+| [Video Decoder](./examples/video_decoder) | Video decoding using hardward |
diff --git a/streamer/examples/ppyoloe/cpp/CMakeLists.txt b/streamer/examples/ppyoloe/cpp/CMakeLists.txt
new file mode 100644
index 000000000..7cd3b2be3
--- /dev/null
+++ b/streamer/examples/ppyoloe/cpp/CMakeLists.txt
@@ -0,0 +1,30 @@
+# 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.
+PROJECT(streamer_ppyoloe C CXX)
+CMAKE_MINIMUM_REQUIRED (VERSION 3.10)
+
+option(FASTDEPLOY_INSTALL_DIR "Path of downloaded fastdeploy sdk.")
+include(${FASTDEPLOY_INSTALL_DIR}/FastDeploy.cmake)
+include_directories(${FASTDEPLOY_INCS})
+
+set(FDSTREAMER_INCLUDE_DIR ${PROJECT_SOURCE_DIR}/../../../src/)
+include_directories(${FDSTREAMER_INCLUDE_DIR})
+link_directories(${PROJECT_SOURCE_DIR}/../../../build/)
+
+find_package(PkgConfig REQUIRED)
+pkg_check_modules(GSTAPP gstreamer-app-1.0 REQUIRED)
+include_directories(${GSTAPP_INCLUDE_DIRS})
+
+add_executable(streamer_demo main.cc)
+target_link_libraries(streamer_demo fd_streamer)
diff --git a/streamer/examples/ppyoloe/cpp/README.md b/streamer/examples/ppyoloe/cpp/README.md
new file mode 120000
index 000000000..f18766817
--- /dev/null
+++ b/streamer/examples/ppyoloe/cpp/README.md
@@ -0,0 +1 @@
+README_EN.md
\ No newline at end of file
diff --git a/streamer/examples/ppyoloe/cpp/README_CN.md b/streamer/examples/ppyoloe/cpp/README_CN.md
new file mode 100644
index 000000000..7305edfee
--- /dev/null
+++ b/streamer/examples/ppyoloe/cpp/README_CN.md
@@ -0,0 +1,44 @@
+简体中文 | [English](README_EN.md)
+
+# FastDeploy Streamer PP-YOLOE C++ Example
+
+## 编译和运行
+
+1. 需要先FastDeploy Streamer, 请参考[README](../../../README.md)
+
+2. 编译Example
+```
+mkdir build && cd build
+cmake .. -DFASTDEPLOY_INSTALL_DIR=[PATH-OF-FASTDEPLOY-INSTALL-DIR]
+make -j
+```
+
+3. 下载模型
+```
+wget https://bj.bcebos.com/paddlehub/fastdeploy/ppyoloe_crn_l_300e_coco_onnx_without_scale_factor.tgz
+tar xvf ppyoloe_crn_l_300e_coco_onnx_without_scale_factor.tgz
+mv ppyoloe_crn_l_300e_coco_onnx_without_scale_factor/ model/
+```
+
+4. 运行
+```
+cp ../nvinfer_config.txt .
+cp ../streamer_cfg.yml .
+./streamer_demo
+```
+
+## 导出ONNX模型,不包含NMS和scale factor
+```
+# 导出Paddle推理模型,exclude_nms=True and trt=True
+git clone https://github.com/PaddlePaddle/PaddleDetection.git
+cd PaddleDetection
+python tools/export_model.py -c configs/ppyoloe/ppyoloe_crn_l_300e_coco.yml -o weights=https://paddledet.bj.bcebos.com/models/ppyoloe_crn_l_300e_coco.pdparams exclude_nms=True trt=True --output_dir inference_model
+
+# 转换为ONNX
+paddle2onnx --model_dir inference_model/ppyoloe_crn_l_300e_coco/ --model_filename model.pdmodel --params_filename model.pdiparams --save_file ppyoloe.onnx --deploy_backend tensorrt --enable_dev_version True
+
+# 裁剪ONNX,删除scale factor
+git clone https://github.com/PaddlePaddle/Paddle2ONNX.git
+cd Paddle2ONNX
+python tools/onnx/prune_onnx_model.py --model ../PaddleDetection/ppyoloe.onnx --output_names concat_14.tmp_0 p2o.Mul.245 --save_file ppyoloe_without_scale_factor.onnx
+```
diff --git a/streamer/examples/ppyoloe/cpp/README_EN.md b/streamer/examples/ppyoloe/cpp/README_EN.md
new file mode 100644
index 000000000..192bab502
--- /dev/null
+++ b/streamer/examples/ppyoloe/cpp/README_EN.md
@@ -0,0 +1,44 @@
+English | [简体中文](README_CN.md)
+
+# FastDeploy Streamer PP-YOLOE C++ Example
+
+## Build and Run
+
+1. Build FastDeploy Streamer first, [README](../../../README.md)
+
+2. Build Example
+```
+mkdir build && cd build
+cmake .. -DFASTDEPLOY_INSTALL_DIR=[PATH-OF-FASTDEPLOY-INSTALL-DIR]
+make -j
+```
+
+3. Download model
+```
+wget https://bj.bcebos.com/paddlehub/fastdeploy/ppyoloe_crn_l_300e_coco_onnx_without_scale_factor.tgz
+tar xvf ppyoloe_crn_l_300e_coco_onnx_without_scale_factor.tgz
+mv ppyoloe_crn_l_300e_coco_onnx_without_scale_factor/ model/
+```
+
+4. Run
+```
+cp ../nvinfer_config.txt .
+cp ../streamer_cfg.yml .
+./streamer_demo
+```
+
+## Export ONNX excluding scale_factor and NMS
+```
+# Export inference model with exclude_nms=True and trt=True
+git clone https://github.com/PaddlePaddle/PaddleDetection.git
+cd PaddleDetection
+python tools/export_model.py -c configs/ppyoloe/ppyoloe_crn_l_300e_coco.yml -o weights=https://paddledet.bj.bcebos.com/models/ppyoloe_crn_l_300e_coco.pdparams exclude_nms=True trt=True --output_dir inference_model
+
+# Convert to ONNX
+paddle2onnx --model_dir inference_model/ppyoloe_crn_l_300e_coco/ --model_filename model.pdmodel --params_filename model.pdiparams --save_file ppyoloe.onnx --deploy_backend tensorrt --enable_dev_version True
+
+# Prune ONNX to delete scale factor
+git clone https://github.com/PaddlePaddle/Paddle2ONNX.git
+cd Paddle2ONNX
+python tools/onnx/prune_onnx_model.py --model ../PaddleDetection/ppyoloe.onnx --output_names concat_14.tmp_0 p2o.Mul.245 --save_file ppyoloe_without_scale_factor.onnx
+```
diff --git a/streamer/examples/ppyoloe/cpp/main.cc b/streamer/examples/ppyoloe/cpp/main.cc
new file mode 100644
index 000000000..5e9a8c9ff
--- /dev/null
+++ b/streamer/examples/ppyoloe/cpp/main.cc
@@ -0,0 +1,22 @@
+// 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 "fd_streamer.h"
+
+int main(int argc, char* argv[]) {
+ auto streamer = fastdeploy::streamer::FDStreamer();
+ streamer.Init("streamer_cfg.yml");
+ streamer.Run();
+ return 0;
+}
diff --git a/streamer/examples/ppyoloe/cpp/nvinfer_config.txt b/streamer/examples/ppyoloe/cpp/nvinfer_config.txt
new file mode 100644
index 000000000..c0a481f5c
--- /dev/null
+++ b/streamer/examples/ppyoloe/cpp/nvinfer_config.txt
@@ -0,0 +1,23 @@
+[property]
+batch-size=4
+net-scale-factor=0.0039215697906911373
+# 0=RGB, 1=BGR
+model-color-format=0
+onnx-file=model/ppyoloe.onnx
+model-engine-file=model/ppyoloe.onnx_b4_gpu0_fp32.engine
+labelfile-path=model/labels.txt
+## 0=FP32, 1=INT8, 2=FP16 mode
+network-mode=0
+num-detected-classes=80
+gie-unique-id=1
+network-type=0
+## 1=DBSCAN, 2=NMS, 3= DBSCAN+NMS Hybrid, 4 = None(No clustering)
+cluster-mode=2
+maintain-aspect-ratio=1
+parse-bbox-func-name=NvDsInferParseCustomPPYOLOE
+custom-lib-path=../../../../build/libfd_streamer.so
+
+[class-attrs-all]
+nms-iou-threshold=0.45
+pre-cluster-threshold=0.25
+topk=300
diff --git a/streamer/examples/ppyoloe/cpp/streamer_cfg.yml b/streamer/examples/ppyoloe/cpp/streamer_cfg.yml
new file mode 100644
index 000000000..eb62e5959
--- /dev/null
+++ b/streamer/examples/ppyoloe/cpp/streamer_cfg.yml
@@ -0,0 +1,46 @@
+app:
+ type: video_analytics
+ enable-perf-measurement: true
+ perf-measurement-interval-sec: 5
+
+nvurisrcbin_list:
+ uri-list:
+ - file:///opt/nvidia/deepstream/deepstream/samples/streams/sample_ride_bike.mov
+ - file:///opt/nvidia/deepstream/deepstream/samples/streams/sample_ride_bike.mov
+ - file:///opt/nvidia/deepstream/deepstream/samples/streams/sample_ride_bike.mov
+ - file:///opt/nvidia/deepstream/deepstream/samples/streams/sample_ride_bike.mov
+ pad-prefix: mux.sink_
+ gpu-id: 0
+
+nvstreammux:
+ name: mux
+ gpu-id: 0
+ batch-size: 4
+ width: 1920
+ height: 1080
+ batched-push-timeout: 40000 # 40ms
+
+nvinfer:
+ gpu-id: 0
+ config-file-path: nvinfer_config.txt
+
+nvtracker:
+ gpu-id: 0
+ tracker-width: 640
+ tracker-height: 640
+ ll-lib-file: /opt/nvidia/deepstream/deepstream/lib/libnvds_nvmultiobjecttracker.so
+ ll-config-file: /opt/nvidia/deepstream/deepstream/samples/configs/deepstream-app/config_tracker_NvDCF_perf.yml
+ enable-batch-process: true
+
+nvmultistreamtiler:
+ gpu-id: 0
+ rows: 2
+ columns: 2
+
+nvosdbin:
+ gpu-id: 0
+
+nvvideoencfilesinkbin:
+ gpu-id: 0
+ bitrate: 4000
+ output-file: out.mp4
diff --git a/streamer/examples/video_decoder/cpp/CMakeLists.txt b/streamer/examples/video_decoder/cpp/CMakeLists.txt
new file mode 100644
index 000000000..2e551a341
--- /dev/null
+++ b/streamer/examples/video_decoder/cpp/CMakeLists.txt
@@ -0,0 +1,30 @@
+# 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.
+PROJECT(video_decoder C CXX)
+CMAKE_MINIMUM_REQUIRED (VERSION 3.10)
+
+option(FASTDEPLOY_INSTALL_DIR "Path of downloaded fastdeploy sdk.")
+include(${FASTDEPLOY_INSTALL_DIR}/FastDeploy.cmake)
+include_directories(${FASTDEPLOY_INCS})
+
+set(FDSTREAMER_INCLUDE_DIR ${PROJECT_SOURCE_DIR}/../../../src/)
+include_directories(${FDSTREAMER_INCLUDE_DIR})
+link_directories(${PROJECT_SOURCE_DIR}/../../../build/)
+
+find_package(PkgConfig REQUIRED)
+pkg_check_modules(GSTAPP gstreamer-app-1.0 REQUIRED)
+include_directories(${GSTAPP_INCLUDE_DIRS})
+
+add_executable(video_decoder main.cc)
+target_link_libraries(video_decoder fd_streamer ${FASTDEPLOY_LIBS})
diff --git a/streamer/examples/video_decoder/cpp/README.md b/streamer/examples/video_decoder/cpp/README.md
new file mode 120000
index 000000000..f18766817
--- /dev/null
+++ b/streamer/examples/video_decoder/cpp/README.md
@@ -0,0 +1 @@
+README_EN.md
\ No newline at end of file
diff --git a/streamer/examples/video_decoder/cpp/README_CN.md b/streamer/examples/video_decoder/cpp/README_CN.md
new file mode 100644
index 000000000..1e91e6783
--- /dev/null
+++ b/streamer/examples/video_decoder/cpp/README_CN.md
@@ -0,0 +1,20 @@
+简体中文 | [English](README_EN.md)
+
+# FastDeploy Streamer Video Decoder Example
+
+## 编译和运行
+
+1. 需要先FastDeploy Streamer, 请参考[README](../../../README.md)
+
+2. 编译Example
+```
+mkdir build && cd build
+cmake .. -DFASTDEPLOY_INSTALL_DIR=[PATH-OF-FASTDEPLOY-INSTALL-DIR]
+make -j
+```
+
+3. 运行
+```
+cp ../streamer_cfg.yml .
+./video_decoder
+```
diff --git a/streamer/examples/video_decoder/cpp/README_EN.md b/streamer/examples/video_decoder/cpp/README_EN.md
new file mode 100644
index 000000000..4b6a0905b
--- /dev/null
+++ b/streamer/examples/video_decoder/cpp/README_EN.md
@@ -0,0 +1,20 @@
+English | [简体中文](README_CN.md)
+
+# FastDeploy Streamer Video Decoder Example
+
+## Build and Run
+
+1. Build FastDeploy Streamer first, [README](../../../README.md)
+
+2. Build Example
+```
+mkdir build && cd build
+cmake .. -DFASTDEPLOY_INSTALL_DIR=[PATH-OF-FASTDEPLOY-INSTALL-DIR]
+make -j
+```
+
+3. Run
+```
+cp ../streamer_cfg.yml .
+./video_decoder
+```
diff --git a/streamer/examples/video_decoder/cpp/main.cc b/streamer/examples/video_decoder/cpp/main.cc
new file mode 100644
index 000000000..0b3d3435e
--- /dev/null
+++ b/streamer/examples/video_decoder/cpp/main.cc
@@ -0,0 +1,43 @@
+// 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 "fd_streamer.h"
+#include "fastdeploy/utils/perf.h"
+#include
+
+int main(int argc, char* argv[]) {
+ auto streamer = fastdeploy::streamer::FDStreamer();
+ streamer.Init("streamer_cfg.yml");
+ streamer.RunAsync();
+ int count = 0;
+ fastdeploy::FDTensor tensor;
+ fastdeploy::TimeCounter tc;
+ tc.Start();
+ while (1) {
+ bool ret = streamer.TryPullFrame(tensor);
+ if (!ret) {
+ if (streamer.Destroyed()) break;
+ std::this_thread::sleep_for(std::chrono::milliseconds(1));
+ continue;
+ }
+ count++;
+ tensor.PrintInfo();
+ cv::Mat mat(tensor.shape[0], tensor.shape[1], CV_8UC3, tensor.Data());
+ cv::imwrite("out/" + std::to_string(count) + ".jpg", mat);
+ }
+ std::cout << "Total number of frames: " << count << std::endl;
+ tc.End();
+ tc.PrintInfo();
+ return 0;
+}
diff --git a/streamer/examples/video_decoder/cpp/streamer_cfg.yml b/streamer/examples/video_decoder/cpp/streamer_cfg.yml
new file mode 100644
index 000000000..9ab1985fb
--- /dev/null
+++ b/streamer/examples/video_decoder/cpp/streamer_cfg.yml
@@ -0,0 +1,19 @@
+app:
+ type: video_decoder
+ enable-perf-measurement: true
+ perf-measurement-interval-sec: 5
+
+nvurisrcbin:
+ uri: file:///opt/nvidia/deepstream/deepstream/samples/streams/sample_ride_bike.mov
+ gpu-id: 0
+
+nvvideoconvert:
+ gpu-id: 0
+
+capsfilter:
+ caps: video/x-raw,format=(string)BGR
+
+appsink:
+ sync: true
+ max-buffers: 60
+ drop: false
diff --git a/streamer/src/app/base_app.cc b/streamer/src/app/base_app.cc
new file mode 100644
index 000000000..dee7c1929
--- /dev/null
+++ b/streamer/src/app/base_app.cc
@@ -0,0 +1,135 @@
+// 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 "app/base_app.h"
+#include "app/yaml_parser.h"
+#include "gstreamer/utils.h"
+#include "gstreamer/perf.h"
+
+namespace fastdeploy {
+namespace streamer {
+
+static GMutex fps_lock;
+
+static gboolean bus_watch_callback(GstBus* bus, GstMessage* msg, gpointer data) {
+ GMainLoop* loop = (GMainLoop*)data;
+ switch (GST_MESSAGE_TYPE(msg)) {
+ case GST_MESSAGE_EOS:
+ g_print("End of stream\n");
+ g_main_loop_quit(loop);
+ break;
+ case GST_MESSAGE_ERROR: {
+ gchar* debug;
+ GError* error;
+ gst_message_parse_error(msg, &error, &debug);
+ g_printerr("ERROR from element %s: %s\n",
+ GST_OBJECT_NAME(msg->src), error->message);
+ if (debug)
+ g_printerr("Error details: %s\n", debug);
+ g_free(debug);
+ g_error_free(error);
+ g_main_loop_quit(loop);
+ break;
+ }
+ default:
+ break;
+ }
+ return TRUE;
+}
+
+static void PerfCallbackFunc(gpointer context, PerfResult* perf) {
+ g_mutex_lock(&fps_lock);
+ std::cout << "FPS: " << perf->fps
+ << ", total avg.: " << perf->fps_avg << std::endl;
+ g_mutex_unlock(&fps_lock);
+}
+
+bool BaseApp::Init(const std::string& config_file) {
+ gst_init(NULL, NULL);
+ loop_ = g_main_loop_new(NULL, FALSE);
+
+ YamlParser parser(config_file);
+ pipeline_ = parser.BuildPipelineFromConfig();
+
+ GstBus* bus = gst_pipeline_get_bus(GST_PIPELINE(pipeline_));
+ bus_watch_id_ = gst_bus_add_watch(bus, bus_watch_callback, loop_);
+ gst_object_unref(bus);
+
+ SetupPerfMeasurement();
+ return true;
+}
+
+bool BaseApp::Run() {
+ gst_element_set_state(pipeline_, GST_STATE_PLAYING);
+
+ /* Wait till pipeline encounters an error or EOS */
+ g_print("Running...\n");
+ g_main_loop_run(loop_);
+
+ Destroy();
+ return true;
+}
+
+static void MainLoopThread(BaseApp* app) {
+ g_main_loop_run(app->GetLoop());
+ app->Destroy();
+}
+
+bool BaseApp::RunAsync() {
+ gst_element_set_state(pipeline_, GST_STATE_PLAYING);
+ g_print("Running Asynchronous...\n");
+ // std::thread t(MainLoopThread, this);
+ // thread_ = std::move(t);
+ std::future fut = std::async(std::launch::async, MainLoopThread, this);
+ future_ = std::move(fut);
+ return true;
+}
+
+void BaseApp::SetupPerfMeasurement() {
+ if (!app_config_.enable_perf_measurement) return;
+
+ GstElement* elem = NULL;
+ auto elem_names = GetSinkElemNames(GST_BIN(pipeline_));
+ for (auto& elem_name : elem_names) {
+ std::cout << elem_name << std::endl;
+ if (elem_name.find("nvvideoencfilesinkbin") != std::string::npos) {
+ elem = gst_bin_get_by_name(GST_BIN(pipeline_), elem_name.c_str());
+ } else if (elem_name.find("appsink") != std::string::npos) {
+ elem = gst_bin_get_by_name(GST_BIN(pipeline_), elem_name.c_str());
+ }
+ }
+ FDASSERT(elem != NULL, "Can't find a properly sink bin in the pipeline");
+
+ GstPad* perf_pad = gst_element_get_static_pad(elem, "sink");
+ FDASSERT(perf_pad != NULL, "Unable to get sink pad");
+
+ perf_ctx_.user_data = nullptr;
+ EnablePerfMeasurement(&perf_ctx_, perf_pad,
+ (gulong)(app_config_.perf_interval_sec), PerfCallbackFunc);
+
+ gst_object_unref(perf_pad);
+}
+
+void BaseApp::Destroy() {
+ g_print("Returned, stopping playback\n");
+ gst_element_set_state(pipeline_, GST_STATE_NULL);
+ g_print("Deleting pipeline\n");
+ gst_object_unref(GST_OBJECT(pipeline_));
+ g_source_remove(bus_watch_id_);
+ g_main_loop_unref(loop_);
+ destroyed_ = true;
+}
+
+} // namespace streamer
+} // namespace fastdeploy
diff --git a/streamer/src/app/base_app.h b/streamer/src/app/base_app.h
new file mode 100644
index 000000000..db1827b5b
--- /dev/null
+++ b/streamer/src/app/base_app.h
@@ -0,0 +1,86 @@
+// 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.
+#pragma once
+
+#include "fastdeploy/utils/utils.h"
+#include "gstreamer/types.h"
+
+#include
+#include // NOLINT
+
+namespace fastdeploy {
+namespace streamer {
+
+enum AppType {
+ VIDEO_ANALYTICS, ///< Video analytics app
+ VIDEO_DECODER, ///< Video decoder app
+};
+
+struct AppConfig {
+ AppType type;
+ bool enable_perf_measurement = false;
+ int perf_interval_sec = 5;
+};
+
+/*! @brief Base App class
+ */
+class BaseApp {
+ public:
+ BaseApp() {}
+ explicit BaseApp(AppConfig& app_config) {
+ app_config_ = app_config;
+ }
+ virtual ~BaseApp() = default;
+
+ virtual bool Init(const std::string& config_file);
+
+ bool Run();
+
+ bool RunAsync();
+
+ void Destroy();
+
+ void SetupPerfMeasurement();
+
+ AppConfig* GetAppConfig() {
+ return &app_config_;
+ }
+
+ GstElement* GetPipeline() {
+ return pipeline_;
+ }
+
+ GMainLoop* GetLoop() {
+ return loop_;
+ }
+
+ guint GetBusId() {
+ return bus_watch_id_;
+ }
+
+ bool Destroyed() {
+ return destroyed_;
+ }
+
+ protected:
+ AppConfig app_config_;
+ GstElement* pipeline_;
+ GMainLoop* loop_;
+ guint bus_watch_id_;
+ PerfContext perf_ctx_;
+ std::future future_;
+ bool destroyed_ = false;
+};
+} // namespace streamer
+} // namespace fastdeploy
diff --git a/streamer/src/app/video_analytics.cc b/streamer/src/app/video_analytics.cc
new file mode 100644
index 000000000..54b5e7ae1
--- /dev/null
+++ b/streamer/src/app/video_analytics.cc
@@ -0,0 +1,21 @@
+// 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 "app/video_analytics.h"
+
+namespace fastdeploy {
+namespace streamer {
+
+} // namespace streamer
+} // namespace fastdeploy
diff --git a/streamer/src/app/video_analytics.h b/streamer/src/app/video_analytics.h
new file mode 100644
index 000000000..e256be4b7
--- /dev/null
+++ b/streamer/src/app/video_analytics.h
@@ -0,0 +1,33 @@
+// 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.
+#pragma once
+
+#include "app/base_app.h"
+#include "fastdeploy/utils/utils.h"
+
+#include
+
+namespace fastdeploy {
+namespace streamer {
+
+/*! @brief VideoAnalyticsApp class
+ */
+class FASTDEPLOY_DECL VideoAnalyticsApp : public BaseApp {
+ public:
+ explicit VideoAnalyticsApp(AppConfig& app_config) : BaseApp(app_config) {}
+
+ private:
+};
+} // namespace streamer
+} // namespace fastdeploy
diff --git a/streamer/src/app/video_decoder.cc b/streamer/src/app/video_decoder.cc
new file mode 100644
index 000000000..7c11e7dd9
--- /dev/null
+++ b/streamer/src/app/video_decoder.cc
@@ -0,0 +1,69 @@
+// 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 "app/video_decoder.h"
+#include "gstreamer/utils.h"
+
+namespace fastdeploy {
+namespace streamer {
+
+bool VideoDecoderApp::Init(const std::string& config_file) {
+ FDINFO << "this " << std::endl;
+ BaseApp::Init(config_file);
+ GetAppsinkFromPipeline();
+ return true;
+}
+
+bool VideoDecoderApp::TryPullFrame(FDTensor& tensor, int timeout_ms) {
+ GstSample* sample = gst_app_sink_try_pull_sample(appsink_,
+ timeout_ms * GST_MSECOND);
+ if (sample == NULL) {
+ return false;
+ }
+ GstCaps* caps = NULL;
+ uint8_t* data = nullptr;
+ Frame frame;
+ do {
+ bool ret = GetFrameFromSample(sample, frame);
+ if (!ret) {
+ FDERROR << "Failed to get buffer from sample." << std::endl;
+ break;
+ }
+ FDASSERT(frame.device == Device::CPU,
+ "Currently, only CPU frame is supported");
+
+ std::vector shape = GetFrameShape(frame);
+ tensor.Resize(shape, FDDataType::UINT8, "", frame.device);
+ FDTensor::CopyBuffer(tensor.Data(), frame.data, tensor.Nbytes(),
+ tensor.device);
+ } while (false);
+
+ if (sample) gst_sample_unref(sample);
+ return true;
+}
+
+void VideoDecoderApp::GetAppsinkFromPipeline() {
+ GstElement* elem = NULL;
+ auto elem_names = GetSinkElemNames(GST_BIN(pipeline_));
+ for (auto& elem_name : elem_names) {
+ std::cout << elem_name << std::endl;
+ if (elem_name.find("appsink") != std::string::npos) {
+ elem = gst_bin_get_by_name(GST_BIN(pipeline_), elem_name.c_str());
+ }
+ }
+ FDASSERT(elem != NULL, "Can't find a appsink in the pipeline");
+ appsink_ = GST_APP_SINK_CAST(elem);
+}
+} // namespace streamer
+} // namespace fastdeploy
diff --git a/streamer/src/app/video_decoder.h b/streamer/src/app/video_decoder.h
new file mode 100644
index 000000000..1bab3e7d6
--- /dev/null
+++ b/streamer/src/app/video_decoder.h
@@ -0,0 +1,41 @@
+// 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.
+#pragma once
+
+#include "app/base_app.h"
+#include "fastdeploy/utils/utils.h"
+#include "fastdeploy/core/fd_tensor.h"
+
+#include
+#include
+
+namespace fastdeploy {
+namespace streamer {
+
+/*! @brief VideoDecoderApp class
+ */
+class FASTDEPLOY_DECL VideoDecoderApp : public BaseApp {
+ public:
+ explicit VideoDecoderApp(AppConfig& app_config) : BaseApp(app_config) {}
+
+ bool Init(const std::string& config_file);
+
+ bool TryPullFrame(FDTensor& tensor, int timeout_ms);
+
+ private:
+ void GetAppsinkFromPipeline();
+ GstAppSink* appsink_;
+};
+} // namespace streamer
+} // namespace fastdeploy
diff --git a/streamer/src/app/yaml_parser.cc b/streamer/src/app/yaml_parser.cc
new file mode 100644
index 000000000..92c385777
--- /dev/null
+++ b/streamer/src/app/yaml_parser.cc
@@ -0,0 +1,125 @@
+// 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 "app/yaml_parser.h"
+#include "gstreamer/utils.h"
+
+namespace fastdeploy {
+namespace streamer {
+
+YamlParser::YamlParser(const std::string& config_file) {
+ try {
+ yaml_config_ = YAML::LoadFile(config_file);
+ } catch (YAML::BadFile& e) {
+ FDERROR << "Failed to load yaml file " << config_file
+ << ", maybe you should check this file." << std::endl;
+ }
+ config_file_ = config_file;
+}
+
+void YamlParser::ParseAppConfg(AppConfig& app_config) {
+ ValidateConfig();
+ auto elem = yaml_config_["app"];
+
+ auto type_str = elem["type"].as();
+ if (type_str == "video_analytics") {
+ app_config.type = AppType::VIDEO_ANALYTICS;
+ } else if (type_str == "video_decoder") {
+ app_config.type = AppType::VIDEO_DECODER;
+ } else {
+ FDASSERT(false, "Unsupported app type: %s.", type_str.c_str());
+ }
+
+ app_config.enable_perf_measurement = elem["enable-perf-measurement"].as();
+ if (app_config.enable_perf_measurement) {
+ app_config.perf_interval_sec = elem["perf-measurement-interval-sec"].as();
+ }
+ app_config_ = app_config;
+}
+
+void YamlParser::ValidateConfig() {
+ auto first_elem = yaml_config_.begin()->first.as();
+ if (first_elem != "app") {
+ FDASSERT(false, "First config element must be app, but got %s.",
+ first_elem.c_str());
+ }
+}
+
+GstElement* YamlParser::BuildPipelineFromConfig() {
+ auto pipeline_desc = YamlToPipelineDescStr();
+ pipeline_ = CreatePipeline(pipeline_desc);
+ return pipeline_;
+}
+
+std::string YamlParser::YamlToPipelineDescStr() {
+ for (const auto& elem : yaml_config_) {
+ std::string elem_name = elem.first.as();
+ std::cout << elem_name << std::endl;
+ ParseElement(elem_name, elem.second);
+ }
+ std::string pipeline_desc = "";
+ for (size_t i = 0; i < elem_descs_.size(); i++) {
+ pipeline_desc += elem_descs_[i];
+ if (elem_descs_[i].find('!') != std::string::npos) continue;
+ if (i >= elem_descs_.size() - 1) continue;
+ pipeline_desc += "! ";
+ }
+ return pipeline_desc;
+}
+
+void YamlParser::ParseElement(const std::string& name, const YAML::Node& properties) {
+ if (name == "app") return;
+
+ if (name == "nvurisrcbin_list") {
+ ParseNvUriSrcBinList(name, properties);
+ return;
+ }
+
+ std::string elem_desc = name + " ";
+ for (auto it = properties.begin(); it != properties.end(); it++) {
+ elem_desc += ParseProperty(it->first, it->second) + " ";
+ }
+ elem_descs_.push_back(elem_desc);
+}
+
+void YamlParser::ParseNvUriSrcBinList(const std::string& name, const YAML::Node& properties) {
+ std::string elem_name = "nvurisrcbin";
+
+ auto uri_list = properties["uri-list"].as>();
+ auto pad_prefix = properties["pad-prefix"].as();
+ for (size_t i = 0; i < uri_list.size(); i++) {
+ std::string elem_desc = elem_name + " ";
+ elem_desc += "uri=" + uri_list[i] + " ";
+ for (auto it = properties.begin(); it != properties.end(); it++) {
+ auto prop_name = it->first.as();
+ if (prop_name == "uri-list" || prop_name == "pad-prefix") continue;
+ elem_desc += ParseProperty(it->first, it->second) + " ";
+ }
+ elem_desc += "! " + pad_prefix + std::to_string(i) + " ";
+ elem_descs_.push_back(elem_desc);
+ }
+}
+
+std::string YamlParser::ParseProperty(const YAML::Node& name, const YAML::Node& value) {
+ std::string prop_name = name.as();
+ std::string prop_value = value.as();
+
+ if (prop_name == "_link_to") {
+ return "! " + prop_value + " ";
+ }
+
+ return prop_name + "=" + prop_value;
+}
+} // namespace streamer
+} // namespace fastdeploy
diff --git a/streamer/src/app/yaml_parser.h b/streamer/src/app/yaml_parser.h
new file mode 100644
index 000000000..966a9b623
--- /dev/null
+++ b/streamer/src/app/yaml_parser.h
@@ -0,0 +1,58 @@
+// 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.
+
+#pragma once
+
+#include "yaml-cpp/yaml.h"
+#include "app/base_app.h"
+#include
+
+namespace fastdeploy {
+namespace streamer {
+
+/*! @brief YAML Parser class, to parse stream configs from yaml file
+ */
+class YamlParser {
+ public:
+ /** \brief Create a YAML parser
+ *
+ * \param[in] config_file Path of configuration file
+ */
+ explicit YamlParser(const std::string& config_file);
+
+ void ParseAppConfg(AppConfig& app_config);
+
+ void ValidateConfig();
+
+ GstElement* BuildPipelineFromConfig();
+
+ private:
+ std::string YamlToPipelineDescStr();
+
+ void ParseElement(const std::string& name, const YAML::Node& properties);
+
+ void ParseNvUriSrcBinList(const std::string& name,
+ const YAML::Node& properties);
+
+ static std::string ParseProperty(const YAML::Node& name,
+ const YAML::Node& value);
+
+ AppConfig app_config_;
+ std::string config_file_;
+ YAML::Node yaml_config_;
+ GstElement* pipeline_;
+ std::vector elem_descs_;
+};
+} // namespace streamer
+} // namespace fastdeploy
diff --git a/streamer/src/deepstream/bbox_parser.cc b/streamer/src/deepstream/bbox_parser.cc
new file mode 100644
index 000000000..7a32de40e
--- /dev/null
+++ b/streamer/src/deepstream/bbox_parser.cc
@@ -0,0 +1,76 @@
+// 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 "nvdsinfer_custom_impl.h"
+#include
+#include
+#include
+#include
+#include
+
+static float clamp(const float val, const float min_val, const float max_val) {
+ assert(min_val <= max_val);
+ return std::min(max_val, std::max(min_val, val));
+}
+
+extern "C" bool NvDsInferParseCustomPPYOLOE(
+ std::vector const& outputLayersInfo,
+ NvDsInferNetworkInfo const& networkInfo,
+ NvDsInferParseDetectionParams const& detectionParams,
+ std::vector& objectList) {
+ if (outputLayersInfo.empty()) {
+ std::cerr << "Could not find output layer in bbox parsing" << std::endl;;
+ return false;
+ }
+
+ int num_classes = outputLayersInfo[0].inferDims.d[0];
+ if (num_classes != detectionParams.numClassesConfigured) {
+ std::cerr << "WARNING: Num classes mismatch. Configured:"
+ << detectionParams.numClassesConfigured
+ << ", detected by network: " << num_classes << std::endl;
+ assert(-1);
+ }
+
+ int num_obj = outputLayersInfo[0].inferDims.d[1];
+ float* score_data = (float*)outputLayersInfo[0].buffer;
+ float* bbox_data = (float*)outputLayersInfo[1].buffer;
+
+ for (int i = 0; i < num_obj; i++) {
+ float max_score = -1.0f;
+ int class_id = -1;
+ for (int j = 0; j < num_classes; j++) {
+ float score = score_data[num_obj * j + i];
+ if (score > max_score) {
+ max_score = score;
+ class_id = j;
+ }
+ }
+ NvDsInferParseObjectInfo obj;
+ obj.classId = (uint32_t)class_id;
+ obj.detectionConfidence = max_score;
+ obj.left = bbox_data[4 * i];
+ obj.top = bbox_data[4 * i + 1];
+ obj.width = bbox_data[4 * i + 2] - bbox_data[4 * i];
+ obj.height = bbox_data[4 * i + 3] - bbox_data[4 * i + 1];
+ obj.left = clamp(obj.left, 0, networkInfo.width);
+ obj.top = clamp(obj.top, 0, networkInfo.height);
+ obj.width = clamp(obj.width, 0, networkInfo.width);
+ obj.height = clamp(obj.height, 0, networkInfo.height);
+ objectList.push_back(obj);
+ }
+ return true;
+}
+
+/* Check that the custom function has been defined correctly */
+CHECK_CUSTOM_PARSE_FUNC_PROTOTYPE(NvDsInferParseCustomPPYOLOE);
diff --git a/streamer/src/fd_streamer.cc b/streamer/src/fd_streamer.cc
new file mode 100644
index 000000000..ecd78a499
--- /dev/null
+++ b/streamer/src/fd_streamer.cc
@@ -0,0 +1,56 @@
+// 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 "fd_streamer.h"
+#include "app/yaml_parser.h"
+#include "app/video_analytics.h"
+#include "app/video_decoder.h"
+#include "fastdeploy/utils/unique_ptr.h"
+
+namespace fastdeploy {
+namespace streamer {
+
+bool FDStreamer::Init(const std::string& config_file) {
+ AppConfig app_config;
+ YamlParser parser(config_file);
+ parser.ParseAppConfg(app_config);
+ if (app_config.type == AppType::VIDEO_ANALYTICS) {
+ app_ = utils::make_unique(app_config);
+ auto casted_app = dynamic_cast