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

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