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

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303
  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. * [Convolution1D](#convolution1d)
  12. * [ConvolutionDepthWise](#convolutiondepthwise)
  13. * [Crop](#crop)
  14. * [Deconvolution](#deconvolution)
  15. * [DeconvolutionDepthWise](#deconvolutiondepthwise)
  16. * [Dequantize](#dequantize)
  17. * [Dropout](#dropout)
  18. * [Eltwise](#eltwise)
  19. * [ELU](#elu)
  20. * [Exp](#exp)
  21. * [Flatten](#flatten)
  22. * [GELU](#gelu)
  23. * [Gemm](#gemm)
  24. * [GroupNorm](#groupnorm)
  25. * [GRU](#gru)
  26. * [HardSigmoid](#hardsigmoid)
  27. * [HardSwish](#hardswish)
  28. * [InnerProduct](#innerproduct)
  29. * [Input](#input)
  30. * [InstanceNorm](#instancenorm)
  31. * [Interp](#interp)
  32. * [LayerNorm](#layernorm)
  33. * [Log](#log)
  34. * [LRN](#lrn)
  35. * [LSTM](#lstm)
  36. * [MemoryData](#memorydata)
  37. * [Mish](#mish)
  38. * [MultiHeadAttention](#multiheadattention)
  39. * [MVN](#mvn)
  40. * [Noop](#noop)
  41. * [Normalize](#normalize)
  42. * [Packing](#packing)
  43. * [Padding](#padding)
  44. * [Permute](#permute)
  45. * [PixelShuffle](#pixelshuffle)
  46. * [Pooling](#pooling)
  47. * [Pooling1D](#pooling1d)
  48. * [Power](#power)
  49. * [PReLU](#prelu)
  50. * [Quantize](#quantize)
  51. * [Reduction](#reduction)
  52. * [ReLU](#relu)
  53. * [Reorg](#reorg)
  54. * [Requantize](#requantize)
  55. * [Reshape](#reshape)
  56. * [RNN](#rnn)
  57. * [Scale](#scale)
  58. * [SELU](#selu)
  59. * [ShuffleChannel](#shufflechannel)
  60. * [Sigmoid](#sigmoid)
  61. * [Slice](#slice)
  62. * [Softmax](#softmax)
  63. * [Softplus](#softplus)
  64. * [Split](#split)
  65. * [Swish](#swish)
  66. * [TanH](#tanh)
  67. * [Threshold](#threshold)
  68. * [UnaryOp](#unaryop)
  69. # AbsVal
  70. ```
  71. y = abs(x)
  72. ```
  73. * one_blob_only
  74. * support_inplace
  75. # ArgMax
  76. ```
  77. y = argmax(x, out_max_val, topk)
  78. ```
  79. * one_blob_only
  80. | param id | name | type | default | description |
  81. | --------- | ------------- | ----- | --------- | ----------------- |
  82. | 0 | out_max_val | int | 0 | |
  83. | 1 | topk | int | 1 | |
  84. # BatchNorm
  85. ```
  86. y = (x - mean) / sqrt(var + eps) * slope + bias
  87. ```
  88. * one_blob_only
  89. * support_inplace
  90. | param id | name | type | default | description |
  91. | --------- | ------------- | ----- | --------- | ----------------- |
  92. | 0 | channels | int | 0 | |
  93. | 1 | eps | float | 0.f | |
  94. | weight | type | shape |
  95. | ------------- | ----- | --------------------- |
  96. | slope_data | float | [channels] |
  97. | mean_data | float | [channels] |
  98. | var_data | float | [channels] |
  99. | bias_data | float | [channels] |
  100. # Bias
  101. ```
  102. y = x + bias
  103. ```
  104. * one_blob_only
  105. * support_inplace
  106. | param id | name | type | default | description |
  107. | --------- | ------------- | ----- | --------- | ----------------- |
  108. | 0 | bias_data_size| int | 0 | |
  109. | weight | type | shape |
  110. | ------------- | ----- | --------------------- |
  111. | bias_data | float | [channels] |
  112. # BinaryOp
  113. This operation is used for binary computation, and the calculation rule depends on the [broadcasting rule](https://github.com/Tencent/ncnn/wiki/binaryop-broadcasting).
  114. ```
  115. C = binaryop(A, B)
  116. ```
  117. if with_scalar = 1:
  118. - one_blob_only
  119. - support_inplace
  120. | param id | name | type | default | description |
  121. | --------- | ------------- | ----- | --------- | ----------------- |
  122. | 0 | op_type | int | 0 | Operation type as follows |
  123. | 1 | with_scalar | int | 0 | with_scalar=0 B is a matrix, with_scalar=1 B is a scalar |
  124. | 2 | b | float | 0.f | When B is a scalar, B = b |
  125. Operation type:
  126. - 0 = ADD
  127. - 1 = SUB
  128. - 2 = MUL
  129. - 3 = DIV
  130. - 4 = MAX
  131. - 5 = MIN
  132. - 6 = POW
  133. - 7 = RSUB
  134. - 8 = RDIV
  135. # BNLL
  136. ```
  137. y = log(1 + e^(-x)) , x > 0
  138. y = log(1 + e^x), x < 0
  139. ```
  140. * one_blob_only
  141. * support_inplace
  142. # Cast
  143. ```
  144. y = cast(x)
  145. ```
  146. * one_blob_only
  147. * support_packing
  148. | param id | name | type | default | description |
  149. | --------- | ------------- | ----- | --------- | ----------------- |
  150. | 0 | type_from | int | 0 | |
  151. | 1 | type_to | int | 0 | |
  152. Element type:
  153. - 0 = auto
  154. - 1 = float32
  155. - 2 = float16
  156. - 3 = int8
  157. - 4 = bfloat16
  158. # Clip
  159. ```
  160. y = clamp(x, min, max)
  161. ```
  162. * one_blob_only
  163. * support_inplace
  164. | param id | name | type | default | description |
  165. | --------- | ------------- | ----- | --------- | ----------------- |
  166. | 0 | min | float | -FLT_MAX | |
  167. | 1 | max | float | FLT_MAX | |
  168. # Concat
  169. ```
  170. y = concat(x0, x1, x2, ...) by axis
  171. ```
  172. | param id | name | type | default | description |
  173. | --------- | ------------- | ----- | --------- | ----------------- |
  174. | 0 | axis | int | 0 | |
  175. # Convolution
  176. ```
  177. x2 = pad(x, pads, pad_value)
  178. x3 = conv(x2, weight, kernel, stride, dilation) + bias
  179. y = activation(x3, act_type, act_params)
  180. ```
  181. * one_blob_only
  182. | param id | name | type | default | description |
  183. | --------- | ------------- | ----- | --------- | ----------------- |
  184. | 0 | num_output | int | 0 | |
  185. | 1 | kernel_w | int | 0 | |
  186. | 2 | dilation_w | int | 1 | |
  187. | 3 | stride_w | int | 1 | |
  188. | 4 | pad_left | int | 0 | |
  189. | 5 | bias_term | int | 0 | |
  190. | 6 | weight_data_size| int | 0 | |
  191. | 8 | int8_scale_term| int | 0 | |
  192. | 9 | activation_type| int | 0 | |
  193. | 10 | activation_params| array | [ ] | |
  194. | 11 | kernel_h | int | kernel_w | |
  195. | 12 | dilation_h | int | dilation_w | |
  196. | 13 | stride_h | int | stride_w | |
  197. | 15 | pad_right | int | pad_left | |
  198. | 14 | pad_top | int | pad_left | |
  199. | 16 | pad_bottom | int | pad_top | |
  200. | 18 | pad_value | float | 0.f | |
  201. | weight | type | shape |
  202. | ------------- | ----- | --------------------- |
  203. | weight_data | float/fp16/int8 | [kernel_w, kernel_h, num_input, num_output] |
  204. | bias_data | float | [num_output] |
  205. | weight_data_int8_scales| float | [num_output] |
  206. | bottom_blob_int8_scales| float | [1] |
  207. | top_blob_int8_scales| float | [1] |
  208. # Convolution1D
  209. ```
  210. x2 = pad(x, pads, pad_value)
  211. x3 = conv1d(x2, weight, kernel, stride, dilation) + bias
  212. y = activation(x3, act_type, act_params)
  213. ```
  214. * one_blob_only
  215. | param id | name | type | default | description |
  216. | --------- | ------------- | ----- | --------- | ----------------- |
  217. | 0 | num_output | int | 0 | |
  218. | 1 | kernel_w | int | 0 | |
  219. | 2 | dilation_w | int | 1 | |
  220. | 3 | stride_w | int | 1 | |
  221. | 4 | pad_left | int | 0 | |
  222. | 5 | bias_term | int | 0 | |
  223. | 6 | weight_data_size| int | 0 | |
  224. | 9 | activation_type| int | 0 | |
  225. | 10 | activation_params| array | [ ] | |
  226. | 15 | pad_right | int | pad_left | |
  227. | 18 | pad_value | float | 0.f | |
  228. | weight | type | shape |
  229. | ------------- | ----- | --------------------- |
  230. | weight_data | float/fp16/int8 | [kernel_w, num_input, num_output] |
  231. | bias_data | float | [num_output] |
  232. # ConvolutionDepthWise
  233. ```
  234. x2 = pad(x, pads, pad_value)
  235. x3 = conv(x2, weight, kernel, stride, dilation, group) + bias
  236. y = activation(x3, act_type, act_params)
  237. ```
  238. * one_blob_only
  239. | param id | name | type | default | description |
  240. | --------- | ------------- | ----- | --------- | ----------------- |
  241. | 0 | num_output | int | 0 | |
  242. | 1 | kernel_w | int | 0 | |
  243. | 2 | dilation_w | int | 1 | |
  244. | 3 | stride_w | int | 1 | |
  245. | 4 | pad_left | int | 0 | |
  246. | 5 | bias_term | int | 0 | |
  247. | 6 | weight_data_size| int | 0 | |
  248. | 7 | group | int | 1 | |
  249. | 8 | int8_scale_term| int | 0 | |
  250. | 9 | activation_type| int | 0 | |
  251. | 10 | activation_params| array | [ ] | |
  252. | 11 | kernel_h | int | kernel_w | |
  253. | 12 | dilation_h | int | dilation_w | |
  254. | 13 | stride_h | int | stride_w | |
  255. | 15 | pad_right | int | pad_left | |
  256. | 14 | pad_top | int | pad_left | |
  257. | 16 | pad_bottom | int | pad_top | |
  258. | 18 | pad_value | float | 0.f | |
  259. | weight | type | shape |
  260. | ------------- | ----- | --------------------- |
  261. | weight_data | float/fp16/int8 | [kernel_w, kernel_h, num_input / group, num_output / group, group] |
  262. | bias_data | float | [num_output] |
  263. | weight_data_int8_scales| float | [group] |
  264. | bottom_blob_int8_scales| float | [1] |
  265. | top_blob_int8_scales| float | [1] |
  266. # Crop
  267. ```
  268. y = crop(x)
  269. ```
  270. * one_blob_only
  271. | param id | name | type | default | description |
  272. | --------- | ------------- | ----- | --------- | ----------------- |
  273. | 0 | woffset | int | 0 | |
  274. | 1 | hoffset | int | 0 | |
  275. | 2 | coffset | int | 1 | |
  276. | 3 | outw | int | 1 | |
  277. | 4 | outh | int | 0 | |
  278. | 5 | outc | int | 0 | |
  279. | 6 | woffset2 | int | 0 | |
  280. | 7 | hoffset2 | int | 1 | |
  281. | 8 | coffset2 | int | 0 | |
  282. | 9 | starts | array | [ ] | |
  283. | 10 | ends | array | [ ] | |
  284. | 11 | axes | array | [ ] | |
  285. # Deconvolution
  286. ```
  287. x2 = deconv(x, weight, kernel, stride, dilation) + bias
  288. x3 = depad(x2, pads, pad_value)
  289. y = activation(x3, act_type, act_params)
  290. ```
  291. * one_blob_only
  292. | param id | name | type | default | description |
  293. | --------- | ------------- | ----- | --------- | ----------------- |
  294. | 0 | num_output | int | 0 | |
  295. | 1 | kernel_w | int | 0 | |
  296. | 2 | dilation_w | int | 1 | |
  297. | 3 | stride_w | int | 1 | |
  298. | 4 | pad_left | int | 0 | |
  299. | 5 | bias_term | int | 0 | |
  300. | 6 | weight_data_size| int | 0 | |
  301. | 8 | int8_scale_term| int | 0 | |
  302. | 9 | activation_type| int | 0 | |
  303. | 10 | activation_params| array | [ ] | |
  304. | 11 | kernel_h | int | kernel_w | |
  305. | 12 | dilation_h | int | dilation_w | |
  306. | 13 | stride_h | int | stride_w | |
  307. | 15 | pad_right | int | pad_left | |
  308. | 14 | pad_top | int | pad_left | |
  309. | 16 | pad_bottom | int | pad_top | |
  310. | 18 | output_pad_right| int | 0 | |
  311. | 19 | output_pad_bottom| int | output_pad_right | |
  312. | 20 | output_w | int | 0 | |
  313. | 21 | output_h | int | output_w | |
  314. | weight | type | shape |
  315. | ------------- | ----- | --------------------- |
  316. | weight_data | float/fp16/int8 | [kernel_w, kernel_h, num_input, num_output] |
  317. | bias_data | float | [num_output] |
  318. # DeconvolutionDepthWise
  319. ```
  320. x2 = deconv(x, weight, kernel, stride, dilation, group) + bias
  321. x3 = depad(x2, pads, pad_value)
  322. y = activation(x3, act_type, act_params)
  323. ```
  324. * one_blob_only
  325. | param id | name | type | default | description |
  326. | --------- | ------------- | ----- | --------- | ----------------- |
  327. | 0 | num_output | int | 0 | |
  328. | 1 | kernel_w | int | 0 | |
  329. | 2 | dilation_w | int | 1 | |
  330. | 3 | stride_w | int | 1 | |
  331. | 4 | pad_left | int | 0 | |
  332. | 5 | bias_term | int | 0 | |
  333. | 6 | weight_data_size| int | 0 | |
  334. | 7 | group | int | 1 | |
  335. | 8 | int8_scale_term| int | 0 | |
  336. | 9 | activation_type| int | 0 | |
  337. | 10 | activation_params| array | [ ] | |
  338. | 11 | kernel_h | int | kernel_w | |
  339. | 12 | dilation_h | int | dilation_w | |
  340. | 13 | stride_h | int | stride_w | |
  341. | 15 | pad_right | int | pad_left | |
  342. | 14 | pad_top | int | pad_left | |
  343. | 16 | pad_bottom | int | pad_top | |
  344. | 18 | output_pad_right| int | 0 | |
  345. | 19 | output_pad_bottom| int | output_pad_right | |
  346. | 20 | output_w | int | 0 | |
  347. | 21 | output_h | int | output_w | |
  348. | weight | type | shape |
  349. | ------------- | ----- | --------------------- |
  350. | weight_data | float/fp16/int8 | [kernel_w, kernel_h, num_input / group, num_output / group, group] |
  351. | bias_data | float | [num_output] |
  352. # Dequantize
  353. ```
  354. y = x * scale + bias
  355. ```
  356. * one_blob_only
  357. * support_inplace
  358. | param id | name | type | default | description |
  359. | --------- | ------------- | ----- | --------- | ----------------- |
  360. | 0 | scale | float | 1.f | |
  361. | 1 | bias_term | int | 0 | |
  362. | 2 | bias_data_size| int | 0 | |
  363. # Dropout
  364. ```
  365. y = x * scale
  366. ```
  367. * one_blob_only
  368. | param id | name | type | default | description |
  369. | --------- | ------------- | ----- | --------- | ----------------- |
  370. | 0 | scale | float | 1.f | |
  371. # Eltwise
  372. ```
  373. y = elementwise_op(x0, x1, ...)
  374. ```
  375. | param id | name | type | default | description |
  376. | --------- | ------------- | ----- | --------- | ----------------- |
  377. | 0 | op_type | int | 0 | |
  378. | 1 | coeffs | array | [ ] | |
  379. Operation type:
  380. - 0 = PROD
  381. - 1 = SUM
  382. - 2 = MAX
  383. # ELU
  384. ```
  385. if x < 0 y = (exp(x) - 1) * alpha
  386. else y = x
  387. ```
  388. * one_blob_only
  389. * support_inplace
  390. | param id | name | type | default | description |
  391. | --------- | ------------- | ----- | --------- | ----------------- |
  392. | 0 | alpha | float | 0.1f | |
  393. # Exp
  394. ```
  395. if base == -1 y = exp(shift + x * scale)
  396. else y = pow(base, (shift + x * scale))
  397. ```
  398. * one_blob_only
  399. * support_inplace
  400. | param id | name | type | default | description |
  401. | --------- | ------------- | ----- | --------- | ----------------- |
  402. | 0 | base | float | -1.f | |
  403. | 1 | scale | float | 1.f | |
  404. | 2 | shift | float | 0.f | |
  405. # Flatten
  406. Reshape blob to 1 dimension
  407. * one_blob_only
  408. # GELU
  409. ```
  410. if fast_gelu == 1 y = 0.5 * x * (1 + tanh(0.79788452 * (x + 0.044715 * x * x * x)));
  411. else y = 0.5 * x * erfc(-0.70710678 * x)
  412. ```
  413. * one_blob_only
  414. * support_inplace
  415. | param id | name | type | default | description |
  416. | --------- | ------------- | ----- | --------- | ----------------- |
  417. | 0 | fast_gelu | int | 0 | use approximation |
  418. # Gemm
  419. ```
  420. a = transA ? transpose(x0) : x0
  421. b = transb ? transpose(x1) : x1
  422. c = x2
  423. y = gemm(a, b) * alpha + c * beta
  424. ```
  425. | param id | name | type | default | description |
  426. | --------- | ------------- | ----- | --------- | ----------------- |
  427. | 0 | alpha | float | 1.f | |
  428. | 1 | beta | float | 1.f | |
  429. | 2 | transA | int | 0 | |
  430. | 3 | transb | int | 0 | |
  431. # GroupNorm
  432. ```
  433. split x along channel axis into group x0, x1 ...
  434. l2 normalize for each group x0, x1 ...
  435. y = x * gamma + beta
  436. ```
  437. * one_blob_only
  438. * support_inplace
  439. | param id | name | type | default | description |
  440. | --------- | ------------- | ----- | --------- | ----------------- |
  441. | 0 | group | int | 1 | |
  442. | 1 | channels | int | 0 | |
  443. | 2 | eps | float | 0.001f | x = x / sqrt(var + eps) |
  444. | 3 | affine | int | 1 | |
  445. | weight | type | shape |
  446. | ------------- | ----- | --------------------- |
  447. | gamma_data | float | [channels] |
  448. | beta_data | float | [channels] |
  449. # GRU
  450. 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]`.
  451. ```
  452. y = gru(x)
  453. y0, hidden y1 = gru(x0, hidden x1)
  454. ```
  455. * one_blob_only if bidirectional
  456. | param id | name | type | default | description |
  457. | --------- | ------------- | ----- | --------- | ----------------- |
  458. | 0 | num_output | int | 0 | hidden size of output |
  459. | 1 | weight_data_size| int | 0 | total size of weight matrix |
  460. | 2 | direction | int | 0 | 0=forward, 1=reverse, 2=bidirectional |
  461. | weight | type | shape |
  462. | ------------- | ----- | --------------------- |
  463. | weight_xc_data| float/fp16/int8 | [input_size, num_output * 3, num_directions] |
  464. | bias_c_data | float/fp16/int8 | [num_output, 4, num_directions] |
  465. | weight_hc_data| float/fp16/int8 | [num_output, num_output * 3, num_directions] |
  466. Direction flag:
  467. - 0 = forward only
  468. - 1 = reverse only
  469. - 2 = bidirectional
  470. # HardSigmoid
  471. ```
  472. y = clamp(x * alpha + beta, 0, 1)
  473. ```
  474. * one_blob_only
  475. * support_inplace
  476. | param id | name | type | default | description |
  477. | --------- | ------------- | ----- | --------- | ----------------- |
  478. | 0 | alpha | float | 0.2f | |
  479. | 1 | beta | float | 0.5f | |
  480. # HardSwish
  481. ```
  482. y = x * clamp(x * alpha + beta, 0, 1)
  483. ```
  484. * one_blob_only
  485. * support_inplace
  486. | param id | name | type | default | description |
  487. | --------- | ------------- | ----- | --------- | ----------------- |
  488. | 0 | alpha | float | 0.2f | |
  489. | 1 | beta | float | 0.5f | |
  490. # InnerProduct
  491. ```
  492. x2 = innerproduct(x, weight) + bias
  493. y = activation(x2, act_type, act_params)
  494. ```
  495. * one_blob_only
  496. | param id | name | type | default | description |
  497. | --------- | ------------- | ----- | --------- | ----------------- |
  498. | 0 | num_output | int | 0 | |
  499. | 1 | bias_term | int | 0 | |
  500. | 2 | weight_data_size| int | 0 | |
  501. | 8 | int8_scale_term| int | 0 | |
  502. | 9 | activation_type| int | 0 | |
  503. | 10 | activation_params| array | [ ] | |
  504. | weight | type | shape |
  505. | ------------- | ----- | --------------------- |
  506. | weight_data | float/fp16/int8 | [num_input, num_output] |
  507. | bias_data | float | [num_output] |
  508. | weight_data_int8_scales| float | [num_output] |
  509. | bottom_blob_int8_scales| float | [1] |
  510. # Input
  511. ```
  512. y = input
  513. ```
  514. * support_inplace
  515. | param id | name | type | default | description |
  516. | --------- | ------------- | ----- | --------- | ----------------- |
  517. | 0 | w | int | 0 | |
  518. | 1 | h | int | 0 | |
  519. | 2 | c | int | 0 | |
  520. # InstanceNorm
  521. ```
  522. split x along channel axis into instance x0, x1 ...
  523. l2 normalize for each channel instance x0, x1 ...
  524. y = x * gamma + beta
  525. ```
  526. * one_blob_only
  527. * support_inplace
  528. | param id | name | type | default | description |
  529. | --------- | ------------- | ----- | --------- | ----------------- |
  530. | 0 | channels | int | 0 | |
  531. | 1 | eps | float | 0.001f | x = x / sqrt(var + eps) |
  532. | 2 | affine | int | 1 | |
  533. | weight | type | shape |
  534. | ------------- | ----- | --------------------- |
  535. | gamma_data | float | [channels] |
  536. | beta_data | float | [channels] |
  537. # Interp
  538. ```
  539. if dynamic_target_size == 0 y = resize(x) by fixed size or scale
  540. else y = resize(x0, size(x1))
  541. ```
  542. * one_blob_only if dynamic_target_size == 0
  543. | param id | name | type | default | description |
  544. | --------- | ------------- | ----- | --------- | ----------------- |
  545. | 0 | resize_type | int | 0 | |
  546. | 1 | height_scale | float | 1.f | |
  547. | 2 | width_scale | float | 1.f | |
  548. | 3 | output_height | int | 0 | |
  549. | 4 | output_width | int | 0 | |
  550. | 5 | dynamic_target_size| int | 0 | |
  551. | 6 | align_corner | int | 0 | |
  552. Resize type:
  553. - 1 = Nearest
  554. - 2 = Bilinear
  555. - 3 = Bicubic
  556. # LayerNorm
  557. ```
  558. split x along outmost axis into part x0, x1 ...
  559. l2 normalize for each part x0, x1 ...
  560. y = x * gamma + beta by elementwise
  561. ```
  562. * one_blob_only
  563. * support_inplace
  564. | param id | name | type | default | description |
  565. | --------- | ------------- | ----- | --------- | ----------------- |
  566. | 0 | affine_size | int | 0 | |
  567. | 1 | eps | float | 0.001f | x = x / sqrt(var + eps) |
  568. | 2 | affine | int | 1 | |
  569. | weight | type | shape |
  570. | ------------- | ----- | --------------------- |
  571. | gamma_data | float | [affine_size] |
  572. | beta_data | float | [affine_size] |
  573. # Log
  574. ```
  575. if base == -1 y = log(shift + x * scale)
  576. else y = log(shift + x * scale) / log(base)
  577. ```
  578. * one_blob_only
  579. * support_inplace
  580. | param id | name | type | default | description |
  581. | --------- | ------------- | ----- | --------- | ----------------- |
  582. | 0 | base | float | -1.f | |
  583. | 1 | scale | float | 1.f | |
  584. | 2 | shift | float | 0.f | |
  585. # LRN
  586. ```
  587. if region_type == ACROSS_CHANNELS square_sum = sum of channel window of local_size
  588. if region_type == WITHIN_CHANNEL square_sum = sum of spatial window of local_size
  589. y = x * pow(bias + alpha * square_sum / (local_size * local_size), -beta)
  590. ```
  591. * one_blob_only
  592. * support_inplace
  593. | param id | name | type | default | description |
  594. | --------- | ------------- | ----- | --------- | ----------------- |
  595. | 0 | region_type | int | 0 | |
  596. | 1 | local_size | int | 5 | |
  597. | 2 | alpha | float | 1.f | |
  598. | 3 | beta | float | 0.75f | |
  599. | 4 | bias | float | 1.f | |
  600. Region type:
  601. - 0 = ACROSS_CHANNELS
  602. - 1 = WITHIN_CHANNEL
  603. # LSTM
  604. 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]`.
  605. ```
  606. y = lstm(x)
  607. y0, hidden y1, cell y2 = lstm(x0, hidden x1, cell x2)
  608. ```
  609. * one_blob_only if bidirectional
  610. | param id | name | type | default | description |
  611. | --------- | ------------- | ----- | --------- | ----------------- |
  612. | 0 | num_output | int | 0 | hidden size of output |
  613. | 1 | weight_data_size| int | 0 | total size of IFOG weight matrix |
  614. | 2 | direction | int | 0 | 0=forward, 1=reverse, 2=bidirectional |
  615. | weight | type | shape |
  616. | ------------- | ----- | --------------------- |
  617. | weight_xc_data| float/fp16/int8 | [input_size, num_output * 4, num_directions] |
  618. | bias_c_data | float/fp16/int8 | [num_output, 4, num_directions] |
  619. | weight_hc_data| float/fp16/int8 | [num_output, num_output * 4, num_directions] |
  620. Direction flag:
  621. - 0 = forward only
  622. - 1 = reverse only
  623. - 2 = bidirectional
  624. # MemoryData
  625. ```
  626. y = data
  627. ```
  628. | param id | name | type | default | description |
  629. | --------- | ------------- | ----- | --------- | ----------------- |
  630. | 0 | w | int | 0 | |
  631. | 1 | h | int | 0 | |
  632. | 2 | c | int | 0 | |
  633. | weight | type | shape |
  634. | ------------- | ----- | --------------------- |
  635. | data | float | [w, h, c] |
  636. # Mish
  637. ```
  638. y = x * tanh(log(exp(x) + 1))
  639. ```
  640. * one_blob_only
  641. * support_inplace
  642. # MultiHeadAttention
  643. ```
  644. split q k v into num_head part q0, k0, v0, q1, k1, v1 ...
  645. for each num_head part
  646. xq = affine(q) / (embed_dim / num_head)
  647. xk = affine(k)
  648. xv = affine(v)
  649. xqk = xq * xk
  650. softmax_inplace(xqk)
  651. xqkv = xqk * xv
  652. merge xqkv to out
  653. y = affine(out)
  654. ```
  655. | param id | name | type | default | description |
  656. | --------- | ------------- | ----- | --------- | ----------------- |
  657. | 0 | embed_dim | int | 0 | |
  658. | 1 | num_head | int | 1 | |
  659. | 2 | weight_data_size| int | 0 | |
  660. | weight | type | shape |
  661. | ------------- | ----- | --------------------- |
  662. | q_weight_data | float/fp16/int8 | [weight_data_size] |
  663. | q_bias_data | float | [embed_dim] |
  664. | k_weight_data | float/fp16/int8 | [weight_data_size] |
  665. | k_bias_data | float | [embed_dim] |
  666. | v_weight_data | float/fp16/int8 | [weight_data_size] |
  667. | v_bias_data | float | [embed_dim] |
  668. | out_weight_data| float/fp16/int8 | [weight_data_size] |
  669. | out_bias_data | float | [embed_dim] |
  670. # MVN
  671. ```
  672. if normalize_variance == 1 && across_channels == 1 y = (x - mean) / (sqrt(var) + eps) of whole blob
  673. if normalize_variance == 1 && across_channels == 0 y = (x - mean) / (sqrt(var) + eps) of each channel
  674. if normalize_variance == 0 && across_channels == 1 y = x - mean of whole blob
  675. if normalize_variance == 0 && across_channels == 0 y = x - mean of each channel
  676. ```
  677. * one_blob_only
  678. | param id | name | type | default | description |
  679. | --------- | ------------- | ----- | --------- | ----------------- |
  680. | 0 | normalize_variance| int | 0 | |
  681. | 1 | across_channels| int | 0 | |
  682. | 2 | eps | float | 0.0001f | x = x / (sqrt(var) + eps) |
  683. # Noop
  684. ```
  685. y = x
  686. ```
  687. # Normalize
  688. ```
  689. if across_spatial == 1 && across_channel == 1 x2 = normalize(x) of whole blob
  690. if across_spatial == 1 && across_channel == 0 x2 = normalize(x) of each channel
  691. if across_spatial == 0 && across_channel == 1 x2 = normalize(x) of each position
  692. y = x2 * scale
  693. ```
  694. * one_blob_only
  695. * support_inplace
  696. | param id | name | type | default | description |
  697. | --------- | ------------- | ----- | --------- | ----------------- |
  698. | 0 | across_spatial| int | 0 | |
  699. | 1 | channel_shared| int | 0 | |
  700. | 2 | eps | float | 0.0001f | see eps mode |
  701. | 3 | scale_data_size| int | 0 | |
  702. | 4 | across_channel| int | 0 | |
  703. | 9 | eps_mode | int | 0 | |
  704. | weight | type | shape |
  705. | ------------- | ----- | --------------------- |
  706. | scale_data | float | [scale_data_size] |
  707. Eps Mode:
  708. - 0 = caffe/mxnet x = x / sqrt(var + eps)
  709. - 1 = pytorch x = x / max(sqrt(var), eps)
  710. - 2 = tensorflow x = x / sqrt(max(var, eps))
  711. # Packing
  712. ```
  713. y = wrap_packing(x)
  714. ```
  715. * one_blob_only
  716. | param id | name | type | default | description |
  717. | --------- | ------------- | ----- | --------- | ----------------- |
  718. | 0 | out_elempack | int | 1 | |
  719. | 1 | use_padding | int | 0 | |
  720. | 2 | cast_type_from| int | 0 | |
  721. | 3 | cast_type_to | int | 0 | |
  722. | 4 | storage_type_from| int | 0 | |
  723. | 5 | storage_type_to| int | 0 | |
  724. # Padding
  725. ```
  726. y = pad(x, pads)
  727. ```
  728. | param id | name | type | default | description |
  729. | --------- | ------------- | ---- | --------- | ----------------- |
  730. | 0 | top | int | 0 | |
  731. | 1 | bottom | int | 0 | |
  732. | 2 | left | int | 0 | |
  733. | 3 | right | int | 0 | |
  734. | 4 | type | int | 0 | |
  735. | 5 | value | float | 0 | |
  736. | 6 | per_channel_pad_data_size| int | 0 | |
  737. | 7 | front | int | stride_w | |
  738. | 8 | behind | int | pad_left | |
  739. | weight | type | shape |
  740. | ------------- | ----- | --------------------- |
  741. | per_channel_pad_data| float | [per_channel_pad_data_size] |
  742. Padding type:
  743. - 0 = CONSTANT
  744. - 1 = REPLICATE
  745. - 2 = REFLECT
  746. # Permute
  747. ```
  748. y = reorder(x)
  749. ```
  750. | param id | name | type | default | description |
  751. | --------- | ------------- | ---- | --------- | ----------------- |
  752. | 0 | order_type | int | 0 | |
  753. Order Type:
  754. - 0 = WH WHC
  755. - 1 = HW HWC
  756. - 2 = WCH
  757. - 3 = CWH
  758. - 4 = HCW
  759. - 5 = CHW
  760. # PixelShuffle
  761. ```
  762. if mode == 0 y = depth_to_space(x) where x channel order is sw-sh-outc
  763. if mode == 1 y = depth_to_space(x) where x channel order is outc-sw-sh
  764. ```
  765. * one_blob_only
  766. | param id | name | type | default | description |
  767. | --------- | ------------- | ---- | --------- | ----------------- |
  768. | 0 | upscale_factor| int | 1 | |
  769. | 1 | mode | int | 0 | |
  770. # Pooling
  771. ```
  772. x2 = pad(x, pads)
  773. x3 = pooling(x2, kernel, stride)
  774. ```
  775. | param id | name | type | default | description |
  776. | --------- | --------------| ---- | --------- | ----------------- |
  777. | 0 | pooling_type | int | 0 | |
  778. | 1 | kernel_w | int | 0 | |
  779. | 2 | stride_w | int | 1 | |
  780. | 3 | pad_left | int | 0 | |
  781. | 4 | global_pooling| int | 0 | |
  782. | 5 | pad_mode | int | 0 | |
  783. | 6 | avgpool_count_include_pad| int | 0 | |
  784. | 7 | adaptive_pooling| int | 0 | |
  785. | 8 | out_w | int | 0 | |
  786. | 11 | kernel_h | int | kernel_w | |
  787. | 12 | stride_h | int | stride_w | |
  788. | 13 | pad_top | int | pad_left | |
  789. | 14 | pad_right | int | pad_left | |
  790. | 15 | pad_bottom | int | pad_top | |
  791. | 18 | out_h | int | 0 | |
  792. Pooling type:
  793. - 0 = MAX
  794. - 1 = AVG
  795. Pad mode:
  796. - 0 = full padding
  797. - 1 = valid padding
  798. - 2 = tensorflow padding=SAME or onnx padding=SAME_UPPER
  799. - 3 = onnx padding=SAME_LOWER
  800. # Pooling1D
  801. ```
  802. x2 = pad(x, pads)
  803. x3 = pooling1d(x2, kernel, stride)
  804. ```
  805. | param id | name | type | default | description |
  806. | --------- | --------------| ---- | --------- | ----------------- |
  807. | 0 | pooling_type | int | 0 | |
  808. | 1 | kernel_w | int | 0 | |
  809. | 2 | stride_w | int | 1 | |
  810. | 3 | pad_left | int | 0 | |
  811. | 4 | global_pooling| int | 0 | |
  812. | 5 | pad_mode | int | 0 | |
  813. | 6 | avgpool_count_include_pad| int | 0 | |
  814. | 7 | adaptive_pooling| int | 0 | |
  815. | 8 | out_w | int | 0 | |
  816. | 14 | pad_right | int | pad_left | |
  817. Pooling type:
  818. - 0 = MAX
  819. - 1 = AVG
  820. Pad mode:
  821. - 0 = full padding
  822. - 1 = valid padding
  823. - 2 = tensorflow padding=SAME or onnx padding=SAME_UPPER
  824. - 3 = onnx padding=SAME_LOWER
  825. # Power
  826. ```
  827. y = pow((shift + x * scale), power)
  828. ```
  829. * one_blob_only
  830. * support_inplace
  831. | param id | name | type | default | description |
  832. | --------- | ------------- | ----- | --------- | ----------------- |
  833. | 0 | power | float | 1.f | |
  834. | 1 | scale | float | 1.f | |
  835. | 2 | shift | float | 0.f | |
  836. # PReLU
  837. ```
  838. if x < 0 y = x * slope
  839. else y = x
  840. ```
  841. * one_blob_only
  842. * support_inplace
  843. | param id | name | type | default | description |
  844. | --------- | ------------- | ----- | --------- | ----------------- |
  845. | 0 | num_slope | int | 0 | |
  846. | weight | type | shape |
  847. | ------------- | ----- | --------------------- |
  848. | slope_data | float | [num_slope] |
  849. # Quantize
  850. ```
  851. y = float2int8(x * scale)
  852. ```
  853. * one_blob_only
  854. | param id | name | type | default | description |
  855. | --------- | ------------- | ----- | --------- | ----------------- |
  856. | 0 | scale_data_size| int | 0 | |
  857. | weight | type | shape |
  858. | ------------- | ----- | --------------------- |
  859. | scale_data | float | [scale_data_size] |
  860. # Reduction
  861. ```
  862. y = reduce_op(x * coeff)
  863. ```
  864. * one_blob_only
  865. | param id | name | type | default | description |
  866. | --------- | ------------- | ----- | --------- | ----------------- |
  867. | 0 | operation | int | 0 | |
  868. | 1 | reduce_all | int | 1 | |
  869. | 2 | coeff | float | 1.f | |
  870. | 3 | axes | array | [ ] | |
  871. | 4 | keepdims | int | 0 | |
  872. Operation type:
  873. - 0 = SUM
  874. - 1 = ASUM
  875. - 2 = SUMSQ
  876. - 3 = MEAN
  877. - 4 = MAX
  878. - 5 = MIN
  879. - 6 = PROD
  880. - 7 = L1
  881. - 8 = L2
  882. - 9 = LogSum
  883. - 10 = LogSumExp
  884. # ReLU
  885. ```
  886. if x < 0 y = x * slope
  887. else y = x
  888. ```
  889. * one_blob_only
  890. * support_inplace
  891. | param id | name | type | default | description |
  892. | --------- | ------------- | ----- | --------- | ----------------- |
  893. | 0 | slope | float | 0.f | |
  894. # Reorg
  895. ```
  896. if mode == 0 y = space_to_depth(x) where x channel order is sw-sh-outc
  897. if mode == 1 y = space_to_depth(x) where x channel order is outc-sw-sh
  898. ```
  899. * one_blob_only
  900. | param id | name | type | default | description |
  901. | --------- | ------------- | ---- | --------- | ----------------- |
  902. | 0 | stride | int | 1 | |
  903. | 1 | mode | int | 0 | |
  904. # Requantize
  905. ```
  906. x2 = x * scale_in + bias
  907. x3 = activation(x2)
  908. y = float2int8(x3 * scale_out)
  909. ```
  910. * one_blob_only
  911. | param id | name | type | default | description |
  912. | --------- | ------------- | ----- | --------- | ----------------- |
  913. | 0 | scale_in_data_size| int | 1 | |
  914. | 1 | scale_out_data_size| int | 1 | |
  915. | 2 | bias_data_size| int | 0 | |
  916. | 3 | activation_type| int | 0 | |
  917. | 4 | activation_params| int | [ ] | |
  918. | weight | type | shape |
  919. | ------------- | ----- | --------------------- |
  920. | scale_in_data | float | [scale_in_data_size] |
  921. | scale_out_data| float | [scale_out_data_size] |
  922. | bias_data | float | [bias_data_size] |
  923. # Reshape
  924. ```
  925. if permute == 1 y = hwc2chw(reshape(chw2hwc(x)))
  926. else y = reshape(x)
  927. ```
  928. * one_blob_only
  929. | param id | name | type | default | description |
  930. | --------- | ------------- | ----- | --------- | ----------------- |
  931. | 0 | w | int | -233 | |
  932. | 1 | h | int | -233 | |
  933. | 2 | c | int | -233 | |
  934. | 3 | permute | int | 0 | |
  935. Reshape flag:
  936. - 0 = copy from bottom
  937. - -1 = remaining
  938. - -233 = drop this dim(default)
  939. # RNN
  940. Apply a single-layer RNN 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]`.
  941. ```
  942. y = rnn(x)
  943. y0, hidden y1 = rnn(x0, hidden x1)
  944. ```
  945. * one_blob_only if bidirectional
  946. | param id | name | type | default | description |
  947. | --------- | ------------- | ----- | --------- | ----------------- |
  948. | 0 | num_output | int | 0 | hidden size of output |
  949. | 1 | weight_data_size| int | 0 | total size of weight matrix |
  950. | 2 | direction | int | 0 | 0=forward, 1=reverse, 2=bidirectional |
  951. | weight | type | shape |
  952. | ------------- | ----- | --------------------- |
  953. | weight_xc_data| float/fp16/int8 | [input_size, num_output, num_directions] |
  954. | bias_c_data | float/fp16/int8 | [num_output, 1, num_directions] |
  955. | weight_hc_data| float/fp16/int8 | [num_output, num_output, num_directions] |
  956. Direction flag:
  957. - 0 = forward only
  958. - 1 = reverse only
  959. - 2 = bidirectional
  960. # Scale
  961. ```
  962. if scale_data_size == -233 y = x0 * x1
  963. else y = x * scale + bias
  964. ```
  965. * one_blob_only if scale_data_size != -233
  966. * support_inplace
  967. | param id | name | type | default | description |
  968. | --------- | ------------- | ----- | --------- | ----------------- |
  969. | 0 | scale_data_size| int | 0 | |
  970. | 1 | bias_term | int | 0 | |
  971. | weight | type | shape |
  972. | ------------- | ----- | --------------------- |
  973. | scale_data | float | [scale_data_size] |
  974. | bias_data | float | [scale_data_size] |
  975. # SELU
  976. ```
  977. if x < 0 y = (exp(x) - 1.f) * alpha * lambda
  978. else y = x * lambda
  979. ```
  980. * one_blob_only
  981. * support_inplace
  982. | param id | name | type | default | description |
  983. | --------- | ------------- | ----- | --------- | ----------------- |
  984. | 0 | alpha | float | 1.67326324f| |
  985. | 1 | lambda | float | 1.050700987f| |
  986. # ShuffleChannel
  987. ```
  988. if reverse == 0 y = shufflechannel(x) by group
  989. if reverse == 1 y = shufflechannel(x) by channel / group
  990. ```
  991. * one_blob_only
  992. | param id | name | type | default | description |
  993. | --------- | ------------- | ---- | --------- | ----------------- |
  994. | 0 | group | int | 1 | |
  995. | 1 | reverse | int | 0 | |
  996. # Sigmoid
  997. ```
  998. y = 1 / (1 + exp(-x))
  999. ```
  1000. * one_blob_only
  1001. * support_inplace
  1002. # Slice
  1003. ```
  1004. split x along axis into slices, each part slice size is based on slices array
  1005. ```
  1006. | param id | name | type | default | description |
  1007. | --------- | ------------- | ----- | --------- | ----------------- |
  1008. | 0 | slices | array | [ ] | |
  1009. | 1 | axis | int | 0 | |
  1010. # Softmax
  1011. ```
  1012. softmax(x, axis)
  1013. ```
  1014. * one_blob_only
  1015. * support_inplace
  1016. | param id | name | type | default | description |
  1017. | --------- | ------------- | ----- | --------- | ----------------- |
  1018. | 0 | axis | int | 0 | |
  1019. | 1 | fixbug0 | int | 0 | hack for bug fix, should be 1 |
  1020. # Softplus
  1021. ```
  1022. y = log(exp(x) + 1)
  1023. ```
  1024. * one_blob_only
  1025. * support_inplace
  1026. # Split
  1027. ```
  1028. y0, y1 ... = x
  1029. ```
  1030. # Swish
  1031. ```
  1032. y = x / (1 + exp(-x))
  1033. ```
  1034. * one_blob_only
  1035. * support_inplace
  1036. # TanH
  1037. ```
  1038. y = tanh(x)
  1039. ```
  1040. * one_blob_only
  1041. * support_inplace
  1042. # Threshold
  1043. ```
  1044. if x > threshold y = 1
  1045. else y = 0
  1046. ```
  1047. * one_blob_only
  1048. * support_inplace
  1049. | param id | name | type | default | description |
  1050. | --------- | ------------- | ----- | --------- | ----------------- |
  1051. | 0 | threshold | float | 0.f | |
  1052. # UnaryOp
  1053. ```
  1054. y = unaryop(x)
  1055. ```
  1056. - one_blob_only
  1057. - support_inplace
  1058. | param id | name | type | default | description |
  1059. | --------- | ------------- | ----- | --------- | ----------------- |
  1060. | 0 | op_type | int | 0 | Operation type as follows |
  1061. Operation type:
  1062. - 0 = ABS
  1063. - 1 = NEG
  1064. - 2 = FLOOR
  1065. - 3 = CEIL
  1066. - 4 = SQUARE
  1067. - 5 = SQRT
  1068. - 6 = RSQ
  1069. - 7 = EXP
  1070. - 8 = LOG
  1071. - 9 = SIN
  1072. - 10 = COS
  1073. - 11 = TAN
  1074. - 12 = ASIN
  1075. - 13 = ACOS
  1076. - 14 = ATAN
  1077. - 15 = RECIPROCAL
  1078. - 16 = TANH