1 /* 2 * Copyright 2023 Unionman Technology Co., Ltd. 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 * 16 */ 17 18 #ifndef _AMLOGIC_NN_DEMO_H 19 #define _AMLOGIC_NN_DEMO_H 20 21 #include "nn_sdk.h" 22 #include "nn_util.h" 23 24 #ifdef __cplusplus 25 extern "C" { 26 #endif 27 #ifdef YOLOV2 28 const int WIDTH = 416; 29 const int HIGH = 416; 30 #else 31 const int WIDTH = 640; 32 const int HIGH = 640; 33 #endif 34 const int CHANNEL = 3; 35 36 typedef struct __nn_image_classify { 37 float score[5]; 38 unsigned int topClass[5]; 39 } img_classify_out_t; 40 41 typedef struct __nn_obj_detect { 42 unsigned int detNum; 43 detBox *pBox; 44 } obj_detect_out_t; 45 46 void activate_array(float *start, int num); 47 int entry_index(int lw, int lh, int lclasses, int loutputs, int batch, int location, int entry); 48 void softmax(float *input, int n, float temp, float *output); 49 void flatten(float *x, int size, int layers, int batch, int forward); 50 void do_nms_sort(box *boxes, float **probs, int total, int classes, float thresh); 51 int nms_comparator(const void *pa, const void *pb); 52 float box_iou(box a, box b); 53 float box_union(box a, box b); 54 float box_intersection(box a, box b); 55 float overlap(float x1, float w1, float x2, float w2); 56 float logistic_activate(float x); 57 float sigmod(float x); 58 unsigned char *transpose(const unsigned char *src, int width, int height); 59 void *post_process_all_module(aml_module_t type, nn_output *pOut); 60 int max_index(float *a, int n); 61 box get_region_box(float *x, float *biases, int n, int index, int i, int j, int w, int h); 62 void process_top5(float *buf, unsigned int num, img_classify_out_t *clsout); 63 void *postprocess_object_detect(nn_output *pout); 64 unsigned char *get_jpeg_rawData(const char *name, unsigned int width, unsigned int height); 65 void *postprocess_yolov5(nn_output *pout); 66 67 #ifdef __cplusplus 68 } // extern "C" 69 #endif 70 #endif