This repository has been archived by the owner on Jun 23, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathlibtf.h
97 lines (82 loc) · 4.79 KB
/
libtf.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
/* This file is part of the OpenMV project.
* Copyright (c) 2013-2024 Ibrahim Abdelkader <[email protected]> & Kwabena W. Agyeman <[email protected]>
* This work is licensed under the MIT license, see the file LICENSE for details.
*/
#ifndef __LIBTF_H
#define __LIBTF_H
#define LIBTF_TENSOR_ARENA_ALIGNMENT 16
#ifdef __cplusplus
extern "C" {
#endif
typedef enum libtf_datatype {
LIBTF_DATATYPE_UINT8,
LIBTF_DATATYPE_INT8,
LIBTF_DATATYPE_FLOAT
} libtf_datatype_t;
typedef struct libtf_parameters {
size_t tensor_arena_size;
size_t input_height, input_width, input_channels;
libtf_datatype_t input_datatype;
float input_scale;
int input_zero_point;
size_t output_height, output_width, output_channels;
libtf_datatype_t output_datatype;
float output_scale;
int output_zero_point;
} libtf_parameters_t;
// Call this first to get the model parameters.
// Returns 0 on success and 1 on failure.
// Errors are printed to stdout.
int libtf_get_parameters_default(const unsigned char *model_data, // TensorFlow Lite binary model (8-bit quant).
unsigned char *tensor_arena, // As big as you can make it scratch buffer.
size_t tensor_arena_size, // Size of the above scratch buffer.
libtf_parameters_t *params); // Struct to hold model parameters.
// Call this first to get the model parameters.
// Returns 0 on success and 1 on failure.
// Errors are printed to stdout.
int libtf_get_parameters_fullops(const unsigned char *model_data, // TensorFlow Lite binary model (8-bit quant).
unsigned char *tensor_arena, // As big as you can make it scratch buffer.
size_t tensor_arena_size, // Size of the above scratch buffer.
libtf_parameters_t *params); // Struct to hold model parameters.
// Callback to populate the model input data byte array (laid out in [height][width][channel] order).
typedef void (*libtf_input_data_callback_t)(void *callback_data,
void *model_input,
libtf_parameters_t *params);
// Callback to use the model output data byte array (laid out in [height][width][channel] order).
typedef void (*libtf_output_data_callback_t)(void *callback_data,
void *model_output,
libtf_parameters_t *params);
// Returns 0 on success and 1 on failure.
// Errors are printed to stdout.
int libtf_invoke_default(const unsigned char *model_data, // TensorFlow Lite binary model (8-bit quant).
unsigned char *tensor_arena, // As big as you can make it scratch buffer.
libtf_parameters_t *params, // Struct with model parameters.
libtf_input_data_callback_t input_callback, // Callback to populate the model input data byte array.
void *input_callback_data, // User data structure passed to input callback.
libtf_output_data_callback_t output_callback, // Callback to use the model output data byte array.
void *output_callback_data); // User data structure passed to output callback.
// Returns 0 on success and 1 on failure.
// Errors are printed to stdout.
int libtf_invoke_fullops(const unsigned char *model_data, // TensorFlow Lite binary model (8-bit quant).
unsigned char *tensor_arena, // As big as you can make it scratch buffer.
libtf_parameters_t *params, // Struct with model parameters.
libtf_input_data_callback_t input_callback, // Callback to populate the model input data byte array.
void *input_callback_data, // User data structure passed to input callback.
libtf_output_data_callback_t output_callback, // Callback to use the model output data byte array.
void *output_callback_data); // User data structure passed to output callback.
// Returns 0 on success and 1 on failure.
// Errors are printed to stdout.
int libtf_initialize_micro_features();
// Returns 0 on success and 1 on failure.
// Errors are printed to stdout.
// Converts audio sample data into a more compact form
// that's appropriate for feeding into a neural network.
int libtf_generate_micro_features(const int16_t *input, // Audio samples
int input_size, // Audio sample size
int output_size, // Slice data size
int8_t *output, // Slice data
size_t *num_samples_read); // Number of samples used
#ifdef __cplusplus
}
#endif
#endif // __LIBTF_H