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

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