You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
351 lines
11 KiB
351 lines
11 KiB
/******************************************************************************* |
|
* @file lib_data_process.h |
|
* @brief This file shows the dproc library API. |
|
* |
|
* History: |
|
* 2018/10/23 - [Hao Qian] created file |
|
* |
|
* Copyright (c) 2018 Ambarella International LP |
|
* |
|
* This file and its contents ( "Software" ) are protected by intellectual |
|
* property rights including, without limitation, U.S. and/or foreign |
|
* copyrights. This Software is also the confidential and proprietary |
|
* information of Ambarella International LP and its licensors. You may not use, reproduce, |
|
* disclose, distribute, modify, or otherwise prepare derivative works of this |
|
* Software or any portion thereof except pursuant to a signed license agreement |
|
* or nondisclosure agreement with Ambarella International LP or its authorized affiliates. |
|
* In the absence of such an agreement, you agree to promptly notify and return |
|
* this Software to Ambarella International LP. |
|
* |
|
* This file includes sample code and is only for internal testing and evaluation. If you |
|
* distribute this sample code (whether in source, object, or binary code form), it will be |
|
* without any warranty or indemnity protection from Ambarella International LP or its affiliates. |
|
* |
|
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, |
|
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, |
|
* MERCHANTABILITY, AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
|
* IN NO EVENT SHALL AMBARELLA INTERNATIONAL LP OR ITS AFFILIATES BE LIABLE FOR ANY DIRECT, |
|
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
|
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
|
* LOSS OF USE, DATA, OR PROFITS; COMPUTER FAILURE OR MALFUNCTION; OR BUSINESS |
|
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
|
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
|
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
|
* POSSIBILITY OF SUCH DAMAGE. |
|
* |
|
******************************************************************************/ |
|
|
|
#ifndef _DPROC_LIB_H |
|
#define _DPROC_LIB_H |
|
|
|
#ifdef __cplusplus |
|
extern "C" { |
|
#endif |
|
|
|
#include <stdint.h> |
|
|
|
#define AMBA_API __attribute__((visibility("default"))) |
|
|
|
/*! |
|
* @addtogroup dproc-helper |
|
* @{ |
|
*/ |
|
|
|
/*! |
|
* @brief Define the layer type of dproc. |
|
*/ |
|
enum dproc_layer_type { |
|
DPROC_SSD_DETECTION_OUT = 0, /*!< for SSD */ |
|
DPROC_YOLOV3_OUT = 1, /*!< for YOLOV3 or TINY_YOLOV3 */ |
|
DPROC_TYPE_NUM, |
|
}; |
|
|
|
|
|
/*************** Share Structure ***************/ |
|
/*! |
|
* @brief Description of the parameters of the bounding box. |
|
*/ |
|
typedef struct dproc_bbox_param_s { |
|
float x_min; /*!< X-coordinate of starting point */ |
|
float y_min; /*!< Y-coordinate of starting point */ |
|
float x_max; /*!< X-coordinate of end point */ |
|
float y_max; /*!< Y-coordinate of end point */ |
|
} dproc_bbox_param_t; |
|
/*************** Share Structure ***************/ |
|
|
|
|
|
/*************** SSD detection_out ***************/ |
|
/*! |
|
* @brief Some debugging information for SSD. |
|
*/ |
|
typedef struct dproc_ssd_class_dbg_info_s { |
|
int num_bboxes_above_threshold; /*!< The number of bbox that exceed the threshold */ |
|
int num_bboxes_post_nms; /*!< The number of bbox returned by nms() */ |
|
} dproc_ssd_class_dbg_info_t; |
|
|
|
/*! |
|
* @brief Description of the coordinate type of the bounding box. |
|
*/ |
|
typedef enum amba_bbox_codetype_s { |
|
AMBA_BBOX_CORNER = 0, |
|
AMBA_BBOX_CENTER_SIZE = 1, /*!< The coordinate type of the bbox is CENTER */ |
|
AMBA_BBOX_CORNER_SIZE = 2, /*!< The coordinate type of the bbox is CORNER */ |
|
AMBA_BBOX_NUM_CODETYPE, |
|
} amba_bbox_codetype_t; |
|
|
|
/*************** TF SSD Scale ***************/ |
|
/*! |
|
* @brief Description of the scale factors of SSD for TF. |
|
*/ |
|
typedef struct ssd_tf_scale_factors_s { |
|
uint32_t center_x_scale; /*!< The scale value of X-coordinate for the center point of bbox */ |
|
uint32_t center_y_scale; /*!< The scale value of Y-coordinate for the center point of bbox */ |
|
uint32_t width_scale; /*!< The scale value of the width of bbox */ |
|
uint32_t height_scale; /*!< The scale value of the height of bbox */ |
|
} ssd_tf_scale_factors_t; |
|
/*************** TF SSD Scale ***************/ |
|
|
|
/*! |
|
* @brief Description of the configuration of SSD detection output. |
|
*/ |
|
typedef struct dproc_ssd_detection_output_config_s { |
|
/* basic related */ |
|
uint16_t img_width; /*!< the width of output image */ |
|
uint16_t img_height; /*!< the height of output image */ |
|
uint32_t num_classes; /*!< the number of classes */ |
|
uint32_t background_label_id; /*!< the label id of background */ |
|
uint32_t mbox_loc_num_elements; /*!< Number of all elements */ |
|
uint32_t num_all_bboxes; /*!< Number of all bboxes */ |
|
|
|
/* detection related */ |
|
float conf_threshold; /*!< the threshold for filter_bboxes */ |
|
uint32_t keep_top_k; /*!< Keep the maximum number of objects */ |
|
|
|
/* nms related */ |
|
float nms_threshold; /*!< the threshold for nms */ |
|
uint32_t nms_top_k; /*!< keep the maximum number of objects by nms*/ |
|
|
|
/* bounding box related */ |
|
/*! |
|
* refer to struct @ref amba_bbox_codetype_s, SSD supports CENTER_SIZE |
|
*/ |
|
amba_bbox_codetype_t code_type; |
|
uint32_t share_location : 1; /*!< only supports True */ |
|
uint32_t unnormalized : 1; /*!< whether the parameter is unnormalized */ |
|
uint32_t reserved : 30; |
|
|
|
/* TF Related */ |
|
/*! |
|
* refer to struct @ref ssd_tf_scale_factors_s. |
|
*/ |
|
ssd_tf_scale_factors_t scale_factors; |
|
|
|
} dproc_ssd_detection_output_config_t; |
|
|
|
/*! |
|
* @brief Output parameters after running SSD. |
|
*/ |
|
typedef struct dproc_run_ssd_detection_output_param_s { |
|
uint8_t *mbox_loc; /*!< output from cavalry */ |
|
uint8_t *mbox_conf_flatten; /*!< output from cavalry */ |
|
|
|
/*! |
|
* Binary which is generated by CV offline tool. |
|
*/ |
|
float *mbox_priorbox; |
|
} dproc_run_ssd_detection_output_param_t; |
|
|
|
/*! |
|
* @brief Description of the result of SSD detection output. |
|
*/ |
|
typedef struct dproc_ssd_detection_output_result_s { |
|
int label; /*!< label id */ |
|
float score; /*!< score */ |
|
|
|
dproc_bbox_param_t bbox; /*!< refer to struct @ref dproc_bbox_param_s. */ |
|
} dproc_ssd_detection_output_result_t; |
|
/*************** SSD detection_out ***************/ |
|
|
|
|
|
/*************** Yolov3 yolo layer ***************/ |
|
/*! |
|
* @brief The number of anchor for TINY_YOLOV3. It is a constant. |
|
*/ |
|
#define TINY_YOLOV3_ANCHOR_NUM 12 |
|
|
|
/*! |
|
* @brief The number of anchor for YOLOV3. It is a constant. |
|
*/ |
|
#define YOLOV3_ANCHOR_NUM 18 |
|
|
|
/*! |
|
* @brief The number of feature map for YOLOV3 or TINY_YOLOV3. |
|
*/ |
|
typedef enum amba_yolov3_feature_type_s { |
|
AMBA_YOLOV3_FEATURE_MAP_32 = 0, |
|
AMBA_YOLOV3_FEATURE_MAP_16 = 1, |
|
AMBA_YOLOV3_FEATURE_MAP_8 = 2, /*!< For TINY_YOLOV3 */ |
|
AMBA_YOLOV3_FEATURE_NUM = 3, /*!< For YOLOV3 */ |
|
} amba_yolov3_feature_type_t; |
|
|
|
/*! |
|
* @brief Description of the configuration of YOLOV3 detection output. |
|
*/ |
|
typedef struct dproc_yolov3_output_config_s { |
|
/* basic related */ |
|
uint16_t img_width; /*!< the width of output image */ |
|
uint16_t img_height; /*!< the height of output image */ |
|
uint32_t num_classes; /*!< the number of classes */ |
|
|
|
/* detection and nms threshold */ |
|
float conf_threshold; /*!< the threshold for yolov3_layer */ |
|
float nms_threshold; /*!< the threshold for nms */ |
|
|
|
/* anchors */ |
|
float *anchors; /*!< Address of the storage anchor */ |
|
|
|
/* others */ |
|
uint32_t tiny_enable : 1; /*!< default is full yolov3, use this to enable tiny_yolov3 */ |
|
uint32_t unnormalized : 1; /*!< whether the parameter is unnormalized */ |
|
uint32_t padding_disable : 1; /*!< whether padding is disabled */ |
|
uint32_t reserved : 29; |
|
|
|
} dproc_yolov3_output_config_t; |
|
|
|
/*! |
|
* @brief Description of the parameters of YOLOV3 output. |
|
*/ |
|
typedef struct dproc_run_yolov3_output_param_s { |
|
/*! |
|
* Output from cavalry. |
|
* YOLOV3 use 3 feature maps, TINY_YOLOV3 only use 2 feature maps. |
|
*/ |
|
float *feature_map[AMBA_YOLOV3_FEATURE_NUM]; |
|
} dproc_run_yolov3_output_param_t; |
|
|
|
/*! |
|
* @brief Description of the parameters of YOLOV3 output result. |
|
*/ |
|
typedef struct dproc_yolov3_output_result_s { |
|
uint32_t valid : 1; |
|
uint32_t reserved : 31; |
|
int label; |
|
float score; |
|
|
|
dproc_bbox_param_t bbox; /*!< refer to struct @ref dproc_bbox_param_s. */ |
|
} dproc_yolov3_output_result_t; |
|
/*************** Yolov3 yolo layer ***************/ |
|
|
|
|
|
/*! |
|
* @brief Description of the configuration of dproc. |
|
*/ |
|
typedef struct dproc_config_s { |
|
enum dproc_layer_type layer_type; /*!< refer to enum @ref dproc_layer_type. */ |
|
|
|
union { |
|
/*! |
|
* refer to struct @ref dproc_ssd_detection_output_config_s. |
|
*/ |
|
dproc_ssd_detection_output_config_t ssd_config; |
|
/*! |
|
* refer to struct @ref dproc_yolov3_output_config_s. |
|
*/ |
|
dproc_yolov3_output_config_t yolov3_config; |
|
} arg; |
|
} dproc_config_t; |
|
|
|
/*! |
|
* @brief Description of the running parameters of dproc. |
|
*/ |
|
typedef struct dproc_run_param_s { |
|
enum dproc_layer_type layer_type; /*!< refer to enum @ref dproc_layer_type */ |
|
|
|
union { |
|
/*! |
|
* refer to struct @ref dproc_run_ssd_detection_output_param_s. |
|
*/ |
|
dproc_run_ssd_detection_output_param_t ssd_param; |
|
/*! |
|
* refer to struct @ref dproc_run_yolov3_output_param_s. |
|
*/ |
|
dproc_run_yolov3_output_param_t yolov3_param; |
|
} arg; |
|
} dproc_run_param_t; |
|
|
|
/*! |
|
* @brief Describe the results after running dproc. |
|
*/ |
|
typedef struct dproc_result_s { |
|
union { |
|
/*! |
|
* refer to struct @ref dproc_ssd_detection_output_result_s. |
|
*/ |
|
dproc_ssd_detection_output_result_t *ssd_result; |
|
/*! |
|
* refer to struct @ref dproc_yolov3_output_result_s. |
|
*/ |
|
dproc_yolov3_output_result_t *yolov3_result; |
|
} arg; |
|
|
|
union { |
|
/*! |
|
* refer to struct @ref dproc_ssd_class_dbg_info_s. |
|
*/ |
|
dproc_ssd_class_dbg_info_t *ssd_debug_info; |
|
} arg_debug; |
|
} dproc_result_t; |
|
|
|
/*! @} */ |
|
|
|
|
|
/*! |
|
* @addtogroup dproc-api |
|
* @{ |
|
*/ |
|
|
|
/*! |
|
* This API initializes control parameters for dproc. |
|
* Call it before running the library. |
|
* |
|
* @param config The required configuration for dproc initialization. |
|
* <br> User can refer to struct @ref dproc_config_s. |
|
* @return 0: success; -1: error. |
|
*/ |
|
AMBA_API int dproc_init(int dproc_ctx_id, dproc_config_t *config); |
|
|
|
/*! |
|
* This API performs corresponding data processing on the output data |
|
* of different network models. The currently supported models are |
|
* SSD, YOLOV3, TINY_YOLOV3. |
|
* Call this API after initialization. |
|
* |
|
* @param run_param The running parameters for dproc. |
|
* <br> User can refer to struct @ref dproc_run_param_s. |
|
* |
|
* @param result The results after running dproc. |
|
* <br> User can refer to struct @ref dproc_result_s. |
|
* |
|
* @return 0: success; -1: error. |
|
*/ |
|
AMBA_API int dproc_run(dproc_run_param_t *run_param, dproc_result_t *result, int dproc_ctx_id); |
|
|
|
/*! |
|
* This API is used to release the library session. |
|
* Call this API at the very end. |
|
* |
|
* @param layer_type The layer type of dproc. |
|
* <br> User can refer to enum @ref dproc_layer_type. |
|
* |
|
* @return 0: success; -1: error. |
|
*/ |
|
AMBA_API int dproc_deinit(enum dproc_layer_type layer_type, int dproc_ctx_id); |
|
|
|
/*! @} */ |
|
|
|
#ifdef __cplusplus |
|
} |
|
#endif |
|
|
|
#endif //_DPROC_LIB_H |
|
|
|
|