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

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