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

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777
  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. # CopyTo
  381. ```
  382. self[offset] = src
  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. | 9 | starts | array | [ ] | |
  391. | 11 | axes | array | [ ] | |
  392. # Crop
  393. ```
  394. y = crop(x)
  395. ```
  396. * one_blob_only
  397. | param id | name | type | default | description |
  398. | --------- | ------------- | ----- | --------- | ----------------- |
  399. | 0 | woffset | int | 0 | |
  400. | 1 | hoffset | int | 0 | |
  401. | 2 | coffset | int | 1 | |
  402. | 3 | outw | int | 1 | |
  403. | 4 | outh | int | 0 | |
  404. | 5 | outc | int | 0 | |
  405. | 6 | woffset2 | int | 0 | |
  406. | 7 | hoffset2 | int | 1 | |
  407. | 8 | coffset2 | int | 0 | |
  408. | 9 | starts | array | [ ] | |
  409. | 10 | ends | array | [ ] | |
  410. | 11 | axes | array | [ ] | |
  411. # CumulativeSum
  412. If axis < 0, we use axis = x.dims + axis
  413. It implements https://pytorch.org/docs/stable/generated/torch.cumsum.html
  414. * one_blob_only
  415. * support_inplace
  416. | param id | name | type | default | description |
  417. | --------- | ------------- | ----- | --------- | ----------------- |
  418. | 0 | axis | int | 0 | |
  419. # Deconvolution
  420. ```
  421. x2 = deconv(x, weight, kernel, stride, dilation) + bias
  422. x3 = depad(x2, pads, pad_value)
  423. y = activation(x3, act_type, act_params)
  424. ```
  425. * one_blob_only
  426. | param id | name | type | default | description |
  427. | --------- | ------------- | ----- | --------- | ----------------- |
  428. | 0 | num_output | int | 0 | |
  429. | 1 | kernel_w | int | 0 | |
  430. | 2 | dilation_w | int | 1 | |
  431. | 3 | stride_w | int | 1 | |
  432. | 4 | pad_left | int | 0 | |
  433. | 5 | bias_term | int | 0 | |
  434. | 6 | weight_data_size| int | 0 | |
  435. | 9 | activation_type| int | 0 | |
  436. | 10 | activation_params| array | [ ] | |
  437. | 11 | kernel_h | int | kernel_w | |
  438. | 12 | dilation_h | int | dilation_w | |
  439. | 13 | stride_h | int | stride_w | |
  440. | 14 | pad_top | int | pad_left | |
  441. | 15 | pad_right | int | pad_left | |
  442. | 16 | pad_bottom | int | pad_top | |
  443. | 18 | output_pad_right| int | 0 | |
  444. | 19 | output_pad_bottom| int | output_pad_right | |
  445. | 20 | output_w | int | 0 | |
  446. | 21 | output_h | int | output_w | |
  447. | weight | type | shape |
  448. | ------------- | ----- | --------------------- |
  449. | weight_data | float/fp16 | [kernel_w, kernel_h, num_input, num_output] |
  450. | bias_data | float | [num_output] |
  451. # Deconvolution1D
  452. ```
  453. x2 = deconv1d(x, weight, kernel, stride, dilation) + bias
  454. x3 = depad(x2, pads, pad_value)
  455. y = activation(x3, act_type, act_params)
  456. ```
  457. * one_blob_only
  458. | param id | name | type | default | description |
  459. | --------- | ------------- | ----- | --------- | ----------------- |
  460. | 0 | num_output | int | 0 | |
  461. | 1 | kernel_w | int | 0 | |
  462. | 2 | dilation_w | int | 1 | |
  463. | 3 | stride_w | int | 1 | |
  464. | 4 | pad_left | int | 0 | |
  465. | 5 | bias_term | int | 0 | |
  466. | 6 | weight_data_size| int | 0 | |
  467. | 9 | activation_type| int | 0 | |
  468. | 10 | activation_params| array | [ ] | |
  469. | 15 | pad_right | int | pad_left | |
  470. | 18 | output_pad_right| int | 0 | |
  471. | 20 | output_w | int | 0 | |
  472. | weight | type | shape |
  473. | ------------- | ----- | --------------------- |
  474. | weight_data | float/fp16 | [kernel_w, num_input, num_output] |
  475. | bias_data | float | [num_output] |
  476. # Deconvolution3D
  477. ```
  478. x2 = deconv3d(x, weight, kernel, stride, dilation) + bias
  479. x3 = depad(x2, pads, pad_value)
  480. y = activation(x3, act_type, act_params)
  481. ```
  482. * one_blob_only
  483. | param id | name | type | default | description |
  484. | --------- | ------------- | ----- | --------- | ----------------- |
  485. | 0 | num_output | int | 0 | |
  486. | 1 | kernel_w | int | 0 | |
  487. | 2 | dilation_w | int | 1 | |
  488. | 3 | stride_w | int | 1 | |
  489. | 4 | pad_left | int | 0 | |
  490. | 5 | bias_term | int | 0 | |
  491. | 6 | weight_data_size| int | 0 | |
  492. | 9 | activation_type| int | 0 | |
  493. | 10 | activation_params| array | [ ] | |
  494. | 11 | kernel_h | int | kernel_w | |
  495. | 12 | dilation_h | int | dilation_w | |
  496. | 13 | stride_h | int | stride_w | |
  497. | 14 | pad_top | int | pad_left | |
  498. | 15 | pad_right | int | pad_left | |
  499. | 16 | pad_bottom | int | pad_top | |
  500. | 17 | pad_behind | int | pad_front | |
  501. | 18 | output_pad_right| int | 0 | |
  502. | 19 | output_pad_bottom| int | output_pad_right | |
  503. | 20 | output_pad_behind| int | output_pad_right | |
  504. | 21 | kernel_d | int | kernel_w | |
  505. | 22 | dilation_d | int | dilation_w | |
  506. | 23 | stride_d | int | stride_w | |
  507. | 24 | pad_front | int | pad_left | |
  508. | 25 | output_w | int | 0 | |
  509. | 26 | output_h | int | output_w | |
  510. | 27 | output_d | int | output_w | |
  511. | weight | type | shape |
  512. | ------------- | ----- | --------------------- |
  513. | weight_data | float/fp16 | [kernel_w, kernel_h, kernel_d, num_input, num_output] |
  514. | bias_data | float | [num_output] |
  515. # DeconvolutionDepthWise
  516. ```
  517. x2 = deconv(x, weight, kernel, stride, dilation, group) + bias
  518. x3 = depad(x2, pads, pad_value)
  519. y = activation(x3, act_type, act_params)
  520. ```
  521. * one_blob_only
  522. | param id | name | type | default | description |
  523. | --------- | ------------- | ----- | --------- | ----------------- |
  524. | 0 | num_output | int | 0 | |
  525. | 1 | kernel_w | int | 0 | |
  526. | 2 | dilation_w | int | 1 | |
  527. | 3 | stride_w | int | 1 | |
  528. | 4 | pad_left | int | 0 | |
  529. | 5 | bias_term | int | 0 | |
  530. | 6 | weight_data_size| int | 0 | |
  531. | 7 | group | int | 1 | |
  532. | 9 | activation_type| int | 0 | |
  533. | 10 | activation_params| array | [ ] | |
  534. | 11 | kernel_h | int | kernel_w | |
  535. | 12 | dilation_h | int | dilation_w | |
  536. | 13 | stride_h | int | stride_w | |
  537. | 14 | pad_top | int | pad_left | |
  538. | 15 | pad_right | int | pad_left | |
  539. | 16 | pad_bottom | int | pad_top | |
  540. | 18 | output_pad_right| int | 0 | |
  541. | 19 | output_pad_bottom| int | output_pad_right | |
  542. | 20 | output_w | int | 0 | |
  543. | 21 | output_h | int | output_w | |
  544. | weight | type | shape |
  545. | ------------- | ----- | --------------------- |
  546. | weight_data | float/fp16 | [kernel_w, kernel_h, num_input / group, num_output / group, group] |
  547. | bias_data | float | [num_output] |
  548. # DeconvolutionDepthWise1D
  549. ```
  550. x2 = deconv1d(x, weight, kernel, stride, dilation, group) + bias
  551. x3 = depad(x2, pads, pad_value)
  552. y = activation(x3, act_type, act_params)
  553. ```
  554. * one_blob_only
  555. | param id | name | type | default | description |
  556. | --------- | ------------- | ----- | --------- | ----------------- |
  557. | 0 | num_output | int | 0 | |
  558. | 1 | kernel_w | int | 0 | |
  559. | 2 | dilation_w | int | 1 | |
  560. | 3 | stride_w | int | 1 | |
  561. | 4 | pad_left | int | 0 | |
  562. | 5 | bias_term | int | 0 | |
  563. | 6 | weight_data_size| int | 0 | |
  564. | 7 | group | int | 1 | |
  565. | 9 | activation_type| int | 0 | |
  566. | 10 | activation_params| array | [ ] | |
  567. | 15 | pad_right | int | pad_left | |
  568. | 18 | output_pad_right| int | 0 | |
  569. | 20 | output_w | int | 0 | |
  570. | weight | type | shape |
  571. | ------------- | ----- | --------------------- |
  572. | weight_data | float/fp16 | [kernel_w, num_input / group, num_output / group, group] |
  573. | bias_data | float | [num_output] |
  574. # DeconvolutionDepthWise3D
  575. ```
  576. x2 = deconv3d(x, weight, kernel, stride, dilation, group) + bias
  577. x3 = depad(x2, pads, pad_value)
  578. y = activation(x3, act_type, act_params)
  579. ```
  580. * one_blob_only
  581. | param id | name | type | default | description |
  582. | --------- | ------------- | ----- | --------- | ----------------- |
  583. | 0 | num_output | int | 0 | |
  584. | 1 | kernel_w | int | 0 | |
  585. | 2 | dilation_w | int | 1 | |
  586. | 3 | stride_w | int | 1 | |
  587. | 4 | pad_left | int | 0 | |
  588. | 5 | bias_term | int | 0 | |
  589. | 6 | weight_data_size| int | 0 | |
  590. | 7 | group | int | 1 | |
  591. | 9 | activation_type| int | 0 | |
  592. | 10 | activation_params| array | [ ] | |
  593. | 11 | kernel_h | int | kernel_w | |
  594. | 12 | dilation_h | int | dilation_w | |
  595. | 13 | stride_h | int | stride_w | |
  596. | 14 | pad_top | int | pad_left | |
  597. | 15 | pad_right | int | pad_left | |
  598. | 16 | pad_bottom | int | pad_top | |
  599. | 17 | pad_behind | int | pad_front | |
  600. | 18 | output_pad_right| int | 0 | |
  601. | 19 | output_pad_bottom| int | output_pad_right | |
  602. | 20 | output_pad_behind| int | output_pad_right | |
  603. | 21 | kernel_d | int | kernel_w | |
  604. | 22 | dilation_d | int | dilation_w | |
  605. | 23 | stride_d | int | stride_w | |
  606. | 24 | pad_front | int | pad_left | |
  607. | 25 | output_w | int | 0 | |
  608. | 26 | output_h | int | output_w | |
  609. | 27 | output_d | int | output_w | |
  610. | weight | type | shape |
  611. | ------------- | ----- | --------------------- |
  612. | weight_data | float/fp16 | [kernel_w, kernel_h, kernel_d, num_input / group, num_output / group, group] |
  613. | bias_data | float | [num_output] |
  614. # DeformableConv2D
  615. ```
  616. x2 = deformableconv2d(x, offset, mask, weight, kernel, stride, dilation) + bias
  617. y = activation(x2, act_type, act_params)
  618. ```
  619. | param id | name | type | default | description |
  620. | --------- | ------------- | ----- | --------- | ----------------- |
  621. | 0 | num_output | int | 0 | |
  622. | 1 | kernel_w | int | 0 | |
  623. | 2 | dilation_w | int | 1 | |
  624. | 3 | stride_w | int | 1 | |
  625. | 4 | pad_left | int | 0 | |
  626. | 5 | bias_term | int | 0 | |
  627. | 6 | weight_data_size| int | 0 | |
  628. | 9 | activation_type| int | 0 | |
  629. | 10 | activation_params| array | [ ] | |
  630. | 11 | kernel_h | int | kernel_w | |
  631. | 12 | dilation_h | int | dilation_w | |
  632. | 13 | stride_h | int | stride_w | |
  633. | 14 | pad_top | int | pad_left | |
  634. | 15 | pad_right | int | pad_left | |
  635. | 16 | pad_bottom | int | pad_top | |
  636. | weight | type | shape |
  637. | ------------- | ----- | --------------------- |
  638. | weight_data | float/fp16/int8 | [kernel_w, kernel_h, num_input, num_output] |
  639. | bias_data | float | [num_output] |
  640. # Dequantize
  641. ```
  642. y = x * scale + bias
  643. ```
  644. * one_blob_only
  645. * support_inplace
  646. | param id | name | type | default | description |
  647. | --------- | ------------- | ----- | --------- | ----------------- |
  648. | 0 | scale_data_size| int | 1 | |
  649. | 1 | bias_data_size| int | 0 | |
  650. | weight | type | shape |
  651. | ------------- | ----- | --------------------- |
  652. | scale_data | float | [scale_data_size] |
  653. | bias_data | float | [bias_data_size] |
  654. # Dropout
  655. ```
  656. y = x * scale
  657. ```
  658. * one_blob_only
  659. | param id | name | type | default | description |
  660. | --------- | ------------- | ----- | --------- | ----------------- |
  661. | 0 | scale | float | 1.f | |
  662. # Eltwise
  663. ```
  664. y = elementwise_op(x0, x1, ...)
  665. ```
  666. | param id | name | type | default | description |
  667. | --------- | ------------- | ----- | --------- | ----------------- |
  668. | 0 | op_type | int | 0 | |
  669. | 1 | coeffs | array | [ ] | |
  670. Operation type:
  671. - 0 = PROD
  672. - 1 = SUM
  673. - 2 = MAX
  674. # ELU
  675. ```
  676. if x < 0 y = (exp(x) - 1) * alpha
  677. else y = x
  678. ```
  679. * one_blob_only
  680. * support_inplace
  681. | param id | name | type | default | description |
  682. | --------- | ------------- | ----- | --------- | ----------------- |
  683. | 0 | alpha | float | 0.1f | |
  684. # Exp
  685. ```
  686. if base == -1 y = exp(shift + x * scale)
  687. else y = pow(base, (shift + x * scale))
  688. ```
  689. * one_blob_only
  690. * support_inplace
  691. | param id | name | type | default | description |
  692. | --------- | ------------- | ----- | --------- | ----------------- |
  693. | 0 | base | float | -1.f | |
  694. | 1 | scale | float | 1.f | |
  695. | 2 | shift | float | 0.f | |
  696. # Flatten
  697. Reshape blob to 1 dimension
  698. * one_blob_only
  699. # GELU
  700. ```
  701. if fast_gelu == 1 y = 0.5 * x * (1 + tanh(0.79788452 * (x + 0.044715 * x * x * x)));
  702. else y = 0.5 * x * erfc(-0.70710678 * x)
  703. ```
  704. * one_blob_only
  705. * support_inplace
  706. | param id | name | type | default | description |
  707. | --------- | ------------- | ----- | --------- | ----------------- |
  708. | 0 | fast_gelu | int | 0 | use approximation |
  709. # GLU
  710. If axis < 0, we use axis = x.dims + axis
  711. GLU(a,b)=a⊗σ(b)
  712. where a is the first half of the input matrix and b is the second half.
  713. axis specifies the dimension to split the input
  714. * one_blob_only
  715. | param id | name | type | default | description |
  716. | --------- | ------------- | ----- | --------- | ----------------- |
  717. | 0 | axis | int | 0 | |
  718. # Gemm
  719. ```
  720. a = transA ? transpose(x0) : x0
  721. b = transb ? transpose(x1) : x1
  722. c = x2
  723. y = (gemm(a, b) + c * beta) * alpha
  724. ```
  725. | param id | name | type | default | description |
  726. | --------- | ------------- | ----- | --------- | ----------------- |
  727. | 0 | alpha | float | 1.f | |
  728. | 1 | beta | float | 1.f | |
  729. | 2 | transA | int | 0 | |
  730. | 3 | transb | int | 0 | |
  731. | 4 | constantA | int | 0 | |
  732. | 5 | constantB | int | 0 | |
  733. | 6 | constantC | int | 0 | |
  734. | 7 | constantM | int | 0 | |
  735. | 8 | constantN | int | 0 | |
  736. | 9 | constantK | int | 0 | |
  737. | 10 | constant_broadcast_type_C | int | 0 | |
  738. | 11 | output_N1M | int | 0 | |
  739. | 12 | output_elempack | int | 0 | |
  740. | 13 | output_elemtype | int | 0 | |
  741. | 14 | output_transpose | int| 0 | |
  742. | 20 | constant_TILE_M | int | 0 | |
  743. | 21 | constant_TILE_N | int | 0 | |
  744. | 22 | constant_TILE_K | int | 0 | |
  745. | weight | type | shape |
  746. | ------------- | ----- | --------------------- |
  747. | A_data | float | [M, K] or [K, M] |
  748. | B_data | float | [N, K] or [K, N] |
  749. | C_data | float | [1], [M] or [N] or [1, M] or [N,1] or [N, M] |
  750. # GridSample
  751. ```
  752. Given an input and a flow-field grid, computes the output using input values and pixel locations from grid.
  753. For each output location output[:, h2, w2], the size-2 vector grid[h2, w2, 2] specifies input pixel[:, h1, w1] locations x and y,
  754. which are used to interpolate the output value output[:, h2, w2]
  755. This function is often used in conjunction with affine_grid() to build Spatial Transformer Networks .
  756. ```
  757. | param id | name | type | default | description |
  758. | --------- | ------------- | ----- | --------- | ----------------- |
  759. | 0 | sample_type | int | 1 | |
  760. | 1 | padding_mode | int | 1 | |
  761. | 2 | align_corner | int | 0 | |
  762. Sample type:
  763. - 1 = Nearest
  764. - 2 = Bilinear
  765. - 3 = Bicubic
  766. Padding mode:
  767. - 1 = zeros
  768. - 2 = border
  769. - 3 = reflection
  770. # GroupNorm
  771. ```
  772. split x along channel axis into group x0, x1 ...
  773. l2 normalize for each group x0, x1 ...
  774. y = x * gamma + beta
  775. ```
  776. * one_blob_only
  777. * support_inplace
  778. | param id | name | type | default | description |
  779. | --------- | ------------- | ----- | --------- | ----------------- |
  780. | 0 | group | int | 1 | |
  781. | 1 | channels | int | 0 | |
  782. | 2 | eps | float | 0.001f | x = x / sqrt(var + eps) |
  783. | 3 | affine | int | 1 | |
  784. | weight | type | shape |
  785. | ------------- | ----- | --------------------- |
  786. | gamma_data | float | [channels] |
  787. | beta_data | float | [channels] |
  788. # GRU
  789. 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]`.
  790. ```
  791. y = gru(x)
  792. y0, hidden y1 = gru(x0, hidden x1)
  793. ```
  794. * one_blob_only if bidirectional
  795. | param id | name | type | default | description |
  796. | --------- | ------------- | ----- | --------- | ----------------- |
  797. | 0 | num_output | int | 0 | hidden size of output |
  798. | 1 | weight_data_size| int | 0 | total size of weight matrix |
  799. | 2 | direction | int | 0 | 0=forward, 1=reverse, 2=bidirectional |
  800. | weight | type | shape |
  801. | ------------- | ----- | --------------------- |
  802. | weight_xc_data| float/fp16/int8 | [input_size, num_output * 3, num_directions] |
  803. | bias_c_data | float/fp16/int8 | [num_output, 4, num_directions] |
  804. | weight_hc_data| float/fp16/int8 | [num_output, num_output * 3, num_directions] |
  805. Direction flag:
  806. - 0 = forward only
  807. - 1 = reverse only
  808. - 2 = bidirectional
  809. # HardSigmoid
  810. ```
  811. y = clamp(x * alpha + beta, 0, 1)
  812. ```
  813. * one_blob_only
  814. * support_inplace
  815. | param id | name | type | default | description |
  816. | --------- | ------------- | ----- | --------- | ----------------- |
  817. | 0 | alpha | float | 0.2f | |
  818. | 1 | beta | float | 0.5f | |
  819. # HardSwish
  820. ```
  821. y = x * clamp(x * alpha + beta, 0, 1)
  822. ```
  823. * one_blob_only
  824. * support_inplace
  825. | param id | name | type | default | description |
  826. | --------- | ------------- | ----- | --------- | ----------------- |
  827. | 0 | alpha | float | 0.2f | |
  828. | 1 | beta | float | 0.5f | |
  829. # InnerProduct
  830. ```
  831. x2 = innerproduct(x, weight) + bias
  832. y = activation(x2, act_type, act_params)
  833. ```
  834. * one_blob_only
  835. | param id | name | type | default | description |
  836. | --------- | ------------- | ----- | --------- | ----------------- |
  837. | 0 | num_output | int | 0 | |
  838. | 1 | bias_term | int | 0 | |
  839. | 2 | weight_data_size| int | 0 | |
  840. | 8 | int8_scale_term| int | 0 | |
  841. | 9 | activation_type| int | 0 | |
  842. | 10 | activation_params| array | [ ] | |
  843. | weight | type | shape |
  844. | ------------- | ----- | --------------------- |
  845. | weight_data | float/fp16/int8 | [num_input, num_output] |
  846. | bias_data | float | [num_output] |
  847. | weight_data_int8_scales| float | [num_output] |
  848. | bottom_blob_int8_scales| float | [1] |
  849. # Input
  850. ```
  851. y = input
  852. ```
  853. * support_inplace
  854. | param id | name | type | default | description |
  855. | --------- | ------------- | ----- | --------- | ----------------- |
  856. | 0 | w | int | 0 | |
  857. | 1 | h | int | 0 | |
  858. | 11 | d | int | 0 | |
  859. | 2 | c | int | 0 | |
  860. # InstanceNorm
  861. ```
  862. split x along channel axis into instance x0, x1 ...
  863. l2 normalize for each channel instance x0, x1 ...
  864. y = x * gamma + beta
  865. ```
  866. * one_blob_only
  867. * support_inplace
  868. | param id | name | type | default | description |
  869. | --------- | ------------- | ----- | --------- | ----------------- |
  870. | 0 | channels | int | 0 | |
  871. | 1 | eps | float | 0.001f | x = x / sqrt(var + eps) |
  872. | 2 | affine | int | 1 | |
  873. | weight | type | shape |
  874. | ------------- | ----- | --------------------- |
  875. | gamma_data | float | [channels] |
  876. | beta_data | float | [channels] |
  877. # Interp
  878. ```
  879. if dynamic_target_size == 0 y = resize(x) by fixed size or scale
  880. else y = resize(x0, size(x1))
  881. ```
  882. * one_blob_only if dynamic_target_size == 0
  883. | param id | name | type | default | description |
  884. | --------- | ------------- | ----- | --------- | ----------------- |
  885. | 0 | resize_type | int | 0 | |
  886. | 1 | height_scale | float | 1.f | |
  887. | 2 | width_scale | float | 1.f | |
  888. | 3 | output_height | int | 0 | |
  889. | 4 | output_width | int | 0 | |
  890. | 5 | dynamic_target_size| int | 0 | |
  891. | 6 | align_corner | int | 0 | |
  892. Resize type:
  893. - 1 = Nearest
  894. - 2 = Bilinear
  895. - 3 = Bicubic
  896. # LayerNorm
  897. ```
  898. split x along outmost axis into part x0, x1 ...
  899. l2 normalize for each part x0, x1 ...
  900. y = x * gamma + beta by elementwise
  901. ```
  902. * one_blob_only
  903. * support_inplace
  904. | param id | name | type | default | description |
  905. | --------- | ------------- | ----- | --------- | ----------------- |
  906. | 0 | affine_size | int | 0 | |
  907. | 1 | eps | float | 0.001f | x = x / sqrt(var + eps) |
  908. | 2 | affine | int | 1 | |
  909. | weight | type | shape |
  910. | ------------- | ----- | --------------------- |
  911. | gamma_data | float | [affine_size] |
  912. | beta_data | float | [affine_size] |
  913. # Log
  914. ```
  915. if base == -1 y = log(shift + x * scale)
  916. else y = log(shift + x * scale) / log(base)
  917. ```
  918. * one_blob_only
  919. * support_inplace
  920. | param id | name | type | default | description |
  921. | --------- | ------------- | ----- | --------- | ----------------- |
  922. | 0 | base | float | -1.f | |
  923. | 1 | scale | float | 1.f | |
  924. | 2 | shift | float | 0.f | |
  925. # LRN
  926. ```
  927. if region_type == ACROSS_CHANNELS square_sum = sum of channel window of local_size
  928. if region_type == WITHIN_CHANNEL square_sum = sum of spatial window of local_size
  929. y = x * pow(bias + alpha * square_sum / (local_size * local_size), -beta)
  930. ```
  931. * one_blob_only
  932. * support_inplace
  933. | param id | name | type | default | description |
  934. | --------- | ------------- | ----- | --------- | ----------------- |
  935. | 0 | region_type | int | 0 | |
  936. | 1 | local_size | int | 5 | |
  937. | 2 | alpha | float | 1.f | |
  938. | 3 | beta | float | 0.75f | |
  939. | 4 | bias | float | 1.f | |
  940. Region type:
  941. - 0 = ACROSS_CHANNELS
  942. - 1 = WITHIN_CHANNEL
  943. # LSTM
  944. 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]`.
  945. ```
  946. y = lstm(x)
  947. y0, hidden y1, cell y2 = lstm(x0, hidden x1, cell x2)
  948. ```
  949. * one_blob_only if bidirectional
  950. | param id | name | type | default | description |
  951. | --------- | ------------- | ----- | --------- | ----------------- |
  952. | 0 | num_output | int | 0 | output size of output |
  953. | 1 | weight_data_size| int | 0 | total size of IFOG weight matrix |
  954. | 2 | direction | int | 0 | 0=forward, 1=reverse, 2=bidirectional |
  955. | 3 | hidden_size | int | num_output| hidden size |
  956. | weight | type | shape |
  957. | ------------- | ----- | --------------------- |
  958. | weight_xc_data| float/fp16/int8 | [input_size, hidden_size * 4, num_directions] |
  959. | bias_c_data | float/fp16/int8 | [hidden_size, 4, num_directions] |
  960. | weight_hc_data| float/fp16/int8 | [num_output, hidden_size * 4, num_directions] |
  961. | weight_hr_data| float/fp16/int8 | [hidden_size, num_output, num_directions] |
  962. Direction flag:
  963. - 0 = forward only
  964. - 1 = reverse only
  965. - 2 = bidirectional
  966. # MemoryData
  967. ```
  968. y = data
  969. ```
  970. | param id | name | type | default | description |
  971. | --------- | ------------- | ----- | --------- | ----------------- |
  972. | 0 | w | int | 0 | |
  973. | 1 | h | int | 0 | |
  974. | 11 | d | int | 0 | |
  975. | 2 | c | int | 0 | |
  976. | weight | type | shape |
  977. | ------------- | ----- | --------------------- |
  978. | data | float | [w, h, d, c] |
  979. # Mish
  980. ```
  981. y = x * tanh(log(exp(x) + 1))
  982. ```
  983. * one_blob_only
  984. * support_inplace
  985. # MultiHeadAttention
  986. ```
  987. split q k v into num_head part q0, k0, v0, q1, k1, v1 ...
  988. for each num_head part
  989. xq = affine(q) / (embed_dim / num_head)
  990. xk = affine(k)
  991. xv = affine(v)
  992. xqk = xq * xk
  993. softmax_inplace(xqk)
  994. xqkv = xqk * xv
  995. merge xqkv to out
  996. y = affine(out)
  997. ```
  998. | param id | name | type | default | description |
  999. | --------- | ------------- | ----- | --------- | ----------------- |
  1000. | 0 | embed_dim | int | 0 | |
  1001. | 1 | num_head | int | 1 | |
  1002. | 2 | weight_data_size| int | 0 | |
  1003. | 3 | kdim | int | embed_dim | |
  1004. | 4 | vdim | int | embed_dim | |
  1005. | weight | type | shape |
  1006. | ------------- | ----- | --------------------- |
  1007. | q_weight_data | float/fp16/int8 | [weight_data_size] |
  1008. | q_bias_data | float | [embed_dim] |
  1009. | k_weight_data | float/fp16/int8 | [embed_dim * kdim] |
  1010. | k_bias_data | float | [embed_dim] |
  1011. | v_weight_data | float/fp16/int8 | [embed_dim * vdim] |
  1012. | v_bias_data | float | [embed_dim] |
  1013. | out_weight_data| float/fp16/int8 | [weight_data_size] |
  1014. | out_bias_data | float | [embed_dim] |
  1015. # MVN
  1016. ```
  1017. if normalize_variance == 1 && across_channels == 1 y = (x - mean) / (sqrt(var) + eps) of whole blob
  1018. if normalize_variance == 1 && across_channels == 0 y = (x - mean) / (sqrt(var) + eps) of each channel
  1019. if normalize_variance == 0 && across_channels == 1 y = x - mean of whole blob
  1020. if normalize_variance == 0 && across_channels == 0 y = x - mean of each channel
  1021. ```
  1022. * one_blob_only
  1023. | param id | name | type | default | description |
  1024. | --------- | ------------- | ----- | --------- | ----------------- |
  1025. | 0 | normalize_variance| int | 0 | |
  1026. | 1 | across_channels| int | 0 | |
  1027. | 2 | eps | float | 0.0001f | x = x / (sqrt(var) + eps) |
  1028. # Noop
  1029. ```
  1030. y = x
  1031. ```
  1032. # Normalize
  1033. ```
  1034. if across_spatial == 1 && across_channel == 1 x2 = normalize(x) of whole blob
  1035. if across_spatial == 1 && across_channel == 0 x2 = normalize(x) of each channel
  1036. if across_spatial == 0 && across_channel == 1 x2 = normalize(x) of each position
  1037. y = x2 * scale
  1038. ```
  1039. * one_blob_only
  1040. * support_inplace
  1041. | param id | name | type | default | description |
  1042. | --------- | ------------- | ----- | --------- | ----------------- |
  1043. | 0 | across_spatial| int | 0 | |
  1044. | 1 | channel_shared| int | 0 | |
  1045. | 2 | eps | float | 0.0001f | see eps mode |
  1046. | 3 | scale_data_size| int | 0 | |
  1047. | 4 | across_channel| int | 0 | |
  1048. | 9 | eps_mode | int | 0 | |
  1049. | weight | type | shape |
  1050. | ------------- | ----- | --------------------- |
  1051. | scale_data | float | [scale_data_size] |
  1052. Eps Mode:
  1053. - 0 = caffe/mxnet x = x / sqrt(var + eps)
  1054. - 1 = pytorch x = x / max(sqrt(var), eps)
  1055. - 2 = tensorflow x = x / sqrt(max(var, eps))
  1056. # Packing
  1057. ```
  1058. y = wrap_packing(x)
  1059. ```
  1060. * one_blob_only
  1061. | param id | name | type | default | description |
  1062. | --------- | ------------- | ----- | --------- | ----------------- |
  1063. | 0 | out_elempack | int | 1 | |
  1064. | 1 | use_padding | int | 0 | |
  1065. | 2 | cast_type_from| int | 0 | |
  1066. | 3 | cast_type_to | int | 0 | |
  1067. | 4 | storage_type_from| int | 0 | |
  1068. | 5 | storage_type_to| int | 0 | |
  1069. # Padding
  1070. ```
  1071. y = pad(x, pads)
  1072. ```
  1073. | param id | name | type | default | description |
  1074. | --------- | ------------- | ---- | --------- | ----------------- |
  1075. | 0 | top | int | 0 | |
  1076. | 1 | bottom | int | 0 | |
  1077. | 2 | left | int | 0 | |
  1078. | 3 | right | int | 0 | |
  1079. | 4 | type | int | 0 | |
  1080. | 5 | value | float | 0 | |
  1081. | 6 | per_channel_pad_data_size| int | 0 | |
  1082. | 7 | front | int | stride_w | |
  1083. | 8 | behind | int | pad_left | |
  1084. | weight | type | shape |
  1085. | ------------- | ----- | --------------------- |
  1086. | per_channel_pad_data| float | [per_channel_pad_data_size] |
  1087. Padding type:
  1088. - 0 = CONSTANT
  1089. - 1 = REPLICATE
  1090. - 2 = REFLECT
  1091. # Permute
  1092. ```
  1093. y = reorder(x)
  1094. ```
  1095. | param id | name | type | default | description |
  1096. | --------- | ------------- | ---- | --------- | ----------------- |
  1097. | 0 | order_type | int | 0 | |
  1098. Order Type:
  1099. - 0 = WH WHC WHDC
  1100. - 1 = HW HWC HWDC
  1101. - 2 = WCH WDHC
  1102. - 3 = CWH DWHC
  1103. - 4 = HCW HDWC
  1104. - 5 = CHW DHWC
  1105. - 6 = WHCD
  1106. - 7 = HWCD
  1107. - 8 = WCHD
  1108. - 9 = CWHD
  1109. - 10 = HCWD
  1110. - 11 = CHWD
  1111. - 12 = WDCH
  1112. - 13 = DWCH
  1113. - 14 = WCDH
  1114. - 15 = CWDH
  1115. - 16 = DCWH
  1116. - 17 = CDWH
  1117. - 18 = HDCW
  1118. - 19 = DHCW
  1119. - 20 = HCDW
  1120. - 21 = CHDW
  1121. - 22 = DCHW
  1122. - 23 = CDHW
  1123. # PixelShuffle
  1124. ```
  1125. if mode == 0 y = depth_to_space(x) where x channel order is sw-sh-outc
  1126. if mode == 1 y = depth_to_space(x) where x channel order is outc-sw-sh
  1127. ```
  1128. * one_blob_only
  1129. | param id | name | type | default | description |
  1130. | --------- | ------------- | ---- | --------- | ----------------- |
  1131. | 0 | upscale_factor| int | 1 | |
  1132. | 1 | mode | int | 0 | |
  1133. # Pooling
  1134. ```
  1135. x2 = pad(x, pads)
  1136. x3 = pooling(x2, kernel, stride)
  1137. ```
  1138. | param id | name | type | default | description |
  1139. | --------- | --------------| ---- | --------- | ----------------- |
  1140. | 0 | pooling_type | int | 0 | |
  1141. | 1 | kernel_w | int | 0 | |
  1142. | 2 | stride_w | int | 1 | |
  1143. | 3 | pad_left | int | 0 | |
  1144. | 4 | global_pooling| int | 0 | |
  1145. | 5 | pad_mode | int | 0 | |
  1146. | 6 | avgpool_count_include_pad| int | 0 | |
  1147. | 7 | adaptive_pooling| int | 0 | |
  1148. | 8 | out_w | int | 0 | |
  1149. | 11 | kernel_h | int | kernel_w | |
  1150. | 12 | stride_h | int | stride_w | |
  1151. | 13 | pad_top | int | pad_left | |
  1152. | 14 | pad_right | int | pad_left | |
  1153. | 15 | pad_bottom | int | pad_top | |
  1154. | 18 | out_h | int | out_w | |
  1155. Pooling type:
  1156. - 0 = MAX
  1157. - 1 = AVG
  1158. Pad mode:
  1159. - 0 = full padding
  1160. - 1 = valid padding
  1161. - 2 = tensorflow padding=SAME or onnx padding=SAME_UPPER
  1162. - 3 = onnx padding=SAME_LOWER
  1163. # Pooling1D
  1164. ```
  1165. x2 = pad(x, pads)
  1166. x3 = pooling1d(x2, kernel, stride)
  1167. ```
  1168. | param id | name | type | default | description |
  1169. | --------- | --------------| ---- | --------- | ----------------- |
  1170. | 0 | pooling_type | int | 0 | |
  1171. | 1 | kernel_w | int | 0 | |
  1172. | 2 | stride_w | int | 1 | |
  1173. | 3 | pad_left | int | 0 | |
  1174. | 4 | global_pooling| int | 0 | |
  1175. | 5 | pad_mode | int | 0 | |
  1176. | 6 | avgpool_count_include_pad| int | 0 | |
  1177. | 7 | adaptive_pooling| int | 0 | |
  1178. | 8 | out_w | int | 0 | |
  1179. | 14 | pad_right | int | pad_left | |
  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. # Pooling3D
  1189. ```
  1190. x2 = pad(x, pads)
  1191. x3 = pooling3d(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. | 11 | kernel_h | int | kernel_w | |
  1205. | 12 | stride_h | int | stride_w | |
  1206. | 13 | pad_top | int | pad_left | |
  1207. | 14 | pad_right | int | pad_left | |
  1208. | 15 | pad_bottom | int | pad_top | |
  1209. | 16 | pad_behind | int | pad_front | |
  1210. | 18 | out_h | int | out_w | |
  1211. | 21 | kernel_d | int | kernel_w | |
  1212. | 22 | stride_d | int | stride_w | |
  1213. | 23 | pad_front | int | pad_left | |
  1214. | 28 | out_d | int | out_w | |
  1215. Pooling type:
  1216. - 0 = MAX
  1217. - 1 = AVG
  1218. Pad mode:
  1219. - 0 = full padding
  1220. - 1 = valid padding
  1221. - 2 = tensorflow padding=SAME or onnx padding=SAME_UPPER
  1222. - 3 = onnx padding=SAME_LOWER
  1223. # Power
  1224. ```
  1225. y = pow((shift + x * scale), power)
  1226. ```
  1227. * one_blob_only
  1228. * support_inplace
  1229. | param id | name | type | default | description |
  1230. | --------- | ------------- | ----- | --------- | ----------------- |
  1231. | 0 | power | float | 1.f | |
  1232. | 1 | scale | float | 1.f | |
  1233. | 2 | shift | float | 0.f | |
  1234. # PReLU
  1235. ```
  1236. if x < 0 y = x * slope
  1237. else y = x
  1238. ```
  1239. * one_blob_only
  1240. * support_inplace
  1241. | param id | name | type | default | description |
  1242. | --------- | ------------- | ----- | --------- | ----------------- |
  1243. | 0 | num_slope | int | 0 | |
  1244. | weight | type | shape |
  1245. | ------------- | ----- | --------------------- |
  1246. | slope_data | float | [num_slope] |
  1247. # Quantize
  1248. ```
  1249. y = float2int8(x * scale)
  1250. ```
  1251. * one_blob_only
  1252. | param id | name | type | default | description |
  1253. | --------- | ------------- | ----- | --------- | ----------------- |
  1254. | 0 | scale_data_size| int | 1 | |
  1255. | weight | type | shape |
  1256. | ------------- | ----- | --------------------- |
  1257. | scale_data | float | [scale_data_size] |
  1258. # Reduction
  1259. ```
  1260. y = reduce_op(x * coeff)
  1261. ```
  1262. * one_blob_only
  1263. | param id | name | type | default | description |
  1264. | --------- | ------------- | ----- | --------- | ----------------- |
  1265. | 0 | operation | int | 0 | |
  1266. | 1 | reduce_all | int | 1 | |
  1267. | 2 | coeff | float | 1.f | |
  1268. | 3 | axes | array | [ ] | |
  1269. | 4 | keepdims | int | 0 | |
  1270. Operation type:
  1271. - 0 = SUM
  1272. - 1 = ASUM
  1273. - 2 = SUMSQ
  1274. - 3 = MEAN
  1275. - 4 = MAX
  1276. - 5 = MIN
  1277. - 6 = PROD
  1278. - 7 = L1
  1279. - 8 = L2
  1280. - 9 = LogSum
  1281. - 10 = LogSumExp
  1282. # ReLU
  1283. ```
  1284. if x < 0 y = x * slope
  1285. else y = x
  1286. ```
  1287. * one_blob_only
  1288. * support_inplace
  1289. | param id | name | type | default | description |
  1290. | --------- | ------------- | ----- | --------- | ----------------- |
  1291. | 0 | slope | float | 0.f | |
  1292. # Reorg
  1293. ```
  1294. if mode == 0 y = space_to_depth(x) where x channel order is sw-sh-outc
  1295. if mode == 1 y = space_to_depth(x) where x channel order is outc-sw-sh
  1296. ```
  1297. * one_blob_only
  1298. | param id | name | type | default | description |
  1299. | --------- | ------------- | ---- | --------- | ----------------- |
  1300. | 0 | stride | int | 1 | |
  1301. | 1 | mode | int | 0 | |
  1302. # Requantize
  1303. ```
  1304. x2 = x * scale_in + bias
  1305. x3 = activation(x2)
  1306. y = float2int8(x3 * scale_out)
  1307. ```
  1308. * one_blob_only
  1309. | param id | name | type | default | description |
  1310. | --------- | ------------- | ----- | --------- | ----------------- |
  1311. | 0 | scale_in_data_size| int | 1 | |
  1312. | 1 | scale_out_data_size| int | 1 | |
  1313. | 2 | bias_data_size| int | 0 | |
  1314. | 3 | activation_type| int | 0 | |
  1315. | 4 | activation_params| int | [ ] | |
  1316. | weight | type | shape |
  1317. | ------------- | ----- | --------------------- |
  1318. | scale_in_data | float | [scale_in_data_size] |
  1319. | scale_out_data| float | [scale_out_data_size] |
  1320. | bias_data | float | [bias_data_size] |
  1321. # Reshape
  1322. ```
  1323. if permute == 1 y = hwc2chw(reshape(chw2hwc(x)))
  1324. else y = reshape(x)
  1325. ```
  1326. * one_blob_only
  1327. | param id | name | type | default | description |
  1328. | --------- | ------------- | ----- | --------- | ----------------- |
  1329. | 0 | w | int | -233 | |
  1330. | 1 | h | int | -233 | |
  1331. | 11 | d | int | -233 | |
  1332. | 2 | c | int | -233 | |
  1333. | 3 | permute | int | 0 | |
  1334. Reshape flag:
  1335. - 0 = copy from bottom
  1336. - -1 = remaining
  1337. - -233 = drop this dim(default)
  1338. # RNN
  1339. 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]`.
  1340. ```
  1341. y = rnn(x)
  1342. y0, hidden y1 = rnn(x0, hidden x1)
  1343. ```
  1344. * one_blob_only if bidirectional
  1345. | param id | name | type | default | description |
  1346. | --------- | ------------- | ----- | --------- | ----------------- |
  1347. | 0 | num_output | int | 0 | hidden size of output |
  1348. | 1 | weight_data_size| int | 0 | total size of weight matrix |
  1349. | 2 | direction | int | 0 | 0=forward, 1=reverse, 2=bidirectional |
  1350. | weight | type | shape |
  1351. | ------------- | ----- | --------------------- |
  1352. | weight_xc_data| float/fp16/int8 | [input_size, num_output, num_directions] |
  1353. | bias_c_data | float/fp16/int8 | [num_output, 1, num_directions] |
  1354. | weight_hc_data| float/fp16/int8 | [num_output, num_output, num_directions] |
  1355. Direction flag:
  1356. - 0 = forward only
  1357. - 1 = reverse only
  1358. - 2 = bidirectional
  1359. # Scale
  1360. ```
  1361. if scale_data_size == -233 y = x0 * x1
  1362. else y = x * scale + bias
  1363. ```
  1364. * one_blob_only if scale_data_size != -233
  1365. * support_inplace
  1366. | param id | name | type | default | description |
  1367. | --------- | ------------- | ----- | --------- | ----------------- |
  1368. | 0 | scale_data_size| int | 0 | |
  1369. | 1 | bias_term | int | 0 | |
  1370. | weight | type | shape |
  1371. | ------------- | ----- | --------------------- |
  1372. | scale_data | float | [scale_data_size] |
  1373. | bias_data | float | [scale_data_size] |
  1374. # SELU
  1375. ```
  1376. if x < 0 y = (exp(x) - 1.f) * alpha * lambda
  1377. else y = x * lambda
  1378. ```
  1379. * one_blob_only
  1380. * support_inplace
  1381. | param id | name | type | default | description |
  1382. | --------- | ------------- | ----- | --------- | ----------------- |
  1383. | 0 | alpha | float | 1.67326324f| |
  1384. | 1 | lambda | float | 1.050700987f| |
  1385. # ShuffleChannel
  1386. ```
  1387. if reverse == 0 y = shufflechannel(x) by group
  1388. if reverse == 1 y = shufflechannel(x) by channel / group
  1389. ```
  1390. * one_blob_only
  1391. | param id | name | type | default | description |
  1392. | --------- | ------------- | ---- | --------- | ----------------- |
  1393. | 0 | group | int | 1 | |
  1394. | 1 | reverse | int | 0 | |
  1395. # Sigmoid
  1396. ```
  1397. y = 1 / (1 + exp(-x))
  1398. ```
  1399. * one_blob_only
  1400. * support_inplace
  1401. # Slice
  1402. ```
  1403. split x along axis into slices, each part slice size is based on slices array
  1404. ```
  1405. | param id | name | type | default | description |
  1406. | --------- | ------------- | ----- | --------- | ----------------- |
  1407. | 0 | slices | array | [ ] | |
  1408. | 1 | axis | int | 0 | |
  1409. # Softmax
  1410. ```
  1411. softmax(x, axis)
  1412. ```
  1413. * one_blob_only
  1414. * support_inplace
  1415. | param id | name | type | default | description |
  1416. | --------- | ------------- | ----- | --------- | ----------------- |
  1417. | 0 | axis | int | 0 | |
  1418. | 1 | fixbug0 | int | 0 | hack for bug fix, should be 1 |
  1419. # Softplus
  1420. ```
  1421. y = log(exp(x) + 1)
  1422. ```
  1423. * one_blob_only
  1424. * support_inplace
  1425. # Split
  1426. ```
  1427. y0, y1 ... = x
  1428. ```
  1429. # Swish
  1430. ```
  1431. y = x / (1 + exp(-x))
  1432. ```
  1433. * one_blob_only
  1434. * support_inplace
  1435. # TanH
  1436. ```
  1437. y = tanh(x)
  1438. ```
  1439. * one_blob_only
  1440. * support_inplace
  1441. # Threshold
  1442. ```
  1443. if x > threshold y = 1
  1444. else y = 0
  1445. ```
  1446. * one_blob_only
  1447. * support_inplace
  1448. | param id | name | type | default | description |
  1449. | --------- | ------------- | ----- | --------- | ----------------- |
  1450. | 0 | threshold | float | 0.f | |
  1451. # Tile
  1452. ```
  1453. y = repeat tiles along axis for x
  1454. ```
  1455. * one_blob_only
  1456. | param id | name | type | default | description |
  1457. | --------- | ------------- | ----- | --------- | ----------------- |
  1458. | 0 | axis | int | 0 | |
  1459. | 1 | tiles | int | 1 | |
  1460. | 2 | repeats | array | [ ] | |
  1461. # UnaryOp
  1462. ```
  1463. y = unaryop(x)
  1464. ```
  1465. - one_blob_only
  1466. - support_inplace
  1467. | param id | name | type | default | description |
  1468. | --------- | ------------- | ----- | --------- | ----------------- |
  1469. | 0 | op_type | int | 0 | Operation type as follows |
  1470. Operation type:
  1471. - 0 = ABS
  1472. - 1 = NEG
  1473. - 2 = FLOOR
  1474. - 3 = CEIL
  1475. - 4 = SQUARE
  1476. - 5 = SQRT
  1477. - 6 = RSQ
  1478. - 7 = EXP
  1479. - 8 = LOG
  1480. - 9 = SIN
  1481. - 10 = COS
  1482. - 11 = TAN
  1483. - 12 = ASIN
  1484. - 13 = ACOS
  1485. - 14 = ATAN
  1486. - 15 = RECIPROCAL
  1487. - 16 = TANH
  1488. - 17 = LOG10