You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

operators.md 7.6 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325
  1. * [absval](#absval)
  2. * [argmax](#argmax)
  3. * [batchnorm](#batchnorm)
  4. * [bias](#bias)
  5. * [binaryop](#binaryop)
  6. * [bnll](#bnll)
  7. * [cast](#cast)
  8. * [clip](#clip)
  9. * [concat](#concat)
  10. * [convolution](#convolution)
  11. * [convolutiondepthwise](#convolutiondepthwise)
  12. * [crop](#crop)
  13. * [dequantize](#dequantize)
  14. * [lstm](#lstm)
  15. * [pooling](#pooling)
  16. * [sigmoid](#sigmoid)
  17. * [softmax](#softmax)
  18. * [tanh](#tanh)
  19. # absval
  20. ```
  21. y = abs(x)
  22. ```
  23. * one_blob_only
  24. * support_inplace
  25. # argmax
  26. ```
  27. y = argmax(x, out_max_val, topk)
  28. ```
  29. * one_blob_only
  30. |param id|name|type|default|
  31. |--|--|--|--|
  32. |0|out_max_val|int|0|
  33. |1|topk|int|1|
  34. # batchnorm
  35. ```
  36. y = (x - mean) / sqrt(var + eps) * slope + bias
  37. ```
  38. * one_blob_only
  39. * support_inplace
  40. |param id|name|type|default|
  41. |--|--|--|--|
  42. |0|channels|int|0|
  43. |1|eps|float|0.f|
  44. |weight|type|
  45. |--|--|
  46. |slope_data|float|
  47. |mean_data|float|
  48. |var_data|float|
  49. |bias_data|float|
  50. # bias
  51. ```
  52. y = x + bias
  53. ```
  54. * one_blob_only
  55. * support_inplace
  56. |param id|name|type|default|
  57. |--|--|--|--|
  58. |0|bias_data_size|int|0|
  59. |weight|type|
  60. |--|--|
  61. |bias_data|float|
  62. # binaryop
  63. This operation is used for binary computation, and the calculation rule depends on the [broadcasting rule](https://github.com/Tencent/ncnn/wiki/binaryop-broadcasting).
  64. ```
  65. C = binaryop(A, B)
  66. ```
  67. if with_scalar = 1:
  68. - one_blob_only
  69. - support_inplace
  70. |param id|name|type|default|description|
  71. |--|--|--|--|--|
  72. |0|op_type|int|0|Operation type as follows|
  73. |1|with_scalar|int|0|with_scalar=0 B is a matrix, with_scalar=1 B is a scalar|
  74. |2|b|float|0.f|When B is a scalar, B = b|
  75. Operation type:
  76. - 0 = ADD
  77. - 1 = SUB
  78. - 2 = MUL
  79. - 3 = DIV
  80. - 4 = MAX
  81. - 5 = MIN
  82. - 6 = POW
  83. - 7 = RSUB
  84. - 8 = RDIV
  85. # bnll
  86. ```
  87. y = log(1 + e^(-x)) , x > 0
  88. y = log(1 + e^x), x < 0
  89. ```
  90. * one_blob_only
  91. * support_inplace
  92. # cast
  93. ```
  94. y = cast(x)
  95. ```
  96. * one_blob_only
  97. * support_packing
  98. |param id|name|type|default|
  99. |--|--|--|--|
  100. |0|type_from|int|0|
  101. |1|type_to|int|0|
  102. Element type:
  103. - 0 = auto
  104. - 1 = float32
  105. - 2 = float16
  106. - 3 = int8
  107. - 4 = bfloat16
  108. # clip
  109. ```
  110. y = clamp(x, min, max)
  111. ```
  112. * one_blob_only
  113. * support_inplace
  114. |param id|name|type|default|
  115. |--|--|--|--|
  116. |0|min|float|-FLT_MAX|
  117. |1|max|float|FLT_MAX|
  118. # concat
  119. ```
  120. y = concat(x0, x1, x2, ...) by axis
  121. ```
  122. |param id|name|type|default|
  123. |--|--|--|--|
  124. |0|axis|int|0|
  125. # convolution
  126. ```
  127. x2 = pad(x, pads, pad_value)
  128. x3 = conv(x2, weight, kernel, stride, dilation) + bias
  129. y = activation(x3, act_type, act_params)
  130. ```
  131. * one_blob_only
  132. |param id|name|type|default|
  133. |--|--|--|--|
  134. |0|num_output|int|0|
  135. |1|kernel_w|int|0|
  136. |2|dilation_w|int|1|
  137. |3|stride_w|int|1|
  138. |4|pad_left|int|0|
  139. |5|bias_term|int|0|
  140. |6|weight_data_size|int|0|
  141. |8|int8_scale_term|int|0|
  142. |9|activation_type|int|0|
  143. |10|activation_params|array|[ ]|
  144. |11|kernel_h|int|kernel_w|
  145. |12|dilation_h|int|dilation_w|
  146. |13|stride_h|int|stride_w|
  147. |15|pad_right|int|pad_left|
  148. |14|pad_top|int|pad_left|
  149. |16|pad_bottom|int|pad_top|
  150. |18|pad_value|float|0.f|
  151. |weight|type|
  152. |--|--|
  153. |weight_data|float/fp16/int8|
  154. |bias_data|float|
  155. # convolutiondepthwise
  156. ```
  157. x2 = pad(x, pads, pad_value)
  158. x3 = conv(x2, weight, kernel, stride, dilation, group) + bias
  159. y = activation(x3, act_type, act_params)
  160. ```
  161. * one_blob_only
  162. |param id|name|type|default|
  163. |--|--|--|--|
  164. |0|num_output|int|0|
  165. |1|kernel_w|int|0|
  166. |2|dilation_w|int|1|
  167. |3|stride_w|int|1|
  168. |4|pad_left|int|0|
  169. |5|bias_term|int|0|
  170. |6|weight_data_size|int|0|
  171. |7|group|int|1|
  172. |8|int8_scale_term|int|0|
  173. |9|activation_type|int|0|
  174. |10|activation_params|array|[ ]|
  175. |11|kernel_h|int|kernel_w|
  176. |12|dilation_h|int|dilation_w|
  177. |13|stride_h|int|stride_w|
  178. |15|pad_right|int|pad_left|
  179. |14|pad_top|int|pad_left|
  180. |16|pad_bottom|int|pad_top|
  181. |18|pad_value|float|0.f|
  182. |weight|type|
  183. |--|--|
  184. |weight_data|float/fp16/int8|
  185. |bias_data|float|
  186. # crop
  187. ```
  188. y = crop(x)
  189. ```
  190. * one_blob_only
  191. |param id|name|type|default|
  192. |--|--|--|--|
  193. |0|woffset|int|0|
  194. |1|hoffset|int|0|
  195. |2|coffset|int|1|
  196. |3|outw|int|1|
  197. |4|outh|int|0|
  198. |5|outc|int|0|
  199. |6|woffset2|int|0|
  200. |7|hoffset2|int|1|
  201. |8|coffset2|int|0|
  202. |9|starts|array|[ ]|
  203. |10|ends|array|[ ]|
  204. |11|axes|array|[ ]|
  205. # dequantize
  206. ```
  207. y = x * scale + bias
  208. ```
  209. * one_blob_only
  210. * support_inplace
  211. |param id|name|type|default|
  212. |--|--|--|--|
  213. |0|scale|float|1.f|
  214. |1|bias_term|int|0|
  215. |2|bias_data_size|int|0|
  216. # lstm
  217. Apply a single-layer LSTM to a feature sequence of `T` timesteps. The input blob shape is `[w=input_size, h=T]` and the output blob shape is `[w=num_output, h=T]`.
  218. * one_blob_only
  219. |param id|name|type|default|description|
  220. |--|--|--|--|--|
  221. |0|num_output|int|0|hidden size of output|
  222. |1|weight_data_size|int|0|total size of IFOG weight matrix|
  223. |2|direction|int|0|0=forward, 1=reverse, 2=bidirectional|
  224. |weight|type|shape|description|
  225. |--|--|--|--|
  226. |weight_xc_data|float|`[w=input_size, h=num_output * 4, c=num_directions]`||
  227. |bias_c_data|float|`[w=num_output, h=4, c=num_directions]`||
  228. |weight_hc_data|float|`[w=num_output, h=num_output * 4, c=num_directions]`||
  229. # pooling
  230. ```
  231. x2 = pad(x, pads)
  232. x3 = pooling(x2, kernel, stride)
  233. ```
  234. | param id | name | type | default | description |
  235. | -------- | -------------- | ---- | -------- | ----------------------------------------------------------------------------------------------------------------------------------- |
  236. | 0 | pooling_type | int | 0 | 0: max 1: avg |
  237. | 1 | kernel_w | int | 0 | |
  238. | 2 | stride_w | int | 1 | |
  239. | 3 | pad_left | int | 0 | |
  240. | 4 | global_pooling | int | 0 | |
  241. | 5 | pad_mode | int | 0 | 0: full padding <br/> 1: valid padding <br/> 2: tensorflow padding=SAME or onnx padding=SAME_UPPER <br/> 3: onnx padding=SAME_LOWER |
  242. | 11 | kernel_h | int | kernel_w | |
  243. | 12 | stride_h | int | stride_w | |
  244. | 13 | pad_top | int | pad_left | |
  245. | 14 | pad_right | int | pad_left | |
  246. | 15 | pad_bottom | int | pad_top | |
  247. # sigmoid
  248. ```
  249. y = 1 / (1 + exp(-x))
  250. ```
  251. * one_blob_only
  252. * support_inplace
  253. # softmax
  254. ```
  255. softmax(x, axis)
  256. ```
  257. * one_blob_only
  258. * support_inplace
  259. |param id|name|type|default|description|
  260. |--|--|--|--|--|
  261. |0|axis|int|0||
  262. |1|fixbug0|int|0|hack for bug fix, should be 1|
  263. # tanh
  264. ```
  265. y = tanh(x)
  266. ```
  267. * one_blob_only
  268. * support_inplace