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

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304
  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 | output_pad_right| int | 0 | |
  311. | 19 | output_pad_bottom| int | output_pad_right | |
  312. | 20 | output_w | int | 0 | |
  313. | 21 | output_h | int | output_w | |
  314. | weight | type | shape |
  315. | ------------- | ----- | --------------------- |
  316. | weight_data | float/fp16/int8 | [kernel_w, kernel_h, num_input, num_output] |
  317. | bias_data | float | [num_output] |
  318. # DeconvolutionDepthWise
  319. ```
  320. x2 = deconv(x, weight, kernel, stride, dilation, group) + bias
  321. x3 = depad(x2, pads, pad_value)
  322. y = activation(x3, act_type, act_params)
  323. ```
  324. * one_blob_only
  325. | param id | name | type | default | description |
  326. | --------- | ------------- | ----- | --------- | ----------------- |
  327. | 0 | num_output | int | 0 | |
  328. | 1 | kernel_w | int | 0 | |
  329. | 2 | dilation_w | int | 1 | |
  330. | 3 | stride_w | int | 1 | |
  331. | 4 | pad_left | int | 0 | |
  332. | 5 | bias_term | int | 0 | |
  333. | 6 | weight_data_size| int | 0 | |
  334. | 7 | group | int | 1 | |
  335. | 8 | int8_scale_term| int | 0 | |
  336. | 9 | activation_type| int | 0 | |
  337. | 10 | activation_params| array | [ ] | |
  338. | 11 | kernel_h | int | kernel_w | |
  339. | 12 | dilation_h | int | dilation_w | |
  340. | 13 | stride_h | int | stride_w | |
  341. | 15 | pad_right | int | pad_left | |
  342. | 14 | pad_top | int | pad_left | |
  343. | 16 | pad_bottom | int | pad_top | |
  344. | 18 | output_pad_right| int | 0 | |
  345. | 19 | output_pad_bottom| int | output_pad_right | |
  346. | 20 | output_w | int | 0 | |
  347. | 21 | output_h | int | output_w | |
  348. | weight | type | shape |
  349. | ------------- | ----- | --------------------- |
  350. | weight_data | float/fp16/int8 | [kernel_w, kernel_h, num_input / group, num_output / group, group] |
  351. | bias_data | float | [num_output] |
  352. # Dequantize
  353. ```
  354. y = x * scale + bias
  355. ```
  356. * one_blob_only
  357. * support_inplace
  358. | param id | name | type | default | description |
  359. | --------- | ------------- | ----- | --------- | ----------------- |
  360. | 0 | scale | float | 1.f | |
  361. | 1 | bias_term | int | 0 | |
  362. | 2 | bias_data_size| int | 0 | |
  363. # Dropout
  364. ```
  365. y = x * scale
  366. ```
  367. * one_blob_only
  368. | param id | name | type | default | description |
  369. | --------- | ------------- | ----- | --------- | ----------------- |
  370. | 0 | scale | float | 1.f | |
  371. # Eltwise
  372. ```
  373. y = elementwise_op(x0, x1, ...)
  374. ```
  375. | param id | name | type | default | description |
  376. | --------- | ------------- | ----- | --------- | ----------------- |
  377. | 0 | op_type | int | 0 | |
  378. | 1 | coeffs | array | [ ] | |
  379. Operation type:
  380. - 0 = PROD
  381. - 1 = SUM
  382. - 2 = MAX
  383. # ELU
  384. ```
  385. if x < 0 y = (exp(x) - 1) * alpha
  386. else y = x
  387. ```
  388. * one_blob_only
  389. * support_inplace
  390. | param id | name | type | default | description |
  391. | --------- | ------------- | ----- | --------- | ----------------- |
  392. | 0 | alpha | float | 0.1f | |
  393. # Exp
  394. ```
  395. if base == -1 y = exp(shift + x * scale)
  396. else y = pow(base, (shift + x * scale))
  397. ```
  398. * one_blob_only
  399. * support_inplace
  400. | param id | name | type | default | description |
  401. | --------- | ------------- | ----- | --------- | ----------------- |
  402. | 0 | base | float | -1.f | |
  403. | 1 | scale | float | 1.f | |
  404. | 2 | shift | float | 0.f | |
  405. # Flatten
  406. Reshape blob to 1 dimension
  407. * one_blob_only
  408. # GELU
  409. ```
  410. if fast_gelu == 1 y = 0.5 * x * (1 + tanh(0.79788452 * (x + 0.044715 * x * x * x)));
  411. else y = 0.5 * x * erfc(-0.70710678 * x)
  412. ```
  413. * one_blob_only
  414. * support_inplace
  415. | param id | name | type | default | description |
  416. | --------- | ------------- | ----- | --------- | ----------------- |
  417. | 0 | fast_gelu | int | 0 | use approximation |
  418. # Gemm
  419. ```
  420. a = transA ? transpose(x0) : x0
  421. b = transb ? transpose(x1) : x1
  422. c = x2
  423. y = gemm(a, b) * alpha + c * beta
  424. ```
  425. | param id | name | type | default | description |
  426. | --------- | ------------- | ----- | --------- | ----------------- |
  427. | 0 | alpha | float | 1.f | |
  428. | 1 | beta | float | 1.f | |
  429. | 2 | transA | int | 0 | |
  430. | 3 | transb | int | 0 | |
  431. # GroupNorm
  432. ```
  433. split x along channel axis into group x0, x1 ...
  434. l2 normalize for each group x0, x1 ...
  435. y = x * gamma + beta
  436. ```
  437. * one_blob_only
  438. * support_inplace
  439. | param id | name | type | default | description |
  440. | --------- | ------------- | ----- | --------- | ----------------- |
  441. | 0 | group | int | 1 | |
  442. | 1 | channels | int | 0 | |
  443. | 2 | eps | float | 0.001f | x = x / sqrt(var + eps) |
  444. | 3 | affine | int | 1 | |
  445. | weight | type | shape |
  446. | ------------- | ----- | --------------------- |
  447. | gamma_data | float | [channels] |
  448. | beta_data | float | [channels] |
  449. # GRU
  450. 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]`.
  451. ```
  452. y = gru(x)
  453. y0, hidden y1 = gru(x0, hidden x1)
  454. ```
  455. * one_blob_only if bidirectional
  456. | param id | name | type | default | description |
  457. | --------- | ------------- | ----- | --------- | ----------------- |
  458. | 0 | num_output | int | 0 | hidden size of output |
  459. | 1 | weight_data_size| int | 0 | total size of weight matrix |
  460. | 2 | direction | int | 0 | 0=forward, 1=reverse, 2=bidirectional |
  461. | weight | type | shape |
  462. | ------------- | ----- | --------------------- |
  463. | weight_xc_data| float | [input_size, num_output * 3, num_directions] |
  464. | bias_c_data | float | [num_output, 4, num_directions] |
  465. | weight_hc_data| float | [num_output, num_output * 3, num_directions] |
  466. Direction flag:
  467. - 0 = forward only
  468. - 1 = reverse only
  469. - 2 = bidirectional
  470. # HardSigmoid
  471. ```
  472. y = clamp(x * alpha + beta, 0, 1)
  473. ```
  474. * one_blob_only
  475. * support_inplace
  476. | param id | name | type | default | description |
  477. | --------- | ------------- | ----- | --------- | ----------------- |
  478. | 0 | alpha | float | 0.2f | |
  479. | 1 | beta | float | 0.5f | |
  480. # HardSwish
  481. ```
  482. y = x * clamp(x * alpha + beta, 0, 1)
  483. ```
  484. * one_blob_only
  485. * support_inplace
  486. | param id | name | type | default | description |
  487. | --------- | ------------- | ----- | --------- | ----------------- |
  488. | 0 | alpha | float | 0.2f | |
  489. | 1 | beta | float | 0.5f | |
  490. # InnerProduct
  491. ```
  492. x2 = innerproduct(x, weight) + bias
  493. y = activation(x2, act_type, act_params)
  494. ```
  495. * one_blob_only
  496. | param id | name | type | default | description |
  497. | --------- | ------------- | ----- | --------- | ----------------- |
  498. | 0 | num_output | int | 0 | |
  499. | 1 | bias_term | int | 0 | |
  500. | 2 | weight_data_size| int | 0 | |
  501. | 8 | int8_scale_term| int | 0 | |
  502. | 9 | activation_type| int | 0 | |
  503. | 10 | activation_params| array | [ ] | |
  504. | weight | type | shape |
  505. | ------------- | ----- | --------------------- |
  506. | weight_data | float/fp16/int8 | [num_input, num_output] |
  507. | bias_data | float | [num_output] |
  508. | weight_data_int8_scales| float | [num_output] |
  509. | bottom_blob_int8_scales| float | [1] |
  510. # Input
  511. ```
  512. y = input
  513. ```
  514. * support_inplace
  515. | param id | name | type | default | description |
  516. | --------- | ------------- | ----- | --------- | ----------------- |
  517. | 0 | w | int | 0 | |
  518. | 1 | h | int | 0 | |
  519. | 2 | c | int | 0 | |
  520. # InstanceNorm
  521. ```
  522. split x along channel axis into instance x0, x1 ...
  523. l2 normalize for each channel instance x0, x1 ...
  524. y = x * gamma + beta
  525. ```
  526. * one_blob_only
  527. * support_inplace
  528. | param id | name | type | default | description |
  529. | --------- | ------------- | ----- | --------- | ----------------- |
  530. | 0 | channels | int | 0 | |
  531. | 1 | eps | float | 0.001f | x = x / sqrt(var + eps) |
  532. | 2 | affine | int | 1 | |
  533. | weight | type | shape |
  534. | ------------- | ----- | --------------------- |
  535. | gamma_data | float | [channels] |
  536. | beta_data | float | [channels] |
  537. # Interp
  538. ```
  539. if dynamic_target_size == 0 y = resize(x) by fixed size or scale
  540. else y = resize(x0, size(x1))
  541. ```
  542. * one_blob_only if dynamic_target_size == 0
  543. | param id | name | type | default | description |
  544. | --------- | ------------- | ----- | --------- | ----------------- |
  545. | 0 | resize_type | int | 0 | |
  546. | 1 | height_scale | float | 1.f | |
  547. | 2 | width_scale | float | 1.f | |
  548. | 3 | output_height | int | 0 | |
  549. | 4 | output_width | int | 0 | |
  550. | 5 | dynamic_target_size| int | 0 | |
  551. | 6 | align_corner | int | 0 | |
  552. Resize type:
  553. - 1 = Nearest
  554. - 2 = Bilinear
  555. - 3 = Bicubic
  556. # LayerNorm
  557. ```
  558. split x along outmost axis into part x0, x1 ...
  559. l2 normalize for each part x0, x1 ...
  560. y = x * gamma + beta by elementwise
  561. ```
  562. * one_blob_only
  563. * support_inplace
  564. | param id | name | type | default | description |
  565. | --------- | ------------- | ----- | --------- | ----------------- |
  566. | 0 | affine_size | int | 0 | |
  567. | 1 | eps | float | 0.001f | x = x / sqrt(var + eps) |
  568. | 2 | affine | int | 1 | |
  569. | weight | type | shape |
  570. | ------------- | ----- | --------------------- |
  571. | gamma_data | float | [affine_size] |
  572. | beta_data | float | [affine_size] |
  573. # Log
  574. ```
  575. if base == -1 y = log(shift + x * scale)
  576. else y = log(shift + x * scale) / log(base)
  577. ```
  578. * one_blob_only
  579. * support_inplace
  580. | param id | name | type | default | description |
  581. | --------- | ------------- | ----- | --------- | ----------------- |
  582. | 0 | base | float | -1.f | |
  583. | 1 | scale | float | 1.f | |
  584. | 2 | shift | float | 0.f | |
  585. # LRN
  586. ```
  587. if region_type == ACROSS_CHANNELS square_sum = sum of channel window of local_size
  588. if region_type == WITHIN_CHANNEL square_sum = sum of spatial window of local_size
  589. y = x * pow(bias + alpha * square_sum / (local_size * local_size), -beta)
  590. ```
  591. * one_blob_only
  592. * support_inplace
  593. | param id | name | type | default | description |
  594. | --------- | ------------- | ----- | --------- | ----------------- |
  595. | 0 | region_type | int | 0 | |
  596. | 1 | local_size | int | 5 | |
  597. | 2 | alpha | float | 1.f | |
  598. | 3 | beta | float | 0.75f | |
  599. | 4 | bias | float | 1.f | |
  600. Region type:
  601. - 0 = ACROSS_CHANNELS
  602. - 1 = WITHIN_CHANNEL
  603. # LSTM
  604. 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]`.
  605. ```
  606. y = lstm(x)
  607. y0, hidden y1, cell y2 = lstm(x0, hidden x1, cell x2)
  608. ```
  609. * one_blob_only if bidirectional
  610. | param id | name | type | default | description |
  611. | --------- | ------------- | ----- | --------- | ----------------- |
  612. | 0 | num_output | int | 0 | hidden size of output |
  613. | 1 | weight_data_size| int | 0 | total size of IFOG weight matrix |
  614. | 2 | direction | int | 0 | 0=forward, 1=reverse, 2=bidirectional |
  615. | weight | type | shape |
  616. | ------------- | ----- | --------------------- |
  617. | weight_xc_data| float | [input_size, num_output * 4, num_directions] |
  618. | bias_c_data | float | [num_output, 4, num_directions] |
  619. | weight_hc_data| float | [num_output, num_output * 4, num_directions] |
  620. Direction flag:
  621. - 0 = forward only
  622. - 1 = reverse only
  623. - 2 = bidirectional
  624. # MemoryData
  625. ```
  626. y = data
  627. ```
  628. | param id | name | type | default | description |
  629. | --------- | ------------- | ----- | --------- | ----------------- |
  630. | 0 | w | int | 0 | |
  631. | 1 | h | int | 0 | |
  632. | 2 | c | int | 0 | |
  633. | weight | type | shape |
  634. | ------------- | ----- | --------------------- |
  635. | data | float | [w, h, c] |
  636. # Mish
  637. ```
  638. y = x * tanh(log(exp(x) + 1))
  639. ```
  640. * one_blob_only
  641. * support_inplace
  642. # MultiHeadAttention
  643. ```
  644. split q k v into num_head part q0, k0, v0, q1, k1, v1 ...
  645. for each num_head part
  646. xq = affine(q) / (embed_dim / num_head)
  647. xk = affine(k)
  648. xv = affine(v)
  649. xqk = xq * xk
  650. softmax_inplace(xqk)
  651. xqkv = xqk * xv
  652. merge xqkv to out
  653. y = affine(out)
  654. ```
  655. | param id | name | type | default | description |
  656. | --------- | ------------- | ----- | --------- | ----------------- |
  657. | 0 | embed_dim | int | 0 | |
  658. | 1 | num_head | int | 1 | |
  659. | 2 | weight_data_size| int | 0 | |
  660. | weight | type | shape |
  661. | ------------- | ----- | --------------------- |
  662. | q_weight_data | float/fp16/int8 | [weight_data_size] |
  663. | q_bias_data | float | [embed_dim] |
  664. | k_weight_data | float/fp16/int8 | [weight_data_size] |
  665. | k_bias_data | float | [embed_dim] |
  666. | v_weight_data | float/fp16/int8 | [weight_data_size] |
  667. | v_bias_data | float | [embed_dim] |
  668. | out_weight_data| float/fp16/int8 | [weight_data_size] |
  669. | out_bias_data | float | [embed_dim] |
  670. # MVN
  671. ```
  672. if normalize_variance == 1 && across_channels == 1 y = (x - mean) / (sqrt(var) + eps) of whole blob
  673. if normalize_variance == 1 && across_channels == 0 y = (x - mean) / (sqrt(var) + eps) of each channel
  674. if normalize_variance == 0 && across_channels == 1 y = x - mean of whole blob
  675. if normalize_variance == 0 && across_channels == 0 y = x - mean of each channel
  676. ```
  677. * one_blob_only
  678. | param id | name | type | default | description |
  679. | --------- | ------------- | ----- | --------- | ----------------- |
  680. | 0 | normalize_variance| int | 0 | |
  681. | 1 | across_channels| int | 0 | |
  682. | 2 | eps | float | 0.0001f | x = x / (sqrt(var) + eps) |
  683. # Noop
  684. ```
  685. y = x
  686. ```
  687. # Normalize
  688. ```
  689. if across_spatial == 1 && across_channel == 1 x2 = normalize(x) of whole blob
  690. if across_spatial == 1 && across_channel == 0 x2 = normalize(x) of each channel
  691. if across_spatial == 0 && across_channel == 1 x2 = normalize(x) of each position
  692. y = x2 * scale
  693. ```
  694. * one_blob_only
  695. * support_inplace
  696. | param id | name | type | default | description |
  697. | --------- | ------------- | ----- | --------- | ----------------- |
  698. | 0 | across_spatial| int | 0 | |
  699. | 1 | channel_shared| int | 0 | |
  700. | 2 | eps | float | 0.0001f | see eps mode |
  701. | 3 | scale_data_size| int | 0 | |
  702. | 4 | across_channel| int | 0 | |
  703. | 9 | eps_mode | int | 0 | |
  704. | weight | type | shape |
  705. | ------------- | ----- | --------------------- |
  706. | scale_data | float | [scale_data_size] |
  707. Eps Mode:
  708. - 0 = caffe/mxnet x = x / sqrt(var + eps)
  709. - 1 = pytorch x = x / max(sqrt(var), eps)
  710. - 2 = tensorflow x = x / sqrt(max(var, eps))
  711. # Packing
  712. ```
  713. y = wrap_packing(x)
  714. ```
  715. * one_blob_only
  716. | param id | name | type | default | description |
  717. | --------- | ------------- | ----- | --------- | ----------------- |
  718. | 0 | out_elempack | int | 1 | |
  719. | 1 | use_padding | int | 0 | |
  720. | 2 | cast_type_from| int | 0 | |
  721. | 3 | cast_type_to | int | 0 | |
  722. | 4 | storage_type_from| int | 0 | |
  723. | 5 | storage_type_to| int | 0 | |
  724. # Padding
  725. ```
  726. if pads != -233/-234 y = pad(x, pads)
  727. else y = pad(x0, pads param from x1)
  728. ```
  729. | param id | name | type | default | description |
  730. | --------- | ------------- | ---- | --------- | ----------------- |
  731. | 0 | top | int | 0 | |
  732. | 1 | bottom | int | 0 | |
  733. | 2 | left | int | 0 | |
  734. | 3 | right | int | 0 | |
  735. | 4 | type | int | 0 | |
  736. | 5 | value | float | 0 | |
  737. | 6 | per_channel_pad_data_size| int | 0 | |
  738. | 7 | front | int | stride_w | |
  739. | 8 | behind | int | pad_left | |
  740. | weight | type | shape |
  741. | ------------- | ----- | --------------------- |
  742. | per_channel_pad_data| float | [per_channel_pad_data_size] |
  743. Padding type:
  744. - 0 = CONSTANT
  745. - 1 = REPLICATE
  746. - 2 = REFLECT
  747. # Permute
  748. ```
  749. y = reorder(x)
  750. ```
  751. | param id | name | type | default | description |
  752. | --------- | ------------- | ---- | --------- | ----------------- |
  753. | 0 | order_type | int | 0 | |
  754. Order Type:
  755. - 0 = WH WHC
  756. - 1 = HW HWC
  757. - 2 = WCH
  758. - 3 = CWH
  759. - 4 = HCW
  760. - 5 = CHW
  761. # PixelShuffle
  762. ```
  763. if mode == 0 y = depth_to_space(x) where x channel order is sw-sh-outc
  764. if mode == 1 y = depth_to_space(x) where x channel order is outc-sw-sh
  765. ```
  766. * one_blob_only
  767. | param id | name | type | default | description |
  768. | --------- | ------------- | ---- | --------- | ----------------- |
  769. | 0 | upscale_factor| int | 1 | |
  770. | 1 | mode | int | 0 | |
  771. # Pooling
  772. ```
  773. x2 = pad(x, pads)
  774. x3 = pooling(x2, kernel, stride)
  775. ```
  776. | param id | name | type | default | description |
  777. | --------- | --------------| ---- | --------- | ----------------- |
  778. | 0 | pooling_type | int | 0 | |
  779. | 1 | kernel_w | int | 0 | |
  780. | 2 | stride_w | int | 1 | |
  781. | 3 | pad_left | int | 0 | |
  782. | 4 | global_pooling| int | 0 | |
  783. | 5 | pad_mode | int | 0 | |
  784. | 6 | avgpool_count_include_pad| int | 0 | |
  785. | 7 | adaptive_pooling| int | 0 | |
  786. | 8 | out_w | int | 0 | |
  787. | 11 | kernel_h | int | kernel_w | |
  788. | 12 | stride_h | int | stride_w | |
  789. | 13 | pad_top | int | pad_left | |
  790. | 14 | pad_right | int | pad_left | |
  791. | 15 | pad_bottom | int | pad_top | |
  792. | 18 | out_h | int | 0 | |
  793. Pooling type:
  794. - 0 = MAX
  795. - 1 = AVG
  796. Pad mode:
  797. - 0 = full padding
  798. - 1 = valid padding
  799. - 2 = tensorflow padding=SAME or onnx padding=SAME_UPPER
  800. - 3 = onnx padding=SAME_LOWER
  801. # Pooling1D
  802. ```
  803. x2 = pad(x, pads)
  804. x3 = pooling1d(x2, kernel, stride)
  805. ```
  806. | param id | name | type | default | description |
  807. | --------- | --------------| ---- | --------- | ----------------- |
  808. | 0 | pooling_type | int | 0 | |
  809. | 1 | kernel_w | int | 0 | |
  810. | 2 | stride_w | int | 1 | |
  811. | 3 | pad_left | int | 0 | |
  812. | 4 | global_pooling| int | 0 | |
  813. | 5 | pad_mode | int | 0 | |
  814. | 6 | avgpool_count_include_pad| int | 0 | |
  815. | 7 | adaptive_pooling| int | 0 | |
  816. | 8 | out_w | int | 0 | |
  817. | 14 | pad_right | int | pad_left | |
  818. Pooling type:
  819. - 0 = MAX
  820. - 1 = AVG
  821. Pad mode:
  822. - 0 = full padding
  823. - 1 = valid padding
  824. - 2 = tensorflow padding=SAME or onnx padding=SAME_UPPER
  825. - 3 = onnx padding=SAME_LOWER
  826. # Power
  827. ```
  828. y = pow((shift + x * scale), power)
  829. ```
  830. * one_blob_only
  831. * support_inplace
  832. | param id | name | type | default | description |
  833. | --------- | ------------- | ----- | --------- | ----------------- |
  834. | 0 | power | float | 1.f | |
  835. | 1 | scale | float | 1.f | |
  836. | 2 | shift | float | 0.f | |
  837. # PReLU
  838. ```
  839. if x < 0 y = x * slope
  840. else y = x
  841. ```
  842. * one_blob_only
  843. * support_inplace
  844. | param id | name | type | default | description |
  845. | --------- | ------------- | ----- | --------- | ----------------- |
  846. | 0 | num_slope | int | 0 | |
  847. | weight | type | shape |
  848. | ------------- | ----- | --------------------- |
  849. | slope_data | float | [num_slope] |
  850. # Quantize
  851. ```
  852. y = float2int8(x * scale)
  853. ```
  854. * one_blob_only
  855. | param id | name | type | default | description |
  856. | --------- | ------------- | ----- | --------- | ----------------- |
  857. | 0 | scale_data_size| int | 0 | |
  858. | weight | type | shape |
  859. | ------------- | ----- | --------------------- |
  860. | scale_data | float | [scale_data_size] |
  861. # Reduction
  862. ```
  863. y = reduce_op(x * coeff)
  864. ```
  865. * one_blob_only
  866. | param id | name | type | default | description |
  867. | --------- | ------------- | ----- | --------- | ----------------- |
  868. | 0 | operation | int | 0 | |
  869. | 1 | reduce_all | int | 1 | |
  870. | 2 | coeff | float | 1.f | |
  871. | 3 | axes | array | [ ] | |
  872. | 4 | keepdims | int | 0 | |
  873. Operation type:
  874. - 0 = SUM
  875. - 1 = ASUM
  876. - 2 = SUMSQ
  877. - 3 = MEAN
  878. - 4 = MAX
  879. - 5 = MIN
  880. - 6 = PROD
  881. - 7 = L1
  882. - 8 = L2
  883. - 9 = LogSum
  884. - 10 = LogSumExp
  885. # ReLU
  886. ```
  887. if x < 0 y = x * slope
  888. else y = x
  889. ```
  890. * one_blob_only
  891. * support_inplace
  892. | param id | name | type | default | description |
  893. | --------- | ------------- | ----- | --------- | ----------------- |
  894. | 0 | slope | float | 0.f | |
  895. # Reorg
  896. ```
  897. if mode == 0 y = space_to_depth(x) where x channel order is sw-sh-outc
  898. if mode == 1 y = space_to_depth(x) where x channel order is outc-sw-sh
  899. ```
  900. * one_blob_only
  901. | param id | name | type | default | description |
  902. | --------- | ------------- | ---- | --------- | ----------------- |
  903. | 0 | stride | int | 1 | |
  904. | 1 | mode | int | 0 | |
  905. # Requantize
  906. ```
  907. x2 = x * scale_in + bias
  908. x3 = activation(x2)
  909. y = float2int8(x3 * scale_out)
  910. ```
  911. * one_blob_only
  912. | param id | name | type | default | description |
  913. | --------- | ------------- | ----- | --------- | ----------------- |
  914. | 0 | scale_in_data_size| int | 1 | |
  915. | 1 | scale_out_data_size| int | 1 | |
  916. | 2 | bias_data_size| int | 0 | |
  917. | 3 | activation_type| int | 0 | |
  918. | 4 | activation_params| int | [ ] | |
  919. | weight | type | shape |
  920. | ------------- | ----- | --------------------- |
  921. | scale_in_data | float | [scale_in_data_size] |
  922. | scale_out_data| float | [scale_out_data_size] |
  923. | bias_data | float | [bias_data_size] |
  924. # Reshape
  925. ```
  926. if permute == 1 y = hwc2chw(reshape(chw2hwc(x)))
  927. else y = reshape(x)
  928. ```
  929. * one_blob_only
  930. | param id | name | type | default | description |
  931. | --------- | ------------- | ----- | --------- | ----------------- |
  932. | 0 | w | int | -233 | |
  933. | 1 | h | int | -233 | |
  934. | 2 | c | int | -233 | |
  935. | 3 | permute | int | 0 | |
  936. Reshape flag:
  937. - 0 = copy from bottom
  938. - -1 = remaining
  939. - -233 = drop this dim(default)
  940. # RNN
  941. 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]`.
  942. ```
  943. y = rnn(x)
  944. y0, hidden y1 = rnn(x0, hidden x1)
  945. ```
  946. * one_blob_only if bidirectional
  947. | param id | name | type | default | description |
  948. | --------- | ------------- | ----- | --------- | ----------------- |
  949. | 0 | num_output | int | 0 | hidden size of output |
  950. | 1 | weight_data_size| int | 0 | total size of weight matrix |
  951. | 2 | direction | int | 0 | 0=forward, 1=reverse, 2=bidirectional |
  952. | weight | type | shape |
  953. | ------------- | ----- | --------------------- |
  954. | weight_xc_data| float | [input_size, num_output, num_directions] |
  955. | bias_c_data | float | [num_output, 1, num_directions] |
  956. | weight_hc_data| float | [num_output, num_output, num_directions] |
  957. Direction flag:
  958. - 0 = forward only
  959. - 1 = reverse only
  960. - 2 = bidirectional
  961. # Scale
  962. ```
  963. if scale_data_size == -233 y = x0 * x1
  964. else y = x * scale + bias
  965. ```
  966. * one_blob_only if scale_data_size != -233
  967. * support_inplace
  968. | param id | name | type | default | description |
  969. | --------- | ------------- | ----- | --------- | ----------------- |
  970. | 0 | scale_data_size| int | 0 | |
  971. | 1 | bias_term | int | 0 | |
  972. | weight | type | shape |
  973. | ------------- | ----- | --------------------- |
  974. | scale_data | float | [scale_data_size] |
  975. | bias_data | float | [scale_data_size] |
  976. # SELU
  977. ```
  978. if x < 0 y = (exp(x) - 1.f) * alpha * lambda
  979. else y = x * lambda
  980. ```
  981. * one_blob_only
  982. * support_inplace
  983. | param id | name | type | default | description |
  984. | --------- | ------------- | ----- | --------- | ----------------- |
  985. | 0 | alpha | float | 1.67326324f| |
  986. | 1 | lambda | float | 1.050700987f| |
  987. # ShuffleChannel
  988. ```
  989. if reverse == 0 y = shufflechannel(x) by group
  990. if reverse == 1 y = shufflechannel(x) by channel / group
  991. ```
  992. * one_blob_only
  993. | param id | name | type | default | description |
  994. | --------- | ------------- | ---- | --------- | ----------------- |
  995. | 0 | group | int | 1 | |
  996. | 1 | reverse | int | 0 | |
  997. # Sigmoid
  998. ```
  999. y = 1 / (1 + exp(-x))
  1000. ```
  1001. * one_blob_only
  1002. * support_inplace
  1003. # Slice
  1004. ```
  1005. split x along axis into slices, each part slice size is based on slices array
  1006. ```
  1007. | param id | name | type | default | description |
  1008. | --------- | ------------- | ----- | --------- | ----------------- |
  1009. | 0 | slices | array | [ ] | |
  1010. | 1 | axis | int | 0 | |
  1011. # Softmax
  1012. ```
  1013. softmax(x, axis)
  1014. ```
  1015. * one_blob_only
  1016. * support_inplace
  1017. | param id | name | type | default | description |
  1018. | --------- | ------------- | ----- | --------- | ----------------- |
  1019. | 0 | axis | int | 0 | |
  1020. | 1 | fixbug0 | int | 0 | hack for bug fix, should be 1 |
  1021. # Softplus
  1022. ```
  1023. y = log(exp(x) + 1)
  1024. ```
  1025. * one_blob_only
  1026. * support_inplace
  1027. # Split
  1028. ```
  1029. y0, y1 ... = x
  1030. ```
  1031. # Swish
  1032. ```
  1033. y = x / (1 + exp(-x))
  1034. ```
  1035. * one_blob_only
  1036. * support_inplace
  1037. # TanH
  1038. ```
  1039. y = tanh(x)
  1040. ```
  1041. * one_blob_only
  1042. * support_inplace
  1043. # Threshold
  1044. ```
  1045. if x > threshold y = 1
  1046. else y = 0
  1047. ```
  1048. * one_blob_only
  1049. * support_inplace
  1050. | param id | name | type | default | description |
  1051. | --------- | ------------- | ----- | --------- | ----------------- |
  1052. | 0 | threshold | float | 0.f | |
  1053. # UnaryOp
  1054. ```
  1055. y = unaryop(x)
  1056. ```
  1057. - one_blob_only
  1058. - support_inplace
  1059. | param id | name | type | default | description |
  1060. | --------- | ------------- | ----- | --------- | ----------------- |
  1061. | 0 | op_type | int | 0 | Operation type as follows |
  1062. Operation type:
  1063. - 0 = ABS
  1064. - 1 = NEG
  1065. - 2 = FLOOR
  1066. - 3 = CEIL
  1067. - 4 = SQUARE
  1068. - 5 = SQRT
  1069. - 6 = RSQ
  1070. - 7 = EXP
  1071. - 8 = LOG
  1072. - 9 = SIN
  1073. - 10 = COS
  1074. - 11 = TAN
  1075. - 12 = ASIN
  1076. - 13 = ACOS
  1077. - 14 = ATAN
  1078. - 15 = RECIPROCAL
  1079. - 16 = TANH