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

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762
  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. * [Convolution3D](#convolution3d)
  13. * [ConvolutionDepthWise](#convolutiondepthwise)
  14. * [ConvolutionDepthWise1D](#convolutiondepthwise1d)
  15. * [ConvolutionDepthWise3D](#convolutiondepthwise3d)
  16. * [Crop](#crop)
  17. * [CumulativeSum](#cumulativesum)
  18. * [Deconvolution](#deconvolution)
  19. * [Deconvolution1D](#deconvolution1d)
  20. * [Deconvolution3D](#deconvolution3d)
  21. * [DeconvolutionDepthWise](#deconvolutiondepthwise)
  22. * [DeconvolutionDepthWise1D](#deconvolutiondepthwise1d)
  23. * [DeconvolutionDepthWise3D](#deconvolutiondepthwise3d)
  24. * [DeformableConv2D](#deformableconv2d)
  25. * [Dequantize](#dequantize)
  26. * [Dropout](#dropout)
  27. * [Eltwise](#eltwise)
  28. * [ELU](#elu)
  29. * [Exp](#exp)
  30. * [Flatten](#flatten)
  31. * [GELU](#gelu)
  32. * [GLU](#glu)
  33. * [Gemm](#gemm)
  34. * [GridSample](#gridsample)
  35. * [GroupNorm](#groupnorm)
  36. * [GRU](#gru)
  37. * [HardSigmoid](#hardsigmoid)
  38. * [HardSwish](#hardswish)
  39. * [InnerProduct](#innerproduct)
  40. * [Input](#input)
  41. * [InstanceNorm](#instancenorm)
  42. * [Interp](#interp)
  43. * [LayerNorm](#layernorm)
  44. * [Log](#log)
  45. * [LRN](#lrn)
  46. * [LSTM](#lstm)
  47. * [MemoryData](#memorydata)
  48. * [Mish](#mish)
  49. * [MultiHeadAttention](#multiheadattention)
  50. * [MVN](#mvn)
  51. * [Noop](#noop)
  52. * [Normalize](#normalize)
  53. * [Packing](#packing)
  54. * [Padding](#padding)
  55. * [Permute](#permute)
  56. * [PixelShuffle](#pixelshuffle)
  57. * [Pooling](#pooling)
  58. * [Pooling1D](#pooling1d)
  59. * [Pooling3D](#pooling3d)
  60. * [Power](#power)
  61. * [PReLU](#prelu)
  62. * [Quantize](#quantize)
  63. * [Reduction](#reduction)
  64. * [ReLU](#relu)
  65. * [Reorg](#reorg)
  66. * [Requantize](#requantize)
  67. * [Reshape](#reshape)
  68. * [RNN](#rnn)
  69. * [Scale](#scale)
  70. * [SELU](#selu)
  71. * [ShuffleChannel](#shufflechannel)
  72. * [Sigmoid](#sigmoid)
  73. * [Slice](#slice)
  74. * [Softmax](#softmax)
  75. * [Softplus](#softplus)
  76. * [Split](#split)
  77. * [Swish](#swish)
  78. * [TanH](#tanh)
  79. * [Threshold](#threshold)
  80. * [Tile](#tile)
  81. * [UnaryOp](#unaryop)
  82. # AbsVal
  83. ```
  84. y = abs(x)
  85. ```
  86. * one_blob_only
  87. * support_inplace
  88. # ArgMax
  89. ```
  90. y = argmax(x, out_max_val, topk)
  91. ```
  92. * one_blob_only
  93. | param id | name | type | default | description |
  94. | --------- | ------------- | ----- | --------- | ----------------- |
  95. | 0 | out_max_val | int | 0 | |
  96. | 1 | topk | int | 1 | |
  97. # BatchNorm
  98. ```
  99. y = (x - mean) / sqrt(var + eps) * slope + bias
  100. ```
  101. * one_blob_only
  102. * support_inplace
  103. | param id | name | type | default | description |
  104. | --------- | ------------- | ----- | --------- | ----------------- |
  105. | 0 | channels | int | 0 | |
  106. | 1 | eps | float | 0.f | |
  107. | weight | type | shape |
  108. | ------------- | ----- | --------------------- |
  109. | slope_data | float | [channels] |
  110. | mean_data | float | [channels] |
  111. | var_data | float | [channels] |
  112. | bias_data | float | [channels] |
  113. # Bias
  114. ```
  115. y = x + bias
  116. ```
  117. * one_blob_only
  118. * support_inplace
  119. | param id | name | type | default | description |
  120. | --------- | ------------- | ----- | --------- | ----------------- |
  121. | 0 | bias_data_size| int | 0 | |
  122. | weight | type | shape |
  123. | ------------- | ----- | --------------------- |
  124. | bias_data | float | [channels] |
  125. # BinaryOp
  126. This operation is used for binary computation, and the calculation rule depends on the [broadcasting rule](https://github.com/Tencent/ncnn/wiki/binaryop-broadcasting).
  127. ```
  128. C = binaryop(A, B)
  129. ```
  130. if with_scalar = 1:
  131. - one_blob_only
  132. - support_inplace
  133. | param id | name | type | default | description |
  134. | --------- | ------------- | ----- | --------- | ----------------- |
  135. | 0 | op_type | int | 0 | Operation type as follows |
  136. | 1 | with_scalar | int | 0 | with_scalar=0 B is a matrix, with_scalar=1 B is a scalar |
  137. | 2 | b | float | 0.f | When B is a scalar, B = b |
  138. Operation type:
  139. - 0 = ADD
  140. - 1 = SUB
  141. - 2 = MUL
  142. - 3 = DIV
  143. - 4 = MAX
  144. - 5 = MIN
  145. - 6 = POW
  146. - 7 = RSUB
  147. - 8 = RDIV
  148. - 9 = RPOW
  149. - 10 = ATAN2
  150. - 11 = RATAN2
  151. # BNLL
  152. ```
  153. y = log(1 + e^(-x)) , x > 0
  154. y = log(1 + e^x), x < 0
  155. ```
  156. * one_blob_only
  157. * support_inplace
  158. # Cast
  159. ```
  160. y = cast(x)
  161. ```
  162. * one_blob_only
  163. * support_packing
  164. | param id | name | type | default | description |
  165. | --------- | ------------- | ----- | --------- | ----------------- |
  166. | 0 | type_from | int | 0 | |
  167. | 1 | type_to | int | 0 | |
  168. Element type:
  169. - 0 = auto
  170. - 1 = float32
  171. - 2 = float16
  172. - 3 = int8
  173. - 4 = bfloat16
  174. # Clip
  175. ```
  176. y = clamp(x, min, max)
  177. ```
  178. * one_blob_only
  179. * support_inplace
  180. | param id | name | type | default | description |
  181. | --------- | ------------- | ----- | --------- | ----------------- |
  182. | 0 | min | float | -FLT_MAX | |
  183. | 1 | max | float | FLT_MAX | |
  184. # Concat
  185. ```
  186. y = concat(x0, x1, x2, ...) by axis
  187. ```
  188. | param id | name | type | default | description |
  189. | --------- | ------------- | ----- | --------- | ----------------- |
  190. | 0 | axis | int | 0 | |
  191. # Convolution
  192. ```
  193. x2 = pad(x, pads, pad_value)
  194. x3 = conv(x2, weight, kernel, stride, dilation) + bias
  195. y = activation(x3, act_type, act_params)
  196. ```
  197. * one_blob_only
  198. | param id | name | type | default | description |
  199. | --------- | ------------- | ----- | --------- | ----------------- |
  200. | 0 | num_output | int | 0 | |
  201. | 1 | kernel_w | int | 0 | |
  202. | 2 | dilation_w | int | 1 | |
  203. | 3 | stride_w | int | 1 | |
  204. | 4 | pad_left | int | 0 | |
  205. | 5 | bias_term | int | 0 | |
  206. | 6 | weight_data_size| int | 0 | |
  207. | 8 | int8_scale_term| int | 0 | |
  208. | 9 | activation_type| int | 0 | |
  209. | 10 | activation_params| array | [ ] | |
  210. | 11 | kernel_h | int | kernel_w | |
  211. | 12 | dilation_h | int | dilation_w | |
  212. | 13 | stride_h | int | stride_w | |
  213. | 14 | pad_top | int | pad_left | |
  214. | 15 | pad_right | int | pad_left | |
  215. | 16 | pad_bottom | int | pad_top | |
  216. | 18 | pad_value | float | 0.f | |
  217. | 19 | dynamic_weight| int | 0 | |
  218. | weight | type | shape |
  219. | ------------- | ----- | --------------------- |
  220. | weight_data | float/fp16/int8 | [kernel_w, kernel_h, num_input, num_output] |
  221. | bias_data | float | [num_output] |
  222. | weight_data_int8_scales| float | [num_output] |
  223. | bottom_blob_int8_scales| float | [1] |
  224. | top_blob_int8_scales| float | [1] |
  225. # Convolution1D
  226. ```
  227. x2 = pad(x, pads, pad_value)
  228. x3 = conv1d(x2, weight, kernel, stride, dilation) + bias
  229. y = activation(x3, act_type, act_params)
  230. ```
  231. * one_blob_only
  232. | param id | name | type | default | description |
  233. | --------- | ------------- | ----- | --------- | ----------------- |
  234. | 0 | num_output | int | 0 | |
  235. | 1 | kernel_w | int | 0 | |
  236. | 2 | dilation_w | int | 1 | |
  237. | 3 | stride_w | int | 1 | |
  238. | 4 | pad_left | int | 0 | |
  239. | 5 | bias_term | int | 0 | |
  240. | 6 | weight_data_size| int | 0 | |
  241. | 9 | activation_type| int | 0 | |
  242. | 10 | activation_params| array | [ ] | |
  243. | 15 | pad_right | int | pad_left | |
  244. | 18 | pad_value | float | 0.f | |
  245. | 19 | dynamic_weight| int | 0 | |
  246. | weight | type | shape |
  247. | ------------- | ----- | --------------------- |
  248. | weight_data | float/fp16/int8 | [kernel_w, num_input, num_output] |
  249. | bias_data | float | [num_output] |
  250. # Convolution3D
  251. ```
  252. x2 = pad(x, pads, pad_value)
  253. x3 = conv3d(x2, weight, kernel, stride, dilation) + bias
  254. y = activation(x3, act_type, act_params)
  255. ```
  256. * one_blob_only
  257. | param id | name | type | default | description |
  258. | --------- | ------------- | ----- | --------- | ----------------- |
  259. | 0 | num_output | int | 0 | |
  260. | 1 | kernel_w | int | 0 | |
  261. | 2 | dilation_w | int | 1 | |
  262. | 3 | stride_w | int | 1 | |
  263. | 4 | pad_left | int | 0 | |
  264. | 5 | bias_term | int | 0 | |
  265. | 6 | weight_data_size| int | 0 | |
  266. | 9 | activation_type| int | 0 | |
  267. | 10 | activation_params| array | [ ] | |
  268. | 11 | kernel_h | int | kernel_w | |
  269. | 12 | dilation_h | int | dilation_w | |
  270. | 13 | stride_h | int | stride_w | |
  271. | 14 | pad_top | int | pad_left | |
  272. | 15 | pad_right | int | pad_left | |
  273. | 16 | pad_bottom | int | pad_top | |
  274. | 17 | pad_behind | int | pad_front | |
  275. | 18 | pad_value | float | 0.f | |
  276. | 21 | kernel_d | int | kernel_w | |
  277. | 22 | dilation_d | int | dilation_w | |
  278. | 23 | stride_d | int | stride_w | |
  279. | 24 | pad_front | int | pad_left | |
  280. | weight | type | shape |
  281. | ------------- | ----- | --------------------- |
  282. | weight_data | float/fp16/int8 | [kernel_w, kernel_h, kernel_d, num_input, num_output] |
  283. | bias_data | float | [num_output] |
  284. # ConvolutionDepthWise
  285. ```
  286. x2 = pad(x, pads, pad_value)
  287. x3 = conv(x2, weight, kernel, stride, dilation, group) + bias
  288. y = activation(x3, act_type, act_params)
  289. ```
  290. * one_blob_only
  291. | param id | name | type | default | description |
  292. | --------- | ------------- | ----- | --------- | ----------------- |
  293. | 0 | num_output | int | 0 | |
  294. | 1 | kernel_w | int | 0 | |
  295. | 2 | dilation_w | int | 1 | |
  296. | 3 | stride_w | int | 1 | |
  297. | 4 | pad_left | int | 0 | |
  298. | 5 | bias_term | int | 0 | |
  299. | 6 | weight_data_size| int | 0 | |
  300. | 7 | group | int | 1 | |
  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. | 14 | pad_top | int | pad_left | |
  308. | 15 | pad_right | int | pad_left | |
  309. | 16 | pad_bottom | int | pad_top | |
  310. | 18 | pad_value | float | 0.f | |
  311. | 19 | dynamic_weight| int | 0 | |
  312. | weight | type | shape |
  313. | ------------- | ----- | --------------------- |
  314. | weight_data | float/fp16/int8 | [kernel_w, kernel_h, num_input / group, num_output / group, group] |
  315. | bias_data | float | [num_output] |
  316. | weight_data_int8_scales| float | [group] |
  317. | bottom_blob_int8_scales| float | [1] |
  318. | top_blob_int8_scales| float | [1] |
  319. # ConvolutionDepthWise1D
  320. ```
  321. x2 = pad(x, pads, pad_value)
  322. x3 = conv1d(x2, weight, kernel, stride, dilation, group) + bias
  323. y = activation(x3, act_type, act_params)
  324. ```
  325. * one_blob_only
  326. | param id | name | type | default | description |
  327. | --------- | ------------- | ----- | --------- | ----------------- |
  328. | 0 | num_output | int | 0 | |
  329. | 1 | kernel_w | int | 0 | |
  330. | 2 | dilation_w | int | 1 | |
  331. | 3 | stride_w | int | 1 | |
  332. | 4 | pad_left | int | 0 | |
  333. | 5 | bias_term | int | 0 | |
  334. | 6 | weight_data_size| int | 0 | |
  335. | 7 | group | int | 1 | |
  336. | 9 | activation_type| int | 0 | |
  337. | 10 | activation_params| array | [ ] | |
  338. | 15 | pad_right | int | pad_left | |
  339. | 18 | pad_value | float | 0.f | |
  340. | 19 | dynamic_weight| int | 0 | |
  341. | weight | type | shape |
  342. | ------------- | ----- | --------------------- |
  343. | weight_data | float/fp16/int8 | [kernel_w, num_input / group, num_output / group, group] |
  344. | bias_data | float | [num_output] |
  345. # ConvolutionDepthWise3D
  346. ```
  347. x2 = pad(x, pads, pad_value)
  348. x3 = conv3d(x2, weight, kernel, stride, dilation, group) + bias
  349. y = activation(x3, act_type, act_params)
  350. ```
  351. * one_blob_only
  352. | param id | name | type | default | description |
  353. | --------- | ------------- | ----- | --------- | ----------------- |
  354. | 0 | num_output | int | 0 | |
  355. | 1 | kernel_w | int | 0 | |
  356. | 2 | dilation_w | int | 1 | |
  357. | 3 | stride_w | int | 1 | |
  358. | 4 | pad_left | int | 0 | |
  359. | 5 | bias_term | int | 0 | |
  360. | 6 | weight_data_size| int | 0 | |
  361. | 7 | group | int | 1 | |
  362. | 9 | activation_type| int | 0 | |
  363. | 10 | activation_params| array | [ ] | |
  364. | 11 | kernel_h | int | kernel_w | |
  365. | 12 | dilation_h | int | dilation_w | |
  366. | 13 | stride_h | int | stride_w | |
  367. | 14 | pad_top | int | pad_left | |
  368. | 15 | pad_right | int | pad_left | |
  369. | 16 | pad_bottom | int | pad_top | |
  370. | 17 | pad_behind | int | pad_front | |
  371. | 18 | pad_value | float | 0.f | |
  372. | 21 | kernel_d | int | kernel_w | |
  373. | 22 | dilation_d | int | dilation_w | |
  374. | 23 | stride_d | int | stride_w | |
  375. | 24 | pad_front | int | pad_left | |
  376. | weight | type | shape |
  377. | ------------- | ----- | --------------------- |
  378. | weight_data | float/fp16/int8 | [kernel_w, kernel_h, kernel_d, num_input / group, num_output / group, group] |
  379. | bias_data | float | [num_output] |
  380. # Crop
  381. ```
  382. y = crop(x)
  383. ```
  384. * one_blob_only
  385. | param id | name | type | default | description |
  386. | --------- | ------------- | ----- | --------- | ----------------- |
  387. | 0 | woffset | int | 0 | |
  388. | 1 | hoffset | int | 0 | |
  389. | 2 | coffset | int | 1 | |
  390. | 3 | outw | int | 1 | |
  391. | 4 | outh | int | 0 | |
  392. | 5 | outc | int | 0 | |
  393. | 6 | woffset2 | int | 0 | |
  394. | 7 | hoffset2 | int | 1 | |
  395. | 8 | coffset2 | int | 0 | |
  396. | 9 | starts | array | [ ] | |
  397. | 10 | ends | array | [ ] | |
  398. | 11 | axes | array | [ ] | |
  399. # CumulativeSum
  400. If axis < 0, we use axis = x.dims + axis
  401. It implements https://pytorch.org/docs/stable/generated/torch.cumsum.html
  402. * one_blob_only
  403. * support_inplace
  404. | param id | name | type | default | description |
  405. | --------- | ------------- | ----- | --------- | ----------------- |
  406. | 0 | axis | int | 0 | |
  407. # Deconvolution
  408. ```
  409. x2 = deconv(x, weight, kernel, stride, dilation) + bias
  410. x3 = depad(x2, pads, pad_value)
  411. y = activation(x3, act_type, act_params)
  412. ```
  413. * one_blob_only
  414. | param id | name | type | default | description |
  415. | --------- | ------------- | ----- | --------- | ----------------- |
  416. | 0 | num_output | int | 0 | |
  417. | 1 | kernel_w | int | 0 | |
  418. | 2 | dilation_w | int | 1 | |
  419. | 3 | stride_w | int | 1 | |
  420. | 4 | pad_left | int | 0 | |
  421. | 5 | bias_term | int | 0 | |
  422. | 6 | weight_data_size| int | 0 | |
  423. | 9 | activation_type| int | 0 | |
  424. | 10 | activation_params| array | [ ] | |
  425. | 11 | kernel_h | int | kernel_w | |
  426. | 12 | dilation_h | int | dilation_w | |
  427. | 13 | stride_h | int | stride_w | |
  428. | 14 | pad_top | int | pad_left | |
  429. | 15 | pad_right | int | pad_left | |
  430. | 16 | pad_bottom | int | pad_top | |
  431. | 18 | output_pad_right| int | 0 | |
  432. | 19 | output_pad_bottom| int | output_pad_right | |
  433. | 20 | output_w | int | 0 | |
  434. | 21 | output_h | int | output_w | |
  435. | weight | type | shape |
  436. | ------------- | ----- | --------------------- |
  437. | weight_data | float/fp16 | [kernel_w, kernel_h, num_input, num_output] |
  438. | bias_data | float | [num_output] |
  439. # Deconvolution1D
  440. ```
  441. x2 = deconv1d(x, weight, kernel, stride, dilation) + bias
  442. x3 = depad(x2, pads, pad_value)
  443. y = activation(x3, act_type, act_params)
  444. ```
  445. * one_blob_only
  446. | param id | name | type | default | description |
  447. | --------- | ------------- | ----- | --------- | ----------------- |
  448. | 0 | num_output | int | 0 | |
  449. | 1 | kernel_w | int | 0 | |
  450. | 2 | dilation_w | int | 1 | |
  451. | 3 | stride_w | int | 1 | |
  452. | 4 | pad_left | int | 0 | |
  453. | 5 | bias_term | int | 0 | |
  454. | 6 | weight_data_size| int | 0 | |
  455. | 9 | activation_type| int | 0 | |
  456. | 10 | activation_params| array | [ ] | |
  457. | 15 | pad_right | int | pad_left | |
  458. | 18 | output_pad_right| int | 0 | |
  459. | 20 | output_w | int | 0 | |
  460. | weight | type | shape |
  461. | ------------- | ----- | --------------------- |
  462. | weight_data | float/fp16 | [kernel_w, num_input, num_output] |
  463. | bias_data | float | [num_output] |
  464. # Deconvolution3D
  465. ```
  466. x2 = deconv3d(x, weight, kernel, stride, dilation) + bias
  467. x3 = depad(x2, pads, pad_value)
  468. y = activation(x3, act_type, act_params)
  469. ```
  470. * one_blob_only
  471. | param id | name | type | default | description |
  472. | --------- | ------------- | ----- | --------- | ----------------- |
  473. | 0 | num_output | int | 0 | |
  474. | 1 | kernel_w | int | 0 | |
  475. | 2 | dilation_w | int | 1 | |
  476. | 3 | stride_w | int | 1 | |
  477. | 4 | pad_left | int | 0 | |
  478. | 5 | bias_term | int | 0 | |
  479. | 6 | weight_data_size| int | 0 | |
  480. | 9 | activation_type| int | 0 | |
  481. | 10 | activation_params| array | [ ] | |
  482. | 11 | kernel_h | int | kernel_w | |
  483. | 12 | dilation_h | int | dilation_w | |
  484. | 13 | stride_h | int | stride_w | |
  485. | 14 | pad_top | int | pad_left | |
  486. | 15 | pad_right | int | pad_left | |
  487. | 16 | pad_bottom | int | pad_top | |
  488. | 17 | pad_behind | int | pad_front | |
  489. | 18 | output_pad_right| int | 0 | |
  490. | 19 | output_pad_bottom| int | output_pad_right | |
  491. | 20 | output_pad_behind| int | output_pad_right | |
  492. | 21 | kernel_d | int | kernel_w | |
  493. | 22 | dilation_d | int | dilation_w | |
  494. | 23 | stride_d | int | stride_w | |
  495. | 24 | pad_front | int | pad_left | |
  496. | 25 | output_w | int | 0 | |
  497. | 26 | output_h | int | output_w | |
  498. | 27 | output_d | int | output_w | |
  499. | weight | type | shape |
  500. | ------------- | ----- | --------------------- |
  501. | weight_data | float/fp16 | [kernel_w, kernel_h, kernel_d, num_input, num_output] |
  502. | bias_data | float | [num_output] |
  503. # DeconvolutionDepthWise
  504. ```
  505. x2 = deconv(x, weight, kernel, stride, dilation, group) + bias
  506. x3 = depad(x2, pads, pad_value)
  507. y = activation(x3, act_type, act_params)
  508. ```
  509. * one_blob_only
  510. | param id | name | type | default | description |
  511. | --------- | ------------- | ----- | --------- | ----------------- |
  512. | 0 | num_output | int | 0 | |
  513. | 1 | kernel_w | int | 0 | |
  514. | 2 | dilation_w | int | 1 | |
  515. | 3 | stride_w | int | 1 | |
  516. | 4 | pad_left | int | 0 | |
  517. | 5 | bias_term | int | 0 | |
  518. | 6 | weight_data_size| int | 0 | |
  519. | 7 | group | int | 1 | |
  520. | 9 | activation_type| int | 0 | |
  521. | 10 | activation_params| array | [ ] | |
  522. | 11 | kernel_h | int | kernel_w | |
  523. | 12 | dilation_h | int | dilation_w | |
  524. | 13 | stride_h | int | stride_w | |
  525. | 14 | pad_top | int | pad_left | |
  526. | 15 | pad_right | int | pad_left | |
  527. | 16 | pad_bottom | int | pad_top | |
  528. | 18 | output_pad_right| int | 0 | |
  529. | 19 | output_pad_bottom| int | output_pad_right | |
  530. | 20 | output_w | int | 0 | |
  531. | 21 | output_h | int | output_w | |
  532. | weight | type | shape |
  533. | ------------- | ----- | --------------------- |
  534. | weight_data | float/fp16 | [kernel_w, kernel_h, num_input / group, num_output / group, group] |
  535. | bias_data | float | [num_output] |
  536. # DeconvolutionDepthWise1D
  537. ```
  538. x2 = deconv1d(x, weight, kernel, stride, dilation, group) + bias
  539. x3 = depad(x2, pads, pad_value)
  540. y = activation(x3, act_type, act_params)
  541. ```
  542. * one_blob_only
  543. | param id | name | type | default | description |
  544. | --------- | ------------- | ----- | --------- | ----------------- |
  545. | 0 | num_output | int | 0 | |
  546. | 1 | kernel_w | int | 0 | |
  547. | 2 | dilation_w | int | 1 | |
  548. | 3 | stride_w | int | 1 | |
  549. | 4 | pad_left | int | 0 | |
  550. | 5 | bias_term | int | 0 | |
  551. | 6 | weight_data_size| int | 0 | |
  552. | 7 | group | int | 1 | |
  553. | 9 | activation_type| int | 0 | |
  554. | 10 | activation_params| array | [ ] | |
  555. | 15 | pad_right | int | pad_left | |
  556. | 18 | output_pad_right| int | 0 | |
  557. | 20 | output_w | int | 0 | |
  558. | weight | type | shape |
  559. | ------------- | ----- | --------------------- |
  560. | weight_data | float/fp16 | [kernel_w, num_input / group, num_output / group, group] |
  561. | bias_data | float | [num_output] |
  562. # DeconvolutionDepthWise3D
  563. ```
  564. x2 = deconv3d(x, weight, kernel, stride, dilation, group) + bias
  565. x3 = depad(x2, pads, pad_value)
  566. y = activation(x3, act_type, act_params)
  567. ```
  568. * one_blob_only
  569. | param id | name | type | default | description |
  570. | --------- | ------------- | ----- | --------- | ----------------- |
  571. | 0 | num_output | int | 0 | |
  572. | 1 | kernel_w | int | 0 | |
  573. | 2 | dilation_w | int | 1 | |
  574. | 3 | stride_w | int | 1 | |
  575. | 4 | pad_left | int | 0 | |
  576. | 5 | bias_term | int | 0 | |
  577. | 6 | weight_data_size| int | 0 | |
  578. | 7 | group | int | 1 | |
  579. | 9 | activation_type| int | 0 | |
  580. | 10 | activation_params| array | [ ] | |
  581. | 11 | kernel_h | int | kernel_w | |
  582. | 12 | dilation_h | int | dilation_w | |
  583. | 13 | stride_h | int | stride_w | |
  584. | 14 | pad_top | int | pad_left | |
  585. | 15 | pad_right | int | pad_left | |
  586. | 16 | pad_bottom | int | pad_top | |
  587. | 17 | pad_behind | int | pad_front | |
  588. | 18 | output_pad_right| int | 0 | |
  589. | 19 | output_pad_bottom| int | output_pad_right | |
  590. | 20 | output_pad_behind| int | output_pad_right | |
  591. | 21 | kernel_d | int | kernel_w | |
  592. | 22 | dilation_d | int | dilation_w | |
  593. | 23 | stride_d | int | stride_w | |
  594. | 24 | pad_front | int | pad_left | |
  595. | 25 | output_w | int | 0 | |
  596. | 26 | output_h | int | output_w | |
  597. | 27 | output_d | int | output_w | |
  598. | weight | type | shape |
  599. | ------------- | ----- | --------------------- |
  600. | weight_data | float/fp16 | [kernel_w, kernel_h, kernel_d, num_input / group, num_output / group, group] |
  601. | bias_data | float | [num_output] |
  602. # DeformableConv2D
  603. ```
  604. x2 = deformableconv2d(x, offset, mask, weight, kernel, stride, dilation) + bias
  605. y = activation(x2, act_type, act_params)
  606. ```
  607. | param id | name | type | default | description |
  608. | --------- | ------------- | ----- | --------- | ----------------- |
  609. | 0 | num_output | int | 0 | |
  610. | 1 | kernel_w | int | 0 | |
  611. | 2 | dilation_w | int | 1 | |
  612. | 3 | stride_w | int | 1 | |
  613. | 4 | pad_left | int | 0 | |
  614. | 5 | bias_term | int | 0 | |
  615. | 6 | weight_data_size| int | 0 | |
  616. | 9 | activation_type| int | 0 | |
  617. | 10 | activation_params| array | [ ] | |
  618. | 11 | kernel_h | int | kernel_w | |
  619. | 12 | dilation_h | int | dilation_w | |
  620. | 13 | stride_h | int | stride_w | |
  621. | 14 | pad_top | int | pad_left | |
  622. | 15 | pad_right | int | pad_left | |
  623. | 16 | pad_bottom | int | pad_top | |
  624. | weight | type | shape |
  625. | ------------- | ----- | --------------------- |
  626. | weight_data | float/fp16/int8 | [kernel_w, kernel_h, num_input, num_output] |
  627. | bias_data | float | [num_output] |
  628. # Dequantize
  629. ```
  630. y = x * scale + bias
  631. ```
  632. * one_blob_only
  633. * support_inplace
  634. | param id | name | type | default | description |
  635. | --------- | ------------- | ----- | --------- | ----------------- |
  636. | 0 | scale_data_size| int | 1 | |
  637. | 1 | bias_data_size| int | 0 | |
  638. | weight | type | shape |
  639. | ------------- | ----- | --------------------- |
  640. | scale_data | float | [scale_data_size] |
  641. | bias_data | float | [bias_data_size] |
  642. # Dropout
  643. ```
  644. y = x * scale
  645. ```
  646. * one_blob_only
  647. | param id | name | type | default | description |
  648. | --------- | ------------- | ----- | --------- | ----------------- |
  649. | 0 | scale | float | 1.f | |
  650. # Eltwise
  651. ```
  652. y = elementwise_op(x0, x1, ...)
  653. ```
  654. | param id | name | type | default | description |
  655. | --------- | ------------- | ----- | --------- | ----------------- |
  656. | 0 | op_type | int | 0 | |
  657. | 1 | coeffs | array | [ ] | |
  658. Operation type:
  659. - 0 = PROD
  660. - 1 = SUM
  661. - 2 = MAX
  662. # ELU
  663. ```
  664. if x < 0 y = (exp(x) - 1) * alpha
  665. else y = x
  666. ```
  667. * one_blob_only
  668. * support_inplace
  669. | param id | name | type | default | description |
  670. | --------- | ------------- | ----- | --------- | ----------------- |
  671. | 0 | alpha | float | 0.1f | |
  672. # Exp
  673. ```
  674. if base == -1 y = exp(shift + x * scale)
  675. else y = pow(base, (shift + x * scale))
  676. ```
  677. * one_blob_only
  678. * support_inplace
  679. | param id | name | type | default | description |
  680. | --------- | ------------- | ----- | --------- | ----------------- |
  681. | 0 | base | float | -1.f | |
  682. | 1 | scale | float | 1.f | |
  683. | 2 | shift | float | 0.f | |
  684. # Flatten
  685. Reshape blob to 1 dimension
  686. * one_blob_only
  687. # GELU
  688. ```
  689. if fast_gelu == 1 y = 0.5 * x * (1 + tanh(0.79788452 * (x + 0.044715 * x * x * x)));
  690. else y = 0.5 * x * erfc(-0.70710678 * x)
  691. ```
  692. * one_blob_only
  693. * support_inplace
  694. | param id | name | type | default | description |
  695. | --------- | ------------- | ----- | --------- | ----------------- |
  696. | 0 | fast_gelu | int | 0 | use approximation |
  697. # GLU
  698. If axis < 0, we use axis = x.dims + axis
  699. GLU(a,b)=a⊗σ(b)
  700. where a is the first half of the input matrix and b is the second half.
  701. axis specifies the dimension to split the input
  702. * one_blob_only
  703. | param id | name | type | default | description |
  704. | --------- | ------------- | ----- | --------- | ----------------- |
  705. | 0 | axis | int | 0 | |
  706. # Gemm
  707. ```
  708. a = transA ? transpose(x0) : x0
  709. b = transb ? transpose(x1) : x1
  710. c = x2
  711. y = (gemm(a, b) + c * beta) * alpha
  712. ```
  713. | param id | name | type | default | description |
  714. | --------- | ------------- | ----- | --------- | ----------------- |
  715. | 0 | alpha | float | 1.f | |
  716. | 1 | beta | float | 1.f | |
  717. | 2 | transA | int | 0 | |
  718. | 3 | transb | int | 0 | |
  719. | 4 | constantA | int | 0 | |
  720. | 5 | constantB | int | 0 | |
  721. | 6 | constantC | int | 0 | |
  722. | 7 | constantM | int | 0 | |
  723. | 8 | constantN | int | 0 | |
  724. | 9 | constantK | int | 0 | |
  725. | 10 | constant_broadcast_type_C | int | 0 | |
  726. | 11 | output_N1M | int | 0 | |
  727. | 12 | output_elempack | int | 0 | |
  728. | 13 | output_elemtype | int | 0 | |
  729. | 14 | output_transpose | int| 0 | |
  730. | 20 | constant_TILE_M | int | 0 | |
  731. | 21 | constant_TILE_N | int | 0 | |
  732. | 22 | constant_TILE_K | int | 0 | |
  733. | weight | type | shape |
  734. | ------------- | ----- | --------------------- |
  735. | A_data | float | [M, K] or [K, M] |
  736. | B_data | float | [N, K] or [K, N] |
  737. | C_data | float | [1], [M] or [N] or [1, M] or [N,1] or [N, M] |
  738. # GridSample
  739. ```
  740. Given an input and a flow-field grid, computes the output using input values and pixel locations from grid.
  741. For each output location output[:, h2, w2], the size-2 vector grid[h2, w2, 2] specifies input pixel[:, h1, w1] locations x and y,
  742. which are used to interpolate the output value output[:, h2, w2]
  743. This function is often used in conjunction with affine_grid() to build Spatial Transformer Networks .
  744. ```
  745. | param id | name | type | default | description |
  746. | --------- | ------------- | ----- | --------- | ----------------- |
  747. | 0 | sample_type | int | 1 | |
  748. | 1 | padding_mode | int | 1 | |
  749. | 2 | align_corner | int | 0 | |
  750. Sample type:
  751. - 1 = Nearest
  752. - 2 = Bilinear
  753. - 3 = Bicubic
  754. Padding mode:
  755. - 1 = zeros
  756. - 2 = border
  757. - 3 = reflection
  758. # GroupNorm
  759. ```
  760. split x along channel axis into group x0, x1 ...
  761. l2 normalize for each group x0, x1 ...
  762. y = x * gamma + beta
  763. ```
  764. * one_blob_only
  765. * support_inplace
  766. | param id | name | type | default | description |
  767. | --------- | ------------- | ----- | --------- | ----------------- |
  768. | 0 | group | int | 1 | |
  769. | 1 | channels | int | 0 | |
  770. | 2 | eps | float | 0.001f | x = x / sqrt(var + eps) |
  771. | 3 | affine | int | 1 | |
  772. | weight | type | shape |
  773. | ------------- | ----- | --------------------- |
  774. | gamma_data | float | [channels] |
  775. | beta_data | float | [channels] |
  776. # GRU
  777. 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]`.
  778. ```
  779. y = gru(x)
  780. y0, hidden y1 = gru(x0, hidden x1)
  781. ```
  782. * one_blob_only if bidirectional
  783. | param id | name | type | default | description |
  784. | --------- | ------------- | ----- | --------- | ----------------- |
  785. | 0 | num_output | int | 0 | hidden size of output |
  786. | 1 | weight_data_size| int | 0 | total size of weight matrix |
  787. | 2 | direction | int | 0 | 0=forward, 1=reverse, 2=bidirectional |
  788. | weight | type | shape |
  789. | ------------- | ----- | --------------------- |
  790. | weight_xc_data| float/fp16/int8 | [input_size, num_output * 3, num_directions] |
  791. | bias_c_data | float/fp16/int8 | [num_output, 4, num_directions] |
  792. | weight_hc_data| float/fp16/int8 | [num_output, num_output * 3, num_directions] |
  793. Direction flag:
  794. - 0 = forward only
  795. - 1 = reverse only
  796. - 2 = bidirectional
  797. # HardSigmoid
  798. ```
  799. y = clamp(x * alpha + beta, 0, 1)
  800. ```
  801. * one_blob_only
  802. * support_inplace
  803. | param id | name | type | default | description |
  804. | --------- | ------------- | ----- | --------- | ----------------- |
  805. | 0 | alpha | float | 0.2f | |
  806. | 1 | beta | float | 0.5f | |
  807. # HardSwish
  808. ```
  809. y = x * clamp(x * alpha + beta, 0, 1)
  810. ```
  811. * one_blob_only
  812. * support_inplace
  813. | param id | name | type | default | description |
  814. | --------- | ------------- | ----- | --------- | ----------------- |
  815. | 0 | alpha | float | 0.2f | |
  816. | 1 | beta | float | 0.5f | |
  817. # InnerProduct
  818. ```
  819. x2 = innerproduct(x, weight) + bias
  820. y = activation(x2, act_type, act_params)
  821. ```
  822. * one_blob_only
  823. | param id | name | type | default | description |
  824. | --------- | ------------- | ----- | --------- | ----------------- |
  825. | 0 | num_output | int | 0 | |
  826. | 1 | bias_term | int | 0 | |
  827. | 2 | weight_data_size| int | 0 | |
  828. | 8 | int8_scale_term| int | 0 | |
  829. | 9 | activation_type| int | 0 | |
  830. | 10 | activation_params| array | [ ] | |
  831. | weight | type | shape |
  832. | ------------- | ----- | --------------------- |
  833. | weight_data | float/fp16/int8 | [num_input, num_output] |
  834. | bias_data | float | [num_output] |
  835. | weight_data_int8_scales| float | [num_output] |
  836. | bottom_blob_int8_scales| float | [1] |
  837. # Input
  838. ```
  839. y = input
  840. ```
  841. * support_inplace
  842. | param id | name | type | default | description |
  843. | --------- | ------------- | ----- | --------- | ----------------- |
  844. | 0 | w | int | 0 | |
  845. | 1 | h | int | 0 | |
  846. | 11 | d | int | 0 | |
  847. | 2 | c | int | 0 | |
  848. # InstanceNorm
  849. ```
  850. split x along channel axis into instance x0, x1 ...
  851. l2 normalize for each channel instance x0, x1 ...
  852. y = x * gamma + beta
  853. ```
  854. * one_blob_only
  855. * support_inplace
  856. | param id | name | type | default | description |
  857. | --------- | ------------- | ----- | --------- | ----------------- |
  858. | 0 | channels | int | 0 | |
  859. | 1 | eps | float | 0.001f | x = x / sqrt(var + eps) |
  860. | 2 | affine | int | 1 | |
  861. | weight | type | shape |
  862. | ------------- | ----- | --------------------- |
  863. | gamma_data | float | [channels] |
  864. | beta_data | float | [channels] |
  865. # Interp
  866. ```
  867. if dynamic_target_size == 0 y = resize(x) by fixed size or scale
  868. else y = resize(x0, size(x1))
  869. ```
  870. * one_blob_only if dynamic_target_size == 0
  871. | param id | name | type | default | description |
  872. | --------- | ------------- | ----- | --------- | ----------------- |
  873. | 0 | resize_type | int | 0 | |
  874. | 1 | height_scale | float | 1.f | |
  875. | 2 | width_scale | float | 1.f | |
  876. | 3 | output_height | int | 0 | |
  877. | 4 | output_width | int | 0 | |
  878. | 5 | dynamic_target_size| int | 0 | |
  879. | 6 | align_corner | int | 0 | |
  880. Resize type:
  881. - 1 = Nearest
  882. - 2 = Bilinear
  883. - 3 = Bicubic
  884. # LayerNorm
  885. ```
  886. split x along outmost axis into part x0, x1 ...
  887. l2 normalize for each part x0, x1 ...
  888. y = x * gamma + beta by elementwise
  889. ```
  890. * one_blob_only
  891. * support_inplace
  892. | param id | name | type | default | description |
  893. | --------- | ------------- | ----- | --------- | ----------------- |
  894. | 0 | affine_size | int | 0 | |
  895. | 1 | eps | float | 0.001f | x = x / sqrt(var + eps) |
  896. | 2 | affine | int | 1 | |
  897. | weight | type | shape |
  898. | ------------- | ----- | --------------------- |
  899. | gamma_data | float | [affine_size] |
  900. | beta_data | float | [affine_size] |
  901. # Log
  902. ```
  903. if base == -1 y = log(shift + x * scale)
  904. else y = log(shift + x * scale) / log(base)
  905. ```
  906. * one_blob_only
  907. * support_inplace
  908. | param id | name | type | default | description |
  909. | --------- | ------------- | ----- | --------- | ----------------- |
  910. | 0 | base | float | -1.f | |
  911. | 1 | scale | float | 1.f | |
  912. | 2 | shift | float | 0.f | |
  913. # LRN
  914. ```
  915. if region_type == ACROSS_CHANNELS square_sum = sum of channel window of local_size
  916. if region_type == WITHIN_CHANNEL square_sum = sum of spatial window of local_size
  917. y = x * pow(bias + alpha * square_sum / (local_size * local_size), -beta)
  918. ```
  919. * one_blob_only
  920. * support_inplace
  921. | param id | name | type | default | description |
  922. | --------- | ------------- | ----- | --------- | ----------------- |
  923. | 0 | region_type | int | 0 | |
  924. | 1 | local_size | int | 5 | |
  925. | 2 | alpha | float | 1.f | |
  926. | 3 | beta | float | 0.75f | |
  927. | 4 | bias | float | 1.f | |
  928. Region type:
  929. - 0 = ACROSS_CHANNELS
  930. - 1 = WITHIN_CHANNEL
  931. # LSTM
  932. 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]`.
  933. ```
  934. y = lstm(x)
  935. y0, hidden y1, cell y2 = lstm(x0, hidden x1, cell x2)
  936. ```
  937. * one_blob_only if bidirectional
  938. | param id | name | type | default | description |
  939. | --------- | ------------- | ----- | --------- | ----------------- |
  940. | 0 | num_output | int | 0 | output size of output |
  941. | 1 | weight_data_size| int | 0 | total size of IFOG weight matrix |
  942. | 2 | direction | int | 0 | 0=forward, 1=reverse, 2=bidirectional |
  943. | 3 | hidden_size | int | num_output| hidden size |
  944. | weight | type | shape |
  945. | ------------- | ----- | --------------------- |
  946. | weight_xc_data| float/fp16/int8 | [input_size, hidden_size * 4, num_directions] |
  947. | bias_c_data | float/fp16/int8 | [hidden_size, 4, num_directions] |
  948. | weight_hc_data| float/fp16/int8 | [num_output, hidden_size * 4, num_directions] |
  949. | weight_hr_data| float/fp16/int8 | [hidden_size, num_output, num_directions] |
  950. Direction flag:
  951. - 0 = forward only
  952. - 1 = reverse only
  953. - 2 = bidirectional
  954. # MemoryData
  955. ```
  956. y = data
  957. ```
  958. | param id | name | type | default | description |
  959. | --------- | ------------- | ----- | --------- | ----------------- |
  960. | 0 | w | int | 0 | |
  961. | 1 | h | int | 0 | |
  962. | 11 | d | int | 0 | |
  963. | 2 | c | int | 0 | |
  964. | weight | type | shape |
  965. | ------------- | ----- | --------------------- |
  966. | data | float | [w, h, d, c] |
  967. # Mish
  968. ```
  969. y = x * tanh(log(exp(x) + 1))
  970. ```
  971. * one_blob_only
  972. * support_inplace
  973. # MultiHeadAttention
  974. ```
  975. split q k v into num_head part q0, k0, v0, q1, k1, v1 ...
  976. for each num_head part
  977. xq = affine(q) / (embed_dim / num_head)
  978. xk = affine(k)
  979. xv = affine(v)
  980. xqk = xq * xk
  981. softmax_inplace(xqk)
  982. xqkv = xqk * xv
  983. merge xqkv to out
  984. y = affine(out)
  985. ```
  986. | param id | name | type | default | description |
  987. | --------- | ------------- | ----- | --------- | ----------------- |
  988. | 0 | embed_dim | int | 0 | |
  989. | 1 | num_head | int | 1 | |
  990. | 2 | weight_data_size| int | 0 | |
  991. | 3 | kdim | int | embed_dim | |
  992. | 4 | vdim | int | embed_dim | |
  993. | weight | type | shape |
  994. | ------------- | ----- | --------------------- |
  995. | q_weight_data | float/fp16/int8 | [weight_data_size] |
  996. | q_bias_data | float | [embed_dim] |
  997. | k_weight_data | float/fp16/int8 | [embed_dim * kdim] |
  998. | k_bias_data | float | [embed_dim] |
  999. | v_weight_data | float/fp16/int8 | [embed_dim * vdim] |
  1000. | v_bias_data | float | [embed_dim] |
  1001. | out_weight_data| float/fp16/int8 | [weight_data_size] |
  1002. | out_bias_data | float | [embed_dim] |
  1003. # MVN
  1004. ```
  1005. if normalize_variance == 1 && across_channels == 1 y = (x - mean) / (sqrt(var) + eps) of whole blob
  1006. if normalize_variance == 1 && across_channels == 0 y = (x - mean) / (sqrt(var) + eps) of each channel
  1007. if normalize_variance == 0 && across_channels == 1 y = x - mean of whole blob
  1008. if normalize_variance == 0 && across_channels == 0 y = x - mean of each channel
  1009. ```
  1010. * one_blob_only
  1011. | param id | name | type | default | description |
  1012. | --------- | ------------- | ----- | --------- | ----------------- |
  1013. | 0 | normalize_variance| int | 0 | |
  1014. | 1 | across_channels| int | 0 | |
  1015. | 2 | eps | float | 0.0001f | x = x / (sqrt(var) + eps) |
  1016. # Noop
  1017. ```
  1018. y = x
  1019. ```
  1020. # Normalize
  1021. ```
  1022. if across_spatial == 1 && across_channel == 1 x2 = normalize(x) of whole blob
  1023. if across_spatial == 1 && across_channel == 0 x2 = normalize(x) of each channel
  1024. if across_spatial == 0 && across_channel == 1 x2 = normalize(x) of each position
  1025. y = x2 * scale
  1026. ```
  1027. * one_blob_only
  1028. * support_inplace
  1029. | param id | name | type | default | description |
  1030. | --------- | ------------- | ----- | --------- | ----------------- |
  1031. | 0 | across_spatial| int | 0 | |
  1032. | 1 | channel_shared| int | 0 | |
  1033. | 2 | eps | float | 0.0001f | see eps mode |
  1034. | 3 | scale_data_size| int | 0 | |
  1035. | 4 | across_channel| int | 0 | |
  1036. | 9 | eps_mode | int | 0 | |
  1037. | weight | type | shape |
  1038. | ------------- | ----- | --------------------- |
  1039. | scale_data | float | [scale_data_size] |
  1040. Eps Mode:
  1041. - 0 = caffe/mxnet x = x / sqrt(var + eps)
  1042. - 1 = pytorch x = x / max(sqrt(var), eps)
  1043. - 2 = tensorflow x = x / sqrt(max(var, eps))
  1044. # Packing
  1045. ```
  1046. y = wrap_packing(x)
  1047. ```
  1048. * one_blob_only
  1049. | param id | name | type | default | description |
  1050. | --------- | ------------- | ----- | --------- | ----------------- |
  1051. | 0 | out_elempack | int | 1 | |
  1052. | 1 | use_padding | int | 0 | |
  1053. | 2 | cast_type_from| int | 0 | |
  1054. | 3 | cast_type_to | int | 0 | |
  1055. | 4 | storage_type_from| int | 0 | |
  1056. | 5 | storage_type_to| int | 0 | |
  1057. # Padding
  1058. ```
  1059. y = pad(x, pads)
  1060. ```
  1061. | param id | name | type | default | description |
  1062. | --------- | ------------- | ---- | --------- | ----------------- |
  1063. | 0 | top | int | 0 | |
  1064. | 1 | bottom | int | 0 | |
  1065. | 2 | left | int | 0 | |
  1066. | 3 | right | int | 0 | |
  1067. | 4 | type | int | 0 | |
  1068. | 5 | value | float | 0 | |
  1069. | 6 | per_channel_pad_data_size| int | 0 | |
  1070. | 7 | front | int | stride_w | |
  1071. | 8 | behind | int | pad_left | |
  1072. | weight | type | shape |
  1073. | ------------- | ----- | --------------------- |
  1074. | per_channel_pad_data| float | [per_channel_pad_data_size] |
  1075. Padding type:
  1076. - 0 = CONSTANT
  1077. - 1 = REPLICATE
  1078. - 2 = REFLECT
  1079. # Permute
  1080. ```
  1081. y = reorder(x)
  1082. ```
  1083. | param id | name | type | default | description |
  1084. | --------- | ------------- | ---- | --------- | ----------------- |
  1085. | 0 | order_type | int | 0 | |
  1086. Order Type:
  1087. - 0 = WH WHC WHDC
  1088. - 1 = HW HWC HWDC
  1089. - 2 = WCH WDHC
  1090. - 3 = CWH DWHC
  1091. - 4 = HCW HDWC
  1092. - 5 = CHW DHWC
  1093. - 6 = WHCD
  1094. - 7 = HWCD
  1095. - 8 = WCHD
  1096. - 9 = CWHD
  1097. - 10 = HCWD
  1098. - 11 = CHWD
  1099. - 12 = WDCH
  1100. - 13 = DWCH
  1101. - 14 = WCDH
  1102. - 15 = CWDH
  1103. - 16 = DCWH
  1104. - 17 = CDWH
  1105. - 18 = HDCW
  1106. - 19 = DHCW
  1107. - 20 = HCDW
  1108. - 21 = CHDW
  1109. - 22 = DCHW
  1110. - 23 = CDHW
  1111. # PixelShuffle
  1112. ```
  1113. if mode == 0 y = depth_to_space(x) where x channel order is sw-sh-outc
  1114. if mode == 1 y = depth_to_space(x) where x channel order is outc-sw-sh
  1115. ```
  1116. * one_blob_only
  1117. | param id | name | type | default | description |
  1118. | --------- | ------------- | ---- | --------- | ----------------- |
  1119. | 0 | upscale_factor| int | 1 | |
  1120. | 1 | mode | int | 0 | |
  1121. # Pooling
  1122. ```
  1123. x2 = pad(x, pads)
  1124. x3 = pooling(x2, kernel, stride)
  1125. ```
  1126. | param id | name | type | default | description |
  1127. | --------- | --------------| ---- | --------- | ----------------- |
  1128. | 0 | pooling_type | int | 0 | |
  1129. | 1 | kernel_w | int | 0 | |
  1130. | 2 | stride_w | int | 1 | |
  1131. | 3 | pad_left | int | 0 | |
  1132. | 4 | global_pooling| int | 0 | |
  1133. | 5 | pad_mode | int | 0 | |
  1134. | 6 | avgpool_count_include_pad| int | 0 | |
  1135. | 7 | adaptive_pooling| int | 0 | |
  1136. | 8 | out_w | int | 0 | |
  1137. | 11 | kernel_h | int | kernel_w | |
  1138. | 12 | stride_h | int | stride_w | |
  1139. | 13 | pad_top | int | pad_left | |
  1140. | 14 | pad_right | int | pad_left | |
  1141. | 15 | pad_bottom | int | pad_top | |
  1142. | 18 | out_h | int | out_w | |
  1143. Pooling type:
  1144. - 0 = MAX
  1145. - 1 = AVG
  1146. Pad mode:
  1147. - 0 = full padding
  1148. - 1 = valid padding
  1149. - 2 = tensorflow padding=SAME or onnx padding=SAME_UPPER
  1150. - 3 = onnx padding=SAME_LOWER
  1151. # Pooling1D
  1152. ```
  1153. x2 = pad(x, pads)
  1154. x3 = pooling1d(x2, kernel, stride)
  1155. ```
  1156. | param id | name | type | default | description |
  1157. | --------- | --------------| ---- | --------- | ----------------- |
  1158. | 0 | pooling_type | int | 0 | |
  1159. | 1 | kernel_w | int | 0 | |
  1160. | 2 | stride_w | int | 1 | |
  1161. | 3 | pad_left | int | 0 | |
  1162. | 4 | global_pooling| int | 0 | |
  1163. | 5 | pad_mode | int | 0 | |
  1164. | 6 | avgpool_count_include_pad| int | 0 | |
  1165. | 7 | adaptive_pooling| int | 0 | |
  1166. | 8 | out_w | int | 0 | |
  1167. | 14 | pad_right | int | pad_left | |
  1168. Pooling type:
  1169. - 0 = MAX
  1170. - 1 = AVG
  1171. Pad mode:
  1172. - 0 = full padding
  1173. - 1 = valid padding
  1174. - 2 = tensorflow padding=SAME or onnx padding=SAME_UPPER
  1175. - 3 = onnx padding=SAME_LOWER
  1176. # Pooling3D
  1177. ```
  1178. x2 = pad(x, pads)
  1179. x3 = pooling3d(x2, kernel, stride)
  1180. ```
  1181. | param id | name | type | default | description |
  1182. | --------- | --------------| ---- | --------- | ----------------- |
  1183. | 0 | pooling_type | int | 0 | |
  1184. | 1 | kernel_w | int | 0 | |
  1185. | 2 | stride_w | int | 1 | |
  1186. | 3 | pad_left | int | 0 | |
  1187. | 4 | global_pooling| int | 0 | |
  1188. | 5 | pad_mode | int | 0 | |
  1189. | 6 | avgpool_count_include_pad| int | 0 | |
  1190. | 7 | adaptive_pooling| int | 0 | |
  1191. | 8 | out_w | int | 0 | |
  1192. | 11 | kernel_h | int | kernel_w | |
  1193. | 12 | stride_h | int | stride_w | |
  1194. | 13 | pad_top | int | pad_left | |
  1195. | 14 | pad_right | int | pad_left | |
  1196. | 15 | pad_bottom | int | pad_top | |
  1197. | 16 | pad_behind | int | pad_front | |
  1198. | 18 | out_h | int | out_w | |
  1199. | 21 | kernel_d | int | kernel_w | |
  1200. | 22 | stride_d | int | stride_w | |
  1201. | 23 | pad_front | int | pad_left | |
  1202. | 28 | out_d | int | out_w | |
  1203. Pooling type:
  1204. - 0 = MAX
  1205. - 1 = AVG
  1206. Pad mode:
  1207. - 0 = full padding
  1208. - 1 = valid padding
  1209. - 2 = tensorflow padding=SAME or onnx padding=SAME_UPPER
  1210. - 3 = onnx padding=SAME_LOWER
  1211. # Power
  1212. ```
  1213. y = pow((shift + x * scale), power)
  1214. ```
  1215. * one_blob_only
  1216. * support_inplace
  1217. | param id | name | type | default | description |
  1218. | --------- | ------------- | ----- | --------- | ----------------- |
  1219. | 0 | power | float | 1.f | |
  1220. | 1 | scale | float | 1.f | |
  1221. | 2 | shift | float | 0.f | |
  1222. # PReLU
  1223. ```
  1224. if x < 0 y = x * slope
  1225. else y = x
  1226. ```
  1227. * one_blob_only
  1228. * support_inplace
  1229. | param id | name | type | default | description |
  1230. | --------- | ------------- | ----- | --------- | ----------------- |
  1231. | 0 | num_slope | int | 0 | |
  1232. | weight | type | shape |
  1233. | ------------- | ----- | --------------------- |
  1234. | slope_data | float | [num_slope] |
  1235. # Quantize
  1236. ```
  1237. y = float2int8(x * scale)
  1238. ```
  1239. * one_blob_only
  1240. | param id | name | type | default | description |
  1241. | --------- | ------------- | ----- | --------- | ----------------- |
  1242. | 0 | scale_data_size| int | 1 | |
  1243. | weight | type | shape |
  1244. | ------------- | ----- | --------------------- |
  1245. | scale_data | float | [scale_data_size] |
  1246. # Reduction
  1247. ```
  1248. y = reduce_op(x * coeff)
  1249. ```
  1250. * one_blob_only
  1251. | param id | name | type | default | description |
  1252. | --------- | ------------- | ----- | --------- | ----------------- |
  1253. | 0 | operation | int | 0 | |
  1254. | 1 | reduce_all | int | 1 | |
  1255. | 2 | coeff | float | 1.f | |
  1256. | 3 | axes | array | [ ] | |
  1257. | 4 | keepdims | int | 0 | |
  1258. Operation type:
  1259. - 0 = SUM
  1260. - 1 = ASUM
  1261. - 2 = SUMSQ
  1262. - 3 = MEAN
  1263. - 4 = MAX
  1264. - 5 = MIN
  1265. - 6 = PROD
  1266. - 7 = L1
  1267. - 8 = L2
  1268. - 9 = LogSum
  1269. - 10 = LogSumExp
  1270. # ReLU
  1271. ```
  1272. if x < 0 y = x * slope
  1273. else y = x
  1274. ```
  1275. * one_blob_only
  1276. * support_inplace
  1277. | param id | name | type | default | description |
  1278. | --------- | ------------- | ----- | --------- | ----------------- |
  1279. | 0 | slope | float | 0.f | |
  1280. # Reorg
  1281. ```
  1282. if mode == 0 y = space_to_depth(x) where x channel order is sw-sh-outc
  1283. if mode == 1 y = space_to_depth(x) where x channel order is outc-sw-sh
  1284. ```
  1285. * one_blob_only
  1286. | param id | name | type | default | description |
  1287. | --------- | ------------- | ---- | --------- | ----------------- |
  1288. | 0 | stride | int | 1 | |
  1289. | 1 | mode | int | 0 | |
  1290. # Requantize
  1291. ```
  1292. x2 = x * scale_in + bias
  1293. x3 = activation(x2)
  1294. y = float2int8(x3 * scale_out)
  1295. ```
  1296. * one_blob_only
  1297. | param id | name | type | default | description |
  1298. | --------- | ------------- | ----- | --------- | ----------------- |
  1299. | 0 | scale_in_data_size| int | 1 | |
  1300. | 1 | scale_out_data_size| int | 1 | |
  1301. | 2 | bias_data_size| int | 0 | |
  1302. | 3 | activation_type| int | 0 | |
  1303. | 4 | activation_params| int | [ ] | |
  1304. | weight | type | shape |
  1305. | ------------- | ----- | --------------------- |
  1306. | scale_in_data | float | [scale_in_data_size] |
  1307. | scale_out_data| float | [scale_out_data_size] |
  1308. | bias_data | float | [bias_data_size] |
  1309. # Reshape
  1310. ```
  1311. if permute == 1 y = hwc2chw(reshape(chw2hwc(x)))
  1312. else y = reshape(x)
  1313. ```
  1314. * one_blob_only
  1315. | param id | name | type | default | description |
  1316. | --------- | ------------- | ----- | --------- | ----------------- |
  1317. | 0 | w | int | -233 | |
  1318. | 1 | h | int | -233 | |
  1319. | 11 | d | int | -233 | |
  1320. | 2 | c | int | -233 | |
  1321. | 3 | permute | int | 0 | |
  1322. Reshape flag:
  1323. - 0 = copy from bottom
  1324. - -1 = remaining
  1325. - -233 = drop this dim(default)
  1326. # RNN
  1327. 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]`.
  1328. ```
  1329. y = rnn(x)
  1330. y0, hidden y1 = rnn(x0, hidden x1)
  1331. ```
  1332. * one_blob_only if bidirectional
  1333. | param id | name | type | default | description |
  1334. | --------- | ------------- | ----- | --------- | ----------------- |
  1335. | 0 | num_output | int | 0 | hidden size of output |
  1336. | 1 | weight_data_size| int | 0 | total size of weight matrix |
  1337. | 2 | direction | int | 0 | 0=forward, 1=reverse, 2=bidirectional |
  1338. | weight | type | shape |
  1339. | ------------- | ----- | --------------------- |
  1340. | weight_xc_data| float/fp16/int8 | [input_size, num_output, num_directions] |
  1341. | bias_c_data | float/fp16/int8 | [num_output, 1, num_directions] |
  1342. | weight_hc_data| float/fp16/int8 | [num_output, num_output, num_directions] |
  1343. Direction flag:
  1344. - 0 = forward only
  1345. - 1 = reverse only
  1346. - 2 = bidirectional
  1347. # Scale
  1348. ```
  1349. if scale_data_size == -233 y = x0 * x1
  1350. else y = x * scale + bias
  1351. ```
  1352. * one_blob_only if scale_data_size != -233
  1353. * support_inplace
  1354. | param id | name | type | default | description |
  1355. | --------- | ------------- | ----- | --------- | ----------------- |
  1356. | 0 | scale_data_size| int | 0 | |
  1357. | 1 | bias_term | int | 0 | |
  1358. | weight | type | shape |
  1359. | ------------- | ----- | --------------------- |
  1360. | scale_data | float | [scale_data_size] |
  1361. | bias_data | float | [scale_data_size] |
  1362. # SELU
  1363. ```
  1364. if x < 0 y = (exp(x) - 1.f) * alpha * lambda
  1365. else y = x * lambda
  1366. ```
  1367. * one_blob_only
  1368. * support_inplace
  1369. | param id | name | type | default | description |
  1370. | --------- | ------------- | ----- | --------- | ----------------- |
  1371. | 0 | alpha | float | 1.67326324f| |
  1372. | 1 | lambda | float | 1.050700987f| |
  1373. # ShuffleChannel
  1374. ```
  1375. if reverse == 0 y = shufflechannel(x) by group
  1376. if reverse == 1 y = shufflechannel(x) by channel / group
  1377. ```
  1378. * one_blob_only
  1379. | param id | name | type | default | description |
  1380. | --------- | ------------- | ---- | --------- | ----------------- |
  1381. | 0 | group | int | 1 | |
  1382. | 1 | reverse | int | 0 | |
  1383. # Sigmoid
  1384. ```
  1385. y = 1 / (1 + exp(-x))
  1386. ```
  1387. * one_blob_only
  1388. * support_inplace
  1389. # Slice
  1390. ```
  1391. split x along axis into slices, each part slice size is based on slices array
  1392. ```
  1393. | param id | name | type | default | description |
  1394. | --------- | ------------- | ----- | --------- | ----------------- |
  1395. | 0 | slices | array | [ ] | |
  1396. | 1 | axis | int | 0 | |
  1397. # Softmax
  1398. ```
  1399. softmax(x, axis)
  1400. ```
  1401. * one_blob_only
  1402. * support_inplace
  1403. | param id | name | type | default | description |
  1404. | --------- | ------------- | ----- | --------- | ----------------- |
  1405. | 0 | axis | int | 0 | |
  1406. | 1 | fixbug0 | int | 0 | hack for bug fix, should be 1 |
  1407. # Softplus
  1408. ```
  1409. y = log(exp(x) + 1)
  1410. ```
  1411. * one_blob_only
  1412. * support_inplace
  1413. # Split
  1414. ```
  1415. y0, y1 ... = x
  1416. ```
  1417. # Swish
  1418. ```
  1419. y = x / (1 + exp(-x))
  1420. ```
  1421. * one_blob_only
  1422. * support_inplace
  1423. # TanH
  1424. ```
  1425. y = tanh(x)
  1426. ```
  1427. * one_blob_only
  1428. * support_inplace
  1429. # Threshold
  1430. ```
  1431. if x > threshold y = 1
  1432. else y = 0
  1433. ```
  1434. * one_blob_only
  1435. * support_inplace
  1436. | param id | name | type | default | description |
  1437. | --------- | ------------- | ----- | --------- | ----------------- |
  1438. | 0 | threshold | float | 0.f | |
  1439. # Tile
  1440. ```
  1441. y = repeat tiles along axis for x
  1442. ```
  1443. * one_blob_only
  1444. | param id | name | type | default | description |
  1445. | --------- | ------------- | ----- | --------- | ----------------- |
  1446. | 0 | axis | int | 0 | |
  1447. | 1 | tiles | int | 1 | |
  1448. | 2 | repeats | array | [ ] | |
  1449. # UnaryOp
  1450. ```
  1451. y = unaryop(x)
  1452. ```
  1453. - one_blob_only
  1454. - support_inplace
  1455. | param id | name | type | default | description |
  1456. | --------- | ------------- | ----- | --------- | ----------------- |
  1457. | 0 | op_type | int | 0 | Operation type as follows |
  1458. Operation type:
  1459. - 0 = ABS
  1460. - 1 = NEG
  1461. - 2 = FLOOR
  1462. - 3 = CEIL
  1463. - 4 = SQUARE
  1464. - 5 = SQRT
  1465. - 6 = RSQ
  1466. - 7 = EXP
  1467. - 8 = LOG
  1468. - 9 = SIN
  1469. - 10 = COS
  1470. - 11 = TAN
  1471. - 12 = ASIN
  1472. - 13 = ACOS
  1473. - 14 = ATAN
  1474. - 15 = RECIPROCAL
  1475. - 16 = TANH
  1476. - 17 = LOG10