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

operators.md 68 kB

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