forked from majianjia/nnom
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnnom_utils.h
80 lines (62 loc) · 2.43 KB
/
nnom_utils.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
/*
* Copyright (c) 2018-2019
* Jianjia Ma, Wearable Bio-Robotics Group (WBR)
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
* 2019-02-05 Jianjia Ma The first version
*/
#ifndef __NNOM_UTILS_H__
#define __NNOM_UTILS_H__
#include <stdint.h>
#include <string.h>
#include <stdbool.h>
#include "nnom.h"
typedef struct _nnom_predict_t
{
uint16_t *confusion_mat; // confusiong matrix
uint32_t *top_k; // which stored the num of prediction in rank_k, example: Top-2 = top_k[0]+top_k[1]
nnom_model_t *model; // the model to run
int8_t *buf_prediction; // the pointer to the output of softmax layer(normally the end of classifier).
// setting
uint32_t label_num; // number of types in classification
uint32_t top_k_size; // number of k that wants to know.
// running
uint32_t predict_count; // how many prediction is done
//timing
uint32_t t_run_total; // total running time
uint32_t t_predict_start; // when it is initial
uint32_t t_predict_total; // total time of the whole test
} nnom_predict_t;
// create a prediction
// input model, the buf pointer to the softwmax output (Temporary, this can be extract from model)
// the size of softmax output (the num of lable)
// the top k that wants to record.
nnom_predict_t *prediction_create(nnom_model_t *m, int8_t *buf_prediction, size_t label_num, size_t top_k_size); // currently int8_t
// after a new data is set in input
// feed data to prediction
// input the current label, (range from 0 to total number of label -1)
// (the current input data should be set by user manully to the input buffer of the model.)
// return NN_ARGUMENT_ERROR if parameter error
nnom_status_t prediction_run(nnom_predict_t *pre, uint32_t true_label, uint32_t* predict_label, float* prob);
// to mark prediction finished
void prediction_end(nnom_predict_t *pre);
// free all resources
void prediction_delete(nnom_predict_t *pre);
// print matrix
void prediction_matrix(nnom_predict_t *pre);
// print top-k
void prediction_top_k(nnom_predict_t *pre);
// this function is to print sumarry
void prediction_summary(nnom_predict_t *pre);
// -------------------------------
// stand alone prediction API
// this api test one set of data, return the prediction
// return the predicted label
// return NN_ARGUMENT_ERROR if parameter error
nnom_status_t nnom_predict(nnom_model_t *m, uint32_t *label, float *prob);
void model_stat(nnom_model_t *m);
#endif