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 30 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875
  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. * [deconvolution](#deconvolution)
  14. * [deconvolutiondepthwise](#deconvolutiondepthwise)
  15. * [dequantize](#dequantize)
  16. * [dropout](#dropout)
  17. * [eltwise](#eltwise)
  18. * [elu](#elu)
  19. * [exp](#exp)
  20. * [flatten](#flatten)
  21. * [gelu](#gelu)
  22. * [gemm](#gemm)
  23. * [groupnorm](#groupnorm)
  24. * [gru](#gru)
  25. * [hardsigmoid](#hardsigmoid)
  26. * [hardswish](#hardswish)
  27. * [innerproduct](#innerproduct)
  28. * [input](#input)
  29. * [instancenorm](#instancenorm)
  30. * [interp](#interp)
  31. * [layernorm](#layernorm)
  32. * [log](#log)
  33. * [lrn](#lrn)
  34. * [lstm](#lstm)
  35. * [memorydata](#memorydata)
  36. * [mish](#mish)
  37. * [multiheadattention](#multiheadattention)
  38. * [pooling](#pooling)
  39. * [selu](#selu)
  40. * [sigmoid](#sigmoid)
  41. * [slice](#slice)
  42. * [softmax](#softmax)
  43. * [softplus](#softplus)
  44. * [split](#split)
  45. * [swish](#swish)
  46. * [tanh](#tanh)
  47. * [threshold](#threshold)
  48. * [unaryop](#unaryop)
  49. # absval
  50. ```
  51. y = abs(x)
  52. ```
  53. * one_blob_only
  54. * support_inplace
  55. # argmax
  56. ```
  57. y = argmax(x, out_max_val, topk)
  58. ```
  59. * one_blob_only
  60. | param id | name | type | default | description |
  61. | --------- | ------------- | ----- | --------- | ----------------- |
  62. | 0 | out_max_val | int | 0 | |
  63. | 1 | topk | int | 1 | |
  64. # batchnorm
  65. ```
  66. y = (x - mean) / sqrt(var + eps) * slope + bias
  67. ```
  68. * one_blob_only
  69. * support_inplace
  70. | param id | name | type | default | description |
  71. | --------- | ------------- | ----- | --------- | ----------------- |
  72. | 0 | channels | int | 0 | |
  73. | 1 | eps | float | 0.f | |
  74. | weight | type | shape |
  75. | ------------- | ----- | --------------------- |
  76. | slope_data | float | [channels] |
  77. | mean_data | float | [channels] |
  78. | var_data | float | [channels] |
  79. | bias_data | float | [channels] |
  80. # bias
  81. ```
  82. y = x + bias
  83. ```
  84. * one_blob_only
  85. * support_inplace
  86. | param id | name | type | default | description |
  87. | --------- | ------------- | ----- | --------- | ----------------- |
  88. | 0 | bias_data_size| int | 0 | |
  89. | weight | type | shape |
  90. | ------------- | ----- | --------------------- |
  91. | bias_data | float | [channels] |
  92. # binaryop
  93. This operation is used for binary computation, and the calculation rule depends on the [broadcasting rule](https://github.com/Tencent/ncnn/wiki/binaryop-broadcasting).
  94. ```
  95. C = binaryop(A, B)
  96. ```
  97. if with_scalar = 1:
  98. - one_blob_only
  99. - support_inplace
  100. | param id | name | type | default | description |
  101. | --------- | ------------- | ----- | --------- | ----------------- |
  102. | 0 | op_type | int | 0 | Operation type as follows |
  103. | 1 | with_scalar | int | 0 | with_scalar=0 B is a matrix, with_scalar=1 B is a scalar |
  104. | 2 | b | float | 0.f | When B is a scalar, B = b |
  105. Operation type:
  106. - 0 = ADD
  107. - 1 = SUB
  108. - 2 = MUL
  109. - 3 = DIV
  110. - 4 = MAX
  111. - 5 = MIN
  112. - 6 = POW
  113. - 7 = RSUB
  114. - 8 = RDIV
  115. # bnll
  116. ```
  117. y = log(1 + e^(-x)) , x > 0
  118. y = log(1 + e^x), x < 0
  119. ```
  120. * one_blob_only
  121. * support_inplace
  122. # cast
  123. ```
  124. y = cast(x)
  125. ```
  126. * one_blob_only
  127. * support_packing
  128. | param id | name | type | default | description |
  129. | --------- | ------------- | ----- | --------- | ----------------- |
  130. | 0 | type_from | int | 0 | |
  131. | 1 | type_to | int | 0 | |
  132. Element type:
  133. - 0 = auto
  134. - 1 = float32
  135. - 2 = float16
  136. - 3 = int8
  137. - 4 = bfloat16
  138. # clip
  139. ```
  140. y = clamp(x, min, max)
  141. ```
  142. * one_blob_only
  143. * support_inplace
  144. | param id | name | type | default | description |
  145. | --------- | ------------- | ----- | --------- | ----------------- |
  146. | 0 | min | float | -FLT_MAX | |
  147. | 1 | max | float | FLT_MAX | |
  148. # concat
  149. ```
  150. y = concat(x0, x1, x2, ...) by axis
  151. ```
  152. | param id | name | type | default | description |
  153. | --------- | ------------- | ----- | --------- | ----------------- |
  154. | 0 | axis | int | 0 | |
  155. # convolution
  156. ```
  157. x2 = pad(x, pads, pad_value)
  158. x3 = conv(x2, weight, kernel, stride, dilation) + bias
  159. y = activation(x3, act_type, act_params)
  160. ```
  161. * one_blob_only
  162. | param id | name | type | default | description |
  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. | 8 | int8_scale_term| int | 0 | |
  172. | 9 | activation_type| int | 0 | |
  173. | 10 | activation_params| array | [ ] | |
  174. | 11 | kernel_h | int | kernel_w | |
  175. | 12 | dilation_h | int | dilation_w | |
  176. | 13 | stride_h | int | stride_w | |
  177. | 15 | pad_right | int | pad_left | |
  178. | 14 | pad_top | int | pad_left | |
  179. | 16 | pad_bottom | int | pad_top | |
  180. | 18 | pad_value | float | 0.f | |
  181. | weight | type | shape |
  182. | ------------- | ----- | --------------------- |
  183. | weight_data | float/fp16/int8 | [kernel_w, kernel_h, num_input, num_output] |
  184. | bias_data | float | [num_output] |
  185. | weight_data_int8_scales| float | [num_output] |
  186. | bottom_blob_int8_scales| float | [1] |
  187. | top_blob_int8_scales| float | [1] |
  188. # convolutiondepthwise
  189. ```
  190. x2 = pad(x, pads, pad_value)
  191. x3 = conv(x2, weight, kernel, stride, dilation, group) + bias
  192. y = activation(x3, act_type, act_params)
  193. ```
  194. * one_blob_only
  195. | param id | name | type | default | description |
  196. | --------- | ------------- | ----- | --------- | ----------------- |
  197. | 0 | num_output | int | 0 | |
  198. | 1 | kernel_w | int | 0 | |
  199. | 2 | dilation_w | int | 1 | |
  200. | 3 | stride_w | int | 1 | |
  201. | 4 | pad_left | int | 0 | |
  202. | 5 | bias_term | int | 0 | |
  203. | 6 | weight_data_size| int | 0 | |
  204. | 7 | group | int | 1 | |
  205. | 8 | int8_scale_term| int | 0 | |
  206. | 9 | activation_type| int | 0 | |
  207. | 10 | activation_params| array | [ ] | |
  208. | 11 | kernel_h | int | kernel_w | |
  209. | 12 | dilation_h | int | dilation_w | |
  210. | 13 | stride_h | int | stride_w | |
  211. | 15 | pad_right | int | pad_left | |
  212. | 14 | pad_top | int | pad_left | |
  213. | 16 | pad_bottom | int | pad_top | |
  214. | 18 | pad_value | float | 0.f | |
  215. | weight | type | shape |
  216. | ------------- | ----- | --------------------- |
  217. | weight_data | float/fp16/int8 | [kernel_w, kernel_h, num_input / group, num_output / group, group] |
  218. | bias_data | float | [num_output] |
  219. | weight_data_int8_scales| float | [group] |
  220. | bottom_blob_int8_scales| float | [1] |
  221. | top_blob_int8_scales| float | [1] |
  222. # crop
  223. ```
  224. y = crop(x)
  225. ```
  226. * one_blob_only
  227. | param id | name | type | default | description |
  228. | --------- | ------------- | ----- | --------- | ----------------- |
  229. | 0 | woffset | int | 0 | |
  230. | 1 | hoffset | int | 0 | |
  231. | 2 | coffset | int | 1 | |
  232. | 3 | outw | int | 1 | |
  233. | 4 | outh | int | 0 | |
  234. | 5 | outc | int | 0 | |
  235. | 6 | woffset2 | int | 0 | |
  236. | 7 | hoffset2 | int | 1 | |
  237. | 8 | coffset2 | int | 0 | |
  238. | 9 | starts | array | [ ] | |
  239. | 10 | ends | array | [ ] | |
  240. | 11 | axes | array | [ ] | |
  241. # deconvolution
  242. ```
  243. x2 = deconv(x, weight, kernel, stride, dilation) + bias
  244. x3 = depad(x2, pads, pad_value)
  245. y = activation(x3, act_type, act_params)
  246. ```
  247. * one_blob_only
  248. | param id | name | type | default | description |
  249. | --------- | ------------- | ----- | --------- | ----------------- |
  250. | 0 | num_output | int | 0 | |
  251. | 1 | kernel_w | int | 0 | |
  252. | 2 | dilation_w | int | 1 | |
  253. | 3 | stride_w | int | 1 | |
  254. | 4 | pad_left | int | 0 | |
  255. | 5 | bias_term | int | 0 | |
  256. | 6 | weight_data_size| int | 0 | |
  257. | 8 | int8_scale_term| int | 0 | |
  258. | 9 | activation_type| int | 0 | |
  259. | 10 | activation_params| array | [ ] | |
  260. | 11 | kernel_h | int | kernel_w | |
  261. | 12 | dilation_h | int | dilation_w | |
  262. | 13 | stride_h | int | stride_w | |
  263. | 15 | pad_right | int | pad_left | |
  264. | 14 | pad_top | int | pad_left | |
  265. | 16 | pad_bottom | int | pad_top | |
  266. | 18 | pad_value | float | 0.f | |
  267. | weight | type | shape |
  268. | ------------- | ----- | --------------------- |
  269. | weight_data | float/fp16/int8 | [kernel_w, kernel_h, num_input, num_output] |
  270. | bias_data | float | [num_output] |
  271. # deconvolutiondepthwise
  272. ```
  273. x2 = deconv(x, weight, kernel, stride, dilation, group) + bias
  274. x3 = depad(x2, pads, pad_value)
  275. y = activation(x3, act_type, act_params)
  276. ```
  277. * one_blob_only
  278. | param id | name | type | default | description |
  279. | --------- | ------------- | ----- | --------- | ----------------- |
  280. | 0 | num_output | int | 0 | |
  281. | 1 | kernel_w | int | 0 | |
  282. | 2 | dilation_w | int | 1 | |
  283. | 3 | stride_w | int | 1 | |
  284. | 4 | pad_left | int | 0 | |
  285. | 5 | bias_term | int | 0 | |
  286. | 6 | weight_data_size| int | 0 | |
  287. | 7 | group | int | 1 | |
  288. | 8 | int8_scale_term| int | 0 | |
  289. | 9 | activation_type| int | 0 | |
  290. | 10 | activation_params| array | [ ] | |
  291. | 11 | kernel_h | int | kernel_w | |
  292. | 12 | dilation_h | int | dilation_w | |
  293. | 13 | stride_h | int | stride_w | |
  294. | 15 | pad_right | int | pad_left | |
  295. | 14 | pad_top | int | pad_left | |
  296. | 16 | pad_bottom | int | pad_top | |
  297. | 18 | pad_value | float | 0.f | |
  298. | weight | type | shape |
  299. | ------------- | ----- | --------------------- |
  300. | weight_data | float/fp16/int8 | [kernel_w, kernel_h, num_input / group, num_output / group, group] |
  301. | bias_data | float | [num_output] |
  302. # dequantize
  303. ```
  304. y = x * scale + bias
  305. ```
  306. * one_blob_only
  307. * support_inplace
  308. | param id | name | type | default | description |
  309. | --------- | ------------- | ----- | --------- | ----------------- |
  310. | 0 | scale | float | 1.f | |
  311. | 1 | bias_term | int | 0 | |
  312. | 2 | bias_data_size| int | 0 | |
  313. # dropout
  314. ```
  315. y = x * scale
  316. ```
  317. * one_blob_only
  318. | param id | name | type | default | description |
  319. | --------- | ------------- | ----- | --------- | ----------------- |
  320. | 0 | scale | float | 1.f | |
  321. # eltwise
  322. ```
  323. y = elementwise_op(x0, x1, ...)
  324. ```
  325. | param id | name | type | default | description |
  326. | --------- | ------------- | ----- | --------- | ----------------- |
  327. | 0 | op_type | int | 0 | |
  328. | 1 | coeffs | array | [ ] | |
  329. Operation type:
  330. - 0 = PROD
  331. - 1 = SUM
  332. - 2 = MAX
  333. # elu
  334. ```
  335. if x < 0 y = (exp(x) - 1) * alpha
  336. else y = x
  337. ```
  338. * one_blob_only
  339. * support_inplace
  340. | param id | name | type | default | description |
  341. | --------- | ------------- | ----- | --------- | ----------------- |
  342. | 0 | alpha | float | 0.1f | |
  343. # exp
  344. ```
  345. if base == -1 y = exp(shift + x * scale)
  346. else y = pow(base, (shift + x * scale))
  347. ```
  348. * one_blob_only
  349. * support_inplace
  350. | param id | name | type | default | description |
  351. | --------- | ------------- | ----- | --------- | ----------------- |
  352. | 0 | base | float | -1.f | |
  353. | 1 | scale | float | 1.f | |
  354. | 2 | shift | float | 0.f | |
  355. # flatten
  356. Reshape blob to 1 dimension
  357. * one_blob_only
  358. # gelu
  359. ```
  360. if fast_gelu == 1 y = 0.5 * x * (1 + tanh(0.79788452 * (x + 0.044715 * x * x * x)));
  361. else y = 0.5 * x * erfc(-0.70710678 * x)
  362. ```
  363. * one_blob_only
  364. * support_inplace
  365. | param id | name | type | default | description |
  366. | --------- | ------------- | ----- | --------- | ----------------- |
  367. | 0 | fast_gelu | int | 0 | use approximation |
  368. # gemm
  369. ```
  370. a = transA ? transpose(x0) : x0
  371. b = transb ? transpose(x1) : x1
  372. c = x2
  373. y = gemm(a, b) * alpha + c * beta
  374. ```
  375. | param id | name | type | default | description |
  376. | --------- | ------------- | ----- | --------- | ----------------- |
  377. | 0 | alpha | float | 1.f | |
  378. | 1 | beta | float | 1.f | |
  379. | 2 | transA | int | 0 | |
  380. | 3 | transb | int | 0 | |
  381. # groupnorm
  382. ```
  383. split x along channel axis into group x0, x1 ...
  384. l2 normalize for each group x0, x1 ...
  385. y = x * gamma + beta
  386. ```
  387. * one_blob_only
  388. * support_inplace
  389. | param id | name | type | default | description |
  390. | --------- | ------------- | ----- | --------- | ----------------- |
  391. | 0 | group | int | 1 | |
  392. | 1 | channels | int | 0 | |
  393. | 2 | eps | float | 0.001f | x = x / sqrt(var + eps) |
  394. | 3 | affine | int | 1 | |
  395. | weight | type | shape |
  396. | ------------- | ----- | --------------------- |
  397. | gamma_data | float | [channels] |
  398. | beta_data | float | [channels] |
  399. # gru
  400. Apply a single-layer GRU 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]`.
  401. * one_blob_only
  402. | param id | name | type | default | description |
  403. | --------- | ------------- | ----- | --------- | ----------------- |
  404. | 0 | num_output | int | 0 | hidden size of output |
  405. | 1 | weight_data_size| int | 0 | total size of weight matrix |
  406. | 2 | direction | int | 0 | 0=forward, 1=reverse, 2=bidirectional |
  407. | weight | type | shape |
  408. | ------------- | ----- | --------------------- |
  409. | weight_xc_data| float | [input_size, num_output * 3, num_directions] |
  410. | bias_c_data | float | [num_output, 4, num_directions] |
  411. | weight_hc_data| float | [num_output, num_output * 3, num_directions] |
  412. # hardsigmoid
  413. ```
  414. y = clamp(x * alpha + beta, 0, 1)
  415. ```
  416. * one_blob_only
  417. * support_inplace
  418. | param id | name | type | default | description |
  419. | --------- | ------------- | ----- | --------- | ----------------- |
  420. | 0 | alpha | float | 0.2f | |
  421. | 1 | beta | float | 0.5f | |
  422. # hardswish
  423. ```
  424. y = x * clamp(x * alpha + beta, 0, 1)
  425. ```
  426. * one_blob_only
  427. * support_inplace
  428. | param id | name | type | default | description |
  429. | --------- | ------------- | ----- | --------- | ----------------- |
  430. | 0 | alpha | float | 0.2f | |
  431. | 1 | beta | float | 0.5f | |
  432. # innerproduct
  433. ```
  434. x2 = innerproduct(x, weight) + bias
  435. y = activation(x2, act_type, act_params)
  436. ```
  437. * one_blob_only
  438. | param id | name | type | default | description |
  439. | --------- | ------------- | ----- | --------- | ----------------- |
  440. | 0 | num_output | int | 0 | |
  441. | 1 | bias_term | int | 0 | |
  442. | 2 | weight_data_size| int | 0 | |
  443. | 8 | int8_scale_term| int | 0 | |
  444. | 9 | activation_type| int | 0 | |
  445. | 10 | activation_params| array | [ ] | |
  446. | weight | type | shape |
  447. | ------------- | ----- | --------------------- |
  448. | weight_data | float/fp16/int8 | [num_input, num_output] |
  449. | bias_data | float | [num_output] |
  450. | weight_data_int8_scales| float | [num_output] |
  451. | bottom_blob_int8_scales| float | [1] |
  452. # input
  453. ```
  454. y = input
  455. ```
  456. * support_inplace
  457. | param id | name | type | default | description |
  458. | --------- | ------------- | ----- | --------- | ----------------- |
  459. | 0 | w | int | 0 | |
  460. | 1 | h | int | 0 | |
  461. | 2 | c | int | 0 | |
  462. # instancenorm
  463. ```
  464. split x along channel axis into instance x0, x1 ...
  465. l2 normalize for each channel instance x0, x1 ...
  466. y = x * gamma + beta
  467. ```
  468. * one_blob_only
  469. * support_inplace
  470. | param id | name | type | default | description |
  471. | --------- | ------------- | ----- | --------- | ----------------- |
  472. | 0 | channels | int | 0 | |
  473. | 1 | eps | float | 0.001f | x = x / sqrt(var + eps) |
  474. | 2 | affine | int | 1 | |
  475. | weight | type | shape |
  476. | ------------- | ----- | --------------------- |
  477. | gamma_data | float | [channels] |
  478. | beta_data | float | [channels] |
  479. # interp
  480. ```
  481. if dynamic_target_size == 0 y = resize(x) by fixed size or scale
  482. else y = resize(x0, size(x1))
  483. ```
  484. * one_blob_only if dynamic_target_size == 0
  485. | param id | name | type | default | description |
  486. | --------- | ------------- | ----- | --------- | ----------------- |
  487. | 0 | resize_type | int | 0 | |
  488. | 1 | height_scale | float | 1.f | |
  489. | 2 | width_scale | float | 1.f | |
  490. | 3 | output_height | int | 0 | |
  491. | 4 | output_width | int | 0 | |
  492. | 5 | dynamic_target_size| int | 0 | |
  493. | 6 | align_corner | int | 0 | |
  494. Resize type:
  495. - 1 = Nearest
  496. - 2 = Bilinear
  497. - 3 = Bicubic
  498. # layernorm
  499. ```
  500. split x along outmost axis into part x0, x1 ...
  501. l2 normalize for each part x0, x1 ...
  502. y = x * gamma + beta by elementwise
  503. ```
  504. * one_blob_only
  505. * support_inplace
  506. | param id | name | type | default | description |
  507. | --------- | ------------- | ----- | --------- | ----------------- |
  508. | 0 | affine_size | int | 0 | |
  509. | 1 | eps | float | 0.001f | x = x / sqrt(var + eps) |
  510. | 2 | affine | int | 1 | |
  511. | weight | type | shape |
  512. | ------------- | ----- | --------------------- |
  513. | gamma_data | float | [affine_size] |
  514. | beta_data | float | [affine_size] |
  515. # log
  516. ```
  517. if base == -1 y = log(shift + x * scale)
  518. else y = log(shift + x * scale) / log(base)
  519. ```
  520. * one_blob_only
  521. * support_inplace
  522. | param id | name | type | default | description |
  523. | --------- | ------------- | ----- | --------- | ----------------- |
  524. | 0 | base | float | -1.f | |
  525. | 1 | scale | float | 1.f | |
  526. | 2 | shift | float | 0.f | |
  527. # lrn
  528. ```
  529. if region_type == ACROSS_CHANNELS square_sum = sum of channel window of local_size
  530. if region_type == WITHIN_CHANNEL square_sum = sum of spatial window of local_size
  531. y = x * pow(bias + alpha * square_sum / (local_size * local_size), -beta)
  532. ```
  533. * one_blob_only
  534. * support_inplace
  535. | param id | name | type | default | description |
  536. | --------- | ------------- | ----- | --------- | ----------------- |
  537. | 0 | region_type | int | 0 | |
  538. | 1 | local_size | int | 5 | |
  539. | 2 | alpha | float | 1.f | |
  540. | 3 | beta | float | 0.75f | |
  541. | 4 | bias | float | 1.f | |
  542. Region type:
  543. - 0 = ACROSS_CHANNELS
  544. - 1 = WITHIN_CHANNEL
  545. # lstm
  546. 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]`.
  547. * one_blob_only
  548. | param id | name | type | default | description |
  549. | --------- | ------------- | ----- | --------- | ----------------- |
  550. | 0 | num_output | int | 0 | hidden size of output |
  551. | 1 | weight_data_size| int | 0 | total size of IFOG weight matrix |
  552. | 2 | direction | int | 0 | 0=forward, 1=reverse, 2=bidirectional |
  553. | weight | type | shape |
  554. | ------------- | ----- | --------------------- |
  555. | weight_xc_data| float | [input_size, num_output * 4, num_directions] |
  556. | bias_c_data | float | [num_output, 4, num_directions] |
  557. | weight_hc_data| float | [num_output, num_output * 4, num_directions] |
  558. # memorydata
  559. ```
  560. y = data
  561. ```
  562. | param id | name | type | default | description |
  563. | --------- | ------------- | ----- | --------- | ----------------- |
  564. | 0 | w | int | 0 | |
  565. | 1 | h | int | 0 | |
  566. | 2 | c | int | 0 | |
  567. | weight | type | shape |
  568. | ------------- | ----- | --------------------- |
  569. | data | float | [w, h, c] |
  570. # mish
  571. ```
  572. y = x * tanh(log(exp(x) + 1))
  573. ```
  574. * one_blob_only
  575. * support_inplace
  576. # multiheadattention
  577. ```
  578. split q k v into num_head part q0, k0, v0, q1, k1, v1 ...
  579. for each num_head part
  580. xq = affine(q) / (embed_dim / num_head)
  581. xk = affine(k)
  582. xv = affine(v)
  583. xqk = xq * xk
  584. softmax_inplace(xqk)
  585. xqkv = xqk * xv
  586. merge xqkv to out
  587. y = affine(out)
  588. ```
  589. | param id | name | type | default | description |
  590. | --------- | ------------- | ----- | --------- | ----------------- |
  591. | 0 | embed_dim | int | 0 | |
  592. | 1 | num_head | int | 1 | |
  593. | 2 | weight_data_size| int | 0 | |
  594. | weight | type | shape |
  595. | ------------- | ----- | --------------------- |
  596. | q_weight_data | float/fp16/int8 | [weight_data_size] |
  597. | q_bias_data | float | [embed_dim] |
  598. | k_weight_data | float/fp16/int8 | [weight_data_size] |
  599. | k_bias_data | float | [embed_dim] |
  600. | v_weight_data | float/fp16/int8 | [weight_data_size] |
  601. | v_bias_data | float | [embed_dim] |
  602. | out_weight_data| float/fp16/int8 | [weight_data_size] |
  603. | out_bias_data | float | [embed_dim] |
  604. # pooling
  605. ```
  606. x2 = pad(x, pads)
  607. x3 = pooling(x2, kernel, stride)
  608. ```
  609. | param id | name | type | default | description |
  610. | --------- | -------------- | ---- | --------- | ----------------- |
  611. | 0 | pooling_type | int | 0 | |
  612. | 1 | kernel_w | int | 0 | |
  613. | 2 | stride_w | int | 1 | |
  614. | 3 | pad_left | int | 0 | |
  615. | 4 | global_pooling | int | 0 | |
  616. | 5 | pad_mode | int | 0 | |
  617. | 11 | kernel_h | int | kernel_w | |
  618. | 12 | stride_h | int | stride_w | |
  619. | 13 | pad_top | int | pad_left | |
  620. | 14 | pad_right | int | pad_left | |
  621. | 15 | pad_bottom | int | pad_top | |
  622. Pooling type:
  623. - 0 = MAX
  624. - 1 = AVG
  625. Pad mode:
  626. - 0 = full padding
  627. - 1 = valid padding
  628. - 2 = tensorflow padding=SAME or onnx padding=SAME_UPPER
  629. - 3 = onnx padding=SAME_LOWER
  630. # selu
  631. ```
  632. if x < 0 y = (exp(x) - 1.f) * alpha * lambda
  633. else y = x * lambda
  634. ```
  635. * one_blob_only
  636. * support_inplace
  637. | param id | name | type | default | description |
  638. | --------- | ------------- | ----- | --------- | ----------------- |
  639. | 0 | alpha | float | 1.67326324f| |
  640. | 1 | lambda | float | 1.050700987f| |
  641. # sigmoid
  642. ```
  643. y = 1 / (1 + exp(-x))
  644. ```
  645. * one_blob_only
  646. * support_inplace
  647. # slice
  648. ```
  649. split x along axis into slices, each part slice size is based on slices array
  650. ```
  651. | param id | name | type | default | description |
  652. | --------- | ------------- | ----- | --------- | ----------------- |
  653. | 0 | slices | array | [ ] | |
  654. | 1 | axis | int | 0 | |
  655. # softmax
  656. ```
  657. softmax(x, axis)
  658. ```
  659. * one_blob_only
  660. * support_inplace
  661. | param id | name | type | default | description |
  662. | --------- | ------------- | ----- | --------- | ----------------- |
  663. | 0 | axis | int | 0 | |
  664. | 1 | fixbug0 | int | 0 | hack for bug fix, should be 1 |
  665. # softplus
  666. ```
  667. y = log(exp(x) + 1)
  668. ```
  669. * one_blob_only
  670. * support_inplace
  671. # split
  672. ```
  673. y0, y1 ... = x
  674. ```
  675. # swish
  676. ```
  677. y = x / (1 + exp(-x))
  678. ```
  679. * one_blob_only
  680. * support_inplace
  681. # tanh
  682. ```
  683. y = tanh(x)
  684. ```
  685. * one_blob_only
  686. * support_inplace
  687. # threshold
  688. ```
  689. if x > threshold y = 1
  690. else y = 0
  691. ```
  692. * one_blob_only
  693. * support_inplace
  694. | param id | name | type | default | description |
  695. | --------- | ------------- | ----- | --------- | ----------------- |
  696. | 0 | threshold | float | 0.f | |
  697. # unaryop
  698. ```
  699. y = unaryop(x)
  700. ```
  701. - one_blob_only
  702. - support_inplace
  703. | param id | name | type | default | description |
  704. | --------- | ------------- | ----- | --------- | ----------------- |
  705. | 0 | op_type | int | 0 | Operation type as follows |
  706. Operation type:
  707. - 0 = ABS
  708. - 1 = NEG
  709. - 2 = FLOOR
  710. - 3 = CEIL
  711. - 4 = SQUARE
  712. - 5 = SQRT
  713. - 6 = RSQ
  714. - 7 = EXP
  715. - 8 = LOG
  716. - 9 = SIN
  717. - 10 = COS
  718. - 11 = TAN
  719. - 12 = ASIN
  720. - 13 = ACOS
  721. - 14 = ATAN
  722. - 15 = RECIPROCAL
  723. - 16 = TANH