net_api.h 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336
  1. #ifndef _NET_API_H_
  2. #define _NET_API_H_
  3. #include <vector>
  4. #include <VX/vx.h>
  5. #include <vx_ext_amd.h>
  6. typedef enum ImageFormat_E {
  7. YUV420_SP = 0x02,
  8. YVU420_SP = 0x04,
  9. NNA_BGRA = 0x09,
  10. NNA_GRAY = 0x07,
  11. } img_fmt;
  12. typedef enum ImageOperation_E {
  13. CVT = 1001,
  14. WARP = 1002,
  15. } img_op;
  16. typedef enum ImageDataLayout_E {
  17. CHW = 2001,
  18. HWC = 2002,
  19. WHC = 2003,
  20. } img_data_layout;
  21. typedef struct ImageConvertParam_S {
  22. img_fmt input_fmt;
  23. int input_width;
  24. int input_height;
  25. int input_crop_x;
  26. int input_crop_y;
  27. int input_crop_w;
  28. int input_crop_h;
  29. int input_color_range;
  30. img_fmt output_fmt;
  31. int output_width;
  32. int output_height;
  33. int output_crop_x;
  34. int output_crop_y;
  35. int output_crop_w;
  36. int output_crop_h;
  37. } img_cvt_param;
  38. typedef struct MbgParam_S {
  39. int input_width;
  40. int input_height;
  41. int blk_width;
  42. int blk_height;
  43. int threshold_enable;
  44. int threshold;
  45. int alpha;
  46. int reset_flag;
  47. int mask_threshold;
  48. } mbg_param;
  49. typedef struct ImageWarpParam_S {
  50. img_fmt input_fmt;
  51. int input_width;
  52. int input_height;
  53. int output_width;
  54. int output_height;
  55. int flip;
  56. float mat[6];
  57. int output_crop_x;
  58. int output_crop_y;
  59. int output_crop_w;
  60. int output_crop_h;
  61. } img_warp_param;
  62. typedef struct InputImage_S {
  63. img_op op;
  64. img_fmt fmt;
  65. int width;
  66. int height;
  67. union {
  68. /* crop out params in cvt_param and warp_param struct have been deprecated. */
  69. struct {
  70. int crop_in_x;
  71. int crop_in_y;
  72. int crop_in_w;
  73. int crop_in_h;
  74. int color_range;
  75. int crop_out_x;
  76. int crop_out_y;
  77. int crop_out_w;
  78. int crop_out_h;
  79. } cvt_param;
  80. struct {
  81. int flip;
  82. int crop_out_x;
  83. int crop_out_y;
  84. int crop_out_w;
  85. int crop_out_h;
  86. float mat[6];
  87. } warp_param;
  88. } u;
  89. vx_size phys_addr;
  90. vx_size phys_addr_uv;
  91. } input_image;
  92. typedef enum NetDataLayout_E {
  93. NCHW = 3001,
  94. NHWC = 3002,
  95. NWHC = 3003,
  96. } net_data_layout;
  97. typedef enum NetDataType_E {
  98. DINT8 = 4001,
  99. DINT16 = 4002,
  100. DFLOAT32 = 4003,
  101. } net_data_type;
  102. typedef struct NetBlobData_S {
  103. int n;
  104. int c;
  105. int h;
  106. int w;
  107. void* data;
  108. bool need_quantize;
  109. net_data_type type;
  110. net_data_layout layout;
  111. } net_blob_data;
  112. typedef struct RoiAlignParam_S {
  113. int input_width;
  114. int input_height;
  115. int input_channel;
  116. int crop_in_c_st;
  117. int crop_in_c_wd;
  118. float roi_in_start_w;
  119. float roi_in_end_w;
  120. float roi_in_start_h;
  121. float roi_in_end_h;
  122. int output_width;
  123. int output_height;
  124. int output_channel;
  125. int crop_out_x_st;
  126. int crop_out_y_st;
  127. int crop_out_c_st;
  128. int bit_width;
  129. int pooled_w;
  130. int pooled_h;
  131. int aligned;
  132. float spatial_ratio;
  133. float sampling_ratio;
  134. } roi_align_param;
  135. /*
  136. * network
  137. */
  138. VX_API_ENTRY vx_graph VX_API_CALL CreateNetGraph(
  139. vx_context context,
  140. vx_uint32 * net_topo,
  141. vx_int8 * net_blobs,
  142. bool on_chip_mem_enable = false,
  143. bool io_mem_shared = false,
  144. int hold_block_idx = 0x7FFFFFFF,
  145. int up_to_block_count = -1);
  146. VX_API_ENTRY vx_status VX_API_CALL GetNetInputBlob(
  147. vx_graph graph,
  148. std::vector<std::string> & names,
  149. std::vector<vx_tensor> & blobs);
  150. VX_API_ENTRY vx_status VX_API_CALL GetNetOutputBlob(
  151. vx_graph graph,
  152. std::vector<std::string> & names,
  153. std::vector<vx_tensor> & blobs);
  154. VX_API_ENTRY vx_status VX_API_CALL GetNetIntermediateBlob(
  155. vx_graph graph,
  156. std::vector<std::string>& names,
  157. std::vector<vx_tensor>& blobs);
  158. VX_API_ENTRY vx_status VX_API_CALL GetNetBlobOriginDims(
  159. vx_graph graph,
  160. std::string& blob_name,
  161. std::vector<int>& dims);
  162. /*
  163. * batch network
  164. */
  165. VX_API_ENTRY vx_graph VX_API_CALL CreateBatchNetGraph(
  166. vx_context context,
  167. vx_uint32* net_topo,
  168. vx_int8* net_blobs,
  169. int batch,
  170. bool io_mem_shared = false);
  171. VX_API_ENTRY vx_status VX_API_CALL GetBatchNetInputBlob(
  172. vx_graph graph,
  173. std::vector<std::string>& names,
  174. std::vector<std::vector<vx_tensor>>& blobs);
  175. VX_API_ENTRY vx_status VX_API_CALL GetBatchNetOutputBlob(
  176. vx_graph graph,
  177. std::vector<std::string>& names,
  178. std::vector<std::vector<vx_tensor>>& blobs);
  179. /*
  180. * config input buffer
  181. */
  182. VX_API_ENTRY vx_status VX_API_CALL SetNetInputBuffer(
  183. vx_graph graph,
  184. std::string& blob_name,
  185. vx_size handle,
  186. int batch_idx = 0);
  187. VX_API_ENTRY vx_status VX_API_CALL ResetNetDefaultInputBuffer(
  188. vx_graph graph,
  189. std::string& blob_name,
  190. int batch_idx = 0);
  191. /*
  192. * import and export network data
  193. */
  194. VX_API_ENTRY vx_status VX_API_CALL ImportNetInputDataFromImage(
  195. vx_graph graph,
  196. std::string& blob_name,
  197. input_image* image,
  198. int batch_idx = 0);
  199. VX_API_ENTRY vx_status VX_API_CALL ImportNetInputDataFromMem(
  200. vx_graph graph,
  201. std::string & blob_name,
  202. int mem_data_len,
  203. vx_uint8* mem_data,
  204. int batch_idx = 0);
  205. VX_API_ENTRY vx_status VX_API_CALL ImportNetInputDataFromDataFile(
  206. vx_graph graph,
  207. std::string& blob_name,
  208. char* fname,
  209. int batch_idx = 0);
  210. VX_API_ENTRY vx_status VX_API_CALL EnableNetInputDataExtPreprocess(
  211. vx_graph graph,
  212. std::string& blob_name);
  213. VX_API_ENTRY vx_status VX_API_CALL DisableNetInputDataExtPreprocess(
  214. vx_graph graph,
  215. std::string& blob_name);
  216. VX_API_ENTRY vx_status VX_API_CALL ImportNetInputDataFromRawData(
  217. vx_graph graph,
  218. std::string& blob_name,
  219. net_blob_data& blob_data,
  220. int batch_idx = 0);
  221. VX_API_ENTRY vx_status VX_API_CALL ExportNetOutputRawData(
  222. vx_graph graph,
  223. std::string& blob_name,
  224. net_blob_data& blob_data,
  225. int batch_idx = 0);
  226. /*
  227. * image process
  228. */
  229. VX_API_ENTRY vx_size VX_API_CALL AllocDeviceImageBuffer(
  230. vx_context context,
  231. img_fmt fmt,
  232. int width,
  233. int height);
  234. VX_API_ENTRY vx_size VX_API_CALL AllocDeviceMbgMaskImageBuffer(
  235. vx_context context,
  236. int width,
  237. int height,
  238. int blk_width,
  239. int blk_height);
  240. VX_API_ENTRY vx_status VX_API_CALL FreeDeviceImageBuffer(
  241. vx_context context,
  242. vx_size handle);
  243. VX_API_ENTRY vx_status VX_API_CALL ImageConvert(
  244. vx_context context,
  245. img_cvt_param * param,
  246. vx_size input_phys_addr,
  247. vx_size input_phys_addr_uv,
  248. vx_size output_handle);
  249. VX_API_ENTRY vx_status VX_API_CALL BackgroundModeling(
  250. vx_context context,
  251. mbg_param * param,
  252. vx_size input_phys_addr,
  253. vx_size input_phys_addr_bg,
  254. vx_size output_handle_bg,
  255. vx_size output_handle_mask);
  256. VX_API_ENTRY vx_status VX_API_CALL ImageWarp(
  257. vx_context context,
  258. img_warp_param * param,
  259. vx_size input_phys_addr,
  260. vx_size input_phys_addr_uv,
  261. vx_size output_handle);
  262. VX_API_ENTRY vx_status VX_API_CALL RgbImageConvert(
  263. int w,
  264. int h,
  265. img_data_layout layout,
  266. vx_uint8 * src,
  267. vx_uint8 * dst);
  268. VX_API_ENTRY vx_status VX_API_CALL RgbImageRevert(
  269. int w,
  270. int h,
  271. vx_uint8 * src,
  272. img_data_layout layout,
  273. vx_uint8 * dst);
  274. VX_API_ENTRY vx_status VX_API_CALL RoiAlign(
  275. vx_context context,
  276. roi_align_param& op_param,
  277. vx_size input_handle,
  278. vx_size output_handle);
  279. /*
  280. * utility
  281. */
  282. VX_API_ENTRY vx_status VX_API_CALL LoadNetModel(
  283. vx_context context,
  284. const char * model_file,
  285. bool encrypted,
  286. vx_int8 ** model);
  287. VX_API_ENTRY vx_status VX_API_CALL LoadNetModelFromMem(
  288. vx_context context,
  289. vx_int8 * model_data,
  290. int model_len,
  291. bool encrypted,
  292. vx_int8 ** model);
  293. VX_API_ENTRY vx_status VX_API_CALL UnLoadNetModel(vx_int8 * model);
  294. #endif