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

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