From 9918374d74fd9e4e6c22b4d3e22b9a4f5308eec5 Mon Sep 17 00:00:00 2001 From: ziqi-jin <67993288+ziqi-jin@users.noreply.github.com> Date: Wed, 10 Aug 2022 10:28:07 +0800 Subject: [PATCH] Modify YOLOv7 Infer file and the external model namespace (#87) * first commit for yolov7 * pybind for yolov7 * CPP README.md * CPP README.md * modified yolov7.cc * README.md * python file modify * delete license in fastdeploy/ * repush the conflict part * README.md modified * README.md modified * file path modified * file path modified * file path modified * file path modified * file path modified * README modified * README modified * move some helpers to private * add examples for yolov7 * api.md modified * api.md modified * api.md modified * YOLOv7 * yolov7 release link * yolov7 release link * yolov7 release link * copyright * change some helpers to private * change variables to const and fix documents. * gitignore * Transfer some funtions to private member of class * Transfer some funtions to private member of class * Merge from develop (#9) * Fix compile problem in different python version (#26) * fix some usage problem in linux * Fix compile problem Co-authored-by: root * Add PaddleDetetion/PPYOLOE model support (#22) * add ppdet/ppyoloe * Add demo code and documents * add convert processor to vision (#27) * update .gitignore * Added checking for cmake include dir * fixed missing trt_backend option bug when init from trt * remove un-need data layout and add pre-check for dtype * changed RGB2BRG to BGR2RGB in ppcls model * add model_zoo yolov6 c++/python demo * fixed CMakeLists.txt typos * update yolov6 cpp/README.md * add yolox c++/pybind and model_zoo demo * move some helpers to private * fixed CMakeLists.txt typos * add normalize with alpha and beta * add version notes for yolov5/yolov6/yolox * add copyright to yolov5.cc * revert normalize * fixed some bugs in yolox * fixed examples/CMakeLists.txt to avoid conflicts * add convert processor to vision * format examples/CMakeLists summary * Fix bug while the inference result is empty with YOLOv5 (#29) * Add multi-label function for yolov5 * Update README.md Update doc * Update fastdeploy_runtime.cc fix variable option.trt_max_shape wrong name * Update runtime_option.md Update resnet model dynamic shape setting name from images to x * Fix bug when inference result boxes are empty * Delete detection.py Co-authored-by: Jason Co-authored-by: root Co-authored-by: DefTruth <31974251+DefTruth@users.noreply.github.com> Co-authored-by: huangjianhui <852142024@qq.com> * first commit for yolor * for merge * Develop (#11) * Fix compile problem in different python version (#26) * fix some usage problem in linux * Fix compile problem Co-authored-by: root * Add PaddleDetetion/PPYOLOE model support (#22) * add ppdet/ppyoloe * Add demo code and documents * add convert processor to vision (#27) * update .gitignore * Added checking for cmake include dir * fixed missing trt_backend option bug when init from trt * remove un-need data layout and add pre-check for dtype * changed RGB2BRG to BGR2RGB in ppcls model * add model_zoo yolov6 c++/python demo * fixed CMakeLists.txt typos * update yolov6 cpp/README.md * add yolox c++/pybind and model_zoo demo * move some helpers to private * fixed CMakeLists.txt typos * add normalize with alpha and beta * add version notes for yolov5/yolov6/yolox * add copyright to yolov5.cc * revert normalize * fixed some bugs in yolox * fixed examples/CMakeLists.txt to avoid conflicts * add convert processor to vision * format examples/CMakeLists summary * Fix bug while the inference result is empty with YOLOv5 (#29) * Add multi-label function for yolov5 * Update README.md Update doc * Update fastdeploy_runtime.cc fix variable option.trt_max_shape wrong name * Update runtime_option.md Update resnet model dynamic shape setting name from images to x * Fix bug when inference result boxes are empty * Delete detection.py Co-authored-by: Jason Co-authored-by: root Co-authored-by: DefTruth <31974251+DefTruth@users.noreply.github.com> Co-authored-by: huangjianhui <852142024@qq.com> * Yolor (#16) * Develop (#11) (#12) * Fix compile problem in different python version (#26) * fix some usage problem in linux * Fix compile problem Co-authored-by: root * Add PaddleDetetion/PPYOLOE model support (#22) * add ppdet/ppyoloe * Add demo code and documents * add convert processor to vision (#27) * update .gitignore * Added checking for cmake include dir * fixed missing trt_backend option bug when init from trt * remove un-need data layout and add pre-check for dtype * changed RGB2BRG to BGR2RGB in ppcls model * add model_zoo yolov6 c++/python demo * fixed CMakeLists.txt typos * update yolov6 cpp/README.md * add yolox c++/pybind and model_zoo demo * move some helpers to private * fixed CMakeLists.txt typos * add normalize with alpha and beta * add version notes for yolov5/yolov6/yolox * add copyright to yolov5.cc * revert normalize * fixed some bugs in yolox * fixed examples/CMakeLists.txt to avoid conflicts * add convert processor to vision * format examples/CMakeLists summary * Fix bug while the inference result is empty with YOLOv5 (#29) * Add multi-label function for yolov5 * Update README.md Update doc * Update fastdeploy_runtime.cc fix variable option.trt_max_shape wrong name * Update runtime_option.md Update resnet model dynamic shape setting name from images to x * Fix bug when inference result boxes are empty * Delete detection.py Co-authored-by: Jason Co-authored-by: root Co-authored-by: DefTruth <31974251+DefTruth@users.noreply.github.com> Co-authored-by: huangjianhui <852142024@qq.com> Co-authored-by: Jason Co-authored-by: root Co-authored-by: DefTruth <31974251+DefTruth@users.noreply.github.com> Co-authored-by: huangjianhui <852142024@qq.com> * Develop (#13) * Fix compile problem in different python version (#26) * fix some usage problem in linux * Fix compile problem Co-authored-by: root * Add PaddleDetetion/PPYOLOE model support (#22) * add ppdet/ppyoloe * Add demo code and documents * add convert processor to vision (#27) * update .gitignore * Added checking for cmake include dir * fixed missing trt_backend option bug when init from trt * remove un-need data layout and add pre-check for dtype * changed RGB2BRG to BGR2RGB in ppcls model * add model_zoo yolov6 c++/python demo * fixed CMakeLists.txt typos * update yolov6 cpp/README.md * add yolox c++/pybind and model_zoo demo * move some helpers to private * fixed CMakeLists.txt typos * add normalize with alpha and beta * add version notes for yolov5/yolov6/yolox * add copyright to yolov5.cc * revert normalize * fixed some bugs in yolox * fixed examples/CMakeLists.txt to avoid conflicts * add convert processor to vision * format examples/CMakeLists summary * Fix bug while the inference result is empty with YOLOv5 (#29) * Add multi-label function for yolov5 * Update README.md Update doc * Update fastdeploy_runtime.cc fix variable option.trt_max_shape wrong name * Update runtime_option.md Update resnet model dynamic shape setting name from images to x * Fix bug when inference result boxes are empty * Delete detection.py Co-authored-by: Jason Co-authored-by: root Co-authored-by: DefTruth <31974251+DefTruth@users.noreply.github.com> Co-authored-by: huangjianhui <852142024@qq.com> * documents * documents * documents * documents * documents * documents * documents * documents * documents * documents * documents * documents * Develop (#14) * Fix compile problem in different python version (#26) * fix some usage problem in linux * Fix compile problem Co-authored-by: root * Add PaddleDetetion/PPYOLOE model support (#22) * add ppdet/ppyoloe * Add demo code and documents * add convert processor to vision (#27) * update .gitignore * Added checking for cmake include dir * fixed missing trt_backend option bug when init from trt * remove un-need data layout and add pre-check for dtype * changed RGB2BRG to BGR2RGB in ppcls model * add model_zoo yolov6 c++/python demo * fixed CMakeLists.txt typos * update yolov6 cpp/README.md * add yolox c++/pybind and model_zoo demo * move some helpers to private * fixed CMakeLists.txt typos * add normalize with alpha and beta * add version notes for yolov5/yolov6/yolox * add copyright to yolov5.cc * revert normalize * fixed some bugs in yolox * fixed examples/CMakeLists.txt to avoid conflicts * add convert processor to vision * format examples/CMakeLists summary * Fix bug while the inference result is empty with YOLOv5 (#29) * Add multi-label function for yolov5 * Update README.md Update doc * Update fastdeploy_runtime.cc fix variable option.trt_max_shape wrong name * Update runtime_option.md Update resnet model dynamic shape setting name from images to x * Fix bug when inference result boxes are empty * Delete detection.py Co-authored-by: root Co-authored-by: DefTruth <31974251+DefTruth@users.noreply.github.com> Co-authored-by: huangjianhui <852142024@qq.com> Co-authored-by: Jason Co-authored-by: root Co-authored-by: DefTruth <31974251+DefTruth@users.noreply.github.com> Co-authored-by: huangjianhui <852142024@qq.com> Co-authored-by: Jason <928090362@qq.com> * add is_dynamic for YOLO series (#22) * modify namespace for yolov5lite * modify namespace for external detection models * modify namespace for yolov5lite * modify namespace for face models * py namespace for external model * fix compile error and infer file * change paddleyolox to yolox * delete space in cmakelist * check code specification Co-authored-by: Jason Co-authored-by: root Co-authored-by: DefTruth <31974251+DefTruth@users.noreply.github.com> Co-authored-by: huangjianhui <852142024@qq.com> Co-authored-by: Jason <928090362@qq.com> --- csrcs/fastdeploy/vision.h | 34 +- .../vision/deepinsight/deepinsight_pybind.cc | 144 ----- .../contrib}/nanodet_plus.cc | 6 +- .../contrib}/nanodet_plus.h | 6 +- .../contrib/nanodet_plus_pybind.cc} | 22 +- .../contrib}/yolov5.cc | 16 +- .../contrib}/yolov5.h | 33 +- .../contrib/yolov5_pybind.cc} | 25 +- .../contrib}/yolov5lite.cc | 7 +- .../{ppogg => detection/contrib}/yolov5lite.h | 7 +- .../contrib/yolov5lite_pybind.cc} | 30 +- .../{meituan => detection/contrib}/yolov6.cc | 12 +- .../{meituan => detection/contrib}/yolov6.h | 35 +- .../vision/detection/contrib/yolov6_pybind.cc | 37 ++ .../{megvii => detection/contrib}/yolox.cc | 8 +- .../{megvii => detection/contrib}/yolox.h | 38 +- .../contrib/yolox_pybind.cc} | 22 +- .../vision/detection/detection_pybind.cc | 10 + .../contrib}/retinaface.cc | 6 +- .../{biubug6 => facedet/contrib}/retinaface.h | 6 +- .../contrib/retinaface_pybind.cc} | 18 +- .../{deepinsight => facedet/contrib}/scrfd.cc | 32 +- .../{deepinsight => facedet/contrib}/scrfd.h | 6 +- .../vision/facedet/contrib/scrfd_pybind.cc | 45 ++ .../{linzaer => facedet/contrib}/ultraface.cc | 6 +- .../{linzaer => facedet/contrib}/ultraface.h | 4 +- .../contrib/ultraface_pybind.cc} | 12 +- .../contrib}/yolov5face.cc | 6 +- .../{deepcam => facedet/contrib}/yolov5face.h | 6 +- .../contrib/yolov5face_pybind.cc} | 22 +- .../vision/facedet/facedet_pybind.cc | 31 + .../contrib}/arcface.cc | 6 +- .../{deepinsight => faceid/contrib}/arcface.h | 6 +- .../vision/faceid/contrib/arcface_pybind.cc | 37 ++ .../contrib}/cosface.cc | 6 +- .../{deepinsight => faceid/contrib}/cosface.h | 6 +- .../vision/faceid/contrib/cosface_pybind.cc | 37 ++ .../contrib}/insightface_rec.cc | 6 +- .../contrib}/insightface_rec.h | 4 +- .../faceid/contrib/insightface_rec_pybind.cc | 42 ++ .../contrib}/partial_fc.cc | 6 +- .../contrib}/partial_fc.h | 6 +- .../faceid/contrib/partial_fc_pybind.cc | 37 ++ .../{deepinsight => faceid/contrib}/vpl.cc | 6 +- .../{deepinsight => faceid/contrib}/vpl.h | 6 +- .../vision/faceid/contrib/vpl_pybind.cc | 37 ++ .../fastdeploy/vision/faceid/faceid_pybind.cc | 33 + .../{zhkkke => matting/contrib}/modnet.cc | 6 +- .../{zhkkke => matting/contrib}/modnet.h | 6 +- .../contrib/modnet_pybind.cc} | 16 +- .../vision/matting/matting_pybind.cc | 26 + .../vision/ultralytics/ultralytics_pybind.cc | 42 -- csrcs/fastdeploy/vision/vision_pybind.cc | 26 +- csrcs/fastdeploy/vision/visualize/visualize.h | 4 +- fastdeploy/vision/__init__.py | 18 +- fastdeploy/vision/deepinsight/__init__.py | 563 ------------------ fastdeploy/vision/detection/__init__.py | 12 +- .../vision/detection/contrib/__init__.py | 15 + .../contrib/nanodet_plus.py} | 6 +- .../detection/{ => contrib}/scaled_yolov4.py | 4 +- .../vision/detection/{ => contrib}/yolor.py | 4 +- .../contrib/yolov5.py} | 6 +- .../contrib/yolov5lite.py} | 6 +- .../contrib/yolov6.py} | 6 +- .../vision/detection/{ => contrib}/yolov7.py | 4 +- .../contrib/yolox.py} | 8 +- fastdeploy/vision/facedet/__init__.py | 19 + fastdeploy/vision/facedet/contrib/__init__.py | 15 + .../contrib/retinaface.py} | 6 +- fastdeploy/vision/facedet/contrib/scrfd.py | 158 +++++ .../contrib/ultraface.py} | 6 +- .../contrib/yolov5face.py} | 6 +- fastdeploy/vision/faceid/__init__.py | 20 + fastdeploy/vision/faceid/contrib/__init__.py | 15 + fastdeploy/vision/faceid/contrib/arcface.py | 100 ++++ fastdeploy/vision/faceid/contrib/cosface.py | 99 +++ .../vision/faceid/contrib/insightface_rec.py | 99 +++ .../vision/faceid/contrib/partial_fc.py | 99 +++ fastdeploy/vision/faceid/contrib/vpl.py | 99 +++ fastdeploy/vision/matting/__init__.py | 16 + fastdeploy/vision/matting/contrib/__init__.py | 15 + .../__init__.py => matting/contrib/modnet.py} | 6 +- fastdeploy/vision/visualize/__init__.py | 4 +- fastdeploy/vision/wongkinyiu/__init__.py | 312 ---------- .../vision/detection/yolov7/cpp/README.md | 2 +- .../vision/detection/yolov7/cpp/infer.cc | 13 +- .../vision/detection/yolov7/python/README.md | 3 +- .../vision/detection/yolov7/python/infer.py | 3 +- 88 files changed, 1461 insertions(+), 1405 deletions(-) delete mode 100644 csrcs/fastdeploy/vision/deepinsight/deepinsight_pybind.cc rename csrcs/fastdeploy/vision/{rangilyu => detection/contrib}/nanodet_plus.cc (99%) rename csrcs/fastdeploy/vision/{rangilyu => detection/contrib}/nanodet_plus.h (97%) rename csrcs/fastdeploy/vision/{megvii/megvii_pybind.cc => detection/contrib/nanodet_plus_pybind.cc} (64%) rename csrcs/fastdeploy/vision/{ultralytics => detection/contrib}/yolov5.cc (97%) rename csrcs/fastdeploy/vision/{ultralytics => detection/contrib}/yolov5.h (83%) rename csrcs/fastdeploy/vision/{meituan/meituan_pybind.cc => detection/contrib/yolov5_pybind.cc} (57%) rename csrcs/fastdeploy/vision/{ppogg => detection/contrib}/yolov5lite.cc (99%) rename csrcs/fastdeploy/vision/{ppogg => detection/contrib}/yolov5lite.h (98%) rename csrcs/fastdeploy/vision/{ppogg/ppogg_pybind.cc => detection/contrib/yolov5lite_pybind.cc} (52%) rename csrcs/fastdeploy/vision/{meituan => detection/contrib}/yolov6.cc (97%) rename csrcs/fastdeploy/vision/{meituan => detection/contrib}/yolov6.h (83%) create mode 100644 csrcs/fastdeploy/vision/detection/contrib/yolov6_pybind.cc rename csrcs/fastdeploy/vision/{megvii => detection/contrib}/yolox.cc (98%) rename csrcs/fastdeploy/vision/{megvii => detection/contrib}/yolox.h (88%) rename csrcs/fastdeploy/vision/{rangilyu/rangilyu_pybind.cc => detection/contrib/yolox_pybind.cc} (58%) rename csrcs/fastdeploy/vision/{biubug6 => facedet/contrib}/retinaface.cc (99%) rename csrcs/fastdeploy/vision/{biubug6 => facedet/contrib}/retinaface.h (96%) rename csrcs/fastdeploy/vision/{biubug6/biubug6_pybind.cc => facedet/contrib/retinaface_pybind.cc} (67%) rename csrcs/fastdeploy/vision/{deepinsight => facedet/contrib}/scrfd.cc (93%) rename csrcs/fastdeploy/vision/{deepinsight => facedet/contrib}/scrfd.h (97%) create mode 100644 csrcs/fastdeploy/vision/facedet/contrib/scrfd_pybind.cc rename csrcs/fastdeploy/vision/{linzaer => facedet/contrib}/ultraface.cc (98%) rename csrcs/fastdeploy/vision/{linzaer => facedet/contrib}/ultraface.h (98%) rename csrcs/fastdeploy/vision/{linzaer/linzaer_pybind.cc => facedet/contrib/ultraface_pybind.cc} (70%) rename csrcs/fastdeploy/vision/{deepcam => facedet/contrib}/yolov5face.cc (99%) rename csrcs/fastdeploy/vision/{deepcam => facedet/contrib}/yolov5face.h (97%) rename csrcs/fastdeploy/vision/{deepcam/deepcam_pybind.cc => facedet/contrib/yolov5face_pybind.cc} (64%) create mode 100644 csrcs/fastdeploy/vision/facedet/facedet_pybind.cc rename csrcs/fastdeploy/vision/{deepinsight => faceid/contrib}/arcface.cc (96%) rename csrcs/fastdeploy/vision/{deepinsight => faceid/contrib}/arcface.h (95%) create mode 100644 csrcs/fastdeploy/vision/faceid/contrib/arcface_pybind.cc rename csrcs/fastdeploy/vision/{deepinsight => faceid/contrib}/cosface.cc (96%) rename csrcs/fastdeploy/vision/{deepinsight => faceid/contrib}/cosface.h (95%) create mode 100644 csrcs/fastdeploy/vision/faceid/contrib/cosface_pybind.cc rename csrcs/fastdeploy/vision/{deepinsight => faceid/contrib}/insightface_rec.cc (97%) rename csrcs/fastdeploy/vision/{deepinsight => faceid/contrib}/insightface_rec.h (98%) create mode 100644 csrcs/fastdeploy/vision/faceid/contrib/insightface_rec_pybind.cc rename csrcs/fastdeploy/vision/{deepinsight => faceid/contrib}/partial_fc.cc (96%) rename csrcs/fastdeploy/vision/{deepinsight => faceid/contrib}/partial_fc.h (95%) create mode 100644 csrcs/fastdeploy/vision/faceid/contrib/partial_fc_pybind.cc rename csrcs/fastdeploy/vision/{deepinsight => faceid/contrib}/vpl.cc (96%) rename csrcs/fastdeploy/vision/{deepinsight => faceid/contrib}/vpl.h (95%) create mode 100644 csrcs/fastdeploy/vision/faceid/contrib/vpl_pybind.cc create mode 100644 csrcs/fastdeploy/vision/faceid/faceid_pybind.cc rename csrcs/fastdeploy/vision/{zhkkke => matting/contrib}/modnet.cc (98%) rename csrcs/fastdeploy/vision/{zhkkke => matting/contrib}/modnet.h (96%) rename csrcs/fastdeploy/vision/{zhkkke/zhkkke_pybind.cc => matting/contrib/modnet_pybind.cc} (63%) create mode 100644 csrcs/fastdeploy/vision/matting/matting_pybind.cc delete mode 100644 csrcs/fastdeploy/vision/ultralytics/ultralytics_pybind.cc delete mode 100644 fastdeploy/vision/deepinsight/__init__.py create mode 100644 fastdeploy/vision/detection/contrib/__init__.py rename fastdeploy/vision/{rangilyu/__init__.py => detection/contrib/nanodet_plus.py} (96%) rename fastdeploy/vision/detection/{ => contrib}/scaled_yolov4.py (98%) rename fastdeploy/vision/detection/{ => contrib}/yolor.py (98%) rename fastdeploy/vision/{ultralytics/__init__.py => detection/contrib/yolov5.py} (97%) rename fastdeploy/vision/{ppogg/__init__.py => detection/contrib/yolov5lite.py} (97%) rename fastdeploy/vision/{meituan/__init__.py => detection/contrib/yolov6.py} (96%) rename fastdeploy/vision/detection/{ => contrib}/yolov7.py (98%) rename fastdeploy/vision/{megvii/__init__.py => detection/contrib/yolox.py} (93%) create mode 100644 fastdeploy/vision/facedet/__init__.py create mode 100644 fastdeploy/vision/facedet/contrib/__init__.py rename fastdeploy/vision/{biubug6/__init__.py => facedet/contrib/retinaface.py} (96%) create mode 100644 fastdeploy/vision/facedet/contrib/scrfd.py rename fastdeploy/vision/{linzaer/__init__.py => facedet/contrib/ultraface.py} (94%) rename fastdeploy/vision/{deepcam/__init__.py => facedet/contrib/yolov5face.py} (96%) create mode 100644 fastdeploy/vision/faceid/__init__.py create mode 100644 fastdeploy/vision/faceid/contrib/__init__.py create mode 100644 fastdeploy/vision/faceid/contrib/arcface.py create mode 100644 fastdeploy/vision/faceid/contrib/cosface.py create mode 100644 fastdeploy/vision/faceid/contrib/insightface_rec.py create mode 100644 fastdeploy/vision/faceid/contrib/partial_fc.py create mode 100644 fastdeploy/vision/faceid/contrib/vpl.py create mode 100644 fastdeploy/vision/matting/__init__.py create mode 100644 fastdeploy/vision/matting/contrib/__init__.py rename fastdeploy/vision/{zhkkke/__init__.py => matting/contrib/modnet.py} (96%) delete mode 100644 fastdeploy/vision/wongkinyiu/__init__.py diff --git a/csrcs/fastdeploy/vision.h b/csrcs/fastdeploy/vision.h index be1aa91a4a..21371b5a11 100644 --- a/csrcs/fastdeploy/vision.h +++ b/csrcs/fastdeploy/vision.h @@ -15,29 +15,27 @@ #include "fastdeploy/core/config.h" #ifdef ENABLE_VISION -#include "fastdeploy/vision/biubug6/retinaface.h" -#include "fastdeploy/vision/deepcam/yolov5face.h" -#include "fastdeploy/vision/deepinsight/arcface.h" -#include "fastdeploy/vision/deepinsight/cosface.h" -#include "fastdeploy/vision/deepinsight/insightface_rec.h" -#include "fastdeploy/vision/deepinsight/partial_fc.h" -#include "fastdeploy/vision/deepinsight/scrfd.h" -#include "fastdeploy/vision/deepinsight/vpl.h" - +#include "fastdeploy/vision/detection/contrib/nanodet_plus.h" #include "fastdeploy/vision/detection/contrib/scaledyolov4.h" #include "fastdeploy/vision/detection/contrib/yolor.h" +#include "fastdeploy/vision/detection/contrib/yolov5.h" +#include "fastdeploy/vision/detection/contrib/yolov5lite.h" +#include "fastdeploy/vision/detection/contrib/yolov6.h" #include "fastdeploy/vision/detection/contrib/yolov7.h" -#include "fastdeploy/vision/detection/ppdet/model.h" - -#include "fastdeploy/vision/linzaer/ultraface.h" -#include "fastdeploy/vision/megvii/yolox.h" -#include "fastdeploy/vision/meituan/yolov6.h" +#include "fastdeploy/vision/detection/contrib/yolox.h" +#include "fastdeploy/vision/facedet/contrib/retinaface.h" +#include "fastdeploy/vision/facedet/contrib/scrfd.h" +#include "fastdeploy/vision/facedet/contrib/ultraface.h" +#include "fastdeploy/vision/facedet/contrib/yolov5face.h" +#include "fastdeploy/vision/faceid/contrib/arcface.h" +#include "fastdeploy/vision/faceid/contrib/cosface.h" +#include "fastdeploy/vision/faceid/contrib/insightface_rec.h" +#include "fastdeploy/vision/faceid/contrib/partial_fc.h" +#include "fastdeploy/vision/faceid/contrib/vpl.h" +#include "fastdeploy/vision/matting/contrib/modnet.h" #include "fastdeploy/vision/ppcls/model.h" -#include "fastdeploy/vision/ppogg/yolov5lite.h" +#include "fastdeploy/vision/detection/ppdet/model.h" #include "fastdeploy/vision/ppseg/model.h" -#include "fastdeploy/vision/rangilyu/nanodet_plus.h" -#include "fastdeploy/vision/ultralytics/yolov5.h" -#include "fastdeploy/vision/zhkkke/modnet.h" #endif #include "fastdeploy/vision/visualize/visualize.h" diff --git a/csrcs/fastdeploy/vision/deepinsight/deepinsight_pybind.cc b/csrcs/fastdeploy/vision/deepinsight/deepinsight_pybind.cc deleted file mode 100644 index 76509079e7..0000000000 --- a/csrcs/fastdeploy/vision/deepinsight/deepinsight_pybind.cc +++ /dev/null @@ -1,144 +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/pybind/main.h" - -namespace fastdeploy { -void BindDeepInsight(pybind11::module& m) { - auto deepinsight_module = - m.def_submodule("deepinsight", "https://github.com/deepinsight"); - // Bind SCRFD - pybind11::class_( - deepinsight_module, "SCRFD") - .def(pybind11::init()) - .def("predict", - [](vision::deepinsight::SCRFD& self, pybind11::array& data, - float conf_threshold, float nms_iou_threshold) { - auto mat = PyArrayToCvMat(data); - vision::FaceDetectionResult res; - self.Predict(&mat, &res, conf_threshold, nms_iou_threshold); - return res; - }) - .def_readwrite("size", &vision::deepinsight::SCRFD::size) - .def_readwrite("padding_value", - &vision::deepinsight::SCRFD::padding_value) - .def_readwrite("is_mini_pad", &vision::deepinsight::SCRFD::is_mini_pad) - .def_readwrite("is_no_pad", &vision::deepinsight::SCRFD::is_no_pad) - .def_readwrite("is_scale_up", &vision::deepinsight::SCRFD::is_scale_up) - .def_readwrite("stride", &vision::deepinsight::SCRFD::stride) - .def_readwrite("use_kps", &vision::deepinsight::SCRFD::use_kps) - .def_readwrite("max_nms", &vision::deepinsight::SCRFD::max_nms) - .def_readwrite("downsample_strides", - &vision::deepinsight::SCRFD::downsample_strides) - .def_readwrite("num_anchors", &vision::deepinsight::SCRFD::num_anchors) - .def_readwrite("landmarks_per_face", - &vision::deepinsight::SCRFD::landmarks_per_face); - // Bind InsightFaceRecognitionModel - pybind11::class_(deepinsight_module, - "InsightFaceRecognitionModel") - .def(pybind11::init()) - .def("predict", - [](vision::deepinsight::InsightFaceRecognitionModel& self, - pybind11::array& data) { - auto mat = PyArrayToCvMat(data); - vision::FaceRecognitionResult res; - self.Predict(&mat, &res); - return res; - }) - .def_readwrite("size", - &vision::deepinsight::InsightFaceRecognitionModel::size) - .def_readwrite("alpha", - &vision::deepinsight::InsightFaceRecognitionModel::alpha) - .def_readwrite("beta", - &vision::deepinsight::InsightFaceRecognitionModel::beta) - .def_readwrite("swap_rb", - &vision::deepinsight::InsightFaceRecognitionModel::swap_rb) - .def_readwrite( - "l2_normalize", - &vision::deepinsight::InsightFaceRecognitionModel::l2_normalize); - // Bind ArcFace - pybind11::class_( - deepinsight_module, "ArcFace") - .def(pybind11::init()) - .def("predict", - [](vision::deepinsight::ArcFace& self, pybind11::array& data) { - auto mat = PyArrayToCvMat(data); - vision::FaceRecognitionResult res; - self.Predict(&mat, &res); - return res; - }) - .def_readwrite("size", &vision::deepinsight::ArcFace::size) - .def_readwrite("alpha", &vision::deepinsight::ArcFace::alpha) - .def_readwrite("beta", &vision::deepinsight::ArcFace::beta) - .def_readwrite("swap_rb", &vision::deepinsight::ArcFace::swap_rb) - .def_readwrite("l2_normalize", - &vision::deepinsight::ArcFace::l2_normalize); - // Bind CosFace - pybind11::class_( - deepinsight_module, "CosFace") - .def(pybind11::init()) - .def("predict", - [](vision::deepinsight::CosFace& self, pybind11::array& data) { - auto mat = PyArrayToCvMat(data); - vision::FaceRecognitionResult res; - self.Predict(&mat, &res); - return res; - }) - .def_readwrite("size", &vision::deepinsight::CosFace::size) - .def_readwrite("alpha", &vision::deepinsight::CosFace::alpha) - .def_readwrite("beta", &vision::deepinsight::CosFace::beta) - .def_readwrite("swap_rb", &vision::deepinsight::CosFace::swap_rb) - .def_readwrite("l2_normalize", - &vision::deepinsight::CosFace::l2_normalize); - // Bind Partial FC - pybind11::class_( - deepinsight_module, "PartialFC") - .def(pybind11::init()) - .def("predict", - [](vision::deepinsight::PartialFC& self, pybind11::array& data) { - auto mat = PyArrayToCvMat(data); - vision::FaceRecognitionResult res; - self.Predict(&mat, &res); - return res; - }) - .def_readwrite("size", &vision::deepinsight::PartialFC::size) - .def_readwrite("alpha", &vision::deepinsight::PartialFC::alpha) - .def_readwrite("beta", &vision::deepinsight::PartialFC::beta) - .def_readwrite("swap_rb", &vision::deepinsight::PartialFC::swap_rb) - .def_readwrite("l2_normalize", - &vision::deepinsight::PartialFC::l2_normalize); - // Bind VPL - pybind11::class_( - deepinsight_module, "VPL") - .def(pybind11::init()) - .def("predict", - [](vision::deepinsight::VPL& self, pybind11::array& data) { - auto mat = PyArrayToCvMat(data); - vision::FaceRecognitionResult res; - self.Predict(&mat, &res); - return res; - }) - .def_readwrite("size", &vision::deepinsight::VPL::size) - .def_readwrite("alpha", &vision::deepinsight::VPL::alpha) - .def_readwrite("beta", &vision::deepinsight::VPL::beta) - .def_readwrite("swap_rb", &vision::deepinsight::VPL::swap_rb) - .def_readwrite("l2_normalize", &vision::deepinsight::VPL::l2_normalize); -} - -} // namespace fastdeploy diff --git a/csrcs/fastdeploy/vision/rangilyu/nanodet_plus.cc b/csrcs/fastdeploy/vision/detection/contrib/nanodet_plus.cc similarity index 99% rename from csrcs/fastdeploy/vision/rangilyu/nanodet_plus.cc rename to csrcs/fastdeploy/vision/detection/contrib/nanodet_plus.cc index 678e131c41..267012c11e 100644 --- a/csrcs/fastdeploy/vision/rangilyu/nanodet_plus.cc +++ b/csrcs/fastdeploy/vision/detection/contrib/nanodet_plus.cc @@ -10,7 +10,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "fastdeploy/vision/rangilyu/nanodet_plus.h" +#include "fastdeploy/vision/detection/contrib/nanodet_plus.h" #include "fastdeploy/utils/perf.h" #include "fastdeploy/vision/utils/utils.h" @@ -18,7 +18,7 @@ namespace fastdeploy { namespace vision { -namespace rangilyu { +namespace detection { struct NanoDetPlusCenterPoint { int grid0; @@ -350,6 +350,6 @@ bool NanoDetPlus::Predict(cv::Mat* im, DetectionResult* result, return true; } -} // namespace rangilyu +} // namespace detection } // namespace vision } // namespace fastdeploy \ No newline at end of file diff --git a/csrcs/fastdeploy/vision/rangilyu/nanodet_plus.h b/csrcs/fastdeploy/vision/detection/contrib/nanodet_plus.h similarity index 97% rename from csrcs/fastdeploy/vision/rangilyu/nanodet_plus.h rename to csrcs/fastdeploy/vision/detection/contrib/nanodet_plus.h index 4184aa18e5..a407b87152 100644 --- a/csrcs/fastdeploy/vision/rangilyu/nanodet_plus.h +++ b/csrcs/fastdeploy/vision/detection/contrib/nanodet_plus.h @@ -22,7 +22,7 @@ namespace fastdeploy { namespace vision { -namespace rangilyu { +namespace detection { class FASTDEPLOY_DECL NanoDetPlus : public FastDeployModel { public: @@ -34,7 +34,7 @@ class FASTDEPLOY_DECL NanoDetPlus : public FastDeployModel { const Frontend& model_format = Frontend::ONNX); // 定义模型的名称 - std::string ModelName() const { return "RangiLyu/nanodet"; } + std::string ModelName() const { return "nanodet"; } // 模型预测接口,即用户调用的接口 // im 为用户的输入数据,目前对于CV均定义为cv::Mat @@ -96,6 +96,6 @@ class FASTDEPLOY_DECL NanoDetPlus : public FastDeployModel { bool is_dynamic_input_; }; -} // namespace rangilyu +} // namespace detection } // namespace vision } // namespace fastdeploy diff --git a/csrcs/fastdeploy/vision/megvii/megvii_pybind.cc b/csrcs/fastdeploy/vision/detection/contrib/nanodet_plus_pybind.cc similarity index 64% rename from csrcs/fastdeploy/vision/megvii/megvii_pybind.cc rename to csrcs/fastdeploy/vision/detection/contrib/nanodet_plus_pybind.cc index 7e7fbc79aa..b415c0b3b6 100644 --- a/csrcs/fastdeploy/vision/megvii/megvii_pybind.cc +++ b/csrcs/fastdeploy/vision/detection/contrib/nanodet_plus_pybind.cc @@ -15,27 +15,25 @@ #include "fastdeploy/pybind/main.h" namespace fastdeploy { -void BindMegvii(pybind11::module& m) { - auto megvii_module = - m.def_submodule("megvii", "https://github.com/megvii/YOLOX"); - pybind11::class_( - megvii_module, "YOLOX") +void BindNanoDetPlus(pybind11::module& m) { + pybind11::class_( + m, "NanoDetPlus") .def(pybind11::init()) .def("predict", - [](vision::megvii::YOLOX& self, pybind11::array& data, + [](vision::detection::NanoDetPlus& self, pybind11::array& data, float conf_threshold, float nms_iou_threshold) { auto mat = PyArrayToCvMat(data); vision::DetectionResult res; self.Predict(&mat, &res, conf_threshold, nms_iou_threshold); return res; }) - .def_readwrite("size", &vision::megvii::YOLOX::size) + .def_readwrite("size", &vision::detection::NanoDetPlus::size) .def_readwrite("padding_value", - &vision::megvii::YOLOX::padding_value) - .def_readwrite("is_decode_exported", - &vision::megvii::YOLOX::is_decode_exported) + &vision::detection::NanoDetPlus::padding_value) + .def_readwrite("keep_ratio", &vision::detection::NanoDetPlus::keep_ratio) .def_readwrite("downsample_strides", - &vision::megvii::YOLOX::downsample_strides) - .def_readwrite("max_wh", &vision::megvii::YOLOX::max_wh); + &vision::detection::NanoDetPlus::downsample_strides) + .def_readwrite("max_wh", &vision::detection::NanoDetPlus::max_wh) + .def_readwrite("reg_max", &vision::detection::NanoDetPlus::reg_max); } } // namespace fastdeploy diff --git a/csrcs/fastdeploy/vision/ultralytics/yolov5.cc b/csrcs/fastdeploy/vision/detection/contrib/yolov5.cc similarity index 97% rename from csrcs/fastdeploy/vision/ultralytics/yolov5.cc rename to csrcs/fastdeploy/vision/detection/contrib/yolov5.cc index 0b7e50e735..306051e806 100644 --- a/csrcs/fastdeploy/vision/ultralytics/yolov5.cc +++ b/csrcs/fastdeploy/vision/detection/contrib/yolov5.cc @@ -12,17 +12,17 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "fastdeploy/vision/ultralytics/yolov5.h" +#include "fastdeploy/vision/detection/contrib/yolov5.h" #include "fastdeploy/utils/perf.h" #include "fastdeploy/vision/utils/utils.h" namespace fastdeploy { namespace vision { -namespace ultralytics { +namespace detection { -void LetterBox(Mat* mat, std::vector size, std::vector color, - bool _auto, bool scale_fill = false, bool scale_up = true, - int stride = 32) { +void YOLOv5::LetterBox(Mat* mat, std::vector size, + std::vector color, bool _auto, bool scale_fill, + bool scale_up, int stride) { float scale = std::min(size[1] * 1.0 / mat->Height(), size[0] * 1.0 / mat->Width()); if (!scale_up) { @@ -204,9 +204,9 @@ bool YOLOv5::Postprocess( } if (result->boxes.size() == 0) { - return true; + return true; } - + utils::NMS(result, nms_iou_threshold); // scale the boxes to the origin image shape @@ -290,6 +290,6 @@ bool YOLOv5::Predict(cv::Mat* im, DetectionResult* result, float conf_threshold, return true; } -} // namespace ultralytics +} // namespace detection } // namespace vision } // namespace fastdeploy diff --git a/csrcs/fastdeploy/vision/ultralytics/yolov5.h b/csrcs/fastdeploy/vision/detection/contrib/yolov5.h similarity index 83% rename from csrcs/fastdeploy/vision/ultralytics/yolov5.h rename to csrcs/fastdeploy/vision/detection/contrib/yolov5.h index 573b0294f2..68c910d23a 100644 --- a/csrcs/fastdeploy/vision/ultralytics/yolov5.h +++ b/csrcs/fastdeploy/vision/detection/contrib/yolov5.h @@ -19,7 +19,7 @@ namespace fastdeploy { namespace vision { -namespace ultralytics { +namespace detection { class FASTDEPLOY_DECL YOLOv5 : public FastDeployModel { public: @@ -30,7 +30,7 @@ class FASTDEPLOY_DECL YOLOv5 : public FastDeployModel { const Frontend& model_format = Frontend::ONNX); // 定义模型的名称 - std::string ModelName() const { return "ultralytics/yolov5"; } + std::string ModelName() const { return "yolov5"; } // 模型预测接口,即用户调用的接口 // im 为用户的输入数据,目前对于CV均定义为cv::Mat @@ -39,7 +39,7 @@ class FASTDEPLOY_DECL YOLOv5 : public FastDeployModel { // nms_iou_threshold 为后处理的参数 virtual bool Predict(cv::Mat* im, DetectionResult* result, float conf_threshold = 0.25, - float nms_iou_threshold = 0.5); + float nms_iou_threshold = 0.5); // 以下为模型在预测时的一些参数,基本是前后处理所需 // 用户在创建模型后,可根据模型的要求,以及自己的需求 @@ -81,21 +81,28 @@ class FASTDEPLOY_DECL YOLOv5 : public FastDeployModel { // conf_threshold 后处理时过滤box的置信度阈值 // nms_iou_threshold 后处理时NMS设定的iou阈值 // multi_label 后处理时box选取是否采用多标签方式 - bool Postprocess( - FDTensor& infer_result, DetectionResult* result, - const std::map>& im_info, - float conf_threshold, float nms_iou_threshold, bool multi_label); + bool Postprocess(FDTensor& infer_result, DetectionResult* result, + const std::map>& im_info, + float conf_threshold, float nms_iou_threshold, + bool multi_label); // 查看输入是否为动态维度的 不建议直接使用 不同模型的逻辑可能不一致 - bool IsDynamicInput() const { return is_dynamic_input_; } + bool IsDynamicInput() const { return is_dynamic_input_; } - // whether to inference with dynamic shape (e.g ONNX export with dynamic shape or not.) - // YOLOv5 official 'export_onnx.py' script will export dynamic ONNX by default. - // while is_dynamic_shape if 'false', is_mini_pad will force 'false'. This value will - // auto check by fastdeploy after the internal Runtime already initialized. + void LetterBox(Mat* mat, std::vector size, std::vector color, + bool _auto, bool scale_fill = false, bool scale_up = true, + int stride = 32); + + // whether to inference with dynamic shape (e.g ONNX export with dynamic shape + // or not.) + // YOLOv5 official 'export_onnx.py' script will export dynamic ONNX by + // default. + // while is_dynamic_shape if 'false', is_mini_pad will force 'false'. This + // value will + // auto check by fastdeploy after the internal Runtime already initialized. bool is_dynamic_input_; }; -} // namespace ultralytics +} // namespace detection } // namespace vision } // namespace fastdeploy diff --git a/csrcs/fastdeploy/vision/meituan/meituan_pybind.cc b/csrcs/fastdeploy/vision/detection/contrib/yolov5_pybind.cc similarity index 57% rename from csrcs/fastdeploy/vision/meituan/meituan_pybind.cc rename to csrcs/fastdeploy/vision/detection/contrib/yolov5_pybind.cc index d1e81fa582..65ba538b89 100644 --- a/csrcs/fastdeploy/vision/meituan/meituan_pybind.cc +++ b/csrcs/fastdeploy/vision/detection/contrib/yolov5_pybind.cc @@ -15,27 +15,24 @@ #include "fastdeploy/pybind/main.h" namespace fastdeploy { -void BindMeituan(pybind11::module& m) { - auto meituan_module = - m.def_submodule("meituan", "https://github.com/meituan/YOLOv6"); - pybind11::class_( - meituan_module, "YOLOv6") +void BindYOLOv5(pybind11::module& m) { + pybind11::class_(m, "YOLOv5") .def(pybind11::init()) .def("predict", - [](vision::meituan::YOLOv6& self, pybind11::array& data, + [](vision::detection::YOLOv5& self, pybind11::array& data, float conf_threshold, float nms_iou_threshold) { auto mat = PyArrayToCvMat(data); vision::DetectionResult res; self.Predict(&mat, &res, conf_threshold, nms_iou_threshold); return res; }) - .def_readwrite("size", &vision::meituan::YOLOv6::size) - .def_readwrite("padding_value", - &vision::meituan::YOLOv6::padding_value) - .def_readwrite("is_mini_pad", &vision::meituan::YOLOv6::is_mini_pad) - .def_readwrite("is_no_pad", &vision::meituan::YOLOv6::is_no_pad) - .def_readwrite("is_scale_up", &vision::meituan::YOLOv6::is_scale_up) - .def_readwrite("stride", &vision::meituan::YOLOv6::stride) - .def_readwrite("max_wh", &vision::meituan::YOLOv6::max_wh); + .def_readwrite("size", &vision::detection::YOLOv5::size) + .def_readwrite("padding_value", &vision::detection::YOLOv5::padding_value) + .def_readwrite("is_mini_pad", &vision::detection::YOLOv5::is_mini_pad) + .def_readwrite("is_no_pad", &vision::detection::YOLOv5::is_no_pad) + .def_readwrite("is_scale_up", &vision::detection::YOLOv5::is_scale_up) + .def_readwrite("stride", &vision::detection::YOLOv5::stride) + .def_readwrite("max_wh", &vision::detection::YOLOv5::max_wh) + .def_readwrite("multi_label", &vision::detection::YOLOv5::multi_label); } } // namespace fastdeploy diff --git a/csrcs/fastdeploy/vision/ppogg/yolov5lite.cc b/csrcs/fastdeploy/vision/detection/contrib/yolov5lite.cc similarity index 99% rename from csrcs/fastdeploy/vision/ppogg/yolov5lite.cc rename to csrcs/fastdeploy/vision/detection/contrib/yolov5lite.cc index a07d896a45..26ca15f1e3 100644 --- a/csrcs/fastdeploy/vision/ppogg/yolov5lite.cc +++ b/csrcs/fastdeploy/vision/detection/contrib/yolov5lite.cc @@ -12,13 +12,13 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "fastdeploy/vision/ppogg/yolov5lite.h" +#include "fastdeploy/vision/detection/contrib/yolov5lite.h" #include "fastdeploy/utils/perf.h" #include "fastdeploy/vision/utils/utils.h" namespace fastdeploy { namespace vision { -namespace ppogg { +namespace detection { void YOLOv5Lite::LetterBox(Mat* mat, const std::vector& size, const std::vector& color, bool _auto, @@ -191,7 +191,6 @@ bool YOLOv5Lite::PostprocessWithDecode( std::vector anchors; int num_anchors = anchor_config[0].size() / 2; GenerateAnchors(size, downsample_strides, &anchors, num_anchors); - // infer_result shape might look like (1,n,85=5+80) float* data = static_cast(infer_result.Data()); for (size_t i = 0; i < infer_result.shape[1]; ++i) { @@ -395,6 +394,6 @@ bool YOLOv5Lite::Predict(cv::Mat* im, DetectionResult* result, return true; } -} // namespace ppogg +} // namespace detection } // namespace vision } // namespace fastdeploy diff --git a/csrcs/fastdeploy/vision/ppogg/yolov5lite.h b/csrcs/fastdeploy/vision/detection/contrib/yolov5lite.h similarity index 98% rename from csrcs/fastdeploy/vision/ppogg/yolov5lite.h rename to csrcs/fastdeploy/vision/detection/contrib/yolov5lite.h index 77209e7ae9..2add202f4d 100644 --- a/csrcs/fastdeploy/vision/ppogg/yolov5lite.h +++ b/csrcs/fastdeploy/vision/detection/contrib/yolov5lite.h @@ -19,7 +19,7 @@ namespace fastdeploy { namespace vision { -namespace ppogg { +namespace detection { class FASTDEPLOY_DECL YOLOv5Lite : public FastDeployModel { public: @@ -30,8 +30,7 @@ class FASTDEPLOY_DECL YOLOv5Lite : public FastDeployModel { const Frontend& model_format = Frontend::ONNX); // 定义模型的名称 - virtual std::string ModelName() const { return "ppogg/YOLOv5-Lite"; } - + virtual std::string ModelName() const { return "YOLOv5-Lite"; } // 模型预测接口,即用户调用的接口 // im 为用户的输入数据,目前对于CV均定义为cv::Mat // result 为模型预测的输出结构体 @@ -134,6 +133,6 @@ class FASTDEPLOY_DECL YOLOv5Lite : public FastDeployModel { // auto check by fastdeploy after the internal Runtime already initialized. bool is_dynamic_input_; }; -} // namespace ppogg +} // namespace detection } // namespace vision } // namespace fastdeploy diff --git a/csrcs/fastdeploy/vision/ppogg/ppogg_pybind.cc b/csrcs/fastdeploy/vision/detection/contrib/yolov5lite_pybind.cc similarity index 52% rename from csrcs/fastdeploy/vision/ppogg/ppogg_pybind.cc rename to csrcs/fastdeploy/vision/detection/contrib/yolov5lite_pybind.cc index 606737ae11..dd064e3bec 100644 --- a/csrcs/fastdeploy/vision/ppogg/ppogg_pybind.cc +++ b/csrcs/fastdeploy/vision/detection/contrib/yolov5lite_pybind.cc @@ -15,29 +15,29 @@ #include "fastdeploy/pybind/main.h" namespace fastdeploy { -void BindPpogg(pybind11::module& m) { - auto ppogg_module = - m.def_submodule("ppogg", "https://github.com/ppogg/YOLOv5-Lite"); - pybind11::class_(ppogg_module, - "YOLOv5Lite") +void BindYOLOv5Lite(pybind11::module& m) { + pybind11::class_(m, + "YOLOv5Lite") .def(pybind11::init()) .def("predict", - [](vision::ppogg::YOLOv5Lite& self, pybind11::array& data, + [](vision::detection::YOLOv5Lite& self, pybind11::array& data, float conf_threshold, float nms_iou_threshold) { auto mat = PyArrayToCvMat(data); vision::DetectionResult res; self.Predict(&mat, &res, conf_threshold, nms_iou_threshold); return res; }) - .def_readwrite("size", &vision::ppogg::YOLOv5Lite::size) - .def_readwrite("padding_value", &vision::ppogg::YOLOv5Lite::padding_value) - .def_readwrite("is_mini_pad", &vision::ppogg::YOLOv5Lite::is_mini_pad) - .def_readwrite("is_no_pad", &vision::ppogg::YOLOv5Lite::is_no_pad) - .def_readwrite("is_scale_up", &vision::ppogg::YOLOv5Lite::is_scale_up) - .def_readwrite("stride", &vision::ppogg::YOLOv5Lite::stride) - .def_readwrite("max_wh", &vision::ppogg::YOLOv5Lite::max_wh) - .def_readwrite("anchor_config", &vision::ppogg::YOLOv5Lite::anchor_config) + .def_readwrite("size", &vision::detection::YOLOv5Lite::size) + .def_readwrite("padding_value", + &vision::detection::YOLOv5Lite::padding_value) + .def_readwrite("is_mini_pad", &vision::detection::YOLOv5Lite::is_mini_pad) + .def_readwrite("is_no_pad", &vision::detection::YOLOv5Lite::is_no_pad) + .def_readwrite("is_scale_up", &vision::detection::YOLOv5Lite::is_scale_up) + .def_readwrite("stride", &vision::detection::YOLOv5Lite::stride) + .def_readwrite("max_wh", &vision::detection::YOLOv5Lite::max_wh) + .def_readwrite("anchor_config", + &vision::detection::YOLOv5Lite::anchor_config) .def_readwrite("is_decode_exported", - &vision::ppogg::YOLOv5Lite::is_decode_exported); + &vision::detection::YOLOv5Lite::is_decode_exported); } } // namespace fastdeploy diff --git a/csrcs/fastdeploy/vision/meituan/yolov6.cc b/csrcs/fastdeploy/vision/detection/contrib/yolov6.cc similarity index 97% rename from csrcs/fastdeploy/vision/meituan/yolov6.cc rename to csrcs/fastdeploy/vision/detection/contrib/yolov6.cc index 8ac7377194..7c68274333 100644 --- a/csrcs/fastdeploy/vision/meituan/yolov6.cc +++ b/csrcs/fastdeploy/vision/detection/contrib/yolov6.cc @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "fastdeploy/vision/meituan/yolov6.h" +#include "fastdeploy/vision/detection/contrib/yolov6.h" #include "fastdeploy/utils/perf.h" #include "fastdeploy/vision/utils/utils.h" @@ -20,11 +20,11 @@ namespace fastdeploy { namespace vision { -namespace meituan { +namespace detection { -void LetterBox(Mat* mat, std::vector size, std::vector color, - bool _auto, bool scale_fill = false, bool scale_up = true, - int stride = 32) { +void YOLOv6::LetterBox(Mat* mat, std::vector size, + std::vector color, bool _auto, bool scale_fill, + bool scale_up, int stride) { float scale = std::min(size[1] * 1.0f / static_cast(mat->Height()), size[0] * 1.0f / static_cast(mat->Width())); if (!scale_up) { @@ -262,6 +262,6 @@ bool YOLOv6::Predict(cv::Mat* im, DetectionResult* result, float conf_threshold, return true; } -} // namespace meituan +} // namespace detection } // namespace vision } // namespace fastdeploy \ No newline at end of file diff --git a/csrcs/fastdeploy/vision/meituan/yolov6.h b/csrcs/fastdeploy/vision/detection/contrib/yolov6.h similarity index 83% rename from csrcs/fastdeploy/vision/meituan/yolov6.h rename to csrcs/fastdeploy/vision/detection/contrib/yolov6.h index b2d6a062df..64af6e2ebf 100644 --- a/csrcs/fastdeploy/vision/meituan/yolov6.h +++ b/csrcs/fastdeploy/vision/detection/contrib/yolov6.h @@ -22,7 +22,7 @@ namespace fastdeploy { namespace vision { -namespace meituan { +namespace detection { class FASTDEPLOY_DECL YOLOv6 : public FastDeployModel { public: @@ -33,7 +33,7 @@ class FASTDEPLOY_DECL YOLOv6 : public FastDeployModel { const Frontend& model_format = Frontend::ONNX); // 定义模型的名称 - std::string ModelName() const { return "meituan/YOLOv6"; } + std::string ModelName() const { return "YOLOv6"; } // 模型预测接口,即用户调用的接口 // im 为用户的输入数据,目前对于CV均定义为cv::Mat @@ -61,7 +61,8 @@ class FASTDEPLOY_DECL YOLOv6 : public FastDeployModel { bool is_scale_up; // padding stride, for is_mini_pad int stride; - // for offseting the boxes by classes when using NMS, default 4096 in meituan/YOLOv6 + // for offseting the boxes by classes when using NMS, default 4096 in + // meituan/YOLOv6 float max_wh; private: @@ -81,21 +82,27 @@ class FASTDEPLOY_DECL YOLOv6 : public FastDeployModel { // im_info 为预处理记录的信息,后处理用于还原box // conf_threshold 后处理时过滤box的置信度阈值 // nms_iou_threshold 后处理时NMS设定的iou阈值 - bool Postprocess( - FDTensor& infer_result, DetectionResult* result, - const std::map>& im_info, - float conf_threshold, float nms_iou_threshold); + bool Postprocess(FDTensor& infer_result, DetectionResult* result, + const std::map>& im_info, + float conf_threshold, float nms_iou_threshold); // 查看输入是否为动态维度的 不建议直接使用 不同模型的逻辑可能不一致 - bool IsDynamicInput() const { return is_dynamic_input_; } + bool IsDynamicInput() const { return is_dynamic_input_; } - // whether to inference with dynamic shape (e.g ONNX export with dynamic shape or not.) - // meituan/YOLOv6 official 'export_onnx.py' script will export static ONNX by default. - // while is_dynamic_input if 'false', is_mini_pad will force 'false'. This value will - // auto check by fastdeploy after the internal Runtime already initialized. + void LetterBox(Mat* mat, std::vector size, std::vector color, + bool _auto, bool scale_fill = false, bool scale_up = true, + int stride = 32); + + // whether to inference with dynamic shape (e.g ONNX export with dynamic shape + // or not.) + // meituan/YOLOv6 official 'export_onnx.py' script will export static ONNX by + // default. + // while is_dynamic_input if 'false', is_mini_pad will force 'false'. This + // value will + // auto check by fastdeploy after the internal Runtime already initialized. bool is_dynamic_input_; }; -} // namespace meituan +} // namespace detection } // namespace vision -} // namespace fastdeploy \ No newline at end of file +} // namespace fastdeploy diff --git a/csrcs/fastdeploy/vision/detection/contrib/yolov6_pybind.cc b/csrcs/fastdeploy/vision/detection/contrib/yolov6_pybind.cc new file mode 100644 index 0000000000..a1d0131df8 --- /dev/null +++ b/csrcs/fastdeploy/vision/detection/contrib/yolov6_pybind.cc @@ -0,0 +1,37 @@ +// 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 BindYOLOv6(pybind11::module& m) { + pybind11::class_(m, "YOLOv6") + .def(pybind11::init()) + .def("predict", + [](vision::detection::YOLOv6& self, pybind11::array& data, + float conf_threshold, float nms_iou_threshold) { + auto mat = PyArrayToCvMat(data); + vision::DetectionResult res; + self.Predict(&mat, &res, conf_threshold, nms_iou_threshold); + return res; + }) + .def_readwrite("size", &vision::detection::YOLOv6::size) + .def_readwrite("padding_value", &vision::detection::YOLOv6::padding_value) + .def_readwrite("is_mini_pad", &vision::detection::YOLOv6::is_mini_pad) + .def_readwrite("is_no_pad", &vision::detection::YOLOv6::is_no_pad) + .def_readwrite("is_scale_up", &vision::detection::YOLOv6::is_scale_up) + .def_readwrite("stride", &vision::detection::YOLOv6::stride) + .def_readwrite("max_wh", &vision::detection::YOLOv6::max_wh); +} +} // namespace fastdeploy diff --git a/csrcs/fastdeploy/vision/megvii/yolox.cc b/csrcs/fastdeploy/vision/detection/contrib/yolox.cc similarity index 98% rename from csrcs/fastdeploy/vision/megvii/yolox.cc rename to csrcs/fastdeploy/vision/detection/contrib/yolox.cc index f2cb5d1c34..5d38806572 100644 --- a/csrcs/fastdeploy/vision/megvii/yolox.cc +++ b/csrcs/fastdeploy/vision/detection/contrib/yolox.cc @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "fastdeploy/vision/megvii/yolox.h" +#include "fastdeploy/vision/detection/contrib/yolox.h" #include "fastdeploy/utils/perf.h" #include "fastdeploy/vision/utils/utils.h" @@ -20,7 +20,7 @@ namespace fastdeploy { namespace vision { -namespace megvii { +namespace detection { struct YOLOXAnchor { int grid0; @@ -334,6 +334,6 @@ bool YOLOX::Predict(cv::Mat* im, DetectionResult* result, float conf_threshold, return true; } -} // namespace megvii +} // namespace detection } // namespace vision -} // namespace fastdeploy \ No newline at end of file +} // namespace fastdeploy diff --git a/csrcs/fastdeploy/vision/megvii/yolox.h b/csrcs/fastdeploy/vision/detection/contrib/yolox.h similarity index 88% rename from csrcs/fastdeploy/vision/megvii/yolox.h rename to csrcs/fastdeploy/vision/detection/contrib/yolox.h index 7ff8edcf00..fc27ca1ede 100644 --- a/csrcs/fastdeploy/vision/megvii/yolox.h +++ b/csrcs/fastdeploy/vision/detection/contrib/yolox.h @@ -22,7 +22,7 @@ namespace fastdeploy { namespace vision { -namespace megvii { +namespace detection { class FASTDEPLOY_DECL YOLOX : public FastDeployModel { public: @@ -33,7 +33,7 @@ class FASTDEPLOY_DECL YOLOX : public FastDeployModel { const Frontend& model_format = Frontend::ONNX); // 定义模型的名称 - std::string ModelName() const { return "megvii/YOLOX"; } + std::string ModelName() const { return "YOLOX"; } // 模型预测接口,即用户调用的接口 // im 为用户的输入数据,目前对于CV均定义为cv::Mat @@ -52,11 +52,11 @@ class FASTDEPLOY_DECL YOLOX : public FastDeployModel { // padding value, size should be same with Channels std::vector padding_value; // whether the model_file was exported with decode module. The official - // YOLOX/tools/export_onnx.py script will export ONNX file without - // decode module. Please set it 'true' manually if the model file + // YOLOX/tools/export_onnx.py script will export ONNX file without + // decode module. Please set it 'true' manually if the model file // was exported with decode module. bool is_decode_exported; - // downsample strides for YOLOX to generate anchors, will take + // downsample strides for YOLOX to generate anchors, will take // (8,16,32) as default values, might have stride=64. std::vector downsample_strides; // for offseting the boxes by classes when using NMS, default 4096. @@ -79,27 +79,29 @@ class FASTDEPLOY_DECL YOLOX : public FastDeployModel { // im_info 为预处理记录的信息,后处理用于还原box // conf_threshold 后处理时过滤box的置信度阈值 // nms_iou_threshold 后处理时NMS设定的iou阈值 - bool Postprocess( - FDTensor& infer_result, DetectionResult* result, - const std::map>& im_info, - float conf_threshold, float nms_iou_threshold); + bool Postprocess(FDTensor& infer_result, DetectionResult* result, + const std::map>& im_info, + float conf_threshold, float nms_iou_threshold); // YOLOX的官方脚本默认导出不带decode模块的模型文件 需要在后处理进行decode bool PostprocessWithDecode( FDTensor& infer_result, DetectionResult* result, const std::map>& im_info, - float conf_threshold, float nms_iou_threshold); + float conf_threshold, float nms_iou_threshold); // 查看输入是否为动态维度的 不建议直接使用 不同模型的逻辑可能不一致 - bool IsDynamicInput() const { return is_dynamic_input_; } - - // whether to inference with dynamic shape (e.g ONNX export with dynamic shape or not.) - // megvii/YOLOX official 'export_onnx.py' script will export static ONNX by default. - // while is_dynamic_shape if 'false', is_mini_pad will force 'false'. This value will - // auto check by fastdeploy after the internal Runtime already initialized. - bool is_dynamic_input_; + bool IsDynamicInput() const { return is_dynamic_input_; } + + // whether to inference with dynamic shape (e.g ONNX export with dynamic shape + // or not.) + // megvii/YOLOX official 'export_onnx.py' script will export static ONNX by + // default. + // while is_dynamic_shape if 'false', is_mini_pad will force 'false'. This + // value will + // auto check by fastdeploy after the internal Runtime already initialized. + bool is_dynamic_input_; }; -} // namespace megvii +} // namespace detection } // namespace vision } // namespace fastdeploy diff --git a/csrcs/fastdeploy/vision/rangilyu/rangilyu_pybind.cc b/csrcs/fastdeploy/vision/detection/contrib/yolox_pybind.cc similarity index 58% rename from csrcs/fastdeploy/vision/rangilyu/rangilyu_pybind.cc rename to csrcs/fastdeploy/vision/detection/contrib/yolox_pybind.cc index 70bde60057..68cb6a4266 100644 --- a/csrcs/fastdeploy/vision/rangilyu/rangilyu_pybind.cc +++ b/csrcs/fastdeploy/vision/detection/contrib/yolox_pybind.cc @@ -15,27 +15,23 @@ #include "fastdeploy/pybind/main.h" namespace fastdeploy { -void BindRangiLyu(pybind11::module& m) { - auto rangilyu_module = - m.def_submodule("rangilyu", "https://github.com/RangiLyu/nanodet"); - pybind11::class_( - rangilyu_module, "NanoDetPlus") +void BindYOLOX(pybind11::module& m) { + pybind11::class_(m, "YOLOX") .def(pybind11::init()) .def("predict", - [](vision::rangilyu::NanoDetPlus& self, pybind11::array& data, + [](vision::detection::YOLOX& self, pybind11::array& data, float conf_threshold, float nms_iou_threshold) { auto mat = PyArrayToCvMat(data); vision::DetectionResult res; self.Predict(&mat, &res, conf_threshold, nms_iou_threshold); return res; }) - .def_readwrite("size", &vision::rangilyu::NanoDetPlus::size) - .def_readwrite("padding_value", - &vision::rangilyu::NanoDetPlus::padding_value) - .def_readwrite("keep_ratio", &vision::rangilyu::NanoDetPlus::keep_ratio) + .def_readwrite("size", &vision::detection::YOLOX::size) + .def_readwrite("padding_value", &vision::detection::YOLOX::padding_value) + .def_readwrite("is_decode_exported", + &vision::detection::YOLOX::is_decode_exported) .def_readwrite("downsample_strides", - &vision::rangilyu::NanoDetPlus::downsample_strides) - .def_readwrite("max_wh", &vision::rangilyu::NanoDetPlus::max_wh) - .def_readwrite("reg_max", &vision::rangilyu::NanoDetPlus::reg_max); + &vision::detection::YOLOX::downsample_strides) + .def_readwrite("max_wh", &vision::detection::YOLOX::max_wh); } } // namespace fastdeploy diff --git a/csrcs/fastdeploy/vision/detection/detection_pybind.cc b/csrcs/fastdeploy/vision/detection/detection_pybind.cc index 4516e4717a..a865dc11e0 100644 --- a/csrcs/fastdeploy/vision/detection/detection_pybind.cc +++ b/csrcs/fastdeploy/vision/detection/detection_pybind.cc @@ -19,6 +19,11 @@ namespace fastdeploy { void BindYOLOv7(pybind11::module& m); void BindScaledYOLOv4(pybind11::module& m); void BindYOLOR(pybind11::module& m); +void BindYOLOv6(pybind11::module& m); +void BindYOLOv5Lite(pybind11::module& m); +void BindYOLOv5(pybind11::module& m); +void BindYOLOX(pybind11::module& m); +void BindNanoDetPlus(pybind11::module& m); void BindPPDet(pybind11::module& m); void BindDetection(pybind11::module& m) { @@ -28,5 +33,10 @@ void BindDetection(pybind11::module& m) { BindYOLOv7(detection_module); BindScaledYOLOv4(detection_module); BindYOLOR(detection_module); + BindYOLOv6(detection_module); + BindYOLOv5Lite(detection_module); + BindYOLOv5(detection_module); + BindYOLOX(detection_module); + BindNanoDetPlus(detection_module); } } // namespace fastdeploy diff --git a/csrcs/fastdeploy/vision/biubug6/retinaface.cc b/csrcs/fastdeploy/vision/facedet/contrib/retinaface.cc similarity index 99% rename from csrcs/fastdeploy/vision/biubug6/retinaface.cc rename to csrcs/fastdeploy/vision/facedet/contrib/retinaface.cc index 2ba1a788e9..ebb52010e1 100644 --- a/csrcs/fastdeploy/vision/biubug6/retinaface.cc +++ b/csrcs/fastdeploy/vision/facedet/contrib/retinaface.cc @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "fastdeploy/vision/biubug6/retinaface.h" +#include "fastdeploy/vision/facedet/contrib/retinaface.h" #include "fastdeploy/utils/perf.h" #include "fastdeploy/vision/utils/utils.h" @@ -20,7 +20,7 @@ namespace fastdeploy { namespace vision { -namespace biubug6 { +namespace facedet { struct RetinaAnchor { float cx; @@ -305,6 +305,6 @@ bool RetinaFace::Predict(cv::Mat* im, FaceDetectionResult* result, return true; } -} // namespace biubug6 +} // namespace facedet } // namespace vision } // namespace fastdeploy \ No newline at end of file diff --git a/csrcs/fastdeploy/vision/biubug6/retinaface.h b/csrcs/fastdeploy/vision/facedet/contrib/retinaface.h similarity index 96% rename from csrcs/fastdeploy/vision/biubug6/retinaface.h rename to csrcs/fastdeploy/vision/facedet/contrib/retinaface.h index d16942f13b..e1ef50e2ec 100644 --- a/csrcs/fastdeploy/vision/biubug6/retinaface.h +++ b/csrcs/fastdeploy/vision/facedet/contrib/retinaface.h @@ -21,7 +21,7 @@ namespace fastdeploy { namespace vision { -namespace biubug6 { +namespace facedet { class FASTDEPLOY_DECL RetinaFace : public FastDeployModel { public: @@ -32,7 +32,7 @@ class FASTDEPLOY_DECL RetinaFace : public FastDeployModel { const Frontend& model_format = Frontend::ONNX); // 定义模型的名称 - std::string ModelName() const { return "biubug6/Pytorch_Retinaface"; } + std::string ModelName() const { return "Pytorch_Retinaface"; } // 模型预测接口,即用户调用的接口 // im 为用户的输入数据,目前对于CV均定义为cv::Mat @@ -87,6 +87,6 @@ class FASTDEPLOY_DECL RetinaFace : public FastDeployModel { bool is_dynamic_input_; }; -} // namespace biubug6 +} // namespace facedet } // namespace vision } // namespace fastdeploy diff --git a/csrcs/fastdeploy/vision/biubug6/biubug6_pybind.cc b/csrcs/fastdeploy/vision/facedet/contrib/retinaface_pybind.cc similarity index 67% rename from csrcs/fastdeploy/vision/biubug6/biubug6_pybind.cc rename to csrcs/fastdeploy/vision/facedet/contrib/retinaface_pybind.cc index 78208280ac..9419327c47 100644 --- a/csrcs/fastdeploy/vision/biubug6/biubug6_pybind.cc +++ b/csrcs/fastdeploy/vision/facedet/contrib/retinaface_pybind.cc @@ -15,26 +15,24 @@ #include "fastdeploy/pybind/main.h" namespace fastdeploy { -void BindBiubug6(pybind11::module& m) { - auto biubug6_module = m.def_submodule( - "biubug6", "https://github.com/biubug6/Pytorch_Retinaface"); - pybind11::class_(biubug6_module, +void BindRetinaFace(pybind11::module& m) { + pybind11::class_(m, "RetinaFace") .def(pybind11::init()) .def("predict", - [](vision::biubug6::RetinaFace& self, pybind11::array& data, + [](vision::facedet::RetinaFace& self, pybind11::array& data, float conf_threshold, float nms_iou_threshold) { auto mat = PyArrayToCvMat(data); vision::FaceDetectionResult res; self.Predict(&mat, &res, conf_threshold, nms_iou_threshold); return res; }) - .def_readwrite("size", &vision::biubug6::RetinaFace::size) - .def_readwrite("variance", &vision::biubug6::RetinaFace::variance) + .def_readwrite("size", &vision::facedet::RetinaFace::size) + .def_readwrite("variance", &vision::facedet::RetinaFace::variance) .def_readwrite("downsample_strides", - &vision::biubug6::RetinaFace::downsample_strides) - .def_readwrite("min_sizes", &vision::biubug6::RetinaFace::min_sizes) + &vision::facedet::RetinaFace::downsample_strides) + .def_readwrite("min_sizes", &vision::facedet::RetinaFace::min_sizes) .def_readwrite("landmarks_per_face", - &vision::biubug6::RetinaFace::landmarks_per_face); + &vision::facedet::RetinaFace::landmarks_per_face); } } // namespace fastdeploy diff --git a/csrcs/fastdeploy/vision/deepinsight/scrfd.cc b/csrcs/fastdeploy/vision/facedet/contrib/scrfd.cc similarity index 93% rename from csrcs/fastdeploy/vision/deepinsight/scrfd.cc rename to csrcs/fastdeploy/vision/facedet/contrib/scrfd.cc index d86331fbee..ffcff65c9a 100644 --- a/csrcs/fastdeploy/vision/deepinsight/scrfd.cc +++ b/csrcs/fastdeploy/vision/facedet/contrib/scrfd.cc @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "fastdeploy/vision/deepinsight/scrfd.h" +#include "fastdeploy/vision/facedet/contrib/scrfd.h" #include "fastdeploy/utils/perf.h" #include "fastdeploy/vision/utils/utils.h" @@ -20,7 +20,7 @@ namespace fastdeploy { namespace vision { -namespace deepinsight { +namespace facedet { void SCRFD::LetterBox(Mat* mat, const std::vector& size, const std::vector& color, bool _auto, @@ -246,14 +246,18 @@ bool SCRFD::Postprocess( float r = offsets[2]; // right float b = offsets[3]; // bottom - float x1 = - ((cx - l) * static_cast(current_stride) - static_cast(pad_w)) / scale; // cx - l x1 - float y1 = - ((cy - t) * static_cast(current_stride) - static_cast(pad_h)) / scale; // cy - t y1 - float x2 = - ((cx + r) * static_cast(current_stride) - static_cast(pad_w)) / scale; // cx + r x2 - float y2 = - ((cy + b) * static_cast(current_stride) - static_cast(pad_h)) / scale; // cy + b y2 + float x1 = ((cx - l) * static_cast(current_stride) - + static_cast(pad_w)) / + scale; // cx - l x1 + float y1 = ((cy - t) * static_cast(current_stride) - + static_cast(pad_h)) / + scale; // cy - t y1 + float x2 = ((cx + r) * static_cast(current_stride) - + static_cast(pad_w)) / + scale; // cx + r x2 + float y2 = ((cy + b) * static_cast(current_stride) - + static_cast(pad_h)) / + scale; // cy + b y2 result->boxes.emplace_back(std::array{x1, y1, x2, y2}); result->scores.push_back(cls_conf); if (use_kps) { @@ -264,9 +268,11 @@ bool SCRFD::Postprocess( for (unsigned int j = 0; j < landmarks_per_face * 2; j += 2) { float kps_l = kps_offsets[j]; float kps_t = kps_offsets[j + 1]; - float kps_x = ((cx + kps_l) * static_cast(current_stride) - static_cast(pad_w)) / + float kps_x = ((cx + kps_l) * static_cast(current_stride) - + static_cast(pad_w)) / scale; // cx + l x - float kps_y = ((cy + kps_t) * static_cast(current_stride) - static_cast(pad_h)) / + float kps_y = ((cy + kps_t) * static_cast(current_stride) - + static_cast(pad_h)) / scale; // cy + t y result->landmarks.emplace_back(std::array{kps_x, kps_y}); } @@ -358,6 +364,6 @@ bool SCRFD::Predict(cv::Mat* im, FaceDetectionResult* result, return true; } -} // namespace deepinsight +} // namespace facedet } // namespace vision } // namespace fastdeploy \ No newline at end of file diff --git a/csrcs/fastdeploy/vision/deepinsight/scrfd.h b/csrcs/fastdeploy/vision/facedet/contrib/scrfd.h similarity index 97% rename from csrcs/fastdeploy/vision/deepinsight/scrfd.h rename to csrcs/fastdeploy/vision/facedet/contrib/scrfd.h index a84eab5f11..3983013634 100644 --- a/csrcs/fastdeploy/vision/deepinsight/scrfd.h +++ b/csrcs/fastdeploy/vision/facedet/contrib/scrfd.h @@ -22,7 +22,7 @@ namespace fastdeploy { namespace vision { -namespace deepinsight { +namespace facedet { class FASTDEPLOY_DECL SCRFD : public FastDeployModel { public: @@ -33,7 +33,7 @@ class FASTDEPLOY_DECL SCRFD : public FastDeployModel { const Frontend& model_format = Frontend::ONNX); // 定义模型的名称 - std::string ModelName() const { return "deepinsight/scrfd"; } + std::string ModelName() const { return "scrfd"; } // 模型预测接口,即用户调用的接口 // im 为用户的输入数据,目前对于CV均定义为cv::Mat @@ -117,6 +117,6 @@ class FASTDEPLOY_DECL SCRFD : public FastDeployModel { std::unordered_map> center_points_; }; -} // namespace deepinsight +} // namespace facedet } // namespace vision } // namespace fastdeploy diff --git a/csrcs/fastdeploy/vision/facedet/contrib/scrfd_pybind.cc b/csrcs/fastdeploy/vision/facedet/contrib/scrfd_pybind.cc new file mode 100644 index 0000000000..7cfa4d0250 --- /dev/null +++ b/csrcs/fastdeploy/vision/facedet/contrib/scrfd_pybind.cc @@ -0,0 +1,45 @@ +// 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 BindSCRFD(pybind11::module& m) { + // Bind SCRFD + pybind11::class_(m, "SCRFD") + .def(pybind11::init()) + .def("predict", + [](vision::facedet::SCRFD& self, pybind11::array& data, + float conf_threshold, float nms_iou_threshold) { + auto mat = PyArrayToCvMat(data); + vision::FaceDetectionResult res; + self.Predict(&mat, &res, conf_threshold, nms_iou_threshold); + return res; + }) + .def_readwrite("size", &vision::facedet::SCRFD::size) + .def_readwrite("padding_value", &vision::facedet::SCRFD::padding_value) + .def_readwrite("is_mini_pad", &vision::facedet::SCRFD::is_mini_pad) + .def_readwrite("is_no_pad", &vision::facedet::SCRFD::is_no_pad) + .def_readwrite("is_scale_up", &vision::facedet::SCRFD::is_scale_up) + .def_readwrite("stride", &vision::facedet::SCRFD::stride) + .def_readwrite("use_kps", &vision::facedet::SCRFD::use_kps) + .def_readwrite("max_nms", &vision::facedet::SCRFD::max_nms) + .def_readwrite("downsample_strides", + &vision::facedet::SCRFD::downsample_strides) + .def_readwrite("num_anchors", &vision::facedet::SCRFD::num_anchors) + .def_readwrite("landmarks_per_face", + &vision::facedet::SCRFD::landmarks_per_face); +} + +} // namespace fastdeploy diff --git a/csrcs/fastdeploy/vision/linzaer/ultraface.cc b/csrcs/fastdeploy/vision/facedet/contrib/ultraface.cc similarity index 98% rename from csrcs/fastdeploy/vision/linzaer/ultraface.cc rename to csrcs/fastdeploy/vision/facedet/contrib/ultraface.cc index 7c35059c60..ed4962306c 100644 --- a/csrcs/fastdeploy/vision/linzaer/ultraface.cc +++ b/csrcs/fastdeploy/vision/facedet/contrib/ultraface.cc @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "fastdeploy/vision/linzaer/ultraface.h" +#include "fastdeploy/vision/facedet/contrib/ultraface.h" #include "fastdeploy/utils/perf.h" #include "fastdeploy/vision/utils/utils.h" @@ -20,7 +20,7 @@ namespace fastdeploy { namespace vision { -namespace linzaer { +namespace facedet { UltraFace::UltraFace(const std::string& model_file, const std::string& params_file, @@ -216,6 +216,6 @@ bool UltraFace::Predict(cv::Mat* im, FaceDetectionResult* result, return true; } -} // namespace linzaer +} // namespace facedet } // namespace vision } // namespace fastdeploy diff --git a/csrcs/fastdeploy/vision/linzaer/ultraface.h b/csrcs/fastdeploy/vision/facedet/contrib/ultraface.h similarity index 98% rename from csrcs/fastdeploy/vision/linzaer/ultraface.h rename to csrcs/fastdeploy/vision/facedet/contrib/ultraface.h index c3e499d99e..387bc1f9a4 100644 --- a/csrcs/fastdeploy/vision/linzaer/ultraface.h +++ b/csrcs/fastdeploy/vision/facedet/contrib/ultraface.h @@ -21,7 +21,7 @@ namespace fastdeploy { namespace vision { -namespace linzaer { +namespace facedet { class FASTDEPLOY_DECL UltraFace : public FastDeployModel { public: @@ -79,6 +79,6 @@ class FASTDEPLOY_DECL UltraFace : public FastDeployModel { bool is_dynamic_input_; }; -} // namespace linzaer +} // namespace facedet } // namespace vision } // namespace fastdeploy diff --git a/csrcs/fastdeploy/vision/linzaer/linzaer_pybind.cc b/csrcs/fastdeploy/vision/facedet/contrib/ultraface_pybind.cc similarity index 70% rename from csrcs/fastdeploy/vision/linzaer/linzaer_pybind.cc rename to csrcs/fastdeploy/vision/facedet/contrib/ultraface_pybind.cc index 89751bca21..855c26908d 100644 --- a/csrcs/fastdeploy/vision/linzaer/linzaer_pybind.cc +++ b/csrcs/fastdeploy/vision/facedet/contrib/ultraface_pybind.cc @@ -15,21 +15,17 @@ #include "fastdeploy/pybind/main.h" namespace fastdeploy { -void BindLinzaer(pybind11::module& m) { - auto linzaer_module = m.def_submodule( - "linzaer", - "https://github.com/Linzaer/Ultra-Light-Fast-Generic-Face-Detector-1MB"); - pybind11::class_(linzaer_module, - "UltraFace") +void BindUltraFace(pybind11::module& m) { + pybind11::class_(m, "UltraFace") .def(pybind11::init()) .def("predict", - [](vision::linzaer::UltraFace& self, pybind11::array& data, + [](vision::facedet::UltraFace& self, pybind11::array& data, float conf_threshold, float nms_iou_threshold) { auto mat = PyArrayToCvMat(data); vision::FaceDetectionResult res; self.Predict(&mat, &res, conf_threshold, nms_iou_threshold); return res; }) - .def_readwrite("size", &vision::linzaer::UltraFace::size); + .def_readwrite("size", &vision::facedet::UltraFace::size); } } // namespace fastdeploy diff --git a/csrcs/fastdeploy/vision/deepcam/yolov5face.cc b/csrcs/fastdeploy/vision/facedet/contrib/yolov5face.cc similarity index 99% rename from csrcs/fastdeploy/vision/deepcam/yolov5face.cc rename to csrcs/fastdeploy/vision/facedet/contrib/yolov5face.cc index 599821b4cd..96af230b06 100644 --- a/csrcs/fastdeploy/vision/deepcam/yolov5face.cc +++ b/csrcs/fastdeploy/vision/facedet/contrib/yolov5face.cc @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "fastdeploy/vision/deepcam/yolov5face.h" +#include "fastdeploy/vision/facedet/contrib/yolov5face.h" #include "fastdeploy/utils/perf.h" #include "fastdeploy/vision/utils/utils.h" @@ -20,7 +20,7 @@ namespace fastdeploy { namespace vision { -namespace deepcam { +namespace facedet { void LetterBox(Mat* mat, std::vector size, std::vector color, bool _auto, bool scale_fill = false, bool scale_up = true, @@ -289,6 +289,6 @@ bool YOLOv5Face::Predict(cv::Mat* im, FaceDetectionResult* result, return true; } -} // namespace deepcam +} // namespace facedet } // namespace vision } // namespace fastdeploy \ No newline at end of file diff --git a/csrcs/fastdeploy/vision/deepcam/yolov5face.h b/csrcs/fastdeploy/vision/facedet/contrib/yolov5face.h similarity index 97% rename from csrcs/fastdeploy/vision/deepcam/yolov5face.h rename to csrcs/fastdeploy/vision/facedet/contrib/yolov5face.h index 74a6f9c699..017c9681a8 100644 --- a/csrcs/fastdeploy/vision/deepcam/yolov5face.h +++ b/csrcs/fastdeploy/vision/facedet/contrib/yolov5face.h @@ -21,7 +21,7 @@ namespace fastdeploy { namespace vision { -namespace deepcam { +namespace facedet { class FASTDEPLOY_DECL YOLOv5Face : public FastDeployModel { public: @@ -32,7 +32,7 @@ class FASTDEPLOY_DECL YOLOv5Face : public FastDeployModel { const Frontend& model_format = Frontend::ONNX); // 定义模型的名称 - std::string ModelName() const { return "deepcam-cn/yolov5-face"; } + std::string ModelName() const { return "yolov5-face"; } // 模型预测接口,即用户调用的接口 // im 为用户的输入数据,目前对于CV均定义为cv::Mat @@ -92,6 +92,6 @@ class FASTDEPLOY_DECL YOLOv5Face : public FastDeployModel { bool is_dynamic_input_; }; -} // namespace deepcam +} // namespace facedet } // namespace vision } // namespace fastdeploy diff --git a/csrcs/fastdeploy/vision/deepcam/deepcam_pybind.cc b/csrcs/fastdeploy/vision/facedet/contrib/yolov5face_pybind.cc similarity index 64% rename from csrcs/fastdeploy/vision/deepcam/deepcam_pybind.cc rename to csrcs/fastdeploy/vision/facedet/contrib/yolov5face_pybind.cc index 3ac741bbcd..b843d4a9fa 100644 --- a/csrcs/fastdeploy/vision/deepcam/deepcam_pybind.cc +++ b/csrcs/fastdeploy/vision/facedet/contrib/yolov5face_pybind.cc @@ -15,29 +15,27 @@ #include "fastdeploy/pybind/main.h" namespace fastdeploy { -void BindDeepCam(pybind11::module& m) { - auto deepcam_module = - m.def_submodule("deepcam", "https://github.com/deepcam-cn/yolov5-face"); - pybind11::class_(deepcam_module, +void BindYOLOv5Face(pybind11::module& m) { + pybind11::class_(m, "YOLOv5Face") .def(pybind11::init()) .def("predict", - [](vision::deepcam::YOLOv5Face& self, pybind11::array& data, + [](vision::facedet::YOLOv5Face& self, pybind11::array& data, float conf_threshold, float nms_iou_threshold) { auto mat = PyArrayToCvMat(data); vision::FaceDetectionResult res; self.Predict(&mat, &res, conf_threshold, nms_iou_threshold); return res; }) - .def_readwrite("size", &vision::deepcam::YOLOv5Face::size) + .def_readwrite("size", &vision::facedet::YOLOv5Face::size) .def_readwrite("padding_value", - &vision::deepcam::YOLOv5Face::padding_value) - .def_readwrite("is_mini_pad", &vision::deepcam::YOLOv5Face::is_mini_pad) - .def_readwrite("is_no_pad", &vision::deepcam::YOLOv5Face::is_no_pad) - .def_readwrite("is_scale_up", &vision::deepcam::YOLOv5Face::is_scale_up) - .def_readwrite("stride", &vision::deepcam::YOLOv5Face::stride) + &vision::facedet::YOLOv5Face::padding_value) + .def_readwrite("is_mini_pad", &vision::facedet::YOLOv5Face::is_mini_pad) + .def_readwrite("is_no_pad", &vision::facedet::YOLOv5Face::is_no_pad) + .def_readwrite("is_scale_up", &vision::facedet::YOLOv5Face::is_scale_up) + .def_readwrite("stride", &vision::facedet::YOLOv5Face::stride) .def_readwrite("landmarks_per_face", - &vision::deepcam::YOLOv5Face::landmarks_per_face); + &vision::facedet::YOLOv5Face::landmarks_per_face); } } // namespace fastdeploy diff --git a/csrcs/fastdeploy/vision/facedet/facedet_pybind.cc b/csrcs/fastdeploy/vision/facedet/facedet_pybind.cc new file mode 100644 index 0000000000..3d9a812af9 --- /dev/null +++ b/csrcs/fastdeploy/vision/facedet/facedet_pybind.cc @@ -0,0 +1,31 @@ +// 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 BindRetinaFace(pybind11::module& m); +void BindUltraFace(pybind11::module& m); +void BindYOLOv5Face(pybind11::module& m); +void BindSCRFD(pybind11::module& m); + +void BindFaceDet(pybind11::module& m) { + auto facedet_module = m.def_submodule("facedet", "Face detection models."); + BindRetinaFace(facedet_module); + BindUltraFace(facedet_module); + BindYOLOv5Face(facedet_module); + BindSCRFD(facedet_module); +} +} // namespace fastdeploy diff --git a/csrcs/fastdeploy/vision/deepinsight/arcface.cc b/csrcs/fastdeploy/vision/faceid/contrib/arcface.cc similarity index 96% rename from csrcs/fastdeploy/vision/deepinsight/arcface.cc rename to csrcs/fastdeploy/vision/faceid/contrib/arcface.cc index 64aac197a7..9c2b647632 100644 --- a/csrcs/fastdeploy/vision/deepinsight/arcface.cc +++ b/csrcs/fastdeploy/vision/faceid/contrib/arcface.cc @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "fastdeploy/vision/deepinsight/arcface.h" +#include "fastdeploy/vision/faceid/contrib/arcface.h" #include "fastdeploy/utils/perf.h" #include "fastdeploy/vision/utils/utils.h" @@ -20,7 +20,7 @@ namespace fastdeploy { namespace vision { -namespace deepinsight { +namespace faceid { ArcFace::ArcFace(const std::string& model_file, const std::string& params_file, const RuntimeOption& custom_option, @@ -78,6 +78,6 @@ bool ArcFace::Predict(cv::Mat* im, FaceRecognitionResult* result) { return InsightFaceRecognitionModel::Predict(im, result); } -} // namespace deepinsight +} // namespace faceid } // namespace vision } // namespace fastdeploy \ No newline at end of file diff --git a/csrcs/fastdeploy/vision/deepinsight/arcface.h b/csrcs/fastdeploy/vision/faceid/contrib/arcface.h similarity index 95% rename from csrcs/fastdeploy/vision/deepinsight/arcface.h rename to csrcs/fastdeploy/vision/faceid/contrib/arcface.h index 73f8ea38dd..698fadcebd 100644 --- a/csrcs/fastdeploy/vision/deepinsight/arcface.h +++ b/csrcs/fastdeploy/vision/faceid/contrib/arcface.h @@ -16,13 +16,13 @@ #include "fastdeploy/fastdeploy_model.h" #include "fastdeploy/vision/common/processors/transform.h" #include "fastdeploy/vision/common/result.h" -#include "fastdeploy/vision/deepinsight/insightface_rec.h" +#include "fastdeploy/vision/faceid/contrib/insightface_rec.h" namespace fastdeploy { namespace vision { -namespace deepinsight { +namespace faceid { class FASTDEPLOY_DECL ArcFace : public InsightFaceRecognitionModel { public: @@ -60,6 +60,6 @@ class FASTDEPLOY_DECL ArcFace : public InsightFaceRecognitionModel { FaceRecognitionResult* result) override; }; -} // namespace deepinsight +} // namespace faceid } // namespace vision } // namespace fastdeploy diff --git a/csrcs/fastdeploy/vision/faceid/contrib/arcface_pybind.cc b/csrcs/fastdeploy/vision/faceid/contrib/arcface_pybind.cc new file mode 100644 index 0000000000..cd9bf7c578 --- /dev/null +++ b/csrcs/fastdeploy/vision/faceid/contrib/arcface_pybind.cc @@ -0,0 +1,37 @@ +// 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 BindArcFace(pybind11::module& m) { + // Bind ArcFace + pybind11::class_(m, "ArcFace") + .def(pybind11::init()) + .def("predict", + [](vision::faceid::ArcFace& self, pybind11::array& data) { + auto mat = PyArrayToCvMat(data); + vision::FaceRecognitionResult res; + self.Predict(&mat, &res); + return res; + }) + .def_readwrite("size", &vision::faceid::ArcFace::size) + .def_readwrite("alpha", &vision::faceid::ArcFace::alpha) + .def_readwrite("beta", &vision::faceid::ArcFace::beta) + .def_readwrite("swap_rb", &vision::faceid::ArcFace::swap_rb) + .def_readwrite("l2_normalize", &vision::faceid::ArcFace::l2_normalize); +} + +} // namespace fastdeploy diff --git a/csrcs/fastdeploy/vision/deepinsight/cosface.cc b/csrcs/fastdeploy/vision/faceid/contrib/cosface.cc similarity index 96% rename from csrcs/fastdeploy/vision/deepinsight/cosface.cc rename to csrcs/fastdeploy/vision/faceid/contrib/cosface.cc index 8bea9d6bbc..4a4d6dc559 100644 --- a/csrcs/fastdeploy/vision/deepinsight/cosface.cc +++ b/csrcs/fastdeploy/vision/faceid/contrib/cosface.cc @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "fastdeploy/vision/deepinsight/cosface.h" +#include "fastdeploy/vision/faceid/contrib/cosface.h" #include "fastdeploy/utils/perf.h" #include "fastdeploy/vision/utils/utils.h" @@ -20,7 +20,7 @@ namespace fastdeploy { namespace vision { -namespace deepinsight { +namespace faceid { CosFace::CosFace(const std::string& model_file, const std::string& params_file, const RuntimeOption& custom_option, @@ -78,6 +78,6 @@ bool CosFace::Predict(cv::Mat* im, FaceRecognitionResult* result) { return InsightFaceRecognitionModel::Predict(im, result); } -} // namespace deepinsight +} // namespace faceid } // namespace vision } // namespace fastdeploy \ No newline at end of file diff --git a/csrcs/fastdeploy/vision/deepinsight/cosface.h b/csrcs/fastdeploy/vision/faceid/contrib/cosface.h similarity index 95% rename from csrcs/fastdeploy/vision/deepinsight/cosface.h rename to csrcs/fastdeploy/vision/faceid/contrib/cosface.h index 10f379a66f..92704536c7 100644 --- a/csrcs/fastdeploy/vision/deepinsight/cosface.h +++ b/csrcs/fastdeploy/vision/faceid/contrib/cosface.h @@ -16,13 +16,13 @@ #include "fastdeploy/fastdeploy_model.h" #include "fastdeploy/vision/common/processors/transform.h" #include "fastdeploy/vision/common/result.h" -#include "fastdeploy/vision/deepinsight/insightface_rec.h" +#include "fastdeploy/vision/faceid/contrib/insightface_rec.h" namespace fastdeploy { namespace vision { -namespace deepinsight { +namespace faceid { class FASTDEPLOY_DECL CosFace : public InsightFaceRecognitionModel { public: @@ -61,6 +61,6 @@ class FASTDEPLOY_DECL CosFace : public InsightFaceRecognitionModel { FaceRecognitionResult* result) override; }; -} // namespace deepinsight +} // namespace faceid } // namespace vision } // namespace fastdeploy diff --git a/csrcs/fastdeploy/vision/faceid/contrib/cosface_pybind.cc b/csrcs/fastdeploy/vision/faceid/contrib/cosface_pybind.cc new file mode 100644 index 0000000000..c09f9e7232 --- /dev/null +++ b/csrcs/fastdeploy/vision/faceid/contrib/cosface_pybind.cc @@ -0,0 +1,37 @@ +// 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 BindCosFace(pybind11::module& m) { + // Bind CosFace + pybind11::class_(m, "CosFace") + .def(pybind11::init()) + .def("predict", + [](vision::faceid::CosFace& self, pybind11::array& data) { + auto mat = PyArrayToCvMat(data); + vision::FaceRecognitionResult res; + self.Predict(&mat, &res); + return res; + }) + .def_readwrite("size", &vision::faceid::CosFace::size) + .def_readwrite("alpha", &vision::faceid::CosFace::alpha) + .def_readwrite("beta", &vision::faceid::CosFace::beta) + .def_readwrite("swap_rb", &vision::faceid::CosFace::swap_rb) + .def_readwrite("l2_normalize", &vision::faceid::CosFace::l2_normalize); +} + +} // namespace fastdeploy diff --git a/csrcs/fastdeploy/vision/deepinsight/insightface_rec.cc b/csrcs/fastdeploy/vision/faceid/contrib/insightface_rec.cc similarity index 97% rename from csrcs/fastdeploy/vision/deepinsight/insightface_rec.cc rename to csrcs/fastdeploy/vision/faceid/contrib/insightface_rec.cc index f470d9e96e..ddd7520d4f 100644 --- a/csrcs/fastdeploy/vision/deepinsight/insightface_rec.cc +++ b/csrcs/fastdeploy/vision/faceid/contrib/insightface_rec.cc @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "fastdeploy/vision/deepinsight/insightface_rec.h" +#include "fastdeploy/vision/faceid/contrib/insightface_rec.h" #include "fastdeploy/utils/perf.h" #include "fastdeploy/vision/utils/utils.h" @@ -20,7 +20,7 @@ namespace fastdeploy { namespace vision { -namespace deepinsight { +namespace faceid { InsightFaceRecognitionModel::InsightFaceRecognitionModel( const std::string& model_file, const std::string& params_file, @@ -148,6 +148,6 @@ bool InsightFaceRecognitionModel::Predict(cv::Mat* im, return true; } -} // namespace deepinsight +} // namespace faceid } // namespace vision } // namespace fastdeploy \ No newline at end of file diff --git a/csrcs/fastdeploy/vision/deepinsight/insightface_rec.h b/csrcs/fastdeploy/vision/faceid/contrib/insightface_rec.h similarity index 98% rename from csrcs/fastdeploy/vision/deepinsight/insightface_rec.h rename to csrcs/fastdeploy/vision/faceid/contrib/insightface_rec.h index 5fab3cee14..b8eb272629 100644 --- a/csrcs/fastdeploy/vision/deepinsight/insightface_rec.h +++ b/csrcs/fastdeploy/vision/faceid/contrib/insightface_rec.h @@ -21,7 +21,7 @@ namespace fastdeploy { namespace vision { -namespace deepinsight { +namespace faceid { class FASTDEPLOY_DECL InsightFaceRecognitionModel : public FastDeployModel { public: @@ -67,6 +67,6 @@ class FASTDEPLOY_DECL InsightFaceRecognitionModel : public FastDeployModel { FaceRecognitionResult* result); }; -} // namespace deepinsight +} // namespace faceid } // namespace vision } // namespace fastdeploy diff --git a/csrcs/fastdeploy/vision/faceid/contrib/insightface_rec_pybind.cc b/csrcs/fastdeploy/vision/faceid/contrib/insightface_rec_pybind.cc new file mode 100644 index 0000000000..78df369bb8 --- /dev/null +++ b/csrcs/fastdeploy/vision/faceid/contrib/insightface_rec_pybind.cc @@ -0,0 +1,42 @@ +// 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 BindInsightFaceRecognitionModel(pybind11::module& m) { + // Bind InsightFaceRecognitionModel + pybind11::class_(m, "InsightFaceRecognitionModel") + .def(pybind11::init()) + .def("predict", + [](vision::faceid::InsightFaceRecognitionModel& self, + pybind11::array& data) { + auto mat = PyArrayToCvMat(data); + vision::FaceRecognitionResult res; + self.Predict(&mat, &res); + return res; + }) + .def_readwrite("size", &vision::faceid::InsightFaceRecognitionModel::size) + .def_readwrite("alpha", + &vision::faceid::InsightFaceRecognitionModel::alpha) + .def_readwrite("beta", &vision::faceid::InsightFaceRecognitionModel::beta) + .def_readwrite("swap_rb", + &vision::faceid::InsightFaceRecognitionModel::swap_rb) + .def_readwrite( + "l2_normalize", + &vision::faceid::InsightFaceRecognitionModel::l2_normalize); +} + +} // namespace fastdeploy diff --git a/csrcs/fastdeploy/vision/deepinsight/partial_fc.cc b/csrcs/fastdeploy/vision/faceid/contrib/partial_fc.cc similarity index 96% rename from csrcs/fastdeploy/vision/deepinsight/partial_fc.cc rename to csrcs/fastdeploy/vision/faceid/contrib/partial_fc.cc index c9c6f082ab..8f13226cbd 100644 --- a/csrcs/fastdeploy/vision/deepinsight/partial_fc.cc +++ b/csrcs/fastdeploy/vision/faceid/contrib/partial_fc.cc @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "fastdeploy/vision/deepinsight/partial_fc.h" +#include "fastdeploy/vision/faceid/contrib/partial_fc.h" #include "fastdeploy/utils/perf.h" #include "fastdeploy/vision/utils/utils.h" @@ -20,7 +20,7 @@ namespace fastdeploy { namespace vision { -namespace deepinsight { +namespace faceid { PartialFC::PartialFC(const std::string& model_file, const std::string& params_file, @@ -79,6 +79,6 @@ bool PartialFC::Predict(cv::Mat* im, FaceRecognitionResult* result) { return InsightFaceRecognitionModel::Predict(im, result); } -} // namespace deepinsight +} // namespace faceid } // namespace vision } // namespace fastdeploy \ No newline at end of file diff --git a/csrcs/fastdeploy/vision/deepinsight/partial_fc.h b/csrcs/fastdeploy/vision/faceid/contrib/partial_fc.h similarity index 95% rename from csrcs/fastdeploy/vision/deepinsight/partial_fc.h rename to csrcs/fastdeploy/vision/faceid/contrib/partial_fc.h index efe66b702a..88a1f2a2ad 100644 --- a/csrcs/fastdeploy/vision/deepinsight/partial_fc.h +++ b/csrcs/fastdeploy/vision/faceid/contrib/partial_fc.h @@ -16,13 +16,13 @@ #include "fastdeploy/fastdeploy_model.h" #include "fastdeploy/vision/common/processors/transform.h" #include "fastdeploy/vision/common/result.h" -#include "fastdeploy/vision/deepinsight/insightface_rec.h" +#include "fastdeploy/vision/faceid/contrib/insightface_rec.h" namespace fastdeploy { namespace vision { -namespace deepinsight { +namespace faceid { class FASTDEPLOY_DECL PartialFC : public InsightFaceRecognitionModel { public: @@ -59,6 +59,6 @@ class FASTDEPLOY_DECL PartialFC : public InsightFaceRecognitionModel { FaceRecognitionResult* result) override; }; -} // namespace deepinsight +} // namespace faceid } // namespace vision } // namespace fastdeploy diff --git a/csrcs/fastdeploy/vision/faceid/contrib/partial_fc_pybind.cc b/csrcs/fastdeploy/vision/faceid/contrib/partial_fc_pybind.cc new file mode 100644 index 0000000000..b8cb31358c --- /dev/null +++ b/csrcs/fastdeploy/vision/faceid/contrib/partial_fc_pybind.cc @@ -0,0 +1,37 @@ +// 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 BindPartialFC(pybind11::module& m) { + // Bind Partial FC + pybind11::class_(m, "PartialFC") + .def(pybind11::init()) + .def("predict", + [](vision::faceid::PartialFC& self, pybind11::array& data) { + auto mat = PyArrayToCvMat(data); + vision::FaceRecognitionResult res; + self.Predict(&mat, &res); + return res; + }) + .def_readwrite("size", &vision::faceid::PartialFC::size) + .def_readwrite("alpha", &vision::faceid::PartialFC::alpha) + .def_readwrite("beta", &vision::faceid::PartialFC::beta) + .def_readwrite("swap_rb", &vision::faceid::PartialFC::swap_rb) + .def_readwrite("l2_normalize", &vision::faceid::PartialFC::l2_normalize); +} + +} // namespace fastdeploy diff --git a/csrcs/fastdeploy/vision/deepinsight/vpl.cc b/csrcs/fastdeploy/vision/faceid/contrib/vpl.cc similarity index 96% rename from csrcs/fastdeploy/vision/deepinsight/vpl.cc rename to csrcs/fastdeploy/vision/faceid/contrib/vpl.cc index 251902cf29..bb34d3993f 100644 --- a/csrcs/fastdeploy/vision/deepinsight/vpl.cc +++ b/csrcs/fastdeploy/vision/faceid/contrib/vpl.cc @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "fastdeploy/vision/deepinsight/vpl.h" +#include "fastdeploy/vision/faceid/contrib/vpl.h" #include "fastdeploy/utils/perf.h" #include "fastdeploy/vision/utils/utils.h" @@ -20,7 +20,7 @@ namespace fastdeploy { namespace vision { -namespace deepinsight { +namespace faceid { VPL::VPL(const std::string& model_file, const std::string& params_file, const RuntimeOption& custom_option, const Frontend& model_format) @@ -77,6 +77,6 @@ bool VPL::Predict(cv::Mat* im, FaceRecognitionResult* result) { return InsightFaceRecognitionModel::Predict(im, result); } -} // namespace deepinsight +} // namespace faceid } // namespace vision } // namespace fastdeploy \ No newline at end of file diff --git a/csrcs/fastdeploy/vision/deepinsight/vpl.h b/csrcs/fastdeploy/vision/faceid/contrib/vpl.h similarity index 95% rename from csrcs/fastdeploy/vision/deepinsight/vpl.h rename to csrcs/fastdeploy/vision/faceid/contrib/vpl.h index a57e33e9f3..696d13ac3f 100644 --- a/csrcs/fastdeploy/vision/deepinsight/vpl.h +++ b/csrcs/fastdeploy/vision/faceid/contrib/vpl.h @@ -16,13 +16,13 @@ #include "fastdeploy/fastdeploy_model.h" #include "fastdeploy/vision/common/processors/transform.h" #include "fastdeploy/vision/common/result.h" -#include "fastdeploy/vision/deepinsight/insightface_rec.h" +#include "fastdeploy/vision/faceid/contrib/insightface_rec.h" namespace fastdeploy { namespace vision { -namespace deepinsight { +namespace faceid { class FASTDEPLOY_DECL VPL : public InsightFaceRecognitionModel { public: @@ -60,6 +60,6 @@ class FASTDEPLOY_DECL VPL : public InsightFaceRecognitionModel { FaceRecognitionResult* result) override; }; -} // namespace deepinsight +} // namespace faceid } // namespace vision } // namespace fastdeploy diff --git a/csrcs/fastdeploy/vision/faceid/contrib/vpl_pybind.cc b/csrcs/fastdeploy/vision/faceid/contrib/vpl_pybind.cc new file mode 100644 index 0000000000..448cf3d3b6 --- /dev/null +++ b/csrcs/fastdeploy/vision/faceid/contrib/vpl_pybind.cc @@ -0,0 +1,37 @@ +// 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 BindVPL(pybind11::module& m) { + // Bind VPL + pybind11::class_(m, "VPL") + .def(pybind11::init()) + .def("predict", + [](vision::faceid::VPL& self, pybind11::array& data) { + auto mat = PyArrayToCvMat(data); + vision::FaceRecognitionResult res; + self.Predict(&mat, &res); + return res; + }) + .def_readwrite("size", &vision::faceid::VPL::size) + .def_readwrite("alpha", &vision::faceid::VPL::alpha) + .def_readwrite("beta", &vision::faceid::VPL::beta) + .def_readwrite("swap_rb", &vision::faceid::VPL::swap_rb) + .def_readwrite("l2_normalize", &vision::faceid::VPL::l2_normalize); +} + +} // namespace fastdeploy diff --git a/csrcs/fastdeploy/vision/faceid/faceid_pybind.cc b/csrcs/fastdeploy/vision/faceid/faceid_pybind.cc new file mode 100644 index 0000000000..40a1c67274 --- /dev/null +++ b/csrcs/fastdeploy/vision/faceid/faceid_pybind.cc @@ -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. + +#include "fastdeploy/pybind/main.h" + +namespace fastdeploy { + +void BindArcFace(pybind11::module& m); +void BindInsightFaceRecognitionModel(pybind11::module& m); +void BindCosFace(pybind11::module& m); +void BindPartialFC(pybind11::module& m); +void BindVPL(pybind11::module& m); + +void BindFaceId(pybind11::module& m) { + auto faceid_module = m.def_submodule("faceid", "Face recognition models."); + BindInsightFaceRecognitionModel(faceid_module); + BindArcFace(faceid_module); + BindCosFace(faceid_module); + BindPartialFC(faceid_module); + BindVPL(faceid_module); +} +} // namespace fastdeploy diff --git a/csrcs/fastdeploy/vision/zhkkke/modnet.cc b/csrcs/fastdeploy/vision/matting/contrib/modnet.cc similarity index 98% rename from csrcs/fastdeploy/vision/zhkkke/modnet.cc rename to csrcs/fastdeploy/vision/matting/contrib/modnet.cc index 2f502a3659..b98d055e33 100644 --- a/csrcs/fastdeploy/vision/zhkkke/modnet.cc +++ b/csrcs/fastdeploy/vision/matting/contrib/modnet.cc @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "fastdeploy/vision/zhkkke/modnet.h" +#include "fastdeploy/vision/matting/contrib/modnet.h" #include "fastdeploy/utils/perf.h" #include "fastdeploy/vision/utils/utils.h" @@ -20,7 +20,7 @@ namespace fastdeploy { namespace vision { -namespace zhkkke { +namespace matting { MODNet::MODNet(const std::string& model_file, const std::string& params_file, const RuntimeOption& custom_option, @@ -170,6 +170,6 @@ bool MODNet::Predict(cv::Mat* im, MattingResult* result) { return true; } -} // namespace zhkkke +} // namespace matting } // namespace vision } // namespace fastdeploy \ No newline at end of file diff --git a/csrcs/fastdeploy/vision/zhkkke/modnet.h b/csrcs/fastdeploy/vision/matting/contrib/modnet.h similarity index 96% rename from csrcs/fastdeploy/vision/zhkkke/modnet.h rename to csrcs/fastdeploy/vision/matting/contrib/modnet.h index e9631098bb..047fd3aeaa 100644 --- a/csrcs/fastdeploy/vision/zhkkke/modnet.h +++ b/csrcs/fastdeploy/vision/matting/contrib/modnet.h @@ -21,7 +21,7 @@ namespace fastdeploy { namespace vision { -namespace zhkkke { +namespace matting { class FASTDEPLOY_DECL MODNet : public FastDeployModel { public: @@ -32,7 +32,7 @@ class FASTDEPLOY_DECL MODNet : public FastDeployModel { const Frontend& model_format = Frontend::ONNX); // 定义模型的名称 - std::string ModelName() const { return "ZHKKKe/MODNet"; } + std::string ModelName() const { return "matting/MODNet"; } // 以下为一些可供用户修改的属性 // tuple of (width, height), default (256, 256) @@ -65,6 +65,6 @@ class FASTDEPLOY_DECL MODNet : public FastDeployModel { const std::map>& im_info); }; -} // namespace zhkkke +} // namespace matting } // namespace vision } // namespace fastdeploy diff --git a/csrcs/fastdeploy/vision/zhkkke/zhkkke_pybind.cc b/csrcs/fastdeploy/vision/matting/contrib/modnet_pybind.cc similarity index 63% rename from csrcs/fastdeploy/vision/zhkkke/zhkkke_pybind.cc rename to csrcs/fastdeploy/vision/matting/contrib/modnet_pybind.cc index e884a8ee07..bfb8b1f889 100644 --- a/csrcs/fastdeploy/vision/zhkkke/zhkkke_pybind.cc +++ b/csrcs/fastdeploy/vision/matting/contrib/modnet_pybind.cc @@ -15,23 +15,21 @@ #include "fastdeploy/pybind/main.h" namespace fastdeploy { -void BindZHKKKe(pybind11::module& m) { - auto zhkkke_module = m.def_submodule("zhkkke", "https://github.com/ZHKKKe"); +void BindMODNet(pybind11::module& m) { // Bind MODNet - pybind11::class_(zhkkke_module, - "MODNet") + pybind11::class_(m, "MODNet") .def(pybind11::init()) .def("predict", - [](vision::zhkkke::MODNet& self, pybind11::array& data) { + [](vision::matting::MODNet& self, pybind11::array& data) { auto mat = PyArrayToCvMat(data); vision::MattingResult res; self.Predict(&mat, &res); return res; }) - .def_readwrite("size", &vision::zhkkke::MODNet::size) - .def_readwrite("alpha", &vision::zhkkke::MODNet::alpha) - .def_readwrite("beta", &vision::zhkkke::MODNet::beta) - .def_readwrite("swap_rb", &vision::zhkkke::MODNet::swap_rb); + .def_readwrite("size", &vision::matting::MODNet::size) + .def_readwrite("alpha", &vision::matting::MODNet::alpha) + .def_readwrite("beta", &vision::matting::MODNet::beta) + .def_readwrite("swap_rb", &vision::matting::MODNet::swap_rb); } } // namespace fastdeploy diff --git a/csrcs/fastdeploy/vision/matting/matting_pybind.cc b/csrcs/fastdeploy/vision/matting/matting_pybind.cc new file mode 100644 index 0000000000..e5fd78925d --- /dev/null +++ b/csrcs/fastdeploy/vision/matting/matting_pybind.cc @@ -0,0 +1,26 @@ +// 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 BindMODNet(pybind11::module& m); + +void BindMatting(pybind11::module& m) { + auto matting_module = + m.def_submodule("matting", "Image object matting models."); + BindMODNet(matting_module); +} +} // namespace fastdeploy diff --git a/csrcs/fastdeploy/vision/ultralytics/ultralytics_pybind.cc b/csrcs/fastdeploy/vision/ultralytics/ultralytics_pybind.cc deleted file mode 100644 index c602143496..0000000000 --- a/csrcs/fastdeploy/vision/ultralytics/ultralytics_pybind.cc +++ /dev/null @@ -1,42 +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/pybind/main.h" - -namespace fastdeploy { -void BindUltralytics(pybind11::module& m) { - auto ultralytics_module = - m.def_submodule("ultralytics", "https://github.com/ultralytics/yolov5"); - pybind11::class_( - ultralytics_module, "YOLOv5") - .def(pybind11::init()) - .def("predict", - [](vision::ultralytics::YOLOv5& self, pybind11::array& data, - float conf_threshold, float nms_iou_threshold) { - auto mat = PyArrayToCvMat(data); - vision::DetectionResult res; - self.Predict(&mat, &res, conf_threshold, nms_iou_threshold); - return res; - }) - .def_readwrite("size", &vision::ultralytics::YOLOv5::size) - .def_readwrite("padding_value", - &vision::ultralytics::YOLOv5::padding_value) - .def_readwrite("is_mini_pad", &vision::ultralytics::YOLOv5::is_mini_pad) - .def_readwrite("is_no_pad", &vision::ultralytics::YOLOv5::is_no_pad) - .def_readwrite("is_scale_up", &vision::ultralytics::YOLOv5::is_scale_up) - .def_readwrite("stride", &vision::ultralytics::YOLOv5::stride) - .def_readwrite("max_wh", &vision::ultralytics::YOLOv5::max_wh) - .def_readwrite("multi_label", &vision::ultralytics::YOLOv5::multi_label); -} -} // namespace fastdeploy diff --git a/csrcs/fastdeploy/vision/vision_pybind.cc b/csrcs/fastdeploy/vision/vision_pybind.cc index e408732c61..6528dd22bf 100644 --- a/csrcs/fastdeploy/vision/vision_pybind.cc +++ b/csrcs/fastdeploy/vision/vision_pybind.cc @@ -19,18 +19,11 @@ namespace fastdeploy { void BindPPCls(pybind11::module& m); void BindPPDet(pybind11::module& m); void BindPPSeg(pybind11::module& m); -void BindUltralytics(pybind11::module& m); -void BindMeituan(pybind11::module& m); -void BindMegvii(pybind11::module& m); -void BindDeepCam(pybind11::module& m); -void BindRangiLyu(pybind11::module& m); -void BindLinzaer(pybind11::module& m); -void BindBiubug6(pybind11::module& m); -void BindPpogg(pybind11::module& m); -void BindDeepInsight(pybind11::module& m); -void BindZHKKKe(pybind11::module& m); void BindDetection(pybind11::module& m); +void BindMatting(pybind11::module& m); +void BindFaceDet(pybind11::module& m); +void BindFaceId(pybind11::module& m); #ifdef ENABLE_VISION_VISUALIZE void BindVisualize(pybind11::module& m); #endif @@ -88,18 +81,11 @@ void BindVision(pybind11::module& m) { BindPPCls(m); BindPPDet(m); BindPPSeg(m); - BindUltralytics(m); - BindMeituan(m); - BindMegvii(m); - BindDeepCam(m); - BindRangiLyu(m); - BindLinzaer(m); - BindBiubug6(m); - BindPpogg(m); - BindDeepInsight(m); - BindZHKKKe(m); BindDetection(m); + BindFaceDet(m); + BindFaceId(m); + BindMatting(m); #ifdef ENABLE_VISION_VISUALIZE BindVisualize(m); #endif diff --git a/csrcs/fastdeploy/vision/visualize/visualize.h b/csrcs/fastdeploy/vision/visualize/visualize.h index 3ba4fe903a..bee62c3012 100644 --- a/csrcs/fastdeploy/vision/visualize/visualize.h +++ b/csrcs/fastdeploy/vision/visualize/visualize.h @@ -26,10 +26,10 @@ class FASTDEPLOY_DECL Visualize { static std::vector color_map_; static const std::vector& GetColorMap(int num_classes = 1000); static cv::Mat VisDetection(const cv::Mat& im, const DetectionResult& result, - int line_size = 2, float font_size = 0.5f); + int line_size = 1, float font_size = 0.5f); static cv::Mat VisFaceDetection(const cv::Mat& im, const FaceDetectionResult& result, - int line_size = 2, float font_size = 0.5f); + int line_size = 1, float font_size = 0.5f); static cv::Mat VisSegmentation(const cv::Mat& im, const SegmentationResult& result); static cv::Mat VisMattingAlpha(const cv::Mat& im, const MattingResult& result, diff --git a/fastdeploy/vision/__init__.py b/fastdeploy/vision/__init__.py index 53dd76953a..54f9aa4d53 100644 --- a/fastdeploy/vision/__init__.py +++ b/fastdeploy/vision/__init__.py @@ -13,21 +13,9 @@ # limitations under the License. from __future__ import absolute_import -from . import evaluation -from . import ppcls -from . import ppdet -from . import ppseg -from . import ultralytics -from . import meituan -from . import megvii -from . import deepcam -from . import rangilyu -from . import linzaer -from . import biubug6 -from . import ppogg -from . import deepinsight -from . import zhkkke - from . import detection +from . import matting +from . import facedet +from . import faceid from .visualize import * diff --git a/fastdeploy/vision/deepinsight/__init__.py b/fastdeploy/vision/deepinsight/__init__.py deleted file mode 100644 index 1d4d00152a..0000000000 --- a/fastdeploy/vision/deepinsight/__init__.py +++ /dev/null @@ -1,563 +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. - -from __future__ import absolute_import -import logging -from ... import FastDeployModel, Frontend -from ... import c_lib_wrap as C - - -class SCRFD(FastDeployModel): - def __init__(self, - model_file, - params_file="", - runtime_option=None, - model_format=Frontend.ONNX): - # 调用基函数进行backend_option的初始化 - # 初始化后的option保存在self._runtime_option - super(SCRFD, self).__init__(runtime_option) - - self._model = C.vision.deepinsight.SCRFD( - model_file, params_file, self._runtime_option, model_format) - # 通过self.initialized判断整个模型的初始化是否成功 - assert self.initialized, "SCRFD initialize failed." - - def predict(self, input_image, conf_threshold=0.7, nms_iou_threshold=0.3): - return self._model.predict(input_image, conf_threshold, - nms_iou_threshold) - - # 一些跟SCRFD模型有关的属性封装 - # 多数是预处理相关,可通过修改如model.size = [640, 640]改变预处理时resize的大小(前提是模型支持) - @property - def size(self): - return self._model.size - - @property - def padding_value(self): - return self._model.padding_value - - @property - def is_no_pad(self): - return self._model.is_no_pad - - @property - def is_mini_pad(self): - return self._model.is_mini_pad - - @property - def is_scale_up(self): - return self._model.is_scale_up - - @property - def stride(self): - return self._model.stride - - @property - def downsample_strides(self): - return self._model.downsample_strides - - @property - def landmarks_per_face(self): - return self._model.landmarks_per_face - - @property - def use_kps(self): - return self._model.use_kps - - @property - def max_nms(self): - return self._model.max_nms - - @property - def num_anchors(self): - return self._model.num_anchors - - @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._model.size = wh - - @padding_value.setter - def padding_value(self, value): - assert isinstance( - value, - list), "The value to set `padding_value` must be type of list." - self._model.padding_value = value - - @is_no_pad.setter - def is_no_pad(self, value): - assert isinstance( - value, bool), "The value to set `is_no_pad` must be type of bool." - self._model.is_no_pad = value - - @is_mini_pad.setter - def is_mini_pad(self, value): - assert isinstance( - value, - bool), "The value to set `is_mini_pad` must be type of bool." - self._model.is_mini_pad = 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._model.is_scale_up = value - - @stride.setter - def stride(self, value): - assert isinstance( - value, int), "The value to set `stride` must be type of int." - self._model.stride = value - - @downsample_strides.setter - def downsample_strides(self, value): - assert isinstance( - value, - list), "The value to set `downsample_strides` must be type of list." - self._model.downsample_strides = value - - @landmarks_per_face.setter - def landmarks_per_face(self, value): - assert isinstance( - value, - int), "The value to set `landmarks_per_face` must be type of int." - self._model.landmarks_per_face = value - - @use_kps.setter - def use_kps(self, value): - assert isinstance( - value, bool), "The value to set `use_kps` must be type of bool." - self._model.use_kps = value - - @max_nms.setter - def max_nms(self, value): - assert isinstance( - value, int), "The value to set `max_nms` must be type of int." - self._model.max_nms = value - - @num_anchors.setter - def num_anchors(self, value): - assert isinstance( - value, int), "The value to set `num_anchors` must be type of int." - self._model.num_anchors = value - - -class InsightFaceRecognitionModel(FastDeployModel): - def __init__(self, - model_file, - params_file="", - runtime_option=None, - model_format=Frontend.ONNX): - # 调用基函数进行backend_option的初始化 - # 初始化后的option保存在self._runtime_option - super(InsightFaceRecognitionModel, self).__init__(runtime_option) - - self._model = C.vision.deepinsight.InsightFaceRecognitionModel( - model_file, params_file, self._runtime_option, model_format) - # 通过self.initialized判断整个模型的初始化是否成功 - assert self.initialized, "InsightFaceRecognitionModel initialize failed." - - def predict(self, input_image): - return self._model.predict(input_image) - - # 一些跟InsightFaceRecognitionModel模型有关的属性封装 - # 多数是预处理相关,可通过修改如model.size = [112, 112]改变预处理时resize的大小(前提是模型支持) - @property - def size(self): - return self._model.size - - @property - def alpha(self): - return self._model.alpha - - @property - def beta(self): - return self._model.beta - - @property - def swap_rb(self): - return self._model.swap_rb - - @property - def l2_normalize(self): - return self._model.l2_normalize - - @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._model.size = wh - - @alpha.setter - def alpha(self, value): - assert isinstance(value, (list, tuple)),\ - "The value to set `alpha` must be type of tuple or list." - assert len(value) == 3,\ - "The value to set `alpha` must contatins 3 elements for each channels, but now it contains {} elements.".format( - len(value)) - self._model.alpha = value - - @beta.setter - def beta(self, value): - assert isinstance(value, (list, tuple)),\ - "The value to set `beta` must be type of tuple or list." - assert len(value) == 3,\ - "The value to set `beta` must contatins 3 elements for each channels, but now it contains {} elements.".format( - len(value)) - self._model.beta = value - - @swap_rb.setter - def swap_rb(self, value): - assert isinstance( - value, bool), "The value to set `swap_rb` must be type of bool." - self._model.swap_rb = value - - @l2_normalize.setter - def l2_normalize(self, value): - assert isinstance( - value, - bool), "The value to set `l2_normalize` must be type of bool." - self._model.l2_normalize = value - - -class ArcFace(FastDeployModel): - def __init__(self, - model_file, - params_file="", - runtime_option=None, - model_format=Frontend.ONNX): - # 调用基函数进行backend_option的初始化 - # 初始化后的option保存在self._runtime_option - super(ArcFace, self).__init__(runtime_option) - - self._model = C.vision.deepinsight.ArcFace( - model_file, params_file, self._runtime_option, model_format) - # 通过self.initialized判断整个模型的初始化是否成功 - assert self.initialized, "ArcFace initialize failed." - - def predict(self, input_image): - return self._model.predict(input_image) - - # 一些跟模型有关的属性封装 - # 多数是预处理相关,可通过修改如model.size = [112, 112]改变预处理时resize的大小(前提是模型支持) - @property - def size(self): - return self._model.size - - @property - def alpha(self): - return self._model.alpha - - @property - def beta(self): - return self._model.beta - - @property - def swap_rb(self): - return self._model.swap_rb - - @property - def l2_normalize(self): - return self._model.l2_normalize - - @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._model.size = wh - - @alpha.setter - def alpha(self, value): - assert isinstance(value, (list, tuple)),\ - "The value to set `alpha` must be type of tuple or list." - assert len(value) == 3,\ - "The value to set `alpha` must contatins 3 elements for each channels, but now it contains {} elements.".format( - len(value)) - self._model.alpha = value - - @beta.setter - def beta(self, value): - assert isinstance(value, (list, tuple)),\ - "The value to set `beta` must be type of tuple or list." - assert len(value) == 3,\ - "The value to set `beta` must contatins 3 elements for each channels, but now it contains {} elements.".format( - len(value)) - self._model.beta = value - - @swap_rb.setter - def swap_rb(self, value): - assert isinstance( - value, bool), "The value to set `swap_rb` must be type of bool." - self._model.swap_rb = value - - @l2_normalize.setter - def l2_normalize(self, value): - assert isinstance( - value, - bool), "The value to set `l2_normalize` must be type of bool." - self._model.l2_normalize = value - - -class CosFace(FastDeployModel): - def __init__(self, - model_file, - params_file="", - runtime_option=None, - model_format=Frontend.ONNX): - # 调用基函数进行backend_option的初始化 - # 初始化后的option保存在self._runtime_option - super(CosFace, self).__init__(runtime_option) - - self._model = C.vision.deepinsight.CosFace( - model_file, params_file, self._runtime_option, model_format) - # 通过self.initialized判断整个模型的初始化是否成功 - assert self.initialized, "CosFace initialize failed." - - def predict(self, input_image): - return self._model.predict(input_image) - - # 一些跟模型有关的属性封装 - # 多数是预处理相关,可通过修改如model.size = [112, 112]改变预处理时resize的大小(前提是模型支持) - @property - def size(self): - return self._model.size - - @property - def alpha(self): - return self._model.alpha - - @property - def beta(self): - return self._model.beta - - @property - def swap_rb(self): - return self._model.swap_rb - - @property - def l2_normalize(self): - return self._model.l2_normalize - - @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._model.size = wh - - @alpha.setter - def alpha(self, value): - assert isinstance(value, (list, tuple)),\ - "The value to set `alpha` must be type of tuple or list." - assert len(value) == 3,\ - "The value to set `alpha` must contatins 3 elements for each channels, but now it contains {} elements.".format( - len(value)) - self._model.alpha = value - - @beta.setter - def beta(self, value): - assert isinstance(value, (list, tuple)),\ - "The value to set `beta` must be type of tuple or list." - assert len(value) == 3,\ - "The value to set `beta` must contatins 3 elements for each channels, but now it contains {} elements.".format( - len(value)) - self._model.beta = value - - @swap_rb.setter - def swap_rb(self, value): - assert isinstance( - value, bool), "The value to set `swap_rb` must be type of bool." - self._model.swap_rb = value - - @l2_normalize.setter - def l2_normalize(self, value): - assert isinstance( - value, - bool), "The value to set `l2_normalize` must be type of bool." - self._model.l2_normalize = value - - -class PartialFC(FastDeployModel): - def __init__(self, - model_file, - params_file="", - runtime_option=None, - model_format=Frontend.ONNX): - # 调用基函数进行backend_option的初始化 - # 初始化后的option保存在self._runtime_option - super(PartialFC, self).__init__(runtime_option) - - self._model = C.vision.deepinsight.PartialFC( - model_file, params_file, self._runtime_option, model_format) - # 通过self.initialized判断整个模型的初始化是否成功 - assert self.initialized, "PartialFC initialize failed." - - def predict(self, input_image): - return self._model.predict(input_image) - - # 一些跟模型有关的属性封装 - # 多数是预处理相关,可通过修改如model.size = [112, 112]改变预处理时resize的大小(前提是模型支持) - @property - def size(self): - return self._model.size - - @property - def alpha(self): - return self._model.alpha - - @property - def beta(self): - return self._model.beta - - @property - def swap_rb(self): - return self._model.swap_rb - - @property - def l2_normalize(self): - return self._model.l2_normalize - - @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._model.size = wh - - @alpha.setter - def alpha(self, value): - assert isinstance(value, (list, tuple)),\ - "The value to set `alpha` must be type of tuple or list." - assert len(value) == 3,\ - "The value to set `alpha` must contatins 3 elements for each channels, but now it contains {} elements.".format( - len(value)) - self._model.alpha = value - - @beta.setter - def beta(self, value): - assert isinstance(value, (list, tuple)),\ - "The value to set `beta` must be type of tuple or list." - assert len(value) == 3,\ - "The value to set `beta` must contatins 3 elements for each channels, but now it contains {} elements.".format( - len(value)) - self._model.beta = value - - @swap_rb.setter - def swap_rb(self, value): - assert isinstance( - value, bool), "The value to set `swap_rb` must be type of bool." - self._model.swap_rb = value - - @l2_normalize.setter - def l2_normalize(self, value): - assert isinstance( - value, - bool), "The value to set `l2_normalize` must be type of bool." - self._model.l2_normalize = value - - -class VPL(FastDeployModel): - def __init__(self, - model_file, - params_file="", - runtime_option=None, - model_format=Frontend.ONNX): - # 调用基函数进行backend_option的初始化 - # 初始化后的option保存在self._runtime_option - super(VPL, self).__init__(runtime_option) - - self._model = C.vision.deepinsight.VPL( - model_file, params_file, self._runtime_option, model_format) - # 通过self.initialized判断整个模型的初始化是否成功 - assert self.initialized, "VPL initialize failed." - - def predict(self, input_image): - return self._model.predict(input_image) - - # 一些跟模型有关的属性封装 - # 多数是预处理相关,可通过修改如model.size = [112, 112]改变预处理时resize的大小(前提是模型支持) - @property - def size(self): - return self._model.size - - @property - def alpha(self): - return self._model.alpha - - @property - def beta(self): - return self._model.beta - - @property - def swap_rb(self): - return self._model.swap_rb - - @property - def l2_normalize(self): - return self._model.l2_normalize - - @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._model.size = wh - - @alpha.setter - def alpha(self, value): - assert isinstance(value, (list, tuple)),\ - "The value to set `alpha` must be type of tuple or list." - assert len(value) == 3,\ - "The value to set `alpha` must contatins 3 elements for each channels, but now it contains {} elements.".format( - len(value)) - self._model.alpha = value - - @beta.setter - def beta(self, value): - assert isinstance(value, (list, tuple)),\ - "The value to set `beta` must be type of tuple or list." - assert len(value) == 3,\ - "The value to set `beta` must contatins 3 elements for each channels, but now it contains {} elements.".format( - len(value)) - self._model.beta = value - - @swap_rb.setter - def swap_rb(self, value): - assert isinstance( - value, bool), "The value to set `swap_rb` must be type of bool." - self._model.swap_rb = value - - @l2_normalize.setter - def l2_normalize(self, value): - assert isinstance( - value, - bool), "The value to set `l2_normalize` must be type of bool." - self._model.l2_normalize = value diff --git a/fastdeploy/vision/detection/__init__.py b/fastdeploy/vision/detection/__init__.py index 92a292b54d..869b47ee50 100644 --- a/fastdeploy/vision/detection/__init__.py +++ b/fastdeploy/vision/detection/__init__.py @@ -13,8 +13,12 @@ # limitations under the License. from __future__ import absolute_import -from .yolov7 import YOLOv7 -from .yolor import YOLOR -from .scaled_yolov4 import ScaledYOLOv4 - +from .contrib.yolov7 import YOLOv7 +from .contrib.yolor import YOLOR +from .contrib.scaled_yolov4 import ScaledYOLOv4 +from .contrib.nanodet_plus import NanoDetPlus +from .contrib.yolox import YOLOX +from .contrib.yolov5 import YOLOv5 +from .contrib.yolov5lite import YOLOv5Lite +from .contrib.yolov6 import YOLOv6 from .ppdet import PPYOLOE, PPYOLO, PPYOLOv2, PaddleYOLOX, PicoDet, FasterRCNN, YOLOv3 diff --git a/fastdeploy/vision/detection/contrib/__init__.py b/fastdeploy/vision/detection/contrib/__init__.py new file mode 100644 index 0000000000..8034e10bfc --- /dev/null +++ b/fastdeploy/vision/detection/contrib/__init__.py @@ -0,0 +1,15 @@ +# 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 diff --git a/fastdeploy/vision/rangilyu/__init__.py b/fastdeploy/vision/detection/contrib/nanodet_plus.py similarity index 96% rename from fastdeploy/vision/rangilyu/__init__.py rename to fastdeploy/vision/detection/contrib/nanodet_plus.py index 412daa77a9..d7d28b794a 100644 --- a/fastdeploy/vision/rangilyu/__init__.py +++ b/fastdeploy/vision/detection/contrib/nanodet_plus.py @@ -14,8 +14,8 @@ from __future__ import absolute_import import logging -from ... import FastDeployModel, Frontend -from ... import c_lib_wrap as C +from .... import FastDeployModel, Frontend +from .... import c_lib_wrap as C class NanoDetPlus(FastDeployModel): @@ -28,7 +28,7 @@ def __init__(self, # 初始化后的option保存在self._runtime_option super(NanoDetPlus, self).__init__(runtime_option) - self._model = C.vision.rangilyu.NanoDetPlus( + self._model = C.vision.detection.NanoDetPlus( model_file, params_file, self._runtime_option, model_format) # 通过self.initialized判断整个模型的初始化是否成功 assert self.initialized, "NanoDetPlus initialize failed." diff --git a/fastdeploy/vision/detection/scaled_yolov4.py b/fastdeploy/vision/detection/contrib/scaled_yolov4.py similarity index 98% rename from fastdeploy/vision/detection/scaled_yolov4.py rename to fastdeploy/vision/detection/contrib/scaled_yolov4.py index f1be5ed918..dad85cde96 100644 --- a/fastdeploy/vision/detection/scaled_yolov4.py +++ b/fastdeploy/vision/detection/contrib/scaled_yolov4.py @@ -14,8 +14,8 @@ from __future__ import absolute_import import logging -from ... import FastDeployModel, Frontend -from ... import c_lib_wrap as C +from .... import FastDeployModel, Frontend +from .... import c_lib_wrap as C class ScaledYOLOv4(FastDeployModel): diff --git a/fastdeploy/vision/detection/yolor.py b/fastdeploy/vision/detection/contrib/yolor.py similarity index 98% rename from fastdeploy/vision/detection/yolor.py rename to fastdeploy/vision/detection/contrib/yolor.py index f2409f69c7..6da736aac1 100644 --- a/fastdeploy/vision/detection/yolor.py +++ b/fastdeploy/vision/detection/contrib/yolor.py @@ -14,8 +14,8 @@ from __future__ import absolute_import import logging -from ... import FastDeployModel, Frontend -from ... import c_lib_wrap as C +from .... import FastDeployModel, Frontend +from .... import c_lib_wrap as C class YOLOR(FastDeployModel): diff --git a/fastdeploy/vision/ultralytics/__init__.py b/fastdeploy/vision/detection/contrib/yolov5.py similarity index 97% rename from fastdeploy/vision/ultralytics/__init__.py rename to fastdeploy/vision/detection/contrib/yolov5.py index 56eaf20542..5a7711dd39 100644 --- a/fastdeploy/vision/ultralytics/__init__.py +++ b/fastdeploy/vision/detection/contrib/yolov5.py @@ -14,8 +14,8 @@ from __future__ import absolute_import import logging -from ... import FastDeployModel, Frontend -from ... import c_lib_wrap as C +from .... import FastDeployModel, Frontend +from .... import c_lib_wrap as C class YOLOv5(FastDeployModel): @@ -28,7 +28,7 @@ def __init__(self, # 初始化后的option保存在self._runtime_option super(YOLOv5, self).__init__(runtime_option) - self._model = C.vision.ultralytics.YOLOv5( + self._model = C.vision.detection.YOLOv5( model_file, params_file, self._runtime_option, model_format) # 通过self.initialized判断整个模型的初始化是否成功 assert self.initialized, "YOLOv5 initialize failed." diff --git a/fastdeploy/vision/ppogg/__init__.py b/fastdeploy/vision/detection/contrib/yolov5lite.py similarity index 97% rename from fastdeploy/vision/ppogg/__init__.py rename to fastdeploy/vision/detection/contrib/yolov5lite.py index 307a6473b3..2168f0cc5f 100644 --- a/fastdeploy/vision/ppogg/__init__.py +++ b/fastdeploy/vision/detection/contrib/yolov5lite.py @@ -14,8 +14,8 @@ from __future__ import absolute_import import logging -from ... import FastDeployModel, Frontend -from ... import c_lib_wrap as C +from .... import FastDeployModel, Frontend +from .... import c_lib_wrap as C class YOLOv5Lite(FastDeployModel): @@ -28,7 +28,7 @@ def __init__(self, # 初始化后的option保存在self._runtime_option super(YOLOv5Lite, self).__init__(runtime_option) - self._model = C.vision.ppogg.YOLOv5Lite( + self._model = C.vision.detection.YOLOv5Lite( model_file, params_file, self._runtime_option, model_format) # 通过self.initialized判断整个模型的初始化是否成功 assert self.initialized, "YOLOv5Lite initialize failed." diff --git a/fastdeploy/vision/meituan/__init__.py b/fastdeploy/vision/detection/contrib/yolov6.py similarity index 96% rename from fastdeploy/vision/meituan/__init__.py rename to fastdeploy/vision/detection/contrib/yolov6.py index bbc9bc9bcd..0ab7ca0331 100644 --- a/fastdeploy/vision/meituan/__init__.py +++ b/fastdeploy/vision/detection/contrib/yolov6.py @@ -14,8 +14,8 @@ from __future__ import absolute_import import logging -from ... import FastDeployModel, Frontend -from ... import c_lib_wrap as C +from .... import FastDeployModel, Frontend +from .... import c_lib_wrap as C class YOLOv6(FastDeployModel): @@ -28,7 +28,7 @@ def __init__(self, # 初始化后的option保存在self._runtime_option super(YOLOv6, self).__init__(runtime_option) - self._model = C.vision.meituan.YOLOv6( + self._model = C.vision.detection.YOLOv6( model_file, params_file, self._runtime_option, model_format) # 通过self.initialized判断整个模型的初始化是否成功 assert self.initialized, "YOLOv6 initialize failed." diff --git a/fastdeploy/vision/detection/yolov7.py b/fastdeploy/vision/detection/contrib/yolov7.py similarity index 98% rename from fastdeploy/vision/detection/yolov7.py rename to fastdeploy/vision/detection/contrib/yolov7.py index a4fd0009c1..e3437d3b40 100644 --- a/fastdeploy/vision/detection/yolov7.py +++ b/fastdeploy/vision/detection/contrib/yolov7.py @@ -14,8 +14,8 @@ from __future__ import absolute_import import logging -from ... import FastDeployModel, Frontend -from ... import c_lib_wrap as C +from .... import FastDeployModel, Frontend +from .... import c_lib_wrap as C class YOLOv7(FastDeployModel): diff --git a/fastdeploy/vision/megvii/__init__.py b/fastdeploy/vision/detection/contrib/yolox.py similarity index 93% rename from fastdeploy/vision/megvii/__init__.py rename to fastdeploy/vision/detection/contrib/yolox.py index 77f3c0cbeb..edd07d5171 100644 --- a/fastdeploy/vision/megvii/__init__.py +++ b/fastdeploy/vision/detection/contrib/yolox.py @@ -14,8 +14,8 @@ from __future__ import absolute_import import logging -from ... import FastDeployModel, Frontend -from ... import c_lib_wrap as C +from .... import FastDeployModel, Frontend +from .... import c_lib_wrap as C class YOLOX(FastDeployModel): @@ -28,8 +28,8 @@ def __init__(self, # 初始化后的option保存在self._runtime_option super(YOLOX, self).__init__(runtime_option) - self._model = C.vision.megvii.YOLOX(model_file, params_file, - self._runtime_option, model_format) + self._model = C.vision.detection.YOLOX( + model_file, params_file, self._runtime_option, model_format) # 通过self.initialized判断整个模型的初始化是否成功 assert self.initialized, "YOLOX initialize failed." diff --git a/fastdeploy/vision/facedet/__init__.py b/fastdeploy/vision/facedet/__init__.py new file mode 100644 index 0000000000..c9fa01b605 --- /dev/null +++ b/fastdeploy/vision/facedet/__init__.py @@ -0,0 +1,19 @@ +# 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 +from .contrib.yolov5face import YOLOv5Face +from .contrib.retinaface import RetinaFace +from .contrib.scrfd import SCRFD +from .contrib.ultraface import UltraFace diff --git a/fastdeploy/vision/facedet/contrib/__init__.py b/fastdeploy/vision/facedet/contrib/__init__.py new file mode 100644 index 0000000000..8034e10bfc --- /dev/null +++ b/fastdeploy/vision/facedet/contrib/__init__.py @@ -0,0 +1,15 @@ +# 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 diff --git a/fastdeploy/vision/biubug6/__init__.py b/fastdeploy/vision/facedet/contrib/retinaface.py similarity index 96% rename from fastdeploy/vision/biubug6/__init__.py rename to fastdeploy/vision/facedet/contrib/retinaface.py index 6b2e5f241c..6f7c7e3add 100644 --- a/fastdeploy/vision/biubug6/__init__.py +++ b/fastdeploy/vision/facedet/contrib/retinaface.py @@ -14,8 +14,8 @@ from __future__ import absolute_import import logging -from ... import FastDeployModel, Frontend -from ... import c_lib_wrap as C +from .... import FastDeployModel, Frontend +from .... import c_lib_wrap as C class RetinaFace(FastDeployModel): @@ -28,7 +28,7 @@ def __init__(self, # 初始化后的option保存在self._runtime_option super(RetinaFace, self).__init__(runtime_option) - self._model = C.vision.biubug6.RetinaFace( + self._model = C.vision.facedet.RetinaFace( model_file, params_file, self._runtime_option, model_format) # 通过self.initialized判断整个模型的初始化是否成功 assert self.initialized, "RetinaFace initialize failed." diff --git a/fastdeploy/vision/facedet/contrib/scrfd.py b/fastdeploy/vision/facedet/contrib/scrfd.py new file mode 100644 index 0000000000..0cad0c42bd --- /dev/null +++ b/fastdeploy/vision/facedet/contrib/scrfd.py @@ -0,0 +1,158 @@ +# 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, Frontend +from .... import c_lib_wrap as C + + +class SCRFD(FastDeployModel): + def __init__(self, + model_file, + params_file="", + runtime_option=None, + model_format=Frontend.ONNX): + # 调用基函数进行backend_option的初始化 + # 初始化后的option保存在self._runtime_option + super(SCRFD, self).__init__(runtime_option) + + self._model = C.vision.facedet.SCRFD( + model_file, params_file, self._runtime_option, model_format) + # 通过self.initialized判断整个模型的初始化是否成功 + assert self.initialized, "SCRFD initialize failed." + + def predict(self, input_image, conf_threshold=0.7, nms_iou_threshold=0.3): + return self._model.predict(input_image, conf_threshold, + nms_iou_threshold) + + # 一些跟SCRFD模型有关的属性封装 + # 多数是预处理相关,可通过修改如model.size = [640, 640]改变预处理时resize的大小(前提是模型支持) + @property + def size(self): + return self._model.size + + @property + def padding_value(self): + return self._model.padding_value + + @property + def is_no_pad(self): + return self._model.is_no_pad + + @property + def is_mini_pad(self): + return self._model.is_mini_pad + + @property + def is_scale_up(self): + return self._model.is_scale_up + + @property + def stride(self): + return self._model.stride + + @property + def downsample_strides(self): + return self._model.downsample_strides + + @property + def landmarks_per_face(self): + return self._model.landmarks_per_face + + @property + def use_kps(self): + return self._model.use_kps + + @property + def max_nms(self): + return self._model.max_nms + + @property + def num_anchors(self): + return self._model.num_anchors + + @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._model.size = wh + + @padding_value.setter + def padding_value(self, value): + assert isinstance( + value, + list), "The value to set `padding_value` must be type of list." + self._model.padding_value = value + + @is_no_pad.setter + def is_no_pad(self, value): + assert isinstance( + value, bool), "The value to set `is_no_pad` must be type of bool." + self._model.is_no_pad = value + + @is_mini_pad.setter + def is_mini_pad(self, value): + assert isinstance( + value, + bool), "The value to set `is_mini_pad` must be type of bool." + self._model.is_mini_pad = 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._model.is_scale_up = value + + @stride.setter + def stride(self, value): + assert isinstance( + value, int), "The value to set `stride` must be type of int." + self._model.stride = value + + @downsample_strides.setter + def downsample_strides(self, value): + assert isinstance( + value, + list), "The value to set `downsample_strides` must be type of list." + self._model.downsample_strides = value + + @landmarks_per_face.setter + def landmarks_per_face(self, value): + assert isinstance( + value, + int), "The value to set `landmarks_per_face` must be type of int." + self._model.landmarks_per_face = value + + @use_kps.setter + def use_kps(self, value): + assert isinstance( + value, bool), "The value to set `use_kps` must be type of bool." + self._model.use_kps = value + + @max_nms.setter + def max_nms(self, value): + assert isinstance( + value, int), "The value to set `max_nms` must be type of int." + self._model.max_nms = value + + @num_anchors.setter + def num_anchors(self, value): + assert isinstance( + value, int), "The value to set `num_anchors` must be type of int." + self._model.num_anchors = value diff --git a/fastdeploy/vision/linzaer/__init__.py b/fastdeploy/vision/facedet/contrib/ultraface.py similarity index 94% rename from fastdeploy/vision/linzaer/__init__.py rename to fastdeploy/vision/facedet/contrib/ultraface.py index ce76663805..9b19af574f 100644 --- a/fastdeploy/vision/linzaer/__init__.py +++ b/fastdeploy/vision/facedet/contrib/ultraface.py @@ -14,8 +14,8 @@ from __future__ import absolute_import import logging -from ... import FastDeployModel, Frontend -from ... import c_lib_wrap as C +from .... import FastDeployModel, Frontend +from .... import c_lib_wrap as C class UltraFace(FastDeployModel): @@ -28,7 +28,7 @@ def __init__(self, # 初始化后的option保存在self._runtime_option super(UltraFace, self).__init__(runtime_option) - self._model = C.vision.linzaer.UltraFace( + self._model = C.vision.facedet.UltraFace( model_file, params_file, self._runtime_option, model_format) # 通过self.initialized判断整个模型的初始化是否成功 assert self.initialized, "UltraFace initialize failed." diff --git a/fastdeploy/vision/deepcam/__init__.py b/fastdeploy/vision/facedet/contrib/yolov5face.py similarity index 96% rename from fastdeploy/vision/deepcam/__init__.py rename to fastdeploy/vision/facedet/contrib/yolov5face.py index 2cde26998f..0a8d2511b4 100644 --- a/fastdeploy/vision/deepcam/__init__.py +++ b/fastdeploy/vision/facedet/contrib/yolov5face.py @@ -14,8 +14,8 @@ from __future__ import absolute_import import logging -from ... import FastDeployModel, Frontend -from ... import c_lib_wrap as C +from .... import FastDeployModel, Frontend +from .... import c_lib_wrap as C class YOLOv5Face(FastDeployModel): @@ -28,7 +28,7 @@ def __init__(self, # 初始化后的option保存在self._runtime_option super(YOLOv5Face, self).__init__(runtime_option) - self._model = C.vision.deepcam.YOLOv5Face( + self._model = C.vision.facedet.YOLOv5Face( model_file, params_file, self._runtime_option, model_format) # 通过self.initialized判断整个模型的初始化是否成功 assert self.initialized, "YOLOv5Face initialize failed." diff --git a/fastdeploy/vision/faceid/__init__.py b/fastdeploy/vision/faceid/__init__.py new file mode 100644 index 0000000000..7c1f3fd66c --- /dev/null +++ b/fastdeploy/vision/faceid/__init__.py @@ -0,0 +1,20 @@ +# 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 +from .contrib.arcface import ArcFace +from .contrib.cosface import CosFace +from .contrib.insightface_rec import InsightFaceRecognitionModel +from .contrib.partial_fc import PartialFC +from .contrib.vpl import VPL diff --git a/fastdeploy/vision/faceid/contrib/__init__.py b/fastdeploy/vision/faceid/contrib/__init__.py new file mode 100644 index 0000000000..8034e10bfc --- /dev/null +++ b/fastdeploy/vision/faceid/contrib/__init__.py @@ -0,0 +1,15 @@ +# 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 diff --git a/fastdeploy/vision/faceid/contrib/arcface.py b/fastdeploy/vision/faceid/contrib/arcface.py new file mode 100644 index 0000000000..7b1160ede1 --- /dev/null +++ b/fastdeploy/vision/faceid/contrib/arcface.py @@ -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. + +from __future__ import absolute_import +import logging +from .... import FastDeployModel, Frontend +from .... import c_lib_wrap as C +from ..contrib.insightface_rec import InsightFaceRecognitionModel + + +class ArcFace(FastDeployModel): + def __init__(self, + model_file, + params_file="", + runtime_option=None, + model_format=Frontend.ONNX): + # 调用基函数进行backend_option的初始化 + # 初始化后的option保存在self._runtime_option + super(ArcFace, self).__init__(runtime_option) + + self._model = C.vision.faceid.ArcFace( + model_file, params_file, self._runtime_option, model_format) + # 通过self.initialized判断整个模型的初始化是否成功 + assert self.initialized, "ArcFace initialize failed." + + def predict(self, input_image): + return self._model.predict(input_image) + + # 一些跟模型有关的属性封装 + # 多数是预处理相关,可通过修改如model.size = [112, 112]改变预处理时resize的大小(前提是模型支持) + @property + def size(self): + return self._model.size + + @property + def alpha(self): + return self._model.alpha + + @property + def beta(self): + return self._model.beta + + @property + def swap_rb(self): + return self._model.swap_rb + + @property + def l2_normalize(self): + return self._model.l2_normalize + + @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._model.size = wh + + @alpha.setter + def alpha(self, value): + assert isinstance(value, (list, tuple)),\ + "The value to set `alpha` must be type of tuple or list." + assert len(value) == 3,\ + "The value to set `alpha` must contatins 3 elements for each channels, but now it contains {} elements.".format( + len(value)) + self._model.alpha = value + + @beta.setter + def beta(self, value): + assert isinstance(value, (list, tuple)),\ + "The value to set `beta` must be type of tuple or list." + assert len(value) == 3,\ + "The value to set `beta` must contatins 3 elements for each channels, but now it contains {} elements.".format( + len(value)) + self._model.beta = value + + @swap_rb.setter + def swap_rb(self, value): + assert isinstance( + value, bool), "The value to set `swap_rb` must be type of bool." + self._model.swap_rb = value + + @l2_normalize.setter + def l2_normalize(self, value): + assert isinstance( + value, + bool), "The value to set `l2_normalize` must be type of bool." + self._model.l2_normalize = value diff --git a/fastdeploy/vision/faceid/contrib/cosface.py b/fastdeploy/vision/faceid/contrib/cosface.py new file mode 100644 index 0000000000..a6029b38bc --- /dev/null +++ b/fastdeploy/vision/faceid/contrib/cosface.py @@ -0,0 +1,99 @@ +# 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, Frontend +from .... import c_lib_wrap as C + + +class CosFace(FastDeployModel): + def __init__(self, + model_file, + params_file="", + runtime_option=None, + model_format=Frontend.ONNX): + # 调用基函数进行backend_option的初始化 + # 初始化后的option保存在self._runtime_option + super(CosFace, self).__init__(runtime_option) + + self._model = C.vision.faceid.CosFace( + model_file, params_file, self._runtime_option, model_format) + # 通过self.initialized判断整个模型的初始化是否成功 + assert self.initialized, "CosFace initialize failed." + + def predict(self, input_image): + return self._model.predict(input_image) + + # 一些跟模型有关的属性封装 + # 多数是预处理相关,可通过修改如model.size = [112, 112]改变预处理时resize的大小(前提是模型支持) + @property + def size(self): + return self._model.size + + @property + def alpha(self): + return self._model.alpha + + @property + def beta(self): + return self._model.beta + + @property + def swap_rb(self): + return self._model.swap_rb + + @property + def l2_normalize(self): + return self._model.l2_normalize + + @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._model.size = wh + + @alpha.setter + def alpha(self, value): + assert isinstance(value, (list, tuple)),\ + "The value to set `alpha` must be type of tuple or list." + assert len(value) == 3,\ + "The value to set `alpha` must contatins 3 elements for each channels, but now it contains {} elements.".format( + len(value)) + self._model.alpha = value + + @beta.setter + def beta(self, value): + assert isinstance(value, (list, tuple)),\ + "The value to set `beta` must be type of tuple or list." + assert len(value) == 3,\ + "The value to set `beta` must contatins 3 elements for each channels, but now it contains {} elements.".format( + len(value)) + self._model.beta = value + + @swap_rb.setter + def swap_rb(self, value): + assert isinstance( + value, bool), "The value to set `swap_rb` must be type of bool." + self._model.swap_rb = value + + @l2_normalize.setter + def l2_normalize(self, value): + assert isinstance( + value, + bool), "The value to set `l2_normalize` must be type of bool." + self._model.l2_normalize = value diff --git a/fastdeploy/vision/faceid/contrib/insightface_rec.py b/fastdeploy/vision/faceid/contrib/insightface_rec.py new file mode 100644 index 0000000000..dcbe7341e9 --- /dev/null +++ b/fastdeploy/vision/faceid/contrib/insightface_rec.py @@ -0,0 +1,99 @@ +# 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, Frontend +from .... import c_lib_wrap as C + + +class InsightFaceRecognitionModel(FastDeployModel): + def __init__(self, + model_file, + params_file="", + runtime_option=None, + model_format=Frontend.ONNX): + # 调用基函数进行backend_option的初始化 + # 初始化后的option保存在self._runtime_option + super(InsightFaceRecognitionModel, self).__init__(runtime_option) + + self._model = C.vision.faceid.InsightFaceRecognitionModel( + model_file, params_file, self._runtime_option, model_format) + # 通过self.initialized判断整个模型的初始化是否成功 + assert self.initialized, "InsightFaceRecognitionModel initialize failed." + + def predict(self, input_image): + return self._model.predict(input_image) + + # 一些跟InsightFaceRecognitionModel模型有关的属性封装 + # 多数是预处理相关,可通过修改如model.size = [112, 112]改变预处理时resize的大小(前提是模型支持) + @property + def size(self): + return self._model.size + + @property + def alpha(self): + return self._model.alpha + + @property + def beta(self): + return self._model.beta + + @property + def swap_rb(self): + return self._model.swap_rb + + @property + def l2_normalize(self): + return self._model.l2_normalize + + @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._model.size = wh + + @alpha.setter + def alpha(self, value): + assert isinstance(value, (list, tuple)),\ + "The value to set `alpha` must be type of tuple or list." + assert len(value) == 3,\ + "The value to set `alpha` must contatins 3 elements for each channels, but now it contains {} elements.".format( + len(value)) + self._model.alpha = value + + @beta.setter + def beta(self, value): + assert isinstance(value, (list, tuple)),\ + "The value to set `beta` must be type of tuple or list." + assert len(value) == 3,\ + "The value to set `beta` must contatins 3 elements for each channels, but now it contains {} elements.".format( + len(value)) + self._model.beta = value + + @swap_rb.setter + def swap_rb(self, value): + assert isinstance( + value, bool), "The value to set `swap_rb` must be type of bool." + self._model.swap_rb = value + + @l2_normalize.setter + def l2_normalize(self, value): + assert isinstance( + value, + bool), "The value to set `l2_normalize` must be type of bool." + self._model.l2_normalize = value diff --git a/fastdeploy/vision/faceid/contrib/partial_fc.py b/fastdeploy/vision/faceid/contrib/partial_fc.py new file mode 100644 index 0000000000..f19457b945 --- /dev/null +++ b/fastdeploy/vision/faceid/contrib/partial_fc.py @@ -0,0 +1,99 @@ +# 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, Frontend +from .... import c_lib_wrap as C + + +class PartialFC(FastDeployModel): + def __init__(self, + model_file, + params_file="", + runtime_option=None, + model_format=Frontend.ONNX): + # 调用基函数进行backend_option的初始化 + # 初始化后的option保存在self._runtime_option + super(PartialFC, self).__init__(runtime_option) + + self._model = C.vision.faceid.PartialFC( + model_file, params_file, self._runtime_option, model_format) + # 通过self.initialized判断整个模型的初始化是否成功 + assert self.initialized, "PartialFC initialize failed." + + def predict(self, input_image): + return self._model.predict(input_image) + + # 一些跟模型有关的属性封装 + # 多数是预处理相关,可通过修改如model.size = [112, 112]改变预处理时resize的大小(前提是模型支持) + @property + def size(self): + return self._model.size + + @property + def alpha(self): + return self._model.alpha + + @property + def beta(self): + return self._model.beta + + @property + def swap_rb(self): + return self._model.swap_rb + + @property + def l2_normalize(self): + return self._model.l2_normalize + + @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._model.size = wh + + @alpha.setter + def alpha(self, value): + assert isinstance(value, (list, tuple)),\ + "The value to set `alpha` must be type of tuple or list." + assert len(value) == 3,\ + "The value to set `alpha` must contatins 3 elements for each channels, but now it contains {} elements.".format( + len(value)) + self._model.alpha = value + + @beta.setter + def beta(self, value): + assert isinstance(value, (list, tuple)),\ + "The value to set `beta` must be type of tuple or list." + assert len(value) == 3,\ + "The value to set `beta` must contatins 3 elements for each channels, but now it contains {} elements.".format( + len(value)) + self._model.beta = value + + @swap_rb.setter + def swap_rb(self, value): + assert isinstance( + value, bool), "The value to set `swap_rb` must be type of bool." + self._model.swap_rb = value + + @l2_normalize.setter + def l2_normalize(self, value): + assert isinstance( + value, + bool), "The value to set `l2_normalize` must be type of bool." + self._model.l2_normalize = value diff --git a/fastdeploy/vision/faceid/contrib/vpl.py b/fastdeploy/vision/faceid/contrib/vpl.py new file mode 100644 index 0000000000..67fff74ba2 --- /dev/null +++ b/fastdeploy/vision/faceid/contrib/vpl.py @@ -0,0 +1,99 @@ +# 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, Frontend +from .... import c_lib_wrap as C + + +class VPL(FastDeployModel): + def __init__(self, + model_file, + params_file="", + runtime_option=None, + model_format=Frontend.ONNX): + # 调用基函数进行backend_option的初始化 + # 初始化后的option保存在self._runtime_option + super(VPL, self).__init__(runtime_option) + + self._model = C.vision.faceid.VPL(model_file, params_file, + self._runtime_option, model_format) + # 通过self.initialized判断整个模型的初始化是否成功 + assert self.initialized, "VPL initialize failed." + + def predict(self, input_image): + return self._model.predict(input_image) + + # 一些跟模型有关的属性封装 + # 多数是预处理相关,可通过修改如model.size = [112, 112]改变预处理时resize的大小(前提是模型支持) + @property + def size(self): + return self._model.size + + @property + def alpha(self): + return self._model.alpha + + @property + def beta(self): + return self._model.beta + + @property + def swap_rb(self): + return self._model.swap_rb + + @property + def l2_normalize(self): + return self._model.l2_normalize + + @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._model.size = wh + + @alpha.setter + def alpha(self, value): + assert isinstance(value, (list, tuple)),\ + "The value to set `alpha` must be type of tuple or list." + assert len(value) == 3,\ + "The value to set `alpha` must contatins 3 elements for each channels, but now it contains {} elements.".format( + len(value)) + self._model.alpha = value + + @beta.setter + def beta(self, value): + assert isinstance(value, (list, tuple)),\ + "The value to set `beta` must be type of tuple or list." + assert len(value) == 3,\ + "The value to set `beta` must contatins 3 elements for each channels, but now it contains {} elements.".format( + len(value)) + self._model.beta = value + + @swap_rb.setter + def swap_rb(self, value): + assert isinstance( + value, bool), "The value to set `swap_rb` must be type of bool." + self._model.swap_rb = value + + @l2_normalize.setter + def l2_normalize(self, value): + assert isinstance( + value, + bool), "The value to set `l2_normalize` must be type of bool." + self._model.l2_normalize = value diff --git a/fastdeploy/vision/matting/__init__.py b/fastdeploy/vision/matting/__init__.py new file mode 100644 index 0000000000..1411461352 --- /dev/null +++ b/fastdeploy/vision/matting/__init__.py @@ -0,0 +1,16 @@ +# 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 +from .contrib.modnet import MODNet diff --git a/fastdeploy/vision/matting/contrib/__init__.py b/fastdeploy/vision/matting/contrib/__init__.py new file mode 100644 index 0000000000..8034e10bfc --- /dev/null +++ b/fastdeploy/vision/matting/contrib/__init__.py @@ -0,0 +1,15 @@ +# 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 diff --git a/fastdeploy/vision/zhkkke/__init__.py b/fastdeploy/vision/matting/contrib/modnet.py similarity index 96% rename from fastdeploy/vision/zhkkke/__init__.py rename to fastdeploy/vision/matting/contrib/modnet.py index b301777c58..82ee542a13 100644 --- a/fastdeploy/vision/zhkkke/__init__.py +++ b/fastdeploy/vision/matting/contrib/modnet.py @@ -14,8 +14,8 @@ from __future__ import absolute_import import logging -from ... import FastDeployModel, Frontend -from ... import c_lib_wrap as C +from .... import FastDeployModel, Frontend +from .... import c_lib_wrap as C class MODNet(FastDeployModel): @@ -28,7 +28,7 @@ def __init__(self, # 初始化后的option保存在self._runtime_option super(MODNet, self).__init__(runtime_option) - self._model = C.vision.zhkkke.MODNet( + self._model = C.vision.matting.MODNet( model_file, params_file, self._runtime_option, model_format) # 通过self.initialized判断整个模型的初始化是否成功 assert self.initialized, "MODNet initialize failed." diff --git a/fastdeploy/vision/visualize/__init__.py b/fastdeploy/vision/visualize/__init__.py index 9770dfd1dd..b2b8e90add 100644 --- a/fastdeploy/vision/visualize/__init__.py +++ b/fastdeploy/vision/visualize/__init__.py @@ -17,12 +17,12 @@ from ... import c_lib_wrap as C -def vis_detection(im_data, det_result, line_size=2, font_size=0.5): +def vis_detection(im_data, det_result, line_size=1, font_size=0.5): return C.vision.Visualize.vis_detection(im_data, det_result, line_size, font_size) -def vis_face_detection(im_data, face_det_result, line_size=2, font_size=0.5): +def vis_face_detection(im_data, face_det_result, line_size=1, font_size=0.5): return C.vision.Visualize.vis_face_detection(im_data, face_det_result, line_size, font_size) diff --git a/fastdeploy/vision/wongkinyiu/__init__.py b/fastdeploy/vision/wongkinyiu/__init__.py deleted file mode 100644 index a0d6624c20..0000000000 --- a/fastdeploy/vision/wongkinyiu/__init__.py +++ /dev/null @@ -1,312 +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. - -from __future__ import absolute_import -import logging -from ... import FastDeployModel, Frontend -from ... import c_lib_wrap as C - - -class YOLOv7(FastDeployModel): - def __init__(self, - model_file, - params_file="", - runtime_option=None, - model_format=Frontend.ONNX): - # 调用基函数进行backend_option的初始化 - # 初始化后的option保存在self._runtime_option - super(YOLOv7, self).__init__(runtime_option) - - self._model = C.vision.wongkinyiu.YOLOv7( - model_file, params_file, self._runtime_option, model_format) - # 通过self.initialized判断整个模型的初始化是否成功 - assert self.initialized, "YOLOv7 initialize failed." - - def predict(self, input_image, conf_threshold=0.25, nms_iou_threshold=0.5): - return self._model.predict(input_image, conf_threshold, - nms_iou_threshold) - - # 一些跟YOLOv7模型有关的属性封装 - # 多数是预处理相关,可通过修改如model.size = [1280, 1280]改变预处理时resize的大小(前提是模型支持) - @property - def size(self): - return self._model.size - - @property - def padding_value(self): - return self._model.padding_value - - @property - def is_no_pad(self): - return self._model.is_no_pad - - @property - def is_mini_pad(self): - return self._model.is_mini_pad - - @property - def is_scale_up(self): - return self._model.is_scale_up - - @property - def stride(self): - return self._model.stride - - @property - def max_wh(self): - return self._model.max_wh - - @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._model.size = wh - - @padding_value.setter - def padding_value(self, value): - assert isinstance( - value, - list), "The value to set `padding_value` must be type of list." - self._model.padding_value = value - - @is_no_pad.setter - def is_no_pad(self, value): - assert isinstance( - value, bool), "The value to set `is_no_pad` must be type of bool." - self._model.is_no_pad = value - - @is_mini_pad.setter - def is_mini_pad(self, value): - assert isinstance( - value, - bool), "The value to set `is_mini_pad` must be type of bool." - self._model.is_mini_pad = 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._model.is_scale_up = value - - @stride.setter - def stride(self, value): - assert isinstance( - value, int), "The value to set `stride` must be type of int." - self._model.stride = value - - @max_wh.setter - def max_wh(self, value): - assert isinstance( - value, float), "The value to set `max_wh` must be type of float." - self._model.max_wh = value - - -class YOLOR(FastDeployModel): - def __init__(self, - model_file, - params_file="", - runtime_option=None, - model_format=Frontend.ONNX): - # 调用基函数进行backend_option的初始化 - # 初始化后的option保存在self._runtime_option - super(YOLOR, self).__init__(runtime_option) - - self._model = C.vision.wongkinyiu.YOLOR( - model_file, params_file, self._runtime_option, model_format) - # 通过self.initialized判断整个模型的初始化是否成功 - assert self.initialized, "YOLOR initialize failed." - - def predict(self, input_image, conf_threshold=0.25, nms_iou_threshold=0.5): - return self._model.predict(input_image, conf_threshold, - nms_iou_threshold) - - # 一些跟YOLOR模型有关的属性封装 - # 多数是预处理相关,可通过修改如model.size = [1280, 1280]改变预处理时resize的大小(前提是模型支持) - @property - def size(self): - return self._model.size - - @property - def padding_value(self): - return self._model.padding_value - - @property - def is_no_pad(self): - return self._model.is_no_pad - - @property - def is_mini_pad(self): - return self._model.is_mini_pad - - @property - def is_scale_up(self): - return self._model.is_scale_up - - @property - def stride(self): - return self._model.stride - - @property - def max_wh(self): - return self._model.max_wh - - @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._model.size = wh - - @padding_value.setter - def padding_value(self, value): - assert isinstance( - value, - list), "The value to set `padding_value` must be type of list." - self._model.padding_value = value - - @is_no_pad.setter - def is_no_pad(self, value): - assert isinstance( - value, bool), "The value to set `is_no_pad` must be type of bool." - self._model.is_no_pad = value - - @is_mini_pad.setter - def is_mini_pad(self, value): - assert isinstance( - value, - bool), "The value to set `is_mini_pad` must be type of bool." - self._model.is_mini_pad = 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._model.is_scale_up = value - - @stride.setter - def stride(self, value): - assert isinstance( - value, int), "The value to set `stride` must be type of int." - self._model.stride = value - - @max_wh.setter - def max_wh(self, value): - assert isinstance( - value, float), "The value to set `max_wh` must be type of float." - self._model.max_wh = value - - -class ScaledYOLOv4(FastDeployModel): - def __init__(self, - model_file, - params_file="", - runtime_option=None, - model_format=Frontend.ONNX): - # 调用基函数进行backend_option的初始化 - # 初始化后的option保存在self._runtime_option - super(ScaledYOLOv4, self).__init__(runtime_option) - - self._model = C.vision.wongkinyiu.ScaledYOLOv4( - model_file, params_file, self._runtime_option, model_format) - # 通过self.initialized判断整个模型的初始化是否成功 - assert self.initialized, "ScaledYOLOv4 initialize failed." - - def predict(self, input_image, conf_threshold=0.25, nms_iou_threshold=0.5): - return self._model.predict(input_image, conf_threshold, - nms_iou_threshold) - - # 一些跟ScaledYOLOv4模型有关的属性封装 - # 多数是预处理相关,可通过修改如model.size = [1280, 1280]改变预处理时resize的大小(前提是模型支持) - @property - def size(self): - return self._model.size - - @property - def padding_value(self): - return self._model.padding_value - - @property - def is_no_pad(self): - return self._model.is_no_pad - - @property - def is_mini_pad(self): - return self._model.is_mini_pad - - @property - def is_scale_up(self): - return self._model.is_scale_up - - @property - def stride(self): - return self._model.stride - - @property - def max_wh(self): - return self._model.max_wh - - @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._model.size = wh - - @padding_value.setter - def padding_value(self, value): - assert isinstance( - value, - list), "The value to set `padding_value` must be type of list." - self._model.padding_value = value - - @is_no_pad.setter - def is_no_pad(self, value): - assert isinstance( - value, bool), "The value to set `is_no_pad` must be type of bool." - self._model.is_no_pad = value - - @is_mini_pad.setter - def is_mini_pad(self, value): - assert isinstance( - value, - bool), "The value to set `is_mini_pad` must be type of bool." - self._model.is_mini_pad = 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._model.is_scale_up = value - - @stride.setter - def stride(self, value): - assert isinstance( - value, int), "The value to set `stride` must be type of int." - self._model.stride = value - - @max_wh.setter - def max_wh(self, value): - assert isinstance( - value, float), "The value to set `max_wh` must be type of float." - self._model.max_wh = value diff --git a/new_examples/vision/detection/yolov7/cpp/README.md b/new_examples/vision/detection/yolov7/cpp/README.md index 22a5368251..6f6812b53c 100644 --- a/new_examples/vision/detection/yolov7/cpp/README.md +++ b/new_examples/vision/detection/yolov7/cpp/README.md @@ -35,7 +35,7 @@ wget https://gitee.com/paddlepaddle/PaddleDetection/raw/release/2.4/demo/0000000 ### YOLOv7类 ``` -fastdeploy::vision::wongkinyiu::YOLOv7( +fastdeploy::vision::detection::YOLOv7( const string& model_file, const string& params_file = "", const RuntimeOption& runtime_option = RuntimeOption(), diff --git a/new_examples/vision/detection/yolov7/cpp/infer.cc b/new_examples/vision/detection/yolov7/cpp/infer.cc index d5d4ad9812..1ddca8f1c8 100644 --- a/new_examples/vision/detection/yolov7/cpp/infer.cc +++ b/new_examples/vision/detection/yolov7/cpp/infer.cc @@ -35,7 +35,7 @@ void CpuInfer(const std::string& model_file, const std::string& image_file) { std::cout << "Visualized result saved in ./vis_result.jpg" << std::endl; } -void GpuInfer() { +void GpuInfer(const std::string& model_file, const std::string& image_file) { auto option = fastdeploy::RuntimeOption(); option.UseGpu(); auto model = fastdeploy::vision::detection::YOLOv7(model_file, "", option); @@ -58,12 +58,11 @@ void GpuInfer() { std::cout << "Visualized result saved in ./vis_result.jpg" << std::endl; } -void TrtInfer() { +void TrtInfer(const std::string& model_file, const std::string& image_file) { auto option = fastdeploy::RuntimeOption(); option.UseGpu(); option.UseTrtBackend(); - option.SetTrtInputShape("image", {1, 3, 320, 320}, {1, 3, 640, 640}, - {1, 3, 1280, 1280}); + option.SetTrtInputShape("images", {1, 3, 640, 640}); auto model = fastdeploy::vision::detection::YOLOv7(model_file, "", option); if (!model.Initialized()) { std::cerr << "Failed to initialize." << std::endl; @@ -96,11 +95,11 @@ int main(int argc, char* argv[]) { } if (std::atoi(argv[3]) == 0) { - CpuInfer(); + CpuInfer(argv[1], argv[2]); } else if (std::atoi(argv[3]) == 1) { - GpuInfer(); + GpuInfer(argv[1], argv[2]); } else if (std::atoi(argv[3]) == 2) { - TrtInfer(); + TrtInfer(argv[1], argv[2]); } return 0; } diff --git a/new_examples/vision/detection/yolov7/python/README.md b/new_examples/vision/detection/yolov7/python/README.md index 138b8e9458..82c1362bea 100644 --- a/new_examples/vision/detection/yolov7/python/README.md +++ b/new_examples/vision/detection/yolov7/python/README.md @@ -10,7 +10,8 @@ ``` #下载yolov7模型文件和测试图片 wget https://bj.bcebos.com/paddlehub/fastdeploy/yolov7.onnx -wget https://gitee.com/paddlepaddle/PaddleDetection/raw/release/2.4/demo/000000087038.jpg +wget https://gitee.com/paddlepaddle/PaddleDetection/raw/release/2.4/demo/000000014439.jpg + #下载部署示例代码 git clone https://github.com/PaddlePaddle/FastDeploy.git diff --git a/new_examples/vision/detection/yolov7/python/infer.py b/new_examples/vision/detection/yolov7/python/infer.py index acc8c3a509..574755c3a3 100644 --- a/new_examples/vision/detection/yolov7/python/infer.py +++ b/new_examples/vision/detection/yolov7/python/infer.py @@ -31,8 +31,7 @@ def build_option(args): if args.use_trt: option.use_trt_backend() - option.set_trt_input_shape("image", [1, 3, 320, 320], - [1, 3, 640, 640], [1, 3, 1280, 1280]) + option.set_trt_input_shape("images", [1, 3, 640, 640]) return option