├── .clang-format ├── .github └── workflows │ ├── build_620a.yml │ ├── build_620q_uclibc.yaml │ ├── build_630c_glibc.yaml │ └── build_650.yml ├── .gitignore ├── CMakeLists.txt ├── LICENSE ├── README.md ├── README_EN.md ├── benchmark ├── Benchmark_AX620A.md ├── Benchmark_AX620Q.md ├── Benchmark_AX630C.md └── Benchmark_AX650N.md ├── cmake ├── ax620.cmake ├── ax620e.cmake ├── ax650.cmake ├── check.cmake └── summary.cmake ├── docs ├── AX620A.md ├── AX620Q.md ├── AX620U.md ├── AX630A.md ├── AX630C.md ├── AX650N.md ├── ax620 │ ├── ax_pose_ppl.jpg │ ├── body_seg_bg_res.jpg │ ├── face_parsing_res.jpg │ ├── handpose.png │ ├── hrnet.png │ ├── hrnet_animal.jpg │ ├── monodlex.png │ ├── palm_detection.jpg │ ├── scrfd.jpg │ ├── seg_res.jpg │ ├── yolopv2.jpg │ ├── yolov3_paddle.jpg │ ├── yolov5_lite_out.jpg │ ├── yolov5s.jpg │ ├── yolov5s_face.jpg │ ├── yolov5s_license_plate_out.jpg │ ├── yolov5s_seg.jpg │ ├── yolov5s_visdrone.jpg │ ├── yolov6s.jpg │ ├── yolov7-tiny.jpg │ ├── yolov7s_face.jpg │ ├── yolov7s_palm.jpg │ ├── yolov8s.jpg │ └── yolov8s_seg.jpg ├── ax620e │ ├── depth_anything_out.png │ ├── simcc_out.jpg │ ├── yolov10s_out.jpg │ ├── yolov5_face_out.jpg │ ├── yolov5s_out.jpg │ ├── yolov5s_seg_out.jpg │ ├── yolov6_out.jpg │ ├── yolov7_face_out.jpg │ ├── yolov7_out.jpg │ ├── yolov8s_out.jpg │ ├── yolov8s_pose_out.jpg │ └── yolox_out.jpg ├── ax650 │ ├── crowdcount_out.jpg │ ├── depth_anything_out.png │ ├── dinov2_mask_out.png │ ├── dog-chai.jpeg │ ├── glpdepth_out.png │ ├── hrnet_out.jpg │ ├── pfld_out.jpg │ ├── ppyoloe_out.jpg │ ├── realesrgan_in.png │ ├── realesrgan_out.jpg │ ├── scrfd_out.jpg │ ├── segformer_out.png │ ├── simcc_out.jpg │ ├── yolo11_out.jpg │ ├── yolo11_pose_out.jpg │ ├── yolo11_seg_out.jpg │ ├── yolo_nas_out.jpg │ ├── yolo_world_open_out.jpg │ ├── yolo_world_out.jpg │ ├── yolov10s_out.jpg │ ├── yolov5_face_out.jpg │ ├── yolov5s_out.jpg │ ├── yolov5s_seg_out.jpg │ ├── yolov6_out.jpg │ ├── yolov7_face_out.jpg │ ├── yolov7_out.jpg │ ├── yolov8_pose_out.jpg │ ├── yolov8_seg_out.jpg │ ├── yolov8s_obb_out.jpg │ ├── yolov8s_out.jpg │ ├── yolov9_out.jpg │ └── yolox_out.jpg ├── compile.md ├── compile_620.md ├── compile_620e.md ├── compile_630.md └── compile_650.md ├── examples ├── CMakeLists.txt ├── ax620 │ ├── CMakeLists.txt │ ├── README.md │ ├── ax_classification_accuracy.cc │ ├── ax_classification_nv12_resize_opt.cc │ ├── ax_classification_nv12_resize_steps.cc │ ├── ax_classification_steps.cc │ ├── ax_crnn_steps.cc │ ├── ax_face_parsing_steps.cc │ ├── ax_handpose_steps.cc │ ├── ax_hrnet_animal_steps.cc │ ├── ax_hrnet_steps.cc │ ├── ax_ld_model_mmap.cc │ ├── ax_models_load_inspect.cc │ ├── ax_monodlex_steps.cc │ ├── ax_nanodet_steps.cc │ ├── ax_paddle_mobilehumseg_steps.cc │ ├── ax_paddle_mobileseg.cc │ ├── ax_paddle_yolov3_steps.cc │ ├── ax_palm_detection_steps.cc │ ├── ax_pose_ppl_steps.cc │ ├── ax_robot_obstacle_detect_steps.cc │ ├── ax_scrfd_steps.cc │ ├── ax_yolo_fastest_body_steps.cc │ ├── ax_yolo_fastest_steps.cc │ ├── ax_yolopv2_steps.cc │ ├── ax_yolov3_accuracy.cc │ ├── ax_yolov3_steps.cc │ ├── ax_yolov3_tiny_steps.cc │ ├── ax_yolov4_steps.cc │ ├── ax_yolov4_tiny_3l_steps.cc │ ├── ax_yolov4_tiny_steps.cc │ ├── ax_yolov5_lite_steps.cc │ ├── ax_yolov5s_620u_steps.cc │ ├── ax_yolov5s_face_steps.cc │ ├── ax_yolov5s_license_plate_steps.cc │ ├── ax_yolov5s_seg_steps.cc │ ├── ax_yolov5s_steps.cc │ ├── ax_yolov5s_visdrone_steps.cc │ ├── ax_yolov6s_steps.cc │ ├── ax_yolov7_steps.cc │ ├── ax_yolov7s_face_steps.cc │ ├── ax_yolov7s_palm_steps.cc │ ├── ax_yolov8s_pose_steps.cc │ ├── ax_yolov8s_seg_steps.cc │ ├── ax_yolov8s_steps.cc │ ├── ax_yoloxs_steps.cc │ ├── cv │ │ ├── cv.hpp │ │ └── utils.hpp │ ├── middleware │ │ ├── common_ax620.hpp │ │ └── io.hpp │ └── mmyolo │ │ ├── ax_mmppyoloeps.cc │ │ ├── ax_mmyolov6s.cc │ │ ├── ax_mmyolov8s.cc │ │ └── ax_mmyoloxs.cc ├── ax620e │ ├── CMakeLists.txt │ ├── README.md │ ├── ax_classification_mmap_steps.cc │ ├── ax_classification_steps.cc │ ├── ax_crowdcount_steps.cc │ ├── ax_depth_anything_steps.cc │ ├── ax_imgproc_steps.cc │ ├── ax_model_info.cc │ ├── ax_rtdetr_steps.cc │ ├── ax_scrfd_steps.cc │ ├── ax_simcc_pose_steps.cc │ ├── ax_yolo11_pose_steps.cc │ ├── ax_yolo11_seg_steps.cc │ ├── ax_yolo11_steps.cc │ ├── ax_yolo_world_open_vocabulary_steps.cc │ ├── ax_yolo_world_steps.cc │ ├── ax_yolov10_ultralytics_steps.cc │ ├── ax_yolov10s_steps.cc │ ├── ax_yolov5_face_steps.cc │ ├── ax_yolov5s_seg_steps.cc │ ├── ax_yolov5s_steps.cc │ ├── ax_yolov6_steps.cc │ ├── ax_yolov7_steps.cc │ ├── ax_yolov7_tiny_face_steps.cc │ ├── ax_yolov8_pose_steps.cc │ ├── ax_yolov8_seg_steps.cc │ ├── ax_yolov8_steps.cc │ ├── ax_yolov9_steps.cc │ ├── ax_yolov9_ultralytics_steps.cc │ ├── ax_yolox_steps.cc │ └── middleware │ │ └── io.hpp ├── ax650 │ ├── CMakeLists.txt │ ├── README.md │ ├── ax_classification_steps.cc │ ├── ax_crowdcount_steps.cc │ ├── ax_depth_anything_steps.cc │ ├── ax_detr_steps.cc │ ├── ax_dinov2_steps.cc │ ├── ax_glpdepth_steps.cc │ ├── ax_hrnet_steps.cc │ ├── ax_imgproc_steps.cc │ ├── ax_model_info.cc │ ├── ax_pfld_steps.cc │ ├── ax_pp_humanseg_steps.cc │ ├── ax_pp_liteseg_stdc2_cityscapes_steps.cc │ ├── ax_pp_ocr_rec_steps.cc │ ├── ax_pp_person_attribute_steps.cc │ ├── ax_pp_vehicle_attribute_steps.cc │ ├── ax_ppyoloe_obj365_steps.cc │ ├── ax_ppyoloe_steps.cc │ ├── ax_realesrgan_steps.cc │ ├── ax_rtdetr_steps.cc │ ├── ax_rtmdet_steps.cc │ ├── ax_scrfd_steps.cc │ ├── ax_segformer_steps.cc │ ├── ax_simcc_pose_steps.cc │ ├── ax_yolo11_pose_steps.cc │ ├── ax_yolo11_seg_steps.cc │ ├── ax_yolo11_steps.cc │ ├── ax_yolo_nas_steps.cc │ ├── ax_yolo_world_open_vocabulary_steps.cc │ ├── ax_yolo_world_steps.cc │ ├── ax_yolov10_ultralytics_steps.cc │ ├── ax_yolov10s_steps.cc │ ├── ax_yolov5_face_steps.cc │ ├── ax_yolov5s_dynamic_batchsize_steps.cc │ ├── ax_yolov5s_seg_steps.cc │ ├── ax_yolov5s_steps.cc │ ├── ax_yolov6_steps.cc │ ├── ax_yolov7_steps.cc │ ├── ax_yolov7_tiny_face_steps.cc │ ├── ax_yolov8_nv12_steps.cc │ ├── ax_yolov8_obb_steps.cc │ ├── ax_yolov8_pose_steps.cc │ ├── ax_yolov8_seg_steps.cc │ ├── ax_yolov8_steps.cc │ ├── ax_yolov9_steps.cc │ ├── ax_yolov9_ultralytics_steps.cc │ ├── ax_yolox_steps.cc │ ├── deprecated │ │ ├── ax_yolov8s_pose_steps.cc │ │ └── ax_yolov8s_steps.cc │ └── middleware │ │ └── io.hpp ├── base │ ├── common.hpp │ ├── detection.hpp │ ├── pose.hpp │ ├── score.hpp │ ├── topk.hpp │ ├── transform.hpp │ └── yolo.hpp └── utilities │ ├── args.hpp │ ├── cmdline.hpp │ ├── file.hpp │ ├── split.hpp │ └── timer.hpp └── toolchains ├── aarch64-none-linux-gnu.toolchain.cmake ├── arm-AX620E-linux-uclibcgnueabihf.toolchain.cmake └── arm-linux-gnueabihf.toolchain.cmake /.clang-format: -------------------------------------------------------------------------------- 1 | # find src/ tools/ tests/ examples/ benchmark/ -type f -name '*.c' -o -name '*.cpp' -o -name '*.h' | xargs -i clang-format -i {} 2 | 3 | # need clang-format >= 10.0 4 | 5 | AccessModifierOffset: -4 6 | AlignAfterOpenBracket: Align 7 | AlignConsecutiveAssignments: false 8 | # AlignConsecutiveBitFields: true 9 | AlignConsecutiveDeclarations: false 10 | AlignConsecutiveMacros: true 11 | AlignEscapedNewlines: Left 12 | # AlignOperands: AlignAfterOperator 13 | AlignTrailingComments: true 14 | AllowAllArgumentsOnNextLine: true 15 | AllowAllConstructorInitializersOnNextLine: true 16 | AllowAllParametersOfDeclarationOnNextLine: true 17 | AllowShortBlocksOnASingleLine: Always 18 | AllowShortCaseLabelsOnASingleLine: true 19 | # AllowShortEnumsOnASingleLine: true 20 | AllowShortFunctionsOnASingleLine: None 21 | AllowShortIfStatementsOnASingleLine: WithoutElse 22 | AllowShortLambdasOnASingleLine: All 23 | AllowShortLoopsOnASingleLine: true 24 | AlwaysBreakAfterReturnType: None 25 | AlwaysBreakBeforeMultilineStrings: false 26 | AlwaysBreakTemplateDeclarations: Yes 27 | BinPackArguments: true 28 | BinPackParameters: true 29 | BraceWrapping: 30 | AfterCaseLabel: true 31 | AfterClass: true 32 | AfterControlStatement: Always 33 | AfterEnum: true 34 | AfterFunction: true 35 | AfterNamespace: true 36 | AfterObjCDeclaration: false 37 | AfterStruct: true 38 | AfterUnion: true 39 | AfterExternBlock: false 40 | BeforeCatch: true 41 | BeforeElse: true 42 | # BeforeLambdaBody: false 43 | # BeforeWhile: false 44 | IndentBraces: false 45 | SplitEmptyFunction: true 46 | SplitEmptyRecord: true 47 | SplitEmptyNamespace: false 48 | BreakAfterJavaFieldAnnotations: true 49 | BreakBeforeBinaryOperators: All 50 | BreakBeforeBraces: Custom 51 | BreakBeforeTernaryOperators: true 52 | BreakConstructorInitializers: BeforeColon 53 | BreakInheritanceList: BeforeColon 54 | BreakStringLiterals: false 55 | ColumnLimit: 0 56 | # CommentPragmas: 57 | CompactNamespaces: false 58 | ConstructorInitializerAllOnOneLineOrOnePerLine: true 59 | ConstructorInitializerIndentWidth: 4 60 | ContinuationIndentWidth: 4 61 | Cpp11BracedListStyle: true 62 | DeriveLineEnding: false 63 | DerivePointerAlignment: false 64 | # DisableFormat: 65 | # ExperimentalAutoDetectBinPacking: 66 | FixNamespaceComments: true 67 | # ForEachMacros: 68 | IncludeBlocks: Regroup 69 | # IncludeCategories: 70 | # IncludeIsMainRegex: 71 | # IncludeIsMainSourceRegex: 72 | # IndentCaseBlocks: false 73 | IndentCaseLabels: false 74 | # IndentExternBlock: NoIndent 75 | IndentGotoLabels: false 76 | IndentPPDirectives: None 77 | IndentWidth: 4 78 | # IndentWrappedFunctionNames: 4 79 | # InsertTrailingCommas: None 80 | # JavaImportGroups: 81 | # JavaScriptQuotes 82 | # JavaScriptWrapImports: 83 | KeepEmptyLinesAtTheStartOfBlocks: false 84 | Language: Cpp 85 | # MacroBlockBegin: 86 | # MacroBlockEnd: 87 | MaxEmptyLinesToKeep: 1 88 | NamespaceIndentation: All 89 | # NamespaceMacros: 90 | # ObjCBinPackProtocolList: 91 | # ObjCBlockIndentWidth: 92 | # ObjCBreakBeforeNestedBlockParam: 93 | # ObjCSpaceAfterProperty: 94 | # ObjCSpaceBeforeProtocolList: 95 | # PenaltyBreakAssignment: 96 | # PenaltyBreakBeforeFirstCallParameter: 97 | # PenaltyBreakComment: 98 | # PenaltyBreakFirstLessLess: 99 | # PenaltyBreakString: 100 | # PenaltyBreakTemplateDeclaration: 101 | # PenaltyExcessCharacter: 102 | # PenaltyReturnTypeOnItsOwnLine: 103 | PointerAlignment: Left 104 | # RawStringFormats: 105 | ReflowComments: false 106 | SortIncludes: false 107 | SortUsingDeclarations: true 108 | SpaceAfterCStyleCast: false 109 | SpaceAfterLogicalNot: false 110 | SpaceAfterTemplateKeyword: false 111 | SpaceBeforeAssignmentOperators: true 112 | SpaceBeforeCpp11BracedList: false 113 | SpaceBeforeCtorInitializerColon: true 114 | SpaceBeforeInheritanceColon: true 115 | SpaceBeforeParens: ControlStatements 116 | SpaceBeforeRangeBasedForLoopColon: true 117 | SpaceBeforeSquareBrackets: false 118 | SpaceInEmptyBlock: false 119 | SpaceInEmptyParentheses: false 120 | SpacesBeforeTrailingComments: 1 121 | SpacesInAngles: false 122 | SpacesInCStyleCastParentheses: false 123 | SpacesInConditionalStatement: false 124 | SpacesInContainerLiterals: false 125 | SpacesInParentheses: false 126 | SpacesInSquareBrackets: false 127 | Standard: c++03 128 | #StatementMacros: 129 | TabWidth: 4 130 | # TypenameMacros: 131 | UseCRLF: false 132 | UseTab: Never 133 | 134 | -------------------------------------------------------------------------------- /.github/workflows/build_620a.yml: -------------------------------------------------------------------------------- 1 | # This is a basic workflow to help you get started with Actions 2 | 3 | name: build_620a 4 | 5 | # Controls when the workflow will run 6 | on: 7 | # Triggers the workflow on push or pull request events but only for the "main" branch 8 | push: 9 | branches: [ "main" ] 10 | pull_request: 11 | branches: [ "main" ] 12 | 13 | # Allows you to run this workflow manually from the Actions tab 14 | workflow_dispatch: 15 | 16 | # A workflow run is made up of one or more jobs that can run sequentially or in parallel 17 | jobs: 18 | # This workflow contains a single job called "build" 19 | build: 20 | # The type of runner that the job will run on 21 | runs-on: ubuntu-latest 22 | 23 | # Steps represent a sequence of tasks that will be executed as part of the job 24 | steps: 25 | # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it 26 | - uses: actions/checkout@v3 27 | 28 | # Runs a set of commands using the runners shell 29 | - name: prepare opencv-library 30 | run: | 31 | mkdir -p ./3rdparty 32 | wget https://github.com/AXERA-TECH/ax-samples/releases/download/v0.1/opencv-arm-linux-gnueabihf-gcc-7.5.0.zip 33 | unzip opencv-arm-linux-gnueabihf-gcc-7.5.0.zip -d ./3rdparty 34 | 35 | - name: build 36 | run: | 37 | mkdir build 38 | cd build 39 | wget https://github.com/AXERA-TECH/ax-samples/releases/download/v0.3/arm_axpi_r1.22.2801.zip 40 | unzip arm_axpi_r1.22.2801.zip -d ax_bsp 41 | export ax_bsp=$PWD/ax_bsp 42 | echo $ax_bsp 43 | wget http://releases.linaro.org/components/toolchain/binaries/7.5-2019.12/arm-linux-gnueabihf/gcc-linaro-7.5.0-2019.12-x86_64_arm-linux-gnueabihf.tar.xz 44 | tar -xf gcc-linaro-7.5.0-2019.12-x86_64_arm-linux-gnueabihf.tar.xz 45 | export PATH=$PATH:gcc-linaro-7.5.0-2019.12-x86_64_arm-linux-gnueabihf/bin/ 46 | arm-linux-gnueabihf-gcc -v 47 | cmake -DCMAKE_TOOLCHAIN_FILE=../toolchains/arm-linux-gnueabihf.toolchain.cmake -DBSP_MSP_DIR=${ax_bsp}/ -DAXERA_TARGET_CHIP=ax620a .. 48 | make -j8 49 | make install 50 | -------------------------------------------------------------------------------- /.github/workflows/build_620q_uclibc.yaml: -------------------------------------------------------------------------------- 1 | # This is a basic workflow to help you get started with Actions 2 | 3 | name: build_620q_uclibc 4 | 5 | # Controls when the workflow will run 6 | on: 7 | # Triggers the workflow on push or pull request events but only for the "main" branch 8 | push: 9 | branches: [ "main" ] 10 | pull_request: 11 | branches: [ "main" ] 12 | 13 | # Allows you to run this workflow manually from the Actions tab 14 | workflow_dispatch: 15 | 16 | # A workflow run is made up of one or more jobs that can run sequentially or in parallel 17 | jobs: 18 | # This workflow contains a single job called "build" 19 | build: 20 | # The type of runner that the job will run on 21 | runs-on: ubuntu-latest 22 | 23 | # Steps represent a sequence of tasks that will be executed as part of the job 24 | steps: 25 | # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it 26 | - uses: actions/checkout@v3 27 | 28 | # Runs a set of commands using the runners shell 29 | - name: prepare opencv-library 30 | run: | 31 | mkdir -p ./3rdparty 32 | wget https://github.com/AXERA-TECH/ax-samples/releases/download/v0.6/opencv-arm-uclibc-linux.zip 33 | unzip opencv-arm-uclibc-linux.zip -d ./3rdparty 34 | 35 | - name: build 36 | run: | 37 | mkdir build 38 | cd build 39 | git clone https://github.com/AXERA-TECH/ax620q_bsp_sdk.git 40 | export ax_bsp=$PWD/ax620q_bsp_sdk/msp/out/arm_uclibc/ 41 | echo $ax_bsp 42 | wget https://github.com/AXERA-TECH/ax620q_bsp_sdk/releases/download/v2.0.0/arm-AX620E-linux-uclibcgnueabihf_V3_20240320.tgz 43 | tar -zxf arm-AX620E-linux-uclibcgnueabihf_V3_20240320.tgz 44 | export PATH=$PATH:arm-AX620E-linux-uclibcgnueabihf/bin/ 45 | arm-AX620E-linux-uclibcgnueabihf-gcc -v 46 | cmake -DCMAKE_TOOLCHAIN_FILE=../toolchains/arm-AX620E-linux-uclibcgnueabihf.toolchain.cmake -DBSP_MSP_DIR=${ax_bsp}/ -DAXERA_TARGET_CHIP=ax620q .. 47 | make -j8 48 | make install 49 | -------------------------------------------------------------------------------- /.github/workflows/build_630c_glibc.yaml: -------------------------------------------------------------------------------- 1 | # This is a basic workflow to help you get started with Actions 2 | 3 | name: build_630c_glibc 4 | 5 | # Controls when the workflow will run 6 | on: 7 | # Triggers the workflow on push or pull request events but only for the "main" branch 8 | push: 9 | branches: [ "main" ] 10 | pull_request: 11 | branches: [ "main" ] 12 | 13 | # Allows you to run this workflow manually from the Actions tab 14 | workflow_dispatch: 15 | 16 | # A workflow run is made up of one or more jobs that can run sequentially or in parallel 17 | jobs: 18 | # This workflow contains a single job called "build" 19 | build: 20 | # The type of runner that the job will run on 21 | runs-on: ubuntu-latest 22 | 23 | # Steps represent a sequence of tasks that will be executed as part of the job 24 | steps: 25 | # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it 26 | - uses: actions/checkout@v3 27 | 28 | # Runs a set of commands using the runners shell 29 | - name: prepare opencv-library 30 | run: | 31 | mkdir -p ./3rdparty 32 | wget https://github.com/AXERA-TECH/ax-samples/releases/download/v0.1/opencv-aarch64-linux-gnu-gcc-7.5.0.zip 33 | unzip opencv-aarch64-linux-gnu-gcc-7.5.0.zip -d ./3rdparty 34 | 35 | - name: build 36 | run: | 37 | mkdir build 38 | cd build 39 | git clone https://github.com/AXERA-TECH/ax620q_bsp_sdk.git 40 | export ax_bsp=$PWD/ax620q_bsp_sdk/msp/out/arm64_glibc/ 41 | echo $ax_bsp 42 | wget https://developer.arm.com/-/media/Files/downloads/gnu-a/9.2-2019.12/binrel/gcc-arm-9.2-2019.12-x86_64-aarch64-none-linux-gnu.tar.xz 43 | tar -xf gcc-arm-9.2-2019.12-x86_64-aarch64-none-linux-gnu.tar.xz 44 | export PATH=$PATH:gcc-arm-9.2-2019.12-x86_64-aarch64-none-linux-gnu/bin/ 45 | aarch64-none-linux-gnu-gcc -v 46 | cmake -DCMAKE_TOOLCHAIN_FILE=../toolchains/aarch64-none-linux-gnu.toolchain.cmake -DBSP_MSP_DIR=${ax_bsp}/ -DAXERA_TARGET_CHIP=ax630c .. 47 | make -j8 48 | make install 49 | -------------------------------------------------------------------------------- /.github/workflows/build_650.yml: -------------------------------------------------------------------------------- 1 | # This is a basic workflow to help you get started with Actions 2 | 3 | name: build_650 4 | 5 | # Controls when the workflow will run 6 | on: 7 | # Triggers the workflow on push or pull request events but only for the "main" branch 8 | push: 9 | branches: [ "main" ] 10 | pull_request: 11 | branches: [ "main" ] 12 | 13 | # Allows you to run this workflow manually from the Actions tab 14 | workflow_dispatch: 15 | 16 | # A workflow run is made up of one or more jobs that can run sequentially or in parallel 17 | jobs: 18 | # This workflow contains a single job called "build" 19 | build: 20 | # The type of runner that the job will run on 21 | runs-on: ubuntu-latest 22 | 23 | # Steps represent a sequence of tasks that will be executed as part of the job 24 | steps: 25 | # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it 26 | - uses: actions/checkout@v3 27 | 28 | # Runs a set of commands using the runners shell 29 | - name: prepare opencv-library 30 | run: | 31 | mkdir -p ./3rdparty 32 | wget https://github.com/AXERA-TECH/ax-samples/releases/download/v0.1/opencv-aarch64-linux-gnu-gcc-7.5.0.zip 33 | unzip opencv-aarch64-linux-gnu-gcc-7.5.0 -d ./3rdparty 34 | 35 | - name: build 36 | run: | 37 | mkdir build 38 | cd build 39 | git clone https://github.com/AXERA-TECH/ax650n_bsp_sdk.git 40 | export ax_bsp=$PWD/ax650n_bsp_sdk/msp/out/ 41 | echo $ax_bsp 42 | wget https://developer.arm.com/-/media/Files/downloads/gnu-a/9.2-2019.12/binrel/gcc-arm-9.2-2019.12-x86_64-aarch64-none-linux-gnu.tar.xz 43 | tar -xf gcc-arm-9.2-2019.12-x86_64-aarch64-none-linux-gnu.tar.xz 44 | export PATH=$PATH:gcc-arm-9.2-2019.12-x86_64-aarch64-none-linux-gnu/bin/ 45 | aarch64-none-linux-gnu-gcc -v 46 | cmake -DCMAKE_TOOLCHAIN_FILE=../toolchains/aarch64-none-linux-gnu.toolchain.cmake -DBSP_MSP_DIR=${ax_bsp}/ -DAXERA_TARGET_CHIP=ax650 .. 47 | make -j8 48 | make install 49 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # clion debug directory 2 | cmake-build* 3 | .idea 4 | 5 | # 3rdparty directory 6 | 3rdparty*/ 7 | 8 | # CMake build directory 9 | build*/ 10 | 11 | # Backup files. 12 | *~ 13 | 14 | # Prerequisites 15 | *.d 16 | 17 | # Compiled Object files 18 | *.slo 19 | *.lo 20 | *.o 21 | *.obj 22 | 23 | # Precompiled Headers 24 | *.gch 25 | *.pch 26 | 27 | # Compiled Dynamic libraries 28 | *.dylib 29 | *.dll 30 | 31 | # Fortran module files 32 | *.mod 33 | *.smod 34 | 35 | # Compiled Static libraries 36 | *.lai 37 | *.la 38 | *.lib 39 | 40 | # Executables 41 | *.exe 42 | *.out 43 | *.app 44 | 45 | # MACOSX 46 | .DS_Store 47 | 48 | # IDE 49 | .vs 50 | .vscode 51 | 52 | # Python 53 | *.egg-info/ 54 | __pycache__/ 55 | 56 | 57 | # msp 58 | out*/ 59 | 3rdparty 60 | -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # AXERA is pleased to support the open source community by making ax-samples available. 2 | # 3 | # Copyright (c) 2022, AXERA Semiconductor (Shanghai) Co., Ltd. All rights reserved. 4 | # 5 | # Licensed under the BSD 3-Clause License (the "License"); you may not use this file except 6 | # in compliance with the License. You may obtain a copy of the License at 7 | # 8 | # https://opensource.org/licenses/BSD-3-Clause 9 | # 10 | # Unless required by applicable law or agreed to in writing, software distributed 11 | # under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 12 | # CONDITIONS OF ANY KIND, either express or implied. See the License for the 13 | # specific language governing permissions and limitations under the License. 14 | # 15 | # Author: ls.wang 16 | # 17 | 18 | # check CMake version 19 | cmake_minimum_required (VERSION 3.13 FATAL_ERROR) 20 | 21 | # disable inplace builds to prevent source tree corruption. 22 | if (" ${CMAKE_SOURCE_DIR}" STREQUAL " ${CMAKE_BINARY_DIR}") 23 | message (FATAL_ERROR "FATAL: Building inplace are not allowed. You should create a separate directory for Building.") 24 | endif () 25 | 26 | # set cmake_install_prefix path 27 | if(NOT DEFINED CMAKE_INSTALL_PREFIX) 28 | set(CMAKE_INSTALL_PREFIX "${CMAKE_BINARY_DIR}/install" CACHE PATH "Installation Directory") 29 | endif() 30 | message(STATUS "CMAKE_INSTALL_PREFIX = ${CMAKE_INSTALL_PREFIX}") 31 | 32 | # enable the languages which in use 33 | enable_language (C CXX) 34 | 35 | # check toolchain about 36 | if(CMAKE_TOOLCHAIN_FILE) 37 | set(LIBRARY_OUTPUT_PATH_ROOT ${CMAKE_BINARY_DIR} CACHE PATH "root for library output, set this to change where android libs are compiled to") 38 | # get absolute path, but get_filename_component ABSOLUTE only refer with source dir, so find_file here :( 39 | get_filename_component(CMAKE_TOOLCHAIN_FILE_NAME ${CMAKE_TOOLCHAIN_FILE} NAME) 40 | find_file(CMAKE_TOOLCHAIN_FILE ${CMAKE_TOOLCHAIN_FILE_NAME} PATHS ${CMAKE_SOURCE_DIR} NO_DEFAULT_PATH) 41 | message(STATUS "CMAKE_TOOLCHAIN_FILE = ${CMAKE_TOOLCHAIN_FILE}") 42 | endif() 43 | 44 | # check if building type is not set 45 | if(NOT CMAKE_BUILD_TYPE) 46 | set(CMAKE_BUILD_TYPE release CACHE STRING "Choose the type of build" FORCE) 47 | endif() 48 | 49 | # do check list 50 | include("${CMAKE_CURRENT_SOURCE_DIR}/cmake/check.cmake") 51 | 52 | # one should have a name finally 53 | project(AXERA-Samples) 54 | 55 | # set default chip as as ax650 56 | # TODO: set as an option 57 | if (NOT AXERA_TARGET_CHIP) 58 | set (AXERA_TARGET_CHIP "ax650") 59 | endif () 60 | 61 | set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -O1 -Wall -s -fPIC -Wunused-function") 62 | set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O1 -Wall -s -fPIC -Wunused-function") 63 | 64 | # src files 65 | add_subdirectory(examples) 66 | 67 | # report summary 68 | include("${CMAKE_CURRENT_SOURCE_DIR}/cmake/summary.cmake") 69 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | BSD 3-Clause License 2 | 3 | Copyright (c) 2022, AXERA Semiconductor (Shanghai) Co., Ltd 4 | All rights reserved. 5 | 6 | Redistribution and use in source and binary forms, with or without 7 | modification, are permitted provided that the following conditions are met: 8 | 9 | 1. Redistributions of source code must retain the above copyright notice, this 10 | list of conditions and the following disclaimer. 11 | 12 | 2. Redistributions in binary form must reproduce the above copyright notice, 13 | this list of conditions and the following disclaimer in the documentation 14 | and/or other materials provided with the distribution. 15 | 16 | 3. Neither the name of the copyright holder nor the names of its 17 | contributors may be used to endorse or promote products derived from 18 | this software without specific prior written permission. 19 | 20 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 21 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 24 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 26 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 27 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 28 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | [English](./README_EN.md) | 简体中文 2 | 3 | # AX-Samples 4 | 5 | [![License](https://img.shields.io/badge/license-BSD--3--Clause-blue.svg)](https://raw.githubusercontent.com/AXERA-TECH/ax-samples/main/LICENSE) 6 | 7 | | Platform | Build Status | 8 | | -------- | ------------ | 9 | | AX650N | ![GitHub Actions Workflow Status](https://img.shields.io/github/actions/workflow/status/AXERA-TECH/ax-samples/build_650.yml)| 10 | | AX630C | ![GitHub Actions Workflow Status](https://img.shields.io/github/actions/workflow/status/AXERA-TECH/ax-samples/build_630c_glibc.yaml)| 11 | | AX620Q | ![GitHub Actions Workflow Status](https://img.shields.io/github/actions/workflow/status/AXERA-TECH/ax-samples/build_620q_uclibc.yaml)| 12 | | AX620A | ![GitHub Actions Workflow Status](https://img.shields.io/github/actions/workflow/status/AXERA-TECH/ax-samples/build_620a.yml)| 13 | 14 | ## 简介 15 | 16 | **AX-Samples** 由 **[爱芯元智](https://www.axera-tech.com/)** 主导开发。该项目实现了常见的 **深度学习开源算法** 在 **爱芯元智** 的 **AI SoC** 上的示例代码,方便社区开发者进行快速评估和适配。 17 | 18 | 已支持芯片 19 | 20 | - [AX630C](docs/AX630C.md)/[AX620Q](docs/AX620Q.md) 21 | - [AX650A](docs/AX650A.md)/[AX650N](docs/AX650N.md) 22 | - [AX620A](docs/AX620A.md)/[AX620U](docs/AX620U.md) 23 | - [AX630A](docs/AX630A.md) 24 | 25 | 已支持开发板 26 | 27 | - [AXera-Pi](https://wiki.sipeed.com/m3axpi)(AX620A) 28 | - [AXera-Pi Pro](https://wiki.sipeed.com/m4ndock)(AX650N) 29 | - [AXera-Pi Zero](https://axera-pi-zero-docs-cn.readthedocs.io/zh-cn/latest/index.html)(AX620Q) 30 | 31 | ## 快速上手 32 | 33 | ### 编译 34 | 35 | - [快速编译](docs/compile.md) 基于 cmake 实现简单的跨平台编译。 36 | 37 | ### 示例 38 | 39 | - [examples](examples/) 提供常见分类、检测、姿态等深度学习开源算法和传统 CV 操作用例,根据 issue 需求持续更新。 40 | 41 | ### 网盘资源 42 | 43 | - 提供 **ModelZoo**, **预编译程序**, **测试图片** 等内容: 44 | - [百度网盘](https://pan.baidu.com/s/15g2eRHo1LkcMDZk1H2zMmA?pwd=9amz) 45 | - [Google Drive](https://drive.google.com/drive/folders/1JY59vOFS2qxI8TkVIZ0pHfxHMfKPW5PS?usp=sharing) 46 | 47 | ### 速度评估 48 | 49 | - [Benchmark](benchmark/) 常见开源模型推理耗时统计,基于 *AXera-Pi* 、 *AXera-Pi Pro* 、*AXera-Pi Zero* 实测。 50 | 51 | ## 关联项目 52 | 53 | - NPU工具链在线文档,其中提供了NPU工具链相关使用说明和获取方式 54 | - [Pulsar](https://pulsar-docs.readthedocs.io/zh_CN/latest/)(Support AX630A/AX620A/AX620U) 55 | - [Pulsar2](https://pulsar2-docs.readthedocs.io/zh_CN/latest/)(Support AX650A/AX650N/AX630C/AX620Q) 56 | 57 | ## 技术讨论 58 | 59 | - Github issues 60 | - QQ 群: 139953715 61 | -------------------------------------------------------------------------------- /README_EN.md: -------------------------------------------------------------------------------- 1 | English | [简体中文](./README.md) 2 | 3 | # AX-Samples 4 | 5 | [![License](https://img.shields.io/badge/license-BSD--3--Clause-blue.svg)](https://raw.githubusercontent.com/AXERA-TECH/ax-samples/main/LICENSE) 6 | 7 | | Platform | Build Status | 8 | | -------- | ------------ | 9 | | AX650N | ![GitHub Actions Workflow Status](https://img.shields.io/github/actions/workflow/status/AXERA-TECH/ax-samples/build_650.yml)| 10 | | AX630C | ![GitHub Actions Workflow Status](https://img.shields.io/github/actions/workflow/status/AXERA-TECH/ax-samples/build_630c_glibc.yaml)| 11 | | AX620Q | ![GitHub Actions Workflow Status](https://img.shields.io/github/actions/workflow/status/AXERA-TECH/ax-samples/build_620q_uclibc.yaml)| 12 | | AX620A | ![GitHub Actions Workflow Status](https://img.shields.io/github/actions/workflow/status/AXERA-TECH/ax-samples/build_620a.yml)| 13 | 14 | ## Intro 15 | 16 | **AX-Samples** by **[Axera](https://www.axera-tech.com/)** dominate the development. The project has implemented the sample code of the most common **deep learning open source algorithm** on the **AI SoC** of **Axera**, which is convenient for community developers to quickly evaluate and adapt. 17 | 18 | Support SoC 19 | 20 | - [AX630C](docs/AX630C.md)/[AX620Q](docs/AX620Q.md) 21 | - [AX650A](docs/AX650A.md)/[AX650N](docs/AX650N.md) 22 | - [AX620A](docs/AX620A.md)/[AX620U](docs/AX620U.md) 23 | - [AX630A](docs/AX630A.md) 24 | 25 | Support Board 26 | 27 | - [AXera-Pi](https://wiki.sipeed.com/m3axpi)(AX620A) 28 | - [AXera-Pi Pro](https://wiki.sipeed.com/m4ndock)(AX650N) 29 | - [AXera-Pi Zero](https://axera-pi-zero-docs-cn.readthedocs.io/zh-cn/latest/index.html)(AX620Q) 30 | 31 | ## Quick Start 32 | 33 | ### Compile 34 | 35 | - [easy compile](docs/compile.md) Simple cross-platform compilation based on **cmake**. 36 | 37 | ### Samples 38 | 39 | - [examples](examples/) It provides open source deep learning algorithms such as common classification, detection, posture and traditional CV operation use cases, which are continuously updated according to the needs of the issue. 40 | 41 | ### Online Disk 42 | 43 | - Provide **ModelZoo**, **pre-compiler bin**, **test pictures** and so on: 44 | - [BaiDu Disk](https://pan.baidu.com/s/1cnMeqsD-hErlRZlBDDvuoA?pwd=oey4) 45 | - [Google Drive](https://drive.google.com/drive/folders/1JY59vOFS2qxI8TkVIZ0pHfxHMfKPW5PS?usp=sharing) 46 | 47 | ### Benchmark 48 | 49 | - [Benchmark](benchmark/) Common open source model inference time statistics, based on *AXera-Pi*, *AXera-Pi Pro*, *AXera-Pi Zero* measured. 50 | 51 | ## Related project 52 | 53 | - NPU Tool Chain Online document, which provides instructions for using the NPU tool chain and how to obtain it. 54 | - [Pulsar](https://pulsar-docs.readthedocs.io/zh_CN/latest/)(Support AX630A/AX620A/AX620U) 55 | - [Pulsar2](https://pulsar2-docs.readthedocs.io/zh_CN/latest/)(Support AX650A/AX650N/AX630C/AX620Q) 56 | 57 | ## Technical discussion 58 | 59 | - Github issues 60 | - QQ Group: 139953715 61 | -------------------------------------------------------------------------------- /benchmark/Benchmark_AX620A.md: -------------------------------------------------------------------------------- 1 | # Benchmark(AX620A) 2 | 3 | Benchmark 是了解硬件平台网络模型运行速度的最佳途径。以下数据基于 AXera-Pi 测试获取,不代表商业交付最终性能。 4 | 5 | ## vnpu 1_1, 1.8Tops@Int8 6 | | Models | Input Size | 耗时(ms) | 7 | | ------------ | ---------- | ---------- | 8 | | mobilenetv1 | 224 | 4.1 | 9 | | mobilenetv2 | 224 | 3.3 | 10 | | mobileone_s0 | 224 | 1.7 | 11 | | resnet18 | 224 | 5.4 | 12 | | resnet50 | 224 | 19.2 | 13 | | squeezenet10 | 224 | 4.2 | 14 | | squeezenet11 | 224 | 2.3 | 15 | | yolov3 | 416 | 59.7 | 16 | | yolov3-tiny | 416 | 5.7 | 17 | | yolov4-tiny | 416 | 5.9 | 18 | | yolov5s | 640 | 22.4 | 19 | | yolov6s | 640 | 32.3 | 20 | | yolov7-tiny | 416 | 9.6 | 21 | | yolov8s | 640 | 36.7 | 22 | | yolox-s | 640 | 41.6 | 23 | | yolopv2 | 228*480 | 100.5 | 24 | | yolo-fastbody| 320 | 3.7 | 25 | | yolo-fast-xl | 320 | 6.2 | 26 | | hrnet | 256 | 14.1 | 27 | -------------------------------------------------------------------------------- /benchmark/Benchmark_AX620Q.md: -------------------------------------------------------------------------------- 1 | # Benchmark(AX620Q) 2 | 3 | Benchmark 是了解硬件平台网络模型运行速度的最佳途径。**仅供社区参考,不代表商业交付最终性能**。 4 | 5 | ### 工具链版本 6 | - Pulsar2 2.5 7 | 8 | ### 数据记录 9 | 10 | | Models | Input Size | Inference Time(ms)@2.4T | 11 | | -------------- | ---------- | ----------------------------- | 12 | | Inceptionv1 | 224 | 2.410 | 13 | | Inceptionv3 | 299 | 9.517 | 14 | | MobileNetv1 | 224 | 1.202 | 15 | | MobileNetv2 | 224 | 1.225 | 16 | | SqueezeNetv11 | 227 | 0.961 | 17 | | ResNet18 | 224 | 3.434 | 18 | | ResNet50 | 224 | 7.573 | 19 | | YOLOv5s | 640 | 16.060 | 20 | | YOLOv6s | 640 | 17.352 | 21 | | YOLOv7-Tiny | 640 | 15.578 | 22 | | YOLOv8s | 640 | 21.946 | 23 | | YOLOX_s | 640 | 19.579 | 24 | | PPYOLOE+_s | 640 | 19.044 | 25 | | Deit_t | 224 | 4.502 | 26 | | Swin_t | 224 | 19.331 | 27 | -------------------------------------------------------------------------------- /benchmark/Benchmark_AX630C.md: -------------------------------------------------------------------------------- 1 | # Benchmark(AX630C) 2 | 3 | Benchmark 是了解硬件平台网络模型运行速度的最佳途径。**仅供社区参考,不代表商业交付最终性能**。 4 | 5 | ### 工具链版本 6 | - Pulsar2 2.5 7 | 8 | ### 数据记录 9 | 10 | | Models | Input Size | Inference Time(ms)@3.2T | 11 | | -------------- | ---------- | ----------------------------- | 12 | | Inceptionv1 | 224 | 1.795 | 13 | | Inceptionv3 | 299 | 7.065 | 14 | | MobileNetv1 | 224 | 0.901 | 15 | | MobileNetv2 | 224 | 0.923 | 16 | | SqueezeNetv11 | 227 | 0.824 | 17 | | SqueezeNetv10 | 227 | 1.097 | 18 | | ResNet18 | 224 | 2.540 | 19 | | ResNet50 | 224 | 5.616 | 20 | | VGG16 | 224 | 32.404 | 21 | | YOLOv3 | 608 | 65.117 | 22 | | YOLOv5s | 640 | 12.707 | 23 | | YOLOv6s | 640 | 13.708 | 24 | | YOLOv7-Tiny | 640 | 12.508 | 25 | | YOLOv8s | 640 | 16.912 | 26 | | YOLO11s | 640 | 15.933 | 27 | | YOLOX_s | 640 | 15.425 | 28 | | PPYOLOE+_s | 640 | 14.885 | 29 | | Deit_t | 224 | 3.350 | 30 | | Swin_t | 224 | 14.459 | 31 | | ViT_b | 224 | 26.711 | 32 | -------------------------------------------------------------------------------- /benchmark/Benchmark_AX650N.md: -------------------------------------------------------------------------------- 1 | # Benchmark(AX650N) 2 | 3 | Benchmark 是了解硬件平台网络模型运行速度的最佳途径。以下数据基于 AXera-Pi Pro 测试获取,**仅供社区参考,不代表商业交付最终性能**。 4 | 5 | ### 工具链版本 6 | - Pulsar2 3.2 7 | 8 | ### 数据记录 9 | 10 | | Models | Input Size | Inference Time(ms)@1 Core | Inference Time(ms)@3 Cores | 11 | | -------------- | ---------- | ----------------------------- | ------------------------------ | 12 | | Inceptionv1 | 224 | 1.166 | 0.495 | 13 | | Inceptionv3 | 299 | 4.370 | 1.670 | 14 | | MobileNetv1 | 224 | 0.567 | 0.277 | 15 | | MobileNetv2 | 224 | 0.595 | 0.282 | 16 | | SqueezeNetv11 | 227 | 0.471 | 0.200 | 17 | | SqueezeNetv10 | 227 | 0.904 | 0.346 | 18 | | ResNet18 | 224 | 1.269 | 0.540 | 19 | | ResNet50 | 224 | 2.867 | 1.335 | 20 | | VGG16 | 224 | 14.135 | 8.141 | 21 | | YOLOv3 | 608 | 43.198 | 14.983 | 22 | | YOLOv5s | 640 | 6.658 | 2.600 | 23 | | YOLOv6s | 640 | 8.913 | 3.126 | 24 | | YOLOv7-Tiny | 640 | 5.938 | 2.771 | 25 | | YOLOv7 | 640 | 34.787 | 12.544 | 26 | | YOLOv8s | 640 | 10.422 | 3.592 | 27 | | YOLOv9s | 640 | 11.212 | 4.181 | 28 | | YOLOv10s | 640 | 9.099 | 3.300 | 29 | | YOLO11s | 640 | 8.886 | 3.192 | 30 | | YOLOX_s | 640 | 9.668 | 3.405 | 31 | | YOLO-Nas_s | 640 | 12.061 | 4.270 | 32 | | PPYOLOE+_s | 640 | 11.439 | 3.045 | 33 | | Deit_t | 224 | 1.723 | 0.780 | 34 | | Swin_t | 224 | 6.334 | 2.492 | 35 | | ViT_b | 224 | 17.369 | 5.725 | 36 | -------------------------------------------------------------------------------- /cmake/ax620.cmake: -------------------------------------------------------------------------------- 1 | # AXERA is pleased to support the open source community by making ax-samples available. 2 | # 3 | # Copyright (c) 2022, AXERA Semiconductor (Shanghai) Co., Ltd. All rights reserved. 4 | # 5 | # Licensed under the BSD 3-Clause License (the "License"); you may not use this file except 6 | # in compliance with the License. You may obtain a copy of the License at 7 | # 8 | # https://opensource.org/licenses/BSD-3-Clause 9 | # 10 | # Unless required by applicable law or agreed to in writing, software distributed 11 | # under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 12 | # CONDITIONS OF ANY KIND, either express or implied. See the License for the 13 | # specific language governing permissions and limitations under the License. 14 | # 15 | # Author: ls.wang 16 | # 17 | 18 | function(axera_example name) 19 | add_executable(${name}) 20 | 21 | # add srcs 22 | foreach(file IN LISTS ARGN) 23 | target_sources(${name} PRIVATE ${file}) 24 | endforeach() 25 | 26 | # headers 27 | target_include_directories(${name} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}) 28 | target_include_directories(${name} PRIVATE ${BSP_MSP_DIR}/include) 29 | 30 | if(${AXERA_TARGET_PROCESSOR} MATCHES "ARM" AND AXERA_TARGET_PROCESSOR_32Bit) 31 | target_include_directories(${name} PRIVATE /opt/include) 32 | endif() 33 | 34 | # libs 35 | if(AXERA_TARGET_CHIP MATCHES "ax620a") # ax620 support 36 | target_link_libraries(${name} PRIVATE pthread dl) # ax620a use this 37 | 38 | # target_link_libraries (${name} PRIVATE pthread dl stdc++fs) # ax620u use this 39 | target_link_libraries(${name} PRIVATE ax_run_joint ax_interpreter_external ax_interpreter ax_sys axsyslog stdc++fs) 40 | else() # ax630a support 41 | target_link_libraries(${name} PRIVATE pthread dl stdc++fs) 42 | target_link_libraries(${name} PRIVATE ax_run_joint ax_interpreter_external ax_interpreter ax_sys) 43 | endif() 44 | 45 | target_link_libraries(${name} PRIVATE ax_ivps ax_npu_cv_kit) 46 | 47 | # folders 48 | target_link_directories(${name} PRIVATE ${BSP_MSP_DIR}/lib) 49 | 50 | if(${AXERA_TARGET_PROCESSOR} MATCHES "ARM" AND AXERA_TARGET_PROCESSOR_32Bit) 51 | target_link_libraries(${name} PRIVATE dl) 52 | target_link_directories(${name} PRIVATE /opt/lib) 53 | endif() 54 | 55 | # opencv 56 | target_include_directories(${name} PRIVATE ${OpenCV_INCLUDE_DIRS}) 57 | target_link_libraries(${name} PRIVATE ${OpenCV_LIBS}) 58 | 59 | # install (TARGETS ${name} DESTINATION bin) 60 | if(AXERA_TARGET_CHIP MATCHES "ax620a") 61 | install(TARGETS ${name} DESTINATION ax620) 62 | elseif(AXERA_TARGET_CHIP MATCHES "ax630a") 63 | install(TARGETS ${name} DESTINATION ax630) 64 | endif() 65 | endfunction() 66 | -------------------------------------------------------------------------------- /cmake/ax620e.cmake: -------------------------------------------------------------------------------- 1 | # AXERA is pleased to support the open source community by making ax-samples available. 2 | # 3 | # Copyright (c) 2022, AXERA Semiconductor (Shanghai) Co., Ltd. All rights reserved. 4 | # 5 | # Licensed under the BSD 3-Clause License (the "License"); you may not use this file except 6 | # in compliance with the License. You may obtain a copy of the License at 7 | # 8 | # https://opensource.org/licenses/BSD-3-Clause 9 | # 10 | # Unless required by applicable law or agreed to in writing, software distributed 11 | # under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 12 | # CONDITIONS OF ANY KIND, either express or implied. See the License for the 13 | # specific language governing permissions and limitations under the License. 14 | # 15 | # Author: ls.wang 16 | # 17 | 18 | function(axera_example example_name) 19 | add_executable(${example_name}) 20 | 21 | foreach (file IN LISTS ARGN) 22 | target_sources(${example_name} PRIVATE ${file}) 23 | endforeach () 24 | 25 | target_include_directories(${example_name} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR} ${BSP_MSP_DIR}/include) 26 | 27 | # opencv 28 | target_include_directories(${example_name} PRIVATE ${OpenCV_INCLUDE_DIRS}) 29 | target_link_libraries(${example_name} PRIVATE ${OpenCV_LIBS}) 30 | 31 | # ax_engine 32 | target_link_libraries(${example_name} PRIVATE ax_engine) 33 | 34 | # sdk 35 | target_link_libraries(${example_name} PRIVATE ${CMAKE_THREAD_LIBS_INIT} ax_interpreter ax_sys ax_ivps) 36 | target_link_directories(${example_name} PRIVATE ${BSP_MSP_DIR}/lib) 37 | 38 | target_compile_options (${example_name} PUBLIC $<$: -O3>) 39 | 40 | if (AXERA_TARGET_CHIP MATCHES "ax630c") 41 | install(TARGETS ${example_name} DESTINATION ax630c) 42 | elseif (AXERA_TARGET_CHIP MATCHES "ax620q") 43 | install(TARGETS ${example_name} DESTINATION ax620q) 44 | endif() 45 | endfunction() 46 | -------------------------------------------------------------------------------- /cmake/ax650.cmake: -------------------------------------------------------------------------------- 1 | # AXERA is pleased to support the open source community by making ax-samples available. 2 | # 3 | # Copyright (c) 2022, AXERA Semiconductor (Shanghai) Co., Ltd. All rights reserved. 4 | # 5 | # Licensed under the BSD 3-Clause License (the "License"); you may not use this file except 6 | # in compliance with the License. You may obtain a copy of the License at 7 | # 8 | # https://opensource.org/licenses/BSD-3-Clause 9 | # 10 | # Unless required by applicable law or agreed to in writing, software distributed 11 | # under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 12 | # CONDITIONS OF ANY KIND, either express or implied. See the License for the 13 | # specific language governing permissions and limitations under the License. 14 | # 15 | # Author: ls.wang 16 | # 17 | 18 | function(axera_example example_name) 19 | add_executable(${example_name}) 20 | 21 | foreach (file IN LISTS ARGN) 22 | target_sources(${example_name} PRIVATE ${file}) 23 | endforeach () 24 | 25 | target_include_directories(${example_name} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR} ${BSP_MSP_DIR}/include) 26 | 27 | # opencv 28 | target_include_directories(${example_name} PRIVATE ${OpenCV_INCLUDE_DIRS}) 29 | target_link_libraries(${example_name} PRIVATE ${OpenCV_LIBS}) 30 | 31 | # ax_engine 32 | target_link_libraries(${example_name} PRIVATE ax_engine) 33 | 34 | # sdk 35 | target_link_libraries(${example_name} PRIVATE ${CMAKE_THREAD_LIBS_INIT} ax_interpreter ax_sys ax_ivps) 36 | target_link_directories(${example_name} PRIVATE ${BSP_MSP_DIR}/lib) 37 | 38 | target_compile_options (${example_name} PUBLIC $<$: -O3>) 39 | 40 | if (AXERA_TARGET_CHIP MATCHES "ax650") 41 | install(TARGETS ${example_name} DESTINATION ax650) 42 | endif() 43 | endfunction() 44 | -------------------------------------------------------------------------------- /cmake/summary.cmake: -------------------------------------------------------------------------------- 1 | # AXERA is pleased to support the open source community by making ax-samples available. 2 | # 3 | # Copyright (c) 2022, AXERA Semiconductor (Shanghai) Co., Ltd. All rights reserved. 4 | # 5 | # Licensed under the BSD 3-Clause License (the "License"); you may not use this file except 6 | # in compliance with the License. You may obtain a copy of the License at 7 | # 8 | # https://opensource.org/licenses/BSD-3-Clause 9 | # 10 | # Unless required by applicable law or agreed to in writing, software distributed 11 | # under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 12 | # CONDITIONS OF ANY KIND, either express or implied. See the License for the 13 | # specific language governing permissions and limitations under the License. 14 | # 15 | # Author: ls.wang 16 | # 17 | 18 | # C/C++ Compiler report 19 | 20 | MESSAGE (STATUS "") 21 | MESSAGE (STATUS "") 22 | MESSAGE (STATUS "Information Summary:") 23 | MESSAGE (STATUS "") 24 | # CMake information 25 | MESSAGE (STATUS "CMake information:") 26 | MESSAGE (STATUS " - CMake version: ${CMAKE_VERSION}") 27 | MESSAGE (STATUS " - CMake generator: ${CMAKE_GENERATOR}") 28 | MESSAGE (STATUS " - CMake building tools: ${CMAKE_BUILD_TOOL}") 29 | MESSAGE (STATUS " - Target System: ${CMAKE_SYSTEM_NAME}") 30 | MESSAGE (STATUS " - Target CPU arch: ${AXERA_TARGET_PROCESSOR}") 31 | IF (AXERA_TARGET_PROCESSOR_32Bit) 32 | MESSAGE (STATUS " - Target CPU bus width: 32 Bit") 33 | ENDIF() 34 | IF (AXERA_TARGET_PROCESSOR_64Bit) 35 | MESSAGE (STATUS " - Target CPU bus width: 64 Bit") 36 | ENDIF() 37 | MESSAGE (STATUS "") 38 | 39 | 40 | # C/C++ Compiler information 41 | MESSAGE (STATUS "${PROJECT_NAME} toolchain information:") 42 | MESSAGE (STATUS " Cross compiling: ${CMAKE_CROSSCOMPILING}") 43 | MESSAGE (STATUS " C/C++ compiler:") 44 | MESSAGE (STATUS " - C standard version: C${CMAKE_C_STANDARD}") 45 | MESSAGE (STATUS " - C standard required: ${CMAKE_C_STANDARD_REQUIRED}") 46 | MESSAGE (STATUS " - C standard extensions: ${CMAKE_C_EXTENSIONS}") 47 | MESSAGE (STATUS " - C compiler version: ${CMAKE_C_COMPILER_VERSION}") 48 | MESSAGE (STATUS " - C compiler: ${CMAKE_C_COMPILER}") 49 | MESSAGE (STATUS " - C++ standard version: C++${CMAKE_CXX_STANDARD}") 50 | MESSAGE (STATUS " - C++ standard required: ${CMAKE_CXX_STANDARD_REQUIRED}") 51 | MESSAGE (STATUS " - C++ standard extensions: ${CMAKE_CXX_EXTENSIONS}") 52 | MESSAGE (STATUS " - C++ compiler version: ${CMAKE_CXX_COMPILER_VERSION}") 53 | MESSAGE (STATUS " - C++ compiler: ${CMAKE_CXX_COMPILER}") 54 | MESSAGE (STATUS " C/C++ compiler flags:") 55 | MESSAGE (STATUS " - C compiler flags: ${CMAKE_C_FLAGS}") 56 | MESSAGE (STATUS " - C++ compiler flags: ${CMAKE_CXX_FLAGS}") 57 | MESSAGE (STATUS " OpenMP:") 58 | IF (OpenMP_FOUND) 59 | MESSAGE (STATUS " - OpenMP was found: YES") 60 | MESSAGE (STATUS " - OpenMP version: ${OpenMP_C_VERSION}") 61 | ELSE() 62 | MESSAGE (STATUS " - OpenMP was found: NO") 63 | ENDIF() 64 | MESSAGE (STATUS "") 65 | 66 | 67 | # CMake project information 68 | MESSAGE (STATUS "${PROJECT_NAME} building information:") 69 | MESSAGE (STATUS " - Project source path is: ${PROJECT_SOURCE_DIR}") 70 | MESSAGE (STATUS " - Project building path is: ${CMAKE_BINARY_DIR}") 71 | MESSAGE (STATUS "") 72 | 73 | 74 | MESSAGE (STATUS "${PROJECT_NAME} other information:") 75 | # show building install path 76 | MESSAGE (STATUS " Package install path: ${CMAKE_INSTALL_PREFIX}") 77 | MESSAGE (STATUS " Target platform: ${AXERA_TARGET_CHIP}") 78 | MESSAGE (STATUS "") 79 | -------------------------------------------------------------------------------- /docs/AX620A.md: -------------------------------------------------------------------------------- 1 | # AX620A 2 | 3 | ## Brief 4 | 5 | - CPU 6 | - Quad-core Cortex A7 7 | - NPU 8 | - 7.2Tops@INT4 or 1.8Tops@INT8 9 | - ISP 10 | - 4K@30fps 11 | - AI-ISP 12 | - Video Encoder 13 | - H.264/H.265, 4K@30fps+ 14 | - Video Decoder 15 | - H.264, 1080p@60fps 16 | - Video Interfaces 17 | - Video Input Interfaces 18 | - 3x4 Lane MIPI CSI 19 | - Video Output Interfaces 20 | - 2x4 Lane MIPI CSI/DSI 21 | - DDR 22 | - 32bit LPDDR4x(x) 23 | - Up to 3733Mbit/s rate 24 | - Ethernet 25 | - One Gigabit Ethernet port 26 | - RGMII and RMII modes 27 | - USB 28 | - USB 2.0 x 1 29 | -------------------------------------------------------------------------------- /docs/AX620Q.md: -------------------------------------------------------------------------------- 1 | # AX620Q 2 | 3 | ## Brief 4 | 5 | - CPU 6 | - Dual-core Cortex A53 7 | - NPU 8 | - 9.6Tops@INT4 or 2.4Tops@INT8 9 | - ISP 10 | - 5Mp@30fps 11 | - AI-ISP/T-ISP 12 | - Video Encoder 13 | - H.264/H.265, 5Mp@30fps+ 14 | - Video Decoder 15 | - H.264, 1080p@60fps 16 | - Video Interfaces 17 | - Video Input Interfaces 18 | - 1x4/2x2 Lane MIPI CSI 19 | - Video Output Interfaces 20 | - 1x4 Lane MIPI DSI 21 | - DDR 22 | - SIP 2Gb 16bit LPDDR4x 23 | - Up to 3200Mbit/s rate 24 | - Ethernet 25 | - One 100M Ethernet port, RMII modes 26 | - Inside RMII ePHY 27 | - USB 28 | - USB 2.0 x 1 29 | - Others 30 | - Inside Audio Codec 31 | -------------------------------------------------------------------------------- /docs/AX620U.md: -------------------------------------------------------------------------------- 1 | # AX620U 2 | 3 | ## Brief 4 | 5 | - CPU 6 | - Quad-core Cortex A7 7 | - NPU 8 | - 4Tops@INT4 or 1Tops@INT8 9 | - ISP 10 | - 5Mp@30fps 11 | - AI-ISP 12 | - Video Encoder 13 | - H.264/H.265, 5Mp@30fps+ 14 | - Video Decoder 15 | - H.264, 1080p@60fps 16 | - Video Interfaces 17 | - Video Input Interfaces 18 | - 4+2 Lane MIPI CSI 19 | - Video Output Interfaces 20 | - 2 Lane MIPI CSI/DSI 21 | - DDR 22 | - SIP 16bit LPDDR4x 23 | - 256 MiB 24 | - Ethernet 25 | - One Gigabit Ethernet port 26 | - RGMII and RMII modes 27 | - USB 28 | - USB 2.0 x 1 29 | -------------------------------------------------------------------------------- /docs/AX630A.md: -------------------------------------------------------------------------------- 1 | # AX630A 2 | 3 | ## Brief 4 | 5 | - CPU 6 | - Quad-core Cortex A53 7 | - NPU 8 | - 28.8Tops@INT4 or 7.2Tops@INT8 9 | - DSP 10 | - Dual VDSP 11 | - ISP 12 | - 4K@60fps 13 | - AI-ISP 14 | - Video Encoder 15 | - H.264/H.265, 2K@60fps 16 | - Video Decoder 17 | - H.264/H.265, 2k@120fps 18 | - Video Interfaces 19 | - Video Input Interfaces 20 | - 4+4 Lane MIPI CSI 21 | - Video Output Interfaces 22 | - HDMI 2.0 23 | - 4k@60fps 24 | - DDR 25 | - 2 x 32bit LPDDR4x(x) 26 | - Up to 4266Mbit/s rate 27 | - Ethernet 28 | - Two Gigabit Ethernet port 29 | - RGMII and RMII modes 30 | - USB 31 | - USB 3.0 x 2 32 | - USB 2.0 x 1 33 | -------------------------------------------------------------------------------- /docs/AX630C.md: -------------------------------------------------------------------------------- 1 | # AX630C 2 | 3 | ## Brief 4 | 5 | - CPU 6 | - Dual-core Cortex A53 7 | - NPU 8 | - 12.8Tops@INT4 or 3.2Tops@INT8 9 | - ISP 10 | - 4K@30fps 11 | - AI-ISP/T-ISP 12 | - Video Encoder 13 | - H.264/H.265, 4K@30fps+ 14 | - Video Decoder 15 | - H.264, 1080p@60fps 16 | - Video Interfaces 17 | - Video Input Interfaces 18 | - 1x4/2x2 Lane MIPI CSI 19 | - Video Output Interfaces 20 | - 1x4 Lane MIPI DSI 21 | - DDR 22 | - 32bit LPDDR4x(x) 23 | - Up to 2666Mbit/s rate 24 | - Ethernet 25 | - One Gigabit Ethernet port 26 | - RGMII and RMII modes 27 | - Inside RMII ePHY 28 | - USB 29 | - USB 2.0 x 1 30 | - Others 31 | - Inside Audio Codec 32 | -------------------------------------------------------------------------------- /docs/AX650N.md: -------------------------------------------------------------------------------- 1 | # AX650N 2 | 3 | ## Brief 4 | 5 | - CPU 6 | - Octa-core Cortex A55 7 | - NPU 8 | - 72Tops@INT4 or 18Tops@INT8 9 | - DSP 10 | - Dual VDSP 11 | - ISP 12 | - 8K@30fps 13 | - AI-ISP 14 | - Video Encoder 15 | - H.264/H.265, 8K@30fps 16 | - Video Decoder 17 | - H.264/H.265, 8K@60fps 18 | - Video Interfaces 19 | - Video Input Interfaces 20 | - 2x4 or 4x2 Lane MIPI CSI 21 | - Video Output Interfaces 22 | - HDMI 2.0 x 2 23 | - 4k@60fps + 1080p@60fps 24 | - DDR 25 | - 64bit LPDDR4(x) 26 | - Up to 4266Mbit/s rate 27 | - Ethernet 28 | - Two Gigabit Ethernet port 29 | - RGMII and RMII modes 30 | - PCIe or SATA 31 | - PCIe 2.0 x 2 32 | - SATA3.0 x 4 33 | - USB 34 | - USB 3.0 x 1 35 | - USB 2.0 x 2 36 | -------------------------------------------------------------------------------- /docs/ax620/ax_pose_ppl.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AXERA-TECH/ax-samples/b1c3d859b2c3e48e7c6ed5fd5432230906f214ea/docs/ax620/ax_pose_ppl.jpg -------------------------------------------------------------------------------- /docs/ax620/body_seg_bg_res.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AXERA-TECH/ax-samples/b1c3d859b2c3e48e7c6ed5fd5432230906f214ea/docs/ax620/body_seg_bg_res.jpg -------------------------------------------------------------------------------- /docs/ax620/face_parsing_res.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AXERA-TECH/ax-samples/b1c3d859b2c3e48e7c6ed5fd5432230906f214ea/docs/ax620/face_parsing_res.jpg -------------------------------------------------------------------------------- /docs/ax620/handpose.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AXERA-TECH/ax-samples/b1c3d859b2c3e48e7c6ed5fd5432230906f214ea/docs/ax620/handpose.png -------------------------------------------------------------------------------- /docs/ax620/hrnet.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AXERA-TECH/ax-samples/b1c3d859b2c3e48e7c6ed5fd5432230906f214ea/docs/ax620/hrnet.png -------------------------------------------------------------------------------- /docs/ax620/hrnet_animal.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AXERA-TECH/ax-samples/b1c3d859b2c3e48e7c6ed5fd5432230906f214ea/docs/ax620/hrnet_animal.jpg -------------------------------------------------------------------------------- /docs/ax620/monodlex.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AXERA-TECH/ax-samples/b1c3d859b2c3e48e7c6ed5fd5432230906f214ea/docs/ax620/monodlex.png -------------------------------------------------------------------------------- /docs/ax620/palm_detection.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AXERA-TECH/ax-samples/b1c3d859b2c3e48e7c6ed5fd5432230906f214ea/docs/ax620/palm_detection.jpg -------------------------------------------------------------------------------- /docs/ax620/scrfd.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AXERA-TECH/ax-samples/b1c3d859b2c3e48e7c6ed5fd5432230906f214ea/docs/ax620/scrfd.jpg -------------------------------------------------------------------------------- /docs/ax620/seg_res.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AXERA-TECH/ax-samples/b1c3d859b2c3e48e7c6ed5fd5432230906f214ea/docs/ax620/seg_res.jpg -------------------------------------------------------------------------------- /docs/ax620/yolopv2.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AXERA-TECH/ax-samples/b1c3d859b2c3e48e7c6ed5fd5432230906f214ea/docs/ax620/yolopv2.jpg -------------------------------------------------------------------------------- /docs/ax620/yolov3_paddle.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AXERA-TECH/ax-samples/b1c3d859b2c3e48e7c6ed5fd5432230906f214ea/docs/ax620/yolov3_paddle.jpg -------------------------------------------------------------------------------- /docs/ax620/yolov5_lite_out.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AXERA-TECH/ax-samples/b1c3d859b2c3e48e7c6ed5fd5432230906f214ea/docs/ax620/yolov5_lite_out.jpg -------------------------------------------------------------------------------- /docs/ax620/yolov5s.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AXERA-TECH/ax-samples/b1c3d859b2c3e48e7c6ed5fd5432230906f214ea/docs/ax620/yolov5s.jpg -------------------------------------------------------------------------------- /docs/ax620/yolov5s_face.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AXERA-TECH/ax-samples/b1c3d859b2c3e48e7c6ed5fd5432230906f214ea/docs/ax620/yolov5s_face.jpg -------------------------------------------------------------------------------- /docs/ax620/yolov5s_license_plate_out.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AXERA-TECH/ax-samples/b1c3d859b2c3e48e7c6ed5fd5432230906f214ea/docs/ax620/yolov5s_license_plate_out.jpg -------------------------------------------------------------------------------- /docs/ax620/yolov5s_seg.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AXERA-TECH/ax-samples/b1c3d859b2c3e48e7c6ed5fd5432230906f214ea/docs/ax620/yolov5s_seg.jpg -------------------------------------------------------------------------------- /docs/ax620/yolov5s_visdrone.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AXERA-TECH/ax-samples/b1c3d859b2c3e48e7c6ed5fd5432230906f214ea/docs/ax620/yolov5s_visdrone.jpg -------------------------------------------------------------------------------- /docs/ax620/yolov6s.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AXERA-TECH/ax-samples/b1c3d859b2c3e48e7c6ed5fd5432230906f214ea/docs/ax620/yolov6s.jpg -------------------------------------------------------------------------------- /docs/ax620/yolov7-tiny.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AXERA-TECH/ax-samples/b1c3d859b2c3e48e7c6ed5fd5432230906f214ea/docs/ax620/yolov7-tiny.jpg -------------------------------------------------------------------------------- /docs/ax620/yolov7s_face.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AXERA-TECH/ax-samples/b1c3d859b2c3e48e7c6ed5fd5432230906f214ea/docs/ax620/yolov7s_face.jpg -------------------------------------------------------------------------------- /docs/ax620/yolov7s_palm.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AXERA-TECH/ax-samples/b1c3d859b2c3e48e7c6ed5fd5432230906f214ea/docs/ax620/yolov7s_palm.jpg -------------------------------------------------------------------------------- /docs/ax620/yolov8s.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AXERA-TECH/ax-samples/b1c3d859b2c3e48e7c6ed5fd5432230906f214ea/docs/ax620/yolov8s.jpg -------------------------------------------------------------------------------- /docs/ax620/yolov8s_seg.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AXERA-TECH/ax-samples/b1c3d859b2c3e48e7c6ed5fd5432230906f214ea/docs/ax620/yolov8s_seg.jpg -------------------------------------------------------------------------------- /docs/ax620e/depth_anything_out.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AXERA-TECH/ax-samples/b1c3d859b2c3e48e7c6ed5fd5432230906f214ea/docs/ax620e/depth_anything_out.png -------------------------------------------------------------------------------- /docs/ax620e/simcc_out.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AXERA-TECH/ax-samples/b1c3d859b2c3e48e7c6ed5fd5432230906f214ea/docs/ax620e/simcc_out.jpg -------------------------------------------------------------------------------- /docs/ax620e/yolov10s_out.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AXERA-TECH/ax-samples/b1c3d859b2c3e48e7c6ed5fd5432230906f214ea/docs/ax620e/yolov10s_out.jpg -------------------------------------------------------------------------------- /docs/ax620e/yolov5_face_out.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AXERA-TECH/ax-samples/b1c3d859b2c3e48e7c6ed5fd5432230906f214ea/docs/ax620e/yolov5_face_out.jpg -------------------------------------------------------------------------------- /docs/ax620e/yolov5s_out.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AXERA-TECH/ax-samples/b1c3d859b2c3e48e7c6ed5fd5432230906f214ea/docs/ax620e/yolov5s_out.jpg -------------------------------------------------------------------------------- /docs/ax620e/yolov5s_seg_out.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AXERA-TECH/ax-samples/b1c3d859b2c3e48e7c6ed5fd5432230906f214ea/docs/ax620e/yolov5s_seg_out.jpg -------------------------------------------------------------------------------- /docs/ax620e/yolov6_out.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AXERA-TECH/ax-samples/b1c3d859b2c3e48e7c6ed5fd5432230906f214ea/docs/ax620e/yolov6_out.jpg -------------------------------------------------------------------------------- /docs/ax620e/yolov7_face_out.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AXERA-TECH/ax-samples/b1c3d859b2c3e48e7c6ed5fd5432230906f214ea/docs/ax620e/yolov7_face_out.jpg -------------------------------------------------------------------------------- /docs/ax620e/yolov7_out.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AXERA-TECH/ax-samples/b1c3d859b2c3e48e7c6ed5fd5432230906f214ea/docs/ax620e/yolov7_out.jpg -------------------------------------------------------------------------------- /docs/ax620e/yolov8s_out.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AXERA-TECH/ax-samples/b1c3d859b2c3e48e7c6ed5fd5432230906f214ea/docs/ax620e/yolov8s_out.jpg -------------------------------------------------------------------------------- /docs/ax620e/yolov8s_pose_out.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AXERA-TECH/ax-samples/b1c3d859b2c3e48e7c6ed5fd5432230906f214ea/docs/ax620e/yolov8s_pose_out.jpg -------------------------------------------------------------------------------- /docs/ax620e/yolox_out.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AXERA-TECH/ax-samples/b1c3d859b2c3e48e7c6ed5fd5432230906f214ea/docs/ax620e/yolox_out.jpg -------------------------------------------------------------------------------- /docs/ax650/crowdcount_out.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AXERA-TECH/ax-samples/b1c3d859b2c3e48e7c6ed5fd5432230906f214ea/docs/ax650/crowdcount_out.jpg -------------------------------------------------------------------------------- /docs/ax650/depth_anything_out.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AXERA-TECH/ax-samples/b1c3d859b2c3e48e7c6ed5fd5432230906f214ea/docs/ax650/depth_anything_out.png -------------------------------------------------------------------------------- /docs/ax650/dinov2_mask_out.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AXERA-TECH/ax-samples/b1c3d859b2c3e48e7c6ed5fd5432230906f214ea/docs/ax650/dinov2_mask_out.png -------------------------------------------------------------------------------- /docs/ax650/dog-chai.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AXERA-TECH/ax-samples/b1c3d859b2c3e48e7c6ed5fd5432230906f214ea/docs/ax650/dog-chai.jpeg -------------------------------------------------------------------------------- /docs/ax650/glpdepth_out.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AXERA-TECH/ax-samples/b1c3d859b2c3e48e7c6ed5fd5432230906f214ea/docs/ax650/glpdepth_out.png -------------------------------------------------------------------------------- /docs/ax650/hrnet_out.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AXERA-TECH/ax-samples/b1c3d859b2c3e48e7c6ed5fd5432230906f214ea/docs/ax650/hrnet_out.jpg -------------------------------------------------------------------------------- /docs/ax650/pfld_out.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AXERA-TECH/ax-samples/b1c3d859b2c3e48e7c6ed5fd5432230906f214ea/docs/ax650/pfld_out.jpg -------------------------------------------------------------------------------- /docs/ax650/ppyoloe_out.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AXERA-TECH/ax-samples/b1c3d859b2c3e48e7c6ed5fd5432230906f214ea/docs/ax650/ppyoloe_out.jpg -------------------------------------------------------------------------------- /docs/ax650/realesrgan_in.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AXERA-TECH/ax-samples/b1c3d859b2c3e48e7c6ed5fd5432230906f214ea/docs/ax650/realesrgan_in.png -------------------------------------------------------------------------------- /docs/ax650/realesrgan_out.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AXERA-TECH/ax-samples/b1c3d859b2c3e48e7c6ed5fd5432230906f214ea/docs/ax650/realesrgan_out.jpg -------------------------------------------------------------------------------- /docs/ax650/scrfd_out.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AXERA-TECH/ax-samples/b1c3d859b2c3e48e7c6ed5fd5432230906f214ea/docs/ax650/scrfd_out.jpg -------------------------------------------------------------------------------- /docs/ax650/segformer_out.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AXERA-TECH/ax-samples/b1c3d859b2c3e48e7c6ed5fd5432230906f214ea/docs/ax650/segformer_out.png -------------------------------------------------------------------------------- /docs/ax650/simcc_out.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AXERA-TECH/ax-samples/b1c3d859b2c3e48e7c6ed5fd5432230906f214ea/docs/ax650/simcc_out.jpg -------------------------------------------------------------------------------- /docs/ax650/yolo11_out.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AXERA-TECH/ax-samples/b1c3d859b2c3e48e7c6ed5fd5432230906f214ea/docs/ax650/yolo11_out.jpg -------------------------------------------------------------------------------- /docs/ax650/yolo11_pose_out.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AXERA-TECH/ax-samples/b1c3d859b2c3e48e7c6ed5fd5432230906f214ea/docs/ax650/yolo11_pose_out.jpg -------------------------------------------------------------------------------- /docs/ax650/yolo11_seg_out.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AXERA-TECH/ax-samples/b1c3d859b2c3e48e7c6ed5fd5432230906f214ea/docs/ax650/yolo11_seg_out.jpg -------------------------------------------------------------------------------- /docs/ax650/yolo_nas_out.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AXERA-TECH/ax-samples/b1c3d859b2c3e48e7c6ed5fd5432230906f214ea/docs/ax650/yolo_nas_out.jpg -------------------------------------------------------------------------------- /docs/ax650/yolo_world_open_out.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AXERA-TECH/ax-samples/b1c3d859b2c3e48e7c6ed5fd5432230906f214ea/docs/ax650/yolo_world_open_out.jpg -------------------------------------------------------------------------------- /docs/ax650/yolo_world_out.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AXERA-TECH/ax-samples/b1c3d859b2c3e48e7c6ed5fd5432230906f214ea/docs/ax650/yolo_world_out.jpg -------------------------------------------------------------------------------- /docs/ax650/yolov10s_out.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AXERA-TECH/ax-samples/b1c3d859b2c3e48e7c6ed5fd5432230906f214ea/docs/ax650/yolov10s_out.jpg -------------------------------------------------------------------------------- /docs/ax650/yolov5_face_out.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AXERA-TECH/ax-samples/b1c3d859b2c3e48e7c6ed5fd5432230906f214ea/docs/ax650/yolov5_face_out.jpg -------------------------------------------------------------------------------- /docs/ax650/yolov5s_out.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AXERA-TECH/ax-samples/b1c3d859b2c3e48e7c6ed5fd5432230906f214ea/docs/ax650/yolov5s_out.jpg -------------------------------------------------------------------------------- /docs/ax650/yolov5s_seg_out.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AXERA-TECH/ax-samples/b1c3d859b2c3e48e7c6ed5fd5432230906f214ea/docs/ax650/yolov5s_seg_out.jpg -------------------------------------------------------------------------------- /docs/ax650/yolov6_out.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AXERA-TECH/ax-samples/b1c3d859b2c3e48e7c6ed5fd5432230906f214ea/docs/ax650/yolov6_out.jpg -------------------------------------------------------------------------------- /docs/ax650/yolov7_face_out.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AXERA-TECH/ax-samples/b1c3d859b2c3e48e7c6ed5fd5432230906f214ea/docs/ax650/yolov7_face_out.jpg -------------------------------------------------------------------------------- /docs/ax650/yolov7_out.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AXERA-TECH/ax-samples/b1c3d859b2c3e48e7c6ed5fd5432230906f214ea/docs/ax650/yolov7_out.jpg -------------------------------------------------------------------------------- /docs/ax650/yolov8_pose_out.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AXERA-TECH/ax-samples/b1c3d859b2c3e48e7c6ed5fd5432230906f214ea/docs/ax650/yolov8_pose_out.jpg -------------------------------------------------------------------------------- /docs/ax650/yolov8_seg_out.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AXERA-TECH/ax-samples/b1c3d859b2c3e48e7c6ed5fd5432230906f214ea/docs/ax650/yolov8_seg_out.jpg -------------------------------------------------------------------------------- /docs/ax650/yolov8s_obb_out.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AXERA-TECH/ax-samples/b1c3d859b2c3e48e7c6ed5fd5432230906f214ea/docs/ax650/yolov8s_obb_out.jpg -------------------------------------------------------------------------------- /docs/ax650/yolov8s_out.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AXERA-TECH/ax-samples/b1c3d859b2c3e48e7c6ed5fd5432230906f214ea/docs/ax650/yolov8s_out.jpg -------------------------------------------------------------------------------- /docs/ax650/yolov9_out.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AXERA-TECH/ax-samples/b1c3d859b2c3e48e7c6ed5fd5432230906f214ea/docs/ax650/yolov9_out.jpg -------------------------------------------------------------------------------- /docs/ax650/yolox_out.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AXERA-TECH/ax-samples/b1c3d859b2c3e48e7c6ed5fd5432230906f214ea/docs/ax650/yolox_out.jpg -------------------------------------------------------------------------------- /docs/compile.md: -------------------------------------------------------------------------------- 1 | # 源码编译 2 | 3 | ## [AX650 系列编译详细说明](./compile_650.md) 4 | 支持以下芯片 5 | - AX650A 6 | - AX650N 7 | 8 | ## [AX620E 系列编译详细说明](./compile_620e.md) 9 | 支持以下芯片 10 | - AX630C 11 | - AX620Q 12 | 13 | ## [AX620 系列编译详细说明](./compile_620.md) 14 | 支持以下芯片 15 | - AX620A 16 | - AX620U 17 | 18 | ## [AX630 系列编译详细说明](./compile_630.md) 19 | 支持以下芯片 20 | - AX630A 21 | -------------------------------------------------------------------------------- /docs/compile_620.md: -------------------------------------------------------------------------------- 1 | # 源码编译(AX620) 2 | 3 | ax-samples 的源码编译目前有两种实现路径: 4 | 5 | - 基于 AX-Pi 的本地编译,因为 AX-Pi 上集成的完成了软件开发环境,操作简单; 6 | - 嵌入式 Linux 交叉编译。 7 | 8 | ## 本地编译 9 | 10 | ### 硬件需求 11 | 12 | - 爱芯派(基于AX620A) 13 | 14 | ### 编译过程 15 | 16 | git clone 下载源码,进入 ax-samples 根目录,创建 cmake 编译任务: 17 | 18 | ```bash 19 | $ git clone https://github.com/AXERA-TECH/ax-samples.git 20 | $ cd ax-samples 21 | $ mkdir build 22 | $ cd build 23 | $ cmake .. 24 | $ make install 25 | ``` 26 | 27 | 编译完成后,生成的可执行示例存放在 `ax-samples/build/install/bin/` 路径下: 28 | 29 | ```bash 30 | ax-samples/build$ tree install 31 | install 32 | └── bin 33 | ├── ax_classification 34 | ├── ax_classification_accuracy 35 | ├── ax_classification_nv12 36 | ├── ax_cv_test 37 | ├── ax_hrnet 38 | ├── ax_models_load_inspect 39 | ├── ax_monodlex 40 | ├── ax_nanodet 41 | ├── ax_paddle_mobilehumseg 42 | ├── ax_paddle_mobileseg 43 | ├── ax_paddle_yolov3 44 | ├── ax_robot_obstacle 45 | ├── ax_scrfd 46 | ├── ax_yolo_fastest 47 | ├── ax_yolo_fastest_body 48 | ├── ax_yolov3 49 | ├── ax_yolov3_accuracy 50 | ├── ax_yolov3_tiny 51 | ├── ax_yolov4 52 | ├── ax_yolov4_tiny 53 | ├── ax_yolov4_tiny_3l 54 | ├── ax_yolov5s 55 | ├── ax_yolov5s_620u 56 | ├── ax_yolov7 57 | └── ax_yoloxs 58 | ``` 59 | 60 | ## 交叉编译 61 | 62 | ### 3rdparty 准备 63 | 64 | - 下载预编译好的 OpenCV 库文件 [AX620A/U 匹配](https://github.com/AXERA-TECH/ax-samples/releases/download/v0.1/opencv-arm-linux-gnueabihf-gcc-7.5.0.zip); 65 | - 在 ax-samples 创建 3rdparty 文件,并将下载好的 OpenCV 库文件压缩包解压到该文件夹中。 66 | 67 | ### 交叉编译 armv7a 版本 68 | 69 | 针对 **AX620A** 和 **AX620U** 硬件平台 70 | 71 | #### 编译环境 72 | - cmake 版本大于等于 3.13 73 | - AX620A/U 配套的交叉编译工具链 `arm-linux-gnueabihf-gxx` 已添加到环境变量中 74 | 75 | #### 安装交叉编译工具链 76 | 77 | - Arm32 Linux 交叉编译工具链[获取地址](http://releases.linaro.org/components/toolchain/binaries/7.5-2019.12/arm-linux-gnueabihf/gcc-linaro-7.5.0-2019.12-x86_64_arm-linux-gnueabihf.tar.xz) 78 | 79 | #### 依赖库准备 80 | 81 | - 下载 **ax-samples** 交叉编译依赖库文件并解压到指定路径 `ax_bsp`, [依赖库获取地址](https://github.com/AXERA-TECH/ax-samples/releases/download/v0.3/arm_axpi_r1.22.2801.zip),并将其目录设置到临时环境变量 `$ax_bsp` 82 | 83 | ``` 84 | wget https://github.com/AXERA-TECH/ax-samples/releases/download/v0.3/arm_axpi_r1.22.2801.zip 85 | unzip arm_axpi_r1.22.2801.zip -d ax_bsp 86 | export ax_bsp=$PWD/ax_bsp 87 | echo $ax_bsp 88 | ``` 89 | 90 | #### 源码编译 91 | git clone 下载源码,进入 ax-samples 根目录,创建 cmake 编译任务: 92 | 93 | ```bash 94 | $ git clone https://github.com/AXERA-TECH/ax-samples.git 95 | $ cd ax-samples 96 | $ mkdir build 97 | $ cd build 98 | $ cmake -DCMAKE_TOOLCHAIN_FILE=../toolchains/arm-linux-gnueabihf.toolchain.cmake -DBSP_MSP_DIR=${ax_bsp}/ .. 99 | $ make install 100 | ``` 101 | 102 | 编译完成后,生成的可执行示例存放在 `ax-samples/build/install/bin/` 路径下: 103 | 104 | ```bash 105 | ax-samples/build$ tree install 106 | install 107 | └── bin 108 | ├── ax_classification 109 | ├── ax_classification_accuracy 110 | ├── ax_classification_nv12 111 | ├── ax_cv_test 112 | ├── ax_hrnet 113 | ├── ax_models_load_inspect 114 | ├── ax_monodlex 115 | ├── ax_nanodet 116 | ├── ax_paddle_mobilehumseg 117 | ├── ax_paddle_mobileseg 118 | ├── ax_paddle_yolov3 119 | ├── ax_robot_obstacle 120 | ├── ax_scrfd 121 | ├── ax_yolo_fastest 122 | ├── ax_yolo_fastest_body 123 | ├── ax_yolov3 124 | ├── ax_yolov3_accuracy 125 | ├── ax_yolov3_tiny 126 | ├── ax_yolov4 127 | ├── ax_yolov4_tiny 128 | ├── ax_yolov4_tiny_3l 129 | ├── ax_yolov5s 130 | ├── ax_yolov5s_620u 131 | ├── ax_yolov7 132 | └── ax_yoloxs 133 | ``` 134 | -------------------------------------------------------------------------------- /docs/compile_620e.md: -------------------------------------------------------------------------------- 1 | # 源码编译(AX620E) 2 | 3 | ax-samples 的源码编译目前有两种实现路径: 4 | 5 | - **本地编译**:由于开发板集成了完整的Linux系统,可以预装必要的 gcc、cmake 等开发环境,因此可以在开发板上直接完成源码编译; 6 | - **交叉编译**:在 x86 PC 的常规开发环境中,通过对应的交叉编译工具链完成对源码的编译。 7 | 8 | ## 本地编译 9 | 10 | - 由于 AX630C/AX620Q 的产品定位是嵌入式智能硬件的主控芯片,当前阶段并无完整 Linux 文件系统的产品支持,因此不会存在本地编译的需求; 11 | - AX620Q 有且仅有 SIP 256MiB 内存,因此不会存在本地编译的需求。 12 | 13 | ## 交叉编译 14 | 15 | 当前SDK版本(v2.0.0_P7)中支持 64位、32位 两种不同的编译器版本,下面示例分别基于 AX630C 的 64 位环境与 AX620Q 的 32 位环境进行说明。 16 | 17 | - [AX630C](#AX630C(64位,aarch64-linux)) 18 | - [AX620Q](#AX620Q(32位,arm-uclibc-linux)) 19 | 20 | ### AX630C(64位,aarch64-linux) 21 | 22 | #### 3rdparty 准备 23 | 24 | - 下载预编译好的 [OpenCV 库文件](https://github.com/AXERA-TECH/ax-samples/releases/download/v0.1/opencv-aarch64-linux-gnu-gcc-7.5.0.zip); 25 | - 在 ax-samples 创建 3rdparty 文件,并将下载好的 OpenCV 库文件压缩包解压到该文件夹中,文件夹目录结构如下所示 26 | 27 | ```bash 28 | ax-samples$ tree -L 3 29 | . 30 | ├── 3rdparty 31 | │   └── opencv-aarch64-linux 32 | │   ├── bin 33 | │   ├── build_opencv_aarch64.sh 34 | │   ├── include 35 | │   ├── lib 36 | │   └── share 37 | ``` 38 | 39 | #### 编译环境 40 | - cmake 版本大于等于 3.13 41 | - AX620E 配套的交叉编译工具链 `aarch64-none-linux-gnu-gcc` 已添加到环境变量中 42 | 43 | #### 安装交叉编译工具链 44 | 45 | - Arm64 Linux 交叉编译工具链 [获取地址](https://developer.arm.com/-/media/Files/downloads/gnu-a/9.2-2019.12/binrel/gcc-arm-9.2-2019.12-x86_64-aarch64-none-linux-gnu.tar.xz) 46 | 47 | #### 依赖库准备 48 | 49 | 请联系 FAE 获取 AX620E BSP 开发包,执行如下操作 50 | 51 | ``` 52 | tar -zxvf AX620E_SDK_XXX.tgz 53 | cd AX620E_SDK_XXX/package 54 | tar -zxvf msp.tgz 55 | ``` 56 | 57 | 解压完成后将文件夹内此 `msp/out` 目录设置到临时环境变量,具体操作如下: 58 | 59 | ``` 60 | export ax_bsp=${ax620e_bsp_sdk PATH}/msp/out/arm64_glibc 61 | ``` 62 | 63 | #### 源码编译 64 | git clone 下载源码,进入 ax-samples 根目录,创建 cmake 编译任务: 65 | 66 | ```bash 67 | git clone https://github.com/AXERA-TECH/ax-samples.git 68 | cd ax-samples 69 | mkdir build && cd build 70 | cmake -DCMAKE_TOOLCHAIN_FILE=../toolchains/aarch64-none-linux-gnu.toolchain.cmake -DBSP_MSP_DIR=${ax_bsp}/ -DAXERA_TARGET_CHIP=ax630c .. 71 | make -j6 72 | make install 73 | ``` 74 | 75 | 编译完成后,生成的可执行示例存放在 `ax-samples/build/install/ax630c/` 路径下: 76 | 77 | ```bash 78 | ax-samples/build$ tree install 79 | install 80 | └── ax630c 81 | ├── ax_classification 82 | ├── ax_crowdcount 83 | ├── ax_depth_anything 84 | ├── ax_imgproc 85 | ├── ax_model_info 86 | ├── ax_rtdetr 87 | ├── ax_scrfd 88 | ├── ax_simcc_pose 89 | ├── ax_yolov5_face 90 | ├── ax_yolov5s 91 | ├── ax_yolov5s_seg 92 | ├── ax_yolov6 93 | ├── ax_yolov7 94 | ├── ax_yolov7_tiny_face 95 | ├── ax_yolov8 96 | ├── ax_yolov8_pose 97 | ├── ax_yolov8_seg 98 | ├── ax_yolov9 99 | └── ax_yolox 100 | ``` 101 | 102 | ### AX620Q(32位,arm-uclibc-linux) 103 | 104 | #### 3rdparty 准备 105 | 106 | - 下载预编译好的 [OpenCV 库文件](https://github.com/AXERA-TECH/ax-samples/releases/download/v0.6/opencv-arm-uclibc-linux.zip); 107 | - 在 ax-samples 创建 3rdparty 文件,并将下载好的 OpenCV 库文件压缩包解压到该文件夹中,文件夹目录结构如下所示 108 | 109 | ```bash 110 | ax-samples$ tree -L 3 111 | . 112 | ├── 3rdparty 113 | │   └── opencv-arm-uclibc-linux 114 | │   ├── bin 115 | │   ├── include 116 | │   ├── lib 117 | │   └── share 118 | ``` 119 | 120 | #### 编译环境 121 | - cmake 版本大于等于 3.13 122 | - AX620E 配套的交叉编译工具链 `arm-AX620E-linux-uclibcgnueabihf-gxx` 已添加到环境变量中 123 | 124 | #### 安装交叉编译工具链 125 | 126 | - Arm32 Linux 交叉编译工具链 [获取地址](https://github.com/AXERA-TECH/ax620q_bsp_sdk/releases/download/v2.0.0/arm-AX620E-linux-uclibcgnueabihf_V3_20240320.tgz) 127 | 128 | #### 依赖库准备 129 | 130 | 请联系 FAE 获取 AX620E BSP 开发包,执行如下操作 131 | 132 | ``` 133 | tar -zxvf AX620E_SDK_XXX.tgz 134 | cd AX620E_SDK_XXX/package 135 | tar -zxvf msp.tgz 136 | ``` 137 | 138 | 解压完成后将文件夹内此 `msp/out` 目录设置到临时环境变量,具体操作如下: 139 | 140 | ``` 141 | export ax_bsp=${ax620e_bsp_sdk PATH}/msp/out/arm_uclibc 142 | ``` 143 | 144 | #### 源码编译 145 | git clone 下载源码,进入 ax-samples 根目录,创建 cmake 编译任务: 146 | 147 | ```bash 148 | git clone https://github.com/AXERA-TECH/ax-samples.git 149 | cd ax-samples 150 | mkdir build && cd build 151 | cmake -DCMAKE_TOOLCHAIN_FILE=../toolchains/arm-AX620E-linux-uclibcgnueabihf.toolchain.cmake -DBSP_MSP_DIR=${ax_bsp}/ -DAXERA_TARGET_CHIP=ax620q .. 152 | make -j6 153 | make install 154 | ``` 155 | 156 | 编译完成后,生成的可执行示例存放在 `ax-samples/build/install/ax620q/` 路径下: 157 | 158 | ```bash 159 | ax-samples/build$ tree install 160 | install 161 | └── ax620q 162 | ├── ax_classification 163 | ├── ax_crowdcount 164 | ├── ax_depth_anything 165 | ├── ax_imgproc 166 | ├── ax_model_info 167 | ├── ax_rtdetr 168 | ├── ax_scrfd 169 | ├── ax_simcc_pose 170 | ├── ax_yolov5_face 171 | ├── ax_yolov5s 172 | ├── ax_yolov5s_seg 173 | ├── ax_yolov6 174 | ├── ax_yolov7 175 | ├── ax_yolov7_tiny_face 176 | ├── ax_yolov8 177 | ├── ax_yolov8_pose 178 | ├── ax_yolov8_seg 179 | ├── ax_yolov9 180 | └── ax_yolox 181 | ``` 182 | -------------------------------------------------------------------------------- /docs/compile_630.md: -------------------------------------------------------------------------------- 1 | # 源码编译(AX630) 2 | 3 | ## 交叉编译 4 | 5 | 针对 **AX630A** 的硬件平台 6 | 7 | #### 编译环境 8 | - cmake 版本大于等于 3.13 9 | - AX630A 配套的交叉编译工具链 `aarch64-linux-gnu-gxx` 已添加到环境变量中 10 | 11 | #### 安装交叉编译工具链 12 | 13 | - aarch64 Linux 交叉编译工具链[获取地址](http://releases.linaro.org/components/toolchain/binaries/7.5-2019.12/aarch64-linux-gnu/gcc-linaro-7.5.0-2019.12-x86_64_aarch64-linux-gnu.tar.xz) 14 | 15 | #### BSP 准备 16 | 17 | 请联系 FAE 获取 AX630 BSP 开发包,执行如下操作 18 | ``` 19 | tar -zxvf AX630_SDK_XXX.tgz 20 | cd AX630_SDK_XXX/package 21 | tar -zxvf msp.tgz 22 | ``` 23 | 24 | #### 源码编译 25 | git clone 下载源码,进入 ax-samples 根目录,创建 cmake 编译任务: 26 | 27 | ```bash 28 | $ git clone https://github.com/AXERA-TECH/ax-samples.git 29 | $ cd ax-samples 30 | $ cd build 31 | $ cmake -DCMAKE_TOOLCHAIN_FILE=../toolchains/aarch64-linux-gnu.toolchain.cmake -DBSP_MSP_DIR=${AX630_SDK_XXX}/msp/out/ -DAXERA_TARGET_CHIP=ax630a .. 32 | $ make install 33 | ``` 34 | 35 | 编译完成后,生成的可执行示例存放在 `ax-samples/build/install/bin/` 路径下: 36 | 37 | ```bash 38 | ax-samples/build$ tree install 39 | install 40 | └── bin 41 | ├── ax_classification 42 | ├── ax_yolo_fastest 43 | ├── ax_yolov3 44 | └── ax_yolov5s 45 | ``` 46 | -------------------------------------------------------------------------------- /docs/compile_650.md: -------------------------------------------------------------------------------- 1 | # 源码编译(AX650N) 2 | 3 | ax-samples 的源码编译目前有两种实现路径: 4 | 5 | - **本地编译**:由于开发板集成了完整的Linux系统,可以预装必要的 gcc、cmake 等开发环境,因此可以在开发板上直接完成源码编译; 6 | - **交叉编译**:在 x86 PC 的常规开发环境中,通过对应的交叉编译工具链完成对源码的编译。 7 | 8 | ## 本地编译 9 | 10 | ### 已支持硬件板卡 11 | 12 | - 爱芯派Pro(基于 AX650N) 13 | 14 | ### 环境搭建 15 | 16 | 在开发板上安装必要的软件开发环境 17 | 18 | ```bash 19 | apt update 20 | apt install build-essential libopencv-dev cmake 21 | ``` 22 | 23 | ### 编译过程 24 | 25 | git clone 下载源码,进入 ax-samples 根目录,创建 cmake 编译任务: 26 | 27 | ```bash 28 | git clone https://github.com/AXERA-TECH/ax-samples.git 29 | cd ax-samples 30 | mkdir build && cd build 31 | cmake -DBSP_MSP_DIR=/soc/ -DAXERA_TARGET_CHIP=ax650 .. 32 | make -j6 33 | make install 34 | ``` 35 | 36 | 编译完成后,生成的可执行示例存放在 `ax-samples/build/install/ax650/` 路径下: 37 | 38 | ```bash 39 | ax-samples/build$ tree install 40 | install 41 | └── ax650 42 | ├── ax_classification 43 | ├── ax_detr 44 | ├── ax_dinov2 45 | ├── ax_glpdepth 46 | ├── ax_hrnet 47 | ├── ax_imgproc 48 | ├── ax_pfld 49 | ├── ax_pp_humanseg 50 | ├── ax_pp_liteseg_stdc2_cityscapes 51 | ├── ax_pp_ocr_rec 52 | ├── ax_pp_person_attribute 53 | ├── ax_pp_vehicle_attribute 54 | ├── ax_ppyoloe 55 | ├── ax_ppyoloe_obj365 56 | ├── ax_realesrgan 57 | ├── ax_rtmdet 58 | ├── ax_scrfd 59 | ├── ax_segformer 60 | ├── ax_simcc_pose 61 | ├── ax_yolo_nas 62 | ├── ax_yolov5_face 63 | ├── ax_yolov5s 64 | ├── ax_yolov5s_seg 65 | ├── ax_yolov6 66 | ├── ax_yolov7 67 | ├── ax_yolov7_tiny_face 68 | ├── ax_yolov8 69 | ├── ax_yolov8_pose 70 | └── ax_yolox 71 | ``` 72 | 73 | ## 交叉编译 74 | 75 | ### 3rdparty 准备 76 | 77 | - 下载预编译好的 [OpenCV 库文件](https://github.com/AXERA-TECH/ax-samples/releases/download/v0.1/opencv-aarch64-linux-gnu-gcc-7.5.0.zip); 78 | - 在 ax-samples 创建 3rdparty 文件,并将下载好的 OpenCV 库文件压缩包解压到该文件夹中,文件夹目录结构如下所示 79 | 80 | ```bash 81 | ax-samples$ tree -L 3 82 | . 83 | ├── 3rdparty 84 | │   └── opencv-aarch64-linux 85 | │   ├── bin 86 | │   ├── build_opencv_aarch64.sh 87 | │   ├── include 88 | │   ├── lib 89 | │   └── share 90 | ``` 91 | 92 | ### 编译环境 93 | - cmake 版本大于等于 3.13 94 | - AX650 配套的交叉编译工具链 `aarch64-none-linux-gnu-gcc` 已添加到环境变量中 95 | 96 | ### 安装交叉编译工具链 97 | 98 | - aarch64 Linux 交叉编译工具链 [获取地址](https://developer.arm.com/-/media/Files/downloads/gnu-a/9.2-2019.12/binrel/gcc-arm-9.2-2019.12-x86_64-aarch64-none-linux-gnu.tar.xz) 99 | 100 | ### 依赖库准备 101 | 102 | 下载 ax650_bsp_sdk 社区版本 103 | ``` 104 | git clone https://github.com/AXERA-TECH/ax650n_bsp_sdk.git 105 | ``` 106 | 107 | 下载完成后将文件夹内此 `msp/out` 目录设置到临时环境变量,具体操作如下: 108 | 109 | ``` 110 | export ax_bsp=${ax650n_bsp_sdk PATH}/msp/out 111 | ``` 112 | 113 | ### 源码编译 114 | git clone 下载源码,进入 ax-samples 根目录,创建 cmake 编译任务: 115 | 116 | ```bash 117 | git clone https://github.com/AXERA-TECH/ax-samples.git 118 | cd ax-samples 119 | mkdir build & cd build 120 | cmake -DCMAKE_TOOLCHAIN_FILE=../toolchains/aarch64-none-linux-gnu.toolchain.cmake -DBSP_MSP_DIR=${ax_bsp}/ -DAXERA_TARGET_CHIP=ax650 .. 121 | make -j6 122 | make install 123 | ``` 124 | 125 | 编译完成后,生成的可执行示例存放在 `ax-samples/build/install/ax650/` 路径下: 126 | 127 | ```bash 128 | ax-samples/build$ tree install 129 | install 130 | └── ax650 131 | ├── ax_classification 132 | ├── ax_detr 133 | ├── ax_dinov2 134 | ├── ax_glpdepth 135 | ├── ax_hrnet 136 | ├── ax_imgproc 137 | ├── ax_pfld 138 | ├── ax_pp_humanseg 139 | ├── ax_pp_liteseg_stdc2_cityscapes 140 | ├── ax_pp_ocr_rec 141 | ├── ax_pp_person_attribute 142 | ├── ax_pp_vehicle_attribute 143 | ├── ax_ppyoloe 144 | ├── ax_ppyoloe_obj365 145 | ├── ax_realesrgan 146 | ├── ax_rtmdet 147 | ├── ax_scrfd 148 | ├── ax_segformer 149 | ├── ax_simcc_pose 150 | ├── ax_yolo_nas 151 | ├── ax_yolov5_face 152 | ├── ax_yolov5s 153 | ├── ax_yolov5s_seg 154 | ├── ax_yolov6 155 | ├── ax_yolov7 156 | ├── ax_yolov7_tiny_face 157 | ├── ax_yolov8 158 | ├── ax_yolov8_pose 159 | └── ax_yolox 160 | ``` 161 | -------------------------------------------------------------------------------- /examples/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # AXERA is pleased to support the open source community by making ax-samples available. 2 | # 3 | # Copyright (c) 2022, AXERA Semiconductor (Shanghai) Co., Ltd. All rights reserved. 4 | # 5 | # Licensed under the BSD 3-Clause License (the "License"); you may not use this file except 6 | # in compliance with the License. You may obtain a copy of the License at 7 | # 8 | # https://opensource.org/licenses/BSD-3-Clause 9 | # 10 | # Unless required by applicable law or agreed to in writing, software distributed 11 | # under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 12 | # CONDITIONS OF ANY KIND, either express or implied. See the License for the 13 | # specific language governing permissions and limitations under the License. 14 | # 15 | # Author: ls.wang 16 | # 17 | 18 | if(NOT BSP_MSP_DIR) 19 | set(BSP_MSP_DIR ${CMAKE_SOURCE_DIR}/out) 20 | endif() 21 | 22 | message(STATUS "BSP_MSP_DIR = ${BSP_MSP_DIR}") 23 | 24 | if(AXERA_TARGET_CHIP MATCHES "ax650") 25 | if(NOT OpenCV_DIR) 26 | set(OpenCV_DIR ${CMAKE_SOURCE_DIR}/3rdparty/opencv-aarch64-linux/lib/cmake/opencv4) 27 | endif() 28 | 29 | add_definitions(-DAXERA_TARGET_CHIP_AX650) 30 | elseif(AXERA_TARGET_CHIP MATCHES "ax630c") 31 | if(NOT OpenCV_DIR) 32 | set(OpenCV_DIR ${CMAKE_SOURCE_DIR}/3rdparty/opencv-aarch64-linux/lib/cmake/opencv4) 33 | endif() 34 | 35 | add_definitions(-DAXERA_TARGET_CHIP_AX620E) 36 | elseif(AXERA_TARGET_CHIP MATCHES "ax620q") 37 | if(NOT OpenCV_DIR) 38 | set(OpenCV_DIR ${CMAKE_SOURCE_DIR}/3rdparty/opencv-arm-uclibc-linux/lib/cmake/opencv4) 39 | endif() 40 | 41 | add_definitions(-DAXERA_TARGET_CHIP_AX620E) 42 | elseif(AXERA_TARGET_CHIP MATCHES "ax620a") 43 | if(NOT OpenCV_DIR) 44 | set(OpenCV_DIR ${CMAKE_SOURCE_DIR}/3rdparty/opencv-arm-linux/lib/cmake/opencv4) 45 | endif() 46 | 47 | add_definitions(-DAXERA_TARGET_CHIP_AX620) 48 | elseif(AXERA_TARGET_CHIP MATCHES "ax630a") 49 | if(NOT OpenCV_DIR) 50 | set(OpenCV_DIR ${CMAKE_SOURCE_DIR}/3rdparty/opencv-aarch64-linux/lib/cmake/opencv4) 51 | endif() 52 | 53 | add_definitions(-DAXERA_TARGET_CHIP_AX630) 54 | endif() 55 | 56 | find_package(OpenCV REQUIRED) 57 | 58 | # open when need debug on board 59 | # add_definitions("-g -O0") 60 | message(STATUS "BUILD FOR ${AXERA_TARGET_CHIP}") 61 | include_directories(.) 62 | 63 | if(AXERA_TARGET_CHIP MATCHES "ax650") 64 | add_subdirectory(${CMAKE_SOURCE_DIR}/examples/ax650) 65 | elseif(AXERA_TARGET_CHIP MATCHES "ax630c") 66 | add_subdirectory(${CMAKE_SOURCE_DIR}/examples/ax620e) 67 | elseif(AXERA_TARGET_CHIP MATCHES "ax620q") 68 | add_subdirectory(${CMAKE_SOURCE_DIR}/examples/ax620e) 69 | elseif(AXERA_TARGET_CHIP MATCHES "ax620a") 70 | add_subdirectory(${CMAKE_SOURCE_DIR}/examples/ax620) 71 | elseif(AXERA_TARGET_CHIP MATCHES "ax630a") 72 | add_subdirectory(${CMAKE_SOURCE_DIR}/examples/ax620) 73 | endif() 74 | -------------------------------------------------------------------------------- /examples/ax620/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # AXERA is pleased to support the open source community by making ax-samples available. 2 | # 3 | # Copyright (c) 2022, AXERA Semiconductor (Shanghai) Co., Ltd. All rights reserved. 4 | # 5 | # Licensed under the BSD 3-Clause License (the "License"); you may not use this file except 6 | # in compliance with the License. You may obtain a copy of the License at 7 | # 8 | # https://opensource.org/licenses/BSD-3-Clause 9 | # 10 | # Unless required by applicable law or agreed to in writing, software distributed 11 | # under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 12 | # CONDITIONS OF ANY KIND, either express or implied. See the License for the 13 | # specific language governing permissions and limitations under the License. 14 | # 15 | # Author: ls.wang 16 | # 17 | 18 | # example generation function 19 | # function (axera_example name) 20 | # add_executable(${name}) 21 | 22 | # # add srcs 23 | # foreach (file IN LISTS ARGN) 24 | # target_sources (${name} PRIVATE ${file}) 25 | # endforeach() 26 | 27 | # # headers 28 | # target_include_directories (${name} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}) 29 | # target_include_directories (${name} PRIVATE ${BSP_MSP_DIR}/include) 30 | # if (${AXERA_TARGET_PROCESSOR} MATCHES "ARM" AND AXERA_TARGET_PROCESSOR_32Bit) 31 | # target_include_directories (${name} PRIVATE /opt/include) 32 | # endif() 33 | 34 | # # libs 35 | # if (AXERA_TARGET_CHIP MATCHES "ax620a") # ax620 support 36 | # target_link_libraries (${name} PRIVATE pthread dl) # ax620a use this 37 | # # target_link_libraries (${name} PRIVATE pthread dl stdc++fs) # ax620u use this 38 | # target_link_libraries (${name} PRIVATE ax_run_joint ax_interpreter_external ax_interpreter ax_sys axsyslog stdc++fs) 39 | # else() # ax630a support 40 | # target_link_libraries (${name} PRIVATE pthread dl stdc++fs) 41 | # target_link_libraries (${name} PRIVATE ax_run_joint ax_interpreter_external ax_interpreter ax_sys) 42 | # endif() 43 | # target_link_libraries (${name} PRIVATE ax_ivps ax_npu_cv_kit) 44 | 45 | # # folders 46 | # target_link_directories (${name} PRIVATE ${BSP_MSP_DIR}/lib) 47 | # if (${AXERA_TARGET_PROCESSOR} MATCHES "ARM" AND AXERA_TARGET_PROCESSOR_32Bit) 48 | # target_link_libraries (${name} PRIVATE dl) 49 | # target_link_directories (${name} PRIVATE /opt/lib) 50 | # endif() 51 | 52 | # # opencv 53 | # target_include_directories (${name} PRIVATE ${OpenCV_INCLUDE_DIRS}) 54 | # target_link_libraries(${name} PRIVATE ${OpenCV_LIBS}) 55 | 56 | # install (TARGETS ${name} DESTINATION bin) 57 | # endfunction() 58 | 59 | if(AXERA_TARGET_CHIP MATCHES "ax620a") # ax620 support 60 | include("${CMAKE_SOURCE_DIR}/cmake/ax620.cmake") 61 | 62 | axera_example(ax_classification ax_classification_steps.cc) 63 | axera_example(ax_classification_nv12 ax_classification_nv12_resize_steps.cc) 64 | axera_example(ax_classification_nv12_opt ax_classification_nv12_resize_opt.cc) 65 | axera_example(ax_yolov5s ax_yolov5s_steps.cc) 66 | axera_example(ax_yolov5_lite ax_yolov5_lite_steps.cc) 67 | axera_example(ax_yolov5s_face ax_yolov5s_face_steps.cc) 68 | axera_example(ax_yolov5s_visdrone ax_yolov5s_visdrone_steps.cc) 69 | axera_example(ax_yoloxs ax_yoloxs_steps.cc) 70 | axera_example(ax_yolo_fastest ax_yolo_fastest_steps.cc) 71 | axera_example(ax_yolo_fastest_body ax_yolo_fastest_body_steps.cc) 72 | axera_example(ax_hrnet ax_hrnet_steps.cc) 73 | axera_example(ax_hrnet_animal ax_hrnet_animal_steps.cc) 74 | axera_example(ax_yolov3 ax_yolov3_steps.cc) 75 | axera_example(ax_yolov3_tiny ax_yolov3_tiny_steps.cc) 76 | axera_example(ax_yolov4 ax_yolov4_steps.cc) 77 | axera_example(ax_yolov4_tiny ax_yolov4_tiny_steps.cc) 78 | axera_example(ax_yolov4_tiny_3l ax_yolov4_tiny_3l_steps.cc) 79 | axera_example(ax_nanodet ax_nanodet_steps.cc) 80 | axera_example(ax_paddle_yolov3 ax_paddle_yolov3_steps.cc) 81 | axera_example(ax_scrfd ax_scrfd_steps.cc) 82 | axera_example(ax_pose_ppl ax_pose_ppl_steps.cc) 83 | axera_example(ax_yolov5s_license_plate ax_yolov5s_license_plate_steps.cc) 84 | 85 | axera_example(ax_classification_accuracy ax_classification_accuracy.cc) 86 | axera_example(ax_yolov3_accuracy ax_yolov3_accuracy.cc) 87 | 88 | axera_example(ax_yolov5s_620u ax_yolov5s_620u_steps.cc) 89 | axera_example(ax_robot_obstacle ax_robot_obstacle_detect_steps.cc) 90 | axera_example(ax_yolov7 ax_yolov7_steps.cc) 91 | axera_example(ax_models_load_inspect ax_models_load_inspect.cc) 92 | axera_example(ax_paddle_mobilehumseg ax_paddle_mobilehumseg_steps.cc) 93 | axera_example(ax_monodlex ax_monodlex_steps.cc) 94 | axera_example(ax_paddle_mobileseg ax_paddle_mobileseg.cc) 95 | axera_example(ax_crnn ax_crnn_steps.cc) 96 | axera_example(ax_face_parsing ax_face_parsing_steps.cc) 97 | axera_example(ax_handpose ax_handpose_steps.cc) 98 | axera_example(ax_yolov5s_seg ax_yolov5s_seg_steps.cc) 99 | axera_example(ax_palm_detection ax_palm_detection_steps.cc) 100 | axera_example(ax_yolopv2 ax_yolopv2_steps.cc) 101 | axera_example(ax_yolov7s_face ax_yolov7s_face_steps.cc) 102 | axera_example(ax_yolov7s_palm ax_yolov7s_palm_steps.cc) 103 | axera_example(ax_yolov6s ax_yolov6s_steps.cc) 104 | axera_example(ax_yolov8s ax_yolov8s_steps.cc) 105 | axera_example(ax_yolov8s_seg ax_yolov8s_seg_steps.cc) 106 | axera_example(ax_yolov8s_pose ax_yolov8s_pose_steps.cc) 107 | 108 | # ******************************** MMYOLO model ********************************# 109 | # axera_example (ax_mmyolov5s mmyolo/ax_mmyolov5s.cc) 110 | axera_example(ax_mmyoloxs mmyolo/ax_mmyoloxs.cc) 111 | axera_example(ax_mmppyoloeps mmyolo/ax_mmppyoloeps.cc) 112 | axera_example(ax_mmyolov6s mmyolo/ax_mmyolov6s.cc) 113 | 114 | # axera_example (ax_mmyolov7t mmyolo/ax_mmyolov7t.cc) 115 | # axera_example (ax_mmrtmdets mmyolo/ax_mmrtmdets.cc) 116 | axera_example(ax_mmyolov8s mmyolo/ax_mmyolov8s.cc) 117 | 118 | else() # ax630a support 119 | axera_example(ax_classification ax_classification_steps.cc) 120 | axera_example(ax_yolov5s ax_yolov5s_steps.cc) 121 | axera_example(ax_yolo_fastest ax_yolo_fastest_steps.cc) 122 | axera_example(ax_yolov3 ax_yolov3_steps.cc) 123 | endif() 124 | -------------------------------------------------------------------------------- /examples/ax620/cv/utils.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * AXERA is pleased to support the open source community by making ax-samples available. 3 | * 4 | * Copyright (c) 2022, AXERA Semiconductor (Shanghai) Co., Ltd. All rights reserved. 5 | * 6 | * Licensed under the BSD 3-Clause License (the "License"); you may not use this file except 7 | * in compliance with the License. You may obtain a copy of the License at 8 | * 9 | * https://opensource.org/licenses/BSD-3-Clause 10 | * 11 | * Unless required by applicable law or agreed to in writing, software distributed 12 | * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 13 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the 14 | * specific language governing permissions and limitations under the License. 15 | */ 16 | 17 | /* 18 | * Author: hebing 19 | */ 20 | 21 | #pragma once 22 | 23 | #include "ax_interpreter_external_api.h" 24 | #include "ax_sys_api.h" 25 | #include "npu_cv_kit/ax_npu_imgproc.h" 26 | #include 27 | #include 28 | 29 | namespace cv 30 | { 31 | static inline AX_NPU_SDK_EX_ATTR_T get_npu_hard_mode(const std::string& mode) 32 | { 33 | AX_NPU_SDK_EX_ATTR_T hard_mode; 34 | if (mode == "1_1") 35 | { 36 | printf("\nVirtual npu mode is 1_1\n\n"); 37 | hard_mode.eHardMode = AX_NPU_SDK_EX_HARD_MODE_T::AX_NPU_VIRTUAL_1_1; 38 | } 39 | else 40 | { 41 | printf("\nVirtual npu disable!\n\n"); 42 | hard_mode.eHardMode = AX_NPU_SDK_EX_HARD_MODE_T::AX_NPU_VIRTUAL_DISABLE; 43 | } 44 | return hard_mode; 45 | } 46 | 47 | static inline AX_NPU_SDK_EX_MODEL_TYPE_T get_npu_mode_type(const std::string& mode_type) 48 | { 49 | if (mode_type == "1_1_1") 50 | { 51 | printf("\nVirtual npu mode type is 1_1_1\n\n"); 52 | return AX_NPU_MODEL_TYPE_1_1_1; 53 | } 54 | else if (mode_type == "1_1_2") 55 | { 56 | printf("\nVirtual npu mode type is 1_1_2\n\n"); 57 | return AX_NPU_MODEL_TYPE_1_1_2; 58 | } 59 | else 60 | { 61 | printf("\nVirtual npu mode type is disable!\n\n"); 62 | return AX_NPU_MODEL_TYPE_DEFUALT; 63 | } 64 | } 65 | 66 | AX_NPU_CV_FrameDataType get_color_space(const std::string& color_space) 67 | { 68 | if (color_space == "NV12" || color_space == "nv12") 69 | { 70 | return AX_NPU_CV_FDT_NV12; 71 | } 72 | else if (color_space == "NV21" || color_space == "nv21") 73 | { 74 | return AX_NPU_CV_FDT_NV21; 75 | } 76 | else if (color_space == "RGB" || color_space == "rgb") 77 | { 78 | return AX_NPU_CV_FDT_RGB; 79 | } 80 | else if (color_space == "BGR" || color_space == "bgr") 81 | { 82 | return AX_NPU_CV_FDT_BGR; 83 | } 84 | else if (color_space == "RGBA" || color_space == "rgba") 85 | { 86 | return AX_NPU_CV_FDT_RGBA; 87 | } 88 | else if (color_space == "GRAY" || color_space == "gray") 89 | { 90 | return AX_NPU_CV_FDT_GRAY; 91 | } 92 | else 93 | { 94 | printf("color space support error! \n"); 95 | } 96 | } 97 | 98 | uint32_t get_image_stride_w(const AX_NPU_CV_Image* pImg) 99 | { 100 | // 内部使用接口,不再冗余校验pImg指针 101 | if (pImg->tStride.nW == 0) 102 | { 103 | return pImg->nWidth; 104 | } 105 | else if (pImg->tStride.nW >= pImg->nWidth) 106 | { 107 | if ((pImg->eDtype == AX_NPU_CV_FDT_NV12 || pImg->eDtype == AX_NPU_CV_FDT_NV21) && pImg->tStride.nW % 2 != 0) 108 | { 109 | fprintf(stderr, "[ERR] Invalid param: image stride_w %d should be even for NV12/NV21", pImg->tStride.nW); 110 | } 111 | return pImg->tStride.nW; 112 | } 113 | else 114 | { 115 | fprintf(stderr, "Invalid param: image stride_w %d not less than image width %d", pImg->tStride.nW, pImg->nWidth); 116 | } 117 | return pImg->nWidth; 118 | } 119 | 120 | int get_image_data_size(const AX_NPU_CV_Image* img) 121 | { 122 | int stride_w = get_image_stride_w(img); 123 | switch (img->eDtype) 124 | { 125 | case AX_NPU_CV_FDT_NV12: // FIXME 126 | case AX_NPU_CV_FDT_NV21: 127 | return int(stride_w * img->nHeight * 3 / 2); 128 | 129 | case AX_NPU_CV_FDT_RGB: 130 | case AX_NPU_CV_FDT_BGR: 131 | case AX_NPU_CV_FDT_YUV444: 132 | return int(stride_w * img->nHeight * 3); 133 | 134 | case AX_NPU_CV_FDT_RGBA: 135 | return int(stride_w * img->nHeight * 4); 136 | 137 | case AX_NPU_CV_FDT_GRAY: 138 | return int(stride_w * img->nHeight * 1); 139 | 140 | default: 141 | fprintf(stderr, "[ERR] unsupported color space %d to calculate image data size\n", (int)img->eDtype); 142 | return 0; 143 | } 144 | } 145 | 146 | } // namespace cv -------------------------------------------------------------------------------- /examples/ax620/middleware/common_ax620.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * AXERA is pleased to support the open source community by making ax-samples available. 3 | * 4 | * Copyright (c) 2022, AXERA Semiconductor (Shanghai) Co., Ltd. All rights reserved. 5 | * 6 | * Licensed under the BSD 3-Clause License (the "License"); you may not use this file except 7 | * in compliance with the License. You may obtain a copy of the License at 8 | * 9 | * https://opensource.org/licenses/BSD-3-Clause 10 | * 11 | * Unless required by applicable law or agreed to in writing, software distributed 12 | * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 13 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the 14 | * specific language governing permissions and limitations under the License. 15 | */ 16 | 17 | /* 18 | * Author: ls.wang 19 | */ 20 | 21 | #pragma once 22 | 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include "ax_interpreter_external_api.h" 30 | #include "base/common.hpp" 31 | 32 | namespace common 33 | { 34 | static inline AX_NPU_SDK_EX_HARD_MODE_T get_hard_mode_by_model_type(int model_type) 35 | { 36 | if (AX_NPU_MODEL_TYPE_DEFUALT == model_type) 37 | { 38 | return AX_NPU_SDK_EX_HARD_MODE_T::AX_NPU_VIRTUAL_DISABLE; 39 | } 40 | #ifdef AXERA_TARGET_CHIP_AX620 41 | else if (model_type == AX_NPU_MODEL_TYPE_1_1_1 || model_type == AX_NPU_MODEL_TYPE_1_1_2) 42 | { 43 | return AX_NPU_SDK_EX_HARD_MODE_T::AX_NPU_VIRTUAL_1_1; 44 | } 45 | #else 46 | else if (model_type == AX_NPU_MODEL_TYPE_3_1_1 || model_type == AX_NPU_MODEL_TYPE_3_1_2) 47 | { 48 | return AX_NPU_SDK_EX_HARD_MODE_T::AX_NPU_VIRTUAL_3_1; 49 | } 50 | else if (model_type == AX_NPU_MODEL_TYPE_2_2_1 || model_type == AX_NPU_MODEL_TYPE_2_2_2) 51 | { 52 | return AX_NPU_SDK_EX_HARD_MODE_T::AX_NPU_VIRTUAL_2_2; 53 | } 54 | #endif 55 | else 56 | { 57 | fprintf(stderr, "[ERR]: get_hard_mode_by_model_type(int model_type) Unknown npu mode(%d). return default mode\n", model_type); 58 | return (AX_NPU_SDK_EX_HARD_MODE_T)0; 59 | } 60 | } 61 | } // namespace common -------------------------------------------------------------------------------- /examples/ax620e/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # AXERA is pleased to support the open source community by making ax-samples available. 2 | # 3 | # Copyright (c) 2022, AXERA Semiconductor (Shanghai) Co., Ltd. All rights reserved. 4 | # 5 | # Licensed under the BSD 3-Clause License (the "License"); you may not use this file except 6 | # in compliance with the License. You may obtain a copy of the License at 7 | # 8 | # https://opensource.org/licenses/BSD-3-Clause 9 | # 10 | # Unless required by applicable law or agreed to in writing, software distributed 11 | # under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 12 | # CONDITIONS OF ANY KIND, either express or implied. See the License for the 13 | # specific language governing permissions and limitations under the License. 14 | # 15 | # Author: 16 | # 17 | 18 | find_package(Threads) 19 | find_package(OpenCV REQUIRED) 20 | 21 | include("${CMAKE_SOURCE_DIR}/cmake/ax620e.cmake") 22 | 23 | axera_example(ax_classification ax_classification_steps.cc) 24 | 25 | axera_example(ax_yolov5s ax_yolov5s_steps.cc) 26 | axera_example(ax_yolov5s_seg ax_yolov5s_seg_steps.cc) 27 | axera_example(ax_yolov5_face ax_yolov5_face_steps.cc) 28 | axera_example(ax_yolov6 ax_yolov6_steps.cc) 29 | axera_example(ax_yolov7_tiny_face ax_yolov7_tiny_face_steps.cc) 30 | axera_example(ax_yolov7 ax_yolov7_steps.cc) 31 | axera_example(ax_yolov8 ax_yolov8_steps.cc) 32 | axera_example(ax_yolov8_seg ax_yolov8_seg_steps.cc) 33 | axera_example(ax_yolov8_pose ax_yolov8_pose_steps.cc) 34 | axera_example(ax_yolov9 ax_yolov9_steps.cc) 35 | axera_example(ax_yolov9_u ax_yolov9_ultralytics_steps.cc) 36 | axera_example(ax_yolov10 ax_yolov10s_steps.cc) 37 | axera_example(ax_yolov10_u ax_yolov10_ultralytics_steps.cc) 38 | axera_example(ax_yolo11 ax_yolo11_steps.cc) 39 | axera_example(ax_yolo11_seg ax_yolo11_seg_steps.cc) 40 | axera_example(ax_yolo11_pose ax_yolo11_pose_steps.cc) 41 | axera_example(ax_yolox ax_yolox_steps.cc) 42 | axera_example(ax_yolo_world ax_yolo_world_steps.cc) 43 | axera_example(ax_yolo_world_open_vocabulary ax_yolo_world_open_vocabulary_steps.cc) 44 | 45 | axera_example(ax_scrfd ax_scrfd_steps.cc) 46 | axera_example(ax_simcc_pose ax_simcc_pose_steps.cc) 47 | axera_example(ax_crowdcount ax_crowdcount_steps.cc) 48 | axera_example(ax_rtdetr ax_rtdetr_steps.cc) 49 | axera_example(ax_depth_anything ax_depth_anything_steps.cc) 50 | 51 | axera_example(ax_imgproc ax_imgproc_steps.cc) 52 | axera_example(ax_model_info ax_model_info.cc) 53 | -------------------------------------------------------------------------------- /examples/ax620e/ax_classification_mmap_steps.cc: -------------------------------------------------------------------------------- 1 | /* 2 | * AXERA is pleased to support the open source community by making ax-samples available. 3 | * 4 | * Copyright (c) 2022, AXERA Semiconductor (Shanghai) Co., Ltd. All rights reserved. 5 | * 6 | * Licensed under the BSD 3-Clause License (the "License"); you may not use this file except 7 | * in compliance with the License. You may obtain a copy of the License at 8 | * 9 | * https://opensource.org/licenses/BSD-3-Clause 10 | * 11 | * Unless required by applicable law or agreed to in writing, software distributed 12 | * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 13 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the 14 | * specific language governing permissions and limitations under the License. 15 | */ 16 | 17 | /* 18 | * Author: ZHEQIUSHUI 19 | */ 20 | 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | 27 | #include 28 | #include "base/common.hpp" 29 | #include "middleware/io.hpp" 30 | 31 | #include "utilities/args.hpp" 32 | #include "utilities/cmdline.hpp" 33 | #include "utilities/file.hpp" 34 | #include "utilities/timer.hpp" 35 | 36 | #include 37 | #include 38 | 39 | #include "base/score.hpp" 40 | #include "base/topk.hpp" 41 | 42 | const int DEFAULT_IMG_H = 224; 43 | const int DEFAULT_IMG_W = 224; 44 | const int DEFAULT_LOOP_COUNT = 1; 45 | 46 | namespace ax 47 | { 48 | void post_process(AX_ENGINE_IO_INFO_T* io_info, AX_ENGINE_IO_T* io_data, const cv::Mat& mat, const std::vector& time_costs) 49 | { 50 | timer timer_postprocess; 51 | 52 | auto& output = io_data->pOutputs[0]; 53 | auto& info = io_info->pOutputs[0]; 54 | auto ptr = (float*)output.pVirAddr; 55 | auto class_num = info.nSize / sizeof(float); 56 | std::vector result(class_num); 57 | for (uint32_t id = 0; id < class_num; id++) 58 | { 59 | result[id].id = id; 60 | result[id].score = ptr[id]; 61 | } 62 | classification::sort_score(result); 63 | fprintf(stdout, "topk cost time:%.2f ms \n", timer_postprocess.cost()); 64 | classification::print_score(result, 5); 65 | 66 | fprintf(stdout, "--------------------------------------\n"); 67 | auto total_time = std::accumulate(time_costs.begin(), time_costs.end(), 0.f); 68 | auto min_max_time = std::minmax_element(time_costs.begin(), time_costs.end()); 69 | fprintf(stdout, 70 | "Repeat %d times, avg time %.2f ms, max_time %.2f ms, min_time %.2f ms\n", 71 | (int)time_costs.size(), 72 | total_time / (float)time_costs.size(), 73 | *min_max_time.second, 74 | *min_max_time.first); 75 | } 76 | 77 | bool run_model(const std::string& model, const std::vector& data, const int& repeat, cv::Mat& mat) 78 | { 79 | // 1. init engine 80 | AX_ENGINE_NPU_ATTR_T npu_attr; 81 | memset(&npu_attr, 0, sizeof(npu_attr)); 82 | npu_attr.eHardMode = AX_ENGINE_VIRTUAL_NPU_DISABLE; 83 | auto ret = AX_ENGINE_Init(&npu_attr); 84 | 85 | if (0 != ret) 86 | { 87 | return ret; 88 | } 89 | 90 | // 2. load model 91 | auto* file_fp = fopen(model.c_str(), "r"); 92 | if (!file_fp) 93 | { 94 | fprintf(stderr, "Read model(%s) file failed.\n", model.c_str()); 95 | return false; 96 | } 97 | fseek(file_fp, 0, SEEK_END); 98 | int model_size = ftell(file_fp); 99 | fclose(file_fp); 100 | int fd = open(model.c_str(), O_RDWR, 0644); 101 | void* mmap_add = mmap(NULL, model_size, PROT_WRITE, MAP_SHARED, fd, 0); 102 | 103 | // 3. create handle 104 | AX_ENGINE_HANDLE handle; 105 | ret = AX_ENGINE_CreateHandle(&handle, mmap_add, model_size); 106 | SAMPLE_AX_ENGINE_DEAL_HANDLE 107 | fprintf(stdout, "Engine creating handle is done.\n"); 108 | munmap(mmap_add, model_size); 109 | 110 | // 4. create context 111 | ret = AX_ENGINE_CreateContext(handle); 112 | SAMPLE_AX_ENGINE_DEAL_HANDLE 113 | fprintf(stdout, "Engine creating context is done.\n"); 114 | 115 | // 5. set io 116 | AX_ENGINE_IO_INFO_T* io_info; 117 | ret = AX_ENGINE_GetIOInfo(handle, &io_info); 118 | SAMPLE_AX_ENGINE_DEAL_HANDLE 119 | fprintf(stdout, "Engine get io info is done. \n"); 120 | 121 | // 6. alloc io 122 | AX_ENGINE_IO_T io_data; 123 | ret = middleware::prepare_io(io_info, &io_data, std::make_pair(AX_ENGINE_ABST_DEFAULT, AX_ENGINE_ABST_CACHED)); 124 | SAMPLE_AX_ENGINE_DEAL_HANDLE 125 | fprintf(stdout, "Engine alloc io is done. \n"); 126 | 127 | // 7. insert input 128 | ret = middleware::push_input(data, &io_data, io_info); 129 | SAMPLE_AX_ENGINE_DEAL_HANDLE_IO 130 | fprintf(stdout, "Engine push input is done. \n"); 131 | fprintf(stdout, "--------------------------------------\n"); 132 | 133 | // 8. warn up 134 | for (int i = 0; i < 5; ++i) 135 | { 136 | AX_ENGINE_RunSync(handle, &io_data); 137 | } 138 | 139 | // 9. run model 140 | std::vector time_costs(repeat, 0); 141 | for (int i = 0; i < repeat; ++i) 142 | { 143 | timer tick; 144 | ret = AX_ENGINE_RunSync(handle, &io_data); 145 | time_costs[i] = tick.cost(); 146 | SAMPLE_AX_ENGINE_DEAL_HANDLE_IO 147 | } 148 | 149 | // 10. get result 150 | post_process(io_info, &io_data, mat, time_costs); 151 | fprintf(stdout, "--------------------------------------\n"); 152 | 153 | middleware::free_io(&io_data); 154 | return AX_ENGINE_DestroyHandle(handle); 155 | } 156 | } // namespace ax 157 | 158 | int main(int argc, char* argv[]) 159 | { 160 | cmdline::parser cmd; 161 | cmd.add("model", 'm', "joint file(a.k.a. joint model)", true, ""); 162 | cmd.add("image", 'i', "image file", true, ""); 163 | cmd.add("size", 'g', "input_h, input_w", false, std::to_string(DEFAULT_IMG_H) + "," + std::to_string(DEFAULT_IMG_W)); 164 | 165 | cmd.add("repeat", 'r', "repeat count", false, DEFAULT_LOOP_COUNT); 166 | cmd.parse_check(argc, argv); 167 | 168 | // 0. get app args, can be removed from user's app 169 | auto model_file = cmd.get("model"); 170 | auto image_file = cmd.get("image"); 171 | 172 | auto model_file_flag = utilities::file_exist(model_file); 173 | auto image_file_flag = utilities::file_exist(image_file); 174 | 175 | if (!model_file_flag | !image_file_flag) 176 | { 177 | auto show_error = [](const std::string& kind, const std::string& value) { 178 | fprintf(stderr, "Input file %s(%s) is not exist, please check it.\n", kind.c_str(), value.c_str()); 179 | }; 180 | 181 | if (!model_file_flag) { show_error("model", model_file); } 182 | if (!image_file_flag) { show_error("image", image_file); } 183 | 184 | return -1; 185 | } 186 | 187 | auto input_size_string = cmd.get("size"); 188 | 189 | std::array input_size = {DEFAULT_IMG_H, DEFAULT_IMG_W}; 190 | 191 | auto input_size_flag = utilities::parse_string(input_size_string, input_size); 192 | 193 | if (!input_size_flag) 194 | { 195 | auto show_error = [](const std::string& kind, const std::string& value) { 196 | fprintf(stderr, "Input %s(%s) is not allowed, please check it.\n", kind.c_str(), value.c_str()); 197 | }; 198 | 199 | show_error("size", input_size_string); 200 | 201 | return -1; 202 | } 203 | 204 | auto repeat = cmd.get("repeat"); 205 | 206 | // 1. print args 207 | fprintf(stdout, "--------------------------------------\n"); 208 | fprintf(stdout, "model file : %s\n", model_file.c_str()); 209 | fprintf(stdout, "image file : %s\n", image_file.c_str()); 210 | fprintf(stdout, "img_h, img_w : %d %d\n", input_size[0], input_size[1]); 211 | fprintf(stdout, "--------------------------------------\n"); 212 | 213 | // 2. read image & resize & transpose 214 | std::vector image(input_size[0] * input_size[1] * 3, 0); 215 | cv::Mat mat = cv::imread(image_file); 216 | if (mat.empty()) 217 | { 218 | fprintf(stderr, "Read image failed.\n"); 219 | return -1; 220 | } 221 | common::get_input_data_centercrop(mat, image, input_size[0], input_size[1]); 222 | 223 | // 3. sys_init 224 | AX_SYS_Init(); 225 | 226 | // 4. - engine model - can only use AX_ENGINE** inside 227 | { 228 | // AX_ENGINE_NPUReset(); // todo ?? 229 | ax::run_model(model_file, image, repeat, mat); 230 | 231 | // 4.3 engine de init 232 | AX_ENGINE_Deinit(); 233 | // AX_ENGINE_NPUReset(); 234 | } 235 | // 4. - engine model - 236 | 237 | AX_SYS_Deinit(); 238 | return 0; 239 | } 240 | -------------------------------------------------------------------------------- /examples/ax620e/ax_classification_steps.cc: -------------------------------------------------------------------------------- 1 | /* 2 | * AXERA is pleased to support the open source community by making ax-samples available. 3 | * 4 | * Copyright (c) 2022, AXERA Semiconductor (Shanghai) Co., Ltd. All rights reserved. 5 | * 6 | * Licensed under the BSD 3-Clause License (the "License"); you may not use this file except 7 | * in compliance with the License. You may obtain a copy of the License at 8 | * 9 | * https://opensource.org/licenses/BSD-3-Clause 10 | * 11 | * Unless required by applicable law or agreed to in writing, software distributed 12 | * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 13 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the 14 | * specific language governing permissions and limitations under the License. 15 | */ 16 | 17 | /* 18 | * Author: ZHEQIUSHUI 19 | */ 20 | 21 | #include 22 | #include 23 | #include 24 | 25 | #include 26 | #include "base/common.hpp" 27 | #include "middleware/io.hpp" 28 | 29 | #include "utilities/args.hpp" 30 | #include "utilities/cmdline.hpp" 31 | #include "utilities/file.hpp" 32 | #include "utilities/timer.hpp" 33 | 34 | #include 35 | #include 36 | 37 | #include "base/score.hpp" 38 | #include "base/topk.hpp" 39 | 40 | const int DEFAULT_IMG_H = 224; 41 | const int DEFAULT_IMG_W = 224; 42 | const int DEFAULT_LOOP_COUNT = 1; 43 | 44 | namespace ax 45 | { 46 | void post_process(AX_ENGINE_IO_INFO_T* io_info, AX_ENGINE_IO_T* io_data, const cv::Mat& mat, const std::vector& time_costs) 47 | { 48 | timer timer_postprocess; 49 | 50 | auto& output = io_data->pOutputs[0]; 51 | auto& info = io_info->pOutputs[0]; 52 | auto ptr = (float*)output.pVirAddr; 53 | auto class_num = info.nSize / sizeof(float); 54 | std::vector result(class_num); 55 | for (uint32_t id = 0; id < class_num; id++) 56 | { 57 | result[id].id = id; 58 | result[id].score = ptr[id]; 59 | } 60 | classification::sort_score(result); 61 | fprintf(stdout, "topk cost time:%.2f ms \n", timer_postprocess.cost()); 62 | classification::print_score(result, 5); 63 | 64 | fprintf(stdout, "--------------------------------------\n"); 65 | auto total_time = std::accumulate(time_costs.begin(), time_costs.end(), 0.f); 66 | auto min_max_time = std::minmax_element(time_costs.begin(), time_costs.end()); 67 | fprintf(stdout, 68 | "Repeat %d times, avg time %.2f ms, max_time %.2f ms, min_time %.2f ms\n", 69 | (int)time_costs.size(), 70 | total_time / (float)time_costs.size(), 71 | *min_max_time.second, 72 | *min_max_time.first); 73 | } 74 | 75 | bool run_model(const std::string& model, const std::vector& data, const int& repeat, cv::Mat& mat) 76 | { 77 | // 1. init engine 78 | AX_ENGINE_NPU_ATTR_T npu_attr; 79 | memset(&npu_attr, 0, sizeof(npu_attr)); 80 | npu_attr.eHardMode = AX_ENGINE_VIRTUAL_NPU_DISABLE; 81 | auto ret = AX_ENGINE_Init(&npu_attr); 82 | 83 | if (0 != ret) 84 | { 85 | return ret; 86 | } 87 | 88 | // 2. load model 89 | std::vector model_buffer; 90 | if (!utilities::read_file(model, model_buffer)) 91 | { 92 | fprintf(stderr, "Read Run-Joint model(%s) file failed.\n", model.c_str()); 93 | return false; 94 | } 95 | 96 | // 3. create handle 97 | AX_ENGINE_HANDLE handle; 98 | ret = AX_ENGINE_CreateHandle(&handle, model_buffer.data(), model_buffer.size()); 99 | SAMPLE_AX_ENGINE_DEAL_HANDLE 100 | fprintf(stdout, "Engine creating handle is done.\n"); 101 | 102 | // 4. create context 103 | ret = AX_ENGINE_CreateContext(handle); 104 | SAMPLE_AX_ENGINE_DEAL_HANDLE 105 | fprintf(stdout, "Engine creating context is done.\n"); 106 | 107 | // 5. set io 108 | AX_ENGINE_IO_INFO_T* io_info; 109 | ret = AX_ENGINE_GetIOInfo(handle, &io_info); 110 | SAMPLE_AX_ENGINE_DEAL_HANDLE 111 | fprintf(stdout, "Engine get io info is done. \n"); 112 | 113 | // 6. alloc io 114 | AX_ENGINE_IO_T io_data; 115 | ret = middleware::prepare_io(io_info, &io_data, std::make_pair(AX_ENGINE_ABST_DEFAULT, AX_ENGINE_ABST_CACHED)); 116 | SAMPLE_AX_ENGINE_DEAL_HANDLE 117 | fprintf(stdout, "Engine alloc io is done. \n"); 118 | 119 | // 7. insert input 120 | ret = middleware::push_input(data, &io_data, io_info); 121 | SAMPLE_AX_ENGINE_DEAL_HANDLE_IO 122 | fprintf(stdout, "Engine push input is done. \n"); 123 | fprintf(stdout, "--------------------------------------\n"); 124 | 125 | // 8. warn up 126 | for (int i = 0; i < 5; ++i) 127 | { 128 | AX_ENGINE_RunSync(handle, &io_data); 129 | } 130 | 131 | // 9. run model 132 | std::vector time_costs(repeat, 0); 133 | for (int i = 0; i < repeat; ++i) 134 | { 135 | timer tick; 136 | ret = AX_ENGINE_RunSync(handle, &io_data); 137 | time_costs[i] = tick.cost(); 138 | SAMPLE_AX_ENGINE_DEAL_HANDLE_IO 139 | } 140 | 141 | // 10. get result 142 | post_process(io_info, &io_data, mat, time_costs); 143 | fprintf(stdout, "--------------------------------------\n"); 144 | 145 | middleware::free_io(&io_data); 146 | return AX_ENGINE_DestroyHandle(handle); 147 | } 148 | } // namespace ax 149 | 150 | int main(int argc, char* argv[]) 151 | { 152 | cmdline::parser cmd; 153 | cmd.add("model", 'm', "joint file(a.k.a. joint model)", true, ""); 154 | cmd.add("image", 'i', "image file", true, ""); 155 | cmd.add("size", 'g', "input_h, input_w", false, std::to_string(DEFAULT_IMG_H) + "," + std::to_string(DEFAULT_IMG_W)); 156 | 157 | cmd.add("repeat", 'r', "repeat count", false, DEFAULT_LOOP_COUNT); 158 | cmd.parse_check(argc, argv); 159 | 160 | // 0. get app args, can be removed from user's app 161 | auto model_file = cmd.get("model"); 162 | auto image_file = cmd.get("image"); 163 | 164 | auto model_file_flag = utilities::file_exist(model_file); 165 | auto image_file_flag = utilities::file_exist(image_file); 166 | 167 | if (!model_file_flag | !image_file_flag) 168 | { 169 | auto show_error = [](const std::string& kind, const std::string& value) { 170 | fprintf(stderr, "Input file %s(%s) is not exist, please check it.\n", kind.c_str(), value.c_str()); 171 | }; 172 | 173 | if (!model_file_flag) { show_error("model", model_file); } 174 | if (!image_file_flag) { show_error("image", image_file); } 175 | 176 | return -1; 177 | } 178 | 179 | auto input_size_string = cmd.get("size"); 180 | 181 | std::array input_size = {DEFAULT_IMG_H, DEFAULT_IMG_W}; 182 | 183 | auto input_size_flag = utilities::parse_string(input_size_string, input_size); 184 | 185 | if (!input_size_flag) 186 | { 187 | auto show_error = [](const std::string& kind, const std::string& value) { 188 | fprintf(stderr, "Input %s(%s) is not allowed, please check it.\n", kind.c_str(), value.c_str()); 189 | }; 190 | 191 | show_error("size", input_size_string); 192 | 193 | return -1; 194 | } 195 | 196 | auto repeat = cmd.get("repeat"); 197 | 198 | // 1. print args 199 | fprintf(stdout, "--------------------------------------\n"); 200 | fprintf(stdout, "model file : %s\n", model_file.c_str()); 201 | fprintf(stdout, "image file : %s\n", image_file.c_str()); 202 | fprintf(stdout, "img_h, img_w : %d %d\n", input_size[0], input_size[1]); 203 | fprintf(stdout, "--------------------------------------\n"); 204 | 205 | // 2. read image & resize & transpose 206 | std::vector image(input_size[0] * input_size[1] * 3, 0); 207 | cv::Mat mat = cv::imread(image_file); 208 | if (mat.empty()) 209 | { 210 | fprintf(stderr, "Read image failed.\n"); 211 | return -1; 212 | } 213 | common::get_input_data_centercrop(mat, image, input_size[0], input_size[1]); 214 | 215 | // 3. sys_init 216 | AX_SYS_Init(); 217 | 218 | // 4. - engine model - can only use AX_ENGINE** inside 219 | { 220 | // AX_ENGINE_NPUReset(); // todo ?? 221 | ax::run_model(model_file, image, repeat, mat); 222 | 223 | // 4.3 engine de init 224 | AX_ENGINE_Deinit(); 225 | // AX_ENGINE_NPUReset(); 226 | } 227 | // 4. - engine model - 228 | 229 | AX_SYS_Deinit(); 230 | return 0; 231 | } 232 | -------------------------------------------------------------------------------- /examples/ax620e/ax_depth_anything_steps.cc: -------------------------------------------------------------------------------- 1 | /* 2 | * AXERA is pleased to support the open source community by making ax-samples available. 3 | * 4 | * Copyright (c) 2022, AXERA Semiconductor (Shanghai) Co., Ltd. All rights reserved. 5 | * 6 | * Licensed under the BSD 3-Clause License (the "License"); you may not use this file except 7 | * in compliance with the License. You may obtain a copy of the License at 8 | * 9 | * https://opensource.org/licenses/BSD-3-Clause 10 | * 11 | * Unless required by applicable law or agreed to in writing, software distributed 12 | * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 13 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the 14 | * specific language governing permissions and limitations under the License. 15 | */ 16 | 17 | /* 18 | * Author: ZHEQIUSHUI 19 | */ 20 | 21 | #include 22 | #include 23 | #include 24 | 25 | #include 26 | #include "base/common.hpp" 27 | #include "base/detection.hpp" 28 | #include "middleware/io.hpp" 29 | 30 | #include "utilities/args.hpp" 31 | #include "utilities/cmdline.hpp" 32 | #include "utilities/file.hpp" 33 | #include "utilities/timer.hpp" 34 | 35 | #include 36 | #include 37 | 38 | const int DEFAULT_IMG_H = 256; 39 | const int DEFAULT_IMG_W = 384; 40 | 41 | const int DEFAULT_LOOP_COUNT = 1; 42 | 43 | namespace ax 44 | { 45 | void post_process(AX_ENGINE_IO_INFO_T* io_info, AX_ENGINE_IO_T* io_data, const cv::Mat& mat, int input_w, int input_h, const std::vector& time_costs) 46 | { 47 | timer timer_postprocess; 48 | auto& output = io_data->pOutputs[0]; 49 | auto& info = io_info->pOutputs[0]; 50 | 51 | cv::Mat feature(info.pShape[2], info.pShape[3], CV_32FC1, output.pVirAddr); 52 | 53 | double minVal, maxVal; 54 | cv::minMaxLoc(feature, &minVal, &maxVal); 55 | 56 | feature -= minVal; 57 | feature /= (maxVal - minVal); 58 | // feature = 1.f - feature; 59 | feature *= 255; 60 | 61 | feature.convertTo(feature, CV_8UC1); 62 | 63 | cv::Mat dst(info.pShape[2], info.pShape[3], CV_8UC3); 64 | cv::applyColorMap(feature, dst, cv::ColormapTypes::COLORMAP_MAGMA); 65 | cv::resize(dst, dst, cv::Size(mat.cols, mat.rows)); 66 | 67 | fprintf(stdout, "post process cost time:%.2f ms \n", timer_postprocess.cost()); 68 | fprintf(stdout, "--------------------------------------\n"); 69 | auto total_time = std::accumulate(time_costs.begin(), time_costs.end(), 0.f); 70 | auto min_max_time = std::minmax_element(time_costs.begin(), time_costs.end()); 71 | fprintf(stdout, 72 | "Repeat %d times, avg time %.2f ms, max_time %.2f ms, min_time %.2f ms\n", 73 | (int)time_costs.size(), 74 | total_time / (float)time_costs.size(), 75 | *min_max_time.second, 76 | *min_max_time.first); 77 | fprintf(stdout, "--------------------------------------\n"); 78 | cv::hconcat(std::vector{mat, dst}, dst); 79 | cv::imwrite("depth_anything_out.png", dst); 80 | } 81 | 82 | bool run_model(const std::string& model, const std::vector& data, const int& repeat, cv::Mat& mat, int input_h, int input_w) 83 | { 84 | // 1. init engine 85 | AX_ENGINE_NPU_ATTR_T npu_attr; 86 | memset(&npu_attr, 0, sizeof(npu_attr)); 87 | npu_attr.eHardMode = AX_ENGINE_VIRTUAL_NPU_DISABLE; 88 | auto ret = AX_ENGINE_Init(&npu_attr); 89 | 90 | if (0 != ret) 91 | { 92 | return ret; 93 | } 94 | 95 | // 2. load model 96 | std::vector model_buffer; 97 | if (!utilities::read_file(model, model_buffer)) 98 | { 99 | fprintf(stderr, "Read Run-Joint model(%s) file failed.\n", model.c_str()); 100 | return false; 101 | } 102 | 103 | // 3. create handle 104 | AX_ENGINE_HANDLE handle; 105 | ret = AX_ENGINE_CreateHandle(&handle, model_buffer.data(), model_buffer.size()); 106 | SAMPLE_AX_ENGINE_DEAL_HANDLE 107 | fprintf(stdout, "Engine creating handle is done.\n"); 108 | 109 | // 4. create context 110 | ret = AX_ENGINE_CreateContext(handle); 111 | SAMPLE_AX_ENGINE_DEAL_HANDLE 112 | fprintf(stdout, "Engine creating context is done.\n"); 113 | 114 | // 5. set io 115 | AX_ENGINE_IO_INFO_T* io_info; 116 | ret = AX_ENGINE_GetIOInfo(handle, &io_info); 117 | SAMPLE_AX_ENGINE_DEAL_HANDLE 118 | fprintf(stdout, "Engine get io info is done. \n"); 119 | 120 | // 6. alloc io 121 | AX_ENGINE_IO_T io_data; 122 | ret = middleware::prepare_io(io_info, &io_data, std::make_pair(AX_ENGINE_ABST_DEFAULT, AX_ENGINE_ABST_CACHED)); 123 | SAMPLE_AX_ENGINE_DEAL_HANDLE 124 | fprintf(stdout, "Engine alloc io is done. \n"); 125 | 126 | // 7. insert input 127 | ret = middleware::push_input(data, &io_data, io_info); 128 | SAMPLE_AX_ENGINE_DEAL_HANDLE_IO 129 | fprintf(stdout, "Engine push input is done. \n"); 130 | fprintf(stdout, "--------------------------------------\n"); 131 | 132 | // 8. warn up 133 | for (int i = 0; i < 5; ++i) 134 | { 135 | AX_ENGINE_RunSync(handle, &io_data); 136 | } 137 | 138 | // 9. run model 139 | std::vector time_costs(repeat, 0); 140 | for (int i = 0; i < repeat; ++i) 141 | { 142 | timer tick; 143 | ret = AX_ENGINE_RunSync(handle, &io_data); 144 | time_costs[i] = tick.cost(); 145 | SAMPLE_AX_ENGINE_DEAL_HANDLE_IO 146 | } 147 | 148 | // 10. get result 149 | post_process(io_info, &io_data, mat, input_w, input_h, time_costs); 150 | fprintf(stdout, "--------------------------------------\n"); 151 | 152 | middleware::free_io(&io_data); 153 | return AX_ENGINE_DestroyHandle(handle); 154 | } 155 | } // namespace ax 156 | 157 | int main(int argc, char* argv[]) 158 | { 159 | cmdline::parser cmd; 160 | cmd.add("model", 'm', "joint file(a.k.a. joint model)", true, ""); 161 | cmd.add("image", 'i', "image file", true, ""); 162 | cmd.add("size", 'g', "input_h, input_w", false, std::to_string(DEFAULT_IMG_H) + "," + std::to_string(DEFAULT_IMG_W)); 163 | 164 | cmd.add("repeat", 'r', "repeat count", false, DEFAULT_LOOP_COUNT); 165 | cmd.parse_check(argc, argv); 166 | 167 | // 0. get app args, can be removed from user's app 168 | auto model_file = cmd.get("model"); 169 | auto image_file = cmd.get("image"); 170 | 171 | auto model_file_flag = utilities::file_exist(model_file); 172 | auto image_file_flag = utilities::file_exist(image_file); 173 | 174 | if (!model_file_flag | !image_file_flag) 175 | { 176 | auto show_error = [](const std::string& kind, const std::string& value) { 177 | fprintf(stderr, "Input file %s(%s) is not exist, please check it.\n", kind.c_str(), value.c_str()); 178 | }; 179 | 180 | if (!model_file_flag) { show_error("model", model_file); } 181 | if (!image_file_flag) { show_error("image", image_file); } 182 | 183 | return -1; 184 | } 185 | 186 | auto input_size_string = cmd.get("size"); 187 | 188 | std::array input_size = {DEFAULT_IMG_H, DEFAULT_IMG_W}; 189 | 190 | auto input_size_flag = utilities::parse_string(input_size_string, input_size); 191 | 192 | if (!input_size_flag) 193 | { 194 | auto show_error = [](const std::string& kind, const std::string& value) { 195 | fprintf(stderr, "Input %s(%s) is not allowed, please check it.\n", kind.c_str(), value.c_str()); 196 | }; 197 | 198 | show_error("size", input_size_string); 199 | 200 | return -1; 201 | } 202 | 203 | auto repeat = cmd.get("repeat"); 204 | 205 | // 1. print args 206 | fprintf(stdout, "--------------------------------------\n"); 207 | fprintf(stdout, "model file : %s\n", model_file.c_str()); 208 | fprintf(stdout, "image file : %s\n", image_file.c_str()); 209 | fprintf(stdout, "img_h, img_w : %d %d\n", input_size[0], input_size[1]); 210 | fprintf(stdout, "--------------------------------------\n"); 211 | 212 | // 2. read image & resize & transpose 213 | std::vector image(input_size[0] * input_size[1] * 3, 0); 214 | cv::Mat mat = cv::imread(image_file); 215 | if (mat.empty()) 216 | { 217 | fprintf(stderr, "Read image failed.\n"); 218 | return -1; 219 | } 220 | common::get_input_data_no_letterbox(mat, image, input_size[0], input_size[1], true); 221 | 222 | // 3. sys_init 223 | AX_SYS_Init(); 224 | 225 | // 4. - engine model - can only use AX_ENGINE** inside 226 | { 227 | // AX_ENGINE_NPUReset(); // todo ?? 228 | ax::run_model(model_file, image, repeat, mat, input_size[0], input_size[1]); 229 | 230 | // 4.3 engine de init 231 | AX_ENGINE_Deinit(); 232 | // AX_ENGINE_NPUReset(); 233 | } 234 | // 4. - engine model - 235 | 236 | AX_SYS_Deinit(); 237 | return 0; 238 | } 239 | -------------------------------------------------------------------------------- /examples/ax620e/ax_model_info.cc: -------------------------------------------------------------------------------- 1 | /* 2 | * AXERA is pleased to support the open source community by making ax-samples available. 3 | * 4 | * Copyright (c) 2022, AXERA Semiconductor (Shanghai) Co., Ltd. All rights reserved. 5 | * 6 | * Licensed under the BSD 3-Clause License (the "License"); you may not use this file except 7 | * in compliance with the License. You may obtain a copy of the License at 8 | * 9 | * https://opensource.org/licenses/BSD-3-Clause 10 | * 11 | * Unless required by applicable law or agreed to in writing, software distributed 12 | * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 13 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the 14 | * specific language governing permissions and limitations under the License. 15 | */ 16 | 17 | /* 18 | * Author: ZHEQIUSHUI 19 | */ 20 | 21 | #include 22 | #include 23 | #include 24 | 25 | #include 26 | #include "base/common.hpp" 27 | #include "middleware/io.hpp" 28 | 29 | #include "utilities/args.hpp" 30 | #include "utilities/cmdline.hpp" 31 | #include "utilities/file.hpp" 32 | #include "utilities/timer.hpp" 33 | 34 | #include 35 | #include 36 | 37 | #include "base/score.hpp" 38 | #include "base/topk.hpp" 39 | 40 | namespace ax 41 | { 42 | bool run_model(const std::string& model) 43 | { 44 | // 1. init engine 45 | AX_ENGINE_NPU_ATTR_T npu_attr; 46 | memset(&npu_attr, 0, sizeof(npu_attr)); 47 | npu_attr.eHardMode = AX_ENGINE_VIRTUAL_NPU_DISABLE; 48 | auto ret = AX_ENGINE_Init(&npu_attr); 49 | 50 | if (0 != ret) 51 | { 52 | return ret; 53 | } 54 | 55 | // 2. load model 56 | std::vector model_buffer; 57 | if (!utilities::read_file(model, model_buffer)) 58 | { 59 | fprintf(stderr, "Read Run-Joint model(%s) file failed.\n", model.c_str()); 60 | return false; 61 | } 62 | 63 | // 3. create handle 64 | AX_ENGINE_HANDLE handle; 65 | ret = AX_ENGINE_CreateHandle(&handle, model_buffer.data(), model_buffer.size()); 66 | SAMPLE_AX_ENGINE_DEAL_HANDLE 67 | fprintf(stdout, "Engine creating handle is done.\n"); 68 | 69 | // 4. create context 70 | ret = AX_ENGINE_CreateContext(handle); 71 | SAMPLE_AX_ENGINE_DEAL_HANDLE 72 | fprintf(stdout, "Engine creating context is done.\n"); 73 | 74 | // 5. set io 75 | AX_ENGINE_IO_INFO_T* io_info; 76 | ret = AX_ENGINE_GetIOInfo(handle, &io_info); 77 | SAMPLE_AX_ENGINE_DEAL_HANDLE 78 | fprintf(stdout, "Engine get io info is done. \n"); 79 | 80 | // 6. printf io 81 | middleware::print_io_info(io_info); 82 | 83 | return AX_ENGINE_DestroyHandle(handle); 84 | } 85 | } // namespace ax 86 | 87 | int main(int argc, char* argv[]) 88 | { 89 | cmdline::parser cmd; 90 | cmd.add("model", 'm', "joint file(a.k.a. joint model)", true, ""); 91 | cmd.parse_check(argc, argv); 92 | 93 | // 0. get app args, can be removed from user's app 94 | auto model_file = cmd.get("model"); 95 | 96 | auto model_file_flag = utilities::file_exist(model_file); 97 | 98 | if (!model_file_flag) 99 | { 100 | auto show_error = [](const std::string& kind, const std::string& value) { 101 | fprintf(stderr, "Input file %s(%s) is not exist, please check it.\n", kind.c_str(), value.c_str()); 102 | }; 103 | 104 | if (!model_file_flag) { show_error("model", model_file); } 105 | 106 | return -1; 107 | } 108 | 109 | // 1. print args 110 | fprintf(stdout, "--------------------------------------\n"); 111 | fprintf(stdout, "model file : %s\n", model_file.c_str()); 112 | fprintf(stdout, "--------------------------------------\n"); 113 | 114 | // 3. sys_init 115 | AX_SYS_Init(); 116 | 117 | // 4. - engine model - can only use AX_ENGINE** inside 118 | { 119 | // AX_ENGINE_NPUReset(); // todo ?? 120 | ax::run_model(model_file); 121 | 122 | // 4.3 engine de init 123 | AX_ENGINE_Deinit(); 124 | // AX_ENGINE_NPUReset(); 125 | } 126 | // 4. - engine model - 127 | 128 | AX_SYS_Deinit(); 129 | return 0; 130 | } 131 | -------------------------------------------------------------------------------- /examples/ax650/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # AXERA is pleased to support the open source community by making ax-samples available. 2 | # 3 | # Copyright (c) 2022, AXERA Semiconductor (Shanghai) Co., Ltd. All rights reserved. 4 | # 5 | # Licensed under the BSD 3-Clause License (the "License"); you may not use this file except 6 | # in compliance with the License. You may obtain a copy of the License at 7 | # 8 | # https://opensource.org/licenses/BSD-3-Clause 9 | # 10 | # Unless required by applicable law or agreed to in writing, software distributed 11 | # under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 12 | # CONDITIONS OF ANY KIND, either express or implied. See the License for the 13 | # specific language governing permissions and limitations under the License. 14 | # 15 | # Author: 16 | # 17 | 18 | find_package(Threads) 19 | find_package(OpenCV REQUIRED) 20 | 21 | include("${CMAKE_SOURCE_DIR}/cmake/ax650.cmake") 22 | 23 | axera_example(ax_classification ax_classification_steps.cc) 24 | 25 | axera_example(ax_yolov5s ax_yolov5s_steps.cc) 26 | axera_example(ax_yolov5s_dynamic_batchsize ax_yolov5s_dynamic_batchsize_steps.cc) 27 | axera_example(ax_yolov5s_seg ax_yolov5s_seg_steps.cc) 28 | axera_example(ax_yolov5_face ax_yolov5_face_steps.cc) 29 | axera_example(ax_yolov6 ax_yolov6_steps.cc) 30 | axera_example(ax_yolov7_tiny_face ax_yolov7_tiny_face_steps.cc) 31 | axera_example(ax_yolov7 ax_yolov7_steps.cc) 32 | axera_example(ax_yolov8 ax_yolov8_steps.cc) 33 | axera_example(ax_yolov8_nv12 ax_yolov8_nv12_steps.cc) 34 | axera_example(ax_yolov8_seg ax_yolov8_seg_steps.cc) 35 | axera_example(ax_yolov8_pose ax_yolov8_pose_steps.cc) 36 | axera_example(ax_yolov8_obb ax_yolov8_obb_steps.cc) 37 | axera_example(ax_yolov9 ax_yolov9_steps.cc) 38 | axera_example(ax_yolov9_u ax_yolov9_ultralytics_steps.cc) 39 | axera_example(ax_yolox ax_yolox_steps.cc) 40 | axera_example(ax_yolov10 ax_yolov10s_steps.cc) 41 | axera_example(ax_yolov10_u ax_yolov10_ultralytics_steps.cc) 42 | axera_example(ax_yolo11 ax_yolo11_steps.cc) 43 | axera_example(ax_yolo11_seg ax_yolo11_seg_steps.cc) 44 | axera_example(ax_yolo11_pose ax_yolo11_pose_steps.cc) 45 | axera_example(ax_yolo_nas ax_yolo_nas_steps.cc) 46 | axera_example(ax_yolo_world ax_yolo_world_steps.cc) 47 | axera_example(ax_yolo_world_open_vocabulary ax_yolo_world_open_vocabulary_steps.cc) 48 | 49 | axera_example(ax_ppyoloe ax_ppyoloe_steps.cc) 50 | axera_example(ax_ppyoloe_obj365 ax_ppyoloe_obj365_steps.cc) 51 | axera_example(ax_pp_person_attribute ax_pp_person_attribute_steps.cc) 52 | axera_example(ax_pp_vehicle_attribute ax_pp_vehicle_attribute_steps.cc) 53 | axera_example(ax_pp_humanseg ax_pp_humanseg_steps.cc) 54 | axera_example(ax_pp_liteseg_stdc2_cityscapes ax_pp_liteseg_stdc2_cityscapes_steps.cc) 55 | axera_example(ax_pp_ocr_rec ax_pp_ocr_rec_steps.cc) 56 | 57 | axera_example(ax_realesrgan ax_realesrgan_steps.cc) 58 | axera_example(ax_detr ax_detr_steps.cc) 59 | axera_example(ax_hrnet ax_hrnet_steps.cc) 60 | axera_example(ax_scrfd ax_scrfd_steps.cc) 61 | axera_example(ax_segformer ax_segformer_steps.cc) 62 | axera_example(ax_rtmdet ax_rtmdet_steps.cc) 63 | axera_example(ax_pfld ax_pfld_steps.cc) 64 | axera_example(ax_dinov2 ax_dinov2_steps.cc) 65 | axera_example(ax_simcc_pose ax_simcc_pose_steps.cc) 66 | axera_example(ax_glpdepth ax_glpdepth_steps.cc) 67 | axera_example(ax_depth_anything ax_depth_anything_steps.cc) 68 | axera_example(ax_rtdetr ax_rtdetr_steps.cc) 69 | axera_example(ax_crowdcount ax_crowdcount_steps.cc) 70 | 71 | axera_example(ax_imgproc ax_imgproc_steps.cc) 72 | axera_example(ax_model_info ax_model_info.cc) 73 | 74 | -------------------------------------------------------------------------------- /examples/ax650/ax_classification_steps.cc: -------------------------------------------------------------------------------- 1 | /* 2 | * AXERA is pleased to support the open source community by making ax-samples available. 3 | * 4 | * Copyright (c) 2022, AXERA Semiconductor (Shanghai) Co., Ltd. All rights reserved. 5 | * 6 | * Licensed under the BSD 3-Clause License (the "License"); you may not use this file except 7 | * in compliance with the License. You may obtain a copy of the License at 8 | * 9 | * https://opensource.org/licenses/BSD-3-Clause 10 | * 11 | * Unless required by applicable law or agreed to in writing, software distributed 12 | * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 13 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the 14 | * specific language governing permissions and limitations under the License. 15 | */ 16 | 17 | /* 18 | * Author: ZHEQIUSHUI 19 | */ 20 | 21 | #include 22 | #include 23 | #include 24 | 25 | #include 26 | #include "base/common.hpp" 27 | #include "middleware/io.hpp" 28 | 29 | #include "utilities/args.hpp" 30 | #include "utilities/cmdline.hpp" 31 | #include "utilities/file.hpp" 32 | #include "utilities/timer.hpp" 33 | 34 | #include 35 | #include 36 | 37 | #include "base/score.hpp" 38 | #include "base/topk.hpp" 39 | 40 | const int DEFAULT_IMG_H = 224; 41 | const int DEFAULT_IMG_W = 224; 42 | const int DEFAULT_LOOP_COUNT = 1; 43 | 44 | namespace ax 45 | { 46 | void post_process(AX_ENGINE_IO_INFO_T* io_info, AX_ENGINE_IO_T* io_data, const cv::Mat& mat, const std::vector& time_costs) 47 | { 48 | timer timer_postprocess; 49 | 50 | auto& output = io_data->pOutputs[0]; 51 | auto& info = io_info->pOutputs[0]; 52 | auto ptr = (float*)output.pVirAddr; 53 | auto class_num = info.nSize / sizeof(float); 54 | std::vector result(class_num); 55 | for (uint32_t id = 0; id < class_num; id++) 56 | { 57 | result[id].id = id; 58 | result[id].score = ptr[id]; 59 | } 60 | classification::sort_score(result); 61 | fprintf(stdout, "topk cost time:%.2f ms \n", timer_postprocess.cost()); 62 | classification::print_score(result, 5); 63 | 64 | fprintf(stdout, "--------------------------------------\n"); 65 | auto total_time = std::accumulate(time_costs.begin(), time_costs.end(), 0.f); 66 | auto min_max_time = std::minmax_element(time_costs.begin(), time_costs.end()); 67 | fprintf(stdout, 68 | "Repeat %d times, avg time %.2f ms, max_time %.2f ms, min_time %.2f ms\n", 69 | (int)time_costs.size(), 70 | total_time / (float)time_costs.size(), 71 | *min_max_time.second, 72 | *min_max_time.first); 73 | } 74 | 75 | bool run_model(const std::string& model, const std::vector& data, const int& repeat, cv::Mat& mat) 76 | { 77 | // 1. init engine 78 | #ifdef AXERA_TARGET_CHIP_AX620E 79 | auto ret = AX_ENGINE_Init(); 80 | #else 81 | AX_ENGINE_NPU_ATTR_T npu_attr; 82 | memset(&npu_attr, 0, sizeof(npu_attr)); 83 | npu_attr.eHardMode = AX_ENGINE_VIRTUAL_NPU_DISABLE; 84 | auto ret = AX_ENGINE_Init(&npu_attr); 85 | #endif 86 | if (0 != ret) 87 | { 88 | return ret; 89 | } 90 | 91 | // 2. load model 92 | std::vector model_buffer; 93 | if (!utilities::read_file(model, model_buffer)) 94 | { 95 | fprintf(stderr, "Read Run-Joint model(%s) file failed.\n", model.c_str()); 96 | return false; 97 | } 98 | 99 | // 3. create handle 100 | AX_ENGINE_HANDLE handle; 101 | ret = AX_ENGINE_CreateHandle(&handle, model_buffer.data(), model_buffer.size()); 102 | SAMPLE_AX_ENGINE_DEAL_HANDLE 103 | fprintf(stdout, "Engine creating handle is done.\n"); 104 | 105 | // 4. create context 106 | ret = AX_ENGINE_CreateContext(handle); 107 | SAMPLE_AX_ENGINE_DEAL_HANDLE 108 | fprintf(stdout, "Engine creating context is done.\n"); 109 | 110 | // 5. set io 111 | AX_ENGINE_IO_INFO_T* io_info; 112 | ret = AX_ENGINE_GetIOInfo(handle, &io_info); 113 | SAMPLE_AX_ENGINE_DEAL_HANDLE 114 | fprintf(stdout, "Engine get io info is done. \n"); 115 | 116 | // 6. alloc io 117 | AX_ENGINE_IO_T io_data; 118 | ret = middleware::prepare_io(io_info, &io_data, std::make_pair(AX_ENGINE_ABST_DEFAULT, AX_ENGINE_ABST_CACHED)); 119 | SAMPLE_AX_ENGINE_DEAL_HANDLE 120 | fprintf(stdout, "Engine alloc io is done. \n"); 121 | 122 | // 7. insert input 123 | ret = middleware::push_input(data, &io_data, io_info); 124 | SAMPLE_AX_ENGINE_DEAL_HANDLE_IO 125 | fprintf(stdout, "Engine push input is done. \n"); 126 | fprintf(stdout, "--------------------------------------\n"); 127 | 128 | // 8. warn up 129 | for (int i = 0; i < 5; ++i) 130 | { 131 | AX_ENGINE_RunSync(handle, &io_data); 132 | } 133 | 134 | // 9. run model 135 | std::vector time_costs(repeat, 0); 136 | for (int i = 0; i < repeat; ++i) 137 | { 138 | timer tick; 139 | ret = AX_ENGINE_RunSync(handle, &io_data); 140 | time_costs[i] = tick.cost(); 141 | SAMPLE_AX_ENGINE_DEAL_HANDLE_IO 142 | } 143 | 144 | // 10. get result 145 | post_process(io_info, &io_data, mat, time_costs); 146 | fprintf(stdout, "--------------------------------------\n"); 147 | 148 | middleware::free_io(&io_data); 149 | return AX_ENGINE_DestroyHandle(handle); 150 | } 151 | } // namespace ax 152 | 153 | int main(int argc, char* argv[]) 154 | { 155 | cmdline::parser cmd; 156 | cmd.add("model", 'm', "joint file(a.k.a. joint model)", true, ""); 157 | cmd.add("image", 'i', "image file", true, ""); 158 | cmd.add("size", 'g', "input_h, input_w", false, std::to_string(DEFAULT_IMG_H) + "," + std::to_string(DEFAULT_IMG_W)); 159 | 160 | cmd.add("repeat", 'r', "repeat count", false, DEFAULT_LOOP_COUNT); 161 | cmd.parse_check(argc, argv); 162 | 163 | // 0. get app args, can be removed from user's app 164 | auto model_file = cmd.get("model"); 165 | auto image_file = cmd.get("image"); 166 | 167 | auto model_file_flag = utilities::file_exist(model_file); 168 | auto image_file_flag = utilities::file_exist(image_file); 169 | 170 | if (!model_file_flag | !image_file_flag) 171 | { 172 | auto show_error = [](const std::string& kind, const std::string& value) { 173 | fprintf(stderr, "Input file %s(%s) is not exist, please check it.\n", kind.c_str(), value.c_str()); 174 | }; 175 | 176 | if (!model_file_flag) { show_error("model", model_file); } 177 | if (!image_file_flag) { show_error("image", image_file); } 178 | 179 | return -1; 180 | } 181 | 182 | auto input_size_string = cmd.get("size"); 183 | 184 | std::array input_size = {DEFAULT_IMG_H, DEFAULT_IMG_W}; 185 | 186 | auto input_size_flag = utilities::parse_string(input_size_string, input_size); 187 | 188 | if (!input_size_flag) 189 | { 190 | auto show_error = [](const std::string& kind, const std::string& value) { 191 | fprintf(stderr, "Input %s(%s) is not allowed, please check it.\n", kind.c_str(), value.c_str()); 192 | }; 193 | 194 | show_error("size", input_size_string); 195 | 196 | return -1; 197 | } 198 | 199 | auto repeat = cmd.get("repeat"); 200 | 201 | // 1. print args 202 | fprintf(stdout, "--------------------------------------\n"); 203 | fprintf(stdout, "model file : %s\n", model_file.c_str()); 204 | fprintf(stdout, "image file : %s\n", image_file.c_str()); 205 | fprintf(stdout, "img_h, img_w : %d %d\n", input_size[0], input_size[1]); 206 | fprintf(stdout, "--------------------------------------\n"); 207 | 208 | // 2. read image & resize & transpose 209 | std::vector image(input_size[0] * input_size[1] * 3, 0); 210 | cv::Mat mat = cv::imread(image_file); 211 | if (mat.empty()) 212 | { 213 | fprintf(stderr, "Read image failed.\n"); 214 | return -1; 215 | } 216 | common::get_input_data_centercrop(mat, image, input_size[0], input_size[1]); 217 | 218 | // 3. sys_init 219 | AX_SYS_Init(); 220 | 221 | // 4. - engine model - can only use AX_ENGINE** inside 222 | { 223 | // AX_ENGINE_NPUReset(); // todo ?? 224 | ax::run_model(model_file, image, repeat, mat); 225 | 226 | // 4.3 engine de init 227 | AX_ENGINE_Deinit(); 228 | // AX_ENGINE_NPUReset(); 229 | } 230 | // 4. - engine model - 231 | 232 | AX_SYS_Deinit(); 233 | return 0; 234 | } 235 | -------------------------------------------------------------------------------- /examples/ax650/ax_depth_anything_steps.cc: -------------------------------------------------------------------------------- 1 | /* 2 | * AXERA is pleased to support the open source community by making ax-samples available. 3 | * 4 | * Copyright (c) 2022, AXERA Semiconductor (Shanghai) Co., Ltd. All rights reserved. 5 | * 6 | * Licensed under the BSD 3-Clause License (the "License"); you may not use this file except 7 | * in compliance with the License. You may obtain a copy of the License at 8 | * 9 | * https://opensource.org/licenses/BSD-3-Clause 10 | * 11 | * Unless required by applicable law or agreed to in writing, software distributed 12 | * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 13 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the 14 | * specific language governing permissions and limitations under the License. 15 | */ 16 | 17 | /* 18 | * Author: ZHEQIUSHUI 19 | */ 20 | 21 | #include 22 | #include 23 | #include 24 | 25 | #include 26 | #include "base/common.hpp" 27 | #include "base/detection.hpp" 28 | #include "middleware/io.hpp" 29 | 30 | #include "utilities/args.hpp" 31 | #include "utilities/cmdline.hpp" 32 | #include "utilities/file.hpp" 33 | #include "utilities/timer.hpp" 34 | 35 | #include 36 | #include 37 | 38 | const int DEFAULT_IMG_H = 384; 39 | const int DEFAULT_IMG_W = 640; 40 | 41 | const int DEFAULT_LOOP_COUNT = 1; 42 | 43 | namespace ax 44 | { 45 | void post_process(AX_ENGINE_IO_INFO_T* io_info, AX_ENGINE_IO_T* io_data, const cv::Mat& mat, int input_w, int input_h, const std::vector& time_costs) 46 | { 47 | timer timer_postprocess; 48 | auto& output = io_data->pOutputs[0]; 49 | auto& info = io_info->pOutputs[0]; 50 | 51 | cv::Mat feature(info.pShape[2], info.pShape[3], CV_32FC1, output.pVirAddr); 52 | 53 | double minVal, maxVal; 54 | cv::minMaxLoc(feature, &minVal, &maxVal); 55 | 56 | feature -= minVal; 57 | feature /= (maxVal - minVal); 58 | // feature = 1.f - feature; 59 | feature *= 255; 60 | 61 | feature.convertTo(feature, CV_8UC1); 62 | 63 | cv::Mat dst(info.pShape[2], info.pShape[3], CV_8UC3); 64 | cv::applyColorMap(feature, dst, cv::ColormapTypes::COLORMAP_MAGMA); 65 | cv::resize(dst, dst, cv::Size(mat.cols, mat.rows)); 66 | 67 | fprintf(stdout, "post process cost time:%.2f ms \n", timer_postprocess.cost()); 68 | fprintf(stdout, "--------------------------------------\n"); 69 | auto total_time = std::accumulate(time_costs.begin(), time_costs.end(), 0.f); 70 | auto min_max_time = std::minmax_element(time_costs.begin(), time_costs.end()); 71 | fprintf(stdout, 72 | "Repeat %d times, avg time %.2f ms, max_time %.2f ms, min_time %.2f ms\n", 73 | (int)time_costs.size(), 74 | total_time / (float)time_costs.size(), 75 | *min_max_time.second, 76 | *min_max_time.first); 77 | fprintf(stdout, "--------------------------------------\n"); 78 | cv::hconcat(std::vector{mat, dst}, dst); 79 | cv::imwrite("depth_anything_out.png", dst); 80 | } 81 | 82 | bool run_model(const std::string& model, const std::vector& data, const int& repeat, cv::Mat& mat, int input_h, int input_w) 83 | { 84 | // 1. init engine 85 | #ifdef AXERA_TARGET_CHIP_AX620E 86 | auto ret = AX_ENGINE_Init(); 87 | #else 88 | AX_ENGINE_NPU_ATTR_T npu_attr; 89 | memset(&npu_attr, 0, sizeof(npu_attr)); 90 | npu_attr.eHardMode = AX_ENGINE_VIRTUAL_NPU_DISABLE; 91 | auto ret = AX_ENGINE_Init(&npu_attr); 92 | #endif 93 | if (0 != ret) 94 | { 95 | return ret; 96 | } 97 | 98 | // 2. load model 99 | std::vector model_buffer; 100 | if (!utilities::read_file(model, model_buffer)) 101 | { 102 | fprintf(stderr, "Read Run-Joint model(%s) file failed.\n", model.c_str()); 103 | return false; 104 | } 105 | 106 | // 3. create handle 107 | AX_ENGINE_HANDLE handle; 108 | ret = AX_ENGINE_CreateHandle(&handle, model_buffer.data(), model_buffer.size()); 109 | SAMPLE_AX_ENGINE_DEAL_HANDLE 110 | fprintf(stdout, "Engine creating handle is done.\n"); 111 | 112 | // 4. create context 113 | ret = AX_ENGINE_CreateContext(handle); 114 | SAMPLE_AX_ENGINE_DEAL_HANDLE 115 | fprintf(stdout, "Engine creating context is done.\n"); 116 | 117 | // 5. set io 118 | AX_ENGINE_IO_INFO_T* io_info; 119 | ret = AX_ENGINE_GetIOInfo(handle, &io_info); 120 | SAMPLE_AX_ENGINE_DEAL_HANDLE 121 | fprintf(stdout, "Engine get io info is done. \n"); 122 | 123 | // 6. alloc io 124 | AX_ENGINE_IO_T io_data; 125 | ret = middleware::prepare_io(io_info, &io_data, std::make_pair(AX_ENGINE_ABST_DEFAULT, AX_ENGINE_ABST_CACHED)); 126 | SAMPLE_AX_ENGINE_DEAL_HANDLE 127 | fprintf(stdout, "Engine alloc io is done. \n"); 128 | 129 | // 7. insert input 130 | ret = middleware::push_input(data, &io_data, io_info); 131 | SAMPLE_AX_ENGINE_DEAL_HANDLE_IO 132 | fprintf(stdout, "Engine push input is done. \n"); 133 | fprintf(stdout, "--------------------------------------\n"); 134 | 135 | // 8. warn up 136 | for (int i = 0; i < 5; ++i) 137 | { 138 | AX_ENGINE_RunSync(handle, &io_data); 139 | } 140 | 141 | // 9. run model 142 | std::vector time_costs(repeat, 0); 143 | for (int i = 0; i < repeat; ++i) 144 | { 145 | timer tick; 146 | ret = AX_ENGINE_RunSync(handle, &io_data); 147 | time_costs[i] = tick.cost(); 148 | SAMPLE_AX_ENGINE_DEAL_HANDLE_IO 149 | } 150 | 151 | // 10. get result 152 | post_process(io_info, &io_data, mat, input_w, input_h, time_costs); 153 | fprintf(stdout, "--------------------------------------\n"); 154 | 155 | middleware::free_io(&io_data); 156 | return AX_ENGINE_DestroyHandle(handle); 157 | } 158 | } // namespace ax 159 | 160 | int main(int argc, char* argv[]) 161 | { 162 | cmdline::parser cmd; 163 | cmd.add("model", 'm', "joint file(a.k.a. joint model)", true, ""); 164 | cmd.add("image", 'i', "image file", true, ""); 165 | cmd.add("size", 'g', "input_h, input_w", false, std::to_string(DEFAULT_IMG_H) + "," + std::to_string(DEFAULT_IMG_W)); 166 | 167 | cmd.add("repeat", 'r', "repeat count", false, DEFAULT_LOOP_COUNT); 168 | cmd.parse_check(argc, argv); 169 | 170 | // 0. get app args, can be removed from user's app 171 | auto model_file = cmd.get("model"); 172 | auto image_file = cmd.get("image"); 173 | 174 | auto model_file_flag = utilities::file_exist(model_file); 175 | auto image_file_flag = utilities::file_exist(image_file); 176 | 177 | if (!model_file_flag | !image_file_flag) 178 | { 179 | auto show_error = [](const std::string& kind, const std::string& value) { 180 | fprintf(stderr, "Input file %s(%s) is not exist, please check it.\n", kind.c_str(), value.c_str()); 181 | }; 182 | 183 | if (!model_file_flag) { show_error("model", model_file); } 184 | if (!image_file_flag) { show_error("image", image_file); } 185 | 186 | return -1; 187 | } 188 | 189 | auto input_size_string = cmd.get("size"); 190 | 191 | std::array input_size = {DEFAULT_IMG_H, DEFAULT_IMG_W}; 192 | 193 | auto input_size_flag = utilities::parse_string(input_size_string, input_size); 194 | 195 | if (!input_size_flag) 196 | { 197 | auto show_error = [](const std::string& kind, const std::string& value) { 198 | fprintf(stderr, "Input %s(%s) is not allowed, please check it.\n", kind.c_str(), value.c_str()); 199 | }; 200 | 201 | show_error("size", input_size_string); 202 | 203 | return -1; 204 | } 205 | 206 | auto repeat = cmd.get("repeat"); 207 | 208 | // 1. print args 209 | fprintf(stdout, "--------------------------------------\n"); 210 | fprintf(stdout, "model file : %s\n", model_file.c_str()); 211 | fprintf(stdout, "image file : %s\n", image_file.c_str()); 212 | fprintf(stdout, "img_h, img_w : %d %d\n", input_size[0], input_size[1]); 213 | fprintf(stdout, "--------------------------------------\n"); 214 | 215 | // 2. read image & resize & transpose 216 | std::vector image(input_size[0] * input_size[1] * 3, 0); 217 | cv::Mat mat = cv::imread(image_file); 218 | if (mat.empty()) 219 | { 220 | fprintf(stderr, "Read image failed.\n"); 221 | return -1; 222 | } 223 | common::get_input_data_no_letterbox(mat, image, input_size[0], input_size[1], true); 224 | 225 | // 3. sys_init 226 | AX_SYS_Init(); 227 | 228 | // 4. - engine model - can only use AX_ENGINE** inside 229 | { 230 | // AX_ENGINE_NPUReset(); // todo ?? 231 | ax::run_model(model_file, image, repeat, mat, input_size[0], input_size[1]); 232 | 233 | // 4.3 engine de init 234 | AX_ENGINE_Deinit(); 235 | // AX_ENGINE_NPUReset(); 236 | } 237 | // 4. - engine model - 238 | 239 | AX_SYS_Deinit(); 240 | return 0; 241 | } 242 | -------------------------------------------------------------------------------- /examples/ax650/ax_glpdepth_steps.cc: -------------------------------------------------------------------------------- 1 | /* 2 | * AXERA is pleased to support the open source community by making ax-samples available. 3 | * 4 | * Copyright (c) 2022, AXERA Semiconductor (Shanghai) Co., Ltd. All rights reserved. 5 | * 6 | * Licensed under the BSD 3-Clause License (the "License"); you may not use this file except 7 | * in compliance with the License. You may obtain a copy of the License at 8 | * 9 | * https://opensource.org/licenses/BSD-3-Clause 10 | * 11 | * Unless required by applicable law or agreed to in writing, software distributed 12 | * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 13 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the 14 | * specific language governing permissions and limitations under the License. 15 | */ 16 | 17 | /* 18 | * Author: ZHEQIUSHUI 19 | */ 20 | 21 | #include 22 | #include 23 | #include 24 | 25 | #include 26 | #include "base/common.hpp" 27 | #include "base/detection.hpp" 28 | #include "middleware/io.hpp" 29 | 30 | #include "utilities/args.hpp" 31 | #include "utilities/cmdline.hpp" 32 | #include "utilities/file.hpp" 33 | #include "utilities/timer.hpp" 34 | 35 | #include 36 | #include 37 | 38 | const int DEFAULT_IMG_H = 896; 39 | const int DEFAULT_IMG_W = 1152; 40 | 41 | const int DEFAULT_LOOP_COUNT = 1; 42 | 43 | namespace ax 44 | { 45 | void post_process(AX_ENGINE_IO_INFO_T* io_info, AX_ENGINE_IO_T* io_data, const cv::Mat& mat, int input_w, int input_h, const std::vector& time_costs) 46 | { 47 | timer timer_postprocess; 48 | auto& output = io_data->pOutputs[0]; 49 | auto& info = io_info->pOutputs[0]; 50 | 51 | cv::Mat feature(info.pShape[2], info.pShape[3], CV_32FC1, output.pVirAddr); 52 | 53 | double minVal, maxVal; 54 | cv::minMaxLoc(feature, &minVal, &maxVal); 55 | 56 | feature -= minVal; 57 | feature /= (maxVal - minVal); 58 | feature = 1.f - feature; 59 | feature *= 255; 60 | 61 | feature.convertTo(feature, CV_8UC1); 62 | 63 | cv::Mat dst(info.pShape[2], info.pShape[3], CV_8UC3); 64 | cv::applyColorMap(feature, dst, cv::ColormapTypes::COLORMAP_MAGMA); 65 | cv::resize(dst, dst, cv::Size(mat.cols, mat.rows)); 66 | 67 | fprintf(stdout, "post process cost time:%.2f ms \n", timer_postprocess.cost()); 68 | fprintf(stdout, "--------------------------------------\n"); 69 | auto total_time = std::accumulate(time_costs.begin(), time_costs.end(), 0.f); 70 | auto min_max_time = std::minmax_element(time_costs.begin(), time_costs.end()); 71 | fprintf(stdout, 72 | "Repeat %d times, avg time %.2f ms, max_time %.2f ms, min_time %.2f ms\n", 73 | (int)time_costs.size(), 74 | total_time / (float)time_costs.size(), 75 | *min_max_time.second, 76 | *min_max_time.first); 77 | fprintf(stdout, "--------------------------------------\n"); 78 | cv::hconcat(std::vector{mat, dst}, dst); 79 | cv::imwrite("glpdepth_out.png", dst); 80 | } 81 | 82 | bool run_model(const std::string& model, const std::vector& data, const int& repeat, cv::Mat& mat, int input_h, int input_w) 83 | { 84 | // 1. init engine 85 | #ifdef AXERA_TARGET_CHIP_AX620E 86 | auto ret = AX_ENGINE_Init(); 87 | #else 88 | AX_ENGINE_NPU_ATTR_T npu_attr; 89 | memset(&npu_attr, 0, sizeof(npu_attr)); 90 | npu_attr.eHardMode = AX_ENGINE_VIRTUAL_NPU_DISABLE; 91 | auto ret = AX_ENGINE_Init(&npu_attr); 92 | #endif 93 | if (0 != ret) 94 | { 95 | return ret; 96 | } 97 | 98 | // 2. load model 99 | std::vector model_buffer; 100 | if (!utilities::read_file(model, model_buffer)) 101 | { 102 | fprintf(stderr, "Read Run-Joint model(%s) file failed.\n", model.c_str()); 103 | return false; 104 | } 105 | 106 | // 3. create handle 107 | AX_ENGINE_HANDLE handle; 108 | ret = AX_ENGINE_CreateHandle(&handle, model_buffer.data(), model_buffer.size()); 109 | SAMPLE_AX_ENGINE_DEAL_HANDLE 110 | fprintf(stdout, "Engine creating handle is done.\n"); 111 | 112 | // 4. create context 113 | ret = AX_ENGINE_CreateContext(handle); 114 | SAMPLE_AX_ENGINE_DEAL_HANDLE 115 | fprintf(stdout, "Engine creating context is done.\n"); 116 | 117 | // 5. set io 118 | AX_ENGINE_IO_INFO_T* io_info; 119 | ret = AX_ENGINE_GetIOInfo(handle, &io_info); 120 | SAMPLE_AX_ENGINE_DEAL_HANDLE 121 | fprintf(stdout, "Engine get io info is done. \n"); 122 | 123 | // 6. alloc io 124 | AX_ENGINE_IO_T io_data; 125 | ret = middleware::prepare_io(io_info, &io_data, std::make_pair(AX_ENGINE_ABST_DEFAULT, AX_ENGINE_ABST_CACHED)); 126 | SAMPLE_AX_ENGINE_DEAL_HANDLE 127 | fprintf(stdout, "Engine alloc io is done. \n"); 128 | 129 | // 7. insert input 130 | ret = middleware::push_input(data, &io_data, io_info); 131 | SAMPLE_AX_ENGINE_DEAL_HANDLE_IO 132 | fprintf(stdout, "Engine push input is done. \n"); 133 | fprintf(stdout, "--------------------------------------\n"); 134 | 135 | // 8. warn up 136 | for (int i = 0; i < 5; ++i) 137 | { 138 | AX_ENGINE_RunSync(handle, &io_data); 139 | } 140 | 141 | // 9. run model 142 | std::vector time_costs(repeat, 0); 143 | for (int i = 0; i < repeat; ++i) 144 | { 145 | timer tick; 146 | ret = AX_ENGINE_RunSync(handle, &io_data); 147 | time_costs[i] = tick.cost(); 148 | SAMPLE_AX_ENGINE_DEAL_HANDLE_IO 149 | } 150 | 151 | // 10. get result 152 | post_process(io_info, &io_data, mat, input_w, input_h, time_costs); 153 | fprintf(stdout, "--------------------------------------\n"); 154 | 155 | middleware::free_io(&io_data); 156 | return AX_ENGINE_DestroyHandle(handle); 157 | } 158 | } // namespace ax 159 | 160 | int main(int argc, char* argv[]) 161 | { 162 | cmdline::parser cmd; 163 | cmd.add("model", 'm', "joint file(a.k.a. joint model)", true, ""); 164 | cmd.add("image", 'i', "image file", true, ""); 165 | cmd.add("size", 'g', "input_h, input_w", false, std::to_string(DEFAULT_IMG_H) + "," + std::to_string(DEFAULT_IMG_W)); 166 | 167 | cmd.add("repeat", 'r', "repeat count", false, DEFAULT_LOOP_COUNT); 168 | cmd.parse_check(argc, argv); 169 | 170 | // 0. get app args, can be removed from user's app 171 | auto model_file = cmd.get("model"); 172 | auto image_file = cmd.get("image"); 173 | 174 | auto model_file_flag = utilities::file_exist(model_file); 175 | auto image_file_flag = utilities::file_exist(image_file); 176 | 177 | if (!model_file_flag | !image_file_flag) 178 | { 179 | auto show_error = [](const std::string& kind, const std::string& value) { 180 | fprintf(stderr, "Input file %s(%s) is not exist, please check it.\n", kind.c_str(), value.c_str()); 181 | }; 182 | 183 | if (!model_file_flag) { show_error("model", model_file); } 184 | if (!image_file_flag) { show_error("image", image_file); } 185 | 186 | return -1; 187 | } 188 | 189 | auto input_size_string = cmd.get("size"); 190 | 191 | std::array input_size = {DEFAULT_IMG_H, DEFAULT_IMG_W}; 192 | 193 | auto input_size_flag = utilities::parse_string(input_size_string, input_size); 194 | 195 | if (!input_size_flag) 196 | { 197 | auto show_error = [](const std::string& kind, const std::string& value) { 198 | fprintf(stderr, "Input %s(%s) is not allowed, please check it.\n", kind.c_str(), value.c_str()); 199 | }; 200 | 201 | show_error("size", input_size_string); 202 | 203 | return -1; 204 | } 205 | 206 | auto repeat = cmd.get("repeat"); 207 | 208 | // 1. print args 209 | fprintf(stdout, "--------------------------------------\n"); 210 | fprintf(stdout, "model file : %s\n", model_file.c_str()); 211 | fprintf(stdout, "image file : %s\n", image_file.c_str()); 212 | fprintf(stdout, "img_h, img_w : %d %d\n", input_size[0], input_size[1]); 213 | fprintf(stdout, "--------------------------------------\n"); 214 | 215 | // 2. read image & resize & transpose 216 | std::vector image(input_size[0] * input_size[1] * 3, 0); 217 | cv::Mat mat = cv::imread(image_file); 218 | if (mat.empty()) 219 | { 220 | fprintf(stderr, "Read image failed.\n"); 221 | return -1; 222 | } 223 | common::get_input_data_no_letterbox(mat, image, input_size[0], input_size[1], true); 224 | 225 | // 3. sys_init 226 | AX_SYS_Init(); 227 | 228 | // 4. - engine model - can only use AX_ENGINE** inside 229 | { 230 | // AX_ENGINE_NPUReset(); // todo ?? 231 | ax::run_model(model_file, image, repeat, mat, input_size[0], input_size[1]); 232 | 233 | // 4.3 engine de init 234 | AX_ENGINE_Deinit(); 235 | // AX_ENGINE_NPUReset(); 236 | } 237 | // 4. - engine model - 238 | 239 | AX_SYS_Deinit(); 240 | return 0; 241 | } 242 | -------------------------------------------------------------------------------- /examples/ax650/ax_hrnet_steps.cc: -------------------------------------------------------------------------------- 1 | /* 2 | * AXERA is pleased to support the open source community by making ax-samples available. 3 | * 4 | * Copyright (c) 2022, AXERA Semiconductor (Shanghai) Co., Ltd. All rights reserved. 5 | * 6 | * Licensed under the BSD 3-Clause License (the "License"); you may not use this file except 7 | * in compliance with the License. You may obtain a copy of the License at 8 | * 9 | * https://opensource.org/licenses/BSD-3-Clause 10 | * 11 | * Unless required by applicable law or agreed to in writing, software distributed 12 | * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 13 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the 14 | * specific language governing permissions and limitations under the License. 15 | */ 16 | 17 | /* 18 | * Author: ZHEQIUSHUI 19 | */ 20 | 21 | #include 22 | #include 23 | #include 24 | 25 | #include 26 | #include "base/common.hpp" 27 | #include "base/detection.hpp" 28 | #include "middleware/io.hpp" 29 | #include "base/pose.hpp" 30 | #include "utilities/args.hpp" 31 | #include "utilities/cmdline.hpp" 32 | #include "utilities/file.hpp" 33 | #include "utilities/timer.hpp" 34 | 35 | #include 36 | #include 37 | 38 | const int HRNET_H = 256; 39 | const int HRNET_W = 192; 40 | const int HRNET_JOINTS = 17; 41 | const int DEFAULT_LOOP_COUNT = 1; 42 | 43 | namespace ax 44 | { 45 | void post_process(AX_ENGINE_IO_INFO_T* io_info, AX_ENGINE_IO_T* io_data, const cv::Mat& mat, int input_w, int input_h, const std::vector& time_costs) 46 | { 47 | timer timer_postprocess; 48 | auto& info = io_info->pOutputs[0]; 49 | float* output = (float*)io_data->pOutputs[0].pVirAddr; 50 | 51 | pose::ai_body_parts_s ai_point_result; 52 | 53 | pose::post_process(output, ai_point_result, HRNET_JOINTS, HRNET_H, HRNET_W); 54 | 55 | fprintf(stdout, "post process cost time:%.2f ms \n", timer_postprocess.cost()); 56 | fprintf(stdout, "--------------------------------------\n"); 57 | auto total_time = std::accumulate(time_costs.begin(), time_costs.end(), 0.f); 58 | auto min_max_time = std::minmax_element(time_costs.begin(), time_costs.end()); 59 | fprintf(stdout, 60 | "Repeat %d times, avg time %.2f ms, max_time %.2f ms, min_time %.2f ms\n", 61 | (int)time_costs.size(), 62 | total_time / (float)time_costs.size(), 63 | *min_max_time.second, 64 | *min_max_time.first); 65 | fprintf(stdout, "--------------------------------------\n"); 66 | pose::draw_result(mat, ai_point_result, HRNET_JOINTS, HRNET_W, HRNET_H); 67 | cv::imwrite("./hrnet_out.jpg", mat); 68 | } 69 | 70 | bool run_model(const std::string& model, const std::vector& data, const int& repeat, cv::Mat& mat, int input_h, int input_w) 71 | { 72 | // 1. init engine 73 | #ifdef AXERA_TARGET_CHIP_AX620E 74 | auto ret = AX_ENGINE_Init(); 75 | #else 76 | AX_ENGINE_NPU_ATTR_T npu_attr; 77 | memset(&npu_attr, 0, sizeof(npu_attr)); 78 | npu_attr.eHardMode = AX_ENGINE_VIRTUAL_NPU_DISABLE; 79 | auto ret = AX_ENGINE_Init(&npu_attr); 80 | #endif 81 | if (0 != ret) 82 | { 83 | return ret; 84 | } 85 | 86 | // 2. load model 87 | std::vector model_buffer; 88 | if (!utilities::read_file(model, model_buffer)) 89 | { 90 | fprintf(stderr, "Read Run-Joint model(%s) file failed.\n", model.c_str()); 91 | return false; 92 | } 93 | 94 | // 3. create handle 95 | AX_ENGINE_HANDLE handle; 96 | ret = AX_ENGINE_CreateHandle(&handle, model_buffer.data(), model_buffer.size()); 97 | SAMPLE_AX_ENGINE_DEAL_HANDLE 98 | fprintf(stdout, "Engine creating handle is done.\n"); 99 | 100 | // 4. create context 101 | ret = AX_ENGINE_CreateContext(handle); 102 | SAMPLE_AX_ENGINE_DEAL_HANDLE 103 | fprintf(stdout, "Engine creating context is done.\n"); 104 | 105 | // 5. set io 106 | AX_ENGINE_IO_INFO_T* io_info; 107 | ret = AX_ENGINE_GetIOInfo(handle, &io_info); 108 | SAMPLE_AX_ENGINE_DEAL_HANDLE 109 | fprintf(stdout, "Engine get io info is done. \n"); 110 | 111 | // 6. alloc io 112 | AX_ENGINE_IO_T io_data; 113 | ret = middleware::prepare_io(io_info, &io_data, std::make_pair(AX_ENGINE_ABST_DEFAULT, AX_ENGINE_ABST_CACHED)); 114 | SAMPLE_AX_ENGINE_DEAL_HANDLE 115 | fprintf(stdout, "Engine alloc io is done. \n"); 116 | 117 | // 7. insert input 118 | ret = middleware::push_input(data, &io_data, io_info); 119 | SAMPLE_AX_ENGINE_DEAL_HANDLE_IO 120 | fprintf(stdout, "Engine push input is done. \n"); 121 | fprintf(stdout, "--------------------------------------\n"); 122 | 123 | // 8. warn up 124 | for (int i = 0; i < 5; ++i) 125 | { 126 | AX_ENGINE_RunSync(handle, &io_data); 127 | } 128 | 129 | // 9. run model 130 | std::vector time_costs(repeat, 0); 131 | for (int i = 0; i < repeat; ++i) 132 | { 133 | timer tick; 134 | ret = AX_ENGINE_RunSync(handle, &io_data); 135 | time_costs[i] = tick.cost(); 136 | SAMPLE_AX_ENGINE_DEAL_HANDLE_IO 137 | } 138 | 139 | // 10. get result 140 | post_process(io_info, &io_data, mat, input_w, input_h, time_costs); 141 | fprintf(stdout, "--------------------------------------\n"); 142 | 143 | middleware::free_io(&io_data); 144 | return AX_ENGINE_DestroyHandle(handle); 145 | } 146 | } // namespace ax 147 | 148 | int main(int argc, char* argv[]) 149 | { 150 | cmdline::parser cmd; 151 | cmd.add("model", 'm', "joint file(a.k.a. joint model)", true, ""); 152 | cmd.add("image", 'i', "image file", true, ""); 153 | cmd.add("size", 'g', "input_h, input_w", false, std::to_string(HRNET_H) + "," + std::to_string(HRNET_W)); 154 | 155 | cmd.add("repeat", 'r', "repeat count", false, DEFAULT_LOOP_COUNT); 156 | cmd.parse_check(argc, argv); 157 | 158 | // 0. get app args, can be removed from user's app 159 | auto model_file = cmd.get("model"); 160 | auto image_file = cmd.get("image"); 161 | 162 | auto model_file_flag = utilities::file_exist(model_file); 163 | auto image_file_flag = utilities::file_exist(image_file); 164 | 165 | if (!model_file_flag | !image_file_flag) 166 | { 167 | auto show_error = [](const std::string& kind, const std::string& value) { 168 | fprintf(stderr, "Input file %s(%s) is not exist, please check it.\n", kind.c_str(), value.c_str()); 169 | }; 170 | 171 | if (!model_file_flag) { show_error("model", model_file); } 172 | if (!image_file_flag) { show_error("image", image_file); } 173 | 174 | return -1; 175 | } 176 | 177 | auto input_size_string = cmd.get("size"); 178 | 179 | std::array input_size = {HRNET_H, HRNET_W}; 180 | 181 | auto input_size_flag = utilities::parse_string(input_size_string, input_size); 182 | 183 | if (!input_size_flag) 184 | { 185 | auto show_error = [](const std::string& kind, const std::string& value) { 186 | fprintf(stderr, "Input %s(%s) is not allowed, please check it.\n", kind.c_str(), value.c_str()); 187 | }; 188 | 189 | show_error("size", input_size_string); 190 | 191 | return -1; 192 | } 193 | 194 | auto repeat = cmd.get("repeat"); 195 | 196 | // 1. print args 197 | fprintf(stdout, "--------------------------------------\n"); 198 | fprintf(stdout, "model file : %s\n", model_file.c_str()); 199 | fprintf(stdout, "image file : %s\n", image_file.c_str()); 200 | fprintf(stdout, "img_h, img_w : %d %d\n", input_size[0], input_size[1]); 201 | fprintf(stdout, "--------------------------------------\n"); 202 | 203 | // 2. read image & resize & transpose 204 | std::vector image(input_size[0] * input_size[1] * 3, 0); 205 | cv::Mat mat = cv::imread(image_file); 206 | if (mat.empty()) 207 | { 208 | fprintf(stderr, "Read image failed.\n"); 209 | return -1; 210 | } 211 | common::get_input_data_letterbox(mat, image, input_size[0], input_size[1]); 212 | 213 | // 3. sys_init 214 | AX_SYS_Init(); 215 | 216 | // 4. - engine model - can only use AX_ENGINE** inside 217 | { 218 | // AX_ENGINE_NPUReset(); // todo ?? 219 | ax::run_model(model_file, image, repeat, mat, input_size[0], input_size[1]); 220 | 221 | // 4.3 engine de init 222 | AX_ENGINE_Deinit(); 223 | // AX_ENGINE_NPUReset(); 224 | } 225 | // 4. - engine model - 226 | 227 | AX_SYS_Deinit(); 228 | return 0; 229 | } 230 | -------------------------------------------------------------------------------- /examples/ax650/ax_model_info.cc: -------------------------------------------------------------------------------- 1 | /* 2 | * AXERA is pleased to support the open source community by making ax-samples available. 3 | * 4 | * Copyright (c) 2022, AXERA Semiconductor (Shanghai) Co., Ltd. All rights reserved. 5 | * 6 | * Licensed under the BSD 3-Clause License (the "License"); you may not use this file except 7 | * in compliance with the License. You may obtain a copy of the License at 8 | * 9 | * https://opensource.org/licenses/BSD-3-Clause 10 | * 11 | * Unless required by applicable law or agreed to in writing, software distributed 12 | * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 13 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the 14 | * specific language governing permissions and limitations under the License. 15 | */ 16 | 17 | /* 18 | * Author: ZHEQIUSHUI 19 | */ 20 | 21 | #include 22 | #include 23 | #include 24 | 25 | #include 26 | #include "base/common.hpp" 27 | #include "middleware/io.hpp" 28 | 29 | #include "utilities/args.hpp" 30 | #include "utilities/cmdline.hpp" 31 | #include "utilities/file.hpp" 32 | #include "utilities/timer.hpp" 33 | 34 | #include 35 | #include 36 | 37 | #include "base/score.hpp" 38 | #include "base/topk.hpp" 39 | 40 | namespace ax 41 | { 42 | bool run_model(const std::string& model) 43 | { 44 | // 1. init engine 45 | #ifdef AXERA_TARGET_CHIP_AX620E 46 | auto ret = AX_ENGINE_Init(); 47 | #else 48 | AX_ENGINE_NPU_ATTR_T npu_attr; 49 | memset(&npu_attr, 0, sizeof(npu_attr)); 50 | npu_attr.eHardMode = AX_ENGINE_VIRTUAL_NPU_DISABLE; 51 | auto ret = AX_ENGINE_Init(&npu_attr); 52 | #endif 53 | if (0 != ret) 54 | { 55 | return ret; 56 | } 57 | 58 | // 2. load model 59 | std::vector model_buffer; 60 | if (!utilities::read_file(model, model_buffer)) 61 | { 62 | fprintf(stderr, "Read Run-Joint model(%s) file failed.\n", model.c_str()); 63 | return false; 64 | } 65 | 66 | // 3. create handle 67 | AX_ENGINE_HANDLE handle; 68 | ret = AX_ENGINE_CreateHandle(&handle, model_buffer.data(), model_buffer.size()); 69 | SAMPLE_AX_ENGINE_DEAL_HANDLE 70 | fprintf(stdout, "Engine creating handle is done.\n"); 71 | 72 | // 4. create context 73 | ret = AX_ENGINE_CreateContext(handle); 74 | SAMPLE_AX_ENGINE_DEAL_HANDLE 75 | fprintf(stdout, "Engine creating context is done.\n"); 76 | 77 | // 5. set io 78 | AX_ENGINE_IO_INFO_T* io_info; 79 | ret = AX_ENGINE_GetIOInfo(handle, &io_info); 80 | SAMPLE_AX_ENGINE_DEAL_HANDLE 81 | fprintf(stdout, "Engine get io info is done. \n"); 82 | 83 | // 6. printf io 84 | middleware::print_io_info(io_info); 85 | 86 | return AX_ENGINE_DestroyHandle(handle); 87 | } 88 | } // namespace ax 89 | 90 | int main(int argc, char* argv[]) 91 | { 92 | cmdline::parser cmd; 93 | cmd.add("model", 'm', "joint file(a.k.a. joint model)", true, ""); 94 | cmd.parse_check(argc, argv); 95 | 96 | // 0. get app args, can be removed from user's app 97 | auto model_file = cmd.get("model"); 98 | 99 | auto model_file_flag = utilities::file_exist(model_file); 100 | 101 | if (!model_file_flag) 102 | { 103 | auto show_error = [](const std::string& kind, const std::string& value) { 104 | fprintf(stderr, "Input file %s(%s) is not exist, please check it.\n", kind.c_str(), value.c_str()); 105 | }; 106 | 107 | if (!model_file_flag) { show_error("model", model_file); } 108 | 109 | return -1; 110 | } 111 | 112 | // 1. print args 113 | fprintf(stdout, "--------------------------------------\n"); 114 | fprintf(stdout, "model file : %s\n", model_file.c_str()); 115 | fprintf(stdout, "--------------------------------------\n"); 116 | 117 | // 3. sys_init 118 | AX_SYS_Init(); 119 | 120 | // 4. - engine model - can only use AX_ENGINE** inside 121 | { 122 | // AX_ENGINE_NPUReset(); // todo ?? 123 | ax::run_model(model_file); 124 | 125 | // 4.3 engine de init 126 | AX_ENGINE_Deinit(); 127 | // AX_ENGINE_NPUReset(); 128 | } 129 | // 4. - engine model - 130 | 131 | AX_SYS_Deinit(); 132 | return 0; 133 | } 134 | -------------------------------------------------------------------------------- /examples/ax650/ax_pfld_steps.cc: -------------------------------------------------------------------------------- 1 | /* 2 | * AXERA is pleased to support the open source community by making ax-samples available. 3 | * 4 | * Copyright (c) 2022, AXERA Semiconductor (Shanghai) Co., Ltd. All rights reserved. 5 | * 6 | * Licensed under the BSD 3-Clause License (the "License"); you may not use this file except 7 | * in compliance with the License. You may obtain a copy of the License at 8 | * 9 | * https://opensource.org/licenses/BSD-3-Clause 10 | * 11 | * Unless required by applicable law or agreed to in writing, software distributed 12 | * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 13 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the 14 | * specific language governing permissions and limitations under the License. 15 | */ 16 | 17 | /* 18 | * Author: ZHEQIUSHUI 19 | */ 20 | 21 | #include 22 | #include 23 | #include 24 | 25 | #include 26 | #include "base/common.hpp" 27 | #include "base/detection.hpp" 28 | #include "middleware/io.hpp" 29 | 30 | #include "utilities/args.hpp" 31 | #include "utilities/cmdline.hpp" 32 | #include "utilities/file.hpp" 33 | #include "utilities/timer.hpp" 34 | 35 | #include 36 | #include 37 | 38 | const int DEFAULT_IMG_H = 112; 39 | const int DEFAULT_IMG_W = 112; 40 | 41 | const int DEFAULT_LOOP_COUNT = 1; 42 | 43 | namespace ax 44 | { 45 | void post_process(AX_ENGINE_IO_INFO_T* io_info, AX_ENGINE_IO_T* io_data, const cv::Mat& mat, int input_w, int input_h, const std::vector& time_costs) 46 | { 47 | timer timer_postprocess; 48 | 49 | auto& output = io_data->pOutputs[1]; 50 | auto& info = io_info->pOutputs[1]; 51 | 52 | auto landmarks_pred = (float*)output.pVirAddr; 53 | for (size_t i = 0; i < info.pShape[1] / 2; i++) 54 | { 55 | cv::circle(mat, 56 | cv::Point(landmarks_pred[2 * i] * mat.cols, landmarks_pred[2 * i + 1] * mat.rows), 57 | 1, cv::Scalar(0, 0, 255), 2); 58 | } 59 | 60 | fprintf(stdout, "post process cost time:%.2f ms \n", timer_postprocess.cost()); 61 | fprintf(stdout, "--------------------------------------\n"); 62 | auto total_time = std::accumulate(time_costs.begin(), time_costs.end(), 0.f); 63 | auto min_max_time = std::minmax_element(time_costs.begin(), time_costs.end()); 64 | fprintf(stdout, 65 | "Repeat %d times, avg time %.2f ms, max_time %.2f ms, min_time %.2f ms\n", 66 | (int)time_costs.size(), 67 | total_time / (float)time_costs.size(), 68 | *min_max_time.second, 69 | *min_max_time.first); 70 | fprintf(stdout, "--------------------------------------\n"); 71 | 72 | cv::imwrite("pfld_out.jpg", mat); 73 | } 74 | 75 | bool run_model(const std::string& model, const std::vector& data, const int& repeat, cv::Mat& mat, int input_h, int input_w) 76 | { 77 | // 1. init engine 78 | #ifdef AXERA_TARGET_CHIP_AX620E 79 | auto ret = AX_ENGINE_Init(); 80 | #else 81 | AX_ENGINE_NPU_ATTR_T npu_attr; 82 | memset(&npu_attr, 0, sizeof(npu_attr)); 83 | npu_attr.eHardMode = AX_ENGINE_VIRTUAL_NPU_DISABLE; 84 | auto ret = AX_ENGINE_Init(&npu_attr); 85 | #endif 86 | if (0 != ret) 87 | { 88 | return ret; 89 | } 90 | 91 | // 2. load model 92 | std::vector model_buffer; 93 | if (!utilities::read_file(model, model_buffer)) 94 | { 95 | fprintf(stderr, "Read Run-Joint model(%s) file failed.\n", model.c_str()); 96 | return false; 97 | } 98 | 99 | // 3. create handle 100 | AX_ENGINE_HANDLE handle; 101 | ret = AX_ENGINE_CreateHandle(&handle, model_buffer.data(), model_buffer.size()); 102 | SAMPLE_AX_ENGINE_DEAL_HANDLE 103 | fprintf(stdout, "Engine creating handle is done.\n"); 104 | 105 | // 4. create context 106 | ret = AX_ENGINE_CreateContext(handle); 107 | SAMPLE_AX_ENGINE_DEAL_HANDLE 108 | fprintf(stdout, "Engine creating context is done.\n"); 109 | 110 | // 5. set io 111 | AX_ENGINE_IO_INFO_T* io_info; 112 | ret = AX_ENGINE_GetIOInfo(handle, &io_info); 113 | SAMPLE_AX_ENGINE_DEAL_HANDLE 114 | fprintf(stdout, "Engine get io info is done. \n"); 115 | 116 | // 6. alloc io 117 | AX_ENGINE_IO_T io_data; 118 | ret = middleware::prepare_io(io_info, &io_data, std::make_pair(AX_ENGINE_ABST_DEFAULT, AX_ENGINE_ABST_CACHED)); 119 | SAMPLE_AX_ENGINE_DEAL_HANDLE 120 | fprintf(stdout, "Engine alloc io is done. \n"); 121 | 122 | // 7. insert input 123 | ret = middleware::push_input(data, &io_data, io_info); 124 | SAMPLE_AX_ENGINE_DEAL_HANDLE_IO 125 | fprintf(stdout, "Engine push input is done. \n"); 126 | fprintf(stdout, "--------------------------------------\n"); 127 | 128 | // 8. warn up 129 | for (int i = 0; i < 5; ++i) 130 | { 131 | AX_ENGINE_RunSync(handle, &io_data); 132 | } 133 | 134 | // 9. run model 135 | std::vector time_costs(repeat, 0); 136 | for (int i = 0; i < repeat; ++i) 137 | { 138 | timer tick; 139 | ret = AX_ENGINE_RunSync(handle, &io_data); 140 | time_costs[i] = tick.cost(); 141 | SAMPLE_AX_ENGINE_DEAL_HANDLE_IO 142 | } 143 | 144 | // 10. get result 145 | post_process(io_info, &io_data, mat, input_w, input_h, time_costs); 146 | fprintf(stdout, "--------------------------------------\n"); 147 | 148 | middleware::free_io(&io_data); 149 | return AX_ENGINE_DestroyHandle(handle); 150 | } 151 | } // namespace ax 152 | 153 | int main(int argc, char* argv[]) 154 | { 155 | cmdline::parser cmd; 156 | cmd.add("model", 'm', "joint file(a.k.a. joint model)", true, ""); 157 | cmd.add("image", 'i', "image file", true, ""); 158 | cmd.add("size", 'g', "input_h, input_w", false, std::to_string(DEFAULT_IMG_H) + "," + std::to_string(DEFAULT_IMG_W)); 159 | 160 | cmd.add("repeat", 'r', "repeat count", false, DEFAULT_LOOP_COUNT); 161 | cmd.parse_check(argc, argv); 162 | 163 | // 0. get app args, can be removed from user's app 164 | auto model_file = cmd.get("model"); 165 | auto image_file = cmd.get("image"); 166 | 167 | auto model_file_flag = utilities::file_exist(model_file); 168 | auto image_file_flag = utilities::file_exist(image_file); 169 | 170 | if (!model_file_flag | !image_file_flag) 171 | { 172 | auto show_error = [](const std::string& kind, const std::string& value) { 173 | fprintf(stderr, "Input file %s(%s) is not exist, please check it.\n", kind.c_str(), value.c_str()); 174 | }; 175 | 176 | if (!model_file_flag) { show_error("model", model_file); } 177 | if (!image_file_flag) { show_error("image", image_file); } 178 | 179 | return -1; 180 | } 181 | 182 | auto input_size_string = cmd.get("size"); 183 | 184 | std::array input_size = {DEFAULT_IMG_H, DEFAULT_IMG_W}; 185 | 186 | auto input_size_flag = utilities::parse_string(input_size_string, input_size); 187 | 188 | if (!input_size_flag) 189 | { 190 | auto show_error = [](const std::string& kind, const std::string& value) { 191 | fprintf(stderr, "Input %s(%s) is not allowed, please check it.\n", kind.c_str(), value.c_str()); 192 | }; 193 | 194 | show_error("size", input_size_string); 195 | 196 | return -1; 197 | } 198 | 199 | auto repeat = cmd.get("repeat"); 200 | 201 | // 1. print args 202 | fprintf(stdout, "--------------------------------------\n"); 203 | fprintf(stdout, "model file : %s\n", model_file.c_str()); 204 | fprintf(stdout, "image file : %s\n", image_file.c_str()); 205 | fprintf(stdout, "img_h, img_w : %d %d\n", input_size[0], input_size[1]); 206 | fprintf(stdout, "--------------------------------------\n"); 207 | 208 | // 2. read image & resize & transpose 209 | std::vector image(input_size[0] * input_size[1] * 3, 0); 210 | cv::Mat mat = cv::imread(image_file); 211 | if (mat.empty()) 212 | { 213 | fprintf(stderr, "Read image failed.\n"); 214 | return -1; 215 | } 216 | common::get_input_data_no_letterbox(mat, image, input_size[0], input_size[1]); 217 | 218 | // 3. sys_init 219 | AX_SYS_Init(); 220 | 221 | // 4. - engine model - can only use AX_ENGINE** inside 222 | { 223 | // AX_ENGINE_NPUReset(); // todo ?? 224 | ax::run_model(model_file, image, repeat, mat, input_size[0], input_size[1]); 225 | 226 | // 4.3 engine de init 227 | AX_ENGINE_Deinit(); 228 | // AX_ENGINE_NPUReset(); 229 | } 230 | // 4. - engine model - 231 | 232 | AX_SYS_Deinit(); 233 | return 0; 234 | } 235 | -------------------------------------------------------------------------------- /examples/ax650/ax_realesrgan_steps.cc: -------------------------------------------------------------------------------- 1 | /* 2 | * AXERA is pleased to support the open source community by making ax-samples available. 3 | * 4 | * Copyright (c) 2022, AXERA Semiconductor (Shanghai) Co., Ltd. All rights reserved. 5 | * 6 | * Licensed under the BSD 3-Clause License (the "License"); you may not use this file except 7 | * in compliance with the License. You may obtain a copy of the License at 8 | * 9 | * https://opensource.org/licenses/BSD-3-Clause 10 | * 11 | * Unless required by applicable law or agreed to in writing, software distributed 12 | * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 13 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the 14 | * specific language governing permissions and limitations under the License. 15 | */ 16 | 17 | /* 18 | * Author: ZHEQIUSHUI 19 | */ 20 | 21 | #include 22 | #include 23 | #include 24 | 25 | #include 26 | #include "base/common.hpp" 27 | #include "base/detection.hpp" 28 | #include "middleware/io.hpp" 29 | 30 | #include "utilities/args.hpp" 31 | #include "utilities/cmdline.hpp" 32 | #include "utilities/file.hpp" 33 | #include "utilities/timer.hpp" 34 | 35 | #include 36 | #include 37 | 38 | const int DEFAULT_IMG_H = 64; 39 | const int DEFAULT_IMG_W = 64; 40 | 41 | const int DEFAULT_LOOP_COUNT = 1; 42 | 43 | namespace ax 44 | { 45 | void post_process(AX_ENGINE_IO_INFO_T* io_info, AX_ENGINE_IO_T* io_data, const cv::Mat& mat, int input_w, int input_h, const std::vector& time_costs) 46 | { 47 | timer timer_postprocess; 48 | auto& info = io_info->pOutputs[0]; 49 | float* output = (float*)io_data->pOutputs[0].pVirAddr; 50 | 51 | cv::Mat dst(info.pShape[1], info.pShape[2], CV_8UC(info.pShape[3])); 52 | uchar* dst_data = dst.data; 53 | for (size_t i = 0; i < info.nSize / 4; i++) 54 | { 55 | float val = output[i] * 255.f; 56 | dst_data[i] = val > UCHAR_MAX ? UCHAR_MAX : val; 57 | } 58 | 59 | fprintf(stdout, "post process cost time:%.2f ms \n", timer_postprocess.cost()); 60 | fprintf(stdout, "--------------------------------------\n"); 61 | auto total_time = std::accumulate(time_costs.begin(), time_costs.end(), 0.f); 62 | auto min_max_time = std::minmax_element(time_costs.begin(), time_costs.end()); 63 | fprintf(stdout, 64 | "Repeat %d times, avg time %.2f ms, max_time %.2f ms, min_time %.2f ms\n", 65 | (int)time_costs.size(), 66 | total_time / (float)time_costs.size(), 67 | *min_max_time.second, 68 | *min_max_time.first); 69 | fprintf(stdout, "--------------------------------------\n"); 70 | cv::imwrite("realesrgan_out.jpg", dst); 71 | } 72 | 73 | bool run_model(const std::string& model, const std::vector& data, const int& repeat, cv::Mat& mat, int input_h, int input_w) 74 | { 75 | // 1. init engine 76 | #ifdef AXERA_TARGET_CHIP_AX620E 77 | auto ret = AX_ENGINE_Init(); 78 | #else 79 | AX_ENGINE_NPU_ATTR_T npu_attr; 80 | memset(&npu_attr, 0, sizeof(npu_attr)); 81 | npu_attr.eHardMode = AX_ENGINE_VIRTUAL_NPU_DISABLE; 82 | auto ret = AX_ENGINE_Init(&npu_attr); 83 | #endif 84 | if (0 != ret) 85 | { 86 | return ret; 87 | } 88 | 89 | // 2. load model 90 | std::vector model_buffer; 91 | if (!utilities::read_file(model, model_buffer)) 92 | { 93 | fprintf(stderr, "Read Run-Joint model(%s) file failed.\n", model.c_str()); 94 | return false; 95 | } 96 | 97 | // 3. create handle 98 | AX_ENGINE_HANDLE handle; 99 | ret = AX_ENGINE_CreateHandle(&handle, model_buffer.data(), model_buffer.size()); 100 | SAMPLE_AX_ENGINE_DEAL_HANDLE 101 | fprintf(stdout, "Engine creating handle is done.\n"); 102 | 103 | // 4. create context 104 | ret = AX_ENGINE_CreateContext(handle); 105 | SAMPLE_AX_ENGINE_DEAL_HANDLE 106 | fprintf(stdout, "Engine creating context is done.\n"); 107 | 108 | // 5. set io 109 | AX_ENGINE_IO_INFO_T* io_info; 110 | ret = AX_ENGINE_GetIOInfo(handle, &io_info); 111 | SAMPLE_AX_ENGINE_DEAL_HANDLE 112 | fprintf(stdout, "Engine get io info is done. \n"); 113 | 114 | // 6. alloc io 115 | AX_ENGINE_IO_T io_data; 116 | ret = middleware::prepare_io(io_info, &io_data, std::make_pair(AX_ENGINE_ABST_DEFAULT, AX_ENGINE_ABST_CACHED)); 117 | SAMPLE_AX_ENGINE_DEAL_HANDLE 118 | fprintf(stdout, "Engine alloc io is done. \n"); 119 | 120 | // 7. insert input 121 | ret = middleware::push_input(data, &io_data, io_info); 122 | SAMPLE_AX_ENGINE_DEAL_HANDLE_IO 123 | fprintf(stdout, "Engine push input is done. \n"); 124 | fprintf(stdout, "--------------------------------------\n"); 125 | 126 | // 8. warn up 127 | for (int i = 0; i < 5; ++i) 128 | { 129 | AX_ENGINE_RunSync(handle, &io_data); 130 | } 131 | 132 | // 9. run model 133 | std::vector time_costs(repeat, 0); 134 | for (int i = 0; i < repeat; ++i) 135 | { 136 | timer tick; 137 | ret = AX_ENGINE_RunSync(handle, &io_data); 138 | time_costs[i] = tick.cost(); 139 | SAMPLE_AX_ENGINE_DEAL_HANDLE_IO 140 | } 141 | 142 | // 10. get result 143 | post_process(io_info, &io_data, mat, input_w, input_h, time_costs); 144 | fprintf(stdout, "--------------------------------------\n"); 145 | 146 | middleware::free_io(&io_data); 147 | return AX_ENGINE_DestroyHandle(handle); 148 | } 149 | } // namespace ax 150 | 151 | int main(int argc, char* argv[]) 152 | { 153 | cmdline::parser cmd; 154 | cmd.add("model", 'm', "joint file(a.k.a. joint model)", true, ""); 155 | cmd.add("image", 'i', "image file", true, ""); 156 | cmd.add("size", 'g', "input_h, input_w", false, std::to_string(DEFAULT_IMG_H) + "," + std::to_string(DEFAULT_IMG_W)); 157 | 158 | cmd.add("repeat", 'r', "repeat count", false, DEFAULT_LOOP_COUNT); 159 | cmd.parse_check(argc, argv); 160 | 161 | // 0. get app args, can be removed from user's app 162 | auto model_file = cmd.get("model"); 163 | auto image_file = cmd.get("image"); 164 | 165 | auto model_file_flag = utilities::file_exist(model_file); 166 | auto image_file_flag = utilities::file_exist(image_file); 167 | 168 | if (!model_file_flag | !image_file_flag) 169 | { 170 | auto show_error = [](const std::string& kind, const std::string& value) { 171 | fprintf(stderr, "Input file %s(%s) is not exist, please check it.\n", kind.c_str(), value.c_str()); 172 | }; 173 | 174 | if (!model_file_flag) { show_error("model", model_file); } 175 | if (!image_file_flag) { show_error("image", image_file); } 176 | 177 | return -1; 178 | } 179 | 180 | auto input_size_string = cmd.get("size"); 181 | 182 | std::array input_size = {DEFAULT_IMG_H, DEFAULT_IMG_W}; 183 | 184 | auto input_size_flag = utilities::parse_string(input_size_string, input_size); 185 | 186 | if (!input_size_flag) 187 | { 188 | auto show_error = [](const std::string& kind, const std::string& value) { 189 | fprintf(stderr, "Input %s(%s) is not allowed, please check it.\n", kind.c_str(), value.c_str()); 190 | }; 191 | 192 | show_error("size", input_size_string); 193 | 194 | return -1; 195 | } 196 | 197 | auto repeat = cmd.get("repeat"); 198 | 199 | // 1. print args 200 | fprintf(stdout, "--------------------------------------\n"); 201 | fprintf(stdout, "model file : %s\n", model_file.c_str()); 202 | fprintf(stdout, "image file : %s\n", image_file.c_str()); 203 | fprintf(stdout, "img_h, img_w : %d %d\n", input_size[0], input_size[1]); 204 | fprintf(stdout, "--------------------------------------\n"); 205 | 206 | // 2. read image & resize & transpose 207 | std::vector image(input_size[0] * input_size[1] * 3, 0); 208 | cv::Mat mat = cv::imread(image_file); 209 | if (mat.empty()) 210 | { 211 | fprintf(stderr, "Read image failed.\n"); 212 | return -1; 213 | } 214 | common::get_input_data_letterbox(mat, image, input_size[0], input_size[1]); 215 | 216 | // 3. sys_init 217 | AX_SYS_Init(); 218 | 219 | // 4. - engine model - can only use AX_ENGINE** inside 220 | { 221 | // AX_ENGINE_NPUReset(); // todo ?? 222 | ax::run_model(model_file, image, repeat, mat, input_size[0], input_size[1]); 223 | 224 | // 4.3 engine de init 225 | AX_ENGINE_Deinit(); 226 | // AX_ENGINE_NPUReset(); 227 | } 228 | // 4. - engine model - 229 | 230 | AX_SYS_Deinit(); 231 | return 0; 232 | } 233 | -------------------------------------------------------------------------------- /examples/ax650/ax_yolov8_obb_steps.cc: -------------------------------------------------------------------------------- 1 | /* 2 | * AXERA is pleased to support the open source community by making ax-samples available. 3 | * 4 | * Copyright (c) 2022, AXERA Semiconductor (Shanghai) Co., Ltd. All rights reserved. 5 | * 6 | * Licensed under the BSD 3-Clause License (the "License"); you may not use this file except 7 | * in compliance with the License. You may obtain a copy of the License at 8 | * 9 | * https://opensource.org/licenses/BSD-3-Clause 10 | * 11 | * Unless required by applicable law or agreed to in writing, software distributed 12 | * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 13 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the 14 | * specific language governing permissions and limitations under the License. 15 | */ 16 | 17 | /* 18 | * Author: FeiGeChuanShu 19 | */ 20 | 21 | #include 22 | #include 23 | #include 24 | 25 | #include 26 | #include "base/common.hpp" 27 | #include "base/detection.hpp" 28 | #include "middleware/io.hpp" 29 | 30 | #include "utilities/args.hpp" 31 | #include "utilities/cmdline.hpp" 32 | #include "utilities/file.hpp" 33 | #include "utilities/timer.hpp" 34 | 35 | #include 36 | #include 37 | 38 | const int DEFAULT_IMG_H = 1024; 39 | const int DEFAULT_IMG_W = 1024; 40 | 41 | static const char* CLASS_NAMES[] = { 42 | "plane", "ship", "storage tank", "baseball diamond", "tennis court", 43 | "basketball court", "ground track field", "harbor", "bridge", "large vehicle", 44 | "small vehicle", "helicopter", "roundabout", "soccer ball field", "swimming pool" 45 | }; 46 | 47 | int NUM_CLASS = 15; 48 | 49 | const int DEFAULT_LOOP_COUNT = 1; 50 | 51 | const float PROB_THRESHOLD = 0.25f; 52 | const float NMS_THRESHOLD = 0.45f; 53 | namespace ax 54 | { 55 | void post_process(AX_ENGINE_IO_INFO_T* io_info, AX_ENGINE_IO_T* io_data, const cv::Mat& mat, int input_w, int input_h, const std::vector& time_costs) 56 | { 57 | std::vector proposals; 58 | std::vector objects; 59 | timer timer_postprocess; 60 | 61 | std::vector strides = { 8, 16, 32 }; 62 | std::vector grid_strides; 63 | detection::generate_grids_and_stride(input_w, input_h, strides, grid_strides); 64 | 65 | auto feat_ptr = (float*)io_data->pOutputs[0].pVirAddr; 66 | detection::obb::generate_proposals_yolov8_obb_native(grid_strides, feat_ptr, PROB_THRESHOLD, proposals, input_w, input_h, NUM_CLASS); 67 | detection::obb::get_out_obb_bbox(proposals, objects, NMS_THRESHOLD, input_h, input_w, mat.rows, mat.cols); 68 | 69 | fprintf(stdout, "post process cost time:%.2f ms \n", timer_postprocess.cost()); 70 | fprintf(stdout, "--------------------------------------\n"); 71 | auto total_time = std::accumulate(time_costs.begin(), time_costs.end(), 0.f); 72 | auto min_max_time = std::minmax_element(time_costs.begin(), time_costs.end()); 73 | fprintf(stdout, 74 | "Repeat %d times, avg time %.2f ms, max_time %.2f ms, min_time %.2f ms\n", 75 | (int)time_costs.size(), 76 | total_time / (float)time_costs.size(), 77 | *min_max_time.second, 78 | *min_max_time.first); 79 | fprintf(stdout, "--------------------------------------\n"); 80 | fprintf(stdout, "detection num: %zu\n", objects.size()); 81 | 82 | detection::obb::draw_objects_obb(mat, objects, CLASS_NAMES, "yolov8s_obb_out", 1); 83 | } 84 | 85 | bool run_model(const std::string& model, const std::vector& data, const int& repeat, cv::Mat& mat, int input_h, int input_w) 86 | { 87 | // 1. init engine 88 | AX_ENGINE_NPU_ATTR_T npu_attr; 89 | memset(&npu_attr, 0, sizeof(npu_attr)); 90 | npu_attr.eHardMode = AX_ENGINE_VIRTUAL_NPU_DISABLE; 91 | auto ret = AX_ENGINE_Init(&npu_attr); 92 | if (0 != ret) 93 | { 94 | return ret; 95 | } 96 | 97 | // 2. load model 98 | std::vector model_buffer; 99 | if (!utilities::read_file(model, model_buffer)) 100 | { 101 | fprintf(stderr, "Read Run-Joint model(%s) file failed.\n", model.c_str()); 102 | return false; 103 | } 104 | 105 | // 3. create handle 106 | AX_ENGINE_HANDLE handle; 107 | ret = AX_ENGINE_CreateHandle(&handle, model_buffer.data(), model_buffer.size()); 108 | SAMPLE_AX_ENGINE_DEAL_HANDLE 109 | fprintf(stdout, "Engine creating handle is done.\n"); 110 | 111 | // 4. create context 112 | ret = AX_ENGINE_CreateContext(handle); 113 | SAMPLE_AX_ENGINE_DEAL_HANDLE 114 | fprintf(stdout, "Engine creating context is done.\n"); 115 | 116 | // 5. set io 117 | AX_ENGINE_IO_INFO_T* io_info; 118 | ret = AX_ENGINE_GetIOInfo(handle, &io_info); 119 | SAMPLE_AX_ENGINE_DEAL_HANDLE 120 | fprintf(stdout, "Engine get io info is done. \n"); 121 | 122 | // 6. alloc io 123 | AX_ENGINE_IO_T io_data; 124 | ret = middleware::prepare_io(io_info, &io_data, std::make_pair(AX_ENGINE_ABST_DEFAULT, AX_ENGINE_ABST_CACHED)); 125 | SAMPLE_AX_ENGINE_DEAL_HANDLE 126 | fprintf(stdout, "Engine alloc io is done. \n"); 127 | 128 | // 7. insert input 129 | ret = middleware::push_input(data, &io_data, io_info); 130 | SAMPLE_AX_ENGINE_DEAL_HANDLE_IO 131 | fprintf(stdout, "Engine push input is done. \n"); 132 | fprintf(stdout, "--------------------------------------\n"); 133 | 134 | // 8. warn up 135 | for (int i = 0; i < 5; ++i) 136 | { 137 | AX_ENGINE_RunSync(handle, &io_data); 138 | } 139 | 140 | // 9. run model 141 | std::vector time_costs(repeat, 0); 142 | for (int i = 0; i < repeat; ++i) 143 | { 144 | timer tick; 145 | ret = AX_ENGINE_RunSync(handle, &io_data); 146 | time_costs[i] = tick.cost(); 147 | SAMPLE_AX_ENGINE_DEAL_HANDLE_IO 148 | } 149 | 150 | // 10. get result 151 | post_process(io_info, &io_data, mat, input_w, input_h, time_costs); 152 | fprintf(stdout, "--------------------------------------\n"); 153 | 154 | middleware::free_io(&io_data); 155 | return AX_ENGINE_DestroyHandle(handle); 156 | } 157 | } // namespace ax 158 | 159 | int main(int argc, char* argv[]) 160 | { 161 | cmdline::parser cmd; 162 | cmd.add("model", 'm', "joint file(a.k.a. joint model)", true, ""); 163 | cmd.add("image", 'i', "image file", true, ""); 164 | cmd.add("size", 'g', "input_h, input_w", false, std::to_string(DEFAULT_IMG_H) + "," + std::to_string(DEFAULT_IMG_W)); 165 | 166 | cmd.add("repeat", 'r', "repeat count", false, DEFAULT_LOOP_COUNT); 167 | cmd.parse_check(argc, argv); 168 | 169 | // 0. get app args, can be removed from user's app 170 | auto model_file = cmd.get("model"); 171 | auto image_file = cmd.get("image"); 172 | 173 | auto model_file_flag = utilities::file_exist(model_file); 174 | auto image_file_flag = utilities::file_exist(image_file); 175 | 176 | if (!model_file_flag | !image_file_flag) 177 | { 178 | auto show_error = [](const std::string& kind, const std::string& value) { 179 | fprintf(stderr, "Input file %s(%s) is not exist, please check it.\n", kind.c_str(), value.c_str()); 180 | }; 181 | 182 | if (!model_file_flag) { show_error("model", model_file); } 183 | if (!image_file_flag) { show_error("image", image_file); } 184 | 185 | return -1; 186 | } 187 | 188 | auto input_size_string = cmd.get("size"); 189 | 190 | std::array input_size = {DEFAULT_IMG_H, DEFAULT_IMG_W}; 191 | 192 | auto input_size_flag = utilities::parse_string(input_size_string, input_size); 193 | 194 | if (!input_size_flag) 195 | { 196 | auto show_error = [](const std::string& kind, const std::string& value) { 197 | fprintf(stderr, "Input %s(%s) is not allowed, please check it.\n", kind.c_str(), value.c_str()); 198 | }; 199 | 200 | show_error("size", input_size_string); 201 | 202 | return -1; 203 | } 204 | 205 | auto repeat = cmd.get("repeat"); 206 | 207 | // 1. print args 208 | fprintf(stdout, "--------------------------------------\n"); 209 | fprintf(stdout, "model file : %s\n", model_file.c_str()); 210 | fprintf(stdout, "image file : %s\n", image_file.c_str()); 211 | fprintf(stdout, "img_h, img_w : %d %d\n", input_size[0], input_size[1]); 212 | fprintf(stdout, "--------------------------------------\n"); 213 | 214 | // 2. read image & resize & transpose 215 | std::vector image(input_size[0] * input_size[1] * 3, 0); 216 | cv::Mat mat = cv::imread(image_file); 217 | if (mat.empty()) 218 | { 219 | fprintf(stderr, "Read image failed.\n"); 220 | return -1; 221 | } 222 | common::get_input_data_letterbox(mat, image, input_size[0], input_size[1]); 223 | 224 | // 3. sys_init 225 | AX_SYS_Init(); 226 | 227 | // 4. - engine model - can only use AX_ENGINE** inside 228 | { 229 | // AX_ENGINE_NPUReset(); // todo ?? 230 | ax::run_model(model_file, image, repeat, mat, input_size[0], input_size[1]); 231 | 232 | // 4.3 engine de init 233 | AX_ENGINE_Deinit(); 234 | // AX_ENGINE_NPUReset(); 235 | } 236 | // 4. - engine model - 237 | 238 | AX_SYS_Deinit(); 239 | return 0; 240 | } 241 | -------------------------------------------------------------------------------- /examples/base/common.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * AXERA is pleased to support the open source community by making ax-samples available. 3 | * 4 | * Copyright (c) 2022, AXERA Semiconductor (Shanghai) Co., Ltd. All rights reserved. 5 | * 6 | * Licensed under the BSD 3-Clause License (the "License"); you may not use this file except 7 | * in compliance with the License. You may obtain a copy of the License at 8 | * 9 | * https://opensource.org/licenses/BSD-3-Clause 10 | * 11 | * Unless required by applicable law or agreed to in writing, software distributed 12 | * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 13 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the 14 | * specific language governing permissions and limitations under the License. 15 | */ 16 | 17 | /* 18 | * Author: ls.wang 19 | */ 20 | 21 | #pragma once 22 | 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | 30 | namespace common 31 | { 32 | // opencv mat(h, w) 33 | // resize cv::Size(dstw, dsth) 34 | void get_input_data_no_letterbox(const cv::Mat& mat, std::vector& image, int model_h, int model_w, bool bgr2rgb = false) 35 | { 36 | cv::Mat img_new(model_h, model_w, CV_8UC3, image.data()); 37 | cv::resize(mat, img_new, cv::Size(model_w, model_h)); 38 | if (bgr2rgb) 39 | { 40 | cv::cvtColor(img_new, img_new, cv::COLOR_BGR2RGB); 41 | } 42 | } 43 | 44 | void get_input_data_letterbox(cv::Mat mat, std::vector& image, int letterbox_rows, int letterbox_cols, bool bgr2rgb = false) 45 | { 46 | /* letterbox process to support different letterbox size */ 47 | float scale_letterbox; 48 | int resize_rows; 49 | int resize_cols; 50 | if ((letterbox_rows * 1.0 / mat.rows) < (letterbox_cols * 1.0 / mat.cols)) 51 | { 52 | scale_letterbox = (float)letterbox_rows * 1.0f / (float)mat.rows; 53 | } 54 | else 55 | { 56 | scale_letterbox = (float)letterbox_cols * 1.0f / (float)mat.cols; 57 | } 58 | resize_cols = int(scale_letterbox * (float)mat.cols); 59 | resize_rows = int(scale_letterbox * (float)mat.rows); 60 | 61 | cv::Mat img_new(letterbox_rows, letterbox_cols, CV_8UC3, image.data()); 62 | 63 | cv::resize(mat, mat, cv::Size(resize_cols, resize_rows)); 64 | 65 | int top = (letterbox_rows - resize_rows) / 2; 66 | int bot = (letterbox_rows - resize_rows + 1) / 2; 67 | int left = (letterbox_cols - resize_cols) / 2; 68 | int right = (letterbox_cols - resize_cols + 1) / 2; 69 | 70 | // Letterbox filling 71 | cv::copyMakeBorder(mat, img_new, top, bot, left, right, cv::BORDER_CONSTANT, cv::Scalar(0, 0, 0)); 72 | if (bgr2rgb) 73 | { 74 | cv::cvtColor(img_new, img_new, cv::COLOR_BGR2RGB); 75 | } 76 | } 77 | 78 | void get_input_data_centercrop(cv::Mat mat, std::vector& image, int model_h, int model_w, bool bgr2rgb = false) 79 | { 80 | /* letterbox process to support different letterbox size */ 81 | 82 | /* C2C BGR */ 83 | if (mat.channels() == 4) 84 | { 85 | cv::cvtColor(mat, mat, cv::COLOR_BGRA2BGR); 86 | } 87 | 88 | if (mat.channels() == 1) 89 | { 90 | cv::cvtColor(mat, mat, cv::COLOR_GRAY2BGR); 91 | } 92 | 93 | /* Center */ 94 | int h0; 95 | int w0; 96 | if (mat.rows < mat.cols) 97 | { 98 | h0 = 256; 99 | w0 = int(mat.cols * (256.0 / mat.rows)); 100 | } 101 | else 102 | { 103 | h0 = int(mat.rows * (256.0 / mat.cols)); 104 | w0 = 256; 105 | } 106 | int center_h = int(h0 / 2); 107 | int center_w = int(w0 / 2); 108 | 109 | cv::resize(mat, mat, cv::Size(w0, h0)); 110 | 111 | // cv::imwrite("center.jpg", mat); 112 | 113 | /* Crop */ 114 | cv::Rect crop_box(center_w - int(model_w / 2), center_h - int(model_h / 2), model_w, model_h); 115 | cv::Mat img_new(model_h, model_w, CV_8UC3, image.data()); 116 | 117 | cv::Mat mat_crop = mat(crop_box).clone(); 118 | 119 | // cv::imwrite("mat_crop.jpg", mat_crop); 120 | mat_crop.copyTo(img_new); 121 | 122 | // cv::imwrite("img_new.jpg", img_new); 123 | 124 | /* SwapRB*/ 125 | if (bgr2rgb) 126 | { 127 | cv::cvtColor(img_new, img_new, cv::COLOR_BGR2RGB); 128 | } 129 | } 130 | 131 | bool read_file(const char* fn, std::vector& data) 132 | { 133 | FILE* fp = fopen(fn, "r"); 134 | if (fp != nullptr) 135 | { 136 | fseek(fp, 0L, SEEK_END); 137 | auto len = ftell(fp); 138 | fseek(fp, 0, SEEK_SET); 139 | data.clear(); 140 | size_t read_size = 0; 141 | if (len > 0) 142 | { 143 | data.resize(len); 144 | read_size = fread(data.data(), 1, len, fp); 145 | } 146 | fclose(fp); 147 | return read_size == (size_t)len; 148 | } 149 | return false; 150 | } 151 | } // namespace common -------------------------------------------------------------------------------- /examples/base/score.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * AXERA is pleased to support the open source community by making ax-samples available. 3 | * 4 | * Copyright (c) 2022, AXERA Semiconductor (Shanghai) Co., Ltd. All rights reserved. 5 | * 6 | * Licensed under the BSD 3-Clause License (the "License"); you may not use this file except 7 | * in compliance with the License. You may obtain a copy of the License at 8 | * 9 | * https://opensource.org/licenses/BSD-3-Clause 10 | * 11 | * Unless required by applicable law or agreed to in writing, software distributed 12 | * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 13 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the 14 | * specific language governing permissions and limitations under the License. 15 | */ 16 | 17 | /* 18 | * Author: ls.wang 19 | */ 20 | 21 | #pragma once 22 | 23 | #include 24 | 25 | 26 | namespace classification 27 | { 28 | typedef struct 29 | { 30 | uint32_t id; 31 | float score; 32 | } score; 33 | } 34 | -------------------------------------------------------------------------------- /examples/base/topk.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * AXERA is pleased to support the open source community by making ax-samples available. 3 | * 4 | * Copyright (c) 2022, AXERA Semiconductor (Shanghai) Co., Ltd. All rights reserved. 5 | * 6 | * Licensed under the BSD 3-Clause License (the "License"); you may not use this file except 7 | * in compliance with the License. You may obtain a copy of the License at 8 | * 9 | * https://opensource.org/licenses/BSD-3-Clause 10 | * 11 | * Unless required by applicable law or agreed to in writing, software distributed 12 | * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 13 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the 14 | * specific language governing permissions and limitations under the License. 15 | */ 16 | 17 | /* 18 | * Author: ls.wang 19 | */ 20 | 21 | #pragma once 22 | 23 | #include 24 | #include 25 | #include 26 | 27 | #include "base/score.hpp" 28 | 29 | 30 | namespace classification 31 | { 32 | void sort_score(std::vector& array, bool reverse = false) 33 | { 34 | auto compare_func = [](const score& a, const score& b) -> bool 35 | { 36 | return a.score > b.score; 37 | }; 38 | 39 | std::sort(array.begin(), array.end(), compare_func); 40 | 41 | if (reverse) std::reverse(array.begin(), array.end()); 42 | } 43 | 44 | 45 | void print_score(const std::vector& array, const size_t& n) 46 | { 47 | for (size_t i = 0; i < n; i++) 48 | { 49 | fprintf(stdout, "%.4f, %d\n", array[i].score, array[i].id); 50 | } 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /examples/base/transform.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * AXERA is pleased to support the open source community by making ax-samples available. 3 | * 4 | * Copyright (c) 2022, AXERA Semiconductor (Shanghai) Co., Ltd. All rights reserved. 5 | * 6 | * Licensed under the BSD 3-Clause License (the "License"); you may not use this file except 7 | * in compliance with the License. You may obtain a copy of the License at 8 | * 9 | * https://opensource.org/licenses/BSD-3-Clause 10 | * 11 | * Unless required by applicable law or agreed to in writing, software distributed 12 | * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 13 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the 14 | * specific language governing permissions and limitations under the License. 15 | */ 16 | 17 | /* 18 | * Author: hebing 19 | */ 20 | 21 | #pragma once 22 | 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | namespace transform 30 | { 31 | static void nhwc2nchw(const float* input, float* output, int h, int w, int c) 32 | { 33 | int output_index = 0; 34 | for (int i = 0; i < c; ++i) 35 | { 36 | for (int j = 0; j < h; ++j) 37 | { 38 | for (int k = 0; k < w; ++k) 39 | { 40 | int input_index = j * w * c + k * c + i; 41 | output[output_index++] = input[input_index]; 42 | } 43 | } 44 | } 45 | } 46 | 47 | } // namespace transform 48 | -------------------------------------------------------------------------------- /examples/utilities/args.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * AXERA is pleased to support the open source community by making ax-samples available. 3 | * 4 | * Copyright (c) 2022, AXERA Semiconductor (Shanghai) Co., Ltd. All rights reserved. 5 | * 6 | * Licensed under the BSD 3-Clause License (the "License"); you may not use this file except 7 | * in compliance with the License. You may obtain a copy of the License at 8 | * 9 | * https://opensource.org/licenses/BSD-3-Clause 10 | * 11 | * Unless required by applicable law or agreed to in writing, software distributed 12 | * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 13 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the 14 | * specific language governing permissions and limitations under the License. 15 | */ 16 | 17 | /* 18 | * Author: ls.wang 19 | */ 20 | 21 | #pragma once 22 | 23 | #include 24 | #include 25 | #include 26 | 27 | #include "utilities/split.hpp" 28 | 29 | 30 | namespace utilities 31 | { 32 | template 33 | bool parse_string(const std::string& argument_string, std::array& arguments, const std::string& delimiter = ",") 34 | { 35 | std::vector result = split_string(argument_string, delimiter); 36 | 37 | if (N != result.size()) 38 | { 39 | return false; 40 | } 41 | 42 | for (size_t i = 0; i < N; i++) 43 | { 44 | if (std::is_integral::value) 45 | { 46 | arguments[i] = std::stoi(result[i]); 47 | } 48 | 49 | if (std::is_floating_point::value) 50 | { 51 | arguments[i] = std::stof(result[i]); 52 | } 53 | } 54 | 55 | return true; 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /examples/utilities/file.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * AXERA is pleased to support the open source community by making ax-samples available. 3 | * 4 | * Copyright (c) 2022, AXERA Semiconductor (Shanghai) Co., Ltd. All rights reserved. 5 | * 6 | * Licensed under the BSD 3-Clause License (the "License"); you may not use this file except 7 | * in compliance with the License. You may obtain a copy of the License at 8 | * 9 | * https://opensource.org/licenses/BSD-3-Clause 10 | * 11 | * Unless required by applicable law or agreed to in writing, software distributed 12 | * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 13 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the 14 | * specific language governing permissions and limitations under the License. 15 | */ 16 | 17 | /* 18 | * Author: ls.wang 19 | */ 20 | 21 | #pragma once 22 | 23 | #include 24 | #include 25 | #include 26 | #include 27 | 28 | namespace utilities 29 | { 30 | bool file_exist(const std::string& path) 31 | { 32 | auto flag = false; 33 | 34 | std::fstream fs(path, std::ios::in | std::ios::binary); 35 | flag = fs.is_open(); 36 | fs.close(); 37 | 38 | return flag; 39 | } 40 | 41 | bool read_file(const std::string& path, std::vector& data) 42 | { 43 | std::fstream fs(path, std::ios::in | std::ios::binary); 44 | 45 | if (!fs.is_open()) 46 | { 47 | return false; 48 | } 49 | 50 | fs.seekg(std::ios::end); 51 | auto fs_end = fs.tellg(); 52 | fs.seekg(std::ios::beg); 53 | auto fs_beg = fs.tellg(); 54 | 55 | auto file_size = static_cast(fs_end - fs_beg); 56 | auto vector_size = data.size(); 57 | 58 | data.reserve(vector_size + file_size); 59 | data.insert(data.end(), std::istreambuf_iterator(fs), std::istreambuf_iterator()); 60 | 61 | fs.close(); 62 | 63 | return true; 64 | } 65 | 66 | bool dump_file(const std::string& path, std::vector& data) 67 | { 68 | std::fstream fs(path, std::ios::out | std::ios::binary); 69 | 70 | if (!fs.is_open() || fs.fail()) 71 | { 72 | fprintf(stderr, "[ERR] cannot open file %s \n", path.c_str()); 73 | } 74 | 75 | fs.write(data.data(), data.size()); 76 | 77 | return true; 78 | } 79 | 80 | bool dump_file(const std::string& path, char* data, int size) 81 | { 82 | std::fstream fs(path, std::ios::out | std::ios::binary); 83 | 84 | if (!fs.is_open() || fs.fail()) 85 | { 86 | fprintf(stderr, "[ERR] cannot open file %s \n", path.c_str()); 87 | } 88 | 89 | fs.write(data, size); 90 | 91 | return true; 92 | } 93 | } // namespace utilities 94 | -------------------------------------------------------------------------------- /examples/utilities/split.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * AXERA is pleased to support the open source community by making ax-samples available. 3 | * 4 | * Copyright (c) 2022, AXERA Semiconductor (Shanghai) Co., Ltd. All rights reserved. 5 | * 6 | * Licensed under the BSD 3-Clause License (the "License"); you may not use this file except 7 | * in compliance with the License. You may obtain a copy of the License at 8 | * 9 | * https://opensource.org/licenses/BSD-3-Clause 10 | * 11 | * Unless required by applicable law or agreed to in writing, software distributed 12 | * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 13 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the 14 | * specific language governing permissions and limitations under the License. 15 | */ 16 | 17 | /* 18 | * Author: ls.wang 19 | */ 20 | 21 | #pragma once 22 | 23 | #include 24 | #include 25 | 26 | 27 | namespace utilities 28 | { 29 | std::vector split_string(const std::string& content, const std::string& delimiter) 30 | { 31 | std::vector result; 32 | 33 | std::string::size_type pos1 = 0; 34 | std::string::size_type pos2 = content.find(delimiter); 35 | 36 | while (std::string::npos != pos2) 37 | { 38 | result.push_back(content.substr(pos1, pos2 - pos1)); 39 | 40 | pos1 = pos2 + delimiter.size(); 41 | pos2 = content.find(delimiter, pos1); 42 | } 43 | 44 | if (pos1 != content.length()) 45 | { 46 | result.push_back(content.substr(pos1)); 47 | } 48 | 49 | return result; 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /examples/utilities/timer.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * AXERA is pleased to support the open source community by making ax-samples available. 3 | * 4 | * Copyright (c) 2022, AXERA Semiconductor (Shanghai) Co., Ltd. All rights reserved. 5 | * 6 | * Licensed under the BSD 3-Clause License (the "License"); you may not use this file except 7 | * in compliance with the License. You may obtain a copy of the License at 8 | * 9 | * https://opensource.org/licenses/BSD-3-Clause 10 | * 11 | * Unless required by applicable law or agreed to in writing, software distributed 12 | * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 13 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the 14 | * specific language governing permissions and limitations under the License. 15 | */ 16 | 17 | /* 18 | * Author: ls.wang 19 | */ 20 | 21 | #pragma once 22 | 23 | #include 24 | 25 | class timer 26 | { 27 | private: 28 | std::chrono::system_clock::time_point start_time, end_time; 29 | 30 | public: 31 | timer() 32 | { 33 | start(); 34 | } 35 | 36 | void start() 37 | { 38 | stop(); 39 | this->start_time = this->end_time; 40 | } 41 | 42 | void stop() 43 | { 44 | #ifdef _MSC_VER 45 | this->end_time = std::chrono::system_clock::now(); 46 | #else 47 | this->end_time = std::chrono::high_resolution_clock::now(); 48 | #endif 49 | } 50 | 51 | float cost() 52 | { 53 | if (this->end_time <= this->start_time) 54 | { 55 | this->stop(); 56 | } 57 | 58 | auto ms = std::chrono::duration_cast(this->end_time - this->start_time).count(); 59 | return static_cast(ms) / 1000.f; 60 | } 61 | }; 62 | -------------------------------------------------------------------------------- /toolchains/aarch64-none-linux-gnu.toolchain.cmake: -------------------------------------------------------------------------------- 1 | # set cross-compiled system type, it's better not use the type which cmake cannot recognized. 2 | SET (CMAKE_SYSTEM_NAME Linux) 3 | SET (CMAKE_SYSTEM_PROCESSOR aarch64) 4 | 5 | # aarch64-linux-gnu-gcc DO NOT need to be installed, so make sure aarch64-linux-gnu-gcc and aarch64-linux-gnu-g++ can be found in $PATH: 6 | SET (CMAKE_C_COMPILER "aarch64-none-linux-gnu-gcc") 7 | SET (CMAKE_CXX_COMPILER "aarch64-none-linux-gnu-g++") 8 | 9 | # set searching rules for cross-compiler 10 | SET (CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) 11 | SET (CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) 12 | SET (CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) 13 | -------------------------------------------------------------------------------- /toolchains/arm-AX620E-linux-uclibcgnueabihf.toolchain.cmake: -------------------------------------------------------------------------------- 1 | # set cross-compiled system type, it's better not use the type which cmake cannot recognized. 2 | SET (CMAKE_SYSTEM_NAME Linux) 3 | SET (CMAKE_SYSTEM_PROCESSOR arm) 4 | 5 | # gcc-arm-linux-gnueabi DO NOT need to be installed, so make sure arm-linux-gnueabihf-gcc and arm-linux-gnueabihf-g++ can be found in $PATH: 6 | SET (CMAKE_C_COMPILER "arm-AX620E-linux-uclibcgnueabihf-gcc") 7 | SET (CMAKE_CXX_COMPILER "arm-AX620E-linux-uclibcgnueabihf-g++") 8 | 9 | # set searching rules for cross-compiler 10 | SET (CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) 11 | SET (CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) 12 | SET (CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) 13 | -------------------------------------------------------------------------------- /toolchains/arm-linux-gnueabihf.toolchain.cmake: -------------------------------------------------------------------------------- 1 | # set cross-compiled system type, it's better not use the type which cmake cannot recognized. 2 | SET (CMAKE_SYSTEM_NAME Linux) 3 | SET (CMAKE_SYSTEM_PROCESSOR arm) 4 | 5 | # gcc-arm-linux-gnueabi DO NOT need to be installed, so make sure arm-linux-gnueabihf-gcc and arm-linux-gnueabihf-g++ can be found in $PATH: 6 | SET (CMAKE_C_COMPILER "arm-linux-gnueabihf-gcc") 7 | SET (CMAKE_CXX_COMPILER "arm-linux-gnueabihf-g++") 8 | 9 | # set searching rules for cross-compiler 10 | SET (CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) 11 | SET (CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) 12 | SET (CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) 13 | --------------------------------------------------------------------------------