You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

operators.md 66 kB

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