-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathOrtInference.h
65 lines (61 loc) · 1.54 KB
/
OrtInference.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#include <stdio.h>
#include <stdlib.h>
#include <string>
#if defined(_WIN32) && defined(__GNUC__)
#undef _WIN32
#include "onnxruntime_c_api.h"
#define _WIN32
#else
#include "onnxruntime_c_api.h"
#endif
#ifdef _WIN32
#include <Windows.h>
#define LIB_PTR HMODULE
#elif __linux__
#include <dlfcn.h>
#define LIB_PTR void *
#elif __APPLE__
#include <dlfcn.h>
#define LIB_PTR void *
#else
#define LIB_PTR void *
#endif
class OrtInference
{
private:
LIB_PTR ort_library_ptr;
const OrtApiBase *api_base;
OrtEnv *ort_env;
OrtSessionOptions *options;
OrtSession *session;
OrtAllocator *allocator;
size_t input_modes_num;
size_t output_modes_num;
OrtMemoryInfo *memory_info;
OrtValue *input_tensor;
OrtValue *output_tensor;
OrtTypeInfo *typeinfo;
const OrtTensorTypeAndShapeInfo *tensor_info;
ONNXTensorElementDataType type;
size_t num_dims;
int64_t *input_shape;
char *input_name;
char *input_names[1];
char *output_name;
char *output_names[1];
OrtTypeInfo *type_info;
OrtTensorTypeAndShapeInfo *output_info;
public:
float *output_values;
size_t output_element_size;
OrtInference();
~OrtInference();
void LoadONNXRuntimeLibrary();
void InitializeONNXEnvironment();
void CreateSessionAndLoadModel(const char *modelPath);
void GetInputOutputInfo();
void PrepareInputData(float *inputData, size_t inputSize);
void RunInference();
void ProcessOutput();
void ReleaseONNXRuntime();
};