net_api.h 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269
  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. #include "img_type.h"
  7. // typedef enum ImageFormat_E {
  8. // YUV420_SP = 0x02,
  9. // YVU420_SP = 0x04,
  10. // NNA_BGRA = 0x09,
  11. // NNA_GRAY = 0x07,
  12. // } img_fmt;
  13. typedef enum ImageOperation_E {
  14. CVT = 1001,
  15. WARP = 1002,
  16. } img_op;
  17. typedef enum ImageDataLayout_E {
  18. CHW = 2001,
  19. HWC = 2002,
  20. WHC = 2003,
  21. } img_data_layout;
  22. typedef struct ImageConvertParam_S {
  23. img_fmt input_fmt;
  24. int input_width;
  25. int input_height;
  26. int input_stride;
  27. int input_crop_x;
  28. int input_crop_y;
  29. int input_crop_w;
  30. int input_crop_h;
  31. int input_color_range;
  32. img_fmt output_fmt;
  33. int output_width;
  34. int output_height;
  35. } img_cvt_param;
  36. typedef struct MbgParam_S {
  37. int input_width;
  38. int input_height;
  39. int blk_width;
  40. int blk_height;
  41. int threshold_enable;
  42. int threshold;
  43. int alpha;
  44. int reset_flag;
  45. int mask_threshold;
  46. } mbg_param;
  47. typedef struct ImageWarpParam_S {
  48. img_fmt input_fmt;
  49. int input_width;
  50. int input_height;
  51. int input_stride;
  52. int flip;
  53. float mat[6];
  54. int output_crop_x;
  55. int output_crop_y;
  56. int output_crop_w;
  57. int output_crop_h;
  58. } img_warp_param;
  59. typedef struct InputImage_S {
  60. img_op op;
  61. img_fmt fmt;
  62. int width;
  63. int height;
  64. int stride;
  65. union {
  66. struct {
  67. int crop_x;
  68. int crop_y;
  69. int crop_w;
  70. int crop_h;
  71. int color_range;
  72. } cvt_param;
  73. struct {
  74. int flip;
  75. int crop_x;
  76. int crop_y;
  77. int crop_w;
  78. int crop_h;
  79. float mat[6];
  80. } warp_param;
  81. } u;
  82. vx_size phys_addr;
  83. vx_size phys_addr_uv;
  84. } input_image;
  85. typedef enum NetDataLayout_E {
  86. NCHW = 3001,
  87. NHWC = 3002,
  88. NWHC = 3003,
  89. CPKT = 3004,
  90. } net_data_layout;
  91. typedef enum NetDataType_E {
  92. DINT8 = 4001,
  93. DINT16 = 4002,
  94. DFLOAT32 = 4003,
  95. } net_data_type;
  96. typedef struct NetBlobData_S {
  97. net_data_type type;
  98. int fixed_pos;
  99. int cpkt_mode;
  100. int dims[4];
  101. int size;
  102. void * data;
  103. } net_blob_data;
  104. /*
  105. * network
  106. */
  107. VX_API_ENTRY vx_graph VX_API_CALL CreateNetGraph(
  108. vx_context context,
  109. vx_uint32 * net_topo,
  110. vx_int8 * net_blobs,
  111. bool on_chip_mem_enable = false,
  112. int hold_block_idx = 0x7FFFFFFF,
  113. int up_to_block_count = -1);
  114. VX_API_ENTRY vx_status VX_API_CALL GetNetInputBlob(
  115. vx_graph graph,
  116. std::vector<std::string> & names,
  117. std::vector<vx_tensor> & blobs);
  118. VX_API_ENTRY vx_status VX_API_CALL GetNetOutputBlob(
  119. vx_graph graph,
  120. std::vector<std::string> & names,
  121. std::vector<vx_tensor> & blobs);
  122. VX_API_ENTRY vx_status VX_API_CALL GetNetIntermediateBlob(
  123. vx_graph graph,
  124. std::vector<std::string>& names,
  125. std::vector<vx_tensor>& blobs);
  126. /*
  127. * batch network
  128. */
  129. VX_API_ENTRY vx_graph VX_API_CALL CreateBatchNetGraph(
  130. vx_context context,
  131. vx_uint32* net_topo,
  132. vx_int8* net_blobs,
  133. int batch);
  134. VX_API_ENTRY vx_status VX_API_CALL GetBatchNetInputBlob(
  135. vx_graph graph,
  136. std::vector<std::string>& names,
  137. std::vector<std::vector<vx_tensor>>& blobs);
  138. VX_API_ENTRY vx_status VX_API_CALL GetBatchNetOutputBlob(
  139. vx_graph graph,
  140. std::vector<std::string>& names,
  141. std::vector<std::vector<vx_tensor>>& blobs);
  142. /*
  143. * config input and output buffer
  144. */
  145. VX_API_ENTRY vx_status VX_API_CALL ConfigNetInOutBuffer(
  146. vx_graph graph,
  147. std::string& blob_name,
  148. int offset,
  149. vx_size handle,
  150. int batch_idx = 0);
  151. VX_API_ENTRY vx_status VX_API_CALL ResetNetInOutBuffer(
  152. vx_graph graph);
  153. /*
  154. * import and export network data
  155. */
  156. VX_API_ENTRY vx_status VX_API_CALL ImportNetInputDataFromImage(
  157. vx_graph graph,
  158. std::string& blob_name,
  159. input_image* image,
  160. int batch_idx = 0);
  161. VX_API_ENTRY vx_status VX_API_CALL ImportNetInputDataFromDataFile(
  162. vx_graph graph,
  163. std::string& blob_name,
  164. char* fname,
  165. int batch_idx = 0);
  166. VX_API_ENTRY vx_status VX_API_CALL ExportNetBlobData(
  167. vx_graph graph,
  168. net_data_layout layout,
  169. std::string& blob_name,
  170. net_blob_data* blob_data,
  171. int batch_idx = 0);
  172. /*
  173. * image process
  174. */
  175. VX_API_ENTRY vx_size VX_API_CALL AllocDeviceImageBuffer(
  176. vx_context context,
  177. img_fmt fmt,
  178. int width,
  179. int height);
  180. VX_API_ENTRY vx_size VX_API_CALL AllocDeviceMbgMaskImageBuffer(
  181. vx_context context,
  182. int width,
  183. int height,
  184. int blk_width,
  185. int blk_height);
  186. VX_API_ENTRY vx_status VX_API_CALL FreeDeviceImageBuffer(
  187. vx_context context,
  188. vx_size handle);
  189. VX_API_ENTRY vx_status VX_API_CALL ImageConvert(
  190. vx_context context,
  191. img_cvt_param * param,
  192. vx_size input_phys_addr,
  193. vx_size input_phys_addr_uv,
  194. vx_size output_handle);
  195. VX_API_ENTRY vx_status VX_API_CALL BackgroundModeling(
  196. vx_context context,
  197. mbg_param * param,
  198. vx_size input_phys_addr,
  199. vx_size input_phys_addr_bg,
  200. vx_size output_handle_bg,
  201. vx_size output_handle_mask);
  202. VX_API_ENTRY vx_status VX_API_CALL ImageWarp(
  203. vx_context context,
  204. img_warp_param * param,
  205. vx_size input_phys_addr,
  206. vx_size input_phys_addr_uv,
  207. vx_size output_handle);
  208. VX_API_ENTRY vx_status VX_API_CALL RgbImageConvert(
  209. int w,
  210. int h,
  211. img_data_layout layout,
  212. vx_uint8 * src,
  213. vx_uint8 * dst);
  214. VX_API_ENTRY vx_status VX_API_CALL RgbImageRevert(
  215. int w,
  216. int h,
  217. vx_uint8 * src,
  218. img_data_layout layout,
  219. vx_uint8 * dst);
  220. /*
  221. * utility
  222. */
  223. VX_API_ENTRY vx_status VX_API_CALL LoadNetModel(
  224. vx_context context,
  225. const char * model_file,
  226. bool encrypted,
  227. vx_int8 ** model);
  228. VX_API_ENTRY vx_status VX_API_CALL LoadNetModelFromMem(
  229. vx_context context,
  230. vx_int8 * model_data,
  231. int model_len,
  232. bool encrypted,
  233. vx_int8 ** model);
  234. VX_API_ENTRY vx_status VX_API_CALL UnLoadNetModel(vx_int8 * model);
  235. #endif