sample_comm_nnie.h 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438
  1. #ifndef __SAMPLE_COMM_NNIE_H__
  2. #define __SAMPLE_COMM_NNIE_H__
  3. #include "hi_comm_svp.h"
  4. #include "hi_nnie.h"
  5. #include "mpi_nnie.h"
  6. #include "sample_comm_ive.h"
  7. #ifdef __cplusplus
  8. #if __cplusplus
  9. extern "C"{
  10. #endif
  11. #endif /* __cplusplus */
  12. /*16Byte align*/
  13. #define SAMPLE_SVP_NNIE_ALIGN_16 16
  14. #define SAMPLE_SVP_NNIE_ALIGN16(u32Num) ((u32Num + SAMPLE_SVP_NNIE_ALIGN_16-1) / SAMPLE_SVP_NNIE_ALIGN_16*SAMPLE_SVP_NNIE_ALIGN_16)
  15. /*32Byte align*/
  16. #define SAMPLE_SVP_NNIE_ALIGN_32 32
  17. #define SAMPLE_SVP_NNIE_ALIGN32(u32Num) ((u32Num + SAMPLE_SVP_NNIE_ALIGN_32-1) / SAMPLE_SVP_NNIE_ALIGN_32*SAMPLE_SVP_NNIE_ALIGN_32)
  18. #define SAMPLE_SVP_COORDI_NUM 4 /*num of coordinates*/
  19. #define SAMPLE_SVP_PROPOSAL_WIDTH 6 /*the width of each proposal array*/
  20. #define SAMPLE_SVP_QUANT_BASE 4096 /*the basic quantity*/
  21. #define SAMPLE_SVP_NNIE_MAX_SOFTWARE_MEM_NUM 4
  22. #define SAMPLE_SVP_NNIE_SSD_REPORT_NODE_NUM 12
  23. #define SAMPLE_SVP_NNIE_SSD_PRIORBOX_NUM 6
  24. #define SAMPLE_SVP_NNIE_SSD_SOFTMAX_NUM 6
  25. #define SAMPLE_SVP_NNIE_SSD_ASPECT_RATIO_NUM 6
  26. #define SAMPLE_SVP_NNIE_YOLOV1_WIDTH_GRID_NUM 7
  27. #define SAMPLE_SVP_NNIE_YOLOV1_HEIGHT_GRID_NUM 7
  28. #define SAMPLE_SVP_NNIE_EACH_SEG_STEP_ADDR_NUM 2
  29. #define SAMPLE_SVP_NNIE_MAX_CLASS_NUM 30
  30. #define SAMPLE_SVP_NNIE_MAX_ROI_NUM_OF_CLASS 50
  31. #define SAMPLE_SVP_NNIE_REPORT_NAME_LENGTH 64
  32. typedef struct hiSAMPLE_SVP_NNIE_MODEL_S
  33. {
  34. SVP_NNIE_MODEL_S stModel;
  35. SVP_MEM_INFO_S stModelBuf;//store Model file
  36. }SAMPLE_SVP_NNIE_MODEL_S;
  37. /*each seg input and output memory*/
  38. typedef struct hiSAMPLE_SVP_NNIE_SEG_DATA_S
  39. {
  40. SVP_SRC_BLOB_S astSrc[SVP_NNIE_MAX_INPUT_NUM];
  41. SVP_DST_BLOB_S astDst[SVP_NNIE_MAX_OUTPUT_NUM];
  42. }SAMPLE_SVP_NNIE_SEG_DATA_S;
  43. /*each seg input and output data memory size*/
  44. typedef struct hiSAMPLE_SVP_NNIE_BLOB_SIZE_S
  45. {
  46. HI_U32 au32SrcSize[SVP_NNIE_MAX_INPUT_NUM];
  47. HI_U32 au32DstSize[SVP_NNIE_MAX_OUTPUT_NUM];
  48. }SAMPLE_SVP_NNIE_BLOB_SIZE_S;
  49. /*NNIE Execution parameters */
  50. typedef struct hiSAMPLE_SVP_NNIE_PARAM_S
  51. {
  52. SVP_NNIE_MODEL_S* pstModel;
  53. HI_U32 u32TmpBufSize;
  54. HI_U32 au32TaskBufSize[SVP_NNIE_MAX_NET_SEG_NUM];
  55. //SVP_MEM_INFO_S stTaskBuf;
  56. //SVP_MEM_INFO_S stTmpBuf;
  57. SVP_MEM_INFO_S stStepBuf;//store Lstm step info
  58. SAMPLE_SVP_NNIE_SEG_DATA_S astSegData[SVP_NNIE_MAX_NET_SEG_NUM];//each seg's input and output blob
  59. SVP_NNIE_FORWARD_CTRL_S astForwardCtrl[SVP_NNIE_MAX_NET_SEG_NUM];
  60. SVP_NNIE_FORWARD_WITHBBOX_CTRL_S astForwardWithBboxCtrl[SVP_NNIE_MAX_NET_SEG_NUM];
  61. }SAMPLE_SVP_NNIE_PARAM_S;
  62. /*NNIE input or output data index*/
  63. typedef struct hiSAMPLE_SVP_NNIE_DATA_INDEX_S
  64. {
  65. HI_U32 u32SegIdx;
  66. HI_U32 u32NodeIdx;
  67. }SAMPLE_SVP_NNIE_DATA_INDEX_S;
  68. /*this struct is used to indicate the input data from which seg's input or report node*/
  69. typedef SAMPLE_SVP_NNIE_DATA_INDEX_S SAMPLE_SVP_NNIE_INPUT_DATA_INDEX_S;
  70. /*this struct is used to indicate which seg will be executed*/
  71. typedef SAMPLE_SVP_NNIE_DATA_INDEX_S SAMPLE_SVP_NNIE_PROCESS_SEG_INDEX_S;
  72. typedef enum hiSAMPLE_SVP_NNIE_NET_TYPE_E
  73. {
  74. SAMPLE_SVP_NNIE_ALEXNET_FASTER_RCNN = 0x0, /*FasterRcnn Alexnet*/
  75. SAMPLE_SVP_NNIE_VGG16_FASTER_RCNN = 0x1, /*FasterRcnn Vgg16*/
  76. SAMPLE_SVP_NNIE_PVANET_FASTER_RCNN = 0x2, /*pavenet fasterRcnn <wz>*/
  77. SAMPLE_SVP_NNIE_NET_TYPE_BUTT
  78. }SAMPLE_SVP_NNIE_NET_TYPE_E;
  79. /*NNIE configuration parameter*/
  80. typedef struct hiSAMPLE_SVP_NNIE_CFG_S
  81. {
  82. HI_CHAR *pszBGR;
  83. HI_CHAR *pszYUV;
  84. HI_CHAR *pszPic;
  85. HI_U32 u32MaxInputNum;
  86. HI_U32 u32MaxRoiNum;
  87. HI_U64 au64StepVirAddr[SAMPLE_SVP_NNIE_EACH_SEG_STEP_ADDR_NUM*SVP_NNIE_MAX_NET_SEG_NUM];//virtual addr of LSTM's or RNN's step buffer
  88. SVP_NNIE_ID_E aenNnieCoreId[SVP_NNIE_MAX_NET_SEG_NUM];
  89. }SAMPLE_SVP_NNIE_CFG_S;
  90. #define SDC_IN
  91. #define SDC_OUT
  92. #define SDC_IN_OUT
  93. typedef struct SDC_SSD_OBJECT_INFO_S
  94. {
  95. HI_S32 x_left;
  96. HI_S32 y_top;
  97. HI_S32 x_right;
  98. HI_S32 y_bottom;
  99. HI_S32 w;
  100. HI_S32 h;
  101. #if defined(__cplusplus) || defined(c_plusplus)
  102. HI_U32 c_class; /* C++ */
  103. #else
  104. HI_U32 class;
  105. #endif
  106. HI_FLOAT confidence;
  107. }SDC_SSD_OBJECT_INFO_S;
  108. typedef struct SDC_SSD_RESULT_S
  109. {
  110. SDC_IN_OUT HI_U32 numOfObject;
  111. SDC_IN HI_FLOAT thresh;
  112. SDC_OUT SDC_SSD_OBJECT_INFO_S *pObjInfo;
  113. }SDC_SSD_RESULT_S;
  114. typedef struct SDC_SSD_INPUT_SIZE_S
  115. {
  116. HI_U32 ImageWidth;
  117. HI_U32 ImageHeight;
  118. }SDC_SSD_INPUT_SIZE_S;
  119. /*CNN GetTopN parameter*/
  120. typedef struct hiSAMPLE_SVP_NNIE_CNN_SOFTWARE_PARAM_S
  121. {
  122. HI_U32 u32TopN;
  123. SVP_DST_BLOB_S stGetTopN;
  124. SVP_MEM_INFO_S stAssistBuf;
  125. }SAMPLE_SVP_NNIE_CNN_SOFTWARE_PARAM_S;
  126. /*FasterRcnn software parameter*/
  127. typedef struct hiSAMPLE_SVP_NNIE_FASTERRCNN_SOFTWARE_PARAM_S
  128. {
  129. HI_U32 au32Scales[9];
  130. HI_U32 au32Ratios[9];
  131. HI_U32 au32ConvHeight[2];
  132. HI_U32 au32ConvWidth[2];
  133. HI_U32 au32ConvChannel[2];
  134. HI_U32 u32ConvStride;
  135. HI_U32 u32NumRatioAnchors;
  136. HI_U32 u32NumScaleAnchors;
  137. HI_U32 u32OriImHeight;
  138. HI_U32 u32OriImWidth;
  139. HI_U32 u32MinSize;
  140. HI_U32 u32SpatialScale;
  141. HI_U32 u32NmsThresh;
  142. HI_U32 u32FilterThresh;
  143. HI_U32 u32NumBeforeNms;
  144. HI_U32 u32MaxRoiNum;
  145. HI_U32 u32ClassNum;
  146. HI_U32 au32ConfThresh[21];
  147. HI_U32 u32ValidNmsThresh;
  148. HI_S32* aps32Conv[2];
  149. SVP_MEM_INFO_S stRpnTmpBuf;
  150. SVP_DST_BLOB_S stRpnBbox;
  151. SVP_DST_BLOB_S stClassRoiNum;
  152. SVP_DST_BLOB_S stDstRoi;
  153. SVP_DST_BLOB_S stDstScore;
  154. SVP_MEM_INFO_S stGetResultTmpBuf;
  155. HI_CHAR* apcRpnDataLayerName[2];
  156. }SAMPLE_SVP_NNIE_FASTERRCNN_SOFTWARE_PARAM_S;
  157. /*Array rect info*/
  158. typedef struct hiSAMPLE_SVP_NNIE_RECT_ARRAY_S
  159. {
  160. HI_U32 u32ClsNum;
  161. HI_U32 u32TotalNum;
  162. HI_U32 au32RoiNum[SAMPLE_SVP_NNIE_MAX_CLASS_NUM];
  163. SAMPLE_IVE_RECT_S astRect[SAMPLE_SVP_NNIE_MAX_CLASS_NUM][SAMPLE_SVP_NNIE_MAX_ROI_NUM_OF_CLASS];
  164. } SAMPLE_SVP_NNIE_RECT_ARRAY_S;
  165. /*RFCN software parameter*/
  166. typedef struct hiSAMPLE_SVP_NNIE_RFCN_SOFTWARE_PARAM_S
  167. {
  168. HI_U32 au32Scales[9];
  169. HI_U32 au32Ratios[9];
  170. HI_U32 au32ConvHeight[2];
  171. HI_U32 au32ConvWidth[2];
  172. HI_U32 au32ConvChannel[2];
  173. HI_U32 u32ConvStride;
  174. HI_U32 u32NumRatioAnchors;
  175. HI_U32 u32NumScaleAnchors;
  176. HI_U32 u32OriImHeight;
  177. HI_U32 u32OriImWidth;
  178. HI_U32 u32MinSize;
  179. HI_U32 u32SpatialScale;
  180. HI_U32 u32NmsThresh;
  181. HI_U32 u32FilterThresh;
  182. HI_U32 u32NumBeforeNms;
  183. HI_U32 u32MaxRoiNum;
  184. HI_U32 u32ClassNum;
  185. HI_U32 au32ConfThresh[21];
  186. HI_U32 u32ValidNmsThresh;
  187. HI_S32* aps32Conv[2];
  188. HI_FLOAT af32ScoreThr[SAMPLE_SVP_NNIE_MAX_CLASS_NUM];
  189. SVP_MEM_INFO_S stRpnTmpBuf;
  190. SVP_DST_BLOB_S stRpnBbox;
  191. SVP_DST_BLOB_S stClassRoiNum;
  192. SVP_DST_BLOB_S stDstRoi;
  193. SVP_DST_BLOB_S stDstScore;
  194. SVP_MEM_INFO_S stGetResultTmpBuf;
  195. SAMPLE_SVP_NNIE_RECT_ARRAY_S stRect;
  196. HI_CHAR* apcRpnDataLayerName[2];
  197. }SAMPLE_SVP_NNIE_RFCN_SOFTWARE_PARAM_S;
  198. /*SSD software parameter*/
  199. typedef struct hiSAMPLE_SVP_NNIE_SSD_SOFTWARE_PARAM_S
  200. {
  201. /*----------------- Model Parameters ---------------*/
  202. HI_U32 au32ConvHeight[12];
  203. HI_U32 au32ConvWidth[12];
  204. HI_U32 au32ConvChannel[12];
  205. /*----------------- PriorBox Parameters ---------------*/
  206. HI_U32 au32PriorBoxWidth[6];
  207. HI_U32 au32PriorBoxHeight[6];
  208. HI_FLOAT af32PriorBoxMinSize[6][1];
  209. HI_FLOAT af32PriorBoxMaxSize[6][1];
  210. HI_U32 u32MinSizeNum;
  211. HI_U32 u32MaxSizeNum;
  212. HI_U32 u32OriImHeight;
  213. HI_U32 u32OriImWidth;
  214. HI_U32 au32InputAspectRatioNum[6];
  215. HI_FLOAT af32PriorBoxAspectRatio[6][2];
  216. HI_FLOAT af32PriorBoxStepWidth[6];
  217. HI_FLOAT af32PriorBoxStepHeight[6];
  218. HI_FLOAT f32Offset;
  219. HI_BOOL bFlip;
  220. HI_BOOL bClip;
  221. HI_S32 as32PriorBoxVar[4];
  222. /*----------------- Softmax Parameters ---------------*/
  223. HI_U32 au32SoftMaxInChn[6];
  224. HI_U32 u32SoftMaxInHeight;
  225. HI_U32 u32ConcatNum;
  226. HI_U32 u32SoftMaxOutWidth;
  227. HI_U32 u32SoftMaxOutHeight;
  228. HI_U32 u32SoftMaxOutChn;
  229. /*----------------- DetectionOut Parameters ---------------*/
  230. HI_U32 u32ClassNum;
  231. HI_U32 u32TopK;
  232. HI_U32 u32KeepTopK;
  233. HI_U32 u32NmsThresh;
  234. HI_U32 u32ConfThresh;
  235. HI_U32 au32DetectInputChn[6];
  236. HI_U32 au32ConvStride[6];
  237. SVP_MEM_INFO_S stPriorBoxTmpBuf;
  238. SVP_MEM_INFO_S stSoftMaxTmpBuf;
  239. SVP_DST_BLOB_S stClassRoiNum;
  240. SVP_DST_BLOB_S stDstRoi;
  241. SVP_DST_BLOB_S stDstScore;
  242. SVP_MEM_INFO_S stGetResultTmpBuf;
  243. }SAMPLE_SVP_NNIE_SSD_SOFTWARE_PARAM_S;
  244. /*Yolov3 software parameter*/
  245. typedef struct hiSAMPLE_SVP_NNIE_YOLOV3_SOFTWARE_PARAM_S
  246. {
  247. HI_U32 u32OriImHeight;
  248. HI_U32 u32OriImWidth;
  249. HI_U32 u32BboxNumEachGrid;
  250. HI_U32 u32ClassNum;
  251. HI_U32 au32GridNumHeight[3];
  252. HI_U32 au32GridNumWidth[3];
  253. HI_U32 u32NmsThresh;
  254. HI_U32 u32ConfThresh;
  255. HI_U32 u32MaxRoiNum;
  256. HI_FLOAT af32Bias[3][6];
  257. SVP_MEM_INFO_S stGetResultTmpBuf;
  258. SVP_DST_BLOB_S stClassRoiNum;
  259. SVP_DST_BLOB_S stDstRoi;
  260. SVP_DST_BLOB_S stDstScore;
  261. }SAMPLE_SVP_NNIE_YOLOV3_SOFTWARE_PARAM_S;
  262. /*Yolov1 software parameter*/
  263. typedef struct hiSAMPLE_SVP_NNIE_YOLOV1_SOFTWARE_PARAM_S
  264. {
  265. HI_U32 u32OriImHeight;
  266. HI_U32 u32OriImWidth;
  267. HI_U32 u32BboxNumEachGrid;
  268. HI_U32 u32ClassNum;
  269. HI_U32 u32GridNumHeight;
  270. HI_U32 u32GridNumWidth;
  271. HI_U32 u32NmsThresh;
  272. HI_U32 u32ConfThresh;
  273. SVP_MEM_INFO_S stGetResultTmpBuf;
  274. SVP_DST_BLOB_S stClassRoiNum;
  275. SVP_DST_BLOB_S stDstRoi;
  276. SVP_DST_BLOB_S stDstScore;
  277. }SAMPLE_SVP_NNIE_YOLOV1_SOFTWARE_PARAM_S;
  278. /*Yolov1 software parameter*/
  279. typedef struct hiSAMPLE_SVP_NNIE_YOLOV2_SOFTWARE_PARAM_S
  280. {
  281. HI_U32 u32OriImHeight;
  282. HI_U32 u32OriImWidth;
  283. HI_U32 u32BboxNumEachGrid;
  284. HI_U32 u32ClassNum;
  285. HI_U32 u32GridNumHeight;
  286. HI_U32 u32GridNumWidth;
  287. HI_U32 u32NmsThresh;
  288. HI_U32 u32ConfThresh;
  289. HI_U32 u32MaxRoiNum;
  290. HI_FLOAT af32Bias[10];
  291. SVP_MEM_INFO_S stGetResultTmpBuf;
  292. SVP_DST_BLOB_S stClassRoiNum;
  293. SVP_DST_BLOB_S stDstRoi;
  294. SVP_DST_BLOB_S stDstScore;
  295. }SAMPLE_SVP_NNIE_YOLOV2_SOFTWARE_PARAM_S;
  296. /*****************************************************************************
  297. * Prototype : SAMPLE_COMM_SVP_NNIE_ParamDeinit
  298. * Description : Deinit NNIE parameters
  299. * Input : SAMPLE_SVP_NNIE_PARAM_S *pstNnieParam NNIE Parameter
  300. * SAMPLE_SVP_NNIE_SOFTWARE_MEM_S *pstSoftWareMem software mem
  301. *
  302. *
  303. *
  304. *
  305. * Output :
  306. * Return Value : HI_S32,HI_SUCCESS:Success,Other:failure
  307. * Spec :
  308. * Calls :
  309. * Called By :
  310. * History:
  311. *
  312. * 1. Date : 2017-11-20
  313. * Author :
  314. * Modification : Create
  315. *
  316. *****************************************************************************/
  317. HI_S32 SAMPLE_COMM_SVP_NNIE_ParamDeinit(SAMPLE_SVP_NNIE_PARAM_S *pstNnieParam);
  318. /*****************************************************************************
  319. * Prototype : SAMPLE_COMM_SVP_NNIE_ParamInit
  320. * Description : Init NNIE parameters
  321. * Input : SAMPLE_SVP_NNIE_CFG_S *pstNnieCfg NNIE configure parameter
  322. * SAMPLE_SVP_NNIE_PARAM_S *pstNnieParam NNIE parameters
  323. *
  324. *
  325. *
  326. * Output :
  327. * Return Value : HI_S32,HI_SUCCESS:Success,Other:failure
  328. * Spec :
  329. * Calls :
  330. * Called By :
  331. * History:
  332. *
  333. * 1. Date : 2017-11-20
  334. * Author :
  335. * Modification : Create
  336. *
  337. *****************************************************************************/
  338. HI_S32 SAMPLE_COMM_SVP_NNIE_ParamInit(SAMPLE_SVP_NNIE_CFG_S *pstNnieCfg,
  339. SAMPLE_SVP_NNIE_PARAM_S *pstNnieParam);
  340. /*****************************************************************************
  341. * Prototype : SAMPLE_COMM_SVP_NNIE_UnloadModel
  342. * Description : unload NNIE model
  343. * Input : SAMPLE_SVP_NNIE_MODEL_S *pstNnieModel NNIE Model
  344. *
  345. *
  346. *
  347. * Output :
  348. * Return Value : HI_S32,HI_SUCCESS:Success,Other:failure
  349. * Spec :
  350. * Calls :
  351. * Called By :
  352. * History:
  353. *
  354. * 1. Date : 2017-11-20
  355. * Author :
  356. * Modification : Create
  357. *
  358. *****************************************************************************/
  359. HI_S32 SAMPLE_COMM_SVP_NNIE_UnloadModel(SAMPLE_SVP_NNIE_MODEL_S *pstNnieModel);
  360. /*****************************************************************************
  361. * Prototype : SAMPLE_COMM_SVP_NNIE_LoadModel
  362. * Description : load NNIE model
  363. * Input : HI_CHAR * pszModelFile Model file name
  364. * SAMPLE_SVP_NNIE_MODEL_S *pstNnieModel NNIE Model
  365. *
  366. *
  367. *
  368. * Output :
  369. * Return Value : HI_S32,HI_SUCCESS:Success,Other:failure
  370. * Spec :
  371. * Calls :
  372. * Called By :
  373. * History:
  374. *
  375. * 1. Date : 2017-11-20
  376. * Author :
  377. * Modification : Create
  378. *
  379. *****************************************************************************/
  380. HI_S32 SAMPLE_COMM_SVP_NNIE_LoadModel(HI_CHAR * pszModelFile,
  381. SAMPLE_SVP_NNIE_MODEL_S *pstNnieModel);
  382. /*****************************************************************************
  383. * Prototype : SAMPLE_COMM_SVP_NNIE_FillRect
  384. * Description : Draw rect
  385. * Input : VIDEO_FRAME_INFO_S *pstFrmInfo Frame info
  386. * SAMPLE_SVP_NNIE_RECT_ARRAY_S *pstRect Rect
  387. * HI_U32 u32Color Color
  388. *
  389. *
  390. * Output :
  391. * Return Value : HI_S32
  392. * Spec :
  393. * Calls :
  394. * Called By :
  395. * History:
  396. *
  397. * 1. Date : 2017-03-14
  398. * Author :
  399. * Modification : Create
  400. *
  401. *****************************************************************************/
  402. HI_S32 SAMPLE_COMM_SVP_NNIE_FillRect(VIDEO_FRAME_INFO_S *pstFrmInfo, SAMPLE_SVP_NNIE_RECT_ARRAY_S* pstRect, HI_U32 u32Color);
  403. #ifdef __cplusplus
  404. #if __cplusplus
  405. }
  406. #endif
  407. #endif /* __cplusplus */
  408. #endif /* __SAMPLE_COMM_NNIE_H__ */