onnx 1.16.1__cp38-cp38-win32.whl → 1.17.0__cp38-cp38-win32.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of onnx might be problematic. Click here for more details.

Files changed (843) hide show
  1. onnx/__init__.py +3 -1
  2. onnx/_custom_element_types.py +63 -0
  3. onnx/backend/base.py +17 -15
  4. onnx/backend/sample/ops/__init__.py +4 -4
  5. onnx/backend/sample/ops/abs.py +1 -0
  6. onnx/backend/test/__init__.py +1 -0
  7. onnx/backend/test/case/__init__.py +2 -2
  8. onnx/backend/test/case/base.py +6 -5
  9. onnx/backend/test/case/model/__init__.py +4 -3
  10. onnx/backend/test/case/model/expand.py +1 -0
  11. onnx/backend/test/case/model/gradient.py +1 -0
  12. onnx/backend/test/case/model/sequence.py +3 -1
  13. onnx/backend/test/case/model/shrink.py +1 -0
  14. onnx/backend/test/case/model/sign.py +1 -0
  15. onnx/backend/test/case/model/single-relu.py +1 -0
  16. onnx/backend/test/case/model/stringnormalizer.py +1 -1
  17. onnx/backend/test/case/node/__init__.py +31 -22
  18. onnx/backend/test/case/node/_image_decoder_data.py +1 -0
  19. onnx/backend/test/case/node/abs.py +1 -0
  20. onnx/backend/test/case/node/acos.py +1 -0
  21. onnx/backend/test/case/node/acosh.py +1 -0
  22. onnx/backend/test/case/node/adagrad.py +2 -1
  23. onnx/backend/test/case/node/adam.py +4 -1
  24. onnx/backend/test/case/node/add.py +1 -0
  25. onnx/backend/test/case/node/affinegrid.py +1 -0
  26. onnx/backend/test/case/node/ai_onnx_ml/array_feature_extractor.py +1 -0
  27. onnx/backend/test/case/node/ai_onnx_ml/binarizer.py +1 -0
  28. onnx/backend/test/case/node/ai_onnx_ml/label_encoder.py +1 -0
  29. onnx/backend/test/case/node/ai_onnx_ml/tree_ensemble.py +1 -0
  30. onnx/backend/test/case/node/and.py +1 -0
  31. onnx/backend/test/case/node/argmax.py +1 -0
  32. onnx/backend/test/case/node/argmin.py +1 -0
  33. onnx/backend/test/case/node/asin.py +1 -0
  34. onnx/backend/test/case/node/asinh.py +1 -0
  35. onnx/backend/test/case/node/atan.py +1 -0
  36. onnx/backend/test/case/node/atanh.py +1 -0
  37. onnx/backend/test/case/node/averagepool.py +1 -0
  38. onnx/backend/test/case/node/batchnorm.py +1 -0
  39. onnx/backend/test/case/node/bernoulli.py +1 -0
  40. onnx/backend/test/case/node/bitshift.py +1 -0
  41. onnx/backend/test/case/node/bitwiseand.py +1 -0
  42. onnx/backend/test/case/node/bitwisenot.py +1 -0
  43. onnx/backend/test/case/node/bitwiseor.py +1 -0
  44. onnx/backend/test/case/node/bitwisexor.py +1 -0
  45. onnx/backend/test/case/node/blackmanwindow.py +13 -3
  46. onnx/backend/test/case/node/cast.py +2 -1
  47. onnx/backend/test/case/node/castlike.py +1 -0
  48. onnx/backend/test/case/node/ceil.py +1 -0
  49. onnx/backend/test/case/node/celu.py +1 -0
  50. onnx/backend/test/case/node/center_crop_pad.py +1 -0
  51. onnx/backend/test/case/node/clip.py +1 -0
  52. onnx/backend/test/case/node/col2im.py +1 -1
  53. onnx/backend/test/case/node/compress.py +1 -0
  54. onnx/backend/test/case/node/concat.py +3 -2
  55. onnx/backend/test/case/node/constant.py +1 -0
  56. onnx/backend/test/case/node/constantofshape.py +1 -0
  57. onnx/backend/test/case/node/conv.py +1 -0
  58. onnx/backend/test/case/node/convinteger.py +1 -0
  59. onnx/backend/test/case/node/convtranspose.py +135 -0
  60. onnx/backend/test/case/node/cos.py +1 -0
  61. onnx/backend/test/case/node/cosh.py +1 -0
  62. onnx/backend/test/case/node/cumsum.py +1 -0
  63. onnx/backend/test/case/node/deformconv.py +17 -26
  64. onnx/backend/test/case/node/depthtospace.py +1 -0
  65. onnx/backend/test/case/node/dequantizelinear.py +1 -0
  66. onnx/backend/test/case/node/det.py +1 -0
  67. onnx/backend/test/case/node/dft.py +1 -0
  68. onnx/backend/test/case/node/div.py +1 -0
  69. onnx/backend/test/case/node/dropout.py +1 -0
  70. onnx/backend/test/case/node/dynamicquantizelinear.py +1 -0
  71. onnx/backend/test/case/node/einsum.py +2 -3
  72. onnx/backend/test/case/node/elu.py +1 -0
  73. onnx/backend/test/case/node/equal.py +1 -0
  74. onnx/backend/test/case/node/erf.py +1 -0
  75. onnx/backend/test/case/node/exp.py +1 -0
  76. onnx/backend/test/case/node/expand.py +1 -0
  77. onnx/backend/test/case/node/eyelike.py +1 -0
  78. onnx/backend/test/case/node/flatten.py +1 -0
  79. onnx/backend/test/case/node/floor.py +1 -0
  80. onnx/backend/test/case/node/gather.py +1 -0
  81. onnx/backend/test/case/node/gatherelements.py +1 -0
  82. onnx/backend/test/case/node/gathernd.py +1 -0
  83. onnx/backend/test/case/node/gelu.py +1 -0
  84. onnx/backend/test/case/node/gemm.py +3 -4
  85. onnx/backend/test/case/node/globalaveragepool.py +1 -0
  86. onnx/backend/test/case/node/globalmaxpool.py +1 -0
  87. onnx/backend/test/case/node/greater.py +1 -0
  88. onnx/backend/test/case/node/greater_equal.py +1 -0
  89. onnx/backend/test/case/node/gridsample.py +1 -0
  90. onnx/backend/test/case/node/groupnormalization.py +1 -0
  91. onnx/backend/test/case/node/gru.py +3 -2
  92. onnx/backend/test/case/node/hammingwindow.py +13 -2
  93. onnx/backend/test/case/node/hannwindow.py +10 -2
  94. onnx/backend/test/case/node/hardmax.py +1 -0
  95. onnx/backend/test/case/node/hardsigmoid.py +1 -0
  96. onnx/backend/test/case/node/hardswish.py +1 -0
  97. onnx/backend/test/case/node/identity.py +1 -0
  98. onnx/backend/test/case/node/if.py +1 -0
  99. onnx/backend/test/case/node/instancenorm.py +1 -0
  100. onnx/backend/test/case/node/isinf.py +1 -0
  101. onnx/backend/test/case/node/isnan.py +1 -0
  102. onnx/backend/test/case/node/layernormalization.py +1 -0
  103. onnx/backend/test/case/node/leakyrelu.py +1 -0
  104. onnx/backend/test/case/node/less.py +1 -0
  105. onnx/backend/test/case/node/less_equal.py +1 -0
  106. onnx/backend/test/case/node/log.py +1 -0
  107. onnx/backend/test/case/node/logsoftmax.py +1 -0
  108. onnx/backend/test/case/node/loop.py +4 -3
  109. onnx/backend/test/case/node/lppool.py +1 -0
  110. onnx/backend/test/case/node/lrn.py +1 -0
  111. onnx/backend/test/case/node/lstm.py +3 -2
  112. onnx/backend/test/case/node/matmul.py +1 -0
  113. onnx/backend/test/case/node/matmulinteger.py +1 -0
  114. onnx/backend/test/case/node/max.py +1 -0
  115. onnx/backend/test/case/node/maxpool.py +1 -0
  116. onnx/backend/test/case/node/maxunpool.py +1 -0
  117. onnx/backend/test/case/node/mean.py +1 -0
  118. onnx/backend/test/case/node/meanvariancenormalization.py +1 -0
  119. onnx/backend/test/case/node/melweightmatrix.py +1 -0
  120. onnx/backend/test/case/node/min.py +1 -0
  121. onnx/backend/test/case/node/mish.py +1 -0
  122. onnx/backend/test/case/node/mod.py +1 -0
  123. onnx/backend/test/case/node/momentum.py +1 -0
  124. onnx/backend/test/case/node/mul.py +1 -0
  125. onnx/backend/test/case/node/neg.py +1 -0
  126. onnx/backend/test/case/node/negativeloglikelihoodloss.py +4 -1
  127. onnx/backend/test/case/node/nonmaxsuppression.py +1 -0
  128. onnx/backend/test/case/node/nonzero.py +1 -0
  129. onnx/backend/test/case/node/not.py +1 -0
  130. onnx/backend/test/case/node/onehot.py +1 -0
  131. onnx/backend/test/case/node/optionalgetelement.py +3 -2
  132. onnx/backend/test/case/node/optionalhaselement.py +2 -3
  133. onnx/backend/test/case/node/or.py +1 -0
  134. onnx/backend/test/case/node/pad.py +2 -1
  135. onnx/backend/test/case/node/pow.py +1 -0
  136. onnx/backend/test/case/node/prelu.py +1 -0
  137. onnx/backend/test/case/node/qlinearconv.py +1 -0
  138. onnx/backend/test/case/node/qlinearmatmul.py +1 -0
  139. onnx/backend/test/case/node/quantizelinear.py +1 -0
  140. onnx/backend/test/case/node/rangeop.py +1 -0
  141. onnx/backend/test/case/node/reciprocal.py +1 -0
  142. onnx/backend/test/case/node/reduce_log_sum.py +1 -0
  143. onnx/backend/test/case/node/reduce_log_sum_exp.py +1 -0
  144. onnx/backend/test/case/node/reducel1.py +1 -0
  145. onnx/backend/test/case/node/reducel2.py +1 -0
  146. onnx/backend/test/case/node/reducemax.py +2 -1
  147. onnx/backend/test/case/node/reducemean.py +1 -0
  148. onnx/backend/test/case/node/reducemin.py +1 -0
  149. onnx/backend/test/case/node/reduceprod.py +1 -0
  150. onnx/backend/test/case/node/reducesum.py +2 -1
  151. onnx/backend/test/case/node/reducesumsquare.py +1 -0
  152. onnx/backend/test/case/node/regex_full_match.py +1 -0
  153. onnx/backend/test/case/node/relu.py +1 -0
  154. onnx/backend/test/case/node/reshape.py +1 -0
  155. onnx/backend/test/case/node/resize.py +3 -2
  156. onnx/backend/test/case/node/reversesequence.py +1 -0
  157. onnx/backend/test/case/node/rnn.py +3 -2
  158. onnx/backend/test/case/node/roialign.py +1 -0
  159. onnx/backend/test/case/node/round.py +4 -3
  160. onnx/backend/test/case/node/scan.py +1 -0
  161. onnx/backend/test/case/node/scatter.py +1 -0
  162. onnx/backend/test/case/node/scatterelements.py +7 -3
  163. onnx/backend/test/case/node/scatternd.py +1 -0
  164. onnx/backend/test/case/node/selu.py +1 -0
  165. onnx/backend/test/case/node/sequence_map.py +1 -0
  166. onnx/backend/test/case/node/sequenceinsert.py +4 -3
  167. onnx/backend/test/case/node/shape.py +1 -0
  168. onnx/backend/test/case/node/shrink.py +1 -0
  169. onnx/backend/test/case/node/sigmoid.py +1 -0
  170. onnx/backend/test/case/node/sign.py +1 -0
  171. onnx/backend/test/case/node/sin.py +1 -0
  172. onnx/backend/test/case/node/sinh.py +1 -0
  173. onnx/backend/test/case/node/size.py +1 -0
  174. onnx/backend/test/case/node/slice.py +1 -0
  175. onnx/backend/test/case/node/softmax.py +1 -0
  176. onnx/backend/test/case/node/softmaxcrossentropy.py +4 -1
  177. onnx/backend/test/case/node/softplus.py +1 -0
  178. onnx/backend/test/case/node/softsign.py +1 -0
  179. onnx/backend/test/case/node/spacetodepth.py +1 -0
  180. onnx/backend/test/case/node/split.py +1 -0
  181. onnx/backend/test/case/node/splittosequence.py +1 -0
  182. onnx/backend/test/case/node/sqrt.py +1 -0
  183. onnx/backend/test/case/node/squeeze.py +1 -0
  184. onnx/backend/test/case/node/stft.py +4 -1
  185. onnx/backend/test/case/node/string_concat.py +1 -0
  186. onnx/backend/test/case/node/string_split.py +1 -0
  187. onnx/backend/test/case/node/stringnormalizer.py +1 -0
  188. onnx/backend/test/case/node/sub.py +1 -0
  189. onnx/backend/test/case/node/sum.py +1 -0
  190. onnx/backend/test/case/node/tan.py +1 -0
  191. onnx/backend/test/case/node/tanh.py +1 -0
  192. onnx/backend/test/case/node/tfidfvectorizer.py +1 -0
  193. onnx/backend/test/case/node/thresholdedrelu.py +1 -0
  194. onnx/backend/test/case/node/tile.py +1 -0
  195. onnx/backend/test/case/node/topk.py +1 -0
  196. onnx/backend/test/case/node/transpose.py +1 -0
  197. onnx/backend/test/case/node/trilu.py +1 -0
  198. onnx/backend/test/case/node/unique.py +7 -0
  199. onnx/backend/test/case/node/unsqueeze.py +1 -0
  200. onnx/backend/test/case/node/upsample.py +1 -0
  201. onnx/backend/test/case/node/where.py +1 -0
  202. onnx/backend/test/case/node/xor.py +1 -0
  203. onnx/backend/test/case/test_case.py +6 -5
  204. onnx/backend/test/case/utils.py +2 -2
  205. onnx/backend/test/cmd_tools.py +1 -0
  206. onnx/backend/test/data/node/test_acos/model.onnx +0 -0
  207. onnx/backend/test/data/node/test_acos/test_data_set_0/output_0.pb +0 -0
  208. onnx/backend/test/data/node/test_acos_example/model.onnx +0 -0
  209. onnx/backend/test/data/node/test_acosh/model.onnx +0 -0
  210. onnx/backend/test/data/node/test_acosh/test_data_set_0/output_0.pb +1 -1
  211. onnx/backend/test/data/node/test_acosh_example/model.onnx +0 -0
  212. onnx/backend/test/data/node/test_asin/model.onnx +0 -0
  213. onnx/backend/test/data/node/test_asin/test_data_set_0/output_0.pb +1 -1
  214. onnx/backend/test/data/node/test_asin_example/model.onnx +0 -0
  215. onnx/backend/test/data/node/test_asinh/model.onnx +0 -0
  216. onnx/backend/test/data/node/test_asinh/test_data_set_0/output_0.pb +1 -1
  217. onnx/backend/test/data/node/test_asinh_example/model.onnx +0 -0
  218. onnx/backend/test/data/node/test_atan/model.onnx +0 -0
  219. onnx/backend/test/data/node/test_atan/test_data_set_0/output_0.pb +1 -1
  220. onnx/backend/test/data/node/test_atan_example/model.onnx +0 -0
  221. onnx/backend/test/data/node/test_atanh/model.onnx +0 -0
  222. onnx/backend/test/data/node/test_atanh/test_data_set_0/output_0.pb +2 -2
  223. onnx/backend/test/data/node/test_atanh_example/model.onnx +0 -0
  224. onnx/backend/test/data/node/test_averagepool_1d_default/model.onnx +0 -0
  225. onnx/backend/test/data/node/test_averagepool_2d_ceil/model.onnx +0 -0
  226. onnx/backend/test/data/node/test_averagepool_2d_default/model.onnx +0 -0
  227. onnx/backend/test/data/node/test_averagepool_2d_dilations/model.onnx +0 -0
  228. onnx/backend/test/data/node/test_averagepool_2d_pads/model.onnx +0 -0
  229. onnx/backend/test/data/node/test_averagepool_2d_pads_count_include_pad/model.onnx +0 -0
  230. onnx/backend/test/data/node/test_averagepool_2d_precomputed_pads/model.onnx +0 -0
  231. onnx/backend/test/data/node/test_averagepool_2d_precomputed_pads_count_include_pad/model.onnx +0 -0
  232. onnx/backend/test/data/node/test_averagepool_2d_precomputed_same_upper/model.onnx +0 -0
  233. onnx/backend/test/data/node/test_averagepool_2d_precomputed_strides/model.onnx +0 -0
  234. onnx/backend/test/data/node/test_averagepool_2d_same_lower/model.onnx +0 -0
  235. onnx/backend/test/data/node/test_averagepool_2d_same_upper/model.onnx +0 -0
  236. onnx/backend/test/data/node/test_averagepool_2d_strides/model.onnx +0 -0
  237. onnx/backend/test/data/node/test_averagepool_3d_default/model.onnx +0 -0
  238. onnx/backend/test/data/node/test_averagepool_3d_dilations_large_count_include_pad_is_0_ceil_mode_is_False/model.onnx +0 -0
  239. onnx/backend/test/data/node/test_averagepool_3d_dilations_large_count_include_pad_is_0_ceil_mode_is_True/model.onnx +0 -0
  240. onnx/backend/test/data/node/test_averagepool_3d_dilations_large_count_include_pad_is_1_ceil_mode_is_False/model.onnx +0 -0
  241. onnx/backend/test/data/node/test_averagepool_3d_dilations_large_count_include_pad_is_1_ceil_mode_is_True/model.onnx +0 -0
  242. onnx/backend/test/data/node/test_averagepool_3d_dilations_small/model.onnx +0 -0
  243. onnx/backend/test/data/node/test_basic_conv_with_padding/model.onnx +0 -0
  244. onnx/backend/test/data/node/test_basic_conv_without_padding/model.onnx +0 -0
  245. onnx/backend/test/data/node/test_basic_deform_conv_with_padding/model.onnx +0 -0
  246. onnx/backend/test/data/node/test_basic_deform_conv_without_padding/model.onnx +0 -0
  247. onnx/backend/test/data/node/test_bernoulli/model.onnx +0 -0
  248. onnx/backend/test/data/node/test_bernoulli_double/model.onnx +0 -0
  249. onnx/backend/test/data/node/test_bernoulli_double_expanded/model.onnx +0 -0
  250. onnx/backend/test/data/node/test_bernoulli_expanded/model.onnx +0 -0
  251. onnx/backend/test/data/node/test_bernoulli_seed/model.onnx +0 -0
  252. onnx/backend/test/data/node/test_bernoulli_seed_expanded/model.onnx +0 -0
  253. onnx/backend/test/data/node/test_blackmanwindow/test_data_set_0/output_0.pb +0 -0
  254. onnx/backend/test/data/node/test_blackmanwindow_expanded/test_data_set_0/output_0.pb +0 -0
  255. onnx/backend/test/data/node/test_blackmanwindow_symmetric/test_data_set_0/output_0.pb +0 -0
  256. onnx/backend/test/data/node/test_blackmanwindow_symmetric_expanded/test_data_set_0/output_0.pb +0 -0
  257. onnx/backend/test/data/node/test_cast_FLOAT16_to_INT4/test_data_set_0/output_0.pb +1 -1
  258. onnx/backend/test/data/node/test_cast_FLOAT_to_INT4/test_data_set_0/output_0.pb +1 -1
  259. onnx/backend/test/data/node/test_cast_INT4_to_FLOAT/test_data_set_0/input_0.pb +1 -1
  260. onnx/backend/test/data/node/test_cast_INT4_to_FLOAT16/test_data_set_0/input_0.pb +1 -1
  261. onnx/backend/test/data/node/test_cast_INT4_to_INT8/test_data_set_0/input_0.pb +1 -1
  262. onnx/backend/test/data/node/test_conv_with_autopad_same/model.onnx +0 -0
  263. onnx/backend/test/data/node/test_conv_with_strides_and_asymmetric_padding/model.onnx +0 -0
  264. onnx/backend/test/data/node/test_conv_with_strides_no_padding/model.onnx +0 -0
  265. onnx/backend/test/data/node/test_conv_with_strides_padding/model.onnx +0 -0
  266. onnx/backend/test/data/node/test_convtranspose/model.onnx +0 -0
  267. onnx/backend/test/data/node/test_convtranspose_1d/model.onnx +0 -0
  268. onnx/backend/test/data/node/test_convtranspose_3d/model.onnx +0 -0
  269. onnx/backend/test/data/node/test_convtranspose_autopad_same/model.onnx +0 -0
  270. onnx/backend/test/data/node/test_convtranspose_dilations/model.onnx +0 -0
  271. onnx/backend/test/data/node/test_convtranspose_group_2/model.onnx +0 -0
  272. onnx/backend/test/data/node/test_convtranspose_group_2/test_data_set_0/input_0.pb +0 -0
  273. onnx/backend/test/data/node/test_convtranspose_group_2/test_data_set_0/input_1.pb +0 -0
  274. onnx/backend/test/data/node/test_convtranspose_group_2/test_data_set_0/output_0.pb +0 -0
  275. onnx/backend/test/data/node/test_convtranspose_group_2_image_3/model.onnx +0 -0
  276. onnx/backend/test/data/node/test_convtranspose_group_2_image_3/test_data_set_0/input_0.pb +0 -0
  277. onnx/backend/test/data/node/test_convtranspose_group_2_image_3/test_data_set_0/input_1.pb +0 -0
  278. onnx/backend/test/data/node/test_convtranspose_group_2_image_3/test_data_set_0/output_0.pb +0 -0
  279. onnx/backend/test/data/node/test_convtranspose_kernel_shape/model.onnx +0 -0
  280. onnx/backend/test/data/node/test_convtranspose_output_shape/model.onnx +0 -0
  281. onnx/backend/test/data/node/test_convtranspose_pad/model.onnx +0 -0
  282. onnx/backend/test/data/node/test_convtranspose_pads/model.onnx +0 -0
  283. onnx/backend/test/data/node/test_cos/model.onnx +0 -0
  284. onnx/backend/test/data/node/test_cos_example/model.onnx +0 -0
  285. onnx/backend/test/data/node/test_cosh/model.onnx +0 -0
  286. onnx/backend/test/data/node/test_cosh/test_data_set_0/output_0.pb +1 -1
  287. onnx/backend/test/data/node/test_cosh_example/model.onnx +0 -0
  288. onnx/backend/test/data/node/test_cosh_example/test_data_set_0/output_0.pb +0 -0
  289. onnx/backend/test/data/node/test_deform_conv_with_mask_bias/model.onnx +0 -0
  290. onnx/backend/test/data/node/test_deform_conv_with_multiple_offset_groups/model.onnx +0 -0
  291. onnx/backend/test/data/node/test_dequantizelinear_int4/test_data_set_0/input_0.pb +1 -1
  292. onnx/backend/test/data/node/test_det_2d/model.onnx +0 -0
  293. onnx/backend/test/data/node/test_det_nd/model.onnx +0 -0
  294. onnx/backend/test/data/node/test_dft/test_data_set_0/output_0.pb +0 -0
  295. onnx/backend/test/data/node/test_dft_axis/test_data_set_0/output_0.pb +0 -0
  296. onnx/backend/test/data/node/test_dft_axis_opset19/test_data_set_0/output_0.pb +0 -0
  297. onnx/backend/test/data/node/test_dft_inverse/test_data_set_0/output_0.pb +0 -0
  298. onnx/backend/test/data/node/test_dft_inverse_opset19/test_data_set_0/output_0.pb +0 -0
  299. onnx/backend/test/data/node/test_dft_opset19/test_data_set_0/output_0.pb +0 -0
  300. onnx/backend/test/data/node/test_dropout_default/model.onnx +0 -0
  301. onnx/backend/test/data/node/test_dropout_default_mask/model.onnx +0 -0
  302. onnx/backend/test/data/node/test_dropout_default_mask_ratio/model.onnx +0 -0
  303. onnx/backend/test/data/node/test_dropout_default_ratio/model.onnx +0 -0
  304. onnx/backend/test/data/node/test_elu/model.onnx +0 -0
  305. onnx/backend/test/data/node/test_elu_default/model.onnx +0 -0
  306. onnx/backend/test/data/node/test_elu_example/model.onnx +0 -0
  307. onnx/backend/test/data/node/test_eyelike_populate_off_main_diagonal/model.onnx +0 -0
  308. onnx/backend/test/data/node/test_eyelike_with_dtype/model.onnx +0 -0
  309. onnx/backend/test/data/node/test_eyelike_without_dtype/model.onnx +0 -0
  310. onnx/backend/test/data/node/test_gelu_default_1/test_data_set_0/output_0.pb +0 -0
  311. onnx/backend/test/data/node/test_gelu_default_1_expanded/test_data_set_0/output_0.pb +0 -0
  312. onnx/backend/test/data/node/test_gelu_default_2/test_data_set_0/output_0.pb +4 -3
  313. onnx/backend/test/data/node/test_gelu_default_2_expanded/test_data_set_0/output_0.pb +4 -3
  314. onnx/backend/test/data/node/test_gelu_tanh_2/test_data_set_0/output_0.pb +0 -0
  315. onnx/backend/test/data/node/test_gelu_tanh_2_expanded/test_data_set_0/output_0.pb +0 -0
  316. onnx/backend/test/data/node/test_globalaveragepool/model.onnx +0 -0
  317. onnx/backend/test/data/node/test_globalaveragepool_precomputed/model.onnx +0 -0
  318. onnx/backend/test/data/node/test_globalmaxpool/model.onnx +0 -0
  319. onnx/backend/test/data/node/test_globalmaxpool_precomputed/model.onnx +0 -0
  320. onnx/backend/test/data/node/test_gridsample/model.onnx +0 -0
  321. onnx/backend/test/data/node/test_gridsample_aligncorners_true/model.onnx +0 -0
  322. onnx/backend/test/data/node/test_gridsample_bicubic/model.onnx +0 -0
  323. onnx/backend/test/data/node/test_gridsample_bicubic_align_corners_0_additional_1/model.onnx +0 -0
  324. onnx/backend/test/data/node/test_gridsample_bicubic_align_corners_1_additional_1/model.onnx +0 -0
  325. onnx/backend/test/data/node/test_gridsample_bilinear/model.onnx +0 -0
  326. onnx/backend/test/data/node/test_gridsample_bilinear_align_corners_0_additional_1/model.onnx +0 -0
  327. onnx/backend/test/data/node/test_gridsample_bilinear_align_corners_1_additional_1/model.onnx +0 -0
  328. onnx/backend/test/data/node/test_gridsample_border_padding/model.onnx +0 -0
  329. onnx/backend/test/data/node/test_gridsample_nearest/model.onnx +0 -0
  330. onnx/backend/test/data/node/test_gridsample_nearest_align_corners_0_additional_1/model.onnx +0 -0
  331. onnx/backend/test/data/node/test_gridsample_nearest_align_corners_1_additional_1/model.onnx +0 -0
  332. onnx/backend/test/data/node/test_gridsample_reflection_padding/model.onnx +0 -0
  333. onnx/backend/test/data/node/test_gridsample_volumetric_bilinear_align_corners_0/model.onnx +0 -0
  334. onnx/backend/test/data/node/test_gridsample_volumetric_bilinear_align_corners_1/model.onnx +0 -0
  335. onnx/backend/test/data/node/test_gridsample_volumetric_nearest_align_corners_0/model.onnx +0 -0
  336. onnx/backend/test/data/node/test_gridsample_volumetric_nearest_align_corners_1/model.onnx +0 -0
  337. onnx/backend/test/data/node/test_gridsample_zeros_padding/model.onnx +0 -0
  338. onnx/backend/test/data/node/test_gru_batchwise/model.onnx +0 -0
  339. onnx/backend/test/data/node/test_gru_defaults/model.onnx +0 -0
  340. onnx/backend/test/data/node/test_gru_seq_length/model.onnx +0 -0
  341. onnx/backend/test/data/node/test_gru_with_initial_bias/model.onnx +0 -0
  342. onnx/backend/test/data/node/test_hammingwindow/test_data_set_0/output_0.pb +0 -0
  343. onnx/backend/test/data/node/test_hammingwindow_expanded/test_data_set_0/output_0.pb +0 -0
  344. onnx/backend/test/data/node/test_hammingwindow_symmetric/test_data_set_0/output_0.pb +1 -1
  345. onnx/backend/test/data/node/test_hammingwindow_symmetric_expanded/test_data_set_0/output_0.pb +1 -1
  346. onnx/backend/test/data/node/test_hannwindow/test_data_set_0/output_0.pb +0 -0
  347. onnx/backend/test/data/node/test_hannwindow_expanded/test_data_set_0/output_0.pb +0 -0
  348. onnx/backend/test/data/node/test_hannwindow_symmetric/test_data_set_0/output_0.pb +0 -0
  349. onnx/backend/test/data/node/test_hannwindow_symmetric_expanded/test_data_set_0/output_0.pb +0 -0
  350. onnx/backend/test/data/node/test_hardsigmoid/model.onnx +0 -0
  351. onnx/backend/test/data/node/test_hardsigmoid_default/model.onnx +0 -0
  352. onnx/backend/test/data/node/test_hardsigmoid_example/model.onnx +0 -0
  353. onnx/backend/test/data/node/test_hardswish/model.onnx +0 -0
  354. onnx/backend/test/data/node/test_hardswish_expanded/model.onnx +0 -0
  355. onnx/backend/test/data/node/test_image_decoder_decode_jpeg2k_rgb/test_data_set_0/input_0.pb +0 -0
  356. onnx/backend/test/data/node/test_instancenorm_epsilon/model.onnx +0 -0
  357. onnx/backend/test/data/node/test_instancenorm_example/model.onnx +0 -0
  358. onnx/backend/test/data/node/test_lppool_1d_default/model.onnx +0 -0
  359. onnx/backend/test/data/node/test_lppool_1d_default/test_data_set_0/output_0.pb +2 -2
  360. onnx/backend/test/data/node/test_lppool_2d_default/model.onnx +0 -0
  361. onnx/backend/test/data/node/test_lppool_2d_default/test_data_set_0/output_0.pb +0 -0
  362. onnx/backend/test/data/node/test_lppool_2d_dilations/model.onnx +0 -0
  363. onnx/backend/test/data/node/test_lppool_2d_pads/model.onnx +0 -0
  364. onnx/backend/test/data/node/test_lppool_2d_pads/test_data_set_0/output_0.pb +0 -0
  365. onnx/backend/test/data/node/test_lppool_2d_same_lower/model.onnx +0 -0
  366. onnx/backend/test/data/node/test_lppool_2d_same_lower/test_data_set_0/output_0.pb +0 -0
  367. onnx/backend/test/data/node/test_lppool_2d_same_upper/model.onnx +0 -0
  368. onnx/backend/test/data/node/test_lppool_2d_same_upper/test_data_set_0/output_0.pb +0 -0
  369. onnx/backend/test/data/node/test_lppool_2d_strides/model.onnx +0 -0
  370. onnx/backend/test/data/node/test_lppool_2d_strides/test_data_set_0/output_0.pb +0 -0
  371. onnx/backend/test/data/node/test_lppool_3d_default/model.onnx +0 -0
  372. onnx/backend/test/data/node/test_lppool_3d_default/test_data_set_0/output_0.pb +0 -0
  373. onnx/backend/test/data/node/test_lstm_batchwise/model.onnx +0 -0
  374. onnx/backend/test/data/node/test_lstm_defaults/model.onnx +0 -0
  375. onnx/backend/test/data/node/test_lstm_with_initial_bias/model.onnx +0 -0
  376. onnx/backend/test/data/node/test_lstm_with_peepholes/model.onnx +0 -0
  377. onnx/backend/test/data/node/test_maxpool_1d_default/model.onnx +0 -0
  378. onnx/backend/test/data/node/test_maxpool_2d_ceil/model.onnx +0 -0
  379. onnx/backend/test/data/node/test_maxpool_2d_ceil_output_size_reduce_by_one/model.onnx +0 -0
  380. onnx/backend/test/data/node/test_maxpool_2d_default/model.onnx +0 -0
  381. onnx/backend/test/data/node/test_maxpool_2d_dilations/model.onnx +0 -0
  382. onnx/backend/test/data/node/test_maxpool_2d_pads/model.onnx +0 -0
  383. onnx/backend/test/data/node/test_maxpool_2d_precomputed_pads/model.onnx +0 -0
  384. onnx/backend/test/data/node/test_maxpool_2d_precomputed_same_upper/model.onnx +0 -0
  385. onnx/backend/test/data/node/test_maxpool_2d_precomputed_strides/model.onnx +0 -0
  386. onnx/backend/test/data/node/test_maxpool_2d_same_lower/model.onnx +0 -0
  387. onnx/backend/test/data/node/test_maxpool_2d_same_upper/model.onnx +0 -0
  388. onnx/backend/test/data/node/test_maxpool_2d_strides/model.onnx +0 -0
  389. onnx/backend/test/data/node/test_maxpool_2d_uint8/model.onnx +0 -0
  390. onnx/backend/test/data/node/test_maxpool_3d_default/model.onnx +0 -0
  391. onnx/backend/test/data/node/test_maxpool_3d_dilations/model.onnx +0 -0
  392. onnx/backend/test/data/node/test_maxpool_3d_dilations_use_ref_impl/model.onnx +0 -0
  393. onnx/backend/test/data/node/test_maxpool_3d_dilations_use_ref_impl_large/model.onnx +0 -0
  394. onnx/backend/test/data/node/test_maxpool_with_argmax_2d_precomputed_pads/model.onnx +0 -0
  395. onnx/backend/test/data/node/test_maxpool_with_argmax_2d_precomputed_strides/model.onnx +0 -0
  396. onnx/backend/test/data/node/test_maxunpool_export_with_output_shape/model.onnx +0 -0
  397. onnx/backend/test/data/node/test_maxunpool_export_without_output_shape/model.onnx +0 -0
  398. onnx/backend/test/data/node/test_mish/model.onnx +0 -0
  399. onnx/backend/test/data/node/test_mish/test_data_set_0/output_0.pb +0 -0
  400. onnx/backend/test/data/node/test_mish_expanded/model.onnx +0 -0
  401. onnx/backend/test/data/node/test_mish_expanded/test_data_set_0/output_0.pb +0 -0
  402. onnx/backend/test/data/node/test_nllloss_NC/model.onnx +0 -0
  403. onnx/backend/test/data/node/test_nllloss_NC_expanded/model.onnx +0 -0
  404. onnx/backend/test/data/node/test_nllloss_NCd1/model.onnx +0 -0
  405. onnx/backend/test/data/node/test_nllloss_NCd1_expanded/model.onnx +0 -0
  406. onnx/backend/test/data/node/test_nllloss_NCd1_ii/model.onnx +0 -0
  407. onnx/backend/test/data/node/test_nllloss_NCd1_ii_expanded/model.onnx +0 -0
  408. onnx/backend/test/data/node/test_nllloss_NCd1_mean_weight_negative_ii/model.onnx +0 -0
  409. onnx/backend/test/data/node/test_nllloss_NCd1_mean_weight_negative_ii_expanded/model.onnx +0 -0
  410. onnx/backend/test/data/node/test_nllloss_NCd1_weight/model.onnx +0 -0
  411. onnx/backend/test/data/node/test_nllloss_NCd1_weight_expanded/model.onnx +0 -0
  412. onnx/backend/test/data/node/test_nllloss_NCd1_weight_ii/model.onnx +0 -0
  413. onnx/backend/test/data/node/test_nllloss_NCd1_weight_ii_expanded/model.onnx +0 -0
  414. onnx/backend/test/data/node/test_nllloss_NCd1d2/model.onnx +0 -0
  415. onnx/backend/test/data/node/test_nllloss_NCd1d2_expanded/model.onnx +0 -0
  416. onnx/backend/test/data/node/test_nllloss_NCd1d2_no_weight_reduction_mean_ii/model.onnx +0 -0
  417. onnx/backend/test/data/node/test_nllloss_NCd1d2_no_weight_reduction_mean_ii_expanded/model.onnx +0 -0
  418. onnx/backend/test/data/node/test_nllloss_NCd1d2_reduction_mean/model.onnx +0 -0
  419. onnx/backend/test/data/node/test_nllloss_NCd1d2_reduction_mean_expanded/model.onnx +0 -0
  420. onnx/backend/test/data/node/test_nllloss_NCd1d2_reduction_sum/model.onnx +0 -0
  421. onnx/backend/test/data/node/test_nllloss_NCd1d2_reduction_sum_expanded/model.onnx +0 -0
  422. onnx/backend/test/data/node/test_nllloss_NCd1d2_with_weight/model.onnx +0 -0
  423. onnx/backend/test/data/node/test_nllloss_NCd1d2_with_weight_expanded/model.onnx +0 -0
  424. onnx/backend/test/data/node/test_nllloss_NCd1d2_with_weight_reduction_mean/model.onnx +0 -0
  425. onnx/backend/test/data/node/test_nllloss_NCd1d2_with_weight_reduction_mean_expanded/model.onnx +0 -0
  426. onnx/backend/test/data/node/test_nllloss_NCd1d2_with_weight_reduction_sum/model.onnx +0 -0
  427. onnx/backend/test/data/node/test_nllloss_NCd1d2_with_weight_reduction_sum_expanded/model.onnx +0 -0
  428. onnx/backend/test/data/node/test_nllloss_NCd1d2_with_weight_reduction_sum_ii/model.onnx +0 -0
  429. onnx/backend/test/data/node/test_nllloss_NCd1d2_with_weight_reduction_sum_ii_expanded/model.onnx +0 -0
  430. onnx/backend/test/data/node/test_nllloss_NCd1d2d3_none_no_weight_negative_ii/model.onnx +0 -0
  431. onnx/backend/test/data/node/test_nllloss_NCd1d2d3_none_no_weight_negative_ii_expanded/model.onnx +0 -0
  432. onnx/backend/test/data/node/test_nllloss_NCd1d2d3_sum_weight_high_ii/model.onnx +0 -0
  433. onnx/backend/test/data/node/test_nllloss_NCd1d2d3_sum_weight_high_ii_expanded/model.onnx +0 -0
  434. onnx/backend/test/data/node/test_nllloss_NCd1d2d3d4d5_mean_weight/model.onnx +0 -0
  435. onnx/backend/test/data/node/test_nllloss_NCd1d2d3d4d5_mean_weight_expanded/model.onnx +0 -0
  436. onnx/backend/test/data/node/test_nllloss_NCd1d2d3d4d5_none_no_weight/model.onnx +0 -0
  437. onnx/backend/test/data/node/test_nllloss_NCd1d2d3d4d5_none_no_weight_expanded/model.onnx +0 -0
  438. onnx/backend/test/data/node/test_quantizelinear_int4/test_data_set_0/output_0.pb +1 -1
  439. onnx/backend/test/data/node/test_reduce_log_sum_exp_do_not_keepdims_random/test_data_set_0/output_0.pb +1 -1
  440. onnx/backend/test/data/node/test_reduce_log_sum_exp_do_not_keepdims_random_expanded/test_data_set_0/output_0.pb +1 -1
  441. onnx/backend/test/data/node/test_reduce_log_sum_exp_keepdims_random/test_data_set_0/output_0.pb +1 -1
  442. onnx/backend/test/data/node/test_reduce_log_sum_exp_keepdims_random_expanded/test_data_set_0/output_0.pb +1 -1
  443. onnx/backend/test/data/node/test_reduce_log_sum_exp_negative_axes_keepdims_random/test_data_set_0/output_0.pb +1 -1
  444. onnx/backend/test/data/node/test_reduce_log_sum_exp_negative_axes_keepdims_random_expanded/test_data_set_0/output_0.pb +1 -1
  445. onnx/backend/test/data/node/test_reduce_max_empty_set/model.onnx +0 -0
  446. onnx/backend/test/data/node/test_reduce_max_empty_set/test_data_set_0/input_0.pb +0 -0
  447. onnx/backend/test/data/node/test_reduce_max_empty_set/test_data_set_0/input_1.pb +0 -0
  448. onnx/backend/test/data/node/test_reduce_max_empty_set/test_data_set_0/output_0.pb +0 -0
  449. onnx/backend/test/data/node/test_reduce_sum_empty_axes_input_noop/model.onnx +0 -0
  450. onnx/backend/test/data/node/test_reduce_sum_empty_axes_input_noop/test_data_set_0/input_0.pb +1 -0
  451. onnx/backend/test/data/node/test_reduce_sum_empty_axes_input_noop/test_data_set_0/input_1.pb +0 -0
  452. onnx/backend/test/data/node/test_reduce_sum_empty_axes_input_noop/test_data_set_0/output_0.pb +1 -0
  453. onnx/backend/test/data/node/test_reduce_sum_negative_axes_keepdims_random/model.onnx +0 -0
  454. onnx/backend/test/data/node/test_reduce_sum_negative_axes_keepdims_random/test_data_set_0/input_1.pb +0 -0
  455. onnx/backend/test/data/node/test_reduce_sum_negative_axes_keepdims_random/test_data_set_0/output_0.pb +1 -1
  456. onnx/backend/test/data/node/test_resize_tf_crop_and_resize/model.onnx +0 -0
  457. onnx/backend/test/data/node/test_resize_tf_crop_and_resize/test_data_set_0/input_1.pb +0 -0
  458. onnx/backend/test/data/node/test_resize_tf_crop_and_resize/test_data_set_0/output_0.pb +0 -0
  459. onnx/backend/test/data/node/test_resize_tf_crop_and_resize_extrapolation_value/model.onnx +0 -0
  460. onnx/backend/test/data/node/test_resize_tf_crop_and_resize_extrapolation_value/test_data_set_0/input_0.pb +0 -0
  461. onnx/backend/test/data/node/test_resize_tf_crop_and_resize_extrapolation_value/test_data_set_0/input_1.pb +0 -0
  462. onnx/backend/test/data/node/test_resize_tf_crop_and_resize_extrapolation_value/test_data_set_0/input_2.pb +0 -0
  463. onnx/backend/test/data/node/test_resize_tf_crop_and_resize_extrapolation_value/test_data_set_0/output_0.pb +0 -0
  464. onnx/backend/test/data/node/test_resize_upsample_sizes_nearest_not_larger/model.onnx +0 -0
  465. onnx/backend/test/data/node/test_resize_upsample_sizes_nearest_not_larger/test_data_set_0/output_0.pb +0 -0
  466. onnx/backend/test/data/node/test_resize_upsample_sizes_nearest_not_smaller/model.onnx +0 -0
  467. onnx/backend/test/data/node/test_resize_upsample_sizes_nearest_not_smaller/test_data_set_0/input_0.pb +0 -0
  468. onnx/backend/test/data/node/test_resize_upsample_sizes_nearest_not_smaller/test_data_set_0/input_1.pb +0 -0
  469. onnx/backend/test/data/node/test_resize_upsample_sizes_nearest_not_smaller/test_data_set_0/output_0.pb +0 -0
  470. onnx/backend/test/data/node/test_rnn_seq_length/model.onnx +0 -0
  471. onnx/backend/test/data/node/test_roialign_aligned_false/model.onnx +0 -0
  472. onnx/backend/test/data/node/test_roialign_aligned_true/model.onnx +0 -0
  473. onnx/backend/test/data/node/test_roialign_mode_max/model.onnx +0 -0
  474. onnx/backend/test/data/node/test_round/model.onnx +0 -0
  475. onnx/backend/test/data/node/test_selu/model.onnx +0 -0
  476. onnx/backend/test/data/node/test_selu_default/model.onnx +0 -0
  477. onnx/backend/test/data/node/test_selu_example/model.onnx +0 -0
  478. onnx/backend/test/data/node/test_simple_rnn_batchwise/model.onnx +0 -0
  479. onnx/backend/test/data/node/test_simple_rnn_defaults/model.onnx +0 -0
  480. onnx/backend/test/data/node/test_simple_rnn_with_initial_bias/model.onnx +0 -0
  481. onnx/backend/test/data/node/test_sin/model.onnx +0 -0
  482. onnx/backend/test/data/node/test_sin_example/model.onnx +0 -0
  483. onnx/backend/test/data/node/test_sinh/model.onnx +0 -0
  484. onnx/backend/test/data/node/test_sinh/test_data_set_0/output_0.pb +1 -1
  485. onnx/backend/test/data/node/test_sinh_example/model.onnx +0 -0
  486. onnx/backend/test/data/node/test_softplus/model.onnx +0 -0
  487. onnx/backend/test/data/node/test_softplus_example/model.onnx +0 -0
  488. onnx/backend/test/data/node/test_softsign/model.onnx +0 -0
  489. onnx/backend/test/data/node/test_softsign_example/model.onnx +0 -0
  490. onnx/backend/test/data/node/test_stft_with_window/test_data_set_0/input_2.pb +0 -0
  491. onnx/backend/test/data/node/test_stft_with_window/test_data_set_0/output_0.pb +0 -0
  492. onnx/backend/test/data/node/test_tan/model.onnx +0 -0
  493. onnx/backend/test/data/node/test_tan/test_data_set_0/output_0.pb +1 -1
  494. onnx/backend/test/data/node/test_tan_example/model.onnx +0 -0
  495. onnx/backend/test/data/node/test_thresholdedrelu/model.onnx +0 -0
  496. onnx/backend/test/data/node/test_thresholdedrelu_default/model.onnx +0 -0
  497. onnx/backend/test/data/node/test_thresholdedrelu_example/model.onnx +0 -0
  498. onnx/backend/test/data/node/test_training_dropout/model.onnx +0 -0
  499. onnx/backend/test/data/node/test_training_dropout_default/model.onnx +0 -0
  500. onnx/backend/test/data/node/test_training_dropout_default_mask/model.onnx +0 -0
  501. onnx/backend/test/data/node/test_training_dropout_mask/model.onnx +0 -0
  502. onnx/backend/test/data/node/test_training_dropout_zero_ratio/model.onnx +0 -0
  503. onnx/backend/test/data/node/test_training_dropout_zero_ratio_mask/model.onnx +0 -0
  504. onnx/backend/test/loader/__init__.py +11 -6
  505. onnx/backend/test/report/__init__.py +4 -3
  506. onnx/backend/test/report/base.py +1 -0
  507. onnx/backend/test/report/coverage.py +21 -20
  508. onnx/backend/test/runner/__init__.py +13 -11
  509. onnx/backend/test/runner/item.py +3 -2
  510. onnx/backend/test/stat_coverage.py +6 -5
  511. onnx/bin/checker.py +1 -0
  512. onnx/checker.cc +6 -1
  513. onnx/common/version.h +1 -1
  514. onnx/compose.py +66 -50
  515. onnx/cpp2py_export.cc +4 -0
  516. onnx/defs/__init__.py +2 -2
  517. onnx/defs/data_type_utils.cc +0 -1
  518. onnx/defs/gen_doc.py +9 -8
  519. onnx/defs/gen_shape_inference_information.py +1 -0
  520. onnx/defs/generator/defs.cc +32 -84
  521. onnx/defs/generator/old.cc +389 -0
  522. onnx/defs/math/defs.cc +308 -313
  523. onnx/defs/math/old.cc +996 -9
  524. onnx/defs/math/utils.cc +12 -1
  525. onnx/defs/math/utils.h +2 -0
  526. onnx/defs/nn/defs.cc +57 -75
  527. onnx/defs/nn/old.cc +1536 -2
  528. onnx/defs/object_detection/defs.cc +4 -7
  529. onnx/defs/object_detection/old.cc +117 -0
  530. onnx/defs/operator_sets.h +108 -1
  531. onnx/defs/parser.cc +10 -1
  532. onnx/defs/quantization/defs.cc +3 -2
  533. onnx/defs/quantization/old.cc +4 -1
  534. onnx/defs/rnn/defs.cc +10 -13
  535. onnx/defs/rnn/old.cc +517 -2
  536. onnx/defs/schema.cc +53 -59
  537. onnx/defs/schema.h +58 -2
  538. onnx/defs/shape_inference.h +67 -18
  539. onnx/defs/tensor/defs.cc +22 -20
  540. onnx/defs/tensor/old.cc +114 -3
  541. onnx/external_data_helper.py +27 -14
  542. onnx/gen_proto.py +3 -2
  543. onnx/helper.py +86 -61
  544. onnx/hub.py +39 -35
  545. onnx/inliner/inliner.cc +0 -1
  546. onnx/mapping.py +3 -2
  547. onnx/numpy_helper.py +159 -23
  548. onnx/onnx-ml.proto +1 -1
  549. onnx/onnx.in.proto +1 -1
  550. onnx/onnx.proto +1 -1
  551. onnx/onnx_cpp2py_export/defs.pyi +0 -2
  552. onnx/onnx_cpp2py_export/inliner.pyi +0 -4
  553. onnx/onnx_cpp2py_export/parser.pyi +0 -4
  554. onnx/onnx_cpp2py_export.cp38-win32.pyd +0 -0
  555. onnx/parser.py +1 -0
  556. onnx/printer.py +2 -3
  557. onnx/reference/__init__.py +1 -0
  558. onnx/reference/custom_element_types.py +73 -8
  559. onnx/reference/op_run.py +13 -58
  560. onnx/reference/ops/__init__.py +1 -0
  561. onnx/reference/ops/_helpers.py +6 -4
  562. onnx/reference/ops/_op.py +16 -5
  563. onnx/reference/ops/_op_common_indices.py +1 -1
  564. onnx/reference/ops/_op_common_pool.py +38 -29
  565. onnx/reference/ops/_op_common_random.py +1 -1
  566. onnx/reference/ops/_op_common_window.py +2 -2
  567. onnx/reference/ops/_op_list.py +9 -6
  568. onnx/reference/ops/aionnx_preview_training/__init__.py +1 -0
  569. onnx/reference/ops/aionnx_preview_training/_op_list.py +5 -7
  570. onnx/reference/ops/aionnx_preview_training/_op_run_training.py +1 -1
  571. onnx/reference/ops/aionnx_preview_training/op_adagrad.py +14 -5
  572. onnx/reference/ops/aionnx_preview_training/op_adam.py +2 -2
  573. onnx/reference/ops/aionnx_preview_training/op_momentum.py +14 -2
  574. onnx/reference/ops/aionnxml/__init__.py +1 -0
  575. onnx/reference/ops/aionnxml/_common_classifier.py +1 -0
  576. onnx/reference/ops/aionnxml/_op_list.py +5 -6
  577. onnx/reference/ops/aionnxml/_op_run_aionnxml.py +1 -1
  578. onnx/reference/ops/aionnxml/op_array_feature_extractor.py +1 -1
  579. onnx/reference/ops/aionnxml/op_binarizer.py +1 -1
  580. onnx/reference/ops/aionnxml/op_dict_vectorizer.py +2 -2
  581. onnx/reference/ops/aionnxml/op_feature_vectorizer.py +1 -1
  582. onnx/reference/ops/aionnxml/op_imputer.py +3 -3
  583. onnx/reference/ops/aionnxml/op_label_encoder.py +1 -1
  584. onnx/reference/ops/aionnxml/op_linear_classifier.py +2 -2
  585. onnx/reference/ops/aionnxml/op_linear_regressor.py +1 -1
  586. onnx/reference/ops/aionnxml/op_normalizer.py +1 -1
  587. onnx/reference/ops/aionnxml/op_one_hot_encoder.py +1 -1
  588. onnx/reference/ops/aionnxml/op_scaler.py +1 -1
  589. onnx/reference/ops/aionnxml/op_svm_classifier.py +10 -7
  590. onnx/reference/ops/aionnxml/op_svm_helper.py +2 -2
  591. onnx/reference/ops/aionnxml/op_svm_regressor.py +1 -1
  592. onnx/reference/ops/aionnxml/op_tree_ensemble.py +3 -3
  593. onnx/reference/ops/aionnxml/op_tree_ensemble_classifier.py +1 -1
  594. onnx/reference/ops/aionnxml/op_tree_ensemble_helper.py +2 -2
  595. onnx/reference/ops/aionnxml/op_tree_ensemble_regressor.py +5 -3
  596. onnx/reference/ops/experimental/__init__.py +1 -0
  597. onnx/reference/ops/experimental/_op_list.py +6 -12
  598. onnx/reference/ops/experimental/_op_run_experimental.py +1 -1
  599. onnx/reference/ops/experimental/op_im2col.py +1 -1
  600. onnx/reference/ops/op_abs.py +1 -1
  601. onnx/reference/ops/op_acos.py +1 -1
  602. onnx/reference/ops/op_acosh.py +1 -1
  603. onnx/reference/ops/op_add.py +1 -1
  604. onnx/reference/ops/op_affine_grid.py +1 -1
  605. onnx/reference/ops/op_and.py +1 -1
  606. onnx/reference/ops/op_argmax.py +1 -1
  607. onnx/reference/ops/op_argmin.py +1 -1
  608. onnx/reference/ops/op_asin.py +1 -1
  609. onnx/reference/ops/op_asinh.py +1 -1
  610. onnx/reference/ops/op_atan.py +1 -1
  611. onnx/reference/ops/op_atanh.py +1 -1
  612. onnx/reference/ops/op_attribute_has_value.py +15 -15
  613. onnx/reference/ops/op_average_pool.py +1 -1
  614. onnx/reference/ops/op_batch_normalization.py +13 -2
  615. onnx/reference/ops/op_bernoulli.py +1 -1
  616. onnx/reference/ops/op_bitshift.py +1 -1
  617. onnx/reference/ops/op_bitwise_and.py +1 -1
  618. onnx/reference/ops/op_bitwise_not.py +1 -1
  619. onnx/reference/ops/op_bitwise_or.py +1 -1
  620. onnx/reference/ops/op_bitwise_xor.py +1 -1
  621. onnx/reference/ops/op_blackman_window.py +1 -1
  622. onnx/reference/ops/op_cast.py +11 -10
  623. onnx/reference/ops/op_cast_like.py +1 -1
  624. onnx/reference/ops/op_ceil.py +1 -1
  625. onnx/reference/ops/op_celu.py +1 -1
  626. onnx/reference/ops/op_center_crop_pad.py +1 -1
  627. onnx/reference/ops/op_clip.py +1 -1
  628. onnx/reference/ops/op_col2im.py +10 -4
  629. onnx/reference/ops/op_compress.py +1 -1
  630. onnx/reference/ops/op_concat.py +1 -1
  631. onnx/reference/ops/op_concat_from_sequence.py +3 -3
  632. onnx/reference/ops/op_constant.py +2 -2
  633. onnx/reference/ops/op_constant_of_shape.py +1 -1
  634. onnx/reference/ops/op_conv.py +22 -17
  635. onnx/reference/ops/op_conv_integer.py +1 -1
  636. onnx/reference/ops/op_conv_transpose.py +37 -6
  637. onnx/reference/ops/op_cos.py +1 -1
  638. onnx/reference/ops/op_cosh.py +1 -1
  639. onnx/reference/ops/op_cum_sum.py +1 -1
  640. onnx/reference/ops/op_deform_conv.py +1 -1
  641. onnx/reference/ops/op_depth_to_space.py +1 -1
  642. onnx/reference/ops/op_dequantize_linear.py +7 -9
  643. onnx/reference/ops/op_det.py +1 -1
  644. onnx/reference/ops/op_dft.py +16 -2
  645. onnx/reference/ops/op_div.py +1 -1
  646. onnx/reference/ops/op_dropout.py +9 -8
  647. onnx/reference/ops/op_dynamic_quantize_linear.py +1 -1
  648. onnx/reference/ops/op_einsum.py +1 -1
  649. onnx/reference/ops/op_elu.py +1 -1
  650. onnx/reference/ops/op_equal.py +1 -1
  651. onnx/reference/ops/op_erf.py +1 -1
  652. onnx/reference/ops/op_exp.py +1 -1
  653. onnx/reference/ops/op_expand.py +1 -1
  654. onnx/reference/ops/op_eyelike.py +2 -2
  655. onnx/reference/ops/op_flatten.py +1 -1
  656. onnx/reference/ops/op_floor.py +1 -1
  657. onnx/reference/ops/op_gather.py +1 -1
  658. onnx/reference/ops/op_gather_elements.py +3 -3
  659. onnx/reference/ops/op_gathernd.py +2 -4
  660. onnx/reference/ops/op_gemm.py +12 -2
  661. onnx/reference/ops/op_global_average_pool.py +1 -1
  662. onnx/reference/ops/op_global_max_pool.py +1 -1
  663. onnx/reference/ops/op_greater.py +1 -1
  664. onnx/reference/ops/op_greater_or_equal.py +1 -1
  665. onnx/reference/ops/op_grid_sample.py +2 -3
  666. onnx/reference/ops/op_gru.py +7 -7
  667. onnx/reference/ops/op_hamming_window.py +1 -1
  668. onnx/reference/ops/op_hann_window.py +1 -1
  669. onnx/reference/ops/op_hard_sigmoid.py +1 -1
  670. onnx/reference/ops/op_hardmax.py +5 -2
  671. onnx/reference/ops/op_identity.py +3 -3
  672. onnx/reference/ops/op_if.py +2 -2
  673. onnx/reference/ops/op_instance_normalization.py +1 -1
  674. onnx/reference/ops/op_isinf.py +1 -1
  675. onnx/reference/ops/op_isnan.py +1 -1
  676. onnx/reference/ops/op_layer_normalization.py +2 -4
  677. onnx/reference/ops/op_leaky_relu.py +1 -1
  678. onnx/reference/ops/op_less.py +1 -1
  679. onnx/reference/ops/op_less_or_equal.py +1 -1
  680. onnx/reference/ops/op_log.py +1 -1
  681. onnx/reference/ops/op_log_softmax.py +1 -1
  682. onnx/reference/ops/op_loop.py +4 -2
  683. onnx/reference/ops/op_lp_normalization.py +1 -1
  684. onnx/reference/ops/op_lp_pool.py +4 -2
  685. onnx/reference/ops/op_lrn.py +1 -1
  686. onnx/reference/ops/op_lstm.py +9 -11
  687. onnx/reference/ops/op_matmul.py +1 -1
  688. onnx/reference/ops/op_matmul_integer.py +1 -1
  689. onnx/reference/ops/op_max.py +1 -1
  690. onnx/reference/ops/op_max_pool.py +8 -8
  691. onnx/reference/ops/op_max_unpool.py +5 -3
  692. onnx/reference/ops/op_mean.py +1 -1
  693. onnx/reference/ops/op_mel_weight_matrix.py +1 -1
  694. onnx/reference/ops/op_min.py +1 -1
  695. onnx/reference/ops/op_mod.py +1 -1
  696. onnx/reference/ops/op_mul.py +1 -1
  697. onnx/reference/ops/op_neg.py +1 -1
  698. onnx/reference/ops/op_negative_log_likelihood_loss.py +4 -2
  699. onnx/reference/ops/op_non_max_suppression.py +10 -11
  700. onnx/reference/ops/op_non_zero.py +1 -1
  701. onnx/reference/ops/op_not.py +1 -1
  702. onnx/reference/ops/op_one_hot.py +1 -1
  703. onnx/reference/ops/op_optional.py +1 -1
  704. onnx/reference/ops/op_optional_get_element.py +1 -1
  705. onnx/reference/ops/op_optional_has_element.py +1 -1
  706. onnx/reference/ops/op_or.py +1 -1
  707. onnx/reference/ops/op_pad.py +1 -1
  708. onnx/reference/ops/op_pool_common.py +7 -6
  709. onnx/reference/ops/op_pow.py +1 -1
  710. onnx/reference/ops/op_prelu.py +3 -3
  711. onnx/reference/ops/op_qlinear_conv.py +1 -1
  712. onnx/reference/ops/op_qlinear_matmul.py +1 -1
  713. onnx/reference/ops/op_quantize_linear.py +15 -9
  714. onnx/reference/ops/op_random_normal.py +1 -1
  715. onnx/reference/ops/op_random_normal_like.py +1 -1
  716. onnx/reference/ops/op_random_uniform.py +1 -1
  717. onnx/reference/ops/op_random_uniform_like.py +1 -1
  718. onnx/reference/ops/op_range.py +1 -1
  719. onnx/reference/ops/op_reciprocal.py +1 -1
  720. onnx/reference/ops/op_reduce_l1.py +1 -1
  721. onnx/reference/ops/op_reduce_l2.py +1 -1
  722. onnx/reference/ops/op_reduce_log_sum.py +1 -1
  723. onnx/reference/ops/op_reduce_log_sum_exp.py +1 -1
  724. onnx/reference/ops/op_reduce_max.py +1 -1
  725. onnx/reference/ops/op_reduce_mean.py +2 -2
  726. onnx/reference/ops/op_reduce_min.py +1 -1
  727. onnx/reference/ops/op_reduce_prod.py +1 -1
  728. onnx/reference/ops/op_reduce_sum.py +2 -2
  729. onnx/reference/ops/op_reduce_sum_square.py +1 -1
  730. onnx/reference/ops/op_regex_full_match.py +1 -1
  731. onnx/reference/ops/op_relu.py +1 -1
  732. onnx/reference/ops/op_reshape.py +1 -1
  733. onnx/reference/ops/op_reverse_sequence.py +1 -1
  734. onnx/reference/ops/op_rnn.py +10 -8
  735. onnx/reference/ops/op_roi_align.py +5 -5
  736. onnx/reference/ops/op_round.py +1 -1
  737. onnx/reference/ops/op_scan.py +8 -8
  738. onnx/reference/ops/op_scatter_elements.py +19 -50
  739. onnx/reference/ops/op_scatternd.py +1 -1
  740. onnx/reference/ops/op_selu.py +1 -1
  741. onnx/reference/ops/op_sequence_at.py +1 -1
  742. onnx/reference/ops/op_sequence_construct.py +1 -1
  743. onnx/reference/ops/op_sequence_empty.py +2 -2
  744. onnx/reference/ops/op_sequence_erase.py +1 -1
  745. onnx/reference/ops/op_sequence_insert.py +6 -6
  746. onnx/reference/ops/op_sequence_length.py +1 -1
  747. onnx/reference/ops/op_sequence_map.py +1 -1
  748. onnx/reference/ops/op_shape.py +2 -6
  749. onnx/reference/ops/op_shrink.py +1 -1
  750. onnx/reference/ops/op_sigmoid.py +1 -1
  751. onnx/reference/ops/op_sign.py +1 -1
  752. onnx/reference/ops/op_sin.py +1 -1
  753. onnx/reference/ops/op_sinh.py +1 -1
  754. onnx/reference/ops/op_size.py +1 -1
  755. onnx/reference/ops/op_slice.py +3 -5
  756. onnx/reference/ops/op_softmax.py +1 -1
  757. onnx/reference/ops/op_softmax_cross_entropy_loss.py +1 -1
  758. onnx/reference/ops/op_softplus.py +1 -1
  759. onnx/reference/ops/op_softsign.py +1 -1
  760. onnx/reference/ops/op_space_to_depth.py +1 -1
  761. onnx/reference/ops/op_split.py +1 -1
  762. onnx/reference/ops/op_split_to_sequence.py +5 -7
  763. onnx/reference/ops/op_sqrt.py +1 -1
  764. onnx/reference/ops/op_squeeze.py +1 -1
  765. onnx/reference/ops/op_stft.py +3 -2
  766. onnx/reference/ops/op_string_concat.py +1 -1
  767. onnx/reference/ops/op_string_normalizer.py +8 -8
  768. onnx/reference/ops/op_string_split.py +2 -4
  769. onnx/reference/ops/op_sub.py +1 -1
  770. onnx/reference/ops/op_sum.py +1 -1
  771. onnx/reference/ops/op_tan.py +1 -1
  772. onnx/reference/ops/op_tanh.py +1 -1
  773. onnx/reference/ops/op_tfidf_vectorizer.py +11 -12
  774. onnx/reference/ops/op_thresholded_relu.py +1 -1
  775. onnx/reference/ops/op_tile.py +1 -1
  776. onnx/reference/ops/op_topk.py +7 -2
  777. onnx/reference/ops/op_transpose.py +1 -1
  778. onnx/reference/ops/op_trilu.py +1 -1
  779. onnx/reference/ops/op_unique.py +3 -1
  780. onnx/reference/ops/op_unsqueeze.py +2 -2
  781. onnx/reference/ops/op_upsample.py +1 -1
  782. onnx/reference/ops/op_where.py +1 -1
  783. onnx/reference/ops/op_xor.py +1 -1
  784. onnx/reference/ops_optimized/__init__.py +1 -0
  785. onnx/reference/ops_optimized/op_conv_optimized.py +1 -1
  786. onnx/reference/reference_evaluator.py +27 -13
  787. onnx/serialization.py +1 -1
  788. onnx/shape_inference/implementation.cc +15 -1
  789. onnx/shape_inference/implementation.h +15 -1
  790. onnx/shape_inference.py +1 -1
  791. onnx/subbyte.py +6 -6
  792. onnx/test/basic_test.py +1 -0
  793. onnx/test/checker_test.py +37 -2
  794. onnx/test/compose_test.py +12 -11
  795. onnx/test/cpp/schema_registration_test.cc +3 -3
  796. onnx/test/cpp/shape_inference_test.cc +38 -2
  797. onnx/test/elu_test.py +2 -0
  798. onnx/test/function_inference_test.py +2 -0
  799. onnx/test/function_test.py +1 -0
  800. onnx/test/helper_test.py +77 -16
  801. onnx/test/hub_test.py +1 -1
  802. onnx/test/inference_function_test.py +25 -8
  803. onnx/test/inliner_test.py +2 -0
  804. onnx/test/model_container_refeval_test.py +2 -1
  805. onnx/test/model_container_test.py +1 -0
  806. onnx/test/model_inference_test.py +2 -0
  807. onnx/test/numpy_helper_test.py +56 -1
  808. onnx/test/parser_test.py +48 -2
  809. onnx/test/printer_test.py +2 -0
  810. onnx/test/reference_evaluator_ml_test.py +2 -3
  811. onnx/test/reference_evaluator_model_test.py +2 -0
  812. onnx/test/reference_evaluator_test.py +173 -19
  813. onnx/test/relu_test.py +2 -0
  814. onnx/test/schema_test.py +4 -2
  815. onnx/test/serialization_test.py +2 -0
  816. onnx/test/shape_inference_test.py +349 -19
  817. onnx/test/symbolic_shape_test.py +3 -3
  818. onnx/test/test_backend_onnxruntime.py +272 -1
  819. onnx/test/test_backend_reference.py +24 -3
  820. onnx/test/test_backend_test.py +6 -5
  821. onnx/test/test_external_data.py +91 -2
  822. onnx/test/test_with_ort.py +1 -0
  823. onnx/test/tools_test.py +15 -14
  824. onnx/test/training_tool_test.py +1 -0
  825. onnx/test/utils_test.py +1 -0
  826. onnx/test/version_converter/automatic_downgrade_test.py +2 -0
  827. onnx/test/version_converter/automatic_upgrade_test.py +2 -0
  828. onnx/test/version_converter_test.py +26 -7
  829. onnx/test/version_utils.py +8 -0
  830. onnx/tools/net_drawer.py +7 -6
  831. onnx/tools/replace_constants.py +11 -11
  832. onnx/tools/update_model_dims.py +7 -6
  833. onnx/utils.py +104 -21
  834. onnx/version.py +2 -2
  835. onnx/version_converter/adapters/split_17_18.h +1 -1
  836. onnx/version_converter/convert.h +107 -2
  837. onnx/version_converter.py +3 -2
  838. {onnx-1.16.1.dist-info → onnx-1.17.0.dist-info}/METADATA +8 -11
  839. {onnx-1.16.1.dist-info → onnx-1.17.0.dist-info}/RECORD +843 -817
  840. {onnx-1.16.1.dist-info → onnx-1.17.0.dist-info}/WHEEL +1 -1
  841. {onnx-1.16.1.dist-info → onnx-1.17.0.dist-info}/LICENSE +0 -0
  842. {onnx-1.16.1.dist-info → onnx-1.17.0.dist-info}/entry_points.txt +0 -0
  843. {onnx-1.16.1.dist-info → onnx-1.17.0.dist-info}/top_level.txt +0 -0
onnx/defs/nn/old.cc CHANGED
@@ -9,6 +9,1540 @@
9
9
 
10
10
  namespace ONNX_NAMESPACE {
11
11
 
12
+ // For GlobalPool operations.
13
+ void globalPoolTypeShapeInference_opset2(InferenceContext& ctx) {
14
+ propagateElemTypeFromInputToOutput(ctx, 0, 0);
15
+
16
+ // needs at least one input with shape.
17
+ if (!hasNInputShapes(ctx, 1)) {
18
+ return;
19
+ }
20
+
21
+ auto input_shape = ctx.getInputType(0)->tensor_type().shape();
22
+ if (input_shape.dim_size() < 2) {
23
+ return;
24
+ }
25
+
26
+ // first dim is the batch axis and the next is the number of channels.
27
+ size_t n_input_dims = static_cast<size_t>(input_shape.dim_size() - 2);
28
+
29
+ // (N, C, 1, 1, ..., 1)
30
+ auto output_shape = ctx.getOutputType(0)->mutable_tensor_type()->mutable_shape();
31
+ *output_shape->add_dim() = input_shape.dim(0);
32
+ *output_shape->add_dim() = input_shape.dim(1);
33
+
34
+ for (size_t i = 0; i < n_input_dims; ++i) {
35
+ output_shape->add_dim()->set_dim_value(1);
36
+ }
37
+ }
38
+
39
+ std::function<void(OpSchema&)> GlobalLpPoolingOpSchemaGenerator_opset2(const char* op_type, const char* op) {
40
+ return [=](OpSchema& schema) {
41
+ std::string doc;
42
+ POPULATE_OP_DOC_STR(doc = R"DOC(
43
+ Global{op_type} consumes an input tensor X and applies {op} pooling across
44
+ the values in the same channel. This is equivalent to {op_type} with kernel size
45
+ equal to the spatial dimension of input tensor.)DOC";
46
+ ReplaceAll(doc, "{op_type}", op_type);
47
+ ReplaceAll(doc, "{op}", op););
48
+ schema.SetDoc(doc);
49
+ schema.Attr(
50
+ "p", "p value of the Lp norm used to pool over the input data.", AttributeProto::INT, static_cast<int64_t>(2));
51
+ schema.Input(
52
+ 0,
53
+ "X",
54
+ "Input data tensor from the previous operator; "
55
+ "dimensions for image case are (N x C x H x W), "
56
+ "where N is the batch size, C is the number of "
57
+ "channels, and H and W are the height and the width "
58
+ "of the data. For non image case, the dimensions are "
59
+ "in the form of (N x C x D1 x D2 ... Dn), "
60
+ "where N is the batch size.",
61
+ "T",
62
+ OpSchema::Single,
63
+ true,
64
+ 1,
65
+ OpSchema::Differentiable);
66
+ schema.Output(
67
+ 0,
68
+ "Y",
69
+ "Output data tensor from pooling across the input "
70
+ "tensor. The output tensor has the same rank as the input. "
71
+ "The first two dimensions of output shape are the same as "
72
+ "the input (N x C), while the other dimensions are all 1.",
73
+ "T",
74
+ OpSchema::Single,
75
+ true,
76
+ 1,
77
+ OpSchema::Differentiable);
78
+ schema.TypeConstraint("T", OpSchema::all_float_types_ir4(), "Constrain input and output types to float tensors.");
79
+ schema.TypeAndShapeInferenceFunction([](InferenceContext& ctx) { globalPoolTypeShapeInference_opset2(ctx); });
80
+ };
81
+ }
82
+
83
+ ONNX_OPERATOR_SET_SCHEMA(
84
+ GlobalLpPool,
85
+ 2,
86
+ OpSchema().FillUsing(GlobalLpPoolingOpSchemaGenerator_opset2("LpPool", "lp pool")));
87
+
88
+ const char* pads_doc_opset11 =
89
+ "Padding for the beginning and ending along each spatial axis, it can take any value greater "
90
+ "than or equal to 0. The value represent the number of pixels added to the beginning "
91
+ "and end part of the corresponding axis. `pads` format should be as follow "
92
+ "[x1_begin, x2_begin...x1_end, x2_end,...], where xi_begin the number of pixels "
93
+ "added at the beginning of axis `i` and xi_end, the number of pixels added at "
94
+ "the end of axis `i`. This attribute cannot be used simultaneously with "
95
+ "auto_pad attribute. If not present, the padding defaults to 0 along start and end of each spatial axis.";
96
+ const char* conv_auto_pad_doc_opset19 =
97
+ "auto_pad must be either NOTSET, SAME_UPPER, SAME_LOWER or VALID. Where "
98
+ "default value is NOTSET, which means explicit padding is used. "
99
+ "SAME_UPPER or SAME_LOWER mean pad the input so that "
100
+ "`output_shape[i] = ceil(input_shape[i] / strides[i])` for each axis `i`. "
101
+ "The padding is split between the two sides equally or almost equally (depending "
102
+ "on whether it is even or odd). In case the padding is an odd number, the extra "
103
+ "padding is added at the end for SAME_UPPER and at the beginning for SAME_LOWER.";
104
+ const char* conv_transpose_auto_pad_doc_opset19 =
105
+ "auto_pad must be either NOTSET, SAME_UPPER, SAME_LOWER or VALID. Where "
106
+ "default value is NOTSET, which means explicit padding is used. "
107
+ "SAME_UPPER or SAME_LOWER mean pad the input so that "
108
+ "`output_shape[i] = input_shape[i] * strides[i]` for each axis `i`. "
109
+ "The padding is split between the two sides equally or almost equally (depending "
110
+ "on whether it is even or odd). In case the padding is an odd number, the extra "
111
+ "padding is added at the end for SAME_UPPER and at the beginning for SAME_LOWER.";
112
+
113
+ void convPoolShapeInference_opset19(
114
+ InferenceContext& ctx,
115
+ bool use_dilation,
116
+ bool require_kernel_shape,
117
+ int input1Idx,
118
+ int input2Idx) {
119
+ // we need the first input shape for this inference.
120
+ if (!hasInputShape(ctx, input1Idx)) {
121
+ return;
122
+ }
123
+
124
+ // if kernel shape is an input (and not attribute)
125
+ // we need the shape of the second input.
126
+ if (!require_kernel_shape && !hasInputShape(ctx, input2Idx)) {
127
+ return;
128
+ }
129
+
130
+ auto input_shape = ctx.getInputType(input1Idx)->tensor_type().shape();
131
+ if (input_shape.dim_size() < 2) {
132
+ fail_shape_inference("Input tensor must have at least 2 dimensions");
133
+ }
134
+
135
+ // first dim is the batch axis and the next is the number of channels.
136
+ size_t n_input_dims = static_cast<size_t>(input_shape.dim_size() - 2);
137
+
138
+ // Only MaxPool and Conv support dilation. For
139
+ // simplicity of the code, we just treat the rest of them as having all-1s
140
+ // dilation.
141
+ std::vector<int64_t> dilations;
142
+ if (use_dilation && getRepeatedAttribute(ctx, "dilations", dilations)) {
143
+ if (dilations.size() != n_input_dims) {
144
+ fail_shape_inference("Attribute dilations has incorrect size");
145
+ }
146
+ } else {
147
+ dilations.assign(n_input_dims, 1);
148
+ }
149
+
150
+ std::vector<int64_t> strides;
151
+ if (getRepeatedAttribute(ctx, "strides", strides)) {
152
+ if (strides.size() != n_input_dims) {
153
+ fail_shape_inference("Attribute strides has incorrect size");
154
+ }
155
+ } else {
156
+ strides.assign(n_input_dims, 1);
157
+ }
158
+
159
+ std::vector<int64_t> kernel_shape;
160
+ if (getRepeatedAttribute(ctx, "kernel_shape", kernel_shape)) {
161
+ if (kernel_shape.size() != n_input_dims) {
162
+ fail_shape_inference("Attribute kernel_shape has incorrect size");
163
+ }
164
+ } else if (require_kernel_shape) {
165
+ fail_shape_inference("Attribute kernel_shape must be specified");
166
+ } else {
167
+ auto second_input_shape = ctx.getInputType(input2Idx)->tensor_type().shape();
168
+ for (int i = 2; i < second_input_shape.dim_size(); ++i) {
169
+ if (!second_input_shape.dim(i).has_dim_value()) {
170
+ return;
171
+ }
172
+ kernel_shape.push_back(second_input_shape.dim(i).dim_value());
173
+ }
174
+ }
175
+
176
+ std::vector<int64_t> effective_kernel_shape = kernel_shape;
177
+ for (int i = 0; i < static_cast<int>(kernel_shape.size()); i++) {
178
+ // accounting for dilation, how big is the kernel in this dimension
179
+ effective_kernel_shape[i] = (effective_kernel_shape[i] - 1) * dilations[i] + 1;
180
+ }
181
+
182
+ std::vector<int64_t> pads;
183
+ if (getRepeatedAttribute(ctx, "pads", pads)) {
184
+ if (pads.size() != n_input_dims * 2) {
185
+ fail_shape_inference("Attribute pads has incorrect size");
186
+ }
187
+ } else {
188
+ pads.assign(n_input_dims * 2, 0);
189
+ const auto* auto_pad_attr = ctx.getAttribute("auto_pad");
190
+ if ((nullptr != auto_pad_attr) && (auto_pad_attr->s() != "VALID")) {
191
+ int input_dims_size = static_cast<int>(n_input_dims);
192
+ for (int i = 0; i < input_dims_size; ++i) {
193
+ int64_t residual = 0;
194
+ int64_t stride = strides[i];
195
+ if (stride > 1) {
196
+ if (!input_shape.dim(2 + i).has_dim_value()) {
197
+ continue;
198
+ }
199
+ residual = input_shape.dim(2 + i).dim_value();
200
+ while (residual >= stride) {
201
+ residual -= stride;
202
+ }
203
+ }
204
+ if (i >= static_cast<int>(effective_kernel_shape.size())) {
205
+ fail_shape_inference("kernel shape should have ", input_dims_size, " values in ", ctx.getDisplayName(), ".");
206
+ }
207
+ int64_t total_pad = residual == 0 ? effective_kernel_shape[i] - stride : effective_kernel_shape[i] - residual;
208
+ if (total_pad < 0)
209
+ total_pad = 0;
210
+ int64_t half_pad_small = total_pad >> 1;
211
+ int64_t half_pad_big = total_pad - half_pad_small;
212
+ if (auto_pad_attr->s() == "SAME_UPPER") {
213
+ pads[i] = half_pad_small;
214
+ pads[i + input_dims_size] = half_pad_big;
215
+ } else if (auto_pad_attr->s() == "SAME_LOWER") {
216
+ pads[i] = half_pad_big;
217
+ pads[i + input_dims_size] = half_pad_small;
218
+ }
219
+ }
220
+ }
221
+ }
222
+
223
+ auto output_shape = ctx.getOutputType(0)->mutable_tensor_type()->mutable_shape();
224
+
225
+ if (require_kernel_shape) {
226
+ // add the first two dimensions from the input.
227
+ *output_shape->add_dim() = input_shape.dim(0);
228
+ *output_shape->add_dim() = input_shape.dim(1);
229
+ } else {
230
+ *output_shape->add_dim() = input_shape.dim(0);
231
+ auto& second_input_shape = getInputShape(ctx, input2Idx);
232
+ if (second_input_shape.dim_size() < 1) {
233
+ fail_shape_inference("Second input tensor has wrong dimension");
234
+ }
235
+ *output_shape->add_dim() = second_input_shape.dim(0);
236
+ }
237
+
238
+ int kernel_shape_size = static_cast<int>(kernel_shape.size());
239
+ for (int i = 0; i < kernel_shape_size; ++i) {
240
+ auto newdim = output_shape->add_dim();
241
+ if (!input_shape.dim(2 + i).has_dim_value()) {
242
+ continue;
243
+ }
244
+ // how big is the input, including padding
245
+ int64_t effective_input_size = input_shape.dim(2 + i).dim_value();
246
+ effective_input_size += pads[i];
247
+ effective_input_size += pads[i + kernel_shape_size];
248
+
249
+ // default is floor mode .i.e. ceil_mode is set to 0
250
+ auto ceil_mode = getAttribute(ctx, "ceil_mode", 0);
251
+
252
+ // how many times we can move the kernel from it's initial position, based
253
+ // on the stride
254
+ int64_t strided_kernel_positions;
255
+
256
+ if (ceil_mode == 1)
257
+ strided_kernel_positions =
258
+ (int64_t)(std::ceil((effective_input_size - effective_kernel_shape[i]) / float(strides[i])));
259
+ else
260
+ strided_kernel_positions = (effective_input_size - effective_kernel_shape[i]) / strides[i];
261
+
262
+ // add in the initial position
263
+ newdim->set_dim_value(1 + strided_kernel_positions);
264
+ }
265
+
266
+ if (ctx.getNumOutputs() > 1) {
267
+ // MaxPool with two outputs case.
268
+ auto second_output_shape = ctx.getOutputType(1)->mutable_tensor_type()->mutable_shape();
269
+ second_output_shape->CopyFrom(*output_shape);
270
+ }
271
+ }
272
+
273
+ static const char* Dropout_ver13_doc = R"DOC(
274
+ Dropout takes an input floating-point tensor, an optional input ratio (floating-point scalar) and an optional input training_mode (boolean scalar). It produces two tensor outputs,
275
+ output (floating-point tensor) and mask (optional `Tensor<bool>`). If `training_mode` is true then the output Y will be a random dropout;
276
+ Note that this Dropout scales the masked input data by the following equation, so to convert the trained model into inference mode,
277
+ the user can simply not pass `training_mode` input or set it to false.
278
+ ```
279
+ output = scale * data * mask,
280
+ ```
281
+ where
282
+ ```
283
+ scale = 1. / (1. - ratio).
284
+ ```
285
+ )DOC";
286
+
287
+ ONNX_OPERATOR_SET_SCHEMA(
288
+ Dropout,
289
+ 13,
290
+ OpSchema()
291
+ .SetDoc(GET_OP_DOC_STR(std::string(Dropout_ver13_doc) + GenerateOptionalArgumentsDoc()))
292
+ .Attr(
293
+ "seed",
294
+ "(Optional) Seed to the random generator, if not specified we will auto generate one.",
295
+ AttributeProto::INT,
296
+ OPTIONAL_VALUE)
297
+ .Input(0, "data", "The input data as Tensor.", "T", OpSchema::Single, true, 1, OpSchema::Differentiable)
298
+ .Input(
299
+ 1,
300
+ "ratio",
301
+ "The ratio of random dropout, with value in [0, 1). If this input was not set, "
302
+ "or if it was set to 0, the output would be a simple copy of the input. "
303
+ "If it's non-zero, output will be a random dropout of the scaled input, which is typically "
304
+ "the case during training. It is an optional value, if not specified it will default to 0.5.",
305
+ "T1",
306
+ OpSchema::Optional,
307
+ true,
308
+ 1,
309
+ OpSchema::NonDifferentiable)
310
+ .Input(
311
+ 2,
312
+ "training_mode",
313
+ "If set to true then it indicates dropout is being used for training. It is an optional value hence unless "
314
+ "specified explicitly, it is false. If it is false, ratio is ignored and the operation mimics inference mode where "
315
+ "nothing will be dropped from the input data and if mask is requested as output it will contain all ones.",
316
+ "T2",
317
+ OpSchema::Optional,
318
+ true,
319
+ 1,
320
+ OpSchema::NonDifferentiable)
321
+ .Output(0, "output", "The output.", "T", OpSchema::Single, true, 1, OpSchema::Differentiable)
322
+ .Output(1, "mask", "The output mask.", "T2", OpSchema::Optional, true, 1, OpSchema::NonDifferentiable)
323
+ .TypeConstraint(
324
+ "T",
325
+ {"tensor(float16)", "tensor(float)", "tensor(double)", "tensor(bfloat16)"},
326
+ "Constrain input and output types to float tensors.")
327
+ .TypeConstraint(
328
+ "T1",
329
+ {"tensor(float16)", "tensor(float)", "tensor(double)"},
330
+ "Constrain input 'ratio' types to float tensors.")
331
+ .TypeConstraint("T2", {"tensor(bool)"}, "Constrain output 'mask' types to boolean tensors.")
332
+ .TypeAndShapeInferenceFunction([](InferenceContext& ctx) {
333
+ propagateElemTypeFromInputToOutput(ctx, 0, 0);
334
+ if (hasInputShape(ctx, 0)) {
335
+ propagateShapeFromInputToOutput(ctx, 0, 0);
336
+ }
337
+
338
+ if (ctx.getNumInputs() > 1 && hasInputShape(ctx, 1)) {
339
+ auto& ratio_input_shape = getInputShape(ctx, 1);
340
+ if (static_cast<int>(ratio_input_shape.dim_size()) != 0) {
341
+ fail_shape_inference("Ratio of Dropout must be a scalar.");
342
+ }
343
+ }
344
+
345
+ if (ctx.getNumInputs() > 2 && hasInputShape(ctx, 2)) {
346
+ auto& training_mode_input_shape = getInputShape(ctx, 2);
347
+ if (static_cast<int>(training_mode_input_shape.dim_size()) != 0) {
348
+ fail_shape_inference("training_mode of Dropout must be a scalar.");
349
+ }
350
+ }
351
+
352
+ if (ctx.getNumOutputs() == 2) {
353
+ updateOutputElemType(ctx, 1, TensorProto::BOOL);
354
+ if (hasNInputShapes(ctx, 1)) {
355
+ propagateShapeFromInputToOutput(ctx, 0, 1);
356
+ }
357
+ }
358
+ }));
359
+
360
+ static const char* LpNormalization_ver1_doc = R"DOC(
361
+ Given a matrix, apply Lp-normalization along the provided axis.
362
+ )DOC";
363
+
364
+ ONNX_OPERATOR_SET_SCHEMA(
365
+ LpNormalization,
366
+ 1,
367
+ OpSchema()
368
+ .Input(0, "input", "Input matrix", "T", OpSchema::Single, true, 1, OpSchema::Differentiable)
369
+ .Output(0, "output", "Matrix after normalization", "T", OpSchema::Single, true, 1, OpSchema::Differentiable)
370
+ .TypeConstraint(
371
+ "T",
372
+ {"tensor(float16)", "tensor(float)", "tensor(double)"},
373
+ "Constrain input and output types to float tensors.")
374
+ .SetDoc(LpNormalization_ver1_doc)
375
+ .Attr(
376
+ "axis",
377
+ "The axis on which to apply normalization, -1 mean last axis.",
378
+ AttributeProto::INT,
379
+ static_cast<int64_t>(-1))
380
+ .Attr(
381
+ "p",
382
+ "The order of the normalization, only 1 or 2 are supported.",
383
+ AttributeProto::INT,
384
+ static_cast<int64_t>(2))
385
+ .TypeAndShapeInferenceFunction([](InferenceContext& ctx) { propagateShapeAndTypeFromFirstInput(ctx); }));
386
+
387
+ static const char* InstanceNormalization_ver6_doc = R"DOC(
388
+ Carries out instance normalization as described in the paper
389
+ https://arxiv.org/abs/1607.08022.
390
+
391
+ y = scale * (x - mean) / sqrt(variance + epsilon) + B,
392
+ where mean and variance are computed per instance per channel.
393
+
394
+ )DOC";
395
+
396
+ ONNX_OPERATOR_SET_SCHEMA(
397
+ InstanceNormalization,
398
+ 6,
399
+ OpSchema()
400
+ .SetDoc(InstanceNormalization_ver6_doc)
401
+ .Attr("epsilon", "The epsilon value to use to avoid division by zero.", AttributeProto::FLOAT, 1e-5f)
402
+ .Input(
403
+ 0,
404
+ "input",
405
+ "Input data tensor from the previous operator; "
406
+ "dimensions for image case are (N x C x H x W), "
407
+ "where N is the batch size, C is the number of "
408
+ "channels, and H and W are the height and the "
409
+ "width of the data. For non image case, the "
410
+ "dimensions are in the form of "
411
+ "(N x C x D1 x D2 ... Dn), where N is the batch "
412
+ "size.",
413
+ "T",
414
+ OpSchema::Single,
415
+ true,
416
+ 1,
417
+ OpSchema::Differentiable)
418
+ .Input(
419
+ 1,
420
+ "scale",
421
+ "The input 1-dimensional scale tensor of size C.",
422
+ "T",
423
+ OpSchema::Single,
424
+ true,
425
+ 1,
426
+ OpSchema::Differentiable)
427
+ .Input(
428
+ 2,
429
+ "B",
430
+ "The input 1-dimensional bias tensor of size C.",
431
+ "T",
432
+ OpSchema::Single,
433
+ true,
434
+ 1,
435
+ OpSchema::Differentiable)
436
+ .Output(
437
+ 0,
438
+ "output",
439
+ "The output tensor of the same shape as input.",
440
+ "T",
441
+ OpSchema::Single,
442
+ true,
443
+ 1,
444
+ OpSchema::Differentiable)
445
+ .TypeConstraint(
446
+ "T",
447
+ {"tensor(float16)", "tensor(float)", "tensor(double)"},
448
+ "Constrain input and output types to float tensors.")
449
+ .TypeAndShapeInferenceFunction([](InferenceContext& ctx) { propagateShapeAndTypeFromFirstInput(ctx); }));
450
+
451
+ void maxUnpoolShapeInference_opset11(InferenceContext& ctx) {
452
+ // we need at least two inputs to have a shape for this inference.
453
+ if (ctx.getNumInputs() != 2 && ctx.getNumInputs() != 3) {
454
+ fail_type_inference("MaxUnpool op must have either two or three inputs.");
455
+ }
456
+ propagateElemTypeFromInputToOutput(ctx, 0, 0);
457
+ if (!hasInputShape(ctx, 0)) {
458
+ return; // If first input does not have shape, we cannot infer much.
459
+ }
460
+ auto input_shape = ctx.getInputType(0)->tensor_type().shape();
461
+ if (input_shape.dim_size() < 2) {
462
+ fail_shape_inference("Input tensor X must have at least 2 dimensions.");
463
+ }
464
+
465
+ // first dim is the batch axis and the next is the number of channels.
466
+ size_t n_input_dims = static_cast<size_t>(input_shape.dim_size() - 2);
467
+
468
+ std::vector<int64_t> pads;
469
+ if (getRepeatedAttribute(ctx, "pads", pads)) {
470
+ if (pads.size() != n_input_dims * 2) {
471
+ fail_shape_inference("Attribute pads has incorrect size.");
472
+ }
473
+ } else {
474
+ pads.assign(n_input_dims * 2, 0);
475
+ }
476
+
477
+ std::vector<int64_t> strides;
478
+ if (getRepeatedAttribute(ctx, "strides", strides)) {
479
+ if (strides.size() != n_input_dims) {
480
+ fail_shape_inference("Attribute strides has incorrect size.");
481
+ }
482
+ } else {
483
+ strides.assign(n_input_dims, 1);
484
+ }
485
+
486
+ std::vector<int64_t> kernel_shape;
487
+ if (getRepeatedAttribute(ctx, "kernel_shape", kernel_shape)) {
488
+ if (kernel_shape.size() != n_input_dims) {
489
+ fail_shape_inference("Attribute kernel_shape has incorrect size.");
490
+ }
491
+ } else {
492
+ fail_shape_inference("Attribute kernel_shape must be specified.");
493
+ }
494
+
495
+ if (ctx.getNumInputs() == 3) {
496
+ // If the third input, output_size, is specified, then use that instead
497
+ // of inferring shape from inputs.
498
+ if (hasInputShape(ctx, 2)) {
499
+ auto& output_shape = getInputShape(ctx, 2);
500
+ if (output_shape.dim_size() != 1) {
501
+ fail_type_inference("'output_shape' must be rank 1 tensor.");
502
+ }
503
+ if (output_shape.dim(static_cast<int>(0)).has_dim_value() &&
504
+ static_cast<int>(output_shape.dim(static_cast<int>(0)).dim_value()) != input_shape.dim_size()) {
505
+ fail_shape_inference("'output_shape' must have same number of elements as the shape of input tensor X.");
506
+ }
507
+ }
508
+ return; // 'output_shape' is specified as input. Actual shape will be
509
+ // determined at runtime.
510
+ }
511
+
512
+ auto final_output_shape = ctx.getOutputType(0)->mutable_tensor_type()->mutable_shape();
513
+
514
+ *final_output_shape->add_dim() = input_shape.dim(0);
515
+ *final_output_shape->add_dim() =
516
+ ctx.getInputType(1)->tensor_type().shape().dim(1); // channels should be the second dim of second input.
517
+
518
+ int kernel_shape_size = static_cast<int>(kernel_shape.size());
519
+ for (int i = 0; i < kernel_shape_size; ++i) {
520
+ auto newdim = final_output_shape->add_dim();
521
+ if (!input_shape.dim(2 + i).has_dim_value()) {
522
+ continue;
523
+ }
524
+
525
+ int64_t newdim_value = strides[i] * (input_shape.dim(2 + i).dim_value() - 1);
526
+ newdim_value += kernel_shape[i];
527
+ newdim_value -= pads[i];
528
+ newdim_value -= pads[i + kernel_shape_size];
529
+
530
+ // add in the initial position
531
+ newdim->set_dim_value(newdim_value);
532
+ }
533
+ }
534
+
535
+ // For GlobalPool operations.
536
+ void globalPoolTypeShapeInference_opset1(InferenceContext& ctx) {
537
+ propagateElemTypeFromInputToOutput(ctx, 0, 0);
538
+
539
+ // needs at least one input with shape.
540
+ if (!hasNInputShapes(ctx, 1)) {
541
+ return;
542
+ }
543
+
544
+ auto input_shape = ctx.getInputType(0)->tensor_type().shape();
545
+ if (input_shape.dim_size() < 2) {
546
+ return;
547
+ }
548
+
549
+ // first dim is the batch axis and the next is the number of channels.
550
+ size_t n_input_dims = static_cast<size_t>(input_shape.dim_size() - 2);
551
+
552
+ // (N, C, 1, 1, ..., 1)
553
+ auto output_shape = ctx.getOutputType(0)->mutable_tensor_type()->mutable_shape();
554
+ *output_shape->add_dim() = input_shape.dim(0);
555
+ *output_shape->add_dim() = input_shape.dim(1);
556
+
557
+ for (size_t i = 0; i < n_input_dims; ++i) {
558
+ output_shape->add_dim()->set_dim_value(1);
559
+ }
560
+ }
561
+
562
+ std::function<void(OpSchema&)> GlobalPoolingOpSchemaGenerator_opset1(const char* op_type, const char* op) {
563
+ return [=](OpSchema& schema) {
564
+ std::string doc;
565
+ POPULATE_OP_DOC_STR(doc = R"DOC(
566
+ Global{op_type} consumes an input tensor X and applies {op} pooling across
567
+ the values in the same channel. This is equivalent to {op_type} with kernel size
568
+ equal to the spatial dimension of input tensor.)DOC";
569
+ ReplaceAll(doc, "{op_type}", op_type);
570
+ ReplaceAll(doc, "{op}", op););
571
+ schema.SetDoc(doc);
572
+ schema.Input(
573
+ 0,
574
+ "X",
575
+ "Input data tensor from the previous operator; "
576
+ "dimensions for image case are (N x C x H x W), "
577
+ "where N is the batch size, C is the number of "
578
+ "channels, and H and W are the height and the width "
579
+ "of the data. For non image case, the dimensions are "
580
+ "in the form of (N x C x D1 x D2 ... Dn), "
581
+ "where N is the batch size.",
582
+ "T",
583
+ OpSchema::Single,
584
+ true,
585
+ 1,
586
+ OpSchema::Differentiable);
587
+ schema.Output(
588
+ 0,
589
+ "Y",
590
+ "Output data tensor from pooling across the input "
591
+ "tensor. The output tensor has the same rank as the input. "
592
+ "The first two dimensions of output shape are the same as "
593
+ "the input (N x C), while the other dimensions are all 1.",
594
+ "T",
595
+ OpSchema::Single,
596
+ true,
597
+ 1,
598
+ OpSchema::Differentiable);
599
+ schema.TypeConstraint(
600
+ "T",
601
+ {"tensor(float16)", "tensor(float)", "tensor(double)"},
602
+ "Constrain input and output types to float tensors.");
603
+ schema.TypeAndShapeInferenceFunction([](InferenceContext& ctx) { globalPoolTypeShapeInference_opset1(ctx); });
604
+ };
605
+ }
606
+ ONNX_OPERATOR_SET_SCHEMA(
607
+ GlobalAveragePool,
608
+ 1,
609
+ OpSchema().FillUsing(GlobalPoolingOpSchemaGenerator_opset1("AveragePool", "average")));
610
+ ONNX_OPERATOR_SET_SCHEMA(
611
+ GlobalMaxPool,
612
+ 1,
613
+ OpSchema().FillUsing(GlobalPoolingOpSchemaGenerator_opset1("MaxPool", "max")));
614
+
615
+ void convTransposeShapeInference_opset11(InferenceContext& ctx) {
616
+ propagateElemTypeFromInputToOutput(ctx, 0, 0);
617
+
618
+ // we need at least two inputs to have a shape for this inference.
619
+ if (!hasNInputShapes(ctx, 2)) {
620
+ return;
621
+ }
622
+
623
+ int64_t group = getAttribute(ctx, "group", 1);
624
+
625
+ auto input_shape = ctx.getInputType(0)->tensor_type().shape();
626
+ if (input_shape.dim_size() < 2) {
627
+ return; // Input tensor should have at least two dimensions.
628
+ }
629
+
630
+ // first dim is the batch axis and the next is the number of channels.
631
+ size_t n_input_dims = static_cast<size_t>(input_shape.dim_size() - 2);
632
+
633
+ std::vector<int64_t> dilations;
634
+ if (getRepeatedAttribute(ctx, "dilations", dilations)) {
635
+ if (dilations.size() != n_input_dims) {
636
+ return;
637
+ }
638
+ } else {
639
+ dilations.assign(n_input_dims, 1);
640
+ }
641
+
642
+ std::vector<int64_t> strides;
643
+ if (getRepeatedAttribute(ctx, "strides", strides)) {
644
+ if (strides.size() != n_input_dims) {
645
+ return;
646
+ }
647
+ } else {
648
+ strides.assign(n_input_dims, 1);
649
+ }
650
+
651
+ std::vector<int64_t> kernel_shape;
652
+ if (getRepeatedAttribute(ctx, "kernel_shape", kernel_shape)) {
653
+ if (kernel_shape.size() != n_input_dims) {
654
+ return;
655
+ }
656
+ } else {
657
+ auto second_input_shape = ctx.getInputType(1)->tensor_type().shape();
658
+ for (int i = 2; i < second_input_shape.dim_size(); ++i) {
659
+ if (!second_input_shape.dim(i).has_dim_value()) {
660
+ return;
661
+ }
662
+ kernel_shape.push_back(second_input_shape.dim(i).dim_value());
663
+ }
664
+ }
665
+
666
+ std::vector<int64_t> effective_kernel_shape = kernel_shape;
667
+ for (int i = 0; i < static_cast<int>(kernel_shape.size()); i++) {
668
+ // accounting for dilation, how big is the kernel in this dimension
669
+ effective_kernel_shape[i] = (effective_kernel_shape[i] - 1) * dilations[i] + 1;
670
+ }
671
+
672
+ std::vector<int64_t> pads;
673
+ if (getRepeatedAttribute(ctx, "pads", pads)) {
674
+ if (pads.size() != n_input_dims * 2) {
675
+ fail_shape_inference("Attribute pads has incorrect size");
676
+ }
677
+ const auto* auto_pad_attr = ctx.getAttribute("auto_pad");
678
+ if (nullptr != auto_pad_attr && auto_pad_attr->s() != "NOTSET") {
679
+ fail_shape_inference("The pads attribute cannot be used simultaneously with auto_pad attribute");
680
+ }
681
+ } else {
682
+ pads.assign(n_input_dims * 2, 0);
683
+ const auto* auto_pad_attr = ctx.getAttribute("auto_pad");
684
+ if ((nullptr != auto_pad_attr) && (auto_pad_attr->s() != "VALID")) {
685
+ int input_dims_size = static_cast<int>(n_input_dims);
686
+ for (int i = 0; i < input_dims_size; ++i) {
687
+ int64_t total_pad = effective_kernel_shape[i] - strides[i];
688
+ if (total_pad < 0)
689
+ total_pad = 0;
690
+ int64_t half_pad_small = total_pad >> 1;
691
+ int64_t half_pad_big = total_pad - half_pad_small;
692
+ if (auto_pad_attr->s() == "SAME_UPPER") {
693
+ pads[i] = half_pad_small;
694
+ pads[i + input_dims_size] = half_pad_big;
695
+ } else if (auto_pad_attr->s() == "SAME_LOWER") {
696
+ pads[i] = half_pad_big;
697
+ pads[i + input_dims_size] = half_pad_small;
698
+ }
699
+ }
700
+ }
701
+ }
702
+
703
+ std::vector<int64_t> output_shape;
704
+ bool output_shape_presented = true;
705
+ if (getRepeatedAttribute(ctx, "output_shape", output_shape)) {
706
+ if (output_shape.size() != n_input_dims) {
707
+ return;
708
+ }
709
+ } else {
710
+ output_shape_presented = false;
711
+ }
712
+
713
+ std::vector<int64_t> output_padding;
714
+ if (getRepeatedAttribute(ctx, "output_padding", output_padding)) {
715
+ if (output_padding.size() != n_input_dims) { // Added only to one side.
716
+ return;
717
+ }
718
+ } else {
719
+ output_padding.assign(n_input_dims, 0);
720
+ }
721
+
722
+ auto final_output_shape = ctx.getOutputType(0)->mutable_tensor_type()->mutable_shape();
723
+
724
+ *final_output_shape->add_dim() = input_shape.dim(0);
725
+ *final_output_shape->add_dim() =
726
+ ctx.getInputType(1)->tensor_type().shape().dim(1) * group; // channels should be the second dim of second input
727
+ // multiply group.
728
+
729
+ int size_of_output;
730
+ if (output_shape_presented) {
731
+ size_of_output = static_cast<int>(output_shape.size());
732
+ for (int i = 0; i < size_of_output; ++i) {
733
+ if (input_shape.dim(i + 2).has_dim_value()) {
734
+ if (output_shape[i] < input_shape.dim(i + 2).dim_value()) {
735
+ // TODO: throw exception?
736
+ return; // output shape value cannot be smaller than the input shape
737
+ // value
738
+ }
739
+ }
740
+ final_output_shape->add_dim()->set_dim_value(output_shape[i]);
741
+ }
742
+ return;
743
+ } else {
744
+ size_of_output = input_shape.dim_size() - 2;
745
+ for (int i = 0; i < size_of_output; ++i) {
746
+ if (input_shape.dim(i + 2).has_dim_value()) {
747
+ int64_t output_shape_dim = strides[i] * (input_shape.dim(i + 2).dim_value() - 1) + output_padding[i] +
748
+ effective_kernel_shape[i] - pads[i] - pads[i + n_input_dims];
749
+ final_output_shape->add_dim()->set_dim_value(output_shape_dim);
750
+ } else {
751
+ final_output_shape->add_dim();
752
+ }
753
+ }
754
+ return;
755
+ }
756
+ }
757
+
758
+ static const char* DeformConv_ver19_doc = R"DOC(
759
+ Performs deformable convolution as described in https://arxiv.org/abs/1703.06211 and https://arxiv.org/abs/1811.11168.
760
+ This operator specification supports the general N-D case. Note that most common use cases have 2D or 3D data.
761
+ )DOC";
762
+
763
+ ONNX_OPERATOR_SET_SCHEMA(
764
+ DeformConv,
765
+ 19,
766
+ OpSchema()
767
+ .SetDoc(DeformConv_ver19_doc)
768
+ .Input(
769
+ 0,
770
+ "X",
771
+ "Input data tensor. For 2D image data, it has shape (N, C, H, W) where N is the batch size, "
772
+ "C is the number of input channels, and H and W are the height and width. "
773
+ "In general, the shape is (N, C, D1, D2, ... , Dn) for n-dimensional data, where "
774
+ "D1 to Dn are the spatial dimension sizes. Most common use cases have n = 2 or 3.",
775
+ "T")
776
+ .Input(
777
+ 1,
778
+ "W",
779
+ "Weight tensor that will be used in the convolutions. It has shape (oC, C/group, kH, kW), "
780
+ "where oC is the number of output channels and kH and kW are the kernel height and width. "
781
+ "For more than 2 dimensions, it has shape (oC, C/group, k1, k2, ... , kn).",
782
+ "T")
783
+ .Input(
784
+ 2,
785
+ "offset",
786
+ "Offset tensor denoting the offset for the sampling locations in the convolution kernel. "
787
+ "It has shape (N, offset_group * kH * kW * 2, oH, oW) for 2D data or "
788
+ "(N, offset_group * k1 * k2 * ... * kn * n, o1, o2, ... , on) for nD data. Use linear interpolation"
789
+ "for fractional offset values. Sampling locations outside of the padded input tensor gives zero.",
790
+ "T")
791
+ .Input(
792
+ 3,
793
+ "B",
794
+ "Optional 1D bias of length oC to be added to the convolution. Default is a tensor of zeros.",
795
+ "T",
796
+ OpSchema::Optional)
797
+ .Input(
798
+ 4,
799
+ "mask",
800
+ "The mask tensor to be applied to each position in the convolution kernel. "
801
+ "It has shape (N, offset_group * kH * kW, oH, oW) for 2D data or "
802
+ "(N, offset_group * k1 * k2 * ... * kn * n, o1, o2, ... , on) for nD data. Default is a "
803
+ "tensor of ones.",
804
+ "T",
805
+ OpSchema::Optional)
806
+ .Output(
807
+ 0,
808
+ "Y",
809
+ "Output data tensor that contains the result of convolution. It has shape (N, oC, oH, oW) "
810
+ "for 2D data or (N, oC, o1, o2, ..., on) for nD data",
811
+ "T")
812
+ .TypeConstraint(
813
+ "T",
814
+ {"tensor(float16)", "tensor(float)", "tensor(double)"},
815
+ "Constrain input and output types to float tensors.")
816
+ .Attr(
817
+ "dilations",
818
+ "Dilation value along each spatial axis of the kernel. Default is 1 along each axis.",
819
+ AttributeProto::INTS,
820
+ OPTIONAL_VALUE)
821
+ .Attr(
822
+ "group",
823
+ "Number of groups the input and output channels, C and oC, are divided into. C and oC must both "
824
+ "be divisible by group. Default is 1.",
825
+ AttributeProto::INT,
826
+ static_cast<int64_t>(1))
827
+ .Attr(
828
+ "kernel_shape",
829
+ "Shape of the convolution kernel. If not present, it is inferred from the shape of input W.",
830
+ AttributeProto::INTS,
831
+ OPTIONAL_VALUE)
832
+ .Attr(
833
+ "offset_group",
834
+ "Number of groups of offset. C must be divisible by offset_group. Default is 1.",
835
+ AttributeProto::INT,
836
+ static_cast<int64_t>(1))
837
+ .Attr(
838
+ "pads",
839
+ "Padding for the beginning and end along each spatial axis. The values represent the number of pixels "
840
+ "added to the beginning and end of the corresponding axis and can take any nonnegative value. "
841
+ "The format should be as follows: [x1_begin, x2_begin, ..., x1_end, x2_end, ...], where xi_begin "
842
+ "is the number of pixels added at the beginning of axis `i` and xi_end is the number of pixels "
843
+ "added at the end of axis `i`. Default is 0 along each axis.",
844
+ AttributeProto::INTS,
845
+ OPTIONAL_VALUE)
846
+ .Attr(
847
+ "strides",
848
+ "Stride along each spatial axis. Default is 1 along each axis.",
849
+ AttributeProto::INTS,
850
+ OPTIONAL_VALUE)
851
+ .TypeAndShapeInferenceFunction([](InferenceContext& ctx) {
852
+ propagateElemTypeFromInputToOutput(ctx, 0, 0);
853
+ convPoolShapeInference_opset19(ctx, true, false, 0, 1);
854
+ }));
855
+
856
+ std::function<void(OpSchema&)> ConvTransposeOpSchemaGenerator_opset11(const char* filter_desc) {
857
+ return [=](OpSchema& schema) {
858
+ std::string doc;
859
+ POPULATE_OP_DOC_STR(doc = R"DOC(
860
+ The convolution transpose operator consumes an input tensor and {filter_desc},
861
+ and computes the output.
862
+
863
+ If the pads parameter is provided the shape of the output is calculated via the following equation:
864
+
865
+ output_shape[i] = stride[i] * (input_size[i] - 1) + output_padding[i] + ((kernel_shape[i] - 1) * dilations[i] + 1) - pads[start_i] - pads[end_i]
866
+
867
+ output_shape can also be explicitly specified in which case pads values are auto generated using these equations:
868
+
869
+ total_padding[i] = stride[i] * (input_size[i] - 1) + output_padding[i] + ((kernel_shape[i] - 1) * dilations[i] + 1) - output_shape[i]
870
+ If (auto_pads == SAME_UPPER): pads[start_i] = total_padding[i]/2; pads[end_i] = total_padding[i] - (total_padding[i]/2)
871
+ Else: pads[start_i] = total_padding[i] - (total_padding[i]/2); pads[end_i] = (total_padding[i]/2).
872
+
873
+ )DOC";
874
+ ReplaceAll(doc, "{filter_desc}", filter_desc););
875
+ schema.SetDoc(doc);
876
+ schema.Input(
877
+ 0,
878
+ "X",
879
+ "Input data tensor from previous layer; has size (N x C x H x W)"
880
+ ", where N is the batch size, C is the number of channels, and"
881
+ " H and W are the height and width. Note that this is for the 2D image. "
882
+ "Otherwise the size is (N x C x D1 x D2 ... x Dn)",
883
+ "T",
884
+ OpSchema::Single,
885
+ true,
886
+ 1,
887
+ OpSchema::Differentiable);
888
+ schema.Input(
889
+ 1,
890
+ "W",
891
+ "The weight tensor that will be used in the "
892
+ "convolutions; has size (C x M/group x kH x kW), where C "
893
+ "is the number of channels, and kH and kW are the "
894
+ "height and width of the kernel, and M is the number "
895
+ "of feature maps. For more than 2 dimensions, the "
896
+ "weight shape will be (C x M/group x k1 x k2 x ... x kn), "
897
+ "where (k1 x k2 x ... x kn) is the dimension of the kernel. "
898
+ "The number of channels in the output should be equal to W.shape[1] * group "
899
+ "(assuming zero based indices of the shape array)",
900
+ "T",
901
+ OpSchema::Single,
902
+ true,
903
+ 1,
904
+ OpSchema::Differentiable);
905
+ schema.Input(
906
+ 2,
907
+ "B",
908
+ "Optional 1D bias to be added to the convolution, has size of M.",
909
+ "T",
910
+ OpSchema::Optional,
911
+ true,
912
+ 1,
913
+ OpSchema::Differentiable);
914
+ schema.Output(
915
+ 0,
916
+ "Y",
917
+ "Output data tensor that contains the result of the convolution. The "
918
+ "output dimensions are functions of the kernel size, stride size, "
919
+ "pad lengths and group count. "
920
+ "The number of channels in the output should be equal to W.shape[1] * group "
921
+ "(assuming zero based indices of the shape array)",
922
+ "T",
923
+ OpSchema::Single,
924
+ true,
925
+ 1,
926
+ OpSchema::Differentiable);
927
+ schema.TypeConstraint(
928
+ "T",
929
+ {"tensor(float16)", "tensor(float)", "tensor(double)"},
930
+ "Constrain input and output types to float tensors.");
931
+ schema.Attr(
932
+ "kernel_shape",
933
+ "The shape of the convolution kernel. If not present, should be inferred from input W.",
934
+ AttributeProto::INTS,
935
+ OPTIONAL_VALUE);
936
+ schema.Attr(
937
+ "output_shape",
938
+ "The shape of the output can be explicitly set which will cause pads values to be auto generated. If output_shape is specified "
939
+ "pads values are ignored. See doc for details for equations to generate pads. Note that the output_shape attribute value "
940
+ "should not include dimensions for batch size and channels, which are automatically inferred.",
941
+ AttributeProto::INTS,
942
+ OPTIONAL_VALUE);
943
+ schema.Attr(
944
+ "output_padding",
945
+ "Additional elements added to the side with higher coordinate indices in the output. "
946
+ "Each padding value in \"output_padding\" must be less than the corresponding stride/dilation dimension. "
947
+ "By default, this attribute is a zero vector. "
948
+ "Note that this attribute doesn't directly affect the computed output values. "
949
+ "It only controls the selection of the computed values, "
950
+ "so changing this attribute only adds or removes output elements. "
951
+ "If \"output_shape\" is explicitly provided, "
952
+ "\"output_padding\" does not contribute additional size to \"output_shape\" but "
953
+ "participates in the computation of the needed padding amount. "
954
+ "This is also called adjs or adjustment in some frameworks.",
955
+ AttributeProto::INTS,
956
+ OPTIONAL_VALUE);
957
+ schema.Attr(
958
+ "dilations",
959
+ "dilation value along each spatial axis of the filter. If not present, the dilation defaults to 1 along each spatial axis.",
960
+ AttributeProto::INTS,
961
+ OPTIONAL_VALUE);
962
+ schema.Attr(
963
+ "strides",
964
+ "Stride along each spatial axis. If not present, the stride defaults to 1 along each spatial axis.",
965
+ AttributeProto::INTS,
966
+ OPTIONAL_VALUE);
967
+ schema.Attr("auto_pad", conv_transpose_auto_pad_doc_opset19, AttributeProto::STRING, std::string("NOTSET"));
968
+ schema.Attr("pads", pads_doc_opset11, AttributeProto::INTS, OPTIONAL_VALUE);
969
+ schema.Attr(
970
+ "group",
971
+ "number of groups input channels and output channels are divided into.",
972
+ AttributeProto::INT,
973
+ static_cast<int64_t>(1));
974
+ schema.TypeAndShapeInferenceFunction([](InferenceContext& ctx) { convTransposeShapeInference_opset11(ctx); });
975
+ };
976
+ }
977
+
978
+ ONNX_OPERATOR_SET_SCHEMA(ConvTranspose, 11, OpSchema().FillUsing(ConvTransposeOpSchemaGenerator_opset11("a filter")));
979
+
980
+ std::function<void(OpSchema&)> ConvOpSchemaGenerator_opset11(const char* filter_desc) {
981
+ return [=](OpSchema& schema) {
982
+ std::string doc;
983
+ POPULATE_OP_DOC_STR(doc = R"DOC(
984
+ The convolution operator consumes an input tensor and {filter_desc}, and
985
+ computes the output.)DOC";
986
+ ReplaceAll(doc, "{filter_desc}", filter_desc););
987
+ schema.SetDoc(doc);
988
+ schema.Input(
989
+ 0,
990
+ "X",
991
+ "Input data tensor from previous layer; "
992
+ "has size (N x C x H x W), where N is the batch size, "
993
+ "C is the number of channels, and H and W are the "
994
+ "height and width. Note that this is for the 2D image. "
995
+ "Otherwise the size is (N x C x D1 x D2 ... x Dn). "
996
+ "Optionally, if dimension denotation is "
997
+ "in effect, the operation expects input data tensor "
998
+ "to arrive with the dimension denotation of [DATA_BATCH, "
999
+ "DATA_CHANNEL, DATA_FEATURE, DATA_FEATURE ...].",
1000
+ "T",
1001
+ OpSchema::Single,
1002
+ true,
1003
+ 1,
1004
+ OpSchema::Differentiable);
1005
+ schema.Input(
1006
+ 1,
1007
+ "W",
1008
+ "The weight tensor that will be used in the "
1009
+ "convolutions; has size (M x C/group x kH x kW), where C "
1010
+ "is the number of channels, and kH and kW are the "
1011
+ "height and width of the kernel, and M is the number "
1012
+ "of feature maps. For more than 2 dimensions, the "
1013
+ "kernel shape will be (M x C/group x k1 x k2 x ... x kn), "
1014
+ "where (k1 x k2 x ... kn) is the dimension of the kernel. "
1015
+ "Optionally, if dimension denotation is in effect, "
1016
+ "the operation expects the weight tensor to arrive "
1017
+ "with the dimension denotation of [FILTER_OUT_CHANNEL, "
1018
+ "FILTER_IN_CHANNEL, FILTER_SPATIAL, FILTER_SPATIAL ...]. "
1019
+ "Assuming zero based indices for the shape array, "
1020
+ "X.shape[1] == (W.shape[1] * group) == C and "
1021
+ "W.shape[0] mod G == 0. Or in other words "
1022
+ "FILTER_IN_CHANNEL multiplied by the number of groups "
1023
+ "should be equal to DATA_CHANNEL and the number of "
1024
+ "feature maps M should be a multiple of the number of "
1025
+ "groups G.",
1026
+ "T",
1027
+ OpSchema::Single,
1028
+ true,
1029
+ 1,
1030
+ OpSchema::Differentiable);
1031
+ schema.Input(
1032
+ 2,
1033
+ "B",
1034
+ "Optional 1D bias to be added to the convolution, has size of M.",
1035
+ "T",
1036
+ OpSchema::Optional,
1037
+ true,
1038
+ 1,
1039
+ OpSchema::Differentiable);
1040
+ schema.Output(
1041
+ 0,
1042
+ "Y",
1043
+ "Output data tensor that contains the result of the "
1044
+ "convolution. The output dimensions are functions "
1045
+ "of the kernel size, stride size, and pad lengths.",
1046
+ "T",
1047
+ OpSchema::Single,
1048
+ true,
1049
+ 1,
1050
+ OpSchema::Differentiable);
1051
+ schema.TypeConstraint(
1052
+ "T",
1053
+ {"tensor(float16)", "tensor(float16)", "tensor(float)", "tensor(double)"},
1054
+ "Constrain input and output types to float tensors.");
1055
+ schema.Attr(
1056
+ "kernel_shape",
1057
+ "The shape of the convolution kernel. If not present, should be inferred from input W.",
1058
+ AttributeProto::INTS,
1059
+ OPTIONAL_VALUE);
1060
+ schema.Attr(
1061
+ "dilations",
1062
+ "dilation value along each spatial axis of the filter. If not present, the dilation defaults is 1 along each spatial axis.",
1063
+ AttributeProto::INTS,
1064
+ OPTIONAL_VALUE);
1065
+ schema.Attr(
1066
+ "strides",
1067
+ "Stride along each spatial axis. If not present, the stride defaults is 1 along each spatial axis.",
1068
+ AttributeProto::INTS,
1069
+ OPTIONAL_VALUE);
1070
+ schema.Attr("auto_pad", conv_auto_pad_doc_opset19, AttributeProto::STRING, std::string("NOTSET"));
1071
+ schema.Attr("pads", pads_doc_opset11, AttributeProto::INTS, OPTIONAL_VALUE);
1072
+ schema.Attr(
1073
+ "group",
1074
+ "number of groups input channels and output channels are divided into.",
1075
+ AttributeProto::INT,
1076
+ static_cast<int64_t>(1));
1077
+ schema.TypeAndShapeInferenceFunction([](InferenceContext& ctx) {
1078
+ propagateElemTypeFromInputToOutput(ctx, 0, 0);
1079
+ convPoolShapeInference_opset19(ctx, true, false, 0, 1);
1080
+ });
1081
+ };
1082
+ }
1083
+
1084
+ ONNX_OPERATOR_SET_SCHEMA(Conv, 11, OpSchema().FillUsing(ConvOpSchemaGenerator_opset11("a filter")));
1085
+
1086
+ void roiPoolTypeShapeInference_opset1(InferenceContext& ctx) {
1087
+ propagateElemTypeFromInputToOutput(ctx, 0, 0);
1088
+
1089
+ // rois is the second input.
1090
+ if (!hasNInputShapes(ctx, 2)) {
1091
+ return;
1092
+ }
1093
+
1094
+ auto input_shape = ctx.getInputType(0)->tensor_type().shape();
1095
+ auto rios_shape = ctx.getInputType(1)->tensor_type().shape();
1096
+
1097
+ if (input_shape.dim_size() < 2) {
1098
+ fail_shape_inference("Input tensor must have at least 2 dimensions");
1099
+ }
1100
+ if (rios_shape.dim_size() != 2) {
1101
+ fail_shape_inference("RoIs tensor must have 2 dimensions");
1102
+ }
1103
+
1104
+ // first dim is the batch axis and the next is the number of channels.
1105
+ size_t n_input_dims = static_cast<size_t>(input_shape.dim_size() - 2);
1106
+
1107
+ std::vector<int64_t> pooled_shape;
1108
+ if (getRepeatedAttribute(ctx, "pooled_shape", pooled_shape)) {
1109
+ if (pooled_shape.size() != n_input_dims) {
1110
+ fail_shape_inference("Attribute pooled_shape has incorrect length");
1111
+ }
1112
+ } else {
1113
+ fail_shape_inference("Attribute pooled_shape must be specified");
1114
+ }
1115
+
1116
+ // (num_rois, channels, pooled_shape[0], pooled_shape[1])
1117
+ auto output_shape = ctx.getOutputType(0)->mutable_tensor_type()->mutable_shape();
1118
+
1119
+ *output_shape->add_dim() = rios_shape.dim(0);
1120
+ *output_shape->add_dim() = input_shape.dim(1);
1121
+ output_shape->add_dim()->set_dim_value(pooled_shape[0]);
1122
+ output_shape->add_dim()->set_dim_value(pooled_shape[1]);
1123
+ }
1124
+
1125
+ std::function<void(OpSchema&)> RoiPoolOpSchemaGenerator_opset1(const char* name) {
1126
+ return [=](OpSchema& schema) {
1127
+ std::string doc;
1128
+ POPULATE_OP_DOC_STR(doc = R"DOC(
1129
+ ROI {name} pool consumes an input tensor X and region of interests (RoIs) to
1130
+ apply {name} pooling across each RoI, to produce output 4-D tensor of shape
1131
+ (num_rois, channels, pooled_shape[0], pooled_shape[1]).)DOC";
1132
+ ReplaceAll(doc, "{name}", name););
1133
+ schema.SetDoc(doc);
1134
+ schema.Attr("pooled_shape", "ROI pool output shape (height, width).", AttributeProto::INTS);
1135
+ schema.Attr(
1136
+ "spatial_scale",
1137
+ "Multiplicative spatial scale factor to translate ROI coordinates from their input scale to the scale used when pooling.",
1138
+ AttributeProto::FLOAT,
1139
+ 1.f);
1140
+ schema.Input(
1141
+ 0,
1142
+ "X",
1143
+ "Input data tensor from the previous operator; "
1144
+ "dimensions for image case are (N x C x H x W), "
1145
+ "where N is the batch size, C is the number of "
1146
+ "channels, and H and W are the height and the "
1147
+ "width of the data.",
1148
+ "T",
1149
+ OpSchema::Single,
1150
+ true,
1151
+ 1,
1152
+ OpSchema::Differentiable);
1153
+ schema.Input(
1154
+ 1,
1155
+ "rois",
1156
+ "RoIs (Regions of Interest) to pool over. Should "
1157
+ "be a 2-D tensor of shape (num_rois, 5) given as "
1158
+ "[[batch_id, x1, y1, x2, y2], ...].",
1159
+ "T",
1160
+ OpSchema::Single,
1161
+ true,
1162
+ 1,
1163
+ OpSchema::NonDifferentiable);
1164
+ schema.Output(
1165
+ 0,
1166
+ "Y",
1167
+ "RoI pooled output 4-D tensor of shape (num_rois, channels, pooled_shape[0], pooled_shape[1]).",
1168
+ "T",
1169
+ OpSchema::Single,
1170
+ true,
1171
+ 1,
1172
+ OpSchema::Differentiable);
1173
+ schema.TypeConstraint(
1174
+ "T",
1175
+ {"tensor(float16)", "tensor(float)", "tensor(double)"},
1176
+ "Constrain input and output types to float tensors.");
1177
+ schema.TypeAndShapeInferenceFunction([](InferenceContext& ctx) { roiPoolTypeShapeInference_opset1(ctx); });
1178
+ };
1179
+ }
1180
+
1181
+ ONNX_OPERATOR_SET_SCHEMA(MaxRoiPool, 1, OpSchema().FillUsing(RoiPoolOpSchemaGenerator_opset1("max")));
1182
+
1183
+ std::function<void(OpSchema&)> LpPoolOpSchemaGenerator_opset18(const char* name) {
1184
+ return [=](OpSchema& schema) {
1185
+ std::string doc;
1186
+ POPULATE_OP_DOC_STR(doc = R"DOC(
1187
+ {name} consumes an input tensor X and applies Lp pooling across
1188
+ the tensor according to kernel sizes, stride sizes, and pad lengths.
1189
+ Lp pooling consisting of computing the Lp norm on all values of a subset
1190
+ of the input tensor according to the kernel size and downsampling the
1191
+ data into the output tensor Y for further processing. The output spatial shape will be following:
1192
+ ```
1193
+ output_spatial_shape[i] = floor((input_spatial_shape[i] + pad_shape[i] - {kernelSpatialShape}) / strides_spatial_shape[i] + 1)
1194
+ ```
1195
+ or
1196
+ ```
1197
+ output_spatial_shape[i] = ceil((input_spatial_shape[i] + pad_shape[i] - {kernelSpatialShape}) / strides_spatial_shape[i] + 1)
1198
+ ```
1199
+ if ceil_mode is enabled `pad_shape[i]` is the sum of pads along axis `i`.
1200
+
1201
+ `auto_pad` is a DEPRECATED attribute. If you are using them currently, the output spatial shape will be following:
1202
+ ```
1203
+ VALID: output_spatial_shape[i] = ceil((input_spatial_shape[i] - {kernelSpatialShape} + 1) / strides_spatial_shape[i])
1204
+ SAME_UPPER or SAME_LOWER: output_spatial_shape[i] = ceil(input_spatial_shape[i] / strides_spatial_shape[i])
1205
+ ```
1206
+ And pad shape will be following if `SAME_UPPER` or `SAME_LOWER`:
1207
+ ```
1208
+ pad_shape[i] = (output_spatial_shape[i] - 1) * strides_spatial_shape[i] + {kernelSpatialShape} - input_spatial_shape[i]
1209
+ ```)DOC";
1210
+ ReplaceAll(doc, "{name}", name););
1211
+ schema.SetDoc(doc);
1212
+ schema.Attr("kernel_shape", "The size of the kernel along each axis.", AttributeProto::INTS);
1213
+ schema.Attr(
1214
+ "strides",
1215
+ "Stride along each spatial axis. If not present, the stride defaults to 1 along each spatial axis.",
1216
+ AttributeProto::INTS,
1217
+ OPTIONAL_VALUE);
1218
+ schema.Attr(
1219
+ "dilations",
1220
+ "dilation value along each spatial axis of the filter. If not present, the dilation defaults is 1 along each spatial axis.",
1221
+ AttributeProto::INTS,
1222
+ OPTIONAL_VALUE);
1223
+ schema.Attr("auto_pad", conv_auto_pad_doc_opset19, AttributeProto::STRING, std::string("NOTSET"));
1224
+ schema.Attr("pads", pads_doc_opset11, AttributeProto::INTS, OPTIONAL_VALUE);
1225
+ schema.Attr(
1226
+ "p", "p value of the Lp norm used to pool over the input data.", AttributeProto::INT, static_cast<int64_t>(2));
1227
+ schema.Attr(
1228
+ "ceil_mode",
1229
+ "Whether to use ceil or floor (default) to compute the output shape.",
1230
+ AttributeProto::INT,
1231
+ static_cast<int64_t>(0));
1232
+ schema.Input(
1233
+ 0,
1234
+ "X",
1235
+ "Input data tensor from the previous operator; "
1236
+ "dimensions for image case are (N x C x H x W), "
1237
+ "where N is the batch size, C is the number of "
1238
+ "channels, and H and W are the height and the "
1239
+ "width of the data. For non image case, the "
1240
+ "dimensions are in the form of "
1241
+ "(N x C x D1 x D2 ... Dn), where N is the "
1242
+ "batch size.",
1243
+ "T",
1244
+ OpSchema::Single,
1245
+ true,
1246
+ 1,
1247
+ OpSchema::Differentiable);
1248
+ schema.Output(
1249
+ 0,
1250
+ "Y",
1251
+ "Output data tensor from Lp pooling across the input "
1252
+ "tensor. Dimensions will vary based on various kernel, stride, and pad "
1253
+ "sizes.",
1254
+ "T",
1255
+ OpSchema::Single,
1256
+ true,
1257
+ 1,
1258
+ OpSchema::Differentiable);
1259
+ schema.TypeConstraint(
1260
+ "T",
1261
+ {"tensor(float16)", "tensor(float)", "tensor(double)"},
1262
+ "Constrain input and output types to float tensors.");
1263
+ schema.TypeAndShapeInferenceFunction([](InferenceContext& ctx) {
1264
+ propagateElemTypeFromInputToOutput(ctx, 0, 0);
1265
+ convPoolShapeInference_opset19(ctx, true, true, 0, 1);
1266
+ });
1267
+ };
1268
+ }
1269
+
1270
+ ONNX_OPERATOR_SET_SCHEMA(LpPool, 18, OpSchema().FillUsing(LpPoolOpSchemaGenerator_opset18("LpPool")));
1271
+
1272
+ static const char* MaxUnpool_ver11_doc = R"DOC(
1273
+ MaxUnpool essentially computes the partial inverse of the MaxPool op.
1274
+ The input information to this op is typically the output information from a MaxPool op. The first
1275
+ input tensor X is the tensor that needs to be unpooled, which is typically the pooled tensor (first output)
1276
+ from MaxPool. The second input tensor, I, contains the indices to the (locally maximal) elements corresponding
1277
+ to the elements in the first input tensor X. Input tensor I is typically the second output of the MaxPool op.
1278
+ The third (optional) input is a tensor that specifies the output size of the unpooling operation.
1279
+
1280
+ MaxUnpool is intended to do 'partial' inverse of the MaxPool op. 'Partial' because all the non-maximal
1281
+ values from the original input to MaxPool are set to zero in the output of the MaxUnpool op. Pooling
1282
+ the result of an unpooling operation should give back the original input to the unpooling op.
1283
+
1284
+ MaxUnpool can produce the same output size for several input sizes, which makes unpooling op ambiguous.
1285
+ The third input argument, output_size, is meant to disambiguate the op and produce output tensor of
1286
+ known/predictable size.
1287
+
1288
+ In addition to the inputs, MaxUnpool takes three attributes, namely kernel_shape, strides, and pads,
1289
+ which define the exact unpooling op. The attributes typically have the same values as the corresponding
1290
+ pooling op that the unpooling op is trying to invert.
1291
+ )DOC";
1292
+
1293
+ ONNX_OPERATOR_SET_SCHEMA(
1294
+ MaxUnpool,
1295
+ 11,
1296
+ OpSchema()
1297
+ .SetDoc(MaxUnpool_ver11_doc)
1298
+ .Attr("kernel_shape", "The size of the kernel along each axis.", AttributeProto::INTS)
1299
+ .Attr(
1300
+ "strides",
1301
+ "Stride along each spatial axis. If not present, the stride defaults to 1 along each spatial axis.",
1302
+ AttributeProto::INTS,
1303
+ OPTIONAL_VALUE)
1304
+ .Attr("pads", pads_doc_opset11, AttributeProto::INTS, OPTIONAL_VALUE)
1305
+ .Input(
1306
+ 0,
1307
+ "X",
1308
+ "Input data tensor that has to be unpooled. "
1309
+ "This tensor is typically the first output of the MaxPool op."
1310
+ "Dimensions for image case are (N x C x H x W), "
1311
+ "where N is the batch size, C is the number of "
1312
+ "channels, and H and W are the height and the "
1313
+ "width of the data. For non-image case, the "
1314
+ "dimensions are in the form of "
1315
+ "(N x C x D1 x D2 ... Dn), where N is the batch "
1316
+ "size. Optionally, if dimension denotation is "
1317
+ "in effect, the operation expects the input "
1318
+ "data tensor to arrive with the dimension denotation "
1319
+ "of [DATA_BATCH, DATA_CHANNEL, DATA_FEATURE, DATA_FEATURE ...].",
1320
+ "T1",
1321
+ OpSchema::Single,
1322
+ true,
1323
+ 1,
1324
+ OpSchema::Differentiable)
1325
+ .Input(
1326
+ 1,
1327
+ "I",
1328
+ "Input data tensor containing the indices corresponding to "
1329
+ "elements in the first input tensor X."
1330
+ "This tensor is typically the second output of the MaxPool op."
1331
+ "Dimensions must be the same as input tensor X. "
1332
+ "The indices are linear, i.e. computed considering the tensor as flattened 1-D tensor, "
1333
+ "assuming row-major storage. Also, the linear indices should not consider padding. "
1334
+ "So the values in indices are in the range [0, N x C x D1 x ... x Dn).",
1335
+ "T2",
1336
+ OpSchema::Single,
1337
+ true,
1338
+ 1,
1339
+ OpSchema::NonDifferentiable)
1340
+ .Input(
1341
+ 2,
1342
+ "output_shape",
1343
+ "The shape of the output can be explicitly set which will cause pads values to be auto generated. If 'output_shape' is specified, "
1344
+ "'pads' values are ignored.",
1345
+ "T2",
1346
+ OpSchema::Optional,
1347
+ true,
1348
+ 1,
1349
+ OpSchema::NonDifferentiable)
1350
+ .Output(
1351
+ 0,
1352
+ "output",
1353
+ "Output data tensor that contains the result of the unpooling.",
1354
+ "T1",
1355
+ OpSchema::Single,
1356
+ true,
1357
+ 1,
1358
+ OpSchema::Differentiable)
1359
+ .TypeConstraint(
1360
+ "T1",
1361
+ {"tensor(float16)", "tensor(float)", "tensor(double)"},
1362
+ "Constrain input and output types to float tensors.")
1363
+ .TypeConstraint("T2", {"tensor(int64)"}, "Constrain index tensor to int64")
1364
+ .TypeAndShapeInferenceFunction([](InferenceContext& ctx) { maxUnpoolShapeInference_opset11(ctx); }));
1365
+
1366
+ std::vector<std::string> GetSupportedDataTypesForPoolingOps_opset19(bool supports8bit) {
1367
+ if (supports8bit) {
1368
+ return {"tensor(float16)", "tensor(float)", "tensor(double)", "tensor(int8)", "tensor(uint8)"};
1369
+ }
1370
+ return {"tensor(float16)", "tensor(float)", "tensor(double)"};
1371
+ }
1372
+
1373
+ std::function<void(OpSchema&)> PoolOpSchemaGenerator_opset19(
1374
+ const char* name,
1375
+ const char* opName,
1376
+ const char* additionalDescription,
1377
+ bool use_dilation,
1378
+ bool supports8bit = false) {
1379
+ return [=](OpSchema& schema) {
1380
+ std::string doc;
1381
+ POPULATE_OP_DOC_STR(
1382
+ doc = R"DOC(
1383
+ {name} consumes an input tensor X and applies {opName} pooling across
1384
+ the tensor according to kernel sizes, stride sizes, and pad lengths.
1385
+ {opName} pooling consisting of computing the {opName} on all values of a
1386
+ subset of the input tensor according to the kernel size and downsampling the
1387
+ data into the output tensor Y for further processing. The output spatial shape is calculated differently
1388
+ depending on whether explicit padding is used, where pads is employed, or auto padding is used, where auto_pad is utilized.
1389
+ With explicit padding (https://pytorch.org/docs/stable/generated/torch.nn.MaxPool2d.html?highlight=maxpool#torch.nn.MaxPool2d):
1390
+ ```
1391
+ output_spatial_shape[i] = floor((input_spatial_shape[i] + pad_shape[i] - dilation[i] * (kernel_shape[i] - 1) - 1) / strides_spatial_shape[i] + 1)
1392
+ ```
1393
+ or
1394
+ ```
1395
+ output_spatial_shape[i] = ceil((input_spatial_shape[i] + pad_shape[i] - dilation[i] * (kernel_shape[i] - 1) - 1) / strides_spatial_shape[i] + 1)
1396
+ ```
1397
+ if ceil_mode is enabled. `pad_shape[i]` is the sum of pads along axis `i`.
1398
+
1399
+ `auto_pad` is a DEPRECATED attribute. If you are using them currently, the output spatial shape will be following when ceil_mode is enabled:
1400
+ ```
1401
+ VALID: output_spatial_shape[i] = ceil((input_spatial_shape[i] - {kernelSpatialShape} + 1) / strides_spatial_shape[i])
1402
+ SAME_UPPER or SAME_LOWER: output_spatial_shape[i] = ceil(input_spatial_shape[i] / strides_spatial_shape[i])
1403
+ ```
1404
+ or when ceil_mode is disabled (https://www.tensorflow.org/api_docs/python/tf/keras/layers/AveragePooling2D):
1405
+ ```
1406
+ VALID: output_spatial_shape[i] = floor((input_spatial_shape[i] - {kernelSpatialShape}) / strides_spatial_shape[i]) + 1
1407
+ SAME_UPPER or SAME_LOWER: output_spatial_shape[i] = floor((input_spatial_shape[i] - 1) / strides_spatial_shape[i]) + 1
1408
+ ```
1409
+ And pad shape will be following if `SAME_UPPER` or `SAME_LOWER`:
1410
+ ```
1411
+ pad_shape[i] = (output_spatial_shape[i] - 1) * strides_spatial_shape[i] + {kernelSpatialShape} - input_spatial_shape[i]
1412
+ ```
1413
+ {additionalDescription}
1414
+ )DOC";
1415
+ ReplaceAll(doc, "{name}", name);
1416
+ ReplaceAll(doc, "{opName}", opName);
1417
+ ReplaceAll(doc, "{additionalDescription}", additionalDescription);
1418
+ ReplaceAll(
1419
+ doc,
1420
+ "{kernelSpatialShape}",
1421
+ use_dilation ? "((kernel_spatial_shape[i] - 1) * dilations[i] + 1)" : "kernel_spatial_shape[i]"););
1422
+ schema.SetDoc(doc);
1423
+ schema.Attr("kernel_shape", "The size of the kernel along each axis.", AttributeProto::INTS);
1424
+ schema.Attr(
1425
+ "strides",
1426
+ "Stride along each spatial axis. If not present, the stride defaults to 1 along each spatial axis.",
1427
+ AttributeProto::INTS,
1428
+ OPTIONAL_VALUE);
1429
+ schema.Attr("auto_pad", conv_auto_pad_doc_opset19, AttributeProto::STRING, std::string("NOTSET"));
1430
+ schema.Attr("pads", pads_doc_opset11, AttributeProto::INTS, OPTIONAL_VALUE);
1431
+ schema.Attr(
1432
+ "ceil_mode",
1433
+ "Whether to use ceil or floor (default) to compute the output shape.",
1434
+ AttributeProto::INT,
1435
+ static_cast<int64_t>(0));
1436
+ schema.Input(
1437
+ 0,
1438
+ "X",
1439
+ "Input data tensor from the previous operator; "
1440
+ "dimensions for image case are (N x C x H x W), "
1441
+ "where N is the batch size, C is the number of "
1442
+ "channels, and H and W are the height and the "
1443
+ "width of the data. For non image case, the "
1444
+ "dimensions are in the form of "
1445
+ "(N x C x D1 x D2 ... Dn), where N is the batch "
1446
+ "size. Optionally, if dimension denotation is "
1447
+ "in effect, the operation expects the input "
1448
+ "data tensor to arrive with the dimension denotation "
1449
+ "of [DATA_BATCH, DATA_CHANNEL, DATA_FEATURE, DATA_FEATURE ...].",
1450
+ "T",
1451
+ OpSchema::Single,
1452
+ true,
1453
+ 1,
1454
+ OpSchema::Differentiable);
1455
+ schema.Output(
1456
+ 0,
1457
+ "Y",
1458
+ "Output data tensor from average or max pooling across "
1459
+ "the input tensor. Dimensions will vary based "
1460
+ "on various kernel, stride, and pad sizes. Floor value of "
1461
+ "the dimension is used",
1462
+ "T",
1463
+ OpSchema::Single,
1464
+ true,
1465
+ 1,
1466
+ OpSchema::Differentiable);
1467
+ schema.TypeConstraint(
1468
+ "T",
1469
+ GetSupportedDataTypesForPoolingOps_opset19(supports8bit),
1470
+ supports8bit ? "Constrain input and output types to float and 8 bit tensors."
1471
+ : "Constrain input and output types to float tensors.");
1472
+ schema.TypeAndShapeInferenceFunction([use_dilation](InferenceContext& ctx) {
1473
+ propagateElemTypeFromInputToOutput(ctx, 0, 0);
1474
+ if (ctx.getNumOutputs() > 1) {
1475
+ // MaxPool with two outputs case.
1476
+ auto output_type = ctx.getOutputType(1);
1477
+ if (output_type->value_case() == TypeProto::kTensorType ||
1478
+ output_type->value_case() == TypeProto::VALUE_NOT_SET) {
1479
+ output_type->mutable_tensor_type()->set_elem_type(TensorProto::INT64);
1480
+ }
1481
+ }
1482
+ convPoolShapeInference_opset19(ctx, use_dilation, true, 0, 1);
1483
+ });
1484
+ };
1485
+ }
1486
+
1487
+ ONNX_OPERATOR_SET_SCHEMA(
1488
+ AveragePool,
1489
+ 19,
1490
+ OpSchema()
1491
+ .FillUsing(PoolOpSchemaGenerator_opset19(
1492
+ "AveragePool",
1493
+ "average",
1494
+ "The output of each pooling window is divided by the number of elements (exclude pad when attribute count_include_pad is zero).",
1495
+ true, /* use_dilation: dilations attribute has been added in opset 19. */
1496
+ false /* supports8bit: does not support 8bit. */))
1497
+ .Attr(
1498
+ "dilations",
1499
+ "Dilation value along each spatial axis of filter. If not present, the dilation defaults to 1 along each spatial axis.",
1500
+ AttributeProto::INTS,
1501
+ OPTIONAL_VALUE)
1502
+ .Attr(
1503
+ "count_include_pad",
1504
+ "Whether include pad pixels when calculating values for the edges. Default is 0, doesn't count include pad.",
1505
+ AttributeProto::INT,
1506
+ static_cast<int64_t>(0)));
1507
+
1508
+ ONNX_OPERATOR_SET_SCHEMA(
1509
+ MaxPool,
1510
+ 12,
1511
+ OpSchema()
1512
+ .FillUsing(PoolOpSchemaGenerator_opset19(
1513
+ "MaxPool",
1514
+ "max",
1515
+ "The output of each pooling window is maximum number of elements exclude pad. ",
1516
+ true,
1517
+ true))
1518
+ .Attr(
1519
+ "storage_order",
1520
+ "The storage order of the tensor. 0 is row major, and 1 is column major. "
1521
+ "This attribute is used only to convert an n-tuple index value into "
1522
+ "a single integer value for producing the second output. ",
1523
+ AttributeProto::INT,
1524
+ static_cast<int64_t>(0))
1525
+ .Attr(
1526
+ "dilations",
1527
+ "Dilation value along each spatial axis of filter. If not present, the dilation defaults to 1 along each spatial axis.",
1528
+ AttributeProto::INTS,
1529
+ OPTIONAL_VALUE)
1530
+ .Output(
1531
+ 1,
1532
+ "Indices",
1533
+ "Indices tensor from max pooling across the input tensor. "
1534
+ "The dimensions of indices are the same as output tensor. "
1535
+ "The values in indices of are the indices of the selected values during pooling. "
1536
+ "The indices are computed as flatten 1-D tensor, "
1537
+ "and the indices do not consider padding. "
1538
+ "So the values in indices are in [0, N x C x D1 x ... x Dn).",
1539
+ "I",
1540
+ OpSchema::Optional,
1541
+ true,
1542
+ 1,
1543
+ OpSchema::NonDifferentiable)
1544
+ .TypeConstraint("I", {"tensor(int64)"}, "Constrain index tensor to int64"));
1545
+
12
1546
  static const char* Dropout_ver12_doc = R"DOC(
13
1547
  Dropout takes an input floating-point tensor, an optional input ratio (floating-point scalar) and an optional input training_mode (boolean scalar). It produces two tensor outputs,
14
1548
  output (floating-point tensor) and mask (optional `Tensor<bool>`). If `training_mode` is true then the output Y will be a random dropout;
@@ -956,8 +2490,8 @@ void maxUnpoolShapeInference1(InferenceContext& ctx) {
956
2490
  if (output_shape.dim_size() != 1) {
957
2491
  fail_type_inference("'output_shape' must be rank 1 tensor.");
958
2492
  }
959
- if (output_shape.dim((int)0).has_dim_value() &&
960
- static_cast<int>(output_shape.dim((int)0).dim_value()) != input_shape.dim_size()) {
2493
+ if (output_shape.dim(static_cast<int>(0)).has_dim_value() &&
2494
+ static_cast<int>(output_shape.dim(static_cast<int>(0)).dim_value()) != input_shape.dim_size()) {
961
2495
  fail_shape_inference("'output_shape' must have same number of elements as the shape of input tensor X.");
962
2496
  }
963
2497
  }