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

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