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

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