📄 Awesome OCR multiple programing languages toolkits based on ONNX Runtime, OpenVINO, MNN, PaddlePaddle, TensorRT and PyTorch.
Remove invalid files.
SWHL73560a6196af
diff --git a/.github/workflows/make-linux.yml b/.github/workflows/make-linux.ymlindex 2f89288..50144ca 100644--- a/.github/workflows/make-linux.yml+++ b/.github/workflows/make-linux.yml@@ -3,7 +3,7 @@ name: CMake-linuxon:push:branches:- - main+ - developpaths:- '!python/**'- '!ocrweb/**'diff --git a/CMakeLists.txt b/CMakeLists.txtdeleted file mode 100755index 457f004..0000000--- a/CMakeLists.txt+++ /dev/null@@ -1,107 +0,0 @@-cmake_minimum_required(VERSION 3.12)-project(RapidOCR)---# Disable in-source builds to prevent source tree corruption.-if(" ${CMAKE_SOURCE_DIR}" STREQUAL " ${CMAKE_BINARY_DIR}")- message(FATAL_ERROR "-FATAL: In-source builds are not allowed.- You should create a separate directory for build files.-")-endif()---include_directories(${CMAKE_CURRENT_SOURCE_DIR}/cpp/RapidOCRCPP/include)--include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include/ /rapidocr/include)-include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include/onnxruntime/)--if(WIN32)-- add_definitions(-D_BPOCR_EXPORT_API)- IF(CMAKE_CL_64)- set(platform x64)- link_directories(${CMAKE_CURRENT_SOURCE_DIR}/lib/win/x64/)- link_directories(c:/rapidocr/onnxruntime-win-x64-1.7.0/lib)- set(OpenCV_DIR c:/rapidocr/windows-x64)-- ELSE(CMAKE_CL_64)- set(platform x86)- link_directories(${CMAKE_CURRENT_SOURCE_DIR}/lib/win/x86/)- link_directories(c:/rapidocr/onnxruntime-win-x86-1.7.0/lib)- set(OpenCV_DIR c:/rapidocr/windows-x86)-- ENDIF(CMAKE_CL_64)-- set(OpenCV_STATIC 1)--- #if(MSVC)- #add_compile_options(- #$<$<CONFIG:>:/MT> #---------|- #$<$<CONFIG:Debug>:/MTd> #---|-- Statically link the runtime libraries- #$<$<CONFIG:Release>:/MT> #--|- #)- #endif()-- # 指向下载的opencv解开后的目录,下面会有bin/lib/include等目录--elseif(UNIX)-- # set(OpenCV_DIR /path/to/opencv/build)-- link_directories(${CMAKE_CURRENT_SOURCE_DIR}/lib/linux /rapidocr/lib/)-endif()--#IF(CMAKE_BUILD_TYPE STREQUAL Debug) #debug-#-#else()-# link_libraries(opencv_world3413.lib onnxruntime.lib)-#endif()--# for onnxruntime--link_libraries(onnxruntime)--FIND_PACKAGE(OpenCV REQUIRED)-if(OPENCV_FOUND)- message("OpenCV FOUND")- include_directories(${OpenCV_INCLUDE_DIRS})- link_directories(${OpenCV_LIBRARY_DIRS})- link_libraries(${OpenCV_LIBS})--endif()--# openmp-FIND_PACKAGE( OpenMP REQUIRED)-if(OPENMP_FOUND)-message("OPENMP FOUND")-set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}")-set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}")-set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${OpenMP_EXE_LINKER_FLAGS}")-message(${CMAKE_EXE_LINKER_FLAGS})-endif()--#end of openmp--add_definitions(-D__OPENMP__)-aux_source_directory(cpp/RapidOCRCPP/src/ SRC_MAIN)-list(REMOVE_ITEM SRC_MAIN "main.cpp")---set(OCR_SRC api4cpp/rapidocr_api.cpp ${SRC_MAIN} )--add_library(rapidocrapi SHARED ${OCR_SRC})--target_compile_definitions(rapidocrapi PUBLIC -D_BPOCR_LIB)----# test program-set(BPOCRTESTSRC api4cpp/rapidocrtest.cpp)-add_executable(rapidocrtest ${BPOCRTESTSRC})---target_link_libraries(rapidocrtest onnxruntime ${OPENCV_LIB} rapidocrapi)--diff --git a/README.md b/README.mdindex c20baad..5b1d0e7 100755--- a/README.md+++ b/README.md@@ -33,14 +33,12 @@- [🤖2022-12-14 update:](#2022-12-14-update)- [🧻2022-11-20 update:](#2022-11-20-update)- [生态框架](#生态框架)- - [SDK 编译状态](#sdk-编译状态)- [在线demo](#在线demo)- [TODO](#todo)- [模型相关](#模型相关)- [各个版本ONNX模型效果对比](#各个版本onnx模型效果对比)- [文本检测模型(仅供参考)](#文本检测模型仅供参考)- [文本识别模型(仅供参考)](#文本识别模型仅供参考)- - [模型转onnx](#模型转onnx)- [原始发起者及初创作者](#原始发起者及初创作者)- [致谢](#致谢)- [赞助](#赞助)@@ -68,10 +66,14 @@- [Python范例](./python/README.md)- [rapidocr_openvino](./python/rapidocr_openvino/README.md)- [C++范例(Windows/Linux/macOS)](./cpp)+ - [RapidOcrOnnx](https://github.com/RapidAI/RapidOcrOnnx)+ - [RapidOcrNcnn](https://github.com/RapidAI/RapidOcrNcnn)- [Jvm范例(Java/Kotlin)](./jvm)-- [.Net范例(C#)](./dotnet)-- [Android范例](./android)-- 网页版范例:+ - [RapidOcrOnnxJvm](https://github.com/RapidAI/RapidOcrOnnxJvm)+ - [RapidOcrNcnnJvm](https://github.com/RapidAI/RapidOcrNcnnJvm)+- [.Net范例(C#)](./dotnet/RapidOcrOnnxCs/README.md)+- [Android范例](https://github.com/RapidAI/RapidOcrAndroidOnnx)+- 网页版范例- [网页版OCR](./ocrweb/README.md)- [多语言网页版OCR](./ocrweb_multi/README.md)- [版面结构化](./python/rapid_structure/README.md)@@ -82,6 +84,10 @@- [垂直项目](./docs/related_projects.md)- [RapidVideOCR](https://github.com/SWHL/RapidVideOCR):基于RapidOCR,提取视频中的硬字幕- [LGPMA_Infer](https://github.com/SWHL/LGPMA_Infer): 表格结构还原 | [博客解读论文和源码](http://t.csdn.cn/QNN3S)+- 模型转换+ - [PaddleOCRModelConverter](https://github.com/RapidAI/PaddleOCRModelConverter)+ - [Paddle2OnnxConvertor](https://github.com/RapidAI/Paddle2OnnxConvertor)+ - [手把手教你使用ONNXRunTime部署PP-OCR](https://aistudio.baidu.com/aistudio/projectdetail/1479970?channelType=0&channel=0)- [常见问题 FAQ](./docs/FAQ.md)@@ -113,14 +119,6 @@ flowchart LRclick B "https://github.com/PaddlePaddle/PaddleOCR" _blank```-## SDK 编译状态-鉴于ubuntu用户都是商业用户,也有编译能力,暂不提供预编译包使用,可自行编译。--| 平台 | 编译状态 | 提供状态 |-| --------------- | -------- | -------- |-| Windows x86/x64 | [](https://github.com/RapidAI/RapidOCR/actions/workflows/windows-all-build.yaml) | [下载链接](https://github.com/RapidAI/RapidOCR/releases) |-| Linux x64 | [](https://github.com/RapidAI/RapidOCR/actions/workflows/make-linux.yml) | 暂不提供,自行编译 |-## 在线demo- [自建在线demo](https://rapidai.deepdatasec.com:9003/)- **说明**: 本在线demo不存储小伙伴们上传测试的任何图像数据,详情参见:[ocrweb/README](./ocrweb/README.md)@@ -177,12 +175,6 @@ flowchart LR| ch_PP-OCRv3_rec_train_teacher.onnx | 0.0140 | 0.5381 | 0.3095 | 0.7667 | 11M |-### 模型转onnx- - [PaddleOCRModelConverter](https://github.com/RapidAI/PaddleOCRModelConverter) by @[SWHL](https://github.com/SWHL)- - [Paddle2OnnxConvertor](https://github.com/RapidAI/Paddle2OnnxConvertor) by @[benjaminwan](https://github.com/benjaminwan)- - [手把手教你使用ONNXRunTime部署PP-OCR](https://aistudio.baidu.com/aistudio/projectdetail/1479970?channelType=0&channel=0) by @[Channingss](https://github.com/Channingss)--## 原始发起者及初创作者<p align="left"><a href="https://github.com/benjaminwan"><img src="https://avatars.githubusercontent.com/u/2362051?v=4" width=65 height=65></a>@@ -211,7 +203,7 @@ flowchart LR## 授权- OCR模型版权归百度所有,其它工程代码版权归本仓库所有者所有。-- 本软件采用Apache 授权方式,欢迎大家贡献代码,提交issue 甚至pr.+- 本软件采用Apache 授权方式,欢迎大家贡献代码,提交issue 甚至PR。## 联系我们- 您可以通过QQ群联系到我们:**887298230**diff --git a/api4cpp/README.md b/api4cpp/README.mddeleted file mode 100755index d569818..0000000--- a/api4cpp/README.md+++ /dev/null@@ -1,35 +0,0 @@-It's only a wrapper for the cpp version. We give it a set of pure C interface APIs for CPP project, so that you can call the APIs in your server or client end APP.--To start, you should open the CMakeLists.txt from the root directory with Visual studio 2019 or CMAKE directly.--### About files in this directory:---rapidocr_api.cpp : the implementation of APIs---rapidocrtest.cpp : the tester---### Supported platform:--1. Windows 32/64 bits--2. Linux 64bits--3. Macos--4. IOS--5. Android--### toolchains-gcc: 4.8.5 or above--ms vs: vs2015 or higher--Onnxruntime: 1.6--opencv : 3.x--Mainly, it shoud be linked to library libopencv_imgcodecs libopencv_imgproc libopencv_corediff --git a/api4cpp/rapidocr_api.cpp b/api4cpp/rapidocr_api.cppdeleted file mode 100755index c9dcd84..0000000--- a/api4cpp/rapidocr_api.cpp+++ /dev/null@@ -1,151 +0,0 @@-#include "../include/precomp.h"-#ifdef __cplusplus-extern "C"-{-#endif-- typedef struct- {- OcrLite OcrObj;- std::string strRes;- }OCR_OBJ;-- _QM_OCR_API BPHANDLE BPOcrInit(const char* szDetModel, const char* szClsModel, const char* szRecModel,const char *szKeyPath, int nThreads)- {-- omp_set_num_threads(nThreads);- OCR_OBJ* pOcrObj=new OCR_OBJ;- if(pOcrObj)- {- pOcrObj->OcrObj.setNumThread(nThreads);-- pOcrObj->OcrObj.initModels(szDetModel, szClsModel, szRecModel, szKeyPath);-- return pOcrObj;- }- else- {- return nullptr;- }-- }--- _QM_OCR_API BOOL BPOcrDoOcr(BPHANDLE handle, const char* szImgPath, BOOL bAutoParam, BOOL bLongPic,RAPIDOCR_PARAM *pParam)- {-- OCR_OBJ* pOcrObj=(OCR_OBJ*)handle;- if(!pOcrObj)- return FALSE;-- RAPIDOCR_PARAM Param = *pParam;-- if (Param.boxScoreThresh == 0)- Param.boxScoreThresh = 0.5;- if (Param.boxThresh == 0)- Param.boxThresh = 0.3f;- if (Param.flagDoAngle == 0)- Param.flagDoAngle = 1;- if (Param.flagMostAngle == 0)- Param.flagMostAngle = 0;---- if (Param.maxSideLen == 0)- Param.maxSideLen = 1024;- if (Param.unClipRatio == 0)- Param.unClipRatio = 1.5;---- if (bAutoParam)- {-- cv::Mat oriImg = cv::imread(szImgPath);-- int nMax = oriImg.rows > oriImg.cols ? oriImg.rows : oriImg.cols;- int nMin = oriImg.rows > oriImg.cols ? oriImg.cols: oriImg.rows ;-- if (nMax > nMin * 5) // 5 times- bLongPic = true;- }--- if (bLongPic)- {-- Param.maxSideLen = 0;-- Param.unClipRatio = 3.0;- }---- // -numThread %NUMBER_OF_PROCESSORS% ^- // --padding 0 ^- // --maxSideLen %MAX_SIDE_LEN% ^- // --boxScoreThresh 0.5 ^- // --boxThresh 0.3 ^- // --unClipRatio %CLIP_RATE% ^- // --doAngle 1 ^- // --mostAngle 0------- std::string imgPath,imgDir,imgName;- imgPath=szImgPath;- imgDir=imgPath.substr(0, imgPath.find_last_of('\\') + 1);- imgName =imgPath.substr(imgPath.find_last_of('\\') + 1);- OcrResult result=pOcrObj->OcrObj.detect(imgDir.c_str(),imgName.c_str(),Param.padding,Param.maxSideLen,Param.boxScoreThresh,Param.boxThresh,Param.unClipRatio,Param.flagDoAngle?true:false,Param.flagMostAngle?true:false);- if (result.strRes.length() > 0)- {-- pOcrObj->strRes = result.strRes;- return TRUE;- }- else- return FALSE;- }--- _QM_OCR_API int BPOcrGetLen(BPHANDLE handle)- {- OCR_OBJ* pOcrObj = (OCR_OBJ*)handle;- if (!pOcrObj)- return 0;- return pOcrObj->strRes.size()+1;- }-- _QM_OCR_API BOOL BPOcrGetResult(BPHANDLE handle, char* szBuf, int nLen)- {-- OCR_OBJ* pOcrObj = (OCR_OBJ*)handle;- if (!pOcrObj)- return FALSE;-- if (nLen > pOcrObj->strRes.size())- {- strncpy(szBuf, pOcrObj->strRes.c_str(), pOcrObj->strRes.size());- szBuf[pOcrObj->strRes.size() - 1] = 0;- }-- return pOcrObj->strRes.size();- }-- _QM_OCR_API void BPOcrDeinit(BPHANDLE handle)- {-- OCR_OBJ* pOcrObj=(OCR_OBJ*)handle;- if(pOcrObj)- delete pOcrObj;--- }---#ifdef __cplusplus-}-#endifdiff --git a/api4cpp/rapidocrtest.cpp b/api4cpp/rapidocrtest.cppdeleted file mode 100755index e0b24b7..0000000--- a/api4cpp/rapidocrtest.cpp+++ /dev/null@@ -1,99 +0,0 @@-#include <stdlib.h>-#include <stdio.h>-#include <iostream>-#include <memory.h>-#include <string>-#include "../include/rapidocr_api.h"--#define BPOCR_DET_MODEL "ch_ppocr_mobile_v2.0_det_infer.onnx"-#define BPOCR_CLS_MODEL "ch_ppocr_mobile_v2.0_cls_infer.onnx"-#define BPOCR_REC_MODEL "ch_ppocr_mobile_v2.0_rec_infer.onnx"-#define BPOCR_KEY_PATH "ppocr_keys_v1.txt"--#define THREAD_NUM 3-#define MAX_PATH 260-#ifdef WIN32--const char* DEFAULT_MODEL_DIR = "E:\\bai-piao-ocr\\cpp\\BaiPiaoOcrOnnx\\models\\";--const char* DEFAULT_TEST_IMG = "E:\\bai-piao-ocr\\cpp\\BaiPiaoOcrOnnx\\images\\long1.jpg";-#else-const char * DEFAULT_MODEL_DIR ="/data/workprj/RapidOCR/models/";--const char * DEFAULT_TEST_IMG ="/data/workprj/RapidOCR/images/1.jpg";-#endif-int main(int argc, char * argv[])-{---#ifndef NDEBUG-//debug---#endif--const char *szModelDir=NULL;-const char *szImagePath=NULL;-- if(argc == 1)- {- szModelDir=DEFAULT_MODEL_DIR;- szImagePath=DEFAULT_TEST_IMG;- }- else- {- szModelDir=argv[1];- szImagePath = argv[2];- }-- char szDetModelPath[MAX_PATH]={0};- char szClsModelPath[MAX_PATH]={0};- char szRecModelPath[MAX_PATH]={0};- char szKeylPath[MAX_PATH]={0};-- strcpy(szDetModelPath,szModelDir);- strcpy(szClsModelPath,szModelDir);- strcpy(szRecModelPath,szModelDir);- strcpy(szKeylPath,szModelDir);-- strcat(szDetModelPath,BPOCR_DET_MODEL);- strcat(szClsModelPath,BPOCR_CLS_MODEL);- strcat(szRecModelPath,BPOCR_REC_MODEL);- strcat(szKeylPath,BPOCR_KEY_PATH);-- BPHANDLE Handle= BPOcrInit(szDetModelPath,szClsModelPath,szRecModelPath,szKeylPath,THREAD_NUM);- if(!Handle)- {- printf("cannot initialize the OCR Engine.\n");- return -1;- }-- RAPIDOCR_PARAM Param={0};- BOOL bRet =BPOcrDoOcr(Handle,szImagePath,true,false,&Param);- if (bRet)- {- int nLen = BPOcrGetLen(Handle);- if (nLen > 0)- {- char* szInfo =(char* )malloc(nLen);- if (szInfo)- {- if (BPOcrGetResult(Handle, szInfo, nLen))- {- printf(szInfo);- }-- free(szInfo);- }--- }- }-- if(Handle)- {- BPOcrDeinit(Handle);- }-- return 0;-}diff --git a/docs/README_en.md b/docs/README_en.mdindex 49ebbee..7424e61 100644--- a/docs/README_en.md+++ b/docs/README_en.md@@ -31,12 +31,10 @@- [🤖2022-12-14 update:](#2022-12-14-update)- [🧻2022-11-20 update:](#2022-11-20-update)- [Overall Framework](#overall-framework)- - [SDK compilation status](#sdk-compilation-status)- [Demo](#demo)- [TODO](#todo)- [Model related](#model-related)- [Download models(Baidu NetDisk | Google Drive)](#download-modelsbaidu-netdisk--google-drive)- - [Model to onnx](#model-to-onnx)- [Compared](#compared)- [Text Det](#text-det)- [Text Recognition](#text-recognition)@@ -65,9 +63,13 @@- [Python demo](../python/README.md)- [rapidocr_openvino](../python/rapidocr_openvino/README.md)- [C++ demo(Windows/Linux/macOS)](../cpp)+ - [RapidOcrOnnx](https://github.com/RapidAI/RapidOcrOnnx)+ - [RapidOcrNcnn](https://github.com/RapidAI/RapidOcrNcnn)- [Jvm demo(Java/Kotlin)](../jvm)+ - [RapidOcrOnnxJvm](https://github.com/RapidAI/RapidOcrOnnxJvm)+ - [RapidOcrNcnnJvm](https://github.com/RapidAI/RapidOcrNcnnJvm)- [.Net demo(C#)](../dotnet)-- [Android demo](../android)+- [Android demo](https://github.com/RapidAI/RapidOcrAndroidOnnx)- Web demo:- [Web OCR](../ocrweb/README.md)- [Multi Web OCR](../ocrweb_multi/README.md)@@ -79,6 +81,10 @@- [Related projects](../docs/related_projects.md)- [RapidVideOCR](https://github.com/SWHL/RapidVideOCR): Extract hard subtitles in videos based on RapidOCR- [LGPMA_Infer](https://github.com/SWHL/LGPMA_Infer): table structure restoration | [blog interpretation papers and source code](http://t.csdn.cn/QNN3S)+- Model Convert+ - [PaddleOCRModelConverter](https://github.com/RapidAI/PaddleOCRModelConverter)+ - [Paddle2OnnxConvertor](https://github.com/RapidAI/Paddle2OnnxConvertor)+ - [Teach you to use ONNXRunTime to deploy PP-OCR](https://aistudio.baidu.com/aistudio/projectdetail/1479970?channelType=0&channel=0)- [FAQ](../docs/FAQ.md)## Recently updates([more](./change_log_en.md))@@ -108,14 +114,6 @@ flowchart LRclick B "https://github.com/PaddlePaddle/PaddleOCR" _blank```-## SDK compilation status-Since ubuntu users are all commercial users and have the ability to compile, pre-compiled packages are not provided for the time being, and they can be compiled by themselves.--| Platform | Compilation Status | Offer Status |-| --------------- | -------- | -------- |-| Windows x86/x64 | [](https://github.com/RapidAI/RapidOCR/actions/workflows/windows-all-build.yaml) | [Download Link](https://github.com/RapidAI/RapidOCR/releases) |-| Linux x64 | [](https://github.com/RapidAI/RapidOCR/actions/workflows/make-linux.yml) | Not available yet, compile by yourself |-## Demo- [Online demo](https://rapidai.deepdatasec.com:9003/)- If the demo fails, you can visit the demo on Hugging Face: [RapidOCRDemo](https://huggingface.co/spaces/SWHL/RapidOCRDemo)@@ -144,10 +142,6 @@ Since ubuntu users are all commercial users and have the ability to compile, pre## Model related#### Download models([Baidu NetDisk](https://pan.baidu.com/s/1mkirNltJS481In4g81jP3w?pwd=zy37) | [Google Drive](https://drive.google.com/drive/folders/1x_a9KpCo_1blxH1xFOfgKVkw1HYRVywY?usp=sharing))-#### Model to onnx- - [PaddleOCRModelConverter](https://github.com/RapidAI/PaddleOCRModelConverter) by @[SWHL](https://github.com/SWHL)- - [Paddle2OnnxConvertor](https://github.com/RapidAI/Paddle2OnnxConvertor) by @[benjaminwan](https://github.com/benjaminwan)- - [Teach you to use ONNXRunTime to deploy PP-OCR](https://aistudio.baidu.com/aistudio/projectdetail/1479970?channelType=0&channel=0) by @[Channingss](https://github.com/Channingss)### Compared#### Text Detdiff --git a/include/onnxruntime/cpu_provider_factory.h b/include/onnxruntime/cpu_provider_factory.hdeleted file mode 100755index 66f2589..0000000--- a/include/onnxruntime/cpu_provider_factory.h+++ /dev/null@@ -1,18 +0,0 @@-// Copyright (c) Microsoft Corporation. All rights reserved.-// Licensed under the MIT License.--#include "onnxruntime_c_api.h"--#ifdef __cplusplus-extern "C" {-#endif--/**- * \param use_arena zero: false. non-zero: true.- */-ORT_API_STATUS(OrtSessionOptionsAppendExecutionProvider_CPU, _In_ OrtSessionOptions* options, int use_arena)-ORT_ALL_ARGS_NONNULL;--#ifdef __cplusplus-}-#endifdiff --git a/include/onnxruntime/cuda_provider_factory.h b/include/onnxruntime/cuda_provider_factory.hdeleted file mode 100755index 81b5477..0000000--- a/include/onnxruntime/cuda_provider_factory.h+++ /dev/null@@ -1,17 +0,0 @@-// Copyright (c) Microsoft Corporation. All rights reserved.-// Licensed under the MIT License.--#include "onnxruntime_c_api.h"--#ifdef __cplusplus-extern "C" {-#endif--/**- * \param device_id cuda device id, starts from zero.- */-ORT_API_STATUS(OrtSessionOptionsAppendExecutionProvider_CUDA, _In_ OrtSessionOptions* options, int device_id);--#ifdef __cplusplus-}-#endifdiff --git a/include/onnxruntime/onnxruntime_c_api.h b/include/onnxruntime/onnxruntime_c_api.hdeleted file mode 100755index 262e388..0000000--- a/include/onnxruntime/onnxruntime_c_api.h+++ /dev/null@@ -1,1181 +0,0 @@-// Copyright (c) Microsoft Corporation. All rights reserved.-// Licensed under the MIT License.--#pragma once-#include <stdlib.h>-#include <stdint.h>-#include <string.h>--// This value is used in structures passed to ORT so that a newer version of ORT will still work with them-#define ORT_API_VERSION 6--#ifdef __cplusplus-extern "C" {-#endif--// SAL2 Definitions-#ifndef _WIN32-#define _In_-#define _In_z_-#define _In_opt_-#define _In_opt_z_-#define _Out_-#define _Outptr_-#define _Out_opt_-#define _Inout_-#define _Inout_opt_-#define _Frees_ptr_opt_-#define _Ret_maybenull_-#define _Ret_notnull_-#define _Check_return_-#define _Outptr_result_maybenull_-#define _In_reads_(X)-#define _Inout_updates_all_(X)-#define _Out_writes_bytes_all_(X)-#define _Out_writes_all_(X)-#define _Success_(X)-#define _Outptr_result_buffer_maybenull_(X)-#define ORT_ALL_ARGS_NONNULL __attribute__((nonnull))-#else-#include <specstrings.h>-#define ORT_ALL_ARGS_NONNULL-#endif--#ifdef _WIN32-// Define ORT_DLL_IMPORT if your program is dynamically linked to Ort.-// dllexport is not used, we use a .def file.-#ifdef ORT_DLL_IMPORT-#define ORT_EXPORT __declspec(dllimport)-#else-#define ORT_EXPORT-#endif-#define ORT_API_CALL _stdcall-#define ORT_MUST_USE_RESULT-#define ORTCHAR_T wchar_t-#else-#define ORT_EXPORT-#define ORT_API_CALL-#define ORT_MUST_USE_RESULT __attribute__((warn_unused_result))-#define ORTCHAR_T char-#endif--#ifndef ORT_TSTR-#ifdef _WIN32-#define ORT_TSTR(X) L##X-#else-#define ORT_TSTR(X) X-#endif-#endif--// Any pointer marked with _In_ or _Out_, cannot be NULL.--// Windows users should use unicode paths when possible to bypass the MAX_PATH limitation-// Every pointer marked with _In_ or _Out_, cannot be NULL. Caller should ensure that.-// for ReleaseXXX(...) functions, they can accept NULL pointer.--#ifdef __cplusplus-// For any compiler with C++11 support, MSVC 2015 and greater, or Clang version supporting noexcept.-// Such complex condition is needed because compilers set __cplusplus value differently.-#ifndef __has_feature-#define __has_feature(x) 0-#endif-#if ((__cplusplus >= 201103L) || (_MSC_VER >= 1900) || (defined(__has_feature) && __has_feature(cxx_noexcept)))-#define NO_EXCEPTION noexcept-#else-#define NO_EXCEPTION throw()-#endif-#else-#define NO_EXCEPTION-#endif--// Copied from TensorProto::DataType-// Currently, Ort doesn't support complex64, complex128-typedef enum ONNXTensorElementDataType {- ONNX_TENSOR_ELEMENT_DATA_TYPE_UNDEFINED,- ONNX_TENSOR_ELEMENT_DATA_TYPE_FLOAT, // maps to c type float- ONNX_TENSOR_ELEMENT_DATA_TYPE_UINT8, // maps to c type uint8_t- ONNX_TENSOR_ELEMENT_DATA_TYPE_INT8, // maps to c type int8_t- ONNX_TENSOR_ELEMENT_DATA_TYPE_UINT16, // maps to c type uint16_t- ONNX_TENSOR_ELEMENT_DATA_TYPE_INT16, // maps to c type int16_t- ONNX_TENSOR_ELEMENT_DATA_TYPE_INT32, // maps to c type int32_t- ONNX_TENSOR_ELEMENT_DATA_TYPE_INT64, // maps to c type int64_t- ONNX_TENSOR_ELEMENT_DATA_TYPE_STRING, // maps to c++ type std::string- ONNX_TENSOR_ELEMENT_DATA_TYPE_BOOL,- ONNX_TENSOR_ELEMENT_DATA_TYPE_FLOAT16,- ONNX_TENSOR_ELEMENT_DATA_TYPE_DOUBLE, // maps to c type double- ONNX_TENSOR_ELEMENT_DATA_TYPE_UINT32, // maps to c type uint32_t- ONNX_TENSOR_ELEMENT_DATA_TYPE_UINT64, // maps to c type uint64_t- ONNX_TENSOR_ELEMENT_DATA_TYPE_COMPLEX64, // complex with float32 real and imaginary components- ONNX_TENSOR_ELEMENT_DATA_TYPE_COMPLEX128, // complex with float64 real and imaginary components- ONNX_TENSOR_ELEMENT_DATA_TYPE_BFLOAT16 // Non-IEEE floating-point format based on IEEE754 single-precision-} ONNXTensorElementDataType;--// Synced with onnx TypeProto oneof-typedef enum ONNXType {- ONNX_TYPE_UNKNOWN,- ONNX_TYPE_TENSOR,- ONNX_TYPE_SEQUENCE,- ONNX_TYPE_MAP,- ONNX_TYPE_OPAQUE,- ONNX_TYPE_SPARSETENSOR,-} ONNXType;--typedef enum OrtLoggingLevel {- ORT_LOGGING_LEVEL_VERBOSE,- ORT_LOGGING_LEVEL_INFO,- ORT_LOGGING_LEVEL_WARNING,- ORT_LOGGING_LEVEL_ERROR,- ORT_LOGGING_LEVEL_FATAL,-} OrtLoggingLevel;--typedef enum OrtErrorCode {- ORT_OK,- ORT_FAIL,- ORT_INVALID_ARGUMENT,- ORT_NO_SUCHFILE,- ORT_NO_MODEL,- ORT_ENGINE_ERROR,- ORT_RUNTIME_EXCEPTION,- ORT_INVALID_PROTOBUF,- ORT_MODEL_LOADED,- ORT_NOT_IMPLEMENTED,- ORT_INVALID_GRAPH,- ORT_EP_FAIL,-} OrtErrorCode;--#define ORT_RUNTIME_CLASS(X) \- struct Ort##X; \- typedef struct Ort##X Ort##X;--// The actual types defined have an Ort prefix-ORT_RUNTIME_CLASS(Env);-ORT_RUNTIME_CLASS(Status); // nullptr for Status* indicates success-ORT_RUNTIME_CLASS(MemoryInfo);-ORT_RUNTIME_CLASS(IoBinding);-ORT_RUNTIME_CLASS(Session); //Don't call OrtReleaseSession from Dllmain (because session owns a thread pool)-ORT_RUNTIME_CLASS(Value);-ORT_RUNTIME_CLASS(RunOptions);-ORT_RUNTIME_CLASS(TypeInfo);-ORT_RUNTIME_CLASS(TensorTypeAndShapeInfo);-ORT_RUNTIME_CLASS(SessionOptions);-ORT_RUNTIME_CLASS(CustomOpDomain);-ORT_RUNTIME_CLASS(MapTypeInfo);-ORT_RUNTIME_CLASS(SequenceTypeInfo);-ORT_RUNTIME_CLASS(ModelMetadata);-ORT_RUNTIME_CLASS(ThreadPoolParams);-ORT_RUNTIME_CLASS(ThreadingOptions);-ORT_RUNTIME_CLASS(ArenaCfg);--#ifdef _WIN32-typedef _Return_type_success_(return == 0) OrtStatus* OrtStatusPtr;-#else-typedef OrtStatus* OrtStatusPtr;-#endif--// __VA_ARGS__ on Windows and Linux are different-#define ORT_API(RETURN_TYPE, NAME, ...) ORT_EXPORT RETURN_TYPE ORT_API_CALL NAME(__VA_ARGS__) NO_EXCEPTION--#define ORT_API_STATUS(NAME, ...) \- ORT_EXPORT _Check_return_ _Ret_maybenull_ OrtStatusPtr ORT_API_CALL NAME(__VA_ARGS__) NO_EXCEPTION ORT_MUST_USE_RESULT--// XXX: Unfortunately, SAL annotations are known to not work with function pointers-#define ORT_API2_STATUS(NAME, ...) \- _Check_return_ _Ret_maybenull_ OrtStatusPtr(ORT_API_CALL* NAME)(__VA_ARGS__) NO_EXCEPTION ORT_MUST_USE_RESULT--// Used in *.cc files. Almost as same as ORT_API_STATUS, except without ORT_MUST_USE_RESULT and ORT_EXPORT-#define ORT_API_STATUS_IMPL(NAME, ...) \- _Check_return_ _Ret_maybenull_ OrtStatusPtr ORT_API_CALL NAME(__VA_ARGS__) NO_EXCEPTION--#define ORT_CLASS_RELEASE(X) void(ORT_API_CALL * Release##X)(_Frees_ptr_opt_ Ort##X * input)--// When passing in an allocator to any ORT function, be sure that the allocator object-// is not destroyed until the last allocated object using it is freed.-typedef struct OrtAllocator {- uint32_t version; // Initialize to ORT_API_VERSION- void*(ORT_API_CALL* Alloc)(struct OrtAllocator* this_, size_t size);- void(ORT_API_CALL* Free)(struct OrtAllocator* this_, void* p);- const struct OrtMemoryInfo*(ORT_API_CALL* Info)(const struct OrtAllocator* this_);-} OrtAllocator;--typedef void(ORT_API_CALL* OrtLoggingFunction)(- void* param, OrtLoggingLevel severity, const char* category, const char* logid, const char* code_location,- const char* message);--// Set Graph optimization level.-// Refer https://github.com/microsoft/onnxruntime/blob/master/docs/ONNX_Runtime_Graph_Optimizations.md-// for in-depth undersrtanding of Graph Optimizations in ORT-typedef enum GraphOptimizationLevel {- ORT_DISABLE_ALL = 0,- ORT_ENABLE_BASIC = 1,- ORT_ENABLE_EXTENDED = 2,- ORT_ENABLE_ALL = 99-} GraphOptimizationLevel;--typedef enum ExecutionMode {- ORT_SEQUENTIAL = 0,- ORT_PARALLEL = 1,-} ExecutionMode;--// Set the language projection, default is C, which means it will classify the language not in the list to C also.-typedef enum OrtLanguageProjection {- ORT_PROJECTION_C = 0, // default- ORT_PROJECTION_CPLUSPLUS = 1,- ORT_PROJECTION_CSHARP = 2,- ORT_PROJECTION_PYTHON = 3,- ORT_PROJECTION_JAVA = 4,- ORT_PROJECTION_WINML = 5,- ORT_PROJECTION_NODEJS = 6,-} OrtLanguageProjection;--struct OrtKernelInfo;-typedef struct OrtKernelInfo OrtKernelInfo;-struct OrtKernelContext;-typedef struct OrtKernelContext OrtKernelContext;-struct OrtCustomOp;-typedef struct OrtCustomOp OrtCustomOp;--typedef enum OrtAllocatorType {- Invalid = -1,- OrtDeviceAllocator = 0,- OrtArenaAllocator = 1-} OrtAllocatorType;--/**- * memory types for allocator, exec provider specific types should be extended in each provider- * Whenever this struct is updated, please also update the MakeKey function in onnxruntime/core/framework/execution_provider.cc-*/-typedef enum OrtMemType {- OrtMemTypeCPUInput = -2, // Any CPU memory used by non-CPU execution provider- OrtMemTypeCPUOutput = -1, // CPU accessible memory outputted by non-CPU execution provider, i.e. CUDA_PINNED- OrtMemTypeCPU = OrtMemTypeCPUOutput, // temporary CPU accessible memory allocated by non-CPU execution provider, i.e. CUDA_PINNED- OrtMemTypeDefault = 0, // the default allocator for execution provider-} OrtMemType;--typedef enum OrtCudnnConvAlgoSearch {- EXHAUSTIVE, // expensive exhaustive benchmarking using cudnnFindConvolutionForwardAlgorithmEx- HEURISTIC, // lightweight heuristic based search using cudnnGetConvolutionForwardAlgorithm_v7- DEFAULT, // default algorithm using CUDNN_CONVOLUTION_FWD_ALGO_IMPLICIT_PRECOMP_GEMM-} OrtCudnnConvAlgoSearch;--/// <summary>-/// Options for the CUDA provider that are passed to SessionOptionsAppendExecutionProvider_CUDA-/// </summary>-typedef struct OrtCUDAProviderOptions {- int device_id; // cuda device with id=0 as default device.- OrtCudnnConvAlgoSearch cudnn_conv_algo_search; // cudnn conv algo search option- size_t cuda_mem_limit; // default cuda memory limitation to maximum finite value of size_t.- int arena_extend_strategy; // default area extend strategy to KNextPowerOfTwo.- int do_copy_in_default_stream;-} OrtCUDAProviderOptions;--/// <summary>-/// Options for the OpenVINO provider that are passed to SessionOptionsAppendExecutionProvider_OpenVINO-/// </summary>-typedef struct OrtOpenVINOProviderOptions {-#ifdef __cplusplus- OrtOpenVINOProviderOptions() : device_type{}, enable_vpu_fast_compile{}, device_id{}, num_of_threads{} {}-#endif- const char* device_type; // CPU_FP32, GPU_FP32, GPU_FP16, MYRIAD_FP16, VAD-M_FP16 or VAD-F_FP32- unsigned char enable_vpu_fast_compile; // 0 = false, nonzero = true- const char* device_id;- size_t num_of_threads; // 0 uses default number of threads-} OrtOpenVINOProviderOptions;--struct OrtApi;-typedef struct OrtApi OrtApi;--struct OrtApiBase {- const OrtApi*(ORT_API_CALL* GetApi)(uint32_t version)NO_EXCEPTION; // Pass in ORT_API_VERSION- // nullptr will be returned if the version is unsupported, for example when using a runtime older than this header file-- const char*(ORT_API_CALL* GetVersionString)() NO_EXCEPTION;-};-typedef struct OrtApiBase OrtApiBase;--ORT_EXPORT const OrtApiBase* ORT_API_CALL OrtGetApiBase(void) NO_EXCEPTION;--struct OrtApi {- /**-* \param msg A null-terminated string. Its content will be copied into the newly created OrtStatus-*/- OrtStatus*(ORT_API_CALL* CreateStatus)(OrtErrorCode code, _In_ const char* msg)NO_EXCEPTION ORT_ALL_ARGS_NONNULL;-- OrtErrorCode(ORT_API_CALL* GetErrorCode)(_In_ const OrtStatus* status) NO_EXCEPTION ORT_ALL_ARGS_NONNULL;-- /**- * \param status must not be NULL- * \return The error message inside the `status`. Do not free the returned value.- */- const char*(ORT_API_CALL* GetErrorMessage)(_In_ const OrtStatus* status)NO_EXCEPTION ORT_ALL_ARGS_NONNULL;-- /**- * \param out Should be freed by `OrtReleaseEnv` after use- */- ORT_API2_STATUS(CreateEnv, OrtLoggingLevel logging_level, _In_ const char* logid, _Outptr_ OrtEnv** out);-- /**- * \param out Should be freed by `OrtReleaseEnv` after use- */- ORT_API2_STATUS(CreateEnvWithCustomLogger, OrtLoggingFunction logging_function, _In_opt_ void* logger_param,- OrtLoggingLevel logging_level, _In_ const char* logid, _Outptr_ OrtEnv** out);-- // Platform telemetry events are on by default since they are lightweight. You can manually turn them off.- ORT_API2_STATUS(EnableTelemetryEvents, _In_ const OrtEnv* env);- ORT_API2_STATUS(DisableTelemetryEvents, _In_ const OrtEnv* env);-- // TODO: document the path separator convention? '/' vs '\'- // TODO: should specify the access characteristics of model_path. Is this read only during the- // execution of CreateSession, or does the OrtSession retain a handle to the file/directory- // and continue to access throughout the OrtSession lifetime?- // What sort of access is needed to model_path : read or read/write?- ORT_API2_STATUS(CreateSession, _In_ const OrtEnv* env, _In_ const ORTCHAR_T* model_path,- _In_ const OrtSessionOptions* options, _Outptr_ OrtSession** out);-- ORT_API2_STATUS(CreateSessionFromArray, _In_ const OrtEnv* env, _In_ const void* model_data, size_t model_data_length,- _In_ const OrtSessionOptions* options, _Outptr_ OrtSession** out);-- ORT_API2_STATUS(Run, _Inout_ OrtSession* sess, _In_opt_ const OrtRunOptions* run_options,- _In_reads_(input_len) const char* const* input_names,- _In_reads_(input_len) const OrtValue* const* input, size_t input_len,- _In_reads_(output_names_len) const char* const* output_names1, size_t output_names_len,- _Inout_updates_all_(output_names_len) OrtValue** output);-- /**- * \return A pointer of the newly created object. The pointer should be freed by OrtReleaseSessionOptions after use- */- ORT_API2_STATUS(CreateSessionOptions, _Outptr_ OrtSessionOptions** options);-- // Set filepath to save optimized model after graph level transformations.- ORT_API2_STATUS(SetOptimizedModelFilePath, _Inout_ OrtSessionOptions* options,- _In_ const ORTCHAR_T* optimized_model_filepath);-- // create a copy of an existing OrtSessionOptions- ORT_API2_STATUS(CloneSessionOptions, _In_ const OrtSessionOptions* in_options,- _Outptr_ OrtSessionOptions** out_options);-- // Controls whether you want to execute operators in your graph sequentially or in parallel. Usually when the model- // has many branches, setting this option to ExecutionMode.ORT_PARALLEL will give you better performance.- // See [docs/ONNX_Runtime_Perf_Tuning.md] for more details.- ORT_API2_STATUS(SetSessionExecutionMode, _Inout_ OrtSessionOptions* options, ExecutionMode execution_mode);-- // Enable profiling for this session.- ORT_API2_STATUS(EnableProfiling, _Inout_ OrtSessionOptions* options, _In_ const ORTCHAR_T* profile_file_prefix);- ORT_API2_STATUS(DisableProfiling, _Inout_ OrtSessionOptions* options);-- // Enable the memory pattern optimization.- // The idea is if the input shapes are the same, we could trace the internal memory allocation- // and generate a memory pattern for future request. So next time we could just do one allocation- // with a big chunk for all the internal memory allocation.- // Note: memory pattern optimization is only available when SequentialExecution enabled.- ORT_API2_STATUS(EnableMemPattern, _Inout_ OrtSessionOptions* options);- ORT_API2_STATUS(DisableMemPattern, _Inout_ OrtSessionOptions* options);-- // Enable the memory arena on CPU- // Arena may pre-allocate memory for future usage.- // set this option to false if you don't want it.- ORT_API2_STATUS(EnableCpuMemArena, _Inout_ OrtSessionOptions* options);- ORT_API2_STATUS(DisableCpuMemArena, _Inout_ OrtSessionOptions* options);-- // < logger id to use for session output- ORT_API2_STATUS(SetSessionLogId, _Inout_ OrtSessionOptions* options, const char* logid);-- // < applies to session load, initialization, etc- ORT_API2_STATUS(SetSessionLogVerbosityLevel, _Inout_ OrtSessionOptions* options, int session_log_verbosity_level);- ORT_API2_STATUS(SetSessionLogSeverityLevel, _Inout_ OrtSessionOptions* options, int session_log_severity_level);-- ORT_API2_STATUS(SetSessionGraphOptimizationLevel, _Inout_ OrtSessionOptions* options,- GraphOptimizationLevel graph_optimization_level);-- // Sets the number of threads used to parallelize the execution within nodes- // A value of 0 means ORT will pick a default- // Note: If you've built ORT with OpenMP, this API has no effect on the number of threads used. In this case- // use the OpenMP env variables to configure the number of intra op num threads.- ORT_API2_STATUS(SetIntraOpNumThreads, _Inout_ OrtSessionOptions* options, int intra_op_num_threads);-- // Sets the number of threads used to parallelize the execution of the graph (across nodes)- // If sequential execution is enabled this value is ignored- // A value of 0 means ORT will pick a default- ORT_API2_STATUS(SetInterOpNumThreads, _Inout_ OrtSessionOptions* options, int inter_op_num_threads);-- /*- Create a custom op domain. After all sessions using it are released, call OrtReleaseCustomOpDomain- */- ORT_API2_STATUS(CreateCustomOpDomain, _In_ const char* domain, _Outptr_ OrtCustomOpDomain** out);-- /*- * Add custom ops to the OrtCustomOpDomain- * Note: The OrtCustomOp* pointer must remain valid until the OrtCustomOpDomain using it is released- */- ORT_API2_STATUS(CustomOpDomain_Add, _Inout_ OrtCustomOpDomain* custom_op_domain, _In_ const OrtCustomOp* op);-- /*- * Add a custom op domain to the OrtSessionOptions- * Note: The OrtCustomOpDomain* must not be deleted until the sessions using it are released- */- ORT_API2_STATUS(AddCustomOpDomain, _Inout_ OrtSessionOptions* options, _In_ OrtCustomOpDomain* custom_op_domain);-- /*- * Loads a DLL named 'library_path' and looks for this entry point:- * OrtStatus* RegisterCustomOps(OrtSessionOptions * options, const OrtApiBase* api);- * It then passes in the provided session options to this function along with the api base.- * The handle to the loaded library is returned in library_handle. It can be freed by the caller after all sessions using the passed in- * session options are destroyed, or if an error occurs and it is non null.- */- ORT_API2_STATUS(RegisterCustomOpsLibrary, _Inout_ OrtSessionOptions* options, _In_ const char* library_path,- void** library_handle);-- /**- * To use additional providers, you must build ORT with the extra providers enabled. Then call one of these- * functions to enable them in the session:- * OrtSessionOptionsAppendExecutionProvider_CPU- * OrtSessionOptionsAppendExecutionProvider_CUDA- * OrtSessionOptionsAppendExecutionProvider_<remaining providers...>- * The order they are called indicates the preference order as well. In other words call this method- * on your most preferred execution provider first followed by the less preferred ones.- * If none are called Ort will use its internal CPU execution provider.- */-- ORT_API2_STATUS(SessionGetInputCount, _In_ const OrtSession* sess, _Out_ size_t* out);- ORT_API2_STATUS(SessionGetOutputCount, _In_ const OrtSession* sess, _Out_ size_t* out);- ORT_API2_STATUS(SessionGetOverridableInitializerCount, _In_ const OrtSession* sess, _Out_ size_t* out);-- /**- * \param out should be freed by OrtReleaseTypeInfo after use- */- ORT_API2_STATUS(SessionGetInputTypeInfo, _In_ const OrtSession* sess, size_t index, _Outptr_ OrtTypeInfo** type_info);-- /**- * \param out should be freed by OrtReleaseTypeInfo after use- */- ORT_API2_STATUS(SessionGetOutputTypeInfo, _In_ const OrtSession* sess, size_t index,- _Outptr_ OrtTypeInfo** type_info);-- /**- * \param out should be freed by OrtReleaseTypeInfo after use- */- ORT_API2_STATUS(SessionGetOverridableInitializerTypeInfo, _In_ const OrtSession* sess, size_t index,- _Outptr_ OrtTypeInfo** type_info);-- /**- * \param value is set to a null terminated string allocated using 'allocator'. The caller is responsible for freeing it.- */- ORT_API2_STATUS(SessionGetInputName, _In_ const OrtSession* sess, size_t index, _Inout_ OrtAllocator* allocator,- _Outptr_ char** value);- ORT_API2_STATUS(SessionGetOutputName, _In_ const OrtSession* sess, size_t index, _Inout_ OrtAllocator* allocator,- _Outptr_ char** value);- ORT_API2_STATUS(SessionGetOverridableInitializerName, _In_ const OrtSession* sess, size_t index,- _Inout_ OrtAllocator* allocator, _Outptr_ char** value);-- /**- * \return A pointer to the newly created object. The pointer should be freed by OrtReleaseRunOptions after use- */- ORT_API2_STATUS(CreateRunOptions, _Outptr_ OrtRunOptions** out);-- ORT_API2_STATUS(RunOptionsSetRunLogVerbosityLevel, _Inout_ OrtRunOptions* options, int value);- ORT_API2_STATUS(RunOptionsSetRunLogSeverityLevel, _Inout_ OrtRunOptions* options, int value);- ORT_API2_STATUS(RunOptionsSetRunTag, _Inout_ OrtRunOptions*, _In_ const char* run_tag);-- ORT_API2_STATUS(RunOptionsGetRunLogVerbosityLevel, _In_ const OrtRunOptions* options, _Out_ int* out);- ORT_API2_STATUS(RunOptionsGetRunLogSeverityLevel, _In_ const OrtRunOptions* options, _Out_ int* out);- ORT_API2_STATUS(RunOptionsGetRunTag, _In_ const OrtRunOptions*, _Out_ const char** out);-- // Set a flag so that ALL incomplete OrtRun calls that are using this instance of OrtRunOptions- // will exit as soon as possible.- ORT_API2_STATUS(RunOptionsSetTerminate, _Inout_ OrtRunOptions* options);- // Unset the terminate flag to enable this OrtRunOptions instance being used in new OrtRun calls.- ORT_API2_STATUS(RunOptionsUnsetTerminate, _Inout_ OrtRunOptions* options);-- /**- * Create a tensor from an allocator. OrtReleaseValue will also release the buffer inside the output value- * \param out Should be freed by calling OrtReleaseValue- * \param type must be one of TENSOR_ELEMENT_DATA_TYPE_xxxx- */- ORT_API2_STATUS(CreateTensorAsOrtValue, _Inout_ OrtAllocator* allocator, _In_ const int64_t* shape, size_t shape_len,- ONNXTensorElementDataType type, _Outptr_ OrtValue** out);-- /**- * Create a tensor with user's buffer. You can fill the buffer either before calling this function or after.- * p_data is owned by caller. OrtReleaseValue won't release p_data.- * \param out Should be freed by calling OrtReleaseValue- */- ORT_API2_STATUS(CreateTensorWithDataAsOrtValue, _In_ const OrtMemoryInfo* info, _Inout_ void* p_data,- size_t p_data_len, _In_ const int64_t* shape, size_t shape_len, ONNXTensorElementDataType type,- _Outptr_ OrtValue** out);-- /**- * \Sets *out to 1 iff an OrtValue is a tensor, 0 otherwise- */- ORT_API2_STATUS(IsTensor, _In_ const OrtValue* value, _Out_ int* out);-- // This function doesn't work with string tensor- // this is a no-copy method whose pointer is only valid until the backing OrtValue is free'd.- ORT_API2_STATUS(GetTensorMutableData, _Inout_ OrtValue* value, _Outptr_ void** out);-- /**- * \param value A tensor created from OrtCreateTensor... function.- * \param s each A string array. Each string in this array must be null terminated.- * \param s_len length of s- */- ORT_API2_STATUS(FillStringTensor, _Inout_ OrtValue* value, _In_ const char* const* s, size_t s_len);-- /**- * \param value A tensor created from OrtCreateTensor... function.- * \param len total data length, not including the trailing '\0' chars.- */- ORT_API2_STATUS(GetStringTensorDataLength, _In_ const OrtValue* value, _Out_ size_t* len);-- /**- * \param s string contents. Each string is NOT null-terminated.- * \param value A tensor created from OrtCreateTensor... function.- * \param s_len total data length, get it from OrtGetStringTensorDataLength- */- ORT_API2_STATUS(GetStringTensorContent, _In_ const OrtValue* value, _Out_writes_bytes_all_(s_len) void* s,- size_t s_len, _Out_writes_all_(offsets_len) size_t* offsets, size_t offsets_len);-- /**- * Don't free the 'out' value- */- ORT_API2_STATUS(CastTypeInfoToTensorInfo, _In_ const OrtTypeInfo*,- _Outptr_result_maybenull_ const OrtTensorTypeAndShapeInfo** out);-- /**- * Return OnnxType from OrtTypeInfo- */- ORT_API2_STATUS(GetOnnxTypeFromTypeInfo, _In_ const OrtTypeInfo*, _Out_ enum ONNXType* out);-- /**- * The 'out' value should be released by calling OrtReleaseTensorTypeAndShapeInfo- */- ORT_API2_STATUS(CreateTensorTypeAndShapeInfo, _Outptr_ OrtTensorTypeAndShapeInfo** out);-- ORT_API2_STATUS(SetTensorElementType, _Inout_ OrtTensorTypeAndShapeInfo*, enum ONNXTensorElementDataType type);-- /**- * \param info Created from CreateTensorTypeAndShapeInfo() function- * \param dim_values An array with length of `dim_count`. Its elements can contain negative values.- * \param dim_count length of dim_values- */- ORT_API2_STATUS(SetDimensions, OrtTensorTypeAndShapeInfo* info, _In_ const int64_t* dim_values, size_t dim_count);-- ORT_API2_STATUS(GetTensorElementType, _In_ const OrtTensorTypeAndShapeInfo*,- _Out_ enum ONNXTensorElementDataType* out);- ORT_API2_STATUS(GetDimensionsCount, _In_ const OrtTensorTypeAndShapeInfo* info, _Out_ size_t* out);- ORT_API2_STATUS(GetDimensions, _In_ const OrtTensorTypeAndShapeInfo* info, _Out_ int64_t* dim_values,- size_t dim_values_length);- ORT_API2_STATUS(GetSymbolicDimensions, _In_ const OrtTensorTypeAndShapeInfo* info,- _Out_writes_all_(dim_params_length) const char* dim_params[], size_t dim_params_length);-- /**- * Return the number of elements specified by the tensor shape.- * Return a negative value if unknown (i.e., any dimension is negative.)- * e.g.- * [] -> 1- * [1,3,4] -> 12- * [2,0,4] -> 0- * [-1,3,4] -> -1- */- ORT_API2_STATUS(GetTensorShapeElementCount, _In_ const OrtTensorTypeAndShapeInfo* info, _Out_ size_t* out);-- /**- * \param out Should be freed by OrtReleaseTensorTypeAndShapeInfo after use- */- ORT_API2_STATUS(GetTensorTypeAndShape, _In_ const OrtValue* value, _Outptr_ OrtTensorTypeAndShapeInfo** out);-- /**- * Get the type information of an OrtValue- * \param value- * \param out The returned value should be freed by OrtReleaseTypeInfo after use- */- ORT_API2_STATUS(GetTypeInfo, _In_ const OrtValue* value, _Outptr_result_maybenull_ OrtTypeInfo** out);-- ORT_API2_STATUS(GetValueType, _In_ const OrtValue* value, _Out_ enum ONNXType* out);-- ORT_API2_STATUS(CreateMemoryInfo, _In_ const char* name1, enum OrtAllocatorType type, int id1,- enum OrtMemType mem_type1, _Outptr_ OrtMemoryInfo** out);-- /**- * Convenience function for special case of CreateMemoryInfo, for the CPU allocator. Uses name = "Cpu" and id = 0.- */- ORT_API2_STATUS(CreateCpuMemoryInfo, enum OrtAllocatorType type, enum OrtMemType mem_type1,- _Outptr_ OrtMemoryInfo** out);-- /**- * Test if two memory info are equal- * \Sets 'out' to 0 if equal, -1 if not equal- */- ORT_API2_STATUS(CompareMemoryInfo, _In_ const OrtMemoryInfo* info1, _In_ const OrtMemoryInfo* info2, _Out_ int* out);-- /**- * Do not free the returned value- */- ORT_API2_STATUS(MemoryInfoGetName, _In_ const OrtMemoryInfo* ptr, _Out_ const char** out);- ORT_API2_STATUS(MemoryInfoGetId, _In_ const OrtMemoryInfo* ptr, _Out_ int* out);- ORT_API2_STATUS(MemoryInfoGetMemType, _In_ const OrtMemoryInfo* ptr, _Out_ OrtMemType* out);- ORT_API2_STATUS(MemoryInfoGetType, _In_ const OrtMemoryInfo* ptr, _Out_ OrtAllocatorType* out);-- ORT_API2_STATUS(AllocatorAlloc, _Inout_ OrtAllocator* ptr, size_t size, _Outptr_ void** out);- ORT_API2_STATUS(AllocatorFree, _Inout_ OrtAllocator* ptr, void* p);- ORT_API2_STATUS(AllocatorGetInfo, _In_ const OrtAllocator* ptr, _Outptr_ const struct OrtMemoryInfo** out);-- // The returned pointer doesn't have to be freed.- // Always returns the same instance on every invocation.- // Please note that this is a non-arena based allocator.- ORT_API2_STATUS(GetAllocatorWithDefaultOptions, _Outptr_ OrtAllocator** out);-- // Override symbolic dimensions (by specific denotation strings) with actual values if known at session initialization time to enable- // optimizations that can take advantage of fixed values (such as memory planning, etc)- ORT_API2_STATUS(AddFreeDimensionOverride, _Inout_ OrtSessionOptions* options, _In_ const char* dim_denotation,- _In_ int64_t dim_value);-- /**- * APIs to support non-tensor types - map and sequence.- * Currently only the following types are supported- * Note: the following types should be kept in sync with data_types.h- * Map types- * =========- * std::map<std::string, std::string>- * std::map<std::string, int64_t>- * std::map<std::string, float>- * std::map<std::string, double>- * std::map<int64_t, std::string>- * std::map<int64_t, int64_t>- * std::map<int64_t, float>- * std::map<int64_t, double>- *- * Sequence types- * ==============- * std::vector<std::string>- * std::vector<int64_t>- * std::vector<float>- * std::vector<double>- * std::vector<std::map<std::string, float>>- * std::vector<std::map<int64_t, float>- */-- /**- * If input OrtValue represents a map, you need to retrieve the keys and values- * separately. Use index=0 to retrieve keys and index=1 to retrieve values.- * If input OrtValue represents a sequence, use index to retrieve the index'th element- * of the sequence.- */- ORT_API2_STATUS(GetValue, _In_ const OrtValue* value, int index, _Inout_ OrtAllocator* allocator,- _Outptr_ OrtValue** out);-- /**- * Returns 2 for type map and N for sequence where N is the number of elements- * in the sequence.- */- ORT_API2_STATUS(GetValueCount, _In_ const OrtValue* value, _Out_ size_t* out);-- /**- * To construct a map, use num_values = 2 and 'in' should be an arrary of 2 OrtValues- * representing keys and values.- * To construct a sequence, use num_values = N where N is the number of the elements in the- * sequence. 'in' should be an arrary of N OrtValues.- * \value_type should be either map or sequence.- */- ORT_API2_STATUS(CreateValue, _In_reads_(num_values) const OrtValue* const* in, size_t num_values,- enum ONNXType value_type, _Outptr_ OrtValue** out);-- /**- * Construct OrtValue that contains a value of non-standard type created for- * experiments or while awaiting standardization. OrtValue in this case would contain- * an internal representation of the Opaque type. Opaque types are distinguished between- * each other by two strings 1) domain and 2) type name. The combination of the two- * must be unique, so the type representation is properly identified internally. The combination- * must be properly registered from within ORT at both compile/run time or by another API.- *- * To construct the OrtValue pass domain and type names, also a pointer to a data container- * the type of which must be know to both ORT and the client program. That data container may or may- * not match the internal representation of the Opaque type. The sizeof(data_container) is passed for- * verification purposes.- *- * \domain_name - domain name for the Opaque type, null terminated.- * \type_name - type name for the Opaque type, null terminated.- * \data_contianer - data to populate OrtValue- * \data_container_size - sizeof() of the data container. Must match the sizeof() of the expected- * data_container size internally.- */- ORT_API2_STATUS(CreateOpaqueValue, _In_z_ const char* domain_name, _In_z_ const char* type_name,- _In_ const void* data_container, size_t data_container_size, _Outptr_ OrtValue** out);-- /**- * Fetch data from an OrtValue that contains a value of non-standard type created for- * experiments or while awaiting standardization.- * \domain_name - domain name for the Opaque type, null terminated.- * \type_name - type name for the Opaque type, null terminated.- * \data_contianer - data to populate OrtValue- * \data_container_size - sizeof() of the data container. Must match the sizeof() of the expected- * data_container size internally.- */-- ORT_API2_STATUS(GetOpaqueValue, _In_ const char* domain_name, _In_ const char* type_name, _In_ const OrtValue* in,- _Out_ void* data_container, size_t data_container_size);-- ORT_API2_STATUS(KernelInfoGetAttribute_float, _In_ const OrtKernelInfo* info, _In_ const char* name,- _Out_ float* out);- ORT_API2_STATUS(KernelInfoGetAttribute_int64, _In_ const OrtKernelInfo* info, _In_ const char* name,- _Out_ int64_t* out);- ORT_API2_STATUS(KernelInfoGetAttribute_string, _In_ const OrtKernelInfo* info, _In_ const char* name, _Out_ char* out,- _Inout_ size_t* size);-- ORT_API2_STATUS(KernelContext_GetInputCount, _In_ const OrtKernelContext* context, _Out_ size_t* out);- ORT_API2_STATUS(KernelContext_GetOutputCount, _In_ const OrtKernelContext* context, _Out_ size_t* out);- ORT_API2_STATUS(KernelContext_GetInput, _In_ const OrtKernelContext* context, _In_ size_t index,- _Out_ const OrtValue** out);- ORT_API2_STATUS(KernelContext_GetOutput, _Inout_ OrtKernelContext* context, _In_ size_t index,- _In_ const int64_t* dim_values, size_t dim_count, _Outptr_ OrtValue** out);-- ORT_CLASS_RELEASE(Env);- ORT_CLASS_RELEASE(Status); // nullptr for Status* indicates success- ORT_CLASS_RELEASE(MemoryInfo);- ORT_CLASS_RELEASE(Session); //Don't call OrtReleaseSession from Dllmain (because session owns a thread pool)- ORT_CLASS_RELEASE(Value);- ORT_CLASS_RELEASE(RunOptions);- ORT_CLASS_RELEASE(TypeInfo);- ORT_CLASS_RELEASE(TensorTypeAndShapeInfo);- ORT_CLASS_RELEASE(SessionOptions);- ORT_CLASS_RELEASE(CustomOpDomain);-- // End of Version 1 - DO NOT MODIFY ABOVE (see above text for more information)-- // Version 2 - In development, feel free to add/remove/rearrange here-- /**- * GetDenotationFromTypeInfo- * This api augments OrtTypeInfo to return denotations on the type.- * This is used by WinML to determine if an input/output is intended to be an Image or a Tensor.- */- ORT_API2_STATUS(GetDenotationFromTypeInfo, _In_ const OrtTypeInfo*, _Out_ const char** const denotation,- _Out_ size_t* len);-- // OrtTypeInfo Casting methods-- /**- * CastTypeInfoToMapTypeInfo- * This api augments OrtTypeInfo to return an OrtMapTypeInfo when the type is a map.- * The OrtMapTypeInfo has additional information about the map's key type and value type.- * This is used by WinML to support model reflection APIs.- * This is used by WinML to support model reflection APIs.- *- * Don't free the 'out' value- */- ORT_API2_STATUS(CastTypeInfoToMapTypeInfo, _In_ const OrtTypeInfo* type_info,- _Outptr_result_maybenull_ const OrtMapTypeInfo** out);-- /**- * CastTypeInfoToSequenceTypeInfo- * This api augments OrtTypeInfo to return an OrtSequenceTypeInfo when the type is a sequence.- * The OrtSequenceTypeInfo has additional information about the sequence's element type.- * This is used by WinML to support model reflection APIs.- *- * Don't free the 'out' value- */- ORT_API2_STATUS(CastTypeInfoToSequenceTypeInfo, _In_ const OrtTypeInfo* type_info,- _Outptr_result_maybenull_ const OrtSequenceTypeInfo** out);-- // OrtMapTypeInfo Accessors-- /**- * GetMapKeyType- * This api augments get the key type of a map. Key types are restricted to being scalar types and use ONNXTensorElementDataType.- * This is used by WinML to support model reflection APIs.- */- ORT_API2_STATUS(GetMapKeyType, _In_ const OrtMapTypeInfo* map_type_info, _Out_ enum ONNXTensorElementDataType* out);-- /**- * GetMapValueType- * This api augments get the value type of a map.- */- ORT_API2_STATUS(GetMapValueType, _In_ const OrtMapTypeInfo* map_type_info, _Outptr_ OrtTypeInfo** type_info);-- // OrtSequenceTypeInfo Accessors-- /**- * GetSequenceElementType- * This api augments get the element type of a sequence.- * This is used by WinML to support model reflection APIs.- */- ORT_API2_STATUS(GetSequenceElementType, _In_ const OrtSequenceTypeInfo* sequence_type_info,- _Outptr_ OrtTypeInfo** type_info);-- ORT_CLASS_RELEASE(MapTypeInfo);- ORT_CLASS_RELEASE(SequenceTypeInfo);-- /**- * \param out is set to a null terminated string allocated using 'allocator'. The caller is responsible for freeing it.- * Profiling is turned ON automatically if enabled for the particular session by invoking EnableProfiling()- * on the SessionOptions instance used to create the session.- */- ORT_API2_STATUS(SessionEndProfiling, _In_ OrtSession* sess, _Inout_ OrtAllocator* allocator, _Outptr_ char** out);-- /**- * \param out is a pointer to the newly created object. The pointer should be freed by calling ReleaseModelMetadata after use.- */- ORT_API2_STATUS(SessionGetModelMetadata, _In_ const OrtSession* sess, _Outptr_ OrtModelMetadata** out);-- /**- * \param value is set to a null terminated string allocated using 'allocator'. The caller is responsible for freeing it.- */- ORT_API2_STATUS(ModelMetadataGetProducerName, _In_ const OrtModelMetadata* model_metadata,- _Inout_ OrtAllocator* allocator, _Outptr_ char** value);- ORT_API2_STATUS(ModelMetadataGetGraphName, _In_ const OrtModelMetadata* model_metadata,- _Inout_ OrtAllocator* allocator, _Outptr_ char** value);- ORT_API2_STATUS(ModelMetadataGetDomain, _In_ const OrtModelMetadata* model_metadata, _Inout_ OrtAllocator* allocator,- _Outptr_ char** value);- ORT_API2_STATUS(ModelMetadataGetDescription, _In_ const OrtModelMetadata* model_metadata,- _Inout_ OrtAllocator* allocator, _Outptr_ char** value);- /**- * \param value is set to a null terminated string allocated using 'allocator'. The caller is responsible for freeing it.- * 'value' will be a nullptr if the given key is not found in the custom metadata map.- */- ORT_API2_STATUS(ModelMetadataLookupCustomMetadataMap, _In_ const OrtModelMetadata* model_metadata,- _Inout_ OrtAllocator* allocator, _In_ const char* key, _Outptr_result_maybenull_ char** value);-- ORT_API2_STATUS(ModelMetadataGetVersion, _In_ const OrtModelMetadata* model_metadata, _Out_ int64_t* value);-- ORT_CLASS_RELEASE(ModelMetadata);-- /*- * Creates an environment with global threadpools that will be shared across sessions.- * Use this in conjunction with DisablePerSessionThreads API or else the session will use- * its own thread pools.- */- ORT_API2_STATUS(CreateEnvWithGlobalThreadPools, OrtLoggingLevel logging_level, _In_ const char* logid,- _In_ const OrtThreadingOptions* t_options, _Outptr_ OrtEnv** out);-- /*- * Calling this API will make the session use the global threadpools shared across sessions.- * This API should be used in conjunction with CreateEnvWithGlobalThreadPools API.- */- ORT_API2_STATUS(DisablePerSessionThreads, _Inout_ OrtSessionOptions* options);-- ORT_API2_STATUS(CreateThreadingOptions, _Outptr_ OrtThreadingOptions** out);-- ORT_CLASS_RELEASE(ThreadingOptions);-- /**- * \param num_keys contains the number of keys in the custom metadata map- * \param keys is an array of null terminated strings (array count = num_keys) allocated using 'allocator'.- * The caller is responsible for freeing each string and the pointer array.- * 'keys' will be a nullptr if custom metadata map is empty.- */- ORT_API2_STATUS(ModelMetadataGetCustomMetadataMapKeys, _In_ const OrtModelMetadata* model_metadata,- _Inout_ OrtAllocator* allocator, _Outptr_result_buffer_maybenull_(*num_keys) char*** keys, _Out_ int64_t* num_keys);-- // Override symbolic dimensions (by specific name strings) with actual values- // if known at session initialization time to enable optimizations that can- // take advantage of fixed values (such as memory planning, etc)- ORT_API2_STATUS(AddFreeDimensionOverrideByName,- _Inout_ OrtSessionOptions* options, _In_ const char* dim_name,- _In_ int64_t dim_value);-- /**- * \param out_ptr will hold a pointer to the array of char *- * representing available providers.- * \param provider_length is a pointer to an int variable where- * the number of available providers will be added.- * The caller is responsible for freeing each char * and the pointer- * array by calling ReleaseAvailableProviders().- */- ORT_API2_STATUS(GetAvailableProviders, _Outptr_ char*** out_ptr,- _In_ int* provider_length);-- /**- * \param ptr is the pointer to an array of available providers you- * get after calling GetAvailableProviders().- * \param providers_length is the number of available providers.- */- ORT_API2_STATUS(ReleaseAvailableProviders, _In_ char** ptr,- _In_ int providers_length);-- /**- * \param value - A tensor created from OrtCreateTensor... function.- * \param index - index of string tensor element, length of element at index will be returned.- * \param out - number of UTF-8 bytes that the string contains- */- ORT_API2_STATUS(GetStringTensorElementLength, _In_ const OrtValue* value, size_t index, _Out_ size_t* out);-- /**- * \param s string element contents in UTF-8 encoding. The string is NOT null-terminated.- * \param value A tensor created from OrtCreateTensor... function.- * \param s_len element length, get it from OrtGetStringTensorElementLength.- * \param index offset of element of tensor to return.- */- ORT_API2_STATUS(GetStringTensorElement, _In_ const OrtValue* value, size_t s_len, size_t index, _Out_writes_bytes_all_(s_len) void* s);-- /**- * \param value - A tensor created from OrtCreateTensor... function.- * \param s - A null terminated UTF-8 encoded string.- * \param index - index of string tensor element to fill- */- ORT_API2_STATUS(FillStringTensorElement, _Inout_ OrtValue* value, _In_ const char* s, size_t index);-- /**- * Set a single session configuration entry as a pair of strings- * If a configuration with same key exists, this will overwrite the configuration with the given config_value- * \param config_key A null terminated string representation of the config key- * \param config_value A null terminated string representation of the config value- * The config_key and the format of config_value are defined in onnxruntime_session_options_config_keys.h- */- ORT_API2_STATUS(AddSessionConfigEntry, _Inout_ OrtSessionOptions* options,- _In_z_ const char* config_key, _In_z_ const char* config_value);-- /**- * \param sess valid OrtSession instance- * \param mem_info - valid OrtMemoryInfo instance- * \param - out a ptr to a new instance of OrtAllocator according to the spec within mem_info- * if successful- * \return OrtStatus or nullptr if successful- */- ORT_API2_STATUS(CreateAllocator, _In_ const OrtSession* sess, _In_ const OrtMemoryInfo* mem_info,- _Outptr_ OrtAllocator** out);-- // Release instance of OrtAllocator obtained from CreateAllocator API- ORT_CLASS_RELEASE(Allocator);-- ORT_API2_STATUS(RunWithBinding, _Inout_ OrtSession* sess, _In_opt_ const OrtRunOptions* run_options, _In_ const OrtIoBinding* binding_ptr);-- // Creates an IoBinding instance that allows one to bind pre-allocated OrtValues- // to input names. Thus if you want to use a raw on device buffer as input or output- // you can avoid extra copy during runtime.- ORT_API2_STATUS(CreateIoBinding, _Inout_ OrtSession* sess, _Outptr_ OrtIoBinding** out);-- // Release instance or OrtIoBinding obtained from CreateIoBinding API- ORT_CLASS_RELEASE(IoBinding);-- /**- * The function will bind the OrtValue to a specified input name.- * The OrtValue must be a Tensor. ORT would use that value in place of input for the specified name.- * \param binding_ptr - an instance of OrtIoBinding created by CreateIoBinding()- * \param name - name for the model input- * \param val_ptr - OrtValue of Tensor type.- * \return OrtStatus instance on error which the caller is responsible to free or nullptr on success- */- ORT_API2_STATUS(BindInput, _Inout_ OrtIoBinding* binding_ptr, _In_ const char* name, _In_ const OrtValue* val_ptr);-- /**- * The function will bind the OrtValue to the specified output name.- * The OrtValue must be a Tensor. ORT would use that value in place of output for the specified name.- *- * \param binding_ptr - an instance of OrtIoBinding created by CreateIoBinding()- * \param name - name for the model output- * \param val_ptr - OrtValue of Tensor type.- * \return OrtStatus instance on error which the caller is responsible to free or nullptr on success- */- ORT_API2_STATUS(BindOutput, _Inout_ OrtIoBinding* binding_ptr, _In_ const char* name, _In_ const OrtValue* val_ptr);-- /**- * The function will bind the OrtValue to a device which specification is contained within OrtMemoryInfo- * You can either create an instance of OrtMemoryInfo with a device id or obtain one from the allocator that you are created/using- * This is useful when one or more outputs have dynamic shapes and, it is hard to pre-allocated and bind a chunk of- * memory within OrtValue ahead of time.- *- * \param binding_ptr - an instance of OrtIoBinding created by CreateIoBinding()- * \param name - name for the model output- * \param mem_info_ptr - OrtMemoryInfo- * \return OrtStatus instance on error which the caller is responsible to free or nullptr on success- */- ORT_API2_STATUS(BindOutputToDevice, _Inout_ OrtIoBinding* binding_ptr, _In_ const char* name, _In_ const OrtMemoryInfo* val_ptr);-- /**- * The function returns the names of the outputs in the order they were bound. This is useful after running the model- * with bound outputs because the returned names are in order in which output OrtValues are returned. This API is optional- * to use. If you knew the order of outputs and its names you used for binding you would not need to use this API.- *- * \param binding_ptr - a ptr to an instance of OrtIoBinding created obtained from CreateIoBinding()- * \param allocator - a ptr to an instance of OrtAllocator obtained with CreateAllocator() or GetAllocatorWithDefaultOptions()- * the specified allocator will be used to allocate continuous buffers for output strings and lengths.- * \param buffer - pointer to a continuous buffer of non-zero terminated UTF-8 encoded strings. The number of strings stored is returned count parameter.- * this buffer will be allocated with the specified allocator and must be freed after it is no longer needed.- * \param lengths - a pointer to a continuous buffer of size_t lengths of strings returned in the buffer. The number of items is returned- * in the count. This buffer is allocated with the specified allocator and must be freed after it is no longer needed.- * \para count - is the number of strings returned. If the instance of OrtIoBiding has no bound outputs, zero is returned,- * no memory allocation is performed and buffer and lengths are nullptr on return.- */- ORT_API2_STATUS(GetBoundOutputNames, _In_ const OrtIoBinding* binding_ptr, _In_ OrtAllocator* allocator,- _Out_ char** buffer, _Out_writes_all_(count) size_t** lengths, _Out_ size_t* count);-- /**- * The function returns an array of pointers to individually allocated OrtValues that contain results of a model execution with RunWithBinding()- * The array contains the same number of OrtValues and they are in the same order as they were bound with BindOutput()- * or BindOutputToDevice().- * The returned OrtValues must be individually released after they are no longer needed.- * The array is allocated using the specified instance of the allocator and must be freed using the same allocator after- * all the OrtValues contained therein are individually released.- *- * \param binding_ptr - instance of OrtIoBidning- * \param allocator - instance of allocator to allocate output array- * \param output - pointer to the allocated buffer. Returns nullptr if no outputs.- * \param output_count - pointer to the number of OrtValues returned. Zero if no outputs.- */- ORT_API2_STATUS(GetBoundOutputValues, _In_ const OrtIoBinding* binding_ptr, _In_ OrtAllocator* allocator,- _Out_writes_all_(output_count) OrtValue*** output, _Out_ size_t* output_count);-- /** Clears any previously specified bindings for inputs/outputs- */- void(ORT_API_CALL* ClearBoundInputs)(_Inout_ OrtIoBinding* binding_ptr) NO_EXCEPTION ORT_ALL_ARGS_NONNULL;- void(ORT_API_CALL* ClearBoundOutputs)(_Inout_ OrtIoBinding* binding_ptr) NO_EXCEPTION ORT_ALL_ARGS_NONNULL;-- /**- * Provides element-level access into a tensor.- * \param location_values a pointer to an array of index values that specify an element's location in the tensor data blob- * \param location_values_count length of location_values- * \param out a pointer to the element specified by location_values- * e.g.- * Given a tensor with overall shape [3,224,224], an element at- * location [2,150,128] can be accessed directly.- *- * This function only works for numeric tensors.- * This is a no-copy method whose pointer is only valid until the backing OrtValue is free'd.- */- ORT_API2_STATUS(TensorAt, _Inout_ OrtValue* value, const int64_t* location_values, size_t location_values_count, _Outptr_ void** out);-- /**- * Creates an allocator instance and registers it with the env to enable- * sharing between multiple sessions that use the same env instance.- * Lifetime of the created allocator will be valid for the duration of the environment.- * Returns an error if an allocator with the same OrtMemoryInfo is already registered.- * \param mem_info must be non-null.- * \param arena_cfg if nullptr defaults will be used.- * See docs/C_API.md for details.- */- ORT_API2_STATUS(CreateAndRegisterAllocator, _Inout_ OrtEnv* env, _In_ const OrtMemoryInfo* mem_info,- _In_ const OrtArenaCfg* arena_cfg);-- /**- * Set the language projection for collecting telemetry data when Env is created- * \param projection the source projected language.- */- ORT_API2_STATUS(SetLanguageProjection, _In_ const OrtEnv* ort_env, _In_ OrtLanguageProjection projection);-- /**- * On some platforms, this timer may not be as precise as nanoseconds- * For instance, on Windows and MacOS, the precision will be ~100ns- * \param out is set to the nanoseconds of profiling's start time- */- ORT_API2_STATUS(SessionGetProfilingStartTimeNs, _In_ const OrtSession* sess, _Outptr_ uint64_t* out);-- /**- * Use this API to configure the global thread pool options to be used in the call to CreateEnvWithGlobalThreadPools.- * A value of 0 means ORT will pick the default.- * A value of 1 means the invoking thread will be used; no threads will be created in the thread pool.- */- ORT_API2_STATUS(SetGlobalIntraOpNumThreads, _Inout_ OrtThreadingOptions* tp_options, int intra_op_num_threads);- ORT_API2_STATUS(SetGlobalInterOpNumThreads, _Inout_ OrtThreadingOptions* tp_options, int inter_op_num_threads);-- /**- * Use this API to configure the global thread pool options to be used in the call to CreateEnvWithGlobalThreadPools.- * Allow spinning of thread pools when their queues are empty. This API will set the value for both- * inter_op and intra_op threadpools.- * \param allow_spinning valid values are 1 and 0.- * 1: threadpool will spin to wait for queue to become non-empty, 0: it won't spin.- * Prefer a value of 0 if your CPU usage is very high.- */- ORT_API2_STATUS(SetGlobalSpinControl, _Inout_ OrtThreadingOptions* tp_options, int allow_spinning);-- /**- * Add a pre-allocated initializer to a session. If a model contains an initializer with a name- * that is same as the name passed to this API call, ORT will use this initializer instance- * instead of deserializing one from the model file. This is useful when you want to share- * the same initializer across sessions.- * \param name name of the initializer- * \param val OrtValue containing the initializer. Lifetime of 'val' and the underlying initializer buffer must be- * managed by the user (created using the CreateTensorWithDataAsOrtValue API) and it must outlive the session object- * to which it is added.- */- ORT_API2_STATUS(AddInitializer, _Inout_ OrtSessionOptions* options, _In_z_ const char* name,- _In_ const OrtValue* val);-- /**- * Creates a custom environment with global threadpools and logger that will be shared across sessions.- * Use this in conjunction with DisablePerSessionThreads API or else the session will use- * its own thread pools.- *- * \param out should be freed by `OrtReleaseEnv` after use- */- ORT_API2_STATUS(CreateEnvWithCustomLoggerAndGlobalThreadPools, OrtLoggingFunction logging_function, _In_opt_ void* logger_param, OrtLoggingLevel logging_level,- _In_ const char* logid, _In_ const struct OrtThreadingOptions* tp_options, _Outptr_ OrtEnv** out);-- /**- * Append CUDA execution provider to the session options- * If CUDA is not available (due to a non cuda enabled build), this function will return failure.- */- ORT_API2_STATUS(SessionOptionsAppendExecutionProvider_CUDA,- _In_ OrtSessionOptions* options, _In_ const OrtCUDAProviderOptions* cuda_options);-- /**- * Append OpenVINO execution provider to the session options- * If OpenVINO is not available (due to the OpenVINO provider shared library or its dependencies not being installed), this function will fail.- */- ORT_API2_STATUS(SessionOptionsAppendExecutionProvider_OpenVINO,- _In_ OrtSessionOptions* options, _In_ const OrtOpenVINOProviderOptions* provider_options);-- /**- * Use this API to configure the global thread pool options to be used in the call to CreateEnvWithGlobalThreadPools.- * When this API is called, flush-to-zero and denormal-as-zero are applied to threads in both intra and inter global thread pool.- * Note that an alternative way not using this option at runtime is to train and export a model without denormals- * and that's recommended because turning this option on may hurt model accuracy.- */- ORT_API2_STATUS(SetGlobalDenormalAsZero, _Inout_ OrtThreadingOptions* tp_options);-- /**- * Use this API to create the configuration of an arena that can eventually be used to define- * an arena based allocator's behavior- * \param max_mem - use 0 to allow ORT to choose the default- * \param arena_extend_strategy - use -1 to allow ORT to choose the default, 0 = kNextPowerOfTwo, 1 = kSameAsRequested- * \param initial_chunk_size_bytes - use -1 to allow ORT to choose the default- * \param max_dead_bytes_per_chunk - use -1 to allow ORT to choose the default- * \param out - a pointer to an OrtArenaCfg instance- * \return a nullptr in case of success or a pointer to an OrtStatus instance in case of failure- * See docs/C_API.md for details on what the following parameters mean and how to choose these values- */- ORT_API2_STATUS(CreateArenaCfg, _In_ size_t max_mem, int arena_extend_strategy, int initial_chunk_size_bytes,- int max_dead_bytes_per_chunk, _Outptr_ OrtArenaCfg** out);-- ORT_CLASS_RELEASE(ArenaCfg);-};--/*- * Steps to use a custom op:- * 1 Create an OrtCustomOpDomain with the domain name used by the custom ops- * 2 Create an OrtCustomOp structure for each op and add them to the domain- * 3 Call OrtAddCustomOpDomain to add the custom domain of ops to the session options-*/-#define OrtCustomOpApi OrtApi--/*- * The OrtCustomOp structure defines a custom op's schema and its kernel callbacks. The callbacks are filled in by- * the implementor of the custom op.-*/-struct OrtCustomOp {- uint32_t version; // Initialize to ORT_API_VERSION-- // This callback creates the kernel, which is a user defined parameter that is passed to the Kernel* callbacks below.- void*(ORT_API_CALL* CreateKernel)(_In_ const struct OrtCustomOp* op, _In_ const OrtApi* api,- _In_ const OrtKernelInfo* info);-- // Returns the name of the op- const char*(ORT_API_CALL* GetName)(_In_ const struct OrtCustomOp* op);-- // Returns the type of the execution provider, return nullptr to use CPU execution provider- const char*(ORT_API_CALL* GetExecutionProviderType)(_In_ const struct OrtCustomOp* op);-- // Returns the count and types of the input & output tensors- ONNXTensorElementDataType(ORT_API_CALL* GetInputType)(_In_ const struct OrtCustomOp* op, _In_ size_t index);- size_t(ORT_API_CALL* GetInputTypeCount)(_In_ const struct OrtCustomOp* op);- ONNXTensorElementDataType(ORT_API_CALL* GetOutputType)(_In_ const struct OrtCustomOp* op, _In_ size_t index);- size_t(ORT_API_CALL* GetOutputTypeCount)(_In_ const struct OrtCustomOp* op);-- // Op kernel callbacks- void(ORT_API_CALL* KernelCompute)(_In_ void* op_kernel, _In_ OrtKernelContext* context);- void(ORT_API_CALL* KernelDestroy)(_In_ void* op_kernel);-};--/*- * END EXPERIMENTAL-*/--#ifdef __cplusplus-}-#endifdiff --git a/include/onnxruntime/onnxruntime_cxx_api.h b/include/onnxruntime/onnxruntime_cxx_api.hdeleted file mode 100755index bafd5ed..0000000--- a/include/onnxruntime/onnxruntime_cxx_api.h+++ /dev/null@@ -1,632 +0,0 @@-// Copyright (c) Microsoft Corporation. All rights reserved.-// Licensed under the MIT License.--// Summary: The Ort C++ API is a header only wrapper around the Ort C API.-//-// The C++ API simplifies usage by returning values directly instead of error codes, throwing exceptions on errors-// and automatically releasing resources in the destructors.-//-// Each of the C++ wrapper classes holds only a pointer to the C internal object. Treat them like smart pointers.-// To create an empty object, pass 'nullptr' to the constructor (for example, Env e{nullptr};).-//-// Only move assignment between objects is allowed, there are no copy constructors. Some objects have explicit 'Clone'-// methods for this purpose.--#pragma once-#include "onnxruntime_c_api.h"-#include <cstddef>-#include <array>-#include <memory>-#include <stdexcept>-#include <string>-#include <vector>-#include <utility>-#include <type_traits>--#ifdef ORT_NO_EXCEPTIONS-#include <iostream>-#endif--namespace Ort {--// All C++ methods that can fail will throw an exception of this type-struct Exception : std::exception {- Exception(std::string&& string, OrtErrorCode code) : message_{std::move(string)}, code_{code} {}-- OrtErrorCode GetOrtErrorCode() const { return code_; }- const char* what() const noexcept override { return message_.c_str(); }-- private:- std::string message_;- OrtErrorCode code_;-};--#ifdef ORT_NO_EXCEPTIONS-#define ORT_CXX_API_THROW(string, code) \- do { \- std::cerr << Ort::Exception(string, code) \- .what() \- << std::endl; \- abort(); \- } while (false)-#else-#define ORT_CXX_API_THROW(string, code) \- throw Ort::Exception(string, code)-#endif--// This is used internally by the C++ API. This class holds the global variable that points to the OrtApi, it's in a template so that we can define a global variable in a header and make-// it transparent to the users of the API.-template <typename T>-struct Global {- static const OrtApi* api_;-};--// If macro ORT_API_MANUAL_INIT is defined, no static initialization will be performed. Instead, user must call InitApi() before using it.--template <typename T>-#ifdef ORT_API_MANUAL_INIT-const OrtApi* Global<T>::api_{};-inline void InitApi() { Global<void>::api_ = OrtGetApiBase()->GetApi(ORT_API_VERSION); }-#else-const OrtApi* Global<T>::api_ = OrtGetApiBase()->GetApi(ORT_API_VERSION);-#endif--// This returns a reference to the OrtApi interface in use, in case someone wants to use the C API functions-inline const OrtApi& GetApi() { return *Global<void>::api_; }--// This is a C++ wrapper for GetAvailableProviders() C API and returns-// a vector of strings representing the available execution providers.-std::vector<std::string> GetAvailableProviders();--// This is used internally by the C++ API. This macro is to make it easy to generate overloaded methods for all of the various OrtRelease* functions for every Ort* type-// This can't be done in the C API since C doesn't have function overloading.-#define ORT_DEFINE_RELEASE(NAME) \- inline void OrtRelease(Ort##NAME* ptr) { GetApi().Release##NAME(ptr); }--ORT_DEFINE_RELEASE(Allocator);-ORT_DEFINE_RELEASE(MemoryInfo);-ORT_DEFINE_RELEASE(CustomOpDomain);-ORT_DEFINE_RELEASE(Env);-ORT_DEFINE_RELEASE(RunOptions);-ORT_DEFINE_RELEASE(Session);-ORT_DEFINE_RELEASE(SessionOptions);-ORT_DEFINE_RELEASE(TensorTypeAndShapeInfo);-ORT_DEFINE_RELEASE(SequenceTypeInfo);-ORT_DEFINE_RELEASE(MapTypeInfo);-ORT_DEFINE_RELEASE(TypeInfo);-ORT_DEFINE_RELEASE(Value);-ORT_DEFINE_RELEASE(ModelMetadata);-ORT_DEFINE_RELEASE(ThreadingOptions);-ORT_DEFINE_RELEASE(IoBinding);-ORT_DEFINE_RELEASE(ArenaCfg);--/*! \class Ort::Float16_t- * \brief it is a structure that represents float16 data.- * \details It is necessary for type dispatching to make use of C++ API- * The type is implicitly convertible to/from uint16_t.- * The size of the structure should align with uint16_t and one can freely cast- * uint16_t buffers to/from Ort::Float16_t to feed and retrieve data.- *- * Generally, you can feed any of your types as float16/blfoat16 data to create a tensor- * on top of it, providing it can form a continuous buffer with 16-bit elements with no padding.- * And you can also feed a array of uint16_t elements directly. For example,- *- * \code{.unparsed}- * uint16_t values[] = { 15360, 16384, 16896, 17408, 17664};- * constexpr size_t values_length = sizeof(values) / sizeof(values[0]);- * std::vector<int64_t> dims = {values_length}; // one dimensional example- * Ort::MemoryInfo info("Cpu", OrtDeviceAllocator, 0, OrtMemTypeDefault);- * // Note we are passing bytes count in this api, not number of elements -> sizeof(values)- * auto float16_tensor = Ort::Value::CreateTensor(info, values, sizeof(values),- * dims.data(), dims.size(), ONNX_TENSOR_ELEMENT_DATA_TYPE_FLOAT16);- * \endcode- *- * Here is another example, a little bit more elaborate. Let's assume that you use your own float16 type and you want to use- * a templated version of the API above so the type is automatically set based on your type. You will need to supply an extra- * template specialization.- *- * \code{.unparsed}- * namespace yours { struct half {}; } // assume this is your type, define this:- * namespace Ort {- * template<>- * struct TypeToTensorType<yours::half> { static constexpr ONNXTensorElementDataType type = ONNX_TENSOR_ELEMENT_DATA_TYPE_FLOAT16; };- * } //namespace Ort- *- * std::vector<yours::half> values;- * std::vector<int64_t> dims = {values.size()}; // one dimensional example- * Ort::MemoryInfo info("Cpu", OrtDeviceAllocator, 0, OrtMemTypeDefault);- * // Here we are passing element count -> values.size()- * auto float16_tensor = Ort::Value::CreateTensor<yours::half>(info, values.data(), values.size(), dims.data(), dims.size());- *- * \endcode- */-struct Float16_t {- uint16_t value;- constexpr Float16_t() noexcept : value(0) {}- constexpr Float16_t(uint16_t v) noexcept : value(v) {}- constexpr operator uint16_t() const noexcept { return value; }- constexpr bool operator==(const Float16_t& rhs) const noexcept { return value == rhs.value; };- constexpr bool operator!=(const Float16_t& rhs) const noexcept { return value != rhs.value; };-};--static_assert(sizeof(Float16_t) == sizeof(uint16_t), "Sizes must match");--/*! \class Ort::BFloat16_t- * \brief is a structure that represents bfloat16 data.- * \details It is necessary for type dispatching to make use of C++ API- * The type is implicitly convertible to/from uint16_t.- * The size of the structure should align with uint16_t and one can freely cast- * uint16_t buffers to/from Ort::BFloat16_t to feed and retrieve data.- *- * See also code examples for Float16_t above.- */-struct BFloat16_t {- uint16_t value;- constexpr BFloat16_t() noexcept : value(0) {}- constexpr BFloat16_t(uint16_t v) noexcept : value(v) {}- constexpr operator uint16_t() const noexcept { return value; }- constexpr bool operator==(const BFloat16_t& rhs) const noexcept { return value == rhs.value; };- constexpr bool operator!=(const BFloat16_t& rhs) const noexcept { return value != rhs.value; };-};--static_assert(sizeof(BFloat16_t) == sizeof(uint16_t), "Sizes must match");--// This is used internally by the C++ API. This is the common base class used by the wrapper objects.-template <typename T>-struct Base {- using contained_type = T;-- Base() = default;- Base(T* p) : p_{p} {- if (!p)- ORT_CXX_API_THROW("Allocation failure", ORT_FAIL);- }- ~Base() { OrtRelease(p_); }-- operator T*() { return p_; }- operator const T*() const { return p_; }-- T* release() {- T* p = p_;- p_ = nullptr;- return p;- }-- protected:- Base(const Base&) = delete;- Base& operator=(const Base&) = delete;- Base(Base&& v) noexcept : p_{v.p_} { v.p_ = nullptr; }- void operator=(Base&& v) noexcept {- OrtRelease(p_);- p_ = v.p_;- v.p_ = nullptr;- }-- T* p_{};-- template <typename>- friend struct Unowned; // This friend line is needed to keep the centos C++ compiler from giving an error-};--template <typename T>-struct Base<const T> {- using contained_type = const T;-- Base() = default;- Base(const T* p) : p_{p} {- if (!p)- ORT_CXX_API_THROW("Invalid instance ptr", ORT_INVALID_ARGUMENT);- }- ~Base() = default;-- operator const T*() const { return p_; }-- protected:- Base(const Base&) = delete;- Base& operator=(const Base&) = delete;- Base(Base&& v) noexcept : p_{v.p_} { v.p_ = nullptr; }- void operator=(Base&& v) noexcept {- p_ = v.p_;- v.p_ = nullptr;- }-- const T* p_{};-};--template <typename T>-struct Unowned : T {- Unowned(decltype(T::p_) p) : T{p} {}- Unowned(Unowned&& v) : T{v.p_} {}- ~Unowned() { this->release(); }-};--struct AllocatorWithDefaultOptions;-struct MemoryInfo;-struct Env;-struct TypeInfo;-struct Value;-struct ModelMetadata;--struct Env : Base<OrtEnv> {- Env(std::nullptr_t) {}- Env(OrtLoggingLevel logging_level = ORT_LOGGING_LEVEL_WARNING, _In_ const char* logid = "");- Env(const OrtThreadingOptions* tp_options, OrtLoggingLevel logging_level = ORT_LOGGING_LEVEL_WARNING, _In_ const char* logid = "");- Env(OrtLoggingLevel logging_level, const char* logid, OrtLoggingFunction logging_function, void* logger_param);- Env(const OrtThreadingOptions* tp_options, OrtLoggingFunction logging_function, void* logger_param,- OrtLoggingLevel logging_level = ORT_LOGGING_LEVEL_WARNING, _In_ const char* logid = "");- explicit Env(OrtEnv* p) : Base<OrtEnv>{p} {}-- Env& EnableTelemetryEvents();- Env& DisableTelemetryEvents();-- Env& CreateAndRegisterAllocator(const OrtMemoryInfo* mem_info, const OrtArenaCfg* arena_cfg);-- static const OrtApi* s_api;-};--struct CustomOpDomain : Base<OrtCustomOpDomain> {- explicit CustomOpDomain(std::nullptr_t) {}- explicit CustomOpDomain(const char* domain);-- void Add(OrtCustomOp* op);-};--struct RunOptions : Base<OrtRunOptions> {- RunOptions(std::nullptr_t) {}- RunOptions();-- RunOptions& SetRunLogVerbosityLevel(int);- int GetRunLogVerbosityLevel() const;-- RunOptions& SetRunLogSeverityLevel(int);- int GetRunLogSeverityLevel() const;-- RunOptions& SetRunTag(const char* run_tag);- const char* GetRunTag() const;-- // terminate ALL currently executing Session::Run calls that were made using this RunOptions instance- RunOptions& SetTerminate();- // unset the terminate flag so this RunOptions instance can be used in a new Session::Run call- RunOptions& UnsetTerminate();-};--struct SessionOptions : Base<OrtSessionOptions> {- explicit SessionOptions(std::nullptr_t) {}- SessionOptions();- explicit SessionOptions(OrtSessionOptions* p) : Base<OrtSessionOptions>{p} {}-- SessionOptions Clone() const;-- SessionOptions& SetIntraOpNumThreads(int intra_op_num_threads);- SessionOptions& SetInterOpNumThreads(int inter_op_num_threads);- SessionOptions& SetGraphOptimizationLevel(GraphOptimizationLevel graph_optimization_level);-- SessionOptions& EnableCpuMemArena();- SessionOptions& DisableCpuMemArena();-- SessionOptions& SetOptimizedModelFilePath(const ORTCHAR_T* optimized_model_file);-- SessionOptions& EnableProfiling(const ORTCHAR_T* profile_file_prefix);- SessionOptions& DisableProfiling();-- SessionOptions& EnableMemPattern();- SessionOptions& DisableMemPattern();-- SessionOptions& SetExecutionMode(ExecutionMode execution_mode);-- SessionOptions& SetLogId(const char* logid);- SessionOptions& SetLogSeverityLevel(int level);-- SessionOptions& Add(OrtCustomOpDomain* custom_op_domain);-- SessionOptions& DisablePerSessionThreads();-- SessionOptions& AddConfigEntry(const char* config_key, const char* config_value);- SessionOptions& AddInitializer(const char* name, const OrtValue* ort_val);-- SessionOptions& AppendExecutionProvider_CUDA(const OrtCUDAProviderOptions& provider_options);- SessionOptions& AppendExecutionProvider_OpenVINO(const OrtOpenVINOProviderOptions& provider_options);-};--struct ModelMetadata : Base<OrtModelMetadata> {- explicit ModelMetadata(std::nullptr_t) {}- explicit ModelMetadata(OrtModelMetadata* p) : Base<OrtModelMetadata>{p} {}-- char* GetProducerName(OrtAllocator* allocator) const;- char* GetGraphName(OrtAllocator* allocator) const;- char* GetDomain(OrtAllocator* allocator) const;- char* GetDescription(OrtAllocator* allocator) const;- char** GetCustomMetadataMapKeys(OrtAllocator* allocator, _Out_ int64_t& num_keys) const;- char* LookupCustomMetadataMap(const char* key, OrtAllocator* allocator) const;- int64_t GetVersion() const;-};--struct Session : Base<OrtSession> {- explicit Session(std::nullptr_t) {}- Session(Env& env, const ORTCHAR_T* model_path, const SessionOptions& options);- Session(Env& env, const void* model_data, size_t model_data_length, const SessionOptions& options);-- // Run that will allocate the output values- std::vector<Value> Run(const RunOptions& run_options, const char* const* input_names, const Value* input_values, size_t input_count,- const char* const* output_names, size_t output_count);- // Run for when there is a list of prealloated outputs- void Run(const RunOptions& run_options, const char* const* input_names, const Value* input_values, size_t input_count,- const char* const* output_names, Value* output_values, size_t output_count);-- void Run(const RunOptions& run_options, const struct IoBinding&);-- size_t GetInputCount() const;- size_t GetOutputCount() const;- size_t GetOverridableInitializerCount() const;-- char* GetInputName(size_t index, OrtAllocator* allocator) const;- char* GetOutputName(size_t index, OrtAllocator* allocator) const;- char* GetOverridableInitializerName(size_t index, OrtAllocator* allocator) const;- char* EndProfiling(OrtAllocator* allocator) const;- uint64_t GetProfilingStartTimeNs() const;- ModelMetadata GetModelMetadata() const;-- TypeInfo GetInputTypeInfo(size_t index) const;- TypeInfo GetOutputTypeInfo(size_t index) const;- TypeInfo GetOverridableInitializerTypeInfo(size_t index) const;-};--struct TensorTypeAndShapeInfo : Base<OrtTensorTypeAndShapeInfo> {- explicit TensorTypeAndShapeInfo(std::nullptr_t) {}- explicit TensorTypeAndShapeInfo(OrtTensorTypeAndShapeInfo* p) : Base<OrtTensorTypeAndShapeInfo>{p} {}-- ONNXTensorElementDataType GetElementType() const;- size_t GetElementCount() const;-- size_t GetDimensionsCount() const;- void GetDimensions(int64_t* values, size_t values_count) const;- void GetSymbolicDimensions(const char** values, size_t values_count) const;-- std::vector<int64_t> GetShape() const;-};--struct SequenceTypeInfo : Base<OrtSequenceTypeInfo> {- explicit SequenceTypeInfo(std::nullptr_t) {}- explicit SequenceTypeInfo(OrtSequenceTypeInfo* p) : Base<OrtSequenceTypeInfo>{p} {}-- TypeInfo GetSequenceElementType() const;-};--struct MapTypeInfo : Base<OrtMapTypeInfo> {- explicit MapTypeInfo(std::nullptr_t) {}- explicit MapTypeInfo(OrtMapTypeInfo* p) : Base<OrtMapTypeInfo>{p} {}-- ONNXTensorElementDataType GetMapKeyType() const;- TypeInfo GetMapValueType() const;-};--struct TypeInfo : Base<OrtTypeInfo> {- explicit TypeInfo(std::nullptr_t) {}- explicit TypeInfo(OrtTypeInfo* p) : Base<OrtTypeInfo>{p} {}-- Unowned<TensorTypeAndShapeInfo> GetTensorTypeAndShapeInfo() const;- Unowned<SequenceTypeInfo> GetSequenceTypeInfo() const;- Unowned<MapTypeInfo> GetMapTypeInfo() const;-- ONNXType GetONNXType() const;-};--struct Value : Base<OrtValue> {- template <typename T>- static Value CreateTensor(const OrtMemoryInfo* info, T* p_data, size_t p_data_element_count, const int64_t* shape, size_t shape_len);- static Value CreateTensor(const OrtMemoryInfo* info, void* p_data, size_t p_data_byte_count, const int64_t* shape, size_t shape_len,- ONNXTensorElementDataType type);- template <typename T>- static Value CreateTensor(OrtAllocator* allocator, const int64_t* shape, size_t shape_len);- static Value CreateTensor(OrtAllocator* allocator, const int64_t* shape, size_t shape_len, ONNXTensorElementDataType type);-- static Value CreateMap(Value& keys, Value& values);- static Value CreateSequence(std::vector<Value>& values);-- template <typename T>- static Value CreateOpaque(const char* domain, const char* type_name, const T&);-- template <typename T>- void GetOpaqueData(const char* domain, const char* type_name, T&) const;-- explicit Value(std::nullptr_t) {}- explicit Value(OrtValue* p) : Base<OrtValue>{p} {}- Value(Value&&) = default;- Value& operator=(Value&&) = default;-- bool IsTensor() const;- size_t GetCount() const; // If a non tensor, returns 2 for map and N for sequence, where N is the number of elements- Value GetValue(int index, OrtAllocator* allocator) const;-- size_t GetStringTensorDataLength() const;- void GetStringTensorContent(void* buffer, size_t buffer_length, size_t* offsets, size_t offsets_count) const;-- template <typename T>- T* GetTensorMutableData();-- template <typename T>- const T* GetTensorData() const;-- template <typename T>- T& At(const std::vector<int64_t>& location);-- TypeInfo GetTypeInfo() const;- TensorTypeAndShapeInfo GetTensorTypeAndShapeInfo() const;-- size_t GetStringTensorElementLength(size_t element_index) const;- void GetStringTensorElement(size_t buffer_length, size_t element_index, void* buffer) const;-- void FillStringTensor(const char* const* s, size_t s_len);- void FillStringTensorElement(const char* s, size_t index);-};--// Represents native memory allocation-struct MemoryAllocation {- MemoryAllocation(OrtAllocator* allocator, void* p, size_t size);- ~MemoryAllocation();- MemoryAllocation(const MemoryAllocation&) = delete;- MemoryAllocation& operator=(const MemoryAllocation&) = delete;- MemoryAllocation(MemoryAllocation&&);- MemoryAllocation& operator=(MemoryAllocation&&);-- void* get() { return p_; }- size_t size() const { return size_; }-- private:- OrtAllocator* allocator_;- void* p_;- size_t size_;-};--struct AllocatorWithDefaultOptions {- AllocatorWithDefaultOptions();-- operator OrtAllocator*() { return p_; }- operator const OrtAllocator*() const { return p_; }-- void* Alloc(size_t size);- // The return value will own the allocation- MemoryAllocation GetAllocation(size_t size);- void Free(void* p);-- const OrtMemoryInfo* GetInfo() const;-- private:- OrtAllocator* p_{};-};--template <typename B>-struct BaseMemoryInfo : B {- BaseMemoryInfo() = default;- explicit BaseMemoryInfo(typename B::contained_type* p) : B(p) {}- ~BaseMemoryInfo() = default;- BaseMemoryInfo(BaseMemoryInfo&&) = default;- BaseMemoryInfo& operator=(BaseMemoryInfo&&) = default;-- std::string GetAllocatorName() const;- OrtAllocatorType GetAllocatorType() const;- int GetDeviceId() const;- OrtMemType GetMemoryType() const;- template <typename U>- bool operator==(const BaseMemoryInfo<U>& o) const;-};--struct UnownedMemoryInfo : BaseMemoryInfo<Base<const OrtMemoryInfo> > {- explicit UnownedMemoryInfo(std::nullptr_t) {}- explicit UnownedMemoryInfo(const OrtMemoryInfo* p) : BaseMemoryInfo(p) {}-};--struct MemoryInfo : BaseMemoryInfo<Base<OrtMemoryInfo> > {- static MemoryInfo CreateCpu(OrtAllocatorType type, OrtMemType mem_type1);-- explicit MemoryInfo(std::nullptr_t) {}- explicit MemoryInfo(OrtMemoryInfo* p) : BaseMemoryInfo(p) {}- MemoryInfo(const char* name, OrtAllocatorType type, int id, OrtMemType mem_type);-};--struct Allocator : public Base<OrtAllocator> {- Allocator(const Session& session, const MemoryInfo&);-- void* Alloc(size_t size) const;- // The return value will own the allocation- MemoryAllocation GetAllocation(size_t size);- void Free(void* p) const;- UnownedMemoryInfo GetInfo() const;-};--struct IoBinding : public Base<OrtIoBinding> {- private:- std::vector<std::string> GetOutputNamesHelper(OrtAllocator*) const;- std::vector<Value> GetOutputValuesHelper(OrtAllocator*) const;-- public:- explicit IoBinding(Session& session);- void BindInput(const char* name, const Value&);- void BindOutput(const char* name, const Value&);- void BindOutput(const char* name, const MemoryInfo&);- std::vector<std::string> GetOutputNames() const;- std::vector<std::string> GetOutputNames(Allocator&) const;- std::vector<Value> GetOutputValues() const;- std::vector<Value> GetOutputValues(Allocator&) const;- void ClearBoundInputs();- void ClearBoundOutputs();-};--/*! \struct Ort::ArenaCfg- * \brief it is a structure that represents the configuration of an arena based allocator- * \details Please see docs/C_API.md for details- */-struct ArenaCfg : Base<OrtArenaCfg> {- explicit ArenaCfg(std::nullptr_t) {}- /**- * \param max_mem - use 0 to allow ORT to choose the default- * \param arena_extend_strategy - use -1 to allow ORT to choose the default, 0 = kNextPowerOfTwo, 1 = kSameAsRequested- * \param initial_chunk_size_bytes - use -1 to allow ORT to choose the default- * \param max_dead_bytes_per_chunk - use -1 to allow ORT to choose the default- * \return an instance of ArenaCfg- * See docs/C_API.md for details on what the following parameters mean and how to choose these values- */- ArenaCfg(size_t max_mem, int arena_extend_strategy, int initial_chunk_size_bytes, int max_dead_bytes_per_chunk);-};--//-// Custom OPs (only needed to implement custom OPs)-//--struct CustomOpApi {- CustomOpApi(const OrtApi& api) : api_(api) {}-- template <typename T> // T is only implemented for float, int64_t, and string- T KernelInfoGetAttribute(_In_ const OrtKernelInfo* info, _In_ const char* name);-- OrtTensorTypeAndShapeInfo* GetTensorTypeAndShape(_In_ const OrtValue* value);- size_t GetTensorShapeElementCount(_In_ const OrtTensorTypeAndShapeInfo* info);- ONNXTensorElementDataType GetTensorElementType(const OrtTensorTypeAndShapeInfo* info);- size_t GetDimensionsCount(_In_ const OrtTensorTypeAndShapeInfo* info);- void GetDimensions(_In_ const OrtTensorTypeAndShapeInfo* info, _Out_ int64_t* dim_values, size_t dim_values_length);- void SetDimensions(OrtTensorTypeAndShapeInfo* info, _In_ const int64_t* dim_values, size_t dim_count);-- template <typename T>- T* GetTensorMutableData(_Inout_ OrtValue* value);- template <typename T>- const T* GetTensorData(_Inout_ const OrtValue* value);-- std::vector<int64_t> GetTensorShape(const OrtTensorTypeAndShapeInfo* info);- void ReleaseTensorTypeAndShapeInfo(OrtTensorTypeAndShapeInfo* input);- size_t KernelContext_GetInputCount(const OrtKernelContext* context);- const OrtValue* KernelContext_GetInput(const OrtKernelContext* context, _In_ size_t index);- size_t KernelContext_GetOutputCount(const OrtKernelContext* context);- OrtValue* KernelContext_GetOutput(OrtKernelContext* context, _In_ size_t index, _In_ const int64_t* dim_values, size_t dim_count);-- void ThrowOnError(OrtStatus* result);-- private:- const OrtApi& api_;-};--template <typename TOp, typename TKernel>-struct CustomOpBase : OrtCustomOp {- CustomOpBase() {- OrtCustomOp::version = ORT_API_VERSION;- OrtCustomOp::CreateKernel = [](const OrtCustomOp* this_, const OrtApi* api, const OrtKernelInfo* info) { return static_cast<const TOp*>(this_)->CreateKernel(*api, info); };- OrtCustomOp::GetName = [](const OrtCustomOp* this_) { return static_cast<const TOp*>(this_)->GetName(); };-- OrtCustomOp::GetExecutionProviderType = [](const OrtCustomOp* this_) { return static_cast<const TOp*>(this_)->GetExecutionProviderType(); };-- OrtCustomOp::GetInputTypeCount = [](const OrtCustomOp* this_) { return static_cast<const TOp*>(this_)->GetInputTypeCount(); };- OrtCustomOp::GetInputType = [](const OrtCustomOp* this_, size_t index) { return static_cast<const TOp*>(this_)->GetInputType(index); };-- OrtCustomOp::GetOutputTypeCount = [](const OrtCustomOp* this_) { return static_cast<const TOp*>(this_)->GetOutputTypeCount(); };- OrtCustomOp::GetOutputType = [](const OrtCustomOp* this_, size_t index) { return static_cast<const TOp*>(this_)->GetOutputType(index); };-- OrtCustomOp::KernelCompute = [](void* op_kernel, OrtKernelContext* context) { static_cast<TKernel*>(op_kernel)->Compute(context); };- OrtCustomOp::KernelDestroy = [](void* op_kernel) { delete static_cast<TKernel*>(op_kernel); };- }-- // Default implementation of GetExecutionProviderType that returns nullptr to default to the CPU provider- const char* GetExecutionProviderType() const { return nullptr; }-};--} // namespace Ort--#include "onnxruntime_cxx_inline.h"diff --git a/include/onnxruntime/onnxruntime_cxx_inline.h b/include/onnxruntime/onnxruntime_cxx_inline.hdeleted file mode 100755index ee89acd..0000000--- a/include/onnxruntime/onnxruntime_cxx_inline.h+++ /dev/null@@ -1,979 +0,0 @@-// Copyright (c) Microsoft Corporation. All rights reserved.-// Licensed under the MIT License.--// Do not include this file directly. Please include "onnxruntime_cxx_api.h" instead.-// If interested in trying out features of the new experimental C++ API, include "experimental_onnxruntime_cxx_api.h" instead.-//-// These are the inline implementations of the C++ header APIs. They're in this separate file as to not clutter-// the main C++ file with implementation details.--namespace Ort {--inline void ThrowOnError(const OrtApi& ort, OrtStatus* status) {- if (status) {- std::string error_message = ort.GetErrorMessage(status);- OrtErrorCode error_code = ort.GetErrorCode(status);- ort.ReleaseStatus(status);- ORT_CXX_API_THROW(std::move(error_message), error_code);- }-}--inline void ThrowOnError(OrtStatus* status) {- ThrowOnError(GetApi(), status);-}--// This template converts a C++ type into it's ONNXTensorElementDataType-template <typename T>-struct TypeToTensorType;-template <>-struct TypeToTensorType<float> { static constexpr ONNXTensorElementDataType type = ONNX_TENSOR_ELEMENT_DATA_TYPE_FLOAT; };-template <>-struct TypeToTensorType<Float16_t> { static constexpr ONNXTensorElementDataType type = ONNX_TENSOR_ELEMENT_DATA_TYPE_FLOAT16; };-template <>-struct TypeToTensorType<BFloat16_t> { static constexpr ONNXTensorElementDataType type = ONNX_TENSOR_ELEMENT_DATA_TYPE_BFLOAT16; };-template <>-struct TypeToTensorType<double> { static constexpr ONNXTensorElementDataType type = ONNX_TENSOR_ELEMENT_DATA_TYPE_DOUBLE; };-template <>-struct TypeToTensorType<int8_t> { static constexpr ONNXTensorElementDataType type = ONNX_TENSOR_ELEMENT_DATA_TYPE_INT8; };-template <>-struct TypeToTensorType<int16_t> { static constexpr ONNXTensorElementDataType type = ONNX_TENSOR_ELEMENT_DATA_TYPE_INT16; };-template <>-struct TypeToTensorType<int32_t> { static constexpr ONNXTensorElementDataType type = ONNX_TENSOR_ELEMENT_DATA_TYPE_INT32; };-template <>-struct TypeToTensorType<int64_t> { static constexpr ONNXTensorElementDataType type = ONNX_TENSOR_ELEMENT_DATA_TYPE_INT64; };-template <>-struct TypeToTensorType<uint8_t> { static constexpr ONNXTensorElementDataType type = ONNX_TENSOR_ELEMENT_DATA_TYPE_UINT8; };-template <>-struct TypeToTensorType<uint16_t> { static constexpr ONNXTensorElementDataType type = ONNX_TENSOR_ELEMENT_DATA_TYPE_UINT16; };-template <>-struct TypeToTensorType<uint32_t> { static constexpr ONNXTensorElementDataType type = ONNX_TENSOR_ELEMENT_DATA_TYPE_UINT32; };-template <>-struct TypeToTensorType<uint64_t> { static constexpr ONNXTensorElementDataType type = ONNX_TENSOR_ELEMENT_DATA_TYPE_UINT64; };-template <>-struct TypeToTensorType<bool> { static constexpr ONNXTensorElementDataType type = ONNX_TENSOR_ELEMENT_DATA_TYPE_BOOL; };--inline MemoryAllocation::MemoryAllocation(OrtAllocator* allocator, void* p, size_t size)- : allocator_(allocator), p_(p), size_(size) {-}--inline MemoryAllocation::~MemoryAllocation() {- if (p_ != nullptr) {- // We do not throw out of destructor- auto ret = GetApi().AllocatorFree(allocator_, p_);- static_cast<void>(ret);- }-}--inline MemoryAllocation::MemoryAllocation(MemoryAllocation&& o) : allocator_(nullptr), p_(nullptr), size_(0) {- *this = std::move(o);-}--inline MemoryAllocation& MemoryAllocation::operator=(MemoryAllocation&& o) {- OrtAllocator* alloc = nullptr;- void* p = nullptr;- size_t sz = 0;-- // Swap out this- std::swap(alloc, allocator_);- std::swap(p, p_);- std::swap(sz, size_);-- // Swap with incoming- std::swap(allocator_, o.allocator_);- std::swap(p_, o.p_);- std::swap(size_, o.size_);-- // Destroy this instance if needed- MemoryAllocation this_alloc(alloc, p, sz);- return *this;-}--inline AllocatorWithDefaultOptions::AllocatorWithDefaultOptions() {- ThrowOnError(GetApi().GetAllocatorWithDefaultOptions(&p_));-}--inline void* AllocatorWithDefaultOptions::Alloc(size_t size) {- void* out;- ThrowOnError(GetApi().AllocatorAlloc(p_, size, &out));- return out;-}--inline MemoryAllocation Ort::AllocatorWithDefaultOptions::GetAllocation(size_t size) {- void* out;- ThrowOnError(GetApi().AllocatorAlloc(p_, size, &out));- MemoryAllocation result(p_, out, size);- return result;-}--inline void AllocatorWithDefaultOptions::Free(void* p) {- ThrowOnError(GetApi().AllocatorFree(p_, p));-}--inline const OrtMemoryInfo* AllocatorWithDefaultOptions::GetInfo() const {- const OrtMemoryInfo* out;- ThrowOnError(GetApi().AllocatorGetInfo(p_, &out));- return out;-}--template <typename B>-inline std::string BaseMemoryInfo<B>::GetAllocatorName() const {- const char* name = nullptr;- ThrowOnError(GetApi().MemoryInfoGetName(*this, &name));- return std::string(name);-}--template <typename B>-inline OrtAllocatorType BaseMemoryInfo<B>::GetAllocatorType() const {- OrtAllocatorType type;- ThrowOnError(GetApi().MemoryInfoGetType(*this, &type));- return type;-}--template <typename B>-int BaseMemoryInfo<B>::GetDeviceId() const {- int id = 0;- ThrowOnError(GetApi().MemoryInfoGetId(*this, &id));- return id;-}--template <typename B>-inline OrtMemType BaseMemoryInfo<B>::GetMemoryType() const {- OrtMemType type;- ThrowOnError(GetApi().MemoryInfoGetMemType(*this, &type));- return type;-}--template <typename B>-template <typename U>-inline bool BaseMemoryInfo<B>::operator==(const BaseMemoryInfo<U>& o) const {- int comp_result = 0;- ThrowOnError(Ort::GetApi().CompareMemoryInfo(*this, o, &comp_result));- return comp_result == 0;-}--inline MemoryInfo MemoryInfo::CreateCpu(OrtAllocatorType type, OrtMemType mem_type) {- OrtMemoryInfo* p;- ThrowOnError(GetApi().CreateCpuMemoryInfo(type, mem_type, &p));- return MemoryInfo(p);-}--inline MemoryInfo::MemoryInfo(const char* name, OrtAllocatorType type, int id, OrtMemType mem_type) {- ThrowOnError(GetApi().CreateMemoryInfo(name, type, id, mem_type, &p_));-}--inline Allocator::Allocator(const Session& sess, const MemoryInfo& mem_info) {- ThrowOnError(GetApi().CreateAllocator(sess, mem_info, &p_));-}--inline void* Allocator::Alloc(size_t size) const {- void* out = nullptr;- ThrowOnError(GetApi().AllocatorAlloc(p_, size, &out));- return out;-}--inline MemoryAllocation Ort::Allocator::GetAllocation(size_t size) {- void* out = nullptr;- ThrowOnError(GetApi().AllocatorAlloc(p_, size, &out));- MemoryAllocation result(p_, out, size);- return result;-}--inline void Allocator::Free(void* p) const {- ThrowOnError(GetApi().AllocatorFree(p_, p));-}--inline UnownedMemoryInfo Allocator::GetInfo() const {- const OrtMemoryInfo* out = nullptr;- ThrowOnError(GetApi().AllocatorGetInfo(p_, &out));- return UnownedMemoryInfo(out);-}--inline IoBinding::IoBinding(Session& session) {- ThrowOnError(GetApi().CreateIoBinding(session, &p_));-}--inline void IoBinding::BindInput(const char* name, const Value& value) {- ThrowOnError(GetApi().BindInput(p_, name, value));-}--inline void IoBinding::BindOutput(const char* name, const Value& value) {- ThrowOnError(GetApi().BindOutput(p_, name, value));-}--inline void IoBinding::BindOutput(const char* name, const MemoryInfo& mem_info) {- ThrowOnError(GetApi().BindOutputToDevice(p_, name, mem_info));-}--inline std::vector<std::string> IoBinding::GetOutputNamesHelper(OrtAllocator* allocator) const {- std::vector<std::string> result;- auto free_fn = [allocator](void* p) { if (p) allocator->Free(allocator, p); };- using Ptr = std::unique_ptr<void, decltype(free_fn)>;-- char* buffer = nullptr;- size_t* lengths = nullptr;- size_t count = 0;- ThrowOnError(GetApi().GetBoundOutputNames(p_, allocator, &buffer, &lengths, &count));-- if (count == 0) {- return result;- }-- Ptr buffer_g(buffer, free_fn);- Ptr lengths_g(lengths, free_fn);-- result.reserve(count);- for (size_t i = 0; i < count; ++i) {- auto sz = *lengths;- result.emplace_back(buffer, sz);- buffer += sz;- ++lengths;- }- return result;-}--inline std::vector<std::string> IoBinding::GetOutputNames() const {- AllocatorWithDefaultOptions allocator;- return GetOutputNamesHelper(allocator);-}--inline std::vector<std::string> IoBinding::GetOutputNames(Allocator& allocator) const {- return GetOutputNamesHelper(allocator);-}--inline std::vector<Value> Ort::IoBinding::GetOutputValuesHelper(OrtAllocator* allocator) const {- std::vector<Value> result;- size_t owned = 0;- size_t output_count = 0;- // Lambda to release the buffer when no longer needed and- // make sure that we destroy all instances on exception- auto free_fn = [&owned, &output_count, allocator](OrtValue** buffer) {- if (buffer) {- while (owned < output_count) {- auto* p = buffer + owned++;- GetApi().ReleaseValue(*p);- }- allocator->Free(allocator, buffer);- }- };- using Ptr = std::unique_ptr<OrtValue*, decltype(free_fn)>;-- OrtValue** output_buffer = nullptr;- ThrowOnError(GetApi().GetBoundOutputValues(p_, allocator, &output_buffer, &output_count));- if (output_count == 0) {- return result;- }-- Ptr buffer_g(output_buffer, free_fn);-- result.reserve(output_count);- for (size_t i = 0; i < output_count; ++i) {- result.emplace_back(output_buffer[i]);- ++owned;- }- return result;-}--inline std::vector<Value> Ort::IoBinding::GetOutputValues(Allocator& allocator) const {- return GetOutputValuesHelper(allocator);-}--inline std::vector<Value> Ort::IoBinding::GetOutputValues() const {- AllocatorWithDefaultOptions allocator;- return GetOutputValuesHelper(allocator);-}--inline void IoBinding::ClearBoundInputs() {- GetApi().ClearBoundInputs(p_);-}--inline void IoBinding::ClearBoundOutputs() {- GetApi().ClearBoundOutputs(p_);-}--inline ArenaCfg::ArenaCfg(size_t max_mem, int arena_extend_strategy, int initial_chunk_size_bytes, int max_dead_bytes_per_chunk) {- ThrowOnError(GetApi().CreateArenaCfg(max_mem, arena_extend_strategy, initial_chunk_size_bytes, max_dead_bytes_per_chunk, &p_));-}--inline Env::Env(OrtLoggingLevel logging_level, _In_ const char* logid) {- ThrowOnError(GetApi().CreateEnv(logging_level, logid, &p_));- if (strcmp(logid, "onnxruntime-node") == 0) {- ThrowOnError(GetApi().SetLanguageProjection(p_, OrtLanguageProjection::ORT_PROJECTION_NODEJS));- } else {- ThrowOnError(GetApi().SetLanguageProjection(p_, OrtLanguageProjection::ORT_PROJECTION_CPLUSPLUS));- }-}--inline Env::Env(OrtLoggingLevel logging_level, const char* logid, OrtLoggingFunction logging_function, void* logger_param) {- ThrowOnError(GetApi().CreateEnvWithCustomLogger(logging_function, logger_param, logging_level, logid, &p_));- if (strcmp(logid, "onnxruntime-node") == 0) {- ThrowOnError(GetApi().SetLanguageProjection(p_, OrtLanguageProjection::ORT_PROJECTION_NODEJS));- } else {- ThrowOnError(GetApi().SetLanguageProjection(p_, OrtLanguageProjection::ORT_PROJECTION_CPLUSPLUS));- }-}--inline Env::Env(const OrtThreadingOptions* tp_options, OrtLoggingLevel logging_level, _In_ const char* logid) {- ThrowOnError(GetApi().CreateEnvWithGlobalThreadPools(logging_level, logid, tp_options, &p_));- if (strcmp(logid, "onnxruntime-node") == 0) {- ThrowOnError(GetApi().SetLanguageProjection(p_, OrtLanguageProjection::ORT_PROJECTION_NODEJS));- } else {- ThrowOnError(GetApi().SetLanguageProjection(p_, OrtLanguageProjection::ORT_PROJECTION_CPLUSPLUS));- }-}--inline Env::Env(const OrtThreadingOptions* tp_options, OrtLoggingFunction logging_function, void* logger_param,- OrtLoggingLevel logging_level, _In_ const char* logid) {- ThrowOnError(GetApi().CreateEnvWithCustomLoggerAndGlobalThreadPools(logging_function, logger_param, logging_level, logid, tp_options, &p_));- if (strcmp(logid, "onnxruntime-node") == 0) {- ThrowOnError(GetApi().SetLanguageProjection(p_, OrtLanguageProjection::ORT_PROJECTION_NODEJS));- } else {- ThrowOnError(GetApi().SetLanguageProjection(p_, OrtLanguageProjection::ORT_PROJECTION_CPLUSPLUS));- }-}--inline Env& Env::EnableTelemetryEvents() {- ThrowOnError(GetApi().EnableTelemetryEvents(p_));- return *this;-}--inline Env& Env::DisableTelemetryEvents() {- ThrowOnError(GetApi().DisableTelemetryEvents(p_));- return *this;-}--inline Env& Env::CreateAndRegisterAllocator(const OrtMemoryInfo* mem_info, const OrtArenaCfg* arena_cfg) {- ThrowOnError(GetApi().CreateAndRegisterAllocator(p_, mem_info, arena_cfg));- return *this;-}--inline CustomOpDomain::CustomOpDomain(const char* domain) {- ThrowOnError(GetApi().CreateCustomOpDomain(domain, &p_));-}--inline void CustomOpDomain::Add(OrtCustomOp* op) {- ThrowOnError(GetApi().CustomOpDomain_Add(p_, op));-}--inline RunOptions::RunOptions() {- ThrowOnError(GetApi().CreateRunOptions(&p_));-}--inline RunOptions& RunOptions::SetRunLogVerbosityLevel(int level) {- ThrowOnError(GetApi().RunOptionsSetRunLogVerbosityLevel(p_, level));- return *this;-}--inline RunOptions& RunOptions::SetRunLogSeverityLevel(int level) {- ThrowOnError(GetApi().RunOptionsSetRunLogSeverityLevel(p_, level));- return *this;-}--inline int RunOptions::GetRunLogVerbosityLevel() const {- int out;- ThrowOnError(GetApi().RunOptionsGetRunLogVerbosityLevel(p_, &out));- return out;-}--inline RunOptions& RunOptions::SetRunTag(const char* run_tag) {- ThrowOnError(GetApi().RunOptionsSetRunTag(p_, run_tag));- return *this;-}--inline const char* RunOptions::GetRunTag() const {- const char* out;- ThrowOnError(GetApi().RunOptionsGetRunTag(p_, &out));- return out;-}--inline RunOptions& RunOptions::SetTerminate() {- ThrowOnError(GetApi().RunOptionsSetTerminate(p_));- return *this;-}--inline RunOptions& RunOptions::UnsetTerminate() {- ThrowOnError(GetApi().RunOptionsUnsetTerminate(p_));- return *this;-}--inline SessionOptions::SessionOptions() {- ThrowOnError(GetApi().CreateSessionOptions(&p_));-}--inline SessionOptions SessionOptions::Clone() const {- OrtSessionOptions* out;- ThrowOnError(GetApi().CloneSessionOptions(p_, &out));- return SessionOptions{out};-}--inline SessionOptions& SessionOptions::SetIntraOpNumThreads(int intra_op_num_threads) {- ThrowOnError(GetApi().SetIntraOpNumThreads(p_, intra_op_num_threads));- return *this;-}--inline SessionOptions& SessionOptions::SetInterOpNumThreads(int inter_op_num_threads) {- ThrowOnError(GetApi().SetInterOpNumThreads(p_, inter_op_num_threads));- return *this;-}--inline SessionOptions& SessionOptions::SetGraphOptimizationLevel(GraphOptimizationLevel graph_optimization_level) {- ThrowOnError(GetApi().SetSessionGraphOptimizationLevel(p_, graph_optimization_level));- return *this;-}--inline SessionOptions& SessionOptions::SetOptimizedModelFilePath(const ORTCHAR_T* optimized_model_filepath) {- ThrowOnError(GetApi().SetOptimizedModelFilePath(p_, optimized_model_filepath));- return *this;-}--inline SessionOptions& SessionOptions::EnableProfiling(const ORTCHAR_T* profile_file_prefix) {- ThrowOnError(GetApi().EnableProfiling(p_, profile_file_prefix));- return *this;-}--inline SessionOptions& SessionOptions::DisableProfiling() {- ThrowOnError(GetApi().DisableProfiling(p_));- return *this;-}--inline SessionOptions& SessionOptions::EnableMemPattern() {- ThrowOnError(GetApi().EnableMemPattern(p_));- return *this;-}--inline SessionOptions& SessionOptions::DisableMemPattern() {- ThrowOnError(GetApi().DisableMemPattern(p_));- return *this;-}--inline SessionOptions& SessionOptions::EnableCpuMemArena() {- ThrowOnError(GetApi().EnableCpuMemArena(p_));- return *this;-}--inline SessionOptions& SessionOptions::DisableCpuMemArena() {- ThrowOnError(GetApi().DisableCpuMemArena(p_));- return *this;-}--inline SessionOptions& SessionOptions::SetExecutionMode(ExecutionMode execution_mode) {- ThrowOnError(GetApi().SetSessionExecutionMode(p_, execution_mode));- return *this;-}--inline SessionOptions& SessionOptions::SetLogId(const char* logid) {- ThrowOnError(GetApi().SetSessionLogId(p_, logid));- return *this;-}--inline SessionOptions& SessionOptions::SetLogSeverityLevel(int level) {- ThrowOnError(GetApi().SetSessionLogSeverityLevel(p_, level));- return *this;-}--inline SessionOptions& SessionOptions::Add(OrtCustomOpDomain* custom_op_domain) {- ThrowOnError(GetApi().AddCustomOpDomain(p_, custom_op_domain));- return *this;-}--inline SessionOptions& SessionOptions::AddConfigEntry(const char* config_key, const char* config_value) {- ThrowOnError(GetApi().AddSessionConfigEntry(p_, config_key, config_value));- return *this;-}--inline SessionOptions& SessionOptions::AddInitializer(const char* name, const OrtValue* ort_val) {- ThrowOnError(GetApi().AddInitializer(p_, name, ort_val));- return *this;-}--inline SessionOptions& SessionOptions::AppendExecutionProvider_CUDA(const OrtCUDAProviderOptions& provider_options) {- ThrowOnError(GetApi().SessionOptionsAppendExecutionProvider_CUDA(p_, &provider_options));- return *this;-}--inline SessionOptions& SessionOptions::AppendExecutionProvider_OpenVINO(const OrtOpenVINOProviderOptions& provider_options) {- ThrowOnError(GetApi().SessionOptionsAppendExecutionProvider_OpenVINO(p_, &provider_options));- return *this;-}--inline Session::Session(Env& env, const ORTCHAR_T* model_path, const SessionOptions& options) {- ThrowOnError(GetApi().CreateSession(env, model_path, options, &p_));-}--inline Session::Session(Env& env, const void* model_data, size_t model_data_length, const SessionOptions& options) {- ThrowOnError(GetApi().CreateSessionFromArray(env, model_data, model_data_length, options, &p_));-}--inline std::vector<Value> Session::Run(const RunOptions& run_options, const char* const* input_names, const Value* input_values, size_t input_count,- const char* const* output_names, size_t output_names_count) {- std::vector<Ort::Value> output_values;- for (size_t i = 0; i < output_names_count; i++)- output_values.emplace_back(nullptr);- Run(run_options, input_names, input_values, input_count, output_names, output_values.data(), output_names_count);- return output_values;-}--inline void Session::Run(const RunOptions& run_options, const char* const* input_names, const Value* input_values, size_t input_count,- const char* const* output_names, Value* output_values, size_t output_count) {- static_assert(sizeof(Value) == sizeof(OrtValue*), "Value is really just an array of OrtValue* in memory, so we can reinterpret_cast safely");- auto ort_input_values = reinterpret_cast<const OrtValue**>(const_cast<Value*>(input_values));- auto ort_output_values = reinterpret_cast<OrtValue**>(output_values);- ThrowOnError(GetApi().Run(p_, run_options, input_names, ort_input_values, input_count, output_names, output_count, ort_output_values));-}--inline void Session::Run(const RunOptions& run_options, const IoBinding& io_binding) {- ThrowOnError(GetApi().RunWithBinding(p_, run_options, io_binding));-}--inline size_t Session::GetInputCount() const {- size_t out;- ThrowOnError(GetApi().SessionGetInputCount(p_, &out));- return out;-}--inline size_t Session::GetOutputCount() const {- size_t out;- ThrowOnError(GetApi().SessionGetOutputCount(p_, &out));- return out;-}--inline size_t Session::GetOverridableInitializerCount() const {- size_t out;- ThrowOnError(GetApi().SessionGetOverridableInitializerCount(p_, &out));- return out;-}--inline char* Session::GetInputName(size_t index, OrtAllocator* allocator) const {- char* out;- ThrowOnError(GetApi().SessionGetInputName(p_, index, allocator, &out));- return out;-}--inline char* Session::GetOutputName(size_t index, OrtAllocator* allocator) const {- char* out;- ThrowOnError(GetApi().SessionGetOutputName(p_, index, allocator, &out));- return out;-}--inline char* Session::GetOverridableInitializerName(size_t index, OrtAllocator* allocator) const {- char* out;- ThrowOnError(GetApi().SessionGetOverridableInitializerName(p_, index, allocator, &out));- return out;-}--inline char* Session::EndProfiling(OrtAllocator* allocator) const {- char* out;- ThrowOnError(GetApi().SessionEndProfiling(p_, allocator, &out));- return out;-}--inline uint64_t Session::GetProfilingStartTimeNs() const {- uint64_t out;- ThrowOnError(GetApi().SessionGetProfilingStartTimeNs(p_, &out));- return out;-}--inline ModelMetadata Session::GetModelMetadata() const {- OrtModelMetadata* out;- ThrowOnError(GetApi().SessionGetModelMetadata(p_, &out));- return ModelMetadata{out};-}--inline char* ModelMetadata::GetProducerName(OrtAllocator* allocator) const {- char* out;- ThrowOnError(GetApi().ModelMetadataGetProducerName(p_, allocator, &out));- return out;-}--inline char* ModelMetadata::GetGraphName(OrtAllocator* allocator) const {- char* out;- ThrowOnError(GetApi().ModelMetadataGetGraphName(p_, allocator, &out));- return out;-}--inline char* ModelMetadata::GetDomain(OrtAllocator* allocator) const {- char* out;- ThrowOnError(GetApi().ModelMetadataGetDomain(p_, allocator, &out));- return out;-}--inline char* ModelMetadata::GetDescription(OrtAllocator* allocator) const {- char* out;- ThrowOnError(GetApi().ModelMetadataGetDescription(p_, allocator, &out));- return out;-}--inline char* ModelMetadata::LookupCustomMetadataMap(const char* key, OrtAllocator* allocator) const {- char* out;- ThrowOnError(GetApi().ModelMetadataLookupCustomMetadataMap(p_, allocator, key, &out));- return out;-}--inline char** ModelMetadata::GetCustomMetadataMapKeys(OrtAllocator* allocator, _Out_ int64_t& num_keys) const {- char** out;- ThrowOnError(GetApi().ModelMetadataGetCustomMetadataMapKeys(p_, allocator, &out, &num_keys));- return out;-}--inline int64_t ModelMetadata::GetVersion() const {- int64_t out;- ThrowOnError(GetApi().ModelMetadataGetVersion(p_, &out));- return out;-}--inline TypeInfo Session::GetInputTypeInfo(size_t index) const {- OrtTypeInfo* out;- ThrowOnError(GetApi().SessionGetInputTypeInfo(p_, index, &out));- return TypeInfo{out};-}--inline TypeInfo Session::GetOutputTypeInfo(size_t index) const {- OrtTypeInfo* out;- ThrowOnError(GetApi().SessionGetOutputTypeInfo(p_, index, &out));- return TypeInfo{out};-}--inline TypeInfo Session::GetOverridableInitializerTypeInfo(size_t index) const {- OrtTypeInfo* out;- ThrowOnError(GetApi().SessionGetOverridableInitializerTypeInfo(p_, index, &out));- return TypeInfo{out};-}--inline ONNXTensorElementDataType TensorTypeAndShapeInfo::GetElementType() const {- ONNXTensorElementDataType out;- ThrowOnError(GetApi().GetTensorElementType(p_, &out));- return out;-}--inline size_t TensorTypeAndShapeInfo::GetElementCount() const {- size_t out;- ThrowOnError(GetApi().GetTensorShapeElementCount(p_, &out));- return static_cast<size_t>(out);-}--inline size_t TensorTypeAndShapeInfo::GetDimensionsCount() const {- size_t out;- ThrowOnError(GetApi().GetDimensionsCount(p_, &out));- return out;-}--inline void TensorTypeAndShapeInfo::GetDimensions(int64_t* values, size_t values_count) const {- ThrowOnError(GetApi().GetDimensions(p_, values, values_count));-}--inline void TensorTypeAndShapeInfo::GetSymbolicDimensions(const char** values, size_t values_count) const {- ThrowOnError(GetApi().GetSymbolicDimensions(p_, values, values_count));-}--inline std::vector<int64_t> TensorTypeAndShapeInfo::GetShape() const {- std::vector<int64_t> out(GetDimensionsCount(), 0);- GetDimensions(out.data(), out.size());- return out;-}--inline Unowned<TensorTypeAndShapeInfo> TypeInfo::GetTensorTypeAndShapeInfo() const {- const OrtTensorTypeAndShapeInfo* out;- ThrowOnError(GetApi().CastTypeInfoToTensorInfo(p_, &out));- return Unowned<TensorTypeAndShapeInfo>(const_cast<OrtTensorTypeAndShapeInfo*>(out));-}--inline Unowned<SequenceTypeInfo> TypeInfo::GetSequenceTypeInfo() const {- const OrtSequenceTypeInfo* out;- ThrowOnError(GetApi().CastTypeInfoToSequenceTypeInfo(p_, &out));- return Unowned<SequenceTypeInfo>{const_cast<OrtSequenceTypeInfo*>(out)};-}--inline TypeInfo SequenceTypeInfo::GetSequenceElementType() const {- OrtTypeInfo* output;- ThrowOnError(GetApi().GetSequenceElementType(p_, &output));- return TypeInfo{output};-}--inline Unowned<MapTypeInfo> TypeInfo::GetMapTypeInfo() const {- const OrtMapTypeInfo* out;- ThrowOnError(GetApi().CastTypeInfoToMapTypeInfo(p_, &out));- return Unowned<MapTypeInfo>{const_cast<OrtMapTypeInfo*>(out)};-}--inline ONNXTensorElementDataType MapTypeInfo::GetMapKeyType() const {- ONNXTensorElementDataType out;- ThrowOnError(GetApi().GetMapKeyType(p_, &out));- return out;-}--inline TypeInfo MapTypeInfo::GetMapValueType() const {- OrtTypeInfo* output;- ThrowOnError(GetApi().GetMapValueType(p_, &output));- return TypeInfo{output};-}--inline ONNXType TypeInfo::GetONNXType() const {- ONNXType out;- ThrowOnError(GetApi().GetOnnxTypeFromTypeInfo(p_, &out));- return out;-}--template <typename T>-inline Value Value::CreateTensor(const OrtMemoryInfo* info, T* p_data, size_t p_data_element_count, const int64_t* shape, size_t shape_len) {- return CreateTensor(info, p_data, p_data_element_count * sizeof(T), shape, shape_len, TypeToTensorType<T>::type);-}--inline Value Value::CreateTensor(const OrtMemoryInfo* info, void* p_data, size_t p_data_byte_count, const int64_t* shape, size_t shape_len,- ONNXTensorElementDataType type) {- OrtValue* out;- ThrowOnError(GetApi().CreateTensorWithDataAsOrtValue(info, p_data, p_data_byte_count, shape, shape_len, type, &out));- return Value{out};-}--template <typename T>-inline Value Value::CreateTensor(OrtAllocator* allocator, const int64_t* shape, size_t shape_len) {- return CreateTensor(allocator, shape, shape_len, TypeToTensorType<T>::type);-}--inline Value Value::CreateTensor(OrtAllocator* allocator, const int64_t* shape, size_t shape_len, ONNXTensorElementDataType type) {- OrtValue* out;- ThrowOnError(GetApi().CreateTensorAsOrtValue(allocator, shape, shape_len, type, &out));- return Value{out};-}--inline Value Value::CreateMap(Value& keys, Value& values) {- OrtValue* out;- OrtValue* inputs[2] = {keys, values};- ThrowOnError(GetApi().CreateValue(inputs, 2, ONNX_TYPE_MAP, &out));- return Value{out};-}--inline Value Value::CreateSequence(std::vector<Value>& values) {- OrtValue* out;- std::vector<OrtValue*> values_ort{values.data(), values.data() + values.size()};- ThrowOnError(GetApi().CreateValue(values_ort.data(), values_ort.size(), ONNX_TYPE_SEQUENCE, &out));- return Value{out};-}--template <typename T>-inline Value Value::CreateOpaque(const char* domain, const char* type_name, const T& data_container) {- OrtValue* out;- ThrowOnError(GetApi().CreateOpaqueValue(domain, type_name, &data_container, sizeof(T), &out));- return Value{out};-}--template <typename T>-inline void Value::GetOpaqueData(const char* domain, const char* type_name, T& out) const {- ThrowOnError(GetApi().GetOpaqueValue(domain, type_name, p_, &out, sizeof(T)));-}--inline bool Value::IsTensor() const {- int out;- ThrowOnError(GetApi().IsTensor(p_, &out));- return out != 0;-}--inline size_t Value::GetCount() const {- size_t out;- ThrowOnError(GetApi().GetValueCount(p_, &out));- return out;-}--inline Value Value::GetValue(int index, OrtAllocator* allocator) const {- OrtValue* out;- ThrowOnError(GetApi().GetValue(p_, index, allocator, &out));- return Value{out};-}--inline size_t Value::GetStringTensorDataLength() const {- size_t out;- ThrowOnError(GetApi().GetStringTensorDataLength(p_, &out));- return out;-}--inline size_t Value::GetStringTensorElementLength(size_t element_index) const {- size_t out;- ThrowOnError(GetApi().GetStringTensorElementLength(p_, element_index, &out));- return out;-}--inline void Value::GetStringTensorContent(void* buffer, size_t buffer_length, size_t* offsets, size_t offsets_count) const {- ThrowOnError(GetApi().GetStringTensorContent(p_, buffer, buffer_length, offsets, offsets_count));-}--inline void Value::GetStringTensorElement(size_t buffer_length, size_t element_index, void* buffer) const {- ThrowOnError(GetApi().GetStringTensorElement(p_, buffer_length, element_index, buffer));-}--inline void Value::FillStringTensor(const char* const* s, size_t s_len) {- ThrowOnError(GetApi().FillStringTensor(p_, s, s_len));-}--inline void Value::FillStringTensorElement(const char* s, size_t index) {- ThrowOnError(GetApi().FillStringTensorElement(p_, s, index));-}--template <typename T>-T* Value::GetTensorMutableData() {- T* out;- ThrowOnError(GetApi().GetTensorMutableData(p_, (void**)&out));- return out;-}--template <typename T>-const T* Value::GetTensorData() const {- T* out;- ThrowOnError(GetApi().GetTensorMutableData(p_, (void**)&out));- return out;-}--template <typename T>-inline T& Value::At(const std::vector<int64_t>& location) {- static_assert(!std::is_same<T, std::string>::value, "this api does not support std::string");- T* out;- ThrowOnError(GetApi().TensorAt(p_, location.data(), location.size(), (void**)&out));- return *out;-}--inline TypeInfo Value::GetTypeInfo() const {- OrtTypeInfo* output;- ThrowOnError(GetApi().GetTypeInfo(p_, &output));- return TypeInfo{output};-}--inline TensorTypeAndShapeInfo Value::GetTensorTypeAndShapeInfo() const {- OrtTensorTypeAndShapeInfo* output;- ThrowOnError(GetApi().GetTensorTypeAndShape(p_, &output));- return TensorTypeAndShapeInfo{output};-}--//-// Custom OP API Inlines-//-inline void CustomOpApi::ThrowOnError(OrtStatus* status) {- Ort::ThrowOnError(api_, status);-}--template <>-inline float CustomOpApi::KernelInfoGetAttribute<float>(_In_ const OrtKernelInfo* info, _In_ const char* name) {- float out;- ThrowOnError(api_.KernelInfoGetAttribute_float(info, name, &out));- return out;-}--template <>-inline int64_t CustomOpApi::KernelInfoGetAttribute<int64_t>(_In_ const OrtKernelInfo* info, _In_ const char* name) {- int64_t out;- ThrowOnError(api_.KernelInfoGetAttribute_int64(info, name, &out));- return out;-}--template <>-inline std::string CustomOpApi::KernelInfoGetAttribute<std::string>(_In_ const OrtKernelInfo* info, _In_ const char* name) {- size_t size = 0;- std::string out;- OrtStatus* status = api_.KernelInfoGetAttribute_string(info, name, nullptr, &size);-- // The status should be ORT_INVALID_ARGUMENT because the size is insufficient to hold the string- if (api_.GetErrorCode(status) == ORT_INVALID_ARGUMENT) {- api_.ReleaseStatus(status);- out.resize(size);- ThrowOnError(api_.KernelInfoGetAttribute_string(info, name, &out[0], &size));- out.resize(size - 1); // remove the terminating character '\0'- } else {- ThrowOnError(status);- }- return out;-}--inline OrtTensorTypeAndShapeInfo* CustomOpApi::GetTensorTypeAndShape(_In_ const OrtValue* value) {- OrtTensorTypeAndShapeInfo* out;- ThrowOnError(api_.GetTensorTypeAndShape(value, &out));- return out;-}--inline size_t CustomOpApi::GetTensorShapeElementCount(_In_ const OrtTensorTypeAndShapeInfo* info) {- size_t out;- ThrowOnError(api_.GetTensorShapeElementCount(info, &out));- return out;-}--inline ONNXTensorElementDataType CustomOpApi::GetTensorElementType(const OrtTensorTypeAndShapeInfo* info) {- ONNXTensorElementDataType out;- ThrowOnError(api_.GetTensorElementType(info, &out));- return out;-}--inline size_t CustomOpApi::GetDimensionsCount(_In_ const OrtTensorTypeAndShapeInfo* info) {- size_t out;- ThrowOnError(api_.GetDimensionsCount(info, &out));- return out;-}--inline void CustomOpApi::GetDimensions(_In_ const OrtTensorTypeAndShapeInfo* info, _Out_ int64_t* dim_values, size_t dim_values_length) {- ThrowOnError(api_.GetDimensions(info, dim_values, dim_values_length));-}--inline void CustomOpApi::SetDimensions(OrtTensorTypeAndShapeInfo* info, _In_ const int64_t* dim_values, size_t dim_count) {- ThrowOnError(api_.SetDimensions(info, dim_values, dim_count));-}--template <typename T>-inline T* CustomOpApi::GetTensorMutableData(_Inout_ OrtValue* value) {- T* data;- ThrowOnError(api_.GetTensorMutableData(value, reinterpret_cast<void**>(&data)));- return data;-}--template <typename T>-inline const T* CustomOpApi::GetTensorData(_Inout_ const OrtValue* value) {- return GetTensorMutableData<T>(const_cast<OrtValue*>(value));-}--inline std::vector<int64_t> CustomOpApi::GetTensorShape(const OrtTensorTypeAndShapeInfo* info) {- std::vector<int64_t> output(GetDimensionsCount(info));- GetDimensions(info, output.data(), output.size());- return output;-}--inline void CustomOpApi::ReleaseTensorTypeAndShapeInfo(OrtTensorTypeAndShapeInfo* input) {- api_.ReleaseTensorTypeAndShapeInfo(input);-}--inline size_t CustomOpApi::KernelContext_GetInputCount(const OrtKernelContext* context) {- size_t out;- ThrowOnError(api_.KernelContext_GetInputCount(context, &out));- return out;-}--inline const OrtValue* CustomOpApi::KernelContext_GetInput(const OrtKernelContext* context, _In_ size_t index) {- const OrtValue* out;- ThrowOnError(api_.KernelContext_GetInput(context, index, &out));- return out;-}--inline size_t CustomOpApi::KernelContext_GetOutputCount(const OrtKernelContext* context) {- size_t out;- ThrowOnError(api_.KernelContext_GetOutputCount(context, &out));- return out;-}--inline OrtValue* CustomOpApi::KernelContext_GetOutput(OrtKernelContext* context, _In_ size_t index,- _In_ const int64_t* dim_values, size_t dim_count) {- OrtValue* out;- ThrowOnError(api_.KernelContext_GetOutput(context, index, dim_values, dim_count, &out));- return out;-}--inline SessionOptions& SessionOptions::DisablePerSessionThreads() {- ThrowOnError(GetApi().DisablePerSessionThreads(p_));- return *this;-}--inline std::vector<std::string> GetAvailableProviders() {- int len;- char** providers;- const OrtApi& api = GetApi();- ThrowOnError(api.GetAvailableProviders(&providers, &len));- std::vector<std::string> available_providers(providers, providers + len);- ThrowOnError(api.ReleaseAvailableProviders(providers, len));- return available_providers;-}--SessionOptions& AddInitializer(const char* name, const OrtValue* ort_val);--} // namespace Ortdiff --git a/include/onnxruntime/onnxruntime_session_options_config_keys.h b/include/onnxruntime/onnxruntime_session_options_config_keys.hdeleted file mode 100755index ff247f2..0000000--- a/include/onnxruntime/onnxruntime_session_options_config_keys.h+++ /dev/null@@ -1,42 +0,0 @@-// Copyright (c) Microsoft Corporation. All rights reserved.-// Licensed under the MIT License.--#pragma once--/*- * This file defines SessionOptions Config Keys and format of the Config Values.- *- * The Naming Convention for a SessionOptions Config Key,- * "[Area][.[SubArea1].[SubArea2]...].[Keyname]"- * Such as "ep.cuda.use_arena"- * The Config Key cannot be empty- * The maximum length of the Config Key is 128- *- * The string format of a SessionOptions Config Value is defined individually for each Config.- * The maximum length of the Config Value is 1024- */--// Key for disable PrePacking,-// If the config value is set to "1" then the prepacking is disabled, otherwise prepacking is enabled (default value)-static const char* const kOrtSessionOptionsConfigDisablePrepacking = "session.disable_prepacking";--// A value of "1" means allocators registered in the env will be used. "0" means the allocators created in the session-// will be used. Use this to override the usage of env allocators on a per session level.-static const char* const kOrtSessionOptionsConfigUseEnvAllocators = "session.use_env_allocators";--// Set to 'ORT' (case sensitive) to load an ORT format model.-// If unset, model type will default to ONNX unless inferred from filename ('.ort' == ORT format) or bytes to be ORT-static const char* const kOrtSessionOptionsConfigLoadModelFormat = "session.load_model_format";--// Set to 'ORT' (case sensitive) to save optimized model in ORT format when SessionOptions.optimized_model_path is set.-// If unset, format will default to ONNX unless optimized_model_filepath ends in '.ort'.-static const char* const kOrtSessionOptionsConfigSaveModelFormat = "session.save_model_format";--// If a value is "1", flush-to-zero and denormal-as-zero are applied. The default is "0".-// When multiple sessions are created, a main thread doesn't override changes from succeeding session options,-// but threads in session thread pools follow option changes.-// When ORT runs with OpenMP, the same rule is applied, i.e. the first session option to flush-to-zero and-// denormal-as-zero is only applied to global OpenMP thread pool, which doesn't support per-session thread pool.-// Note that an alternative way not using this option at runtime is to train and export a model without denormals-// and that's recommended because turning this option on may hurt model accuracy.-static const char* const kOrtSessionOptionsConfigSetDenormalAsZero = "session.set_denormal_as_zero";diff --git a/include/precomp.h b/include/precomp.hdeleted file mode 100755index 6c332ed..0000000--- a/include/precomp.h+++ /dev/null@@ -1,6 +0,0 @@-#pragma once-#include "OcrUtils.h"-#include "rapidocr_api.h"-#include "omp.h"-#include "OcrLite.h"-#include "opencv2/imgcodecs.hpp"\ No newline at end of filediff --git a/include/rapidocr_api.h b/include/rapidocr_api.hdeleted file mode 100755index 65afb69..0000000--- a/include/rapidocr_api.h+++ /dev/null@@ -1,61 +0,0 @@-#pragma once-#ifdef __cplusplus-extern "C"-{-#endif--#ifdef WIN32--#ifdef _BPOCR_EXPORT_API-#define _QM_OCR_API __declspec(dllexport)-#else-#define _QM_OCR_API __declspec(dllimport)-#endif-#else--#define _QM_OCR_API-#endif--typedef void* BPHANDLE;-typedef char BOOL;--#ifndef NULL-#define NULL 0-#endif-#define TRUE 1-#define FALSE 0---typedef struct __rapidocr_param-{- float unClipRatio;- int maxSideLen;- int padding;- float boxThresh;- float boxScoreThresh;- int numThread;- int flagDoAngle; // 1 means do- int flagMostAngle; // 1 means true-} RAPIDOCR_PARAM;----/*-By default, nThreads should be the number of threads-*/-_QM_OCR_API BPHANDLE BPOcrInit(const char * szDetModel, const char * szClsModel, const char * szRecModel,const char *szKeyPath,int nThreads);--_QM_OCR_API BOOL BPOcrDoOcr(BPHANDLE handle, const char* szImgPath, BOOL bAutoParam,BOOL bLongPic, RAPIDOCR_PARAM *pParam);--_QM_OCR_API int BPOcrGetLen(BPHANDLE handle);--_QM_OCR_API BOOL BPOcrGetResult(BPHANDLE handle, char* szBuf, int nLen);--_QM_OCR_API void BPOcrDeinit(BPHANDLE handle);-----#ifdef __cplusplus-}-#endifdiff --git a/lib/README.md b/lib/README.mddeleted file mode 100755index 0b10924..0000000--- a/lib/README.md+++ /dev/null@@ -1,3 +0,0 @@-You need to put your library files here in its appropriate directory respectively.--Mainly you need put your onnxruntime library file in its correct directory.diff --git a/lib/linux/readme.md b/lib/linux/readme.mddeleted file mode 100755index 48cdce8..0000000--- a/lib/linux/readme.md+++ /dev/null@@ -1 +0,0 @@-placeholderdiff --git a/lib/win/x64/readme.md b/lib/win/x64/readme.mddeleted file mode 100755index 48cdce8..0000000--- a/lib/win/x64/readme.md+++ /dev/null@@ -1 +0,0 @@-placeholderdiff --git a/lib/win/x86/readme.md b/lib/win/x86/readme.mddeleted file mode 100755index 48cdce8..0000000--- a/lib/win/x86/readme.md+++ /dev/null@@ -1 +0,0 @@-placeholderdiff --git a/release/cpp_sdk/README.md b/release/cpp_sdk/README.mddeleted file mode 100644index 71d3075..0000000--- a/release/cpp_sdk/README.md+++ /dev/null@@ -1,25 +0,0 @@-#### SDK包中的目录说明--### C++项目使用onnxruntime和ncnn两种推理框架,实现了2种版本-### onnxruntime版:[RapidOcrOnnx](https://github.com/RapidAI/RapidOcrOnnx)-### ncnn版:[RapidOcrNcnn](https://github.com/RapidAI/RapidOcrNcnn)-### 以下内容停止更新--```text-x86 32位二进制制文件-libx86 32位链接库文件-x64 64位二进制制文件-libx64 64位链接库文件-include 头文件目录-```--#### 测试程序与dll/so位于同一个目录中,使用方法-```shell-/path/to/test /path/to/model/dir/ /path/to/img/file--# example-c:\test\x64\rapidocrtester.exe e:\rapidocr\models\ e:\test\test.jpg-```---#### 下载多语言模型文件 [link](https://github.com/RapidAI/RapidOCR/releases/download/V1.0/rapid-model.tgz)diff --git a/tools/export_custom.py b/tools/export_custom.pydeleted file mode 100755index 6a79867..0000000--- a/tools/export_custom.py+++ /dev/null@@ -1,70 +0,0 @@-# Copyright (c) 2020 PaddlePaddle Authors. All Rights Reserved.-#-# Licensed under the Apache License, Version 2.0 (the "License");-# you may not use this file except in compliance with the License.-# You may obtain a copy of the License at-#-# http://www.apache.org/licenses/LICENSE-2.0-#-# Unless required by applicable law or agreed to in writing, software-# distributed under the License is distributed on an "AS IS" BASIS,-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.-# See the License for the specific language governing permissions and-# limitations under the License.--import os-import sys--__dir__ = os.path.dirname(os.path.abspath(__file__))-sys.path.append(__dir__)-sys.path.append(os.path.abspath(os.path.join(__dir__, '..')))--import argparse--import paddle-from paddle.jit import to_static--from ppocr.modeling.architectures import build_model-from ppocr.postprocess import build_post_process-from ppocr.utils.save_load import init_model-from ppocr.utils.logging import get_logger-from tools.program import load_config, merge_config, ArgsParser---def main():- FLAGS = ArgsParser().parse_args()- config = load_config(FLAGS.config)- merge_config(FLAGS.opt)- logger = get_logger()- # build post process-- post_process_class = build_post_process(config['PostProcess'],- config['Global'])-- # build model- # for rec algorithm- if hasattr(post_process_class, 'character'):- char_num = len(getattr(post_process_class, 'character'))- config['Architecture']["Head"]['out_channels'] = char_num- model = build_model(config['Architecture'])- init_model(config, model, logger)- model.eval()-- save_path = '{}/inference'.format(config['Global']['save_inference_dir'])-- infer_shape = [3, int(FLAGS.height), int(FLAGS.width)]- if config['Architecture']['model_type'] == "rec":- infer_shape = [3, 32, -1]-- model = to_static(- model,- input_spec=[- paddle.static.InputSpec(- shape=[None] + infer_shape, dtype='float32')- ])- paddle.jit.save(model, save_path)- logger.info('inference model is saved to {}'.format(save_path))---if __name__ == "__main__":- main()diff --git a/tools/gen-models.sh b/tools/gen-models.shdeleted file mode 100755index 4ecacaa..0000000--- a/tools/gen-models.sh+++ /dev/null@@ -1,110 +0,0 @@-#!/bin/bash--function trainToOnnx() {- python3 tools/export_custom.py --height ${1} \- --width ${2} \- -c ${3} \- -o Global.pretrained_model=./inference/${4}_train/best_accuracy Global.load_static_weights=False Global.save_inference_dir=./inference/${4}_infer/-- paddle2onnx --model_dir inference/${4}_infer \- --model_filename inference.pdmodel \- --params_filename inference.pdiparams \- --save_file inference/${4}_infer.onnx \- --opset_version 11 \- --enable_onnx_checker True-}--# ch_ppocr_mobile_v2.0_cls-trainToOnnx 48 192 configs/cls/cls_mv3.yml ch_ppocr_mobile_v2.0_cls--# ch_ppocr_mobile_v2.0_det-trainToOnnx -1 -1 configs/det/ch_ppocr_v2.0/ch_det_mv3_db_v2.0.yml ch_ppocr_mobile_v2.0_det--# ch_ppocr_server_v2.0_det-trainToOnnx -1 -1 configs/det/ch_ppocr_v2.0/ch_det_res18_db_v2.0.yml ch_ppocr_server_v2.0_det--# ch_ppocr_mobile_v2.0_rec-trainToOnnx 32 -1 configs/rec/ch_ppocr_v2.0/rec_chinese_lite_train_v2.0.yml ch_ppocr_mobile_v2.0_rec--# ch_ppocr_server_v2.0_rec-trainToOnnx 32 -1 configs/rec/ch_ppocr_v2.0/rec_chinese_common_train_v2.0.yml ch_ppocr_server_v2.0_rec--# en_number_mobile_v2.0_rec-trainToOnnx 32 -1 configs/rec/multi_language/rec_en_number_lite_train.yml en_number_mobile_v2.0_rec--# french_mobile_v2.0_rec-trainToOnnx 32 -1 configs/rec/multi_language/rec_french_lite_train.yml french_mobile_v2.0_rec--# german_mobile_v2.0_rec-trainToOnnx 32 -1 configs/rec/multi_language/rec_german_lite_train.yml german_mobile_v2.0_rec--# korean_mobile_v2.0_rec-trainToOnnx 32 -1 configs/rec/multi_language/rec_korean_lite_train.yml korean_mobile_v2.0_rec--# japan_mobile_v2.0_rec-trainToOnnx 32 -1 configs/rec/multi_language/rec_japan_lite_train.yml japan_mobile_v2.0_rec--# it_mobile_v2.0_rec-trainToOnnx 32 -1 configs/rec/multi_language/rec_it_lite_train.yml it_mobile_v2.0_rec--# xi_mobile_v2.0_rec-#trainToOnnx 32 -1 configs/rec/multi_language/rec_xi_lite_train.yml xi_mobile_v2.0_rec ##--# pu_mobile_v2.0_rec-trainToOnnx 32 -1 configs/rec/multi_language/rec_pt_lite_train.yml pt_mobile_v2.0_rec--# ru_mobile_v2.0_rec-trainToOnnx 32 -1 configs/rec/multi_language/rec_ru_lite_train.yml ru_mobile_v2.0_rec--# ar_mobile_v2.0_rec-trainToOnnx 32 -1 configs/rec/multi_language/rec_ar_lite_train.yml ar_mobile_v2.0_rec--# hi_mobile_v2.0_rec-trainToOnnx 32 -1 configs/rec/multi_language/rec_hi_lite_train.yml hi_mobile_v2.0_rec--# chinese_cht_mobile_v2.0_rec-trainToOnnx 32 -1 configs/rec/multi_language/rec_ch_tra_lite_train.yml ch_tra_mobile_v2.0_rec--# ug_mobile_v2.0_rec-trainToOnnx 32 -1 configs/rec/multi_language/rec_ug_lite_train.yml ug_mobile_v2.0_rec--# fa_mobile_v2.0_rec-trainToOnnx 32 -1 configs/rec/multi_language/rec_fa_lite_train.yml fa_mobile_v2.0_rec--# ur_mobile_v2.0_rec-trainToOnnx 32 -1 configs/rec/multi_language/rec_ur_lite_train.yml ur_mobile_v2.0_rec--# rs_mobile_v2.0_rec-trainToOnnx 32 -1 configs/rec/multi_language/rec_rs_cyrillic_lite_train.yml rs_cyrillic_mobile_v2.0_rec-trainToOnnx 32 -1 configs/rec/multi_language/rec_rs_latin_lite_train.yml rs_latin_mobile_v2.0_rec--# oc_mobile_v2.0_rec-trainToOnnx 32 -1 configs/rec/multi_language/rec_oc_lite_train.yml oc_mobile_v2.0_rec--# mr_mobile_v2.0_rec-trainToOnnx 32 -1 configs/rec/multi_language/rec_mr_lite_train.yml mr_mobile_v2.0_rec--# ne_mobile_v2.0_rec-trainToOnnx 32 -1 configs/rec/multi_language/rec_ne_lite_train.yml ne_mobile_v2.0_rec---# bg_mobile_v2.0_rec-trainToOnnx 32 -1 configs/rec/multi_language/rec_bg_lite_train.yml bg_mobile_v2.0_rec--# uk_mobile_v2.0_rec-trainToOnnx 32 -1 configs/rec/multi_language/rec_uk_lite_train.yml uk_mobile_v2.0_rec--# be_mobile_v2.0_rec-trainToOnnx 32 -1 configs/rec/multi_language/rec_be_lite_train.yml be_mobile_v2.0_rec--# te_mobile_v2.0_rec-trainToOnnx 32 -1 configs/rec/multi_language/rec_te_lite_train.yml te_mobile_v2.0_rec--# ka_mobile_v2.0_rec-trainToOnnx 32 -1 configs/rec/multi_language/rec_kn_lite_train.yml kn_mobile_v2.0_rec--# ta_mobile_v2.0_rec-trainToOnnx 32 -1 configs/rec/multi_language/rec_ta_lite_train.yml ta_mobile_v2.0_rec--# es_mobile_v2.0_rec-trainToOnnx 32 -1 configs/rec/multi_language/rec_es_lite_train.yml es_mobile_v2.0_recdiff --git a/tools/getmodels.sh b/tools/getmodels.shdeleted file mode 100644index dbdb075..0000000--- a/tools/getmodels.sh+++ /dev/null@@ -1,97 +0,0 @@-#!/bin/bash-wget https://paddleocr.bj.bcebos.com/dygraph_v2.0/ch/ch_ppocr_mobile_v2.0_cls_train.tar-wget https://paddleocr.bj.bcebos.com/dygraph_v2.0/ch/ch_ppocr_mobile_v2.0_det_train.tar-wget https://paddleocr.bj.bcebos.com/dygraph_v2.0/ch/ch_ppocr_server_v2.0_det_train.tar-wget https://paddleocr.bj.bcebos.com/dygraph_v2.0/ch/ch_ppocr_mobile_v2.0_rec_train.tar-wget https://paddleocr.bj.bcebos.com/dygraph_v2.0/ch/ch_ppocr_server_v2.0_rec_train.tar-wget https://paddleocr.bj.bcebos.com/dygraph_v2.0/multilingual/en_number_mobile_v2.0_rec_train.tar-wget https://paddleocr.bj.bcebos.com/dygraph_v2.0/multilingual/french_mobile_v2.0_rec_train.tar-wget https://paddleocr.bj.bcebos.com/dygraph_v2.0/multilingual/german_mobile_v2.0_rec_train.tar-wget https://paddleocr.bj.bcebos.com/dygraph_v2.0/multilingual/korean_mobile_v2.0_rec_train.tar-wget https://paddleocr.bj.bcebos.com/dygraph_v2.0/multilingual/japan_mobile_v2.0_rec_train.tar-wget https://paddleocr.bj.bcebos.com/dygraph_v2.0/multilingual/it_mobile_v2.0_rec_train.tar-wget https://paddleocr.bj.bcebos.com/dygraph_v2.0/multilingual/es_mobile_v2.0_rec_train.tar-wget https://paddleocr.bj.bcebos.com/dygraph_v2.0/multilingual/pt_mobile_v2.0_rec_train.tar-wget https://paddleocr.bj.bcebos.com/dygraph_v2.0/multilingual/ru_mobile_v2.0_rec_train.tar-wget https://paddleocr.bj.bcebos.com/dygraph_v2.0/multilingual/ar_mobile_v2.0_rec_train.tar-wget https://paddleocr.bj.bcebos.com/dygraph_v2.0/multilingual/hi_mobile_v2.0_rec_train.tar-wget https://paddleocr.bj.bcebos.com/dygraph_v2.0/multilingual/ch_tra_mobile_v2.0_rec_train.tar-wget https://paddleocr.bj.bcebos.com/dygraph_v2.0/multilingual/ug_mobile_v2.0_rec_train.tar-wget https://paddleocr.bj.bcebos.com/dygraph_v2.0/multilingual/fa_mobile_v2.0_rec_train.tar-wget https://paddleocr.bj.bcebos.com/dygraph_v2.0/multilingual/ur_mobile_v2.0_rec_train.tar-wget https://paddleocr.bj.bcebos.com/dygraph_v2.0/multilingual/rs_latin_mobile_v2.0_rec_train.tar-wget https://paddleocr.bj.bcebos.com/dygraph_v2.0/multilingual/oc_mobile_v2.0_rec_train.tar-wget https://paddleocr.bj.bcebos.com/dygraph_v2.0/multilingual/mr_mobile_v2.0_rec_train.tar-wget https://paddleocr.bj.bcebos.com/dygraph_v2.0/multilingual/ne_mobile_v2.0_rec_train.tar-wget https://paddleocr.bj.bcebos.com/dygraph_v2.0/multilingual/rs_cyrillic_mobile_v2.0_rec_train.tar-wget https://paddleocr.bj.bcebos.com/dygraph_v2.0/multilingual/bg_mobile_v2.0_rec_train.tar-wget https://paddleocr.bj.bcebos.com/dygraph_v2.0/multilingual/uk_mobile_v2.0_rec_train.tar-wget https://paddleocr.bj.bcebos.com/dygraph_v2.0/multilingual/be_mobile_v2.0_rec_train.tar-wget https://paddleocr.bj.bcebos.com/dygraph_v2.0/multilingual/te_mobile_v2.0_rec_train.tar-wget https://paddleocr.bj.bcebos.com/dygraph_v2.0/multilingual/kn_mobile_v2.0_rec_train.tar-wget https://paddleocr.bj.bcebos.com/dygraph_v2.0/multilingual/ta_mobile_v2.0_rec_train.tar---tar xf ./ch_ppocr_mobile_v2.0_cls_train.tar-tar xf ./ch_ppocr_mobile_v2.0_det_train.tar-tar xf ./ch_ppocr_server_v2.0_det_train.tar-tar xf ./ch_ppocr_mobile_v2.0_rec_train.tar-tar xf ./ch_ppocr_server_v2.0_rec_train.tar-tar xf ./ch_tra_mobile_v2.0_rec_train.tar-tar xf ./en_number_mobile_v2.0_rec_train.tar-tar xf ./french_mobile_v2.0_rec_train.tar-tar xf ./japan_mobile_v2.0_rec_train.tar-tar xf ./korean_mobile_v2.0_rec_train.tar-tar xf ./pt_mobile_v2.0_rec_train.tar-tar xf ./kn_mobile_v2.0_rec_train.tar-tar xf ./rs_cyrillic_mobile_v2.0_rec_train.tar-tar xf ./rs_latin_mobile_v2.0_rec_train.tar-tar xf ./es_mobile_v2.0_rec_train.tar--mkdir german_mobile_v2.0_rec_train-tar xf ./german_mobile_v2.0_rec_train.tar -C./german_mobile_v2.0_rec_train---mkdir it_mobile_v2.0_rec_train-tar xf ./it_mobile_v2.0_rec_train.tar -C./it_mobile_v2.0_rec_train--mkdir ru_mobile_v2.0_rec_train-tar xf ./ru_mobile_v2.0_rec_train.tar -C./ru_mobile_v2.0_rec_train--mkdir ar_mobile_v2.0_rec_train-tar xf ./ar_mobile_v2.0_rec_train.tar -C./ar_mobile_v2.0_rec_train--mkdir hi_mobile_v2.0_rec_train-tar xf ./hi_mobile_v2.0_rec_train.tar -C./hi_mobile_v2.0_rec_train--mkdir ug_mobile_v2.0_rec_train-tar xf ./ug_mobile_v2.0_rec_train.tar -C./ug_mobile_v2.0_rec_train--mkdir fa_mobile_v2.0_rec_train-tar xf ./fa_mobile_v2.0_rec_train.tar -C./fa_mobile_v2.0_rec_train--mkdir ur_mobile_v2.0_rec_train-tar xf ./ur_mobile_v2.0_rec_train.tar -C./ur_mobile_v2.0_rec_train--mkdir oc_mobile_v2.0_rec_train-tar xf ./oc_mobile_v2.0_rec_train.tar -C./oc_mobile_v2.0_rec_train-mkdir mr_mobile_v2.0_rec_train-tar xf ./mr_mobile_v2.0_rec_train.tar -C./mr_mobile_v2.0_rec_train--mkdir ne_mobile_v2.0_rec_train-tar xf ./ne_mobile_v2.0_rec_train.tar -C./ne_mobile_v2.0_rec_train--mkdir bg_mobile_v2.0_rec_train-tar xf ./bg_mobile_v2.0_rec_train.tar -C./bg_mobile_v2.0_rec_train--mkdir uk_mobile_v2.0_rec_train-tar xf ./uk_mobile_v2.0_rec_train.tar -C./uk_mobile_v2.0_rec_train--mkdir be_mobile_v2.0_rec_train-tar xf ./be_mobile_v2.0_rec_train.tar -C./be_mobile_v2.0_rec_train--mkdir te_mobile_v2.0_rec_train-tar xf ./te_mobile_v2.0_rec_train.tar -C./te_mobile_v2.0_rec_train--mkdir ta_mobile_v2.0_rec_train-tar xf ./ta_mobile_v2.0_rec_train.tar -C./ta_mobile_v2.0_rec_traindiff --git a/tools/modelconvert.py b/tools/modelconvert.pydeleted file mode 100755index b8f5560..0000000--- a/tools/modelconvert.py+++ /dev/null@@ -1,33 +0,0 @@-import os-import onnx--def WalkDir(dirlist,filelist,dirname):- try:- ls=os.listdir(dirname)- except:- print(" Access Deny.")- else:- for fn in ls:- temp=os.path.join(dirname,fn)- if (os.path.isdir(temp)):- dirlist.append(temp)- # WalkDir(dirlist,filelist,temp)- else:- if temp.endswith(".onnx"):- filelist.append(temp)- return dirlist,filelist--def ConvertModel(srcfile, dstfile):- onnx_model = onnx.load(srcfile)- onnx_model.graph.input[0].type.tensor_type.shape.dim[2].dim_param = '?' # w涓哄姩鎬佽緭鍏?- onnx_model.graph.input[0].type.tensor_type.shape.dim[3].dim_param = '?'- onnx.save(onnx_model, dstfile)---dirlist=[]-filelist=[]-WalkDir(dirlist,filelist,os.getcwd())--for file in filelist:- dstfile=file+".new"- ConvertModel(file,dstfile)diff --git a/tools/program.py b/tools/program.pydeleted file mode 100755index b8c94db..0000000--- a/tools/program.py+++ /dev/null@@ -1,376 +0,0 @@-# Copyright (c) 2020 PaddlePaddle Authors. All Rights Reserved.-#-# Licensed under the Apache License, Version 2.0 (the "License");-# you may not use this file except in compliance with the License.-# You may obtain a copy of the License at-#-# http://www.apache.org/licenses/LICENSE-2.0-#-# Unless required by applicable law or agreed to in writing, software-# distributed under the License is distributed on an "AS IS" BASIS,-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.-# See the License for the specific language governing permissions and-# limitations under the License.--from __future__ import absolute_import-from __future__ import division-from __future__ import print_function--import os-import sys-import yaml-import time-import shutil-import paddle-import paddle.distributed as dist-from tqdm import tqdm-from argparse import ArgumentParser, RawDescriptionHelpFormatter--from ppocr.utils.stats import TrainingStats-from ppocr.utils.save_load import save_model-from ppocr.utils.utility import print_dict-from ppocr.utils.logging import get_logger-from ppocr.data import build_dataloader-import numpy as np---class ArgsParser(ArgumentParser):- def __init__(self):- super(ArgsParser, self).__init__(- formatter_class=RawDescriptionHelpFormatter)- self.add_argument("-c", "--config", help="configuration file to use")- self.add_argument(- "-o", "--opt", nargs='+', help="set configuration options")- self.add_argument("-ih","--height",help="config input height")- self.add_argument("-iw","--width",help="config input width")-- def parse_args(self, argv=None):- args = super(ArgsParser, self).parse_args(argv)- assert args.config is not None, \- "Please specify --config=configure_file_path."- args.opt = self._parse_opt(args.opt)- return args-- def _parse_opt(self, opts):- config = {}- if not opts:- return config- for s in opts:- s = s.strip()- k, v = s.split('=')- config[k] = yaml.load(v, Loader=yaml.Loader)- return config---class AttrDict(dict):- """Single level attribute dict, NOT recursive"""-- def __init__(self, **kwargs):- super(AttrDict, self).__init__()- super(AttrDict, self).update(kwargs)-- def __getattr__(self, key):- if key in self:- return self[key]- raise AttributeError("object has no attribute '{}'".format(key))---global_config = AttrDict()--default_config = {'Global': {'debug': False, }}---def load_config(file_path):- """- Load config from yml/yaml file.- Args:- file_path (str): Path of the config file to be loaded.- Returns: global config- """- merge_config(default_config)- _, ext = os.path.splitext(file_path)- assert ext in ['.yml', '.yaml'], "only support yaml files for now"- merge_config(yaml.load(open(file_path, 'rb'), Loader=yaml.Loader))- return global_config---def merge_config(config):- """- Merge config into global config.- Args:- config (dict): Config to be merged.- Returns: global config- """- for key, value in config.items():- if "." not in key:- if isinstance(value, dict) and key in global_config:- global_config[key].update(value)- else:- global_config[key] = value- else:- sub_keys = key.split('.')- assert (- sub_keys[0] in global_config- ), "the sub_keys can only be one of global_config: {}, but get: {}, please check your running command".format(- global_config.keys(), sub_keys[0])- cur = global_config[sub_keys[0]]- for idx, sub_key in enumerate(sub_keys[1:]):- if idx == len(sub_keys) - 2:- cur[sub_key] = value- else:- cur = cur[sub_key]---def check_gpu(use_gpu):- """- Log error and exit when set use_gpu=true in paddlepaddle- cpu version.- """- err = "Config use_gpu cannot be set as true while you are " \- "using paddlepaddle cpu version ! \nPlease try: \n" \- "\t1. Install paddlepaddle-gpu to run model on GPU \n" \- "\t2. Set use_gpu as false in config file to run " \- "model on CPU"-- try:- if use_gpu and not paddle.is_compiled_with_cuda():- print(err)- sys.exit(1)- except Exception as e:- pass---def train(config,- train_dataloader,- valid_dataloader,- device,- model,- loss_class,- optimizer,- lr_scheduler,- post_process_class,- eval_class,- pre_best_model_dict,- logger,- vdl_writer=None):- cal_metric_during_train = config['Global'].get('cal_metric_during_train',- False)- log_smooth_window = config['Global']['log_smooth_window']- epoch_num = config['Global']['epoch_num']- print_batch_step = config['Global']['print_batch_step']- eval_batch_step = config['Global']['eval_batch_step']-- global_step = 0- start_eval_step = 0- if type(eval_batch_step) == list and len(eval_batch_step) >= 2:- start_eval_step = eval_batch_step[0]- eval_batch_step = eval_batch_step[1]- logger.info(- "During the training process, after the {}th iteration, an evaluation is run every {} iterations".- format(start_eval_step, eval_batch_step))- save_epoch_step = config['Global']['save_epoch_step']- save_model_dir = config['Global']['save_model_dir']- if not os.path.exists(save_model_dir):- os.makedirs(save_model_dir)- main_indicator = eval_class.main_indicator- best_model_dict = {main_indicator: 0}- best_model_dict.update(pre_best_model_dict)- train_stats = TrainingStats(log_smooth_window, ['lr'])- model.train()-- if 'start_epoch' in best_model_dict:- start_epoch = best_model_dict['start_epoch']- else:- start_epoch = 1-- for epoch in range(start_epoch, epoch_num + 1):- train_dataloader = build_dataloader(- config, 'Train', device, logger, seed=epoch)- train_batch_cost = 0.0- train_reader_cost = 0.0- batch_sum = 0- batch_start = time.time()- for idx, batch in enumerate(train_dataloader):- train_reader_cost += time.time() - batch_start- if idx >= len(train_dataloader):- break- lr = optimizer.get_lr()- images = batch[0]- preds = model(images)- loss = loss_class(preds, batch)- avg_loss = loss['loss']- avg_loss.backward()- optimizer.step()- optimizer.clear_grad()-- train_batch_cost += time.time() - batch_start- batch_sum += len(images)-- if not isinstance(lr_scheduler, float):- lr_scheduler.step()-- # logger and visualdl- stats = {k: v.numpy().mean() for k, v in loss.items()}- stats['lr'] = lr- train_stats.update(stats)-- if cal_metric_during_train: # only rec and cls need- batch = [item.numpy() for item in batch]- post_result = post_process_class(preds, batch[1])- eval_class(post_result, batch)- metirc = eval_class.get_metric()- train_stats.update(metirc)-- if vdl_writer is not None and dist.get_rank() == 0:- for k, v in train_stats.get().items():- vdl_writer.add_scalar('TRAIN/{}'.format(k), v, global_step)- vdl_writer.add_scalar('TRAIN/lr', lr, global_step)-- if dist.get_rank(- ) == 0 and global_step > 0 and global_step % print_batch_step == 0:- logs = train_stats.log()- strs = 'epoch: [{}/{}], iter: {}, {}, reader_cost: {:.5f} s, batch_cost: {:.5f} s, samples: {}, ips: {:.5f}'.format(- epoch, epoch_num, global_step, logs, train_reader_cost /- print_batch_step, train_batch_cost / print_batch_step,- batch_sum, batch_sum / train_batch_cost)- logger.info(strs)- train_batch_cost = 0.0- train_reader_cost = 0.0- batch_sum = 0- # eval- if global_step > start_eval_step and \- (global_step - start_eval_step) % eval_batch_step == 0 and dist.get_rank() == 0:- cur_metric = eval(model, valid_dataloader, post_process_class,- eval_class)- cur_metric_str = 'cur metric, {}'.format(', '.join(- ['{}: {}'.format(k, v) for k, v in cur_metric.items()]))- logger.info(cur_metric_str)-- # logger metric- if vdl_writer is not None:- for k, v in cur_metric.items():- if isinstance(v, (float, int)):- vdl_writer.add_scalar('EVAL/{}'.format(k),- cur_metric[k], global_step)- if cur_metric[main_indicator] >= best_model_dict[- main_indicator]:- best_model_dict.update(cur_metric)- best_model_dict['best_epoch'] = epoch- save_model(- model,- optimizer,- save_model_dir,- logger,- is_best=True,- prefix='best_accuracy',- best_model_dict=best_model_dict,- epoch=epoch)- best_str = 'best metric, {}'.format(', '.join([- '{}: {}'.format(k, v) for k, v in best_model_dict.items()- ]))- logger.info(best_str)- # logger best metric- if vdl_writer is not None:- vdl_writer.add_scalar('EVAL/best_{}'.format(main_indicator),- best_model_dict[main_indicator],- global_step)- global_step += 1- batch_start = time.time()- if dist.get_rank() == 0:- save_model(- model,- optimizer,- save_model_dir,- logger,- is_best=False,- prefix='latest',- best_model_dict=best_model_dict,- epoch=epoch)- if dist.get_rank() == 0 and epoch > 0 and epoch % save_epoch_step == 0:- save_model(- model,- optimizer,- save_model_dir,- logger,- is_best=False,- prefix='iter_epoch_{}'.format(epoch),- best_model_dict=best_model_dict,- epoch=epoch)- best_str = 'best metric, {}'.format(', '.join(- ['{}: {}'.format(k, v) for k, v in best_model_dict.items()]))- logger.info(best_str)- if dist.get_rank() == 0 and vdl_writer is not None:- vdl_writer.close()- return---def eval(model, valid_dataloader, post_process_class, eval_class):- model.eval()- with paddle.no_grad():- total_frame = 0.0- total_time = 0.0- pbar = tqdm(total=len(valid_dataloader), desc='eval model:')- for idx, batch in enumerate(valid_dataloader):- if idx >= len(valid_dataloader):- break- images = batch[0]- start = time.time()- preds = model(images)-- batch = [item.numpy() for item in batch]- # Obtain usable results from post-processing methods- post_result = post_process_class(preds, batch[1])- total_time += time.time() - start- # Evaluate the results of the current batch- eval_class(post_result, batch)- pbar.update(1)- total_frame += len(images)- # Get final metric,eg. acc or hmean- metric = eval_class.get_metric()-- pbar.close()- model.train()- metric['fps'] = total_frame / total_time- return metric---def preprocess(is_train=False):- FLAGS = ArgsParser().parse_args()- config = load_config(FLAGS.config)- merge_config(FLAGS.opt)-- # check if set use_gpu=True in paddlepaddle cpu version- use_gpu = config['Global']['use_gpu']- check_gpu(use_gpu)-- alg = config['Architecture']['algorithm']- assert alg in [- 'EAST', 'DB', 'SAST', 'Rosetta', 'CRNN', 'STARNet', 'RARE', 'SRN', 'CLS'- ]-- device = 'gpu:{}'.format(dist.ParallelEnv().dev_id) if use_gpu else 'cpu'- device = paddle.set_device(device)-- config['Global']['distributed'] = dist.get_world_size() != 1- if is_train:- # save_config- save_model_dir = config['Global']['save_model_dir']- os.makedirs(save_model_dir, exist_ok=True)- with open(os.path.join(save_model_dir, 'config.yml'), 'w') as f:- yaml.dump(- dict(config), f, default_flow_style=False, sort_keys=False)- log_file = '{}/train.log'.format(save_model_dir)- else:- log_file = None- logger = get_logger(name='root', log_file=log_file)- if config['Global']['use_visualdl']:- from visualdl import LogWriter- vdl_writer_path = '{}/vdl/'.format(save_model_dir)- os.makedirs(vdl_writer_path, exist_ok=True)- vdl_writer = LogWriter(logdir=vdl_writer_path)- else:- vdl_writer = None- print_dict(config, logger)- logger.info('train with paddle {} and device {}'.format(paddle.__version__,- device))- return config, device, logger, vdl_writerdiff --git a/tools/test.py b/tools/test.pydeleted file mode 100755index 8af02a5..0000000--- a/tools/test.py+++ /dev/null@@ -1,8 +0,0 @@-import numpy as np-import onnx-import onnxruntime as ort-x=np.random.rand(1,3,32,256)-session = ort.InferenceSession("ch_ppocr_mobile_v2.0_det_infer.onnx.new")-onnx_inputs = { session.get_inputs()[0].name: x.astype(np.float32)}-onnx_outputs=session.run(None, onnx_inputs)-print(onnx_outputs)