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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293
  1. * [absval](#absval)
  2. * [argmax](#argmax)
  3. * [batchnorm](#batchnorm)
  4. * [bias](#bias)
  5. * [binaryop](#binaryop)
  6. * [bnll](#bnll)
  7. * [cast](#cast)
  8. * [clip](#clip)
  9. * [concat](#concat)
  10. * [convolution](#convolution)
  11. * [convolution1d](#convolution1d)
  12. * [convolutiondepthwise](#convolutiondepthwise)
  13. * [crop](#crop)
  14. * [deconvolution](#deconvolution)
  15. * [deconvolutiondepthwise](#deconvolutiondepthwise)
  16. * [dequantize](#dequantize)
  17. * [dropout](#dropout)
  18. * [eltwise](#eltwise)
  19. * [elu](#elu)
  20. * [exp](#exp)
  21. * [flatten](#flatten)
  22. * [gelu](#gelu)
  23. * [gemm](#gemm)
  24. * [groupnorm](#groupnorm)
  25. * [gru](#gru)
  26. * [hardsigmoid](#hardsigmoid)
  27. * [hardswish](#hardswish)
  28. * [innerproduct](#innerproduct)
  29. * [input](#input)
  30. * [instancenorm](#instancenorm)
  31. * [interp](#interp)
  32. * [layernorm](#layernorm)
  33. * [log](#log)
  34. * [lrn](#lrn)
  35. * [lstm](#lstm)
  36. * [memorydata](#memorydata)
  37. * [mish](#mish)
  38. * [multiheadattention](#multiheadattention)
  39. * [mvn](#mvn)
  40. * [noop](#noop)
  41. * [normalize](#normalize)
  42. * [packing](#packing)
  43. * [padding](#padding)
  44. * [permute](#permute)
  45. * [pixelshuffle](#pixelshuffle)
  46. * [pooling](#pooling)
  47. * [pooling1d](#pooling1d)
  48. * [power](#power)
  49. * [prelu](#prelu)
  50. * [quantize](#quantize)
  51. * [reduction](#reduction)
  52. * [relu](#relu)
  53. * [reorg](#reorg)
  54. * [requantize](#requantize)
  55. * [reshape](#reshape)
  56. * [rnn](#rnn)
  57. * [scale](#scale)
  58. * [selu](#selu)
  59. * [shufflechannel](#shufflechannel)
  60. * [sigmoid](#sigmoid)
  61. * [slice](#slice)
  62. * [softmax](#softmax)
  63. * [softplus](#softplus)
  64. * [split](#split)
  65. * [swish](#swish)
  66. * [tanh](#tanh)
  67. * [threshold](#threshold)
  68. * [unaryop](#unaryop)
  69. # absval
  70. ```
  71. y = abs(x)
  72. ```
  73. * one_blob_only
  74. * support_inplace
  75. # argmax
  76. ```
  77. y = argmax(x, out_max_val, topk)
  78. ```
  79. * one_blob_only
  80. | param id | name | type | default | description |
  81. | --------- | ------------- | ----- | --------- | ----------------- |
  82. | 0 | out_max_val | int | 0 | |
  83. | 1 | topk | int | 1 | |
  84. # batchnorm
  85. ```
  86. y = (x - mean) / sqrt(var + eps) * slope + bias
  87. ```
  88. * one_blob_only
  89. * support_inplace
  90. | param id | name | type | default | description |
  91. | --------- | ------------- | ----- | --------- | ----------------- |
  92. | 0 | channels | int | 0 | |
  93. | 1 | eps | float | 0.f | |
  94. | weight | type | shape |
  95. | ------------- | ----- | --------------------- |
  96. | slope_data | float | [channels] |
  97. | mean_data | float | [channels] |
  98. | var_data | float | [channels] |
  99. | bias_data | float | [channels] |
  100. # bias
  101. ```
  102. y = x + bias
  103. ```
  104. * one_blob_only
  105. * support_inplace
  106. | param id | name | type | default | description |
  107. | --------- | ------------- | ----- | --------- | ----------------- |
  108. | 0 | bias_data_size| int | 0 | |
  109. | weight | type | shape |
  110. | ------------- | ----- | --------------------- |
  111. | bias_data | float | [channels] |
  112. # binaryop
  113. This operation is used for binary computation, and the calculation rule depends on the [broadcasting rule](https://github.com/Tencent/ncnn/wiki/binaryop-broadcasting).
  114. ```
  115. C = binaryop(A, B)
  116. ```
  117. if with_scalar = 1:
  118. - one_blob_only
  119. - support_inplace
  120. | param id | name | type | default | description |
  121. | --------- | ------------- | ----- | --------- | ----------------- |
  122. | 0 | op_type | int | 0 | Operation type as follows |
  123. | 1 | with_scalar | int | 0 | with_scalar=0 B is a matrix, with_scalar=1 B is a scalar |
  124. | 2 | b | float | 0.f | When B is a scalar, B = b |
  125. Operation type:
  126. - 0 = ADD
  127. - 1 = SUB
  128. - 2 = MUL
  129. - 3 = DIV
  130. - 4 = MAX
  131. - 5 = MIN
  132. - 6 = POW
  133. - 7 = RSUB
  134. - 8 = RDIV
  135. # bnll
  136. ```
  137. y = log(1 + e^(-x)) , x > 0
  138. y = log(1 + e^x), x < 0
  139. ```
  140. * one_blob_only
  141. * support_inplace
  142. # cast
  143. ```
  144. y = cast(x)
  145. ```
  146. * one_blob_only
  147. * support_packing
  148. | param id | name | type | default | description |
  149. | --------- | ------------- | ----- | --------- | ----------------- |
  150. | 0 | type_from | int | 0 | |
  151. | 1 | type_to | int | 0 | |
  152. Element type:
  153. - 0 = auto
  154. - 1 = float32
  155. - 2 = float16
  156. - 3 = int8
  157. - 4 = bfloat16
  158. # clip
  159. ```
  160. y = clamp(x, min, max)
  161. ```
  162. * one_blob_only
  163. * support_inplace
  164. | param id | name | type | default | description |
  165. | --------- | ------------- | ----- | --------- | ----------------- |
  166. | 0 | min | float | -FLT_MAX | |
  167. | 1 | max | float | FLT_MAX | |
  168. # concat
  169. ```
  170. y = concat(x0, x1, x2, ...) by axis
  171. ```
  172. | param id | name | type | default | description |
  173. | --------- | ------------- | ----- | --------- | ----------------- |
  174. | 0 | axis | int | 0 | |
  175. # convolution
  176. ```
  177. x2 = pad(x, pads, pad_value)
  178. x3 = conv(x2, weight, kernel, stride, dilation) + bias
  179. y = activation(x3, act_type, act_params)
  180. ```
  181. * one_blob_only
  182. | param id | name | type | default | description |
  183. | --------- | ------------- | ----- | --------- | ----------------- |
  184. | 0 | num_output | int | 0 | |
  185. | 1 | kernel_w | int | 0 | |
  186. | 2 | dilation_w | int | 1 | |
  187. | 3 | stride_w | int | 1 | |
  188. | 4 | pad_left | int | 0 | |
  189. | 5 | bias_term | int | 0 | |
  190. | 6 | weight_data_size| int | 0 | |
  191. | 8 | int8_scale_term| int | 0 | |
  192. | 9 | activation_type| int | 0 | |
  193. | 10 | activation_params| array | [ ] | |
  194. | 11 | kernel_h | int | kernel_w | |
  195. | 12 | dilation_h | int | dilation_w | |
  196. | 13 | stride_h | int | stride_w | |
  197. | 15 | pad_right | int | pad_left | |
  198. | 14 | pad_top | int | pad_left | |
  199. | 16 | pad_bottom | int | pad_top | |
  200. | 18 | pad_value | float | 0.f | |
  201. | weight | type | shape |
  202. | ------------- | ----- | --------------------- |
  203. | weight_data | float/fp16/int8 | [kernel_w, kernel_h, num_input, num_output] |
  204. | bias_data | float | [num_output] |
  205. | weight_data_int8_scales| float | [num_output] |
  206. | bottom_blob_int8_scales| float | [1] |
  207. | top_blob_int8_scales| float | [1] |
  208. # convolution1d
  209. ```
  210. x2 = pad(x, pads, pad_value)
  211. x3 = conv1d(x2, weight, kernel, stride, dilation) + bias
  212. y = activation(x3, act_type, act_params)
  213. ```
  214. * one_blob_only
  215. | param id | name | type | default | description |
  216. | --------- | ------------- | ----- | --------- | ----------------- |
  217. | 0 | num_output | int | 0 | |
  218. | 1 | kernel_w | int | 0 | |
  219. | 2 | dilation_w | int | 1 | |
  220. | 3 | stride_w | int | 1 | |
  221. | 4 | pad_left | int | 0 | |
  222. | 5 | bias_term | int | 0 | |
  223. | 6 | weight_data_size| int | 0 | |
  224. | 9 | activation_type| int | 0 | |
  225. | 10 | activation_params| array | [ ] | |
  226. | 15 | pad_right | int | pad_left | |
  227. | 18 | pad_value | float | 0.f | |
  228. | weight | type | shape |
  229. | ------------- | ----- | --------------------- |
  230. | weight_data | float/fp16/int8 | [kernel_w, num_input, num_output] |
  231. | bias_data | float | [num_output] |
  232. # convolutiondepthwise
  233. ```
  234. x2 = pad(x, pads, pad_value)
  235. x3 = conv(x2, weight, kernel, stride, dilation, group) + bias
  236. y = activation(x3, act_type, act_params)
  237. ```
  238. * one_blob_only
  239. | param id | name | type | default | description |
  240. | --------- | ------------- | ----- | --------- | ----------------- |
  241. | 0 | num_output | int | 0 | |
  242. | 1 | kernel_w | int | 0 | |
  243. | 2 | dilation_w | int | 1 | |
  244. | 3 | stride_w | int | 1 | |
  245. | 4 | pad_left | int | 0 | |
  246. | 5 | bias_term | int | 0 | |
  247. | 6 | weight_data_size| int | 0 | |
  248. | 7 | group | int | 1 | |
  249. | 8 | int8_scale_term| int | 0 | |
  250. | 9 | activation_type| int | 0 | |
  251. | 10 | activation_params| array | [ ] | |
  252. | 11 | kernel_h | int | kernel_w | |
  253. | 12 | dilation_h | int | dilation_w | |
  254. | 13 | stride_h | int | stride_w | |
  255. | 15 | pad_right | int | pad_left | |
  256. | 14 | pad_top | int | pad_left | |
  257. | 16 | pad_bottom | int | pad_top | |
  258. | 18 | pad_value | float | 0.f | |
  259. | weight | type | shape |
  260. | ------------- | ----- | --------------------- |
  261. | weight_data | float/fp16/int8 | [kernel_w, kernel_h, num_input / group, num_output / group, group] |
  262. | bias_data | float | [num_output] |
  263. | weight_data_int8_scales| float | [group] |
  264. | bottom_blob_int8_scales| float | [1] |
  265. | top_blob_int8_scales| float | [1] |
  266. # crop
  267. ```
  268. y = crop(x)
  269. ```
  270. * one_blob_only
  271. | param id | name | type | default | description |
  272. | --------- | ------------- | ----- | --------- | ----------------- |
  273. | 0 | woffset | int | 0 | |
  274. | 1 | hoffset | int | 0 | |
  275. | 2 | coffset | int | 1 | |
  276. | 3 | outw | int | 1 | |
  277. | 4 | outh | int | 0 | |
  278. | 5 | outc | int | 0 | |
  279. | 6 | woffset2 | int | 0 | |
  280. | 7 | hoffset2 | int | 1 | |
  281. | 8 | coffset2 | int | 0 | |
  282. | 9 | starts | array | [ ] | |
  283. | 10 | ends | array | [ ] | |
  284. | 11 | axes | array | [ ] | |
  285. # deconvolution
  286. ```
  287. x2 = deconv(x, weight, kernel, stride, dilation) + bias
  288. x3 = depad(x2, pads, pad_value)
  289. y = activation(x3, act_type, act_params)
  290. ```
  291. * one_blob_only
  292. | param id | name | type | default | description |
  293. | --------- | ------------- | ----- | --------- | ----------------- |
  294. | 0 | num_output | int | 0 | |
  295. | 1 | kernel_w | int | 0 | |
  296. | 2 | dilation_w | int | 1 | |
  297. | 3 | stride_w | int | 1 | |
  298. | 4 | pad_left | int | 0 | |
  299. | 5 | bias_term | int | 0 | |
  300. | 6 | weight_data_size| int | 0 | |
  301. | 8 | int8_scale_term| int | 0 | |
  302. | 9 | activation_type| int | 0 | |
  303. | 10 | activation_params| array | [ ] | |
  304. | 11 | kernel_h | int | kernel_w | |
  305. | 12 | dilation_h | int | dilation_w | |
  306. | 13 | stride_h | int | stride_w | |
  307. | 15 | pad_right | int | pad_left | |
  308. | 14 | pad_top | int | pad_left | |
  309. | 16 | pad_bottom | int | pad_top | |
  310. | 18 | pad_value | float | 0.f | |
  311. | weight | type | shape |
  312. | ------------- | ----- | --------------------- |
  313. | weight_data | float/fp16/int8 | [kernel_w, kernel_h, num_input, num_output] |
  314. | bias_data | float | [num_output] |
  315. # deconvolutiondepthwise
  316. ```
  317. x2 = deconv(x, weight, kernel, stride, dilation, group) + bias
  318. x3 = depad(x2, pads, pad_value)
  319. y = activation(x3, act_type, act_params)
  320. ```
  321. * one_blob_only
  322. | param id | name | type | default | description |
  323. | --------- | ------------- | ----- | --------- | ----------------- |
  324. | 0 | num_output | int | 0 | |
  325. | 1 | kernel_w | int | 0 | |
  326. | 2 | dilation_w | int | 1 | |
  327. | 3 | stride_w | int | 1 | |
  328. | 4 | pad_left | int | 0 | |
  329. | 5 | bias_term | int | 0 | |
  330. | 6 | weight_data_size| int | 0 | |
  331. | 7 | group | int | 1 | |
  332. | 8 | int8_scale_term| int | 0 | |
  333. | 9 | activation_type| int | 0 | |
  334. | 10 | activation_params| array | [ ] | |
  335. | 11 | kernel_h | int | kernel_w | |
  336. | 12 | dilation_h | int | dilation_w | |
  337. | 13 | stride_h | int | stride_w | |
  338. | 15 | pad_right | int | pad_left | |
  339. | 14 | pad_top | int | pad_left | |
  340. | 16 | pad_bottom | int | pad_top | |
  341. | 18 | pad_value | float | 0.f | |
  342. | weight | type | shape |
  343. | ------------- | ----- | --------------------- |
  344. | weight_data | float/fp16/int8 | [kernel_w, kernel_h, num_input / group, num_output / group, group] |
  345. | bias_data | float | [num_output] |
  346. # dequantize
  347. ```
  348. y = x * scale + bias
  349. ```
  350. * one_blob_only
  351. * support_inplace
  352. | param id | name | type | default | description |
  353. | --------- | ------------- | ----- | --------- | ----------------- |
  354. | 0 | scale | float | 1.f | |
  355. | 1 | bias_term | int | 0 | |
  356. | 2 | bias_data_size| int | 0 | |
  357. # dropout
  358. ```
  359. y = x * scale
  360. ```
  361. * one_blob_only
  362. | param id | name | type | default | description |
  363. | --------- | ------------- | ----- | --------- | ----------------- |
  364. | 0 | scale | float | 1.f | |
  365. # eltwise
  366. ```
  367. y = elementwise_op(x0, x1, ...)
  368. ```
  369. | param id | name | type | default | description |
  370. | --------- | ------------- | ----- | --------- | ----------------- |
  371. | 0 | op_type | int | 0 | |
  372. | 1 | coeffs | array | [ ] | |
  373. Operation type:
  374. - 0 = PROD
  375. - 1 = SUM
  376. - 2 = MAX
  377. # elu
  378. ```
  379. if x < 0 y = (exp(x) - 1) * alpha
  380. else y = x
  381. ```
  382. * one_blob_only
  383. * support_inplace
  384. | param id | name | type | default | description |
  385. | --------- | ------------- | ----- | --------- | ----------------- |
  386. | 0 | alpha | float | 0.1f | |
  387. # exp
  388. ```
  389. if base == -1 y = exp(shift + x * scale)
  390. else y = pow(base, (shift + x * scale))
  391. ```
  392. * one_blob_only
  393. * support_inplace
  394. | param id | name | type | default | description |
  395. | --------- | ------------- | ----- | --------- | ----------------- |
  396. | 0 | base | float | -1.f | |
  397. | 1 | scale | float | 1.f | |
  398. | 2 | shift | float | 0.f | |
  399. # flatten
  400. Reshape blob to 1 dimension
  401. * one_blob_only
  402. # gelu
  403. ```
  404. if fast_gelu == 1 y = 0.5 * x * (1 + tanh(0.79788452 * (x + 0.044715 * x * x * x)));
  405. else y = 0.5 * x * erfc(-0.70710678 * x)
  406. ```
  407. * one_blob_only
  408. * support_inplace
  409. | param id | name | type | default | description |
  410. | --------- | ------------- | ----- | --------- | ----------------- |
  411. | 0 | fast_gelu | int | 0 | use approximation |
  412. # gemm
  413. ```
  414. a = transA ? transpose(x0) : x0
  415. b = transb ? transpose(x1) : x1
  416. c = x2
  417. y = gemm(a, b) * alpha + c * beta
  418. ```
  419. | param id | name | type | default | description |
  420. | --------- | ------------- | ----- | --------- | ----------------- |
  421. | 0 | alpha | float | 1.f | |
  422. | 1 | beta | float | 1.f | |
  423. | 2 | transA | int | 0 | |
  424. | 3 | transb | int | 0 | |
  425. # groupnorm
  426. ```
  427. split x along channel axis into group x0, x1 ...
  428. l2 normalize for each group x0, x1 ...
  429. y = x * gamma + beta
  430. ```
  431. * one_blob_only
  432. * support_inplace
  433. | param id | name | type | default | description |
  434. | --------- | ------------- | ----- | --------- | ----------------- |
  435. | 0 | group | int | 1 | |
  436. | 1 | channels | int | 0 | |
  437. | 2 | eps | float | 0.001f | x = x / sqrt(var + eps) |
  438. | 3 | affine | int | 1 | |
  439. | weight | type | shape |
  440. | ------------- | ----- | --------------------- |
  441. | gamma_data | float | [channels] |
  442. | beta_data | float | [channels] |
  443. # gru
  444. 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]`.
  445. ```
  446. y = gru(x)
  447. y0, hidden y1 = gru(x0, hidden x1)
  448. ```
  449. * one_blob_only if bidirectional
  450. | param id | name | type | default | description |
  451. | --------- | ------------- | ----- | --------- | ----------------- |
  452. | 0 | num_output | int | 0 | hidden size of output |
  453. | 1 | weight_data_size| int | 0 | total size of weight matrix |
  454. | 2 | direction | int | 0 | 0=forward, 1=reverse, 2=bidirectional |
  455. | weight | type | shape |
  456. | ------------- | ----- | --------------------- |
  457. | weight_xc_data| float | [input_size, num_output * 3, num_directions] |
  458. | bias_c_data | float | [num_output, 4, num_directions] |
  459. | weight_hc_data| float | [num_output, num_output * 3, num_directions] |
  460. Direction flag:
  461. - 0 = forward only
  462. - 1 = reverse only
  463. - 2 = bidirectional
  464. # hardsigmoid
  465. ```
  466. y = clamp(x * alpha + beta, 0, 1)
  467. ```
  468. * one_blob_only
  469. * support_inplace
  470. | param id | name | type | default | description |
  471. | --------- | ------------- | ----- | --------- | ----------------- |
  472. | 0 | alpha | float | 0.2f | |
  473. | 1 | beta | float | 0.5f | |
  474. # hardswish
  475. ```
  476. y = x * clamp(x * alpha + beta, 0, 1)
  477. ```
  478. * one_blob_only
  479. * support_inplace
  480. | param id | name | type | default | description |
  481. | --------- | ------------- | ----- | --------- | ----------------- |
  482. | 0 | alpha | float | 0.2f | |
  483. | 1 | beta | float | 0.5f | |
  484. # innerproduct
  485. ```
  486. x2 = innerproduct(x, weight) + bias
  487. y = activation(x2, act_type, act_params)
  488. ```
  489. * one_blob_only
  490. | param id | name | type | default | description |
  491. | --------- | ------------- | ----- | --------- | ----------------- |
  492. | 0 | num_output | int | 0 | |
  493. | 1 | bias_term | int | 0 | |
  494. | 2 | weight_data_size| int | 0 | |
  495. | 8 | int8_scale_term| int | 0 | |
  496. | 9 | activation_type| int | 0 | |
  497. | 10 | activation_params| array | [ ] | |
  498. | weight | type | shape |
  499. | ------------- | ----- | --------------------- |
  500. | weight_data | float/fp16/int8 | [num_input, num_output] |
  501. | bias_data | float | [num_output] |
  502. | weight_data_int8_scales| float | [num_output] |
  503. | bottom_blob_int8_scales| float | [1] |
  504. # input
  505. ```
  506. y = input
  507. ```
  508. * support_inplace
  509. | param id | name | type | default | description |
  510. | --------- | ------------- | ----- | --------- | ----------------- |
  511. | 0 | w | int | 0 | |
  512. | 1 | h | int | 0 | |
  513. | 2 | c | int | 0 | |
  514. # instancenorm
  515. ```
  516. split x along channel axis into instance x0, x1 ...
  517. l2 normalize for each channel instance x0, x1 ...
  518. y = x * gamma + beta
  519. ```
  520. * one_blob_only
  521. * support_inplace
  522. | param id | name | type | default | description |
  523. | --------- | ------------- | ----- | --------- | ----------------- |
  524. | 0 | channels | int | 0 | |
  525. | 1 | eps | float | 0.001f | x = x / sqrt(var + eps) |
  526. | 2 | affine | int | 1 | |
  527. | weight | type | shape |
  528. | ------------- | ----- | --------------------- |
  529. | gamma_data | float | [channels] |
  530. | beta_data | float | [channels] |
  531. # interp
  532. ```
  533. if dynamic_target_size == 0 y = resize(x) by fixed size or scale
  534. else y = resize(x0, size(x1))
  535. ```
  536. * one_blob_only if dynamic_target_size == 0
  537. | param id | name | type | default | description |
  538. | --------- | ------------- | ----- | --------- | ----------------- |
  539. | 0 | resize_type | int | 0 | |
  540. | 1 | height_scale | float | 1.f | |
  541. | 2 | width_scale | float | 1.f | |
  542. | 3 | output_height | int | 0 | |
  543. | 4 | output_width | int | 0 | |
  544. | 5 | dynamic_target_size| int | 0 | |
  545. | 6 | align_corner | int | 0 | |
  546. Resize type:
  547. - 1 = Nearest
  548. - 2 = Bilinear
  549. - 3 = Bicubic
  550. # layernorm
  551. ```
  552. split x along outmost axis into part x0, x1 ...
  553. l2 normalize for each part x0, x1 ...
  554. y = x * gamma + beta by elementwise
  555. ```
  556. * one_blob_only
  557. * support_inplace
  558. | param id | name | type | default | description |
  559. | --------- | ------------- | ----- | --------- | ----------------- |
  560. | 0 | affine_size | int | 0 | |
  561. | 1 | eps | float | 0.001f | x = x / sqrt(var + eps) |
  562. | 2 | affine | int | 1 | |
  563. | weight | type | shape |
  564. | ------------- | ----- | --------------------- |
  565. | gamma_data | float | [affine_size] |
  566. | beta_data | float | [affine_size] |
  567. # log
  568. ```
  569. if base == -1 y = log(shift + x * scale)
  570. else y = log(shift + x * scale) / log(base)
  571. ```
  572. * one_blob_only
  573. * support_inplace
  574. | param id | name | type | default | description |
  575. | --------- | ------------- | ----- | --------- | ----------------- |
  576. | 0 | base | float | -1.f | |
  577. | 1 | scale | float | 1.f | |
  578. | 2 | shift | float | 0.f | |
  579. # lrn
  580. ```
  581. if region_type == ACROSS_CHANNELS square_sum = sum of channel window of local_size
  582. if region_type == WITHIN_CHANNEL square_sum = sum of spatial window of local_size
  583. y = x * pow(bias + alpha * square_sum / (local_size * local_size), -beta)
  584. ```
  585. * one_blob_only
  586. * support_inplace
  587. | param id | name | type | default | description |
  588. | --------- | ------------- | ----- | --------- | ----------------- |
  589. | 0 | region_type | int | 0 | |
  590. | 1 | local_size | int | 5 | |
  591. | 2 | alpha | float | 1.f | |
  592. | 3 | beta | float | 0.75f | |
  593. | 4 | bias | float | 1.f | |
  594. Region type:
  595. - 0 = ACROSS_CHANNELS
  596. - 1 = WITHIN_CHANNEL
  597. # lstm
  598. 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]`.
  599. ```
  600. y = lstm(x)
  601. y0, hidden y1, cell y2 = lstm(x0, hidden x1, cell x2)
  602. ```
  603. * one_blob_only if bidirectional
  604. | param id | name | type | default | description |
  605. | --------- | ------------- | ----- | --------- | ----------------- |
  606. | 0 | num_output | int | 0 | hidden size of output |
  607. | 1 | weight_data_size| int | 0 | total size of IFOG weight matrix |
  608. | 2 | direction | int | 0 | 0=forward, 1=reverse, 2=bidirectional |
  609. | weight | type | shape |
  610. | ------------- | ----- | --------------------- |
  611. | weight_xc_data| float | [input_size, num_output * 4, num_directions] |
  612. | bias_c_data | float | [num_output, 4, num_directions] |
  613. | weight_hc_data| float | [num_output, num_output * 4, num_directions] |
  614. Direction flag:
  615. - 0 = forward only
  616. - 1 = reverse only
  617. - 2 = bidirectional
  618. # memorydata
  619. ```
  620. y = data
  621. ```
  622. | param id | name | type | default | description |
  623. | --------- | ------------- | ----- | --------- | ----------------- |
  624. | 0 | w | int | 0 | |
  625. | 1 | h | int | 0 | |
  626. | 2 | c | int | 0 | |
  627. | weight | type | shape |
  628. | ------------- | ----- | --------------------- |
  629. | data | float | [w, h, c] |
  630. # mish
  631. ```
  632. y = x * tanh(log(exp(x) + 1))
  633. ```
  634. * one_blob_only
  635. * support_inplace
  636. # multiheadattention
  637. ```
  638. split q k v into num_head part q0, k0, v0, q1, k1, v1 ...
  639. for each num_head part
  640. xq = affine(q) / (embed_dim / num_head)
  641. xk = affine(k)
  642. xv = affine(v)
  643. xqk = xq * xk
  644. softmax_inplace(xqk)
  645. xqkv = xqk * xv
  646. merge xqkv to out
  647. y = affine(out)
  648. ```
  649. | param id | name | type | default | description |
  650. | --------- | ------------- | ----- | --------- | ----------------- |
  651. | 0 | embed_dim | int | 0 | |
  652. | 1 | num_head | int | 1 | |
  653. | 2 | weight_data_size| int | 0 | |
  654. | weight | type | shape |
  655. | ------------- | ----- | --------------------- |
  656. | q_weight_data | float/fp16/int8 | [weight_data_size] |
  657. | q_bias_data | float | [embed_dim] |
  658. | k_weight_data | float/fp16/int8 | [weight_data_size] |
  659. | k_bias_data | float | [embed_dim] |
  660. | v_weight_data | float/fp16/int8 | [weight_data_size] |
  661. | v_bias_data | float | [embed_dim] |
  662. | out_weight_data| float/fp16/int8 | [weight_data_size] |
  663. | out_bias_data | float | [embed_dim] |
  664. # mvn
  665. ```
  666. if normalize_variance == 1 && across_channels == 1 y = (x - mean) / (sqrt(var) + eps) of whole blob
  667. if normalize_variance == 1 && across_channels == 0 y = (x - mean) / (sqrt(var) + eps) of each channel
  668. if normalize_variance == 0 && across_channels == 1 y = x - mean of whole blob
  669. if normalize_variance == 0 && across_channels == 0 y = x - mean of each channel
  670. ```
  671. * one_blob_only
  672. | param id | name | type | default | description |
  673. | --------- | ------------- | ----- | --------- | ----------------- |
  674. | 0 | normalize_variance| int | 0 | |
  675. | 1 | across_channels| int | 0 | |
  676. | 2 | eps | float | 0.0001f | x = x / (sqrt(var) + eps) |
  677. # noop
  678. ```
  679. y = x
  680. ```
  681. # normalize
  682. ```
  683. if across_spatial == 1 && across_channel == 1 x2 = normalize(x) of whole blob
  684. if across_spatial == 1 && across_channel == 0 x2 = normalize(x) of each channel
  685. if across_spatial == 0 && across_channel == 1 x2 = normalize(x) of each position
  686. y = x2 * scale
  687. ```
  688. * one_blob_only
  689. * support_inplace
  690. | param id | name | type | default | description |
  691. | --------- | ------------- | ----- | --------- | ----------------- |
  692. | 0 | across_spatial| int | 0 | |
  693. | 1 | channel_shared| int | 0 | |
  694. | 2 | eps | float | 0.0001f | see eps mode |
  695. | 3 | scale_data_size| int | 0 | |
  696. | 4 | across_channel| int | 0 | |
  697. | 9 | eps_mode | int | 0 | |
  698. | weight | type | shape |
  699. | ------------- | ----- | --------------------- |
  700. | scale_data | float | [scale_data_size] |
  701. Eps Mode:
  702. - 0 = caffe/mxnet x = x / sqrt(var + eps)
  703. - 1 = pytorch x = x / max(sqrt(var), eps)
  704. - 2 = tensorflow x = x / sqrt(max(var, eps))
  705. # packing
  706. ```
  707. y = wrap_packing(x)
  708. ```
  709. * one_blob_only
  710. | param id | name | type | default | description |
  711. | --------- | ------------- | ----- | --------- | ----------------- |
  712. | 0 | out_elempack | int | 1 | |
  713. | 1 | use_padding | int | 0 | |
  714. | 2 | cast_type_from| float | 0 | |
  715. | 3 | cast_type_to | int | 0 | |
  716. | 4 | storage_type_from| int | 0 | |
  717. | 5 | storage_type_to| int | 0 | |
  718. # padding
  719. ```
  720. if pads != -233/-234 y = pad(x, pads)
  721. else y = pad(x0, pads param from x1)
  722. ```
  723. | param id | name | type | default | description |
  724. | --------- | ------------- | ---- | --------- | ----------------- |
  725. | 0 | top | int | 0 | |
  726. | 1 | bottom | int | 0 | |
  727. | 2 | left | int | 0 | |
  728. | 3 | right | int | 0 | |
  729. | 4 | type | int | 0 | |
  730. | 5 | value | int | 0 | |
  731. | 6 | per_channel_pad_data_size| int | 0 | |
  732. | 7 | front | int | stride_w | |
  733. | 8 | behind | int | pad_left | |
  734. | weight | type | shape |
  735. | ------------- | ----- | --------------------- |
  736. | per_channel_pad_data| float | [per_channel_pad_data_size] |
  737. # permute
  738. ```
  739. y = reorder(x)
  740. ```
  741. | param id | name | type | default | description |
  742. | --------- | ------------- | ---- | --------- | ----------------- |
  743. | 0 | order_type | int | 0 | |
  744. Order Type:
  745. - 0 = WH WHC
  746. - 1 = HW HWC
  747. - 2 = WCH
  748. - 3 = CWH
  749. - 4 = HCW
  750. - 5 = CHW
  751. # pixelshuffle
  752. ```
  753. if mode == 0 y = depth_to_space(x) where x channel order is sw-sh-outc
  754. if mode == 1 y = depth_to_space(x) where x channel order is outc-sw-sh
  755. ```
  756. * one_blob_only
  757. | param id | name | type | default | description |
  758. | --------- | ------------- | ---- | --------- | ----------------- |
  759. | 0 | upscale_factor| int | 1 | |
  760. | 1 | mode | int | 0 | |
  761. # pooling
  762. ```
  763. x2 = pad(x, pads)
  764. x3 = pooling(x2, kernel, stride)
  765. ```
  766. | param id | name | type | default | description |
  767. | --------- | --------------| ---- | --------- | ----------------- |
  768. | 0 | pooling_type | int | 0 | |
  769. | 1 | kernel_w | int | 0 | |
  770. | 2 | stride_w | int | 1 | |
  771. | 3 | pad_left | int | 0 | |
  772. | 4 | global_pooling| int | 0 | |
  773. | 5 | pad_mode | int | 0 | |
  774. | 6 | avgpool_count_include_pad| int | 0 | |
  775. | 7 | adaptive_pooling| int | 0 | |
  776. | 8 | out_w | int | 0 | |
  777. | 11 | kernel_h | int | kernel_w | |
  778. | 12 | stride_h | int | stride_w | |
  779. | 13 | pad_top | int | pad_left | |
  780. | 14 | pad_right | int | pad_left | |
  781. | 15 | pad_bottom | int | pad_top | |
  782. | 18 | out_h | int | 0 | |
  783. Pooling type:
  784. - 0 = MAX
  785. - 1 = AVG
  786. Pad mode:
  787. - 0 = full padding
  788. - 1 = valid padding
  789. - 2 = tensorflow padding=SAME or onnx padding=SAME_UPPER
  790. - 3 = onnx padding=SAME_LOWER
  791. # pooling1d
  792. ```
  793. x2 = pad(x, pads)
  794. x3 = pooling1d(x2, kernel, stride)
  795. ```
  796. | param id | name | type | default | description |
  797. | --------- | --------------| ---- | --------- | ----------------- |
  798. | 0 | pooling_type | int | 0 | |
  799. | 1 | kernel_w | int | 0 | |
  800. | 2 | stride_w | int | 1 | |
  801. | 3 | pad_left | int | 0 | |
  802. | 4 | global_pooling| int | 0 | |
  803. | 5 | pad_mode | int | 0 | |
  804. | 6 | avgpool_count_include_pad| int | 0 | |
  805. | 7 | adaptive_pooling| int | 0 | |
  806. | 8 | out_w | int | 0 | |
  807. | 14 | pad_right | int | pad_left | |
  808. Pooling type:
  809. - 0 = MAX
  810. - 1 = AVG
  811. Pad mode:
  812. - 0 = full padding
  813. - 1 = valid padding
  814. - 2 = tensorflow padding=SAME or onnx padding=SAME_UPPER
  815. - 3 = onnx padding=SAME_LOWER
  816. # power
  817. ```
  818. y = pow((shift + x * scale), power)
  819. ```
  820. * one_blob_only
  821. * support_inplace
  822. | param id | name | type | default | description |
  823. | --------- | ------------- | ----- | --------- | ----------------- |
  824. | 0 | power | float | 1.f | |
  825. | 1 | scale | float | 1.f | |
  826. | 2 | shift | float | 0.f | |
  827. # prelu
  828. ```
  829. if x < 0 y = x * slope
  830. else y = x
  831. ```
  832. * one_blob_only
  833. * support_inplace
  834. | param id | name | type | default | description |
  835. | --------- | ------------- | ----- | --------- | ----------------- |
  836. | 0 | num_slope | int | 0 | |
  837. | weight | type | shape |
  838. | ------------- | ----- | --------------------- |
  839. | slope_data | float | [num_slope] |
  840. # quantize
  841. ```
  842. y = float2int8(x * scale)
  843. ```
  844. * one_blob_only
  845. | param id | name | type | default | description |
  846. | --------- | ------------- | ----- | --------- | ----------------- |
  847. | 0 | scale_data_size| int | 0 | |
  848. | weight | type | shape |
  849. | ------------- | ----- | --------------------- |
  850. | scale_data | float | [scale_data_size] |
  851. # reduction
  852. ```
  853. y = reduce_op(x * coeff)
  854. ```
  855. * one_blob_only
  856. | param id | name | type | default | description |
  857. | --------- | ------------- | ----- | --------- | ----------------- |
  858. | 0 | operation | int | 0 | |
  859. | 1 | reduce_all | int | 1 | |
  860. | 2 | coeff | float | 1.f | |
  861. | 3 | axes | array | [ ] | |
  862. | 4 | keepdims | int | 0 | |
  863. Operation type:
  864. - 0 = SUM
  865. - 1 = ASUM
  866. - 2 = SUMSQ
  867. - 3 = MEAN
  868. - 4 = MAX
  869. - 5 = MIN
  870. - 6 = PROD
  871. - 7 = L1
  872. - 8 = L2
  873. - 9 = LogSum
  874. - 10 = LogSumExp
  875. # relu
  876. ```
  877. if x < 0 y = x * slope
  878. else y = x
  879. ```
  880. * one_blob_only
  881. * support_inplace
  882. | param id | name | type | default | description |
  883. | --------- | ------------- | ----- | --------- | ----------------- |
  884. | 0 | slope | float | 0.f | |
  885. # reorg
  886. ```
  887. if mode == 0 y = space_to_depth(x) where x channel order is sw-sh-outc
  888. if mode == 1 y = space_to_depth(x) where x channel order is outc-sw-sh
  889. ```
  890. * one_blob_only
  891. | param id | name | type | default | description |
  892. | --------- | ------------- | ---- | --------- | ----------------- |
  893. | 0 | stride | int | 1 | |
  894. | 1 | mode | int | 0 | |
  895. # requantize
  896. ```
  897. x2 = x * scale_in + bias
  898. x3 = activation(x2)
  899. y = float2int8(x3 * scale_out)
  900. ```
  901. * one_blob_only
  902. | param id | name | type | default | description |
  903. | --------- | ------------- | ----- | --------- | ----------------- |
  904. | 0 | scale_in_data_size| int | 1 | |
  905. | 1 | scale_out_data_size| int | 1 | |
  906. | 2 | bias_data_size| int | 0 | |
  907. | 3 | activation_type| int | 0 | |
  908. | 4 | activation_params| int | [ ] | |
  909. | weight | type | shape |
  910. | ------------- | ----- | --------------------- |
  911. | scale_in_data | float | [scale_in_data_size] |
  912. | scale_out_data| float | [scale_out_data_size] |
  913. | bias_data | float | [bias_data_size] |
  914. # reshape
  915. ```
  916. if permute == 1 y = hwc2chw(reshape(chw2hwc(x)))
  917. else y = reshape(x)
  918. ```
  919. * one_blob_only
  920. | param id | name | type | default | description |
  921. | --------- | ------------- | ----- | --------- | ----------------- |
  922. | 0 | w | int | -233 | |
  923. | 1 | h | int | -233 | |
  924. | 2 | c | int | -233 | |
  925. | 3 | permute | int | 0 | |
  926. Reshape flag:
  927. - 0 = copy from bottom
  928. - -1 = remaining
  929. - -233 = drop this dim(default)
  930. # rnn
  931. 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]`.
  932. ```
  933. y = rnn(x)
  934. y0, hidden y1 = rnn(x0, hidden x1)
  935. ```
  936. * one_blob_only if bidirectional
  937. | param id | name | type | default | description |
  938. | --------- | ------------- | ----- | --------- | ----------------- |
  939. | 0 | num_output | int | 0 | hidden size of output |
  940. | 1 | weight_data_size| int | 0 | total size of weight matrix |
  941. | 2 | direction | int | 0 | 0=forward, 1=reverse, 2=bidirectional |
  942. | weight | type | shape |
  943. | ------------- | ----- | --------------------- |
  944. | weight_xc_data| float | [input_size, num_output, num_directions] |
  945. | bias_c_data | float | [num_output, 1, num_directions] |
  946. | weight_hc_data| float | [num_output, num_output, num_directions] |
  947. Direction flag:
  948. - 0 = forward only
  949. - 1 = reverse only
  950. - 2 = bidirectional
  951. # scale
  952. ```
  953. if scale_data_size == -233 y = x0 * x1
  954. else y = x * scale + bias
  955. ```
  956. * one_blob_only if scale_data_size != -233
  957. * support_inplace
  958. | param id | name | type | default | description |
  959. | --------- | ------------- | ----- | --------- | ----------------- |
  960. | 0 | scale_data_size| int | 0 | |
  961. | 1 | bias_term | int | 0 | |
  962. | weight | type | shape |
  963. | ------------- | ----- | --------------------- |
  964. | scale_data | float | [scale_data_size] |
  965. | bias_data | float | [scale_data_size] |
  966. # selu
  967. ```
  968. if x < 0 y = (exp(x) - 1.f) * alpha * lambda
  969. else y = x * lambda
  970. ```
  971. * one_blob_only
  972. * support_inplace
  973. | param id | name | type | default | description |
  974. | --------- | ------------- | ----- | --------- | ----------------- |
  975. | 0 | alpha | float | 1.67326324f| |
  976. | 1 | lambda | float | 1.050700987f| |
  977. # shufflechannel
  978. ```
  979. if reverse == 0 y = shufflechannel(x) by group
  980. if reverse == 1 y = shufflechannel(x) by channel / group
  981. ```
  982. * one_blob_only
  983. | param id | name | type | default | description |
  984. | --------- | ------------- | ---- | --------- | ----------------- |
  985. | 0 | group | int | 1 | |
  986. | 1 | reverse | int | 0 | |
  987. # sigmoid
  988. ```
  989. y = 1 / (1 + exp(-x))
  990. ```
  991. * one_blob_only
  992. * support_inplace
  993. # slice
  994. ```
  995. split x along axis into slices, each part slice size is based on slices array
  996. ```
  997. | param id | name | type | default | description |
  998. | --------- | ------------- | ----- | --------- | ----------------- |
  999. | 0 | slices | array | [ ] | |
  1000. | 1 | axis | int | 0 | |
  1001. # softmax
  1002. ```
  1003. softmax(x, axis)
  1004. ```
  1005. * one_blob_only
  1006. * support_inplace
  1007. | param id | name | type | default | description |
  1008. | --------- | ------------- | ----- | --------- | ----------------- |
  1009. | 0 | axis | int | 0 | |
  1010. | 1 | fixbug0 | int | 0 | hack for bug fix, should be 1 |
  1011. # softplus
  1012. ```
  1013. y = log(exp(x) + 1)
  1014. ```
  1015. * one_blob_only
  1016. * support_inplace
  1017. # split
  1018. ```
  1019. y0, y1 ... = x
  1020. ```
  1021. # swish
  1022. ```
  1023. y = x / (1 + exp(-x))
  1024. ```
  1025. * one_blob_only
  1026. * support_inplace
  1027. # tanh
  1028. ```
  1029. y = tanh(x)
  1030. ```
  1031. * one_blob_only
  1032. * support_inplace
  1033. # threshold
  1034. ```
  1035. if x > threshold y = 1
  1036. else y = 0
  1037. ```
  1038. * one_blob_only
  1039. * support_inplace
  1040. | param id | name | type | default | description |
  1041. | --------- | ------------- | ----- | --------- | ----------------- |
  1042. | 0 | threshold | float | 0.f | |
  1043. # unaryop
  1044. ```
  1045. y = unaryop(x)
  1046. ```
  1047. - one_blob_only
  1048. - support_inplace
  1049. | param id | name | type | default | description |
  1050. | --------- | ------------- | ----- | --------- | ----------------- |
  1051. | 0 | op_type | int | 0 | Operation type as follows |
  1052. Operation type:
  1053. - 0 = ABS
  1054. - 1 = NEG
  1055. - 2 = FLOOR
  1056. - 3 = CEIL
  1057. - 4 = SQUARE
  1058. - 5 = SQRT
  1059. - 6 = RSQ
  1060. - 7 = EXP
  1061. - 8 = LOG
  1062. - 9 = SIN
  1063. - 10 = COS
  1064. - 11 = TAN
  1065. - 12 = ASIN
  1066. - 13 = ACOS
  1067. - 14 = ATAN
  1068. - 15 = RECIPROCAL
  1069. - 16 = TANH