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

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