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

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