diff --git a/.gitignore b/.gitignore index fbe05e7b..437c6163 100644 --- a/.gitignore +++ b/.gitignore @@ -38,3 +38,20 @@ _doc/sphinxdoc/source/phdoc_static/*.js _doc/sphinxdoc/source/phdoc_static/reveal.js/* _doc/sphinxdoc/source/phdoc_static/style_notebook_snippet.css _unittests/ut_utils/t.* +_doc/sphinxdoc/source/_temp_* +_doc/sphinxdoc/source/all_*.rst +_doc/sphinxdoc/source/blog/* +_doc/sphinxdoc/source/filechanges.rst +_doc/sphinxdoc/source/index_*.rst +_doc/sphinxdoc/source/onnxcustom/* +_doc/sphinxdoc/source/phdoc_templates/*.html +_doc/sphinxdoc/source/README.rst +_doc/sphinxdoc/source/notebooks/reveal.js/* +_doc/sphinxdoc/source/gyexamples/* +_doc/examples/*.dot* +_doc/sphinxdoc/build/* +_doc/sphinxdoc/source/HISTORY.rst +_doc/sphinxdoc/source/LICENSE.txt +_doc/sphinxdoc/source/nbcov*.png +_doc/sphinxdoc/source/notebooks/* +_doc/sphinxdoc/source/gallery/* diff --git a/_doc/sphinxdoc/source/conf.py b/_doc/sphinxdoc/source/conf.py index e7e9e385..b6b22962 100644 --- a/_doc/sphinxdoc/source/conf.py +++ b/_doc/sphinxdoc/source/conf.py @@ -20,7 +20,8 @@ title="onnxcustom", book=True) extensions.extend([ - "sphinxcontrib.blockdiag" + "sphinxcontrib.blockdiag", + "myst_parser" ]) blog_root = "http://www.xavierdupre.fr/app/onnxcustom/helpsphinx/" @@ -111,6 +112,7 @@ 'skorch': 'https://skorch.readthedocs.io/en/stable/', 'sklearn-onnx': 'https://github.com/onnx/sklearn-onnx', 'sphinx-gallery': 'https://github.com/sphinx-gallery/sphinx-gallery', + 'sqlite3': 'https://docs.python.org/3/library/sqlite3.html', 'Stochastic Gradient Descent': 'https://en.wikipedia.org/wiki/Stochastic_gradient_descent', 'tqdm': 'https://github.com/tqdm/tqdm', diff --git a/_doc/sphinxdoc/source/index.rst b/_doc/sphinxdoc/source/index.rst index b227e801..ba1533dc 100644 --- a/_doc/sphinxdoc/source/index.rst +++ b/_doc/sphinxdoc/source/index.rst @@ -70,6 +70,7 @@ Among the tools this package implements, you may find: all_notebooks license other_pages + onnxmd/index Sources available on `github/onnxcustom `_. diff --git a/_doc/sphinxdoc/source/onnxmd/index.rst b/_doc/sphinxdoc/source/onnxmd/index.rst new file mode 100644 index 00000000..d0434296 --- /dev/null +++ b/_doc/sphinxdoc/source/onnxmd/index.rst @@ -0,0 +1,13 @@ + +ONNX projects +============= + +This section only renders markdown documentation +from :epkg:`onnx` or :epkg:`onnxruntime` using Sphinx. +The documentation can be searched. + +.. toctree:: + :maxdepth: 1 + + index_onnx + index_onnxruntime diff --git a/_doc/sphinxdoc/source/onnxmd/index_onnx.rst b/_doc/sphinxdoc/source/onnxmd/index_onnx.rst new file mode 100644 index 00000000..a6dcd12f --- /dev/null +++ b/_doc/sphinxdoc/source/onnxmd/index_onnx.rst @@ -0,0 +1,81 @@ + + +ONNX documentation rendered with Sphinx +======================================= + +.. contents:: + :local: + +Overwiew +++++++++ + +.. toctree:: + :maxdepth: 1 + + onnx_docs/Overview.md + onnx_docs/IR.md + onnx_docs/PythonAPIOverview.md + onnx_docs/OpConventions.md + onnx_docs/DimensionDenotation.md + onnx_docs/Broadcasting.md + onnx_docs/ExternalData.md + onnx_docs/Hub.md + onnx_metadata + onnx_docs/ShapeInference.md + +Syntax +++++++ + +.. toctree:: + :maxdepth: 1 + + onnx_docs/Syntax.md + +Versions +++++++++ + +.. toctree:: + :maxdepth: 1 + + onnx_docs/Versioning.md + onnx_docs/VersionConverter.md + onnx_docs/Relicensing.md + onnx_releases + +Operators ++++++++++ + +.. toctree:: + :maxdepth: 1 + + onnx_operators + onnx_operators_ml + onnx_changelog + onnx_changelog_ml + onnx_test_coverage + onnx_test_coverage_ml + +Contribute +++++++++++ + +.. toctree:: + :maxdepth: 1 + + onnx_contributing + onnx_add_new_op + onnx_docs/ImplementingAnOnnxBackend.md + onnx_docs/OnnxBackendTest.md + onnx_managing + onnx_docs/ONNXIFI.md + onnx_docs/ONNXTypes.md + onnx_docs/TypeAnnotations.md + onnx_docs/TypeDenotation.md + +Training +++++++++ + +.. toctree:: + :maxdepth: 1 + + onnx_docs/DefineDifferentiability.md + \ No newline at end of file diff --git a/_doc/sphinxdoc/source/onnxmd/index_onnxruntime.rst b/_doc/sphinxdoc/source/onnxmd/index_onnxruntime.rst new file mode 100644 index 00000000..87932732 --- /dev/null +++ b/_doc/sphinxdoc/source/onnxmd/index_onnxruntime.rst @@ -0,0 +1,71 @@ + + +onnxruntime markdown documentation rendered with Sphinx +======================================================= + +The full documentation is available on +`onnxruntime.ai/docs `_, +with the `Python API `_. +The following pages renders the `markdown documentation +`_. + +.. contents:: + :local: + +Overwiew +++++++++ + +.. toctree:: + :maxdepth: 1 + + onnxruntime_docs/Roadmap.md + onnxruntime_docs/Privacy.md + onnxruntime_docs/Server.md + onnxruntime_docs/ONNX_Runtime_Server_Usage.md + onnxruntime_docs/FAQ.md + onnxruntime_docs/OperatorKernels.md + +Versions +++++++++ + +.. toctree:: + :maxdepth: 1 + + onnxruntime_docs/Versioning.md + +Contributing +++++++++++++ + +.. toctree:: + :maxdepth: 1 + + onnxruntime_docs/Coding_Conventions_and_Standards.md + onnxruntime_docs/ABI_Dev_Notes.md + onnxruntime_docs/PR_Guidelines.md + onnxruntime_docs/Model_Test.md + onnxruntime_docs/NotesOnThreading.md + onnxruntime_docs/Python_Dev_Notes.md + +C API ++++++ + +.. toctree:: + :maxdepth: 1 + + onnxruntime_docs/How_To_Update_ONNX_Dev_Notes.md + onnxruntime_docs/C_API_Guidelines.md + onnxruntime_docs/cmake_guideline.md + onnxruntime_docs/onnxruntime_extensions.md + onnxruntime_docs/ContribOperators.md + +Others +++++++ + +.. toctree:: + :maxdepth: 1 + + onnxruntime_docs/Android_testing.md + onnxruntime_docs/ORTMobilePackageOperatorTypeSupport.md + onnxruntime_docs/WinML_principles.md + onnxruntime_docs/Reduced_Operator_Kernel_build.md + onnxruntime_docs/ReleaseManagement.md diff --git a/_doc/sphinxdoc/source/onnxmd/onnx_add_new_op.rst b/_doc/sphinxdoc/source/onnxmd/onnx_add_new_op.rst new file mode 100644 index 00000000..9f976693 --- /dev/null +++ b/_doc/sphinxdoc/source/onnxmd/onnx_add_new_op.rst @@ -0,0 +1,9 @@ + + +Adding a new operator +===================== + +.. toctree:: + :maxdepth: 1 + + onnx_docs/AddNewOp.md diff --git a/_doc/sphinxdoc/source/onnxmd/onnx_changelog.rst b/_doc/sphinxdoc/source/onnxmd/onnx_changelog.rst new file mode 100644 index 00000000..cf5dac09 --- /dev/null +++ b/_doc/sphinxdoc/source/onnxmd/onnx_changelog.rst @@ -0,0 +1,9 @@ + + +Change Logs +=========== + +.. toctree:: + :maxdepth: 1 + + onnx_docs/Changelog.md diff --git a/_doc/sphinxdoc/source/onnxmd/onnx_changelog_ml.rst b/_doc/sphinxdoc/source/onnxmd/onnx_changelog_ml.rst new file mode 100644 index 00000000..6fd7a244 --- /dev/null +++ b/_doc/sphinxdoc/source/onnxmd/onnx_changelog_ml.rst @@ -0,0 +1,9 @@ + + +ML Change Logs +============== + +.. toctree:: + :maxdepth: 1 + + onnx_docs/Changelog-ml.md diff --git a/_doc/sphinxdoc/source/onnxmd/onnx_contributing.rst b/_doc/sphinxdoc/source/onnxmd/onnx_contributing.rst new file mode 100644 index 00000000..781cec23 --- /dev/null +++ b/_doc/sphinxdoc/source/onnxmd/onnx_contributing.rst @@ -0,0 +1,9 @@ + + +Contributing +============ + +.. toctree:: + :maxdepth: 1 + + onnx_docs/CONTRIBUTING.md diff --git a/_doc/sphinxdoc/source/onnxmd/onnx_docs/AddNewOp.md b/_doc/sphinxdoc/source/onnxmd/onnx_docs/AddNewOp.md new file mode 100644 index 00000000..369d7e6c --- /dev/null +++ b/_doc/sphinxdoc/source/onnxmd/onnx_docs/AddNewOp.md @@ -0,0 +1,98 @@ + + +# Table of Contents +1. [New Operator or Function](#new_operator_or_function) + 1. [Step 1: Proposing a new operator/function](#step1_new_operator_or_function) + 2. [Step 2: Submit PR](#step2_new_operator_or_function) + 3. [Step 3: PR Review by Operators SIG](#step3_new_operator_or_function) + 4. [Step 4: ONNX release](#step4_new_operator_or_function) + +2. [Removing Operator or Function](#removing_operator_or_function) + 1. [Removing operator](#removing_operator) + 2. [Removing function](#removing_function) + 3. [Document removing operator or function](#document_removing_operator_or_function) + +# Proposing and submitting a new operator or function to ONNX + +Operators are the basic building blocks that define ONNX model. With a rich set of operators, ONNX can describe most DNN and ML models from various frameworks. Functions allow for composing complex operators from more primitive operators. The ONNX specification includes a core set of operators that enable many models. It is a non-goal to add all possible operators, however more operators are added as needed to cover evolving needs. + +In this document, we describe the process of accepting a new proposed operator and how to properly submit a new operator as part of ONNX standard. The goal is to improve on what we currently have based on our experience, learning and feedbacks we gathered from the community. + +## 4 steps to add an operator +1. Decide what to propose +2. Submit PR for new operator/function +3. Review of PR by Operators SIG +4. Merging of PR and inclusion in next ONNX release + +## Step 1: Proposing a new operator/function +In order to propose a new operator/function, the following is needed: +1. If the operator can be composed by other ONNX operators, then it should be a function and not an operator (we have a function in ONNX : MeanVarianceNormalization). +2. If the operators can be split to new primitives, propose those primitives instead and make the operator a function. +3. Based on a model. This will help us understand the usage and that it solves an actual problem. For the case of the model being private or IP and can't be shared, the operator doesn't belong to the standard and should be implemented as custom OP. +4. The operator needs to be implemented by at-least one (well-known) framework. This help us to understand the actual behavior of the operator and its usage. +5. Operator signature and behavior: + 1. If the operator is available in numpy, prefer numpy semantics. + 2. If the operator is available in more than one frameworks, make sure that your design is general and cover those frameworks. +6. Prefer attributes over inputs. + +## Step 2: Submit PR +Once the criteria of proposing new operator/function has been satisfied, you will need to submit a PR for the new operator/function. Here the expectation of what the PR should include. The reviewer is expected to verify the completeness of the PR before signoff. +1. Description: + 1. Write a detailed description about the operator, and its expected behavior. Pretty much, the description should be clear enough to avoid confusion between implementors. + 2. Add an example in the description to illustrate the usage. + 3. Add reference to the source of the operator in the corresponding framework in the description (if possible). + 4. Write the mathematic formula or a pseudocode in the description. The core algorithm needs to be very clear. +2. Write a reference implementation in Python, this reference implementation should cover all the expected behavior of the operator. Only in extremely rare case, we will waive this requirement. +3. Operator version: check out our +[versioning doc](https://github.com/onnx/onnx/blob/master/docs/Versioning.md#operator-versioning) +4. Write unit test, that cover main usage and corner cases. + 1. The testing examples will be extracted to the doc. + 2. We also generate binary data for it. + 3. Example: https://github.com/onnx/onnx/blob/master/onnx/backend/test/case/node/abs.py +5. Add at least one automatic upgrade test for your operator in https://github.com/onnx/onnx/blob/master/onnx/test/automatic_upgrade_test.py using `_test_op_upgrade`. These tests create a given operator at a given opset version (usually the version the operator was introduced in) and test that the version converter is able to convert them to the highest available version. So for a new operator `_test_op_upgrade` will not test anything, but as soon as the operator gets updated in a future opset the test will autoamtically become nontrivial. +6. Update the documentation and generate the test data. + 1. Running [the script](https://github.com/onnx/onnx/blob/master/tools/update_doc.sh) +to update the doc and generate the test data. +7. Shape Inference function + 1. Please provide a shape inference function in cases where it is meaningful and applicable. + 2. In cases where shape inference is not possible, it must have logic to perform +rank inference at the very least (adding right amount of dimensions to the output shape) + 3. Shape inference functions must be accompanied by unit tests (https://github.com/onnx/onnx/blob/master/onnx/test/shape_inference_test.py). + 4. You can refer to the shape inference function for the `TopK` operator while implementing your own function (https://github.com/onnx/onnx/blob/master/onnx/defs/math/defs.cc#L943) + +### Example to Follow +[PR 1959](https://github.com/onnx/onnx/pull/1959) is a good example to follow. + +## Step 3: PR Review by Operators SIG +The [Operators SIG](https://github.com/onnx/sigs/tree/master/operators) is responsible for the operators/functions in the ONNX specification. The SIG regularly meets and reviews PRs. + +### Sign-off +At least two sign-off from the Operators SIG [contributors](https://github.com/onnx/onnx/tree/master/community#community-roles). + +## Step 4: ONNX release +Once the PR is reviewed and signed off by the Operators SIG, it will be merged. Your new operator/function will be part of the master branch and available to anyone building from source. These are not official releases. ONNX periodically releases official new versions that are a snapshot of the master branch. Your new operator/function will be part of that release. + +# Removing operator or function +There are a lot of reasons for removing existing ONNX operator or function, such us being replaced with different operator or can be decomposed by a set of other operators. This document describes the criteria of removing an existing ONNX operator from the standard. + +## Removing operator +Any operator in ONNX was added because it was required by a model and/or framework. In order to deprecate such an operator we need to do the following. +* Operator can’t be deprecated unless there is a replacement. + * Replacement can be a more general operator that supersedes the old one. + * Or a set of primitive operators that together can implement the same functionality and behavior of the deprecated operator (Function). +* If the deprecated operator can be decomposed by existing operators then it must be converted to a function. +* If replacement isn’t in ONNX standard yet, then add the replacement operator or set of operators first. +* Add a version adapter which turns the operator into its replacement for the version converter. Example: https://github.com/onnx/onnx/blob/master/onnx/version_converter/adapters/upsample_9_10.h +* No grace period is needed for deprecated operators. + +## Removing function +Function, by definition, is composed of ONNX primitives; however, function could have been accelerated by framework or runtime that support ONNX. So, removing function is not recommended, with the exception of adding another single function which supersede its functionality. + +## Document removing operator or function +To make sure everyone is aware of the deprecation, the following need to happen: +* Any removed operator or function from ONNX need to be mentioned in the release note. +* Their old documentation needs to be updated to show the new replacement and the mapping between the old to the new. + * Only `def.cc` need to be remove, `old.cc` will remain. + * `old.cc` need to be updated with the mapping to the replacement. +* ONNX checker need to be updated to error with a proper message. +* All removed operators need to be appended at the end of the `operator.md` file. diff --git a/_doc/sphinxdoc/source/onnxmd/onnx_docs/Broadcasting.md b/_doc/sphinxdoc/source/onnxmd/onnx_docs/Broadcasting.md new file mode 100644 index 00000000..02be7251 --- /dev/null +++ b/_doc/sphinxdoc/source/onnxmd/onnx_docs/Broadcasting.md @@ -0,0 +1,72 @@ + + +# Broadcasting in ONNX + +In ONNX, element-wise operators can take inputs with different shape, +as long as the input tensors are broadcastable to the same shape. +ONNX supports two types of broadcasting: multidirectional broadcasting and +unidirectional broadcasting. We will introduce these two types of broadcasting +respectively in the following sections. + + +## Multidirectional Broadcasting + +In ONNX, a set of tensors are multidirectional broadcastable to the same shape +if one of the following is true: +- The tensors all have exactly the same shape. +- The tensors all have the same number of dimensions and the length of +each dimensions is either a common length or 1. +- The tensors that have too few dimensions can have their shapes prepended +with a dimension of length 1 to satisfy property 2. + +For example, the following tensor shapes are supported by multidirectional broadcasting: + +- shape(A) = (2, 3, 4, 5), shape(B) = (,), i.e. B is a scalar ==> shape(result) = (2, 3, 4, 5) +- shape(A) = (2, 3, 4, 5), shape(B) = (5,), ==> shape(result) = (2, 3, 4, 5) +- shape(A) = (4, 5), shape(B) = (2, 3, 4, 5), ==> shape(result) = (2, 3, 4, 5) +- shape(A) = (1, 4, 5), shape(B) = (2, 3, 1, 1), ==> shape(result) = (2, 3, 4, 5) +- shape(A) = (3, 4, 5), shape(B) = (2, 1, 1, 1), ==> shape(result) = (2, 3, 4, 5) + +Multidirectional broadcasting is the same as [Numpy's broadcasting](https://docs.scipy.org/doc/numpy/user/basics.broadcasting.html#general-broadcasting-rules). + +Multidirectional broadcasting is supported by the following operators in ONNX: +- [Add](Operators.md#Add) +- [And](Operators.md#And) +- [Div](Operators.md#Div) +- [Equal](Operators.md#Equal) +- [Greater](Operators.md#Greater) +- [Less](Operators.md#Less) +- [Max](Operators.md#Max) +- [Mean](Operators.md#Mean) +- [Min](Operators.md#Min) +- [Mul](Operators.md#Mul) +- [Or](Operators.md#Or) +- [Pow](Operators.md#Pow) +- [Sub](Operators.md#Sub) +- [Sum](Operators.md#Sum) +- [Where](Operators.md#Where) +- [Xor](Operators.md#Xor) + +## Unidirectional Broadcasting + +In ONNX, tensor B is unidirectional broadcastable to tensor A +if one of the following is true: +- Tensor A and B both have exactly the same shape. +- Tensor A and B all have the same number of dimensions and the length of +each dimensions is either a common length or B's length is 1. +- Tensor B has too few dimensions, and B can have its shapes prepended +with a dimension of length 1 to satisfy property 2. + +When unidirectional broadcasting happens, the output's shape is the same as +the shape of A (i.e., the larger shape of two input tensors). + +In the following examples, tensor B is unidirectional broadcastable to tensor A: + +- shape(A) = (2, 3, 4, 5), shape(B) = (,), i.e. B is a scalar ==> shape(result) = (2, 3, 4, 5) +- shape(A) = (2, 3, 4, 5), shape(B) = (5,), ==> shape(result) = (2, 3, 4, 5) +- shape(A) = (2, 3, 4, 5), shape(B) = (2, 1, 1, 5), ==> shape(result) = (2, 3, 4, 5) +- shape(A) = (2, 3, 4, 5), shape(B) = (1, 3, 1, 5), ==> shape(result) = (2, 3, 4, 5) + +Unidirectional broadcasting is supported by the following operators in ONNX: +- [Gemm](Operators.md#Gemm) +- [PRelu](Operators.md#PRelu) diff --git a/_doc/sphinxdoc/source/onnxmd/onnx_docs/CONTRIBUTING.md b/_doc/sphinxdoc/source/onnxmd/onnx_docs/CONTRIBUTING.md new file mode 100644 index 00000000..2052c4fa --- /dev/null +++ b/_doc/sphinxdoc/source/onnxmd/onnx_docs/CONTRIBUTING.md @@ -0,0 +1,105 @@ + + +# Development + +You will need to install protobuf and numpy to build ONNX. An easy +way to get these dependencies is via [Anaconda](https://www.anaconda.com/download/): + +``` +# Use conda-forge protobuf, as defaults doesn't come with protoc +conda install -c conda-forge protobuf numpy +``` + +During development, it's convenient to install ONNX in development mode (to disable ONNX-ML, set environment variable `ONNX_ML=0`): + +``` +git clone --recursive https://github.com/onnx/onnx.git +pip install -e onnx/ +``` +Then, after you have made changes to Python and C++ files: + +- `Python files`: the changes are effective immediately in your installation. You don't need to install these again. +- `C++ files`: you need to install these again to trigger the native extension build. + +## Folder structure + +- `onnx/`: the main folder that all code lies under + - `onnx.proto`: the protobuf (v2.6.1) that contains all the structures + - `checker.py`: a utility to check whether a serialized ONNX proto is legal + - `helper.py`: tools for graph operation + - `defs/`: a subfolder that defines the ONNX operators + - `test/`: test files + +## Generated operator documentation + +[Operator docs in Operators.md](Operators.md) are automatically generated based on C++ operator definitions and backend Python snippets. To refresh these docs, run the following commands from the repo root and commit the results. Note `ONNX_ML=0` updates Operators.md whereas `ONNX_ML=1` updates Operators-ml.md: + +``` +set ONNX_ML=0 +pip install setup.py +python onnx/defs/gen_doc.py +``` + +## Adding a new operator + +ONNX is an open standard, and we encourage developers to contribute high +quality operators to ONNX specification. +Before proposing a new operator, please read [the tutorial](AddNewOp.md). + +# Testing + +ONNX uses [pytest](https://docs.pytest.org) as a test driver. To run tests, you'll first need to install pytest: + +``` +pip install pytest nbval +``` + +After installing pytest, run from the root of the repo: + +``` +pytest +``` + +to begin the tests. + +You'll need to regenerate test coverage too, by running this command from the root of the repo: + +``` +python onnx\backend\test\stat_coverage.py +``` + +# Static typing (mypy) + +We use [mypy](http://mypy-lang.org/) to run static type checks on the onnx code base. To check that your code passes, you'll first need to install the mypy type checker. If you're using python 3, call from your onnx source folder: + +``` +pip install -e .[mypy] +``` + +The type checker cannot run in a python 2 environment (but it will check python 2 code). +If you're using python 2, you need to install mypy into your system packages instead: + +``` +pip3 install mypy==[version] +``` +*Note: You'll find the version we're currently using in `setup.py`.* + +After having installed mypy, you can run the type checks: + +``` +python setup.py typecheck +``` + + +# Other developer documentation + +* [How to implement ONNX backend (ONNX to something converter)](ImplementingAnOnnxBackend.md) +* [Backend test infrastructure and how to add tests](OnnxBackendTest.md) + +# License + +[Apache License v2.0](https://github.com/onnx/onnx/blob/master/LICENSE) + +# Code of Conduct + +[ONNX Open Source Code of Conduct](http://onnx.ai/codeofconduct.html) diff --git a/_doc/sphinxdoc/source/onnxmd/onnx_docs/Changelog-ml.md b/_doc/sphinxdoc/source/onnxmd/onnx_docs/Changelog-ml.md new file mode 100644 index 00000000..39da3b82 --- /dev/null +++ b/_doc/sphinxdoc/source/onnxmd/onnx_docs/Changelog-ml.md @@ -0,0 +1,971 @@ + +## Operator Changelog +*This file is automatically generated from the + [def files](/onnx/defs) via [this script](/onnx/defs/gen_doc.py). + Do not modify directly and instead edit operator definitions.* + +For an operator input/output's differentiability, it can be differentiable, + non-differentiable, or undefined. If a variable's differentiability + is not specified, that variable has undefined differentiability. + +# ai.onnx.ml +## Version 1 of the 'ai.onnx.ml' operator set +### **ai.onnx.ml.ArrayFeatureExtractor-1** + + Select elements of the input tensor based on the indices passed.
+ The indices are applied to the last axes of the tensor. + +#### Version + +This version of the operator has been available since version 1 of the 'ai.onnx.ml' operator set. + +#### Inputs + +
+
X : T
+
Data to be selected
+
Y : tensor(int64)
+
The indices, based on 0 as the first index of any dimension.
+
+ +#### Outputs + +
+
Z : T
+
Selected output data as an array
+
+ +#### Type Constraints + +
+
T : tensor(float), tensor(double), tensor(int64), tensor(int32), tensor(string)
+
The input must be a tensor of a numeric type or string. The output will be of the same tensor type.
+
+ +### **ai.onnx.ml.Binarizer-1** + + Maps the values of the input tensor to either 0 or 1, element-wise, based on the outcome of a comparison against a threshold value. + +#### Version + +This version of the operator has been available since version 1 of the 'ai.onnx.ml' operator set. + +#### Attributes + +
+
threshold : float (default is 0.0)
+
Values greater than this are mapped to 1, others to 0.
+
+ +#### Inputs + +
+
X : T
+
Data to be binarized
+
+ +#### Outputs + +
+
Y : T
+
Binarized output data
+
+ +#### Type Constraints + +
+
T : tensor(float), tensor(double), tensor(int64), tensor(int32)
+
The input must be a tensor of a numeric type. The output will be of the same tensor type.
+
+ +### **ai.onnx.ml.CastMap-1** + + Converts a map to a tensor.
The map key must be an int64 and the values will be ordered + in ascending order based on this key.
The operator supports dense packing or sparse packing. + If using sparse packing, the key cannot exceed the max_map-1 value. + +#### Version + +This version of the operator has been available since version 1 of the 'ai.onnx.ml' operator set. + +#### Attributes + +
+
cast_to : string (default is TO_FLOAT)
+
A string indicating the desired element type of the output tensor, one of 'TO_FLOAT', 'TO_STRING', 'TO_INT64'.
+
map_form : string (default is DENSE)
+
Indicates whether to only output as many values as are in the input (dense), or position the input based on using the key of the map as the index of the output (sparse).
One of 'DENSE', 'SPARSE'.
+
max_map : int (default is 1)
+
If the value of map_form is 'SPARSE,' this attribute indicates the total length of the output tensor.
+
+ +#### Inputs + +
+
X : T1
+
The input map that is to be cast to a tensor
+
+ +#### Outputs + +
+
Y : T2
+
A tensor representing the same data as the input map, ordered by their keys
+
+ +#### Type Constraints + +
+
T1 : map(int64, string), map(int64, float)
+
The input must be an integer map to either string or float.
+
T2 : tensor(string), tensor(float), tensor(int64)
+
The output is a 1-D tensor of string, float, or integer.
+
+ +### **ai.onnx.ml.CategoryMapper-1** + + Converts strings to integers and vice versa.
+ Two sequences of equal length are used to map between integers and strings, + with strings and integers at the same index detailing the mapping.
+ Each operator converts either integers to strings or strings to integers, depending + on which default value attribute is provided. Only one default value attribute + should be defined.
+ If the string default value is set, it will convert integers to strings. + If the int default value is set, it will convert strings to integers. + +#### Version + +This version of the operator has been available since version 1 of the 'ai.onnx.ml' operator set. + +#### Attributes + +
+
cats_int64s : list of ints
+
The integers of the map. This sequence must be the same length as the 'cats_strings' sequence.
+
cats_strings : list of strings
+
The strings of the map. This sequence must be the same length as the 'cats_int64s' sequence
+
default_int64 : int (default is -1)
+
An integer to use when an input string value is not found in the map.
One and only one of the 'default_*' attributes must be defined.
+
default_string : string (default is _Unused)
+
A string to use when an input integer value is not found in the map.
One and only one of the 'default_*' attributes must be defined.
+
+ +#### Inputs + +
+
X : T1
+
Input data
+
+ +#### Outputs + +
+
Y : T2
+
Output data. If strings are input, the output values are integers, and vice versa.
+
+ +#### Type Constraints + +
+
T1 : tensor(string), tensor(int64)
+
The input must be a tensor of strings or integers, either [N,C] or [C].
+
T2 : tensor(string), tensor(int64)
+
The output is a tensor of strings or integers. Its shape will be the same as the input shape.
+
+ +### **ai.onnx.ml.DictVectorizer-1** + + Uses an index mapping to convert a dictionary to an array.
+ Given a dictionary, each key is looked up in the vocabulary attribute corresponding to + the key type. The index into the vocabulary array at which the key is found is then + used to index the output 1-D tensor 'Y' and insert into it the value found in the dictionary 'X'.
+ The key type of the input map must correspond to the element type of the defined vocabulary attribute. + Therefore, the output array will be equal in length to the index mapping vector parameter. + All keys in the input dictionary must be present in the index mapping vector. + For each item in the input dictionary, insert its value in the output array. + Any keys not present in the input dictionary, will be zero in the output array.
+ For example: if the ``string_vocabulary`` parameter is set to ``["a", "c", "b", "z"]``, + then an input of ``{"a": 4, "c": 8}`` will produce an output of ``[4, 8, 0, 0]``. + + +#### Version + +This version of the operator has been available since version 1 of the 'ai.onnx.ml' operator set. + +#### Attributes + +
+
int64_vocabulary : list of ints
+
An integer vocabulary array.
One and only one of the vocabularies must be defined.
+
string_vocabulary : list of strings
+
A string vocabulary array.
One and only one of the vocabularies must be defined.
+
+ +#### Inputs + +
+
X : T1
+
A dictionary.
+
+ +#### Outputs + +
+
Y : T2
+
A 1-D tensor holding values from the input dictionary.
+
+ +#### Type Constraints + +
+
T1 : map(string, int64), map(int64, string), map(int64, float), map(int64, double), map(string, float), map(string, double)
+
The input must be a map from strings or integers to either strings or a numeric type. The key and value types cannot be the same.
+
T2 : tensor(int64), tensor(float), tensor(double), tensor(string)
+
The output will be a tensor of the value type of the input map. It's shape will be [1,C], where C is the length of the input dictionary.
+
+ +### **ai.onnx.ml.FeatureVectorizer-1** + + Concatenates input tensors into one continuous output.
+ All input shapes are 2-D and are concatenated along the second dimention. 1-D tensors are treated as [1,C]. + Inputs are copied to the output maintaining the order of the input arguments.
+ All inputs must be integers or floats, while the output will be all floating point values. + +#### Version + +This version of the operator has been available since version 1 of the 'ai.onnx.ml' operator set. + +#### Attributes + +
+
inputdimensions : list of ints
+
The size of each input in the input list
+
+ +#### Inputs (1 - ∞) + +
+
X (variadic) : T1
+
An ordered collection of tensors, all with the same element type.
+
+ +#### Outputs + +
+
Y : tensor(float)
+
The output array, elements ordered as the inputs.
+
+ +#### Type Constraints + +
+
T1 : tensor(int32), tensor(int64), tensor(float), tensor(double)
+
The input type must be a tensor of a numeric type.
+
+ +### **ai.onnx.ml.Imputer-1** + + Replaces inputs that equal one value with another, leaving all other elements alone.
+ This operator is typically used to replace missing values in situations where they have a canonical + representation, such as -1, 0, NaN, or some extreme value.
+ One and only one of imputed_value_floats or imputed_value_int64s should be defined -- floats if the input tensor + holds floats, integers if the input tensor holds integers. The imputed values must all fit within the + width of the tensor element type. One and only one of the replaced_value_float or replaced_value_int64 should be defined, + which one depends on whether floats or integers are being processed.
+ The imputed_value attribute length can be 1 element, or it can have one element per input feature.
In other words, if the input tensor has the shape [*,F], then the length of the attribute array may be 1 or F. If it is 1, then it is broadcast along the last dimension and applied to each feature. + +#### Version + +This version of the operator has been available since version 1 of the 'ai.onnx.ml' operator set. + +#### Attributes + +
+
imputed_value_floats : list of floats
+
Value(s) to change to
+
imputed_value_int64s : list of ints
+
Value(s) to change to.
+
replaced_value_float : float (default is 0.0)
+
A value that needs replacing.
+
replaced_value_int64 : int (default is 0)
+
A value that needs replacing.
+
+ +#### Inputs + +
+
X : T
+
Data to be processed.
+
+ +#### Outputs + +
+
Y : T
+
Imputed output data
+
+ +#### Type Constraints + +
+
T : tensor(float), tensor(double), tensor(int64), tensor(int32)
+
The input type must be a tensor of a numeric type, either [N,C] or [C]. The output type will be of the same tensor type and shape.
+
+ +### **ai.onnx.ml.LabelEncoder-1** + + Converts strings to integers and vice versa.
+ If the string default value is set, it will convert integers to strings. + If the int default value is set, it will convert strings to integers.
+ Each operator converts either integers to strings or strings to integers, depending + on which default value attribute is provided. Only one default value attribute + should be defined.
+ When converting from integers to strings, the string is fetched from the + 'classes_strings' list, by simple indexing.
+ When converting from strings to integers, the string is looked up in the list + and the index at which it is found is used as the converted value. + +#### Version + +This version of the operator has been available since version 1 of the 'ai.onnx.ml' operator set. + +#### Attributes + +
+
classes_strings : list of strings
+
A list of labels.
+
default_int64 : int (default is -1)
+
An integer to use when an input string value is not found in the map.
One and only one of the 'default_*' attributes must be defined.
+
default_string : string (default is _Unused)
+
A string to use when an input integer value is not found in the map.
One and only one of the 'default_*' attributes must be defined.
+
+ +#### Inputs + +
+
X : T1
+
Input data.
+
+ +#### Outputs + +
+
Y : T2
+
Output data. If strings are input, the output values are integers, and vice versa.
+
+ +#### Type Constraints + +
+
T1 : tensor(string), tensor(int64)
+
The input type must be a tensor of integers or strings, of any shape.
+
T2 : tensor(string), tensor(int64)
+
The output type will be a tensor of strings or integers, and will have the same shape as the input.
+
+ +### **ai.onnx.ml.LinearClassifier-1** + + Linear classifier + +#### Version + +This version of the operator has been available since version 1 of the 'ai.onnx.ml' operator set. + +#### Attributes + +
+
classlabels_ints : list of ints
+
Class labels when using integer labels. One and only one 'classlabels' attribute must be defined.
+
classlabels_strings : list of strings
+
Class labels when using string labels. One and only one 'classlabels' attribute must be defined.
+
coefficients : list of floats (required)
+
A collection of weights of the model(s).
+
intercepts : list of floats
+
A collection of intercepts.
+
multi_class : int (default is 0)
+
Indicates whether to do OvR or multinomial (0=OvR is the default).
+
post_transform : string (default is NONE)
+
Indicates the transform to apply to the scores vector.
One of 'NONE,' 'SOFTMAX,' 'LOGISTIC,' 'SOFTMAX_ZERO,' or 'PROBIT'
+
+ +#### Inputs + +
+
X : T1
+
Data to be classified.
+
+ +#### Outputs + +
+
Y : T2
+
Classification outputs (one class per example).
+
Z : tensor(float)
+
Classification scores ([N,E] - one score for each class and example
+
+ +#### Type Constraints + +
+
T1 : tensor(float), tensor(double), tensor(int64), tensor(int32)
+
The input must be a tensor of a numeric type, and of of shape [N,C] or [C]. In the latter case, it will be treated as [1,C]
+
T2 : tensor(string), tensor(int64)
+
The output will be a tensor of strings or integers.
+
+ +### **ai.onnx.ml.LinearRegressor-1** + + Generalized linear regression evaluation.
+ If targets is set to 1 (default) then univariate regression is performed.
+ If targets is set to M then M sets of coefficients must be passed in as a sequence + and M results will be output for each input n in N.
+ The coefficients array is of length n, and the coefficients for each target are contiguous. + Intercepts are optional but if provided must match the number of targets. + +#### Version + +This version of the operator has been available since version 1 of the 'ai.onnx.ml' operator set. + +#### Attributes + +
+
coefficients : list of floats
+
Weights of the model(s).
+
intercepts : list of floats
+
Weights of the intercepts, if used.
+
post_transform : string (default is NONE)
+
Indicates the transform to apply to the regression output vector.
One of 'NONE,' 'SOFTMAX,' 'LOGISTIC,' 'SOFTMAX_ZERO,' or 'PROBIT'
+
targets : int (default is 1)
+
The total number of regression targets, 1 if not defined.
+
+ +#### Inputs + +
+
X : T
+
Data to be regressed.
+
+ +#### Outputs + +
+
Y : tensor(float)
+
Regression outputs (one per target, per example).
+
+ +#### Type Constraints + +
+
T : tensor(float), tensor(double), tensor(int64), tensor(int32)
+
The input must be a tensor of a numeric type.
+
+ +### **ai.onnx.ml.Normalizer-1** + + Normalize the input. There are three normalization modes, which have the corresponding formulas, + defined using element-wise infix operators '/' and '^' and tensor-wide functions 'max' and 'sum':
+
+ Max: Y = X / max(X)
+ L1: Y = X / sum(X)
+ L2: Y = sqrt(X^2 / sum(X^2)}
+ In all modes, if the divisor is zero, Y == X. +
+ For batches, that is, [N,C] tensors, normalization is done along the C axis. In other words, each row + of the batch is normalized independently. + +#### Version + +This version of the operator has been available since version 1 of the 'ai.onnx.ml' operator set. + +#### Attributes + +
+
norm : string (default is MAX)
+
One of 'MAX,' 'L1,' 'L2'
+
+ +#### Inputs + +
+
X : T
+
Data to be encoded, a tensor of shape [N,C] or [C]
+
+ +#### Outputs + +
+
Y : tensor(float)
+
Encoded output data
+
+ +#### Type Constraints + +
+
T : tensor(float), tensor(double), tensor(int64), tensor(int32)
+
The input must be a tensor of a numeric type.
+
+ +### **ai.onnx.ml.OneHotEncoder-1** + + Replace each input element with an array of ones and zeros, where a single + one is placed at the index of the category that was passed in. The total category count + will determine the size of the extra dimension of the output array Y.
+ For example, if we pass a tensor with a single value of 4, and a category count of 8, + the output will be a tensor with ``[0,0,0,0,1,0,0,0]``.
+ This operator assumes every input feature is from the same set of categories.
+ If the input is a tensor of float, int32, or double, the data will be cast + to integers and the cats_int64s category list will be used for the lookups. + +#### Version + +This version of the operator has been available since version 1 of the 'ai.onnx.ml' operator set. + +#### Attributes + +
+
cats_int64s : list of ints
+
List of categories, ints.
One and only one of the 'cats_*' attributes must be defined.
+
cats_strings : list of strings
+
List of categories, strings.
One and only one of the 'cats_*' attributes must be defined.
+
zeros : int (default is 1)
+
If true and category is not present, will return all zeros; if false and a category if not found, the operator will fail.
+
+ +#### Inputs + +
+
X : T
+
Data to be encoded.
+
+ +#### Outputs + +
+
Y : tensor(float)
+
Encoded output data, having one more dimension than X.
+
+ +#### Type Constraints + +
+
T : tensor(string), tensor(int64), tensor(int32), tensor(float), tensor(double)
+
The input must be a tensor of a numeric type.
+
+ +### **ai.onnx.ml.SVMClassifier-1** + + Support Vector Machine classifier + +#### Version + +This version of the operator has been available since version 1 of the 'ai.onnx.ml' operator set. + +#### Attributes + +
+
classlabels_ints : list of ints
+
Class labels if using integer labels.
One and only one of the 'classlabels_*' attributes must be defined.
+
classlabels_strings : list of strings
+
Class labels if using string labels.
One and only one of the 'classlabels_*' attributes must be defined.
+
coefficients : list of floats
+
+
kernel_params : list of floats
+
List of 3 elements containing gamma, coef0, and degree, in that order. Zero if unused for the kernel.
+
kernel_type : string (default is LINEAR)
+
The kernel type, one of 'LINEAR,' 'POLY,' 'RBF,' 'SIGMOID'.
+
post_transform : string (default is NONE)
+
Indicates the transform to apply to the score.
One of 'NONE,' 'SOFTMAX,' 'LOGISTIC,' 'SOFTMAX_ZERO,' or 'PROBIT'
+
prob_a : list of floats
+
First set of probability coefficients.
+
prob_b : list of floats
+
Second set of probability coefficients. This array must be same size as prob_a.
If these are provided then output Z are probability estimates, otherwise they are raw scores.
+
rho : list of floats
+
+
support_vectors : list of floats
+
+
vectors_per_class : list of ints
+
+
+ +#### Inputs + +
+
X : T1
+
Data to be classified.
+
+ +#### Outputs + +
+
Y : T2
+
Classification outputs (one class per example).
+
Z : tensor(float)
+
Class scores (one per class per example), if prob_a and prob_b are provided they are probabilities for each class, otherwise they are raw scores.
+
+ +#### Type Constraints + +
+
T1 : tensor(float), tensor(double), tensor(int64), tensor(int32)
+
The input must be a tensor of a numeric type, either [C] or [N,C].
+
T2 : tensor(string), tensor(int64)
+
The output type will be a tensor of strings or integers, depending on which of the the classlabels_* attributes is used. Its size will match the bactch size of the input.
+
+ +### **ai.onnx.ml.SVMRegressor-1** + + Support Vector Machine regression prediction and one-class SVM anomaly detection. + +#### Version + +This version of the operator has been available since version 1 of the 'ai.onnx.ml' operator set. + +#### Attributes + +
+
coefficients : list of floats
+
Support vector coefficients.
+
kernel_params : list of floats
+
List of 3 elements containing gamma, coef0, and degree, in that order. Zero if unused for the kernel.
+
kernel_type : string (default is LINEAR)
+
The kernel type, one of 'LINEAR,' 'POLY,' 'RBF,' 'SIGMOID'.
+
n_supports : int (default is 0)
+
The number of support vectors.
+
one_class : int (default is 0)
+
Flag indicating whether the regression is a one-class SVM or not.
+
post_transform : string (default is NONE)
+
Indicates the transform to apply to the score.
One of 'NONE,' 'SOFTMAX,' 'LOGISTIC,' 'SOFTMAX_ZERO,' or 'PROBIT.'
+
rho : list of floats
+
+
support_vectors : list of floats
+
Chosen support vectors
+
+ +#### Inputs + +
+
X : T
+
Data to be regressed.
+
+ +#### Outputs + +
+
Y : tensor(float)
+
Regression outputs (one score per target per example).
+
+ +#### Type Constraints + +
+
T : tensor(float), tensor(double), tensor(int64), tensor(int32)
+
The input type must be a tensor of a numeric type, either [C] or [N,C].
+
+ +### **ai.onnx.ml.Scaler-1** + + Rescale input data, for example to standardize features by removing the mean and scaling to unit variance. + +#### Version + +This version of the operator has been available since version 1 of the 'ai.onnx.ml' operator set. + +#### Attributes + +
+
offset : list of floats
+
First, offset by this.
Can be length of features in an [N,F] tensor or length 1, in which case it applies to all features, regardless of dimension count.
+
scale : list of floats
+
Second, multiply by this.
Can be length of features in an [N,F] tensor or length 1, in which case it applies to all features, regardless of dimension count.
Must be same length as 'offset'
+
+ +#### Inputs + +
+
X : T
+
Data to be scaled.
+
+ +#### Outputs + +
+
Y : tensor(float)
+
Scaled output data.
+
+ +#### Type Constraints + +
+
T : tensor(float), tensor(double), tensor(int64), tensor(int32)
+
The input must be a tensor of a numeric type.
+
+ +### **ai.onnx.ml.TreeEnsembleClassifier-1** + + Tree Ensemble classifier. Returns the top class for each of N inputs.
+ The attributes named 'nodes_X' form a sequence of tuples, associated by + index into the sequences, which must all be of equal length. These tuples + define the nodes.
+ Similarly, all fields prefixed with 'class_' are tuples of votes at the leaves. + A leaf may have multiple votes, where each vote is weighted by + the associated class_weights index.
+ One and only one of classlabels_strings or classlabels_int64s + will be defined. The class_ids are indices into this list. + +#### Version + +This version of the operator has been available since version 1 of the 'ai.onnx.ml' operator set. + +#### Attributes + +
+
base_values : list of floats
+
Base values for classification, added to final class score; the size must be the same as the classes or can be left unassigned (assumed 0)
+
class_ids : list of ints
+
The index of the class list that each weight is for.
+
class_nodeids : list of ints
+
node id that this weight is for.
+
class_treeids : list of ints
+
The id of the tree that this node is in.
+
class_weights : list of floats
+
The weight for the class in class_id.
+
classlabels_int64s : list of ints
+
Class labels if using integer labels.
One and only one of the 'classlabels_*' attributes must be defined.
+
classlabels_strings : list of strings
+
Class labels if using string labels.
One and only one of the 'classlabels_*' attributes must be defined.
+
nodes_falsenodeids : list of ints
+
Child node if expression is false.
+
nodes_featureids : list of ints
+
Feature id for each node.
+
nodes_hitrates : list of floats
+
Popularity of each node, used for performance and may be omitted.
+
nodes_missing_value_tracks_true : list of ints
+
For each node, define what to do in the presence of a missing value: if a value is missing (NaN), use the 'true' or 'false' branch based on the value in this array.
This attribute may be left undefined, and the defalt value is false (0) for all nodes.
+
nodes_modes : list of strings
+
The node kind, that is, the comparison to make at the node. There is no comparison to make at a leaf node.
One of 'BRANCH_LEQ', 'BRANCH_LT', 'BRANCH_GTE', 'BRANCH_GT', 'BRANCH_EQ', 'BRANCH_NEQ', 'LEAF'
+
nodes_nodeids : list of ints
+
Node id for each node. Ids may restart at zero for each tree, but it not required to.
+
nodes_treeids : list of ints
+
Tree id for each node.
+
nodes_truenodeids : list of ints
+
Child node if expression is true.
+
nodes_values : list of floats
+
Thresholds to do the splitting on for each node.
+
post_transform : string (default is NONE)
+
Indicates the transform to apply to the score.
One of 'NONE,' 'SOFTMAX,' 'LOGISTIC,' 'SOFTMAX_ZERO,' or 'PROBIT.'
+
+ +#### Inputs + +
+
X : T1
+
Input of shape [N,F]
+
+ +#### Outputs + +
+
Y : T2
+
N, Top class for each point
+
Z : tensor(float)
+
The class score for each class, for each point, a tensor of shape [N,E].
+
+ +#### Type Constraints + +
+
T1 : tensor(float), tensor(double), tensor(int64), tensor(int32)
+
The input type must be a tensor of a numeric type.
+
T2 : tensor(string), tensor(int64)
+
The output type will be a tensor of strings or integers, depending on which of the the classlabels_* attributes is used.
+
+ +### **ai.onnx.ml.TreeEnsembleRegressor-1** + + Tree Ensemble regressor. Returns the regressed values for each input in N.
+ All args with nodes_ are fields of a tuple of tree nodes, and + it is assumed they are the same length, and an index i will decode the + tuple across these inputs. Each node id can appear only once + for each tree id.
+ All fields prefixed with target_ are tuples of votes at the leaves.
+ A leaf may have multiple votes, where each vote is weighted by + the associated target_weights index.
+ All trees must have their node ids start at 0 and increment by 1.
+ Mode enum is BRANCH_LEQ, BRANCH_LT, BRANCH_GTE, BRANCH_GT, BRANCH_EQ, BRANCH_NEQ, LEAF + +#### Version + +This version of the operator has been available since version 1 of the 'ai.onnx.ml' operator set. + +#### Attributes + +
+
aggregate_function : string (default is SUM)
+
Defines how to aggregate leaf values within a target.
One of 'AVERAGE,' 'SUM,' 'MIN,' 'MAX.'
+
base_values : list of floats
+
Base values for classification, added to final class score; the size must be the same as the classes or can be left unassigned (assumed 0)
+
n_targets : int
+
The total number of targets.
+
nodes_falsenodeids : list of ints
+
Child node if expression is false
+
nodes_featureids : list of ints
+
Feature id for each node.
+
nodes_hitrates : list of floats
+
Popularity of each node, used for performance and may be omitted.
+
nodes_missing_value_tracks_true : list of ints
+
For each node, define what to do in the presence of a NaN: use the 'true' (if the attribute value is 1) or 'false' (if the attribute value is 0) branch based on the value in this array.
This attribute may be left undefined and the defalt value is false (0) for all nodes.
+
nodes_modes : list of strings
+
The node kind, that is, the comparison to make at the node. There is no comparison to make at a leaf node.
One of 'BRANCH_LEQ', 'BRANCH_LT', 'BRANCH_GTE', 'BRANCH_GT', 'BRANCH_EQ', 'BRANCH_NEQ', 'LEAF'
+
nodes_nodeids : list of ints
+
Node id for each node. Node ids must restart at zero for each tree and increase sequentially.
+
nodes_treeids : list of ints
+
Tree id for each node.
+
nodes_truenodeids : list of ints
+
Child node if expression is true
+
nodes_values : list of floats
+
Thresholds to do the splitting on for each node.
+
post_transform : string (default is NONE)
+
Indicates the transform to apply to the score.
One of 'NONE,' 'SOFTMAX,' 'LOGISTIC,' 'SOFTMAX_ZERO,' or 'PROBIT'
+
target_ids : list of ints
+
The index of the target that each weight is for
+
target_nodeids : list of ints
+
The node id of each weight
+
target_treeids : list of ints
+
The id of the tree that each node is in.
+
target_weights : list of floats
+
The weight for each target
+
+ +#### Inputs + +
+
X : T
+
Input of shape [N,F]
+
+ +#### Outputs + +
+
Y : tensor(float)
+
N classes
+
+ +#### Type Constraints + +
+
T : tensor(float), tensor(double), tensor(int64), tensor(int32)
+
The input type must be a tensor of a numeric type.
+
+ +### **ai.onnx.ml.ZipMap-1** + + Creates a map from the input and the attributes.
+ The values are provided by the input tensor, while the keys are specified by the attributes. + Must provide keys in either classlabels_strings or classlabels_int64s (but not both).
+ The columns of the tensor correspond one-by-one to the keys specified by the attributes. There must be as many columns as keys.
+ +#### Version + +This version of the operator has been available since version 1 of the 'ai.onnx.ml' operator set. + +#### Attributes + +
+
classlabels_int64s : list of ints
+
The keys when using int keys.
One and only one of the 'classlabels_*' attributes must be defined.
+
classlabels_strings : list of strings
+
The keys when using string keys.
One and only one of the 'classlabels_*' attributes must be defined.
+
+ +#### Inputs + +
+
X : tensor(float)
+
The input values
+
+ +#### Outputs + +
+
Z : T
+
The output map
+
+ +#### Type Constraints + +
+
T : seq(map(string, float)), seq(map(int64, float))
+
The output will be a sequence of string or integer maps to float.
+
+ +## Version 2 of the 'ai.onnx.ml' operator set +### **ai.onnx.ml.LabelEncoder-2** + + Maps each element in the input tensor to another value.
+ The mapping is determined by the two parallel attributes, 'keys_*' and + 'values_*' attribute. The i-th value in the specified 'keys_*' attribute + would be mapped to the i-th value in the specified 'values_*' attribute. It + implies that input's element type and the element type of the specified + 'keys_*' should be identical while the output type is identical to the + specified 'values_*' attribute. If an input element can not be found in the + specified 'keys_*' attribute, the 'default_*' that matches the specified + 'values_*' attribute may be used as its output value.
+ Let's consider an example which maps a string tensor to an integer tensor. + Assume and 'keys_strings' is ["Amy", "Sally"], 'values_int64s' is [5, 6], + and 'default_int64' is '-1'. The input ["Dori", "Amy", "Amy", "Sally", + "Sally"] would be mapped to [-1, 5, 5, 6, 6].
+ Since this operator is an one-to-one mapping, its input and output shapes + are the same. Notice that only one of 'keys_*'/'values_*' can be set.
+ For key look-up, bit-wise comparison is used so even a float NaN can be + mapped to a value in 'values_*' attribute.
+ +#### Version + +This version of the operator has been available since version 2 of the 'ai.onnx.ml' operator set. + +#### Attributes + +
+
default_float : float (default is -0.0)
+
A float.
+
default_int64 : int (default is -1)
+
An integer.
+
default_string : string (default is _Unused)
+
A string.
+
keys_floats : list of floats
+
A list of floats.
+
keys_int64s : list of ints
+
A list of ints.
+
keys_strings : list of strings
+
A list of strings. One and only one of 'keys_*'s should be set.
+
values_floats : list of floats
+
A list of floats.
+
values_int64s : list of ints
+
A list of ints.
+
values_strings : list of strings
+
A list of strings. One and only one of 'value_*'s should be set.
+
+ +#### Inputs + +
+
X : T1
+
Input data. It can be either tensor or scalar.
+
+ +#### Outputs + +
+
Y : T2
+
Output data.
+
+ +#### Type Constraints + +
+
T1 : tensor(string), tensor(int64), tensor(float)
+
The input type is a tensor of any shape.
+
T2 : tensor(string), tensor(int64), tensor(float)
+
Output type is determined by the specified 'values_*' attribute.
+
+ diff --git a/_doc/sphinxdoc/source/onnxmd/onnx_docs/Changelog.md b/_doc/sphinxdoc/source/onnxmd/onnx_docs/Changelog.md new file mode 100644 index 00000000..df551d85 --- /dev/null +++ b/_doc/sphinxdoc/source/onnxmd/onnx_docs/Changelog.md @@ -0,0 +1,20964 @@ + +## Operator Changelog +*This file is automatically generated from the + [def files](/onnx/defs) via [this script](/onnx/defs/gen_doc.py). + Do not modify directly and instead edit operator definitions.* + +For an operator input/output's differentiability, it can be differentiable, + non-differentiable, or undefined. If a variable's differentiability + is not specified, that variable has undefined differentiability. + +# ai.onnx (default) +## Version 1 of the default ONNX operator set +### **Abs-1** + + Absolute takes one input data (Tensor) and produces one output data + (Tensor) where the absolute is, y = abs(x), is applied to + the tensor elementwise. + +#### Version + +This version of the operator has been available since version 1 of the default ONNX operator set. + +#### Attributes + +
+
consumed_inputs : list of ints
+
legacy optimization attribute.
+
+ +#### Inputs + +
+
X : T
+
Input tensor
+
+ +#### Outputs + +
+
Y : T
+
Output tensor
+
+ +#### Type Constraints + +
+
T : tensor(float16), tensor(float), tensor(double)
+
Constrain input and output types to float tensors.
+
+ +### **Add-1** + + Performs element-wise binary addition (with limited broadcast support). + + If necessary the right-hand-side argument will be broadcasted to match the + shape of left-hand-side argument. When broadcasting is specified, the second + tensor can either be of element size 1 (including a scalar tensor and any + tensor with rank equal to or smaller than the first tensor), or having its + shape as a contiguous subset of the first tensor's shape. The starting of the + mutually equal shape is specified by the argument "axis", and if it is not set, + suffix matching is assumed. 1-dim expansion doesn't work yet. + + For example, the following tensor shapes are supported (with broadcast=1): + + shape(A) = (2, 3, 4, 5), shape(B) = (,), i.e. B is a scalar tensor + shape(A) = (2, 3, 4, 5), shape(B) = (1, 1), i.e. B is an 1-element tensor + shape(A) = (2, 3, 4, 5), shape(B) = (5,) + shape(A) = (2, 3, 4, 5), shape(B) = (4, 5) + shape(A) = (2, 3, 4, 5), shape(B) = (3, 4), with axis=1 + shape(A) = (2, 3, 4, 5), shape(B) = (2), with axis=0 + + Attribute `broadcast=1` needs to be passed to enable broadcasting. + +#### Version + +This version of the operator has been available since version 1 of the default ONNX operator set. + +#### Attributes + +
+
axis : int
+
If set, defines the broadcast dimensions. See doc for details.
+
broadcast : int (default is 0)
+
Pass 1 to enable broadcasting
+
consumed_inputs : list of ints
+
legacy optimization attribute.
+
+ +#### Inputs + +
+
A : T
+
First operand, should share the type with the second operand.
+
B : T
+
Second operand. With broadcasting can be of smaller size than A. If broadcasting is disabled it should be of the same size.
+
+ +#### Outputs + +
+
C : T
+
Result, has same dimensions and type as A
+
+ +#### Type Constraints + +
+
T : tensor(float16), tensor(float), tensor(double)
+
Constrain input and output types to float tensors.
+
+ +### **And-1** + + Returns the tensor resulted from performing the `and` logical operation + elementwise on the input tensors `A` and `B`. + + If broadcasting is enabled, the right-hand-side argument will be broadcasted + to match the shape of left-hand-side argument. See the doc of `Add` for a + detailed description of the broadcasting rules. + +#### Version + +This version of the operator has been available since version 1 of the default ONNX operator set. + +#### Attributes + +
+
axis : int
+
If set, defines the broadcast dimensions.
+
broadcast : int (default is 0)
+
Enable broadcasting
+
+ +#### Inputs + +
+
A : T
+
Left input tensor for the logical operator.
+
B : T
+
Right input tensor for the logical operator.
+
+ +#### Outputs + +
+
C : T1
+
Result tensor.
+
+ +#### Type Constraints + +
+
T : tensor(bool)
+
Constrains input to boolean tensor.
+
T1 : tensor(bool)
+
Constrains output to boolean tensor.
+
+ +### **ArgMax-1** + + Computes the indices of the max elements of the input tensor's element along the + provided axis. The resulted tensor has the same rank as the input if keepdims equal 1. + If keepdims equal 0, then the resulted tensor have the reduced dimension pruned. + The type of the output tensor is integer. + +#### Version + +This version of the operator has been available since version 1 of the default ONNX operator set. + +#### Attributes + +
+
axis : int (default is 0)
+
The axis in which to compute the arg indices.
+
keepdims : int (default is 1)
+
Keep the reduced dimension or not, default 1 mean keep reduced dimension.
+
+ +#### Inputs + +
+
data : T
+
An input tensor.
+
+ +#### Outputs + +
+
reduced : tensor(int64)
+
Reduced output tensor with integer data type.
+
+ +#### Type Constraints + +
+
T : tensor(uint8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(int8), tensor(int16), tensor(int32), tensor(int64), tensor(float16), tensor(float), tensor(double)
+
Constrain input and output types to all numeric tensors.
+
+ +### **ArgMin-1** + + Computes the indices of the min elements of the input tensor's element along the + provided axis. The resulted tensor has the same rank as the input if keepdims equal 1. + If keepdims equal 0, then the resulted tensor have the reduced dimension pruned. + The type of the output tensor is integer. + +#### Version + +This version of the operator has been available since version 1 of the default ONNX operator set. + +#### Attributes + +
+
axis : int (default is 0)
+
The axis in which to compute the arg indices.
+
keepdims : int (default is 1)
+
Keep the reduced dimension or not, default 1 mean keep reduced dimension.
+
+ +#### Inputs + +
+
data : T
+
An input tensor.
+
+ +#### Outputs + +
+
reduced : tensor(int64)
+
Reduced output tensor with integer data type.
+
+ +#### Type Constraints + +
+
T : tensor(uint8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(int8), tensor(int16), tensor(int32), tensor(int64), tensor(float16), tensor(float), tensor(double)
+
Constrain input and output types to all numeric tensors.
+
+ +### **AveragePool-1** + + AveragePool consumes an input tensor X and applies average pooling across + the tensor according to kernel sizes, stride sizes, and pad lengths. + average pooling consisting of computing the average on all values of a + subset of the input tensor according to the kernel size and downsampling the + data into the output tensor Y for further processing. The output spatial shape will be following: + ``` + output_spatial_shape[i] = floor((input_spatial_shape[i] + pad_shape[i] - kernel_spatial_shape[i]) / strides_spatial_shape[i] + 1) + + * pad_shape[i] is sum of pads along axis i + ``` + + `auto_pad` is a DEPRECATED attribute. If you are using them currently, the output spatial shape will be following: + ``` + VALID: output_spatial_shape[i] = ceil((input_spatial_shape[i] - kernel_spatial_shape[i] + 1) / strides_spatial_shape[i]) + SAME_UPPER or SAME_LOWER: output_spatial_shape[i] = ceil(input_spatial_shape[i] / strides_spatial_shape[i]) + ``` + And pad shape will be following if `SAME_UPPER` or `SAME_LOWER`: + ``` + pad_shape[i] = (output_spatial_shape[i] - 1) * strides_spatial_shape[i] + kernel_spatial_shape[i] - input_spatial_shape[i] + ``` + The output of each pooling window is divided by the number of elements exclude pad. + + +#### Version + +This version of the operator has been available since version 1 of the default ONNX operator set. + +#### Attributes + +
+
auto_pad : string (default is NOTSET)
+
auto_pad must be either NOTSET, SAME_UPPER, SAME_LOWER or VALID. Where default value is NOTSET, which means explicit padding is used. SAME_UPPER or SAME_LOWER mean pad the input so that the output spatial size match the input.In case of odd number add the extra padding at the end for SAME_UPPER and at the beginning for SAME_LOWER. VALID mean no padding.
+
kernel_shape : list of ints (required)
+
The size of the kernel along each axis.
+
pads : list of ints
+
Padding for the beginning and ending along each spatial axis, it can take any value greater than or equal to 0. The value represent the number of pixels added to the beginning and end part of the corresponding axis. `pads` format should be as follow [x1_begin, x2_begin...x1_end, x2_end,...], where xi_begin the number of pixels added at the beginning of axis `i` and xi_end, the number of pixels added at the end of axis `i`. This attribute cannot be used simultaneously with auto_pad attribute. If not present, the padding defaults to 0 along start and end of each spatial axis.
+
strides : list of ints
+
Stride along each spatial axis.
+
+ +#### Inputs + +
+
X : T
+
Input data tensor from the previous operator; dimensions for image case are (N x C x H x W), where N is the batch size, C is the number of channels, and H and W are the height and the width of the data. For non image case, the dimensions are in the form of (N x C x D1 x D2 ... Dn), where N is the batch size. Optionally, if dimension denotation is in effect, the operation expects the input data tensor to arrive with the dimension denotation of [DATA_BATCH, DATA_CHANNEL, DATA_FEATURE, DATA_FEATURE ...].
+
+ +#### Outputs + +
+
Y : T
+
Output data tensor from average or max pooling across the input tensor. Dimensions will vary based on various kernel, stride, and pad sizes. Floor value of the dimension is used
+
+ +#### Type Constraints + +
+
T : tensor(float16), tensor(float), tensor(double)
+
Constrain input and output types to float tensors.
+
+ +### **BatchNormalization-1** + + Carries out batch normalization as described in the paper + https://arxiv.org/abs/1502.03167. Depending on the mode it is being run, + there are multiple cases for the number of outputs, which we list below: + + Output case #1: Y, mean, var, saved_mean, saved_var (training mode) + Output case #2: Y (test mode) + + +#### Version + +This version of the operator has been available since version 1 of the default ONNX operator set. + +#### Attributes + +
+
consumed_inputs : list of ints (required)
+
legacy optimization attribute.
+
epsilon : float (default is 1e-05)
+
The epsilon value to use to avoid division by zero, default is 1e-5f.
+
is_test : int (default is 0)
+
If set to nonzero, run spatial batch normalization in test mode, default is 0.
+
momentum : float (default is 0.9)
+
Factor used in computing the running mean and variance.e.g., running_mean = running_mean * momentum + mean * (1 - momentum), default is 0.9f.
+
spatial : int (default is 1)
+
If true, compute the mean and variance across all spatial elements If false, compute the mean and variance across per feature.Default is 1.
+
+ +#### Inputs + +
+
X : T
+
The input 4-dimensional tensor of shape NCHW.
+
scale : T
+
The scale as a 1-dimensional tensor of size C to be applied to the output.
+
B : T
+
The bias as a 1-dimensional tensor of size C to be applied to the output.
+
mean : T
+
The running mean (training) or the estimated mean (testing) as a 1-dimensional tensor of size C.
+
var : T
+
The running variance (training) or the estimated variance (testing) as a 1-dimensional tensor of size C.
+
+ +#### Outputs (1 - 5) + +
+
Y : T
+
The output 4-dimensional tensor of the same shape as X.
+
mean (optional) : T
+
The running mean after the BatchNormalization operator. Must be in-place with the input mean. Should not be used for testing.
+
var (optional) : T
+
The running variance after the BatchNormalization operator. Must be in-place with the input var. Should not be used for testing.
+
saved_mean (optional) : T
+
Saved mean used during training to speed up gradient computation. Should not be used for testing.
+
saved_var (optional) : T
+
Saved variance used during training to speed up gradient computation. Should not be used for testing.
+
+ +#### Type Constraints + +
+
T : tensor(float16), tensor(float), tensor(double)
+
Constrain input and output types to float tensors.
+
+ +### **Cast-1** + + The operator casts the elements of a given input tensor to a data type + specified by the 'to' argument and returns an output tensor of the same size in + the converted type. The 'to' argument must be one of the data types specified + in the 'DataType' enum field in the TensorProto message. + NOTE: Casting to and from strings is not supported yet. + +#### Version + +This version of the operator has been available since version 1 of the default ONNX operator set. + +#### Attributes + +
+
to : string (required)
+
The data type to which the elements of the input tensor are cast. Strictly must be one of the types from DataType enum in TensorProto
+
+ +#### Inputs + +
+
input : T1
+
Input tensor to be cast.
+
+ +#### Outputs + +
+
output : T2
+
Output tensor with the same shape as input with type specified by the 'to' argument
+
+ +#### Type Constraints + +
+
T1 : tensor(float16), tensor(float), tensor(double), tensor(int8), tensor(int16), tensor(int32), tensor(int64), tensor(uint8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(bool)
+
Constrain input types. Casting from strings and complex are not supported.
+
T2 : tensor(float16), tensor(float), tensor(double), tensor(int8), tensor(int16), tensor(int32), tensor(int64), tensor(uint8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(bool)
+
Constrain output types. Casting to strings and complex are not supported.
+
+ +### **Ceil-1** + + Ceil takes one input data (Tensor) and produces one output data + (Tensor) where the ceil is, y = ceil(x), is applied to + the tensor elementwise. + +#### Version + +This version of the operator has been available since version 1 of the default ONNX operator set. + +#### Attributes + +
+
consumed_inputs : list of ints
+
legacy optimization attribute.
+
+ +#### Inputs + +
+
X : T
+
Input tensor
+
+ +#### Outputs + +
+
Y : T
+
Output tensor
+
+ +#### Type Constraints + +
+
T : tensor(float16), tensor(float), tensor(double)
+
Constrain input and output types to float tensors.
+
+ +### **Clip-1** + + Clip operator limits the given input within an interval. The interval is + specified with arguments 'min' and 'max'. They default to + numeric_limits::lowest() and numeric_limits::max() respectively. + +#### Version + +This version of the operator has been available since version 1 of the default ONNX operator set. + +#### Attributes + +
+
consumed_inputs : list of ints
+
legacy optimization attribute.
+
max : float
+
Maximum value, above which element is replaced by max
+
min : float
+
Minimum value, under which element is replaced by min
+
+ +#### Inputs + +
+
input : T
+
Input tensor whose elements to be clipped
+
+ +#### Outputs + +
+
output : T
+
Output tensor with clipped input elements
+
+ +#### Type Constraints + +
+
T : tensor(float16), tensor(float), tensor(double)
+
Constrain input and output types to float tensors.
+
+ +### **Concat-1** + + Concatenate a list of tensors into a single tensor + +#### Version + +This version of the operator has been available since version 1 of the default ONNX operator set. + +#### Attributes + +
+
axis : int
+
Which axis to concat on. Default value is 1.
+
+ +#### Inputs (1 - ∞) + +
+
inputs (variadic) : T
+
List of tensors for concatenation
+
+ +#### Outputs + +
+
concat_result : T
+
Concatenated tensor
+
+ +#### Type Constraints + +
+
T : tensor(float16), tensor(float), tensor(double)
+
Constrain output types to float tensors.
+
+ +### **Constant-1** + + A constant tensor. + +#### Version + +This version of the operator has been available since version 1 of the default ONNX operator set. + +#### Attributes + +
+
value : tensor (required)
+
The value for the elements of the output tensor.
+
+ +#### Inputs + + +#### Outputs + +
+
output : T
+
Output tensor containing the same value of the provided tensor.
+
+ +#### Type Constraints + +
+
T : tensor(float16), tensor(float), tensor(double)
+
Constrain input and output types to float tensors.
+
+ +### **Conv-1** + + The convolution operator consumes an input tensor and a filter, and + computes the output. + +#### Version + +This version of the operator has been available since version 1 of the default ONNX operator set. + +#### Attributes + +
+
auto_pad : string (default is NOTSET)
+
auto_pad must be either NOTSET, SAME_UPPER, SAME_LOWER or VALID. Where default value is NOTSET, which means explicit padding is used. SAME_UPPER or SAME_LOWER mean pad the input so that the output spatial size match the input.In case of odd number add the extra padding at the end for SAME_UPPER and at the beginning for SAME_LOWER. VALID mean no padding.
+
dilations : list of ints
+
dilation value along each spatial axis of the filter.
+
group : int (default is 1)
+
number of groups input channels and output channels are divided into.
+
kernel_shape : list of ints
+
The shape of the convolution kernel. If not present, should be inferred from input W.
+
pads : list of ints
+
Padding for the beginning and ending along each spatial axis, it can take any value greater than or equal to 0. The value represent the number of pixels added to the beginning and end part of the corresponding axis. `pads` format should be as follow [x1_begin, x2_begin...x1_end, x2_end,...], where xi_begin the number of pixels added at the beginning of axis `i` and xi_end, the number of pixels added at the end of axis `i`. This attribute cannot be used simultaneously with auto_pad attribute. If not present, the padding defaults to 0 along start and end of each spatial axis.
+
strides : list of ints
+
Stride along each spatial axis.
+
+ +#### Inputs (2 - 3) + +
+
X : T
+
Input data tensor from previous layer; has size (N x C x H x W), where N is the batch size, C is the number of channels, and H and W are the height and width. Note that this is for the 2D image. Otherwise the size is (N x C x D1 x D2 ... x Dn). Optionally, if dimension denotation is in effect, the operation expects input data tensor to arrive with the dimension denotation of [DATA_BATCH, DATA_CHANNEL, DATA_FEATURE, DATA_FEATURE ...].
+
W : T
+
The weight tensor that will be used in the convolutions; has size (M x C/group x kH x kW), where C is the number of channels, and kH and kW are the height and width of the kernel, and M is the number of feature maps. For more than 2 dimensions, the kernel shape will be (M x C/group x k1 x k2 x ... x kn), where (k1 x k2 x ... kn) is the dimension of the kernel. Optionally, if dimension denotation is in effect, the operation expects the weight tensor to arrive with the dimension denotation of [FILTER_OUT_CHANNEL, FILTER_IN_CHANNEL, FILTER_SPATIAL, FILTER_SPATIAL ...]. X.shape[1] == (W.shape[1] * group) == C (assuming zero based indices for the shape array). Or in other words FILTER_IN_CHANNEL should be equal to DATA_CHANNEL.
+
B (optional) : T
+
Optional 1D bias to be added to the convolution, has size of M.
+
+ +#### Outputs + +
+
Y : T
+
Output data tensor that contains the result of the convolution. The output dimensions are functions of the kernel size, stride size, and pad lengths.
+
+ +#### Type Constraints + +
+
T : tensor(float16), tensor(float), tensor(double)
+
Constrain input and output types to float tensors.
+
+ +### **ConvTranspose-1** + + The convolution transpose operator consumes an input tensor and a filter, + and computes the output. + + If the pads parameter is provided the shape of the output is calculated via the following equation: + + 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] + + output_shape can also be explicitly specified in which case pads values are auto generated using these equations: + + total_padding[i] = stride[i] * (input_size[i] - 1) + output_padding[i] + ((kernel_shape[i] - 1) * dilations[i] + 1) - output_shape[i] + If (auto_pads != SAME_UPPER): pads[start_i] = total_padding[i]/2; pads[end_i] = total_padding[i] - (total_padding[i]/2) + Else: pads[start_i] = total_padding[i] - (total_padding[i]/2); pads[end_i] = (total_padding[i]/2). + + + +#### Version + +This version of the operator has been available since version 1 of the default ONNX operator set. + +#### Attributes + +
+
auto_pad : string (default is NOTSET)
+
auto_pad must be either NOTSET, SAME_UPPER, SAME_LOWER or VALID. Where default value is NOTSET, which means explicit padding is used. SAME_UPPER or SAME_LOWER mean pad the input so that the output spatial size match the input.In case of odd number add the extra padding at the end for SAME_UPPER and at the beginning for SAME_LOWER. VALID mean no padding.
+
dilations : list of ints
+
dilation value along each spatial axis of the filter.
+
group : int (default is 1)
+
number of groups input channels and output channels are divided into.
+
kernel_shape : list of ints
+
The shape of the convolution kernel. If not present, should be inferred from input W.
+
output_padding : list of ints
+
The zero-padding added to one side of the output. This is also called adjs/adjustment in some frameworks.
+
output_shape : list of ints
+
The shape of the output can be explicitly set which will cause pads values to be auto generated. If output_shape is specified pads values are ignored. See doc for details for equations to generate pads
+
pads : list of ints
+
Padding for the beginning and ending along each spatial axis, it can take any value greater than or equal to 0. The value represent the number of pixels added to the beginning and end part of the corresponding axis. `pads` format should be as follow [x1_begin, x2_begin...x1_end, x2_end,...], where xi_begin the number of pixels added at the beginning of axis `i` and xi_end, the number of pixels added at the end of axis `i`. This attribute cannot be used simultaneously with auto_pad attribute. If not present, the padding defaults to 0 along start and end of each spatial axis.
+
strides : list of ints
+
Stride along each spatial axis.
+
+ +#### Inputs (2 - 3) + +
+
X : T
+
Input data tensor from previous layer; has size (N x C x H x W), where N is the batch size, C is the number of channels, and H and W are the height and width. Note that this is for the 2D image. Otherwise the size is (N x C x D1 x D2 ... x Dn)
+
W : T
+
The weight tensor that will be used in the convolutions; has size (C x M/group x kH x kW), where C is the number of channels, and kH and kW are the height and width of the kernel, and M is the number of feature maps. For more than 2 dimensions, the weight shape will be (C x M/group x k1 x k2 x ... x kn), where (k1 x k2 x ... x kn) is the dimension of the kernel. The number of channels in the output should be equal to W.shape[1] * group (assuming zero based indices of the shape array)
+
B (optional) : T
+
Optional 1D bias to be added to the convolution, has size of M.
+
+ +#### Outputs + +
+
Y : T
+
Output data tensor that contains the result of the convolution. The output dimensions are functions of the kernel size, stride size, pad lengths and group count. The number of channels in the output should be equal to W.shape[1] * group (assuming zero based indices of the shape array)
+
+ +#### Type Constraints + +
+
T : tensor(float16), tensor(float), tensor(double)
+
Constrain input and output types to float tensors.
+
+ +### **DepthToSpace-1** + + DepthToSpace rearranges (permutes) data from depth into blocks of spatial data. + This is the reverse transformation of SpaceToDepth. More specifically, this op outputs a copy of + the input tensor where values from the depth dimension are moved in spatial blocks to the height + and width dimensions. + +#### Version + +This version of the operator has been available since version 1 of the default ONNX operator set. + +#### Attributes + +
+
blocksize : int (required)
+
Blocks of [blocksize, blocksize] are moved.
+
+ +#### Inputs + +
+
input : T
+
Input tensor of [N,C,H,W], where N is the batch axis, C is the channel or depth, H is the height and W is the width.
+
+ +#### Outputs + +
+
output : T
+
Output tensor of [N, C/(blocksize * blocksize), H * blocksize, W * blocksize].
+
+ +#### Type Constraints + +
+
T : tensor(uint8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(int8), tensor(int16), tensor(int32), tensor(int64), tensor(float16), tensor(float), tensor(double), tensor(string), tensor(bool), tensor(complex64), tensor(complex128)
+
Constrain input and output types to all tensor types.
+
+ +### **Div-1** + + Performs element-wise binary division (with limited broadcast support). + + If necessary the right-hand-side argument will be broadcasted to match the + shape of left-hand-side argument. When broadcasting is specified, the second + tensor can either be of element size 1 (including a scalar tensor and any + tensor with rank equal to or smaller than the first tensor), or having its + shape as a contiguous subset of the first tensor's shape. The starting of the + mutually equal shape is specified by the argument "axis", and if it is not set, + suffix matching is assumed. 1-dim expansion doesn't work yet. + + For example, the following tensor shapes are supported (with broadcast=1): + + shape(A) = (2, 3, 4, 5), shape(B) = (,), i.e. B is a scalar tensor + shape(A) = (2, 3, 4, 5), shape(B) = (1, 1), i.e. B is an 1-element tensor + shape(A) = (2, 3, 4, 5), shape(B) = (5,) + shape(A) = (2, 3, 4, 5), shape(B) = (4, 5) + shape(A) = (2, 3, 4, 5), shape(B) = (3, 4), with axis=1 + shape(A) = (2, 3, 4, 5), shape(B) = (2), with axis=0 + + Attribute `broadcast=1` needs to be passed to enable broadcasting. + +#### Version + +This version of the operator has been available since version 1 of the default ONNX operator set. + +#### Attributes + +
+
axis : int
+
If set, defines the broadcast dimensions. See doc for details.
+
broadcast : int (default is 0)
+
Pass 1 to enable broadcasting
+
consumed_inputs : list of ints
+
legacy optimization attribute.
+
+ +#### Inputs + +
+
A : T
+
First operand, should share the type with the second operand.
+
B : T
+
Second operand. With broadcasting can be of smaller size than A. If broadcasting is disabled it should be of the same size.
+
+ +#### Outputs + +
+
C : T
+
Result, has same dimensions and type as A
+
+ +#### Type Constraints + +
+
T : tensor(float16), tensor(float), tensor(double)
+
Constrain input and output types to float tensors.
+
+ +### **Dropout-1** + + Dropout takes one input data (Tensor) and produces two Tensor outputs, + output (Tensor) and mask (Tensor). Depending on whether it is in + test mode or not, the output Y will either be a random dropout, or a simple + copy of the input. Note that our implementation of Dropout does scaling in + the training phase, so during testing nothing needs to be done. + +#### Version + +This version of the operator has been available since version 1 of the default ONNX operator set. + +#### Attributes + +
+
consumed_inputs : list of ints
+
legacy optimization attribute.
+
is_test : int (default is 0)
+
(int, default 0) if nonzero, run dropout in test mode where the output is simply Y = X.
+
ratio : float (default is 0.5)
+
(float, default 0.5) the ratio of random dropout
+
+ +#### Inputs + +
+
data : T
+
The input data as Tensor.
+
+ +#### Outputs (1 - 2) + +
+
output : T
+
The output.
+
mask (optional) : T
+
The output mask. If is_test is nonzero, this output is not filled.
+
+ +#### Type Constraints + +
+
T : tensor(float16), tensor(float), tensor(double)
+
Constrain input and output types to float tensors.
+
+ +### **Elu-1** + + Elu takes one input data (Tensor) and produces one output data + (Tensor) where the function `f(x) = alpha * (exp(x) - 1.) for x < + 0`, `f(x) = x for x >= 0`., is applied to the tensor elementwise. + + +#### Version + +This version of the operator has been available since version 1 of the default ONNX operator set. + +#### Attributes + +
+
alpha : float (default is 1.0)
+
Coefficient of ELU default to 1.0.
+
consumed_inputs : list of ints
+
legacy optimization attribute.
+
+ +#### Inputs + +
+
X : T
+
1D input tensor
+
+ +#### Outputs + +
+
Y : T
+
1D input tensor
+
+ +#### Type Constraints + +
+
T : tensor(float16), tensor(float), tensor(double)
+
Constrain input and output types to float tensors.
+
+ +### **Equal-1** + + Returns the tensor resulted from performing the `equal` logical operation + elementwise on the input tensors `A` and `B`. + + If broadcasting is enabled, the right-hand-side argument will be broadcasted + to match the shape of left-hand-side argument. See the doc of `Add` for a + detailed description of the broadcasting rules. + +#### Version + +This version of the operator has been available since version 1 of the default ONNX operator set. + +#### Attributes + +
+
axis : int
+
If set, defines the broadcast dimensions.
+
broadcast : int (default is 0)
+
Enable broadcasting
+
+ +#### Inputs + +
+
A : T
+
Left input tensor for the logical operator.
+
B : T
+
Right input tensor for the logical operator.
+
+ +#### Outputs + +
+
C : T1
+
Result tensor.
+
+ +#### Type Constraints + +
+
T : tensor(bool), tensor(int32), tensor(int64)
+
Constrains input to integral tensors.
+
T1 : tensor(bool)
+
Constrains output to boolean tensor.
+
+ +### **Exp-1** + + Calculates the exponential of the given input tensor, element-wise. + +#### Version + +This version of the operator has been available since version 1 of the default ONNX operator set. + +#### Attributes + +
+
consumed_inputs : list of ints
+
legacy optimization attribute.
+
+ +#### Inputs + +
+
input : T
+
Input tensor
+
+ +#### Outputs + +
+
output : T
+
The exponential of the input tensor computed element-wise
+
+ +#### Type Constraints + +
+
T : tensor(float16), tensor(float), tensor(double)
+
Constrain input and output types to float tensors.
+
+ +### **Flatten-1** + + Flattens the input tensor into a 2D matrix. If input tensor has shape + (d_0, d_1, ... d_n) then the output will have shape + (d_0 X d_1 ... d_(axis-1), d_axis X d_(axis+1) ... X dn). + +#### Version + +This version of the operator has been available since version 1 of the default ONNX operator set. + +#### Attributes + +
+
axis : int (default is 1)
+
Indicate up to which input dimensions (exclusive) should be flattened to the outer dimension of the output. The value for axis must be in the range [0, R], where R is the rank of the input tensor. When axis = 0, the shape of the output tensor is (1, (d_0 X d_1 ... d_n), where the shape of the input tensor is (d_0, d_1, ... d_n).
+
+ +#### Inputs + +
+
input : T
+
A tensor of rank >= axis.
+
+ +#### Outputs + +
+
output : T
+
A 2D tensor with the contents of the input tensor, with input dimensions up to axis flattened to the outer dimension of the output and remaining input dimensions flattened into the inner dimension of the output.
+
+ +#### Type Constraints + +
+
T : tensor(float16), tensor(float), tensor(double)
+
Constrain input and output types to float tensors.
+
+ +### **Floor-1** + + Floor takes one input data (Tensor) and produces one output data + (Tensor) where the floor is, y = floor(x), is applied to + the tensor elementwise. + +#### Version + +This version of the operator has been available since version 1 of the default ONNX operator set. + +#### Attributes + +
+
consumed_inputs : list of ints
+
legacy optimization attribute.
+
+ +#### Inputs + +
+
X : T
+
Input tensor
+
+ +#### Outputs + +
+
Y : T
+
Output tensor
+
+ +#### Type Constraints + +
+
T : tensor(float16), tensor(float), tensor(double)
+
Constrain input and output types to float tensors.
+
+ +### **GRU-1** + + Computes an one-layer GRU. This operator is usually supported via some custom + implementation such as CuDNN. + + Notations: + + `X` - input tensor + + `z` - update gate + + `r` - reset gate + + `h` - hidden gate + + `t` - time step (t-1 means previous time step) + + `W[zrh]` - W parameter weight matrix for update, reset, and hidden gates + + `R[zrh]` - R recurrence weight matrix for update, reset, and hidden gates + + `Wb[zrh]` - W bias vectors for update, reset, and hidden gates + + `Rb[zrh]` - R bias vectors for update, reset, and hidden gates + + `WB[zrh]` - W parameter weight matrix for backward update, reset, and hidden gates + + `RB[zrh]` - R recurrence weight matrix for backward update, reset, and hidden gates + + `WBb[zrh]` - W bias vectors for backward update, reset, and hidden gates + + `RBb[zrh]` - R bias vectors for backward update, reset, and hidden gates + + `H` - Hidden state + + `num_directions` - 2 if direction == bidirectional else 1 + + Activation functions: + + Relu(x) - max(0, x) + + Tanh(x) - (1 - e^{-2x})/(1 + e^{-2x}) + + Sigmoid(x) - 1/(1 + e^{-x}) + + (NOTE: Below are optional) + + Affine(x) - alpha*x + beta + + LeakyRelu(x) - x if x >= 0 else alpha * x + + ThresholdedRelu(x) - x if x >= alpha else 0 + + ScaledTanh(x) - alpha*Tanh(beta*x) + + HardSigmoid(x) - min(max(alpha*x + beta, 0), 1) + + Elu(x) - x if x >= 0 else alpha*(e^x - 1) + + Softsign(x) - x/(1 + |x|) + + Softplus(x) - log(1 + e^x) + + Equations (Default: f=Sigmoid, g=Tanh): + + - zt = f(Xt*(Wz^T) + Ht-1*Rz + Wbz + Rbz) + + - rt = f(Xt*(Wr^T) + Ht-1*Rr + Wbr + Rbr) + + - ht = g(Xt*(Wh^T) + (rt (.) Ht-1)*Rh + Rbh + Wbh) # default, when linear_before_reset = 0 + + - ht = g(Xt*(Wh^T) + (rt (.) (Ht-1*Rh + Rbh) + Wbh) # when linear_before_reset != 0 + + - Ht = (1 - zt) (.) ht + zt (.) Ht-1 + +#### Version + +This version of the operator has been available since version 1 of the default ONNX operator set. + +#### Attributes + +
+
activation_alpha : list of floats
+
Optional scaling values used by some activation functions. The values are consumed in the order of activation functions, for example (f, g, h) in LSTM.
+
activation_beta : list of floats
+
Optional scaling values used by some activation functions. The values are consumed in the order of activation functions, for example (f, g, h) in LSTM.
+
activations : list of strings
+
A list of 2 (or 4 if bidirectional) activation functions for update, reset, and hidden gates. The activation functions must be one of the activation functions specified above. Optional: See the equations for default if not specified.
+
clip : float
+
Cell clip threshold. Clipping bounds the elements of a tensor in the range of [-threshold, +threshold] and is applied to the input of activations. No clip if not specified.
+
direction : string (default is foward)
+
Specify if the RNN is forward, reverse, or bidirectional. Must be one of forward (default), reverse, or bidirectional.
+
hidden_size : int
+
Number of neurons in the hidden layer
+
output_sequence : int (default is 0)
+
The sequence output for the hidden is optional if 0. Default 0.
+
+ +#### Inputs (3 - 6) + +
+
X : T
+
The input sequences packed (and potentially padded) into one 3-D tensor with the shape of `[seq_length, batch_size, input_size]`.
+
W : T
+
The weight tensor for the gates. Concatenation of `W[zrh]` and `WB[zrh]` (if bidirectional) along dimension 0. This tensor has shape `[num_directions, 3*hidden_size, input_size]`.
+
R : T
+
The recurrence weight tensor. Concatenation of `R[zrh]` and `RB[zrh]` (if bidirectional) along dimension 0. This tensor has shape `[num_directions, 3*hidden_size, hidden_size]`.
+
B (optional) : T
+
The bias tensor for the gates. Concatenation of `[Wb[zrh], Rb[zrh]]` and `[WBb[zrh], RBb[zrh]]` (if bidirectional) along dimension 0. This tensor has shape `[num_directions, 6*hidden_size]`. Optional: If not specified - assumed to be 0
+
sequence_lens (optional) : T1
+
Optional tensor specifying lengths of the sequences in a batch. If not specified - assumed all sequences in the batch to have length `seq_length`. It has shape `[batch_size]`.
+
initial_h (optional) : T
+
Optional initial value of the hidden. If not specified - assumed to be 0. It has shape `[num_directions, batch_size, hidden_size]`.
+
+ +#### Outputs + +
+
Y (optional) : T
+
A tensor that concats all the intermediate output values of the hidden. It has shape `[seq_length, num_directions, batch_size, hidden_size]`. It is optional if `output_sequence` is 0.
+
Y_h : T
+
The last output value of the hidden. It has shape `[num_directions, batch_size, hidden_size]`.
+
+ +#### Type Constraints + +
+
T : tensor(float16), tensor(float), tensor(double)
+
Constrain input and output types to float tensors.
+
T1 : tensor(int32)
+
Constrain seq_lens to integer tensor.
+
+ +### **Gather-1** + + Given `data` tensor of rank r >= 1, and `indices` tensor of rank q, gather + entries of the axis dimension of `data` (by default outer-most one as axis=0) indexed by `indices`, and concatenates + them in an output tensor of rank q + (r - 1). + Example 1: + ``` + data = [ + [1.0, 1.2], + [2.3, 3.4], + [4.5, 5.7], + ] + indices = [ + [0, 1], + [1, 2], + ] + output = [ + [ + [1.0, 1.2], + [2.3, 3.4], + ], + [ + [2.3, 3.4], + [4.5, 5.7], + ], + ] + ``` + Example 2: + ``` + data = [ + [1.0, 1.2, 1.9], + [2.3, 3.4, 3.9], + [4.5, 5.7, 5.9], + ] + indices = [ + [0, 2], + ] + axis = 1, + output = [ + [ + [1.0, 1.9], + [2.3, 3.9], + [4.5, 5.9], + ], + ] + ``` + +#### Version + +This version of the operator has been available since version 1 of the default ONNX operator set. + +#### Attributes + +
+
axis : int (default is 0)
+
Which axis to gather on. Negative value means counting dimensions from the back. Accepted range is [-r, r-1]
+
+ +#### Inputs + +
+
data : T
+
Tensor of rank r >= 1.
+
indices : Tind
+
Tensor of int32/int64 indices, of any rank q. All index values are expected to be within bounds. It is an error if any of the index values are out of bounds.
+
+ +#### Outputs + +
+
output : T
+
Tensor of rank q + (r - 1).
+
+ +#### Type Constraints + +
+
T : tensor(uint8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(int8), tensor(int16), tensor(int32), tensor(int64), tensor(float16), tensor(float), tensor(double), tensor(string), tensor(bool), tensor(complex64), tensor(complex128)
+
Constrain input and output types to any tensor type.
+
Tind : tensor(int32), tensor(int64)
+
Constrain indices to integer types
+
+ +### **Gemm-1** + + General Matrix multiplication: + https://en.wikipedia.org/wiki/Basic_Linear_Algebra_Subprograms#Level_3 + Compute Y = alpha * A * B + beta * C, where input tensor A has + dimension (M X K), input tensor B has dimension (K X N), input tensor C and + output tensor Y have dimension (M X N). + If attribute broadcast is non-zero, input tensor C will be broadcasted to match + the dimension requirement. A will be transposed before doing the computation + if attribute transA is non-zero, same for B and transB. + +#### Version + +This version of the operator has been available since version 1 of the default ONNX operator set. + +#### Attributes + +
+
alpha : float (default is 1.0)
+
Scalar multiplier for the product of input tensors A * B, the default value is 1.0.
+
beta : float (default is 1.0)
+
Scalar multiplier for input tensor C, the default value is 1.0.
+
broadcast : int (default is 0)
+
Whether C should be broadcasted
+
transA : int (default is 0)
+
Whether A should be transposed
+
transB : int (default is 0)
+
Whether B should be transposed
+
+ +#### Inputs + +
+
A : T
+
Input tensor A
+
B : T
+
Input tensor B
+
C : T
+
Input tensor C, can be inplace.
+
+ +#### Outputs + +
+
Y : T
+
Output tensor.
+
+ +#### Type Constraints + +
+
T : tensor(float16), tensor(float), tensor(double)
+
Constrain input and output types to float tensors.
+
+ +### **GlobalAveragePool-1** + + GlobalAveragePool consumes an input tensor X and applies average pooling across + the values in the same channel. This is equivalent to AveragePool with kernel size + equal to the spatial dimension of input tensor. + +#### Version + +This version of the operator has been available since version 1 of the default ONNX operator set. + +#### Inputs + +
+
X (differentiable) : T
+
Input data tensor from the previous operator; dimensions for image case are (N x C x H x W), where N is the batch size, C is the number of channels, and H and W are the height and the width of the data. For non image case, the dimensions are in the form of (N x C x D1 x D2 ... Dn), where N is the batch size.
+
+ +#### Outputs + +
+
Y (differentiable) : T
+
Output data tensor from pooling across the input tensor. The output tensor has the same rank as the input. The first two dimensions of output shape are the same as the input (N x C), while the other dimensions are all 1.
+
+ +#### Type Constraints + +
+
T : tensor(float16), tensor(float), tensor(double)
+
Constrain input and output types to float tensors.
+
+ +### **GlobalLpPool-1** + + GlobalLpPool consumes an input tensor X and applies lp pool pooling across the + the values in the same channel. This is equivalent to LpPool with kernel size + equal to the spatial dimension of input tensor. + +#### Version + +This version of the operator has been available since version 1 of the default ONNX operator set. + +#### Attributes + +
+
p : float (default is 2.0)
+
p value of the Lp norm used to pool over the input data, default is 2.0.
+
+ +#### Inputs + +
+
X : T
+
Input data tensor from the previous operator; dimensions for image case are (N x C x H x W), where N is the batch size, C is the number of channels, and H and W are the height and the width of the data. For non image case, the dimension are in the form of (N x C x D1 x D2 ... Dn), where N is the batch size.
+
+ +#### Outputs + +
+
Y : T
+
Output data tensor from pooling across the input tensor. Dimensions will be N x C x 1 x 1
+
+ +#### Type Constraints + +
+
T : tensor(float16), tensor(float), tensor(double)
+
Constrain input and output types to float tensors.
+
+ +### **GlobalMaxPool-1** + + GlobalMaxPool consumes an input tensor X and applies max pooling across + the values in the same channel. This is equivalent to MaxPool with kernel size + equal to the spatial dimension of input tensor. + +#### Version + +This version of the operator has been available since version 1 of the default ONNX operator set. + +#### Inputs + +
+
X (differentiable) : T
+
Input data tensor from the previous operator; dimensions for image case are (N x C x H x W), where N is the batch size, C is the number of channels, and H and W are the height and the width of the data. For non image case, the dimensions are in the form of (N x C x D1 x D2 ... Dn), where N is the batch size.
+
+ +#### Outputs + +
+
Y (differentiable) : T
+
Output data tensor from pooling across the input tensor. The output tensor has the same rank as the input. The first two dimensions of output shape are the same as the input (N x C), while the other dimensions are all 1.
+
+ +#### Type Constraints + +
+
T : tensor(float16), tensor(float), tensor(double)
+
Constrain input and output types to float tensors.
+
+ +### **Greater-1** + + Returns the tensor resulted from performing the `greater` logical operation + elementwise on the input tensors `A` and `B`. + + If broadcasting is enabled, the right-hand-side argument will be broadcasted + to match the shape of left-hand-side argument. See the doc of `Add` for a + detailed description of the broadcasting rules. + +#### Version + +This version of the operator has been available since version 1 of the default ONNX operator set. + +#### Attributes + +
+
axis : int
+
If set, defines the broadcast dimensions.
+
broadcast : int (default is 0)
+
Enable broadcasting
+
+ +#### Inputs + +
+
A : T
+
Left input tensor for the logical operator.
+
B : T
+
Right input tensor for the logical operator.
+
+ +#### Outputs + +
+
C : T1
+
Result tensor.
+
+ +#### Type Constraints + +
+
T : tensor(float16), tensor(float), tensor(double)
+
Constrains input to float tensors.
+
T1 : tensor(bool)
+
Constrains output to boolean tensor.
+
+ +### **HardSigmoid-1** + + HardSigmoid takes one input data (Tensor) and produces one output data + (Tensor) where the HardSigmoid function, y = max(0, min(1, alpha * x + beta)), + is applied to the tensor elementwise. + +#### Version + +This version of the operator has been available since version 1 of the default ONNX operator set. + +#### Attributes + +
+
alpha : float (default is 0.2)
+
Value of alpha default to 0.2
+
beta : float (default is 0.5)
+
Value of beta default to 0.5
+
consumed_inputs : list of ints
+
legacy optimization attribute.
+
+ +#### Inputs + +
+
X : T
+
Input tensor
+
+ +#### Outputs + +
+
Y : T
+
Output tensor
+
+ +#### Type Constraints + +
+
T : tensor(float16), tensor(float), tensor(double)
+
Constrain input and output types to float tensors.
+
+ +### **Hardmax-1** + + The operator computes the hardmax (1 for the first maximum value, and 0 for all others) values for each layer in the batch + of the given input. The input is a 2-D tensor (Tensor) of size + (batch_size x input_feature_dimensions). The output tensor has the same shape + and contains the hardmax values of the corresponding input. + + Input does not need to explicitly be a 2D vector; rather, it will be + coerced into one. For an arbitrary n-dimensional tensor + input \in [a_0, a_1, ..., a_{k-1}, a_k, ..., a_{n-1}] and k is + the axis provided, then input will be coerced into a 2-dimensional tensor with + dimensions [a_0 * ... * a_{k-1}, a_k * ... * a_{n-1}]. For the default + case where axis=1, this means the input tensor will be coerced into a 2D tensor + of dimensions [a_0, a_1 * ... * a_{n-1}], where a_0 is often the batch size. + In this situation, we must have a_0 = N and a_1 * ... * a_{n-1} = D. + Each of these dimensions must be matched correctly, or else the operator + will throw errors. + +#### Version + +This version of the operator has been available since version 1 of the default ONNX operator set. + +#### Attributes + +
+
axis : int (default is 1)
+
Describes the axis of the inputs when coerced to 2D; defaults to one because the 0th axis most likely describes the batch_size
+
+ +#### Inputs + +
+
input : T
+
The input tensor that's coerced into a 2D matrix of size (NxD) as described above.
+
+ +#### Outputs + +
+
output : T
+
The output values with the same shape as input tensor (the original size without coercion).
+
+ +#### Type Constraints + +
+
T : tensor(float16), tensor(float), tensor(double)
+
Constrain input and output types to float tensors.
+
+ +### **Identity-1** + + Identity operator + +#### Version + +This version of the operator has been available since version 1 of the default ONNX operator set. + +#### Inputs + +
+
input : T
+
Input tensor
+
+ +#### Outputs + +
+
output : T
+
Tensor to copy input into.
+
+ +#### Type Constraints + +
+
T : tensor(uint8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(int8), tensor(int16), tensor(int32), tensor(int64), tensor(float16), tensor(float), tensor(double), tensor(string), tensor(bool), tensor(complex64), tensor(complex128)
+
Constrain input and output types to all tensor types.
+
+ +### **If-1** + + If conditional + +#### Version + +This version of the operator has been available since version 1 of the default ONNX operator set. + +#### Attributes + +
+
else_branch : graph (required)
+
Graph to run if condition is false. Has N outputs: values you wish to be live-out to the enclosing scope. The number of outputs must match the number of outputs in the then_branch.
+
then_branch : graph (required)
+
Graph to run if condition is true. Has N outputs: values you wish to be live-out to the enclosing scope. The number of outputs must match the number of outputs in the else_branch.
+
+ +#### Inputs + +
+
cond : B
+
Condition for the if
+
+ +#### Outputs (1 - ∞) + +
+
outputs (variadic, heterogeneous) : V
+
Values that are live-out to the enclosing scope. The return values in the `then_branch` and `else_branch` must be of the same shape and same data type.
+
+ +#### Type Constraints + +
+
V : tensor(uint8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(int8), tensor(int16), tensor(int32), tensor(int64), tensor(float16), tensor(float), tensor(double), tensor(string), tensor(bool), tensor(complex64), tensor(complex128)
+
All Tensor types
+
B : tensor(bool)
+
Only bool
+
+ +### **InstanceNormalization-1** + + Carries out instance normalization as described in the paper + https://arxiv.org/abs/1607.08022. + + y = scale * (x - mean) / sqrt(variance + epsilon) + B, + where mean and variance are computed per instance per channel. + + +#### Version + +This version of the operator has been available since version 1 of the default ONNX operator set. + +#### Attributes + +
+
consumed_inputs : list of ints
+
legacy optimization attribute.
+
epsilon : float (default is 1e-05)
+
The epsilon value to use to avoid division by zero, default is 1e-5f.
+
+ +#### Inputs + +
+
input : T
+
The input 4-dimensional tensor of shape NCHW.
+
scale : T
+
The input 1-dimensional scale tensor of size C.
+
B : T
+
The input 1-dimensional bias tensor of size C.
+
+ +#### Outputs + +
+
output : T
+
The output 4-dimensional tensor of the same shape as input.
+
+ +#### Type Constraints + +
+
T : tensor(float16), tensor(float), tensor(double)
+
Constrain input and output types to float tensors.
+
+ +### **LRN-1** + + Local Response Normalization proposed in the [AlexNet paper](https://papers.nips.cc/paper/4824-imagenet-classification-with-deep-convolutional-neural-networks.pdf). + It normalizes over local input regions. + The local region is defined across the channels. For an element X[n, c, d1, ..., dk] in a tensor + of shape (N x C x D1 x D2, ..., Dk), its region is + {X[n, i, d1, ..., dk] | max(0, c - floor((size - 1) / 2)) <= i <= min(C - 1, c + ceil((size - 1) / 2))}. + + square_sum[n, c, d1, ..., dk] = sum(X[n, i, d1, ..., dk] ^ 2), + where max(0, c - floor((size - 1) / 2)) <= i <= min(C - 1, c + ceil((size - 1) / 2)). + + Y[n, c, d1, ..., dk] = X[n, c, d1, ..., dk] / (bias + alpha / size * square_sum[n, c, d1, ..., dk] ) ^ beta + +#### Version + +This version of the operator has been available since version 1 of the default ONNX operator set. + +#### Attributes + +
+
alpha : float (default is 0.0001)
+
Scaling parameter.
+
beta : float (default is 0.75)
+
The exponent.
+
bias : float (default is 1.0)
+
+
size : int (required)
+
The number of channels to sum over
+
+ +#### Inputs + +
+
X : T
+
Input data tensor from the previous operator; dimensions for image case are (N x C x H x W), where N is the batch size, C is the number of channels, and H and W are the height and the width of the data. For non image case, the dimensions are in the form of (N x C x D1 x D2 ... Dn), where N is the batch size. Optionally, if dimension denotation is in effect, the operation expects the input data tensor to arrive with the dimension denotation of [DATA_BATCH, DATA_CHANNEL, DATA_FEATURE, DATA_FEATURE ...].
+
+ +#### Outputs + +
+
Y : T
+
Output tensor, which has the shape and type as input tensor
+
+ +#### Type Constraints + +
+
T : tensor(float16), tensor(float), tensor(double)
+
Constrain input and output types to float tensors.
+
+ +### **LSTM-1** + + Computes an one-layer LSTM. This operator is usually supported via some + custom implementation such as CuDNN. + + Notations: + + `X` - input tensor + + `i` - input gate + + `o` - output gate + + `f` - forget gate + + `c` - cell gate + + `t` - time step (t-1 means previous time step) + + `W[iofc]` - W parameter weight matrix for input, output, forget, and cell gates + + `R[iofc]` - R recurrence weight matrix for input, output, forget, and cell gates + + `Wb[iofc]` - W bias vectors for input, output, forget, and cell gates + + `Rb[iofc]` - R bias vectors for input, output, forget, and cell gates + + `P[iof]` - P peephole weight vector for input, output, and forget gates + + `WB[iofc]` - W parameter weight matrix for backward input, output, forget, and cell gates + + `RB[iofc]` - R recurrence weight matrix for backward input, output, forget, and cell gates + + `WBb[iofc]` - W bias vectors for backward input, output, forget, and cell gates + + `RBb[iofc]` - R bias vectors for backward input, output, forget, and cell gates + + `PB[iof]` - P peephole weight vector for backward input, output, and forget gates + + `H` - Hidden state + + `num_directions` - 2 if direction == bidirectional else 1 + + Activation functions: + + Relu(x) - max(0, x) + + Tanh(x) - (1 - e^{-2x})/(1 + e^{-2x}) + + Sigmoid(x) - 1/(1 + e^{-x}) + + (NOTE: Below are optional) + + Affine(x) - alpha*x + beta + + LeakyRelu(x) - x if x >= 0 else alpha * x + + ThresholdedRelu(x) - x if x >= alpha else 0 + + ScaledTanh(x) - alpha*Tanh(beta*x) + + HardSigmoid(x) - min(max(alpha*x + beta, 0), 1) + + Elu(x) - x if x >= 0 else alpha*(e^x - 1) + + Softsign(x) - x/(1 + |x|) + + Softplus(x) - log(1 + e^x) + + Equations (Default: f=Sigmoid, g=Tanh, h=Tanh): + + - it = f(Xt*(Wi^T) + Ht-1*Ri + Pi (.) Ct-1 + Wbi + Rbi) + + - ft = f(Xt*(Wf^T) + Ht-1*Rf + Pf (.) Ct-1 + Wbf + Rbf) + + - ct = g(Xt*(Wc^T) + Ht-1*Rc + Wbc + Rbc) + + - Ct = ft (.) Ct-1 + it (.) ct + + - ot = f(Xt*(Wo^T) + Ht-1*Ro + Po (.) Ct + Wbo + Rbo) + + - Ht = ot (.) h(Ct) + +#### Version + +This version of the operator has been available since version 1 of the default ONNX operator set. + +#### Attributes + +
+
activation_alpha : list of floats
+
Optional scaling values used by some activation functions. The values are consumed in the order of activation functions, for example (f, g, h) in LSTM. Default values are the same as of corresponding ONNX operators.For example with LeakyRelu, the default alpha is 0.01.
+
activation_beta : list of floats
+
Optional scaling values used by some activation functions. The values are consumed in the order of activation functions, for example (f, g, h) in LSTM. Default values are the same as of corresponding ONNX operators.
+
activations : list of strings
+
A list of 3 (or 6 if bidirectional) activation functions for input, output, forget, cell, and hidden. The activation functions must be one of the activation functions specified above. Optional: See the equations for default if not specified.
+
clip : float
+
Cell clip threshold. Clipping bounds the elements of a tensor in the range of [-threshold, +threshold] and is applied to the input of activations. No clip if not specified.
+
direction : string (default is forward)
+
Specify if the RNN is forward, reverse, or bidirectional. Must be one of forward (default), reverse, or bidirectional.
+
hidden_size : int
+
Number of neurons in the hidden layer
+
input_forget : int (default is 0)
+
Couple the input and forget gates if 1, default 0.
+
output_sequence : int (default is 0)
+
The sequence output for the hidden is optional if 0. Default 0.
+
+ +#### Inputs (3 - 8) + +
+
X : T
+
The input sequences packed (and potentially padded) into one 3-D tensor with the shape of `[seq_length, batch_size, input_size]`.
+
W : T
+
The weight tensor for the gates. Concatenation of `W[iofc]` and `WB[iofc]` (if bidirectional) along dimension 0. The tensor has shape `[num_directions, 4*hidden_size, input_size]`.
+
R : T
+
The recurrence weight tensor. Concatenation of `R[iofc]` and `RB[iofc]` (if bidirectional) along dimension 0. This tensor has shape `[num_directions, 4*hidden_size, hidden_size]`.
+
B (optional) : T
+
The bias tensor for input gate. Concatenation of `[Wb[iofc], Rb[iofc]]`, and `[WBb[iofc], RBb[iofc]]` (if bidirectional) along dimension 0. This tensor has shape `[num_directions, 8*hidden_size]`. Optional: If not specified - assumed to be 0.
+
sequence_lens (optional) : T1
+
Optional tensor specifying lengths of the sequences in a batch. If not specified - assumed all sequences in the batch to have length `seq_length`. It has shape `[batch_size]`.
+
initial_h (optional) : T
+
Optional initial value of the hidden. If not specified - assumed to be 0. It has shape `[num_directions, batch_size, hidden_size]`.
+
initial_c (optional) : T
+
Optional initial value of the cell. If not specified - assumed to be 0. It has shape `[num_directions, batch_size, hidden_size]`.
+
P (optional) : T
+
The weight tensor for peepholes. Concatenation of `P[iof]` and `PB[iof]` (if bidirectional) along dimension 0. It has shape `[num_directions, 3*hidde_size]`. Optional: If not specified - assumed to be 0.
+
+ +#### Outputs (0 - 3) + +
+
Y (optional) : T
+
A tensor that concats all the intermediate output values of the hidden. It has shape `[seq_length, num_directions, batch_size, hidden_size]`. It is optional if `output_sequence` is 0.
+
Y_h (optional) : T
+
The last output value of the hidden. It has shape `[num_directions, batch_size, hidden_size]`.
+
Y_c (optional) : T
+
The last output value of the cell. It has shape `[num_directions, batch_size, hidden_size]`.
+
+ +#### Type Constraints + +
+
T : tensor(float16), tensor(float), tensor(double)
+
Constrain input and output types to float tensors.
+
T1 : tensor(int32)
+
Constrain seq_lens to integer tensor.
+
+ +### **LeakyRelu-1** + + LeakyRelu takes input data (Tensor) and an argument alpha, and produces one + output data (Tensor) where the function `f(x) = alpha * x for x < 0`, + `f(x) = x for x >= 0`, is applied to the data tensor elementwise. + +#### Version + +This version of the operator has been available since version 1 of the default ONNX operator set. + +#### Attributes + +
+
alpha : float (default is 0.01)
+
Coefficient of leakage default to 0.01.
+
consumed_inputs : list of ints
+
legacy optimization attribute.
+
+ +#### Inputs + +
+
X : T
+
Input tensor
+
+ +#### Outputs + +
+
Y : T
+
Output tensor
+
+ +#### Type Constraints + +
+
T : tensor(float16), tensor(float), tensor(double)
+
Constrain input and output types to float tensors.
+
+ +### **Less-1** + + Returns the tensor resulted from performing the `less` logical operation + elementwise on the input tensors `A` and `B`. + + If broadcasting is enabled, the right-hand-side argument will be broadcasted + to match the shape of left-hand-side argument. See the doc of `Add` for a + detailed description of the broadcasting rules. + +#### Version + +This version of the operator has been available since version 1 of the default ONNX operator set. + +#### Attributes + +
+
axis : int
+
If set, defines the broadcast dimensions.
+
broadcast : int (default is 0)
+
Enable broadcasting
+
+ +#### Inputs + +
+
A : T
+
Left input tensor for the logical operator.
+
B : T
+
Right input tensor for the logical operator.
+
+ +#### Outputs + +
+
C : T1
+
Result tensor.
+
+ +#### Type Constraints + +
+
T : tensor(float16), tensor(float), tensor(double)
+
Constrains input to float tensors.
+
T1 : tensor(bool)
+
Constrains output to boolean tensor.
+
+ +### **Log-1** + + Calculates the natural log of the given input tensor, element-wise. + +#### Version + +This version of the operator has been available since version 1 of the default ONNX operator set. + +#### Attributes + +
+
consumed_inputs : list of ints
+
legacy optimization attribute.
+
+ +#### Inputs + +
+
input : T
+
Input tensor
+
+ +#### Outputs + +
+
output : T
+
The natural log of the input tensor computed element-wise
+
+ +#### Type Constraints + +
+
T : tensor(float16), tensor(float), tensor(double)
+
Constrain input and output types to float tensors.
+
+ +### **LogSoftmax-1** + + The operator computes the logsoftmax (log of softmax) values for each layer in the batch + of the given input. The input is a 2-D tensor (Tensor) of size + (batch_size x input_feature_dimensions). The output tensor has the same shape + and contains the logsoftmax values of the corresponding input. + + Input does not need to explicitly be a 2D vector; rather, it will be + coerced into one. For an arbitrary n-dimensional tensor + input \in [a_0, a_1, ..., a_{k-1}, a_k, ..., a_{n-1}] and k is + the axis provided, then input will be coerced into a 2-dimensional tensor with + dimensions [a_0 * ... * a_{k-1}, a_k * ... * a_{n-1}]. For the default + case where axis=1, this means the input tensor will be coerced into a 2D tensor + of dimensions [a_0, a_1 * ... * a_{n-1}], where a_0 is often the batch size. + In this situation, we must have a_0 = N and a_1 * ... * a_{n-1} = D. + Each of these dimensions must be matched correctly, or else the operator + will throw errors. + +#### Version + +This version of the operator has been available since version 1 of the default ONNX operator set. + +#### Attributes + +
+
axis : int (default is 1)
+
Describes the axis of the inputs when coerced to 2D; defaults to one because the 0th axis most likely describes the batch_size
+
+ +#### Inputs + +
+
input : T
+
The input tensor that's coerced into a 2D matrix of size (NxD) as described above.
+
+ +#### Outputs + +
+
output : T
+
The output values with the same shape as input tensor (the original size without coercion).
+
+ +#### Type Constraints + +
+
T : tensor(float16), tensor(float), tensor(double)
+
Constrain input and output types to float tensors.
+
+ +### **Loop-1** + + Generic Looping construct. This loop has multiple termination conditions: + + 1) Trip count. Iteration count specified at runtime. Set by + specifying the input M. Optional. Set to empty string to omit. + Note that a static trip count (specified at graph construction time) can be + specified by passing in a constant node for input M. + 2) Loop termination condition. This is an input to the op that determines + whether to run the first iteration and also a loop-carried dependency for + the body graph. The body graph must yield a value for the condition variable, + whether this input is provided or not. + + This table summarizes the operating modes of this operator with equivalent + C-style code: + + Operator inputs defined as (max_trip_count, condition_var). + + input ("", ""): + for (int i=0; ; ++i) { + cond = ... // Note this value is ignored, but is required in the body + } + + input ("", cond) // Note this is analogous to a while loop + bool cond = ...; + for (int i=0; cond; ++i) { + cond = ...; + } + + input ("", 1) // Note this is analogous to a do-while loop + bool cond = true + for (int i=0; cond; ++i) { + cond = ...; + } + + input (trip_count, "") // Note this is analogous to a for loop + int trip_count = ... + for (int i=0; i < trip_count; ++i) { + cond = ...; // ignored + } + + input (trip_count, cond) + int trip_count = ...; + bool cond = ...; + for (int i=0; i < trip_count && cond; ++i) { + cond = ...; + } + + + *Sample usage - cond as well as trip count* + + graph predict-net { + %a = Constant[value = ]() + %b = Constant[value = ]() + %keepgoing = Constant[value = ]() + %max_trip_count = Constant[value = ]() + %keepgoing_out, %b_out, %user_defined_vals = Loop[body = ](%max_trip_count, %keepgoing, %b) + return + } + + graph body-net ( + %i[INT32, scalar] + %keepgoing[BOOL, scalar] + %b[INT32, scalar] + ) { + %my_local = Add(%a, %b) + %b_out = Sub(%a, %b) + %keepgoing_out = Greater(%my_local, %b_out) + %user_defined_vals = Add(%b, %b) + return %keepgoing_out, %b_out, %user_defined_vals + } + + *Sample equivalent C code* + + { + /* User-defined code (enclosing scope) */ + int a = 3, b = 6; + bool keepgoing = true; // Analogous to input cond + /* End user-defined code */ + + /* Implicitly-defined code */ + const int max_trip_count = 10; // Analogous to input M + int user_defined_vals[]; // Imagine this is resizable + /* End implicitly-defined code */ + for (int i=0; i < max_trip_count && keepgoing; ++i) { + /* User-defined code (loop body) */ + int my_local = a + b; // Reading values in the enclosing scope is fine + b = a - b; // writes fine if we specify b as a loop-carried dependency + keepgoing = my_local > b; // keepgoing is a loop-carried dependency + user_defined_vals[i] = b + b; + /* End user-defined code */ + } + // my_local = 123; // Can't do this. my_local was defined in the the body + + // These below values are live-out from the loop and therefore accessible + b_out; user_defined_vals; keepgoing_out; + } + + There are several things of note in this code snippet: + + 1) Values from the enclosing scope (i.e. variable a here) are in scope and can + be referenced in the inputs of the loop. + 2) Any variables which you wish to make available in the enclosing scope (i.e. + the variables b and keepgoing) must be declared as either loop-carried + dependencies (both at the op inputs and output and at the body net input and + output) or scan_outputs. + 3) Values created in the body cannot be accessed in the enclosing scope. + + Note that the semantics of this op support "diagonal" or "wavefront" execution. + (See Step 3 here for an example: + https://devblogs.nvidia.com/optimizing-recurrent-neural-networks-cudnn-5/). + Frontends should emit multi-layer RNNs as a series of While operators (with + time being the inner looping dimension), with each successive layer consuming + the scan_outputs from the previous layer, possibly going through several + point-wise operators (e.g. dropout, residual connections, linear layer). + +#### Version + +This version of the operator has been available since version 1 of the default ONNX operator set. + +#### Attributes + +
+
body : graph (required)
+
The graph run each iteration. It has 2+N inputs: (iteration_num, condition, loop carried dependencies...). It has 1+N+K outputs: (condition, loop carried dependencies..., scan_outputs...). Each scan_output is created by concatenating the value of the specified output value at the end of each iteration of the loop. It is an error if the dimensions or data type of these scan_outputs change across loop iterations.
+
+ +#### Inputs (3 - ∞) + +
+
M (optional) : I
+
A maximum trip-count for the loop specified at runtime. Optional. Pass empty string to skip.
+
cond (optional) : B
+
A boolean termination condition. Optional. Pass empty string to skip.
+
v_initial (variadic, heterogeneous) : V
+
The initial values of any loop-carried dependencies (values that change across loop iterations)
+
+ +#### Outputs (1 - ∞) + +
+
v_final_and_scan_outputs (variadic, heterogeneous) : V
+
Final N loop carried dependency values then K scan_outputs
+
+ +#### Type Constraints + +
+
V : tensor(uint8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(int8), tensor(int16), tensor(int32), tensor(int64), tensor(float16), tensor(float), tensor(double), tensor(string), tensor(bool), tensor(complex64), tensor(complex128)
+
All Tensor types
+
I : tensor(int64)
+
tensor of int64, which should be a scalar.
+
B : tensor(bool)
+
tensor of bool, which should be a scalar.
+
+ +### **LpNormalization-1** + + Given a matrix, apply Lp-normalization along the provided axis. + +#### Version + +This version of the operator has been available since version 1 of the default ONNX operator set. + +#### Attributes + +
+
axis : int (default is -1)
+
The axis on which to apply normalization, -1 mean last axis.
+
p : int (default is 2)
+
The order of the normalization, only 1 or 2 are supported.
+
+ +#### Inputs + +
+
input (differentiable) : T
+
Input matrix
+
+ +#### Outputs + +
+
output (differentiable) : T
+
Matrix after normalization
+
+ +#### Type Constraints + +
+
T : tensor(float16), tensor(float), tensor(double)
+
Constrain input and output types to float tensors.
+
+ +### **LpPool-1** + + LpPool consumes an input tensor X and applies Lp pooling across the + the tensor according to kernel sizes, stride sizes, and pad lengths. + Lp pooling consisting of computing the Lp norm on all values of a subset + of the input tensor according to the kernel size and downsampling the + data into the output tensor Y for further processing. + +#### Version + +This version of the operator has been available since version 1 of the default ONNX operator set. + +#### Attributes + +
+
auto_pad : string (default is NOTSET)
+
auto_pad must be either NOTSET, SAME_UPPER, SAME_LOWER or VALID. Where default value is NOTSET, which means explicit padding is used. SAME_UPPER or SAME_LOWER mean pad the input so that the output size match the input.In case of odd number add the extra padding at the end for SAME_UPPER and at the beginning for SAME_LOWER. VALID mean no padding. DEPRECATION NOTE: auto_pad is only intended to support legacy uses, and for framework authors, one is explicitly encouraged to use explicit padding specified in the pads attribute.
+
kernel_shape : list of ints
+
The size of the kernel along each axis.
+
p : float (default is 2.0)
+
p value of the Lp norm used to pool over the input data, default is 2.0.
+
pads : list of ints
+
Padding for the beginning and ending along each axis, it can take any value greater than or equal to 0. The value represent the number of pixels added to the beginning and end part of the corresponding axis. `pads` format should be as follow [x1_begin, x2_begin...x1_end, x2_end,...], where xi_begin the number of pixels added at the beginning of axis `i` and xi_end, the number of pixels added at the end of axis `i`. This attribute cannot be used simultaneously with auto_pad attribute.
+
strides : list of ints
+
Stride along each axis.
+
+ +#### Inputs + +
+
X : T
+
Input data tensor from the previous operator; dimensions for image case are (N x C x H x W), where N is the batch size, C is the number of channels, and H and W are the height and the width of the data. For non image case, the dimension are in the form of (N x C x D1 x D2 ... Dn), where N is the batch size.
+
+ +#### Outputs + +
+
Y : T
+
Output data tensor from Lp pooling across the input tensor. Dimensions will vary based on various kernel, stride, and pad sizes.
+
+ +#### Type Constraints + +
+
T : tensor(float16), tensor(float), tensor(double)
+
Constrain input and output types to float tensors.
+
+ +### **MatMul-1** + + Matrix product that behaves like numpy.matmul: https://docs.scipy.org/doc/numpy-1.13.0/reference/generated/numpy.matmul.html + +#### Version + +This version of the operator has been available since version 1 of the default ONNX operator set. + +#### Inputs + +
+
A : T
+
N-dimensional matrix A
+
B : T
+
N-dimensional matrix B
+
+ +#### Outputs + +
+
Y : T
+
Matrix multiply results from A * B
+
+ +#### Type Constraints + +
+
T : tensor(float16), tensor(float), tensor(double)
+
Constrain input and output types to float tensors.
+
+ +### **Max-1** + + Element-wise max of each of the input tensors. All inputs and outputs must + have the same shape and data type. + +#### Version + +This version of the operator has been available since version 1 of the default ONNX operator set. + +#### Attributes + +
+
consumed_inputs : list of ints
+
legacy optimization attribute.
+
+ +#### Inputs (1 - ∞) + +
+
data_0 (variadic) : T
+
List of tensors for Max.
+
+ +#### Outputs + +
+
max : T
+
Output tensor. Same dimension as inputs.
+
+ +#### Type Constraints + +
+
T : tensor(float16), tensor(float), tensor(double)
+
Constrain input and output types to float tensors.
+
+ +### **MaxPool-1** + + MaxPool consumes an input tensor X and applies max pooling across + the tensor according to kernel sizes, stride sizes, and pad lengths. + max pooling consisting of computing the max on all values of a + subset of the input tensor according to the kernel size and downsampling the + data into the output tensor Y for further processing. The output spatial shape will be following: + ``` + output_spatial_shape[i] = floor((input_spatial_shape[i] + pad_shape[i] - kernel_spatial_shape[i]) / strides_spatial_shape[i] + 1) + + * pad_shape[i] is sum of pads along axis i + ``` + + `auto_pad` is a DEPRECATED attribute. If you are using them currently, the output spatial shape will be following: + ``` + VALID: output_spatial_shape[i] = ceil((input_spatial_shape[i] - kernel_spatial_shape[i] + 1) / strides_spatial_shape[i]) + SAME_UPPER or SAME_LOWER: output_spatial_shape[i] = ceil(input_spatial_shape[i] / strides_spatial_shape[i]) + ``` + And pad shape will be following if `SAME_UPPER` or `SAME_LOWER`: + ``` + pad_shape[i] = (output_spatial_shape[i] - 1) * strides_spatial_shape[i] + kernel_spatial_shape[i] - input_spatial_shape[i] + ``` + The output of each pooling window is maximum number of elements exclude pad. + + +#### Version + +This version of the operator has been available since version 1 of the default ONNX operator set. + +#### Attributes + +
+
auto_pad : string (default is NOTSET)
+
auto_pad must be either NOTSET, SAME_UPPER, SAME_LOWER or VALID. Where default value is NOTSET, which means explicit padding is used. SAME_UPPER or SAME_LOWER mean pad the input so that the output spatial size match the input.In case of odd number add the extra padding at the end for SAME_UPPER and at the beginning for SAME_LOWER. VALID mean no padding.
+
kernel_shape : list of ints (required)
+
The size of the kernel along each axis.
+
pads : list of ints
+
Padding for the beginning and ending along each spatial axis, it can take any value greater than or equal to 0. The value represent the number of pixels added to the beginning and end part of the corresponding axis. `pads` format should be as follow [x1_begin, x2_begin...x1_end, x2_end,...], where xi_begin the number of pixels added at the beginning of axis `i` and xi_end, the number of pixels added at the end of axis `i`. This attribute cannot be used simultaneously with auto_pad attribute. If not present, the padding defaults to 0 along start and end of each spatial axis.
+
strides : list of ints
+
Stride along each spatial axis.
+
+ +#### Inputs + +
+
X : T
+
Input data tensor from the previous operator; dimensions for image case are (N x C x H x W), where N is the batch size, C is the number of channels, and H and W are the height and the width of the data. For non image case, the dimensions are in the form of (N x C x D1 x D2 ... Dn), where N is the batch size. Optionally, if dimension denotation is in effect, the operation expects the input data tensor to arrive with the dimension denotation of [DATA_BATCH, DATA_CHANNEL, DATA_FEATURE, DATA_FEATURE ...].
+
+ +#### Outputs + +
+
Y : T
+
Output data tensor from average or max pooling across the input tensor. Dimensions will vary based on various kernel, stride, and pad sizes. Floor value of the dimension is used
+
+ +#### Type Constraints + +
+
T : tensor(float16), tensor(float), tensor(double)
+
Constrain input and output types to float tensors.
+
+ +### **MaxRoiPool-1** + + ROI max pool consumes an input tensor X and region of interests (RoIs) to + apply max pooling across each RoI, to produce output 4-D tensor of shape + (num_rois, channels, pooled_shape[0], pooled_shape[1]). + +#### Version + +This version of the operator has been available since version 1 of the default ONNX operator set. + +#### Attributes + +
+
pooled_shape : list of ints (required)
+
ROI pool output shape (height, width).
+
spatial_scale : float (default is 1.0)
+
Multiplicative spatial scale factor to translate ROI coordinates from their input scale to the scale used when pooling.
+
+ +#### Inputs + +
+
X (differentiable) : T
+
Input data tensor from the previous operator; dimensions for image case are (N x C x H x W), where N is the batch size, C is the number of channels, and H and W are the height and the width of the data.
+
rois (non-differentiable) : T
+
RoIs (Regions of Interest) to pool over. Should be a 2-D tensor of shape (num_rois, 5) given as [[batch_id, x1, y1, x2, y2], ...].
+
+ +#### Outputs + +
+
Y (differentiable) : T
+
RoI pooled output 4-D tensor of shape (num_rois, channels, pooled_shape[0], pooled_shape[1]).
+
+ +#### Type Constraints + +
+
T : tensor(float16), tensor(float), tensor(double)
+
Constrain input and output types to float tensors.
+
+ +### **Mean-1** + + Element-wise mean of each of the input tensors. All inputs and outputs must + have the same shape and data type. + +#### Version + +This version of the operator has been available since version 1 of the default ONNX operator set. + +#### Attributes + +
+
consumed_inputs : list of ints
+
legacy optimization attribute.
+
+ +#### Inputs (1 - ∞) + +
+
data_0 (variadic) : T
+
List of tensors for Mean.
+
+ +#### Outputs + +
+
mean : T
+
Output tensor. Same dimension as inputs.
+
+ +#### Type Constraints + +
+
T : tensor(float16), tensor(float), tensor(double)
+
Constrain input and output types to float tensors.
+
+ +### **Min-1** + + Element-wise min of each of the input tensors. All inputs and outputs must + have the same shape and data type. + +#### Version + +This version of the operator has been available since version 1 of the default ONNX operator set. + +#### Attributes + +
+
consumed_inputs : list of ints
+
legacy optimization attribute.
+
+ +#### Inputs (1 - ∞) + +
+
data_0 (variadic) : T
+
List of tensors for Min
+
+ +#### Outputs + +
+
min : T
+
Output tensor. Same dimension as inputs.
+
+ +#### Type Constraints + +
+
T : tensor(float16), tensor(float), tensor(double)
+
Constrain input and output types to float tensors.
+
+ +### **Mul-1** + + Performs element-wise binary multiplication (with limited broadcast support). + + If necessary the right-hand-side argument will be broadcasted to match the + shape of left-hand-side argument. When broadcasting is specified, the second + tensor can either be of element size 1 (including a scalar tensor and any + tensor with rank equal to or smaller than the first tensor), or having its + shape as a contiguous subset of the first tensor's shape. The starting of the + mutually equal shape is specified by the argument "axis", and if it is not set, + suffix matching is assumed. 1-dim expansion doesn't work yet. + + For example, the following tensor shapes are supported (with broadcast=1): + + shape(A) = (2, 3, 4, 5), shape(B) = (,), i.e. B is a scalar tensor + shape(A) = (2, 3, 4, 5), shape(B) = (1, 1), i.e. B is an 1-element tensor + shape(A) = (2, 3, 4, 5), shape(B) = (5,) + shape(A) = (2, 3, 4, 5), shape(B) = (4, 5) + shape(A) = (2, 3, 4, 5), shape(B) = (3, 4), with axis=1 + shape(A) = (2, 3, 4, 5), shape(B) = (2), with axis=0 + + Attribute `broadcast=1` needs to be passed to enable broadcasting. + +#### Version + +This version of the operator has been available since version 1 of the default ONNX operator set. + +#### Attributes + +
+
axis : int
+
If set, defines the broadcast dimensions. See doc for details.
+
broadcast : int (default is 0)
+
Pass 1 to enable broadcasting
+
consumed_inputs : list of ints
+
legacy optimization attribute.
+
+ +#### Inputs + +
+
A : T
+
First operand, should share the type with the second operand.
+
B : T
+
Second operand. With broadcasting can be of smaller size than A. If broadcasting is disabled it should be of the same size.
+
+ +#### Outputs + +
+
C : T
+
Result, has same dimensions and type as A
+
+ +#### Type Constraints + +
+
T : tensor(float16), tensor(float), tensor(double)
+
Constrain input and output types to float tensors.
+
+ +### **Neg-1** + + Neg takes one input data (Tensor) and produces one output data + (Tensor) where each element flipped sign, y = -x, is applied to + the tensor elementwise. + +#### Version + +This version of the operator has been available since version 1 of the default ONNX operator set. + +#### Attributes + +
+
consumed_inputs : list of ints
+
legacy optimization attribute.
+
+ +#### Inputs + +
+
X : T
+
Input tensor
+
+ +#### Outputs + +
+
Y : T
+
Output tensor
+
+ +#### Type Constraints + +
+
T : tensor(float16), tensor(float), tensor(double)
+
Constrain input and output types to float tensors.
+
+ +### **Not-1** + + Returns the negation of the input tensor element-wise. + +#### Version + +This version of the operator has been available since version 1 of the default ONNX operator set. + +#### Inputs + +
+
X (non-differentiable) : T
+
Input tensor
+
+ +#### Outputs + +
+
Y (non-differentiable) : T
+
Output tensor
+
+ +#### Type Constraints + +
+
T : tensor(bool)
+
Constrains input/output to boolean tensors.
+
+ +### **Or-1** + + Returns the tensor resulted from performing the `or` logical operation + elementwise on the input tensors `A` and `B`. + + If broadcasting is enabled, the right-hand-side argument will be broadcasted + to match the shape of left-hand-side argument. See the doc of `Add` for a + detailed description of the broadcasting rules. + +#### Version + +This version of the operator has been available since version 1 of the default ONNX operator set. + +#### Attributes + +
+
axis : int
+
If set, defines the broadcast dimensions.
+
broadcast : int (default is 0)
+
Enable broadcasting
+
+ +#### Inputs + +
+
A : T
+
Left input tensor for the logical operator.
+
B : T
+
Right input tensor for the logical operator.
+
+ +#### Outputs + +
+
C : T1
+
Result tensor.
+
+ +#### Type Constraints + +
+
T : tensor(bool)
+
Constrains input to boolean tensor.
+
T1 : tensor(bool)
+
Constrains output to boolean tensor.
+
+ +### **PRelu-1** + + PRelu takes input data (Tensor) and slope tensor as input, and produces one + output data (Tensor) where the function `f(x) = slope * x for x < 0`, + `f(x) = x for x >= 0`., is applied to the data tensor elementwise. + + +#### Version + +This version of the operator has been available since version 1 of the default ONNX operator set. + +#### Attributes + +
+
consumed_inputs : list of ints
+
legacy optimization attribute.
+
+ +#### Inputs + +
+
X : T
+
Input tensor
+
slope : T
+
Slope tensor. If `Slope` is of size 1, the value is sharedacross different channels
+
+ +#### Outputs + +
+
Y : T
+
Output tensor
+
+ +#### Type Constraints + +
+
T : tensor(float16), tensor(float), tensor(double)
+
Constrain input and output types to float tensors.
+
+ +### **Pad-1** + + Given `data` tensor, paddings, mode, and value. + Example: + Insert 0 paddings to the beginning of the second dimension. + data = [ + [1.0, 1.2], + [2.3, 3.4], + [4.5, 5.7], + ] + paddings = [0, 0, 2, 0] + output = [ + [ + [0.0, 0.0, 1.0, 1.2], + [0.0, 0.0, 2.3, 3.4], + [0.0, 0.0, 4.5, 5.7], + ], + ] + +#### Version + +This version of the operator has been available since version 1 of the default ONNX operator set. + +#### Attributes + +
+
mode : string (default is constant)
+
Three modes: constant(default), reflect, edge
+
paddings : list of ints (required)
+
List of integers indicate the padding element count at the beginning and end of each axis, for 2D it is the number of pixel. `paddings` rank should be double of the input's rank. `paddings` format should be as follow [x1_begin, x2_begin...x1_end, x2_end,...], where xi_begin the number of pixels added at the beginning of axis `i` and xi_end, the number of pixels added at the end of axis `i`.
+
value : float (default is 0.0)
+
One float, indicates the value to be filled, default is 0
+
+ +#### Inputs + +
+
data : T
+
Input tensor.
+
+ +#### Outputs + +
+
output : T
+
Tensor after padding.
+
+ +#### Type Constraints + +
+
T : tensor(float16), tensor(float), tensor(double)
+
Constrain input and output types to float tensors.
+
+ +### **Pow-1** + + Pow takes input data (Tensor) and exponent Tensor, and + produces one output data (Tensor) where the function `f(x) = x^exponent`, + is applied to the data tensor elementwise. + + If necessary the right-hand-side argument will be broadcasted to match the + shape of left-hand-side argument. When broadcasting is specified, the second + tensor can either be of element size 1 (including a scalar tensor and any + tensor with rank equal to or smaller than the first tensor), or having its + shape as a contiguous subset of the first tensor's shape. The starting of the + mutually equal shape is specified by the argument "axis", and if it is not set, + suffix matching is assumed. 1-dim expansion doesn't work yet. + + For example, the following tensor shapes are supported (with broadcast=1): + + shape(A) = (2, 3, 4, 5), shape(B) = (,), i.e. B is a scalar tensor + shape(A) = (2, 3, 4, 5), shape(B) = (1, 1), i.e. B is an 1-element tensor + shape(A) = (2, 3, 4, 5), shape(B) = (5,) + shape(A) = (2, 3, 4, 5), shape(B) = (4, 5) + shape(A) = (2, 3, 4, 5), shape(B) = (3, 4), with axis=1 + shape(A) = (2, 3, 4, 5), shape(B) = (2), with axis=0 + + Attribute `broadcast=1` needs to be passed to enable broadcasting. + +#### Version + +This version of the operator has been available since version 1 of the default ONNX operator set. + +#### Attributes + +
+
axis : int
+
If set, defines the broadcast dimensions. See doc for details.
+
broadcast : int (default is 0)
+
Pass 1 to enable broadcasting
+
+ +#### Inputs + +
+
X : T
+
Input tensor of any shape, base of the exponent.
+
Y : T
+
Input tensor of any shape broadcastable to X shape, the exponent component.
+
+ +#### Outputs + +
+
Z : T
+
Output tensor (same size as X)
+
+ +#### Type Constraints + +
+
T : tensor(float16), tensor(float), tensor(double)
+
Constrain input and output types to float tensors.
+
+ +### **RNN-1** + + Computes an one-layer simple RNN. This operator is usually supported + via some custom implementation such as CuDNN. + + Notations: + + `X` - input tensor + + `i` - input gate + + `t` - time step (t-1 means previous time step) + + `Wi` - W parameter weight matrix for input gate + + `Ri` - R recurrence weight matrix for input gate + + `Wbi` - W parameter bias vector for input gate + + `Rbi` - R parameter bias vector for input gate + + `WBi` - W parameter weight matrix for backward input gate + + `RBi` - R recurrence weight matrix for backward input gate + + `WBbi` - WR bias vectors for backward input gate + + `RBbi` - RR bias vectors for backward input gate + + `H` - Hidden state + + `num_directions` - 2 if direction == bidirectional else 1 + + Activation functions: + + Relu(x) - max(0, x) + + Tanh(x) - (1 - e^{-2x})/(1 + e^{-2x}) + + Sigmoid(x) - 1/(1 + e^{-x}) + + (NOTE: Below are optional) + + Affine(x) - alpha*x + beta + + LeakyRelu(x) - x if x >= 0 else alpha * x + + ThresholdedRelu(x) - x if x >= alpha else 0 + + ScaledTanh(x) - alpha*Tanh(beta*x) + + HardSigmoid(x) - min(max(alpha*x + beta, 0), 1) + + Elu(x) - x if x >= 0 else alpha*(e^x - 1) + + Softsign(x) - x/(1 + |x|) + + Softplus(x) - log(1 + e^x) + + Equations (Default: f=Tanh): + + - Ht = f(Xt*(Wi^T) + Ht-1*Ri + Wbi + Rbi) + +#### Version + +This version of the operator has been available since version 1 of the default ONNX operator set. + +#### Attributes + +
+
activation_alpha : list of floats
+
Optional scaling values used by some activation functions. The values are consumed in the order of activation functions, for example (f, g, h) in LSTM. Default values are the same as of corresponding ONNX operators.For example with LeakyRelu, the default alpha is 0.01.
+
activation_beta : list of floats
+
Optional scaling values used by some activation functions. The values are consumed in the order of activation functions, for example (f, g, h) in LSTM. Default values are the same as of corresponding ONNX operators.
+
activations : list of strings (default is ['Tanh', 'Tanh'])
+
One (or two if bidirectional) activation function for input gate. The activation function must be one of the activation functions specified above. Optional: Default `Tanh` if not specified.
+
clip : float
+
Cell clip threshold. Clipping bounds the elements of a tensor in the range of [-threshold, +threshold] and is applied to the input of activations. No clip if not specified.
+
direction : string (default is forward)
+
Specify if the RNN is forward, reverse, or bidirectional. Must be one of forward (default), reverse, or bidirectional.
+
hidden_size : int
+
Number of neurons in the hidden layer
+
output_sequence : int (default is 0)
+
The sequence output for the hidden is optional if 0. Default 0.
+
+ +#### Inputs (3 - 6) + +
+
X : T
+
The input sequences packed (and potentially padded) into one 3-D tensor with the shape of `[seq_length, batch_size, input_size]`.
+
W : T
+
The weight tensor for input gate. Concatenation of `Wi` and `WBi` (if bidirectional). The tensor has shape `[num_directions, hidden_size, input_size]`.
+
R : T
+
The recurrence weight tensor. Concatenation of `Ri` and `RBi` (if bidirectional). The tensor has shape `[num_directions, hidden_size, hidden_size]`.
+
B (optional) : T
+
The bias tensor for input gate. Concatenation of `[Wbi, Rbi]` and `[WBbi, RBbi]` (if bidirectional). The tensor has shape `[num_directions, 2*hidden_size]`. Optional: If not specified - assumed to be 0.
+
sequence_lens (optional) : T1
+
Optional tensor specifying lengths of the sequences in a batch. If not specified - assumed all sequences in the batch to have length `seq_length`. It has shape `[batch_size]`.
+
initial_h (optional) : T
+
Optional initial value of the hidden. If not specified - assumed to be 0. It has shape `[num_directions, batch_size, hidden_size]`.
+
+ +#### Outputs (0 - 2) + +
+
Y (optional) : T
+
A tensor that concats all the intermediate output values of the hidden. It has shape `[seq_length, num_directions, batch_size, hidden_size]`. It is optional if `output_sequence` is 0.
+
Y_h (optional) : T
+
The last output value of the hidden. It has shape `[num_directions, batch_size, hidden_size]`.
+
+ +#### Type Constraints + +
+
T : tensor(float16), tensor(float), tensor(double)
+
Constrain input and output types to float tensors.
+
T1 : tensor(int32)
+
Constrain seq_lens to integer tensor.
+
+ +### **RandomNormal-1** + + Generate a tensor with random values drawn from a normal distribution. The shape + of the tensor is specified by the `shape` argument and the parameter of the normal distribution + specified by `mean` and `scale`. + + The data type is specified by the 'dtype' argument. The 'dtype' argument must + be one of the data types specified in the 'DataType' enum field in the + TensorProto message. + +#### Version + +This version of the operator has been available since version 1 of the default ONNX operator set. + +#### Attributes + +
+
dtype : int (default is 1)
+
The data type for the elements of the output tensor. Default is TensorProto::FLOAT.
+
mean : float (default is 0.0)
+
The mean of the normal distribution.
+
scale : float (default is 1.0)
+
The standard deviation of the normal distribution.
+
seed : float
+
(Optional) Seed to the random generator, if not specified we will auto generate one.
+
shape : list of ints (required)
+
The shape of the output tensor.
+
+ +#### Inputs + + +#### Outputs + +
+
output : T
+
Output tensor of random values drawn from normal distribution
+
+ +#### Type Constraints + +
+
T : tensor(float16), tensor(float), tensor(double)
+
Constrain output types to float tensors.
+
+ +### **RandomNormalLike-1** + + Generate a tensor with random values drawn from a normal distribution. + The shape of the output tensor is copied from the shape of the input tensor, + and the parameters of the normal distribution are specified by `mean` and `scale`. + + The data type is specified by the 'dtype' argument, or copied from the input tensor if not provided. + The 'dtype' argument must be one of the data types specified in the 'DataType' enum field in the + TensorProto message, and be valid as an output type. + +#### Version + +This version of the operator has been available since version 1 of the default ONNX operator set. + +#### Attributes + +
+
dtype : int
+
(Optional) The data type for the elements of the output tensor, if not specified, we will use the data type of the input tensor.
+
mean : float (default is 0.0)
+
The mean of the normal distribution.
+
scale : float (default is 1.0)
+
The standard deviation of the normal distribution.
+
seed : float
+
(Optional) Seed to the random generator, if not specified we will auto generate one.
+
+ +#### Inputs + +
+
input : T1
+
Input tensor to copy shape and optionally type information from.
+
+ +#### Outputs + +
+
output : T2
+
Output tensor of random values drawn from normal distribution
+
+ +#### Type Constraints + +
+
T1 : tensor(uint8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(int8), tensor(int16), tensor(int32), tensor(int64), tensor(float16), tensor(float), tensor(double), tensor(string), tensor(bool), tensor(complex64), tensor(complex128)
+
Constrain to any tensor type. If the dtype attribute is not provided this must be a valid output type.
+
T2 : tensor(float16), tensor(float), tensor(double)
+
Constrain output types to float tensors.
+
+ +### **RandomUniform-1** + + Generate a tensor with random values drawn from a uniform distribution. The shape + of the tensor is specified by the `shape` argument and the range by `low` and `high`. + + The data type is specified by the 'dtype' argument. The 'dtype' argument must + be one of the data types specified in the 'DataType' enum field in the + TensorProto message. + +#### Version + +This version of the operator has been available since version 1 of the default ONNX operator set. + +#### Attributes + +
+
dtype : int (default is 1)
+
The data type for the elements of the output tensor. If not specified, default is TensorProto::FLOAT.
+
high : float (default is 1.0)
+
Upper boundary of the output values.
+
low : float (default is 0.0)
+
Lower boundary of the output values.
+
seed : float
+
(Optional) Seed to the random generator, if not specified we will auto generate one.
+
shape : list of ints (required)
+
The shape of the output tensor.
+
+ +#### Inputs + + +#### Outputs + +
+
output : T
+
Output tensor of random values drawn from uniform distribution
+
+ +#### Type Constraints + +
+
T : tensor(float16), tensor(float), tensor(double)
+
Constrain output types to float tensors.
+
+ +### **RandomUniformLike-1** + + Generate a tensor with random values drawn from a uniform distribution. + The shape of the output tensor is copied from the shape of the input tensor, + and the parameters of the uniform distribution are specified by `low` and `high`. + + The data type is specified by the 'dtype' argument, or copied from the input tensor if not provided. + The 'dtype' argument must be one of the data types specified in the 'DataType' enum field in the + TensorProto message and be valid as an output type. + +#### Version + +This version of the operator has been available since version 1 of the default ONNX operator set. + +#### Attributes + +
+
dtype : int
+
(Optional) The data type for the elements of the output tensor, if not specified, we will use the data type of the input tensor.
+
high : float (default is 1.0)
+
Upper boundary of the output values.
+
low : float (default is 0.0)
+
Lower boundary of the output values.
+
seed : float
+
(Optional) Seed to the random generator, if not specified we will auto generate one.
+
+ +#### Inputs + +
+
input : T1
+
Input tensor to copy shape and optionally type information from.
+
+ +#### Outputs + +
+
output : T2
+
Output tensor of random values drawn from uniform distribution
+
+ +#### Type Constraints + +
+
T1 : tensor(uint8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(int8), tensor(int16), tensor(int32), tensor(int64), tensor(float16), tensor(float), tensor(double), tensor(string), tensor(bool), tensor(complex64), tensor(complex128)
+
Constrain to any tensor type. If the dtype attribute is not provided this must be a valid output type.
+
T2 : tensor(float16), tensor(float), tensor(double)
+
Constrain output types to float tensors.
+
+ +### **Reciprocal-1** + + Reciprocal takes one input data (Tensor) and produces one output data + (Tensor) where the reciprocal is, y = 1/x, is applied to + the tensor elementwise. + +#### Version + +This version of the operator has been available since version 1 of the default ONNX operator set. + +#### Attributes + +
+
consumed_inputs : list of ints
+
legacy optimization attribute.
+
+ +#### Inputs + +
+
X : T
+
Input tensor
+
+ +#### Outputs + +
+
Y : T
+
Output tensor
+
+ +#### Type Constraints + +
+
T : tensor(float16), tensor(float), tensor(double)
+
Constrain input and output types to float tensors.
+
+ +### **ReduceL1-1** + + Computes the L1 norm of the input tensor's element along the provided axes. The resulted + tensor has the same rank as the input if keepdims equal 1. If keepdims equal 0, then + the resulted tensor have the reduced dimension pruned. + + The above behavior is similar to numpy, with the exception that numpy default keepdims to + False instead of True. + +#### Version + +This version of the operator has been available since version 1 of the default ONNX operator set. + +#### Attributes + +
+
axes : list of ints
+
A list of integers, along which to reduce. The default is to reduce over all the dimensions of the input tensor.
+
keepdims : int (default is 1)
+
Keep the reduced dimension or not, default 1 mean keep reduced dimension.
+
+ +#### Inputs + +
+
data : T
+
An input tensor.
+
+ +#### Outputs + +
+
reduced : T
+
Reduced output tensor.
+
+ +#### Type Constraints + +
+
T : tensor(uint32), tensor(uint64), tensor(int32), tensor(int64), tensor(float16), tensor(float), tensor(double)
+
Constrain input and output types to high-precision numeric tensors.
+
+ +### **ReduceL2-1** + + Computes the L2 norm of the input tensor's element along the provided axes. The resulted + tensor has the same rank as the input if keepdims equal 1. If keepdims equal 0, then + the resulted tensor have the reduced dimension pruned. + + The above behavior is similar to numpy, with the exception that numpy default keepdims to + False instead of True. + +#### Version + +This version of the operator has been available since version 1 of the default ONNX operator set. + +#### Attributes + +
+
axes : list of ints
+
A list of integers, along which to reduce. The default is to reduce over all the dimensions of the input tensor.
+
keepdims : int (default is 1)
+
Keep the reduced dimension or not, default 1 mean keep reduced dimension.
+
+ +#### Inputs + +
+
data : T
+
An input tensor.
+
+ +#### Outputs + +
+
reduced : T
+
Reduced output tensor.
+
+ +#### Type Constraints + +
+
T : tensor(uint32), tensor(uint64), tensor(int32), tensor(int64), tensor(float16), tensor(float), tensor(double)
+
Constrain input and output types to high-precision numeric tensors.
+
+ +### **ReduceLogSum-1** + + Computes the log sum of the input tensor's element along the provided axes. The resulted + tensor has the same rank as the input if keepdims equal 1. If keepdims equal 0, then + the resulted tensor have the reduced dimension pruned. + + The above behavior is similar to numpy, with the exception that numpy default keepdims to + False instead of True. + +#### Version + +This version of the operator has been available since version 1 of the default ONNX operator set. + +#### Attributes + +
+
axes : list of ints
+
A list of integers, along which to reduce. The default is to reduce over all the dimensions of the input tensor.
+
keepdims : int (default is 1)
+
Keep the reduced dimension or not, default 1 mean keep reduced dimension.
+
+ +#### Inputs + +
+
data : T
+
An input tensor.
+
+ +#### Outputs + +
+
reduced : T
+
Reduced output tensor.
+
+ +#### Type Constraints + +
+
T : tensor(uint32), tensor(uint64), tensor(int32), tensor(int64), tensor(float16), tensor(float), tensor(double)
+
Constrain input and output types to high-precision numeric tensors.
+
+ +### **ReduceLogSumExp-1** + + Computes the log sum exponent of the input tensor's element along the provided axes. The resulted + tensor has the same rank as the input if keepdims equal 1. If keepdims equal 0, then + the resulted tensor have the reduced dimension pruned. + + The above behavior is similar to numpy, with the exception that numpy default keepdims to + False instead of True. + +#### Version + +This version of the operator has been available since version 1 of the default ONNX operator set. + +#### Attributes + +
+
axes : list of ints
+
A list of integers, along which to reduce. The default is to reduce over all the dimensions of the input tensor.
+
keepdims : int (default is 1)
+
Keep the reduced dimension or not, default 1 mean keep reduced dimension.
+
+ +#### Inputs + +
+
data : T
+
An input tensor.
+
+ +#### Outputs + +
+
reduced : T
+
Reduced output tensor.
+
+ +#### Type Constraints + +
+
T : tensor(uint32), tensor(uint64), tensor(int32), tensor(int64), tensor(float16), tensor(float), tensor(double)
+
Constrain input and output types to high-precision numeric tensors.
+
+ +### **ReduceMax-1** + + Computes the max of the input tensor's element along the provided axes. The resulted + tensor has the same rank as the input if keepdims equal 1. If keepdims equal 0, then + the resulted tensor have the reduced dimension pruned. + + The above behavior is similar to numpy, with the exception that numpy default keepdims to + False instead of True. + +#### Version + +This version of the operator has been available since version 1 of the default ONNX operator set. + +#### Attributes + +
+
axes : list of ints
+
A list of integers, along which to reduce. The default is to reduce over all the dimensions of the input tensor.
+
keepdims : int (default is 1)
+
Keep the reduced dimension or not, default 1 mean keep reduced dimension.
+
+ +#### Inputs + +
+
data : T
+
An input tensor.
+
+ +#### Outputs + +
+
reduced : T
+
Reduced output tensor.
+
+ +#### Type Constraints + +
+
T : tensor(uint32), tensor(uint64), tensor(int32), tensor(int64), tensor(float16), tensor(float), tensor(double)
+
Constrain input and output types to high-precision numeric tensors.
+
+ +### **ReduceMean-1** + + Computes the mean of the input tensor's element along the provided axes. The resulted + tensor has the same rank as the input if keepdims equal 1. If keepdims equal 0, then + the resulted tensor have the reduced dimension pruned. + + The above behavior is similar to numpy, with the exception that numpy default keepdims to + False instead of True. + +#### Version + +This version of the operator has been available since version 1 of the default ONNX operator set. + +#### Attributes + +
+
axes : list of ints
+
A list of integers, along which to reduce. The default is to reduce over all the dimensions of the input tensor.
+
keepdims : int (default is 1)
+
Keep the reduced dimension or not, default 1 mean keep reduced dimension.
+
+ +#### Inputs + +
+
data : T
+
An input tensor.
+
+ +#### Outputs + +
+
reduced : T
+
Reduced output tensor.
+
+ +#### Type Constraints + +
+
T : tensor(uint32), tensor(uint64), tensor(int32), tensor(int64), tensor(float16), tensor(float), tensor(double)
+
Constrain input and output types to high-precision numeric tensors.
+
+ +### **ReduceMin-1** + + Computes the min of the input tensor's element along the provided axes. The resulted + tensor has the same rank as the input if keepdims equal 1. If keepdims equal 0, then + the resulted tensor have the reduced dimension pruned. + + The above behavior is similar to numpy, with the exception that numpy default keepdims to + False instead of True. + +#### Version + +This version of the operator has been available since version 1 of the default ONNX operator set. + +#### Attributes + +
+
axes : list of ints
+
A list of integers, along which to reduce. The default is to reduce over all the dimensions of the input tensor.
+
keepdims : int (default is 1)
+
Keep the reduced dimension or not, default 1 mean keep reduced dimension.
+
+ +#### Inputs + +
+
data : T
+
An input tensor.
+
+ +#### Outputs + +
+
reduced : T
+
Reduced output tensor.
+
+ +#### Type Constraints + +
+
T : tensor(uint32), tensor(uint64), tensor(int32), tensor(int64), tensor(float16), tensor(float), tensor(double)
+
Constrain input and output types to high-precision numeric tensors.
+
+ +### **ReduceProd-1** + + Computes the product of the input tensor's element along the provided axes. The resulted + tensor has the same rank as the input if keepdims equal 1. If keepdims equal 0, then + the resulted tensor have the reduced dimension pruned. + + The above behavior is similar to numpy, with the exception that numpy default keepdims to + False instead of True. + +#### Version + +This version of the operator has been available since version 1 of the default ONNX operator set. + +#### Attributes + +
+
axes : list of ints
+
A list of integers, along which to reduce. The default is to reduce over all the dimensions of the input tensor.
+
keepdims : int (default is 1)
+
Keep the reduced dimension or not, default 1 mean keep reduced dimension.
+
+ +#### Inputs + +
+
data : T
+
An input tensor.
+
+ +#### Outputs + +
+
reduced : T
+
Reduced output tensor.
+
+ +#### Type Constraints + +
+
T : tensor(uint32), tensor(uint64), tensor(int32), tensor(int64), tensor(float16), tensor(float), tensor(double)
+
Constrain input and output types to high-precision numeric tensors.
+
+ +### **ReduceSum-1** + + Computes the sum of the input tensor's element along the provided axes. The resulted + tensor has the same rank as the input if keepdims equal 1. If keepdims equal 0, then + the resulted tensor have the reduced dimension pruned. + + The above behavior is similar to numpy, with the exception that numpy default keepdims to + False instead of True. + +#### Version + +This version of the operator has been available since version 1 of the default ONNX operator set. + +#### Attributes + +
+
axes : list of ints
+
A list of integers, along which to reduce. The default is to reduce over all the dimensions of the input tensor.
+
keepdims : int (default is 1)
+
Keep the reduced dimension or not, default 1 mean keep reduced dimension.
+
+ +#### Inputs + +
+
data : T
+
An input tensor.
+
+ +#### Outputs + +
+
reduced : T
+
Reduced output tensor.
+
+ +#### Type Constraints + +
+
T : tensor(uint32), tensor(uint64), tensor(int32), tensor(int64), tensor(float16), tensor(float), tensor(double)
+
Constrain input and output types to high-precision numeric tensors.
+
+ +### **ReduceSumSquare-1** + + Computes the sum square of the input tensor's element along the provided axes. The resulted + tensor has the same rank as the input if keepdims equal 1. If keepdims equal 0, then + the resulted tensor have the reduced dimension pruned. + + The above behavior is similar to numpy, with the exception that numpy default keepdims to + False instead of True. + +#### Version + +This version of the operator has been available since version 1 of the default ONNX operator set. + +#### Attributes + +
+
axes : list of ints
+
A list of integers, along which to reduce. The default is to reduce over all the dimensions of the input tensor.
+
keepdims : int (default is 1)
+
Keep the reduced dimension or not, default 1 mean keep reduced dimension.
+
+ +#### Inputs + +
+
data : T
+
An input tensor.
+
+ +#### Outputs + +
+
reduced : T
+
Reduced output tensor.
+
+ +#### Type Constraints + +
+
T : tensor(uint32), tensor(uint64), tensor(int32), tensor(int64), tensor(float16), tensor(float), tensor(double)
+
Constrain input and output types to high-precision numeric tensors.
+
+ +### **Relu-1** + + Relu takes one input data (Tensor) and produces one output data + (Tensor) where the rectified linear function, y = max(0, x), is applied to + the tensor elementwise. + +#### Version + +This version of the operator has been available since version 1 of the default ONNX operator set. + +#### Attributes + +
+
consumed_inputs : list of ints
+
legacy optimization attribute.
+
+ +#### Inputs + +
+
X : T
+
Input tensor
+
+ +#### Outputs + +
+
Y : T
+
Output tensor
+
+ +#### Type Constraints + +
+
T : tensor(float16), tensor(float), tensor(double)
+
Constrain input and output types to float tensors.
+
+ +### **Reshape-1** + + Reshape the input tensor similar to numpy.reshape. + It takes a tensor as input and an argument `shape`. It outputs the reshaped tensor. + At most one dimension of the new shape can be -1. In this case, the value is + inferred from the size of the tensor and the remaining dimensions. A dimension + could also be 0, in which case the actual dimension value is unchanged (i.e. taken + from the input tensor). + +#### Version + +This version of the operator has been available since version 1 of the default ONNX operator set. + +#### Attributes + +
+
consumed_inputs : list of ints
+
legacy optimization attribute.
+
shape : list of ints
+
New shape
+
+ +#### Inputs + +
+
data : T
+
An input tensor.
+
+ +#### Outputs + +
+
reshaped : T
+
Reshaped data.
+
+ +#### Type Constraints + +
+
T : tensor(float16), tensor(float), tensor(double)
+
Constrain input and output types to float tensors.
+
+ +### **Selu-1** + + Selu takes one input data (Tensor) and produces one output data + (Tensor) where the scaled exponential linear unit function, + `y = gamma * (alpha * e^x - alpha) for x <= 0`, `y = gamma * x for x > 0`, + is applied to the tensor elementwise. + +#### Version + +This version of the operator has been available since version 1 of the default ONNX operator set. + +#### Attributes + +
+
alpha : float (default is 1.6732)
+
Coefficient of SELU default to 1.6732.
+
consumed_inputs : list of ints
+
legacy optimization attribute.
+
gamma : float (default is 1.0507)
+
Coefficient of SELU default to 1.0507.
+
+ +#### Inputs + +
+
X : T
+
Input tensor
+
+ +#### Outputs + +
+
Y : T
+
Output tensor
+
+ +#### Type Constraints + +
+
T : tensor(float16), tensor(float), tensor(double)
+
Constrain input and output types to float tensors.
+
+ +### **Shape-1** + + Takes a tensor as input and outputs an 1D int64 tensor containing the shape of the input tensor. + +#### Version + +This version of the operator has been available since version 1 of the default ONNX operator set. + +#### Inputs + +
+
data : T
+
An input tensor.
+
+ +#### Outputs + +
+
shape : T1
+
Shape of the input tensor
+
+ +#### Type Constraints + +
+
T : tensor(uint8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(int8), tensor(int16), tensor(int32), tensor(int64), tensor(float16), tensor(float), tensor(double), tensor(string), tensor(bool), tensor(complex64), tensor(complex128)
+
Input tensor can be of arbitrary type.
+
T1 : tensor(int64)
+
Constrain output to int64 tensor.
+
+ +### **Sigmoid-1** + + Sigmoid takes one input data (Tensor) and produces one output data + (Tensor) where the sigmoid function, y = 1 / (1 + exp(-x)), is applied to the + tensor elementwise. + +#### Version + +This version of the operator has been available since version 1 of the default ONNX operator set. + +#### Attributes + +
+
consumed_inputs : list of ints
+
legacy optimization attribute.
+
+ +#### Inputs + +
+
X : T
+
Input tensor
+
+ +#### Outputs + +
+
Y : T
+
Output tensor
+
+ +#### Type Constraints + +
+
T : tensor(float16), tensor(float), tensor(double)
+
Constrain input and output types to float tensors.
+
+ +### **Size-1** + + Takes a tensor as input and outputs a int64 scalar that equals to the total number of elements of the input tensor. + +#### Version + +This version of the operator has been available since version 1 of the default ONNX operator set. + +#### Inputs + +
+
data : T
+
An input tensor.
+
+ +#### Outputs + +
+
size : T1
+
Total number of elements of the input tensor
+
+ +#### Type Constraints + +
+
T : tensor(uint8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(int8), tensor(int16), tensor(int32), tensor(int64), tensor(float16), tensor(float), tensor(double), tensor(string), tensor(bool), tensor(complex64), tensor(complex128)
+
Input tensor can be of arbitrary type.
+
T1 : tensor(int64)
+
Constrain output to int64 tensor, which should be a scalar though.
+
+ +### **Slice-1** + + Produces a slice of the input tensor along multiple axes. Similar to numpy: + https://docs.scipy.org/doc/numpy/reference/arrays.indexing.html + Slices uses `axes`, `starts` and `ends` attributes to specify the start and end + dimension for each axis in the list of axes, it uses this information to + slice the input `data` tensor. If a negative value is passed for any of the + start or end indices, it represent number of elements before the end of that + dimension. If the value passed to start or end is larger than the `n` (the + number of elements in this dimension), it represents `n`. For slicing to the + end of a dimension with unknown size, it is recommended to pass in `INT_MAX`. + If `axes` are omitted, they are set to `[0, ..., ndim-1]`. + Example 1: + data = [ + [1, 2, 3, 4], + [5, 6, 7, 8], + ] + axes = [0, 1] + starts = [1, 0] + ends = [2, 3] + result = [ + [5, 6, 7], + ] + Example 2: + data = [ + [1, 2, 3, 4], + [5, 6, 7, 8], + ] + starts = [0, 1] + ends = [-1, 1000] + result = [ + [2, 3, 4], + ] + +#### Version + +This version of the operator has been available since version 1 of the default ONNX operator set. + +#### Attributes + +
+
axes : list of ints
+
Axes that `starts` and `ends` apply to. It's optional. If not present, will be treated as [0, 1, ..., len(`starts`) - 1].
+
ends : list of ints (required)
+
Ending indices (exclusive) of corresponding axis in axes`
+
starts : list of ints (required)
+
Starting indices of corresponding axis in `axes`
+
+ +#### Inputs + +
+
data : T
+
Tensor of data to extract slices from.
+
+ +#### Outputs + +
+
output : T
+
Sliced data tensor.
+
+ +#### Type Constraints + +
+
T : tensor(uint8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(int8), tensor(int16), tensor(int32), tensor(int64), tensor(float16), tensor(float), tensor(double), tensor(string), tensor(bool), tensor(complex64), tensor(complex128)
+
Constrain input and output types to all tensor types.
+
+ +### **Softmax-1** + + The operator computes the softmax (normalized exponential) values for each layer in the batch + of the given input. The input is a 2-D tensor (Tensor) of size + (batch_size x input_feature_dimensions). The output tensor has the same shape + and contains the softmax values of the corresponding input. + + Input does not need to explicitly be a 2D vector; rather, it will be + coerced into one. For an arbitrary n-dimensional tensor + input \in [a_0, a_1, ..., a_{k-1}, a_k, ..., a_{n-1}] and k is + the axis provided, then input will be coerced into a 2-dimensional tensor with + dimensions [a_0 * ... * a_{k-1}, a_k * ... * a_{n-1}]. For the default + case where axis=1, this means the input tensor will be coerced into a 2D tensor + of dimensions [a_0, a_1 * ... * a_{n-1}], where a_0 is often the batch size. + In this situation, we must have a_0 = N and a_1 * ... * a_{n-1} = D. + Each of these dimensions must be matched correctly, or else the operator + will throw errors. + +#### Version + +This version of the operator has been available since version 1 of the default ONNX operator set. + +#### Attributes + +
+
axis : int (default is 1)
+
Describes the axis of the inputs when coerced to 2D; defaults to one because the 0th axis most likely describes the batch_size
+
+ +#### Inputs + +
+
input : T
+
The input tensor that's coerced into a 2D matrix of size (NxD) as described above.
+
+ +#### Outputs + +
+
output : T
+
The output values with the same shape as input tensor (the original size without coercion).
+
+ +#### Type Constraints + +
+
T : tensor(float16), tensor(float), tensor(double)
+
Constrain input and output types to float tensors.
+
+ +### **Softplus-1** + + Softplus takes one input data (Tensor) and produces one output data + (Tensor) where the softplus function, y = ln(exp(x) + 1), is applied to + the tensor elementwise. + +#### Version + +This version of the operator has been available since version 1 of the default ONNX operator set. + +#### Inputs + +
+
X (differentiable) : T
+
1D input tensor
+
+ +#### Outputs + +
+
Y (differentiable) : T
+
1D input tensor
+
+ +#### Type Constraints + +
+
T : tensor(float16), tensor(float), tensor(double)
+
Constrain input and output types to float tensors.
+
+ +### **Softsign-1** + + Calculates the softsign (x/(1+|x|)) of the given input tensor element-wise. + +#### Version + +This version of the operator has been available since version 1 of the default ONNX operator set. + +#### Inputs + +
+
input (differentiable) : T
+
Input tensor
+
+ +#### Outputs + +
+
output (differentiable) : T
+
The softsign (x/(1+|x|)) values of the input tensor computed element-wise
+
+ +#### Type Constraints + +
+
T : tensor(float16), tensor(float), tensor(double)
+
Constrain input and output types to float tensors.
+
+ +### **SpaceToDepth-1** + + SpaceToDepth rearranges blocks of spatial data into depth. More specifically, + this op outputs a copy of the input tensor where values from the height and width dimensions + are moved to the depth dimension. + +#### Version + +This version of the operator has been available since version 1 of the default ONNX operator set. + +#### Attributes + +
+
blocksize : int (required)
+
Blocks of [blocksize, blocksize] are moved.
+
+ +#### Inputs + +
+
input : T
+
Input tensor of [N,C,H,W], where N is the batch axis, C is the channel or depth, H is the height and W is the width.
+
+ +#### Outputs + +
+
output : T
+
Output tensor of [N, C * blocksize * blocksize, H/blocksize, W/blocksize].
+
+ +#### Type Constraints + +
+
T : tensor(uint8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(int8), tensor(int16), tensor(int32), tensor(int64), tensor(float16), tensor(float), tensor(double), tensor(string), tensor(bool), tensor(complex64), tensor(complex128)
+
Constrain input and output types to all tensor types.
+
+ +### **Split-1** + + Split a tensor into a list of tensors, along the specified + 'axis'. The lengths of the split can be specified using argument 'axis' or + optional second input blob to the operator. Otherwise, the tensor is split + to equal sized parts. + +#### Version + +This version of the operator has been available since version 1 of the default ONNX operator set. + +#### Attributes + +
+
axis : int
+
Which axis to split on
+
split : list of ints
+
length of each output
+
+ +#### Inputs (1 - 2) + +
+
input : T
+
The tensor to split
+
split (optional) : T
+
Optional list of output lengths (see also arg 'split')
+
+ +#### Outputs (1 - ∞) + +
+
outputs... (variadic) : T
+
One or more outputs forming list of tensors after splitting
+
+ +#### Type Constraints + +
+
T : tensor(float16), tensor(float), tensor(double)
+
Constrain input types to float tensors.
+
+ +### **Sqrt-1** + + Square root takes one input data (Tensor) and produces one output data + (Tensor) where the square root is, y = x^0.5, is applied to + the tensor elementwise. If x is negative, then it will return NaN. + +#### Version + +This version of the operator has been available since version 1 of the default ONNX operator set. + +#### Attributes + +
+
consumed_inputs : list of ints
+
legacy optimization attribute.
+
+ +#### Inputs + +
+
X : T
+
Input tensor
+
+ +#### Outputs + +
+
Y : T
+
Output tensor
+
+ +#### Type Constraints + +
+
T : tensor(float16), tensor(float), tensor(double)
+
Constrain input and output types to float tensors.
+
+ +### **Squeeze-1** + + Remove single-dimensional entries from the shape of a tensor. + Takes a parameter `axes` with a list of axes to squeeze. + If `axes` is not provided, all the single dimensions will be removed from + the shape. If an axis is selected with shape entry not equal to one, an error is raised. + +#### Version + +This version of the operator has been available since version 1 of the default ONNX operator set. + +#### Attributes + +
+
axes : list of ints
+
List of non-negative integers, indicate the dimensions to squeeze.
+
+ +#### Inputs + +
+
data : T
+
Tensors with at least max(dims) dimensions.
+
+ +#### Outputs + +
+
squeezed : T
+
Reshaped tensor with same data as input.
+
+ +#### Type Constraints + +
+
T : tensor(uint8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(int8), tensor(int16), tensor(int32), tensor(int64), tensor(float16), tensor(float), tensor(double), tensor(string), tensor(bool), tensor(complex64), tensor(complex128)
+
Constrain input and output types to all tensor types.
+
+ +### **Sub-1** + + Performs element-wise binary subtraction (with limited broadcast support). + + If necessary the right-hand-side argument will be broadcasted to match the + shape of left-hand-side argument. When broadcasting is specified, the second + tensor can either be of element size 1 (including a scalar tensor and any + tensor with rank equal to or smaller than the first tensor), or having its + shape as a contiguous subset of the first tensor's shape. The starting of the + mutually equal shape is specified by the argument "axis", and if it is not set, + suffix matching is assumed. 1-dim expansion doesn't work yet. + + For example, the following tensor shapes are supported (with broadcast=1): + + shape(A) = (2, 3, 4, 5), shape(B) = (,), i.e. B is a scalar tensor + shape(A) = (2, 3, 4, 5), shape(B) = (1, 1), i.e. B is an 1-element tensor + shape(A) = (2, 3, 4, 5), shape(B) = (5,) + shape(A) = (2, 3, 4, 5), shape(B) = (4, 5) + shape(A) = (2, 3, 4, 5), shape(B) = (3, 4), with axis=1 + shape(A) = (2, 3, 4, 5), shape(B) = (2), with axis=0 + + Attribute `broadcast=1` needs to be passed to enable broadcasting. + +#### Version + +This version of the operator has been available since version 1 of the default ONNX operator set. + +#### Attributes + +
+
axis : int
+
If set, defines the broadcast dimensions. See doc for details.
+
broadcast : int (default is 0)
+
Pass 1 to enable broadcasting
+
consumed_inputs : list of ints
+
legacy optimization attribute.
+
+ +#### Inputs + +
+
A : T
+
First operand, should share the type with the second operand.
+
B : T
+
Second operand. With broadcasting can be of smaller size than A. If broadcasting is disabled it should be of the same size.
+
+ +#### Outputs + +
+
C : T
+
Result, has same dimensions and type as A
+
+ +#### Type Constraints + +
+
T : tensor(float16), tensor(float), tensor(double)
+
Constrain input and output types to float tensors.
+
+ +### **Sum-1** + + Element-wise sum of each of the input tensors. All inputs and outputs must + have the same shape and data type. + +#### Version + +This version of the operator has been available since version 1 of the default ONNX operator set. + +#### Attributes + +
+
consumed_inputs : list of ints
+
legacy optimization attribute.
+
+ +#### Inputs (1 - ∞) + +
+
data_0 (variadic) : T
+
List of tensors for Sum.
+
+ +#### Outputs + +
+
sum : T
+
Output tensor. Same dimension as inputs.
+
+ +#### Type Constraints + +
+
T : tensor(float16), tensor(float), tensor(double)
+
Constrain input and output types to float tensors.
+
+ +### **Tanh-1** + + Calculates the hyperbolic tangent of the given input tensor element-wise. + +#### Version + +This version of the operator has been available since version 1 of the default ONNX operator set. + +#### Attributes + +
+
consumed_inputs : list of ints
+
legacy optimization attribute.
+
+ +#### Inputs + +
+
input : T
+
1-D input tensor
+
+ +#### Outputs + +
+
output : T
+
The hyperbolic tangent values of the input tensor computed element-wise
+
+ +#### Type Constraints + +
+
T : tensor(float16), tensor(float), tensor(double)
+
Constrain input and output types to float tensors.
+
+ +### **Tile-1** + + Repeat the elements of a tensor along an axis. + +#### Version + +This version of the operator has been available since version 1 of the default ONNX operator set. + +#### Inputs + +
+
input : T
+
Input tensor of any shape.
+
tiles : T
+
Number of repeated copies to make of the input tensor.
+
axis : T
+
Axis along which to repeat.
+
+ +#### Outputs + +
+
output : T
+
Output tensor of same shape and type as input.
+
+ +#### Type Constraints + +
+
T : tensor(float16), tensor(float), tensor(double)
+
Constrain input types to float tensors.
+
T1 : tensor(int64)
+
Constrain tiles and axis's type to int64 tensors.
+
+ +### **TopK-1** + + Retrieve the top-K elements along a specified axis. Given an input tensor of + shape [a_1, a_2, ..., a_n, r] and integer argument k, return two outputs: + -Value tensor of shape [a_1, a_2, ..., a_{axis-1}, k, a_{axis+1}, ... a_n] + which contains the values of the top k elements along the specified axis + -Index tensor of shape [a_1, a_2, ..., a_{axis-1}, k, a_{axis+1}, ... a_n] which + contains the indices of the top k elements (original indices from the input + tensor). + Given two equivalent values, this operator uses the indices along the axis as + a tiebreaker. That is, the element with the lower index will appear first. + +#### Version + +This version of the operator has been available since version 1 of the default ONNX operator set. + +#### Attributes + +
+
axis : int (default is -1)
+
Dimension on which to do the sort.
+
k : int (required)
+
Number of top elements to retrieve
+
+ +#### Inputs + +
+
X : T
+
Tensor of shape [a_1, a_2, ..., a_n, r]
+
+ +#### Outputs + +
+
Values : T
+
Tensor of shape [a_1, a_2, ..., a_{axis-1}, k, a_{axis+1}, ... a_n] containing top K values from the input tensor
+
Indices : I
+
Tensor of shape [a_1, a_2, ..., a_{axis-1}, k, a_{axis+1}, ... a_n] containing the corresponding input tensor indices for the top K values.
+
+ +#### Type Constraints + +
+
T : tensor(float16), tensor(float), tensor(double)
+
Constrain input and output types to float tensors.
+
I : tensor(int64)
+
Constrain index tensor to int64
+
+ +### **Transpose-1** + + Transpose the input tensor similar to numpy.transpose. For example, when + perm=(1, 0, 2), given an input tensor of shape (1, 2, 3), the output shape + will be (2, 1, 3). + +#### Version + +This version of the operator has been available since version 1 of the default ONNX operator set. + +#### Attributes + +
+
perm : list of ints
+
A list of integers. By default, reverse the dimensions, otherwise permute the axes according to the values given.
+
+ +#### Inputs + +
+
data : T
+
An input tensor.
+
+ +#### Outputs + +
+
transposed : T
+
Transposed output.
+
+ +#### Type Constraints + +
+
T : tensor(uint8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(int8), tensor(int16), tensor(int32), tensor(int64), tensor(float16), tensor(float), tensor(double), tensor(string), tensor(bool), tensor(complex64), tensor(complex128)
+
Constrain input and output types to all tensor types.
+
+ +### **Unsqueeze-1** + + Insert single-dimensional entries to the shape of a tensor. + Takes one required argument `axes`, a list of dimensions that will be inserted. + Dimension indices in `axes` are as seen in the output tensor. For example: + Given a tensor such that tensor with shape [3, 4, 5], then + Unsqueeze(tensor, axes=[0, 4]) has shape [1, 3, 4, 5, 1] + +#### Version + +This version of the operator has been available since version 1 of the default ONNX operator set. + +#### Attributes + +
+
axes : list of ints (required)
+
List of non-negative integers, indicate the dimensions to be inserted
+
+ +#### Inputs + +
+
data : T
+
Original tensor
+
+ +#### Outputs + +
+
expanded : T
+
Reshaped tensor with same data as input.
+
+ +#### Type Constraints + +
+
T : tensor(uint8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(int8), tensor(int16), tensor(int32), tensor(int64), tensor(float16), tensor(float), tensor(double), tensor(string), tensor(bool), tensor(complex64), tensor(complex128)
+
Constrain input and output types to all tensor types.
+
+ +### **Upsample-1** + + Upsample the input tensor. + The width and height of the output tensor are: + output_width = floor(input_width * width_scale), + output_height = floor(input_height * height_scale). + Example: + Given `data` tensor, width_scale, height_scale, mode, + Upsample the input 4-D tensor in nearest mode: + data = [[[ + [1, 2], + [3, 4] + ]]] + width_scale = 2 + height_scale = 2 + mode = "nearest" + output = [[[ + [1, 1, 2, 2], + [1, 1, 2, 2], + [3, 3, 4, 4], + [3, 3, 4, 4] + ]]] + +#### Version + +No versioning maintained for experimental ops. +#### Attributes + +
+
height_scale : float (required)
+
The scale along height dimension. It takes value greater than or equal to 1.
+
mode : string (default is nearest)
+
Two interpolation modes: nearest(default), bilinear
+
width_scale : float (required)
+
The scale along width dimension. It takes value greater than or equal to 1.
+
+ +#### Inputs + +
+
X : T
+
4-D tensor, [N,C,H,W]
+
+ +#### Outputs + +
+
Y : T
+
4-D tensor after resizing, [N,C,H,W]
+
+ +#### Type Constraints + +
+
T : tensor(bool), tensor(int32), tensor(int64), tensor(float16), tensor(float), tensor(double)
+
Constrain output types to bool, int32, int64, float16, float, double tensors.
+
+ +### **Xor-1** + + Returns the tensor resulted from performing the `xor` logical operation + elementwise on the input tensors `A` and `B`. + + If broadcasting is enabled, the right-hand-side argument will be broadcasted + to match the shape of left-hand-side argument. See the doc of `Add` for a + detailed description of the broadcasting rules. + +#### Version + +This version of the operator has been available since version 1 of the default ONNX operator set. + +#### Attributes + +
+
axis : int
+
If set, defines the broadcast dimensions.
+
broadcast : int (default is 0)
+
Enable broadcasting
+
+ +#### Inputs + +
+
A : T
+
Left input tensor for the logical operator.
+
B : T
+
Right input tensor for the logical operator.
+
+ +#### Outputs + +
+
C : T1
+
Result tensor.
+
+ +#### Type Constraints + +
+
T : tensor(bool)
+
Constrains input to boolean tensor.
+
T1 : tensor(bool)
+
Constrains output to boolean tensor.
+
+ +## Version 2 of the default ONNX operator set +### **GlobalLpPool-2** + + GlobalLpPool consumes an input tensor X and applies lp pool pooling across + the values in the same channel. This is equivalent to LpPool with kernel size + equal to the spatial dimension of input tensor. + +#### Version + +This version of the operator has been available since version 2 of the default ONNX operator set. + +#### Attributes + +
+
p : int (default is 2)
+
p value of the Lp norm used to pool over the input data.
+
+ +#### Inputs + +
+
X (differentiable) : T
+
Input data tensor from the previous operator; dimensions for image case are (N x C x H x W), where N is the batch size, C is the number of channels, and H and W are the height and the width of the data. For non image case, the dimensions are in the form of (N x C x D1 x D2 ... Dn), where N is the batch size.
+
+ +#### Outputs + +
+
Y (differentiable) : T
+
Output data tensor from pooling across the input tensor. The output tensor has the same rank as the input. The first two dimensions of output shape are the same as the input (N x C), while the other dimensions are all 1.
+
+ +#### Type Constraints + +
+
T : tensor(float16), tensor(float), tensor(double)
+
Constrain input and output types to float tensors.
+
+ +### **LpPool-2** + + LpPool consumes an input tensor X and applies Lp pooling across + the tensor according to kernel sizes, stride sizes, and pad lengths. + Lp pooling consisting of computing the Lp norm on all values of a subset + of the input tensor according to the kernel size and downsampling the + data into the output tensor Y for further processing. + +#### Version + +This version of the operator has been available since version 2 of the default ONNX operator set. + +#### Attributes + +
+
auto_pad : string (default is NOTSET)
+
auto_pad must be either NOTSET, SAME_UPPER, SAME_LOWER or VALID. Where default value is NOTSET, which means explicit padding is used. SAME_UPPER or SAME_LOWER mean pad the input so that the output spatial size match the input.In case of odd number add the extra padding at the end for SAME_UPPER and at the beginning for SAME_LOWER. VALID mean no padding.
+
kernel_shape : list of ints (required)
+
The size of the kernel along each axis.
+
p : int (default is 2)
+
p value of the Lp norm used to pool over the input data.
+
pads : list of ints
+
Padding for the beginning and ending along each spatial axis, it can take any value greater than or equal to 0. The value represent the number of pixels added to the beginning and end part of the corresponding axis. `pads` format should be as follow [x1_begin, x2_begin...x1_end, x2_end,...], where xi_begin the number of pixels added at the beginning of axis `i` and xi_end, the number of pixels added at the end of axis `i`. This attribute cannot be used simultaneously with auto_pad attribute. If not present, the padding defaults to 0 along start and end of each spatial axis.
+
strides : list of ints
+
Stride along each spatial axis.
+
+ +#### Inputs + +
+
X : T
+
Input data tensor from the previous operator; dimensions for image case are (N x C x H x W), where N is the batch size, C is the number of channels, and H and W are the height and the width of the data. For non image case, the dimensions are in the form of (N x C x D1 x D2 ... Dn), where N is the batch size.
+
+ +#### Outputs + +
+
Y : T
+
Output data tensor from Lp pooling across the input tensor. Dimensions will vary based on various kernel, stride, and pad sizes.
+
+ +#### Type Constraints + +
+
T : tensor(float16), tensor(float), tensor(double)
+
Constrain input and output types to float tensors.
+
+ +### **Pad-2** + + Given `data` tensor, pads, mode, and value. + Example: + Insert 0 pads to the beginning of the second dimension. + data = [ + [1.0, 1.2], + [2.3, 3.4], + [4.5, 5.7], + ] + pads = [0, 2, 0, 0] + output = [ + [ + [0.0, 0.0, 1.0, 1.2], + [0.0, 0.0, 2.3, 3.4], + [0.0, 0.0, 4.5, 5.7], + ], + ] + +#### Version + +This version of the operator has been available since version 2 of the default ONNX operator set. + +#### Attributes + +
+
mode : string (default is constant)
+
Three modes: constant(default), reflect, edge
+
pads : list of ints (required)
+
List of integers indicating the number of padding elements to add or remove (if negative) at the beginning and end of each axis. For 2D it is the number of pixels. `pads` rank should be double of the input's rank. `pads` format should be as follow [x1_begin, x2_begin...x1_end, x2_end,...], where xi_begin the number of pixels added at the beginning of axis `i` and xi_end, the number of pixels added at the end of axis `i`.
+
value : float (default is 0.0)
+
One float, indicates the value to be filled.
+
+ +#### Inputs + +
+
data : T
+
Input tensor.
+
+ +#### Outputs + +
+
output : T
+
Tensor after padding.
+
+ +#### Type Constraints + +
+
T : tensor(float16), tensor(float), tensor(double)
+
Constrain input and output types to float tensors.
+
+ +### **Split-2** + + Split a tensor into a list of tensors, along the specified + 'axis'. Lengths of the parts can be specified using argument 'split'. + Otherwise, the tensor is split to equal sized parts. + +#### Version + +This version of the operator has been available since version 2 of the default ONNX operator set. + +#### Attributes + +
+
axis : int (default is 0)
+
Which axis to split on.
+
split : list of ints
+
length of each output
+
+ +#### Inputs + +
+
input : T
+
The tensor to split
+
+ +#### Outputs (1 - ∞) + +
+
outputs (variadic) : T
+
One or more outputs forming list of tensors after splitting
+
+ +#### Type Constraints + +
+
T : tensor(uint8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(int8), tensor(int16), tensor(int32), tensor(int64), tensor(float16), tensor(float), tensor(double), tensor(string), tensor(bool), tensor(complex64), tensor(complex128)
+
Constrain input and output types to all tensor types.
+
+ +## Version 3 of the default ONNX operator set +### **GRU-3** + + Computes an one-layer GRU. This operator is usually supported via some custom + implementation such as CuDNN. + + Notations: + + `X` - input tensor + + `z` - update gate + + `r` - reset gate + + `h` - hidden gate + + `t` - time step (t-1 means previous time step) + + `W[zrh]` - W parameter weight matrix for update, reset, and hidden gates + + `R[zrh]` - R recurrence weight matrix for update, reset, and hidden gates + + `Wb[zrh]` - W bias vectors for update, reset, and hidden gates + + `Rb[zrh]` - R bias vectors for update, reset, and hidden gates + + `WB[zrh]` - W parameter weight matrix for backward update, reset, and hidden gates + + `RB[zrh]` - R recurrence weight matrix for backward update, reset, and hidden gates + + `WBb[zrh]` - W bias vectors for backward update, reset, and hidden gates + + `RBb[zrh]` - R bias vectors for backward update, reset, and hidden gates + + `H` - Hidden state + + `num_directions` - 2 if direction == bidirectional else 1 + + Activation functions: + + Relu(x) - max(0, x) + + Tanh(x) - (1 - e^{-2x})/(1 + e^{-2x}) + + Sigmoid(x) - 1/(1 + e^{-x}) + + (NOTE: Below are optional) + + Affine(x) - alpha*x + beta + + LeakyRelu(x) - x if x >= 0 else alpha * x + + ThresholdedRelu(x) - x if x >= alpha else 0 + + ScaledTanh(x) - alpha*Tanh(beta*x) + + HardSigmoid(x) - min(max(alpha*x + beta, 0), 1) + + Elu(x) - x if x >= 0 else alpha*(e^x - 1) + + Softsign(x) - x/(1 + |x|) + + Softplus(x) - log(1 + e^x) + + Equations (Default: f=Sigmoid, g=Tanh): + + - zt = f(Xt*(Wz^T) + Ht-1*Rz + Wbz + Rbz) + + - rt = f(Xt*(Wr^T) + Ht-1*Rr + Wbr + Rbr) + + - ht = g(Xt*(Wh^T) + (rt (.) Ht-1)*Rh + Rbh + Wbh) # default, when linear_before_reset = 0 + + - ht = g(Xt*(Wh^T) + (rt (.) (Ht-1*Rh + Rbh) + Wbh) # when linear_before_reset != 0 + + - Ht = (1 - zt) (.) ht + zt (.) Ht-1 + +#### Version + +This version of the operator has been available since version 3 of the default ONNX operator set. + +#### Attributes + +
+
activation_alpha : list of floats
+
Optional scaling values used by some activation functions. The values are consumed in the order of activation functions, for example (f, g, h) in LSTM. Default values are the same as of corresponding ONNX operators.For example with LeakyRelu, the default alpha is 0.01.
+
activation_beta : list of floats
+
Optional scaling values used by some activation functions. The values are consumed in the order of activation functions, for example (f, g, h) in LSTM. Default values are the same as of corresponding ONNX operators.
+
activations : list of strings
+
A list of 2 (or 4 if bidirectional) activation functions for update, reset, and hidden gates. The activation functions must be one of the activation functions specified above. Optional: See the equations for default if not specified.
+
clip : float
+
Cell clip threshold. Clipping bounds the elements of a tensor in the range of [-threshold, +threshold] and is applied to the input of activations. No clip if not specified.
+
direction : string (default is forward)
+
Specify if the RNN is forward, reverse, or bidirectional. Must be one of forward (default), reverse, or bidirectional.
+
hidden_size : int
+
Number of neurons in the hidden layer
+
linear_before_reset : int (default is 0)
+
When computing the output of the hidden gate, apply the linear transformation before multiplying by the output of the reset gate.
+
output_sequence : int (default is 0)
+
The sequence output for the hidden is optional if 0. Default 0.
+
+ +#### Inputs (3 - 6) + +
+
X : T
+
The input sequences packed (and potentially padded) into one 3-D tensor with the shape of `[seq_length, batch_size, input_size]`.
+
W : T
+
The weight tensor for the gates. Concatenation of `W[zrh]` and `WB[zrh]` (if bidirectional) along dimension 0. This tensor has shape `[num_directions, 3*hidden_size, input_size]`.
+
R : T
+
The recurrence weight tensor. Concatenation of `R[zrh]` and `RB[zrh]` (if bidirectional) along dimension 0. This tensor has shape `[num_directions, 3*hidden_size, hidden_size]`.
+
B (optional) : T
+
The bias tensor for the gates. Concatenation of `[Wb[zrh], Rb[zrh]]` and `[WBb[zrh], RBb[zrh]]` (if bidirectional) along dimension 0. This tensor has shape `[num_directions, 6*hidden_size]`. Optional: If not specified - assumed to be 0
+
sequence_lens (optional) : T1
+
Optional tensor specifying lengths of the sequences in a batch. If not specified - assumed all sequences in the batch to have length `seq_length`. It has shape `[batch_size]`.
+
initial_h (optional) : T
+
Optional initial value of the hidden. If not specified - assumed to be 0. It has shape `[num_directions, batch_size, hidden_size]`.
+
+ +#### Outputs (0 - 2) + +
+
Y (optional) : T
+
A tensor that concats all the intermediate output values of the hidden. It has shape `[seq_length, num_directions, batch_size, hidden_size]`. It is optional if `output_sequence` is 0.
+
Y_h (optional) : T
+
The last output value of the hidden. It has shape `[num_directions, batch_size, hidden_size]`.
+
+ +#### Type Constraints + +
+
T : tensor(float16), tensor(float), tensor(double)
+
Constrain input and output types to float tensors.
+
T1 : tensor(int32)
+
Constrain seq_lens to integer tensor.
+
+ +## Version 4 of the default ONNX operator set +### **Concat-4** + + Concatenate a list of tensors into a single tensor + +#### Version + +This version of the operator has been available since version 4 of the default ONNX operator set. + +#### Attributes + +
+
axis : int (required)
+
Which axis to concat on
+
+ +#### Inputs (1 - ∞) + +
+
inputs (variadic) : T
+
List of tensors for concatenation
+
+ +#### Outputs + +
+
concat_result : T
+
Concatenated tensor
+
+ +#### Type Constraints + +
+
T : tensor(uint8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(int8), tensor(int16), tensor(int32), tensor(int64), tensor(float16), tensor(float), tensor(double), tensor(string), tensor(bool), tensor(complex64), tensor(complex128)
+
Constrain output types to any tensor type.
+
+ +## Version 5 of the default ONNX operator set +### **Reshape-5** + + Reshape the input tensor similar to numpy.reshape. + First input is the data tensor, second input is a shape tensor which specifies the output shape. It outputs the reshaped tensor. + At most one dimension of the new shape can be -1. In this case, the value is + inferred from the size of the tensor and the remaining dimensions. A dimension + could also be 0, in which case the actual dimension value is unchanged (i.e. taken + from the input tensor). + +#### Version + +This version of the operator has been available since version 5 of the default ONNX operator set. + +#### Inputs + +
+
data : T
+
An input tensor.
+
shape : tensor(int64)
+
Specified shape for output.
+
+ +#### Outputs + +
+
reshaped : T
+
Reshaped data.
+
+ +#### Type Constraints + +
+
T : tensor(uint8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(int8), tensor(int16), tensor(int32), tensor(int64), tensor(float16), tensor(float), tensor(double), tensor(string), tensor(bool), tensor(complex64), tensor(complex128)
+
Constrain input and output types to all tensor types.
+
+ +## Version 6 of the default ONNX operator set +### **Abs-6** + + Absolute takes one input data (Tensor) and produces one output data + (Tensor) where the absolute is, y = abs(x), is applied to + the tensor elementwise. + +#### Version + +This version of the operator has been available since version 6 of the default ONNX operator set. + +#### Inputs + +
+
X : T
+
Input tensor
+
+ +#### Outputs + +
+
Y : T
+
Output tensor
+
+ +#### Type Constraints + +
+
T : tensor(uint8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(int8), tensor(int16), tensor(int32), tensor(int64), tensor(float16), tensor(float), tensor(double)
+
Constrain input and output types to all numeric tensors.
+
+ +### **Add-6** + + Performs element-wise binary addition (with limited broadcast support). + + If necessary the right-hand-side argument will be broadcasted to match the + shape of left-hand-side argument. When broadcasting is specified, the second + tensor can either be of element size 1 (including a scalar tensor and any + tensor with rank equal to or smaller than the first tensor), or having its + shape as a contiguous subset of the first tensor's shape. The starting of the + mutually equal shape is specified by the argument "axis", and if it is not set, + suffix matching is assumed. 1-dim expansion doesn't work yet. + + For example, the following tensor shapes are supported (with broadcast=1): + + shape(A) = (2, 3, 4, 5), shape(B) = (,), i.e. B is a scalar tensor + shape(A) = (2, 3, 4, 5), shape(B) = (1, 1), i.e. B is an 1-element tensor + shape(A) = (2, 3, 4, 5), shape(B) = (5,) + shape(A) = (2, 3, 4, 5), shape(B) = (4, 5) + shape(A) = (2, 3, 4, 5), shape(B) = (3, 4), with axis=1 + shape(A) = (2, 3, 4, 5), shape(B) = (2), with axis=0 + + Attribute `broadcast=1` needs to be passed to enable broadcasting. + +#### Version + +This version of the operator has been available since version 6 of the default ONNX operator set. + +#### Attributes + +
+
axis : int
+
If set, defines the broadcast dimensions. See doc for details.
+
broadcast : int (default is 0)
+
Pass 1 to enable broadcasting
+
+ +#### Inputs + +
+
A : T
+
First operand, should share the type with the second operand.
+
B : T
+
Second operand. With broadcasting can be of smaller size than A. If broadcasting is disabled it should be of the same size.
+
+ +#### Outputs + +
+
C : T
+
Result, has same dimensions and type as A
+
+ +#### Type Constraints + +
+
T : tensor(uint32), tensor(uint64), tensor(int32), tensor(int64), tensor(float16), tensor(float), tensor(double)
+
Constrain input and output types to high-precision numeric tensors.
+
+ +### **BatchNormalization-6** + + Carries out batch normalization as described in the paper + https://arxiv.org/abs/1502.03167. Depending on the mode it is being run, + there are multiple cases for the number of outputs, which we list below: + + Output case #1: Y, mean, var, saved_mean, saved_var (training mode) + Output case #2: Y (test mode) + +#### Version + +This version of the operator has been available since version 6 of the default ONNX operator set. + +#### Attributes + +
+
epsilon : float (default is 1e-05)
+
The epsilon value to use to avoid division by zero, default is 1e-5f.
+
is_test : int (default is 0)
+
If set to nonzero, run spatial batch normalization in test mode, default is 0.
+
momentum : float (default is 0.9)
+
Factor used in computing the running mean and variance.e.g., running_mean = running_mean * momentum + mean * (1 - momentum), default is 0.9f.
+
spatial : int (default is 1)
+
If true, compute the mean and variance across all spatial elements If false, compute the mean and variance across per feature.Default is 1.
+
+ +#### Inputs + +
+
X : T
+
Input data tensor from the previous operator; dimensions for image case are (N x C x H x W), where N is the batch size, C is the number of channels, and H and W are the height and the width of the data. For non image case, the dimensions are in the form of (N x C x D1 x D2 ... Dn), where N is the batch size.
+
scale : T
+
The scale as a 1-dimensional tensor of size C to be applied to the output.
+
B : T
+
The bias as a 1-dimensional tensor of size C to be applied to the output.
+
mean : T
+
The running mean (training) or the estimated mean (testing) as a 1-dimensional tensor of size C.
+
var : T
+
The running variance (training) or the estimated variance (testing) as a 1-dimensional tensor of size C.
+
+ +#### Outputs (1 - 5) + +
+
Y : T
+
The output tensor of the same shape as X.
+
mean (optional) : T
+
The running mean after the BatchNormalization operator. Must be in-place with the input mean. Should not be used for testing.
+
var (optional) : T
+
The running variance after the BatchNormalization operator. Must be in-place with the input var. Should not be used for testing.
+
saved_mean (optional) : T
+
Saved mean used during training to speed up gradient computation. Should not be used for testing.
+
saved_var (optional) : T
+
Saved variance used during training to speed up gradient computation. Should not be used for testing.
+
+ +#### Type Constraints + +
+
T : tensor(float16), tensor(float), tensor(double)
+
Constrain input and output types to float tensors.
+
+ +### **Cast-6** + + The operator casts the elements of a given input tensor to a data type + specified by the 'to' argument and returns an output tensor of the same size in + the converted type. The 'to' argument must be one of the data types specified + in the 'DataType' enum field in the TensorProto message. + NOTE: Casting to and from strings is not supported yet. + +#### Version + +This version of the operator has been available since version 6 of the default ONNX operator set. + +#### Attributes + +
+
to : int (required)
+
The data type to which the elements of the input tensor are cast. Strictly must be one of the types from DataType enum in TensorProto
+
+ +#### Inputs + +
+
input : T1
+
Input tensor to be cast.
+
+ +#### Outputs + +
+
output : T2
+
Output tensor with the same shape as input with type specified by the 'to' argument
+
+ +#### Type Constraints + +
+
T1 : tensor(float16), tensor(float), tensor(double), tensor(int8), tensor(int16), tensor(int32), tensor(int64), tensor(uint8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(bool)
+
Constrain input types. Casting from strings and complex are not supported.
+
T2 : tensor(float16), tensor(float), tensor(double), tensor(int8), tensor(int16), tensor(int32), tensor(int64), tensor(uint8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(bool)
+
Constrain output types. Casting to strings and complex are not supported.
+
+ +### **Ceil-6** + + Ceil takes one input data (Tensor) and produces one output data + (Tensor) where the ceil is, y = ceil(x), is applied to + the tensor elementwise. + +#### Version + +This version of the operator has been available since version 6 of the default ONNX operator set. + +#### Inputs + +
+
X : T
+
Input tensor
+
+ +#### Outputs + +
+
Y : T
+
Output tensor
+
+ +#### Type Constraints + +
+
T : tensor(float16), tensor(float), tensor(double)
+
Constrain input and output types to float tensors.
+
+ +### **Clip-6** + + Clip operator limits the given input within an interval. The interval is + specified with arguments 'min' and 'max'. They default to + numeric_limits::lowest() and numeric_limits::max() respectively. + +#### Version + +This version of the operator has been available since version 6 of the default ONNX operator set. + +#### Attributes + +
+
max : float (default is (3.402823e+38))
+
Maximum value, above which element is replaced by max
+
min : float (default is (-3.402823e+38))
+
Minimum value, under which element is replaced by min
+
+ +#### Inputs + +
+
input : T
+
Input tensor whose elements to be clipped
+
+ +#### Outputs + +
+
output : T
+
Output tensor with clipped input elements
+
+ +#### Type Constraints + +
+
T : tensor(float16), tensor(float), tensor(double)
+
Constrain input and output types to float tensors.
+
+ +### **Div-6** + + Performs element-wise binary division (with limited broadcast support). + + If necessary the right-hand-side argument will be broadcasted to match the + shape of left-hand-side argument. When broadcasting is specified, the second + tensor can either be of element size 1 (including a scalar tensor and any + tensor with rank equal to or smaller than the first tensor), or having its + shape as a contiguous subset of the first tensor's shape. The starting of the + mutually equal shape is specified by the argument "axis", and if it is not set, + suffix matching is assumed. 1-dim expansion doesn't work yet. + + For example, the following tensor shapes are supported (with broadcast=1): + + shape(A) = (2, 3, 4, 5), shape(B) = (,), i.e. B is a scalar tensor + shape(A) = (2, 3, 4, 5), shape(B) = (1, 1), i.e. B is an 1-element tensor + shape(A) = (2, 3, 4, 5), shape(B) = (5,) + shape(A) = (2, 3, 4, 5), shape(B) = (4, 5) + shape(A) = (2, 3, 4, 5), shape(B) = (3, 4), with axis=1 + shape(A) = (2, 3, 4, 5), shape(B) = (2), with axis=0 + + Attribute `broadcast=1` needs to be passed to enable broadcasting. + +#### Version + +This version of the operator has been available since version 6 of the default ONNX operator set. + +#### Attributes + +
+
axis : int
+
If set, defines the broadcast dimensions. See doc for details.
+
broadcast : int (default is 0)
+
Pass 1 to enable broadcasting
+
+ +#### Inputs + +
+
A : T
+
First operand, should share the type with the second operand.
+
B : T
+
Second operand. With broadcasting can be of smaller size than A. If broadcasting is disabled it should be of the same size.
+
+ +#### Outputs + +
+
C : T
+
Result, has same dimensions and type as A
+
+ +#### Type Constraints + +
+
T : tensor(uint32), tensor(uint64), tensor(int32), tensor(int64), tensor(float16), tensor(float), tensor(double)
+
Constrain input and output types to high-precision numeric tensors.
+
+ +### **Dropout-6** + + Dropout takes one input data (Tensor) and produces two Tensor outputs, + output (Tensor) and mask (Tensor). Depending on whether it is in + test mode or not, the output Y will either be a random dropout, or a simple + copy of the input. Note that our implementation of Dropout does scaling in + the training phase, so during testing nothing needs to be done. + +#### Version + +This version of the operator has been available since version 6 of the default ONNX operator set. + +#### Attributes + +
+
is_test : int (default is 0)
+
(int, default 0) if nonzero, run dropout in test mode where the output is simply Y = X.
+
ratio : float (default is 0.5)
+
(float, default 0.5) the ratio of random dropout
+
+ +#### Inputs + +
+
data : T
+
The input data as Tensor.
+
+ +#### Outputs (1 - 2) + +
+
output : T
+
The output.
+
mask (optional) : T
+
The output mask. If is_test is nonzero, this output is not filled.
+
+ +#### Type Constraints + +
+
T : tensor(float16), tensor(float), tensor(double)
+
Constrain input and output types to float tensors.
+
+ +### **Elu-6** + + Elu takes one input data (Tensor) and produces one output data + (Tensor) where the function `f(x) = alpha * (exp(x) - 1.) for x < + 0`, `f(x) = x for x >= 0`., is applied to the tensor elementwise. + + +#### Version + +This version of the operator has been available since version 6 of the default ONNX operator set. + +#### Attributes + +
+
alpha : float (default is 1.0)
+
Coefficient of ELU.
+
+ +#### Inputs + +
+
X (differentiable) : T
+
1D input tensor
+
+ +#### Outputs + +
+
Y (differentiable) : T
+
1D output tensor
+
+ +#### Type Constraints + +
+
T : tensor(float16), tensor(float), tensor(double)
+
Constrain input and output types to float tensors.
+
+ +### **Exp-6** + + Calculates the exponential of the given input tensor, element-wise. + +#### Version + +This version of the operator has been available since version 6 of the default ONNX operator set. + +#### Inputs + +
+
input : T
+
Input tensor
+
+ +#### Outputs + +
+
output : T
+
The exponential of the input tensor computed element-wise
+
+ +#### Type Constraints + +
+
T : tensor(float16), tensor(float), tensor(double)
+
Constrain input and output types to float tensors.
+
+ +### **Floor-6** + + Floor takes one input data (Tensor) and produces one output data + (Tensor) where the floor is, y = floor(x), is applied to + the tensor elementwise. + +#### Version + +This version of the operator has been available since version 6 of the default ONNX operator set. + +#### Inputs + +
+
X : T
+
Input tensor
+
+ +#### Outputs + +
+
Y : T
+
Output tensor
+
+ +#### Type Constraints + +
+
T : tensor(float16), tensor(float), tensor(double)
+
Constrain input and output types to float tensors.
+
+ +### **Gemm-6** + + General Matrix multiplication: + https://en.wikipedia.org/wiki/Basic_Linear_Algebra_Subprograms#Level_3 + Compute Y = alpha * A * B + beta * C, where input tensor A has + dimension (M X K), input tensor B has dimension (K X N), input tensor C and + output tensor Y have dimension (M X N). + If attribute broadcast is non-zero, input tensor C will be broadcasted to match + the dimension requirement. A will be transposed before doing the computation + if attribute transA is non-zero, same for B and transB. + +#### Version + +This version of the operator has been available since version 6 of the default ONNX operator set. + +#### Attributes + +
+
alpha : float (default is 1.0)
+
Scalar multiplier for the product of input tensors A * B, the default value is 1.0.
+
beta : float (default is 1.0)
+
Scalar multiplier for input tensor C, the default value is 1.0.
+
broadcast : int (default is 0)
+
Whether C should be broadcasted
+
transA : int (default is 0)
+
Whether A should be transposed
+
transB : int (default is 0)
+
Whether B should be transposed
+
+ +#### Inputs + +
+
A : T
+
Input tensor A
+
B : T
+
Input tensor B
+
C : T
+
Input tensor C
+
+ +#### Outputs + +
+
Y : T
+
Output tensor.
+
+ +#### Type Constraints + +
+
T : tensor(float16), tensor(float), tensor(double)
+
Constrain input and output types to float tensors.
+
+ +### **HardSigmoid-6** + + HardSigmoid takes one input data (Tensor) and produces one output data + (Tensor) where the HardSigmoid function, y = max(0, min(1, alpha * x + beta)), + is applied to the tensor elementwise. + +#### Version + +This version of the operator has been available since version 6 of the default ONNX operator set. + +#### Attributes + +
+
alpha : float (default is 0.2)
+
Value of alpha.
+
beta : float (default is 0.5)
+
Value of beta.
+
+ +#### Inputs + +
+
X (differentiable) : T
+
Input tensor
+
+ +#### Outputs + +
+
Y (differentiable) : T
+
Output tensor
+
+ +#### Type Constraints + +
+
T : tensor(float16), tensor(float), tensor(double)
+
Constrain input and output types to float tensors.
+
+ +### **InstanceNormalization-6** + + Carries out instance normalization as described in the paper + https://arxiv.org/abs/1607.08022. + + y = scale * (x - mean) / sqrt(variance + epsilon) + B, + where mean and variance are computed per instance per channel. + + +#### Version + +This version of the operator has been available since version 6 of the default ONNX operator set. + +#### Attributes + +
+
epsilon : float (default is 1e-05)
+
The epsilon value to use to avoid division by zero.
+
+ +#### Inputs + +
+
input (differentiable) : T
+
Input data tensor from the previous operator; dimensions for image case are (N x C x H x W), where N is the batch size, C is the number of channels, and H and W are the height and the width of the data. For non image case, the dimensions are in the form of (N x C x D1 x D2 ... Dn), where N is the batch size.
+
scale (differentiable) : T
+
The input 1-dimensional scale tensor of size C.
+
B (differentiable) : T
+
The input 1-dimensional bias tensor of size C.
+
+ +#### Outputs + +
+
output (differentiable) : T
+
The output tensor of the same shape as input.
+
+ +#### Type Constraints + +
+
T : tensor(float16), tensor(float), tensor(double)
+
Constrain input and output types to float tensors.
+
+ +### **LeakyRelu-6** + + LeakyRelu takes input data (Tensor) and an argument alpha, and produces one + output data (Tensor) where the function `f(x) = alpha * x for x < 0`, + `f(x) = x for x >= 0`, is applied to the data tensor elementwise. + +#### Version + +This version of the operator has been available since version 6 of the default ONNX operator set. + +#### Attributes + +
+
alpha : float (default is 0.01)
+
Coefficient of leakage.
+
+ +#### Inputs + +
+
X (differentiable) : T
+
Input tensor
+
+ +#### Outputs + +
+
Y (differentiable) : T
+
Output tensor
+
+ +#### Type Constraints + +
+
T : tensor(float16), tensor(float), tensor(double)
+
Constrain input and output types to float tensors.
+
+ +### **Log-6** + + Calculates the natural log of the given input tensor, element-wise. + +#### Version + +This version of the operator has been available since version 6 of the default ONNX operator set. + +#### Inputs + +
+
input : T
+
Input tensor
+
+ +#### Outputs + +
+
output : T
+
The natural log of the input tensor computed element-wise
+
+ +#### Type Constraints + +
+
T : tensor(float16), tensor(float), tensor(double)
+
Constrain input and output types to float tensors.
+
+ +### **Max-6** + + Element-wise max of each of the input tensors. All inputs and outputs must + have the same shape and data type. + +#### Version + +This version of the operator has been available since version 6 of the default ONNX operator set. + +#### Inputs (1 - ∞) + +
+
data_0 (variadic) : T
+
List of tensors for Max.
+
+ +#### Outputs + +
+
max : T
+
Output tensor. Same dimension as inputs.
+
+ +#### Type Constraints + +
+
T : tensor(float16), tensor(float), tensor(double)
+
Constrain input and output types to float tensors.
+
+ +### **Mean-6** + + Element-wise mean of each of the input tensors. All inputs and outputs must + have the same shape and data type. + +#### Version + +This version of the operator has been available since version 6 of the default ONNX operator set. + +#### Inputs (1 - ∞) + +
+
data_0 (variadic) : T
+
List of tensors for Mean.
+
+ +#### Outputs + +
+
mean : T
+
Output tensor. Same dimension as inputs.
+
+ +#### Type Constraints + +
+
T : tensor(float16), tensor(float), tensor(double)
+
Constrain input and output types to float tensors.
+
+ +### **Min-6** + + Element-wise min of each of the input tensors. All inputs and outputs must + have the same shape and data type. + +#### Version + +This version of the operator has been available since version 6 of the default ONNX operator set. + +#### Inputs (1 - ∞) + +
+
data_0 (variadic) : T
+
List of tensors for Min
+
+ +#### Outputs + +
+
min : T
+
Output tensor. Same dimension as inputs.
+
+ +#### Type Constraints + +
+
T : tensor(float16), tensor(float), tensor(double)
+
Constrain input and output types to float tensors.
+
+ +### **Mul-6** + + Performs element-wise binary multiplication (with limited broadcast support). + + If necessary the right-hand-side argument will be broadcasted to match the + shape of left-hand-side argument. When broadcasting is specified, the second + tensor can either be of element size 1 (including a scalar tensor and any + tensor with rank equal to or smaller than the first tensor), or having its + shape as a contiguous subset of the first tensor's shape. The starting of the + mutually equal shape is specified by the argument "axis", and if it is not set, + suffix matching is assumed. 1-dim expansion doesn't work yet. + + For example, the following tensor shapes are supported (with broadcast=1): + + shape(A) = (2, 3, 4, 5), shape(B) = (,), i.e. B is a scalar tensor + shape(A) = (2, 3, 4, 5), shape(B) = (1, 1), i.e. B is an 1-element tensor + shape(A) = (2, 3, 4, 5), shape(B) = (5,) + shape(A) = (2, 3, 4, 5), shape(B) = (4, 5) + shape(A) = (2, 3, 4, 5), shape(B) = (3, 4), with axis=1 + shape(A) = (2, 3, 4, 5), shape(B) = (2), with axis=0 + + Attribute `broadcast=1` needs to be passed to enable broadcasting. + +#### Version + +This version of the operator has been available since version 6 of the default ONNX operator set. + +#### Attributes + +
+
axis : int
+
If set, defines the broadcast dimensions. See doc for details.
+
broadcast : int (default is 0)
+
Pass 1 to enable broadcasting
+
+ +#### Inputs + +
+
A : T
+
First operand, should share the type with the second operand.
+
B : T
+
Second operand. With broadcasting can be of smaller size than A. If broadcasting is disabled it should be of the same size.
+
+ +#### Outputs + +
+
C : T
+
Result, has same dimensions and type as A
+
+ +#### Type Constraints + +
+
T : tensor(uint32), tensor(uint64), tensor(int32), tensor(int64), tensor(float16), tensor(float), tensor(double)
+
Constrain input and output types to high-precision numeric tensors.
+
+ +### **Neg-6** + + Neg takes one input data (Tensor) and produces one output data + (Tensor) where each element flipped sign, y = -x, is applied to + the tensor elementwise. + +#### Version + +This version of the operator has been available since version 6 of the default ONNX operator set. + +#### Inputs + +
+
X : T
+
Input tensor
+
+ +#### Outputs + +
+
Y : T
+
Output tensor
+
+ +#### Type Constraints + +
+
T : tensor(float), tensor(int32), tensor(int8), tensor(int16), tensor(int64), tensor(float16), tensor(double)
+
Constrain input and output types to signed numeric tensors.
+
+ +### **PRelu-6** + + PRelu takes input data (Tensor) and slope tensor as input, and produces one + output data (Tensor) where the function `f(x) = slope * x for x < 0`, + `f(x) = x for x >= 0`., is applied to the data tensor elementwise. + + +#### Version + +This version of the operator has been available since version 6 of the default ONNX operator set. + +#### Inputs + +
+
X : T
+
Input tensor
+
slope : T
+
Slope tensor. If `Slope` is of size 1, the value is sharedacross different channels
+
+ +#### Outputs + +
+
Y : T
+
Output tensor
+
+ +#### Type Constraints + +
+
T : tensor(float16), tensor(float), tensor(double)
+
Constrain input and output types to float tensors.
+
+ +### **Reciprocal-6** + + Reciprocal takes one input data (Tensor) and produces one output data + (Tensor) where the reciprocal is, y = 1/x, is applied to + the tensor elementwise. + +#### Version + +This version of the operator has been available since version 6 of the default ONNX operator set. + +#### Inputs + +
+
X : T
+
Input tensor
+
+ +#### Outputs + +
+
Y : T
+
Output tensor
+
+ +#### Type Constraints + +
+
T : tensor(float16), tensor(float), tensor(double)
+
Constrain input and output types to float tensors.
+
+ +### **Relu-6** + + Relu takes one input data (Tensor) and produces one output data + (Tensor) where the rectified linear function, y = max(0, x), is applied to + the tensor elementwise. + +#### Version + +This version of the operator has been available since version 6 of the default ONNX operator set. + +#### Inputs + +
+
X : T
+
Input tensor
+
+ +#### Outputs + +
+
Y : T
+
Output tensor
+
+ +#### Type Constraints + +
+
T : tensor(float16), tensor(float), tensor(double)
+
Constrain input and output types to float tensors.
+
+ +### **Selu-6** + + Selu takes one input data (Tensor) and produces one output data + (Tensor) where the scaled exponential linear unit function, + `y = gamma * (alpha * e^x - alpha) for x <= 0`, `y = gamma * x for x > 0`, + is applied to the tensor elementwise. + +#### Version + +This version of the operator has been available since version 6 of the default ONNX operator set. + +#### Attributes + +
+
alpha : float (default is 1.67326)
+
Coefficient of SELU default to 1.67326319217681884765625 (i.e., float32 approximation of 1.6732632423543772848170429916717).
+
gamma : float (default is 1.0507)
+
Coefficient of SELU default to 1.05070102214813232421875 (i.e., float32 approximation of 1.0507009873554804934193349852946).
+
+ +#### Inputs + +
+
X (differentiable) : T
+
Input tensor
+
+ +#### Outputs + +
+
Y (differentiable) : T
+
Output tensor
+
+ +#### Type Constraints + +
+
T : tensor(float16), tensor(float), tensor(double)
+
Constrain input and output types to float tensors.
+
+ +### **Sigmoid-6** + + Sigmoid takes one input data (Tensor) and produces one output data + (Tensor) where the sigmoid function, y = 1 / (1 + exp(-x)), is applied to the + tensor elementwise. + +#### Version + +This version of the operator has been available since version 6 of the default ONNX operator set. + +#### Inputs + +
+
X : T
+
Input tensor
+
+ +#### Outputs + +
+
Y : T
+
Output tensor
+
+ +#### Type Constraints + +
+
T : tensor(float16), tensor(float), tensor(double)
+
Constrain input and output types to float tensors.
+
+ +### **Sqrt-6** + + Square root takes one input data (Tensor) and produces one output data + (Tensor) where the square root is, y = x^0.5, is applied to + the tensor elementwise. If x is negative, then it will return NaN. + +#### Version + +This version of the operator has been available since version 6 of the default ONNX operator set. + +#### Inputs + +
+
X : T
+
Input tensor
+
+ +#### Outputs + +
+
Y : T
+
Output tensor
+
+ +#### Type Constraints + +
+
T : tensor(float16), tensor(float), tensor(double)
+
Constrain input and output types to float tensors.
+
+ +### **Sub-6** + + Performs element-wise binary subtraction (with limited broadcast support). + + If necessary the right-hand-side argument will be broadcasted to match the + shape of left-hand-side argument. When broadcasting is specified, the second + tensor can either be of element size 1 (including a scalar tensor and any + tensor with rank equal to or smaller than the first tensor), or having its + shape as a contiguous subset of the first tensor's shape. The starting of the + mutually equal shape is specified by the argument "axis", and if it is not set, + suffix matching is assumed. 1-dim expansion doesn't work yet. + + For example, the following tensor shapes are supported (with broadcast=1): + + shape(A) = (2, 3, 4, 5), shape(B) = (,), i.e. B is a scalar tensor + shape(A) = (2, 3, 4, 5), shape(B) = (1, 1), i.e. B is an 1-element tensor + shape(A) = (2, 3, 4, 5), shape(B) = (5,) + shape(A) = (2, 3, 4, 5), shape(B) = (4, 5) + shape(A) = (2, 3, 4, 5), shape(B) = (3, 4), with axis=1 + shape(A) = (2, 3, 4, 5), shape(B) = (2), with axis=0 + + Attribute `broadcast=1` needs to be passed to enable broadcasting. + +#### Version + +This version of the operator has been available since version 6 of the default ONNX operator set. + +#### Attributes + +
+
axis : int
+
If set, defines the broadcast dimensions. See doc for details.
+
broadcast : int (default is 0)
+
Pass 1 to enable broadcasting
+
+ +#### Inputs + +
+
A : T
+
First operand, should share the type with the second operand.
+
B : T
+
Second operand. With broadcasting can be of smaller size than A. If broadcasting is disabled it should be of the same size.
+
+ +#### Outputs + +
+
C : T
+
Result, has same dimensions and type as A
+
+ +#### Type Constraints + +
+
T : tensor(uint32), tensor(uint64), tensor(int32), tensor(int64), tensor(float16), tensor(float), tensor(double)
+
Constrain input and output types to high-precision numeric tensors.
+
+ +### **Sum-6** + + Element-wise sum of each of the input tensors. All inputs and outputs must + have the same shape and data type. + +#### Version + +This version of the operator has been available since version 6 of the default ONNX operator set. + +#### Inputs (1 - ∞) + +
+
data_0 (variadic) : T
+
List of tensors for Sum.
+
+ +#### Outputs + +
+
sum : T
+
Output tensor. Same dimension as inputs.
+
+ +#### Type Constraints + +
+
T : tensor(float16), tensor(float), tensor(double)
+
Constrain input and output types to float tensors.
+
+ +### **Tanh-6** + + Calculates the hyperbolic tangent of the given input tensor element-wise. + +#### Version + +This version of the operator has been available since version 6 of the default ONNX operator set. + +#### Inputs + +
+
input : T
+
Input tensor
+
+ +#### Outputs + +
+
output : T
+
The hyperbolic tangent values of the input tensor computed element-wise
+
+ +#### Type Constraints + +
+
T : tensor(float16), tensor(float), tensor(double)
+
Constrain input and output types to float tensors.
+
+ +### **Tile-6** + + Constructs a tensor by tiling a given tensor. + This is the same as function `tile` in Numpy, but no broadcast. + For example A = [[1, 2], [3, 4]], B = [1, 2], tile(A, B) = [[1, 2, 1, 2], [3, 4, 3, 4]] + +#### Version + +This version of the operator has been available since version 6 of the default ONNX operator set. + +#### Inputs + +
+
input : T
+
Input tensor of any shape.
+
repeats : T1
+
1D int64 tensor of the same length as input's dimension number, includes numbers of repeated copies along input's dimensions.
+
+ +#### Outputs + +
+
output : T
+
Output tensor of the same dimension and type as tensor input. output_dim[i] = input_dim[i] * repeats[i]
+
+ +#### Type Constraints + +
+
T : tensor(uint8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(int8), tensor(int16), tensor(int32), tensor(int64), tensor(float16), tensor(float), tensor(double), tensor(string), tensor(bool), tensor(complex64), tensor(complex128)
+
Constrain input and output types to all tensor types.
+
T1 : tensor(int64)
+
Constrain repeat's type to int64 tensors.
+
+ +## Version 7 of the default ONNX operator set +### **Acos-7** + + Calculates the arccosine (inverse of cosine) of the given input tensor, element-wise. + +#### Version + +This version of the operator has been available since version 7 of the default ONNX operator set. + +#### Inputs + +
+
input (differentiable) : T
+
Input tensor
+
+ +#### Outputs + +
+
output (differentiable) : T
+
The arccosine of the input tensor computed element-wise
+
+ +#### Type Constraints + +
+
T : tensor(float16), tensor(float), tensor(double)
+
Constrain input and output types to float tensors.
+
+ +### **Add-7** + + Performs element-wise binary addition (with Numpy-style broadcasting support). + + This operator supports **multidirectional (i.e., Numpy-style) broadcasting**; for more details please check [the doc](Broadcasting.md). + +#### Version + +This version of the operator has been available since version 7 of the default ONNX operator set. + +#### Inputs + +
+
A : T
+
First operand.
+
B : T
+
Second operand.
+
+ +#### Outputs + +
+
C : T
+
Result, has same element type as two inputs
+
+ +#### Type Constraints + +
+
T : tensor(uint32), tensor(uint64), tensor(int32), tensor(int64), tensor(float16), tensor(float), tensor(double)
+
Constrain input and output types to high-precision numeric tensors.
+
+ +### **And-7** + + Returns the tensor resulted from performing the `and` logical operation + elementwise on the input tensors `A` and `B` (with Numpy-style broadcasting support). + + This operator supports **multidirectional (i.e., Numpy-style) broadcasting**; for more details please check [the doc](Broadcasting.md). + +#### Version + +This version of the operator has been available since version 7 of the default ONNX operator set. + +#### Inputs + +
+
A (non-differentiable) : T
+
First input operand for the logical operator.
+
B (non-differentiable) : T
+
Second input operand for the logical operator.
+
+ +#### Outputs + +
+
C (non-differentiable) : T1
+
Result tensor.
+
+ +#### Type Constraints + +
+
T : tensor(bool)
+
Constrains input to boolean tensor.
+
T1 : tensor(bool)
+
Constrains output to boolean tensor.
+
+ +### **Asin-7** + + Calculates the arcsine (inverse of sine) of the given input tensor, element-wise. + +#### Version + +This version of the operator has been available since version 7 of the default ONNX operator set. + +#### Inputs + +
+
input (differentiable) : T
+
Input tensor
+
+ +#### Outputs + +
+
output (differentiable) : T
+
The arcsine of the input tensor computed element-wise
+
+ +#### Type Constraints + +
+
T : tensor(float16), tensor(float), tensor(double)
+
Constrain input and output types to float tensors.
+
+ +### **Atan-7** + + Calculates the arctangent (inverse of tangent) of the given input tensor, element-wise. + +#### Version + +This version of the operator has been available since version 7 of the default ONNX operator set. + +#### Inputs + +
+
input (differentiable) : T
+
Input tensor
+
+ +#### Outputs + +
+
output (differentiable) : T
+
The arctangent of the input tensor computed element-wise
+
+ +#### Type Constraints + +
+
T : tensor(float16), tensor(float), tensor(double)
+
Constrain input and output types to float tensors.
+
+ +### **AveragePool-7** + + AveragePool consumes an input tensor X and applies average pooling across + the tensor according to kernel sizes, stride sizes, and pad lengths. + average pooling consisting of computing the average on all values of a + subset of the input tensor according to the kernel size and downsampling the + data into the output tensor Y for further processing. The output spatial shape will be following: + ``` + output_spatial_shape[i] = floor((input_spatial_shape[i] + pad_shape[i] - kernel_spatial_shape[i]) / strides_spatial_shape[i] + 1) + + * pad_shape[i] is sum of pads along axis i + ``` + + `auto_pad` is a DEPRECATED attribute. If you are using them currently, the output spatial shape will be following: + ``` + VALID: output_spatial_shape[i] = ceil((input_spatial_shape[i] - kernel_spatial_shape[i] + 1) / strides_spatial_shape[i]) + SAME_UPPER or SAME_LOWER: output_spatial_shape[i] = ceil(input_spatial_shape[i] / strides_spatial_shape[i]) + ``` + And pad shape will be following if `SAME_UPPER` or `SAME_LOWER`: + ``` + pad_shape[i] = (output_spatial_shape[i] - 1) * strides_spatial_shape[i] + kernel_spatial_shape[i] - input_spatial_shape[i] + ``` + The output of each pooling window is divided by the number of elements (exclude pad when attribute count_include_pad is zero). + + +#### Version + +This version of the operator has been available since version 7 of the default ONNX operator set. + +#### Attributes + +
+
auto_pad : string (default is NOTSET)
+
auto_pad must be either NOTSET, SAME_UPPER, SAME_LOWER or VALID. Where default value is NOTSET, which means explicit padding is used. SAME_UPPER or SAME_LOWER mean pad the input so that the output spatial size match the input.In case of odd number add the extra padding at the end for SAME_UPPER and at the beginning for SAME_LOWER. VALID mean no padding.
+
count_include_pad : int (default is 0)
+
Whether include pad pixels when calculating values for the edges. Default is 0, doesn't count include pad.
+
kernel_shape : list of ints (required)
+
The size of the kernel along each axis.
+
pads : list of ints
+
Padding for the beginning and ending along each spatial axis, it can take any value greater than or equal to 0. The value represent the number of pixels added to the beginning and end part of the corresponding axis. `pads` format should be as follow [x1_begin, x2_begin...x1_end, x2_end,...], where xi_begin the number of pixels added at the beginning of axis `i` and xi_end, the number of pixels added at the end of axis `i`. This attribute cannot be used simultaneously with auto_pad attribute. If not present, the padding defaults to 0 along start and end of each spatial axis.
+
strides : list of ints
+
Stride along each spatial axis.
+
+ +#### Inputs + +
+
X : T
+
Input data tensor from the previous operator; dimensions for image case are (N x C x H x W), where N is the batch size, C is the number of channels, and H and W are the height and the width of the data. For non image case, the dimensions are in the form of (N x C x D1 x D2 ... Dn), where N is the batch size. Optionally, if dimension denotation is in effect, the operation expects the input data tensor to arrive with the dimension denotation of [DATA_BATCH, DATA_CHANNEL, DATA_FEATURE, DATA_FEATURE ...].
+
+ +#### Outputs + +
+
Y : T
+
Output data tensor from average or max pooling across the input tensor. Dimensions will vary based on various kernel, stride, and pad sizes. Floor value of the dimension is used
+
+ +#### Type Constraints + +
+
T : tensor(float16), tensor(float), tensor(double)
+
Constrain input and output types to float tensors.
+
+ +### **BatchNormalization-7** + + Carries out batch normalization as described in the paper + https://arxiv.org/abs/1502.03167. Depending on the mode it is being run, + there are multiple cases for the number of outputs, which we list below: + + Output case #1: Y, mean, var, saved_mean, saved_var (training mode) + Output case #2: Y (test mode) + This operator has **optional** inputs/outputs. See [the doc](IR.md) for more details about the representation of optional arguments. An empty string may be used in the place of an actual argument's name to indicate a missing argument. Trailing optional arguments (those not followed by an argument that is present) may also be simply omitted. + +#### Version + +This version of the operator has been available since version 7 of the default ONNX operator set. + +#### Attributes + +
+
epsilon : float (default is 1e-05)
+
The epsilon value to use to avoid division by zero.
+
momentum : float (default is 0.9)
+
Factor used in computing the running mean and variance.e.g., running_mean = running_mean * momentum + mean * (1 - momentum).
+
spatial : int (default is 1)
+
If true, compute the mean and variance across per activation. If false, compute the mean and variance across per feature over each mini-batch.
+
+ +#### Inputs + +
+
X : T
+
Input data tensor from the previous operator; dimensions for image case are (N x C x H x W), where N is the batch size, C is the number of channels, and H and W are the height and the width of the data. For non image case, the dimensions are in the form of (N x C x D1 x D2 ... Dn), where N is the batch size.
+
scale : T
+
If spatial is true, the dimension of scale is (C). If spatial is false, the dimensions of scale are (C x D1 x ... x Dn)
+
B : T
+
If spatial is true, the dimension of bias is (C). If spatial is false, the dimensions of bias are (C x D1 x ... x Dn)
+
mean : T
+
If spatial is true, the dimension of the running mean (training) or the estimated mean (testing) is (C). If spatial is false, the dimensions of the running mean (training) or the estimated mean (testing) are (C x D1 x ... x Dn).
+
var : T
+
If spatial is true, the dimension of the running variance(training) or the estimated variance (testing) is (C). If spatial is false, the dimensions of the running variance(training) or the estimated variance (testing) are (C x D1 x ... x Dn).
+
+ +#### Outputs (1 - 5) + +
+
Y : T
+
The output tensor of the same shape as X
+
mean (optional) : T
+
The running mean after the BatchNormalization operator.
+
var (optional) : T
+
The running variance after the BatchNormalization operator.
+
saved_mean (optional) : T
+
Saved mean used during training to speed up gradient computation.
+
saved_var (optional) : T
+
Saved variance used during training to speed up gradient computation.
+
+ +#### Type Constraints + +
+
T : tensor(float16), tensor(float), tensor(double)
+
Constrain input and output types to float tensors.
+
+ +### **Cos-7** + + Calculates the cosine of the given input tensor, element-wise. + +#### Version + +This version of the operator has been available since version 7 of the default ONNX operator set. + +#### Inputs + +
+
input (differentiable) : T
+
Input tensor
+
+ +#### Outputs + +
+
output (differentiable) : T
+
The cosine of the input tensor computed element-wise
+
+ +#### Type Constraints + +
+
T : tensor(float16), tensor(float), tensor(double)
+
Constrain input and output types to float tensors.
+
+ +### **Div-7** + + Performs element-wise binary division (with Numpy-style broadcasting support). + + This operator supports **multidirectional (i.e., Numpy-style) broadcasting**; for more details please check [the doc](Broadcasting.md). + +#### Version + +This version of the operator has been available since version 7 of the default ONNX operator set. + +#### Inputs + +
+
A : T
+
First operand.
+
B : T
+
Second operand.
+
+ +#### Outputs + +
+
C : T
+
Result, has same element type as two inputs
+
+ +#### Type Constraints + +
+
T : tensor(uint32), tensor(uint64), tensor(int32), tensor(int64), tensor(float16), tensor(float), tensor(double)
+
Constrain input and output types to high-precision numeric tensors.
+
+ +### **Dropout-7** + + Dropout takes one input data (Tensor) and produces two Tensor outputs, + output (Tensor) and mask (Tensor). Depending on whether it is in + test mode or not, the output Y will either be a random dropout, or a simple + copy of the input. Note that our implementation of Dropout does scaling in + the training phase, so during testing nothing needs to be done. + This operator has **optional** inputs/outputs. See [the doc](IR.md) for more details about the representation of optional arguments. An empty string may be used in the place of an actual argument's name to indicate a missing argument. Trailing optional arguments (those not followed by an argument that is present) may also be simply omitted. + +#### Version + +This version of the operator has been available since version 7 of the default ONNX operator set. + +#### Attributes + +
+
ratio : float (default is 0.5)
+
The ratio of random dropout
+
+ +#### Inputs + +
+
data : T
+
The input data as Tensor.
+
+ +#### Outputs (1 - 2) + +
+
output : T
+
The output.
+
mask (optional) : T
+
The output mask.
+
+ +#### Type Constraints + +
+
T : tensor(float16), tensor(float), tensor(double)
+
Constrain input and output types to float tensors.
+
+ +### **Equal-7** + + Returns the tensor resulted from performing the `equal` logical operation + elementwise on the input tensors `A` and `B` (with Numpy-style broadcasting support). + + This operator supports **multidirectional (i.e., Numpy-style) broadcasting**; for more details please check [the doc](Broadcasting.md). + +#### Version + +This version of the operator has been available since version 7 of the default ONNX operator set. + +#### Inputs + +
+
A : T
+
First input operand for the logical operator.
+
B : T
+
Second input operand for the logical operator.
+
+ +#### Outputs + +
+
C : T1
+
Result tensor.
+
+ +#### Type Constraints + +
+
T : tensor(bool), tensor(int32), tensor(int64)
+
Constrains input to integral tensors.
+
T1 : tensor(bool)
+
Constrains output to boolean tensor.
+
+ +### **GRU-7** + + Computes an one-layer GRU. This operator is usually supported via some custom + implementation such as CuDNN. + + Notations: + + `X` - input tensor + + `z` - update gate + + `r` - reset gate + + `h` - hidden gate + + `t` - time step (t-1 means previous time step) + + `W[zrh]` - W parameter weight matrix for update, reset, and hidden gates + + `R[zrh]` - R recurrence weight matrix for update, reset, and hidden gates + + `Wb[zrh]` - W bias vectors for update, reset, and hidden gates + + `Rb[zrh]` - R bias vectors for update, reset, and hidden gates + + `WB[zrh]` - W parameter weight matrix for backward update, reset, and hidden gates + + `RB[zrh]` - R recurrence weight matrix for backward update, reset, and hidden gates + + `WBb[zrh]` - W bias vectors for backward update, reset, and hidden gates + + `RBb[zrh]` - R bias vectors for backward update, reset, and hidden gates + + `H` - Hidden state + + `num_directions` - 2 if direction == bidirectional else 1 + + Activation functions: + + Relu(x) - max(0, x) + + Tanh(x) - (1 - e^{-2x})/(1 + e^{-2x}) + + Sigmoid(x) - 1/(1 + e^{-x}) + + (NOTE: Below are optional) + + Affine(x) - alpha*x + beta + + LeakyRelu(x) - x if x >= 0 else alpha * x + + ThresholdedRelu(x) - x if x >= alpha else 0 + + ScaledTanh(x) - alpha*Tanh(beta*x) + + HardSigmoid(x) - min(max(alpha*x + beta, 0), 1) + + Elu(x) - x if x >= 0 else alpha*(e^x - 1) + + Softsign(x) - x/(1 + |x|) + + Softplus(x) - log(1 + e^x) + + Equations (Default: f=Sigmoid, g=Tanh): + + - zt = f(Xt*(Wz^T) + Ht-1*(Rz^T) + Wbz + Rbz) + + - rt = f(Xt*(Wr^T) + Ht-1*(Rr^T) + Wbr + Rbr) + + - ht = g(Xt*(Wh^T) + (rt (.) Ht-1)*(Rh^T) + Rbh + Wbh) # default, when linear_before_reset = 0 + + - ht = g(Xt*(Wh^T) + (rt (.) (Ht-1*(Rh^T) + Rbh)) + Wbh) # when linear_before_reset != 0 + + - Ht = (1 - zt) (.) ht + zt (.) Ht-1 + This operator has **optional** inputs/outputs. See [the doc](IR.md) for more details about the representation of optional arguments. An empty string may be used in the place of an actual argument's name to indicate a missing argument. Trailing optional arguments (those not followed by an argument that is present) may also be simply omitted. + +#### Version + +This version of the operator has been available since version 7 of the default ONNX operator set. + +#### Attributes + +
+
activation_alpha : list of floats
+
Optional scaling values used by some activation functions. The values are consumed in the order of activation functions, for example (f, g, h) in LSTM. Default values are the same as of corresponding ONNX operators.For example with LeakyRelu, the default alpha is 0.01.
+
activation_beta : list of floats
+
Optional scaling values used by some activation functions. The values are consumed in the order of activation functions, for example (f, g, h) in LSTM. Default values are the same as of corresponding ONNX operators.
+
activations : list of strings
+
A list of 2 (or 4 if bidirectional) activation functions for update, reset, and hidden gates. The activation functions must be one of the activation functions specified above. Optional: See the equations for default if not specified.
+
clip : float
+
Cell clip threshold. Clipping bounds the elements of a tensor in the range of [-threshold, +threshold] and is applied to the input of activations. No clip if not specified.
+
direction : string (default is forward)
+
Specify if the RNN is forward, reverse, or bidirectional. Must be one of forward (default), reverse, or bidirectional.
+
hidden_size : int
+
Number of neurons in the hidden layer
+
linear_before_reset : int (default is 0)
+
When computing the output of the hidden gate, apply the linear transformation before multiplying by the output of the reset gate.
+
+ +#### Inputs (3 - 6) + +
+
X : T
+
The input sequences packed (and potentially padded) into one 3-D tensor with the shape of `[seq_length, batch_size, input_size]`.
+
W : T
+
The weight tensor for the gates. Concatenation of `W[zrh]` and `WB[zrh]` (if bidirectional) along dimension 0. This tensor has shape `[num_directions, 3*hidden_size, input_size]`.
+
R : T
+
The recurrence weight tensor. Concatenation of `R[zrh]` and `RB[zrh]` (if bidirectional) along dimension 0. This tensor has shape `[num_directions, 3*hidden_size, hidden_size]`.
+
B (optional) : T
+
The bias tensor for the gates. Concatenation of `[Wb[zrh], Rb[zrh]]` and `[WBb[zrh], RBb[zrh]]` (if bidirectional) along dimension 0. This tensor has shape `[num_directions, 6*hidden_size]`. Optional: If not specified - assumed to be 0
+
sequence_lens (optional) : T1
+
Optional tensor specifying lengths of the sequences in a batch. If not specified - assumed all sequences in the batch to have length `seq_length`. It has shape `[batch_size]`.
+
initial_h (optional) : T
+
Optional initial value of the hidden. If not specified - assumed to be 0. It has shape `[num_directions, batch_size, hidden_size]`.
+
+ +#### Outputs (0 - 2) + +
+
Y (optional) : T
+
A tensor that concats all the intermediate output values of the hidden. It has shape `[seq_length, num_directions, batch_size, hidden_size]`.
+
Y_h (optional) : T
+
The last output value of the hidden. It has shape `[num_directions, batch_size, hidden_size]`.
+
+ +#### Type Constraints + +
+
T : tensor(float16), tensor(float), tensor(double)
+
Constrain input and output types to float tensors.
+
T1 : tensor(int32)
+
Constrain seq_lens to integer tensor.
+
+ +### **Gemm-7** + + General Matrix multiplication: + https://en.wikipedia.org/wiki/Basic_Linear_Algebra_Subprograms#Level_3 + + A' = transpose(A) if transA else A + + B' = transpose(B) if transB else B + + Compute Y = alpha * A' * B' + beta * C, where input tensor A has shape (M, K) or (K, M), + input tensor B has shape (K, N) or (N, K), input tensor C is broadcastable to shape (M, N), + and output tensor Y has shape (M, N). A will be transposed before doing the + computation if attribute transA is non-zero, same for B and transB. + This operator supports **unidirectional broadcasting** (tensor C should be unidirectional broadcastable to tensor A * B); for more details please check [the doc](Broadcasting.md). + +#### Version + +This version of the operator has been available since version 7 of the default ONNX operator set. + +#### Attributes + +
+
alpha : float (default is 1.0)
+
Scalar multiplier for the product of input tensors A * B.
+
beta : float (default is 1.0)
+
Scalar multiplier for input tensor C.
+
transA : int (default is 0)
+
Whether A should be transposed
+
transB : int (default is 0)
+
Whether B should be transposed
+
+ +#### Inputs + +
+
A : T
+
Input tensor A. The shape of A should be (M, K) if transA is 0, or (K, M) if transA is non-zero.
+
B : T
+
Input tensor B. The shape of B should be (K, N) if transB is 0, or (N, K) if transB is non-zero.
+
C : T
+
Input tensor C. The shape of C should be unidirectional broadcastable to (M, N).
+
+ +#### Outputs + +
+
Y : T
+
Output tensor of shape (M, N).
+
+ +#### Type Constraints + +
+
T : tensor(float16), tensor(float), tensor(double)
+
Constrain input and output types to float tensors.
+
+ +### **Greater-7** + + Returns the tensor resulted from performing the `greater` logical operation + elementwise on the input tensors `A` and `B` (with Numpy-style broadcasting support). + + This operator supports **multidirectional (i.e., Numpy-style) broadcasting**; for more details please check [the doc](Broadcasting.md). + +#### Version + +This version of the operator has been available since version 7 of the default ONNX operator set. + +#### Inputs + +
+
A : T
+
First input operand for the logical operator.
+
B : T
+
Second input operand for the logical operator.
+
+ +#### Outputs + +
+
C : T1
+
Result tensor.
+
+ +#### Type Constraints + +
+
T : tensor(float16), tensor(float), tensor(double)
+
Constrains input to float tensors.
+
T1 : tensor(bool)
+
Constrains output to boolean tensor.
+
+ +### **LSTM-7** + + Computes an one-layer LSTM. This operator is usually supported via some + custom implementation such as CuDNN. + + Notations: + + `X` - input tensor + + `i` - input gate + + `o` - output gate + + `f` - forget gate + + `c` - cell gate + + `t` - time step (t-1 means previous time step) + + `W[iofc]` - W parameter weight matrix for input, output, forget, and cell gates + + `R[iofc]` - R recurrence weight matrix for input, output, forget, and cell gates + + `Wb[iofc]` - W bias vectors for input, output, forget, and cell gates + + `Rb[iofc]` - R bias vectors for input, output, forget, and cell gates + + `P[iof]` - P peephole weight vector for input, output, and forget gates + + `WB[iofc]` - W parameter weight matrix for backward input, output, forget, and cell gates + + `RB[iofc]` - R recurrence weight matrix for backward input, output, forget, and cell gates + + `WBb[iofc]` - W bias vectors for backward input, output, forget, and cell gates + + `RBb[iofc]` - R bias vectors for backward input, output, forget, and cell gates + + `PB[iof]` - P peephole weight vector for backward input, output, and forget gates + + `H` - Hidden state + + `num_directions` - 2 if direction == bidirectional else 1 + + Activation functions: + + Relu(x) - max(0, x) + + Tanh(x) - (1 - e^{-2x})/(1 + e^{-2x}) + + Sigmoid(x) - 1/(1 + e^{-x}) + + (NOTE: Below are optional) + + Affine(x) - alpha*x + beta + + LeakyRelu(x) - x if x >= 0 else alpha * x + + ThresholdedRelu(x) - x if x >= alpha else 0 + + ScaledTanh(x) - alpha*Tanh(beta*x) + + HardSigmoid(x) - min(max(alpha*x + beta, 0), 1) + + Elu(x) - x if x >= 0 else alpha*(e^x - 1) + + Softsign(x) - x/(1 + |x|) + + Softplus(x) - log(1 + e^x) + + Equations (Default: f=Sigmoid, g=Tanh, h=Tanh): + + - it = f(Xt*(Wi^T) + Ht-1*(Ri^T) + Pi (.) Ct-1 + Wbi + Rbi) + + - ft = f(Xt*(Wf^T) + Ht-1*(Rf^T) + Pf (.) Ct-1 + Wbf + Rbf) + + - ct = g(Xt*(Wc^T) + Ht-1*(Rc^T) + Wbc + Rbc) + + - Ct = ft (.) Ct-1 + it (.) ct + + - ot = f(Xt*(Wo^T) + Ht-1*(Ro^T) + Po (.) Ct + Wbo + Rbo) + + - Ht = ot (.) h(Ct) + This operator has **optional** inputs/outputs. See [the doc](IR.md) for more details about the representation of optional arguments. An empty string may be used in the place of an actual argument's name to indicate a missing argument. Trailing optional arguments (those not followed by an argument that is present) may also be simply omitted. + +#### Version + +This version of the operator has been available since version 7 of the default ONNX operator set. + +#### Attributes + +
+
activation_alpha : list of floats
+
Optional scaling values used by some activation functions. The values are consumed in the order of activation functions, for example (f, g, h) in LSTM. Default values are the same as of corresponding ONNX operators.For example with LeakyRelu, the default alpha is 0.01.
+
activation_beta : list of floats
+
Optional scaling values used by some activation functions. The values are consumed in the order of activation functions, for example (f, g, h) in LSTM. Default values are the same as of corresponding ONNX operators.
+
activations : list of strings
+
A list of 3 (or 6 if bidirectional) activation functions for input, output, forget, cell, and hidden. The activation functions must be one of the activation functions specified above. Optional: See the equations for default if not specified.
+
clip : float
+
Cell clip threshold. Clipping bounds the elements of a tensor in the range of [-threshold, +threshold] and is applied to the input of activations. No clip if not specified.
+
direction : string (default is forward)
+
Specify if the RNN is forward, reverse, or bidirectional. Must be one of forward (default), reverse, or bidirectional.
+
hidden_size : int
+
Number of neurons in the hidden layer
+
input_forget : int (default is 0)
+
Couple the input and forget gates if 1.
+
+ +#### Inputs (3 - 8) + +
+
X : T
+
The input sequences packed (and potentially padded) into one 3-D tensor with the shape of `[seq_length, batch_size, input_size]`.
+
W : T
+
The weight tensor for the gates. Concatenation of `W[iofc]` and `WB[iofc]` (if bidirectional) along dimension 0. The tensor has shape `[num_directions, 4*hidden_size, input_size]`.
+
R : T
+
The recurrence weight tensor. Concatenation of `R[iofc]` and `RB[iofc]` (if bidirectional) along dimension 0. This tensor has shape `[num_directions, 4*hidden_size, hidden_size]`.
+
B (optional) : T
+
The bias tensor for input gate. Concatenation of `[Wb[iofc], Rb[iofc]]`, and `[WBb[iofc], RBb[iofc]]` (if bidirectional) along dimension 0. This tensor has shape `[num_directions, 8*hidden_size]`. Optional: If not specified - assumed to be 0.
+
sequence_lens (optional) : T1
+
Optional tensor specifying lengths of the sequences in a batch. If not specified - assumed all sequences in the batch to have length `seq_length`. It has shape `[batch_size]`.
+
initial_h (optional) : T
+
Optional initial value of the hidden. If not specified - assumed to be 0. It has shape `[num_directions, batch_size, hidden_size]`.
+
initial_c (optional) : T
+
Optional initial value of the cell. If not specified - assumed to be 0. It has shape `[num_directions, batch_size, hidden_size]`.
+
P (optional) : T
+
The weight tensor for peepholes. Concatenation of `P[iof]` and `PB[iof]` (if bidirectional) along dimension 0. It has shape `[num_directions, 3*hidde_size]`. Optional: If not specified - assumed to be 0.
+
+ +#### Outputs (0 - 3) + +
+
Y (optional) : T
+
A tensor that concats all the intermediate output values of the hidden. It has shape `[seq_length, num_directions, batch_size, hidden_size]`.
+
Y_h (optional) : T
+
The last output value of the hidden. It has shape `[num_directions, batch_size, hidden_size]`.
+
Y_c (optional) : T
+
The last output value of the cell. It has shape `[num_directions, batch_size, hidden_size]`.
+
+ +#### Type Constraints + +
+
T : tensor(float16), tensor(float), tensor(double)
+
Constrain input and output types to float tensors.
+
T1 : tensor(int32)
+
Constrain seq_lens to integer tensor.
+
+ +### **Less-7** + + Returns the tensor resulted from performing the `less` logical operation + elementwise on the input tensors `A` and `B` (with Numpy-style broadcasting support). + + This operator supports **multidirectional (i.e., Numpy-style) broadcasting**; for more details please check [the doc](Broadcasting.md). + +#### Version + +This version of the operator has been available since version 7 of the default ONNX operator set. + +#### Inputs + +
+
A : T
+
First input operand for the logical operator.
+
B : T
+
Second input operand for the logical operator.
+
+ +#### Outputs + +
+
C : T1
+
Result tensor.
+
+ +#### Type Constraints + +
+
T : tensor(float16), tensor(float), tensor(double)
+
Constrains input to float tensors.
+
T1 : tensor(bool)
+
Constrains output to boolean tensor.
+
+ +### **Mul-7** + + Performs element-wise binary multiplication (with Numpy-style broadcasting support). + + This operator supports **multidirectional (i.e., Numpy-style) broadcasting**; for more details please check [the doc](Broadcasting.md). + +#### Version + +This version of the operator has been available since version 7 of the default ONNX operator set. + +#### Inputs + +
+
A : T
+
First operand.
+
B : T
+
Second operand.
+
+ +#### Outputs + +
+
C : T
+
Result, has same element type as two inputs
+
+ +#### Type Constraints + +
+
T : tensor(uint32), tensor(uint64), tensor(int32), tensor(int64), tensor(float16), tensor(float), tensor(double)
+
Constrain input and output types to high-precision numeric tensors.
+
+ +### **Multinomial-7** + + Generate a tensor of samples from a multinomial distribution according to the probabilities + of each of the possible outcomes. + +#### Version + +This version of the operator has been available since version 7 of the default ONNX operator set. + +#### Attributes + +
+
dtype : int (default is 6)
+
(Optional) The data type for the elements of the output tensor, if not specified, we will use int32.
+
sample_size : int (default is 1)
+
Number of times to sample.
+
seed : float
+
(Optional) Seed to the random generator, if not specified we will auto generate one.
+
+ +#### Inputs + +
+
input : T1
+
Input tensor with shape [batch_size, class_size], where class_size is the number of all possible outcomes. Each value along the axis zero represents the unnormalized log-probability of each corresponding outcome in a batch.
+
+ +#### Outputs + +
+
output : T2
+
Output tensor with shape [batch_size, sample_size], where sample_size is the number of times to sample. Each value along the axis zero represents the outcome of the corresponding sample in a batch.
+
+ +#### Type Constraints + +
+
T1 : tensor(float16), tensor(float), tensor(double)
+
Constrain input types to float tensors.
+
T2 : tensor(int32), tensor(int64)
+
Constrain output types to integral tensors.
+
+ +### **Or-7** + + Returns the tensor resulted from performing the `or` logical operation + elementwise on the input tensors `A` and `B` (with Numpy-style broadcasting support). + + This operator supports **multidirectional (i.e., Numpy-style) broadcasting**; for more details please check [the doc](Broadcasting.md). + +#### Version + +This version of the operator has been available since version 7 of the default ONNX operator set. + +#### Inputs + +
+
A (non-differentiable) : T
+
First input operand for the logical operator.
+
B (non-differentiable) : T
+
Second input operand for the logical operator.
+
+ +#### Outputs + +
+
C (non-differentiable) : T1
+
Result tensor.
+
+ +#### Type Constraints + +
+
T : tensor(bool)
+
Constrains input to boolean tensor.
+
T1 : tensor(bool)
+
Constrains output to boolean tensor.
+
+ +### **PRelu-7** + + PRelu takes input data (Tensor) and slope tensor as input, and produces one + output data (Tensor) where the function `f(x) = slope * x for x < 0`, + `f(x) = x for x >= 0`., is applied to the data tensor elementwise. + This operator supports **unidirectional broadcasting** (tensor slope should be unidirectional broadcastable to input tensor X); for more details please check [the doc](Broadcasting.md). + +#### Version + +This version of the operator has been available since version 7 of the default ONNX operator set. + +#### Inputs + +
+
X : T
+
Input tensor
+
slope : T
+
Slope tensor. The shape of slope can be smaller then first input X; if so, its shape must be unidirectional broadcastable to X
+
+ +#### Outputs + +
+
Y : T
+
Output tensor (same size as X)
+
+ +#### Type Constraints + +
+
T : tensor(float16), tensor(float), tensor(double)
+
Constrain input and output types to float tensors.
+
+ +### **Pow-7** + + Pow takes input data (Tensor) and exponent Tensor, and + produces one output data (Tensor) where the function `f(x) = x^exponent`, + is applied to the data tensor elementwise. + This operator supports **multidirectional (i.e., Numpy-style) broadcasting**; for more details please check [the doc](Broadcasting.md). + +#### Version + +This version of the operator has been available since version 7 of the default ONNX operator set. + +#### Inputs + +
+
X : T
+
First operand, base of the exponent.
+
Y : T
+
Second operand, power of the exponent.
+
+ +#### Outputs + +
+
Z : T
+
Output tensor.
+
+ +#### Type Constraints + +
+
T : tensor(float16), tensor(float), tensor(double)
+
Constrain input and output types to float tensors.
+
+ +### **RNN-7** + + Computes an one-layer simple RNN. This operator is usually supported + via some custom implementation such as CuDNN. + + Notations: + + `X` - input tensor + + `i` - input gate + + `t` - time step (t-1 means previous time step) + + `Wi` - W parameter weight matrix for input gate + + `Ri` - R recurrence weight matrix for input gate + + `Wbi` - W parameter bias vector for input gate + + `Rbi` - R parameter bias vector for input gate + + `WBi` - W parameter weight matrix for backward input gate + + `RBi` - R recurrence weight matrix for backward input gate + + `WBbi` - WR bias vectors for backward input gate + + `RBbi` - RR bias vectors for backward input gate + + `H` - Hidden state + + `num_directions` - 2 if direction == bidirectional else 1 + + Activation functions: + + Relu(x) - max(0, x) + + Tanh(x) - (1 - e^{-2x})/(1 + e^{-2x}) + + Sigmoid(x) - 1/(1 + e^{-x}) + + (NOTE: Below are optional) + + Affine(x) - alpha*x + beta + + LeakyRelu(x) - x if x >= 0 else alpha * x + + ThresholdedRelu(x) - x if x >= alpha else 0 + + ScaledTanh(x) - alpha*Tanh(beta*x) + + HardSigmoid(x) - min(max(alpha*x + beta, 0), 1) + + Elu(x) - x if x >= 0 else alpha*(e^x - 1) + + Softsign(x) - x/(1 + |x|) + + Softplus(x) - log(1 + e^x) + + Equations (Default: f=Tanh): + + - Ht = f(Xt*(Wi^T) + Ht-1*(Ri^T) + Wbi + Rbi) + This operator has **optional** inputs/outputs. See [the doc](IR.md) for more details about the representation of optional arguments. An empty string may be used in the place of an actual argument's name to indicate a missing argument. Trailing optional arguments (those not followed by an argument that is present) may also be simply omitted. + +#### Version + +This version of the operator has been available since version 7 of the default ONNX operator set. + +#### Attributes + +
+
activation_alpha : list of floats
+
Optional scaling values used by some activation functions. The values are consumed in the order of activation functions, for example (f, g, h) in LSTM. Default values are the same as of corresponding ONNX operators.For example with LeakyRelu, the default alpha is 0.01.
+
activation_beta : list of floats
+
Optional scaling values used by some activation functions. The values are consumed in the order of activation functions, for example (f, g, h) in LSTM. Default values are the same as of corresponding ONNX operators.
+
activations : list of strings (default is ['Tanh', 'Tanh'])
+
One (or two if bidirectional) activation function for input gate. The activation function must be one of the activation functions specified above. Optional: Default `Tanh` if not specified.
+
clip : float
+
Cell clip threshold. Clipping bounds the elements of a tensor in the range of [-threshold, +threshold] and is applied to the input of activations. No clip if not specified.
+
direction : string (default is forward)
+
Specify if the RNN is forward, reverse, or bidirectional. Must be one of forward (default), reverse, or bidirectional.
+
hidden_size : int
+
Number of neurons in the hidden layer
+
+ +#### Inputs (3 - 6) + +
+
X : T
+
The input sequences packed (and potentially padded) into one 3-D tensor with the shape of `[seq_length, batch_size, input_size]`.
+
W : T
+
The weight tensor for input gate. Concatenation of `Wi` and `WBi` (if bidirectional). The tensor has shape `[num_directions, hidden_size, input_size]`.
+
R : T
+
The recurrence weight tensor. Concatenation of `Ri` and `RBi` (if bidirectional). The tensor has shape `[num_directions, hidden_size, hidden_size]`.
+
B (optional) : T
+
The bias tensor for input gate. Concatenation of `[Wbi, Rbi]` and `[WBbi, RBbi]` (if bidirectional). The tensor has shape `[num_directions, 2*hidden_size]`. Optional: If not specified - assumed to be 0.
+
sequence_lens (optional) : T1
+
Optional tensor specifying lengths of the sequences in a batch. If not specified - assumed all sequences in the batch to have length `seq_length`. It has shape `[batch_size]`.
+
initial_h (optional) : T
+
Optional initial value of the hidden. If not specified - assumed to be 0. It has shape `[num_directions, batch_size, hidden_size]`.
+
+ +#### Outputs (0 - 2) + +
+
Y (optional) : T
+
A tensor that concats all the intermediate output values of the hidden. It has shape `[seq_length, num_directions, batch_size, hidden_size]`.
+
Y_h (optional) : T
+
The last output value of the hidden. It has shape `[num_directions, batch_size, hidden_size]`.
+
+ +#### Type Constraints + +
+
T : tensor(float16), tensor(float), tensor(double)
+
Constrain input and output types to float tensors.
+
T1 : tensor(int32)
+
Constrain seq_lens to integer tensor.
+
+ +### **Sin-7** + + Calculates the sine of the given input tensor, element-wise. + +#### Version + +This version of the operator has been available since version 7 of the default ONNX operator set. + +#### Inputs + +
+
input (differentiable) : T
+
Input tensor
+
+ +#### Outputs + +
+
output (differentiable) : T
+
The sine of the input tensor computed element-wise
+
+ +#### Type Constraints + +
+
T : tensor(float16), tensor(float), tensor(double)
+
Constrain input and output types to float tensors.
+
+ +### **Sub-7** + + Performs element-wise binary subtraction (with Numpy-style broadcasting support). + + This operator supports **multidirectional (i.e., Numpy-style) broadcasting**; for more details please check [the doc](Broadcasting.md). + +#### Version + +This version of the operator has been available since version 7 of the default ONNX operator set. + +#### Inputs + +
+
A : T
+
First operand.
+
B : T
+
Second operand.
+
+ +#### Outputs + +
+
C : T
+
Result, has same element type as two inputs
+
+ +#### Type Constraints + +
+
T : tensor(uint32), tensor(uint64), tensor(int32), tensor(int64), tensor(float16), tensor(float), tensor(double)
+
Constrain input and output types to high-precision numeric tensors.
+
+ +### **Tan-7** + + Calculates the tangent of the given input tensor, element-wise. + +#### Version + +This version of the operator has been available since version 7 of the default ONNX operator set. + +#### Inputs + +
+
input (differentiable) : T
+
Input tensor
+
+ +#### Outputs + +
+
output (differentiable) : T
+
The tangent of the input tensor computed element-wise
+
+ +#### Type Constraints + +
+
T : tensor(float16), tensor(float), tensor(double)
+
Constrain input and output types to float tensors.
+
+ +### **Upsample-7** + + Upsample the input tensor. + Each dimension value of the output tensor is: + output_dimension = floor(input_dimension * scale). + +#### Version + +This version of the operator has been available since version 7 of the default ONNX operator set. + +#### Attributes + +
+
mode : string (default is nearest)
+
Two interpolation modes: nearest (default), and linear (including bilinear, trilinear, etc)
+
scales : list of floats (required)
+
The scale array along each dimension. It takes value greater than or equal to 1. The number of elements of 'scales' should be the same as the rank of input 'X'.
+
+ +#### Inputs + +
+
X : T
+
N-D tensor
+
+ +#### Outputs + +
+
Y : T
+
N-D tensor after resizing
+
+ +#### Type Constraints + +
+
T : tensor(uint8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(int8), tensor(int16), tensor(int32), tensor(int64), tensor(float16), tensor(float), tensor(double), tensor(string), tensor(bool), tensor(complex64), tensor(complex128)
+
Constrain input and output types to all tensor types.
+
+ +### **Xor-7** + + Returns the tensor resulted from performing the `xor` logical operation + elementwise on the input tensors `A` and `B` (with Numpy-style broadcasting support). + + This operator supports **multidirectional (i.e., Numpy-style) broadcasting**; for more details please check [the doc](Broadcasting.md). + +#### Version + +This version of the operator has been available since version 7 of the default ONNX operator set. + +#### Inputs + +
+
A (non-differentiable) : T
+
First input operand for the logical operator.
+
B (non-differentiable) : T
+
Second input operand for the logical operator.
+
+ +#### Outputs + +
+
C (non-differentiable) : T1
+
Result tensor.
+
+ +#### Type Constraints + +
+
T : tensor(bool)
+
Constrains input to boolean tensor.
+
T1 : tensor(bool)
+
Constrains output to boolean tensor.
+
+ +## Version 8 of the default ONNX operator set +### **Expand-8** + + Broadcast the input tensor following the given shape and the broadcast rule. + The broadcast rule is similar to numpy.array(input) * numpy.ones(shape): + Dimensions are right alignment; + Two corresponding dimension must have the same value, or one of them is equal to 1. + Also, this operator is similar to numpy.broadcast_to(input, shape), + but the major difference is numpy.broadcast_to() does not allow shape to be smaller than input.size(). + It is possible that the output.shape is not equal to shape, when some dimensions in shape is equal to 1, + or the shape.ndim < input.shape.ndim. + +#### Version + +This version of the operator has been available since version 8 of the default ONNX operator set. + +#### Inputs + +
+
input : T
+
Input tensor
+
shape : tensor(int64)
+
A 1-D tensor indicates the shape you want to expand to, following the broadcast rule
+
+ +#### Outputs + +
+
output : T
+
Output tensor
+
+ +#### Type Constraints + +
+
T : tensor(uint8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(int8), tensor(int16), tensor(int32), tensor(int64), tensor(float16), tensor(float), tensor(double), tensor(string), tensor(bool), tensor(complex64), tensor(complex128)
+
Constrain input and output types to all tensors.
+
+ +### **Max-8** + + Element-wise max of each of the input tensors (with Numpy-style broadcasting support). + All inputs and outputs must have the same data type. + This operator supports **multidirectional (i.e., Numpy-style) broadcasting**; for more details please check [the doc](Broadcasting.md). + +#### Version + +This version of the operator has been available since version 8 of the default ONNX operator set. + +#### Inputs (1 - ∞) + +
+
data_0 (variadic) : T
+
List of tensors for max.
+
+ +#### Outputs + +
+
max : T
+
Output tensor.
+
+ +#### Type Constraints + +
+
T : tensor(float16), tensor(float), tensor(double)
+
Constrain input and output types to float tensors.
+
+ +### **MaxPool-8** + + MaxPool consumes an input tensor X and applies max pooling across + the tensor according to kernel sizes, stride sizes, and pad lengths. + max pooling consisting of computing the max on all values of a + subset of the input tensor according to the kernel size and downsampling the + data into the output tensor Y for further processing. The output spatial shape will be following: + ``` + output_spatial_shape[i] = floor((input_spatial_shape[i] + pad_shape[i] - kernel_spatial_shape[i]) / strides_spatial_shape[i] + 1) + + * pad_shape[i] is sum of pads along axis i + ``` + + `auto_pad` is a DEPRECATED attribute. If you are using them currently, the output spatial shape will be following: + ``` + VALID: output_spatial_shape[i] = ceil((input_spatial_shape[i] - kernel_spatial_shape[i] + 1) / strides_spatial_shape[i]) + SAME_UPPER or SAME_LOWER: output_spatial_shape[i] = ceil(input_spatial_shape[i] / strides_spatial_shape[i]) + ``` + And pad shape will be following if `SAME_UPPER` or `SAME_LOWER`: + ``` + pad_shape[i] = (output_spatial_shape[i] - 1) * strides_spatial_shape[i] + kernel_spatial_shape[i] - input_spatial_shape[i] + ``` + The output of each pooling window is maximum number of elements exclude pad. + + +#### Version + +This version of the operator has been available since version 8 of the default ONNX operator set. + +#### Attributes + +
+
auto_pad : string (default is NOTSET)
+
auto_pad must be either NOTSET, SAME_UPPER, SAME_LOWER or VALID. Where default value is NOTSET, which means explicit padding is used. SAME_UPPER or SAME_LOWER mean pad the input so that the output spatial size match the input.In case of odd number add the extra padding at the end for SAME_UPPER and at the beginning for SAME_LOWER. VALID mean no padding.
+
kernel_shape : list of ints (required)
+
The size of the kernel along each axis.
+
pads : list of ints
+
Padding for the beginning and ending along each spatial axis, it can take any value greater than or equal to 0. The value represent the number of pixels added to the beginning and end part of the corresponding axis. `pads` format should be as follow [x1_begin, x2_begin...x1_end, x2_end,...], where xi_begin the number of pixels added at the beginning of axis `i` and xi_end, the number of pixels added at the end of axis `i`. This attribute cannot be used simultaneously with auto_pad attribute. If not present, the padding defaults to 0 along start and end of each spatial axis.
+
storage_order : int (default is 0)
+
The storage order of the tensor. 0 is row major, and 1 is column major.
+
strides : list of ints
+
Stride along each spatial axis.
+
+ +#### Inputs + +
+
X : T
+
Input data tensor from the previous operator; dimensions for image case are (N x C x H x W), where N is the batch size, C is the number of channels, and H and W are the height and the width of the data. For non image case, the dimensions are in the form of (N x C x D1 x D2 ... Dn), where N is the batch size. Optionally, if dimension denotation is in effect, the operation expects the input data tensor to arrive with the dimension denotation of [DATA_BATCH, DATA_CHANNEL, DATA_FEATURE, DATA_FEATURE ...].
+
+ +#### Outputs (1 - 2) + +
+
Y : T
+
Output data tensor from average or max pooling across the input tensor. Dimensions will vary based on various kernel, stride, and pad sizes. Floor value of the dimension is used
+
Indices (optional) : I
+
Indices tensor from max pooling across the input tensor. The dimensions of indices are the same as output tensor. The values in indices of are the indices of the selected values during pooling. The indices are computed as flatten 1-D tensor, and the indices do not consider padding. So the values in indices are in [0, N x C x D1 x ... x Dn).
+
+ +#### Type Constraints + +
+
T : tensor(float16), tensor(float), tensor(double)
+
Constrain input and output types to float tensors.
+
I : tensor(int64)
+
Constrain index tensor to int64
+
+ +### **Mean-8** + + Element-wise mean of each of the input tensors (with Numpy-style broadcasting support). + All inputs and outputs must have the same data type. + This operator supports **multidirectional (i.e., Numpy-style) broadcasting**; for more details please check [the doc](Broadcasting.md). + +#### Version + +This version of the operator has been available since version 8 of the default ONNX operator set. + +#### Inputs (1 - ∞) + +
+
data_0 (variadic) : T
+
List of tensors for mean.
+
+ +#### Outputs + +
+
mean : T
+
Output tensor.
+
+ +#### Type Constraints + +
+
T : tensor(float16), tensor(float), tensor(double)
+
Constrain input and output types to float tensors.
+
+ +### **Min-8** + + Element-wise min of each of the input tensors (with Numpy-style broadcasting support). + All inputs and outputs must have the same data type. + This operator supports **multidirectional (i.e., Numpy-style) broadcasting**; for more details please check [the doc](Broadcasting.md). + +#### Version + +This version of the operator has been available since version 8 of the default ONNX operator set. + +#### Inputs (1 - ∞) + +
+
data_0 (variadic) : T
+
List of tensors for min.
+
+ +#### Outputs + +
+
min : T
+
Output tensor.
+
+ +#### Type Constraints + +
+
T : tensor(float16), tensor(float), tensor(double)
+
Constrain input and output types to float tensors.
+
+ +### **Scan-8** + + Scan can be used to iterate over one or more scan_input tensors, + constructing zero or more scan_output tensors. It combines ideas from general recurrences, + functional programming constructs such as scan, fold, map, and zip and is intended to enable + generalizations of RNN-like constructs for sequence-to-sequence processing. + Other tensors (referred to as state_variables here) can be used to carry a state + when iterating from one element to another (similar to hidden-state in RNNs, also referred + to as loop-carried dependences in the context of loops). All these tensors are required to + have the same shape in each iteration of the loop (a restriction imposed to enable efficient + memory allocation). Many common usages involve a single scan_input tensor (where functionality + similar to scan, fold and map can be obtained). When more than one scan_input is used, + a behavior similar to zip is obtained. + + The attribute body must be a graph, specifying the computation to be performed in + every iteration. It takes as input the current values of the state_variables and + the current iterated element of the scan_inputs. It must return the (updated) values + of the state_variables and zero or more scan_output_element tensors. The values of the + scan_output_element tensors are concatenated over all the iterations to produce the + scan_output values of the scan construct (similar to the concatenated intermediate + hidden-state values of RNN-like constructs). + + The scan operation returns the final values of the state_variables as well as the + scan_outputs. + + The operation supports batching, and the batch-axis is required to be 0. + When multiple scan_input tensors are used, they must all have the same batch-size, + and they must all have the same maximum-sequence-length (the dimensionality of the + sequence axis or scan axis). The sequence axis or scan axis is required to be 1. + + The operation has an optional sequence_lens input (of shape [BATCH_SIZE]) to + allow variable length sequences of length <= the maximum-sequence-length. If this + input is not specified, all sequences are assumed to be of length equal to + maximum-sequence-length. For variable length input sequences, the scan_outputs + will consist of a sequence of same length as the input, padded to the + maximum-sequence-length. + + The optional attribute directions can be used to scan a sequence in the reverse direction. + If this attribute is omitted, all sequences are scanned in the forward direction. + A bidirectional scan be performed by specifying the same tensor input twice in the + scan_inputs, once with a forward direction, and once with a backward direction. + + Note that because of the ONNX restriction that only the last parameter of an operator can + be variadic, the initial-states and scan-inputs are listed together as one input parameter. + Similarly, the final-states and scan-outputs are listed together as one output parameter. + The attribute num_scan_inputs indicates the number M of scan-inputs. + + The behavior of + + Scan < + num_scan_inputs = m, + body = loop-body + > (sequence_lengths, init_1, ..., init_n, scan_1, ..., scan_m) + + is equivalent to the following pseudo-code: + + // T.shape[0] denotes the batch-size of T + // The batch-size of scan_1, ..., scan_m are all required to be equal + batch_size = scan_1.shape[0]; + + // scan_i.shape[1] denotes the (max) sequence-length of scan_i + // scan_i.shape[1] is required to be equal to scan_j.shape[1] for all i,j. + max_sequence_length = scan_1.shape[1]; + + for (int batch = 0; batch < batch_size; ++batch) { + // initialize state-variables + st_1 = init_1; ... st_n = init_n; + // initialize scan-output variables: [] denotes an empty tensor + scan_out_1 = []; ...; scan_out_k = []; + // identify number of iterations: + N = (sequence_lengths specified) ? sequence_lengths[batch] : max_sequence_length; + + // execute loop + for (int t = 0; t < N; ++t) { + // generate the scan-input elements: the notation T[t] indicates the sub-tensor + // of rank one less than T obtained by indexing T at position t along axis k. + si_1 = (scan_1[batch])[t]; + ... ; + si_m = (scan_m[batch])[t]; + // execute loop-body + st_1, ..., st_n, so_1, ..., so_k = loop-body(st_1, ..., st_n, si_1, ..., si_m) + // accumulate the scan-output elements + scan_out_1 = Concat(scan_out_1, so_1); ... ; scan_out_k = Concat(scan_out_k, so_k); + } + // accumulate the outputs for this batch: + bst_1[batch] = st_1; ..., bst_n[batch] = st_n; + // Note scan-outputs will have size max_sequence_length, but only first N values will be meaningful. + // The remaining values have an undefined value. + b_scan_out_1[batch] = scan_out_1; ...; b_scan_out_k[batch] = scan_out_k; + } + return bst_1, ..., bst_n, b_scan_out_1, ..., b_scan_out_k; + + + + *Sample usage: Encoding RNN using a Scan* + + The following example shows how a simple RNN over an input tensor %X, with weight tensor %Wi, + recurrence weight tensor %Ri, bias tensors %Wbi and %Rbi, and initial hidden-state %H_0 can + be encoded as a ScanLoop. Note that the loop-body is a nested graph, and it directly computes + %Wi, %Ri, %Wbi, and %Rbi (typically constants or initializers in the body graph). If these + values are computed in the outer graph, they need to be passed in as extra state_variables. + + graph rnn-encoding { + %H_0 = ... + %X = ... + %Y_h, %Y = Scan[body = , num_scan_inputs=1]("", %H_0, %X) + return %Y, %Y_h + } + + graph rnn-cell-1 ( + %H_tminus1[FLOAT, tensor] + %X_t[FLOAT, tensor] + ) { + %Wi = ... + %Ri = ... + %Wbi = ... + %Rbi = ... + %t1 = X_t * (Wi^T) + %t2 = H_tminus1*(Ri^T) + %t3 = Add(%t1, %t2) + %t4 = Add(%t3, %Wbi) + %t5 = Add(%t4, %Rbi) + %Ht = Tanh(%t5) + %Accumulate = Identity(%Ht) + return %Ht, %Accumulate + } + + +#### Version + +This version of the operator has been available since version 8 of the default ONNX operator set. + +#### Attributes + +
+
body : graph (required)
+
The graph run each iteration. It has N+M inputs: (loop state variables..., scan_input_elts...). It has N+K outputs: (loop state variables..., scan_output_elts...). Each scan_output is created by concatenating the value of the specified scan_output_elt value at the end of each iteration of the loop. It is an error if the dimensions of these values change across loop iterations.
+
directions : list of ints
+
An optional list of M flags. The i-th element of the list specifies the direction to be scanned for the i-th scan_input tensor: 0 indicates forward direction and 1 indicates reverse direction. If omitted, all scan_input tensors will be scanned in the forward direction.
+
num_scan_inputs : int (required)
+
An attribute specifying the number of scan_inputs M.
+
+ +#### Inputs (2 - ∞) + +
+
sequence_lens (optional) : I
+
Optional tensor specifying lengths of the sequences in a batch. If this input is not specified, all sequences are assumed to be of the maximum sequence length (the dimension of the sequence axis of the scan_input tensors).
+
initial_state_and_scan_inputs (variadic, heterogeneous) : V
+
Initial values of the loop's N state variables followed by M scan_inputs
+
+ +#### Outputs (1 - ∞) + +
+
final_state_and_scan_outputs (variadic, heterogeneous) : V
+
Final values of the loop's N state variables followed by K scan_outputs
+
+ +#### Type Constraints + +
+
I : tensor(int64)
+
Int64 tensor
+
V : tensor(uint8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(int8), tensor(int16), tensor(int32), tensor(int64), tensor(float16), tensor(float), tensor(double), tensor(string), tensor(bool), tensor(complex64), tensor(complex128)
+
All Tensor types
+
+ +### **Sum-8** + + Element-wise sum of each of the input tensors (with Numpy-style broadcasting support). + All inputs and outputs must have the same data type. + This operator supports **multidirectional (i.e., Numpy-style) broadcasting**; for more details please check [the doc](Broadcasting.md). + +#### Version + +This version of the operator has been available since version 8 of the default ONNX operator set. + +#### Inputs (1 - ∞) + +
+
data_0 (variadic) : T
+
List of tensors for sum.
+
+ +#### Outputs + +
+
sum : T
+
Output tensor.
+
+ +#### Type Constraints + +
+
T : tensor(float16), tensor(float), tensor(double)
+
Constrain input and output types to float tensors.
+
+ +## Version 9 of the default ONNX operator set +### **Acosh-9** + + Calculates the hyperbolic arccosine of the given input tensor element-wise. + +#### Version + +This version of the operator has been available since version 9 of the default ONNX operator set. + +#### Inputs + +
+
input (differentiable) : T
+
Input tensor
+
+ +#### Outputs + +
+
output (differentiable) : T
+
The hyperbolic arccosine values of the input tensor computed element-wise
+
+ +#### Type Constraints + +
+
T : tensor(float16), tensor(float), tensor(double)
+
Constrain input and output types to float tensors.
+
+ +### **Asinh-9** + + Calculates the hyperbolic arcsine of the given input tensor element-wise. + +#### Version + +This version of the operator has been available since version 9 of the default ONNX operator set. + +#### Inputs + +
+
input (differentiable) : T
+
Input tensor
+
+ +#### Outputs + +
+
output (differentiable) : T
+
The hyperbolic arcsine values of the input tensor computed element-wise
+
+ +#### Type Constraints + +
+
T : tensor(float16), tensor(float), tensor(double)
+
Constrain input and output types to float tensors.
+
+ +### **Atanh-9** + + Calculates the hyperbolic arctangent of the given input tensor element-wise. + +#### Version + +This version of the operator has been available since version 9 of the default ONNX operator set. + +#### Inputs + +
+
input (differentiable) : T
+
Input tensor
+
+ +#### Outputs + +
+
output (differentiable) : T
+
The hyperbolic arctangent values of the input tensor computed element-wise
+
+ +#### Type Constraints + +
+
T : tensor(float16), tensor(float), tensor(double)
+
Constrain input and output types to float tensors.
+
+ +### **BatchNormalization-9** + + Carries out batch normalization as described in the paper + https://arxiv.org/abs/1502.03167. Depending on the mode it is being run, + there are multiple cases for the number of outputs, which we list below: + + Output case #1: Y, mean, var, saved_mean, saved_var (training mode) + Output case #2: Y (test mode) + + For previous (depreciated) non-spatial cases, implementors are suggested + to flatten the input shape to (N x C*D1*D2 ..*Dn) before a BatchNormalization Op. + This operator has **optional** inputs/outputs. See [the doc](IR.md) for more details about the representation of optional arguments. An empty string may be used in the place of an actual argument's name to indicate a missing argument. Trailing optional arguments (those not followed by an argument that is present) may also be simply omitted. + +#### Version + +This version of the operator has been available since version 9 of the default ONNX operator set. + +#### Attributes + +
+
epsilon : float (default is 1e-05)
+
The epsilon value to use to avoid division by zero.
+
momentum : float (default is 0.9)
+
Factor used in computing the running mean and variance.e.g., running_mean = running_mean * momentum + mean * (1 - momentum).
+
+ +#### Inputs + +
+
X (differentiable) : T
+
Input data tensor from the previous operator; dimensions are in the form of (N x C x D1 x D2 ... Dn), where N is the batch size, C is the number of channels. Statistics are computed for every channel of C over N and D1 to Dn dimensions. For image data, input dimensions become (N x C x H x W). The op also accepts single dimension input of size N in which case C is assumed to be 1
+
scale (differentiable) : T
+
Scale tensor of shape (C).
+
B (differentiable) : T
+
Bias tensor of shape (C).
+
mean (differentiable) : T
+
running (training) or estimated (testing) mean tensor of shape (C).
+
var (differentiable) : T
+
running (training) or estimated (testing) variance tensor of shape (C).
+
+ +#### Outputs (1 - 5) + +
+
Y (differentiable) : T
+
The output tensor of the same shape as X
+
mean (optional, non-differentiable) : T
+
The running mean after the BatchNormalization operator.
+
var (optional, non-differentiable) : T
+
The running variance after the BatchNormalization operator.
+
saved_mean (optional, non-differentiable) : T
+
Saved mean used during training to speed up gradient computation.
+
saved_var (optional, non-differentiable) : T
+
Saved variance used during training to speed up gradient computation.
+
+ +#### Type Constraints + +
+
T : tensor(float16), tensor(float), tensor(double)
+
Constrain input and output types to float tensors.
+
+ +### **Cast-9** + + The operator casts the elements of a given input tensor to a data type + specified by the 'to' argument and returns an output tensor of the same size in + the converted type. The 'to' argument must be one of the data types specified + in the 'DataType' enum field in the TensorProto message. + + Casting from string tensor in plain (e.g., "3.14" and "1000") and scientific numeric representations + (e.g., "1e-5" and "1E8") to float types is supported. For example, converting string "100.5" to an integer may + result 100. There are some string literals reserved for special floating-point values; + "+INF" (and "INF"), "-INF", and "NaN" are positive infinity, negative infinity, and not-a-number, respectively. + Any string which can exactly match "+INF" in a case-insensitive way would be mapped to positive infinite. Similarly, + this case-insensitive rule is applied to "INF" and "NaN". When casting from numeric tensors + to string tensors, plain floating-point representation (such as "314.15926") would be used. + Converting non-numerical-literal string such as "Hello World!" is an undefined behavior. Cases + of converting string representing floating-point arithmetic value, such as "2.718", to INT is an undefined behavior. + + Conversion from a numerical type to any numerical type is always allowed. + User must be aware of precision loss and value change caused by range difference between two types. + For example, a 64-bit float 3.1415926459 may be round to a 32-bit float 3.141592. Similarly, converting + an integer 36 to Boolean may produce 1 because we truncate bits which can't be stored in the targeted type. + +#### Version + +This version of the operator has been available since version 9 of the default ONNX operator set. + +#### Attributes + +
+
to : int (required)
+
The data type to which the elements of the input tensor are cast. Strictly must be one of the types from DataType enum in TensorProto
+
+ +#### Inputs + +
+
input : T1
+
Input tensor to be cast.
+
+ +#### Outputs + +
+
output : T2
+
Output tensor with the same shape as input with type specified by the 'to' argument
+
+ +#### Type Constraints + +
+
T1 : tensor(float16), tensor(float), tensor(double), tensor(int8), tensor(int16), tensor(int32), tensor(int64), tensor(uint8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(bool), tensor(string)
+
Constrain input types. Casting from complex is not supported.
+
T2 : tensor(float16), tensor(float), tensor(double), tensor(int8), tensor(int16), tensor(int32), tensor(int64), tensor(uint8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(bool), tensor(string)
+
Constrain output types. Casting to complex is not supported.
+
+ +### **Compress-9** + + Selects slices from an input tensor along a given axis where condition evaluates to True for each axis index. + In case axis is not provided, input is flattened before elements are selected. + Compress behaves like numpy.compress: https://docs.scipy.org/doc/numpy/reference/generated/numpy.compress.html + + +#### Version + +This version of the operator has been available since version 9 of the default ONNX operator set. + +#### Attributes + +
+
axis : int
+
(Optional) Axis along which to take slices. If not specified, input is flattened before elements being selected.
+
+ +#### Inputs + +
+
input : T
+
Tensor of rank r >= 1.
+
condition : T1
+
Rank 1 tensor of booleans to indicate which slices or data elements to be selected. Its length can be less than the input length alone the axis or the flattened input size if axis is not specified. In such cases data slices or elements exceeding the condition length are discarded.
+
+ +#### Outputs + +
+
output : T
+
Tensor of rank r if axis is specified. Otherwise output is a Tensor of rank 1.
+
+ +#### Type Constraints + +
+
T : tensor(uint8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(int8), tensor(int16), tensor(int32), tensor(int64), tensor(float16), tensor(float), tensor(double), tensor(string), tensor(bool), tensor(complex64), tensor(complex128)
+
Constrain input and output types to all tensor types.
+
T1 : tensor(bool)
+
Constrains to boolean tensors.
+
+ +### **Constant-9** + + A constant tensor. + +#### Version + +This version of the operator has been available since version 9 of the default ONNX operator set. + +#### Attributes + +
+
value : tensor (required)
+
The value for the elements of the output tensor.
+
+ +#### Inputs + + +#### Outputs + +
+
output : T
+
Output tensor containing the same value of the provided tensor.
+
+ +#### Type Constraints + +
+
T : tensor(uint8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(int8), tensor(int16), tensor(int32), tensor(int64), tensor(float16), tensor(float), tensor(double), tensor(string), tensor(bool), tensor(complex64), tensor(complex128)
+
Constrain input and output types to all tensor types.
+
+ +### **ConstantOfShape-9** + + Generate a tensor with given value and shape. + +#### Version + +This version of the operator has been available since version 9 of the default ONNX operator set. + +#### Attributes + +
+
value : tensor
+
(Optional) The value of the output elements.Should be a one-element tensor. If not specified, it defaults to a tensor of value 0 and datatype float32
+
+ +#### Inputs + +
+
input : T1
+
1D tensor. The shape of the expected output tensor. If empty tensor is given, the output would be a scalar. All values must be >= 0.
+
+ +#### Outputs + +
+
output : T2
+
Output tensor of shape specified by 'input'.If attribute 'value' is specified, the value and datatype of the output tensor is taken from 'value'.If attribute 'value' is not specified, the value in the output defaults to 0, and the datatype defaults to float32.
+
+ +#### Type Constraints + +
+
T1 : tensor(int64)
+
Constrain input types.
+
T2 : tensor(float16), tensor(float), tensor(double), tensor(int8), tensor(int16), tensor(int32), tensor(int64), tensor(uint8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(bool)
+
Constrain output types to be numerics.
+
+ +### **Cosh-9** + + Calculates the hyperbolic cosine of the given input tensor element-wise. + +#### Version + +This version of the operator has been available since version 9 of the default ONNX operator set. + +#### Inputs + +
+
input (differentiable) : T
+
Input tensor
+
+ +#### Outputs + +
+
output (differentiable) : T
+
The hyperbolic cosine values of the input tensor computed element-wise
+
+ +#### Type Constraints + +
+
T : tensor(float16), tensor(float), tensor(double)
+
Constrain input and output types to float tensors.
+
+ +### **Erf-9** + + Computes the error function of the given input tensor element-wise. + +#### Version + +This version of the operator has been available since version 9 of the default ONNX operator set. + +#### Inputs + +
+
input : T
+
Input tensor
+
+ +#### Outputs + +
+
output : T
+
The error function of the input tensor computed element-wise. It has the same shape and type of the input.
+
+ +#### Type Constraints + +
+
T : tensor(uint8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(int8), tensor(int16), tensor(int32), tensor(int64), tensor(float16), tensor(float), tensor(double)
+
Constrain input and output types to all numeric tensors.
+
+ +### **EyeLike-9** + + Generate a 2D tensor (matrix) with ones on the diagonal and zeros everywhere else. Only 2D + tensors are supported, i.e. input T1 must be of rank 2. The shape of the output tensor is the + same as the input tensor. The data type can be specified by the 'dtype' argument. If + 'dtype' is not specified, then the type of input tensor is used. By default, the main diagonal + is populated with ones, but attribute 'k' can be used to populate upper or lower diagonals. + The 'dtype' argument must be one of the data types specified in the 'DataType' enum field in the + TensorProto message and be valid as an output type. + +#### Version + +This version of the operator has been available since version 9 of the default ONNX operator set. + +#### Attributes + +
+
dtype : int
+
(Optional) The data type for the elements of the output tensor. If not specified,the data type of the input tensor T1 is used. If input tensor T1 is also notspecified, then type defaults to 'float'.
+
k : int (default is 0)
+
(Optional) Index of the diagonal to be populated with ones. Default is 0. If T2 is the output, this op sets T2[i, i+k] = 1. k = 0 populates the main diagonal, k > 0 populates an upper diagonal, and k < 0 populates a lower diagonal.
+
+ +#### Inputs + +
+
input : T1
+
2D input tensor to copy shape, and optionally, type information from.
+
+ +#### Outputs + +
+
output : T2
+
Output tensor, same shape as input tensor T1.
+
+ +#### Type Constraints + +
+
T1 : tensor(float16), tensor(float), tensor(double), tensor(int8), tensor(int16), tensor(int32), tensor(int64), tensor(uint8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(bool)
+
Constrain input types. Strings and complex are not supported.
+
T2 : tensor(float16), tensor(float), tensor(double), tensor(int8), tensor(int16), tensor(int32), tensor(int64), tensor(uint8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(bool)
+
Constrain output types. Strings and complex are not supported.
+
+ +### **Flatten-9** + + Flattens the input tensor into a 2D matrix. If input tensor has shape + (d_0, d_1, ... d_n) then the output will have shape + (d_0 X d_1 ... d_(axis-1), d_axis X d_(axis+1) ... X dn). + +#### Version + +This version of the operator has been available since version 9 of the default ONNX operator set. + +#### Attributes + +
+
axis : int (default is 1)
+
Indicate up to which input dimensions (exclusive) should be flattened to the outer dimension of the output. The value for axis must be in the range [0, R], where R is the rank of the input tensor. When axis = 0, the shape of the output tensor is (1, (d_0 X d_1 ... d_n), where the shape of the input tensor is (d_0, d_1, ... d_n).
+
+ +#### Inputs + +
+
input : T
+
A tensor of rank >= axis.
+
+ +#### Outputs + +
+
output : T
+
A 2D tensor with the contents of the input tensor, with input dimensions up to axis flattened to the outer dimension of the output and remaining input dimensions flattened into the inner dimension of the output.
+
+ +#### Type Constraints + +
+
T : tensor(uint8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(int8), tensor(int16), tensor(int32), tensor(int64), tensor(float16), tensor(float), tensor(double), tensor(string), tensor(bool), tensor(complex64), tensor(complex128)
+
Constrain input and output to all tensor types.
+
+ +### **Gemm-9** + + General Matrix multiplication: + https://en.wikipedia.org/wiki/Basic_Linear_Algebra_Subprograms#Level_3 + + A' = transpose(A) if transA else A + + B' = transpose(B) if transB else B + + Compute Y = alpha * A' * B' + beta * C, where input tensor A has shape (M, K) or (K, M), + input tensor B has shape (K, N) or (N, K), input tensor C is broadcastable to shape (M, N), + and output tensor Y has shape (M, N). A will be transposed before doing the + computation if attribute transA is non-zero, same for B and transB. + This operator supports **unidirectional broadcasting** (tensor C should be unidirectional broadcastable to tensor A * B); for more details please check [the doc](Broadcasting.md). + +#### Version + +This version of the operator has been available since version 9 of the default ONNX operator set. + +#### Attributes + +
+
alpha : float (default is 1.0)
+
Scalar multiplier for the product of input tensors A * B.
+
beta : float (default is 1.0)
+
Scalar multiplier for input tensor C.
+
transA : int (default is 0)
+
Whether A should be transposed
+
transB : int (default is 0)
+
Whether B should be transposed
+
+ +#### Inputs + +
+
A : T
+
Input tensor A. The shape of A should be (M, K) if transA is 0, or (K, M) if transA is non-zero.
+
B : T
+
Input tensor B. The shape of B should be (K, N) if transB is 0, or (N, K) if transB is non-zero.
+
C : T
+
Input tensor C. The shape of C should be unidirectional broadcastable to (M, N).
+
+ +#### Outputs + +
+
Y : T
+
Output tensor of shape (M, N).
+
+ +#### Type Constraints + +
+
T : tensor(float16), tensor(float), tensor(double), tensor(uint32), tensor(uint64), tensor(int32), tensor(int64)
+
Constrain input and output types to float/int tensors.
+
+ +### **Greater-9** + + Returns the tensor resulted from performing the `greater` logical operation + elementwise on the input tensors `A` and `B` (with Numpy-style broadcasting support). + + This operator supports **multidirectional (i.e., Numpy-style) broadcasting**; for more details please check [the doc](Broadcasting.md). + +#### Version + +This version of the operator has been available since version 9 of the default ONNX operator set. + +#### Inputs + +
+
A : T
+
First input operand for the logical operator.
+
B : T
+
Second input operand for the logical operator.
+
+ +#### Outputs + +
+
C : T1
+
Result tensor.
+
+ +#### Type Constraints + +
+
T : tensor(uint8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(int8), tensor(int16), tensor(int32), tensor(int64), tensor(float16), tensor(float), tensor(double)
+
Constrains input types to all numeric tensors.
+
T1 : tensor(bool)
+
Constrains output to boolean tensor.
+
+ +### **IsNaN-9** + + Returns which elements of the input are NaN. + +#### Version + +This version of the operator has been available since version 9 of the default ONNX operator set. + +#### Inputs + +
+
X : T1
+
input
+
+ +#### Outputs + +
+
Y : T2
+
output
+
+ +#### Type Constraints + +
+
T1 : tensor(float16), tensor(float), tensor(double)
+
Constrain input types to float tensors.
+
T2 : tensor(bool)
+
Constrain output types to boolean tensors.
+
+ +### **Less-9** + + Returns the tensor resulted from performing the `less` logical operation + elementwise on the input tensors `A` and `B` (with Numpy-style broadcasting support). + + This operator supports **multidirectional (i.e., Numpy-style) broadcasting**; for more details please check [the doc](Broadcasting.md). + +#### Version + +This version of the operator has been available since version 9 of the default ONNX operator set. + +#### Inputs + +
+
A : T
+
First input operand for the logical operator.
+
B : T
+
Second input operand for the logical operator.
+
+ +#### Outputs + +
+
C : T1
+
Result tensor.
+
+ +#### Type Constraints + +
+
T : tensor(uint8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(int8), tensor(int16), tensor(int32), tensor(int64), tensor(float16), tensor(float), tensor(double)
+
Constrains input types to all numeric tensors.
+
T1 : tensor(bool)
+
Constrains output to boolean tensor.
+
+ +### **MatMul-9** + + Matrix product that behaves like numpy.matmul: https://docs.scipy.org/doc/numpy-1.13.0/reference/generated/numpy.matmul.html + +#### Version + +This version of the operator has been available since version 9 of the default ONNX operator set. + +#### Inputs + +
+
A : T
+
N-dimensional matrix A
+
B : T
+
N-dimensional matrix B
+
+ +#### Outputs + +
+
Y : T
+
Matrix multiply results from A * B
+
+ +#### Type Constraints + +
+
T : tensor(float16), tensor(float), tensor(double), tensor(uint32), tensor(uint64), tensor(int32), tensor(int64)
+
Constrain input and output types to float/int tensors.
+
+ +### **MaxUnpool-9** + + MaxUnpool essentially computes the partial inverse of the MaxPool op. + The input information to this op is typically the the output information from a MaxPool op. The first + input tensor X is the tensor that needs to be unpooled, which is typically the pooled tensor (first output) + from MaxPool. The second input tensor, I, contains the indices to the (locally maximal) elements corrsponding + to the elements in the first input tensor X. Input tensor I is typically the second output of the MaxPool op. + The third (optional) input is a tensor that specifies the output size of the unpooling operation. + + MaxUnpool is intended to do 'partial' inverse of the MaxPool op. 'Partial' because all the non-maximal + values from the original input to MaxPool are set to zero in the output of the MaxUnpool op. Pooling + the result of an unpooling operation should give back the original input to the unpooling op. + + MaxUnpool can produce the same output size for several input sizes, which makes unpooling op ambiguous. + The third input argument, output_size, is meant to disambiguate the op and produce output tensor of + known/predictable size. + + In addition to the inputs, MaxUnpool takes three attributes, namely kernel_shape, strides, and pads, + which define the exact unpooling op. The attributes typically have the same values as the corrsponding + pooling op that the unpooling op is trying to invert. + +#### Version + +This version of the operator has been available since version 9 of the default ONNX operator set. + +#### Attributes + +
+
kernel_shape : list of ints (required)
+
The size of the kernel along each axis.
+
pads : list of ints
+
Padding for the beginning and ending along each spatial axis, it can take any value greater than or equal to 0. The value represent the number of pixels added to the beginning and end part of the corresponding axis. `pads` format should be as follow [x1_begin, x2_begin...x1_end, x2_end,...], where xi_begin the number of pixels added at the beginning of axis `i` and xi_end, the number of pixels added at the end of axis `i`. This attribute cannot be used simultaneously with auto_pad attribute. If not present, the padding defaults to 0 along start and end of each spatial axis.
+
strides : list of ints
+
Stride along each spatial axis.
+
+ +#### Inputs (2 - 3) + +
+
X : T1
+
Input data tensor that has to be unpooled. This tensor is typically the first output of the MaxPool op.Dimensions for image case are (N x C x H x W), where N is the batch size, C is the number of channels, and H and W are the height and the width of the data. For non-image case, the dimensions are in the form of (N x C x D1 x D2 ... Dn), where N is the batch size. Optionally, if dimension denotation is in effect, the operation expects the input data tensor to arrive with the dimension denotation of [DATA_BATCH, DATA_CHANNEL, DATA_FEATURE, DATA_FEATURE ...].
+
I : T2
+
Input data tensor containing the indices corresponding to elements in the first input tensor X.This tensor is typically the second output of the MaxPool op.Dimensions must be the same as input tensor X. The indices are linear, i.e. computed considering the tensor as flattened 1-D tensor, assuming row-major storage. Also, the linear indices should not consider padding. So the values in indices are in the range [0, N x C x D1 x ... x Dn).
+
output_shape (optional) : T2
+
The shape of the output can be explicitly set which will cause pads values to be auto generated. If 'output_shape' is specified, 'pads' values are ignored.
+
+ +#### Outputs + +
+
output : T1
+
Output data tensor that contains the result of the unpooling.
+
+ +#### Type Constraints + +
+
T1 : tensor(float16), tensor(float), tensor(double)
+
Constrain input and output types to float tensors.
+
T2 : tensor(int64)
+
Constrain index tensor to int64
+
+ +### **MeanVarianceNormalization-9** + + A MeanVarianceNormalization Function: Perform mean variance normalization + on the input tensor X using formula:
``` (X-EX)/sqrt(E(X-EX)^2) ``` + +#### Version + +This version of the operator has been available since version 9 of the default ONNX operator set. + +#### Attributes + +
+
axes : list of ints (default is ['0', '2', '3'])
+
A list of integers, along which to reduce. The default is to caculate along axes [0,2,3] for calculating mean and variance along each channel. Two variables with the same C-coordinate are associated with the same mean and variance.
+
+ +#### Inputs + +
+
X : T
+
Input tensor
+
+ +#### Outputs + +
+
Y : T
+
Output tensor
+
+ +#### Type Constraints + +
+
T : tensor(float16), tensor(float), tensor(double)
+
Constrain input and output types to all numeric tensors.
+
+ +### **NonZero-9** + + Returns the indices of the elements that are non-zero + (in row-major order - by dimension). + NonZero behaves similar to numpy.nonzero: + https://docs.scipy.org/doc/numpy/reference/generated/numpy.nonzero.html + +#### Version + +This version of the operator has been available since version 9 of the default ONNX operator set. + +#### Inputs + +
+
X : T
+
input
+
+ +#### Outputs + +
+
Y : tensor(int64)
+
output
+
+ +#### Type Constraints + +
+
T : tensor(uint8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(int8), tensor(int16), tensor(int32), tensor(int64), tensor(float16), tensor(float), tensor(double), tensor(string), tensor(bool), tensor(complex64), tensor(complex128)
+
Constrain to all tensor types.
+
+ +### **OneHot-9** + + Produces a one-hot tensor based on inputs. + The locations represented by the index values in the 'indices' input tensor will have 'on_value' + and the other locations will have 'off_value' in the output tensor, where 'on_value' and 'off_value' + are specified as part of required input argument 'values', which is a two-element tensor of format + [off_value, on_value]. The rank of the output tensor will be one greater than the rank of the + input tensor. The additional dimension is for one-hot representation. The additional dimension will + be inserted at the position specified by 'axis'. If 'axis' is not specified then then additional + dimension will be inserted as the innermost dimension, i.e. axis=-1. The size of the additional + dimension is specified by required scalar input 'depth'. The type of the output tensor is the same + as the type of the 'values' input. Any entries in the 'indices' input tensor with values outside + the range [0, depth) will result in one-hot representation with all 'off_value' values in the + output tensor. + +#### Version + +This version of the operator has been available since version 9 of the default ONNX operator set. + +#### Attributes + +
+
axis : int (default is -1)
+
(Optional) Axis along which one-hot representation in added. Default: axis=-1. axis=-1 means that the additional dimension will be inserted as the innermost/last dimension in the output tensor.
+
+ +#### Inputs + +
+
indices : T1
+
Input tensor containing indices. The values must be non-negative integers. Any entries in the 'indices' input tensor with values outside the range [0, depth) will result in one-hot representation with all 'off_value' values in the output tensor.In case 'indices' is of non-integer type, the values will be casted to int64 before use.
+
depth : T2
+
Scalar specifying the number of classes in one-hot tensor. This is also the size of the one-hot dimension (specified by 'axis' attribute) added on in the output tensor. The values in the 'indices' input tensor are expected to be in the range [0, depth). In case 'depth' is of non-integer type, it will be casted to int64 before use.
+
values : T3
+
Rank 1 tensor containing exactly two elements, in the format [off_value, on_value], where 'on_value' is the value used for filling locations specified in 'indices' input tensor, and 'off_value' is the value used for filling locations other than those specified in 'indices' input tensor.
+
+ +#### Outputs + +
+
output : T3
+
Tensor of rank one greater than input tensor 'indices', i.e. rank(output) = rank(indices) + 1. The data type for the elements of the output tensor is the same as the type of input 'values' is used.
+
+ +#### Type Constraints + +
+
T1 : tensor(uint8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(int8), tensor(int16), tensor(int32), tensor(int64), tensor(float16), tensor(float), tensor(double)
+
Constrains input to only numeric types.
+
T2 : tensor(uint8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(int8), tensor(int16), tensor(int32), tensor(int64), tensor(float16), tensor(float), tensor(double)
+
Constrains input to only numeric types.
+
T3 : tensor(uint8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(int8), tensor(int16), tensor(int32), tensor(int64), tensor(float16), tensor(float), tensor(double), tensor(string), tensor(bool), tensor(complex64), tensor(complex128)
+
Constrain to any tensor type.
+
+ +### **PRelu-9** + + PRelu takes input data (Tensor) and slope tensor as input, and produces one + output data (Tensor) where the function `f(x) = slope * x for x < 0`, + `f(x) = x for x >= 0`., is applied to the data tensor elementwise. + This operator supports **unidirectional broadcasting** (tensor slope should be unidirectional broadcastable to input tensor X); for more details please check [the doc](Broadcasting.md). + +#### Version + +This version of the operator has been available since version 9 of the default ONNX operator set. + +#### Inputs + +
+
X (differentiable) : T
+
Input tensor
+
slope (differentiable) : T
+
Slope tensor. The shape of slope can be smaller then first input X; if so, its shape must be unidirectional broadcastable to X
+
+ +#### Outputs + +
+
Y (differentiable) : T
+
Output tensor (same size as X)
+
+ +#### Type Constraints + +
+
T : tensor(float16), tensor(float), tensor(double), tensor(uint32), tensor(uint64), tensor(int32), tensor(int64)
+
Constrain input and output types to float/int tensors.
+
+ +### **Scan-9** + + Scan can be used to iterate over one or more scan_input tensors, + constructing zero or more scan_output tensors. It combines ideas from general recurrences, + functional programming constructs such as scan, fold, map, and zip and is intended to enable + generalizations of RNN-like constructs for sequence-to-sequence processing. + Other tensors (referred to as state_variables here) can be used to carry a state + when iterating from one element to another (similar to hidden-state in RNNs, also referred + to as loop-carried dependences in the context of loops). + Many common usages involve a single scan_input tensor (where functionality + similar to scan, fold and map can be obtained). When more than one scan_input is used, + a behavior similar to zip is obtained. + + The attribute body must be a graph, specifying the computation to be performed in + every iteration. It takes as input the current values of the state_variables and + the current iterated element of the scan_inputs. It must return the (updated) values + of the state_variables and zero or more scan_output_element tensors. The values of the + scan_output_element tensors are concatenated over all the iterations to produce the + scan_output values of the scan construct (similar to the concatenated intermediate + hidden-state values of RNN-like constructs). All the output tensors (state_variables as + well as scan_output_element tensors) are required to have the same shape in each iteration + of the loop (a restriction imposed to enable efficient memory allocation). + + Note that the iterated element passed to the body subgraph does not have a sequence + axis. It will have a rank one less than the rank of the corresponding scan_input. + + The scan operation returns the final values of the state_variables as well as the + scan_outputs. + + The optional attribute scan_input_directions specifies the direction (forward or backward) + for each scan input. If this attribute is omitted, all sequences are scanned in the forward + direction. A bidirectional scan may be performed by specifying the same tensor input twice + in the scan_inputs, once with a forward direction, and once with a backward direction. + + The scan_output of the operation is produced by concatenating the scan_output_element + values produced by the body in each iteration. The optional attribute scan_output_directions + specifies the direction in which scan_output is constructed (by appending or prepending the + scan_output_element to scan_output in each iteration) for each scan_output. If this attribute + is omitted, the scan_output_element is appended to the scan_output in each iteration. + + The optional attribute scan_input_axes specifies the axis to be scanned for each scan_input. + If omitted, every scan_input will be scanned in axis 0. For example, if axis 0 is the + batch axis and axis 1 is the time axis (to be scanned), specify an axis value of 1. + Note that scanning a non-zero axis may be less efficient than scanning axis zero. + + The optional attribute scan_output_axes specifies the axis along which the scan_outputs + are accumulated for each scan_output. For example, if axis 1 is the time axis (to be + scanned) for both inputs and outputs, specify a scan_input axis and scan_output axis + value of 1. + + Note that because of the ONNX restriction that only the last parameter of an operator can + be variadic, the initial-states and scan-inputs are listed together as one input parameter. + Similarly, the final-states and scan-outputs are listed together as one output parameter. + The attribute num_scan_inputs indicates the number M of scan-inputs. + + The behavior of + + Scan < + num_scan_inputs = m, + body = loop-body, + scan_input_axes = [axis_1, ..., axis_m] + > (init_1, ..., init_n, scan_1, ..., scan_m) + + is equivalent to the following pseudo-code: + + // scan_i.shape[axis_i] denotes the (max) sequence-length of scan_i + // scan_i.shape[axis_i] is required to be equal to scan_j.shape[axis_j] for all i,j. + sequence_length = scan_1.shape[axis_1]; + + // initialize state-variables + st_1 = init_1; ... st_n = init_n; + // initialize scan-output variables: [] denotes an empty tensor + scan_out_1 = []; ...; scan_out_k = []; + // identify number of iterations: + + // execute loop + for (int t = 0; t < sequence_length; ++t) { + // generate the scan-input elements: the notation T[t] indicates the sub-tensor + // of rank one less than T obtained by indexing T at position t along axis k. + si_1 = scan_1[t]; + ... ; + si_m = scan_m[t]; + // execute loop-body + st_1, ..., st_n, so_1, ..., so_k = loop-body(st_1, ..., st_n, si_1, ..., si_m) + // accumulate the scan-output elements + scan_out_1 = Concat(scan_out_1, so_1); ... ; scan_out_k = Concat(scan_out_k, so_k); + } + + return st_1, ..., st_n, scan_out_1, ..., scan_out_k; + + *Sample usage: Encoding RNN using a Scan* + + The following example shows how a simple RNN over an input tensor %X, with weight tensor %Wi, + recurrence weight tensor %Ri, bias tensors %Wbi and %Rbi, and initial hidden-state %H_0 can + be encoded as a ScanLoop. Note that the loop-body is a nested graph, and it directly computes + %Wi, %Ri, %Wbi, and %Rbi (typically constants or initializers in the body graph). If these + values are computed in the outer graph, they need to be passed in as extra state_variables. + + graph rnn-encoding { + %H_0 = ... + %X = ... + %Y_h, %Y = Scan[body = , num_scan_inputs=1](%H_0, %X) + return %Y, %Y_h + } + + graph rnn-cell-1 ( + %H_tminus1[FLOAT, tensor] + %X_t[FLOAT, tensor] + ) { + %Wi = ... + %Ri = ... + %Wbi = ... + %Rbi = ... + %t1 = X_t * (Wi^T) + %t2 = H_tminus1*(Ri^T) + %t3 = Add(%t1, %t2) + %t4 = Add(%t3, %Wbi) + %t5 = Add(%t4, %Rbi) + %Ht = Tanh(%t5) + %Accumulate = Identity(%Ht) + return %Ht, %Accumulate + } + + +#### Version + +This version of the operator has been available since version 9 of the default ONNX operator set. + +#### Attributes + +
+
body : graph (required)
+
The graph run each iteration. It has N+M inputs: (loop state variables..., scan_input_elts...). It has N+K outputs: (loop state variables..., scan_output_elts...). Each scan_output is created by concatenating the value of the specified scan_output_elt value at the end of each iteration of the loop. It is an error if the dimensions of these values change across loop iterations.
+
num_scan_inputs : int (required)
+
An attribute specifying the number of scan_inputs M.
+
scan_input_axes : list of ints
+
An optional list of M flags. The i-th element of the list specifies the axis to be scanned (the sequence axis) for the i-th scan_input. If omitted, 0 will be used as the scan axis for every scan_input.
+
scan_input_directions : list of ints
+
An optional list of M flags. The i-th element of the list specifies the direction to be scanned for the i-th scan_input tensor: 0 indicates forward direction and 1 indicates reverse direction. If omitted, all scan_input tensors will be scanned in the forward direction.
+
scan_output_axes : list of ints
+
An optional list of K flags. The i-th element of the list specifies the axis for the i-th scan_output. The scan outputs are accumulated along the specified axis. If omitted, 0 will be used as the scan axis for every scan_output.
+
scan_output_directions : list of ints
+
An optional list of K flags, one for each scan_output. The i-th element of the list specifies whether the i-th scan_output should be constructed by appending or prepending a new value in each iteration: 0 indicates appending and 1 indicates prepending. If omitted, all scan_output tensors will be produced by appending a value in each iteration.
+
+ +#### Inputs (1 - ∞) + +
+
initial_state_and_scan_inputs (variadic, heterogeneous) : V
+
Initial values of the loop's N state variables followed by M scan_inputs
+
+ +#### Outputs (1 - ∞) + +
+
final_state_and_scan_outputs (variadic, heterogeneous) : V
+
Final values of the loop's N state variables followed by K scan_outputs
+
+ +#### Type Constraints + +
+
I : tensor(int64)
+
Int64 tensor
+
V : tensor(uint8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(int8), tensor(int16), tensor(int32), tensor(int64), tensor(float16), tensor(float), tensor(double), tensor(string), tensor(bool), tensor(complex64), tensor(complex128)
+
All Tensor types
+
+ +### **Scatter-9** + + Given `data`, `updates` and `indices` input tensors of rank r >= 1, write the values provided by `updates` + into the first input, `data`, along `axis` dimension of `data` (by default outer-most one as axis=0) at corresponding `indices`. + For each entry in `updates`, the target index in `data` is specified by corresponding entry in `indices` + for dimension = axis, and index in source for dimension != axis. For instance, in a 2-D tensor case, + data[indices[i][j]][j] = updates[i][j] if axis = 0, or data[i][indices[i][j]] = updates[i][j] if axis = 1, + where i and j are loop counters from 0 up to the respective size in `updates` - 1. + Example 1: + data = [ + [0.0, 0.0, 0.0], + [0.0, 0.0, 0.0], + [0.0, 0.0, 0.0], + ] + indices = [ + [1, 0, 2], + [0, 2, 1], + ] + updates = [ + [1.0, 1.1, 1.2], + [2.0, 2.1, 2.2], + ] + output = [ + [2.0, 1.1, 0.0] + [1.0, 0.0, 2.2] + [0.0, 2.1, 1.2] + ] + Example 2: + data = [[1.0, 2.0, 3.0, 4.0, 5.0]] + indices = [[1, 3]] + updates = [[1.1, 2.1]] + axis = 1 + output = [[1.0, 1.1, 3.0, 2.1, 5.0]] + +#### Version + +This version of the operator has been available since version 9 of the default ONNX operator set. + +#### Attributes + +
+
axis : int (default is 0)
+
Which axis to scatter on. Negative value means counting dimensions from the back. Accepted range is [-r, r-1]
+
+ +#### Inputs + +
+
data : T
+
Tensor of rank r >= 1.
+
indices : Tind
+
Tensor of int32/int64 indices, of r >= 1 (same rank as input).
+
updates : T
+
Tensor of rank r >=1 (same rank and shape as indices)
+
+ +#### Outputs + +
+
output : T
+
Tensor of rank r >= 1 (same rank as input).
+
+ +#### Type Constraints + +
+
T : tensor(uint8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(int8), tensor(int16), tensor(int32), tensor(int64), tensor(float16), tensor(float), tensor(double), tensor(string), tensor(bool), tensor(complex64), tensor(complex128)
+
Input and output types can be of any tensor type.
+
Tind : tensor(int32), tensor(int64)
+
Constrain indices to integer types
+
+ +### **Shrink-9** + + Shrink takes one input data (Tensor) and produces one Tensor output, + having same datatype and shape with input. It has two attributes, lambd and + bias. The formula of this operator is: If x < -lambd, y = x + bias; + If x > lambd, y = x - bias; Otherwise, y = 0. + +#### Version + +This version of the operator has been available since version 9 of the default ONNX operator set. + +#### Attributes + +
+
bias : float (default is 0.0)
+
The bias value added to output. Default is 0.
+
lambd : float (default is 0.5)
+
The lambd value for the Shrink formulation. Default is 0.5.
+
+ +#### Inputs + +
+
input (differentiable) : T
+
The input data as Tensor.
+
+ +#### Outputs + +
+
output (differentiable) : T
+
The output.
+
+ +#### Type Constraints + +
+
T : tensor(uint8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(int8), tensor(int16), tensor(int32), tensor(int64), tensor(float16), tensor(float), tensor(double)
+
Constrains input to only numeric types.
+
+ +### **Sign-9** + + Calculate the sign of the given input tensor element-wise. + If input > 0, output 1. if input < 0, output -1. if input == 0, output 0. + +#### Version + +This version of the operator has been available since version 9 of the default ONNX operator set. + +#### Inputs + +
+
input : T
+
Input tensor
+
+ +#### Outputs + +
+
output : T
+
The sign of the input tensor computed element-wise. It has the same shape and type of the input.
+
+ +#### Type Constraints + +
+
T : tensor(uint8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(int8), tensor(int16), tensor(int32), tensor(int64), tensor(float16), tensor(float), tensor(double)
+
Constrain input and output types to all numeric tensors.
+
+ +### **Sinh-9** + + Calculates the hyperbolic sine of the given input tensor element-wise. + +#### Version + +This version of the operator has been available since version 9 of the default ONNX operator set. + +#### Inputs + +
+
input (differentiable) : T
+
Input tensor
+
+ +#### Outputs + +
+
output (differentiable) : T
+
The hyperbolic sine values of the input tensor computed element-wise
+
+ +#### Type Constraints + +
+
T : tensor(float16), tensor(float), tensor(double)
+
Constrain input and output types to float tensors.
+
+ +### **TfIdfVectorizer-9** + + This transform extracts n-grams from the input sequence and save them as a vector. Input can + be either a 1-D or 2-D tensor. For 1-D input, output is the n-gram representation of that input. + For 2-D input, the output is also a 2-D tensor whose i-th row is the n-gram representation of the i-th input row. + More specifically, if input shape is [C], the corresponding output shape would be [max(ngram_indexes) + 1]. + If input shape is [N, C], this operator produces a [N, max(ngram_indexes) + 1]-tensor. + + In contrast to standard n-gram extraction, here, the indexes of extracting an n-gram from the original + sequence are not necessarily consecutive numbers. The discontinuity between indexes are controlled by the number of skips. + If the number of skips is 2, we should skip two tokens when scanning through the original sequence. + Let's consider an example. Assume that input sequence is [94, 17, 36, 12, 28] and the number of skips is 2. + The associated 2-grams are [94, 12] and [17, 28] respectively indexed by [0, 3] and [1, 4]. + If the number of skips becomes 0, the 2-grams generated are [94, 17], [17, 36], [36, 12], [12, 28] + indexed by [0, 1], [1, 2], [2, 3], [3, 4], respectively. + + The output vector (denoted by Y) stores the count of each n-gram; + Y[ngram_indexes[i]] indicates the times that the i-th n-gram is found. The attribute ngram_indexes is used to determine the mapping + between index i and the corresponding n-gram's output coordinate. If pool_int64s is [94, 17, 17, 36], ngram_indexes is [1, 0], + ngram_counts=[0, 0], then the Y[0] (first element in Y) and Y[1] (second element in Y) are the counts of [17, 36] and [94, 17], + respectively. An n-gram which cannot be found in pool_strings/pool_int64s should be ignored and has no effect on the output. + Note that we may consider all skips up to S when generating the n-grams. + + The examples used above are true if mode is "TF". If mode is "IDF", all the counts larger than 1 would be truncated to 1 and + the i-th element in weights would be used to scale (by multiplication) the count of the i-th n-gram in pool. If mode is "TFIDF", + this operator first computes the counts of all n-grams and then scale them by the associated values in the weights attribute. + + Only one of pool_strings and pool_int64s can be set. If pool_int64s is set, the input should be an integer tensor. + If pool_strings is set, the input must be a string tensor. + +#### Version + +This version of the operator has been available since version 9 of the default ONNX operator set. + +#### Attributes + +
+
max_gram_length : int (required)
+
Maximum n-gram length. If this value is 3, 3-grams will be used to generate the output.
+
max_skip_count : int (required)
+
Maximum number of items (integers/strings) to be skipped when constructing an n-gram from X. If max_skip_count=1, min_gram_length=2, max_gram_length=3, this operator may generate 2-grams with skip_count=0 and skip_count=1, and 3-grams with skip_count=0 and skip_count=1
+
min_gram_length : int (required)
+
Minimum n-gram length. If this value is 2 and max_gram_length is 3, output may contain counts of 2-grams and 3-grams.
+
mode : string (required)
+
The weighting criteria. It can be one of "TF" (term frequency), "IDF" (inverse document frequency), and "TFIDF" (the combination of TF and IDF)
+
ngram_counts : list of ints (required)
+
The starting indexes of 1-grams, 2-grams, and so on in pool. It is useful when determining the boundary between two consecutive collections of n-grams. For example, if ngram_counts is [0, 17, 36], the first index (zero-based) of 1-gram/2-gram/3-gram in pool are 0/17/36. This format is essentially identical to CSR (or CSC) sparse matrix format, and we choose to use this due to its popularity.
+
ngram_indexes : list of ints (required)
+
list of int64s (type: AttributeProto::INTS). This list is parallel to the specified 'pool_*' attribute. The i-th element in ngram_indexes indicate the coordinate of the i-th n-gram in the output tensor.
+
pool_int64s : list of ints
+
List of int64 n-grams learned from the training set. Either this or pool_strings attributes must be present but not both. It's an 1-D tensor starting with the collections of all 1-grams and ending with the collections of n-grams. The i-th element in pool stores the n-gram that should be mapped to coordinate ngram_indexes[i] in the output vector.
+
pool_strings : list of strings
+
List of strings n-grams learned from the training set. Either this or pool_int64s attributes must be present but not both. It's an 1-D tensor starting with the collections of all 1-grams and ending with the collections of n-grams. The i-th element in pool stores the n-gram that should be mapped to coordinate ngram_indexes[i] in the output vector.
+
weights : list of floats
+
list of floats. This attribute stores the weight of each n-gram in pool. The i-th element in weights is the weight of the i-th n-gram in pool. Its length equals to the size of ngram_indexes. By default, weights is an all-one tensor.This attribute is used when mode is "IDF" or "TFIDF" to scale the associated word counts.
+
+ +#### Inputs + +
+
X (non-differentiable) : T
+
Input for n-gram extraction
+
+ +#### Outputs + +
+
Y (non-differentiable) : T1
+
Ngram results
+
+ +#### Type Constraints + +
+
T : tensor(string), tensor(int32), tensor(int64)
+
Input is ether string UTF-8 or int32/int64
+
T1 : tensor(float)
+
1-D tensor of floats
+
+ +### **Upsample-9** + + Upsample the input tensor. + Each dimension value of the output tensor is: + output_dimension = floor(input_dimension * scale). + +#### Version + +This version of the operator has been available since version 9 of the default ONNX operator set. + +#### Attributes + +
+
mode : string (default is nearest)
+
Two interpolation modes: nearest (default), and linear (including bilinear, trilinear, etc)
+
+ +#### Inputs + +
+
X : T
+
N-D tensor
+
scales : tensor(float)
+
The scale array along each dimension. It takes value greater than or equal to 1. The number of elements of 'scales' should be the same as the rank of input 'X'.
+
+ +#### Outputs + +
+
Y : T
+
N-D tensor after resizing
+
+ +#### Type Constraints + +
+
T : tensor(uint8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(int8), tensor(int16), tensor(int32), tensor(int64), tensor(float16), tensor(float), tensor(double), tensor(string), tensor(bool), tensor(complex64), tensor(complex128)
+
Constrain input 'X' and output 'Y' to all tensor types.
+
+ +### **Where-9** + + Return elements, either from X or Y, depending on condition. + Where behaves like + [numpy.where](https://docs.scipy.org/doc/numpy/reference/generated/numpy.where.html) + with three parameters. + + This operator supports **multidirectional (i.e., Numpy-style) broadcasting**; for more details please check [the doc](Broadcasting.md). + +#### Version + +This version of the operator has been available since version 9 of the default ONNX operator set. + +#### Inputs + +
+
condition (non-differentiable) : B
+
When True (nonzero), yield X, otherwise yield Y
+
X (differentiable) : T
+
values selected at indices where condition is True
+
Y (differentiable) : T
+
values selected at indices where condition is False
+
+ +#### Outputs + +
+
output (differentiable) : T
+
Tensor of shape equal to the broadcasted shape of condition, X, and Y.
+
+ +#### Type Constraints + +
+
B : tensor(bool)
+
Constrain to boolean tensors.
+
T : tensor(uint8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(int8), tensor(int16), tensor(int32), tensor(int64), tensor(float16), tensor(float), tensor(double), tensor(string), tensor(bool), tensor(complex64), tensor(complex128)
+
Constrain input and output types to all tensor types.
+
+ +## Version 10 of the default ONNX operator set +### **AveragePool-10** + + AveragePool consumes an input tensor X and applies average pooling across + the tensor according to kernel sizes, stride sizes, and pad lengths. + average pooling consisting of computing the average on all values of a + subset of the input tensor according to the kernel size and downsampling the + data into the output tensor Y for further processing. The output spatial shape will be following: + ``` + output_spatial_shape[i] = floor((input_spatial_shape[i] + pad_shape[i] - kernel_spatial_shape[i]) / strides_spatial_shape[i] + 1) + ``` + or + ``` + output_spatial_shape[i] = ceil((input_spatial_shape[i] + pad_shape[i] - kernel_spatial_shape[i]) / strides_spatial_shape[i] + 1) + ``` + if ceil_mode is enabled + + ``` + * pad_shape[i] is sum of pads along axis i + ``` + + `auto_pad` is a DEPRECATED attribute. If you are using them currently, the output spatial shape will be following: + ``` + VALID: output_spatial_shape[i] = ceil((input_spatial_shape[i] - kernel_spatial_shape[i] + 1) / strides_spatial_shape[i]) + SAME_UPPER or SAME_LOWER: output_spatial_shape[i] = ceil(input_spatial_shape[i] / strides_spatial_shape[i]) + ``` + And pad shape will be following if `SAME_UPPER` or `SAME_LOWER`: + ``` + pad_shape[i] = (output_spatial_shape[i] - 1) * strides_spatial_shape[i] + kernel_spatial_shape[i] - input_spatial_shape[i] + ``` + The output of each pooling window is divided by the number of elements (exclude pad when attribute count_include_pad is zero). + + +#### Version + +This version of the operator has been available since version 10 of the default ONNX operator set. + +#### Attributes + +
+
auto_pad : string (default is NOTSET)
+
auto_pad must be either NOTSET, SAME_UPPER, SAME_LOWER or VALID. Where default value is NOTSET, which means explicit padding is used. SAME_UPPER or SAME_LOWER mean pad the input so that the output spatial size match the input.In case of odd number add the extra padding at the end for SAME_UPPER and at the beginning for SAME_LOWER. VALID mean no padding.
+
ceil_mode : int (default is 0)
+
Whether to use ceil or floor (default) to compute the output shape.
+
count_include_pad : int (default is 0)
+
Whether include pad pixels when calculating values for the edges. Default is 0, doesn't count include pad.
+
kernel_shape : list of ints (required)
+
The size of the kernel along each axis.
+
pads : list of ints
+
Padding for the beginning and ending along each spatial axis, it can take any value greater than or equal to 0. The value represent the number of pixels added to the beginning and end part of the corresponding axis. `pads` format should be as follow [x1_begin, x2_begin...x1_end, x2_end,...], where xi_begin the number of pixels added at the beginning of axis `i` and xi_end, the number of pixels added at the end of axis `i`. This attribute cannot be used simultaneously with auto_pad attribute. If not present, the padding defaults to 0 along start and end of each spatial axis.
+
strides : list of ints
+
Stride along each spatial axis.
+
+ +#### Inputs + +
+
X : T
+
Input data tensor from the previous operator; dimensions for image case are (N x C x H x W), where N is the batch size, C is the number of channels, and H and W are the height and the width of the data. For non image case, the dimensions are in the form of (N x C x D1 x D2 ... Dn), where N is the batch size. Optionally, if dimension denotation is in effect, the operation expects the input data tensor to arrive with the dimension denotation of [DATA_BATCH, DATA_CHANNEL, DATA_FEATURE, DATA_FEATURE ...].
+
+ +#### Outputs + +
+
Y : T
+
Output data tensor from average or max pooling across the input tensor. Dimensions will vary based on various kernel, stride, and pad sizes. Floor value of the dimension is used
+
+ +#### Type Constraints + +
+
T : tensor(float16), tensor(float), tensor(double)
+
Constrain input and output types to float tensors.
+
+ +### **ConvInteger-10** + + The integer convolution operator consumes an input tensor, its zero-point, a filter, and its zero-point, + and computes the output. The production MUST never overflow. The accumulation may overflow if and only if in 32 bits. + +#### Version + +This version of the operator has been available since version 10 of the default ONNX operator set. + +#### Attributes + +
+
auto_pad : string (default is NOTSET)
+
auto_pad must be either NOTSET, SAME_UPPER, SAME_LOWER or VALID. Where default value is NOTSET, which means explicit padding is used. SAME_UPPER or SAME_LOWER mean pad the input so that `output_shape[i] = ceil(input_shape[i] / strides[i])` for each axis `i`. The padding is split between the two sides equally or almost equally (depending on whether it is even or odd). In case the padding is an odd number, the extra padding is added at the end for SAME_UPPER and at the beginning for SAME_LOWER.
+
dilations : list of ints
+
dilation value along each spatial axis of the filter. If not present, the dilation defaults to 1 along each axis.
+
group : int (default is 1)
+
number of groups input channels and output channels are divided into. default is 1.
+
kernel_shape : list of ints
+
The shape of the convolution kernel. If not present, should be inferred from input 'w'.
+
pads : list of ints
+
Padding for the beginning and ending along each spatial axis, it can take any value greater than or equal to 0.The value represent the number of pixels added to the beginning and end part of the corresponding axis.`pads` format should be as follow [x1_begin, x2_begin...x1_end, x2_end,...], where xi_begin the number ofpixels added at the beginning of axis `i` and xi_end, the number of pixels added at the end of axis `i`.This attribute cannot be used simultaneously with auto_pad attribute. If not present, the padding defaultsto 0 along start and end of each spatial axis.
+
strides : list of ints
+
Stride along each spatial axis. If not present, the stride defaults to 1 along each axis.
+
+ +#### Inputs (2 - 4) + +
+
x : T1
+
Input data tensor from previous layer; has size (N x C x H x W), where N is the batch size, C is the number of channels, and H and W are the height and width. Note that this is for the 2D image. Otherwise the size is (N x C x D1 x D2 ... x Dn). Optionally, if dimension denotation is in effect, the operation expects input data tensor to arrive with the dimension denotation of [DATA_BATCH, DATA_CHANNEL, DATA_FEATURE, DATA_FEATURE ...].
+
w : T2
+
The weight tensor that will be used in the convolutions; has size (M x C/group x kH x kW), where C is the number of channels, and kH and kW are the height and width of the kernel, and M is the number of feature maps. For more than 2 dimensions, the kernel shape will be (M x C/group x k1 x k2 x ... x kn), where (k1 x k2 x ... kn) is the dimension of the kernel. Optionally, if dimension denotation is in effect, the operation expects the weight tensor to arrive with the dimension denotation of [FILTER_OUT_CHANNEL, FILTER_IN_CHANNEL, FILTER_SPATIAL, FILTER_SPATIAL ...]. X.shape[1] == (W.shape[1] * group) == C (assuming zero based indices for the shape array). Or in other words FILTER_IN_CHANNEL should be equal to DATA_CHANNEL.
+
x_zero_point (optional) : T1
+
Zero point tensor for input 'x'. It's optional and default value is 0. It's a scalar, which means a per-tensor/layer quantization.
+
w_zero_point (optional) : T2
+
Zero point tensor for input 'w'. It's optional and default value is 0. It could be a scalar or a 1-D tensor, which means a per-tensor/layer or per output channel quantization. If it's a 1-D tensor, its number of elements should be equal to the number of output channels (M)
+
+ +#### Outputs + +
+
y : T3
+
Output data tensor that contains the result of the convolution. The output dimensions are functions of the kernel size, stride size, and pad lengths.
+
+ +#### Type Constraints + +
+
T1 : tensor(int8), tensor(uint8)
+
Constrain input x and its zero point data type to 8-bit integer tensor.
+
T2 : tensor(int8), tensor(uint8)
+
Constrain input w and its zero point data type to 8-bit integer tensor.
+
T3 : tensor(int32)
+
Constrain output y data type to 32-bit integer tensor.
+
+ +### **DequantizeLinear-10** + + The linear dequantization operator. It consumes a quantized tensor, a scale, a zero point to compute the full precision tensor. + The dequantization formula is y = (x - x_zero_point) * x_scale. 'x_scale' and 'x_zero_point' are both scalars. + 'x_zero_point' and 'x' must have same type. 'x' and 'y' must have same shape. In the case of dequantizing int32, + there's no zero point (zero point is supposed to be 0). + +#### Version + +This version of the operator has been available since version 10 of the default ONNX operator set. + +#### Inputs (2 - 3) + +
+
x : T
+
N-D quantized input tensor to be de-quantized.
+
x_scale : tensor(float)
+
Scale for input 'x'. It's a scalar, which means a per-tensor/layer quantization.
+
x_zero_point (optional) : T
+
Zero point for input 'x'. It's a scalar, which means a per-tensor/layer quantization. It's optional. 0 is the default value when it's not specified.
+
+ +#### Outputs + +
+
y : tensor(float)
+
N-D full precision output tensor. It has same shape as input 'x'.
+
+ +#### Type Constraints + +
+
T : tensor(int8), tensor(uint8), tensor(int32)
+
Constrain 'x_zero_point' and 'x' to 8-bit/32-bit integer tensor.
+
+ +### **Dropout-10** + + Dropout takes one input floating tensor and produces two tensor outputs, + output (floating tensor) and mask (`Tensor`). Depending on whether it is + in test mode or not, the output Y will either be a random dropout, or a simple + copy of the input. Note that our implementation of Dropout does scaling in + the training phase, so during testing nothing needs to be done. + This operator has **optional** inputs/outputs. See [the doc](IR.md) for more details about the representation of optional arguments. An empty string may be used in the place of an actual argument's name to indicate a missing argument. Trailing optional arguments (those not followed by an argument that is present) may also be simply omitted. + +#### Version + +This version of the operator has been available since version 10 of the default ONNX operator set. + +#### Attributes + +
+
ratio : float (default is 0.5)
+
The ratio of random dropout
+
+ +#### Inputs + +
+
data : T
+
The input data as Tensor.
+
+ +#### Outputs (1 - 2) + +
+
output : T
+
The output.
+
mask (optional) : T1
+
The output mask.
+
+ +#### Type Constraints + +
+
T : tensor(float16), tensor(float), tensor(double)
+
Constrain input and output types to float tensors.
+
T1 : tensor(bool)
+
Constrain output mask types to boolean tensors.
+
+ +### **IsInf-10** + + Map infinity to true and other values to false. + +#### Version + +This version of the operator has been available since version 10 of the default ONNX operator set. + +#### Attributes + +
+
detect_negative : int (default is 1)
+
(Optional) Whether map negative infinity to true. Default to 1 so that negative infinity induces true. Set this attribute to 0 if negative infinity should be mapped to false.
+
detect_positive : int (default is 1)
+
(Optional) Whether map positive infinity to true. Default to 1 so that positive infinity induces true. Set this attribute to 0 if positive infinity should be mapped to false.
+
+ +#### Inputs + +
+
X (non-differentiable) : T1
+
input
+
+ +#### Outputs + +
+
Y (non-differentiable) : T2
+
output
+
+ +#### Type Constraints + +
+
T1 : tensor(float), tensor(double)
+
Constrain input types to float tensors.
+
T2 : tensor(bool)
+
Constrain output types to boolean tensors.
+
+ +### **MatMulInteger-10** + + Matrix product that behaves like numpy.matmul: https://docs.scipy.org/doc/numpy-1.13.0/reference/generated/numpy.matmul.html. + The production MUST never overflow. The accumulation may overflow if and only if in 32 bits. + +#### Version + +This version of the operator has been available since version 10 of the default ONNX operator set. + +#### Inputs (2 - 4) + +
+
A (non-differentiable) : T1
+
N-dimensional matrix A
+
B (non-differentiable) : T2
+
N-dimensional matrix B
+
a_zero_point (optional, non-differentiable) : T1
+
Zero point tensor for input 'A'. It's optional and default value is 0. It could be a scalar or N-D tensor. Scalar refers to per tensor quantization whereas N-D refers to per row quantization. If the input is 2D of shape [M, K] then zero point tensor may be an M element vector [zp_1, zp_2, ..., zp_M]. If the input is N-D tensor with shape [D1, D2, M, K] then zero point tensor may have shape [D1, D2, M, 1].
+
b_zero_point (optional, non-differentiable) : T2
+
Zero point tensor for input 'B'. It's optional and default value is 0. It could be a scalar or a N-D tensor, Scalar refers to per tensor quantization whereas N-D refers to per col quantization. If the input is 2D of shape [K, N] then zero point tensor may be an N element vector [zp_1, zp_2, ..., zp_N]. If the input is N-D tensor with shape [D1, D2, K, N] then zero point tensor may have shape [D1, D2, 1, N].
+
+ +#### Outputs + +
+
Y (non-differentiable) : T3
+
Matrix multiply results from A * B
+
+ +#### Type Constraints + +
+
T1 : tensor(int8), tensor(uint8)
+
Constrain input A data type to 8-bit integer tensor.
+
T2 : tensor(int8), tensor(uint8)
+
Constrain input B data type to 8-bit integer tensor.
+
T3 : tensor(int32)
+
Constrain output Y data type as 32-bit integer tensor.
+
+ +### **MaxPool-10** + + MaxPool consumes an input tensor X and applies max pooling across + the tensor according to kernel sizes, stride sizes, and pad lengths. + max pooling consisting of computing the max on all values of a + subset of the input tensor according to the kernel size and downsampling the + data into the output tensor Y for further processing. The output spatial shape will be following: + ``` + output_spatial_shape[i] = floor((input_spatial_shape[i] + pad_shape[i] - ((kernel_spatial_shape[i] - 1) * dilations[i] + 1)) / strides_spatial_shape[i] + 1) + ``` + or + ``` + output_spatial_shape[i] = ceil((input_spatial_shape[i] + pad_shape[i] - ((kernel_spatial_shape[i] - 1) * dilations[i] + 1)) / strides_spatial_shape[i] + 1) + ``` + if ceil_mode is enabled + + ``` + * pad_shape[i] is sum of pads along axis i + ``` + + `auto_pad` is a DEPRECATED attribute. If you are using them currently, the output spatial shape will be following: + ``` + VALID: output_spatial_shape[i] = ceil((input_spatial_shape[i] - ((kernel_spatial_shape[i] - 1) * dilations[i] + 1) + 1) / strides_spatial_shape[i]) + SAME_UPPER or SAME_LOWER: output_spatial_shape[i] = ceil(input_spatial_shape[i] / strides_spatial_shape[i]) + ``` + And pad shape will be following if `SAME_UPPER` or `SAME_LOWER`: + ``` + pad_shape[i] = (output_spatial_shape[i] - 1) * strides_spatial_shape[i] + ((kernel_spatial_shape[i] - 1) * dilations[i] + 1) - input_spatial_shape[i] + ``` + The output of each pooling window is maximum number of elements exclude pad. + + +#### Version + +This version of the operator has been available since version 10 of the default ONNX operator set. + +#### Attributes + +
+
auto_pad : string (default is NOTSET)
+
auto_pad must be either NOTSET, SAME_UPPER, SAME_LOWER or VALID. Where default value is NOTSET, which means explicit padding is used. SAME_UPPER or SAME_LOWER mean pad the input so that the output spatial size match the input.In case of odd number add the extra padding at the end for SAME_UPPER and at the beginning for SAME_LOWER. VALID mean no padding.
+
ceil_mode : int (default is 0)
+
Whether to use ceil or floor (default) to compute the output shape.
+
dilations : list of ints
+
Dilation value along each spatial axis of filter.
+
kernel_shape : list of ints (required)
+
The size of the kernel along each axis.
+
pads : list of ints
+
Padding for the beginning and ending along each spatial axis, it can take any value greater than or equal to 0. The value represent the number of pixels added to the beginning and end part of the corresponding axis. `pads` format should be as follow [x1_begin, x2_begin...x1_end, x2_end,...], where xi_begin the number of pixels added at the beginning of axis `i` and xi_end, the number of pixels added at the end of axis `i`. This attribute cannot be used simultaneously with auto_pad attribute. If not present, the padding defaults to 0 along start and end of each spatial axis.
+
storage_order : int (default is 0)
+
The storage order of the tensor. 0 is row major, and 1 is column major.
+
strides : list of ints
+
Stride along each spatial axis.
+
+ +#### Inputs + +
+
X : T
+
Input data tensor from the previous operator; dimensions for image case are (N x C x H x W), where N is the batch size, C is the number of channels, and H and W are the height and the width of the data. For non image case, the dimensions are in the form of (N x C x D1 x D2 ... Dn), where N is the batch size. Optionally, if dimension denotation is in effect, the operation expects the input data tensor to arrive with the dimension denotation of [DATA_BATCH, DATA_CHANNEL, DATA_FEATURE, DATA_FEATURE ...].
+
+ +#### Outputs (1 - 2) + +
+
Y : T
+
Output data tensor from average or max pooling across the input tensor. Dimensions will vary based on various kernel, stride, and pad sizes. Floor value of the dimension is used
+
Indices (optional) : I
+
Indices tensor from max pooling across the input tensor. The dimensions of indices are the same as output tensor. The values in indices of are the indices of the selected values during pooling. The indices are computed as flatten 1-D tensor, and the indices do not consider padding. So the values in indices are in [0, N x C x D1 x ... x Dn).
+
+ +#### Type Constraints + +
+
T : tensor(float16), tensor(float), tensor(double)
+
Constrain input and output types to float tensors.
+
I : tensor(int64)
+
Constrain index tensor to int64
+
+ +### **Mod-10** + + Performs element-wise binary modulus (with Numpy-style broadcasting support). + The sign of the remainder is the same as that of the Divisor. + + Mod operator can also behave like C fmod() or numpy.fmod. In this case, the sign of the remainder however, will be the same as the Dividend + (in contrast to integer mod). To force a behavior like numpy.fmod() an 'fmod' Attribute is provided. + This attribute is set to 0 by default causing the behavior to be like integer mod. + Setting this attribute to 1 causes the remainder to be calculated similar to that of numpy.fmod(). + + If the input type is floating point, then `fmod` attribute must be set to 1. + + In case of dividend being zero, the results will be platform dependent. + + This operator supports **multidirectional (i.e., Numpy-style) broadcasting**; for more details please check [the doc](Broadcasting.md). + +#### Version + +This version of the operator has been available since version 10 of the default ONNX operator set. + +#### Attributes + +
+
fmod : int (default is 0)
+
Whether the operator should behave like fmod (default=0 meaning it will do integer mods); Set this to 1 to force fmod treatment
+
+ +#### Inputs + +
+
A : T
+
Dividend tensor
+
B : T
+
Divisor tensor
+
+ +#### Outputs + +
+
C : T
+
Remainder tensor
+
+ +#### Type Constraints + +
+
T : tensor(uint8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(int8), tensor(int16), tensor(int32), tensor(int64), tensor(float16), tensor(float), tensor(double)
+
Constrain input and output types to high-precision numeric tensors.
+
+ +### **NonMaxSuppression-10** + + Filter out boxes that have high intersection-over-union (IOU) overlap with previously selected boxes. + Bounding boxes with score less than score_threshold are removed. Bounding box format is indicated by attribute center_point_box. + Note that this algorithm is agnostic to where the origin is in the coordinate system and more generally is invariant to + orthogonal transformations and translations of the coordinate system; thus translating or reflections of the coordinate system + result in the same boxes being selected by the algorithm. + The selected_indices output is a set of integers indexing into the input collection of bounding boxes representing the selected boxes. + The bounding box coordinates corresponding to the selected indices can then be obtained using the Gather or GatherND operation. + +#### Version + +This version of the operator has been available since version 10 of the default ONNX operator set. + +#### Attributes + +
+
center_point_box : int (default is 0)
+
Integer indicate the format of the box data. The default is 0. 0 - the box data is supplied as [y1, x1, y2, x2] where (y1, x1) and (y2, x2) are the coordinates of any diagonal pair of box corners and the coordinates can be provided as normalized (i.e., lying in the interval [0, 1]) or absolute. Mostly used for TF models. 1 - the box data is supplied as [x_center, y_center, width, height]. Mostly used for Pytorch models.
+
+ +#### Inputs (2 - 5) + +
+
boxes : tensor(float)
+
An input tensor with shape [num_batches, spatial_dimension, 4]. The single box data format is indicated by center_point_box.
+
scores : tensor(float)
+
An input tensor with shape [num_batches, num_classes, spatial_dimension]
+
max_output_boxes_per_class (optional) : tensor(int64)
+
Integer representing the maximum number of boxes to be selected per batch per class. It is a scalar. Default to 0, which means no output.
+
iou_threshold (optional) : tensor(float)
+
Float representing the threshold for deciding whether boxes overlap too much with respect to IOU. It is scalar. Value range [0, 1]. Default to 0.
+
score_threshold (optional) : tensor(float)
+
Float representing the threshold for deciding when to remove boxes based on score. It is a scalar.
+
+ +#### Outputs + +
+
selected_indices : tensor(int64)
+
selected indices from the boxes tensor. [num_selected_indices, 3], the selected index format is [batch_index, class_index, box_index].
+
+ +#### Type Constraints + + +### **QLinearConv-10** + + The convolution operator consumes a quantized input tensor, its scale and zero point, + a quantized filter, its scale and zero point, and output's scale and zero point, + and computes the quantized output. Each scale and zero-point pair must have same shape. + It means they must be either scalars (per tensor) or 1-D tensors (per output channel). + Each input or output and its related zero point must have same type. + When bias is present it must be quantized using scale = input scale * weight scale and + zero point as 0. + +#### Version + +This version of the operator has been available since version 10 of the default ONNX operator set. + +#### Attributes + +
+
auto_pad : string (default is NOTSET)
+
auto_pad must be either NOTSET, SAME_UPPER, SAME_LOWER or VALID. Where default value is NOTSET, which means explicit padding is used. SAME_UPPER or SAME_LOWER mean pad the input so that `output_shape[i] = ceil(input_shape[i] / strides[i])` for each axis `i`. The padding is split between the two sides equally or almost equally (depending on whether it is even or odd). In case the padding is an odd number, the extra padding is added at the end for SAME_UPPER and at the beginning for SAME_LOWER.
+
dilations : list of ints
+
dilation value along each spatial axis of the filter. If not present, the dilation defaults to 1 along each spatial axis.
+
group : int (default is 1)
+
number of groups input channels and output channels are divided into. default is 1.
+
kernel_shape : list of ints
+
The shape of the convolution kernel. If not present, should be inferred from input 'w'.
+
pads : list of ints
+
Padding for the beginning and ending along each spatial axis, it can take any value greater than or equal to 0.The value represent the number of pixels added to the beginning and end part of the corresponding axis.`pads` format should be as follow [x1_begin, x2_begin...x1_end, x2_end,...], where xi_begin the number ofpixels added at the beginning of axis `i` and xi_end, the number of pixels added at the end of axis `i`.This attribute cannot be used simultaneously with auto_pad attribute. If not present, the padding defaultsto 0 along start and end of each spatial axis.
+
strides : list of ints
+
Stride along each spatial axis. If not present, the stride defaults to 1 along each spatial axis.
+
+ +#### Inputs (8 - 9) + +
+
x : T1
+
Input data tensor from previous layer; has size (N x C x H x W), where N is the batch size, C is the number of channels, and H and W are the height and width. Note that this is for the 2D image. Otherwise the size is (N x C x D1 x D2 ... x Dn). Optionally, if dimension denotation is in effect, the operation expects input data tensor to arrive with the dimension denotation of [DATA_BATCH, DATA_CHANNEL, DATA_FEATURE, DATA_FEATURE ...].
+
x_scale : tensor(float)
+
Scale tensor for input 'x'. It's a scalar, which means a per-tensor/layer quantization.
+
x_zero_point : T1
+
Zero point tensor for input 'x'. It's a scalar, which means a per-tensor/layer quantization.
+
w : T2
+
The weight tensor that will be used in the convolutions; has size (M x C/group x kH x kW), where C is the number of channels, and kH and kW are the height and width of the kernel, and M is the number of feature maps. For more than 2 dimensions, the kernel shape will be (M x C/group x k1 x k2 x ... x kn), where (k1 x k2 x ... kn) is the dimension of the kernel. Optionally, if dimension denotation is in effect, the operation expects the weight tensor to arrive with the dimension denotation of [FILTER_OUT_CHANNEL, FILTER_IN_CHANNEL, FILTER_SPATIAL, FILTER_SPATIAL ...]. X.shape[1] == (W.shape[1] * group) == C (assuming zero based indices for the shape array). Or in other words FILTER_IN_CHANNEL should be equal to DATA_CHANNEL.
+
w_scale : tensor(float)
+
Scale tensor for input 'w'. It could be a scalar or a 1-D tensor, which means a per-tensor/layer or per output channel quantization. If it's a 1-D tensor, its number of elements should be equal to the number of output channels (M).
+
w_zero_point : T2
+
Zero point tensor for input 'w'. It could be a scalar or a 1-D tensor, which means a per-tensor/layer or per output channel quantization. If it's a 1-D tensor, its number of elements should be equal to the number of output channels (M).
+
y_scale : tensor(float)
+
Scale tensor for output 'y'. It's a scalar, which means a per-tensor/layer quantization.
+
y_zero_point : T3
+
Zero point tensor for output 'y'. It's a scalar, which means a per-tensor/layer quantization.
+
B (optional) : T4
+
Optional 1D bias to be added to the convolution, has size of M. Bias must be quantized using scale = x_scale * w_scale and zero_point = 0
+
+ +#### Outputs + +
+
y : T3
+
Output data tensor that contains the result of the convolution. The output dimensions are functions of the kernel size, stride size, and pad lengths.
+
+ +#### Type Constraints + +
+
T1 : tensor(int8), tensor(uint8)
+
Constrain input type to 8-bit integer tensor.
+
T2 : tensor(int8), tensor(uint8)
+
Constrain filter type to 8-bit integer tensor.
+
T3 : tensor(int8), tensor(uint8)
+
Constrain output type to 8-bit integer tensor.
+
T4 : tensor(int32)
+
Constrain bias type to 32-bit integer tensor.
+
+ +### **QLinearMatMul-10** + + Matrix product that behaves like numpy.matmul: https://docs.scipy.org/doc/numpy-1.13.0/reference/generated/numpy.matmul.html. + It consumes two quantized input tensors, their scales and zero points, scale and zero point of output, + and computes the quantized output. The quantization formula is y = saturate((x / y_scale) + y_zero_point). + For (x / y_scale), it is rounding to nearest ties to even. Refer to https://en.wikipedia.org/wiki/Rounding for details. + Scale and zero point must have same shape. They must be either scalar (per tensor) or N-D tensor + (per row for 'a' and per column for 'b'). Scalar refers to per tensor quantization whereas N-D refers to per row + or per column quantization. If the input is 2D of shape [M, K] then zero point and scale tensor may be + an M element vector [v_1, v_2, ..., v_M] for per row quantization and K element vector of shape [v_1, v_2, ..., v_K] + for per column quantization. If the input is N-D tensor with shape [D1, D2, M, K] then zero point and scale tensor may + have shape [D1, D2, M, 1] for per row quantization and shape [D1, D2, 1, K] for per column quantization. + Production must never overflow, and accumulation may overflow if and only if in 32 bits. + +#### Version + +This version of the operator has been available since version 10 of the default ONNX operator set. + +#### Inputs + +
+
a (non-differentiable) : T1
+
N-dimensional quantized matrix a
+
a_scale (non-differentiable) : tensor(float)
+
scale of quantized input a
+
a_zero_point (non-differentiable) : T1
+
zero point of quantized input a
+
b (non-differentiable) : T2
+
N-dimensional quantized matrix b
+
b_scale (non-differentiable) : tensor(float)
+
scale of quantized input b
+
b_zero_point (non-differentiable) : T2
+
zero point of quantized input b
+
y_scale (non-differentiable) : tensor(float)
+
scale of quantized output y
+
y_zero_point (non-differentiable) : T3
+
zero point of quantized output y
+
+ +#### Outputs + +
+
y (non-differentiable) : T3
+
Quantized matrix multiply results from a * b
+
+ +#### Type Constraints + +
+
T1 : tensor(int8), tensor(uint8)
+
Constrain input a and its zero point data type to 8-bit integer tensor.
+
T2 : tensor(int8), tensor(uint8)
+
Constrain input b and its zero point data type to 8-bit integer tensor.
+
T3 : tensor(int8), tensor(uint8)
+
Constrain output y and its zero point data type to 8-bit integer tensor.
+
+ +### **QuantizeLinear-10** + + The linear per-tensor/layer quantization operator. It consumes a high precision tensor, a scale, a zero point to compute the low precision / quantized tensor. + The quantization formula is y = saturate ((x / y_scale) + y_zero_point). For saturation, it saturates to [0, 255] if it's uint8, or [-128, 127] if it's int8. + For (x / y_scale), it's rounding to nearest ties to even. Refer to https://en.wikipedia.org/wiki/Rounding for details. 'y_zero_point' and 'y' must have same type. + +#### Version + +This version of the operator has been available since version 10 of the default ONNX operator set. + +#### Inputs (2 - 3) + +
+
x : T1
+
N-D full precision Input tensor to be quantized.
+
y_scale : tensor(float)
+
Scale for doing quantization to get 'y'. It's a scalar, which means a per-tensor/layer quantization.
+
y_zero_point (optional) : T2
+
Zero point for doing quantization to get 'y'. It's a scalar, which means a per-tensor/layer quantization. Default value is uint8 typed 0 if it's not specified.
+
+ +#### Outputs + +
+
y : T2
+
N-D quantized output tensor. It has same shape as input 'x'.
+
+ +#### Type Constraints + +
+
T1 : tensor(float), tensor(int32)
+
Constrain 'x' to float or int32 tensor.
+
T2 : tensor(int8), tensor(uint8)
+
Constrain 'y_zero_point' and 'y' to 8-bit integer tensor.
+
+ +### **Resize-10** + + Resize the input tensor. + Each dimension value of the output tensor is: + output_dimension = floor(input_dimension * scale). + +#### Version + +This version of the operator has been available since version 10 of the default ONNX operator set. + +#### Attributes + +
+
mode : string (default is nearest)
+
Two interpolation modes: nearest (default), and linear (including bilinear, trilinear, etc)
+
+ +#### Inputs + +
+
X : T
+
N-D tensor
+
scales : tensor(float)
+
The scale array along each dimension. It takes value greater than 0. If it's less than 1, it's sampling down, otherwise, it's upsampling. The number of elements of 'scales' should be the same as the rank of input 'X'.
+
+ +#### Outputs + +
+
Y : T
+
N-D tensor after resizing
+
+ +#### Type Constraints + +
+
T : tensor(uint8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(int8), tensor(int16), tensor(int32), tensor(int64), tensor(float16), tensor(float), tensor(double), tensor(string), tensor(bool), tensor(complex64), tensor(complex128)
+
Constrain input 'X' and output 'Y' to all tensor types.
+
+ +### **ReverseSequence-10** + + Reverse batch of sequences having different lengths specified by `sequence_lens`. + + For each slice i iterating on batch axis, the operator reverses the first sequence_lens[i] elements on time axis, + and copies elements whose index's beyond sequence_lens[i] to the output. So the output slice i contains reversed + sequences on the first sequence_lens[i] elements, then have original values copied for the other elements. + + Example 1: + input = [[0.0, 4.0, 8.0, 12.0], + [1.0, 5.0, 9.0, 13.0], + [2.0, 6.0, 10.0, 14.0], + [3.0, 7.0, 11.0, 15.0]] + sequence_lens = [4, 3, 2, 1] + time_axis = 0 + batch_axis = 1 + + output = [[3.0, 6.0, 9.0, 12.0], + [2.0, 5.0, 8.0, 13.0], + [1.0, 4.0, 10.0, 14.0], + [0.0, 7.0, 11.0, 15.0]] + + Example 2: + input = [[0.0, 1.0, 2.0, 3.0 ], + [4.0, 5.0, 6.0, 7.0 ], + [8.0, 9.0, 10.0, 11.0], + [12.0, 13.0, 14.0, 15.0]] + sequence_lens = [1, 2, 3, 4] + time_axis = 1 + batch_axis = 0 + + output = [[0.0, 1.0, 2.0, 3.0 ], + [5.0, 4.0, 6.0, 7.0 ], + [10.0, 9.0, 8.0, 11.0], + [15.0, 14.0, 13.0, 12.0]] + +#### Version + +This version of the operator has been available since version 10 of the default ONNX operator set. + +#### Attributes + +
+
batch_axis : int (default is 1)
+
(Optional) Specify which axis is batch axis. Must be one of 1 (default), or 0.
+
time_axis : int (default is 0)
+
(Optional) Specify which axis is time axis. Must be one of 0 (default), or 1.
+
+ +#### Inputs + +
+
input : T
+
Tensor of rank r >= 2.
+
sequence_lens : tensor(int64)
+
Tensor specifying lengths of the sequences in a batch. It has shape `[batch_size]`.
+
+ +#### Outputs + +
+
Y : T
+
Tensor with same shape of input.
+
+ +#### Type Constraints + +
+
T : tensor(uint8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(int8), tensor(int16), tensor(int32), tensor(int64), tensor(float16), tensor(float), tensor(double), tensor(string), tensor(bool), tensor(complex64), tensor(complex128)
+
Input and output types can be of any tensor type.
+
+ +### **RoiAlign-10** + + Region of Interest (RoI) align operation described in the + [Mask R-CNN paper](https://arxiv.org/abs/1703.06870). + RoiAlign consumes an input tensor X and region of interests (rois) + to apply pooling across each RoI; it produces a 4-D tensor of shape + (num_rois, C, output_height, output_width). + + RoiAlign is proposed to avoid the misalignment by removing + quantizations while converting from original image into feature + map and from feature map into RoI feature; in each ROI bin, + the value of the sampled locations are computed directly + through bilinear interpolation. + +#### Version + +This version of the operator has been available since version 10 of the default ONNX operator set. + +#### Attributes + +
+
mode : string (default is avg)
+
The pooling method. Two modes are supported: 'avg' and 'max'. Default is 'avg'.
+
output_height : int (default is 1)
+
default 1; Pooled output Y's height.
+
output_width : int (default is 1)
+
default 1; Pooled output Y's width.
+
sampling_ratio : int (default is 0)
+
Number of sampling points in the interpolation grid used to compute the output value of each pooled output bin. If > 0, then exactly sampling_ratio x sampling_ratio grid points are used. If == 0, then an adaptive number of grid points are used (computed as ceil(roi_width / output_width), and likewise for height). Default is 0.
+
spatial_scale : float (default is 1.0)
+
Multiplicative spatial scale factor to translate ROI coordinates from their input spatial scale to the scale used when pooling, i.e., spatial scale of the input feature map X relative to the input image. E.g.; default is 1.0f.
+
+ +#### Inputs + +
+
X : T1
+
Input data tensor from the previous operator; 4-D feature map of shape (N, C, H, W), where N is the batch size, C is the number of channels, and H and W are the height and the width of the data.
+
rois : T1
+
RoIs (Regions of Interest) to pool over; rois is 2-D input of shape (num_rois, 4) given as [[x1, y1, x2, y2], ...]. The RoIs' coordinates are in the coordinate system of the input image. Each coordinate set has a 1:1 correspondence with the 'batch_indices' input.
+
batch_indices : T2
+
1-D tensor of shape (num_rois,) with each element denoting the index of the corresponding image in the batch.
+
+ +#### Outputs + +
+
Y : T1
+
RoI pooled output, 4-D tensor of shape (num_rois, C, output_height, output_width). The r-th batch element Y[r-1] is a pooled feature map corresponding to the r-th RoI X[r-1].
+
+ +#### Type Constraints + +
+
T1 : tensor(float16), tensor(float), tensor(double)
+
Constrain types to float tensors.
+
T2 : tensor(int64)
+
Constrain types to int tensors.
+
+ +### **Slice-10** + + Produces a slice of the input tensor along multiple axes. Similar to numpy: + https://docs.scipy.org/doc/numpy/reference/arrays.indexing.html + Slices uses `starts`, `ends`, `axes` and `steps` inputs to specify the start and end + dimension and step for each axis in the list of axes, it uses this information to + slice the input `data` tensor. If a negative value is passed for any of the + start or end indices, it represent number of elements before the end of that + dimension. If the value passed to start or end is larger than the `n` (the + number of elements in this dimension), it represents `n`. For slicing to the + end of a dimension with unknown size, it is recommended to pass in `INT_MAX`. + If a negative value is passed for step, it represents slicing backward. + If `axes` are omitted, they are set to `[0, ..., ndim-1]`. + If `steps` are omitted, they are set to `[1, ..., 1]` of length `len(starts)` + Example 1: + data = [ + [1, 2, 3, 4], + [5, 6, 7, 8], + ] + axes = [0, 1] + starts = [1, 0] + ends = [2, 3] + steps = [1, 2] + result = [ + [5, 7], + ] + Example 2: + data = [ + [1, 2, 3, 4], + [5, 6, 7, 8], + ] + starts = [0, 1] + ends = [-1, 1000] + result = [ + [2, 3, 4], + ] + +#### Version + +This version of the operator has been available since version 10 of the default ONNX operator set. + +#### Inputs (3 - 5) + +
+
data : T
+
Tensor of data to extract slices from.
+
starts : Tind
+
1-D tensor of starting indices of corresponding axis in `axes`
+
ends : Tind
+
1-D tensor of ending indices (exclusive) of corresponding axis in `axes`
+
axes (optional) : Tind
+
1-D tensor of axes that `starts` and `ends` apply to.
+
steps (optional) : Tind
+
1-D tensor of slice step of corresponding axis in `axes`. Default to 1.
+
+ +#### Outputs + +
+
output : T
+
Sliced data tensor.
+
+ +#### Type Constraints + +
+
T : tensor(uint8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(int8), tensor(int16), tensor(int32), tensor(int64), tensor(float16), tensor(float), tensor(double), tensor(string), tensor(bool), tensor(complex64), tensor(complex128)
+
Constrain input and output types to all tensor types.
+
Tind : tensor(int32), tensor(int64)
+
Constrain indices to integer types
+
+ +### **StringNormalizer-10** + + StringNormalization performs string operations for basic cleaning. + This operator has only one input (denoted by X) and only one output + (denoted by Y). This operator first examines the elements in the X, + and removes elements specified in "stopwords" attribute. + After removing stop words, the intermediate result can be further lowercased, + uppercased, or just returned depending the "case_change_action" attribute. + This operator only accepts [C]- and [1, C]-tensor. + If all elements in X are dropped, the output will be the empty value of string tensor with shape [1] + if input shape is [C] and shape [1, 1] if input shape is [1, C]. + +#### Version + +This version of the operator has been available since version 10 of the default ONNX operator set. + +#### Attributes + +
+
case_change_action : string (default is NONE)
+
string enum that cases output to be lowercased/uppercases/unchanged. Valid values are "LOWER", "UPPER", "NONE". Default is "NONE"
+
is_case_sensitive : int (default is 0)
+
Boolean. Whether the identification of stop words in X is case-sensitive. Default is false
+
locale : string
+
Environment dependent string that denotes the locale according to which output strings needs to be upper/lowercased.Default en_US or platform specific equivalent as decided by the implementation.
+
stopwords : list of strings
+
List of stop words. If not set, no word would be removed from X.
+
+ +#### Inputs + +
+
X : tensor(string)
+
UTF-8 strings to normalize
+
+ +#### Outputs + +
+
Y : tensor(string)
+
UTF-8 Normalized strings
+
+ +#### Type Constraints + + +### **ThresholdedRelu-10** + + ThresholdedRelu takes one input data (Tensor) and produces one output data + (Tensor) where the rectified linear function, y = x for x > alpha, y = 0 otherwise, + is applied to the tensor elementwise. + +#### Version + +This version of the operator has been available since version 10 of the default ONNX operator set. + +#### Attributes + +
+
alpha : float (default is 1.0)
+
Threshold value
+
+ +#### Inputs + +
+
X (differentiable) : T
+
Input tensor
+
+ +#### Outputs + +
+
Y (differentiable) : T
+
Output tensor
+
+ +#### Type Constraints + +
+
T : tensor(float16), tensor(float), tensor(double)
+
Constrain input and output types to float tensors.
+
+ +### **TopK-10** + + Retrieve the top-K elements along a specified axis. Given an input tensor of + shape [a_1, a_2, ..., a_n, r] and integer argument k, return two outputs: + -Value tensor of shape [a_1, a_2, ..., a_{axis-1}, k, a_{axis+1}, ... a_n] + which contains the values of the top k elements along the specified axis + -Index tensor of shape [a_1, a_2, ..., a_{axis-1}, k, a_{axis+1}, ... a_n] which + contains the indices of the top k elements (original indices from the input + tensor). + + Given two equivalent values, this operator uses the indices along the axis as + a tiebreaker. That is, the element with the lower index will appear first. + +#### Version + +This version of the operator has been available since version 10 of the default ONNX operator set. + +#### Attributes + +
+
axis : int (default is -1)
+
Dimension on which to do the sort.
+
+ +#### Inputs + +
+
X : T
+
Tensor of shape [a_1, a_2, ..., a_n, r]
+
K : tensor(int64)
+
A 1-D tensor containing a single positive value corresponding to the number of top elements to retrieve
+
+ +#### Outputs + +
+
Values : T
+
Tensor of shape [a_1, a_2, ..., a_{axis-1}, k, a_{axis+1}, ... a_n] containing top K values from the input tensor
+
Indices : I
+
Tensor of shape [a_1, a_2, ..., a_{axis-1}, k, a_{axis+1}, ... a_n] containing the corresponding input tensor indices for the top K values.
+
+ +#### Type Constraints + +
+
T : tensor(float16), tensor(float), tensor(double)
+
Constrain input and output types to float tensors.
+
I : tensor(int64)
+
Constrain index tensor to int64
+
+ +### **Upsample-10** (deprecated) + + Upsample the input tensor. + Each dimension value of the output tensor is: + output_dimension = floor(input_dimension * scale). + +#### Version + +This version of the operator has been deprecated since version 10 of the default ONNX operator set. + +## Version 11 of the default ONNX operator set +### **ArgMax-11** + + Computes the indices of the max elements of the input tensor's element along the + provided axis. The resulting tensor has the same rank as the input if keepdims equal 1. + If keepdims equal 0, then the resulting tensor have the reduced dimension pruned. + The type of the output tensor is integer. + +#### Version + +This version of the operator has been available since version 11 of the default ONNX operator set. + +#### Attributes + +
+
axis : int (default is 0)
+
The axis in which to compute the arg indices. Accepted range is [-r, r-1] where r = rank(data).
+
keepdims : int (default is 1)
+
Keep the reduced dimension or not, default 1 mean keep reduced dimension.
+
+ +#### Inputs + +
+
data : T
+
An input tensor.
+
+ +#### Outputs + +
+
reduced : tensor(int64)
+
Reduced output tensor with integer data type.
+
+ +#### Type Constraints + +
+
T : tensor(uint8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(int8), tensor(int16), tensor(int32), tensor(int64), tensor(float16), tensor(float), tensor(double)
+
Constrain input and output types to all numeric tensors.
+
+ +### **ArgMin-11** + + Computes the indices of the min elements of the input tensor's element along the + provided axis. The resulting tensor has the same rank as the input if keepdims equal 1. + If keepdims equal 0, then the resulting tensor have the reduced dimension pruned. + The type of the output tensor is integer. + +#### Version + +This version of the operator has been available since version 11 of the default ONNX operator set. + +#### Attributes + +
+
axis : int (default is 0)
+
The axis in which to compute the arg indices. Accepted range is [-r, r-1] where r = rank(data).
+
keepdims : int (default is 1)
+
Keep the reduced dimension or not, default 1 mean keep reduced dimension.
+
+ +#### Inputs + +
+
data : T
+
An input tensor.
+
+ +#### Outputs + +
+
reduced : tensor(int64)
+
Reduced output tensor with integer data type.
+
+ +#### Type Constraints + +
+
T : tensor(uint8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(int8), tensor(int16), tensor(int32), tensor(int64), tensor(float16), tensor(float), tensor(double)
+
Constrain input and output types to all numeric tensors.
+
+ +### **AveragePool-11** + + AveragePool consumes an input tensor X and applies average pooling across + the tensor according to kernel sizes, stride sizes, and pad lengths. + average pooling consisting of computing the average on all values of a + subset of the input tensor according to the kernel size and downsampling the + data into the output tensor Y for further processing. The output spatial shape will be following: + ``` + output_spatial_shape[i] = floor((input_spatial_shape[i] + pad_shape[i] - kernel_spatial_shape[i]) / strides_spatial_shape[i] + 1) + ``` + or + ``` + output_spatial_shape[i] = ceil((input_spatial_shape[i] + pad_shape[i] - kernel_spatial_shape[i]) / strides_spatial_shape[i] + 1) + ``` + if ceil_mode is enabled + + ``` + * pad_shape[i] is sum of pads along axis i + ``` + + `auto_pad` is a DEPRECATED attribute. If you are using them currently, the output spatial shape will be following: + ``` + VALID: output_spatial_shape[i] = ceil((input_spatial_shape[i] - kernel_spatial_shape[i] + 1) / strides_spatial_shape[i]) + SAME_UPPER or SAME_LOWER: output_spatial_shape[i] = ceil(input_spatial_shape[i] / strides_spatial_shape[i]) + ``` + And pad shape will be following if `SAME_UPPER` or `SAME_LOWER`: + ``` + pad_shape[i] = (output_spatial_shape[i] - 1) * strides_spatial_shape[i] + kernel_spatial_shape[i] - input_spatial_shape[i] + ``` + The output of each pooling window is divided by the number of elements (exclude pad when attribute count_include_pad is zero). + + +#### Version + +This version of the operator has been available since version 11 of the default ONNX operator set. + +#### Attributes + +
+
auto_pad : string (default is NOTSET)
+
auto_pad must be either NOTSET, SAME_UPPER, SAME_LOWER or VALID. Where default value is NOTSET, which means explicit padding is used. SAME_UPPER or SAME_LOWER mean pad the input so that `output_shape[i] = ceil(input_shape[i] / strides[i])` for each axis `i`. The padding is split between the two sides equally or almost equally (depending on whether it is even or odd). In case the padding is an odd number, the extra padding is added at the end for SAME_UPPER and at the beginning for SAME_LOWER.
+
ceil_mode : int (default is 0)
+
Whether to use ceil or floor (default) to compute the output shape.
+
count_include_pad : int (default is 0)
+
Whether include pad pixels when calculating values for the edges. Default is 0, doesn't count include pad.
+
kernel_shape : list of ints (required)
+
The size of the kernel along each axis.
+
pads : list of ints
+
Padding for the beginning and ending along each spatial axis, it can take any value greater than or equal to 0. The value represent the number of pixels added to the beginning and end part of the corresponding axis. `pads` format should be as follow [x1_begin, x2_begin...x1_end, x2_end,...], where xi_begin the number of pixels added at the beginning of axis `i` and xi_end, the number of pixels added at the end of axis `i`. This attribute cannot be used simultaneously with auto_pad attribute. If not present, the padding defaults to 0 along start and end of each spatial axis.
+
strides : list of ints
+
Stride along each spatial axis. If not present, the stride defaults to 1 along each spatial axis.
+
+ +#### Inputs + +
+
X (differentiable) : T
+
Input data tensor from the previous operator; dimensions for image case are (N x C x H x W), where N is the batch size, C is the number of channels, and H and W are the height and the width of the data. For non image case, the dimensions are in the form of (N x C x D1 x D2 ... Dn), where N is the batch size. Optionally, if dimension denotation is in effect, the operation expects the input data tensor to arrive with the dimension denotation of [DATA_BATCH, DATA_CHANNEL, DATA_FEATURE, DATA_FEATURE ...].
+
+ +#### Outputs + +
+
Y (differentiable) : T
+
Output data tensor from average or max pooling across the input tensor. Dimensions will vary based on various kernel, stride, and pad sizes. Floor value of the dimension is used
+
+ +#### Type Constraints + +
+
T : tensor(float16), tensor(float), tensor(double)
+
Constrain input and output types to float tensors.
+
+ +### **BitShift-11** + + Bitwise shift operator performs element-wise operation. For each input element, if the + attribute "direction" is "RIGHT", this operator moves its binary representation toward + the right side so that the input value is effectively decreased. If the attribute "direction" + is "LEFT", bits of binary representation moves toward the left side, which results the + increase of its actual value. The input X is the tensor to be shifted and another input + Y specifies the amounts of shifting. For example, if "direction" is "Right", X is [1, 4], + and S is [1, 1], the corresponding output Z would be [0, 2]. If "direction" is "LEFT" with + X=[1, 2] and S=[1, 2], the corresponding output Y would be [2, 8]. + + Because this operator supports Numpy-style broadcasting, X's and Y's shapes are + not necessarily identical. + This operator supports **multidirectional (i.e., Numpy-style) broadcasting**; for more details please check [the doc](Broadcasting.md). + +#### Version + +This version of the operator has been available since version 11 of the default ONNX operator set. + +#### Attributes + +
+
direction : string (required)
+
Direction of moving bits. It can be either "RIGHT" (for right shift) or "LEFT" (for left shift).
+
+ +#### Inputs + +
+
X (non-differentiable) : T
+
First operand, input to be shifted.
+
Y (non-differentiable) : T
+
Second operand, amounts of shift.
+
+ +#### Outputs + +
+
Z (non-differentiable) : T
+
Output tensor
+
+ +#### Type Constraints + +
+
T : tensor(uint8), tensor(uint16), tensor(uint32), tensor(uint64)
+
Constrain input and output types to integer tensors.
+
+ +### **Clip-11** + + Clip operator limits the given input within an interval. The interval is + specified by the inputs 'min' and 'max'. They default to + numeric_limits::lowest() and numeric_limits::max(), respectively. + +#### Version + +This version of the operator has been available since version 11 of the default ONNX operator set. + +#### Inputs (1 - 3) + +
+
input : T
+
Input tensor whose elements to be clipped
+
min (optional) : T
+
Minimum value, under which element is replaced by min. It must be a scalar(tensor of empty shape).
+
max (optional) : T
+
Maximum value, above which element is replaced by max. It must be a scalar(tensor of empty shape).
+
+ +#### Outputs + +
+
output : T
+
Output tensor with clipped input elements
+
+ +#### Type Constraints + +
+
T : tensor(float16), tensor(float), tensor(double)
+
Constrain input and output types to float tensors.
+
+ +### **Compress-11** + + Selects slices from an input tensor along a given axis where condition evaluates to True for each axis index. + In case axis is not provided, input is flattened before elements are selected. + Compress behaves like numpy.compress: https://docs.scipy.org/doc/numpy/reference/generated/numpy.compress.html + + +#### Version + +This version of the operator has been available since version 11 of the default ONNX operator set. + +#### Attributes + +
+
axis : int
+
(Optional) Axis along which to take slices. If not specified, input is flattened before elements being selected. Negative value means counting dimensions from the back. Accepted range is [-r, r-1] where r = rank(input).
+
+ +#### Inputs + +
+
input (differentiable) : T
+
Tensor of rank r >= 1.
+
condition (non-differentiable) : T1
+
Rank 1 tensor of booleans to indicate which slices or data elements to be selected. Its length can be less than the input length along the axis or the flattened input size if axis is not specified. In such cases data slices or elements exceeding the condition length are discarded.
+
+ +#### Outputs + +
+
output (differentiable) : T
+
Tensor of rank r if axis is specified. Otherwise output is a Tensor of rank 1.
+
+ +#### Type Constraints + +
+
T : tensor(uint8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(int8), tensor(int16), tensor(int32), tensor(int64), tensor(float16), tensor(float), tensor(double), tensor(string), tensor(bool), tensor(complex64), tensor(complex128)
+
Constrain input and output types to all tensor types.
+
T1 : tensor(bool)
+
Constrains to boolean tensors.
+
+ +### **Concat-11** + + Concatenate a list of tensors into a single tensor. All input tensors must have the same shape, except for the dimension size of the axis to concatenate on. + +#### Version + +This version of the operator has been available since version 11 of the default ONNX operator set. + +#### Attributes + +
+
axis : int (required)
+
Which axis to concat on. A negative value means counting dimensions from the back. Accepted range is [-r, r-1] where r = rank(inputs)..
+
+ +#### Inputs (1 - ∞) + +
+
inputs (variadic) : T
+
List of tensors for concatenation
+
+ +#### Outputs + +
+
concat_result : T
+
Concatenated tensor
+
+ +#### Type Constraints + +
+
T : tensor(uint8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(int8), tensor(int16), tensor(int32), tensor(int64), tensor(float16), tensor(float), tensor(double), tensor(string), tensor(bool), tensor(complex64), tensor(complex128)
+
Constrain output types to any tensor type.
+
+ +### **ConcatFromSequence-11** + + Concatenate a sequence of tensors into a single tensor. + All input tensors must have the same shape, except for the dimension size of the axis to concatenate on. + By default 'new_axis' is 0, the behavior is similar to numpy.concatenate. + When 'new_axis' is 1, the behavior is similar to numpy.stack. + +#### Version + +This version of the operator has been available since version 11 of the default ONNX operator set. + +#### Attributes + +
+
axis : int (required)
+
Which axis to concat on. Accepted range in `[-r, r - 1]`, where `r` is the rank of input tensors. When `new_axis` is 1, accepted range is `[-r - 1, r]`.
+
new_axis : int (default is 0)
+
Insert and concatenate on a new axis or not, default 0 means do not insert new axis.
+
+ +#### Inputs + +
+
input_sequence : S
+
Sequence of tensors for concatenation
+
+ +#### Outputs + +
+
concat_result : T
+
Concatenated tensor
+
+ +#### Type Constraints + +
+
S : seq(tensor(uint8)), seq(tensor(uint16)), seq(tensor(uint32)), seq(tensor(uint64)), seq(tensor(int8)), seq(tensor(int16)), seq(tensor(int32)), seq(tensor(int64)), seq(tensor(float16)), seq(tensor(float)), seq(tensor(double)), seq(tensor(string)), seq(tensor(bool)), seq(tensor(complex64)), seq(tensor(complex128))
+
Constrain input types to any tensor type.
+
T : tensor(uint8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(int8), tensor(int16), tensor(int32), tensor(int64), tensor(float16), tensor(float), tensor(double), tensor(string), tensor(bool), tensor(complex64), tensor(complex128)
+
Constrain output types to any tensor type.
+
+ +### **Constant-11** + + A constant tensor. Exactly one of the two attributes, either value or sparse_value, + must be specified. + +#### Version + +This version of the operator has been available since version 11 of the default ONNX operator set. + +#### Attributes + +
+
sparse_value : sparse_tensor
+
The value for the elements of the output tensor in sparse format.
+
value : tensor
+
The value for the elements of the output tensor.
+
+ +#### Inputs + + +#### Outputs + +
+
output : T
+
Output tensor containing the same value of the provided tensor.
+
+ +#### Type Constraints + +
+
T : tensor(uint8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(int8), tensor(int16), tensor(int32), tensor(int64), tensor(float16), tensor(float), tensor(double), tensor(string), tensor(bool), tensor(complex64), tensor(complex128)
+
Constrain input and output types to all tensor types.
+
+ +### **Conv-11** + + The convolution operator consumes an input tensor and a filter, and + computes the output. + +#### Version + +This version of the operator has been available since version 11 of the default ONNX operator set. + +#### Attributes + +
+
auto_pad : string (default is NOTSET)
+
auto_pad must be either NOTSET, SAME_UPPER, SAME_LOWER or VALID. Where default value is NOTSET, which means explicit padding is used. SAME_UPPER or SAME_LOWER mean pad the input so that `output_shape[i] = ceil(input_shape[i] / strides[i])` for each axis `i`. The padding is split between the two sides equally or almost equally (depending on whether it is even or odd). In case the padding is an odd number, the extra padding is added at the end for SAME_UPPER and at the beginning for SAME_LOWER.
+
dilations : list of ints
+
dilation value along each spatial axis of the filter. If not present, the dilation defaults is 1 along each spatial axis.
+
group : int (default is 1)
+
number of groups input channels and output channels are divided into.
+
kernel_shape : list of ints
+
The shape of the convolution kernel. If not present, should be inferred from input W.
+
pads : list of ints
+
Padding for the beginning and ending along each spatial axis, it can take any value greater than or equal to 0. The value represent the number of pixels added to the beginning and end part of the corresponding axis. `pads` format should be as follow [x1_begin, x2_begin...x1_end, x2_end,...], where xi_begin the number of pixels added at the beginning of axis `i` and xi_end, the number of pixels added at the end of axis `i`. This attribute cannot be used simultaneously with auto_pad attribute. If not present, the padding defaults to 0 along start and end of each spatial axis.
+
strides : list of ints
+
Stride along each spatial axis. If not present, the stride defaults is 1 along each spatial axis.
+
+ +#### Inputs (2 - 3) + +
+
X (differentiable) : T
+
Input data tensor from previous layer; has size (N x C x H x W), where N is the batch size, C is the number of channels, and H and W are the height and width. Note that this is for the 2D image. Otherwise the size is (N x C x D1 x D2 ... x Dn). Optionally, if dimension denotation is in effect, the operation expects input data tensor to arrive with the dimension denotation of [DATA_BATCH, DATA_CHANNEL, DATA_FEATURE, DATA_FEATURE ...].
+
W (differentiable) : T
+
The weight tensor that will be used in the convolutions; has size (M x C/group x kH x kW), where C is the number of channels, and kH and kW are the height and width of the kernel, and M is the number of feature maps. For more than 2 dimensions, the kernel shape will be (M x C/group x k1 x k2 x ... x kn), where (k1 x k2 x ... kn) is the dimension of the kernel. Optionally, if dimension denotation is in effect, the operation expects the weight tensor to arrive with the dimension denotation of [FILTER_OUT_CHANNEL, FILTER_IN_CHANNEL, FILTER_SPATIAL, FILTER_SPATIAL ...]. Assuming zero based indices for the shape array, X.shape[1] == (W.shape[1] * group) == C and W.shape[0] mod G == 0. Or in other words FILTER_IN_CHANNEL multiplied by the number of groups should be equal to DATA_CHANNEL and the number of feature maps M should be a multiple of the number of groups G.
+
B (optional, differentiable) : T
+
Optional 1D bias to be added to the convolution, has size of M.
+
+ +#### Outputs + +
+
Y (differentiable) : T
+
Output data tensor that contains the result of the convolution. The output dimensions are functions of the kernel size, stride size, and pad lengths.
+
+ +#### Type Constraints + +
+
T : tensor(float16), tensor(float), tensor(double)
+
Constrain input and output types to float tensors.
+
+ +### **ConvTranspose-11** + + The convolution transpose operator consumes an input tensor and a filter, + and computes the output. + + If the pads parameter is provided the shape of the output is calculated via the following equation: + + 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] + + output_shape can also be explicitly specified in which case pads values are auto generated using these equations: + + total_padding[i] = stride[i] * (input_size[i] - 1) + output_padding[i] + ((kernel_shape[i] - 1) * dilations[i] + 1) - output_shape[i] + If (auto_pads == SAME_UPPER): pads[start_i] = total_padding[i]/2; pads[end_i] = total_padding[i] - (total_padding[i]/2) + Else: pads[start_i] = total_padding[i] - (total_padding[i]/2); pads[end_i] = (total_padding[i]/2). + + + +#### Version + +This version of the operator has been available since version 11 of the default ONNX operator set. + +#### Attributes + +
+
auto_pad : string (default is NOTSET)
+
auto_pad must be either NOTSET, SAME_UPPER, SAME_LOWER or VALID. Where default value is NOTSET, which means explicit padding is used. SAME_UPPER or SAME_LOWER mean pad the input so that `output_shape[i] = input_shape[i] * strides[i]` for each axis `i`. The padding is split between the two sides equally or almost equally (depending on whether it is even or odd). In case the padding is an odd number, the extra padding is added at the end for SAME_UPPER and at the beginning for SAME_LOWER.
+
dilations : list of ints
+
dilation value along each spatial axis of the filter. If not present, the dilation defaults to 1 along each spatial axis.
+
group : int (default is 1)
+
number of groups input channels and output channels are divided into.
+
kernel_shape : list of ints
+
The shape of the convolution kernel. If not present, should be inferred from input W.
+
output_padding : list of ints
+
Additional elements added to the side with higher coordinate indices in the output. Each padding value in "output_padding" must be less than the corresponding stride/dilation dimension. By default, this attribute is a zero vector. Note that this attribute doesn't directly affect the computed output values. It only controls the selection of the computed values, so changing this attribute only adds or removes output elements. If "output_shape" is explicitly provided, "output_padding" does not contribute additional size to "output_shape" but participates in the computation of the needed padding amount. This is also called adjs or adjustment in some frameworks.
+
output_shape : list of ints
+
The shape of the output can be explicitly set which will cause pads values to be auto generated. If output_shape is specified pads values are ignored. See doc for details for equations to generate pads
+
pads : list of ints
+
Padding for the beginning and ending along each spatial axis, it can take any value greater than or equal to 0. The value represent the number of pixels added to the beginning and end part of the corresponding axis. `pads` format should be as follow [x1_begin, x2_begin...x1_end, x2_end,...], where xi_begin the number of pixels added at the beginning of axis `i` and xi_end, the number of pixels added at the end of axis `i`. This attribute cannot be used simultaneously with auto_pad attribute. If not present, the padding defaults to 0 along start and end of each spatial axis.
+
strides : list of ints
+
Stride along each spatial axis. If not present, the stride defaults to 1 along each spatial axis.
+
+ +#### Inputs (2 - 3) + +
+
X (differentiable) : T
+
Input data tensor from previous layer; has size (N x C x H x W), where N is the batch size, C is the number of channels, and H and W are the height and width. Note that this is for the 2D image. Otherwise the size is (N x C x D1 x D2 ... x Dn)
+
W (differentiable) : T
+
The weight tensor that will be used in the convolutions; has size (C x M/group x kH x kW), where C is the number of channels, and kH and kW are the height and width of the kernel, and M is the number of feature maps. For more than 2 dimensions, the weight shape will be (C x M/group x k1 x k2 x ... x kn), where (k1 x k2 x ... x kn) is the dimension of the kernel. The number of channels in the output should be equal to W.shape[1] * group (assuming zero based indices of the shape array)
+
B (optional, differentiable) : T
+
Optional 1D bias to be added to the convolution, has size of M.
+
+ +#### Outputs + +
+
Y (differentiable) : T
+
Output data tensor that contains the result of the convolution. The output dimensions are functions of the kernel size, stride size, pad lengths and group count. The number of channels in the output should be equal to W.shape[1] * group (assuming zero based indices of the shape array)
+
+ +#### Type Constraints + +
+
T : tensor(float16), tensor(float), tensor(double)
+
Constrain input and output types to float tensors.
+
+ +### **CumSum-11** + + Performs cumulative sum of the input elements along the given axis. + By default, it will do the sum inclusively meaning the first element is copied as is. + Through an `exclusive` attribute, this behavior can change to exclude the first element. + It can also perform summation in the opposite direction of the axis. For that, set `reverse` attribute to 1. + + Example: + ``` + input_x = [1, 2, 3] + axis=0 + output = [1, 3, 6] + exclusive=1 + output = [0, 1, 3] + exclusive=0 + reverse=1 + output = [6, 5, 3] + exclusive=1 + reverse=1 + output = [5, 3, 0] + ``` + + +#### Version + +This version of the operator has been available since version 11 of the default ONNX operator set. + +#### Attributes + +
+
exclusive : int (default is 0)
+
If set to 1 will return exclusive sum in which the top element is not included. In other terms, if set to 1, the j-th output element would be the sum of the first (j-1) elements. Otherwise, it would be the sum of the first j elements.
+
reverse : int (default is 0)
+
If set to 1 will perform the sums in reverse direction.
+
+ +#### Inputs + +
+
x (differentiable) : T
+
An input tensor that is to be processed.
+
axis (non-differentiable) : T2
+
A 0-D tensor. Must be in the range [-rank(x), rank(x)-1]. Negative value means counting dimensions from the back.
+
+ +#### Outputs + +
+
y (differentiable) : T
+
Output tensor of the same type as 'x' with cumulative sums of the x's elements
+
+ +#### Type Constraints + +
+
T : tensor(uint32), tensor(uint64), tensor(int32), tensor(int64), tensor(float), tensor(double)
+
Input can be of any tensor type.
+
T2 : tensor(int32), tensor(int64)
+
axis tensor can be int32 or int64 only
+
+ +### **DepthToSpace-11** + + DepthToSpace rearranges (permutes) data from depth into blocks of spatial data. + This is the reverse transformation of SpaceToDepth. More specifically, this op outputs a copy of + the input tensor where values from the depth dimension are moved in spatial blocks to the height + and width dimensions. By default, `mode` = `DCR`. + In the DCR mode, elements along the depth dimension from the input tensor are rearranged in the + following order: depth, column, and then row. The output y is computed from the input x as below: + + b, c, h, w = x.shape + + tmp = np.reshape(x, [b, blocksize, blocksize, c // (blocksize**2), h, w]) + + tmp = np.transpose(tmp, [0, 3, 4, 1, 5, 2]) + + y = np.reshape(tmp, [b, c // (blocksize**2), h * blocksize, w * blocksize]) + + + In the CRD mode, elements along the depth dimension from the input tensor are rearranged in the + following order: column, row, and the depth. The output y is computed from the input x as below: + + b, c, h, w = x.shape + + tmp = np.reshape(x, [b, c // (blocksize ** 2), blocksize, blocksize, h, w]) + + tmp = np.transpose(tmp, [0, 1, 4, 2, 5, 3]) + + y = np.reshape(tmp, [b, c // (blocksize ** 2), h * blocksize, w * blocksize]) + + +#### Version + +This version of the operator has been available since version 11 of the default ONNX operator set. + +#### Attributes + +
+
blocksize : int (required)
+
Blocks of [blocksize, blocksize] are moved.
+
mode : string (default is DCR)
+
DCR (default) for depth-column-row order re-arrangement. Use CRD for column-row-depth order.
+
+ +#### Inputs + +
+
input : T
+
Input tensor of [N,C,H,W], where N is the batch axis, C is the channel or depth, H is the height and W is the width.
+
+ +#### Outputs + +
+
output : T
+
Output tensor of [N, C/(blocksize * blocksize), H * blocksize, W * blocksize].
+
+ +#### Type Constraints + +
+
T : tensor(uint8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(int8), tensor(int16), tensor(int32), tensor(int64), tensor(float16), tensor(float), tensor(double), tensor(string), tensor(bool), tensor(complex64), tensor(complex128)
+
Constrain input and output types to all tensor types.
+
+ +### **Det-11** + + Det calculates determinant of a square matrix or batches of square matrices. + Det takes one input tensor of shape `[*, M, M]`, where `*` is zero or more batch dimensions, + and the inner-most 2 dimensions form square matrices. + The output is a tensor of shape `[*]`, containing the determinants of all input submatrices. + e.g., When the input is 2-D, the output is a scalar(shape is empty: `[]`). + +#### Version + +This version of the operator has been available since version 11 of the default ONNX operator set. + +#### Inputs + +
+
X (differentiable) : T
+
Input tensor
+
+ +#### Outputs + +
+
Y (differentiable) : T
+
Output tensor
+
+ +#### Type Constraints + +
+
T : tensor(float16), tensor(float), tensor(double)
+
Constrain input and output types to floating-point tensors.
+
+ +### **DynamicQuantizeLinear-11** + + A Function to fuse calculation for Scale, Zero Point and FP32->8Bit convertion of FP32 Input data. + Outputs Scale, ZeroPoint and Quantized Input for a given FP32 Input. + Scale is calculated as: + ``` + y_scale = (max(x) - min(x))/(qmax - qmin) + * where qmax and qmin are max and min values for quantization range .i.e [0, 255] in case of uint8 + * data range is adjusted to include 0. + ``` + Zero point is calculated as: + ``` + intermediate_zero_point = qmin - min(x)/y_scale + y_zero_point = cast(round(saturate(itermediate_zero_point))) + * where qmax and qmin are max and min values for quantization range .i.e [0, 255] in case of uint8 + * for saturation, it saturates to [0, 255] if it's uint8, or [-127, 127] if it's int8. Right now only uint8 is supported. + * rounding to nearest ties to even. + ``` + Data quantization formula is: + ``` + y = saturate (round (x / y_scale) + y_zero_point) + * for saturation, it saturates to [0, 255] if it's uint8, or [-127, 127] if it's int8. Right now only uint8 is supported. + * rounding to nearest ties to even. + ``` + +#### Version + +This version of the operator has been available since version 11 of the default ONNX operator set. + +#### Inputs + +
+
x : T1
+
Input tensor
+
+ +#### Outputs + +
+
y : T2
+
Quantized output tensor
+
y_scale : tensor(float)
+
Output scale. It's a scalar, which means a per-tensor/layer quantization.
+
y_zero_point : T2
+
Output zero point. It's a scalar, which means a per-tensor/layer quantization.
+
+ +#### Type Constraints + +
+
T1 : tensor(float)
+
Constrain 'x' to float tensor.
+
T2 : tensor(uint8)
+
Constrain 'y_zero_point' and 'y' to 8-bit unsigned integer tensor.
+
+ +### **Equal-11** + + Returns the tensor resulted from performing the `equal` logical operation + elementwise on the input tensors `A` and `B` (with Numpy-style broadcasting support). + + This operator supports **multidirectional (i.e., Numpy-style) broadcasting**; for more details please check [the doc](Broadcasting.md). + +#### Version + +This version of the operator has been available since version 11 of the default ONNX operator set. + +#### Inputs + +
+
A : T
+
First input operand for the logical operator.
+
B : T
+
Second input operand for the logical operator.
+
+ +#### Outputs + +
+
C : T1
+
Result tensor.
+
+ +#### Type Constraints + +
+
T : tensor(bool), tensor(uint8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(int8), tensor(int16), tensor(int32), tensor(int64), tensor(float16), tensor(float), tensor(double)
+
Constrains input types to all numeric tensors.
+
T1 : tensor(bool)
+
Constrains output to boolean tensor.
+
+ +### **Flatten-11** + + Flattens the input tensor into a 2D matrix. If input tensor has shape + (d_0, d_1, ... d_n) then the output will have shape + (d_0 X d_1 ... d_(axis-1), d_axis X d_(axis+1) ... X dn). + +#### Version + +This version of the operator has been available since version 11 of the default ONNX operator set. + +#### Attributes + +
+
axis : int (default is 1)
+
Indicate up to which input dimensions (exclusive) should be flattened to the outer dimension of the output. The value for axis must be in the range [-r, r], where r is the rank of the input tensor. Negative value means counting dimensions from the back. When axis = 0, the shape of the output tensor is (1, (d_0 X d_1 ... d_n), where the shape of the input tensor is (d_0, d_1, ... d_n).
+
+ +#### Inputs + +
+
input : T
+
A tensor of rank >= axis.
+
+ +#### Outputs + +
+
output : T
+
A 2D tensor with the contents of the input tensor, with input dimensions up to axis flattened to the outer dimension of the output and remaining input dimensions flattened into the inner dimension of the output.
+
+ +#### Type Constraints + +
+
T : tensor(uint8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(int8), tensor(int16), tensor(int32), tensor(int64), tensor(float16), tensor(float), tensor(double), tensor(string), tensor(bool), tensor(complex64), tensor(complex128)
+
Constrain input and output to all tensor types.
+
+ +### **Gather-11** + + Given `data` tensor of rank r >= 1, and `indices` tensor of rank q, gather + entries of the axis dimension of `data` (by default outer-most one as axis=0) indexed by `indices`, and concatenates + them in an output tensor of rank q + (r - 1). + + axis = 0 : + + Let + k = indices[i_{0}, ..., i_{q-1}] + Then + output[i_{0}, ..., i_{q-1}, j_{0}, ..., j_{r-2}] = input[k , j_{0}, ..., j_{r-2}] + + ``` + data = [ + [1.0, 1.2], + [2.3, 3.4], + [4.5, 5.7], + ] + indices = [ + [0, 1], + [1, 2], + ] + output = [ + [ + [1.0, 1.2], + [2.3, 3.4], + ], + [ + [2.3, 3.4], + [4.5, 5.7], + ], + ] + ``` + axis = 1 : + + Let + k = indices[i_{0}, ..., i_{q-1}] + Then + output[i_{0}, ..., i_{q-1}, j_{0}, ..., j_{r-2}] = input[j_{0}, k, j_{1}, ..., j_{r-2}] + + ``` + data = [ + [1.0, 1.2, 1.9], + [2.3, 3.4, 3.9], + [4.5, 5.7, 5.9], + ] + indices = [ + [0, 2], + ] + axis = 1, + output = [ + [ + [1.0, 1.9], + [2.3, 3.9], + [4.5, 5.9], + ], + ] + ``` + +#### Version + +This version of the operator has been available since version 11 of the default ONNX operator set. + +#### Attributes + +
+
axis : int (default is 0)
+
Which axis to gather on. Negative value means counting dimensions from the back. Accepted range is [-r, r-1] where r = rank(data).
+
+ +#### Inputs + +
+
data : T
+
Tensor of rank r >= 1.
+
indices : Tind
+
Tensor of int32/int64 indices, of any rank q. All index values are expected to be within bounds [-s, s-1] along axis of size s. It is an error if any of the index values are out of bounds.
+
+ +#### Outputs + +
+
output : T
+
Tensor of rank q + (r - 1).
+
+ +#### Type Constraints + +
+
T : tensor(uint8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(int8), tensor(int16), tensor(int32), tensor(int64), tensor(float16), tensor(float), tensor(double), tensor(string), tensor(bool), tensor(complex64), tensor(complex128)
+
Constrain input and output types to any tensor type.
+
Tind : tensor(int32), tensor(int64)
+
Constrain indices to integer types
+
+ +### **GatherElements-11** + + GatherElements takes two inputs `data` and `indices` of the same rank r >= 1 + and an optional attribute `axis` that identifies an axis of `data` + (by default, the outer-most axis, that is axis 0). It is an indexing operation + that produces its output by indexing into the input data tensor at index + positions determined by elements of the `indices` tensor. + Its output shape is the same as the shape of `indices` and consists of one value + (gathered from the `data`) for each element in `indices`. + + For instance, in the 3-D case (r = 3), the output produced is determined + by the following equations: + ``` + out[i][j][k] = input[index[i][j][k]][j][k] if axis = 0, + out[i][j][k] = input[i][index[i][j][k]][k] if axis = 1, + out[i][j][k] = input[i][j][index[i][j][k]] if axis = 2, + ``` + + This operator is also the inverse of ScatterElements. It is similar to Torch's gather operation. + + Example 1: + ``` + data = [ + [1, 2], + [3, 4], + ] + indices = [ + [0, 0], + [1, 0], + ] + axis = 1 + output = [ + [ + [1, 1], + [4, 3], + ], + ] + ``` + Example 2: + ``` + data = [ + [1, 2, 3], + [4, 5, 6], + [7, 8, 9], + ] + indices = [ + [1, 2, 0], + [2, 0, 0], + ] + axis = 0 + output = [ + [ + [4, 8, 3], + [7, 2, 3], + ], + ] + ``` + +#### Version + +This version of the operator has been available since version 11 of the default ONNX operator set. + +#### Attributes + +
+
axis : int (default is 0)
+
Which axis to gather on. Negative value means counting dimensions from the back. Accepted range is [-r, r-1] where r = rank(data).
+
+ +#### Inputs + +
+
data : T
+
Tensor of rank r >= 1.
+
indices : Tind
+
Tensor of int32/int64 indices, with the same rank r as the input. All index values are expected to be within bounds [-s, s-1] along axis of size s. It is an error if any of the index values are out of bounds.
+
+ +#### Outputs + +
+
output : T
+
Tensor of the same shape as indices.
+
+ +#### Type Constraints + +
+
T : tensor(uint8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(int8), tensor(int16), tensor(int32), tensor(int64), tensor(float16), tensor(float), tensor(double), tensor(string), tensor(bool), tensor(complex64), tensor(complex128)
+
Constrain input and output types to any tensor type.
+
Tind : tensor(int32), tensor(int64)
+
Constrain indices to integer types
+
+ +### **GatherND-11** + + Given `data` tensor of rank `r` >= 1, and `indices` tensor of rank `q` >= 1, this operator gathers + slices of `data` into an output tensor of rank `q + r - indices_shape[-1] - 1`. + + `indices` is an q-dimensional integer tensor, best thought of as a `(q-1)`-dimensional tensor of index-tuples into `data`, + where each element defines a slice of `data` + + Some salient points about the inputs' rank and shape: + + 1) r >= 1 and q >= 1 are to be honored. There is no dependency condition to be met between ranks `r` and `q` + + 2) The `indices_shape[-1]` should have a value between 1 (inclusive) and rank `r` (inclusive) + + 3) All values in `indices` are expected to be within bounds [-s, s-1] along axis of size `s` (i.e.) `-data_shape[i] <= indices[...,i] <= data_shape[i] - 1`. + It is an error if any of the index values are out of bounds. + + The output is computed as follows: + + The output tensor is obtained by mapping each index-tuple in the `indices` tensor to the corresponding slice of the input `data`. + + 1) If `indices_shape[-1] > r` => error condition + + 2) If `indices_shape[-1] == r`, since the rank of `indices` is `q`, `indices` can be thought of as a `(q-1)`-dimensional tensor + containing 1-D tensors of dimension `r`. Let us think of each such `r` ranked tensor as `indices_slice`. + Each *scalar value* corresponding to `data[indices_slice]` is filled into the corresponding location of the `(q-1)`-dimensional tensor + to form the `output` tensor (Example 1 below) + + 3) If `indices_shape[-1] < r`, since the rank of `indices` is `q`, `indices` can be thought of as a `(q-1)`-dimensional tensor + containing 1-D tensors of dimension `< r`. Let us think of each such tensors as `indices_slice`. + Each *tensor slice* corresponding to `data[indices_slice , :]` is filled into the corresponding location of the `(q-1)`-dimensional tensor + to form the `output` tensor (Examples 2, 3, and 4 below) + + This operator is the inverse of `ScatterND`. + + `Example 1` + + data = [[0,1],[2,3]] # data_shape = [2, 2] + + indices = [[0,0],[1,1]] # indices_shape = [2, 2] + + output = [0,3] # output_shape = [2] + + `Example 2` + + data = [[0,1],[2,3]] # data_shape = [2, 2] + + indices = [[1],[0]] # indices_shape = [2, 1] + + output = [[2,3],[0,1]] # output_shape = [2, 2] + + `Example 3` + + data = [[[0,1],[2,3]],[[4,5],[6,7]]] # data_shape = [2, 2, 2] + + indices = [[0,1],[1,0]] # indices_shape = [2, 2] + + output = [[2,3],[4,5]] # output_shape = [2, 2] + + `Example 4` + + data = [[[0,1],[2,3]],[[4,5],[6,7]]] # data_shape = [2, 2, 2] + + indices = [[[0,1]],[[1,0]]] # indices_shape = [2, 1, 2] + + output = [[[2,3]],[[4,5]]] # output_shape = [2, 1, 2] + + +#### Version + +This version of the operator has been available since version 11 of the default ONNX operator set. + +#### Inputs + +
+
data : T
+
Tensor of rank r >= 1.
+
indices : tensor(int64)
+
Tensor of rank q >= 1. All index values are expected to be within bounds [-s, s-1] along axis of size s. It is an error if any of the index values are out of bounds.
+
+ +#### Outputs + +
+
output : T
+
Tensor of rank q + r - indices_shape[-1] - 1.
+
+ +#### Type Constraints + +
+
T : tensor(uint8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(int8), tensor(int16), tensor(int32), tensor(int64), tensor(float16), tensor(float), tensor(double), tensor(string), tensor(bool), tensor(complex64), tensor(complex128)
+
Constrain input and output types to any tensor type.
+
+ +### **Gemm-11** + + General Matrix multiplication: + https://en.wikipedia.org/wiki/Basic_Linear_Algebra_Subprograms#Level_3 + + A' = transpose(A) if transA else A + + B' = transpose(B) if transB else B + + Compute Y = alpha * A' * B' + beta * C, where input tensor A has shape (M, K) or (K, M), + input tensor B has shape (K, N) or (N, K), input tensor C is broadcastable to shape (M, N), + and output tensor Y has shape (M, N). A will be transposed before doing the + computation if attribute transA is non-zero, same for B and transB. + This operator supports **unidirectional broadcasting** (tensor C should be unidirectional broadcastable to tensor A * B); for more details please check [the doc](Broadcasting.md). + This operator has **optional** inputs/outputs. See [the doc](IR.md) for more details about the representation of optional arguments. An empty string may be used in the place of an actual argument's name to indicate a missing argument. Trailing optional arguments (those not followed by an argument that is present) may also be simply omitted. + +#### Version + +This version of the operator has been available since version 11 of the default ONNX operator set. + +#### Attributes + +
+
alpha : float (default is 1.0)
+
Scalar multiplier for the product of input tensors A * B.
+
beta : float (default is 1.0)
+
Scalar multiplier for input tensor C.
+
transA : int (default is 0)
+
Whether A should be transposed
+
transB : int (default is 0)
+
Whether B should be transposed
+
+ +#### Inputs (2 - 3) + +
+
A : T
+
Input tensor A. The shape of A should be (M, K) if transA is 0, or (K, M) if transA is non-zero.
+
B : T
+
Input tensor B. The shape of B should be (K, N) if transB is 0, or (N, K) if transB is non-zero.
+
C (optional) : T
+
Optional input tensor C. If not specified, the computation is done as if C is a scalar 0. The shape of C should be unidirectional broadcastable to (M, N).
+
+ +#### Outputs + +
+
Y : T
+
Output tensor of shape (M, N).
+
+ +#### Type Constraints + +
+
T : tensor(float16), tensor(float), tensor(double), tensor(uint32), tensor(uint64), tensor(int32), tensor(int64)
+
Constrain input and output types to float/int tensors.
+
+ +### **Hardmax-11** + + The operator computes the hardmax (1 for the first maximum value, and 0 for all others) values for each layer in the batch + of the given input. + + The input does not need to explicitly be a 2D vector; rather, it will be + coerced into one. For an arbitrary n-dimensional tensor + input \in [a_0, a_1, ..., a_{k-1}, a_k, ..., a_{n-1}] and k is + the axis provided, then input will be coerced into a 2-dimensional tensor with + dimensions [a_0 * ... * a_{k-1}, a_k * ... * a_{n-1}]. For the default + case where axis=1, this means the input tensor will be coerced into a 2D tensor + of dimensions [a_0, a_1 * ... * a_{n-1}], where a_0 is often the batch size. + In this situation, we must have a_0 = N and a_1 * ... * a_{n-1} = D. + Each of these dimensions must be matched correctly, or else the operator + will throw errors. The output tensor has the same shape + and contains the hardmax values of the corresponding input. + +#### Version + +This version of the operator has been available since version 11 of the default ONNX operator set. + +#### Attributes + +
+
axis : int (default is 1)
+
Describes the axis of the inputs when coerced to 2D; defaults to one because the 0th axis most likely describes the batch_size. Negative value means counting dimensions from the back. Accepted range is [-r, r-1] where r = rank(input).
+
+ +#### Inputs + +
+
input : T
+
The input tensor that's coerced into a 2D matrix of size (NxD) as described above.
+
+ +#### Outputs + +
+
output : T
+
The output values with the same shape as input tensor (the original size without coercion).
+
+ +#### Type Constraints + +
+
T : tensor(float16), tensor(float), tensor(double)
+
Constrain input and output types to float tensors.
+
+ +### **If-11** + + If conditional + +#### Version + +This version of the operator has been available since version 11 of the default ONNX operator set. + +#### Attributes + +
+
else_branch : graph (required)
+
Graph to run if condition is false. Has N outputs: values you wish to be live-out to the enclosing scope. The number of outputs must match the number of outputs in the then_branch.
+
then_branch : graph (required)
+
Graph to run if condition is true. Has N outputs: values you wish to be live-out to the enclosing scope. The number of outputs must match the number of outputs in the else_branch.
+
+ +#### Inputs + +
+
cond : B
+
Condition for the if
+
+ +#### Outputs (1 - ∞) + +
+
outputs (variadic, heterogeneous) : V
+
Values that are live-out to the enclosing scope. The return values in the `then_branch` and `else_branch` must be of the same data type. The `then_branch` and `else_branch` may produce tensors with the same element type and different shapes. If corresponding outputs from the then-branch and the else-branch have static shapes S1 and S2, then the shape of the corresponding output variable of the if-node (if present) must be compatible with both S1 and S2 as it represents the union of both possible shapes.For example, if in a model file, the the first output of `then_branch` is typed float tensor with shape [2] and the first output of `else_branch` is another float tensor with shape [3], If's first output should have (a) no shape set, or (b) a shape of rank 1 with neither `dim_value` nor `dim_param` set, or (c) a shape of rank 1 with a unique `dim_param`. In contrast, the first output cannot have the shape [2] since [2] and [3] are not compatible.
+
+ +#### Type Constraints + +
+
V : tensor(uint8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(int8), tensor(int16), tensor(int32), tensor(int64), tensor(float16), tensor(float), tensor(double), tensor(string), tensor(bool), tensor(complex64), tensor(complex128)
+
All Tensor types
+
B : tensor(bool)
+
Only bool
+
+ +### **LogSoftmax-11** + + The operator computes the logsoftmax (log of softmax) values for each layer in the batch + of the given input. + + The input does not need to explicitly be a 2D vector; rather, it will be + coerced into one. For an arbitrary n-dimensional tensor + input \in [a_0, a_1, ..., a_{k-1}, a_k, ..., a_{n-1}] and k is + the axis provided, then input will be coerced into a 2-dimensional tensor with + dimensions [a_0 * ... * a_{k-1}, a_k * ... * a_{n-1}]. For the default + case where axis=1, this means the input tensor will be coerced into a 2D tensor + of dimensions [a_0, a_1 * ... * a_{n-1}], where a_0 is often the batch size. + In this situation, we must have a_0 = N and a_1 * ... * a_{n-1} = D. + Each of these dimensions must be matched correctly, or else the operator + will throw errors. The output tensor has the same shape + and contains the logsoftmax values of the corresponding input. + +#### Version + +This version of the operator has been available since version 11 of the default ONNX operator set. + +#### Attributes + +
+
axis : int (default is 1)
+
Describes the axis of the inputs when coerced to 2D; defaults to one because the 0th axis most likely describes the batch_size. Negative value means counting dimensions from the back. Accepted range is [-r, r-1] where r = rank(input).
+
+ +#### Inputs + +
+
input : T
+
The input tensor that's coerced into a 2D matrix of size (NxD) as described above.
+
+ +#### Outputs + +
+
output : T
+
The output values with the same shape as input tensor (the original size without coercion).
+
+ +#### Type Constraints + +
+
T : tensor(float16), tensor(float), tensor(double)
+
Constrain input and output types to float tensors.
+
+ +### **Loop-11** + + Generic Looping construct. This loop has multiple termination conditions: + + 1) Trip count. Iteration count specified at runtime. Set by + specifying the input M. Optional. Set to empty string to omit. + Note that a static trip count (specified at graph construction time) can be + specified by passing in a constant node for input M. + 2) Loop termination condition. This is an input to the op that determines + whether to run the first iteration and also a loop-carried dependency for + the body graph. The body graph must yield a value for the condition variable, + whether this input is provided or not. + + This table summarizes the operating modes of this operator with equivalent + C-style code: + + Operator inputs defined as (max_trip_count, condition_var). + + input ("", ""): + for (int i=0; ; ++i) { + cond = ... // Note this value is ignored, but is required in the body + } + + input ("", cond) // Note this is analogous to a while loop + bool cond = ...; + for (int i=0; cond; ++i) { + cond = ...; + } + + input ("", 1) // Note this is analogous to a do-while loop + bool cond = true + for (int i=0; cond; ++i) { + cond = ...; + } + + input (trip_count, "") // Note this is analogous to a for loop + int trip_count = ... + for (int i=0; i < trip_count; ++i) { + cond = ...; // ignored + } + + input (trip_count, cond) + int trip_count = ...; + bool cond = ...; + for (int i=0; i < trip_count && cond; ++i) { + cond = ...; + } + + + *Sample usage - cond as well as trip count* + + graph predict-net { + %a = Constant[value = ]() + %b = Constant[value = ]() + %keepgoing = Constant[value = ]() + %max_trip_count = Constant[value = ]() + %keepgoing_out, %b_out, %user_defined_vals = Loop[body = ](%max_trip_count, %keepgoing, %b) + return + } + + graph body-net ( + %i[INT32, scalar] // iteration number + %keepgoing_in[BOOL, scalar] // incoming loop-termination-condition; not used + %b_in[INT32, scalar] // incoming value of loop-carried-dependency b + ) { + %my_local = Add(%a, %b_in) + %b_out = Sub(%a, %b_in) // outgoing value of loop-carried-dependency b + %keepgoing_out = Greater(%my_local, %b_out) // outgoing loop-termination-condition + %user_defined_val = Add(%b_in, %b_in) // scan-output value to be accumulated + return %keepgoing_out, %b_out, %user_defined_val + } + + *Sample equivalent C code* + + { + /* User-defined code (enclosing scope) */ + int a = 3, b = 6; + bool keepgoing = true; // Analogous to input cond + /* End user-defined code */ + + /* Implicitly-defined code */ + const int max_trip_count = 10; // Analogous to input M + int user_defined_vals[]; // Imagine this is resizable + /* End implicitly-defined code */ + /* initialize loop-carried variables and scan-output variables */ + bool keepgoing_out = keepgoing + int b_out = b + + for (int i=0; i < max_trip_count && keepgoing_out; ++i) { + /* Implicitly-defined code: bind actual parameter values + to formal parameter variables of loop-body */ + bool keepgoing_in = keepgoing_out; + bool b_in = b_out; + + /* User-defined code (loop body) */ + int my_local = a + b_in; // Reading value "a" from the enclosing scope is fine + b_out = a - b_in; + keepgoing_out = my_local > b_out; + user_defined_val = b_in + b_in; // b_in and b_out are different variables + /* End user-defined code */ + + /* Implicitly defined-code */ + user_defined_vals[i] = user_defined_val // accumulate scan-output values + } + // int t = my_local; // Can't do this. my_local is not accessible here. + + // The values below are bound to the output variables of the loop and therefore accessible + // b_out; user_defined_vals; keepgoing_out; + } + + There are several things of note in this code snippet: + + 1) Values from the enclosing scope (i.e. variable "a" here) are in scope and can + be referenced in the inputs of the loop. + 2) Any values computed in the loop body that needs to be used in a subsequent + iteration or after the loop are modelled using a pair of variables in the loop-body, + consisting of an input variable (eg., b_in) and an output variable (eg., b_out). + These are referred to as loop-carried dependences. The loop operation node + supplies the input value of the input variable for the first iteration, and + returns the output value of the output variable produced by the final + iteration. + 3) Scan_output variables are used to implicitly concatenate values computed across + all the iterations. In the above example, the value of user_defined_val computed + over all iterations are concatenated and returned as the value of user_defined_vals + after the loop. + 4) Values created in the body cannot be accessed in the enclosing scope, + except using the mechanism described above. + + Note that the semantics of this op support "diagonal" or "wavefront" execution. + (See Step 3 here for an example: + https://devblogs.nvidia.com/optimizing-recurrent-neural-networks-cudnn-5/). + Frontends should emit multi-layer RNNs as a series of While operators (with + time being the inner looping dimension), with each successive layer consuming + the scan_outputs from the previous layer, possibly going through several + point-wise operators (e.g. dropout, residual connections, linear layer). + +#### Version + +This version of the operator has been available since version 11 of the default ONNX operator set. + +#### Attributes + +
+
body : graph (required)
+
The graph run each iteration. It has 2+N inputs: (iteration_num, condition, loop carried dependencies...). It has 1+N+K outputs: (condition, loop carried dependencies..., scan_outputs...). Each scan_output is created by concatenating the value of the specified output value at the end of each iteration of the loop. It is an error if the dimensions or data type of these scan_outputs change across loop iterations.
+
+ +#### Inputs (2 - ∞) + +
+
M (optional) : I
+
A maximum trip-count for the loop specified at runtime. Optional. Pass empty string to skip.
+
cond (optional) : B
+
A boolean termination condition. Optional. Pass empty string to skip.
+
v_initial (variadic, heterogeneous) : V
+
The initial values of any loop-carried dependencies (values that change across loop iterations)
+
+ +#### Outputs (1 - ∞) + +
+
v_final_and_scan_outputs (variadic, heterogeneous) : V
+
Final N loop carried dependency values then K scan_outputs
+
+ +#### Type Constraints + +
+
V : tensor(uint8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(int8), tensor(int16), tensor(int32), tensor(int64), tensor(float16), tensor(float), tensor(double), tensor(string), tensor(bool), tensor(complex64), tensor(complex128)
+
All Tensor types
+
I : tensor(int64)
+
tensor of int64, which should be a scalar.
+
B : tensor(bool)
+
tensor of bool, which should be a scalar.
+
+ +### **LpPool-11** + + LpPool consumes an input tensor X and applies Lp pooling across + the tensor according to kernel sizes, stride sizes, and pad lengths. + Lp pooling consisting of computing the Lp norm on all values of a subset + of the input tensor according to the kernel size and downsampling the + data into the output tensor Y for further processing. + +#### Version + +This version of the operator has been available since version 11 of the default ONNX operator set. + +#### Attributes + +
+
auto_pad : string (default is NOTSET)
+
auto_pad must be either NOTSET, SAME_UPPER, SAME_LOWER or VALID. Where default value is NOTSET, which means explicit padding is used. SAME_UPPER or SAME_LOWER mean pad the input so that `output_shape[i] = ceil(input_shape[i] / strides[i])` for each axis `i`. The padding is split between the two sides equally or almost equally (depending on whether it is even or odd). In case the padding is an odd number, the extra padding is added at the end for SAME_UPPER and at the beginning for SAME_LOWER.
+
kernel_shape : list of ints (required)
+
The size of the kernel along each axis.
+
p : int (default is 2)
+
p value of the Lp norm used to pool over the input data.
+
pads : list of ints
+
Padding for the beginning and ending along each spatial axis, it can take any value greater than or equal to 0. The value represent the number of pixels added to the beginning and end part of the corresponding axis. `pads` format should be as follow [x1_begin, x2_begin...x1_end, x2_end,...], where xi_begin the number of pixels added at the beginning of axis `i` and xi_end, the number of pixels added at the end of axis `i`. This attribute cannot be used simultaneously with auto_pad attribute. If not present, the padding defaults to 0 along start and end of each spatial axis.
+
strides : list of ints
+
Stride along each spatial axis. If not present, the stride defaults to 1 along each spatial axis.
+
+ +#### Inputs + +
+
X (differentiable) : T
+
Input data tensor from the previous operator; dimensions for image case are (N x C x H x W), where N is the batch size, C is the number of channels, and H and W are the height and the width of the data. For non image case, the dimensions are in the form of (N x C x D1 x D2 ... Dn), where N is the batch size.
+
+ +#### Outputs + +
+
Y (differentiable) : T
+
Output data tensor from Lp pooling across the input tensor. Dimensions will vary based on various kernel, stride, and pad sizes.
+
+ +#### Type Constraints + +
+
T : tensor(float16), tensor(float), tensor(double)
+
Constrain input and output types to float tensors.
+
+ +### **MaxPool-11** + + MaxPool consumes an input tensor X and applies max pooling across + the tensor according to kernel sizes, stride sizes, and pad lengths. + max pooling consisting of computing the max on all values of a + subset of the input tensor according to the kernel size and downsampling the + data into the output tensor Y for further processing. The output spatial shape will be following: + ``` + output_spatial_shape[i] = floor((input_spatial_shape[i] + pad_shape[i] - ((kernel_spatial_shape[i] - 1) * dilations[i] + 1)) / strides_spatial_shape[i] + 1) + ``` + or + ``` + output_spatial_shape[i] = ceil((input_spatial_shape[i] + pad_shape[i] - ((kernel_spatial_shape[i] - 1) * dilations[i] + 1)) / strides_spatial_shape[i] + 1) + ``` + if ceil_mode is enabled + + ``` + * pad_shape[i] is sum of pads along axis i + ``` + + `auto_pad` is a DEPRECATED attribute. If you are using them currently, the output spatial shape will be following: + ``` + VALID: output_spatial_shape[i] = ceil((input_spatial_shape[i] - ((kernel_spatial_shape[i] - 1) * dilations[i] + 1) + 1) / strides_spatial_shape[i]) + SAME_UPPER or SAME_LOWER: output_spatial_shape[i] = ceil(input_spatial_shape[i] / strides_spatial_shape[i]) + ``` + And pad shape will be following if `SAME_UPPER` or `SAME_LOWER`: + ``` + pad_shape[i] = (output_spatial_shape[i] - 1) * strides_spatial_shape[i] + ((kernel_spatial_shape[i] - 1) * dilations[i] + 1) - input_spatial_shape[i] + ``` + The output of each pooling window is maximum number of elements exclude pad. + + +#### Version + +This version of the operator has been available since version 11 of the default ONNX operator set. + +#### Attributes + +
+
auto_pad : string (default is NOTSET)
+
auto_pad must be either NOTSET, SAME_UPPER, SAME_LOWER or VALID. Where default value is NOTSET, which means explicit padding is used. SAME_UPPER or SAME_LOWER mean pad the input so that the output spatial size match the input.In case of odd number add the extra padding at the end for SAME_UPPER and at the beginning for SAME_LOWER. VALID mean no padding.
+
ceil_mode : int (default is 0)
+
Whether to use ceil or floor (default) to compute the output shape.
+
dilations : list of ints
+
Dilation value along each spatial axis of filter. If not present, the dilation defaults to 1 along each spatial axis.
+
kernel_shape : list of ints (required)
+
The size of the kernel along each axis.
+
pads : list of ints
+
Padding for the beginning and ending along each spatial axis, it can take any value greater than or equal to 0. The value represent the number of pixels added to the beginning and end part of the corresponding axis. `pads` format should be as follow [x1_begin, x2_begin...x1_end, x2_end,...], where xi_begin the number of pixels added at the beginning of axis `i` and xi_end, the number of pixels added at the end of axis `i`. This attribute cannot be used simultaneously with auto_pad attribute. If not present, the padding defaults to 0 along start and end of each spatial axis.
+
storage_order : int (default is 0)
+
The storage order of the tensor. 0 is row major, and 1 is column major.
+
strides : list of ints
+
Stride along each spatial axis. If not present, the stride defaults to 1 along each spatial axis.
+
+ +#### Inputs + +
+
X : T
+
Input data tensor from the previous operator; dimensions for image case are (N x C x H x W), where N is the batch size, C is the number of channels, and H and W are the height and the width of the data. For non image case, the dimensions are in the form of (N x C x D1 x D2 ... Dn), where N is the batch size. Optionally, if dimension denotation is in effect, the operation expects the input data tensor to arrive with the dimension denotation of [DATA_BATCH, DATA_CHANNEL, DATA_FEATURE, DATA_FEATURE ...].
+
+ +#### Outputs (1 - 2) + +
+
Y : T
+
Output data tensor from average or max pooling across the input tensor. Dimensions will vary based on various kernel, stride, and pad sizes. Floor value of the dimension is used
+
Indices (optional) : I
+
Indices tensor from max pooling across the input tensor. The dimensions of indices are the same as output tensor. The values in indices of are the indices of the selected values during pooling. The indices are computed as flatten 1-D tensor, and the indices do not consider padding. So the values in indices are in [0, N x C x D1 x ... x Dn).
+
+ +#### Type Constraints + +
+
T : tensor(float16), tensor(float), tensor(double)
+
Constrain input and output types to float tensors.
+
I : tensor(int64)
+
Constrain index tensor to int64
+
+ +### **MaxUnpool-11** + + MaxUnpool essentially computes the partial inverse of the MaxPool op. + The input information to this op is typically the the output information from a MaxPool op. The first + input tensor X is the tensor that needs to be unpooled, which is typically the pooled tensor (first output) + from MaxPool. The second input tensor, I, contains the indices to the (locally maximal) elements corrsponding + to the elements in the first input tensor X. Input tensor I is typically the second output of the MaxPool op. + The third (optional) input is a tensor that specifies the output size of the unpooling operation. + + MaxUnpool is intended to do 'partial' inverse of the MaxPool op. 'Partial' because all the non-maximal + values from the original input to MaxPool are set to zero in the output of the MaxUnpool op. Pooling + the result of an unpooling operation should give back the original input to the unpooling op. + + MaxUnpool can produce the same output size for several input sizes, which makes unpooling op ambiguous. + The third input argument, output_size, is meant to disambiguate the op and produce output tensor of + known/predictable size. + + In addition to the inputs, MaxUnpool takes three attributes, namely kernel_shape, strides, and pads, + which define the exact unpooling op. The attributes typically have the same values as the corrsponding + pooling op that the unpooling op is trying to invert. + +#### Version + +This version of the operator has been available since version 11 of the default ONNX operator set. + +#### Attributes + +
+
kernel_shape : list of ints (required)
+
The size of the kernel along each axis.
+
pads : list of ints
+
Padding for the beginning and ending along each spatial axis, it can take any value greater than or equal to 0. The value represent the number of pixels added to the beginning and end part of the corresponding axis. `pads` format should be as follow [x1_begin, x2_begin...x1_end, x2_end,...], where xi_begin the number of pixels added at the beginning of axis `i` and xi_end, the number of pixels added at the end of axis `i`. This attribute cannot be used simultaneously with auto_pad attribute. If not present, the padding defaults to 0 along start and end of each spatial axis.
+
strides : list of ints
+
Stride along each spatial axis. If not present, the stride defaults to 1 along each spatial axis.
+
+ +#### Inputs (2 - 3) + +
+
X (differentiable) : T1
+
Input data tensor that has to be unpooled. This tensor is typically the first output of the MaxPool op.Dimensions for image case are (N x C x H x W), where N is the batch size, C is the number of channels, and H and W are the height and the width of the data. For non-image case, the dimensions are in the form of (N x C x D1 x D2 ... Dn), where N is the batch size. Optionally, if dimension denotation is in effect, the operation expects the input data tensor to arrive with the dimension denotation of [DATA_BATCH, DATA_CHANNEL, DATA_FEATURE, DATA_FEATURE ...].
+
I (non-differentiable) : T2
+
Input data tensor containing the indices corresponding to elements in the first input tensor X.This tensor is typically the second output of the MaxPool op.Dimensions must be the same as input tensor X. The indices are linear, i.e. computed considering the tensor as flattened 1-D tensor, assuming row-major storage. Also, the linear indices should not consider padding. So the values in indices are in the range [0, N x C x D1 x ... x Dn).
+
output_shape (optional, non-differentiable) : T2
+
The shape of the output can be explicitly set which will cause pads values to be auto generated. If 'output_shape' is specified, 'pads' values are ignored.
+
+ +#### Outputs + +
+
output (differentiable) : T1
+
Output data tensor that contains the result of the unpooling.
+
+ +#### Type Constraints + +
+
T1 : tensor(float16), tensor(float), tensor(double)
+
Constrain input and output types to float tensors.
+
T2 : tensor(int64)
+
Constrain index tensor to int64
+
+ +### **NonMaxSuppression-11** + + Filter out boxes that have high intersection-over-union (IOU) overlap with previously selected boxes. + Bounding boxes with score less than score_threshold are removed. Bounding box format is indicated by attribute center_point_box. + Note that this algorithm is agnostic to where the origin is in the coordinate system and more generally is invariant to + orthogonal transformations and translations of the coordinate system; thus translating or reflections of the coordinate system + result in the same boxes being selected by the algorithm. + The selected_indices output is a set of integers indexing into the input collection of bounding boxes representing the selected boxes. + The bounding box coordinates corresponding to the selected indices can then be obtained using the Gather or GatherND operation. + +#### Version + +This version of the operator has been available since version 11 of the default ONNX operator set. + +#### Attributes + +
+
center_point_box : int (default is 0)
+
Integer indicate the format of the box data. The default is 0. 0 - the box data is supplied as [y1, x1, y2, x2] where (y1, x1) and (y2, x2) are the coordinates of any diagonal pair of box corners and the coordinates can be provided as normalized (i.e., lying in the interval [0, 1]) or absolute. Mostly used for TF models. 1 - the box data is supplied as [x_center, y_center, width, height]. Mostly used for Pytorch models.
+
+ +#### Inputs (2 - 5) + +
+
boxes : tensor(float)
+
An input tensor with shape [num_batches, spatial_dimension, 4]. The single box data format is indicated by center_point_box.
+
scores : tensor(float)
+
An input tensor with shape [num_batches, num_classes, spatial_dimension]
+
max_output_boxes_per_class (optional) : tensor(int64)
+
Integer representing the maximum number of boxes to be selected per batch per class. It is a scalar. Default to 0, which means no output.
+
iou_threshold (optional) : tensor(float)
+
Float representing the threshold for deciding whether boxes overlap too much with respect to IOU. It is scalar. Value range [0, 1]. Default to 0.
+
score_threshold (optional) : tensor(float)
+
Float representing the threshold for deciding when to remove boxes based on score. It is a scalar.
+
+ +#### Outputs + +
+
selected_indices : tensor(int64)
+
selected indices from the boxes tensor. [num_selected_indices, 3], the selected index format is [batch_index, class_index, box_index].
+
+ +#### Type Constraints + + +### **OneHot-11** + + Produces a one-hot tensor based on inputs. + The locations represented by the index values in the 'indices' input tensor will have 'on_value' + and the other locations will have 'off_value' in the output tensor, where 'on_value' and 'off_value' + are specified as part of required input argument 'values', which is a two-element tensor of format + [off_value, on_value]. The rank of the output tensor will be one greater than the rank of the + input tensor. The additional dimension is for one-hot representation. The additional dimension will + be inserted at the position specified by 'axis'. If 'axis' is not specified then then additional + dimension will be inserted as the innermost dimension, i.e. axis=-1. The size of the additional + dimension is specified by required scalar input 'depth'. The type of the output tensor is the same + as the type of the 'values' input. Any entries in the 'indices' input tensor with values outside + the range [-depth, depth-1] will result in one-hot representation with all 'off_value' values in the + output tensor. + + when axis = 0: + output[input[i, j, k], i, j, k] = 1 for all i, j, k and 0 otherwise. + + when axis = -1: + output[i, j, k, input[i, j, k]] = 1 for all i, j, k and 0 otherwise. + + +#### Version + +This version of the operator has been available since version 11 of the default ONNX operator set. + +#### Attributes + +
+
axis : int (default is -1)
+
(Optional) Axis along which one-hot representation in added. Default: axis=-1. axis=-1 means that the additional dimension will be inserted as the innermost/last dimension in the output tensor. Negative value means counting dimensions from the back. Accepted range is [-r-1, r] where r = rank(indices).
+
+ +#### Inputs + +
+
indices (non-differentiable) : T1
+
Input tensor containing indices. Any entries in the 'indices' input tensor with values outside the range [-depth, depth-1] will result in one-hot representation with all 'off_value' values in the output tensor.In case 'indices' is of non-integer type, the values will be casted to int64 before use.
+
depth (non-differentiable) : T2
+
Scalar specifying the number of classes in one-hot tensor. This is also the size of the one-hot dimension (specified by 'axis' attribute) added on in the output tensor. The values in the 'indices' input tensor are expected to be in the range [-depth, depth-1]. In case 'depth' is of non-integer type, it will be casted to int64 before use.
+
values (non-differentiable) : T3
+
Rank 1 tensor containing exactly two elements, in the format [off_value, on_value], where 'on_value' is the value used for filling locations specified in 'indices' input tensor, and 'off_value' is the value used for filling locations other than those specified in 'indices' input tensor.
+
+ +#### Outputs + +
+
output (non-differentiable) : T3
+
Tensor of rank one greater than input tensor 'indices', i.e. rank(output) = rank(indices) + 1. The data type for the elements of the output tensor is the same as the type of input 'values' is used.
+
+ +#### Type Constraints + +
+
T1 : tensor(uint8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(int8), tensor(int16), tensor(int32), tensor(int64), tensor(float16), tensor(float), tensor(double)
+
Constrains input to only numeric types.
+
T2 : tensor(uint8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(int8), tensor(int16), tensor(int32), tensor(int64), tensor(float16), tensor(float), tensor(double)
+
Constrains input to only numeric types.
+
T3 : tensor(uint8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(int8), tensor(int16), tensor(int32), tensor(int64), tensor(float16), tensor(float), tensor(double), tensor(string), tensor(bool), tensor(complex64), tensor(complex128)
+
Constrain to any tensor type.
+
+ +### **Pad-11** + + Given a tensor containing the data to be padded (`data`), a tensor containing the number of start and end pad values for axis (`pads`), (optionally) a `mode`, and (optionally) `constant_value`, + a padded tensor (`output`) is generated. + + The three supported `modes` are (similar to corresponding modes supported by `numpy.pad`): + + 1) `constant`(default) - pads with a given constant value as specified by `constant_value` (which defaults to 0) + + 2) `reflect` - pads with the reflection of the vector mirrored on the first and last values of the vector along each axis + + 3) `edge` - pads with the edge values of array + + + Example 1 (`constant` mode): + Insert 0 pads to the beginning of the second dimension. + + data = + [ + [1.0, 1.2], + [2.3, 3.4], + [4.5, 5.7], + ] + + pads = [0, 2, 0, 0] + + mode = 'constant' + + constant_value = 0.0 + + output = + [ + [0.0, 0.0, 1.0, 1.2], + [0.0, 0.0, 2.3, 3.4], + [0.0, 0.0, 4.5, 5.7], + ] + + + Example 2 (`reflect` mode): + data = + [ + [1.0, 1.2], + [2.3, 3.4], + [4.5, 5.7], + ] + + pads = [0, 2, 0, 0] + + mode = 'reflect' + + output = + [ + [1.0, 1.2, 1.0, 1.2], + [2.3, 3.4, 2.3, 3.4], + [4.5, 5.7, 4.5, 5.7], + ] + + + Example 3 (`edge` mode): + data = + [ + [1.0, 1.2], + [2.3, 3.4], + [4.5, 5.7], + ] + + pads = [0, 2, 0, 0] + + mode = 'edge' + + output = + [ + [1.0, 1.0, 1.0, 1.2], + [2.3, 2.3, 2.3, 3.4], + [4.5, 4.5, 4.5, 5.7], + ] + + +#### Version + +This version of the operator has been available since version 11 of the default ONNX operator set. + +#### Attributes + +
+
mode : string (default is constant)
+
Supported modes: `constant`(default), `reflect`, `edge`
+
+ +#### Inputs (2 - 3) + +
+
data : T
+
Input tensor.
+
pads : tensor(int64)
+
Tensor of integers indicating the number of padding elements to add or remove (if negative) at the beginning and end of each axis. For 2D input tensor, it is the number of pixels. `pads` should be a 1D tensor of shape [2 * input_rank]. `pads` format should be: [x1_begin, x2_begin,...,x1_end, x2_end,...], where xi_begin is the number of pad values added at the beginning of axis `i` and xi_end, the number of pad values added at the end of axis `i`.
+
constant_value (optional) : T
+
(Optional) A scalar value to be used if the mode chosen is `constant` (by default it is 0).
+
+ +#### Outputs + +
+
output : T
+
Tensor after padding.
+
+ +#### Type Constraints + +
+
T : tensor(uint8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(int8), tensor(int16), tensor(int32), tensor(int64), tensor(float16), tensor(float), tensor(double)
+
Constrains input and output to only numeric types.
+
+ +### **Range-11** + + Generate a tensor containing a sequence of numbers that begin at `start` and extends by increments of `delta` + up to `limit` (exclusive). + + The number of elements in the output of range is computed as below- + + `number_of_elements = max( ceil( (limit - start) / delta ) , 0 )` + + The pseudocode determining the contents of the output is shown below- + + `for(int i=0; i +
start : T
+
Scalar. First entry for the range of output values.
+
limit : T
+
Scalar. Exclusive upper limit for the range of output values.
+
delta : T
+
Scalar. Value to step by.
+ + +#### Outputs + +
+
output : T
+
A 1-D tensor with same type as the inputs containing generated range of values.
+
+ +#### Type Constraints + +
+
T : tensor(float), tensor(double), tensor(int16), tensor(int32), tensor(int64)
+
Constrain input types to common numeric type tensors.
+
+ +### **ReduceL1-11** + + Computes the L1 norm of the input tensor's element along the provided axes. The resulted + tensor has the same rank as the input if keepdims equal 1. If keepdims equal 0, then + the resulted tensor have the reduced dimension pruned. + + The above behavior is similar to numpy, with the exception that numpy default keepdims to + False instead of True. + +#### Version + +This version of the operator has been available since version 11 of the default ONNX operator set. + +#### Attributes + +
+
axes : list of ints
+
A list of integers, along which to reduce. The default is to reduce over all the dimensions of the input tensor. Accepted range is [-r, r-1] where r = rank(data).
+
keepdims : int (default is 1)
+
Keep the reduced dimension or not, default 1 mean keep reduced dimension.
+
+ +#### Inputs + +
+
data : T
+
An input tensor.
+
+ +#### Outputs + +
+
reduced : T
+
Reduced output tensor.
+
+ +#### Type Constraints + +
+
T : tensor(uint32), tensor(uint64), tensor(int32), tensor(int64), tensor(float16), tensor(float), tensor(double)
+
Constrain input and output types to high-precision numeric tensors.
+
+ +### **ReduceL2-11** + + Computes the L2 norm of the input tensor's element along the provided axes. The resulted + tensor has the same rank as the input if keepdims equal 1. If keepdims equal 0, then + the resulted tensor have the reduced dimension pruned. + + The above behavior is similar to numpy, with the exception that numpy default keepdims to + False instead of True. + +#### Version + +This version of the operator has been available since version 11 of the default ONNX operator set. + +#### Attributes + +
+
axes : list of ints
+
A list of integers, along which to reduce. The default is to reduce over all the dimensions of the input tensor. Accepted range is [-r, r-1] where r = rank(data).
+
keepdims : int (default is 1)
+
Keep the reduced dimension or not, default 1 mean keep reduced dimension.
+
+ +#### Inputs + +
+
data : T
+
An input tensor.
+
+ +#### Outputs + +
+
reduced : T
+
Reduced output tensor.
+
+ +#### Type Constraints + +
+
T : tensor(uint32), tensor(uint64), tensor(int32), tensor(int64), tensor(float16), tensor(float), tensor(double)
+
Constrain input and output types to high-precision numeric tensors.
+
+ +### **ReduceLogSum-11** + + Computes the log sum of the input tensor's element along the provided axes. The resulted + tensor has the same rank as the input if keepdims equal 1. If keepdims equal 0, then + the resulted tensor have the reduced dimension pruned. + + The above behavior is similar to numpy, with the exception that numpy default keepdims to + False instead of True. + +#### Version + +This version of the operator has been available since version 11 of the default ONNX operator set. + +#### Attributes + +
+
axes : list of ints
+
A list of integers, along which to reduce. The default is to reduce over all the dimensions of the input tensor. Accepted range is [-r, r-1] where r = rank(data).
+
keepdims : int (default is 1)
+
Keep the reduced dimension or not, default 1 mean keep reduced dimension.
+
+ +#### Inputs + +
+
data : T
+
An input tensor.
+
+ +#### Outputs + +
+
reduced : T
+
Reduced output tensor.
+
+ +#### Type Constraints + +
+
T : tensor(uint32), tensor(uint64), tensor(int32), tensor(int64), tensor(float16), tensor(float), tensor(double)
+
Constrain input and output types to high-precision numeric tensors.
+
+ +### **ReduceLogSumExp-11** + + Computes the log sum exponent of the input tensor's element along the provided axes. The resulted + tensor has the same rank as the input if keepdims equal 1. If keepdims equal 0, then + the resulted tensor have the reduced dimension pruned. + + The above behavior is similar to numpy, with the exception that numpy default keepdims to + False instead of True. + +#### Version + +This version of the operator has been available since version 11 of the default ONNX operator set. + +#### Attributes + +
+
axes : list of ints
+
A list of integers, along which to reduce. The default is to reduce over all the dimensions of the input tensor. Accepted range is [-r, r-1] where r = rank(data).
+
keepdims : int (default is 1)
+
Keep the reduced dimension or not, default 1 mean keep reduced dimension.
+
+ +#### Inputs + +
+
data : T
+
An input tensor.
+
+ +#### Outputs + +
+
reduced : T
+
Reduced output tensor.
+
+ +#### Type Constraints + +
+
T : tensor(uint32), tensor(uint64), tensor(int32), tensor(int64), tensor(float16), tensor(float), tensor(double)
+
Constrain input and output types to high-precision numeric tensors.
+
+ +### **ReduceMax-11** + + Computes the max of the input tensor's element along the provided axes. The resulted + tensor has the same rank as the input if keepdims equal 1. If keepdims equal 0, then + the resulted tensor have the reduced dimension pruned. + + The above behavior is similar to numpy, with the exception that numpy default keepdims to + False instead of True. + +#### Version + +This version of the operator has been available since version 11 of the default ONNX operator set. + +#### Attributes + +
+
axes : list of ints
+
A list of integers, along which to reduce. The default is to reduce over all the dimensions of the input tensor. Accepted range is [-r, r-1] where r = rank(data).
+
keepdims : int (default is 1)
+
Keep the reduced dimension or not, default 1 mean keep reduced dimension.
+
+ +#### Inputs + +
+
data : T
+
An input tensor.
+
+ +#### Outputs + +
+
reduced : T
+
Reduced output tensor.
+
+ +#### Type Constraints + +
+
T : tensor(uint32), tensor(uint64), tensor(int32), tensor(int64), tensor(float16), tensor(float), tensor(double)
+
Constrain input and output types to high-precision numeric tensors.
+
+ +### **ReduceMean-11** + + Computes the mean of the input tensor's element along the provided axes. The resulted + tensor has the same rank as the input if keepdims equal 1. If keepdims equal 0, then + the resulted tensor have the reduced dimension pruned. + + The above behavior is similar to numpy, with the exception that numpy default keepdims to + False instead of True. + +#### Version + +This version of the operator has been available since version 11 of the default ONNX operator set. + +#### Attributes + +
+
axes : list of ints
+
A list of integers, along which to reduce. The default is to reduce over all the dimensions of the input tensor. Accepted range is [-r, r-1] where r = rank(data).
+
keepdims : int (default is 1)
+
Keep the reduced dimension or not, default 1 mean keep reduced dimension.
+
+ +#### Inputs + +
+
data : T
+
An input tensor.
+
+ +#### Outputs + +
+
reduced : T
+
Reduced output tensor.
+
+ +#### Type Constraints + +
+
T : tensor(uint32), tensor(uint64), tensor(int32), tensor(int64), tensor(float16), tensor(float), tensor(double)
+
Constrain input and output types to high-precision numeric tensors.
+
+ +### **ReduceMin-11** + + Computes the min of the input tensor's element along the provided axes. The resulted + tensor has the same rank as the input if keepdims equal 1. If keepdims equal 0, then + the resulted tensor have the reduced dimension pruned. + + The above behavior is similar to numpy, with the exception that numpy default keepdims to + False instead of True. + +#### Version + +This version of the operator has been available since version 11 of the default ONNX operator set. + +#### Attributes + +
+
axes : list of ints
+
A list of integers, along which to reduce. The default is to reduce over all the dimensions of the input tensor. Accepted range is [-r, r-1] where r = rank(data).
+
keepdims : int (default is 1)
+
Keep the reduced dimension or not, default 1 mean keep reduced dimension.
+
+ +#### Inputs + +
+
data : T
+
An input tensor.
+
+ +#### Outputs + +
+
reduced : T
+
Reduced output tensor.
+
+ +#### Type Constraints + +
+
T : tensor(uint32), tensor(uint64), tensor(int32), tensor(int64), tensor(float16), tensor(float), tensor(double)
+
Constrain input and output types to high-precision numeric tensors.
+
+ +### **ReduceProd-11** + + Computes the product of the input tensor's element along the provided axes. The resulted + tensor has the same rank as the input if keepdims equal 1. If keepdims equal 0, then + the resulted tensor have the reduced dimension pruned. + + The above behavior is similar to numpy, with the exception that numpy default keepdims to + False instead of True. + +#### Version + +This version of the operator has been available since version 11 of the default ONNX operator set. + +#### Attributes + +
+
axes : list of ints
+
A list of integers, along which to reduce. The default is to reduce over all the dimensions of the input tensor. Accepted range is [-r, r-1] where r = rank(data).
+
keepdims : int (default is 1)
+
Keep the reduced dimension or not, default 1 mean keep reduced dimension.
+
+ +#### Inputs + +
+
data : T
+
An input tensor.
+
+ +#### Outputs + +
+
reduced : T
+
Reduced output tensor.
+
+ +#### Type Constraints + +
+
T : tensor(uint32), tensor(uint64), tensor(int32), tensor(int64), tensor(float16), tensor(float), tensor(double)
+
Constrain input and output types to high-precision numeric tensors.
+
+ +### **ReduceSum-11** + + Computes the sum of the input tensor's element along the provided axes. The resulted + tensor has the same rank as the input if keepdims equal 1. If keepdims equal 0, then + the resulted tensor have the reduced dimension pruned. + + The above behavior is similar to numpy, with the exception that numpy default keepdims to + False instead of True. + +#### Version + +This version of the operator has been available since version 11 of the default ONNX operator set. + +#### Attributes + +
+
axes : list of ints
+
A list of integers, along which to reduce. The default is to reduce over all the dimensions of the input tensor. Accepted range is [-r, r-1] where r = rank(data).
+
keepdims : int (default is 1)
+
Keep the reduced dimension or not, default 1 mean keep reduced dimension.
+
+ +#### Inputs + +
+
data : T
+
An input tensor.
+
+ +#### Outputs + +
+
reduced : T
+
Reduced output tensor.
+
+ +#### Type Constraints + +
+
T : tensor(uint32), tensor(uint64), tensor(int32), tensor(int64), tensor(float16), tensor(float), tensor(double)
+
Constrain input and output types to high-precision numeric tensors.
+
+ +### **ReduceSumSquare-11** + + Computes the sum square of the input tensor's element along the provided axes. The resulted + tensor has the same rank as the input if keepdims equal 1. If keepdims equal 0, then + the resulted tensor have the reduced dimension pruned. + + The above behavior is similar to numpy, with the exception that numpy default keepdims to + False instead of True. + +#### Version + +This version of the operator has been available since version 11 of the default ONNX operator set. + +#### Attributes + +
+
axes : list of ints
+
A list of integers, along which to reduce. The default is to reduce over all the dimensions of the input tensor. Accepted range is [-r, r-1] where r = rank(data).
+
keepdims : int (default is 1)
+
Keep the reduced dimension or not, default 1 mean keep reduced dimension.
+
+ +#### Inputs + +
+
data : T
+
An input tensor.
+
+ +#### Outputs + +
+
reduced : T
+
Reduced output tensor.
+
+ +#### Type Constraints + +
+
T : tensor(uint32), tensor(uint64), tensor(int32), tensor(int64), tensor(float16), tensor(float), tensor(double)
+
Constrain input and output types to high-precision numeric tensors.
+
+ +### **Resize-11** + + Resize the input tensor. In general, it calculates every value in the output tensor as a weighted average of neighborhood (a.k.a. sampling locations) in the input tensor. + Each dimension value of the output tensor is: + output_dimension = floor(input_dimension * (roi_end - roi_start) * scale) if input \"sizes\" is not specified. + +#### Version + +This version of the operator has been available since version 11 of the default ONNX operator set. + +#### Attributes + +
+
coordinate_transformation_mode : string (default is half_pixel)
+
+This attribute describes how to transform the coordinate in the resized tensor to the coordinate in the original tensor.
+ +The coordinate of each dimension is transformed individually. Let's describe a case using axis x as an example. +Denote x_resized as the coordinate of axis x in the resized tensor, x_original as the coordinate of axis x in the original tensor, length_original as the length of the original tensor in axis x, length_resized as the length of the resized tensor in axis x, roi_x = (start_x, end_x) of the axis x in input "roi", scale = length_resized / length_original,
+ +if coordinate_transformation_mode is "half_pixel",
+x_original = (x_resized + 0.5) / scale - 0.5,
+ +if coordinate_transformation_mode is "pytorch_half_pixel",
+x_original = length_resized > 1 ? (x_resized + 0.5) / scale - 0.5 : 0,
+ +if coordinate_transformation_mode is "align_corners",
+x_original = x_resized * (length_original - 1) / (length_resized - 1),
+ +if coordinate_transformation_mode is "asymmetric",
+x_original = x_resized / scale,
+ +if coordinate_transformation_mode is "tf_half_pixel_for_nn",
+x_original = (x_resized + 0.5) / scale,
+ +if coordinate_transformation_mode is "tf_crop_and_resize",
+x_original = length_resized > 1 ? start_x * (length_original - 1) + x_resized * (end_x - start_x) * (length_original - 1) / (length_resized - 1) : 0.5 * (start_x + end_x) * (length_original - 1).
+
cubic_coeff_a : float (default is -0.75)
+
The coefficient 'a' used in cubic interpolation. Two common choice are -0.5 (in some cases of TensorFlow) and -0.75 (in PyTorch). Check out Equation (4) in https://ieeexplore.ieee.org/document/1163711 for the details. This attribute is valid only if "mode" is "cubic".
+
exclude_outside : int (default is 0)
+
If set to 1, the weight of sampling locations outside the tensor will be set to 0 and the weight will be renormalized so that their sum is 1.0. The default value is 0.
+
extrapolation_value : float (default is 0.0)
+
When coordinate_transformation_mode is "tf_crop_and_resize" and x_original is outside the range [0, length_original - 1], this value is used as the corresponding output value. Default is 0.0f.
+
mode : string (default is nearest)
+
Three interpolation modes: nearest (default), linear and cubic. The "linear" mode includes linear interpolation for 1D tensor and N-linear interpolation for N-D tensor (for example, bilinear interpolation for 2D tensor). The "cubic" mode includes cubic interpolation for 1D tensor and N-cubic interpolation for N-D tensor (for example, bicubic interpolation for 2D tensor).
+
nearest_mode : string (default is round_prefer_floor)
+
Four modes: round_prefer_floor (default, as known as round half down), round_prefer_ceil (as known as round half up), floor, ceil. Only used by nearest interpolation. It indicates how to get "nearest" pixel in input tensor from x_original, so this attribute is valid only if "mode" is "nearest".
+
+ +#### Inputs (3 - 4) + +
+
X : T1
+
N-D tensor
+
roi : T2
+
1-D tensor given as [start1, ..., startN, end1, ..., endN], where N is the rank of X. The RoIs' coordinates are normalized in the coordinate system of the input image. It only takes effect when coordinate_transformation_mode is "tf_crop_and_resize"
+
scales : tensor(float)
+
The scale array along each dimension. It takes value greater than 0. If it's less than 1, it's sampling down, otherwise, it's upsampling. The number of elements of 'scales' should be the same as the rank of input 'X'. Only one of 'scales' and 'sizes' can be specified. If 'size' is needed, the user can use an empty string as the name of 'scales' in this operator's input list.
+
sizes (optional) : tensor(int64)
+
The size of the output tensor. The number of elements of 'sizes' should be the same as the rank of input 'X'. Only one of 'scales' and 'sizes' can be specified.
+
+ +#### Outputs + +
+
Y : T1
+
N-D tensor after resizing
+
+ +#### Type Constraints + +
+
T1 : tensor(uint8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(int8), tensor(int16), tensor(int32), tensor(int64), tensor(float16), tensor(float), tensor(double), tensor(string), tensor(bool), tensor(complex64), tensor(complex128)
+
Constrain input 'X' and output 'Y' to all tensor types.
+
T2 : tensor(float16), tensor(float), tensor(double)
+
Constrain roi type to float or double.
+
+ +### **Round-11** + + Round takes one input Tensor and rounds the values, element-wise, meaning + it finds the nearest integer for each value. + In case of halfs, the rule is to round them to the nearest even integer. + The output tensor has the same shape and type as the input. + + Examples: + ``` + round([0.9]) = [1.0] + round([2.5]) = [2.0] + round([2.3]) = [2.0] + round([1.5]) = [2.0] + round([-4.5]) = [-4.0] + ``` + +#### Version + +This version of the operator has been available since version 11 of the default ONNX operator set. + +#### Inputs + +
+
X (non-differentiable) : T
+
Input tensor
+
+ +#### Outputs + +
+
Y (non-differentiable) : T
+
Output tensor
+
+ +#### Type Constraints + +
+
T : tensor(float16), tensor(float), tensor(double)
+
Constrain input and output types to float tensors.
+
+ +### **Scan-11** + + Scan can be used to iterate over one or more scan_input tensors, + constructing zero or more scan_output tensors. It combines ideas from general recurrences, + functional programming constructs such as scan, fold, map, and zip and is intended to enable + generalizations of RNN-like constructs for sequence-to-sequence processing. + Other tensors (referred to as state_variables here) can be used to carry a state + when iterating from one element to another (similar to hidden-state in RNNs, also referred + to as loop-carried dependences in the context of loops). + Many common usages involve a single scan_input tensor (where functionality + similar to scan, fold and map can be obtained). When more than one scan_input is used, + a behavior similar to zip is obtained. + + The attribute body must be a graph, specifying the computation to be performed in + every iteration. It takes as input the current values of the state_variables and + the current iterated element of the scan_inputs. It must return the (updated) values + of the state_variables and zero or more scan_output_element tensors. The values of the + scan_output_element tensors are concatenated over all the iterations to produce the + scan_output values of the scan construct (similar to the concatenated intermediate + hidden-state values of RNN-like constructs). All the output tensors (state_variables as + well as scan_output_element tensors) are required to have the same shape in each iteration + of the loop (a restriction imposed to enable efficient memory allocation). + + Note that the iterated element passed to the body subgraph does not have a sequence + axis. It will have a rank one less than the rank of the corresponding scan_input. + + The scan operation returns the final values of the state_variables as well as the + scan_outputs. + + The optional attribute scan_input_directions specifies the direction (forward or backward) + for each scan input. If this attribute is omitted, all sequences are scanned in the forward + direction. A bidirectional scan may be performed by specifying the same tensor input twice + in the scan_inputs, once with a forward direction, and once with a backward direction. + + The scan_output of the operation is produced by concatenating the scan_output_element + values produced by the body in each iteration. The optional attribute scan_output_directions + specifies the direction in which scan_output is constructed (by appending or prepending the + scan_output_element to scan_output in each iteration) for each scan_output. If this attribute + is omitted, the scan_output_element is appended to the scan_output in each iteration. + + The optional attribute scan_input_axes specifies the axis to be scanned for each scan_input. + If omitted, every scan_input will be scanned in axis 0. For example, if axis 0 is the + batch axis and axis 1 is the time axis (to be scanned), specify an axis value of 1. + Note that scanning a non-zero axis may be less efficient than scanning axis zero. + + The optional attribute scan_output_axes specifies the axis along which the scan_outputs + are accumulated for each scan_output. For example, if axis 1 is the time axis (to be + scanned) for both inputs and outputs, specify a scan_input axis and scan_output axis + value of 1. + + Note that because of the ONNX restriction that only the last parameter of an operator can + be variadic, the initial-states and scan-inputs are listed together as one input parameter. + Similarly, the final-states and scan-outputs are listed together as one output parameter. + The attribute num_scan_inputs indicates the number M of scan-inputs. + + The behavior of + + Scan < + num_scan_inputs = m, + body = loop-body, + scan_input_axes = [axis_1, ..., axis_m] + > (init_1, ..., init_n, scan_1, ..., scan_m) + + is equivalent to the following pseudo-code: + + // scan_i.shape[axis_i] denotes the (max) sequence-length of scan_i + // scan_i.shape[axis_i] is required to be equal to scan_j.shape[axis_j] for all i,j. + sequence_length = scan_1.shape[axis_1]; + + // initialize state-variables + st_1 = init_1; ... st_n = init_n; + // initialize scan-output variables: [] denotes an empty tensor + scan_out_1 = []; ...; scan_out_k = []; + // identify number of iterations: + + // execute loop + for (int t = 0; t < sequence_length; ++t) { + // generate the scan-input elements: the notation T[t] indicates the sub-tensor + // of rank one less than T obtained by indexing T at position t along axis k. + si_1 = scan_1[t]; + ... ; + si_m = scan_m[t]; + // execute loop-body + st_1, ..., st_n, so_1, ..., so_k = loop-body(st_1, ..., st_n, si_1, ..., si_m) + // accumulate the scan-output elements + scan_out_1 = Concat(scan_out_1, so_1); ... ; scan_out_k = Concat(scan_out_k, so_k); + } + + return st_1, ..., st_n, scan_out_1, ..., scan_out_k; + + *Sample usage: Encoding RNN using a Scan* + + The following example shows how a simple RNN over an input tensor %X, with weight tensor %Wi, + recurrence weight tensor %Ri, bias tensors %Wbi and %Rbi, and initial hidden-state %H_0 can + be encoded as a ScanLoop. Note that the loop-body is a nested graph, and it directly computes + %Wi, %Ri, %Wbi, and %Rbi (typically constants or initializers in the body graph). If these + values are computed in the outer graph, they need to be passed in as extra state_variables. + + graph rnn-encoding { + %H_0 = ... + %X = ... + %Y_h, %Y = Scan[body = , num_scan_inputs=1](%H_0, %X) + return %Y, %Y_h + } + + graph rnn-cell-1 ( + %H_tminus1[FLOAT, tensor] + %X_t[FLOAT, tensor] + ) { + %Wi = ... + %Ri = ... + %Wbi = ... + %Rbi = ... + %t1 = X_t * (Wi^T) + %t2 = H_tminus1*(Ri^T) + %t3 = Add(%t1, %t2) + %t4 = Add(%t3, %Wbi) + %t5 = Add(%t4, %Rbi) + %Ht = Tanh(%t5) + %Accumulate = Identity(%Ht) + return %Ht, %Accumulate + } + + +#### Version + +This version of the operator has been available since version 11 of the default ONNX operator set. + +#### Attributes + +
+
body : graph (required)
+
The graph run each iteration. It has N+M inputs: (loop state variables..., scan_input_elts...). It has N+K outputs: (loop state variables..., scan_output_elts...). Each scan_output is created by concatenating the value of the specified scan_output_elt value at the end of each iteration of the loop. It is an error if the dimensions of these values change across loop iterations.
+
num_scan_inputs : int (required)
+
An attribute specifying the number of scan_inputs M.
+
scan_input_axes : list of ints
+
An optional list of M flags. The i-th element of the list specifies the axis to be scanned (the sequence axis) for the i-th scan_input. If omitted, 0 will be used as the scan axis for every scan_input. Negative value for an axis means counting dimensions from the back. Accepted range is [-r, r-1] where r = rank(input).
+
scan_input_directions : list of ints
+
An optional list of M flags. The i-th element of the list specifies the direction to be scanned for the i-th scan_input tensor: 0 indicates forward direction and 1 indicates reverse direction. If omitted, all scan_input tensors will be scanned in the forward direction.
+
scan_output_axes : list of ints
+
An optional list of K flags. The i-th element of the list specifies the axis for the i-th scan_output. The scan outputs are accumulated along the specified axis. If omitted, 0 will be used as the scan axis for every scan_output. Negative value for an axis means counting dimensions from the back. Accepted range is [-r, r-1].
+
scan_output_directions : list of ints
+
An optional list of K flags, one for each scan_output. The i-th element of the list specifies whether the i-th scan_output should be constructed by appending or prepending a new value in each iteration: 0 indicates appending and 1 indicates prepending. If omitted, all scan_output tensors will be produced by appending a value in each iteration.
+
+ +#### Inputs (1 - ∞) + +
+
initial_state_and_scan_inputs (variadic, heterogeneous) : V
+
Initial values of the loop's N state variables followed by M scan_inputs
+
+ +#### Outputs (1 - ∞) + +
+
final_state_and_scan_outputs (variadic, heterogeneous) : V
+
Final values of the loop's N state variables followed by K scan_outputs
+
+ +#### Type Constraints + +
+
I : tensor(int64)
+
Int64 tensor
+
V : tensor(uint8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(int8), tensor(int16), tensor(int32), tensor(int64), tensor(float16), tensor(float), tensor(double), tensor(string), tensor(bool), tensor(complex64), tensor(complex128)
+
All Tensor types
+
+ +### **Scatter-11** (deprecated) + + This operator is deprecated. Please use ScatterElements, which provides the same functionality. + + Scatter takes three inputs `data`, `updates`, and `indices` of the same + rank r >= 1 and an optional attribute axis that identifies an axis of `data` + (by default, the outer-most axis, that is axis 0). The output of the operation + is produced by creating a copy of the input `data`, and then updating its value + to values specified by `updates` at specific index positions specified by + `indices`. Its output shape is the same as the shape of `data`. + + For each entry in `updates`, the target index in `data` is obtained by combining + the corresponding entry in `indices` with the index of the entry itself: the + index-value for dimension = axis is obtained from the value of the corresponding + entry in `indices` and the index-value for dimension != axis is obtained from the + index of the entry itself. + + For instance, in a 2-D tensor case, the update corresponding to the [i][j] entry + is performed as below: + ``` + output[indices[i][j]][j] = updates[i][j] if axis = 0, + output[i][indices[i][j]] = updates[i][j] if axis = 1, + ``` + + This operator is the inverse of GatherElements. It is similar to Torch's Scatter operation. + + Example 1: + ``` + data = [ + [0.0, 0.0, 0.0], + [0.0, 0.0, 0.0], + [0.0, 0.0, 0.0], + ] + indices = [ + [1, 0, 2], + [0, 2, 1], + ] + updates = [ + [1.0, 1.1, 1.2], + [2.0, 2.1, 2.2], + ] + output = [ + [2.0, 1.1, 0.0] + [1.0, 0.0, 2.2] + [0.0, 2.1, 1.2] + ] + ``` + Example 2: + ``` + data = [[1.0, 2.0, 3.0, 4.0, 5.0]] + indices = [[1, 3]] + updates = [[1.1, 2.1]] + axis = 1 + output = [[1.0, 1.1, 3.0, 2.1, 5.0]] + ``` + +#### Version + +This version of the operator has been deprecated since version 11 of the default ONNX operator set. + +### **ScatterElements-11** + + ScatterElements takes three inputs `data`, `updates`, and `indices` of the same + rank r >= 1 and an optional attribute axis that identifies an axis of `data` + (by default, the outer-most axis, that is axis 0). The output of the operation + is produced by creating a copy of the input `data`, and then updating its value + to values specified by `updates` at specific index positions specified by + `indices`. Its output shape is the same as the shape of `data`. + + For each entry in `updates`, the target index in `data` is obtained by combining + the corresponding entry in `indices` with the index of the entry itself: the + index-value for dimension = axis is obtained from the value of the corresponding + entry in `indices` and the index-value for dimension != axis is obtained from the + index of the entry itself. + + For instance, in a 2-D tensor case, the update corresponding to the [i][j] entry + is performed as below: + ``` + output[indices[i][j]][j] = updates[i][j] if axis = 0, + output[i][indices[i][j]] = updates[i][j] if axis = 1, + ``` + + This operator is the inverse of GatherElements. It is similar to Torch's Scatter operation. + + Example 1: + ``` + data = [ + [0.0, 0.0, 0.0], + [0.0, 0.0, 0.0], + [0.0, 0.0, 0.0], + ] + indices = [ + [1, 0, 2], + [0, 2, 1], + ] + updates = [ + [1.0, 1.1, 1.2], + [2.0, 2.1, 2.2], + ] + output = [ + [2.0, 1.1, 0.0] + [1.0, 0.0, 2.2] + [0.0, 2.1, 1.2] + ] + ``` + Example 2: + ``` + data = [[1.0, 2.0, 3.0, 4.0, 5.0]] + indices = [[1, 3]] + updates = [[1.1, 2.1]] + axis = 1 + output = [[1.0, 1.1, 3.0, 2.1, 5.0]] + ``` + +#### Version + +This version of the operator has been available since version 11 of the default ONNX operator set. + +#### Attributes + +
+
axis : int (default is 0)
+
Which axis to scatter on. Negative value means counting dimensions from the back. Accepted range is [-r, r-1] where r = rank(data).
+
+ +#### Inputs + +
+
data : T
+
Tensor of rank r >= 1.
+
indices : Tind
+
Tensor of int32/int64 indices, of r >= 1 (same rank as input). All index values are expected to be within bounds [-s, s-1] along axis of size s. It is an error if any of the index values are out of bounds.
+
updates : T
+
Tensor of rank r >=1 (same rank and shape as indices)
+
+ +#### Outputs + +
+
output : T
+
Tensor of rank r >= 1 (same rank as input).
+
+ +#### Type Constraints + +
+
T : tensor(uint8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(int8), tensor(int16), tensor(int32), tensor(int64), tensor(float16), tensor(float), tensor(double), tensor(string), tensor(bool), tensor(complex64), tensor(complex128)
+
Input and output types can be of any tensor type.
+
Tind : tensor(int32), tensor(int64)
+
Constrain indices to integer types
+
+ +### **ScatterND-11** + + ScatterND takes three inputs `data` tensor of rank r >= 1, `indices` tensor of rank q >= 1, + and `updates` tensor of rank q + r - indices.shape[-1] - 1. The output of the operation + is produced by creating a copy of the input `data`, and then updating its value to values + specified by `updates` at specific index positions specified by `indices`. Its output shape + is the same as the shape of `data`. Note that `indices` should not have duplicate entries. + That is, two or more `updates` for the same index-location is not supported. + + `indices` is an integer tensor. Let k denote indices.shape[-1], the last dimension in the shape of `indices`. + `indices` is treated as a (q-1)-dimensional tensor of k-tuples, where each k-tuple is a partial-index into `data`. + Hence, k can be a value at most the rank of `data`. When k equals rank(data), each update entry specifies an + update to a single element of the tensor. When k is less than rank(data) each update entry specifies an + update to a slice of the tensor. + + `updates` is treated as a (q-1)-dimensional tensor of replacement-slice-values. Thus, the + first (q-1) dimensions of updates.shape must match the first (q-1) dimensions of indices.shape. + The remaining dimensions of `updates` correspond to the dimensions of the + replacement-slice-values. Each replacement-slice-value is a (r-k) dimensional tensor, + corresponding to the trailing (r-k) dimensions of `data`. Thus, the shape of `updates` + must equal indices.shape[0:q-1] ++ data.shape[k:r-1], where ++ denotes the concatenation + of shapes. + + The `output` is calculated via the following equation: + + output = np.copy(data) + update_indices = indices.shape[:-1] + for idx in np.ndindex(update_indices): + output[indices[idx]] = updates[idx] + + The order of iteration in the above loop is not specified. + In particular, indices should not have duplicate entries: that is, if idx1 != idx2, then indices[idx1] != indices[idx2]. + This ensures that the output value does not depend on the iteration order. + + This operator is the inverse of GatherND. + + Example 1: + ``` + data = [1, 2, 3, 4, 5, 6, 7, 8] + indices = [[4], [3], [1], [7]] + updates = [9, 10, 11, 12] + output = [1, 11, 3, 10, 9, 6, 7, 12] + ``` + + Example 2: + ``` + data = [[[1, 2, 3, 4], [5, 6, 7, 8], [8, 7, 6, 5], [4, 3, 2, 1]], + [[1, 2, 3, 4], [5, 6, 7, 8], [8, 7, 6, 5], [4, 3, 2, 1]], + [[8, 7, 6, 5], [4, 3, 2, 1], [1, 2, 3, 4], [5, 6, 7, 8]], + [[8, 7, 6, 5], [4, 3, 2, 1], [1, 2, 3, 4], [5, 6, 7, 8]]] + indices = [[0], [2]] + updates = [[[5, 5, 5, 5], [6, 6, 6, 6], [7, 7, 7, 7], [8, 8, 8, 8]], + [[1, 1, 1, 1], [2, 2, 2, 2], [3, 3, 3, 3], [4, 4, 4, 4]]] + output = [[[5, 5, 5, 5], [6, 6, 6, 6], [7, 7, 7, 7], [8, 8, 8, 8]], + [[1, 2, 3, 4], [5, 6, 7, 8], [8, 7, 6, 5], [4, 3, 2, 1]], + [[1, 1, 1, 1], [2, 2, 2, 2], [3, 3, 3, 3], [4, 4, 4, 4]], + [[8, 7, 6, 5], [4, 3, 2, 1], [1, 2, 3, 4], [5, 6, 7, 8]]] + ``` + +#### Version + +This version of the operator has been available since version 11 of the default ONNX operator set. + +#### Inputs + +
+
data : T
+
Tensor of rank r >= 1.
+
indices : tensor(int64)
+
Tensor of rank q >= 1.
+
updates : T
+
Tensor of rank q + r - indices_shape[-1] - 1.
+
+ +#### Outputs + +
+
output : T
+
Tensor of rank r >= 1.
+
+ +#### Type Constraints + +
+
T : tensor(uint8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(int8), tensor(int16), tensor(int32), tensor(int64), tensor(float16), tensor(float), tensor(double), tensor(string), tensor(bool), tensor(complex64), tensor(complex128)
+
Constrain input and output types to any tensor type.
+
+ +### **SequenceAt-11** + + Outputs a tensor copy from the tensor at 'position' in 'input_sequence'. + Accepted range for 'position' is in `[-n, n - 1]`, where `n` is the number of tensors in 'input_sequence'. + Negative value means counting positions from the back. + +#### Version + +This version of the operator has been available since version 11 of the default ONNX operator set. + +#### Inputs + +
+
input_sequence : S
+
Input sequence.
+
position : I
+
Position of the tensor in the sequence. Negative value means counting positions from the back. Accepted range in `[-n, n - 1]`, where `n` is the number of tensors in 'input_sequence'. It is an error if any of the index values are out of bounds. It must be a scalar(tensor of empty shape).
+
+ +#### Outputs + +
+
tensor : T
+
Output tensor at the specified position in the input sequence.
+
+ +#### Type Constraints + +
+
S : seq(tensor(uint8)), seq(tensor(uint16)), seq(tensor(uint32)), seq(tensor(uint64)), seq(tensor(int8)), seq(tensor(int16)), seq(tensor(int32)), seq(tensor(int64)), seq(tensor(float16)), seq(tensor(float)), seq(tensor(double)), seq(tensor(string)), seq(tensor(bool)), seq(tensor(complex64)), seq(tensor(complex128))
+
Constrain to any tensor type.
+
T : tensor(uint8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(int8), tensor(int16), tensor(int32), tensor(int64), tensor(float16), tensor(float), tensor(double), tensor(string), tensor(bool), tensor(complex64), tensor(complex128)
+
Constrain to any tensor type.
+
I : tensor(int32), tensor(int64)
+
Constrain position to integral tensor. It must be a scalar(tensor of empty shape).
+
+ +### **SequenceConstruct-11** + + Construct a tensor sequence containing 'inputs' tensors. + All tensors in 'inputs' must have the same data type. + +#### Version + +This version of the operator has been available since version 11 of the default ONNX operator set. + +#### Inputs (1 - ∞) + +
+
inputs (variadic) : T
+
Tensors.
+
+ +#### Outputs + +
+
output_sequence : S
+
Sequence enclosing the input tensors.
+
+ +#### Type Constraints + +
+
T : tensor(uint8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(int8), tensor(int16), tensor(int32), tensor(int64), tensor(float16), tensor(float), tensor(double), tensor(string), tensor(bool), tensor(complex64), tensor(complex128)
+
Constrain input types to any tensor type.
+
S : seq(tensor(uint8)), seq(tensor(uint16)), seq(tensor(uint32)), seq(tensor(uint64)), seq(tensor(int8)), seq(tensor(int16)), seq(tensor(int32)), seq(tensor(int64)), seq(tensor(float16)), seq(tensor(float)), seq(tensor(double)), seq(tensor(string)), seq(tensor(bool)), seq(tensor(complex64)), seq(tensor(complex128))
+
Constrain output types to any tensor type.
+
+ +### **SequenceEmpty-11** + + Construct an empty tensor sequence, with given data type. + +#### Version + +This version of the operator has been available since version 11 of the default ONNX operator set. + +#### Attributes + +
+
dtype : int
+
(Optional) The data type of the tensors in the output sequence. The default type is 'float'.
+
+ +#### Inputs + + +#### Outputs + +
+
output : S
+
Empty sequence.
+
+ +#### Type Constraints + +
+
S : seq(tensor(uint8)), seq(tensor(uint16)), seq(tensor(uint32)), seq(tensor(uint64)), seq(tensor(int8)), seq(tensor(int16)), seq(tensor(int32)), seq(tensor(int64)), seq(tensor(float16)), seq(tensor(float)), seq(tensor(double)), seq(tensor(string)), seq(tensor(bool)), seq(tensor(complex64)), seq(tensor(complex128))
+
Constrain output types to any tensor type.
+
+ +### **SequenceErase-11** + + Outputs a tensor sequence that removes the tensor at 'position' from 'input_sequence'. + Accepted range for 'position' is in `[-n, n - 1]`, where `n` is the number of tensors in 'input_sequence'. + Negative value means counting positions from the back. + 'position' is optional, by default it erases the last tensor from 'input_sequence'. + +#### Version + +This version of the operator has been available since version 11 of the default ONNX operator set. + +#### Inputs (1 - 2) + +
+
input_sequence : S
+
Input sequence.
+
position (optional) : I
+
Position of the tensor in the sequence. Negative value means counting positions from the back. Accepted range in `[-n, n - 1]`, where `n` is the number of tensors in 'input_sequence'. It is an error if any of the index values are out of bounds. It must be a scalar(tensor of empty shape).
+
+ +#### Outputs + +
+
output_sequence : S
+
Output sequence that has the tensor at the specified position removed.
+
+ +#### Type Constraints + +
+
S : seq(tensor(uint8)), seq(tensor(uint16)), seq(tensor(uint32)), seq(tensor(uint64)), seq(tensor(int8)), seq(tensor(int16)), seq(tensor(int32)), seq(tensor(int64)), seq(tensor(float16)), seq(tensor(float)), seq(tensor(double)), seq(tensor(string)), seq(tensor(bool)), seq(tensor(complex64)), seq(tensor(complex128))
+
Constrain to any tensor type.
+
I : tensor(int32), tensor(int64)
+
Constrain position to integral tensor. It must be a scalar(tensor of empty shape).
+
+ +### **SequenceInsert-11** + + Outputs a tensor sequence that inserts 'tensor' into 'input_sequence' at 'position'. + 'tensor' must have the same data type as 'input_sequence'. + Accepted range for 'position' is in `[-n, n]`, where `n` is the number of tensors in 'input_sequence'. + Negative value means counting positions from the back. + 'position' is optional, by default it inserts 'tensor' to the back of 'input_sequence'. + +#### Version + +This version of the operator has been available since version 11 of the default ONNX operator set. + +#### Inputs (2 - 3) + +
+
input_sequence : S
+
Input sequence.
+
tensor : T
+
Input tensor to be inserted into the input sequence.
+
position (optional) : I
+
Position in the sequence where the new tensor is inserted. It is optional and default is to insert to the back of the sequence. Negative value means counting positions from the back. Accepted range in `[-n, n]`, where `n` is the number of tensors in 'input_sequence'. It is an error if any of the index values are out of bounds. It must be a scalar(tensor of empty shape).
+
+ +#### Outputs + +
+
output_sequence : S
+
Output sequence that contains the inserted tensor at given position.
+
+ +#### Type Constraints + +
+
T : tensor(uint8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(int8), tensor(int16), tensor(int32), tensor(int64), tensor(float16), tensor(float), tensor(double), tensor(string), tensor(bool), tensor(complex64), tensor(complex128)
+
Constrain to any tensor type.
+
S : seq(tensor(uint8)), seq(tensor(uint16)), seq(tensor(uint32)), seq(tensor(uint64)), seq(tensor(int8)), seq(tensor(int16)), seq(tensor(int32)), seq(tensor(int64)), seq(tensor(float16)), seq(tensor(float)), seq(tensor(double)), seq(tensor(string)), seq(tensor(bool)), seq(tensor(complex64)), seq(tensor(complex128))
+
Constrain to any tensor type.
+
I : tensor(int32), tensor(int64)
+
Constrain position to integral tensor. It must be a scalar(tensor of empty shape).
+
+ +### **SequenceLength-11** + + Produces a scalar(tensor of empty shape) containing the number of tensors in 'input_sequence'. + +#### Version + +This version of the operator has been available since version 11 of the default ONNX operator set. + +#### Inputs + +
+
input_sequence : S
+
Input sequence.
+
+ +#### Outputs + +
+
length : I
+
Length of input sequence. It must be a scalar(tensor of empty shape).
+
+ +#### Type Constraints + +
+
S : seq(tensor(uint8)), seq(tensor(uint16)), seq(tensor(uint32)), seq(tensor(uint64)), seq(tensor(int8)), seq(tensor(int16)), seq(tensor(int32)), seq(tensor(int64)), seq(tensor(float16)), seq(tensor(float)), seq(tensor(double)), seq(tensor(string)), seq(tensor(bool)), seq(tensor(complex64)), seq(tensor(complex128))
+
Constrain to any tensor type.
+
I : tensor(int64)
+
Constrain output to integral tensor. It must be a scalar(tensor of empty shape).
+
+ +### **Slice-11** + + Produces a slice of the input tensor along multiple axes. Similar to numpy: + https://docs.scipy.org/doc/numpy/reference/arrays.indexing.html + Slices uses `starts`, `ends`, `axes` and `steps` inputs to specify the start and end + dimension and step for each axis in the list of axes, it uses this information to + slice the input `data` tensor. If a negative value is passed for any of the + start or end indices, it represents number of elements before the end of that + dimension. If the value passed to start or end is larger than the `n` (the + number of elements in this dimension), it represents `n`. For slicing to the + end of a dimension with unknown size, it is recommended to pass in `INT_MAX` + when sclicing forward and 'INT_MIN' when slicing backward. + If a negative value is passed for step, it represents slicing backward. + However step value cannot be 0. + If `axes` are omitted, they are set to `[0, ..., ndim-1]`. + If `steps` are omitted, they are set to `[1, ..., 1]` of length `len(starts)` + Example 1: + data = [ + [1, 2, 3, 4], + [5, 6, 7, 8], + ] + axes = [0, 1] + starts = [1, 0] + ends = [2, 3] + steps = [1, 2] + result = [ + [5, 7], + ] + Example 2: + data = [ + [1, 2, 3, 4], + [5, 6, 7, 8], + ] + starts = [0, 1] + ends = [-1, 1000] + result = [ + [2, 3, 4], + ] + +#### Version + +This version of the operator has been available since version 11 of the default ONNX operator set. + +#### Inputs (3 - 5) + +
+
data : T
+
Tensor of data to extract slices from.
+
starts : Tind
+
1-D tensor of starting indices of corresponding axis in `axes`
+
ends : Tind
+
1-D tensor of ending indices (exclusive) of corresponding axis in `axes`
+
axes (optional) : Tind
+
1-D tensor of axes that `starts` and `ends` apply to. Negative value means counting dimensions from the back. Accepted range is [-r, r-1] where r = rank(data).
+
steps (optional) : Tind
+
1-D tensor of slice step of corresponding axis in `axes`. Negative value means slicing backward. 'steps' cannot be 0. Defaults to 1.
+
+ +#### Outputs + +
+
output : T
+
Sliced data tensor.
+
+ +#### Type Constraints + +
+
T : tensor(uint8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(int8), tensor(int16), tensor(int32), tensor(int64), tensor(float16), tensor(float), tensor(double), tensor(string), tensor(bool), tensor(complex64), tensor(complex128)
+
Constrain input and output types to all tensor types.
+
Tind : tensor(int32), tensor(int64)
+
Constrain indices to integer types
+
+ +### **Softmax-11** + + The operator computes the softmax (normalized exponential) values for each layer in the batch + of the given input. + + The input does not need to explicitly be a 2D vector; rather, it will be + coerced into one. For an arbitrary n-dimensional tensor + input \in [a_0, a_1, ..., a_{k-1}, a_k, ..., a_{n-1}] and k is + the axis provided, then input will be coerced into a 2-dimensional tensor with + dimensions [a_0 * ... * a_{k-1}, a_k * ... * a_{n-1}]. For the default + case where axis=1, this means the input tensor will be coerced into a 2D tensor + of dimensions [a_0, a_1 * ... * a_{n-1}], where a_0 is often the batch size. + In this situation, we must have a_0 = N and a_1 * ... * a_{n-1} = D. + Each of these dimensions must be matched correctly, or else the operator + will throw errors. The output tensor has the same shape + and contains the softmax values of the corresponding input. + +#### Version + +This version of the operator has been available since version 11 of the default ONNX operator set. + +#### Attributes + +
+
axis : int (default is 1)
+
Describes the axis of the inputs when coerced to 2D; defaults to one because the 0th axis most likely describes the batch_size. Negative value means counting dimensions from the back. Accepted range is [-r, r-1] where r = rank(input).
+
+ +#### Inputs + +
+
input : T
+
The input tensor that's coerced into a 2D matrix of size (NxD) as described above.
+
+ +#### Outputs + +
+
output : T
+
The output values with the same shape as input tensor (the original size without coercion).
+
+ +#### Type Constraints + +
+
T : tensor(float16), tensor(float), tensor(double)
+
Constrain input and output types to float tensors.
+
+ +### **Split-11** + + Split a tensor into a list of tensors, along the specified + 'axis'. Lengths of the parts can be specified using argument 'split'. + Otherwise, the tensor is split to equal sized parts. + +#### Version + +This version of the operator has been available since version 11 of the default ONNX operator set. + +#### Attributes + +
+
axis : int (default is 0)
+
Which axis to split on. A negative value means counting dimensions from the back. Accepted range is [-rank, rank-1] where r = rank(input).
+
split : list of ints
+
length of each output. Values should be >= 0.
+
+ +#### Inputs + +
+
input : T
+
The tensor to split
+
+ +#### Outputs (1 - ∞) + +
+
outputs (variadic) : T
+
One or more outputs forming list of tensors after splitting
+
+ +#### Type Constraints + +
+
T : tensor(uint8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(int8), tensor(int16), tensor(int32), tensor(int64), tensor(float16), tensor(float), tensor(double), tensor(string), tensor(bool), tensor(complex64), tensor(complex128)
+
Constrain input and output types to all tensor types.
+
+ +### **SplitToSequence-11** + + Split a tensor into a sequence of tensors, along the specified + 'axis'. Lengths of the parts can be specified using argument 'split'. + 'split' must contain only positive numbers. + 'split' is either a scalar (tensor of empty shape), or a 1-D tensor. + If 'split' is a scalar, then 'input' will be split into equally sized chunks(if possible). + Last chunk will be smaller if the 'input' size along the given axis 'axis' is not divisible + by 'split'. + Otherwise, the tensor is split into 'size(split)' chunks, with lengths of the parts on 'axis' + specified in 'split'. In this scenario, the sum of entries in 'split' must be equal to the + dimension size of input tensor on 'axis'. + +#### Version + +This version of the operator has been available since version 11 of the default ONNX operator set. + +#### Attributes + +
+
axis : int (default is 0)
+
Which axis to split on. A negative value means counting dimensions from the back. Accepted range is [-rank, rank-1].
+
keepdims : int (default is 1)
+
Keep the split dimension or not. Default 1, which means we keep split dimension. If input 'split' is specified, this attribute is ignored.
+
+ +#### Inputs (1 - 2) + +
+
input : T
+
The tensor to split
+
split (optional) : I
+
Length of each output. It can be either a scalar(tensor of empty shape), or a 1-D tensor. All values must be >= 0.
+
+ +#### Outputs + +
+
output_sequence : S
+
One or more outputs forming a sequence of tensors after splitting
+
+ +#### Type Constraints + +
+
T : tensor(uint8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(int8), tensor(int16), tensor(int32), tensor(int64), tensor(float16), tensor(float), tensor(double), tensor(string), tensor(bool), tensor(complex64), tensor(complex128)
+
Constrain input types to all tensor types.
+
I : tensor(int32), tensor(int64)
+
Constrain split size to integral tensor.
+
S : seq(tensor(uint8)), seq(tensor(uint16)), seq(tensor(uint32)), seq(tensor(uint64)), seq(tensor(int8)), seq(tensor(int16)), seq(tensor(int32)), seq(tensor(int64)), seq(tensor(float16)), seq(tensor(float)), seq(tensor(double)), seq(tensor(string)), seq(tensor(bool)), seq(tensor(complex64)), seq(tensor(complex128))
+
Constrain output types to all tensor types.
+
+ +### **Squeeze-11** + + Remove single-dimensional entries from the shape of a tensor. + Takes a parameter `axes` with a list of axes to squeeze. + If `axes` is not provided, all the single dimensions will be removed from + the shape. If an axis is selected with shape entry not equal to one, an error is raised. + +#### Version + +This version of the operator has been available since version 11 of the default ONNX operator set. + +#### Attributes + +
+
axes : list of ints
+
List of integers indicating the dimensions to squeeze. Negative value means counting dimensions from the back. Accepted range is [-r, r-1] where r = rank(data).
+
+ +#### Inputs + +
+
data : T
+
Tensors with at least max(dims) dimensions.
+
+ +#### Outputs + +
+
squeezed : T
+
Reshaped tensor with same data as input.
+
+ +#### Type Constraints + +
+
T : tensor(uint8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(int8), tensor(int16), tensor(int32), tensor(int64), tensor(float16), tensor(float), tensor(double), tensor(string), tensor(bool), tensor(complex64), tensor(complex128)
+
Constrain input and output types to all tensor types.
+
+ +### **TopK-11** + + Retrieve the top-K largest or smallest elements along a specified axis. Given an input tensor of + shape [a_1, a_2, ..., a_n, r] and integer argument k, return two outputs: + -Value tensor of shape [a_1, a_2, ..., a_{axis-1}, k, a_{axis+1}, ... a_n] + which contains the values of the top k elements along the specified axis + -Index tensor of shape [a_1, a_2, ..., a_{axis-1}, k, a_{axis+1}, ... a_n] which + contains the indices of the top k elements (original indices from the input + tensor). + + If "largest" is 1 (the default value) then the k largest elements are returned. + If "sorted" is 1 (the default value) then the resulting k elements will be sorted. + If "sorted" is 0, order of returned 'Values' and 'Indices' are undefined. + + Given two equivalent values, this operator uses the indices along the axis as + a tiebreaker. That is, the element with the lower index will appear first. + +#### Version + +This version of the operator has been available since version 11 of the default ONNX operator set. + +#### Attributes + +
+
axis : int (default is -1)
+
Dimension on which to do the sort. Negative value means counting dimensions from the back. Accepted range is [-r, r-1] where r = rank(input).
+
largest : int (default is 1)
+
Whether to return the top-K largest or smallest elements.
+
sorted : int (default is 1)
+
Whether to return the elements in sorted order.
+
+ +#### Inputs + +
+
X (differentiable) : T
+
Tensor of shape [a_1, a_2, ..., a_n, r]
+
K (non-differentiable) : tensor(int64)
+
A 1-D tensor containing a single positive value corresponding to the number of top elements to retrieve
+
+ +#### Outputs + +
+
Values (differentiable) : T
+
Tensor of shape [a_1, a_2, ..., a_{axis-1}, k, a_{axis+1}, ... a_n] containing top K values from the input tensor
+
Indices (non-differentiable) : I
+
Tensor of shape [a_1, a_2, ..., a_{axis-1}, k, a_{axis+1}, ... a_n] containing the corresponding input tensor indices for the top K values.
+
+ +#### Type Constraints + +
+
T : tensor(uint8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(int8), tensor(int16), tensor(int32), tensor(int64), tensor(float16), tensor(float), tensor(double)
+
Constrain input and output types to numeric tensors.
+
I : tensor(int64)
+
Constrain index tensor to int64
+
+ +### **Unique-11** + + Find the unique elements of a tensor. When an optional attribute 'axis' is provided, unique subtensors sliced along the 'axis' are returned. + Otherwise the input tensor is flattened and unique values of the flattened tensor are returned. + + This operator returns the unique values or sliced unique subtensors of the input tensor and three optional outputs. + The first output tensor 'Y' contains all unique values or subtensors of the input. + The second optional output tensor 'indices' contains indices of 'Y' elements' first occurance in 'X'.. + The third optional output tensor 'inverse_indices' contains, for elements of 'X', its corresponding indices in 'Y'. ". + The fourth optional output tensor 'counts' contains the count of each element of 'Y' in the input. + + Outputs are either sorted in ascending order or optionally in the order of the first occurrence of the values in the input. + + https://docs.scipy.org/doc/numpy/reference/generated/numpy.unique.html + + Example 1: + input_X = [2, 1, 1, 3, 4, 3] + attribute_sorted = 0 + attribute_axis = None + output_Y = [2, 1, 3, 4] + output_indices = [0, 1, 3, 4] + output_inverse_indices = [0, 1, 1, 2, 3, 2] + output_counts = [1, 2, 2, 1] + + Example 2: + input_X = [[1, 3], [2, 3]] + attribute_sorted = 1 + attribute_axis = None + output_Y = [1, 2, 3] + output_indices = [0, 2, 1] + output_inverse_indices = [0, 2, 1, 2] + output_counts = [1, 1, 2] + + Example 3: + input_X = [[1, 0, 0], [1, 0, 0], [2, 3, 4]] + attribute_sorted = 1 + attribute_axis = 0 + output_Y = [[1, 0, 0], [2, 3, 4]] + output_indices = [0, 2] + output_inverse_indices = [0, 0, 1] + output_counts = [2, 1] + + Example 4: + input_x = [[[1., 1.], [0., 1.], [2., 1.], [0., 1.]], + [[1., 1.], [0., 1.], [2., 1.], [0., 1.]]] + attribute_sorted = 1 + attribute_axis = 1 + + intermediate data are presented below for better understanding: + + there are 4 subtensors sliced along axis 1 of input_x (shape = (2, 4, 2)): + A: [[1, 1], [1, 1]], + [[0, 1], [0, 1]], + [[2, 1], [2, 1]], + [[0, 1], [0, 1]]. + + there are 3 unique subtensors: + [[1, 1], [1, 1]], + [[0, 1], [0, 1]], + [[2, 1], [2, 1]]. + + sorted unique subtensors: + B: [[0, 1], [0, 1]], + [[1, 1], [1, 1]], + [[2, 1], [2, 1]]. + + output_Y is constructed from B: + [[[0. 1.], [1. 1.], [2. 1.]], + [[0. 1.], [1. 1.], [2. 1.]]] + + output_indices is to map from B to A: + [1, 0, 2] + + output_inverse_indices is to map from A to B: + [1, 0, 2, 0] + + output_counts = [2 1 1] + +#### Version + +This version of the operator has been available since version 11 of the default ONNX operator set. + +#### Attributes + +
+
axis : int
+
(Optional) The dimension to apply unique. If not specified, the unique elements of the flattened input are returned. Negative value means counting dimensions from the back. Accepted range is [-r, r-1] where r = rank(input).
+
sorted : int (default is 1)
+
(Optional) Whether to sort the unique elements in ascending order before returning as output. Must be one of 0, or 1 (default).
+
+ +#### Inputs + +
+
X (non-differentiable) : T
+
A N-D input tensor that is to be processed.
+
+ +#### Outputs (1 - 4) + +
+
Y (non-differentiable) : T
+
A tensor of the same type as 'X' containing all the unique values or subtensors sliced along a provided 'axis' in 'X', either sorted or maintained in the same order they occur in input 'X'
+
indices (optional, non-differentiable) : tensor(int64)
+
A 1-D INT64 tensor containing indices of 'Y' elements' first occurance in 'X'. When 'axis' is provided, it contains indices to subtensors in input 'X' on the 'axis'. When 'axis' is not provided, it contains indices to values in the flattened input tensor.
+
inverse_indices (optional, non-differentiable) : tensor(int64)
+
A 1-D INT64 tensor containing, for elements of 'X', its corresponding indices in 'Y'. When 'axis' is provided, it contains indices to subtensors in output 'Y' on the 'axis'. When 'axis' is not provided, it contains indices to values in output 'Y'.
+
counts (optional, non-differentiable) : tensor(int64)
+
A 1-D INT64 tensor containing the count of each element of 'Y' in input 'X'
+
+ +#### Type Constraints + +
+
T : tensor(uint8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(int8), tensor(int16), tensor(int32), tensor(int64), tensor(float16), tensor(float), tensor(double), tensor(string), tensor(bool), tensor(complex64), tensor(complex128)
+
Input can be of any tensor type.
+
+ +### **Unsqueeze-11** + + Insert single-dimensional entries to the shape of an input tensor (`data`). + Takes one required argument `axes` - which contains a list of dimension indices and this operator will insert a dimension of value `1` into the corresponding index of the output tensor (`expanded`). + + For example: + Given an input tensor (`data`) of shape [3, 4, 5], then + Unsqueeze(data, axes=[0, 4]) outputs a tensor (`expanded`) containing same data as `data` but with shape [1, 3, 4, 5, 1]. + + The attribute `axes` should not contain any duplicate entries. It is an error if it contains duplicates. + The rank of the output tensor (`output_rank`) is the rank of the input tensor (`data`) plus the number of values in `axes`. + Each value in `axes` should be within the (inclusive) range [-output_rank , output_rank - 1]. + The order of values in `axes` does not matter and can come in any order. + + +#### Version + +This version of the operator has been available since version 11 of the default ONNX operator set. + +#### Attributes + +
+
axes : list of ints (required)
+
List of integers indicating the dimensions to be inserted. Negative value means counting dimensions from the back. Accepted range is [-r, r-1] where r = rank(expanded).
+
+ +#### Inputs + +
+
data : T
+
Original tensor
+
+ +#### Outputs + +
+
expanded : T
+
Reshaped tensor with same data as input.
+
+ +#### Type Constraints + +
+
T : tensor(uint8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(int8), tensor(int16), tensor(int32), tensor(int64), tensor(float16), tensor(float), tensor(double), tensor(string), tensor(bool), tensor(complex64), tensor(complex128)
+
Constrain input and output types to all tensor types.
+
+ +## Version 12 of the default ONNX operator set +### **ArgMax-12** + + Computes the indices of the max elements of the input tensor's element along the + provided axis. The resulting tensor has the same rank as the input if keepdims equal 1. + If keepdims equal 0, then the resulting tensor have the reduced dimension pruned. + If select_last_index is True (default False), the index of the last occurrence of the max + is selected if the max appears more than once in the input. Otherwise the index of the + first occurrence is selected. + The type of the output tensor is integer. + +#### Version + +This version of the operator has been available since version 12 of the default ONNX operator set. + +#### Attributes + +
+
axis : int (default is 0)
+
The axis in which to compute the arg indices. Accepted range is [-r, r-1] where r = rank(data).
+
keepdims : int (default is 1)
+
Keep the reduced dimension or not, default 1 mean keep reduced dimension.
+
select_last_index : int (default is 0)
+
Whether to select the last index or the first index if the {name} appears in multiple indices, default is False (first index).
+
+ +#### Inputs + +
+
data : T
+
An input tensor.
+
+ +#### Outputs + +
+
reduced : tensor(int64)
+
Reduced output tensor with integer data type.
+
+ +#### Type Constraints + +
+
T : tensor(uint8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(int8), tensor(int16), tensor(int32), tensor(int64), tensor(float16), tensor(float), tensor(double)
+
Constrain input and output types to all numeric tensors.
+
+ +### **ArgMin-12** + + Computes the indices of the min elements of the input tensor's element along the + provided axis. The resulting tensor has the same rank as the input if keepdims equal 1. + If keepdims equal 0, then the resulting tensor have the reduced dimension pruned. + If select_last_index is True (default False), the index of the last occurrence of the min + is selected if the min appears more than once in the input. Otherwise the index of the + first occurrence is selected. + The type of the output tensor is integer. + +#### Version + +This version of the operator has been available since version 12 of the default ONNX operator set. + +#### Attributes + +
+
axis : int (default is 0)
+
The axis in which to compute the arg indices. Accepted range is [-r, r-1] where r = rank(data).
+
keepdims : int (default is 1)
+
Keep the reduced dimension or not, default 1 mean keep reduced dimension.
+
select_last_index : int (default is 0)
+
Whether to select the last index or the first index if the {name} appears in multiple indices, default is False (first index).
+
+ +#### Inputs + +
+
data : T
+
An input tensor.
+
+ +#### Outputs + +
+
reduced : tensor(int64)
+
Reduced output tensor with integer data type.
+
+ +#### Type Constraints + +
+
T : tensor(uint8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(int8), tensor(int16), tensor(int32), tensor(int64), tensor(float16), tensor(float), tensor(double)
+
Constrain input and output types to all numeric tensors.
+
+ +### **Celu-12** + + Continuously Differentiable Exponential Linear Units: + Perform the linear unit element-wise on the input tensor X + using formula: + + ``` + max(0,x) + min(0,alpha*(exp(x/alpha)-1)) + ``` + +#### Version + +This version of the operator has been available since version 12 of the default ONNX operator set. + +#### Attributes + +
+
alpha : float (default is 1.0)
+
The Alpha value in Celu formula which control the shape of the unit. The default value is 1.0.
+
+ +#### Inputs + +
+
X (differentiable) : T
+
Input tensor
+
+ +#### Outputs + +
+
Y (differentiable) : T
+
Output tensor
+
+ +#### Type Constraints + +
+
T : tensor(float)
+
Constrain input and output types to float32 tensors.
+
+ +### **Clip-12** + + Clip operator limits the given input within an interval. The interval is + specified by the inputs 'min' and 'max'. They default to + numeric_limits::lowest() and numeric_limits::max(), respectively. + +#### Version + +This version of the operator has been available since version 12 of the default ONNX operator set. + +#### Inputs (1 - 3) + +
+
input : T
+
Input tensor whose elements to be clipped
+
min (optional) : T
+
Minimum value, under which element is replaced by min. It must be a scalar(tensor of empty shape).
+
max (optional) : T
+
Maximum value, above which element is replaced by max. It must be a scalar(tensor of empty shape).
+
+ +#### Outputs + +
+
output : T
+
Output tensor with clipped input elements
+
+ +#### Type Constraints + +
+
T : tensor(uint8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(int8), tensor(int16), tensor(int32), tensor(int64), tensor(float16), tensor(float), tensor(double)
+
Constrain input and output types to all numeric tensors.
+
+ +### **Constant-12** + + This operator produces a constant tensor. Exactly one of the provided attributes, either value, sparse_value, + or value_* must be specified. + +#### Version + +This version of the operator has been available since version 12 of the default ONNX operator set. + +#### Attributes + +
+
sparse_value : sparse_tensor
+
The value for the elements of the output tensor in sparse format.
+
value : tensor
+
The value for the elements of the output tensor.
+
value_float : float
+
The value for the sole element for the scalar, float32, output tensor.
+
value_floats : list of floats
+
The values for the elements for the 1D, float32, output tensor.
+
value_int : int
+
The value for the sole element for the scalar, int64, output tensor.
+
value_ints : list of ints
+
The values for the elements for the 1D, int64, output tensor.
+
value_string : string
+
The value for the sole element for the scalar, UTF-8 string, output tensor.
+
value_strings : list of strings
+
The values for the elements for the 1D, UTF-8 string, output tensor.
+
+ +#### Inputs + + +#### Outputs + +
+
output : T
+
Output tensor containing the same value of the provided tensor.
+
+ +#### Type Constraints + +
+
T : tensor(uint8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(int8), tensor(int16), tensor(int32), tensor(int64), tensor(float16), tensor(float), tensor(double), tensor(string), tensor(bool), tensor(complex64), tensor(complex128)
+
Constrain input and output types to all tensor types.
+
+ +### **Dropout-12** + + 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, + output (floating-point tensor) and mask (optional `Tensor`). If `training_mode` is true then the output Y will be a random dropout; + Note that this Dropout scales the masked input data by the following equation, so to convert the trained model into inference mode, + the user can simply not pass `training_mode` input or set it to false. + ``` + output = scale * data * mask, + ``` + where + ``` + scale = 1. / (1. - ratio). + ``` + This operator has **optional** inputs/outputs. See [the doc](IR.md) for more details about the representation of optional arguments. An empty string may be used in the place of an actual argument's name to indicate a missing argument. Trailing optional arguments (those not followed by an argument that is present) may also be simply omitted. + +#### Version + +This version of the operator has been available since version 12 of the default ONNX operator set. + +#### Attributes + +
+
seed : int
+
(Optional) Seed to the random generator, if not specified we will auto generate one.
+
+ +#### Inputs (1 - 3) + +
+
data : T
+
The input data as Tensor.
+
ratio (optional) : T1
+
The ratio of random dropout, with value in [0, 1). If this input was not set, or if it was set to 0, the output would be a simple copy of the input. If it's non-zero, output will be a random dropout of the scaled input, which is typically the case during training. It is an optional value, if not specified it will default to 0.5.
+
training_mode (optional) : T2
+
If set to true then it indicates dropout is being used for training. It is an optional value hence unless specified explicitly, it is false. If it is false, ratio is ignored and the operation mimics inference mode where nothing will be dropped from the input data and if mask is requested as output it will contain all ones.
+
+ +#### Outputs (1 - 2) + +
+
output : T
+
The output.
+
mask (optional) : T2
+
The output mask.
+
+ +#### Type Constraints + +
+
T : tensor(float16), tensor(float), tensor(double)
+
Constrain input and output types to float tensors.
+
T1 : tensor(float16), tensor(float), tensor(double)
+
Constrain input 'ratio' types to float tensors.
+
T2 : tensor(bool)
+
Constrain output 'mask' types to boolean tensors.
+
+ +### **Einsum-12** + + An einsum of the form ```term1, term2 -> output-term``` produces an output tensor using the following equation + + ```output[output-term] = reduce-sum( input1[term1] * input2[term] )``` + + where the reduce-sum performs a summation over all the indices occurring in the input terms (term1, term2) + that do not occur in the output-term. + + The Einsum operator evaluates algebraic tensor operations on a sequence of tensors, using the Einstein summation + convention. The equation string contains a comma-separated sequence of lower case letters. Each term corresponds to + an operand tensor, and the characters within the terms correspond to operands dimensions. + + This sequence may be followed by "->" to separate the left and right hand side of the equation. + If the equation contains "->" followed by the right-hand side, the explicit (not classical) form of the Einstein + summation is performed, and the right-hand side indices indicate output tensor dimensions. In other cases, + output indices are (implicitly) set to the alphabetically sorted sequence of indices appearing exactly once in the + equation. + + When a dimension character is repeated in the left-hand side, it represents summation along the dimension. + + The equation may contain ellipsis ("...") to enable broadcasting. Ellipsis must indicate a fixed number of dimensions. + Specifically, every occurrence of ellipsis in the equation must represent the same number of dimensions. + The right-hand side may contain exactly one ellipsis. In implicit mode, the ellipsis dimensions are set to the + beginning of the output. The equation string may contain space (U+0020) character. + +#### Version + +This version of the operator has been available since version 12 of the default ONNX operator set. + +#### Attributes + +
+
equation : string (required)
+
Einsum expression string.
+
+ +#### Inputs (1 - ∞) + +
+
Inputs (variadic, differentiable) : T
+
Operands
+
+ +#### Outputs + +
+
Output (differentiable) : T
+
Output tensor
+
+ +#### Type Constraints + +
+
T : tensor(uint8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(int8), tensor(int16), tensor(int32), tensor(int64), tensor(float16), tensor(float), tensor(double)
+
Constrain input and output types to all numerical tensor types.
+
+ +### **GatherND-12** + + Given `data` tensor of rank `r` >= 1, `indices` tensor of rank `q` >= 1, and `batch_dims` integer `b`, this operator gathers + slices of `data` into an output tensor of rank `q + r - indices_shape[-1] - 1 - b`. + + `indices` is an q-dimensional integer tensor, best thought of as a `(q-1)`-dimensional tensor of index-tuples into `data`, + where each element defines a slice of `data` + + `batch_dims` (denoted as `b`) is an integer indicating the number of batch dimensions, i.e the leading `b` number of dimensions of + `data` tensor and `indices` are representing the batches, and the gather starts from the `b+1` dimension. + + Some salient points about the inputs' rank and shape: + + 1) r >= 1 and q >= 1 are to be honored. There is no dependency condition to be met between ranks `r` and `q` + + 2) The first `b` dimensions of the shape of `indices` tensor and `data` tensor must be equal. + + 3) b < min(q, r) is to be honored. + + 4) The `indices_shape[-1]` should have a value between 1 (inclusive) and rank `r-b` (inclusive) + + 5) All values in `indices` are expected to be within bounds [-s, s-1] along axis of size `s` (i.e.) `-data_shape[i] <= indices[...,i] <= data_shape[i] - 1`. + It is an error if any of the index values are out of bounds. + + The output is computed as follows: + + The output tensor is obtained by mapping each index-tuple in the `indices` tensor to the corresponding slice of the input `data`. + + 1) If `indices_shape[-1] > r-b` => error condition + + 2) If `indices_shape[-1] == r-b`, since the rank of `indices` is `q`, `indices` can be thought of as `N` `(q-b-1)`-dimensional tensors + containing 1-D tensors of dimension `r-b`, where `N` is an integer equals to the product of 1 and all the elements in the batch dimensions + of the indices_shape. Let us think of each such `r-b` ranked tensor as `indices_slice`. Each *scalar value* corresponding to `data[0:b-1,indices_slice]` + is filled into the corresponding location of the `(q-b-1)`-dimensional tensor to form the `output` tensor (Example 1 below) + + 3) If `indices_shape[-1] < r-b`, since the rank of `indices` is `q`, `indices` can be thought of as `N` `(q-b-1)`-dimensional tensor + containing 1-D tensors of dimension `< r-b`. Let us think of each such tensors as `indices_slice`. Each *tensor slice* corresponding + to `data[0:b-1, indices_slice , :]` is filled into the corresponding location of the `(q-b-1)`-dimensional tensor + to form the `output` tensor (Examples 2, 3, 4 and 5 below) + + This operator is the inverse of `ScatterND`. + + `Example 1` + + batch_dims = 0 + + data = [[0,1],[2,3]] # data_shape = [2, 2] + + indices = [[0,0],[1,1]] # indices_shape = [2, 2] + + output = [0,3] # output_shape = [2] + + `Example 2` + + batch_dims = 0 + + data = [[0,1],[2,3]] # data_shape = [2, 2] + + indices = [[1],[0]] # indices_shape = [2, 1] + + output = [[2,3],[0,1]] # output_shape = [2, 2] + + `Example 3` + + batch_dims = 0 + + data = [[[0,1],[2,3]],[[4,5],[6,7]]] # data_shape = [2, 2, 2] + + indices = [[0,1],[1,0]] # indices_shape = [2, 2] + + output = [[2,3],[4,5]] # output_shape = [2, 2] + + `Example 4` + + batch_dims = 0 + + data = [[[0,1],[2,3]],[[4,5],[6,7]]] # data_shape = [2, 2, 2] + + indices = [[[0,1]],[[1,0]]] # indices_shape = [2, 1, 2] + + output = [[[2,3]],[[4,5]]] # output_shape = [2, 1, 2] + + `Example 5` + + batch_dims = 1 + + data = [[[0,1],[2,3]],[[4,5],[6,7]]] # data_shape = [2, 2, 2] + + indices = [[1],[0]] # indices_shape = [2, 1] + + output = [[2,3],[4,5]] # output_shape = [2, 2] + + + +#### Version + +This version of the operator has been available since version 12 of the default ONNX operator set. + +#### Attributes + +
+
batch_dims : int (default is 0)
+
The number of batch dimensions. The gather of indexing starts from dimension of data[batch_dims:]
+
+ +#### Inputs + +
+
data : T
+
Tensor of rank r >= 1.
+
indices : tensor(int64)
+
Tensor of rank q >= 1. All index values are expected to be within bounds [-s, s-1] along axis of size s. It is an error if any of the index values are out of bounds.
+
+ +#### Outputs + +
+
output : T
+
Tensor of rank q + r - indices_shape[-1] - 1.
+
+ +#### Type Constraints + +
+
T : tensor(uint8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(int8), tensor(int16), tensor(int32), tensor(int64), tensor(float16), tensor(float), tensor(double), tensor(string), tensor(bool), tensor(complex64), tensor(complex128)
+
Constrain input and output types to any tensor type.
+
+ +### **GreaterOrEqual-12** + + Returns the tensor resulted from performing the `greater_equal` logical operation + elementwise on the input tensors `A` and `B` (with Numpy-style broadcasting support). + + This operator supports **multidirectional (i.e., Numpy-style) broadcasting**; for more details please check [the doc](Broadcasting.md). + +#### Version + +This version of the operator has been available since version 12 of the default ONNX operator set. + +#### Inputs + +
+
A (non-differentiable) : T
+
First input operand for the logical operator.
+
B (non-differentiable) : T
+
Second input operand for the logical operator.
+
+ +#### Outputs + +
+
C (non-differentiable) : T1
+
Result tensor.
+
+ +#### Type Constraints + +
+
T : tensor(uint8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(int8), tensor(int16), tensor(int32), tensor(int64), tensor(float16), tensor(float), tensor(double)
+
Constrains input types to all numeric tensors.
+
T1 : tensor(bool)
+
Constrains output to boolean tensor.
+
+ +### **LessOrEqual-12** + + Returns the tensor resulted from performing the `less_equal` logical operation + elementwise on the input tensors `A` and `B` (with Numpy-style broadcasting support). + + This operator supports **multidirectional (i.e., Numpy-style) broadcasting**; for more details please check [the doc](Broadcasting.md). + +#### Version + +This version of the operator has been available since version 12 of the default ONNX operator set. + +#### Inputs + +
+
A (non-differentiable) : T
+
First input operand for the logical operator.
+
B (non-differentiable) : T
+
Second input operand for the logical operator.
+
+ +#### Outputs + +
+
C (non-differentiable) : T1
+
Result tensor.
+
+ +#### Type Constraints + +
+
T : tensor(uint8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(int8), tensor(int16), tensor(int32), tensor(int64), tensor(float16), tensor(float), tensor(double)
+
Constrains input types to all numeric tensors.
+
T1 : tensor(bool)
+
Constrains output to boolean tensor.
+
+ +### **Max-12** + + Element-wise max of each of the input tensors (with Numpy-style broadcasting support). + All inputs and outputs must have the same data type. + This operator supports **multidirectional (i.e., Numpy-style) broadcasting**; for more details please check [the doc](Broadcasting.md). + +#### Version + +This version of the operator has been available since version 12 of the default ONNX operator set. + +#### Inputs (1 - ∞) + +
+
data_0 (variadic) : T
+
List of tensors for max.
+
+ +#### Outputs + +
+
max : T
+
Output tensor.
+
+ +#### Type Constraints + +
+
T : tensor(uint8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(int8), tensor(int16), tensor(int32), tensor(int64), tensor(float16), tensor(float), tensor(double)
+
Constrain input and output types to numeric tensors.
+
+ +### **MaxPool-12** + + MaxPool consumes an input tensor X and applies max pooling across + the tensor according to kernel sizes, stride sizes, and pad lengths. + max pooling consisting of computing the max on all values of a + subset of the input tensor according to the kernel size and downsampling the + data into the output tensor Y for further processing. The output spatial shape will be following: + ``` + output_spatial_shape[i] = floor((input_spatial_shape[i] + pad_shape[i] - ((kernel_spatial_shape[i] - 1) * dilations[i] + 1)) / strides_spatial_shape[i] + 1) + ``` + or + ``` + output_spatial_shape[i] = ceil((input_spatial_shape[i] + pad_shape[i] - ((kernel_spatial_shape[i] - 1) * dilations[i] + 1)) / strides_spatial_shape[i] + 1) + ``` + if ceil_mode is enabled + + ``` + * pad_shape[i] is sum of pads along axis i + ``` + + `auto_pad` is a DEPRECATED attribute. If you are using them currently, the output spatial shape will be following: + ``` + VALID: output_spatial_shape[i] = ceil((input_spatial_shape[i] - ((kernel_spatial_shape[i] - 1) * dilations[i] + 1) + 1) / strides_spatial_shape[i]) + SAME_UPPER or SAME_LOWER: output_spatial_shape[i] = ceil(input_spatial_shape[i] / strides_spatial_shape[i]) + ``` + And pad shape will be following if `SAME_UPPER` or `SAME_LOWER`: + ``` + pad_shape[i] = (output_spatial_shape[i] - 1) * strides_spatial_shape[i] + ((kernel_spatial_shape[i] - 1) * dilations[i] + 1) - input_spatial_shape[i] + ``` + The output of each pooling window is maximum number of elements exclude pad. + + +#### Version + +This version of the operator has been available since version 12 of the default ONNX operator set. + +#### Attributes + +
+
auto_pad : string (default is NOTSET)
+
auto_pad must be either NOTSET, SAME_UPPER, SAME_LOWER or VALID. Where default value is NOTSET, which means explicit padding is used. SAME_UPPER or SAME_LOWER mean pad the input so that `output_shape[i] = ceil(input_shape[i] / strides[i])` for each axis `i`. The padding is split between the two sides equally or almost equally (depending on whether it is even or odd). In case the padding is an odd number, the extra padding is added at the end for SAME_UPPER and at the beginning for SAME_LOWER.
+
ceil_mode : int (default is 0)
+
Whether to use ceil or floor (default) to compute the output shape.
+
dilations : list of ints
+
Dilation value along each spatial axis of filter. If not present, the dilation defaults to 1 along each spatial axis.
+
kernel_shape : list of ints (required)
+
The size of the kernel along each axis.
+
pads : list of ints
+
Padding for the beginning and ending along each spatial axis, it can take any value greater than or equal to 0. The value represent the number of pixels added to the beginning and end part of the corresponding axis. `pads` format should be as follow [x1_begin, x2_begin...x1_end, x2_end,...], where xi_begin the number of pixels added at the beginning of axis `i` and xi_end, the number of pixels added at the end of axis `i`. This attribute cannot be used simultaneously with auto_pad attribute. If not present, the padding defaults to 0 along start and end of each spatial axis.
+
storage_order : int (default is 0)
+
The storage order of the tensor. 0 is row major, and 1 is column major.
+
strides : list of ints
+
Stride along each spatial axis. If not present, the stride defaults to 1 along each spatial axis.
+
+ +#### Inputs + +
+
X (differentiable) : T
+
Input data tensor from the previous operator; dimensions for image case are (N x C x H x W), where N is the batch size, C is the number of channels, and H and W are the height and the width of the data. For non image case, the dimensions are in the form of (N x C x D1 x D2 ... Dn), where N is the batch size. Optionally, if dimension denotation is in effect, the operation expects the input data tensor to arrive with the dimension denotation of [DATA_BATCH, DATA_CHANNEL, DATA_FEATURE, DATA_FEATURE ...].
+
+ +#### Outputs (1 - 2) + +
+
Y (differentiable) : T
+
Output data tensor from average or max pooling across the input tensor. Dimensions will vary based on various kernel, stride, and pad sizes. Floor value of the dimension is used
+
Indices (optional, non-differentiable) : I
+
Indices tensor from max pooling across the input tensor. The dimensions of indices are the same as output tensor. The values in indices of are the indices of the selected values during pooling. The indices are computed as flatten 1-D tensor, and the indices do not consider padding. So the values in indices are in [0, N x C x D1 x ... x Dn).
+
+ +#### Type Constraints + +
+
T : tensor(float16), tensor(float), tensor(double), tensor(int8), tensor(uint8)
+
Constrain input and output types to float and 8 bit tensors.
+
I : tensor(int64)
+
Constrain index tensor to int64
+
+ +### **Min-12** + + Element-wise min of each of the input tensors (with Numpy-style broadcasting support). + All inputs and outputs must have the same data type. + This operator supports **multidirectional (i.e., Numpy-style) broadcasting**; for more details please check [the doc](Broadcasting.md). + +#### Version + +This version of the operator has been available since version 12 of the default ONNX operator set. + +#### Inputs (1 - ∞) + +
+
data_0 (variadic) : T
+
List of tensors for min.
+
+ +#### Outputs + +
+
min : T
+
Output tensor.
+
+ +#### Type Constraints + +
+
T : tensor(uint8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(int8), tensor(int16), tensor(int32), tensor(int64), tensor(float16), tensor(float), tensor(double)
+
Constrain input and output types to numeric tensors.
+
+ +### **NegativeLogLikelihoodLoss-12** + + A NegativeLogLikelihoodLoss operator computes (weighted) negative log likelihood loss. + Its "input" tensor has the shape of (N, C, d1, d2, ..., dk) where k >= 0. + The "input" tensor contains log-probabilities for input[n, :, d_1, d_2,..., d_k] being in a class of [0, C). + The operator's "target" input tensor has the shape of (N, d1, d2, ..., dk). It encodes class labels (one of C classes) + or it may contain a special value (indicated by an attribute ignore_index) for N x d1 x d2 x ... x dk samples. + The loss value for input[n, :, d_1, d_2,...d_k] being classified as class c = target[n][d_1][d_2]...[d_k] is computed as: + loss[n][d_1][d_2]...[d_k] = -input[n][c][d_1][d_2]...[d_k]. + When an optional "weight" is provided, the sample loss is calculated as: + loss[n][d_1][d_2]...[d_k] = -input[n][c][d_1][d_2]...[d_k] * weight[c]. + loss is zero for the case when target-value equals ignore_index. + + loss[n][d_1][d_2]...[d_k] = 0, when target[n][d_1][d_2]...[d_k] = ignore_index + If "reduction" attribute is set to "none", the operator's output will be the above loss with shape (N, d1, d2, ..., dk). + If "reduction" attribute is set to "mean" (the default attribute value), the output loss is (weight) averaged: + mean(loss), if "weight" is not provided, + or if weight is provided, + sum(loss) / sum(weight[target[n][d_1][d_2]...[d_k]]]), for all samples. + If "reduction" attribute is set to "sum", the output is a scalar: + sum(loss). + See also https://pytorch.org/docs/stable/nn.html#torch.nn.NLLLoss. + Example 1: + // negative log likelihood loss, "none" reduction + N, C, d1 = 2, 3, 2 + input = [[[1.0, 2.0], [2.0, 2.0], [3.0, 2.0]], + [[0.0, 1.0], [2.0, 2.0], [1.0, 2]]] + target = [[2, 1], [0, 2]] + loss = np.zeros((N, d1)) + for n in range(N): + for d_1 in range(d1): + c = target[n][d_1] + loss[n][d_1] = -input[n][c][d_1] + // print(loss) + // [[-3. -2.] + // [-0. -2.]] + Example 2: + // weighted negative log likelihood loss, sum reduction + N, C, d1 = 2, 3, 2 + input = [[[1.0, 2.0], [2.0, 2.0], [3.0, 2.0]], + [[0.0, 1.0], [2.0, 2.0], [1.0, 2]]] + target = [[2, 1], [0, 2]] + weight = [0.2, 0.3, 0.1] + loss = np.zeros((N, d1)) + for n in range(N): + for d_1 in range(d1): + c = target[n][d_1] + loss[n][d_1] = -input[n][c][d_1] * weight[c] + loss = np.sum(loss) + // print(loss) + // -1.1 + Example 3: + // weighted negative log likelihood loss, mean reduction + N, C, d1 = 2, 3, 2 + input = [[[1.0, 2.0], [2.0, 2.0], [3.0, 2.0]], + [[0.0, 1.0], [2.0, 2.0], [1.0, 2]]] + target = [[2, 1], [0, 2]] + weight = [0.2, 0.3, 0.1] + loss = np.zeros((N, d1)) + weight_total = 0 + for n in range(N): + for d_1 in range(d1): + c = target[n][d_1] + loss[n][d_1] = -input[n][c][d_1] * weight[c] + weight_total = weight_total + weight[c] + loss = np.sum(loss) / weight_total + // print(loss) + // -1.57 + +#### Version + +This version of the operator has been available since version 12 of the default ONNX operator set. + +#### Attributes + +
+
ignore_index : int
+
Specifies a target value that is ignored and does not contribute to the input gradient. It's an optional value.
+
reduction : string (default is mean)
+
Type of reduction to apply to loss: none, sum, mean (default). 'none': the output is the loss for each sample. 'sum': the output will be summed. 'mean': the sum of the output will be divided by the sum of applied weights.
+
+ +#### Inputs (2 - 3) + +
+
input : T
+
Input tensor of shape (N, C) or (N, C, d1, d2, ..., dk).
+
target : Tind
+
Target tensor of shape (N) or (N, d1, d2, ..., dk). Target element value shall be in range of [0, C). If ignore_index is specified, it may have a value outside [0, C) and the target values should either be in the range [0, C) or have the value ignore_index.
+
weight (optional) : T
+
Optional rescaling weight tensor. If given, it has to be a tensor of size C. Otherwise, it is treated as if having all ones.
+
+ +#### Outputs + +
+
loss : T
+
The negative log likelihood loss
+
+ +#### Type Constraints + +
+
T : tensor(float16), tensor(float), tensor(double)
+
Constrain input, weight, and output types to floating-point tensors.
+
Tind : tensor(int32), tensor(int64)
+
Constrain target to integer types
+
+ +### **Pow-12** + + Pow takes input data (Tensor) and exponent Tensor, and + produces one output data (Tensor) where the function `f(x) = x^exponent`, + is applied to the data tensor elementwise. + This operator supports **multidirectional (i.e., Numpy-style) broadcasting**; for more details please check [the doc](Broadcasting.md). + +#### Version + +This version of the operator has been available since version 12 of the default ONNX operator set. + +#### Inputs + +
+
X : T
+
First operand, base of the exponent.
+
Y : T1
+
Second operand, power of the exponent.
+
+ +#### Outputs + +
+
Z : T
+
Output tensor.
+
+ +#### Type Constraints + +
+
T : tensor(int32), tensor(int64), tensor(float16), tensor(float), tensor(double)
+
Constrain input X and output types to float/int tensors.
+
T1 : tensor(uint8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(int8), tensor(int16), tensor(int32), tensor(int64), tensor(float16), tensor(float), tensor(double)
+
Constrain input Y types to float/int tensors.
+
+ +### **ReduceMax-12** + + Computes the max of the input tensor's element along the provided axes. The resulted + tensor has the same rank as the input if keepdims equal 1. If keepdims equal 0, then + the resulted tensor have the reduced dimension pruned. + + The above behavior is similar to numpy, with the exception that numpy default keepdims to + False instead of True. + +#### Version + +This version of the operator has been available since version 12 of the default ONNX operator set. + +#### Attributes + +
+
axes : list of ints
+
A list of integers, along which to reduce. The default is to reduce over all the dimensions of the input tensor. Accepted range is [-r, r-1] where r = rank(data).
+
keepdims : int (default is 1)
+
Keep the reduced dimension or not, default 1 mean keep reduced dimension.
+
+ +#### Inputs + +
+
data : T
+
An input tensor.
+
+ +#### Outputs + +
+
reduced : T
+
Reduced output tensor.
+
+ +#### Type Constraints + +
+
T : tensor(uint32), tensor(uint64), tensor(int32), tensor(int64), tensor(float16), tensor(float), tensor(double), tensor(uint8), tensor(int8)
+
Constrain input and output types to high-precision and 8 bit numeric tensors.
+
+ +### **ReduceMin-12** + + Computes the min of the input tensor's element along the provided axes. The resulted + tensor has the same rank as the input if keepdims equal 1. If keepdims equal 0, then + the resulted tensor have the reduced dimension pruned. + + The above behavior is similar to numpy, with the exception that numpy default keepdims to + False instead of True. + +#### Version + +This version of the operator has been available since version 12 of the default ONNX operator set. + +#### Attributes + +
+
axes : list of ints
+
A list of integers, along which to reduce. The default is to reduce over all the dimensions of the input tensor. Accepted range is [-r, r-1] where r = rank(data).
+
keepdims : int (default is 1)
+
Keep the reduced dimension or not, default 1 mean keep reduced dimension.
+
+ +#### Inputs + +
+
data : T
+
An input tensor.
+
+ +#### Outputs + +
+
reduced : T
+
Reduced output tensor.
+
+ +#### Type Constraints + +
+
T : tensor(uint32), tensor(uint64), tensor(int32), tensor(int64), tensor(float16), tensor(float), tensor(double), tensor(uint8), tensor(int8)
+
Constrain input and output types to high-precision and 8 bit numeric tensors.
+
+ +### **SoftmaxCrossEntropyLoss-12** + + Loss function that measures the softmax cross entropy + between 'scores' and 'labels'. + This operator first computes a loss tensor whose shape is identical to the labels input. + If the input is 2-D with shape (N, C), the loss tensor may be a N-element vector L = (l_1, l_2, ..., l_N). + If the input is N-D tensor with shape (N, C, D1, D2, ..., Dk), + the loss tensor L may have (N, D1, D2, ..., Dk) as its shape and L[i,][j_1][j_2]...[j_k] denotes a scalar element in L. + After L is available, this operator can optionally do a reduction operator. + + shape(scores): (N, C) where C is the number of classes, or (N, C, D1, D2,..., Dk), + with K >= 1 in case of K-dimensional loss. + shape(labels): (N) where each value is 0 <= labels[i] <= C-1, or (N, D1, D2,..., Dk), + with K >= 1 in case of K-dimensional loss. + + The loss for one sample, l_i, can caculated as follows: + l[i][d1][d2]...[dk] = -y[i][c][d1][d2]..[dk], where i is the index of classes. + or + l[i][d1][d2]...[dk] = -y[i][c][d1][d2]..[dk] * weights[c], if 'weights' is provided. + + loss is zero for the case when label-value equals ignore_index. + l[i][d1][d2]...[dk] = 0, when labels[n][d1][d2]...[dk] = ignore_index + + where: + p = Softmax(scores) + y = Log(p) + c = labels[i][d1][d2]...[dk] + + Finally, L is optionally reduced: + If reduction = 'none', the output is L with shape (N, D1, D2, ..., Dk). + If reduction = 'sum', the output is scalar: Sum(L). + If reduction = 'mean', the output is scalar: ReduceMean(L), or if weight is provided: ReduceSum(L) / ReduceSum(W), + where tensor W is of shape (N, D1, D2, ..., Dk) and W[n][d1][d2]...[dk] = weights[labels[i][d1][d2]...[dk]]. + +#### Version + +This version of the operator has been available since version 12 of the default ONNX operator set. + +#### Attributes + +
+
ignore_index : int
+
Specifies a target value that is ignored and does not contribute to the input gradient. It's an optional value.
+
reduction : string (default is mean)
+
Type of reduction to apply to loss: none, sum, mean(default). 'none': no reduction will be applied, 'sum': the output will be summed. 'mean': the sum of the output will be divided by the number of elements in the output.
+
+ +#### Inputs (2 - 3) + +
+
scores : T
+
The predicted outputs with shape [batch_size, class_size], or [batch_size, class_size, D1, D2 , ..., Dk], where K is the number of dimensions.
+
labels : Tind
+
The ground truth output tensor, with shape [batch_size], or [batch_size, D1, D2, ..., Dk], where K is the number of dimensions. Labels element value shall be in range of [0, C). If ignore_index is specified, it may have a value outside [0, C) and the label values should either be in the range [0, C) or have the value ignore_index.
+
weights (optional) : T
+
A manual rescaling weight given to each class. If given, it has to be a 1D Tensor assigning weight to each of the classes. Otherwise, it is treated as if having all ones.
+
+ +#### Outputs (1 - 2) + +
+
output : T
+
Weighted loss float Tensor. If reduction is 'none', this has the shape of [batch_size], or [batch_size, D1, D2, ..., Dk] in case of K-dimensional loss. Otherwise, it is a scalar.
+
log_prob (optional) : T
+
Log probability tensor. If the output of softmax is prob, its value is log(prob).
+
+ +#### Type Constraints + +
+
T : tensor(float16), tensor(float), tensor(double)
+
Constrain input and output types to float tensors.
+
Tind : tensor(int32), tensor(int64)
+
Constrain target to integer types
+
+ +## Version 13 of the default ONNX operator set +### **Abs-13** + + Absolute takes one input data (Tensor) and produces one output data + (Tensor) where the absolute is, y = abs(x), is applied to + the tensor elementwise. + +#### Version + +This version of the operator has been available since version 13 of the default ONNX operator set. + +#### Inputs + +
+
X (differentiable) : T
+
Input tensor
+
+ +#### Outputs + +
+
Y (differentiable) : T
+
Output tensor
+
+ +#### Type Constraints + +
+
T : tensor(uint8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(int8), tensor(int16), tensor(int32), tensor(int64), tensor(float16), tensor(float), tensor(double), tensor(bfloat16)
+
Constrain input and output types to all numeric tensors.
+
+ +### **Add-13** + + Performs element-wise binary addition (with Numpy-style broadcasting support). + + This operator supports **multidirectional (i.e., Numpy-style) broadcasting**; for more details please check [the doc](Broadcasting.md). + +#### Version + +This version of the operator has been available since version 13 of the default ONNX operator set. + +#### Inputs + +
+
A (differentiable) : T
+
First operand.
+
B (differentiable) : T
+
Second operand.
+
+ +#### Outputs + +
+
C (differentiable) : T
+
Result, has same element type as two inputs
+
+ +#### Type Constraints + +
+
T : tensor(uint32), tensor(uint64), tensor(int32), tensor(int64), tensor(float16), tensor(float), tensor(double), tensor(bfloat16)
+
Constrain input and output types to high-precision numeric tensors.
+
+ +### **ArgMax-13** + + Computes the indices of the max elements of the input tensor's element along the + provided axis. The resulting tensor has the same rank as the input if keepdims equal 1. + If keepdims equal 0, then the resulting tensor have the reduced dimension pruned. + If select_last_index is True (default False), the index of the last occurrence of the max + is selected if the max appears more than once in the input. Otherwise the index of the + first occurrence is selected. + The type of the output tensor is integer. + +#### Version + +This version of the operator has been available since version 13 of the default ONNX operator set. + +#### Attributes + +
+
axis : int (default is 0)
+
The axis in which to compute the arg indices. Accepted range is [-r, r-1] where r = rank(data).
+
keepdims : int (default is 1)
+
Keep the reduced dimension or not, default 1 mean keep reduced dimension.
+
select_last_index : int (default is 0)
+
Whether to select the last index or the first index if the {name} appears in multiple indices, default is False (first index).
+
+ +#### Inputs + +
+
data (non-differentiable) : T
+
An input tensor.
+
+ +#### Outputs + +
+
reduced (non-differentiable) : tensor(int64)
+
Reduced output tensor with integer data type.
+
+ +#### Type Constraints + +
+
T : tensor(uint8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(int8), tensor(int16), tensor(int32), tensor(int64), tensor(float16), tensor(float), tensor(double), tensor(bfloat16)
+
Constrain input and output types to all numeric tensors.
+
+ +### **ArgMin-13** + + Computes the indices of the min elements of the input tensor's element along the + provided axis. The resulting tensor has the same rank as the input if keepdims equal 1. + If keepdims equal 0, then the resulting tensor have the reduced dimension pruned. + If select_last_index is True (default False), the index of the last occurrence of the min + is selected if the min appears more than once in the input. Otherwise the index of the + first occurrence is selected. + The type of the output tensor is integer. + +#### Version + +This version of the operator has been available since version 13 of the default ONNX operator set. + +#### Attributes + +
+
axis : int (default is 0)
+
The axis in which to compute the arg indices. Accepted range is [-r, r-1] where r = rank(data).
+
keepdims : int (default is 1)
+
Keep the reduced dimension or not, default 1 mean keep reduced dimension.
+
select_last_index : int (default is 0)
+
Whether to select the last index or the first index if the {name} appears in multiple indices, default is False (first index).
+
+ +#### Inputs + +
+
data (non-differentiable) : T
+
An input tensor.
+
+ +#### Outputs + +
+
reduced (non-differentiable) : tensor(int64)
+
Reduced output tensor with integer data type.
+
+ +#### Type Constraints + +
+
T : tensor(uint8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(int8), tensor(int16), tensor(int32), tensor(int64), tensor(float16), tensor(float), tensor(double), tensor(bfloat16)
+
Constrain input and output types to all numeric tensors.
+
+ +### **Cast-13** + + The operator casts the elements of a given input tensor to a data type + specified by the 'to' argument and returns an output tensor of the same size in + the converted type. The 'to' argument must be one of the data types specified + in the 'DataType' enum field in the TensorProto message. + + Casting from string tensor in plain (e.g., "3.14" and "1000") and scientific numeric representations + (e.g., "1e-5" and "1E8") to float types is supported. For example, converting string "100.5" to an integer may + result 100. There are some string literals reserved for special floating-point values; + "+INF" (and "INF"), "-INF", and "NaN" are positive infinity, negative infinity, and not-a-number, respectively. + Any string which can exactly match "+INF" in a case-insensitive way would be mapped to positive infinite. Similarly, + this case-insensitive rule is applied to "INF" and "NaN". When casting from numeric tensors + to string tensors, plain floating-point representation (such as "314.15926") would be used. + Converting non-numerical-literal string such as "Hello World!" is an undefined behavior. Cases + of converting string representing floating-point arithmetic value, such as "2.718", to INT is an undefined behavior. + + Conversion from a numerical type to any numerical type is always allowed. + User must be aware of precision loss and value change caused by range difference between two types. + For example, a 64-bit float 3.1415926459 may be round to a 32-bit float 3.141592. Similarly, converting + an integer 36 to Boolean may produce 1 because we truncate bits which can't be stored in the targeted type. + +#### Version + +This version of the operator has been available since version 13 of the default ONNX operator set. + +#### Attributes + +
+
to : int (required)
+
The data type to which the elements of the input tensor are cast. Strictly must be one of the types from DataType enum in TensorProto
+
+ +#### Inputs + +
+
input (differentiable) : T1
+
Input tensor to be cast.
+
+ +#### Outputs + +
+
output (differentiable) : T2
+
Output tensor with the same shape as input with type specified by the 'to' argument
+
+ +#### Type Constraints + +
+
T1 : tensor(float16), tensor(float), tensor(double), tensor(int8), tensor(int16), tensor(int32), tensor(int64), tensor(uint8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(bool), tensor(string), tensor(bfloat16)
+
Constrain input types. Casting from complex is not supported.
+
T2 : tensor(float16), tensor(float), tensor(double), tensor(int8), tensor(int16), tensor(int32), tensor(int64), tensor(uint8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(bool), tensor(string), tensor(bfloat16)
+
Constrain output types. Casting to complex is not supported.
+
+ +### **Ceil-13** + + Ceil takes one input data (Tensor) and produces one output data + (Tensor) where the ceil is, y = ceil(x), is applied to + the tensor elementwise. + +#### Version + +This version of the operator has been available since version 13 of the default ONNX operator set. + +#### Inputs + +
+
X (non-differentiable) : T
+
Input tensor
+
+ +#### Outputs + +
+
Y (non-differentiable) : T
+
Output tensor
+
+ +#### Type Constraints + +
+
T : tensor(float16), tensor(float), tensor(double), tensor(bfloat16)
+
Constrain input and output types to float tensors.
+
+ +### **Clip-13** + + Clip operator limits the given input within an interval. The interval is + specified by the inputs 'min' and 'max'. They default to + numeric_limits::lowest() and numeric_limits::max(), respectively. + +#### Version + +This version of the operator has been available since version 13 of the default ONNX operator set. + +#### Inputs (1 - 3) + +
+
input (differentiable) : T
+
Input tensor whose elements to be clipped
+
min (optional, non-differentiable) : T
+
Minimum value, under which element is replaced by min. It must be a scalar(tensor of empty shape).
+
max (optional, non-differentiable) : T
+
Maximum value, above which element is replaced by max. It must be a scalar(tensor of empty shape).
+
+ +#### Outputs + +
+
output (differentiable) : T
+
Output tensor with clipped input elements
+
+ +#### Type Constraints + +
+
T : tensor(uint8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(int8), tensor(int16), tensor(int32), tensor(int64), tensor(float16), tensor(float), tensor(double), tensor(bfloat16)
+
Constrain input and output types to all numeric tensors.
+
+ +### **Concat-13** + + Concatenate a list of tensors into a single tensor. All input tensors must have the same shape, except for the dimension size of the axis to concatenate on. + +#### Version + +This version of the operator has been available since version 13 of the default ONNX operator set. + +#### Attributes + +
+
axis : int (required)
+
Which axis to concat on. A negative value means counting dimensions from the back. Accepted range is [-r, r-1] where r = rank(inputs)..
+
+ +#### Inputs (1 - ∞) + +
+
inputs (variadic, differentiable) : T
+
List of tensors for concatenation
+
+ +#### Outputs + +
+
concat_result (differentiable) : T
+
Concatenated tensor
+
+ +#### Type Constraints + +
+
T : tensor(uint8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(int8), tensor(int16), tensor(int32), tensor(int64), tensor(bfloat16), tensor(float16), tensor(float), tensor(double), tensor(string), tensor(bool), tensor(complex64), tensor(complex128)
+
Constrain output types to any tensor type.
+
+ +### **Constant-13** + + This operator produces a constant tensor. Exactly one of the provided attributes, either value, sparse_value, + or value_* must be specified. + +#### Version + +This version of the operator has been available since version 13 of the default ONNX operator set. + +#### Attributes + +
+
sparse_value : sparse_tensor
+
The value for the elements of the output tensor in sparse format.
+
value : tensor
+
The value for the elements of the output tensor.
+
value_float : float
+
The value for the sole element for the scalar, float32, output tensor.
+
value_floats : list of floats
+
The values for the elements for the 1D, float32, output tensor.
+
value_int : int
+
The value for the sole element for the scalar, int64, output tensor.
+
value_ints : list of ints
+
The values for the elements for the 1D, int64, output tensor.
+
value_string : string
+
The value for the sole element for the scalar, UTF-8 string, output tensor.
+
value_strings : list of strings
+
The values for the elements for the 1D, UTF-8 string, output tensor.
+
+ +#### Inputs + + +#### Outputs + +
+
output : T
+
Output tensor containing the same value of the provided tensor.
+
+ +#### Type Constraints + +
+
T : tensor(uint8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(int8), tensor(int16), tensor(int32), tensor(int64), tensor(bfloat16), tensor(float16), tensor(float), tensor(double), tensor(string), tensor(bool), tensor(complex64), tensor(complex128)
+
Constrain input and output types to all tensor types.
+
+ +### **DepthToSpace-13** + + DepthToSpace rearranges (permutes) data from depth into blocks of spatial data. + This is the reverse transformation of SpaceToDepth. More specifically, this op outputs a copy of + the input tensor where values from the depth dimension are moved in spatial blocks to the height + and width dimensions. By default, `mode` = `DCR`. + In the DCR mode, elements along the depth dimension from the input tensor are rearranged in the + following order: depth, column, and then row. The output y is computed from the input x as below: + + b, c, h, w = x.shape + + tmp = np.reshape(x, [b, blocksize, blocksize, c // (blocksize**2), h, w]) + + tmp = np.transpose(tmp, [0, 3, 4, 1, 5, 2]) + + y = np.reshape(tmp, [b, c // (blocksize**2), h * blocksize, w * blocksize]) + + + In the CRD mode, elements along the depth dimension from the input tensor are rearranged in the + following order: column, row, and the depth. The output y is computed from the input x as below: + + b, c, h, w = x.shape + + tmp = np.reshape(x, [b, c // (blocksize ** 2), blocksize, blocksize, h, w]) + + tmp = np.transpose(tmp, [0, 1, 4, 2, 5, 3]) + + y = np.reshape(tmp, [b, c // (blocksize ** 2), h * blocksize, w * blocksize]) + + +#### Version + +This version of the operator has been available since version 13 of the default ONNX operator set. + +#### Attributes + +
+
blocksize : int (required)
+
Blocks of [blocksize, blocksize] are moved.
+
mode : string (default is DCR)
+
DCR (default) for depth-column-row order re-arrangement. Use CRD for column-row-depth order.
+
+ +#### Inputs + +
+
input (differentiable) : T
+
Input tensor of [N,C,H,W], where N is the batch axis, C is the channel or depth, H is the height and W is the width.
+
+ +#### Outputs + +
+
output (differentiable) : T
+
Output tensor of [N, C/(blocksize * blocksize), H * blocksize, W * blocksize].
+
+ +#### Type Constraints + +
+
T : tensor(uint8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(int8), tensor(int16), tensor(int32), tensor(int64), tensor(bfloat16), tensor(float16), tensor(float), tensor(double), tensor(string), tensor(bool), tensor(complex64), tensor(complex128)
+
Constrain input and output types to all tensor types.
+
+ +### **DequantizeLinear-13** + + The linear dequantization operator. It consumes a quantized tensor, a scale, and a zero point to compute the full precision tensor. + The dequantization formula is y = (x - x_zero_point) * x_scale. 'x_scale' and 'x_zero_point' must have same shape, and can be either a scalar + for per-tensor / per layer quantization, or a 1-D tensor for per-axis quantization. + 'x_zero_point' and 'x' must have same type. 'x' and 'y' must have same shape. In the case of dequantizing int32, + there's no zero point (zero point is supposed to be 0). + +#### Version + +This version of the operator has been available since version 13 of the default ONNX operator set. + +#### Attributes + +
+
axis : int (default is 1)
+
(Optional) The axis of the dequantizing dimension of the input tensor. Ignored for per-tensor quantization. Negative value means counting dimensions from the back. Accepted range is [-r, r-1] where r = rank(input).
+
+ +#### Inputs (2 - 3) + +
+
x : T
+
N-D quantized input tensor to be de-quantized.
+
x_scale : tensor(float)
+
Scale for input 'x'. It can be a scalar, which means a per-tensor/layer dequantization, or a 1-D tensor for per-axis dequantization.
+
x_zero_point (optional) : T
+
Zero point for input 'x'. Shape must match x_scale. It's optional. Zero point is 0 when it's not specified.
+
+ +#### Outputs + +
+
y : tensor(float)
+
N-D full precision output tensor. It has same shape as input 'x'.
+
+ +#### Type Constraints + +
+
T : tensor(int8), tensor(uint8), tensor(int32)
+
Constrain 'x_zero_point' and 'x' to 8-bit/32-bit integer tensor.
+
+ +### **Div-13** + + Performs element-wise binary division (with Numpy-style broadcasting support). + + This operator supports **multidirectional (i.e., Numpy-style) broadcasting**; for more details please check [the doc](Broadcasting.md). + +#### Version + +This version of the operator has been available since version 13 of the default ONNX operator set. + +#### Inputs + +
+
A (differentiable) : T
+
First operand.
+
B (differentiable) : T
+
Second operand.
+
+ +#### Outputs + +
+
C (differentiable) : T
+
Result, has same element type as two inputs
+
+ +#### Type Constraints + +
+
T : tensor(uint32), tensor(uint64), tensor(int32), tensor(int64), tensor(float16), tensor(float), tensor(double), tensor(bfloat16)
+
Constrain input and output types to high-precision numeric tensors.
+
+ +### **Dropout-13** + + 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, + output (floating-point tensor) and mask (optional `Tensor`). If `training_mode` is true then the output Y will be a random dropout; + Note that this Dropout scales the masked input data by the following equation, so to convert the trained model into inference mode, + the user can simply not pass `training_mode` input or set it to false. + ``` + output = scale * data * mask, + ``` + where + ``` + scale = 1. / (1. - ratio). + ``` + This operator has **optional** inputs/outputs. See [the doc](IR.md) for more details about the representation of optional arguments. An empty string may be used in the place of an actual argument's name to indicate a missing argument. Trailing optional arguments (those not followed by an argument that is present) may also be simply omitted. + +#### Version + +This version of the operator has been available since version 13 of the default ONNX operator set. + +#### Attributes + +
+
seed : int
+
(Optional) Seed to the random generator, if not specified we will auto generate one.
+
+ +#### Inputs (1 - 3) + +
+
data (differentiable) : T
+
The input data as Tensor.
+
ratio (optional, non-differentiable) : T1
+
The ratio of random dropout, with value in [0, 1). If this input was not set, or if it was set to 0, the output would be a simple copy of the input. If it's non-zero, output will be a random dropout of the scaled input, which is typically the case during training. It is an optional value, if not specified it will default to 0.5.
+
training_mode (optional, non-differentiable) : T2
+
If set to true then it indicates dropout is being used for training. It is an optional value hence unless specified explicitly, it is false. If it is false, ratio is ignored and the operation mimics inference mode where nothing will be dropped from the input data and if mask is requested as output it will contain all ones.
+
+ +#### Outputs (1 - 2) + +
+
output (differentiable) : T
+
The output.
+
mask (optional, non-differentiable) : T2
+
The output mask.
+
+ +#### Type Constraints + +
+
T : tensor(float16), tensor(float), tensor(double), tensor(bfloat16)
+
Constrain input and output types to float tensors.
+
T1 : tensor(float16), tensor(float), tensor(double)
+
Constrain input 'ratio' types to float tensors.
+
T2 : tensor(bool)
+
Constrain output 'mask' types to boolean tensors.
+
+ +### **Equal-13** + + Returns the tensor resulted from performing the `equal` logical operation + elementwise on the input tensors `A` and `B` (with Numpy-style broadcasting support). + + This operator supports **multidirectional (i.e., Numpy-style) broadcasting**; for more details please check [the doc](Broadcasting.md). + +#### Version + +This version of the operator has been available since version 13 of the default ONNX operator set. + +#### Inputs + +
+
A (non-differentiable) : T
+
First input operand for the logical operator.
+
B (non-differentiable) : T
+
Second input operand for the logical operator.
+
+ +#### Outputs + +
+
C (non-differentiable) : T1
+
Result tensor.
+
+ +#### Type Constraints + +
+
T : tensor(bool), tensor(uint8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(int8), tensor(int16), tensor(int32), tensor(int64), tensor(float16), tensor(float), tensor(double), tensor(bfloat16)
+
Constrains input types to all numeric tensors.
+
T1 : tensor(bool)
+
Constrains output to boolean tensor.
+
+ +### **Erf-13** + + Computes the error function of the given input tensor element-wise. + +#### Version + +This version of the operator has been available since version 13 of the default ONNX operator set. + +#### Inputs + +
+
input (differentiable) : T
+
Input tensor
+
+ +#### Outputs + +
+
output (differentiable) : T
+
The error function of the input tensor computed element-wise. It has the same shape and type of the input.
+
+ +#### Type Constraints + +
+
T : tensor(uint8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(int8), tensor(int16), tensor(int32), tensor(int64), tensor(float16), tensor(float), tensor(double), tensor(bfloat16)
+
Constrain input and output types to all numeric tensors.
+
+ +### **Exp-13** + + Calculates the exponential of the given input tensor, element-wise. + +#### Version + +This version of the operator has been available since version 13 of the default ONNX operator set. + +#### Inputs + +
+
input (differentiable) : T
+
Input tensor
+
+ +#### Outputs + +
+
output (differentiable) : T
+
The exponential of the input tensor computed element-wise
+
+ +#### Type Constraints + +
+
T : tensor(float16), tensor(float), tensor(double), tensor(bfloat16)
+
Constrain input and output types to float tensors.
+
+ +### **Expand-13** + + Broadcast the input tensor following the given shape and the broadcast rule. + The broadcast rule is similar to numpy.array(input) * numpy.ones(shape): + Dimensions are right alignment; + Two corresponding dimension must have the same value, or one of them is equal to 1. + Also, this operator is similar to numpy.broadcast_to(input, shape), + but the major difference is numpy.broadcast_to() does not allow shape to be smaller than input.size(). + It is possible that the output.shape is not equal to shape, when some dimensions in shape is equal to 1, + or the shape.ndim < input.shape.ndim. + +#### Version + +This version of the operator has been available since version 13 of the default ONNX operator set. + +#### Inputs + +
+
input (differentiable) : T
+
Input tensor
+
shape (non-differentiable) : tensor(int64)
+
A 1-D tensor indicates the shape you want to expand to, following the broadcast rule
+
+ +#### Outputs + +
+
output (differentiable) : T
+
Output tensor
+
+ +#### Type Constraints + +
+
T : tensor(uint8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(int8), tensor(int16), tensor(int32), tensor(int64), tensor(bfloat16), tensor(float16), tensor(float), tensor(double), tensor(string), tensor(bool), tensor(complex64), tensor(complex128)
+
Constrain input and output types to all tensors.
+
+ +### **Flatten-13** + + Flattens the input tensor into a 2D matrix. If input tensor has shape + (d_0, d_1, ... d_n) then the output will have shape + (d_0 X d_1 ... d_(axis-1), d_axis X d_(axis+1) ... X dn). + +#### Version + +This version of the operator has been available since version 13 of the default ONNX operator set. + +#### Attributes + +
+
axis : int (default is 1)
+
Indicate up to which input dimensions (exclusive) should be flattened to the outer dimension of the output. The value for axis must be in the range [-r, r], where r is the rank of the input tensor. Negative value means counting dimensions from the back. When axis = 0, the shape of the output tensor is (1, (d_0 X d_1 ... d_n), where the shape of the input tensor is (d_0, d_1, ... d_n).
+
+ +#### Inputs + +
+
input (differentiable) : T
+
A tensor of rank >= axis.
+
+ +#### Outputs + +
+
output (differentiable) : T
+
A 2D tensor with the contents of the input tensor, with input dimensions up to axis flattened to the outer dimension of the output and remaining input dimensions flattened into the inner dimension of the output.
+
+ +#### Type Constraints + +
+
T : tensor(uint8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(int8), tensor(int16), tensor(int32), tensor(int64), tensor(bfloat16), tensor(float16), tensor(float), tensor(double), tensor(string), tensor(bool), tensor(complex64), tensor(complex128)
+
Constrain input and output to all tensor types.
+
+ +### **Floor-13** + + Floor takes one input data (Tensor) and produces one output data + (Tensor) where the floor is, y = floor(x), is applied to + the tensor elementwise. + +#### Version + +This version of the operator has been available since version 13 of the default ONNX operator set. + +#### Inputs + +
+
X (non-differentiable) : T
+
Input tensor
+
+ +#### Outputs + +
+
Y (non-differentiable) : T
+
Output tensor
+
+ +#### Type Constraints + +
+
T : tensor(float16), tensor(float), tensor(double), tensor(bfloat16)
+
Constrain input and output types to float tensors.
+
+ +### **Gather-13** + + Given `data` tensor of rank r >= 1, and `indices` tensor of rank q, gather + entries of the axis dimension of `data` (by default outer-most one as axis=0) indexed by `indices`, and concatenates + them in an output tensor of rank q + (r - 1). + + axis = 0 : + + Let + k = indices[i_{0}, ..., i_{q-1}] + Then + output[i_{0}, ..., i_{q-1}, j_{0}, ..., j_{r-2}] = input[k , j_{0}, ..., j_{r-2}] + + ``` + data = [ + [1.0, 1.2], + [2.3, 3.4], + [4.5, 5.7], + ] + indices = [ + [0, 1], + [1, 2], + ] + output = [ + [ + [1.0, 1.2], + [2.3, 3.4], + ], + [ + [2.3, 3.4], + [4.5, 5.7], + ], + ] + ``` + axis = 1 : + + Let + k = indices[i_{0}, ..., i_{q-1}] + Then + output[i_{0}, ..., i_{q-1}, j_{0}, ..., j_{r-2}] = input[j_{0}, k, j_{1}, ..., j_{r-2}] + + ``` + data = [ + [1.0, 1.2, 1.9], + [2.3, 3.4, 3.9], + [4.5, 5.7, 5.9], + ] + indices = [ + [0, 2], + ] + axis = 1, + output = [ + [[1.0, 1.9]], + [[2.3, 3.9]], + [[4.5, 5.9]], + ] + ``` + +#### Version + +This version of the operator has been available since version 13 of the default ONNX operator set. + +#### Attributes + +
+
axis : int (default is 0)
+
Which axis to gather on. Negative value means counting dimensions from the back. Accepted range is [-r, r-1] where r = rank(data).
+
+ +#### Inputs + +
+
data (differentiable) : T
+
Tensor of rank r >= 1.
+
indices (non-differentiable) : Tind
+
Tensor of int32/int64 indices, of any rank q. All index values are expected to be within bounds [-s, s-1] along axis of size s. It is an error if any of the index values are out of bounds.
+
+ +#### Outputs + +
+
output (differentiable) : T
+
Tensor of rank q + (r - 1).
+
+ +#### Type Constraints + +
+
T : tensor(uint8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(int8), tensor(int16), tensor(int32), tensor(int64), tensor(bfloat16), tensor(float16), tensor(float), tensor(double), tensor(string), tensor(bool), tensor(complex64), tensor(complex128)
+
Constrain input and output types to any tensor type.
+
Tind : tensor(int32), tensor(int64)
+
Constrain indices to integer types
+
+ +### **GatherElements-13** + + GatherElements takes two inputs `data` and `indices` of the same rank r >= 1 + and an optional attribute `axis` that identifies an axis of `data` + (by default, the outer-most axis, that is axis 0). It is an indexing operation + that produces its output by indexing into the input data tensor at index + positions determined by elements of the `indices` tensor. + Its output shape is the same as the shape of `indices` and consists of one value + (gathered from the `data`) for each element in `indices`. + + For instance, in the 3-D case (r = 3), the output produced is determined + by the following equations: + ``` + out[i][j][k] = input[index[i][j][k]][j][k] if axis = 0, + out[i][j][k] = input[i][index[i][j][k]][k] if axis = 1, + out[i][j][k] = input[i][j][index[i][j][k]] if axis = 2, + ``` + + This operator is also the inverse of ScatterElements. It is similar to Torch's gather operation. + + Example 1: + ``` + data = [ + [1, 2], + [3, 4], + ] + indices = [ + [0, 0], + [1, 0], + ] + axis = 1 + output = [ + [1, 1], + [4, 3], + ] + ``` + Example 2: + ``` + data = [ + [1, 2, 3], + [4, 5, 6], + [7, 8, 9], + ] + indices = [ + [1, 2, 0], + [2, 0, 0], + ] + axis = 0 + output = [ + [4, 8, 3], + [7, 2, 3], + ] + ``` + +#### Version + +This version of the operator has been available since version 13 of the default ONNX operator set. + +#### Attributes + +
+
axis : int (default is 0)
+
Which axis to gather on. Negative value means counting dimensions from the back. Accepted range is [-r, r-1] where r = rank(data).
+
+ +#### Inputs + +
+
data (differentiable) : T
+
Tensor of rank r >= 1.
+
indices (non-differentiable) : Tind
+
Tensor of int32/int64 indices, with the same rank r as the input. All index values are expected to be within bounds [-s, s-1] along axis of size s. It is an error if any of the index values are out of bounds.
+
+ +#### Outputs + +
+
output (differentiable) : T
+
Tensor of the same shape as indices.
+
+ +#### Type Constraints + +
+
T : tensor(uint8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(int8), tensor(int16), tensor(int32), tensor(int64), tensor(bfloat16), tensor(float16), tensor(float), tensor(double), tensor(string), tensor(bool), tensor(complex64), tensor(complex128)
+
Constrain input and output types to any tensor type.
+
Tind : tensor(int32), tensor(int64)
+
Constrain indices to integer types
+
+ +### **GatherND-13** + + Given `data` tensor of rank `r` >= 1, `indices` tensor of rank `q` >= 1, and `batch_dims` integer `b`, this operator gathers + slices of `data` into an output tensor of rank `q + r - indices_shape[-1] - 1 - b`. + + `indices` is an q-dimensional integer tensor, best thought of as a `(q-1)`-dimensional tensor of index-tuples into `data`, + where each element defines a slice of `data` + + `batch_dims` (denoted as `b`) is an integer indicating the number of batch dimensions, i.e the leading `b` number of dimensions of + `data` tensor and `indices` are representing the batches, and the gather starts from the `b+1` dimension. + + Some salient points about the inputs' rank and shape: + + 1) r >= 1 and q >= 1 are to be honored. There is no dependency condition to be met between ranks `r` and `q` + + 2) The first `b` dimensions of the shape of `indices` tensor and `data` tensor must be equal. + + 3) b < min(q, r) is to be honored. + + 4) The `indices_shape[-1]` should have a value between 1 (inclusive) and rank `r-b` (inclusive) + + 5) All values in `indices` are expected to be within bounds [-s, s-1] along axis of size `s` (i.e.) `-data_shape[i] <= indices[...,i] <= data_shape[i] - 1`. + It is an error if any of the index values are out of bounds. + + The output is computed as follows: + + The output tensor is obtained by mapping each index-tuple in the `indices` tensor to the corresponding slice of the input `data`. + + 1) If `indices_shape[-1] > r-b` => error condition + + 2) If `indices_shape[-1] == r-b`, since the rank of `indices` is `q`, `indices` can be thought of as `N` `(q-b-1)`-dimensional tensors + containing 1-D tensors of dimension `r-b`, where `N` is an integer equals to the product of 1 and all the elements in the batch dimensions + of the indices_shape. Let us think of each such `r-b` ranked tensor as `indices_slice`. Each *scalar value* corresponding to `data[0:b-1,indices_slice]` + is filled into the corresponding location of the `(q-b-1)`-dimensional tensor to form the `output` tensor (Example 1 below) + + 3) If `indices_shape[-1] < r-b`, since the rank of `indices` is `q`, `indices` can be thought of as `N` `(q-b-1)`-dimensional tensor + containing 1-D tensors of dimension `< r-b`. Let us think of each such tensors as `indices_slice`. Each *tensor slice* corresponding + to `data[0:b-1, indices_slice , :]` is filled into the corresponding location of the `(q-b-1)`-dimensional tensor + to form the `output` tensor (Examples 2, 3, 4 and 5 below) + + This operator is the inverse of `ScatterND`. + + `Example 1` + + batch_dims = 0 + + data = [[0,1],[2,3]] # data_shape = [2, 2] + + indices = [[0,0],[1,1]] # indices_shape = [2, 2] + + output = [0,3] # output_shape = [2] + + `Example 2` + + batch_dims = 0 + + data = [[0,1],[2,3]] # data_shape = [2, 2] + + indices = [[1],[0]] # indices_shape = [2, 1] + + output = [[2,3],[0,1]] # output_shape = [2, 2] + + `Example 3` + + batch_dims = 0 + + data = [[[0,1],[2,3]],[[4,5],[6,7]]] # data_shape = [2, 2, 2] + + indices = [[0,1],[1,0]] # indices_shape = [2, 2] + + output = [[2,3],[4,5]] # output_shape = [2, 2] + + `Example 4` + + batch_dims = 0 + + data = [[[0,1],[2,3]],[[4,5],[6,7]]] # data_shape = [2, 2, 2] + + indices = [[[0,1]],[[1,0]]] # indices_shape = [2, 1, 2] + + output = [[[2,3]],[[4,5]]] # output_shape = [2, 1, 2] + + `Example 5` + + batch_dims = 1 + + data = [[[0,1],[2,3]],[[4,5],[6,7]]] # data_shape = [2, 2, 2] + + indices = [[1],[0]] # indices_shape = [2, 1] + + output = [[2,3],[4,5]] # output_shape = [2, 2] + + + +#### Version + +This version of the operator has been available since version 13 of the default ONNX operator set. + +#### Attributes + +
+
batch_dims : int (default is 0)
+
The number of batch dimensions. The gather of indexing starts from dimension of data[batch_dims:]
+
+ +#### Inputs + +
+
data (differentiable) : T
+
Tensor of rank r >= 1.
+
indices (non-differentiable) : tensor(int64)
+
Tensor of rank q >= 1. All index values are expected to be within bounds [-s, s-1] along axis of size s. It is an error if any of the index values are out of bounds.
+
+ +#### Outputs + +
+
output (differentiable) : T
+
Tensor of rank q + r - indices_shape[-1] - 1.
+
+ +#### Type Constraints + +
+
T : tensor(uint8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(int8), tensor(int16), tensor(int32), tensor(int64), tensor(bfloat16), tensor(float16), tensor(float), tensor(double), tensor(string), tensor(bool), tensor(complex64), tensor(complex128)
+
Constrain input and output types to any tensor type.
+
+ +### **Gemm-13** + + General Matrix multiplication: + https://en.wikipedia.org/wiki/Basic_Linear_Algebra_Subprograms#Level_3 + + A' = transpose(A) if transA else A + + B' = transpose(B) if transB else B + + Compute Y = alpha * A' * B' + beta * C, where input tensor A has shape (M, K) or (K, M), + input tensor B has shape (K, N) or (N, K), input tensor C is broadcastable to shape (M, N), + and output tensor Y has shape (M, N). A will be transposed before doing the + computation if attribute transA is non-zero, same for B and transB. + This operator supports **unidirectional broadcasting** (tensor C should be unidirectional broadcastable to tensor A * B); for more details please check [the doc](Broadcasting.md). + This operator has **optional** inputs/outputs. See [the doc](IR.md) for more details about the representation of optional arguments. An empty string may be used in the place of an actual argument's name to indicate a missing argument. Trailing optional arguments (those not followed by an argument that is present) may also be simply omitted. + +#### Version + +This version of the operator has been available since version 13 of the default ONNX operator set. + +#### Attributes + +
+
alpha : float (default is 1.0)
+
Scalar multiplier for the product of input tensors A * B.
+
beta : float (default is 1.0)
+
Scalar multiplier for input tensor C.
+
transA : int (default is 0)
+
Whether A should be transposed
+
transB : int (default is 0)
+
Whether B should be transposed
+
+ +#### Inputs (2 - 3) + +
+
A (differentiable) : T
+
Input tensor A. The shape of A should be (M, K) if transA is 0, or (K, M) if transA is non-zero.
+
B (differentiable) : T
+
Input tensor B. The shape of B should be (K, N) if transB is 0, or (N, K) if transB is non-zero.
+
C (optional, differentiable) : T
+
Optional input tensor C. If not specified, the computation is done as if C is a scalar 0. The shape of C should be unidirectional broadcastable to (M, N).
+
+ +#### Outputs + +
+
Y (differentiable) : T
+
Output tensor of shape (M, N).
+
+ +#### Type Constraints + +
+
T : tensor(float16), tensor(float), tensor(double), tensor(uint32), tensor(uint64), tensor(int32), tensor(int64), tensor(bfloat16)
+
Constrain input and output types to float/int tensors.
+
+ +### **Greater-13** + + Returns the tensor resulted from performing the `greater` logical operation + elementwise on the input tensors `A` and `B` (with Numpy-style broadcasting support). + + This operator supports **multidirectional (i.e., Numpy-style) broadcasting**; for more details please check [the doc](Broadcasting.md). + +#### Version + +This version of the operator has been available since version 13 of the default ONNX operator set. + +#### Inputs + +
+
A (non-differentiable) : T
+
First input operand for the logical operator.
+
B (non-differentiable) : T
+
Second input operand for the logical operator.
+
+ +#### Outputs + +
+
C (non-differentiable) : T1
+
Result tensor.
+
+ +#### Type Constraints + +
+
T : tensor(uint8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(int8), tensor(int16), tensor(int32), tensor(int64), tensor(float16), tensor(float), tensor(double), tensor(bfloat16)
+
Constrains input types to all numeric tensors.
+
T1 : tensor(bool)
+
Constrains output to boolean tensor.
+
+ +### **Hardmax-13** + + The operator computes the hardmax values for the given input: + + Hardmax(element in input, axis) = 1 if the element is the first maximum value along the specified axis, 0 otherwise + + The "axis" attribute indicates the dimension along which Hardmax + will be performed. The output tensor has the same shape + and contains the Hardmax values of the corresponding input. + +#### Version + +This version of the operator has been available since version 13 of the default ONNX operator set. + +#### Attributes + +
+
axis : int (default is -1)
+
+Describes the dimension Hardmax will be performed on. +Negative value means counting dimensions +from the back. Accepted range is [-r, r-1] where r = rank(input). +
+
+ +#### Inputs + +
+
input (differentiable) : T
+
The input tensor of rank >= axis.
+
+ +#### Outputs + +
+
output (differentiable) : T
+
The output values with the same shape as the input tensor.
+
+ +#### Type Constraints + +
+
T : tensor(float16), tensor(float), tensor(double), tensor(bfloat16)
+
Constrain input and output types to float tensors.
+
+ +### **Identity-13** + + Identity operator + +#### Version + +This version of the operator has been available since version 13 of the default ONNX operator set. + +#### Inputs + +
+
input (differentiable) : T
+
Input tensor
+
+ +#### Outputs + +
+
output (differentiable) : T
+
Tensor to copy input into.
+
+ +#### Type Constraints + +
+
T : tensor(uint8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(int8), tensor(int16), tensor(int32), tensor(int64), tensor(bfloat16), tensor(float16), tensor(float), tensor(double), tensor(string), tensor(bool), tensor(complex64), tensor(complex128)
+
Constrain input and output types to all tensor types.
+
+ +### **If-13** + + If conditional + +#### Version + +This version of the operator has been available since version 13 of the default ONNX operator set. + +#### Attributes + +
+
else_branch : graph (required)
+
Graph to run if condition is false. Has N outputs: values you wish to be live-out to the enclosing scope. The number of outputs must match the number of outputs in the then_branch.
+
then_branch : graph (required)
+
Graph to run if condition is true. Has N outputs: values you wish to be live-out to the enclosing scope. The number of outputs must match the number of outputs in the else_branch.
+
+ +#### Inputs + +
+
cond : B
+
Condition for the if
+
+ +#### Outputs (1 - ∞) + +
+
outputs (variadic, heterogeneous) : V
+
Values that are live-out to the enclosing scope. The return values in the `then_branch` and `else_branch` must be of the same data type. The `then_branch` and `else_branch` may produce tensors with the same element type and different shapes. If corresponding outputs from the then-branch and the else-branch have static shapes S1 and S2, then the shape of the corresponding output variable of the if-node (if present) must be compatible with both S1 and S2 as it represents the union of both possible shapes.For example, if in a model file, the the first output of `then_branch` is typed float tensor with shape [2] and the first output of `else_branch` is another float tensor with shape [3], If's first output should have (a) no shape set, or (b) a shape of rank 1 with neither `dim_value` nor `dim_param` set, or (c) a shape of rank 1 with a unique `dim_param`. In contrast, the first output cannot have the shape [2] since [2] and [3] are not compatible.
+
+ +#### Type Constraints + +
+
V : tensor(uint8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(int8), tensor(int16), tensor(int32), tensor(int64), tensor(float16), tensor(float), tensor(double), tensor(string), tensor(bool), tensor(complex64), tensor(complex128), seq(tensor(uint8)), seq(tensor(uint16)), seq(tensor(uint32)), seq(tensor(uint64)), seq(tensor(int8)), seq(tensor(int16)), seq(tensor(int32)), seq(tensor(int64)), seq(tensor(float16)), seq(tensor(float)), seq(tensor(double)), seq(tensor(string)), seq(tensor(bool)), seq(tensor(complex64)), seq(tensor(complex128))
+
All Tensor and Sequence types
+
B : tensor(bool)
+
Only bool
+
+ +### **IsNaN-13** + + Returns which elements of the input are NaN. + +#### Version + +This version of the operator has been available since version 13 of the default ONNX operator set. + +#### Inputs + +
+
X (non-differentiable) : T1
+
input
+
+ +#### Outputs + +
+
Y (non-differentiable) : T2
+
output
+
+ +#### Type Constraints + +
+
T1 : tensor(float16), tensor(float), tensor(double), tensor(bfloat16)
+
Constrain input types to float tensors.
+
T2 : tensor(bool)
+
Constrain output types to boolean tensors.
+
+ +### **LRN-13** + + Local Response Normalization proposed in the [AlexNet paper](https://papers.nips.cc/paper/4824-imagenet-classification-with-deep-convolutional-neural-networks.pdf). + It normalizes over local input regions. + The local region is defined across the channels. For an element X[n, c, d1, ..., dk] in a tensor + of shape (N x C x D1 x D2, ..., Dk), its region is + {X[n, i, d1, ..., dk] | max(0, c - floor((size - 1) / 2)) <= i <= min(C - 1, c + ceil((size - 1) / 2))}. + + square_sum[n, c, d1, ..., dk] = sum(X[n, i, d1, ..., dk] ^ 2), + where max(0, c - floor((size - 1) / 2)) <= i <= min(C - 1, c + ceil((size - 1) / 2)). + + Y[n, c, d1, ..., dk] = X[n, c, d1, ..., dk] / (bias + alpha / size * square_sum[n, c, d1, ..., dk] ) ^ beta + +#### Version + +This version of the operator has been available since version 13 of the default ONNX operator set. + +#### Attributes + +
+
alpha : float (default is 0.0001)
+
Scaling parameter.
+
beta : float (default is 0.75)
+
The exponent.
+
bias : float (default is 1.0)
+
+
size : int (required)
+
The number of channels to sum over
+
+ +#### Inputs + +
+
X (differentiable) : T
+
Input data tensor from the previous operator; dimensions for image case are (N x C x H x W), where N is the batch size, C is the number of channels, and H and W are the height and the width of the data. For non image case, the dimensions are in the form of (N x C x D1 x D2 ... Dn), where N is the batch size. Optionally, if dimension denotation is in effect, the operation expects the input data tensor to arrive with the dimension denotation of [DATA_BATCH, DATA_CHANNEL, DATA_FEATURE, DATA_FEATURE ...].
+
+ +#### Outputs + +
+
Y (differentiable) : T
+
Output tensor, which has the shape and type as input tensor
+
+ +#### Type Constraints + +
+
T : tensor(float16), tensor(float), tensor(double), tensor(bfloat16)
+
Constrain input and output types to float tensors.
+
+ +### **Less-13** + + Returns the tensor resulted from performing the `less` logical operation + elementwise on the input tensors `A` and `B` (with Numpy-style broadcasting support). + + This operator supports **multidirectional (i.e., Numpy-style) broadcasting**; for more details please check [the doc](Broadcasting.md). + +#### Version + +This version of the operator has been available since version 13 of the default ONNX operator set. + +#### Inputs + +
+
A (non-differentiable) : T
+
First input operand for the logical operator.
+
B (non-differentiable) : T
+
Second input operand for the logical operator.
+
+ +#### Outputs + +
+
C (non-differentiable) : T1
+
Result tensor.
+
+ +#### Type Constraints + +
+
T : tensor(uint8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(int8), tensor(int16), tensor(int32), tensor(int64), tensor(float16), tensor(float), tensor(double), tensor(bfloat16)
+
Constrains input types to all numeric tensors.
+
T1 : tensor(bool)
+
Constrains output to boolean tensor.
+
+ +### **Log-13** + + Calculates the natural log of the given input tensor, element-wise. + +#### Version + +This version of the operator has been available since version 13 of the default ONNX operator set. + +#### Inputs + +
+
input (differentiable) : T
+
Input tensor
+
+ +#### Outputs + +
+
output (differentiable) : T
+
The natural log of the input tensor computed element-wise
+
+ +#### Type Constraints + +
+
T : tensor(float16), tensor(float), tensor(double), tensor(bfloat16)
+
Constrain input and output types to float tensors.
+
+ +### **LogSoftmax-13** + + The operator computes the log of softmax values for the given input: + + LogSoftmax(input, axis) = Log(Softmax(input, axis=axis)) + + The "axis" attribute indicates the dimension along which LogSoftmax + will be performed. The output tensor has the same shape + and contains the LogSoftmax values of the corresponding input. + +#### Version + +This version of the operator has been available since version 13 of the default ONNX operator set. + +#### Attributes + +
+
axis : int (default is -1)
+
+Describes the dimension LogSoftmax will be performed on. +Negative value means counting dimensions +from the back. Accepted range is [-r, r-1] where r = rank(input). +
+
+ +#### Inputs + +
+
input (differentiable) : T
+
The input tensor of rank >= axis.
+
+ +#### Outputs + +
+
output (differentiable) : T
+
The output values with the same shape as the input tensor.
+
+ +#### Type Constraints + +
+
T : tensor(float16), tensor(float), tensor(double), tensor(bfloat16)
+
Constrain input and output types to float tensors.
+
+ +### **Loop-13** + + Generic Looping construct. This loop has multiple termination conditions: + + 1) Trip count. Iteration count specified at runtime. Set by + specifying the input M. Optional. Set to empty string to omit. + Note that a static trip count (specified at graph construction time) can be + specified by passing in a constant node for input M. + 2) Loop termination condition. This is an input to the op that determines + whether to run the first iteration and also a loop-carried dependency for + the body graph. The body graph must yield a value for the condition variable, + whether this input is provided or not. + + This table summarizes the operating modes of this operator with equivalent + C-style code: + + Operator inputs defined as (max_trip_count, condition_var). + + input ("", ""): + for (int i=0; ; ++i) { + cond = ... // Note this value is ignored, but is required in the body + } + + input ("", cond) // Note this is analogous to a while loop + bool cond = ...; + for (int i=0; cond; ++i) { + cond = ...; + } + + input ("", 1) // Note this is analogous to a do-while loop + bool cond = true + for (int i=0; cond; ++i) { + cond = ...; + } + + input (trip_count, "") // Note this is analogous to a for loop + int trip_count = ... + for (int i=0; i < trip_count; ++i) { + cond = ...; // ignored + } + + input (trip_count, cond) + int trip_count = ...; + bool cond = ...; + for (int i=0; i < trip_count && cond; ++i) { + cond = ...; + } + + + *Sample usage - cond as well as trip count* + + graph predict-net { + %a = Constant[value = ]() + %b = Constant[value = ]() + %keepgoing = Constant[value = ]() + %max_trip_count = Constant[value = ]() + %keepgoing_out, %b_out, %user_defined_vals = Loop[body = ](%max_trip_count, %keepgoing, %b) + return + } + + graph body-net ( + %i[INT32, scalar] // iteration number + %keepgoing_in[BOOL, scalar] // incoming loop-termination-condition; not used + %b_in[INT32, scalar] // incoming value of loop-carried-dependency b + ) { + %my_local = Add(%a, %b_in) + %b_out = Sub(%a, %b_in) // outgoing value of loop-carried-dependency b + %keepgoing_out = Greater(%my_local, %b_out) // outgoing loop-termination-condition + %user_defined_val = Add(%b_in, %b_in) // scan-output value to be accumulated + return %keepgoing_out, %b_out, %user_defined_val + } + + *Sample equivalent C code* + + { + /* User-defined code (enclosing scope) */ + int a = 3, b = 6; + bool keepgoing = true; // Analogous to input cond + /* End user-defined code */ + + /* Implicitly-defined code */ + const int max_trip_count = 10; // Analogous to input M + int user_defined_vals[]; // Imagine this is resizable + /* End implicitly-defined code */ + /* initialize loop-carried variables and scan-output variables */ + bool keepgoing_out = keepgoing + int b_out = b + + for (int i=0; i < max_trip_count && keepgoing_out; ++i) { + /* Implicitly-defined code: bind actual parameter values + to formal parameter variables of loop-body */ + bool keepgoing_in = keepgoing_out; + bool b_in = b_out; + + /* User-defined code (loop body) */ + int my_local = a + b_in; // Reading value "a" from the enclosing scope is fine + b_out = a - b_in; + keepgoing_out = my_local > b_out; + user_defined_val = b_in + b_in; // b_in and b_out are different variables + /* End user-defined code */ + + /* Implicitly defined-code */ + user_defined_vals[i] = user_defined_val // accumulate scan-output values + } + // int t = my_local; // Can't do this. my_local is not accessible here. + + // The values below are bound to the output variables of the loop and therefore accessible + // b_out; user_defined_vals; keepgoing_out; + } + + There are several things of note in this code snippet: + + 1) Values from the enclosing scope (i.e. variable "a" here) are in scope and can + be referenced in the inputs of the loop. + 2) Any values computed in the loop body that needs to be used in a subsequent + iteration or after the loop are modelled using a pair of variables in the loop-body, + consisting of an input variable (eg., b_in) and an output variable (eg., b_out). + These are referred to as loop-carried dependences. The loop operation node + supplies the input value of the input variable for the first iteration, and + returns the output value of the output variable produced by the final + iteration. + 3) Scan_output variables are used to implicitly concatenate values computed across + all the iterations. In the above example, the value of user_defined_val computed + over all iterations are concatenated and returned as the value of user_defined_vals + after the loop. + 4) Values created in the body cannot be accessed in the enclosing scope, + except using the mechanism described above. + + Note that the semantics of this op support "diagonal" or "wavefront" execution. + (See Step 3 here for an example: + https://devblogs.nvidia.com/optimizing-recurrent-neural-networks-cudnn-5/). + Frontends should emit multi-layer RNNs as a series of While operators (with + time being the inner looping dimension), with each successive layer consuming + the scan_outputs from the previous layer, possibly going through several + point-wise operators (e.g. dropout, residual connections, linear layer). + + The input/output of subgraph (produced by loop node) matching is based on order instead of name. The implementation will figure out the names based on this order. + +#### Version + +This version of the operator has been available since version 13 of the default ONNX operator set. + +#### Attributes + +
+
body : graph (required)
+
The graph run each iteration. It has 2+N inputs: (iteration_num, condition, loop carried dependencies...). It has 1+N+K outputs: (condition, loop carried dependencies..., scan_outputs...). Each scan_output is created by concatenating the value of the specified output value at the end of each iteration of the loop. It is an error if the dimensions or data type of these scan_outputs change across loop iterations.
+
+ +#### Inputs (2 - ∞) + +
+
M (optional) : I
+
A maximum trip-count for the loop specified at runtime. Optional. Pass empty string to skip.
+
cond (optional) : B
+
A boolean termination condition. Optional. Pass empty string to skip.
+
v_initial (variadic, heterogeneous) : V
+
The initial values of any loop-carried dependencies (values that change across loop iterations)
+
+ +#### Outputs (1 - ∞) + +
+
v_final_and_scan_outputs (variadic, heterogeneous) : V
+
Final N loop carried dependency values then K scan_outputs. Scan outputs must be Tensors.
+
+ +#### Type Constraints + +
+
V : tensor(uint8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(int8), tensor(int16), tensor(int32), tensor(int64), tensor(float16), tensor(float), tensor(double), tensor(string), tensor(bool), tensor(complex64), tensor(complex128), seq(tensor(uint8)), seq(tensor(uint16)), seq(tensor(uint32)), seq(tensor(uint64)), seq(tensor(int8)), seq(tensor(int16)), seq(tensor(int32)), seq(tensor(int64)), seq(tensor(float16)), seq(tensor(float)), seq(tensor(double)), seq(tensor(string)), seq(tensor(bool)), seq(tensor(complex64)), seq(tensor(complex128))
+
All Tensor and Sequence types
+
I : tensor(int64)
+
tensor of int64, which should be a scalar.
+
B : tensor(bool)
+
tensor of bool, which should be a scalar.
+
+ +### **MatMul-13** + + Matrix product that behaves like numpy.matmul: https://docs.scipy.org/doc/numpy-1.13.0/reference/generated/numpy.matmul.html + +#### Version + +This version of the operator has been available since version 13 of the default ONNX operator set. + +#### Inputs + +
+
A (differentiable) : T
+
N-dimensional matrix A
+
B (differentiable) : T
+
N-dimensional matrix B
+
+ +#### Outputs + +
+
Y (differentiable) : T
+
Matrix multiply results from A * B
+
+ +#### Type Constraints + +
+
T : tensor(float16), tensor(float), tensor(double), tensor(uint32), tensor(uint64), tensor(int32), tensor(int64), tensor(bfloat16)
+
Constrain input and output types to float/int tensors.
+
+ +### **Max-13** + + Element-wise max of each of the input tensors (with Numpy-style broadcasting support). + All inputs and outputs must have the same data type. + This operator supports **multidirectional (i.e., Numpy-style) broadcasting**; for more details please check [the doc](Broadcasting.md). + +#### Version + +This version of the operator has been available since version 13 of the default ONNX operator set. + +#### Inputs (1 - ∞) + +
+
data_0 (variadic, differentiable) : T
+
List of tensors for max.
+
+ +#### Outputs + +
+
max (differentiable) : T
+
Output tensor.
+
+ +#### Type Constraints + +
+
T : tensor(uint8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(int8), tensor(int16), tensor(int32), tensor(int64), tensor(float16), tensor(float), tensor(double), tensor(bfloat16)
+
Constrain input and output types to numeric tensors.
+
+ +### **Mean-13** + + Element-wise mean of each of the input tensors (with Numpy-style broadcasting support). + All inputs and outputs must have the same data type. + This operator supports **multidirectional (i.e., Numpy-style) broadcasting**; for more details please check [the doc](Broadcasting.md). + +#### Version + +This version of the operator has been available since version 13 of the default ONNX operator set. + +#### Inputs (1 - ∞) + +
+
data_0 (variadic, differentiable) : T
+
List of tensors for mean.
+
+ +#### Outputs + +
+
mean (differentiable) : T
+
Output tensor.
+
+ +#### Type Constraints + +
+
T : tensor(float16), tensor(float), tensor(double), tensor(bfloat16)
+
Constrain input and output types to float tensors.
+
+ +### **MeanVarianceNormalization-13** + + A MeanVarianceNormalization Function: Perform mean variance normalization + on the input tensor X using formula:
``` (X-EX)/sqrt(E(X-EX)^2) ``` + +#### Version + +This version of the operator has been available since version 13 of the default ONNX operator set. + +#### Attributes + +
+
axes : list of ints (default is ['0', '2', '3'])
+
A list of integers, along which to reduce. The default is to caculate along axes [0,2,3] for calculating mean and variance along each channel. Two variables with the same C-coordinate are associated with the same mean and variance.
+
+ +#### Inputs + +
+
X (differentiable) : T
+
Input tensor
+
+ +#### Outputs + +
+
Y (differentiable) : T
+
Output tensor
+
+ +#### Type Constraints + +
+
T : tensor(float16), tensor(float), tensor(double), tensor(bfloat16)
+
Constrain input and output types to all numeric tensors.
+
+ +### **Min-13** + + Element-wise min of each of the input tensors (with Numpy-style broadcasting support). + All inputs and outputs must have the same data type. + This operator supports **multidirectional (i.e., Numpy-style) broadcasting**; for more details please check [the doc](Broadcasting.md). + +#### Version + +This version of the operator has been available since version 13 of the default ONNX operator set. + +#### Inputs (1 - ∞) + +
+
data_0 (variadic, differentiable) : T
+
List of tensors for min.
+
+ +#### Outputs + +
+
min (differentiable) : T
+
Output tensor.
+
+ +#### Type Constraints + +
+
T : tensor(uint8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(int8), tensor(int16), tensor(int32), tensor(int64), tensor(float16), tensor(float), tensor(double), tensor(bfloat16)
+
Constrain input and output types to numeric tensors.
+
+ +### **Mod-13** + + Performs element-wise binary modulus (with Numpy-style broadcasting support). + The sign of the remainder is the same as that of the Divisor. + + Mod operator can also behave like C fmod() or numpy.fmod. In this case, the sign of the remainder however, will be the same as the Dividend + (in contrast to integer mod). To force a behavior like numpy.fmod() an 'fmod' Attribute is provided. + This attribute is set to 0 by default causing the behavior to be like integer mod. + Setting this attribute to 1 causes the remainder to be calculated similar to that of numpy.fmod(). + + If the input type is floating point, then `fmod` attribute must be set to 1. + + In case of dividend being zero, the results will be platform dependent. + + This operator supports **multidirectional (i.e., Numpy-style) broadcasting**; for more details please check [the doc](Broadcasting.md). + +#### Version + +This version of the operator has been available since version 13 of the default ONNX operator set. + +#### Attributes + +
+
fmod : int (default is 0)
+
Whether the operator should behave like fmod (default=0 meaning it will do integer mods); Set this to 1 to force fmod treatment
+
+ +#### Inputs + +
+
A (differentiable) : T
+
Dividend tensor
+
B (non-differentiable) : T
+
Divisor tensor
+
+ +#### Outputs + +
+
C (differentiable) : T
+
Remainder tensor
+
+ +#### Type Constraints + +
+
T : tensor(uint8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(int8), tensor(int16), tensor(int32), tensor(int64), tensor(float16), tensor(float), tensor(double), tensor(bfloat16)
+
Constrain input and output types to high-precision numeric tensors.
+
+ +### **Mul-13** + + Performs element-wise binary multiplication (with Numpy-style broadcasting support). + + This operator supports **multidirectional (i.e., Numpy-style) broadcasting**; for more details please check [the doc](Broadcasting.md). + +#### Version + +This version of the operator has been available since version 13 of the default ONNX operator set. + +#### Inputs + +
+
A (differentiable) : T
+
First operand.
+
B (differentiable) : T
+
Second operand.
+
+ +#### Outputs + +
+
C (differentiable) : T
+
Result, has same element type as two inputs
+
+ +#### Type Constraints + +
+
T : tensor(uint32), tensor(uint64), tensor(int32), tensor(int64), tensor(float16), tensor(float), tensor(double), tensor(bfloat16)
+
Constrain input and output types to high-precision numeric tensors.
+
+ +### **Neg-13** + + Neg takes one input data (Tensor) and produces one output data + (Tensor) where each element flipped sign, y = -x, is applied to + the tensor elementwise. + +#### Version + +This version of the operator has been available since version 13 of the default ONNX operator set. + +#### Inputs + +
+
X (differentiable) : T
+
Input tensor
+
+ +#### Outputs + +
+
Y (differentiable) : T
+
Output tensor
+
+ +#### Type Constraints + +
+
T : tensor(float), tensor(int32), tensor(int8), tensor(int16), tensor(int64), tensor(float16), tensor(double), tensor(bfloat16)
+
Constrain input and output types to signed numeric tensors.
+
+ +### **NegativeLogLikelihoodLoss-13** + + A NegativeLogLikelihoodLoss operator computes (weighted) negative log likelihood loss. + Its "input" tensor has the shape of (N, C, d1, d2, ..., dk) where k >= 0. + The "input" tensor contains log-probabilities for input[n, :, d_1, d_2,..., d_k] being in a class of [0, C). + The operator's "target" input tensor has the shape of (N, d1, d2, ..., dk). It encodes class labels (one of C classes) + or it may contain a special value (indicated by an attribute ignore_index) for N x d1 x d2 x ... x dk samples. + The loss value for input[n, :, d_1, d_2,...d_k] being classified as class c = target[n][d_1][d_2]...[d_k] is computed as: + + loss[n][d_1][d_2]...[d_k] = -input[n][c][d_1][d_2]...[d_k]. + + When an optional "weight" is provided, the sample loss is calculated as: + + loss[n][d_1][d_2]...[d_k] = -input[n][c][d_1][d_2]...[d_k] * weight[c]. + + loss is zero for the case when target-value equals ignore_index. + + loss[n][d_1][d_2]...[d_k] = 0, when target[n][d_1][d_2]...[d_k] = ignore_index + + If "reduction" attribute is set to "none", the operator's output will be the above loss with shape (N, d1, d2, ..., dk). + If "reduction" attribute is set to "mean" (the default attribute value), the output loss is (weight) averaged: + + mean(loss), if "weight" is not provided, + + or if weight is provided, + + sum(loss) / sum(weight[target[n][d_1][d_2]...[d_k]]]), for all samples. + + If "reduction" attribute is set to "sum", the output is a scalar: + sum(loss). + + See also https://pytorch.org/docs/stable/nn.html#torch.nn.NLLLoss. + + Example 1: + + // negative log likelihood loss, "none" reduction + N, C, d1 = 2, 3, 2 + input = [[[1.0, 2.0], [2.0, 2.0], [3.0, 2.0]], + [[0.0, 1.0], [2.0, 2.0], [1.0, 2]]] + target = [[2, 1], [0, 2]] + + loss = np.zeros((N, d1)) + for n in range(N): + for d_1 in range(d1): + c = target[n][d_1] + loss[n][d_1] = -input[n][c][d_1] + + // print(loss) + // [[-3. -2.] + // [-0. -2.]] + + Example 2: + + // weighted negative log likelihood loss, sum reduction + N, C, d1 = 2, 3, 2 + input = [[[1.0, 2.0], [2.0, 2.0], [3.0, 2.0]], + [[0.0, 1.0], [2.0, 2.0], [1.0, 2]]] + target = [[2, 1], [0, 2]] + weight = [0.2, 0.3, 0.1] + loss = np.zeros((N, d1)) + for n in range(N): + for d_1 in range(d1): + c = target[n][d_1] + loss[n][d_1] = -input[n][c][d_1] * weight[c] + + loss = np.sum(loss) + // print(loss) + // -1.1 + + Example 3: + + // weighted negative log likelihood loss, mean reduction + N, C, d1 = 2, 3, 2 + input = [[[1.0, 2.0], [2.0, 2.0], [3.0, 2.0]], + [[0.0, 1.0], [2.0, 2.0], [1.0, 2]]] + target = [[2, 1], [0, 2]] + weight = [0.2, 0.3, 0.1] + loss = np.zeros((N, d1)) + weight_total = 0 + for n in range(N): + for d_1 in range(d1): + c = target[n][d_1] + loss[n][d_1] = -input[n][c][d_1] * weight[c] + weight_total = weight_total + weight[c] + + loss = np.sum(loss) / weight_total + // print(loss) + // -1.57 + +#### Version + +This version of the operator has been available since version 13 of the default ONNX operator set. + +#### Attributes + +
+
ignore_index : int
+
Specifies a target value that is ignored and does not contribute to the input gradient. It's an optional value.
+
reduction : string (default is mean)
+
Type of reduction to apply to loss: none, sum, mean (default). 'none': the output is the loss for each sample. 'sum': the output will be summed. 'mean': the sum of the output will be divided by the sum of applied weights.
+
+ +#### Inputs (2 - 3) + +
+
input (differentiable) : T
+
Input tensor of shape (N, C) or (N, C, d1, d2, ..., dk).
+
target (non-differentiable) : Tind
+
Target tensor of shape (N) or (N, d1, d2, ..., dk). Target element value shall be in range of [0, C). If ignore_index is specified, it may have a value outside [0, C) and the target values should either be in the range [0, C) or have the value ignore_index.
+
weight (optional, non-differentiable) : T
+
Optional rescaling weight tensor. If given, it has to be a tensor of size C. Otherwise, it is treated as if having all ones.
+
+ +#### Outputs + +
+
loss (differentiable) : T
+
The negative log likelihood loss
+
+ +#### Type Constraints + +
+
T : tensor(float16), tensor(float), tensor(double)
+
Constrain input, weight, and output types to floating-point tensors.
+
Tind : tensor(int32), tensor(int64)
+
Constrain target to integer types
+
+ +### **NonZero-13** + + Returns the indices of the elements that are non-zero + (in row-major order - by dimension). + NonZero behaves similar to numpy.nonzero: + https://docs.scipy.org/doc/numpy/reference/generated/numpy.nonzero.html + +#### Version + +This version of the operator has been available since version 13 of the default ONNX operator set. + +#### Inputs + +
+
X (non-differentiable) : T
+
input
+
+ +#### Outputs + +
+
Y (non-differentiable) : tensor(int64)
+
output
+
+ +#### Type Constraints + +
+
T : tensor(uint8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(int8), tensor(int16), tensor(int32), tensor(int64), tensor(bfloat16), tensor(float16), tensor(float), tensor(double), tensor(string), tensor(bool), tensor(complex64), tensor(complex128)
+
Constrain to all tensor types.
+
+ +### **Pad-13** + + Given a tensor containing the data to be padded (`data`), a tensor containing the number of start and end pad values for axis (`pads`), (optionally) a `mode`, and (optionally) `constant_value`, + a padded tensor (`output`) is generated. + + The three supported `modes` are (similar to corresponding modes supported by `numpy.pad`): + + 1) `constant`(default) - pads with a given constant value as specified by `constant_value` (which defaults to 0, empty string, or False) + + 2) `reflect` - pads with the reflection of the vector mirrored on the first and last values of the vector along each axis + + 3) `edge` - pads with the edge values of array + + + Example 1 (`constant` mode): + Insert 0 pads to the beginning of the second dimension. + + data = + [ + [1.0, 1.2], + [2.3, 3.4], + [4.5, 5.7], + ] + + pads = [0, 2, 0, 0] + + mode = 'constant' + + constant_value = 0.0 + + output = + [ + [0.0, 0.0, 1.0, 1.2], + [0.0, 0.0, 2.3, 3.4], + [0.0, 0.0, 4.5, 5.7], + ] + + + Example 2 (`reflect` mode): + data = + [ + [1.0, 1.2], + [2.3, 3.4], + [4.5, 5.7], + ] + + pads = [0, 2, 0, 0] + + mode = 'reflect' + + output = + [ + [1.0, 1.2, 1.0, 1.2], + [2.3, 3.4, 2.3, 3.4], + [4.5, 5.7, 4.5, 5.7], + ] + + + Example 3 (`edge` mode): + data = + [ + [1.0, 1.2], + [2.3, 3.4], + [4.5, 5.7], + ] + + pads = [0, 2, 0, 0] + + mode = 'edge' + + output = + [ + [1.0, 1.0, 1.0, 1.2], + [2.3, 2.3, 2.3, 3.4], + [4.5, 4.5, 4.5, 5.7], + ] + + +#### Version + +This version of the operator has been available since version 13 of the default ONNX operator set. + +#### Attributes + +
+
mode : string (default is constant)
+
Supported modes: `constant`(default), `reflect`, `edge`
+
+ +#### Inputs (2 - 3) + +
+
data (differentiable) : T
+
Input tensor.
+
pads (non-differentiable) : tensor(int64)
+
Tensor of integers indicating the number of padding elements to add or remove (if negative) at the beginning and end of each axis. For 2D input tensor, it is the number of pixels. `pads` should be a 1D tensor of shape [2 * input_rank]. `pads` format should be: [x1_begin, x2_begin,...,x1_end, x2_end,...], where xi_begin is the number of pad values added at the beginning of axis `i` and xi_end, the number of pad values added at the end of axis `i`.
+
constant_value (optional, non-differentiable) : T
+
(Optional) A scalar value to be used if the mode chosen is `constant` (by default it is 0, empty string or False).
+
+ +#### Outputs + +
+
output (differentiable) : T
+
Tensor after padding.
+
+ +#### Type Constraints + +
+
T : tensor(uint8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(int8), tensor(int16), tensor(int32), tensor(int64), tensor(bfloat16), tensor(float16), tensor(float), tensor(double), tensor(string), tensor(bool), tensor(complex64), tensor(complex128)
+
Constrain input and output types to all tensor types.
+
+ +### **Pow-13** + + Pow takes input data (Tensor) and exponent Tensor, and + produces one output data (Tensor) where the function `f(x) = x^exponent`, + is applied to the data tensor elementwise. + This operator supports **multidirectional (i.e., Numpy-style) broadcasting**; for more details please check [the doc](Broadcasting.md). + +#### Version + +This version of the operator has been available since version 13 of the default ONNX operator set. + +#### Inputs + +
+
X (differentiable) : T
+
First operand, base of the exponent.
+
Y (differentiable) : T1
+
Second operand, power of the exponent.
+
+ +#### Outputs + +
+
Z (differentiable) : T
+
Output tensor
+
+ +#### Type Constraints + +
+
T : tensor(int32), tensor(int64), tensor(float16), tensor(float), tensor(double), tensor(bfloat16)
+
Constrain input X and output types to float/int tensors.
+
T1 : tensor(uint8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(int8), tensor(int16), tensor(int32), tensor(int64), tensor(float16), tensor(float), tensor(double)
+
Constrain input Y types to float/int tensors.
+
+ +### **QuantizeLinear-13** + + The linear quantization operator. It consumes a high precision tensor, a scale, and a zero point to compute the low precision / quantized tensor. + The scale factor and zero point must have same shape, and can be either a scalar for per-tensor / per layer quantization, or a 1-D tensor for per-axis quantization. + The quantization formula is y = saturate ((x / y_scale) + y_zero_point). + For saturation, it saturates to [0, 255] if it's uint8, or [-128, 127] if it's int8. + For (x / y_scale), it's rounding to nearest ties to even. Refer to https://en.wikipedia.org/wiki/Rounding for details. 'y_zero_point' and 'y' must have same type. + +#### Version + +This version of the operator has been available since version 13 of the default ONNX operator set. + +#### Attributes + +
+
axis : int (default is 1)
+
(Optional) The axis of the quantization dimension of the input tensor. Ignored for per-tensor quantization. Negative value means counting dimensions from the back. Accepted range is [-r, r-1] where r = rank(input).
+
+ +#### Inputs (2 - 3) + +
+
x : T1
+
N-D full precision Input tensor to be quantized.
+
y_scale : tensor(float)
+
Scale for doing quantization to get 'y'. It can be a scalar, which means per-tensor/layer quantization, or a 1-D Tensor for per-axis quantization.
+
y_zero_point (optional) : T2
+
Zero point for doing quantization to get 'y'. Shape must match y_scale. Default is uint8 with zero point of 0 if it's not specified.
+
+ +#### Outputs + +
+
y : T2
+
N-D quantized output tensor. It has same shape as input 'x'.
+
+ +#### Type Constraints + +
+
T1 : tensor(float), tensor(int32)
+
Constrain 'x' to float or int32 tensor.
+
T2 : tensor(int8), tensor(uint8)
+
Constrain 'y_zero_point' and 'y' to 8-bit integer tensor.
+
+ +### **Reciprocal-13** + + Reciprocal takes one input data (Tensor) and produces one output data + (Tensor) where the reciprocal is, y = 1/x, is applied to + the tensor elementwise. + +#### Version + +This version of the operator has been available since version 13 of the default ONNX operator set. + +#### Inputs + +
+
X (differentiable) : T
+
Input tensor
+
+ +#### Outputs + +
+
Y (differentiable) : T
+
Output tensor
+
+ +#### Type Constraints + +
+
T : tensor(float16), tensor(float), tensor(double), tensor(bfloat16)
+
Constrain input and output types to float tensors.
+
+ +### **ReduceL1-13** + + Computes the L1 norm of the input tensor's element along the provided axes. The resulted + tensor has the same rank as the input if keepdims equal 1. If keepdims equal 0, then + the resulted tensor have the reduced dimension pruned. + + The above behavior is similar to numpy, with the exception that numpy default keepdims to + False instead of True. + +#### Version + +This version of the operator has been available since version 13 of the default ONNX operator set. + +#### Attributes + +
+
axes : list of ints
+
A list of integers, along which to reduce. The default is to reduce over all the dimensions of the input tensor. Accepted range is [-r, r-1] where r = rank(data).
+
keepdims : int (default is 1)
+
Keep the reduced dimension or not, default 1 mean keep reduced dimension.
+
+ +#### Inputs + +
+
data (differentiable) : T
+
An input tensor.
+
+ +#### Outputs + +
+
reduced (differentiable) : T
+
Reduced output tensor.
+
+ +#### Type Constraints + +
+
T : tensor(uint32), tensor(uint64), tensor(int32), tensor(int64), tensor(float16), tensor(float), tensor(double), tensor(bfloat16)
+
Constrain input and output types to high-precision numeric tensors.
+
+ +### **ReduceL2-13** + + Computes the L2 norm of the input tensor's element along the provided axes. The resulted + tensor has the same rank as the input if keepdims equal 1. If keepdims equal 0, then + the resulted tensor have the reduced dimension pruned. + + The above behavior is similar to numpy, with the exception that numpy default keepdims to + False instead of True. + +#### Version + +This version of the operator has been available since version 13 of the default ONNX operator set. + +#### Attributes + +
+
axes : list of ints
+
A list of integers, along which to reduce. The default is to reduce over all the dimensions of the input tensor. Accepted range is [-r, r-1] where r = rank(data).
+
keepdims : int (default is 1)
+
Keep the reduced dimension or not, default 1 mean keep reduced dimension.
+
+ +#### Inputs + +
+
data (differentiable) : T
+
An input tensor.
+
+ +#### Outputs + +
+
reduced (differentiable) : T
+
Reduced output tensor.
+
+ +#### Type Constraints + +
+
T : tensor(uint32), tensor(uint64), tensor(int32), tensor(int64), tensor(float16), tensor(float), tensor(double), tensor(bfloat16)
+
Constrain input and output types to high-precision numeric tensors.
+
+ +### **ReduceLogSum-13** + + Computes the log sum of the input tensor's element along the provided axes. The resulted + tensor has the same rank as the input if keepdims equal 1. If keepdims equal 0, then + the resulted tensor have the reduced dimension pruned. + + The above behavior is similar to numpy, with the exception that numpy default keepdims to + False instead of True. + +#### Version + +This version of the operator has been available since version 13 of the default ONNX operator set. + +#### Attributes + +
+
axes : list of ints
+
A list of integers, along which to reduce. The default is to reduce over all the dimensions of the input tensor. Accepted range is [-r, r-1] where r = rank(data).
+
keepdims : int (default is 1)
+
Keep the reduced dimension or not, default 1 mean keep reduced dimension.
+
+ +#### Inputs + +
+
data (differentiable) : T
+
An input tensor.
+
+ +#### Outputs + +
+
reduced (differentiable) : T
+
Reduced output tensor.
+
+ +#### Type Constraints + +
+
T : tensor(uint32), tensor(uint64), tensor(int32), tensor(int64), tensor(float16), tensor(float), tensor(double), tensor(bfloat16)
+
Constrain input and output types to high-precision numeric tensors.
+
+ +### **ReduceLogSumExp-13** + + Computes the log sum exponent of the input tensor's element along the provided axes. The resulted + tensor has the same rank as the input if keepdims equal 1. If keepdims equal 0, then + the resulted tensor have the reduced dimension pruned. + + The above behavior is similar to numpy, with the exception that numpy default keepdims to + False instead of True. + +#### Version + +This version of the operator has been available since version 13 of the default ONNX operator set. + +#### Attributes + +
+
axes : list of ints
+
A list of integers, along which to reduce. The default is to reduce over all the dimensions of the input tensor. Accepted range is [-r, r-1] where r = rank(data).
+
keepdims : int (default is 1)
+
Keep the reduced dimension or not, default 1 mean keep reduced dimension.
+
+ +#### Inputs + +
+
data (differentiable) : T
+
An input tensor.
+
+ +#### Outputs + +
+
reduced (differentiable) : T
+
Reduced output tensor.
+
+ +#### Type Constraints + +
+
T : tensor(uint32), tensor(uint64), tensor(int32), tensor(int64), tensor(float16), tensor(float), tensor(double), tensor(bfloat16)
+
Constrain input and output types to high-precision numeric tensors.
+
+ +### **ReduceMax-13** + + Computes the max of the input tensor's element along the provided axes. The resulted + tensor has the same rank as the input if keepdims equal 1. If keepdims equal 0, then + the resulted tensor have the reduced dimension pruned. + + The above behavior is similar to numpy, with the exception that numpy default keepdims to + False instead of True. + +#### Version + +This version of the operator has been available since version 13 of the default ONNX operator set. + +#### Attributes + +
+
axes : list of ints
+
A list of integers, along which to reduce. The default is to reduce over all the dimensions of the input tensor. Accepted range is [-r, r-1] where r = rank(data).
+
keepdims : int (default is 1)
+
Keep the reduced dimension or not, default 1 mean keep reduced dimension.
+
+ +#### Inputs + +
+
data (differentiable) : T
+
An input tensor.
+
+ +#### Outputs + +
+
reduced (differentiable) : T
+
Reduced output tensor.
+
+ +#### Type Constraints + +
+
T : tensor(uint32), tensor(uint64), tensor(int32), tensor(int64), tensor(float16), tensor(float), tensor(double), tensor(bfloat16), tensor(uint8), tensor(int8)
+
Constrain input and output types to high-precision and 8 bit numeric tensors.
+
+ +### **ReduceMean-13** + + Computes the mean of the input tensor's element along the provided axes. The resulted + tensor has the same rank as the input if keepdims equal 1. If keepdims equal 0, then + the resulted tensor have the reduced dimension pruned. + + The above behavior is similar to numpy, with the exception that numpy default keepdims to + False instead of True. + +#### Version + +This version of the operator has been available since version 13 of the default ONNX operator set. + +#### Attributes + +
+
axes : list of ints
+
A list of integers, along which to reduce. The default is to reduce over all the dimensions of the input tensor. Accepted range is [-r, r-1] where r = rank(data).
+
keepdims : int (default is 1)
+
Keep the reduced dimension or not, default 1 mean keep reduced dimension.
+
+ +#### Inputs + +
+
data (differentiable) : T
+
An input tensor.
+
+ +#### Outputs + +
+
reduced (differentiable) : T
+
Reduced output tensor.
+
+ +#### Type Constraints + +
+
T : tensor(uint32), tensor(uint64), tensor(int32), tensor(int64), tensor(float16), tensor(float), tensor(double), tensor(bfloat16)
+
Constrain input and output types to high-precision numeric tensors.
+
+ +### **ReduceMin-13** + + Computes the min of the input tensor's element along the provided axes. The resulted + tensor has the same rank as the input if keepdims equal 1. If keepdims equal 0, then + the resulted tensor have the reduced dimension pruned. + + The above behavior is similar to numpy, with the exception that numpy default keepdims to + False instead of True. + +#### Version + +This version of the operator has been available since version 13 of the default ONNX operator set. + +#### Attributes + +
+
axes : list of ints
+
A list of integers, along which to reduce. The default is to reduce over all the dimensions of the input tensor. Accepted range is [-r, r-1] where r = rank(data).
+
keepdims : int (default is 1)
+
Keep the reduced dimension or not, default 1 mean keep reduced dimension.
+
+ +#### Inputs + +
+
data (differentiable) : T
+
An input tensor.
+
+ +#### Outputs + +
+
reduced (differentiable) : T
+
Reduced output tensor.
+
+ +#### Type Constraints + +
+
T : tensor(uint32), tensor(uint64), tensor(int32), tensor(int64), tensor(float16), tensor(float), tensor(double), tensor(bfloat16), tensor(uint8), tensor(int8)
+
Constrain input and output types to high-precision and 8 bit numeric tensors.
+
+ +### **ReduceProd-13** + + Computes the product of the input tensor's element along the provided axes. The resulted + tensor has the same rank as the input if keepdims equal 1. If keepdims equal 0, then + the resulted tensor have the reduced dimension pruned. + + The above behavior is similar to numpy, with the exception that numpy default keepdims to + False instead of True. + +#### Version + +This version of the operator has been available since version 13 of the default ONNX operator set. + +#### Attributes + +
+
axes : list of ints
+
A list of integers, along which to reduce. The default is to reduce over all the dimensions of the input tensor. Accepted range is [-r, r-1] where r = rank(data).
+
keepdims : int (default is 1)
+
Keep the reduced dimension or not, default 1 mean keep reduced dimension.
+
+ +#### Inputs + +
+
data (differentiable) : T
+
An input tensor.
+
+ +#### Outputs + +
+
reduced (differentiable) : T
+
Reduced output tensor.
+
+ +#### Type Constraints + +
+
T : tensor(uint32), tensor(uint64), tensor(int32), tensor(int64), tensor(float16), tensor(float), tensor(double), tensor(bfloat16)
+
Constrain input and output types to high-precision numeric tensors.
+
+ +### **ReduceSum-13** + + Computes the sum of the input tensor's element along the provided axes. The resulted + tensor has the same rank as the input if keepdims equal 1. If keepdims equal 0, then + the resulted tensor have the reduced dimension pruned. + + The above behavior is similar to numpy, with the exception that numpy default keepdims to + False instead of True. + +#### Version + +This version of the operator has been available since version 13 of the default ONNX operator set. + +#### Attributes + +
+
keepdims : int (default is 1)
+
Keep the reduced dimension or not, default 1 mean keep reduced dimension.
+
noop_with_empty_axes : int (default is 0)
+
Defines behaviour if 'axes' is empty. Default behaviour with 'false' is to reduce all axes. When axes is empty and this attribute is set to true, input tensor will not be reduced,and the output tensor would be equivalent to input tensor.
+
+ +#### Inputs (1 - 2) + +
+
data (differentiable) : T
+
An input tensor.
+
axes (optional, non-differentiable) : tensor(int64)
+
Optional input list of integers, along which to reduce. The default is to reduce over all the dimensions of the input tensor if 'noop_with_empty_axes' is false, else act as an Identity op when 'noop_with_empty_axes' is true. Accepted range is [-r, r-1] where r = rank(data).
+
+ +#### Outputs + +
+
reduced (differentiable) : T
+
Reduced output tensor.
+
+ +#### Type Constraints + +
+
T : tensor(uint32), tensor(uint64), tensor(int32), tensor(int64), tensor(float16), tensor(float), tensor(double), tensor(bfloat16)
+
Constrain input and output types to high-precision numeric tensors.
+
+ +### **ReduceSumSquare-13** + + Computes the sum square of the input tensor's element along the provided axes. The resulted + tensor has the same rank as the input if keepdims equal 1. If keepdims equal 0, then + the resulted tensor have the reduced dimension pruned. + + The above behavior is similar to numpy, with the exception that numpy default keepdims to + False instead of True. + +#### Version + +This version of the operator has been available since version 13 of the default ONNX operator set. + +#### Attributes + +
+
axes : list of ints
+
A list of integers, along which to reduce. The default is to reduce over all the dimensions of the input tensor. Accepted range is [-r, r-1] where r = rank(data).
+
keepdims : int (default is 1)
+
Keep the reduced dimension or not, default 1 mean keep reduced dimension.
+
+ +#### Inputs + +
+
data (differentiable) : T
+
An input tensor.
+
+ +#### Outputs + +
+
reduced (differentiable) : T
+
Reduced output tensor.
+
+ +#### Type Constraints + +
+
T : tensor(uint32), tensor(uint64), tensor(int32), tensor(int64), tensor(float16), tensor(float), tensor(double), tensor(bfloat16)
+
Constrain input and output types to high-precision numeric tensors.
+
+ +### **Relu-13** + + Relu takes one input data (Tensor) and produces one output data + (Tensor) where the rectified linear function, y = max(0, x), is applied to + the tensor elementwise. + +#### Version + +This version of the operator has been available since version 13 of the default ONNX operator set. + +#### Inputs + +
+
X (differentiable) : T
+
Input tensor
+
+ +#### Outputs + +
+
Y (differentiable) : T
+
Output tensor
+
+ +#### Type Constraints + +
+
T : tensor(float16), tensor(float), tensor(double), tensor(bfloat16)
+
Constrain input and output types to float tensors.
+
+ +### **Reshape-13** + + Reshape the input tensor similar to numpy.reshape. + First input is the data tensor, second input is a shape tensor which specifies the output shape. It outputs the reshaped tensor. + At most one dimension of the new shape can be -1. In this case, the value is + inferred from the size of the tensor and the remaining dimensions. A dimension + could also be 0, in which case the actual dimension value is unchanged (i.e. taken + from the input tensor). + +#### Version + +This version of the operator has been available since version 13 of the default ONNX operator set. + +#### Inputs + +
+
data (differentiable) : T
+
An input tensor.
+
shape (non-differentiable) : tensor(int64)
+
Specified shape for output.
+
+ +#### Outputs + +
+
reshaped (differentiable) : T
+
Reshaped data.
+
+ +#### Type Constraints + +
+
T : tensor(uint8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(int8), tensor(int16), tensor(int32), tensor(int64), tensor(bfloat16), tensor(float16), tensor(float), tensor(double), tensor(string), tensor(bool), tensor(complex64), tensor(complex128)
+
Constrain input and output types to all tensor types.
+
+ +### **Resize-13** + + Resize the input tensor. In general, it calculates every value in the output tensor as a weighted average of neighborhood (a.k.a. sampling locations) in the input tensor. + Each dimension value of the output tensor is: + output_dimension = floor(input_dimension * (roi_end - roi_start) * scale) if input \"sizes\" is not specified. + +#### Version + +This version of the operator has been available since version 13 of the default ONNX operator set. + +#### Attributes + +
+
coordinate_transformation_mode : string (default is half_pixel)
+
+This attribute describes how to transform the coordinate in the resized tensor to the coordinate in the original tensor.
+ +The coordinate of each dimension is transformed individually. Let's describe a case using axis x as an example. +Denote x_resized as the coordinate of axis x in the resized tensor, x_original as the coordinate of axis x in the original tensor, length_original as the length of the original tensor in axis x, length_resized as the length of the resized tensor in axis x, roi_x = (start_x, end_x) of the axis x in input "roi", scale = length_resized / length_original,
+ +if coordinate_transformation_mode is "half_pixel",
+x_original = (x_resized + 0.5) / scale - 0.5,
+ +if coordinate_transformation_mode is "pytorch_half_pixel",
+x_original = length_resized > 1 ? (x_resized + 0.5) / scale - 0.5 : 0,
+ +if coordinate_transformation_mode is "align_corners",
+x_original = x_resized * (length_original - 1) / (length_resized - 1),
+ +if coordinate_transformation_mode is "asymmetric",
+x_original = x_resized / scale,
+ +if coordinate_transformation_mode is "tf_crop_and_resize",
+x_original = length_resized > 1 ? start_x * (length_original - 1) + x_resized * (end_x - start_x) * (length_original - 1) / (length_resized - 1) : 0.5 * (start_x + end_x) * (length_original - 1).
+
cubic_coeff_a : float (default is -0.75)
+
The coefficient 'a' used in cubic interpolation. Two common choice are -0.5 (in some cases of TensorFlow) and -0.75 (in PyTorch). Check out Equation (4) in https://ieeexplore.ieee.org/document/1163711 for the details. This attribute is valid only if "mode" is "cubic".
+
exclude_outside : int (default is 0)
+
If set to 1, the weight of sampling locations outside the tensor will be set to 0 and the weight will be renormalized so that their sum is 1.0. The default value is 0.
+
extrapolation_value : float (default is 0.0)
+
When coordinate_transformation_mode is "tf_crop_and_resize" and x_original is outside the range [0, length_original - 1], this value is used as the corresponding output value. Default is 0.0f.
+
mode : string (default is nearest)
+
Three interpolation modes: nearest (default), linear and cubic. The "linear" mode includes linear interpolation for 1D tensor and N-linear interpolation for N-D tensor (for example, bilinear interpolation for 2D tensor). The "cubic" mode includes cubic interpolation for 1D tensor and N-cubic interpolation for N-D tensor (for example, bicubic interpolation for 2D tensor).
+
nearest_mode : string (default is round_prefer_floor)
+
Four modes: round_prefer_floor (default, as known as round half down), round_prefer_ceil (as known as round half up), floor, ceil. Only used by nearest interpolation. It indicates how to get "nearest" pixel in input tensor from x_original, so this attribute is valid only if "mode" is "nearest".
+
+ +#### Inputs (1 - 4) + +
+
X (differentiable) : T1
+
N-D tensor
+
roi (optional, non-differentiable) : T2
+
1-D tensor given as [start1, ..., startN, end1, ..., endN], where N is the rank of X. The RoIs' coordinates are normalized in the coordinate system of the input image. It only takes effect when coordinate_transformation_mode is "tf_crop_and_resize"
+
scales (optional, non-differentiable) : tensor(float)
+
The scale array along each dimension. It takes value greater than 0. If it's less than 1, it's sampling down, otherwise, it's upsampling. The number of elements of 'scales' should be the same as the rank of input 'X'. One of 'scales' and 'sizes' MUST be specified and it is an error if both are specified. If 'sizes' is needed, the user can use an empty string as the name of 'scales' in this operator's input list.
+
sizes (optional, non-differentiable) : tensor(int64)
+
The size of the output tensor. The number of elements of 'sizes' should be the same as the rank of input 'X'. Only one of 'scales' and 'sizes' can be specified.
+
+ +#### Outputs + +
+
Y (differentiable) : T1
+
N-D tensor after resizing
+
+ +#### Type Constraints + +
+
T1 : tensor(uint8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(int8), tensor(int16), tensor(int32), tensor(int64), tensor(bfloat16), tensor(float16), tensor(float), tensor(double), tensor(string), tensor(bool), tensor(complex64), tensor(complex128)
+
Constrain input 'X' and output 'Y' to all tensor types.
+
T2 : tensor(float16), tensor(float), tensor(double)
+
Constrain roi type to float or double.
+
+ +### **ScatterElements-13** + + ScatterElements takes three inputs `data`, `updates`, and `indices` of the same + rank r >= 1 and an optional attribute axis that identifies an axis of `data` + (by default, the outer-most axis, that is axis 0). The output of the operation + is produced by creating a copy of the input `data`, and then updating its value + to values specified by `updates` at specific index positions specified by + `indices`. Its output shape is the same as the shape of `data`. + + For each entry in `updates`, the target index in `data` is obtained by combining + the corresponding entry in `indices` with the index of the entry itself: the + index-value for dimension = axis is obtained from the value of the corresponding + entry in `indices` and the index-value for dimension != axis is obtained from the + index of the entry itself. + + For instance, in a 2-D tensor case, the update corresponding to the [i][j] entry + is performed as below: + ``` + output[indices[i][j]][j] = updates[i][j] if axis = 0, + output[i][indices[i][j]] = updates[i][j] if axis = 1, + ``` + + This operator is the inverse of GatherElements. It is similar to Torch's Scatter operation. + + Example 1: + ``` + data = [ + [0.0, 0.0, 0.0], + [0.0, 0.0, 0.0], + [0.0, 0.0, 0.0], + ] + indices = [ + [1, 0, 2], + [0, 2, 1], + ] + updates = [ + [1.0, 1.1, 1.2], + [2.0, 2.1, 2.2], + ] + output = [ + [2.0, 1.1, 0.0] + [1.0, 0.0, 2.2] + [0.0, 2.1, 1.2] + ] + ``` + Example 2: + ``` + data = [[1.0, 2.0, 3.0, 4.0, 5.0]] + indices = [[1, 3]] + updates = [[1.1, 2.1]] + axis = 1 + output = [[1.0, 1.1, 3.0, 2.1, 5.0]] + ``` + +#### Version + +This version of the operator has been available since version 13 of the default ONNX operator set. + +#### Attributes + +
+
axis : int (default is 0)
+
Which axis to scatter on. Negative value means counting dimensions from the back. Accepted range is [-r, r-1] where r = rank(data).
+
+ +#### Inputs + +
+
data (differentiable) : T
+
Tensor of rank r >= 1.
+
indices (non-differentiable) : Tind
+
Tensor of int32/int64 indices, of r >= 1 (same rank as input). All index values are expected to be within bounds [-s, s-1] along axis of size s. It is an error if any of the index values are out of bounds.
+
updates (differentiable) : T
+
Tensor of rank r >=1 (same rank and shape as indices)
+
+ +#### Outputs + +
+
output (differentiable) : T
+
Tensor of rank r >= 1 (same rank as input).
+
+ +#### Type Constraints + +
+
T : tensor(uint8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(int8), tensor(int16), tensor(int32), tensor(int64), tensor(bfloat16), tensor(float16), tensor(float), tensor(double), tensor(string), tensor(bool), tensor(complex64), tensor(complex128)
+
Input and output types can be of any tensor type.
+
Tind : tensor(int32), tensor(int64)
+
Constrain indices to integer types
+
+ +### **ScatterND-13** + + ScatterND takes three inputs `data` tensor of rank r >= 1, `indices` tensor of rank q >= 1, + and `updates` tensor of rank q + r - indices.shape[-1] - 1. The output of the operation + is produced by creating a copy of the input `data`, and then updating its value to values + specified by `updates` at specific index positions specified by `indices`. Its output shape + is the same as the shape of `data`. Note that `indices` should not have duplicate entries. + That is, two or more `updates` for the same index-location is not supported. + + `indices` is an integer tensor. Let k denote indices.shape[-1], the last dimension in the shape of `indices`. + `indices` is treated as a (q-1)-dimensional tensor of k-tuples, where each k-tuple is a partial-index into `data`. + Hence, k can be a value at most the rank of `data`. When k equals rank(data), each update entry specifies an + update to a single element of the tensor. When k is less than rank(data) each update entry specifies an + update to a slice of the tensor. + + `updates` is treated as a (q-1)-dimensional tensor of replacement-slice-values. Thus, the + first (q-1) dimensions of updates.shape must match the first (q-1) dimensions of indices.shape. + The remaining dimensions of `updates` correspond to the dimensions of the + replacement-slice-values. Each replacement-slice-value is a (r-k) dimensional tensor, + corresponding to the trailing (r-k) dimensions of `data`. Thus, the shape of `updates` + must equal indices.shape[0:q-1] ++ data.shape[k:r-1], where ++ denotes the concatenation + of shapes. + + The `output` is calculated via the following equation: + + output = np.copy(data) + update_indices = indices.shape[:-1] + for idx in np.ndindex(update_indices): + output[indices[idx]] = updates[idx] + + The order of iteration in the above loop is not specified. + In particular, indices should not have duplicate entries: that is, if idx1 != idx2, then indices[idx1] != indices[idx2]. + This ensures that the output value does not depend on the iteration order. + + This operator is the inverse of GatherND. + + Example 1: + ``` + data = [1, 2, 3, 4, 5, 6, 7, 8] + indices = [[4], [3], [1], [7]] + updates = [9, 10, 11, 12] + output = [1, 11, 3, 10, 9, 6, 7, 12] + ``` + + Example 2: + ``` + data = [[[1, 2, 3, 4], [5, 6, 7, 8], [8, 7, 6, 5], [4, 3, 2, 1]], + [[1, 2, 3, 4], [5, 6, 7, 8], [8, 7, 6, 5], [4, 3, 2, 1]], + [[8, 7, 6, 5], [4, 3, 2, 1], [1, 2, 3, 4], [5, 6, 7, 8]], + [[8, 7, 6, 5], [4, 3, 2, 1], [1, 2, 3, 4], [5, 6, 7, 8]]] + indices = [[0], [2]] + updates = [[[5, 5, 5, 5], [6, 6, 6, 6], [7, 7, 7, 7], [8, 8, 8, 8]], + [[1, 1, 1, 1], [2, 2, 2, 2], [3, 3, 3, 3], [4, 4, 4, 4]]] + output = [[[5, 5, 5, 5], [6, 6, 6, 6], [7, 7, 7, 7], [8, 8, 8, 8]], + [[1, 2, 3, 4], [5, 6, 7, 8], [8, 7, 6, 5], [4, 3, 2, 1]], + [[1, 1, 1, 1], [2, 2, 2, 2], [3, 3, 3, 3], [4, 4, 4, 4]], + [[8, 7, 6, 5], [4, 3, 2, 1], [1, 2, 3, 4], [5, 6, 7, 8]]] + ``` + +#### Version + +This version of the operator has been available since version 13 of the default ONNX operator set. + +#### Inputs + +
+
data (differentiable) : T
+
Tensor of rank r >= 1.
+
indices (non-differentiable) : tensor(int64)
+
Tensor of rank q >= 1.
+
updates (differentiable) : T
+
Tensor of rank q + r - indices_shape[-1] - 1.
+
+ +#### Outputs + +
+
output (differentiable) : T
+
Tensor of rank r >= 1.
+
+ +#### Type Constraints + +
+
T : tensor(uint8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(int8), tensor(int16), tensor(int32), tensor(int64), tensor(bfloat16), tensor(float16), tensor(float), tensor(double), tensor(string), tensor(bool), tensor(complex64), tensor(complex128)
+
Constrain input and output types to any tensor type.
+
+ +### **Shape-13** + + Takes a tensor as input and outputs an 1D int64 tensor containing the shape of the input tensor. + +#### Version + +This version of the operator has been available since version 13 of the default ONNX operator set. + +#### Inputs + +
+
data (non-differentiable) : T
+
An input tensor.
+
+ +#### Outputs + +
+
shape (non-differentiable) : T1
+
Shape of the input tensor
+
+ +#### Type Constraints + +
+
T : tensor(uint8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(int8), tensor(int16), tensor(int32), tensor(int64), tensor(bfloat16), tensor(float16), tensor(float), tensor(double), tensor(string), tensor(bool), tensor(complex64), tensor(complex128)
+
Input tensor can be of arbitrary type.
+
T1 : tensor(int64)
+
Constrain output to int64 tensor.
+
+ +### **Sigmoid-13** + + Sigmoid takes one input data (Tensor) and produces one output data + (Tensor) where the sigmoid function, y = 1 / (1 + exp(-x)), is applied to the + tensor elementwise. + +#### Version + +This version of the operator has been available since version 13 of the default ONNX operator set. + +#### Inputs + +
+
X (differentiable) : T
+
Input tensor
+
+ +#### Outputs + +
+
Y (differentiable) : T
+
Output tensor
+
+ +#### Type Constraints + +
+
T : tensor(float16), tensor(float), tensor(double), tensor(bfloat16)
+
Constrain input and output types to float tensors.
+
+ +### **Sign-13** + + Calculate the sign of the given input tensor element-wise. + If input > 0, output 1. if input < 0, output -1. if input == 0, output 0. + +#### Version + +This version of the operator has been available since version 13 of the default ONNX operator set. + +#### Inputs + +
+
input (non-differentiable) : T
+
Input tensor
+
+ +#### Outputs + +
+
output (non-differentiable) : T
+
The sign of the input tensor computed element-wise. It has the same shape and type of the input.
+
+ +#### Type Constraints + +
+
T : tensor(uint8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(int8), tensor(int16), tensor(int32), tensor(int64), tensor(float16), tensor(float), tensor(double), tensor(bfloat16)
+
Constrain input and output types to all numeric tensors.
+
+ +### **Size-13** + + Takes a tensor as input and outputs a int64 scalar that equals to the total number of elements of the input tensor. + +#### Version + +This version of the operator has been available since version 13 of the default ONNX operator set. + +#### Inputs + +
+
data (non-differentiable) : T
+
An input tensor.
+
+ +#### Outputs + +
+
size (non-differentiable) : T1
+
Total number of elements of the input tensor
+
+ +#### Type Constraints + +
+
T : tensor(uint8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(int8), tensor(int16), tensor(int32), tensor(int64), tensor(bfloat16), tensor(float16), tensor(float), tensor(double), tensor(string), tensor(bool), tensor(complex64), tensor(complex128)
+
Input tensor can be of arbitrary type.
+
T1 : tensor(int64)
+
Constrain output to int64 tensor, which should be a scalar though.
+
+ +### **Slice-13** + + Produces a slice of the input tensor along multiple axes. Similar to numpy: + https://docs.scipy.org/doc/numpy/reference/arrays.indexing.html + Slices uses `starts`, `ends`, `axes` and `steps` inputs to specify the start and end + dimension and step for each axis in the list of axes, it uses this information to + slice the input `data` tensor. If a negative value is passed for any of the + start or end indices, it represents number of elements before the end of that + dimension. If the value passed to start or end is larger than the `n` (the + number of elements in this dimension), it represents `n`. For slicing to the + end of a dimension with unknown size, it is recommended to pass in `INT_MAX` + when sclicing forward and 'INT_MIN' when slicing backward. + If a negative value is passed for step, it represents slicing backward. + However step value cannot be 0. + If `axes` are omitted, they are set to `[0, ..., ndim-1]`. + If `steps` are omitted, they are set to `[1, ..., 1]` of length `len(starts)` + Example 1: + data = [ + [1, 2, 3, 4], + [5, 6, 7, 8], + ] + axes = [0, 1] + starts = [1, 0] + ends = [2, 3] + steps = [1, 2] + result = [ + [5, 7], + ] + Example 2: + data = [ + [1, 2, 3, 4], + [5, 6, 7, 8], + ] + starts = [0, 1] + ends = [-1, 1000] + result = [ + [2, 3, 4], + ] + +#### Version + +This version of the operator has been available since version 13 of the default ONNX operator set. + +#### Inputs (3 - 5) + +
+
data (differentiable) : T
+
Tensor of data to extract slices from.
+
starts (non-differentiable) : Tind
+
1-D tensor of starting indices of corresponding axis in `axes`
+
ends (non-differentiable) : Tind
+
1-D tensor of ending indices (exclusive) of corresponding axis in `axes`
+
axes (optional, non-differentiable) : Tind
+
1-D tensor of axes that `starts` and `ends` apply to. Negative value means counting dimensions from the back. Accepted range is [-r, r-1] where r = rank(data).
+
steps (optional, non-differentiable) : Tind
+
1-D tensor of slice step of corresponding axis in `axes`. Negative value means slicing backward. 'steps' cannot be 0. Defaults to 1.
+
+ +#### Outputs + +
+
output (differentiable) : T
+
Sliced data tensor.
+
+ +#### Type Constraints + +
+
T : tensor(uint8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(int8), tensor(int16), tensor(int32), tensor(int64), tensor(bfloat16), tensor(float16), tensor(float), tensor(double), tensor(string), tensor(bool), tensor(complex64), tensor(complex128)
+
Constrain input and output types to all tensor types.
+
Tind : tensor(int32), tensor(int64)
+
Constrain indices to integer types
+
+ +### **Softmax-13** + + The operator computes the normalized exponential values for the given input: + + Softmax(input, axis) = Exp(input) / ReduceSum(Exp(input), axis=axis, keepdims=1) + + The "axis" attribute indicates the dimension along which Softmax + will be performed. The output tensor has the same shape + and contains the Softmax values of the corresponding input. + +#### Version + +This version of the operator has been available since version 13 of the default ONNX operator set. + +#### Attributes + +
+
axis : int (default is -1)
+
+Describes the dimension Softmax will be performed on. +Negative value means counting dimensions +from the back. Accepted range is [-r, r-1] where r = rank(input). +
+
+ +#### Inputs + +
+
input (differentiable) : T
+
The input tensor of rank >= axis.
+
+ +#### Outputs + +
+
output (differentiable) : T
+
The output values with the same shape as the input tensor.
+
+ +#### Type Constraints + +
+
T : tensor(float16), tensor(float), tensor(double), tensor(bfloat16)
+
Constrain input and output types to float tensors.
+
+ +### **SoftmaxCrossEntropyLoss-13** + + Loss function that measures the softmax cross entropy + between 'scores' and 'labels'. + This operator first computes a loss tensor whose shape is identical to the labels input. + If the input is 2-D with shape (N, C), the loss tensor may be a N-element vector L = (l_1, l_2, ..., l_N). + If the input is N-D tensor with shape (N, C, D1, D2, ..., Dk), + the loss tensor L may have (N, D1, D2, ..., Dk) as its shape and L[i,][j_1][j_2]...[j_k] denotes a scalar element in L. + After L is available, this operator can optionally do a reduction operator. + + shape(scores): (N, C) where C is the number of classes, or (N, C, D1, D2,..., Dk), + with K >= 1 in case of K-dimensional loss. + shape(labels): (N) where each value is 0 <= labels[i] <= C-1, or (N, D1, D2,..., Dk), + with K >= 1 in case of K-dimensional loss. + + The loss for one sample, l_i, can caculated as follows: + l[i][d1][d2]...[dk] = -y[i][c][d1][d2]..[dk], where i is the index of classes. + or + l[i][d1][d2]...[dk] = -y[i][c][d1][d2]..[dk] * weights[c], if 'weights' is provided. + + loss is zero for the case when label-value equals ignore_index. + l[i][d1][d2]...[dk] = 0, when labels[n][d1][d2]...[dk] = ignore_index + + where: + p = Softmax(scores) + y = Log(p) + c = labels[i][d1][d2]...[dk] + + Finally, L is optionally reduced: + If reduction = 'none', the output is L with shape (N, D1, D2, ..., Dk). + If reduction = 'sum', the output is scalar: Sum(L). + If reduction = 'mean', the output is scalar: ReduceMean(L), or if weight is provided: ReduceSum(L) / ReduceSum(W), + where tensor W is of shape (N, D1, D2, ..., Dk) and W[n][d1][d2]...[dk] = weights[labels[i][d1][d2]...[dk]]. + +#### Version + +This version of the operator has been available since version 13 of the default ONNX operator set. + +#### Attributes + +
+
ignore_index : int
+
Specifies a target value that is ignored and does not contribute to the input gradient. It's an optional value.
+
reduction : string (default is mean)
+
Type of reduction to apply to loss: none, sum, mean(default). 'none': no reduction will be applied, 'sum': the output will be summed. 'mean': the sum of the output will be divided by the number of elements in the output.
+
+ +#### Inputs (2 - 3) + +
+
scores (differentiable) : T
+
The predicted outputs with shape [batch_size, class_size], or [batch_size, class_size, D1, D2 , ..., Dk], where K is the number of dimensions.
+
labels (non-differentiable) : Tind
+
The ground truth output tensor, with shape [batch_size], or [batch_size, D1, D2, ..., Dk], where K is the number of dimensions. Labels element value shall be in range of [0, C). If ignore_index is specified, it may have a value outside [0, C) and the label values should either be in the range [0, C) or have the value ignore_index.
+
weights (optional, non-differentiable) : T
+
A manual rescaling weight given to each class. If given, it has to be a 1D Tensor assigning weight to each of the classes. Otherwise, it is treated as if having all ones.
+
+ +#### Outputs (1 - 2) + +
+
output (differentiable) : T
+
Weighted loss float Tensor. If reduction is 'none', this has the shape of [batch_size], or [batch_size, D1, D2, ..., Dk] in case of K-dimensional loss. Otherwise, it is a scalar.
+
log_prob (optional, differentiable) : T
+
Log probability tensor. If the output of softmax is prob, its value is log(prob).
+
+ +#### Type Constraints + +
+
T : tensor(float16), tensor(float), tensor(double), tensor(bfloat16)
+
Constrain input and output types to float tensors.
+
Tind : tensor(int32), tensor(int64)
+
Constrain target to integer types
+
+ +### **SpaceToDepth-13** + + SpaceToDepth rearranges blocks of spatial data into depth. More specifically, + this op outputs a copy of the input tensor where values from the height and width dimensions + are moved to the depth dimension. + +#### Version + +This version of the operator has been available since version 13 of the default ONNX operator set. + +#### Attributes + +
+
blocksize : int (required)
+
Blocks of [blocksize, blocksize] are moved.
+
+ +#### Inputs + +
+
input (differentiable) : T
+
Input tensor of [N,C,H,W], where N is the batch axis, C is the channel or depth, H is the height and W is the width.
+
+ +#### Outputs + +
+
output (differentiable) : T
+
Output tensor of [N, C * blocksize * blocksize, H/blocksize, W/blocksize].
+
+ +#### Type Constraints + +
+
T : tensor(uint8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(int8), tensor(int16), tensor(int32), tensor(int64), tensor(bfloat16), tensor(float16), tensor(float), tensor(double), tensor(string), tensor(bool), tensor(complex64), tensor(complex128)
+
Constrain input and output types to all tensor types.
+
+ +### **Split-13** + + Split a tensor into a list of tensors, along the specified + 'axis'. Lengths of the parts can be specified using input 'split'. + Otherwise, the tensor is split to equal sized parts. + +#### Version + +This version of the operator has been available since version 13 of the default ONNX operator set. + +#### Attributes + +
+
axis : int (default is 0)
+
Which axis to split on. A negative value means counting dimensions from the back. Accepted range is [-rank, rank-1] where r = rank(input).
+
+ +#### Inputs (1 - 2) + +
+
input (differentiable) : T
+
The tensor to split
+
split (optional, non-differentiable) : tensor(int64)
+
Optional length of each output. Values should be >= 0.Sum of the values must be equal to the dim value at 'axis' specified.
+
+ +#### Outputs (1 - ∞) + +
+
outputs (variadic, differentiable) : T
+
One or more outputs forming list of tensors after splitting
+
+ +#### Type Constraints + +
+
T : tensor(uint8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(int8), tensor(int16), tensor(int32), tensor(int64), tensor(bfloat16), tensor(float16), tensor(float), tensor(double), tensor(string), tensor(bool), tensor(complex64), tensor(complex128)
+
Constrain input and output types to all tensor types.
+
+ +### **Sqrt-13** + + Square root takes one input data (Tensor) and produces one output data + (Tensor) where the square root is, y = x^0.5, is applied to + the tensor elementwise. If x is negative, then it will return NaN. + +#### Version + +This version of the operator has been available since version 13 of the default ONNX operator set. + +#### Inputs + +
+
X (differentiable) : T
+
Input tensor
+
+ +#### Outputs + +
+
Y (differentiable) : T
+
Output tensor
+
+ +#### Type Constraints + +
+
T : tensor(float16), tensor(float), tensor(double), tensor(bfloat16)
+
Constrain input and output types to float tensors.
+
+ +### **Squeeze-13** + + Remove single-dimensional entries from the shape of a tensor. + Takes an input `axes` with a list of axes to squeeze. + If `axes` is not provided, all the single dimensions will be removed from + the shape. If an axis is selected with shape entry not equal to one, an error is raised. + +#### Version + +This version of the operator has been available since version 13 of the default ONNX operator set. + +#### Inputs (1 - 2) + +
+
data (differentiable) : T
+
Tensors with at least max(dims) dimensions.
+
axes (optional, non-differentiable) : tensor(int64)
+
List of integers indicating the dimensions to squeeze. Negative value means counting dimensions from the back. Accepted range is [-r, r-1] where r = rank(data).
+
+ +#### Outputs + +
+
squeezed (differentiable) : T
+
Reshaped tensor with same data as input.
+
+ +#### Type Constraints + +
+
T : tensor(uint8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(int8), tensor(int16), tensor(int32), tensor(int64), tensor(bfloat16), tensor(float16), tensor(float), tensor(double), tensor(string), tensor(bool), tensor(complex64), tensor(complex128)
+
Constrain input and output types to all tensor types.
+
+ +### **Sub-13** + + Performs element-wise binary subtraction (with Numpy-style broadcasting support). + + This operator supports **multidirectional (i.e., Numpy-style) broadcasting**; for more details please check [the doc](Broadcasting.md). + +#### Version + +This version of the operator has been available since version 13 of the default ONNX operator set. + +#### Inputs + +
+
A (differentiable) : T
+
First operand.
+
B (differentiable) : T
+
Second operand.
+
+ +#### Outputs + +
+
C (differentiable) : T
+
Result, has same element type as two inputs
+
+ +#### Type Constraints + +
+
T : tensor(uint32), tensor(uint64), tensor(int32), tensor(int64), tensor(float16), tensor(float), tensor(double), tensor(bfloat16)
+
Constrain input and output types to high-precision numeric tensors.
+
+ +### **Sum-13** + + Element-wise sum of each of the input tensors (with Numpy-style broadcasting support). + All inputs and outputs must have the same data type. + This operator supports **multidirectional (i.e., Numpy-style) broadcasting**; for more details please check [the doc](Broadcasting.md). + +#### Version + +This version of the operator has been available since version 13 of the default ONNX operator set. + +#### Inputs (1 - ∞) + +
+
data_0 (variadic, differentiable) : T
+
List of tensors for sum.
+
+ +#### Outputs + +
+
sum (differentiable) : T
+
Output tensor.
+
+ +#### Type Constraints + +
+
T : tensor(float16), tensor(float), tensor(double), tensor(bfloat16)
+
Constrain input and output types to float tensors.
+
+ +### **Tanh-13** + + Calculates the hyperbolic tangent of the given input tensor element-wise. + +#### Version + +This version of the operator has been available since version 13 of the default ONNX operator set. + +#### Inputs + +
+
input (differentiable) : T
+
Input tensor
+
+ +#### Outputs + +
+
output (differentiable) : T
+
The hyperbolic tangent values of the input tensor computed element-wise
+
+ +#### Type Constraints + +
+
T : tensor(float16), tensor(float), tensor(double), tensor(bfloat16)
+
Constrain input and output types to float tensors.
+
+ +### **Tile-13** + + Constructs a tensor by tiling a given tensor. + This is the same as function `tile` in Numpy, but no broadcast. + For example A = [[1, 2], [3, 4]], B = [1, 2], tile(A, B) = [[1, 2, 1, 2], [3, 4, 3, 4]] + +#### Version + +This version of the operator has been available since version 13 of the default ONNX operator set. + +#### Inputs + +
+
input (differentiable) : T
+
Input tensor of any shape.
+
repeats (non-differentiable) : T1
+
1D int64 tensor of the same length as input's dimension number, includes numbers of repeated copies along input's dimensions.
+
+ +#### Outputs + +
+
output (differentiable) : T
+
Output tensor of the same dimension and type as tensor input. output_dim[i] = input_dim[i] * repeats[i]
+
+ +#### Type Constraints + +
+
T : tensor(uint8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(int8), tensor(int16), tensor(int32), tensor(int64), tensor(bfloat16), tensor(float16), tensor(float), tensor(double), tensor(string), tensor(bool), tensor(complex64), tensor(complex128)
+
Constrain input and output types to all tensor types.
+
T1 : tensor(int64)
+
Constrain repeat's type to int64 tensors.
+
+ +### **Transpose-13** + + Transpose the input tensor similar to numpy.transpose. For example, when + perm=(1, 0, 2), given an input tensor of shape (1, 2, 3), the output shape + will be (2, 1, 3). + +#### Version + +This version of the operator has been available since version 13 of the default ONNX operator set. + +#### Attributes + +
+
perm : list of ints
+
A list of integers. By default, reverse the dimensions, otherwise permute the axes according to the values given.
+
+ +#### Inputs + +
+
data (differentiable) : T
+
An input tensor.
+
+ +#### Outputs + +
+
transposed (differentiable) : T
+
Transposed output.
+
+ +#### Type Constraints + +
+
T : tensor(uint8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(int8), tensor(int16), tensor(int32), tensor(int64), tensor(bfloat16), tensor(float16), tensor(float), tensor(double), tensor(string), tensor(bool), tensor(complex64), tensor(complex128)
+
Constrain input and output types to all tensor types.
+
+ +### **Unsqueeze-13** + + Insert single-dimensional entries to the shape of an input tensor (`data`). + Takes one required input `axes` - which contains a list of dimension indices and this operator will insert a dimension of value `1` into the corresponding index of the output tensor (`expanded`). + + For example: + Given an input tensor (`data`) of shape [3, 4, 5], then + Unsqueeze(data, axes=[0, 4]) outputs a tensor (`expanded`) containing same data as `data` but with shape [1, 3, 4, 5, 1]. + + The input `axes` should not contain any duplicate entries. It is an error if it contains duplicates. + The rank of the output tensor (`output_rank`) is the rank of the input tensor (`data`) plus the number of values in `axes`. + Each value in `axes` should be within the (inclusive) range [-output_rank , output_rank - 1]. + The order of values in `axes` does not matter and can come in any order. + + +#### Version + +This version of the operator has been available since version 13 of the default ONNX operator set. + +#### Inputs + +
+
data (differentiable) : T
+
Original tensor
+
axes (non-differentiable) : tensor(int64)
+
List of integers indicating the dimensions to be inserted. Negative value means counting dimensions from the back. Accepted range is [-r, r-1] where r = rank(expanded).
+
+ +#### Outputs + +
+
expanded (differentiable) : T
+
Reshaped tensor with same data as input.
+
+ +#### Type Constraints + +
+
T : tensor(uint8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(int8), tensor(int16), tensor(int32), tensor(int64), tensor(bfloat16), tensor(float16), tensor(float), tensor(double), tensor(string), tensor(bool), tensor(complex64), tensor(complex128)
+
Constrain input and output types to all tensor types.
+
+ +## Version 14 of the default ONNX operator set +### **Add-14** + + Performs element-wise binary addition (with Numpy-style broadcasting support). + + This operator supports **multidirectional (i.e., Numpy-style) broadcasting**; for more details please check [the doc](Broadcasting.md). + + (Opset 14 change): Extend supported types to include uint8, int8, uint16, and int16. + +#### Version + +This version of the operator has been available since version 14 of the default ONNX operator set. + +#### Inputs + +
+
A (differentiable) : T
+
First operand.
+
B (differentiable) : T
+
Second operand.
+
+ +#### Outputs + +
+
C (differentiable) : T
+
Result, has same element type as two inputs
+
+ +#### Type Constraints + +
+
T : tensor(uint8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(int8), tensor(int16), tensor(int32), tensor(int64), tensor(float16), tensor(float), tensor(double), tensor(bfloat16)
+
Constrain input and output types to all numeric tensors.
+
+ +### **BatchNormalization-14** + + Carries out batch normalization as described in the paper + https://arxiv.org/abs/1502.03167. Depending on the mode it is being run, + There are five required inputs 'X', 'scale', 'B', 'input_mean' and + 'input_var'. + Note that 'input_mean' and 'input_var' are expected to be the estimated + statistics in inference mode (training_mode=False, default), + and the running statistics in training mode (training_mode=True). + There are multiple cases for the number of outputs, which we list below: + + Output case #1: Y, running_mean, running_var (training_mode=True) + Output case #2: Y (training_mode=False) + + When training_mode=False, extra outputs are invalid. + The outputs are updated as follows when training_mode=True: + ``` + running_mean = input_mean * momentum + current_mean * (1 - momentum) + running_var = input_var * momentum + current_var * (1 - momentum) + + Y = (X - current_mean) / sqrt(current_var + epsilon) * scale + B + + where: + + current_mean = ReduceMean(X, axis=all_except_channel_index) + current_var = ReduceVar(X, axis=all_except_channel_index) + + Notice that ReduceVar refers to the population variance, and it equals to + sum(sqrd(x_i - x_avg)) / N + where N is the population size (this formula does not use sample size N - 1). + + ``` + + When training_mode=False: + ``` + Y = (X - input_mean) / sqrt(input_var + epsilon) * scale + B + ``` + + For previous (depreciated) non-spatial cases, implementors are suggested + to flatten the input shape to (N x C * D1 * D2 * ... * Dn) before a BatchNormalization Op. + This operator has **optional** inputs/outputs. See [the doc](IR.md) for more details about the representation of optional arguments. An empty string may be used in the place of an actual argument's name to indicate a missing argument. Trailing optional arguments (those not followed by an argument that is present) may also be simply omitted. + +#### Version + +This version of the operator has been available since version 14 of the default ONNX operator set. + +#### Attributes + +
+
epsilon : float (default is 1e-05)
+
The epsilon value to use to avoid division by zero.
+
momentum : float (default is 0.9)
+
Factor used in computing the running mean and variance.e.g., running_mean = running_mean * momentum + mean * (1 - momentum).
+
training_mode : int (default is 0)
+
If set to true, it indicates BatchNormalization is being used for training, and outputs 1, 2, 3, and 4 would be populated.
+
+ +#### Inputs + +
+
X (differentiable) : T
+
Input data tensor from the previous operator; dimensions are in the form of (N x C x D1 x D2 ... Dn), where N is the batch size, C is the number of channels. Statistics are computed for every channel of C over N and D1 to Dn dimensions. For image data, input dimensions become (N x C x H x W). The op also accepts single dimension input of size N in which case C is assumed to be 1
+
scale (differentiable) : T
+
Scale tensor of shape (C).
+
B (differentiable) : T
+
Bias tensor of shape (C).
+
input_mean (differentiable) : U
+
running (training) or estimated (testing) mean tensor of shape (C).
+
input_var (differentiable) : U
+
running (training) or estimated (testing) variance tensor of shape (C).
+
+ +#### Outputs (1 - 3) + +
+
Y (differentiable) : T
+
The output tensor of the same shape as X
+
running_mean (optional, non-differentiable) : U
+
The running mean after the BatchNormalization operator.
+
running_var (optional, non-differentiable) : U
+
The running variance after the BatchNormalization operator. This op uses the population size (N) for calculating variance, and not the sample size N-1.
+
+ +#### Type Constraints + +
+
T : tensor(float16), tensor(float), tensor(double), tensor(bfloat16)
+
Constrain input and output types to float tensors.
+
U : tensor(float16), tensor(float), tensor(double), tensor(bfloat16)
+
Constrain mean and variance types to float tensors. It allows all float type for U.
+
+ +### **CumSum-14** + + Performs cumulative sum of the input elements along the given axis. + By default, it will do the sum inclusively meaning the first element is copied as is. + Through an `exclusive` attribute, this behavior can change to exclude the first element. + It can also perform summation in the opposite direction of the axis. For that, set `reverse` attribute to 1. + + Example: + ``` + input_x = [1, 2, 3] + axis=0 + output = [1, 3, 6] + exclusive=1 + output = [0, 1, 3] + exclusive=0 + reverse=1 + output = [6, 5, 3] + exclusive=1 + reverse=1 + output = [5, 3, 0] + ``` + + +#### Version + +This version of the operator has been available since version 14 of the default ONNX operator set. + +#### Attributes + +
+
exclusive : int (default is 0)
+
If set to 1 will return exclusive sum in which the top element is not included. In other terms, if set to 1, the j-th output element would be the sum of the first (j-1) elements. Otherwise, it would be the sum of the first j elements.
+
reverse : int (default is 0)
+
If set to 1 will perform the sums in reverse direction.
+
+ +#### Inputs + +
+
x (differentiable) : T
+
An input tensor that is to be processed.
+
axis (non-differentiable) : T2
+
A 0-D tensor. Must be in the range [-rank(x), rank(x)-1]. Negative value means counting dimensions from the back.
+
+ +#### Outputs + +
+
y (differentiable) : T
+
Output tensor of the same type as 'x' with cumulative sums of the x's elements
+
+ +#### Type Constraints + +
+
T : tensor(uint32), tensor(uint64), tensor(int32), tensor(int64), tensor(float16), tensor(float), tensor(double), tensor(bfloat16)
+
Constrain input and output types to high-precision numeric tensors.
+
T2 : tensor(int32), tensor(int64)
+
axis tensor can be int32 or int64 only
+
+ +### **Div-14** + + Performs element-wise binary division (with Numpy-style broadcasting support). + + This operator supports **multidirectional (i.e., Numpy-style) broadcasting**; for more details please check [the doc](Broadcasting.md). + + (Opset 14 change): Extend supported types to include uint8, int8, uint16, and int16. + +#### Version + +This version of the operator has been available since version 14 of the default ONNX operator set. + +#### Inputs + +
+
A (differentiable) : T
+
First operand.
+
B (differentiable) : T
+
Second operand.
+
+ +#### Outputs + +
+
C (differentiable) : T
+
Result, has same element type as two inputs
+
+ +#### Type Constraints + +
+
T : tensor(uint8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(int8), tensor(int16), tensor(int32), tensor(int64), tensor(float16), tensor(float), tensor(double), tensor(bfloat16)
+
Constrain input and output types to all numeric tensors.
+
+ +### **GRU-14** + + Computes an one-layer GRU. This operator is usually supported via some custom + implementation such as CuDNN. + + Notations: + + `X` - input tensor + + `z` - update gate + + `r` - reset gate + + `h` - hidden gate + + `t` - time step (t-1 means previous time step) + + `W[zrh]` - W parameter weight matrix for update, reset, and hidden gates + + `R[zrh]` - R recurrence weight matrix for update, reset, and hidden gates + + `Wb[zrh]` - W bias vectors for update, reset, and hidden gates + + `Rb[zrh]` - R bias vectors for update, reset, and hidden gates + + `WB[zrh]` - W parameter weight matrix for backward update, reset, and hidden gates + + `RB[zrh]` - R recurrence weight matrix for backward update, reset, and hidden gates + + `WBb[zrh]` - W bias vectors for backward update, reset, and hidden gates + + `RBb[zrh]` - R bias vectors for backward update, reset, and hidden gates + + `H` - Hidden state + + `num_directions` - 2 if direction == bidirectional else 1 + + Activation functions: + + Relu(x) - max(0, x) + + Tanh(x) - (1 - e^{-2x})/(1 + e^{-2x}) + + Sigmoid(x) - 1/(1 + e^{-x}) + + (NOTE: Below are optional) + + Affine(x) - alpha*x + beta + + LeakyRelu(x) - x if x >= 0 else alpha * x + + ThresholdedRelu(x) - x if x >= alpha else 0 + + ScaledTanh(x) - alpha*Tanh(beta*x) + + HardSigmoid(x) - min(max(alpha*x + beta, 0), 1) + + Elu(x) - x if x >= 0 else alpha*(e^x - 1) + + Softsign(x) - x/(1 + |x|) + + Softplus(x) - log(1 + e^x) + + Equations (Default: f=Sigmoid, g=Tanh): + + - zt = f(Xt*(Wz^T) + Ht-1*(Rz^T) + Wbz + Rbz) + + - rt = f(Xt*(Wr^T) + Ht-1*(Rr^T) + Wbr + Rbr) + + - ht = g(Xt*(Wh^T) + (rt (.) Ht-1)*(Rh^T) + Rbh + Wbh) # default, when linear_before_reset = 0 + + - ht = g(Xt*(Wh^T) + (rt (.) (Ht-1*(Rh^T) + Rbh)) + Wbh) # when linear_before_reset != 0 + + - Ht = (1 - zt) (.) ht + zt (.) Ht-1 + This operator has **optional** inputs/outputs. See [the doc](IR.md) for more details about the representation of optional arguments. An empty string may be used in the place of an actual argument's name to indicate a missing argument. Trailing optional arguments (those not followed by an argument that is present) may also be simply omitted. + +#### Version + +This version of the operator has been available since version 14 of the default ONNX operator set. + +#### Attributes + +
+
activation_alpha : list of floats
+
Optional scaling values used by some activation functions. The values are consumed in the order of activation functions, for example (f, g, h) in LSTM. Default values are the same as of corresponding ONNX operators.For example with LeakyRelu, the default alpha is 0.01.
+
activation_beta : list of floats
+
Optional scaling values used by some activation functions. The values are consumed in the order of activation functions, for example (f, g, h) in LSTM. Default values are the same as of corresponding ONNX operators.
+
activations : list of strings
+
A list of 2 (or 4 if bidirectional) activation functions for update, reset, and hidden gates. The activation functions must be one of the activation functions specified above. Optional: See the equations for default if not specified.
+
clip : float
+
Cell clip threshold. Clipping bounds the elements of a tensor in the range of [-threshold, +threshold] and is applied to the input of activations. No clip if not specified.
+
direction : string (default is forward)
+
Specify if the RNN is forward, reverse, or bidirectional. Must be one of forward (default), reverse, or bidirectional.
+
hidden_size : int
+
Number of neurons in the hidden layer
+
layout : int (default is 0)
+
The shape format of inputs X, initial_h and outputs Y, Y_h. If 0, the following shapes are expected: X.shape = [seq_length, batch_size, input_size], Y.shape = [seq_length, num_directions, batch_size, hidden_size], initial_h.shape = Y_h.shape = [num_directions, batch_size, hidden_size]. If 1, the following shapes are expected: X.shape = [batch_size, seq_length, input_size], Y.shape = [batch_size, seq_length, num_directions, hidden_size], initial_h.shape = Y_h.shape = [batch_size, num_directions, hidden_size].
+
linear_before_reset : int (default is 0)
+
When computing the output of the hidden gate, apply the linear transformation before multiplying by the output of the reset gate.
+
+ +#### Inputs (3 - 6) + +
+
X (differentiable) : T
+
The input sequences packed (and potentially padded) into one 3-D tensor with the shape of `[seq_length, batch_size, input_size]`.
+
W (differentiable) : T
+
The weight tensor for the gates. Concatenation of `W[zrh]` and `WB[zrh]` (if bidirectional) along dimension 0. This tensor has shape `[num_directions, 3*hidden_size, input_size]`.
+
R (differentiable) : T
+
The recurrence weight tensor. Concatenation of `R[zrh]` and `RB[zrh]` (if bidirectional) along dimension 0. This tensor has shape `[num_directions, 3*hidden_size, hidden_size]`.
+
B (optional, differentiable) : T
+
The bias tensor for the gates. Concatenation of `[Wb[zrh], Rb[zrh]]` and `[WBb[zrh], RBb[zrh]]` (if bidirectional) along dimension 0. This tensor has shape `[num_directions, 6*hidden_size]`. Optional: If not specified - assumed to be 0
+
sequence_lens (optional, non-differentiable) : T1
+
Optional tensor specifying lengths of the sequences in a batch. If not specified - assumed all sequences in the batch to have length `seq_length`. It has shape `[batch_size]`.
+
initial_h (optional, non-differentiable) : T
+
Optional initial value of the hidden. If not specified - assumed to be 0. It has shape `[num_directions, batch_size, hidden_size]`.
+
+ +#### Outputs (0 - 2) + +
+
Y (optional, differentiable) : T
+
A tensor that concats all the intermediate output values of the hidden. It has shape `[seq_length, num_directions, batch_size, hidden_size]`.
+
Y_h (optional, differentiable) : T
+
The last output value of the hidden. It has shape `[num_directions, batch_size, hidden_size]`.
+
+ +#### Type Constraints + +
+
T : tensor(float16), tensor(float), tensor(double)
+
Constrain input and output types to float tensors.
+
T1 : tensor(int32)
+
Constrain seq_lens to integer tensor.
+
+ +### **HardSwish-14** + + HardSwish takes one input data (Tensor) and produces one output data (Tensor) where + the HardSwish function, y = x * max(0, min(1, alpha * x + beta)) = x * HardSigmoid(x), + where alpha = 1/6 and beta = 0.5, is applied to the tensor elementwise. + +#### Version + +This version of the operator has been available since version 14 of the default ONNX operator set. + +#### Inputs + +
+
X (differentiable) : T
+
Input tensor
+
+ +#### Outputs + +
+
Y (differentiable) : T
+
Output tensor
+
+ +#### Type Constraints + +
+
T : tensor(float16), tensor(float), tensor(double)
+
Constrain input and output types to float tensors.
+
+ +### **Identity-14** + + Identity operator + +#### Version + +This version of the operator has been available since version 14 of the default ONNX operator set. + +#### Inputs + +
+
input (differentiable) : V
+
Input tensor
+
+ +#### Outputs + +
+
output (differentiable) : V
+
Tensor to copy input into.
+
+ +#### Type Constraints + +
+
V : tensor(uint8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(int8), tensor(int16), tensor(int32), tensor(int64), tensor(bfloat16), tensor(float16), tensor(float), tensor(double), tensor(string), tensor(bool), tensor(complex64), tensor(complex128), seq(tensor(uint8)), seq(tensor(uint16)), seq(tensor(uint32)), seq(tensor(uint64)), seq(tensor(int8)), seq(tensor(int16)), seq(tensor(int32)), seq(tensor(int64)), seq(tensor(float16)), seq(tensor(float)), seq(tensor(double)), seq(tensor(string)), seq(tensor(bool)), seq(tensor(complex64)), seq(tensor(complex128))
+
Constrain input and output types to all tensor and sequence types.
+
+ +### **LSTM-14** + + Computes an one-layer LSTM. This operator is usually supported via some + custom implementation such as CuDNN. + + Notations: + + `X` - input tensor + + `i` - input gate + + `o` - output gate + + `f` - forget gate + + `c` - cell gate + + `t` - time step (t-1 means previous time step) + + `W[iofc]` - W parameter weight matrix for input, output, forget, and cell gates + + `R[iofc]` - R recurrence weight matrix for input, output, forget, and cell gates + + `Wb[iofc]` - W bias vectors for input, output, forget, and cell gates + + `Rb[iofc]` - R bias vectors for input, output, forget, and cell gates + + `P[iof]` - P peephole weight vector for input, output, and forget gates + + `WB[iofc]` - W parameter weight matrix for backward input, output, forget, and cell gates + + `RB[iofc]` - R recurrence weight matrix for backward input, output, forget, and cell gates + + `WBb[iofc]` - W bias vectors for backward input, output, forget, and cell gates + + `RBb[iofc]` - R bias vectors for backward input, output, forget, and cell gates + + `PB[iof]` - P peephole weight vector for backward input, output, and forget gates + + `H` - Hidden state + + `num_directions` - 2 if direction == bidirectional else 1 + + Activation functions: + + Relu(x) - max(0, x) + + Tanh(x) - (1 - e^{-2x})/(1 + e^{-2x}) + + Sigmoid(x) - 1/(1 + e^{-x}) + + (NOTE: Below are optional) + + Affine(x) - alpha*x + beta + + LeakyRelu(x) - x if x >= 0 else alpha * x + + ThresholdedRelu(x) - x if x >= alpha else 0 + + ScaledTanh(x) - alpha*Tanh(beta*x) + + HardSigmoid(x) - min(max(alpha*x + beta, 0), 1) + + Elu(x) - x if x >= 0 else alpha*(e^x - 1) + + Softsign(x) - x/(1 + |x|) + + Softplus(x) - log(1 + e^x) + + Equations (Default: f=Sigmoid, g=Tanh, h=Tanh): + + - it = f(Xt*(Wi^T) + Ht-1*(Ri^T) + Pi (.) Ct-1 + Wbi + Rbi) + + - ft = f(Xt*(Wf^T) + Ht-1*(Rf^T) + Pf (.) Ct-1 + Wbf + Rbf) + + - ct = g(Xt*(Wc^T) + Ht-1*(Rc^T) + Wbc + Rbc) + + - Ct = ft (.) Ct-1 + it (.) ct + + - ot = f(Xt*(Wo^T) + Ht-1*(Ro^T) + Po (.) Ct + Wbo + Rbo) + + - Ht = ot (.) h(Ct) + This operator has **optional** inputs/outputs. See [the doc](IR.md) for more details about the representation of optional arguments. An empty string may be used in the place of an actual argument's name to indicate a missing argument. Trailing optional arguments (those not followed by an argument that is present) may also be simply omitted. + +#### Version + +This version of the operator has been available since version 14 of the default ONNX operator set. + +#### Attributes + +
+
activation_alpha : list of floats
+
Optional scaling values used by some activation functions. The values are consumed in the order of activation functions, for example (f, g, h) in LSTM. Default values are the same as of corresponding ONNX operators.For example with LeakyRelu, the default alpha is 0.01.
+
activation_beta : list of floats
+
Optional scaling values used by some activation functions. The values are consumed in the order of activation functions, for example (f, g, h) in LSTM. Default values are the same as of corresponding ONNX operators.
+
activations : list of strings
+
A list of 3 (or 6 if bidirectional) activation functions for input, output, forget, cell, and hidden. The activation functions must be one of the activation functions specified above. Optional: See the equations for default if not specified.
+
clip : float
+
Cell clip threshold. Clipping bounds the elements of a tensor in the range of [-threshold, +threshold] and is applied to the input of activations. No clip if not specified.
+
direction : string (default is forward)
+
Specify if the RNN is forward, reverse, or bidirectional. Must be one of forward (default), reverse, or bidirectional.
+
hidden_size : int
+
Number of neurons in the hidden layer
+
input_forget : int (default is 0)
+
Couple the input and forget gates if 1.
+
layout : int (default is 0)
+
The shape format of inputs X, initial_h, initial_c and outputs Y, Y_h, Y_c. If 0, the following shapes are expected: X.shape = [seq_length, batch_size, input_size], Y.shape = [seq_length, num_directions, batch_size, hidden_size], initial_h.shape = Y_h.shape = initial_c.shape = Y_c.shape = [num_directions, batch_size, hidden_size]. If 1, the following shapes are expected: X.shape = [batch_size, seq_length, input_size], Y.shape = [batch_size, seq_length, num_directions, hidden_size], initial_h.shape = Y_h.shape = initial_c.shape = Y_c.shape = [batch_size, num_directions, hidden_size].
+
+ +#### Inputs (3 - 8) + +
+
X (differentiable) : T
+
The input sequences packed (and potentially padded) into one 3-D tensor with the shape of `[seq_length, batch_size, input_size]`.
+
W (differentiable) : T
+
The weight tensor for the gates. Concatenation of `W[iofc]` and `WB[iofc]` (if bidirectional) along dimension 0. The tensor has shape `[num_directions, 4*hidden_size, input_size]`.
+
R (differentiable) : T
+
The recurrence weight tensor. Concatenation of `R[iofc]` and `RB[iofc]` (if bidirectional) along dimension 0. This tensor has shape `[num_directions, 4*hidden_size, hidden_size]`.
+
B (optional, differentiable) : T
+
The bias tensor for input gate. Concatenation of `[Wb[iofc], Rb[iofc]]`, and `[WBb[iofc], RBb[iofc]]` (if bidirectional) along dimension 0. This tensor has shape `[num_directions, 8*hidden_size]`. Optional: If not specified - assumed to be 0.
+
sequence_lens (optional, non-differentiable) : T1
+
Optional tensor specifying lengths of the sequences in a batch. If not specified - assumed all sequences in the batch to have length `seq_length`. It has shape `[batch_size]`.
+
initial_h (optional, non-differentiable) : T
+
Optional initial value of the hidden. If not specified - assumed to be 0. It has shape `[num_directions, batch_size, hidden_size]`.
+
initial_c (optional, non-differentiable) : T
+
Optional initial value of the cell. If not specified - assumed to be 0. It has shape `[num_directions, batch_size, hidden_size]`.
+
P (optional, differentiable) : T
+
The weight tensor for peepholes. Concatenation of `P[iof]` and `PB[iof]` (if bidirectional) along dimension 0. It has shape `[num_directions, 3*hidde_size]`. Optional: If not specified - assumed to be 0.
+
+ +#### Outputs (0 - 3) + +
+
Y (optional, differentiable) : T
+
A tensor that concats all the intermediate output values of the hidden. It has shape `[seq_length, num_directions, batch_size, hidden_size]`.
+
Y_h (optional, differentiable) : T
+
The last output value of the hidden. It has shape `[num_directions, batch_size, hidden_size]`.
+
Y_c (optional, differentiable) : T
+
The last output value of the cell. It has shape `[num_directions, batch_size, hidden_size]`.
+
+ +#### Type Constraints + +
+
T : tensor(float16), tensor(float), tensor(double)
+
Constrain input and output types to float tensors.
+
T1 : tensor(int32)
+
Constrain seq_lens to integer tensor.
+
+ +### **Mul-14** + + Performs element-wise binary multiplication (with Numpy-style broadcasting support). + + This operator supports **multidirectional (i.e., Numpy-style) broadcasting**; for more details please check [the doc](Broadcasting.md). + + (Opset 14 change): Extend supported types to include uint8, int8, uint16, and int16. + +#### Version + +This version of the operator has been available since version 14 of the default ONNX operator set. + +#### Inputs + +
+
A (differentiable) : T
+
First operand.
+
B (differentiable) : T
+
Second operand.
+
+ +#### Outputs + +
+
C (differentiable) : T
+
Result, has same element type as two inputs
+
+ +#### Type Constraints + +
+
T : tensor(uint8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(int8), tensor(int16), tensor(int32), tensor(int64), tensor(float16), tensor(float), tensor(double), tensor(bfloat16)
+
Constrain input and output types to all numeric tensors.
+
+ +### **RNN-14** + + Computes an one-layer simple RNN. This operator is usually supported + via some custom implementation such as CuDNN. + + Notations: + + `X` - input tensor + + `i` - input gate + + `t` - time step (t-1 means previous time step) + + `Wi` - W parameter weight matrix for input gate + + `Ri` - R recurrence weight matrix for input gate + + `Wbi` - W parameter bias vector for input gate + + `Rbi` - R parameter bias vector for input gate + + `WBi` - W parameter weight matrix for backward input gate + + `RBi` - R recurrence weight matrix for backward input gate + + `WBbi` - WR bias vectors for backward input gate + + `RBbi` - RR bias vectors for backward input gate + + `H` - Hidden state + + `num_directions` - 2 if direction == bidirectional else 1 + + Activation functions: + + Relu(x) - max(0, x) + + Tanh(x) - (1 - e^{-2x})/(1 + e^{-2x}) + + Sigmoid(x) - 1/(1 + e^{-x}) + + (NOTE: Below are optional) + + Affine(x) - alpha*x + beta + + LeakyRelu(x) - x if x >= 0 else alpha * x + + ThresholdedRelu(x) - x if x >= alpha else 0 + + ScaledTanh(x) - alpha*Tanh(beta*x) + + HardSigmoid(x) - min(max(alpha*x + beta, 0), 1) + + Elu(x) - x if x >= 0 else alpha*(e^x - 1) + + Softsign(x) - x/(1 + |x|) + + Softplus(x) - log(1 + e^x) + + Equations (Default: f=Tanh): + + - Ht = f(Xt*(Wi^T) + Ht-1*(Ri^T) + Wbi + Rbi) + This operator has **optional** inputs/outputs. See [the doc](IR.md) for more details about the representation of optional arguments. An empty string may be used in the place of an actual argument's name to indicate a missing argument. Trailing optional arguments (those not followed by an argument that is present) may also be simply omitted. + +#### Version + +This version of the operator has been available since version 14 of the default ONNX operator set. + +#### Attributes + +
+
activation_alpha : list of floats
+
Optional scaling values used by some activation functions. The values are consumed in the order of activation functions, for example (f, g, h) in LSTM. Default values are the same as of corresponding ONNX operators.For example with LeakyRelu, the default alpha is 0.01.
+
activation_beta : list of floats
+
Optional scaling values used by some activation functions. The values are consumed in the order of activation functions, for example (f, g, h) in LSTM. Default values are the same as of corresponding ONNX operators.
+
activations : list of strings (default is ['Tanh', 'Tanh'])
+
One (or two if bidirectional) activation function for input gate. The activation function must be one of the activation functions specified above. Optional: Default `Tanh` if not specified.
+
clip : float
+
Cell clip threshold. Clipping bounds the elements of a tensor in the range of [-threshold, +threshold] and is applied to the input of activations. No clip if not specified.
+
direction : string (default is forward)
+
Specify if the RNN is forward, reverse, or bidirectional. Must be one of forward (default), reverse, or bidirectional.
+
hidden_size : int
+
Number of neurons in the hidden layer
+
layout : int (default is 0)
+
The shape format of inputs X, initial_h and outputs Y, Y_h. If 0, the following shapes are expected: X.shape = [seq_length, batch_size, input_size], Y.shape = [seq_length, num_directions, batch_size, hidden_size], initial_h.shape = Y_h.shape = [num_directions, batch_size, hidden_size]. If 1, the following shapes are expected: X.shape = [batch_size, seq_length, input_size], Y.shape = [batch_size, seq_length, num_directions, hidden_size], initial_h.shape = Y_h.shape = [batch_size, num_directions, hidden_size].
+
+ +#### Inputs (3 - 6) + +
+
X (differentiable) : T
+
The input sequences packed (and potentially padded) into one 3-D tensor with the shape of `[seq_length, batch_size, input_size]`.
+
W (differentiable) : T
+
The weight tensor for input gate. Concatenation of `Wi` and `WBi` (if bidirectional). The tensor has shape `[num_directions, hidden_size, input_size]`.
+
R (differentiable) : T
+
The recurrence weight tensor. Concatenation of `Ri` and `RBi` (if bidirectional). The tensor has shape `[num_directions, hidden_size, hidden_size]`.
+
B (optional, differentiable) : T
+
The bias tensor for input gate. Concatenation of `[Wbi, Rbi]` and `[WBbi, RBbi]` (if bidirectional). The tensor has shape `[num_directions, 2*hidden_size]`. Optional: If not specified - assumed to be 0.
+
sequence_lens (optional, non-differentiable) : T1
+
Optional tensor specifying lengths of the sequences in a batch. If not specified - assumed all sequences in the batch to have length `seq_length`. It has shape `[batch_size]`.
+
initial_h (optional, non-differentiable) : T
+
Optional initial value of the hidden. If not specified - assumed to be 0. It has shape `[num_directions, batch_size, hidden_size]`.
+
+ +#### Outputs (0 - 2) + +
+
Y (optional, differentiable) : T
+
A tensor that concats all the intermediate output values of the hidden. It has shape `[seq_length, num_directions, batch_size, hidden_size]`.
+
Y_h (optional, differentiable) : T
+
The last output value of the hidden. It has shape `[num_directions, batch_size, hidden_size]`.
+
+ +#### Type Constraints + +
+
T : tensor(float16), tensor(float), tensor(double)
+
Constrain input and output types to float tensors.
+
T1 : tensor(int32)
+
Constrain seq_lens to integer tensor.
+
+ +### **Relu-14** + + Relu takes one input data (Tensor) and produces one output data + (Tensor) where the rectified linear function, y = max(0, x), is applied to + the tensor elementwise. + +#### Version + +This version of the operator has been available since version 14 of the default ONNX operator set. + +#### Inputs + +
+
X (differentiable) : T
+
Input tensor
+
+ +#### Outputs + +
+
Y (differentiable) : T
+
Output tensor
+
+ +#### Type Constraints + +
+
T : tensor(float), tensor(int32), tensor(int8), tensor(int16), tensor(int64), tensor(float16), tensor(double), tensor(bfloat16)
+
Constrain input and output types to signed numeric tensors.
+
+ +### **Reshape-14** + + Reshape the input tensor similar to numpy.reshape. + First input is the data tensor, second input is a shape tensor which specifies the output shape. It outputs the reshaped tensor. + At most one dimension of the new shape can be -1. In this case, the value is + inferred from the size of the tensor and the remaining dimensions. A dimension + could also be 0, in which case the actual dimension value is unchanged (i.e. taken + from the input tensor). If 'allowzero' is set, and the new shape includes 0, the + dimension will be set explicitly to zero (i.e. not taken from input tensor) + +#### Version + +This version of the operator has been available since version 14 of the default ONNX operator set. + +#### Attributes + +
+
allowzero : int (default is 0)
+
(Optional) By default, when any value in the 'shape' input is equal to zero the corresponding dimension value is copied from the input tensor dynamically. allowzero=1 indicates that if any value in the 'shape' input is set to zero, the zero value is honored, similar to NumPy.
+
+ +#### Inputs + +
+
data (differentiable) : T
+
An input tensor.
+
shape (non-differentiable) : tensor(int64)
+
Specified shape for output.
+
+ +#### Outputs + +
+
reshaped (differentiable) : T
+
Reshaped data.
+
+ +#### Type Constraints + +
+
T : tensor(uint8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(int8), tensor(int16), tensor(int32), tensor(int64), tensor(bfloat16), tensor(float16), tensor(float), tensor(double), tensor(string), tensor(bool), tensor(complex64), tensor(complex128)
+
Constrain input and output types to all tensor types.
+
+ +### **Sub-14** + + Performs element-wise binary subtraction (with Numpy-style broadcasting support). + + This operator supports **multidirectional (i.e., Numpy-style) broadcasting**; for more details please check [the doc](Broadcasting.md). + + (Opset 14 change): Extend supported types to include uint8, int8, uint16, and int16. + +#### Version + +This version of the operator has been available since version 14 of the default ONNX operator set. + +#### Inputs + +
+
A (differentiable) : T
+
First operand.
+
B (differentiable) : T
+
Second operand.
+
+ +#### Outputs + +
+
C (differentiable) : T
+
Result, has same element type as two inputs
+
+ +#### Type Constraints + +
+
T : tensor(uint8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(int8), tensor(int16), tensor(int32), tensor(int64), tensor(float16), tensor(float), tensor(double), tensor(bfloat16)
+
Constrain input and output types to all numeric tensors.
+
+ +### **Trilu-14** + + Given a 2-D matrix or batches of 2-D matrices, returns the upper or lower triangular part of the tensor(s). + The attribute "upper" determines whether the upper or lower part is retained. If set to true, + the upper triangular matrix is retained. Lower triangular matrix is retained otherwise. + Default value for the "upper" attribute is true. + Trilu takes one input tensor of shape [*, N, M], where * is zero or more batch dimensions. The upper triangular part consists + of the elements on and above the given diagonal (k). The lower triangular part consists of elements on and below the diagonal. + All other elements in the matrix are set to zero. + If k = 0, the triangular part on and above/below the main diagonal is retained. + If upper is set to true, a positive k retains the upper triangular matrix excluding the main diagonal and (k-1) diagonals above it. + A negative k value retains the main diagonal and |k| diagonals below it. + If upper is set to false, a positive k retains the lower triangular matrix including the main diagonal and k diagonals above it. + A negative k value excludes the main diagonal and (|k|-1) diagonals below it. + +#### Version + +This version of the operator has been available since version 14 of the default ONNX operator set. + +#### Attributes + +
+
upper : int (default is 1)
+
Boolean. Indicates whether upper or lower part of matrix is retained. Default is true.
+
+ +#### Inputs (1 - 2) + +
+
input (differentiable) : T
+
Input tensor of rank 2 or higher.
+
k (optional, non-differentiable) : tensor(int64)
+
A 0-D tensor containing a single value corresponding to the number diagonals above or below the main diagonal to exclude or include. Default value is 0 if it's not specified.
+
+ +#### Outputs + +
+
output (differentiable) : T
+
Output tensor of the same type and shape as the input tensor.
+
+ +#### Type Constraints + +
+
T : tensor(uint8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(int8), tensor(int16), tensor(int32), tensor(int64), tensor(bfloat16), tensor(float16), tensor(float), tensor(double), tensor(string), tensor(bool), tensor(complex64), tensor(complex128)
+
Constrain input and output types to all tensor types.
+
+ +## Version 15 of the default ONNX operator set +### **BatchNormalization-15** + + Carries out batch normalization as described in the paper + https://arxiv.org/abs/1502.03167. Depending on the mode it is being run, + There are five required inputs 'X', 'scale', 'B', 'input_mean' and + 'input_var'. + Note that 'input_mean' and 'input_var' are expected to be the estimated + statistics in inference mode (training_mode=False, default), + and the running statistics in training mode (training_mode=True). + There are multiple cases for the number of outputs, which we list below: + + Output case #1: Y, running_mean, running_var (training_mode=True) + Output case #2: Y (training_mode=False) + + When training_mode=False, extra outputs are invalid. + The outputs are updated as follows when training_mode=True: + ``` + running_mean = input_mean * momentum + current_mean * (1 - momentum) + running_var = input_var * momentum + current_var * (1 - momentum) + + Y = (X - current_mean) / sqrt(current_var + epsilon) * scale + B + + where: + + current_mean = ReduceMean(X, axis=all_except_channel_index) + current_var = ReduceVar(X, axis=all_except_channel_index) + + Notice that ReduceVar refers to the population variance, and it equals to + sum(sqrd(x_i - x_avg)) / N + where N is the population size (this formula does not use sample size N - 1). + + ``` + + The computation of ReduceMean and ReduceVar uses float to avoid overflow for float16 inputs. + + When training_mode=False: + ``` + Y = (X - input_mean) / sqrt(input_var + epsilon) * scale + B + ``` + + For previous (depreciated) non-spatial cases, implementors are suggested + to flatten the input shape to (N x C * D1 * D2 * ... * Dn) before a BatchNormalization Op. + This operator has **optional** inputs/outputs. See [the doc](IR.md) for more details about the representation of optional arguments. An empty string may be used in the place of an actual argument's name to indicate a missing argument. Trailing optional arguments (those not followed by an argument that is present) may also be simply omitted. + +#### Version + +This version of the operator has been available since version 15 of the default ONNX operator set. + +#### Attributes + +
+
epsilon : float (default is 1e-05)
+
The epsilon value to use to avoid division by zero.
+
momentum : float (default is 0.9)
+
Factor used in computing the running mean and variance.e.g., running_mean = running_mean * momentum + mean * (1 - momentum).
+
training_mode : int (default is 0)
+
If set to true, it indicates BatchNormalization is being used for training, and outputs 1, 2, 3, and 4 would be populated.
+
+ +#### Inputs + +
+
X (differentiable) : T
+
Input data tensor from the previous operator; dimensions are in the form of (N x C x D1 x D2 ... Dn), where N is the batch size, C is the number of channels. Statistics are computed for every channel of C over N and D1 to Dn dimensions. For image data, input dimensions become (N x C x H x W). The op also accepts single dimension input of size N in which case C is assumed to be 1
+
scale (differentiable) : T1
+
Scale tensor of shape (C).
+
B (differentiable) : T1
+
Bias tensor of shape (C).
+
input_mean (differentiable) : T2
+
running (training) or estimated (testing) mean tensor of shape (C).
+
input_var (differentiable) : T2
+
running (training) or estimated (testing) variance tensor of shape (C).
+
+ +#### Outputs (1 - 3) + +
+
Y (differentiable) : T
+
The output tensor of the same shape as X
+
running_mean (optional, non-differentiable) : T2
+
The running mean after the BatchNormalization operator.
+
running_var (optional, non-differentiable) : T2
+
The running variance after the BatchNormalization operator. This op uses the population size (N) for calculating variance, and not the sample size N-1.
+
+ +#### Type Constraints + +
+
T : tensor(float16), tensor(float), tensor(double), tensor(bfloat16)
+
Constrain input and output types to float tensors.
+
T1 : tensor(float16), tensor(float), tensor(double), tensor(bfloat16)
+
Constrain scale and bias types to float tensors.
+
T2 : tensor(float16), tensor(float), tensor(double), tensor(bfloat16)
+
Constrain mean and variance types to float tensors.
+
+ +### **Bernoulli-15** + + Draws binary random numbers (0 or 1) from a Bernoulli distribution. The input tensor should be a tensor + containing probabilities p (a value in the range [0,1]) to be used for drawing the binary random number, + where an output of 1 is produced with probability p and an output of 0 is produced with probability (1-p). + + This operator is non-deterministic and may not produce the same values in different + implementations (even if a seed is specified). + +#### Version + +This version of the operator has been available since version 15 of the default ONNX operator set. + +#### Attributes + +
+
dtype : int
+
The data type for the elements of the output tensor. if not specified, we will use the data type of the input tensor.
+
seed : float
+
(Optional) Seed to the random generator, if not specified we will auto generate one.
+
+ +#### Inputs + +
+
input : T1
+
All values in input have to be in the range:[0, 1].
+
+ +#### Outputs + +
+
output : T2
+
The returned output tensor only has values 0 or 1, same shape as input tensor.
+
+ +#### Type Constraints + +
+
T1 : tensor(float16), tensor(float), tensor(double)
+
Constrain input types to float tensors.
+
T2 : tensor(float16), tensor(float), tensor(double), tensor(bfloat16), tensor(uint8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(int8), tensor(int16), tensor(int32), tensor(int64), tensor(bool)
+
Constrain output types to all numeric tensors and bool tensors.
+
+ +### **CastLike-15** + + The operator casts the elements of a given input tensor (the first input) to + the same data type as the elements of the second input tensor. + See documentation of the Cast operator for further details. + +#### Version + +This version of the operator has been available since version 15 of the default ONNX operator set. + +#### Inputs + +
+
input (differentiable) : T1
+
Input tensor to be cast.
+
target_type (non-differentiable) : T2
+
The (first) input tensor will be cast to produce a tensor of the same type as this (second input) tensor.
+
+ +#### Outputs + +
+
output (differentiable) : T2
+
Output tensor produced by casting the first input tensor to have the same type as the second input tensor.
+
+ +#### Type Constraints + +
+
T1 : tensor(float16), tensor(float), tensor(double), tensor(int8), tensor(int16), tensor(int32), tensor(int64), tensor(uint8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(bool), tensor(string), tensor(bfloat16)
+
Constrain input types. Casting from complex is not supported.
+
T2 : tensor(float16), tensor(float), tensor(double), tensor(int8), tensor(int16), tensor(int32), tensor(int64), tensor(uint8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(bool), tensor(string), tensor(bfloat16)
+
Constrain output types. Casting to complex is not supported.
+
+ +### **Optional-15** + + Constructs an optional-type value containing either an empty optional of a certain type specified by the attribute, + or a non-empty value containing the input element. + +#### Version + +This version of the operator has been available since version 15 of the default ONNX operator set. + +#### Attributes + +
+
type : type_proto
+
Type of the element in the optional output
+
+ +#### Inputs (0 - 1) + +
+
input (optional) : V
+
The input element.
+
+ +#### Outputs + +
+
output : O
+
The optional output enclosing the input element.
+
+ +#### Type Constraints + +
+
V : tensor(uint8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(int8), tensor(int16), tensor(int32), tensor(int64), tensor(float16), tensor(float), tensor(double), tensor(string), tensor(bool), tensor(complex64), tensor(complex128), seq(tensor(uint8)), seq(tensor(uint16)), seq(tensor(uint32)), seq(tensor(uint64)), seq(tensor(int8)), seq(tensor(int16)), seq(tensor(int32)), seq(tensor(int64)), seq(tensor(float16)), seq(tensor(float)), seq(tensor(double)), seq(tensor(string)), seq(tensor(bool)), seq(tensor(complex64)), seq(tensor(complex128))
+
Constrains input type to all tensor and sequence types.
+
O : optional(seq(tensor(uint8))), optional(seq(tensor(uint16))), optional(seq(tensor(uint32))), optional(seq(tensor(uint64))), optional(seq(tensor(int8))), optional(seq(tensor(int16))), optional(seq(tensor(int32))), optional(seq(tensor(int64))), optional(seq(tensor(float16))), optional(seq(tensor(float))), optional(seq(tensor(double))), optional(seq(tensor(string))), optional(seq(tensor(bool))), optional(seq(tensor(complex64))), optional(seq(tensor(complex128))), optional(tensor(uint8)), optional(tensor(uint16)), optional(tensor(uint32)), optional(tensor(uint64)), optional(tensor(int8)), optional(tensor(int16)), optional(tensor(int32)), optional(tensor(int64)), optional(tensor(float16)), optional(tensor(float)), optional(tensor(double)), optional(tensor(string)), optional(tensor(bool)), optional(tensor(complex64)), optional(tensor(complex128))
+
Constrains output type to all optional tensor or optional sequence types.
+
+ +### **OptionalGetElement-15** + + Outputs the element in the optional-type input. It is an error if the input value does not have an element + and the behavior is undefined in this case. + +#### Version + +This version of the operator has been available since version 15 of the default ONNX operator set. + +#### Inputs + +
+
input : O
+
The optional input.
+
+ +#### Outputs + +
+
output : V
+
Output element in the optional input.
+
+ +#### Type Constraints + +
+
O : optional(seq(tensor(uint8))), optional(seq(tensor(uint16))), optional(seq(tensor(uint32))), optional(seq(tensor(uint64))), optional(seq(tensor(int8))), optional(seq(tensor(int16))), optional(seq(tensor(int32))), optional(seq(tensor(int64))), optional(seq(tensor(float16))), optional(seq(tensor(float))), optional(seq(tensor(double))), optional(seq(tensor(string))), optional(seq(tensor(bool))), optional(seq(tensor(complex64))), optional(seq(tensor(complex128))), optional(tensor(uint8)), optional(tensor(uint16)), optional(tensor(uint32)), optional(tensor(uint64)), optional(tensor(int8)), optional(tensor(int16)), optional(tensor(int32)), optional(tensor(int64)), optional(tensor(float16)), optional(tensor(float)), optional(tensor(double)), optional(tensor(string)), optional(tensor(bool)), optional(tensor(complex64)), optional(tensor(complex128))
+
Constrains input type to optional tensor and optional sequence types.
+
V : tensor(uint8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(int8), tensor(int16), tensor(int32), tensor(int64), tensor(float16), tensor(float), tensor(double), tensor(string), tensor(bool), tensor(complex64), tensor(complex128), seq(tensor(uint8)), seq(tensor(uint16)), seq(tensor(uint32)), seq(tensor(uint64)), seq(tensor(int8)), seq(tensor(int16)), seq(tensor(int32)), seq(tensor(int64)), seq(tensor(float16)), seq(tensor(float)), seq(tensor(double)), seq(tensor(string)), seq(tensor(bool)), seq(tensor(complex64)), seq(tensor(complex128))
+
Constrain output type to all tensor or sequence types.
+
+ +### **OptionalHasElement-15** + + Returns true if the optional-type input contains an element. If it is an empty optional-type, this op returns false. + +#### Version + +This version of the operator has been available since version 15 of the default ONNX operator set. + +#### Inputs + +
+
input : O
+
The optional input.
+
+ +#### Outputs + +
+
output : B
+
A scalar boolean tensor. If true, it indicates that optional-type input contains an element. Otherwise, it is empty.
+
+ +#### Type Constraints + +
+
O : optional(seq(tensor(uint8))), optional(seq(tensor(uint16))), optional(seq(tensor(uint32))), optional(seq(tensor(uint64))), optional(seq(tensor(int8))), optional(seq(tensor(int16))), optional(seq(tensor(int32))), optional(seq(tensor(int64))), optional(seq(tensor(float16))), optional(seq(tensor(float))), optional(seq(tensor(double))), optional(seq(tensor(string))), optional(seq(tensor(bool))), optional(seq(tensor(complex64))), optional(seq(tensor(complex128))), optional(tensor(uint8)), optional(tensor(uint16)), optional(tensor(uint32)), optional(tensor(uint64)), optional(tensor(int8)), optional(tensor(int16)), optional(tensor(int32)), optional(tensor(int64)), optional(tensor(float16)), optional(tensor(float)), optional(tensor(double)), optional(tensor(string)), optional(tensor(bool)), optional(tensor(complex64)), optional(tensor(complex128))
+
Constrains input type to optional tensor and optional sequence types.
+
B : tensor(bool)
+
Constrains output to a boolean tensor.
+
+ +### **Pow-15** + + Pow takes input data (Tensor) and exponent Tensor, and + produces one output data (Tensor) where the function `f(x) = x^exponent`, + is applied to the data tensor elementwise. + This operator supports **multidirectional (i.e., Numpy-style) broadcasting**; for more details please check [the doc](Broadcasting.md). + +#### Version + +This version of the operator has been available since version 15 of the default ONNX operator set. + +#### Inputs + +
+
X (differentiable) : T
+
First operand, base of the exponent.
+
Y (differentiable) : T1
+
Second operand, power of the exponent.
+
+ +#### Outputs + +
+
Z (differentiable) : T
+
Output tensor
+
+ +#### Type Constraints + +
+
T : tensor(int32), tensor(int64), tensor(float16), tensor(float), tensor(double), tensor(bfloat16)
+
Constrain input X and output types to float/int tensors.
+
T1 : tensor(uint8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(int8), tensor(int16), tensor(int32), tensor(int64), tensor(float16), tensor(float), tensor(double), tensor(bfloat16)
+
Constrain input Y types to float/int tensors.
+
+ +### **Shape-15** + + Takes a tensor as input and outputs an 1D int64 tensor containing the shape of the input tensor. + Optional attributes start and end can be used to compute a slice of the input tensor's shape. + If start axis is omitted, the slice starts from axis 0. + The end axis, if specified, is exclusive (and the returned value will not include the size of that axis). + If the end axis is omitted, the axes upto the last one will be included. + Negative axes indicate counting back from the last axis. + Note that axes will be clipped to the range [0, r-1], where r is the + rank of the input tensor if they are out-of-range (after adding r in the case of + negative axis). Thus, specifying any end value > r is equivalent to specifying an end + value of r, and specifying any start value < -r is equivalent to specifying a start + value of 0. + + For example: + Input tensor with shape: [2, 3, 4] + No attributes specified. + Output: [2, 3, 4] + + Input tensor with shape: [2, 3, 4] + start: -1 + Output: [4] + + Input tensor with shape: [2, 3, 4] + end: -1 + Output: [2, 3] + + Input tensor with shape: [2, 3, 4] + start: 1 + end: 2 + Output: [3] + +#### Version + +This version of the operator has been available since version 15 of the default ONNX operator set. + +#### Attributes + +
+
end : int
+
(Optional) Ending axis for slicing the shape. Negative value means counting dimensions from the back. If omitted, sizes of all axes upto (including) the last one will be included.
+
start : int (default is 0)
+
(Optional) Starting axis for slicing the shape. Default value is 0.Negative value means counting dimensions from the back.
+
+ +#### Inputs + +
+
data (non-differentiable) : T
+
An input tensor.
+
+ +#### Outputs + +
+
shape (non-differentiable) : T1
+
Shape of the input tensor
+
+ +#### Type Constraints + +
+
T : tensor(uint8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(int8), tensor(int16), tensor(int32), tensor(int64), tensor(bfloat16), tensor(float16), tensor(float), tensor(double), tensor(string), tensor(bool), tensor(complex64), tensor(complex128)
+
Input tensor can be of arbitrary type.
+
T1 : tensor(int64)
+
Constrain output to int64 tensor.
+
+ +## Version 16 of the default ONNX operator set +### **GridSample-16** + + Given an `input` and a flow-field `grid`, computes the `output` using `input` values and pixel locations from `grid`. + Currently, only spatial (4-D) inputs are supported. For `input` with shape (N, C, H, W) and `grid` with shape (N, H_out, W_out, 2), + the `output` will have shape (N, C, H_out, W_out). + For each output location `output[N, C, H_out, W_out]`, the size-2 vector `grid[N, H_out, W_out]` specifies `input` pixel locations `x` and `y`, + which are used to interpolate the output value `output[N, C, H_out, W_out]`. + + The GridSample operator is often used in doing grid generator and sampler in the [Spatial Transformer Networks](https://arxiv.org/abs/1506.02025). + See also in [torch.nn.functional.grid_sample](https://pytorch.org/docs/master/generated/torch.nn.functional.grid_sample.html#torch-nn-functional-grid-sample). + +#### Version + +This version of the operator has been available since version 16 of the default ONNX operator set. + +#### Attributes + +
+
align_corners : int (default is 0)
+
If align_corners=1, the extrema (-1 and 1) are considered as referring to the center points of the input's corner pixels. If align_corners=0, they are instead considered as referring to the corner points of the input's corner pixels, making the sampling more resolution agnostic.
+
mode : string (default is bilinear)
+
Three interpolation modes: bilinear (default), nearest and bicubic.
+
padding_mode : string (default is zeros)
+
Support padding modes for outside grid values: `zeros`(default), `border`, `reflection`. zeros: use 0 for out-of-bound grid locations, border: use border values for out-of-bound grid locations, reflection: use values at locations reflected by the border for out-of-bound grid locations. If index 0 represents the margin pixel, the reflected value at index -1 will be the same as the value at index 1. For location far away from the border, it will keep being reflected until becoming in bound. If pixel location x = -3.5 reflects by border -1 and becomes x' = 1.5, then reflects by border 1 and becomes x'' = 0.5.
+
+ +#### Inputs + +
+
X (differentiable) : T1
+
4-D tensor of shape (N, C, H, W), where N is the batch size, C is the numbers of channels, H and W are the height and width of the input data.
+
grid (non-differentiable) : T1
+
Input offset, 4-D tensor of shape (N, H_out, W_out, 2), where H_out and W_out are the height and width of grid and output, Grid specifies the sampling pixel locations normalized by the input spatial dimensions. Therefore, it should have most values in the range of [-1, 1]. If grid has values outside the range of [-1, 1], the corresponding outputs will be handled as defined by padding_mode.
+
+ +#### Outputs + +
+
Y (differentiable) : T2
+
4-D tensor of shape (N, C, H_out, W_out).
+
+ +#### Type Constraints + +
+
T1 : tensor(uint8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(int8), tensor(int16), tensor(int32), tensor(int64), tensor(float16), tensor(float), tensor(double), tensor(string), tensor(bool), tensor(complex64), tensor(complex128)
+
Constrain input types to all tensor types.
+
T2 : tensor(float16), tensor(float), tensor(double)
+
Constrain output types to float tensors.
+
+ +### **Identity-16** + + Identity operator + +#### Version + +This version of the operator has been available since version 16 of the default ONNX operator set. + +#### Inputs + +
+
input (differentiable) : V
+
Input tensor
+
+ +#### Outputs + +
+
output (differentiable) : V
+
Tensor to copy input into.
+
+ +#### Type Constraints + +
+
V : tensor(uint8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(int8), tensor(int16), tensor(int32), tensor(int64), tensor(bfloat16), tensor(float16), tensor(float), tensor(double), tensor(string), tensor(bool), tensor(complex64), tensor(complex128), seq(tensor(uint8)), seq(tensor(uint16)), seq(tensor(uint32)), seq(tensor(uint64)), seq(tensor(int8)), seq(tensor(int16)), seq(tensor(int32)), seq(tensor(int64)), seq(tensor(float16)), seq(tensor(float)), seq(tensor(double)), seq(tensor(string)), seq(tensor(bool)), seq(tensor(complex64)), seq(tensor(complex128)), optional(seq(tensor(uint8))), optional(seq(tensor(uint16))), optional(seq(tensor(uint32))), optional(seq(tensor(uint64))), optional(seq(tensor(int8))), optional(seq(tensor(int16))), optional(seq(tensor(int32))), optional(seq(tensor(int64))), optional(seq(tensor(float16))), optional(seq(tensor(float))), optional(seq(tensor(double))), optional(seq(tensor(string))), optional(seq(tensor(bool))), optional(seq(tensor(complex64))), optional(seq(tensor(complex128))), optional(tensor(uint8)), optional(tensor(uint16)), optional(tensor(uint32)), optional(tensor(uint64)), optional(tensor(int8)), optional(tensor(int16)), optional(tensor(int32)), optional(tensor(int64)), optional(tensor(float16)), optional(tensor(float)), optional(tensor(double)), optional(tensor(string)), optional(tensor(bool)), optional(tensor(complex64)), optional(tensor(complex128))
+
Constrain input and output types to all tensor, sequence, and optional types.
+
+ +### **If-16** + + If conditional + +#### Version + +This version of the operator has been available since version 16 of the default ONNX operator set. + +#### Attributes + +
+
else_branch : graph (required)
+
Graph to run if condition is false. Has N outputs: values you wish to be live-out to the enclosing scope. The number of outputs must match the number of outputs in the then_branch.
+
then_branch : graph (required)
+
Graph to run if condition is true. Has N outputs: values you wish to be live-out to the enclosing scope. The number of outputs must match the number of outputs in the else_branch.
+
+ +#### Inputs + +
+
cond : B
+
Condition for the if
+
+ +#### Outputs (1 - ∞) + +
+
outputs (variadic, heterogeneous) : V
+
Values that are live-out to the enclosing scope. The return values in the `then_branch` and `else_branch` must be of the same data type. The `then_branch` and `else_branch` may produce tensors with the same element type and different shapes. If corresponding outputs from the then-branch and the else-branch have static shapes S1 and S2, then the shape of the corresponding output variable of the if-node (if present) must be compatible with both S1 and S2 as it represents the union of both possible shapes.For example, if in a model file, the the first output of `then_branch` is typed float tensor with shape [2] and the first output of `else_branch` is another float tensor with shape [3], If's first output should have (a) no shape set, or (b) a shape of rank 1 with neither `dim_value` nor `dim_param` set, or (c) a shape of rank 1 with a unique `dim_param`. In contrast, the first output cannot have the shape [2] since [2] and [3] are not compatible.
+
+ +#### Type Constraints + +
+
V : tensor(uint8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(int8), tensor(int16), tensor(int32), tensor(int64), tensor(float16), tensor(float), tensor(double), tensor(string), tensor(bool), tensor(complex64), tensor(complex128), seq(tensor(uint8)), seq(tensor(uint16)), seq(tensor(uint32)), seq(tensor(uint64)), seq(tensor(int8)), seq(tensor(int16)), seq(tensor(int32)), seq(tensor(int64)), seq(tensor(float16)), seq(tensor(float)), seq(tensor(double)), seq(tensor(string)), seq(tensor(bool)), seq(tensor(complex64)), seq(tensor(complex128)), optional(seq(tensor(uint8))), optional(seq(tensor(uint16))), optional(seq(tensor(uint32))), optional(seq(tensor(uint64))), optional(seq(tensor(int8))), optional(seq(tensor(int16))), optional(seq(tensor(int32))), optional(seq(tensor(int64))), optional(seq(tensor(float16))), optional(seq(tensor(float))), optional(seq(tensor(double))), optional(seq(tensor(string))), optional(seq(tensor(bool))), optional(seq(tensor(complex64))), optional(seq(tensor(complex128))), optional(tensor(uint8)), optional(tensor(uint16)), optional(tensor(uint32)), optional(tensor(uint64)), optional(tensor(int8)), optional(tensor(int16)), optional(tensor(int32)), optional(tensor(int64)), optional(tensor(float16)), optional(tensor(float)), optional(tensor(double)), optional(tensor(string)), optional(tensor(bool)), optional(tensor(complex64)), optional(tensor(complex128))
+
All Tensor, Sequence, and optional types
+
B : tensor(bool)
+
Only bool
+
+ +### **Loop-16** + + Generic Looping construct. This loop has multiple termination conditions: + + 1) Trip count. Iteration count specified at runtime. Set by + specifying the input M. Optional. Set to empty string to omit. + Note that a static trip count (specified at graph construction time) can be + specified by passing in a constant node for input M. + 2) Loop termination condition. This is an input to the op that determines + whether to run the first iteration and also a loop-carried dependency for + the body graph. The body graph must yield a value for the condition variable, + whether this input is provided or not. + + This table summarizes the operating modes of this operator with equivalent + C-style code: + + Operator inputs defined as (max_trip_count, condition_var). + + input ("", ""): + for (int i=0; ; ++i) { + cond = ... // Note this value is ignored, but is required in the body + } + + input ("", cond) // Note this is analogous to a while loop + bool cond = ...; + for (int i=0; cond; ++i) { + cond = ...; + } + + input ("", 1) // Note this is analogous to a do-while loop + bool cond = true + for (int i=0; cond; ++i) { + cond = ...; + } + + input (trip_count, "") // Note this is analogous to a for loop + int trip_count = ... + for (int i=0; i < trip_count; ++i) { + cond = ...; // ignored + } + + input (trip_count, cond) + int trip_count = ...; + bool cond = ...; + for (int i=0; i < trip_count && cond; ++i) { + cond = ...; + } + + + *Sample usage - cond as well as trip count* + + graph predict-net { + %a = Constant[value = ]() + %b = Constant[value = ]() + %keepgoing = Constant[value = ]() + %max_trip_count = Constant[value = ]() + %keepgoing_out, %b_out, %user_defined_vals = Loop[body = ](%max_trip_count, %keepgoing, %b) + return + } + + graph body-net ( + %i[INT32, scalar] // iteration number + %keepgoing_in[BOOL, scalar] // incoming loop-termination-condition; not used + %b_in[INT32, scalar] // incoming value of loop-carried-dependency b + ) { + %my_local = Add(%a, %b_in) + %b_out = Sub(%a, %b_in) // outgoing value of loop-carried-dependency b + %keepgoing_out = Greater(%my_local, %b_out) // outgoing loop-termination-condition + %user_defined_val = Add(%b_in, %b_in) // scan-output value to be accumulated + return %keepgoing_out, %b_out, %user_defined_val + } + + *Sample equivalent C code* + + { + /* User-defined code (enclosing scope) */ + int a = 3, b = 6; + bool keepgoing = true; // Analogous to input cond + /* End user-defined code */ + + /* Implicitly-defined code */ + const int max_trip_count = 10; // Analogous to input M + int user_defined_vals[]; // Imagine this is resizable + /* End implicitly-defined code */ + /* initialize loop-carried variables and scan-output variables */ + bool keepgoing_out = keepgoing + int b_out = b + + for (int i=0; i < max_trip_count && keepgoing_out; ++i) { + /* Implicitly-defined code: bind actual parameter values + to formal parameter variables of loop-body */ + bool keepgoing_in = keepgoing_out; + bool b_in = b_out; + + /* User-defined code (loop body) */ + int my_local = a + b_in; // Reading value "a" from the enclosing scope is fine + b_out = a - b_in; + keepgoing_out = my_local > b_out; + user_defined_val = b_in + b_in; // b_in and b_out are different variables + /* End user-defined code */ + + /* Implicitly defined-code */ + user_defined_vals[i] = user_defined_val // accumulate scan-output values + } + // int t = my_local; // Can't do this. my_local is not accessible here. + + // The values below are bound to the output variables of the loop and therefore accessible + // b_out; user_defined_vals; keepgoing_out; + } + + There are several things of note in this code snippet: + + 1) Values from the enclosing scope (i.e. variable "a" here) are in scope and can + be referenced in the inputs of the loop. + 2) Any values computed in the loop body that needs to be used in a subsequent + iteration or after the loop are modelled using a pair of variables in the loop-body, + consisting of an input variable (eg., b_in) and an output variable (eg., b_out). + These are referred to as loop-carried dependences. The loop operation node + supplies the input value of the input variable for the first iteration, and + returns the output value of the output variable produced by the final + iteration. + 3) Scan_output variables are used to implicitly concatenate values computed across + all the iterations. In the above example, the value of user_defined_val computed + over all iterations are concatenated and returned as the value of user_defined_vals + after the loop. + 4) Values created in the body cannot be accessed in the enclosing scope, + except using the mechanism described above. + + Note that the semantics of this op support "diagonal" or "wavefront" execution. + (See Step 3 here for an example: + https://devblogs.nvidia.com/optimizing-recurrent-neural-networks-cudnn-5/). + Frontends should emit multi-layer RNNs as a series of While operators (with + time being the inner looping dimension), with each successive layer consuming + the scan_outputs from the previous layer, possibly going through several + point-wise operators (e.g. dropout, residual connections, linear layer). + + The input/output of subgraph (produced by loop node) matching is based on order instead of name. The implementation will figure out the names based on this order. + +#### Version + +This version of the operator has been available since version 16 of the default ONNX operator set. + +#### Attributes + +
+
body : graph (required)
+
The graph run each iteration. It has 2+N inputs: (iteration_num, condition, loop carried dependencies...). It has 1+N+K outputs: (condition, loop carried dependencies..., scan_outputs...). Each scan_output is created by concatenating the value of the specified output value at the end of each iteration of the loop. It is an error if the dimensions or data type of these scan_outputs change across loop iterations.
+
+ +#### Inputs (2 - ∞) + +
+
M (optional) : I
+
A maximum trip-count for the loop specified at runtime. Optional. Pass empty string to skip.
+
cond (optional) : B
+
A boolean termination condition. Optional. Pass empty string to skip.
+
v_initial (variadic, heterogeneous) : V
+
The initial values of any loop-carried dependencies (values that change across loop iterations)
+
+ +#### Outputs (1 - ∞) + +
+
v_final_and_scan_outputs (variadic, heterogeneous) : V
+
Final N loop carried dependency values then K scan_outputs. Scan outputs must be Tensors.
+
+ +#### Type Constraints + +
+
V : tensor(uint8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(int8), tensor(int16), tensor(int32), tensor(int64), tensor(float16), tensor(float), tensor(double), tensor(string), tensor(bool), tensor(complex64), tensor(complex128), seq(tensor(uint8)), seq(tensor(uint16)), seq(tensor(uint32)), seq(tensor(uint64)), seq(tensor(int8)), seq(tensor(int16)), seq(tensor(int32)), seq(tensor(int64)), seq(tensor(float16)), seq(tensor(float)), seq(tensor(double)), seq(tensor(string)), seq(tensor(bool)), seq(tensor(complex64)), seq(tensor(complex128)), optional(seq(tensor(uint8))), optional(seq(tensor(uint16))), optional(seq(tensor(uint32))), optional(seq(tensor(uint64))), optional(seq(tensor(int8))), optional(seq(tensor(int16))), optional(seq(tensor(int32))), optional(seq(tensor(int64))), optional(seq(tensor(float16))), optional(seq(tensor(float))), optional(seq(tensor(double))), optional(seq(tensor(string))), optional(seq(tensor(bool))), optional(seq(tensor(complex64))), optional(seq(tensor(complex128))), optional(tensor(uint8)), optional(tensor(uint16)), optional(tensor(uint32)), optional(tensor(uint64)), optional(tensor(int8)), optional(tensor(int16)), optional(tensor(int32)), optional(tensor(int64)), optional(tensor(float16)), optional(tensor(float)), optional(tensor(double)), optional(tensor(string)), optional(tensor(bool)), optional(tensor(complex64)), optional(tensor(complex128))
+
All Tensor and Sequence types
+
I : tensor(int64)
+
tensor of int64, which should be a scalar.
+
B : tensor(bool)
+
tensor of bool, which should be a scalar.
+
+ +### **RoiAlign-16** + + Region of Interest (RoI) align operation described in the + [Mask R-CNN paper](https://arxiv.org/abs/1703.06870). + RoiAlign consumes an input tensor X and region of interests (rois) + to apply pooling across each RoI; it produces a 4-D tensor of shape + (num_rois, C, output_height, output_width). + + RoiAlign is proposed to avoid the misalignment by removing + quantizations while converting from original image into feature + map and from feature map into RoI feature; in each ROI bin, + the value of the sampled locations are computed directly + through bilinear interpolation. + +#### Version + +This version of the operator has been available since version 16 of the default ONNX operator set. + +#### Attributes + +
+
coordinate_transformation_mode : string (default is half_pixel)
+
Allowed values are 'half_pixel' and 'output_half_pixel'. Use the value 'half_pixel' to pixel shift the input coordinates by -0.5 (the recommended behavior). Use the value 'output_half_pixel' to omit the pixel shift for the input (use this for a backward-compatible behavior).
+
mode : string (default is avg)
+
The pooling method. Two modes are supported: 'avg' and 'max'. Default is 'avg'.
+
output_height : int (default is 1)
+
default 1; Pooled output Y's height.
+
output_width : int (default is 1)
+
default 1; Pooled output Y's width.
+
sampling_ratio : int (default is 0)
+
Number of sampling points in the interpolation grid used to compute the output value of each pooled output bin. If > 0, then exactly sampling_ratio x sampling_ratio grid points are used. If == 0, then an adaptive number of grid points are used (computed as ceil(roi_width / output_width), and likewise for height). Default is 0.
+
spatial_scale : float (default is 1.0)
+
Multiplicative spatial scale factor to translate ROI coordinates from their input spatial scale to the scale used when pooling, i.e., spatial scale of the input feature map X relative to the input image. E.g.; default is 1.0f.
+
+ +#### Inputs + +
+
X : T1
+
Input data tensor from the previous operator; 4-D feature map of shape (N, C, H, W), where N is the batch size, C is the number of channels, and H and W are the height and the width of the data.
+
rois : T1
+
RoIs (Regions of Interest) to pool over; rois is 2-D input of shape (num_rois, 4) given as [[x1, y1, x2, y2], ...]. The RoIs' coordinates are in the coordinate system of the input image. Each coordinate set has a 1:1 correspondence with the 'batch_indices' input.
+
batch_indices : T2
+
1-D tensor of shape (num_rois,) with each element denoting the index of the corresponding image in the batch.
+
+ +#### Outputs + +
+
Y : T1
+
RoI pooled output, 4-D tensor of shape (num_rois, C, output_height, output_width). The r-th batch element Y[r-1] is a pooled feature map corresponding to the r-th RoI X[r-1].
+
+ +#### Type Constraints + +
+
T1 : tensor(float16), tensor(float), tensor(double)
+
Constrain types to float tensors.
+
T2 : tensor(int64)
+
Constrain types to int tensors.
+
+ +### **ScatterElements-16** + + ScatterElements takes three inputs `data`, `updates`, and `indices` of the same + rank r >= 1 and an optional attribute axis that identifies an axis of `data` + (by default, the outer-most axis, that is axis 0). The output of the operation + is produced by creating a copy of the input `data`, and then updating its value + to values specified by `updates` at specific index positions specified by + `indices`. Its output shape is the same as the shape of `data`. + + For each entry in `updates`, the target index in `data` is obtained by combining + the corresponding entry in `indices` with the index of the entry itself: the + index-value for dimension = axis is obtained from the value of the corresponding + entry in `indices` and the index-value for dimension != axis is obtained from the + index of the entry itself. + + `reduction` allows specification of an optional reduction operation, which is applied to all values in `updates` + tensor into `output` at the specified `indices`. + In cases where `reduction` is set to "none", indices should not have duplicate entries: that is, if idx1 != idx2, + then indices[idx1] != indices[idx2]. For instance, in a 2-D tensor case, the update + corresponding to the [i][j] entry is performed as below: + ``` + output[indices[i][j]][j] = updates[i][j] if axis = 0, + output[i][indices[i][j]] = updates[i][j] if axis = 1, + ``` + When `reduction` is set to "add", the update corresponding to the [i][j] entry is performed as below: + ``` + output[indices[i][j]][j] += updates[i][j] if axis = 0, + output[i][indices[i][j]] += updates[i][j] if axis = 1, + ``` + When `reduction` is set to "mul", the update corresponding to the [i][j] entry is performed as below: + ``` + output[indices[i][j]][j] *= updates[i][j] if axis = 0, + output[i][indices[i][j]] *= updates[i][j] if axis = 1, + ``` + + This operator is the inverse of GatherElements. It is similar to Torch's Scatter operation. + + Example 1: + ``` + data = [ + [0.0, 0.0, 0.0], + [0.0, 0.0, 0.0], + [0.0, 0.0, 0.0], + ] + indices = [ + [1, 0, 2], + [0, 2, 1], + ] + updates = [ + [1.0, 1.1, 1.2], + [2.0, 2.1, 2.2], + ] + output = [ + [2.0, 1.1, 0.0] + [1.0, 0.0, 2.2] + [0.0, 2.1, 1.2] + ] + ``` + Example 2: + ``` + data = [[1.0, 2.0, 3.0, 4.0, 5.0]] + indices = [[1, 3]] + updates = [[1.1, 2.1]] + axis = 1 + output = [[1.0, 1.1, 3.0, 2.1, 5.0]] + ``` + +#### Version + +This version of the operator has been available since version 16 of the default ONNX operator set. + +#### Attributes + +
+
axis : int (default is 0)
+
Which axis to scatter on. Negative value means counting dimensions from the back. Accepted range is [-r, r-1] where r = rank(data).
+
reduction : string (default is none)
+
Type of reduction to apply: none (default), add, mul. 'none': no reduction applied. 'add': reduction using the addition operation. 'mul': reduction using the multiplication operation.
+
+ +#### Inputs + +
+
data (differentiable) : T
+
Tensor of rank r >= 1.
+
indices (non-differentiable) : Tind
+
Tensor of int32/int64 indices, of r >= 1 (same rank as input). All index values are expected to be within bounds [-s, s-1] along axis of size s. It is an error if any of the index values are out of bounds.
+
updates (differentiable) : T
+
Tensor of rank r >=1 (same rank and shape as indices)
+
+ +#### Outputs + +
+
output (differentiable) : T
+
Tensor of rank r >= 1 (same rank as input).
+
+ +#### Type Constraints + +
+
T : tensor(uint8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(int8), tensor(int16), tensor(int32), tensor(int64), tensor(bfloat16), tensor(float16), tensor(float), tensor(double), tensor(string), tensor(bool), tensor(complex64), tensor(complex128)
+
Input and output types can be of any tensor type.
+
Tind : tensor(int32), tensor(int64)
+
Constrain indices to integer types
+
+ +### **ScatterND-16** + + ScatterND takes three inputs `data` tensor of rank r >= 1, `indices` tensor of rank q >= 1, + and `updates` tensor of rank q + r - indices.shape[-1] - 1. The output of the operation + is produced by creating a copy of the input `data`, and then updating its value to values + specified by `updates` at specific index positions specified by `indices`. Its output shape + is the same as the shape of `data`. Note that `indices` should not have duplicate entries. + That is, two or more `updates` for the same index-location is not supported. + + `indices` is an integer tensor. Let k denote indices.shape[-1], the last dimension in the shape of `indices`. + `indices` is treated as a (q-1)-dimensional tensor of k-tuples, where each k-tuple is a partial-index into `data`. + Hence, k can be a value at most the rank of `data`. When k equals rank(data), each update entry specifies an + update to a single element of the tensor. When k is less than rank(data) each update entry specifies an + update to a slice of the tensor. + + `updates` is treated as a (q-1)-dimensional tensor of replacement-slice-values. Thus, the + first (q-1) dimensions of updates.shape must match the first (q-1) dimensions of indices.shape. + The remaining dimensions of `updates` correspond to the dimensions of the + replacement-slice-values. Each replacement-slice-value is a (r-k) dimensional tensor, + corresponding to the trailing (r-k) dimensions of `data`. Thus, the shape of `updates` + must equal indices.shape[0:q-1] ++ data.shape[k:r-1], where ++ denotes the concatenation + of shapes. + + The `output` is calculated via the following equation: + + output = np.copy(data) + update_indices = indices.shape[:-1] + for idx in np.ndindex(update_indices): + output[indices[idx]] = updates[idx] + + The order of iteration in the above loop is not specified. + In particular, indices should not have duplicate entries: that is, if idx1 != idx2, then indices[idx1] != indices[idx2]. + This ensures that the output value does not depend on the iteration order. + + `reduction` allows specification of an optional reduction operation, which is applied to all values in `updates` + tensor into `output` at the specified `indices`. + In cases where `reduction` is set to "none", indices should not have duplicate entries: that is, if idx1 != idx2, + then indices[idx1] != indices[idx2]. This ensures that the output value does not depend on the iteration order. + When `reduction` is set to "add", `output` is calculated as follows: + + output = np.copy(data) + update_indices = indices.shape[:-1] + for idx in np.ndindex(update_indices): + output[indices[idx]] += updates[idx] + + When `reduction` is set to "mul", `output` is calculated as follows: + + output = np.copy(data) + update_indices = indices.shape[:-1] + for idx in np.ndindex(update_indices): + output[indices[idx]] *= updates[idx] + + This operator is the inverse of GatherND. + + Example 1: + ``` + data = [1, 2, 3, 4, 5, 6, 7, 8] + indices = [[4], [3], [1], [7]] + updates = [9, 10, 11, 12] + output = [1, 11, 3, 10, 9, 6, 7, 12] + ``` + + Example 2: + ``` + data = [[[1, 2, 3, 4], [5, 6, 7, 8], [8, 7, 6, 5], [4, 3, 2, 1]], + [[1, 2, 3, 4], [5, 6, 7, 8], [8, 7, 6, 5], [4, 3, 2, 1]], + [[8, 7, 6, 5], [4, 3, 2, 1], [1, 2, 3, 4], [5, 6, 7, 8]], + [[8, 7, 6, 5], [4, 3, 2, 1], [1, 2, 3, 4], [5, 6, 7, 8]]] + indices = [[0], [2]] + updates = [[[5, 5, 5, 5], [6, 6, 6, 6], [7, 7, 7, 7], [8, 8, 8, 8]], + [[1, 1, 1, 1], [2, 2, 2, 2], [3, 3, 3, 3], [4, 4, 4, 4]]] + output = [[[5, 5, 5, 5], [6, 6, 6, 6], [7, 7, 7, 7], [8, 8, 8, 8]], + [[1, 2, 3, 4], [5, 6, 7, 8], [8, 7, 6, 5], [4, 3, 2, 1]], + [[1, 1, 1, 1], [2, 2, 2, 2], [3, 3, 3, 3], [4, 4, 4, 4]], + [[8, 7, 6, 5], [4, 3, 2, 1], [1, 2, 3, 4], [5, 6, 7, 8]]] + ``` + +#### Version + +This version of the operator has been available since version 16 of the default ONNX operator set. + +#### Attributes + +
+
reduction : string (default is none)
+
Type of reduction to apply: none (default), add, mul. 'none': no reduction applied. 'add': reduction using the addition operation. 'mul': reduction using the multiplication operation.
+
+ +#### Inputs + +
+
data (differentiable) : T
+
Tensor of rank r >= 1.
+
indices (non-differentiable) : tensor(int64)
+
Tensor of rank q >= 1.
+
updates (differentiable) : T
+
Tensor of rank q + r - indices_shape[-1] - 1.
+
+ +#### Outputs + +
+
output (differentiable) : T
+
Tensor of rank r >= 1.
+
+ +#### Type Constraints + +
+
T : tensor(uint8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(int8), tensor(int16), tensor(int32), tensor(int64), tensor(bfloat16), tensor(float16), tensor(float), tensor(double), tensor(string), tensor(bool), tensor(complex64), tensor(complex128)
+
Constrain input and output types to any tensor type.
+
+ +### **Where-16** + + Return elements, either from X or Y, depending on condition. + Where behaves like + [numpy.where](https://docs.scipy.org/doc/numpy/reference/generated/numpy.where.html) + with three parameters. + + This operator supports **multidirectional (i.e., Numpy-style) broadcasting**; for more details please check [the doc](Broadcasting.md). + + **History** + - Version 16 adds bfloat16 to the types allowed (for the second and third parameter). + +#### Version + +This version of the operator has been available since version 16 of the default ONNX operator set. + +#### Inputs + +
+
condition (non-differentiable) : B
+
When True (nonzero), yield X, otherwise yield Y
+
X (differentiable) : T
+
values selected at indices where condition is True
+
Y (differentiable) : T
+
values selected at indices where condition is False
+
+ +#### Outputs + +
+
output (differentiable) : T
+
Tensor of shape equal to the broadcasted shape of condition, X, and Y.
+
+ +#### Type Constraints + +
+
B : tensor(bool)
+
Constrain to boolean tensors.
+
T : tensor(uint8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(int8), tensor(int16), tensor(int32), tensor(int64), tensor(bfloat16), tensor(float16), tensor(float), tensor(double), tensor(string), tensor(bool), tensor(complex64), tensor(complex128)
+
Constrain input and output types to all tensor types (including bfloat).
+
+ +# ai.onnx.preview.training +## Version 1 of the 'ai.onnx.preview.training' operator set +### **ai.onnx.preview.training.Adagrad-1** + + Compute one iteration of ADAGRAD, a stochastic gradient based optimization + algorithm. This operator can conduct the optimization of multiple tensor variables. + + Let's define the behavior of this operator. As you can imagine, ADAGRAD requires + some parameters: + + - The initial learning-rate "R". + - The update count "T". That is, the number of training iterations conducted. + - A L2-norm regularization coefficient "norm_coefficient". + - A learning-rate decay factor "decay_factor". + - A small constant "epsilon" to avoid dividing-by-zero. + + At each ADAGRAD iteration, the optimized tensors are moved along a direction + computed based on their estimated gradient and accumulated squared gradient. Assume + that only a single tensor "X" is updated by this operator. We need the value of "X", + its gradient "G", and its accumulated squared gradient "H". Therefore, variables in + this operator's input list are sequentially "R", "T", "X", "G", and "H". Other + parameters are given as attributes because they are usually constants. Also, the + corresponding output tensors are the new value of "X" (called "X_new"), and then + the new accumulated squared gradient (called "H_new"). Those outputs are computed + from the given inputs following the pseudo code below. + + Let "+", "-", "*", and "/" are all element-wise arithmetic operations with + numpy-style broadcasting support. The pseudo code to compute those outputs is: + + // Compute a scalar learning-rate factor. At the first update of X, T is generally + // 0 (0-based update index) or 1 (1-based update index). + r = R / (1 + T * decay_factor); + + // Add gradient of 0.5 * norm_coefficient * ||X||_2^2, where ||X||_2 is the 2-norm. + G_regularized = norm_coefficient * X + G; + + // Compute new accumulated squared gradient. + H_new = H + G_regularized * G_regularized; + + // Compute the adaptive part of per-coordinate learning rate. Note that Sqrt(...) + // computes element-wise square-root. + H_adaptive = Sqrt(H_new) + epsilon + + // Compute the new value of "X". + X_new = X - r * G_regularized / H_adaptive; + + If one assign this operators to optimize multiple inputs, for example, "X_1" and "X_2", the same + pseudo code may be extended to handle all tensors jointly. More specifically, we can view "X" as a + concatenation of "X_1" and "X_2" (of course, their gradient and accumulate gradient should + be concatenated too) and then just reuse the entire pseudo code. + + Note that ADAGRAD was first proposed in http://jmlr.org/papers/volume12/duchi11a/duchi11a.pdf. + In that reference paper, this operator is a special case of the Figure 1's composite mirror + descent update. + +#### Version + +This version of the operator has been available since version 1 of the 'ai.onnx.preview.training' operator set. + +#### Attributes + +
+
decay_factor : float (default is 0.0)
+
The decay factor of learning rate after one update.The effective learning rate is computed by r = R / (1 + T * decay_factor). Default to 0 so that increasing update counts doesn't reduce the learning rate.
+
epsilon : float (default is 0.0)
+
Small scalar to avoid dividing by zero.
+
norm_coefficient : float (default is 0.0)
+
Regularization coefficient in 0.5 * norm_coefficient * ||X||_2^2. Default to 0, which means no regularization.
+
+ +#### Inputs (3 - ∞) + +
+
R : T1
+
The initial learning rate.
+
T : T2
+
The update count of "X". It should be a scalar.
+
inputs (variadic, heterogeneous) : T3
+
The current values of optimized tensors, followed by their respective gradients, followed by their respective accumulated squared gradients.For example, if two tensor "X_1" and "X_2" are optimized, The input list would be ["X_1", "X_2", gradient of "X_1", gradient of "X_2", accumulated squared gradient of "X_1", accumulated squared gradient of "X_2"].
+
+ +#### Outputs (1 - ∞) + +
+
outputs (variadic, heterogeneous) : T3
+
Updated values of optimized tensors, followed by their updated values of accumulated squared gradients. For example, if two tensor "X_1" and "X_2" are optimized, the output list would be [new value of "X_1," new value of "X_2" new accumulated squared gradient of "X_1", new accumulated squared gradient of "X_2"].
+
+ +#### Type Constraints + +
+
T1 : tensor(float), tensor(double)
+
Constrain input types to float scalars.
+
T2 : tensor(int64)
+
Constrain input types to 64-bit integer scalars.
+
T3 : tensor(float), tensor(double)
+
Constrain input and output types to float tensors.
+
+ +### **ai.onnx.preview.training.Adam-1** + + Compute one iteration of Adam, a stochastic gradient based optimization + algorithm. This operator can conduct the optimization of multiple tensor variables. + + Let's define the behavior of this operator. First of all, Adam requires + some parameters: + + - The learning-rate "R". + - The update count "T". That is, the number of training iterations conducted. + - A L2-norm regularization coefficient "norm_coefficient". + - A small constant "epsilon" to avoid dividing-by-zero. + - Two coefficients, "alpha" and "beta". + + At each Adam iteration, the optimized tensors are moved along a direction + computed based on their exponentially-averaged historical gradient and + exponentially-averaged historical squared gradient. Assume that only a tensor + "X" is being optimized. The rest of required information is + + - the value of "X", + - "X"'s gradient (denoted by "G"), + - "X"'s exponentially-averaged historical gradient (denoted by "V"), and + - "X"'s exponentially-averaged historical squared gradient (denoted by "H"). + + Some of those parameters are passed into this operator as input tensors and others + are stored as this operator's attributes. Specifically, this operator's input tensor + list is ["R", "T", "X", "G", "V", "H"]. That is, "R" is the first input, "T" is + the second input, and so on. Other parameters are given as attributes because they + are constants. Moreover, the corresponding output tensors are + + - the new value of "X" (called "X_new"), + - the new exponentially-averaged historical gradient (denoted by "V_new"), and + - the new exponentially-averaged historical squared gradient (denoted by "H_new"). + + Those outputs are computed following the pseudo code below. + + Let "+", "-", "*", and "/" are all element-wise arithmetic operations with + numpy-style broadcasting support. The pseudo code to compute those outputs is: + + // Add gradient of 0.5 * norm_coefficient * ||X||_2^2, where ||X||_2 is the 2-norm. + G_regularized = norm_coefficient * X + G + + // Update exponentially-averaged historical gradient. + V_new = alpha * V + (1 - alpha) * G_regularized + + // Update exponentially-averaged historical squared gradient. + H_new = beta * H + (1 - beta) * G_regularized * G_regularized + + // Compute the element-wise square-root of H_new. V_new will be element-wisely + // divided by H_sqrt for a better update direction. + H_sqrt = Sqrt(H_new) + epsilon + + // Compute learning-rate. Note that "alpha**T"/"beta**T" is alpha's/beta's T-th power. + R_adjusted = T > 0 ? R * Sqrt(1 - beta**T) / (1 - alpha**T) : R + + // Compute new value of "X". + X_new = X - R_adjusted * V_new / H_sqrt + + // Post-update regularization. + X_final = (1 - norm_coefficient_post) * X_new + + If there are multiple inputs to be optimized, the pseudo code will be applied + independently to each of them. + +#### Version + +This version of the operator has been available since version 1 of the 'ai.onnx.preview.training' operator set. + +#### Attributes + +
+
alpha : float (default is 0.9)
+
Coefficient of previously accumulated gradient in running average. Default to 0.9.
+
beta : float (default is 0.999)
+
Coefficient of previously accumulated squared-gradient in running average. Default to 0.999.
+
epsilon : float (default is 0.0)
+
Small scalar to avoid dividing by zero.
+
norm_coefficient : float (default is 0.0)
+
Regularization coefficient of 0.5 * norm_coefficient * ||X||_2^2. Default to 0, which means no regularization.
+
norm_coefficient_post : float (default is 0.0)
+
Regularization coefficient of 0.5 * norm_coefficient * ||X||_2^2. Default to 0, which means no regularization.
+
+ +#### Inputs (3 - ∞) + +
+
R : T1
+
The initial learning rate.
+
T : T2
+
The update count of "X". It should be a scalar.
+
inputs (variadic, heterogeneous) : T3
+
The tensors to be optimized, followed by their respective gradients, followed by their respective accumulated gradients (aka momentum), followed by their respective accumulated squared gradients. For example, to optimize tensors "X_1" and "X_2,", the input list would be ["X_1", "X_2", gradient of "X_1", gradient of "X_2", accumulated gradient of "X_1", accumulated gradient of "X_2", accumulated squared gradient of "X_1", accumulated squared gradient of "X_2"].
+
+ +#### Outputs (1 - ∞) + +
+
outputs (variadic, heterogeneous) : T3
+
New values of optimized tensors, followed by their respective new accumulated gradients, followed by their respective new accumulated squared gradients. For example, if two tensors "X_1" and "X_2" are optimized, the outputs list would be [new value of "X_1", new value of "X_2", new accumulated gradient of "X_1", new accumulated gradient of "X_2", new accumulated squared gradient of "X_1", new accumulated squared gradient of "X_2"].
+
+ +#### Type Constraints + +
+
T1 : tensor(float), tensor(double)
+
Constrain input types to float scalars.
+
T2 : tensor(int64)
+
Constrain input types to 64-bit integer scalars.
+
T3 : tensor(float), tensor(double)
+
Constrain input and output types to float tensors.
+
+ +### **ai.onnx.preview.training.Gradient-1** + + Gradient operator computes the partial derivatives of a specific tensor w.r.t. + some other tensors. This operator is widely used in gradient-based training + algorithms. To illustrate its use, let's consider a computation graph, + + ``` + X -----. + | + v + W --> Conv --> H --> Gemm --> Y + ^ + | + Z + ``` + + , where W and Z are trainable tensors. Note that operators' attributes are + omitted for the sake of simplicity. Let dY/dW (dY/dZ) be the gradient of + Y with respect to W (Z). The user can compute gradient by inserting Gradient + operator to form another graph shown below. + + ``` + W --> Conv --> H --> Gemm --> Y + | ^ ^ + | | | + | X Z + | | | + | | .----------' + | | | (W/Z/X is the 1st/2nd/3rd input of Gradient as shown in + | | | "xs" followed by "zs") + | v v + '---> Gradient(xs=["W", "Z"], zs=["X"], y="Y") + | | + | '-----------------------------------> dY/dW (1st output of Gradient) + | + '---------------------------------------> dY/dZ (2nd output of Gradient) + ``` + + By definition, the tensor "y" is a function of independent variables in "xs" + and "zs". Since we only compute the gradient of "y" w.r.t. the differentiable + variables in "xs", this Gradient only outputs dY/dW and dY/dZ. Note that "H" + cannot appear in "xs" and "zs". The reason is that "H" can be determined by + tensors "W" and "X" and therefore "H" is not an independent variable. + + All outputs are optional. If needed, for example, user can assign an empty + string to the 1st output name of that Gradient to skip the generation of dY/dW. + Note that the concept of optional outputs can also be found in ONNX's RNN, GRU, + and LSTM. + + Gradient operator can compute derivative against intermediate tensors. For + example, the gradient of Y with respect to H can be done via + + ``` + W --> Conv --> H --> Gemm --> Y + ^ | ^ + | | | + X | Z + .-------' | + | .----------' + | | (H/Z is the 1st/2nd input of Gradient as shown in "xs") + v v + Gradient(xs=["H", "Z"], y="Y") + | | + | '-----------------------------------> dY/dH (1st output of Gradient) + | + '---------------------------------------> dY/dZ (2nd output of Gradient) + ``` + + It is possible to represent high-order differentiation using Gradient operators. + For example, given the following linear model: + + ``` + W --> Gemm --> Y --> Loss --> O + ^ ^ + | | + X L + ``` + + To compute the 2nd order derivative of O with respect to W (denoted by + d^2O/dW^2), one can do + + ``` + W --> Gemm --> Y --> Loss --> O + | ^ ^ + | | | + | X .------------L + | | | | + | | | v + +------+-+> Gradient(xs=["X", "W"], zs=["L"], y="O") ---> dO/dX (1st output of Gradient) + | | | | + | | | '---> dO/dW (2nd output of Gradient) + | v v + '---> Gradient(xs=["X", "W"], zs=["L"], y="dO/dW") ---> d(dO/dW)dX (1st output of + | Gradient) + | + | + '---> d^2O/dW^2 (2nd output of Gradient) + ``` + + The tensors named in attributes "xs", "zs", and "y" define the differentiated + computation graph, and the inputs to Gradient node define the values at + which the gradient is computed. We can feed different tensors to the identified + graph. For example, one can compute the gradient of Y with respect to H at + a specific value of H, H_1, by providing that value as an input to the Gradient + node. + + ``` + W --> Conv --> H --> Gemm --> Y + ^ ^ + | | + X Z + + Z_1 (2nd input of Gradient) + | + v + H_1 --> Gradient(xs=["H", "Z"], y="Y") ---> dY/dH when H = H_1 and Y = Y_1. + | + '------------------------------> dY/dZ (2nd output of Gradient) + ``` + + When the inputs of Gradient are the tensors named in "xs" and "zs", the + computation can be optimized. More specifically, intermediate variables in + forward pass can be reused if the gradient is computed via reverse-mode + auto-differentiation. + + +#### Version + +This version of the operator has been available since version 1 of the 'ai.onnx.preview.training' operator set. + +#### Attributes + +
+
xs : list of strings (required)
+
Input tensor names of the differentiated sub-graph. It contains only the necessary differentiated inputs of a (sub-)graph. Variables (usually called intermediate variables) that can be generated from inputs cannot be included in this attribute.
+
y : string (required)
+
The targeted tensor. It can be viewed as the output of the differentiated function. The attribute "xs" and attribute "zs" are the minimal independent variable set that determines the value of "y".
+
zs : list of strings
+
Input tensor names of the differentiated sub-graph. It contains only the necessary non-differentiated inputs of a (sub-)graph. Variables (usually called intermediate variables) that can be generated from inputs cannot be included in this attribute.
+
+ +#### Inputs (1 - ∞) + +
+
Inputs (variadic, heterogeneous) : T1
+
The values fed into graph identified by the attributes. The i-th input is the value of the i-th tensor specified in the concatenated list of the attribute "xs" and the attribute "zs". For example, if xs=["A", "B"] and zs=["C"], the first input is used as the value of symbol "A" and the 3rd input is substituted for all the occurrences of "C".
+
+ +#### Outputs (1 - ∞) + +
+
Outputs (variadic, heterogeneous) : T2
+
The gradient of the tensor specified by the attribute "y" with respect to each of tensors specified in the attribute "xs". The i-th output is the gradient of "y" with respect to the i-th tensor specified in the attribute "xs".
+
+ +#### Type Constraints + +
+
T1 : tensor(uint8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(int8), tensor(int16), tensor(int32), tensor(int64), tensor(float16), tensor(float), tensor(double), tensor(string), tensor(bool), tensor(complex64), tensor(complex128)
+
Allow outputs to be any kind of tensor.
+
T2 : tensor(float16), tensor(float), tensor(double)
+
Allow inputs to be any kind of floating-point tensor.
+
+ +### **ai.onnx.preview.training.Momentum-1** + + Compute one iteration of stochastic gradient update with momentum. + This operator can conduct the optimization of multiple tensor variables. + + Let's define the behavior of this operator. As you can imagine, SG with momentum requires + several parameters: + + - The learning-rate "R". + - The update count "T". That is, the number of conducted training iterations. It should + be zero in the first training iteration. + - A L2-norm regularization coefficient "norm_coefficient". + - A decay coefficient of previous accumulated gradient (i.e., momentum) "alpha". + - The scaling coefficient of current gradient "beta". + - An attribute to choose either standard momentum or Nesterov's momentum "mode" should + be used. + + For the sake of simplicity, assume that there is only one tensor (called "X") to be optimized. + Other necessary inputs are "X"'s gradient (called "G") and "X"'s momentum (called "V"). This + Momentum operator maps all these inputs to the new value of "X" (called "X_new") and its new + momentum (called "V_new"). + + This operator supports two different momentum algorithms. Set the attribute "mode" to + "nesterov" if Nesterov's momentum is desired. Otherwise, set the attribute "model" to + "standard" to use standard momentum. Computation details are described subsequently. + + Let "+", "-", "*", and "/" are all element-wise operations with numpy-style broadcasting. + + Pseudo code for SG with standard momentum: + + // Add gradient of 0.5 * norm_coefficient * ||X||^2, where ||X|| is the sum of squared + // values of all elements in X. + G_regularized = norm_coefficient * X + G + + // In the first training iteration, beta should always be 1. + beta_adjusted = T > 0 ? beta : 1 + + // Compute the current momentum based on previous momentum and the current gradient. + V_new = alpha * V + beta_adjusted * G_regularized + + // Update X. + X_new = X - R * V_new + + Pseudo code for SG with Nesterov's momentum: + + // Add gradient of 0.5 * norm_coefficient * ||X||^2, where ||X|| is the sum of squared + // values of all elements in X. + G_regularized = norm_coefficient * X + G; + + // In the first training iteration, beta should always be 1. + beta_adjusted = T > 0 ? beta : 1 + + // Compute the current momentum based on previous momentum and the current gradient. + V_new = alpha * V + beta_adjusted * G_regularized; + + // Compute final update direction and then update X. + X_new = X - R * (G_regularized + alpha * V_new) + + If one assign this operators to optimize multiple inputs, for example, "X_1" and "X_2". The same + pseudo code would be extended to handle all tensors jointly. More specifically, we can view "X" as a + concatenation of "X_1" and "X_2" (of course, their gradient and accumulate gradient should + be concatenated too) and then our pseudo code becomes applicable. + +#### Version + +This version of the operator has been available since version 1 of the 'ai.onnx.preview.training' operator set. + +#### Attributes + +
+
alpha : float (required)
+
The decay factor of momentum. It should be a scalar.
+
beta : float (required)
+
The coefficient of gradient in computing new momentum. It should be a scalar.
+
mode : string (required)
+
Its value should be either "nesterov" or "standard". The value "nesterov" leads to the use of Nesterov's momentum while "standard" invokes stochastic gradient method using standard momentum
+
norm_coefficient : float (required)
+
Coefficient of 0.5 * norm_coefficient * ||X||^2.
+
+ +#### Inputs (3 - ∞) + +
+
R : T1
+
The learning rate.
+
T : T2
+
Update count of "X". It should be a scalar.
+
inputs (variadic, heterogeneous) : T3
+
It sequentially contains the current values of optimized tensors, then their gradient tensors, and finally their momentum tensors. For example, if two tensors "X_1" and "X_2" are optimized, The expected input list would be ["X_1", "X_2", gradient of "X_1", gradient of "X_2", momentum of "X_1", momentum of "X_2"].
+
+ +#### Outputs (1 - ∞) + +
+
outputs (variadic, heterogeneous) : T3
+
It sequentially contains the new values of optimized tensors and then the new values of their momentum tensors. For example, if two tensors "X_1" and "X_2" are optimized, the output list would be [new value of "X_1," new value of "X_2" new momentum of "X_1", new momentum of "X_2"].
+
+ +#### Type Constraints + +
+
T1 : tensor(float), tensor(double)
+
Constrain input types to float scalars.
+
T2 : tensor(int64)
+
Constrain input types to 64-bit integer scalars.
+
T3 : tensor(float), tensor(double)
+
Constrain input types to float tensors.
+
+ diff --git a/_doc/sphinxdoc/source/onnxmd/onnx_docs/DefineDifferentiability.md b/_doc/sphinxdoc/source/onnxmd/onnx_docs/DefineDifferentiability.md new file mode 100644 index 00000000..783ebd3b --- /dev/null +++ b/_doc/sphinxdoc/source/onnxmd/onnx_docs/DefineDifferentiability.md @@ -0,0 +1,108 @@ + + +# A Short Guide on the Differentiability Tag for ONNX Operators + +## Differentiability Tag +The ONNX operator schema for each operator includes a differentiability tag for each input and output. +In this document, we explain the meaning of this tag and how to ensure the correctness of the tags. +Briefly, the tag identifies the set of differentiable inputs and differentiable outputs of an operator. +The meaning of the tag is that the partial derivative of each differentiable output is defined with respect to each differentiable output. + +## Ways to Define Differentiability Tag +The differentiability definition of an operator consists of several aspects. + +- Differentiable inputs, which can be referenced in Gradient's `xs` attribute. +- Differentiable outputs, which can be referenced in Gradient's `y` attribute. +- The math equation to compute the Jacobian matrix (or tensor). If a variable (input or output) is differentiable or not is judged by math. If the Jacobian matrix (or tensor) exists, then the considered operator has some differentiable inputs and outputs. + +There are several strategies to implement auto-differentiation such as forward accumulation, backward accumulation, and dual variable. +Because most deep learning frameworks are backward-based, the reviewers should ensure the PR authors of tags provide enough details on that. +We present a couple of methods below to verify the differentiability for ONNX operator. + +### Method 1: Reuse Existing Deep Learning Frameworks +The first way is to show that the considered operator's backward operation exists in an existing framework such as Pytorch or Tensorflow. In this case, the author should provide a runnable python script which computes the backward pass of the considered operator. The author should also point out how to map the Pytorch or Tensor code to ONNX format (for example, the author can call `torch.onnx.export` to save an ONNX model). The following script shows the differentiability of ONNX Reshape using Pytorch. + +```python +import torch +import torch.nn as nn + +# A single-operator model. It's literally a Pytorch Reshape. +# Note that Pytorch Reshape can be directly mapped to ONNX Reshape. +class MyModel(nn.Module): + def __init__(self): + super(MyModel, self).__init__() + + def forward(self, x): + y = torch.reshape(x, (x.numel(),)) + y.retain_grad() + return y + +model = MyModel() + +x = torch.tensor([[1., -1.], [1., 1.]], requires_grad=True) +y = model(x) +dy = torch.tensor([1., 2., 3., 4.]) + +torch.autograd.backward([y], + grad_tensors=[dy], + retain_graph=True, + create_graph=True, + grad_variables=None) + +# This example shows the input and the output in Pytorch are differentiable. +# From the exported ONNX model below, we also see that "x" is the first input +# of ONNX Reshape and "y" the output of ONNX Reshape. Therefore, we can say +# the first input and the output of ONNX Reshape are differentiable. +print(x.grad) +print(y.grad) + +with open('model.onnx', 'wb') as f: + torch.onnx.export(model, x, f) +``` + +### Method 2: Manually Do the Math +The second way is formally proving the existence of the Jacobian matrix (or tensor) from outputs to inputs with at least two numerical examples. In this case, the reviewer should go through the math and confirm if the numerical result is correct. The author should add enough details so that any STEM graduated student can easily review it. + +For example, to show the differentiability of Add, the author may first write down its equation: +``` +C = A + B +``` +For the sake of simplicity, assume `A` and `B` are same-shape vector. +``` +A = [a1, a2]^T +B = [b1, b2]^T +C = [c1, c2]^T +``` +Here we use the symbol `^T` to denote transpose of the attached matrix or vector. +Let `X = [a1, a2, b1, b2]^T` and `Y = [c1, c2]^T` and consider Add as a function which maps `X` to `Y`. +Then, this function's Jacobian matrix is a 4-by-2 matrix, +``` +J = [[dc1/da1, dc2/da1], + [dc1/da2, dc2/da2], + [dc1/db1, dc2/db1], + [dc1/db2, dc2/db2]] + = [[1, 0], + [0, 1], + [1, 0], + [0, 1]] +``` +If +``` +dL/dC = [dL/dc1, dL/dc2]^T, +``` +then `dL/dA = [dL/da1, dL/da2]^T` and `dL/dB = [dL/db1, dL/db2]^T` can be computed from elements in +``` + [[dL/da1], [dL/da2], [dL/db1], [dL/db2]] += J * dL/dC += [[dL/dc1], [dL/dc2], [dL/dc1], [dL/dc2]] +``` +where `*` is standard matrix multiplication. +If `dL/dC = [0.2, 0.8]^T`, then `dL/dA = [0.2, 0.8]^T` and `dL/dB = [0.2, 0.8]^T`. +Notice that the procedure to compute `dL/dA` and `dL/dB` from `dL/dC` is usually called backward of an operator. +We can see backward operator of Add takes `dL/dC` as an input and produces two outputs `dL/dA` and `dL/dB`. +Consequently, all of `A`, `B`, and `C` are differentiable. +By flattening tensor into 1-D vector, this example can be extended to cover all tensors when shape broadcasting is not needed. +If broadcasting happens, the broadcasted element's gradient is the sum of all associated elements' gradient in its **non-broadcasting** case. +Let's consider the above example again. +If `B = [b]^T` becomes an 1-element vector, `B` may be broadcasted to `[b1, b2]^T` and `dL/dB = [dL/ db]^T = [dL/db1 + dL/db2]^T`. +For high-dimensional tensors, this is in fact a ReduceSum operation along all expanded axes. diff --git a/_doc/sphinxdoc/source/onnxmd/onnx_docs/DimensionDenotation.md b/_doc/sphinxdoc/source/onnxmd/onnx_docs/DimensionDenotation.md new file mode 100644 index 00000000..2c59b653 --- /dev/null +++ b/_doc/sphinxdoc/source/onnxmd/onnx_docs/DimensionDenotation.md @@ -0,0 +1,51 @@ + + +# Dimension Denotation + +Dimension Denotation is an experimental attempt to give tensor axis semantic descriptions and thus types and perform verification steps based on them subsequently. + +## Motivation + +The motivation of such a mechanism can be illustrated via a simple example. In the linear neural network specification below, we assume a NCHW model input: + +``` +input_in_NCHW -> Transpose(input, perm=[0, 2, 1, 3]) -> AveragePool(input, ...) +``` + +In this neural network, a user mistakenly constructed a neural network that transposes an NCHW input to a weird NHCW format and pass through spatial pooling that assumes a NCHW input format. As clearly a mistake as it is, no existing infrastructure will report an error to the user. This is should be deeply unnerving to programmers who rely heavily on type checking as an integral part of program correctness guarantee. This proposal seeks to resolve this vacuum of proper type-checking inherent in the current paradigm of neural network specification. + +This proposal consists of three key components: Denotation Definition, Denotation Propagation and Denotation Verification, each of which will be discussed in detail. + +## Denotation Definition + +To begin with, we define a set of types for tensor types. Such types are defined based on the following principles: +1. Be fine grain enough to eliminate potential pitfalls. For instance, the above example illustrated in the motivation section mandates that we distinguish between a channel dimension and a spatial feature dimension to ensure the correctness of execution of the AveragePool op. +2. Be coarse grain enough to alleviate the mental burden of users. For instance, in the above example, there is significantly less need to distinguish between a width dimension and a height dimension because operations like pooling and convolution often do not draw a distinction between various spatial dimensions. Thus, we summarize all the spatial dimensions as feature dimensions. +3. As an important corollary of 2, be model agnostic. For instance, the semantics of feature dimensions in recurrent neural networks (RNN) and the semantics of spatial dimensions in convolutional neural network (CNN) are almost indistinguishable and therefore we permit users and developers to describe either as a feature dimension. + +Specifically, in our first proposal, we define the following set of standard denotations: + +1. `DATA_BATCH` describes a batch dimension of the training data. This corresponds to the `N` dimension in the more commonly used tensor format notation `NCHW`. +2. `DATA_CHANNEL` describes a channel dimension of the training data. This corresponds to the `C` dimension. +3. `DATA_TIME` describes a time dimension. +4. `DATA_FEATURE` describes a feature dimension. This corresponds to the `H`, `W` dimension or the feature dimension in RNN. +5. `FILTER_IN_CHANNEL` describes a filter in-channel dimension. This is the dimension that is identical (in size) to the channel dimension of the input image feature maps. +6. `FILTER_OUT_CHANNEL` describes a filter out-channel dimension. This is the dimension that is identical (in size) to the channel dimension of the output image feature maps. +7. `FILTER_SPATIAL` describes a filter spatial dimension. + +## Denotation Propagation + +Denotation Propagation happens when an operation permutes, destroys or creates dimensions with respect to its input tensor. In such scenarios, we will implement customized, operation-specific functions to infer the output tensor dimension denotation based on the input tensor dimension denotation. An example operation where denotation propagation happens is Transpose operation where the pseudocode for output dimension denotation inference can be formulated as a function of the input dimension denotation: + +``` +for i, j in enumerate(perm): + out_dim_denotaion[i] = in_dim_denotation[j] +``` + +## Denotation Verification + +Denotation Verification happens when an operation expects its input to arrive in a particular format. An example operation where denotation verification happens is AveragePool operation where the input, if annotated with dimension denotation, in the 2D case should have the denotation [`DATA_BATCH`, `DATA_CHANNEL`, `DATA_FEATURE`, `DATA_FEATURE`]. If there is a mismatch between the expected dimension denotation and the actual dimension denotation, an error should be reported. + +## Type Denotation + +See the [type denotation documentation](TypeDenotation.md) for more details on how to describe images and other types. diff --git a/_doc/sphinxdoc/source/onnxmd/onnx_docs/ExternalData.md b/_doc/sphinxdoc/source/onnxmd/onnx_docs/ExternalData.md new file mode 100644 index 00000000..c1e53d7b --- /dev/null +++ b/_doc/sphinxdoc/source/onnxmd/onnx_docs/ExternalData.md @@ -0,0 +1,89 @@ + + +# External Data + +## Loading an ONNX Model with External Data + +* [Default] If the external data is under the same directory of the model, simply use `onnx.load()` +```python +import onnx + +onnx_model = onnx.load('path/to/the/model.onnx') +``` + +* If the external data is under another directory, use `load_external_data_for_model()` to specify the directory path and load after using `onnx.load()` + +```python +import onnx +from onnx.external_data_helper import load_external_data_for_model + +onnx_model = onnx.load('path/to/the/model.onnx', load_external_data=False) +load_external_data_for_model(onnx_model, 'data/directory/path/') +# Then the onnx_model has loaded the external data from the specific directory +``` + +## Converting an ONNX Model to External Data +```python +import onnx +from onnx.external_data_helper import convert_model_to_external_data + +onnx_model = ... # Your model in memory as ModelProto +convert_model_to_external_data(onnx_model, all_tensors_to_one_file=True, location='filename', size_threshold=1024, convert_attribute=False) +# Must be followed by save_model to save the converted model to a specific path +onnx.save_model(onnx_model, 'path/to/save/the/model.onnx') +# Then the onnx_model has converted raw data as external data and saved to specific directory +``` + +## Converting and Saving an ONNX Model to External Data +```python +import onnx + +onnx_model = ... # Your model in memory as ModelProto +onnx.save_model(onnx_model, 'path/to/save/the/model.onnx', save_as_external_data=True, all_tensors_to_one_file=True, location='filename', size_threshold=1024, convert_attribute=False) +# Then the onnx_model has converted raw data as external data and saved to specific directory +``` + +## onnx.checker for Models with External Data + +### Models with External Data (<2GB) + +Current checker supports checking models with external data. Specify either loaded onnx model or model path to the checker. + +### Large models >2GB +However, for those models larger than 2GB, please use the model path for onnx.checker and the external data needs to be under the same directory. + +```python +import onnx + +onnx.checker.check_model('path/to/the/model.onnx') +# onnx.checker.check_model(loaded_onnx_model) will fail if given >2GB model +``` + +## TensorProto: data_location and external_data fields + +There are two fields related to the external data in TensorProto message type. + +### data_location field +`data_location` field stores the location of data for this tensor. Value MUST be one of: +* `MESSAGE` - data stored in type-specific fields inside the protobuf message. +* `RAW` - data stored in raw_data field. +* `EXTERNAL` - data stored in an external location as described by external_data field. +* `value` not set - legacy value. Assume data is stored in raw_data (if set) otherwise in message. + +### external_data field +`external_data` field stores key-value pairs of strings describing data location + +Recognized keys are: + +* `"location"` (required) - file path relative to the filesystem directory where the ONNX protobuf model was stored. Up-directory path components such as .. are disallowed and should be stripped when parsing. +* `"offset"` (optional) - position of byte at which stored data begins. Integer stored as string. Offset values SHOULD be multiples 4096 (page size) to enable mmap support. +* `"length"` (optional) - number of bytes containing data. Integer stored as string. +* `"checksum"` (optional) - SHA1 digest of file specified in under 'location' key. + +After an ONNX file is loaded, all `external_data` fields may be updated with an additional key `("basepath")`, which stores the path to the directory from which he ONNX model file was loaded. + +### External data files +Data stored in external data files will be in the same binary bytes string format as is used by the `raw_data` field in current ONNX implementations. + +Reference +https://github.com/onnx/onnx/pull/678 diff --git a/_doc/sphinxdoc/source/onnxmd/onnx_docs/Hub.md b/_doc/sphinxdoc/source/onnxmd/onnx_docs/Hub.md new file mode 100644 index 00000000..9bd9c40e --- /dev/null +++ b/_doc/sphinxdoc/source/onnxmd/onnx_docs/Hub.md @@ -0,0 +1,235 @@ + + +# ONNX Model Hub + +The ONNX Model Hub is a simple and fast way to get started with state of the art pre-trained +ONNX models from the [ONNX Model Zoo](https://github.com/onnx/models). Furthermore, this allows researchers and model +developers the opportunity to share their pre-trained models with the broader community. + +## Install + The ONNX Model hub will be included in the `onnx` package from version 1.11 onwards. + To use the hub before the 1.11 release please install from the weekly build: + +```shell script +pip install -i https://test.pypi.org/simple/ onnx-weekly +``` + +## Basic usage +The ONNX Model Hub is capable of downloading, listing, and querying trained models from any git repository, + and defaults to the official [ONNX Model Zoo](https://github.com/onnx/models). In this section we demonstrate some of the basic functionality. + +First please import the hub using: +```python +from onnx import hub +``` + +#### Downloading a model by name: + +The `load` function will default to searching the model zoo for the latest model with a matching name, + download this model to a local cache, and load the model into a `ModelProto` + object for use with the ONNX runtime. + +```python +model = hub.load("resnet50") +``` + + +#### Downloading from custom repositories: + +Any repository with the proper structure can be a ONNX model hub. To download from other hubs, + or to specify a particular branch or commit on the main model hub one can provide the `repo` parameter: + +```python +model = hub.load("resnet50", repo='onnx/models:771185265efbdc049fb223bd68ab1aeb1aecde76') +``` + +#### Listing and inspecting Models: + +The model hub provides APIs for querying the model zoo to learn more about available models. + This does not download the models, but rather just returns information about models matching the given arguments + + ```python +# List all models in the onnx/models:master repo +all_models = hub.list_models() + +# List all versions/opsets of a specific model +mnist_models = hub.list_models(model="mnist") + +# List all models matching a given "tag" +vision_models = hub.list_models(tags=["vision"]) +``` + +One can also inspect the metadata of a model prior to download with the `get_model_info` function: + +```python +print(hub.get_model_info(model="mnist", opset=8)) +``` +This will print something like: +``` +ModelInfo( + model=MNIST, + opset=8, + path=vision/classification/mnist/model/mnist-8.onnx, + metadata={ + 'model_sha': '2f06e72de813a8635c9bc0397ac447a601bdbfa7df4bebc278723b958831c9bf', + 'model_bytes': 26454, + 'tags': ['vision', 'classification', 'mnist'], + 'io_ports': { + 'inputs': [{'name': 'Input3', 'shape': [1, 1, 28, 28], 'type': 'tensor(float)'}], + 'outputs': [{'name': 'Plus214_Output_0', 'shape': [1, 10], 'type': 'tensor(float)'}]}, + 'model_with_data_path': 'vision/classification/mnist/model/mnist-8.tar.gz', + 'model_with_data_sha': '1dd098b0fe8bc750585eefc02013c37be1a1cae2bdba0191ccdb8e8518b3a882', + 'model_with_data_bytes': 25962} +) +``` + + +## Local Caching + +The ONNX Model hub locally caches downloaded models in a configurable location +so that subsequent calls to `hub.load` do not require network connection. + +#### Default cache location +The hub client looks for the following default cache locations in this order: + +1) `$ONNX_HOME/hub` if the `ONNX_HOME` environment variable is defined +2) `$XDG_CACHE_HOME/hub` if the `XDG_CACHE_HOME` environment variable is defined +3) `~/.cache/onnx/hub` where `~` is the user home directory + +#### Setting the cache location +To manually set the cache location use: + +```python +hub.set_dir("my/cache/directory") +``` + +Additionally one can inspect the cache location with: + +```python +print(hub.get_dir()) +``` + +#### Additional cache details + +To clear the model cache one can simply delete the cache directory using a python utility like `shutil` or `os`. +Furthermore one can choose to override the cached model using the `force_reload` option: + +```python +model = hub.load("resnet50", force_reload=True) +``` + +We include this flag for completeness but note that models in the cache are disambiguated with sha256 hashes so + the force_reload flag is not necessary for normal use. +Finally we note that the model cache directory structure will mirror the directory structure +specified by the `model_path` field of the manifest, but with file names disambiguated with model SHA256 Hashes. + +This way, the model cache is human readable, can disambiguate between multiple versions of models, + and can re-use cached models across different hubs if they have the same name and hash. + +## Architecture + +![ONNX Hub Architecture](images/onnx_hub_arch.svg) + +The ONNX Hub consists of two main components, the client and the server. + The client code currently is included in the `onnx` package and can be pointed at a + server in the form of a hosted `ONNX_HUB_MANIFEST.json` within a github repository + such as [the one in the ONNX Model Zoo](https://github.com/onnx/models/blob/master/ONNX_HUB_MANIFEST.json). + This manifest file is a JSON document which lists all models and their metadata + and is designed to be programming language agnostic. An example of a well formed model manifest entry is as follows: + + ```json +{ + "model": "BERT-Squad", + "model_path": "text/machine_comprehension/bert-squad/model/bertsquad-8.onnx", + "onnx_version": "1.3", + "opset_version": 8, + "metadata": { + "model_sha": "cad65b9807a5e0393e4f84331f9a0c5c844d9cc736e39781a80f9c48ca39447c", + "model_bytes": 435882893, + "tags": ["text", "machine comprehension", "bert-squad"], + "io_ports": { + "inputs": [ + { + "name": "unique_ids_raw_output___9:0", + "shape": ["unk__475"], + "type": "tensor(int64)" + }, + { + "name": "segment_ids:0", + "shape": ["unk__476", 256], + "type": "tensor(int64)" + }, + { + "name": "input_mask:0", + "shape": ["unk__477", 256], + "type": "tensor(int64)" + }, + { + "name": "input_ids:0", + "shape": ["unk__478", 256], + "type": "tensor(int64)" + } + ], + "outputs": [ + { + "name": "unstack:1", + "shape": ["unk__479", 256], + "type": "tensor(float)" + }, + { + "name": "unstack:0", + "shape": ["unk__480", 256], + "type": "tensor(float)" + }, + { + "name": "unique_ids:0", + "shape": ["unk__481"], + "type": "tensor(int64)" + } + ] + }, + "model_with_data_path": "text/machine_comprehension/bert-squad/model/bertsquad-8.tar.gz", + "model_with_data_sha": "c8c6c7e0ab9e1333b86e8415a9d990b2570f9374f80be1c1cb72f182d266f666", + "model_with_data_bytes": 403400046 + } +} +``` +These important fields are: + +- `model`: The name of the model used for querying +- `model_path`: The relative path of the model stored in Git LFS. +- `onnx_version`: The ONNX version of the model +- `opset_version`: The version of the opset. The client downloads the latest opset if left unspecified. +- `metadata/model_sha`: Optional model sha specification for increased download security +- `metadata/tags`: Optional high level tags to help users find models by a given type + +All other fields in the `metadata` field are optional for the client but provide important details for users. + +## Adding to the ONNX Model Hub + + +#### Contributing an official model + +The simplest way to add a model to the official `onnx/models` version model hub is to follow +[these guidelines](https://github.com/onnx/models/blob/master/contribute.md) to contribute your model. Once contributed, +ensure that your model has a markdown table in its `README.md` +([Example](https://github.com/onnx/models/tree/master/vision/classification/mobilenet)). The model hub + manifest generator will pull information from these markdown tables. To run the generator: + + ```shell script +git clone https://github.com/onnx/models.git +git lfs pull --include="*" --exclude="" +cd models/workflow_scripts +python generate_onnx_hub_manifest.py +``` + +Once a new manifest is generated add, submit it in a pull request to ``onnx/models`` + +#### Hosting your own ONNX Model Hub + +To host your own model hub, add an `ONNX_HUB_MANIFEST.json` to the top level of your github repository + ([Example](https://github.com/onnx/models/blob/master/ONNX_HUB_MANIFEST.json)). At a minimum your + manifest entries should include the fields mentioned in + the [Architecture Section](Hub.md#Architecture) of this document. + Once committed, check that you can download models + using the "Downloading from custom repositories" section of this doc. \ No newline at end of file diff --git a/_doc/sphinxdoc/source/onnxmd/onnx_docs/IR.md b/_doc/sphinxdoc/source/onnxmd/onnx_docs/IR.md new file mode 100644 index 00000000..67234558 --- /dev/null +++ b/_doc/sphinxdoc/source/onnxmd/onnx_docs/IR.md @@ -0,0 +1,462 @@ + + +Open Neural Network Exchange Intermediate Representation (ONNX IR) Specification +========= + +__Purpose__ + +This document contains the normative specification of the semantics of ONNX. + +The `.proto` and `.proto3` files found under the [onnx folder](/onnx/) form the normative specification of its syntax authored in the [Protocol Buffers](https://developers.google.com/protocol-buffers) definition language. Commentary found in the `.proto` and `.proto3` files are intended to improve readability of those files, but are not normative if they conflict with this document. Such conflicts should be reported as documentation bugs. + +__Notes on model validation__ + +A [tool](../onnx/checker.py) is available to perform general validation of models against this specification. It is implemented in C++ with Python command-line wrapper. + +__Notes on language in this and all related documents__: + +1. The use of SHOULD, MUST, MAY and so on in this document is consistent with [RFC 2119](https://www.ietf.org/rfc/rfc2119.txt). + +2. The use of 'list' shall denote an ordered collection of items, 'set' shall denote an unordered collection of unique elements, and 'bag' an unordered collection of possibly non-unique elements. + +## Components + +ONNX is an open specification that consists of the following components: + +1) A definition of an extensible computation graph model. + +2) Definitions of standard data types. + +3) Definitions of built-in operators. + +#1 and #2 together make up the ONNX Intermediate Representation, or 'IR', specification which is covered herein; the built-in operators are covered in documents listed at the end. Specifically, built-in operators are divided into a set of primitive operators and functions. A function is an operator whose semantics is formally expressed via expansion into a sub-graph (called the function body) using other operators (and functions). Functionality-wise, an ONNX compatible framework or runtime may inline a function body to execute it if it does not have corresponding implementation of the function. + +There are two official ONNX variants; the main distinction between the two is found in the default operator sets. __ONNX-ML__ extends the __ONNX__ operator set with ML algorithms that are not based on neural networks. + +Up to IR version 6, the ONNX specification and model format addressed only inference (also known as scoring). Starting from IR version 7, the ONNX specification and model format also support training. An ONNX training model is an extension of the inference-model. An inference-only runtime can consume a training model ignoring the training-related extensions. However, an inference-only model may enable a representation that is more optimal for inference purposes than a training model. + +## Runtime Agnostic + +ONNX does not pre-suppose or imply any particular method of runtime implementation. + +For example, an implementation may consist of a rich runtime which interprets the model; it may be a code generator that translates the model in its entirety to executable code for some target programming language; it may be a hardware implementation; it may be a combination of two or three of those. + +Nothing in this specification should be construed as advocating one implementation approach over any other; any comments on the inner workings of concrete implementations are to be interpreted as examples. + +## ONNX Versioning + +The IR specification, individual models, and operator sets are all versioned. Furthermore, each individual operator indicates which version of its containing operator set it was introduced or stabilized in. + +Version numbers can be used as a simple number, or used to encode [semantic versions](https://semver.org/)(AKA SemVer). If using semantic versions, the convention is to use the two most significant bytes for the major number, the next two bytes for the minor number, and the least significant four bytes for the patch/build/bugfix number. When using semantic versioning, at least one of the major/minor numbers MUST be non-zero. + +The IR specification uses simple monotonically increasing numbers for its versions. The valid IR versions are defined by the `onnx.Version` enumeration in [onnx.proto](/onnx/onnx.proto). + +Operator sets use a simple version number. Each operator set version represents a snapshot of the set of operators, and their semantics at a particular point in time. + +This specification does not provide guidance on what versioning scheme model producers should be using. + +More details on conventions and best practices for versioning of IR, operator sets, and models can be found in [Versioning](Versioning.md). + +## Extensible computation graph model + +ONNX specifies the portable, serialized format of a computation graph. It does not have to be the form a framework chooses to use internally. For example, an implementation may represent the model differently in memory if it is more efficient to manipulate during optimization passes. + +An implementation MAY extend ONNX by adding operators expressing semantics beyond the standard set of operators that all implementations MUST support. The mechanism for this is adding operator sets to the `opset_import` property in a model that depends on the extension operators. + +### Models + +The top-level ONNX construct is a ‘Model.’, and is represented in protocol buffers as the type `onnx.ModelProto` + +The main purpose of the model structure is to associate metadata with a graph which contains all the executable elements. The metadata is used when first reading the model file, giving an implementation the information it needs in order to determine whether it will be able to execute the model, generate logging messages, error reports, etc. Further, the metadata is useful to tools, such as IDEs and model galleries, which need it for informing humans about a given model’s purpose and characteristics. + +Each model has the following components: + +|Name|Type|Description| +|---|---|---| +|ir_version|int64|The ONNX version assumed by the model.| +|opset_import|OperatorSetId|A collection of operator set identifiers made available to the model. An implementation must support all operators in the set or reject the model.| +|producer_name|string|The name of the tool used to generate the model.| +|producer_version|string|The version of the generating tool.| +|domain|string|A reverse-DNS name to indicate the model namespace or domain, for example, 'org.onnx'| +|model_version|int64|The version of the model itself, encoded in an integer.| +|doc_string|string|Human-readable documentation for this model. Markdown is allowed.| +|graph|Graph|The parameterized graph that is evaluated to execute the model.| +|metadata_props|map|Named metadata values; keys should be distinct.| +|training_info|TrainingInfoProto[]|An optional extension that contains information for training.| +|functions|FunctionProto[]|An optional list of functions local to the model.| + + Models MUST specify a domain and use reverse domain names based on the responsible organization's identity, the same convention that is used for [naming Java packages](https://docs.oracle.com/javase/tutorial/java/package/namingpkgs.html). + +__Note: Exploring an ONNX file__ + +You can use the `protoc` tool that is part of the Protocol Buffers distribution to examine the contents of an ONNX file, you do so like this: + +``` +$ protoc --decode=onnx.ModelProto onnx.proto < yourfile.onnx +``` + +Where [onnx.proto](/onnx/onnx.proto) is the file that is part of this repository. + +Alternatively, you can use a tool like [Netron](https://github.com/lutzroeder/netron) to explore the ONNX file. + +### Model Semantics + +The semantics of an inference-model is a _stateless function_ (except possibly for the state used for random-number generation). Thus, whenever an inference-model (without random-generator operations) is used to perform inference on the same input, it is expeced to produce the same output. + +The semantics of a training model is that of a _stateful object_, with the state consisting of the current values of trained-weights (and any other auxiliary state required, such as momentum, for example, used by the learning algorithm). Specifically, its semantics is captured via three methods: an initialization method (which is used to initialize or reset the values of state variables), a training step method (to train using a batch of input-output pairs), and an inference method to perform inference using the current values of the learned weights. The first two methods update the state of the object, while the third method is side-effect-free. + +### Optional Metadata + +The 'metadata_props' field in the model is available for any kind of optional metadata that a tool or model developer chooses to place there. The following are the defined “standard” optional metadata properties of a model. + +Name|Type|Format|Description +|---|---|---|---| +model_author|string|A comma-separated list of names.|The personal name of the author(s) of the model, and/or their organizations. +model_license|string|Name or URL.|The well-known name or URL of the license under which the model is made available. + + +### Operator Sets + +Each model MUST explicitly name the operator sets that it relies on for its functionality. Operator sets define the available operators and their version. Each model defines the imported operator sets by their domains. All models implicitly import the default ONNX operator set. + +Each operator set SHALL be defined in a separate document, also using protobuf as the serialization format. How operator set documents are found at runtime is implementation-dependent. + +__Note: As of the publication of this document, no ONNX implementation is known to process operator set documents.__ + +The properties of an operator set are: + +Name|Type|Description +|---|---|---| +magic|string|The value ‘ONNXOPSET’ +ir_version|int32|The ONNX version corresponding to the operators. +ir_version_prerelease|string|The prerelease component of the SemVer of the IR. +ir_build_metadata|string|The build metadata of this version of the operator set. +domain|string|The domain of the operator set. Must be unique among all sets. +opset_version|int64|The version of the operator set. +doc_string|string|Human-readable documentation for this operator set. Markdown is allowed. +operator|Operator[]|The operators contained in this operator set. + +The operator set version is a simple integer value that is monotonically increased as new versions of the operator set are published. + +Operator sets other than the default operator set MUST specify a domain and SHOULD use reverse domain names based on the responsible organization's identity, the same convention that is used for [naming Java packages](https://docs.oracle.com/javase/tutorial/java/package/namingpkgs.html). + +### Operators + +Each operator used within a graph MUST be explicitly declared by one of the operator sets imported by the model. + +The properties of an operator definition are: + +Name|Type|Description +|---|---|---| +op_type|string|The name of the operator, as used in graph nodes. MUST be unique within the operator set’s domain. +since_version|int64|The version of the operator set when this operator was introduced. +status|OperatorStatus|One of ‘EXPERIMENTAL’ or ‘STABLE.’ +doc_string|string|A human-readable documentation string for this operator. Markdown is allowed. + +The version value MUST be the same value as the operator set version when the operator was first published. Subsequent versions of the operator set MUST NOT alter the signature or semantics of the operator once published as STABLE. + +The ‘status’ property indicates whether the syntax, semantics, or presence of the operator is in an experimental or stable stage. Once an operator is published as STABLE, it’s syntax and semantics MUST NOT change in subsequent versions of the operator set. + +There are two distinct ways to pass information to operators – inputs and attributes. Inputs represent graph inputs or values computed elsewhere in the graph, while attributes are used for values that are constants in the graph. This distinction may be highly relevant to achieving good performance for some implementations, while completely irrelevant to others. + +### Graphs + +A graph is used to describe a side-effect-free computation (function). +A serialized graph is comprised of a set of metadata fields, a list of model parameters, and a list of computation nodes. + +Each computation dataflow graph is structured as a topologically sorted list of nodes that form a graph, which MUST be free of cycles. Each node represents a call to an operator or a model local function. Each node has zero or more inputs and one or more outputs. + +Graphs have the following properties: + +|Name|Type|Description| +|---|---|---| +name|string|The name of the model graph. +node|Node[]|A list of nodes, forming a partially ordered computation graph based on input/output data dependencies. It is in topological order. +initializer|Tensor[]|A list of named tensor values. When an initializer has the same name as a graph input, it specifies a default value for that input. When an initializer has a name different from all graph inputs, it specifies a constant value. The order of the list is unspecified. +doc_string|string|Human-readable documentation for this model. Markdown is allowed. +input|ValueInfo[]|The input parameters of the graph, possibly initialized by a default value found in ‘initializer.’ +output|ValueInfo[]|The output parameters of the graph. Once all output parameters have been written to by a graph execution, the execution is complete. +value_info|ValueInfo[]|Used to store the type and shape information of values that are not inputs or outputs. + +ValueInfo has the following properties: + +Name|Type|Description +|---|---|---| +name|string|The name of the value/parameter. +type|Type|The type of the value **including shape information**. +doc_string|string|Human-readable documentation for this value. Markdown is allowed. + +Each main (top-level) graph MUST define the names, types and shapes of its inputs and outputs, which are specified as ‘value info’ structures. The main graph inputs and outputs are required to have a shape, indicating the rank, even though the exact dimensions need not be specified. + +Nested subgraphs (specified as attribute values) MUST define the names of its inputs and outputs +and MAY define the types of its inputs and outputs. + +Each graph MUST specify a name. + +The graph MUST adhere to single static assignment (SSA) for all node outputs; this means that all node output names MUST be unique within a graph. + +Graphs SHOULD be populated with documentation strings, which MAY be interpreted using GitHub-style markdown syntax. HTML and other text-markup languages MAY NOT be used in documentation strings. + +### Names Within a Graph + +All names MUST adhere to [C90 identifier syntax rules](https://en.cppreference.com/w/c/language/identifier). + +Names of nodes, inputs, outputs, initializers, and attributes are organized into several namespaces. Within a namespace, each name MUST be unique for each given graph. Please see below for further clarification in the case where a graph contains nested subgraphs (as attribute values). + +The namespaces are: + +Namespace|Description +|---|---| +Attribute|The names of attributes of an operator. Unique for each operator. +Value|The names of values – node inputs & outputs, tensor values (if named), graph inputs, outputs. +Node|The names of graph nodes. +Graph|The names of graphs within a domain, unique within the model domain. +Operator|The names of operators within a domain. +Shape|The names of tensor shape variables – scoped to the value information records of a graph, which is where shape variables occur. + + +### Nodes + +Computation nodes are comprised of a name, the name of an operator that it invokes, a list of named inputs, a list of named outputs, and a list of attributes. + +Input and outputs are positionally associated with operator inputs and outputs. Attributes are associated with operator attributes by name. + +They have the following properties: + +Name|Type|Description +|---|---|---| +name|string|An optional name of the node, used for diagnostic purposes only. +input|string[]|Names of the values used by the node to propagate input values to the node operator. It must refer to either a graph input, a graph initializer or a node output. +output|string[]|Names of the outputs used by the node to capture data from the operator invoked by the node. It either introduces a value in the graph or refers to a graph output. +op_type|string|The symbolic identifier of the operator to invoke. +domain|string|The domain of the operator set that contains the operator named by the op_type. +attribute|Attribute[]|Named attributes, another form of operator parameterization, used for constant values rather than propagated values. +doc_string|string|Human-readable documentation for this value. Markdown is allowed. + +A name belonging to the Value namespace may appear in multiple places, namely as a graph input, a graph initializer, a graph output, a node input, or a node output. The occurrence of a name as a graph input, a graph initializer, or as a node output is said to be a definition and the occurrence of a name as a node input or as a graph output is said to be a use. + +A value name used in a graph must have a unique definition, with the exception that the same name MAY appear in both the graph input list and graph initializer list. (Further exceptions apply in the presence of nested subgraphs, as described later.) + +When a name appears in both the initializer list and the graph input list, a runtime MAY allow a caller to specify a value for this (input) name overriding the value specified in the initializer and a runtime MAY allow users to omit specifying a value for this (input) name, choosing the value specified in the initializer. Names of constants that are not meant to be overridden by the caller should appear only in the initializer list and not in the graph input list. In models with IR version >= 4, in nested subgraphs used as attribute values, users MUST NOT use the same name as both a subgraph initializer and subgraph input unless the corresponding op's specification explicitly allows it. In models with IR version <= 3, users MAY use the same name as both a subgraph initializer and subgraph input, but this is restricted to support constants via initializers that are not intended to correspond to any actual inputs passed from the node into the subgraph. In particular, the control-flow operator semantics determines the set of inputs supplied to the execution of the subgraph, and these input names MUST NOT appear as subgraph initializers. Subgraph initializer names must appear in the graph input list _after_ the actual inputs. This allows the actual inputs and formal inputs to be matched positionally. + +Edges in the computation graph are established by outputs of one node being referenced by name in the inputs of a subsequent node. + +The outputs of a given node introduce new names into the graph. The values of node outputs are computed by the node's operator. Node inputs MAY refer to node outputs, graph inputs, and graph initializers. When the name of a node output coincides with the name of a graph output, the graph output's value is the corresponding output value computed by that node. A node input in a nested subgraph MAY refer to names introduced in outer graphs (as node outputs, graph inputs, or graph initializers). + +The graph MUST use single static assignment for all node outputs, which means that all node output names MUST be unique within a graph. In the case of a nested subgraph, a node output name MUST be distinct from the names from the outer scopes that are visible in the nested subgraph. + +Node dependencies MUST NOT create cycles in the computation graph. + +The number of inputs and outputs in a node, their types, the set of attributes specified in a node and their types MUST satisfy the constraints imposed by the signature of the node’s operator. + +The list of nodes defining the top-level computation graph MUST be ordered topologically; that is, if node K follows node N in the graph, none of the data inputs of N may refer to outputs of K. + +Node attributes are used to pass literal (static) values to operators. + +#### Input and Output Values + +The representation distinguishes between two kinds of values: attribute values, which are statically known, and input/output values. The types of values permitted in the two cases are different. + +Input and output values are found as graph inputs, outputs, and initializers, and as node inputs and outputs. Their values are determined at runtime, either by the code that initiates model execution, or by operators computing output values. + +#### Attributes + +Attribute values are only found in nodes, passed to operators by name association. Attribute values are runtime constants, in that their values are determined when a model graph is constructed and therefore not computed at runtime. A common use for attributes is to represent coefficients established during model training. + +Attributes have the following properties: + +Name|Type|Description +|---|---|---| +name|string|The name of the attribute. Must be unique among attributes, inputs, and outputs for any given operator and node. +doc_string|string|Human-readable documentation for this value. Markdown is allowed. +type|AttributeType|The type of the attribute, determining which of the remaining fields is used to hold the value of the attribute. +f|float|A 32-bit floating-point value. +i|int64|A 64-bit integer value. +s|byte[]|UTF-8 string. +t|Tensor|A tensor value. +g|Graph|A graph. +floats|float[]|A list of 32-bit floating-point values. +ints|int64[]|A list of 64-bit integer values. +strings|byte[][]|A list of UTF-8 strings. +tensors|Tensor[]|A list of tensor values. +graphs|Graph[]|A list of graphs. + +The properties ‘name’ and ‘type’ are required on all attributes, and ‘doc_string’ SHOULD be used on all attributes. An attribute MUST have only one of the value-carrying properties. + + +#### Variadic Inputs and Outputs + +The last input or output of an operator MAY be marked as variadic. For example, the operator 'Max()' can be used to compute the maximum of a varying number of input values. A variadic operator has a minimum arity, which specifies the minimum number of operands that must be specified. + +For each variadic operator input, N or more node inputs must be specified where N is the minimum arity of the operator. For each variadic operator output, N or more node outputs must be specified where N is the minimum arity of the operator. + +#### Optional Inputs and Outputs + +Some operators have inputs that are marked as optional, which means that a referring node MAY forgo providing values for such inputs. + +Some operators have outputs that are optional. When an actual output parameter of an operator is not specified, the operator implementation MAY forgo computing values for such outputs. + +There are two ways to leave an optional input or output unspecified: the first, available only for trailing inputs and outputs, is to simply not provide that input; the second method is to use an empty string in place of an input or output name. + +Each node referring to an operator with optional outputs MUST provide a name for each output that is computed and MUST NOT provide names for outputs that are not computed. + +#### External Tensor Data + +The raw data for large constant tensors, such as initializers, MAY be serialised in a separate file. In such a case, the tensor MUST provide the filename relative to the model file and MUST NOT use the value fields. It MAY provide a byte offset and length within that file. It MAY also specify a SHA1 digest of the file. One file MAY contain the data for multiple tensors. + +More details can be found in [External Data](ExternalData.md). + +## Standard data types + +There are two official ONNX variants; the main distinction between the two is found in the supported types and the supported operators. + +With respect to supported types, both __ONNX__ and __ONNX-ML__ definition recognize tensors, sparse tensors, sequences, maps, and optionals as input and output types. Sequences and maps were supported from the IR version 6 (ONNX 1.6.0 release). Optional type was supported from IR vesion 8 (ONNX 1.10.0 release). + +The following data types are supported by ONNX for inputs and outputs of graphs and nodes as well as the initializers of a graph. + +Primitive numeric, string, and Boolean types MUST be used as elements of tensors. + +### Tensor Definition + +Tensors are a generalization of vectors and matrices; whereas vectors have one dimension, and matrices two, tensors can have any number of dimensions, including zero. A zero-dimensional tensor is logically equivalent to a scalar value. + +Mathematically, a tensor can be defined as a pair of sequences/lists (V, S) where S is the shape of the tensor (a list of non-negative integers) and V is a list of values with length equal to the product of the dimensions in S. Two tensors (V, S) and (V', S') are equal if and only if V = V' and S = S'. The length of S is referred to as the rank. + + - If S has length 0, V must have length 1, since the empty product is defined to be 1. In this case, the tensor represents a scalar. + - S can contain dimensions of value 0. If any dimensions are 0, V must have length 0. + - If S has length 1, V has length equal to the single dimension in S. In this case, the tensor represents a vector. + - A tensor representing a vector of length 1 has shape [1], while a tensor representing a scalar has shape []. They both have a single element, but scalars are _not_ vectors of length 1. + +A tensor's shape S is a list but can be represented as a tensor with values S and shape [R] where R is the rank of the tensor. + + - For a tensor (V, S), the tensor representing its shape is (S, [R]). + - The shape of a scalar is []. Represented as a tensor, [] has shape [0]. + +#### Representation + +It is common to represent a tensor as a nested list. This generally works fine, but is problematic when zero dimensions are involved. A tensor of shape (5, 0) can be represented as [[], [], [], [], []], but (0, 5) is represented as [] which loses the information that the second dimension is 5. + + - A nested list is not a complete representation of a tensor with dimensions of value zero. + +### Tensor Element Types + +|Group|Types|Description| +|---|---|---| +Floating Point Types|float16, float32, float64|Values adhering to the IEEE 754-2008 standard representation of floating-point data. +Signed Integer Types|int8, int16, int32, int64|Signed integers are supported for 8-64 bit widths. +Unsigned Integer Types|uint8, uint16|Unsigned integers of 8 or 16 bits are supported. +Complex Types|complex64, complex128|A complex number with either 32- or 64-bit real and imaginary parts. +Other|string|Strings represent textual data. All strings are encoded using UTF-8. +Other|bool|Boolean values represent data with only two values, typically true and false. + +### Input / Output Data Types + +The following types are used to define the types of graph and node inputs and outputs. + +|Variant | Type | Description | +|---|---|---| +ONNX|dense tensors|Represents a Tensor. See definition above. +ONNX|sequence|Sequences are dense, ordered, collections of elements that are of homogeneous types. +ONNX|map|Maps are associative tables, defined by a key type and a value type. +ONNX|optional|Optionals are wrappers that may contain an element of tensor, sequence, or map type, or may be empty (containing none). [Details](ONNXTypes.md) + +#### Static tensor shapes + +In addition to element type, tensor types have a **static** shape. The static shape of a tensor variable is related to, but different from, the runtime (dynamic) shape of a tensor value. A static tensor shape is a list of records that indicates whether the tensor is a vector, a matrix, or a higher-dimensional value. For example, a 100x100 matrix has the shape [100,100]. + +The static shape is defined by 'TensorShapeProto': + +``` +message TensorShapeProto { + message Dimension { + oneof value { + int64 dim_value = 1; + string dim_param = 2; + }; + }; + repeated Dimension dim = 1; +} +``` +Which is referenced by the Tensor type message: + +``` + message Tensor { + optional TensorProto.DataType elem_type = 1; + optional TensorShapeProto shape = 2; + } +``` + +The empty list of dimension sizes, [], is a valid tensor shape, denoting a zero-dimension (scalar) value. A zero-dimension tensor is distinct from a tensor of unknown dimensionality, which is indicated by an absent 'shape' property in the Tensor message. When the shape property is absent in the type of a value (including node input), +it indicates that the corresponding runtime value may have any shape. This sub-section describes how to interpret a missing-shape or a shape with missing dimensions etc. However, specific usage contexts may impose further constraints on a type and shape. +For example, the inputs and outputs of a model (top-level graph) are required to *have* a shape, indicating the rank of inputs and outputs, +even though the exact dimensions need not be specified. + +Each size in the list MAY be expressed as an integral value or as a "dimension variable," a string denoting that the actual size of the dimension is not statically constrained to a particular number. This is useful for declaring interfaces that care about the number of dimensions, but not the exact size of each dimension. A dimension MAY have neither dim_value nor dim_param set. Such a dimension represents an unknown dimension unrelated to other unknown dimensions. + +For example, a NxM matrix would have the shape list [N,M]. + +The name of each dimension variable MUST adhere to [C90 identifier syntax rules](https://en.cppreference.com/w/c/language/identifier). + +Currently, dimension variables are not scoped. A dimension variable "N" represents the same value across the entire graph in a model. For example, if the graph has two inputs X and Y each with shape ["N"], then at runtime the values passed in for X and Y MUST be tensors of rank 1 with the same dimension. Nested sub-graphs currently share the same scope for dimension variables as the main-graph. This allows a model to relate the dimensions of tensors inside the subgraph to the dimensions of tensors in the outer graph. + +ONNX supports types such as Sequences of Tensors. The global scoping of dimension variables means that a variable with type "Sequence" represents a sequence of tensors that *all have the same shape*. The dimension variables M or N must be omitted from the above type if that dimension does not have a fixed size across all tensors in the sequence. The entire shape must be omitted from the type if different tensors in the sequence may have different ranks. + +For example, a graph that performs matrix cross-product may be defined as taking two inputs of shape [K,M] and [M,N], and producing an output of shape [K,N]. + +Shapes MAY be defined using a combination of integers and variables. + +_Historical Notes_: The following extensions were considered early on, but were never implemented or supported. +* The use of an empty string (as a dimension variable) to denote an unknown dimension not related to any other dimension. This was discarded in favor of using a Dimension with neither dim_value nor dim_param set. +* The use of the string "\*" (as a dimension variable) to denote a sequence of zero or more dimensions of unknown cardinality. This is not supported. In the current implementation, the number of dimensions in a shape MUST represent the rank of the tensor. A tensor of unknown rank is represented using a TypeProto::Tensor object with no shape, which is legal. +* A scoping mechanism to allow dimension variables that are local to a sub-graph (such as the body of a loop) may be useful, but is not currently supported. +* ONNX supports types such as Sequences of Tensors. A scoping mechanism for the dimension variables local to a type may be useful to distinguish between the following two types: a sequence of square matrices (of differing sizes) vs a sequence of square matrices (all of same size). This is not currently supported. + +### Attribute Types + +The type system used for attributes is related to but slightly different from that used for of inputs and outputs. Attribute values may be a dense tensor, sparse tensor, a scalar numerical value, a string, a graph, or repeated values of one of the above mentioned types. + +## Training Related Information + +Training related information is described by one or more instances of _TrainingInfoProto_ contained in a model. Each TrainingInfoProto contains information describing both an initialization step and a training step. + +The initialization step is described using a Graph (TrainingInfoProto.initialization) and an initialization-binding map (TrainingInfoProto.initialization_binding). The initialization step is performed by evaluating the Graph, and assigning the outputs produced by the Graph to the _state variables_ of the training model as specified in the initialization-binding. The initialization-binding is conceptually a map, specified as a list of key-value pairs, where each key is the name of a state variable, and the value is the name of an output of the (initialization) Graph. Each name specified as a key in the binding MUST be the name of an initializer that appears in the main inference graph (i.e., in ModelProto.graph.initializer) or the name of an initializer that appears in TrainingInfoProto.algorithm.initializer. Each name specified as a value in the binding MUST be the name of an output of the TrainingInfoProto.initialization graph. Key values specified in the repeated initialization_binding field MUST be unique. + +The training step is similarly described using a Graph (TrainingInfoProto.algorithm) and an update-binding map (TrainingInfoProto.update_binding). The training step is performed by evaluating the Graph and assigning the outputs produced by the Graph to the state variables as specified in the update-binding. The constraints and description presented above for the initialization apply to the training step as well. + +Thus, the state variables of the training model consist of a subset of the initializers of the main inference graph (i.e., ModelProto.graph.initializer) and the training-algorithm graph (TrainingInfoProto.algorithm.initializer) as identified by the keys of the bindings (in TrainingInfoProto.initialization_binding and TrainingInfoProto.update_binding). Note that the state variables are not constant values in the context of training. They represent mutable variables shared by multiple graphs (implicitly declared in the top-level training model scope). This implicit declaration of shared mutable variables is used instead of an explicit declaration for purposes of backward compatibility with the inference graph representation. + +All state variables are pre-initialized to the value specified in the corresponding initializer. A subsequent call to perform the initialization step (using the appropriate API exposed by a runtime) updates the values of the state variables as described above. If the training model has more than one instance of TrainingInfoProto, the initialization step corresponding to each is performed in order. A TrainingInfoProto.initialization MAY be omitted (only if there are no initialization_bindings). For the training step, a runtime MAY allow users to invoke any one of the TrainingInfoProto.algorithm, allowing the training process to interleave the different algorithms as desired. The order in which the different TrainingProto.algorithms are called affects the training result, and it is the callers responsibility to call them in the correct order. + +## Other Specification Documents + +The ONNX specification is comprised of this document, which defines the semantics of the IR and the standard data types, and the following documents defining standard operator semantics and the IR syntax. The latter is specified as Protobuf v2 and v3 schema files. + +See the [metadata category documentation](MetadataProps.md) for more details. + +### Operators + +[Neural Network Operators](Operators.md) + +[Classical Machine Learning operators](Operators-ml.md) + +### Syntax + +[ONNX Models and Graphs - protobuf v2](../onnx/onnx.proto) + +[ONNX Models and Graphs - protobuf v3](../onnx/onnx.proto3) + +[ONNX-ML Models and Graphs - protobuf v2](../onnx/onnx-ml.proto) + +[ONNX-ML Models and Graphs - protobuf v3](../onnx/onnx-ml.proto3) + +[ONNX Operator Sets - protobuf v2](../onnx/onnx-operators.proto) + +[ONNX Operator Sets - protobuf v3](../onnx/onnx-operators.proto3) + +[ONNX-ML Operator Sets - protobuf v2](../onnx/onnx-operators-ml.proto) + +[ONNX-ML Operator Sets - protobuf v3](../onnx/onnx-operators-ml.proto3) + +### Versioning Conventions and Best Practices + +[Versioning](Versioning.md) diff --git a/_doc/sphinxdoc/source/onnxmd/onnx_docs/ImplementingAnOnnxBackend.md b/_doc/sphinxdoc/source/onnxmd/onnx_docs/ImplementingAnOnnxBackend.md new file mode 100644 index 00000000..061e8c77 --- /dev/null +++ b/_doc/sphinxdoc/source/onnxmd/onnx_docs/ImplementingAnOnnxBackend.md @@ -0,0 +1,123 @@ + + +### Implementing an ONNX backend + +#### What is an ONNX backend + +An ONNX backend is a library that can run ONNX models. Since many deep learning frameworks already exist, you likely won't need to create everything from scratch. Rather, you'll likely create a converter that converts ONNX models to the corresponding framework specific representation and then delegate the execution to the framework. For example, [onnx-caffe2 (as part of caffe2)](https://github.com/caffe2/caffe2/tree/master/caffe2/python/onnx) , [onnx-coreml](https://github.com/onnx/onnx-coreml), and [onnx-tensorflow](https://github.com/onnx/onnx-tensorflow) are all implemented as converters. + +#### Unified backend interface + +ONNX has defined a unified (Python) backend interface at https://github.com/onnx/onnx/blob/master/onnx/backend/base.py. + +There are three core concepts in this interface: `Device`, `Backend` and `BackendRep`. + +- `Device` is a lightweight abstraction over various hardware, e.g., CPU, GPU, etc. + +- `Backend` is the entity that will take an ONNX model with inputs, perform a computation, and then return the output. + + For one-off execution, users can use `run_node` and `run_model` to obtain results quickly. + + For repeated execution, users should use `prepare`, in which the `Backend` does all of the preparation work for executing the model repeatedly (e.g., loading initializers), and returns a `BackendRep` handle. + +- `BackendRep` is the handle that a `Backend` returns after preparing to execute a model repeatedly. Users will then pass inputs to the `run` function of `BackendRep` to retrieve the corresponding results. + +Note that even though the ONNX unified backend interface is defined in Python, your backend does not need to be implemented in Python. For example, yours can be created in C++, and tools such as [pybind11](https://github.com/pybind/pybind11) or [cython](http://cython.org/) can be used to fulfill the interface. + +#### ONNX backend test + +ONNX provides a standard backend test suite to assist backend implementation verification. It's strongly encouraged that each ONNX backend runs this test. + +Integrating the ONNX Backend Test suite into your CI is simple. The following are some examples demonstrating how a backend performs the integration: + +- [onnx-caffe2 onnx backend test](https://github.com/caffe2/caffe2/blob/master/caffe2/python/onnx/tests/onnx_backend_test.py) + +- [onnx-tensorflow onnx backend test](https://github.com/onnx/onnx-tensorflow/blob/master/test/backend/test_onnx_backend.py) + +- [onnx-coreml onnx backend test](https://github.com/onnx/onnx-coreml/blob/master/tests/onnx_backend_test.py) + +If you have [pytest](https://docs.pytest.org/en/latest/) installed, you can get a coverage report after running the ONNX backend test to see how well your backend is doing: + +``` +---------- onnx coverage: ---------- +Operators (passed/loaded/total): 21/21/70 +------------------------------------ +╒════════════════════╤════════════════════╕ +│ Operator │ Attributes │ +│ │ (name: #values) │ +╞════════════════════╪════════════════════╡ +│ Slice │ axes: 2 │ +│ │ ends: 3 │ +│ │ starts: 3 │ +├────────────────────┼────────────────────┤ +│ Constant │ value: 1 │ +├────────────────────┼────────────────────┤ +│ Concat │ axis: 0 │ +├────────────────────┼────────────────────┤ +│ Conv │ group: 6 │ +│ │ kernel_shape: 5 │ +│ │ pads: 4 │ +│ │ strides: 3 │ +│ │ auto_pad: 0 │ +│ │ dilations: 0 │ +├────────────────────┼────────────────────┤ +│ Reshape │ shape: 9 │ +├────────────────────┼────────────────────┤ +│ BatchNormalization │ consumed_inputs: 1 │ +│ │ epsilon: 2 │ +│ │ is_test: 1 │ +│ │ momentum: 0 │ +│ │ spatial: 0 │ +├────────────────────┼────────────────────┤ +│ Dropout │ is_test: 1 │ +│ │ ratio: 2 │ +├────────────────────┼────────────────────┤ +│ MaxPool │ kernel_shape: 2 │ +│ │ pads: 3 │ +│ │ strides: 2 │ +│ │ auto_pad: 0 │ +│ │ dilations: 0 │ +├────────────────────┼────────────────────┤ +│ Transpose │ perm: 1 │ +├────────────────────┼────────────────────┤ +│ MatMul │ No attributes │ +├────────────────────┼────────────────────┤ +│ Relu │ No attributes │ +├────────────────────┼────────────────────┤ +│ LRN │ alpha: 2 │ +│ │ beta: 1 │ +│ │ bias: 2 │ +│ │ size: 1 │ +├────────────────────┼────────────────────┤ +│ Add │ axis: 1 │ +│ │ broadcast: 1 │ +├────────────────────┼────────────────────┤ +│ Abs │ No attributes │ +├────────────────────┼────────────────────┤ +│ Pad │ mode: 3 │ +│ │ paddings: 2 │ +│ │ value: 1 │ +├────────────────────┼────────────────────┤ +│ Softmax │ axis: 0 │ +├────────────────────┼────────────────────┤ +│ GlobalAveragePool │ No attributes │ +├────────────────────┼────────────────────┤ +│ Mul │ axis: 1 │ +│ │ broadcast: 1 │ +├────────────────────┼────────────────────┤ +│ Sum │ No attributes │ +├────────────────────┼────────────────────┤ +│ Gemm │ broadcast: 1 │ +│ │ transB: 1 │ +│ │ alpha: 0 │ +│ │ beta: 0 │ +│ │ transA: 0 │ +├────────────────────┼────────────────────┤ +│ AveragePool │ kernel_shape: 3 │ +│ │ pads: 3 │ +│ │ strides: 2 │ +│ │ auto_pad: 0 │ +╘════════════════════╧════════════════════╛ +``` + +The numbers in the line `Operators (passed/loaded/total): 21/21/70` indicate 21 operators covered in all test cases of your backend have passed, 21 operators were covered in all test cases of the ONNX backend test, and ONNX has a total of 70 operators. diff --git a/_doc/sphinxdoc/source/onnxmd/onnx_docs/ManagingExperimentalOps.md b/_doc/sphinxdoc/source/onnxmd/onnx_docs/ManagingExperimentalOps.md new file mode 100644 index 00000000..03ccd97c --- /dev/null +++ b/_doc/sphinxdoc/source/onnxmd/onnx_docs/ManagingExperimentalOps.md @@ -0,0 +1,34 @@ + + +## Deprecated Experimental Operators + +The following experimental operators were deprecated and removed from ONNX. They should be removed from models, either substituted with newer superseding operators or decomposed into functionally equivalent operators: + +Old operator |New Operator +--------------------|-------------------------- +`ATen` |NA +`Affine` |`Add(Mul(X, alpha), beta)` +`ConstantFill` |`ConstantOfShape` +`Crop` |`Slice-1` +`DynamicSlice` |`Slice-10` +`GRUUnit` |NA +`GivenTensorFill` |`Const` or `ConstantOfShape` +`ImageScaler` |`Add(Mul(X, scale), Unsqueeze(bias, axes=[0, 2, 3]))` +`ParametricSoftplus`|`Mul(alpha, Softplus(Mul(beta, X)))` +`Scale` |`Mul(X, scale)` +`ScaledTanh` |`Mul(Tanh(Mul(X, beta)), alpha)` + +## Adding Experimental Operators [Deprecated - as of v1.5 experimental ops are no longer supported] + +The experimental flag in ONNX operator definitions indicates that a customer of ONNX may not be able to take a long term dependency on that op. Ops in the ONNX namespace (ai.onnx) in the _master_ branch, whether experimental or not, go through the regular review process. + +Experimental ops that are being worked on that do not have consensus yet can be managed in one of 2 ways: +1. Use a fork or branch – what you do in the fork or branch is entirely up to you. When you are ready, you can submit a PR using the normal process. This is the recommended way. +2. If a fork/branch is not workable (for example due to complexity of mapping different branches between multiple repos), put the experimental ops in a custom namespace in the master branch. +The specific process for this is: + * Submit an Issue with a proposal explaining the motivation and plan. It does not need to include detailed technical design. Issues will be tagged as "experimental op". + * Reviewers will generally approve by default unless the proposal directly conflicts with existing ops or somehow goes against general ONNX strategy. Approval is indicated by adding the "experiment approved" tag. + * The approval is good for 3 months, but can be renewed if needed. + * Experimental ops should be submitted in a PR in a custom namespace that is the name of the proposal, i.e. “proposal.controlflow”. The name should be descriptive rather than a company or entity name. These PRs will be approved by default as long as the parent proposal is approved and active. + * Once experimentation is done, the ops can be submitted for addition to the ONNX namespace via the regular process. The owner can also choose to end the experiment without promoting the ops. + * Either way, the custom namespace is deleted once experimentation is complete or when the approval expires. diff --git a/_doc/sphinxdoc/source/onnxmd/onnx_docs/MetadataProps.md b/_doc/sphinxdoc/source/onnxmd/onnx_docs/MetadataProps.md new file mode 100644 index 00000000..21a7c4df --- /dev/null +++ b/_doc/sphinxdoc/source/onnxmd/onnx_docs/MetadataProps.md @@ -0,0 +1,35 @@ + + +# Metadata +# Metadata + +In addition to the core metadata recommendations listed in the [extensibility documentation](IR.md#optional-metadata) there is additional experimental metadata to help provide information for model inputs and outputs. + +This metadata applies to all input and output tensors of a given category. The first such category we define is: `Image`. + +## Motivation + +The motivation of such a mechanism is to allow model authors to convey to model consumers enough information for them to consume the model. + +In the case of images there are many option for providing valid image data. However a model which consumes images was trained with a particular set of these options which must +be used during inferencing. + +The goal is this proposal is to provide enough metadata that the model consumer can perform their own featurization prior to running the model and provide a compatible input or retrive an output and know what its format is. + +## Image Category Definition + +For every tensor in this model that uses [Type Denotation](TypeDenotation.md) to declare itself an `IMAGE`, you SHOULD provide metadata to assist the model consumer. Note that any metadata provided using this mechanism is global to ALL types +with the accompanying denotation. + +Keys and values are case insenstive. + +Specifically, we define here the following set image metadata: + +|Key|Value|Description| +|-----|----|-----------| +|`Image.BitmapPixelFormat`|__string__|Specifies the format of pixel data. Each enumeration value defines a channel ordering and bit depth. Possible values:
  • `Gray8`: 1 channel image, the pixel data is 8 bpp grayscale.
  • `Rgb8`: 3 channel image, channel order is RGB, pixel data is 8bpp (No alpha)
  • `Bgr8`: 3 channel image, channel order is BGR, pixel data is 8bpp (No alpha)
  • `Rgba8`: 4 channel image, channel order is RGBA, pixel data is 8bpp (Straight alpha)
  • `Bgra8`: 4 channel image, channel order is BGRA, pixel data is 8bpp (Straight alpha)
| +|`Image.ColorSpaceGamma`|__string__|Specifies the gamma color space used. Possible values:
  • `Linear`: Linear color space, gamma == 1.0
  • `SRGB`: sRGB color space, gamma == 2.2
| +|`Image.NominalPixelRange`|__string__|Specifies the range that pixel values are stored. Possible values:
  • `NominalRange_0_255`: [0...255] for 8bpp samples
  • `Normalized_0_1`: [0...1] pixel data is stored normalized
  • `Normalized_1_1`: [-1...1] pixel data is stored normalized
  • `NominalRange_16_235`: [16...235] for 8bpp samples
| + + + diff --git a/_doc/sphinxdoc/source/onnxmd/onnx_docs/ONNXIFI.md b/_doc/sphinxdoc/source/onnxmd/onnx_docs/ONNXIFI.md new file mode 100644 index 00000000..011ac45e --- /dev/null +++ b/_doc/sphinxdoc/source/onnxmd/onnx_docs/ONNXIFI.md @@ -0,0 +1,66 @@ + + +# ONNX Interface for Framework Integration (ONNXIFI) + +ONNXIFI is a cross-platform API for loading and executing ONNX graphs on optimized backends. High-level frameworks and applications can use this API to execute neural network and machine learning models. Hardware vendors can implement this API to expose specialized hardware accelerators and highly optimized software infrastructure to the users. + +## Core Features + +- Standardized interface for neural network inference on special-purpose accelerators (NPUs), CPUs, GPUs, DSPs, and FPGAs +- Based on widely supported technologies + - C API for function calls + - ONNX format for passing model graphs + - NCHW tensor layout for passing inputs and outputs +- Dynamic discovery of available backends for model execution + - Multiple backends from different vendors can co-exist on the same system +- Dynamic discovery of supported ONNX Operators on each backend + +### Optional Features: + +- Graphs with variable-shape inputs and/or outputs +- Graphs with data-dependendent output shapes + +## How to Use ONNX Interface for Framework Integration + +0. (Optional) Use `onnxifi_load` to dynamically load the ONNX Interface for Framework Integration library. +1. Call `onnxGetBackendIDs` to get stable identifiers of available backends. Note: it is possible there are no backends installed in the system. +2. Call `onnxGetBackendInfo` to check additional information about any available backend. +3. Call `onnxGetBackendCompatibility` to check which operations within your model can run on the backend. +4. Call `onnxInitBackend` to initialize a backend, then call `onnxInitGraph` to offload one or more model graphs to the backend. +5. Call `onnxSetGraphIO` to set locations and shapes for inputs and outputs of a graph. +6. Initialize an `inputFence` structure of type `onnxMemoryFenceV1`: set `tag` to `ONNXIFI_TAG_MEMORY_FENCE_V1`, `type` to `ONNXIFI_SYNCHRONIZATION_EVENT`, and call `onnxInitEvent` to initiaze the `event` member. +7. Initialize an `outputFence` structure of type `onnxMemoryFenceV1`: set `tag` to `ONNXIFI_TAG_MEMORY_FENCE_V1`, `type` to `ONNXIFI_SYNCHRONIZATION_EVENT`, and `event` to null. +8. Call `onnxRunGraph` with the initialized `inputFence` and `outputFence` structures to enable execution of the graph. The call to `onnxRunGraph` will populate `event` member of the `outputFence` with a newly created event object, asynchronously execute the graph once `inputFence`'s `event` is signalled, and then signal the `outputFence`'s `event`. +9. Call `onnxSignalEvent` with `event` member of `inputFence` to signal to the backend that the inputs are ready to be consumed. +10. Call `onnxWaitEvent` (alternatively, repeatedly call `onnxGetEventState` in a loop until the event state is `ONNXIFI_EVENT_STATE_SIGNALLED`) with `event` member of `outputFence` to wait until graph outputs are ready to be consumed. Release events for inputs and outputs using `onnxReleaseEvent`. +11. If your model works with fixed-size inputs and outputs, and shape and location of inputs and outputs does not change, one call to `onnxSetGraphIO` is sufficient for multiple `onnxRunGraph` calls. The previous call to `onnxRunGraph`, however, must have finished before a user calls `onnxRunGraph` again, because concurrent execution with the same input and output locations is not allowed. For models with variable-size inputs or outputs, you'd need to call `onnxSetGraphIO` before each `onnxRunGraph` call. +12. When done using the model, release the model graph(s) with `onnxReleaseGraph`, then release the backend with `onnxReleaseBackend` and backend ID with `onnxReleaseBackendID`. + +## How to Implement ONNX Interface for Framework Integration + +The minimum functionality an ONNXIFI implementation must provide is the following: + +- Support ONNX 1.0 model format. + - There is no minimum list of Operators a backend has to support. +- Support graph inputs / outputs in CPU memory. +- Support graph inputs / outputs with fixed shape, specified in GraphProto message. + +### Discovery + +Vendor-provided libraries should adhere to some rules to ensure discovery by ONNX-supported frameworks and applications: + +1. The libraries must be installed in the following directories: + - GNU/Linux: user-installed system library directory (typically /usr/lib) + - macOS: /opt/onnx/lib + - Windows: system directory (typically C:\Windows\System32) + +2. Filenames of vendor-specific libraries must follow the rule below: + - On Windows, library filename must match wildcard `onnxifi-*.dll` + - On macOS, library filename must match wildcard `libonnxifi-*.dylib` + - On Linux and other OSes, library filename must match wildcard `libonnxifi-*.so` + +### Extensions + +Hardware vendors are welcome to add their own extensions to ONNX backend interface. The backend interface offers several extension mechanisms: +- Experimental, exotic, or vendor-specific operators can be supported in a private domain using NodeProto.domain attribute. +- Vendor-provided ONNXIFI implementation can expose additional functions. diff --git a/_doc/sphinxdoc/source/onnxmd/onnx_docs/ONNXTypes.md b/_doc/sphinxdoc/source/onnxmd/onnx_docs/ONNXTypes.md new file mode 100644 index 00000000..2edea6e4 --- /dev/null +++ b/_doc/sphinxdoc/source/onnxmd/onnx_docs/ONNXTypes.md @@ -0,0 +1,96 @@ +## Optional Type + +An optional type represents a reference to either an element (could be Tensor, Sequence, Map, or Sparse Tensor) or a null value. The optional type appears in model inputs, outputs, as well as intermediate values. + +### Use-cases + +Optional type enables users to represent more dynamic typing senarios in ONNX. Similar to Optional[X] type hint in Python typing which is equivalent to Union[None, X], Optional types in ONNX may reference a single element, or null. + +### Examples in PyTorch +Optional type only appears in TorchScript graphs generated by jit script compiler. Scripting a model captures dynamic types where an optional value can be assigned either None or a value. + +- Example 1 + + class Model(torch.nn.Module): + def forward(self, x, y:Optional[Tensor]=None): + if y is not None: + return x + y + return x + + Corresponding TorchScript graph: + + Graph( + %self : __torch__.Model, + %x.1 : Tensor, + %y.1 : Tensor? + ): + %11 : int = prim::Constant[value=1]() + %4 : None = prim::Constant() + %5 : bool = aten::__isnot__(%y.1, %4) + %6 : Tensor = prim::If(%5) + block0(): + %y.4 : Tensor = prim::unchecked_cast(%y.1) + %12 : Tensor = aten::add(%x.1, %y.4, %11) + -> (%12) + block1(): + -> (%x.1) + return (%6) + + ONNX graph: + + Graph( + %x.1 : Float(2, 3), + %y.1 : Float(2, 3) + ): + %2 : Bool(1) = onnx::OptionalHasElement(%y.1) + %5 : Float(2, 3) = onnx::If(%2) + block0(): + %3 : Float(2, 3) = onnx::OptionalGetElement(%y.1) + %4 : Float(2, 3) = onnx::Add(%x.1, %3) + -> (%4) + block1(): + %x.2 : Float(2, 3) = onnx::Identity(%x.1) + -> (%x.2) + return (%5) + +- Example 2 + + class Model(torch.nn.Module): + def forward( + self, + src_tokens, + return_all_hiddens=torch.tensor([False]), + ): + encoder_states: Optional[Tensor] = None + if return_all_hiddens: + encoder_states = src_tokens + + return src_tokens, encoder_states + + Corresponding TorchScript graph: + + Graph( + %src_tokens.1 : Float(3, 2, 4,), + %return_all_hiddens.1 : Bool(1) + ): + %3 : None = prim::Constant() + %encoder_states : Tensor? = prim::If(%return_all_hiddens.1) + block0(): + -> (%src_tokens.1) + block1(): + -> (%3) + return (%src_tokens.1, %encoder_states) + + ONNX graph: + + Graph( + %src_tokens.1 : Float(3, 2, 4), + %return_all_hiddens.1 : Bool(1) + ): + %2 : Float(3, 2, 4) = onnx::Optional[type=tensor(float)]() + %3 : Float(3, 2, 4) = onnx::If(%return_all_hiddens.1) + block0(): + -> (%src_tokens.1) + block1(): + -> (%2) + return (%3) \ No newline at end of file diff --git a/_doc/sphinxdoc/source/onnxmd/onnx_docs/ONNX_logo_main.png b/_doc/sphinxdoc/source/onnxmd/onnx_docs/ONNX_logo_main.png new file mode 100644 index 00000000..24ed87b3 Binary files /dev/null and b/_doc/sphinxdoc/source/onnxmd/onnx_docs/ONNX_logo_main.png differ diff --git a/_doc/sphinxdoc/source/onnxmd/onnx_docs/OnnxBackendTest.md b/_doc/sphinxdoc/source/onnxmd/onnx_docs/OnnxBackendTest.md new file mode 100644 index 00000000..56a08e07 --- /dev/null +++ b/_doc/sphinxdoc/source/onnxmd/onnx_docs/OnnxBackendTest.md @@ -0,0 +1,20 @@ + + +### ONNX Backend Test + +#### What is ONNX Backend Test + +ONNX Backend Test is a test suite that each ONNX backend should run to verify whether it fulfills ONNX's standard. It serves both as a verification tool for backend implementations and one of the two ways to define each operator's expected behavior (the other way is to add it to the documentation). + +There are two types of tests in this suite – Node Tests and Model Tests: + +- **Node Tests** verify whether a backend is performing the correct computation, having the expected behavior of handling various attributes for each individual operator. In each test case, the backend will be given a node with some input, and the returned output will be compared with an expected output. +- **Model Tests** verify the backend at the model level. The test cases are similar to those of Node Tests', but instead of a node, the backend will be given an ONNX model. + +#### Contributing + +As ONNX aims to become the spec of deep learning models format, it's important to ensure that there is no ambiguity in each ONNX operator's definition; adding more test cases is the only way to enforce this. + +Node Tests are created as Python/Numpy code in https://github.com/onnx/onnx/tree/master/onnx/backend/test/case/node, and then exported to protobuf files to https://github.com/onnx/onnx/tree/master/onnx/backend/test/data/node as the source of truth by invoking the shell command `backend-test-tools generate-data`. Test cases of each operator lives in one standalone file, e.g. for the operator [Add](https://github.com/onnx/onnx/blob/master/docs/Operators.md#Add), its test cases are in [add.py](https://github.com/onnx/onnx/blob/master/onnx/backend/test/case/node/add.py), and each `expect(...)` statement in the code corresponds to one test case. The source code of all `export.*` functions will be also embedded as example code snippets in the [Operators documentation page](https://github.com/onnx/onnx/blob/master/docs/Operators.md). You are contributing to both the test and the documentation! + +For Model Tests, since each model protobuf file can be large in size, we don't place the file directly in the repo. Rather, we upload them to the cloud, and download them on demand when running the tests. Each test case consists of one model definition protobuf file, and several pairs of input and output files. Adding a new test case involves some manual work from admins (like uploading the files to the cloud), so if you have an ONNX model that you would like to contribute, please contact us. diff --git a/_doc/sphinxdoc/source/onnxmd/onnx_docs/OnnxReleases.md b/_doc/sphinxdoc/source/onnxmd/onnx_docs/OnnxReleases.md new file mode 100644 index 00000000..886b18f6 --- /dev/null +++ b/_doc/sphinxdoc/source/onnxmd/onnx_docs/OnnxReleases.md @@ -0,0 +1,122 @@ + + +The ONNX project, going forward, will plan to release roughly on a two month cadence. We follow the [Semver](https://semver.org/) versioning approach and will make decisions as a community on a release by release basis on whether to do a major or minor release. + +## Preparation + +* Install Twine, a utility tool to interact with PyPI. Do - ``pip install twine`` +* Get hold of the username and password for the ‘onnx’ PyPI account. Release manager should get onnx pypi account credentials from steering committee or from previous release manager. +* Pick a release tag (v.1.X.X) for the new release through mutual consent – Slack channel for Releases (https://lfaifoundation.slack.com/archives/C018VGGJUGK) +* Prepare a change log for the release – + * ``git log --pretty=format:"%h - %s" ...`` + * And draft a new release statement - https://github.com/onnx/onnx/releases listing out the new features and bug fixes, and potential changes being introduced in the release. +* Before creating the release branch, increase `VERSION_NUMBER` in the main branch. The following files will be updated: [VERSION_NUMBER file](https://github.com/onnx/onnx/blob/master/VERSION_NUMBER) and +[version.h](../onnx/common/version.h) + +* Please use a VERSION_NUMBER smaller than the target (release VERSION_NUMBER) and larger than the previous one to test TestPyPI before using the target VERSION_NUMBER. + +* Make sure that the IR version number and opset version numbers are up-to-date in +[ONNX proto files](../onnx/onnx.in.proto), +[Versioning.md](Versioning.md), +[schema.h](../onnx/defs/schema.h), +[helper.py](../onnx/helper.py) and [helper_test.py](../onnx/test/helper_test.py). Please note that this also needs to be happened in the main branch before creating the release branch. + +* Create a release branch (please use rel-* as the branch name) from master. Checkout the release tag in a clean branch on your local repo. Make sure all tests pass on that branch. +* Create an issue in onnxruntime to update onnx commit in onnxruntime to the release branch commit and run all the CI and packaging pipelines. + +## Upload to TestPyPI +**Wheels** +* In release branch update the version number in file [VERSION_NUMBER] to something like `1.x.0rc1` as release candidate for verification before finally using the targeted version number for this release. +* Windows + * Use GitHub Action (`.github/workflows/release_win.yml`) under onnx repo to produce wheels for Windows. + +* Linux + * Use GitHub Action (`.github/workflows/release_linux_x86_64.yml`) and (`.github/workflows/release_linux_i686.yml`) under onnx repo to produce x64/i686 wheels for Linux. + +* Mac + * Use GitHub Action (`.github/workflows/release_mac.yml`) under onnx repo to produce wheels for Mac. + +* After success, upload the produced wheels manually to TestPyPI: `twine upload --verbose *.whl --repository-url https://test.pypi.org/legacy/ -u PYPI_USERNAME -p PYPI_PASSWORD`. + + +**Source Distribution** +* Make sure all the git submodules are updated + * ``git submodule update --init`` +* Make sure the git checkout is clean – + * Do ``git clean -nxd`` and make sure that none of the auto-generated header files *like* the following are not present. + * onnx/onnx-operators.pb.cc + * onnx/onnx-operator.pb.h + * onnx/onnx.pb.cc + * onnx/onnx.pb.h + * If they are present run ``git clean -ixd`` and remove those files from your local branch +* Do ``python setup.py sdist`` to generate the source distribution. +* Do ``twine upload dist/* --repository-url https://test.pypi.org/legacy/ -u PYPI_USERNAME -p PYPI_PASSWORD`` to upload it to the test instance of PyPI. + +## TestPyPI package verification +**Test ONNX itself** +* Test the PyPI package installation with different combinations of various Python versions, Protobuf versions and platforms. + * Python versions : Applicable python versions for the release. + * Protobuf versions : Latest protobuf version at the time of the release + protobuf version used for previous release + * Utilize the following matrix to check: + + |   | 3.5 | 3.6 | 3.7 | 3.8 | + -- | -- | -- | -- | -- | + Linux |   |   |   |   | + Windows |   |   |   |   | + Mac |   |   |   |   | + + +* After installing the PyPI package, run `pytest` in the release branch. + +**Partner Validation** + + * Test with onnxruntime package: To test the interaction with onnxruntime, use ONNX functions like `load`, `checker.check_model`, `shape_inference.infer_shapes`, `save` with onnxruntime functions like `InferenceSession` and `InferenceSession.run` on certain example ONNX model. For example, run the test script from [test_with_ort.py](../onnx/test/test_with_ort.py) with installed onnxruntime package. + + * Test with ONNX converters: Create GitHub issues in converters repos to provide them the package links and have them test the TestPyPI packages. + * https://github.com/pytorch/pytorch + * https://github.com/onnx/onnx-tensorflow + * https://github.com/onnx/tensorflow-onnx + * https://github.com/onnx/sklearn-onnx + * https://github.com/onnx/onnxmltools + * https://github.com/onnx/keras-onnx + * https://github.com/onnx/onnx-tensorrt + * https://github.com/onnx/onnx-coreml + + +**Source distribution verification** +* Test the source distribution by doing ``pip install --index-url https://test.pypi.org/simple --no-binary onnx onnx`` in a new environment. + +## Upload to official PyPI +**NOTE: Once the packages are uploaded to PyPI, you cannot overwrite it on the same PyPI instance. Please make sure everything is good on TestPyPI before uploading to PyPI** + +**Wheels** +* Windows/Linux/Mac + * Same as TestPyPI, use `twine upload --verbose *.whl --repository-url https://upload.pypi.org/legacy/ -u PYPI_USERNAME -p PYPI_PASSWORD` instead. + +**Source Distribution** +* Follow the same process in TestPyPI to produce the source distribution. +* Use ``twine upload --verbose dist/* --repository-url https://upload.pypi.org/legacy/`` instead to upload to the official PyPI. +* Test with ``pip install --no-binary onnx onnx`` + +## After PyPI Release + +**Release summary** +* Upload the source distribution, `.tar.gz` and `.zip`, in the release summary. +* Create release in github with the right tag and upload the release summary along with .tar.gz and .zip + +**Announce** +* Announce in slack, for instance, `onnx-general` channel. +* Notify ONNX partners like converter team and runtime team. +* Create a news by updating `js/news.json` to announce ONNX release under [onnx/onnx.github.io](https://github.com/onnx/onnx.github.io) repo. For instance: https://github.com/onnx/onnx.github.io/pull/83. + +**Update conda-forge package with the new ONNX version** +* Conda builds of ONNX are done via conda-forge, which runs infrastructure for building packages and uploading them to conda-forge. If it does not happen automatically, you need to submit a PR to https://github.com/conda-forge/onnx-feedstock (see https://github.com/conda-forge/onnx-feedstock/pull/1/files or https://github.com/conda-forge/onnx-feedstock/pull/50/files for example PRs) You will need to have uploaded to PyPI already, and update the version number and tarball hash of the PyPI uploaded tarball. + +**Merge into main branch** +* After everything above is done, merge the release branch into the main branch to make it consistent. + +## TODO list for next release +* Remove `onnx.optimizer` in ONNX 1.9 +* Be aware of protobuf version gap issue (like building onnx with protobuf>=3.12 is not compatible with older protobuf) +* (Optional) Deprecate Python 3.5 and add Python 3.9. +* (Optional) Automatically upload created wheels for Windows diff --git a/_doc/sphinxdoc/source/onnxmd/onnx_docs/OpConventions.md b/_doc/sphinxdoc/source/onnxmd/onnx_docs/OpConventions.md new file mode 100644 index 00000000..ac4e5316 --- /dev/null +++ b/_doc/sphinxdoc/source/onnxmd/onnx_docs/OpConventions.md @@ -0,0 +1,12 @@ + + +# Operator Conventions + +To maintain consistency in operator signatures, we use the following principles: +- All attribute names should be lower case and use underscores when it helps with readability +- Any input/output represented by a single letter is capitalized (i.e. X) +- Any input/output represented by a full word or multiple words is all lower case and uses underscores when it helps with readability +- Any input/output representing a bias tensor will utilize the name "B" +- Any input/output representing a weight tensor will utilize the name “W” +- “axes” is used when an input, output or attribute is representing multiple axes +- “axis” is used when an input, output or attribute is representing a single axis diff --git a/_doc/sphinxdoc/source/onnxmd/onnx_docs/Operators-ml.md b/_doc/sphinxdoc/source/onnxmd/onnx_docs/Operators-ml.md new file mode 100644 index 00000000..fc08f5a9 --- /dev/null +++ b/_doc/sphinxdoc/source/onnxmd/onnx_docs/Operators-ml.md @@ -0,0 +1,961 @@ + +## Operator Schemas +*This file is automatically generated from the + [def files](/onnx/defs) via [this script](/onnx/defs/gen_doc.py). + Do not modify directly and instead edit operator definitions.* + +For an operator input/output's differentiability, it can be differentiable, + non-differentiable, or undefined. If a variable's differentiability + is not specified, that variable has undefined differentiability. + +### ai.onnx.ml +|**Operator**|**Since version**| +|-|-| +|ai.onnx.ml.ArrayFeatureExtractor|1| +|ai.onnx.ml.Binarizer|1| +|ai.onnx.ml.CastMap|1| +|ai.onnx.ml.CategoryMapper|1| +|ai.onnx.ml.DictVectorizer|1| +|ai.onnx.ml.FeatureVectorizer|1| +|ai.onnx.ml.Imputer|1| +|ai.onnx.ml.LabelEncoder|2, 1| +|ai.onnx.ml.LinearClassifier|1| +|ai.onnx.ml.LinearRegressor|1| +|ai.onnx.ml.Normalizer|1| +|ai.onnx.ml.OneHotEncoder|1| +|ai.onnx.ml.SVMClassifier|1| +|ai.onnx.ml.SVMRegressor|1| +|ai.onnx.ml.Scaler|1| +|ai.onnx.ml.TreeEnsembleClassifier|1| +|ai.onnx.ml.TreeEnsembleRegressor|1| +|ai.onnx.ml.ZipMap|1| + + +## ai.onnx.ml +### **ai.onnx.ml.ArrayFeatureExtractor** + + Select elements of the input tensor based on the indices passed.
+ The indices are applied to the last axes of the tensor. + +#### Version + +This version of the operator has been available since version 1 of the 'ai.onnx.ml' operator set. + +#### Inputs + +
+
X : T
+
Data to be selected
+
Y : tensor(int64)
+
The indices, based on 0 as the first index of any dimension.
+
+ +#### Outputs + +
+
Z : T
+
Selected output data as an array
+
+ +#### Type Constraints + +
+
T : tensor(float), tensor(double), tensor(int64), tensor(int32), tensor(string)
+
The input must be a tensor of a numeric type or string. The output will be of the same tensor type.
+
+ + +### **ai.onnx.ml.Binarizer** + + Maps the values of the input tensor to either 0 or 1, element-wise, based on the outcome of a comparison against a threshold value. + +#### Version + +This version of the operator has been available since version 1 of the 'ai.onnx.ml' operator set. + +#### Attributes + +
+
threshold : float (default is 0.0)
+
Values greater than this are mapped to 1, others to 0.
+
+ +#### Inputs + +
+
X : T
+
Data to be binarized
+
+ +#### Outputs + +
+
Y : T
+
Binarized output data
+
+ +#### Type Constraints + +
+
T : tensor(float), tensor(double), tensor(int64), tensor(int32)
+
The input must be a tensor of a numeric type. The output will be of the same tensor type.
+
+ + +### **ai.onnx.ml.CastMap** + + Converts a map to a tensor.
The map key must be an int64 and the values will be ordered + in ascending order based on this key.
The operator supports dense packing or sparse packing. + If using sparse packing, the key cannot exceed the max_map-1 value. + +#### Version + +This version of the operator has been available since version 1 of the 'ai.onnx.ml' operator set. + +#### Attributes + +
+
cast_to : string (default is TO_FLOAT)
+
A string indicating the desired element type of the output tensor, one of 'TO_FLOAT', 'TO_STRING', 'TO_INT64'.
+
map_form : string (default is DENSE)
+
Indicates whether to only output as many values as are in the input (dense), or position the input based on using the key of the map as the index of the output (sparse).
One of 'DENSE', 'SPARSE'.
+
max_map : int (default is 1)
+
If the value of map_form is 'SPARSE,' this attribute indicates the total length of the output tensor.
+
+ +#### Inputs + +
+
X : T1
+
The input map that is to be cast to a tensor
+
+ +#### Outputs + +
+
Y : T2
+
A tensor representing the same data as the input map, ordered by their keys
+
+ +#### Type Constraints + +
+
T1 : map(int64, string), map(int64, float)
+
The input must be an integer map to either string or float.
+
T2 : tensor(string), tensor(float), tensor(int64)
+
The output is a 1-D tensor of string, float, or integer.
+
+ + +### **ai.onnx.ml.CategoryMapper** + + Converts strings to integers and vice versa.
+ Two sequences of equal length are used to map between integers and strings, + with strings and integers at the same index detailing the mapping.
+ Each operator converts either integers to strings or strings to integers, depending + on which default value attribute is provided. Only one default value attribute + should be defined.
+ If the string default value is set, it will convert integers to strings. + If the int default value is set, it will convert strings to integers. + +#### Version + +This version of the operator has been available since version 1 of the 'ai.onnx.ml' operator set. + +#### Attributes + +
+
cats_int64s : list of ints
+
The integers of the map. This sequence must be the same length as the 'cats_strings' sequence.
+
cats_strings : list of strings
+
The strings of the map. This sequence must be the same length as the 'cats_int64s' sequence
+
default_int64 : int (default is -1)
+
An integer to use when an input string value is not found in the map.
One and only one of the 'default_*' attributes must be defined.
+
default_string : string (default is _Unused)
+
A string to use when an input integer value is not found in the map.
One and only one of the 'default_*' attributes must be defined.
+
+ +#### Inputs + +
+
X : T1
+
Input data
+
+ +#### Outputs + +
+
Y : T2
+
Output data. If strings are input, the output values are integers, and vice versa.
+
+ +#### Type Constraints + +
+
T1 : tensor(string), tensor(int64)
+
The input must be a tensor of strings or integers, either [N,C] or [C].
+
T2 : tensor(string), tensor(int64)
+
The output is a tensor of strings or integers. Its shape will be the same as the input shape.
+
+ + +### **ai.onnx.ml.DictVectorizer** + + Uses an index mapping to convert a dictionary to an array.
+ Given a dictionary, each key is looked up in the vocabulary attribute corresponding to + the key type. The index into the vocabulary array at which the key is found is then + used to index the output 1-D tensor 'Y' and insert into it the value found in the dictionary 'X'.
+ The key type of the input map must correspond to the element type of the defined vocabulary attribute. + Therefore, the output array will be equal in length to the index mapping vector parameter. + All keys in the input dictionary must be present in the index mapping vector. + For each item in the input dictionary, insert its value in the output array. + Any keys not present in the input dictionary, will be zero in the output array.
+ For example: if the ``string_vocabulary`` parameter is set to ``["a", "c", "b", "z"]``, + then an input of ``{"a": 4, "c": 8}`` will produce an output of ``[4, 8, 0, 0]``. + + +#### Version + +This version of the operator has been available since version 1 of the 'ai.onnx.ml' operator set. + +#### Attributes + +
+
int64_vocabulary : list of ints
+
An integer vocabulary array.
One and only one of the vocabularies must be defined.
+
string_vocabulary : list of strings
+
A string vocabulary array.
One and only one of the vocabularies must be defined.
+
+ +#### Inputs + +
+
X : T1
+
A dictionary.
+
+ +#### Outputs + +
+
Y : T2
+
A 1-D tensor holding values from the input dictionary.
+
+ +#### Type Constraints + +
+
T1 : map(string, int64), map(int64, string), map(int64, float), map(int64, double), map(string, float), map(string, double)
+
The input must be a map from strings or integers to either strings or a numeric type. The key and value types cannot be the same.
+
T2 : tensor(int64), tensor(float), tensor(double), tensor(string)
+
The output will be a tensor of the value type of the input map. It's shape will be [1,C], where C is the length of the input dictionary.
+
+ + +### **ai.onnx.ml.FeatureVectorizer** + + Concatenates input tensors into one continuous output.
+ All input shapes are 2-D and are concatenated along the second dimention. 1-D tensors are treated as [1,C]. + Inputs are copied to the output maintaining the order of the input arguments.
+ All inputs must be integers or floats, while the output will be all floating point values. + +#### Version + +This version of the operator has been available since version 1 of the 'ai.onnx.ml' operator set. + +#### Attributes + +
+
inputdimensions : list of ints
+
The size of each input in the input list
+
+ +#### Inputs (1 - ∞) + +
+
X (variadic) : T1
+
An ordered collection of tensors, all with the same element type.
+
+ +#### Outputs + +
+
Y : tensor(float)
+
The output array, elements ordered as the inputs.
+
+ +#### Type Constraints + +
+
T1 : tensor(int32), tensor(int64), tensor(float), tensor(double)
+
The input type must be a tensor of a numeric type.
+
+ + +### **ai.onnx.ml.Imputer** + + Replaces inputs that equal one value with another, leaving all other elements alone.
+ This operator is typically used to replace missing values in situations where they have a canonical + representation, such as -1, 0, NaN, or some extreme value.
+ One and only one of imputed_value_floats or imputed_value_int64s should be defined -- floats if the input tensor + holds floats, integers if the input tensor holds integers. The imputed values must all fit within the + width of the tensor element type. One and only one of the replaced_value_float or replaced_value_int64 should be defined, + which one depends on whether floats or integers are being processed.
+ The imputed_value attribute length can be 1 element, or it can have one element per input feature.
In other words, if the input tensor has the shape [*,F], then the length of the attribute array may be 1 or F. If it is 1, then it is broadcast along the last dimension and applied to each feature. + +#### Version + +This version of the operator has been available since version 1 of the 'ai.onnx.ml' operator set. + +#### Attributes + +
+
imputed_value_floats : list of floats
+
Value(s) to change to
+
imputed_value_int64s : list of ints
+
Value(s) to change to.
+
replaced_value_float : float (default is 0.0)
+
A value that needs replacing.
+
replaced_value_int64 : int (default is 0)
+
A value that needs replacing.
+
+ +#### Inputs + +
+
X : T
+
Data to be processed.
+
+ +#### Outputs + +
+
Y : T
+
Imputed output data
+
+ +#### Type Constraints + +
+
T : tensor(float), tensor(double), tensor(int64), tensor(int32)
+
The input type must be a tensor of a numeric type, either [N,C] or [C]. The output type will be of the same tensor type and shape.
+
+ + +### **ai.onnx.ml.LabelEncoder** + + Maps each element in the input tensor to another value.
+ The mapping is determined by the two parallel attributes, 'keys_*' and + 'values_*' attribute. The i-th value in the specified 'keys_*' attribute + would be mapped to the i-th value in the specified 'values_*' attribute. It + implies that input's element type and the element type of the specified + 'keys_*' should be identical while the output type is identical to the + specified 'values_*' attribute. If an input element can not be found in the + specified 'keys_*' attribute, the 'default_*' that matches the specified + 'values_*' attribute may be used as its output value.
+ Let's consider an example which maps a string tensor to an integer tensor. + Assume and 'keys_strings' is ["Amy", "Sally"], 'values_int64s' is [5, 6], + and 'default_int64' is '-1'. The input ["Dori", "Amy", "Amy", "Sally", + "Sally"] would be mapped to [-1, 5, 5, 6, 6].
+ Since this operator is an one-to-one mapping, its input and output shapes + are the same. Notice that only one of 'keys_*'/'values_*' can be set.
+ For key look-up, bit-wise comparison is used so even a float NaN can be + mapped to a value in 'values_*' attribute.
+ +#### Version + +This version of the operator has been available since version 2 of the 'ai.onnx.ml' operator set. + +Other versions of this operator: 1 + +#### Attributes + +
+
default_float : float (default is -0.0)
+
A float.
+
default_int64 : int (default is -1)
+
An integer.
+
default_string : string (default is _Unused)
+
A string.
+
keys_floats : list of floats
+
A list of floats.
+
keys_int64s : list of ints
+
A list of ints.
+
keys_strings : list of strings
+
A list of strings. One and only one of 'keys_*'s should be set.
+
values_floats : list of floats
+
A list of floats.
+
values_int64s : list of ints
+
A list of ints.
+
values_strings : list of strings
+
A list of strings. One and only one of 'value_*'s should be set.
+
+ +#### Inputs + +
+
X : T1
+
Input data. It can be either tensor or scalar.
+
+ +#### Outputs + +
+
Y : T2
+
Output data.
+
+ +#### Type Constraints + +
+
T1 : tensor(string), tensor(int64), tensor(float)
+
The input type is a tensor of any shape.
+
T2 : tensor(string), tensor(int64), tensor(float)
+
Output type is determined by the specified 'values_*' attribute.
+
+ + +### **ai.onnx.ml.LinearClassifier** + + Linear classifier + +#### Version + +This version of the operator has been available since version 1 of the 'ai.onnx.ml' operator set. + +#### Attributes + +
+
classlabels_ints : list of ints
+
Class labels when using integer labels. One and only one 'classlabels' attribute must be defined.
+
classlabels_strings : list of strings
+
Class labels when using string labels. One and only one 'classlabels' attribute must be defined.
+
coefficients : list of floats (required)
+
A collection of weights of the model(s).
+
intercepts : list of floats
+
A collection of intercepts.
+
multi_class : int (default is 0)
+
Indicates whether to do OvR or multinomial (0=OvR is the default).
+
post_transform : string (default is NONE)
+
Indicates the transform to apply to the scores vector.
One of 'NONE,' 'SOFTMAX,' 'LOGISTIC,' 'SOFTMAX_ZERO,' or 'PROBIT'
+
+ +#### Inputs + +
+
X : T1
+
Data to be classified.
+
+ +#### Outputs + +
+
Y : T2
+
Classification outputs (one class per example).
+
Z : tensor(float)
+
Classification scores ([N,E] - one score for each class and example
+
+ +#### Type Constraints + +
+
T1 : tensor(float), tensor(double), tensor(int64), tensor(int32)
+
The input must be a tensor of a numeric type, and of of shape [N,C] or [C]. In the latter case, it will be treated as [1,C]
+
T2 : tensor(string), tensor(int64)
+
The output will be a tensor of strings or integers.
+
+ + +### **ai.onnx.ml.LinearRegressor** + + Generalized linear regression evaluation.
+ If targets is set to 1 (default) then univariate regression is performed.
+ If targets is set to M then M sets of coefficients must be passed in as a sequence + and M results will be output for each input n in N.
+ The coefficients array is of length n, and the coefficients for each target are contiguous. + Intercepts are optional but if provided must match the number of targets. + +#### Version + +This version of the operator has been available since version 1 of the 'ai.onnx.ml' operator set. + +#### Attributes + +
+
coefficients : list of floats
+
Weights of the model(s).
+
intercepts : list of floats
+
Weights of the intercepts, if used.
+
post_transform : string (default is NONE)
+
Indicates the transform to apply to the regression output vector.
One of 'NONE,' 'SOFTMAX,' 'LOGISTIC,' 'SOFTMAX_ZERO,' or 'PROBIT'
+
targets : int (default is 1)
+
The total number of regression targets, 1 if not defined.
+
+ +#### Inputs + +
+
X : T
+
Data to be regressed.
+
+ +#### Outputs + +
+
Y : tensor(float)
+
Regression outputs (one per target, per example).
+
+ +#### Type Constraints + +
+
T : tensor(float), tensor(double), tensor(int64), tensor(int32)
+
The input must be a tensor of a numeric type.
+
+ + +### **ai.onnx.ml.Normalizer** + + Normalize the input. There are three normalization modes, which have the corresponding formulas, + defined using element-wise infix operators '/' and '^' and tensor-wide functions 'max' and 'sum':
+
+ Max: Y = X / max(X)
+ L1: Y = X / sum(X)
+ L2: Y = sqrt(X^2 / sum(X^2)}
+ In all modes, if the divisor is zero, Y == X. +
+ For batches, that is, [N,C] tensors, normalization is done along the C axis. In other words, each row + of the batch is normalized independently. + +#### Version + +This version of the operator has been available since version 1 of the 'ai.onnx.ml' operator set. + +#### Attributes + +
+
norm : string (default is MAX)
+
One of 'MAX,' 'L1,' 'L2'
+
+ +#### Inputs + +
+
X : T
+
Data to be encoded, a tensor of shape [N,C] or [C]
+
+ +#### Outputs + +
+
Y : tensor(float)
+
Encoded output data
+
+ +#### Type Constraints + +
+
T : tensor(float), tensor(double), tensor(int64), tensor(int32)
+
The input must be a tensor of a numeric type.
+
+ + +### **ai.onnx.ml.OneHotEncoder** + + Replace each input element with an array of ones and zeros, where a single + one is placed at the index of the category that was passed in. The total category count + will determine the size of the extra dimension of the output array Y.
+ For example, if we pass a tensor with a single value of 4, and a category count of 8, + the output will be a tensor with ``[0,0,0,0,1,0,0,0]``.
+ This operator assumes every input feature is from the same set of categories.
+ If the input is a tensor of float, int32, or double, the data will be cast + to integers and the cats_int64s category list will be used for the lookups. + +#### Version + +This version of the operator has been available since version 1 of the 'ai.onnx.ml' operator set. + +#### Attributes + +
+
cats_int64s : list of ints
+
List of categories, ints.
One and only one of the 'cats_*' attributes must be defined.
+
cats_strings : list of strings
+
List of categories, strings.
One and only one of the 'cats_*' attributes must be defined.
+
zeros : int (default is 1)
+
If true and category is not present, will return all zeros; if false and a category if not found, the operator will fail.
+
+ +#### Inputs + +
+
X : T
+
Data to be encoded.
+
+ +#### Outputs + +
+
Y : tensor(float)
+
Encoded output data, having one more dimension than X.
+
+ +#### Type Constraints + +
+
T : tensor(string), tensor(int64), tensor(int32), tensor(float), tensor(double)
+
The input must be a tensor of a numeric type.
+
+ + +### **ai.onnx.ml.SVMClassifier** + + Support Vector Machine classifier + +#### Version + +This version of the operator has been available since version 1 of the 'ai.onnx.ml' operator set. + +#### Attributes + +
+
classlabels_ints : list of ints
+
Class labels if using integer labels.
One and only one of the 'classlabels_*' attributes must be defined.
+
classlabels_strings : list of strings
+
Class labels if using string labels.
One and only one of the 'classlabels_*' attributes must be defined.
+
coefficients : list of floats
+
+
kernel_params : list of floats
+
List of 3 elements containing gamma, coef0, and degree, in that order. Zero if unused for the kernel.
+
kernel_type : string (default is LINEAR)
+
The kernel type, one of 'LINEAR,' 'POLY,' 'RBF,' 'SIGMOID'.
+
post_transform : string (default is NONE)
+
Indicates the transform to apply to the score.
One of 'NONE,' 'SOFTMAX,' 'LOGISTIC,' 'SOFTMAX_ZERO,' or 'PROBIT'
+
prob_a : list of floats
+
First set of probability coefficients.
+
prob_b : list of floats
+
Second set of probability coefficients. This array must be same size as prob_a.
If these are provided then output Z are probability estimates, otherwise they are raw scores.
+
rho : list of floats
+
+
support_vectors : list of floats
+
+
vectors_per_class : list of ints
+
+
+ +#### Inputs + +
+
X : T1
+
Data to be classified.
+
+ +#### Outputs + +
+
Y : T2
+
Classification outputs (one class per example).
+
Z : tensor(float)
+
Class scores (one per class per example), if prob_a and prob_b are provided they are probabilities for each class, otherwise they are raw scores.
+
+ +#### Type Constraints + +
+
T1 : tensor(float), tensor(double), tensor(int64), tensor(int32)
+
The input must be a tensor of a numeric type, either [C] or [N,C].
+
T2 : tensor(string), tensor(int64)
+
The output type will be a tensor of strings or integers, depending on which of the the classlabels_* attributes is used. Its size will match the bactch size of the input.
+
+ + +### **ai.onnx.ml.SVMRegressor** + + Support Vector Machine regression prediction and one-class SVM anomaly detection. + +#### Version + +This version of the operator has been available since version 1 of the 'ai.onnx.ml' operator set. + +#### Attributes + +
+
coefficients : list of floats
+
Support vector coefficients.
+
kernel_params : list of floats
+
List of 3 elements containing gamma, coef0, and degree, in that order. Zero if unused for the kernel.
+
kernel_type : string (default is LINEAR)
+
The kernel type, one of 'LINEAR,' 'POLY,' 'RBF,' 'SIGMOID'.
+
n_supports : int (default is 0)
+
The number of support vectors.
+
one_class : int (default is 0)
+
Flag indicating whether the regression is a one-class SVM or not.
+
post_transform : string (default is NONE)
+
Indicates the transform to apply to the score.
One of 'NONE,' 'SOFTMAX,' 'LOGISTIC,' 'SOFTMAX_ZERO,' or 'PROBIT.'
+
rho : list of floats
+
+
support_vectors : list of floats
+
Chosen support vectors
+
+ +#### Inputs + +
+
X : T
+
Data to be regressed.
+
+ +#### Outputs + +
+
Y : tensor(float)
+
Regression outputs (one score per target per example).
+
+ +#### Type Constraints + +
+
T : tensor(float), tensor(double), tensor(int64), tensor(int32)
+
The input type must be a tensor of a numeric type, either [C] or [N,C].
+
+ + +### **ai.onnx.ml.Scaler** + + Rescale input data, for example to standardize features by removing the mean and scaling to unit variance. + +#### Version + +This version of the operator has been available since version 1 of the 'ai.onnx.ml' operator set. + +#### Attributes + +
+
offset : list of floats
+
First, offset by this.
Can be length of features in an [N,F] tensor or length 1, in which case it applies to all features, regardless of dimension count.
+
scale : list of floats
+
Second, multiply by this.
Can be length of features in an [N,F] tensor or length 1, in which case it applies to all features, regardless of dimension count.
Must be same length as 'offset'
+
+ +#### Inputs + +
+
X : T
+
Data to be scaled.
+
+ +#### Outputs + +
+
Y : tensor(float)
+
Scaled output data.
+
+ +#### Type Constraints + +
+
T : tensor(float), tensor(double), tensor(int64), tensor(int32)
+
The input must be a tensor of a numeric type.
+
+ + +### **ai.onnx.ml.TreeEnsembleClassifier** + + Tree Ensemble classifier. Returns the top class for each of N inputs.
+ The attributes named 'nodes_X' form a sequence of tuples, associated by + index into the sequences, which must all be of equal length. These tuples + define the nodes.
+ Similarly, all fields prefixed with 'class_' are tuples of votes at the leaves. + A leaf may have multiple votes, where each vote is weighted by + the associated class_weights index.
+ One and only one of classlabels_strings or classlabels_int64s + will be defined. The class_ids are indices into this list. + +#### Version + +This version of the operator has been available since version 1 of the 'ai.onnx.ml' operator set. + +#### Attributes + +
+
base_values : list of floats
+
Base values for classification, added to final class score; the size must be the same as the classes or can be left unassigned (assumed 0)
+
class_ids : list of ints
+
The index of the class list that each weight is for.
+
class_nodeids : list of ints
+
node id that this weight is for.
+
class_treeids : list of ints
+
The id of the tree that this node is in.
+
class_weights : list of floats
+
The weight for the class in class_id.
+
classlabels_int64s : list of ints
+
Class labels if using integer labels.
One and only one of the 'classlabels_*' attributes must be defined.
+
classlabels_strings : list of strings
+
Class labels if using string labels.
One and only one of the 'classlabels_*' attributes must be defined.
+
nodes_falsenodeids : list of ints
+
Child node if expression is false.
+
nodes_featureids : list of ints
+
Feature id for each node.
+
nodes_hitrates : list of floats
+
Popularity of each node, used for performance and may be omitted.
+
nodes_missing_value_tracks_true : list of ints
+
For each node, define what to do in the presence of a missing value: if a value is missing (NaN), use the 'true' or 'false' branch based on the value in this array.
This attribute may be left undefined, and the defalt value is false (0) for all nodes.
+
nodes_modes : list of strings
+
The node kind, that is, the comparison to make at the node. There is no comparison to make at a leaf node.
One of 'BRANCH_LEQ', 'BRANCH_LT', 'BRANCH_GTE', 'BRANCH_GT', 'BRANCH_EQ', 'BRANCH_NEQ', 'LEAF'
+
nodes_nodeids : list of ints
+
Node id for each node. Ids may restart at zero for each tree, but it not required to.
+
nodes_treeids : list of ints
+
Tree id for each node.
+
nodes_truenodeids : list of ints
+
Child node if expression is true.
+
nodes_values : list of floats
+
Thresholds to do the splitting on for each node.
+
post_transform : string (default is NONE)
+
Indicates the transform to apply to the score.
One of 'NONE,' 'SOFTMAX,' 'LOGISTIC,' 'SOFTMAX_ZERO,' or 'PROBIT.'
+
+ +#### Inputs + +
+
X : T1
+
Input of shape [N,F]
+
+ +#### Outputs + +
+
Y : T2
+
N, Top class for each point
+
Z : tensor(float)
+
The class score for each class, for each point, a tensor of shape [N,E].
+
+ +#### Type Constraints + +
+
T1 : tensor(float), tensor(double), tensor(int64), tensor(int32)
+
The input type must be a tensor of a numeric type.
+
T2 : tensor(string), tensor(int64)
+
The output type will be a tensor of strings or integers, depending on which of the the classlabels_* attributes is used.
+
+ + +### **ai.onnx.ml.TreeEnsembleRegressor** + + Tree Ensemble regressor. Returns the regressed values for each input in N.
+ All args with nodes_ are fields of a tuple of tree nodes, and + it is assumed they are the same length, and an index i will decode the + tuple across these inputs. Each node id can appear only once + for each tree id.
+ All fields prefixed with target_ are tuples of votes at the leaves.
+ A leaf may have multiple votes, where each vote is weighted by + the associated target_weights index.
+ All trees must have their node ids start at 0 and increment by 1.
+ Mode enum is BRANCH_LEQ, BRANCH_LT, BRANCH_GTE, BRANCH_GT, BRANCH_EQ, BRANCH_NEQ, LEAF + +#### Version + +This version of the operator has been available since version 1 of the 'ai.onnx.ml' operator set. + +#### Attributes + +
+
aggregate_function : string (default is SUM)
+
Defines how to aggregate leaf values within a target.
One of 'AVERAGE,' 'SUM,' 'MIN,' 'MAX.'
+
base_values : list of floats
+
Base values for classification, added to final class score; the size must be the same as the classes or can be left unassigned (assumed 0)
+
n_targets : int
+
The total number of targets.
+
nodes_falsenodeids : list of ints
+
Child node if expression is false
+
nodes_featureids : list of ints
+
Feature id for each node.
+
nodes_hitrates : list of floats
+
Popularity of each node, used for performance and may be omitted.
+
nodes_missing_value_tracks_true : list of ints
+
For each node, define what to do in the presence of a NaN: use the 'true' (if the attribute value is 1) or 'false' (if the attribute value is 0) branch based on the value in this array.
This attribute may be left undefined and the defalt value is false (0) for all nodes.
+
nodes_modes : list of strings
+
The node kind, that is, the comparison to make at the node. There is no comparison to make at a leaf node.
One of 'BRANCH_LEQ', 'BRANCH_LT', 'BRANCH_GTE', 'BRANCH_GT', 'BRANCH_EQ', 'BRANCH_NEQ', 'LEAF'
+
nodes_nodeids : list of ints
+
Node id for each node. Node ids must restart at zero for each tree and increase sequentially.
+
nodes_treeids : list of ints
+
Tree id for each node.
+
nodes_truenodeids : list of ints
+
Child node if expression is true
+
nodes_values : list of floats
+
Thresholds to do the splitting on for each node.
+
post_transform : string (default is NONE)
+
Indicates the transform to apply to the score.
One of 'NONE,' 'SOFTMAX,' 'LOGISTIC,' 'SOFTMAX_ZERO,' or 'PROBIT'
+
target_ids : list of ints
+
The index of the target that each weight is for
+
target_nodeids : list of ints
+
The node id of each weight
+
target_treeids : list of ints
+
The id of the tree that each node is in.
+
target_weights : list of floats
+
The weight for each target
+
+ +#### Inputs + +
+
X : T
+
Input of shape [N,F]
+
+ +#### Outputs + +
+
Y : tensor(float)
+
N classes
+
+ +#### Type Constraints + +
+
T : tensor(float), tensor(double), tensor(int64), tensor(int32)
+
The input type must be a tensor of a numeric type.
+
+ + +### **ai.onnx.ml.ZipMap** + + Creates a map from the input and the attributes.
+ The values are provided by the input tensor, while the keys are specified by the attributes. + Must provide keys in either classlabels_strings or classlabels_int64s (but not both).
+ The columns of the tensor correspond one-by-one to the keys specified by the attributes. There must be as many columns as keys.
+ +#### Version + +This version of the operator has been available since version 1 of the 'ai.onnx.ml' operator set. + +#### Attributes + +
+
classlabels_int64s : list of ints
+
The keys when using int keys.
One and only one of the 'classlabels_*' attributes must be defined.
+
classlabels_strings : list of strings
+
The keys when using string keys.
One and only one of the 'classlabels_*' attributes must be defined.
+
+ +#### Inputs + +
+
X : tensor(float)
+
The input values
+
+ +#### Outputs + +
+
Z : T
+
The output map
+
+ +#### Type Constraints + +
+
T : seq(map(string, float)), seq(map(int64, float))
+
The output will be a sequence of string or integer maps to float.
+
+ + diff --git a/_doc/sphinxdoc/source/onnxmd/onnx_docs/Operators.md b/_doc/sphinxdoc/source/onnxmd/onnx_docs/Operators.md new file mode 100644 index 00000000..365a35aa --- /dev/null +++ b/_doc/sphinxdoc/source/onnxmd/onnx_docs/Operators.md @@ -0,0 +1,25630 @@ + +## Operator Schemas +*This file is automatically generated from the + [def files](/onnx/defs) via [this script](/onnx/defs/gen_doc.py). + Do not modify directly and instead edit operator definitions.* + +For an operator input/output's differentiability, it can be differentiable, + non-differentiable, or undefined. If a variable's differentiability + is not specified, that variable has undefined differentiability. + +### ai.onnx (default) +|**Operator**|**Since version**| +|-|-| +|Abs|13, 6, 1| +|Acos|7| +|Acosh|9| +|Add|14, 13, 7, 6, 1| +|And|7, 1| +|ArgMax|13, 12, 11, 1| +|ArgMin|13, 12, 11, 1| +|Asin|7| +|Asinh|9| +|Atan|7| +|Atanh|9| +|AveragePool|11, 10, 7, 1| +|BatchNormalization|15, 14, 9, 7, 6, 1| +|BitShift|11| +|Cast|13, 9, 6, 1| +|Ceil|13, 6, 1| +|Clip|13, 12, 11, 6, 1| +|Compress|11, 9| +|Concat|13, 11, 4, 1| +|ConcatFromSequence|11| +|Constant|13, 12, 11, 9, 1| +|ConstantOfShape|9| +|Conv|11, 1| +|ConvInteger|10| +|ConvTranspose|11, 1| +|Cos|7| +|Cosh|9| +|CumSum|14, 11| +|DepthToSpace|13, 11, 1| +|DequantizeLinear|13, 10| +|Det|11| +|Div|14, 13, 7, 6, 1| +|Dropout|13, 12, 10, 7, 6, 1| +|Einsum|12| +|Elu|6, 1| +|Equal|13, 11, 7, 1| +|Erf|13, 9| +|Exp|13, 6, 1| +|Expand|13, 8| +|EyeLike|9| +|Flatten|13, 11, 9, 1| +|Floor|13, 6, 1| +|GRU|14, 7, 3, 1| +|Gather|13, 11, 1| +|GatherElements|13, 11| +|GatherND|13, 12, 11| +|Gemm|13, 11, 9, 7, 6, 1| +|GlobalAveragePool|1| +|GlobalLpPool|2, 1| +|GlobalMaxPool|1| +|Greater|13, 9, 7, 1| +|GridSample|16| +|HardSigmoid|6, 1| +|Hardmax|13, 11, 1| +|Identity|16, 14, 13, 1| +|If|16, 13, 11, 1| +|InstanceNormalization|6, 1| +|IsInf|10| +|IsNaN|13, 9| +|LRN|13, 1| +|LSTM|14, 7, 1| +|LeakyRelu|6, 1| +|Less|13, 9, 7, 1| +|Log|13, 6, 1| +|Loop|16, 13, 11, 1| +|LpNormalization|1| +|LpPool|11, 2, 1| +|MatMul|13, 9, 1| +|MatMulInteger|10| +|Max|13, 12, 8, 6, 1| +|MaxPool|12, 11, 10, 8, 1| +|MaxRoiPool|1| +|MaxUnpool|11, 9| +|Mean|13, 8, 6, 1| +|Min|13, 12, 8, 6, 1| +|Mod|13, 10| +|Mul|14, 13, 7, 6, 1| +|Multinomial|7| +|Neg|13, 6, 1| +|NonMaxSuppression|11, 10| +|NonZero|13, 9| +|Not|1| +|OneHot|11, 9| +|Optional|15| +|OptionalGetElement|15| +|OptionalHasElement|15| +|Or|7, 1| +|PRelu|9, 7, 6, 1| +|Pad|13, 11, 2, 1| +|Pow|15, 13, 12, 7, 1| +|QLinearConv|10| +|QLinearMatMul|10| +|QuantizeLinear|13, 10| +|RNN|14, 7, 1| +|RandomNormal|1| +|RandomNormalLike|1| +|RandomUniform|1| +|RandomUniformLike|1| +|Reciprocal|13, 6, 1| +|ReduceL1|13, 11, 1| +|ReduceL2|13, 11, 1| +|ReduceLogSum|13, 11, 1| +|ReduceLogSumExp|13, 11, 1| +|ReduceMax|13, 12, 11, 1| +|ReduceMean|13, 11, 1| +|ReduceMin|13, 12, 11, 1| +|ReduceProd|13, 11, 1| +|ReduceSum|13, 11, 1| +|ReduceSumSquare|13, 11, 1| +|Relu|14, 13, 6, 1| +|Reshape|14, 13, 5, 1| +|Resize|13, 11, 10| +|ReverseSequence|10| +|RoiAlign|16, 10| +|Round|11| +|Scan|11, 9, 8| +|Scatter (deprecated)|11, 9| +|ScatterElements|16, 13, 11| +|ScatterND|16, 13, 11| +|Selu|6, 1| +|SequenceAt|11| +|SequenceConstruct|11| +|SequenceEmpty|11| +|SequenceErase|11| +|SequenceInsert|11| +|SequenceLength|11| +|Shape|15, 13, 1| +|Shrink|9| +|Sigmoid|13, 6, 1| +|Sign|13, 9| +|Sin|7| +|Sinh|9| +|Size|13, 1| +|Slice|13, 11, 10, 1| +|Softplus|1| +|Softsign|1| +|SpaceToDepth|13, 1| +|Split|13, 11, 2, 1| +|SplitToSequence|11| +|Sqrt|13, 6, 1| +|Squeeze|13, 11, 1| +|StringNormalizer|10| +|Sub|14, 13, 7, 6, 1| +|Sum|13, 8, 6, 1| +|Tan|7| +|Tanh|13, 6, 1| +|TfIdfVectorizer|9| +|ThresholdedRelu|10| +|Tile|13, 6, 1| +|TopK|11, 10, 1| +|Transpose|13, 1| +|Trilu|14| +|Unique|11| +|Unsqueeze|13, 11, 1| +|Upsample (deprecated)|10, 9, 7| +|Where|16, 9| +|Xor|7, 1| +|**Function**|**Since version**| +|Bernoulli|15| +|CastLike|15| +|Celu|12| +|DynamicQuantizeLinear|11| +|GreaterOrEqual|12| +|HardSwish|14| +|LessOrEqual|12| +|LogSoftmax|13, 11, 1| +|MeanVarianceNormalization|13, 9| +|NegativeLogLikelihoodLoss|13, 12| +|Range|11| +|Softmax|13, 11, 1| +|SoftmaxCrossEntropyLoss|13, 12| + +### ai.onnx.preview.training +|**Operator**|**Since version**| +|-|-| +|ai.onnx.preview.training.Adagrad|1| +|ai.onnx.preview.training.Adam|1| +|ai.onnx.preview.training.Gradient|1| +|ai.onnx.preview.training.Momentum|1| + + +## ai.onnx (default) +### **Abs** + + Absolute takes one input data (Tensor) and produces one output data + (Tensor) where the absolute is, y = abs(x), is applied to + the tensor elementwise. + +#### Version + +This version of the operator has been available since version 13 of the default ONNX operator set. + +Other versions of this operator: 1, 6 + +#### Inputs + +
+
X (differentiable) : T
+
Input tensor
+
+ +#### Outputs + +
+
Y (differentiable) : T
+
Output tensor
+
+ +#### Type Constraints + +
+
T : tensor(uint8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(int8), tensor(int16), tensor(int32), tensor(int64), tensor(float16), tensor(float), tensor(double), tensor(bfloat16)
+
Constrain input and output types to all numeric tensors.
+
+ + +#### Examples + +
+abs + +```python +node = onnx.helper.make_node( + 'Abs', + inputs=['x'], + outputs=['y'], +) +x = np.random.randn(3, 4, 5).astype(np.float32) +y = abs(x) + +expect(node, inputs=[x], outputs=[y], + name='test_abs') +``` + +
+ + +#### Sample Implementation + +
+Abs + +```python +# SPDX-License-Identifier: Apache-2.0 + +from __future__ import absolute_import +from __future__ import division +from __future__ import print_function +from __future__ import unicode_literals + +import numpy as np # type: ignore + + +def abs(input): # type: (np.ndarray) -> np.ndarray + return np.abs(input) + +``` + +
+ + +### **Acos** + + Calculates the arccosine (inverse of cosine) of the given input tensor, element-wise. + +#### Version + +This version of the operator has been available since version 7 of the default ONNX operator set. + +#### Inputs + +
+
input (differentiable) : T
+
Input tensor
+
+ +#### Outputs + +
+
output (differentiable) : T
+
The arccosine of the input tensor computed element-wise
+
+ +#### Type Constraints + +
+
T : tensor(float16), tensor(float), tensor(double)
+
Constrain input and output types to float tensors.
+
+ + +#### Examples + +
+acos + +```python +node = onnx.helper.make_node( + 'Acos', + inputs=['x'], + outputs=['y'], +) + +x = np.array([-0.5, 0, 0.5]).astype(np.float32) +y = np.arccos(x) +expect(node, inputs=[x], outputs=[y], + name='test_acos_example') + +x = np.random.rand(3, 4, 5).astype(np.float32) +y = np.arccos(x) +expect(node, inputs=[x], outputs=[y], + name='test_acos') +``` + +
+ + +### **Acosh** + + Calculates the hyperbolic arccosine of the given input tensor element-wise. + +#### Version + +This version of the operator has been available since version 9 of the default ONNX operator set. + +#### Inputs + +
+
input (differentiable) : T
+
Input tensor
+
+ +#### Outputs + +
+
output (differentiable) : T
+
The hyperbolic arccosine values of the input tensor computed element-wise
+
+ +#### Type Constraints + +
+
T : tensor(float16), tensor(float), tensor(double)
+
Constrain input and output types to float tensors.
+
+ + +#### Examples + +
+acosh + +```python +node = onnx.helper.make_node( + 'Acosh', + inputs=['x'], + outputs=['y'], +) + +x = np.array([10, np.e, 1]).astype(np.float32) +y = np.arccosh(x) # expected output [2.99322295, 1.65745449, 0.] +expect(node, inputs=[x], outputs=[y], + name='test_acosh_example') + +x = np.random.uniform(1.0, 10.0, (3, 4, 5)).astype(np.float32) +y = np.arccosh(x) +expect(node, inputs=[x], outputs=[y], + name='test_acosh') +``` + +
+ + +### **Add** + + Performs element-wise binary addition (with Numpy-style broadcasting support). + + This operator supports **multidirectional (i.e., Numpy-style) broadcasting**; for more details please check [the doc](Broadcasting.md). + + (Opset 14 change): Extend supported types to include uint8, int8, uint16, and int16. + +#### Version + +This version of the operator has been available since version 14 of the default ONNX operator set. + +Other versions of this operator: 1, 6, 7, 13 + +#### Inputs + +
+
A (differentiable) : T
+
First operand.
+
B (differentiable) : T
+
Second operand.
+
+ +#### Outputs + +
+
C (differentiable) : T
+
Result, has same element type as two inputs
+
+ +#### Type Constraints + +
+
T : tensor(uint8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(int8), tensor(int16), tensor(int32), tensor(int64), tensor(float16), tensor(float), tensor(double), tensor(bfloat16)
+
Constrain input and output types to all numeric tensors.
+
+ + +#### Examples + +
+add + +```python +node = onnx.helper.make_node( + 'Add', + inputs=['x', 'y'], + outputs=['sum'], +) + +x = np.random.randn(3, 4, 5).astype(np.float32) +y = np.random.randn(3, 4, 5).astype(np.float32) +expect(node, inputs=[x, y], outputs=[x + y], + name='test_add') +``` + +
+ + +
+add_broadcast + +```python +node = onnx.helper.make_node( + 'Add', + inputs=['x', 'y'], + outputs=['sum'], +) + +x = np.random.randn(3, 4, 5).astype(np.float32) +y = np.random.randn(5).astype(np.float32) +expect(node, inputs=[x, y], outputs=[x + y], + name='test_add_bcast') +``` + +
+ + +
+add_uint8 + +```python +node = onnx.helper.make_node( + 'Add', + inputs=['x', 'y'], + outputs=['sum'], +) + +x = np.random.randint(24, size=(3, 4, 5), dtype=np.uint8) +y = np.random.randint(24, size=(3, 4, 5), dtype=np.uint8) +expect(node, inputs=[x, y], outputs=[x + y], + name='test_add_uint8') +``` + +
+ + +### **And** + + Returns the tensor resulted from performing the `and` logical operation + elementwise on the input tensors `A` and `B` (with Numpy-style broadcasting support). + + This operator supports **multidirectional (i.e., Numpy-style) broadcasting**; for more details please check [the doc](Broadcasting.md). + +#### Version + +This version of the operator has been available since version 7 of the default ONNX operator set. + +Other versions of this operator: 1 + +#### Inputs + +
+
A (non-differentiable) : T
+
First input operand for the logical operator.
+
B (non-differentiable) : T
+
Second input operand for the logical operator.
+
+ +#### Outputs + +
+
C (non-differentiable) : T1
+
Result tensor.
+
+ +#### Type Constraints + +
+
T : tensor(bool)
+
Constrains input to boolean tensor.
+
T1 : tensor(bool)
+
Constrains output to boolean tensor.
+
+ + +#### Examples + +
+and + +```python +node = onnx.helper.make_node( + 'And', + inputs=['x', 'y'], + outputs=['and'], +) + +# 2d +x = (np.random.randn(3, 4) > 0).astype(bool) +y = (np.random.randn(3, 4) > 0).astype(bool) +z = np.logical_and(x, y) +expect(node, inputs=[x, y], outputs=[z], + name='test_and2d') + +# 3d +x = (np.random.randn(3, 4, 5) > 0).astype(bool) +y = (np.random.randn(3, 4, 5) > 0).astype(bool) +z = np.logical_and(x, y) +expect(node, inputs=[x, y], outputs=[z], + name='test_and3d') + +# 4d +x = (np.random.randn(3, 4, 5, 6) > 0).astype(bool) +y = (np.random.randn(3, 4, 5, 6) > 0).astype(bool) +z = np.logical_and(x, y) +expect(node, inputs=[x, y], outputs=[z], + name='test_and4d') +``` + +
+ + +
+and_broadcast + +```python +node = onnx.helper.make_node( + 'And', + inputs=['x', 'y'], + outputs=['and'], +) + +# 3d vs 1d +x = (np.random.randn(3, 4, 5) > 0).astype(bool) +y = (np.random.randn(5) > 0).astype(bool) +z = np.logical_and(x, y) +expect(node, inputs=[x, y], outputs=[z], + name='test_and_bcast3v1d') + +# 3d vs 2d +x = (np.random.randn(3, 4, 5) > 0).astype(bool) +y = (np.random.randn(4, 5) > 0).astype(bool) +z = np.logical_and(x, y) +expect(node, inputs=[x, y], outputs=[z], + name='test_and_bcast3v2d') + +# 4d vs 2d +x = (np.random.randn(3, 4, 5, 6) > 0).astype(bool) +y = (np.random.randn(5, 6) > 0).astype(bool) +z = np.logical_and(x, y) +expect(node, inputs=[x, y], outputs=[z], + name='test_and_bcast4v2d') + +# 4d vs 3d +x = (np.random.randn(3, 4, 5, 6) > 0).astype(bool) +y = (np.random.randn(4, 5, 6) > 0).astype(bool) +z = np.logical_and(x, y) +expect(node, inputs=[x, y], outputs=[z], + name='test_and_bcast4v3d') + +# 4d vs 4d +x = (np.random.randn(1, 4, 1, 6) > 0).astype(bool) +y = (np.random.randn(3, 1, 5, 6) > 0).astype(bool) +z = np.logical_and(x, y) +expect(node, inputs=[x, y], outputs=[z], + name='test_and_bcast4v4d') +``` + +
+ + +### **ArgMax** + + Computes the indices of the max elements of the input tensor's element along the + provided axis. The resulting tensor has the same rank as the input if keepdims equal 1. + If keepdims equal 0, then the resulting tensor have the reduced dimension pruned. + If select_last_index is True (default False), the index of the last occurrence of the max + is selected if the max appears more than once in the input. Otherwise the index of the + first occurrence is selected. + The type of the output tensor is integer. + +#### Version + +This version of the operator has been available since version 13 of the default ONNX operator set. + +Other versions of this operator: 1, 11, 12 + +#### Attributes + +
+
axis : int (default is 0)
+
The axis in which to compute the arg indices. Accepted range is [-r, r-1] where r = rank(data).
+
keepdims : int (default is 1)
+
Keep the reduced dimension or not, default 1 mean keep reduced dimension.
+
select_last_index : int (default is 0)
+
Whether to select the last index or the first index if the {name} appears in multiple indices, default is False (first index).
+
+ +#### Inputs + +
+
data (non-differentiable) : T
+
An input tensor.
+
+ +#### Outputs + +
+
reduced (non-differentiable) : tensor(int64)
+
Reduced output tensor with integer data type.
+
+ +#### Type Constraints + +
+
T : tensor(uint8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(int8), tensor(int16), tensor(int32), tensor(int64), tensor(float16), tensor(float), tensor(double), tensor(bfloat16)
+
Constrain input and output types to all numeric tensors.
+
+ + +#### Examples + +
+default_axes_keepdims + +```python +data = np.array([[2, 1], [3, 10]], dtype=np.float32) +keepdims = 1 +node = onnx.helper.make_node( + 'ArgMax', + inputs=['data'], + outputs=['result'], + keepdims=keepdims) + +# result: [[1, 1]] +result = argmax_use_numpy(data, keepdims=keepdims) +expect(node, inputs=[data], outputs=[result], name='test_argmax_default_axis_example') + +data = np.random.uniform(-10, 10, [2, 3, 4]).astype(np.float32) +# result's shape: [1, 3, 4] +result = argmax_use_numpy(data, keepdims=keepdims) +expect(node, inputs=[data], outputs=[result], name='test_argmax_default_axis_random') +``` + +
+ + +
+default_axes_keepdims_select_last_index + +```python +data = np.array([[2, 2], [3, 10]], dtype=np.float32) +keepdims = 1 +node = onnx.helper.make_node( + 'ArgMax', + inputs=['data'], + outputs=['result'], + keepdims=keepdims, + select_last_index=True) + +# result: [[1, 1]] +result = argmax_use_numpy_select_last_index(data, keepdims=keepdims) +expect(node, inputs=[data], outputs=[result], name='test_argmax_default_axis_example_select_last_index') + +data = np.random.uniform(-10, 10, [2, 3, 4]).astype(np.float32) +# result's shape: [1, 3, 4] +result = argmax_use_numpy_select_last_index(data, keepdims=keepdims) +expect(node, inputs=[data], outputs=[result], name='test_argmax_default_axis_random_select_last_index') +``` + +
+ + +
+keepdims + +```python +data = np.array([[2, 1], [3, 10]], dtype=np.float32) +axis = 1 +keepdims = 1 +node = onnx.helper.make_node( + 'ArgMax', + inputs=['data'], + outputs=['result'], + axis=axis, + keepdims=keepdims) +# result: [[0], [1]] +result = argmax_use_numpy(data, axis=axis, keepdims=keepdims) +expect(node, inputs=[data], outputs=[result], name='test_argmax_keepdims_example') + +data = np.random.uniform(-10, 10, [2, 3, 4]).astype(np.float32) +# result's shape: [2, 1, 4] +result = argmax_use_numpy(data, axis=axis, keepdims=keepdims) +expect(node, inputs=[data], outputs=[result], name='test_argmax_keepdims_random') +``` + +
+ + +
+keepdims_select_last_index + +```python +data = np.array([[2, 2], [3, 10]], dtype=np.float32) +axis = 1 +keepdims = 1 +node = onnx.helper.make_node( + 'ArgMax', + inputs=['data'], + outputs=['result'], + axis=axis, + keepdims=keepdims, + select_last_index=True) +# result: [[1], [1]] +result = argmax_use_numpy_select_last_index(data, axis=axis, keepdims=keepdims) +expect(node, inputs=[data], outputs=[result], name='test_argmax_keepdims_example_select_last_index') + +data = np.random.uniform(-10, 10, [2, 3, 4]).astype(np.float32) +# result's shape: [2, 1, 4] +result = argmax_use_numpy_select_last_index(data, axis=axis, keepdims=keepdims) +expect(node, inputs=[data], outputs=[result], name='test_argmax_keepdims_random_select_last_index') +``` + +
+ + +
+negative_axis_keepdims + +```python +data = np.array([[2, 1], [3, 10]], dtype=np.float32) +axis = -1 +keepdims = 1 +node = onnx.helper.make_node( + 'ArgMax', + inputs=['data'], + outputs=['result'], + axis=axis, + keepdims=keepdims) +# result: [[0], [1]] +result = argmax_use_numpy(data, axis=axis, keepdims=keepdims) +expect(node, inputs=[data], outputs=[result], name='test_argmax_negative_axis_keepdims_example') + +data = np.random.uniform(-10, 10, [2, 3, 4]).astype(np.float32) +# result's shape: [2, 3, 1] +result = argmax_use_numpy(data, axis=axis, keepdims=keepdims) +expect(node, inputs=[data], outputs=[result], name='test_argmax_negative_axis_keepdims_random') +``` + +
+ + +
+negative_axis_keepdims_select_last_index + +```python +data = np.array([[2, 2], [3, 10]], dtype=np.float32) +axis = -1 +keepdims = 1 +node = onnx.helper.make_node( + 'ArgMax', + inputs=['data'], + outputs=['result'], + axis=axis, + keepdims=keepdims, + select_last_index=True) +# result: [[1], [1]] +result = argmax_use_numpy_select_last_index(data, axis=axis, keepdims=keepdims) +expect(node, inputs=[data], outputs=[result], name='test_argmax_negative_axis_keepdims_example_select_last_index') + +data = np.random.uniform(-10, 10, [2, 3, 4]).astype(np.float32) +# result's shape: [2, 3, 1] +result = argmax_use_numpy_select_last_index(data, axis=axis, keepdims=keepdims) +expect(node, inputs=[data], outputs=[result], name='test_argmax_negative_axis_keepdims_random_select_last_index') +``` + +
+ + +
+no_keepdims + +```python +data = np.array([[2, 1], [3, 10]], dtype=np.float32) +axis = 1 +keepdims = 0 +node = onnx.helper.make_node( + 'ArgMax', + inputs=['data'], + outputs=['result'], + axis=axis, + keepdims=keepdims) +# result: [0, 1] +result = argmax_use_numpy(data, axis=axis, keepdims=keepdims) +expect(node, inputs=[data], outputs=[result], name='test_argmax_no_keepdims_example') + +data = np.random.uniform(-10, 10, [2, 3, 4]).astype(np.float32) +# result's shape: [2, 4] +result = argmax_use_numpy(data, axis=axis, keepdims=keepdims) +expect(node, inputs=[data], outputs=[result], name='test_argmax_no_keepdims_random') +``` + +
+ + +
+no_keepdims_select_last_index + +```python +data = np.array([[2, 2], [3, 10]], dtype=np.float32) +axis = 1 +keepdims = 0 +node = onnx.helper.make_node( + 'ArgMax', + inputs=['data'], + outputs=['result'], + axis=axis, + keepdims=keepdims, + select_last_index=True) +# result: [1, 1] +result = argmax_use_numpy_select_last_index(data, axis=axis, keepdims=keepdims) +expect(node, inputs=[data], outputs=[result], name='test_argmax_no_keepdims_example_select_last_index') + +data = np.random.uniform(-10, 10, [2, 3, 4]).astype(np.float32) +# result's shape: [2, 4] +result = argmax_use_numpy_select_last_index(data, axis=axis, keepdims=keepdims) +expect(node, inputs=[data], outputs=[result], name='test_argmax_no_keepdims_random_select_last_index') +``` + +
+ + +### **ArgMin** + + Computes the indices of the min elements of the input tensor's element along the + provided axis. The resulting tensor has the same rank as the input if keepdims equal 1. + If keepdims equal 0, then the resulting tensor have the reduced dimension pruned. + If select_last_index is True (default False), the index of the last occurrence of the min + is selected if the min appears more than once in the input. Otherwise the index of the + first occurrence is selected. + The type of the output tensor is integer. + +#### Version + +This version of the operator has been available since version 13 of the default ONNX operator set. + +Other versions of this operator: 1, 11, 12 + +#### Attributes + +
+
axis : int (default is 0)
+
The axis in which to compute the arg indices. Accepted range is [-r, r-1] where r = rank(data).
+
keepdims : int (default is 1)
+
Keep the reduced dimension or not, default 1 mean keep reduced dimension.
+
select_last_index : int (default is 0)
+
Whether to select the last index or the first index if the {name} appears in multiple indices, default is False (first index).
+
+ +#### Inputs + +
+
data (non-differentiable) : T
+
An input tensor.
+
+ +#### Outputs + +
+
reduced (non-differentiable) : tensor(int64)
+
Reduced output tensor with integer data type.
+
+ +#### Type Constraints + +
+
T : tensor(uint8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(int8), tensor(int16), tensor(int32), tensor(int64), tensor(float16), tensor(float), tensor(double), tensor(bfloat16)
+
Constrain input and output types to all numeric tensors.
+
+ + +#### Examples + +
+default_axes_keepdims + +```python +data = np.array([[2, 1], [3, 10]], dtype=np.float32) +keepdims = 1 +node = onnx.helper.make_node( + 'ArgMin', + inputs=['data'], + outputs=['result'], + keepdims=keepdims) + +# The content of result is : [[0], [0]] +result = argmin_use_numpy(data, keepdims=keepdims) +expect(node, inputs=[data], outputs=[result], name='test_argmin_default_axis_example') + +data = np.random.uniform(-10, 10, [2, 3, 4]).astype(np.float32) +# result's shape: [1, 3, 4] +result = argmin_use_numpy(data, keepdims=keepdims) +expect(node, inputs=[data], outputs=[result], name='test_argmin_default_axis_random') +``` + +
+ + +
+default_axes_keepdims_select_last_index + +```python +data = np.array([[2, 2], [3, 10]], dtype=np.float32) +keepdims = 1 +node = onnx.helper.make_node( + 'ArgMin', + inputs=['data'], + outputs=['result'], + keepdims=keepdims, + select_last_index=True) + +# result: [[0, 0]] +result = argmin_use_numpy_select_last_index(data, keepdims=keepdims) +expect(node, inputs=[data], outputs=[result], name='test_argmin_default_axis_example_select_last_index') + +data = np.random.uniform(-10, 10, [2, 3, 4]).astype(np.float32) +# result's shape: [1, 3, 4] +result = argmin_use_numpy_select_last_index(data, keepdims=keepdims) +expect(node, inputs=[data], outputs=[result], name='test_argmin_default_axis_random_select_last_index') +``` + +
+ + +
+keepdims + +```python +data = np.array([[2, 1], [3, 10]], dtype=np.float32) +axis = 1 +keepdims = 1 +node = onnx.helper.make_node( + 'ArgMin', + inputs=['data'], + outputs=['result'], + axis=axis, + keepdims=keepdims) +# The content of result is : [[1], [0]] +result = argmin_use_numpy(data, axis=axis, keepdims=keepdims) +expect(node, inputs=[data], outputs=[result], name='test_argmin_keepdims_example') + +data = np.random.uniform(-10, 10, [2, 3, 4]).astype(np.float32) +# result's shape: [2, 1, 4] +result = argmin_use_numpy(data, axis=axis, keepdims=keepdims) +expect(node, inputs=[data], outputs=[result], name='test_argmin_keepdims_random') +``` + +
+ + +
+keepdims_select_last_index + +```python +data = np.array([[2, 2], [3, 10]], dtype=np.float32) +axis = 1 +keepdims = 1 +node = onnx.helper.make_node( + 'ArgMin', + inputs=['data'], + outputs=['result'], + axis=axis, + keepdims=keepdims, + select_last_index=True) +# result: [[1], [0]] +result = argmin_use_numpy_select_last_index(data, axis=axis, keepdims=keepdims) +expect(node, inputs=[data], outputs=[result], name='test_argmin_keepdims_example_select_last_index') + +data = np.random.uniform(-10, 10, [2, 3, 4]).astype(np.float32) +# result's shape: [2, 1, 4] +result = argmin_use_numpy_select_last_index(data, axis=axis, keepdims=keepdims) +expect(node, inputs=[data], outputs=[result], name='test_argmin_keepdims_random_select_last_index') +``` + +
+ + +
+negative_axis_keepdims + +```python +data = np.array([[2, 1], [3, 10]], dtype=np.float32) +axis = -1 +keepdims = 1 +node = onnx.helper.make_node( + 'ArgMin', + inputs=['data'], + outputs=['result'], + axis=axis, + keepdims=keepdims) +# The content of result is : [[1], [0]] +result = argmin_use_numpy(data, axis=axis, keepdims=keepdims) +expect(node, inputs=[data], outputs=[result], name='test_argmin_negative_axis_keepdims_example') + +data = np.random.uniform(-10, 10, [2, 3, 4]).astype(np.float32) +# result's shape: [2, 3, 1] +result = argmin_use_numpy(data, axis=axis, keepdims=keepdims) +expect(node, inputs=[data], outputs=[result], name='test_argmin_negative_axis_keepdims_random') +``` + +
+ + +
+negative_axis_keepdims_select_last_index + +```python +data = np.array([[2, 2], [3, 10]], dtype=np.float32) +axis = -1 +keepdims = 1 +node = onnx.helper.make_node( + 'ArgMin', + inputs=['data'], + outputs=['result'], + axis=axis, + keepdims=keepdims, + select_last_index=True) +# result: [[1], [0]] +result = argmin_use_numpy_select_last_index(data, axis=axis, keepdims=keepdims) +expect(node, inputs=[data], outputs=[result], name='test_argmin_negative_axis_keepdims_example_select_last_index') + +data = np.random.uniform(-10, 10, [2, 3, 4]).astype(np.float32) +# result's shape: [2, 3, 1] +result = argmin_use_numpy_select_last_index(data, axis=axis, keepdims=keepdims) +expect(node, inputs=[data], outputs=[result], name='test_argmin_negative_axis_keepdims_random_select_last_index') +``` + +
+ + +
+no_keepdims + +```python +data = np.array([[2, 1], [3, 10]], dtype=np.float32) +axis = 1 +keepdims = 0 +node = onnx.helper.make_node( + 'ArgMin', + inputs=['data'], + outputs=['result'], + axis=axis, + keepdims=keepdims) +# The content of result is : [[1, 0]] +result = argmin_use_numpy(data, axis=axis, keepdims=keepdims) +expect(node, inputs=[data], outputs=[result], name='test_argmin_no_keepdims_example') + +data = np.random.uniform(-10, 10, [2, 3, 4]).astype(np.float32) +# result's shape: [2, 4] +result = argmin_use_numpy(data, axis=axis, keepdims=keepdims) +expect(node, inputs=[data], outputs=[result], name='test_argmin_no_keepdims_random') +``` + +
+ + +
+no_keepdims_select_last_index + +```python +data = np.array([[2, 2], [3, 10]], dtype=np.float32) +axis = 1 +keepdims = 0 +node = onnx.helper.make_node( + 'ArgMin', + inputs=['data'], + outputs=['result'], + axis=axis, + keepdims=keepdims, + select_last_index=True) +# result: [[1, 0]] +result = argmin_use_numpy_select_last_index(data, axis=axis, keepdims=keepdims) +expect(node, inputs=[data], outputs=[result], name='test_argmin_no_keepdims_example_select_last_index') + +data = np.random.uniform(-10, 10, [2, 3, 4]).astype(np.float32) +# result's shape: [2, 4] +result = argmin_use_numpy_select_last_index(data, axis=axis, keepdims=keepdims) +expect(node, inputs=[data], outputs=[result], name='test_argmin_no_keepdims_random_select_last_index') +``` + +
+ + +### **Asin** + + Calculates the arcsine (inverse of sine) of the given input tensor, element-wise. + +#### Version + +This version of the operator has been available since version 7 of the default ONNX operator set. + +#### Inputs + +
+
input (differentiable) : T
+
Input tensor
+
+ +#### Outputs + +
+
output (differentiable) : T
+
The arcsine of the input tensor computed element-wise
+
+ +#### Type Constraints + +
+
T : tensor(float16), tensor(float), tensor(double)
+
Constrain input and output types to float tensors.
+
+ + +#### Examples + +
+asin + +```python +node = onnx.helper.make_node( + 'Asin', + inputs=['x'], + outputs=['y'], +) + +x = np.array([-0.5, 0, 0.5]).astype(np.float32) +y = np.arcsin(x) +expect(node, inputs=[x], outputs=[y], + name='test_asin_example') + +x = np.random.rand(3, 4, 5).astype(np.float32) +y = np.arcsin(x) +expect(node, inputs=[x], outputs=[y], + name='test_asin') +``` + +
+ + +### **Asinh** + + Calculates the hyperbolic arcsine of the given input tensor element-wise. + +#### Version + +This version of the operator has been available since version 9 of the default ONNX operator set. + +#### Inputs + +
+
input (differentiable) : T
+
Input tensor
+
+ +#### Outputs + +
+
output (differentiable) : T
+
The hyperbolic arcsine values of the input tensor computed element-wise
+
+ +#### Type Constraints + +
+
T : tensor(float16), tensor(float), tensor(double)
+
Constrain input and output types to float tensors.
+
+ + +#### Examples + +
+asinh + +```python +node = onnx.helper.make_node( + 'Asinh', + inputs=['x'], + outputs=['y'], +) + +x = np.array([-1, 0, 1]).astype(np.float32) +y = np.arcsinh(x) # expected output [-0.88137358, 0., 0.88137358] +expect(node, inputs=[x], outputs=[y], + name='test_asinh_example') + +x = np.random.randn(3, 4, 5).astype(np.float32) +y = np.arcsinh(x) +expect(node, inputs=[x], outputs=[y], + name='test_asinh') +``` + +
+ + +### **Atan** + + Calculates the arctangent (inverse of tangent) of the given input tensor, element-wise. + +#### Version + +This version of the operator has been available since version 7 of the default ONNX operator set. + +#### Inputs + +
+
input (differentiable) : T
+
Input tensor
+
+ +#### Outputs + +
+
output (differentiable) : T
+
The arctangent of the input tensor computed element-wise
+
+ +#### Type Constraints + +
+
T : tensor(float16), tensor(float), tensor(double)
+
Constrain input and output types to float tensors.
+
+ + +#### Examples + +
+atan + +```python +node = onnx.helper.make_node( + 'Atan', + inputs=['x'], + outputs=['y'], +) + +x = np.array([-1, 0, 1]).astype(np.float32) +y = np.arctan(x) +expect(node, inputs=[x], outputs=[y], + name='test_atan_example') + +x = np.random.randn(3, 4, 5).astype(np.float32) +y = np.arctan(x) +expect(node, inputs=[x], outputs=[y], + name='test_atan') +``` + +
+ + +### **Atanh** + + Calculates the hyperbolic arctangent of the given input tensor element-wise. + +#### Version + +This version of the operator has been available since version 9 of the default ONNX operator set. + +#### Inputs + +
+
input (differentiable) : T
+
Input tensor
+
+ +#### Outputs + +
+
output (differentiable) : T
+
The hyperbolic arctangent values of the input tensor computed element-wise
+
+ +#### Type Constraints + +
+
T : tensor(float16), tensor(float), tensor(double)
+
Constrain input and output types to float tensors.
+
+ + +#### Examples + +
+atanh + +```python +node = onnx.helper.make_node( + 'Atanh', + inputs=['x'], + outputs=['y'], +) + +x = np.array([-0.5, 0, 0.5]).astype(np.float32) +y = np.arctanh(x) # expected output [-0.54930615, 0., 0.54930615] +expect(node, inputs=[x], outputs=[y], + name='test_atanh_example') + +x = np.random.uniform(0.0, 1.0, (3, 4, 5)).astype(np.float32) +y = np.arctanh(x) +expect(node, inputs=[x], outputs=[y], + name='test_atanh') +``` + +
+ + +### **AveragePool** + + AveragePool consumes an input tensor X and applies average pooling across + the tensor according to kernel sizes, stride sizes, and pad lengths. + average pooling consisting of computing the average on all values of a + subset of the input tensor according to the kernel size and downsampling the + data into the output tensor Y for further processing. The output spatial shape will be following: + ``` + output_spatial_shape[i] = floor((input_spatial_shape[i] + pad_shape[i] - kernel_spatial_shape[i]) / strides_spatial_shape[i] + 1) + ``` + or + ``` + output_spatial_shape[i] = ceil((input_spatial_shape[i] + pad_shape[i] - kernel_spatial_shape[i]) / strides_spatial_shape[i] + 1) + ``` + if ceil_mode is enabled + + ``` + * pad_shape[i] is sum of pads along axis i + ``` + + `auto_pad` is a DEPRECATED attribute. If you are using them currently, the output spatial shape will be following: + ``` + VALID: output_spatial_shape[i] = ceil((input_spatial_shape[i] - kernel_spatial_shape[i] + 1) / strides_spatial_shape[i]) + SAME_UPPER or SAME_LOWER: output_spatial_shape[i] = ceil(input_spatial_shape[i] / strides_spatial_shape[i]) + ``` + And pad shape will be following if `SAME_UPPER` or `SAME_LOWER`: + ``` + pad_shape[i] = (output_spatial_shape[i] - 1) * strides_spatial_shape[i] + kernel_spatial_shape[i] - input_spatial_shape[i] + ``` + The output of each pooling window is divided by the number of elements (exclude pad when attribute count_include_pad is zero). + + +#### Version + +This version of the operator has been available since version 11 of the default ONNX operator set. + +Other versions of this operator: 1, 7, 10 + +#### Attributes + +
+
auto_pad : string (default is NOTSET)
+
auto_pad must be either NOTSET, SAME_UPPER, SAME_LOWER or VALID. Where default value is NOTSET, which means explicit padding is used. SAME_UPPER or SAME_LOWER mean pad the input so that `output_shape[i] = ceil(input_shape[i] / strides[i])` for each axis `i`. The padding is split between the two sides equally or almost equally (depending on whether it is even or odd). In case the padding is an odd number, the extra padding is added at the end for SAME_UPPER and at the beginning for SAME_LOWER.
+
ceil_mode : int (default is 0)
+
Whether to use ceil or floor (default) to compute the output shape.
+
count_include_pad : int (default is 0)
+
Whether include pad pixels when calculating values for the edges. Default is 0, doesn't count include pad.
+
kernel_shape : list of ints (required)
+
The size of the kernel along each axis.
+
pads : list of ints
+
Padding for the beginning and ending along each spatial axis, it can take any value greater than or equal to 0. The value represent the number of pixels added to the beginning and end part of the corresponding axis. `pads` format should be as follow [x1_begin, x2_begin...x1_end, x2_end,...], where xi_begin the number of pixels added at the beginning of axis `i` and xi_end, the number of pixels added at the end of axis `i`. This attribute cannot be used simultaneously with auto_pad attribute. If not present, the padding defaults to 0 along start and end of each spatial axis.
+
strides : list of ints
+
Stride along each spatial axis. If not present, the stride defaults to 1 along each spatial axis.
+
+ +#### Inputs + +
+
X (differentiable) : T
+
Input data tensor from the previous operator; dimensions for image case are (N x C x H x W), where N is the batch size, C is the number of channels, and H and W are the height and the width of the data. For non image case, the dimensions are in the form of (N x C x D1 x D2 ... Dn), where N is the batch size. Optionally, if dimension denotation is in effect, the operation expects the input data tensor to arrive with the dimension denotation of [DATA_BATCH, DATA_CHANNEL, DATA_FEATURE, DATA_FEATURE ...].
+
+ +#### Outputs + +
+
Y (differentiable) : T
+
Output data tensor from average or max pooling across the input tensor. Dimensions will vary based on various kernel, stride, and pad sizes. Floor value of the dimension is used
+
+ +#### Type Constraints + +
+
T : tensor(float16), tensor(float), tensor(double)
+
Constrain input and output types to float tensors.
+
+ + +#### Examples + +
+averagepool_1d_default + +```python +""" +input_shape: [1, 3, 32] +output_shape: [1, 3, 31] +""" +node = onnx.helper.make_node( + 'AveragePool', + inputs=['x'], + outputs=['y'], + kernel_shape=[2], +) +x = np.random.randn(1, 3, 32).astype(np.float32) +x_shape = np.shape(x) +kernel_shape = [2] +strides = [1] +out_shape = get_output_shape('VALID', x_shape[2:], kernel_shape, strides) +padded = x +y = pool(padded, x_shape, kernel_shape, strides, out_shape, [0], 'AVG') + +expect(node, inputs=[x], outputs=[y], name='test_averagepool_1d_default') +``` + +
+ + +
+averagepool_2d_ceil + +```python +""" +input_shape: [1, 1, 4, 4] +output_shape: [1, 1, 2, 2] +""" +node = onnx.helper.make_node( + 'AveragePool', + inputs=['x'], + outputs=['y'], + kernel_shape=[3, 3], + strides=[2, 2], + ceil_mode=True +) +x = np.array([[[ + [1, 2, 3, 4], + [5, 6, 7, 8], + [9, 10, 11, 12], + [13, 14, 15, 16], +]]]).astype(np.float32) +y = np.array([[[ + [6, 7.5], + [12, 13.5]]]]).astype(np.float32) + +expect(node, inputs=[x], outputs=[y], name='test_averagepool_2d_ceil') +``` + +
+ + +
+averagepool_2d_default + +```python +""" +input_shape: [1, 3, 32, 32] +output_shape: [1, 3, 31, 31] +""" +node = onnx.helper.make_node( + 'AveragePool', + inputs=['x'], + outputs=['y'], + kernel_shape=[2, 2], +) +x = np.random.randn(1, 3, 32, 32).astype(np.float32) +x_shape = np.shape(x) +kernel_shape = (2, 2) +strides = (1, 1) +out_shape = get_output_shape('VALID', x_shape[2:], kernel_shape, strides) +padded = x +y = pool(padded, x_shape, kernel_shape, strides, out_shape, (0, 0), 'AVG') + +expect(node, inputs=[x], outputs=[y], name='test_averagepool_2d_default') +``` + +
+ + +
+averagepool_2d_pads + +```python +""" +input_shape: [1, 3, 28, 28] +output_shape: [1, 3, 30, 30] +pad_shape: [4, 4] -> [2, 2, 2, 2] by axis +""" +node = onnx.helper.make_node( + 'AveragePool', + inputs=['x'], + outputs=['y'], + kernel_shape=[3, 3], + pads=[2, 2, 2, 2] +) +x = np.random.randn(1, 3, 28, 28).astype(np.float32) +x_shape = np.shape(x) +kernel_shape = (3, 3) +strides = (1, 1) +pad_bottom = 2 +pad_top = 2 +pad_right = 2 +pad_left = 2 +pad_shape = [pad_top + pad_bottom, pad_left + pad_right] +out_shape = get_output_shape('VALID', np.add(x_shape[2:], pad_shape), kernel_shape, strides) +padded = np.pad(x, ((0, 0), (0, 0), (pad_top, pad_bottom), (pad_left, pad_right)), mode='constant', + constant_values=np.nan) +y = pool(padded, x_shape, kernel_shape, strides, out_shape, pad_shape, 'AVG') + +expect(node, inputs=[x], outputs=[y], name='test_averagepool_2d_pads') +``` + +
+ + +
+averagepool_2d_pads_count_include_pad + +```python +""" +input_shape: [1, 3, 28, 28] +output_shape: [1, 3, 30, 30] +pad_shape: [4, 4] -> [2, 2, 2, 2] by axis +""" +node = onnx.helper.make_node( + 'AveragePool', + inputs=['x'], + outputs=['y'], + kernel_shape=[3, 3], + pads=[2, 2, 2, 2], + count_include_pad=1, +) +x = np.random.randn(1, 3, 28, 28).astype(np.float32) +x_shape = np.shape(x) +kernel_shape = (3, 3) +strides = (1, 1) +pad_bottom = 2 +pad_top = 2 +pad_right = 2 +pad_left = 2 +pad_shape = [pad_top + pad_bottom, pad_left + pad_right] +out_shape = get_output_shape('VALID', np.add(x_shape[2:], pad_shape), kernel_shape, strides) +padded = np.pad(x, ((0, 0), (0, 0), (pad_top, pad_bottom), (pad_left, pad_right)), mode='constant', + constant_values=0) +y = pool(padded, x_shape, kernel_shape, strides, out_shape, pad_shape, 'AVG', count_include_pad=1) + +expect(node, inputs=[x], outputs=[y], name='test_averagepool_2d_pads_count_include_pad') +``` + +
+ + +
+averagepool_2d_precomputed_pads + +```python +""" +input_shape: [1, 1, 5, 5] +output_shape: [1, 1, 5, 5] +pad_shape: [4, 4] -> [2, 2, 2, 2] by axis +""" +node = onnx.helper.make_node( + 'AveragePool', + inputs=['x'], + outputs=['y'], + kernel_shape=[5, 5], + pads=[2, 2, 2, 2] + +) +x = np.array([[[ + [1, 2, 3, 4, 5], + [6, 7, 8, 9, 10], + [11, 12, 13, 14, 15], + [16, 17, 18, 19, 20], + [21, 22, 23, 24, 25], +]]]).astype(np.float32) +y = np.array([[[[7, 7.5, 8, 8.5, 9], + [9.5, 10, 10.5, 11, 11.5], + [12, 12.5, 13, 13.5, 14], + [14.5, 15, 15.5, 16, 16.5], + [17, 17.5, 18, 18.5, 19]]]]).astype(np.float32) + +expect(node, inputs=[x], outputs=[y], name='test_averagepool_2d_precomputed_pads') +``` + +
+ + +
+averagepool_2d_precomputed_pads_count_include_pad + +```python +""" +input_shape: [1, 1, 5, 5] +output_shape: [1, 1, 5, 5] +pad_shape: [4, 4] -> [2, 2, 2, 2] by axis +""" +node = onnx.helper.make_node( + 'AveragePool', + inputs=['x'], + outputs=['y'], + kernel_shape=[5, 5], + pads=[2, 2, 2, 2], + count_include_pad=1 +) +x = np.array([[[ + [1, 2, 3, 4, 5], + [6, 7, 8, 9, 10], + [11, 12, 13, 14, 15], + [16, 17, 18, 19, 20], + [21, 22, 23, 24, 25], +]]]).astype(np.float32) +y = np.array([[[[2.5200, 3.6000, 4.8000, 4.0800, 3.2400], + [4.5600, 6.4000, 8.4000, 7.0400, 5.5200], + [7.2000, 10.0000, 13.0000, 10.8000, 8.4000], + [6.9600, 9.6000, 12.4000, 10.2400, 7.9200], + [6.1200, 8.4000, 10.8000, 8.8800, 6.8400]]]]).astype(np.float32) + +expect(node, inputs=[x], outputs=[y], name='test_averagepool_2d_precomputed_pads_count_include_pad') +``` + +
+ + +
+averagepool_2d_precomputed_same_upper + +```python +""" +input_shape: [1, 1, 5, 5] +output_shape: [1, 1, 3, 3] +pad_shape: [2, 2] -> [1, 1, 1, 1] by axis +""" +node = onnx.helper.make_node( + 'AveragePool', + inputs=['x'], + outputs=['y'], + kernel_shape=[3, 3], + strides=[2, 2], + auto_pad='SAME_UPPER' +) +x = np.array([[[ + [1, 2, 3, 4, 5], + [6, 7, 8, 9, 10], + [11, 12, 13, 14, 15], + [16, 17, 18, 19, 20], + [21, 22, 23, 24, 25], +]]]).astype(np.float32) +y = np.array([[[[4, 5.5, 7], + [11.5, 13, 14.5], + [19, 20.5, 22]]]]).astype(np.float32) + +expect(node, inputs=[x], outputs=[y], name='test_averagepool_2d_precomputed_same_upper') +``` + +
+ + +
+averagepool_2d_precomputed_strides + +```python +""" +input_shape: [1, 1, 5, 5] +output_shape: [1, 1, 2, 2] +""" +node = onnx.helper.make_node( + 'AveragePool', + inputs=['x'], + outputs=['y'], + kernel_shape=[2, 2], + strides=[2, 2] +) +x = np.array([[[ + [1, 2, 3, 4, 5], + [6, 7, 8, 9, 10], + [11, 12, 13, 14, 15], + [16, 17, 18, 19, 20], + [21, 22, 23, 24, 25], +]]]).astype(np.float32) +y = np.array([[[[4, 6], + [14, 16]]]]).astype(np.float32) + +expect(node, inputs=[x], outputs=[y], name='test_averagepool_2d_precomputed_strides') +``` + +
+ + +
+averagepool_2d_same_lower + +```python +""" +input_shape: [1, 3, 32, 32] +output_shape: [1, 3, 32, 32] +pad_shape: [1, 1] -> [1, 0, 1, 0] by axis +""" +node = onnx.helper.make_node( + 'AveragePool', + inputs=['x'], + outputs=['y'], + kernel_shape=[2, 2], + auto_pad='SAME_LOWER' +) +x = np.random.randn(1, 3, 32, 32).astype(np.float32) +x_shape = np.shape(x) +kernel_shape = (2, 2) +strides = (1, 1) +out_shape = get_output_shape('SAME_LOWER', x_shape[2:], kernel_shape, strides) +pad_shape = get_pad_shape('SAME_LOWER', x_shape[2:], kernel_shape, strides, out_shape) +pad_bottom = pad_shape[0] // 2 +pad_top = pad_shape[0] - pad_bottom +pad_right = pad_shape[1] // 2 +pad_left = pad_shape[1] - pad_right +padded = np.pad(x, ((0, 0), (0, 0), (pad_top, pad_bottom), (pad_left, pad_right)), mode='constant', + constant_values=np.nan) +y = pool(padded, x_shape, kernel_shape, strides, out_shape, pad_shape, 'AVG') + +expect(node, inputs=[x], outputs=[y], name='test_averagepool_2d_same_lower') +``` + +
+ + +
+averagepool_2d_same_upper + +```python +""" +input_shape: [1, 3, 32, 32] +output_shape: [1, 3, 32, 32] +pad_shape: [1, 1] -> [0, 1, 0, 1] by axis +""" +node = onnx.helper.make_node( + 'AveragePool', + inputs=['x'], + outputs=['y'], + kernel_shape=[2, 2], + auto_pad='SAME_UPPER' +) +x = np.random.randn(1, 3, 32, 32).astype(np.float32) +x_shape = np.shape(x) +kernel_shape = (2, 2) +strides = (1, 1) +out_shape = get_output_shape('SAME_UPPER', x_shape[2:], kernel_shape, strides) +pad_shape = get_pad_shape('SAME_UPPER', x_shape[2:], kernel_shape, strides, out_shape) +pad_top = pad_shape[0] // 2 +pad_bottom = pad_shape[0] - pad_top +pad_left = pad_shape[1] // 2 +pad_right = pad_shape[1] - pad_left +padded = np.pad(x, ((0, 0), (0, 0), (pad_top, pad_bottom), (pad_left, pad_right)), mode='constant', + constant_values=np.nan) +y = pool(padded, x_shape, kernel_shape, strides, out_shape, pad_shape, 'AVG') + +expect(node, inputs=[x], outputs=[y], name='test_averagepool_2d_same_upper') +``` + +
+ + +
+averagepool_2d_strides + +```python +""" +input_shape: [1, 3, 32, 32] +output_shape: [1, 3, 10, 10] +""" +node = onnx.helper.make_node( + 'AveragePool', + inputs=['x'], + outputs=['y'], + kernel_shape=[5, 5], + strides=[3, 3] +) +x = np.random.randn(1, 3, 32, 32).astype(np.float32) +x_shape = np.shape(x) +kernel_shape = (5, 5) +strides = (3, 3) +out_shape = get_output_shape('VALID', x_shape[2:], kernel_shape, strides) +padded = x +y = pool(padded, x_shape, kernel_shape, strides, out_shape, (0, 0), 'AVG') + +expect(node, inputs=[x], outputs=[y], name='test_averagepool_2d_strides') +``` + +
+ + +
+averagepool_3d_default + +```python +""" +input_shape: [1, 3, 32, 32, 32] +output_shape: [1, 3, 31, 31, 31] +""" +node = onnx.helper.make_node( + 'AveragePool', + inputs=['x'], + outputs=['y'], + kernel_shape=[2, 2, 2], +) +x = np.random.randn(1, 3, 32, 32, 32).astype(np.float32) +x_shape = np.shape(x) +kernel_shape = [2, 2, 2] +strides = [1, 1, 1] +out_shape = get_output_shape('VALID', x_shape[2:], kernel_shape, strides) +padded = x +y = pool(padded, x_shape, kernel_shape, strides, out_shape, [0, 0, 0], 'AVG') + +expect(node, inputs=[x], outputs=[y], name='test_averagepool_3d_default') +``` + +
+ + +### **BatchNormalization** + + Carries out batch normalization as described in the paper + https://arxiv.org/abs/1502.03167. Depending on the mode it is being run, + There are five required inputs 'X', 'scale', 'B', 'input_mean' and + 'input_var'. + Note that 'input_mean' and 'input_var' are expected to be the estimated + statistics in inference mode (training_mode=False, default), + and the running statistics in training mode (training_mode=True). + There are multiple cases for the number of outputs, which we list below: + + Output case #1: Y, running_mean, running_var (training_mode=True) + Output case #2: Y (training_mode=False) + + When training_mode=False, extra outputs are invalid. + The outputs are updated as follows when training_mode=True: + ``` + running_mean = input_mean * momentum + current_mean * (1 - momentum) + running_var = input_var * momentum + current_var * (1 - momentum) + + Y = (X - current_mean) / sqrt(current_var + epsilon) * scale + B + + where: + + current_mean = ReduceMean(X, axis=all_except_channel_index) + current_var = ReduceVar(X, axis=all_except_channel_index) + + Notice that ReduceVar refers to the population variance, and it equals to + sum(sqrd(x_i - x_avg)) / N + where N is the population size (this formula does not use sample size N - 1). + + ``` + + The computation of ReduceMean and ReduceVar uses float to avoid overflow for float16 inputs. + + When training_mode=False: + ``` + Y = (X - input_mean) / sqrt(input_var + epsilon) * scale + B + ``` + + For previous (depreciated) non-spatial cases, implementors are suggested + to flatten the input shape to (N x C * D1 * D2 * ... * Dn) before a BatchNormalization Op. + This operator has **optional** inputs/outputs. See [the doc](IR.md) for more details about the representation of optional arguments. An empty string may be used in the place of an actual argument's name to indicate a missing argument. Trailing optional arguments (those not followed by an argument that is present) may also be simply omitted. + +#### Version + +This version of the operator has been available since version 15 of the default ONNX operator set. + +Other versions of this operator: 1, 6, 7, 9, 14 + +#### Attributes + +
+
epsilon : float (default is 1e-05)
+
The epsilon value to use to avoid division by zero.
+
momentum : float (default is 0.9)
+
Factor used in computing the running mean and variance.e.g., running_mean = running_mean * momentum + mean * (1 - momentum).
+
training_mode : int (default is 0)
+
If set to true, it indicates BatchNormalization is being used for training, and outputs 1, 2, 3, and 4 would be populated.
+
+ +#### Inputs + +
+
X (differentiable) : T
+
Input data tensor from the previous operator; dimensions are in the form of (N x C x D1 x D2 ... Dn), where N is the batch size, C is the number of channels. Statistics are computed for every channel of C over N and D1 to Dn dimensions. For image data, input dimensions become (N x C x H x W). The op also accepts single dimension input of size N in which case C is assumed to be 1
+
scale (differentiable) : T1
+
Scale tensor of shape (C).
+
B (differentiable) : T1
+
Bias tensor of shape (C).
+
input_mean (differentiable) : T2
+
running (training) or estimated (testing) mean tensor of shape (C).
+
input_var (differentiable) : T2
+
running (training) or estimated (testing) variance tensor of shape (C).
+
+ +#### Outputs (1 - 3) + +
+
Y (differentiable) : T
+
The output tensor of the same shape as X
+
running_mean (optional, non-differentiable) : T2
+
The running mean after the BatchNormalization operator.
+
running_var (optional, non-differentiable) : T2
+
The running variance after the BatchNormalization operator. This op uses the population size (N) for calculating variance, and not the sample size N-1.
+
+ +#### Type Constraints + +
+
T : tensor(float16), tensor(float), tensor(double), tensor(bfloat16)
+
Constrain input and output types to float tensors.
+
T1 : tensor(float16), tensor(float), tensor(double), tensor(bfloat16)
+
Constrain scale and bias types to float tensors.
+
T2 : tensor(float16), tensor(float), tensor(double), tensor(bfloat16)
+
Constrain mean and variance types to float tensors.
+
+ + +#### Examples + +
+batchnormalization + +```python +# input size: (2, 3, 4, 5) +x = np.random.randn(2, 3, 4, 5).astype(np.float32) +s = np.random.randn(3).astype(np.float32) +bias = np.random.randn(3).astype(np.float32) +mean = np.random.randn(3).astype(np.float32) +var = np.random.rand(3).astype(np.float32) +y = _batchnorm_test_mode(x, s, bias, mean, var).astype(np.float32) + +node = onnx.helper.make_node( + 'BatchNormalization', + inputs=['x', 's', 'bias', 'mean', 'var'], + outputs=['y'], +) + +# output size: (2, 3, 4, 5) +expect(node, inputs=[x, s, bias, mean, var], outputs=[y], + name='test_batchnorm_example') + +# input size: (2, 3, 4, 5) +x = np.random.randn(2, 3, 4, 5).astype(np.float32) +s = np.random.randn(3).astype(np.float32) +bias = np.random.randn(3).astype(np.float32) +mean = np.random.randn(3).astype(np.float32) +var = np.random.rand(3).astype(np.float32) +epsilon = 1e-2 +y = _batchnorm_test_mode(x, s, bias, mean, var, epsilon).astype(np.float32) + +node = onnx.helper.make_node( + 'BatchNormalization', + inputs=['x', 's', 'bias', 'mean', 'var'], + outputs=['y'], + epsilon=epsilon, +) + +# output size: (2, 3, 4, 5) +expect(node, inputs=[x, s, bias, mean, var], outputs=[y], + name='test_batchnorm_epsilon') +``` + +
+ + +
+train + +```python +# input size: (2, 3, 4, 5) +x = np.random.randn(2, 3, 4, 5).astype(np.float32) +s = np.random.randn(3).astype(np.float32) +bias = np.random.randn(3).astype(np.float32) +mean = np.random.randn(3).astype(np.float32) +var = np.random.rand(3).astype(np.float32) +# using np.bool(1) while generating test data with "'bool' object has no attribute 'dtype'" +# working around by using np.byte(1).astype(bool) +training_mode = 1 +y, output_mean, output_var = _batchnorm_training_mode(x, s, bias, mean, var) + +node = onnx.helper.make_node( + 'BatchNormalization', + inputs=['x', 's', 'bias', 'mean', 'var'], + outputs=['y', 'output_mean', 'output_var'], + training_mode=training_mode +) + +# output size: (2, 3, 4, 5) +expect(node, inputs=[x, s, bias, mean, var], + outputs=[y, output_mean, output_var], + name='test_batchnorm_example_training_mode') + +# input size: (2, 3, 4, 5) +x = np.random.randn(2, 3, 4, 5).astype(np.float32) +s = np.random.randn(3).astype(np.float32) +bias = np.random.randn(3).astype(np.float32) +mean = np.random.randn(3).astype(np.float32) +var = np.random.rand(3).astype(np.float32) +training_mode = 1 +momentum = 0.9 +epsilon = 1e-2 +y, output_mean, output_var = _batchnorm_training_mode(x, s, bias, mean, var, momentum, + epsilon) + +node = onnx.helper.make_node( + 'BatchNormalization', + inputs=['x', 's', 'bias', 'mean', 'var'], + outputs=['y', 'output_mean', 'output_var'], + epsilon=epsilon, + training_mode=training_mode +) + +# output size: (2, 3, 4, 5) +expect(node, inputs=[x, s, bias, mean, var], + outputs=[y, output_mean, output_var], + name='test_batchnorm_epsilon_training_mode') +``` + +
+ + +### **Bernoulli** + + Draws binary random numbers (0 or 1) from a Bernoulli distribution. The input tensor should be a tensor + containing probabilities p (a value in the range [0,1]) to be used for drawing the binary random number, + where an output of 1 is produced with probability p and an output of 0 is produced with probability (1-p). + + This operator is non-deterministic and may not produce the same values in different + implementations (even if a seed is specified). + +#### Version + +This version of the operator has been available since version 15 of the default ONNX operator set. + +#### Attributes + +
+
dtype : int
+
The data type for the elements of the output tensor. if not specified, we will use the data type of the input tensor.
+
seed : float
+
(Optional) Seed to the random generator, if not specified we will auto generate one.
+
+ +#### Inputs + +
+
input : T1
+
All values in input have to be in the range:[0, 1].
+
+ +#### Outputs + +
+
output : T2
+
The returned output tensor only has values 0 or 1, same shape as input tensor.
+
+ +#### Type Constraints + +
+
T1 : tensor(float16), tensor(float), tensor(double)
+
Constrain input types to float tensors.
+
T2 : tensor(float16), tensor(float), tensor(double), tensor(bfloat16), tensor(uint8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(int8), tensor(int16), tensor(int32), tensor(int64), tensor(bool)
+
Constrain output types to all numeric tensors and bool tensors.
+
+ + +#### Examples + +
+bernoulli_with_dtype + +```python +node = onnx.helper.make_node( + 'Bernoulli', + inputs=['x'], + outputs=['y'], + dtype=onnx.TensorProto.DOUBLE, +) + +x = np.random.uniform(0.0, 1.0, 10).astype(np.float32) +y = bernoulli_reference_implementation(x, np.float64) +expect(node, inputs=[x], outputs=[y], name='test_bernoulli_double') +``` + +
+ + +
+bernoulli_with_seed + +```python +seed = np.float(0) +node = onnx.helper.make_node( + 'Bernoulli', + inputs=['x'], + outputs=['y'], + seed=seed, +) + +x = np.random.uniform(0.0, 1.0, 10).astype(np.float32) +y = bernoulli_reference_implementation(x, np.float32) +expect(node, inputs=[x], outputs=[y], name='test_bernoulli_seed') +``` + +
+ + +
+bernoulli_without_dtype + +```python +node = onnx.helper.make_node( + 'Bernoulli', + inputs=['x'], + outputs=['y'], +) + +x = np.random.uniform(0.0, 1.0, 10).astype(np.float) +y = bernoulli_reference_implementation(x, np.float) +expect(node, inputs=[x], outputs=[y], name='test_bernoulli') +``` + +
+ + +### **BitShift** + + Bitwise shift operator performs element-wise operation. For each input element, if the + attribute "direction" is "RIGHT", this operator moves its binary representation toward + the right side so that the input value is effectively decreased. If the attribute "direction" + is "LEFT", bits of binary representation moves toward the left side, which results the + increase of its actual value. The input X is the tensor to be shifted and another input + Y specifies the amounts of shifting. For example, if "direction" is "Right", X is [1, 4], + and S is [1, 1], the corresponding output Z would be [0, 2]. If "direction" is "LEFT" with + X=[1, 2] and S=[1, 2], the corresponding output Y would be [2, 8]. + + Because this operator supports Numpy-style broadcasting, X's and Y's shapes are + not necessarily identical. + This operator supports **multidirectional (i.e., Numpy-style) broadcasting**; for more details please check [the doc](Broadcasting.md). + +#### Version + +This version of the operator has been available since version 11 of the default ONNX operator set. + +#### Attributes + +
+
direction : string (required)
+
Direction of moving bits. It can be either "RIGHT" (for right shift) or "LEFT" (for left shift).
+
+ +#### Inputs + +
+
X (non-differentiable) : T
+
First operand, input to be shifted.
+
Y (non-differentiable) : T
+
Second operand, amounts of shift.
+
+ +#### Outputs + +
+
Z (non-differentiable) : T
+
Output tensor
+
+ +#### Type Constraints + +
+
T : tensor(uint8), tensor(uint16), tensor(uint32), tensor(uint64)
+
Constrain input and output types to integer tensors.
+
+ + +#### Examples + +
+left_unit16 + +```python +node = onnx.helper.make_node( + 'BitShift', + inputs=['x', 'y'], + outputs=['z'], + direction="LEFT" +) + +x = np.array([16, 4, 1]).astype(np.uint16) +y = np.array([1, 2, 3]).astype(np.uint16) +z = x << y # expected output [32, 16, 8] +expect(node, inputs=[x, y], outputs=[z], + name='test_bitshift_left_uint16') +``` + +
+ + +
+left_unit32 + +```python +node = onnx.helper.make_node( + 'BitShift', + inputs=['x', 'y'], + outputs=['z'], + direction="LEFT" +) + +x = np.array([16, 4, 1]).astype(np.uint32) +y = np.array([1, 2, 3]).astype(np.uint32) +z = x << y # expected output [32, 16, 8] +expect(node, inputs=[x, y], outputs=[z], + name='test_bitshift_left_uint32') +``` + +
+ + +
+left_unit64 + +```python +node = onnx.helper.make_node( + 'BitShift', + inputs=['x', 'y'], + outputs=['z'], + direction="LEFT" +) + +x = np.array([16, 4, 1]).astype(np.uint64) +y = np.array([1, 2, 3]).astype(np.uint64) +z = x << y # expected output [32, 16, 8] +expect(node, inputs=[x, y], outputs=[z], + name='test_bitshift_left_uint64') +``` + +
+ + +
+left_unit8 + +```python +node = onnx.helper.make_node( + 'BitShift', + inputs=['x', 'y'], + outputs=['z'], + direction="LEFT" +) + +x = np.array([16, 4, 1]).astype(np.uint8) +y = np.array([1, 2, 3]).astype(np.uint8) +z = x << y # expected output [32, 16, 8] +expect(node, inputs=[x, y], outputs=[z], + name='test_bitshift_left_uint8') +``` + +
+ + +
+right_unit16 + +```python +node = onnx.helper.make_node( + 'BitShift', + inputs=['x', 'y'], + outputs=['z'], + direction="RIGHT" +) + +x = np.array([16, 4, 1]).astype(np.uint16) +y = np.array([1, 2, 3]).astype(np.uint16) +z = x >> y # expected output [8, 1, 0] +expect(node, inputs=[x, y], outputs=[z], + name='test_bitshift_right_uint16') +``` + +
+ + +
+right_unit32 + +```python +node = onnx.helper.make_node( + 'BitShift', + inputs=['x', 'y'], + outputs=['z'], + direction="RIGHT" +) + +x = np.array([16, 4, 1]).astype(np.uint32) +y = np.array([1, 2, 3]).astype(np.uint32) +z = x >> y # expected output [8, 1, 0] +expect(node, inputs=[x, y], outputs=[z], + name='test_bitshift_right_uint32') +``` + +
+ + +
+right_unit64 + +```python +node = onnx.helper.make_node( + 'BitShift', + inputs=['x', 'y'], + outputs=['z'], + direction="RIGHT" +) + +x = np.array([16, 4, 1]).astype(np.uint64) +y = np.array([1, 2, 3]).astype(np.uint64) +z = x >> y # expected output [8, 1, 0] +expect(node, inputs=[x, y], outputs=[z], + name='test_bitshift_right_uint64') +``` + +
+ + +
+right_unit8 + +```python +node = onnx.helper.make_node( + 'BitShift', + inputs=['x', 'y'], + outputs=['z'], + direction="RIGHT" +) + +x = np.array([16, 4, 1]).astype(np.uint8) +y = np.array([1, 2, 3]).astype(np.uint8) +z = x >> y # expected output [8, 1, 0] +expect(node, inputs=[x, y], outputs=[z], + name='test_bitshift_right_uint8') +``` + +
+ + +### **Cast** + + The operator casts the elements of a given input tensor to a data type + specified by the 'to' argument and returns an output tensor of the same size in + the converted type. The 'to' argument must be one of the data types specified + in the 'DataType' enum field in the TensorProto message. + + Casting from string tensor in plain (e.g., "3.14" and "1000") and scientific numeric representations + (e.g., "1e-5" and "1E8") to float types is supported. For example, converting string "100.5" to an integer may + result 100. There are some string literals reserved for special floating-point values; + "+INF" (and "INF"), "-INF", and "NaN" are positive infinity, negative infinity, and not-a-number, respectively. + Any string which can exactly match "+INF" in a case-insensitive way would be mapped to positive infinite. Similarly, + this case-insensitive rule is applied to "INF" and "NaN". When casting from numeric tensors + to string tensors, plain floating-point representation (such as "314.15926") would be used. + Converting non-numerical-literal string such as "Hello World!" is an undefined behavior. Cases + of converting string representing floating-point arithmetic value, such as "2.718", to INT is an undefined behavior. + + Conversion from a numerical type to any numerical type is always allowed. + User must be aware of precision loss and value change caused by range difference between two types. + For example, a 64-bit float 3.1415926459 may be round to a 32-bit float 3.141592. Similarly, converting + an integer 36 to Boolean may produce 1 because we truncate bits which can't be stored in the targeted type. + +#### Version + +This version of the operator has been available since version 13 of the default ONNX operator set. + +Other versions of this operator: 1, 6, 9 + +#### Attributes + +
+
to : int (required)
+
The data type to which the elements of the input tensor are cast. Strictly must be one of the types from DataType enum in TensorProto
+
+ +#### Inputs + +
+
input (differentiable) : T1
+
Input tensor to be cast.
+
+ +#### Outputs + +
+
output (differentiable) : T2
+
Output tensor with the same shape as input with type specified by the 'to' argument
+
+ +#### Type Constraints + +
+
T1 : tensor(float16), tensor(float), tensor(double), tensor(int8), tensor(int16), tensor(int32), tensor(int64), tensor(uint8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(bool), tensor(string), tensor(bfloat16)
+
Constrain input types. Casting from complex is not supported.
+
T2 : tensor(float16), tensor(float), tensor(double), tensor(int8), tensor(int16), tensor(int32), tensor(int64), tensor(uint8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(bool), tensor(string), tensor(bfloat16)
+
Constrain output types. Casting to complex is not supported.
+
+ + +#### Examples + +
+cast + +```python +shape = (3, 4) +test_cases = [ + ('FLOAT', 'FLOAT16'), + ('FLOAT', 'DOUBLE'), + ('FLOAT16', 'FLOAT'), + ('FLOAT16', 'DOUBLE'), + ('DOUBLE', 'FLOAT'), + ('DOUBLE', 'FLOAT16'), + ('FLOAT', 'STRING'), + ('STRING', 'FLOAT'), + ('FLOAT', 'BFLOAT16'), + ('BFLOAT16', 'FLOAT'), +] + +for from_type, to_type in test_cases: + input_type_proto = None + output_type_proto = None + if 'BFLOAT16' == from_type or 'BFLOAT16' == to_type: + np_fp32 = np.array([u'0.47892547', u'0.48033667', u'0.49968487', u'0.81910545', + u'0.47031248', u'0.816468', u'0.21087195', u'0.7229038', + u'NaN', u'INF', u'+INF', u'-INF'], dtype=np.float32) + little_endisan = sys.byteorder == 'little' + np_uint16_view = np_fp32.view(dtype=np.uint16) + np_bfp16 = np_uint16_view[1::2] if little_endisan else np_uint16_view[0::2] + if 'BFLOAT16' == to_type: + assert from_type == 'FLOAT' + input = np_fp32.reshape([3, 4]) + output = np_bfp16.reshape([3, 4]) + input_type_proto = onnx.helper.make_tensor_type_proto(int(TensorProto.FLOAT), input.shape) + output_type_proto = onnx.helper.make_tensor_type_proto(int(TensorProto.BFLOAT16), output.shape) + else: + assert to_type == 'FLOAT' + input = np_bfp16.reshape([3, 4]) + #convert bfloat to FLOAT + np_fp32_zeros = np.zeros((len(np_bfp16) * 2,), dtype=np.uint16) + if little_endisan: + np_fp32_zeros[1::2] = np_bfp16 + else: + np_fp32_zeros[0::2] = np_bfp16 + np_fp32_from_bfloat = np_fp32_zeros.view(dtype=np.float32) + output = np_fp32_from_bfloat.reshape([3, 4]) + input_type_proto = onnx.helper.make_tensor_type_proto(int(TensorProto.BFLOAT16), input.shape) + output_type_proto = onnx.helper.make_tensor_type_proto(int(TensorProto.FLOAT), output.shape) + elif 'STRING' != from_type: + input = np.random.random_sample(shape).astype( + TENSOR_TYPE_TO_NP_TYPE[getattr(TensorProto, from_type)]) + if ('STRING' == to_type): + # Converting input to str, then give it object dtype for generating script + ss = [] + for i in input.flatten(): + s = str(i).encode('utf-8') + su = s.decode('utf-8') + ss.append(su) + + output = np.array(ss).astype(object).reshape([3, 4]) + else: + output = input.astype(TENSOR_TYPE_TO_NP_TYPE[getattr(TensorProto, to_type)]) + else: + input = np.array([u'0.47892547', u'0.48033667', u'0.49968487', u'0.81910545', + u'0.47031248', u'0.816468', u'0.21087195', u'0.7229038', + u'NaN', u'INF', u'+INF', u'-INF'], dtype=np.dtype(object)).reshape([3, 4]) + output = input.astype(TENSOR_TYPE_TO_NP_TYPE[getattr(TensorProto, to_type)]) + node = onnx.helper.make_node( + 'Cast', + inputs=['input'], + outputs=['output'], + to=getattr(TensorProto, to_type), + ) + if input_type_proto and output_type_proto: + expect(node, inputs=[input], outputs=[output], + name='test_cast_' + from_type + '_to_' + to_type, + input_type_protos=[input_type_proto], + output_type_protos=[output_type_proto]) + else: + expect(node, inputs=[input], outputs=[output], + name='test_cast_' + from_type + '_to_' + to_type) +``` + +
+ + +### **CastLike** + + The operator casts the elements of a given input tensor (the first input) to + the same data type as the elements of the second input tensor. + See documentation of the Cast operator for further details. + +#### Version + +This version of the operator has been available since version 15 of the default ONNX operator set. + +#### Inputs + +
+
input (differentiable) : T1
+
Input tensor to be cast.
+
target_type (non-differentiable) : T2
+
The (first) input tensor will be cast to produce a tensor of the same type as this (second input) tensor.
+
+ +#### Outputs + +
+
output (differentiable) : T2
+
Output tensor produced by casting the first input tensor to have the same type as the second input tensor.
+
+ +#### Type Constraints + +
+
T1 : tensor(float16), tensor(float), tensor(double), tensor(int8), tensor(int16), tensor(int32), tensor(int64), tensor(uint8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(bool), tensor(string), tensor(bfloat16)
+
Constrain input types. Casting from complex is not supported.
+
T2 : tensor(float16), tensor(float), tensor(double), tensor(int8), tensor(int16), tensor(int32), tensor(int64), tensor(uint8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(bool), tensor(string), tensor(bfloat16)
+
Constrain output types. Casting to complex is not supported.
+
+ + +#### Examples + +
+castlike + +```python +shape = (3, 4) +test_cases = [ + ('FLOAT', 'FLOAT16'), + ('FLOAT', 'DOUBLE'), + ('FLOAT16', 'FLOAT'), + ('FLOAT16', 'DOUBLE'), + ('DOUBLE', 'FLOAT'), + ('DOUBLE', 'FLOAT16'), + ('FLOAT', 'STRING'), + ('STRING', 'FLOAT'), + ('FLOAT', 'BFLOAT16'), + ('BFLOAT16', 'FLOAT'), +] + +for from_type, to_type in test_cases: + input_type_proto = None + output_type_proto = None + if 'BFLOAT16' == from_type or 'BFLOAT16' == to_type: + np_fp32 = np.array([u'0.47892547', u'0.48033667', u'0.49968487', u'0.81910545', + u'0.47031248', u'0.816468', u'0.21087195', u'0.7229038', + u'NaN', u'INF', u'+INF', u'-INF'], dtype=np.float32) + little_endisan = sys.byteorder == 'little' + np_uint16_view = np_fp32.view(dtype=np.uint16) + np_bfp16 = np_uint16_view[1::2] if little_endisan else np_uint16_view[0::2] + if 'BFLOAT16' == to_type: + assert from_type == 'FLOAT' + input = np_fp32.reshape([3, 4]) + output = np_bfp16.reshape([3, 4]) + input_type_proto = onnx.helper.make_tensor_type_proto(int(TensorProto.FLOAT), input.shape) + output_type_proto = onnx.helper.make_tensor_type_proto(int(TensorProto.BFLOAT16), output.shape) + else: + assert to_type == 'FLOAT' + input = np_bfp16.reshape([3, 4]) + #convert bfloat to FLOAT + np_fp32_zeros = np.zeros((len(np_bfp16) * 2,), dtype=np.uint16) + if little_endisan: + np_fp32_zeros[1::2] = np_bfp16 + else: + np_fp32_zeros[0::2] = np_bfp16 + np_fp32_from_bfloat = np_fp32_zeros.view(dtype=np.float32) + output = np_fp32_from_bfloat.reshape([3, 4]) + input_type_proto = onnx.helper.make_tensor_type_proto(int(TensorProto.BFLOAT16), input.shape) + output_type_proto = onnx.helper.make_tensor_type_proto(int(TensorProto.FLOAT), output.shape) + elif 'STRING' != from_type: + input = np.random.random_sample(shape).astype( + TENSOR_TYPE_TO_NP_TYPE[getattr(TensorProto, from_type)]) + if ('STRING' == to_type): + # Converting input to str, then give it np.object dtype for generating script + ss = [] + for i in input.flatten(): + s = str(i).encode('utf-8') + su = s.decode('utf-8') + ss.append(su) + + output = np.array(ss).astype(np.object).reshape([3, 4]) + else: + output = input.astype(TENSOR_TYPE_TO_NP_TYPE[getattr(TensorProto, to_type)]) + else: + input = np.array([u'0.47892547', u'0.48033667', u'0.49968487', u'0.81910545', + u'0.47031248', u'0.816468', u'0.21087195', u'0.7229038', + u'NaN', u'INF', u'+INF', u'-INF'], dtype=np.dtype(np.object)).reshape([3, 4]) + output = input.astype(TENSOR_TYPE_TO_NP_TYPE[getattr(TensorProto, to_type)]) + like = output.flatten()[0:1] + node = onnx.helper.make_node( + 'CastLike', + inputs=['input', 'like'], + outputs=['output'], + ) + if input_type_proto and output_type_proto: + expect(node, inputs=[input, like], outputs=[output], + name='test_castlike_' + from_type + '_to_' + to_type, + input_type_protos=[input_type_proto, output_type_proto], + output_type_protos=[output_type_proto]) + else: + expect(node, inputs=[input, like], outputs=[output], + name='test_castlike_' + from_type + '_to_' + to_type) +``` + +
+ + +### **Ceil** + + Ceil takes one input data (Tensor) and produces one output data + (Tensor) where the ceil is, y = ceil(x), is applied to + the tensor elementwise. + +#### Version + +This version of the operator has been available since version 13 of the default ONNX operator set. + +Other versions of this operator: 1, 6 + +#### Inputs + +
+
X (non-differentiable) : T
+
Input tensor
+
+ +#### Outputs + +
+
Y (non-differentiable) : T
+
Output tensor
+
+ +#### Type Constraints + +
+
T : tensor(float16), tensor(float), tensor(double), tensor(bfloat16)
+
Constrain input and output types to float tensors.
+
+ + +#### Examples + +
+ceil + +```python +node = onnx.helper.make_node( + 'Ceil', + inputs=['x'], + outputs=['y'], +) + +x = np.array([-1.5, 1.2]).astype(np.float32) +y = np.ceil(x) # expected output [-1., 2.] +expect(node, inputs=[x], outputs=[y], + name='test_ceil_example') + +x = np.random.randn(3, 4, 5).astype(np.float32) +y = np.ceil(x) +expect(node, inputs=[x], outputs=[y], + name='test_ceil') +``` + +
+ + +### **Celu** + + Continuously Differentiable Exponential Linear Units: + Perform the linear unit element-wise on the input tensor X + using formula: + + ``` + max(0,x) + min(0,alpha*(exp(x/alpha)-1)) + ``` + +#### Version + +This version of the operator has been available since version 12 of the default ONNX operator set. + +#### Attributes + +
+
alpha : float (default is 1.0)
+
The Alpha value in Celu formula which control the shape of the unit. The default value is 1.0.
+
+ +#### Inputs + +
+
X (differentiable) : T
+
Input tensor
+
+ +#### Outputs + +
+
Y (differentiable) : T
+
Output tensor
+
+ +#### Type Constraints + +
+
T : tensor(float)
+
Constrain input and output types to float32 tensors.
+
+ + +#### Examples + +
+celu + +```python +alpha = 2.0 +node = onnx.helper.make_node( + 'Celu', + inputs=['X'], + outputs=['Y'], + alpha=alpha, +) + +input_data = np.array([[[[0.8439683], [0.5665144], [0.05836735]], + [[0.02916367], [0.12964272], [0.5060197]], + [[0.79538304], [0.9411346], [0.9546573]]], + [[[0.17730942], [0.46192095], [0.26480448]], + [[0.6746842], [0.01665257], [0.62473077]], + [[0.9240844], [0.9722341], [0.11965699]]], + [[[0.41356155], [0.9129373], [0.59330076]], + [[0.81929934], [0.7862604], [0.11799799]], + [[0.69248444], [0.54119414], [0.07513223]]]], dtype=np.float32) + +# Calculate expected output data +positive_input = np.maximum(0, input_data) +negative_input = np.minimum(0, alpha * (np.exp(input_data / alpha) - 1)) +expected_output = positive_input + negative_input + +expect(node, inputs=[input_data], outputs=[expected_output], + name='test_celu') +``` + +
+ + +### **Clip** + + Clip operator limits the given input within an interval. The interval is + specified by the inputs 'min' and 'max'. They default to + numeric_limits::lowest() and numeric_limits::max(), respectively. + +#### Version + +This version of the operator has been available since version 13 of the default ONNX operator set. + +Other versions of this operator: 1, 6, 11, 12 + +#### Inputs (1 - 3) + +
+
input (differentiable) : T
+
Input tensor whose elements to be clipped
+
min (optional, non-differentiable) : T
+
Minimum value, under which element is replaced by min. It must be a scalar(tensor of empty shape).
+
max (optional, non-differentiable) : T
+
Maximum value, above which element is replaced by max. It must be a scalar(tensor of empty shape).
+
+ +#### Outputs + +
+
output (differentiable) : T
+
Output tensor with clipped input elements
+
+ +#### Type Constraints + +
+
T : tensor(uint8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(int8), tensor(int16), tensor(int32), tensor(int64), tensor(float16), tensor(float), tensor(double), tensor(bfloat16)
+
Constrain input and output types to all numeric tensors.
+
+ + +#### Examples + +
+clip + +```python +node = onnx.helper.make_node( + 'Clip', + inputs=['x', 'min', 'max'], + outputs=['y'], +) + +x = np.array([-2, 0, 2]).astype(np.float32) +min_val = np.float32(-1) +max_val = np.float32(1) +y = np.clip(x, min_val, max_val) # expected output [-1., 0., 1.] +expect(node, inputs=[x, min_val, max_val], outputs=[y], + name='test_clip_example') + +x = np.random.randn(3, 4, 5).astype(np.float32) +y = np.clip(x, min_val, max_val) +expect(node, inputs=[x, min_val, max_val], outputs=[y], + name='test_clip') +node = onnx.helper.make_node( + 'Clip', + inputs=['x', 'min', 'max'], + outputs=['y'], +) + +min_val = np.float32(-5) +max_val = np.float32(5) + +x = np.array([-1, 0, 1]).astype(np.float32) +y = np.array([-1, 0, 1]).astype(np.float32) +expect(node, inputs=[x, min_val, max_val], outputs=[y], + name='test_clip_inbounds') + +x = np.array([-6, 0, 6]).astype(np.float32) +y = np.array([-5, 0, 5]).astype(np.float32) +expect(node, inputs=[x, min_val, max_val], outputs=[y], + name='test_clip_outbounds') + +x = np.array([-1, 0, 6]).astype(np.float32) +y = np.array([-1, 0, 5]).astype(np.float32) +expect(node, inputs=[x, min_val, max_val], outputs=[y], + name='test_clip_splitbounds') +``` + +
+ + +
+clip_default + +```python +node = onnx.helper.make_node( + 'Clip', + inputs=['x', 'min'], + outputs=['y'], +) +min_val = np.float32(0) +x = np.random.randn(3, 4, 5).astype(np.float32) +y = np.clip(x, min_val, np.inf) +expect(node, inputs=[x, min_val], outputs=[y], + name='test_clip_default_min') + +no_min = "" # optional input, not supplied +node = onnx.helper.make_node( + 'Clip', + inputs=['x', no_min, 'max'], + outputs=['y'], +) +max_val = np.float32(0) +x = np.random.randn(3, 4, 5).astype(np.float32) +y = np.clip(x, -np.inf, max_val) +expect(node, inputs=[x, max_val], outputs=[y], + name='test_clip_default_max') + +no_max = "" # optional input, not supplied +node = onnx.helper.make_node( + 'Clip', + inputs=['x', no_min, no_max], + outputs=['y'], +) + +x = np.array([-1, 0, 1]).astype(np.float32) +y = np.array([-1, 0, 1]).astype(np.float32) +expect(node, inputs=[x], outputs=[y], + name='test_clip_default_inbounds') +``` + +
+ + +
+clip_default_int8 + +```python +node = onnx.helper.make_node( + 'Clip', + inputs=['x', 'min'], + outputs=['y'], +) +min_val = np.int8(0) +x = np.random.randn(3, 4, 5).astype(np.int8) +y = np.clip(x, min_val, np.iinfo(np.int8).max) +expect(node, inputs=[x, min_val], outputs=[y], + name='test_clip_default_int8_min') + +no_min = "" # optional input, not supplied +node = onnx.helper.make_node( + 'Clip', + inputs=['x', no_min, 'max'], + outputs=['y'], +) +max_val = np.int8(0) +x = np.random.randn(3, 4, 5).astype(np.int8) +y = np.clip(x, np.iinfo(np.int8).min, max_val) +expect(node, inputs=[x, max_val], outputs=[y], + name='test_clip_default_int8_max') + +no_max = "" # optional input, not supplied +node = onnx.helper.make_node( + 'Clip', + inputs=['x', no_min, no_max], + outputs=['y'], +) + +x = np.array([-1, 0, 1]).astype(np.int8) +y = np.array([-1, 0, 1]).astype(np.int8) +expect(node, inputs=[x], outputs=[y], + name='test_clip_default_int8_inbounds') +``` + +
+ + +### **Compress** + + Selects slices from an input tensor along a given axis where condition evaluates to True for each axis index. + In case axis is not provided, input is flattened before elements are selected. + Compress behaves like numpy.compress: https://docs.scipy.org/doc/numpy/reference/generated/numpy.compress.html + + +#### Version + +This version of the operator has been available since version 11 of the default ONNX operator set. + +Other versions of this operator: 9 + +#### Attributes + +
+
axis : int
+
(Optional) Axis along which to take slices. If not specified, input is flattened before elements being selected. Negative value means counting dimensions from the back. Accepted range is [-r, r-1] where r = rank(input).
+
+ +#### Inputs + +
+
input (differentiable) : T
+
Tensor of rank r >= 1.
+
condition (non-differentiable) : T1
+
Rank 1 tensor of booleans to indicate which slices or data elements to be selected. Its length can be less than the input length along the axis or the flattened input size if axis is not specified. In such cases data slices or elements exceeding the condition length are discarded.
+
+ +#### Outputs + +
+
output (differentiable) : T
+
Tensor of rank r if axis is specified. Otherwise output is a Tensor of rank 1.
+
+ +#### Type Constraints + +
+
T : tensor(uint8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(int8), tensor(int16), tensor(int32), tensor(int64), tensor(float16), tensor(float), tensor(double), tensor(string), tensor(bool), tensor(complex64), tensor(complex128)
+
Constrain input and output types to all tensor types.
+
T1 : tensor(bool)
+
Constrains to boolean tensors.
+
+ + +#### Examples + +
+compress_0 + +```python +node = onnx.helper.make_node( + 'Compress', + inputs=['input', 'condition'], + outputs=['output'], + axis=0, +) +input = np.array([[1, 2], [3, 4], [5, 6]]).astype(np.float32) +condition = np.array([0, 1, 1]) +output = np.compress(condition, input, axis=0) +#print(output) +#[[ 3. 4.] +# [ 5. 6.]] + +expect(node, inputs=[input, condition.astype(bool)], outputs=[output], + name='test_compress_0') +``` + +
+ + +
+compress_1 + +```python +node = onnx.helper.make_node( + 'Compress', + inputs=['input', 'condition'], + outputs=['output'], + axis=1, +) +input = np.array([[1, 2], [3, 4], [5, 6]]).astype(np.float32) +condition = np.array([0, 1]) +output = np.compress(condition, input, axis=1) +#print(output) +#[[ 2.] +# [ 4.] +# [ 6.]] + +expect(node, inputs=[input, condition.astype(bool)], outputs=[output], + name='test_compress_1') +``` + +
+ + +
+compress_default_axis + +```python +node = onnx.helper.make_node( + 'Compress', + inputs=['input', 'condition'], + outputs=['output'], +) +input = np.array([[1, 2], [3, 4], [5, 6]]).astype(np.float32) +condition = np.array([0, 1, 0, 0, 1]) +output = np.compress(condition, input) +#print(output) +#[ 2., 5.] + +expect(node, inputs=[input, condition.astype(bool)], outputs=[output], + name='test_compress_default_axis') +``` + +
+ + +
+compress_negative_axis + +```python +node = onnx.helper.make_node( + 'Compress', + inputs=['input', 'condition'], + outputs=['output'], + axis=-1, +) +input = np.array([[1, 2], [3, 4], [5, 6]]).astype(np.float32) +condition = np.array([0, 1]) +output = np.compress(condition, input, axis=-1) +# print(output) +#[[ 2.] +# [ 4.] +# [ 6.]] +expect(node, inputs=[input, condition.astype(bool)], outputs=[output], + name='test_compress_negative_axis') +``` + +
+ + +### **Concat** + + Concatenate a list of tensors into a single tensor. All input tensors must have the same shape, except for the dimension size of the axis to concatenate on. + +#### Version + +This version of the operator has been available since version 13 of the default ONNX operator set. + +Other versions of this operator: 1, 4, 11 + +#### Attributes + +
+
axis : int (required)
+
Which axis to concat on. A negative value means counting dimensions from the back. Accepted range is [-r, r-1] where r = rank(inputs)..
+
+ +#### Inputs (1 - ∞) + +
+
inputs (variadic, differentiable) : T
+
List of tensors for concatenation
+
+ +#### Outputs + +
+
concat_result (differentiable) : T
+
Concatenated tensor
+
+ +#### Type Constraints + +
+
T : tensor(uint8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(int8), tensor(int16), tensor(int32), tensor(int64), tensor(bfloat16), tensor(float16), tensor(float), tensor(double), tensor(string), tensor(bool), tensor(complex64), tensor(complex128)
+
Constrain output types to any tensor type.
+
+ + +#### Examples + +
+concat + +```python +test_cases = { + '1d': ([1, 2], + [3, 4]), + '2d': ([[1, 2], [3, 4]], + [[5, 6], [7, 8]]), + '3d': ([[[1, 2], [3, 4]], [[5, 6], [7, 8]]], + [[[9, 10], [11, 12]], [[13, 14], [15, 16]]]) +} # type: Dict[Text, Sequence[Any]] + +for test_case, values_ in test_cases.items(): + values = [np.asarray(v, dtype=np.float32) for v in values_] + for i in range(len(values[0].shape)): + in_args = ['value' + str(k) for k in range(len(values))] + node = onnx.helper.make_node( + 'Concat', + inputs=[s for s in in_args], + outputs=['output'], + axis=i + ) + output = np.concatenate(values, i) + expect(node, inputs=[v for v in values], outputs=[output], + name='test_concat_' + test_case + '_axis_' + str(i)) + + for i in range(-len(values[0].shape), 0): + in_args = ['value' + str(k) for k in range(len(values))] + node = onnx.helper.make_node( + 'Concat', + inputs=[s for s in in_args], + outputs=['output'], + axis=i + ) + output = np.concatenate(values, i) + expect(node, inputs=[v for v in values], outputs=[output], + name='test_concat_' + test_case + '_axis_negative_' + str(abs(i))) +``` + +
+ + +### **ConcatFromSequence** + + Concatenate a sequence of tensors into a single tensor. + All input tensors must have the same shape, except for the dimension size of the axis to concatenate on. + By default 'new_axis' is 0, the behavior is similar to numpy.concatenate. + When 'new_axis' is 1, the behavior is similar to numpy.stack. + +#### Version + +This version of the operator has been available since version 11 of the default ONNX operator set. + +#### Attributes + +
+
axis : int (required)
+
Which axis to concat on. Accepted range in `[-r, r - 1]`, where `r` is the rank of input tensors. When `new_axis` is 1, accepted range is `[-r - 1, r]`.
+
new_axis : int (default is 0)
+
Insert and concatenate on a new axis or not, default 0 means do not insert new axis.
+
+ +#### Inputs + +
+
input_sequence : S
+
Sequence of tensors for concatenation
+
+ +#### Outputs + +
+
concat_result : T
+
Concatenated tensor
+
+ +#### Type Constraints + +
+
S : seq(tensor(uint8)), seq(tensor(uint16)), seq(tensor(uint32)), seq(tensor(uint64)), seq(tensor(int8)), seq(tensor(int16)), seq(tensor(int32)), seq(tensor(int64)), seq(tensor(float16)), seq(tensor(float)), seq(tensor(double)), seq(tensor(string)), seq(tensor(bool)), seq(tensor(complex64)), seq(tensor(complex128))
+
Constrain input types to any tensor type.
+
T : tensor(uint8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(int8), tensor(int16), tensor(int32), tensor(int64), tensor(float16), tensor(float), tensor(double), tensor(string), tensor(bool), tensor(complex64), tensor(complex128)
+
Constrain output types to any tensor type.
+
+ + +### **Constant** + + This operator produces a constant tensor. Exactly one of the provided attributes, either value, sparse_value, + or value_* must be specified. + +#### Version + +This version of the operator has been available since version 13 of the default ONNX operator set. + +Other versions of this operator: 1, 9, 11, 12 + +#### Attributes + +
+
sparse_value : sparse_tensor
+
The value for the elements of the output tensor in sparse format.
+
value : tensor
+
The value for the elements of the output tensor.
+
value_float : float
+
The value for the sole element for the scalar, float32, output tensor.
+
value_floats : list of floats
+
The values for the elements for the 1D, float32, output tensor.
+
value_int : int
+
The value for the sole element for the scalar, int64, output tensor.
+
value_ints : list of ints
+
The values for the elements for the 1D, int64, output tensor.
+
value_string : string
+
The value for the sole element for the scalar, UTF-8 string, output tensor.
+
value_strings : list of strings
+
The values for the elements for the 1D, UTF-8 string, output tensor.
+
+ +#### Inputs + + +#### Outputs + +
+
output : T
+
Output tensor containing the same value of the provided tensor.
+
+ +#### Type Constraints + +
+
T : tensor(uint8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(int8), tensor(int16), tensor(int32), tensor(int64), tensor(bfloat16), tensor(float16), tensor(float), tensor(double), tensor(string), tensor(bool), tensor(complex64), tensor(complex128)
+
Constrain input and output types to all tensor types.
+
+ + +#### Examples + +
+constant + +```python +values = np.random.randn(5, 5).astype(np.float32) +node = onnx.helper.make_node( + 'Constant', + inputs=[], + outputs=['values'], + value=onnx.helper.make_tensor( + name='const_tensor', + data_type=onnx.TensorProto.FLOAT, + dims=values.shape, + vals=values.flatten().astype(float), + ), +) + +expect(node, inputs=[], outputs=[values], + name='test_constant') +``` + +
+ + +### **ConstantOfShape** + + Generate a tensor with given value and shape. + +#### Version + +This version of the operator has been available since version 9 of the default ONNX operator set. + +#### Attributes + +
+
value : tensor
+
(Optional) The value of the output elements.Should be a one-element tensor. If not specified, it defaults to a tensor of value 0 and datatype float32
+
+ +#### Inputs + +
+
input : T1
+
1D tensor. The shape of the expected output tensor. If empty tensor is given, the output would be a scalar. All values must be >= 0.
+
+ +#### Outputs + +
+
output : T2
+
Output tensor of shape specified by 'input'.If attribute 'value' is specified, the value and datatype of the output tensor is taken from 'value'.If attribute 'value' is not specified, the value in the output defaults to 0, and the datatype defaults to float32.
+
+ +#### Type Constraints + +
+
T1 : tensor(int64)
+
Constrain input types.
+
T2 : tensor(float16), tensor(float), tensor(double), tensor(int8), tensor(int16), tensor(int32), tensor(int64), tensor(uint8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(bool)
+
Constrain output types to be numerics.
+
+ + +#### Examples + +
+float_ones + +```python +x = np.array([4, 3, 2]).astype(np.int64) +tensor_value = onnx.helper.make_tensor("value", onnx.TensorProto.FLOAT, + [1], [1]) +node = onnx.helper.make_node( + 'ConstantOfShape', + inputs=['x'], + outputs=['y'], + value=tensor_value, +) + +y = np.ones(x, dtype=np.float32) +expect(node, inputs=[x], outputs=[y], + name='test_constantofshape_float_ones') +``` + +
+ + +
+int32_shape_zero + +```python +x = np.array([0, ]).astype(np.int64) +tensor_value = onnx.helper.make_tensor("value", onnx.TensorProto.INT32, + [1], [0]) +node = onnx.helper.make_node( + 'ConstantOfShape', + inputs=['x'], + outputs=['y'], + value=tensor_value, +) +y = np.zeros(x, dtype=np.int32) +expect(node, inputs=[x], outputs=[y], + name='test_constantofshape_int_shape_zero') +``` + +
+ + +
+int32_zeros + +```python +x = np.array([10, 6]).astype(np.int64) +tensor_value = onnx.helper.make_tensor("value", onnx.TensorProto.INT32, + [1], [0]) +node = onnx.helper.make_node( + 'ConstantOfShape', + inputs=['x'], + outputs=['y'], + value=tensor_value, +) +y = np.zeros(x, dtype=np.int32) +expect(node, inputs=[x], outputs=[y], + name='test_constantofshape_int_zeros') +``` + +
+ + +### **Conv** + + The convolution operator consumes an input tensor and a filter, and + computes the output. + +#### Version + +This version of the operator has been available since version 11 of the default ONNX operator set. + +Other versions of this operator: 1 + +#### Attributes + +
+
auto_pad : string (default is NOTSET)
+
auto_pad must be either NOTSET, SAME_UPPER, SAME_LOWER or VALID. Where default value is NOTSET, which means explicit padding is used. SAME_UPPER or SAME_LOWER mean pad the input so that `output_shape[i] = ceil(input_shape[i] / strides[i])` for each axis `i`. The padding is split between the two sides equally or almost equally (depending on whether it is even or odd). In case the padding is an odd number, the extra padding is added at the end for SAME_UPPER and at the beginning for SAME_LOWER.
+
dilations : list of ints
+
dilation value along each spatial axis of the filter. If not present, the dilation defaults is 1 along each spatial axis.
+
group : int (default is 1)
+
number of groups input channels and output channels are divided into.
+
kernel_shape : list of ints
+
The shape of the convolution kernel. If not present, should be inferred from input W.
+
pads : list of ints
+
Padding for the beginning and ending along each spatial axis, it can take any value greater than or equal to 0. The value represent the number of pixels added to the beginning and end part of the corresponding axis. `pads` format should be as follow [x1_begin, x2_begin...x1_end, x2_end,...], where xi_begin the number of pixels added at the beginning of axis `i` and xi_end, the number of pixels added at the end of axis `i`. This attribute cannot be used simultaneously with auto_pad attribute. If not present, the padding defaults to 0 along start and end of each spatial axis.
+
strides : list of ints
+
Stride along each spatial axis. If not present, the stride defaults is 1 along each spatial axis.
+
+ +#### Inputs (2 - 3) + +
+
X (differentiable) : T
+
Input data tensor from previous layer; has size (N x C x H x W), where N is the batch size, C is the number of channels, and H and W are the height and width. Note that this is for the 2D image. Otherwise the size is (N x C x D1 x D2 ... x Dn). Optionally, if dimension denotation is in effect, the operation expects input data tensor to arrive with the dimension denotation of [DATA_BATCH, DATA_CHANNEL, DATA_FEATURE, DATA_FEATURE ...].
+
W (differentiable) : T
+
The weight tensor that will be used in the convolutions; has size (M x C/group x kH x kW), where C is the number of channels, and kH and kW are the height and width of the kernel, and M is the number of feature maps. For more than 2 dimensions, the kernel shape will be (M x C/group x k1 x k2 x ... x kn), where (k1 x k2 x ... kn) is the dimension of the kernel. Optionally, if dimension denotation is in effect, the operation expects the weight tensor to arrive with the dimension denotation of [FILTER_OUT_CHANNEL, FILTER_IN_CHANNEL, FILTER_SPATIAL, FILTER_SPATIAL ...]. Assuming zero based indices for the shape array, X.shape[1] == (W.shape[1] * group) == C and W.shape[0] mod G == 0. Or in other words FILTER_IN_CHANNEL multiplied by the number of groups should be equal to DATA_CHANNEL and the number of feature maps M should be a multiple of the number of groups G.
+
B (optional, differentiable) : T
+
Optional 1D bias to be added to the convolution, has size of M.
+
+ +#### Outputs + +
+
Y (differentiable) : T
+
Output data tensor that contains the result of the convolution. The output dimensions are functions of the kernel size, stride size, and pad lengths.
+
+ +#### Type Constraints + +
+
T : tensor(float16), tensor(float), tensor(double)
+
Constrain input and output types to float tensors.
+
+ + +#### Examples + +
+conv + +```python + +x = np.array([[[[0., 1., 2., 3., 4.], # (1, 1, 5, 5) input tensor + [5., 6., 7., 8., 9.], + [10., 11., 12., 13., 14.], + [15., 16., 17., 18., 19.], + [20., 21., 22., 23., 24.]]]]).astype(np.float32) +W = np.array([[[[1., 1., 1.], # (1, 1, 3, 3) tensor for convolution weights + [1., 1., 1.], + [1., 1., 1.]]]]).astype(np.float32) + +# Convolution with padding +node_with_padding = onnx.helper.make_node( + 'Conv', + inputs=['x', 'W'], + outputs=['y'], + kernel_shape=[3, 3], + # Default values for other attributes: strides=[1, 1], dilations=[1, 1], groups=1 + pads=[1, 1, 1, 1], +) +y_with_padding = np.array([[[[12., 21., 27., 33., 24.], # (1, 1, 5, 5) output tensor + [33., 54., 63., 72., 51.], + [63., 99., 108., 117., 81.], + [93., 144., 153., 162., 111.], + [72., 111., 117., 123., 84.]]]]).astype(np.float32) +expect(node_with_padding, inputs=[x, W], outputs=[y_with_padding], + name='test_basic_conv_with_padding') + +# Convolution without padding +node_without_padding = onnx.helper.make_node( + 'Conv', + inputs=['x', 'W'], + outputs=['y'], + kernel_shape=[3, 3], + # Default values for other attributes: strides=[1, 1], dilations=[1, 1], groups=1 + pads=[0, 0, 0, 0], +) +y_without_padding = np.array([[[[54., 63., 72.], # (1, 1, 3, 3) output tensor + [99., 108., 117.], + [144., 153., 162.]]]]).astype(np.float32) +expect(node_without_padding, inputs=[x, W], outputs=[y_without_padding], + name='test_basic_conv_without_padding') +``` + +
+ + +
+conv_with_autopad_same + +```python + +x = np.array([[[[0., 1., 2., 3., 4.], # (1, 1, 5, 5) input tensor + [5., 6., 7., 8., 9.], + [10., 11., 12., 13., 14.], + [15., 16., 17., 18., 19.], + [20., 21., 22., 23., 24.]]]]).astype(np.float32) +W = np.array([[[[1., 1., 1.], # (1, 1, 3, 3) tensor for convolution weights + [1., 1., 1.], + [1., 1., 1.]]]]).astype(np.float32) + +# Convolution with auto_pad='SAME_LOWER' and strides=2 +node = onnx.helper.make_node( + 'Conv', + inputs=['x', 'W'], + outputs=['y'], + auto_pad='SAME_LOWER', + kernel_shape=[3, 3], + strides=[2, 2], +) +y = np.array([[[[12., 27., 24.], + [63., 108., 81.], + [72., 117., 84.]]]]).astype(np.float32) +expect(node, inputs=[x, W], outputs=[y], + name='test_conv_with_autopad_same') +``` + +
+ + +
+conv_with_strides + +```python + +x = np.array([[[[0., 1., 2., 3., 4.], # (1, 1, 7, 5) input tensor + [5., 6., 7., 8., 9.], + [10., 11., 12., 13., 14.], + [15., 16., 17., 18., 19.], + [20., 21., 22., 23., 24.], + [25., 26., 27., 28., 29.], + [30., 31., 32., 33., 34.]]]]).astype(np.float32) +W = np.array([[[[1., 1., 1.], # (1, 1, 3, 3) tensor for convolution weights + [1., 1., 1.], + [1., 1., 1.]]]]).astype(np.float32) + +# Convolution with strides=2 and padding +node_with_padding = onnx.helper.make_node( + 'Conv', + inputs=['x', 'W'], + outputs=['y'], + kernel_shape=[3, 3], + pads=[1, 1, 1, 1], + strides=[2, 2], # Default values for other attributes: dilations=[1, 1], groups=1 +) +y_with_padding = np.array([[[[12., 27., 24.], # (1, 1, 4, 3) output tensor + [63., 108., 81.], + [123., 198., 141.], + [112., 177., 124.]]]]).astype(np.float32) +expect(node_with_padding, inputs=[x, W], outputs=[y_with_padding], + name='test_conv_with_strides_padding') + +# Convolution with strides=2 and no padding +node_without_padding = onnx.helper.make_node( + 'Conv', + inputs=['x', 'W'], + outputs=['y'], + kernel_shape=[3, 3], + pads=[0, 0, 0, 0], + strides=[2, 2], # Default values for other attributes: dilations=[1, 1], groups=1 +) +y_without_padding = np.array([[[[54., 72.], # (1, 1, 3, 2) output tensor + [144., 162.], + [234., 252.]]]]).astype(np.float32) +expect(node_without_padding, inputs=[x, W], outputs=[y_without_padding], + name='test_conv_with_strides_no_padding') + +# Convolution with strides=2 and padding only along one dimension (the H dimension in NxCxHxW tensor) +node_with_asymmetric_padding = onnx.helper.make_node( + 'Conv', + inputs=['x', 'W'], + outputs=['y'], + kernel_shape=[3, 3], + pads=[1, 0, 1, 0], + strides=[2, 2], # Default values for other attributes: dilations=[1, 1], groups=1 +) +y_with_asymmetric_padding = np.array([[[[21., 33.], # (1, 1, 4, 2) output tensor + [99., 117.], + [189., 207.], + [171., 183.]]]]).astype(np.float32) +expect(node_with_asymmetric_padding, inputs=[x, W], outputs=[y_with_asymmetric_padding], + name='test_conv_with_strides_and_asymmetric_padding') +``` + +
+ + +### **ConvInteger** + + The integer convolution operator consumes an input tensor, its zero-point, a filter, and its zero-point, + and computes the output. The production MUST never overflow. The accumulation may overflow if and only if in 32 bits. + +#### Version + +This version of the operator has been available since version 10 of the default ONNX operator set. + +#### Attributes + +
+
auto_pad : string (default is NOTSET)
+
auto_pad must be either NOTSET, SAME_UPPER, SAME_LOWER or VALID. Where default value is NOTSET, which means explicit padding is used. SAME_UPPER or SAME_LOWER mean pad the input so that `output_shape[i] = ceil(input_shape[i] / strides[i])` for each axis `i`. The padding is split between the two sides equally or almost equally (depending on whether it is even or odd). In case the padding is an odd number, the extra padding is added at the end for SAME_UPPER and at the beginning for SAME_LOWER.
+
dilations : list of ints
+
dilation value along each spatial axis of the filter. If not present, the dilation defaults to 1 along each axis.
+
group : int (default is 1)
+
number of groups input channels and output channels are divided into. default is 1.
+
kernel_shape : list of ints
+
The shape of the convolution kernel. If not present, should be inferred from input 'w'.
+
pads : list of ints
+
Padding for the beginning and ending along each spatial axis, it can take any value greater than or equal to 0.The value represent the number of pixels added to the beginning and end part of the corresponding axis.`pads` format should be as follow [x1_begin, x2_begin...x1_end, x2_end,...], where xi_begin the number ofpixels added at the beginning of axis `i` and xi_end, the number of pixels added at the end of axis `i`.This attribute cannot be used simultaneously with auto_pad attribute. If not present, the padding defaultsto 0 along start and end of each spatial axis.
+
strides : list of ints
+
Stride along each spatial axis. If not present, the stride defaults to 1 along each axis.
+
+ +#### Inputs (2 - 4) + +
+
x : T1
+
Input data tensor from previous layer; has size (N x C x H x W), where N is the batch size, C is the number of channels, and H and W are the height and width. Note that this is for the 2D image. Otherwise the size is (N x C x D1 x D2 ... x Dn). Optionally, if dimension denotation is in effect, the operation expects input data tensor to arrive with the dimension denotation of [DATA_BATCH, DATA_CHANNEL, DATA_FEATURE, DATA_FEATURE ...].
+
w : T2
+
The weight tensor that will be used in the convolutions; has size (M x C/group x kH x kW), where C is the number of channels, and kH and kW are the height and width of the kernel, and M is the number of feature maps. For more than 2 dimensions, the kernel shape will be (M x C/group x k1 x k2 x ... x kn), where (k1 x k2 x ... kn) is the dimension of the kernel. Optionally, if dimension denotation is in effect, the operation expects the weight tensor to arrive with the dimension denotation of [FILTER_OUT_CHANNEL, FILTER_IN_CHANNEL, FILTER_SPATIAL, FILTER_SPATIAL ...]. X.shape[1] == (W.shape[1] * group) == C (assuming zero based indices for the shape array). Or in other words FILTER_IN_CHANNEL should be equal to DATA_CHANNEL.
+
x_zero_point (optional) : T1
+
Zero point tensor for input 'x'. It's optional and default value is 0. It's a scalar, which means a per-tensor/layer quantization.
+
w_zero_point (optional) : T2
+
Zero point tensor for input 'w'. It's optional and default value is 0. It could be a scalar or a 1-D tensor, which means a per-tensor/layer or per output channel quantization. If it's a 1-D tensor, its number of elements should be equal to the number of output channels (M)
+
+ +#### Outputs + +
+
y : T3
+
Output data tensor that contains the result of the convolution. The output dimensions are functions of the kernel size, stride size, and pad lengths.
+
+ +#### Type Constraints + +
+
T1 : tensor(int8), tensor(uint8)
+
Constrain input x and its zero point data type to 8-bit integer tensor.
+
T2 : tensor(int8), tensor(uint8)
+
Constrain input w and its zero point data type to 8-bit integer tensor.
+
T3 : tensor(int32)
+
Constrain output y data type to 32-bit integer tensor.
+
+ + +#### Examples + +
+with_padding + +```python + +x = np.array([2, 3, 4, 5, 6, 7, 8, 9, 10]).astype(np.uint8).reshape((1, 1, 3, 3)) +x_zero_point = np.uint8(1) +w = np.array([1, 1, 1, 1]).astype(np.uint8).reshape((1, 1, 2, 2)) + +y = np.array([1, 3, 5, 3, 5, 12, 16, 9, 11, 24, 28, 15, 7, 15, 17, 9]).astype(np.int32).reshape((1, 1, 4, 4)) + +# ConvInteger with padding +convinteger_node_with_padding = onnx.helper.make_node('ConvInteger', + inputs=['x', 'w', 'x_zero_point'], + outputs=['y'], + pads=[1, 1, 1, 1],) + +expect(convinteger_node_with_padding, inputs=[x, w, x_zero_point], outputs=[y], + name='test_convinteger_with_padding') +``` + +
+ + +
+without_padding + +```python + +x = np.array([2, 3, 4, 5, 6, 7, 8, 9, 10]).astype(np.uint8).reshape((1, 1, 3, 3)) +x_zero_point = np.uint8(1) +w = np.array([1, 1, 1, 1]).astype(np.uint8).reshape((1, 1, 2, 2)) + +y = np.array([12, 16, 24, 28]).astype(np.int32).reshape(1, 1, 2, 2) + +# ConvInteger without padding +convinteger_node = onnx.helper.make_node('ConvInteger', + inputs=['x', 'w', 'x_zero_point'], + outputs=['y']) + +expect(convinteger_node, inputs=[x, w, x_zero_point], outputs=[y], + name='test_convinteger_without_padding') +``` + +
+ + +### **ConvTranspose** + + The convolution transpose operator consumes an input tensor and a filter, + and computes the output. + + If the pads parameter is provided the shape of the output is calculated via the following equation: + + 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] + + output_shape can also be explicitly specified in which case pads values are auto generated using these equations: + + total_padding[i] = stride[i] * (input_size[i] - 1) + output_padding[i] + ((kernel_shape[i] - 1) * dilations[i] + 1) - output_shape[i] + If (auto_pads == SAME_UPPER): pads[start_i] = total_padding[i]/2; pads[end_i] = total_padding[i] - (total_padding[i]/2) + Else: pads[start_i] = total_padding[i] - (total_padding[i]/2); pads[end_i] = (total_padding[i]/2). + + + +#### Version + +This version of the operator has been available since version 11 of the default ONNX operator set. + +Other versions of this operator: 1 + +#### Attributes + +
+
auto_pad : string (default is NOTSET)
+
auto_pad must be either NOTSET, SAME_UPPER, SAME_LOWER or VALID. Where default value is NOTSET, which means explicit padding is used. SAME_UPPER or SAME_LOWER mean pad the input so that `output_shape[i] = input_shape[i] * strides[i]` for each axis `i`. The padding is split between the two sides equally or almost equally (depending on whether it is even or odd). In case the padding is an odd number, the extra padding is added at the end for SAME_UPPER and at the beginning for SAME_LOWER.
+
dilations : list of ints
+
dilation value along each spatial axis of the filter. If not present, the dilation defaults to 1 along each spatial axis.
+
group : int (default is 1)
+
number of groups input channels and output channels are divided into.
+
kernel_shape : list of ints
+
The shape of the convolution kernel. If not present, should be inferred from input W.
+
output_padding : list of ints
+
Additional elements added to the side with higher coordinate indices in the output. Each padding value in "output_padding" must be less than the corresponding stride/dilation dimension. By default, this attribute is a zero vector. Note that this attribute doesn't directly affect the computed output values. It only controls the selection of the computed values, so changing this attribute only adds or removes output elements. If "output_shape" is explicitly provided, "output_padding" does not contribute additional size to "output_shape" but participates in the computation of the needed padding amount. This is also called adjs or adjustment in some frameworks.
+
output_shape : list of ints
+
The shape of the output can be explicitly set which will cause pads values to be auto generated. If output_shape is specified pads values are ignored. See doc for details for equations to generate pads
+
pads : list of ints
+
Padding for the beginning and ending along each spatial axis, it can take any value greater than or equal to 0. The value represent the number of pixels added to the beginning and end part of the corresponding axis. `pads` format should be as follow [x1_begin, x2_begin...x1_end, x2_end,...], where xi_begin the number of pixels added at the beginning of axis `i` and xi_end, the number of pixels added at the end of axis `i`. This attribute cannot be used simultaneously with auto_pad attribute. If not present, the padding defaults to 0 along start and end of each spatial axis.
+
strides : list of ints
+
Stride along each spatial axis. If not present, the stride defaults to 1 along each spatial axis.
+
+ +#### Inputs (2 - 3) + +
+
X (differentiable) : T
+
Input data tensor from previous layer; has size (N x C x H x W), where N is the batch size, C is the number of channels, and H and W are the height and width. Note that this is for the 2D image. Otherwise the size is (N x C x D1 x D2 ... x Dn)
+
W (differentiable) : T
+
The weight tensor that will be used in the convolutions; has size (C x M/group x kH x kW), where C is the number of channels, and kH and kW are the height and width of the kernel, and M is the number of feature maps. For more than 2 dimensions, the weight shape will be (C x M/group x k1 x k2 x ... x kn), where (k1 x k2 x ... x kn) is the dimension of the kernel. The number of channels in the output should be equal to W.shape[1] * group (assuming zero based indices of the shape array)
+
B (optional, differentiable) : T
+
Optional 1D bias to be added to the convolution, has size of M.
+
+ +#### Outputs + +
+
Y (differentiable) : T
+
Output data tensor that contains the result of the convolution. The output dimensions are functions of the kernel size, stride size, pad lengths and group count. The number of channels in the output should be equal to W.shape[1] * group (assuming zero based indices of the shape array)
+
+ +#### Type Constraints + +
+
T : tensor(float16), tensor(float), tensor(double)
+
Constrain input and output types to float tensors.
+
+ + +#### Examples + +
+convtranspose + +```python +x = np.array([[[[0., 1., 2.], # (1, 1, 3, 3) + [3., 4., 5.], + [6., 7., 8.]]]]).astype(np.float32) + +W = np.array([[[[1., 1., 1.], # (1, 2, 3, 3) + [1., 1., 1.], + [1., 1., 1.]], + [[1., 1., 1.], + [1., 1., 1.], + [1., 1., 1.]]]]).astype(np.float32) + +node = onnx.helper.make_node("ConvTranspose", ["X", "W"], ["Y"]) + +y = np.array([[[[0., 1., 3., 3., 2.], # (1, 2, 5, 5) + [3., 8., 15., 12., 7.], + [9., 21., 36., 27., 15.], + [9., 20., 33., 24., 13.], + [6., 13., 21., 15., 8.]], + + [[0., 1., 3., 3., 2.], + [3., 8., 15., 12., 7.], + [9., 21., 36., 27., 15.], + [9., 20., 33., 24., 13.], + [6., 13., 21., 15., 8.]]]]).astype(np.float32) + +expect(node, inputs=[x, W], outputs=[y], name='test_convtranspose') +``` + +
+ + +
+convtranspose_1d + +```python +x = np.array([[[0., 1., 2.]]]).astype(np.float32) # (1, 1, 3) + +W = np.array([[[1., 1., 1.], # (1, 2, 3) + [1., 1., 1.]]]).astype(np.float32) + +node = onnx.helper.make_node("ConvTranspose", ["X", "W"], ["Y"]) + +y = np.array([[[0., 1., 3., 3., 2.], # (1, 2, 5) + [0., 1., 3., 3., 2.]]]).astype(np.float32) + +expect(node, inputs=[x, W], outputs=[y], name='test_convtranspose_1d') +``` + +
+ + +
+convtranspose_3d + +```python +x = np.array([[[[[0., 1., 2., 3., 4.], # (1, 1, 3, 4, 5) + [5., 6., 7., 8., 9.], + [10., 11., 12., 13., 14.], + [15., 16., 17., 18., 19.]], + [[20., 21., 22., 23., 24.], + [25., 26., 27., 28., 29.], + [30., 31., 32., 33., 34.], + [35., 36., 37., 38., 39.]], + [[40., 41., 42., 43., 44.], + [45., 46., 47., 48., 49.], + [50., 51., 52., 53., 54.], + [55., 56., 57., 58., 59.]]]]]).astype(np.float32) + +W = np.array([[[[[1., 1., 1.], # (1, 2, 3, 3, 3) + [1., 1., 1.], + [1., 1., 1.]], + [[1., 1., 1.], + [1., 1., 1.], + [1., 1., 1.]], + [[1., 1., 1.], + [1., 1., 1.], + [1., 1., 1.]]], + [[[1., 1., 1.], + [1., 1., 1.], + [1., 1., 1.]], + [[1., 1., 1.], + [1., 1., 1.], + [1., 1., 1.]], + [[1., 1., 1.], + [1., 1., 1.], + [1., 1., 1.]]]]]).astype(np.float32) + +node = onnx.helper.make_node("ConvTranspose", ["X", "W"], ["Y"]) + +y = np.array([[[[[0., 1., 3., 6., 9., 7., 4.], # (1, 2, 5, 6, 7) + [5., 12., 21., 27., 33., 24., 13.], + [15., 33., 54., 63., 72., 51., 27.], + [30., 63., 99., 108., 117., 81., 42.], + [25., 52., 81., 87., 93., 64., 33.], + [15., 31., 48., 51., 54., 37., 19.]], + + [[20., 42., 66., 72., 78., 54., 28.], + [50., 104., 162., 174., 186., 128., 66.], + [90., 186., 288., 306., 324., 222., 114.], + [120., 246., 378., 396., 414., 282., 144.], + [90., 184., 282., 294., 306., 208., 106.], + [50., 102., 156., 162., 168., 114., 58.]], + + [[60., 123., 189., 198., 207., 141., 72.], + [135., 276., 423., 441., 459., 312., 159.], + [225., 459., 702., 729., 756., 513., 261.], + [270., 549., 837., 864., 891., 603., 306.], + [195., 396., 603., 621., 639., 432., 219.], + [105., 213., 324., 333., 342., 231., 117.]], + + [[60., 122., 186., 192., 198., 134., 68.], + [130., 264., 402., 414., 426., 288., 146.], + [210., 426., 648., 666., 684., 462., 234.], + [240., 486., 738., 756., 774., 522., 264.], + [170., 344., 522., 534., 546., 368., 186.], + [90., 182., 276., 282., 288., 194., 98.]], + + [[40., 81., 123., 126., 129., 87., 44.], + [85., 172., 261., 267., 273., 184., 93.], + [135., 273., 414., 423., 432., 291., 147.], + [150., 303., 459., 468., 477., 321., 162.], + [105., 212., 321., 327., 333., 224., 113.], + [55., 111., 168., 171., 174., 117., 59.]]], + + [[[0., 1., 3., 6., 9., 7., 4.], + [5., 12., 21., 27., 33., 24., 13.], + [15., 33., 54., 63., 72., 51., 27.], + [30., 63., 99., 108., 117., 81., 42.], + [25., 52., 81., 87., 93., 64., 33.], + [15., 31., 48., 51., 54., 37., 19.]], + + [[20., 42., 66., 72., 78., 54., 28.], + [50., 104., 162., 174., 186., 128., 66.], + [90., 186., 288., 306., 324., 222., 114.], + [120., 246., 378., 396., 414., 282., 144.], + [90., 184., 282., 294., 306., 208., 106.], + [50., 102., 156., 162., 168., 114., 58.]], + + [[60., 123., 189., 198., 207., 141., 72.], + [135., 276., 423., 441., 459., 312., 159.], + [225., 459., 702., 729., 756., 513., 261.], + [270., 549., 837., 864., 891., 603., 306.], + [195., 396., 603., 621., 639., 432., 219.], + [105., 213., 324., 333., 342., 231., 117.]], + + [[60., 122., 186., 192., 198., 134., 68.], + [130., 264., 402., 414., 426., 288., 146.], + [210., 426., 648., 666., 684., 462., 234.], + [240., 486., 738., 756., 774., 522., 264.], + [170., 344., 522., 534., 546., 368., 186.], + [90., 182., 276., 282., 288., 194., 98.]], + + [[40., 81., 123., 126., 129., 87., 44.], + [85., 172., 261., 267., 273., 184., 93.], + [135., 273., 414., 423., 432., 291., 147.], + [150., 303., 459., 468., 477., 321., 162.], + [105., 212., 321., 327., 333., 224., 113.], + [55., 111., 168., 171., 174., 117., 59.]]]]]).astype(np.float32) + +expect(node, inputs=[x, W], outputs=[y], name='test_convtranspose_3d') +``` + +
+ + +
+convtranspose_attributes + +```python +x = np.array([[[[0., 1., 2.], # (1, 1, 3, 3) + [3., 4., 5.], + [6., 7., 8.]]]]).astype(np.float32) + +W = np.array([[[[1., 1., 1.], # (1, 2, 3, 3) + [1., 1., 1.], + [1., 1., 1.]], + [[1., 1., 1.], + [1., 1., 1.], + [1., 1., 1.]]]]).astype(np.float32) + +y = np.array([[[[0., 0., 1., 1., 3., 2., 2., 0.], # (1, 2, 10, 8) + [0., 0., 1., 1., 3., 2., 2., 0.], + [0., 0., 1., 1., 3., 2., 2., 0.], + [3., 3., 7., 4., 9., 5., 5., 0.], + [3., 3., 7., 4., 9., 5., 5., 0.], + [3., 3., 7., 4., 9., 5., 5., 0.], + [6., 6., 13., 7., 15., 8., 8., 0.], + [6., 6., 13., 7., 15., 8., 8., 0.], + [6., 6., 13., 7., 15., 8., 8., 0.], + [0., 0., 0., 0., 0., 0., 0., 0.]], + + [[0., 0., 1., 1., 3., 2., 2., 0.], + [0., 0., 1., 1., 3., 2., 2., 0.], + [0., 0., 1., 1., 3., 2., 2., 0.], + [3., 3., 7., 4., 9., 5., 5., 0.], + [3., 3., 7., 4., 9., 5., 5., 0.], + [3., 3., 7., 4., 9., 5., 5., 0.], + [6., 6., 13., 7., 15., 8., 8., 0.], + [6., 6., 13., 7., 15., 8., 8., 0.], + [6., 6., 13., 7., 15., 8., 8., 0.], + [0., 0., 0., 0., 0., 0., 0., 0.]]]]).astype(np.float32) + +node = onnx.helper.make_node("ConvTranspose", ["X", "W"], ["Y"], + strides=[3, 2], + output_shape=[10, 8]) +expect(node, inputs=[x, W], outputs=[y], name='test_convtranspose_output_shape') + +node = onnx.helper.make_node("ConvTranspose", ["X", "W"], ["Y"], + strides=[3, 2], + output_padding=[1, 1]) +expect(node, inputs=[x, W], outputs=[y], name='test_convtranspose_pad') + +node = onnx.helper.make_node( + 'ConvTranspose', ['X', 'W'], ['Y'], + name='test', + strides=[3, 2], + output_shape=[10, 8], + kernel_shape=[3, 3], + output_padding=[1, 1] +) +expect(node, inputs=[x, W], outputs=[y], + name='test_convtranspose_kernel_shape') +``` + +
+ + +
+convtranspose_autopad_same + +```python +x = np.array([[[[0., 1., 2.], # (1, 1, 3, 3) + [3., 4., 5.], + [6., 7., 8.]]]]).astype(np.float32) + +W = np.array([[[[1., 1., 1.], # (1, 2, 3, 3) + [1., 1., 1.], + [1., 1., 1.]], + [[1., 1., 1.], + [1., 1., 1.], + [1., 1., 1.]]]]).astype(np.float32) + +node = onnx.helper.make_node("ConvTranspose", ["X", "W"], ["Y"], auto_pad="SAME_UPPER", strides=[2, 2]) + +y = np.array([[[[0., 0., 1., 1., 3., 2.], + [0., 0., 1., 1., 3., 2.], + [3., 3., 8., 5., 12., 7.], + [3., 3., 7., 4., 9., 5.], + [9., 9., 20., 11., 24., 13.], + [6., 6., 13., 7., 15., 8.]], + + [[0., 0., 1., 1., 3., 2.], + [0., 0., 1., 1., 3., 2.], + [3., 3., 8., 5., 12., 7.], + [3., 3., 7., 4., 9., 5.], + [9., 9., 20., 11., 24., 13.], + [6., 6., 13., 7., 15., 8.]]]]).astype(np.float32) + +expect(node, inputs=[x, W], outputs=[y], name='test_convtranspose_autopad_same') +``` + +
+ + +
+convtranspose_dilations + +```python +x = np.array([[[[3., 8., 1.], # (1, 1, 3, 3) + [9., 5., 7.], + [3., 2., 6.]]]]).astype(np.float32) +W = np.array([[[[7., 2.], # (1, 1, 2, 2) + [1., 9.]]]]).astype(np.float32) + +node = onnx.helper.make_node("ConvTranspose", ["X", "W"], ["Y"], dilations=[2, 2]) + +y = np.array([[[[21., 56., 13., 16., 2.], # [1, 1, 5, 5] + [63., 35., 67., 10., 14.], + [24., 22., 76., 76., 21.], + [9., 5., 88., 45., 63.], + [3., 2., 33., 18., 54.]]]]).astype(np.float32) + +expect(node, inputs=[x, W], outputs=[y], name='test_convtranspose_dilations') +``` + +
+ + +
+convtranspose_pads + +```python +x = np.array([[[[0., 1., 2.], # (1, 1, 3, 3) + [3., 4., 5.], + [6., 7., 8.]]]]).astype(np.float32) + +W = np.array([[[[1., 1., 1.], # (1, 2, 3, 3) + [1., 1., 1.], + [1., 1., 1.]], + [[1., 1., 1.], + [1., 1., 1.], + [1., 1., 1.]]]]).astype(np.float32) + +node = onnx.helper.make_node("ConvTranspose", ["X", "W"], ["Y"], + strides=[3, 2], + pads=[1, 2, 1, 2]) + +y = np.array([[[[1., 1., 3.], # (1, 2, 7, 3) + [1., 1., 3.], + [7., 4., 9.], + [7., 4., 9.], + [7., 4., 9.], + [13., 7., 15.], + [13., 7., 15.]], + + [[1., 1., 3.], + [1., 1., 3.], + [7., 4., 9.], + [7., 4., 9.], + [7., 4., 9.], + [13., 7., 15.], + [13., 7., 15.]]]]).astype(np.float32) + +expect(node, inputs=[x, W], outputs=[y], name='test_convtranspose_pads') +``` + +
+ + +### **Cos** + + Calculates the cosine of the given input tensor, element-wise. + +#### Version + +This version of the operator has been available since version 7 of the default ONNX operator set. + +#### Inputs + +
+
input (differentiable) : T
+
Input tensor
+
+ +#### Outputs + +
+
output (differentiable) : T
+
The cosine of the input tensor computed element-wise
+
+ +#### Type Constraints + +
+
T : tensor(float16), tensor(float), tensor(double)
+
Constrain input and output types to float tensors.
+
+ + +#### Examples + +
+cos + +```python +node = onnx.helper.make_node( + 'Cos', + inputs=['x'], + outputs=['y'], +) + +x = np.array([-1, 0, 1]).astype(np.float32) +y = np.cos(x) +expect(node, inputs=[x], outputs=[y], + name='test_cos_example') + +x = np.random.randn(3, 4, 5).astype(np.float32) +y = np.cos(x) +expect(node, inputs=[x], outputs=[y], + name='test_cos') +``` + +
+ + +### **Cosh** + + Calculates the hyperbolic cosine of the given input tensor element-wise. + +#### Version + +This version of the operator has been available since version 9 of the default ONNX operator set. + +#### Inputs + +
+
input (differentiable) : T
+
Input tensor
+
+ +#### Outputs + +
+
output (differentiable) : T
+
The hyperbolic cosine values of the input tensor computed element-wise
+
+ +#### Type Constraints + +
+
T : tensor(float16), tensor(float), tensor(double)
+
Constrain input and output types to float tensors.
+
+ + +#### Examples + +
+cosh + +```python +node = onnx.helper.make_node( + 'Cosh', + inputs=['x'], + outputs=['y'], +) + +x = np.array([-1, 0, 1]).astype(np.float32) +y = np.cosh(x) # expected output [1.54308069, 1., 1.54308069] +expect(node, inputs=[x], outputs=[y], + name='test_cosh_example') + +x = np.random.randn(3, 4, 5).astype(np.float32) +y = np.cosh(x) +expect(node, inputs=[x], outputs=[y], + name='test_cosh') +``` + +
+ + +### **CumSum** + + Performs cumulative sum of the input elements along the given axis. + By default, it will do the sum inclusively meaning the first element is copied as is. + Through an `exclusive` attribute, this behavior can change to exclude the first element. + It can also perform summation in the opposite direction of the axis. For that, set `reverse` attribute to 1. + + Example: + ``` + input_x = [1, 2, 3] + axis=0 + output = [1, 3, 6] + exclusive=1 + output = [0, 1, 3] + exclusive=0 + reverse=1 + output = [6, 5, 3] + exclusive=1 + reverse=1 + output = [5, 3, 0] + ``` + + +#### Version + +This version of the operator has been available since version 14 of the default ONNX operator set. + +Other versions of this operator: 11 + +#### Attributes + +
+
exclusive : int (default is 0)
+
If set to 1 will return exclusive sum in which the top element is not included. In other terms, if set to 1, the j-th output element would be the sum of the first (j-1) elements. Otherwise, it would be the sum of the first j elements.
+
reverse : int (default is 0)
+
If set to 1 will perform the sums in reverse direction.
+
+ +#### Inputs + +
+
x (differentiable) : T
+
An input tensor that is to be processed.
+
axis (non-differentiable) : T2
+
A 0-D tensor. Must be in the range [-rank(x), rank(x)-1]. Negative value means counting dimensions from the back.
+
+ +#### Outputs + +
+
y (differentiable) : T
+
Output tensor of the same type as 'x' with cumulative sums of the x's elements
+
+ +#### Type Constraints + +
+
T : tensor(uint32), tensor(uint64), tensor(int32), tensor(int64), tensor(float16), tensor(float), tensor(double), tensor(bfloat16)
+
Constrain input and output types to high-precision numeric tensors.
+
T2 : tensor(int32), tensor(int64)
+
axis tensor can be int32 or int64 only
+
+ + +#### Examples + +
+cumsum_1d + +```python +node = onnx.helper.make_node( + 'CumSum', + inputs=['x', 'axis'], + outputs=['y'] +) +x = np.array([1., 2., 3., 4., 5.]).astype(np.float64) +axis = np.int32(0) +y = np.array([1., 3., 6., 10., 15.]).astype(np.float64) +expect(node, inputs=[x, axis], outputs=[y], + name='test_cumsum_1d') +``` + +
+ + +
+cumsum_1d_exclusive + +```python +node = onnx.helper.make_node( + 'CumSum', + inputs=['x', 'axis'], + outputs=['y'], + exclusive=1 +) +x = np.array([1., 2., 3., 4., 5.]).astype(np.float64) +axis = np.int32(0) +y = np.array([0., 1., 3., 6., 10.]).astype(np.float64) +expect(node, inputs=[x, axis], outputs=[y], + name='test_cumsum_1d_exclusive') +``` + +
+ + +
+cumsum_1d_reverse + +```python +node = onnx.helper.make_node( + 'CumSum', + inputs=['x', 'axis'], + outputs=['y'], + reverse=1 +) +x = np.array([1., 2., 3., 4., 5.]).astype(np.float64) +axis = np.int32(0) +y = np.array([15., 14., 12., 9., 5.]).astype(np.float64) +expect(node, inputs=[x, axis], outputs=[y], + name='test_cumsum_1d_reverse') +``` + +
+ + +
+cumsum_1d_reverse_exclusive + +```python +node = onnx.helper.make_node( + 'CumSum', + inputs=['x', 'axis'], + outputs=['y'], + reverse=1, + exclusive=1 +) +x = np.array([1., 2., 3., 4., 5.]).astype(np.float64) +axis = np.int32(0) +y = np.array([14., 12., 9., 5., 0.]).astype(np.float64) +expect(node, inputs=[x, axis], outputs=[y], + name='test_cumsum_1d_reverse_exclusive') +``` + +
+ + +
+cumsum_2d_axis_0 + +```python +node = onnx.helper.make_node( + 'CumSum', + inputs=['x', 'axis'], + outputs=['y'], +) +x = np.array([1., 2., 3., 4., 5., 6.]).astype(np.float64).reshape((2, 3)) +axis = np.int32(0) +y = np.array([1., 2., 3., 5., 7., 9.]).astype(np.float64).reshape((2, 3)) +expect(node, inputs=[x, axis], outputs=[y], + name='test_cumsum_2d_axis_0') +``` + +
+ + +
+cumsum_2d_axis_1 + +```python +node = onnx.helper.make_node( + 'CumSum', + inputs=['x', 'axis'], + outputs=['y'], +) +x = np.array([1., 2., 3., 4., 5., 6.]).astype(np.float64).reshape((2, 3)) +axis = np.int32(1) +y = np.array([1., 3., 6., 4., 9., 15.]).astype(np.float64).reshape((2, 3)) +expect(node, inputs=[x, axis], outputs=[y], + name='test_cumsum_2d_axis_1') +``` + +
+ + +
+cumsum_2d_negative_axis + +```python +node = onnx.helper.make_node( + 'CumSum', + inputs=['x', 'axis'], + outputs=['y'], +) +x = np.array([1., 2., 3., 4., 5., 6.]).astype(np.float64).reshape((2, 3)) +axis = np.int32(-1) +y = np.array([1., 3., 6., 4., 9., 15.]).astype(np.float64).reshape((2, 3)) +expect(node, inputs=[x, axis], outputs=[y], + name='test_cumsum_2d_negative_axis') +``` + +
+ + +### **DepthToSpace** + + DepthToSpace rearranges (permutes) data from depth into blocks of spatial data. + This is the reverse transformation of SpaceToDepth. More specifically, this op outputs a copy of + the input tensor where values from the depth dimension are moved in spatial blocks to the height + and width dimensions. By default, `mode` = `DCR`. + In the DCR mode, elements along the depth dimension from the input tensor are rearranged in the + following order: depth, column, and then row. The output y is computed from the input x as below: + + b, c, h, w = x.shape + + tmp = np.reshape(x, [b, blocksize, blocksize, c // (blocksize**2), h, w]) + + tmp = np.transpose(tmp, [0, 3, 4, 1, 5, 2]) + + y = np.reshape(tmp, [b, c // (blocksize**2), h * blocksize, w * blocksize]) + + + In the CRD mode, elements along the depth dimension from the input tensor are rearranged in the + following order: column, row, and the depth. The output y is computed from the input x as below: + + b, c, h, w = x.shape + + tmp = np.reshape(x, [b, c // (blocksize ** 2), blocksize, blocksize, h, w]) + + tmp = np.transpose(tmp, [0, 1, 4, 2, 5, 3]) + + y = np.reshape(tmp, [b, c // (blocksize ** 2), h * blocksize, w * blocksize]) + + +#### Version + +This version of the operator has been available since version 13 of the default ONNX operator set. + +Other versions of this operator: 1, 11 + +#### Attributes + +
+
blocksize : int (required)
+
Blocks of [blocksize, blocksize] are moved.
+
mode : string (default is DCR)
+
DCR (default) for depth-column-row order re-arrangement. Use CRD for column-row-depth order.
+
+ +#### Inputs + +
+
input (differentiable) : T
+
Input tensor of [N,C,H,W], where N is the batch axis, C is the channel or depth, H is the height and W is the width.
+
+ +#### Outputs + +
+
output (differentiable) : T
+
Output tensor of [N, C/(blocksize * blocksize), H * blocksize, W * blocksize].
+
+ +#### Type Constraints + +
+
T : tensor(uint8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(int8), tensor(int16), tensor(int32), tensor(int64), tensor(bfloat16), tensor(float16), tensor(float), tensor(double), tensor(string), tensor(bool), tensor(complex64), tensor(complex128)
+
Constrain input and output types to all tensor types.
+
+ + +#### Examples + +
+crd_mode_example + +```python +node = onnx.helper.make_node( + 'DepthToSpace', + inputs=['x'], + outputs=['y'], + blocksize=2, + mode='CRD' +) + +# (1, 8, 2, 3) input tensor +x = np.array([[[[0., 1., 2.], + [3., 4., 5.]], + [[9., 10., 11.], + [12., 13., 14.]], + [[18., 19., 20.], + [21., 22., 23.]], + [[27., 28., 29.], + [30., 31., 32.]], + [[36., 37., 38.], + [39., 40., 41.]], + [[45., 46., 47.], + [48., 49., 50.]], + [[54., 55., 56.], + [57., 58., 59.]], + [[63., 64., 65.], + [66., 67., 68.]]]]).astype(np.float32) + +# (1, 2, 4, 6) output tensor +y = np.array([[[[0., 9., 1., 10., 2., 11.], + [18., 27., 19., 28., 20., 29.], + [3., 12., 4., 13., 5., 14.], + [21., 30., 22., 31., 23., 32.]], + [[36., 45., 37., 46., 38., 47.], + [54., 63., 55., 64., 56., 65.], + [39., 48., 40., 49., 41., 50.], + [57., 66., 58., 67., 59., 68.]]]]).astype(np.float32) +expect(node, inputs=[x], outputs=[y], + name='test_depthtospace_crd_mode_example') +``` + +
+ + +
+default_mode_example + +```python +node = onnx.helper.make_node( + 'DepthToSpace', + inputs=['x'], + outputs=['y'], + blocksize=2, + mode='DCR' +) + +# (1, 8, 2, 3) input tensor +x = np.array([[[[0., 1., 2.], + [3., 4., 5.]], + [[9., 10., 11.], + [12., 13., 14.]], + [[18., 19., 20.], + [21., 22., 23.]], + [[27., 28., 29.], + [30., 31., 32.]], + [[36., 37., 38.], + [39., 40., 41.]], + [[45., 46., 47.], + [48., 49., 50.]], + [[54., 55., 56.], + [57., 58., 59.]], + [[63., 64., 65.], + [66., 67., 68.]]]]).astype(np.float32) + +# (1, 2, 4, 6) output tensor +y = np.array([[[[0., 18., 1., 19., 2., 20.], + [36., 54., 37., 55., 38., 56.], + [3., 21., 4., 22., 5., 23.], + [39., 57., 40., 58., 41., 59.]], + [[9., 27., 10., 28., 11., 29.], + [45., 63., 46., 64., 47., 65.], + [12., 30., 13., 31., 14., 32.], + [48., 66., 49., 67., 50., 68.]]]]).astype(np.float32) +expect(node, inputs=[x], outputs=[y], + name='test_depthtospace_example') +``` + +
+ + +### **DequantizeLinear** + + The linear dequantization operator. It consumes a quantized tensor, a scale, and a zero point to compute the full precision tensor. + The dequantization formula is y = (x - x_zero_point) * x_scale. 'x_scale' and 'x_zero_point' must have same shape, and can be either a scalar + for per-tensor / per layer quantization, or a 1-D tensor for per-axis quantization. + 'x_zero_point' and 'x' must have same type. 'x' and 'y' must have same shape. In the case of dequantizing int32, + there's no zero point (zero point is supposed to be 0). + +#### Version + +This version of the operator has been available since version 13 of the default ONNX operator set. + +Other versions of this operator: 10 + +#### Attributes + +
+
axis : int (default is 1)
+
(Optional) The axis of the dequantizing dimension of the input tensor. Ignored for per-tensor quantization. Negative value means counting dimensions from the back. Accepted range is [-r, r-1] where r = rank(input).
+
+ +#### Inputs (2 - 3) + +
+
x : T
+
N-D quantized input tensor to be de-quantized.
+
x_scale : tensor(float)
+
Scale for input 'x'. It can be a scalar, which means a per-tensor/layer dequantization, or a 1-D tensor for per-axis dequantization.
+
x_zero_point (optional) : T
+
Zero point for input 'x'. Shape must match x_scale. It's optional. Zero point is 0 when it's not specified.
+
+ +#### Outputs + +
+
y : tensor(float)
+
N-D full precision output tensor. It has same shape as input 'x'.
+
+ +#### Type Constraints + +
+
T : tensor(int8), tensor(uint8), tensor(int32)
+
Constrain 'x_zero_point' and 'x' to 8-bit/32-bit integer tensor.
+
+ + +#### Examples + +
+axis + +```python +node = onnx.helper.make_node('DequantizeLinear', + inputs=['x', 'x_scale', 'x_zero_point'], + outputs=['y'],) + +# 1-D tensor zero point and scale of size equal to axis 1 of the input tensor +x = np.array([[[[3, 89], + [34, 200], + [74, 59]], + + [[5, 24], + [24, 87], + [32, 13]], + + [[245, 99], + [4, 142], + [121, 102]], ], ], dtype=np.uint8) +x_scale = np.array([2, 4, 5], dtype=np.float32) +x_zero_point = np.array([84, 24, 196], dtype=np.uint8) +y = (x.astype(np.float32) - x_zero_point.reshape(1, 3, 1, 1).astype(np.float32)) * x_scale.reshape(1, 3, 1, 1) + +expect(node, inputs=[x, x_scale, x_zero_point], outputs=[y], + name='test_dequantizelinear_axis') +``` + +
+ + +
+dequantizelinear + +```python +node = onnx.helper.make_node('DequantizeLinear', + inputs=['x', 'x_scale', 'x_zero_point'], + outputs=['y'],) + +# scalar zero point and scale +x = np.array([0, 3, 128, 255]).astype(np.uint8) +x_scale = np.float32(2) +x_zero_point = np.uint8(128) +y = np.array([-256, -250, 0, 254], dtype=np.float32) + +expect(node, inputs=[x, x_scale, x_zero_point], outputs=[y], + name='test_dequantizelinear') +``` + +
+ + +### **Det** + + Det calculates determinant of a square matrix or batches of square matrices. + Det takes one input tensor of shape `[*, M, M]`, where `*` is zero or more batch dimensions, + and the inner-most 2 dimensions form square matrices. + The output is a tensor of shape `[*]`, containing the determinants of all input submatrices. + e.g., When the input is 2-D, the output is a scalar(shape is empty: `[]`). + +#### Version + +This version of the operator has been available since version 11 of the default ONNX operator set. + +#### Inputs + +
+
X (differentiable) : T
+
Input tensor
+
+ +#### Outputs + +
+
Y (differentiable) : T
+
Output tensor
+
+ +#### Type Constraints + +
+
T : tensor(float16), tensor(float), tensor(double)
+
Constrain input and output types to floating-point tensors.
+
+ + +#### Examples + +
+2d + +```python +node = onnx.helper.make_node( + 'Det', + inputs=['x'], + outputs=['y'], +) + +x = np.arange(4).reshape(2, 2).astype(np.float32) +y = np.linalg.det(x) # expect -2 +expect(node, inputs=[x], outputs=[y], + name='test_det_2d') +``` + +
+ + +
+nd + +```python +node = onnx.helper.make_node( + 'Det', + inputs=['x'], + outputs=['y'], +) + +x = np.array([[[1, 2], [3, 4]], [[1, 2], [2, 1]], [[1, 3], [3, 1]]]).astype(np.float32) +y = np.linalg.det(x) # expect array([-2., -3., -8.]) +expect(node, inputs=[x], outputs=[y], + name='test_det_nd') +``` + +
+ + +### **Div** + + Performs element-wise binary division (with Numpy-style broadcasting support). + + This operator supports **multidirectional (i.e., Numpy-style) broadcasting**; for more details please check [the doc](Broadcasting.md). + + (Opset 14 change): Extend supported types to include uint8, int8, uint16, and int16. + +#### Version + +This version of the operator has been available since version 14 of the default ONNX operator set. + +Other versions of this operator: 1, 6, 7, 13 + +#### Inputs + +
+
A (differentiable) : T
+
First operand.
+
B (differentiable) : T
+
Second operand.
+
+ +#### Outputs + +
+
C (differentiable) : T
+
Result, has same element type as two inputs
+
+ +#### Type Constraints + +
+
T : tensor(uint8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(int8), tensor(int16), tensor(int32), tensor(int64), tensor(float16), tensor(float), tensor(double), tensor(bfloat16)
+
Constrain input and output types to all numeric tensors.
+
+ + +#### Examples + +
+div + +```python +node = onnx.helper.make_node( + 'Div', + inputs=['x', 'y'], + outputs=['z'], +) + +x = np.array([3, 4]).astype(np.float32) +y = np.array([1, 2]).astype(np.float32) +z = x / y # expected output [3., 2.] +expect(node, inputs=[x, y], outputs=[z], + name='test_div_example') + +x = np.random.randn(3, 4, 5).astype(np.float32) +y = np.random.rand(3, 4, 5).astype(np.float32) + 1.0 +z = x / y +expect(node, inputs=[x, y], outputs=[z], + name='test_div') + +x = np.random.randint(24, size=(3, 4, 5), dtype=np.uint8) +y = np.random.randint(24, size=(3, 4, 5), dtype=np.uint8) + 1 +z = x // y +expect(node, inputs=[x, y], outputs=[z], + name='test_div_uint8') +``` + +
+ + +
+div_broadcast + +```python +node = onnx.helper.make_node( + 'Div', + inputs=['x', 'y'], + outputs=['z'], +) + +x = np.random.randn(3, 4, 5).astype(np.float32) +y = np.random.rand(5).astype(np.float32) + 1.0 +z = x / y +expect(node, inputs=[x, y], outputs=[z], + name='test_div_bcast') +``` + +
+ + +### **Dropout** + + 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, + output (floating-point tensor) and mask (optional `Tensor`). If `training_mode` is true then the output Y will be a random dropout; + Note that this Dropout scales the masked input data by the following equation, so to convert the trained model into inference mode, + the user can simply not pass `training_mode` input or set it to false. + ``` + output = scale * data * mask, + ``` + where + ``` + scale = 1. / (1. - ratio). + ``` + This operator has **optional** inputs/outputs. See [the doc](IR.md) for more details about the representation of optional arguments. An empty string may be used in the place of an actual argument's name to indicate a missing argument. Trailing optional arguments (those not followed by an argument that is present) may also be simply omitted. + +#### Version + +This version of the operator has been available since version 13 of the default ONNX operator set. + +Other versions of this operator: 1, 6, 7, 10, 12 + +#### Attributes + +
+
seed : int
+
(Optional) Seed to the random generator, if not specified we will auto generate one.
+
+ +#### Inputs (1 - 3) + +
+
data (differentiable) : T
+
The input data as Tensor.
+
ratio (optional, non-differentiable) : T1
+
The ratio of random dropout, with value in [0, 1). If this input was not set, or if it was set to 0, the output would be a simple copy of the input. If it's non-zero, output will be a random dropout of the scaled input, which is typically the case during training. It is an optional value, if not specified it will default to 0.5.
+
training_mode (optional, non-differentiable) : T2
+
If set to true then it indicates dropout is being used for training. It is an optional value hence unless specified explicitly, it is false. If it is false, ratio is ignored and the operation mimics inference mode where nothing will be dropped from the input data and if mask is requested as output it will contain all ones.
+
+ +#### Outputs (1 - 2) + +
+
output (differentiable) : T
+
The output.
+
mask (optional, non-differentiable) : T2
+
The output mask.
+
+ +#### Type Constraints + +
+
T : tensor(float16), tensor(float), tensor(double), tensor(bfloat16)
+
Constrain input and output types to float tensors.
+
T1 : tensor(float16), tensor(float), tensor(double)
+
Constrain input 'ratio' types to float tensors.
+
T2 : tensor(bool)
+
Constrain output 'mask' types to boolean tensors.
+
+ + +#### Examples + +
+default + +```python +seed = np.int64(0) +node = onnx.helper.make_node( + 'Dropout', + inputs=['x'], + outputs=['y'], + seed=seed +) + +x = np.random.randn(3, 4, 5).astype(np.float32) +y = dropout(x) +expect(node, inputs=[x], outputs=[y], name='test_dropout_default') +``` + +
+ + +
+default_mask + +```python +seed = np.int64(0) +node = onnx.helper.make_node( + 'Dropout', + inputs=['x'], + outputs=['y', 'z'], + seed=seed +) + +x = np.random.randn(3, 4, 5).astype(np.float32) +y, z = dropout(x, return_mask=True) +expect(node, inputs=[x], outputs=[y, z], name='test_dropout_default_mask') +``` + +
+ + +
+default_mask_ratio + +```python +seed = np.int64(0) +node = onnx.helper.make_node( + 'Dropout', + inputs=['x', 'r'], + outputs=['y', 'z'], + seed=seed +) + +r = np.float32(0.1) +x = np.random.randn(3, 4, 5).astype(np.float32) +y, z = dropout(x, r, return_mask=True) +expect(node, inputs=[x, r], outputs=[y, z], name='test_dropout_default_mask_ratio') +``` + +
+ + +
+default_old + +```python +node = onnx.helper.make_node( + 'Dropout', + inputs=['x'], + outputs=['y'], +) + +x = np.array([-1, 0, 1]).astype(np.float32) +y = x +expect(node, inputs=[x], outputs=[y], + name='test_dropout_default_old', opset_imports=[helper.make_opsetid("", 11)]) +``` + +
+ + +
+default_ratio + +```python +seed = np.int64(0) +node = onnx.helper.make_node( + 'Dropout', + inputs=['x', 'r'], + outputs=['y'], + seed=seed +) + +r = np.float32(0.1) +x = np.random.randn(3, 4, 5).astype(np.float32) +y = dropout(x, r) +expect(node, inputs=[x, r], outputs=[y], name='test_dropout_default_ratio') +``` + +
+ + +
+random_old + +```python +node = onnx.helper.make_node( + 'Dropout', + inputs=['x'], + outputs=['y'], + ratio=.2, +) + +x = np.random.randn(3, 4, 5).astype(np.float32) +y = x +expect(node, inputs=[x], outputs=[y], + name='test_dropout_random_old', opset_imports=[helper.make_opsetid("", 11)]) +``` + +
+ + +
+training + +```python +seed = np.int64(0) +node = onnx.helper.make_node( + 'Dropout', + inputs=['x', 'r', 't'], + outputs=['y'], + seed=seed +) + +x = np.random.randn(3, 4, 5).astype(np.float32) +r = np.float32(0.75) +t = np.bool_(True) +y = dropout(x, r, training_mode=t) +expect(node, inputs=[x, r, t], outputs=[y], name='test_training_dropout') +``` + +
+ + +
+training_default + +```python +seed = np.int64(0) +node = onnx.helper.make_node( + 'Dropout', + inputs=['x', 'r', 't'], + outputs=['y'], + seed=seed +) + +x = np.random.randn(3, 4, 5).astype(np.float32) +r = np.float32(0.5) +t = np.bool_(True) +y = dropout(x, r, training_mode=t) +expect(node, inputs=[x, r, t], outputs=[y], name='test_training_dropout_default') +``` + +
+ + +
+training_default_ratio_mask + +```python +seed = np.int64(0) +node = onnx.helper.make_node( + 'Dropout', + inputs=['x', 'r', 't'], + outputs=['y', 'z'], + seed=seed +) + +x = np.random.randn(3, 4, 5).astype(np.float32) +r = np.float32(0.5) +t = np.bool_(True) +y, z = dropout(x, r, training_mode=t, return_mask=True) +expect(node, inputs=[x, r, t], outputs=[y, z], name='test_training_dropout_default_mask') +``` + +
+ + +
+training_default_zero_ratio + +```python +seed = np.int64(0) +node = onnx.helper.make_node( + 'Dropout', + inputs=['x', 'r', 't'], + outputs=['y'], + seed=seed +) + +x = np.random.randn(3, 4, 5).astype(np.float32) +r = np.float32(0.0) +t = np.bool_(True) +y = dropout(x, r, training_mode=t) +expect(node, inputs=[x, r, t], outputs=[y], name='test_training_dropout_zero_ratio') +``` + +
+ + +
+training_default_zero_ratio_mask + +```python +seed = np.int64(0) +node = onnx.helper.make_node( + 'Dropout', + inputs=['x', 'r', 't'], + outputs=['y', 'z'], + seed=seed +) + +x = np.random.randn(3, 4, 5).astype(np.float32) +r = np.float32(0.0) +t = np.bool_(True) +y, z = dropout(x, r, training_mode=t, return_mask=True) +expect(node, inputs=[x, r, t], outputs=[y, z], name='test_training_dropout_zero_ratio_mask') +``` + +
+ + +
+training_ratio_mask + +```python +seed = np.int64(0) +node = onnx.helper.make_node( + 'Dropout', + inputs=['x', 'r', 't'], + outputs=['y', 'z'], + seed=seed +) + +x = np.random.randn(3, 4, 5).astype(np.float32) +r = np.float32(0.75) +t = np.bool_(True) +y, z = dropout(x, r, training_mode=t, return_mask=True) +expect(node, inputs=[x, r, t], outputs=[y, z], name='test_training_dropout_mask') +``` + +
+ + +### **DynamicQuantizeLinear** + + A Function to fuse calculation for Scale, Zero Point and FP32->8Bit convertion of FP32 Input data. + Outputs Scale, ZeroPoint and Quantized Input for a given FP32 Input. + Scale is calculated as: + ``` + y_scale = (max(x) - min(x))/(qmax - qmin) + * where qmax and qmin are max and min values for quantization range .i.e [0, 255] in case of uint8 + * data range is adjusted to include 0. + ``` + Zero point is calculated as: + ``` + intermediate_zero_point = qmin - min(x)/y_scale + y_zero_point = cast(round(saturate(itermediate_zero_point))) + * where qmax and qmin are max and min values for quantization range .i.e [0, 255] in case of uint8 + * for saturation, it saturates to [0, 255] if it's uint8, or [-127, 127] if it's int8. Right now only uint8 is supported. + * rounding to nearest ties to even. + ``` + Data quantization formula is: + ``` + y = saturate (round (x / y_scale) + y_zero_point) + * for saturation, it saturates to [0, 255] if it's uint8, or [-127, 127] if it's int8. Right now only uint8 is supported. + * rounding to nearest ties to even. + ``` + +#### Version + +This version of the operator has been available since version 11 of the default ONNX operator set. + +#### Inputs + +
+
x : T1
+
Input tensor
+
+ +#### Outputs + +
+
y : T2
+
Quantized output tensor
+
y_scale : tensor(float)
+
Output scale. It's a scalar, which means a per-tensor/layer quantization.
+
y_zero_point : T2
+
Output zero point. It's a scalar, which means a per-tensor/layer quantization.
+
+ +#### Type Constraints + +
+
T1 : tensor(float)
+
Constrain 'x' to float tensor.
+
T2 : tensor(uint8)
+
Constrain 'y_zero_point' and 'y' to 8-bit unsigned integer tensor.
+
+ + +#### Examples + +
+dynamicquantizelinear + +```python +node = onnx.helper.make_node('DynamicQuantizeLinear', + inputs=['x'], + outputs=['y', 'y_scale', 'y_zero_point'], +) + +# expected scale 0.0196078438 and zero point 153 +X = np.array([0, 2, -3, -2.5, 1.34, 0.5]).astype(np.float32) +x_min = np.minimum(0, np.min(X)) +x_max = np.maximum(0, np.max(X)) +Y_Scale = np.float32((x_max - x_min) / (255 - 0)) # uint8 -> [0, 255] +Y_ZeroPoint = np.clip(round((0 - x_min) / Y_Scale), 0, 255).astype(np.uint8) +Y = np.clip(np.round(X / Y_Scale) + Y_ZeroPoint, 0, 255).astype(np.uint8) + +expect(node, inputs=[X], outputs=[Y, Y_Scale, Y_ZeroPoint], + name='test_dynamicquantizelinear') + +# expected scale 0.0156862754 and zero point 255 +X = np.array([-1.0, -2.1, -1.3, -2.5, -3.34, -4.0]).astype(np.float32) +x_min = np.minimum(0, np.min(X)) +x_max = np.maximum(0, np.max(X)) +Y_Scale = np.float32((x_max - x_min) / (255 - 0)) # uint8 -> [0, 255] +Y_ZeroPoint = np.clip(round((0 - x_min) / Y_Scale), 0, 255).astype(np.uint8) +Y = np.clip(np.round(X / Y_Scale) + Y_ZeroPoint, 0, 255).astype(np.uint8) + +expect(node, inputs=[X], outputs=[Y, Y_Scale, Y_ZeroPoint], + name='test_dynamicquantizelinear_max_adjusted') + +X = np.array([1, 2.1, 1.3, 2.5, + 3.34, 4.0, 1.5, 2.6, + 3.9, 4.0, 3.0, 2.345]).astype(np.float32).reshape((3, 4)) + +# expected scale 0.0156862754 and zero point 0 +x_min = np.minimum(0, np.min(X)) +x_max = np.maximum(0, np.max(X)) +Y_Scale = np.float32((x_max - x_min) / (255 - 0)) # uint8 -> [0, 255] +Y_ZeroPoint = np.clip(round((0 - x_min) / Y_Scale), 0, 255).astype(np.uint8) +Y = np.clip(np.round(X / Y_Scale) + Y_ZeroPoint, 0, 255).astype(np.uint8) + +expect(node, inputs=[X], outputs=[Y, Y_Scale, Y_ZeroPoint], + name='test_dynamicquantizelinear_min_adjusted') +``` + +
+ + +### **Einsum** + + An einsum of the form ```term1, term2 -> output-term``` produces an output tensor using the following equation + + ```output[output-term] = reduce-sum( input1[term1] * input2[term] )``` + + where the reduce-sum performs a summation over all the indices occurring in the input terms (term1, term2) + that do not occur in the output-term. + + The Einsum operator evaluates algebraic tensor operations on a sequence of tensors, using the Einstein summation + convention. The equation string contains a comma-separated sequence of lower case letters. Each term corresponds to + an operand tensor, and the characters within the terms correspond to operands dimensions. + + This sequence may be followed by "->" to separate the left and right hand side of the equation. + If the equation contains "->" followed by the right-hand side, the explicit (not classical) form of the Einstein + summation is performed, and the right-hand side indices indicate output tensor dimensions. In other cases, + output indices are (implicitly) set to the alphabetically sorted sequence of indices appearing exactly once in the + equation. + + When a dimension character is repeated in the left-hand side, it represents summation along the dimension. + + The equation may contain ellipsis ("...") to enable broadcasting. Ellipsis must indicate a fixed number of dimensions. + Specifically, every occurrence of ellipsis in the equation must represent the same number of dimensions. + The right-hand side may contain exactly one ellipsis. In implicit mode, the ellipsis dimensions are set to the + beginning of the output. The equation string may contain space (U+0020) character. + +#### Version + +This version of the operator has been available since version 12 of the default ONNX operator set. + +#### Attributes + +
+
equation : string (required)
+
Einsum expression string.
+
+ +#### Inputs (1 - ∞) + +
+
Inputs (variadic, differentiable) : T
+
Operands
+
+ +#### Outputs + +
+
Output (differentiable) : T
+
Output tensor
+
+ +#### Type Constraints + +
+
T : tensor(uint8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(int8), tensor(int16), tensor(int32), tensor(int64), tensor(float16), tensor(float), tensor(double)
+
Constrain input and output types to all numerical tensor types.
+
+ + +#### Examples + +
+einsum_batch_diagonal + +```python +Eqn = '...ii ->...i' +node = onnx.helper.make_node( + 'Einsum', + inputs=['x'], + outputs=['y'], + equation=Eqn +) + +X = np.random.randn(3, 5, 5) +Z = einsum_reference_implementation(Eqn, (X,)) + +expect(node, inputs=[X], outputs=[Z], name='test_einsum_batch_diagonal') +``` + +
+ + +
+einsum_batch_matmul + +```python +Eqn = 'bij, bjk -> bik' +node = onnx.helper.make_node( + 'Einsum', + inputs=['x', 'y'], + outputs=['z'], + equation=Eqn +) + +X = np.random.randn(5, 2, 3) +Y = np.random.randn(5, 3, 4) +Z = einsum_reference_implementation(Eqn, (X, Y)) + +expect(node, inputs=[X, Y], outputs=[Z], name='test_einsum_batch_matmul') +``` + +
+ + +
+einsum_inner_prod + +```python +Eqn = 'i,i' +node = onnx.helper.make_node( + 'Einsum', + inputs=['x', 'y'], + outputs=['z'], + equation=Eqn +) + +X = np.random.randn(5) +Y = np.random.randn(5) +Z = einsum_reference_implementation(Eqn, (X, Y)) + +expect(node, inputs=[X, Y], outputs=[Z], name='test_einsum_inner_prod') +``` + +
+ + +
+einsum_sum + +```python +Eqn = 'ij->i' +node = onnx.helper.make_node( + 'Einsum', + inputs=['x'], + outputs=['y'], + equation=Eqn +) + +X = np.random.randn(3, 4) +Z = einsum_reference_implementation(Eqn, (X,)) + +expect(node, inputs=[X], outputs=[Z], name='test_einsum_sum') +``` + +
+ + +
+einsum_transpose + +```python +Eqn = 'ij->ji' +node = onnx.helper.make_node( + 'Einsum', + inputs=['x'], + outputs=['y'], + equation=Eqn +) + +X = np.random.randn(3, 4) +Y = einsum_reference_implementation(Eqn, (X,)) + +expect(node, inputs=[X], outputs=[Y], name='test_einsum_transpose') +``` + +
+ + +### **Elu** + + Elu takes one input data (Tensor) and produces one output data + (Tensor) where the function `f(x) = alpha * (exp(x) - 1.) for x < + 0`, `f(x) = x for x >= 0`., is applied to the tensor elementwise. + + +#### Version + +This version of the operator has been available since version 6 of the default ONNX operator set. + +Other versions of this operator: 1 + +#### Attributes + +
+
alpha : float (default is 1.0)
+
Coefficient of ELU.
+
+ +#### Inputs + +
+
X (differentiable) : T
+
1D input tensor
+
+ +#### Outputs + +
+
Y (differentiable) : T
+
1D output tensor
+
+ +#### Type Constraints + +
+
T : tensor(float16), tensor(float), tensor(double)
+
Constrain input and output types to float tensors.
+
+ + +#### Examples + +
+elu + +```python +node = onnx.helper.make_node( + 'Elu', + inputs=['x'], + outputs=['y'], + alpha=2.0 +) + +x = np.array([-1, 0, 1]).astype(np.float32) +# expected output [-1.2642411, 0., 1.] +y = np.clip(x, 0, np.inf) + (np.exp(np.clip(x, -np.inf, 0)) - 1) * 2.0 +expect(node, inputs=[x], outputs=[y], + name='test_elu_example') + +x = np.random.randn(3, 4, 5).astype(np.float32) +y = np.clip(x, 0, np.inf) + (np.exp(np.clip(x, -np.inf, 0)) - 1) * 2.0 +expect(node, inputs=[x], outputs=[y], + name='test_elu') +``` + +
+ + +
+elu_default + +```python +default_alpha = 1.0 +node = onnx.helper.make_node( + 'Elu', + inputs=['x'], + outputs=['y'], +) +x = np.random.randn(3, 4, 5).astype(np.float32) +y = np.clip(x, 0, np.inf) + (np.exp(np.clip(x, -np.inf, 0)) - 1) * default_alpha +expect(node, inputs=[x], outputs=[y], + name='test_elu_default') +``` + +
+ + +### **Equal** + + Returns the tensor resulted from performing the `equal` logical operation + elementwise on the input tensors `A` and `B` (with Numpy-style broadcasting support). + + This operator supports **multidirectional (i.e., Numpy-style) broadcasting**; for more details please check [the doc](Broadcasting.md). + +#### Version + +This version of the operator has been available since version 13 of the default ONNX operator set. + +Other versions of this operator: 1, 7, 11 + +#### Inputs + +
+
A (non-differentiable) : T
+
First input operand for the logical operator.
+
B (non-differentiable) : T
+
Second input operand for the logical operator.
+
+ +#### Outputs + +
+
C (non-differentiable) : T1
+
Result tensor.
+
+ +#### Type Constraints + +
+
T : tensor(bool), tensor(uint8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(int8), tensor(int16), tensor(int32), tensor(int64), tensor(float16), tensor(float), tensor(double), tensor(bfloat16)
+
Constrains input types to all numeric tensors.
+
T1 : tensor(bool)
+
Constrains output to boolean tensor.
+
+ + +#### Examples + +
+equal + +```python +node = onnx.helper.make_node( + 'Equal', + inputs=['x', 'y'], + outputs=['z'], +) + +x = (np.random.randn(3, 4, 5) * 10).astype(np.int32) +y = (np.random.randn(3, 4, 5) * 10).astype(np.int32) +z = np.equal(x, y) +expect(node, inputs=[x, y], outputs=[z], + name='test_equal') +``` + +
+ + +
+equal_broadcast + +```python +node = onnx.helper.make_node( + 'Equal', + inputs=['x', 'y'], + outputs=['z'], +) + +x = (np.random.randn(3, 4, 5) * 10).astype(np.int32) +y = (np.random.randn(5) * 10).astype(np.int32) +z = np.equal(x, y) +expect(node, inputs=[x, y], outputs=[z], + name='test_equal_bcast') +``` + +
+ + +### **Erf** + + Computes the error function of the given input tensor element-wise. + +#### Version + +This version of the operator has been available since version 13 of the default ONNX operator set. + +Other versions of this operator: 9 + +#### Inputs + +
+
input (differentiable) : T
+
Input tensor
+
+ +#### Outputs + +
+
output (differentiable) : T
+
The error function of the input tensor computed element-wise. It has the same shape and type of the input.
+
+ +#### Type Constraints + +
+
T : tensor(uint8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(int8), tensor(int16), tensor(int32), tensor(int64), tensor(float16), tensor(float), tensor(double), tensor(bfloat16)
+
Constrain input and output types to all numeric tensors.
+
+ + +#### Examples + +
+erf + +```python +node = onnx.helper.make_node( + 'Erf', + inputs=['x'], + outputs=['y'], +) + +x = np.random.randn(1, 3, 32, 32).astype(np.float32) +y = np.vectorize(math.erf)(x).astype(np.float32) +expect(node, inputs=[x], outputs=[y], + name='test_erf') +``` + +
+ + +### **Exp** + + Calculates the exponential of the given input tensor, element-wise. + +#### Version + +This version of the operator has been available since version 13 of the default ONNX operator set. + +Other versions of this operator: 1, 6 + +#### Inputs + +
+
input (differentiable) : T
+
Input tensor
+
+ +#### Outputs + +
+
output (differentiable) : T
+
The exponential of the input tensor computed element-wise
+
+ +#### Type Constraints + +
+
T : tensor(float16), tensor(float), tensor(double), tensor(bfloat16)
+
Constrain input and output types to float tensors.
+
+ + +#### Examples + +
+exp + +```python +node = onnx.helper.make_node( + 'Exp', + inputs=['x'], + outputs=['y'], +) + +x = np.array([-1, 0, 1]).astype(np.float32) +y = np.exp(x) # expected output [0.36787945, 1., 2.71828175] +expect(node, inputs=[x], outputs=[y], + name='test_exp_example') + +x = np.random.randn(3, 4, 5).astype(np.float32) +y = np.exp(x) +expect(node, inputs=[x], outputs=[y], + name='test_exp') +``` + +
+ + +### **Expand** + + Broadcast the input tensor following the given shape and the broadcast rule. + The broadcast rule is similar to numpy.array(input) * numpy.ones(shape): + Dimensions are right alignment; + Two corresponding dimension must have the same value, or one of them is equal to 1. + Also, this operator is similar to numpy.broadcast_to(input, shape), + but the major difference is numpy.broadcast_to() does not allow shape to be smaller than input.size(). + It is possible that the output.shape is not equal to shape, when some dimensions in shape is equal to 1, + or the shape.ndim < input.shape.ndim. + +#### Version + +This version of the operator has been available since version 13 of the default ONNX operator set. + +Other versions of this operator: 8 + +#### Inputs + +
+
input (differentiable) : T
+
Input tensor
+
shape (non-differentiable) : tensor(int64)
+
A 1-D tensor indicates the shape you want to expand to, following the broadcast rule
+
+ +#### Outputs + +
+
output (differentiable) : T
+
Output tensor
+
+ +#### Type Constraints + +
+
T : tensor(uint8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(int8), tensor(int16), tensor(int32), tensor(int64), tensor(bfloat16), tensor(float16), tensor(float), tensor(double), tensor(string), tensor(bool), tensor(complex64), tensor(complex128)
+
Constrain input and output types to all tensors.
+
+ + +#### Examples + +
+dim_changed + +```python +node = onnx.helper.make_node( + 'Expand', + inputs=['data', 'new_shape'], + outputs=['expanded'], +) +shape = [3, 1] +data = np.reshape(np.arange(1, np.prod(shape) + 1, dtype=np.float32), shape) +#print(data) +#[[1.], [2.], [3.]] +new_shape = [2, 1, 6] +expanded = data * np.ones(new_shape, dtype=np.float32) +#print(expanded) +#[[[1., 1., 1., 1., 1., 1.], +# [2., 2., 2., 2., 2., 2.], +# [3., 3., 3., 3., 3., 3.]], +# +# [[1., 1., 1., 1., 1., 1.], +# [2., 2., 2., 2., 2., 2.], +# [3., 3., 3., 3., 3., 3.]]] +new_shape = np.array(new_shape, dtype=np.int64) +expect(node, inputs=[data, new_shape], outputs=[expanded], + name='test_expand_dim_changed') +``` + +
+ + +
+dim_unchanged + +```python +node = onnx.helper.make_node( + 'Expand', + inputs=['data', 'new_shape'], + outputs=['expanded'], +) +shape = [3, 1] +new_shape = [3, 4] +data = np.reshape(np.arange(1, np.prod(shape) + 1, dtype=np.float32), shape) +#print(data) +#[[1.], [2.], [3.]] +expanded = np.tile(data, 4) +#print(expanded) +#[[1., 1., 1., 1.], +# [2., 2., 2., 2.], +# [3., 3., 3., 3.]] +new_shape = np.array(new_shape, dtype=np.int64) +expect(node, inputs=[data, new_shape], outputs=[expanded], + name='test_expand_dim_unchanged') +``` + +
+ + +### **EyeLike** + + Generate a 2D tensor (matrix) with ones on the diagonal and zeros everywhere else. Only 2D + tensors are supported, i.e. input T1 must be of rank 2. The shape of the output tensor is the + same as the input tensor. The data type can be specified by the 'dtype' argument. If + 'dtype' is not specified, then the type of input tensor is used. By default, the main diagonal + is populated with ones, but attribute 'k' can be used to populate upper or lower diagonals. + The 'dtype' argument must be one of the data types specified in the 'DataType' enum field in the + TensorProto message and be valid as an output type. + +#### Version + +This version of the operator has been available since version 9 of the default ONNX operator set. + +#### Attributes + +
+
dtype : int
+
(Optional) The data type for the elements of the output tensor. If not specified,the data type of the input tensor T1 is used. If input tensor T1 is also notspecified, then type defaults to 'float'.
+
k : int (default is 0)
+
(Optional) Index of the diagonal to be populated with ones. Default is 0. If T2 is the output, this op sets T2[i, i+k] = 1. k = 0 populates the main diagonal, k > 0 populates an upper diagonal, and k < 0 populates a lower diagonal.
+
+ +#### Inputs + +
+
input : T1
+
2D input tensor to copy shape, and optionally, type information from.
+
+ +#### Outputs + +
+
output : T2
+
Output tensor, same shape as input tensor T1.
+
+ +#### Type Constraints + +
+
T1 : tensor(float16), tensor(float), tensor(double), tensor(int8), tensor(int16), tensor(int32), tensor(int64), tensor(uint8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(bool)
+
Constrain input types. Strings and complex are not supported.
+
T2 : tensor(float16), tensor(float), tensor(double), tensor(int8), tensor(int16), tensor(int32), tensor(int64), tensor(uint8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(bool)
+
Constrain output types. Strings and complex are not supported.
+
+ + +#### Examples + +
+populate_off_main_diagonal + +```python +shape = (4, 5) +off_diagonal_offset = 1 +node = onnx.helper.make_node( + 'EyeLike', + inputs=['x'], + outputs=['y'], + k=off_diagonal_offset, + dtype=onnx.TensorProto.FLOAT, +) + +x = np.random.randint(0, 100, size=shape, dtype=np.int32) +y = np.eye(shape[0], shape[1], k=off_diagonal_offset, dtype=np.float32) +expect(node, inputs=[x], outputs=[y], name='test_eyelike_populate_off_main_diagonal') +``` + +
+ + +
+with_dtype + +```python +shape = (3, 4) +node = onnx.helper.make_node( + 'EyeLike', + inputs=['x'], + outputs=['y'], + dtype=onnx.TensorProto.DOUBLE, +) + +x = np.random.randint(0, 100, size=shape, dtype=np.int32) +y = np.eye(shape[0], shape[1], dtype=np.float64) +expect(node, inputs=[x], outputs=[y], name='test_eyelike_with_dtype') +``` + +
+ + +
+without_dtype + +```python +shape = (4, 4) +node = onnx.helper.make_node( + 'EyeLike', + inputs=['x'], + outputs=['y'], +) + +x = np.random.randint(0, 100, size=shape, dtype=np.int32) +y = np.eye(shape[0], shape[1], dtype=np.int32) +expect(node, inputs=[x], outputs=[y], name='test_eyelike_without_dtype') +``` + +
+ + +### **Flatten** + + Flattens the input tensor into a 2D matrix. If input tensor has shape + (d_0, d_1, ... d_n) then the output will have shape + (d_0 X d_1 ... d_(axis-1), d_axis X d_(axis+1) ... X dn). + +#### Version + +This version of the operator has been available since version 13 of the default ONNX operator set. + +Other versions of this operator: 1, 9, 11 + +#### Attributes + +
+
axis : int (default is 1)
+
Indicate up to which input dimensions (exclusive) should be flattened to the outer dimension of the output. The value for axis must be in the range [-r, r], where r is the rank of the input tensor. Negative value means counting dimensions from the back. When axis = 0, the shape of the output tensor is (1, (d_0 X d_1 ... d_n), where the shape of the input tensor is (d_0, d_1, ... d_n).
+
+ +#### Inputs + +
+
input (differentiable) : T
+
A tensor of rank >= axis.
+
+ +#### Outputs + +
+
output (differentiable) : T
+
A 2D tensor with the contents of the input tensor, with input dimensions up to axis flattened to the outer dimension of the output and remaining input dimensions flattened into the inner dimension of the output.
+
+ +#### Type Constraints + +
+
T : tensor(uint8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(int8), tensor(int16), tensor(int32), tensor(int64), tensor(bfloat16), tensor(float16), tensor(float), tensor(double), tensor(string), tensor(bool), tensor(complex64), tensor(complex128)
+
Constrain input and output to all tensor types.
+
+ + +#### Examples + +
+flatten + +```python +shape = (2, 3, 4, 5) +a = np.random.random_sample(shape).astype(np.float32) + +for i in range(len(shape)): + node = onnx.helper.make_node( + 'Flatten', + inputs=['a'], + outputs=['b'], + axis=i, + ) + + new_shape = (1, -1) if i == 0 else (np.prod(shape[0:i]).astype(int), -1) + b = np.reshape(a, new_shape) + expect(node, inputs=[a], outputs=[b], + name='test_flatten_axis' + str(i)) +``` + +
+ + +
+flatten_negative_axis + +```python +shape = (2, 3, 4, 5) +a = np.random.random_sample(shape).astype(np.float32) + +for i in range(-len(shape), 0): + node = onnx.helper.make_node( + 'Flatten', + inputs=['a'], + outputs=['b'], + axis=i, + ) + + new_shape = (np.prod(shape[0:i]).astype(int), -1) + b = np.reshape(a, new_shape) + expect(node, inputs=[a], outputs=[b], + name='test_flatten_negative_axis' + str(abs(i))) +``` + +
+ + +
+flatten_with_default_axis + +```python +node = onnx.helper.make_node( + 'Flatten', + inputs=['a'], + outputs=['b'], # Default value for axis: axis=1 +) + +shape = (5, 4, 3, 2) +a = np.random.random_sample(shape).astype(np.float32) +new_shape = (5, 24) +b = np.reshape(a, new_shape) +expect(node, inputs=[a], outputs=[b], + name='test_flatten_default_axis') +``` + +
+ + +### **Floor** + + Floor takes one input data (Tensor) and produces one output data + (Tensor) where the floor is, y = floor(x), is applied to + the tensor elementwise. + +#### Version + +This version of the operator has been available since version 13 of the default ONNX operator set. + +Other versions of this operator: 1, 6 + +#### Inputs + +
+
X (non-differentiable) : T
+
Input tensor
+
+ +#### Outputs + +
+
Y (non-differentiable) : T
+
Output tensor
+
+ +#### Type Constraints + +
+
T : tensor(float16), tensor(float), tensor(double), tensor(bfloat16)
+
Constrain input and output types to float tensors.
+
+ + +#### Examples + +
+floor + +```python +node = onnx.helper.make_node( + 'Floor', + inputs=['x'], + outputs=['y'], +) + +x = np.array([-1.5, 1.2, 2]).astype(np.float32) +y = np.floor(x) # expected output [-2., 1., 2.] +expect(node, inputs=[x], outputs=[y], + name='test_floor_example') + +x = np.random.randn(3, 4, 5).astype(np.float32) +y = np.floor(x) +expect(node, inputs=[x], outputs=[y], + name='test_floor') +``` + +
+ + +### **GRU** + + Computes an one-layer GRU. This operator is usually supported via some custom + implementation such as CuDNN. + + Notations: + + `X` - input tensor + + `z` - update gate + + `r` - reset gate + + `h` - hidden gate + + `t` - time step (t-1 means previous time step) + + `W[zrh]` - W parameter weight matrix for update, reset, and hidden gates + + `R[zrh]` - R recurrence weight matrix for update, reset, and hidden gates + + `Wb[zrh]` - W bias vectors for update, reset, and hidden gates + + `Rb[zrh]` - R bias vectors for update, reset, and hidden gates + + `WB[zrh]` - W parameter weight matrix for backward update, reset, and hidden gates + + `RB[zrh]` - R recurrence weight matrix for backward update, reset, and hidden gates + + `WBb[zrh]` - W bias vectors for backward update, reset, and hidden gates + + `RBb[zrh]` - R bias vectors for backward update, reset, and hidden gates + + `H` - Hidden state + + `num_directions` - 2 if direction == bidirectional else 1 + + Activation functions: + + Relu(x) - max(0, x) + + Tanh(x) - (1 - e^{-2x})/(1 + e^{-2x}) + + Sigmoid(x) - 1/(1 + e^{-x}) + + (NOTE: Below are optional) + + Affine(x) - alpha*x + beta + + LeakyRelu(x) - x if x >= 0 else alpha * x + + ThresholdedRelu(x) - x if x >= alpha else 0 + + ScaledTanh(x) - alpha*Tanh(beta*x) + + HardSigmoid(x) - min(max(alpha*x + beta, 0), 1) + + Elu(x) - x if x >= 0 else alpha*(e^x - 1) + + Softsign(x) - x/(1 + |x|) + + Softplus(x) - log(1 + e^x) + + Equations (Default: f=Sigmoid, g=Tanh): + + - zt = f(Xt*(Wz^T) + Ht-1*(Rz^T) + Wbz + Rbz) + + - rt = f(Xt*(Wr^T) + Ht-1*(Rr^T) + Wbr + Rbr) + + - ht = g(Xt*(Wh^T) + (rt (.) Ht-1)*(Rh^T) + Rbh + Wbh) # default, when linear_before_reset = 0 + + - ht = g(Xt*(Wh^T) + (rt (.) (Ht-1*(Rh^T) + Rbh)) + Wbh) # when linear_before_reset != 0 + + - Ht = (1 - zt) (.) ht + zt (.) Ht-1 + This operator has **optional** inputs/outputs. See [the doc](IR.md) for more details about the representation of optional arguments. An empty string may be used in the place of an actual argument's name to indicate a missing argument. Trailing optional arguments (those not followed by an argument that is present) may also be simply omitted. + +#### Version + +This version of the operator has been available since version 14 of the default ONNX operator set. + +Other versions of this operator: 1, 3, 7 + +#### Attributes + +
+
activation_alpha : list of floats
+
Optional scaling values used by some activation functions. The values are consumed in the order of activation functions, for example (f, g, h) in LSTM. Default values are the same as of corresponding ONNX operators.For example with LeakyRelu, the default alpha is 0.01.
+
activation_beta : list of floats
+
Optional scaling values used by some activation functions. The values are consumed in the order of activation functions, for example (f, g, h) in LSTM. Default values are the same as of corresponding ONNX operators.
+
activations : list of strings
+
A list of 2 (or 4 if bidirectional) activation functions for update, reset, and hidden gates. The activation functions must be one of the activation functions specified above. Optional: See the equations for default if not specified.
+
clip : float
+
Cell clip threshold. Clipping bounds the elements of a tensor in the range of [-threshold, +threshold] and is applied to the input of activations. No clip if not specified.
+
direction : string (default is forward)
+
Specify if the RNN is forward, reverse, or bidirectional. Must be one of forward (default), reverse, or bidirectional.
+
hidden_size : int
+
Number of neurons in the hidden layer
+
layout : int (default is 0)
+
The shape format of inputs X, initial_h and outputs Y, Y_h. If 0, the following shapes are expected: X.shape = [seq_length, batch_size, input_size], Y.shape = [seq_length, num_directions, batch_size, hidden_size], initial_h.shape = Y_h.shape = [num_directions, batch_size, hidden_size]. If 1, the following shapes are expected: X.shape = [batch_size, seq_length, input_size], Y.shape = [batch_size, seq_length, num_directions, hidden_size], initial_h.shape = Y_h.shape = [batch_size, num_directions, hidden_size].
+
linear_before_reset : int (default is 0)
+
When computing the output of the hidden gate, apply the linear transformation before multiplying by the output of the reset gate.
+
+ +#### Inputs (3 - 6) + +
+
X (differentiable) : T
+
The input sequences packed (and potentially padded) into one 3-D tensor with the shape of `[seq_length, batch_size, input_size]`.
+
W (differentiable) : T
+
The weight tensor for the gates. Concatenation of `W[zrh]` and `WB[zrh]` (if bidirectional) along dimension 0. This tensor has shape `[num_directions, 3*hidden_size, input_size]`.
+
R (differentiable) : T
+
The recurrence weight tensor. Concatenation of `R[zrh]` and `RB[zrh]` (if bidirectional) along dimension 0. This tensor has shape `[num_directions, 3*hidden_size, hidden_size]`.
+
B (optional, differentiable) : T
+
The bias tensor for the gates. Concatenation of `[Wb[zrh], Rb[zrh]]` and `[WBb[zrh], RBb[zrh]]` (if bidirectional) along dimension 0. This tensor has shape `[num_directions, 6*hidden_size]`. Optional: If not specified - assumed to be 0
+
sequence_lens (optional, non-differentiable) : T1
+
Optional tensor specifying lengths of the sequences in a batch. If not specified - assumed all sequences in the batch to have length `seq_length`. It has shape `[batch_size]`.
+
initial_h (optional, non-differentiable) : T
+
Optional initial value of the hidden. If not specified - assumed to be 0. It has shape `[num_directions, batch_size, hidden_size]`.
+
+ +#### Outputs (0 - 2) + +
+
Y (optional, differentiable) : T
+
A tensor that concats all the intermediate output values of the hidden. It has shape `[seq_length, num_directions, batch_size, hidden_size]`.
+
Y_h (optional, differentiable) : T
+
The last output value of the hidden. It has shape `[num_directions, batch_size, hidden_size]`.
+
+ +#### Type Constraints + +
+
T : tensor(float16), tensor(float), tensor(double)
+
Constrain input and output types to float tensors.
+
T1 : tensor(int32)
+
Constrain seq_lens to integer tensor.
+
+ + +#### Examples + +
+batchwise + +```python +input = np.array([[[1., 2.]], [[3., 4.]], [[5., 6.]]]).astype(np.float32) + +input_size = 2 +hidden_size = 6 +number_of_gates = 3 +weight_scale = 0.2 +layout = 1 + +node = onnx.helper.make_node( + 'GRU', + inputs=['X', 'W', 'R'], + outputs=['Y', 'Y_h'], + hidden_size=hidden_size, + layout=layout +) + +W = weight_scale * np.ones((1, number_of_gates * hidden_size, input_size)).astype(np.float32) +R = weight_scale * np.ones((1, number_of_gates * hidden_size, hidden_size)).astype(np.float32) + +gru = GRU_Helper(X=input, W=W, R=R, layout=layout) +Y, Y_h = gru.step() +expect(node, inputs=[input, W, R], outputs=[Y.astype(np.float32), Y_h.astype(np.float32)], name='test_gru_batchwise') +``` + +
+ + +
+defaults + +```python +input = np.array([[[1., 2.], [3., 4.], [5., 6.]]]).astype(np.float32) + +input_size = 2 +hidden_size = 5 +weight_scale = 0.1 +number_of_gates = 3 + +node = onnx.helper.make_node( + 'GRU', + inputs=['X', 'W', 'R'], + outputs=['', 'Y_h'], + hidden_size=hidden_size +) + +W = weight_scale * np.ones((1, number_of_gates * hidden_size, input_size)).astype(np.float32) +R = weight_scale * np.ones((1, number_of_gates * hidden_size, hidden_size)).astype(np.float32) + +gru = GRU_Helper(X=input, W=W, R=R) +_, Y_h = gru.step() +expect(node, inputs=[input, W, R], outputs=[Y_h.astype(np.float32)], name='test_gru_defaults') +``` + +
+ + +
+initial_bias + +```python +input = np.array([[[1., 2., 3.], [4., 5., 6.], [7., 8., 9.]]]).astype(np.float32) + +input_size = 3 +hidden_size = 3 +weight_scale = 0.1 +custom_bias = 0.1 +number_of_gates = 3 + +node = onnx.helper.make_node( + 'GRU', + inputs=['X', 'W', 'R', 'B'], + outputs=['', 'Y_h'], + hidden_size=hidden_size +) + +W = weight_scale * np.ones((1, number_of_gates * hidden_size, input_size)).astype(np.float32) +R = weight_scale * np.ones((1, number_of_gates * hidden_size, hidden_size)).astype(np.float32) + +# Adding custom bias +W_B = custom_bias * np.ones((1, number_of_gates * hidden_size)).astype(np.float32) +R_B = np.zeros((1, number_of_gates * hidden_size)).astype(np.float32) +B = np.concatenate((W_B, R_B), axis=1) + +gru = GRU_Helper(X=input, W=W, R=R, B=B) +_, Y_h = gru.step() +expect(node, inputs=[input, W, R, B], outputs=[Y_h.astype(np.float32)], name='test_gru_with_initial_bias') +``` + +
+ + +
+seq_length + +```python +input = np.array([[[1., 2., 3.], [4., 5., 6.], [7., 8., 9.]], + [[10., 11., 12.], [13., 14., 15.], [16., 17., 18.]]]).astype(np.float32) + +input_size = 3 +hidden_size = 5 +number_of_gates = 3 + +node = onnx.helper.make_node( + 'GRU', + inputs=['X', 'W', 'R', 'B'], + outputs=['', 'Y_h'], + hidden_size=hidden_size +) + +W = np.random.randn(1, number_of_gates * hidden_size, input_size).astype(np.float32) +R = np.random.randn(1, number_of_gates * hidden_size, hidden_size).astype(np.float32) + +# Adding custom bias +W_B = np.random.randn(1, number_of_gates * hidden_size).astype(np.float32) +R_B = np.random.randn(1, number_of_gates * hidden_size).astype(np.float32) +B = np.concatenate((W_B, R_B), axis=1) + +gru = GRU_Helper(X=input, W=W, R=R, B=B) +_, Y_h = gru.step() +expect(node, inputs=[input, W, R, B], outputs=[Y_h.astype(np.float32)], name='test_gru_seq_length') +``` + +
+ + +### **Gather** + + Given `data` tensor of rank r >= 1, and `indices` tensor of rank q, gather + entries of the axis dimension of `data` (by default outer-most one as axis=0) indexed by `indices`, and concatenates + them in an output tensor of rank q + (r - 1). + + axis = 0 : + + Let + k = indices[i_{0}, ..., i_{q-1}] + Then + output[i_{0}, ..., i_{q-1}, j_{0}, ..., j_{r-2}] = input[k , j_{0}, ..., j_{r-2}] + + ``` + data = [ + [1.0, 1.2], + [2.3, 3.4], + [4.5, 5.7], + ] + indices = [ + [0, 1], + [1, 2], + ] + output = [ + [ + [1.0, 1.2], + [2.3, 3.4], + ], + [ + [2.3, 3.4], + [4.5, 5.7], + ], + ] + ``` + axis = 1 : + + Let + k = indices[i_{0}, ..., i_{q-1}] + Then + output[i_{0}, ..., i_{q-1}, j_{0}, ..., j_{r-2}] = input[j_{0}, k, j_{1}, ..., j_{r-2}] + + ``` + data = [ + [1.0, 1.2, 1.9], + [2.3, 3.4, 3.9], + [4.5, 5.7, 5.9], + ] + indices = [ + [0, 2], + ] + axis = 1, + output = [ + [[1.0, 1.9]], + [[2.3, 3.9]], + [[4.5, 5.9]], + ] + ``` + +#### Version + +This version of the operator has been available since version 13 of the default ONNX operator set. + +Other versions of this operator: 1, 11 + +#### Attributes + +
+
axis : int (default is 0)
+
Which axis to gather on. Negative value means counting dimensions from the back. Accepted range is [-r, r-1] where r = rank(data).
+
+ +#### Inputs + +
+
data (differentiable) : T
+
Tensor of rank r >= 1.
+
indices (non-differentiable) : Tind
+
Tensor of int32/int64 indices, of any rank q. All index values are expected to be within bounds [-s, s-1] along axis of size s. It is an error if any of the index values are out of bounds.
+
+ +#### Outputs + +
+
output (differentiable) : T
+
Tensor of rank q + (r - 1).
+
+ +#### Type Constraints + +
+
T : tensor(uint8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(int8), tensor(int16), tensor(int32), tensor(int64), tensor(bfloat16), tensor(float16), tensor(float), tensor(double), tensor(string), tensor(bool), tensor(complex64), tensor(complex128)
+
Constrain input and output types to any tensor type.
+
Tind : tensor(int32), tensor(int64)
+
Constrain indices to integer types
+
+ + +#### Examples + +
+gather_0 + +```python +node = onnx.helper.make_node( + 'Gather', + inputs=['data', 'indices'], + outputs=['y'], + axis=0, +) +data = np.random.randn(5, 4, 3, 2).astype(np.float32) +indices = np.array([0, 1, 3]) +y = np.take(data, indices, axis=0) + +expect(node, inputs=[data, indices.astype(np.int64)], outputs=[y], + name='test_gather_0') +``` + +
+ + +
+gather_1 + +```python +node = onnx.helper.make_node( + 'Gather', + inputs=['data', 'indices'], + outputs=['y'], + axis=1, +) +data = np.random.randn(5, 4, 3, 2).astype(np.float32) +indices = np.array([0, 1, 3]) +y = np.take(data, indices, axis=1) + +expect(node, inputs=[data, indices.astype(np.int64)], outputs=[y], + name='test_gather_1') +``` + +
+ + +
+gather_2d_indices + +```python +node = onnx.helper.make_node( + 'Gather', + inputs=['data', 'indices'], + outputs=['y'], + axis=1, +) +data = np.random.randn(3, 3).astype(np.float32) +indices = np.array([[0, 2]]) +y = np.take(data, indices, axis=1) + +expect(node, inputs=[data, indices.astype(np.int64)], outputs=[y], + name='test_gather_2d_indices') +``` + +
+ + +
+gather_negative_indices + +```python +node = onnx.helper.make_node( + 'Gather', + inputs=['data', 'indices'], + outputs=['y'], + axis=0, +) +data = np.arange(10).astype(np.float32) +indices = np.array([0, -9, -10]) +y = np.take(data, indices, axis=0) + +# print(y) +# [0. 1. 0.] + +expect(node, inputs=[data, indices.astype(np.int64)], outputs=[y], + name='test_gather_negative_indices') +``` + +
+ + +### **GatherElements** + + GatherElements takes two inputs `data` and `indices` of the same rank r >= 1 + and an optional attribute `axis` that identifies an axis of `data` + (by default, the outer-most axis, that is axis 0). It is an indexing operation + that produces its output by indexing into the input data tensor at index + positions determined by elements of the `indices` tensor. + Its output shape is the same as the shape of `indices` and consists of one value + (gathered from the `data`) for each element in `indices`. + + For instance, in the 3-D case (r = 3), the output produced is determined + by the following equations: + ``` + out[i][j][k] = input[index[i][j][k]][j][k] if axis = 0, + out[i][j][k] = input[i][index[i][j][k]][k] if axis = 1, + out[i][j][k] = input[i][j][index[i][j][k]] if axis = 2, + ``` + + This operator is also the inverse of ScatterElements. It is similar to Torch's gather operation. + + Example 1: + ``` + data = [ + [1, 2], + [3, 4], + ] + indices = [ + [0, 0], + [1, 0], + ] + axis = 1 + output = [ + [1, 1], + [4, 3], + ] + ``` + Example 2: + ``` + data = [ + [1, 2, 3], + [4, 5, 6], + [7, 8, 9], + ] + indices = [ + [1, 2, 0], + [2, 0, 0], + ] + axis = 0 + output = [ + [4, 8, 3], + [7, 2, 3], + ] + ``` + +#### Version + +This version of the operator has been available since version 13 of the default ONNX operator set. + +Other versions of this operator: 11 + +#### Attributes + +
+
axis : int (default is 0)
+
Which axis to gather on. Negative value means counting dimensions from the back. Accepted range is [-r, r-1] where r = rank(data).
+
+ +#### Inputs + +
+
data (differentiable) : T
+
Tensor of rank r >= 1.
+
indices (non-differentiable) : Tind
+
Tensor of int32/int64 indices, with the same rank r as the input. All index values are expected to be within bounds [-s, s-1] along axis of size s. It is an error if any of the index values are out of bounds.
+
+ +#### Outputs + +
+
output (differentiable) : T
+
Tensor of the same shape as indices.
+
+ +#### Type Constraints + +
+
T : tensor(uint8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(int8), tensor(int16), tensor(int32), tensor(int64), tensor(bfloat16), tensor(float16), tensor(float), tensor(double), tensor(string), tensor(bool), tensor(complex64), tensor(complex128)
+
Constrain input and output types to any tensor type.
+
Tind : tensor(int32), tensor(int64)
+
Constrain indices to integer types
+
+ + +#### Examples + +
+gather_elements_0 + +```python +axis = 1 +node = onnx.helper.make_node( + 'GatherElements', + inputs=['data', 'indices'], + outputs=['y'], + axis=axis, +) +data = np.array([[1, 2], + [3, 4]], dtype=np.float32) +indices = np.array([[0, 0], + [1, 0]], dtype=np.int32) + +y = gather_elements(data, indices, axis) +# print(y) produces +# [[1, 1], +# [4, 3]] + +expect(node, inputs=[data, indices.astype(np.int64)], outputs=[y], + name='test_gather_elements_0') +``` + +
+ + +
+gather_elements_1 + +```python +axis = 0 +node = onnx.helper.make_node( + 'GatherElements', + inputs=['data', 'indices'], + outputs=['y'], + axis=axis, +) +data = np.array([[1, 2, 3], + [4, 5, 6], + [7, 8, 9]], dtype=np.float32) +indices = np.array([[1, 2, 0], + [2, 0, 0]], dtype=np.int32) + +y = gather_elements(data, indices, axis) +# print(y) produces +# [[4, 8, 3], +# [7, 2, 3]] + +expect(node, inputs=[data, indices.astype(np.int64)], outputs=[y], + name='test_gather_elements_1') +``` + +
+ + +
+gather_elements_negative_indices + +```python +axis = 0 +node = onnx.helper.make_node( + 'GatherElements', + inputs=['data', 'indices'], + outputs=['y'], + axis=axis, +) +data = np.array([[1, 2, 3], + [4, 5, 6], + [7, 8, 9]], dtype=np.float32) +indices = np.array([[-1, -2, 0], + [-2, 0, 0]], dtype=np.int32) + +y = gather_elements(data, indices, axis) +# print(y) produces +# [[7, 5, 3], +# [4, 2, 3]] + +expect(node, inputs=[data, indices.astype(np.int64)], outputs=[y], + name='test_gather_elements_negative_indices') +``` + +
+ + +### **GatherND** + + Given `data` tensor of rank `r` >= 1, `indices` tensor of rank `q` >= 1, and `batch_dims` integer `b`, this operator gathers + slices of `data` into an output tensor of rank `q + r - indices_shape[-1] - 1 - b`. + + `indices` is an q-dimensional integer tensor, best thought of as a `(q-1)`-dimensional tensor of index-tuples into `data`, + where each element defines a slice of `data` + + `batch_dims` (denoted as `b`) is an integer indicating the number of batch dimensions, i.e the leading `b` number of dimensions of + `data` tensor and `indices` are representing the batches, and the gather starts from the `b+1` dimension. + + Some salient points about the inputs' rank and shape: + + 1) r >= 1 and q >= 1 are to be honored. There is no dependency condition to be met between ranks `r` and `q` + + 2) The first `b` dimensions of the shape of `indices` tensor and `data` tensor must be equal. + + 3) b < min(q, r) is to be honored. + + 4) The `indices_shape[-1]` should have a value between 1 (inclusive) and rank `r-b` (inclusive) + + 5) All values in `indices` are expected to be within bounds [-s, s-1] along axis of size `s` (i.e.) `-data_shape[i] <= indices[...,i] <= data_shape[i] - 1`. + It is an error if any of the index values are out of bounds. + + The output is computed as follows: + + The output tensor is obtained by mapping each index-tuple in the `indices` tensor to the corresponding slice of the input `data`. + + 1) If `indices_shape[-1] > r-b` => error condition + + 2) If `indices_shape[-1] == r-b`, since the rank of `indices` is `q`, `indices` can be thought of as `N` `(q-b-1)`-dimensional tensors + containing 1-D tensors of dimension `r-b`, where `N` is an integer equals to the product of 1 and all the elements in the batch dimensions + of the indices_shape. Let us think of each such `r-b` ranked tensor as `indices_slice`. Each *scalar value* corresponding to `data[0:b-1,indices_slice]` + is filled into the corresponding location of the `(q-b-1)`-dimensional tensor to form the `output` tensor (Example 1 below) + + 3) If `indices_shape[-1] < r-b`, since the rank of `indices` is `q`, `indices` can be thought of as `N` `(q-b-1)`-dimensional tensor + containing 1-D tensors of dimension `< r-b`. Let us think of each such tensors as `indices_slice`. Each *tensor slice* corresponding + to `data[0:b-1, indices_slice , :]` is filled into the corresponding location of the `(q-b-1)`-dimensional tensor + to form the `output` tensor (Examples 2, 3, 4 and 5 below) + + This operator is the inverse of `ScatterND`. + + `Example 1` + + batch_dims = 0 + + data = [[0,1],[2,3]] # data_shape = [2, 2] + + indices = [[0,0],[1,1]] # indices_shape = [2, 2] + + output = [0,3] # output_shape = [2] + + `Example 2` + + batch_dims = 0 + + data = [[0,1],[2,3]] # data_shape = [2, 2] + + indices = [[1],[0]] # indices_shape = [2, 1] + + output = [[2,3],[0,1]] # output_shape = [2, 2] + + `Example 3` + + batch_dims = 0 + + data = [[[0,1],[2,3]],[[4,5],[6,7]]] # data_shape = [2, 2, 2] + + indices = [[0,1],[1,0]] # indices_shape = [2, 2] + + output = [[2,3],[4,5]] # output_shape = [2, 2] + + `Example 4` + + batch_dims = 0 + + data = [[[0,1],[2,3]],[[4,5],[6,7]]] # data_shape = [2, 2, 2] + + indices = [[[0,1]],[[1,0]]] # indices_shape = [2, 1, 2] + + output = [[[2,3]],[[4,5]]] # output_shape = [2, 1, 2] + + `Example 5` + + batch_dims = 1 + + data = [[[0,1],[2,3]],[[4,5],[6,7]]] # data_shape = [2, 2, 2] + + indices = [[1],[0]] # indices_shape = [2, 1] + + output = [[2,3],[4,5]] # output_shape = [2, 2] + + + +#### Version + +This version of the operator has been available since version 13 of the default ONNX operator set. + +Other versions of this operator: 11, 12 + +#### Attributes + +
+
batch_dims : int (default is 0)
+
The number of batch dimensions. The gather of indexing starts from dimension of data[batch_dims:]
+
+ +#### Inputs + +
+
data (differentiable) : T
+
Tensor of rank r >= 1.
+
indices (non-differentiable) : tensor(int64)
+
Tensor of rank q >= 1. All index values are expected to be within bounds [-s, s-1] along axis of size s. It is an error if any of the index values are out of bounds.
+
+ +#### Outputs + +
+
output (differentiable) : T
+
Tensor of rank q + r - indices_shape[-1] - 1.
+
+ +#### Type Constraints + +
+
T : tensor(uint8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(int8), tensor(int16), tensor(int32), tensor(int64), tensor(bfloat16), tensor(float16), tensor(float), tensor(double), tensor(string), tensor(bool), tensor(complex64), tensor(complex128)
+
Constrain input and output types to any tensor type.
+
+ + +#### Examples + +
+float32 + +```python +node = onnx.helper.make_node( + 'GatherND', + inputs=['data', 'indices'], + outputs=['output'], +) + +data = np.array([[[0, 1], [2, 3]], [[4, 5], [6, 7]]], dtype=np.float32) +indices = np.array([[[0, 1]], [[1, 0]]], dtype=np.int64) +output = gather_nd_impl(data, indices, 0) +expected_output = np.array([[[2, 3]], [[4, 5]]], dtype=np.float32) +assert (np.array_equal(output, expected_output)) +expect(node, inputs=[data, indices], outputs=[output], + name='test_gathernd_example_float32') +``` + +
+ + +
+int32 + +```python +node = onnx.helper.make_node( + 'GatherND', + inputs=['data', 'indices'], + outputs=['output'], +) + +data = np.array([[0, 1], [2, 3]], dtype=np.int32) +indices = np.array([[0, 0], [1, 1]], dtype=np.int64) +output = gather_nd_impl(data, indices, 0) +expected_output = np.array([0, 3], dtype=np.int32) +assert (np.array_equal(output, expected_output)) +expect(node, inputs=[data, indices], outputs=[output], + name='test_gathernd_example_int32') +``` + +
+ + +
+int32_batchdim_1 + +```python +node = onnx.helper.make_node( + 'GatherND', + inputs=['data', 'indices'], + outputs=['output'], + batch_dims=1, +) + +data = np.array([[[0, 1], [2, 3]], [[4, 5], [6, 7]]], dtype=np.int32) +indices = np.array([[1], [0]], dtype=np.int64) +output = gather_nd_impl(data, indices, 1) +expected_output = np.array([[2, 3], [4, 5]], dtype=np.int32) +assert (np.array_equal(output, expected_output)) +expect(node, inputs=[data, indices], outputs=[output], + name='test_gathernd_example_int32_batch_dim1') +``` + +
+ + +### **Gemm** + + General Matrix multiplication: + https://en.wikipedia.org/wiki/Basic_Linear_Algebra_Subprograms#Level_3 + + A' = transpose(A) if transA else A + + B' = transpose(B) if transB else B + + Compute Y = alpha * A' * B' + beta * C, where input tensor A has shape (M, K) or (K, M), + input tensor B has shape (K, N) or (N, K), input tensor C is broadcastable to shape (M, N), + and output tensor Y has shape (M, N). A will be transposed before doing the + computation if attribute transA is non-zero, same for B and transB. + This operator supports **unidirectional broadcasting** (tensor C should be unidirectional broadcastable to tensor A * B); for more details please check [the doc](Broadcasting.md). + This operator has **optional** inputs/outputs. See [the doc](IR.md) for more details about the representation of optional arguments. An empty string may be used in the place of an actual argument's name to indicate a missing argument. Trailing optional arguments (those not followed by an argument that is present) may also be simply omitted. + +#### Version + +This version of the operator has been available since version 13 of the default ONNX operator set. + +Other versions of this operator: 1, 6, 7, 9, 11 + +#### Attributes + +
+
alpha : float (default is 1.0)
+
Scalar multiplier for the product of input tensors A * B.
+
beta : float (default is 1.0)
+
Scalar multiplier for input tensor C.
+
transA : int (default is 0)
+
Whether A should be transposed
+
transB : int (default is 0)
+
Whether B should be transposed
+
+ +#### Inputs (2 - 3) + +
+
A (differentiable) : T
+
Input tensor A. The shape of A should be (M, K) if transA is 0, or (K, M) if transA is non-zero.
+
B (differentiable) : T
+
Input tensor B. The shape of B should be (K, N) if transB is 0, or (N, K) if transB is non-zero.
+
C (optional, differentiable) : T
+
Optional input tensor C. If not specified, the computation is done as if C is a scalar 0. The shape of C should be unidirectional broadcastable to (M, N).
+
+ +#### Outputs + +
+
Y (differentiable) : T
+
Output tensor of shape (M, N).
+
+ +#### Type Constraints + +
+
T : tensor(float16), tensor(float), tensor(double), tensor(uint32), tensor(uint64), tensor(int32), tensor(int64), tensor(bfloat16)
+
Constrain input and output types to float/int tensors.
+
+ + +#### Examples + +
+all_attributes + +```python +node = onnx.helper.make_node( + 'Gemm', + inputs=['a', 'b', 'c'], + outputs=['y'], + alpha=0.25, + beta=0.35, + transA=1, + transB=1 +) +a = np.random.ranf([4, 3]).astype(np.float32) +b = np.random.ranf([5, 4]).astype(np.float32) +c = np.random.ranf([1, 5]).astype(np.float32) +y = gemm_reference_implementation(a, b, c, transA=1, transB=1, alpha=0.25, beta=0.35) +expect(node, inputs=[a, b, c], outputs=[y], + name='test_gemm_all_attributes') +``` + +
+ + +
+alpha + +```python +node = onnx.helper.make_node( + 'Gemm', + inputs=['a', 'b', 'c'], + outputs=['y'], + alpha=0.5 +) +a = np.random.ranf([3, 5]).astype(np.float32) +b = np.random.ranf([5, 4]).astype(np.float32) +c = np.zeros([1, 4]).astype(np.float32) +y = gemm_reference_implementation(a, b, c, alpha=0.5) +expect(node, inputs=[a, b, c], outputs=[y], + name='test_gemm_alpha') +``` + +
+ + +
+beta + +```python +node = onnx.helper.make_node( + 'Gemm', + inputs=['a', 'b', 'c'], + outputs=['y'], + beta=0.5 +) +a = np.random.ranf([2, 7]).astype(np.float32) +b = np.random.ranf([7, 4]).astype(np.float32) +c = np.random.ranf([1, 4]).astype(np.float32) +y = gemm_reference_implementation(a, b, c, beta=0.5) +expect(node, inputs=[a, b, c], outputs=[y], + name='test_gemm_beta') +``` + +
+ + +
+default_matrix_bias + +```python +node = onnx.helper.make_node( + 'Gemm', + inputs=['a', 'b', 'c'], + outputs=['y'] +) +a = np.random.ranf([3, 6]).astype(np.float32) +b = np.random.ranf([6, 4]).astype(np.float32) +c = np.random.ranf([3, 4]).astype(np.float32) +y = gemm_reference_implementation(a, b, c) +expect(node, inputs=[a, b, c], outputs=[y], + name='test_gemm_default_matrix_bias') +``` + +
+ + +
+default_no_bias + +```python +node = onnx.helper.make_node( + 'Gemm', + inputs=['a', 'b'], + outputs=['y'] +) +a = np.random.ranf([2, 10]).astype(np.float32) +b = np.random.ranf([10, 3]).astype(np.float32) +y = gemm_reference_implementation(a, b) +expect(node, inputs=[a, b], outputs=[y], + name='test_gemm_default_no_bias') +``` + +
+ + +
+default_scalar_bias + +```python +node = onnx.helper.make_node( + 'Gemm', + inputs=['a', 'b', 'c'], + outputs=['y'] +) +a = np.random.ranf([2, 3]).astype(np.float32) +b = np.random.ranf([3, 4]).astype(np.float32) +c = np.array(3.14).astype(np.float32) +y = gemm_reference_implementation(a, b, c) +expect(node, inputs=[a, b, c], outputs=[y], + name='test_gemm_default_scalar_bias') +``` + +
+ + +
+default_single_elem_vector_bias + +```python +node = onnx.helper.make_node( + 'Gemm', + inputs=['a', 'b', 'c'], + outputs=['y'] +) +a = np.random.ranf([3, 7]).astype(np.float32) +b = np.random.ranf([7, 3]).astype(np.float32) +c = np.random.ranf([1]).astype(np.float32) +y = gemm_reference_implementation(a, b, c) +expect(node, inputs=[a, b, c], outputs=[y], + name='test_gemm_default_single_elem_vector_bias') +``` + +
+ + +
+default_vector_bias + +```python +node = onnx.helper.make_node( + 'Gemm', + inputs=['a', 'b', 'c'], + outputs=['y'] +) +a = np.random.ranf([2, 7]).astype(np.float32) +b = np.random.ranf([7, 4]).astype(np.float32) +c = np.random.ranf([1, 4]).astype(np.float32) +y = gemm_reference_implementation(a, b, c) +expect(node, inputs=[a, b, c], outputs=[y], + name='test_gemm_default_vector_bias') +``` + +
+ + +
+default_zero_bias + +```python +node = onnx.helper.make_node( + 'Gemm', + inputs=['a', 'b', 'c'], + outputs=['y'] +) +a = np.random.ranf([3, 5]).astype(np.float32) +b = np.random.ranf([5, 4]).astype(np.float32) +c = np.zeros([1, 4]).astype(np.float32) +y = gemm_reference_implementation(a, b, c) +expect(node, inputs=[a, b, c], outputs=[y], + name='test_gemm_default_zero_bias') +``` + +
+ + +
+transposeA + +```python +node = onnx.helper.make_node( + 'Gemm', + inputs=['a', 'b', 'c'], + outputs=['y'], + transA=1 +) +a = np.random.ranf([6, 3]).astype(np.float32) +b = np.random.ranf([6, 4]).astype(np.float32) +c = np.zeros([1, 4]).astype(np.float32) +y = gemm_reference_implementation(a, b, c, transA=1) +expect(node, inputs=[a, b, c], outputs=[y], + name='test_gemm_transposeA') +``` + +
+ + +
+transposeB + +```python +node = onnx.helper.make_node( + 'Gemm', + inputs=['a', 'b', 'c'], + outputs=['y'], + transB=1 +) +a = np.random.ranf([3, 6]).astype(np.float32) +b = np.random.ranf([4, 6]).astype(np.float32) +c = np.zeros([1, 4]).astype(np.float32) +y = gemm_reference_implementation(a, b, c, transB=1) +expect(node, inputs=[a, b, c], outputs=[y], + name='test_gemm_transposeB') +``` + +
+ + +### **GlobalAveragePool** + + GlobalAveragePool consumes an input tensor X and applies average pooling across + the values in the same channel. This is equivalent to AveragePool with kernel size + equal to the spatial dimension of input tensor. + +#### Version + +This version of the operator has been available since version 1 of the default ONNX operator set. + +#### Inputs + +
+
X (differentiable) : T
+
Input data tensor from the previous operator; dimensions for image case are (N x C x H x W), where N is the batch size, C is the number of channels, and H and W are the height and the width of the data. For non image case, the dimensions are in the form of (N x C x D1 x D2 ... Dn), where N is the batch size.
+
+ +#### Outputs + +
+
Y (differentiable) : T
+
Output data tensor from pooling across the input tensor. The output tensor has the same rank as the input. The first two dimensions of output shape are the same as the input (N x C), while the other dimensions are all 1.
+
+ +#### Type Constraints + +
+
T : tensor(float16), tensor(float), tensor(double)
+
Constrain input and output types to float tensors.
+
+ + +#### Examples + +
+globalaveragepool + +```python +node = onnx.helper.make_node( + 'GlobalAveragePool', + inputs=['x'], + outputs=['y'], +) +x = np.random.randn(1, 3, 5, 5).astype(np.float32) +y = np.mean(x, axis=tuple(range(2, np.ndim(x))), keepdims=True) +expect(node, inputs=[x], outputs=[y], name='test_globalaveragepool') +``` + +
+ + +
+globalaveragepool_precomputed + +```python + +node = onnx.helper.make_node( + 'GlobalAveragePool', + inputs=['x'], + outputs=['y'], +) +x = np.array([[[ + [1, 2, 3], + [4, 5, 6], + [7, 8, 9], +]]]).astype(np.float32) +y = np.array([[[[5]]]]).astype(np.float32) +expect(node, inputs=[x], outputs=[y], name='test_globalaveragepool_precomputed') +``` + +
+ + +### **GlobalLpPool** + + GlobalLpPool consumes an input tensor X and applies lp pool pooling across + the values in the same channel. This is equivalent to LpPool with kernel size + equal to the spatial dimension of input tensor. + +#### Version + +This version of the operator has been available since version 2 of the default ONNX operator set. + +Other versions of this operator: 1 + +#### Attributes + +
+
p : int (default is 2)
+
p value of the Lp norm used to pool over the input data.
+
+ +#### Inputs + +
+
X (differentiable) : T
+
Input data tensor from the previous operator; dimensions for image case are (N x C x H x W), where N is the batch size, C is the number of channels, and H and W are the height and the width of the data. For non image case, the dimensions are in the form of (N x C x D1 x D2 ... Dn), where N is the batch size.
+
+ +#### Outputs + +
+
Y (differentiable) : T
+
Output data tensor from pooling across the input tensor. The output tensor has the same rank as the input. The first two dimensions of output shape are the same as the input (N x C), while the other dimensions are all 1.
+
+ +#### Type Constraints + +
+
T : tensor(float16), tensor(float), tensor(double)
+
Constrain input and output types to float tensors.
+
+ + +### **GlobalMaxPool** + + GlobalMaxPool consumes an input tensor X and applies max pooling across + the values in the same channel. This is equivalent to MaxPool with kernel size + equal to the spatial dimension of input tensor. + +#### Version + +This version of the operator has been available since version 1 of the default ONNX operator set. + +#### Inputs + +
+
X (differentiable) : T
+
Input data tensor from the previous operator; dimensions for image case are (N x C x H x W), where N is the batch size, C is the number of channels, and H and W are the height and the width of the data. For non image case, the dimensions are in the form of (N x C x D1 x D2 ... Dn), where N is the batch size.
+
+ +#### Outputs + +
+
Y (differentiable) : T
+
Output data tensor from pooling across the input tensor. The output tensor has the same rank as the input. The first two dimensions of output shape are the same as the input (N x C), while the other dimensions are all 1.
+
+ +#### Type Constraints + +
+
T : tensor(float16), tensor(float), tensor(double)
+
Constrain input and output types to float tensors.
+
+ + +#### Examples + +
+globalmaxpool + +```python + +node = onnx.helper.make_node( + 'GlobalMaxPool', + inputs=['x'], + outputs=['y'], +) +x = np.random.randn(1, 3, 5, 5).astype(np.float32) +y = np.max(x, axis=tuple(range(2, np.ndim(x))), keepdims=True) +expect(node, inputs=[x], outputs=[y], name='test_globalmaxpool') +``` + +
+ + +
+globalmaxpool_precomputed + +```python + +node = onnx.helper.make_node( + 'GlobalMaxPool', + inputs=['x'], + outputs=['y'], +) +x = np.array([[[ + [1, 2, 3], + [4, 5, 6], + [7, 8, 9], +]]]).astype(np.float32) +y = np.array([[[[9]]]]).astype(np.float32) +expect(node, inputs=[x], outputs=[y], name='test_globalmaxpool_precomputed') +``` + +
+ + +### **Greater** + + Returns the tensor resulted from performing the `greater` logical operation + elementwise on the input tensors `A` and `B` (with Numpy-style broadcasting support). + + This operator supports **multidirectional (i.e., Numpy-style) broadcasting**; for more details please check [the doc](Broadcasting.md). + +#### Version + +This version of the operator has been available since version 13 of the default ONNX operator set. + +Other versions of this operator: 1, 7, 9 + +#### Inputs + +
+
A (non-differentiable) : T
+
First input operand for the logical operator.
+
B (non-differentiable) : T
+
Second input operand for the logical operator.
+
+ +#### Outputs + +
+
C (non-differentiable) : T1
+
Result tensor.
+
+ +#### Type Constraints + +
+
T : tensor(uint8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(int8), tensor(int16), tensor(int32), tensor(int64), tensor(float16), tensor(float), tensor(double), tensor(bfloat16)
+
Constrains input types to all numeric tensors.
+
T1 : tensor(bool)
+
Constrains output to boolean tensor.
+
+ + +#### Examples + +
+greater + +```python +node = onnx.helper.make_node( + 'Greater', + inputs=['x', 'y'], + outputs=['greater'], +) + +x = np.random.randn(3, 4, 5).astype(np.float32) +y = np.random.randn(3, 4, 5).astype(np.float32) +z = np.greater(x, y) +expect(node, inputs=[x, y], outputs=[z], + name='test_greater') +``` + +
+ + +
+greater + +```python +node = onnx.helper.make_node( + 'GreaterOrEqual', + inputs=['x', 'y'], + outputs=['greater_equal'], +) + +x = np.random.randn(3, 4, 5).astype(np.float32) +y = np.random.randn(3, 4, 5).astype(np.float32) +z = np.greater_equal(x, y) +expect(node, inputs=[x, y], outputs=[z], + name='test_greater_equal') +``` + +
+ + +
+greater_broadcast + +```python +node = onnx.helper.make_node( + 'Greater', + inputs=['x', 'y'], + outputs=['greater'], +) + +x = np.random.randn(3, 4, 5).astype(np.float32) +y = np.random.randn(5).astype(np.float32) +z = np.greater(x, y) +expect(node, inputs=[x, y], outputs=[z], + name='test_greater_bcast') +``` + +
+ + +
+greater_broadcast + +```python +node = onnx.helper.make_node( + 'GreaterOrEqual', + inputs=['x', 'y'], + outputs=['greater_equal'], +) + +x = np.random.randn(3, 4, 5).astype(np.float32) +y = np.random.randn(5).astype(np.float32) +z = np.greater_equal(x, y) +expect(node, inputs=[x, y], outputs=[z], + name='test_greater_equal_bcast') +``` + +
+ + +### **GreaterOrEqual** + + Returns the tensor resulted from performing the `greater_equal` logical operation + elementwise on the input tensors `A` and `B` (with Numpy-style broadcasting support). + + This operator supports **multidirectional (i.e., Numpy-style) broadcasting**; for more details please check [the doc](Broadcasting.md). + +#### Version + +This version of the operator has been available since version 12 of the default ONNX operator set. + +#### Inputs + +
+
A (non-differentiable) : T
+
First input operand for the logical operator.
+
B (non-differentiable) : T
+
Second input operand for the logical operator.
+
+ +#### Outputs + +
+
C (non-differentiable) : T1
+
Result tensor.
+
+ +#### Type Constraints + +
+
T : tensor(uint8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(int8), tensor(int16), tensor(int32), tensor(int64), tensor(float16), tensor(float), tensor(double)
+
Constrains input types to all numeric tensors.
+
T1 : tensor(bool)
+
Constrains output to boolean tensor.
+
+ + +### **GridSample** + + Given an `input` and a flow-field `grid`, computes the `output` using `input` values and pixel locations from `grid`. + Currently, only spatial (4-D) inputs are supported. For `input` with shape (N, C, H, W) and `grid` with shape (N, H_out, W_out, 2), + the `output` will have shape (N, C, H_out, W_out). + For each output location `output[N, C, H_out, W_out]`, the size-2 vector `grid[N, H_out, W_out]` specifies `input` pixel locations `x` and `y`, + which are used to interpolate the output value `output[N, C, H_out, W_out]`. + + The GridSample operator is often used in doing grid generator and sampler in the [Spatial Transformer Networks](https://arxiv.org/abs/1506.02025). + See also in [torch.nn.functional.grid_sample](https://pytorch.org/docs/master/generated/torch.nn.functional.grid_sample.html#torch-nn-functional-grid-sample). + +#### Version + +This version of the operator has been available since version 16 of the default ONNX operator set. + +#### Attributes + +
+
align_corners : int (default is 0)
+
If align_corners=1, the extrema (-1 and 1) are considered as referring to the center points of the input's corner pixels. If align_corners=0, they are instead considered as referring to the corner points of the input's corner pixels, making the sampling more resolution agnostic.
+
mode : string (default is bilinear)
+
Three interpolation modes: bilinear (default), nearest and bicubic.
+
padding_mode : string (default is zeros)
+
Support padding modes for outside grid values: `zeros`(default), `border`, `reflection`. zeros: use 0 for out-of-bound grid locations, border: use border values for out-of-bound grid locations, reflection: use values at locations reflected by the border for out-of-bound grid locations. If index 0 represents the margin pixel, the reflected value at index -1 will be the same as the value at index 1. For location far away from the border, it will keep being reflected until becoming in bound. If pixel location x = -3.5 reflects by border -1 and becomes x' = 1.5, then reflects by border 1 and becomes x'' = 0.5.
+
+ +#### Inputs + +
+
X (differentiable) : T1
+
4-D tensor of shape (N, C, H, W), where N is the batch size, C is the numbers of channels, H and W are the height and width of the input data.
+
grid (non-differentiable) : T1
+
Input offset, 4-D tensor of shape (N, H_out, W_out, 2), where H_out and W_out are the height and width of grid and output, Grid specifies the sampling pixel locations normalized by the input spatial dimensions. Therefore, it should have most values in the range of [-1, 1]. If grid has values outside the range of [-1, 1], the corresponding outputs will be handled as defined by padding_mode.
+
+ +#### Outputs + +
+
Y (differentiable) : T2
+
4-D tensor of shape (N, C, H_out, W_out).
+
+ +#### Type Constraints + +
+
T1 : tensor(uint8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(int8), tensor(int16), tensor(int32), tensor(int64), tensor(float16), tensor(float), tensor(double), tensor(string), tensor(bool), tensor(complex64), tensor(complex128)
+
Constrain input types to all tensor types.
+
T2 : tensor(float16), tensor(float), tensor(double)
+
Constrain output types to float tensors.
+
+ + +#### Examples + +
+gridsample + +```python +node = onnx.helper.make_node( + 'GridSample', + inputs=['X', 'Grid'], + outputs=['Y'], + mode='bilinear', + padding_mode='zeros', + align_corners=0, +) +# X shape, [N, C, H, W] - [1, 1, 4, 4] +X = np.array( + [ + [ + [ + [0., 1., 2., 3.], + [4., 5., 6., 7.], + [8., 9., 10., 11.], + [12., 13., 14., 15.] + ] + ] + ], + dtype=np.float32, +) +# Grid shape, [N, H_out, W_out, 2] - [1, 6, 6, 2] +Grid = np.array( + [ + [ + [ + [-1.0000, -1.0000], + [-0.6000, -1.0000], + [-0.2000, -1.0000], + [0.2000, -1.0000], + [0.6000, -1.0000], + [1.0000, -1.0000] + ], + [ + [-1.0000, -0.6000], + [-0.6000, -0.6000], + [-0.2000, -0.6000], + [0.2000, -0.6000], + [0.6000, -0.6000], + [1.0000, -0.6000] + ], + [ + [-1.0000, -0.2000], + [-0.6000, -0.2000], + [-0.2000, -0.2000], + [0.2000, -0.2000], + [0.6000, -0.2000], + [1.0000, -0.2000] + ], + [ + [-1.0000, 0.2000], + [-0.6000, 0.2000], + [-0.2000, 0.2000], + [0.2000, 0.2000], + [0.6000, 0.2000], + [1.0000, 0.2000] + ], + [ + [-1.0000, 0.6000], + [-0.6000, 0.6000], + [-0.2000, 0.6000], + [0.2000, 0.6000], + [0.6000, 0.6000], + [1.0000, 0.6000] + ], + [ + [-1.0000, 1.0000], + [-0.6000, 1.0000], + [-0.2000, 1.0000], + [0.2000, 1.0000], + [0.6000, 1.0000], + [1.0000, 1.0000] + ] + ] + ], + dtype=np.float32, +) +# Y shape, [N, C, H_out, W_out] - [1, 1, 6, 6] +Y = np.array( + [ + [ + [ + [0.0000, 0.1500, 0.5500, 0.9500, 1.3500, 0.7500], + [0.6000, 1.5000, 2.3000, 3.1000, 3.9000, 2.1000], + [2.2000, 4.7000, 5.5000, 6.3000, 7.1000, 3.7000], + [3.8000, 7.9000, 8.7000, 9.5000, 10.3000, 5.3000], + [5.4000, 11.1000, 11.9000, 12.7000, 13.5000, 6.9000], + [3.0000, 6.1500, 6.5500, 6.9500, 7.3500, 3.7500] + ] + ] + ], + dtype=np.float32, +) +expect(node, inputs=[X, Grid], outputs=[Y], + name='test_gridsample') +``` + +
+ + +
+gridsample_mode_aligncorners + +```python +# X shape, [N, C, H, W] - [1, 1, 3, 2] +X = np.array( + [ + [ + [ + [0., 1.], + [2., 3.], + [4., 5.] + ] + ] + ], + dtype=np.float32, +) +# Grid shape, [N, H_out, W_out, 2] - [1, 2, 4, 2] +Grid = np.array( + [ + [ + [ + [-1.0000, -1.0000], + [-0.5000, -0.5000], + [-0.2000, -0.2000], + [0.0000, 0.0000] + ], + + [ + [0.0000, 0.0000], + [-0.2000, -0.2000], + [0.5000, 0.5000], + [1.0000, 1.0000] + ] + ] + ], + dtype=np.float32, +) + +# setting mode = 'bilinear', default align_corners = 0 +node = onnx.helper.make_node( + 'GridSample', + inputs=['X', 'Grid'], + outputs=['Y'], + mode='bilinear', +) +# Y shape, [N, C, H_out, W_out] - [1, 1, 2, 4] +Y_bilinear = np.array( + [ + [ + [ + [0.0000, 0.5000, 1.7000, 2.5000], + [2.5000, 1.7000, 4.5000, 1.2500] + ] + ] + ], + dtype=np.float32, +) + +expect(node, inputs=[X, Grid], outputs=[Y_bilinear], + name='test_gridsample_bilinear') + +# setting mode = 'bilinear', align_corners = 1 +node = onnx.helper.make_node( + 'GridSample', + inputs=['X', 'Grid'], + outputs=['Y'], + mode='bilinear', + align_corners=1, +) +# Y shape, [N, C, H_out, W_out] - [1, 1, 2, 4] +Y_align_corners = np.array( + [ + [ + [ + [0.0000, 1.2500, 2.0000, 2.5000], + [2.5000, 2.0000, 3.7500, 5.0000] + ] + ] + ], + dtype=np.float32, +) + +expect(node, inputs=[X, Grid], outputs=[Y_align_corners], + name='test_gridsample_aligncorners_true') + +# setting mode = 'nearest' +node = onnx.helper.make_node( + 'GridSample', + inputs=['X', 'Grid'], + outputs=['Y'], + mode='nearest', +) +# Y shape, [N, C, H_out, W_out] - [1, 1, 2, 4] +Y_nearest = np.array( + [ + [ + [ + [0., 0., 2., 2.], + [2., 2., 5., 0.] + ] + ] + ], + dtype=np.float32, +) + +expect(node, inputs=[X, Grid], outputs=[Y_nearest], + name='test_gridsample_nearest') + +# setting mode = 'bicubic' +node = onnx.helper.make_node( + 'GridSample', + inputs=['X', 'Grid'], + outputs=['Y'], + mode='bicubic', +) +# Y shape, [N, C, H_out, W_out] - [1, 1, 2, 4] +Y_bicubic = np.array( + [ + [ + [ + [-0.1406, 0.3828, 1.7556, 2.9688], + [2.9688, 1.7556, 5.1445, 1.3906] + ] + ] + ], + dtype=np.float32, +) + +expect(node, inputs=[X, Grid], outputs=[Y_bicubic], + name='test_gridsample_bicubic') +``` + +
+ + +
+gridsample_paddingmode + +```python +# X shape, [N, C, H, W] - [1, 1, 3, 2] +X = np.array( + [ + [ + [ + [0., 1.], + [2., 3.], + [4., 5.] + ] + ] + ], + dtype=np.float32, +) +# Grid shape, [N, H_out, W_out, 2] - [1, 2, 4, 2] +Grid = np.array( + [ + [ + [ + [-10.0000, -10.0000], + [-5.0000, -5.0000], + [-0.2000, -0.2000], + [10.0000, 10.0000] + ], + + [ + [10.0000, 10.0000], + [-0.2000, -0.2000], + [5.0000, 5.0000], + [10.0000, 10.0000] + ] + ] + ], + dtype=np.float32, +) + +# setting padding_mode = 'zeros' +node = onnx.helper.make_node( + 'GridSample', + inputs=['X', 'Grid'], + outputs=['Y'], + padding_mode='zeros', +) +# Y shape, [N, C, H_out, W_out] - [1, 1, 2, 4] +Y_zeros = np.array( + [ + [ + [ + [0.0000, 0.0000, 1.7000, 0.0000], + [0.0000, 1.7000, 0.0000, 0.0000] + ] + ] + ], + dtype=np.float32, +) + +expect(node, inputs=[X, Grid], outputs=[Y_zeros], + name='test_gridsample_zeros_padding') + +# setting padding_mode = 'border' +node = onnx.helper.make_node( + 'GridSample', + inputs=['X', 'Grid'], + outputs=['Y'], + padding_mode='border', +) +# Y shape, [N, C, H_out, W_out] - [1, 1, 2, 4] +Y_border = np.array( + [ + [ + [ + [0.0000, 0.0000, 1.7000, 5.0000], + [5.0000, 1.7000, 5.0000, 5.0000] + ] + ] + ], + dtype=np.float32, +) + +expect(node, inputs=[X, Grid], outputs=[Y_border], + name='test_gridsample_border_padding') + +# setting padding_mode = 'reflection' +node = onnx.helper.make_node( + 'GridSample', + inputs=['X', 'Grid'], + outputs=['Y'], + padding_mode='reflection', +) +# Y shape, [N, C, H_out, W_out] - [1, 1, 2, 4] +Y_reflection = np.array( + [ + [ + [ + [2.5000, 0.0000, 1.7000, 2.5000], + [2.5000, 1.7000, 5.0000, 2.5000] + ] + ] + ], + dtype=np.float32, +) + +expect(node, inputs=[X, Grid], outputs=[Y_reflection], + name='test_gridsample_reflection_padding') +``` + +
+ + +### **HardSigmoid** + + HardSigmoid takes one input data (Tensor) and produces one output data + (Tensor) where the HardSigmoid function, y = max(0, min(1, alpha * x + beta)), + is applied to the tensor elementwise. + +#### Version + +This version of the operator has been available since version 6 of the default ONNX operator set. + +Other versions of this operator: 1 + +#### Attributes + +
+
alpha : float (default is 0.2)
+
Value of alpha.
+
beta : float (default is 0.5)
+
Value of beta.
+
+ +#### Inputs + +
+
X (differentiable) : T
+
Input tensor
+
+ +#### Outputs + +
+
Y (differentiable) : T
+
Output tensor
+
+ +#### Type Constraints + +
+
T : tensor(float16), tensor(float), tensor(double)
+
Constrain input and output types to float tensors.
+
+ + +#### Examples + +
+hardsigmoid + +```python +node = onnx.helper.make_node( + 'HardSigmoid', + inputs=['x'], + outputs=['y'], + alpha=0.5, + beta=0.6 +) + +x = np.array([-1, 0, 1]).astype(np.float32) +y = np.clip(x * 0.5 + 0.6, 0, 1) # expected output [0.1, 0.6, 1.] +expect(node, inputs=[x], outputs=[y], + name='test_hardsigmoid_example') + +x = np.random.randn(3, 4, 5).astype(np.float32) +y = np.clip(x * 0.5 + 0.6, 0, 1) +expect(node, inputs=[x], outputs=[y], + name='test_hardsigmoid') +``` + +
+ + +
+hardsigmoid_default + +```python +default_alpha = 0.2 +default_beta = 0.5 +node = onnx.helper.make_node( + 'HardSigmoid', + inputs=['x'], + outputs=['y'], +) +x = np.random.randn(3, 4, 5).astype(np.float32) +y = np.clip(x * default_alpha + default_beta, 0, 1) +expect(node, inputs=[x], outputs=[y], + name='test_hardsigmoid_default') +``` + +
+ + +### **HardSwish** + + HardSwish takes one input data (Tensor) and produces one output data (Tensor) where + the HardSwish function, y = x * max(0, min(1, alpha * x + beta)) = x * HardSigmoid(x), + where alpha = 1/6 and beta = 0.5, is applied to the tensor elementwise. + +#### Version + +This version of the operator has been available since version 14 of the default ONNX operator set. + +#### Inputs + +
+
X (differentiable) : T
+
Input tensor
+
+ +#### Outputs + +
+
Y (differentiable) : T
+
Output tensor
+
+ +#### Type Constraints + +
+
T : tensor(float16), tensor(float), tensor(double)
+
Constrain input and output types to float tensors.
+
+ + +#### Examples + +
+hardswish + +```python +node = onnx.helper.make_node( + 'HardSwish', + inputs=['x'], + outputs=['y'], +) +x = np.random.randn(3, 4, 5).astype(np.float32) +y = hardswish(x) + +expect(node, inputs=[x], outputs=[y], + name='test_hardswish') +``` + +
+ + +### **Hardmax** + + The operator computes the hardmax values for the given input: + + Hardmax(element in input, axis) = 1 if the element is the first maximum value along the specified axis, 0 otherwise + + The "axis" attribute indicates the dimension along which Hardmax + will be performed. The output tensor has the same shape + and contains the Hardmax values of the corresponding input. + +#### Version + +This version of the operator has been available since version 13 of the default ONNX operator set. + +Other versions of this operator: 1, 11 + +#### Attributes + +
+
axis : int (default is -1)
+
+Describes the dimension Hardmax will be performed on. +Negative value means counting dimensions +from the back. Accepted range is [-r, r-1] where r = rank(input). +
+
+ +#### Inputs + +
+
input (differentiable) : T
+
The input tensor of rank >= axis.
+
+ +#### Outputs + +
+
output (differentiable) : T
+
The output values with the same shape as the input tensor.
+
+ +#### Type Constraints + +
+
T : tensor(float16), tensor(float), tensor(double), tensor(bfloat16)
+
Constrain input and output types to float tensors.
+
+ + +#### Examples + +
+hardmax + +```python +node = onnx.helper.make_node( + 'Hardmax', + inputs=['x'], + outputs=['y'], +) + +x = np.array([[3, 0, 1, 2], [2, 5, 1, 0], [0, 1, 3, 2], + [0, 1, 2, 3]]).astype(np.float32) +# expect result: +# [[1. 0. 0. 0.] +# [0. 1. 0. 0.] +# [0. 0. 1. 0.] +# [0. 0. 0. 1.]] +y = hardmax(x) +expect(node, inputs=[x], outputs=[y], + name='test_hardmax_example') + +# For multiple occurrences of the maximal values, the first occurrence is selected for one-hot output +x = np.array([[3, 3, 3, 1]]).astype(np.float32) +# expect result: +# [[1, 0, 0, 0]] +y = hardmax(x) +expect(node, inputs=[x], outputs=[y], + name='test_hardmax_one_hot') +``` + +
+ + +
+hardmax_axis + +```python +x = np.random.randn(3, 4, 5).astype(np.float32) +node = onnx.helper.make_node( + 'Hardmax', + inputs=['x'], + outputs=['y'], + axis=0, +) +y = hardmax(x, axis=0) +expect(node, inputs=[x], outputs=[y], + name='test_hardmax_axis_0') + +node = onnx.helper.make_node( + 'Hardmax', + inputs=['x'], + outputs=['y'], + axis=1, +) +y = hardmax(x, axis=1) +expect(node, inputs=[x], outputs=[y], + name='test_hardmax_axis_1') + +node = onnx.helper.make_node( + 'Hardmax', + inputs=['x'], + outputs=['y'], + axis=2, +) +y = hardmax(x, axis=2) +expect(node, inputs=[x], outputs=[y], + name='test_hardmax_axis_2') + +node = onnx.helper.make_node( + 'Hardmax', + inputs=['x'], + outputs=['y'], + axis=-1, +) +y = hardmax(x, axis=-1) +expect(node, inputs=[x], outputs=[y], + name='test_hardmax_negative_axis') + +# default axis is -1 +node = onnx.helper.make_node( + 'Hardmax', + inputs=['x'], + outputs=['y'], +) +expect(node, inputs=[x], outputs=[y], + name='test_hardmax_default_axis') +``` + +
+ + +### **Identity** + + Identity operator + +#### Version + +This version of the operator has been available since version 16 of the default ONNX operator set. + +Other versions of this operator: 1, 13, 14 + +#### Inputs + +
+
input (differentiable) : V
+
Input tensor
+
+ +#### Outputs + +
+
output (differentiable) : V
+
Tensor to copy input into.
+
+ +#### Type Constraints + +
+
V : tensor(uint8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(int8), tensor(int16), tensor(int32), tensor(int64), tensor(bfloat16), tensor(float16), tensor(float), tensor(double), tensor(string), tensor(bool), tensor(complex64), tensor(complex128), seq(tensor(uint8)), seq(tensor(uint16)), seq(tensor(uint32)), seq(tensor(uint64)), seq(tensor(int8)), seq(tensor(int16)), seq(tensor(int32)), seq(tensor(int64)), seq(tensor(float16)), seq(tensor(float)), seq(tensor(double)), seq(tensor(string)), seq(tensor(bool)), seq(tensor(complex64)), seq(tensor(complex128)), optional(seq(tensor(uint8))), optional(seq(tensor(uint16))), optional(seq(tensor(uint32))), optional(seq(tensor(uint64))), optional(seq(tensor(int8))), optional(seq(tensor(int16))), optional(seq(tensor(int32))), optional(seq(tensor(int64))), optional(seq(tensor(float16))), optional(seq(tensor(float))), optional(seq(tensor(double))), optional(seq(tensor(string))), optional(seq(tensor(bool))), optional(seq(tensor(complex64))), optional(seq(tensor(complex128))), optional(tensor(uint8)), optional(tensor(uint16)), optional(tensor(uint32)), optional(tensor(uint64)), optional(tensor(int8)), optional(tensor(int16)), optional(tensor(int32)), optional(tensor(int64)), optional(tensor(float16)), optional(tensor(float)), optional(tensor(double)), optional(tensor(string)), optional(tensor(bool)), optional(tensor(complex64)), optional(tensor(complex128))
+
Constrain input and output types to all tensor, sequence, and optional types.
+
+ + +#### Examples + +
+identity + +```python +node = onnx.helper.make_node( + 'Identity', + inputs=['x'], + outputs=['y'], +) + +data = np.array([[[ + [1, 2], + [3, 4], +]]], dtype=np.float32) + +expect(node, inputs=[data], outputs=[data], + name='test_identity') +``` + +
+ + +
+identity_opt + +```python +ten_in_tp = onnx.helper.make_tensor_type_proto(onnx.TensorProto.FLOAT, shape=[5]) +seq_in_tp = onnx.helper.make_sequence_type_proto(ten_in_tp) +opt_in_tp = onnx.helper.make_optional_type_proto(seq_in_tp) + +identity_node = onnx.helper.make_node( + 'Identity', + inputs=['opt_in'], + outputs=['opt_out'] +) + +x = [np.array([1, 2, 3, 4, 5]).astype(np.float32)] + +expect(identity_node, inputs=[x], outputs=[x], name='test_identity_opt', + opset_imports=[onnx.helper.make_opsetid("", 16)], + input_type_protos=[opt_in_tp], + output_type_protos=[opt_in_tp]) +``` + +
+ + +
+sequence + +```python +node = onnx.helper.make_node( + 'Identity', + inputs=['x'], + outputs=['y'], +) + +data = [ + np.array([[[ + [1, 2], + [3, 4], + ]]], dtype=np.float32), + np.array([[[ + [2, 3], + [1, 5], + ]]], dtype=np.float32)] + +expect(node, inputs=[data], outputs=[data], name='test_identity_sequence') +``` + +
+ + +### **If** + + If conditional + +#### Version + +This version of the operator has been available since version 16 of the default ONNX operator set. + +Other versions of this operator: 1, 11, 13 + +#### Attributes + +
+
else_branch : graph (required)
+
Graph to run if condition is false. Has N outputs: values you wish to be live-out to the enclosing scope. The number of outputs must match the number of outputs in the then_branch.
+
then_branch : graph (required)
+
Graph to run if condition is true. Has N outputs: values you wish to be live-out to the enclosing scope. The number of outputs must match the number of outputs in the else_branch.
+
+ +#### Inputs + +
+
cond : B
+
Condition for the if
+
+ +#### Outputs (1 - ∞) + +
+
outputs (variadic, heterogeneous) : V
+
Values that are live-out to the enclosing scope. The return values in the `then_branch` and `else_branch` must be of the same data type. The `then_branch` and `else_branch` may produce tensors with the same element type and different shapes. If corresponding outputs from the then-branch and the else-branch have static shapes S1 and S2, then the shape of the corresponding output variable of the if-node (if present) must be compatible with both S1 and S2 as it represents the union of both possible shapes.For example, if in a model file, the the first output of `then_branch` is typed float tensor with shape [2] and the first output of `else_branch` is another float tensor with shape [3], If's first output should have (a) no shape set, or (b) a shape of rank 1 with neither `dim_value` nor `dim_param` set, or (c) a shape of rank 1 with a unique `dim_param`. In contrast, the first output cannot have the shape [2] since [2] and [3] are not compatible.
+
+ +#### Type Constraints + +
+
V : tensor(uint8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(int8), tensor(int16), tensor(int32), tensor(int64), tensor(float16), tensor(float), tensor(double), tensor(string), tensor(bool), tensor(complex64), tensor(complex128), seq(tensor(uint8)), seq(tensor(uint16)), seq(tensor(uint32)), seq(tensor(uint64)), seq(tensor(int8)), seq(tensor(int16)), seq(tensor(int32)), seq(tensor(int64)), seq(tensor(float16)), seq(tensor(float)), seq(tensor(double)), seq(tensor(string)), seq(tensor(bool)), seq(tensor(complex64)), seq(tensor(complex128)), optional(seq(tensor(uint8))), optional(seq(tensor(uint16))), optional(seq(tensor(uint32))), optional(seq(tensor(uint64))), optional(seq(tensor(int8))), optional(seq(tensor(int16))), optional(seq(tensor(int32))), optional(seq(tensor(int64))), optional(seq(tensor(float16))), optional(seq(tensor(float))), optional(seq(tensor(double))), optional(seq(tensor(string))), optional(seq(tensor(bool))), optional(seq(tensor(complex64))), optional(seq(tensor(complex128))), optional(tensor(uint8)), optional(tensor(uint16)), optional(tensor(uint32)), optional(tensor(uint64)), optional(tensor(int8)), optional(tensor(int16)), optional(tensor(int32)), optional(tensor(int64)), optional(tensor(float16)), optional(tensor(float)), optional(tensor(double)), optional(tensor(string)), optional(tensor(bool)), optional(tensor(complex64)), optional(tensor(complex128))
+
All Tensor, Sequence, and optional types
+
B : tensor(bool)
+
Only bool
+
+ + +#### Examples + +
+if + +```python +# Given a bool scalar input cond. +# return constant tensor x if cond is True, otherwise return constant tensor y. + +then_out = onnx.helper.make_tensor_value_info('then_out', onnx.TensorProto.FLOAT, [5]) +else_out = onnx.helper.make_tensor_value_info('else_out', onnx.TensorProto.FLOAT, [5]) + +x = np.array([1, 2, 3, 4, 5]).astype(np.float32) +y = np.array([5, 4, 3, 2, 1]).astype(np.float32) + +then_const_node = onnx.helper.make_node( + 'Constant', + inputs=[], + outputs=['then_out'], + value=onnx.numpy_helper.from_array(x) +) + +else_const_node = onnx.helper.make_node( + 'Constant', + inputs=[], + outputs=['else_out'], + value=onnx.numpy_helper.from_array(y) +) + +then_body = onnx.helper.make_graph( + [then_const_node], + 'then_body', + [], + [then_out] +) + +else_body = onnx.helper.make_graph( + [else_const_node], + 'else_body', + [], + [else_out] +) + +if_node = onnx.helper.make_node( + 'If', + inputs=['cond'], + outputs=['res'], + then_branch=then_body, + else_branch=else_body +) + +cond = np.array(1).astype(bool) +res = x if cond else y +expect(if_node, inputs=[cond], outputs=[res], name='test_if', + opset_imports=[onnx.helper.make_opsetid("", 11)]) +``` + +
+ + +
+if_optional + +```python +# Given a bool scalar input cond, return an empty optional sequence of +# tensor if True, return an optional sequence with value x +# (the input optional sequence) otherwise. + +ten_in_tp = onnx.helper.make_tensor_type_proto(onnx.TensorProto.FLOAT, shape=[5]) +seq_in_tp = onnx.helper.make_sequence_type_proto(ten_in_tp) + +then_out_tensor_tp = onnx.helper.make_tensor_type_proto(onnx.TensorProto.FLOAT, shape=[5]) +then_out_seq_tp = onnx.helper.make_sequence_type_proto(then_out_tensor_tp) +then_out_opt_tp = onnx.helper.make_optional_type_proto(then_out_seq_tp) +then_out = onnx.helper.make_value_info('optional_empty', then_out_opt_tp) + +else_out_tensor_tp = onnx.helper.make_tensor_type_proto(onnx.TensorProto.FLOAT, shape=[5]) +else_out_seq_tp = onnx.helper.make_sequence_type_proto(else_out_tensor_tp) +else_out_opt_tp = onnx.helper.make_optional_type_proto(else_out_seq_tp) +else_out = onnx.helper.make_value_info('else_opt', else_out_opt_tp) + +x = [np.array([1, 2, 3, 4, 5]).astype(np.float32)] +cond = np.array(0).astype(bool) +res = compute_if_outputs(x, cond) + +opt_empty_in = onnx.helper.make_node( + 'Optional', + inputs=[], + outputs=['optional_empty'], + type=seq_in_tp +) + +then_body = onnx.helper.make_graph( + [opt_empty_in], + 'then_body', + [], + [then_out] +) + +else_const_node = onnx.helper.make_node( + 'Constant', + inputs=[], + outputs=['x'], + value=onnx.numpy_helper.from_array(x[0]) +) + +else_seq_node = onnx.helper.make_node( + 'SequenceConstruct', + inputs=['x'], + outputs=['else_seq'] +) + +else_optional_seq_node = onnx.helper.make_node( + 'Optional', + inputs=['else_seq'], + outputs=['else_opt'] +) + +else_body = onnx.helper.make_graph( + [else_const_node, else_seq_node, else_optional_seq_node], + 'else_body', + [], + [else_out] +) + +if_node = onnx.helper.make_node( + 'If', + inputs=['cond'], + outputs=['sequence'], + then_branch=then_body, + else_branch=else_body +) + +expect(if_node, inputs=[cond], outputs=[res], name='test_if_opt', + output_type_protos=[else_out_opt_tp], + opset_imports=[onnx.helper.make_opsetid("", 16)]) +``` + +
+ + +
+if_seq + +```python +# Given a bool scalar input cond. +# return constant sequence x if cond is True, otherwise return constant sequence y. + +then_out = onnx.helper.make_tensor_sequence_value_info('then_out', onnx.TensorProto.FLOAT, shape=[5]) +else_out = onnx.helper.make_tensor_sequence_value_info('else_out', onnx.TensorProto.FLOAT, shape=[5]) + +x = [np.array([1, 2, 3, 4, 5]).astype(np.float32)] +y = [np.array([5, 4, 3, 2, 1]).astype(np.float32)] + +then_const_node = onnx.helper.make_node( + 'Constant', + inputs=[], + outputs=['x'], + value=onnx.numpy_helper.from_array(x[0]) +) + +then_seq_node = onnx.helper.make_node( + 'SequenceConstruct', + inputs=['x'], + outputs=['then_out'] +) + +else_const_node = onnx.helper.make_node( + 'Constant', + inputs=[], + outputs=['y'], + value=onnx.numpy_helper.from_array(y[0]) +) + +else_seq_node = onnx.helper.make_node( + 'SequenceConstruct', + inputs=['y'], + outputs=['else_out'] +) + +then_body = onnx.helper.make_graph( + [then_const_node, then_seq_node], + 'then_body', + [], + [then_out] +) + +else_body = onnx.helper.make_graph( + [else_const_node, else_seq_node], + 'else_body', + [], + [else_out] +) + +if_node = onnx.helper.make_node( + 'If', + inputs=['cond'], + outputs=['res'], + then_branch=then_body, + else_branch=else_body +) + +cond = np.array(1).astype(bool) +res = x if cond else y +expect(if_node, inputs=[cond], outputs=[res], name='test_if_seq', + opset_imports=[onnx.helper.make_opsetid("", 13)]) +``` + +
+ + +### **InstanceNormalization** + + Carries out instance normalization as described in the paper + https://arxiv.org/abs/1607.08022. + + y = scale * (x - mean) / sqrt(variance + epsilon) + B, + where mean and variance are computed per instance per channel. + + +#### Version + +This version of the operator has been available since version 6 of the default ONNX operator set. + +Other versions of this operator: 1 + +#### Attributes + +
+
epsilon : float (default is 1e-05)
+
The epsilon value to use to avoid division by zero.
+
+ +#### Inputs + +
+
input (differentiable) : T
+
Input data tensor from the previous operator; dimensions for image case are (N x C x H x W), where N is the batch size, C is the number of channels, and H and W are the height and the width of the data. For non image case, the dimensions are in the form of (N x C x D1 x D2 ... Dn), where N is the batch size.
+
scale (differentiable) : T
+
The input 1-dimensional scale tensor of size C.
+
B (differentiable) : T
+
The input 1-dimensional bias tensor of size C.
+
+ +#### Outputs + +
+
output (differentiable) : T
+
The output tensor of the same shape as input.
+
+ +#### Type Constraints + +
+
T : tensor(float16), tensor(float), tensor(double)
+
Constrain input and output types to float tensors.
+
+ + +#### Examples + +
+instancenormalization + +```python +def _instancenorm_test_mode(x, s, bias, epsilon=1e-5): # type: ignore + dims_x = len(x.shape) + axis = tuple(range(2, dims_x)) + mean = np.mean(x, axis=axis, keepdims=True) + var = np.var(x, axis=axis, keepdims=True) + dim_ones = (1,) * (dims_x - 2) + s = s.reshape(-1, *dim_ones) + bias = bias.reshape(-1, *dim_ones) + return s * (x - mean) / np.sqrt(var + epsilon) + bias + +# input size: (1, 2, 1, 3) +x = np.array([[[[-1, 0, 1]], [[2, 3, 4]]]]).astype(np.float32) +s = np.array([1.0, 1.5]).astype(np.float32) +bias = np.array([0, 1]).astype(np.float32) +y = _instancenorm_test_mode(x, s, bias).astype(np.float32) + +node = onnx.helper.make_node( + 'InstanceNormalization', + inputs=['x', 's', 'bias'], + outputs=['y'], +) + +# output size: (1, 2, 1, 3) +expect(node, inputs=[x, s, bias], outputs=[y], + name='test_instancenorm_example') + +# input size: (2, 3, 4, 5) +x = np.random.randn(2, 3, 4, 5).astype(np.float32) +s = np.random.randn(3).astype(np.float32) +bias = np.random.randn(3).astype(np.float32) +epsilon = 1e-2 +y = _instancenorm_test_mode(x, s, bias, epsilon).astype(np.float32) + +node = onnx.helper.make_node( + 'InstanceNormalization', + inputs=['x', 's', 'bias'], + outputs=['y'], + epsilon=epsilon, +) + +# output size: (2, 3, 4, 5) +expect(node, inputs=[x, s, bias], outputs=[y], + name='test_instancenorm_epsilon') +``` + +
+ + +### **IsInf** + + Map infinity to true and other values to false. + +#### Version + +This version of the operator has been available since version 10 of the default ONNX operator set. + +#### Attributes + +
+
detect_negative : int (default is 1)
+
(Optional) Whether map negative infinity to true. Default to 1 so that negative infinity induces true. Set this attribute to 0 if negative infinity should be mapped to false.
+
detect_positive : int (default is 1)
+
(Optional) Whether map positive infinity to true. Default to 1 so that positive infinity induces true. Set this attribute to 0 if positive infinity should be mapped to false.
+
+ +#### Inputs + +
+
X (non-differentiable) : T1
+
input
+
+ +#### Outputs + +
+
Y (non-differentiable) : T2
+
output
+
+ +#### Type Constraints + +
+
T1 : tensor(float), tensor(double)
+
Constrain input types to float tensors.
+
T2 : tensor(bool)
+
Constrain output types to boolean tensors.
+
+ + +#### Examples + +
+infinity + +```python +node = onnx.helper.make_node('IsInf', + inputs=['x'], + outputs=['y'], + ) + +x = np.array([-1.2, np.nan, np.inf, 2.8, np.NINF, np.inf], + dtype=np.float32) +y = np.isinf(x) +expect(node, inputs=[x], outputs=[y], name='test_isinf') +``` + +
+ + +
+negative_infinity_only + +```python +node = onnx.helper.make_node('IsInf', + inputs=['x'], + outputs=['y'], + detect_positive=0 + ) + +x = np.array([-1.7, np.nan, np.inf, -3.6, np.NINF, np.inf], + dtype=np.float32) +y = np.isneginf(x) +expect(node, inputs=[x], outputs=[y], name='test_isinf_negative') +``` + +
+ + +
+positive_infinity_only + +```python +node = onnx.helper.make_node('IsInf', + inputs=['x'], + outputs=['y'], + detect_negative=0 + ) + +x = np.array([-1.7, np.nan, np.inf, 3.6, np.NINF, np.inf], + dtype=np.float32) +y = np.isposinf(x) +expect(node, inputs=[x], outputs=[y], name='test_isinf_positive') +``` + +
+ + +### **IsNaN** + + Returns which elements of the input are NaN. + +#### Version + +This version of the operator has been available since version 13 of the default ONNX operator set. + +Other versions of this operator: 9 + +#### Inputs + +
+
X (non-differentiable) : T1
+
input
+
+ +#### Outputs + +
+
Y (non-differentiable) : T2
+
output
+
+ +#### Type Constraints + +
+
T1 : tensor(float16), tensor(float), tensor(double), tensor(bfloat16)
+
Constrain input types to float tensors.
+
T2 : tensor(bool)
+
Constrain output types to boolean tensors.
+
+ + +#### Examples + +
+isnan + +```python +node = onnx.helper.make_node( + 'IsNaN', + inputs=['x'], + outputs=['y'], +) + +x = np.array([3.0, np.nan, 4.0, np.nan], dtype=np.float32) +y = np.isnan(x) +expect(node, inputs=[x], outputs=[y], name='test_isnan') +``` + +
+ + +### **LRN** + + Local Response Normalization proposed in the [AlexNet paper](https://papers.nips.cc/paper/4824-imagenet-classification-with-deep-convolutional-neural-networks.pdf). + It normalizes over local input regions. + The local region is defined across the channels. For an element X[n, c, d1, ..., dk] in a tensor + of shape (N x C x D1 x D2, ..., Dk), its region is + {X[n, i, d1, ..., dk] | max(0, c - floor((size - 1) / 2)) <= i <= min(C - 1, c + ceil((size - 1) / 2))}. + + square_sum[n, c, d1, ..., dk] = sum(X[n, i, d1, ..., dk] ^ 2), + where max(0, c - floor((size - 1) / 2)) <= i <= min(C - 1, c + ceil((size - 1) / 2)). + + Y[n, c, d1, ..., dk] = X[n, c, d1, ..., dk] / (bias + alpha / size * square_sum[n, c, d1, ..., dk] ) ^ beta + +#### Version + +This version of the operator has been available since version 13 of the default ONNX operator set. + +Other versions of this operator: 1 + +#### Attributes + +
+
alpha : float (default is 0.0001)
+
Scaling parameter.
+
beta : float (default is 0.75)
+
The exponent.
+
bias : float (default is 1.0)
+
+
size : int (required)
+
The number of channels to sum over
+
+ +#### Inputs + +
+
X (differentiable) : T
+
Input data tensor from the previous operator; dimensions for image case are (N x C x H x W), where N is the batch size, C is the number of channels, and H and W are the height and the width of the data. For non image case, the dimensions are in the form of (N x C x D1 x D2 ... Dn), where N is the batch size. Optionally, if dimension denotation is in effect, the operation expects the input data tensor to arrive with the dimension denotation of [DATA_BATCH, DATA_CHANNEL, DATA_FEATURE, DATA_FEATURE ...].
+
+ +#### Outputs + +
+
Y (differentiable) : T
+
Output tensor, which has the shape and type as input tensor
+
+ +#### Type Constraints + +
+
T : tensor(float16), tensor(float), tensor(double), tensor(bfloat16)
+
Constrain input and output types to float tensors.
+
+ + +#### Examples + +
+default + +```python +alpha = 0.0001 +beta = 0.75 +bias = 1.0 +nsize = 3 +node = onnx.helper.make_node( + 'LRN', + inputs=['x'], + outputs=['y'], + size=3 +) +x = np.random.randn(5, 5, 5, 5).astype(np.float32) +square_sum = np.zeros((5, 5, 5, 5)).astype(np.float32) +for n, c, h, w in np.ndindex(x.shape): + square_sum[n, c, h, w] = sum(x[n, + max(0, c - int(math.floor((nsize - 1) / 2))):min(5, c + int(math.ceil((nsize - 1) / 2)) + 1), + h, + w] ** 2) +y = x / ((bias + (alpha / nsize) * square_sum) ** beta) +expect(node, inputs=[x], outputs=[y], + name='test_lrn_default') +``` + +
+ + +
+lrn + +```python +alpha = 0.0002 +beta = 0.5 +bias = 2.0 +nsize = 3 +node = onnx.helper.make_node( + 'LRN', + inputs=['x'], + outputs=['y'], + alpha=alpha, + beta=beta, + bias=bias, + size=nsize +) +x = np.random.randn(5, 5, 5, 5).astype(np.float32) +square_sum = np.zeros((5, 5, 5, 5)).astype(np.float32) +for n, c, h, w in np.ndindex(x.shape): + square_sum[n, c, h, w] = sum(x[n, + max(0, c - int(math.floor((nsize - 1) / 2))):min(5, c + int(math.ceil((nsize - 1) / 2)) + 1), + h, + w] ** 2) +y = x / ((bias + (alpha / nsize) * square_sum) ** beta) +expect(node, inputs=[x], outputs=[y], + name='test_lrn') +``` + +
+ + +### **LSTM** + + Computes an one-layer LSTM. This operator is usually supported via some + custom implementation such as CuDNN. + + Notations: + + `X` - input tensor + + `i` - input gate + + `o` - output gate + + `f` - forget gate + + `c` - cell gate + + `t` - time step (t-1 means previous time step) + + `W[iofc]` - W parameter weight matrix for input, output, forget, and cell gates + + `R[iofc]` - R recurrence weight matrix for input, output, forget, and cell gates + + `Wb[iofc]` - W bias vectors for input, output, forget, and cell gates + + `Rb[iofc]` - R bias vectors for input, output, forget, and cell gates + + `P[iof]` - P peephole weight vector for input, output, and forget gates + + `WB[iofc]` - W parameter weight matrix for backward input, output, forget, and cell gates + + `RB[iofc]` - R recurrence weight matrix for backward input, output, forget, and cell gates + + `WBb[iofc]` - W bias vectors for backward input, output, forget, and cell gates + + `RBb[iofc]` - R bias vectors for backward input, output, forget, and cell gates + + `PB[iof]` - P peephole weight vector for backward input, output, and forget gates + + `H` - Hidden state + + `num_directions` - 2 if direction == bidirectional else 1 + + Activation functions: + + Relu(x) - max(0, x) + + Tanh(x) - (1 - e^{-2x})/(1 + e^{-2x}) + + Sigmoid(x) - 1/(1 + e^{-x}) + + (NOTE: Below are optional) + + Affine(x) - alpha*x + beta + + LeakyRelu(x) - x if x >= 0 else alpha * x + + ThresholdedRelu(x) - x if x >= alpha else 0 + + ScaledTanh(x) - alpha*Tanh(beta*x) + + HardSigmoid(x) - min(max(alpha*x + beta, 0), 1) + + Elu(x) - x if x >= 0 else alpha*(e^x - 1) + + Softsign(x) - x/(1 + |x|) + + Softplus(x) - log(1 + e^x) + + Equations (Default: f=Sigmoid, g=Tanh, h=Tanh): + + - it = f(Xt*(Wi^T) + Ht-1*(Ri^T) + Pi (.) Ct-1 + Wbi + Rbi) + + - ft = f(Xt*(Wf^T) + Ht-1*(Rf^T) + Pf (.) Ct-1 + Wbf + Rbf) + + - ct = g(Xt*(Wc^T) + Ht-1*(Rc^T) + Wbc + Rbc) + + - Ct = ft (.) Ct-1 + it (.) ct + + - ot = f(Xt*(Wo^T) + Ht-1*(Ro^T) + Po (.) Ct + Wbo + Rbo) + + - Ht = ot (.) h(Ct) + This operator has **optional** inputs/outputs. See [the doc](IR.md) for more details about the representation of optional arguments. An empty string may be used in the place of an actual argument's name to indicate a missing argument. Trailing optional arguments (those not followed by an argument that is present) may also be simply omitted. + +#### Version + +This version of the operator has been available since version 14 of the default ONNX operator set. + +Other versions of this operator: 1, 7 + +#### Attributes + +
+
activation_alpha : list of floats
+
Optional scaling values used by some activation functions. The values are consumed in the order of activation functions, for example (f, g, h) in LSTM. Default values are the same as of corresponding ONNX operators.For example with LeakyRelu, the default alpha is 0.01.
+
activation_beta : list of floats
+
Optional scaling values used by some activation functions. The values are consumed in the order of activation functions, for example (f, g, h) in LSTM. Default values are the same as of corresponding ONNX operators.
+
activations : list of strings
+
A list of 3 (or 6 if bidirectional) activation functions for input, output, forget, cell, and hidden. The activation functions must be one of the activation functions specified above. Optional: See the equations for default if not specified.
+
clip : float
+
Cell clip threshold. Clipping bounds the elements of a tensor in the range of [-threshold, +threshold] and is applied to the input of activations. No clip if not specified.
+
direction : string (default is forward)
+
Specify if the RNN is forward, reverse, or bidirectional. Must be one of forward (default), reverse, or bidirectional.
+
hidden_size : int
+
Number of neurons in the hidden layer
+
input_forget : int (default is 0)
+
Couple the input and forget gates if 1.
+
layout : int (default is 0)
+
The shape format of inputs X, initial_h, initial_c and outputs Y, Y_h, Y_c. If 0, the following shapes are expected: X.shape = [seq_length, batch_size, input_size], Y.shape = [seq_length, num_directions, batch_size, hidden_size], initial_h.shape = Y_h.shape = initial_c.shape = Y_c.shape = [num_directions, batch_size, hidden_size]. If 1, the following shapes are expected: X.shape = [batch_size, seq_length, input_size], Y.shape = [batch_size, seq_length, num_directions, hidden_size], initial_h.shape = Y_h.shape = initial_c.shape = Y_c.shape = [batch_size, num_directions, hidden_size].
+
+ +#### Inputs (3 - 8) + +
+
X (differentiable) : T
+
The input sequences packed (and potentially padded) into one 3-D tensor with the shape of `[seq_length, batch_size, input_size]`.
+
W (differentiable) : T
+
The weight tensor for the gates. Concatenation of `W[iofc]` and `WB[iofc]` (if bidirectional) along dimension 0. The tensor has shape `[num_directions, 4*hidden_size, input_size]`.
+
R (differentiable) : T
+
The recurrence weight tensor. Concatenation of `R[iofc]` and `RB[iofc]` (if bidirectional) along dimension 0. This tensor has shape `[num_directions, 4*hidden_size, hidden_size]`.
+
B (optional, differentiable) : T
+
The bias tensor for input gate. Concatenation of `[Wb[iofc], Rb[iofc]]`, and `[WBb[iofc], RBb[iofc]]` (if bidirectional) along dimension 0. This tensor has shape `[num_directions, 8*hidden_size]`. Optional: If not specified - assumed to be 0.
+
sequence_lens (optional, non-differentiable) : T1
+
Optional tensor specifying lengths of the sequences in a batch. If not specified - assumed all sequences in the batch to have length `seq_length`. It has shape `[batch_size]`.
+
initial_h (optional, non-differentiable) : T
+
Optional initial value of the hidden. If not specified - assumed to be 0. It has shape `[num_directions, batch_size, hidden_size]`.
+
initial_c (optional, non-differentiable) : T
+
Optional initial value of the cell. If not specified - assumed to be 0. It has shape `[num_directions, batch_size, hidden_size]`.
+
P (optional, differentiable) : T
+
The weight tensor for peepholes. Concatenation of `P[iof]` and `PB[iof]` (if bidirectional) along dimension 0. It has shape `[num_directions, 3*hidde_size]`. Optional: If not specified - assumed to be 0.
+
+ +#### Outputs (0 - 3) + +
+
Y (optional, differentiable) : T
+
A tensor that concats all the intermediate output values of the hidden. It has shape `[seq_length, num_directions, batch_size, hidden_size]`.
+
Y_h (optional, differentiable) : T
+
The last output value of the hidden. It has shape `[num_directions, batch_size, hidden_size]`.
+
Y_c (optional, differentiable) : T
+
The last output value of the cell. It has shape `[num_directions, batch_size, hidden_size]`.
+
+ +#### Type Constraints + +
+
T : tensor(float16), tensor(float), tensor(double)
+
Constrain input and output types to float tensors.
+
T1 : tensor(int32)
+
Constrain seq_lens to integer tensor.
+
+ + +#### Examples + +
+batchwise + +```python +input = np.array([[[1., 2.]], [[3., 4.]], [[5., 6.]]]).astype(np.float32) + +input_size = 2 +hidden_size = 7 +weight_scale = 0.3 +number_of_gates = 4 +layout = 1 + +node = onnx.helper.make_node( + 'LSTM', + inputs=['X', 'W', 'R'], + outputs=['Y', 'Y_h'], + hidden_size=hidden_size, + layout=layout +) + +W = weight_scale * np.ones((1, number_of_gates * hidden_size, input_size)).astype(np.float32) +R = weight_scale * np.ones((1, number_of_gates * hidden_size, hidden_size)).astype(np.float32) + +lstm = LSTM_Helper(X=input, W=W, R=R, layout=layout) +Y, Y_h = lstm.step() +expect(node, inputs=[input, W, R], outputs=[Y.astype(np.float32), Y_h.astype(np.float32)], name='test_lstm_batchwise') +``` + +
+ + +
+defaults + +```python +input = np.array([[[1., 2.], [3., 4.], [5., 6.]]]).astype(np.float32) + +input_size = 2 +hidden_size = 3 +weight_scale = 0.1 +number_of_gates = 4 + +node = onnx.helper.make_node( + 'LSTM', + inputs=['X', 'W', 'R'], + outputs=['', 'Y_h'], + hidden_size=hidden_size +) + +W = weight_scale * np.ones((1, number_of_gates * hidden_size, input_size)).astype(np.float32) +R = weight_scale * np.ones((1, number_of_gates * hidden_size, hidden_size)).astype(np.float32) + +lstm = LSTM_Helper(X=input, W=W, R=R) +_, Y_h = lstm.step() +expect(node, inputs=[input, W, R], outputs=[Y_h.astype(np.float32)], name='test_lstm_defaults') +``` + +
+ + +
+initial_bias + +```python +input = np.array([[[1., 2., 3.], [4., 5., 6.], [7., 8., 9.]]]).astype(np.float32) + +input_size = 3 +hidden_size = 4 +weight_scale = 0.1 +custom_bias = 0.1 +number_of_gates = 4 + +node = onnx.helper.make_node( + 'LSTM', + inputs=['X', 'W', 'R', 'B'], + outputs=['', 'Y_h'], + hidden_size=hidden_size +) + +W = weight_scale * np.ones((1, number_of_gates * hidden_size, input_size)).astype(np.float32) +R = weight_scale * np.ones((1, number_of_gates * hidden_size, hidden_size)).astype(np.float32) + +# Adding custom bias +W_B = custom_bias * np.ones((1, number_of_gates * hidden_size)).astype(np.float32) +R_B = np.zeros((1, number_of_gates * hidden_size)).astype(np.float32) +B = np.concatenate((W_B, R_B), 1) + +lstm = LSTM_Helper(X=input, W=W, R=R, B=B) +_, Y_h = lstm.step() +expect(node, inputs=[input, W, R, B], outputs=[Y_h.astype(np.float32)], name='test_lstm_with_initial_bias') +``` + +
+ + +
+peepholes + +```python +input = np.array([[[1., 2., 3., 4.], [5., 6., 7., 8.]]]).astype(np.float32) + +input_size = 4 +hidden_size = 3 +weight_scale = 0.1 +number_of_gates = 4 +number_of_peepholes = 3 + +node = onnx.helper.make_node( + 'LSTM', + inputs=['X', 'W', 'R', 'B', 'sequence_lens', 'initial_h', 'initial_c', 'P'], + outputs=['', 'Y_h'], + hidden_size=hidden_size +) + +# Initializing Inputs +W = weight_scale * np.ones((1, number_of_gates * hidden_size, input_size)).astype(np.float32) +R = weight_scale * np.ones((1, number_of_gates * hidden_size, hidden_size)).astype(np.float32) +B = np.zeros((1, 2 * number_of_gates * hidden_size)).astype(np.float32) +seq_lens = np.repeat(input.shape[0], input.shape[1]).astype(np.int32) +init_h = np.zeros((1, input.shape[1], hidden_size)).astype(np.float32) +init_c = np.zeros((1, input.shape[1], hidden_size)).astype(np.float32) +P = weight_scale * np.ones((1, number_of_peepholes * hidden_size)).astype(np.float32) + +lstm = LSTM_Helper(X=input, W=W, R=R, B=B, P=P, initial_c=init_c, initial_h=init_h) +_, Y_h = lstm.step() +expect(node, inputs=[input, W, R, B, seq_lens, init_h, init_c, P], outputs=[Y_h.astype(np.float32)], + name='test_lstm_with_peepholes') +``` + +
+ + +### **LeakyRelu** + + LeakyRelu takes input data (Tensor) and an argument alpha, and produces one + output data (Tensor) where the function `f(x) = alpha * x for x < 0`, + `f(x) = x for x >= 0`, is applied to the data tensor elementwise. + +#### Version + +This version of the operator has been available since version 6 of the default ONNX operator set. + +Other versions of this operator: 1 + +#### Attributes + +
+
alpha : float (default is 0.01)
+
Coefficient of leakage.
+
+ +#### Inputs + +
+
X (differentiable) : T
+
Input tensor
+
+ +#### Outputs + +
+
Y (differentiable) : T
+
Output tensor
+
+ +#### Type Constraints + +
+
T : tensor(float16), tensor(float), tensor(double)
+
Constrain input and output types to float tensors.
+
+ + +#### Examples + +
+leakyrelu + +```python +node = onnx.helper.make_node( + 'LeakyRelu', + inputs=['x'], + outputs=['y'], + alpha=0.1 +) + +x = np.array([-1, 0, 1]).astype(np.float32) +# expected output [-0.1, 0., 1.] +y = np.clip(x, 0, np.inf) + np.clip(x, -np.inf, 0) * 0.1 +expect(node, inputs=[x], outputs=[y], + name='test_leakyrelu_example') + +x = np.random.randn(3, 4, 5).astype(np.float32) +y = np.clip(x, 0, np.inf) + np.clip(x, -np.inf, 0) * 0.1 +expect(node, inputs=[x], outputs=[y], + name='test_leakyrelu') +``` + +
+ + +
+leakyrelu_default + +```python +default_alpha = 0.01 +node = onnx.helper.make_node( + 'LeakyRelu', + inputs=['x'], + outputs=['y'], +) +x = np.random.randn(3, 4, 5).astype(np.float32) +y = np.clip(x, 0, np.inf) + np.clip(x, -np.inf, 0) * default_alpha +expect(node, inputs=[x], outputs=[y], + name='test_leakyrelu_default') +``` + +
+ + +### **Less** + + Returns the tensor resulted from performing the `less` logical operation + elementwise on the input tensors `A` and `B` (with Numpy-style broadcasting support). + + This operator supports **multidirectional (i.e., Numpy-style) broadcasting**; for more details please check [the doc](Broadcasting.md). + +#### Version + +This version of the operator has been available since version 13 of the default ONNX operator set. + +Other versions of this operator: 1, 7, 9 + +#### Inputs + +
+
A (non-differentiable) : T
+
First input operand for the logical operator.
+
B (non-differentiable) : T
+
Second input operand for the logical operator.
+
+ +#### Outputs + +
+
C (non-differentiable) : T1
+
Result tensor.
+
+ +#### Type Constraints + +
+
T : tensor(uint8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(int8), tensor(int16), tensor(int32), tensor(int64), tensor(float16), tensor(float), tensor(double), tensor(bfloat16)
+
Constrains input types to all numeric tensors.
+
T1 : tensor(bool)
+
Constrains output to boolean tensor.
+
+ + +#### Examples + +
+less + +```python +node = onnx.helper.make_node( + 'Less', + inputs=['x', 'y'], + outputs=['less'], +) + +x = np.random.randn(3, 4, 5).astype(np.float32) +y = np.random.randn(3, 4, 5).astype(np.float32) +z = np.less(x, y) +expect(node, inputs=[x, y], outputs=[z], + name='test_less') +``` + +
+ + +
+less + +```python +node = onnx.helper.make_node( + 'LessOrEqual', + inputs=['x', 'y'], + outputs=['less_equal'], +) + +x = np.random.randn(3, 4, 5).astype(np.float32) +y = np.random.randn(3, 4, 5).astype(np.float32) +z = np.less_equal(x, y) +expect(node, inputs=[x, y], outputs=[z], + name='test_less_equal') +``` + +
+ + +
+less_broadcast + +```python +node = onnx.helper.make_node( + 'Less', + inputs=['x', 'y'], + outputs=['less'], +) + +x = np.random.randn(3, 4, 5).astype(np.float32) +y = np.random.randn(5).astype(np.float32) +z = np.less(x, y) +expect(node, inputs=[x, y], outputs=[z], + name='test_less_bcast') +``` + +
+ + +
+less_broadcast + +```python +node = onnx.helper.make_node( + 'LessOrEqual', + inputs=['x', 'y'], + outputs=['less_equal'], +) + +x = np.random.randn(3, 4, 5).astype(np.float32) +y = np.random.randn(5).astype(np.float32) +z = np.less_equal(x, y) +expect(node, inputs=[x, y], outputs=[z], + name='test_less_equal_bcast') +``` + +
+ + +### **LessOrEqual** + + Returns the tensor resulted from performing the `less_equal` logical operation + elementwise on the input tensors `A` and `B` (with Numpy-style broadcasting support). + + This operator supports **multidirectional (i.e., Numpy-style) broadcasting**; for more details please check [the doc](Broadcasting.md). + +#### Version + +This version of the operator has been available since version 12 of the default ONNX operator set. + +#### Inputs + +
+
A (non-differentiable) : T
+
First input operand for the logical operator.
+
B (non-differentiable) : T
+
Second input operand for the logical operator.
+
+ +#### Outputs + +
+
C (non-differentiable) : T1
+
Result tensor.
+
+ +#### Type Constraints + +
+
T : tensor(uint8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(int8), tensor(int16), tensor(int32), tensor(int64), tensor(float16), tensor(float), tensor(double)
+
Constrains input types to all numeric tensors.
+
T1 : tensor(bool)
+
Constrains output to boolean tensor.
+
+ + +### **Log** + + Calculates the natural log of the given input tensor, element-wise. + +#### Version + +This version of the operator has been available since version 13 of the default ONNX operator set. + +Other versions of this operator: 1, 6 + +#### Inputs + +
+
input (differentiable) : T
+
Input tensor
+
+ +#### Outputs + +
+
output (differentiable) : T
+
The natural log of the input tensor computed element-wise
+
+ +#### Type Constraints + +
+
T : tensor(float16), tensor(float), tensor(double), tensor(bfloat16)
+
Constrain input and output types to float tensors.
+
+ + +#### Examples + +
+log + +```python +node = onnx.helper.make_node( + 'Log', + inputs=['x'], + outputs=['y'], +) + +x = np.array([1, 10]).astype(np.float32) +y = np.log(x) # expected output [0., 2.30258512] +expect(node, inputs=[x], outputs=[y], + name='test_log_example') + +x = np.exp(np.random.randn(3, 4, 5).astype(np.float32)) +y = np.log(x) +expect(node, inputs=[x], outputs=[y], + name='test_log') +``` + +
+ + +### **LogSoftmax** + + The operator computes the log of softmax values for the given input: + + LogSoftmax(input, axis) = Log(Softmax(input, axis=axis)) + + The "axis" attribute indicates the dimension along which LogSoftmax + will be performed. The output tensor has the same shape + and contains the LogSoftmax values of the corresponding input. + +#### Version + +This version of the operator has been available since version 13 of the default ONNX operator set. + +Other versions of this operator: 1, 11 + +#### Attributes + +
+
axis : int (default is -1)
+
+Describes the dimension LogSoftmax will be performed on. +Negative value means counting dimensions +from the back. Accepted range is [-r, r-1] where r = rank(input). +
+
+ +#### Inputs + +
+
input (differentiable) : T
+
The input tensor of rank >= axis.
+
+ +#### Outputs + +
+
output (differentiable) : T
+
The output values with the same shape as the input tensor.
+
+ +#### Type Constraints + +
+
T : tensor(float16), tensor(float), tensor(double), tensor(bfloat16)
+
Constrain input and output types to float tensors.
+
+ + +#### Examples + +
+logsoftmax + +```python +node = onnx.helper.make_node( + 'LogSoftmax', + inputs=['x'], + outputs=['y'], +) +x = np.array([[-1, 0, 1]]).astype(np.float32) +# expected output +# [[-2.4076061 -1.407606 -0.407606 ]] +y = logsoftmax(x) +expect(node, inputs=[x], outputs=[y], + name='test_logsoftmax_example_1') +``` + +
+ + +
+logsoftmax_axis + +```python +x = np.array([[0, 1, 2, 3], [10000, 10001, 10002, 10003]] + ).astype(np.float32) +# expected output +# [[-3.4401896 -2.4401896 -1.4401896 -0.44018966] +# [-3.4401896 -2.4401896 -1.4401896 -0.44018966]] +y = logsoftmax(x) + +node = onnx.helper.make_node( + 'LogSoftmax', + inputs=['x'], + outputs=['y'], +) +expect(node, inputs=[x], outputs=[y], + name='test_logsoftmax_large_number') + +x = np.abs(np.random.randn(3, 4, 5).astype(np.float32)) +node = onnx.helper.make_node( + 'LogSoftmax', + inputs=['x'], + outputs=['y'], + axis=0, +) +y = logsoftmax(x, axis=0) +expect(node, inputs=[x], outputs=[y], + name='test_logsoftmax_axis_0') + +node = onnx.helper.make_node( + 'LogSoftmax', + inputs=['x'], + outputs=['y'], + axis=1, +) +y = logsoftmax(x, axis=1) +expect(node, inputs=[x], outputs=[y], + name='test_logsoftmax_axis_1') + +node = onnx.helper.make_node( + 'LogSoftmax', + inputs=['x'], + outputs=['y'], + axis=2, +) +y = logsoftmax(x, axis=2) +expect(node, inputs=[x], outputs=[y], + name='test_logsoftmax_axis_2') + +node = onnx.helper.make_node( + 'LogSoftmax', + inputs=['x'], + outputs=['y'], + axis=-1, +) +y = logsoftmax(x, axis=-1) +expect(node, inputs=[x], outputs=[y], + name='test_logsoftmax_negative_axis') + +# default axis is -1 +node = onnx.helper.make_node( + 'LogSoftmax', + inputs=['x'], + outputs=['y'], +) +expect(node, inputs=[x], outputs=[y], + name='test_logsoftmax_default_axis') +``` + +
+ + +### **Loop** + + Generic Looping construct. This loop has multiple termination conditions: + + 1) Trip count. Iteration count specified at runtime. Set by + specifying the input M. Optional. Set to empty string to omit. + Note that a static trip count (specified at graph construction time) can be + specified by passing in a constant node for input M. + 2) Loop termination condition. This is an input to the op that determines + whether to run the first iteration and also a loop-carried dependency for + the body graph. The body graph must yield a value for the condition variable, + whether this input is provided or not. + + This table summarizes the operating modes of this operator with equivalent + C-style code: + + Operator inputs defined as (max_trip_count, condition_var). + + input ("", ""): + for (int i=0; ; ++i) { + cond = ... // Note this value is ignored, but is required in the body + } + + input ("", cond) // Note this is analogous to a while loop + bool cond = ...; + for (int i=0; cond; ++i) { + cond = ...; + } + + input ("", 1) // Note this is analogous to a do-while loop + bool cond = true + for (int i=0; cond; ++i) { + cond = ...; + } + + input (trip_count, "") // Note this is analogous to a for loop + int trip_count = ... + for (int i=0; i < trip_count; ++i) { + cond = ...; // ignored + } + + input (trip_count, cond) + int trip_count = ...; + bool cond = ...; + for (int i=0; i < trip_count && cond; ++i) { + cond = ...; + } + + + *Sample usage - cond as well as trip count* + + graph predict-net { + %a = Constant[value = ]() + %b = Constant[value = ]() + %keepgoing = Constant[value = ]() + %max_trip_count = Constant[value = ]() + %keepgoing_out, %b_out, %user_defined_vals = Loop[body = ](%max_trip_count, %keepgoing, %b) + return + } + + graph body-net ( + %i[INT32, scalar] // iteration number + %keepgoing_in[BOOL, scalar] // incoming loop-termination-condition; not used + %b_in[INT32, scalar] // incoming value of loop-carried-dependency b + ) { + %my_local = Add(%a, %b_in) + %b_out = Sub(%a, %b_in) // outgoing value of loop-carried-dependency b + %keepgoing_out = Greater(%my_local, %b_out) // outgoing loop-termination-condition + %user_defined_val = Add(%b_in, %b_in) // scan-output value to be accumulated + return %keepgoing_out, %b_out, %user_defined_val + } + + *Sample equivalent C code* + + { + /* User-defined code (enclosing scope) */ + int a = 3, b = 6; + bool keepgoing = true; // Analogous to input cond + /* End user-defined code */ + + /* Implicitly-defined code */ + const int max_trip_count = 10; // Analogous to input M + int user_defined_vals[]; // Imagine this is resizable + /* End implicitly-defined code */ + /* initialize loop-carried variables and scan-output variables */ + bool keepgoing_out = keepgoing + int b_out = b + + for (int i=0; i < max_trip_count && keepgoing_out; ++i) { + /* Implicitly-defined code: bind actual parameter values + to formal parameter variables of loop-body */ + bool keepgoing_in = keepgoing_out; + bool b_in = b_out; + + /* User-defined code (loop body) */ + int my_local = a + b_in; // Reading value "a" from the enclosing scope is fine + b_out = a - b_in; + keepgoing_out = my_local > b_out; + user_defined_val = b_in + b_in; // b_in and b_out are different variables + /* End user-defined code */ + + /* Implicitly defined-code */ + user_defined_vals[i] = user_defined_val // accumulate scan-output values + } + // int t = my_local; // Can't do this. my_local is not accessible here. + + // The values below are bound to the output variables of the loop and therefore accessible + // b_out; user_defined_vals; keepgoing_out; + } + + There are several things of note in this code snippet: + + 1) Values from the enclosing scope (i.e. variable "a" here) are in scope and can + be referenced in the inputs of the loop. + 2) Any values computed in the loop body that needs to be used in a subsequent + iteration or after the loop are modelled using a pair of variables in the loop-body, + consisting of an input variable (eg., b_in) and an output variable (eg., b_out). + These are referred to as loop-carried dependences. The loop operation node + supplies the input value of the input variable for the first iteration, and + returns the output value of the output variable produced by the final + iteration. + 3) Scan_output variables are used to implicitly concatenate values computed across + all the iterations. In the above example, the value of user_defined_val computed + over all iterations are concatenated and returned as the value of user_defined_vals + after the loop. + 4) Values created in the body cannot be accessed in the enclosing scope, + except using the mechanism described above. + + Note that the semantics of this op support "diagonal" or "wavefront" execution. + (See Step 3 here for an example: + https://devblogs.nvidia.com/optimizing-recurrent-neural-networks-cudnn-5/). + Frontends should emit multi-layer RNNs as a series of While operators (with + time being the inner looping dimension), with each successive layer consuming + the scan_outputs from the previous layer, possibly going through several + point-wise operators (e.g. dropout, residual connections, linear layer). + + The input/output of subgraph (produced by loop node) matching is based on order instead of name. The implementation will figure out the names based on this order. + +#### Version + +This version of the operator has been available since version 16 of the default ONNX operator set. + +Other versions of this operator: 1, 11, 13 + +#### Attributes + +
+
body : graph (required)
+
The graph run each iteration. It has 2+N inputs: (iteration_num, condition, loop carried dependencies...). It has 1+N+K outputs: (condition, loop carried dependencies..., scan_outputs...). Each scan_output is created by concatenating the value of the specified output value at the end of each iteration of the loop. It is an error if the dimensions or data type of these scan_outputs change across loop iterations.
+
+ +#### Inputs (2 - ∞) + +
+
M (optional) : I
+
A maximum trip-count for the loop specified at runtime. Optional. Pass empty string to skip.
+
cond (optional) : B
+
A boolean termination condition. Optional. Pass empty string to skip.
+
v_initial (variadic, heterogeneous) : V
+
The initial values of any loop-carried dependencies (values that change across loop iterations)
+
+ +#### Outputs (1 - ∞) + +
+
v_final_and_scan_outputs (variadic, heterogeneous) : V
+
Final N loop carried dependency values then K scan_outputs. Scan outputs must be Tensors.
+
+ +#### Type Constraints + +
+
V : tensor(uint8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(int8), tensor(int16), tensor(int32), tensor(int64), tensor(float16), tensor(float), tensor(double), tensor(string), tensor(bool), tensor(complex64), tensor(complex128), seq(tensor(uint8)), seq(tensor(uint16)), seq(tensor(uint32)), seq(tensor(uint64)), seq(tensor(int8)), seq(tensor(int16)), seq(tensor(int32)), seq(tensor(int64)), seq(tensor(float16)), seq(tensor(float)), seq(tensor(double)), seq(tensor(string)), seq(tensor(bool)), seq(tensor(complex64)), seq(tensor(complex128)), optional(seq(tensor(uint8))), optional(seq(tensor(uint16))), optional(seq(tensor(uint32))), optional(seq(tensor(uint64))), optional(seq(tensor(int8))), optional(seq(tensor(int16))), optional(seq(tensor(int32))), optional(seq(tensor(int64))), optional(seq(tensor(float16))), optional(seq(tensor(float))), optional(seq(tensor(double))), optional(seq(tensor(string))), optional(seq(tensor(bool))), optional(seq(tensor(complex64))), optional(seq(tensor(complex128))), optional(tensor(uint8)), optional(tensor(uint16)), optional(tensor(uint32)), optional(tensor(uint64)), optional(tensor(int8)), optional(tensor(int16)), optional(tensor(int32)), optional(tensor(int64)), optional(tensor(float16)), optional(tensor(float)), optional(tensor(double)), optional(tensor(string)), optional(tensor(bool)), optional(tensor(complex64)), optional(tensor(complex128))
+
All Tensor and Sequence types
+
I : tensor(int64)
+
tensor of int64, which should be a scalar.
+
B : tensor(bool)
+
tensor of bool, which should be a scalar.
+
+ + +#### Examples + +
+loop_11 + +```python +# Given a tensor x of values [x1, ..., xN], and initial tensor y +# sum up its elements using a scan +# returning the final state (y+x1+x2+...+xN) as well the scan_output +# [y+x1, y+x1+x2, ..., y+x1+x2+...+xN] + +y_in = onnx.helper.make_tensor_value_info('y_in', onnx.TensorProto.FLOAT, [1]) +y_out = onnx.helper.make_tensor_value_info('y_out', onnx.TensorProto.FLOAT, [1]) +scan_out = onnx.helper.make_tensor_value_info('scan_out', onnx.TensorProto.FLOAT, [1]) +cond_in = onnx.helper.make_tensor_value_info('cond_in', onnx.TensorProto.BOOL, []) +cond_out = onnx.helper.make_tensor_value_info('cond_out', onnx.TensorProto.BOOL, []) +iter_count = onnx.helper.make_tensor_value_info('iter_count', onnx.TensorProto.INT64, []) + +x = np.array([1, 2, 3, 4, 5]).astype(np.float32) +y = np.array([-2]).astype(np.float32) + +x_const_node = onnx.helper.make_node( + 'Constant', + inputs=[], + outputs=['x'], + value=onnx.helper.make_tensor( + name='const_tensor_x', + data_type=onnx.TensorProto.FLOAT, + dims=x.shape, + vals=x.flatten().astype(float), + ) +) + +one_const_node = onnx.helper.make_node( + 'Constant', + inputs=[], + outputs=['one'], + value=onnx.helper.make_tensor( + name='const_tensor_one', + data_type=onnx.TensorProto.INT64, + dims=(), + vals=[1] + ) +) + +i_add_node = onnx.helper.make_node( + 'Add', + inputs=['iter_count', 'one'], + outputs=['end'] +) + +start_unsqueeze_node = onnx.helper.make_node( + 'Unsqueeze', + inputs=['iter_count'], + outputs=['slice_start'], + axes=[0] +) + +end_unsqueeze_node = onnx.helper.make_node( + 'Unsqueeze', + inputs=['end'], + outputs=['slice_end'], + axes=[0] +) + +slice_node = onnx.helper.make_node( + 'Slice', + inputs=['x', 'slice_start', 'slice_end'], + outputs=['slice_out'] +) + +y_add_node = onnx.helper.make_node( + 'Add', + inputs=['y_in', 'slice_out'], + outputs=['y_out'] +) + +identity_node = onnx.helper.make_node( + 'Identity', + inputs=['cond_in'], + outputs=['cond_out'] +) + +scan_identity_node = onnx.helper.make_node( + 'Identity', + inputs=['y_out'], + outputs=['scan_out'] +) + +loop_body = onnx.helper.make_graph( + [identity_node, x_const_node, one_const_node, i_add_node, + start_unsqueeze_node, end_unsqueeze_node, slice_node, y_add_node, + scan_identity_node], + 'loop_body', + [iter_count, cond_in, y_in], + [cond_out, y_out, scan_out] +) + +node = onnx.helper.make_node( + 'Loop', + inputs=['trip_count', 'cond', 'y'], + outputs=['res_y', 'res_scan'], + body=loop_body +) + +trip_count = np.array(5).astype(np.int64) +res_y = np.array([13]).astype(np.float32) +cond = np.array(1).astype(bool) +res_scan = np.array([-1, 1, 4, 8, 13]).astype(np.float32).reshape((5, 1)) +expect(node, inputs=[trip_count, cond, y], outputs=[res_y, res_scan], + name='test_loop11', opset_imports=[onnx.helper.make_opsetid("", 11)]) +``` + +
+ + +
+loop_13 + +```python +# Given a tensor x of values [x1, ..., xN], +# Return a sequence of tensors of +# [[x1], [x1, x2], ..., [x1, ..., xN]] + +seq_in = onnx.helper.make_tensor_sequence_value_info('seq_in', onnx.TensorProto.FLOAT, None) +seq_out = onnx.helper.make_tensor_sequence_value_info('seq_out', onnx.TensorProto.FLOAT, None) +cond_in = onnx.helper.make_tensor_value_info('cond_in', onnx.TensorProto.BOOL, []) +cond_out = onnx.helper.make_tensor_value_info('cond_out', onnx.TensorProto.BOOL, []) +iter_count = onnx.helper.make_tensor_value_info('iter_count', onnx.TensorProto.INT64, []) + +x = np.array([1, 2, 3, 4, 5]).astype(np.float32) + +x_const_node = onnx.helper.make_node( + 'Constant', + inputs=[], + outputs=['x'], + value=onnx.helper.make_tensor( + name='const_tensor_x', + data_type=onnx.TensorProto.FLOAT, + dims=x.shape, + vals=x.flatten().astype(float), + ) +) + +one_const_node = onnx.helper.make_node( + 'Constant', + inputs=[], + outputs=['one'], + value=onnx.helper.make_tensor( + name='const_tensor_one', + data_type=onnx.TensorProto.INT64, + dims=(), + vals=[1] + ) +) + +zero_const_node = onnx.helper.make_node( + 'Constant', + inputs=[], + outputs=['slice_start'], + value=onnx.helper.make_tensor( + name='const_tensor_zero', + data_type=onnx.TensorProto.INT64, + dims=(1,), + vals=[0] + ) +) + +axes_node = onnx.helper.make_node( + 'Constant', + inputs=[], + outputs=['axes'], + value=onnx.helper.make_tensor( + name='const_tensor_axes', + data_type=onnx.TensorProto.INT64, + dims=(), + vals=[0] + ) +) + +add_node = onnx.helper.make_node( + 'Add', + inputs=['iter_count', 'one'], + outputs=['end'] +) + +end_unsqueeze_node = onnx.helper.make_node( + 'Unsqueeze', + inputs=['end', 'axes'], + outputs=['slice_end'] +) + +slice_node = onnx.helper.make_node( + 'Slice', + inputs=['x', 'slice_start', 'slice_end'], + outputs=['slice_out'] +) + +insert_node = onnx.helper.make_node( + 'SequenceInsert', + inputs=['seq_in', 'slice_out'], + outputs=['seq_out'] +) + +identity_node = onnx.helper.make_node( + 'Identity', + inputs=['cond_in'], + outputs=['cond_out'] +) + +loop_body = onnx.helper.make_graph( + [identity_node, x_const_node, one_const_node, zero_const_node, add_node, + axes_node, end_unsqueeze_node, slice_node, insert_node], + 'loop_body', + [iter_count, cond_in, seq_in], + [cond_out, seq_out] +) + +node = onnx.helper.make_node( + 'Loop', + inputs=['trip_count', 'cond', 'seq_empty'], + outputs=['seq_res'], + body=loop_body +) + +trip_count = np.array(5).astype(np.int64) +seq_empty = [] # type: List[Any] +seq_res = [x[:int(i)] for i in x] +cond = np.array(1).astype(bool) +expect(node, inputs=[trip_count, cond, seq_empty], outputs=[seq_res], + name='test_loop13_seq', opset_imports=[onnx.helper.make_opsetid("", 13)], + input_type_protos=[onnx.helper.make_tensor_type_proto(onnx.TensorProto.INT64, trip_count.shape), + onnx.helper.make_tensor_type_proto(onnx.TensorProto.BOOL, cond.shape), + onnx.helper.make_sequence_type_proto( + onnx.helper.make_tensor_type_proto(onnx.TensorProto.FLOAT, []))]) +``` + +
+ + +
+loop_16_none + +```python +# Given a tensor sequence of values [x1, ..., xN], and an initial optional sequence of tensors [x0], +# Return a concatenated sequence of tensors of +# [x0, [x1], [x1, x2], ..., [x1, ..., xN]] + +ten_in_tp = onnx.helper.make_tensor_type_proto(onnx.TensorProto.FLOAT, []) +seq_in_tp = onnx.helper.make_sequence_type_proto(ten_in_tp) +opt_in_tp = onnx.helper.make_optional_type_proto(seq_in_tp) +opt_in = onnx.helper.make_value_info('opt_seq_in', opt_in_tp) +seq_out = onnx.helper.make_tensor_sequence_value_info('seq_out', onnx.TensorProto.FLOAT, []) +cond_in = onnx.helper.make_tensor_value_info('cond_in', onnx.TensorProto.BOOL, []) +cond_out = onnx.helper.make_tensor_value_info('cond_out', onnx.TensorProto.BOOL, []) +iter_count = onnx.helper.make_tensor_value_info('iter_count', onnx.TensorProto.INT64, []) + +x0 = np.array(0).astype(np.float32) +x = np.array([1, 2, 3, 4, 5]).astype(np.float32) + +optional_has_elem_node = onnx.helper.make_node( + 'OptionalHasElement', + inputs=['opt_seq_in'], + outputs=['optional_has_elem'] +) + +optional_is_none = onnx.helper.make_node( + 'Not', + inputs=['optional_has_elem'], + outputs=['optional_is_none'] +) + +optional_get_elem = onnx.helper.make_node( + 'OptionalGetElement', + inputs=['opt_seq_in'], + outputs=['seq_in'] +) + +constant_in = onnx.helper.make_node( + 'Constant', + inputs=[], + outputs=['constant_in'], + value=onnx.helper.make_tensor( + name='const_tensor', + data_type=onnx.TensorProto.FLOAT, + dims=(), + vals=[0] + ) +) + +seq_const_in = onnx.helper.make_node( + 'SequenceConstruct', + inputs=['constant_in'], + outputs=['init_seq_in'] +) + +then_seq_out = onnx.helper.make_tensor_sequence_value_info('init_seq_in', onnx.TensorProto.FLOAT, []) +then_body = onnx.helper.make_graph( + [constant_in, seq_const_in], + 'then_body', + [], + [then_seq_out] +) + +else_seq_out = onnx.helper.make_tensor_sequence_value_info('seq_in', onnx.TensorProto.FLOAT, []) +else_body = onnx.helper.make_graph( + [optional_get_elem], + 'else_body', + [], + [else_seq_out] +) + +if_node = onnx.helper.make_node( + 'If', + inputs=['optional_is_none'], + outputs=['sequence'], + then_branch=then_body, + else_branch=else_body +) + +x_const_node = onnx.helper.make_node( + 'Constant', + inputs=[], + outputs=['x'], + value=onnx.helper.make_tensor( + name='const_tensor_x', + data_type=onnx.TensorProto.FLOAT, + dims=x.shape, + vals=x.flatten().astype(float), + ) +) + +one_const_node = onnx.helper.make_node( + 'Constant', + inputs=[], + outputs=['one'], + value=onnx.helper.make_tensor( + name='const_tensor_one', + data_type=onnx.TensorProto.INT64, + dims=(), + vals=[1] + ) +) + +zero_const_node = onnx.helper.make_node( + 'Constant', + inputs=[], + outputs=['slice_start'], + value=onnx.helper.make_tensor( + name='const_tensor_zero', + data_type=onnx.TensorProto.INT64, + dims=(1,), + vals=[0] + ) +) + +axes_node = onnx.helper.make_node( + 'Constant', + inputs=[], + outputs=['axes'], + value=onnx.helper.make_tensor( + name='const_tensor_axes', + data_type=onnx.TensorProto.INT64, + dims=(), + vals=[0] + ) +) + +add_node = onnx.helper.make_node( + 'Add', + inputs=['iter_count', 'one'], + outputs=['end'] +) + +end_unsqueeze_node = onnx.helper.make_node( + 'Unsqueeze', + inputs=['end', 'axes'], + outputs=['slice_end'] +) + +slice_node = onnx.helper.make_node( + 'Slice', + inputs=['x', 'slice_start', 'slice_end'], + outputs=['slice_out'] +) + +insert_node = onnx.helper.make_node( + 'SequenceInsert', + inputs=['sequence', 'slice_out'], + outputs=['seq_out'] +) + +identity_node = onnx.helper.make_node( + 'Identity', + inputs=['cond_in'], + outputs=['cond_out'] +) + +loop_body = onnx.helper.make_graph( + [identity_node, optional_has_elem_node, optional_is_none, if_node, x_const_node, one_const_node, + zero_const_node, add_node, axes_node, end_unsqueeze_node, slice_node, insert_node], + 'loop_body', + [iter_count, cond_in, opt_in], + [cond_out, seq_out] +) + +node = onnx.helper.make_node( + 'Loop', + inputs=['trip_count', 'cond', 'opt_seq'], + outputs=['seq_res'], + body=loop_body +) + +trip_count = np.array(5).astype(np.int64) +cond = np.array(1).astype(bool) +seq_res = compute_loop_outputs(x, [x0], trip_count) +opt_seq_in = [x0] # type: List[Any] +expect(node, inputs=[trip_count, cond, opt_seq_in], outputs=[seq_res], + name='test_loop16_seq_none', opset_imports=[onnx.helper.make_opsetid("", 16)], + input_type_protos=[onnx.helper.make_tensor_type_proto(onnx.TensorProto.INT64, trip_count.shape), + onnx.helper.make_tensor_type_proto(onnx.TensorProto.BOOL, cond.shape), + opt_in_tp]) +``` + +
+ + +### **LpNormalization** + + Given a matrix, apply Lp-normalization along the provided axis. + +#### Version + +This version of the operator has been available since version 1 of the default ONNX operator set. + +#### Attributes + +
+
axis : int (default is -1)
+
The axis on which to apply normalization, -1 mean last axis.
+
p : int (default is 2)
+
The order of the normalization, only 1 or 2 are supported.
+
+ +#### Inputs + +
+
input (differentiable) : T
+
Input matrix
+
+ +#### Outputs + +
+
output (differentiable) : T
+
Matrix after normalization
+
+ +#### Type Constraints + +
+
T : tensor(float16), tensor(float), tensor(double)
+
Constrain input and output types to float tensors.
+
+ + +### **LpPool** + + LpPool consumes an input tensor X and applies Lp pooling across + the tensor according to kernel sizes, stride sizes, and pad lengths. + Lp pooling consisting of computing the Lp norm on all values of a subset + of the input tensor according to the kernel size and downsampling the + data into the output tensor Y for further processing. + +#### Version + +This version of the operator has been available since version 11 of the default ONNX operator set. + +Other versions of this operator: 1, 2 + +#### Attributes + +
+
auto_pad : string (default is NOTSET)
+
auto_pad must be either NOTSET, SAME_UPPER, SAME_LOWER or VALID. Where default value is NOTSET, which means explicit padding is used. SAME_UPPER or SAME_LOWER mean pad the input so that `output_shape[i] = ceil(input_shape[i] / strides[i])` for each axis `i`. The padding is split between the two sides equally or almost equally (depending on whether it is even or odd). In case the padding is an odd number, the extra padding is added at the end for SAME_UPPER and at the beginning for SAME_LOWER.
+
kernel_shape : list of ints (required)
+
The size of the kernel along each axis.
+
p : int (default is 2)
+
p value of the Lp norm used to pool over the input data.
+
pads : list of ints
+
Padding for the beginning and ending along each spatial axis, it can take any value greater than or equal to 0. The value represent the number of pixels added to the beginning and end part of the corresponding axis. `pads` format should be as follow [x1_begin, x2_begin...x1_end, x2_end,...], where xi_begin the number of pixels added at the beginning of axis `i` and xi_end, the number of pixels added at the end of axis `i`. This attribute cannot be used simultaneously with auto_pad attribute. If not present, the padding defaults to 0 along start and end of each spatial axis.
+
strides : list of ints
+
Stride along each spatial axis. If not present, the stride defaults to 1 along each spatial axis.
+
+ +#### Inputs + +
+
X (differentiable) : T
+
Input data tensor from the previous operator; dimensions for image case are (N x C x H x W), where N is the batch size, C is the number of channels, and H and W are the height and the width of the data. For non image case, the dimensions are in the form of (N x C x D1 x D2 ... Dn), where N is the batch size.
+
+ +#### Outputs + +
+
Y (differentiable) : T
+
Output data tensor from Lp pooling across the input tensor. Dimensions will vary based on various kernel, stride, and pad sizes.
+
+ +#### Type Constraints + +
+
T : tensor(float16), tensor(float), tensor(double)
+
Constrain input and output types to float tensors.
+
+ + +### **MatMul** + + Matrix product that behaves like numpy.matmul: https://docs.scipy.org/doc/numpy-1.13.0/reference/generated/numpy.matmul.html + +#### Version + +This version of the operator has been available since version 13 of the default ONNX operator set. + +Other versions of this operator: 1, 9 + +#### Inputs + +
+
A (differentiable) : T
+
N-dimensional matrix A
+
B (differentiable) : T
+
N-dimensional matrix B
+
+ +#### Outputs + +
+
Y (differentiable) : T
+
Matrix multiply results from A * B
+
+ +#### Type Constraints + +
+
T : tensor(float16), tensor(float), tensor(double), tensor(uint32), tensor(uint64), tensor(int32), tensor(int64), tensor(bfloat16)
+
Constrain input and output types to float/int tensors.
+
+ + +#### Examples + +
+matmul + +```python +node = onnx.helper.make_node( + 'MatMul', + inputs=['a', 'b'], + outputs=['c'], +) + +# 2d +a = np.random.randn(3, 4).astype(np.float32) +b = np.random.randn(4, 3).astype(np.float32) +c = np.matmul(a, b) +expect(node, inputs=[a, b], outputs=[c], + name='test_matmul_2d') + +# 3d +a = np.random.randn(2, 3, 4).astype(np.float32) +b = np.random.randn(2, 4, 3).astype(np.float32) +c = np.matmul(a, b) +expect(node, inputs=[a, b], outputs=[c], + name='test_matmul_3d') + +# 4d +a = np.random.randn(1, 2, 3, 4).astype(np.float32) +b = np.random.randn(1, 2, 4, 3).astype(np.float32) +c = np.matmul(a, b) +expect(node, inputs=[a, b], outputs=[c], + name='test_matmul_4d') +``` + +
+ + +### **MatMulInteger** + + Matrix product that behaves like numpy.matmul: https://docs.scipy.org/doc/numpy-1.13.0/reference/generated/numpy.matmul.html. + The production MUST never overflow. The accumulation may overflow if and only if in 32 bits. + +#### Version + +This version of the operator has been available since version 10 of the default ONNX operator set. + +#### Inputs (2 - 4) + +
+
A (non-differentiable) : T1
+
N-dimensional matrix A
+
B (non-differentiable) : T2
+
N-dimensional matrix B
+
a_zero_point (optional, non-differentiable) : T1
+
Zero point tensor for input 'A'. It's optional and default value is 0. It could be a scalar or N-D tensor. Scalar refers to per tensor quantization whereas N-D refers to per row quantization. If the input is 2D of shape [M, K] then zero point tensor may be an M element vector [zp_1, zp_2, ..., zp_M]. If the input is N-D tensor with shape [D1, D2, M, K] then zero point tensor may have shape [D1, D2, M, 1].
+
b_zero_point (optional, non-differentiable) : T2
+
Zero point tensor for input 'B'. It's optional and default value is 0. It could be a scalar or a N-D tensor, Scalar refers to per tensor quantization whereas N-D refers to per col quantization. If the input is 2D of shape [K, N] then zero point tensor may be an N element vector [zp_1, zp_2, ..., zp_N]. If the input is N-D tensor with shape [D1, D2, K, N] then zero point tensor may have shape [D1, D2, 1, N].
+
+ +#### Outputs + +
+
Y (non-differentiable) : T3
+
Matrix multiply results from A * B
+
+ +#### Type Constraints + +
+
T1 : tensor(int8), tensor(uint8)
+
Constrain input A data type to 8-bit integer tensor.
+
T2 : tensor(int8), tensor(uint8)
+
Constrain input B data type to 8-bit integer tensor.
+
T3 : tensor(int32)
+
Constrain output Y data type as 32-bit integer tensor.
+
+ + +#### Examples + +
+matmulinteger + +```python +node = onnx.helper.make_node('MatMulInteger', + inputs=['A', 'B', 'a_zero_point', 'b_zero_point'], + outputs=['Y'],) + +A = np.array([[11, 7, 3], + [10, 6, 2], + [9, 5, 1], + [8, 4, 0], ], dtype=np.uint8) + +a_zero_point = np.array([12], dtype=np.uint8) + +B = np.array([[1, 4], + [2, 5], + [3, 6], ], dtype=np.uint8) + +b_zero_point = np.array([0], dtype=np.uint8) + +output = np.array([[-38, -83], + [-44, -98], + [-50, -113], + [-56, -128], ], dtype=np.int32) + +expect(node, inputs=[A, B, a_zero_point, b_zero_point], outputs=[output], + name='test_matmulinteger') +``` + +
+ + +### **Max** + + Element-wise max of each of the input tensors (with Numpy-style broadcasting support). + All inputs and outputs must have the same data type. + This operator supports **multidirectional (i.e., Numpy-style) broadcasting**; for more details please check [the doc](Broadcasting.md). + +#### Version + +This version of the operator has been available since version 13 of the default ONNX operator set. + +Other versions of this operator: 1, 6, 8, 12 + +#### Inputs (1 - ∞) + +
+
data_0 (variadic, differentiable) : T
+
List of tensors for max.
+
+ +#### Outputs + +
+
max (differentiable) : T
+
Output tensor.
+
+ +#### Type Constraints + +
+
T : tensor(uint8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(int8), tensor(int16), tensor(int32), tensor(int64), tensor(float16), tensor(float), tensor(double), tensor(bfloat16)
+
Constrain input and output types to numeric tensors.
+
+ + +#### Examples + +
+max + +```python +data_0 = np.array([3, 2, 1]).astype(np.float32) +data_1 = np.array([1, 4, 4]).astype(np.float32) +data_2 = np.array([2, 5, 3]).astype(np.float32) +result = np.array([3, 5, 4]).astype(np.float32) +node = onnx.helper.make_node( + 'Max', + inputs=['data_0', 'data_1', 'data_2'], + outputs=['result'], +) +expect(node, inputs=[data_0, data_1, data_2], outputs=[result], + name='test_max_example') + +node = onnx.helper.make_node( + 'Max', + inputs=['data_0'], + outputs=['result'], +) +expect(node, inputs=[data_0], outputs=[data_0], + name='test_max_one_input') + +result = np.maximum(data_0, data_1) +node = onnx.helper.make_node( + 'Max', + inputs=['data_0', 'data_1'], + outputs=['result'], +) +expect(node, inputs=[data_0, data_1], outputs=[result], + name='test_max_two_inputs') +``` + +
+ + +
+max_all_numeric_types + +```python +for op_dtype in all_numeric_dtypes: + data_0 = np.array([3, 2, 1]).astype(op_dtype) + data_1 = np.array([1, 4, 4]).astype(op_dtype) + result = np.array([3, 4, 4]).astype(op_dtype) + node = onnx.helper.make_node( + 'Max', + inputs=['data_0', 'data_1'], + outputs=['result'], + ) + expect(node, inputs=[data_0, data_1], outputs=[result], + name='test_max_{0}'.format(np.dtype(op_dtype).name)) +``` + +
+ + +### **MaxPool** + + MaxPool consumes an input tensor X and applies max pooling across + the tensor according to kernel sizes, stride sizes, and pad lengths. + max pooling consisting of computing the max on all values of a + subset of the input tensor according to the kernel size and downsampling the + data into the output tensor Y for further processing. The output spatial shape will be following: + ``` + output_spatial_shape[i] = floor((input_spatial_shape[i] + pad_shape[i] - ((kernel_spatial_shape[i] - 1) * dilations[i] + 1)) / strides_spatial_shape[i] + 1) + ``` + or + ``` + output_spatial_shape[i] = ceil((input_spatial_shape[i] + pad_shape[i] - ((kernel_spatial_shape[i] - 1) * dilations[i] + 1)) / strides_spatial_shape[i] + 1) + ``` + if ceil_mode is enabled + + ``` + * pad_shape[i] is sum of pads along axis i + ``` + + `auto_pad` is a DEPRECATED attribute. If you are using them currently, the output spatial shape will be following: + ``` + VALID: output_spatial_shape[i] = ceil((input_spatial_shape[i] - ((kernel_spatial_shape[i] - 1) * dilations[i] + 1) + 1) / strides_spatial_shape[i]) + SAME_UPPER or SAME_LOWER: output_spatial_shape[i] = ceil(input_spatial_shape[i] / strides_spatial_shape[i]) + ``` + And pad shape will be following if `SAME_UPPER` or `SAME_LOWER`: + ``` + pad_shape[i] = (output_spatial_shape[i] - 1) * strides_spatial_shape[i] + ((kernel_spatial_shape[i] - 1) * dilations[i] + 1) - input_spatial_shape[i] + ``` + The output of each pooling window is maximum number of elements exclude pad. + + +#### Version + +This version of the operator has been available since version 12 of the default ONNX operator set. + +Other versions of this operator: 1, 8, 10, 11 + +#### Attributes + +
+
auto_pad : string (default is NOTSET)
+
auto_pad must be either NOTSET, SAME_UPPER, SAME_LOWER or VALID. Where default value is NOTSET, which means explicit padding is used. SAME_UPPER or SAME_LOWER mean pad the input so that `output_shape[i] = ceil(input_shape[i] / strides[i])` for each axis `i`. The padding is split between the two sides equally or almost equally (depending on whether it is even or odd). In case the padding is an odd number, the extra padding is added at the end for SAME_UPPER and at the beginning for SAME_LOWER.
+
ceil_mode : int (default is 0)
+
Whether to use ceil or floor (default) to compute the output shape.
+
dilations : list of ints
+
Dilation value along each spatial axis of filter. If not present, the dilation defaults to 1 along each spatial axis.
+
kernel_shape : list of ints (required)
+
The size of the kernel along each axis.
+
pads : list of ints
+
Padding for the beginning and ending along each spatial axis, it can take any value greater than or equal to 0. The value represent the number of pixels added to the beginning and end part of the corresponding axis. `pads` format should be as follow [x1_begin, x2_begin...x1_end, x2_end,...], where xi_begin the number of pixels added at the beginning of axis `i` and xi_end, the number of pixels added at the end of axis `i`. This attribute cannot be used simultaneously with auto_pad attribute. If not present, the padding defaults to 0 along start and end of each spatial axis.
+
storage_order : int (default is 0)
+
The storage order of the tensor. 0 is row major, and 1 is column major.
+
strides : list of ints
+
Stride along each spatial axis. If not present, the stride defaults to 1 along each spatial axis.
+
+ +#### Inputs + +
+
X (differentiable) : T
+
Input data tensor from the previous operator; dimensions for image case are (N x C x H x W), where N is the batch size, C is the number of channels, and H and W are the height and the width of the data. For non image case, the dimensions are in the form of (N x C x D1 x D2 ... Dn), where N is the batch size. Optionally, if dimension denotation is in effect, the operation expects the input data tensor to arrive with the dimension denotation of [DATA_BATCH, DATA_CHANNEL, DATA_FEATURE, DATA_FEATURE ...].
+
+ +#### Outputs (1 - 2) + +
+
Y (differentiable) : T
+
Output data tensor from average or max pooling across the input tensor. Dimensions will vary based on various kernel, stride, and pad sizes. Floor value of the dimension is used
+
Indices (optional, non-differentiable) : I
+
Indices tensor from max pooling across the input tensor. The dimensions of indices are the same as output tensor. The values in indices of are the indices of the selected values during pooling. The indices are computed as flatten 1-D tensor, and the indices do not consider padding. So the values in indices are in [0, N x C x D1 x ... x Dn).
+
+ +#### Type Constraints + +
+
T : tensor(float16), tensor(float), tensor(double), tensor(int8), tensor(uint8)
+
Constrain input and output types to float and 8 bit tensors.
+
I : tensor(int64)
+
Constrain index tensor to int64
+
+ + +#### Examples + +
+maxpool_1d_default + +```python +""" +input_shape: [1, 3, 32] +output_shape: [1, 3, 31] +""" +node = onnx.helper.make_node( + 'MaxPool', + inputs=['x'], + outputs=['y'], + kernel_shape=[2], +) +x = np.random.randn(1, 3, 32).astype(np.float32) +x_shape = np.shape(x) +kernel_shape = [2] +strides = [1] +out_shape = get_output_shape('VALID', x_shape[2:], kernel_shape, strides) +padded = x +y = pool(padded, x_shape, kernel_shape, strides, out_shape, [0], 'MAX') + +expect(node, inputs=[x], outputs=[y], name='test_maxpool_1d_default') +``` + +
+ + +
+maxpool_2d_ceil + +```python +""" +input_shape: [1, 1, 4, 4] +output_shape: [1, 1, 2, 2] +""" +node = onnx.helper.make_node( + 'MaxPool', + inputs=['x'], + outputs=['y'], + kernel_shape=[3, 3], + strides=[2, 2], + ceil_mode=True +) +x = np.array([[[ + [1, 2, 3, 4], + [5, 6, 7, 8], + [9, 10, 11, 12], + [13, 14, 15, 16], +]]]).astype(np.float32) +y = np.array([[[ + [11, 12], + [15, 16]]]]).astype(np.float32) + +expect(node, inputs=[x], outputs=[y], name='test_maxpool_2d_ceil') +``` + +
+ + +
+maxpool_2d_default + +```python +""" +input_shape: [1, 3, 32, 32] +output_shape: [1, 3, 31, 31] +""" +node = onnx.helper.make_node( + 'MaxPool', + inputs=['x'], + outputs=['y'], + kernel_shape=[2, 2], +) +x = np.random.randn(1, 3, 32, 32).astype(np.float32) +x_shape = np.shape(x) +kernel_shape = (2, 2) +strides = (1, 1) +out_shape = get_output_shape('VALID', x_shape[2:], kernel_shape, strides) +padded = x +y = pool(padded, x_shape, kernel_shape, strides, out_shape, (0, 0), 'MAX') + +expect(node, inputs=[x], outputs=[y], name='test_maxpool_2d_default') +``` + +
+ + +
+maxpool_2d_dilations + +```python +""" +input_shape: [1, 1, 4, 4] +output_shape: [1, 1, 2, 2] +""" +node = onnx.helper.make_node( + 'MaxPool', + inputs=['x'], + outputs=['y'], + kernel_shape=[2, 2], + strides=[1, 1], + dilations=[2, 2] +) +x = np.array([[[ + [1, 2, 3, 4], + [5, 6, 7, 8], + [9, 10, 11, 12], + [13, 14, 15, 16], +]]]).astype(np.float32) +y = np.array([[[ + [11, 12], + [15, 16]]]]).astype(np.float32) + +expect(node, inputs=[x], outputs=[y], name='test_maxpool_2d_dilations') +``` + +
+ + +
+maxpool_2d_pads + +```python +""" +input_shape: [1, 3, 28, 28] +output_shape: [1, 3, 30, 30] +pad_shape: [4, 4] -> [2, 2, 2, 2] by axis +""" +node = onnx.helper.make_node( + 'MaxPool', + inputs=['x'], + outputs=['y'], + kernel_shape=[3, 3], + pads=[2, 2, 2, 2] +) +x = np.random.randn(1, 3, 28, 28).astype(np.float32) +x_shape = np.shape(x) +kernel_shape = (3, 3) +strides = (1, 1) +pad_bottom = pad_top = pad_right = pad_left = 2 +pad_shape = [pad_top + pad_bottom, pad_left + pad_right] +out_shape = get_output_shape('VALID', np.add(x_shape[2:], pad_shape), kernel_shape, strides) +padded = np.pad(x, ((0, 0), (0, 0), (pad_top, pad_bottom), (pad_left, pad_right)), mode='constant', + constant_values=np.nan) +y = pool(padded, x_shape, kernel_shape, strides, out_shape, pad_shape, 'MAX') + +expect(node, inputs=[x], outputs=[y], name='test_maxpool_2d_pads') +``` + +
+ + +
+maxpool_2d_precomputed_pads + +```python +""" +input_shape: [1, 1, 5, 5] +output_shape: [1, 1, 5, 5] +pad_shape: [4, 4] -> [2, 2, 2, 2] by axis +""" +node = onnx.helper.make_node( + 'MaxPool', + inputs=['x'], + outputs=['y'], + kernel_shape=[5, 5], + pads=[2, 2, 2, 2] + +) +x = np.array([[[ + [1, 2, 3, 4, 5], + [6, 7, 8, 9, 10], + [11, 12, 13, 14, 15], + [16, 17, 18, 19, 20], + [21, 22, 23, 24, 25], +]]]).astype(np.float32) +y = np.array([[[ + [13, 14, 15, 15, 15], + [18, 19, 20, 20, 20], + [23, 24, 25, 25, 25], + [23, 24, 25, 25, 25], + [23, 24, 25, 25, 25]]]]).astype(np.float32) + +expect(node, inputs=[x], outputs=[y], name='test_maxpool_2d_precomputed_pads') +``` + +
+ + +
+maxpool_2d_precomputed_same_upper + +```python +""" +input_shape: [1, 1, 5, 5] +output_shape: [1, 1, 3, 3] +pad_shape: [2, 2] -> [1, 1, 1, 1] by axis +""" +node = onnx.helper.make_node( + 'MaxPool', + inputs=['x'], + outputs=['y'], + kernel_shape=[3, 3], + strides=[2, 2], + auto_pad='SAME_UPPER' +) +x = np.array([[[ + [1, 2, 3, 4, 5], + [6, 7, 8, 9, 10], + [11, 12, 13, 14, 15], + [16, 17, 18, 19, 20], + [21, 22, 23, 24, 25], +]]]).astype(np.float32) +y = np.array([[[[7, 9, 10], + [17, 19, 20], + [22, 24, 25]]]]).astype(np.float32) + +expect(node, inputs=[x], outputs=[y], name='test_maxpool_2d_precomputed_same_upper') +``` + +
+ + +
+maxpool_2d_precomputed_strides + +```python +""" +input_shape: [1, 1, 5, 5] +output_shape: [1, 1, 2, 2] +""" +node = onnx.helper.make_node( + 'MaxPool', + inputs=['x'], + outputs=['y'], + kernel_shape=[2, 2], + strides=[2, 2] +) +x = np.array([[[ + [1, 2, 3, 4, 5], + [6, 7, 8, 9, 10], + [11, 12, 13, 14, 15], + [16, 17, 18, 19, 20], + [21, 22, 23, 24, 25], +]]]).astype(np.float32) +y = np.array([[[[7, 9], + [17, 19]]]]).astype(np.float32) + +expect(node, inputs=[x], outputs=[y], name='test_maxpool_2d_precomputed_strides') +``` + +
+ + +
+maxpool_2d_same_lower + +```python +""" +input_shape: [1, 3, 32, 32] +output_shape: [1, 3, 32, 32] +pad_shape: [1, 1] -> [1, 0, 1, 0] by axis +""" +node = onnx.helper.make_node( + 'MaxPool', + inputs=['x'], + outputs=['y'], + kernel_shape=[2, 2], + auto_pad='SAME_LOWER' +) +x = np.random.randn(1, 3, 32, 32).astype(np.float32) +x_shape = np.shape(x) +kernel_shape = (2, 2) +strides = (1, 1) +out_shape = get_output_shape('SAME_LOWER', x_shape[2:], kernel_shape, strides) +pad_shape = get_pad_shape('SAME_LOWER', x_shape[2:], kernel_shape, strides, out_shape) +pad_bottom = pad_shape[0] // 2 +pad_top = pad_shape[0] - pad_bottom +pad_right = pad_shape[1] // 2 +pad_left = pad_shape[1] - pad_right +padded = np.pad(x, ((0, 0), (0, 0), (pad_top, pad_bottom), (pad_left, pad_right)), mode='constant', + constant_values=np.nan) +y = pool(padded, x_shape, kernel_shape, strides, out_shape, pad_shape, 'MAX') + +expect(node, inputs=[x], outputs=[y], name='test_maxpool_2d_same_lower') +``` + +
+ + +
+maxpool_2d_same_upper + +```python +""" +input_shape: [1, 3, 32, 32] +output_shape: [1, 3, 32, 32] +pad_shape: [1, 1] -> [0, 1, 0, 1] by axis +""" +node = onnx.helper.make_node( + 'MaxPool', + inputs=['x'], + outputs=['y'], + kernel_shape=[2, 2], + auto_pad='SAME_UPPER' +) +x = np.random.randn(1, 3, 32, 32).astype(np.float32) +x_shape = np.shape(x) +kernel_shape = (2, 2) +strides = (1, 1) +out_shape = get_output_shape('SAME_UPPER', x_shape[2:], kernel_shape, strides) +pad_shape = get_pad_shape('SAME_UPPER', x_shape[2:], kernel_shape, strides, out_shape) +pad_top = pad_shape[0] // 2 +pad_bottom = pad_shape[0] - pad_top +pad_left = pad_shape[1] // 2 +pad_right = pad_shape[1] - pad_left +padded = np.pad(x, ((0, 0), (0, 0), (pad_top, pad_bottom), (pad_left, pad_right)), mode='constant', + constant_values=np.nan) +y = pool(padded, x_shape, kernel_shape, strides, out_shape, pad_shape, 'MAX') + +expect(node, inputs=[x], outputs=[y], name='test_maxpool_2d_same_upper') +``` + +
+ + +
+maxpool_2d_strides + +```python +""" +input_shape: [1, 3, 32, 32] +output_shape: [1, 3, 10, 10] +""" +node = onnx.helper.make_node( + 'MaxPool', + inputs=['x'], + outputs=['y'], + kernel_shape=[5, 5], + strides=[3, 3] +) +x = np.random.randn(1, 3, 32, 32).astype(np.float32) +x_shape = np.shape(x) +kernel_shape = (5, 5) +strides = (3, 3) +out_shape = get_output_shape('VALID', x_shape[2:], kernel_shape, strides) +padded = x +y = pool(padded, x_shape, kernel_shape, strides, out_shape, (0, 0), 'MAX') + +expect(node, inputs=[x], outputs=[y], name='test_maxpool_2d_strides') +``` + +
+ + +
+maxpool_2d_uint8 + +```python +""" +input_shape: [1, 1, 5, 5] +output_shape: [1, 1, 5, 5] +pad_shape: [4, 4] -> [2, 2, 2, 2] by axis +""" +node = onnx.helper.make_node( + 'MaxPool', + inputs=['x'], + outputs=['y'], + kernel_shape=[5, 5], + pads=[2, 2, 2, 2] +) +x = np.array([[[ + [1, 2, 3, 4, 5], + [6, 7, 8, 9, 10], + [11, 12, 13, 14, 15], + [16, 17, 18, 19, 20], + [21, 22, 23, 24, 25], +]]]).astype(np.uint8) +y = np.array([[[ + [13, 14, 15, 15, 15], + [18, 19, 20, 20, 20], + [23, 24, 25, 25, 25], + [23, 24, 25, 25, 25], + [23, 24, 25, 25, 25]]]]).astype(np.uint8) + +expect(node, inputs=[x], outputs=[y], name='test_maxpool_2d_uint8') +``` + +
+ + +
+maxpool_3d_default + +```python +""" +input_shape: [1, 3, 32, 32, 32] +output_shape: [1, 3, 31, 31, 31] +""" +node = onnx.helper.make_node( + 'MaxPool', + inputs=['x'], + outputs=['y'], + kernel_shape=[2, 2, 2], +) +x = np.random.randn(1, 3, 32, 32, 32).astype(np.float32) +x_shape = np.shape(x) +kernel_shape = [2, 2, 2] +strides = [1, 1, 1] +out_shape = get_output_shape('VALID', x_shape[2:], kernel_shape, strides) +padded = x +y = pool(padded, x_shape, kernel_shape, strides, out_shape, [0, 0, 0], 'MAX') + +expect(node, inputs=[x], outputs=[y], name='test_maxpool_3d_default') +``` + +
+ + +
+maxpool_with_argmax_2d_precomputed_pads + +```python +""" +input_shape: [1, 1, 5, 5] +output_shape: [1, 1, 5, 5] +pad_shape: [4, 4] -> [2, 2, 2, 2] by axis +""" +node = onnx.helper.make_node( + 'MaxPool', + inputs=['x'], + outputs=['y', 'z'], + kernel_shape=[5, 5], + pads=[2, 2, 2, 2] +) +x = np.array([[[ + [1, 2, 3, 4, 5], + [6, 7, 8, 9, 10], + [11, 12, 13, 14, 15], + [16, 17, 18, 19, 20], + [21, 22, 23, 24, 25], +]]]).astype(np.float32) +y = np.array([[[ + [13, 14, 15, 15, 15], + [18, 19, 20, 20, 20], + [23, 24, 25, 25, 25], + [23, 24, 25, 25, 25], + [23, 24, 25, 25, 25]]]]).astype(np.float32) +z = np.array([[[ + [12, 13, 14, 14, 14], + [17, 18, 19, 19, 19], + [22, 23, 24, 24, 24], + [22, 23, 24, 24, 24], + [22, 23, 24, 24, 24]]]]).astype(np.int64) + +expect(node, inputs=[x], outputs=[y, z], name='test_maxpool_with_argmax_2d_precomputed_pads') +``` + +
+ + +
+maxpool_with_argmax_2d_precomputed_strides + +```python +""" +input_shape: [1, 1, 5, 5] +output_shape: [1, 1, 2, 2] +""" +node = onnx.helper.make_node( + 'MaxPool', + inputs=['x'], + outputs=['y', 'z'], + kernel_shape=[2, 2], + strides=[2, 2], + storage_order=1 +) +x = np.array([[[ + [1, 2, 3, 4, 5], + [6, 7, 8, 9, 10], + [11, 12, 13, 14, 15], + [16, 17, 18, 19, 20], + [21, 22, 23, 24, 25], +]]]).astype(np.float32) +y = np.array([[[[7, 9], + [17, 19]]]]).astype(np.float32) +z = np.array([[[[6, 16], + [8, 18]]]]).astype(np.int64) + +expect(node, inputs=[x], outputs=[y, z], name='test_maxpool_with_argmax_2d_precomputed_strides') +``` + +
+ + +### **MaxRoiPool** + + ROI max pool consumes an input tensor X and region of interests (RoIs) to + apply max pooling across each RoI, to produce output 4-D tensor of shape + (num_rois, channels, pooled_shape[0], pooled_shape[1]). + +#### Version + +This version of the operator has been available since version 1 of the default ONNX operator set. + +#### Attributes + +
+
pooled_shape : list of ints (required)
+
ROI pool output shape (height, width).
+
spatial_scale : float (default is 1.0)
+
Multiplicative spatial scale factor to translate ROI coordinates from their input scale to the scale used when pooling.
+
+ +#### Inputs + +
+
X (differentiable) : T
+
Input data tensor from the previous operator; dimensions for image case are (N x C x H x W), where N is the batch size, C is the number of channels, and H and W are the height and the width of the data.
+
rois (non-differentiable) : T
+
RoIs (Regions of Interest) to pool over. Should be a 2-D tensor of shape (num_rois, 5) given as [[batch_id, x1, y1, x2, y2], ...].
+
+ +#### Outputs + +
+
Y (differentiable) : T
+
RoI pooled output 4-D tensor of shape (num_rois, channels, pooled_shape[0], pooled_shape[1]).
+
+ +#### Type Constraints + +
+
T : tensor(float16), tensor(float), tensor(double)
+
Constrain input and output types to float tensors.
+
+ + +### **MaxUnpool** + + MaxUnpool essentially computes the partial inverse of the MaxPool op. + The input information to this op is typically the the output information from a MaxPool op. The first + input tensor X is the tensor that needs to be unpooled, which is typically the pooled tensor (first output) + from MaxPool. The second input tensor, I, contains the indices to the (locally maximal) elements corrsponding + to the elements in the first input tensor X. Input tensor I is typically the second output of the MaxPool op. + The third (optional) input is a tensor that specifies the output size of the unpooling operation. + + MaxUnpool is intended to do 'partial' inverse of the MaxPool op. 'Partial' because all the non-maximal + values from the original input to MaxPool are set to zero in the output of the MaxUnpool op. Pooling + the result of an unpooling operation should give back the original input to the unpooling op. + + MaxUnpool can produce the same output size for several input sizes, which makes unpooling op ambiguous. + The third input argument, output_size, is meant to disambiguate the op and produce output tensor of + known/predictable size. + + In addition to the inputs, MaxUnpool takes three attributes, namely kernel_shape, strides, and pads, + which define the exact unpooling op. The attributes typically have the same values as the corrsponding + pooling op that the unpooling op is trying to invert. + +#### Version + +This version of the operator has been available since version 11 of the default ONNX operator set. + +Other versions of this operator: 9 + +#### Attributes + +
+
kernel_shape : list of ints (required)
+
The size of the kernel along each axis.
+
pads : list of ints
+
Padding for the beginning and ending along each spatial axis, it can take any value greater than or equal to 0. The value represent the number of pixels added to the beginning and end part of the corresponding axis. `pads` format should be as follow [x1_begin, x2_begin...x1_end, x2_end,...], where xi_begin the number of pixels added at the beginning of axis `i` and xi_end, the number of pixels added at the end of axis `i`. This attribute cannot be used simultaneously with auto_pad attribute. If not present, the padding defaults to 0 along start and end of each spatial axis.
+
strides : list of ints
+
Stride along each spatial axis. If not present, the stride defaults to 1 along each spatial axis.
+
+ +#### Inputs (2 - 3) + +
+
X (differentiable) : T1
+
Input data tensor that has to be unpooled. This tensor is typically the first output of the MaxPool op.Dimensions for image case are (N x C x H x W), where N is the batch size, C is the number of channels, and H and W are the height and the width of the data. For non-image case, the dimensions are in the form of (N x C x D1 x D2 ... Dn), where N is the batch size. Optionally, if dimension denotation is in effect, the operation expects the input data tensor to arrive with the dimension denotation of [DATA_BATCH, DATA_CHANNEL, DATA_FEATURE, DATA_FEATURE ...].
+
I (non-differentiable) : T2
+
Input data tensor containing the indices corresponding to elements in the first input tensor X.This tensor is typically the second output of the MaxPool op.Dimensions must be the same as input tensor X. The indices are linear, i.e. computed considering the tensor as flattened 1-D tensor, assuming row-major storage. Also, the linear indices should not consider padding. So the values in indices are in the range [0, N x C x D1 x ... x Dn).
+
output_shape (optional, non-differentiable) : T2
+
The shape of the output can be explicitly set which will cause pads values to be auto generated. If 'output_shape' is specified, 'pads' values are ignored.
+
+ +#### Outputs + +
+
output (differentiable) : T1
+
Output data tensor that contains the result of the unpooling.
+
+ +#### Type Constraints + +
+
T1 : tensor(float16), tensor(float), tensor(double)
+
Constrain input and output types to float tensors.
+
T2 : tensor(int64)
+
Constrain index tensor to int64
+
+ + +#### Examples + +
+with_output_shape + +```python +node = onnx.helper.make_node( + 'MaxUnpool', + inputs=['xT', 'xI', 'output_shape'], + outputs=['y'], + kernel_shape=[2, 2], + strides=[2, 2] +) +xT = np.array([[[[5, 6], + [7, 8]]]], dtype=np.float32) +xI = np.array([[[[5, 7], + [13, 15]]]], dtype=np.int64) +output_shape = np.array((1, 1, 5, 5), dtype=np.int64) +y = np.array([[[[0, 0, 0, 0, 0], + [0, 5, 0, 6, 0], + [0, 0, 0, 0, 0], + [0, 7, 0, 8, 0], + [0, 0, 0, 0, 0]]]], dtype=np.float32) +expect(node, inputs=[xT, xI, output_shape], outputs=[y], name='test_maxunpool_export_with_output_shape') +``` + +
+ + +
+without_output_shape + +```python +node = onnx.helper.make_node( + 'MaxUnpool', + inputs=['xT', 'xI'], + outputs=['y'], + kernel_shape=[2, 2], + strides=[2, 2] +) +xT = np.array([[[[1, 2], + [3, 4]]]], dtype=np.float32) +xI = np.array([[[[5, 7], + [13, 15]]]], dtype=np.int64) +y = np.array([[[[0, 0, 0, 0], + [0, 1, 0, 2], + [0, 0, 0, 0], + [0, 3, 0, 4]]]], dtype=np.float32) +expect(node, inputs=[xT, xI], outputs=[y], name='test_maxunpool_export_without_output_shape') +``` + +
+ + +### **Mean** + + Element-wise mean of each of the input tensors (with Numpy-style broadcasting support). + All inputs and outputs must have the same data type. + This operator supports **multidirectional (i.e., Numpy-style) broadcasting**; for more details please check [the doc](Broadcasting.md). + +#### Version + +This version of the operator has been available since version 13 of the default ONNX operator set. + +Other versions of this operator: 1, 6, 8 + +#### Inputs (1 - ∞) + +
+
data_0 (variadic, differentiable) : T
+
List of tensors for mean.
+
+ +#### Outputs + +
+
mean (differentiable) : T
+
Output tensor.
+
+ +#### Type Constraints + +
+
T : tensor(float16), tensor(float), tensor(double), tensor(bfloat16)
+
Constrain input and output types to float tensors.
+
+ + +#### Examples + +
+mean + +```python +data_0 = np.array([3, 0, 2]).astype(np.float32) +data_1 = np.array([1, 3, 4]).astype(np.float32) +data_2 = np.array([2, 6, 6]).astype(np.float32) +result = np.array([2, 3, 4]).astype(np.float32) +node = onnx.helper.make_node( + 'Mean', + inputs=['data_0', 'data_1', 'data_2'], + outputs=['result'], +) +expect(node, inputs=[data_0, data_1, data_2], outputs=[result], + name='test_mean_example') + +node = onnx.helper.make_node( + 'Mean', + inputs=['data_0'], + outputs=['result'], +) +expect(node, inputs=[data_0], outputs=[data_0], + name='test_mean_one_input') + +result = np.divide(np.add(data_0, data_1), 2.) +node = onnx.helper.make_node( + 'Mean', + inputs=['data_0', 'data_1'], + outputs=['result'], +) +expect(node, inputs=[data_0, data_1], outputs=[result], + name='test_mean_two_inputs') +``` + +
+ + +### **MeanVarianceNormalization** + + A MeanVarianceNormalization Function: Perform mean variance normalization + on the input tensor X using formula:
``` (X-EX)/sqrt(E(X-EX)^2) ``` + +#### Version + +This version of the operator has been available since version 13 of the default ONNX operator set. + +Other versions of this operator: 9 + +#### Attributes + +
+
axes : list of ints (default is ['0', '2', '3'])
+
A list of integers, along which to reduce. The default is to caculate along axes [0,2,3] for calculating mean and variance along each channel. Two variables with the same C-coordinate are associated with the same mean and variance.
+
+ +#### Inputs + +
+
X (differentiable) : T
+
Input tensor
+
+ +#### Outputs + +
+
Y (differentiable) : T
+
Output tensor
+
+ +#### Type Constraints + +
+
T : tensor(float16), tensor(float), tensor(double), tensor(bfloat16)
+
Constrain input and output types to all numeric tensors.
+
+ + +#### Examples + +
+meanvariancenormalization + +```python +node = onnx.helper.make_node( + 'MeanVarianceNormalization', + inputs=['X'], + outputs=['Y'] +) + +input_data = np.array([[[[0.8439683], [0.5665144], [0.05836735]], + [[0.02916367], [0.12964272], [0.5060197]], + [[0.79538304], [0.9411346], [0.9546573]]], + [[[0.17730942], [0.46192095], [0.26480448]], + [[0.6746842], [0.01665257], [0.62473077]], + [[0.9240844], [0.9722341], [0.11965699]]], + [[[0.41356155], [0.9129373], [0.59330076]], + [[0.81929934], [0.7862604], [0.11799799]], + [[0.69248444], [0.54119414], [0.07513223]]]], dtype=np.float32) + +# Calculate expected output data +data_mean = np.mean(input_data, axis=(0, 2, 3), keepdims=1) +data_mean_squared = np.power(data_mean, 2) +data_squared = np.power(input_data, 2) +data_squared_mean = np.mean(data_squared, axis=(0, 2, 3), keepdims=1) +std = np.sqrt(data_squared_mean - data_mean_squared) +expected_output = (input_data - data_mean) / (std + 1e-9) + +expect(node, inputs=[input_data], outputs=[expected_output], + name='test_mvn') +``` + +
+ + +### **Min** + + Element-wise min of each of the input tensors (with Numpy-style broadcasting support). + All inputs and outputs must have the same data type. + This operator supports **multidirectional (i.e., Numpy-style) broadcasting**; for more details please check [the doc](Broadcasting.md). + +#### Version + +This version of the operator has been available since version 13 of the default ONNX operator set. + +Other versions of this operator: 1, 6, 8, 12 + +#### Inputs (1 - ∞) + +
+
data_0 (variadic, differentiable) : T
+
List of tensors for min.
+
+ +#### Outputs + +
+
min (differentiable) : T
+
Output tensor.
+
+ +#### Type Constraints + +
+
T : tensor(uint8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(int8), tensor(int16), tensor(int32), tensor(int64), tensor(float16), tensor(float), tensor(double), tensor(bfloat16)
+
Constrain input and output types to numeric tensors.
+
+ + +#### Examples + +
+min + +```python +data_0 = np.array([3, 2, 1]).astype(np.float32) +data_1 = np.array([1, 4, 4]).astype(np.float32) +data_2 = np.array([2, 5, 0]).astype(np.float32) +result = np.array([1, 2, 0]).astype(np.float32) +node = onnx.helper.make_node( + 'Min', + inputs=['data_0', 'data_1', 'data_2'], + outputs=['result'], +) +expect(node, inputs=[data_0, data_1, data_2], outputs=[result], + name='test_min_example') + +node = onnx.helper.make_node( + 'Min', + inputs=['data_0'], + outputs=['result'], +) +expect(node, inputs=[data_0], outputs=[data_0], + name='test_min_one_input') + +result = np.minimum(data_0, data_1) +node = onnx.helper.make_node( + 'Min', + inputs=['data_0', 'data_1'], + outputs=['result'], +) +expect(node, inputs=[data_0, data_1], outputs=[result], + name='test_min_two_inputs') +``` + +
+ + +
+min_all_numeric_types + +```python +for op_dtype in all_numeric_dtypes: + data_0 = np.array([3, 2, 1]).astype(op_dtype) + data_1 = np.array([1, 4, 4]).astype(op_dtype) + result = np.array([1, 2, 1]).astype(op_dtype) + node = onnx.helper.make_node( + 'Min', + inputs=['data_0', 'data_1'], + outputs=['result'], + ) + expect(node, inputs=[data_0, data_1], outputs=[result], + name='test_min_{0}'.format(np.dtype(op_dtype).name)) +``` + +
+ + +### **Mod** + + Performs element-wise binary modulus (with Numpy-style broadcasting support). + The sign of the remainder is the same as that of the Divisor. + + Mod operator can also behave like C fmod() or numpy.fmod. In this case, the sign of the remainder however, will be the same as the Dividend + (in contrast to integer mod). To force a behavior like numpy.fmod() an 'fmod' Attribute is provided. + This attribute is set to 0 by default causing the behavior to be like integer mod. + Setting this attribute to 1 causes the remainder to be calculated similar to that of numpy.fmod(). + + If the input type is floating point, then `fmod` attribute must be set to 1. + + In case of dividend being zero, the results will be platform dependent. + + This operator supports **multidirectional (i.e., Numpy-style) broadcasting**; for more details please check [the doc](Broadcasting.md). + +#### Version + +This version of the operator has been available since version 13 of the default ONNX operator set. + +Other versions of this operator: 10 + +#### Attributes + +
+
fmod : int (default is 0)
+
Whether the operator should behave like fmod (default=0 meaning it will do integer mods); Set this to 1 to force fmod treatment
+
+ +#### Inputs + +
+
A (differentiable) : T
+
Dividend tensor
+
B (non-differentiable) : T
+
Divisor tensor
+
+ +#### Outputs + +
+
C (differentiable) : T
+
Remainder tensor
+
+ +#### Type Constraints + +
+
T : tensor(uint8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(int8), tensor(int16), tensor(int32), tensor(int64), tensor(float16), tensor(float), tensor(double), tensor(bfloat16)
+
Constrain input and output types to high-precision numeric tensors.
+
+ + +#### Examples + +
+mod_broadcast + +```python +node = onnx.helper.make_node( + 'Mod', + inputs=['x', 'y'], + outputs=['z'], +) + +x = np.arange(0, 30).reshape([3, 2, 5]).astype(np.int32) +y = np.array([7]).astype(np.int32) +z = np.mod(x, y) +# array([[[0, 1, 2, 3, 4], +# [5, 6, 0, 1, 2]], + +# [[3, 4, 5, 6, 0], +# [1, 2, 3, 4, 5]], + +# [[6, 0, 1, 2, 3], +# [4, 5, 6, 0, 1]]], dtype=int32) +expect(node, inputs=[x, y], outputs=[z], + name='test_mod_broadcast') +``` + +
+ + +
+mod_int64_fmod + +```python +node = onnx.helper.make_node( + 'Mod', + inputs=['x', 'y'], + outputs=['z'], + fmod=1 +) + +x = np.array([-4, 7, 5, 4, -7, 8]).astype(np.int64) +y = np.array([2, -3, 8, -2, 3, 5]).astype(np.int64) +z = np.fmod(x, y) # expected output [ 0, 1, 5, 0, -1, 3] +expect(node, inputs=[x, y], outputs=[z], + name='test_mod_int64_fmod') +``` + +
+ + +
+mod_mixed_sign_float16 + +```python +node = onnx.helper.make_node( + 'Mod', + inputs=['x', 'y'], + outputs=['z'], + fmod=1 +) + +x = np.array([-4.3, 7.2, 5.0, 4.3, -7.2, 8.0]).astype(np.float16) +y = np.array([2.1, -3.4, 8.0, -2.1, 3.4, 5.0]).astype(np.float16) +z = np.fmod(x, y) # expected output [-0.10156, 0.3984 , 5. , 0.10156, -0.3984 , 3.] +expect(node, inputs=[x, y], outputs=[z], + name='test_mod_mixed_sign_float16') +``` + +
+ + +
+mod_mixed_sign_float32 + +```python +node = onnx.helper.make_node( + 'Mod', + inputs=['x', 'y'], + outputs=['z'], + fmod=1 +) + +x = np.array([-4.3, 7.2, 5.0, 4.3, -7.2, 8.0]).astype(np.float32) +y = np.array([2.1, -3.4, 8.0, -2.1, 3.4, 5.0]).astype(np.float32) +z = np.fmod(x, y) # expected output [-0.10000038, 0.39999962, 5. , 0.10000038, -0.39999962, 3.] +expect(node, inputs=[x, y], outputs=[z], + name='test_mod_mixed_sign_float32') +``` + +
+ + +
+mod_mixed_sign_float64 + +```python +node = onnx.helper.make_node( + 'Mod', + inputs=['x', 'y'], + outputs=['z'], + fmod=1 +) + +x = np.array([-4.3, 7.2, 5.0, 4.3, -7.2, 8.0]).astype(np.float64) +y = np.array([2.1, -3.4, 8.0, -2.1, 3.4, 5.0]).astype(np.float64) +z = np.fmod(x, y) # expected output [-0.1, 0.4, 5. , 0.1, -0.4, 3.] +expect(node, inputs=[x, y], outputs=[z], + name='test_mod_mixed_sign_float64') +``` + +
+ + +
+mod_mixed_sign_int16 + +```python +node = onnx.helper.make_node( + 'Mod', + inputs=['x', 'y'], + outputs=['z'], +) + +x = np.array([-4, 7, 5, 4, -7, 8]).astype(np.int16) +y = np.array([2, -3, 8, -2, 3, 5]).astype(np.int16) +z = np.mod(x, y) # expected output [ 0, -2, 5, 0, 2, 3] +expect(node, inputs=[x, y], outputs=[z], + name='test_mod_mixed_sign_int16') +``` + +
+ + +
+mod_mixed_sign_int32 + +```python +node = onnx.helper.make_node( + 'Mod', + inputs=['x', 'y'], + outputs=['z'], +) + +x = np.array([-4, 7, 5, 4, -7, 8]).astype(np.int32) +y = np.array([2, -3, 8, -2, 3, 5]).astype(np.int32) +z = np.mod(x, y) # expected output [ 0, -2, 5, 0, 2, 3] +expect(node, inputs=[x, y], outputs=[z], + name='test_mod_mixed_sign_int32') +``` + +
+ + +
+mod_mixed_sign_int64 + +```python +node = onnx.helper.make_node( + 'Mod', + inputs=['x', 'y'], + outputs=['z'], +) + +x = np.array([-4, 7, 5, 4, -7, 8]).astype(np.int64) +y = np.array([2, -3, 8, -2, 3, 5]).astype(np.int64) +z = np.mod(x, y) # expected output [ 0, -2, 5, 0, 2, 3] +expect(node, inputs=[x, y], outputs=[z], + name='test_mod_mixed_sign_int64') +``` + +
+ + +
+mod_mixed_sign_int8 + +```python +node = onnx.helper.make_node( + 'Mod', + inputs=['x', 'y'], + outputs=['z'], +) + +x = np.array([-4, 7, 5, 4, -7, 8]).astype(np.int8) +y = np.array([2, -3, 8, -2, 3, 5]).astype(np.int8) +z = np.mod(x, y) # expected output [ 0, -2, 5, 0, 2, 3] +expect(node, inputs=[x, y], outputs=[z], + name='test_mod_mixed_sign_int8') +``` + +
+ + +
+mod_uint16 + +```python +node = onnx.helper.make_node( + 'Mod', + inputs=['x', 'y'], + outputs=['z'], +) + +x = np.array([4, 7, 5]).astype(np.uint16) +y = np.array([2, 3, 8]).astype(np.uint16) +z = np.mod(x, y) # expected output [0, 1, 5] +expect(node, inputs=[x, y], outputs=[z], + name='test_mod_uint16') +``` + +
+ + +
+mod_uint32 + +```python +node = onnx.helper.make_node( + 'Mod', + inputs=['x', 'y'], + outputs=['z'], +) + +x = np.array([4, 7, 5]).astype(np.uint32) +y = np.array([2, 3, 8]).astype(np.uint32) +z = np.mod(x, y) # expected output [0, 1, 5] +expect(node, inputs=[x, y], outputs=[z], + name='test_mod_uint32') +``` + +
+ + +
+mod_uint64 + +```python +node = onnx.helper.make_node( + 'Mod', + inputs=['x', 'y'], + outputs=['z'], +) + +x = np.array([4, 7, 5]).astype(np.uint64) +y = np.array([2, 3, 8]).astype(np.uint64) +z = np.mod(x, y) # expected output [0, 1, 5] +expect(node, inputs=[x, y], outputs=[z], + name='test_mod_uint64') +``` + +
+ + +
+mod_uint8 + +```python +node = onnx.helper.make_node( + 'Mod', + inputs=['x', 'y'], + outputs=['z'], +) + +x = np.array([4, 7, 5]).astype(np.uint8) +y = np.array([2, 3, 8]).astype(np.uint8) +z = np.mod(x, y) # expected output [0, 1, 5] +expect(node, inputs=[x, y], outputs=[z], + name='test_mod_uint8') +``` + +
+ + +### **Mul** + + Performs element-wise binary multiplication (with Numpy-style broadcasting support). + + This operator supports **multidirectional (i.e., Numpy-style) broadcasting**; for more details please check [the doc](Broadcasting.md). + + (Opset 14 change): Extend supported types to include uint8, int8, uint16, and int16. + +#### Version + +This version of the operator has been available since version 14 of the default ONNX operator set. + +Other versions of this operator: 1, 6, 7, 13 + +#### Inputs + +
+
A (differentiable) : T
+
First operand.
+
B (differentiable) : T
+
Second operand.
+
+ +#### Outputs + +
+
C (differentiable) : T
+
Result, has same element type as two inputs
+
+ +#### Type Constraints + +
+
T : tensor(uint8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(int8), tensor(int16), tensor(int32), tensor(int64), tensor(float16), tensor(float), tensor(double), tensor(bfloat16)
+
Constrain input and output types to all numeric tensors.
+
+ + +#### Examples + +
+mul + +```python +node = onnx.helper.make_node( + 'Mul', + inputs=['x', 'y'], + outputs=['z'], +) + +x = np.array([1, 2, 3]).astype(np.float32) +y = np.array([4, 5, 6]).astype(np.float32) +z = x * y # expected output [4., 10., 18.] +expect(node, inputs=[x, y], outputs=[z], + name='test_mul_example') + +x = np.random.randn(3, 4, 5).astype(np.float32) +y = np.random.randn(3, 4, 5).astype(np.float32) +z = x * y +expect(node, inputs=[x, y], outputs=[z], + name='test_mul') + +x = np.random.randint(4, size=(3, 4, 5), dtype=np.uint8) +y = np.random.randint(24, size=(3, 4, 5), dtype=np.uint8) +z = x * y +expect(node, inputs=[x, y], outputs=[z], + name='test_mul_uint8') +``` + +
+ + +
+mul_broadcast + +```python +node = onnx.helper.make_node( + 'Mul', + inputs=['x', 'y'], + outputs=['z'], +) + +x = np.random.randn(3, 4, 5).astype(np.float32) +y = np.random.randn(5).astype(np.float32) +z = x * y +expect(node, inputs=[x, y], outputs=[z], + name='test_mul_bcast') +``` + +
+ + +### **Multinomial** + + Generate a tensor of samples from a multinomial distribution according to the probabilities + of each of the possible outcomes. + +#### Version + +This version of the operator has been available since version 7 of the default ONNX operator set. + +#### Attributes + +
+
dtype : int (default is 6)
+
(Optional) The data type for the elements of the output tensor, if not specified, we will use int32.
+
sample_size : int (default is 1)
+
Number of times to sample.
+
seed : float
+
(Optional) Seed to the random generator, if not specified we will auto generate one.
+
+ +#### Inputs + +
+
input : T1
+
Input tensor with shape [batch_size, class_size], where class_size is the number of all possible outcomes. Each value along the axis zero represents the unnormalized log-probability of each corresponding outcome in a batch.
+
+ +#### Outputs + +
+
output : T2
+
Output tensor with shape [batch_size, sample_size], where sample_size is the number of times to sample. Each value along the axis zero represents the outcome of the corresponding sample in a batch.
+
+ +#### Type Constraints + +
+
T1 : tensor(float16), tensor(float), tensor(double)
+
Constrain input types to float tensors.
+
T2 : tensor(int32), tensor(int64)
+
Constrain output types to integral tensors.
+
+ + +### **Neg** + + Neg takes one input data (Tensor) and produces one output data + (Tensor) where each element flipped sign, y = -x, is applied to + the tensor elementwise. + +#### Version + +This version of the operator has been available since version 13 of the default ONNX operator set. + +Other versions of this operator: 1, 6 + +#### Inputs + +
+
X (differentiable) : T
+
Input tensor
+
+ +#### Outputs + +
+
Y (differentiable) : T
+
Output tensor
+
+ +#### Type Constraints + +
+
T : tensor(float), tensor(int32), tensor(int8), tensor(int16), tensor(int64), tensor(float16), tensor(double), tensor(bfloat16)
+
Constrain input and output types to signed numeric tensors.
+
+ + +#### Examples + +
+neg + +```python +node = onnx.helper.make_node( + 'Neg', + inputs=['x'], + outputs=['y'], +) + +x = np.array([-4, 2]).astype(np.float32) +y = np.negative(x) # expected output [4., -2.], +expect(node, inputs=[x], outputs=[y], + name='test_neg_example') + +x = np.random.randn(3, 4, 5).astype(np.float32) +y = np.negative(x) +expect(node, inputs=[x], outputs=[y], + name='test_neg') +``` + +
+ + +### **NegativeLogLikelihoodLoss** + + A NegativeLogLikelihoodLoss operator computes (weighted) negative log likelihood loss. + Its "input" tensor has the shape of (N, C, d1, d2, ..., dk) where k >= 0. + The "input" tensor contains log-probabilities for input[n, :, d_1, d_2,..., d_k] being in a class of [0, C). + The operator's "target" input tensor has the shape of (N, d1, d2, ..., dk). It encodes class labels (one of C classes) + or it may contain a special value (indicated by an attribute ignore_index) for N x d1 x d2 x ... x dk samples. + The loss value for input[n, :, d_1, d_2,...d_k] being classified as class c = target[n][d_1][d_2]...[d_k] is computed as: + + loss[n][d_1][d_2]...[d_k] = -input[n][c][d_1][d_2]...[d_k]. + + When an optional "weight" is provided, the sample loss is calculated as: + + loss[n][d_1][d_2]...[d_k] = -input[n][c][d_1][d_2]...[d_k] * weight[c]. + + loss is zero for the case when target-value equals ignore_index. + + loss[n][d_1][d_2]...[d_k] = 0, when target[n][d_1][d_2]...[d_k] = ignore_index + + If "reduction" attribute is set to "none", the operator's output will be the above loss with shape (N, d1, d2, ..., dk). + If "reduction" attribute is set to "mean" (the default attribute value), the output loss is (weight) averaged: + + mean(loss), if "weight" is not provided, + + or if weight is provided, + + sum(loss) / sum(weight[target[n][d_1][d_2]...[d_k]]]), for all samples. + + If "reduction" attribute is set to "sum", the output is a scalar: + sum(loss). + + See also https://pytorch.org/docs/stable/nn.html#torch.nn.NLLLoss. + + Example 1: + + // negative log likelihood loss, "none" reduction + N, C, d1 = 2, 3, 2 + input = [[[1.0, 2.0], [2.0, 2.0], [3.0, 2.0]], + [[0.0, 1.0], [2.0, 2.0], [1.0, 2]]] + target = [[2, 1], [0, 2]] + + loss = np.zeros((N, d1)) + for n in range(N): + for d_1 in range(d1): + c = target[n][d_1] + loss[n][d_1] = -input[n][c][d_1] + + // print(loss) + // [[-3. -2.] + // [-0. -2.]] + + Example 2: + + // weighted negative log likelihood loss, sum reduction + N, C, d1 = 2, 3, 2 + input = [[[1.0, 2.0], [2.0, 2.0], [3.0, 2.0]], + [[0.0, 1.0], [2.0, 2.0], [1.0, 2]]] + target = [[2, 1], [0, 2]] + weight = [0.2, 0.3, 0.1] + loss = np.zeros((N, d1)) + for n in range(N): + for d_1 in range(d1): + c = target[n][d_1] + loss[n][d_1] = -input[n][c][d_1] * weight[c] + + loss = np.sum(loss) + // print(loss) + // -1.1 + + Example 3: + + // weighted negative log likelihood loss, mean reduction + N, C, d1 = 2, 3, 2 + input = [[[1.0, 2.0], [2.0, 2.0], [3.0, 2.0]], + [[0.0, 1.0], [2.0, 2.0], [1.0, 2]]] + target = [[2, 1], [0, 2]] + weight = [0.2, 0.3, 0.1] + loss = np.zeros((N, d1)) + weight_total = 0 + for n in range(N): + for d_1 in range(d1): + c = target[n][d_1] + loss[n][d_1] = -input[n][c][d_1] * weight[c] + weight_total = weight_total + weight[c] + + loss = np.sum(loss) / weight_total + // print(loss) + // -1.57 + +#### Version + +This version of the operator has been available since version 13 of the default ONNX operator set. + +Other versions of this operator: 12 + +#### Attributes + +
+
ignore_index : int
+
Specifies a target value that is ignored and does not contribute to the input gradient. It's an optional value.
+
reduction : string (default is mean)
+
Type of reduction to apply to loss: none, sum, mean (default). 'none': the output is the loss for each sample. 'sum': the output will be summed. 'mean': the sum of the output will be divided by the sum of applied weights.
+
+ +#### Inputs (2 - 3) + +
+
input (differentiable) : T
+
Input tensor of shape (N, C) or (N, C, d1, d2, ..., dk).
+
target (non-differentiable) : Tind
+
Target tensor of shape (N) or (N, d1, d2, ..., dk). Target element value shall be in range of [0, C). If ignore_index is specified, it may have a value outside [0, C) and the target values should either be in the range [0, C) or have the value ignore_index.
+
weight (optional, non-differentiable) : T
+
Optional rescaling weight tensor. If given, it has to be a tensor of size C. Otherwise, it is treated as if having all ones.
+
+ +#### Outputs + +
+
loss (differentiable) : T
+
The negative log likelihood loss
+
+ +#### Type Constraints + +
+
T : tensor(float16), tensor(float), tensor(double)
+
Constrain input, weight, and output types to floating-point tensors.
+
Tind : tensor(int32), tensor(int64)
+
Constrain target to integer types
+
+ + +#### Examples + +
+input_shape_is_NC + +```python +reduction = 'none' +node = onnx.helper.make_node( + 'NegativeLogLikelihoodLoss', + inputs=['input', 'target'], + outputs=['loss'], + reduction=reduction +) + +N, C = 3, 5 +np.random.seed(0) +input = np.random.rand(N, C).astype(np.float32) +target = np.random.randint(0, high=C, size=(N, )).astype(np.int64) + +negative_log_likelihood_loss = compute_negative_log_likelihood_loss(input, target, weight=None, reduction=reduction) + +expect(node, inputs=[input, target], outputs=[negative_log_likelihood_loss], + name='test_nllloss_NC') +``` + +
+ + +
+input_shape_is_NCd1 + +```python +reduction = 'mean' +node = onnx.helper.make_node( + 'NegativeLogLikelihoodLoss', + inputs=['input', 'target'], + outputs=['loss'], + reduction=reduction +) + +N, C, d1 = 3, 5, 2 +np.random.seed(0) +input = np.random.rand(N, C, d1).astype(np.float32) +target = np.random.randint(0, high=C, size=(N, d1)).astype(np.int64) + +negative_log_likelihood_loss = compute_negative_log_likelihood_loss(input, target, weight=None, reduction=reduction) + +expect(node, inputs=[input, target], outputs=[negative_log_likelihood_loss], + name='test_nllloss_NCd1') +``` + +
+ + +
+input_shape_is_NCd1_ii + +```python +reduction = 'mean' +ignore_index = np.int64(1) +node = onnx.helper.make_node( + 'NegativeLogLikelihoodLoss', + inputs=['input', 'target'], + outputs=['loss'], + reduction=reduction, + ignore_index=ignore_index +) + +N, C, d1 = 3, 5, 2 +np.random.seed(0) +input = np.random.rand(N, C, d1).astype(np.float32) +target = np.random.randint(0, high=C, size=(N, d1)).astype(np.int64) +target[0][0] = np.int64(1) + +negative_log_likelihood_loss = compute_negative_log_likelihood_loss(input, target, weight=None, reduction=reduction, ignore_index=ignore_index) + +expect(node, inputs=[input, target], outputs=[negative_log_likelihood_loss], + name='test_nllloss_NCd1_ii') +``` + +
+ + +
+input_shape_is_NCd1_mean_weight_negative_ii + +```python +reduction = 'mean' +ignore_index = np.int64(-1) + +node = onnx.helper.make_node( + 'NegativeLogLikelihoodLoss', + inputs=['input', 'target', 'weight'], + outputs=['loss'], + reduction=reduction, + ignore_index=ignore_index) + +N, C, dim1 = 3, 5, 6 +np.random.seed(0) +input = np.random.rand(N, C, dim1).astype(np.float32) +target = np.random.randint(0, high=C, size=(N, dim1)).astype(np.int64) +target[0][0] = -1 +weight = np.random.rand(C).astype(np.float32) + +negative_log_likelihood_loss = compute_negative_log_likelihood_loss(input, + target, + weight=weight, + reduction=reduction, + ignore_index=ignore_index) + +expect(node, inputs=[input, target, weight], outputs=[negative_log_likelihood_loss], + name='test_nllloss_NCd1_mean_weight_negative_ii') +``` + +
+ + +
+input_shape_is_NCd1_weight + +```python +reduction = 'mean' +node = onnx.helper.make_node( + 'NegativeLogLikelihoodLoss', + inputs=['input', 'target', 'weight'], + outputs=['loss'], + reduction=reduction +) + +N, C, d1 = 3, 5, 2 +np.random.seed(0) +input = np.random.rand(N, C, d1).astype(np.float32) +target = np.random.randint(0, high=C, size=(N, d1)).astype(np.int64) +weight = np.random.rand(C).astype(np.float32) + +negative_log_likelihood_loss = compute_negative_log_likelihood_loss(input, target, weight=weight, reduction=reduction) + +expect(node, inputs=[input, target, weight], outputs=[negative_log_likelihood_loss], + name='test_nllloss_NCd1_weight') +``` + +
+ + +
+input_shape_is_NCd1_weight_ii + +```python +reduction = 'mean' +ignore_index = np.int64(1) +node = onnx.helper.make_node( + 'NegativeLogLikelihoodLoss', + inputs=['input', 'target', 'weight'], + outputs=['loss'], + reduction=reduction, + ignore_index=ignore_index +) + +N, C, d1 = 3, 5, 2 +np.random.seed(0) +input = np.random.rand(N, C, d1).astype(np.float32) +target = np.random.randint(0, high=C, size=(N, d1)).astype(np.int64) +target[0][0] = np.int64(1) +weight = np.random.rand(C).astype(np.float32) + +negative_log_likelihood_loss = compute_negative_log_likelihood_loss(input, target, weight=weight, reduction=reduction, ignore_index=ignore_index) + +expect(node, inputs=[input, target, weight], outputs=[negative_log_likelihood_loss], + name='test_nllloss_NCd1_weight_ii') +``` + +
+ + +
+input_shape_is_NCd1d2 + +```python +reduction = 'none' +node = onnx.helper.make_node( + 'NegativeLogLikelihoodLoss', + inputs=['input', 'target'], + outputs=['loss'], + reduction=reduction +) + +N, C, dim1, dim2 = 3, 5, 6, 6 +np.random.seed(0) +input = np.random.rand(N, C, dim1, dim2).astype(np.float32) +target = np.random.randint(0, high=C, size=(N, dim1, dim2)).astype(np.int64) + +negative_log_likelihood_loss = compute_negative_log_likelihood_loss(input, target, weight=None, reduction=reduction) + +expect(node, inputs=[input, target], outputs=[negative_log_likelihood_loss], + name='test_nllloss_NCd1d2') +``` + +
+ + +
+input_shape_is_NCd1d2_no_weight_reduction_mean_ii + +```python +reduction = 'mean' +ignore_index = np.int64(1) +node = onnx.helper.make_node( + 'NegativeLogLikelihoodLoss', + inputs=['input', 'target'], + outputs=['loss'], + reduction=reduction, + ignore_index=ignore_index +) + +N, C, dim1, dim2 = 3, 5, 6, 6 +np.random.seed(0) +input = np.random.rand(N, C, dim1, dim2).astype(np.float32) +target = np.random.randint(0, high=C, size=(N, dim1, dim2)).astype(np.int64) +target[0][0][0] = np.int64(1) + +negative_log_likelihood_loss = compute_negative_log_likelihood_loss(input, target, reduction=reduction, ignore_index=ignore_index) + +expect(node, inputs=[input, target], outputs=[negative_log_likelihood_loss], + name='test_nllloss_NCd1d2_no_weight_reduction_mean_ii') +``` + +
+ + +
+input_shape_is_NCd1d2_reduction_mean + +```python +reduction = 'mean' +node = onnx.helper.make_node( + 'NegativeLogLikelihoodLoss', + inputs=['input', 'target'], + outputs=['loss'], + reduction=reduction +) + +N, C, dim1, dim2 = 3, 5, 6, 6 +np.random.seed(0) +input = np.random.rand(N, C, dim1, dim2).astype(np.float32) +target = np.random.randint(0, high=C, size=(N, dim1, dim2)).astype(np.int64) + +negative_log_likelihood_loss = compute_negative_log_likelihood_loss(input, target, weight=None, reduction=reduction) + +expect(node, inputs=[input, target], outputs=[negative_log_likelihood_loss], + name='test_nllloss_NCd1d2_reduction_mean') +``` + +
+ + +
+input_shape_is_NCd1d2_reduction_sum + +```python +reduction = 'sum' +node = onnx.helper.make_node( + 'NegativeLogLikelihoodLoss', + inputs=['input', 'target'], + outputs=['loss'], + reduction=reduction +) + +N, C, dim1, dim2 = 3, 5, 6, 6 +np.random.seed(0) +input = np.random.rand(N, C, dim1, dim2).astype(np.float32) +target = np.random.randint(0, high=C, size=(N, dim1, dim2)) + +negative_log_likelihood_loss = compute_negative_log_likelihood_loss(input, target, weight=None, reduction=reduction) + +expect(node, inputs=[input, target], outputs=[negative_log_likelihood_loss], + name='test_nllloss_NCd1d2_reduction_sum') +``` + +
+ + +
+input_shape_is_NCd1d2_with_weight + +```python +reduction = 'none' +node = onnx.helper.make_node( + 'NegativeLogLikelihoodLoss', + inputs=['input', 'target', 'weight'], + outputs=['loss'], + reduction=reduction +) + +N, C, dim1, dim2 = 3, 5, 6, 6 +np.random.seed(0) +input = np.random.rand(N, C, dim1, dim2).astype(np.float32) +target = np.random.randint(0, high=C, size=(N, dim1, dim2)).astype(np.int64) +weight = np.random.rand(C).astype(np.float32) + +negative_log_likelihood_loss = compute_negative_log_likelihood_loss(input, target, weight=weight, reduction=reduction) + +expect(node, inputs=[input, target, weight], outputs=[negative_log_likelihood_loss], + name='test_nllloss_NCd1d2_with_weight') +``` + +
+ + +
+input_shape_is_NCd1d2_with_weight_reduction_mean + +```python +reduction = 'mean' +node = onnx.helper.make_node( + 'NegativeLogLikelihoodLoss', + inputs=['input', 'target', 'weight'], + outputs=['loss'], + reduction=reduction +) + +N, C, dim1, dim2 = 3, 5, 6, 6 +np.random.seed(0) +input = np.random.rand(N, C, dim1, dim2).astype(np.float32) +target = np.random.randint(0, high=C, size=(N, dim1, dim2)).astype(np.int64) +weight = np.random.rand(C).astype(np.float32) + +negative_log_likelihood_loss = compute_negative_log_likelihood_loss(input, target, weight=weight, reduction=reduction) + +expect(node, inputs=[input, target, weight], outputs=[negative_log_likelihood_loss], + name='test_nllloss_NCd1d2_with_weight_reduction_mean') +``` + +
+ + +
+input_shape_is_NCd1d2_with_weight_reduction_sum + +```python +reduction = 'sum' +node = onnx.helper.make_node( + 'NegativeLogLikelihoodLoss', + inputs=['input', 'target', 'weight'], + outputs=['loss'], + reduction=reduction +) + +N, C, dim1, dim2 = 3, 5, 6, 6 +np.random.seed(0) +input = np.random.rand(N, C, dim1, dim2).astype(np.float32) +target = np.random.randint(0, high=C, size=(N, dim1, dim2)).astype(np.int64) +weight = np.random.rand(C).astype(np.float32) + +negative_log_likelihood_loss = compute_negative_log_likelihood_loss(input, target, weight=weight, reduction=reduction) + +expect(node, inputs=[input, target, weight], outputs=[negative_log_likelihood_loss], + name='test_nllloss_NCd1d2_with_weight_reduction_sum') +``` + +
+ + +
+input_shape_is_NCd1d2_with_weight_reduction_sum_ii + +```python +reduction = 'sum' +ignore_index = np.int64(0) +node = onnx.helper.make_node( + 'NegativeLogLikelihoodLoss', + inputs=['input', 'target', 'weight'], + outputs=['loss'], + reduction=reduction, + ignore_index=ignore_index +) + +N, C, dim1, dim2 = 3, 5, 6, 6 +np.random.seed(0) +input = np.random.rand(N, C, dim1, dim2).astype(np.float32) +target = np.random.randint(0, high=C, size=(N, dim1, dim2)).astype(np.int64) +target[0][0][0] = np.int64(0) +weight = np.random.rand(C).astype(np.float32) + +negative_log_likelihood_loss = compute_negative_log_likelihood_loss(input, target, weight=weight, reduction=reduction, ignore_index=ignore_index) + +expect(node, inputs=[input, target, weight], outputs=[negative_log_likelihood_loss], + name='test_nllloss_NCd1d2_with_weight_reduction_sum_ii') +``` + +
+ + +
+input_shape_is_NCd1d2d3_none_no_weight_negative_ii + +```python +reduction = 'none' +ignore_index = np.int64(-5) + +node = onnx.helper.make_node( + 'NegativeLogLikelihoodLoss', + inputs=['input', 'target'], + outputs=['loss'], + reduction=reduction, + ignore_index=ignore_index) + +N, C, dim1, dim2, dim3 = 3, 5, 6, 6, 5 +np.random.seed(0) +input = np.random.rand(N, C, dim1, dim2, dim3).astype(np.float32) +target = np.random.randint(0, high=C, size=(N, dim1, dim2, dim3)).astype(np.int64) +target[0][0][0][0] = -5 + +negative_log_likelihood_loss = compute_negative_log_likelihood_loss(input, + target, + reduction=reduction, + ignore_index=ignore_index) + +expect(node, inputs=[input, target], outputs=[negative_log_likelihood_loss], + name='test_nllloss_NCd1d2d3_none_no_weight_negative_ii') +``` + +
+ + +
+input_shape_is_NCd1d2d3_sum_weight_high_ii + +```python +reduction = 'sum' +ignore_index = np.int64(10) + +node = onnx.helper.make_node( + 'NegativeLogLikelihoodLoss', + inputs=['input', 'target', 'weight'], + outputs=['loss'], + reduction=reduction, + ignore_index=ignore_index) + +N, C = 3, 5 +np.random.seed(0) +input = np.random.rand(N, C).astype(np.float32) +target = np.random.randint(0, high=C, size=(N)) +target[0] = 10 +weight = np.random.rand(C).astype(np.float32) + +negative_log_likelihood_loss = compute_negative_log_likelihood_loss(input, + target, + weight=weight, + reduction=reduction, + ignore_index=ignore_index) + +expect(node, inputs=[input, target, weight], outputs=[negative_log_likelihood_loss], + name='test_nllloss_NCd1d2d3_sum_weight_high_ii') +``` + +
+ + +
+input_shape_is_NCd1d2d3d4d5_mean_weight + +```python +reduction = 'mean' + +node = onnx.helper.make_node( + 'NegativeLogLikelihoodLoss', + inputs=['input', 'target', 'weight'], + outputs=['loss'], + reduction=reduction) + +N, C, dim1, dim2, dim3, dim4, dim5 = 3, 5, 6, 6, 5, 3, 4 +np.random.seed(0) +input = np.random.rand(N, C, dim1, dim2, dim3, dim4, dim5).astype(np.float32) +target = np.random.randint(0, high=C, size=(N, dim1, dim2, dim3, dim4, dim5)).astype(np.int64) +weight = np.random.rand(C).astype(np.float32) + +negative_log_likelihood_loss = compute_negative_log_likelihood_loss(input, + target, + weight=weight, + reduction=reduction) + +expect(node, inputs=[input, target, weight], outputs=[negative_log_likelihood_loss], + name='test_nllloss_NCd1d2d3d4d5_mean_weight') +``` + +
+ + +
+input_shape_is_NCd1d2d3d4d5_none_no_weight + +```python +reduction = 'none' + +node = onnx.helper.make_node( + 'NegativeLogLikelihoodLoss', + inputs=['input', 'target'], + outputs=['loss'], + reduction=reduction) + +N, C, dim1, dim2, dim3, dim4, dim5 = 3, 5, 6, 6, 5, 3, 4 +np.random.seed(0) +input = np.random.rand(N, C, dim1, dim2, dim3, dim4, dim5).astype(np.float32) +target = np.random.randint(0, high=C, size=(N, dim1, dim2, dim3, dim4, dim5)).astype(np.int64) + +negative_log_likelihood_loss = compute_negative_log_likelihood_loss(input, + target, + reduction=reduction) + +expect(node, inputs=[input, target], outputs=[negative_log_likelihood_loss], + name='test_nllloss_NCd1d2d3d4d5_none_no_weight') +``` + +
+ + +### **NonMaxSuppression** + + Filter out boxes that have high intersection-over-union (IOU) overlap with previously selected boxes. + Bounding boxes with score less than score_threshold are removed. Bounding box format is indicated by attribute center_point_box. + Note that this algorithm is agnostic to where the origin is in the coordinate system and more generally is invariant to + orthogonal transformations and translations of the coordinate system; thus translating or reflections of the coordinate system + result in the same boxes being selected by the algorithm. + The selected_indices output is a set of integers indexing into the input collection of bounding boxes representing the selected boxes. + The bounding box coordinates corresponding to the selected indices can then be obtained using the Gather or GatherND operation. + +#### Version + +This version of the operator has been available since version 11 of the default ONNX operator set. + +Other versions of this operator: 10 + +#### Attributes + +
+
center_point_box : int (default is 0)
+
Integer indicate the format of the box data. The default is 0. 0 - the box data is supplied as [y1, x1, y2, x2] where (y1, x1) and (y2, x2) are the coordinates of any diagonal pair of box corners and the coordinates can be provided as normalized (i.e., lying in the interval [0, 1]) or absolute. Mostly used for TF models. 1 - the box data is supplied as [x_center, y_center, width, height]. Mostly used for Pytorch models.
+
+ +#### Inputs (2 - 5) + +
+
boxes : tensor(float)
+
An input tensor with shape [num_batches, spatial_dimension, 4]. The single box data format is indicated by center_point_box.
+
scores : tensor(float)
+
An input tensor with shape [num_batches, num_classes, spatial_dimension]
+
max_output_boxes_per_class (optional) : tensor(int64)
+
Integer representing the maximum number of boxes to be selected per batch per class. It is a scalar. Default to 0, which means no output.
+
iou_threshold (optional) : tensor(float)
+
Float representing the threshold for deciding whether boxes overlap too much with respect to IOU. It is scalar. Value range [0, 1]. Default to 0.
+
score_threshold (optional) : tensor(float)
+
Float representing the threshold for deciding when to remove boxes based on score. It is a scalar.
+
+ +#### Outputs + +
+
selected_indices : tensor(int64)
+
selected indices from the boxes tensor. [num_selected_indices, 3], the selected index format is [batch_index, class_index, box_index].
+
+ +#### Type Constraints + + + +#### Examples + +
+nonmaxsuppression_center_point_box_format + +```python +node = onnx.helper.make_node( + 'NonMaxSuppression', + inputs=['boxes', 'scores', 'max_output_boxes_per_class', 'iou_threshold', 'score_threshold'], + outputs=['selected_indices'], + center_point_box=1 +) +boxes = np.array([[ + [0.5, 0.5, 1.0, 1.0], + [0.5, 0.6, 1.0, 1.0], + [0.5, 0.4, 1.0, 1.0], + [0.5, 10.5, 1.0, 1.0], + [0.5, 10.6, 1.0, 1.0], + [0.5, 100.5, 1.0, 1.0] +]]).astype(np.float32) +scores = np.array([[[0.9, 0.75, 0.6, 0.95, 0.5, 0.3]]]).astype(np.float32) +max_output_boxes_per_class = np.array([3]).astype(np.int64) +iou_threshold = np.array([0.5]).astype(np.float32) +score_threshold = np.array([0.0]).astype(np.float32) +selected_indices = np.array([[0, 0, 3], [0, 0, 0], [0, 0, 5]]).astype(np.int64) + +expect(node, inputs=[boxes, scores, max_output_boxes_per_class, iou_threshold, score_threshold], outputs=[selected_indices], name='test_nonmaxsuppression_center_point_box_format') +``` + +
+ + +
+nonmaxsuppression_flipped_coordinates + +```python +node = onnx.helper.make_node( + 'NonMaxSuppression', + inputs=['boxes', 'scores', 'max_output_boxes_per_class', 'iou_threshold', 'score_threshold'], + outputs=['selected_indices'] +) +boxes = np.array([[ + [1.0, 1.0, 0.0, 0.0], + [0.0, 0.1, 1.0, 1.1], + [0.0, 0.9, 1.0, -0.1], + [0.0, 10.0, 1.0, 11.0], + [1.0, 10.1, 0.0, 11.1], + [1.0, 101.0, 0.0, 100.0] +]]).astype(np.float32) +scores = np.array([[[0.9, 0.75, 0.6, 0.95, 0.5, 0.3]]]).astype(np.float32) +max_output_boxes_per_class = np.array([3]).astype(np.int64) +iou_threshold = np.array([0.5]).astype(np.float32) +score_threshold = np.array([0.0]).astype(np.float32) +selected_indices = np.array([[0, 0, 3], [0, 0, 0], [0, 0, 5]]).astype(np.int64) + +expect(node, inputs=[boxes, scores, max_output_boxes_per_class, iou_threshold, score_threshold], outputs=[selected_indices], name='test_nonmaxsuppression_flipped_coordinates') +``` + +
+ + +
+nonmaxsuppression_identical_boxes + +```python +node = onnx.helper.make_node( + 'NonMaxSuppression', + inputs=['boxes', 'scores', 'max_output_boxes_per_class', 'iou_threshold', 'score_threshold'], + outputs=['selected_indices'] +) +boxes = np.array([[ + [0.0, 0.0, 1.0, 1.0], + [0.0, 0.0, 1.0, 1.0], + [0.0, 0.0, 1.0, 1.0], + [0.0, 0.0, 1.0, 1.0], + [0.0, 0.0, 1.0, 1.0], + + [0.0, 0.0, 1.0, 1.0], + [0.0, 0.0, 1.0, 1.0], + [0.0, 0.0, 1.0, 1.0], + [0.0, 0.0, 1.0, 1.0], + [0.0, 0.0, 1.0, 1.0] +]]).astype(np.float32) +scores = np.array([[[0.9, 0.9, 0.9, 0.9, 0.9, 0.9, 0.9, 0.9, 0.9, 0.9]]]).astype(np.float32) +max_output_boxes_per_class = np.array([3]).astype(np.int64) +iou_threshold = np.array([0.5]).astype(np.float32) +score_threshold = np.array([0.0]).astype(np.float32) +selected_indices = np.array([[0, 0, 0]]).astype(np.int64) + +expect(node, inputs=[boxes, scores, max_output_boxes_per_class, iou_threshold, score_threshold], outputs=[selected_indices], name='test_nonmaxsuppression_identical_boxes') +``` + +
+ + +
+nonmaxsuppression_limit_output_size + +```python +node = onnx.helper.make_node( + 'NonMaxSuppression', + inputs=['boxes', 'scores', 'max_output_boxes_per_class', 'iou_threshold', 'score_threshold'], + outputs=['selected_indices'] +) +boxes = np.array([[ + [0.0, 0.0, 1.0, 1.0], + [0.0, 0.1, 1.0, 1.1], + [0.0, -0.1, 1.0, 0.9], + [0.0, 10.0, 1.0, 11.0], + [0.0, 10.1, 1.0, 11.1], + [0.0, 100.0, 1.0, 101.0] +]]).astype(np.float32) +scores = np.array([[[0.9, 0.75, 0.6, 0.95, 0.5, 0.3]]]).astype(np.float32) +max_output_boxes_per_class = np.array([2]).astype(np.int64) +iou_threshold = np.array([0.5]).astype(np.float32) +score_threshold = np.array([0.0]).astype(np.float32) +selected_indices = np.array([[0, 0, 3], [0, 0, 0]]).astype(np.int64) + +expect(node, inputs=[boxes, scores, max_output_boxes_per_class, iou_threshold, score_threshold], outputs=[selected_indices], name='test_nonmaxsuppression_limit_output_size') +``` + +
+ + +
+nonmaxsuppression_single_box + +```python +node = onnx.helper.make_node( + 'NonMaxSuppression', + inputs=['boxes', 'scores', 'max_output_boxes_per_class', 'iou_threshold', 'score_threshold'], + outputs=['selected_indices'] +) +boxes = np.array([[ + [0.0, 0.0, 1.0, 1.0] +]]).astype(np.float32) +scores = np.array([[[0.9]]]).astype(np.float32) +max_output_boxes_per_class = np.array([3]).astype(np.int64) +iou_threshold = np.array([0.5]).astype(np.float32) +score_threshold = np.array([0.0]).astype(np.float32) +selected_indices = np.array([[0, 0, 0]]).astype(np.int64) + +expect(node, inputs=[boxes, scores, max_output_boxes_per_class, iou_threshold, score_threshold], outputs=[selected_indices], name='test_nonmaxsuppression_single_box') +``` + +
+ + +
+nonmaxsuppression_suppress_by_IOU + +```python +node = onnx.helper.make_node( + 'NonMaxSuppression', + inputs=['boxes', 'scores', 'max_output_boxes_per_class', 'iou_threshold', 'score_threshold'], + outputs=['selected_indices'] +) +boxes = np.array([[ + [0.0, 0.0, 1.0, 1.0], + [0.0, 0.1, 1.0, 1.1], + [0.0, -0.1, 1.0, 0.9], + [0.0, 10.0, 1.0, 11.0], + [0.0, 10.1, 1.0, 11.1], + [0.0, 100.0, 1.0, 101.0] +]]).astype(np.float32) +scores = np.array([[[0.9, 0.75, 0.6, 0.95, 0.5, 0.3]]]).astype(np.float32) +max_output_boxes_per_class = np.array([3]).astype(np.int64) +iou_threshold = np.array([0.5]).astype(np.float32) +score_threshold = np.array([0.0]).astype(np.float32) +selected_indices = np.array([[0, 0, 3], [0, 0, 0], [0, 0, 5]]).astype(np.int64) + +expect(node, inputs=[boxes, scores, max_output_boxes_per_class, iou_threshold, score_threshold], outputs=[selected_indices], name='test_nonmaxsuppression_suppress_by_IOU') +``` + +
+ + +
+nonmaxsuppression_suppress_by_IOU_and_scores + +```python +node = onnx.helper.make_node( + 'NonMaxSuppression', + inputs=['boxes', 'scores', 'max_output_boxes_per_class', 'iou_threshold', 'score_threshold'], + outputs=['selected_indices'] +) +boxes = np.array([[ + [0.0, 0.0, 1.0, 1.0], + [0.0, 0.1, 1.0, 1.1], + [0.0, -0.1, 1.0, 0.9], + [0.0, 10.0, 1.0, 11.0], + [0.0, 10.1, 1.0, 11.1], + [0.0, 100.0, 1.0, 101.0] +]]).astype(np.float32) +scores = np.array([[[0.9, 0.75, 0.6, 0.95, 0.5, 0.3]]]).astype(np.float32) +max_output_boxes_per_class = np.array([3]).astype(np.int64) +iou_threshold = np.array([0.5]).astype(np.float32) +score_threshold = np.array([0.4]).astype(np.float32) +selected_indices = np.array([[0, 0, 3], [0, 0, 0]]).astype(np.int64) + +expect(node, inputs=[boxes, scores, max_output_boxes_per_class, iou_threshold, score_threshold], outputs=[selected_indices], name='test_nonmaxsuppression_suppress_by_IOU_and_scores') +``` + +
+ + +
+nonmaxsuppression_two_batches + +```python +node = onnx.helper.make_node( + 'NonMaxSuppression', + inputs=['boxes', 'scores', 'max_output_boxes_per_class', 'iou_threshold', 'score_threshold'], + outputs=['selected_indices'] +) +boxes = np.array([[[0.0, 0.0, 1.0, 1.0], + [0.0, 0.1, 1.0, 1.1], + [0.0, -0.1, 1.0, 0.9], + [0.0, 10.0, 1.0, 11.0], + [0.0, 10.1, 1.0, 11.1], + [0.0, 100.0, 1.0, 101.0]], + [[0.0, 0.0, 1.0, 1.0], + [0.0, 0.1, 1.0, 1.1], + [0.0, -0.1, 1.0, 0.9], + [0.0, 10.0, 1.0, 11.0], + [0.0, 10.1, 1.0, 11.1], + [0.0, 100.0, 1.0, 101.0]]]).astype(np.float32) +scores = np.array([[[0.9, 0.75, 0.6, 0.95, 0.5, 0.3]], + [[0.9, 0.75, 0.6, 0.95, 0.5, 0.3]]]).astype(np.float32) +max_output_boxes_per_class = np.array([2]).astype(np.int64) +iou_threshold = np.array([0.5]).astype(np.float32) +score_threshold = np.array([0.0]).astype(np.float32) +selected_indices = np.array([[0, 0, 3], [0, 0, 0], [1, 0, 3], [1, 0, 0]]).astype(np.int64) + +expect(node, inputs=[boxes, scores, max_output_boxes_per_class, iou_threshold, score_threshold], outputs=[selected_indices], name='test_nonmaxsuppression_two_batches') +``` + +
+ + +
+nonmaxsuppression_two_classes + +```python +node = onnx.helper.make_node( + 'NonMaxSuppression', + inputs=['boxes', 'scores', 'max_output_boxes_per_class', 'iou_threshold', 'score_threshold'], + outputs=['selected_indices'] +) +boxes = np.array([[ + [0.0, 0.0, 1.0, 1.0], + [0.0, 0.1, 1.0, 1.1], + [0.0, -0.1, 1.0, 0.9], + [0.0, 10.0, 1.0, 11.0], + [0.0, 10.1, 1.0, 11.1], + [0.0, 100.0, 1.0, 101.0] +]]).astype(np.float32) +scores = np.array([[[0.9, 0.75, 0.6, 0.95, 0.5, 0.3], + [0.9, 0.75, 0.6, 0.95, 0.5, 0.3]]]).astype(np.float32) +max_output_boxes_per_class = np.array([2]).astype(np.int64) +iou_threshold = np.array([0.5]).astype(np.float32) +score_threshold = np.array([0.0]).astype(np.float32) +selected_indices = np.array([[0, 0, 3], [0, 0, 0], [0, 1, 3], [0, 1, 0]]).astype(np.int64) + +expect(node, inputs=[boxes, scores, max_output_boxes_per_class, iou_threshold, score_threshold], outputs=[selected_indices], name='test_nonmaxsuppression_two_classes') +``` + +
+ + +### **NonZero** + + Returns the indices of the elements that are non-zero + (in row-major order - by dimension). + NonZero behaves similar to numpy.nonzero: + https://docs.scipy.org/doc/numpy/reference/generated/numpy.nonzero.html + +#### Version + +This version of the operator has been available since version 13 of the default ONNX operator set. + +Other versions of this operator: 9 + +#### Inputs + +
+
X (non-differentiable) : T
+
input
+
+ +#### Outputs + +
+
Y (non-differentiable) : tensor(int64)
+
output
+
+ +#### Type Constraints + +
+
T : tensor(uint8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(int8), tensor(int16), tensor(int32), tensor(int64), tensor(bfloat16), tensor(float16), tensor(float), tensor(double), tensor(string), tensor(bool), tensor(complex64), tensor(complex128)
+
Constrain to all tensor types.
+
+ + +#### Examples + +
+nonzero + +```python +node = onnx.helper.make_node( + 'NonZero', + inputs=['condition'], + outputs=['result'], +) + +condition = np.array([[1, 0], [1, 1]], dtype=bool) +result = np.array(np.nonzero(condition), dtype=np.int64) # expected output [[0, 1, 1], [0, 0, 1]] +expect(node, inputs=[condition], outputs=[result], + name='test_nonzero_example') +``` + +
+ + +### **Not** + + Returns the negation of the input tensor element-wise. + +#### Version + +This version of the operator has been available since version 1 of the default ONNX operator set. + +#### Inputs + +
+
X (non-differentiable) : T
+
Input tensor
+
+ +#### Outputs + +
+
Y (non-differentiable) : T
+
Output tensor
+
+ +#### Type Constraints + +
+
T : tensor(bool)
+
Constrains input/output to boolean tensors.
+
+ + +#### Examples + +
+not + +```python +node = onnx.helper.make_node( + 'Not', + inputs=['x'], + outputs=['not'], +) + +# 2d +x = (np.random.randn(3, 4) > 0).astype(bool) +expect(node, inputs=[x], outputs=[np.logical_not(x)], + name='test_not_2d') + +# 3d +x = (np.random.randn(3, 4, 5) > 0).astype(bool) +expect(node, inputs=[x], outputs=[np.logical_not(x)], + name='test_not_3d') + +# 4d +x = (np.random.randn(3, 4, 5, 6) > 0).astype(bool) +expect(node, inputs=[x], outputs=[np.logical_not(x)], + name='test_not_4d') +``` + +
+ + +### **OneHot** + + Produces a one-hot tensor based on inputs. + The locations represented by the index values in the 'indices' input tensor will have 'on_value' + and the other locations will have 'off_value' in the output tensor, where 'on_value' and 'off_value' + are specified as part of required input argument 'values', which is a two-element tensor of format + [off_value, on_value]. The rank of the output tensor will be one greater than the rank of the + input tensor. The additional dimension is for one-hot representation. The additional dimension will + be inserted at the position specified by 'axis'. If 'axis' is not specified then then additional + dimension will be inserted as the innermost dimension, i.e. axis=-1. The size of the additional + dimension is specified by required scalar input 'depth'. The type of the output tensor is the same + as the type of the 'values' input. Any entries in the 'indices' input tensor with values outside + the range [-depth, depth-1] will result in one-hot representation with all 'off_value' values in the + output tensor. + + when axis = 0: + output[input[i, j, k], i, j, k] = 1 for all i, j, k and 0 otherwise. + + when axis = -1: + output[i, j, k, input[i, j, k]] = 1 for all i, j, k and 0 otherwise. + + +#### Version + +This version of the operator has been available since version 11 of the default ONNX operator set. + +Other versions of this operator: 9 + +#### Attributes + +
+
axis : int (default is -1)
+
(Optional) Axis along which one-hot representation in added. Default: axis=-1. axis=-1 means that the additional dimension will be inserted as the innermost/last dimension in the output tensor. Negative value means counting dimensions from the back. Accepted range is [-r-1, r] where r = rank(indices).
+
+ +#### Inputs + +
+
indices (non-differentiable) : T1
+
Input tensor containing indices. Any entries in the 'indices' input tensor with values outside the range [-depth, depth-1] will result in one-hot representation with all 'off_value' values in the output tensor.In case 'indices' is of non-integer type, the values will be casted to int64 before use.
+
depth (non-differentiable) : T2
+
Scalar specifying the number of classes in one-hot tensor. This is also the size of the one-hot dimension (specified by 'axis' attribute) added on in the output tensor. The values in the 'indices' input tensor are expected to be in the range [-depth, depth-1]. In case 'depth' is of non-integer type, it will be casted to int64 before use.
+
values (non-differentiable) : T3
+
Rank 1 tensor containing exactly two elements, in the format [off_value, on_value], where 'on_value' is the value used for filling locations specified in 'indices' input tensor, and 'off_value' is the value used for filling locations other than those specified in 'indices' input tensor.
+
+ +#### Outputs + +
+
output (non-differentiable) : T3
+
Tensor of rank one greater than input tensor 'indices', i.e. rank(output) = rank(indices) + 1. The data type for the elements of the output tensor is the same as the type of input 'values' is used.
+
+ +#### Type Constraints + +
+
T1 : tensor(uint8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(int8), tensor(int16), tensor(int32), tensor(int64), tensor(float16), tensor(float), tensor(double)
+
Constrains input to only numeric types.
+
T2 : tensor(uint8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(int8), tensor(int16), tensor(int32), tensor(int64), tensor(float16), tensor(float), tensor(double)
+
Constrains input to only numeric types.
+
T3 : tensor(uint8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(int8), tensor(int16), tensor(int32), tensor(int64), tensor(float16), tensor(float), tensor(double), tensor(string), tensor(bool), tensor(complex64), tensor(complex128)
+
Constrain to any tensor type.
+
+ + +#### Examples + +
+with_axis + +```python +axisValue = 1 +on_value = 3 +off_value = 1 +output_type = np.float32 +node = onnx.helper.make_node( + 'OneHot', + inputs=['indices', 'depth', 'values'], + outputs=['y'], + axis=axisValue +) +indices = np.array([[1, 9], + [2, 4]], dtype=np.float32) +depth = np.float32(10) +values = np.array([off_value, on_value], dtype=output_type) +y = one_hot(indices, depth, axis=axisValue, dtype=output_type) +y = y * (on_value - off_value) + off_value +expect(node, inputs=[indices, depth, values], outputs=[y], name='test_onehot_with_axis') +``` + +
+ + +
+with_negative_axis + +```python +axisValue = -2 +on_value = 3 +off_value = 1 +output_type = np.float32 +node = onnx.helper.make_node( + 'OneHot', + inputs=['indices', 'depth', 'values'], + outputs=['y'], + axis=axisValue +) +indices = np.array([[1, 9], + [2, 4]], dtype=np.float32) +depth = np.float32(10) +values = np.array([off_value, on_value], dtype=output_type) +y = one_hot(indices, depth, axis=axisValue, dtype=output_type) +y = y * (on_value - off_value) + off_value +expect(node, inputs=[indices, depth, values], outputs=[y], name='test_onehot_with_negative_axis') +``` + +
+ + +
+with_negative_indices + +```python +axisValue = 1 +on_value = 3 +off_value = 1 +output_type = np.float32 +node = onnx.helper.make_node( + 'OneHot', + inputs=['indices', 'depth', 'values'], + outputs=['y'], + axis=axisValue +) +indices = np.array([0, -7, -8], dtype=np.int64) + +# print(y) +# [[3. 1. 1. 1. 1. 1. 1. 1. 1. 1.] +# [1. 1. 1. 3. 1. 1. 1. 1. 1. 1.] +# [1. 1. 3. 1. 1. 1. 1. 1. 1. 1.]] + +depth = np.float32(10) +values = np.array([off_value, on_value], dtype=output_type) +y = one_hot(indices, depth, axis=axisValue, dtype=output_type) +y = y * (on_value - off_value) + off_value +expect(node, inputs=[indices, depth, values], outputs=[y], name='test_onehot_negative_indices') +``` + +
+ + +
+without_axis + +```python +on_value = 5 +off_value = 2 +output_type = np.int32 +node = onnx.helper.make_node( + 'OneHot', + inputs=['indices', 'depth', 'values'], + outputs=['y'] +) +indices = np.array([0, 7, 8], dtype=np.int64) +depth = np.float32(12) +values = np.array([off_value, on_value], dtype=output_type) +y = one_hot(indices, depth, dtype=output_type) +y = y * (on_value - off_value) + off_value +expect(node, inputs=[indices, depth, values], outputs=[y], name='test_onehot_without_axis') +``` + +
+ + +### **Optional** + + Constructs an optional-type value containing either an empty optional of a certain type specified by the attribute, + or a non-empty value containing the input element. + +#### Version + +This version of the operator has been available since version 15 of the default ONNX operator set. + +#### Attributes + +
+
type : type_proto
+
Type of the element in the optional output
+
+ +#### Inputs (0 - 1) + +
+
input (optional) : V
+
The input element.
+
+ +#### Outputs + +
+
output : O
+
The optional output enclosing the input element.
+
+ +#### Type Constraints + +
+
V : tensor(uint8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(int8), tensor(int16), tensor(int32), tensor(int64), tensor(float16), tensor(float), tensor(double), tensor(string), tensor(bool), tensor(complex64), tensor(complex128), seq(tensor(uint8)), seq(tensor(uint16)), seq(tensor(uint32)), seq(tensor(uint64)), seq(tensor(int8)), seq(tensor(int16)), seq(tensor(int32)), seq(tensor(int64)), seq(tensor(float16)), seq(tensor(float)), seq(tensor(double)), seq(tensor(string)), seq(tensor(bool)), seq(tensor(complex64)), seq(tensor(complex128))
+
Constrains input type to all tensor and sequence types.
+
O : optional(seq(tensor(uint8))), optional(seq(tensor(uint16))), optional(seq(tensor(uint32))), optional(seq(tensor(uint64))), optional(seq(tensor(int8))), optional(seq(tensor(int16))), optional(seq(tensor(int32))), optional(seq(tensor(int64))), optional(seq(tensor(float16))), optional(seq(tensor(float))), optional(seq(tensor(double))), optional(seq(tensor(string))), optional(seq(tensor(bool))), optional(seq(tensor(complex64))), optional(seq(tensor(complex128))), optional(tensor(uint8)), optional(tensor(uint16)), optional(tensor(uint32)), optional(tensor(uint64)), optional(tensor(int8)), optional(tensor(int16)), optional(tensor(int32)), optional(tensor(int64)), optional(tensor(float16)), optional(tensor(float)), optional(tensor(double)), optional(tensor(string)), optional(tensor(bool)), optional(tensor(complex64)), optional(tensor(complex128))
+
Constrains output type to all optional tensor or optional sequence types.
+
+ + +### **OptionalGetElement** + + Outputs the element in the optional-type input. It is an error if the input value does not have an element + and the behavior is undefined in this case. + +#### Version + +This version of the operator has been available since version 15 of the default ONNX operator set. + +#### Inputs + +
+
input : O
+
The optional input.
+
+ +#### Outputs + +
+
output : V
+
Output element in the optional input.
+
+ +#### Type Constraints + +
+
O : optional(seq(tensor(uint8))), optional(seq(tensor(uint16))), optional(seq(tensor(uint32))), optional(seq(tensor(uint64))), optional(seq(tensor(int8))), optional(seq(tensor(int16))), optional(seq(tensor(int32))), optional(seq(tensor(int64))), optional(seq(tensor(float16))), optional(seq(tensor(float))), optional(seq(tensor(double))), optional(seq(tensor(string))), optional(seq(tensor(bool))), optional(seq(tensor(complex64))), optional(seq(tensor(complex128))), optional(tensor(uint8)), optional(tensor(uint16)), optional(tensor(uint32)), optional(tensor(uint64)), optional(tensor(int8)), optional(tensor(int16)), optional(tensor(int32)), optional(tensor(int64)), optional(tensor(float16)), optional(tensor(float)), optional(tensor(double)), optional(tensor(string)), optional(tensor(bool)), optional(tensor(complex64)), optional(tensor(complex128))
+
Constrains input type to optional tensor and optional sequence types.
+
V : tensor(uint8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(int8), tensor(int16), tensor(int32), tensor(int64), tensor(float16), tensor(float), tensor(double), tensor(string), tensor(bool), tensor(complex64), tensor(complex128), seq(tensor(uint8)), seq(tensor(uint16)), seq(tensor(uint32)), seq(tensor(uint64)), seq(tensor(int8)), seq(tensor(int16)), seq(tensor(int32)), seq(tensor(int64)), seq(tensor(float16)), seq(tensor(float)), seq(tensor(double)), seq(tensor(string)), seq(tensor(bool)), seq(tensor(complex64)), seq(tensor(complex128))
+
Constrain output type to all tensor or sequence types.
+
+ + +### **OptionalHasElement** + + Returns true if the optional-type input contains an element. If it is an empty optional-type, this op returns false. + +#### Version + +This version of the operator has been available since version 15 of the default ONNX operator set. + +#### Inputs + +
+
input : O
+
The optional input.
+
+ +#### Outputs + +
+
output : B
+
A scalar boolean tensor. If true, it indicates that optional-type input contains an element. Otherwise, it is empty.
+
+ +#### Type Constraints + +
+
O : optional(seq(tensor(uint8))), optional(seq(tensor(uint16))), optional(seq(tensor(uint32))), optional(seq(tensor(uint64))), optional(seq(tensor(int8))), optional(seq(tensor(int16))), optional(seq(tensor(int32))), optional(seq(tensor(int64))), optional(seq(tensor(float16))), optional(seq(tensor(float))), optional(seq(tensor(double))), optional(seq(tensor(string))), optional(seq(tensor(bool))), optional(seq(tensor(complex64))), optional(seq(tensor(complex128))), optional(tensor(uint8)), optional(tensor(uint16)), optional(tensor(uint32)), optional(tensor(uint64)), optional(tensor(int8)), optional(tensor(int16)), optional(tensor(int32)), optional(tensor(int64)), optional(tensor(float16)), optional(tensor(float)), optional(tensor(double)), optional(tensor(string)), optional(tensor(bool)), optional(tensor(complex64)), optional(tensor(complex128))
+
Constrains input type to optional tensor and optional sequence types.
+
B : tensor(bool)
+
Constrains output to a boolean tensor.
+
+ + +#### Examples + +
+empty + +```python +optional = None +tensor_type_proto = onnx.helper.make_tensor_type_proto(elem_type=onnx.TensorProto.INT32, shape=[]) +input_type_proto = onnx.helper.make_optional_type_proto(tensor_type_proto) +node = onnx.helper.make_node( + 'OptionalHasElement', + inputs=['optional_input'], + outputs=['output'] +) +output = optional_has_element_reference_implementation(optional) +expect(node, inputs=[optional], outputs=[output], + input_type_protos=[input_type_proto], + name='test_optional_has_element_empty') +``` + +
+ + +
+get_element_sequence + +```python +optional = [np.array([1, 2, 3, 4]).astype(np.int32)] +tensor_type_proto = onnx.helper.make_tensor_type_proto(elem_type=onnx.TensorProto.INT32, shape=[4, ]) +seq_type_proto = onnx.helper.make_sequence_type_proto(tensor_type_proto) +input_type_proto = onnx.helper.make_optional_type_proto(seq_type_proto) + +node = onnx.helper.make_node( + 'OptionalGetElement', + inputs=['optional_input'], + outputs=['output'] +) +output = optional_get_element_reference_implementation(optional) +expect(node, inputs=[optional], outputs=[output], + input_type_protos=[input_type_proto], + name='test_optional_get_element_sequence') +``` + +
+ + +
+get_element_tensor + +```python +optional = np.array([1, 2, 3, 4]).astype(np.float32) +tensor_type_proto = onnx.helper.make_tensor_type_proto(elem_type=onnx.TensorProto.FLOAT, shape=[4, ]) +input_type_proto = onnx.helper.make_optional_type_proto(tensor_type_proto) + +node = onnx.helper.make_node( + 'OptionalGetElement', + inputs=['optional_input'], + outputs=['output'] +) +output = optional_get_element_reference_implementation(optional) +expect(node, inputs=[optional], outputs=[output], + input_type_protos=[input_type_proto], + name='test_optional_get_element') +``` + +
+ + +
+optionalhaselement + +```python +optional = np.array([1, 2, 3, 4]).astype(np.float32) +tensor_type_proto = onnx.helper.make_tensor_type_proto(elem_type=onnx.TensorProto.FLOAT, shape=[4, ]) +input_type_proto = onnx.helper.make_optional_type_proto(tensor_type_proto) +node = onnx.helper.make_node( + 'OptionalHasElement', + inputs=['optional_input'], + outputs=['output'] +) +output = optional_has_element_reference_implementation(optional) +expect(node, inputs=[optional], outputs=[output], + input_type_protos=[input_type_proto], + name='test_optional_has_element') +``` + +
+ + +### **Or** + + Returns the tensor resulted from performing the `or` logical operation + elementwise on the input tensors `A` and `B` (with Numpy-style broadcasting support). + + This operator supports **multidirectional (i.e., Numpy-style) broadcasting**; for more details please check [the doc](Broadcasting.md). + +#### Version + +This version of the operator has been available since version 7 of the default ONNX operator set. + +Other versions of this operator: 1 + +#### Inputs + +
+
A (non-differentiable) : T
+
First input operand for the logical operator.
+
B (non-differentiable) : T
+
Second input operand for the logical operator.
+
+ +#### Outputs + +
+
C (non-differentiable) : T1
+
Result tensor.
+
+ +#### Type Constraints + +
+
T : tensor(bool)
+
Constrains input to boolean tensor.
+
T1 : tensor(bool)
+
Constrains output to boolean tensor.
+
+ + +#### Examples + +
+or + +```python +node = onnx.helper.make_node( + 'Or', + inputs=['x', 'y'], + outputs=['or'], +) + +# 2d +x = (np.random.randn(3, 4) > 0).astype(bool) +y = (np.random.randn(3, 4) > 0).astype(bool) +z = np.logical_or(x, y) +expect(node, inputs=[x, y], outputs=[z], + name='test_or2d') + +# 3d +x = (np.random.randn(3, 4, 5) > 0).astype(bool) +y = (np.random.randn(3, 4, 5) > 0).astype(bool) +z = np.logical_or(x, y) +expect(node, inputs=[x, y], outputs=[z], + name='test_or3d') + +# 4d +x = (np.random.randn(3, 4, 5, 6) > 0).astype(bool) +y = (np.random.randn(3, 4, 5, 6) > 0).astype(bool) +z = np.logical_or(x, y) +expect(node, inputs=[x, y], outputs=[z], + name='test_or4d') +``` + +
+ + +
+or_broadcast + +```python +node = onnx.helper.make_node( + 'Or', + inputs=['x', 'y'], + outputs=['or'], +) + +# 3d vs 1d +x = (np.random.randn(3, 4, 5) > 0).astype(bool) +y = (np.random.randn(5) > 0).astype(bool) +z = np.logical_or(x, y) +expect(node, inputs=[x, y], outputs=[z], + name='test_or_bcast3v1d') + +# 3d vs 2d +x = (np.random.randn(3, 4, 5) > 0).astype(bool) +y = (np.random.randn(4, 5) > 0).astype(bool) +z = np.logical_or(x, y) +expect(node, inputs=[x, y], outputs=[z], + name='test_or_bcast3v2d') + +# 4d vs 2d +x = (np.random.randn(3, 4, 5, 6) > 0).astype(bool) +y = (np.random.randn(5, 6) > 0).astype(bool) +z = np.logical_or(x, y) +expect(node, inputs=[x, y], outputs=[z], + name='test_or_bcast4v2d') + +# 4d vs 3d +x = (np.random.randn(3, 4, 5, 6) > 0).astype(bool) +y = (np.random.randn(4, 5, 6) > 0).astype(bool) +z = np.logical_or(x, y) +expect(node, inputs=[x, y], outputs=[z], + name='test_or_bcast4v3d') + +# 4d vs 4d +x = (np.random.randn(1, 4, 1, 6) > 0).astype(bool) +y = (np.random.randn(3, 1, 5, 6) > 0).astype(bool) +z = np.logical_or(x, y) +expect(node, inputs=[x, y], outputs=[z], + name='test_or_bcast4v4d') +``` + +
+ + +### **PRelu** + + PRelu takes input data (Tensor) and slope tensor as input, and produces one + output data (Tensor) where the function `f(x) = slope * x for x < 0`, + `f(x) = x for x >= 0`., is applied to the data tensor elementwise. + This operator supports **unidirectional broadcasting** (tensor slope should be unidirectional broadcastable to input tensor X); for more details please check [the doc](Broadcasting.md). + +#### Version + +This version of the operator has been available since version 9 of the default ONNX operator set. + +Other versions of this operator: 1, 6, 7 + +#### Inputs + +
+
X (differentiable) : T
+
Input tensor
+
slope (differentiable) : T
+
Slope tensor. The shape of slope can be smaller then first input X; if so, its shape must be unidirectional broadcastable to X
+
+ +#### Outputs + +
+
Y (differentiable) : T
+
Output tensor (same size as X)
+
+ +#### Type Constraints + +
+
T : tensor(float16), tensor(float), tensor(double), tensor(uint32), tensor(uint64), tensor(int32), tensor(int64)
+
Constrain input and output types to float/int tensors.
+
+ + +#### Examples + +
+prelu + +```python +node = onnx.helper.make_node( + 'PRelu', + inputs=['x', 'slope'], + outputs=['y'], +) + +x = np.random.randn(3, 4, 5).astype(np.float32) +slope = np.random.randn(3, 4, 5).astype(np.float32) +y = np.clip(x, 0, np.inf) + np.clip(x, -np.inf, 0) * slope + +expect(node, inputs=[x, slope], outputs=[y], + name='test_prelu_example') +``` + +
+ + +
+prelu_broadcast + +```python +node = onnx.helper.make_node( + 'PRelu', + inputs=['x', 'slope'], + outputs=['y'], +) + +x = np.random.randn(3, 4, 5).astype(np.float32) +slope = np.random.randn(5).astype(np.float32) +y = np.clip(x, 0, np.inf) + np.clip(x, -np.inf, 0) * slope + +expect(node, inputs=[x, slope], outputs=[y], + name='test_prelu_broadcast') +``` + +
+ + +### **Pad** + + Given a tensor containing the data to be padded (`data`), a tensor containing the number of start and end pad values for axis (`pads`), (optionally) a `mode`, and (optionally) `constant_value`, + a padded tensor (`output`) is generated. + + The three supported `modes` are (similar to corresponding modes supported by `numpy.pad`): + + 1) `constant`(default) - pads with a given constant value as specified by `constant_value` (which defaults to 0, empty string, or False) + + 2) `reflect` - pads with the reflection of the vector mirrored on the first and last values of the vector along each axis + + 3) `edge` - pads with the edge values of array + + + Example 1 (`constant` mode): + Insert 0 pads to the beginning of the second dimension. + + data = + [ + [1.0, 1.2], + [2.3, 3.4], + [4.5, 5.7], + ] + + pads = [0, 2, 0, 0] + + mode = 'constant' + + constant_value = 0.0 + + output = + [ + [0.0, 0.0, 1.0, 1.2], + [0.0, 0.0, 2.3, 3.4], + [0.0, 0.0, 4.5, 5.7], + ] + + + Example 2 (`reflect` mode): + data = + [ + [1.0, 1.2], + [2.3, 3.4], + [4.5, 5.7], + ] + + pads = [0, 2, 0, 0] + + mode = 'reflect' + + output = + [ + [1.0, 1.2, 1.0, 1.2], + [2.3, 3.4, 2.3, 3.4], + [4.5, 5.7, 4.5, 5.7], + ] + + + Example 3 (`edge` mode): + data = + [ + [1.0, 1.2], + [2.3, 3.4], + [4.5, 5.7], + ] + + pads = [0, 2, 0, 0] + + mode = 'edge' + + output = + [ + [1.0, 1.0, 1.0, 1.2], + [2.3, 2.3, 2.3, 3.4], + [4.5, 4.5, 4.5, 5.7], + ] + + +#### Version + +This version of the operator has been available since version 13 of the default ONNX operator set. + +Other versions of this operator: 1, 2, 11 + +#### Attributes + +
+
mode : string (default is constant)
+
Supported modes: `constant`(default), `reflect`, `edge`
+
+ +#### Inputs (2 - 3) + +
+
data (differentiable) : T
+
Input tensor.
+
pads (non-differentiable) : tensor(int64)
+
Tensor of integers indicating the number of padding elements to add or remove (if negative) at the beginning and end of each axis. For 2D input tensor, it is the number of pixels. `pads` should be a 1D tensor of shape [2 * input_rank]. `pads` format should be: [x1_begin, x2_begin,...,x1_end, x2_end,...], where xi_begin is the number of pad values added at the beginning of axis `i` and xi_end, the number of pad values added at the end of axis `i`.
+
constant_value (optional, non-differentiable) : T
+
(Optional) A scalar value to be used if the mode chosen is `constant` (by default it is 0, empty string or False).
+
+ +#### Outputs + +
+
output (differentiable) : T
+
Tensor after padding.
+
+ +#### Type Constraints + +
+
T : tensor(uint8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(int8), tensor(int16), tensor(int32), tensor(int64), tensor(bfloat16), tensor(float16), tensor(float), tensor(double), tensor(string), tensor(bool), tensor(complex64), tensor(complex128)
+
Constrain input and output types to all tensor types.
+
+ + +#### Examples + +
+constant_pad + +```python +node = onnx.helper.make_node( + 'Pad', + inputs=['x', 'pads', 'value'], + outputs=['y'], + mode='constant' +) +x = np.random.randn(1, 3, 4, 5).astype(np.float32) +pads = np.array([0, 0, 1, 3, 0, 0, 2, 4]).astype(np.int64) # pad order [x1_begin, x2_begin, ..., x1_end, x2_end, ...] +value = np.float32(1.2) +y = pad_impl( + x, + pads, + 'constant', + 1.2 +) + +expect(node, inputs=[x, pads, value], outputs=[y], + name='test_constant_pad') +``` + +
+ + +
+reflection_and_edge_pad + +```python +for mode in ['edge', 'reflect']: + node = onnx.helper.make_node( + 'Pad', + inputs=['x', 'pads'], + outputs=['y'], + mode=mode + ) + x = np.random.randn(1, 3, 4, 5).astype(np.int32) + pads = np.array([0, 0, 1, 1, 0, 0, 1, 1]).astype(np.int64) # pad order [x1_begin, x2_begin, ..., x1_end, x2_end, ...] + y = pad_impl( + x, + pads, + mode + ) + + expect(node, inputs=[x, pads], outputs=[y], + name='test_{}_pad'.format(mode)) +``` + +
+ + +### **Pow** + + Pow takes input data (Tensor) and exponent Tensor, and + produces one output data (Tensor) where the function `f(x) = x^exponent`, + is applied to the data tensor elementwise. + This operator supports **multidirectional (i.e., Numpy-style) broadcasting**; for more details please check [the doc](Broadcasting.md). + +#### Version + +This version of the operator has been available since version 15 of the default ONNX operator set. + +Other versions of this operator: 1, 7, 12, 13 + +#### Inputs + +
+
X (differentiable) : T
+
First operand, base of the exponent.
+
Y (differentiable) : T1
+
Second operand, power of the exponent.
+
+ +#### Outputs + +
+
Z (differentiable) : T
+
Output tensor
+
+ +#### Type Constraints + +
+
T : tensor(int32), tensor(int64), tensor(float16), tensor(float), tensor(double), tensor(bfloat16)
+
Constrain input X and output types to float/int tensors.
+
T1 : tensor(uint8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(int8), tensor(int16), tensor(int32), tensor(int64), tensor(float16), tensor(float), tensor(double), tensor(bfloat16)
+
Constrain input Y types to float/int tensors.
+
+ + +#### Examples + +
+pow + +```python +node = onnx.helper.make_node( + 'Pow', + inputs=['x', 'y'], + outputs=['z'], +) + +x = np.array([1, 2, 3]).astype(np.float32) +y = np.array([4, 5, 6]).astype(np.float32) +z = pow(x, y) # expected output [1., 32., 729.] +expect(node, inputs=[x, y], outputs=[z], + name='test_pow_example') + +x = np.arange(60).reshape(3, 4, 5).astype(np.float32) +y = np.random.randn(3, 4, 5).astype(np.float32) +z = pow(x, y) +expect(node, inputs=[x, y], outputs=[z], + name='test_pow') +``` + +
+ + +
+pow_broadcast + +```python +node = onnx.helper.make_node( + 'Pow', + inputs=['x', 'y'], + outputs=['z'], +) + +x = np.array([1, 2, 3]).astype(np.float32) +y = np.array(2).astype(np.float32) +z = pow(x, y) # expected output [1., 4., 9.] +expect(node, inputs=[x, y], outputs=[z], + name='test_pow_bcast_scalar') + +node = onnx.helper.make_node( + 'Pow', + inputs=['x', 'y'], + outputs=['z'], +) +x = np.array([[1, 2, 3], [4, 5, 6]]).astype(np.float32) +y = np.array([1, 2, 3]).astype(np.float32) +# expected output [[1, 4, 27], [4, 25, 216]] +z = pow(x, y) +expect(node, inputs=[x, y], outputs=[z], + name='test_pow_bcast_array') +``` + +
+ + +
+types + +```python +node = onnx.helper.make_node( + 'Pow', + inputs=['x', 'y'], + outputs=['z'], +) + +x = np.array([1, 2, 3]).astype(np.float32) +y = np.array([4, 5, 6]).astype(np.int64) +z = pow(x, y) # expected output [1., 32., 729.] +expect(node, inputs=[x, y], outputs=[z], + name='test_pow_types_float32_int64') + +x = np.array([1, 2, 3]).astype(np.int64) +y = np.array([4, 5, 6]).astype(np.float32) +z = pow(x, y) # expected output [1, 32, 729] +expect(node, inputs=[x, y], outputs=[z], + name='test_pow_types_int64_float32') + +x = np.array([1, 2, 3]).astype(np.float32) +y = np.array([4, 5, 6]).astype(np.int32) +z = pow(x, y) # expected output [1., 32., 729.] +expect(node, inputs=[x, y], outputs=[z], + name='test_pow_types_float32_int32') + +x = np.array([1, 2, 3]).astype(np.int32) +y = np.array([4, 5, 6]).astype(np.float32) +z = pow(x, y) # expected output [1, 32, 729] +expect(node, inputs=[x, y], outputs=[z], + name='test_pow_types_int32_float32') + +x = np.array([1, 2, 3]).astype(np.float32) +y = np.array([4, 5, 6]).astype(np.uint64) +z = pow(x, y) # expected output [1., 32., 729.] +expect(node, inputs=[x, y], outputs=[z], + name='test_pow_types_float32_uint64') + +x = np.array([1, 2, 3]).astype(np.float32) +y = np.array([4, 5, 6]).astype(np.uint32) +z = pow(x, y) # expected output [1., 32., 729.] +expect(node, inputs=[x, y], outputs=[z], + name='test_pow_types_float32_uint32') + +x = np.array([1, 2, 3]).astype(np.int64) +y = np.array([4, 5, 6]).astype(np.int64) +z = pow(x, y) # expected output [1, 32, 729] +expect(node, inputs=[x, y], outputs=[z], + name='test_pow_types_int64_int64') + +x = np.array([1, 2, 3]).astype(np.int32) +y = np.array([4, 5, 6]).astype(np.int32) +z = pow(x, y) # expected output [1, 32, 729] +expect(node, inputs=[x, y], outputs=[z], + name='test_pow_types_int32_int32') +``` + +
+ + +### **QLinearConv** + + The convolution operator consumes a quantized input tensor, its scale and zero point, + a quantized filter, its scale and zero point, and output's scale and zero point, + and computes the quantized output. Each scale and zero-point pair must have same shape. + It means they must be either scalars (per tensor) or 1-D tensors (per output channel). + Each input or output and its related zero point must have same type. + When bias is present it must be quantized using scale = input scale * weight scale and + zero point as 0. + +#### Version + +This version of the operator has been available since version 10 of the default ONNX operator set. + +#### Attributes + +
+
auto_pad : string (default is NOTSET)
+
auto_pad must be either NOTSET, SAME_UPPER, SAME_LOWER or VALID. Where default value is NOTSET, which means explicit padding is used. SAME_UPPER or SAME_LOWER mean pad the input so that `output_shape[i] = ceil(input_shape[i] / strides[i])` for each axis `i`. The padding is split between the two sides equally or almost equally (depending on whether it is even or odd). In case the padding is an odd number, the extra padding is added at the end for SAME_UPPER and at the beginning for SAME_LOWER.
+
dilations : list of ints
+
dilation value along each spatial axis of the filter. If not present, the dilation defaults to 1 along each spatial axis.
+
group : int (default is 1)
+
number of groups input channels and output channels are divided into. default is 1.
+
kernel_shape : list of ints
+
The shape of the convolution kernel. If not present, should be inferred from input 'w'.
+
pads : list of ints
+
Padding for the beginning and ending along each spatial axis, it can take any value greater than or equal to 0.The value represent the number of pixels added to the beginning and end part of the corresponding axis.`pads` format should be as follow [x1_begin, x2_begin...x1_end, x2_end,...], where xi_begin the number ofpixels added at the beginning of axis `i` and xi_end, the number of pixels added at the end of axis `i`.This attribute cannot be used simultaneously with auto_pad attribute. If not present, the padding defaultsto 0 along start and end of each spatial axis.
+
strides : list of ints
+
Stride along each spatial axis. If not present, the stride defaults to 1 along each spatial axis.
+
+ +#### Inputs (8 - 9) + +
+
x : T1
+
Input data tensor from previous layer; has size (N x C x H x W), where N is the batch size, C is the number of channels, and H and W are the height and width. Note that this is for the 2D image. Otherwise the size is (N x C x D1 x D2 ... x Dn). Optionally, if dimension denotation is in effect, the operation expects input data tensor to arrive with the dimension denotation of [DATA_BATCH, DATA_CHANNEL, DATA_FEATURE, DATA_FEATURE ...].
+
x_scale : tensor(float)
+
Scale tensor for input 'x'. It's a scalar, which means a per-tensor/layer quantization.
+
x_zero_point : T1
+
Zero point tensor for input 'x'. It's a scalar, which means a per-tensor/layer quantization.
+
w : T2
+
The weight tensor that will be used in the convolutions; has size (M x C/group x kH x kW), where C is the number of channels, and kH and kW are the height and width of the kernel, and M is the number of feature maps. For more than 2 dimensions, the kernel shape will be (M x C/group x k1 x k2 x ... x kn), where (k1 x k2 x ... kn) is the dimension of the kernel. Optionally, if dimension denotation is in effect, the operation expects the weight tensor to arrive with the dimension denotation of [FILTER_OUT_CHANNEL, FILTER_IN_CHANNEL, FILTER_SPATIAL, FILTER_SPATIAL ...]. X.shape[1] == (W.shape[1] * group) == C (assuming zero based indices for the shape array). Or in other words FILTER_IN_CHANNEL should be equal to DATA_CHANNEL.
+
w_scale : tensor(float)
+
Scale tensor for input 'w'. It could be a scalar or a 1-D tensor, which means a per-tensor/layer or per output channel quantization. If it's a 1-D tensor, its number of elements should be equal to the number of output channels (M).
+
w_zero_point : T2
+
Zero point tensor for input 'w'. It could be a scalar or a 1-D tensor, which means a per-tensor/layer or per output channel quantization. If it's a 1-D tensor, its number of elements should be equal to the number of output channels (M).
+
y_scale : tensor(float)
+
Scale tensor for output 'y'. It's a scalar, which means a per-tensor/layer quantization.
+
y_zero_point : T3
+
Zero point tensor for output 'y'. It's a scalar, which means a per-tensor/layer quantization.
+
B (optional) : T4
+
Optional 1D bias to be added to the convolution, has size of M. Bias must be quantized using scale = x_scale * w_scale and zero_point = 0
+
+ +#### Outputs + +
+
y : T3
+
Output data tensor that contains the result of the convolution. The output dimensions are functions of the kernel size, stride size, and pad lengths.
+
+ +#### Type Constraints + +
+
T1 : tensor(int8), tensor(uint8)
+
Constrain input type to 8-bit integer tensor.
+
T2 : tensor(int8), tensor(uint8)
+
Constrain filter type to 8-bit integer tensor.
+
T3 : tensor(int8), tensor(uint8)
+
Constrain output type to 8-bit integer tensor.
+
T4 : tensor(int32)
+
Constrain bias type to 32-bit integer tensor.
+
+ + +#### Examples + +
+qlinearconv + +```python +node = onnx.helper.make_node('QLinearConv', + inputs=['x', 'x_scale', 'x_zero_point', 'w', 'w_scale', 'w_zero_point', 'y_scale', 'y_zero_point'], + outputs=['y'],) + +x = np.array([[255, 174, 162, 25, 203, 168, 58], + [15, 59, 237, 95, 129, 0, 64], + [56, 242, 153, 221, 168, 12, 166], + [232, 178, 186, 195, 237, 162, 237], + [188, 39, 124, 77, 80, 102, 43], + [127, 230, 21, 83, 41, 40, 134], + [255, 154, 92, 141, 42, 148, 247], ], dtype=np.uint8).reshape((1, 1, 7, 7)) + +x_scale = np.float32(0.00369204697) +x_zero_point = np.uint8(132) + +w = np.array([0], dtype=np.uint8).reshape((1, 1, 1, 1)) + +w_scale = np.array([0.00172794575], dtype=np.float32) +w_zero_point = np.array([255], dtype=np.uint8) + +y_scale = np.float32(0.00162681262) +y_zero_point = np.uint8(123) + +output = np.array([[0, 81, 93, 230, 52, 87, 197], + [240, 196, 18, 160, 126, 255, 191], + [199, 13, 102, 34, 87, 243, 89], + [23, 77, 69, 60, 18, 93, 18], + [67, 216, 131, 178, 175, 153, 212], + [128, 25, 234, 172, 214, 215, 121], + [0, 101, 163, 114, 213, 107, 8], ], dtype=np.uint8).reshape((1, 1, 7, 7)) + +expect(node, inputs=[x, x_scale, x_zero_point, w, w_scale, w_zero_point, y_scale, y_zero_point], outputs=[output], + name='test_qlinearconv') +``` + +
+ + +### **QLinearMatMul** + + Matrix product that behaves like numpy.matmul: https://docs.scipy.org/doc/numpy-1.13.0/reference/generated/numpy.matmul.html. + It consumes two quantized input tensors, their scales and zero points, scale and zero point of output, + and computes the quantized output. The quantization formula is y = saturate((x / y_scale) + y_zero_point). + For (x / y_scale), it is rounding to nearest ties to even. Refer to https://en.wikipedia.org/wiki/Rounding for details. + Scale and zero point must have same shape. They must be either scalar (per tensor) or N-D tensor + (per row for 'a' and per column for 'b'). Scalar refers to per tensor quantization whereas N-D refers to per row + or per column quantization. If the input is 2D of shape [M, K] then zero point and scale tensor may be + an M element vector [v_1, v_2, ..., v_M] for per row quantization and K element vector of shape [v_1, v_2, ..., v_K] + for per column quantization. If the input is N-D tensor with shape [D1, D2, M, K] then zero point and scale tensor may + have shape [D1, D2, M, 1] for per row quantization and shape [D1, D2, 1, K] for per column quantization. + Production must never overflow, and accumulation may overflow if and only if in 32 bits. + +#### Version + +This version of the operator has been available since version 10 of the default ONNX operator set. + +#### Inputs + +
+
a (non-differentiable) : T1
+
N-dimensional quantized matrix a
+
a_scale (non-differentiable) : tensor(float)
+
scale of quantized input a
+
a_zero_point (non-differentiable) : T1
+
zero point of quantized input a
+
b (non-differentiable) : T2
+
N-dimensional quantized matrix b
+
b_scale (non-differentiable) : tensor(float)
+
scale of quantized input b
+
b_zero_point (non-differentiable) : T2
+
zero point of quantized input b
+
y_scale (non-differentiable) : tensor(float)
+
scale of quantized output y
+
y_zero_point (non-differentiable) : T3
+
zero point of quantized output y
+
+ +#### Outputs + +
+
y (non-differentiable) : T3
+
Quantized matrix multiply results from a * b
+
+ +#### Type Constraints + +
+
T1 : tensor(int8), tensor(uint8)
+
Constrain input a and its zero point data type to 8-bit integer tensor.
+
T2 : tensor(int8), tensor(uint8)
+
Constrain input b and its zero point data type to 8-bit integer tensor.
+
T3 : tensor(int8), tensor(uint8)
+
Constrain output y and its zero point data type to 8-bit integer tensor.
+
+ + +#### Examples + +
+qlinearmatmul + +```python +node = onnx.helper.make_node('QLinearMatMul', + inputs=['a', 'a_scale', 'a_zero_point', 'b', 'b_scale', 'b_zero_point', 'y_scale', 'y_zero_point'], + outputs=['y'],) + +#2D +a = np.array([[208, 236, 0, 238], + [3, 214, 255, 29], ], dtype=np.uint8) + +a_scale = np.array([0.0066], dtype=np.float32) +a_zero_point = np.array([113], dtype=np.uint8) + +b = np.array([[152, 51, 244], + [60, 26, 255], + [0, 127, 246], + [127, 254, 247]], dtype=np.uint8) + +b_scale = np.array([0.00705], dtype=np.float32) +b_zero_point = np.array([114], dtype=np.uint8) + +y_scale = np.array([0.0107], dtype=np.float32) +y_zero_point = np.array([118], dtype=np.uint8) + +output = np.array([[168, 115, 255], + [1, 66, 151], ], dtype=np.uint8) + +expect(node, inputs=[a, a_scale, a_zero_point, b, b_scale, b_zero_point, y_scale, y_zero_point], outputs=[output], + name='test_qlinearmatmul_2D') + +#3D +a = np.array([[[208, 236, 0, 238], + [3, 214, 255, 29]], + [[208, 236, 0, 238], + [3, 214, 255, 29]]], dtype=np.uint8) + +a_scale = np.array([0.0066], dtype=np.float32) +a_zero_point = np.array([113], dtype=np.uint8) + +b = np.array([[[152, 51, 244], + [60, 26, 255], + [0, 127, 246], + [127, 254, 247]], + [[152, 51, 244], + [60, 26, 255], + [0, 127, 246], + [127, 254, 247]]], dtype=np.uint8) + +b_scale = np.array([0.00705], dtype=np.float32) +b_zero_point = np.array([114], dtype=np.uint8) + +y_scale = np.array([0.0107], dtype=np.float32) +y_zero_point = np.array([118], dtype=np.uint8) + +output = np.array([[[168, 115, 255], + [1, 66, 151]], + [[168, 115, 255], + [1, 66, 151]]], dtype=np.uint8) + +expect(node, inputs=[a, a_scale, a_zero_point, b, b_scale, b_zero_point, y_scale, y_zero_point], outputs=[output], + name='test_qlinearmatmul_3D') +``` + +
+ + +### **QuantizeLinear** + + The linear quantization operator. It consumes a high precision tensor, a scale, and a zero point to compute the low precision / quantized tensor. + The scale factor and zero point must have same shape, and can be either a scalar for per-tensor / per layer quantization, or a 1-D tensor for per-axis quantization. + The quantization formula is y = saturate ((x / y_scale) + y_zero_point). + For saturation, it saturates to [0, 255] if it's uint8, or [-128, 127] if it's int8. + For (x / y_scale), it's rounding to nearest ties to even. Refer to https://en.wikipedia.org/wiki/Rounding for details. 'y_zero_point' and 'y' must have same type. + +#### Version + +This version of the operator has been available since version 13 of the default ONNX operator set. + +Other versions of this operator: 10 + +#### Attributes + +
+
axis : int (default is 1)
+
(Optional) The axis of the quantization dimension of the input tensor. Ignored for per-tensor quantization. Negative value means counting dimensions from the back. Accepted range is [-r, r-1] where r = rank(input).
+
+ +#### Inputs (2 - 3) + +
+
x : T1
+
N-D full precision Input tensor to be quantized.
+
y_scale : tensor(float)
+
Scale for doing quantization to get 'y'. It can be a scalar, which means per-tensor/layer quantization, or a 1-D Tensor for per-axis quantization.
+
y_zero_point (optional) : T2
+
Zero point for doing quantization to get 'y'. Shape must match y_scale. Default is uint8 with zero point of 0 if it's not specified.
+
+ +#### Outputs + +
+
y : T2
+
N-D quantized output tensor. It has same shape as input 'x'.
+
+ +#### Type Constraints + +
+
T1 : tensor(float), tensor(int32)
+
Constrain 'x' to float or int32 tensor.
+
T2 : tensor(int8), tensor(uint8)
+
Constrain 'y_zero_point' and 'y' to 8-bit integer tensor.
+
+ + +#### Examples + +
+axis + +```python +node = onnx.helper.make_node('QuantizeLinear', + inputs=['x', 'y_scale', 'y_zero_point'], + outputs=['y'],) + +x = np.array([[[[-162, 10], + [-100, 232], + [-20, -50]], + + [[-76, 0], + [0, 252], + [32, -44]], + + [[245, -485], + [-960, -270], + [-375, -470]], ], ], dtype=np.float32) +y_scale = np.array([2, 4, 5], dtype=np.float32) +y_zero_point = np.array([84, 24, 196], dtype=np.uint8) +y = (x / y_scale.reshape(1, 3, 1, 1) + y_zero_point.reshape(1, 3, 1, 1)).astype(np.uint8) + +expect(node, inputs=[x, y_scale, y_zero_point], outputs=[y], + name='test_quantizelinear_axis') +``` + +
+ + +
+quantizelinear + +```python +node = onnx.helper.make_node('QuantizeLinear', + inputs=['x', 'y_scale', 'y_zero_point'], + outputs=['y'],) + +x = np.array([0, 2, 3, 1000, -254, -1000]).astype(np.float32) +y_scale = np.float32(2) +y_zero_point = np.uint8(128) +y = np.array([128, 129, 130, 255, 1, 0]).astype(np.uint8) + +expect(node, inputs=[x, y_scale, y_zero_point], outputs=[y], + name='test_quantizelinear') +``` + +
+ + +### **RNN** + + Computes an one-layer simple RNN. This operator is usually supported + via some custom implementation such as CuDNN. + + Notations: + + `X` - input tensor + + `i` - input gate + + `t` - time step (t-1 means previous time step) + + `Wi` - W parameter weight matrix for input gate + + `Ri` - R recurrence weight matrix for input gate + + `Wbi` - W parameter bias vector for input gate + + `Rbi` - R parameter bias vector for input gate + + `WBi` - W parameter weight matrix for backward input gate + + `RBi` - R recurrence weight matrix for backward input gate + + `WBbi` - WR bias vectors for backward input gate + + `RBbi` - RR bias vectors for backward input gate + + `H` - Hidden state + + `num_directions` - 2 if direction == bidirectional else 1 + + Activation functions: + + Relu(x) - max(0, x) + + Tanh(x) - (1 - e^{-2x})/(1 + e^{-2x}) + + Sigmoid(x) - 1/(1 + e^{-x}) + + (NOTE: Below are optional) + + Affine(x) - alpha*x + beta + + LeakyRelu(x) - x if x >= 0 else alpha * x + + ThresholdedRelu(x) - x if x >= alpha else 0 + + ScaledTanh(x) - alpha*Tanh(beta*x) + + HardSigmoid(x) - min(max(alpha*x + beta, 0), 1) + + Elu(x) - x if x >= 0 else alpha*(e^x - 1) + + Softsign(x) - x/(1 + |x|) + + Softplus(x) - log(1 + e^x) + + Equations (Default: f=Tanh): + + - Ht = f(Xt*(Wi^T) + Ht-1*(Ri^T) + Wbi + Rbi) + This operator has **optional** inputs/outputs. See [the doc](IR.md) for more details about the representation of optional arguments. An empty string may be used in the place of an actual argument's name to indicate a missing argument. Trailing optional arguments (those not followed by an argument that is present) may also be simply omitted. + +#### Version + +This version of the operator has been available since version 14 of the default ONNX operator set. + +Other versions of this operator: 1, 7 + +#### Attributes + +
+
activation_alpha : list of floats
+
Optional scaling values used by some activation functions. The values are consumed in the order of activation functions, for example (f, g, h) in LSTM. Default values are the same as of corresponding ONNX operators.For example with LeakyRelu, the default alpha is 0.01.
+
activation_beta : list of floats
+
Optional scaling values used by some activation functions. The values are consumed in the order of activation functions, for example (f, g, h) in LSTM. Default values are the same as of corresponding ONNX operators.
+
activations : list of strings (default is ['Tanh', 'Tanh'])
+
One (or two if bidirectional) activation function for input gate. The activation function must be one of the activation functions specified above. Optional: Default `Tanh` if not specified.
+
clip : float
+
Cell clip threshold. Clipping bounds the elements of a tensor in the range of [-threshold, +threshold] and is applied to the input of activations. No clip if not specified.
+
direction : string (default is forward)
+
Specify if the RNN is forward, reverse, or bidirectional. Must be one of forward (default), reverse, or bidirectional.
+
hidden_size : int
+
Number of neurons in the hidden layer
+
layout : int (default is 0)
+
The shape format of inputs X, initial_h and outputs Y, Y_h. If 0, the following shapes are expected: X.shape = [seq_length, batch_size, input_size], Y.shape = [seq_length, num_directions, batch_size, hidden_size], initial_h.shape = Y_h.shape = [num_directions, batch_size, hidden_size]. If 1, the following shapes are expected: X.shape = [batch_size, seq_length, input_size], Y.shape = [batch_size, seq_length, num_directions, hidden_size], initial_h.shape = Y_h.shape = [batch_size, num_directions, hidden_size].
+
+ +#### Inputs (3 - 6) + +
+
X (differentiable) : T
+
The input sequences packed (and potentially padded) into one 3-D tensor with the shape of `[seq_length, batch_size, input_size]`.
+
W (differentiable) : T
+
The weight tensor for input gate. Concatenation of `Wi` and `WBi` (if bidirectional). The tensor has shape `[num_directions, hidden_size, input_size]`.
+
R (differentiable) : T
+
The recurrence weight tensor. Concatenation of `Ri` and `RBi` (if bidirectional). The tensor has shape `[num_directions, hidden_size, hidden_size]`.
+
B (optional, differentiable) : T
+
The bias tensor for input gate. Concatenation of `[Wbi, Rbi]` and `[WBbi, RBbi]` (if bidirectional). The tensor has shape `[num_directions, 2*hidden_size]`. Optional: If not specified - assumed to be 0.
+
sequence_lens (optional, non-differentiable) : T1
+
Optional tensor specifying lengths of the sequences in a batch. If not specified - assumed all sequences in the batch to have length `seq_length`. It has shape `[batch_size]`.
+
initial_h (optional, non-differentiable) : T
+
Optional initial value of the hidden. If not specified - assumed to be 0. It has shape `[num_directions, batch_size, hidden_size]`.
+
+ +#### Outputs (0 - 2) + +
+
Y (optional, differentiable) : T
+
A tensor that concats all the intermediate output values of the hidden. It has shape `[seq_length, num_directions, batch_size, hidden_size]`.
+
Y_h (optional, differentiable) : T
+
The last output value of the hidden. It has shape `[num_directions, batch_size, hidden_size]`.
+
+ +#### Type Constraints + +
+
T : tensor(float16), tensor(float), tensor(double)
+
Constrain input and output types to float tensors.
+
T1 : tensor(int32)
+
Constrain seq_lens to integer tensor.
+
+ + +#### Examples + +
+batchwise + +```python +input = np.array([[[1., 2.]], [[3., 4.]], [[5., 6.]]]).astype(np.float32) + +input_size = 2 +hidden_size = 4 +weight_scale = 0.5 +layout = 1 + +node = onnx.helper.make_node( + 'RNN', + inputs=['X', 'W', 'R'], + outputs=['Y', 'Y_h'], + hidden_size=hidden_size, + layout=layout +) + +W = weight_scale * np.ones((1, hidden_size, input_size)).astype(np.float32) +R = weight_scale * np.ones((1, hidden_size, hidden_size)).astype(np.float32) + +rnn = RNN_Helper(X=input, W=W, R=R, layout=layout) +Y, Y_h = rnn.step() +expect(node, inputs=[input, W, R], outputs=[Y.astype(np.float32), Y_h.astype(np.float32)], name='test_simple_rnn_batchwise') +``` + +
+ + +
+defaults + +```python +input = np.array([[[1., 2.], [3., 4.], [5., 6.]]]).astype(np.float32) + +input_size = 2 +hidden_size = 4 +weight_scale = 0.1 + +node = onnx.helper.make_node( + 'RNN', + inputs=['X', 'W', 'R'], + outputs=['', 'Y_h'], + hidden_size=hidden_size +) + +W = weight_scale * np.ones((1, hidden_size, input_size)).astype(np.float32) +R = weight_scale * np.ones((1, hidden_size, hidden_size)).astype(np.float32) + +rnn = RNN_Helper(X=input, W=W, R=R) +_, Y_h = rnn.step() +expect(node, inputs=[input, W, R], outputs=[Y_h.astype(np.float32)], name='test_simple_rnn_defaults') +``` + +
+ + +
+initial_bias + +```python +input = np.array([[[1., 2., 3.], [4., 5., 6.], [7., 8., 9.]]]).astype(np.float32) + +input_size = 3 +hidden_size = 5 +custom_bias = 0.1 +weight_scale = 0.1 + +node = onnx.helper.make_node( + 'RNN', + inputs=['X', 'W', 'R', 'B'], + outputs=['', 'Y_h'], + hidden_size=hidden_size +) + +W = weight_scale * np.ones((1, hidden_size, input_size)).astype(np.float32) +R = weight_scale * np.ones((1, hidden_size, hidden_size)).astype(np.float32) + +# Adding custom bias +W_B = custom_bias * np.ones((1, hidden_size)).astype(np.float32) +R_B = np.zeros((1, hidden_size)).astype(np.float32) +B = np.concatenate((W_B, R_B), axis=1) + +rnn = RNN_Helper(X=input, W=W, R=R, B=B) +_, Y_h = rnn.step() +expect(node, inputs=[input, W, R, B], outputs=[Y_h.astype(np.float32)], + name='test_simple_rnn_with_initial_bias') +``` + +
+ + +
+seq_length + +```python +input = np.array([[[1., 2., 3.], [4., 5., 6.], [7., 8., 9.]], + [[10., 11., 12.], [13., 14., 15.], [16., 17., 18.]]]).astype(np.float32) + +input_size = 3 +hidden_size = 5 + +node = onnx.helper.make_node( + 'RNN', + inputs=['X', 'W', 'R', 'B'], + outputs=['', 'Y_h'], + hidden_size=hidden_size +) + +W = np.random.randn(1, hidden_size, input_size).astype(np.float32) +R = np.random.randn(1, hidden_size, hidden_size).astype(np.float32) + +# Adding custom bias +W_B = np.random.randn(1, hidden_size).astype(np.float32) +R_B = np.random.randn(1, hidden_size).astype(np.float32) +B = np.concatenate((W_B, R_B), axis=1) + +rnn = RNN_Helper(X=input, W=W, R=R, B=B) +_, Y_h = rnn.step() +expect(node, inputs=[input, W, R, B], outputs=[Y_h.astype(np.float32)], name='test_rnn_seq_length') +``` + +
+ + +### **RandomNormal** + + Generate a tensor with random values drawn from a normal distribution. The shape + of the tensor is specified by the `shape` argument and the parameter of the normal distribution + specified by `mean` and `scale`. + + The data type is specified by the 'dtype' argument. The 'dtype' argument must + be one of the data types specified in the 'DataType' enum field in the + TensorProto message. + +#### Version + +This version of the operator has been available since version 1 of the default ONNX operator set. + +#### Attributes + +
+
dtype : int (default is 1)
+
The data type for the elements of the output tensor. Default is TensorProto::FLOAT.
+
mean : float (default is 0.0)
+
The mean of the normal distribution.
+
scale : float (default is 1.0)
+
The standard deviation of the normal distribution.
+
seed : float
+
(Optional) Seed to the random generator, if not specified we will auto generate one.
+
shape : list of ints (required)
+
The shape of the output tensor.
+
+ +#### Inputs + + +#### Outputs + +
+
output : T
+
Output tensor of random values drawn from normal distribution
+
+ +#### Type Constraints + +
+
T : tensor(float16), tensor(float), tensor(double)
+
Constrain output types to float tensors.
+
+ + +### **RandomNormalLike** + + Generate a tensor with random values drawn from a normal distribution. + The shape of the output tensor is copied from the shape of the input tensor, + and the parameters of the normal distribution are specified by `mean` and `scale`. + + The data type is specified by the 'dtype' argument, or copied from the input tensor if not provided. + The 'dtype' argument must be one of the data types specified in the 'DataType' enum field in the + TensorProto message, and be valid as an output type. + +#### Version + +This version of the operator has been available since version 1 of the default ONNX operator set. + +#### Attributes + +
+
dtype : int
+
(Optional) The data type for the elements of the output tensor, if not specified, we will use the data type of the input tensor.
+
mean : float (default is 0.0)
+
The mean of the normal distribution.
+
scale : float (default is 1.0)
+
The standard deviation of the normal distribution.
+
seed : float
+
(Optional) Seed to the random generator, if not specified we will auto generate one.
+
+ +#### Inputs + +
+
input : T1
+
Input tensor to copy shape and optionally type information from.
+
+ +#### Outputs + +
+
output : T2
+
Output tensor of random values drawn from normal distribution
+
+ +#### Type Constraints + +
+
T1 : tensor(uint8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(int8), tensor(int16), tensor(int32), tensor(int64), tensor(float16), tensor(float), tensor(double), tensor(string), tensor(bool), tensor(complex64), tensor(complex128)
+
Constrain to any tensor type. If the dtype attribute is not provided this must be a valid output type.
+
T2 : tensor(float16), tensor(float), tensor(double)
+
Constrain output types to float tensors.
+
+ + +### **RandomUniform** + + Generate a tensor with random values drawn from a uniform distribution. The shape + of the tensor is specified by the `shape` argument and the range by `low` and `high`. + + The data type is specified by the 'dtype' argument. The 'dtype' argument must + be one of the data types specified in the 'DataType' enum field in the + TensorProto message. + +#### Version + +This version of the operator has been available since version 1 of the default ONNX operator set. + +#### Attributes + +
+
dtype : int (default is 1)
+
The data type for the elements of the output tensor. If not specified, default is TensorProto::FLOAT.
+
high : float (default is 1.0)
+
Upper boundary of the output values.
+
low : float (default is 0.0)
+
Lower boundary of the output values.
+
seed : float
+
(Optional) Seed to the random generator, if not specified we will auto generate one.
+
shape : list of ints (required)
+
The shape of the output tensor.
+
+ +#### Inputs + + +#### Outputs + +
+
output : T
+
Output tensor of random values drawn from uniform distribution
+
+ +#### Type Constraints + +
+
T : tensor(float16), tensor(float), tensor(double)
+
Constrain output types to float tensors.
+
+ + +### **RandomUniformLike** + + Generate a tensor with random values drawn from a uniform distribution. + The shape of the output tensor is copied from the shape of the input tensor, + and the parameters of the uniform distribution are specified by `low` and `high`. + + The data type is specified by the 'dtype' argument, or copied from the input tensor if not provided. + The 'dtype' argument must be one of the data types specified in the 'DataType' enum field in the + TensorProto message and be valid as an output type. + +#### Version + +This version of the operator has been available since version 1 of the default ONNX operator set. + +#### Attributes + +
+
dtype : int
+
(Optional) The data type for the elements of the output tensor, if not specified, we will use the data type of the input tensor.
+
high : float (default is 1.0)
+
Upper boundary of the output values.
+
low : float (default is 0.0)
+
Lower boundary of the output values.
+
seed : float
+
(Optional) Seed to the random generator, if not specified we will auto generate one.
+
+ +#### Inputs + +
+
input : T1
+
Input tensor to copy shape and optionally type information from.
+
+ +#### Outputs + +
+
output : T2
+
Output tensor of random values drawn from uniform distribution
+
+ +#### Type Constraints + +
+
T1 : tensor(uint8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(int8), tensor(int16), tensor(int32), tensor(int64), tensor(float16), tensor(float), tensor(double), tensor(string), tensor(bool), tensor(complex64), tensor(complex128)
+
Constrain to any tensor type. If the dtype attribute is not provided this must be a valid output type.
+
T2 : tensor(float16), tensor(float), tensor(double)
+
Constrain output types to float tensors.
+
+ + +### **Range** + + Generate a tensor containing a sequence of numbers that begin at `start` and extends by increments of `delta` + up to `limit` (exclusive). + + The number of elements in the output of range is computed as below- + + `number_of_elements = max( ceil( (limit - start) / delta ) , 0 )` + + The pseudocode determining the contents of the output is shown below- + + `for(int i=0; i +
start : T
+
Scalar. First entry for the range of output values.
+
limit : T
+
Scalar. Exclusive upper limit for the range of output values.
+
delta : T
+
Scalar. Value to step by.
+ + +#### Outputs + +
+
output : T
+
A 1-D tensor with same type as the inputs containing generated range of values.
+
+ +#### Type Constraints + +
+
T : tensor(float), tensor(double), tensor(int16), tensor(int32), tensor(int64)
+
Constrain input types to common numeric type tensors.
+
+ + +#### Examples + +
+range_float_type_positive_delta + +```python +node = onnx.helper.make_node( + 'Range', + inputs=['start', 'limit', 'delta'], + outputs=['output'], +) + +start = np.float32(1) +limit = np.float32(5) +delta = np.float32(2) + +output = np.arange(start, limit, delta, dtype=np.float32) # expected output [1.0, 3.0] +expect(node, inputs=[start, limit, delta], outputs=[output], + name='test_range_float_type_positive_delta') +``` + +
+ + +
+range_int32_type_negative_delta + +```python +node = onnx.helper.make_node( + 'Range', + inputs=['start', 'limit', 'delta'], + outputs=['output'], +) + +start = np.int32(10) +limit = np.int32(6) +delta = np.int32(-3) + +output = np.arange(start, limit, delta, dtype=np.int32) # expected output [10, 7] +expect(node, inputs=[start, limit, delta], outputs=[output], + name='test_range_int32_type_negative_delta') +``` + +
+ + +### **Reciprocal** + + Reciprocal takes one input data (Tensor) and produces one output data + (Tensor) where the reciprocal is, y = 1/x, is applied to + the tensor elementwise. + +#### Version + +This version of the operator has been available since version 13 of the default ONNX operator set. + +Other versions of this operator: 1, 6 + +#### Inputs + +
+
X (differentiable) : T
+
Input tensor
+
+ +#### Outputs + +
+
Y (differentiable) : T
+
Output tensor
+
+ +#### Type Constraints + +
+
T : tensor(float16), tensor(float), tensor(double), tensor(bfloat16)
+
Constrain input and output types to float tensors.
+
+ + +#### Examples + +
+reciprocal + +```python +node = onnx.helper.make_node( + 'Reciprocal', + inputs=['x'], + outputs=['y'], +) + +x = np.array([-4, 2]).astype(np.float32) +y = np.reciprocal(x) # expected output [-0.25, 0.5], +expect(node, inputs=[x], outputs=[y], + name='test_reciprocal_example') + +x = np.random.rand(3, 4, 5).astype(np.float32) + 0.5 +y = np.reciprocal(x) +expect(node, inputs=[x], outputs=[y], + name='test_reciprocal') +``` + +
+ + +### **ReduceL1** + + Computes the L1 norm of the input tensor's element along the provided axes. The resulted + tensor has the same rank as the input if keepdims equal 1. If keepdims equal 0, then + the resulted tensor have the reduced dimension pruned. + + The above behavior is similar to numpy, with the exception that numpy default keepdims to + False instead of True. + +#### Version + +This version of the operator has been available since version 13 of the default ONNX operator set. + +Other versions of this operator: 1, 11 + +#### Attributes + +
+
axes : list of ints
+
A list of integers, along which to reduce. The default is to reduce over all the dimensions of the input tensor. Accepted range is [-r, r-1] where r = rank(data).
+
keepdims : int (default is 1)
+
Keep the reduced dimension or not, default 1 mean keep reduced dimension.
+
+ +#### Inputs + +
+
data (differentiable) : T
+
An input tensor.
+
+ +#### Outputs + +
+
reduced (differentiable) : T
+
Reduced output tensor.
+
+ +#### Type Constraints + +
+
T : tensor(uint32), tensor(uint64), tensor(int32), tensor(int64), tensor(float16), tensor(float), tensor(double), tensor(bfloat16)
+
Constrain input and output types to high-precision numeric tensors.
+
+ + +#### Examples + +
+default_axes_keepdims + +```python +shape = [3, 2, 2] +axes = None +keepdims = 1 + +node = onnx.helper.make_node( + 'ReduceL1', + inputs=['data'], + outputs=['reduced'], + keepdims=keepdims +) + +data = np.reshape(np.arange(1, np.prod(shape) + 1, dtype=np.float32), shape) +#print(data) +#[[[1., 2.], [3., 4.]], [[5., 6.], [7., 8.]], [[9., 10.], [11., 12.]]] + +reduced = np.sum(a=np.abs(data), axis=axes, keepdims=keepdims == 1) +#print(reduced) +#[[[78.]]] + +expect(node, inputs=[data], outputs=[reduced], + name='test_reduce_l1_default_axes_keepdims_example') + +np.random.seed(0) +data = np.random.uniform(-10, 10, shape).astype(np.float32) +reduced = np.sum(a=np.abs(data), axis=axes, keepdims=keepdims == 1) + +expect(node, inputs=[data], outputs=[reduced], + name='test_reduce_l1_default_axes_keepdims_random') +``` + +
+ + +
+do_not_keepdims + +```python +shape = [3, 2, 2] +axes = [2] +keepdims = 0 + +node = onnx.helper.make_node( + 'ReduceL1', + inputs=['data'], + outputs=['reduced'], + axes=axes, + keepdims=keepdims +) + +data = np.reshape(np.arange(1, np.prod(shape) + 1, dtype=np.float32), shape) +#print(data) +#[[[1., 2.], [3., 4.]], [[5., 6.], [7., 8.]], [[9., 10.], [11., 12.]]] + +reduced = np.sum(a=np.abs(data), axis=tuple(axes), keepdims=keepdims == 1) +#print(reduced) +#[[3., 7.], [11., 15.], [19., 23.]] + +expect(node, inputs=[data], outputs=[reduced], + name='test_reduce_l1_do_not_keepdims_example') + +np.random.seed(0) +data = np.random.uniform(-10, 10, shape).astype(np.float32) +reduced = np.sum(a=np.abs(data), axis=tuple(axes), keepdims=keepdims == 1) + +expect(node, inputs=[data], outputs=[reduced], + name='test_reduce_l1_do_not_keepdims_random') +``` + +
+ + +
+keepdims + +```python +shape = [3, 2, 2] +axes = [2] +keepdims = 1 + +node = onnx.helper.make_node( + 'ReduceL1', + inputs=['data'], + outputs=['reduced'], + axes=axes, + keepdims=keepdims +) + +data = np.reshape(np.arange(1, np.prod(shape) + 1, dtype=np.float32), shape) +#print(data) +#[[[1., 2.], [3., 4.]], [[5., 6.], [7., 8.]], [[9., 10.], [11., 12.]]] + +reduced = np.sum(a=np.abs(data), axis=tuple(axes), keepdims=keepdims == 1) +#print(reduced) +#[[[3.], [7.]], [[11.], [15.]], [[19.], [23.]]] + +expect(node, inputs=[data], outputs=[reduced], + name='test_reduce_l1_keep_dims_example') + +np.random.seed(0) +data = np.random.uniform(-10, 10, shape).astype(np.float32) +reduced = np.sum(a=np.abs(data), axis=tuple(axes), keepdims=keepdims == 1) + +expect(node, inputs=[data], outputs=[reduced], + name='test_reduce_l1_keep_dims_random') +``` + +
+ + +
+negative_axes_keepdims + +```python +shape = [3, 2, 2] +axes = [-1] +keepdims = 1 + +node = onnx.helper.make_node( + 'ReduceL1', + inputs=['data'], + outputs=['reduced'], + axes=axes, + keepdims=keepdims +) + +data = np.reshape(np.arange(1, np.prod(shape) + 1, dtype=np.float32), shape) +# print(data) +#[[[1., 2.], [3., 4.]], [[5., 6.], [7., 8.]], [[9., 10.], [11., 12.]]] + +reduced = np.sum(a=np.abs(data), axis=tuple(axes), keepdims=keepdims == 1) +# print(reduced) +#[[[3.], [7.]], [[11.], [15.]], [[19.], [23.]]] + +expect(node, inputs=[data], outputs=[reduced], + name='test_reduce_l1_negative_axes_keep_dims_example') + +np.random.seed(0) +data = np.random.uniform(-10, 10, shape).astype(np.float32) +reduced = np.sum(a=np.abs(data), axis=tuple(axes), keepdims=keepdims == 1) + +expect(node, inputs=[data], outputs=[reduced], + name='test_reduce_l1_negative_axes_keep_dims_random') +``` + +
+ + +### **ReduceL2** + + Computes the L2 norm of the input tensor's element along the provided axes. The resulted + tensor has the same rank as the input if keepdims equal 1. If keepdims equal 0, then + the resulted tensor have the reduced dimension pruned. + + The above behavior is similar to numpy, with the exception that numpy default keepdims to + False instead of True. + +#### Version + +This version of the operator has been available since version 13 of the default ONNX operator set. + +Other versions of this operator: 1, 11 + +#### Attributes + +
+
axes : list of ints
+
A list of integers, along which to reduce. The default is to reduce over all the dimensions of the input tensor. Accepted range is [-r, r-1] where r = rank(data).
+
keepdims : int (default is 1)
+
Keep the reduced dimension or not, default 1 mean keep reduced dimension.
+
+ +#### Inputs + +
+
data (differentiable) : T
+
An input tensor.
+
+ +#### Outputs + +
+
reduced (differentiable) : T
+
Reduced output tensor.
+
+ +#### Type Constraints + +
+
T : tensor(uint32), tensor(uint64), tensor(int32), tensor(int64), tensor(float16), tensor(float), tensor(double), tensor(bfloat16)
+
Constrain input and output types to high-precision numeric tensors.
+
+ + +#### Examples + +
+default_axes_keepdims + +```python +shape = [3, 2, 2] +axes = None +keepdims = 1 + +node = onnx.helper.make_node( + 'ReduceL2', + inputs=['data'], + outputs=['reduced'], + keepdims=keepdims +) + +data = np.reshape(np.arange(1, np.prod(shape) + 1, dtype=np.float32), shape) +#print(data) +#[[[1., 2.], [3., 4.]], [[5., 6.], [7., 8.]], [[9., 10.], [11., 12.]]] + +reduced = np.sqrt(np.sum( + a=np.square(data), axis=axes, keepdims=keepdims == 1)) +#print(reduced) +#[[[25.49509757]]] + +expect(node, inputs=[data], outputs=[reduced], + name='test_reduce_l2_default_axes_keepdims_example') + +np.random.seed(0) +data = np.random.uniform(-10, 10, shape).astype(np.float32) +reduced = np.sqrt(np.sum( + a=np.square(data), axis=axes, keepdims=keepdims == 1)) + +expect(node, inputs=[data], outputs=[reduced], + name='test_reduce_l2_default_axes_keepdims_random') +``` + +
+ + +
+do_not_keepdims + +```python +shape = [3, 2, 2] +axes = [2] +keepdims = 0 + +node = onnx.helper.make_node( + 'ReduceL2', + inputs=['data'], + outputs=['reduced'], + axes=axes, + keepdims=keepdims +) + +data = np.reshape(np.arange(1, np.prod(shape) + 1, dtype=np.float32), shape) +#print(data) +#[[[1., 2.], [3., 4.]], [[5., 6.], [7., 8.]], [[9., 10.], [11., 12.]]] + +reduced = np.sqrt(np.sum( + a=np.square(data), axis=tuple(axes), keepdims=keepdims == 1)) +#print(reduced) +#[[2.23606798, 5.], +# [7.81024968, 10.63014581], +# [13.45362405, 16.2788206]] + +expect(node, inputs=[data], outputs=[reduced], + name='test_reduce_l2_do_not_keepdims_example') + +np.random.seed(0) +data = np.random.uniform(-10, 10, shape).astype(np.float32) +reduced = np.sqrt(np.sum( + a=np.square(data), axis=tuple(axes), keepdims=keepdims == 1)) + +expect(node, inputs=[data], outputs=[reduced], + name='test_reduce_l2_do_not_keepdims_random') +``` + +
+ + +
+keepdims + +```python +shape = [3, 2, 2] +axes = [2] +keepdims = 1 + +node = onnx.helper.make_node( + 'ReduceL2', + inputs=['data'], + outputs=['reduced'], + axes=axes, + keepdims=keepdims +) + +data = np.reshape(np.arange(1, np.prod(shape) + 1, dtype=np.float32), shape) +#print(data) +#[[[1., 2.], [3., 4.]], [[5., 6.], [7., 8.]], [[9., 10.], [11., 12.]]] + +reduced = np.sqrt(np.sum( + a=np.square(data), axis=tuple(axes), keepdims=keepdims == 1)) +#print(reduced) +#[[[2.23606798], [5.]] +# [[7.81024968], [10.63014581]] +# [[13.45362405], [16.2788206 ]]] + +expect(node, inputs=[data], outputs=[reduced], + name='test_reduce_l2_keep_dims_example') + +np.random.seed(0) +data = np.random.uniform(-10, 10, shape).astype(np.float32) +reduced = np.sqrt(np.sum( + a=np.square(data), axis=tuple(axes), keepdims=keepdims == 1)) + +expect(node, inputs=[data], outputs=[reduced], name='test_reduce_l2_keep_dims_random') +``` + +
+ + +
+negative_axes_keepdims + +```python +shape = [3, 2, 2] +axes = [-1] +keepdims = 1 + +node = onnx.helper.make_node( + 'ReduceL2', + inputs=['data'], + outputs=['reduced'], + axes=axes, + keepdims=keepdims +) + +data = np.reshape(np.arange(1, np.prod(shape) + 1, dtype=np.float32), shape) +# print(data) +#[[[1., 2.], [3., 4.]], [[5., 6.], [7., 8.]], [[9., 10.], [11., 12.]]] + +reduced = np.sqrt(np.sum( + a=np.square(data), axis=tuple(axes), keepdims=keepdims == 1)) +# print(reduced) +#[[[2.23606798], [5.]] +# [[7.81024968], [10.63014581]] +# [[13.45362405], [16.2788206 ]]] + +expect(node, inputs=[data], outputs=[reduced], + name='test_reduce_l2_negative_axes_keep_dims_example') + +np.random.seed(0) +data = np.random.uniform(-10, 10, shape).astype(np.float32) +reduced = np.sqrt(np.sum( + a=np.square(data), axis=tuple(axes), keepdims=keepdims == 1)) + +expect(node, inputs=[data], outputs=[reduced], + name='test_reduce_l2_negative_axes_keep_dims_random') +``` + +
+ + +### **ReduceLogSum** + + Computes the log sum of the input tensor's element along the provided axes. The resulted + tensor has the same rank as the input if keepdims equal 1. If keepdims equal 0, then + the resulted tensor have the reduced dimension pruned. + + The above behavior is similar to numpy, with the exception that numpy default keepdims to + False instead of True. + +#### Version + +This version of the operator has been available since version 13 of the default ONNX operator set. + +Other versions of this operator: 1, 11 + +#### Attributes + +
+
axes : list of ints
+
A list of integers, along which to reduce. The default is to reduce over all the dimensions of the input tensor. Accepted range is [-r, r-1] where r = rank(data).
+
keepdims : int (default is 1)
+
Keep the reduced dimension or not, default 1 mean keep reduced dimension.
+
+ +#### Inputs + +
+
data (differentiable) : T
+
An input tensor.
+
+ +#### Outputs + +
+
reduced (differentiable) : T
+
Reduced output tensor.
+
+ +#### Type Constraints + +
+
T : tensor(uint32), tensor(uint64), tensor(int32), tensor(int64), tensor(float16), tensor(float), tensor(double), tensor(bfloat16)
+
Constrain input and output types to high-precision numeric tensors.
+
+ + +#### Examples + +
+keepdims + +```python +node = onnx.helper.make_node( + 'ReduceLogSum', + inputs=['data'], + outputs=["reduced"] +) +data = np.random.ranf([3, 4, 5]).astype(np.float32) +reduced = np.log(np.sum(data, keepdims=True)) +expect(node, inputs=[data], outputs=[reduced], + name='test_reduce_log_sum_default') +``` + +
+ + +
+negative_axes_keepdims + +```python +node = onnx.helper.make_node( + 'ReduceLogSum', + inputs=['data'], + outputs=["reduced"], + axes=[-2] +) +data = np.random.ranf([3, 4, 5]).astype(np.float32) +reduced = np.log(np.sum(data, axis=(-2), keepdims=True)) +# print(reduced) +expect(node, inputs=[data], outputs=[reduced], + name='test_reduce_log_sum_negative_axes') +``` + +
+ + +
+nokeepdims + +```python +node = onnx.helper.make_node( + 'ReduceLogSum', + inputs=['data'], + outputs=["reduced"], + axes=[2, 1], + keepdims=0 +) +data = np.random.ranf([3, 4, 5]).astype(np.float32) +reduced = np.log(np.sum(data, axis=(2, 1), keepdims=False)) +expect(node, inputs=[data], outputs=[reduced], + name='test_reduce_log_sum_desc_axes') + +node = onnx.helper.make_node( + 'ReduceLogSum', + inputs=['data'], + outputs=["reduced"], + axes=[0, 1], + keepdims=0 +) +data = np.random.ranf([3, 4, 5]).astype(np.float32) +reduced = np.log(np.sum(data, axis=(0, 1), keepdims=False)) +expect(node, inputs=[data], outputs=[reduced], + name='test_reduce_log_sum_asc_axes') +``` + +
+ + +### **ReduceLogSumExp** + + Computes the log sum exponent of the input tensor's element along the provided axes. The resulted + tensor has the same rank as the input if keepdims equal 1. If keepdims equal 0, then + the resulted tensor have the reduced dimension pruned. + + The above behavior is similar to numpy, with the exception that numpy default keepdims to + False instead of True. + +#### Version + +This version of the operator has been available since version 13 of the default ONNX operator set. + +Other versions of this operator: 1, 11 + +#### Attributes + +
+
axes : list of ints
+
A list of integers, along which to reduce. The default is to reduce over all the dimensions of the input tensor. Accepted range is [-r, r-1] where r = rank(data).
+
keepdims : int (default is 1)
+
Keep the reduced dimension or not, default 1 mean keep reduced dimension.
+
+ +#### Inputs + +
+
data (differentiable) : T
+
An input tensor.
+
+ +#### Outputs + +
+
reduced (differentiable) : T
+
Reduced output tensor.
+
+ +#### Type Constraints + +
+
T : tensor(uint32), tensor(uint64), tensor(int32), tensor(int64), tensor(float16), tensor(float), tensor(double), tensor(bfloat16)
+
Constrain input and output types to high-precision numeric tensors.
+
+ + +#### Examples + +
+default_axes_keepdims + +```python +shape = [3, 2, 2] +axes = None +keepdims = 1 + +node = onnx.helper.make_node( + 'ReduceLogSumExp', + inputs=['data'], + outputs=['reduced'], + keepdims=keepdims +) + +data = np.array( + [[[5, 1], [20, 2]], [[30, 1], [40, 2]], [[55, 1], [60, 2]]], + dtype=np.double) +reduced = np.log(np.sum(np.exp(data), + axis=axes, + keepdims=keepdims == 1)) +# print(reduced) +# [[[60.00671387]]] + +expect(node, inputs=[data], outputs=[reduced], + name='test_reduce_log_sum_exp_default_axes_keepdims_example') + +np.random.seed(0) +data = np.random.uniform(-10, 10, shape).astype(np.double) +reduced = np.log(np.sum(np.exp(data), + axis=axes, + keepdims=keepdims == 1)) +expect(node, inputs=[data], outputs=[reduced], + name='test_reduce_log_sum_exp_default_axes_keepdims_random') +``` + +
+ + +
+do_not_keepdims + +```python +shape = [3, 2, 2] +axes = [1] +keepdims = 0 +node = onnx.helper.make_node( + 'ReduceLogSumExp', + inputs=['data'], + outputs=['reduced'], + axes=axes, + keepdims=keepdims +) + +data = np.array( + [[[5, 1], [20, 2]], [[30, 1], [40, 2]], [[55, 1], [60, 2]]], + dtype=np.double) +reduced = np.log(np.sum( + np.exp(data), axis=tuple(axes), keepdims=keepdims == 1)) +# print(reduced) +#[[20., 2.31326175] +# [40.00004578, 2.31326175] +# [60.00671387, 2.31326175]] + +expect(node, inputs=[data], outputs=[reduced], + name='test_reduce_log_sum_exp_do_not_keepdims_example') + +np.random.seed(0) +data = np.random.uniform(-10, 10, shape).astype(np.double) +reduced = np.log(np.sum( + np.exp(data), axis=tuple(axes), keepdims=keepdims == 1)) + +expect(node, inputs=[data], outputs=[reduced], + name='test_reduce_log_sum_exp_do_not_keepdims_random') +``` + +
+ + +
+keepdims + +```python +shape = [3, 2, 2] +axes = [1] +keepdims = 1 +node = onnx.helper.make_node( + 'ReduceLogSumExp', + inputs=['data'], + outputs=['reduced'], + axes=axes, + keepdims=keepdims +) + +data = np.array( + [[[5, 1], [20, 2]], [[30, 1], [40, 2]], [[55, 1], [60, 2]]], + dtype=np.double) +reduced = np.log(np.sum(np.exp(data), + axis=tuple(axes), + keepdims=keepdims == 1)) +# print(reduced) +# [[[20., 2.31326175]] +# [[40.00004578, 2.31326175]] +# [[60.00671387, 2.31326175]]] + +expect(node, inputs=[data], outputs=[reduced], + name='test_reduce_log_sum_exp_keepdims_example') + +np.random.seed(0) +data = np.random.uniform(-10, 10, shape).astype(np.double) +reduced = np.log(np.sum(np.exp(data), + axis=tuple(axes), + keepdims=keepdims == 1)) + +expect(node, inputs=[data], outputs=[reduced], + name='test_reduce_log_sum_exp_keepdims_random') +``` + +
+ + +
+negative_axes_keepdims + +```python +shape = [3, 2, 2] +axes = [-2] +keepdims = 1 +node = onnx.helper.make_node( + 'ReduceLogSumExp', + inputs=['data'], + outputs=['reduced'], + axes=axes, + keepdims=keepdims +) + +data = np.array( + [[[5, 1], [20, 2]], [[30, 1], [40, 2]], [[55, 1], [60, 2]]], + dtype=np.double) +reduced = np.log(np.sum(np.exp(data), + axis=tuple(axes), + keepdims=keepdims == 1)) +# print(reduced) +# [[[20., 2.31326175]] +# [[40.00004578, 2.31326175]] +# [[60.00671387, 2.31326175]]] + +expect(node, inputs=[data], outputs=[reduced], + name='test_reduce_log_sum_exp_negative_axes_keepdims_example') + +np.random.seed(0) +data = np.random.uniform(-10, 10, shape).astype(np.double) +reduced = np.log(np.sum(np.exp(data), + axis=tuple(axes), + keepdims=keepdims == 1)) + +expect(node, inputs=[data], outputs=[reduced], + name='test_reduce_log_sum_exp_negative_axes_keepdims_random') +``` + +
+ + +### **ReduceMax** + + Computes the max of the input tensor's element along the provided axes. The resulted + tensor has the same rank as the input if keepdims equal 1. If keepdims equal 0, then + the resulted tensor have the reduced dimension pruned. + + The above behavior is similar to numpy, with the exception that numpy default keepdims to + False instead of True. + +#### Version + +This version of the operator has been available since version 13 of the default ONNX operator set. + +Other versions of this operator: 1, 11, 12 + +#### Attributes + +
+
axes : list of ints
+
A list of integers, along which to reduce. The default is to reduce over all the dimensions of the input tensor. Accepted range is [-r, r-1] where r = rank(data).
+
keepdims : int (default is 1)
+
Keep the reduced dimension or not, default 1 mean keep reduced dimension.
+
+ +#### Inputs + +
+
data (differentiable) : T
+
An input tensor.
+
+ +#### Outputs + +
+
reduced (differentiable) : T
+
Reduced output tensor.
+
+ +#### Type Constraints + +
+
T : tensor(uint32), tensor(uint64), tensor(int32), tensor(int64), tensor(float16), tensor(float), tensor(double), tensor(bfloat16), tensor(uint8), tensor(int8)
+
Constrain input and output types to high-precision and 8 bit numeric tensors.
+
+ + +#### Examples + +
+default_axes_keepdims + +```python +shape = [3, 2, 2] +axes = None +keepdims = 1 +node = onnx.helper.make_node( + 'ReduceMax', + inputs=['data'], + outputs=['reduced'], + keepdims=keepdims) + +data = np.array([[[5, 1], [20, 2]], [[30, 1], [40, 2]], [[55, 1], [60, 2]]], dtype=np.float32) +reduced = np.maximum.reduce(data, axis=axes, keepdims=keepdims == 1) +#print(reduced) +[[[60.]]] + +expect(node, inputs=[data], outputs=[reduced], name='test_reduce_max_default_axes_keepdim_example') + +np.random.seed(0) +data = np.random.uniform(-10, 10, shape).astype(np.float32) +reduced = np.maximum.reduce(data, axis=axes, keepdims=keepdims == 1) + +expect(node, inputs=[data], outputs=[reduced], name='test_reduce_max_default_axes_keepdims_random') +``` + +
+ + +
+do_not_keepdims + +```python +shape = [3, 2, 2] +axes = [1] +keepdims = 0 + +node = onnx.helper.make_node( + 'ReduceMax', + inputs=['data'], + outputs=['reduced'], + axes=axes, + keepdims=keepdims) + +data = np.array([[[5, 1], [20, 2]], [[30, 1], [40, 2]], [[55, 1], [60, 2]]], dtype=np.float32) +reduced = np.maximum.reduce(data, axis=tuple(axes), keepdims=keepdims == 1) +#print(reduced) +#[[20., 2.] +# [40., 2.] +# [60., 2.]] + +expect(node, inputs=[data], outputs=[reduced], name='test_reduce_max_do_not_keepdims_example') + +np.random.seed(0) +data = np.random.uniform(-10, 10, shape).astype(np.float32) +reduced = np.maximum.reduce(data, axis=tuple(axes), keepdims=keepdims == 1) + +expect(node, inputs=[data], outputs=[reduced], name='test_reduce_max_do_not_keepdims_random') +``` + +
+ + +
+keepdims + +```python +shape = [3, 2, 2] +axes = [1] +keepdims = 1 + +node = onnx.helper.make_node( + 'ReduceMax', + inputs=['data'], + outputs=['reduced'], + axes=axes, + keepdims=keepdims) + +data = np.array([[[5, 1], [20, 2]], [[30, 1], [40, 2]], [[55, 1], [60, 2]]], dtype=np.float32) +reduced = np.maximum.reduce(data, axis=tuple(axes), keepdims=keepdims == 1) +#print(reduced) +#[[[20., 2.]] +# [[40., 2.]] +# [[60., 2.]]] + +expect(node, inputs=[data], outputs=[reduced], name='test_reduce_max_keepdims_example') + +np.random.seed(0) +data = np.random.uniform(-10, 10, shape).astype(np.float32) +reduced = np.maximum.reduce(data, axis=tuple(axes), keepdims=keepdims == 1) + +expect(node, inputs=[data], outputs=[reduced], name='test_reduce_max_keepdims_random') +``` + +
+ + +
+negative_axes_keepdims + +```python +shape = [3, 2, 2] +axes = [-2] +keepdims = 1 + +node = onnx.helper.make_node( + 'ReduceMax', + inputs=['data'], + outputs=['reduced'], + axes=axes, + keepdims=keepdims) + +data = np.array([[[5, 1], [20, 2]], [[30, 1], [40, 2]], [[55, 1], [60, 2]]], dtype=np.float32) +reduced = np.maximum.reduce(data, axis=tuple(axes), keepdims=keepdims == 1) +# print(reduced) +#[[[20., 2.]] +# [[40., 2.]] +# [[60., 2.]]] + +expect(node, inputs=[data], outputs=[reduced], name='test_reduce_max_negative_axes_keepdims_example') + +np.random.seed(0) +data = np.random.uniform(-10, 10, shape).astype(np.float32) +reduced = np.maximum.reduce(data, axis=tuple(axes), keepdims=keepdims == 1) + +expect(node, inputs=[data], outputs=[reduced], name='test_reduce_max_negative_axes_keepdims_random') +``` + +
+ + +### **ReduceMean** + + Computes the mean of the input tensor's element along the provided axes. The resulted + tensor has the same rank as the input if keepdims equal 1. If keepdims equal 0, then + the resulted tensor have the reduced dimension pruned. + + The above behavior is similar to numpy, with the exception that numpy default keepdims to + False instead of True. + +#### Version + +This version of the operator has been available since version 13 of the default ONNX operator set. + +Other versions of this operator: 1, 11 + +#### Attributes + +
+
axes : list of ints
+
A list of integers, along which to reduce. The default is to reduce over all the dimensions of the input tensor. Accepted range is [-r, r-1] where r = rank(data).
+
keepdims : int (default is 1)
+
Keep the reduced dimension or not, default 1 mean keep reduced dimension.
+
+ +#### Inputs + +
+
data (differentiable) : T
+
An input tensor.
+
+ +#### Outputs + +
+
reduced (differentiable) : T
+
Reduced output tensor.
+
+ +#### Type Constraints + +
+
T : tensor(uint32), tensor(uint64), tensor(int32), tensor(int64), tensor(float16), tensor(float), tensor(double), tensor(bfloat16)
+
Constrain input and output types to high-precision numeric tensors.
+
+ + +#### Examples + +
+default_axes_keepdims + +```python +shape = [3, 2, 2] +axes = None +keepdims = 1 + +node = onnx.helper.make_node( + 'ReduceMean', + inputs=['data'], + outputs=['reduced'], + keepdims=keepdims) + +data = np.array([[[5, 1], [20, 2]], [[30, 1], [40, 2]], [[55, 1], [60, 2]]], dtype=np.float32) +reduced = np.mean(data, axis=axes, keepdims=keepdims == 1) +#print(reduced) +#[[[18.25]]] + +expect(node, inputs=[data], outputs=[reduced], name='test_reduce_mean_default_axes_keepdims_example') + +np.random.seed(0) +data = np.random.uniform(-10, 10, shape).astype(np.float32) +reduced = np.mean(data, axis=axes, keepdims=keepdims == 1) + +expect(node, inputs=[data], outputs=[reduced], name='test_reduce_mean_default_axes_keepdims_random') +``` + +
+ + +
+do_not_keepdims + +```python +shape = [3, 2, 2] +axes = [1] +keepdims = 0 + +node = onnx.helper.make_node( + 'ReduceMean', + inputs=['data'], + outputs=['reduced'], + axes=axes, + keepdims=keepdims) + +data = np.array([[[5, 1], [20, 2]], [[30, 1], [40, 2]], [[55, 1], [60, 2]]], dtype=np.float32) +reduced = np.mean(data, axis=tuple(axes), keepdims=keepdims == 1) +#print(reduced) +#[[12.5, 1.5] +# [35., 1.5] +# [57.5, 1.5]] + +expect(node, inputs=[data], outputs=[reduced], name='test_reduce_mean_do_not_keepdims_example') + +np.random.seed(0) +data = np.random.uniform(-10, 10, shape).astype(np.float32) +reduced = np.mean(data, axis=tuple(axes), keepdims=keepdims == 1) + +expect(node, inputs=[data], outputs=[reduced], name='test_reduce_mean_do_not_keepdims_random') +``` + +
+ + +
+keepdims + +```python +shape = [3, 2, 2] +axes = [1] +keepdims = 1 + +node = onnx.helper.make_node( + 'ReduceMean', + inputs=['data'], + outputs=['reduced'], + axes=axes, + keepdims=keepdims) + +data = np.array([[[5, 1], [20, 2]], [[30, 1], [40, 2]], [[55, 1], [60, 2]]], dtype=np.float32) +reduced = np.mean(data, axis=tuple(axes), keepdims=keepdims == 1) +#print(reduced) +#[[[12.5, 1.5]] +# [[35., 1.5]] +# [[57.5, 1.5]]] + +expect(node, inputs=[data], outputs=[reduced], name='test_reduce_mean_keepdims_example') + +np.random.seed(0) +data = np.random.uniform(-10, 10, shape).astype(np.float32) +reduced = np.mean(data, axis=tuple(axes), keepdims=keepdims == 1) + +expect(node, inputs=[data], outputs=[reduced], name='test_reduce_mean_keepdims_random') +``` + +
+ + +
+negative_axes_keepdims + +```python +shape = [3, 2, 2] +axes = [-2] +keepdims = 1 + +node = onnx.helper.make_node( + 'ReduceMean', + inputs=['data'], + outputs=['reduced'], + axes=axes, + keepdims=keepdims) + +data = np.array([[[5, 1], [20, 2]], [[30, 1], [40, 2]], [[55, 1], [60, 2]]], dtype=np.float32) +reduced = np.mean(data, axis=tuple(axes), keepdims=keepdims == 1) +# print(reduced) +# [[[12.5, 1.5]] +# [[35., 1.5]] +# [[57.5, 1.5]]] + +expect(node, inputs=[data], outputs=[reduced], name='test_reduce_mean_negative_axes_keepdims_example') + +np.random.seed(0) +data = np.random.uniform(-10, 10, shape).astype(np.float32) +reduced = np.mean(data, axis=tuple(axes), keepdims=keepdims == 1) + +expect(node, inputs=[data], outputs=[reduced], name='test_reduce_mean_negative_axes_keepdims_random') +``` + +
+ + +### **ReduceMin** + + Computes the min of the input tensor's element along the provided axes. The resulted + tensor has the same rank as the input if keepdims equal 1. If keepdims equal 0, then + the resulted tensor have the reduced dimension pruned. + + The above behavior is similar to numpy, with the exception that numpy default keepdims to + False instead of True. + +#### Version + +This version of the operator has been available since version 13 of the default ONNX operator set. + +Other versions of this operator: 1, 11, 12 + +#### Attributes + +
+
axes : list of ints
+
A list of integers, along which to reduce. The default is to reduce over all the dimensions of the input tensor. Accepted range is [-r, r-1] where r = rank(data).
+
keepdims : int (default is 1)
+
Keep the reduced dimension or not, default 1 mean keep reduced dimension.
+
+ +#### Inputs + +
+
data (differentiable) : T
+
An input tensor.
+
+ +#### Outputs + +
+
reduced (differentiable) : T
+
Reduced output tensor.
+
+ +#### Type Constraints + +
+
T : tensor(uint32), tensor(uint64), tensor(int32), tensor(int64), tensor(float16), tensor(float), tensor(double), tensor(bfloat16), tensor(uint8), tensor(int8)
+
Constrain input and output types to high-precision and 8 bit numeric tensors.
+
+ + +#### Examples + +
+default_axes_keepdims + +```python +shape = [3, 2, 2] +axes = None +keepdims = 1 + +node = onnx.helper.make_node( + 'ReduceMin', + inputs=['data'], + outputs=['reduced'], + keepdims=keepdims) + +data = np.array([[[5, 1], [20, 2]], [[30, 1], [40, 2]], [[55, 1], [60, 2]]], dtype=np.float32) +reduced = np.minimum.reduce(data, axis=axes, keepdims=keepdims == 1) +#print(reduced) +#[[[1.]]] + +expect(node, inputs=[data], outputs=[reduced], name='test_reduce_min_default_axes_keepdims_example') + +np.random.seed(0) +data = np.random.uniform(-10, 10, shape).astype(np.float32) +reduced = np.minimum.reduce(data, axis=axes, keepdims=keepdims == 1) + +expect(node, inputs=[data], outputs=[reduced], name='test_reduce_min_default_axes_keepdims_random') +``` + +
+ + +
+do_not_keepdims + +```python +shape = [3, 2, 2] +axes = [1] +keepdims = 0 + +node = onnx.helper.make_node( + 'ReduceMin', + inputs=['data'], + outputs=['reduced'], + axes=axes, + keepdims=keepdims) + +data = np.array([[[5, 1], [20, 2]], [[30, 1], [40, 2]], [[55, 1], [60, 2]]], dtype=np.float32) +reduced = np.minimum.reduce(data, axis=tuple(axes), keepdims=keepdims == 1) +#print(reduced) +#[[5., 1.] +# [30., 1.] +# [55., 1.]] + +expect(node, inputs=[data], outputs=[reduced], name='test_reduce_min_do_not_keepdims_example') + +np.random.seed(0) +data = np.random.uniform(-10, 10, shape).astype(np.float32) +reduced = np.minimum.reduce(data, axis=tuple(axes), keepdims=keepdims == 1) + +expect(node, inputs=[data], outputs=[reduced], name='test_reduce_min_do_not_keepdims_random') +``` + +
+ + +
+keepdims + +```python +shape = [3, 2, 2] +axes = [1] +keepdims = 1 + +node = onnx.helper.make_node( + 'ReduceMin', inputs=['data'], + outputs=['reduced'], + axes=axes, + keepdims=keepdims) + +data = np.array([[[5, 1], [20, 2]], [[30, 1], [40, 2]], [[55, 1], [60, 2]]], dtype=np.float32) +reduced = np.minimum.reduce(data, axis=tuple(axes), keepdims=keepdims == 1) +#print(reduced) +#[[[5., 1.]] +# [[30., 1.]] +# [[55., 1.]]] + +expect(node, inputs=[data], outputs=[reduced], name='test_reduce_min_keepdims_example') + +np.random.seed(0) +data = np.random.uniform(-10, 10, shape).astype(np.float32) +reduced = np.minimum.reduce(data, axis=tuple(axes), keepdims=keepdims == 1) + +expect(node, inputs=[data], outputs=[reduced], name='test_reduce_min_keepdims_random') +``` + +
+ + +
+negative_axes_keepdims + +```python +shape = [3, 2, 2] +axes = [-2] +keepdims = 1 + +node = onnx.helper.make_node( + 'ReduceMin', inputs=['data'], + outputs=['reduced'], + axes=axes, + keepdims=keepdims) + +data = np.array([[[5, 1], [20, 2]], [[30, 1], [40, 2]], [[55, 1], [60, 2]]], dtype=np.float32) +reduced = np.minimum.reduce(data, axis=tuple(axes), keepdims=keepdims == 1) +# print(reduced) +#[[[5., 1.]] +# [[30., 1.]] +# [[55., 1.]]] + +expect(node, inputs=[data], outputs=[reduced], name='test_reduce_min_negative_axes_keepdims_example') + +np.random.seed(0) +data = np.random.uniform(-10, 10, shape).astype(np.float32) +reduced = np.minimum.reduce(data, axis=tuple(axes), keepdims=keepdims == 1) + +expect(node, inputs=[data], outputs=[reduced], name='test_reduce_min_negative_axes_keepdims_random') +``` + +
+ + +### **ReduceProd** + + Computes the product of the input tensor's element along the provided axes. The resulted + tensor has the same rank as the input if keepdims equal 1. If keepdims equal 0, then + the resulted tensor have the reduced dimension pruned. + + The above behavior is similar to numpy, with the exception that numpy default keepdims to + False instead of True. + +#### Version + +This version of the operator has been available since version 13 of the default ONNX operator set. + +Other versions of this operator: 1, 11 + +#### Attributes + +
+
axes : list of ints
+
A list of integers, along which to reduce. The default is to reduce over all the dimensions of the input tensor. Accepted range is [-r, r-1] where r = rank(data).
+
keepdims : int (default is 1)
+
Keep the reduced dimension or not, default 1 mean keep reduced dimension.
+
+ +#### Inputs + +
+
data (differentiable) : T
+
An input tensor.
+
+ +#### Outputs + +
+
reduced (differentiable) : T
+
Reduced output tensor.
+
+ +#### Type Constraints + +
+
T : tensor(uint32), tensor(uint64), tensor(int32), tensor(int64), tensor(float16), tensor(float), tensor(double), tensor(bfloat16)
+
Constrain input and output types to high-precision numeric tensors.
+
+ + +#### Examples + +
+default_axes_keepdims + +```python +shape = [3, 2, 2] +axes = None +keepdims = 1 + +node = onnx.helper.make_node( + 'ReduceProd', + inputs=['data'], + outputs=['reduced'], + keepdims=keepdims) + +data = np.array([[[1, 2], [3, 4]], [[5, 6], [7, 8]], [[9, 10], [11, 12]]], dtype=np.float32) +reduced = np.prod(data, axis=axes, keepdims=keepdims == 1) +#print(reduced) +#[[[4.790016e+08]]] + +expect(node, inputs=[data], outputs=[reduced], name='test_reduce_prod_default_axes_keepdims_example') + +np.random.seed(0) +data = np.random.uniform(-10, 10, shape).astype(np.float32) +reduced = np.prod(data, axis=axes, keepdims=keepdims == 1) +expect(node, inputs=[data], outputs=[reduced], name='test_reduce_prod_default_axes_keepdims_random') +``` + +
+ + +
+do_not_keepdims + +```python +shape = [3, 2, 2] +axes = [1] +keepdims = 0 + +node = onnx.helper.make_node( + 'ReduceProd', + inputs=['data'], + outputs=['reduced'], + axes=axes, + keepdims=keepdims) + +data = np.array([[[1, 2], [3, 4]], [[5, 6], [7, 8]], [[9, 10], [11, 12]]], dtype=np.float32) +reduced = np.prod(data, axis=tuple(axes), keepdims=keepdims == 1) +#print(reduced) +#[[3., 8.] +# [35., 48.] +# [99., 120.]] + +expect(node, inputs=[data], outputs=[reduced], name='test_reduce_prod_do_not_keepdims_example') + +np.random.seed(0) +data = np.random.uniform(-10, 10, shape).astype(np.float32) +reduced = np.prod(data, axis=tuple(axes), keepdims=keepdims == 1) +expect(node, inputs=[data], outputs=[reduced], name='test_reduce_prod_do_not_keepdims_random') +``` + +
+ + +
+keepdims + +```python +shape = [3, 2, 2] +axes = [1] +keepdims = 1 + +node = onnx.helper.make_node( + 'ReduceProd', + inputs=['data'], + outputs=['reduced'], + axes=axes, + keepdims=keepdims) + +data = np.array([[[1, 2], [3, 4]], [[5, 6], [7, 8]], [[9, 10], [11, 12]]], dtype=np.float32) +reduced = np.prod(data, axis=tuple(axes), keepdims=keepdims == 1) +#print(reduced) +#[[[3., 8.]] +# [[35., 48.]] +# [[99., 120.]]] + +expect(node, inputs=[data], outputs=[reduced], name='test_reduce_prod_keepdims_example') + +np.random.seed(0) +data = np.random.uniform(-10, 10, shape).astype(np.float32) +reduced = np.prod(data, axis=tuple(axes), keepdims=keepdims == 1) +expect(node, inputs=[data], outputs=[reduced], name='test_reduce_prod_keepdims_random') +``` + +
+ + +
+negative_axes_keepdims + +```python +shape = [3, 2, 2] +axes = [-2] +keepdims = 1 + +node = onnx.helper.make_node( + 'ReduceProd', + inputs=['data'], + outputs=['reduced'], + axes=axes, + keepdims=keepdims) + +data = np.array([[[1, 2], [3, 4]], [[5, 6], [7, 8]], [[9, 10], [11, 12]]], dtype=np.float32) +reduced = np.prod(data, axis=tuple(axes), keepdims=keepdims == 1) +# print(reduced) +#[[[3., 8.]] +# [[35., 48.]] +# [[99., 120.]]] + +expect(node, inputs=[data], outputs=[reduced], name='test_reduce_prod_negative_axes_keepdims_example') + +np.random.seed(0) +data = np.random.uniform(-10, 10, shape).astype(np.float32) +reduced = np.prod(data, axis=tuple(axes), keepdims=keepdims == 1) +expect(node, inputs=[data], outputs=[reduced], name='test_reduce_prod_negative_axes_keepdims_random') +``` + +
+ + +### **ReduceSum** + + Computes the sum of the input tensor's element along the provided axes. The resulted + tensor has the same rank as the input if keepdims equal 1. If keepdims equal 0, then + the resulted tensor have the reduced dimension pruned. + + The above behavior is similar to numpy, with the exception that numpy default keepdims to + False instead of True. + +#### Version + +This version of the operator has been available since version 13 of the default ONNX operator set. + +Other versions of this operator: 1, 11 + +#### Attributes + +
+
keepdims : int (default is 1)
+
Keep the reduced dimension or not, default 1 mean keep reduced dimension.
+
noop_with_empty_axes : int (default is 0)
+
Defines behaviour if 'axes' is empty. Default behaviour with 'false' is to reduce all axes. When axes is empty and this attribute is set to true, input tensor will not be reduced,and the output tensor would be equivalent to input tensor.
+
+ +#### Inputs (1 - 2) + +
+
data (differentiable) : T
+
An input tensor.
+
axes (optional, non-differentiable) : tensor(int64)
+
Optional input list of integers, along which to reduce. The default is to reduce over all the dimensions of the input tensor if 'noop_with_empty_axes' is false, else act as an Identity op when 'noop_with_empty_axes' is true. Accepted range is [-r, r-1] where r = rank(data).
+
+ +#### Outputs + +
+
reduced (differentiable) : T
+
Reduced output tensor.
+
+ +#### Type Constraints + +
+
T : tensor(uint32), tensor(uint64), tensor(int32), tensor(int64), tensor(float16), tensor(float), tensor(double), tensor(bfloat16)
+
Constrain input and output types to high-precision numeric tensors.
+
+ + +#### Examples + +
+default_axes_keepdims + +```python +shape = [3, 2, 2] +axes = np.array([], dtype=np.int64) +keepdims = 1 + +node = onnx.helper.make_node( + 'ReduceSum', + inputs=['data', 'axes'], + outputs=['reduced'], + keepdims=keepdims) + +data = np.array([[[1, 2], [3, 4]], [[5, 6], [7, 8]], [[9, 10], [11, 12]]], dtype=np.float32) +reduced = np.sum(data, axis=None, keepdims=keepdims == 1) +#print(reduced) +#[[[78.]]] + +expect(node, inputs=[data, axes], outputs=[reduced], name='test_reduce_sum_default_axes_keepdims_example') + +np.random.seed(0) +data = np.random.uniform(-10, 10, shape).astype(np.float32) +reduced = np.sum(data, axis=None, keepdims=keepdims == 1) + +expect(node, inputs=[data, axes], outputs=[reduced], name='test_reduce_sum_default_axes_keepdims_random') +``` + +
+ + +
+do_not_keepdims + +```python +shape = [3, 2, 2] +axes = np.array([1], dtype=np.int64) +keepdims = 0 + +node = onnx.helper.make_node( + 'ReduceSum', + inputs=['data', 'axes'], + outputs=['reduced'], + keepdims=keepdims) + +data = np.array([[[1, 2], [3, 4]], [[5, 6], [7, 8]], [[9, 10], [11, 12]]], dtype=np.float32) +reduced = np.sum(data, axis=tuple(axes.tolist()), keepdims=keepdims == 1) +#print(reduced) +#[[4., 6.] +# [12., 14.] +# [20., 22.]] + +expect(node, inputs=[data, axes], outputs=[reduced], name='test_reduce_sum_do_not_keepdims_example') + +np.random.seed(0) +data = np.random.uniform(-10, 10, shape).astype(np.float32) +reduced = np.sum(data, axis=tuple(axes.tolist()), keepdims=keepdims == 1) + +expect(node, inputs=[data, axes], outputs=[reduced], name='test_reduce_sum_do_not_keepdims_random') +``` + +
+ + +
+empty_axes_input_noop + +```python +shape = [3, 2, 2] +keepdims = 1 + +node = onnx.helper.make_node( + 'ReduceSum', + inputs=['data', 'axes'], + outputs=['reduced'], + keepdims=keepdims, + noop_with_empty_axes=True) + +data = np.array([[[1, 2], [3, 4]], [[5, 6], [7, 8]], [[9, 10], [11, 12]]], dtype=np.float32) +axes = np.array([], dtype=np.int64) +reduced = np.array(data) +#print(reduced) +#[[[1, 2], [3, 4]], [[5, 6], [7, 8]], [[9, 10], [11, 12]]] + +expect(node, inputs=[data, axes], outputs=[reduced], + name='test_reduce_sum_empty_axes_input_noop_example') + +np.random.seed(0) +data = np.random.uniform(-10, 10, shape).astype(np.float32) +reduced = np.array(data) + +expect(node, inputs=[data, axes], outputs=[reduced], name='test_reduce_sum_negative_axes_keepdims_random') +``` + +
+ + +
+keepdims + +```python +shape = [3, 2, 2] +axes = np.array([1], dtype=np.int64) +keepdims = 1 + +node = onnx.helper.make_node( + 'ReduceSum', + inputs=['data', 'axes'], + outputs=['reduced'], + keepdims=keepdims) + +data = np.array([[[1, 2], [3, 4]], [[5, 6], [7, 8]], [[9, 10], [11, 12]]], dtype=np.float32) +reduced = np.sum(data, axis=tuple(axes.tolist()), keepdims=keepdims == 1) +#print(reduced) +#[[[4., 6.]] +# [[12., 14.]] +# [[20., 22.]]] + +expect(node, inputs=[data, axes], outputs=[reduced], name='test_reduce_sum_keepdims_example') + +np.random.seed(0) +data = np.random.uniform(-10, 10, shape).astype(np.float32) +reduced = np.sum(data, axis=tuple(axes.tolist()), keepdims=keepdims == 1) + +expect(node, inputs=[data, axes], outputs=[reduced], name='test_reduce_sum_keepdims_random') +``` + +
+ + +
+negative_axes_keepdims + +```python +shape = [3, 2, 2] +axes = np.array([-2], dtype=np.int64) +keepdims = 1 + +node = onnx.helper.make_node( + 'ReduceSum', + inputs=['data', 'axes'], + outputs=['reduced'], + keepdims=keepdims) + +data = np.array([[[1, 2], [3, 4]], [[5, 6], [7, 8]], [[9, 10], [11, 12]]], dtype=np.float32) +reduced = np.sum(data, axis=tuple(axes.tolist()), keepdims=keepdims == 1) +# print(reduced) +#[[[4., 6.]] +# [[12., 14.]] +# [[20., 22.]]] + +expect(node, inputs=[data, axes], outputs=[reduced], + name='test_reduce_sum_negative_axes_keepdims_example') + +np.random.seed(0) +data = np.random.uniform(-10, 10, shape).astype(np.float32) +reduced = np.sum(data, axis=tuple( + axes.tolist()), keepdims=keepdims == 1) + +expect(node, inputs=[data, axes], outputs=[reduced], + name='test_reduce_sum_negative_axes_keepdims_random') +``` + +
+ + +### **ReduceSumSquare** + + Computes the sum square of the input tensor's element along the provided axes. The resulted + tensor has the same rank as the input if keepdims equal 1. If keepdims equal 0, then + the resulted tensor have the reduced dimension pruned. + + The above behavior is similar to numpy, with the exception that numpy default keepdims to + False instead of True. + +#### Version + +This version of the operator has been available since version 13 of the default ONNX operator set. + +Other versions of this operator: 1, 11 + +#### Attributes + +
+
axes : list of ints
+
A list of integers, along which to reduce. The default is to reduce over all the dimensions of the input tensor. Accepted range is [-r, r-1] where r = rank(data).
+
keepdims : int (default is 1)
+
Keep the reduced dimension or not, default 1 mean keep reduced dimension.
+
+ +#### Inputs + +
+
data (differentiable) : T
+
An input tensor.
+
+ +#### Outputs + +
+
reduced (differentiable) : T
+
Reduced output tensor.
+
+ +#### Type Constraints + +
+
T : tensor(uint32), tensor(uint64), tensor(int32), tensor(int64), tensor(float16), tensor(float), tensor(double), tensor(bfloat16)
+
Constrain input and output types to high-precision numeric tensors.
+
+ + +#### Examples + +
+default_axes_keepdims + +```python +shape = [3, 2, 2] +axes = None +keepdims = 1 + +node = onnx.helper.make_node( + 'ReduceSumSquare', + inputs=['data'], + outputs=['reduced'], + keepdims=keepdims) + +data = np.array([[[1, 2], [3, 4]], [[5, 6], [7, 8]], [[9, 10], [11, 12]]], dtype=np.float32) +reduced = np.sum(np.square(data), axis=axes, keepdims=keepdims == 1) +#print(reduced) +#[[[650.]]] + +expect(node, inputs=[data], outputs=[reduced], name='test_reduce_sum_square_default_axes_keepdims_example') + +np.random.seed(0) +data = np.random.uniform(-10, 10, shape).astype(np.float32) +reduced = np.sum(np.square(data), axis=axes, keepdims=keepdims == 1) + +expect(node, inputs=[data], outputs=[reduced], name='test_reduce_sum_square_default_axes_keepdims_random') +``` + +
+ + +
+do_not_keepdims + +```python +shape = [3, 2, 2] +axes = [1] +keepdims = 0 + +node = onnx.helper.make_node( + 'ReduceSumSquare', + inputs=['data'], + outputs=['reduced'], + axes=axes, + keepdims=keepdims) + +data = np.array([[[1, 2], [3, 4]], [[5, 6], [7, 8]], [[9, 10], [11, 12]]], dtype=np.float32) +reduced = np.sum(np.square(data), axis=tuple(axes), keepdims=keepdims == 1) +#print(reduced) +#[[10., 20.] +# [74., 100.] +# [202., 244.]] + +expect(node, inputs=[data], outputs=[reduced], name='test_reduce_sum_square_do_not_keepdims_example') + +np.random.seed(0) +data = np.random.uniform(-10, 10, shape).astype(np.float32) +reduced = np.sum(np.square(data), axis=tuple(axes), keepdims=keepdims == 1) + +expect(node, inputs=[data], outputs=[reduced], name='test_reduce_sum_square_do_not_keepdims_random') +``` + +
+ + +
+keepdims + +```python +shape = [3, 2, 2] +axes = [1] +keepdims = 1 + +node = onnx.helper.make_node( + 'ReduceSumSquare', + inputs=['data'], + outputs=['reduced'], + axes=axes, + keepdims=keepdims) + +data = np.array([[[1, 2], [3, 4]], [[5, 6], [7, 8]], [[9, 10], [11, 12]]], dtype=np.float32) +reduced = np.sum(np.square(data), axis=tuple(axes), keepdims=keepdims == 1) +#print(reduced) +#[[[10., 20.]] +# [[74., 100.]] +# [[202., 244.]]] + +expect(node, inputs=[data], outputs=[reduced], name='test_reduce_sum_square_keepdims_example') + +np.random.seed(0) +data = np.random.uniform(-10, 10, shape).astype(np.float32) +reduced = np.sum(np.square(data), axis=tuple(axes), keepdims=keepdims == 1) + +expect(node, inputs=[data], outputs=[reduced], name='test_reduce_sum_square_keepdims_random') +``` + +
+ + +
+negative_axes_keepdims + +```python +shape = [3, 2, 2] +axes = [-2] +keepdims = 1 + +node = onnx.helper.make_node( + 'ReduceSumSquare', + inputs=['data'], + outputs=['reduced'], + axes=axes, + keepdims=keepdims) + +data = np.array([[[1, 2], [3, 4]], [[5, 6], [7, 8]], [[9, 10], [11, 12]]], dtype=np.float32) +reduced = np.sum(np.square(data), axis=tuple(axes), keepdims=keepdims == 1) +# print(reduced) +#[[[10., 20.s]] +# [[74., 100.]] +# [[202., 244.]]] + +expect(node, inputs=[data], outputs=[reduced], name='test_reduce_sum_square_negative_axes_keepdims_example') + +np.random.seed(0) +data = np.random.uniform(-10, 10, shape).astype(np.float32) +reduced = np.sum(np.square(data), axis=tuple(axes), keepdims=keepdims == 1) + +expect(node, inputs=[data], outputs=[reduced], name='test_reduce_sum_square_negative_axes_keepdims_random') +``` + +
+ + +### **Relu** + + Relu takes one input data (Tensor) and produces one output data + (Tensor) where the rectified linear function, y = max(0, x), is applied to + the tensor elementwise. + +#### Version + +This version of the operator has been available since version 14 of the default ONNX operator set. + +Other versions of this operator: 1, 6, 13 + +#### Inputs + +
+
X (differentiable) : T
+
Input tensor
+
+ +#### Outputs + +
+
Y (differentiable) : T
+
Output tensor
+
+ +#### Type Constraints + +
+
T : tensor(float), tensor(int32), tensor(int8), tensor(int16), tensor(int64), tensor(float16), tensor(double), tensor(bfloat16)
+
Constrain input and output types to signed numeric tensors.
+
+ + +#### Examples + +
+relu + +```python +node = onnx.helper.make_node( + 'Relu', + inputs=['x'], + outputs=['y'], +) +x = np.random.randn(3, 4, 5).astype(np.float32) +y = np.clip(x, 0, np.inf) + +expect(node, inputs=[x], outputs=[y], + name='test_relu') +``` + +
+ + +### **Reshape** + + Reshape the input tensor similar to numpy.reshape. + First input is the data tensor, second input is a shape tensor which specifies the output shape. It outputs the reshaped tensor. + At most one dimension of the new shape can be -1. In this case, the value is + inferred from the size of the tensor and the remaining dimensions. A dimension + could also be 0, in which case the actual dimension value is unchanged (i.e. taken + from the input tensor). If 'allowzero' is set, and the new shape includes 0, the + dimension will be set explicitly to zero (i.e. not taken from input tensor) + +#### Version + +This version of the operator has been available since version 14 of the default ONNX operator set. + +Other versions of this operator: 1, 5, 13 + +#### Attributes + +
+
allowzero : int (default is 0)
+
(Optional) By default, when any value in the 'shape' input is equal to zero the corresponding dimension value is copied from the input tensor dynamically. allowzero=1 indicates that if any value in the 'shape' input is set to zero, the zero value is honored, similar to NumPy.
+
+ +#### Inputs + +
+
data (differentiable) : T
+
An input tensor.
+
shape (non-differentiable) : tensor(int64)
+
Specified shape for output.
+
+ +#### Outputs + +
+
reshaped (differentiable) : T
+
Reshaped data.
+
+ +#### Type Constraints + +
+
T : tensor(uint8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(int8), tensor(int16), tensor(int32), tensor(int64), tensor(bfloat16), tensor(float16), tensor(float), tensor(double), tensor(string), tensor(bool), tensor(complex64), tensor(complex128)
+
Constrain input and output types to all tensor types.
+
+ + +#### Examples + +
+allowzero + +```python +original_shape = [0, 3, 4] +test_cases = { + 'allowzero_reordered': np.array([3, 4, 0], dtype=np.int64), +} +data = np.random.random_sample(original_shape).astype(np.float32) + +for test_name, shape in test_cases.items(): + node = onnx.helper.make_node( + 'Reshape', + inputs=['data', 'shape'], + outputs=['reshaped'], + allowzero=1, # if allowzero=1, final shape = (3, 4, 0) + # if allowzero=0, final shape = (3, 4, 4) + ) + + reshaped = reshape_reference_implementation(data, shape, allowzero=1) + + expect(node, inputs=[data, shape], outputs=[reshaped], + name='test_reshape_' + test_name) +``` + +
+ + +
+reshape + +```python +original_shape = [2, 3, 4] +test_cases = { + 'reordered_all_dims': np.array([4, 2, 3], dtype=np.int64), + 'reordered_last_dims': np.array([2, 4, 3], dtype=np.int64), + 'reduced_dims': np.array([2, 12], dtype=np.int64), + 'extended_dims': np.array([2, 3, 2, 2], dtype=np.int64), + 'one_dim': np.array([24], dtype=np.int64), + 'negative_dim': np.array([2, -1, 2], dtype=np.int64), + 'negative_extended_dims': np.array([-1, 2, 3, 4], dtype=np.int64), + 'zero_dim': np.array([2, 0, 4, 1], dtype=np.int64), + 'zero_and_negative_dim': np.array([2, 0, 1, -1], dtype=np.int64), +} +data = np.random.random_sample(original_shape).astype(np.float32) + +for test_name, shape in test_cases.items(): + node = onnx.helper.make_node( + 'Reshape', + inputs=['data', 'shape'], + outputs=['reshaped'], + ) + + reshaped = reshape_reference_implementation(data, shape) + + expect(node, inputs=[data, shape], outputs=[reshaped], + name='test_reshape_' + test_name) +``` + +
+ + +### **Resize** + + Resize the input tensor. In general, it calculates every value in the output tensor as a weighted average of neighborhood (a.k.a. sampling locations) in the input tensor. + Each dimension value of the output tensor is: + output_dimension = floor(input_dimension * (roi_end - roi_start) * scale) if input \"sizes\" is not specified. + +#### Version + +This version of the operator has been available since version 13 of the default ONNX operator set. + +Other versions of this operator: 10, 11 + +#### Attributes + +
+
coordinate_transformation_mode : string (default is half_pixel)
+
+This attribute describes how to transform the coordinate in the resized tensor to the coordinate in the original tensor.
+ +The coordinate of each dimension is transformed individually. Let's describe a case using axis x as an example. +Denote x_resized as the coordinate of axis x in the resized tensor, x_original as the coordinate of axis x in the original tensor, length_original as the length of the original tensor in axis x, length_resized as the length of the resized tensor in axis x, roi_x = (start_x, end_x) of the axis x in input "roi", scale = length_resized / length_original,
+ +if coordinate_transformation_mode is "half_pixel",
+x_original = (x_resized + 0.5) / scale - 0.5,
+ +if coordinate_transformation_mode is "pytorch_half_pixel",
+x_original = length_resized > 1 ? (x_resized + 0.5) / scale - 0.5 : 0,
+ +if coordinate_transformation_mode is "align_corners",
+x_original = x_resized * (length_original - 1) / (length_resized - 1),
+ +if coordinate_transformation_mode is "asymmetric",
+x_original = x_resized / scale,
+ +if coordinate_transformation_mode is "tf_crop_and_resize",
+x_original = length_resized > 1 ? start_x * (length_original - 1) + x_resized * (end_x - start_x) * (length_original - 1) / (length_resized - 1) : 0.5 * (start_x + end_x) * (length_original - 1).
+
cubic_coeff_a : float (default is -0.75)
+
The coefficient 'a' used in cubic interpolation. Two common choice are -0.5 (in some cases of TensorFlow) and -0.75 (in PyTorch). Check out Equation (4) in https://ieeexplore.ieee.org/document/1163711 for the details. This attribute is valid only if "mode" is "cubic".
+
exclude_outside : int (default is 0)
+
If set to 1, the weight of sampling locations outside the tensor will be set to 0 and the weight will be renormalized so that their sum is 1.0. The default value is 0.
+
extrapolation_value : float (default is 0.0)
+
When coordinate_transformation_mode is "tf_crop_and_resize" and x_original is outside the range [0, length_original - 1], this value is used as the corresponding output value. Default is 0.0f.
+
mode : string (default is nearest)
+
Three interpolation modes: nearest (default), linear and cubic. The "linear" mode includes linear interpolation for 1D tensor and N-linear interpolation for N-D tensor (for example, bilinear interpolation for 2D tensor). The "cubic" mode includes cubic interpolation for 1D tensor and N-cubic interpolation for N-D tensor (for example, bicubic interpolation for 2D tensor).
+
nearest_mode : string (default is round_prefer_floor)
+
Four modes: round_prefer_floor (default, as known as round half down), round_prefer_ceil (as known as round half up), floor, ceil. Only used by nearest interpolation. It indicates how to get "nearest" pixel in input tensor from x_original, so this attribute is valid only if "mode" is "nearest".
+
+ +#### Inputs (1 - 4) + +
+
X (differentiable) : T1
+
N-D tensor
+
roi (optional, non-differentiable) : T2
+
1-D tensor given as [start1, ..., startN, end1, ..., endN], where N is the rank of X. The RoIs' coordinates are normalized in the coordinate system of the input image. It only takes effect when coordinate_transformation_mode is "tf_crop_and_resize"
+
scales (optional, non-differentiable) : tensor(float)
+
The scale array along each dimension. It takes value greater than 0. If it's less than 1, it's sampling down, otherwise, it's upsampling. The number of elements of 'scales' should be the same as the rank of input 'X'. One of 'scales' and 'sizes' MUST be specified and it is an error if both are specified. If 'sizes' is needed, the user can use an empty string as the name of 'scales' in this operator's input list.
+
sizes (optional, non-differentiable) : tensor(int64)
+
The size of the output tensor. The number of elements of 'sizes' should be the same as the rank of input 'X'. Only one of 'scales' and 'sizes' can be specified.
+
+ +#### Outputs + +
+
Y (differentiable) : T1
+
N-D tensor after resizing
+
+ +#### Type Constraints + +
+
T1 : tensor(uint8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(int8), tensor(int16), tensor(int32), tensor(int64), tensor(bfloat16), tensor(float16), tensor(float), tensor(double), tensor(string), tensor(bool), tensor(complex64), tensor(complex128)
+
Constrain input 'X' and output 'Y' to all tensor types.
+
T2 : tensor(float16), tensor(float), tensor(double)
+
Constrain roi type to float or double.
+
+ + +#### Examples + +
+resize_downsample_scales_cubic + +```python +node = onnx.helper.make_node( + 'Resize', + inputs=['X', '', 'scales'], + outputs=['Y'], + mode='cubic', +) + +data = np.array([[[ + [1, 2, 3, 4], + [5, 6, 7, 8], + [9, 10, 11, 12], + [13, 14, 15, 16], +]]], dtype=np.float32) + +scales = np.array([1.0, 1.0, 0.8, 0.8], dtype=np.float32) + +# [[[[ 1.47119141 2.78125 4.08251953] +# [ 6.71142578 8.02148438 9.32275391] +# [11.91650391 13.2265625 14.52783203]]]] +output = interpolate_nd( + data, cubic_coeffs, scale_factors=scales).astype(np.float32) + +expect(node, inputs=[data, scales], outputs=[output], + name='test_resize_downsample_scales_cubic') +``` + +
+ + +
+resize_downsample_scales_cubic_A_n0p5_exclude_outside + +```python +node = onnx.helper.make_node( + 'Resize', + inputs=['X', '', 'scales'], + outputs=['Y'], + mode='cubic', + cubic_coeff_a=-0.5, + exclude_outside=True +) + +data = np.array([[[ + [1, 2, 3, 4], + [5, 6, 7, 8], + [9, 10, 11, 12], + [13, 14, 15, 16], +]]], dtype=np.float32) + +scales = np.array([1.0, 1.0, 0.8, 0.8], dtype=np.float32) + +# [[[[ 1.36812675 2.6695014 4.0133367 ] +# [ 6.57362535 7.875 9.2188353 ] +# [11.94896657 13.25034122 14.59417652]]]] +output = interpolate_nd(data, lambda x: cubic_coeffs(x, A=-0.5), scale_factors=scales, + exclude_outside=True).astype(np.float32) + +expect(node, inputs=[data, scales], outputs=[output], + name='test_resize_downsample_scales_cubic_A_n0p5_exclude_outside') +``` + +
+ + +
+resize_downsample_scales_cubic_align_corners + +```python +node = onnx.helper.make_node( + 'Resize', + inputs=['X', '', 'scales'], + outputs=['Y'], + mode='cubic', + coordinate_transformation_mode='align_corners' +) + +data = np.array([[[ + [1, 2, 3, 4], + [5, 6, 7, 8], + [9, 10, 11, 12], + [13, 14, 15, 16], +]]], dtype=np.float32) + +scales = np.array([1.0, 1.0, 0.8, 0.8], dtype=np.float32) + +# [[[[ 1. 2.39519159 3.79038317] +# [ 6.58076634 7.97595793 9.37114951] +# [12.16153268 13.55672427 14.95191585]]]] +output = interpolate_nd( + data, cubic_coeffs, scale_factors=scales, coordinate_transformation_mode='align_corners').astype(np.float32) + +expect(node, inputs=[data, scales], outputs=[output], + name='test_resize_downsample_scales_cubic_align_corners') +``` + +
+ + +
+resize_downsample_scales_linear + +```python +node = onnx.helper.make_node( + 'Resize', + inputs=['X', '', 'scales'], + outputs=['Y'], + mode='linear', +) + +data = np.array([[[ + [1, 2, 3, 4], + [5, 6, 7, 8], +]]], dtype=np.float32) + +scales = np.array([1.0, 1.0, 0.6, 0.6], dtype=np.float32) + +# [[[[2.6666665 4.3333331]]]] +output = interpolate_nd( + data, linear_coeffs, scale_factors=scales).astype(np.float32) + +expect(node, inputs=[data, scales], outputs=[output], + name='test_resize_downsample_scales_linear') +``` + +
+ + +
+resize_downsample_scales_linear_align_corners + +```python +node = onnx.helper.make_node( + 'Resize', + inputs=['X', '', 'scales'], + outputs=['Y'], + mode='linear', + coordinate_transformation_mode='align_corners' +) + +data = np.array([[[ + [1, 2, 3, 4], + [5, 6, 7, 8], +]]], dtype=np.float32) + +scales = np.array([1.0, 1.0, 0.6, 0.6], dtype=np.float32) + +# [[[[1. 3.142857]]]] +output = interpolate_nd( + data, linear_coeffs, scale_factors=scales, coordinate_transformation_mode='align_corners').astype(np.float32) + +expect(node, inputs=[data, scales], outputs=[output], + name='test_resize_downsample_scales_linear_align_corners') +``` + +
+ + +
+resize_downsample_scales_nearest + +```python +node = onnx.helper.make_node( + 'Resize', + inputs=['X', '', 'scales'], + outputs=['Y'], + mode='nearest', +) + +data = np.array([[[ + [1, 2, 3, 4], + [5, 6, 7, 8], +]]], dtype=np.float32) + +scales = np.array([1.0, 1.0, 0.6, 0.6], dtype=np.float32) + +# [[[[1. 3.]]]] +output = interpolate_nd( + data, nearest_coeffs, scale_factors=scales).astype(np.float32) + +expect(node, inputs=[data, scales], outputs=[output], + name='test_resize_downsample_scales_nearest') +``` + +
+ + +
+resize_downsample_sizes_cubic + +```python +node = onnx.helper.make_node( + 'Resize', + inputs=['X', '', '', 'sizes'], + outputs=['Y'], + mode='cubic', +) + +data = np.array([[[ + [1, 2, 3, 4], + [5, 6, 7, 8], + [9, 10, 11, 12], + [13, 14, 15, 16], +]]], dtype=np.float32) + +sizes = np.array([1, 1, 3, 3], dtype=np.int64) + +# [[[[ 1.63078704 3.00462963 4.37847222] +# [ 7.12615741 8.5 9.87384259] +# [12.62152778 13.99537037 15.36921296]]]] +output = interpolate_nd( + data, cubic_coeffs, output_size=sizes).astype(np.float32) + +expect(node, inputs=[data, sizes], outputs=[output], + name='test_resize_downsample_sizes_cubic') +``` + +
+ + +
+resize_downsample_sizes_linear_pytorch_half_pixel + +```python +node = onnx.helper.make_node( + 'Resize', + inputs=['X', '', '', 'sizes'], + outputs=['Y'], + mode='linear', + coordinate_transformation_mode='pytorch_half_pixel' +) + +data = np.array([[[ + [1, 2, 3, 4], + [5, 6, 7, 8], + [9, 10, 11, 12], + [13, 14, 15, 16], +]]], dtype=np.float32) + +sizes = np.array([1, 1, 3, 1], dtype=np.int64) + +# [[[[ 1.6666666] +# [ 7. ] +# [12.333333 ]]]] +output = interpolate_nd( + data, linear_coeffs, output_size=sizes, coordinate_transformation_mode='pytorch_half_pixel').astype(np.float32) + +expect(node, inputs=[data, sizes], outputs=[output], + name='test_resize_downsample_sizes_linear_pytorch_half_pixel') +``` + +
+ + +
+resize_downsample_sizes_nearest + +```python +node = onnx.helper.make_node( + 'Resize', + inputs=['X', '', '', 'sizes'], + outputs=['Y'], + mode='nearest', +) + +data = np.array([[[ + [1, 2, 3, 4], + [5, 6, 7, 8], +]]], dtype=np.float32) + +sizes = np.array([1, 1, 1, 3], dtype=np.int64) + +# [[[[1. 3.]]]] +output = interpolate_nd( + data, nearest_coeffs, output_size=sizes).astype(np.float32) + +expect(node, inputs=[data, sizes], outputs=[output], + name='test_resize_downsample_sizes_nearest') +``` + +
+ + +
+resize_tf_crop_and_resize + +```python +node = onnx.helper.make_node( + 'Resize', + inputs=['X', 'roi', '', 'sizes'], + outputs=['Y'], + mode='linear', + coordinate_transformation_mode='tf_crop_and_resize' +) + +data = np.array([[[ + [1, 2, 3, 4], + [5, 6, 7, 8], + [9, 10, 11, 12], + [13, 14, 15, 16], +]]], dtype=np.float32) + +# Note: for some rois, the result may be different with that of TF for inaccurate floating point +roi = np.array([0, 0, 0.4, 0.6, 1, 1, 0.6, 0.8], dtype=np.float32) +sizes = np.array([1, 1, 3, 3], dtype=np.int64) + +# [[[[ 7.6000004 7.9 8.2 ] +# [ 8.8 9.1 9.400001 ] +# [10. 10.3 10.6 ]]]] +output = interpolate_nd(data, linear_coeffs, output_size=sizes, roi=roi, + coordinate_transformation_mode='tf_crop_and_resize').astype(np.float32) + +expect(node, inputs=[data, roi, sizes], outputs=[output], + name='test_resize_tf_crop_and_resize') +``` + +
+ + +
+resize_tf_crop_and_resize_extrapolation_value + +```python +node = onnx.helper.make_node( + 'Resize', + inputs=['X', 'roi', '', 'sizes'], + outputs=['Y'], + mode='linear', + coordinate_transformation_mode='tf_crop_and_resize', + extrapolation_value=10.0 +) + +data = np.array([[[ + [1, 2, 3, 4], + [5, 6, 7, 8], + [9, 10, 11, 12], + [13, 14, 15, 16], +]]], dtype=np.float32) + +# Note: for some rois, the result may be different with that of TF for inaccurate floating point +roi = np.array([0, 0, 0.4, 0.6, 1, 1, 1.2, 1.7], dtype=np.float32) +sizes = np.array([1, 1, 3, 3], dtype=np.int64) + +# [[[[ 7.6000004 10. 10. ] +# [12.400001 10. 10. ] +# [10. 10. 10. ]]]] +output = interpolate_nd(data, linear_coeffs, output_size=sizes, roi=roi, + coordinate_transformation_mode='tf_crop_and_resize', extrapolation_value=10.0).astype(np.float32) + +expect(node, inputs=[data, roi, sizes], outputs=[output], + name='test_resize_tf_crop_and_resize') +``` + +
+ + +
+resize_upsample_scales_cubic + +```python +node = onnx.helper.make_node( + 'Resize', + inputs=['X', '', 'scales'], + outputs=['Y'], + mode='cubic', +) + +data = np.array([[[ + [1, 2, 3, 4], + [5, 6, 7, 8], + [9, 10, 11, 12], + [13, 14, 15, 16], +]]], dtype=np.float32) + +scales = np.array([1.0, 1.0, 2.0, 2.0], dtype=np.float32) + +# [[[[ 0.47265625 0.76953125 1.24609375 1.875 2.28125 +# 2.91015625 3.38671875 3.68359375] +# [ 1.66015625 1.95703125 2.43359375 3.0625 3.46875 +# 4.09765625 4.57421875 4.87109375] +# [ 3.56640625 3.86328125 4.33984375 4.96875 5.375 +# 6.00390625 6.48046875 6.77734375] +# [ 6.08203125 6.37890625 6.85546875 7.484375 7.890625 +# 8.51953125 8.99609375 9.29296875] +# [ 7.70703125 8.00390625 8.48046875 9.109375 9.515625 +# 10.14453125 10.62109375 10.91796875] +# [10.22265625 10.51953125 10.99609375 11.625 12.03125 +# 12.66015625 13.13671875 13.43359375] +# [12.12890625 12.42578125 12.90234375 13.53125 13.9375 +# 14.56640625 15.04296875 15.33984375] +# [13.31640625 13.61328125 14.08984375 14.71875 15.125 +# 15.75390625 16.23046875 16.52734375]]]] +output = interpolate_nd( + data, cubic_coeffs, scale_factors=scales).astype(np.float32) + +expect(node, inputs=[data, scales], outputs=[output], + name='test_resize_upsample_scales_cubic') +``` + +
+ + +
+resize_upsample_scales_cubic_A_n0p5_exclude_outside + +```python +node = onnx.helper.make_node( + 'Resize', + inputs=['X', '', 'scales'], + outputs=['Y'], + mode='cubic', + cubic_coeff_a=-0.5, + exclude_outside=True +) + +data = np.array([[[ + [1, 2, 3, 4], + [5, 6, 7, 8], + [9, 10, 11, 12], + [13, 14, 15, 16], +]]], dtype=np.float32) + +scales = np.array([1.0, 1.0, 2.0, 2.0], dtype=np.float32) + +# [[[[ 0.55882353 0.81494204 1.35698249 1.89705882 2.39705882 +# 2.93713516 3.47917561 3.73529412] +# [ 1.58329755 1.83941606 2.38145651 2.92153285 3.42153285 +# 3.96160918 4.50364964 4.75976814] +# [ 3.75145936 4.00757787 4.54961832 5.08969466 5.58969466 +# 6.12977099 6.67181144 6.92792995] +# [ 5.91176471 6.16788321 6.70992366 7.25 7.75 +# 8.29007634 8.83211679 9.08823529] +# [ 7.91176471 8.16788321 8.70992366 9.25 9.75 +# 10.29007634 10.83211679 11.08823529] +# [10.07207005 10.32818856 10.87022901 11.41030534 11.91030534 +# 12.45038168 12.99242213 13.24854064] +# [12.24023186 12.49635036 13.03839082 13.57846715 14.07846715 +# 14.61854349 15.16058394 15.41670245] +# [13.26470588 13.52082439 14.06286484 14.60294118 15.10294118 +# 15.64301751 16.18505796 16.44117647]]]] +output = interpolate_nd(data, lambda x: cubic_coeffs(x, A=-0.5), scale_factors=scales, + exclude_outside=True).astype(np.float32) + +expect(node, inputs=[data, scales], outputs=[output], + name='test_resize_upsample_scales_cubic_A_n0p5_exclude_outside') +``` + +
+ + +
+resize_upsample_scales_cubic_align_corners + +```python +node = onnx.helper.make_node( + 'Resize', + inputs=['X', '', 'scales'], + outputs=['Y'], + mode='cubic', + coordinate_transformation_mode='align_corners' +) + +data = np.array([[[ + [1, 2, 3, 4], + [5, 6, 7, 8], + [9, 10, 11, 12], + [13, 14, 15, 16], +]]], dtype=np.float32) + +scales = np.array([1.0, 1.0, 2.0, 2.0], dtype=np.float32) + +# [[[[ 1. 1.34110787 1.80029155 2.32944606 2.67055394 +# 3.19970845 3.65889213 4. ] +# [ 2.36443149 2.70553936 3.16472303 3.69387755 4.03498542 +# 4.56413994 5.02332362 5.36443149] +# [ 4.20116618 4.54227405 5.00145773 5.53061224 5.87172012 +# 6.40087464 6.86005831 7.20116618] +# [ 6.31778426 6.65889213 7.1180758 7.64723032 7.98833819 +# 8.51749271 8.97667638 9.31778426] +# [ 7.68221574 8.02332362 8.48250729 9.01166181 9.35276968 +# 9.8819242 10.34110787 10.68221574] +# [ 9.79883382 10.13994169 10.59912536 11.12827988 11.46938776 +# 11.99854227 12.45772595 12.79883382] +# [11.63556851 11.97667638 12.43586006 12.96501458 13.30612245 +# 13.83527697 14.29446064 14.63556851] +# [13. 13.34110787 13.80029155 14.32944606 14.67055394 +# 15.19970845 15.65889213 16. ]]]] +output = interpolate_nd( + data, cubic_coeffs, scale_factors=scales, coordinate_transformation_mode='align_corners').astype(np.float32) + +expect(node, inputs=[data, scales], outputs=[output], + name='test_resize_upsample_scales_cubic_align_corners') +``` + +
+ + +
+resize_upsample_scales_cubic_asymmetric + +```python +node = onnx.helper.make_node( + 'Resize', + inputs=['X', '', 'scales'], + outputs=['Y'], + mode='cubic', + coordinate_transformation_mode='asymmetric' +) + +data = np.array([[[ + [1, 2, 3, 4], + [5, 6, 7, 8], + [9, 10, 11, 12], + [13, 14, 15, 16], +]]], dtype=np.float32) + +scales = np.array([1.0, 1.0, 2.0, 2.0], dtype=np.float32) + +# [[[[ 1. 1.40625 2. 2.5 3. 3.59375 4. +# 4.09375] +# [ 2.625 3.03125 3.625 4.125 4.625 5.21875 5.625 +# 5.71875] +# [ 5. 5.40625 6. 6.5 7. 7.59375 8. +# 8.09375] +# [ 7. 7.40625 8. 8.5 9. 9.59375 10. +# 10.09375] +# [ 9. 9.40625 10. 10.5 11. 11.59375 12. +# 12.09375] +# [11.375 11.78125 12.375 12.875 13.375 13.96875 14.375 +# 14.46875] +# [13. 13.40625 14. 14.5 15. 15.59375 16. +# 16.09375] +# [13.375 13.78125 14.375 14.875 15.375 15.96875 16.375 +# 16.46875]]]] +output = interpolate_nd(data, lambda x: cubic_coeffs(x, A=-0.75), scale_factors=scales, + coordinate_transformation_mode='asymmetric').astype(np.float32) + +expect(node, inputs=[data, scales], outputs=[output], + name='test_resize_upsample_scales_cubic_asymmetric') +``` + +
+ + +
+resize_upsample_scales_linear + +```python +node = onnx.helper.make_node( + 'Resize', + inputs=['X', '', 'scales'], + outputs=['Y'], + mode='linear', +) + +data = np.array([[[ + [1, 2], + [3, 4], +]]], dtype=np.float32) + +scales = np.array([1.0, 1.0, 2.0, 2.0], dtype=np.float32) + +# [[[[1. 1.25 1.75 2. ] +# [1.5 1.75 2.25 2.5 ] +# [2.5 2.75 3.25 3.5 ] +# [3. 3.25 3.75 4. ]]]] +output = interpolate_nd( + data, linear_coeffs, scale_factors=scales).astype(np.float32) + +expect(node, inputs=[data, scales], outputs=[output], + name='test_resize_upsample_scales_linear') +``` + +
+ + +
+resize_upsample_scales_linear_align_corners + +```python +node = onnx.helper.make_node( + 'Resize', + inputs=['X', '', 'scales'], + outputs=['Y'], + mode='linear', + coordinate_transformation_mode='align_corners' +) + +data = np.array([[[ + [1, 2], + [3, 4], +]]], dtype=np.float32) + +scales = np.array([1.0, 1.0, 2.0, 2.0], dtype=np.float32) + +# [[[[1. 1.33333333 1.66666667 2. ] +# [1.66666667 2. 2.33333333 2.66666667] +# [2.33333333 2.66666667 3. 3.33333333] +# [3. 3.33333333 3.66666667 4. ]]]] +output = interpolate_nd( + data, linear_coeffs, scale_factors=scales, coordinate_transformation_mode='align_corners').astype(np.float32) + +expect(node, inputs=[data, scales], outputs=[output], + name='test_resize_upsample_scales_linear_align_corners') +``` + +
+ + +
+resize_upsample_scales_nearest + +```python +node = onnx.helper.make_node( + 'Resize', + inputs=['X', '', 'scales'], + outputs=['Y'], + mode='nearest', +) + +data = np.array([[[ + [1, 2], + [3, 4], +]]], dtype=np.float32) + +scales = np.array([1.0, 1.0, 2.0, 3.0], dtype=np.float32) + +# [[[[1. 1. 1. 2. 2. 2.] +# [1. 1. 1. 2. 2. 2.] +# [3. 3. 3. 4. 4. 4.] +# [3. 3. 3. 4. 4. 4.]]]] +output = interpolate_nd( + data, nearest_coeffs, scale_factors=scales).astype(np.float32) + +expect(node, inputs=[data, scales], outputs=[output], + name='test_resize_upsample_scales_nearest') +``` + +
+ + +
+resize_upsample_sizes_cubic + +```python +node = onnx.helper.make_node( + 'Resize', + inputs=['X', '', '', 'sizes'], + outputs=['Y'], + mode='cubic', +) + +data = np.array([[[ + [1, 2, 3, 4], + [5, 6, 7, 8], + [9, 10, 11, 12], + [13, 14, 15, 16], +]]], dtype=np.float32) + +sizes = np.array([1, 1, 9, 10], dtype=np.int64) + +# [[[[ 0.45507922 0.64057922 0.97157922 1.42257922 1.90732922 +# 2.22332922 2.70807922 3.15907922 3.49007922 3.67557922] +# [ 1.39437963 1.57987963 1.91087963 2.36187963 2.84662963 +# 3.16262963 3.64737963 4.09837963 4.42937963 4.61487963] +# [ 2.95130693 3.13680693 3.46780693 3.91880693 4.40355693 +# 4.71955693 5.20430693 5.65530693 5.98630693 6.17180693] +# [ 5.20525069 5.39075069 5.72175069 6.17275069 6.65750069 +# 6.97350069 7.45825069 7.90925069 8.24025069 8.42575069] +# [ 6.88975 7.07525 7.40625 7.85725 8.342 +# 8.658 9.14275 9.59375 9.92475 10.11025 ] +# [ 8.57424931 8.75974931 9.09074931 9.54174931 10.02649931 +# 10.34249931 10.82724931 11.27824931 11.60924931 11.79474931] +# [10.82819307 11.01369307 11.34469307 11.79569307 12.28044307 +# 12.59644307 13.08119307 13.53219307 13.86319307 14.04869307] +# [12.38512037 12.57062037 12.90162037 13.35262037 13.83737037 +# 14.15337037 14.63812037 15.08912037 15.42012037 15.60562037] +# [13.32442078 13.50992078 13.84092078 14.29192078 14.77667078 +# 15.09267078 15.57742078 16.02842078 16.35942078 16.54492078]]]] +output = interpolate_nd( + data, cubic_coeffs, output_size=sizes).astype(np.float32) + +expect(node, inputs=[data, sizes], outputs=[output], + name='test_resize_upsample_sizes_cubic') +``` + +
+ + +
+resize_upsample_sizes_nearest + +```python +node = onnx.helper.make_node( + 'Resize', + inputs=['X', '', '', 'sizes'], + outputs=['Y'], + mode='nearest', +) + +data = np.array([[[ + [1, 2], + [3, 4], +]]], dtype=np.float32) + +sizes = np.array([1, 1, 7, 8], dtype=np.int64) + +# [[[[1. 1. 1. 1. 2. 2. 2. 2.] +# [1. 1. 1. 1. 2. 2. 2. 2.] +# [1. 1. 1. 1. 2. 2. 2. 2.] +# [1. 1. 1. 1. 2. 2. 2. 2.] +# [3. 3. 3. 3. 4. 4. 4. 4.] +# [3. 3. 3. 3. 4. 4. 4. 4.] +# [3. 3. 3. 3. 4. 4. 4. 4.]]]] +output = interpolate_nd( + data, nearest_coeffs, output_size=sizes).astype(np.float32) + +expect(node, inputs=[data, sizes], outputs=[output], + name='test_resize_upsample_sizes_nearest') +``` + +
+ + +
+resize_upsample_sizes_nearest_ceil_half_pixel + +```python +node = onnx.helper.make_node( + 'Resize', + inputs=['X', '', '', 'sizes'], + outputs=['Y'], + mode='nearest', + coordinate_transformation_mode='half_pixel', + nearest_mode='ceil' +) + +data = np.array([[[ + [1, 2, 3, 4], + [5, 6, 7, 8], + [9, 10, 11, 12], + [13, 14, 15, 16], +]]], dtype=np.float32) + +sizes = np.array([1, 1, 8, 8], dtype=np.int64) + +# [[[[ 1. 2. 2. 3. 3. 4. 4. 4.] +# [ 5. 6. 6. 7. 7. 8. 8. 8.] +# [ 5. 6. 6. 7. 7. 8. 8. 8.] +# [ 9. 10. 10. 11. 11. 12. 12. 12.] +# [ 9. 10. 10. 11. 11. 12. 12. 12.] +# [13. 14. 14. 15. 15. 16. 16. 16.] +# [13. 14. 14. 15. 15. 16. 16. 16.] +# [13. 14. 14. 15. 15. 16. 16. 16.]]]] +output = interpolate_nd( + data, lambda x: nearest_coeffs(x, mode='ceil'), output_size=sizes).astype(np.float32) + +expect(node, inputs=[data, sizes], outputs=[output], + name='test_resize_upsample_sizes_nearest_ceil_half_pixel') +``` + +
+ + +
+resize_upsample_sizes_nearest_floor_align_corners + +```python +node = onnx.helper.make_node( + 'Resize', + inputs=['X', '', '', 'sizes'], + outputs=['Y'], + mode='nearest', + coordinate_transformation_mode='align_corners', + nearest_mode='floor' +) + +data = np.array([[[ + [1, 2, 3, 4], + [5, 6, 7, 8], + [9, 10, 11, 12], + [13, 14, 15, 16], +]]], dtype=np.float32) + +sizes = np.array([1, 1, 8, 8], dtype=np.int64) + +# [[[[ 1. 1. 1. 2. 2. 3. 3. 4.] +# [ 1. 1. 1. 2. 2. 3. 3. 4.] +# [ 1. 1. 1. 2. 2. 3. 3. 4.] +# [ 5. 5. 5. 6. 6. 7. 7. 8.] +# [ 5. 5. 5. 6. 6. 7. 7. 8.] +# [ 9. 9. 9. 10. 10. 11. 11. 12.] +# [ 9. 9. 9. 10. 10. 11. 11. 12.] +# [13. 13. 13. 14. 14. 15. 15. 16.]]]] +output = interpolate_nd( + data, lambda x: nearest_coeffs(x, mode='floor'), output_size=sizes, coordinate_transformation_mode='align_corners').astype(np.float32) + +expect(node, inputs=[data, sizes], outputs=[output], + name='test_resize_upsample_sizes_nearest_floor_align_corners') +``` + +
+ + +
+resize_upsample_sizes_nearest_round_prefer_ceil_asymmetric + +```python +node = onnx.helper.make_node( + 'Resize', + inputs=['X', '', '', 'sizes'], + outputs=['Y'], + mode='nearest', + coordinate_transformation_mode='asymmetric', + nearest_mode='round_prefer_ceil' +) + +data = np.array([[[ + [1, 2, 3, 4], + [5, 6, 7, 8], + [9, 10, 11, 12], + [13, 14, 15, 16], +]]], dtype=np.float32) + +sizes = np.array([1, 1, 8, 8], dtype=np.int64) + +# [[[[ 1. 2. 2. 3. 3. 4. 4. 4.] +# [ 5. 6. 6. 7. 7. 8. 8. 8.] +# [ 5. 6. 6. 7. 7. 8. 8. 8.] +# [ 9. 10. 10. 11. 11. 12. 12. 12.] +# [ 9. 10. 10. 11. 11. 12. 12. 12.] +# [13. 14. 14. 15. 15. 16. 16. 16.] +# [13. 14. 14. 15. 15. 16. 16. 16.] +# [13. 14. 14. 15. 15. 16. 16. 16.]]]] +output = interpolate_nd( + data, lambda x: nearest_coeffs(x, mode='round_prefer_ceil'), + output_size=sizes, coordinate_transformation_mode='asymmetric').astype(np.float32) + +expect(node, inputs=[data, sizes], outputs=[output], + name='test_resize_upsample_sizes_nearest_round_prefer_ceil_asymmetric') +``` + +
+ + +### **ReverseSequence** + + Reverse batch of sequences having different lengths specified by `sequence_lens`. + + For each slice i iterating on batch axis, the operator reverses the first sequence_lens[i] elements on time axis, + and copies elements whose index's beyond sequence_lens[i] to the output. So the output slice i contains reversed + sequences on the first sequence_lens[i] elements, then have original values copied for the other elements. + + Example 1: + input = [[0.0, 4.0, 8.0, 12.0], + [1.0, 5.0, 9.0, 13.0], + [2.0, 6.0, 10.0, 14.0], + [3.0, 7.0, 11.0, 15.0]] + sequence_lens = [4, 3, 2, 1] + time_axis = 0 + batch_axis = 1 + + output = [[3.0, 6.0, 9.0, 12.0], + [2.0, 5.0, 8.0, 13.0], + [1.0, 4.0, 10.0, 14.0], + [0.0, 7.0, 11.0, 15.0]] + + Example 2: + input = [[0.0, 1.0, 2.0, 3.0 ], + [4.0, 5.0, 6.0, 7.0 ], + [8.0, 9.0, 10.0, 11.0], + [12.0, 13.0, 14.0, 15.0]] + sequence_lens = [1, 2, 3, 4] + time_axis = 1 + batch_axis = 0 + + output = [[0.0, 1.0, 2.0, 3.0 ], + [5.0, 4.0, 6.0, 7.0 ], + [10.0, 9.0, 8.0, 11.0], + [15.0, 14.0, 13.0, 12.0]] + +#### Version + +This version of the operator has been available since version 10 of the default ONNX operator set. + +#### Attributes + +
+
batch_axis : int (default is 1)
+
(Optional) Specify which axis is batch axis. Must be one of 1 (default), or 0.
+
time_axis : int (default is 0)
+
(Optional) Specify which axis is time axis. Must be one of 0 (default), or 1.
+
+ +#### Inputs + +
+
input : T
+
Tensor of rank r >= 2.
+
sequence_lens : tensor(int64)
+
Tensor specifying lengths of the sequences in a batch. It has shape `[batch_size]`.
+
+ +#### Outputs + +
+
Y : T
+
Tensor with same shape of input.
+
+ +#### Type Constraints + +
+
T : tensor(uint8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(int8), tensor(int16), tensor(int32), tensor(int64), tensor(float16), tensor(float), tensor(double), tensor(string), tensor(bool), tensor(complex64), tensor(complex128)
+
Input and output types can be of any tensor type.
+
+ + +#### Examples + +
+reversesequence_batch + +```python +node = onnx.helper.make_node( + 'ReverseSequence', + inputs=['x', 'sequence_lens'], + outputs=['y'], + time_axis=1, + batch_axis=0, +) +x = np.array([[0.0, 1.0, 2.0, 3.0], + [4.0, 5.0, 6.0, 7.0], + [8.0, 9.0, 10.0, 11.0], + [12.0, 13.0, 14.0, 15.0]], dtype=np.float32) +sequence_lens = np.array([1, 2, 3, 4], dtype=np.int64) + +y = np.array([[0.0, 1.0, 2.0, 3.0], + [5.0, 4.0, 6.0, 7.0], + [10.0, 9.0, 8.0, 11.0], + [15.0, 14.0, 13.0, 12.0]], dtype=np.float32) + +expect(node, inputs=[x, sequence_lens], outputs=[y], + name='test_reversesequence_batch') +``` + +
+ + +
+reversesequence_time + +```python +node = onnx.helper.make_node( + 'ReverseSequence', + inputs=['x', 'sequence_lens'], + outputs=['y'], + time_axis=0, + batch_axis=1, +) +x = np.array([[0.0, 4.0, 8.0, 12.0], + [1.0, 5.0, 9.0, 13.0], + [2.0, 6.0, 10.0, 14.0], + [3.0, 7.0, 11.0, 15.0]], dtype=np.float32) +sequence_lens = np.array([4, 3, 2, 1], dtype=np.int64) + +y = np.array([[3.0, 6.0, 9.0, 12.0], + [2.0, 5.0, 8.0, 13.0], + [1.0, 4.0, 10.0, 14.0], + [0.0, 7.0, 11.0, 15.0]], dtype=np.float32) + +expect(node, inputs=[x, sequence_lens], outputs=[y], + name='test_reversesequence_time') +``` + +
+ + +### **RoiAlign** + + Region of Interest (RoI) align operation described in the + [Mask R-CNN paper](https://arxiv.org/abs/1703.06870). + RoiAlign consumes an input tensor X and region of interests (rois) + to apply pooling across each RoI; it produces a 4-D tensor of shape + (num_rois, C, output_height, output_width). + + RoiAlign is proposed to avoid the misalignment by removing + quantizations while converting from original image into feature + map and from feature map into RoI feature; in each ROI bin, + the value of the sampled locations are computed directly + through bilinear interpolation. + +#### Version + +This version of the operator has been available since version 16 of the default ONNX operator set. + +Other versions of this operator: 10 + +#### Attributes + +
+
coordinate_transformation_mode : string (default is half_pixel)
+
Allowed values are 'half_pixel' and 'output_half_pixel'. Use the value 'half_pixel' to pixel shift the input coordinates by -0.5 (the recommended behavior). Use the value 'output_half_pixel' to omit the pixel shift for the input (use this for a backward-compatible behavior).
+
mode : string (default is avg)
+
The pooling method. Two modes are supported: 'avg' and 'max'. Default is 'avg'.
+
output_height : int (default is 1)
+
default 1; Pooled output Y's height.
+
output_width : int (default is 1)
+
default 1; Pooled output Y's width.
+
sampling_ratio : int (default is 0)
+
Number of sampling points in the interpolation grid used to compute the output value of each pooled output bin. If > 0, then exactly sampling_ratio x sampling_ratio grid points are used. If == 0, then an adaptive number of grid points are used (computed as ceil(roi_width / output_width), and likewise for height). Default is 0.
+
spatial_scale : float (default is 1.0)
+
Multiplicative spatial scale factor to translate ROI coordinates from their input spatial scale to the scale used when pooling, i.e., spatial scale of the input feature map X relative to the input image. E.g.; default is 1.0f.
+
+ +#### Inputs + +
+
X : T1
+
Input data tensor from the previous operator; 4-D feature map of shape (N, C, H, W), where N is the batch size, C is the number of channels, and H and W are the height and the width of the data.
+
rois : T1
+
RoIs (Regions of Interest) to pool over; rois is 2-D input of shape (num_rois, 4) given as [[x1, y1, x2, y2], ...]. The RoIs' coordinates are in the coordinate system of the input image. Each coordinate set has a 1:1 correspondence with the 'batch_indices' input.
+
batch_indices : T2
+
1-D tensor of shape (num_rois,) with each element denoting the index of the corresponding image in the batch.
+
+ +#### Outputs + +
+
Y : T1
+
RoI pooled output, 4-D tensor of shape (num_rois, C, output_height, output_width). The r-th batch element Y[r-1] is a pooled feature map corresponding to the r-th RoI X[r-1].
+
+ +#### Type Constraints + +
+
T1 : tensor(float16), tensor(float), tensor(double)
+
Constrain types to float tensors.
+
T2 : tensor(int64)
+
Constrain types to int tensors.
+
+ + +#### Examples + +
+roialign_aligned_false + +```python +node = onnx.helper.make_node( + "RoiAlign", + inputs=["X", "rois", "batch_indices"], + outputs=["Y"], + spatial_scale=1.0, + output_height=5, + output_width=5, + sampling_ratio=2, + coordinate_transformation_mode="output_half_pixel", +) + +X, batch_indices, rois = get_roi_align_input_values() +# (num_rois, C, output_height, output_width) +Y = np.array( + [ + [ + [ + [0.4664, 0.4466, 0.3405, 0.5688, 0.6068], + [0.3714, 0.4296, 0.3835, 0.5562, 0.3510], + [0.2768, 0.4883, 0.5222, 0.5528, 0.4171], + [0.4713, 0.4844, 0.6904, 0.4920, 0.8774], + [0.6239, 0.7125, 0.6289, 0.3355, 0.3495], + ] + ], + [ + [ + [0.3022, 0.4305, 0.4696, 0.3978, 0.5423], + [0.3656, 0.7050, 0.5165, 0.3172, 0.7015], + [0.2912, 0.5059, 0.6476, 0.6235, 0.8299], + [0.5916, 0.7389, 0.7048, 0.8372, 0.8893], + [0.6227, 0.6153, 0.7097, 0.6154, 0.4585], + ] + ], + [ + [ + [0.2384, 0.3379, 0.3717, 0.6100, 0.7601], + [0.3767, 0.3785, 0.7147, 0.9243, 0.9727], + [0.5749, 0.5826, 0.5709, 0.7619, 0.8770], + [0.5355, 0.2566, 0.2141, 0.2796, 0.3600], + [0.4365, 0.3504, 0.2887, 0.3661, 0.2349], + ] + ], + ], + dtype=np.float32, +) + +expect(node, inputs=[X, rois, batch_indices], outputs=[Y], name="test_roialign_aligned_false") +``` + +
+ + +
+roialign_aligned_true + +```python +node = onnx.helper.make_node( + "RoiAlign", + inputs=["X", "rois", "batch_indices"], + outputs=["Y"], + spatial_scale=1.0, + output_height=5, + output_width=5, + sampling_ratio=2, + coordinate_transformation_mode="half_pixel", +) + +X, batch_indices, rois = get_roi_align_input_values() +# (num_rois, C, output_height, output_width) +Y = np.array( + [ + [ + [ + [0.5178, 0.3434, 0.3229, 0.4474, 0.6344], + [0.4031, 0.5366, 0.4428, 0.4861, 0.4023], + [0.2512, 0.4002, 0.5155, 0.6954, 0.3465], + [0.3350, 0.4601, 0.5881, 0.3439, 0.6849], + [0.4932, 0.7141, 0.8217, 0.4719, 0.4039], + ] + ], + [ + [ + [0.3070, 0.2187, 0.3337, 0.4880, 0.4870], + [0.1871, 0.4914, 0.5561, 0.4192, 0.3686], + [0.1433, 0.4608, 0.5971, 0.5310, 0.4982], + [0.2788, 0.4386, 0.6022, 0.7000, 0.7524], + [0.5774, 0.7024, 0.7251, 0.7338, 0.8163], + ] + ], + [ + [ + [0.2393, 0.4075, 0.3379, 0.2525, 0.4743], + [0.3671, 0.2702, 0.4105, 0.6419, 0.8308], + [0.5556, 0.4543, 0.5564, 0.7502, 0.9300], + [0.6626, 0.5617, 0.4813, 0.4954, 0.6663], + [0.6636, 0.3721, 0.2056, 0.1928, 0.2478], + ] + ], + ], + dtype=np.float32, +) + +expect(node, inputs=[X, rois, batch_indices], outputs=[Y], name="test_roialign_aligned_true") +``` + +
+ + +### **Round** + + Round takes one input Tensor and rounds the values, element-wise, meaning + it finds the nearest integer for each value. + In case of halfs, the rule is to round them to the nearest even integer. + The output tensor has the same shape and type as the input. + + Examples: + ``` + round([0.9]) = [1.0] + round([2.5]) = [2.0] + round([2.3]) = [2.0] + round([1.5]) = [2.0] + round([-4.5]) = [-4.0] + ``` + +#### Version + +This version of the operator has been available since version 11 of the default ONNX operator set. + +#### Inputs + +
+
X (non-differentiable) : T
+
Input tensor
+
+ +#### Outputs + +
+
Y (non-differentiable) : T
+
Output tensor
+
+ +#### Type Constraints + +
+
T : tensor(float16), tensor(float), tensor(double)
+
Constrain input and output types to float tensors.
+
+ + +#### Examples + +
+round + +```python +node = onnx.helper.make_node( + 'Round', + inputs=['x'], + outputs=['y'], +) + +x = np.array([0.1, 0.5, 0.9, 1.2, 1.5, + 1.8, 2.3, 2.5, 2.7, -1.1, + -1.5, -1.9, -2.2, -2.5, -2.8]).astype(np.float32) +y = np.array([0., 0., 1., 1., 2., + 2., 2., 2., 3., -1., + -2., -2., -2., -2., -3.]).astype(np.float32) # expected output +expect(node, inputs=[x], outputs=[y], + name='test_round') +``` + +
+ + +### **Scan** + + Scan can be used to iterate over one or more scan_input tensors, + constructing zero or more scan_output tensors. It combines ideas from general recurrences, + functional programming constructs such as scan, fold, map, and zip and is intended to enable + generalizations of RNN-like constructs for sequence-to-sequence processing. + Other tensors (referred to as state_variables here) can be used to carry a state + when iterating from one element to another (similar to hidden-state in RNNs, also referred + to as loop-carried dependences in the context of loops). + Many common usages involve a single scan_input tensor (where functionality + similar to scan, fold and map can be obtained). When more than one scan_input is used, + a behavior similar to zip is obtained. + + The attribute body must be a graph, specifying the computation to be performed in + every iteration. It takes as input the current values of the state_variables and + the current iterated element of the scan_inputs. It must return the (updated) values + of the state_variables and zero or more scan_output_element tensors. The values of the + scan_output_element tensors are concatenated over all the iterations to produce the + scan_output values of the scan construct (similar to the concatenated intermediate + hidden-state values of RNN-like constructs). All the output tensors (state_variables as + well as scan_output_element tensors) are required to have the same shape in each iteration + of the loop (a restriction imposed to enable efficient memory allocation). + + Note that the iterated element passed to the body subgraph does not have a sequence + axis. It will have a rank one less than the rank of the corresponding scan_input. + + The scan operation returns the final values of the state_variables as well as the + scan_outputs. + + The optional attribute scan_input_directions specifies the direction (forward or backward) + for each scan input. If this attribute is omitted, all sequences are scanned in the forward + direction. A bidirectional scan may be performed by specifying the same tensor input twice + in the scan_inputs, once with a forward direction, and once with a backward direction. + + The scan_output of the operation is produced by concatenating the scan_output_element + values produced by the body in each iteration. The optional attribute scan_output_directions + specifies the direction in which scan_output is constructed (by appending or prepending the + scan_output_element to scan_output in each iteration) for each scan_output. If this attribute + is omitted, the scan_output_element is appended to the scan_output in each iteration. + + The optional attribute scan_input_axes specifies the axis to be scanned for each scan_input. + If omitted, every scan_input will be scanned in axis 0. For example, if axis 0 is the + batch axis and axis 1 is the time axis (to be scanned), specify an axis value of 1. + Note that scanning a non-zero axis may be less efficient than scanning axis zero. + + The optional attribute scan_output_axes specifies the axis along which the scan_outputs + are accumulated for each scan_output. For example, if axis 1 is the time axis (to be + scanned) for both inputs and outputs, specify a scan_input axis and scan_output axis + value of 1. + + Note that because of the ONNX restriction that only the last parameter of an operator can + be variadic, the initial-states and scan-inputs are listed together as one input parameter. + Similarly, the final-states and scan-outputs are listed together as one output parameter. + The attribute num_scan_inputs indicates the number M of scan-inputs. + + The behavior of + + Scan < + num_scan_inputs = m, + body = loop-body, + scan_input_axes = [axis_1, ..., axis_m] + > (init_1, ..., init_n, scan_1, ..., scan_m) + + is equivalent to the following pseudo-code: + + // scan_i.shape[axis_i] denotes the (max) sequence-length of scan_i + // scan_i.shape[axis_i] is required to be equal to scan_j.shape[axis_j] for all i,j. + sequence_length = scan_1.shape[axis_1]; + + // initialize state-variables + st_1 = init_1; ... st_n = init_n; + // initialize scan-output variables: [] denotes an empty tensor + scan_out_1 = []; ...; scan_out_k = []; + // identify number of iterations: + + // execute loop + for (int t = 0; t < sequence_length; ++t) { + // generate the scan-input elements: the notation T[t] indicates the sub-tensor + // of rank one less than T obtained by indexing T at position t along axis k. + si_1 = scan_1[t]; + ... ; + si_m = scan_m[t]; + // execute loop-body + st_1, ..., st_n, so_1, ..., so_k = loop-body(st_1, ..., st_n, si_1, ..., si_m) + // accumulate the scan-output elements + scan_out_1 = Concat(scan_out_1, so_1); ... ; scan_out_k = Concat(scan_out_k, so_k); + } + + return st_1, ..., st_n, scan_out_1, ..., scan_out_k; + + *Sample usage: Encoding RNN using a Scan* + + The following example shows how a simple RNN over an input tensor %X, with weight tensor %Wi, + recurrence weight tensor %Ri, bias tensors %Wbi and %Rbi, and initial hidden-state %H_0 can + be encoded as a ScanLoop. Note that the loop-body is a nested graph, and it directly computes + %Wi, %Ri, %Wbi, and %Rbi (typically constants or initializers in the body graph). If these + values are computed in the outer graph, they need to be passed in as extra state_variables. + + graph rnn-encoding { + %H_0 = ... + %X = ... + %Y_h, %Y = Scan[body = , num_scan_inputs=1](%H_0, %X) + return %Y, %Y_h + } + + graph rnn-cell-1 ( + %H_tminus1[FLOAT, tensor] + %X_t[FLOAT, tensor] + ) { + %Wi = ... + %Ri = ... + %Wbi = ... + %Rbi = ... + %t1 = X_t * (Wi^T) + %t2 = H_tminus1*(Ri^T) + %t3 = Add(%t1, %t2) + %t4 = Add(%t3, %Wbi) + %t5 = Add(%t4, %Rbi) + %Ht = Tanh(%t5) + %Accumulate = Identity(%Ht) + return %Ht, %Accumulate + } + + +#### Version + +This version of the operator has been available since version 11 of the default ONNX operator set. + +Other versions of this operator: 8, 9 + +#### Attributes + +
+
body : graph (required)
+
The graph run each iteration. It has N+M inputs: (loop state variables..., scan_input_elts...). It has N+K outputs: (loop state variables..., scan_output_elts...). Each scan_output is created by concatenating the value of the specified scan_output_elt value at the end of each iteration of the loop. It is an error if the dimensions of these values change across loop iterations.
+
num_scan_inputs : int (required)
+
An attribute specifying the number of scan_inputs M.
+
scan_input_axes : list of ints
+
An optional list of M flags. The i-th element of the list specifies the axis to be scanned (the sequence axis) for the i-th scan_input. If omitted, 0 will be used as the scan axis for every scan_input. Negative value for an axis means counting dimensions from the back. Accepted range is [-r, r-1] where r = rank(input).
+
scan_input_directions : list of ints
+
An optional list of M flags. The i-th element of the list specifies the direction to be scanned for the i-th scan_input tensor: 0 indicates forward direction and 1 indicates reverse direction. If omitted, all scan_input tensors will be scanned in the forward direction.
+
scan_output_axes : list of ints
+
An optional list of K flags. The i-th element of the list specifies the axis for the i-th scan_output. The scan outputs are accumulated along the specified axis. If omitted, 0 will be used as the scan axis for every scan_output. Negative value for an axis means counting dimensions from the back. Accepted range is [-r, r-1].
+
scan_output_directions : list of ints
+
An optional list of K flags, one for each scan_output. The i-th element of the list specifies whether the i-th scan_output should be constructed by appending or prepending a new value in each iteration: 0 indicates appending and 1 indicates prepending. If omitted, all scan_output tensors will be produced by appending a value in each iteration.
+
+ +#### Inputs (1 - ∞) + +
+
initial_state_and_scan_inputs (variadic, heterogeneous) : V
+
Initial values of the loop's N state variables followed by M scan_inputs
+
+ +#### Outputs (1 - ∞) + +
+
final_state_and_scan_outputs (variadic, heterogeneous) : V
+
Final values of the loop's N state variables followed by K scan_outputs
+
+ +#### Type Constraints + +
+
I : tensor(int64)
+
Int64 tensor
+
V : tensor(uint8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(int8), tensor(int16), tensor(int32), tensor(int64), tensor(float16), tensor(float), tensor(double), tensor(string), tensor(bool), tensor(complex64), tensor(complex128)
+
All Tensor types
+
+ + +#### Examples + +
+scan_8 + +```python +# Given an input sequence [x1, ..., xN], sum up its elements using a scan +# returning the final state (x1+x2+...+xN) as well the scan_output +# [x1, x1+x2, ..., x1+x2+...+xN] +# +# create graph to represent scan body +sum_in = onnx.helper.make_tensor_value_info('sum_in', onnx.TensorProto.FLOAT, [2]) +next = onnx.helper.make_tensor_value_info('next', onnx.TensorProto.FLOAT, [2]) +sum_out = onnx.helper.make_tensor_value_info('sum_out', onnx.TensorProto.FLOAT, [2]) +scan_out = onnx.helper.make_tensor_value_info('scan_out', onnx.TensorProto.FLOAT, [2]) +add_node = onnx.helper.make_node( + 'Add', + inputs=['sum_in', 'next'], + outputs=['sum_out'] +) +id_node = onnx.helper.make_node( + 'Identity', + inputs=['sum_out'], + outputs=['scan_out'] +) +scan_body = onnx.helper.make_graph( + [add_node, id_node], + 'scan_body', + [sum_in, next], + [sum_out, scan_out] +) +# create scan op node +no_sequence_lens = '' # optional input, not supplied +node = onnx.helper.make_node( + 'Scan', + inputs=[no_sequence_lens, 'initial', 'x'], + outputs=['y', 'z'], + num_scan_inputs=1, + body=scan_body +) +# create inputs for batch-size 1, sequence-length 3, inner dimension 2 +initial = np.array([0, 0]).astype(np.float32).reshape((1, 2)) +x = np.array([1, 2, 3, 4, 5, 6]).astype(np.float32).reshape((1, 3, 2)) +# final state computed = [1 + 3 + 5, 2 + 4 + 6] +y = np.array([9, 12]).astype(np.float32).reshape((1, 2)) +# scan-output computed +z = np.array([1, 2, 4, 6, 9, 12]).astype(np.float32).reshape((1, 3, 2)) + +expect(node, inputs=[initial, x], outputs=[y, z], + name='test_scan_sum', opset_imports=[onnx.helper.make_opsetid("", 8)]) +``` + +
+ + +
+scan_9 + +```python +# Given an input sequence [x1, ..., xN], sum up its elements using a scan +# returning the final state (x1+x2+...+xN) as well the scan_output +# [x1, x1+x2, ..., x1+x2+...+xN] +# +# create graph to represent scan body +sum_in = onnx.helper.make_tensor_value_info('sum_in', onnx.TensorProto.FLOAT, [2]) +next = onnx.helper.make_tensor_value_info('next', onnx.TensorProto.FLOAT, [2]) +sum_out = onnx.helper.make_tensor_value_info('sum_out', onnx.TensorProto.FLOAT, [2]) +scan_out = onnx.helper.make_tensor_value_info('scan_out', onnx.TensorProto.FLOAT, [2]) +add_node = onnx.helper.make_node( + 'Add', + inputs=['sum_in', 'next'], + outputs=['sum_out'] +) +id_node = onnx.helper.make_node( + 'Identity', + inputs=['sum_out'], + outputs=['scan_out'] +) +scan_body = onnx.helper.make_graph( + [add_node, id_node], + 'scan_body', + [sum_in, next], + [sum_out, scan_out] +) +# create scan op node +node = onnx.helper.make_node( + 'Scan', + inputs=['initial', 'x'], + outputs=['y', 'z'], + num_scan_inputs=1, + body=scan_body +) +# create inputs for sequence-length 3, inner dimension 2 +initial = np.array([0, 0]).astype(np.float32).reshape((2,)) +x = np.array([1, 2, 3, 4, 5, 6]).astype(np.float32).reshape((3, 2)) +# final state computed = [1 + 3 + 5, 2 + 4 + 6] +y = np.array([9, 12]).astype(np.float32).reshape((2,)) +# scan-output computed +z = np.array([1, 2, 4, 6, 9, 12]).astype(np.float32).reshape((3, 2)) + +expect(node, inputs=[initial, x], outputs=[y, z], + name='test_scan9_sum', opset_imports=[onnx.helper.make_opsetid("", 9)]) +``` + +
+ + +### **Scatter** (deprecated) + + This operator is deprecated. Please use ScatterElements, which provides the same functionality. + + Scatter takes three inputs `data`, `updates`, and `indices` of the same + rank r >= 1 and an optional attribute axis that identifies an axis of `data` + (by default, the outer-most axis, that is axis 0). The output of the operation + is produced by creating a copy of the input `data`, and then updating its value + to values specified by `updates` at specific index positions specified by + `indices`. Its output shape is the same as the shape of `data`. + + For each entry in `updates`, the target index in `data` is obtained by combining + the corresponding entry in `indices` with the index of the entry itself: the + index-value for dimension = axis is obtained from the value of the corresponding + entry in `indices` and the index-value for dimension != axis is obtained from the + index of the entry itself. + + For instance, in a 2-D tensor case, the update corresponding to the [i][j] entry + is performed as below: + ``` + output[indices[i][j]][j] = updates[i][j] if axis = 0, + output[i][indices[i][j]] = updates[i][j] if axis = 1, + ``` + + This operator is the inverse of GatherElements. It is similar to Torch's Scatter operation. + + Example 1: + ``` + data = [ + [0.0, 0.0, 0.0], + [0.0, 0.0, 0.0], + [0.0, 0.0, 0.0], + ] + indices = [ + [1, 0, 2], + [0, 2, 1], + ] + updates = [ + [1.0, 1.1, 1.2], + [2.0, 2.1, 2.2], + ] + output = [ + [2.0, 1.1, 0.0] + [1.0, 0.0, 2.2] + [0.0, 2.1, 1.2] + ] + ``` + Example 2: + ``` + data = [[1.0, 2.0, 3.0, 4.0, 5.0]] + indices = [[1, 3]] + updates = [[1.1, 2.1]] + axis = 1 + output = [[1.0, 1.1, 3.0, 2.1, 5.0]] + ``` + +#### Version + +This version of the operator has been deprecated since version 11 of the default ONNX operator set. + +Other versions of this operator: 9 + + +#### Examples + +
+scatter_with_axis + +```python +axis = 1 +node = onnx.helper.make_node( + 'Scatter', + inputs=['data', 'indices', 'updates'], + outputs=['y'], + axis=axis, +) +data = np.array([[1.0, 2.0, 3.0, 4.0, 5.0]], dtype=np.float32) +indices = np.array([[1, 3]], dtype=np.int64) +updates = np.array([[1.1, 2.1]], dtype=np.float32) + +y = scatter(data, indices, updates, axis=axis) +# print(y) produces +# [[1.0, 1.1, 3.0, 2.1, 5.0]] + +expect(node, inputs=[data, indices, updates], outputs=[y], + name='test_scatter_with_axis', opset_imports=[helper.make_opsetid("", 10)]) +``` + +
+ + +
+scatter_without_axis + +```python +node = onnx.helper.make_node( + 'Scatter', + inputs=['data', 'indices', 'updates'], + outputs=['y'], +) +data = np.zeros((3, 3), dtype=np.float32) +indices = np.array([[1, 0, 2], [0, 2, 1]], dtype=np.int64) +updates = np.array([[1.0, 1.1, 1.2], [2.0, 2.1, 2.2]], dtype=np.float32) + +y = scatter(data, indices, updates) +# print(y) produces +# [[2.0, 1.1, 0.0], +# [1.0, 0.0, 2.2], +# [0.0, 2.1, 1.2]] + +expect(node, inputs=[data, indices, updates], outputs=[y], + name='test_scatter_without_axis', opset_imports=[helper.make_opsetid("", 10)]) +``` + +
+ + +### **ScatterElements** + + ScatterElements takes three inputs `data`, `updates`, and `indices` of the same + rank r >= 1 and an optional attribute axis that identifies an axis of `data` + (by default, the outer-most axis, that is axis 0). The output of the operation + is produced by creating a copy of the input `data`, and then updating its value + to values specified by `updates` at specific index positions specified by + `indices`. Its output shape is the same as the shape of `data`. + + For each entry in `updates`, the target index in `data` is obtained by combining + the corresponding entry in `indices` with the index of the entry itself: the + index-value for dimension = axis is obtained from the value of the corresponding + entry in `indices` and the index-value for dimension != axis is obtained from the + index of the entry itself. + + `reduction` allows specification of an optional reduction operation, which is applied to all values in `updates` + tensor into `output` at the specified `indices`. + In cases where `reduction` is set to "none", indices should not have duplicate entries: that is, if idx1 != idx2, + then indices[idx1] != indices[idx2]. For instance, in a 2-D tensor case, the update + corresponding to the [i][j] entry is performed as below: + ``` + output[indices[i][j]][j] = updates[i][j] if axis = 0, + output[i][indices[i][j]] = updates[i][j] if axis = 1, + ``` + When `reduction` is set to "add", the update corresponding to the [i][j] entry is performed as below: + ``` + output[indices[i][j]][j] += updates[i][j] if axis = 0, + output[i][indices[i][j]] += updates[i][j] if axis = 1, + ``` + When `reduction` is set to "mul", the update corresponding to the [i][j] entry is performed as below: + ``` + output[indices[i][j]][j] *= updates[i][j] if axis = 0, + output[i][indices[i][j]] *= updates[i][j] if axis = 1, + ``` + + This operator is the inverse of GatherElements. It is similar to Torch's Scatter operation. + + Example 1: + ``` + data = [ + [0.0, 0.0, 0.0], + [0.0, 0.0, 0.0], + [0.0, 0.0, 0.0], + ] + indices = [ + [1, 0, 2], + [0, 2, 1], + ] + updates = [ + [1.0, 1.1, 1.2], + [2.0, 2.1, 2.2], + ] + output = [ + [2.0, 1.1, 0.0] + [1.0, 0.0, 2.2] + [0.0, 2.1, 1.2] + ] + ``` + Example 2: + ``` + data = [[1.0, 2.0, 3.0, 4.0, 5.0]] + indices = [[1, 3]] + updates = [[1.1, 2.1]] + axis = 1 + output = [[1.0, 1.1, 3.0, 2.1, 5.0]] + ``` + +#### Version + +This version of the operator has been available since version 16 of the default ONNX operator set. + +Other versions of this operator: 11, 13 + +#### Attributes + +
+
axis : int (default is 0)
+
Which axis to scatter on. Negative value means counting dimensions from the back. Accepted range is [-r, r-1] where r = rank(data).
+
reduction : string (default is none)
+
Type of reduction to apply: none (default), add, mul. 'none': no reduction applied. 'add': reduction using the addition operation. 'mul': reduction using the multiplication operation.
+
+ +#### Inputs + +
+
data (differentiable) : T
+
Tensor of rank r >= 1.
+
indices (non-differentiable) : Tind
+
Tensor of int32/int64 indices, of r >= 1 (same rank as input). All index values are expected to be within bounds [-s, s-1] along axis of size s. It is an error if any of the index values are out of bounds.
+
updates (differentiable) : T
+
Tensor of rank r >=1 (same rank and shape as indices)
+
+ +#### Outputs + +
+
output (differentiable) : T
+
Tensor of rank r >= 1 (same rank as input).
+
+ +#### Type Constraints + +
+
T : tensor(uint8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(int8), tensor(int16), tensor(int32), tensor(int64), tensor(bfloat16), tensor(float16), tensor(float), tensor(double), tensor(string), tensor(bool), tensor(complex64), tensor(complex128)
+
Input and output types can be of any tensor type.
+
Tind : tensor(int32), tensor(int64)
+
Constrain indices to integer types
+
+ + +#### Examples + +
+scatter_elements_with_axis + +```python +axis = 1 +node = onnx.helper.make_node( + 'ScatterElements', + inputs=['data', 'indices', 'updates'], + outputs=['y'], + axis=axis, +) +data = np.array([[1.0, 2.0, 3.0, 4.0, 5.0]], dtype=np.float32) +indices = np.array([[1, 3]], dtype=np.int64) +updates = np.array([[1.1, 2.1]], dtype=np.float32) + +y = scatter_elements(data, indices, updates, axis) +# print(y) produces +# [[1.0, 1.1, 3.0, 2.1, 5.0]] + +expect(node, inputs=[data, indices, updates], outputs=[y], + name='test_scatter_elements_with_axis') +``` + +
+ + +
+scatter_elements_with_duplicate_indices + +```python +axis = 1 +node = onnx.helper.make_node( + 'ScatterElements', + inputs=['data', 'indices', 'updates'], + outputs=['y'], + axis=axis, + reduction='add', +) +data = np.array([[1.0, 2.0, 3.0, 4.0, 5.0]], dtype=np.float32) +indices = np.array([[1, 1]], dtype=np.int64) +updates = np.array([[1.1, 2.1]], dtype=np.float32) + +y = scatter_elements(data, indices, updates, axis, reduction='add') +# print(y) produces +# [[1.0, 5.2, 3.0, 4.0, 5.0]] + +expect(node, inputs=[data, indices, updates], outputs=[y], + name='test_scatter_elements_with_duplicate_indices') +``` + +
+ + +
+scatter_elements_with_negative_indices + +```python +axis = 1 +node = onnx.helper.make_node( + 'ScatterElements', + inputs=['data', 'indices', 'updates'], + outputs=['y'], + axis=axis, +) +data = np.array([[1.0, 2.0, 3.0, 4.0, 5.0]], dtype=np.float32) +indices = np.array([[1, -3]], dtype=np.int64) +updates = np.array([[1.1, 2.1]], dtype=np.float32) + +y = scatter_elements(data, indices, updates, axis) +# print(y) produces +# [[1.0, 1.1, 2.1, 4.0, 5.0]] + +expect(node, inputs=[data, indices, updates], outputs=[y], + name='test_scatter_elements_with_negative_indices') +``` + +
+ + +
+scatter_elements_without_axis + +```python +node = onnx.helper.make_node( + 'ScatterElements', + inputs=['data', 'indices', 'updates'], + outputs=['y'], +) +data = np.zeros((3, 3), dtype=np.float32) +indices = np.array([[1, 0, 2], [0, 2, 1]], dtype=np.int64) +updates = np.array([[1.0, 1.1, 1.2], [2.0, 2.1, 2.2]], dtype=np.float32) + +y = scatter_elements(data, indices, updates) +# print(y) produces +# [[2.0, 1.1, 0.0], +# [1.0, 0.0, 2.2], +# [0.0, 2.1, 1.2]] + +expect(node, inputs=[data, indices, updates], outputs=[y], + name='test_scatter_elements_without_axis') +``` + +
+ + +### **ScatterND** + + ScatterND takes three inputs `data` tensor of rank r >= 1, `indices` tensor of rank q >= 1, + and `updates` tensor of rank q + r - indices.shape[-1] - 1. The output of the operation + is produced by creating a copy of the input `data`, and then updating its value to values + specified by `updates` at specific index positions specified by `indices`. Its output shape + is the same as the shape of `data`. Note that `indices` should not have duplicate entries. + That is, two or more `updates` for the same index-location is not supported. + + `indices` is an integer tensor. Let k denote indices.shape[-1], the last dimension in the shape of `indices`. + `indices` is treated as a (q-1)-dimensional tensor of k-tuples, where each k-tuple is a partial-index into `data`. + Hence, k can be a value at most the rank of `data`. When k equals rank(data), each update entry specifies an + update to a single element of the tensor. When k is less than rank(data) each update entry specifies an + update to a slice of the tensor. + + `updates` is treated as a (q-1)-dimensional tensor of replacement-slice-values. Thus, the + first (q-1) dimensions of updates.shape must match the first (q-1) dimensions of indices.shape. + The remaining dimensions of `updates` correspond to the dimensions of the + replacement-slice-values. Each replacement-slice-value is a (r-k) dimensional tensor, + corresponding to the trailing (r-k) dimensions of `data`. Thus, the shape of `updates` + must equal indices.shape[0:q-1] ++ data.shape[k:r-1], where ++ denotes the concatenation + of shapes. + + The `output` is calculated via the following equation: + + output = np.copy(data) + update_indices = indices.shape[:-1] + for idx in np.ndindex(update_indices): + output[indices[idx]] = updates[idx] + + The order of iteration in the above loop is not specified. + In particular, indices should not have duplicate entries: that is, if idx1 != idx2, then indices[idx1] != indices[idx2]. + This ensures that the output value does not depend on the iteration order. + + `reduction` allows specification of an optional reduction operation, which is applied to all values in `updates` + tensor into `output` at the specified `indices`. + In cases where `reduction` is set to "none", indices should not have duplicate entries: that is, if idx1 != idx2, + then indices[idx1] != indices[idx2]. This ensures that the output value does not depend on the iteration order. + When `reduction` is set to "add", `output` is calculated as follows: + + output = np.copy(data) + update_indices = indices.shape[:-1] + for idx in np.ndindex(update_indices): + output[indices[idx]] += updates[idx] + + When `reduction` is set to "mul", `output` is calculated as follows: + + output = np.copy(data) + update_indices = indices.shape[:-1] + for idx in np.ndindex(update_indices): + output[indices[idx]] *= updates[idx] + + This operator is the inverse of GatherND. + + Example 1: + ``` + data = [1, 2, 3, 4, 5, 6, 7, 8] + indices = [[4], [3], [1], [7]] + updates = [9, 10, 11, 12] + output = [1, 11, 3, 10, 9, 6, 7, 12] + ``` + + Example 2: + ``` + data = [[[1, 2, 3, 4], [5, 6, 7, 8], [8, 7, 6, 5], [4, 3, 2, 1]], + [[1, 2, 3, 4], [5, 6, 7, 8], [8, 7, 6, 5], [4, 3, 2, 1]], + [[8, 7, 6, 5], [4, 3, 2, 1], [1, 2, 3, 4], [5, 6, 7, 8]], + [[8, 7, 6, 5], [4, 3, 2, 1], [1, 2, 3, 4], [5, 6, 7, 8]]] + indices = [[0], [2]] + updates = [[[5, 5, 5, 5], [6, 6, 6, 6], [7, 7, 7, 7], [8, 8, 8, 8]], + [[1, 1, 1, 1], [2, 2, 2, 2], [3, 3, 3, 3], [4, 4, 4, 4]]] + output = [[[5, 5, 5, 5], [6, 6, 6, 6], [7, 7, 7, 7], [8, 8, 8, 8]], + [[1, 2, 3, 4], [5, 6, 7, 8], [8, 7, 6, 5], [4, 3, 2, 1]], + [[1, 1, 1, 1], [2, 2, 2, 2], [3, 3, 3, 3], [4, 4, 4, 4]], + [[8, 7, 6, 5], [4, 3, 2, 1], [1, 2, 3, 4], [5, 6, 7, 8]]] + ``` + +#### Version + +This version of the operator has been available since version 16 of the default ONNX operator set. + +Other versions of this operator: 11, 13 + +#### Attributes + +
+
reduction : string (default is none)
+
Type of reduction to apply: none (default), add, mul. 'none': no reduction applied. 'add': reduction using the addition operation. 'mul': reduction using the multiplication operation.
+
+ +#### Inputs + +
+
data (differentiable) : T
+
Tensor of rank r >= 1.
+
indices (non-differentiable) : tensor(int64)
+
Tensor of rank q >= 1.
+
updates (differentiable) : T
+
Tensor of rank q + r - indices_shape[-1] - 1.
+
+ +#### Outputs + +
+
output (differentiable) : T
+
Tensor of rank r >= 1.
+
+ +#### Type Constraints + +
+
T : tensor(uint8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(int8), tensor(int16), tensor(int32), tensor(int64), tensor(bfloat16), tensor(float16), tensor(float), tensor(double), tensor(string), tensor(bool), tensor(complex64), tensor(complex128)
+
Constrain input and output types to any tensor type.
+
+ + +#### Examples + +
+scatternd + +```python +node = onnx.helper.make_node( + 'ScatterND', + inputs=['data', 'indices', 'updates'], + outputs=['y'], +) +data = np.array( + [[[1, 2, 3, 4], [5, 6, 7, 8], [8, 7, 6, 5], [4, 3, 2, 1]], + [[1, 2, 3, 4], [5, 6, 7, 8], [8, 7, 6, 5], [4, 3, 2, 1]], + [[8, 7, 6, 5], [4, 3, 2, 1], [1, 2, 3, 4], [5, 6, 7, 8]], + [[8, 7, 6, 5], [4, 3, 2, 1], [1, 2, 3, 4], [5, 6, 7, 8]]], dtype=np.float32) +indices = np.array([[0], [2]], dtype=np.int64) +updates = np.array( + [[[5, 5, 5, 5], [6, 6, 6, 6], [7, 7, 7, 7], [8, 8, 8, 8]], + [[1, 1, 1, 1], [2, 2, 2, 2], [3, 3, 3, 3], [4, 4, 4, 4]]], dtype=np.float32) +# Expecting output as np.array( +# [[[5, 5, 5, 5], [6, 6, 6, 6], [7, 7, 7, 7], [8, 8, 8, 8]], +# [[1, 2, 3, 4], [5, 6, 7, 8], [8, 7, 6, 5], [4, 3, 2, 1]], +# [[1, 1, 1, 1], [2, 2, 2, 2], [3, 3, 3, 3], [4, 4, 4, 4]], +# [[8, 7, 6, 5], [4, 3, 2, 1], [1, 2, 3, 4], [5, 6, 7, 8]]], dtype=np.float32) +output = scatter_nd_impl(data, indices, updates) +expect(node, inputs=[data, indices, updates], outputs=[output], + name='test_scatternd') +``` + +
+ + +
+scatternd_add + +```python +node = onnx.helper.make_node( + 'ScatterND', + inputs=['data', 'indices', 'updates'], + outputs=['y'], + reduction='add', +) +data = np.array( + [[[1, 2, 3, 4], [5, 6, 7, 8], [8, 7, 6, 5], [4, 3, 2, 1]], + [[1, 2, 3, 4], [5, 6, 7, 8], [8, 7, 6, 5], [4, 3, 2, 1]], + [[8, 7, 6, 5], [4, 3, 2, 1], [1, 2, 3, 4], [5, 6, 7, 8]], + [[8, 7, 6, 5], [4, 3, 2, 1], [1, 2, 3, 4], [5, 6, 7, 8]]], dtype=np.float32) +indices = np.array([[0], [0]], dtype=np.int64) +updates = np.array( + [[[5, 5, 5, 5], [6, 6, 6, 6], [7, 7, 7, 7], [8, 8, 8, 8]], + [[1, 1, 1, 1], [2, 2, 2, 2], [3, 3, 3, 3], [4, 4, 4, 4]]], dtype=np.float32) +# Expecting output as np.array( +# [[[7, 8, 9, 10], [13, 14, 15, 16], [18, 17, 16, 15], [16, 15, 14, 13]], +# [[1, 2, 3, 4], [5, 6, 7, 8], [8, 7, 6, 5], [4, 3, 2, 1]], +# [[1, 1, 1, 1], [2, 2, 2, 2], [3, 3, 3, 3], [4, 4, 4, 4]], +# [[8, 7, 6, 5], [4, 3, 2, 1], [1, 2, 3, 4], [5, 6, 7, 8]]], dtype=np.float32) +output = scatter_nd_impl(data, indices, updates, reduction='add') +expect(node, inputs=[data, indices, updates], outputs=[output], + name='test_scatternd_add') +``` + +
+ + +
+scatternd_multiply + +```python +node = onnx.helper.make_node( + 'ScatterND', + inputs=['data', 'indices', 'updates'], + outputs=['y'], + reduction='mul', +) +data = np.array( + [[[1, 2, 3, 4], [5, 6, 7, 8], [8, 7, 6, 5], [4, 3, 2, 1]], + [[1, 2, 3, 4], [5, 6, 7, 8], [8, 7, 6, 5], [4, 3, 2, 1]], + [[8, 7, 6, 5], [4, 3, 2, 1], [1, 2, 3, 4], [5, 6, 7, 8]], + [[8, 7, 6, 5], [4, 3, 2, 1], [1, 2, 3, 4], [5, 6, 7, 8]]], dtype=np.float32) +indices = np.array([[0], [0]], dtype=np.int64) +updates = np.array( + [[[5, 5, 5, 5], [6, 6, 6, 6], [7, 7, 7, 7], [8, 8, 8, 8]], + [[1, 1, 1, 1], [2, 2, 2, 2], [3, 3, 3, 3], [4, 4, 4, 4]]], dtype=np.float32) +# Expecting output as np.array( +# [[[5, 10, 15, 20], [60, 72, 84, 96], [168, 147, 126, 105], [128, 96, 64, 32]], +# [[1, 2, 3, 4], [5, 6, 7, 8], [8, 7, 6, 5], [4, 3, 2, 1]], +# [[1, 1, 1, 1], [2, 2, 2, 2], [3, 3, 3, 3], [4, 4, 4, 4]], +# [[8, 7, 6, 5], [4, 3, 2, 1], [1, 2, 3, 4], [5, 6, 7, 8]]], dtype=np.float32) +output = scatter_nd_impl(data, indices, updates, reduction='mul') +expect(node, inputs=[data, indices, updates], outputs=[output], + name='test_scatternd_multiply') +``` + +
+ + +### **Selu** + + Selu takes one input data (Tensor) and produces one output data + (Tensor) where the scaled exponential linear unit function, + `y = gamma * (alpha * e^x - alpha) for x <= 0`, `y = gamma * x for x > 0`, + is applied to the tensor elementwise. + +#### Version + +This version of the operator has been available since version 6 of the default ONNX operator set. + +Other versions of this operator: 1 + +#### Attributes + +
+
alpha : float (default is 1.67326)
+
Coefficient of SELU default to 1.67326319217681884765625 (i.e., float32 approximation of 1.6732632423543772848170429916717).
+
gamma : float (default is 1.0507)
+
Coefficient of SELU default to 1.05070102214813232421875 (i.e., float32 approximation of 1.0507009873554804934193349852946).
+
+ +#### Inputs + +
+
X (differentiable) : T
+
Input tensor
+
+ +#### Outputs + +
+
Y (differentiable) : T
+
Output tensor
+
+ +#### Type Constraints + +
+
T : tensor(float16), tensor(float), tensor(double)
+
Constrain input and output types to float tensors.
+
+ + +#### Examples + +
+selu + +```python +node = onnx.helper.make_node( + 'Selu', + inputs=['x'], + outputs=['y'], + alpha=2.0, + gamma=3.0 +) + +x = np.array([-1, 0, 1]).astype(np.float32) +# expected output [-3.79272318, 0., 3.] +y = np.clip(x, 0, np.inf) * 3.0 + (np.exp(np.clip(x, -np.inf, 0)) - 1) * 2.0 * 3.0 +expect(node, inputs=[x], outputs=[y], + name='test_selu_example') + +x = np.random.randn(3, 4, 5).astype(np.float32) +y = np.clip(x, 0, np.inf) * 3.0 + (np.exp(np.clip(x, -np.inf, 0)) - 1) * 2.0 * 3.0 +expect(node, inputs=[x], outputs=[y], + name='test_selu') +``` + +
+ + +
+selu_default + +```python +default_alpha = 1.67326319217681884765625 +default_gamma = 1.05070102214813232421875 +node = onnx.helper.make_node( + 'Selu', + inputs=['x'], + outputs=['y'], +) +x = np.random.randn(3, 4, 5).astype(np.float32) +y = np.clip(x, 0, np.inf) * default_gamma + \ + (np.exp(np.clip(x, -np.inf, 0)) - 1) * default_alpha * default_gamma +expect(node, inputs=[x], outputs=[y], + name='test_selu_default') +``` + +
+ + +### **SequenceAt** + + Outputs a tensor copy from the tensor at 'position' in 'input_sequence'. + Accepted range for 'position' is in `[-n, n - 1]`, where `n` is the number of tensors in 'input_sequence'. + Negative value means counting positions from the back. + +#### Version + +This version of the operator has been available since version 11 of the default ONNX operator set. + +#### Inputs + +
+
input_sequence : S
+
Input sequence.
+
position : I
+
Position of the tensor in the sequence. Negative value means counting positions from the back. Accepted range in `[-n, n - 1]`, where `n` is the number of tensors in 'input_sequence'. It is an error if any of the index values are out of bounds. It must be a scalar(tensor of empty shape).
+
+ +#### Outputs + +
+
tensor : T
+
Output tensor at the specified position in the input sequence.
+
+ +#### Type Constraints + +
+
S : seq(tensor(uint8)), seq(tensor(uint16)), seq(tensor(uint32)), seq(tensor(uint64)), seq(tensor(int8)), seq(tensor(int16)), seq(tensor(int32)), seq(tensor(int64)), seq(tensor(float16)), seq(tensor(float)), seq(tensor(double)), seq(tensor(string)), seq(tensor(bool)), seq(tensor(complex64)), seq(tensor(complex128))
+
Constrain to any tensor type.
+
T : tensor(uint8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(int8), tensor(int16), tensor(int32), tensor(int64), tensor(float16), tensor(float), tensor(double), tensor(string), tensor(bool), tensor(complex64), tensor(complex128)
+
Constrain to any tensor type.
+
I : tensor(int32), tensor(int64)
+
Constrain position to integral tensor. It must be a scalar(tensor of empty shape).
+
+ + +### **SequenceConstruct** + + Construct a tensor sequence containing 'inputs' tensors. + All tensors in 'inputs' must have the same data type. + +#### Version + +This version of the operator has been available since version 11 of the default ONNX operator set. + +#### Inputs (1 - ∞) + +
+
inputs (variadic) : T
+
Tensors.
+
+ +#### Outputs + +
+
output_sequence : S
+
Sequence enclosing the input tensors.
+
+ +#### Type Constraints + +
+
T : tensor(uint8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(int8), tensor(int16), tensor(int32), tensor(int64), tensor(float16), tensor(float), tensor(double), tensor(string), tensor(bool), tensor(complex64), tensor(complex128)
+
Constrain input types to any tensor type.
+
S : seq(tensor(uint8)), seq(tensor(uint16)), seq(tensor(uint32)), seq(tensor(uint64)), seq(tensor(int8)), seq(tensor(int16)), seq(tensor(int32)), seq(tensor(int64)), seq(tensor(float16)), seq(tensor(float)), seq(tensor(double)), seq(tensor(string)), seq(tensor(bool)), seq(tensor(complex64)), seq(tensor(complex128))
+
Constrain output types to any tensor type.
+
+ + +### **SequenceEmpty** + + Construct an empty tensor sequence, with given data type. + +#### Version + +This version of the operator has been available since version 11 of the default ONNX operator set. + +#### Attributes + +
+
dtype : int
+
(Optional) The data type of the tensors in the output sequence. The default type is 'float'.
+
+ +#### Inputs + + +#### Outputs + +
+
output : S
+
Empty sequence.
+
+ +#### Type Constraints + +
+
S : seq(tensor(uint8)), seq(tensor(uint16)), seq(tensor(uint32)), seq(tensor(uint64)), seq(tensor(int8)), seq(tensor(int16)), seq(tensor(int32)), seq(tensor(int64)), seq(tensor(float16)), seq(tensor(float)), seq(tensor(double)), seq(tensor(string)), seq(tensor(bool)), seq(tensor(complex64)), seq(tensor(complex128))
+
Constrain output types to any tensor type.
+
+ + +### **SequenceErase** + + Outputs a tensor sequence that removes the tensor at 'position' from 'input_sequence'. + Accepted range for 'position' is in `[-n, n - 1]`, where `n` is the number of tensors in 'input_sequence'. + Negative value means counting positions from the back. + 'position' is optional, by default it erases the last tensor from 'input_sequence'. + +#### Version + +This version of the operator has been available since version 11 of the default ONNX operator set. + +#### Inputs (1 - 2) + +
+
input_sequence : S
+
Input sequence.
+
position (optional) : I
+
Position of the tensor in the sequence. Negative value means counting positions from the back. Accepted range in `[-n, n - 1]`, where `n` is the number of tensors in 'input_sequence'. It is an error if any of the index values are out of bounds. It must be a scalar(tensor of empty shape).
+
+ +#### Outputs + +
+
output_sequence : S
+
Output sequence that has the tensor at the specified position removed.
+
+ +#### Type Constraints + +
+
S : seq(tensor(uint8)), seq(tensor(uint16)), seq(tensor(uint32)), seq(tensor(uint64)), seq(tensor(int8)), seq(tensor(int16)), seq(tensor(int32)), seq(tensor(int64)), seq(tensor(float16)), seq(tensor(float)), seq(tensor(double)), seq(tensor(string)), seq(tensor(bool)), seq(tensor(complex64)), seq(tensor(complex128))
+
Constrain to any tensor type.
+
I : tensor(int32), tensor(int64)
+
Constrain position to integral tensor. It must be a scalar(tensor of empty shape).
+
+ + +### **SequenceInsert** + + Outputs a tensor sequence that inserts 'tensor' into 'input_sequence' at 'position'. + 'tensor' must have the same data type as 'input_sequence'. + Accepted range for 'position' is in `[-n, n]`, where `n` is the number of tensors in 'input_sequence'. + Negative value means counting positions from the back. + 'position' is optional, by default it inserts 'tensor' to the back of 'input_sequence'. + +#### Version + +This version of the operator has been available since version 11 of the default ONNX operator set. + +#### Inputs (2 - 3) + +
+
input_sequence : S
+
Input sequence.
+
tensor : T
+
Input tensor to be inserted into the input sequence.
+
position (optional) : I
+
Position in the sequence where the new tensor is inserted. It is optional and default is to insert to the back of the sequence. Negative value means counting positions from the back. Accepted range in `[-n, n]`, where `n` is the number of tensors in 'input_sequence'. It is an error if any of the index values are out of bounds. It must be a scalar(tensor of empty shape).
+
+ +#### Outputs + +
+
output_sequence : S
+
Output sequence that contains the inserted tensor at given position.
+
+ +#### Type Constraints + +
+
T : tensor(uint8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(int8), tensor(int16), tensor(int32), tensor(int64), tensor(float16), tensor(float), tensor(double), tensor(string), tensor(bool), tensor(complex64), tensor(complex128)
+
Constrain to any tensor type.
+
S : seq(tensor(uint8)), seq(tensor(uint16)), seq(tensor(uint32)), seq(tensor(uint64)), seq(tensor(int8)), seq(tensor(int16)), seq(tensor(int32)), seq(tensor(int64)), seq(tensor(float16)), seq(tensor(float)), seq(tensor(double)), seq(tensor(string)), seq(tensor(bool)), seq(tensor(complex64)), seq(tensor(complex128))
+
Constrain to any tensor type.
+
I : tensor(int32), tensor(int64)
+
Constrain position to integral tensor. It must be a scalar(tensor of empty shape).
+
+ + +#### Examples + +
+sequenceinsert + +```python +test_cases = { + 'at_back': [np.array([10, 11, 12]).astype(np.int64)], + 'at_front': [np.array([-2, -1, 0]), np.array([0]).astype(np.int64)] +} +sequence = [np.array([1, 2, 3, 4]).astype(np.int64), np.array([5, 6, 7]).astype(np.int64), np.array([8, 9]).astype(np.int64)] + +for test_name, test_inputs in test_cases.items(): + tensor = test_inputs[0].astype(np.int64) + + if len(test_inputs) > 1: + node = onnx.helper.make_node( + 'SequenceInsert', + inputs=['sequence', 'tensor', 'position'], + outputs=['output_sequence'] + ) + position = test_inputs[1] + inserted = sequence_insert_reference_implementation(sequence, tensor, position) + expect(node, inputs=[sequence, tensor, position], outputs=[inserted], + name='test_sequence_insert_' + test_name) + else: + node = onnx.helper.make_node( + 'SequenceInsert', + inputs=['sequence', 'tensor'], + outputs=['output_sequence'] + ) + inserted = sequence_insert_reference_implementation(sequence, tensor) + expect(node, inputs=[sequence, tensor], outputs=[inserted], + name='test_sequence_insert_' + test_name) +``` + +
+ + +### **SequenceLength** + + Produces a scalar(tensor of empty shape) containing the number of tensors in 'input_sequence'. + +#### Version + +This version of the operator has been available since version 11 of the default ONNX operator set. + +#### Inputs + +
+
input_sequence : S
+
Input sequence.
+
+ +#### Outputs + +
+
length : I
+
Length of input sequence. It must be a scalar(tensor of empty shape).
+
+ +#### Type Constraints + +
+
S : seq(tensor(uint8)), seq(tensor(uint16)), seq(tensor(uint32)), seq(tensor(uint64)), seq(tensor(int8)), seq(tensor(int16)), seq(tensor(int32)), seq(tensor(int64)), seq(tensor(float16)), seq(tensor(float)), seq(tensor(double)), seq(tensor(string)), seq(tensor(bool)), seq(tensor(complex64)), seq(tensor(complex128))
+
Constrain to any tensor type.
+
I : tensor(int64)
+
Constrain output to integral tensor. It must be a scalar(tensor of empty shape).
+
+ + +### **Shape** + + Takes a tensor as input and outputs an 1D int64 tensor containing the shape of the input tensor. + Optional attributes start and end can be used to compute a slice of the input tensor's shape. + If start axis is omitted, the slice starts from axis 0. + The end axis, if specified, is exclusive (and the returned value will not include the size of that axis). + If the end axis is omitted, the axes upto the last one will be included. + Negative axes indicate counting back from the last axis. + Note that axes will be clipped to the range [0, r-1], where r is the + rank of the input tensor if they are out-of-range (after adding r in the case of + negative axis). Thus, specifying any end value > r is equivalent to specifying an end + value of r, and specifying any start value < -r is equivalent to specifying a start + value of 0. + + For example: + Input tensor with shape: [2, 3, 4] + No attributes specified. + Output: [2, 3, 4] + + Input tensor with shape: [2, 3, 4] + start: -1 + Output: [4] + + Input tensor with shape: [2, 3, 4] + end: -1 + Output: [2, 3] + + Input tensor with shape: [2, 3, 4] + start: 1 + end: 2 + Output: [3] + +#### Version + +This version of the operator has been available since version 15 of the default ONNX operator set. + +Other versions of this operator: 1, 13 + +#### Attributes + +
+
end : int
+
(Optional) Ending axis for slicing the shape. Negative value means counting dimensions from the back. If omitted, sizes of all axes upto (including) the last one will be included.
+
start : int (default is 0)
+
(Optional) Starting axis for slicing the shape. Default value is 0.Negative value means counting dimensions from the back.
+
+ +#### Inputs + +
+
data (non-differentiable) : T
+
An input tensor.
+
+ +#### Outputs + +
+
shape (non-differentiable) : T1
+
Shape of the input tensor
+
+ +#### Type Constraints + +
+
T : tensor(uint8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(int8), tensor(int16), tensor(int32), tensor(int64), tensor(bfloat16), tensor(float16), tensor(float), tensor(double), tensor(string), tensor(bool), tensor(complex64), tensor(complex128)
+
Input tensor can be of arbitrary type.
+
T1 : tensor(int64)
+
Constrain output to int64 tensor.
+
+ + +#### Examples + +
+shape + +```python +x = np.array([ + [1, 2, 3], + [4, 5, 6], +]).astype(np.float32) +test_shape('_example', x) # preserve names of original test cases + +x = np.random.randn(3, 4, 5).astype(np.float32) + +test_shape('', x) # preserve names of original test cases + +test_shape('_start_1', x, start=1) + +test_shape('_end_1', x, end=1) + +test_shape('_start_negative_1', x, start=-1) + +test_shape('_end_negative_1', x, end=-1) + +test_shape('_start_1_end_negative_1', x, start=1, end=-1) + +test_shape('_start_1_end_2', x, start=1, end=2) + +test_shape('_clip_start', x, start=-10) + +test_shape('_clip_end', x, end=10) +``` + +
+ + +### **Shrink** + + Shrink takes one input data (Tensor) and produces one Tensor output, + having same datatype and shape with input. It has two attributes, lambd and + bias. The formula of this operator is: If x < -lambd, y = x + bias; + If x > lambd, y = x - bias; Otherwise, y = 0. + +#### Version + +This version of the operator has been available since version 9 of the default ONNX operator set. + +#### Attributes + +
+
bias : float (default is 0.0)
+
The bias value added to output. Default is 0.
+
lambd : float (default is 0.5)
+
The lambd value for the Shrink formulation. Default is 0.5.
+
+ +#### Inputs + +
+
input (differentiable) : T
+
The input data as Tensor.
+
+ +#### Outputs + +
+
output (differentiable) : T
+
The output.
+
+ +#### Type Constraints + +
+
T : tensor(uint8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(int8), tensor(int16), tensor(int32), tensor(int64), tensor(float16), tensor(float), tensor(double)
+
Constrains input to only numeric types.
+
+ + +#### Examples + +
+hard_shrink + +```python +node = onnx.helper.make_node( + 'Shrink', + inputs=['x'], + outputs=['y'], + lambd=1.5, +) +X = np.arange(-2.0, 2.1, dtype=np.float32) +Y = np.array([-2, 0, 0, 0, 2], dtype=np.float32) +expect(node, inputs=[X], outputs=[Y], + name='test_shrink_hard') +``` + +
+ + +
+soft_shrink + +```python +node = onnx.helper.make_node( + 'Shrink', + inputs=['x'], + outputs=['y'], + lambd=1.5, + bias=1.5, +) +X = np.arange(-2.0, 2.1, dtype=np.float32) +Y = np.array([-0.5, 0, 0, 0, 0.5], dtype=np.float32) +expect(node, inputs=[X], outputs=[Y], + name='test_shrink_soft') +``` + +
+ + +### **Sigmoid** + + Sigmoid takes one input data (Tensor) and produces one output data + (Tensor) where the sigmoid function, y = 1 / (1 + exp(-x)), is applied to the + tensor elementwise. + +#### Version + +This version of the operator has been available since version 13 of the default ONNX operator set. + +Other versions of this operator: 1, 6 + +#### Inputs + +
+
X (differentiable) : T
+
Input tensor
+
+ +#### Outputs + +
+
Y (differentiable) : T
+
Output tensor
+
+ +#### Type Constraints + +
+
T : tensor(float16), tensor(float), tensor(double), tensor(bfloat16)
+
Constrain input and output types to float tensors.
+
+ + +#### Examples + +
+sigmoid + +```python +node = onnx.helper.make_node( + 'Sigmoid', + inputs=['x'], + outputs=['y'], +) + +x = np.array([-1, 0, 1]).astype(np.float32) +y = 1.0 / (1.0 + np.exp(np.negative(x))) # expected output [0.26894143, 0.5, 0.7310586] +expect(node, inputs=[x], outputs=[y], + name='test_sigmoid_example') + +x = np.random.randn(3, 4, 5).astype(np.float32) +y = 1.0 / (1.0 + np.exp(np.negative(x))) +expect(node, inputs=[x], outputs=[y], + name='test_sigmoid') +``` + +
+ + +### **Sign** + + Calculate the sign of the given input tensor element-wise. + If input > 0, output 1. if input < 0, output -1. if input == 0, output 0. + +#### Version + +This version of the operator has been available since version 13 of the default ONNX operator set. + +Other versions of this operator: 9 + +#### Inputs + +
+
input (non-differentiable) : T
+
Input tensor
+
+ +#### Outputs + +
+
output (non-differentiable) : T
+
The sign of the input tensor computed element-wise. It has the same shape and type of the input.
+
+ +#### Type Constraints + +
+
T : tensor(uint8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(int8), tensor(int16), tensor(int32), tensor(int64), tensor(float16), tensor(float), tensor(double), tensor(bfloat16)
+
Constrain input and output types to all numeric tensors.
+
+ + +#### Examples + +
+sign + +```python +node = onnx.helper.make_node( + 'Sign', + inputs=['x'], + outputs=['y'], +) + +x = np.array(range(-5, 6)).astype(np.float32) +y = np.sign(x) +expect(node, inputs=[x], outputs=[y], + name='test_sign') +``` + +
+ + +### **Sin** + + Calculates the sine of the given input tensor, element-wise. + +#### Version + +This version of the operator has been available since version 7 of the default ONNX operator set. + +#### Inputs + +
+
input (differentiable) : T
+
Input tensor
+
+ +#### Outputs + +
+
output (differentiable) : T
+
The sine of the input tensor computed element-wise
+
+ +#### Type Constraints + +
+
T : tensor(float16), tensor(float), tensor(double)
+
Constrain input and output types to float tensors.
+
+ + +#### Examples + +
+sin + +```python +node = onnx.helper.make_node( + 'Sin', + inputs=['x'], + outputs=['y'], +) + +x = np.array([-1, 0, 1]).astype(np.float32) +y = np.sin(x) +expect(node, inputs=[x], outputs=[y], + name='test_sin_example') + +x = np.random.randn(3, 4, 5).astype(np.float32) +y = np.sin(x) +expect(node, inputs=[x], outputs=[y], + name='test_sin') +``` + +
+ + +### **Sinh** + + Calculates the hyperbolic sine of the given input tensor element-wise. + +#### Version + +This version of the operator has been available since version 9 of the default ONNX operator set. + +#### Inputs + +
+
input (differentiable) : T
+
Input tensor
+
+ +#### Outputs + +
+
output (differentiable) : T
+
The hyperbolic sine values of the input tensor computed element-wise
+
+ +#### Type Constraints + +
+
T : tensor(float16), tensor(float), tensor(double)
+
Constrain input and output types to float tensors.
+
+ + +#### Examples + +
+sinh + +```python +node = onnx.helper.make_node( + 'Sinh', + inputs=['x'], + outputs=['y'], +) + +x = np.array([-1, 0, 1]).astype(np.float32) +y = np.sinh(x) # expected output [-1.17520118, 0., 1.17520118] +expect(node, inputs=[x], outputs=[y], + name='test_sinh_example') + +x = np.random.randn(3, 4, 5).astype(np.float32) +y = np.sinh(x) +expect(node, inputs=[x], outputs=[y], + name='test_sinh') +``` + +
+ + +### **Size** + + Takes a tensor as input and outputs a int64 scalar that equals to the total number of elements of the input tensor. + +#### Version + +This version of the operator has been available since version 13 of the default ONNX operator set. + +Other versions of this operator: 1 + +#### Inputs + +
+
data (non-differentiable) : T
+
An input tensor.
+
+ +#### Outputs + +
+
size (non-differentiable) : T1
+
Total number of elements of the input tensor
+
+ +#### Type Constraints + +
+
T : tensor(uint8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(int8), tensor(int16), tensor(int32), tensor(int64), tensor(bfloat16), tensor(float16), tensor(float), tensor(double), tensor(string), tensor(bool), tensor(complex64), tensor(complex128)
+
Input tensor can be of arbitrary type.
+
T1 : tensor(int64)
+
Constrain output to int64 tensor, which should be a scalar though.
+
+ + +#### Examples + +
+size + +```python +node = onnx.helper.make_node( + 'Size', + inputs=['x'], + outputs=['y'], +) + +x = np.array([ + [1, 2, 3], + [4, 5, 6], +]).astype(np.float32) +y = np.array(6).astype(np.int64) + +expect(node, inputs=[x], outputs=[y], + name='test_size_example') + +x = np.random.randn(3, 4, 5).astype(np.float32) +y = np.array(x.size).astype(np.int64) + +expect(node, inputs=[x], outputs=[y], + name='test_size') +``` + +
+ + +### **Slice** + + Produces a slice of the input tensor along multiple axes. Similar to numpy: + https://docs.scipy.org/doc/numpy/reference/arrays.indexing.html + Slices uses `starts`, `ends`, `axes` and `steps` inputs to specify the start and end + dimension and step for each axis in the list of axes, it uses this information to + slice the input `data` tensor. If a negative value is passed for any of the + start or end indices, it represents number of elements before the end of that + dimension. If the value passed to start or end is larger than the `n` (the + number of elements in this dimension), it represents `n`. For slicing to the + end of a dimension with unknown size, it is recommended to pass in `INT_MAX` + when sclicing forward and 'INT_MIN' when slicing backward. + If a negative value is passed for step, it represents slicing backward. + However step value cannot be 0. + If `axes` are omitted, they are set to `[0, ..., ndim-1]`. + If `steps` are omitted, they are set to `[1, ..., 1]` of length `len(starts)` + Example 1: + data = [ + [1, 2, 3, 4], + [5, 6, 7, 8], + ] + axes = [0, 1] + starts = [1, 0] + ends = [2, 3] + steps = [1, 2] + result = [ + [5, 7], + ] + Example 2: + data = [ + [1, 2, 3, 4], + [5, 6, 7, 8], + ] + starts = [0, 1] + ends = [-1, 1000] + result = [ + [2, 3, 4], + ] + +#### Version + +This version of the operator has been available since version 13 of the default ONNX operator set. + +Other versions of this operator: 1, 10, 11 + +#### Inputs (3 - 5) + +
+
data (differentiable) : T
+
Tensor of data to extract slices from.
+
starts (non-differentiable) : Tind
+
1-D tensor of starting indices of corresponding axis in `axes`
+
ends (non-differentiable) : Tind
+
1-D tensor of ending indices (exclusive) of corresponding axis in `axes`
+
axes (optional, non-differentiable) : Tind
+
1-D tensor of axes that `starts` and `ends` apply to. Negative value means counting dimensions from the back. Accepted range is [-r, r-1] where r = rank(data).
+
steps (optional, non-differentiable) : Tind
+
1-D tensor of slice step of corresponding axis in `axes`. Negative value means slicing backward. 'steps' cannot be 0. Defaults to 1.
+
+ +#### Outputs + +
+
output (differentiable) : T
+
Sliced data tensor.
+
+ +#### Type Constraints + +
+
T : tensor(uint8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(int8), tensor(int16), tensor(int32), tensor(int64), tensor(bfloat16), tensor(float16), tensor(float), tensor(double), tensor(string), tensor(bool), tensor(complex64), tensor(complex128)
+
Constrain input and output types to all tensor types.
+
Tind : tensor(int32), tensor(int64)
+
Constrain indices to integer types
+
+ + +#### Examples + +
+slice + +```python +node = onnx.helper.make_node( + 'Slice', + inputs=['x', 'starts', 'ends', 'axes', 'steps'], + outputs=['y'], +) + +x = np.random.randn(20, 10, 5).astype(np.float32) +y = x[0:3, 0:10] +starts = np.array([0, 0], dtype=np.int64) +ends = np.array([3, 10], dtype=np.int64) +axes = np.array([0, 1], dtype=np.int64) +steps = np.array([1, 1], dtype=np.int64) + +expect(node, inputs=[x, starts, ends, axes, steps], outputs=[y], + name='test_slice') +``` + +
+ + +
+slice_default_axes + +```python +node = onnx.helper.make_node( + 'Slice', + inputs=['x', 'starts', 'ends'], + outputs=['y'], +) + +x = np.random.randn(20, 10, 5).astype(np.float32) +starts = np.array([0, 0, 3], dtype=np.int64) +ends = np.array([20, 10, 4], dtype=np.int64) +y = x[:, :, 3:4] + +expect(node, inputs=[x, starts, ends], outputs=[y], + name='test_slice_default_axes') +``` + +
+ + +
+slice_default_steps + +```python +node = onnx.helper.make_node( + 'Slice', + inputs=['x', 'starts', 'ends', 'axes'], + outputs=['y'], +) + +x = np.random.randn(20, 10, 5).astype(np.float32) +starts = np.array([0, 0, 3], dtype=np.int64) +ends = np.array([20, 10, 4], dtype=np.int64) +axes = np.array([0, 1, 2], dtype=np.int64) +y = x[:, :, 3:4] + +expect(node, inputs=[x, starts, ends, axes], outputs=[y], + name='test_slice_default_steps') +``` + +
+ + +
+slice_end_out_of_bounds + +```python +node = onnx.helper.make_node( + 'Slice', + inputs=['x', 'starts', 'ends', 'axes', 'steps'], + outputs=['y'], +) + +x = np.random.randn(20, 10, 5).astype(np.float32) +starts = np.array([1], dtype=np.int64) +ends = np.array([1000], dtype=np.int64) +axes = np.array([1], dtype=np.int64) +steps = np.array([1], dtype=np.int64) +y = x[:, 1:1000] + +expect(node, inputs=[x, starts, ends, axes, steps], outputs=[y], + name='test_slice_end_out_of_bounds') +``` + +
+ + +
+slice_neg + +```python +node = onnx.helper.make_node( + 'Slice', + inputs=['x', 'starts', 'ends', 'axes', 'steps'], + outputs=['y'], +) + +x = np.random.randn(20, 10, 5).astype(np.float32) +starts = np.array([0], dtype=np.int64) +ends = np.array([-1], dtype=np.int64) +axes = np.array([1], dtype=np.int64) +steps = np.array([1], dtype=np.int64) +y = x[:, 0:-1] + +expect(node, inputs=[x, starts, ends, axes, steps], outputs=[y], + name='test_slice_neg') +``` + +
+ + +
+slice_neg_steps + +```python +node = onnx.helper.make_node( + 'Slice', + inputs=['x', 'starts', 'ends', 'axes', 'steps'], + outputs=['y'], +) + +x = np.random.randn(20, 10, 5).astype(np.float32) +starts = np.array([20, 10, 4], dtype=np.int64) +ends = np.array([0, 0, 1], dtype=np.int64) +axes = np.array([0, 1, 2], dtype=np.int64) +steps = np.array([-1, -3, -2]).astype(np.int64) +y = x[20:0:-1, 10:0:-3, 4:1:-2] + +expect(node, inputs=[x, starts, ends, axes, steps], outputs=[y], + name='test_slice_neg_steps') +``` + +
+ + +
+slice_negative_axes + +```python +node = onnx.helper.make_node( + 'Slice', + inputs=['x', 'starts', 'ends', 'axes'], + outputs=['y'], +) + +x = np.random.randn(20, 10, 5).astype(np.float32) +starts = np.array([0, 0, 3], dtype=np.int64) +ends = np.array([20, 10, 4], dtype=np.int64) +axes = np.array([0, -2, -1], dtype=np.int64) +y = x[:, :, 3:4] + +expect(node, inputs=[x, starts, ends, axes], outputs=[y], + name='test_slice_negative_axes') +``` + +
+ + +
+slice_start_out_of_bounds + +```python +node = onnx.helper.make_node( + 'Slice', + inputs=['x', 'starts', 'ends', 'axes', 'steps'], + outputs=['y'], +) + +x = np.random.randn(20, 10, 5).astype(np.float32) +starts = np.array([1000], dtype=np.int64) +ends = np.array([1000], dtype=np.int64) +axes = np.array([1], dtype=np.int64) +steps = np.array([1], dtype=np.int64) +y = x[:, 1000:1000] + +expect(node, inputs=[x, starts, ends, axes, steps], outputs=[y], + name='test_slice_start_out_of_bounds') +``` + +
+ + +### **Softmax** + + The operator computes the normalized exponential values for the given input: + + Softmax(input, axis) = Exp(input) / ReduceSum(Exp(input), axis=axis, keepdims=1) + + The "axis" attribute indicates the dimension along which Softmax + will be performed. The output tensor has the same shape + and contains the Softmax values of the corresponding input. + +#### Version + +This version of the operator has been available since version 13 of the default ONNX operator set. + +Other versions of this operator: 1, 11 + +#### Attributes + +
+
axis : int (default is -1)
+
+Describes the dimension Softmax will be performed on. +Negative value means counting dimensions +from the back. Accepted range is [-r, r-1] where r = rank(input). +
+
+ +#### Inputs + +
+
input (differentiable) : T
+
The input tensor of rank >= axis.
+
+ +#### Outputs + +
+
output (differentiable) : T
+
The output values with the same shape as the input tensor.
+
+ +#### Type Constraints + +
+
T : tensor(float16), tensor(float), tensor(double), tensor(bfloat16)
+
Constrain input and output types to float tensors.
+
+ + +#### Examples + +
+softmax + +```python +node = onnx.helper.make_node( + 'Softmax', + inputs=['x'], + outputs=['y'], +) +x = np.array([[-1, 0, 1]]).astype(np.float32) +# expected output [[0.09003058, 0.24472848, 0.66524094]] +y = softmax(x, axis=1) +expect(node, inputs=[x], outputs=[y], + name='test_softmax_example') +``` + +
+ + +
+softmax_axis + +```python +x = np.array([[0, 1, 2, 3], [10000, 10001, 10002, 10003]] + ).astype(np.float32) +# expected output +# [[0.032058604 0.08714432 0.23688284 0.6439143 ] +# [0.032058604 0.08714432 0.23688284 0.6439143 ]] +y = softmax(x) + +node = onnx.helper.make_node( + 'Softmax', + inputs=['x'], + outputs=['y'], +) +expect(node, inputs=[x], outputs=[y], + name='test_softmax_large_number') + +x = np.abs(np.random.randn(3, 4, 5).astype(np.float32)) +node = onnx.helper.make_node( + 'Softmax', + inputs=['x'], + outputs=['y'], + axis=0, +) +y = softmax(x, axis=0) +expect(node, inputs=[x], outputs=[y], + name='test_softmax_axis_0') + +node = onnx.helper.make_node( + 'Softmax', + inputs=['x'], + outputs=['y'], + axis=1, +) +y = softmax(x, axis=1) +expect(node, inputs=[x], outputs=[y], + name='test_softmax_axis_1') + +node = onnx.helper.make_node( + 'Softmax', + inputs=['x'], + outputs=['y'], + axis=2, +) +y = softmax(x, axis=2) +expect(node, inputs=[x], outputs=[y], + name='test_softmax_axis_2') + +node = onnx.helper.make_node( + 'Softmax', + inputs=['x'], + outputs=['y'], + axis=-1, +) +y = softmax(x, axis=-1) +expect(node, inputs=[x], outputs=[y], + name='test_softmax_negative_axis') + +# default axis is -1 +node = onnx.helper.make_node( + 'Softmax', + inputs=['x'], + outputs=['y'], +) +expect(node, inputs=[x], outputs=[y], + name='test_softmax_default_axis') +``` + +
+ + +### **SoftmaxCrossEntropyLoss** + + Loss function that measures the softmax cross entropy + between 'scores' and 'labels'. + This operator first computes a loss tensor whose shape is identical to the labels input. + If the input is 2-D with shape (N, C), the loss tensor may be a N-element vector L = (l_1, l_2, ..., l_N). + If the input is N-D tensor with shape (N, C, D1, D2, ..., Dk), + the loss tensor L may have (N, D1, D2, ..., Dk) as its shape and L[i,][j_1][j_2]...[j_k] denotes a scalar element in L. + After L is available, this operator can optionally do a reduction operator. + + shape(scores): (N, C) where C is the number of classes, or (N, C, D1, D2,..., Dk), + with K >= 1 in case of K-dimensional loss. + shape(labels): (N) where each value is 0 <= labels[i] <= C-1, or (N, D1, D2,..., Dk), + with K >= 1 in case of K-dimensional loss. + + The loss for one sample, l_i, can caculated as follows: + l[i][d1][d2]...[dk] = -y[i][c][d1][d2]..[dk], where i is the index of classes. + or + l[i][d1][d2]...[dk] = -y[i][c][d1][d2]..[dk] * weights[c], if 'weights' is provided. + + loss is zero for the case when label-value equals ignore_index. + l[i][d1][d2]...[dk] = 0, when labels[n][d1][d2]...[dk] = ignore_index + + where: + p = Softmax(scores) + y = Log(p) + c = labels[i][d1][d2]...[dk] + + Finally, L is optionally reduced: + If reduction = 'none', the output is L with shape (N, D1, D2, ..., Dk). + If reduction = 'sum', the output is scalar: Sum(L). + If reduction = 'mean', the output is scalar: ReduceMean(L), or if weight is provided: ReduceSum(L) / ReduceSum(W), + where tensor W is of shape (N, D1, D2, ..., Dk) and W[n][d1][d2]...[dk] = weights[labels[i][d1][d2]...[dk]]. + +#### Version + +This version of the operator has been available since version 13 of the default ONNX operator set. + +Other versions of this operator: 12 + +#### Attributes + +
+
ignore_index : int
+
Specifies a target value that is ignored and does not contribute to the input gradient. It's an optional value.
+
reduction : string (default is mean)
+
Type of reduction to apply to loss: none, sum, mean(default). 'none': no reduction will be applied, 'sum': the output will be summed. 'mean': the sum of the output will be divided by the number of elements in the output.
+
+ +#### Inputs (2 - 3) + +
+
scores (differentiable) : T
+
The predicted outputs with shape [batch_size, class_size], or [batch_size, class_size, D1, D2 , ..., Dk], where K is the number of dimensions.
+
labels (non-differentiable) : Tind
+
The ground truth output tensor, with shape [batch_size], or [batch_size, D1, D2, ..., Dk], where K is the number of dimensions. Labels element value shall be in range of [0, C). If ignore_index is specified, it may have a value outside [0, C) and the label values should either be in the range [0, C) or have the value ignore_index.
+
weights (optional, non-differentiable) : T
+
A manual rescaling weight given to each class. If given, it has to be a 1D Tensor assigning weight to each of the classes. Otherwise, it is treated as if having all ones.
+
+ +#### Outputs (1 - 2) + +
+
output (differentiable) : T
+
Weighted loss float Tensor. If reduction is 'none', this has the shape of [batch_size], or [batch_size, D1, D2, ..., Dk] in case of K-dimensional loss. Otherwise, it is a scalar.
+
log_prob (optional, differentiable) : T
+
Log probability tensor. If the output of softmax is prob, its value is log(prob).
+
+ +#### Type Constraints + +
+
T : tensor(float16), tensor(float), tensor(double), tensor(bfloat16)
+
Constrain input and output types to float tensors.
+
Tind : tensor(int32), tensor(int64)
+
Constrain target to integer types
+
+ + +#### Examples + +
+input_shape_is_NCd1_mean_weight_negative_ii + +```python +reduction = 'mean' +ignore_index = np.int64(-1) + +node = onnx.helper.make_node('SoftmaxCrossEntropyLoss', + inputs=['x', 'y', 'w'], + outputs=['z'], + reduction=reduction, + ignore_index=ignore_index) + +N, C, dim1 = 3, 5, 6 +np.random.seed(0) +x = np.random.rand(N, C, dim1).astype(np.float32) +labels = np.random.randint(0, high=C, size=(N, dim1)).astype(np.int64) +labels[0][0] = -1 +weight = np.random.rand(C).astype(np.float32) + +sce = softmaxcrossentropy(x, + labels, + weight=weight, + reduction=reduction, + ignore_index=ignore_index) + +expect(node, inputs=[x, labels, weight], outputs=[sce], name='test_sce_NCd1_mean_weight_negative_ii') +``` + +
+ + +
+input_shape_is_NCd1_mean_weight_negative_ii_log_prob + +```python +reduction = 'mean' +ignore_index = np.int64(-1) + +node = onnx.helper.make_node('SoftmaxCrossEntropyLoss', + inputs=['x', 'y', 'w'], + outputs=['z', 'log_prob'], + reduction=reduction, + ignore_index=ignore_index) + +N, C, dim1 = 3, 5, 6 +np.random.seed(0) +x = np.random.rand(N, C, dim1).astype(np.float32) +labels = np.random.randint(0, high=C, size=(N, dim1)).astype(np.int64) +labels[0][0] = -1 +weight = np.random.rand(C).astype(np.float32) + +loss, log_prob = softmaxcrossentropy(x, + labels, + weight=weight, + reduction=reduction, + ignore_index=ignore_index, + get_log_prob=True) + +expect(node, inputs=[x, labels, weight], outputs=[loss, log_prob], name='test_sce_NCd1_mean_weight_negative_ii_log_prob') +``` + +
+ + +
+input_shape_is_NCd1d2d3_none_no_weight_negative_ii + +```python +reduction = 'none' +ignore_index = np.int64(-5) + +node = onnx.helper.make_node('SoftmaxCrossEntropyLoss', + inputs=['x', 'y'], + outputs=['z'], + reduction=reduction, + ignore_index=ignore_index) + +N, C, dim1, dim2, dim3 = 3, 5, 6, 6, 5 +np.random.seed(0) +x = np.random.rand(N, C, dim1, dim2, dim3).astype(np.float32) +labels = np.random.randint(0, high=C, size=(N, dim1, dim2, dim3)).astype(np.int64) +labels[0][0][0][0] = -5 + +sce = softmaxcrossentropy(x, + labels, + reduction=reduction, + ignore_index=ignore_index) + +expect(node, inputs=[x, labels], outputs=[sce], name='test_sce_NCd1d2d3_none_no_weight_negative_ii') +``` + +
+ + +
+input_shape_is_NCd1d2d3_none_no_weight_negative_ii_log_prob + +```python +reduction = 'none' +ignore_index = np.int64(-5) + +node = onnx.helper.make_node('SoftmaxCrossEntropyLoss', + inputs=['x', 'y'], + outputs=['z', 'log_prob'], + reduction=reduction, + ignore_index=ignore_index) + +N, C, dim1, dim2, dim3 = 3, 5, 6, 6, 5 +np.random.seed(0) +x = np.random.rand(N, C, dim1, dim2, dim3).astype(np.float32) +labels = np.random.randint(0, high=C, size=(N, dim1, dim2, dim3)).astype(np.int64) +labels[0][0][0][0] = -5 + +loss, log_prob = softmaxcrossentropy(x, + labels, + reduction=reduction, + ignore_index=ignore_index, + get_log_prob=True) + +expect(node, inputs=[x, labels], outputs=[loss, log_prob], name='test_sce_NCd1d2d3_none_no_weight_negative_ii_log_prob') +``` + +
+ + +
+input_shape_is_NCd1d2d3_sum_weight_high_ii + +```python +reduction = 'sum' +ignore_index = np.int64(10) + +node = onnx.helper.make_node('SoftmaxCrossEntropyLoss', + inputs=['x', 'y', 'w'], + outputs=['z'], + reduction=reduction, + ignore_index=ignore_index) + +N, C = 3, 5 +np.random.seed(0) +x = np.random.rand(N, C).astype(np.float32) +labels = np.random.randint(0, high=C, size=(N)).astype(np.int64) +labels[0] = 10 +weight = np.random.rand(C).astype(np.float32) + +sce = softmaxcrossentropy(x, + labels, + weight=weight, + reduction=reduction, + ignore_index=ignore_index) + +expect(node, inputs=[x, labels, weight], outputs=[sce], name='test_sce_NCd1d2d3_sum_weight_high_ii') +``` + +
+ + +
+input_shape_is_NCd1d2d3_sum_weight_high_ii_log_prob + +```python +reduction = 'sum' +ignore_index = np.int64(10) + +node = onnx.helper.make_node('SoftmaxCrossEntropyLoss', + inputs=['x', 'y', 'w'], + outputs=['z', 'log_prob'], + reduction=reduction, + ignore_index=ignore_index) + +N, C = 3, 5 +np.random.seed(0) +x = np.random.rand(N, C).astype(np.float32) +labels = np.random.randint(0, high=C, size=(N)).astype(np.int64) +labels[0] = 10 +weight = np.random.rand(C).astype(np.float32) + +loss, log_prob = softmaxcrossentropy(x, + labels, + weight=weight, + reduction=reduction, + ignore_index=ignore_index, + get_log_prob=True) + +expect(node, inputs=[x, labels, weight], outputs=[loss, log_prob], name='test_sce_NCd1d2d3_sum_weight_high_ii_log_prob') +``` + +
+ + +
+input_shape_is_NCd1d2d3d4d5_mean_weight + +```python +reduction = 'mean' + +node = onnx.helper.make_node('SoftmaxCrossEntropyLoss', + inputs=['x', 'y', 'w'], + outputs=['z'], + reduction=reduction) + +N, C, dim1, dim2, dim3, dim4, dim5 = 3, 5, 6, 6, 5, 3, 4 +np.random.seed(0) +x = np.random.rand(N, C, dim1, dim2, dim3, dim4, dim5).astype(np.float32) +labels = np.random.randint(0, high=C, size=(N, dim1, dim2, dim3, dim4, dim5)).astype(np.int64) +weight = np.random.rand(C).astype(np.float32) + +sce = softmaxcrossentropy(x, + labels, + weight=weight, + reduction=reduction) + +expect(node, inputs=[x, labels, weight], outputs=[sce], name='test_sce_NCd1d2d3d4d5_mean_weight') +``` + +
+ + +
+input_shape_is_NCd1d2d3d4d5_mean_weight_log_prob + +```python +reduction = 'mean' + +node = onnx.helper.make_node('SoftmaxCrossEntropyLoss', + inputs=['x', 'y', 'w'], + outputs=['z', 'log_prob'], + reduction=reduction) + +N, C, dim1, dim2, dim3, dim4, dim5 = 3, 5, 6, 6, 5, 3, 4 +np.random.seed(0) +x = np.random.rand(N, C, dim1, dim2, dim3, dim4, dim5).astype(np.float32) +labels = np.random.randint(0, high=C, size=(N, dim1, dim2, dim3, dim4, dim5)).astype(np.int64) +weight = np.random.rand(C).astype(np.float32) + +loss, log_prob = softmaxcrossentropy(x, + labels, + weight=weight, + reduction=reduction, + get_log_prob=True) + +expect(node, inputs=[x, labels, weight], outputs=[loss, log_prob], name='test_sce_NCd1d2d3d4d5_mean_weight_log_prob') +``` + +
+ + +
+input_shape_is_NCd1d2d3d4d5_none_no_weight + +```python +reduction = 'none' + +node = onnx.helper.make_node('SoftmaxCrossEntropyLoss', + inputs=['x', 'y'], + outputs=['z'], + reduction=reduction) + +N, C, dim1, dim2, dim3, dim4, dim5 = 3, 5, 6, 6, 5, 3, 4 +np.random.seed(0) +x = np.random.rand(N, C, dim1, dim2, dim3, dim4, dim5).astype(np.float32) +labels = np.random.randint(0, high=C, size=(N, dim1, dim2, dim3, dim4, dim5)).astype(np.int64) + +sce = softmaxcrossentropy(x, + labels, + reduction=reduction) + +expect(node, inputs=[x, labels], outputs=[sce], name='test_sce_NCd1d2d3d4d5_none_no_weight') +``` + +
+ + +
+input_shape_is_NCd1d2d3d4d5_none_no_weight_log_prob + +```python +reduction = 'none' + +node = onnx.helper.make_node('SoftmaxCrossEntropyLoss', + inputs=['x', 'y'], + outputs=['z', 'log_prob'], + reduction=reduction) + +N, C, dim1, dim2, dim3, dim4, dim5 = 3, 5, 6, 6, 5, 3, 4 +np.random.seed(0) +x = np.random.rand(N, C, dim1, dim2, dim3, dim4, dim5).astype(np.float32) +labels = np.random.randint(0, high=C, size=(N, dim1, dim2, dim3, dim4, dim5)).astype(np.int64) + +loss, log_prob = softmaxcrossentropy(x, + labels, + reduction=reduction, + get_log_prob=True) + +expect(node, inputs=[x, labels], outputs=[loss, log_prob], name='test_sce_NCd1d2d3d4d5_none_no_weight_log_prob') +``` + +
+ + +
+softmaxcrossentropy_mean + +```python +# Define operator attributes. +reduction = 'mean' + +# Create operator. +node = onnx.helper.make_node('SoftmaxCrossEntropyLoss', + inputs=['x', 'y'], + outputs=['z'], + reduction=reduction) + +# Define operator inputs. +np.random.seed(0) +x = np.random.rand(3, 5).astype(np.float32) +labels = np.random.randint(0, high=5, size=(3, )).astype(np.int64) + +# Compute SoftmaxCrossEntropyLoss +sce = softmaxcrossentropy(x, labels) + +# Check results +expect(node, inputs=[x, labels], outputs=[sce], name='test_sce_mean') +``` + +
+ + +
+softmaxcrossentropy_mean_3d + +```python +# Define operator attributes. +reduction = 'mean' + +# Create operator. +node = onnx.helper.make_node('SoftmaxCrossEntropyLoss', + inputs=['x', 'y'], + outputs=['z'], + reduction=reduction) + +# Define operator inputs. +np.random.seed(0) +x = np.random.rand(3, 5, 2).astype(np.float32) +y = np.random.randint(0, high=5, size=(3, 2)).astype(np.int64) + +# Compute SoftmaxCrossEntropyLoss +sce = softmaxcrossentropy(x, y) + +# Check results +expect(node, inputs=[x, y], outputs=[sce], name='test_sce_mean_3d') +``` + +
+ + +
+softmaxcrossentropy_mean_3d_log_prob + +```python +# Define operator attributes. +reduction = 'mean' + +# Create operator. +node = onnx.helper.make_node('SoftmaxCrossEntropyLoss', + inputs=['x', 'y'], + outputs=['z', 'log_prob'], + reduction=reduction) + +# Define operator inputs. +np.random.seed(0) +x = np.random.rand(3, 5, 2).astype(np.float32) +y = np.random.randint(0, high=5, size=(3, 2)).astype(np.int64) + +# Compute SoftmaxCrossEntropyLoss +loss, log_prob = softmaxcrossentropy(x, y, get_log_prob=True) + +# Check results +expect(node, inputs=[x, y], outputs=[loss, log_prob], name='test_sce_mean_3d_log_prob') +``` + +
+ + +
+softmaxcrossentropy_mean_log_prob + +```python +# Define operator attributes. +reduction = 'mean' + +# Create operator. +node = onnx.helper.make_node('SoftmaxCrossEntropyLoss', + inputs=['x', 'y'], + outputs=['z', 'log_prob'], + reduction=reduction) + +# Define operator inputs. +np.random.seed(0) +x = np.random.rand(3, 5).astype(np.float32) +labels = np.random.randint(0, high=5, size=(3, )).astype(np.int64) + +# Compute SoftmaxCrossEntropyLoss +loss, log_prob = softmaxcrossentropy(x, labels, get_log_prob=True) + +# Check results +expect(node, inputs=[x, labels], outputs=[loss, log_prob], name='test_sce_mean_log_prob') +``` + +
+ + +
+softmaxcrossentropy_mean_no_weights_ii + +```python +# Define operator attributes. +reduction = 'mean' +ignore_index = np.int64(2) + +# Create operator. +node = onnx.helper.make_node('SoftmaxCrossEntropyLoss', + inputs=['x', 'y'], + outputs=['z'], + reduction=reduction, + ignore_index=ignore_index) + +# Define operator inputs. +np.random.seed(0) +x = np.random.rand(3, 5).astype(np.float32) +labels = np.random.randint(0, high=5, size=(3, )).astype(np.int64) +labels[0] = np.int64(2) + +# Compute SoftmaxCrossEntropyLoss +sce = softmaxcrossentropy(x, labels, ignore_index=ignore_index) + +# Check results +expect(node, inputs=[x, labels], outputs=[sce], name='test_sce_mean_no_weight_ii') +``` + +
+ + +
+softmaxcrossentropy_mean_no_weights_ii_3d + +```python +# Define operator attributes. +reduction = 'mean' +ignore_index = np.int64(2) + +# Create operator. +node = onnx.helper.make_node('SoftmaxCrossEntropyLoss', + inputs=['x', 'y'], + outputs=['z'], + reduction=reduction, + ignore_index=ignore_index) + +# Define operator inputs. +np.random.seed(0) +x = np.random.rand(3, 5, 2).astype(np.float32) +labels = np.random.randint(0, high=5, size=(3, 2)).astype(np.int64) +labels[0][0] = np.int64(2) + +# Compute SoftmaxCrossEntropyLoss +sce = softmaxcrossentropy(x, labels, ignore_index=ignore_index) + +# Check results +expect(node, inputs=[x, labels], outputs=[sce], name='test_sce_mean_no_weight_ii_3d') +``` + +
+ + +
+softmaxcrossentropy_mean_no_weights_ii_3d_log_prob + +```python +# Define operator attributes. +reduction = 'mean' +ignore_index = np.int64(2) + +# Create operator. +node = onnx.helper.make_node('SoftmaxCrossEntropyLoss', + inputs=['x', 'y'], + outputs=['z', 'log_prob'], + reduction=reduction, + ignore_index=ignore_index) + +# Define operator inputs. +np.random.seed(0) +x = np.random.rand(3, 5, 2).astype(np.float32) +labels = np.random.randint(0, high=5, size=(3, 2)).astype(np.int64) +labels[0][0] = np.int64(2) + +# Compute SoftmaxCrossEntropyLoss +loss, log_prob = softmaxcrossentropy(x, labels, ignore_index=ignore_index, get_log_prob=True) + +# Check results +expect(node, inputs=[x, labels], outputs=[loss, log_prob], name='test_sce_mean_no_weight_ii_3d_log_prob') +``` + +
+ + +
+softmaxcrossentropy_mean_no_weights_ii_4d + +```python +# Define operator attributes. +reduction = 'mean' +ignore_index = np.int64(2) + +# Create operator. +node = onnx.helper.make_node('SoftmaxCrossEntropyLoss', + inputs=['x', 'y'], + outputs=['z'], + reduction=reduction, + ignore_index=ignore_index) + +# Define operator inputs. +np.random.seed(0) +x = np.random.rand(3, 5, 2, 7).astype(np.float32) +labels = np.random.randint(0, high=5, size=(3, 2, 7)).astype(np.int64) +labels[0][0][0] = np.int64(2) + +# Compute SoftmaxCrossEntropyLoss +sce = softmaxcrossentropy(x, labels, reduction=reduction, ignore_index=ignore_index) + +# Check results +expect(node, inputs=[x, labels], outputs=[sce], name='test_sce_mean_no_weight_ii_4d') +``` + +
+ + +
+softmaxcrossentropy_mean_no_weights_ii_4d_log_prob + +```python +# Define operator attributes. +reduction = 'mean' +ignore_index = np.int64(2) + +# Create operator. +node = onnx.helper.make_node('SoftmaxCrossEntropyLoss', + inputs=['x', 'y'], + outputs=['z', 'log_prob'], + reduction=reduction, + ignore_index=ignore_index) + +# Define operator inputs. +np.random.seed(0) +x = np.random.rand(3, 5, 2, 7).astype(np.float32) +labels = np.random.randint(0, high=5, size=(3, 2, 7)).astype(np.int64) +labels[0][0][0] = np.int64(2) + +# Compute SoftmaxCrossEntropyLoss +loss, log_prob = softmaxcrossentropy(x, labels, reduction=reduction, ignore_index=ignore_index, get_log_prob=True) + +# Check results +expect(node, inputs=[x, labels], outputs=[loss, log_prob], name='test_sce_mean_no_weight_ii_4d_log_prob') +``` + +
+ + +
+softmaxcrossentropy_mean_no_weights_ii_log_prob + +```python +# Define operator attributes. +reduction = 'mean' +ignore_index = np.int64(2) + +# Create operator. +node = onnx.helper.make_node('SoftmaxCrossEntropyLoss', + inputs=['x', 'y'], + outputs=['z', 'log_prob'], + reduction=reduction, + ignore_index=ignore_index) + +# Define operator inputs. +np.random.seed(0) +x = np.random.rand(3, 5).astype(np.float32) +labels = np.random.randint(0, high=5, size=(3, )).astype(np.int64) +labels[0] = np.int64(2) + +# Compute SoftmaxCrossEntropyLoss +loss, log_prob = softmaxcrossentropy(x, labels, ignore_index=ignore_index, get_log_prob=True) + +# Check results +expect(node, inputs=[x, labels], outputs=[loss, log_prob], name='test_sce_mean_no_weight_ii_log_prob') +``` + +
+ + +
+softmaxcrossentropy_mean_weights + +```python +# Define operator attributes. +reduction = 'mean' + +# Create operator. +node = onnx.helper.make_node('SoftmaxCrossEntropyLoss', + inputs=['x', 'y', 'w'], + outputs=['z'], + reduction=reduction) + +# Define operator inputs. +np.random.seed(0) +x = np.random.rand(3, 5).astype(np.float32) +labels = np.random.randint(0, high=5, size=(3, )).astype(np.int64) +weights = np.array([0.9, 0.7, 0.8, 0.9, 0.9], dtype=np.float32) + +# Compute SoftmaxCrossEntropyLoss +sce = softmaxcrossentropy(x, labels, weight=weights) + +# Check results +expect(node, inputs=[x, labels, weights], outputs=[sce], name='test_sce_mean_weight') +``` + +
+ + +
+softmaxcrossentropy_mean_weights_ii + +```python +# Define operator attributes. +reduction = 'mean' +ignore_index = np.int64(0) + +# Create operator. +node = onnx.helper.make_node('SoftmaxCrossEntropyLoss', + inputs=['x', 'y', 'w'], + outputs=['z'], + reduction=reduction, + ignore_index=ignore_index) + +# Define operator inputs. +np.random.seed(0) +x = np.random.rand(3, 5).astype(np.float32) +labels = np.random.randint(0, high=5, size=(3, )).astype(np.int64) +labels[0] = np.int64(0) +weights = np.array([0.9, 0.7, 0.8, 0.9, 0.9], dtype=np.float32) + +# Compute SoftmaxCrossEntropyLoss +sce = softmaxcrossentropy(x, labels, weight=weights, ignore_index=ignore_index) + +# Check results +expect(node, inputs=[x, labels, weights], outputs=[sce], name='test_sce_mean_weight_ii') +``` + +
+ + +
+softmaxcrossentropy_mean_weights_ii_3d + +```python +# Define operator attributes. +reduction = 'mean' +ignore_index = np.int64(1) + +# Create operator. +node = onnx.helper.make_node('SoftmaxCrossEntropyLoss', + inputs=['x', 'y', 'w'], + outputs=['z'], + reduction=reduction, + ignore_index=ignore_index) + +# Define operator inputs. +np.random.seed(0) +x = np.random.rand(3, 5, 2).astype(np.float32) +labels = np.random.randint(0, high=5, size=(3, 2)).astype(np.int64) +labels[0][0] = np.int64(1) +weights = np.array([0.2, 0.3, 0.6, 0.1, 0.5], dtype=np.float32) + +# Compute SoftmaxCrossEntropyLoss +sce = softmaxcrossentropy(x, labels, weight=weights, ignore_index=ignore_index) + +# Check results +expect(node, inputs=[x, labels, weights], outputs=[sce], name='test_sce_mean_weight_ii_3d') +``` + +
+ + +
+softmaxcrossentropy_mean_weights_ii_3d_log_prob + +```python +# Define operator attributes. +reduction = 'mean' +ignore_index = np.int64(1) + +# Create operator. +node = onnx.helper.make_node('SoftmaxCrossEntropyLoss', + inputs=['x', 'y', 'w'], + outputs=['z', 'log_prob'], + reduction=reduction, + ignore_index=ignore_index) + +# Define operator inputs. +np.random.seed(0) +x = np.random.rand(3, 5, 2).astype(np.float32) +labels = np.random.randint(0, high=5, size=(3, 2)).astype(np.int64) +labels[0][0] = np.int64(1) +weights = np.array([0.2, 0.3, 0.6, 0.1, 0.5], dtype=np.float32) + +# Compute SoftmaxCrossEntropyLoss +loss, log_prob = softmaxcrossentropy(x, labels, weight=weights, ignore_index=ignore_index, get_log_prob=True) + +# Check results +expect(node, inputs=[x, labels, weights], outputs=[loss, log_prob], name='test_sce_mean_weight_ii_3d_log_prob') +``` + +
+ + +
+softmaxcrossentropy_mean_weights_ii_4d + +```python +# Define operator attributes. +reduction = 'mean' +ignore_index = np.int64(2) + +# Create operator. +node = onnx.helper.make_node('SoftmaxCrossEntropyLoss', + inputs=['x', 'y', 'w'], + outputs=['z'], + reduction=reduction, + ignore_index=ignore_index) + +# Define operator inputs. +np.random.seed(0) +x = np.random.rand(3, 5, 2, 7).astype(np.float32) +labels = np.random.randint(0, high=5, size=(3, 2, 7)).astype(np.int64) +labels[0][0][0] = np.int64(2) +weights = np.array([0.2, 0.3, 0.6, 0.1, 0.5], dtype=np.float32) + +# Compute SoftmaxCrossEntropyLoss +sce = softmaxcrossentropy(x, labels, reduction=reduction, weight=weights, ignore_index=ignore_index) + +# Check results +expect(node, inputs=[x, labels, weights], outputs=[sce], name='test_sce_mean_weight_ii_4d') +``` + +
+ + +
+softmaxcrossentropy_mean_weights_ii_4d_log_prob + +```python +# Define operator attributes. +reduction = 'mean' +ignore_index = np.int64(2) + +# Create operator. +node = onnx.helper.make_node('SoftmaxCrossEntropyLoss', + inputs=['x', 'y', 'w'], + outputs=['z', 'log_prob'], + reduction=reduction, + ignore_index=ignore_index) + +# Define operator inputs. +np.random.seed(0) +x = np.random.rand(3, 5, 2, 7).astype(np.float32) +labels = np.random.randint(0, high=5, size=(3, 2, 7)).astype(np.int64) +labels[0][0][0] = np.int64(2) +weights = np.array([0.2, 0.3, 0.6, 0.1, 0.5], dtype=np.float32) + +# Compute SoftmaxCrossEntropyLoss +loss, log_prob = softmaxcrossentropy(x, labels, reduction=reduction, weight=weights, ignore_index=ignore_index, get_log_prob=True) + +# Check results +expect(node, inputs=[x, labels, weights], outputs=[loss, log_prob], name='test_sce_mean_weight_ii_4d_log_prob') +``` + +
+ + +
+softmaxcrossentropy_mean_weights_ii_log_prob + +```python +# Define operator attributes. +reduction = 'mean' +ignore_index = np.int64(0) + +# Create operator. +node = onnx.helper.make_node('SoftmaxCrossEntropyLoss', + inputs=['x', 'y', 'w'], + outputs=['z', 'log_prob'], + reduction=reduction, + ignore_index=ignore_index) + +# Define operator inputs. +np.random.seed(0) +x = np.random.rand(3, 5).astype(np.float32) +labels = np.random.randint(0, high=5, size=(3, )).astype(np.int64) +labels[0] = np.int64(0) +weights = np.array([0.9, 0.7, 0.8, 0.9, 0.9], dtype=np.float32) + +# Compute SoftmaxCrossEntropyLoss +loss, log_prob = softmaxcrossentropy(x, labels, weight=weights, ignore_index=ignore_index, get_log_prob=True) + +# Check results +expect(node, inputs=[x, labels, weights], outputs=[loss, log_prob], name='test_sce_mean_weight_ii_log_prob') +``` + +
+ + +
+softmaxcrossentropy_mean_weights_log_prob + +```python +# Define operator attributes. +reduction = 'mean' + +# Create operator. +node = onnx.helper.make_node('SoftmaxCrossEntropyLoss', + inputs=['x', 'y', 'w'], + outputs=['z', 'log_prob'], + reduction=reduction) + +# Define operator inputs. +np.random.seed(0) +x = np.random.rand(3, 5).astype(np.float32) +labels = np.random.randint(0, high=5, size=(3, )).astype(np.int64) +weights = np.array([0.9, 0.7, 0.8, 0.9, 0.9], dtype=np.float32) + +# Compute SoftmaxCrossEntropyLoss +loss, log_prob = softmaxcrossentropy(x, labels, weight=weights, get_log_prob=True) + +# Check results +expect(node, inputs=[x, labels, weights], outputs=[loss, log_prob], name='test_sce_mean_weight_log_prob') +``` + +
+ + +
+softmaxcrossentropy_none + +```python +# Define operator attributes. +reduction = 'none' + +# Create operator. +node = onnx.helper.make_node('SoftmaxCrossEntropyLoss', + inputs=['x', 'y'], + outputs=['z'], + reduction=reduction) + +# Define operator inputs. +np.random.seed(0) +x = np.random.rand(3, 5).astype(np.float32) +labels = np.random.randint(0, high=5, size=(3, )).astype(np.int64) + +# Compute SoftmaxCrossEntropyLoss +sce = softmaxcrossentropy(x, labels, reduction='none') + +# Check results +expect(node, inputs=[x, labels], outputs=[sce], name='test_sce_none') +``` + +
+ + +
+softmaxcrossentropy_none_log_prob + +```python +# Define operator attributes. +reduction = 'none' + +# Create operator. +node = onnx.helper.make_node('SoftmaxCrossEntropyLoss', + inputs=['x', 'y'], + outputs=['z', 'log_prob'], + reduction=reduction) + +# Define operator inputs. +np.random.seed(0) +x = np.random.rand(3, 5).astype(np.float32) +labels = np.random.randint(0, high=5, size=(3, )).astype(np.int64) + +# Compute SoftmaxCrossEntropyLoss +loss, log_prob = softmaxcrossentropy(x, labels, reduction='none', get_log_prob=True) + +# Check results +expect(node, inputs=[x, labels], outputs=[loss, log_prob], name='test_sce_none_log_prob') +``` + +
+ + +
+softmaxcrossentropy_none_weights + +```python +# Define operator attributes. +reduction = 'none' + +# Create operator. +node = onnx.helper.make_node('SoftmaxCrossEntropyLoss', + inputs=['x', 'y', 'w'], + outputs=['z'], + reduction=reduction) + +# Define operator inputs. +np.random.seed(0) +x = np.random.rand(3, 5).astype(np.float32) +labels = np.random.randint(0, high=5, size=(3, )).astype(np.int64) +weights = np.array([0.9, 0.7, 0.8, 0.9, 0.9], dtype=np.float32) + +# Compute SoftmaxCrossEntropyLoss +sce = softmaxcrossentropy(x, labels, weight=weights, reduction='none') + +# Check results +expect(node, inputs=[x, labels, weights], outputs=[sce], name='test_sce_none_weights') +``` + +
+ + +
+softmaxcrossentropy_none_weights_log_prob + +```python +# Define operator attributes. +reduction = 'none' + +# Create operator. +node = onnx.helper.make_node('SoftmaxCrossEntropyLoss', + inputs=['x', 'y', 'w'], + outputs=['z', 'log_prob'], + reduction=reduction) + +# Define operator inputs. +np.random.seed(0) +x = np.random.rand(3, 5).astype(np.float32) +labels = np.random.randint(0, high=5, size=(3, )).astype(np.int64) +weights = np.array([0.9, 0.7, 0.8, 0.9, 0.9], dtype=np.float32) + +# Compute SoftmaxCrossEntropyLoss +loss, log_prob = softmaxcrossentropy(x, labels, weight=weights, reduction='none', get_log_prob=True) + +# Check results +expect(node, inputs=[x, labels, weights], outputs=[loss, log_prob], name='test_sce_none_weights_log_prob') +``` + +
+ + +
+softmaxcrossentropy_sum + +```python +# Define operator attributes. +reduction = 'sum' + +# Create operator. +node = onnx.helper.make_node('SoftmaxCrossEntropyLoss', + inputs=['x', 'y'], + outputs=['z'], + reduction=reduction) + +# Define operator inputs. +np.random.seed(0) +x = np.random.rand(3, 5).astype(np.float32) +labels = np.random.randint(0, high=5, size=(3, )).astype(np.int64) + +# Compute SoftmaxCrossEntropyLoss +sce = softmaxcrossentropy(x, labels, reduction='sum') + +# Check results +expect(node, inputs=[x, labels], outputs=[sce], name='test_sce_sum') +``` + +
+ + +
+softmaxcrossentropy_sum_log_prob + +```python +# Define operator attributes. +reduction = 'sum' + +# Create operator. +node = onnx.helper.make_node('SoftmaxCrossEntropyLoss', + inputs=['x', 'y'], + outputs=['z', 'log_prob'], + reduction=reduction) + +# Define operator inputs. +np.random.seed(0) +x = np.random.rand(3, 5).astype(np.float32) +labels = np.random.randint(0, high=5, size=(3, )).astype(np.int64) + +# Compute SoftmaxCrossEntropyLoss +loss, log_prob = softmaxcrossentropy(x, labels, reduction='sum', get_log_prob=True) + +# Check results +expect(node, inputs=[x, labels], outputs=[loss, log_prob], name='test_sce_sum_log_prob') +``` + +
+ + +### **Softplus** + + Softplus takes one input data (Tensor) and produces one output data + (Tensor) where the softplus function, y = ln(exp(x) + 1), is applied to + the tensor elementwise. + +#### Version + +This version of the operator has been available since version 1 of the default ONNX operator set. + +#### Inputs + +
+
X (differentiable) : T
+
1D input tensor
+
+ +#### Outputs + +
+
Y (differentiable) : T
+
1D input tensor
+
+ +#### Type Constraints + +
+
T : tensor(float16), tensor(float), tensor(double)
+
Constrain input and output types to float tensors.
+
+ + +#### Examples + +
+softplus + +```python +node = onnx.helper.make_node( + 'Softplus', + inputs=['x'], + outputs=['y'], +) + +x = np.array([-1, 0, 1]).astype(np.float32) +y = np.log(np.exp(x) + 1) # expected output [0.31326166, 0.69314718, 1.31326163] +expect(node, inputs=[x], outputs=[y], + name='test_softplus_example') + +x = np.random.randn(3, 4, 5).astype(np.float32) +y = np.log(np.exp(x) + 1) +expect(node, inputs=[x], outputs=[y], + name='test_softplus') +``` + +
+ + +### **Softsign** + + Calculates the softsign (x/(1+|x|)) of the given input tensor element-wise. + +#### Version + +This version of the operator has been available since version 1 of the default ONNX operator set. + +#### Inputs + +
+
input (differentiable) : T
+
Input tensor
+
+ +#### Outputs + +
+
output (differentiable) : T
+
The softsign (x/(1+|x|)) values of the input tensor computed element-wise
+
+ +#### Type Constraints + +
+
T : tensor(float16), tensor(float), tensor(double)
+
Constrain input and output types to float tensors.
+
+ + +#### Examples + +
+softsign + +```python +node = onnx.helper.make_node( + 'Softsign', + inputs=['x'], + outputs=['y'], +) + +x = np.array([-1, 0, 1]).astype(np.float32) +y = np.array([-0.5, 0, 0.5]).astype(np.float32) +expect(node, inputs=[x], outputs=[y], + name='test_softsign_example') + +x = np.random.randn(3, 4, 5).astype(np.float32) +y = x / (1 + np.abs(x)) +expect(node, inputs=[x], outputs=[y], + name='test_softsign') +``` + +
+ + +### **SpaceToDepth** + + SpaceToDepth rearranges blocks of spatial data into depth. More specifically, + this op outputs a copy of the input tensor where values from the height and width dimensions + are moved to the depth dimension. + +#### Version + +This version of the operator has been available since version 13 of the default ONNX operator set. + +Other versions of this operator: 1 + +#### Attributes + +
+
blocksize : int (required)
+
Blocks of [blocksize, blocksize] are moved.
+
+ +#### Inputs + +
+
input (differentiable) : T
+
Input tensor of [N,C,H,W], where N is the batch axis, C is the channel or depth, H is the height and W is the width.
+
+ +#### Outputs + +
+
output (differentiable) : T
+
Output tensor of [N, C * blocksize * blocksize, H/blocksize, W/blocksize].
+
+ +#### Type Constraints + +
+
T : tensor(uint8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(int8), tensor(int16), tensor(int32), tensor(int64), tensor(bfloat16), tensor(float16), tensor(float), tensor(double), tensor(string), tensor(bool), tensor(complex64), tensor(complex128)
+
Constrain input and output types to all tensor types.
+
+ + +#### Examples + +
+example + +```python +node = onnx.helper.make_node( + 'SpaceToDepth', + inputs=['x'], + outputs=['y'], + blocksize=2, +) + +# (1, 1, 4, 6) input tensor +x = np.array([[[[0, 6, 1, 7, 2, 8], + [12, 18, 13, 19, 14, 20], + [3, 9, 4, 10, 5, 11], + [15, 21, 16, 22, 17, 23]]]]).astype(np.float32) + +# (1, 4, 2, 3) output tensor +y = np.array([[[[0, 1, 2], + [3, 4, 5]], + [[6, 7, 8], + [9, 10, 11]], + [[12, 13, 14], + [15, 16, 17]], + [[18, 19, 20], + [21, 22, 23]]]]).astype(np.float32) +expect(node, inputs=[x], outputs=[y], + name='test_spacetodepth_example') +``` + +
+ + +
+spacetodepth + +```python +b, c, h, w = shape = (2, 2, 6, 6) +blocksize = 2 +node = onnx.helper.make_node( + 'SpaceToDepth', + inputs=['x'], + outputs=['y'], + blocksize=blocksize, +) +x = np.random.random_sample(shape).astype(np.float32) +tmp = np.reshape(x, [b, c, + h // blocksize, blocksize, + w // blocksize, blocksize]) +tmp = np.transpose(tmp, [0, 3, 5, 1, 2, 4]) +y = np.reshape(tmp, [b, c * (blocksize**2), + h // blocksize, + w // blocksize]) +expect(node, inputs=[x], outputs=[y], + name='test_spacetodepth') +``` + +
+ + +### **Split** + + Split a tensor into a list of tensors, along the specified + 'axis'. Lengths of the parts can be specified using input 'split'. + Otherwise, the tensor is split to equal sized parts. + +#### Version + +This version of the operator has been available since version 13 of the default ONNX operator set. + +Other versions of this operator: 1, 2, 11 + +#### Attributes + +
+
axis : int (default is 0)
+
Which axis to split on. A negative value means counting dimensions from the back. Accepted range is [-rank, rank-1] where r = rank(input).
+
+ +#### Inputs (1 - 2) + +
+
input (differentiable) : T
+
The tensor to split
+
split (optional, non-differentiable) : tensor(int64)
+
Optional length of each output. Values should be >= 0.Sum of the values must be equal to the dim value at 'axis' specified.
+
+ +#### Outputs (1 - ∞) + +
+
outputs (variadic, differentiable) : T
+
One or more outputs forming list of tensors after splitting
+
+ +#### Type Constraints + +
+
T : tensor(uint8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(int8), tensor(int16), tensor(int32), tensor(int64), tensor(bfloat16), tensor(float16), tensor(float), tensor(double), tensor(string), tensor(bool), tensor(complex64), tensor(complex128)
+
Constrain input and output types to all tensor types.
+
+ + +#### Examples + +
+1d + +```python +input = np.array([1., 2., 3., 4., 5., 6.]).astype(np.float32) + +node = onnx.helper.make_node( + 'Split', + inputs=['input'], + outputs=['output_1', 'output_2', 'output_3'], + axis=0 +) + +expected_outputs = [np.array([1., 2.]).astype(np.float32), np.array([3., 4.]).astype(np.float32), np.array([5., 6.]).astype(np.float32)] +expect(node, inputs=[input], outputs=[y for y in expected_outputs], name='test_split_equal_parts_1d') + +split = np.array([2, 4]).astype(np.int64) +node = onnx.helper.make_node( + 'Split', + inputs=['input', 'split'], + outputs=['output_1', 'output_2'], + axis=0, +) + +expected_outputs = [np.array([1., 2.]).astype(np.float32), np.array([3., 4., 5., 6.]).astype(np.float32)] +expect(node, inputs=[input, split], outputs=[y for y in expected_outputs], name='test_split_variable_parts_1d') +``` + +
+ + +
+2d + +```python +input = np.array([[1., 2., 3., 4., 5., 6.], + [7., 8., 9., 10., 11., 12.]]).astype(np.float32) + +node = onnx.helper.make_node( + 'Split', + inputs=['input'], + outputs=['output_1', 'output_2'], + axis=1 +) + +expected_outputs = [np.array([[1., 2., 3.], [7., 8., 9.]]).astype(np.float32), + np.array([[4., 5., 6.], [10., 11., 12.]]).astype(np.float32)] + +expect(node, inputs=[input], outputs=[y for y in expected_outputs], name='test_split_equal_parts_2d') + +split = np.array([2, 4]).astype(np.int64) +node = onnx.helper.make_node( + 'Split', + inputs=['input', 'split'], + outputs=['output_1', 'output_2'], + axis=1, +) + +expected_outputs = [np.array([[1., 2.], [7., 8.]]).astype(np.float32), + np.array([[3., 4., 5., 6.], [9., 10., 11., 12.]]).astype(np.float32)] + +expect(node, inputs=[input, split], outputs=[y for y in expected_outputs], name='test_split_variable_parts_2d') +``` + +
+ + +
+default_values + +```python +input = np.array([1., 2., 3., 4., 5., 6.]).astype(np.float32) + +# If axis is not specified, split is applied on default axis 0 +node = onnx.helper.make_node( + 'Split', + inputs=['input'], + outputs=['output_1', 'output_2', 'output_3'] +) + +expected_outputs = [np.array([1., 2.]).astype(np.float32), np.array([3., 4.]).astype(np.float32), np.array([5., 6.]).astype(np.float32)] +expect(node, inputs=[input], outputs=[y for y in expected_outputs], name='test_split_equal_parts_default_axis') + +split = np.array([2, 4]).astype(np.int64) +node = onnx.helper.make_node( + 'Split', + inputs=['input', 'split'], + outputs=['output_1', 'output_2'] +) + +expected_outputs = [np.array([1., 2.]).astype(np.float32), np.array([3., 4., 5., 6.]).astype(np.float32)] +expect(node, inputs=[input, split], outputs=[y for y in expected_outputs], name='test_split_variable_parts_default_axis') +``` + +
+ + +
+zero_size_splits + +```python +input = np.array([]).astype(np.float32) + +# Split emtpy tensor to tensors of size zero +split = np.array([0, 0, 0]).astype(np.int64) +node = onnx.helper.make_node( + 'Split', + inputs=['input', 'split'], + outputs=['output_1', 'output_2', 'output_3'] +) + +expected_outputs = [np.array([]).astype(np.float32), np.array([]).astype(np.float32), np.array([]).astype(np.float32)] +expect(node, inputs=[input, split], outputs=[y for y in expected_outputs], name='test_split_zero_size_splits') +``` + +
+ + +### **SplitToSequence** + + Split a tensor into a sequence of tensors, along the specified + 'axis'. Lengths of the parts can be specified using argument 'split'. + 'split' must contain only positive numbers. + 'split' is either a scalar (tensor of empty shape), or a 1-D tensor. + If 'split' is a scalar, then 'input' will be split into equally sized chunks(if possible). + Last chunk will be smaller if the 'input' size along the given axis 'axis' is not divisible + by 'split'. + Otherwise, the tensor is split into 'size(split)' chunks, with lengths of the parts on 'axis' + specified in 'split'. In this scenario, the sum of entries in 'split' must be equal to the + dimension size of input tensor on 'axis'. + +#### Version + +This version of the operator has been available since version 11 of the default ONNX operator set. + +#### Attributes + +
+
axis : int (default is 0)
+
Which axis to split on. A negative value means counting dimensions from the back. Accepted range is [-rank, rank-1].
+
keepdims : int (default is 1)
+
Keep the split dimension or not. Default 1, which means we keep split dimension. If input 'split' is specified, this attribute is ignored.
+
+ +#### Inputs (1 - 2) + +
+
input : T
+
The tensor to split
+
split (optional) : I
+
Length of each output. It can be either a scalar(tensor of empty shape), or a 1-D tensor. All values must be >= 0.
+
+ +#### Outputs + +
+
output_sequence : S
+
One or more outputs forming a sequence of tensors after splitting
+
+ +#### Type Constraints + +
+
T : tensor(uint8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(int8), tensor(int16), tensor(int32), tensor(int64), tensor(float16), tensor(float), tensor(double), tensor(string), tensor(bool), tensor(complex64), tensor(complex128)
+
Constrain input types to all tensor types.
+
I : tensor(int32), tensor(int64)
+
Constrain split size to integral tensor.
+
S : seq(tensor(uint8)), seq(tensor(uint16)), seq(tensor(uint32)), seq(tensor(uint64)), seq(tensor(int8)), seq(tensor(int16)), seq(tensor(int32)), seq(tensor(int64)), seq(tensor(float16)), seq(tensor(float)), seq(tensor(double)), seq(tensor(string)), seq(tensor(bool)), seq(tensor(complex64)), seq(tensor(complex128))
+
Constrain output types to all tensor types.
+
+ + +### **Sqrt** + + Square root takes one input data (Tensor) and produces one output data + (Tensor) where the square root is, y = x^0.5, is applied to + the tensor elementwise. If x is negative, then it will return NaN. + +#### Version + +This version of the operator has been available since version 13 of the default ONNX operator set. + +Other versions of this operator: 1, 6 + +#### Inputs + +
+
X (differentiable) : T
+
Input tensor
+
+ +#### Outputs + +
+
Y (differentiable) : T
+
Output tensor
+
+ +#### Type Constraints + +
+
T : tensor(float16), tensor(float), tensor(double), tensor(bfloat16)
+
Constrain input and output types to float tensors.
+
+ + +#### Examples + +
+sqrt + +```python +node = onnx.helper.make_node( + 'Sqrt', + inputs=['x'], + outputs=['y'], +) + +x = np.array([1, 4, 9]).astype(np.float32) +y = np.sqrt(x) # expected output [1., 2., 3.] +expect(node, inputs=[x], outputs=[y], + name='test_sqrt_example') + +x = np.abs(np.random.randn(3, 4, 5).astype(np.float32)) +y = np.sqrt(x) +expect(node, inputs=[x], outputs=[y], + name='test_sqrt') +``` + +
+ + +### **Squeeze** + + Remove single-dimensional entries from the shape of a tensor. + Takes an input `axes` with a list of axes to squeeze. + If `axes` is not provided, all the single dimensions will be removed from + the shape. If an axis is selected with shape entry not equal to one, an error is raised. + +#### Version + +This version of the operator has been available since version 13 of the default ONNX operator set. + +Other versions of this operator: 1, 11 + +#### Inputs (1 - 2) + +
+
data (differentiable) : T
+
Tensors with at least max(dims) dimensions.
+
axes (optional, non-differentiable) : tensor(int64)
+
List of integers indicating the dimensions to squeeze. Negative value means counting dimensions from the back. Accepted range is [-r, r-1] where r = rank(data).
+
+ +#### Outputs + +
+
squeezed (differentiable) : T
+
Reshaped tensor with same data as input.
+
+ +#### Type Constraints + +
+
T : tensor(uint8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(int8), tensor(int16), tensor(int32), tensor(int64), tensor(bfloat16), tensor(float16), tensor(float), tensor(double), tensor(string), tensor(bool), tensor(complex64), tensor(complex128)
+
Constrain input and output types to all tensor types.
+
+ + +#### Examples + +
+squeeze + +```python +node = onnx.helper.make_node( + 'Squeeze', + inputs=['x', 'axes'], + outputs=['y'], +) +x = np.random.randn(1, 3, 4, 5).astype(np.float32) +axes = np.array([0], dtype=np.int64) +y = np.squeeze(x, axis=0) + +expect(node, inputs=[x, axes], outputs=[y], + name='test_squeeze') +``` + +
+ + +
+squeeze_negative_axes + +```python +node = onnx.helper.make_node( + 'Squeeze', + inputs=['x', 'axes'], + outputs=['y'], +) +x = np.random.randn(1, 3, 1, 5).astype(np.float32) +axes = np.array([-2], dtype=np.int64) +y = np.squeeze(x, axis=-2) +expect(node, inputs=[x, axes], outputs=[y], + name='test_squeeze_negative_axes') +``` + +
+ + +### **StringNormalizer** + + StringNormalization performs string operations for basic cleaning. + This operator has only one input (denoted by X) and only one output + (denoted by Y). This operator first examines the elements in the X, + and removes elements specified in "stopwords" attribute. + After removing stop words, the intermediate result can be further lowercased, + uppercased, or just returned depending the "case_change_action" attribute. + This operator only accepts [C]- and [1, C]-tensor. + If all elements in X are dropped, the output will be the empty value of string tensor with shape [1] + if input shape is [C] and shape [1, 1] if input shape is [1, C]. + +#### Version + +This version of the operator has been available since version 10 of the default ONNX operator set. + +#### Attributes + +
+
case_change_action : string (default is NONE)
+
string enum that cases output to be lowercased/uppercases/unchanged. Valid values are "LOWER", "UPPER", "NONE". Default is "NONE"
+
is_case_sensitive : int (default is 0)
+
Boolean. Whether the identification of stop words in X is case-sensitive. Default is false
+
locale : string
+
Environment dependent string that denotes the locale according to which output strings needs to be upper/lowercased.Default en_US or platform specific equivalent as decided by the implementation.
+
stopwords : list of strings
+
List of stop words. If not set, no word would be removed from X.
+
+ +#### Inputs + +
+
X : tensor(string)
+
UTF-8 strings to normalize
+
+ +#### Outputs + +
+
Y : tensor(string)
+
UTF-8 Normalized strings
+
+ +#### Type Constraints + + + +#### Examples + +
+monday_casesensintive_lower + +```python +input = np.array([u'monday', u'tuesday', u'wednesday', u'thursday']).astype(object) +output = np.array([u'tuesday', u'wednesday', u'thursday']).astype(object) +stopwords = [u'monday'] + +node = onnx.helper.make_node( + 'StringNormalizer', + inputs=['x'], + outputs=['y'], + case_change_action='LOWER', + is_case_sensitive=1, + stopwords=stopwords +) +expect(node, inputs=[input], outputs=[output], name='test_strnormalizer_export_monday_casesensintive_lower') +``` + +
+ + +
+monday_casesensintive_nochangecase + +```python +input = np.array([u'monday', u'tuesday', u'wednesday', u'thursday']).astype(object) +output = np.array([u'tuesday', u'wednesday', u'thursday']).astype(object) +stopwords = [u'monday'] + +node = onnx.helper.make_node( + 'StringNormalizer', + inputs=['x'], + outputs=['y'], + is_case_sensitive=1, + stopwords=stopwords +) +expect(node, inputs=[input], outputs=[output], name='test_strnormalizer_export_monday_casesensintive_nochangecase') +``` + +
+ + +
+monday_casesensintive_upper + +```python +input = np.array([u'monday', u'tuesday', u'wednesday', u'thursday']).astype(object) +output = np.array([u'TUESDAY', u'WEDNESDAY', u'THURSDAY']).astype(object) +stopwords = [u'monday'] + +node = onnx.helper.make_node( + 'StringNormalizer', + inputs=['x'], + outputs=['y'], + case_change_action='UPPER', + is_case_sensitive=1, + stopwords=stopwords +) +expect(node, inputs=[input], outputs=[output], name='test_strnormalizer_export_monday_casesensintive_upper') +``` + +
+ + +
+monday_empty_output + +```python +input = np.array([u'monday', u'monday']).astype(object) +output = np.array([u'']).astype(object) +stopwords = [u'monday'] + +node = onnx.helper.make_node( + 'StringNormalizer', + inputs=['x'], + outputs=['y'], + case_change_action='UPPER', + is_case_sensitive=1, + stopwords=stopwords +) +expect(node, inputs=[input], outputs=[output], name='test_strnormalizer_export_monday_empty_output') +``` + +
+ + +
+monday_insensintive_upper_twodim + +```python +input = np.array([u'Monday', u'tuesday', u'wednesday', u'Monday', u'tuesday', u'wednesday']).astype(object).reshape([1, 6]) + +# It does upper case cecedille, accented E +# and german umlaut but fails +# with german eszett +output = np.array([u'TUESDAY', u'WEDNESDAY', u'TUESDAY', u'WEDNESDAY']).astype(object).reshape([1, 4]) +stopwords = [u'monday'] + +node = onnx.helper.make_node( + 'StringNormalizer', + inputs=['x'], + outputs=['y'], + case_change_action='UPPER', + stopwords=stopwords +) +expect(node, inputs=[input], outputs=[output], name='test_strnormalizer_export_monday_insensintive_upper_twodim') +``` + +
+ + +
+nostopwords_nochangecase + +```python +input = np.array([u'monday', u'tuesday']).astype(object) +output = input + +# No stopwords. This is a NOOP +node = onnx.helper.make_node( + 'StringNormalizer', + inputs=['x'], + outputs=['y'], + is_case_sensitive=1, +) +expect(node, inputs=[input], outputs=[output], name='test_strnormalizer_nostopwords_nochangecase') +``` + +
+ + +### **Sub** + + Performs element-wise binary subtraction (with Numpy-style broadcasting support). + + This operator supports **multidirectional (i.e., Numpy-style) broadcasting**; for more details please check [the doc](Broadcasting.md). + + (Opset 14 change): Extend supported types to include uint8, int8, uint16, and int16. + +#### Version + +This version of the operator has been available since version 14 of the default ONNX operator set. + +Other versions of this operator: 1, 6, 7, 13 + +#### Inputs + +
+
A (differentiable) : T
+
First operand.
+
B (differentiable) : T
+
Second operand.
+
+ +#### Outputs + +
+
C (differentiable) : T
+
Result, has same element type as two inputs
+
+ +#### Type Constraints + +
+
T : tensor(uint8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(int8), tensor(int16), tensor(int32), tensor(int64), tensor(float16), tensor(float), tensor(double), tensor(bfloat16)
+
Constrain input and output types to all numeric tensors.
+
+ + +#### Examples + +
+sub + +```python +node = onnx.helper.make_node( + 'Sub', + inputs=['x', 'y'], + outputs=['z'], +) + +x = np.array([1, 2, 3]).astype(np.float32) +y = np.array([3, 2, 1]).astype(np.float32) +z = x - y # expected output [-2., 0., 2.] +expect(node, inputs=[x, y], outputs=[z], + name='test_sub_example') + +x = np.random.randn(3, 4, 5).astype(np.float32) +y = np.random.randn(3, 4, 5).astype(np.float32) +z = x - y +expect(node, inputs=[x, y], outputs=[z], + name='test_sub') + +x = np.random.randint(12, 24, size=(3, 4, 5), dtype=np.uint8) +y = np.random.randint(12, size=(3, 4, 5), dtype=np.uint8) +z = x - y +expect(node, inputs=[x, y], outputs=[z], + name='test_sub_uint8') +``` + +
+ + +
+sub_broadcast + +```python +node = onnx.helper.make_node( + 'Sub', + inputs=['x', 'y'], + outputs=['z'], +) + +x = np.random.randn(3, 4, 5).astype(np.float32) +y = np.random.randn(5).astype(np.float32) +z = x - y +expect(node, inputs=[x, y], outputs=[z], + name='test_sub_bcast') +``` + +
+ + +### **Sum** + + Element-wise sum of each of the input tensors (with Numpy-style broadcasting support). + All inputs and outputs must have the same data type. + This operator supports **multidirectional (i.e., Numpy-style) broadcasting**; for more details please check [the doc](Broadcasting.md). + +#### Version + +This version of the operator has been available since version 13 of the default ONNX operator set. + +Other versions of this operator: 1, 6, 8 + +#### Inputs (1 - ∞) + +
+
data_0 (variadic, differentiable) : T
+
List of tensors for sum.
+
+ +#### Outputs + +
+
sum (differentiable) : T
+
Output tensor.
+
+ +#### Type Constraints + +
+
T : tensor(float16), tensor(float), tensor(double), tensor(bfloat16)
+
Constrain input and output types to float tensors.
+
+ + +#### Examples + +
+sum + +```python +data_0 = np.array([3, 0, 2]).astype(np.float32) +data_1 = np.array([1, 3, 4]).astype(np.float32) +data_2 = np.array([2, 6, 6]).astype(np.float32) +result = np.array([6, 9, 12]).astype(np.float32) +node = onnx.helper.make_node( + 'Sum', + inputs=['data_0', 'data_1', 'data_2'], + outputs=['result'], +) +expect(node, inputs=[data_0, data_1, data_2], outputs=[result], + name='test_sum_example') + +node = onnx.helper.make_node( + 'Sum', + inputs=['data_0'], + outputs=['result'], +) +expect(node, inputs=[data_0], outputs=[data_0], + name='test_sum_one_input') + +result = np.add(data_0, data_1) +node = onnx.helper.make_node( + 'Sum', + inputs=['data_0', 'data_1'], + outputs=['result'], +) +expect(node, inputs=[data_0, data_1], outputs=[result], + name='test_sum_two_inputs') +``` + +
+ + +### **Tan** + + Calculates the tangent of the given input tensor, element-wise. + +#### Version + +This version of the operator has been available since version 7 of the default ONNX operator set. + +#### Inputs + +
+
input (differentiable) : T
+
Input tensor
+
+ +#### Outputs + +
+
output (differentiable) : T
+
The tangent of the input tensor computed element-wise
+
+ +#### Type Constraints + +
+
T : tensor(float16), tensor(float), tensor(double)
+
Constrain input and output types to float tensors.
+
+ + +#### Examples + +
+tan + +```python +node = onnx.helper.make_node( + 'Tan', + inputs=['x'], + outputs=['y'], +) + +x = np.array([-1, 0, 1]).astype(np.float32) +y = np.tan(x) +expect(node, inputs=[x], outputs=[y], + name='test_tan_example') + +x = np.random.randn(3, 4, 5).astype(np.float32) +y = np.tan(x) +expect(node, inputs=[x], outputs=[y], + name='test_tan') +``` + +
+ + +### **Tanh** + + Calculates the hyperbolic tangent of the given input tensor element-wise. + +#### Version + +This version of the operator has been available since version 13 of the default ONNX operator set. + +Other versions of this operator: 1, 6 + +#### Inputs + +
+
input (differentiable) : T
+
Input tensor
+
+ +#### Outputs + +
+
output (differentiable) : T
+
The hyperbolic tangent values of the input tensor computed element-wise
+
+ +#### Type Constraints + +
+
T : tensor(float16), tensor(float), tensor(double), tensor(bfloat16)
+
Constrain input and output types to float tensors.
+
+ + +#### Examples + +
+tanh + +```python +node = onnx.helper.make_node( + 'Tanh', + inputs=['x'], + outputs=['y'], +) + +x = np.array([-1, 0, 1]).astype(np.float32) +y = np.tanh(x) # expected output [-0.76159418, 0., 0.76159418] +expect(node, inputs=[x], outputs=[y], + name='test_tanh_example') + +x = np.random.randn(3, 4, 5).astype(np.float32) +y = np.tanh(x) +expect(node, inputs=[x], outputs=[y], + name='test_tanh') +``` + +
+ + +### **TfIdfVectorizer** + + This transform extracts n-grams from the input sequence and save them as a vector. Input can + be either a 1-D or 2-D tensor. For 1-D input, output is the n-gram representation of that input. + For 2-D input, the output is also a 2-D tensor whose i-th row is the n-gram representation of the i-th input row. + More specifically, if input shape is [C], the corresponding output shape would be [max(ngram_indexes) + 1]. + If input shape is [N, C], this operator produces a [N, max(ngram_indexes) + 1]-tensor. + + In contrast to standard n-gram extraction, here, the indexes of extracting an n-gram from the original + sequence are not necessarily consecutive numbers. The discontinuity between indexes are controlled by the number of skips. + If the number of skips is 2, we should skip two tokens when scanning through the original sequence. + Let's consider an example. Assume that input sequence is [94, 17, 36, 12, 28] and the number of skips is 2. + The associated 2-grams are [94, 12] and [17, 28] respectively indexed by [0, 3] and [1, 4]. + If the number of skips becomes 0, the 2-grams generated are [94, 17], [17, 36], [36, 12], [12, 28] + indexed by [0, 1], [1, 2], [2, 3], [3, 4], respectively. + + The output vector (denoted by Y) stores the count of each n-gram; + Y[ngram_indexes[i]] indicates the times that the i-th n-gram is found. The attribute ngram_indexes is used to determine the mapping + between index i and the corresponding n-gram's output coordinate. If pool_int64s is [94, 17, 17, 36], ngram_indexes is [1, 0], + ngram_counts=[0, 0], then the Y[0] (first element in Y) and Y[1] (second element in Y) are the counts of [17, 36] and [94, 17], + respectively. An n-gram which cannot be found in pool_strings/pool_int64s should be ignored and has no effect on the output. + Note that we may consider all skips up to S when generating the n-grams. + + The examples used above are true if mode is "TF". If mode is "IDF", all the counts larger than 1 would be truncated to 1 and + the i-th element in weights would be used to scale (by multiplication) the count of the i-th n-gram in pool. If mode is "TFIDF", + this operator first computes the counts of all n-grams and then scale them by the associated values in the weights attribute. + + Only one of pool_strings and pool_int64s can be set. If pool_int64s is set, the input should be an integer tensor. + If pool_strings is set, the input must be a string tensor. + +#### Version + +This version of the operator has been available since version 9 of the default ONNX operator set. + +#### Attributes + +
+
max_gram_length : int (required)
+
Maximum n-gram length. If this value is 3, 3-grams will be used to generate the output.
+
max_skip_count : int (required)
+
Maximum number of items (integers/strings) to be skipped when constructing an n-gram from X. If max_skip_count=1, min_gram_length=2, max_gram_length=3, this operator may generate 2-grams with skip_count=0 and skip_count=1, and 3-grams with skip_count=0 and skip_count=1
+
min_gram_length : int (required)
+
Minimum n-gram length. If this value is 2 and max_gram_length is 3, output may contain counts of 2-grams and 3-grams.
+
mode : string (required)
+
The weighting criteria. It can be one of "TF" (term frequency), "IDF" (inverse document frequency), and "TFIDF" (the combination of TF and IDF)
+
ngram_counts : list of ints (required)
+
The starting indexes of 1-grams, 2-grams, and so on in pool. It is useful when determining the boundary between two consecutive collections of n-grams. For example, if ngram_counts is [0, 17, 36], the first index (zero-based) of 1-gram/2-gram/3-gram in pool are 0/17/36. This format is essentially identical to CSR (or CSC) sparse matrix format, and we choose to use this due to its popularity.
+
ngram_indexes : list of ints (required)
+
list of int64s (type: AttributeProto::INTS). This list is parallel to the specified 'pool_*' attribute. The i-th element in ngram_indexes indicate the coordinate of the i-th n-gram in the output tensor.
+
pool_int64s : list of ints
+
List of int64 n-grams learned from the training set. Either this or pool_strings attributes must be present but not both. It's an 1-D tensor starting with the collections of all 1-grams and ending with the collections of n-grams. The i-th element in pool stores the n-gram that should be mapped to coordinate ngram_indexes[i] in the output vector.
+
pool_strings : list of strings
+
List of strings n-grams learned from the training set. Either this or pool_int64s attributes must be present but not both. It's an 1-D tensor starting with the collections of all 1-grams and ending with the collections of n-grams. The i-th element in pool stores the n-gram that should be mapped to coordinate ngram_indexes[i] in the output vector.
+
weights : list of floats
+
list of floats. This attribute stores the weight of each n-gram in pool. The i-th element in weights is the weight of the i-th n-gram in pool. Its length equals to the size of ngram_indexes. By default, weights is an all-one tensor.This attribute is used when mode is "IDF" or "TFIDF" to scale the associated word counts.
+
+ +#### Inputs + +
+
X (non-differentiable) : T
+
Input for n-gram extraction
+
+ +#### Outputs + +
+
Y (non-differentiable) : T1
+
Ngram results
+
+ +#### Type Constraints + +
+
T : tensor(string), tensor(int32), tensor(int64)
+
Input is ether string UTF-8 or int32/int64
+
T1 : tensor(float)
+
1-D tensor of floats
+
+ + +#### Examples + +
+tf_batch_onlybigrams_skip0 + +```python +input = np.array([[1, 1, 3, 3, 3, 7], [8, 6, 7, 5, 6, 8]]).astype(np.int32) +output = np.array([[0., 0., 0., 0., 0., 0., 0.], [0., 0., 0., 0., 1., 0., 1.]]).astype(np.float32) + +ngram_counts = np.array([0, 4]).astype(np.int64) +ngram_indexes = np.array([0, 1, 2, 3, 4, 5, 6]).astype(np.int64) +pool_int64s = np.array([2, 3, 5, 4, # unigrams + 5, 6, 7, 8, 6, 7]).astype(np.int64) # bigrams + +helper = TfIdfVectorizerHelper( + mode='TF', + min_gram_length=2, + max_gram_length=2, + max_skip_count=0, + ngram_counts=ngram_counts, + ngram_indexes=ngram_indexes, + pool_int64s=pool_int64s +) +node = helper.make_node_noweights() +expect(node, inputs=[input], outputs=[output], name='test_tfidfvectorizer_tf_batch_onlybigrams_skip0') +``` + +
+ + +
+tf_batch_onlybigrams_skip5 + +```python +input = np.array([[1, 1, 3, 3, 3, 7], [8, 6, 7, 5, 6, 8]]).astype(np.int32) +output = np.array([[0., 0., 0., 0., 0., 0., 0.], [0., 0., 0., 0., 1., 1., 1.]]).astype(np.float32) + +ngram_counts = np.array([0, 4]).astype(np.int64) +ngram_indexes = np.array([0, 1, 2, 3, 4, 5, 6]).astype(np.int64) +pool_int64s = np.array([2, 3, 5, 4, # unigrams + 5, 6, 7, 8, 6, 7]).astype(np.int64) # bigrams + +helper = TfIdfVectorizerHelper( + mode='TF', + min_gram_length=2, + max_gram_length=2, + max_skip_count=5, + ngram_counts=ngram_counts, + ngram_indexes=ngram_indexes, + pool_int64s=pool_int64s +) +node = helper.make_node_noweights() +expect(node, inputs=[input], outputs=[output], name='test_tfidfvectorizer_tf_batch_onlybigrams_skip5') +``` + +
+ + +
+tf_batch_uniandbigrams_skip5 + +```python +input = np.array([[1, 1, 3, 3, 3, 7], [8, 6, 7, 5, 6, 8]]).astype(np.int32) +output = np.array([[0., 3., 0., 0., 0., 0., 0.], [0., 0., 1., 0., 1., 1., 1.]]).astype(np.float32) + +ngram_counts = np.array([0, 4]).astype(np.int64) +ngram_indexes = np.array([0, 1, 2, 3, 4, 5, 6]).astype(np.int64) +pool_int64s = np.array([2, 3, 5, 4, # unigrams + 5, 6, 7, 8, 6, 7]).astype(np.int64) # bigrams + +helper = TfIdfVectorizerHelper( + mode='TF', + min_gram_length=1, + max_gram_length=2, + max_skip_count=5, + ngram_counts=ngram_counts, + ngram_indexes=ngram_indexes, + pool_int64s=pool_int64s +) +node = helper.make_node_noweights() +expect(node, inputs=[input], outputs=[output], name='test_tfidfvectorizer_tf_batch_uniandbigrams_skip5') +``` + +
+ + +
+tf_only_bigrams_skip0 + +```python +input = np.array([1, 1, 3, 3, 3, 7, 8, 6, 7, 5, 6, 8]).astype(np.int32) +output = np.array([0., 0., 0., 0., 1., 1., 1.]).astype(np.float32) + +ngram_counts = np.array([0, 4]).astype(np.int64) +ngram_indexes = np.array([0, 1, 2, 3, 4, 5, 6]).astype(np.int64) +pool_int64s = np.array([2, 3, 5, 4, # unigrams + 5, 6, 7, 8, 6, 7]).astype(np.int64) # bigrams + +helper = TfIdfVectorizerHelper( + mode='TF', + min_gram_length=2, + max_gram_length=2, + max_skip_count=0, + ngram_counts=ngram_counts, + ngram_indexes=ngram_indexes, + pool_int64s=pool_int64s +) +node = helper.make_node_noweights() +expect(node, inputs=[input], outputs=[output], name='test_tfidfvectorizer_tf_only_bigrams_skip0') +``` + +
+ + +
+tf_onlybigrams_levelempty + +```python +input = np.array([1, 1, 3, 3, 3, 7, 8, 6, 7, 5, 6, 8]).astype(np.int32) +output = np.array([1., 1., 1.]).astype(np.float32) + +ngram_counts = np.array([0, 0]).astype(np.int64) +ngram_indexes = np.array([0, 1, 2]).astype(np.int64) +pool_int64s = np.array([ # unigrams none + 5, 6, 7, 8, 6, 7]).astype(np.int64) # bigrams + +helper = TfIdfVectorizerHelper( + mode='TF', + min_gram_length=2, + max_gram_length=2, + max_skip_count=0, + ngram_counts=ngram_counts, + ngram_indexes=ngram_indexes, + pool_int64s=pool_int64s +) +node = helper.make_node_noweights() +expect(node, inputs=[input], outputs=[output], name='test_tfidfvectorizer_tf_onlybigrams_levelempty') +``` + +
+ + +
+tf_onlybigrams_skip5 + +```python +input = np.array([1, 1, 3, 3, 3, 7, 8, 6, 7, 5, 6, 8]).astype(np.int32) +output = np.array([0., 0., 0., 0., 1., 3., 1.]).astype(np.float32) + +ngram_counts = np.array([0, 4]).astype(np.int64) +ngram_indexes = np.array([0, 1, 2, 3, 4, 5, 6]).astype(np.int64) +pool_int64s = np.array([2, 3, 5, 4, # unigrams + 5, 6, 7, 8, 6, 7]).astype(np.int64) # bigrams + +helper = TfIdfVectorizerHelper( + mode='TF', + min_gram_length=2, + max_gram_length=2, + max_skip_count=5, + ngram_counts=ngram_counts, + ngram_indexes=ngram_indexes, + pool_int64s=pool_int64s +) +node = helper.make_node_noweights() +expect(node, inputs=[input], outputs=[output], name='test_tfidfvectorizer_tf_onlybigrams_skip5') +``` + +
+ + +
+tf_uniandbigrams_skip5 + +```python +input = np.array([1, 1, 3, 3, 3, 7, 8, 6, 7, 5, 6, 8]).astype(np.int32) +output = np.array([0., 3., 1., 0., 1., 3., 1.]).astype(np.float32) + +ngram_counts = np.array([0, 4]).astype(np.int64) +ngram_indexes = np.array([0, 1, 2, 3, 4, 5, 6]).astype(np.int64) +pool_int64s = np.array([2, 3, 5, 4, # unigrams + 5, 6, 7, 8, 6, 7]).astype(np.int64) # bigrams + +helper = TfIdfVectorizerHelper( + mode='TF', + min_gram_length=1, + max_gram_length=2, + max_skip_count=5, + ngram_counts=ngram_counts, + ngram_indexes=ngram_indexes, + pool_int64s=pool_int64s +) +node = helper.make_node_noweights() +expect(node, inputs=[input], outputs=[output], name='test_tfidfvectorizer_tf_uniandbigrams_skip5') +``` + +
+ + +### **ThresholdedRelu** + + ThresholdedRelu takes one input data (Tensor) and produces one output data + (Tensor) where the rectified linear function, y = x for x > alpha, y = 0 otherwise, + is applied to the tensor elementwise. + +#### Version + +This version of the operator has been available since version 10 of the default ONNX operator set. + +#### Attributes + +
+
alpha : float (default is 1.0)
+
Threshold value
+
+ +#### Inputs + +
+
X (differentiable) : T
+
Input tensor
+
+ +#### Outputs + +
+
Y (differentiable) : T
+
Output tensor
+
+ +#### Type Constraints + +
+
T : tensor(float16), tensor(float), tensor(double)
+
Constrain input and output types to float tensors.
+
+ + +#### Examples + +
+default + +```python +default_alpha = 1.0 +node = onnx.helper.make_node( + 'ThresholdedRelu', + inputs=['x'], + outputs=['y'] +) +x = np.random.randn(3, 4, 5).astype(np.float32) +y = np.clip(x, default_alpha, np.inf) +y[y == default_alpha] = 0 + +expect(node, inputs=[x], outputs=[y], + name='test_thresholdedrelu_default') +``` + +
+ + +
+thresholdedrelu + +```python +alpha = 2.0 +node = onnx.helper.make_node( + 'ThresholdedRelu', + inputs=['x'], + outputs=['y'], + alpha=alpha +) + +x = np.array([-1.5, 0., 1.2, 2.0, 2.2]).astype(np.float32) +y = np.clip(x, alpha, np.inf) # expected output [0., 0., 0., 0., 2.2] +y[y == alpha] = 0 + +expect(node, inputs=[x], outputs=[y], + name='test_thresholdedrelu_example') + +x = np.random.randn(3, 4, 5).astype(np.float32) +y = np.clip(x, alpha, np.inf) +y[y == alpha] = 0 + +expect(node, inputs=[x], outputs=[y], + name='test_thresholdedrelu') +``` + +
+ + +### **Tile** + + Constructs a tensor by tiling a given tensor. + This is the same as function `tile` in Numpy, but no broadcast. + For example A = [[1, 2], [3, 4]], B = [1, 2], tile(A, B) = [[1, 2, 1, 2], [3, 4, 3, 4]] + +#### Version + +This version of the operator has been available since version 13 of the default ONNX operator set. + +Other versions of this operator: 1, 6 + +#### Inputs + +
+
input (differentiable) : T
+
Input tensor of any shape.
+
repeats (non-differentiable) : T1
+
1D int64 tensor of the same length as input's dimension number, includes numbers of repeated copies along input's dimensions.
+
+ +#### Outputs + +
+
output (differentiable) : T
+
Output tensor of the same dimension and type as tensor input. output_dim[i] = input_dim[i] * repeats[i]
+
+ +#### Type Constraints + +
+
T : tensor(uint8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(int8), tensor(int16), tensor(int32), tensor(int64), tensor(bfloat16), tensor(float16), tensor(float), tensor(double), tensor(string), tensor(bool), tensor(complex64), tensor(complex128)
+
Constrain input and output types to all tensor types.
+
T1 : tensor(int64)
+
Constrain repeat's type to int64 tensors.
+
+ + +#### Examples + +
+tile + +```python +node = onnx.helper.make_node( + 'Tile', + inputs=['x', 'y'], + outputs=['z'] +) + +x = np.random.rand(2, 3, 4, 5).astype(np.float32) + +repeats = np.random.randint(low=1, high=10, size=(np.ndim(x),)).astype(np.int64) + +z = np.tile(x, repeats) + +expect(node, + inputs=[x, repeats], + outputs=[z], + name='test_tile') +``` + +
+ + +
+tile_precomputed + +```python +node = onnx.helper.make_node( + 'Tile', + inputs=['x', 'y'], + outputs=['z'] +) + +x = np.array([ + [0, 1], + [2, 3] +], dtype=np.float32) + +repeats = np.array([2, 2], dtype=np.int64) + +z = np.array([ + [0, 1, 0, 1], + [2, 3, 2, 3], + [0, 1, 0, 1], + [2, 3, 2, 3] +], dtype=np.float32) + +expect(node, + inputs=[x, repeats], + outputs=[z], + name='test_tile_precomputed') +``` + +
+ + +### **TopK** + + Retrieve the top-K largest or smallest elements along a specified axis. Given an input tensor of + shape [a_1, a_2, ..., a_n, r] and integer argument k, return two outputs: + -Value tensor of shape [a_1, a_2, ..., a_{axis-1}, k, a_{axis+1}, ... a_n] + which contains the values of the top k elements along the specified axis + -Index tensor of shape [a_1, a_2, ..., a_{axis-1}, k, a_{axis+1}, ... a_n] which + contains the indices of the top k elements (original indices from the input + tensor). + + If "largest" is 1 (the default value) then the k largest elements are returned. + If "sorted" is 1 (the default value) then the resulting k elements will be sorted. + If "sorted" is 0, order of returned 'Values' and 'Indices' are undefined. + + Given two equivalent values, this operator uses the indices along the axis as + a tiebreaker. That is, the element with the lower index will appear first. + +#### Version + +This version of the operator has been available since version 11 of the default ONNX operator set. + +Other versions of this operator: 1, 10 + +#### Attributes + +
+
axis : int (default is -1)
+
Dimension on which to do the sort. Negative value means counting dimensions from the back. Accepted range is [-r, r-1] where r = rank(input).
+
largest : int (default is 1)
+
Whether to return the top-K largest or smallest elements.
+
sorted : int (default is 1)
+
Whether to return the elements in sorted order.
+
+ +#### Inputs + +
+
X (differentiable) : T
+
Tensor of shape [a_1, a_2, ..., a_n, r]
+
K (non-differentiable) : tensor(int64)
+
A 1-D tensor containing a single positive value corresponding to the number of top elements to retrieve
+
+ +#### Outputs + +
+
Values (differentiable) : T
+
Tensor of shape [a_1, a_2, ..., a_{axis-1}, k, a_{axis+1}, ... a_n] containing top K values from the input tensor
+
Indices (non-differentiable) : I
+
Tensor of shape [a_1, a_2, ..., a_{axis-1}, k, a_{axis+1}, ... a_n] containing the corresponding input tensor indices for the top K values.
+
+ +#### Type Constraints + +
+
T : tensor(uint8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(int8), tensor(int16), tensor(int32), tensor(int64), tensor(float16), tensor(float), tensor(double)
+
Constrain input and output types to numeric tensors.
+
I : tensor(int64)
+
Constrain index tensor to int64
+
+ + +#### Examples + +
+top_k + +```python +axis = 1 +largest = 1 + +k = 3 +node = onnx.helper.make_node( + 'TopK', + inputs=['x', 'k'], + outputs=['values', 'indices'], + axis=axis +) +X = np.array([ + [0, 1, 2, 3], + [4, 5, 6, 7], + [8, 9, 10, 11], +], dtype=np.float32) +K = np.array([k], dtype=np.int64) +values_ref, indices_ref = topk_sorted_implementation(X, k, axis, largest) + +#print(values_ref) +#[[ 3. 2. 1.] +# [ 7. 6. 5.] +# [11. 10. 9.]] +#print(indices_ref) +#[[3 2 1] +# [3 2 1] +# [3 2 1]] + +expect(node, inputs=[X, K], outputs=[values_ref, indices_ref], + name='test_top_k') +``` + +
+ + +
+top_k_negative_axis + +```python +axis = -1 +largest = 1 + +k = 3 +node = onnx.helper.make_node( + 'TopK', + inputs=['x', 'k'], + outputs=['values', 'indices'], + axis=axis +) +X = np.array([ + [0, 1, 2, 3], + [4, 5, 6, 7], + [8, 9, 10, 11], +], dtype=np.float32) +K = np.array([k], dtype=np.int64) +values_ref, indices_ref = topk_sorted_implementation(X, k, axis, largest) + +# print(values_ref) +#[[ 3. 2. 1.] +# [ 7. 6. 5.] +# [11. 10. 9.]] +# print(indices_ref) +#[[3 2 1] +# [3 2 1] +# [3 2 1]] + +expect(node, inputs=[X, K], outputs=[values_ref, indices_ref], + name='test_top_k_negative_axis') +``` + +
+ + +
+top_k_smallest + +```python +axis = 1 +largest = 0 +sorted = 1 +k = 3 + +node = onnx.helper.make_node( + 'TopK', + inputs=['x', 'k'], + outputs=['values', 'indices'], + axis=axis, + largest=largest, + sorted=sorted +) + +X = np.array([ + [0, 1, 2, 3], + [4, 5, 6, 7], + [11, 10, 9, 8], +], dtype=np.float32) +K = np.array([k], dtype=np.int64) +values_ref, indices_ref = topk_sorted_implementation(X, k, axis, largest) + +#print(values_ref) +#[[ 0. 1. 2.] +# [ 4. 5. 6.] +# [ 8. 9. 10.]] +#print(indices_ref) +#[[0 1 2] +# [0 1 2] +# [3 2 1]] + +expect(node, inputs=[X, K], outputs=[values_ref, indices_ref], + name='test_top_k_smallest') +``` + +
+ + +### **Transpose** + + Transpose the input tensor similar to numpy.transpose. For example, when + perm=(1, 0, 2), given an input tensor of shape (1, 2, 3), the output shape + will be (2, 1, 3). + +#### Version + +This version of the operator has been available since version 13 of the default ONNX operator set. + +Other versions of this operator: 1 + +#### Attributes + +
+
perm : list of ints
+
A list of integers. By default, reverse the dimensions, otherwise permute the axes according to the values given.
+
+ +#### Inputs + +
+
data (differentiable) : T
+
An input tensor.
+
+ +#### Outputs + +
+
transposed (differentiable) : T
+
Transposed output.
+
+ +#### Type Constraints + +
+
T : tensor(uint8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(int8), tensor(int16), tensor(int32), tensor(int64), tensor(bfloat16), tensor(float16), tensor(float), tensor(double), tensor(string), tensor(bool), tensor(complex64), tensor(complex128)
+
Constrain input and output types to all tensor types.
+
+ + +#### Examples + +
+all_permutations + +```python +shape = (2, 3, 4) +data = np.random.random_sample(shape).astype(np.float32) +permutations = list(itertools.permutations(np.arange(len(shape)))) + +for i in range(len(permutations)): + node = onnx.helper.make_node( + 'Transpose', + inputs=['data'], + outputs=['transposed'], + perm=permutations[i] + ) + transposed = np.transpose(data, permutations[i]) + expect(node, inputs=[data], outputs=[transposed], + name='test_transpose_all_permutations_' + str(i)) +``` + +
+ + +
+default + +```python +shape = (2, 3, 4) +data = np.random.random_sample(shape).astype(np.float32) + +node = onnx.helper.make_node( + 'Transpose', + inputs=['data'], + outputs=['transposed'] +) + +transposed = np.transpose(data) +expect(node, inputs=[data], outputs=[transposed], + name='test_transpose_default') +``` + +
+ + +### **Trilu** + + Given a 2-D matrix or batches of 2-D matrices, returns the upper or lower triangular part of the tensor(s). + The attribute "upper" determines whether the upper or lower part is retained. If set to true, + the upper triangular matrix is retained. Lower triangular matrix is retained otherwise. + Default value for the "upper" attribute is true. + Trilu takes one input tensor of shape [*, N, M], where * is zero or more batch dimensions. The upper triangular part consists + of the elements on and above the given diagonal (k). The lower triangular part consists of elements on and below the diagonal. + All other elements in the matrix are set to zero. + If k = 0, the triangular part on and above/below the main diagonal is retained. + If upper is set to true, a positive k retains the upper triangular matrix excluding the main diagonal and (k-1) diagonals above it. + A negative k value retains the main diagonal and |k| diagonals below it. + If upper is set to false, a positive k retains the lower triangular matrix including the main diagonal and k diagonals above it. + A negative k value excludes the main diagonal and (|k|-1) diagonals below it. + +#### Version + +This version of the operator has been available since version 14 of the default ONNX operator set. + +#### Attributes + +
+
upper : int (default is 1)
+
Boolean. Indicates whether upper or lower part of matrix is retained. Default is true.
+
+ +#### Inputs (1 - 2) + +
+
input (differentiable) : T
+
Input tensor of rank 2 or higher.
+
k (optional, non-differentiable) : tensor(int64)
+
A 0-D tensor containing a single value corresponding to the number diagonals above or below the main diagonal to exclude or include. Default value is 0 if it's not specified.
+
+ +#### Outputs + +
+
output (differentiable) : T
+
Output tensor of the same type and shape as the input tensor.
+
+ +#### Type Constraints + +
+
T : tensor(uint8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(int8), tensor(int16), tensor(int32), tensor(int64), tensor(bfloat16), tensor(float16), tensor(float), tensor(double), tensor(string), tensor(bool), tensor(complex64), tensor(complex128)
+
Constrain input and output types to all tensor types.
+
+ + +#### Examples + +
+tril + +```python +node = onnx.helper.make_node( + 'Trilu', + inputs=['x'], + outputs=['y'], + upper=0, +) + +x = np.random.randint(10, size=(4, 5)).astype(np.int64) +# X: +# [[4, 7, 3, 7, 9], +# [1, 2, 8, 6, 9], +# [9, 4, 1, 8, 7], +# [4, 3, 4, 2, 4]] +# expect result: +# [[4, 0, 0, 0, 0], +# [1, 2, 0, 0, 0], +# [9, 4, 1, 0, 0], +# [4, 3, 4, 2, 0]] +y = tril_reference_implementation(x) +expect(node, inputs=[x], outputs=[y], name='test_tril') +``` + +
+ + +
+tril_neg + +```python +node = onnx.helper.make_node( + 'Trilu', + inputs=['x', 'k'], + outputs=['y'], + upper=0, +) + +x = np.random.randint(10, size=(4, 5)).astype(np.int64) +k = np.array(-1).astype(np.int64) +# X: +# [[4, 7, 3, 7, 9], +# [1, 2, 8, 6, 9], +# [9, 4, 1, 8, 7], +# [4, 3, 4, 2, 4]] +# expect result: +# [[0, 0, 0, 0, 0], +# [1, 0, 0, 0, 0], +# [9, 4, 0, 0, 0], +# [4, 3, 4, 0, 0]] +y = tril_reference_implementation(x, int(k)) +expect(node, inputs=[x, k], outputs=[y], name='test_tril_neg') +``` + +
+ + +
+tril_one_row + +```python +node = onnx.helper.make_node( + 'Trilu', + inputs=['x'], + outputs=['y'], + upper=0, +) + +x = np.random.randint(10, size=(3, 1, 5)).astype(np.int64) +# X: +# [[[6, 2, 4, 1, 6]], +# +# [[8, 3, 8, 7, 0]], +# +# [[2, 2, 9, 5, 9]]] +# expect result: +# [[[6, 0, 0, 0, 0]], +# +# [[8, 0, 0, 0, 0]], +# +# [[2, 0, 0, 0, 0]]] +y = tril_reference_implementation(x) +expect(node, inputs=[x], outputs=[y], name='test_tril_one_row_neg') +``` + +
+ + +
+tril_out_neg + +```python +node = onnx.helper.make_node( + 'Trilu', + inputs=['x', 'k'], + outputs=['y'], + upper=0, +) + +x = np.random.randint(10, size=(4, 5)).astype(np.int64) +k = np.array(-7).astype(np.int64) +# X: +# [[4, 7, 3, 7, 9], +# [1, 2, 8, 6, 9], +# [9, 4, 1, 8, 7], +# [4, 3, 4, 2, 4]] +# expect result: +# [[0, 0, 0, 0, 0], +# [0, 0, 0, 0, 0], +# [0, 0, 0, 0, 0], +# [0, 0, 0, 0, 0]] +y = tril_reference_implementation(x, int(k)) +expect(node, inputs=[x, k], outputs=[y], name='test_tril_out_neg') +``` + +
+ + +
+tril_out_pos + +```python +node = onnx.helper.make_node( + 'Trilu', + inputs=['x', 'k'], + outputs=['y'], + upper=0, +) +x = np.random.randint(10, size=(4, 5)).astype(np.int64) +k = np.array(6).astype(np.int64) +# X: +# [[4, 7, 3, 7, 9], +# [1, 2, 8, 6, 9], +# [9, 4, 1, 8, 7], +# [4, 3, 4, 2, 4]] +# expect result: +# [[4, 7, 3, 7, 9], +# [1, 2, 8, 6, 9], +# [9, 4, 1, 8, 7], +# [4, 3, 4, 2, 4]] +y = tril_reference_implementation(x, int(k)) +expect(node, inputs=[x, k], outputs=[y], name='test_tril_out_pos') +``` + +
+ + +
+tril_pos + +```python +node = onnx.helper.make_node( + 'Trilu', + inputs=['x', 'k'], + outputs=['y'], + upper=0, +) + +x = np.random.randint(10, size=(4, 5)).astype(np.int64) +k = np.array(2).astype(np.int64) +# X: +# [[4, 7, 3, 7, 9], +# [1, 2, 8, 6, 9], +# [9, 4, 1, 8, 7], +# [4, 3, 4, 2, 4]] +# expect result: +# [[4, 7, 3, 0, 0], +# [1, 2, 8, 6, 0], +# [9, 4, 1, 8, 7], +# [4, 3, 4, 2, 4]] +y = tril_reference_implementation(x, int(k)) +expect(node, inputs=[x, k], outputs=[y], name='test_tril_pos') +``` + +
+ + +
+tril_square + +```python +node = onnx.helper.make_node( + 'Trilu', + inputs=['x'], + outputs=['y'], + upper=0, +) + +x = np.random.randint(10, size=(2, 3, 3)).astype(np.int64) +# X: +# [[[0, 4, 3], +# [2, 0, 9], +# [8, 2, 5]], +# +# [[2, 7, 2], +# [2, 6, 0], +# [2, 6, 5]]] +# expect result: +# [[[0, 0, 0], +# [2, 0, 0], +# [8, 2, 5]], +# +# [[2, 0, 0], +# [2, 6, 0], +# [2, 6, 5]]] +y = tril_reference_implementation(x) +expect(node, inputs=[x], outputs=[y], name='test_tril_square') +``` + +
+ + +
+tril_square_neg + +```python +node = onnx.helper.make_node( + 'Trilu', + inputs=['x', 'k'], + outputs=['y'], + upper=0, +) + +x = np.random.randint(10, size=(2, 3, 3)).astype(np.int64) +k = np.array(-1).astype(np.int64) +# X: +# [[[0, 4, 3], +# [2, 0, 9], +# [8, 2, 5]], +# +# [[2, 7, 2], +# [2, 6, 0], +# [2, 6, 5]]] +# expect result: +# [[[0, 0, 0], +# [2, 0, 0], +# [8, 2, 0]], +# +# [[0, 0, 0], +# [2, 0, 0], +# [2, 6, 0]]] +y = tril_reference_implementation(x, int(k)) +expect(node, inputs=[x, k], outputs=[y], name='test_tril_square_neg') +``` + +
+ + +
+tril_zero + +```python +node = onnx.helper.make_node( + 'Trilu', + inputs=['x', 'k'], + outputs=['y'], + upper=0, +) + +x = np.random.randint(10, size=(3, 0, 5)).astype(np.int64) +k = np.array(6).astype(np.int64) +# X: +# [] +# expect result: +# [] +y = tril_reference_implementation(x, int(k)) +expect(node, inputs=[x, k], outputs=[y], name='test_tril_zero') +``` + +
+ + +
+triu + +```python +node = onnx.helper.make_node( + 'Trilu', + inputs=['x'], + outputs=['y'], +) + +x = np.random.randint(10, size=(4, 5)).astype(np.int64) +# X: +# [[4, 7, 3, 7, 9], +# [1, 2, 8, 6, 9], +# [9, 4, 0, 8, 7], +# [4, 3, 4, 2, 4]] +# expect result: +# [[4, 7, 3, 7, 9], +# [0, 2, 8, 6, 9], +# [0, 0, 0, 8, 7], +# [0, 0, 0, 2, 4]] +y = triu_reference_implementation(x) +expect(node, inputs=[x], outputs=[y], name='test_triu') +``` + +
+ + +
+triu_neg + +```python +node = onnx.helper.make_node( + 'Trilu', + inputs=['x', 'k'], + outputs=['y'], +) + +x = np.random.randint(10, size=(4, 5)).astype(np.int64) +k = np.array(-1).astype(np.int64) +# X: +# [[4, 7, 3, 7, 9], +# [1, 2, 8, 6, 9], +# [9, 4, 0, 8, 7], +# [4, 3, 4, 2, 4]] +# expect result: +# [[4, 7, 3, 7, 9], +# [1, 2, 8, 6, 9], +# [0, 4, 0, 8, 7], +# [0, 0, 4, 2, 4]] +y = triu_reference_implementation(x, int(k)) +expect(node, inputs=[x, k], outputs=[y], name='test_triu_neg') +``` + +
+ + +
+triu_one_row + +```python +node = onnx.helper.make_node( + 'Trilu', + inputs=['x', 'k'], + outputs=['y'], +) + +x = np.random.randint(10, size=(3, 1, 5)).astype(np.int64) +k = np.array(1).astype(np.int64) +# X: +# [[[1, 4, 9, 7, 1]], +# +# [[9, 2, 8, 8, 4]], +# +# [[3, 9, 7, 4, 2]]] +# expect result: +# [[[0, 4, 9, 7, 1]], +# +# [[0, 2, 8, 8, 4]], +# +# [[0, 9, 7, 4, 2]]] +y = triu_reference_implementation(x, int(k)) +expect(node, inputs=[x, k], outputs=[y], name='test_triu_one_row') +``` + +
+ + +
+triu_out_neg_out + +```python +node = onnx.helper.make_node( + 'Trilu', + inputs=['x', 'k'], + outputs=['y'], +) + +x = np.random.randint(10, size=(4, 5)).astype(np.int64) +k = np.array(-7).astype(np.int64) +# X: +# [[4, 7, 3, 7, 9], +# [1, 2, 8, 6, 9], +# [9, 4, 0, 8, 7], +# [4, 3, 4, 2, 4]] +# expect result: +# [[4, 7, 3, 7, 9], +# [1, 2, 8, 6, 9], +# [9, 4, 0, 8, 7], +# [4, 3, 4, 2, 4]] +y = triu_reference_implementation(x, int(k)) +expect(node, inputs=[x, k], outputs=[y], name='test_triu_out_neg_out') +``` + +
+ + +
+triu_out_pos + +```python +node = onnx.helper.make_node( + 'Trilu', + inputs=['x', 'k'], + outputs=['y'], +) + +x = np.random.randint(10, size=(4, 5)).astype(np.int64) +k = np.array(6).astype(np.int64) +# X: +# [[4, 7, 3, 7, 9], +# [1, 2, 8, 6, 9], +# [9, 4, 0, 8, 7], +# [4, 3, 4, 2, 4]] +# expect result: +# [[0, 0, 0, 0, 0], +# [0, 0, 0, 0, 0], +# [0, 0, 0, 0, 0], +# [0, 0, 0, 0, 0]] +y = triu_reference_implementation(x, int(k)) +expect(node, inputs=[x, k], outputs=[y], name='test_triu_out_pos') +``` + +
+ + +
+triu_pos + +```python +node = onnx.helper.make_node( + 'Trilu', + inputs=['x', 'k'], + outputs=['y'], +) + +x = np.random.randint(10, size=(4, 5)).astype(np.int64) +k = np.array(2).astype(np.int64) +# X: +# [[4, 7, 3, 7, 9], +# [1, 2, 8, 6, 9], +# [9, 4, 0, 8, 7], +# [4, 3, 4, 2, 4]] +# expect result: +# [[0, 0, 3, 7, 9], +# [0, 0, 0, 6, 9], +# [0, 0, 0, 0, 7], +# [0, 0, 0, 0, 0]] +y = triu_reference_implementation(x, int(k)) +expect(node, inputs=[x, k], outputs=[y], name='test_triu_pos') +``` + +
+ + +
+triu_square + +```python +node = onnx.helper.make_node( + 'Trilu', + inputs=['x'], + outputs=['y'], +) + +x = np.random.randint(10, size=(2, 3, 3)).astype(np.int64) +y = triu_reference_implementation(x) +# X: +# [[[4, 6, 9], +# [7, 5, 4], +# [8, 1, 2]], +# +# [[1, 4, 9], +# [9, 6, 3], +# [8, 9, 8]]] +# expect result: +# [[[4, 6, 9], +# [0, 5, 4], +# [0, 0, 2]], +# +# [[1, 4, 9], +# [0, 6, 3], +# [0, 0, 8]]] +expect(node, inputs=[x], outputs=[y], name='test_triu_square') +``` + +
+ + +
+triu_square_neg + +```python +node = onnx.helper.make_node( + 'Trilu', + inputs=['x', 'k'], + outputs=['y'], +) + +x = np.random.randint(10, size=(2, 3, 3)).astype(np.int64) +k = np.array(-1).astype(np.int64) +# X: +# [[[4, 6, 9], +# [7, 5, 4], +# [8, 1, 2]], +# +# [[1, 4, 9], +# [9, 6, 3], +# [8, 9, 8]]] +# expect result: +# [[[4, 6, 9], +# [7, 5, 4], +# [0, 1, 2]], +# +# [[1, 4, 9], +# [9, 6, 3], +# [0, 9, 8]]] +y = triu_reference_implementation(x, int(k)) +expect(node, inputs=[x, k], outputs=[y], name='test_triu_square_neg') +``` + +
+ + +
+triu_zero + +```python +node = onnx.helper.make_node( + 'Trilu', + inputs=['x', 'k'], + outputs=['y'], +) + +x = np.random.randint(10, size=(0, 5)).astype(np.int64) +k = np.array(6).astype(np.int64) +# X: +# [] +# expect result: +# [] +y = triu_reference_implementation(x, int(k)) +expect(node, inputs=[x, k], outputs=[y], name='test_triu_zero') +``` + +
+ + +### **Unique** + + Find the unique elements of a tensor. When an optional attribute 'axis' is provided, unique subtensors sliced along the 'axis' are returned. + Otherwise the input tensor is flattened and unique values of the flattened tensor are returned. + + This operator returns the unique values or sliced unique subtensors of the input tensor and three optional outputs. + The first output tensor 'Y' contains all unique values or subtensors of the input. + The second optional output tensor 'indices' contains indices of 'Y' elements' first occurance in 'X'.. + The third optional output tensor 'inverse_indices' contains, for elements of 'X', its corresponding indices in 'Y'. ". + The fourth optional output tensor 'counts' contains the count of each element of 'Y' in the input. + + Outputs are either sorted in ascending order or optionally in the order of the first occurrence of the values in the input. + + https://docs.scipy.org/doc/numpy/reference/generated/numpy.unique.html + + Example 1: + input_X = [2, 1, 1, 3, 4, 3] + attribute_sorted = 0 + attribute_axis = None + output_Y = [2, 1, 3, 4] + output_indices = [0, 1, 3, 4] + output_inverse_indices = [0, 1, 1, 2, 3, 2] + output_counts = [1, 2, 2, 1] + + Example 2: + input_X = [[1, 3], [2, 3]] + attribute_sorted = 1 + attribute_axis = None + output_Y = [1, 2, 3] + output_indices = [0, 2, 1] + output_inverse_indices = [0, 2, 1, 2] + output_counts = [1, 1, 2] + + Example 3: + input_X = [[1, 0, 0], [1, 0, 0], [2, 3, 4]] + attribute_sorted = 1 + attribute_axis = 0 + output_Y = [[1, 0, 0], [2, 3, 4]] + output_indices = [0, 2] + output_inverse_indices = [0, 0, 1] + output_counts = [2, 1] + + Example 4: + input_x = [[[1., 1.], [0., 1.], [2., 1.], [0., 1.]], + [[1., 1.], [0., 1.], [2., 1.], [0., 1.]]] + attribute_sorted = 1 + attribute_axis = 1 + + intermediate data are presented below for better understanding: + + there are 4 subtensors sliced along axis 1 of input_x (shape = (2, 4, 2)): + A: [[1, 1], [1, 1]], + [[0, 1], [0, 1]], + [[2, 1], [2, 1]], + [[0, 1], [0, 1]]. + + there are 3 unique subtensors: + [[1, 1], [1, 1]], + [[0, 1], [0, 1]], + [[2, 1], [2, 1]]. + + sorted unique subtensors: + B: [[0, 1], [0, 1]], + [[1, 1], [1, 1]], + [[2, 1], [2, 1]]. + + output_Y is constructed from B: + [[[0. 1.], [1. 1.], [2. 1.]], + [[0. 1.], [1. 1.], [2. 1.]]] + + output_indices is to map from B to A: + [1, 0, 2] + + output_inverse_indices is to map from A to B: + [1, 0, 2, 0] + + output_counts = [2 1 1] + +#### Version + +This version of the operator has been available since version 11 of the default ONNX operator set. + +#### Attributes + +
+
axis : int
+
(Optional) The dimension to apply unique. If not specified, the unique elements of the flattened input are returned. Negative value means counting dimensions from the back. Accepted range is [-r, r-1] where r = rank(input).
+
sorted : int (default is 1)
+
(Optional) Whether to sort the unique elements in ascending order before returning as output. Must be one of 0, or 1 (default).
+
+ +#### Inputs + +
+
X (non-differentiable) : T
+
A N-D input tensor that is to be processed.
+
+ +#### Outputs (1 - 4) + +
+
Y (non-differentiable) : T
+
A tensor of the same type as 'X' containing all the unique values or subtensors sliced along a provided 'axis' in 'X', either sorted or maintained in the same order they occur in input 'X'
+
indices (optional, non-differentiable) : tensor(int64)
+
A 1-D INT64 tensor containing indices of 'Y' elements' first occurance in 'X'. When 'axis' is provided, it contains indices to subtensors in input 'X' on the 'axis'. When 'axis' is not provided, it contains indices to values in the flattened input tensor.
+
inverse_indices (optional, non-differentiable) : tensor(int64)
+
A 1-D INT64 tensor containing, for elements of 'X', its corresponding indices in 'Y'. When 'axis' is provided, it contains indices to subtensors in output 'Y' on the 'axis'. When 'axis' is not provided, it contains indices to values in output 'Y'.
+
counts (optional, non-differentiable) : tensor(int64)
+
A 1-D INT64 tensor containing the count of each element of 'Y' in input 'X'
+
+ +#### Type Constraints + +
+
T : tensor(uint8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(int8), tensor(int16), tensor(int32), tensor(int64), tensor(float16), tensor(float), tensor(double), tensor(string), tensor(bool), tensor(complex64), tensor(complex128)
+
Input can be of any tensor type.
+
+ + +#### Examples + +
+not_sorted_without_axis + +```python +node_not_sorted = onnx.helper.make_node( + 'Unique', + inputs=['X'], + outputs=['Y', 'indices', 'inverse_indices', 'counts'], + sorted=0 +) +# numpy unique does not retain original order (it sorts the output unique values) +# https://github.com/numpy/numpy/issues/8621 +# we need to recover unsorted output and indices +x = np.array([2.0, 1.0, 1.0, 3.0, 4.0, 3.0], dtype=np.float32) +y, indices, inverse_indices, counts = np.unique(x, True, True, True) + +# prepare index mapping from sorted to unsorted +argsorted_indices = np.argsort(indices) +inverse_indices_map = {i: si for i, si in zip(argsorted_indices, np.arange(len(argsorted_indices)))} + +indices = indices[argsorted_indices] +y = np.take(x, indices, axis=0) +inverse_indices = np.asarray([inverse_indices_map[i] for i in inverse_indices], dtype=np.int64) +counts = counts[argsorted_indices] +indices, inverse_indices, counts = specify_int64(indices, inverse_indices, counts) +# print(y) +# [2.0, 1.0, 3.0, 4.0] +# print(indices) +# [0 1 3 4] +# print(inverse_indices) +# [0, 1, 1, 2, 3, 2] +# print(counts) +# [1, 2, 2, 1] + +expect(node_not_sorted, inputs=[x], outputs=[y, indices, inverse_indices, counts], name='test_unique_not_sorted_without_axis') +``` + +
+ + +
+sorted_with_axis + +```python +node_sorted = onnx.helper.make_node( + 'Unique', + inputs=['X'], + outputs=['Y', 'indices', 'inverse_indices', 'counts'], + sorted=1, + axis=0 +) + +x = np.array([[1, 0, 0], [1, 0, 0], [2, 3, 4]], dtype=np.float32) +y, indices, inverse_indices, counts = np.unique(x, True, True, True, axis=0) +indices, inverse_indices, counts = specify_int64(indices, inverse_indices, counts) +# print(y) +# [[1. 0. 0.] +# [2. 3. 4.]] +# print(indices) +# [0 2] +# print(inverse_indices) +# [0 0 1] +# print(counts) +# [2 1] + +expect(node_sorted, inputs=[x], outputs=[y, indices, inverse_indices, counts], name='test_unique_sorted_with_axis') +``` + +
+ + +
+sorted_with_axis_3d + +```python +node_sorted = onnx.helper.make_node( + 'Unique', + inputs=['X'], + outputs=['Y', 'indices', 'inverse_indices', 'counts'], + sorted=1, + axis=1 +) + +x = np.array([[[1., 1.], [0., 1.], [2., 1.], [0., 1.]], + [[1., 1.], [0., 1.], [2., 1.], [0., 1.]]], dtype=np.float32) +y, indices, inverse_indices, counts = np.unique(x, True, True, True, axis=1) +indices, inverse_indices, counts = specify_int64(indices, inverse_indices, counts) +# print(y) +# [[[0. 1.] +# [1. 1.] +# [2. 1.]] +# [[0. 1.] +# [1. 1.] +# [2. 1.]]] +# print(indices) +# [1 0 2] +# print(inverse_indices) +# [1 0 2 0] +# print(counts) +# [2 1 1] +expect(node_sorted, inputs=[x], outputs=[y, indices, inverse_indices, counts], name='test_unique_sorted_with_axis_3d') +``` + +
+ + +
+sorted_with_negative_axis + +```python +node_sorted = onnx.helper.make_node( + 'Unique', + inputs=['X'], + outputs=['Y', 'indices', 'inverse_indices', 'counts'], + sorted=1, + axis=-1 +) + +x = np.array([[1, 0, 0], [1, 0, 0], [2, 3, 3]], dtype=np.float32) +y, indices, inverse_indices, counts = np.unique(x, True, True, True, axis=-1) +indices, inverse_indices, counts = specify_int64(indices, inverse_indices, counts) +# print(y) +# [[0. 1.] +# [0. 1.] +# [3. 2.]] +# print(indices) +# [1 0] +# print(inverse_indices) +# [1 0 0] +# print(counts) +# [2 1] + +expect(node_sorted, inputs=[x], outputs=[y, indices, inverse_indices, counts], name='test_unique_sorted_with_negative_axis') +``` + +
+ + +
+sorted_without_axis + +```python +node_sorted = onnx.helper.make_node( + 'Unique', + inputs=['X'], + outputs=['Y', 'indices', 'inverse_indices', 'counts'] +) + +x = np.array([2.0, 1.0, 1.0, 3.0, 4.0, 3.0], dtype=np.float32) +y, indices, inverse_indices, counts = np.unique(x, True, True, True) +indices, inverse_indices, counts = specify_int64(indices, inverse_indices, counts) +expect(node_sorted, inputs=[x], outputs=[y, indices, inverse_indices, counts], name='test_unique_sorted_without_axis') +``` + +
+ + +### **Unsqueeze** + + Insert single-dimensional entries to the shape of an input tensor (`data`). + Takes one required input `axes` - which contains a list of dimension indices and this operator will insert a dimension of value `1` into the corresponding index of the output tensor (`expanded`). + + For example: + Given an input tensor (`data`) of shape [3, 4, 5], then + Unsqueeze(data, axes=[0, 4]) outputs a tensor (`expanded`) containing same data as `data` but with shape [1, 3, 4, 5, 1]. + + The input `axes` should not contain any duplicate entries. It is an error if it contains duplicates. + The rank of the output tensor (`output_rank`) is the rank of the input tensor (`data`) plus the number of values in `axes`. + Each value in `axes` should be within the (inclusive) range [-output_rank , output_rank - 1]. + The order of values in `axes` does not matter and can come in any order. + + +#### Version + +This version of the operator has been available since version 13 of the default ONNX operator set. + +Other versions of this operator: 1, 11 + +#### Inputs + +
+
data (differentiable) : T
+
Original tensor
+
axes (non-differentiable) : tensor(int64)
+
List of integers indicating the dimensions to be inserted. Negative value means counting dimensions from the back. Accepted range is [-r, r-1] where r = rank(expanded).
+
+ +#### Outputs + +
+
expanded (differentiable) : T
+
Reshaped tensor with same data as input.
+
+ +#### Type Constraints + +
+
T : tensor(uint8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(int8), tensor(int16), tensor(int32), tensor(int64), tensor(bfloat16), tensor(float16), tensor(float), tensor(double), tensor(string), tensor(bool), tensor(complex64), tensor(complex128)
+
Constrain input and output types to all tensor types.
+
+ + +#### Examples + +
+unsqueeze_negative_axes + +```python +node = onnx.helper.make_node( + 'Unsqueeze', + inputs=['x', 'axes'], + outputs=['y'], +) +x = np.random.randn(1, 3, 1, 5).astype(np.float32) +axes = np.array([-2]).astype(np.int64) +y = np.expand_dims(x, axis=-2) +expect(node, inputs=[x, axes], outputs=[y], + name='test_unsqueeze_negative_axes') +``` + +
+ + +
+unsqueeze_one_axis + +```python +x = np.random.randn(3, 4, 5).astype(np.float32) + +for i in range(x.ndim): + axes = np.array([i]).astype(np.int64) + node = onnx.helper.make_node( + 'Unsqueeze', + inputs=['x', 'axes'], + outputs=['y'], + ) + y = np.expand_dims(x, axis=i) + + expect(node, inputs=[x, axes], outputs=[y], + name='test_unsqueeze_axis_' + str(i)) +``` + +
+ + +
+unsqueeze_three_axes + +```python +x = np.random.randn(3, 4, 5).astype(np.float32) +axes = np.array([2, 4, 5]).astype(np.int64) + +node = onnx.helper.make_node( + 'Unsqueeze', + inputs=['x', 'axes'], + outputs=['y'], +) +y = np.expand_dims(x, axis=2) +y = np.expand_dims(y, axis=4) +y = np.expand_dims(y, axis=5) + +expect(node, inputs=[x, axes], outputs=[y], + name='test_unsqueeze_three_axes') +``` + +
+ + +
+unsqueeze_two_axes + +```python +x = np.random.randn(3, 4, 5).astype(np.float32) +axes = np.array([1, 4]).astype(np.int64) + +node = onnx.helper.make_node( + 'Unsqueeze', + inputs=['x', 'axes'], + outputs=['y'], +) +y = np.expand_dims(x, axis=1) +y = np.expand_dims(y, axis=4) + +expect(node, inputs=[x, axes], outputs=[y], + name='test_unsqueeze_two_axes') +``` + +
+ + +
+unsqueeze_unsorted_axes + +```python +x = np.random.randn(3, 4, 5).astype(np.float32) +axes = np.array([5, 4, 2]).astype(np.int64) + +node = onnx.helper.make_node( + 'Unsqueeze', + inputs=['x', 'axes'], + outputs=['y'], +) +y = np.expand_dims(x, axis=2) +y = np.expand_dims(y, axis=4) +y = np.expand_dims(y, axis=5) + +expect(node, inputs=[x, axes], outputs=[y], + name='test_unsqueeze_unsorted_axes') +``` + +
+ + +### **Upsample** (deprecated) + + Upsample the input tensor. + Each dimension value of the output tensor is: + output_dimension = floor(input_dimension * scale). + +#### Version + +This version of the operator has been deprecated since version 10 of the default ONNX operator set. + +Other versions of this operator: 7, 9 + + +#### Examples + +
+nearest + +```python +node = onnx.helper.make_node( + 'Upsample', + inputs=['X', 'scales'], + outputs=['Y'], + mode='nearest', +) + +data = np.array([[[ + [1, 2], + [3, 4], +]]], dtype=np.float32) + +scales = np.array([1.0, 1.0, 2.0, 3.0], dtype=np.float32) + +output = np.array([[[ + [1, 1, 1, 2, 2, 2], + [1, 1, 1, 2, 2, 2], + [3, 3, 3, 4, 4, 4], + [3, 3, 3, 4, 4, 4], +]]], dtype=np.float32) + +expect(node, inputs=[data, scales], outputs=[output], + name='test_upsample_nearest', opset_imports=[helper.make_opsetid("", 9)]) +``` + +
+ + +### **Where** + + Return elements, either from X or Y, depending on condition. + Where behaves like + [numpy.where](https://docs.scipy.org/doc/numpy/reference/generated/numpy.where.html) + with three parameters. + + This operator supports **multidirectional (i.e., Numpy-style) broadcasting**; for more details please check [the doc](Broadcasting.md). + + **History** + - Version 16 adds bfloat16 to the types allowed (for the second and third parameter). + +#### Version + +This version of the operator has been available since version 16 of the default ONNX operator set. + +Other versions of this operator: 9 + +#### Inputs + +
+
condition (non-differentiable) : B
+
When True (nonzero), yield X, otherwise yield Y
+
X (differentiable) : T
+
values selected at indices where condition is True
+
Y (differentiable) : T
+
values selected at indices where condition is False
+
+ +#### Outputs + +
+
output (differentiable) : T
+
Tensor of shape equal to the broadcasted shape of condition, X, and Y.
+
+ +#### Type Constraints + +
+
B : tensor(bool)
+
Constrain to boolean tensors.
+
T : tensor(uint8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(int8), tensor(int16), tensor(int32), tensor(int64), tensor(bfloat16), tensor(float16), tensor(float), tensor(double), tensor(string), tensor(bool), tensor(complex64), tensor(complex128)
+
Constrain input and output types to all tensor types (including bfloat).
+
+ + +#### Examples + +
+long + +```python +node = onnx.helper.make_node( + 'Where', + inputs=['condition', 'x', 'y'], + outputs=['z'], +) + +condition = np.array([[1, 0], [1, 1]], dtype=bool) +x = np.array([[1, 2], [3, 4]], dtype=np.int64) +y = np.array([[9, 8], [7, 6]], dtype=np.int64) +z = np.where(condition, x, y) # expected output [[1, 8], [3, 4]] +expect(node, inputs=[condition, x, y], outputs=[z], + name='test_where_long_example') +``` + +
+ + +
+where + +```python +node = onnx.helper.make_node( + 'Where', + inputs=['condition', 'x', 'y'], + outputs=['z'], +) + +condition = np.array([[1, 0], [1, 1]], dtype=bool) +x = np.array([[1, 2], [3, 4]], dtype=np.float32) +y = np.array([[9, 8], [7, 6]], dtype=np.float32) +z = np.where(condition, x, y) # expected output [[1, 8], [3, 4]] +expect(node, inputs=[condition, x, y], outputs=[z], + name='test_where_example') +``` + +
+ + +### **Xor** + + Returns the tensor resulted from performing the `xor` logical operation + elementwise on the input tensors `A` and `B` (with Numpy-style broadcasting support). + + This operator supports **multidirectional (i.e., Numpy-style) broadcasting**; for more details please check [the doc](Broadcasting.md). + +#### Version + +This version of the operator has been available since version 7 of the default ONNX operator set. + +Other versions of this operator: 1 + +#### Inputs + +
+
A (non-differentiable) : T
+
First input operand for the logical operator.
+
B (non-differentiable) : T
+
Second input operand for the logical operator.
+
+ +#### Outputs + +
+
C (non-differentiable) : T1
+
Result tensor.
+
+ +#### Type Constraints + +
+
T : tensor(bool)
+
Constrains input to boolean tensor.
+
T1 : tensor(bool)
+
Constrains output to boolean tensor.
+
+ + +#### Examples + +
+xor + +```python +node = onnx.helper.make_node( + 'Xor', + inputs=['x', 'y'], + outputs=['xor'], +) + +# 2d +x = (np.random.randn(3, 4) > 0).astype(bool) +y = (np.random.randn(3, 4) > 0).astype(bool) +z = np.logical_xor(x, y) +expect(node, inputs=[x, y], outputs=[z], + name='test_xor2d') + +# 3d +x = (np.random.randn(3, 4, 5) > 0).astype(bool) +y = (np.random.randn(3, 4, 5) > 0).astype(bool) +z = np.logical_xor(x, y) +expect(node, inputs=[x, y], outputs=[z], + name='test_xor3d') + +# 4d +x = (np.random.randn(3, 4, 5, 6) > 0).astype(bool) +y = (np.random.randn(3, 4, 5, 6) > 0).astype(bool) +z = np.logical_xor(x, y) +expect(node, inputs=[x, y], outputs=[z], + name='test_xor4d') +``` + +
+ + +
+xor_broadcast + +```python +node = onnx.helper.make_node( + 'Xor', + inputs=['x', 'y'], + outputs=['xor'], +) + +# 3d vs 1d +x = (np.random.randn(3, 4, 5) > 0).astype(bool) +y = (np.random.randn(5) > 0).astype(bool) +z = np.logical_xor(x, y) +expect(node, inputs=[x, y], outputs=[z], + name='test_xor_bcast3v1d') + +# 3d vs 2d +x = (np.random.randn(3, 4, 5) > 0).astype(bool) +y = (np.random.randn(4, 5) > 0).astype(bool) +z = np.logical_xor(x, y) +expect(node, inputs=[x, y], outputs=[z], + name='test_xor_bcast3v2d') + +# 4d vs 2d +x = (np.random.randn(3, 4, 5, 6) > 0).astype(bool) +y = (np.random.randn(5, 6) > 0).astype(bool) +z = np.logical_xor(x, y) +expect(node, inputs=[x, y], outputs=[z], + name='test_xor_bcast4v2d') + +# 4d vs 3d +x = (np.random.randn(3, 4, 5, 6) > 0).astype(bool) +y = (np.random.randn(4, 5, 6) > 0).astype(bool) +z = np.logical_xor(x, y) +expect(node, inputs=[x, y], outputs=[z], + name='test_xor_bcast4v3d') + +# 4d vs 4d +x = (np.random.randn(1, 4, 1, 6) > 0).astype(bool) +y = (np.random.randn(3, 1, 5, 6) > 0).astype(bool) +z = np.logical_xor(x, y) +expect(node, inputs=[x, y], outputs=[z], + name='test_xor_bcast4v4d') +``` + +
+ + +## ai.onnx.preview.training +### **ai.onnx.preview.training.Adagrad** + + Compute one iteration of ADAGRAD, a stochastic gradient based optimization + algorithm. This operator can conduct the optimization of multiple tensor variables. + + Let's define the behavior of this operator. As you can imagine, ADAGRAD requires + some parameters: + + - The initial learning-rate "R". + - The update count "T". That is, the number of training iterations conducted. + - A L2-norm regularization coefficient "norm_coefficient". + - A learning-rate decay factor "decay_factor". + - A small constant "epsilon" to avoid dividing-by-zero. + + At each ADAGRAD iteration, the optimized tensors are moved along a direction + computed based on their estimated gradient and accumulated squared gradient. Assume + that only a single tensor "X" is updated by this operator. We need the value of "X", + its gradient "G", and its accumulated squared gradient "H". Therefore, variables in + this operator's input list are sequentially "R", "T", "X", "G", and "H". Other + parameters are given as attributes because they are usually constants. Also, the + corresponding output tensors are the new value of "X" (called "X_new"), and then + the new accumulated squared gradient (called "H_new"). Those outputs are computed + from the given inputs following the pseudo code below. + + Let "+", "-", "*", and "/" are all element-wise arithmetic operations with + numpy-style broadcasting support. The pseudo code to compute those outputs is: + + // Compute a scalar learning-rate factor. At the first update of X, T is generally + // 0 (0-based update index) or 1 (1-based update index). + r = R / (1 + T * decay_factor); + + // Add gradient of 0.5 * norm_coefficient * ||X||_2^2, where ||X||_2 is the 2-norm. + G_regularized = norm_coefficient * X + G; + + // Compute new accumulated squared gradient. + H_new = H + G_regularized * G_regularized; + + // Compute the adaptive part of per-coordinate learning rate. Note that Sqrt(...) + // computes element-wise square-root. + H_adaptive = Sqrt(H_new) + epsilon + + // Compute the new value of "X". + X_new = X - r * G_regularized / H_adaptive; + + If one assign this operators to optimize multiple inputs, for example, "X_1" and "X_2", the same + pseudo code may be extended to handle all tensors jointly. More specifically, we can view "X" as a + concatenation of "X_1" and "X_2" (of course, their gradient and accumulate gradient should + be concatenated too) and then just reuse the entire pseudo code. + + Note that ADAGRAD was first proposed in http://jmlr.org/papers/volume12/duchi11a/duchi11a.pdf. + In that reference paper, this operator is a special case of the Figure 1's composite mirror + descent update. + +#### Version + +This version of the operator has been available since version 1 of the 'ai.onnx.preview.training' operator set. + +#### Attributes + +
+
decay_factor : float (default is 0.0)
+
The decay factor of learning rate after one update.The effective learning rate is computed by r = R / (1 + T * decay_factor). Default to 0 so that increasing update counts doesn't reduce the learning rate.
+
epsilon : float (default is 0.0)
+
Small scalar to avoid dividing by zero.
+
norm_coefficient : float (default is 0.0)
+
Regularization coefficient in 0.5 * norm_coefficient * ||X||_2^2. Default to 0, which means no regularization.
+
+ +#### Inputs (3 - ∞) + +
+
R : T1
+
The initial learning rate.
+
T : T2
+
The update count of "X". It should be a scalar.
+
inputs (variadic, heterogeneous) : T3
+
The current values of optimized tensors, followed by their respective gradients, followed by their respective accumulated squared gradients.For example, if two tensor "X_1" and "X_2" are optimized, The input list would be ["X_1", "X_2", gradient of "X_1", gradient of "X_2", accumulated squared gradient of "X_1", accumulated squared gradient of "X_2"].
+
+ +#### Outputs (1 - ∞) + +
+
outputs (variadic, heterogeneous) : T3
+
Updated values of optimized tensors, followed by their updated values of accumulated squared gradients. For example, if two tensor "X_1" and "X_2" are optimized, the output list would be [new value of "X_1," new value of "X_2" new accumulated squared gradient of "X_1", new accumulated squared gradient of "X_2"].
+
+ +#### Type Constraints + +
+
T1 : tensor(float), tensor(double)
+
Constrain input types to float scalars.
+
T2 : tensor(int64)
+
Constrain input types to 64-bit integer scalars.
+
T3 : tensor(float), tensor(double)
+
Constrain input and output types to float tensors.
+
+ + +#### Examples + +
+adagrad + +```python +# Define operator attributes. +norm_coefficient = 0.001 +epsilon = 1e-5 +decay_factor = 0.1 + +# Create operator. +node = onnx.helper.make_node('Adagrad', + inputs=['R', 'T', 'X', 'G', 'H'], + outputs=['X_new', 'H_new'], + norm_coefficient=norm_coefficient, + epsilon=epsilon, + decay_factor=decay_factor, + domain=AI_ONNX_PREVIEW_TRAINING_DOMAIN + ) + +# Define operator inputs. +r = np.array(0.1, dtype=np.float32) # scalar +t = np.array(0, dtype=np.int64) # scalar +x = np.array([1.0], dtype=np.float32) +g = np.array([-1.0], dtype=np.float32) +h = np.array([2.0], dtype=np.float32) + +# Compute expected outputs of Adagrad. +x_new, h_new = apply_adagrad(r, t, x, g, h, + norm_coefficient, epsilon, decay_factor) + +# Check results. +expect(node, inputs=[r, t, x, g, h], + outputs=[x_new, h_new], name='test_adagrad', + opset_imports=[onnx.helper.make_opsetid(AI_ONNX_PREVIEW_TRAINING_DOMAIN, 1)]) +``` + +
+ + +
+adagrad_multiple + +```python +# Define operator attributes. +norm_coefficient = 0.001 +epsilon = 1e-5 +decay_factor = 0.1 + +node = onnx.helper.make_node('Adagrad', + inputs=['R', 'T', 'X1', 'X2', + 'G1', 'G2', 'H1', 'H2'], + outputs=['X1_new', 'X2_new', + 'H1_new', 'H2_new'], + norm_coefficient=norm_coefficient, + epsilon=epsilon, + decay_factor=decay_factor, + domain=AI_ONNX_PREVIEW_TRAINING_DOMAIN + ) + +# Define operator inputs. +r = np.array(0.1, dtype=np.float32) # scalar +t = np.array(0, dtype=np.int64) # scalar + +x1 = np.array([1.0], dtype=np.float32) +g1 = np.array([-1.0], dtype=np.float32) +h1 = np.array([2.0], dtype=np.float32) + +x2 = np.array([1.0, 2.0], dtype=np.float32) +g2 = np.array([-1.0, -3.0], dtype=np.float32) +h2 = np.array([4.0, 1.0], dtype=np.float32) + +# Compute expected outputs of Adagrad. +x1_new, h1_new = apply_adagrad(r, t, x1, g1, h1, + norm_coefficient, epsilon, decay_factor) +x2_new, h2_new = apply_adagrad(r, t, x2, g2, h2, + norm_coefficient, epsilon, decay_factor) + +# Check results. +expect(node, inputs=[r, t, x1, x2, g1, g2, h1, h2], + outputs=[x1_new, x2_new, h1_new, h2_new], name='test_adagrad_multiple', + opset_imports=[onnx.helper.make_opsetid(AI_ONNX_PREVIEW_TRAINING_DOMAIN, 1)]) +``` + +
+ + +### **ai.onnx.preview.training.Adam** + + Compute one iteration of Adam, a stochastic gradient based optimization + algorithm. This operator can conduct the optimization of multiple tensor variables. + + Let's define the behavior of this operator. First of all, Adam requires + some parameters: + + - The learning-rate "R". + - The update count "T". That is, the number of training iterations conducted. + - A L2-norm regularization coefficient "norm_coefficient". + - A small constant "epsilon" to avoid dividing-by-zero. + - Two coefficients, "alpha" and "beta". + + At each Adam iteration, the optimized tensors are moved along a direction + computed based on their exponentially-averaged historical gradient and + exponentially-averaged historical squared gradient. Assume that only a tensor + "X" is being optimized. The rest of required information is + + - the value of "X", + - "X"'s gradient (denoted by "G"), + - "X"'s exponentially-averaged historical gradient (denoted by "V"), and + - "X"'s exponentially-averaged historical squared gradient (denoted by "H"). + + Some of those parameters are passed into this operator as input tensors and others + are stored as this operator's attributes. Specifically, this operator's input tensor + list is ["R", "T", "X", "G", "V", "H"]. That is, "R" is the first input, "T" is + the second input, and so on. Other parameters are given as attributes because they + are constants. Moreover, the corresponding output tensors are + + - the new value of "X" (called "X_new"), + - the new exponentially-averaged historical gradient (denoted by "V_new"), and + - the new exponentially-averaged historical squared gradient (denoted by "H_new"). + + Those outputs are computed following the pseudo code below. + + Let "+", "-", "*", and "/" are all element-wise arithmetic operations with + numpy-style broadcasting support. The pseudo code to compute those outputs is: + + // Add gradient of 0.5 * norm_coefficient * ||X||_2^2, where ||X||_2 is the 2-norm. + G_regularized = norm_coefficient * X + G + + // Update exponentially-averaged historical gradient. + V_new = alpha * V + (1 - alpha) * G_regularized + + // Update exponentially-averaged historical squared gradient. + H_new = beta * H + (1 - beta) * G_regularized * G_regularized + + // Compute the element-wise square-root of H_new. V_new will be element-wisely + // divided by H_sqrt for a better update direction. + H_sqrt = Sqrt(H_new) + epsilon + + // Compute learning-rate. Note that "alpha**T"/"beta**T" is alpha's/beta's T-th power. + R_adjusted = T > 0 ? R * Sqrt(1 - beta**T) / (1 - alpha**T) : R + + // Compute new value of "X". + X_new = X - R_adjusted * V_new / H_sqrt + + // Post-update regularization. + X_final = (1 - norm_coefficient_post) * X_new + + If there are multiple inputs to be optimized, the pseudo code will be applied + independently to each of them. + +#### Version + +This version of the operator has been available since version 1 of the 'ai.onnx.preview.training' operator set. + +#### Attributes + +
+
alpha : float (default is 0.9)
+
Coefficient of previously accumulated gradient in running average. Default to 0.9.
+
beta : float (default is 0.999)
+
Coefficient of previously accumulated squared-gradient in running average. Default to 0.999.
+
epsilon : float (default is 0.0)
+
Small scalar to avoid dividing by zero.
+
norm_coefficient : float (default is 0.0)
+
Regularization coefficient of 0.5 * norm_coefficient * ||X||_2^2. Default to 0, which means no regularization.
+
norm_coefficient_post : float (default is 0.0)
+
Regularization coefficient of 0.5 * norm_coefficient * ||X||_2^2. Default to 0, which means no regularization.
+
+ +#### Inputs (3 - ∞) + +
+
R : T1
+
The initial learning rate.
+
T : T2
+
The update count of "X". It should be a scalar.
+
inputs (variadic, heterogeneous) : T3
+
The tensors to be optimized, followed by their respective gradients, followed by their respective accumulated gradients (aka momentum), followed by their respective accumulated squared gradients. For example, to optimize tensors "X_1" and "X_2,", the input list would be ["X_1", "X_2", gradient of "X_1", gradient of "X_2", accumulated gradient of "X_1", accumulated gradient of "X_2", accumulated squared gradient of "X_1", accumulated squared gradient of "X_2"].
+
+ +#### Outputs (1 - ∞) + +
+
outputs (variadic, heterogeneous) : T3
+
New values of optimized tensors, followed by their respective new accumulated gradients, followed by their respective new accumulated squared gradients. For example, if two tensors "X_1" and "X_2" are optimized, the outputs list would be [new value of "X_1", new value of "X_2", new accumulated gradient of "X_1", new accumulated gradient of "X_2", new accumulated squared gradient of "X_1", new accumulated squared gradient of "X_2"].
+
+ +#### Type Constraints + +
+
T1 : tensor(float), tensor(double)
+
Constrain input types to float scalars.
+
T2 : tensor(int64)
+
Constrain input types to 64-bit integer scalars.
+
T3 : tensor(float), tensor(double)
+
Constrain input and output types to float tensors.
+
+ + +#### Examples + +
+adam + +```python +# Define operator attributes. +norm_coefficient = 0.001 +alpha = 0.95 +beta = 0.1 +epsilon = 1e-7 + +# Create operator. +node = onnx.helper.make_node('Adam', + inputs=['R', 'T', 'X', 'G', 'V', 'H'], + outputs=['X_new', 'V_new', 'H_new'], + norm_coefficient=norm_coefficient, + alpha=alpha, + beta=beta, + epsilon=epsilon, + domain=AI_ONNX_PREVIEW_TRAINING_DOMAIN + ) + +# Define operator inputs. +r = np.array(0.1, dtype=np.float32) # scalar +t = np.array(0, dtype=np.int64) # scalar +x = np.array([1.2, 2.8], dtype=np.float32) +g = np.array([-0.94, -2.5], dtype=np.float32) +v = np.array([1.7, 3.6], dtype=np.float32) +h = np.array([0.1, 0.1], dtype=np.float32) + +# Compute expected outputs of Adam. +x_new, v_new, h_new = apply_adam(r, t, x, g, v, h, + norm_coefficient, 0.0, alpha, beta, + epsilon) + +# Check results. +expect(node, inputs=[r, t, x, g, v, h], + outputs=[x_new, v_new, h_new], name='test_adam', + opset_imports=[onnx.helper.make_opsetid(AI_ONNX_PREVIEW_TRAINING_DOMAIN, 1)]) +``` + +
+ + +
+adam_multiple + +```python +# Define operator attributes. +norm_coefficient = 0.001 +alpha = 0.95 +beta = 0.85 +epsilon = 1e-2 + +node = onnx.helper.make_node('Adam', + inputs=['R', 'T', 'X1', 'X2', + 'G1', 'G2', 'V1', 'V2', + 'H1', 'H2'], + outputs=['X1_new', 'X2_new', + 'V1_new', 'V2_new', + 'H1_new', 'H2_new'], + norm_coefficient=norm_coefficient, + alpha=alpha, + beta=beta, + domain=AI_ONNX_PREVIEW_TRAINING_DOMAIN + ) + +# Define operator inputs. +r = np.array(0.1, dtype=np.float32) # scalar +t = np.array(0, dtype=np.int64) # scalar + +x1 = np.array([1.0], dtype=np.float32) +g1 = np.array([-1.0], dtype=np.float32) +v1 = np.array([2.0], dtype=np.float32) +h1 = np.array([0.5], dtype=np.float32) + +x2 = np.array([1.0, 2.0], dtype=np.float32) +g2 = np.array([-1.0, -3.0], dtype=np.float32) +v2 = np.array([4.0, 1.0], dtype=np.float32) +h2 = np.array([1.0, 10.0], dtype=np.float32) + +# Compute expected outputs of Adam. +x1_new, v1_new, h1_new = apply_adam(r, t, x1, g1, v1, h1, + norm_coefficient, 0.0, alpha, beta, + epsilon) +x2_new, v2_new, h2_new = apply_adam(r, t, x2, g2, v2, h2, + norm_coefficient, 0.0, alpha, beta, + epsilon) + +# Check results. +expect(node, inputs=[r, t, x1, x2, g1, g2, v1, v2, h1, h2], + outputs=[x1_new, x2_new, v1_new, v2_new, h1_new, h2_new], + name='test_adam_multiple', + opset_imports=[onnx.helper.make_opsetid(AI_ONNX_PREVIEW_TRAINING_DOMAIN, 1)]) +``` + +
+ + +### **ai.onnx.preview.training.Gradient** + + Gradient operator computes the partial derivatives of a specific tensor w.r.t. + some other tensors. This operator is widely used in gradient-based training + algorithms. To illustrate its use, let's consider a computation graph, + + ``` + X -----. + | + v + W --> Conv --> H --> Gemm --> Y + ^ + | + Z + ``` + + , where W and Z are trainable tensors. Note that operators' attributes are + omitted for the sake of simplicity. Let dY/dW (dY/dZ) be the gradient of + Y with respect to W (Z). The user can compute gradient by inserting Gradient + operator to form another graph shown below. + + ``` + W --> Conv --> H --> Gemm --> Y + | ^ ^ + | | | + | X Z + | | | + | | .----------' + | | | (W/Z/X is the 1st/2nd/3rd input of Gradient as shown in + | | | "xs" followed by "zs") + | v v + '---> Gradient(xs=["W", "Z"], zs=["X"], y="Y") + | | + | '-----------------------------------> dY/dW (1st output of Gradient) + | + '---------------------------------------> dY/dZ (2nd output of Gradient) + ``` + + By definition, the tensor "y" is a function of independent variables in "xs" + and "zs". Since we only compute the gradient of "y" w.r.t. the differentiable + variables in "xs", this Gradient only outputs dY/dW and dY/dZ. Note that "H" + cannot appear in "xs" and "zs". The reason is that "H" can be determined by + tensors "W" and "X" and therefore "H" is not an independent variable. + + All outputs are optional. If needed, for example, user can assign an empty + string to the 1st output name of that Gradient to skip the generation of dY/dW. + Note that the concept of optional outputs can also be found in ONNX's RNN, GRU, + and LSTM. + + Gradient operator can compute derivative against intermediate tensors. For + example, the gradient of Y with respect to H can be done via + + ``` + W --> Conv --> H --> Gemm --> Y + ^ | ^ + | | | + X | Z + .-------' | + | .----------' + | | (H/Z is the 1st/2nd input of Gradient as shown in "xs") + v v + Gradient(xs=["H", "Z"], y="Y") + | | + | '-----------------------------------> dY/dH (1st output of Gradient) + | + '---------------------------------------> dY/dZ (2nd output of Gradient) + ``` + + It is possible to represent high-order differentiation using Gradient operators. + For example, given the following linear model: + + ``` + W --> Gemm --> Y --> Loss --> O + ^ ^ + | | + X L + ``` + + To compute the 2nd order derivative of O with respect to W (denoted by + d^2O/dW^2), one can do + + ``` + W --> Gemm --> Y --> Loss --> O + | ^ ^ + | | | + | X .------------L + | | | | + | | | v + +------+-+> Gradient(xs=["X", "W"], zs=["L"], y="O") ---> dO/dX (1st output of Gradient) + | | | | + | | | '---> dO/dW (2nd output of Gradient) + | v v + '---> Gradient(xs=["X", "W"], zs=["L"], y="dO/dW") ---> d(dO/dW)dX (1st output of + | Gradient) + | + | + '---> d^2O/dW^2 (2nd output of Gradient) + ``` + + The tensors named in attributes "xs", "zs", and "y" define the differentiated + computation graph, and the inputs to Gradient node define the values at + which the gradient is computed. We can feed different tensors to the identified + graph. For example, one can compute the gradient of Y with respect to H at + a specific value of H, H_1, by providing that value as an input to the Gradient + node. + + ``` + W --> Conv --> H --> Gemm --> Y + ^ ^ + | | + X Z + + Z_1 (2nd input of Gradient) + | + v + H_1 --> Gradient(xs=["H", "Z"], y="Y") ---> dY/dH when H = H_1 and Y = Y_1. + | + '------------------------------> dY/dZ (2nd output of Gradient) + ``` + + When the inputs of Gradient are the tensors named in "xs" and "zs", the + computation can be optimized. More specifically, intermediate variables in + forward pass can be reused if the gradient is computed via reverse-mode + auto-differentiation. + + +#### Version + +This version of the operator has been available since version 1 of the 'ai.onnx.preview.training' operator set. + +#### Attributes + +
+
xs : list of strings (required)
+
Input tensor names of the differentiated sub-graph. It contains only the necessary differentiated inputs of a (sub-)graph. Variables (usually called intermediate variables) that can be generated from inputs cannot be included in this attribute.
+
y : string (required)
+
The targeted tensor. It can be viewed as the output of the differentiated function. The attribute "xs" and attribute "zs" are the minimal independent variable set that determines the value of "y".
+
zs : list of strings
+
Input tensor names of the differentiated sub-graph. It contains only the necessary non-differentiated inputs of a (sub-)graph. Variables (usually called intermediate variables) that can be generated from inputs cannot be included in this attribute.
+
+ +#### Inputs (1 - ∞) + +
+
Inputs (variadic, heterogeneous) : T1
+
The values fed into graph identified by the attributes. The i-th input is the value of the i-th tensor specified in the concatenated list of the attribute "xs" and the attribute "zs". For example, if xs=["A", "B"] and zs=["C"], the first input is used as the value of symbol "A" and the 3rd input is substituted for all the occurrences of "C".
+
+ +#### Outputs (1 - ∞) + +
+
Outputs (variadic, heterogeneous) : T2
+
The gradient of the tensor specified by the attribute "y" with respect to each of tensors specified in the attribute "xs". The i-th output is the gradient of "y" with respect to the i-th tensor specified in the attribute "xs".
+
+ +#### Type Constraints + +
+
T1 : tensor(uint8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(int8), tensor(int16), tensor(int32), tensor(int64), tensor(float16), tensor(float), tensor(double), tensor(string), tensor(bool), tensor(complex64), tensor(complex128)
+
Allow outputs to be any kind of tensor.
+
T2 : tensor(float16), tensor(float), tensor(double)
+
Allow inputs to be any kind of floating-point tensor.
+
+ + +#### Examples + +
+gradient_scalar_add + +```python +add_node = onnx.helper.make_node('Add', + ['a', 'b'], ['c'], name='my_add') +gradient_node = onnx.helper.make_node( + 'Gradient', ['a', 'b'], + ['dc_da', 'dc_db'], name='my_gradient', + domain=AI_ONNX_PREVIEW_TRAINING_DOMAIN, + xs=['a', 'b'], y='c') + +a = np.array(1.0).astype(np.float32) +b = np.array(2.0).astype(np.float32) +c = a + b +# dc / da = d(a+b) / da = 1 +dc_da = np.array(1).astype(np.float32) +# db / db = d(a+b) / db = 1 +dc_db = np.array(1).astype(np.float32) + +graph = onnx.helper.make_graph( + nodes=[add_node, gradient_node], + name='GradientOfAdd', + inputs=[ + onnx.helper.make_tensor_value_info('a', onnx.TensorProto.FLOAT, + []), + onnx.helper.make_tensor_value_info('b', onnx.TensorProto.FLOAT, + [])], + outputs=[ + onnx.helper.make_tensor_value_info('c', onnx.TensorProto.FLOAT, + []), + onnx.helper.make_tensor_value_info('dc_da', + onnx.TensorProto.FLOAT, []), + onnx.helper.make_tensor_value_info('dc_db', + onnx.TensorProto.FLOAT, [])]) +opsets = [ + onnx.helper.make_operatorsetid(ONNX_DOMAIN, 12), + onnx.helper.make_operatorsetid(AI_ONNX_PREVIEW_TRAINING_DOMAIN, 1)] +model = onnx.helper.make_model( + graph, + producer_name='backend-test', + opset_imports=opsets) +expect(model, inputs=[a, b], outputs=[c, dc_da, dc_db], + name='test_gradient_of_add') +``` + +
+ + +
+gradient_scalar_add_and_mul + +```python +add_node = onnx.helper.make_node('Add', + ['a', 'b'], ['c'], name='my_add') +mul_node = onnx.helper.make_node('Mul', + ['c', 'a'], ['d'], name='my_mul') +gradient_node = onnx.helper.make_node( + 'Gradient', ['a', 'b'], + ['dd_da', 'dd_db'], name='my_gradient', + domain=AI_ONNX_PREVIEW_TRAINING_DOMAIN, + xs=['a', 'b'], y='d') + +a = np.array(1.0).astype(np.float32) +b = np.array(2.0).astype(np.float32) +c = a + b +# d = a * c = a * (a + b) +d = a * c +# dd / da = d(a*a+a*b) / da = 2 * a + b +dd_da = (2 * a + b).astype(np.float32) +# dd / db = d(a*a+a*b) / db = a +dd_db = a + +graph = onnx.helper.make_graph( + nodes=[add_node, mul_node, gradient_node], + name='GradientOfTwoOperators', + inputs=[ + onnx.helper.make_tensor_value_info('a', onnx.TensorProto.FLOAT, + []), + onnx.helper.make_tensor_value_info('b', onnx.TensorProto.FLOAT, + [])], + outputs=[ + onnx.helper.make_tensor_value_info('d', onnx.TensorProto.FLOAT, + []), + onnx.helper.make_tensor_value_info('dd_da', + onnx.TensorProto.FLOAT, []), + onnx.helper.make_tensor_value_info('dd_db', + onnx.TensorProto.FLOAT, [])]) + +opsets = [ + onnx.helper.make_operatorsetid(ONNX_DOMAIN, 12), + onnx.helper.make_operatorsetid(AI_ONNX_PREVIEW_TRAINING_DOMAIN, 1)] +model = onnx.helper.make_model(graph, + producer_name='backend-test', + opset_imports=opsets) +expect(model, inputs=[a, b], outputs=[d, dd_da, dd_db], + name='test_gradient_of_add_and_mul') +``` + +
+ + +### **ai.onnx.preview.training.Momentum** + + Compute one iteration of stochastic gradient update with momentum. + This operator can conduct the optimization of multiple tensor variables. + + Let's define the behavior of this operator. As you can imagine, SG with momentum requires + several parameters: + + - The learning-rate "R". + - The update count "T". That is, the number of conducted training iterations. It should + be zero in the first training iteration. + - A L2-norm regularization coefficient "norm_coefficient". + - A decay coefficient of previous accumulated gradient (i.e., momentum) "alpha". + - The scaling coefficient of current gradient "beta". + - An attribute to choose either standard momentum or Nesterov's momentum "mode" should + be used. + + For the sake of simplicity, assume that there is only one tensor (called "X") to be optimized. + Other necessary inputs are "X"'s gradient (called "G") and "X"'s momentum (called "V"). This + Momentum operator maps all these inputs to the new value of "X" (called "X_new") and its new + momentum (called "V_new"). + + This operator supports two different momentum algorithms. Set the attribute "mode" to + "nesterov" if Nesterov's momentum is desired. Otherwise, set the attribute "model" to + "standard" to use standard momentum. Computation details are described subsequently. + + Let "+", "-", "*", and "/" are all element-wise operations with numpy-style broadcasting. + + Pseudo code for SG with standard momentum: + + // Add gradient of 0.5 * norm_coefficient * ||X||^2, where ||X|| is the sum of squared + // values of all elements in X. + G_regularized = norm_coefficient * X + G + + // In the first training iteration, beta should always be 1. + beta_adjusted = T > 0 ? beta : 1 + + // Compute the current momentum based on previous momentum and the current gradient. + V_new = alpha * V + beta_adjusted * G_regularized + + // Update X. + X_new = X - R * V_new + + Pseudo code for SG with Nesterov's momentum: + + // Add gradient of 0.5 * norm_coefficient * ||X||^2, where ||X|| is the sum of squared + // values of all elements in X. + G_regularized = norm_coefficient * X + G; + + // In the first training iteration, beta should always be 1. + beta_adjusted = T > 0 ? beta : 1 + + // Compute the current momentum based on previous momentum and the current gradient. + V_new = alpha * V + beta_adjusted * G_regularized; + + // Compute final update direction and then update X. + X_new = X - R * (G_regularized + alpha * V_new) + + If one assign this operators to optimize multiple inputs, for example, "X_1" and "X_2". The same + pseudo code would be extended to handle all tensors jointly. More specifically, we can view "X" as a + concatenation of "X_1" and "X_2" (of course, their gradient and accumulate gradient should + be concatenated too) and then our pseudo code becomes applicable. + +#### Version + +This version of the operator has been available since version 1 of the 'ai.onnx.preview.training' operator set. + +#### Attributes + +
+
alpha : float (required)
+
The decay factor of momentum. It should be a scalar.
+
beta : float (required)
+
The coefficient of gradient in computing new momentum. It should be a scalar.
+
mode : string (required)
+
Its value should be either "nesterov" or "standard". The value "nesterov" leads to the use of Nesterov's momentum while "standard" invokes stochastic gradient method using standard momentum
+
norm_coefficient : float (required)
+
Coefficient of 0.5 * norm_coefficient * ||X||^2.
+
+ +#### Inputs (3 - ∞) + +
+
R : T1
+
The learning rate.
+
T : T2
+
Update count of "X". It should be a scalar.
+
inputs (variadic, heterogeneous) : T3
+
It sequentially contains the current values of optimized tensors, then their gradient tensors, and finally their momentum tensors. For example, if two tensors "X_1" and "X_2" are optimized, The expected input list would be ["X_1", "X_2", gradient of "X_1", gradient of "X_2", momentum of "X_1", momentum of "X_2"].
+
+ +#### Outputs (1 - ∞) + +
+
outputs (variadic, heterogeneous) : T3
+
It sequentially contains the new values of optimized tensors and then the new values of their momentum tensors. For example, if two tensors "X_1" and "X_2" are optimized, the output list would be [new value of "X_1," new value of "X_2" new momentum of "X_1", new momentum of "X_2"].
+
+ +#### Type Constraints + +
+
T1 : tensor(float), tensor(double)
+
Constrain input types to float scalars.
+
T2 : tensor(int64)
+
Constrain input types to 64-bit integer scalars.
+
T3 : tensor(float), tensor(double)
+
Constrain input types to float tensors.
+
+ + +#### Examples + +
+momentum + +```python +# Define operator attributes. +norm_coefficient = 0.001 +alpha = 0.95 +beta = 0.1 + +# Create operator. +node = onnx.helper.make_node('Momentum', + inputs=['R', 'T', 'X', 'G', 'V'], + outputs=['X_new', 'V_new'], + norm_coefficient=norm_coefficient, + alpha=alpha, + beta=beta, + mode='standard', + domain=AI_ONNX_PREVIEW_TRAINING_DOMAIN + ) + +# Define operator inputs. +r = np.array(0.1, dtype=np.float32) # scalar +t = np.array(0, dtype=np.int64) # scalar +x = np.array([1.2, 2.8], dtype=np.float32) +g = np.array([-0.94, -2.5], dtype=np.float32) +v = np.array([1.7, 3.6], dtype=np.float32) + +# Compute expected outputs of Momentum. +x_new, v_new = apply_momentum(r, t, x, g, v, + norm_coefficient, alpha, beta) + +# Check results. +expect(node, inputs=[r, t, x, g, v], + outputs=[x_new, v_new], name='test_momentum', + opset_imports=[onnx.helper.make_opsetid(AI_ONNX_PREVIEW_TRAINING_DOMAIN, 1)]) +``` + +
+ + +
+momentum_multiple + +```python +# Define operator attributes. +norm_coefficient = 0.001 +alpha = 0.95 +beta = 0.85 + +node = onnx.helper.make_node('Momentum', + inputs=['R', 'T', 'X1', 'X2', + 'G1', 'G2', 'H1', 'H2'], + outputs=['X1_new', 'X2_new', + 'V1_new', 'V2_new'], + norm_coefficient=norm_coefficient, + alpha=alpha, + beta=beta, + mode='standard', + domain=AI_ONNX_PREVIEW_TRAINING_DOMAIN + ) + +# Define operator inputs. +r = np.array(0.1, dtype=np.float32) # scalar +t = np.array(0, dtype=np.int64) # scalar + +x1 = np.array([1.0], dtype=np.float32) +g1 = np.array([-1.0], dtype=np.float32) +v1 = np.array([2.0], dtype=np.float32) + +x2 = np.array([1.0, 2.0], dtype=np.float32) +g2 = np.array([-1.0, -3.0], dtype=np.float32) +v2 = np.array([4.0, 1.0], dtype=np.float32) + +# Compute expected outputs of Momentum. +x1_new, v1_new = apply_momentum(r, t, x1, g1, v1, + norm_coefficient, alpha, beta) +x2_new, v2_new = apply_momentum(r, t, x2, g2, v2, + norm_coefficient, alpha, beta) + +# Check results. +expect(node, inputs=[r, t, x1, x2, g1, g2, v1, v2], + outputs=[x1_new, x2_new, v1_new, v2_new], name='test_momentum_multiple', + opset_imports=[onnx.helper.make_opsetid(AI_ONNX_PREVIEW_TRAINING_DOMAIN, 1)]) +``` + +
+ + +
+nesterov_momentum + +```python +# Define operator attributes. +norm_coefficient = 0.01 +alpha = 0.95 +beta = 1.0 + +# Create operator. +node = onnx.helper.make_node('Momentum', + inputs=['R', 'T', 'X', 'G', 'V'], + outputs=['X_new', 'V_new'], + norm_coefficient=norm_coefficient, + alpha=alpha, + beta=beta, + mode='nesterov', + domain=AI_ONNX_PREVIEW_TRAINING_DOMAIN + ) + +# Define operator inputs. +r = np.array(0.1, dtype=np.float32) # scalar +t = np.array(0, dtype=np.int64) # scalar +x = np.array([1.2, 2.8], dtype=np.float32) +g = np.array([-0.94, -2.5], dtype=np.float32) +v = np.array([1.7, 3.6], dtype=np.float32) + +# Compute expected outputs of Momentum. +x_new, v_new = apply_nesterov(r, t, x, g, v, + norm_coefficient, alpha, beta) + +# Check results. +expect(node, inputs=[r, t, x, g, v], + outputs=[x_new, v_new], name='test_nesterov_momentum', + opset_imports=[onnx.helper.make_opsetid(AI_ONNX_PREVIEW_TRAINING_DOMAIN, 1)]) +``` + +
+ + diff --git a/_doc/sphinxdoc/source/onnxmd/onnx_docs/Overview.md b/_doc/sphinxdoc/source/onnxmd/onnx_docs/Overview.md new file mode 100644 index 00000000..c5062e76 --- /dev/null +++ b/_doc/sphinxdoc/source/onnxmd/onnx_docs/Overview.md @@ -0,0 +1,22 @@ + + +Overview +======== + +Deep learning with neural networks is accomplished through computation over dataflow graphs. Some frameworks (such as CNTK, Caffe2, Theano, and TensorFlow) make use of static graphs, while others (such as PyTorch and Chainer) use dynamic graphs. However, they all provide interfaces that make it simple for developers to construct computation graphs and runtimes that process the graphs in an optimized way. The graph serves as an Intermediate Representation (IR) that captures the specific intent of the developer's source code, and is conducive for optimization and translation to run on specific devices (CPU, GPU, FPGA, etc.). + +Why a common IR? +---------------- + +Today, each framework has its own proprietary representation of the graph, though they all provide similar capabilities – meaning each framework is a siloed stack of API, graph, and runtime. Furthermore, frameworks are typically optimized for some characteristic, such as fast training, supporting complicated network architectures, inference on mobile devices, etc. It's up to the developer to select a framework that is optimized for one of these characteristics. Additionally, these optimizations may be better suited for particular stages of development. This leads to significant delays between research and production due to the necessity of conversion. + +With the goal of democratizing AI, we envision empowering developers to select the framework that works best for their project, at any stage of development or deployment. The Open Neural Network Exchange (ONNX) format is a common IR to help establish this powerful ecosystem. + +By providing a common representation of the computation graph, ONNX helps developers choose the right framework for their task, allows authors to focus on innovative enhancements, and enables hardware vendors to streamline optimizations for their platforms. + +ONNX is designed to be an open format. We welcome contributions from the community and encourage everyone to adopt ONNX in their ecosystem. + +Why two variants? +----------------- + +The base definition of ONNX includes the necessary support for machine learning algorithms based on neural network technologies. ONNX-ML includes additional types and standard operators commonly used in classical machine learning algorithms. The two variants were created in order to explicitly recognize the desire for some frameworks to go beyond neural network algorithms in a standardized fashion, while allowing other frameworks to support only neural networks. diff --git a/_doc/sphinxdoc/source/onnxmd/onnx_docs/PythonAPIOverview.md b/_doc/sphinxdoc/source/onnxmd/onnx_docs/PythonAPIOverview.md new file mode 100644 index 00000000..16930a34 --- /dev/null +++ b/_doc/sphinxdoc/source/onnxmd/onnx_docs/PythonAPIOverview.md @@ -0,0 +1,318 @@ + + +# Python API Overview + +## Loading an ONNX Model +```python +import onnx + +# onnx_model is an in-memory ModelProto +onnx_model = onnx.load('path/to/the/model.onnx') +``` +Runnable IPython notebooks: +- [load_model.ipynb](/onnx/examples/load_model.ipynb) + +## Loading an ONNX Model with External Data + + +* [Default] If the external data is under the same directory of the model, simply use `onnx.load()` +```python +import onnx + +onnx_model = onnx.load('path/to/the/model.onnx') +``` + +* If the external data is under another directory, use `load_external_data_for_model()` to specify the directory path and load after using `onnx.load()` + +```python +import onnx +from onnx.external_data_helper import load_external_data_for_model + +onnx_model = onnx.load('path/to/the/model.onnx', load_external_data=False) +load_external_data_for_model(onnx_model, 'data/directory/path/') +# Then the onnx_model has loaded the external data from the specific directory +``` + +## Converting an ONNX Model to External Data +```python +from onnx.external_data_helper import convert_model_to_external_data + +# onnx_model is an in-memory ModelProto +onnx_model = ... +convert_model_to_external_data(onnx_model, all_tensors_to_one_file=True, location='filename', size_threshold=1024, convert_attribute=False) +# Then the onnx_model has converted raw data as external data +# Must be followed by save +``` + +## Saving an ONNX Model +```python +import onnx + +# onnx_model is an in-memory ModelProto +onnx_model = ... + +# Save the ONNX model +onnx.save(onnx_model, 'path/to/the/model.onnx') +``` +Runnable IPython notebooks: +- [save_model.ipynb](/onnx/examples/save_model.ipynb) + + +## Converting and Saving an ONNX Model to External Data +```python +import onnx + +# onnx_model is an in-memory ModelProto +onnx_model = ... +onnx.save_model(onnx_model, 'path/to/save/the/model.onnx', save_as_external_data=True, all_tensors_to_one_file=True, location='filename', size_threshold=1024, convert_attribute=False) +# Then the onnx_model has converted raw data as external data and saved to specific directory +``` + + +## Manipulating TensorProto and Numpy Array +```python +import numpy +import onnx +from onnx import numpy_helper + +# Preprocessing: create a Numpy array +numpy_array = numpy.array([[1.0, 2.0, 3.0], [4.0, 5.0, 6.0]], dtype=float) +print('Original Numpy array:\n{}\n'.format(numpy_array)) + +# Convert the Numpy array to a TensorProto +tensor = numpy_helper.from_array(numpy_array) +print('TensorProto:\n{}'.format(tensor)) + +# Convert the TensorProto to a Numpy array +new_array = numpy_helper.to_array(tensor) +print('After round trip, Numpy array:\n{}\n'.format(new_array)) + +# Save the TensorProto +with open('tensor.pb', 'wb') as f: + f.write(tensor.SerializeToString()) + +# Load a TensorProto +new_tensor = onnx.TensorProto() +with open('tensor.pb', 'rb') as f: + new_tensor.ParseFromString(f.read()) +print('After saving and loading, new TensorProto:\n{}'.format(new_tensor)) +``` +Runnable IPython notebooks: +- [np_array_tensorproto.ipynb](/onnx/examples/np_array_tensorproto.ipynb) + +## Creating an ONNX Model Using Helper Functions +```python +import onnx +from onnx import helper +from onnx import AttributeProto, TensorProto, GraphProto + + +# The protobuf definition can be found here: +# https://github.com/onnx/onnx/blob/master/onnx/onnx.proto + + +# Create one input (ValueInfoProto) +X = helper.make_tensor_value_info('X', TensorProto.FLOAT, [3, 2]) +pads = helper.make_tensor_value_info('pads', TensorProto.FLOAT, [1, 4]) + +value = helper.make_tensor_value_info('value', AttributeProto.FLOAT, [1]) + + +# Create one output (ValueInfoProto) +Y = helper.make_tensor_value_info('Y', TensorProto.FLOAT, [3, 4]) + +# Create a node (NodeProto) - This is based on Pad-11 +node_def = helper.make_node( + 'Pad', # name + ['X', 'pads', 'value'], # inputs + ['Y'], # outputs + mode='constant', # attributes +) + +# Create the graph (GraphProto) +graph_def = helper.make_graph( + [node_def], # nodes + 'test-model', # name + [X, pads, value], # inputs + [Y], # outputs +) + +# Create the model (ModelProto) +model_def = helper.make_model(graph_def, producer_name='onnx-example') + +print('The model is:\n{}'.format(model_def)) +onnx.checker.check_model(model_def) +print('The model is checked!') +``` +Runnable IPython notebooks: +- [make_model.ipynb](/onnx/examples/make_model.ipynb) +- [Protobufs.ipynb](/onnx/examples/Protobufs.ipynb) + +## Checking an ONNX Model +```python +import onnx + +# Preprocessing: load the ONNX model +model_path = 'path/to/the/model.onnx' +onnx_model = onnx.load(model_path) + +print('The model is:\n{}'.format(onnx_model)) + +# Check the model +try: + onnx.checker.check_model(onnx_model) +except onnx.checker.ValidationError as e: + print('The model is invalid: %s' % e) +else: + print('The model is valid!') +``` +Runnable IPython notebooks: +- [check_model.ipynb](/onnx/examples/check_model.ipynb) + +### Checking a Large ONNX Model >2GB +Current checker supports checking models with external data, but for those models larger than 2GB, please use the model path for onnx.checker and the external data needs to be under the same directory. + +```python +import onnx + +onnx.checker.check_model('path/to/the/model.onnx') +# onnx.checker.check_model(loaded_onnx_model) will fail if given >2GB model +``` + +## Running Shape Inference on an ONNX Model +```python +import onnx +from onnx import helper, shape_inference +from onnx import TensorProto + + +# Preprocessing: create a model with two nodes, Y's shape is unknown +node1 = helper.make_node('Transpose', ['X'], ['Y'], perm=[1, 0, 2]) +node2 = helper.make_node('Transpose', ['Y'], ['Z'], perm=[1, 0, 2]) + +graph = helper.make_graph( + [node1, node2], + 'two-transposes', + [helper.make_tensor_value_info('X', TensorProto.FLOAT, (2, 3, 4))], + [helper.make_tensor_value_info('Z', TensorProto.FLOAT, (2, 3, 4))], +) + +original_model = helper.make_model(graph, producer_name='onnx-examples') + +# Check the model and print Y's shape information +onnx.checker.check_model(original_model) +print('Before shape inference, the shape info of Y is:\n{}'.format(original_model.graph.value_info)) + +# Apply shape inference on the model +inferred_model = shape_inference.infer_shapes(original_model) + +# Check the model and print Y's shape information +onnx.checker.check_model(inferred_model) +print('After shape inference, the shape info of Y is:\n{}'.format(inferred_model.graph.value_info)) +``` +Runnable IPython notebooks: +- [shape_inference.ipynb](/onnx/examples/shape_inference.ipynb) + +### Shape inference a Large ONNX Model >2GB +Current shape_inference supports models with external data, but for those models larger than 2GB, please use the model path for onnx.shape_inference.infer_shapes_path and the external data needs to be under the same directory. You can specify the output path for saving the inferred model; otherwise, the default output path is same as the original model path. + +```python +import onnx + +# output the inferred model to the original model path +onnx.shape_inference.infer_shapes_path('path/to/the/model.onnx') + +# output the inferred model to the specified model path +onnx.shape_inference.infer_shapes_path('path/to/the/model.onnx', 'output/inferred/model.onnx') + +# inferred_model = onnx.shape_inference.infer_shapes(loaded_onnx_model) will fail if given >2GB model +``` + +## Converting Version of an ONNX Model within Default Domain (""/"ai.onnx") +```python +import onnx +from onnx import version_converter, helper + +# Preprocessing: load the model to be converted. +model_path = 'path/to/the/model.onnx' +original_model = onnx.load(model_path) + +print('The model before conversion:\n{}'.format(original_model)) + +# A full list of supported adapters can be found here: +# https://github.com/onnx/onnx/blob/master/onnx/version_converter.py#L21 +# Apply the version conversion on the original model +converted_model = version_converter.convert_version(original_model, ) + +print('The model after conversion:\n{}'.format(converted_model)) +``` + +## Utility Functions +### Extracting Sub-model with Inputs Outputs Tensor Names + +Function `extract_model()` extracts sub-model from an ONNX model. +The sub-model is defined by the names of the input and output tensors *exactly*. + +```python +import onnx + +input_path = 'path/to/the/original/model.onnx' +output_path = 'path/to/save/the/extracted/model.onnx' +input_names = ['input_0', 'input_1', 'input_2'] +output_names = ['output_0', 'output_1'] + +onnx.utils.extract_model(input_path, output_path, input_names, output_names) +``` + +Note: For control-flow operators, e.g. If and Loop, the _boundary of sub-model_, +which is defined by the input and output tensors, should not _cut through_ the +subgraph that is connected to the _main graph_ as attributes of these operators. + +## Tools +### Updating Model's Inputs Outputs Dimension Sizes with Variable Length +Function `update_inputs_outputs_dims` updates the dimension of the inputs and outputs of the model, +to the provided values in the parameter. You could provide both static and dynamic dimension size, +by using dim_param. For more information on static and dynamic dimension size, checkout [Tensor Shapes](IR.md#tensor-shapes). + +The function runs model checker after the input/output sizes are updated. +```python +import onnx +from onnx.tools import update_model_dims + +model = onnx.load('path/to/the/model.onnx') +# Here both 'seq', 'batch' and -1 are dynamic using dim_param. +variable_length_model = update_model_dims.update_inputs_outputs_dims(model, {'input_name': ['seq', 'batch', 3, -1]}, {'output_name': ['seq', 'batch', 1, -1]}) +``` + +## ONNX Parser + +Functions `onnx.parser.parse_model` and `onnx.parser.parse_graph` can be used to create an ONNX model +or graph from a textual representation as shown below. See [Language Syntax](Syntax.md) for more details +about the language syntax. + +```python +input = ''' + agraph (float[N, 128] X, float[128,10] W, float[10] B) => (float[N] C) + { + T = MatMul(X, W) + S = Add(T, B) + C = Softmax(S) + } +''' +graph = onnx.parser.parse_graph(input) + +input = ''' + < + ir_version: 7, + opset_import: ["" : 10] + > + agraph (float[N, 128] X, float[128,10] W, float[10] B) => (float[N] C) + { + T = MatMul(X, W) + S = Add(T, B) + C = Softmax(S) + } +''' +model = onnx.parser.parse_model(input) + +``` diff --git a/_doc/sphinxdoc/source/onnxmd/onnx_docs/README.txt b/_doc/sphinxdoc/source/onnxmd/onnx_docs/README.txt new file mode 100644 index 00000000..d9045faf --- /dev/null +++ b/_doc/sphinxdoc/source/onnxmd/onnx_docs/README.txt @@ -0,0 +1,2 @@ +Copied from +https://github.com/onnx/onnx/tree/master/docs \ No newline at end of file diff --git a/_doc/sphinxdoc/source/onnxmd/onnx_docs/Relicensing.md b/_doc/sphinxdoc/source/onnxmd/onnx_docs/Relicensing.md new file mode 100644 index 00000000..3a65903f --- /dev/null +++ b/_doc/sphinxdoc/source/onnxmd/onnx_docs/Relicensing.md @@ -0,0 +1,11 @@ + + +# Relicensing MIT to Apache-2.0 + +The following copyright holders agree that all of their contributions originally submitted to this project under the MIT license are hereby relicensed to Apache-2.0, and are submitted pursuant to the Developer Certificate of Origin, version 1.1: + +Intel Corporation +Microsoft Corporation +NVIDIA Corporation +IBM Corporation +Facebook Inc. diff --git a/_doc/sphinxdoc/source/onnxmd/onnx_docs/ShapeInference.md b/_doc/sphinxdoc/source/onnxmd/onnx_docs/ShapeInference.md new file mode 100644 index 00000000..04f279b2 --- /dev/null +++ b/_doc/sphinxdoc/source/onnxmd/onnx_docs/ShapeInference.md @@ -0,0 +1,73 @@ + + +# ONNX Shape Inference + +ONNX provides an optional implementation of shape inference on ONNX +graphs. This implementation covers each of the core operators, as well +as provides an interface for extensibility. Therefore, you may choose +to invoke the existing shape inference functionality on your graphs, +or to define shape inference implementations to go along with your +custom operators (or both!). Shape inference functions are stored as a +member of the OpSchema objects. + +In ONNX 1.10 release, symbol generation and propagation along with shape +data propagation was added to ONNX graph level shape inference. +Detailed proposal is [here](proposals/SymbolicShapeInfProposal.md) + +## Invoking Shape Inference + +Shape inference can be invoked either via C++ or Python. The Python +API is described, with example, +[here](PythonAPIOverview.md#running-shape-inference-on-an-onnx-model). + +The C++ API consists of a single function + +``` +shape_inference::InferShapes( + ModelProto& m, + const ISchemaRegistry* schema_registry); +``` + +The first argument is a `ModelProto` to perform shape inference on, +which is annotated in-place with shape information. The second +argument is optional. + +## Implementing Shape Inference For Custom Operators + +You can add a shape inference function to your operator's Schema with + +``` +OpSchema& Opschema::TypeAndShapeInferenceFunction(InferenceFunction inferenceFunction); +``` + +`InferenceFunction` is defined in +[shape_inference.h](/onnx/defs/shape_inference.h), along with the core +interface struct `InferenceContext` and an assortment of helper +methods. `InferenceContext` is the core struct which is provided to +your inference function. It allows accessing information about the +operator's inputs, and also allows writing out inferred information. + +To see numerous examples, search for occurrences of +`TypeAndShapeInferenceFunction` in the codebase. One that is +relatively involved is the implementation for `Concat`, in +onnx/defs/tensor/defs.cc. + +## Limitations + +Shape inference is not guaranteed to be complete. In particular, some +dynamic behaviors block the flow of shape inference, for example a +Reshape to a dynamically-provide shape. Also, all operators are not +required to have a shape inference implementation. + +Shape inference works only with constants and simple variables. It +does not support arithmetic expressions containing variables. For +example, `Concat` on tensors of shapes `(5, 2)` and `(7, 2)` can be +inferred to produce a result of shape `(12, 2)`, but `Concat` on +tensors of shapes `(5, 2)` and `(N, 2)` will simply produce `(M, 2)`, +rather than containing a representation of `N+5`. Note that differing +unknown symbolic values will be propagated, so the `M` here represents +an unknown quantity that is the same as other occurrences of `M`. + +These limitations are a property of the current implementation, not +fundamental constraints - if you are in need of something more +advanced, do let us know! diff --git a/_doc/sphinxdoc/source/onnxmd/onnx_docs/Syntax.md b/_doc/sphinxdoc/source/onnxmd/onnx_docs/Syntax.md new file mode 100644 index 00000000..f7183840 --- /dev/null +++ b/_doc/sphinxdoc/source/onnxmd/onnx_docs/Syntax.md @@ -0,0 +1,74 @@ + + +Overview +======== + +This document describes a textual syntax for ONNX models, which is currently an experimental feature. +The syntax enables a compact and readable representation of ONNX models. It is motivated by a couple +of use-cases. One is to enable compact description of test-cases and its use in CI (both in the ONNX +repo as well as in other dependent repos such as ONNX-MLIR). The second is to help simplify the +definition of ONNX functions. Several of the existing function-definitions are verbose, and the +use of this syntax will lead to more compact, readable, and easier-to-maintain function definitions. +Efficient representation and efficient parsing of very large tensor-constants is *not* a goal. +Alternative methods should be used for that. + +The API +------- + +The key parser methods are the ```OnnxParser::Parse``` methods, used as below. + +```cpp + const char* code = R"ONNX( +< + ir_version: 7, + opset_import: [ "" : 10 ] +> +agraph (float[N, 128] X, float[128,10] W, float[10] B) => (float[N] C) +{ + T = MatMul(X, W) + S = Add(T, B) + C = Softmax(S) +} +)ONNX"; + + ModelProto model; + OnnxParser::Parse(model, code); + + checker::check_model(model); +``` + +See the [test-cases](../onnx/test/cpp/parser_test.cc) for more examples illustrating the API and syntax. + +The Syntax +---------- + +The grammar below describes the syntax: + +``` + id-list ::= id (',' id)* + tensor-dim ::= '?' | id | int-constant + tensor-dims ::= tensor-dim (',' tensor-dim)* + tensor-type ::= prim-type | prim-type '[' ']' | prim-type '[' tensor-dims ']' + type ::= tensor-type + value-info ::= type id + value-infos ::= value-info (',' value-info)* + value-info-list ::= '(' value-infos? ')' + prim-constants ::= prim-constant (',' prim-constant)* + tensor-constant ::= tensor-type '{' prim-constants '}' + single-attr-value ::= tensor-constant | graph | prim-constant + attr-value-list ::= '[' single-attr-value (',' single-attr-value)* ']' + attr-value ::= single-attr-value | attr-value-list + attr ::= id '=' attr-value + attr-list ::= '<' attr (',' attr)* '>' + node ::= id-list? '=' qualified-id attr-list? '(' id-list? ')' + | id-list? '=' qualified-id '(' id-list? ')' attr-list + node-list ::= '{' node* '}' + graph ::= id value-info-list '=>' value-info-list node-list + other-data ::= id ':' value + other-data-list ::= '<' other-data (',' other-data)* '>' + fun-attr-list ::= '<' id-list '>' + fun-input-list ::= '(' id-list ')' + fun-output-list ::= '(' id-list ')' + function ::= other-data-list? id fun-attr-list? fun-input-list '=>' fun-output-list node-list + model ::= other-data-list? graph function* +``` \ No newline at end of file diff --git a/_doc/sphinxdoc/source/onnxmd/onnx_docs/TestCoverage-ml.md b/_doc/sphinxdoc/source/onnxmd/onnx_docs/TestCoverage-ml.md new file mode 100644 index 00000000..1f4e2e00 --- /dev/null +++ b/_doc/sphinxdoc/source/onnxmd/onnx_docs/TestCoverage-ml.md @@ -0,0 +1,87 @@ + +# Test Coverage Report (ONNX-ML Operators) +## Outlines +* [Node Test Coverage](#node-test-coverage) +* [Model Test Coverage](#model-test-coverage) +* [Overall Test Coverage](#overall-test-coverage) +# Node Test Coverage +## Summary +Node tests have covered 0/18 (0.00%, 0 generators excluded) common operators. + +Node tests have covered 0/0 (N/A) experimental operators. + +* [Covered Common Operators](#covered-common-operators) +* [No Cover Common Operators](#no-cover-common-operators) +* [Covered Experimental Operators](#covered-experimental-operators) +* [No Cover Experimental Operators](#no-cover-experimental-operators) + +## 💚Covered Common Operators +
+ +## 💔No Cover Common Operators +### ArrayFeatureExtractor (call for test cases) + + +### Binarizer (call for test cases) + + +### CastMap (call for test cases) + + +### CategoryMapper (call for test cases) + + +### DictVectorizer (call for test cases) + + +### FeatureVectorizer (call for test cases) + + +### Imputer (call for test cases) + + +### LabelEncoder (call for test cases) + + +### LinearClassifier (call for test cases) + + +### LinearRegressor (call for test cases) + + +### Normalizer (call for test cases) + + +### OneHotEncoder (call for test cases) + + +### SVMClassifier (call for test cases) + + +### SVMRegressor (call for test cases) + + +### Scaler (call for test cases) + + +### TreeEnsembleClassifier (call for test cases) + + +### TreeEnsembleRegressor (call for test cases) + + +### ZipMap (call for test cases) + + +
+ +## 💚Covered Experimental Operators +
+ +## 💔No Cover Experimental Operators +
+ +# Model Test Coverage +No model tests present for selected domain +# Overall Test Coverage +## To be filled. diff --git a/_doc/sphinxdoc/source/onnxmd/onnx_docs/TestCoverage.md b/_doc/sphinxdoc/source/onnxmd/onnx_docs/TestCoverage.md new file mode 100644 index 00000000..025173d1 --- /dev/null +++ b/_doc/sphinxdoc/source/onnxmd/onnx_docs/TestCoverage.md @@ -0,0 +1,16334 @@ + +# Test Coverage Report (ONNX Core Operators) +## Outlines +* [Node Test Coverage](#node-test-coverage) +* [Model Test Coverage](#model-test-coverage) +* [Overall Test Coverage](#overall-test-coverage) +# Node Test Coverage +## Summary +Node tests have covered 154/169 (91.12%, 5 generators excluded) common operators. + +Node tests have covered 0/0 (N/A) experimental operators. + +* [Covered Common Operators](#covered-common-operators) +* [No Cover Common Operators](#no-cover-common-operators) +* [Covered Experimental Operators](#covered-experimental-operators) +* [No Cover Experimental Operators](#no-cover-experimental-operators) + +## 💚Covered Common Operators +### Abs +There are 1 test cases, listed as following: +
+abs + +```python +node = onnx.helper.make_node( + 'Abs', + inputs=['x'], + outputs=['y'], +) +x = np.random.randn(3, 4, 5).astype(np.float32) +y = abs(x) + +expect(node, inputs=[x], outputs=[y], + name='test_abs') +``` + +
+ + +### Acos +There are 1 test cases, listed as following: +
+acos + +```python +node = onnx.helper.make_node( + 'Acos', + inputs=['x'], + outputs=['y'], +) + +x = np.array([-0.5, 0, 0.5]).astype(np.float32) +y = np.arccos(x) +expect(node, inputs=[x], outputs=[y], + name='test_acos_example') + +x = np.random.rand(3, 4, 5).astype(np.float32) +y = np.arccos(x) +expect(node, inputs=[x], outputs=[y], + name='test_acos') +``` + +
+ + +### Acosh +There are 1 test cases, listed as following: +
+acosh + +```python +node = onnx.helper.make_node( + 'Acosh', + inputs=['x'], + outputs=['y'], +) + +x = np.array([10, np.e, 1]).astype(np.float32) +y = np.arccosh(x) # expected output [2.99322295, 1.65745449, 0.] +expect(node, inputs=[x], outputs=[y], + name='test_acosh_example') + +x = np.random.uniform(1.0, 10.0, (3, 4, 5)).astype(np.float32) +y = np.arccosh(x) +expect(node, inputs=[x], outputs=[y], + name='test_acosh') +``` + +
+ + +### Adagrad +There are 2 test cases, listed as following: +
+adagrad + +```python +# Define operator attributes. +norm_coefficient = 0.001 +epsilon = 1e-5 +decay_factor = 0.1 + +# Create operator. +node = onnx.helper.make_node('Adagrad', + inputs=['R', 'T', 'X', 'G', 'H'], + outputs=['X_new', 'H_new'], + norm_coefficient=norm_coefficient, + epsilon=epsilon, + decay_factor=decay_factor, + domain=AI_ONNX_PREVIEW_TRAINING_DOMAIN + ) + +# Define operator inputs. +r = np.array(0.1, dtype=np.float32) # scalar +t = np.array(0, dtype=np.int64) # scalar +x = np.array([1.0], dtype=np.float32) +g = np.array([-1.0], dtype=np.float32) +h = np.array([2.0], dtype=np.float32) + +# Compute expected outputs of Adagrad. +x_new, h_new = apply_adagrad(r, t, x, g, h, + norm_coefficient, epsilon, decay_factor) + +# Check results. +expect(node, inputs=[r, t, x, g, h], + outputs=[x_new, h_new], name='test_adagrad', + opset_imports=[onnx.helper.make_opsetid(AI_ONNX_PREVIEW_TRAINING_DOMAIN, 1)]) +``` + +
+
+adagrad_multiple + +```python +# Define operator attributes. +norm_coefficient = 0.001 +epsilon = 1e-5 +decay_factor = 0.1 + +node = onnx.helper.make_node('Adagrad', + inputs=['R', 'T', 'X1', 'X2', + 'G1', 'G2', 'H1', 'H2'], + outputs=['X1_new', 'X2_new', + 'H1_new', 'H2_new'], + norm_coefficient=norm_coefficient, + epsilon=epsilon, + decay_factor=decay_factor, + domain=AI_ONNX_PREVIEW_TRAINING_DOMAIN + ) + +# Define operator inputs. +r = np.array(0.1, dtype=np.float32) # scalar +t = np.array(0, dtype=np.int64) # scalar + +x1 = np.array([1.0], dtype=np.float32) +g1 = np.array([-1.0], dtype=np.float32) +h1 = np.array([2.0], dtype=np.float32) + +x2 = np.array([1.0, 2.0], dtype=np.float32) +g2 = np.array([-1.0, -3.0], dtype=np.float32) +h2 = np.array([4.0, 1.0], dtype=np.float32) + +# Compute expected outputs of Adagrad. +x1_new, h1_new = apply_adagrad(r, t, x1, g1, h1, + norm_coefficient, epsilon, decay_factor) +x2_new, h2_new = apply_adagrad(r, t, x2, g2, h2, + norm_coefficient, epsilon, decay_factor) + +# Check results. +expect(node, inputs=[r, t, x1, x2, g1, g2, h1, h2], + outputs=[x1_new, x2_new, h1_new, h2_new], name='test_adagrad_multiple', + opset_imports=[onnx.helper.make_opsetid(AI_ONNX_PREVIEW_TRAINING_DOMAIN, 1)]) +``` + +
+ + +### Adam +There are 2 test cases, listed as following: +
+adam + +```python +# Define operator attributes. +norm_coefficient = 0.001 +alpha = 0.95 +beta = 0.1 +epsilon = 1e-7 + +# Create operator. +node = onnx.helper.make_node('Adam', + inputs=['R', 'T', 'X', 'G', 'V', 'H'], + outputs=['X_new', 'V_new', 'H_new'], + norm_coefficient=norm_coefficient, + alpha=alpha, + beta=beta, + epsilon=epsilon, + domain=AI_ONNX_PREVIEW_TRAINING_DOMAIN + ) + +# Define operator inputs. +r = np.array(0.1, dtype=np.float32) # scalar +t = np.array(0, dtype=np.int64) # scalar +x = np.array([1.2, 2.8], dtype=np.float32) +g = np.array([-0.94, -2.5], dtype=np.float32) +v = np.array([1.7, 3.6], dtype=np.float32) +h = np.array([0.1, 0.1], dtype=np.float32) + +# Compute expected outputs of Adam. +x_new, v_new, h_new = apply_adam(r, t, x, g, v, h, + norm_coefficient, 0.0, alpha, beta, + epsilon) + +# Check results. +expect(node, inputs=[r, t, x, g, v, h], + outputs=[x_new, v_new, h_new], name='test_adam', + opset_imports=[onnx.helper.make_opsetid(AI_ONNX_PREVIEW_TRAINING_DOMAIN, 1)]) +``` + +
+
+adam_multiple + +```python +# Define operator attributes. +norm_coefficient = 0.001 +alpha = 0.95 +beta = 0.85 +epsilon = 1e-2 + +node = onnx.helper.make_node('Adam', + inputs=['R', 'T', 'X1', 'X2', + 'G1', 'G2', 'V1', 'V2', + 'H1', 'H2'], + outputs=['X1_new', 'X2_new', + 'V1_new', 'V2_new', + 'H1_new', 'H2_new'], + norm_coefficient=norm_coefficient, + alpha=alpha, + beta=beta, + domain=AI_ONNX_PREVIEW_TRAINING_DOMAIN + ) + +# Define operator inputs. +r = np.array(0.1, dtype=np.float32) # scalar +t = np.array(0, dtype=np.int64) # scalar + +x1 = np.array([1.0], dtype=np.float32) +g1 = np.array([-1.0], dtype=np.float32) +v1 = np.array([2.0], dtype=np.float32) +h1 = np.array([0.5], dtype=np.float32) + +x2 = np.array([1.0, 2.0], dtype=np.float32) +g2 = np.array([-1.0, -3.0], dtype=np.float32) +v2 = np.array([4.0, 1.0], dtype=np.float32) +h2 = np.array([1.0, 10.0], dtype=np.float32) + +# Compute expected outputs of Adam. +x1_new, v1_new, h1_new = apply_adam(r, t, x1, g1, v1, h1, + norm_coefficient, 0.0, alpha, beta, + epsilon) +x2_new, v2_new, h2_new = apply_adam(r, t, x2, g2, v2, h2, + norm_coefficient, 0.0, alpha, beta, + epsilon) + +# Check results. +expect(node, inputs=[r, t, x1, x2, g1, g2, v1, v2, h1, h2], + outputs=[x1_new, x2_new, v1_new, v2_new, h1_new, h2_new], + name='test_adam_multiple', + opset_imports=[onnx.helper.make_opsetid(AI_ONNX_PREVIEW_TRAINING_DOMAIN, 1)]) +``` + +
+ + +### Add +There are 3 test cases, listed as following: +
+add + +```python +node = onnx.helper.make_node( + 'Add', + inputs=['x', 'y'], + outputs=['sum'], +) + +x = np.random.randn(3, 4, 5).astype(np.float32) +y = np.random.randn(3, 4, 5).astype(np.float32) +expect(node, inputs=[x, y], outputs=[x + y], + name='test_add') +``` + +
+
+add_broadcast + +```python +node = onnx.helper.make_node( + 'Add', + inputs=['x', 'y'], + outputs=['sum'], +) + +x = np.random.randn(3, 4, 5).astype(np.float32) +y = np.random.randn(5).astype(np.float32) +expect(node, inputs=[x, y], outputs=[x + y], + name='test_add_bcast') +``` + +
+
+add_uint8 + +```python +node = onnx.helper.make_node( + 'Add', + inputs=['x', 'y'], + outputs=['sum'], +) + +x = np.random.randint(24, size=(3, 4, 5), dtype=np.uint8) +y = np.random.randint(24, size=(3, 4, 5), dtype=np.uint8) +expect(node, inputs=[x, y], outputs=[x + y], + name='test_add_uint8') +``` + +
+ + +### And +There are 2 test cases, listed as following: +
+and + +```python +node = onnx.helper.make_node( + 'And', + inputs=['x', 'y'], + outputs=['and'], +) + +# 2d +x = (np.random.randn(3, 4) > 0).astype(bool) +y = (np.random.randn(3, 4) > 0).astype(bool) +z = np.logical_and(x, y) +expect(node, inputs=[x, y], outputs=[z], + name='test_and2d') + +# 3d +x = (np.random.randn(3, 4, 5) > 0).astype(bool) +y = (np.random.randn(3, 4, 5) > 0).astype(bool) +z = np.logical_and(x, y) +expect(node, inputs=[x, y], outputs=[z], + name='test_and3d') + +# 4d +x = (np.random.randn(3, 4, 5, 6) > 0).astype(bool) +y = (np.random.randn(3, 4, 5, 6) > 0).astype(bool) +z = np.logical_and(x, y) +expect(node, inputs=[x, y], outputs=[z], + name='test_and4d') +``` + +
+
+and_broadcast + +```python +node = onnx.helper.make_node( + 'And', + inputs=['x', 'y'], + outputs=['and'], +) + +# 3d vs 1d +x = (np.random.randn(3, 4, 5) > 0).astype(bool) +y = (np.random.randn(5) > 0).astype(bool) +z = np.logical_and(x, y) +expect(node, inputs=[x, y], outputs=[z], + name='test_and_bcast3v1d') + +# 3d vs 2d +x = (np.random.randn(3, 4, 5) > 0).astype(bool) +y = (np.random.randn(4, 5) > 0).astype(bool) +z = np.logical_and(x, y) +expect(node, inputs=[x, y], outputs=[z], + name='test_and_bcast3v2d') + +# 4d vs 2d +x = (np.random.randn(3, 4, 5, 6) > 0).astype(bool) +y = (np.random.randn(5, 6) > 0).astype(bool) +z = np.logical_and(x, y) +expect(node, inputs=[x, y], outputs=[z], + name='test_and_bcast4v2d') + +# 4d vs 3d +x = (np.random.randn(3, 4, 5, 6) > 0).astype(bool) +y = (np.random.randn(4, 5, 6) > 0).astype(bool) +z = np.logical_and(x, y) +expect(node, inputs=[x, y], outputs=[z], + name='test_and_bcast4v3d') + +# 4d vs 4d +x = (np.random.randn(1, 4, 1, 6) > 0).astype(bool) +y = (np.random.randn(3, 1, 5, 6) > 0).astype(bool) +z = np.logical_and(x, y) +expect(node, inputs=[x, y], outputs=[z], + name='test_and_bcast4v4d') +``` + +
+ + +### ArgMax +There are 8 test cases, listed as following: +
+default_axes_keepdims + +```python +data = np.array([[2, 1], [3, 10]], dtype=np.float32) +keepdims = 1 +node = onnx.helper.make_node( + 'ArgMax', + inputs=['data'], + outputs=['result'], + keepdims=keepdims) + +# result: [[1, 1]] +result = argmax_use_numpy(data, keepdims=keepdims) +expect(node, inputs=[data], outputs=[result], name='test_argmax_default_axis_example') + +data = np.random.uniform(-10, 10, [2, 3, 4]).astype(np.float32) +# result's shape: [1, 3, 4] +result = argmax_use_numpy(data, keepdims=keepdims) +expect(node, inputs=[data], outputs=[result], name='test_argmax_default_axis_random') +``` + +
+
+default_axes_keepdims_select_last_index + +```python +data = np.array([[2, 2], [3, 10]], dtype=np.float32) +keepdims = 1 +node = onnx.helper.make_node( + 'ArgMax', + inputs=['data'], + outputs=['result'], + keepdims=keepdims, + select_last_index=True) + +# result: [[1, 1]] +result = argmax_use_numpy_select_last_index(data, keepdims=keepdims) +expect(node, inputs=[data], outputs=[result], name='test_argmax_default_axis_example_select_last_index') + +data = np.random.uniform(-10, 10, [2, 3, 4]).astype(np.float32) +# result's shape: [1, 3, 4] +result = argmax_use_numpy_select_last_index(data, keepdims=keepdims) +expect(node, inputs=[data], outputs=[result], name='test_argmax_default_axis_random_select_last_index') +``` + +
+
+keepdims + +```python +data = np.array([[2, 1], [3, 10]], dtype=np.float32) +axis = 1 +keepdims = 1 +node = onnx.helper.make_node( + 'ArgMax', + inputs=['data'], + outputs=['result'], + axis=axis, + keepdims=keepdims) +# result: [[0], [1]] +result = argmax_use_numpy(data, axis=axis, keepdims=keepdims) +expect(node, inputs=[data], outputs=[result], name='test_argmax_keepdims_example') + +data = np.random.uniform(-10, 10, [2, 3, 4]).astype(np.float32) +# result's shape: [2, 1, 4] +result = argmax_use_numpy(data, axis=axis, keepdims=keepdims) +expect(node, inputs=[data], outputs=[result], name='test_argmax_keepdims_random') +``` + +
+
+keepdims_select_last_index + +```python +data = np.array([[2, 2], [3, 10]], dtype=np.float32) +axis = 1 +keepdims = 1 +node = onnx.helper.make_node( + 'ArgMax', + inputs=['data'], + outputs=['result'], + axis=axis, + keepdims=keepdims, + select_last_index=True) +# result: [[1], [1]] +result = argmax_use_numpy_select_last_index(data, axis=axis, keepdims=keepdims) +expect(node, inputs=[data], outputs=[result], name='test_argmax_keepdims_example_select_last_index') + +data = np.random.uniform(-10, 10, [2, 3, 4]).astype(np.float32) +# result's shape: [2, 1, 4] +result = argmax_use_numpy_select_last_index(data, axis=axis, keepdims=keepdims) +expect(node, inputs=[data], outputs=[result], name='test_argmax_keepdims_random_select_last_index') +``` + +
+
+negative_axis_keepdims + +```python +data = np.array([[2, 1], [3, 10]], dtype=np.float32) +axis = -1 +keepdims = 1 +node = onnx.helper.make_node( + 'ArgMax', + inputs=['data'], + outputs=['result'], + axis=axis, + keepdims=keepdims) +# result: [[0], [1]] +result = argmax_use_numpy(data, axis=axis, keepdims=keepdims) +expect(node, inputs=[data], outputs=[result], name='test_argmax_negative_axis_keepdims_example') + +data = np.random.uniform(-10, 10, [2, 3, 4]).astype(np.float32) +# result's shape: [2, 3, 1] +result = argmax_use_numpy(data, axis=axis, keepdims=keepdims) +expect(node, inputs=[data], outputs=[result], name='test_argmax_negative_axis_keepdims_random') +``` + +
+
+negative_axis_keepdims_select_last_index + +```python +data = np.array([[2, 2], [3, 10]], dtype=np.float32) +axis = -1 +keepdims = 1 +node = onnx.helper.make_node( + 'ArgMax', + inputs=['data'], + outputs=['result'], + axis=axis, + keepdims=keepdims, + select_last_index=True) +# result: [[1], [1]] +result = argmax_use_numpy_select_last_index(data, axis=axis, keepdims=keepdims) +expect(node, inputs=[data], outputs=[result], name='test_argmax_negative_axis_keepdims_example_select_last_index') + +data = np.random.uniform(-10, 10, [2, 3, 4]).astype(np.float32) +# result's shape: [2, 3, 1] +result = argmax_use_numpy_select_last_index(data, axis=axis, keepdims=keepdims) +expect(node, inputs=[data], outputs=[result], name='test_argmax_negative_axis_keepdims_random_select_last_index') +``` + +
+
+no_keepdims + +```python +data = np.array([[2, 1], [3, 10]], dtype=np.float32) +axis = 1 +keepdims = 0 +node = onnx.helper.make_node( + 'ArgMax', + inputs=['data'], + outputs=['result'], + axis=axis, + keepdims=keepdims) +# result: [0, 1] +result = argmax_use_numpy(data, axis=axis, keepdims=keepdims) +expect(node, inputs=[data], outputs=[result], name='test_argmax_no_keepdims_example') + +data = np.random.uniform(-10, 10, [2, 3, 4]).astype(np.float32) +# result's shape: [2, 4] +result = argmax_use_numpy(data, axis=axis, keepdims=keepdims) +expect(node, inputs=[data], outputs=[result], name='test_argmax_no_keepdims_random') +``` + +
+
+no_keepdims_select_last_index + +```python +data = np.array([[2, 2], [3, 10]], dtype=np.float32) +axis = 1 +keepdims = 0 +node = onnx.helper.make_node( + 'ArgMax', + inputs=['data'], + outputs=['result'], + axis=axis, + keepdims=keepdims, + select_last_index=True) +# result: [1, 1] +result = argmax_use_numpy_select_last_index(data, axis=axis, keepdims=keepdims) +expect(node, inputs=[data], outputs=[result], name='test_argmax_no_keepdims_example_select_last_index') + +data = np.random.uniform(-10, 10, [2, 3, 4]).astype(np.float32) +# result's shape: [2, 4] +result = argmax_use_numpy_select_last_index(data, axis=axis, keepdims=keepdims) +expect(node, inputs=[data], outputs=[result], name='test_argmax_no_keepdims_random_select_last_index') +``` + +
+ + +### ArgMin +There are 8 test cases, listed as following: +
+default_axes_keepdims + +```python +data = np.array([[2, 1], [3, 10]], dtype=np.float32) +keepdims = 1 +node = onnx.helper.make_node( + 'ArgMin', + inputs=['data'], + outputs=['result'], + keepdims=keepdims) + +# The content of result is : [[0], [0]] +result = argmin_use_numpy(data, keepdims=keepdims) +expect(node, inputs=[data], outputs=[result], name='test_argmin_default_axis_example') + +data = np.random.uniform(-10, 10, [2, 3, 4]).astype(np.float32) +# result's shape: [1, 3, 4] +result = argmin_use_numpy(data, keepdims=keepdims) +expect(node, inputs=[data], outputs=[result], name='test_argmin_default_axis_random') +``` + +
+
+default_axes_keepdims_select_last_index + +```python +data = np.array([[2, 2], [3, 10]], dtype=np.float32) +keepdims = 1 +node = onnx.helper.make_node( + 'ArgMin', + inputs=['data'], + outputs=['result'], + keepdims=keepdims, + select_last_index=True) + +# result: [[0, 0]] +result = argmin_use_numpy_select_last_index(data, keepdims=keepdims) +expect(node, inputs=[data], outputs=[result], name='test_argmin_default_axis_example_select_last_index') + +data = np.random.uniform(-10, 10, [2, 3, 4]).astype(np.float32) +# result's shape: [1, 3, 4] +result = argmin_use_numpy_select_last_index(data, keepdims=keepdims) +expect(node, inputs=[data], outputs=[result], name='test_argmin_default_axis_random_select_last_index') +``` + +
+
+keepdims + +```python +data = np.array([[2, 1], [3, 10]], dtype=np.float32) +axis = 1 +keepdims = 1 +node = onnx.helper.make_node( + 'ArgMin', + inputs=['data'], + outputs=['result'], + axis=axis, + keepdims=keepdims) +# The content of result is : [[1], [0]] +result = argmin_use_numpy(data, axis=axis, keepdims=keepdims) +expect(node, inputs=[data], outputs=[result], name='test_argmin_keepdims_example') + +data = np.random.uniform(-10, 10, [2, 3, 4]).astype(np.float32) +# result's shape: [2, 1, 4] +result = argmin_use_numpy(data, axis=axis, keepdims=keepdims) +expect(node, inputs=[data], outputs=[result], name='test_argmin_keepdims_random') +``` + +
+
+keepdims_select_last_index + +```python +data = np.array([[2, 2], [3, 10]], dtype=np.float32) +axis = 1 +keepdims = 1 +node = onnx.helper.make_node( + 'ArgMin', + inputs=['data'], + outputs=['result'], + axis=axis, + keepdims=keepdims, + select_last_index=True) +# result: [[1], [0]] +result = argmin_use_numpy_select_last_index(data, axis=axis, keepdims=keepdims) +expect(node, inputs=[data], outputs=[result], name='test_argmin_keepdims_example_select_last_index') + +data = np.random.uniform(-10, 10, [2, 3, 4]).astype(np.float32) +# result's shape: [2, 1, 4] +result = argmin_use_numpy_select_last_index(data, axis=axis, keepdims=keepdims) +expect(node, inputs=[data], outputs=[result], name='test_argmin_keepdims_random_select_last_index') +``` + +
+
+negative_axis_keepdims + +```python +data = np.array([[2, 1], [3, 10]], dtype=np.float32) +axis = -1 +keepdims = 1 +node = onnx.helper.make_node( + 'ArgMin', + inputs=['data'], + outputs=['result'], + axis=axis, + keepdims=keepdims) +# The content of result is : [[1], [0]] +result = argmin_use_numpy(data, axis=axis, keepdims=keepdims) +expect(node, inputs=[data], outputs=[result], name='test_argmin_negative_axis_keepdims_example') + +data = np.random.uniform(-10, 10, [2, 3, 4]).astype(np.float32) +# result's shape: [2, 3, 1] +result = argmin_use_numpy(data, axis=axis, keepdims=keepdims) +expect(node, inputs=[data], outputs=[result], name='test_argmin_negative_axis_keepdims_random') +``` + +
+
+negative_axis_keepdims_select_last_index + +```python +data = np.array([[2, 2], [3, 10]], dtype=np.float32) +axis = -1 +keepdims = 1 +node = onnx.helper.make_node( + 'ArgMin', + inputs=['data'], + outputs=['result'], + axis=axis, + keepdims=keepdims, + select_last_index=True) +# result: [[1], [0]] +result = argmin_use_numpy_select_last_index(data, axis=axis, keepdims=keepdims) +expect(node, inputs=[data], outputs=[result], name='test_argmin_negative_axis_keepdims_example_select_last_index') + +data = np.random.uniform(-10, 10, [2, 3, 4]).astype(np.float32) +# result's shape: [2, 3, 1] +result = argmin_use_numpy_select_last_index(data, axis=axis, keepdims=keepdims) +expect(node, inputs=[data], outputs=[result], name='test_argmin_negative_axis_keepdims_random_select_last_index') +``` + +
+
+no_keepdims + +```python +data = np.array([[2, 1], [3, 10]], dtype=np.float32) +axis = 1 +keepdims = 0 +node = onnx.helper.make_node( + 'ArgMin', + inputs=['data'], + outputs=['result'], + axis=axis, + keepdims=keepdims) +# The content of result is : [[1, 0]] +result = argmin_use_numpy(data, axis=axis, keepdims=keepdims) +expect(node, inputs=[data], outputs=[result], name='test_argmin_no_keepdims_example') + +data = np.random.uniform(-10, 10, [2, 3, 4]).astype(np.float32) +# result's shape: [2, 4] +result = argmin_use_numpy(data, axis=axis, keepdims=keepdims) +expect(node, inputs=[data], outputs=[result], name='test_argmin_no_keepdims_random') +``` + +
+
+no_keepdims_select_last_index + +```python +data = np.array([[2, 2], [3, 10]], dtype=np.float32) +axis = 1 +keepdims = 0 +node = onnx.helper.make_node( + 'ArgMin', + inputs=['data'], + outputs=['result'], + axis=axis, + keepdims=keepdims, + select_last_index=True) +# result: [[1, 0]] +result = argmin_use_numpy_select_last_index(data, axis=axis, keepdims=keepdims) +expect(node, inputs=[data], outputs=[result], name='test_argmin_no_keepdims_example_select_last_index') + +data = np.random.uniform(-10, 10, [2, 3, 4]).astype(np.float32) +# result's shape: [2, 4] +result = argmin_use_numpy_select_last_index(data, axis=axis, keepdims=keepdims) +expect(node, inputs=[data], outputs=[result], name='test_argmin_no_keepdims_random_select_last_index') +``` + +
+ + +### Asin +There are 1 test cases, listed as following: +
+asin + +```python +node = onnx.helper.make_node( + 'Asin', + inputs=['x'], + outputs=['y'], +) + +x = np.array([-0.5, 0, 0.5]).astype(np.float32) +y = np.arcsin(x) +expect(node, inputs=[x], outputs=[y], + name='test_asin_example') + +x = np.random.rand(3, 4, 5).astype(np.float32) +y = np.arcsin(x) +expect(node, inputs=[x], outputs=[y], + name='test_asin') +``` + +
+ + +### Asinh +There are 1 test cases, listed as following: +
+asinh + +```python +node = onnx.helper.make_node( + 'Asinh', + inputs=['x'], + outputs=['y'], +) + +x = np.array([-1, 0, 1]).astype(np.float32) +y = np.arcsinh(x) # expected output [-0.88137358, 0., 0.88137358] +expect(node, inputs=[x], outputs=[y], + name='test_asinh_example') + +x = np.random.randn(3, 4, 5).astype(np.float32) +y = np.arcsinh(x) +expect(node, inputs=[x], outputs=[y], + name='test_asinh') +``` + +
+ + +### Atan +There are 1 test cases, listed as following: +
+atan + +```python +node = onnx.helper.make_node( + 'Atan', + inputs=['x'], + outputs=['y'], +) + +x = np.array([-1, 0, 1]).astype(np.float32) +y = np.arctan(x) +expect(node, inputs=[x], outputs=[y], + name='test_atan_example') + +x = np.random.randn(3, 4, 5).astype(np.float32) +y = np.arctan(x) +expect(node, inputs=[x], outputs=[y], + name='test_atan') +``` + +
+ + +### Atanh +There are 1 test cases, listed as following: +
+atanh + +```python +node = onnx.helper.make_node( + 'Atanh', + inputs=['x'], + outputs=['y'], +) + +x = np.array([-0.5, 0, 0.5]).astype(np.float32) +y = np.arctanh(x) # expected output [-0.54930615, 0., 0.54930615] +expect(node, inputs=[x], outputs=[y], + name='test_atanh_example') + +x = np.random.uniform(0.0, 1.0, (3, 4, 5)).astype(np.float32) +y = np.arctanh(x) +expect(node, inputs=[x], outputs=[y], + name='test_atanh') +``` + +
+ + +### AveragePool +There are 13 test cases, listed as following: +
+averagepool_1d_default + +```python +""" +input_shape: [1, 3, 32] +output_shape: [1, 3, 31] +""" +node = onnx.helper.make_node( + 'AveragePool', + inputs=['x'], + outputs=['y'], + kernel_shape=[2], +) +x = np.random.randn(1, 3, 32).astype(np.float32) +x_shape = np.shape(x) +kernel_shape = [2] +strides = [1] +out_shape = get_output_shape('VALID', x_shape[2:], kernel_shape, strides) +padded = x +y = pool(padded, x_shape, kernel_shape, strides, out_shape, [0], 'AVG') + +expect(node, inputs=[x], outputs=[y], name='test_averagepool_1d_default') +``` + +
+
+averagepool_2d_ceil + +```python +""" +input_shape: [1, 1, 4, 4] +output_shape: [1, 1, 2, 2] +""" +node = onnx.helper.make_node( + 'AveragePool', + inputs=['x'], + outputs=['y'], + kernel_shape=[3, 3], + strides=[2, 2], + ceil_mode=True +) +x = np.array([[[ + [1, 2, 3, 4], + [5, 6, 7, 8], + [9, 10, 11, 12], + [13, 14, 15, 16], +]]]).astype(np.float32) +y = np.array([[[ + [6, 7.5], + [12, 13.5]]]]).astype(np.float32) + +expect(node, inputs=[x], outputs=[y], name='test_averagepool_2d_ceil') +``` + +
+
+averagepool_2d_default + +```python +""" +input_shape: [1, 3, 32, 32] +output_shape: [1, 3, 31, 31] +""" +node = onnx.helper.make_node( + 'AveragePool', + inputs=['x'], + outputs=['y'], + kernel_shape=[2, 2], +) +x = np.random.randn(1, 3, 32, 32).astype(np.float32) +x_shape = np.shape(x) +kernel_shape = (2, 2) +strides = (1, 1) +out_shape = get_output_shape('VALID', x_shape[2:], kernel_shape, strides) +padded = x +y = pool(padded, x_shape, kernel_shape, strides, out_shape, (0, 0), 'AVG') + +expect(node, inputs=[x], outputs=[y], name='test_averagepool_2d_default') +``` + +
+
+averagepool_2d_pads + +```python +""" +input_shape: [1, 3, 28, 28] +output_shape: [1, 3, 30, 30] +pad_shape: [4, 4] -> [2, 2, 2, 2] by axis +""" +node = onnx.helper.make_node( + 'AveragePool', + inputs=['x'], + outputs=['y'], + kernel_shape=[3, 3], + pads=[2, 2, 2, 2] +) +x = np.random.randn(1, 3, 28, 28).astype(np.float32) +x_shape = np.shape(x) +kernel_shape = (3, 3) +strides = (1, 1) +pad_bottom = 2 +pad_top = 2 +pad_right = 2 +pad_left = 2 +pad_shape = [pad_top + pad_bottom, pad_left + pad_right] +out_shape = get_output_shape('VALID', np.add(x_shape[2:], pad_shape), kernel_shape, strides) +padded = np.pad(x, ((0, 0), (0, 0), (pad_top, pad_bottom), (pad_left, pad_right)), mode='constant', + constant_values=np.nan) +y = pool(padded, x_shape, kernel_shape, strides, out_shape, pad_shape, 'AVG') + +expect(node, inputs=[x], outputs=[y], name='test_averagepool_2d_pads') +``` + +
+
+averagepool_2d_pads_count_include_pad + +```python +""" +input_shape: [1, 3, 28, 28] +output_shape: [1, 3, 30, 30] +pad_shape: [4, 4] -> [2, 2, 2, 2] by axis +""" +node = onnx.helper.make_node( + 'AveragePool', + inputs=['x'], + outputs=['y'], + kernel_shape=[3, 3], + pads=[2, 2, 2, 2], + count_include_pad=1, +) +x = np.random.randn(1, 3, 28, 28).astype(np.float32) +x_shape = np.shape(x) +kernel_shape = (3, 3) +strides = (1, 1) +pad_bottom = 2 +pad_top = 2 +pad_right = 2 +pad_left = 2 +pad_shape = [pad_top + pad_bottom, pad_left + pad_right] +out_shape = get_output_shape('VALID', np.add(x_shape[2:], pad_shape), kernel_shape, strides) +padded = np.pad(x, ((0, 0), (0, 0), (pad_top, pad_bottom), (pad_left, pad_right)), mode='constant', + constant_values=0) +y = pool(padded, x_shape, kernel_shape, strides, out_shape, pad_shape, 'AVG', count_include_pad=1) + +expect(node, inputs=[x], outputs=[y], name='test_averagepool_2d_pads_count_include_pad') +``` + +
+
+averagepool_2d_precomputed_pads + +```python +""" +input_shape: [1, 1, 5, 5] +output_shape: [1, 1, 5, 5] +pad_shape: [4, 4] -> [2, 2, 2, 2] by axis +""" +node = onnx.helper.make_node( + 'AveragePool', + inputs=['x'], + outputs=['y'], + kernel_shape=[5, 5], + pads=[2, 2, 2, 2] + +) +x = np.array([[[ + [1, 2, 3, 4, 5], + [6, 7, 8, 9, 10], + [11, 12, 13, 14, 15], + [16, 17, 18, 19, 20], + [21, 22, 23, 24, 25], +]]]).astype(np.float32) +y = np.array([[[[7, 7.5, 8, 8.5, 9], + [9.5, 10, 10.5, 11, 11.5], + [12, 12.5, 13, 13.5, 14], + [14.5, 15, 15.5, 16, 16.5], + [17, 17.5, 18, 18.5, 19]]]]).astype(np.float32) + +expect(node, inputs=[x], outputs=[y], name='test_averagepool_2d_precomputed_pads') +``` + +
+
+averagepool_2d_precomputed_pads_count_include_pad + +```python +""" +input_shape: [1, 1, 5, 5] +output_shape: [1, 1, 5, 5] +pad_shape: [4, 4] -> [2, 2, 2, 2] by axis +""" +node = onnx.helper.make_node( + 'AveragePool', + inputs=['x'], + outputs=['y'], + kernel_shape=[5, 5], + pads=[2, 2, 2, 2], + count_include_pad=1 +) +x = np.array([[[ + [1, 2, 3, 4, 5], + [6, 7, 8, 9, 10], + [11, 12, 13, 14, 15], + [16, 17, 18, 19, 20], + [21, 22, 23, 24, 25], +]]]).astype(np.float32) +y = np.array([[[[2.5200, 3.6000, 4.8000, 4.0800, 3.2400], + [4.5600, 6.4000, 8.4000, 7.0400, 5.5200], + [7.2000, 10.0000, 13.0000, 10.8000, 8.4000], + [6.9600, 9.6000, 12.4000, 10.2400, 7.9200], + [6.1200, 8.4000, 10.8000, 8.8800, 6.8400]]]]).astype(np.float32) + +expect(node, inputs=[x], outputs=[y], name='test_averagepool_2d_precomputed_pads_count_include_pad') +``` + +
+
+averagepool_2d_precomputed_same_upper + +```python +""" +input_shape: [1, 1, 5, 5] +output_shape: [1, 1, 3, 3] +pad_shape: [2, 2] -> [1, 1, 1, 1] by axis +""" +node = onnx.helper.make_node( + 'AveragePool', + inputs=['x'], + outputs=['y'], + kernel_shape=[3, 3], + strides=[2, 2], + auto_pad='SAME_UPPER' +) +x = np.array([[[ + [1, 2, 3, 4, 5], + [6, 7, 8, 9, 10], + [11, 12, 13, 14, 15], + [16, 17, 18, 19, 20], + [21, 22, 23, 24, 25], +]]]).astype(np.float32) +y = np.array([[[[4, 5.5, 7], + [11.5, 13, 14.5], + [19, 20.5, 22]]]]).astype(np.float32) + +expect(node, inputs=[x], outputs=[y], name='test_averagepool_2d_precomputed_same_upper') +``` + +
+
+averagepool_2d_precomputed_strides + +```python +""" +input_shape: [1, 1, 5, 5] +output_shape: [1, 1, 2, 2] +""" +node = onnx.helper.make_node( + 'AveragePool', + inputs=['x'], + outputs=['y'], + kernel_shape=[2, 2], + strides=[2, 2] +) +x = np.array([[[ + [1, 2, 3, 4, 5], + [6, 7, 8, 9, 10], + [11, 12, 13, 14, 15], + [16, 17, 18, 19, 20], + [21, 22, 23, 24, 25], +]]]).astype(np.float32) +y = np.array([[[[4, 6], + [14, 16]]]]).astype(np.float32) + +expect(node, inputs=[x], outputs=[y], name='test_averagepool_2d_precomputed_strides') +``` + +
+
+averagepool_2d_same_lower + +```python +""" +input_shape: [1, 3, 32, 32] +output_shape: [1, 3, 32, 32] +pad_shape: [1, 1] -> [1, 0, 1, 0] by axis +""" +node = onnx.helper.make_node( + 'AveragePool', + inputs=['x'], + outputs=['y'], + kernel_shape=[2, 2], + auto_pad='SAME_LOWER' +) +x = np.random.randn(1, 3, 32, 32).astype(np.float32) +x_shape = np.shape(x) +kernel_shape = (2, 2) +strides = (1, 1) +out_shape = get_output_shape('SAME_LOWER', x_shape[2:], kernel_shape, strides) +pad_shape = get_pad_shape('SAME_LOWER', x_shape[2:], kernel_shape, strides, out_shape) +pad_bottom = pad_shape[0] // 2 +pad_top = pad_shape[0] - pad_bottom +pad_right = pad_shape[1] // 2 +pad_left = pad_shape[1] - pad_right +padded = np.pad(x, ((0, 0), (0, 0), (pad_top, pad_bottom), (pad_left, pad_right)), mode='constant', + constant_values=np.nan) +y = pool(padded, x_shape, kernel_shape, strides, out_shape, pad_shape, 'AVG') + +expect(node, inputs=[x], outputs=[y], name='test_averagepool_2d_same_lower') +``` + +
+
+averagepool_2d_same_upper + +```python +""" +input_shape: [1, 3, 32, 32] +output_shape: [1, 3, 32, 32] +pad_shape: [1, 1] -> [0, 1, 0, 1] by axis +""" +node = onnx.helper.make_node( + 'AveragePool', + inputs=['x'], + outputs=['y'], + kernel_shape=[2, 2], + auto_pad='SAME_UPPER' +) +x = np.random.randn(1, 3, 32, 32).astype(np.float32) +x_shape = np.shape(x) +kernel_shape = (2, 2) +strides = (1, 1) +out_shape = get_output_shape('SAME_UPPER', x_shape[2:], kernel_shape, strides) +pad_shape = get_pad_shape('SAME_UPPER', x_shape[2:], kernel_shape, strides, out_shape) +pad_top = pad_shape[0] // 2 +pad_bottom = pad_shape[0] - pad_top +pad_left = pad_shape[1] // 2 +pad_right = pad_shape[1] - pad_left +padded = np.pad(x, ((0, 0), (0, 0), (pad_top, pad_bottom), (pad_left, pad_right)), mode='constant', + constant_values=np.nan) +y = pool(padded, x_shape, kernel_shape, strides, out_shape, pad_shape, 'AVG') + +expect(node, inputs=[x], outputs=[y], name='test_averagepool_2d_same_upper') +``` + +
+
+averagepool_2d_strides + +```python +""" +input_shape: [1, 3, 32, 32] +output_shape: [1, 3, 10, 10] +""" +node = onnx.helper.make_node( + 'AveragePool', + inputs=['x'], + outputs=['y'], + kernel_shape=[5, 5], + strides=[3, 3] +) +x = np.random.randn(1, 3, 32, 32).astype(np.float32) +x_shape = np.shape(x) +kernel_shape = (5, 5) +strides = (3, 3) +out_shape = get_output_shape('VALID', x_shape[2:], kernel_shape, strides) +padded = x +y = pool(padded, x_shape, kernel_shape, strides, out_shape, (0, 0), 'AVG') + +expect(node, inputs=[x], outputs=[y], name='test_averagepool_2d_strides') +``` + +
+
+averagepool_3d_default + +```python +""" +input_shape: [1, 3, 32, 32, 32] +output_shape: [1, 3, 31, 31, 31] +""" +node = onnx.helper.make_node( + 'AveragePool', + inputs=['x'], + outputs=['y'], + kernel_shape=[2, 2, 2], +) +x = np.random.randn(1, 3, 32, 32, 32).astype(np.float32) +x_shape = np.shape(x) +kernel_shape = [2, 2, 2] +strides = [1, 1, 1] +out_shape = get_output_shape('VALID', x_shape[2:], kernel_shape, strides) +padded = x +y = pool(padded, x_shape, kernel_shape, strides, out_shape, [0, 0, 0], 'AVG') + +expect(node, inputs=[x], outputs=[y], name='test_averagepool_3d_default') +``` + +
+ + +### BatchNormalization +There are 2 test cases, listed as following: +
+batchnormalization + +```python +# input size: (2, 3, 4, 5) +x = np.random.randn(2, 3, 4, 5).astype(np.float32) +s = np.random.randn(3).astype(np.float32) +bias = np.random.randn(3).astype(np.float32) +mean = np.random.randn(3).astype(np.float32) +var = np.random.rand(3).astype(np.float32) +y = _batchnorm_test_mode(x, s, bias, mean, var).astype(np.float32) + +node = onnx.helper.make_node( + 'BatchNormalization', + inputs=['x', 's', 'bias', 'mean', 'var'], + outputs=['y'], +) + +# output size: (2, 3, 4, 5) +expect(node, inputs=[x, s, bias, mean, var], outputs=[y], + name='test_batchnorm_example') + +# input size: (2, 3, 4, 5) +x = np.random.randn(2, 3, 4, 5).astype(np.float32) +s = np.random.randn(3).astype(np.float32) +bias = np.random.randn(3).astype(np.float32) +mean = np.random.randn(3).astype(np.float32) +var = np.random.rand(3).astype(np.float32) +epsilon = 1e-2 +y = _batchnorm_test_mode(x, s, bias, mean, var, epsilon).astype(np.float32) + +node = onnx.helper.make_node( + 'BatchNormalization', + inputs=['x', 's', 'bias', 'mean', 'var'], + outputs=['y'], + epsilon=epsilon, +) + +# output size: (2, 3, 4, 5) +expect(node, inputs=[x, s, bias, mean, var], outputs=[y], + name='test_batchnorm_epsilon') +``` + +
+
+train + +```python +# input size: (2, 3, 4, 5) +x = np.random.randn(2, 3, 4, 5).astype(np.float32) +s = np.random.randn(3).astype(np.float32) +bias = np.random.randn(3).astype(np.float32) +mean = np.random.randn(3).astype(np.float32) +var = np.random.rand(3).astype(np.float32) +# using np.bool(1) while generating test data with "'bool' object has no attribute 'dtype'" +# working around by using np.byte(1).astype(bool) +training_mode = 1 +y, output_mean, output_var = _batchnorm_training_mode(x, s, bias, mean, var) + +node = onnx.helper.make_node( + 'BatchNormalization', + inputs=['x', 's', 'bias', 'mean', 'var'], + outputs=['y', 'output_mean', 'output_var'], + training_mode=training_mode +) + +# output size: (2, 3, 4, 5) +expect(node, inputs=[x, s, bias, mean, var], + outputs=[y, output_mean, output_var], + name='test_batchnorm_example_training_mode') + +# input size: (2, 3, 4, 5) +x = np.random.randn(2, 3, 4, 5).astype(np.float32) +s = np.random.randn(3).astype(np.float32) +bias = np.random.randn(3).astype(np.float32) +mean = np.random.randn(3).astype(np.float32) +var = np.random.rand(3).astype(np.float32) +training_mode = 1 +momentum = 0.9 +epsilon = 1e-2 +y, output_mean, output_var = _batchnorm_training_mode(x, s, bias, mean, var, momentum, + epsilon) + +node = onnx.helper.make_node( + 'BatchNormalization', + inputs=['x', 's', 'bias', 'mean', 'var'], + outputs=['y', 'output_mean', 'output_var'], + epsilon=epsilon, + training_mode=training_mode +) + +# output size: (2, 3, 4, 5) +expect(node, inputs=[x, s, bias, mean, var], + outputs=[y, output_mean, output_var], + name='test_batchnorm_epsilon_training_mode') +``` + +
+ + +### Bernoulli +There are 3 test cases, listed as following: +
+bernoulli_with_dtype + +```python +node = onnx.helper.make_node( + 'Bernoulli', + inputs=['x'], + outputs=['y'], + dtype=onnx.TensorProto.DOUBLE, +) + +x = np.random.uniform(0.0, 1.0, 10).astype(np.float32) +y = bernoulli_reference_implementation(x, np.float64) +expect(node, inputs=[x], outputs=[y], name='test_bernoulli_double') +``` + +
+
+bernoulli_with_seed + +```python +seed = np.float(0) +node = onnx.helper.make_node( + 'Bernoulli', + inputs=['x'], + outputs=['y'], + seed=seed, +) + +x = np.random.uniform(0.0, 1.0, 10).astype(np.float32) +y = bernoulli_reference_implementation(x, np.float32) +expect(node, inputs=[x], outputs=[y], name='test_bernoulli_seed') +``` + +
+
+bernoulli_without_dtype + +```python +node = onnx.helper.make_node( + 'Bernoulli', + inputs=['x'], + outputs=['y'], +) + +x = np.random.uniform(0.0, 1.0, 10).astype(np.float) +y = bernoulli_reference_implementation(x, np.float) +expect(node, inputs=[x], outputs=[y], name='test_bernoulli') +``` + +
+ + +### BitShift +There are 8 test cases, listed as following: +
+left_unit16 + +```python +node = onnx.helper.make_node( + 'BitShift', + inputs=['x', 'y'], + outputs=['z'], + direction="LEFT" +) + +x = np.array([16, 4, 1]).astype(np.uint16) +y = np.array([1, 2, 3]).astype(np.uint16) +z = x << y # expected output [32, 16, 8] +expect(node, inputs=[x, y], outputs=[z], + name='test_bitshift_left_uint16') +``` + +
+
+left_unit32 + +```python +node = onnx.helper.make_node( + 'BitShift', + inputs=['x', 'y'], + outputs=['z'], + direction="LEFT" +) + +x = np.array([16, 4, 1]).astype(np.uint32) +y = np.array([1, 2, 3]).astype(np.uint32) +z = x << y # expected output [32, 16, 8] +expect(node, inputs=[x, y], outputs=[z], + name='test_bitshift_left_uint32') +``` + +
+
+left_unit64 + +```python +node = onnx.helper.make_node( + 'BitShift', + inputs=['x', 'y'], + outputs=['z'], + direction="LEFT" +) + +x = np.array([16, 4, 1]).astype(np.uint64) +y = np.array([1, 2, 3]).astype(np.uint64) +z = x << y # expected output [32, 16, 8] +expect(node, inputs=[x, y], outputs=[z], + name='test_bitshift_left_uint64') +``` + +
+
+left_unit8 + +```python +node = onnx.helper.make_node( + 'BitShift', + inputs=['x', 'y'], + outputs=['z'], + direction="LEFT" +) + +x = np.array([16, 4, 1]).astype(np.uint8) +y = np.array([1, 2, 3]).astype(np.uint8) +z = x << y # expected output [32, 16, 8] +expect(node, inputs=[x, y], outputs=[z], + name='test_bitshift_left_uint8') +``` + +
+
+right_unit16 + +```python +node = onnx.helper.make_node( + 'BitShift', + inputs=['x', 'y'], + outputs=['z'], + direction="RIGHT" +) + +x = np.array([16, 4, 1]).astype(np.uint16) +y = np.array([1, 2, 3]).astype(np.uint16) +z = x >> y # expected output [8, 1, 0] +expect(node, inputs=[x, y], outputs=[z], + name='test_bitshift_right_uint16') +``` + +
+
+right_unit32 + +```python +node = onnx.helper.make_node( + 'BitShift', + inputs=['x', 'y'], + outputs=['z'], + direction="RIGHT" +) + +x = np.array([16, 4, 1]).astype(np.uint32) +y = np.array([1, 2, 3]).astype(np.uint32) +z = x >> y # expected output [8, 1, 0] +expect(node, inputs=[x, y], outputs=[z], + name='test_bitshift_right_uint32') +``` + +
+
+right_unit64 + +```python +node = onnx.helper.make_node( + 'BitShift', + inputs=['x', 'y'], + outputs=['z'], + direction="RIGHT" +) + +x = np.array([16, 4, 1]).astype(np.uint64) +y = np.array([1, 2, 3]).astype(np.uint64) +z = x >> y # expected output [8, 1, 0] +expect(node, inputs=[x, y], outputs=[z], + name='test_bitshift_right_uint64') +``` + +
+
+right_unit8 + +```python +node = onnx.helper.make_node( + 'BitShift', + inputs=['x', 'y'], + outputs=['z'], + direction="RIGHT" +) + +x = np.array([16, 4, 1]).astype(np.uint8) +y = np.array([1, 2, 3]).astype(np.uint8) +z = x >> y # expected output [8, 1, 0] +expect(node, inputs=[x, y], outputs=[z], + name='test_bitshift_right_uint8') +``` + +
+ + +### Cast +There are 1 test cases, listed as following: +
+cast + +```python +shape = (3, 4) +test_cases = [ + ('FLOAT', 'FLOAT16'), + ('FLOAT', 'DOUBLE'), + ('FLOAT16', 'FLOAT'), + ('FLOAT16', 'DOUBLE'), + ('DOUBLE', 'FLOAT'), + ('DOUBLE', 'FLOAT16'), + ('FLOAT', 'STRING'), + ('STRING', 'FLOAT'), + ('FLOAT', 'BFLOAT16'), + ('BFLOAT16', 'FLOAT'), +] + +for from_type, to_type in test_cases: + input_type_proto = None + output_type_proto = None + if 'BFLOAT16' == from_type or 'BFLOAT16' == to_type: + np_fp32 = np.array([u'0.47892547', u'0.48033667', u'0.49968487', u'0.81910545', + u'0.47031248', u'0.816468', u'0.21087195', u'0.7229038', + u'NaN', u'INF', u'+INF', u'-INF'], dtype=np.float32) + little_endisan = sys.byteorder == 'little' + np_uint16_view = np_fp32.view(dtype=np.uint16) + np_bfp16 = np_uint16_view[1::2] if little_endisan else np_uint16_view[0::2] + if 'BFLOAT16' == to_type: + assert from_type == 'FLOAT' + input = np_fp32.reshape([3, 4]) + output = np_bfp16.reshape([3, 4]) + input_type_proto = onnx.helper.make_tensor_type_proto(int(TensorProto.FLOAT), input.shape) + output_type_proto = onnx.helper.make_tensor_type_proto(int(TensorProto.BFLOAT16), output.shape) + else: + assert to_type == 'FLOAT' + input = np_bfp16.reshape([3, 4]) + #convert bfloat to FLOAT + np_fp32_zeros = np.zeros((len(np_bfp16) * 2,), dtype=np.uint16) + if little_endisan: + np_fp32_zeros[1::2] = np_bfp16 + else: + np_fp32_zeros[0::2] = np_bfp16 + np_fp32_from_bfloat = np_fp32_zeros.view(dtype=np.float32) + output = np_fp32_from_bfloat.reshape([3, 4]) + input_type_proto = onnx.helper.make_tensor_type_proto(int(TensorProto.BFLOAT16), input.shape) + output_type_proto = onnx.helper.make_tensor_type_proto(int(TensorProto.FLOAT), output.shape) + elif 'STRING' != from_type: + input = np.random.random_sample(shape).astype( + TENSOR_TYPE_TO_NP_TYPE[getattr(TensorProto, from_type)]) + if ('STRING' == to_type): + # Converting input to str, then give it object dtype for generating script + ss = [] + for i in input.flatten(): + s = str(i).encode('utf-8') + su = s.decode('utf-8') + ss.append(su) + + output = np.array(ss).astype(object).reshape([3, 4]) + else: + output = input.astype(TENSOR_TYPE_TO_NP_TYPE[getattr(TensorProto, to_type)]) + else: + input = np.array([u'0.47892547', u'0.48033667', u'0.49968487', u'0.81910545', + u'0.47031248', u'0.816468', u'0.21087195', u'0.7229038', + u'NaN', u'INF', u'+INF', u'-INF'], dtype=np.dtype(object)).reshape([3, 4]) + output = input.astype(TENSOR_TYPE_TO_NP_TYPE[getattr(TensorProto, to_type)]) + node = onnx.helper.make_node( + 'Cast', + inputs=['input'], + outputs=['output'], + to=getattr(TensorProto, to_type), + ) + if input_type_proto and output_type_proto: + expect(node, inputs=[input], outputs=[output], + name='test_cast_' + from_type + '_to_' + to_type, + input_type_protos=[input_type_proto], + output_type_protos=[output_type_proto]) + else: + expect(node, inputs=[input], outputs=[output], + name='test_cast_' + from_type + '_to_' + to_type) +``` + +
+ + +### CastLike +There are 1 test cases, listed as following: +
+castlike + +```python +shape = (3, 4) +test_cases = [ + ('FLOAT', 'FLOAT16'), + ('FLOAT', 'DOUBLE'), + ('FLOAT16', 'FLOAT'), + ('FLOAT16', 'DOUBLE'), + ('DOUBLE', 'FLOAT'), + ('DOUBLE', 'FLOAT16'), + ('FLOAT', 'STRING'), + ('STRING', 'FLOAT'), + ('FLOAT', 'BFLOAT16'), + ('BFLOAT16', 'FLOAT'), +] + +for from_type, to_type in test_cases: + input_type_proto = None + output_type_proto = None + if 'BFLOAT16' == from_type or 'BFLOAT16' == to_type: + np_fp32 = np.array([u'0.47892547', u'0.48033667', u'0.49968487', u'0.81910545', + u'0.47031248', u'0.816468', u'0.21087195', u'0.7229038', + u'NaN', u'INF', u'+INF', u'-INF'], dtype=np.float32) + little_endisan = sys.byteorder == 'little' + np_uint16_view = np_fp32.view(dtype=np.uint16) + np_bfp16 = np_uint16_view[1::2] if little_endisan else np_uint16_view[0::2] + if 'BFLOAT16' == to_type: + assert from_type == 'FLOAT' + input = np_fp32.reshape([3, 4]) + output = np_bfp16.reshape([3, 4]) + input_type_proto = onnx.helper.make_tensor_type_proto(int(TensorProto.FLOAT), input.shape) + output_type_proto = onnx.helper.make_tensor_type_proto(int(TensorProto.BFLOAT16), output.shape) + else: + assert to_type == 'FLOAT' + input = np_bfp16.reshape([3, 4]) + #convert bfloat to FLOAT + np_fp32_zeros = np.zeros((len(np_bfp16) * 2,), dtype=np.uint16) + if little_endisan: + np_fp32_zeros[1::2] = np_bfp16 + else: + np_fp32_zeros[0::2] = np_bfp16 + np_fp32_from_bfloat = np_fp32_zeros.view(dtype=np.float32) + output = np_fp32_from_bfloat.reshape([3, 4]) + input_type_proto = onnx.helper.make_tensor_type_proto(int(TensorProto.BFLOAT16), input.shape) + output_type_proto = onnx.helper.make_tensor_type_proto(int(TensorProto.FLOAT), output.shape) + elif 'STRING' != from_type: + input = np.random.random_sample(shape).astype( + TENSOR_TYPE_TO_NP_TYPE[getattr(TensorProto, from_type)]) + if ('STRING' == to_type): + # Converting input to str, then give it np.object dtype for generating script + ss = [] + for i in input.flatten(): + s = str(i).encode('utf-8') + su = s.decode('utf-8') + ss.append(su) + + output = np.array(ss).astype(np.object).reshape([3, 4]) + else: + output = input.astype(TENSOR_TYPE_TO_NP_TYPE[getattr(TensorProto, to_type)]) + else: + input = np.array([u'0.47892547', u'0.48033667', u'0.49968487', u'0.81910545', + u'0.47031248', u'0.816468', u'0.21087195', u'0.7229038', + u'NaN', u'INF', u'+INF', u'-INF'], dtype=np.dtype(np.object)).reshape([3, 4]) + output = input.astype(TENSOR_TYPE_TO_NP_TYPE[getattr(TensorProto, to_type)]) + like = output.flatten()[0:1] + node = onnx.helper.make_node( + 'CastLike', + inputs=['input', 'like'], + outputs=['output'], + ) + if input_type_proto and output_type_proto: + expect(node, inputs=[input, like], outputs=[output], + name='test_castlike_' + from_type + '_to_' + to_type, + input_type_protos=[input_type_proto, output_type_proto], + output_type_protos=[output_type_proto]) + else: + expect(node, inputs=[input, like], outputs=[output], + name='test_castlike_' + from_type + '_to_' + to_type) +``` + +
+ + +### Ceil +There are 1 test cases, listed as following: +
+ceil + +```python +node = onnx.helper.make_node( + 'Ceil', + inputs=['x'], + outputs=['y'], +) + +x = np.array([-1.5, 1.2]).astype(np.float32) +y = np.ceil(x) # expected output [-1., 2.] +expect(node, inputs=[x], outputs=[y], + name='test_ceil_example') + +x = np.random.randn(3, 4, 5).astype(np.float32) +y = np.ceil(x) +expect(node, inputs=[x], outputs=[y], + name='test_ceil') +``` + +
+ + +### Celu +There are 1 test cases, listed as following: +
+celu + +```python +alpha = 2.0 +node = onnx.helper.make_node( + 'Celu', + inputs=['X'], + outputs=['Y'], + alpha=alpha, +) + +input_data = np.array([[[[0.8439683], [0.5665144], [0.05836735]], + [[0.02916367], [0.12964272], [0.5060197]], + [[0.79538304], [0.9411346], [0.9546573]]], + [[[0.17730942], [0.46192095], [0.26480448]], + [[0.6746842], [0.01665257], [0.62473077]], + [[0.9240844], [0.9722341], [0.11965699]]], + [[[0.41356155], [0.9129373], [0.59330076]], + [[0.81929934], [0.7862604], [0.11799799]], + [[0.69248444], [0.54119414], [0.07513223]]]], dtype=np.float32) + +# Calculate expected output data +positive_input = np.maximum(0, input_data) +negative_input = np.minimum(0, alpha * (np.exp(input_data / alpha) - 1)) +expected_output = positive_input + negative_input + +expect(node, inputs=[input_data], outputs=[expected_output], + name='test_celu') +``` + +
+ + +### Clip +There are 3 test cases, listed as following: +
+clip + +```python +node = onnx.helper.make_node( + 'Clip', + inputs=['x', 'min', 'max'], + outputs=['y'], +) + +x = np.array([-2, 0, 2]).astype(np.float32) +min_val = np.float32(-1) +max_val = np.float32(1) +y = np.clip(x, min_val, max_val) # expected output [-1., 0., 1.] +expect(node, inputs=[x, min_val, max_val], outputs=[y], + name='test_clip_example') + +x = np.random.randn(3, 4, 5).astype(np.float32) +y = np.clip(x, min_val, max_val) +expect(node, inputs=[x, min_val, max_val], outputs=[y], + name='test_clip') +node = onnx.helper.make_node( + 'Clip', + inputs=['x', 'min', 'max'], + outputs=['y'], +) + +min_val = np.float32(-5) +max_val = np.float32(5) + +x = np.array([-1, 0, 1]).astype(np.float32) +y = np.array([-1, 0, 1]).astype(np.float32) +expect(node, inputs=[x, min_val, max_val], outputs=[y], + name='test_clip_inbounds') + +x = np.array([-6, 0, 6]).astype(np.float32) +y = np.array([-5, 0, 5]).astype(np.float32) +expect(node, inputs=[x, min_val, max_val], outputs=[y], + name='test_clip_outbounds') + +x = np.array([-1, 0, 6]).astype(np.float32) +y = np.array([-1, 0, 5]).astype(np.float32) +expect(node, inputs=[x, min_val, max_val], outputs=[y], + name='test_clip_splitbounds') +``` + +
+
+clip_default + +```python +node = onnx.helper.make_node( + 'Clip', + inputs=['x', 'min'], + outputs=['y'], +) +min_val = np.float32(0) +x = np.random.randn(3, 4, 5).astype(np.float32) +y = np.clip(x, min_val, np.inf) +expect(node, inputs=[x, min_val], outputs=[y], + name='test_clip_default_min') + +no_min = "" # optional input, not supplied +node = onnx.helper.make_node( + 'Clip', + inputs=['x', no_min, 'max'], + outputs=['y'], +) +max_val = np.float32(0) +x = np.random.randn(3, 4, 5).astype(np.float32) +y = np.clip(x, -np.inf, max_val) +expect(node, inputs=[x, max_val], outputs=[y], + name='test_clip_default_max') + +no_max = "" # optional input, not supplied +node = onnx.helper.make_node( + 'Clip', + inputs=['x', no_min, no_max], + outputs=['y'], +) + +x = np.array([-1, 0, 1]).astype(np.float32) +y = np.array([-1, 0, 1]).astype(np.float32) +expect(node, inputs=[x], outputs=[y], + name='test_clip_default_inbounds') +``` + +
+
+clip_default_int8 + +```python +node = onnx.helper.make_node( + 'Clip', + inputs=['x', 'min'], + outputs=['y'], +) +min_val = np.int8(0) +x = np.random.randn(3, 4, 5).astype(np.int8) +y = np.clip(x, min_val, np.iinfo(np.int8).max) +expect(node, inputs=[x, min_val], outputs=[y], + name='test_clip_default_int8_min') + +no_min = "" # optional input, not supplied +node = onnx.helper.make_node( + 'Clip', + inputs=['x', no_min, 'max'], + outputs=['y'], +) +max_val = np.int8(0) +x = np.random.randn(3, 4, 5).astype(np.int8) +y = np.clip(x, np.iinfo(np.int8).min, max_val) +expect(node, inputs=[x, max_val], outputs=[y], + name='test_clip_default_int8_max') + +no_max = "" # optional input, not supplied +node = onnx.helper.make_node( + 'Clip', + inputs=['x', no_min, no_max], + outputs=['y'], +) + +x = np.array([-1, 0, 1]).astype(np.int8) +y = np.array([-1, 0, 1]).astype(np.int8) +expect(node, inputs=[x], outputs=[y], + name='test_clip_default_int8_inbounds') +``` + +
+ + +### Compress +There are 4 test cases, listed as following: +
+compress_0 + +```python +node = onnx.helper.make_node( + 'Compress', + inputs=['input', 'condition'], + outputs=['output'], + axis=0, +) +input = np.array([[1, 2], [3, 4], [5, 6]]).astype(np.float32) +condition = np.array([0, 1, 1]) +output = np.compress(condition, input, axis=0) +#print(output) +#[[ 3. 4.] +# [ 5. 6.]] + +expect(node, inputs=[input, condition.astype(bool)], outputs=[output], + name='test_compress_0') +``` + +
+
+compress_1 + +```python +node = onnx.helper.make_node( + 'Compress', + inputs=['input', 'condition'], + outputs=['output'], + axis=1, +) +input = np.array([[1, 2], [3, 4], [5, 6]]).astype(np.float32) +condition = np.array([0, 1]) +output = np.compress(condition, input, axis=1) +#print(output) +#[[ 2.] +# [ 4.] +# [ 6.]] + +expect(node, inputs=[input, condition.astype(bool)], outputs=[output], + name='test_compress_1') +``` + +
+
+compress_default_axis + +```python +node = onnx.helper.make_node( + 'Compress', + inputs=['input', 'condition'], + outputs=['output'], +) +input = np.array([[1, 2], [3, 4], [5, 6]]).astype(np.float32) +condition = np.array([0, 1, 0, 0, 1]) +output = np.compress(condition, input) +#print(output) +#[ 2., 5.] + +expect(node, inputs=[input, condition.astype(bool)], outputs=[output], + name='test_compress_default_axis') +``` + +
+
+compress_negative_axis + +```python +node = onnx.helper.make_node( + 'Compress', + inputs=['input', 'condition'], + outputs=['output'], + axis=-1, +) +input = np.array([[1, 2], [3, 4], [5, 6]]).astype(np.float32) +condition = np.array([0, 1]) +output = np.compress(condition, input, axis=-1) +# print(output) +#[[ 2.] +# [ 4.] +# [ 6.]] +expect(node, inputs=[input, condition.astype(bool)], outputs=[output], + name='test_compress_negative_axis') +``` + +
+ + +### Concat +There are 1 test cases, listed as following: +
+concat + +```python +test_cases = { + '1d': ([1, 2], + [3, 4]), + '2d': ([[1, 2], [3, 4]], + [[5, 6], [7, 8]]), + '3d': ([[[1, 2], [3, 4]], [[5, 6], [7, 8]]], + [[[9, 10], [11, 12]], [[13, 14], [15, 16]]]) +} # type: Dict[Text, Sequence[Any]] + +for test_case, values_ in test_cases.items(): + values = [np.asarray(v, dtype=np.float32) for v in values_] + for i in range(len(values[0].shape)): + in_args = ['value' + str(k) for k in range(len(values))] + node = onnx.helper.make_node( + 'Concat', + inputs=[s for s in in_args], + outputs=['output'], + axis=i + ) + output = np.concatenate(values, i) + expect(node, inputs=[v for v in values], outputs=[output], + name='test_concat_' + test_case + '_axis_' + str(i)) + + for i in range(-len(values[0].shape), 0): + in_args = ['value' + str(k) for k in range(len(values))] + node = onnx.helper.make_node( + 'Concat', + inputs=[s for s in in_args], + outputs=['output'], + axis=i + ) + output = np.concatenate(values, i) + expect(node, inputs=[v for v in values], outputs=[output], + name='test_concat_' + test_case + '_axis_negative_' + str(abs(i))) +``` + +
+ + +### Constant +There are 1 test cases, listed as following: +
+constant + +```python +values = np.random.randn(5, 5).astype(np.float32) +node = onnx.helper.make_node( + 'Constant', + inputs=[], + outputs=['values'], + value=onnx.helper.make_tensor( + name='const_tensor', + data_type=onnx.TensorProto.FLOAT, + dims=values.shape, + vals=values.flatten().astype(float), + ), +) + +expect(node, inputs=[], outputs=[values], + name='test_constant') +``` + +
+ + +### ConstantOfShape +There are 3 test cases, listed as following: +
+float_ones + +```python +x = np.array([4, 3, 2]).astype(np.int64) +tensor_value = onnx.helper.make_tensor("value", onnx.TensorProto.FLOAT, + [1], [1]) +node = onnx.helper.make_node( + 'ConstantOfShape', + inputs=['x'], + outputs=['y'], + value=tensor_value, +) + +y = np.ones(x, dtype=np.float32) +expect(node, inputs=[x], outputs=[y], + name='test_constantofshape_float_ones') +``` + +
+
+int32_shape_zero + +```python +x = np.array([0, ]).astype(np.int64) +tensor_value = onnx.helper.make_tensor("value", onnx.TensorProto.INT32, + [1], [0]) +node = onnx.helper.make_node( + 'ConstantOfShape', + inputs=['x'], + outputs=['y'], + value=tensor_value, +) +y = np.zeros(x, dtype=np.int32) +expect(node, inputs=[x], outputs=[y], + name='test_constantofshape_int_shape_zero') +``` + +
+
+int32_zeros + +```python +x = np.array([10, 6]).astype(np.int64) +tensor_value = onnx.helper.make_tensor("value", onnx.TensorProto.INT32, + [1], [0]) +node = onnx.helper.make_node( + 'ConstantOfShape', + inputs=['x'], + outputs=['y'], + value=tensor_value, +) +y = np.zeros(x, dtype=np.int32) +expect(node, inputs=[x], outputs=[y], + name='test_constantofshape_int_zeros') +``` + +
+ + +### Conv +There are 3 test cases, listed as following: +
+conv + +```python + +x = np.array([[[[0., 1., 2., 3., 4.], # (1, 1, 5, 5) input tensor + [5., 6., 7., 8., 9.], + [10., 11., 12., 13., 14.], + [15., 16., 17., 18., 19.], + [20., 21., 22., 23., 24.]]]]).astype(np.float32) +W = np.array([[[[1., 1., 1.], # (1, 1, 3, 3) tensor for convolution weights + [1., 1., 1.], + [1., 1., 1.]]]]).astype(np.float32) + +# Convolution with padding +node_with_padding = onnx.helper.make_node( + 'Conv', + inputs=['x', 'W'], + outputs=['y'], + kernel_shape=[3, 3], + # Default values for other attributes: strides=[1, 1], dilations=[1, 1], groups=1 + pads=[1, 1, 1, 1], +) +y_with_padding = np.array([[[[12., 21., 27., 33., 24.], # (1, 1, 5, 5) output tensor + [33., 54., 63., 72., 51.], + [63., 99., 108., 117., 81.], + [93., 144., 153., 162., 111.], + [72., 111., 117., 123., 84.]]]]).astype(np.float32) +expect(node_with_padding, inputs=[x, W], outputs=[y_with_padding], + name='test_basic_conv_with_padding') + +# Convolution without padding +node_without_padding = onnx.helper.make_node( + 'Conv', + inputs=['x', 'W'], + outputs=['y'], + kernel_shape=[3, 3], + # Default values for other attributes: strides=[1, 1], dilations=[1, 1], groups=1 + pads=[0, 0, 0, 0], +) +y_without_padding = np.array([[[[54., 63., 72.], # (1, 1, 3, 3) output tensor + [99., 108., 117.], + [144., 153., 162.]]]]).astype(np.float32) +expect(node_without_padding, inputs=[x, W], outputs=[y_without_padding], + name='test_basic_conv_without_padding') +``` + +
+
+conv_with_autopad_same + +```python + +x = np.array([[[[0., 1., 2., 3., 4.], # (1, 1, 5, 5) input tensor + [5., 6., 7., 8., 9.], + [10., 11., 12., 13., 14.], + [15., 16., 17., 18., 19.], + [20., 21., 22., 23., 24.]]]]).astype(np.float32) +W = np.array([[[[1., 1., 1.], # (1, 1, 3, 3) tensor for convolution weights + [1., 1., 1.], + [1., 1., 1.]]]]).astype(np.float32) + +# Convolution with auto_pad='SAME_LOWER' and strides=2 +node = onnx.helper.make_node( + 'Conv', + inputs=['x', 'W'], + outputs=['y'], + auto_pad='SAME_LOWER', + kernel_shape=[3, 3], + strides=[2, 2], +) +y = np.array([[[[12., 27., 24.], + [63., 108., 81.], + [72., 117., 84.]]]]).astype(np.float32) +expect(node, inputs=[x, W], outputs=[y], + name='test_conv_with_autopad_same') +``` + +
+
+conv_with_strides + +```python + +x = np.array([[[[0., 1., 2., 3., 4.], # (1, 1, 7, 5) input tensor + [5., 6., 7., 8., 9.], + [10., 11., 12., 13., 14.], + [15., 16., 17., 18., 19.], + [20., 21., 22., 23., 24.], + [25., 26., 27., 28., 29.], + [30., 31., 32., 33., 34.]]]]).astype(np.float32) +W = np.array([[[[1., 1., 1.], # (1, 1, 3, 3) tensor for convolution weights + [1., 1., 1.], + [1., 1., 1.]]]]).astype(np.float32) + +# Convolution with strides=2 and padding +node_with_padding = onnx.helper.make_node( + 'Conv', + inputs=['x', 'W'], + outputs=['y'], + kernel_shape=[3, 3], + pads=[1, 1, 1, 1], + strides=[2, 2], # Default values for other attributes: dilations=[1, 1], groups=1 +) +y_with_padding = np.array([[[[12., 27., 24.], # (1, 1, 4, 3) output tensor + [63., 108., 81.], + [123., 198., 141.], + [112., 177., 124.]]]]).astype(np.float32) +expect(node_with_padding, inputs=[x, W], outputs=[y_with_padding], + name='test_conv_with_strides_padding') + +# Convolution with strides=2 and no padding +node_without_padding = onnx.helper.make_node( + 'Conv', + inputs=['x', 'W'], + outputs=['y'], + kernel_shape=[3, 3], + pads=[0, 0, 0, 0], + strides=[2, 2], # Default values for other attributes: dilations=[1, 1], groups=1 +) +y_without_padding = np.array([[[[54., 72.], # (1, 1, 3, 2) output tensor + [144., 162.], + [234., 252.]]]]).astype(np.float32) +expect(node_without_padding, inputs=[x, W], outputs=[y_without_padding], + name='test_conv_with_strides_no_padding') + +# Convolution with strides=2 and padding only along one dimension (the H dimension in NxCxHxW tensor) +node_with_asymmetric_padding = onnx.helper.make_node( + 'Conv', + inputs=['x', 'W'], + outputs=['y'], + kernel_shape=[3, 3], + pads=[1, 0, 1, 0], + strides=[2, 2], # Default values for other attributes: dilations=[1, 1], groups=1 +) +y_with_asymmetric_padding = np.array([[[[21., 33.], # (1, 1, 4, 2) output tensor + [99., 117.], + [189., 207.], + [171., 183.]]]]).astype(np.float32) +expect(node_with_asymmetric_padding, inputs=[x, W], outputs=[y_with_asymmetric_padding], + name='test_conv_with_strides_and_asymmetric_padding') +``` + +
+ + +### ConvInteger +There are 2 test cases, listed as following: +
+with_padding + +```python + +x = np.array([2, 3, 4, 5, 6, 7, 8, 9, 10]).astype(np.uint8).reshape((1, 1, 3, 3)) +x_zero_point = np.uint8(1) +w = np.array([1, 1, 1, 1]).astype(np.uint8).reshape((1, 1, 2, 2)) + +y = np.array([1, 3, 5, 3, 5, 12, 16, 9, 11, 24, 28, 15, 7, 15, 17, 9]).astype(np.int32).reshape((1, 1, 4, 4)) + +# ConvInteger with padding +convinteger_node_with_padding = onnx.helper.make_node('ConvInteger', + inputs=['x', 'w', 'x_zero_point'], + outputs=['y'], + pads=[1, 1, 1, 1],) + +expect(convinteger_node_with_padding, inputs=[x, w, x_zero_point], outputs=[y], + name='test_convinteger_with_padding') +``` + +
+
+without_padding + +```python + +x = np.array([2, 3, 4, 5, 6, 7, 8, 9, 10]).astype(np.uint8).reshape((1, 1, 3, 3)) +x_zero_point = np.uint8(1) +w = np.array([1, 1, 1, 1]).astype(np.uint8).reshape((1, 1, 2, 2)) + +y = np.array([12, 16, 24, 28]).astype(np.int32).reshape(1, 1, 2, 2) + +# ConvInteger without padding +convinteger_node = onnx.helper.make_node('ConvInteger', + inputs=['x', 'w', 'x_zero_point'], + outputs=['y']) + +expect(convinteger_node, inputs=[x, w, x_zero_point], outputs=[y], + name='test_convinteger_without_padding') +``` + +
+ + +### ConvTranspose +There are 7 test cases, listed as following: +
+convtranspose + +```python +x = np.array([[[[0., 1., 2.], # (1, 1, 3, 3) + [3., 4., 5.], + [6., 7., 8.]]]]).astype(np.float32) + +W = np.array([[[[1., 1., 1.], # (1, 2, 3, 3) + [1., 1., 1.], + [1., 1., 1.]], + [[1., 1., 1.], + [1., 1., 1.], + [1., 1., 1.]]]]).astype(np.float32) + +node = onnx.helper.make_node("ConvTranspose", ["X", "W"], ["Y"]) + +y = np.array([[[[0., 1., 3., 3., 2.], # (1, 2, 5, 5) + [3., 8., 15., 12., 7.], + [9., 21., 36., 27., 15.], + [9., 20., 33., 24., 13.], + [6., 13., 21., 15., 8.]], + + [[0., 1., 3., 3., 2.], + [3., 8., 15., 12., 7.], + [9., 21., 36., 27., 15.], + [9., 20., 33., 24., 13.], + [6., 13., 21., 15., 8.]]]]).astype(np.float32) + +expect(node, inputs=[x, W], outputs=[y], name='test_convtranspose') +``` + +
+
+convtranspose_1d + +```python +x = np.array([[[0., 1., 2.]]]).astype(np.float32) # (1, 1, 3) + +W = np.array([[[1., 1., 1.], # (1, 2, 3) + [1., 1., 1.]]]).astype(np.float32) + +node = onnx.helper.make_node("ConvTranspose", ["X", "W"], ["Y"]) + +y = np.array([[[0., 1., 3., 3., 2.], # (1, 2, 5) + [0., 1., 3., 3., 2.]]]).astype(np.float32) + +expect(node, inputs=[x, W], outputs=[y], name='test_convtranspose_1d') +``` + +
+
+convtranspose_3d + +```python +x = np.array([[[[[0., 1., 2., 3., 4.], # (1, 1, 3, 4, 5) + [5., 6., 7., 8., 9.], + [10., 11., 12., 13., 14.], + [15., 16., 17., 18., 19.]], + [[20., 21., 22., 23., 24.], + [25., 26., 27., 28., 29.], + [30., 31., 32., 33., 34.], + [35., 36., 37., 38., 39.]], + [[40., 41., 42., 43., 44.], + [45., 46., 47., 48., 49.], + [50., 51., 52., 53., 54.], + [55., 56., 57., 58., 59.]]]]]).astype(np.float32) + +W = np.array([[[[[1., 1., 1.], # (1, 2, 3, 3, 3) + [1., 1., 1.], + [1., 1., 1.]], + [[1., 1., 1.], + [1., 1., 1.], + [1., 1., 1.]], + [[1., 1., 1.], + [1., 1., 1.], + [1., 1., 1.]]], + [[[1., 1., 1.], + [1., 1., 1.], + [1., 1., 1.]], + [[1., 1., 1.], + [1., 1., 1.], + [1., 1., 1.]], + [[1., 1., 1.], + [1., 1., 1.], + [1., 1., 1.]]]]]).astype(np.float32) + +node = onnx.helper.make_node("ConvTranspose", ["X", "W"], ["Y"]) + +y = np.array([[[[[0., 1., 3., 6., 9., 7., 4.], # (1, 2, 5, 6, 7) + [5., 12., 21., 27., 33., 24., 13.], + [15., 33., 54., 63., 72., 51., 27.], + [30., 63., 99., 108., 117., 81., 42.], + [25., 52., 81., 87., 93., 64., 33.], + [15., 31., 48., 51., 54., 37., 19.]], + + [[20., 42., 66., 72., 78., 54., 28.], + [50., 104., 162., 174., 186., 128., 66.], + [90., 186., 288., 306., 324., 222., 114.], + [120., 246., 378., 396., 414., 282., 144.], + [90., 184., 282., 294., 306., 208., 106.], + [50., 102., 156., 162., 168., 114., 58.]], + + [[60., 123., 189., 198., 207., 141., 72.], + [135., 276., 423., 441., 459., 312., 159.], + [225., 459., 702., 729., 756., 513., 261.], + [270., 549., 837., 864., 891., 603., 306.], + [195., 396., 603., 621., 639., 432., 219.], + [105., 213., 324., 333., 342., 231., 117.]], + + [[60., 122., 186., 192., 198., 134., 68.], + [130., 264., 402., 414., 426., 288., 146.], + [210., 426., 648., 666., 684., 462., 234.], + [240., 486., 738., 756., 774., 522., 264.], + [170., 344., 522., 534., 546., 368., 186.], + [90., 182., 276., 282., 288., 194., 98.]], + + [[40., 81., 123., 126., 129., 87., 44.], + [85., 172., 261., 267., 273., 184., 93.], + [135., 273., 414., 423., 432., 291., 147.], + [150., 303., 459., 468., 477., 321., 162.], + [105., 212., 321., 327., 333., 224., 113.], + [55., 111., 168., 171., 174., 117., 59.]]], + + [[[0., 1., 3., 6., 9., 7., 4.], + [5., 12., 21., 27., 33., 24., 13.], + [15., 33., 54., 63., 72., 51., 27.], + [30., 63., 99., 108., 117., 81., 42.], + [25., 52., 81., 87., 93., 64., 33.], + [15., 31., 48., 51., 54., 37., 19.]], + + [[20., 42., 66., 72., 78., 54., 28.], + [50., 104., 162., 174., 186., 128., 66.], + [90., 186., 288., 306., 324., 222., 114.], + [120., 246., 378., 396., 414., 282., 144.], + [90., 184., 282., 294., 306., 208., 106.], + [50., 102., 156., 162., 168., 114., 58.]], + + [[60., 123., 189., 198., 207., 141., 72.], + [135., 276., 423., 441., 459., 312., 159.], + [225., 459., 702., 729., 756., 513., 261.], + [270., 549., 837., 864., 891., 603., 306.], + [195., 396., 603., 621., 639., 432., 219.], + [105., 213., 324., 333., 342., 231., 117.]], + + [[60., 122., 186., 192., 198., 134., 68.], + [130., 264., 402., 414., 426., 288., 146.], + [210., 426., 648., 666., 684., 462., 234.], + [240., 486., 738., 756., 774., 522., 264.], + [170., 344., 522., 534., 546., 368., 186.], + [90., 182., 276., 282., 288., 194., 98.]], + + [[40., 81., 123., 126., 129., 87., 44.], + [85., 172., 261., 267., 273., 184., 93.], + [135., 273., 414., 423., 432., 291., 147.], + [150., 303., 459., 468., 477., 321., 162.], + [105., 212., 321., 327., 333., 224., 113.], + [55., 111., 168., 171., 174., 117., 59.]]]]]).astype(np.float32) + +expect(node, inputs=[x, W], outputs=[y], name='test_convtranspose_3d') +``` + +
+
+convtranspose_attributes + +```python +x = np.array([[[[0., 1., 2.], # (1, 1, 3, 3) + [3., 4., 5.], + [6., 7., 8.]]]]).astype(np.float32) + +W = np.array([[[[1., 1., 1.], # (1, 2, 3, 3) + [1., 1., 1.], + [1., 1., 1.]], + [[1., 1., 1.], + [1., 1., 1.], + [1., 1., 1.]]]]).astype(np.float32) + +y = np.array([[[[0., 0., 1., 1., 3., 2., 2., 0.], # (1, 2, 10, 8) + [0., 0., 1., 1., 3., 2., 2., 0.], + [0., 0., 1., 1., 3., 2., 2., 0.], + [3., 3., 7., 4., 9., 5., 5., 0.], + [3., 3., 7., 4., 9., 5., 5., 0.], + [3., 3., 7., 4., 9., 5., 5., 0.], + [6., 6., 13., 7., 15., 8., 8., 0.], + [6., 6., 13., 7., 15., 8., 8., 0.], + [6., 6., 13., 7., 15., 8., 8., 0.], + [0., 0., 0., 0., 0., 0., 0., 0.]], + + [[0., 0., 1., 1., 3., 2., 2., 0.], + [0., 0., 1., 1., 3., 2., 2., 0.], + [0., 0., 1., 1., 3., 2., 2., 0.], + [3., 3., 7., 4., 9., 5., 5., 0.], + [3., 3., 7., 4., 9., 5., 5., 0.], + [3., 3., 7., 4., 9., 5., 5., 0.], + [6., 6., 13., 7., 15., 8., 8., 0.], + [6., 6., 13., 7., 15., 8., 8., 0.], + [6., 6., 13., 7., 15., 8., 8., 0.], + [0., 0., 0., 0., 0., 0., 0., 0.]]]]).astype(np.float32) + +node = onnx.helper.make_node("ConvTranspose", ["X", "W"], ["Y"], + strides=[3, 2], + output_shape=[10, 8]) +expect(node, inputs=[x, W], outputs=[y], name='test_convtranspose_output_shape') + +node = onnx.helper.make_node("ConvTranspose", ["X", "W"], ["Y"], + strides=[3, 2], + output_padding=[1, 1]) +expect(node, inputs=[x, W], outputs=[y], name='test_convtranspose_pad') + +node = onnx.helper.make_node( + 'ConvTranspose', ['X', 'W'], ['Y'], + name='test', + strides=[3, 2], + output_shape=[10, 8], + kernel_shape=[3, 3], + output_padding=[1, 1] +) +expect(node, inputs=[x, W], outputs=[y], + name='test_convtranspose_kernel_shape') +``` + +
+
+convtranspose_autopad_same + +```python +x = np.array([[[[0., 1., 2.], # (1, 1, 3, 3) + [3., 4., 5.], + [6., 7., 8.]]]]).astype(np.float32) + +W = np.array([[[[1., 1., 1.], # (1, 2, 3, 3) + [1., 1., 1.], + [1., 1., 1.]], + [[1., 1., 1.], + [1., 1., 1.], + [1., 1., 1.]]]]).astype(np.float32) + +node = onnx.helper.make_node("ConvTranspose", ["X", "W"], ["Y"], auto_pad="SAME_UPPER", strides=[2, 2]) + +y = np.array([[[[0., 0., 1., 1., 3., 2.], + [0., 0., 1., 1., 3., 2.], + [3., 3., 8., 5., 12., 7.], + [3., 3., 7., 4., 9., 5.], + [9., 9., 20., 11., 24., 13.], + [6., 6., 13., 7., 15., 8.]], + + [[0., 0., 1., 1., 3., 2.], + [0., 0., 1., 1., 3., 2.], + [3., 3., 8., 5., 12., 7.], + [3., 3., 7., 4., 9., 5.], + [9., 9., 20., 11., 24., 13.], + [6., 6., 13., 7., 15., 8.]]]]).astype(np.float32) + +expect(node, inputs=[x, W], outputs=[y], name='test_convtranspose_autopad_same') +``` + +
+
+convtranspose_dilations + +```python +x = np.array([[[[3., 8., 1.], # (1, 1, 3, 3) + [9., 5., 7.], + [3., 2., 6.]]]]).astype(np.float32) +W = np.array([[[[7., 2.], # (1, 1, 2, 2) + [1., 9.]]]]).astype(np.float32) + +node = onnx.helper.make_node("ConvTranspose", ["X", "W"], ["Y"], dilations=[2, 2]) + +y = np.array([[[[21., 56., 13., 16., 2.], # [1, 1, 5, 5] + [63., 35., 67., 10., 14.], + [24., 22., 76., 76., 21.], + [9., 5., 88., 45., 63.], + [3., 2., 33., 18., 54.]]]]).astype(np.float32) + +expect(node, inputs=[x, W], outputs=[y], name='test_convtranspose_dilations') +``` + +
+
+convtranspose_pads + +```python +x = np.array([[[[0., 1., 2.], # (1, 1, 3, 3) + [3., 4., 5.], + [6., 7., 8.]]]]).astype(np.float32) + +W = np.array([[[[1., 1., 1.], # (1, 2, 3, 3) + [1., 1., 1.], + [1., 1., 1.]], + [[1., 1., 1.], + [1., 1., 1.], + [1., 1., 1.]]]]).astype(np.float32) + +node = onnx.helper.make_node("ConvTranspose", ["X", "W"], ["Y"], + strides=[3, 2], + pads=[1, 2, 1, 2]) + +y = np.array([[[[1., 1., 3.], # (1, 2, 7, 3) + [1., 1., 3.], + [7., 4., 9.], + [7., 4., 9.], + [7., 4., 9.], + [13., 7., 15.], + [13., 7., 15.]], + + [[1., 1., 3.], + [1., 1., 3.], + [7., 4., 9.], + [7., 4., 9.], + [7., 4., 9.], + [13., 7., 15.], + [13., 7., 15.]]]]).astype(np.float32) + +expect(node, inputs=[x, W], outputs=[y], name='test_convtranspose_pads') +``` + +
+ + +### Cos +There are 1 test cases, listed as following: +
+cos + +```python +node = onnx.helper.make_node( + 'Cos', + inputs=['x'], + outputs=['y'], +) + +x = np.array([-1, 0, 1]).astype(np.float32) +y = np.cos(x) +expect(node, inputs=[x], outputs=[y], + name='test_cos_example') + +x = np.random.randn(3, 4, 5).astype(np.float32) +y = np.cos(x) +expect(node, inputs=[x], outputs=[y], + name='test_cos') +``` + +
+ + +### Cosh +There are 1 test cases, listed as following: +
+cosh + +```python +node = onnx.helper.make_node( + 'Cosh', + inputs=['x'], + outputs=['y'], +) + +x = np.array([-1, 0, 1]).astype(np.float32) +y = np.cosh(x) # expected output [1.54308069, 1., 1.54308069] +expect(node, inputs=[x], outputs=[y], + name='test_cosh_example') + +x = np.random.randn(3, 4, 5).astype(np.float32) +y = np.cosh(x) +expect(node, inputs=[x], outputs=[y], + name='test_cosh') +``` + +
+ + +### CumSum +There are 7 test cases, listed as following: +
+cumsum_1d + +```python +node = onnx.helper.make_node( + 'CumSum', + inputs=['x', 'axis'], + outputs=['y'] +) +x = np.array([1., 2., 3., 4., 5.]).astype(np.float64) +axis = np.int32(0) +y = np.array([1., 3., 6., 10., 15.]).astype(np.float64) +expect(node, inputs=[x, axis], outputs=[y], + name='test_cumsum_1d') +``` + +
+
+cumsum_1d_exclusive + +```python +node = onnx.helper.make_node( + 'CumSum', + inputs=['x', 'axis'], + outputs=['y'], + exclusive=1 +) +x = np.array([1., 2., 3., 4., 5.]).astype(np.float64) +axis = np.int32(0) +y = np.array([0., 1., 3., 6., 10.]).astype(np.float64) +expect(node, inputs=[x, axis], outputs=[y], + name='test_cumsum_1d_exclusive') +``` + +
+
+cumsum_1d_reverse + +```python +node = onnx.helper.make_node( + 'CumSum', + inputs=['x', 'axis'], + outputs=['y'], + reverse=1 +) +x = np.array([1., 2., 3., 4., 5.]).astype(np.float64) +axis = np.int32(0) +y = np.array([15., 14., 12., 9., 5.]).astype(np.float64) +expect(node, inputs=[x, axis], outputs=[y], + name='test_cumsum_1d_reverse') +``` + +
+
+cumsum_1d_reverse_exclusive + +```python +node = onnx.helper.make_node( + 'CumSum', + inputs=['x', 'axis'], + outputs=['y'], + reverse=1, + exclusive=1 +) +x = np.array([1., 2., 3., 4., 5.]).astype(np.float64) +axis = np.int32(0) +y = np.array([14., 12., 9., 5., 0.]).astype(np.float64) +expect(node, inputs=[x, axis], outputs=[y], + name='test_cumsum_1d_reverse_exclusive') +``` + +
+
+cumsum_2d_axis_0 + +```python +node = onnx.helper.make_node( + 'CumSum', + inputs=['x', 'axis'], + outputs=['y'], +) +x = np.array([1., 2., 3., 4., 5., 6.]).astype(np.float64).reshape((2, 3)) +axis = np.int32(0) +y = np.array([1., 2., 3., 5., 7., 9.]).astype(np.float64).reshape((2, 3)) +expect(node, inputs=[x, axis], outputs=[y], + name='test_cumsum_2d_axis_0') +``` + +
+
+cumsum_2d_axis_1 + +```python +node = onnx.helper.make_node( + 'CumSum', + inputs=['x', 'axis'], + outputs=['y'], +) +x = np.array([1., 2., 3., 4., 5., 6.]).astype(np.float64).reshape((2, 3)) +axis = np.int32(1) +y = np.array([1., 3., 6., 4., 9., 15.]).astype(np.float64).reshape((2, 3)) +expect(node, inputs=[x, axis], outputs=[y], + name='test_cumsum_2d_axis_1') +``` + +
+
+cumsum_2d_negative_axis + +```python +node = onnx.helper.make_node( + 'CumSum', + inputs=['x', 'axis'], + outputs=['y'], +) +x = np.array([1., 2., 3., 4., 5., 6.]).astype(np.float64).reshape((2, 3)) +axis = np.int32(-1) +y = np.array([1., 3., 6., 4., 9., 15.]).astype(np.float64).reshape((2, 3)) +expect(node, inputs=[x, axis], outputs=[y], + name='test_cumsum_2d_negative_axis') +``` + +
+ + +### DepthToSpace +There are 2 test cases, listed as following: +
+crd_mode_example + +```python +node = onnx.helper.make_node( + 'DepthToSpace', + inputs=['x'], + outputs=['y'], + blocksize=2, + mode='CRD' +) + +# (1, 8, 2, 3) input tensor +x = np.array([[[[0., 1., 2.], + [3., 4., 5.]], + [[9., 10., 11.], + [12., 13., 14.]], + [[18., 19., 20.], + [21., 22., 23.]], + [[27., 28., 29.], + [30., 31., 32.]], + [[36., 37., 38.], + [39., 40., 41.]], + [[45., 46., 47.], + [48., 49., 50.]], + [[54., 55., 56.], + [57., 58., 59.]], + [[63., 64., 65.], + [66., 67., 68.]]]]).astype(np.float32) + +# (1, 2, 4, 6) output tensor +y = np.array([[[[0., 9., 1., 10., 2., 11.], + [18., 27., 19., 28., 20., 29.], + [3., 12., 4., 13., 5., 14.], + [21., 30., 22., 31., 23., 32.]], + [[36., 45., 37., 46., 38., 47.], + [54., 63., 55., 64., 56., 65.], + [39., 48., 40., 49., 41., 50.], + [57., 66., 58., 67., 59., 68.]]]]).astype(np.float32) +expect(node, inputs=[x], outputs=[y], + name='test_depthtospace_crd_mode_example') +``` + +
+
+default_mode_example + +```python +node = onnx.helper.make_node( + 'DepthToSpace', + inputs=['x'], + outputs=['y'], + blocksize=2, + mode='DCR' +) + +# (1, 8, 2, 3) input tensor +x = np.array([[[[0., 1., 2.], + [3., 4., 5.]], + [[9., 10., 11.], + [12., 13., 14.]], + [[18., 19., 20.], + [21., 22., 23.]], + [[27., 28., 29.], + [30., 31., 32.]], + [[36., 37., 38.], + [39., 40., 41.]], + [[45., 46., 47.], + [48., 49., 50.]], + [[54., 55., 56.], + [57., 58., 59.]], + [[63., 64., 65.], + [66., 67., 68.]]]]).astype(np.float32) + +# (1, 2, 4, 6) output tensor +y = np.array([[[[0., 18., 1., 19., 2., 20.], + [36., 54., 37., 55., 38., 56.], + [3., 21., 4., 22., 5., 23.], + [39., 57., 40., 58., 41., 59.]], + [[9., 27., 10., 28., 11., 29.], + [45., 63., 46., 64., 47., 65.], + [12., 30., 13., 31., 14., 32.], + [48., 66., 49., 67., 50., 68.]]]]).astype(np.float32) +expect(node, inputs=[x], outputs=[y], + name='test_depthtospace_example') +``` + +
+ + +### DequantizeLinear +There are 2 test cases, listed as following: +
+axis + +```python +node = onnx.helper.make_node('DequantizeLinear', + inputs=['x', 'x_scale', 'x_zero_point'], + outputs=['y'],) + +# 1-D tensor zero point and scale of size equal to axis 1 of the input tensor +x = np.array([[[[3, 89], + [34, 200], + [74, 59]], + + [[5, 24], + [24, 87], + [32, 13]], + + [[245, 99], + [4, 142], + [121, 102]], ], ], dtype=np.uint8) +x_scale = np.array([2, 4, 5], dtype=np.float32) +x_zero_point = np.array([84, 24, 196], dtype=np.uint8) +y = (x.astype(np.float32) - x_zero_point.reshape(1, 3, 1, 1).astype(np.float32)) * x_scale.reshape(1, 3, 1, 1) + +expect(node, inputs=[x, x_scale, x_zero_point], outputs=[y], + name='test_dequantizelinear_axis') +``` + +
+
+dequantizelinear + +```python +node = onnx.helper.make_node('DequantizeLinear', + inputs=['x', 'x_scale', 'x_zero_point'], + outputs=['y'],) + +# scalar zero point and scale +x = np.array([0, 3, 128, 255]).astype(np.uint8) +x_scale = np.float32(2) +x_zero_point = np.uint8(128) +y = np.array([-256, -250, 0, 254], dtype=np.float32) + +expect(node, inputs=[x, x_scale, x_zero_point], outputs=[y], + name='test_dequantizelinear') +``` + +
+ + +### Det +There are 2 test cases, listed as following: +
+2d + +```python +node = onnx.helper.make_node( + 'Det', + inputs=['x'], + outputs=['y'], +) + +x = np.arange(4).reshape(2, 2).astype(np.float32) +y = np.linalg.det(x) # expect -2 +expect(node, inputs=[x], outputs=[y], + name='test_det_2d') +``` + +
+
+nd + +```python +node = onnx.helper.make_node( + 'Det', + inputs=['x'], + outputs=['y'], +) + +x = np.array([[[1, 2], [3, 4]], [[1, 2], [2, 1]], [[1, 3], [3, 1]]]).astype(np.float32) +y = np.linalg.det(x) # expect array([-2., -3., -8.]) +expect(node, inputs=[x], outputs=[y], + name='test_det_nd') +``` + +
+ + +### Div +There are 2 test cases, listed as following: +
+div + +```python +node = onnx.helper.make_node( + 'Div', + inputs=['x', 'y'], + outputs=['z'], +) + +x = np.array([3, 4]).astype(np.float32) +y = np.array([1, 2]).astype(np.float32) +z = x / y # expected output [3., 2.] +expect(node, inputs=[x, y], outputs=[z], + name='test_div_example') + +x = np.random.randn(3, 4, 5).astype(np.float32) +y = np.random.rand(3, 4, 5).astype(np.float32) + 1.0 +z = x / y +expect(node, inputs=[x, y], outputs=[z], + name='test_div') + +x = np.random.randint(24, size=(3, 4, 5), dtype=np.uint8) +y = np.random.randint(24, size=(3, 4, 5), dtype=np.uint8) + 1 +z = x // y +expect(node, inputs=[x, y], outputs=[z], + name='test_div_uint8') +``` + +
+
+div_broadcast + +```python +node = onnx.helper.make_node( + 'Div', + inputs=['x', 'y'], + outputs=['z'], +) + +x = np.random.randn(3, 4, 5).astype(np.float32) +y = np.random.rand(5).astype(np.float32) + 1.0 +z = x / y +expect(node, inputs=[x, y], outputs=[z], + name='test_div_bcast') +``` + +
+ + +### Dropout +There are 12 test cases, listed as following: +
+default + +```python +seed = np.int64(0) +node = onnx.helper.make_node( + 'Dropout', + inputs=['x'], + outputs=['y'], + seed=seed +) + +x = np.random.randn(3, 4, 5).astype(np.float32) +y = dropout(x) +expect(node, inputs=[x], outputs=[y], name='test_dropout_default') +``` + +
+
+default_mask + +```python +seed = np.int64(0) +node = onnx.helper.make_node( + 'Dropout', + inputs=['x'], + outputs=['y', 'z'], + seed=seed +) + +x = np.random.randn(3, 4, 5).astype(np.float32) +y, z = dropout(x, return_mask=True) +expect(node, inputs=[x], outputs=[y, z], name='test_dropout_default_mask') +``` + +
+
+default_mask_ratio + +```python +seed = np.int64(0) +node = onnx.helper.make_node( + 'Dropout', + inputs=['x', 'r'], + outputs=['y', 'z'], + seed=seed +) + +r = np.float32(0.1) +x = np.random.randn(3, 4, 5).astype(np.float32) +y, z = dropout(x, r, return_mask=True) +expect(node, inputs=[x, r], outputs=[y, z], name='test_dropout_default_mask_ratio') +``` + +
+
+default_old + +```python +node = onnx.helper.make_node( + 'Dropout', + inputs=['x'], + outputs=['y'], +) + +x = np.array([-1, 0, 1]).astype(np.float32) +y = x +expect(node, inputs=[x], outputs=[y], + name='test_dropout_default_old', opset_imports=[helper.make_opsetid("", 11)]) +``` + +
+
+default_ratio + +```python +seed = np.int64(0) +node = onnx.helper.make_node( + 'Dropout', + inputs=['x', 'r'], + outputs=['y'], + seed=seed +) + +r = np.float32(0.1) +x = np.random.randn(3, 4, 5).astype(np.float32) +y = dropout(x, r) +expect(node, inputs=[x, r], outputs=[y], name='test_dropout_default_ratio') +``` + +
+
+random_old + +```python +node = onnx.helper.make_node( + 'Dropout', + inputs=['x'], + outputs=['y'], + ratio=.2, +) + +x = np.random.randn(3, 4, 5).astype(np.float32) +y = x +expect(node, inputs=[x], outputs=[y], + name='test_dropout_random_old', opset_imports=[helper.make_opsetid("", 11)]) +``` + +
+
+training + +```python +seed = np.int64(0) +node = onnx.helper.make_node( + 'Dropout', + inputs=['x', 'r', 't'], + outputs=['y'], + seed=seed +) + +x = np.random.randn(3, 4, 5).astype(np.float32) +r = np.float32(0.75) +t = np.bool_(True) +y = dropout(x, r, training_mode=t) +expect(node, inputs=[x, r, t], outputs=[y], name='test_training_dropout') +``` + +
+
+training_default + +```python +seed = np.int64(0) +node = onnx.helper.make_node( + 'Dropout', + inputs=['x', 'r', 't'], + outputs=['y'], + seed=seed +) + +x = np.random.randn(3, 4, 5).astype(np.float32) +r = np.float32(0.5) +t = np.bool_(True) +y = dropout(x, r, training_mode=t) +expect(node, inputs=[x, r, t], outputs=[y], name='test_training_dropout_default') +``` + +
+
+training_default_ratio_mask + +```python +seed = np.int64(0) +node = onnx.helper.make_node( + 'Dropout', + inputs=['x', 'r', 't'], + outputs=['y', 'z'], + seed=seed +) + +x = np.random.randn(3, 4, 5).astype(np.float32) +r = np.float32(0.5) +t = np.bool_(True) +y, z = dropout(x, r, training_mode=t, return_mask=True) +expect(node, inputs=[x, r, t], outputs=[y, z], name='test_training_dropout_default_mask') +``` + +
+
+training_default_zero_ratio + +```python +seed = np.int64(0) +node = onnx.helper.make_node( + 'Dropout', + inputs=['x', 'r', 't'], + outputs=['y'], + seed=seed +) + +x = np.random.randn(3, 4, 5).astype(np.float32) +r = np.float32(0.0) +t = np.bool_(True) +y = dropout(x, r, training_mode=t) +expect(node, inputs=[x, r, t], outputs=[y], name='test_training_dropout_zero_ratio') +``` + +
+
+training_default_zero_ratio_mask + +```python +seed = np.int64(0) +node = onnx.helper.make_node( + 'Dropout', + inputs=['x', 'r', 't'], + outputs=['y', 'z'], + seed=seed +) + +x = np.random.randn(3, 4, 5).astype(np.float32) +r = np.float32(0.0) +t = np.bool_(True) +y, z = dropout(x, r, training_mode=t, return_mask=True) +expect(node, inputs=[x, r, t], outputs=[y, z], name='test_training_dropout_zero_ratio_mask') +``` + +
+
+training_ratio_mask + +```python +seed = np.int64(0) +node = onnx.helper.make_node( + 'Dropout', + inputs=['x', 'r', 't'], + outputs=['y', 'z'], + seed=seed +) + +x = np.random.randn(3, 4, 5).astype(np.float32) +r = np.float32(0.75) +t = np.bool_(True) +y, z = dropout(x, r, training_mode=t, return_mask=True) +expect(node, inputs=[x, r, t], outputs=[y, z], name='test_training_dropout_mask') +``` + +
+ + +### DynamicQuantizeLinear +There are 1 test cases, listed as following: +
+dynamicquantizelinear + +```python +node = onnx.helper.make_node('DynamicQuantizeLinear', + inputs=['x'], + outputs=['y', 'y_scale', 'y_zero_point'], +) + +# expected scale 0.0196078438 and zero point 153 +X = np.array([0, 2, -3, -2.5, 1.34, 0.5]).astype(np.float32) +x_min = np.minimum(0, np.min(X)) +x_max = np.maximum(0, np.max(X)) +Y_Scale = np.float32((x_max - x_min) / (255 - 0)) # uint8 -> [0, 255] +Y_ZeroPoint = np.clip(round((0 - x_min) / Y_Scale), 0, 255).astype(np.uint8) +Y = np.clip(np.round(X / Y_Scale) + Y_ZeroPoint, 0, 255).astype(np.uint8) + +expect(node, inputs=[X], outputs=[Y, Y_Scale, Y_ZeroPoint], + name='test_dynamicquantizelinear') + +# expected scale 0.0156862754 and zero point 255 +X = np.array([-1.0, -2.1, -1.3, -2.5, -3.34, -4.0]).astype(np.float32) +x_min = np.minimum(0, np.min(X)) +x_max = np.maximum(0, np.max(X)) +Y_Scale = np.float32((x_max - x_min) / (255 - 0)) # uint8 -> [0, 255] +Y_ZeroPoint = np.clip(round((0 - x_min) / Y_Scale), 0, 255).astype(np.uint8) +Y = np.clip(np.round(X / Y_Scale) + Y_ZeroPoint, 0, 255).astype(np.uint8) + +expect(node, inputs=[X], outputs=[Y, Y_Scale, Y_ZeroPoint], + name='test_dynamicquantizelinear_max_adjusted') + +X = np.array([1, 2.1, 1.3, 2.5, + 3.34, 4.0, 1.5, 2.6, + 3.9, 4.0, 3.0, 2.345]).astype(np.float32).reshape((3, 4)) + +# expected scale 0.0156862754 and zero point 0 +x_min = np.minimum(0, np.min(X)) +x_max = np.maximum(0, np.max(X)) +Y_Scale = np.float32((x_max - x_min) / (255 - 0)) # uint8 -> [0, 255] +Y_ZeroPoint = np.clip(round((0 - x_min) / Y_Scale), 0, 255).astype(np.uint8) +Y = np.clip(np.round(X / Y_Scale) + Y_ZeroPoint, 0, 255).astype(np.uint8) + +expect(node, inputs=[X], outputs=[Y, Y_Scale, Y_ZeroPoint], + name='test_dynamicquantizelinear_min_adjusted') +``` + +
+ + +### Einsum +There are 5 test cases, listed as following: +
+einsum_batch_diagonal + +```python +Eqn = '...ii ->...i' +node = onnx.helper.make_node( + 'Einsum', + inputs=['x'], + outputs=['y'], + equation=Eqn +) + +X = np.random.randn(3, 5, 5) +Z = einsum_reference_implementation(Eqn, (X,)) + +expect(node, inputs=[X], outputs=[Z], name='test_einsum_batch_diagonal') +``` + +
+
+einsum_batch_matmul + +```python +Eqn = 'bij, bjk -> bik' +node = onnx.helper.make_node( + 'Einsum', + inputs=['x', 'y'], + outputs=['z'], + equation=Eqn +) + +X = np.random.randn(5, 2, 3) +Y = np.random.randn(5, 3, 4) +Z = einsum_reference_implementation(Eqn, (X, Y)) + +expect(node, inputs=[X, Y], outputs=[Z], name='test_einsum_batch_matmul') +``` + +
+
+einsum_inner_prod + +```python +Eqn = 'i,i' +node = onnx.helper.make_node( + 'Einsum', + inputs=['x', 'y'], + outputs=['z'], + equation=Eqn +) + +X = np.random.randn(5) +Y = np.random.randn(5) +Z = einsum_reference_implementation(Eqn, (X, Y)) + +expect(node, inputs=[X, Y], outputs=[Z], name='test_einsum_inner_prod') +``` + +
+
+einsum_sum + +```python +Eqn = 'ij->i' +node = onnx.helper.make_node( + 'Einsum', + inputs=['x'], + outputs=['y'], + equation=Eqn +) + +X = np.random.randn(3, 4) +Z = einsum_reference_implementation(Eqn, (X,)) + +expect(node, inputs=[X], outputs=[Z], name='test_einsum_sum') +``` + +
+
+einsum_transpose + +```python +Eqn = 'ij->ji' +node = onnx.helper.make_node( + 'Einsum', + inputs=['x'], + outputs=['y'], + equation=Eqn +) + +X = np.random.randn(3, 4) +Y = einsum_reference_implementation(Eqn, (X,)) + +expect(node, inputs=[X], outputs=[Y], name='test_einsum_transpose') +``` + +
+ + +### Elu +There are 2 test cases, listed as following: +
+elu + +```python +node = onnx.helper.make_node( + 'Elu', + inputs=['x'], + outputs=['y'], + alpha=2.0 +) + +x = np.array([-1, 0, 1]).astype(np.float32) +# expected output [-1.2642411, 0., 1.] +y = np.clip(x, 0, np.inf) + (np.exp(np.clip(x, -np.inf, 0)) - 1) * 2.0 +expect(node, inputs=[x], outputs=[y], + name='test_elu_example') + +x = np.random.randn(3, 4, 5).astype(np.float32) +y = np.clip(x, 0, np.inf) + (np.exp(np.clip(x, -np.inf, 0)) - 1) * 2.0 +expect(node, inputs=[x], outputs=[y], + name='test_elu') +``` + +
+
+elu_default + +```python +default_alpha = 1.0 +node = onnx.helper.make_node( + 'Elu', + inputs=['x'], + outputs=['y'], +) +x = np.random.randn(3, 4, 5).astype(np.float32) +y = np.clip(x, 0, np.inf) + (np.exp(np.clip(x, -np.inf, 0)) - 1) * default_alpha +expect(node, inputs=[x], outputs=[y], + name='test_elu_default') +``` + +
+ + +### Equal +There are 2 test cases, listed as following: +
+equal + +```python +node = onnx.helper.make_node( + 'Equal', + inputs=['x', 'y'], + outputs=['z'], +) + +x = (np.random.randn(3, 4, 5) * 10).astype(np.int32) +y = (np.random.randn(3, 4, 5) * 10).astype(np.int32) +z = np.equal(x, y) +expect(node, inputs=[x, y], outputs=[z], + name='test_equal') +``` + +
+
+equal_broadcast + +```python +node = onnx.helper.make_node( + 'Equal', + inputs=['x', 'y'], + outputs=['z'], +) + +x = (np.random.randn(3, 4, 5) * 10).astype(np.int32) +y = (np.random.randn(5) * 10).astype(np.int32) +z = np.equal(x, y) +expect(node, inputs=[x, y], outputs=[z], + name='test_equal_bcast') +``` + +
+ + +### Erf +There are 1 test cases, listed as following: +
+erf + +```python +node = onnx.helper.make_node( + 'Erf', + inputs=['x'], + outputs=['y'], +) + +x = np.random.randn(1, 3, 32, 32).astype(np.float32) +y = np.vectorize(math.erf)(x).astype(np.float32) +expect(node, inputs=[x], outputs=[y], + name='test_erf') +``` + +
+ + +### Exp +There are 1 test cases, listed as following: +
+exp + +```python +node = onnx.helper.make_node( + 'Exp', + inputs=['x'], + outputs=['y'], +) + +x = np.array([-1, 0, 1]).astype(np.float32) +y = np.exp(x) # expected output [0.36787945, 1., 2.71828175] +expect(node, inputs=[x], outputs=[y], + name='test_exp_example') + +x = np.random.randn(3, 4, 5).astype(np.float32) +y = np.exp(x) +expect(node, inputs=[x], outputs=[y], + name='test_exp') +``` + +
+ + +### Expand +There are 2 test cases, listed as following: +
+dim_changed + +```python +node = onnx.helper.make_node( + 'Expand', + inputs=['data', 'new_shape'], + outputs=['expanded'], +) +shape = [3, 1] +data = np.reshape(np.arange(1, np.prod(shape) + 1, dtype=np.float32), shape) +#print(data) +#[[1.], [2.], [3.]] +new_shape = [2, 1, 6] +expanded = data * np.ones(new_shape, dtype=np.float32) +#print(expanded) +#[[[1., 1., 1., 1., 1., 1.], +# [2., 2., 2., 2., 2., 2.], +# [3., 3., 3., 3., 3., 3.]], +# +# [[1., 1., 1., 1., 1., 1.], +# [2., 2., 2., 2., 2., 2.], +# [3., 3., 3., 3., 3., 3.]]] +new_shape = np.array(new_shape, dtype=np.int64) +expect(node, inputs=[data, new_shape], outputs=[expanded], + name='test_expand_dim_changed') +``` + +
+
+dim_unchanged + +```python +node = onnx.helper.make_node( + 'Expand', + inputs=['data', 'new_shape'], + outputs=['expanded'], +) +shape = [3, 1] +new_shape = [3, 4] +data = np.reshape(np.arange(1, np.prod(shape) + 1, dtype=np.float32), shape) +#print(data) +#[[1.], [2.], [3.]] +expanded = np.tile(data, 4) +#print(expanded) +#[[1., 1., 1., 1.], +# [2., 2., 2., 2.], +# [3., 3., 3., 3.]] +new_shape = np.array(new_shape, dtype=np.int64) +expect(node, inputs=[data, new_shape], outputs=[expanded], + name='test_expand_dim_unchanged') +``` + +
+ + +### EyeLike +There are 3 test cases, listed as following: +
+populate_off_main_diagonal + +```python +shape = (4, 5) +off_diagonal_offset = 1 +node = onnx.helper.make_node( + 'EyeLike', + inputs=['x'], + outputs=['y'], + k=off_diagonal_offset, + dtype=onnx.TensorProto.FLOAT, +) + +x = np.random.randint(0, 100, size=shape, dtype=np.int32) +y = np.eye(shape[0], shape[1], k=off_diagonal_offset, dtype=np.float32) +expect(node, inputs=[x], outputs=[y], name='test_eyelike_populate_off_main_diagonal') +``` + +
+
+with_dtype + +```python +shape = (3, 4) +node = onnx.helper.make_node( + 'EyeLike', + inputs=['x'], + outputs=['y'], + dtype=onnx.TensorProto.DOUBLE, +) + +x = np.random.randint(0, 100, size=shape, dtype=np.int32) +y = np.eye(shape[0], shape[1], dtype=np.float64) +expect(node, inputs=[x], outputs=[y], name='test_eyelike_with_dtype') +``` + +
+
+without_dtype + +```python +shape = (4, 4) +node = onnx.helper.make_node( + 'EyeLike', + inputs=['x'], + outputs=['y'], +) + +x = np.random.randint(0, 100, size=shape, dtype=np.int32) +y = np.eye(shape[0], shape[1], dtype=np.int32) +expect(node, inputs=[x], outputs=[y], name='test_eyelike_without_dtype') +``` + +
+ + +### Flatten +There are 3 test cases, listed as following: +
+flatten + +```python +shape = (2, 3, 4, 5) +a = np.random.random_sample(shape).astype(np.float32) + +for i in range(len(shape)): + node = onnx.helper.make_node( + 'Flatten', + inputs=['a'], + outputs=['b'], + axis=i, + ) + + new_shape = (1, -1) if i == 0 else (np.prod(shape[0:i]).astype(int), -1) + b = np.reshape(a, new_shape) + expect(node, inputs=[a], outputs=[b], + name='test_flatten_axis' + str(i)) +``` + +
+
+flatten_negative_axis + +```python +shape = (2, 3, 4, 5) +a = np.random.random_sample(shape).astype(np.float32) + +for i in range(-len(shape), 0): + node = onnx.helper.make_node( + 'Flatten', + inputs=['a'], + outputs=['b'], + axis=i, + ) + + new_shape = (np.prod(shape[0:i]).astype(int), -1) + b = np.reshape(a, new_shape) + expect(node, inputs=[a], outputs=[b], + name='test_flatten_negative_axis' + str(abs(i))) +``` + +
+
+flatten_with_default_axis + +```python +node = onnx.helper.make_node( + 'Flatten', + inputs=['a'], + outputs=['b'], # Default value for axis: axis=1 +) + +shape = (5, 4, 3, 2) +a = np.random.random_sample(shape).astype(np.float32) +new_shape = (5, 24) +b = np.reshape(a, new_shape) +expect(node, inputs=[a], outputs=[b], + name='test_flatten_default_axis') +``` + +
+ + +### Floor +There are 1 test cases, listed as following: +
+floor + +```python +node = onnx.helper.make_node( + 'Floor', + inputs=['x'], + outputs=['y'], +) + +x = np.array([-1.5, 1.2, 2]).astype(np.float32) +y = np.floor(x) # expected output [-2., 1., 2.] +expect(node, inputs=[x], outputs=[y], + name='test_floor_example') + +x = np.random.randn(3, 4, 5).astype(np.float32) +y = np.floor(x) +expect(node, inputs=[x], outputs=[y], + name='test_floor') +``` + +
+ + +### GRU +There are 4 test cases, listed as following: +
+batchwise + +```python +input = np.array([[[1., 2.]], [[3., 4.]], [[5., 6.]]]).astype(np.float32) + +input_size = 2 +hidden_size = 6 +number_of_gates = 3 +weight_scale = 0.2 +layout = 1 + +node = onnx.helper.make_node( + 'GRU', + inputs=['X', 'W', 'R'], + outputs=['Y', 'Y_h'], + hidden_size=hidden_size, + layout=layout +) + +W = weight_scale * np.ones((1, number_of_gates * hidden_size, input_size)).astype(np.float32) +R = weight_scale * np.ones((1, number_of_gates * hidden_size, hidden_size)).astype(np.float32) + +gru = GRU_Helper(X=input, W=W, R=R, layout=layout) +Y, Y_h = gru.step() +expect(node, inputs=[input, W, R], outputs=[Y.astype(np.float32), Y_h.astype(np.float32)], name='test_gru_batchwise') +``` + +
+
+defaults + +```python +input = np.array([[[1., 2.], [3., 4.], [5., 6.]]]).astype(np.float32) + +input_size = 2 +hidden_size = 5 +weight_scale = 0.1 +number_of_gates = 3 + +node = onnx.helper.make_node( + 'GRU', + inputs=['X', 'W', 'R'], + outputs=['', 'Y_h'], + hidden_size=hidden_size +) + +W = weight_scale * np.ones((1, number_of_gates * hidden_size, input_size)).astype(np.float32) +R = weight_scale * np.ones((1, number_of_gates * hidden_size, hidden_size)).astype(np.float32) + +gru = GRU_Helper(X=input, W=W, R=R) +_, Y_h = gru.step() +expect(node, inputs=[input, W, R], outputs=[Y_h.astype(np.float32)], name='test_gru_defaults') +``` + +
+
+initial_bias + +```python +input = np.array([[[1., 2., 3.], [4., 5., 6.], [7., 8., 9.]]]).astype(np.float32) + +input_size = 3 +hidden_size = 3 +weight_scale = 0.1 +custom_bias = 0.1 +number_of_gates = 3 + +node = onnx.helper.make_node( + 'GRU', + inputs=['X', 'W', 'R', 'B'], + outputs=['', 'Y_h'], + hidden_size=hidden_size +) + +W = weight_scale * np.ones((1, number_of_gates * hidden_size, input_size)).astype(np.float32) +R = weight_scale * np.ones((1, number_of_gates * hidden_size, hidden_size)).astype(np.float32) + +# Adding custom bias +W_B = custom_bias * np.ones((1, number_of_gates * hidden_size)).astype(np.float32) +R_B = np.zeros((1, number_of_gates * hidden_size)).astype(np.float32) +B = np.concatenate((W_B, R_B), axis=1) + +gru = GRU_Helper(X=input, W=W, R=R, B=B) +_, Y_h = gru.step() +expect(node, inputs=[input, W, R, B], outputs=[Y_h.astype(np.float32)], name='test_gru_with_initial_bias') +``` + +
+
+seq_length + +```python +input = np.array([[[1., 2., 3.], [4., 5., 6.], [7., 8., 9.]], + [[10., 11., 12.], [13., 14., 15.], [16., 17., 18.]]]).astype(np.float32) + +input_size = 3 +hidden_size = 5 +number_of_gates = 3 + +node = onnx.helper.make_node( + 'GRU', + inputs=['X', 'W', 'R', 'B'], + outputs=['', 'Y_h'], + hidden_size=hidden_size +) + +W = np.random.randn(1, number_of_gates * hidden_size, input_size).astype(np.float32) +R = np.random.randn(1, number_of_gates * hidden_size, hidden_size).astype(np.float32) + +# Adding custom bias +W_B = np.random.randn(1, number_of_gates * hidden_size).astype(np.float32) +R_B = np.random.randn(1, number_of_gates * hidden_size).astype(np.float32) +B = np.concatenate((W_B, R_B), axis=1) + +gru = GRU_Helper(X=input, W=W, R=R, B=B) +_, Y_h = gru.step() +expect(node, inputs=[input, W, R, B], outputs=[Y_h.astype(np.float32)], name='test_gru_seq_length') +``` + +
+ + +### Gather +There are 4 test cases, listed as following: +
+gather_0 + +```python +node = onnx.helper.make_node( + 'Gather', + inputs=['data', 'indices'], + outputs=['y'], + axis=0, +) +data = np.random.randn(5, 4, 3, 2).astype(np.float32) +indices = np.array([0, 1, 3]) +y = np.take(data, indices, axis=0) + +expect(node, inputs=[data, indices.astype(np.int64)], outputs=[y], + name='test_gather_0') +``` + +
+
+gather_1 + +```python +node = onnx.helper.make_node( + 'Gather', + inputs=['data', 'indices'], + outputs=['y'], + axis=1, +) +data = np.random.randn(5, 4, 3, 2).astype(np.float32) +indices = np.array([0, 1, 3]) +y = np.take(data, indices, axis=1) + +expect(node, inputs=[data, indices.astype(np.int64)], outputs=[y], + name='test_gather_1') +``` + +
+
+gather_2d_indices + +```python +node = onnx.helper.make_node( + 'Gather', + inputs=['data', 'indices'], + outputs=['y'], + axis=1, +) +data = np.random.randn(3, 3).astype(np.float32) +indices = np.array([[0, 2]]) +y = np.take(data, indices, axis=1) + +expect(node, inputs=[data, indices.astype(np.int64)], outputs=[y], + name='test_gather_2d_indices') +``` + +
+
+gather_negative_indices + +```python +node = onnx.helper.make_node( + 'Gather', + inputs=['data', 'indices'], + outputs=['y'], + axis=0, +) +data = np.arange(10).astype(np.float32) +indices = np.array([0, -9, -10]) +y = np.take(data, indices, axis=0) + +# print(y) +# [0. 1. 0.] + +expect(node, inputs=[data, indices.astype(np.int64)], outputs=[y], + name='test_gather_negative_indices') +``` + +
+ + +### GatherElements +There are 3 test cases, listed as following: +
+gather_elements_0 + +```python +axis = 1 +node = onnx.helper.make_node( + 'GatherElements', + inputs=['data', 'indices'], + outputs=['y'], + axis=axis, +) +data = np.array([[1, 2], + [3, 4]], dtype=np.float32) +indices = np.array([[0, 0], + [1, 0]], dtype=np.int32) + +y = gather_elements(data, indices, axis) +# print(y) produces +# [[1, 1], +# [4, 3]] + +expect(node, inputs=[data, indices.astype(np.int64)], outputs=[y], + name='test_gather_elements_0') +``` + +
+
+gather_elements_1 + +```python +axis = 0 +node = onnx.helper.make_node( + 'GatherElements', + inputs=['data', 'indices'], + outputs=['y'], + axis=axis, +) +data = np.array([[1, 2, 3], + [4, 5, 6], + [7, 8, 9]], dtype=np.float32) +indices = np.array([[1, 2, 0], + [2, 0, 0]], dtype=np.int32) + +y = gather_elements(data, indices, axis) +# print(y) produces +# [[4, 8, 3], +# [7, 2, 3]] + +expect(node, inputs=[data, indices.astype(np.int64)], outputs=[y], + name='test_gather_elements_1') +``` + +
+
+gather_elements_negative_indices + +```python +axis = 0 +node = onnx.helper.make_node( + 'GatherElements', + inputs=['data', 'indices'], + outputs=['y'], + axis=axis, +) +data = np.array([[1, 2, 3], + [4, 5, 6], + [7, 8, 9]], dtype=np.float32) +indices = np.array([[-1, -2, 0], + [-2, 0, 0]], dtype=np.int32) + +y = gather_elements(data, indices, axis) +# print(y) produces +# [[7, 5, 3], +# [4, 2, 3]] + +expect(node, inputs=[data, indices.astype(np.int64)], outputs=[y], + name='test_gather_elements_negative_indices') +``` + +
+ + +### GatherND +There are 3 test cases, listed as following: +
+float32 + +```python +node = onnx.helper.make_node( + 'GatherND', + inputs=['data', 'indices'], + outputs=['output'], +) + +data = np.array([[[0, 1], [2, 3]], [[4, 5], [6, 7]]], dtype=np.float32) +indices = np.array([[[0, 1]], [[1, 0]]], dtype=np.int64) +output = gather_nd_impl(data, indices, 0) +expected_output = np.array([[[2, 3]], [[4, 5]]], dtype=np.float32) +assert (np.array_equal(output, expected_output)) +expect(node, inputs=[data, indices], outputs=[output], + name='test_gathernd_example_float32') +``` + +
+
+int32 + +```python +node = onnx.helper.make_node( + 'GatherND', + inputs=['data', 'indices'], + outputs=['output'], +) + +data = np.array([[0, 1], [2, 3]], dtype=np.int32) +indices = np.array([[0, 0], [1, 1]], dtype=np.int64) +output = gather_nd_impl(data, indices, 0) +expected_output = np.array([0, 3], dtype=np.int32) +assert (np.array_equal(output, expected_output)) +expect(node, inputs=[data, indices], outputs=[output], + name='test_gathernd_example_int32') +``` + +
+
+int32_batchdim_1 + +```python +node = onnx.helper.make_node( + 'GatherND', + inputs=['data', 'indices'], + outputs=['output'], + batch_dims=1, +) + +data = np.array([[[0, 1], [2, 3]], [[4, 5], [6, 7]]], dtype=np.int32) +indices = np.array([[1], [0]], dtype=np.int64) +output = gather_nd_impl(data, indices, 1) +expected_output = np.array([[2, 3], [4, 5]], dtype=np.int32) +assert (np.array_equal(output, expected_output)) +expect(node, inputs=[data, indices], outputs=[output], + name='test_gathernd_example_int32_batch_dim1') +``` + +
+ + +### Gemm +There are 11 test cases, listed as following: +
+all_attributes + +```python +node = onnx.helper.make_node( + 'Gemm', + inputs=['a', 'b', 'c'], + outputs=['y'], + alpha=0.25, + beta=0.35, + transA=1, + transB=1 +) +a = np.random.ranf([4, 3]).astype(np.float32) +b = np.random.ranf([5, 4]).astype(np.float32) +c = np.random.ranf([1, 5]).astype(np.float32) +y = gemm_reference_implementation(a, b, c, transA=1, transB=1, alpha=0.25, beta=0.35) +expect(node, inputs=[a, b, c], outputs=[y], + name='test_gemm_all_attributes') +``` + +
+
+alpha + +```python +node = onnx.helper.make_node( + 'Gemm', + inputs=['a', 'b', 'c'], + outputs=['y'], + alpha=0.5 +) +a = np.random.ranf([3, 5]).astype(np.float32) +b = np.random.ranf([5, 4]).astype(np.float32) +c = np.zeros([1, 4]).astype(np.float32) +y = gemm_reference_implementation(a, b, c, alpha=0.5) +expect(node, inputs=[a, b, c], outputs=[y], + name='test_gemm_alpha') +``` + +
+
+beta + +```python +node = onnx.helper.make_node( + 'Gemm', + inputs=['a', 'b', 'c'], + outputs=['y'], + beta=0.5 +) +a = np.random.ranf([2, 7]).astype(np.float32) +b = np.random.ranf([7, 4]).astype(np.float32) +c = np.random.ranf([1, 4]).astype(np.float32) +y = gemm_reference_implementation(a, b, c, beta=0.5) +expect(node, inputs=[a, b, c], outputs=[y], + name='test_gemm_beta') +``` + +
+
+default_matrix_bias + +```python +node = onnx.helper.make_node( + 'Gemm', + inputs=['a', 'b', 'c'], + outputs=['y'] +) +a = np.random.ranf([3, 6]).astype(np.float32) +b = np.random.ranf([6, 4]).astype(np.float32) +c = np.random.ranf([3, 4]).astype(np.float32) +y = gemm_reference_implementation(a, b, c) +expect(node, inputs=[a, b, c], outputs=[y], + name='test_gemm_default_matrix_bias') +``` + +
+
+default_no_bias + +```python +node = onnx.helper.make_node( + 'Gemm', + inputs=['a', 'b'], + outputs=['y'] +) +a = np.random.ranf([2, 10]).astype(np.float32) +b = np.random.ranf([10, 3]).astype(np.float32) +y = gemm_reference_implementation(a, b) +expect(node, inputs=[a, b], outputs=[y], + name='test_gemm_default_no_bias') +``` + +
+
+default_scalar_bias + +```python +node = onnx.helper.make_node( + 'Gemm', + inputs=['a', 'b', 'c'], + outputs=['y'] +) +a = np.random.ranf([2, 3]).astype(np.float32) +b = np.random.ranf([3, 4]).astype(np.float32) +c = np.array(3.14).astype(np.float32) +y = gemm_reference_implementation(a, b, c) +expect(node, inputs=[a, b, c], outputs=[y], + name='test_gemm_default_scalar_bias') +``` + +
+
+default_single_elem_vector_bias + +```python +node = onnx.helper.make_node( + 'Gemm', + inputs=['a', 'b', 'c'], + outputs=['y'] +) +a = np.random.ranf([3, 7]).astype(np.float32) +b = np.random.ranf([7, 3]).astype(np.float32) +c = np.random.ranf([1]).astype(np.float32) +y = gemm_reference_implementation(a, b, c) +expect(node, inputs=[a, b, c], outputs=[y], + name='test_gemm_default_single_elem_vector_bias') +``` + +
+
+default_vector_bias + +```python +node = onnx.helper.make_node( + 'Gemm', + inputs=['a', 'b', 'c'], + outputs=['y'] +) +a = np.random.ranf([2, 7]).astype(np.float32) +b = np.random.ranf([7, 4]).astype(np.float32) +c = np.random.ranf([1, 4]).astype(np.float32) +y = gemm_reference_implementation(a, b, c) +expect(node, inputs=[a, b, c], outputs=[y], + name='test_gemm_default_vector_bias') +``` + +
+
+default_zero_bias + +```python +node = onnx.helper.make_node( + 'Gemm', + inputs=['a', 'b', 'c'], + outputs=['y'] +) +a = np.random.ranf([3, 5]).astype(np.float32) +b = np.random.ranf([5, 4]).astype(np.float32) +c = np.zeros([1, 4]).astype(np.float32) +y = gemm_reference_implementation(a, b, c) +expect(node, inputs=[a, b, c], outputs=[y], + name='test_gemm_default_zero_bias') +``` + +
+
+transposeA + +```python +node = onnx.helper.make_node( + 'Gemm', + inputs=['a', 'b', 'c'], + outputs=['y'], + transA=1 +) +a = np.random.ranf([6, 3]).astype(np.float32) +b = np.random.ranf([6, 4]).astype(np.float32) +c = np.zeros([1, 4]).astype(np.float32) +y = gemm_reference_implementation(a, b, c, transA=1) +expect(node, inputs=[a, b, c], outputs=[y], + name='test_gemm_transposeA') +``` + +
+
+transposeB + +```python +node = onnx.helper.make_node( + 'Gemm', + inputs=['a', 'b', 'c'], + outputs=['y'], + transB=1 +) +a = np.random.ranf([3, 6]).astype(np.float32) +b = np.random.ranf([4, 6]).astype(np.float32) +c = np.zeros([1, 4]).astype(np.float32) +y = gemm_reference_implementation(a, b, c, transB=1) +expect(node, inputs=[a, b, c], outputs=[y], + name='test_gemm_transposeB') +``` + +
+ + +### GlobalAveragePool +There are 2 test cases, listed as following: +
+globalaveragepool + +```python +node = onnx.helper.make_node( + 'GlobalAveragePool', + inputs=['x'], + outputs=['y'], +) +x = np.random.randn(1, 3, 5, 5).astype(np.float32) +y = np.mean(x, axis=tuple(range(2, np.ndim(x))), keepdims=True) +expect(node, inputs=[x], outputs=[y], name='test_globalaveragepool') +``` + +
+
+globalaveragepool_precomputed + +```python + +node = onnx.helper.make_node( + 'GlobalAveragePool', + inputs=['x'], + outputs=['y'], +) +x = np.array([[[ + [1, 2, 3], + [4, 5, 6], + [7, 8, 9], +]]]).astype(np.float32) +y = np.array([[[[5]]]]).astype(np.float32) +expect(node, inputs=[x], outputs=[y], name='test_globalaveragepool_precomputed') +``` + +
+ + +### GlobalMaxPool +There are 2 test cases, listed as following: +
+globalmaxpool + +```python + +node = onnx.helper.make_node( + 'GlobalMaxPool', + inputs=['x'], + outputs=['y'], +) +x = np.random.randn(1, 3, 5, 5).astype(np.float32) +y = np.max(x, axis=tuple(range(2, np.ndim(x))), keepdims=True) +expect(node, inputs=[x], outputs=[y], name='test_globalmaxpool') +``` + +
+
+globalmaxpool_precomputed + +```python + +node = onnx.helper.make_node( + 'GlobalMaxPool', + inputs=['x'], + outputs=['y'], +) +x = np.array([[[ + [1, 2, 3], + [4, 5, 6], + [7, 8, 9], +]]]).astype(np.float32) +y = np.array([[[[9]]]]).astype(np.float32) +expect(node, inputs=[x], outputs=[y], name='test_globalmaxpool_precomputed') +``` + +
+ + +### Gradient +There are 2 test cases, listed as following: +
+gradient_scalar_add + +```python +add_node = onnx.helper.make_node('Add', + ['a', 'b'], ['c'], name='my_add') +gradient_node = onnx.helper.make_node( + 'Gradient', ['a', 'b'], + ['dc_da', 'dc_db'], name='my_gradient', + domain=AI_ONNX_PREVIEW_TRAINING_DOMAIN, + xs=['a', 'b'], y='c') + +a = np.array(1.0).astype(np.float32) +b = np.array(2.0).astype(np.float32) +c = a + b +# dc / da = d(a+b) / da = 1 +dc_da = np.array(1).astype(np.float32) +# db / db = d(a+b) / db = 1 +dc_db = np.array(1).astype(np.float32) + +graph = onnx.helper.make_graph( + nodes=[add_node, gradient_node], + name='GradientOfAdd', + inputs=[ + onnx.helper.make_tensor_value_info('a', onnx.TensorProto.FLOAT, + []), + onnx.helper.make_tensor_value_info('b', onnx.TensorProto.FLOAT, + [])], + outputs=[ + onnx.helper.make_tensor_value_info('c', onnx.TensorProto.FLOAT, + []), + onnx.helper.make_tensor_value_info('dc_da', + onnx.TensorProto.FLOAT, []), + onnx.helper.make_tensor_value_info('dc_db', + onnx.TensorProto.FLOAT, [])]) +opsets = [ + onnx.helper.make_operatorsetid(ONNX_DOMAIN, 12), + onnx.helper.make_operatorsetid(AI_ONNX_PREVIEW_TRAINING_DOMAIN, 1)] +model = onnx.helper.make_model( + graph, + producer_name='backend-test', + opset_imports=opsets) +expect(model, inputs=[a, b], outputs=[c, dc_da, dc_db], + name='test_gradient_of_add') +``` + +
+
+gradient_scalar_add_and_mul + +```python +add_node = onnx.helper.make_node('Add', + ['a', 'b'], ['c'], name='my_add') +mul_node = onnx.helper.make_node('Mul', + ['c', 'a'], ['d'], name='my_mul') +gradient_node = onnx.helper.make_node( + 'Gradient', ['a', 'b'], + ['dd_da', 'dd_db'], name='my_gradient', + domain=AI_ONNX_PREVIEW_TRAINING_DOMAIN, + xs=['a', 'b'], y='d') + +a = np.array(1.0).astype(np.float32) +b = np.array(2.0).astype(np.float32) +c = a + b +# d = a * c = a * (a + b) +d = a * c +# dd / da = d(a*a+a*b) / da = 2 * a + b +dd_da = (2 * a + b).astype(np.float32) +# dd / db = d(a*a+a*b) / db = a +dd_db = a + +graph = onnx.helper.make_graph( + nodes=[add_node, mul_node, gradient_node], + name='GradientOfTwoOperators', + inputs=[ + onnx.helper.make_tensor_value_info('a', onnx.TensorProto.FLOAT, + []), + onnx.helper.make_tensor_value_info('b', onnx.TensorProto.FLOAT, + [])], + outputs=[ + onnx.helper.make_tensor_value_info('d', onnx.TensorProto.FLOAT, + []), + onnx.helper.make_tensor_value_info('dd_da', + onnx.TensorProto.FLOAT, []), + onnx.helper.make_tensor_value_info('dd_db', + onnx.TensorProto.FLOAT, [])]) + +opsets = [ + onnx.helper.make_operatorsetid(ONNX_DOMAIN, 12), + onnx.helper.make_operatorsetid(AI_ONNX_PREVIEW_TRAINING_DOMAIN, 1)] +model = onnx.helper.make_model(graph, + producer_name='backend-test', + opset_imports=opsets) +expect(model, inputs=[a, b], outputs=[d, dd_da, dd_db], + name='test_gradient_of_add_and_mul') +``` + +
+ + +### Greater +There are 4 test cases, listed as following: +
+greater + +```python +node = onnx.helper.make_node( + 'Greater', + inputs=['x', 'y'], + outputs=['greater'], +) + +x = np.random.randn(3, 4, 5).astype(np.float32) +y = np.random.randn(3, 4, 5).astype(np.float32) +z = np.greater(x, y) +expect(node, inputs=[x, y], outputs=[z], + name='test_greater') +``` + +
+
+greater + +```python +node = onnx.helper.make_node( + 'GreaterOrEqual', + inputs=['x', 'y'], + outputs=['greater_equal'], +) + +x = np.random.randn(3, 4, 5).astype(np.float32) +y = np.random.randn(3, 4, 5).astype(np.float32) +z = np.greater_equal(x, y) +expect(node, inputs=[x, y], outputs=[z], + name='test_greater_equal') +``` + +
+
+greater_broadcast + +```python +node = onnx.helper.make_node( + 'Greater', + inputs=['x', 'y'], + outputs=['greater'], +) + +x = np.random.randn(3, 4, 5).astype(np.float32) +y = np.random.randn(5).astype(np.float32) +z = np.greater(x, y) +expect(node, inputs=[x, y], outputs=[z], + name='test_greater_bcast') +``` + +
+
+greater_broadcast + +```python +node = onnx.helper.make_node( + 'GreaterOrEqual', + inputs=['x', 'y'], + outputs=['greater_equal'], +) + +x = np.random.randn(3, 4, 5).astype(np.float32) +y = np.random.randn(5).astype(np.float32) +z = np.greater_equal(x, y) +expect(node, inputs=[x, y], outputs=[z], + name='test_greater_equal_bcast') +``` + +
+ + +### GridSample +There are 3 test cases, listed as following: +
+gridsample + +```python +node = onnx.helper.make_node( + 'GridSample', + inputs=['X', 'Grid'], + outputs=['Y'], + mode='bilinear', + padding_mode='zeros', + align_corners=0, +) +# X shape, [N, C, H, W] - [1, 1, 4, 4] +X = np.array( + [ + [ + [ + [0., 1., 2., 3.], + [4., 5., 6., 7.], + [8., 9., 10., 11.], + [12., 13., 14., 15.] + ] + ] + ], + dtype=np.float32, +) +# Grid shape, [N, H_out, W_out, 2] - [1, 6, 6, 2] +Grid = np.array( + [ + [ + [ + [-1.0000, -1.0000], + [-0.6000, -1.0000], + [-0.2000, -1.0000], + [0.2000, -1.0000], + [0.6000, -1.0000], + [1.0000, -1.0000] + ], + [ + [-1.0000, -0.6000], + [-0.6000, -0.6000], + [-0.2000, -0.6000], + [0.2000, -0.6000], + [0.6000, -0.6000], + [1.0000, -0.6000] + ], + [ + [-1.0000, -0.2000], + [-0.6000, -0.2000], + [-0.2000, -0.2000], + [0.2000, -0.2000], + [0.6000, -0.2000], + [1.0000, -0.2000] + ], + [ + [-1.0000, 0.2000], + [-0.6000, 0.2000], + [-0.2000, 0.2000], + [0.2000, 0.2000], + [0.6000, 0.2000], + [1.0000, 0.2000] + ], + [ + [-1.0000, 0.6000], + [-0.6000, 0.6000], + [-0.2000, 0.6000], + [0.2000, 0.6000], + [0.6000, 0.6000], + [1.0000, 0.6000] + ], + [ + [-1.0000, 1.0000], + [-0.6000, 1.0000], + [-0.2000, 1.0000], + [0.2000, 1.0000], + [0.6000, 1.0000], + [1.0000, 1.0000] + ] + ] + ], + dtype=np.float32, +) +# Y shape, [N, C, H_out, W_out] - [1, 1, 6, 6] +Y = np.array( + [ + [ + [ + [0.0000, 0.1500, 0.5500, 0.9500, 1.3500, 0.7500], + [0.6000, 1.5000, 2.3000, 3.1000, 3.9000, 2.1000], + [2.2000, 4.7000, 5.5000, 6.3000, 7.1000, 3.7000], + [3.8000, 7.9000, 8.7000, 9.5000, 10.3000, 5.3000], + [5.4000, 11.1000, 11.9000, 12.7000, 13.5000, 6.9000], + [3.0000, 6.1500, 6.5500, 6.9500, 7.3500, 3.7500] + ] + ] + ], + dtype=np.float32, +) +expect(node, inputs=[X, Grid], outputs=[Y], + name='test_gridsample') +``` + +
+
+gridsample_mode_aligncorners + +```python +# X shape, [N, C, H, W] - [1, 1, 3, 2] +X = np.array( + [ + [ + [ + [0., 1.], + [2., 3.], + [4., 5.] + ] + ] + ], + dtype=np.float32, +) +# Grid shape, [N, H_out, W_out, 2] - [1, 2, 4, 2] +Grid = np.array( + [ + [ + [ + [-1.0000, -1.0000], + [-0.5000, -0.5000], + [-0.2000, -0.2000], + [0.0000, 0.0000] + ], + + [ + [0.0000, 0.0000], + [-0.2000, -0.2000], + [0.5000, 0.5000], + [1.0000, 1.0000] + ] + ] + ], + dtype=np.float32, +) + +# setting mode = 'bilinear', default align_corners = 0 +node = onnx.helper.make_node( + 'GridSample', + inputs=['X', 'Grid'], + outputs=['Y'], + mode='bilinear', +) +# Y shape, [N, C, H_out, W_out] - [1, 1, 2, 4] +Y_bilinear = np.array( + [ + [ + [ + [0.0000, 0.5000, 1.7000, 2.5000], + [2.5000, 1.7000, 4.5000, 1.2500] + ] + ] + ], + dtype=np.float32, +) + +expect(node, inputs=[X, Grid], outputs=[Y_bilinear], + name='test_gridsample_bilinear') + +# setting mode = 'bilinear', align_corners = 1 +node = onnx.helper.make_node( + 'GridSample', + inputs=['X', 'Grid'], + outputs=['Y'], + mode='bilinear', + align_corners=1, +) +# Y shape, [N, C, H_out, W_out] - [1, 1, 2, 4] +Y_align_corners = np.array( + [ + [ + [ + [0.0000, 1.2500, 2.0000, 2.5000], + [2.5000, 2.0000, 3.7500, 5.0000] + ] + ] + ], + dtype=np.float32, +) + +expect(node, inputs=[X, Grid], outputs=[Y_align_corners], + name='test_gridsample_aligncorners_true') + +# setting mode = 'nearest' +node = onnx.helper.make_node( + 'GridSample', + inputs=['X', 'Grid'], + outputs=['Y'], + mode='nearest', +) +# Y shape, [N, C, H_out, W_out] - [1, 1, 2, 4] +Y_nearest = np.array( + [ + [ + [ + [0., 0., 2., 2.], + [2., 2., 5., 0.] + ] + ] + ], + dtype=np.float32, +) + +expect(node, inputs=[X, Grid], outputs=[Y_nearest], + name='test_gridsample_nearest') + +# setting mode = 'bicubic' +node = onnx.helper.make_node( + 'GridSample', + inputs=['X', 'Grid'], + outputs=['Y'], + mode='bicubic', +) +# Y shape, [N, C, H_out, W_out] - [1, 1, 2, 4] +Y_bicubic = np.array( + [ + [ + [ + [-0.1406, 0.3828, 1.7556, 2.9688], + [2.9688, 1.7556, 5.1445, 1.3906] + ] + ] + ], + dtype=np.float32, +) + +expect(node, inputs=[X, Grid], outputs=[Y_bicubic], + name='test_gridsample_bicubic') +``` + +
+
+gridsample_paddingmode + +```python +# X shape, [N, C, H, W] - [1, 1, 3, 2] +X = np.array( + [ + [ + [ + [0., 1.], + [2., 3.], + [4., 5.] + ] + ] + ], + dtype=np.float32, +) +# Grid shape, [N, H_out, W_out, 2] - [1, 2, 4, 2] +Grid = np.array( + [ + [ + [ + [-10.0000, -10.0000], + [-5.0000, -5.0000], + [-0.2000, -0.2000], + [10.0000, 10.0000] + ], + + [ + [10.0000, 10.0000], + [-0.2000, -0.2000], + [5.0000, 5.0000], + [10.0000, 10.0000] + ] + ] + ], + dtype=np.float32, +) + +# setting padding_mode = 'zeros' +node = onnx.helper.make_node( + 'GridSample', + inputs=['X', 'Grid'], + outputs=['Y'], + padding_mode='zeros', +) +# Y shape, [N, C, H_out, W_out] - [1, 1, 2, 4] +Y_zeros = np.array( + [ + [ + [ + [0.0000, 0.0000, 1.7000, 0.0000], + [0.0000, 1.7000, 0.0000, 0.0000] + ] + ] + ], + dtype=np.float32, +) + +expect(node, inputs=[X, Grid], outputs=[Y_zeros], + name='test_gridsample_zeros_padding') + +# setting padding_mode = 'border' +node = onnx.helper.make_node( + 'GridSample', + inputs=['X', 'Grid'], + outputs=['Y'], + padding_mode='border', +) +# Y shape, [N, C, H_out, W_out] - [1, 1, 2, 4] +Y_border = np.array( + [ + [ + [ + [0.0000, 0.0000, 1.7000, 5.0000], + [5.0000, 1.7000, 5.0000, 5.0000] + ] + ] + ], + dtype=np.float32, +) + +expect(node, inputs=[X, Grid], outputs=[Y_border], + name='test_gridsample_border_padding') + +# setting padding_mode = 'reflection' +node = onnx.helper.make_node( + 'GridSample', + inputs=['X', 'Grid'], + outputs=['Y'], + padding_mode='reflection', +) +# Y shape, [N, C, H_out, W_out] - [1, 1, 2, 4] +Y_reflection = np.array( + [ + [ + [ + [2.5000, 0.0000, 1.7000, 2.5000], + [2.5000, 1.7000, 5.0000, 2.5000] + ] + ] + ], + dtype=np.float32, +) + +expect(node, inputs=[X, Grid], outputs=[Y_reflection], + name='test_gridsample_reflection_padding') +``` + +
+ + +### HardSigmoid +There are 2 test cases, listed as following: +
+hardsigmoid + +```python +node = onnx.helper.make_node( + 'HardSigmoid', + inputs=['x'], + outputs=['y'], + alpha=0.5, + beta=0.6 +) + +x = np.array([-1, 0, 1]).astype(np.float32) +y = np.clip(x * 0.5 + 0.6, 0, 1) # expected output [0.1, 0.6, 1.] +expect(node, inputs=[x], outputs=[y], + name='test_hardsigmoid_example') + +x = np.random.randn(3, 4, 5).astype(np.float32) +y = np.clip(x * 0.5 + 0.6, 0, 1) +expect(node, inputs=[x], outputs=[y], + name='test_hardsigmoid') +``` + +
+
+hardsigmoid_default + +```python +default_alpha = 0.2 +default_beta = 0.5 +node = onnx.helper.make_node( + 'HardSigmoid', + inputs=['x'], + outputs=['y'], +) +x = np.random.randn(3, 4, 5).astype(np.float32) +y = np.clip(x * default_alpha + default_beta, 0, 1) +expect(node, inputs=[x], outputs=[y], + name='test_hardsigmoid_default') +``` + +
+ + +### HardSwish +There are 1 test cases, listed as following: +
+hardswish + +```python +node = onnx.helper.make_node( + 'HardSwish', + inputs=['x'], + outputs=['y'], +) +x = np.random.randn(3, 4, 5).astype(np.float32) +y = hardswish(x) + +expect(node, inputs=[x], outputs=[y], + name='test_hardswish') +``` + +
+ + +### Hardmax +There are 2 test cases, listed as following: +
+hardmax + +```python +node = onnx.helper.make_node( + 'Hardmax', + inputs=['x'], + outputs=['y'], +) + +x = np.array([[3, 0, 1, 2], [2, 5, 1, 0], [0, 1, 3, 2], + [0, 1, 2, 3]]).astype(np.float32) +# expect result: +# [[1. 0. 0. 0.] +# [0. 1. 0. 0.] +# [0. 0. 1. 0.] +# [0. 0. 0. 1.]] +y = hardmax(x) +expect(node, inputs=[x], outputs=[y], + name='test_hardmax_example') + +# For multiple occurrences of the maximal values, the first occurrence is selected for one-hot output +x = np.array([[3, 3, 3, 1]]).astype(np.float32) +# expect result: +# [[1, 0, 0, 0]] +y = hardmax(x) +expect(node, inputs=[x], outputs=[y], + name='test_hardmax_one_hot') +``` + +
+
+hardmax_axis + +```python +x = np.random.randn(3, 4, 5).astype(np.float32) +node = onnx.helper.make_node( + 'Hardmax', + inputs=['x'], + outputs=['y'], + axis=0, +) +y = hardmax(x, axis=0) +expect(node, inputs=[x], outputs=[y], + name='test_hardmax_axis_0') + +node = onnx.helper.make_node( + 'Hardmax', + inputs=['x'], + outputs=['y'], + axis=1, +) +y = hardmax(x, axis=1) +expect(node, inputs=[x], outputs=[y], + name='test_hardmax_axis_1') + +node = onnx.helper.make_node( + 'Hardmax', + inputs=['x'], + outputs=['y'], + axis=2, +) +y = hardmax(x, axis=2) +expect(node, inputs=[x], outputs=[y], + name='test_hardmax_axis_2') + +node = onnx.helper.make_node( + 'Hardmax', + inputs=['x'], + outputs=['y'], + axis=-1, +) +y = hardmax(x, axis=-1) +expect(node, inputs=[x], outputs=[y], + name='test_hardmax_negative_axis') + +# default axis is -1 +node = onnx.helper.make_node( + 'Hardmax', + inputs=['x'], + outputs=['y'], +) +expect(node, inputs=[x], outputs=[y], + name='test_hardmax_default_axis') +``` + +
+ + +### Identity +There are 3 test cases, listed as following: +
+identity + +```python +node = onnx.helper.make_node( + 'Identity', + inputs=['x'], + outputs=['y'], +) + +data = np.array([[[ + [1, 2], + [3, 4], +]]], dtype=np.float32) + +expect(node, inputs=[data], outputs=[data], + name='test_identity') +``` + +
+
+identity_opt + +```python +ten_in_tp = onnx.helper.make_tensor_type_proto(onnx.TensorProto.FLOAT, shape=[5]) +seq_in_tp = onnx.helper.make_sequence_type_proto(ten_in_tp) +opt_in_tp = onnx.helper.make_optional_type_proto(seq_in_tp) + +identity_node = onnx.helper.make_node( + 'Identity', + inputs=['opt_in'], + outputs=['opt_out'] +) + +x = [np.array([1, 2, 3, 4, 5]).astype(np.float32)] + +expect(identity_node, inputs=[x], outputs=[x], name='test_identity_opt', + opset_imports=[onnx.helper.make_opsetid("", 16)], + input_type_protos=[opt_in_tp], + output_type_protos=[opt_in_tp]) +``` + +
+
+sequence + +```python +node = onnx.helper.make_node( + 'Identity', + inputs=['x'], + outputs=['y'], +) + +data = [ + np.array([[[ + [1, 2], + [3, 4], + ]]], dtype=np.float32), + np.array([[[ + [2, 3], + [1, 5], + ]]], dtype=np.float32)] + +expect(node, inputs=[data], outputs=[data], name='test_identity_sequence') +``` + +
+ + +### If +There are 3 test cases, listed as following: +
+if + +```python +# Given a bool scalar input cond. +# return constant tensor x if cond is True, otherwise return constant tensor y. + +then_out = onnx.helper.make_tensor_value_info('then_out', onnx.TensorProto.FLOAT, [5]) +else_out = onnx.helper.make_tensor_value_info('else_out', onnx.TensorProto.FLOAT, [5]) + +x = np.array([1, 2, 3, 4, 5]).astype(np.float32) +y = np.array([5, 4, 3, 2, 1]).astype(np.float32) + +then_const_node = onnx.helper.make_node( + 'Constant', + inputs=[], + outputs=['then_out'], + value=onnx.numpy_helper.from_array(x) +) + +else_const_node = onnx.helper.make_node( + 'Constant', + inputs=[], + outputs=['else_out'], + value=onnx.numpy_helper.from_array(y) +) + +then_body = onnx.helper.make_graph( + [then_const_node], + 'then_body', + [], + [then_out] +) + +else_body = onnx.helper.make_graph( + [else_const_node], + 'else_body', + [], + [else_out] +) + +if_node = onnx.helper.make_node( + 'If', + inputs=['cond'], + outputs=['res'], + then_branch=then_body, + else_branch=else_body +) + +cond = np.array(1).astype(bool) +res = x if cond else y +expect(if_node, inputs=[cond], outputs=[res], name='test_if', + opset_imports=[onnx.helper.make_opsetid("", 11)]) +``` + +
+
+if_optional + +```python +# Given a bool scalar input cond, return an empty optional sequence of +# tensor if True, return an optional sequence with value x +# (the input optional sequence) otherwise. + +ten_in_tp = onnx.helper.make_tensor_type_proto(onnx.TensorProto.FLOAT, shape=[5]) +seq_in_tp = onnx.helper.make_sequence_type_proto(ten_in_tp) + +then_out_tensor_tp = onnx.helper.make_tensor_type_proto(onnx.TensorProto.FLOAT, shape=[5]) +then_out_seq_tp = onnx.helper.make_sequence_type_proto(then_out_tensor_tp) +then_out_opt_tp = onnx.helper.make_optional_type_proto(then_out_seq_tp) +then_out = onnx.helper.make_value_info('optional_empty', then_out_opt_tp) + +else_out_tensor_tp = onnx.helper.make_tensor_type_proto(onnx.TensorProto.FLOAT, shape=[5]) +else_out_seq_tp = onnx.helper.make_sequence_type_proto(else_out_tensor_tp) +else_out_opt_tp = onnx.helper.make_optional_type_proto(else_out_seq_tp) +else_out = onnx.helper.make_value_info('else_opt', else_out_opt_tp) + +x = [np.array([1, 2, 3, 4, 5]).astype(np.float32)] +cond = np.array(0).astype(bool) +res = compute_if_outputs(x, cond) + +opt_empty_in = onnx.helper.make_node( + 'Optional', + inputs=[], + outputs=['optional_empty'], + type=seq_in_tp +) + +then_body = onnx.helper.make_graph( + [opt_empty_in], + 'then_body', + [], + [then_out] +) + +else_const_node = onnx.helper.make_node( + 'Constant', + inputs=[], + outputs=['x'], + value=onnx.numpy_helper.from_array(x[0]) +) + +else_seq_node = onnx.helper.make_node( + 'SequenceConstruct', + inputs=['x'], + outputs=['else_seq'] +) + +else_optional_seq_node = onnx.helper.make_node( + 'Optional', + inputs=['else_seq'], + outputs=['else_opt'] +) + +else_body = onnx.helper.make_graph( + [else_const_node, else_seq_node, else_optional_seq_node], + 'else_body', + [], + [else_out] +) + +if_node = onnx.helper.make_node( + 'If', + inputs=['cond'], + outputs=['sequence'], + then_branch=then_body, + else_branch=else_body +) + +expect(if_node, inputs=[cond], outputs=[res], name='test_if_opt', + output_type_protos=[else_out_opt_tp], + opset_imports=[onnx.helper.make_opsetid("", 16)]) +``` + +
+
+if_seq + +```python +# Given a bool scalar input cond. +# return constant sequence x if cond is True, otherwise return constant sequence y. + +then_out = onnx.helper.make_tensor_sequence_value_info('then_out', onnx.TensorProto.FLOAT, shape=[5]) +else_out = onnx.helper.make_tensor_sequence_value_info('else_out', onnx.TensorProto.FLOAT, shape=[5]) + +x = [np.array([1, 2, 3, 4, 5]).astype(np.float32)] +y = [np.array([5, 4, 3, 2, 1]).astype(np.float32)] + +then_const_node = onnx.helper.make_node( + 'Constant', + inputs=[], + outputs=['x'], + value=onnx.numpy_helper.from_array(x[0]) +) + +then_seq_node = onnx.helper.make_node( + 'SequenceConstruct', + inputs=['x'], + outputs=['then_out'] +) + +else_const_node = onnx.helper.make_node( + 'Constant', + inputs=[], + outputs=['y'], + value=onnx.numpy_helper.from_array(y[0]) +) + +else_seq_node = onnx.helper.make_node( + 'SequenceConstruct', + inputs=['y'], + outputs=['else_out'] +) + +then_body = onnx.helper.make_graph( + [then_const_node, then_seq_node], + 'then_body', + [], + [then_out] +) + +else_body = onnx.helper.make_graph( + [else_const_node, else_seq_node], + 'else_body', + [], + [else_out] +) + +if_node = onnx.helper.make_node( + 'If', + inputs=['cond'], + outputs=['res'], + then_branch=then_body, + else_branch=else_body +) + +cond = np.array(1).astype(bool) +res = x if cond else y +expect(if_node, inputs=[cond], outputs=[res], name='test_if_seq', + opset_imports=[onnx.helper.make_opsetid("", 13)]) +``` + +
+ + +### InstanceNormalization +There are 1 test cases, listed as following: +
+instancenormalization + +```python +def _instancenorm_test_mode(x, s, bias, epsilon=1e-5): # type: ignore + dims_x = len(x.shape) + axis = tuple(range(2, dims_x)) + mean = np.mean(x, axis=axis, keepdims=True) + var = np.var(x, axis=axis, keepdims=True) + dim_ones = (1,) * (dims_x - 2) + s = s.reshape(-1, *dim_ones) + bias = bias.reshape(-1, *dim_ones) + return s * (x - mean) / np.sqrt(var + epsilon) + bias + +# input size: (1, 2, 1, 3) +x = np.array([[[[-1, 0, 1]], [[2, 3, 4]]]]).astype(np.float32) +s = np.array([1.0, 1.5]).astype(np.float32) +bias = np.array([0, 1]).astype(np.float32) +y = _instancenorm_test_mode(x, s, bias).astype(np.float32) + +node = onnx.helper.make_node( + 'InstanceNormalization', + inputs=['x', 's', 'bias'], + outputs=['y'], +) + +# output size: (1, 2, 1, 3) +expect(node, inputs=[x, s, bias], outputs=[y], + name='test_instancenorm_example') + +# input size: (2, 3, 4, 5) +x = np.random.randn(2, 3, 4, 5).astype(np.float32) +s = np.random.randn(3).astype(np.float32) +bias = np.random.randn(3).astype(np.float32) +epsilon = 1e-2 +y = _instancenorm_test_mode(x, s, bias, epsilon).astype(np.float32) + +node = onnx.helper.make_node( + 'InstanceNormalization', + inputs=['x', 's', 'bias'], + outputs=['y'], + epsilon=epsilon, +) + +# output size: (2, 3, 4, 5) +expect(node, inputs=[x, s, bias], outputs=[y], + name='test_instancenorm_epsilon') +``` + +
+ + +### IsInf +There are 3 test cases, listed as following: +
+infinity + +```python +node = onnx.helper.make_node('IsInf', + inputs=['x'], + outputs=['y'], + ) + +x = np.array([-1.2, np.nan, np.inf, 2.8, np.NINF, np.inf], + dtype=np.float32) +y = np.isinf(x) +expect(node, inputs=[x], outputs=[y], name='test_isinf') +``` + +
+
+negative_infinity_only + +```python +node = onnx.helper.make_node('IsInf', + inputs=['x'], + outputs=['y'], + detect_positive=0 + ) + +x = np.array([-1.7, np.nan, np.inf, -3.6, np.NINF, np.inf], + dtype=np.float32) +y = np.isneginf(x) +expect(node, inputs=[x], outputs=[y], name='test_isinf_negative') +``` + +
+
+positive_infinity_only + +```python +node = onnx.helper.make_node('IsInf', + inputs=['x'], + outputs=['y'], + detect_negative=0 + ) + +x = np.array([-1.7, np.nan, np.inf, 3.6, np.NINF, np.inf], + dtype=np.float32) +y = np.isposinf(x) +expect(node, inputs=[x], outputs=[y], name='test_isinf_positive') +``` + +
+ + +### IsNaN +There are 1 test cases, listed as following: +
+isnan + +```python +node = onnx.helper.make_node( + 'IsNaN', + inputs=['x'], + outputs=['y'], +) + +x = np.array([3.0, np.nan, 4.0, np.nan], dtype=np.float32) +y = np.isnan(x) +expect(node, inputs=[x], outputs=[y], name='test_isnan') +``` + +
+ + +### LRN +There are 2 test cases, listed as following: +
+default + +```python +alpha = 0.0001 +beta = 0.75 +bias = 1.0 +nsize = 3 +node = onnx.helper.make_node( + 'LRN', + inputs=['x'], + outputs=['y'], + size=3 +) +x = np.random.randn(5, 5, 5, 5).astype(np.float32) +square_sum = np.zeros((5, 5, 5, 5)).astype(np.float32) +for n, c, h, w in np.ndindex(x.shape): + square_sum[n, c, h, w] = sum(x[n, + max(0, c - int(math.floor((nsize - 1) / 2))):min(5, c + int(math.ceil((nsize - 1) / 2)) + 1), + h, + w] ** 2) +y = x / ((bias + (alpha / nsize) * square_sum) ** beta) +expect(node, inputs=[x], outputs=[y], + name='test_lrn_default') +``` + +
+
+lrn + +```python +alpha = 0.0002 +beta = 0.5 +bias = 2.0 +nsize = 3 +node = onnx.helper.make_node( + 'LRN', + inputs=['x'], + outputs=['y'], + alpha=alpha, + beta=beta, + bias=bias, + size=nsize +) +x = np.random.randn(5, 5, 5, 5).astype(np.float32) +square_sum = np.zeros((5, 5, 5, 5)).astype(np.float32) +for n, c, h, w in np.ndindex(x.shape): + square_sum[n, c, h, w] = sum(x[n, + max(0, c - int(math.floor((nsize - 1) / 2))):min(5, c + int(math.ceil((nsize - 1) / 2)) + 1), + h, + w] ** 2) +y = x / ((bias + (alpha / nsize) * square_sum) ** beta) +expect(node, inputs=[x], outputs=[y], + name='test_lrn') +``` + +
+ + +### LSTM +There are 4 test cases, listed as following: +
+batchwise + +```python +input = np.array([[[1., 2.]], [[3., 4.]], [[5., 6.]]]).astype(np.float32) + +input_size = 2 +hidden_size = 7 +weight_scale = 0.3 +number_of_gates = 4 +layout = 1 + +node = onnx.helper.make_node( + 'LSTM', + inputs=['X', 'W', 'R'], + outputs=['Y', 'Y_h'], + hidden_size=hidden_size, + layout=layout +) + +W = weight_scale * np.ones((1, number_of_gates * hidden_size, input_size)).astype(np.float32) +R = weight_scale * np.ones((1, number_of_gates * hidden_size, hidden_size)).astype(np.float32) + +lstm = LSTM_Helper(X=input, W=W, R=R, layout=layout) +Y, Y_h = lstm.step() +expect(node, inputs=[input, W, R], outputs=[Y.astype(np.float32), Y_h.astype(np.float32)], name='test_lstm_batchwise') +``` + +
+
+defaults + +```python +input = np.array([[[1., 2.], [3., 4.], [5., 6.]]]).astype(np.float32) + +input_size = 2 +hidden_size = 3 +weight_scale = 0.1 +number_of_gates = 4 + +node = onnx.helper.make_node( + 'LSTM', + inputs=['X', 'W', 'R'], + outputs=['', 'Y_h'], + hidden_size=hidden_size +) + +W = weight_scale * np.ones((1, number_of_gates * hidden_size, input_size)).astype(np.float32) +R = weight_scale * np.ones((1, number_of_gates * hidden_size, hidden_size)).astype(np.float32) + +lstm = LSTM_Helper(X=input, W=W, R=R) +_, Y_h = lstm.step() +expect(node, inputs=[input, W, R], outputs=[Y_h.astype(np.float32)], name='test_lstm_defaults') +``` + +
+
+initial_bias + +```python +input = np.array([[[1., 2., 3.], [4., 5., 6.], [7., 8., 9.]]]).astype(np.float32) + +input_size = 3 +hidden_size = 4 +weight_scale = 0.1 +custom_bias = 0.1 +number_of_gates = 4 + +node = onnx.helper.make_node( + 'LSTM', + inputs=['X', 'W', 'R', 'B'], + outputs=['', 'Y_h'], + hidden_size=hidden_size +) + +W = weight_scale * np.ones((1, number_of_gates * hidden_size, input_size)).astype(np.float32) +R = weight_scale * np.ones((1, number_of_gates * hidden_size, hidden_size)).astype(np.float32) + +# Adding custom bias +W_B = custom_bias * np.ones((1, number_of_gates * hidden_size)).astype(np.float32) +R_B = np.zeros((1, number_of_gates * hidden_size)).astype(np.float32) +B = np.concatenate((W_B, R_B), 1) + +lstm = LSTM_Helper(X=input, W=W, R=R, B=B) +_, Y_h = lstm.step() +expect(node, inputs=[input, W, R, B], outputs=[Y_h.astype(np.float32)], name='test_lstm_with_initial_bias') +``` + +
+
+peepholes + +```python +input = np.array([[[1., 2., 3., 4.], [5., 6., 7., 8.]]]).astype(np.float32) + +input_size = 4 +hidden_size = 3 +weight_scale = 0.1 +number_of_gates = 4 +number_of_peepholes = 3 + +node = onnx.helper.make_node( + 'LSTM', + inputs=['X', 'W', 'R', 'B', 'sequence_lens', 'initial_h', 'initial_c', 'P'], + outputs=['', 'Y_h'], + hidden_size=hidden_size +) + +# Initializing Inputs +W = weight_scale * np.ones((1, number_of_gates * hidden_size, input_size)).astype(np.float32) +R = weight_scale * np.ones((1, number_of_gates * hidden_size, hidden_size)).astype(np.float32) +B = np.zeros((1, 2 * number_of_gates * hidden_size)).astype(np.float32) +seq_lens = np.repeat(input.shape[0], input.shape[1]).astype(np.int32) +init_h = np.zeros((1, input.shape[1], hidden_size)).astype(np.float32) +init_c = np.zeros((1, input.shape[1], hidden_size)).astype(np.float32) +P = weight_scale * np.ones((1, number_of_peepholes * hidden_size)).astype(np.float32) + +lstm = LSTM_Helper(X=input, W=W, R=R, B=B, P=P, initial_c=init_c, initial_h=init_h) +_, Y_h = lstm.step() +expect(node, inputs=[input, W, R, B, seq_lens, init_h, init_c, P], outputs=[Y_h.astype(np.float32)], + name='test_lstm_with_peepholes') +``` + +
+ + +### LeakyRelu +There are 2 test cases, listed as following: +
+leakyrelu + +```python +node = onnx.helper.make_node( + 'LeakyRelu', + inputs=['x'], + outputs=['y'], + alpha=0.1 +) + +x = np.array([-1, 0, 1]).astype(np.float32) +# expected output [-0.1, 0., 1.] +y = np.clip(x, 0, np.inf) + np.clip(x, -np.inf, 0) * 0.1 +expect(node, inputs=[x], outputs=[y], + name='test_leakyrelu_example') + +x = np.random.randn(3, 4, 5).astype(np.float32) +y = np.clip(x, 0, np.inf) + np.clip(x, -np.inf, 0) * 0.1 +expect(node, inputs=[x], outputs=[y], + name='test_leakyrelu') +``` + +
+
+leakyrelu_default + +```python +default_alpha = 0.01 +node = onnx.helper.make_node( + 'LeakyRelu', + inputs=['x'], + outputs=['y'], +) +x = np.random.randn(3, 4, 5).astype(np.float32) +y = np.clip(x, 0, np.inf) + np.clip(x, -np.inf, 0) * default_alpha +expect(node, inputs=[x], outputs=[y], + name='test_leakyrelu_default') +``` + +
+ + +### Less +There are 4 test cases, listed as following: +
+less + +```python +node = onnx.helper.make_node( + 'Less', + inputs=['x', 'y'], + outputs=['less'], +) + +x = np.random.randn(3, 4, 5).astype(np.float32) +y = np.random.randn(3, 4, 5).astype(np.float32) +z = np.less(x, y) +expect(node, inputs=[x, y], outputs=[z], + name='test_less') +``` + +
+
+less + +```python +node = onnx.helper.make_node( + 'LessOrEqual', + inputs=['x', 'y'], + outputs=['less_equal'], +) + +x = np.random.randn(3, 4, 5).astype(np.float32) +y = np.random.randn(3, 4, 5).astype(np.float32) +z = np.less_equal(x, y) +expect(node, inputs=[x, y], outputs=[z], + name='test_less_equal') +``` + +
+
+less_broadcast + +```python +node = onnx.helper.make_node( + 'Less', + inputs=['x', 'y'], + outputs=['less'], +) + +x = np.random.randn(3, 4, 5).astype(np.float32) +y = np.random.randn(5).astype(np.float32) +z = np.less(x, y) +expect(node, inputs=[x, y], outputs=[z], + name='test_less_bcast') +``` + +
+
+less_broadcast + +```python +node = onnx.helper.make_node( + 'LessOrEqual', + inputs=['x', 'y'], + outputs=['less_equal'], +) + +x = np.random.randn(3, 4, 5).astype(np.float32) +y = np.random.randn(5).astype(np.float32) +z = np.less_equal(x, y) +expect(node, inputs=[x, y], outputs=[z], + name='test_less_equal_bcast') +``` + +
+ + +### Log +There are 1 test cases, listed as following: +
+log + +```python +node = onnx.helper.make_node( + 'Log', + inputs=['x'], + outputs=['y'], +) + +x = np.array([1, 10]).astype(np.float32) +y = np.log(x) # expected output [0., 2.30258512] +expect(node, inputs=[x], outputs=[y], + name='test_log_example') + +x = np.exp(np.random.randn(3, 4, 5).astype(np.float32)) +y = np.log(x) +expect(node, inputs=[x], outputs=[y], + name='test_log') +``` + +
+ + +### LogSoftmax +There are 2 test cases, listed as following: +
+logsoftmax + +```python +node = onnx.helper.make_node( + 'LogSoftmax', + inputs=['x'], + outputs=['y'], +) +x = np.array([[-1, 0, 1]]).astype(np.float32) +# expected output +# [[-2.4076061 -1.407606 -0.407606 ]] +y = logsoftmax(x) +expect(node, inputs=[x], outputs=[y], + name='test_logsoftmax_example_1') +``` + +
+
+logsoftmax_axis + +```python +x = np.array([[0, 1, 2, 3], [10000, 10001, 10002, 10003]] + ).astype(np.float32) +# expected output +# [[-3.4401896 -2.4401896 -1.4401896 -0.44018966] +# [-3.4401896 -2.4401896 -1.4401896 -0.44018966]] +y = logsoftmax(x) + +node = onnx.helper.make_node( + 'LogSoftmax', + inputs=['x'], + outputs=['y'], +) +expect(node, inputs=[x], outputs=[y], + name='test_logsoftmax_large_number') + +x = np.abs(np.random.randn(3, 4, 5).astype(np.float32)) +node = onnx.helper.make_node( + 'LogSoftmax', + inputs=['x'], + outputs=['y'], + axis=0, +) +y = logsoftmax(x, axis=0) +expect(node, inputs=[x], outputs=[y], + name='test_logsoftmax_axis_0') + +node = onnx.helper.make_node( + 'LogSoftmax', + inputs=['x'], + outputs=['y'], + axis=1, +) +y = logsoftmax(x, axis=1) +expect(node, inputs=[x], outputs=[y], + name='test_logsoftmax_axis_1') + +node = onnx.helper.make_node( + 'LogSoftmax', + inputs=['x'], + outputs=['y'], + axis=2, +) +y = logsoftmax(x, axis=2) +expect(node, inputs=[x], outputs=[y], + name='test_logsoftmax_axis_2') + +node = onnx.helper.make_node( + 'LogSoftmax', + inputs=['x'], + outputs=['y'], + axis=-1, +) +y = logsoftmax(x, axis=-1) +expect(node, inputs=[x], outputs=[y], + name='test_logsoftmax_negative_axis') + +# default axis is -1 +node = onnx.helper.make_node( + 'LogSoftmax', + inputs=['x'], + outputs=['y'], +) +expect(node, inputs=[x], outputs=[y], + name='test_logsoftmax_default_axis') +``` + +
+ + +### Loop +There are 3 test cases, listed as following: +
+loop_11 + +```python +# Given a tensor x of values [x1, ..., xN], and initial tensor y +# sum up its elements using a scan +# returning the final state (y+x1+x2+...+xN) as well the scan_output +# [y+x1, y+x1+x2, ..., y+x1+x2+...+xN] + +y_in = onnx.helper.make_tensor_value_info('y_in', onnx.TensorProto.FLOAT, [1]) +y_out = onnx.helper.make_tensor_value_info('y_out', onnx.TensorProto.FLOAT, [1]) +scan_out = onnx.helper.make_tensor_value_info('scan_out', onnx.TensorProto.FLOAT, [1]) +cond_in = onnx.helper.make_tensor_value_info('cond_in', onnx.TensorProto.BOOL, []) +cond_out = onnx.helper.make_tensor_value_info('cond_out', onnx.TensorProto.BOOL, []) +iter_count = onnx.helper.make_tensor_value_info('iter_count', onnx.TensorProto.INT64, []) + +x = np.array([1, 2, 3, 4, 5]).astype(np.float32) +y = np.array([-2]).astype(np.float32) + +x_const_node = onnx.helper.make_node( + 'Constant', + inputs=[], + outputs=['x'], + value=onnx.helper.make_tensor( + name='const_tensor_x', + data_type=onnx.TensorProto.FLOAT, + dims=x.shape, + vals=x.flatten().astype(float), + ) +) + +one_const_node = onnx.helper.make_node( + 'Constant', + inputs=[], + outputs=['one'], + value=onnx.helper.make_tensor( + name='const_tensor_one', + data_type=onnx.TensorProto.INT64, + dims=(), + vals=[1] + ) +) + +i_add_node = onnx.helper.make_node( + 'Add', + inputs=['iter_count', 'one'], + outputs=['end'] +) + +start_unsqueeze_node = onnx.helper.make_node( + 'Unsqueeze', + inputs=['iter_count'], + outputs=['slice_start'], + axes=[0] +) + +end_unsqueeze_node = onnx.helper.make_node( + 'Unsqueeze', + inputs=['end'], + outputs=['slice_end'], + axes=[0] +) + +slice_node = onnx.helper.make_node( + 'Slice', + inputs=['x', 'slice_start', 'slice_end'], + outputs=['slice_out'] +) + +y_add_node = onnx.helper.make_node( + 'Add', + inputs=['y_in', 'slice_out'], + outputs=['y_out'] +) + +identity_node = onnx.helper.make_node( + 'Identity', + inputs=['cond_in'], + outputs=['cond_out'] +) + +scan_identity_node = onnx.helper.make_node( + 'Identity', + inputs=['y_out'], + outputs=['scan_out'] +) + +loop_body = onnx.helper.make_graph( + [identity_node, x_const_node, one_const_node, i_add_node, + start_unsqueeze_node, end_unsqueeze_node, slice_node, y_add_node, + scan_identity_node], + 'loop_body', + [iter_count, cond_in, y_in], + [cond_out, y_out, scan_out] +) + +node = onnx.helper.make_node( + 'Loop', + inputs=['trip_count', 'cond', 'y'], + outputs=['res_y', 'res_scan'], + body=loop_body +) + +trip_count = np.array(5).astype(np.int64) +res_y = np.array([13]).astype(np.float32) +cond = np.array(1).astype(bool) +res_scan = np.array([-1, 1, 4, 8, 13]).astype(np.float32).reshape((5, 1)) +expect(node, inputs=[trip_count, cond, y], outputs=[res_y, res_scan], + name='test_loop11', opset_imports=[onnx.helper.make_opsetid("", 11)]) +``` + +
+
+loop_13 + +```python +# Given a tensor x of values [x1, ..., xN], +# Return a sequence of tensors of +# [[x1], [x1, x2], ..., [x1, ..., xN]] + +seq_in = onnx.helper.make_tensor_sequence_value_info('seq_in', onnx.TensorProto.FLOAT, None) +seq_out = onnx.helper.make_tensor_sequence_value_info('seq_out', onnx.TensorProto.FLOAT, None) +cond_in = onnx.helper.make_tensor_value_info('cond_in', onnx.TensorProto.BOOL, []) +cond_out = onnx.helper.make_tensor_value_info('cond_out', onnx.TensorProto.BOOL, []) +iter_count = onnx.helper.make_tensor_value_info('iter_count', onnx.TensorProto.INT64, []) + +x = np.array([1, 2, 3, 4, 5]).astype(np.float32) + +x_const_node = onnx.helper.make_node( + 'Constant', + inputs=[], + outputs=['x'], + value=onnx.helper.make_tensor( + name='const_tensor_x', + data_type=onnx.TensorProto.FLOAT, + dims=x.shape, + vals=x.flatten().astype(float), + ) +) + +one_const_node = onnx.helper.make_node( + 'Constant', + inputs=[], + outputs=['one'], + value=onnx.helper.make_tensor( + name='const_tensor_one', + data_type=onnx.TensorProto.INT64, + dims=(), + vals=[1] + ) +) + +zero_const_node = onnx.helper.make_node( + 'Constant', + inputs=[], + outputs=['slice_start'], + value=onnx.helper.make_tensor( + name='const_tensor_zero', + data_type=onnx.TensorProto.INT64, + dims=(1,), + vals=[0] + ) +) + +axes_node = onnx.helper.make_node( + 'Constant', + inputs=[], + outputs=['axes'], + value=onnx.helper.make_tensor( + name='const_tensor_axes', + data_type=onnx.TensorProto.INT64, + dims=(), + vals=[0] + ) +) + +add_node = onnx.helper.make_node( + 'Add', + inputs=['iter_count', 'one'], + outputs=['end'] +) + +end_unsqueeze_node = onnx.helper.make_node( + 'Unsqueeze', + inputs=['end', 'axes'], + outputs=['slice_end'] +) + +slice_node = onnx.helper.make_node( + 'Slice', + inputs=['x', 'slice_start', 'slice_end'], + outputs=['slice_out'] +) + +insert_node = onnx.helper.make_node( + 'SequenceInsert', + inputs=['seq_in', 'slice_out'], + outputs=['seq_out'] +) + +identity_node = onnx.helper.make_node( + 'Identity', + inputs=['cond_in'], + outputs=['cond_out'] +) + +loop_body = onnx.helper.make_graph( + [identity_node, x_const_node, one_const_node, zero_const_node, add_node, + axes_node, end_unsqueeze_node, slice_node, insert_node], + 'loop_body', + [iter_count, cond_in, seq_in], + [cond_out, seq_out] +) + +node = onnx.helper.make_node( + 'Loop', + inputs=['trip_count', 'cond', 'seq_empty'], + outputs=['seq_res'], + body=loop_body +) + +trip_count = np.array(5).astype(np.int64) +seq_empty = [] # type: List[Any] +seq_res = [x[:int(i)] for i in x] +cond = np.array(1).astype(bool) +expect(node, inputs=[trip_count, cond, seq_empty], outputs=[seq_res], + name='test_loop13_seq', opset_imports=[onnx.helper.make_opsetid("", 13)], + input_type_protos=[onnx.helper.make_tensor_type_proto(onnx.TensorProto.INT64, trip_count.shape), + onnx.helper.make_tensor_type_proto(onnx.TensorProto.BOOL, cond.shape), + onnx.helper.make_sequence_type_proto( + onnx.helper.make_tensor_type_proto(onnx.TensorProto.FLOAT, []))]) +``` + +
+
+loop_16_none + +```python +# Given a tensor sequence of values [x1, ..., xN], and an initial optional sequence of tensors [x0], +# Return a concatenated sequence of tensors of +# [x0, [x1], [x1, x2], ..., [x1, ..., xN]] + +ten_in_tp = onnx.helper.make_tensor_type_proto(onnx.TensorProto.FLOAT, []) +seq_in_tp = onnx.helper.make_sequence_type_proto(ten_in_tp) +opt_in_tp = onnx.helper.make_optional_type_proto(seq_in_tp) +opt_in = onnx.helper.make_value_info('opt_seq_in', opt_in_tp) +seq_out = onnx.helper.make_tensor_sequence_value_info('seq_out', onnx.TensorProto.FLOAT, []) +cond_in = onnx.helper.make_tensor_value_info('cond_in', onnx.TensorProto.BOOL, []) +cond_out = onnx.helper.make_tensor_value_info('cond_out', onnx.TensorProto.BOOL, []) +iter_count = onnx.helper.make_tensor_value_info('iter_count', onnx.TensorProto.INT64, []) + +x0 = np.array(0).astype(np.float32) +x = np.array([1, 2, 3, 4, 5]).astype(np.float32) + +optional_has_elem_node = onnx.helper.make_node( + 'OptionalHasElement', + inputs=['opt_seq_in'], + outputs=['optional_has_elem'] +) + +optional_is_none = onnx.helper.make_node( + 'Not', + inputs=['optional_has_elem'], + outputs=['optional_is_none'] +) + +optional_get_elem = onnx.helper.make_node( + 'OptionalGetElement', + inputs=['opt_seq_in'], + outputs=['seq_in'] +) + +constant_in = onnx.helper.make_node( + 'Constant', + inputs=[], + outputs=['constant_in'], + value=onnx.helper.make_tensor( + name='const_tensor', + data_type=onnx.TensorProto.FLOAT, + dims=(), + vals=[0] + ) +) + +seq_const_in = onnx.helper.make_node( + 'SequenceConstruct', + inputs=['constant_in'], + outputs=['init_seq_in'] +) + +then_seq_out = onnx.helper.make_tensor_sequence_value_info('init_seq_in', onnx.TensorProto.FLOAT, []) +then_body = onnx.helper.make_graph( + [constant_in, seq_const_in], + 'then_body', + [], + [then_seq_out] +) + +else_seq_out = onnx.helper.make_tensor_sequence_value_info('seq_in', onnx.TensorProto.FLOAT, []) +else_body = onnx.helper.make_graph( + [optional_get_elem], + 'else_body', + [], + [else_seq_out] +) + +if_node = onnx.helper.make_node( + 'If', + inputs=['optional_is_none'], + outputs=['sequence'], + then_branch=then_body, + else_branch=else_body +) + +x_const_node = onnx.helper.make_node( + 'Constant', + inputs=[], + outputs=['x'], + value=onnx.helper.make_tensor( + name='const_tensor_x', + data_type=onnx.TensorProto.FLOAT, + dims=x.shape, + vals=x.flatten().astype(float), + ) +) + +one_const_node = onnx.helper.make_node( + 'Constant', + inputs=[], + outputs=['one'], + value=onnx.helper.make_tensor( + name='const_tensor_one', + data_type=onnx.TensorProto.INT64, + dims=(), + vals=[1] + ) +) + +zero_const_node = onnx.helper.make_node( + 'Constant', + inputs=[], + outputs=['slice_start'], + value=onnx.helper.make_tensor( + name='const_tensor_zero', + data_type=onnx.TensorProto.INT64, + dims=(1,), + vals=[0] + ) +) + +axes_node = onnx.helper.make_node( + 'Constant', + inputs=[], + outputs=['axes'], + value=onnx.helper.make_tensor( + name='const_tensor_axes', + data_type=onnx.TensorProto.INT64, + dims=(), + vals=[0] + ) +) + +add_node = onnx.helper.make_node( + 'Add', + inputs=['iter_count', 'one'], + outputs=['end'] +) + +end_unsqueeze_node = onnx.helper.make_node( + 'Unsqueeze', + inputs=['end', 'axes'], + outputs=['slice_end'] +) + +slice_node = onnx.helper.make_node( + 'Slice', + inputs=['x', 'slice_start', 'slice_end'], + outputs=['slice_out'] +) + +insert_node = onnx.helper.make_node( + 'SequenceInsert', + inputs=['sequence', 'slice_out'], + outputs=['seq_out'] +) + +identity_node = onnx.helper.make_node( + 'Identity', + inputs=['cond_in'], + outputs=['cond_out'] +) + +loop_body = onnx.helper.make_graph( + [identity_node, optional_has_elem_node, optional_is_none, if_node, x_const_node, one_const_node, + zero_const_node, add_node, axes_node, end_unsqueeze_node, slice_node, insert_node], + 'loop_body', + [iter_count, cond_in, opt_in], + [cond_out, seq_out] +) + +node = onnx.helper.make_node( + 'Loop', + inputs=['trip_count', 'cond', 'opt_seq'], + outputs=['seq_res'], + body=loop_body +) + +trip_count = np.array(5).astype(np.int64) +cond = np.array(1).astype(bool) +seq_res = compute_loop_outputs(x, [x0], trip_count) +opt_seq_in = [x0] # type: List[Any] +expect(node, inputs=[trip_count, cond, opt_seq_in], outputs=[seq_res], + name='test_loop16_seq_none', opset_imports=[onnx.helper.make_opsetid("", 16)], + input_type_protos=[onnx.helper.make_tensor_type_proto(onnx.TensorProto.INT64, trip_count.shape), + onnx.helper.make_tensor_type_proto(onnx.TensorProto.BOOL, cond.shape), + opt_in_tp]) +``` + +
+ + +### MatMul +There are 1 test cases, listed as following: +
+matmul + +```python +node = onnx.helper.make_node( + 'MatMul', + inputs=['a', 'b'], + outputs=['c'], +) + +# 2d +a = np.random.randn(3, 4).astype(np.float32) +b = np.random.randn(4, 3).astype(np.float32) +c = np.matmul(a, b) +expect(node, inputs=[a, b], outputs=[c], + name='test_matmul_2d') + +# 3d +a = np.random.randn(2, 3, 4).astype(np.float32) +b = np.random.randn(2, 4, 3).astype(np.float32) +c = np.matmul(a, b) +expect(node, inputs=[a, b], outputs=[c], + name='test_matmul_3d') + +# 4d +a = np.random.randn(1, 2, 3, 4).astype(np.float32) +b = np.random.randn(1, 2, 4, 3).astype(np.float32) +c = np.matmul(a, b) +expect(node, inputs=[a, b], outputs=[c], + name='test_matmul_4d') +``` + +
+ + +### MatMulInteger +There are 1 test cases, listed as following: +
+matmulinteger + +```python +node = onnx.helper.make_node('MatMulInteger', + inputs=['A', 'B', 'a_zero_point', 'b_zero_point'], + outputs=['Y'],) + +A = np.array([[11, 7, 3], + [10, 6, 2], + [9, 5, 1], + [8, 4, 0], ], dtype=np.uint8) + +a_zero_point = np.array([12], dtype=np.uint8) + +B = np.array([[1, 4], + [2, 5], + [3, 6], ], dtype=np.uint8) + +b_zero_point = np.array([0], dtype=np.uint8) + +output = np.array([[-38, -83], + [-44, -98], + [-50, -113], + [-56, -128], ], dtype=np.int32) + +expect(node, inputs=[A, B, a_zero_point, b_zero_point], outputs=[output], + name='test_matmulinteger') +``` + +
+ + +### Max +There are 2 test cases, listed as following: +
+max + +```python +data_0 = np.array([3, 2, 1]).astype(np.float32) +data_1 = np.array([1, 4, 4]).astype(np.float32) +data_2 = np.array([2, 5, 3]).astype(np.float32) +result = np.array([3, 5, 4]).astype(np.float32) +node = onnx.helper.make_node( + 'Max', + inputs=['data_0', 'data_1', 'data_2'], + outputs=['result'], +) +expect(node, inputs=[data_0, data_1, data_2], outputs=[result], + name='test_max_example') + +node = onnx.helper.make_node( + 'Max', + inputs=['data_0'], + outputs=['result'], +) +expect(node, inputs=[data_0], outputs=[data_0], + name='test_max_one_input') + +result = np.maximum(data_0, data_1) +node = onnx.helper.make_node( + 'Max', + inputs=['data_0', 'data_1'], + outputs=['result'], +) +expect(node, inputs=[data_0, data_1], outputs=[result], + name='test_max_two_inputs') +``` + +
+
+max_all_numeric_types + +```python +for op_dtype in all_numeric_dtypes: + data_0 = np.array([3, 2, 1]).astype(op_dtype) + data_1 = np.array([1, 4, 4]).astype(op_dtype) + result = np.array([3, 4, 4]).astype(op_dtype) + node = onnx.helper.make_node( + 'Max', + inputs=['data_0', 'data_1'], + outputs=['result'], + ) + expect(node, inputs=[data_0, data_1], outputs=[result], + name='test_max_{0}'.format(np.dtype(op_dtype).name)) +``` + +
+ + +### MaxPool +There are 15 test cases, listed as following: +
+maxpool_1d_default + +```python +""" +input_shape: [1, 3, 32] +output_shape: [1, 3, 31] +""" +node = onnx.helper.make_node( + 'MaxPool', + inputs=['x'], + outputs=['y'], + kernel_shape=[2], +) +x = np.random.randn(1, 3, 32).astype(np.float32) +x_shape = np.shape(x) +kernel_shape = [2] +strides = [1] +out_shape = get_output_shape('VALID', x_shape[2:], kernel_shape, strides) +padded = x +y = pool(padded, x_shape, kernel_shape, strides, out_shape, [0], 'MAX') + +expect(node, inputs=[x], outputs=[y], name='test_maxpool_1d_default') +``` + +
+
+maxpool_2d_ceil + +```python +""" +input_shape: [1, 1, 4, 4] +output_shape: [1, 1, 2, 2] +""" +node = onnx.helper.make_node( + 'MaxPool', + inputs=['x'], + outputs=['y'], + kernel_shape=[3, 3], + strides=[2, 2], + ceil_mode=True +) +x = np.array([[[ + [1, 2, 3, 4], + [5, 6, 7, 8], + [9, 10, 11, 12], + [13, 14, 15, 16], +]]]).astype(np.float32) +y = np.array([[[ + [11, 12], + [15, 16]]]]).astype(np.float32) + +expect(node, inputs=[x], outputs=[y], name='test_maxpool_2d_ceil') +``` + +
+
+maxpool_2d_default + +```python +""" +input_shape: [1, 3, 32, 32] +output_shape: [1, 3, 31, 31] +""" +node = onnx.helper.make_node( + 'MaxPool', + inputs=['x'], + outputs=['y'], + kernel_shape=[2, 2], +) +x = np.random.randn(1, 3, 32, 32).astype(np.float32) +x_shape = np.shape(x) +kernel_shape = (2, 2) +strides = (1, 1) +out_shape = get_output_shape('VALID', x_shape[2:], kernel_shape, strides) +padded = x +y = pool(padded, x_shape, kernel_shape, strides, out_shape, (0, 0), 'MAX') + +expect(node, inputs=[x], outputs=[y], name='test_maxpool_2d_default') +``` + +
+
+maxpool_2d_dilations + +```python +""" +input_shape: [1, 1, 4, 4] +output_shape: [1, 1, 2, 2] +""" +node = onnx.helper.make_node( + 'MaxPool', + inputs=['x'], + outputs=['y'], + kernel_shape=[2, 2], + strides=[1, 1], + dilations=[2, 2] +) +x = np.array([[[ + [1, 2, 3, 4], + [5, 6, 7, 8], + [9, 10, 11, 12], + [13, 14, 15, 16], +]]]).astype(np.float32) +y = np.array([[[ + [11, 12], + [15, 16]]]]).astype(np.float32) + +expect(node, inputs=[x], outputs=[y], name='test_maxpool_2d_dilations') +``` + +
+
+maxpool_2d_pads + +```python +""" +input_shape: [1, 3, 28, 28] +output_shape: [1, 3, 30, 30] +pad_shape: [4, 4] -> [2, 2, 2, 2] by axis +""" +node = onnx.helper.make_node( + 'MaxPool', + inputs=['x'], + outputs=['y'], + kernel_shape=[3, 3], + pads=[2, 2, 2, 2] +) +x = np.random.randn(1, 3, 28, 28).astype(np.float32) +x_shape = np.shape(x) +kernel_shape = (3, 3) +strides = (1, 1) +pad_bottom = pad_top = pad_right = pad_left = 2 +pad_shape = [pad_top + pad_bottom, pad_left + pad_right] +out_shape = get_output_shape('VALID', np.add(x_shape[2:], pad_shape), kernel_shape, strides) +padded = np.pad(x, ((0, 0), (0, 0), (pad_top, pad_bottom), (pad_left, pad_right)), mode='constant', + constant_values=np.nan) +y = pool(padded, x_shape, kernel_shape, strides, out_shape, pad_shape, 'MAX') + +expect(node, inputs=[x], outputs=[y], name='test_maxpool_2d_pads') +``` + +
+
+maxpool_2d_precomputed_pads + +```python +""" +input_shape: [1, 1, 5, 5] +output_shape: [1, 1, 5, 5] +pad_shape: [4, 4] -> [2, 2, 2, 2] by axis +""" +node = onnx.helper.make_node( + 'MaxPool', + inputs=['x'], + outputs=['y'], + kernel_shape=[5, 5], + pads=[2, 2, 2, 2] + +) +x = np.array([[[ + [1, 2, 3, 4, 5], + [6, 7, 8, 9, 10], + [11, 12, 13, 14, 15], + [16, 17, 18, 19, 20], + [21, 22, 23, 24, 25], +]]]).astype(np.float32) +y = np.array([[[ + [13, 14, 15, 15, 15], + [18, 19, 20, 20, 20], + [23, 24, 25, 25, 25], + [23, 24, 25, 25, 25], + [23, 24, 25, 25, 25]]]]).astype(np.float32) + +expect(node, inputs=[x], outputs=[y], name='test_maxpool_2d_precomputed_pads') +``` + +
+
+maxpool_2d_precomputed_same_upper + +```python +""" +input_shape: [1, 1, 5, 5] +output_shape: [1, 1, 3, 3] +pad_shape: [2, 2] -> [1, 1, 1, 1] by axis +""" +node = onnx.helper.make_node( + 'MaxPool', + inputs=['x'], + outputs=['y'], + kernel_shape=[3, 3], + strides=[2, 2], + auto_pad='SAME_UPPER' +) +x = np.array([[[ + [1, 2, 3, 4, 5], + [6, 7, 8, 9, 10], + [11, 12, 13, 14, 15], + [16, 17, 18, 19, 20], + [21, 22, 23, 24, 25], +]]]).astype(np.float32) +y = np.array([[[[7, 9, 10], + [17, 19, 20], + [22, 24, 25]]]]).astype(np.float32) + +expect(node, inputs=[x], outputs=[y], name='test_maxpool_2d_precomputed_same_upper') +``` + +
+
+maxpool_2d_precomputed_strides + +```python +""" +input_shape: [1, 1, 5, 5] +output_shape: [1, 1, 2, 2] +""" +node = onnx.helper.make_node( + 'MaxPool', + inputs=['x'], + outputs=['y'], + kernel_shape=[2, 2], + strides=[2, 2] +) +x = np.array([[[ + [1, 2, 3, 4, 5], + [6, 7, 8, 9, 10], + [11, 12, 13, 14, 15], + [16, 17, 18, 19, 20], + [21, 22, 23, 24, 25], +]]]).astype(np.float32) +y = np.array([[[[7, 9], + [17, 19]]]]).astype(np.float32) + +expect(node, inputs=[x], outputs=[y], name='test_maxpool_2d_precomputed_strides') +``` + +
+
+maxpool_2d_same_lower + +```python +""" +input_shape: [1, 3, 32, 32] +output_shape: [1, 3, 32, 32] +pad_shape: [1, 1] -> [1, 0, 1, 0] by axis +""" +node = onnx.helper.make_node( + 'MaxPool', + inputs=['x'], + outputs=['y'], + kernel_shape=[2, 2], + auto_pad='SAME_LOWER' +) +x = np.random.randn(1, 3, 32, 32).astype(np.float32) +x_shape = np.shape(x) +kernel_shape = (2, 2) +strides = (1, 1) +out_shape = get_output_shape('SAME_LOWER', x_shape[2:], kernel_shape, strides) +pad_shape = get_pad_shape('SAME_LOWER', x_shape[2:], kernel_shape, strides, out_shape) +pad_bottom = pad_shape[0] // 2 +pad_top = pad_shape[0] - pad_bottom +pad_right = pad_shape[1] // 2 +pad_left = pad_shape[1] - pad_right +padded = np.pad(x, ((0, 0), (0, 0), (pad_top, pad_bottom), (pad_left, pad_right)), mode='constant', + constant_values=np.nan) +y = pool(padded, x_shape, kernel_shape, strides, out_shape, pad_shape, 'MAX') + +expect(node, inputs=[x], outputs=[y], name='test_maxpool_2d_same_lower') +``` + +
+
+maxpool_2d_same_upper + +```python +""" +input_shape: [1, 3, 32, 32] +output_shape: [1, 3, 32, 32] +pad_shape: [1, 1] -> [0, 1, 0, 1] by axis +""" +node = onnx.helper.make_node( + 'MaxPool', + inputs=['x'], + outputs=['y'], + kernel_shape=[2, 2], + auto_pad='SAME_UPPER' +) +x = np.random.randn(1, 3, 32, 32).astype(np.float32) +x_shape = np.shape(x) +kernel_shape = (2, 2) +strides = (1, 1) +out_shape = get_output_shape('SAME_UPPER', x_shape[2:], kernel_shape, strides) +pad_shape = get_pad_shape('SAME_UPPER', x_shape[2:], kernel_shape, strides, out_shape) +pad_top = pad_shape[0] // 2 +pad_bottom = pad_shape[0] - pad_top +pad_left = pad_shape[1] // 2 +pad_right = pad_shape[1] - pad_left +padded = np.pad(x, ((0, 0), (0, 0), (pad_top, pad_bottom), (pad_left, pad_right)), mode='constant', + constant_values=np.nan) +y = pool(padded, x_shape, kernel_shape, strides, out_shape, pad_shape, 'MAX') + +expect(node, inputs=[x], outputs=[y], name='test_maxpool_2d_same_upper') +``` + +
+
+maxpool_2d_strides + +```python +""" +input_shape: [1, 3, 32, 32] +output_shape: [1, 3, 10, 10] +""" +node = onnx.helper.make_node( + 'MaxPool', + inputs=['x'], + outputs=['y'], + kernel_shape=[5, 5], + strides=[3, 3] +) +x = np.random.randn(1, 3, 32, 32).astype(np.float32) +x_shape = np.shape(x) +kernel_shape = (5, 5) +strides = (3, 3) +out_shape = get_output_shape('VALID', x_shape[2:], kernel_shape, strides) +padded = x +y = pool(padded, x_shape, kernel_shape, strides, out_shape, (0, 0), 'MAX') + +expect(node, inputs=[x], outputs=[y], name='test_maxpool_2d_strides') +``` + +
+
+maxpool_2d_uint8 + +```python +""" +input_shape: [1, 1, 5, 5] +output_shape: [1, 1, 5, 5] +pad_shape: [4, 4] -> [2, 2, 2, 2] by axis +""" +node = onnx.helper.make_node( + 'MaxPool', + inputs=['x'], + outputs=['y'], + kernel_shape=[5, 5], + pads=[2, 2, 2, 2] +) +x = np.array([[[ + [1, 2, 3, 4, 5], + [6, 7, 8, 9, 10], + [11, 12, 13, 14, 15], + [16, 17, 18, 19, 20], + [21, 22, 23, 24, 25], +]]]).astype(np.uint8) +y = np.array([[[ + [13, 14, 15, 15, 15], + [18, 19, 20, 20, 20], + [23, 24, 25, 25, 25], + [23, 24, 25, 25, 25], + [23, 24, 25, 25, 25]]]]).astype(np.uint8) + +expect(node, inputs=[x], outputs=[y], name='test_maxpool_2d_uint8') +``` + +
+
+maxpool_3d_default + +```python +""" +input_shape: [1, 3, 32, 32, 32] +output_shape: [1, 3, 31, 31, 31] +""" +node = onnx.helper.make_node( + 'MaxPool', + inputs=['x'], + outputs=['y'], + kernel_shape=[2, 2, 2], +) +x = np.random.randn(1, 3, 32, 32, 32).astype(np.float32) +x_shape = np.shape(x) +kernel_shape = [2, 2, 2] +strides = [1, 1, 1] +out_shape = get_output_shape('VALID', x_shape[2:], kernel_shape, strides) +padded = x +y = pool(padded, x_shape, kernel_shape, strides, out_shape, [0, 0, 0], 'MAX') + +expect(node, inputs=[x], outputs=[y], name='test_maxpool_3d_default') +``` + +
+
+maxpool_with_argmax_2d_precomputed_pads + +```python +""" +input_shape: [1, 1, 5, 5] +output_shape: [1, 1, 5, 5] +pad_shape: [4, 4] -> [2, 2, 2, 2] by axis +""" +node = onnx.helper.make_node( + 'MaxPool', + inputs=['x'], + outputs=['y', 'z'], + kernel_shape=[5, 5], + pads=[2, 2, 2, 2] +) +x = np.array([[[ + [1, 2, 3, 4, 5], + [6, 7, 8, 9, 10], + [11, 12, 13, 14, 15], + [16, 17, 18, 19, 20], + [21, 22, 23, 24, 25], +]]]).astype(np.float32) +y = np.array([[[ + [13, 14, 15, 15, 15], + [18, 19, 20, 20, 20], + [23, 24, 25, 25, 25], + [23, 24, 25, 25, 25], + [23, 24, 25, 25, 25]]]]).astype(np.float32) +z = np.array([[[ + [12, 13, 14, 14, 14], + [17, 18, 19, 19, 19], + [22, 23, 24, 24, 24], + [22, 23, 24, 24, 24], + [22, 23, 24, 24, 24]]]]).astype(np.int64) + +expect(node, inputs=[x], outputs=[y, z], name='test_maxpool_with_argmax_2d_precomputed_pads') +``` + +
+
+maxpool_with_argmax_2d_precomputed_strides + +```python +""" +input_shape: [1, 1, 5, 5] +output_shape: [1, 1, 2, 2] +""" +node = onnx.helper.make_node( + 'MaxPool', + inputs=['x'], + outputs=['y', 'z'], + kernel_shape=[2, 2], + strides=[2, 2], + storage_order=1 +) +x = np.array([[[ + [1, 2, 3, 4, 5], + [6, 7, 8, 9, 10], + [11, 12, 13, 14, 15], + [16, 17, 18, 19, 20], + [21, 22, 23, 24, 25], +]]]).astype(np.float32) +y = np.array([[[[7, 9], + [17, 19]]]]).astype(np.float32) +z = np.array([[[[6, 16], + [8, 18]]]]).astype(np.int64) + +expect(node, inputs=[x], outputs=[y, z], name='test_maxpool_with_argmax_2d_precomputed_strides') +``` + +
+ + +### MaxUnpool +There are 2 test cases, listed as following: +
+with_output_shape + +```python +node = onnx.helper.make_node( + 'MaxUnpool', + inputs=['xT', 'xI', 'output_shape'], + outputs=['y'], + kernel_shape=[2, 2], + strides=[2, 2] +) +xT = np.array([[[[5, 6], + [7, 8]]]], dtype=np.float32) +xI = np.array([[[[5, 7], + [13, 15]]]], dtype=np.int64) +output_shape = np.array((1, 1, 5, 5), dtype=np.int64) +y = np.array([[[[0, 0, 0, 0, 0], + [0, 5, 0, 6, 0], + [0, 0, 0, 0, 0], + [0, 7, 0, 8, 0], + [0, 0, 0, 0, 0]]]], dtype=np.float32) +expect(node, inputs=[xT, xI, output_shape], outputs=[y], name='test_maxunpool_export_with_output_shape') +``` + +
+
+without_output_shape + +```python +node = onnx.helper.make_node( + 'MaxUnpool', + inputs=['xT', 'xI'], + outputs=['y'], + kernel_shape=[2, 2], + strides=[2, 2] +) +xT = np.array([[[[1, 2], + [3, 4]]]], dtype=np.float32) +xI = np.array([[[[5, 7], + [13, 15]]]], dtype=np.int64) +y = np.array([[[[0, 0, 0, 0], + [0, 1, 0, 2], + [0, 0, 0, 0], + [0, 3, 0, 4]]]], dtype=np.float32) +expect(node, inputs=[xT, xI], outputs=[y], name='test_maxunpool_export_without_output_shape') +``` + +
+ + +### Mean +There are 1 test cases, listed as following: +
+mean + +```python +data_0 = np.array([3, 0, 2]).astype(np.float32) +data_1 = np.array([1, 3, 4]).astype(np.float32) +data_2 = np.array([2, 6, 6]).astype(np.float32) +result = np.array([2, 3, 4]).astype(np.float32) +node = onnx.helper.make_node( + 'Mean', + inputs=['data_0', 'data_1', 'data_2'], + outputs=['result'], +) +expect(node, inputs=[data_0, data_1, data_2], outputs=[result], + name='test_mean_example') + +node = onnx.helper.make_node( + 'Mean', + inputs=['data_0'], + outputs=['result'], +) +expect(node, inputs=[data_0], outputs=[data_0], + name='test_mean_one_input') + +result = np.divide(np.add(data_0, data_1), 2.) +node = onnx.helper.make_node( + 'Mean', + inputs=['data_0', 'data_1'], + outputs=['result'], +) +expect(node, inputs=[data_0, data_1], outputs=[result], + name='test_mean_two_inputs') +``` + +
+ + +### MeanVarianceNormalization +There are 1 test cases, listed as following: +
+meanvariancenormalization + +```python +node = onnx.helper.make_node( + 'MeanVarianceNormalization', + inputs=['X'], + outputs=['Y'] +) + +input_data = np.array([[[[0.8439683], [0.5665144], [0.05836735]], + [[0.02916367], [0.12964272], [0.5060197]], + [[0.79538304], [0.9411346], [0.9546573]]], + [[[0.17730942], [0.46192095], [0.26480448]], + [[0.6746842], [0.01665257], [0.62473077]], + [[0.9240844], [0.9722341], [0.11965699]]], + [[[0.41356155], [0.9129373], [0.59330076]], + [[0.81929934], [0.7862604], [0.11799799]], + [[0.69248444], [0.54119414], [0.07513223]]]], dtype=np.float32) + +# Calculate expected output data +data_mean = np.mean(input_data, axis=(0, 2, 3), keepdims=1) +data_mean_squared = np.power(data_mean, 2) +data_squared = np.power(input_data, 2) +data_squared_mean = np.mean(data_squared, axis=(0, 2, 3), keepdims=1) +std = np.sqrt(data_squared_mean - data_mean_squared) +expected_output = (input_data - data_mean) / (std + 1e-9) + +expect(node, inputs=[input_data], outputs=[expected_output], + name='test_mvn') +``` + +
+ + +### Min +There are 2 test cases, listed as following: +
+min + +```python +data_0 = np.array([3, 2, 1]).astype(np.float32) +data_1 = np.array([1, 4, 4]).astype(np.float32) +data_2 = np.array([2, 5, 0]).astype(np.float32) +result = np.array([1, 2, 0]).astype(np.float32) +node = onnx.helper.make_node( + 'Min', + inputs=['data_0', 'data_1', 'data_2'], + outputs=['result'], +) +expect(node, inputs=[data_0, data_1, data_2], outputs=[result], + name='test_min_example') + +node = onnx.helper.make_node( + 'Min', + inputs=['data_0'], + outputs=['result'], +) +expect(node, inputs=[data_0], outputs=[data_0], + name='test_min_one_input') + +result = np.minimum(data_0, data_1) +node = onnx.helper.make_node( + 'Min', + inputs=['data_0', 'data_1'], + outputs=['result'], +) +expect(node, inputs=[data_0, data_1], outputs=[result], + name='test_min_two_inputs') +``` + +
+
+min_all_numeric_types + +```python +for op_dtype in all_numeric_dtypes: + data_0 = np.array([3, 2, 1]).astype(op_dtype) + data_1 = np.array([1, 4, 4]).astype(op_dtype) + result = np.array([1, 2, 1]).astype(op_dtype) + node = onnx.helper.make_node( + 'Min', + inputs=['data_0', 'data_1'], + outputs=['result'], + ) + expect(node, inputs=[data_0, data_1], outputs=[result], + name='test_min_{0}'.format(np.dtype(op_dtype).name)) +``` + +
+ + +### Mod +There are 13 test cases, listed as following: +
+mod_broadcast + +```python +node = onnx.helper.make_node( + 'Mod', + inputs=['x', 'y'], + outputs=['z'], +) + +x = np.arange(0, 30).reshape([3, 2, 5]).astype(np.int32) +y = np.array([7]).astype(np.int32) +z = np.mod(x, y) +# array([[[0, 1, 2, 3, 4], +# [5, 6, 0, 1, 2]], + +# [[3, 4, 5, 6, 0], +# [1, 2, 3, 4, 5]], + +# [[6, 0, 1, 2, 3], +# [4, 5, 6, 0, 1]]], dtype=int32) +expect(node, inputs=[x, y], outputs=[z], + name='test_mod_broadcast') +``` + +
+
+mod_int64_fmod + +```python +node = onnx.helper.make_node( + 'Mod', + inputs=['x', 'y'], + outputs=['z'], + fmod=1 +) + +x = np.array([-4, 7, 5, 4, -7, 8]).astype(np.int64) +y = np.array([2, -3, 8, -2, 3, 5]).astype(np.int64) +z = np.fmod(x, y) # expected output [ 0, 1, 5, 0, -1, 3] +expect(node, inputs=[x, y], outputs=[z], + name='test_mod_int64_fmod') +``` + +
+
+mod_mixed_sign_float16 + +```python +node = onnx.helper.make_node( + 'Mod', + inputs=['x', 'y'], + outputs=['z'], + fmod=1 +) + +x = np.array([-4.3, 7.2, 5.0, 4.3, -7.2, 8.0]).astype(np.float16) +y = np.array([2.1, -3.4, 8.0, -2.1, 3.4, 5.0]).astype(np.float16) +z = np.fmod(x, y) # expected output [-0.10156, 0.3984 , 5. , 0.10156, -0.3984 , 3.] +expect(node, inputs=[x, y], outputs=[z], + name='test_mod_mixed_sign_float16') +``` + +
+
+mod_mixed_sign_float32 + +```python +node = onnx.helper.make_node( + 'Mod', + inputs=['x', 'y'], + outputs=['z'], + fmod=1 +) + +x = np.array([-4.3, 7.2, 5.0, 4.3, -7.2, 8.0]).astype(np.float32) +y = np.array([2.1, -3.4, 8.0, -2.1, 3.4, 5.0]).astype(np.float32) +z = np.fmod(x, y) # expected output [-0.10000038, 0.39999962, 5. , 0.10000038, -0.39999962, 3.] +expect(node, inputs=[x, y], outputs=[z], + name='test_mod_mixed_sign_float32') +``` + +
+
+mod_mixed_sign_float64 + +```python +node = onnx.helper.make_node( + 'Mod', + inputs=['x', 'y'], + outputs=['z'], + fmod=1 +) + +x = np.array([-4.3, 7.2, 5.0, 4.3, -7.2, 8.0]).astype(np.float64) +y = np.array([2.1, -3.4, 8.0, -2.1, 3.4, 5.0]).astype(np.float64) +z = np.fmod(x, y) # expected output [-0.1, 0.4, 5. , 0.1, -0.4, 3.] +expect(node, inputs=[x, y], outputs=[z], + name='test_mod_mixed_sign_float64') +``` + +
+
+mod_mixed_sign_int16 + +```python +node = onnx.helper.make_node( + 'Mod', + inputs=['x', 'y'], + outputs=['z'], +) + +x = np.array([-4, 7, 5, 4, -7, 8]).astype(np.int16) +y = np.array([2, -3, 8, -2, 3, 5]).astype(np.int16) +z = np.mod(x, y) # expected output [ 0, -2, 5, 0, 2, 3] +expect(node, inputs=[x, y], outputs=[z], + name='test_mod_mixed_sign_int16') +``` + +
+
+mod_mixed_sign_int32 + +```python +node = onnx.helper.make_node( + 'Mod', + inputs=['x', 'y'], + outputs=['z'], +) + +x = np.array([-4, 7, 5, 4, -7, 8]).astype(np.int32) +y = np.array([2, -3, 8, -2, 3, 5]).astype(np.int32) +z = np.mod(x, y) # expected output [ 0, -2, 5, 0, 2, 3] +expect(node, inputs=[x, y], outputs=[z], + name='test_mod_mixed_sign_int32') +``` + +
+
+mod_mixed_sign_int64 + +```python +node = onnx.helper.make_node( + 'Mod', + inputs=['x', 'y'], + outputs=['z'], +) + +x = np.array([-4, 7, 5, 4, -7, 8]).astype(np.int64) +y = np.array([2, -3, 8, -2, 3, 5]).astype(np.int64) +z = np.mod(x, y) # expected output [ 0, -2, 5, 0, 2, 3] +expect(node, inputs=[x, y], outputs=[z], + name='test_mod_mixed_sign_int64') +``` + +
+
+mod_mixed_sign_int8 + +```python +node = onnx.helper.make_node( + 'Mod', + inputs=['x', 'y'], + outputs=['z'], +) + +x = np.array([-4, 7, 5, 4, -7, 8]).astype(np.int8) +y = np.array([2, -3, 8, -2, 3, 5]).astype(np.int8) +z = np.mod(x, y) # expected output [ 0, -2, 5, 0, 2, 3] +expect(node, inputs=[x, y], outputs=[z], + name='test_mod_mixed_sign_int8') +``` + +
+
+mod_uint16 + +```python +node = onnx.helper.make_node( + 'Mod', + inputs=['x', 'y'], + outputs=['z'], +) + +x = np.array([4, 7, 5]).astype(np.uint16) +y = np.array([2, 3, 8]).astype(np.uint16) +z = np.mod(x, y) # expected output [0, 1, 5] +expect(node, inputs=[x, y], outputs=[z], + name='test_mod_uint16') +``` + +
+
+mod_uint32 + +```python +node = onnx.helper.make_node( + 'Mod', + inputs=['x', 'y'], + outputs=['z'], +) + +x = np.array([4, 7, 5]).astype(np.uint32) +y = np.array([2, 3, 8]).astype(np.uint32) +z = np.mod(x, y) # expected output [0, 1, 5] +expect(node, inputs=[x, y], outputs=[z], + name='test_mod_uint32') +``` + +
+
+mod_uint64 + +```python +node = onnx.helper.make_node( + 'Mod', + inputs=['x', 'y'], + outputs=['z'], +) + +x = np.array([4, 7, 5]).astype(np.uint64) +y = np.array([2, 3, 8]).astype(np.uint64) +z = np.mod(x, y) # expected output [0, 1, 5] +expect(node, inputs=[x, y], outputs=[z], + name='test_mod_uint64') +``` + +
+
+mod_uint8 + +```python +node = onnx.helper.make_node( + 'Mod', + inputs=['x', 'y'], + outputs=['z'], +) + +x = np.array([4, 7, 5]).astype(np.uint8) +y = np.array([2, 3, 8]).astype(np.uint8) +z = np.mod(x, y) # expected output [0, 1, 5] +expect(node, inputs=[x, y], outputs=[z], + name='test_mod_uint8') +``` + +
+ + +### Momentum +There are 3 test cases, listed as following: +
+momentum + +```python +# Define operator attributes. +norm_coefficient = 0.001 +alpha = 0.95 +beta = 0.1 + +# Create operator. +node = onnx.helper.make_node('Momentum', + inputs=['R', 'T', 'X', 'G', 'V'], + outputs=['X_new', 'V_new'], + norm_coefficient=norm_coefficient, + alpha=alpha, + beta=beta, + mode='standard', + domain=AI_ONNX_PREVIEW_TRAINING_DOMAIN + ) + +# Define operator inputs. +r = np.array(0.1, dtype=np.float32) # scalar +t = np.array(0, dtype=np.int64) # scalar +x = np.array([1.2, 2.8], dtype=np.float32) +g = np.array([-0.94, -2.5], dtype=np.float32) +v = np.array([1.7, 3.6], dtype=np.float32) + +# Compute expected outputs of Momentum. +x_new, v_new = apply_momentum(r, t, x, g, v, + norm_coefficient, alpha, beta) + +# Check results. +expect(node, inputs=[r, t, x, g, v], + outputs=[x_new, v_new], name='test_momentum', + opset_imports=[onnx.helper.make_opsetid(AI_ONNX_PREVIEW_TRAINING_DOMAIN, 1)]) +``` + +
+
+momentum_multiple + +```python +# Define operator attributes. +norm_coefficient = 0.001 +alpha = 0.95 +beta = 0.85 + +node = onnx.helper.make_node('Momentum', + inputs=['R', 'T', 'X1', 'X2', + 'G1', 'G2', 'H1', 'H2'], + outputs=['X1_new', 'X2_new', + 'V1_new', 'V2_new'], + norm_coefficient=norm_coefficient, + alpha=alpha, + beta=beta, + mode='standard', + domain=AI_ONNX_PREVIEW_TRAINING_DOMAIN + ) + +# Define operator inputs. +r = np.array(0.1, dtype=np.float32) # scalar +t = np.array(0, dtype=np.int64) # scalar + +x1 = np.array([1.0], dtype=np.float32) +g1 = np.array([-1.0], dtype=np.float32) +v1 = np.array([2.0], dtype=np.float32) + +x2 = np.array([1.0, 2.0], dtype=np.float32) +g2 = np.array([-1.0, -3.0], dtype=np.float32) +v2 = np.array([4.0, 1.0], dtype=np.float32) + +# Compute expected outputs of Momentum. +x1_new, v1_new = apply_momentum(r, t, x1, g1, v1, + norm_coefficient, alpha, beta) +x2_new, v2_new = apply_momentum(r, t, x2, g2, v2, + norm_coefficient, alpha, beta) + +# Check results. +expect(node, inputs=[r, t, x1, x2, g1, g2, v1, v2], + outputs=[x1_new, x2_new, v1_new, v2_new], name='test_momentum_multiple', + opset_imports=[onnx.helper.make_opsetid(AI_ONNX_PREVIEW_TRAINING_DOMAIN, 1)]) +``` + +
+
+nesterov_momentum + +```python +# Define operator attributes. +norm_coefficient = 0.01 +alpha = 0.95 +beta = 1.0 + +# Create operator. +node = onnx.helper.make_node('Momentum', + inputs=['R', 'T', 'X', 'G', 'V'], + outputs=['X_new', 'V_new'], + norm_coefficient=norm_coefficient, + alpha=alpha, + beta=beta, + mode='nesterov', + domain=AI_ONNX_PREVIEW_TRAINING_DOMAIN + ) + +# Define operator inputs. +r = np.array(0.1, dtype=np.float32) # scalar +t = np.array(0, dtype=np.int64) # scalar +x = np.array([1.2, 2.8], dtype=np.float32) +g = np.array([-0.94, -2.5], dtype=np.float32) +v = np.array([1.7, 3.6], dtype=np.float32) + +# Compute expected outputs of Momentum. +x_new, v_new = apply_nesterov(r, t, x, g, v, + norm_coefficient, alpha, beta) + +# Check results. +expect(node, inputs=[r, t, x, g, v], + outputs=[x_new, v_new], name='test_nesterov_momentum', + opset_imports=[onnx.helper.make_opsetid(AI_ONNX_PREVIEW_TRAINING_DOMAIN, 1)]) +``` + +
+ + +### Mul +There are 2 test cases, listed as following: +
+mul + +```python +node = onnx.helper.make_node( + 'Mul', + inputs=['x', 'y'], + outputs=['z'], +) + +x = np.array([1, 2, 3]).astype(np.float32) +y = np.array([4, 5, 6]).astype(np.float32) +z = x * y # expected output [4., 10., 18.] +expect(node, inputs=[x, y], outputs=[z], + name='test_mul_example') + +x = np.random.randn(3, 4, 5).astype(np.float32) +y = np.random.randn(3, 4, 5).astype(np.float32) +z = x * y +expect(node, inputs=[x, y], outputs=[z], + name='test_mul') + +x = np.random.randint(4, size=(3, 4, 5), dtype=np.uint8) +y = np.random.randint(24, size=(3, 4, 5), dtype=np.uint8) +z = x * y +expect(node, inputs=[x, y], outputs=[z], + name='test_mul_uint8') +``` + +
+
+mul_broadcast + +```python +node = onnx.helper.make_node( + 'Mul', + inputs=['x', 'y'], + outputs=['z'], +) + +x = np.random.randn(3, 4, 5).astype(np.float32) +y = np.random.randn(5).astype(np.float32) +z = x * y +expect(node, inputs=[x, y], outputs=[z], + name='test_mul_bcast') +``` + +
+ + +### Neg +There are 1 test cases, listed as following: +
+neg + +```python +node = onnx.helper.make_node( + 'Neg', + inputs=['x'], + outputs=['y'], +) + +x = np.array([-4, 2]).astype(np.float32) +y = np.negative(x) # expected output [4., -2.], +expect(node, inputs=[x], outputs=[y], + name='test_neg_example') + +x = np.random.randn(3, 4, 5).astype(np.float32) +y = np.negative(x) +expect(node, inputs=[x], outputs=[y], + name='test_neg') +``` + +
+ + +### NegativeLogLikelihoodLoss +There are 18 test cases, listed as following: +
+input_shape_is_NC + +```python +reduction = 'none' +node = onnx.helper.make_node( + 'NegativeLogLikelihoodLoss', + inputs=['input', 'target'], + outputs=['loss'], + reduction=reduction +) + +N, C = 3, 5 +np.random.seed(0) +input = np.random.rand(N, C).astype(np.float32) +target = np.random.randint(0, high=C, size=(N, )).astype(np.int64) + +negative_log_likelihood_loss = compute_negative_log_likelihood_loss(input, target, weight=None, reduction=reduction) + +expect(node, inputs=[input, target], outputs=[negative_log_likelihood_loss], + name='test_nllloss_NC') +``` + +
+
+input_shape_is_NCd1 + +```python +reduction = 'mean' +node = onnx.helper.make_node( + 'NegativeLogLikelihoodLoss', + inputs=['input', 'target'], + outputs=['loss'], + reduction=reduction +) + +N, C, d1 = 3, 5, 2 +np.random.seed(0) +input = np.random.rand(N, C, d1).astype(np.float32) +target = np.random.randint(0, high=C, size=(N, d1)).astype(np.int64) + +negative_log_likelihood_loss = compute_negative_log_likelihood_loss(input, target, weight=None, reduction=reduction) + +expect(node, inputs=[input, target], outputs=[negative_log_likelihood_loss], + name='test_nllloss_NCd1') +``` + +
+
+input_shape_is_NCd1_ii + +```python +reduction = 'mean' +ignore_index = np.int64(1) +node = onnx.helper.make_node( + 'NegativeLogLikelihoodLoss', + inputs=['input', 'target'], + outputs=['loss'], + reduction=reduction, + ignore_index=ignore_index +) + +N, C, d1 = 3, 5, 2 +np.random.seed(0) +input = np.random.rand(N, C, d1).astype(np.float32) +target = np.random.randint(0, high=C, size=(N, d1)).astype(np.int64) +target[0][0] = np.int64(1) + +negative_log_likelihood_loss = compute_negative_log_likelihood_loss(input, target, weight=None, reduction=reduction, ignore_index=ignore_index) + +expect(node, inputs=[input, target], outputs=[negative_log_likelihood_loss], + name='test_nllloss_NCd1_ii') +``` + +
+
+input_shape_is_NCd1_mean_weight_negative_ii + +```python +reduction = 'mean' +ignore_index = np.int64(-1) + +node = onnx.helper.make_node( + 'NegativeLogLikelihoodLoss', + inputs=['input', 'target', 'weight'], + outputs=['loss'], + reduction=reduction, + ignore_index=ignore_index) + +N, C, dim1 = 3, 5, 6 +np.random.seed(0) +input = np.random.rand(N, C, dim1).astype(np.float32) +target = np.random.randint(0, high=C, size=(N, dim1)).astype(np.int64) +target[0][0] = -1 +weight = np.random.rand(C).astype(np.float32) + +negative_log_likelihood_loss = compute_negative_log_likelihood_loss(input, + target, + weight=weight, + reduction=reduction, + ignore_index=ignore_index) + +expect(node, inputs=[input, target, weight], outputs=[negative_log_likelihood_loss], + name='test_nllloss_NCd1_mean_weight_negative_ii') +``` + +
+
+input_shape_is_NCd1_weight + +```python +reduction = 'mean' +node = onnx.helper.make_node( + 'NegativeLogLikelihoodLoss', + inputs=['input', 'target', 'weight'], + outputs=['loss'], + reduction=reduction +) + +N, C, d1 = 3, 5, 2 +np.random.seed(0) +input = np.random.rand(N, C, d1).astype(np.float32) +target = np.random.randint(0, high=C, size=(N, d1)).astype(np.int64) +weight = np.random.rand(C).astype(np.float32) + +negative_log_likelihood_loss = compute_negative_log_likelihood_loss(input, target, weight=weight, reduction=reduction) + +expect(node, inputs=[input, target, weight], outputs=[negative_log_likelihood_loss], + name='test_nllloss_NCd1_weight') +``` + +
+
+input_shape_is_NCd1_weight_ii + +```python +reduction = 'mean' +ignore_index = np.int64(1) +node = onnx.helper.make_node( + 'NegativeLogLikelihoodLoss', + inputs=['input', 'target', 'weight'], + outputs=['loss'], + reduction=reduction, + ignore_index=ignore_index +) + +N, C, d1 = 3, 5, 2 +np.random.seed(0) +input = np.random.rand(N, C, d1).astype(np.float32) +target = np.random.randint(0, high=C, size=(N, d1)).astype(np.int64) +target[0][0] = np.int64(1) +weight = np.random.rand(C).astype(np.float32) + +negative_log_likelihood_loss = compute_negative_log_likelihood_loss(input, target, weight=weight, reduction=reduction, ignore_index=ignore_index) + +expect(node, inputs=[input, target, weight], outputs=[negative_log_likelihood_loss], + name='test_nllloss_NCd1_weight_ii') +``` + +
+
+input_shape_is_NCd1d2 + +```python +reduction = 'none' +node = onnx.helper.make_node( + 'NegativeLogLikelihoodLoss', + inputs=['input', 'target'], + outputs=['loss'], + reduction=reduction +) + +N, C, dim1, dim2 = 3, 5, 6, 6 +np.random.seed(0) +input = np.random.rand(N, C, dim1, dim2).astype(np.float32) +target = np.random.randint(0, high=C, size=(N, dim1, dim2)).astype(np.int64) + +negative_log_likelihood_loss = compute_negative_log_likelihood_loss(input, target, weight=None, reduction=reduction) + +expect(node, inputs=[input, target], outputs=[negative_log_likelihood_loss], + name='test_nllloss_NCd1d2') +``` + +
+
+input_shape_is_NCd1d2_no_weight_reduction_mean_ii + +```python +reduction = 'mean' +ignore_index = np.int64(1) +node = onnx.helper.make_node( + 'NegativeLogLikelihoodLoss', + inputs=['input', 'target'], + outputs=['loss'], + reduction=reduction, + ignore_index=ignore_index +) + +N, C, dim1, dim2 = 3, 5, 6, 6 +np.random.seed(0) +input = np.random.rand(N, C, dim1, dim2).astype(np.float32) +target = np.random.randint(0, high=C, size=(N, dim1, dim2)).astype(np.int64) +target[0][0][0] = np.int64(1) + +negative_log_likelihood_loss = compute_negative_log_likelihood_loss(input, target, reduction=reduction, ignore_index=ignore_index) + +expect(node, inputs=[input, target], outputs=[negative_log_likelihood_loss], + name='test_nllloss_NCd1d2_no_weight_reduction_mean_ii') +``` + +
+
+input_shape_is_NCd1d2_reduction_mean + +```python +reduction = 'mean' +node = onnx.helper.make_node( + 'NegativeLogLikelihoodLoss', + inputs=['input', 'target'], + outputs=['loss'], + reduction=reduction +) + +N, C, dim1, dim2 = 3, 5, 6, 6 +np.random.seed(0) +input = np.random.rand(N, C, dim1, dim2).astype(np.float32) +target = np.random.randint(0, high=C, size=(N, dim1, dim2)).astype(np.int64) + +negative_log_likelihood_loss = compute_negative_log_likelihood_loss(input, target, weight=None, reduction=reduction) + +expect(node, inputs=[input, target], outputs=[negative_log_likelihood_loss], + name='test_nllloss_NCd1d2_reduction_mean') +``` + +
+
+input_shape_is_NCd1d2_reduction_sum + +```python +reduction = 'sum' +node = onnx.helper.make_node( + 'NegativeLogLikelihoodLoss', + inputs=['input', 'target'], + outputs=['loss'], + reduction=reduction +) + +N, C, dim1, dim2 = 3, 5, 6, 6 +np.random.seed(0) +input = np.random.rand(N, C, dim1, dim2).astype(np.float32) +target = np.random.randint(0, high=C, size=(N, dim1, dim2)) + +negative_log_likelihood_loss = compute_negative_log_likelihood_loss(input, target, weight=None, reduction=reduction) + +expect(node, inputs=[input, target], outputs=[negative_log_likelihood_loss], + name='test_nllloss_NCd1d2_reduction_sum') +``` + +
+
+input_shape_is_NCd1d2_with_weight + +```python +reduction = 'none' +node = onnx.helper.make_node( + 'NegativeLogLikelihoodLoss', + inputs=['input', 'target', 'weight'], + outputs=['loss'], + reduction=reduction +) + +N, C, dim1, dim2 = 3, 5, 6, 6 +np.random.seed(0) +input = np.random.rand(N, C, dim1, dim2).astype(np.float32) +target = np.random.randint(0, high=C, size=(N, dim1, dim2)).astype(np.int64) +weight = np.random.rand(C).astype(np.float32) + +negative_log_likelihood_loss = compute_negative_log_likelihood_loss(input, target, weight=weight, reduction=reduction) + +expect(node, inputs=[input, target, weight], outputs=[negative_log_likelihood_loss], + name='test_nllloss_NCd1d2_with_weight') +``` + +
+
+input_shape_is_NCd1d2_with_weight_reduction_mean + +```python +reduction = 'mean' +node = onnx.helper.make_node( + 'NegativeLogLikelihoodLoss', + inputs=['input', 'target', 'weight'], + outputs=['loss'], + reduction=reduction +) + +N, C, dim1, dim2 = 3, 5, 6, 6 +np.random.seed(0) +input = np.random.rand(N, C, dim1, dim2).astype(np.float32) +target = np.random.randint(0, high=C, size=(N, dim1, dim2)).astype(np.int64) +weight = np.random.rand(C).astype(np.float32) + +negative_log_likelihood_loss = compute_negative_log_likelihood_loss(input, target, weight=weight, reduction=reduction) + +expect(node, inputs=[input, target, weight], outputs=[negative_log_likelihood_loss], + name='test_nllloss_NCd1d2_with_weight_reduction_mean') +``` + +
+
+input_shape_is_NCd1d2_with_weight_reduction_sum + +```python +reduction = 'sum' +node = onnx.helper.make_node( + 'NegativeLogLikelihoodLoss', + inputs=['input', 'target', 'weight'], + outputs=['loss'], + reduction=reduction +) + +N, C, dim1, dim2 = 3, 5, 6, 6 +np.random.seed(0) +input = np.random.rand(N, C, dim1, dim2).astype(np.float32) +target = np.random.randint(0, high=C, size=(N, dim1, dim2)).astype(np.int64) +weight = np.random.rand(C).astype(np.float32) + +negative_log_likelihood_loss = compute_negative_log_likelihood_loss(input, target, weight=weight, reduction=reduction) + +expect(node, inputs=[input, target, weight], outputs=[negative_log_likelihood_loss], + name='test_nllloss_NCd1d2_with_weight_reduction_sum') +``` + +
+
+input_shape_is_NCd1d2_with_weight_reduction_sum_ii + +```python +reduction = 'sum' +ignore_index = np.int64(0) +node = onnx.helper.make_node( + 'NegativeLogLikelihoodLoss', + inputs=['input', 'target', 'weight'], + outputs=['loss'], + reduction=reduction, + ignore_index=ignore_index +) + +N, C, dim1, dim2 = 3, 5, 6, 6 +np.random.seed(0) +input = np.random.rand(N, C, dim1, dim2).astype(np.float32) +target = np.random.randint(0, high=C, size=(N, dim1, dim2)).astype(np.int64) +target[0][0][0] = np.int64(0) +weight = np.random.rand(C).astype(np.float32) + +negative_log_likelihood_loss = compute_negative_log_likelihood_loss(input, target, weight=weight, reduction=reduction, ignore_index=ignore_index) + +expect(node, inputs=[input, target, weight], outputs=[negative_log_likelihood_loss], + name='test_nllloss_NCd1d2_with_weight_reduction_sum_ii') +``` + +
+
+input_shape_is_NCd1d2d3_none_no_weight_negative_ii + +```python +reduction = 'none' +ignore_index = np.int64(-5) + +node = onnx.helper.make_node( + 'NegativeLogLikelihoodLoss', + inputs=['input', 'target'], + outputs=['loss'], + reduction=reduction, + ignore_index=ignore_index) + +N, C, dim1, dim2, dim3 = 3, 5, 6, 6, 5 +np.random.seed(0) +input = np.random.rand(N, C, dim1, dim2, dim3).astype(np.float32) +target = np.random.randint(0, high=C, size=(N, dim1, dim2, dim3)).astype(np.int64) +target[0][0][0][0] = -5 + +negative_log_likelihood_loss = compute_negative_log_likelihood_loss(input, + target, + reduction=reduction, + ignore_index=ignore_index) + +expect(node, inputs=[input, target], outputs=[negative_log_likelihood_loss], + name='test_nllloss_NCd1d2d3_none_no_weight_negative_ii') +``` + +
+
+input_shape_is_NCd1d2d3_sum_weight_high_ii + +```python +reduction = 'sum' +ignore_index = np.int64(10) + +node = onnx.helper.make_node( + 'NegativeLogLikelihoodLoss', + inputs=['input', 'target', 'weight'], + outputs=['loss'], + reduction=reduction, + ignore_index=ignore_index) + +N, C = 3, 5 +np.random.seed(0) +input = np.random.rand(N, C).astype(np.float32) +target = np.random.randint(0, high=C, size=(N)) +target[0] = 10 +weight = np.random.rand(C).astype(np.float32) + +negative_log_likelihood_loss = compute_negative_log_likelihood_loss(input, + target, + weight=weight, + reduction=reduction, + ignore_index=ignore_index) + +expect(node, inputs=[input, target, weight], outputs=[negative_log_likelihood_loss], + name='test_nllloss_NCd1d2d3_sum_weight_high_ii') +``` + +
+
+input_shape_is_NCd1d2d3d4d5_mean_weight + +```python +reduction = 'mean' + +node = onnx.helper.make_node( + 'NegativeLogLikelihoodLoss', + inputs=['input', 'target', 'weight'], + outputs=['loss'], + reduction=reduction) + +N, C, dim1, dim2, dim3, dim4, dim5 = 3, 5, 6, 6, 5, 3, 4 +np.random.seed(0) +input = np.random.rand(N, C, dim1, dim2, dim3, dim4, dim5).astype(np.float32) +target = np.random.randint(0, high=C, size=(N, dim1, dim2, dim3, dim4, dim5)).astype(np.int64) +weight = np.random.rand(C).astype(np.float32) + +negative_log_likelihood_loss = compute_negative_log_likelihood_loss(input, + target, + weight=weight, + reduction=reduction) + +expect(node, inputs=[input, target, weight], outputs=[negative_log_likelihood_loss], + name='test_nllloss_NCd1d2d3d4d5_mean_weight') +``` + +
+
+input_shape_is_NCd1d2d3d4d5_none_no_weight + +```python +reduction = 'none' + +node = onnx.helper.make_node( + 'NegativeLogLikelihoodLoss', + inputs=['input', 'target'], + outputs=['loss'], + reduction=reduction) + +N, C, dim1, dim2, dim3, dim4, dim5 = 3, 5, 6, 6, 5, 3, 4 +np.random.seed(0) +input = np.random.rand(N, C, dim1, dim2, dim3, dim4, dim5).astype(np.float32) +target = np.random.randint(0, high=C, size=(N, dim1, dim2, dim3, dim4, dim5)).astype(np.int64) + +negative_log_likelihood_loss = compute_negative_log_likelihood_loss(input, + target, + reduction=reduction) + +expect(node, inputs=[input, target], outputs=[negative_log_likelihood_loss], + name='test_nllloss_NCd1d2d3d4d5_none_no_weight') +``` + +
+ + +### NonMaxSuppression +There are 9 test cases, listed as following: +
+nonmaxsuppression_center_point_box_format + +```python +node = onnx.helper.make_node( + 'NonMaxSuppression', + inputs=['boxes', 'scores', 'max_output_boxes_per_class', 'iou_threshold', 'score_threshold'], + outputs=['selected_indices'], + center_point_box=1 +) +boxes = np.array([[ + [0.5, 0.5, 1.0, 1.0], + [0.5, 0.6, 1.0, 1.0], + [0.5, 0.4, 1.0, 1.0], + [0.5, 10.5, 1.0, 1.0], + [0.5, 10.6, 1.0, 1.0], + [0.5, 100.5, 1.0, 1.0] +]]).astype(np.float32) +scores = np.array([[[0.9, 0.75, 0.6, 0.95, 0.5, 0.3]]]).astype(np.float32) +max_output_boxes_per_class = np.array([3]).astype(np.int64) +iou_threshold = np.array([0.5]).astype(np.float32) +score_threshold = np.array([0.0]).astype(np.float32) +selected_indices = np.array([[0, 0, 3], [0, 0, 0], [0, 0, 5]]).astype(np.int64) + +expect(node, inputs=[boxes, scores, max_output_boxes_per_class, iou_threshold, score_threshold], outputs=[selected_indices], name='test_nonmaxsuppression_center_point_box_format') +``` + +
+
+nonmaxsuppression_flipped_coordinates + +```python +node = onnx.helper.make_node( + 'NonMaxSuppression', + inputs=['boxes', 'scores', 'max_output_boxes_per_class', 'iou_threshold', 'score_threshold'], + outputs=['selected_indices'] +) +boxes = np.array([[ + [1.0, 1.0, 0.0, 0.0], + [0.0, 0.1, 1.0, 1.1], + [0.0, 0.9, 1.0, -0.1], + [0.0, 10.0, 1.0, 11.0], + [1.0, 10.1, 0.0, 11.1], + [1.0, 101.0, 0.0, 100.0] +]]).astype(np.float32) +scores = np.array([[[0.9, 0.75, 0.6, 0.95, 0.5, 0.3]]]).astype(np.float32) +max_output_boxes_per_class = np.array([3]).astype(np.int64) +iou_threshold = np.array([0.5]).astype(np.float32) +score_threshold = np.array([0.0]).astype(np.float32) +selected_indices = np.array([[0, 0, 3], [0, 0, 0], [0, 0, 5]]).astype(np.int64) + +expect(node, inputs=[boxes, scores, max_output_boxes_per_class, iou_threshold, score_threshold], outputs=[selected_indices], name='test_nonmaxsuppression_flipped_coordinates') +``` + +
+
+nonmaxsuppression_identical_boxes + +```python +node = onnx.helper.make_node( + 'NonMaxSuppression', + inputs=['boxes', 'scores', 'max_output_boxes_per_class', 'iou_threshold', 'score_threshold'], + outputs=['selected_indices'] +) +boxes = np.array([[ + [0.0, 0.0, 1.0, 1.0], + [0.0, 0.0, 1.0, 1.0], + [0.0, 0.0, 1.0, 1.0], + [0.0, 0.0, 1.0, 1.0], + [0.0, 0.0, 1.0, 1.0], + + [0.0, 0.0, 1.0, 1.0], + [0.0, 0.0, 1.0, 1.0], + [0.0, 0.0, 1.0, 1.0], + [0.0, 0.0, 1.0, 1.0], + [0.0, 0.0, 1.0, 1.0] +]]).astype(np.float32) +scores = np.array([[[0.9, 0.9, 0.9, 0.9, 0.9, 0.9, 0.9, 0.9, 0.9, 0.9]]]).astype(np.float32) +max_output_boxes_per_class = np.array([3]).astype(np.int64) +iou_threshold = np.array([0.5]).astype(np.float32) +score_threshold = np.array([0.0]).astype(np.float32) +selected_indices = np.array([[0, 0, 0]]).astype(np.int64) + +expect(node, inputs=[boxes, scores, max_output_boxes_per_class, iou_threshold, score_threshold], outputs=[selected_indices], name='test_nonmaxsuppression_identical_boxes') +``` + +
+
+nonmaxsuppression_limit_output_size + +```python +node = onnx.helper.make_node( + 'NonMaxSuppression', + inputs=['boxes', 'scores', 'max_output_boxes_per_class', 'iou_threshold', 'score_threshold'], + outputs=['selected_indices'] +) +boxes = np.array([[ + [0.0, 0.0, 1.0, 1.0], + [0.0, 0.1, 1.0, 1.1], + [0.0, -0.1, 1.0, 0.9], + [0.0, 10.0, 1.0, 11.0], + [0.0, 10.1, 1.0, 11.1], + [0.0, 100.0, 1.0, 101.0] +]]).astype(np.float32) +scores = np.array([[[0.9, 0.75, 0.6, 0.95, 0.5, 0.3]]]).astype(np.float32) +max_output_boxes_per_class = np.array([2]).astype(np.int64) +iou_threshold = np.array([0.5]).astype(np.float32) +score_threshold = np.array([0.0]).astype(np.float32) +selected_indices = np.array([[0, 0, 3], [0, 0, 0]]).astype(np.int64) + +expect(node, inputs=[boxes, scores, max_output_boxes_per_class, iou_threshold, score_threshold], outputs=[selected_indices], name='test_nonmaxsuppression_limit_output_size') +``` + +
+
+nonmaxsuppression_single_box + +```python +node = onnx.helper.make_node( + 'NonMaxSuppression', + inputs=['boxes', 'scores', 'max_output_boxes_per_class', 'iou_threshold', 'score_threshold'], + outputs=['selected_indices'] +) +boxes = np.array([[ + [0.0, 0.0, 1.0, 1.0] +]]).astype(np.float32) +scores = np.array([[[0.9]]]).astype(np.float32) +max_output_boxes_per_class = np.array([3]).astype(np.int64) +iou_threshold = np.array([0.5]).astype(np.float32) +score_threshold = np.array([0.0]).astype(np.float32) +selected_indices = np.array([[0, 0, 0]]).astype(np.int64) + +expect(node, inputs=[boxes, scores, max_output_boxes_per_class, iou_threshold, score_threshold], outputs=[selected_indices], name='test_nonmaxsuppression_single_box') +``` + +
+
+nonmaxsuppression_suppress_by_IOU + +```python +node = onnx.helper.make_node( + 'NonMaxSuppression', + inputs=['boxes', 'scores', 'max_output_boxes_per_class', 'iou_threshold', 'score_threshold'], + outputs=['selected_indices'] +) +boxes = np.array([[ + [0.0, 0.0, 1.0, 1.0], + [0.0, 0.1, 1.0, 1.1], + [0.0, -0.1, 1.0, 0.9], + [0.0, 10.0, 1.0, 11.0], + [0.0, 10.1, 1.0, 11.1], + [0.0, 100.0, 1.0, 101.0] +]]).astype(np.float32) +scores = np.array([[[0.9, 0.75, 0.6, 0.95, 0.5, 0.3]]]).astype(np.float32) +max_output_boxes_per_class = np.array([3]).astype(np.int64) +iou_threshold = np.array([0.5]).astype(np.float32) +score_threshold = np.array([0.0]).astype(np.float32) +selected_indices = np.array([[0, 0, 3], [0, 0, 0], [0, 0, 5]]).astype(np.int64) + +expect(node, inputs=[boxes, scores, max_output_boxes_per_class, iou_threshold, score_threshold], outputs=[selected_indices], name='test_nonmaxsuppression_suppress_by_IOU') +``` + +
+
+nonmaxsuppression_suppress_by_IOU_and_scores + +```python +node = onnx.helper.make_node( + 'NonMaxSuppression', + inputs=['boxes', 'scores', 'max_output_boxes_per_class', 'iou_threshold', 'score_threshold'], + outputs=['selected_indices'] +) +boxes = np.array([[ + [0.0, 0.0, 1.0, 1.0], + [0.0, 0.1, 1.0, 1.1], + [0.0, -0.1, 1.0, 0.9], + [0.0, 10.0, 1.0, 11.0], + [0.0, 10.1, 1.0, 11.1], + [0.0, 100.0, 1.0, 101.0] +]]).astype(np.float32) +scores = np.array([[[0.9, 0.75, 0.6, 0.95, 0.5, 0.3]]]).astype(np.float32) +max_output_boxes_per_class = np.array([3]).astype(np.int64) +iou_threshold = np.array([0.5]).astype(np.float32) +score_threshold = np.array([0.4]).astype(np.float32) +selected_indices = np.array([[0, 0, 3], [0, 0, 0]]).astype(np.int64) + +expect(node, inputs=[boxes, scores, max_output_boxes_per_class, iou_threshold, score_threshold], outputs=[selected_indices], name='test_nonmaxsuppression_suppress_by_IOU_and_scores') +``` + +
+
+nonmaxsuppression_two_batches + +```python +node = onnx.helper.make_node( + 'NonMaxSuppression', + inputs=['boxes', 'scores', 'max_output_boxes_per_class', 'iou_threshold', 'score_threshold'], + outputs=['selected_indices'] +) +boxes = np.array([[[0.0, 0.0, 1.0, 1.0], + [0.0, 0.1, 1.0, 1.1], + [0.0, -0.1, 1.0, 0.9], + [0.0, 10.0, 1.0, 11.0], + [0.0, 10.1, 1.0, 11.1], + [0.0, 100.0, 1.0, 101.0]], + [[0.0, 0.0, 1.0, 1.0], + [0.0, 0.1, 1.0, 1.1], + [0.0, -0.1, 1.0, 0.9], + [0.0, 10.0, 1.0, 11.0], + [0.0, 10.1, 1.0, 11.1], + [0.0, 100.0, 1.0, 101.0]]]).astype(np.float32) +scores = np.array([[[0.9, 0.75, 0.6, 0.95, 0.5, 0.3]], + [[0.9, 0.75, 0.6, 0.95, 0.5, 0.3]]]).astype(np.float32) +max_output_boxes_per_class = np.array([2]).astype(np.int64) +iou_threshold = np.array([0.5]).astype(np.float32) +score_threshold = np.array([0.0]).astype(np.float32) +selected_indices = np.array([[0, 0, 3], [0, 0, 0], [1, 0, 3], [1, 0, 0]]).astype(np.int64) + +expect(node, inputs=[boxes, scores, max_output_boxes_per_class, iou_threshold, score_threshold], outputs=[selected_indices], name='test_nonmaxsuppression_two_batches') +``` + +
+
+nonmaxsuppression_two_classes + +```python +node = onnx.helper.make_node( + 'NonMaxSuppression', + inputs=['boxes', 'scores', 'max_output_boxes_per_class', 'iou_threshold', 'score_threshold'], + outputs=['selected_indices'] +) +boxes = np.array([[ + [0.0, 0.0, 1.0, 1.0], + [0.0, 0.1, 1.0, 1.1], + [0.0, -0.1, 1.0, 0.9], + [0.0, 10.0, 1.0, 11.0], + [0.0, 10.1, 1.0, 11.1], + [0.0, 100.0, 1.0, 101.0] +]]).astype(np.float32) +scores = np.array([[[0.9, 0.75, 0.6, 0.95, 0.5, 0.3], + [0.9, 0.75, 0.6, 0.95, 0.5, 0.3]]]).astype(np.float32) +max_output_boxes_per_class = np.array([2]).astype(np.int64) +iou_threshold = np.array([0.5]).astype(np.float32) +score_threshold = np.array([0.0]).astype(np.float32) +selected_indices = np.array([[0, 0, 3], [0, 0, 0], [0, 1, 3], [0, 1, 0]]).astype(np.int64) + +expect(node, inputs=[boxes, scores, max_output_boxes_per_class, iou_threshold, score_threshold], outputs=[selected_indices], name='test_nonmaxsuppression_two_classes') +``` + +
+ + +### NonZero +There are 1 test cases, listed as following: +
+nonzero + +```python +node = onnx.helper.make_node( + 'NonZero', + inputs=['condition'], + outputs=['result'], +) + +condition = np.array([[1, 0], [1, 1]], dtype=bool) +result = np.array(np.nonzero(condition), dtype=np.int64) # expected output [[0, 1, 1], [0, 0, 1]] +expect(node, inputs=[condition], outputs=[result], + name='test_nonzero_example') +``` + +
+ + +### Not +There are 1 test cases, listed as following: +
+not + +```python +node = onnx.helper.make_node( + 'Not', + inputs=['x'], + outputs=['not'], +) + +# 2d +x = (np.random.randn(3, 4) > 0).astype(bool) +expect(node, inputs=[x], outputs=[np.logical_not(x)], + name='test_not_2d') + +# 3d +x = (np.random.randn(3, 4, 5) > 0).astype(bool) +expect(node, inputs=[x], outputs=[np.logical_not(x)], + name='test_not_3d') + +# 4d +x = (np.random.randn(3, 4, 5, 6) > 0).astype(bool) +expect(node, inputs=[x], outputs=[np.logical_not(x)], + name='test_not_4d') +``` + +
+ + +### OneHot +There are 4 test cases, listed as following: +
+with_axis + +```python +axisValue = 1 +on_value = 3 +off_value = 1 +output_type = np.float32 +node = onnx.helper.make_node( + 'OneHot', + inputs=['indices', 'depth', 'values'], + outputs=['y'], + axis=axisValue +) +indices = np.array([[1, 9], + [2, 4]], dtype=np.float32) +depth = np.float32(10) +values = np.array([off_value, on_value], dtype=output_type) +y = one_hot(indices, depth, axis=axisValue, dtype=output_type) +y = y * (on_value - off_value) + off_value +expect(node, inputs=[indices, depth, values], outputs=[y], name='test_onehot_with_axis') +``` + +
+
+with_negative_axis + +```python +axisValue = -2 +on_value = 3 +off_value = 1 +output_type = np.float32 +node = onnx.helper.make_node( + 'OneHot', + inputs=['indices', 'depth', 'values'], + outputs=['y'], + axis=axisValue +) +indices = np.array([[1, 9], + [2, 4]], dtype=np.float32) +depth = np.float32(10) +values = np.array([off_value, on_value], dtype=output_type) +y = one_hot(indices, depth, axis=axisValue, dtype=output_type) +y = y * (on_value - off_value) + off_value +expect(node, inputs=[indices, depth, values], outputs=[y], name='test_onehot_with_negative_axis') +``` + +
+
+with_negative_indices + +```python +axisValue = 1 +on_value = 3 +off_value = 1 +output_type = np.float32 +node = onnx.helper.make_node( + 'OneHot', + inputs=['indices', 'depth', 'values'], + outputs=['y'], + axis=axisValue +) +indices = np.array([0, -7, -8], dtype=np.int64) + +# print(y) +# [[3. 1. 1. 1. 1. 1. 1. 1. 1. 1.] +# [1. 1. 1. 3. 1. 1. 1. 1. 1. 1.] +# [1. 1. 3. 1. 1. 1. 1. 1. 1. 1.]] + +depth = np.float32(10) +values = np.array([off_value, on_value], dtype=output_type) +y = one_hot(indices, depth, axis=axisValue, dtype=output_type) +y = y * (on_value - off_value) + off_value +expect(node, inputs=[indices, depth, values], outputs=[y], name='test_onehot_negative_indices') +``` + +
+
+without_axis + +```python +on_value = 5 +off_value = 2 +output_type = np.int32 +node = onnx.helper.make_node( + 'OneHot', + inputs=['indices', 'depth', 'values'], + outputs=['y'] +) +indices = np.array([0, 7, 8], dtype=np.int64) +depth = np.float32(12) +values = np.array([off_value, on_value], dtype=output_type) +y = one_hot(indices, depth, dtype=output_type) +y = y * (on_value - off_value) + off_value +expect(node, inputs=[indices, depth, values], outputs=[y], name='test_onehot_without_axis') +``` + +
+ + +### OptionalHasElement +There are 4 test cases, listed as following: +
+empty + +```python +optional = None +tensor_type_proto = onnx.helper.make_tensor_type_proto(elem_type=onnx.TensorProto.INT32, shape=[]) +input_type_proto = onnx.helper.make_optional_type_proto(tensor_type_proto) +node = onnx.helper.make_node( + 'OptionalHasElement', + inputs=['optional_input'], + outputs=['output'] +) +output = optional_has_element_reference_implementation(optional) +expect(node, inputs=[optional], outputs=[output], + input_type_protos=[input_type_proto], + name='test_optional_has_element_empty') +``` + +
+
+get_element_sequence + +```python +optional = [np.array([1, 2, 3, 4]).astype(np.int32)] +tensor_type_proto = onnx.helper.make_tensor_type_proto(elem_type=onnx.TensorProto.INT32, shape=[4, ]) +seq_type_proto = onnx.helper.make_sequence_type_proto(tensor_type_proto) +input_type_proto = onnx.helper.make_optional_type_proto(seq_type_proto) + +node = onnx.helper.make_node( + 'OptionalGetElement', + inputs=['optional_input'], + outputs=['output'] +) +output = optional_get_element_reference_implementation(optional) +expect(node, inputs=[optional], outputs=[output], + input_type_protos=[input_type_proto], + name='test_optional_get_element_sequence') +``` + +
+
+get_element_tensor + +```python +optional = np.array([1, 2, 3, 4]).astype(np.float32) +tensor_type_proto = onnx.helper.make_tensor_type_proto(elem_type=onnx.TensorProto.FLOAT, shape=[4, ]) +input_type_proto = onnx.helper.make_optional_type_proto(tensor_type_proto) + +node = onnx.helper.make_node( + 'OptionalGetElement', + inputs=['optional_input'], + outputs=['output'] +) +output = optional_get_element_reference_implementation(optional) +expect(node, inputs=[optional], outputs=[output], + input_type_protos=[input_type_proto], + name='test_optional_get_element') +``` + +
+
+optionalhaselement + +```python +optional = np.array([1, 2, 3, 4]).astype(np.float32) +tensor_type_proto = onnx.helper.make_tensor_type_proto(elem_type=onnx.TensorProto.FLOAT, shape=[4, ]) +input_type_proto = onnx.helper.make_optional_type_proto(tensor_type_proto) +node = onnx.helper.make_node( + 'OptionalHasElement', + inputs=['optional_input'], + outputs=['output'] +) +output = optional_has_element_reference_implementation(optional) +expect(node, inputs=[optional], outputs=[output], + input_type_protos=[input_type_proto], + name='test_optional_has_element') +``` + +
+ + +### Or +There are 2 test cases, listed as following: +
+or + +```python +node = onnx.helper.make_node( + 'Or', + inputs=['x', 'y'], + outputs=['or'], +) + +# 2d +x = (np.random.randn(3, 4) > 0).astype(bool) +y = (np.random.randn(3, 4) > 0).astype(bool) +z = np.logical_or(x, y) +expect(node, inputs=[x, y], outputs=[z], + name='test_or2d') + +# 3d +x = (np.random.randn(3, 4, 5) > 0).astype(bool) +y = (np.random.randn(3, 4, 5) > 0).astype(bool) +z = np.logical_or(x, y) +expect(node, inputs=[x, y], outputs=[z], + name='test_or3d') + +# 4d +x = (np.random.randn(3, 4, 5, 6) > 0).astype(bool) +y = (np.random.randn(3, 4, 5, 6) > 0).astype(bool) +z = np.logical_or(x, y) +expect(node, inputs=[x, y], outputs=[z], + name='test_or4d') +``` + +
+
+or_broadcast + +```python +node = onnx.helper.make_node( + 'Or', + inputs=['x', 'y'], + outputs=['or'], +) + +# 3d vs 1d +x = (np.random.randn(3, 4, 5) > 0).astype(bool) +y = (np.random.randn(5) > 0).astype(bool) +z = np.logical_or(x, y) +expect(node, inputs=[x, y], outputs=[z], + name='test_or_bcast3v1d') + +# 3d vs 2d +x = (np.random.randn(3, 4, 5) > 0).astype(bool) +y = (np.random.randn(4, 5) > 0).astype(bool) +z = np.logical_or(x, y) +expect(node, inputs=[x, y], outputs=[z], + name='test_or_bcast3v2d') + +# 4d vs 2d +x = (np.random.randn(3, 4, 5, 6) > 0).astype(bool) +y = (np.random.randn(5, 6) > 0).astype(bool) +z = np.logical_or(x, y) +expect(node, inputs=[x, y], outputs=[z], + name='test_or_bcast4v2d') + +# 4d vs 3d +x = (np.random.randn(3, 4, 5, 6) > 0).astype(bool) +y = (np.random.randn(4, 5, 6) > 0).astype(bool) +z = np.logical_or(x, y) +expect(node, inputs=[x, y], outputs=[z], + name='test_or_bcast4v3d') + +# 4d vs 4d +x = (np.random.randn(1, 4, 1, 6) > 0).astype(bool) +y = (np.random.randn(3, 1, 5, 6) > 0).astype(bool) +z = np.logical_or(x, y) +expect(node, inputs=[x, y], outputs=[z], + name='test_or_bcast4v4d') +``` + +
+ + +### PRelu +There are 2 test cases, listed as following: +
+prelu + +```python +node = onnx.helper.make_node( + 'PRelu', + inputs=['x', 'slope'], + outputs=['y'], +) + +x = np.random.randn(3, 4, 5).astype(np.float32) +slope = np.random.randn(3, 4, 5).astype(np.float32) +y = np.clip(x, 0, np.inf) + np.clip(x, -np.inf, 0) * slope + +expect(node, inputs=[x, slope], outputs=[y], + name='test_prelu_example') +``` + +
+
+prelu_broadcast + +```python +node = onnx.helper.make_node( + 'PRelu', + inputs=['x', 'slope'], + outputs=['y'], +) + +x = np.random.randn(3, 4, 5).astype(np.float32) +slope = np.random.randn(5).astype(np.float32) +y = np.clip(x, 0, np.inf) + np.clip(x, -np.inf, 0) * slope + +expect(node, inputs=[x, slope], outputs=[y], + name='test_prelu_broadcast') +``` + +
+ + +### Pad +There are 2 test cases, listed as following: +
+constant_pad + +```python +node = onnx.helper.make_node( + 'Pad', + inputs=['x', 'pads', 'value'], + outputs=['y'], + mode='constant' +) +x = np.random.randn(1, 3, 4, 5).astype(np.float32) +pads = np.array([0, 0, 1, 3, 0, 0, 2, 4]).astype(np.int64) # pad order [x1_begin, x2_begin, ..., x1_end, x2_end, ...] +value = np.float32(1.2) +y = pad_impl( + x, + pads, + 'constant', + 1.2 +) + +expect(node, inputs=[x, pads, value], outputs=[y], + name='test_constant_pad') +``` + +
+
+reflection_and_edge_pad + +```python +for mode in ['edge', 'reflect']: + node = onnx.helper.make_node( + 'Pad', + inputs=['x', 'pads'], + outputs=['y'], + mode=mode + ) + x = np.random.randn(1, 3, 4, 5).astype(np.int32) + pads = np.array([0, 0, 1, 1, 0, 0, 1, 1]).astype(np.int64) # pad order [x1_begin, x2_begin, ..., x1_end, x2_end, ...] + y = pad_impl( + x, + pads, + mode + ) + + expect(node, inputs=[x, pads], outputs=[y], + name='test_{}_pad'.format(mode)) +``` + +
+ + +### Pow +There are 3 test cases, listed as following: +
+pow + +```python +node = onnx.helper.make_node( + 'Pow', + inputs=['x', 'y'], + outputs=['z'], +) + +x = np.array([1, 2, 3]).astype(np.float32) +y = np.array([4, 5, 6]).astype(np.float32) +z = pow(x, y) # expected output [1., 32., 729.] +expect(node, inputs=[x, y], outputs=[z], + name='test_pow_example') + +x = np.arange(60).reshape(3, 4, 5).astype(np.float32) +y = np.random.randn(3, 4, 5).astype(np.float32) +z = pow(x, y) +expect(node, inputs=[x, y], outputs=[z], + name='test_pow') +``` + +
+
+pow_broadcast + +```python +node = onnx.helper.make_node( + 'Pow', + inputs=['x', 'y'], + outputs=['z'], +) + +x = np.array([1, 2, 3]).astype(np.float32) +y = np.array(2).astype(np.float32) +z = pow(x, y) # expected output [1., 4., 9.] +expect(node, inputs=[x, y], outputs=[z], + name='test_pow_bcast_scalar') + +node = onnx.helper.make_node( + 'Pow', + inputs=['x', 'y'], + outputs=['z'], +) +x = np.array([[1, 2, 3], [4, 5, 6]]).astype(np.float32) +y = np.array([1, 2, 3]).astype(np.float32) +# expected output [[1, 4, 27], [4, 25, 216]] +z = pow(x, y) +expect(node, inputs=[x, y], outputs=[z], + name='test_pow_bcast_array') +``` + +
+
+types + +```python +node = onnx.helper.make_node( + 'Pow', + inputs=['x', 'y'], + outputs=['z'], +) + +x = np.array([1, 2, 3]).astype(np.float32) +y = np.array([4, 5, 6]).astype(np.int64) +z = pow(x, y) # expected output [1., 32., 729.] +expect(node, inputs=[x, y], outputs=[z], + name='test_pow_types_float32_int64') + +x = np.array([1, 2, 3]).astype(np.int64) +y = np.array([4, 5, 6]).astype(np.float32) +z = pow(x, y) # expected output [1, 32, 729] +expect(node, inputs=[x, y], outputs=[z], + name='test_pow_types_int64_float32') + +x = np.array([1, 2, 3]).astype(np.float32) +y = np.array([4, 5, 6]).astype(np.int32) +z = pow(x, y) # expected output [1., 32., 729.] +expect(node, inputs=[x, y], outputs=[z], + name='test_pow_types_float32_int32') + +x = np.array([1, 2, 3]).astype(np.int32) +y = np.array([4, 5, 6]).astype(np.float32) +z = pow(x, y) # expected output [1, 32, 729] +expect(node, inputs=[x, y], outputs=[z], + name='test_pow_types_int32_float32') + +x = np.array([1, 2, 3]).astype(np.float32) +y = np.array([4, 5, 6]).astype(np.uint64) +z = pow(x, y) # expected output [1., 32., 729.] +expect(node, inputs=[x, y], outputs=[z], + name='test_pow_types_float32_uint64') + +x = np.array([1, 2, 3]).astype(np.float32) +y = np.array([4, 5, 6]).astype(np.uint32) +z = pow(x, y) # expected output [1., 32., 729.] +expect(node, inputs=[x, y], outputs=[z], + name='test_pow_types_float32_uint32') + +x = np.array([1, 2, 3]).astype(np.int64) +y = np.array([4, 5, 6]).astype(np.int64) +z = pow(x, y) # expected output [1, 32, 729] +expect(node, inputs=[x, y], outputs=[z], + name='test_pow_types_int64_int64') + +x = np.array([1, 2, 3]).astype(np.int32) +y = np.array([4, 5, 6]).astype(np.int32) +z = pow(x, y) # expected output [1, 32, 729] +expect(node, inputs=[x, y], outputs=[z], + name='test_pow_types_int32_int32') +``` + +
+ + +### QLinearConv +There are 1 test cases, listed as following: +
+qlinearconv + +```python +node = onnx.helper.make_node('QLinearConv', + inputs=['x', 'x_scale', 'x_zero_point', 'w', 'w_scale', 'w_zero_point', 'y_scale', 'y_zero_point'], + outputs=['y'],) + +x = np.array([[255, 174, 162, 25, 203, 168, 58], + [15, 59, 237, 95, 129, 0, 64], + [56, 242, 153, 221, 168, 12, 166], + [232, 178, 186, 195, 237, 162, 237], + [188, 39, 124, 77, 80, 102, 43], + [127, 230, 21, 83, 41, 40, 134], + [255, 154, 92, 141, 42, 148, 247], ], dtype=np.uint8).reshape((1, 1, 7, 7)) + +x_scale = np.float32(0.00369204697) +x_zero_point = np.uint8(132) + +w = np.array([0], dtype=np.uint8).reshape((1, 1, 1, 1)) + +w_scale = np.array([0.00172794575], dtype=np.float32) +w_zero_point = np.array([255], dtype=np.uint8) + +y_scale = np.float32(0.00162681262) +y_zero_point = np.uint8(123) + +output = np.array([[0, 81, 93, 230, 52, 87, 197], + [240, 196, 18, 160, 126, 255, 191], + [199, 13, 102, 34, 87, 243, 89], + [23, 77, 69, 60, 18, 93, 18], + [67, 216, 131, 178, 175, 153, 212], + [128, 25, 234, 172, 214, 215, 121], + [0, 101, 163, 114, 213, 107, 8], ], dtype=np.uint8).reshape((1, 1, 7, 7)) + +expect(node, inputs=[x, x_scale, x_zero_point, w, w_scale, w_zero_point, y_scale, y_zero_point], outputs=[output], + name='test_qlinearconv') +``` + +
+ + +### QLinearMatMul +There are 1 test cases, listed as following: +
+qlinearmatmul + +```python +node = onnx.helper.make_node('QLinearMatMul', + inputs=['a', 'a_scale', 'a_zero_point', 'b', 'b_scale', 'b_zero_point', 'y_scale', 'y_zero_point'], + outputs=['y'],) + +#2D +a = np.array([[208, 236, 0, 238], + [3, 214, 255, 29], ], dtype=np.uint8) + +a_scale = np.array([0.0066], dtype=np.float32) +a_zero_point = np.array([113], dtype=np.uint8) + +b = np.array([[152, 51, 244], + [60, 26, 255], + [0, 127, 246], + [127, 254, 247]], dtype=np.uint8) + +b_scale = np.array([0.00705], dtype=np.float32) +b_zero_point = np.array([114], dtype=np.uint8) + +y_scale = np.array([0.0107], dtype=np.float32) +y_zero_point = np.array([118], dtype=np.uint8) + +output = np.array([[168, 115, 255], + [1, 66, 151], ], dtype=np.uint8) + +expect(node, inputs=[a, a_scale, a_zero_point, b, b_scale, b_zero_point, y_scale, y_zero_point], outputs=[output], + name='test_qlinearmatmul_2D') + +#3D +a = np.array([[[208, 236, 0, 238], + [3, 214, 255, 29]], + [[208, 236, 0, 238], + [3, 214, 255, 29]]], dtype=np.uint8) + +a_scale = np.array([0.0066], dtype=np.float32) +a_zero_point = np.array([113], dtype=np.uint8) + +b = np.array([[[152, 51, 244], + [60, 26, 255], + [0, 127, 246], + [127, 254, 247]], + [[152, 51, 244], + [60, 26, 255], + [0, 127, 246], + [127, 254, 247]]], dtype=np.uint8) + +b_scale = np.array([0.00705], dtype=np.float32) +b_zero_point = np.array([114], dtype=np.uint8) + +y_scale = np.array([0.0107], dtype=np.float32) +y_zero_point = np.array([118], dtype=np.uint8) + +output = np.array([[[168, 115, 255], + [1, 66, 151]], + [[168, 115, 255], + [1, 66, 151]]], dtype=np.uint8) + +expect(node, inputs=[a, a_scale, a_zero_point, b, b_scale, b_zero_point, y_scale, y_zero_point], outputs=[output], + name='test_qlinearmatmul_3D') +``` + +
+ + +### QuantizeLinear +There are 2 test cases, listed as following: +
+axis + +```python +node = onnx.helper.make_node('QuantizeLinear', + inputs=['x', 'y_scale', 'y_zero_point'], + outputs=['y'],) + +x = np.array([[[[-162, 10], + [-100, 232], + [-20, -50]], + + [[-76, 0], + [0, 252], + [32, -44]], + + [[245, -485], + [-960, -270], + [-375, -470]], ], ], dtype=np.float32) +y_scale = np.array([2, 4, 5], dtype=np.float32) +y_zero_point = np.array([84, 24, 196], dtype=np.uint8) +y = (x / y_scale.reshape(1, 3, 1, 1) + y_zero_point.reshape(1, 3, 1, 1)).astype(np.uint8) + +expect(node, inputs=[x, y_scale, y_zero_point], outputs=[y], + name='test_quantizelinear_axis') +``` + +
+
+quantizelinear + +```python +node = onnx.helper.make_node('QuantizeLinear', + inputs=['x', 'y_scale', 'y_zero_point'], + outputs=['y'],) + +x = np.array([0, 2, 3, 1000, -254, -1000]).astype(np.float32) +y_scale = np.float32(2) +y_zero_point = np.uint8(128) +y = np.array([128, 129, 130, 255, 1, 0]).astype(np.uint8) + +expect(node, inputs=[x, y_scale, y_zero_point], outputs=[y], + name='test_quantizelinear') +``` + +
+ + +### RNN +There are 4 test cases, listed as following: +
+batchwise + +```python +input = np.array([[[1., 2.]], [[3., 4.]], [[5., 6.]]]).astype(np.float32) + +input_size = 2 +hidden_size = 4 +weight_scale = 0.5 +layout = 1 + +node = onnx.helper.make_node( + 'RNN', + inputs=['X', 'W', 'R'], + outputs=['Y', 'Y_h'], + hidden_size=hidden_size, + layout=layout +) + +W = weight_scale * np.ones((1, hidden_size, input_size)).astype(np.float32) +R = weight_scale * np.ones((1, hidden_size, hidden_size)).astype(np.float32) + +rnn = RNN_Helper(X=input, W=W, R=R, layout=layout) +Y, Y_h = rnn.step() +expect(node, inputs=[input, W, R], outputs=[Y.astype(np.float32), Y_h.astype(np.float32)], name='test_simple_rnn_batchwise') +``` + +
+
+defaults + +```python +input = np.array([[[1., 2.], [3., 4.], [5., 6.]]]).astype(np.float32) + +input_size = 2 +hidden_size = 4 +weight_scale = 0.1 + +node = onnx.helper.make_node( + 'RNN', + inputs=['X', 'W', 'R'], + outputs=['', 'Y_h'], + hidden_size=hidden_size +) + +W = weight_scale * np.ones((1, hidden_size, input_size)).astype(np.float32) +R = weight_scale * np.ones((1, hidden_size, hidden_size)).astype(np.float32) + +rnn = RNN_Helper(X=input, W=W, R=R) +_, Y_h = rnn.step() +expect(node, inputs=[input, W, R], outputs=[Y_h.astype(np.float32)], name='test_simple_rnn_defaults') +``` + +
+
+initial_bias + +```python +input = np.array([[[1., 2., 3.], [4., 5., 6.], [7., 8., 9.]]]).astype(np.float32) + +input_size = 3 +hidden_size = 5 +custom_bias = 0.1 +weight_scale = 0.1 + +node = onnx.helper.make_node( + 'RNN', + inputs=['X', 'W', 'R', 'B'], + outputs=['', 'Y_h'], + hidden_size=hidden_size +) + +W = weight_scale * np.ones((1, hidden_size, input_size)).astype(np.float32) +R = weight_scale * np.ones((1, hidden_size, hidden_size)).astype(np.float32) + +# Adding custom bias +W_B = custom_bias * np.ones((1, hidden_size)).astype(np.float32) +R_B = np.zeros((1, hidden_size)).astype(np.float32) +B = np.concatenate((W_B, R_B), axis=1) + +rnn = RNN_Helper(X=input, W=W, R=R, B=B) +_, Y_h = rnn.step() +expect(node, inputs=[input, W, R, B], outputs=[Y_h.astype(np.float32)], + name='test_simple_rnn_with_initial_bias') +``` + +
+
+seq_length + +```python +input = np.array([[[1., 2., 3.], [4., 5., 6.], [7., 8., 9.]], + [[10., 11., 12.], [13., 14., 15.], [16., 17., 18.]]]).astype(np.float32) + +input_size = 3 +hidden_size = 5 + +node = onnx.helper.make_node( + 'RNN', + inputs=['X', 'W', 'R', 'B'], + outputs=['', 'Y_h'], + hidden_size=hidden_size +) + +W = np.random.randn(1, hidden_size, input_size).astype(np.float32) +R = np.random.randn(1, hidden_size, hidden_size).astype(np.float32) + +# Adding custom bias +W_B = np.random.randn(1, hidden_size).astype(np.float32) +R_B = np.random.randn(1, hidden_size).astype(np.float32) +B = np.concatenate((W_B, R_B), axis=1) + +rnn = RNN_Helper(X=input, W=W, R=R, B=B) +_, Y_h = rnn.step() +expect(node, inputs=[input, W, R, B], outputs=[Y_h.astype(np.float32)], name='test_rnn_seq_length') +``` + +
+ + +### Range +There are 2 test cases, listed as following: +
+range_float_type_positive_delta + +```python +node = onnx.helper.make_node( + 'Range', + inputs=['start', 'limit', 'delta'], + outputs=['output'], +) + +start = np.float32(1) +limit = np.float32(5) +delta = np.float32(2) + +output = np.arange(start, limit, delta, dtype=np.float32) # expected output [1.0, 3.0] +expect(node, inputs=[start, limit, delta], outputs=[output], + name='test_range_float_type_positive_delta') +``` + +
+
+range_int32_type_negative_delta + +```python +node = onnx.helper.make_node( + 'Range', + inputs=['start', 'limit', 'delta'], + outputs=['output'], +) + +start = np.int32(10) +limit = np.int32(6) +delta = np.int32(-3) + +output = np.arange(start, limit, delta, dtype=np.int32) # expected output [10, 7] +expect(node, inputs=[start, limit, delta], outputs=[output], + name='test_range_int32_type_negative_delta') +``` + +
+ + +### Reciprocal +There are 1 test cases, listed as following: +
+reciprocal + +```python +node = onnx.helper.make_node( + 'Reciprocal', + inputs=['x'], + outputs=['y'], +) + +x = np.array([-4, 2]).astype(np.float32) +y = np.reciprocal(x) # expected output [-0.25, 0.5], +expect(node, inputs=[x], outputs=[y], + name='test_reciprocal_example') + +x = np.random.rand(3, 4, 5).astype(np.float32) + 0.5 +y = np.reciprocal(x) +expect(node, inputs=[x], outputs=[y], + name='test_reciprocal') +``` + +
+ + +### ReduceL1 +There are 4 test cases, listed as following: +
+default_axes_keepdims + +```python +shape = [3, 2, 2] +axes = None +keepdims = 1 + +node = onnx.helper.make_node( + 'ReduceL1', + inputs=['data'], + outputs=['reduced'], + keepdims=keepdims +) + +data = np.reshape(np.arange(1, np.prod(shape) + 1, dtype=np.float32), shape) +#print(data) +#[[[1., 2.], [3., 4.]], [[5., 6.], [7., 8.]], [[9., 10.], [11., 12.]]] + +reduced = np.sum(a=np.abs(data), axis=axes, keepdims=keepdims == 1) +#print(reduced) +#[[[78.]]] + +expect(node, inputs=[data], outputs=[reduced], + name='test_reduce_l1_default_axes_keepdims_example') + +np.random.seed(0) +data = np.random.uniform(-10, 10, shape).astype(np.float32) +reduced = np.sum(a=np.abs(data), axis=axes, keepdims=keepdims == 1) + +expect(node, inputs=[data], outputs=[reduced], + name='test_reduce_l1_default_axes_keepdims_random') +``` + +
+
+do_not_keepdims + +```python +shape = [3, 2, 2] +axes = [2] +keepdims = 0 + +node = onnx.helper.make_node( + 'ReduceL1', + inputs=['data'], + outputs=['reduced'], + axes=axes, + keepdims=keepdims +) + +data = np.reshape(np.arange(1, np.prod(shape) + 1, dtype=np.float32), shape) +#print(data) +#[[[1., 2.], [3., 4.]], [[5., 6.], [7., 8.]], [[9., 10.], [11., 12.]]] + +reduced = np.sum(a=np.abs(data), axis=tuple(axes), keepdims=keepdims == 1) +#print(reduced) +#[[3., 7.], [11., 15.], [19., 23.]] + +expect(node, inputs=[data], outputs=[reduced], + name='test_reduce_l1_do_not_keepdims_example') + +np.random.seed(0) +data = np.random.uniform(-10, 10, shape).astype(np.float32) +reduced = np.sum(a=np.abs(data), axis=tuple(axes), keepdims=keepdims == 1) + +expect(node, inputs=[data], outputs=[reduced], + name='test_reduce_l1_do_not_keepdims_random') +``` + +
+
+keepdims + +```python +shape = [3, 2, 2] +axes = [2] +keepdims = 1 + +node = onnx.helper.make_node( + 'ReduceL1', + inputs=['data'], + outputs=['reduced'], + axes=axes, + keepdims=keepdims +) + +data = np.reshape(np.arange(1, np.prod(shape) + 1, dtype=np.float32), shape) +#print(data) +#[[[1., 2.], [3., 4.]], [[5., 6.], [7., 8.]], [[9., 10.], [11., 12.]]] + +reduced = np.sum(a=np.abs(data), axis=tuple(axes), keepdims=keepdims == 1) +#print(reduced) +#[[[3.], [7.]], [[11.], [15.]], [[19.], [23.]]] + +expect(node, inputs=[data], outputs=[reduced], + name='test_reduce_l1_keep_dims_example') + +np.random.seed(0) +data = np.random.uniform(-10, 10, shape).astype(np.float32) +reduced = np.sum(a=np.abs(data), axis=tuple(axes), keepdims=keepdims == 1) + +expect(node, inputs=[data], outputs=[reduced], + name='test_reduce_l1_keep_dims_random') +``` + +
+
+negative_axes_keepdims + +```python +shape = [3, 2, 2] +axes = [-1] +keepdims = 1 + +node = onnx.helper.make_node( + 'ReduceL1', + inputs=['data'], + outputs=['reduced'], + axes=axes, + keepdims=keepdims +) + +data = np.reshape(np.arange(1, np.prod(shape) + 1, dtype=np.float32), shape) +# print(data) +#[[[1., 2.], [3., 4.]], [[5., 6.], [7., 8.]], [[9., 10.], [11., 12.]]] + +reduced = np.sum(a=np.abs(data), axis=tuple(axes), keepdims=keepdims == 1) +# print(reduced) +#[[[3.], [7.]], [[11.], [15.]], [[19.], [23.]]] + +expect(node, inputs=[data], outputs=[reduced], + name='test_reduce_l1_negative_axes_keep_dims_example') + +np.random.seed(0) +data = np.random.uniform(-10, 10, shape).astype(np.float32) +reduced = np.sum(a=np.abs(data), axis=tuple(axes), keepdims=keepdims == 1) + +expect(node, inputs=[data], outputs=[reduced], + name='test_reduce_l1_negative_axes_keep_dims_random') +``` + +
+ + +### ReduceL2 +There are 4 test cases, listed as following: +
+default_axes_keepdims + +```python +shape = [3, 2, 2] +axes = None +keepdims = 1 + +node = onnx.helper.make_node( + 'ReduceL2', + inputs=['data'], + outputs=['reduced'], + keepdims=keepdims +) + +data = np.reshape(np.arange(1, np.prod(shape) + 1, dtype=np.float32), shape) +#print(data) +#[[[1., 2.], [3., 4.]], [[5., 6.], [7., 8.]], [[9., 10.], [11., 12.]]] + +reduced = np.sqrt(np.sum( + a=np.square(data), axis=axes, keepdims=keepdims == 1)) +#print(reduced) +#[[[25.49509757]]] + +expect(node, inputs=[data], outputs=[reduced], + name='test_reduce_l2_default_axes_keepdims_example') + +np.random.seed(0) +data = np.random.uniform(-10, 10, shape).astype(np.float32) +reduced = np.sqrt(np.sum( + a=np.square(data), axis=axes, keepdims=keepdims == 1)) + +expect(node, inputs=[data], outputs=[reduced], + name='test_reduce_l2_default_axes_keepdims_random') +``` + +
+
+do_not_keepdims + +```python +shape = [3, 2, 2] +axes = [2] +keepdims = 0 + +node = onnx.helper.make_node( + 'ReduceL2', + inputs=['data'], + outputs=['reduced'], + axes=axes, + keepdims=keepdims +) + +data = np.reshape(np.arange(1, np.prod(shape) + 1, dtype=np.float32), shape) +#print(data) +#[[[1., 2.], [3., 4.]], [[5., 6.], [7., 8.]], [[9., 10.], [11., 12.]]] + +reduced = np.sqrt(np.sum( + a=np.square(data), axis=tuple(axes), keepdims=keepdims == 1)) +#print(reduced) +#[[2.23606798, 5.], +# [7.81024968, 10.63014581], +# [13.45362405, 16.2788206]] + +expect(node, inputs=[data], outputs=[reduced], + name='test_reduce_l2_do_not_keepdims_example') + +np.random.seed(0) +data = np.random.uniform(-10, 10, shape).astype(np.float32) +reduced = np.sqrt(np.sum( + a=np.square(data), axis=tuple(axes), keepdims=keepdims == 1)) + +expect(node, inputs=[data], outputs=[reduced], + name='test_reduce_l2_do_not_keepdims_random') +``` + +
+
+keepdims + +```python +shape = [3, 2, 2] +axes = [2] +keepdims = 1 + +node = onnx.helper.make_node( + 'ReduceL2', + inputs=['data'], + outputs=['reduced'], + axes=axes, + keepdims=keepdims +) + +data = np.reshape(np.arange(1, np.prod(shape) + 1, dtype=np.float32), shape) +#print(data) +#[[[1., 2.], [3., 4.]], [[5., 6.], [7., 8.]], [[9., 10.], [11., 12.]]] + +reduced = np.sqrt(np.sum( + a=np.square(data), axis=tuple(axes), keepdims=keepdims == 1)) +#print(reduced) +#[[[2.23606798], [5.]] +# [[7.81024968], [10.63014581]] +# [[13.45362405], [16.2788206 ]]] + +expect(node, inputs=[data], outputs=[reduced], + name='test_reduce_l2_keep_dims_example') + +np.random.seed(0) +data = np.random.uniform(-10, 10, shape).astype(np.float32) +reduced = np.sqrt(np.sum( + a=np.square(data), axis=tuple(axes), keepdims=keepdims == 1)) + +expect(node, inputs=[data], outputs=[reduced], name='test_reduce_l2_keep_dims_random') +``` + +
+
+negative_axes_keepdims + +```python +shape = [3, 2, 2] +axes = [-1] +keepdims = 1 + +node = onnx.helper.make_node( + 'ReduceL2', + inputs=['data'], + outputs=['reduced'], + axes=axes, + keepdims=keepdims +) + +data = np.reshape(np.arange(1, np.prod(shape) + 1, dtype=np.float32), shape) +# print(data) +#[[[1., 2.], [3., 4.]], [[5., 6.], [7., 8.]], [[9., 10.], [11., 12.]]] + +reduced = np.sqrt(np.sum( + a=np.square(data), axis=tuple(axes), keepdims=keepdims == 1)) +# print(reduced) +#[[[2.23606798], [5.]] +# [[7.81024968], [10.63014581]] +# [[13.45362405], [16.2788206 ]]] + +expect(node, inputs=[data], outputs=[reduced], + name='test_reduce_l2_negative_axes_keep_dims_example') + +np.random.seed(0) +data = np.random.uniform(-10, 10, shape).astype(np.float32) +reduced = np.sqrt(np.sum( + a=np.square(data), axis=tuple(axes), keepdims=keepdims == 1)) + +expect(node, inputs=[data], outputs=[reduced], + name='test_reduce_l2_negative_axes_keep_dims_random') +``` + +
+ + +### ReduceLogSum +There are 3 test cases, listed as following: +
+keepdims + +```python +node = onnx.helper.make_node( + 'ReduceLogSum', + inputs=['data'], + outputs=["reduced"] +) +data = np.random.ranf([3, 4, 5]).astype(np.float32) +reduced = np.log(np.sum(data, keepdims=True)) +expect(node, inputs=[data], outputs=[reduced], + name='test_reduce_log_sum_default') +``` + +
+
+negative_axes_keepdims + +```python +node = onnx.helper.make_node( + 'ReduceLogSum', + inputs=['data'], + outputs=["reduced"], + axes=[-2] +) +data = np.random.ranf([3, 4, 5]).astype(np.float32) +reduced = np.log(np.sum(data, axis=(-2), keepdims=True)) +# print(reduced) +expect(node, inputs=[data], outputs=[reduced], + name='test_reduce_log_sum_negative_axes') +``` + +
+
+nokeepdims + +```python +node = onnx.helper.make_node( + 'ReduceLogSum', + inputs=['data'], + outputs=["reduced"], + axes=[2, 1], + keepdims=0 +) +data = np.random.ranf([3, 4, 5]).astype(np.float32) +reduced = np.log(np.sum(data, axis=(2, 1), keepdims=False)) +expect(node, inputs=[data], outputs=[reduced], + name='test_reduce_log_sum_desc_axes') + +node = onnx.helper.make_node( + 'ReduceLogSum', + inputs=['data'], + outputs=["reduced"], + axes=[0, 1], + keepdims=0 +) +data = np.random.ranf([3, 4, 5]).astype(np.float32) +reduced = np.log(np.sum(data, axis=(0, 1), keepdims=False)) +expect(node, inputs=[data], outputs=[reduced], + name='test_reduce_log_sum_asc_axes') +``` + +
+ + +### ReduceLogSumExp +There are 4 test cases, listed as following: +
+default_axes_keepdims + +```python +shape = [3, 2, 2] +axes = None +keepdims = 1 + +node = onnx.helper.make_node( + 'ReduceLogSumExp', + inputs=['data'], + outputs=['reduced'], + keepdims=keepdims +) + +data = np.array( + [[[5, 1], [20, 2]], [[30, 1], [40, 2]], [[55, 1], [60, 2]]], + dtype=np.double) +reduced = np.log(np.sum(np.exp(data), + axis=axes, + keepdims=keepdims == 1)) +# print(reduced) +# [[[60.00671387]]] + +expect(node, inputs=[data], outputs=[reduced], + name='test_reduce_log_sum_exp_default_axes_keepdims_example') + +np.random.seed(0) +data = np.random.uniform(-10, 10, shape).astype(np.double) +reduced = np.log(np.sum(np.exp(data), + axis=axes, + keepdims=keepdims == 1)) +expect(node, inputs=[data], outputs=[reduced], + name='test_reduce_log_sum_exp_default_axes_keepdims_random') +``` + +
+
+do_not_keepdims + +```python +shape = [3, 2, 2] +axes = [1] +keepdims = 0 +node = onnx.helper.make_node( + 'ReduceLogSumExp', + inputs=['data'], + outputs=['reduced'], + axes=axes, + keepdims=keepdims +) + +data = np.array( + [[[5, 1], [20, 2]], [[30, 1], [40, 2]], [[55, 1], [60, 2]]], + dtype=np.double) +reduced = np.log(np.sum( + np.exp(data), axis=tuple(axes), keepdims=keepdims == 1)) +# print(reduced) +#[[20., 2.31326175] +# [40.00004578, 2.31326175] +# [60.00671387, 2.31326175]] + +expect(node, inputs=[data], outputs=[reduced], + name='test_reduce_log_sum_exp_do_not_keepdims_example') + +np.random.seed(0) +data = np.random.uniform(-10, 10, shape).astype(np.double) +reduced = np.log(np.sum( + np.exp(data), axis=tuple(axes), keepdims=keepdims == 1)) + +expect(node, inputs=[data], outputs=[reduced], + name='test_reduce_log_sum_exp_do_not_keepdims_random') +``` + +
+
+keepdims + +```python +shape = [3, 2, 2] +axes = [1] +keepdims = 1 +node = onnx.helper.make_node( + 'ReduceLogSumExp', + inputs=['data'], + outputs=['reduced'], + axes=axes, + keepdims=keepdims +) + +data = np.array( + [[[5, 1], [20, 2]], [[30, 1], [40, 2]], [[55, 1], [60, 2]]], + dtype=np.double) +reduced = np.log(np.sum(np.exp(data), + axis=tuple(axes), + keepdims=keepdims == 1)) +# print(reduced) +# [[[20., 2.31326175]] +# [[40.00004578, 2.31326175]] +# [[60.00671387, 2.31326175]]] + +expect(node, inputs=[data], outputs=[reduced], + name='test_reduce_log_sum_exp_keepdims_example') + +np.random.seed(0) +data = np.random.uniform(-10, 10, shape).astype(np.double) +reduced = np.log(np.sum(np.exp(data), + axis=tuple(axes), + keepdims=keepdims == 1)) + +expect(node, inputs=[data], outputs=[reduced], + name='test_reduce_log_sum_exp_keepdims_random') +``` + +
+
+negative_axes_keepdims + +```python +shape = [3, 2, 2] +axes = [-2] +keepdims = 1 +node = onnx.helper.make_node( + 'ReduceLogSumExp', + inputs=['data'], + outputs=['reduced'], + axes=axes, + keepdims=keepdims +) + +data = np.array( + [[[5, 1], [20, 2]], [[30, 1], [40, 2]], [[55, 1], [60, 2]]], + dtype=np.double) +reduced = np.log(np.sum(np.exp(data), + axis=tuple(axes), + keepdims=keepdims == 1)) +# print(reduced) +# [[[20., 2.31326175]] +# [[40.00004578, 2.31326175]] +# [[60.00671387, 2.31326175]]] + +expect(node, inputs=[data], outputs=[reduced], + name='test_reduce_log_sum_exp_negative_axes_keepdims_example') + +np.random.seed(0) +data = np.random.uniform(-10, 10, shape).astype(np.double) +reduced = np.log(np.sum(np.exp(data), + axis=tuple(axes), + keepdims=keepdims == 1)) + +expect(node, inputs=[data], outputs=[reduced], + name='test_reduce_log_sum_exp_negative_axes_keepdims_random') +``` + +
+ + +### ReduceMax +There are 4 test cases, listed as following: +
+default_axes_keepdims + +```python +shape = [3, 2, 2] +axes = None +keepdims = 1 +node = onnx.helper.make_node( + 'ReduceMax', + inputs=['data'], + outputs=['reduced'], + keepdims=keepdims) + +data = np.array([[[5, 1], [20, 2]], [[30, 1], [40, 2]], [[55, 1], [60, 2]]], dtype=np.float32) +reduced = np.maximum.reduce(data, axis=axes, keepdims=keepdims == 1) +#print(reduced) +[[[60.]]] + +expect(node, inputs=[data], outputs=[reduced], name='test_reduce_max_default_axes_keepdim_example') + +np.random.seed(0) +data = np.random.uniform(-10, 10, shape).astype(np.float32) +reduced = np.maximum.reduce(data, axis=axes, keepdims=keepdims == 1) + +expect(node, inputs=[data], outputs=[reduced], name='test_reduce_max_default_axes_keepdims_random') +``` + +
+
+do_not_keepdims + +```python +shape = [3, 2, 2] +axes = [1] +keepdims = 0 + +node = onnx.helper.make_node( + 'ReduceMax', + inputs=['data'], + outputs=['reduced'], + axes=axes, + keepdims=keepdims) + +data = np.array([[[5, 1], [20, 2]], [[30, 1], [40, 2]], [[55, 1], [60, 2]]], dtype=np.float32) +reduced = np.maximum.reduce(data, axis=tuple(axes), keepdims=keepdims == 1) +#print(reduced) +#[[20., 2.] +# [40., 2.] +# [60., 2.]] + +expect(node, inputs=[data], outputs=[reduced], name='test_reduce_max_do_not_keepdims_example') + +np.random.seed(0) +data = np.random.uniform(-10, 10, shape).astype(np.float32) +reduced = np.maximum.reduce(data, axis=tuple(axes), keepdims=keepdims == 1) + +expect(node, inputs=[data], outputs=[reduced], name='test_reduce_max_do_not_keepdims_random') +``` + +
+
+keepdims + +```python +shape = [3, 2, 2] +axes = [1] +keepdims = 1 + +node = onnx.helper.make_node( + 'ReduceMax', + inputs=['data'], + outputs=['reduced'], + axes=axes, + keepdims=keepdims) + +data = np.array([[[5, 1], [20, 2]], [[30, 1], [40, 2]], [[55, 1], [60, 2]]], dtype=np.float32) +reduced = np.maximum.reduce(data, axis=tuple(axes), keepdims=keepdims == 1) +#print(reduced) +#[[[20., 2.]] +# [[40., 2.]] +# [[60., 2.]]] + +expect(node, inputs=[data], outputs=[reduced], name='test_reduce_max_keepdims_example') + +np.random.seed(0) +data = np.random.uniform(-10, 10, shape).astype(np.float32) +reduced = np.maximum.reduce(data, axis=tuple(axes), keepdims=keepdims == 1) + +expect(node, inputs=[data], outputs=[reduced], name='test_reduce_max_keepdims_random') +``` + +
+
+negative_axes_keepdims + +```python +shape = [3, 2, 2] +axes = [-2] +keepdims = 1 + +node = onnx.helper.make_node( + 'ReduceMax', + inputs=['data'], + outputs=['reduced'], + axes=axes, + keepdims=keepdims) + +data = np.array([[[5, 1], [20, 2]], [[30, 1], [40, 2]], [[55, 1], [60, 2]]], dtype=np.float32) +reduced = np.maximum.reduce(data, axis=tuple(axes), keepdims=keepdims == 1) +# print(reduced) +#[[[20., 2.]] +# [[40., 2.]] +# [[60., 2.]]] + +expect(node, inputs=[data], outputs=[reduced], name='test_reduce_max_negative_axes_keepdims_example') + +np.random.seed(0) +data = np.random.uniform(-10, 10, shape).astype(np.float32) +reduced = np.maximum.reduce(data, axis=tuple(axes), keepdims=keepdims == 1) + +expect(node, inputs=[data], outputs=[reduced], name='test_reduce_max_negative_axes_keepdims_random') +``` + +
+ + +### ReduceMean +There are 4 test cases, listed as following: +
+default_axes_keepdims + +```python +shape = [3, 2, 2] +axes = None +keepdims = 1 + +node = onnx.helper.make_node( + 'ReduceMean', + inputs=['data'], + outputs=['reduced'], + keepdims=keepdims) + +data = np.array([[[5, 1], [20, 2]], [[30, 1], [40, 2]], [[55, 1], [60, 2]]], dtype=np.float32) +reduced = np.mean(data, axis=axes, keepdims=keepdims == 1) +#print(reduced) +#[[[18.25]]] + +expect(node, inputs=[data], outputs=[reduced], name='test_reduce_mean_default_axes_keepdims_example') + +np.random.seed(0) +data = np.random.uniform(-10, 10, shape).astype(np.float32) +reduced = np.mean(data, axis=axes, keepdims=keepdims == 1) + +expect(node, inputs=[data], outputs=[reduced], name='test_reduce_mean_default_axes_keepdims_random') +``` + +
+
+do_not_keepdims + +```python +shape = [3, 2, 2] +axes = [1] +keepdims = 0 + +node = onnx.helper.make_node( + 'ReduceMean', + inputs=['data'], + outputs=['reduced'], + axes=axes, + keepdims=keepdims) + +data = np.array([[[5, 1], [20, 2]], [[30, 1], [40, 2]], [[55, 1], [60, 2]]], dtype=np.float32) +reduced = np.mean(data, axis=tuple(axes), keepdims=keepdims == 1) +#print(reduced) +#[[12.5, 1.5] +# [35., 1.5] +# [57.5, 1.5]] + +expect(node, inputs=[data], outputs=[reduced], name='test_reduce_mean_do_not_keepdims_example') + +np.random.seed(0) +data = np.random.uniform(-10, 10, shape).astype(np.float32) +reduced = np.mean(data, axis=tuple(axes), keepdims=keepdims == 1) + +expect(node, inputs=[data], outputs=[reduced], name='test_reduce_mean_do_not_keepdims_random') +``` + +
+
+keepdims + +```python +shape = [3, 2, 2] +axes = [1] +keepdims = 1 + +node = onnx.helper.make_node( + 'ReduceMean', + inputs=['data'], + outputs=['reduced'], + axes=axes, + keepdims=keepdims) + +data = np.array([[[5, 1], [20, 2]], [[30, 1], [40, 2]], [[55, 1], [60, 2]]], dtype=np.float32) +reduced = np.mean(data, axis=tuple(axes), keepdims=keepdims == 1) +#print(reduced) +#[[[12.5, 1.5]] +# [[35., 1.5]] +# [[57.5, 1.5]]] + +expect(node, inputs=[data], outputs=[reduced], name='test_reduce_mean_keepdims_example') + +np.random.seed(0) +data = np.random.uniform(-10, 10, shape).astype(np.float32) +reduced = np.mean(data, axis=tuple(axes), keepdims=keepdims == 1) + +expect(node, inputs=[data], outputs=[reduced], name='test_reduce_mean_keepdims_random') +``` + +
+
+negative_axes_keepdims + +```python +shape = [3, 2, 2] +axes = [-2] +keepdims = 1 + +node = onnx.helper.make_node( + 'ReduceMean', + inputs=['data'], + outputs=['reduced'], + axes=axes, + keepdims=keepdims) + +data = np.array([[[5, 1], [20, 2]], [[30, 1], [40, 2]], [[55, 1], [60, 2]]], dtype=np.float32) +reduced = np.mean(data, axis=tuple(axes), keepdims=keepdims == 1) +# print(reduced) +# [[[12.5, 1.5]] +# [[35., 1.5]] +# [[57.5, 1.5]]] + +expect(node, inputs=[data], outputs=[reduced], name='test_reduce_mean_negative_axes_keepdims_example') + +np.random.seed(0) +data = np.random.uniform(-10, 10, shape).astype(np.float32) +reduced = np.mean(data, axis=tuple(axes), keepdims=keepdims == 1) + +expect(node, inputs=[data], outputs=[reduced], name='test_reduce_mean_negative_axes_keepdims_random') +``` + +
+ + +### ReduceMin +There are 4 test cases, listed as following: +
+default_axes_keepdims + +```python +shape = [3, 2, 2] +axes = None +keepdims = 1 + +node = onnx.helper.make_node( + 'ReduceMin', + inputs=['data'], + outputs=['reduced'], + keepdims=keepdims) + +data = np.array([[[5, 1], [20, 2]], [[30, 1], [40, 2]], [[55, 1], [60, 2]]], dtype=np.float32) +reduced = np.minimum.reduce(data, axis=axes, keepdims=keepdims == 1) +#print(reduced) +#[[[1.]]] + +expect(node, inputs=[data], outputs=[reduced], name='test_reduce_min_default_axes_keepdims_example') + +np.random.seed(0) +data = np.random.uniform(-10, 10, shape).astype(np.float32) +reduced = np.minimum.reduce(data, axis=axes, keepdims=keepdims == 1) + +expect(node, inputs=[data], outputs=[reduced], name='test_reduce_min_default_axes_keepdims_random') +``` + +
+
+do_not_keepdims + +```python +shape = [3, 2, 2] +axes = [1] +keepdims = 0 + +node = onnx.helper.make_node( + 'ReduceMin', + inputs=['data'], + outputs=['reduced'], + axes=axes, + keepdims=keepdims) + +data = np.array([[[5, 1], [20, 2]], [[30, 1], [40, 2]], [[55, 1], [60, 2]]], dtype=np.float32) +reduced = np.minimum.reduce(data, axis=tuple(axes), keepdims=keepdims == 1) +#print(reduced) +#[[5., 1.] +# [30., 1.] +# [55., 1.]] + +expect(node, inputs=[data], outputs=[reduced], name='test_reduce_min_do_not_keepdims_example') + +np.random.seed(0) +data = np.random.uniform(-10, 10, shape).astype(np.float32) +reduced = np.minimum.reduce(data, axis=tuple(axes), keepdims=keepdims == 1) + +expect(node, inputs=[data], outputs=[reduced], name='test_reduce_min_do_not_keepdims_random') +``` + +
+
+keepdims + +```python +shape = [3, 2, 2] +axes = [1] +keepdims = 1 + +node = onnx.helper.make_node( + 'ReduceMin', inputs=['data'], + outputs=['reduced'], + axes=axes, + keepdims=keepdims) + +data = np.array([[[5, 1], [20, 2]], [[30, 1], [40, 2]], [[55, 1], [60, 2]]], dtype=np.float32) +reduced = np.minimum.reduce(data, axis=tuple(axes), keepdims=keepdims == 1) +#print(reduced) +#[[[5., 1.]] +# [[30., 1.]] +# [[55., 1.]]] + +expect(node, inputs=[data], outputs=[reduced], name='test_reduce_min_keepdims_example') + +np.random.seed(0) +data = np.random.uniform(-10, 10, shape).astype(np.float32) +reduced = np.minimum.reduce(data, axis=tuple(axes), keepdims=keepdims == 1) + +expect(node, inputs=[data], outputs=[reduced], name='test_reduce_min_keepdims_random') +``` + +
+
+negative_axes_keepdims + +```python +shape = [3, 2, 2] +axes = [-2] +keepdims = 1 + +node = onnx.helper.make_node( + 'ReduceMin', inputs=['data'], + outputs=['reduced'], + axes=axes, + keepdims=keepdims) + +data = np.array([[[5, 1], [20, 2]], [[30, 1], [40, 2]], [[55, 1], [60, 2]]], dtype=np.float32) +reduced = np.minimum.reduce(data, axis=tuple(axes), keepdims=keepdims == 1) +# print(reduced) +#[[[5., 1.]] +# [[30., 1.]] +# [[55., 1.]]] + +expect(node, inputs=[data], outputs=[reduced], name='test_reduce_min_negative_axes_keepdims_example') + +np.random.seed(0) +data = np.random.uniform(-10, 10, shape).astype(np.float32) +reduced = np.minimum.reduce(data, axis=tuple(axes), keepdims=keepdims == 1) + +expect(node, inputs=[data], outputs=[reduced], name='test_reduce_min_negative_axes_keepdims_random') +``` + +
+ + +### ReduceProd +There are 4 test cases, listed as following: +
+default_axes_keepdims + +```python +shape = [3, 2, 2] +axes = None +keepdims = 1 + +node = onnx.helper.make_node( + 'ReduceProd', + inputs=['data'], + outputs=['reduced'], + keepdims=keepdims) + +data = np.array([[[1, 2], [3, 4]], [[5, 6], [7, 8]], [[9, 10], [11, 12]]], dtype=np.float32) +reduced = np.prod(data, axis=axes, keepdims=keepdims == 1) +#print(reduced) +#[[[4.790016e+08]]] + +expect(node, inputs=[data], outputs=[reduced], name='test_reduce_prod_default_axes_keepdims_example') + +np.random.seed(0) +data = np.random.uniform(-10, 10, shape).astype(np.float32) +reduced = np.prod(data, axis=axes, keepdims=keepdims == 1) +expect(node, inputs=[data], outputs=[reduced], name='test_reduce_prod_default_axes_keepdims_random') +``` + +
+
+do_not_keepdims + +```python +shape = [3, 2, 2] +axes = [1] +keepdims = 0 + +node = onnx.helper.make_node( + 'ReduceProd', + inputs=['data'], + outputs=['reduced'], + axes=axes, + keepdims=keepdims) + +data = np.array([[[1, 2], [3, 4]], [[5, 6], [7, 8]], [[9, 10], [11, 12]]], dtype=np.float32) +reduced = np.prod(data, axis=tuple(axes), keepdims=keepdims == 1) +#print(reduced) +#[[3., 8.] +# [35., 48.] +# [99., 120.]] + +expect(node, inputs=[data], outputs=[reduced], name='test_reduce_prod_do_not_keepdims_example') + +np.random.seed(0) +data = np.random.uniform(-10, 10, shape).astype(np.float32) +reduced = np.prod(data, axis=tuple(axes), keepdims=keepdims == 1) +expect(node, inputs=[data], outputs=[reduced], name='test_reduce_prod_do_not_keepdims_random') +``` + +
+
+keepdims + +```python +shape = [3, 2, 2] +axes = [1] +keepdims = 1 + +node = onnx.helper.make_node( + 'ReduceProd', + inputs=['data'], + outputs=['reduced'], + axes=axes, + keepdims=keepdims) + +data = np.array([[[1, 2], [3, 4]], [[5, 6], [7, 8]], [[9, 10], [11, 12]]], dtype=np.float32) +reduced = np.prod(data, axis=tuple(axes), keepdims=keepdims == 1) +#print(reduced) +#[[[3., 8.]] +# [[35., 48.]] +# [[99., 120.]]] + +expect(node, inputs=[data], outputs=[reduced], name='test_reduce_prod_keepdims_example') + +np.random.seed(0) +data = np.random.uniform(-10, 10, shape).astype(np.float32) +reduced = np.prod(data, axis=tuple(axes), keepdims=keepdims == 1) +expect(node, inputs=[data], outputs=[reduced], name='test_reduce_prod_keepdims_random') +``` + +
+
+negative_axes_keepdims + +```python +shape = [3, 2, 2] +axes = [-2] +keepdims = 1 + +node = onnx.helper.make_node( + 'ReduceProd', + inputs=['data'], + outputs=['reduced'], + axes=axes, + keepdims=keepdims) + +data = np.array([[[1, 2], [3, 4]], [[5, 6], [7, 8]], [[9, 10], [11, 12]]], dtype=np.float32) +reduced = np.prod(data, axis=tuple(axes), keepdims=keepdims == 1) +# print(reduced) +#[[[3., 8.]] +# [[35., 48.]] +# [[99., 120.]]] + +expect(node, inputs=[data], outputs=[reduced], name='test_reduce_prod_negative_axes_keepdims_example') + +np.random.seed(0) +data = np.random.uniform(-10, 10, shape).astype(np.float32) +reduced = np.prod(data, axis=tuple(axes), keepdims=keepdims == 1) +expect(node, inputs=[data], outputs=[reduced], name='test_reduce_prod_negative_axes_keepdims_random') +``` + +
+ + +### ReduceSum +There are 5 test cases, listed as following: +
+default_axes_keepdims + +```python +shape = [3, 2, 2] +axes = np.array([], dtype=np.int64) +keepdims = 1 + +node = onnx.helper.make_node( + 'ReduceSum', + inputs=['data', 'axes'], + outputs=['reduced'], + keepdims=keepdims) + +data = np.array([[[1, 2], [3, 4]], [[5, 6], [7, 8]], [[9, 10], [11, 12]]], dtype=np.float32) +reduced = np.sum(data, axis=None, keepdims=keepdims == 1) +#print(reduced) +#[[[78.]]] + +expect(node, inputs=[data, axes], outputs=[reduced], name='test_reduce_sum_default_axes_keepdims_example') + +np.random.seed(0) +data = np.random.uniform(-10, 10, shape).astype(np.float32) +reduced = np.sum(data, axis=None, keepdims=keepdims == 1) + +expect(node, inputs=[data, axes], outputs=[reduced], name='test_reduce_sum_default_axes_keepdims_random') +``` + +
+
+do_not_keepdims + +```python +shape = [3, 2, 2] +axes = np.array([1], dtype=np.int64) +keepdims = 0 + +node = onnx.helper.make_node( + 'ReduceSum', + inputs=['data', 'axes'], + outputs=['reduced'], + keepdims=keepdims) + +data = np.array([[[1, 2], [3, 4]], [[5, 6], [7, 8]], [[9, 10], [11, 12]]], dtype=np.float32) +reduced = np.sum(data, axis=tuple(axes.tolist()), keepdims=keepdims == 1) +#print(reduced) +#[[4., 6.] +# [12., 14.] +# [20., 22.]] + +expect(node, inputs=[data, axes], outputs=[reduced], name='test_reduce_sum_do_not_keepdims_example') + +np.random.seed(0) +data = np.random.uniform(-10, 10, shape).astype(np.float32) +reduced = np.sum(data, axis=tuple(axes.tolist()), keepdims=keepdims == 1) + +expect(node, inputs=[data, axes], outputs=[reduced], name='test_reduce_sum_do_not_keepdims_random') +``` + +
+
+empty_axes_input_noop + +```python +shape = [3, 2, 2] +keepdims = 1 + +node = onnx.helper.make_node( + 'ReduceSum', + inputs=['data', 'axes'], + outputs=['reduced'], + keepdims=keepdims, + noop_with_empty_axes=True) + +data = np.array([[[1, 2], [3, 4]], [[5, 6], [7, 8]], [[9, 10], [11, 12]]], dtype=np.float32) +axes = np.array([], dtype=np.int64) +reduced = np.array(data) +#print(reduced) +#[[[1, 2], [3, 4]], [[5, 6], [7, 8]], [[9, 10], [11, 12]]] + +expect(node, inputs=[data, axes], outputs=[reduced], + name='test_reduce_sum_empty_axes_input_noop_example') + +np.random.seed(0) +data = np.random.uniform(-10, 10, shape).astype(np.float32) +reduced = np.array(data) + +expect(node, inputs=[data, axes], outputs=[reduced], name='test_reduce_sum_negative_axes_keepdims_random') +``` + +
+
+keepdims + +```python +shape = [3, 2, 2] +axes = np.array([1], dtype=np.int64) +keepdims = 1 + +node = onnx.helper.make_node( + 'ReduceSum', + inputs=['data', 'axes'], + outputs=['reduced'], + keepdims=keepdims) + +data = np.array([[[1, 2], [3, 4]], [[5, 6], [7, 8]], [[9, 10], [11, 12]]], dtype=np.float32) +reduced = np.sum(data, axis=tuple(axes.tolist()), keepdims=keepdims == 1) +#print(reduced) +#[[[4., 6.]] +# [[12., 14.]] +# [[20., 22.]]] + +expect(node, inputs=[data, axes], outputs=[reduced], name='test_reduce_sum_keepdims_example') + +np.random.seed(0) +data = np.random.uniform(-10, 10, shape).astype(np.float32) +reduced = np.sum(data, axis=tuple(axes.tolist()), keepdims=keepdims == 1) + +expect(node, inputs=[data, axes], outputs=[reduced], name='test_reduce_sum_keepdims_random') +``` + +
+
+negative_axes_keepdims + +```python +shape = [3, 2, 2] +axes = np.array([-2], dtype=np.int64) +keepdims = 1 + +node = onnx.helper.make_node( + 'ReduceSum', + inputs=['data', 'axes'], + outputs=['reduced'], + keepdims=keepdims) + +data = np.array([[[1, 2], [3, 4]], [[5, 6], [7, 8]], [[9, 10], [11, 12]]], dtype=np.float32) +reduced = np.sum(data, axis=tuple(axes.tolist()), keepdims=keepdims == 1) +# print(reduced) +#[[[4., 6.]] +# [[12., 14.]] +# [[20., 22.]]] + +expect(node, inputs=[data, axes], outputs=[reduced], + name='test_reduce_sum_negative_axes_keepdims_example') + +np.random.seed(0) +data = np.random.uniform(-10, 10, shape).astype(np.float32) +reduced = np.sum(data, axis=tuple( + axes.tolist()), keepdims=keepdims == 1) + +expect(node, inputs=[data, axes], outputs=[reduced], + name='test_reduce_sum_negative_axes_keepdims_random') +``` + +
+ + +### ReduceSumSquare +There are 4 test cases, listed as following: +
+default_axes_keepdims + +```python +shape = [3, 2, 2] +axes = None +keepdims = 1 + +node = onnx.helper.make_node( + 'ReduceSumSquare', + inputs=['data'], + outputs=['reduced'], + keepdims=keepdims) + +data = np.array([[[1, 2], [3, 4]], [[5, 6], [7, 8]], [[9, 10], [11, 12]]], dtype=np.float32) +reduced = np.sum(np.square(data), axis=axes, keepdims=keepdims == 1) +#print(reduced) +#[[[650.]]] + +expect(node, inputs=[data], outputs=[reduced], name='test_reduce_sum_square_default_axes_keepdims_example') + +np.random.seed(0) +data = np.random.uniform(-10, 10, shape).astype(np.float32) +reduced = np.sum(np.square(data), axis=axes, keepdims=keepdims == 1) + +expect(node, inputs=[data], outputs=[reduced], name='test_reduce_sum_square_default_axes_keepdims_random') +``` + +
+
+do_not_keepdims + +```python +shape = [3, 2, 2] +axes = [1] +keepdims = 0 + +node = onnx.helper.make_node( + 'ReduceSumSquare', + inputs=['data'], + outputs=['reduced'], + axes=axes, + keepdims=keepdims) + +data = np.array([[[1, 2], [3, 4]], [[5, 6], [7, 8]], [[9, 10], [11, 12]]], dtype=np.float32) +reduced = np.sum(np.square(data), axis=tuple(axes), keepdims=keepdims == 1) +#print(reduced) +#[[10., 20.] +# [74., 100.] +# [202., 244.]] + +expect(node, inputs=[data], outputs=[reduced], name='test_reduce_sum_square_do_not_keepdims_example') + +np.random.seed(0) +data = np.random.uniform(-10, 10, shape).astype(np.float32) +reduced = np.sum(np.square(data), axis=tuple(axes), keepdims=keepdims == 1) + +expect(node, inputs=[data], outputs=[reduced], name='test_reduce_sum_square_do_not_keepdims_random') +``` + +
+
+keepdims + +```python +shape = [3, 2, 2] +axes = [1] +keepdims = 1 + +node = onnx.helper.make_node( + 'ReduceSumSquare', + inputs=['data'], + outputs=['reduced'], + axes=axes, + keepdims=keepdims) + +data = np.array([[[1, 2], [3, 4]], [[5, 6], [7, 8]], [[9, 10], [11, 12]]], dtype=np.float32) +reduced = np.sum(np.square(data), axis=tuple(axes), keepdims=keepdims == 1) +#print(reduced) +#[[[10., 20.]] +# [[74., 100.]] +# [[202., 244.]]] + +expect(node, inputs=[data], outputs=[reduced], name='test_reduce_sum_square_keepdims_example') + +np.random.seed(0) +data = np.random.uniform(-10, 10, shape).astype(np.float32) +reduced = np.sum(np.square(data), axis=tuple(axes), keepdims=keepdims == 1) + +expect(node, inputs=[data], outputs=[reduced], name='test_reduce_sum_square_keepdims_random') +``` + +
+
+negative_axes_keepdims + +```python +shape = [3, 2, 2] +axes = [-2] +keepdims = 1 + +node = onnx.helper.make_node( + 'ReduceSumSquare', + inputs=['data'], + outputs=['reduced'], + axes=axes, + keepdims=keepdims) + +data = np.array([[[1, 2], [3, 4]], [[5, 6], [7, 8]], [[9, 10], [11, 12]]], dtype=np.float32) +reduced = np.sum(np.square(data), axis=tuple(axes), keepdims=keepdims == 1) +# print(reduced) +#[[[10., 20.s]] +# [[74., 100.]] +# [[202., 244.]]] + +expect(node, inputs=[data], outputs=[reduced], name='test_reduce_sum_square_negative_axes_keepdims_example') + +np.random.seed(0) +data = np.random.uniform(-10, 10, shape).astype(np.float32) +reduced = np.sum(np.square(data), axis=tuple(axes), keepdims=keepdims == 1) + +expect(node, inputs=[data], outputs=[reduced], name='test_reduce_sum_square_negative_axes_keepdims_random') +``` + +
+ + +### Relu +There are 1 test cases, listed as following: +
+relu + +```python +node = onnx.helper.make_node( + 'Relu', + inputs=['x'], + outputs=['y'], +) +x = np.random.randn(3, 4, 5).astype(np.float32) +y = np.clip(x, 0, np.inf) + +expect(node, inputs=[x], outputs=[y], + name='test_relu') +``` + +
+ + +### Reshape +There are 2 test cases, listed as following: +
+allowzero + +```python +original_shape = [0, 3, 4] +test_cases = { + 'allowzero_reordered': np.array([3, 4, 0], dtype=np.int64), +} +data = np.random.random_sample(original_shape).astype(np.float32) + +for test_name, shape in test_cases.items(): + node = onnx.helper.make_node( + 'Reshape', + inputs=['data', 'shape'], + outputs=['reshaped'], + allowzero=1, # if allowzero=1, final shape = (3, 4, 0) + # if allowzero=0, final shape = (3, 4, 4) + ) + + reshaped = reshape_reference_implementation(data, shape, allowzero=1) + + expect(node, inputs=[data, shape], outputs=[reshaped], + name='test_reshape_' + test_name) +``` + +
+
+reshape + +```python +original_shape = [2, 3, 4] +test_cases = { + 'reordered_all_dims': np.array([4, 2, 3], dtype=np.int64), + 'reordered_last_dims': np.array([2, 4, 3], dtype=np.int64), + 'reduced_dims': np.array([2, 12], dtype=np.int64), + 'extended_dims': np.array([2, 3, 2, 2], dtype=np.int64), + 'one_dim': np.array([24], dtype=np.int64), + 'negative_dim': np.array([2, -1, 2], dtype=np.int64), + 'negative_extended_dims': np.array([-1, 2, 3, 4], dtype=np.int64), + 'zero_dim': np.array([2, 0, 4, 1], dtype=np.int64), + 'zero_and_negative_dim': np.array([2, 0, 1, -1], dtype=np.int64), +} +data = np.random.random_sample(original_shape).astype(np.float32) + +for test_name, shape in test_cases.items(): + node = onnx.helper.make_node( + 'Reshape', + inputs=['data', 'shape'], + outputs=['reshaped'], + ) + + reshaped = reshape_reference_implementation(data, shape) + + expect(node, inputs=[data, shape], outputs=[reshaped], + name='test_reshape_' + test_name) +``` + +
+ + +### Resize +There are 23 test cases, listed as following: +
+resize_downsample_scales_cubic + +```python +node = onnx.helper.make_node( + 'Resize', + inputs=['X', '', 'scales'], + outputs=['Y'], + mode='cubic', +) + +data = np.array([[[ + [1, 2, 3, 4], + [5, 6, 7, 8], + [9, 10, 11, 12], + [13, 14, 15, 16], +]]], dtype=np.float32) + +scales = np.array([1.0, 1.0, 0.8, 0.8], dtype=np.float32) + +# [[[[ 1.47119141 2.78125 4.08251953] +# [ 6.71142578 8.02148438 9.32275391] +# [11.91650391 13.2265625 14.52783203]]]] +output = interpolate_nd( + data, cubic_coeffs, scale_factors=scales).astype(np.float32) + +expect(node, inputs=[data, scales], outputs=[output], + name='test_resize_downsample_scales_cubic') +``` + +
+
+resize_downsample_scales_cubic_A_n0p5_exclude_outside + +```python +node = onnx.helper.make_node( + 'Resize', + inputs=['X', '', 'scales'], + outputs=['Y'], + mode='cubic', + cubic_coeff_a=-0.5, + exclude_outside=True +) + +data = np.array([[[ + [1, 2, 3, 4], + [5, 6, 7, 8], + [9, 10, 11, 12], + [13, 14, 15, 16], +]]], dtype=np.float32) + +scales = np.array([1.0, 1.0, 0.8, 0.8], dtype=np.float32) + +# [[[[ 1.36812675 2.6695014 4.0133367 ] +# [ 6.57362535 7.875 9.2188353 ] +# [11.94896657 13.25034122 14.59417652]]]] +output = interpolate_nd(data, lambda x: cubic_coeffs(x, A=-0.5), scale_factors=scales, + exclude_outside=True).astype(np.float32) + +expect(node, inputs=[data, scales], outputs=[output], + name='test_resize_downsample_scales_cubic_A_n0p5_exclude_outside') +``` + +
+
+resize_downsample_scales_cubic_align_corners + +```python +node = onnx.helper.make_node( + 'Resize', + inputs=['X', '', 'scales'], + outputs=['Y'], + mode='cubic', + coordinate_transformation_mode='align_corners' +) + +data = np.array([[[ + [1, 2, 3, 4], + [5, 6, 7, 8], + [9, 10, 11, 12], + [13, 14, 15, 16], +]]], dtype=np.float32) + +scales = np.array([1.0, 1.0, 0.8, 0.8], dtype=np.float32) + +# [[[[ 1. 2.39519159 3.79038317] +# [ 6.58076634 7.97595793 9.37114951] +# [12.16153268 13.55672427 14.95191585]]]] +output = interpolate_nd( + data, cubic_coeffs, scale_factors=scales, coordinate_transformation_mode='align_corners').astype(np.float32) + +expect(node, inputs=[data, scales], outputs=[output], + name='test_resize_downsample_scales_cubic_align_corners') +``` + +
+
+resize_downsample_scales_linear + +```python +node = onnx.helper.make_node( + 'Resize', + inputs=['X', '', 'scales'], + outputs=['Y'], + mode='linear', +) + +data = np.array([[[ + [1, 2, 3, 4], + [5, 6, 7, 8], +]]], dtype=np.float32) + +scales = np.array([1.0, 1.0, 0.6, 0.6], dtype=np.float32) + +# [[[[2.6666665 4.3333331]]]] +output = interpolate_nd( + data, linear_coeffs, scale_factors=scales).astype(np.float32) + +expect(node, inputs=[data, scales], outputs=[output], + name='test_resize_downsample_scales_linear') +``` + +
+
+resize_downsample_scales_linear_align_corners + +```python +node = onnx.helper.make_node( + 'Resize', + inputs=['X', '', 'scales'], + outputs=['Y'], + mode='linear', + coordinate_transformation_mode='align_corners' +) + +data = np.array([[[ + [1, 2, 3, 4], + [5, 6, 7, 8], +]]], dtype=np.float32) + +scales = np.array([1.0, 1.0, 0.6, 0.6], dtype=np.float32) + +# [[[[1. 3.142857]]]] +output = interpolate_nd( + data, linear_coeffs, scale_factors=scales, coordinate_transformation_mode='align_corners').astype(np.float32) + +expect(node, inputs=[data, scales], outputs=[output], + name='test_resize_downsample_scales_linear_align_corners') +``` + +
+
+resize_downsample_scales_nearest + +```python +node = onnx.helper.make_node( + 'Resize', + inputs=['X', '', 'scales'], + outputs=['Y'], + mode='nearest', +) + +data = np.array([[[ + [1, 2, 3, 4], + [5, 6, 7, 8], +]]], dtype=np.float32) + +scales = np.array([1.0, 1.0, 0.6, 0.6], dtype=np.float32) + +# [[[[1. 3.]]]] +output = interpolate_nd( + data, nearest_coeffs, scale_factors=scales).astype(np.float32) + +expect(node, inputs=[data, scales], outputs=[output], + name='test_resize_downsample_scales_nearest') +``` + +
+
+resize_downsample_sizes_cubic + +```python +node = onnx.helper.make_node( + 'Resize', + inputs=['X', '', '', 'sizes'], + outputs=['Y'], + mode='cubic', +) + +data = np.array([[[ + [1, 2, 3, 4], + [5, 6, 7, 8], + [9, 10, 11, 12], + [13, 14, 15, 16], +]]], dtype=np.float32) + +sizes = np.array([1, 1, 3, 3], dtype=np.int64) + +# [[[[ 1.63078704 3.00462963 4.37847222] +# [ 7.12615741 8.5 9.87384259] +# [12.62152778 13.99537037 15.36921296]]]] +output = interpolate_nd( + data, cubic_coeffs, output_size=sizes).astype(np.float32) + +expect(node, inputs=[data, sizes], outputs=[output], + name='test_resize_downsample_sizes_cubic') +``` + +
+
+resize_downsample_sizes_linear_pytorch_half_pixel + +```python +node = onnx.helper.make_node( + 'Resize', + inputs=['X', '', '', 'sizes'], + outputs=['Y'], + mode='linear', + coordinate_transformation_mode='pytorch_half_pixel' +) + +data = np.array([[[ + [1, 2, 3, 4], + [5, 6, 7, 8], + [9, 10, 11, 12], + [13, 14, 15, 16], +]]], dtype=np.float32) + +sizes = np.array([1, 1, 3, 1], dtype=np.int64) + +# [[[[ 1.6666666] +# [ 7. ] +# [12.333333 ]]]] +output = interpolate_nd( + data, linear_coeffs, output_size=sizes, coordinate_transformation_mode='pytorch_half_pixel').astype(np.float32) + +expect(node, inputs=[data, sizes], outputs=[output], + name='test_resize_downsample_sizes_linear_pytorch_half_pixel') +``` + +
+
+resize_downsample_sizes_nearest + +```python +node = onnx.helper.make_node( + 'Resize', + inputs=['X', '', '', 'sizes'], + outputs=['Y'], + mode='nearest', +) + +data = np.array([[[ + [1, 2, 3, 4], + [5, 6, 7, 8], +]]], dtype=np.float32) + +sizes = np.array([1, 1, 1, 3], dtype=np.int64) + +# [[[[1. 3.]]]] +output = interpolate_nd( + data, nearest_coeffs, output_size=sizes).astype(np.float32) + +expect(node, inputs=[data, sizes], outputs=[output], + name='test_resize_downsample_sizes_nearest') +``` + +
+
+resize_tf_crop_and_resize + +```python +node = onnx.helper.make_node( + 'Resize', + inputs=['X', 'roi', '', 'sizes'], + outputs=['Y'], + mode='linear', + coordinate_transformation_mode='tf_crop_and_resize' +) + +data = np.array([[[ + [1, 2, 3, 4], + [5, 6, 7, 8], + [9, 10, 11, 12], + [13, 14, 15, 16], +]]], dtype=np.float32) + +# Note: for some rois, the result may be different with that of TF for inaccurate floating point +roi = np.array([0, 0, 0.4, 0.6, 1, 1, 0.6, 0.8], dtype=np.float32) +sizes = np.array([1, 1, 3, 3], dtype=np.int64) + +# [[[[ 7.6000004 7.9 8.2 ] +# [ 8.8 9.1 9.400001 ] +# [10. 10.3 10.6 ]]]] +output = interpolate_nd(data, linear_coeffs, output_size=sizes, roi=roi, + coordinate_transformation_mode='tf_crop_and_resize').astype(np.float32) + +expect(node, inputs=[data, roi, sizes], outputs=[output], + name='test_resize_tf_crop_and_resize') +``` + +
+
+resize_tf_crop_and_resize_extrapolation_value + +```python +node = onnx.helper.make_node( + 'Resize', + inputs=['X', 'roi', '', 'sizes'], + outputs=['Y'], + mode='linear', + coordinate_transformation_mode='tf_crop_and_resize', + extrapolation_value=10.0 +) + +data = np.array([[[ + [1, 2, 3, 4], + [5, 6, 7, 8], + [9, 10, 11, 12], + [13, 14, 15, 16], +]]], dtype=np.float32) + +# Note: for some rois, the result may be different with that of TF for inaccurate floating point +roi = np.array([0, 0, 0.4, 0.6, 1, 1, 1.2, 1.7], dtype=np.float32) +sizes = np.array([1, 1, 3, 3], dtype=np.int64) + +# [[[[ 7.6000004 10. 10. ] +# [12.400001 10. 10. ] +# [10. 10. 10. ]]]] +output = interpolate_nd(data, linear_coeffs, output_size=sizes, roi=roi, + coordinate_transformation_mode='tf_crop_and_resize', extrapolation_value=10.0).astype(np.float32) + +expect(node, inputs=[data, roi, sizes], outputs=[output], + name='test_resize_tf_crop_and_resize') +``` + +
+
+resize_upsample_scales_cubic + +```python +node = onnx.helper.make_node( + 'Resize', + inputs=['X', '', 'scales'], + outputs=['Y'], + mode='cubic', +) + +data = np.array([[[ + [1, 2, 3, 4], + [5, 6, 7, 8], + [9, 10, 11, 12], + [13, 14, 15, 16], +]]], dtype=np.float32) + +scales = np.array([1.0, 1.0, 2.0, 2.0], dtype=np.float32) + +# [[[[ 0.47265625 0.76953125 1.24609375 1.875 2.28125 +# 2.91015625 3.38671875 3.68359375] +# [ 1.66015625 1.95703125 2.43359375 3.0625 3.46875 +# 4.09765625 4.57421875 4.87109375] +# [ 3.56640625 3.86328125 4.33984375 4.96875 5.375 +# 6.00390625 6.48046875 6.77734375] +# [ 6.08203125 6.37890625 6.85546875 7.484375 7.890625 +# 8.51953125 8.99609375 9.29296875] +# [ 7.70703125 8.00390625 8.48046875 9.109375 9.515625 +# 10.14453125 10.62109375 10.91796875] +# [10.22265625 10.51953125 10.99609375 11.625 12.03125 +# 12.66015625 13.13671875 13.43359375] +# [12.12890625 12.42578125 12.90234375 13.53125 13.9375 +# 14.56640625 15.04296875 15.33984375] +# [13.31640625 13.61328125 14.08984375 14.71875 15.125 +# 15.75390625 16.23046875 16.52734375]]]] +output = interpolate_nd( + data, cubic_coeffs, scale_factors=scales).astype(np.float32) + +expect(node, inputs=[data, scales], outputs=[output], + name='test_resize_upsample_scales_cubic') +``` + +
+
+resize_upsample_scales_cubic_A_n0p5_exclude_outside + +```python +node = onnx.helper.make_node( + 'Resize', + inputs=['X', '', 'scales'], + outputs=['Y'], + mode='cubic', + cubic_coeff_a=-0.5, + exclude_outside=True +) + +data = np.array([[[ + [1, 2, 3, 4], + [5, 6, 7, 8], + [9, 10, 11, 12], + [13, 14, 15, 16], +]]], dtype=np.float32) + +scales = np.array([1.0, 1.0, 2.0, 2.0], dtype=np.float32) + +# [[[[ 0.55882353 0.81494204 1.35698249 1.89705882 2.39705882 +# 2.93713516 3.47917561 3.73529412] +# [ 1.58329755 1.83941606 2.38145651 2.92153285 3.42153285 +# 3.96160918 4.50364964 4.75976814] +# [ 3.75145936 4.00757787 4.54961832 5.08969466 5.58969466 +# 6.12977099 6.67181144 6.92792995] +# [ 5.91176471 6.16788321 6.70992366 7.25 7.75 +# 8.29007634 8.83211679 9.08823529] +# [ 7.91176471 8.16788321 8.70992366 9.25 9.75 +# 10.29007634 10.83211679 11.08823529] +# [10.07207005 10.32818856 10.87022901 11.41030534 11.91030534 +# 12.45038168 12.99242213 13.24854064] +# [12.24023186 12.49635036 13.03839082 13.57846715 14.07846715 +# 14.61854349 15.16058394 15.41670245] +# [13.26470588 13.52082439 14.06286484 14.60294118 15.10294118 +# 15.64301751 16.18505796 16.44117647]]]] +output = interpolate_nd(data, lambda x: cubic_coeffs(x, A=-0.5), scale_factors=scales, + exclude_outside=True).astype(np.float32) + +expect(node, inputs=[data, scales], outputs=[output], + name='test_resize_upsample_scales_cubic_A_n0p5_exclude_outside') +``` + +
+
+resize_upsample_scales_cubic_align_corners + +```python +node = onnx.helper.make_node( + 'Resize', + inputs=['X', '', 'scales'], + outputs=['Y'], + mode='cubic', + coordinate_transformation_mode='align_corners' +) + +data = np.array([[[ + [1, 2, 3, 4], + [5, 6, 7, 8], + [9, 10, 11, 12], + [13, 14, 15, 16], +]]], dtype=np.float32) + +scales = np.array([1.0, 1.0, 2.0, 2.0], dtype=np.float32) + +# [[[[ 1. 1.34110787 1.80029155 2.32944606 2.67055394 +# 3.19970845 3.65889213 4. ] +# [ 2.36443149 2.70553936 3.16472303 3.69387755 4.03498542 +# 4.56413994 5.02332362 5.36443149] +# [ 4.20116618 4.54227405 5.00145773 5.53061224 5.87172012 +# 6.40087464 6.86005831 7.20116618] +# [ 6.31778426 6.65889213 7.1180758 7.64723032 7.98833819 +# 8.51749271 8.97667638 9.31778426] +# [ 7.68221574 8.02332362 8.48250729 9.01166181 9.35276968 +# 9.8819242 10.34110787 10.68221574] +# [ 9.79883382 10.13994169 10.59912536 11.12827988 11.46938776 +# 11.99854227 12.45772595 12.79883382] +# [11.63556851 11.97667638 12.43586006 12.96501458 13.30612245 +# 13.83527697 14.29446064 14.63556851] +# [13. 13.34110787 13.80029155 14.32944606 14.67055394 +# 15.19970845 15.65889213 16. ]]]] +output = interpolate_nd( + data, cubic_coeffs, scale_factors=scales, coordinate_transformation_mode='align_corners').astype(np.float32) + +expect(node, inputs=[data, scales], outputs=[output], + name='test_resize_upsample_scales_cubic_align_corners') +``` + +
+
+resize_upsample_scales_cubic_asymmetric + +```python +node = onnx.helper.make_node( + 'Resize', + inputs=['X', '', 'scales'], + outputs=['Y'], + mode='cubic', + coordinate_transformation_mode='asymmetric' +) + +data = np.array([[[ + [1, 2, 3, 4], + [5, 6, 7, 8], + [9, 10, 11, 12], + [13, 14, 15, 16], +]]], dtype=np.float32) + +scales = np.array([1.0, 1.0, 2.0, 2.0], dtype=np.float32) + +# [[[[ 1. 1.40625 2. 2.5 3. 3.59375 4. +# 4.09375] +# [ 2.625 3.03125 3.625 4.125 4.625 5.21875 5.625 +# 5.71875] +# [ 5. 5.40625 6. 6.5 7. 7.59375 8. +# 8.09375] +# [ 7. 7.40625 8. 8.5 9. 9.59375 10. +# 10.09375] +# [ 9. 9.40625 10. 10.5 11. 11.59375 12. +# 12.09375] +# [11.375 11.78125 12.375 12.875 13.375 13.96875 14.375 +# 14.46875] +# [13. 13.40625 14. 14.5 15. 15.59375 16. +# 16.09375] +# [13.375 13.78125 14.375 14.875 15.375 15.96875 16.375 +# 16.46875]]]] +output = interpolate_nd(data, lambda x: cubic_coeffs(x, A=-0.75), scale_factors=scales, + coordinate_transformation_mode='asymmetric').astype(np.float32) + +expect(node, inputs=[data, scales], outputs=[output], + name='test_resize_upsample_scales_cubic_asymmetric') +``` + +
+
+resize_upsample_scales_linear + +```python +node = onnx.helper.make_node( + 'Resize', + inputs=['X', '', 'scales'], + outputs=['Y'], + mode='linear', +) + +data = np.array([[[ + [1, 2], + [3, 4], +]]], dtype=np.float32) + +scales = np.array([1.0, 1.0, 2.0, 2.0], dtype=np.float32) + +# [[[[1. 1.25 1.75 2. ] +# [1.5 1.75 2.25 2.5 ] +# [2.5 2.75 3.25 3.5 ] +# [3. 3.25 3.75 4. ]]]] +output = interpolate_nd( + data, linear_coeffs, scale_factors=scales).astype(np.float32) + +expect(node, inputs=[data, scales], outputs=[output], + name='test_resize_upsample_scales_linear') +``` + +
+
+resize_upsample_scales_linear_align_corners + +```python +node = onnx.helper.make_node( + 'Resize', + inputs=['X', '', 'scales'], + outputs=['Y'], + mode='linear', + coordinate_transformation_mode='align_corners' +) + +data = np.array([[[ + [1, 2], + [3, 4], +]]], dtype=np.float32) + +scales = np.array([1.0, 1.0, 2.0, 2.0], dtype=np.float32) + +# [[[[1. 1.33333333 1.66666667 2. ] +# [1.66666667 2. 2.33333333 2.66666667] +# [2.33333333 2.66666667 3. 3.33333333] +# [3. 3.33333333 3.66666667 4. ]]]] +output = interpolate_nd( + data, linear_coeffs, scale_factors=scales, coordinate_transformation_mode='align_corners').astype(np.float32) + +expect(node, inputs=[data, scales], outputs=[output], + name='test_resize_upsample_scales_linear_align_corners') +``` + +
+
+resize_upsample_scales_nearest + +```python +node = onnx.helper.make_node( + 'Resize', + inputs=['X', '', 'scales'], + outputs=['Y'], + mode='nearest', +) + +data = np.array([[[ + [1, 2], + [3, 4], +]]], dtype=np.float32) + +scales = np.array([1.0, 1.0, 2.0, 3.0], dtype=np.float32) + +# [[[[1. 1. 1. 2. 2. 2.] +# [1. 1. 1. 2. 2. 2.] +# [3. 3. 3. 4. 4. 4.] +# [3. 3. 3. 4. 4. 4.]]]] +output = interpolate_nd( + data, nearest_coeffs, scale_factors=scales).astype(np.float32) + +expect(node, inputs=[data, scales], outputs=[output], + name='test_resize_upsample_scales_nearest') +``` + +
+
+resize_upsample_sizes_cubic + +```python +node = onnx.helper.make_node( + 'Resize', + inputs=['X', '', '', 'sizes'], + outputs=['Y'], + mode='cubic', +) + +data = np.array([[[ + [1, 2, 3, 4], + [5, 6, 7, 8], + [9, 10, 11, 12], + [13, 14, 15, 16], +]]], dtype=np.float32) + +sizes = np.array([1, 1, 9, 10], dtype=np.int64) + +# [[[[ 0.45507922 0.64057922 0.97157922 1.42257922 1.90732922 +# 2.22332922 2.70807922 3.15907922 3.49007922 3.67557922] +# [ 1.39437963 1.57987963 1.91087963 2.36187963 2.84662963 +# 3.16262963 3.64737963 4.09837963 4.42937963 4.61487963] +# [ 2.95130693 3.13680693 3.46780693 3.91880693 4.40355693 +# 4.71955693 5.20430693 5.65530693 5.98630693 6.17180693] +# [ 5.20525069 5.39075069 5.72175069 6.17275069 6.65750069 +# 6.97350069 7.45825069 7.90925069 8.24025069 8.42575069] +# [ 6.88975 7.07525 7.40625 7.85725 8.342 +# 8.658 9.14275 9.59375 9.92475 10.11025 ] +# [ 8.57424931 8.75974931 9.09074931 9.54174931 10.02649931 +# 10.34249931 10.82724931 11.27824931 11.60924931 11.79474931] +# [10.82819307 11.01369307 11.34469307 11.79569307 12.28044307 +# 12.59644307 13.08119307 13.53219307 13.86319307 14.04869307] +# [12.38512037 12.57062037 12.90162037 13.35262037 13.83737037 +# 14.15337037 14.63812037 15.08912037 15.42012037 15.60562037] +# [13.32442078 13.50992078 13.84092078 14.29192078 14.77667078 +# 15.09267078 15.57742078 16.02842078 16.35942078 16.54492078]]]] +output = interpolate_nd( + data, cubic_coeffs, output_size=sizes).astype(np.float32) + +expect(node, inputs=[data, sizes], outputs=[output], + name='test_resize_upsample_sizes_cubic') +``` + +
+
+resize_upsample_sizes_nearest + +```python +node = onnx.helper.make_node( + 'Resize', + inputs=['X', '', '', 'sizes'], + outputs=['Y'], + mode='nearest', +) + +data = np.array([[[ + [1, 2], + [3, 4], +]]], dtype=np.float32) + +sizes = np.array([1, 1, 7, 8], dtype=np.int64) + +# [[[[1. 1. 1. 1. 2. 2. 2. 2.] +# [1. 1. 1. 1. 2. 2. 2. 2.] +# [1. 1. 1. 1. 2. 2. 2. 2.] +# [1. 1. 1. 1. 2. 2. 2. 2.] +# [3. 3. 3. 3. 4. 4. 4. 4.] +# [3. 3. 3. 3. 4. 4. 4. 4.] +# [3. 3. 3. 3. 4. 4. 4. 4.]]]] +output = interpolate_nd( + data, nearest_coeffs, output_size=sizes).astype(np.float32) + +expect(node, inputs=[data, sizes], outputs=[output], + name='test_resize_upsample_sizes_nearest') +``` + +
+
+resize_upsample_sizes_nearest_ceil_half_pixel + +```python +node = onnx.helper.make_node( + 'Resize', + inputs=['X', '', '', 'sizes'], + outputs=['Y'], + mode='nearest', + coordinate_transformation_mode='half_pixel', + nearest_mode='ceil' +) + +data = np.array([[[ + [1, 2, 3, 4], + [5, 6, 7, 8], + [9, 10, 11, 12], + [13, 14, 15, 16], +]]], dtype=np.float32) + +sizes = np.array([1, 1, 8, 8], dtype=np.int64) + +# [[[[ 1. 2. 2. 3. 3. 4. 4. 4.] +# [ 5. 6. 6. 7. 7. 8. 8. 8.] +# [ 5. 6. 6. 7. 7. 8. 8. 8.] +# [ 9. 10. 10. 11. 11. 12. 12. 12.] +# [ 9. 10. 10. 11. 11. 12. 12. 12.] +# [13. 14. 14. 15. 15. 16. 16. 16.] +# [13. 14. 14. 15. 15. 16. 16. 16.] +# [13. 14. 14. 15. 15. 16. 16. 16.]]]] +output = interpolate_nd( + data, lambda x: nearest_coeffs(x, mode='ceil'), output_size=sizes).astype(np.float32) + +expect(node, inputs=[data, sizes], outputs=[output], + name='test_resize_upsample_sizes_nearest_ceil_half_pixel') +``` + +
+
+resize_upsample_sizes_nearest_floor_align_corners + +```python +node = onnx.helper.make_node( + 'Resize', + inputs=['X', '', '', 'sizes'], + outputs=['Y'], + mode='nearest', + coordinate_transformation_mode='align_corners', + nearest_mode='floor' +) + +data = np.array([[[ + [1, 2, 3, 4], + [5, 6, 7, 8], + [9, 10, 11, 12], + [13, 14, 15, 16], +]]], dtype=np.float32) + +sizes = np.array([1, 1, 8, 8], dtype=np.int64) + +# [[[[ 1. 1. 1. 2. 2. 3. 3. 4.] +# [ 1. 1. 1. 2. 2. 3. 3. 4.] +# [ 1. 1. 1. 2. 2. 3. 3. 4.] +# [ 5. 5. 5. 6. 6. 7. 7. 8.] +# [ 5. 5. 5. 6. 6. 7. 7. 8.] +# [ 9. 9. 9. 10. 10. 11. 11. 12.] +# [ 9. 9. 9. 10. 10. 11. 11. 12.] +# [13. 13. 13. 14. 14. 15. 15. 16.]]]] +output = interpolate_nd( + data, lambda x: nearest_coeffs(x, mode='floor'), output_size=sizes, coordinate_transformation_mode='align_corners').astype(np.float32) + +expect(node, inputs=[data, sizes], outputs=[output], + name='test_resize_upsample_sizes_nearest_floor_align_corners') +``` + +
+
+resize_upsample_sizes_nearest_round_prefer_ceil_asymmetric + +```python +node = onnx.helper.make_node( + 'Resize', + inputs=['X', '', '', 'sizes'], + outputs=['Y'], + mode='nearest', + coordinate_transformation_mode='asymmetric', + nearest_mode='round_prefer_ceil' +) + +data = np.array([[[ + [1, 2, 3, 4], + [5, 6, 7, 8], + [9, 10, 11, 12], + [13, 14, 15, 16], +]]], dtype=np.float32) + +sizes = np.array([1, 1, 8, 8], dtype=np.int64) + +# [[[[ 1. 2. 2. 3. 3. 4. 4. 4.] +# [ 5. 6. 6. 7. 7. 8. 8. 8.] +# [ 5. 6. 6. 7. 7. 8. 8. 8.] +# [ 9. 10. 10. 11. 11. 12. 12. 12.] +# [ 9. 10. 10. 11. 11. 12. 12. 12.] +# [13. 14. 14. 15. 15. 16. 16. 16.] +# [13. 14. 14. 15. 15. 16. 16. 16.] +# [13. 14. 14. 15. 15. 16. 16. 16.]]]] +output = interpolate_nd( + data, lambda x: nearest_coeffs(x, mode='round_prefer_ceil'), + output_size=sizes, coordinate_transformation_mode='asymmetric').astype(np.float32) + +expect(node, inputs=[data, sizes], outputs=[output], + name='test_resize_upsample_sizes_nearest_round_prefer_ceil_asymmetric') +``` + +
+ + +### ReverseSequence +There are 2 test cases, listed as following: +
+reversesequence_batch + +```python +node = onnx.helper.make_node( + 'ReverseSequence', + inputs=['x', 'sequence_lens'], + outputs=['y'], + time_axis=1, + batch_axis=0, +) +x = np.array([[0.0, 1.0, 2.0, 3.0], + [4.0, 5.0, 6.0, 7.0], + [8.0, 9.0, 10.0, 11.0], + [12.0, 13.0, 14.0, 15.0]], dtype=np.float32) +sequence_lens = np.array([1, 2, 3, 4], dtype=np.int64) + +y = np.array([[0.0, 1.0, 2.0, 3.0], + [5.0, 4.0, 6.0, 7.0], + [10.0, 9.0, 8.0, 11.0], + [15.0, 14.0, 13.0, 12.0]], dtype=np.float32) + +expect(node, inputs=[x, sequence_lens], outputs=[y], + name='test_reversesequence_batch') +``` + +
+
+reversesequence_time + +```python +node = onnx.helper.make_node( + 'ReverseSequence', + inputs=['x', 'sequence_lens'], + outputs=['y'], + time_axis=0, + batch_axis=1, +) +x = np.array([[0.0, 4.0, 8.0, 12.0], + [1.0, 5.0, 9.0, 13.0], + [2.0, 6.0, 10.0, 14.0], + [3.0, 7.0, 11.0, 15.0]], dtype=np.float32) +sequence_lens = np.array([4, 3, 2, 1], dtype=np.int64) + +y = np.array([[3.0, 6.0, 9.0, 12.0], + [2.0, 5.0, 8.0, 13.0], + [1.0, 4.0, 10.0, 14.0], + [0.0, 7.0, 11.0, 15.0]], dtype=np.float32) + +expect(node, inputs=[x, sequence_lens], outputs=[y], + name='test_reversesequence_time') +``` + +
+ + +### RoiAlign +There are 2 test cases, listed as following: +
+roialign_aligned_false + +```python +node = onnx.helper.make_node( + "RoiAlign", + inputs=["X", "rois", "batch_indices"], + outputs=["Y"], + spatial_scale=1.0, + output_height=5, + output_width=5, + sampling_ratio=2, + coordinate_transformation_mode="output_half_pixel", +) + +X, batch_indices, rois = get_roi_align_input_values() +# (num_rois, C, output_height, output_width) +Y = np.array( + [ + [ + [ + [0.4664, 0.4466, 0.3405, 0.5688, 0.6068], + [0.3714, 0.4296, 0.3835, 0.5562, 0.3510], + [0.2768, 0.4883, 0.5222, 0.5528, 0.4171], + [0.4713, 0.4844, 0.6904, 0.4920, 0.8774], + [0.6239, 0.7125, 0.6289, 0.3355, 0.3495], + ] + ], + [ + [ + [0.3022, 0.4305, 0.4696, 0.3978, 0.5423], + [0.3656, 0.7050, 0.5165, 0.3172, 0.7015], + [0.2912, 0.5059, 0.6476, 0.6235, 0.8299], + [0.5916, 0.7389, 0.7048, 0.8372, 0.8893], + [0.6227, 0.6153, 0.7097, 0.6154, 0.4585], + ] + ], + [ + [ + [0.2384, 0.3379, 0.3717, 0.6100, 0.7601], + [0.3767, 0.3785, 0.7147, 0.9243, 0.9727], + [0.5749, 0.5826, 0.5709, 0.7619, 0.8770], + [0.5355, 0.2566, 0.2141, 0.2796, 0.3600], + [0.4365, 0.3504, 0.2887, 0.3661, 0.2349], + ] + ], + ], + dtype=np.float32, +) + +expect(node, inputs=[X, rois, batch_indices], outputs=[Y], name="test_roialign_aligned_false") +``` + +
+
+roialign_aligned_true + +```python +node = onnx.helper.make_node( + "RoiAlign", + inputs=["X", "rois", "batch_indices"], + outputs=["Y"], + spatial_scale=1.0, + output_height=5, + output_width=5, + sampling_ratio=2, + coordinate_transformation_mode="half_pixel", +) + +X, batch_indices, rois = get_roi_align_input_values() +# (num_rois, C, output_height, output_width) +Y = np.array( + [ + [ + [ + [0.5178, 0.3434, 0.3229, 0.4474, 0.6344], + [0.4031, 0.5366, 0.4428, 0.4861, 0.4023], + [0.2512, 0.4002, 0.5155, 0.6954, 0.3465], + [0.3350, 0.4601, 0.5881, 0.3439, 0.6849], + [0.4932, 0.7141, 0.8217, 0.4719, 0.4039], + ] + ], + [ + [ + [0.3070, 0.2187, 0.3337, 0.4880, 0.4870], + [0.1871, 0.4914, 0.5561, 0.4192, 0.3686], + [0.1433, 0.4608, 0.5971, 0.5310, 0.4982], + [0.2788, 0.4386, 0.6022, 0.7000, 0.7524], + [0.5774, 0.7024, 0.7251, 0.7338, 0.8163], + ] + ], + [ + [ + [0.2393, 0.4075, 0.3379, 0.2525, 0.4743], + [0.3671, 0.2702, 0.4105, 0.6419, 0.8308], + [0.5556, 0.4543, 0.5564, 0.7502, 0.9300], + [0.6626, 0.5617, 0.4813, 0.4954, 0.6663], + [0.6636, 0.3721, 0.2056, 0.1928, 0.2478], + ] + ], + ], + dtype=np.float32, +) + +expect(node, inputs=[X, rois, batch_indices], outputs=[Y], name="test_roialign_aligned_true") +``` + +
+ + +### Round +There are 1 test cases, listed as following: +
+round + +```python +node = onnx.helper.make_node( + 'Round', + inputs=['x'], + outputs=['y'], +) + +x = np.array([0.1, 0.5, 0.9, 1.2, 1.5, + 1.8, 2.3, 2.5, 2.7, -1.1, + -1.5, -1.9, -2.2, -2.5, -2.8]).astype(np.float32) +y = np.array([0., 0., 1., 1., 2., + 2., 2., 2., 3., -1., + -2., -2., -2., -2., -3.]).astype(np.float32) # expected output +expect(node, inputs=[x], outputs=[y], + name='test_round') +``` + +
+ + +### Scan +There are 2 test cases, listed as following: +
+scan_8 + +```python +# Given an input sequence [x1, ..., xN], sum up its elements using a scan +# returning the final state (x1+x2+...+xN) as well the scan_output +# [x1, x1+x2, ..., x1+x2+...+xN] +# +# create graph to represent scan body +sum_in = onnx.helper.make_tensor_value_info('sum_in', onnx.TensorProto.FLOAT, [2]) +next = onnx.helper.make_tensor_value_info('next', onnx.TensorProto.FLOAT, [2]) +sum_out = onnx.helper.make_tensor_value_info('sum_out', onnx.TensorProto.FLOAT, [2]) +scan_out = onnx.helper.make_tensor_value_info('scan_out', onnx.TensorProto.FLOAT, [2]) +add_node = onnx.helper.make_node( + 'Add', + inputs=['sum_in', 'next'], + outputs=['sum_out'] +) +id_node = onnx.helper.make_node( + 'Identity', + inputs=['sum_out'], + outputs=['scan_out'] +) +scan_body = onnx.helper.make_graph( + [add_node, id_node], + 'scan_body', + [sum_in, next], + [sum_out, scan_out] +) +# create scan op node +no_sequence_lens = '' # optional input, not supplied +node = onnx.helper.make_node( + 'Scan', + inputs=[no_sequence_lens, 'initial', 'x'], + outputs=['y', 'z'], + num_scan_inputs=1, + body=scan_body +) +# create inputs for batch-size 1, sequence-length 3, inner dimension 2 +initial = np.array([0, 0]).astype(np.float32).reshape((1, 2)) +x = np.array([1, 2, 3, 4, 5, 6]).astype(np.float32).reshape((1, 3, 2)) +# final state computed = [1 + 3 + 5, 2 + 4 + 6] +y = np.array([9, 12]).astype(np.float32).reshape((1, 2)) +# scan-output computed +z = np.array([1, 2, 4, 6, 9, 12]).astype(np.float32).reshape((1, 3, 2)) + +expect(node, inputs=[initial, x], outputs=[y, z], + name='test_scan_sum', opset_imports=[onnx.helper.make_opsetid("", 8)]) +``` + +
+
+scan_9 + +```python +# Given an input sequence [x1, ..., xN], sum up its elements using a scan +# returning the final state (x1+x2+...+xN) as well the scan_output +# [x1, x1+x2, ..., x1+x2+...+xN] +# +# create graph to represent scan body +sum_in = onnx.helper.make_tensor_value_info('sum_in', onnx.TensorProto.FLOAT, [2]) +next = onnx.helper.make_tensor_value_info('next', onnx.TensorProto.FLOAT, [2]) +sum_out = onnx.helper.make_tensor_value_info('sum_out', onnx.TensorProto.FLOAT, [2]) +scan_out = onnx.helper.make_tensor_value_info('scan_out', onnx.TensorProto.FLOAT, [2]) +add_node = onnx.helper.make_node( + 'Add', + inputs=['sum_in', 'next'], + outputs=['sum_out'] +) +id_node = onnx.helper.make_node( + 'Identity', + inputs=['sum_out'], + outputs=['scan_out'] +) +scan_body = onnx.helper.make_graph( + [add_node, id_node], + 'scan_body', + [sum_in, next], + [sum_out, scan_out] +) +# create scan op node +node = onnx.helper.make_node( + 'Scan', + inputs=['initial', 'x'], + outputs=['y', 'z'], + num_scan_inputs=1, + body=scan_body +) +# create inputs for sequence-length 3, inner dimension 2 +initial = np.array([0, 0]).astype(np.float32).reshape((2,)) +x = np.array([1, 2, 3, 4, 5, 6]).astype(np.float32).reshape((3, 2)) +# final state computed = [1 + 3 + 5, 2 + 4 + 6] +y = np.array([9, 12]).astype(np.float32).reshape((2,)) +# scan-output computed +z = np.array([1, 2, 4, 6, 9, 12]).astype(np.float32).reshape((3, 2)) + +expect(node, inputs=[initial, x], outputs=[y, z], + name='test_scan9_sum', opset_imports=[onnx.helper.make_opsetid("", 9)]) +``` + +
+ + +### Scatter +There are 2 test cases, listed as following: +
+scatter_with_axis + +```python +axis = 1 +node = onnx.helper.make_node( + 'Scatter', + inputs=['data', 'indices', 'updates'], + outputs=['y'], + axis=axis, +) +data = np.array([[1.0, 2.0, 3.0, 4.0, 5.0]], dtype=np.float32) +indices = np.array([[1, 3]], dtype=np.int64) +updates = np.array([[1.1, 2.1]], dtype=np.float32) + +y = scatter(data, indices, updates, axis=axis) +# print(y) produces +# [[1.0, 1.1, 3.0, 2.1, 5.0]] + +expect(node, inputs=[data, indices, updates], outputs=[y], + name='test_scatter_with_axis', opset_imports=[helper.make_opsetid("", 10)]) +``` + +
+
+scatter_without_axis + +```python +node = onnx.helper.make_node( + 'Scatter', + inputs=['data', 'indices', 'updates'], + outputs=['y'], +) +data = np.zeros((3, 3), dtype=np.float32) +indices = np.array([[1, 0, 2], [0, 2, 1]], dtype=np.int64) +updates = np.array([[1.0, 1.1, 1.2], [2.0, 2.1, 2.2]], dtype=np.float32) + +y = scatter(data, indices, updates) +# print(y) produces +# [[2.0, 1.1, 0.0], +# [1.0, 0.0, 2.2], +# [0.0, 2.1, 1.2]] + +expect(node, inputs=[data, indices, updates], outputs=[y], + name='test_scatter_without_axis', opset_imports=[helper.make_opsetid("", 10)]) +``` + +
+ + +### ScatterElements +There are 4 test cases, listed as following: +
+scatter_elements_with_axis + +```python +axis = 1 +node = onnx.helper.make_node( + 'ScatterElements', + inputs=['data', 'indices', 'updates'], + outputs=['y'], + axis=axis, +) +data = np.array([[1.0, 2.0, 3.0, 4.0, 5.0]], dtype=np.float32) +indices = np.array([[1, 3]], dtype=np.int64) +updates = np.array([[1.1, 2.1]], dtype=np.float32) + +y = scatter_elements(data, indices, updates, axis) +# print(y) produces +# [[1.0, 1.1, 3.0, 2.1, 5.0]] + +expect(node, inputs=[data, indices, updates], outputs=[y], + name='test_scatter_elements_with_axis') +``` + +
+
+scatter_elements_with_duplicate_indices + +```python +axis = 1 +node = onnx.helper.make_node( + 'ScatterElements', + inputs=['data', 'indices', 'updates'], + outputs=['y'], + axis=axis, + reduction='add', +) +data = np.array([[1.0, 2.0, 3.0, 4.0, 5.0]], dtype=np.float32) +indices = np.array([[1, 1]], dtype=np.int64) +updates = np.array([[1.1, 2.1]], dtype=np.float32) + +y = scatter_elements(data, indices, updates, axis, reduction='add') +# print(y) produces +# [[1.0, 5.2, 3.0, 4.0, 5.0]] + +expect(node, inputs=[data, indices, updates], outputs=[y], + name='test_scatter_elements_with_duplicate_indices') +``` + +
+
+scatter_elements_with_negative_indices + +```python +axis = 1 +node = onnx.helper.make_node( + 'ScatterElements', + inputs=['data', 'indices', 'updates'], + outputs=['y'], + axis=axis, +) +data = np.array([[1.0, 2.0, 3.0, 4.0, 5.0]], dtype=np.float32) +indices = np.array([[1, -3]], dtype=np.int64) +updates = np.array([[1.1, 2.1]], dtype=np.float32) + +y = scatter_elements(data, indices, updates, axis) +# print(y) produces +# [[1.0, 1.1, 2.1, 4.0, 5.0]] + +expect(node, inputs=[data, indices, updates], outputs=[y], + name='test_scatter_elements_with_negative_indices') +``` + +
+
+scatter_elements_without_axis + +```python +node = onnx.helper.make_node( + 'ScatterElements', + inputs=['data', 'indices', 'updates'], + outputs=['y'], +) +data = np.zeros((3, 3), dtype=np.float32) +indices = np.array([[1, 0, 2], [0, 2, 1]], dtype=np.int64) +updates = np.array([[1.0, 1.1, 1.2], [2.0, 2.1, 2.2]], dtype=np.float32) + +y = scatter_elements(data, indices, updates) +# print(y) produces +# [[2.0, 1.1, 0.0], +# [1.0, 0.0, 2.2], +# [0.0, 2.1, 1.2]] + +expect(node, inputs=[data, indices, updates], outputs=[y], + name='test_scatter_elements_without_axis') +``` + +
+ + +### ScatterND +There are 3 test cases, listed as following: +
+scatternd + +```python +node = onnx.helper.make_node( + 'ScatterND', + inputs=['data', 'indices', 'updates'], + outputs=['y'], +) +data = np.array( + [[[1, 2, 3, 4], [5, 6, 7, 8], [8, 7, 6, 5], [4, 3, 2, 1]], + [[1, 2, 3, 4], [5, 6, 7, 8], [8, 7, 6, 5], [4, 3, 2, 1]], + [[8, 7, 6, 5], [4, 3, 2, 1], [1, 2, 3, 4], [5, 6, 7, 8]], + [[8, 7, 6, 5], [4, 3, 2, 1], [1, 2, 3, 4], [5, 6, 7, 8]]], dtype=np.float32) +indices = np.array([[0], [2]], dtype=np.int64) +updates = np.array( + [[[5, 5, 5, 5], [6, 6, 6, 6], [7, 7, 7, 7], [8, 8, 8, 8]], + [[1, 1, 1, 1], [2, 2, 2, 2], [3, 3, 3, 3], [4, 4, 4, 4]]], dtype=np.float32) +# Expecting output as np.array( +# [[[5, 5, 5, 5], [6, 6, 6, 6], [7, 7, 7, 7], [8, 8, 8, 8]], +# [[1, 2, 3, 4], [5, 6, 7, 8], [8, 7, 6, 5], [4, 3, 2, 1]], +# [[1, 1, 1, 1], [2, 2, 2, 2], [3, 3, 3, 3], [4, 4, 4, 4]], +# [[8, 7, 6, 5], [4, 3, 2, 1], [1, 2, 3, 4], [5, 6, 7, 8]]], dtype=np.float32) +output = scatter_nd_impl(data, indices, updates) +expect(node, inputs=[data, indices, updates], outputs=[output], + name='test_scatternd') +``` + +
+
+scatternd_add + +```python +node = onnx.helper.make_node( + 'ScatterND', + inputs=['data', 'indices', 'updates'], + outputs=['y'], + reduction='add', +) +data = np.array( + [[[1, 2, 3, 4], [5, 6, 7, 8], [8, 7, 6, 5], [4, 3, 2, 1]], + [[1, 2, 3, 4], [5, 6, 7, 8], [8, 7, 6, 5], [4, 3, 2, 1]], + [[8, 7, 6, 5], [4, 3, 2, 1], [1, 2, 3, 4], [5, 6, 7, 8]], + [[8, 7, 6, 5], [4, 3, 2, 1], [1, 2, 3, 4], [5, 6, 7, 8]]], dtype=np.float32) +indices = np.array([[0], [0]], dtype=np.int64) +updates = np.array( + [[[5, 5, 5, 5], [6, 6, 6, 6], [7, 7, 7, 7], [8, 8, 8, 8]], + [[1, 1, 1, 1], [2, 2, 2, 2], [3, 3, 3, 3], [4, 4, 4, 4]]], dtype=np.float32) +# Expecting output as np.array( +# [[[7, 8, 9, 10], [13, 14, 15, 16], [18, 17, 16, 15], [16, 15, 14, 13]], +# [[1, 2, 3, 4], [5, 6, 7, 8], [8, 7, 6, 5], [4, 3, 2, 1]], +# [[1, 1, 1, 1], [2, 2, 2, 2], [3, 3, 3, 3], [4, 4, 4, 4]], +# [[8, 7, 6, 5], [4, 3, 2, 1], [1, 2, 3, 4], [5, 6, 7, 8]]], dtype=np.float32) +output = scatter_nd_impl(data, indices, updates, reduction='add') +expect(node, inputs=[data, indices, updates], outputs=[output], + name='test_scatternd_add') +``` + +
+
+scatternd_multiply + +```python +node = onnx.helper.make_node( + 'ScatterND', + inputs=['data', 'indices', 'updates'], + outputs=['y'], + reduction='mul', +) +data = np.array( + [[[1, 2, 3, 4], [5, 6, 7, 8], [8, 7, 6, 5], [4, 3, 2, 1]], + [[1, 2, 3, 4], [5, 6, 7, 8], [8, 7, 6, 5], [4, 3, 2, 1]], + [[8, 7, 6, 5], [4, 3, 2, 1], [1, 2, 3, 4], [5, 6, 7, 8]], + [[8, 7, 6, 5], [4, 3, 2, 1], [1, 2, 3, 4], [5, 6, 7, 8]]], dtype=np.float32) +indices = np.array([[0], [0]], dtype=np.int64) +updates = np.array( + [[[5, 5, 5, 5], [6, 6, 6, 6], [7, 7, 7, 7], [8, 8, 8, 8]], + [[1, 1, 1, 1], [2, 2, 2, 2], [3, 3, 3, 3], [4, 4, 4, 4]]], dtype=np.float32) +# Expecting output as np.array( +# [[[5, 10, 15, 20], [60, 72, 84, 96], [168, 147, 126, 105], [128, 96, 64, 32]], +# [[1, 2, 3, 4], [5, 6, 7, 8], [8, 7, 6, 5], [4, 3, 2, 1]], +# [[1, 1, 1, 1], [2, 2, 2, 2], [3, 3, 3, 3], [4, 4, 4, 4]], +# [[8, 7, 6, 5], [4, 3, 2, 1], [1, 2, 3, 4], [5, 6, 7, 8]]], dtype=np.float32) +output = scatter_nd_impl(data, indices, updates, reduction='mul') +expect(node, inputs=[data, indices, updates], outputs=[output], + name='test_scatternd_multiply') +``` + +
+ + +### Selu +There are 2 test cases, listed as following: +
+selu + +```python +node = onnx.helper.make_node( + 'Selu', + inputs=['x'], + outputs=['y'], + alpha=2.0, + gamma=3.0 +) + +x = np.array([-1, 0, 1]).astype(np.float32) +# expected output [-3.79272318, 0., 3.] +y = np.clip(x, 0, np.inf) * 3.0 + (np.exp(np.clip(x, -np.inf, 0)) - 1) * 2.0 * 3.0 +expect(node, inputs=[x], outputs=[y], + name='test_selu_example') + +x = np.random.randn(3, 4, 5).astype(np.float32) +y = np.clip(x, 0, np.inf) * 3.0 + (np.exp(np.clip(x, -np.inf, 0)) - 1) * 2.0 * 3.0 +expect(node, inputs=[x], outputs=[y], + name='test_selu') +``` + +
+
+selu_default + +```python +default_alpha = 1.67326319217681884765625 +default_gamma = 1.05070102214813232421875 +node = onnx.helper.make_node( + 'Selu', + inputs=['x'], + outputs=['y'], +) +x = np.random.randn(3, 4, 5).astype(np.float32) +y = np.clip(x, 0, np.inf) * default_gamma + \ + (np.exp(np.clip(x, -np.inf, 0)) - 1) * default_alpha * default_gamma +expect(node, inputs=[x], outputs=[y], + name='test_selu_default') +``` + +
+ + +### SequenceInsert +There are 1 test cases, listed as following: +
+sequenceinsert + +```python +test_cases = { + 'at_back': [np.array([10, 11, 12]).astype(np.int64)], + 'at_front': [np.array([-2, -1, 0]), np.array([0]).astype(np.int64)] +} +sequence = [np.array([1, 2, 3, 4]).astype(np.int64), np.array([5, 6, 7]).astype(np.int64), np.array([8, 9]).astype(np.int64)] + +for test_name, test_inputs in test_cases.items(): + tensor = test_inputs[0].astype(np.int64) + + if len(test_inputs) > 1: + node = onnx.helper.make_node( + 'SequenceInsert', + inputs=['sequence', 'tensor', 'position'], + outputs=['output_sequence'] + ) + position = test_inputs[1] + inserted = sequence_insert_reference_implementation(sequence, tensor, position) + expect(node, inputs=[sequence, tensor, position], outputs=[inserted], + name='test_sequence_insert_' + test_name) + else: + node = onnx.helper.make_node( + 'SequenceInsert', + inputs=['sequence', 'tensor'], + outputs=['output_sequence'] + ) + inserted = sequence_insert_reference_implementation(sequence, tensor) + expect(node, inputs=[sequence, tensor], outputs=[inserted], + name='test_sequence_insert_' + test_name) +``` + +
+ + +### Shape +There are 1 test cases, listed as following: +
+shape + +```python +x = np.array([ + [1, 2, 3], + [4, 5, 6], +]).astype(np.float32) +test_shape('_example', x) # preserve names of original test cases + +x = np.random.randn(3, 4, 5).astype(np.float32) + +test_shape('', x) # preserve names of original test cases + +test_shape('_start_1', x, start=1) + +test_shape('_end_1', x, end=1) + +test_shape('_start_negative_1', x, start=-1) + +test_shape('_end_negative_1', x, end=-1) + +test_shape('_start_1_end_negative_1', x, start=1, end=-1) + +test_shape('_start_1_end_2', x, start=1, end=2) + +test_shape('_clip_start', x, start=-10) + +test_shape('_clip_end', x, end=10) +``` + +
+ + +### Shrink +There are 2 test cases, listed as following: +
+hard_shrink + +```python +node = onnx.helper.make_node( + 'Shrink', + inputs=['x'], + outputs=['y'], + lambd=1.5, +) +X = np.arange(-2.0, 2.1, dtype=np.float32) +Y = np.array([-2, 0, 0, 0, 2], dtype=np.float32) +expect(node, inputs=[X], outputs=[Y], + name='test_shrink_hard') +``` + +
+
+soft_shrink + +```python +node = onnx.helper.make_node( + 'Shrink', + inputs=['x'], + outputs=['y'], + lambd=1.5, + bias=1.5, +) +X = np.arange(-2.0, 2.1, dtype=np.float32) +Y = np.array([-0.5, 0, 0, 0, 0.5], dtype=np.float32) +expect(node, inputs=[X], outputs=[Y], + name='test_shrink_soft') +``` + +
+ + +### Sigmoid +There are 1 test cases, listed as following: +
+sigmoid + +```python +node = onnx.helper.make_node( + 'Sigmoid', + inputs=['x'], + outputs=['y'], +) + +x = np.array([-1, 0, 1]).astype(np.float32) +y = 1.0 / (1.0 + np.exp(np.negative(x))) # expected output [0.26894143, 0.5, 0.7310586] +expect(node, inputs=[x], outputs=[y], + name='test_sigmoid_example') + +x = np.random.randn(3, 4, 5).astype(np.float32) +y = 1.0 / (1.0 + np.exp(np.negative(x))) +expect(node, inputs=[x], outputs=[y], + name='test_sigmoid') +``` + +
+ + +### Sign +There are 1 test cases, listed as following: +
+sign + +```python +node = onnx.helper.make_node( + 'Sign', + inputs=['x'], + outputs=['y'], +) + +x = np.array(range(-5, 6)).astype(np.float32) +y = np.sign(x) +expect(node, inputs=[x], outputs=[y], + name='test_sign') +``` + +
+ + +### Sin +There are 1 test cases, listed as following: +
+sin + +```python +node = onnx.helper.make_node( + 'Sin', + inputs=['x'], + outputs=['y'], +) + +x = np.array([-1, 0, 1]).astype(np.float32) +y = np.sin(x) +expect(node, inputs=[x], outputs=[y], + name='test_sin_example') + +x = np.random.randn(3, 4, 5).astype(np.float32) +y = np.sin(x) +expect(node, inputs=[x], outputs=[y], + name='test_sin') +``` + +
+ + +### Sinh +There are 1 test cases, listed as following: +
+sinh + +```python +node = onnx.helper.make_node( + 'Sinh', + inputs=['x'], + outputs=['y'], +) + +x = np.array([-1, 0, 1]).astype(np.float32) +y = np.sinh(x) # expected output [-1.17520118, 0., 1.17520118] +expect(node, inputs=[x], outputs=[y], + name='test_sinh_example') + +x = np.random.randn(3, 4, 5).astype(np.float32) +y = np.sinh(x) +expect(node, inputs=[x], outputs=[y], + name='test_sinh') +``` + +
+ + +### Size +There are 1 test cases, listed as following: +
+size + +```python +node = onnx.helper.make_node( + 'Size', + inputs=['x'], + outputs=['y'], +) + +x = np.array([ + [1, 2, 3], + [4, 5, 6], +]).astype(np.float32) +y = np.array(6).astype(np.int64) + +expect(node, inputs=[x], outputs=[y], + name='test_size_example') + +x = np.random.randn(3, 4, 5).astype(np.float32) +y = np.array(x.size).astype(np.int64) + +expect(node, inputs=[x], outputs=[y], + name='test_size') +``` + +
+ + +### Slice +There are 8 test cases, listed as following: +
+slice + +```python +node = onnx.helper.make_node( + 'Slice', + inputs=['x', 'starts', 'ends', 'axes', 'steps'], + outputs=['y'], +) + +x = np.random.randn(20, 10, 5).astype(np.float32) +y = x[0:3, 0:10] +starts = np.array([0, 0], dtype=np.int64) +ends = np.array([3, 10], dtype=np.int64) +axes = np.array([0, 1], dtype=np.int64) +steps = np.array([1, 1], dtype=np.int64) + +expect(node, inputs=[x, starts, ends, axes, steps], outputs=[y], + name='test_slice') +``` + +
+
+slice_default_axes + +```python +node = onnx.helper.make_node( + 'Slice', + inputs=['x', 'starts', 'ends'], + outputs=['y'], +) + +x = np.random.randn(20, 10, 5).astype(np.float32) +starts = np.array([0, 0, 3], dtype=np.int64) +ends = np.array([20, 10, 4], dtype=np.int64) +y = x[:, :, 3:4] + +expect(node, inputs=[x, starts, ends], outputs=[y], + name='test_slice_default_axes') +``` + +
+
+slice_default_steps + +```python +node = onnx.helper.make_node( + 'Slice', + inputs=['x', 'starts', 'ends', 'axes'], + outputs=['y'], +) + +x = np.random.randn(20, 10, 5).astype(np.float32) +starts = np.array([0, 0, 3], dtype=np.int64) +ends = np.array([20, 10, 4], dtype=np.int64) +axes = np.array([0, 1, 2], dtype=np.int64) +y = x[:, :, 3:4] + +expect(node, inputs=[x, starts, ends, axes], outputs=[y], + name='test_slice_default_steps') +``` + +
+
+slice_end_out_of_bounds + +```python +node = onnx.helper.make_node( + 'Slice', + inputs=['x', 'starts', 'ends', 'axes', 'steps'], + outputs=['y'], +) + +x = np.random.randn(20, 10, 5).astype(np.float32) +starts = np.array([1], dtype=np.int64) +ends = np.array([1000], dtype=np.int64) +axes = np.array([1], dtype=np.int64) +steps = np.array([1], dtype=np.int64) +y = x[:, 1:1000] + +expect(node, inputs=[x, starts, ends, axes, steps], outputs=[y], + name='test_slice_end_out_of_bounds') +``` + +
+
+slice_neg + +```python +node = onnx.helper.make_node( + 'Slice', + inputs=['x', 'starts', 'ends', 'axes', 'steps'], + outputs=['y'], +) + +x = np.random.randn(20, 10, 5).astype(np.float32) +starts = np.array([0], dtype=np.int64) +ends = np.array([-1], dtype=np.int64) +axes = np.array([1], dtype=np.int64) +steps = np.array([1], dtype=np.int64) +y = x[:, 0:-1] + +expect(node, inputs=[x, starts, ends, axes, steps], outputs=[y], + name='test_slice_neg') +``` + +
+
+slice_neg_steps + +```python +node = onnx.helper.make_node( + 'Slice', + inputs=['x', 'starts', 'ends', 'axes', 'steps'], + outputs=['y'], +) + +x = np.random.randn(20, 10, 5).astype(np.float32) +starts = np.array([20, 10, 4], dtype=np.int64) +ends = np.array([0, 0, 1], dtype=np.int64) +axes = np.array([0, 1, 2], dtype=np.int64) +steps = np.array([-1, -3, -2]).astype(np.int64) +y = x[20:0:-1, 10:0:-3, 4:1:-2] + +expect(node, inputs=[x, starts, ends, axes, steps], outputs=[y], + name='test_slice_neg_steps') +``` + +
+
+slice_negative_axes + +```python +node = onnx.helper.make_node( + 'Slice', + inputs=['x', 'starts', 'ends', 'axes'], + outputs=['y'], +) + +x = np.random.randn(20, 10, 5).astype(np.float32) +starts = np.array([0, 0, 3], dtype=np.int64) +ends = np.array([20, 10, 4], dtype=np.int64) +axes = np.array([0, -2, -1], dtype=np.int64) +y = x[:, :, 3:4] + +expect(node, inputs=[x, starts, ends, axes], outputs=[y], + name='test_slice_negative_axes') +``` + +
+
+slice_start_out_of_bounds + +```python +node = onnx.helper.make_node( + 'Slice', + inputs=['x', 'starts', 'ends', 'axes', 'steps'], + outputs=['y'], +) + +x = np.random.randn(20, 10, 5).astype(np.float32) +starts = np.array([1000], dtype=np.int64) +ends = np.array([1000], dtype=np.int64) +axes = np.array([1], dtype=np.int64) +steps = np.array([1], dtype=np.int64) +y = x[:, 1000:1000] + +expect(node, inputs=[x, starts, ends, axes, steps], outputs=[y], + name='test_slice_start_out_of_bounds') +``` + +
+ + +### Softmax +There are 2 test cases, listed as following: +
+softmax + +```python +node = onnx.helper.make_node( + 'Softmax', + inputs=['x'], + outputs=['y'], +) +x = np.array([[-1, 0, 1]]).astype(np.float32) +# expected output [[0.09003058, 0.24472848, 0.66524094]] +y = softmax(x, axis=1) +expect(node, inputs=[x], outputs=[y], + name='test_softmax_example') +``` + +
+
+softmax_axis + +```python +x = np.array([[0, 1, 2, 3], [10000, 10001, 10002, 10003]] + ).astype(np.float32) +# expected output +# [[0.032058604 0.08714432 0.23688284 0.6439143 ] +# [0.032058604 0.08714432 0.23688284 0.6439143 ]] +y = softmax(x) + +node = onnx.helper.make_node( + 'Softmax', + inputs=['x'], + outputs=['y'], +) +expect(node, inputs=[x], outputs=[y], + name='test_softmax_large_number') + +x = np.abs(np.random.randn(3, 4, 5).astype(np.float32)) +node = onnx.helper.make_node( + 'Softmax', + inputs=['x'], + outputs=['y'], + axis=0, +) +y = softmax(x, axis=0) +expect(node, inputs=[x], outputs=[y], + name='test_softmax_axis_0') + +node = onnx.helper.make_node( + 'Softmax', + inputs=['x'], + outputs=['y'], + axis=1, +) +y = softmax(x, axis=1) +expect(node, inputs=[x], outputs=[y], + name='test_softmax_axis_1') + +node = onnx.helper.make_node( + 'Softmax', + inputs=['x'], + outputs=['y'], + axis=2, +) +y = softmax(x, axis=2) +expect(node, inputs=[x], outputs=[y], + name='test_softmax_axis_2') + +node = onnx.helper.make_node( + 'Softmax', + inputs=['x'], + outputs=['y'], + axis=-1, +) +y = softmax(x, axis=-1) +expect(node, inputs=[x], outputs=[y], + name='test_softmax_negative_axis') + +# default axis is -1 +node = onnx.helper.make_node( + 'Softmax', + inputs=['x'], + outputs=['y'], +) +expect(node, inputs=[x], outputs=[y], + name='test_softmax_default_axis') +``` + +
+ + +### SoftmaxCrossEntropyLoss +There are 34 test cases, listed as following: +
+input_shape_is_NCd1_mean_weight_negative_ii + +```python +reduction = 'mean' +ignore_index = np.int64(-1) + +node = onnx.helper.make_node('SoftmaxCrossEntropyLoss', + inputs=['x', 'y', 'w'], + outputs=['z'], + reduction=reduction, + ignore_index=ignore_index) + +N, C, dim1 = 3, 5, 6 +np.random.seed(0) +x = np.random.rand(N, C, dim1).astype(np.float32) +labels = np.random.randint(0, high=C, size=(N, dim1)).astype(np.int64) +labels[0][0] = -1 +weight = np.random.rand(C).astype(np.float32) + +sce = softmaxcrossentropy(x, + labels, + weight=weight, + reduction=reduction, + ignore_index=ignore_index) + +expect(node, inputs=[x, labels, weight], outputs=[sce], name='test_sce_NCd1_mean_weight_negative_ii') +``` + +
+
+input_shape_is_NCd1_mean_weight_negative_ii_log_prob + +```python +reduction = 'mean' +ignore_index = np.int64(-1) + +node = onnx.helper.make_node('SoftmaxCrossEntropyLoss', + inputs=['x', 'y', 'w'], + outputs=['z', 'log_prob'], + reduction=reduction, + ignore_index=ignore_index) + +N, C, dim1 = 3, 5, 6 +np.random.seed(0) +x = np.random.rand(N, C, dim1).astype(np.float32) +labels = np.random.randint(0, high=C, size=(N, dim1)).astype(np.int64) +labels[0][0] = -1 +weight = np.random.rand(C).astype(np.float32) + +loss, log_prob = softmaxcrossentropy(x, + labels, + weight=weight, + reduction=reduction, + ignore_index=ignore_index, + get_log_prob=True) + +expect(node, inputs=[x, labels, weight], outputs=[loss, log_prob], name='test_sce_NCd1_mean_weight_negative_ii_log_prob') +``` + +
+
+input_shape_is_NCd1d2d3_none_no_weight_negative_ii + +```python +reduction = 'none' +ignore_index = np.int64(-5) + +node = onnx.helper.make_node('SoftmaxCrossEntropyLoss', + inputs=['x', 'y'], + outputs=['z'], + reduction=reduction, + ignore_index=ignore_index) + +N, C, dim1, dim2, dim3 = 3, 5, 6, 6, 5 +np.random.seed(0) +x = np.random.rand(N, C, dim1, dim2, dim3).astype(np.float32) +labels = np.random.randint(0, high=C, size=(N, dim1, dim2, dim3)).astype(np.int64) +labels[0][0][0][0] = -5 + +sce = softmaxcrossentropy(x, + labels, + reduction=reduction, + ignore_index=ignore_index) + +expect(node, inputs=[x, labels], outputs=[sce], name='test_sce_NCd1d2d3_none_no_weight_negative_ii') +``` + +
+
+input_shape_is_NCd1d2d3_none_no_weight_negative_ii_log_prob + +```python +reduction = 'none' +ignore_index = np.int64(-5) + +node = onnx.helper.make_node('SoftmaxCrossEntropyLoss', + inputs=['x', 'y'], + outputs=['z', 'log_prob'], + reduction=reduction, + ignore_index=ignore_index) + +N, C, dim1, dim2, dim3 = 3, 5, 6, 6, 5 +np.random.seed(0) +x = np.random.rand(N, C, dim1, dim2, dim3).astype(np.float32) +labels = np.random.randint(0, high=C, size=(N, dim1, dim2, dim3)).astype(np.int64) +labels[0][0][0][0] = -5 + +loss, log_prob = softmaxcrossentropy(x, + labels, + reduction=reduction, + ignore_index=ignore_index, + get_log_prob=True) + +expect(node, inputs=[x, labels], outputs=[loss, log_prob], name='test_sce_NCd1d2d3_none_no_weight_negative_ii_log_prob') +``` + +
+
+input_shape_is_NCd1d2d3_sum_weight_high_ii + +```python +reduction = 'sum' +ignore_index = np.int64(10) + +node = onnx.helper.make_node('SoftmaxCrossEntropyLoss', + inputs=['x', 'y', 'w'], + outputs=['z'], + reduction=reduction, + ignore_index=ignore_index) + +N, C = 3, 5 +np.random.seed(0) +x = np.random.rand(N, C).astype(np.float32) +labels = np.random.randint(0, high=C, size=(N)).astype(np.int64) +labels[0] = 10 +weight = np.random.rand(C).astype(np.float32) + +sce = softmaxcrossentropy(x, + labels, + weight=weight, + reduction=reduction, + ignore_index=ignore_index) + +expect(node, inputs=[x, labels, weight], outputs=[sce], name='test_sce_NCd1d2d3_sum_weight_high_ii') +``` + +
+
+input_shape_is_NCd1d2d3_sum_weight_high_ii_log_prob + +```python +reduction = 'sum' +ignore_index = np.int64(10) + +node = onnx.helper.make_node('SoftmaxCrossEntropyLoss', + inputs=['x', 'y', 'w'], + outputs=['z', 'log_prob'], + reduction=reduction, + ignore_index=ignore_index) + +N, C = 3, 5 +np.random.seed(0) +x = np.random.rand(N, C).astype(np.float32) +labels = np.random.randint(0, high=C, size=(N)).astype(np.int64) +labels[0] = 10 +weight = np.random.rand(C).astype(np.float32) + +loss, log_prob = softmaxcrossentropy(x, + labels, + weight=weight, + reduction=reduction, + ignore_index=ignore_index, + get_log_prob=True) + +expect(node, inputs=[x, labels, weight], outputs=[loss, log_prob], name='test_sce_NCd1d2d3_sum_weight_high_ii_log_prob') +``` + +
+
+input_shape_is_NCd1d2d3d4d5_mean_weight + +```python +reduction = 'mean' + +node = onnx.helper.make_node('SoftmaxCrossEntropyLoss', + inputs=['x', 'y', 'w'], + outputs=['z'], + reduction=reduction) + +N, C, dim1, dim2, dim3, dim4, dim5 = 3, 5, 6, 6, 5, 3, 4 +np.random.seed(0) +x = np.random.rand(N, C, dim1, dim2, dim3, dim4, dim5).astype(np.float32) +labels = np.random.randint(0, high=C, size=(N, dim1, dim2, dim3, dim4, dim5)).astype(np.int64) +weight = np.random.rand(C).astype(np.float32) + +sce = softmaxcrossentropy(x, + labels, + weight=weight, + reduction=reduction) + +expect(node, inputs=[x, labels, weight], outputs=[sce], name='test_sce_NCd1d2d3d4d5_mean_weight') +``` + +
+
+input_shape_is_NCd1d2d3d4d5_mean_weight_log_prob + +```python +reduction = 'mean' + +node = onnx.helper.make_node('SoftmaxCrossEntropyLoss', + inputs=['x', 'y', 'w'], + outputs=['z', 'log_prob'], + reduction=reduction) + +N, C, dim1, dim2, dim3, dim4, dim5 = 3, 5, 6, 6, 5, 3, 4 +np.random.seed(0) +x = np.random.rand(N, C, dim1, dim2, dim3, dim4, dim5).astype(np.float32) +labels = np.random.randint(0, high=C, size=(N, dim1, dim2, dim3, dim4, dim5)).astype(np.int64) +weight = np.random.rand(C).astype(np.float32) + +loss, log_prob = softmaxcrossentropy(x, + labels, + weight=weight, + reduction=reduction, + get_log_prob=True) + +expect(node, inputs=[x, labels, weight], outputs=[loss, log_prob], name='test_sce_NCd1d2d3d4d5_mean_weight_log_prob') +``` + +
+
+input_shape_is_NCd1d2d3d4d5_none_no_weight + +```python +reduction = 'none' + +node = onnx.helper.make_node('SoftmaxCrossEntropyLoss', + inputs=['x', 'y'], + outputs=['z'], + reduction=reduction) + +N, C, dim1, dim2, dim3, dim4, dim5 = 3, 5, 6, 6, 5, 3, 4 +np.random.seed(0) +x = np.random.rand(N, C, dim1, dim2, dim3, dim4, dim5).astype(np.float32) +labels = np.random.randint(0, high=C, size=(N, dim1, dim2, dim3, dim4, dim5)).astype(np.int64) + +sce = softmaxcrossentropy(x, + labels, + reduction=reduction) + +expect(node, inputs=[x, labels], outputs=[sce], name='test_sce_NCd1d2d3d4d5_none_no_weight') +``` + +
+
+input_shape_is_NCd1d2d3d4d5_none_no_weight_log_prob + +```python +reduction = 'none' + +node = onnx.helper.make_node('SoftmaxCrossEntropyLoss', + inputs=['x', 'y'], + outputs=['z', 'log_prob'], + reduction=reduction) + +N, C, dim1, dim2, dim3, dim4, dim5 = 3, 5, 6, 6, 5, 3, 4 +np.random.seed(0) +x = np.random.rand(N, C, dim1, dim2, dim3, dim4, dim5).astype(np.float32) +labels = np.random.randint(0, high=C, size=(N, dim1, dim2, dim3, dim4, dim5)).astype(np.int64) + +loss, log_prob = softmaxcrossentropy(x, + labels, + reduction=reduction, + get_log_prob=True) + +expect(node, inputs=[x, labels], outputs=[loss, log_prob], name='test_sce_NCd1d2d3d4d5_none_no_weight_log_prob') +``` + +
+
+softmaxcrossentropy_mean + +```python +# Define operator attributes. +reduction = 'mean' + +# Create operator. +node = onnx.helper.make_node('SoftmaxCrossEntropyLoss', + inputs=['x', 'y'], + outputs=['z'], + reduction=reduction) + +# Define operator inputs. +np.random.seed(0) +x = np.random.rand(3, 5).astype(np.float32) +labels = np.random.randint(0, high=5, size=(3, )).astype(np.int64) + +# Compute SoftmaxCrossEntropyLoss +sce = softmaxcrossentropy(x, labels) + +# Check results +expect(node, inputs=[x, labels], outputs=[sce], name='test_sce_mean') +``` + +
+
+softmaxcrossentropy_mean_3d + +```python +# Define operator attributes. +reduction = 'mean' + +# Create operator. +node = onnx.helper.make_node('SoftmaxCrossEntropyLoss', + inputs=['x', 'y'], + outputs=['z'], + reduction=reduction) + +# Define operator inputs. +np.random.seed(0) +x = np.random.rand(3, 5, 2).astype(np.float32) +y = np.random.randint(0, high=5, size=(3, 2)).astype(np.int64) + +# Compute SoftmaxCrossEntropyLoss +sce = softmaxcrossentropy(x, y) + +# Check results +expect(node, inputs=[x, y], outputs=[sce], name='test_sce_mean_3d') +``` + +
+
+softmaxcrossentropy_mean_3d_log_prob + +```python +# Define operator attributes. +reduction = 'mean' + +# Create operator. +node = onnx.helper.make_node('SoftmaxCrossEntropyLoss', + inputs=['x', 'y'], + outputs=['z', 'log_prob'], + reduction=reduction) + +# Define operator inputs. +np.random.seed(0) +x = np.random.rand(3, 5, 2).astype(np.float32) +y = np.random.randint(0, high=5, size=(3, 2)).astype(np.int64) + +# Compute SoftmaxCrossEntropyLoss +loss, log_prob = softmaxcrossentropy(x, y, get_log_prob=True) + +# Check results +expect(node, inputs=[x, y], outputs=[loss, log_prob], name='test_sce_mean_3d_log_prob') +``` + +
+
+softmaxcrossentropy_mean_log_prob + +```python +# Define operator attributes. +reduction = 'mean' + +# Create operator. +node = onnx.helper.make_node('SoftmaxCrossEntropyLoss', + inputs=['x', 'y'], + outputs=['z', 'log_prob'], + reduction=reduction) + +# Define operator inputs. +np.random.seed(0) +x = np.random.rand(3, 5).astype(np.float32) +labels = np.random.randint(0, high=5, size=(3, )).astype(np.int64) + +# Compute SoftmaxCrossEntropyLoss +loss, log_prob = softmaxcrossentropy(x, labels, get_log_prob=True) + +# Check results +expect(node, inputs=[x, labels], outputs=[loss, log_prob], name='test_sce_mean_log_prob') +``` + +
+
+softmaxcrossentropy_mean_no_weights_ii + +```python +# Define operator attributes. +reduction = 'mean' +ignore_index = np.int64(2) + +# Create operator. +node = onnx.helper.make_node('SoftmaxCrossEntropyLoss', + inputs=['x', 'y'], + outputs=['z'], + reduction=reduction, + ignore_index=ignore_index) + +# Define operator inputs. +np.random.seed(0) +x = np.random.rand(3, 5).astype(np.float32) +labels = np.random.randint(0, high=5, size=(3, )).astype(np.int64) +labels[0] = np.int64(2) + +# Compute SoftmaxCrossEntropyLoss +sce = softmaxcrossentropy(x, labels, ignore_index=ignore_index) + +# Check results +expect(node, inputs=[x, labels], outputs=[sce], name='test_sce_mean_no_weight_ii') +``` + +
+
+softmaxcrossentropy_mean_no_weights_ii_3d + +```python +# Define operator attributes. +reduction = 'mean' +ignore_index = np.int64(2) + +# Create operator. +node = onnx.helper.make_node('SoftmaxCrossEntropyLoss', + inputs=['x', 'y'], + outputs=['z'], + reduction=reduction, + ignore_index=ignore_index) + +# Define operator inputs. +np.random.seed(0) +x = np.random.rand(3, 5, 2).astype(np.float32) +labels = np.random.randint(0, high=5, size=(3, 2)).astype(np.int64) +labels[0][0] = np.int64(2) + +# Compute SoftmaxCrossEntropyLoss +sce = softmaxcrossentropy(x, labels, ignore_index=ignore_index) + +# Check results +expect(node, inputs=[x, labels], outputs=[sce], name='test_sce_mean_no_weight_ii_3d') +``` + +
+
+softmaxcrossentropy_mean_no_weights_ii_3d_log_prob + +```python +# Define operator attributes. +reduction = 'mean' +ignore_index = np.int64(2) + +# Create operator. +node = onnx.helper.make_node('SoftmaxCrossEntropyLoss', + inputs=['x', 'y'], + outputs=['z', 'log_prob'], + reduction=reduction, + ignore_index=ignore_index) + +# Define operator inputs. +np.random.seed(0) +x = np.random.rand(3, 5, 2).astype(np.float32) +labels = np.random.randint(0, high=5, size=(3, 2)).astype(np.int64) +labels[0][0] = np.int64(2) + +# Compute SoftmaxCrossEntropyLoss +loss, log_prob = softmaxcrossentropy(x, labels, ignore_index=ignore_index, get_log_prob=True) + +# Check results +expect(node, inputs=[x, labels], outputs=[loss, log_prob], name='test_sce_mean_no_weight_ii_3d_log_prob') +``` + +
+
+softmaxcrossentropy_mean_no_weights_ii_4d + +```python +# Define operator attributes. +reduction = 'mean' +ignore_index = np.int64(2) + +# Create operator. +node = onnx.helper.make_node('SoftmaxCrossEntropyLoss', + inputs=['x', 'y'], + outputs=['z'], + reduction=reduction, + ignore_index=ignore_index) + +# Define operator inputs. +np.random.seed(0) +x = np.random.rand(3, 5, 2, 7).astype(np.float32) +labels = np.random.randint(0, high=5, size=(3, 2, 7)).astype(np.int64) +labels[0][0][0] = np.int64(2) + +# Compute SoftmaxCrossEntropyLoss +sce = softmaxcrossentropy(x, labels, reduction=reduction, ignore_index=ignore_index) + +# Check results +expect(node, inputs=[x, labels], outputs=[sce], name='test_sce_mean_no_weight_ii_4d') +``` + +
+
+softmaxcrossentropy_mean_no_weights_ii_4d_log_prob + +```python +# Define operator attributes. +reduction = 'mean' +ignore_index = np.int64(2) + +# Create operator. +node = onnx.helper.make_node('SoftmaxCrossEntropyLoss', + inputs=['x', 'y'], + outputs=['z', 'log_prob'], + reduction=reduction, + ignore_index=ignore_index) + +# Define operator inputs. +np.random.seed(0) +x = np.random.rand(3, 5, 2, 7).astype(np.float32) +labels = np.random.randint(0, high=5, size=(3, 2, 7)).astype(np.int64) +labels[0][0][0] = np.int64(2) + +# Compute SoftmaxCrossEntropyLoss +loss, log_prob = softmaxcrossentropy(x, labels, reduction=reduction, ignore_index=ignore_index, get_log_prob=True) + +# Check results +expect(node, inputs=[x, labels], outputs=[loss, log_prob], name='test_sce_mean_no_weight_ii_4d_log_prob') +``` + +
+
+softmaxcrossentropy_mean_no_weights_ii_log_prob + +```python +# Define operator attributes. +reduction = 'mean' +ignore_index = np.int64(2) + +# Create operator. +node = onnx.helper.make_node('SoftmaxCrossEntropyLoss', + inputs=['x', 'y'], + outputs=['z', 'log_prob'], + reduction=reduction, + ignore_index=ignore_index) + +# Define operator inputs. +np.random.seed(0) +x = np.random.rand(3, 5).astype(np.float32) +labels = np.random.randint(0, high=5, size=(3, )).astype(np.int64) +labels[0] = np.int64(2) + +# Compute SoftmaxCrossEntropyLoss +loss, log_prob = softmaxcrossentropy(x, labels, ignore_index=ignore_index, get_log_prob=True) + +# Check results +expect(node, inputs=[x, labels], outputs=[loss, log_prob], name='test_sce_mean_no_weight_ii_log_prob') +``` + +
+
+softmaxcrossentropy_mean_weights + +```python +# Define operator attributes. +reduction = 'mean' + +# Create operator. +node = onnx.helper.make_node('SoftmaxCrossEntropyLoss', + inputs=['x', 'y', 'w'], + outputs=['z'], + reduction=reduction) + +# Define operator inputs. +np.random.seed(0) +x = np.random.rand(3, 5).astype(np.float32) +labels = np.random.randint(0, high=5, size=(3, )).astype(np.int64) +weights = np.array([0.9, 0.7, 0.8, 0.9, 0.9], dtype=np.float32) + +# Compute SoftmaxCrossEntropyLoss +sce = softmaxcrossentropy(x, labels, weight=weights) + +# Check results +expect(node, inputs=[x, labels, weights], outputs=[sce], name='test_sce_mean_weight') +``` + +
+
+softmaxcrossentropy_mean_weights_ii + +```python +# Define operator attributes. +reduction = 'mean' +ignore_index = np.int64(0) + +# Create operator. +node = onnx.helper.make_node('SoftmaxCrossEntropyLoss', + inputs=['x', 'y', 'w'], + outputs=['z'], + reduction=reduction, + ignore_index=ignore_index) + +# Define operator inputs. +np.random.seed(0) +x = np.random.rand(3, 5).astype(np.float32) +labels = np.random.randint(0, high=5, size=(3, )).astype(np.int64) +labels[0] = np.int64(0) +weights = np.array([0.9, 0.7, 0.8, 0.9, 0.9], dtype=np.float32) + +# Compute SoftmaxCrossEntropyLoss +sce = softmaxcrossentropy(x, labels, weight=weights, ignore_index=ignore_index) + +# Check results +expect(node, inputs=[x, labels, weights], outputs=[sce], name='test_sce_mean_weight_ii') +``` + +
+
+softmaxcrossentropy_mean_weights_ii_3d + +```python +# Define operator attributes. +reduction = 'mean' +ignore_index = np.int64(1) + +# Create operator. +node = onnx.helper.make_node('SoftmaxCrossEntropyLoss', + inputs=['x', 'y', 'w'], + outputs=['z'], + reduction=reduction, + ignore_index=ignore_index) + +# Define operator inputs. +np.random.seed(0) +x = np.random.rand(3, 5, 2).astype(np.float32) +labels = np.random.randint(0, high=5, size=(3, 2)).astype(np.int64) +labels[0][0] = np.int64(1) +weights = np.array([0.2, 0.3, 0.6, 0.1, 0.5], dtype=np.float32) + +# Compute SoftmaxCrossEntropyLoss +sce = softmaxcrossentropy(x, labels, weight=weights, ignore_index=ignore_index) + +# Check results +expect(node, inputs=[x, labels, weights], outputs=[sce], name='test_sce_mean_weight_ii_3d') +``` + +
+
+softmaxcrossentropy_mean_weights_ii_3d_log_prob + +```python +# Define operator attributes. +reduction = 'mean' +ignore_index = np.int64(1) + +# Create operator. +node = onnx.helper.make_node('SoftmaxCrossEntropyLoss', + inputs=['x', 'y', 'w'], + outputs=['z', 'log_prob'], + reduction=reduction, + ignore_index=ignore_index) + +# Define operator inputs. +np.random.seed(0) +x = np.random.rand(3, 5, 2).astype(np.float32) +labels = np.random.randint(0, high=5, size=(3, 2)).astype(np.int64) +labels[0][0] = np.int64(1) +weights = np.array([0.2, 0.3, 0.6, 0.1, 0.5], dtype=np.float32) + +# Compute SoftmaxCrossEntropyLoss +loss, log_prob = softmaxcrossentropy(x, labels, weight=weights, ignore_index=ignore_index, get_log_prob=True) + +# Check results +expect(node, inputs=[x, labels, weights], outputs=[loss, log_prob], name='test_sce_mean_weight_ii_3d_log_prob') +``` + +
+
+softmaxcrossentropy_mean_weights_ii_4d + +```python +# Define operator attributes. +reduction = 'mean' +ignore_index = np.int64(2) + +# Create operator. +node = onnx.helper.make_node('SoftmaxCrossEntropyLoss', + inputs=['x', 'y', 'w'], + outputs=['z'], + reduction=reduction, + ignore_index=ignore_index) + +# Define operator inputs. +np.random.seed(0) +x = np.random.rand(3, 5, 2, 7).astype(np.float32) +labels = np.random.randint(0, high=5, size=(3, 2, 7)).astype(np.int64) +labels[0][0][0] = np.int64(2) +weights = np.array([0.2, 0.3, 0.6, 0.1, 0.5], dtype=np.float32) + +# Compute SoftmaxCrossEntropyLoss +sce = softmaxcrossentropy(x, labels, reduction=reduction, weight=weights, ignore_index=ignore_index) + +# Check results +expect(node, inputs=[x, labels, weights], outputs=[sce], name='test_sce_mean_weight_ii_4d') +``` + +
+
+softmaxcrossentropy_mean_weights_ii_4d_log_prob + +```python +# Define operator attributes. +reduction = 'mean' +ignore_index = np.int64(2) + +# Create operator. +node = onnx.helper.make_node('SoftmaxCrossEntropyLoss', + inputs=['x', 'y', 'w'], + outputs=['z', 'log_prob'], + reduction=reduction, + ignore_index=ignore_index) + +# Define operator inputs. +np.random.seed(0) +x = np.random.rand(3, 5, 2, 7).astype(np.float32) +labels = np.random.randint(0, high=5, size=(3, 2, 7)).astype(np.int64) +labels[0][0][0] = np.int64(2) +weights = np.array([0.2, 0.3, 0.6, 0.1, 0.5], dtype=np.float32) + +# Compute SoftmaxCrossEntropyLoss +loss, log_prob = softmaxcrossentropy(x, labels, reduction=reduction, weight=weights, ignore_index=ignore_index, get_log_prob=True) + +# Check results +expect(node, inputs=[x, labels, weights], outputs=[loss, log_prob], name='test_sce_mean_weight_ii_4d_log_prob') +``` + +
+
+softmaxcrossentropy_mean_weights_ii_log_prob + +```python +# Define operator attributes. +reduction = 'mean' +ignore_index = np.int64(0) + +# Create operator. +node = onnx.helper.make_node('SoftmaxCrossEntropyLoss', + inputs=['x', 'y', 'w'], + outputs=['z', 'log_prob'], + reduction=reduction, + ignore_index=ignore_index) + +# Define operator inputs. +np.random.seed(0) +x = np.random.rand(3, 5).astype(np.float32) +labels = np.random.randint(0, high=5, size=(3, )).astype(np.int64) +labels[0] = np.int64(0) +weights = np.array([0.9, 0.7, 0.8, 0.9, 0.9], dtype=np.float32) + +# Compute SoftmaxCrossEntropyLoss +loss, log_prob = softmaxcrossentropy(x, labels, weight=weights, ignore_index=ignore_index, get_log_prob=True) + +# Check results +expect(node, inputs=[x, labels, weights], outputs=[loss, log_prob], name='test_sce_mean_weight_ii_log_prob') +``` + +
+
+softmaxcrossentropy_mean_weights_log_prob + +```python +# Define operator attributes. +reduction = 'mean' + +# Create operator. +node = onnx.helper.make_node('SoftmaxCrossEntropyLoss', + inputs=['x', 'y', 'w'], + outputs=['z', 'log_prob'], + reduction=reduction) + +# Define operator inputs. +np.random.seed(0) +x = np.random.rand(3, 5).astype(np.float32) +labels = np.random.randint(0, high=5, size=(3, )).astype(np.int64) +weights = np.array([0.9, 0.7, 0.8, 0.9, 0.9], dtype=np.float32) + +# Compute SoftmaxCrossEntropyLoss +loss, log_prob = softmaxcrossentropy(x, labels, weight=weights, get_log_prob=True) + +# Check results +expect(node, inputs=[x, labels, weights], outputs=[loss, log_prob], name='test_sce_mean_weight_log_prob') +``` + +
+
+softmaxcrossentropy_none + +```python +# Define operator attributes. +reduction = 'none' + +# Create operator. +node = onnx.helper.make_node('SoftmaxCrossEntropyLoss', + inputs=['x', 'y'], + outputs=['z'], + reduction=reduction) + +# Define operator inputs. +np.random.seed(0) +x = np.random.rand(3, 5).astype(np.float32) +labels = np.random.randint(0, high=5, size=(3, )).astype(np.int64) + +# Compute SoftmaxCrossEntropyLoss +sce = softmaxcrossentropy(x, labels, reduction='none') + +# Check results +expect(node, inputs=[x, labels], outputs=[sce], name='test_sce_none') +``` + +
+
+softmaxcrossentropy_none_log_prob + +```python +# Define operator attributes. +reduction = 'none' + +# Create operator. +node = onnx.helper.make_node('SoftmaxCrossEntropyLoss', + inputs=['x', 'y'], + outputs=['z', 'log_prob'], + reduction=reduction) + +# Define operator inputs. +np.random.seed(0) +x = np.random.rand(3, 5).astype(np.float32) +labels = np.random.randint(0, high=5, size=(3, )).astype(np.int64) + +# Compute SoftmaxCrossEntropyLoss +loss, log_prob = softmaxcrossentropy(x, labels, reduction='none', get_log_prob=True) + +# Check results +expect(node, inputs=[x, labels], outputs=[loss, log_prob], name='test_sce_none_log_prob') +``` + +
+
+softmaxcrossentropy_none_weights + +```python +# Define operator attributes. +reduction = 'none' + +# Create operator. +node = onnx.helper.make_node('SoftmaxCrossEntropyLoss', + inputs=['x', 'y', 'w'], + outputs=['z'], + reduction=reduction) + +# Define operator inputs. +np.random.seed(0) +x = np.random.rand(3, 5).astype(np.float32) +labels = np.random.randint(0, high=5, size=(3, )).astype(np.int64) +weights = np.array([0.9, 0.7, 0.8, 0.9, 0.9], dtype=np.float32) + +# Compute SoftmaxCrossEntropyLoss +sce = softmaxcrossentropy(x, labels, weight=weights, reduction='none') + +# Check results +expect(node, inputs=[x, labels, weights], outputs=[sce], name='test_sce_none_weights') +``` + +
+
+softmaxcrossentropy_none_weights_log_prob + +```python +# Define operator attributes. +reduction = 'none' + +# Create operator. +node = onnx.helper.make_node('SoftmaxCrossEntropyLoss', + inputs=['x', 'y', 'w'], + outputs=['z', 'log_prob'], + reduction=reduction) + +# Define operator inputs. +np.random.seed(0) +x = np.random.rand(3, 5).astype(np.float32) +labels = np.random.randint(0, high=5, size=(3, )).astype(np.int64) +weights = np.array([0.9, 0.7, 0.8, 0.9, 0.9], dtype=np.float32) + +# Compute SoftmaxCrossEntropyLoss +loss, log_prob = softmaxcrossentropy(x, labels, weight=weights, reduction='none', get_log_prob=True) + +# Check results +expect(node, inputs=[x, labels, weights], outputs=[loss, log_prob], name='test_sce_none_weights_log_prob') +``` + +
+
+softmaxcrossentropy_sum + +```python +# Define operator attributes. +reduction = 'sum' + +# Create operator. +node = onnx.helper.make_node('SoftmaxCrossEntropyLoss', + inputs=['x', 'y'], + outputs=['z'], + reduction=reduction) + +# Define operator inputs. +np.random.seed(0) +x = np.random.rand(3, 5).astype(np.float32) +labels = np.random.randint(0, high=5, size=(3, )).astype(np.int64) + +# Compute SoftmaxCrossEntropyLoss +sce = softmaxcrossentropy(x, labels, reduction='sum') + +# Check results +expect(node, inputs=[x, labels], outputs=[sce], name='test_sce_sum') +``` + +
+
+softmaxcrossentropy_sum_log_prob + +```python +# Define operator attributes. +reduction = 'sum' + +# Create operator. +node = onnx.helper.make_node('SoftmaxCrossEntropyLoss', + inputs=['x', 'y'], + outputs=['z', 'log_prob'], + reduction=reduction) + +# Define operator inputs. +np.random.seed(0) +x = np.random.rand(3, 5).astype(np.float32) +labels = np.random.randint(0, high=5, size=(3, )).astype(np.int64) + +# Compute SoftmaxCrossEntropyLoss +loss, log_prob = softmaxcrossentropy(x, labels, reduction='sum', get_log_prob=True) + +# Check results +expect(node, inputs=[x, labels], outputs=[loss, log_prob], name='test_sce_sum_log_prob') +``` + +
+ + +### Softplus +There are 1 test cases, listed as following: +
+softplus + +```python +node = onnx.helper.make_node( + 'Softplus', + inputs=['x'], + outputs=['y'], +) + +x = np.array([-1, 0, 1]).astype(np.float32) +y = np.log(np.exp(x) + 1) # expected output [0.31326166, 0.69314718, 1.31326163] +expect(node, inputs=[x], outputs=[y], + name='test_softplus_example') + +x = np.random.randn(3, 4, 5).astype(np.float32) +y = np.log(np.exp(x) + 1) +expect(node, inputs=[x], outputs=[y], + name='test_softplus') +``` + +
+ + +### Softsign +There are 1 test cases, listed as following: +
+softsign + +```python +node = onnx.helper.make_node( + 'Softsign', + inputs=['x'], + outputs=['y'], +) + +x = np.array([-1, 0, 1]).astype(np.float32) +y = np.array([-0.5, 0, 0.5]).astype(np.float32) +expect(node, inputs=[x], outputs=[y], + name='test_softsign_example') + +x = np.random.randn(3, 4, 5).astype(np.float32) +y = x / (1 + np.abs(x)) +expect(node, inputs=[x], outputs=[y], + name='test_softsign') +``` + +
+ + +### SpaceToDepth +There are 2 test cases, listed as following: +
+example + +```python +node = onnx.helper.make_node( + 'SpaceToDepth', + inputs=['x'], + outputs=['y'], + blocksize=2, +) + +# (1, 1, 4, 6) input tensor +x = np.array([[[[0, 6, 1, 7, 2, 8], + [12, 18, 13, 19, 14, 20], + [3, 9, 4, 10, 5, 11], + [15, 21, 16, 22, 17, 23]]]]).astype(np.float32) + +# (1, 4, 2, 3) output tensor +y = np.array([[[[0, 1, 2], + [3, 4, 5]], + [[6, 7, 8], + [9, 10, 11]], + [[12, 13, 14], + [15, 16, 17]], + [[18, 19, 20], + [21, 22, 23]]]]).astype(np.float32) +expect(node, inputs=[x], outputs=[y], + name='test_spacetodepth_example') +``` + +
+
+spacetodepth + +```python +b, c, h, w = shape = (2, 2, 6, 6) +blocksize = 2 +node = onnx.helper.make_node( + 'SpaceToDepth', + inputs=['x'], + outputs=['y'], + blocksize=blocksize, +) +x = np.random.random_sample(shape).astype(np.float32) +tmp = np.reshape(x, [b, c, + h // blocksize, blocksize, + w // blocksize, blocksize]) +tmp = np.transpose(tmp, [0, 3, 5, 1, 2, 4]) +y = np.reshape(tmp, [b, c * (blocksize**2), + h // blocksize, + w // blocksize]) +expect(node, inputs=[x], outputs=[y], + name='test_spacetodepth') +``` + +
+ + +### Split +There are 4 test cases, listed as following: +
+1d + +```python +input = np.array([1., 2., 3., 4., 5., 6.]).astype(np.float32) + +node = onnx.helper.make_node( + 'Split', + inputs=['input'], + outputs=['output_1', 'output_2', 'output_3'], + axis=0 +) + +expected_outputs = [np.array([1., 2.]).astype(np.float32), np.array([3., 4.]).astype(np.float32), np.array([5., 6.]).astype(np.float32)] +expect(node, inputs=[input], outputs=[y for y in expected_outputs], name='test_split_equal_parts_1d') + +split = np.array([2, 4]).astype(np.int64) +node = onnx.helper.make_node( + 'Split', + inputs=['input', 'split'], + outputs=['output_1', 'output_2'], + axis=0, +) + +expected_outputs = [np.array([1., 2.]).astype(np.float32), np.array([3., 4., 5., 6.]).astype(np.float32)] +expect(node, inputs=[input, split], outputs=[y for y in expected_outputs], name='test_split_variable_parts_1d') +``` + +
+
+2d + +```python +input = np.array([[1., 2., 3., 4., 5., 6.], + [7., 8., 9., 10., 11., 12.]]).astype(np.float32) + +node = onnx.helper.make_node( + 'Split', + inputs=['input'], + outputs=['output_1', 'output_2'], + axis=1 +) + +expected_outputs = [np.array([[1., 2., 3.], [7., 8., 9.]]).astype(np.float32), + np.array([[4., 5., 6.], [10., 11., 12.]]).astype(np.float32)] + +expect(node, inputs=[input], outputs=[y for y in expected_outputs], name='test_split_equal_parts_2d') + +split = np.array([2, 4]).astype(np.int64) +node = onnx.helper.make_node( + 'Split', + inputs=['input', 'split'], + outputs=['output_1', 'output_2'], + axis=1, +) + +expected_outputs = [np.array([[1., 2.], [7., 8.]]).astype(np.float32), + np.array([[3., 4., 5., 6.], [9., 10., 11., 12.]]).astype(np.float32)] + +expect(node, inputs=[input, split], outputs=[y for y in expected_outputs], name='test_split_variable_parts_2d') +``` + +
+
+default_values + +```python +input = np.array([1., 2., 3., 4., 5., 6.]).astype(np.float32) + +# If axis is not specified, split is applied on default axis 0 +node = onnx.helper.make_node( + 'Split', + inputs=['input'], + outputs=['output_1', 'output_2', 'output_3'] +) + +expected_outputs = [np.array([1., 2.]).astype(np.float32), np.array([3., 4.]).astype(np.float32), np.array([5., 6.]).astype(np.float32)] +expect(node, inputs=[input], outputs=[y for y in expected_outputs], name='test_split_equal_parts_default_axis') + +split = np.array([2, 4]).astype(np.int64) +node = onnx.helper.make_node( + 'Split', + inputs=['input', 'split'], + outputs=['output_1', 'output_2'] +) + +expected_outputs = [np.array([1., 2.]).astype(np.float32), np.array([3., 4., 5., 6.]).astype(np.float32)] +expect(node, inputs=[input, split], outputs=[y for y in expected_outputs], name='test_split_variable_parts_default_axis') +``` + +
+
+zero_size_splits + +```python +input = np.array([]).astype(np.float32) + +# Split emtpy tensor to tensors of size zero +split = np.array([0, 0, 0]).astype(np.int64) +node = onnx.helper.make_node( + 'Split', + inputs=['input', 'split'], + outputs=['output_1', 'output_2', 'output_3'] +) + +expected_outputs = [np.array([]).astype(np.float32), np.array([]).astype(np.float32), np.array([]).astype(np.float32)] +expect(node, inputs=[input, split], outputs=[y for y in expected_outputs], name='test_split_zero_size_splits') +``` + +
+ + +### Sqrt +There are 1 test cases, listed as following: +
+sqrt + +```python +node = onnx.helper.make_node( + 'Sqrt', + inputs=['x'], + outputs=['y'], +) + +x = np.array([1, 4, 9]).astype(np.float32) +y = np.sqrt(x) # expected output [1., 2., 3.] +expect(node, inputs=[x], outputs=[y], + name='test_sqrt_example') + +x = np.abs(np.random.randn(3, 4, 5).astype(np.float32)) +y = np.sqrt(x) +expect(node, inputs=[x], outputs=[y], + name='test_sqrt') +``` + +
+ + +### Squeeze +There are 2 test cases, listed as following: +
+squeeze + +```python +node = onnx.helper.make_node( + 'Squeeze', + inputs=['x', 'axes'], + outputs=['y'], +) +x = np.random.randn(1, 3, 4, 5).astype(np.float32) +axes = np.array([0], dtype=np.int64) +y = np.squeeze(x, axis=0) + +expect(node, inputs=[x, axes], outputs=[y], + name='test_squeeze') +``` + +
+
+squeeze_negative_axes + +```python +node = onnx.helper.make_node( + 'Squeeze', + inputs=['x', 'axes'], + outputs=['y'], +) +x = np.random.randn(1, 3, 1, 5).astype(np.float32) +axes = np.array([-2], dtype=np.int64) +y = np.squeeze(x, axis=-2) +expect(node, inputs=[x, axes], outputs=[y], + name='test_squeeze_negative_axes') +``` + +
+ + +### StringNormalizer +There are 6 test cases, listed as following: +
+monday_casesensintive_lower + +```python +input = np.array([u'monday', u'tuesday', u'wednesday', u'thursday']).astype(object) +output = np.array([u'tuesday', u'wednesday', u'thursday']).astype(object) +stopwords = [u'monday'] + +node = onnx.helper.make_node( + 'StringNormalizer', + inputs=['x'], + outputs=['y'], + case_change_action='LOWER', + is_case_sensitive=1, + stopwords=stopwords +) +expect(node, inputs=[input], outputs=[output], name='test_strnormalizer_export_monday_casesensintive_lower') +``` + +
+
+monday_casesensintive_nochangecase + +```python +input = np.array([u'monday', u'tuesday', u'wednesday', u'thursday']).astype(object) +output = np.array([u'tuesday', u'wednesday', u'thursday']).astype(object) +stopwords = [u'monday'] + +node = onnx.helper.make_node( + 'StringNormalizer', + inputs=['x'], + outputs=['y'], + is_case_sensitive=1, + stopwords=stopwords +) +expect(node, inputs=[input], outputs=[output], name='test_strnormalizer_export_monday_casesensintive_nochangecase') +``` + +
+
+monday_casesensintive_upper + +```python +input = np.array([u'monday', u'tuesday', u'wednesday', u'thursday']).astype(object) +output = np.array([u'TUESDAY', u'WEDNESDAY', u'THURSDAY']).astype(object) +stopwords = [u'monday'] + +node = onnx.helper.make_node( + 'StringNormalizer', + inputs=['x'], + outputs=['y'], + case_change_action='UPPER', + is_case_sensitive=1, + stopwords=stopwords +) +expect(node, inputs=[input], outputs=[output], name='test_strnormalizer_export_monday_casesensintive_upper') +``` + +
+
+monday_empty_output + +```python +input = np.array([u'monday', u'monday']).astype(object) +output = np.array([u'']).astype(object) +stopwords = [u'monday'] + +node = onnx.helper.make_node( + 'StringNormalizer', + inputs=['x'], + outputs=['y'], + case_change_action='UPPER', + is_case_sensitive=1, + stopwords=stopwords +) +expect(node, inputs=[input], outputs=[output], name='test_strnormalizer_export_monday_empty_output') +``` + +
+
+monday_insensintive_upper_twodim + +```python +input = np.array([u'Monday', u'tuesday', u'wednesday', u'Monday', u'tuesday', u'wednesday']).astype(object).reshape([1, 6]) + +# It does upper case cecedille, accented E +# and german umlaut but fails +# with german eszett +output = np.array([u'TUESDAY', u'WEDNESDAY', u'TUESDAY', u'WEDNESDAY']).astype(object).reshape([1, 4]) +stopwords = [u'monday'] + +node = onnx.helper.make_node( + 'StringNormalizer', + inputs=['x'], + outputs=['y'], + case_change_action='UPPER', + stopwords=stopwords +) +expect(node, inputs=[input], outputs=[output], name='test_strnormalizer_export_monday_insensintive_upper_twodim') +``` + +
+
+nostopwords_nochangecase + +```python +input = np.array([u'monday', u'tuesday']).astype(object) +output = input + +# No stopwords. This is a NOOP +node = onnx.helper.make_node( + 'StringNormalizer', + inputs=['x'], + outputs=['y'], + is_case_sensitive=1, +) +expect(node, inputs=[input], outputs=[output], name='test_strnormalizer_nostopwords_nochangecase') +``` + +
+ + +### Sub +There are 2 test cases, listed as following: +
+sub + +```python +node = onnx.helper.make_node( + 'Sub', + inputs=['x', 'y'], + outputs=['z'], +) + +x = np.array([1, 2, 3]).astype(np.float32) +y = np.array([3, 2, 1]).astype(np.float32) +z = x - y # expected output [-2., 0., 2.] +expect(node, inputs=[x, y], outputs=[z], + name='test_sub_example') + +x = np.random.randn(3, 4, 5).astype(np.float32) +y = np.random.randn(3, 4, 5).astype(np.float32) +z = x - y +expect(node, inputs=[x, y], outputs=[z], + name='test_sub') + +x = np.random.randint(12, 24, size=(3, 4, 5), dtype=np.uint8) +y = np.random.randint(12, size=(3, 4, 5), dtype=np.uint8) +z = x - y +expect(node, inputs=[x, y], outputs=[z], + name='test_sub_uint8') +``` + +
+
+sub_broadcast + +```python +node = onnx.helper.make_node( + 'Sub', + inputs=['x', 'y'], + outputs=['z'], +) + +x = np.random.randn(3, 4, 5).astype(np.float32) +y = np.random.randn(5).astype(np.float32) +z = x - y +expect(node, inputs=[x, y], outputs=[z], + name='test_sub_bcast') +``` + +
+ + +### Sum +There are 1 test cases, listed as following: +
+sum + +```python +data_0 = np.array([3, 0, 2]).astype(np.float32) +data_1 = np.array([1, 3, 4]).astype(np.float32) +data_2 = np.array([2, 6, 6]).astype(np.float32) +result = np.array([6, 9, 12]).astype(np.float32) +node = onnx.helper.make_node( + 'Sum', + inputs=['data_0', 'data_1', 'data_2'], + outputs=['result'], +) +expect(node, inputs=[data_0, data_1, data_2], outputs=[result], + name='test_sum_example') + +node = onnx.helper.make_node( + 'Sum', + inputs=['data_0'], + outputs=['result'], +) +expect(node, inputs=[data_0], outputs=[data_0], + name='test_sum_one_input') + +result = np.add(data_0, data_1) +node = onnx.helper.make_node( + 'Sum', + inputs=['data_0', 'data_1'], + outputs=['result'], +) +expect(node, inputs=[data_0, data_1], outputs=[result], + name='test_sum_two_inputs') +``` + +
+ + +### Tan +There are 1 test cases, listed as following: +
+tan + +```python +node = onnx.helper.make_node( + 'Tan', + inputs=['x'], + outputs=['y'], +) + +x = np.array([-1, 0, 1]).astype(np.float32) +y = np.tan(x) +expect(node, inputs=[x], outputs=[y], + name='test_tan_example') + +x = np.random.randn(3, 4, 5).astype(np.float32) +y = np.tan(x) +expect(node, inputs=[x], outputs=[y], + name='test_tan') +``` + +
+ + +### Tanh +There are 1 test cases, listed as following: +
+tanh + +```python +node = onnx.helper.make_node( + 'Tanh', + inputs=['x'], + outputs=['y'], +) + +x = np.array([-1, 0, 1]).astype(np.float32) +y = np.tanh(x) # expected output [-0.76159418, 0., 0.76159418] +expect(node, inputs=[x], outputs=[y], + name='test_tanh_example') + +x = np.random.randn(3, 4, 5).astype(np.float32) +y = np.tanh(x) +expect(node, inputs=[x], outputs=[y], + name='test_tanh') +``` + +
+ + +### TfIdfVectorizer +There are 7 test cases, listed as following: +
+tf_batch_onlybigrams_skip0 + +```python +input = np.array([[1, 1, 3, 3, 3, 7], [8, 6, 7, 5, 6, 8]]).astype(np.int32) +output = np.array([[0., 0., 0., 0., 0., 0., 0.], [0., 0., 0., 0., 1., 0., 1.]]).astype(np.float32) + +ngram_counts = np.array([0, 4]).astype(np.int64) +ngram_indexes = np.array([0, 1, 2, 3, 4, 5, 6]).astype(np.int64) +pool_int64s = np.array([2, 3, 5, 4, # unigrams + 5, 6, 7, 8, 6, 7]).astype(np.int64) # bigrams + +helper = TfIdfVectorizerHelper( + mode='TF', + min_gram_length=2, + max_gram_length=2, + max_skip_count=0, + ngram_counts=ngram_counts, + ngram_indexes=ngram_indexes, + pool_int64s=pool_int64s +) +node = helper.make_node_noweights() +expect(node, inputs=[input], outputs=[output], name='test_tfidfvectorizer_tf_batch_onlybigrams_skip0') +``` + +
+
+tf_batch_onlybigrams_skip5 + +```python +input = np.array([[1, 1, 3, 3, 3, 7], [8, 6, 7, 5, 6, 8]]).astype(np.int32) +output = np.array([[0., 0., 0., 0., 0., 0., 0.], [0., 0., 0., 0., 1., 1., 1.]]).astype(np.float32) + +ngram_counts = np.array([0, 4]).astype(np.int64) +ngram_indexes = np.array([0, 1, 2, 3, 4, 5, 6]).astype(np.int64) +pool_int64s = np.array([2, 3, 5, 4, # unigrams + 5, 6, 7, 8, 6, 7]).astype(np.int64) # bigrams + +helper = TfIdfVectorizerHelper( + mode='TF', + min_gram_length=2, + max_gram_length=2, + max_skip_count=5, + ngram_counts=ngram_counts, + ngram_indexes=ngram_indexes, + pool_int64s=pool_int64s +) +node = helper.make_node_noweights() +expect(node, inputs=[input], outputs=[output], name='test_tfidfvectorizer_tf_batch_onlybigrams_skip5') +``` + +
+
+tf_batch_uniandbigrams_skip5 + +```python +input = np.array([[1, 1, 3, 3, 3, 7], [8, 6, 7, 5, 6, 8]]).astype(np.int32) +output = np.array([[0., 3., 0., 0., 0., 0., 0.], [0., 0., 1., 0., 1., 1., 1.]]).astype(np.float32) + +ngram_counts = np.array([0, 4]).astype(np.int64) +ngram_indexes = np.array([0, 1, 2, 3, 4, 5, 6]).astype(np.int64) +pool_int64s = np.array([2, 3, 5, 4, # unigrams + 5, 6, 7, 8, 6, 7]).astype(np.int64) # bigrams + +helper = TfIdfVectorizerHelper( + mode='TF', + min_gram_length=1, + max_gram_length=2, + max_skip_count=5, + ngram_counts=ngram_counts, + ngram_indexes=ngram_indexes, + pool_int64s=pool_int64s +) +node = helper.make_node_noweights() +expect(node, inputs=[input], outputs=[output], name='test_tfidfvectorizer_tf_batch_uniandbigrams_skip5') +``` + +
+
+tf_only_bigrams_skip0 + +```python +input = np.array([1, 1, 3, 3, 3, 7, 8, 6, 7, 5, 6, 8]).astype(np.int32) +output = np.array([0., 0., 0., 0., 1., 1., 1.]).astype(np.float32) + +ngram_counts = np.array([0, 4]).astype(np.int64) +ngram_indexes = np.array([0, 1, 2, 3, 4, 5, 6]).astype(np.int64) +pool_int64s = np.array([2, 3, 5, 4, # unigrams + 5, 6, 7, 8, 6, 7]).astype(np.int64) # bigrams + +helper = TfIdfVectorizerHelper( + mode='TF', + min_gram_length=2, + max_gram_length=2, + max_skip_count=0, + ngram_counts=ngram_counts, + ngram_indexes=ngram_indexes, + pool_int64s=pool_int64s +) +node = helper.make_node_noweights() +expect(node, inputs=[input], outputs=[output], name='test_tfidfvectorizer_tf_only_bigrams_skip0') +``` + +
+
+tf_onlybigrams_levelempty + +```python +input = np.array([1, 1, 3, 3, 3, 7, 8, 6, 7, 5, 6, 8]).astype(np.int32) +output = np.array([1., 1., 1.]).astype(np.float32) + +ngram_counts = np.array([0, 0]).astype(np.int64) +ngram_indexes = np.array([0, 1, 2]).astype(np.int64) +pool_int64s = np.array([ # unigrams none + 5, 6, 7, 8, 6, 7]).astype(np.int64) # bigrams + +helper = TfIdfVectorizerHelper( + mode='TF', + min_gram_length=2, + max_gram_length=2, + max_skip_count=0, + ngram_counts=ngram_counts, + ngram_indexes=ngram_indexes, + pool_int64s=pool_int64s +) +node = helper.make_node_noweights() +expect(node, inputs=[input], outputs=[output], name='test_tfidfvectorizer_tf_onlybigrams_levelempty') +``` + +
+
+tf_onlybigrams_skip5 + +```python +input = np.array([1, 1, 3, 3, 3, 7, 8, 6, 7, 5, 6, 8]).astype(np.int32) +output = np.array([0., 0., 0., 0., 1., 3., 1.]).astype(np.float32) + +ngram_counts = np.array([0, 4]).astype(np.int64) +ngram_indexes = np.array([0, 1, 2, 3, 4, 5, 6]).astype(np.int64) +pool_int64s = np.array([2, 3, 5, 4, # unigrams + 5, 6, 7, 8, 6, 7]).astype(np.int64) # bigrams + +helper = TfIdfVectorizerHelper( + mode='TF', + min_gram_length=2, + max_gram_length=2, + max_skip_count=5, + ngram_counts=ngram_counts, + ngram_indexes=ngram_indexes, + pool_int64s=pool_int64s +) +node = helper.make_node_noweights() +expect(node, inputs=[input], outputs=[output], name='test_tfidfvectorizer_tf_onlybigrams_skip5') +``` + +
+
+tf_uniandbigrams_skip5 + +```python +input = np.array([1, 1, 3, 3, 3, 7, 8, 6, 7, 5, 6, 8]).astype(np.int32) +output = np.array([0., 3., 1., 0., 1., 3., 1.]).astype(np.float32) + +ngram_counts = np.array([0, 4]).astype(np.int64) +ngram_indexes = np.array([0, 1, 2, 3, 4, 5, 6]).astype(np.int64) +pool_int64s = np.array([2, 3, 5, 4, # unigrams + 5, 6, 7, 8, 6, 7]).astype(np.int64) # bigrams + +helper = TfIdfVectorizerHelper( + mode='TF', + min_gram_length=1, + max_gram_length=2, + max_skip_count=5, + ngram_counts=ngram_counts, + ngram_indexes=ngram_indexes, + pool_int64s=pool_int64s +) +node = helper.make_node_noweights() +expect(node, inputs=[input], outputs=[output], name='test_tfidfvectorizer_tf_uniandbigrams_skip5') +``` + +
+ + +### ThresholdedRelu +There are 2 test cases, listed as following: +
+default + +```python +default_alpha = 1.0 +node = onnx.helper.make_node( + 'ThresholdedRelu', + inputs=['x'], + outputs=['y'] +) +x = np.random.randn(3, 4, 5).astype(np.float32) +y = np.clip(x, default_alpha, np.inf) +y[y == default_alpha] = 0 + +expect(node, inputs=[x], outputs=[y], + name='test_thresholdedrelu_default') +``` + +
+
+thresholdedrelu + +```python +alpha = 2.0 +node = onnx.helper.make_node( + 'ThresholdedRelu', + inputs=['x'], + outputs=['y'], + alpha=alpha +) + +x = np.array([-1.5, 0., 1.2, 2.0, 2.2]).astype(np.float32) +y = np.clip(x, alpha, np.inf) # expected output [0., 0., 0., 0., 2.2] +y[y == alpha] = 0 + +expect(node, inputs=[x], outputs=[y], + name='test_thresholdedrelu_example') + +x = np.random.randn(3, 4, 5).astype(np.float32) +y = np.clip(x, alpha, np.inf) +y[y == alpha] = 0 + +expect(node, inputs=[x], outputs=[y], + name='test_thresholdedrelu') +``` + +
+ + +### Tile +There are 2 test cases, listed as following: +
+tile + +```python +node = onnx.helper.make_node( + 'Tile', + inputs=['x', 'y'], + outputs=['z'] +) + +x = np.random.rand(2, 3, 4, 5).astype(np.float32) + +repeats = np.random.randint(low=1, high=10, size=(np.ndim(x),)).astype(np.int64) + +z = np.tile(x, repeats) + +expect(node, + inputs=[x, repeats], + outputs=[z], + name='test_tile') +``` + +
+
+tile_precomputed + +```python +node = onnx.helper.make_node( + 'Tile', + inputs=['x', 'y'], + outputs=['z'] +) + +x = np.array([ + [0, 1], + [2, 3] +], dtype=np.float32) + +repeats = np.array([2, 2], dtype=np.int64) + +z = np.array([ + [0, 1, 0, 1], + [2, 3, 2, 3], + [0, 1, 0, 1], + [2, 3, 2, 3] +], dtype=np.float32) + +expect(node, + inputs=[x, repeats], + outputs=[z], + name='test_tile_precomputed') +``` + +
+ + +### TopK +There are 3 test cases, listed as following: +
+top_k + +```python +axis = 1 +largest = 1 + +k = 3 +node = onnx.helper.make_node( + 'TopK', + inputs=['x', 'k'], + outputs=['values', 'indices'], + axis=axis +) +X = np.array([ + [0, 1, 2, 3], + [4, 5, 6, 7], + [8, 9, 10, 11], +], dtype=np.float32) +K = np.array([k], dtype=np.int64) +values_ref, indices_ref = topk_sorted_implementation(X, k, axis, largest) + +#print(values_ref) +#[[ 3. 2. 1.] +# [ 7. 6. 5.] +# [11. 10. 9.]] +#print(indices_ref) +#[[3 2 1] +# [3 2 1] +# [3 2 1]] + +expect(node, inputs=[X, K], outputs=[values_ref, indices_ref], + name='test_top_k') +``` + +
+
+top_k_negative_axis + +```python +axis = -1 +largest = 1 + +k = 3 +node = onnx.helper.make_node( + 'TopK', + inputs=['x', 'k'], + outputs=['values', 'indices'], + axis=axis +) +X = np.array([ + [0, 1, 2, 3], + [4, 5, 6, 7], + [8, 9, 10, 11], +], dtype=np.float32) +K = np.array([k], dtype=np.int64) +values_ref, indices_ref = topk_sorted_implementation(X, k, axis, largest) + +# print(values_ref) +#[[ 3. 2. 1.] +# [ 7. 6. 5.] +# [11. 10. 9.]] +# print(indices_ref) +#[[3 2 1] +# [3 2 1] +# [3 2 1]] + +expect(node, inputs=[X, K], outputs=[values_ref, indices_ref], + name='test_top_k_negative_axis') +``` + +
+
+top_k_smallest + +```python +axis = 1 +largest = 0 +sorted = 1 +k = 3 + +node = onnx.helper.make_node( + 'TopK', + inputs=['x', 'k'], + outputs=['values', 'indices'], + axis=axis, + largest=largest, + sorted=sorted +) + +X = np.array([ + [0, 1, 2, 3], + [4, 5, 6, 7], + [11, 10, 9, 8], +], dtype=np.float32) +K = np.array([k], dtype=np.int64) +values_ref, indices_ref = topk_sorted_implementation(X, k, axis, largest) + +#print(values_ref) +#[[ 0. 1. 2.] +# [ 4. 5. 6.] +# [ 8. 9. 10.]] +#print(indices_ref) +#[[0 1 2] +# [0 1 2] +# [3 2 1]] + +expect(node, inputs=[X, K], outputs=[values_ref, indices_ref], + name='test_top_k_smallest') +``` + +
+ + +### Transpose +There are 2 test cases, listed as following: +
+all_permutations + +```python +shape = (2, 3, 4) +data = np.random.random_sample(shape).astype(np.float32) +permutations = list(itertools.permutations(np.arange(len(shape)))) + +for i in range(len(permutations)): + node = onnx.helper.make_node( + 'Transpose', + inputs=['data'], + outputs=['transposed'], + perm=permutations[i] + ) + transposed = np.transpose(data, permutations[i]) + expect(node, inputs=[data], outputs=[transposed], + name='test_transpose_all_permutations_' + str(i)) +``` + +
+
+default + +```python +shape = (2, 3, 4) +data = np.random.random_sample(shape).astype(np.float32) + +node = onnx.helper.make_node( + 'Transpose', + inputs=['data'], + outputs=['transposed'] +) + +transposed = np.transpose(data) +expect(node, inputs=[data], outputs=[transposed], + name='test_transpose_default') +``` + +
+ + +### Trilu +There are 18 test cases, listed as following: +
+tril + +```python +node = onnx.helper.make_node( + 'Trilu', + inputs=['x'], + outputs=['y'], + upper=0, +) + +x = np.random.randint(10, size=(4, 5)).astype(np.int64) +# X: +# [[4, 7, 3, 7, 9], +# [1, 2, 8, 6, 9], +# [9, 4, 1, 8, 7], +# [4, 3, 4, 2, 4]] +# expect result: +# [[4, 0, 0, 0, 0], +# [1, 2, 0, 0, 0], +# [9, 4, 1, 0, 0], +# [4, 3, 4, 2, 0]] +y = tril_reference_implementation(x) +expect(node, inputs=[x], outputs=[y], name='test_tril') +``` + +
+
+tril_neg + +```python +node = onnx.helper.make_node( + 'Trilu', + inputs=['x', 'k'], + outputs=['y'], + upper=0, +) + +x = np.random.randint(10, size=(4, 5)).astype(np.int64) +k = np.array(-1).astype(np.int64) +# X: +# [[4, 7, 3, 7, 9], +# [1, 2, 8, 6, 9], +# [9, 4, 1, 8, 7], +# [4, 3, 4, 2, 4]] +# expect result: +# [[0, 0, 0, 0, 0], +# [1, 0, 0, 0, 0], +# [9, 4, 0, 0, 0], +# [4, 3, 4, 0, 0]] +y = tril_reference_implementation(x, int(k)) +expect(node, inputs=[x, k], outputs=[y], name='test_tril_neg') +``` + +
+
+tril_one_row + +```python +node = onnx.helper.make_node( + 'Trilu', + inputs=['x'], + outputs=['y'], + upper=0, +) + +x = np.random.randint(10, size=(3, 1, 5)).astype(np.int64) +# X: +# [[[6, 2, 4, 1, 6]], +# +# [[8, 3, 8, 7, 0]], +# +# [[2, 2, 9, 5, 9]]] +# expect result: +# [[[6, 0, 0, 0, 0]], +# +# [[8, 0, 0, 0, 0]], +# +# [[2, 0, 0, 0, 0]]] +y = tril_reference_implementation(x) +expect(node, inputs=[x], outputs=[y], name='test_tril_one_row_neg') +``` + +
+
+tril_out_neg + +```python +node = onnx.helper.make_node( + 'Trilu', + inputs=['x', 'k'], + outputs=['y'], + upper=0, +) + +x = np.random.randint(10, size=(4, 5)).astype(np.int64) +k = np.array(-7).astype(np.int64) +# X: +# [[4, 7, 3, 7, 9], +# [1, 2, 8, 6, 9], +# [9, 4, 1, 8, 7], +# [4, 3, 4, 2, 4]] +# expect result: +# [[0, 0, 0, 0, 0], +# [0, 0, 0, 0, 0], +# [0, 0, 0, 0, 0], +# [0, 0, 0, 0, 0]] +y = tril_reference_implementation(x, int(k)) +expect(node, inputs=[x, k], outputs=[y], name='test_tril_out_neg') +``` + +
+
+tril_out_pos + +```python +node = onnx.helper.make_node( + 'Trilu', + inputs=['x', 'k'], + outputs=['y'], + upper=0, +) +x = np.random.randint(10, size=(4, 5)).astype(np.int64) +k = np.array(6).astype(np.int64) +# X: +# [[4, 7, 3, 7, 9], +# [1, 2, 8, 6, 9], +# [9, 4, 1, 8, 7], +# [4, 3, 4, 2, 4]] +# expect result: +# [[4, 7, 3, 7, 9], +# [1, 2, 8, 6, 9], +# [9, 4, 1, 8, 7], +# [4, 3, 4, 2, 4]] +y = tril_reference_implementation(x, int(k)) +expect(node, inputs=[x, k], outputs=[y], name='test_tril_out_pos') +``` + +
+
+tril_pos + +```python +node = onnx.helper.make_node( + 'Trilu', + inputs=['x', 'k'], + outputs=['y'], + upper=0, +) + +x = np.random.randint(10, size=(4, 5)).astype(np.int64) +k = np.array(2).astype(np.int64) +# X: +# [[4, 7, 3, 7, 9], +# [1, 2, 8, 6, 9], +# [9, 4, 1, 8, 7], +# [4, 3, 4, 2, 4]] +# expect result: +# [[4, 7, 3, 0, 0], +# [1, 2, 8, 6, 0], +# [9, 4, 1, 8, 7], +# [4, 3, 4, 2, 4]] +y = tril_reference_implementation(x, int(k)) +expect(node, inputs=[x, k], outputs=[y], name='test_tril_pos') +``` + +
+
+tril_square + +```python +node = onnx.helper.make_node( + 'Trilu', + inputs=['x'], + outputs=['y'], + upper=0, +) + +x = np.random.randint(10, size=(2, 3, 3)).astype(np.int64) +# X: +# [[[0, 4, 3], +# [2, 0, 9], +# [8, 2, 5]], +# +# [[2, 7, 2], +# [2, 6, 0], +# [2, 6, 5]]] +# expect result: +# [[[0, 0, 0], +# [2, 0, 0], +# [8, 2, 5]], +# +# [[2, 0, 0], +# [2, 6, 0], +# [2, 6, 5]]] +y = tril_reference_implementation(x) +expect(node, inputs=[x], outputs=[y], name='test_tril_square') +``` + +
+
+tril_square_neg + +```python +node = onnx.helper.make_node( + 'Trilu', + inputs=['x', 'k'], + outputs=['y'], + upper=0, +) + +x = np.random.randint(10, size=(2, 3, 3)).astype(np.int64) +k = np.array(-1).astype(np.int64) +# X: +# [[[0, 4, 3], +# [2, 0, 9], +# [8, 2, 5]], +# +# [[2, 7, 2], +# [2, 6, 0], +# [2, 6, 5]]] +# expect result: +# [[[0, 0, 0], +# [2, 0, 0], +# [8, 2, 0]], +# +# [[0, 0, 0], +# [2, 0, 0], +# [2, 6, 0]]] +y = tril_reference_implementation(x, int(k)) +expect(node, inputs=[x, k], outputs=[y], name='test_tril_square_neg') +``` + +
+
+tril_zero + +```python +node = onnx.helper.make_node( + 'Trilu', + inputs=['x', 'k'], + outputs=['y'], + upper=0, +) + +x = np.random.randint(10, size=(3, 0, 5)).astype(np.int64) +k = np.array(6).astype(np.int64) +# X: +# [] +# expect result: +# [] +y = tril_reference_implementation(x, int(k)) +expect(node, inputs=[x, k], outputs=[y], name='test_tril_zero') +``` + +
+
+triu + +```python +node = onnx.helper.make_node( + 'Trilu', + inputs=['x'], + outputs=['y'], +) + +x = np.random.randint(10, size=(4, 5)).astype(np.int64) +# X: +# [[4, 7, 3, 7, 9], +# [1, 2, 8, 6, 9], +# [9, 4, 0, 8, 7], +# [4, 3, 4, 2, 4]] +# expect result: +# [[4, 7, 3, 7, 9], +# [0, 2, 8, 6, 9], +# [0, 0, 0, 8, 7], +# [0, 0, 0, 2, 4]] +y = triu_reference_implementation(x) +expect(node, inputs=[x], outputs=[y], name='test_triu') +``` + +
+
+triu_neg + +```python +node = onnx.helper.make_node( + 'Trilu', + inputs=['x', 'k'], + outputs=['y'], +) + +x = np.random.randint(10, size=(4, 5)).astype(np.int64) +k = np.array(-1).astype(np.int64) +# X: +# [[4, 7, 3, 7, 9], +# [1, 2, 8, 6, 9], +# [9, 4, 0, 8, 7], +# [4, 3, 4, 2, 4]] +# expect result: +# [[4, 7, 3, 7, 9], +# [1, 2, 8, 6, 9], +# [0, 4, 0, 8, 7], +# [0, 0, 4, 2, 4]] +y = triu_reference_implementation(x, int(k)) +expect(node, inputs=[x, k], outputs=[y], name='test_triu_neg') +``` + +
+
+triu_one_row + +```python +node = onnx.helper.make_node( + 'Trilu', + inputs=['x', 'k'], + outputs=['y'], +) + +x = np.random.randint(10, size=(3, 1, 5)).astype(np.int64) +k = np.array(1).astype(np.int64) +# X: +# [[[1, 4, 9, 7, 1]], +# +# [[9, 2, 8, 8, 4]], +# +# [[3, 9, 7, 4, 2]]] +# expect result: +# [[[0, 4, 9, 7, 1]], +# +# [[0, 2, 8, 8, 4]], +# +# [[0, 9, 7, 4, 2]]] +y = triu_reference_implementation(x, int(k)) +expect(node, inputs=[x, k], outputs=[y], name='test_triu_one_row') +``` + +
+
+triu_out_neg_out + +```python +node = onnx.helper.make_node( + 'Trilu', + inputs=['x', 'k'], + outputs=['y'], +) + +x = np.random.randint(10, size=(4, 5)).astype(np.int64) +k = np.array(-7).astype(np.int64) +# X: +# [[4, 7, 3, 7, 9], +# [1, 2, 8, 6, 9], +# [9, 4, 0, 8, 7], +# [4, 3, 4, 2, 4]] +# expect result: +# [[4, 7, 3, 7, 9], +# [1, 2, 8, 6, 9], +# [9, 4, 0, 8, 7], +# [4, 3, 4, 2, 4]] +y = triu_reference_implementation(x, int(k)) +expect(node, inputs=[x, k], outputs=[y], name='test_triu_out_neg_out') +``` + +
+
+triu_out_pos + +```python +node = onnx.helper.make_node( + 'Trilu', + inputs=['x', 'k'], + outputs=['y'], +) + +x = np.random.randint(10, size=(4, 5)).astype(np.int64) +k = np.array(6).astype(np.int64) +# X: +# [[4, 7, 3, 7, 9], +# [1, 2, 8, 6, 9], +# [9, 4, 0, 8, 7], +# [4, 3, 4, 2, 4]] +# expect result: +# [[0, 0, 0, 0, 0], +# [0, 0, 0, 0, 0], +# [0, 0, 0, 0, 0], +# [0, 0, 0, 0, 0]] +y = triu_reference_implementation(x, int(k)) +expect(node, inputs=[x, k], outputs=[y], name='test_triu_out_pos') +``` + +
+
+triu_pos + +```python +node = onnx.helper.make_node( + 'Trilu', + inputs=['x', 'k'], + outputs=['y'], +) + +x = np.random.randint(10, size=(4, 5)).astype(np.int64) +k = np.array(2).astype(np.int64) +# X: +# [[4, 7, 3, 7, 9], +# [1, 2, 8, 6, 9], +# [9, 4, 0, 8, 7], +# [4, 3, 4, 2, 4]] +# expect result: +# [[0, 0, 3, 7, 9], +# [0, 0, 0, 6, 9], +# [0, 0, 0, 0, 7], +# [0, 0, 0, 0, 0]] +y = triu_reference_implementation(x, int(k)) +expect(node, inputs=[x, k], outputs=[y], name='test_triu_pos') +``` + +
+
+triu_square + +```python +node = onnx.helper.make_node( + 'Trilu', + inputs=['x'], + outputs=['y'], +) + +x = np.random.randint(10, size=(2, 3, 3)).astype(np.int64) +y = triu_reference_implementation(x) +# X: +# [[[4, 6, 9], +# [7, 5, 4], +# [8, 1, 2]], +# +# [[1, 4, 9], +# [9, 6, 3], +# [8, 9, 8]]] +# expect result: +# [[[4, 6, 9], +# [0, 5, 4], +# [0, 0, 2]], +# +# [[1, 4, 9], +# [0, 6, 3], +# [0, 0, 8]]] +expect(node, inputs=[x], outputs=[y], name='test_triu_square') +``` + +
+
+triu_square_neg + +```python +node = onnx.helper.make_node( + 'Trilu', + inputs=['x', 'k'], + outputs=['y'], +) + +x = np.random.randint(10, size=(2, 3, 3)).astype(np.int64) +k = np.array(-1).astype(np.int64) +# X: +# [[[4, 6, 9], +# [7, 5, 4], +# [8, 1, 2]], +# +# [[1, 4, 9], +# [9, 6, 3], +# [8, 9, 8]]] +# expect result: +# [[[4, 6, 9], +# [7, 5, 4], +# [0, 1, 2]], +# +# [[1, 4, 9], +# [9, 6, 3], +# [0, 9, 8]]] +y = triu_reference_implementation(x, int(k)) +expect(node, inputs=[x, k], outputs=[y], name='test_triu_square_neg') +``` + +
+
+triu_zero + +```python +node = onnx.helper.make_node( + 'Trilu', + inputs=['x', 'k'], + outputs=['y'], +) + +x = np.random.randint(10, size=(0, 5)).astype(np.int64) +k = np.array(6).astype(np.int64) +# X: +# [] +# expect result: +# [] +y = triu_reference_implementation(x, int(k)) +expect(node, inputs=[x, k], outputs=[y], name='test_triu_zero') +``` + +
+ + +### Unique +There are 5 test cases, listed as following: +
+not_sorted_without_axis + +```python +node_not_sorted = onnx.helper.make_node( + 'Unique', + inputs=['X'], + outputs=['Y', 'indices', 'inverse_indices', 'counts'], + sorted=0 +) +# numpy unique does not retain original order (it sorts the output unique values) +# https://github.com/numpy/numpy/issues/8621 +# we need to recover unsorted output and indices +x = np.array([2.0, 1.0, 1.0, 3.0, 4.0, 3.0], dtype=np.float32) +y, indices, inverse_indices, counts = np.unique(x, True, True, True) + +# prepare index mapping from sorted to unsorted +argsorted_indices = np.argsort(indices) +inverse_indices_map = {i: si for i, si in zip(argsorted_indices, np.arange(len(argsorted_indices)))} + +indices = indices[argsorted_indices] +y = np.take(x, indices, axis=0) +inverse_indices = np.asarray([inverse_indices_map[i] for i in inverse_indices], dtype=np.int64) +counts = counts[argsorted_indices] +indices, inverse_indices, counts = specify_int64(indices, inverse_indices, counts) +# print(y) +# [2.0, 1.0, 3.0, 4.0] +# print(indices) +# [0 1 3 4] +# print(inverse_indices) +# [0, 1, 1, 2, 3, 2] +# print(counts) +# [1, 2, 2, 1] + +expect(node_not_sorted, inputs=[x], outputs=[y, indices, inverse_indices, counts], name='test_unique_not_sorted_without_axis') +``` + +
+
+sorted_with_axis + +```python +node_sorted = onnx.helper.make_node( + 'Unique', + inputs=['X'], + outputs=['Y', 'indices', 'inverse_indices', 'counts'], + sorted=1, + axis=0 +) + +x = np.array([[1, 0, 0], [1, 0, 0], [2, 3, 4]], dtype=np.float32) +y, indices, inverse_indices, counts = np.unique(x, True, True, True, axis=0) +indices, inverse_indices, counts = specify_int64(indices, inverse_indices, counts) +# print(y) +# [[1. 0. 0.] +# [2. 3. 4.]] +# print(indices) +# [0 2] +# print(inverse_indices) +# [0 0 1] +# print(counts) +# [2 1] + +expect(node_sorted, inputs=[x], outputs=[y, indices, inverse_indices, counts], name='test_unique_sorted_with_axis') +``` + +
+
+sorted_with_axis_3d + +```python +node_sorted = onnx.helper.make_node( + 'Unique', + inputs=['X'], + outputs=['Y', 'indices', 'inverse_indices', 'counts'], + sorted=1, + axis=1 +) + +x = np.array([[[1., 1.], [0., 1.], [2., 1.], [0., 1.]], + [[1., 1.], [0., 1.], [2., 1.], [0., 1.]]], dtype=np.float32) +y, indices, inverse_indices, counts = np.unique(x, True, True, True, axis=1) +indices, inverse_indices, counts = specify_int64(indices, inverse_indices, counts) +# print(y) +# [[[0. 1.] +# [1. 1.] +# [2. 1.]] +# [[0. 1.] +# [1. 1.] +# [2. 1.]]] +# print(indices) +# [1 0 2] +# print(inverse_indices) +# [1 0 2 0] +# print(counts) +# [2 1 1] +expect(node_sorted, inputs=[x], outputs=[y, indices, inverse_indices, counts], name='test_unique_sorted_with_axis_3d') +``` + +
+
+sorted_with_negative_axis + +```python +node_sorted = onnx.helper.make_node( + 'Unique', + inputs=['X'], + outputs=['Y', 'indices', 'inverse_indices', 'counts'], + sorted=1, + axis=-1 +) + +x = np.array([[1, 0, 0], [1, 0, 0], [2, 3, 3]], dtype=np.float32) +y, indices, inverse_indices, counts = np.unique(x, True, True, True, axis=-1) +indices, inverse_indices, counts = specify_int64(indices, inverse_indices, counts) +# print(y) +# [[0. 1.] +# [0. 1.] +# [3. 2.]] +# print(indices) +# [1 0] +# print(inverse_indices) +# [1 0 0] +# print(counts) +# [2 1] + +expect(node_sorted, inputs=[x], outputs=[y, indices, inverse_indices, counts], name='test_unique_sorted_with_negative_axis') +``` + +
+
+sorted_without_axis + +```python +node_sorted = onnx.helper.make_node( + 'Unique', + inputs=['X'], + outputs=['Y', 'indices', 'inverse_indices', 'counts'] +) + +x = np.array([2.0, 1.0, 1.0, 3.0, 4.0, 3.0], dtype=np.float32) +y, indices, inverse_indices, counts = np.unique(x, True, True, True) +indices, inverse_indices, counts = specify_int64(indices, inverse_indices, counts) +expect(node_sorted, inputs=[x], outputs=[y, indices, inverse_indices, counts], name='test_unique_sorted_without_axis') +``` + +
+ + +### Unsqueeze +There are 5 test cases, listed as following: +
+unsqueeze_negative_axes + +```python +node = onnx.helper.make_node( + 'Unsqueeze', + inputs=['x', 'axes'], + outputs=['y'], +) +x = np.random.randn(1, 3, 1, 5).astype(np.float32) +axes = np.array([-2]).astype(np.int64) +y = np.expand_dims(x, axis=-2) +expect(node, inputs=[x, axes], outputs=[y], + name='test_unsqueeze_negative_axes') +``` + +
+
+unsqueeze_one_axis + +```python +x = np.random.randn(3, 4, 5).astype(np.float32) + +for i in range(x.ndim): + axes = np.array([i]).astype(np.int64) + node = onnx.helper.make_node( + 'Unsqueeze', + inputs=['x', 'axes'], + outputs=['y'], + ) + y = np.expand_dims(x, axis=i) + + expect(node, inputs=[x, axes], outputs=[y], + name='test_unsqueeze_axis_' + str(i)) +``` + +
+
+unsqueeze_three_axes + +```python +x = np.random.randn(3, 4, 5).astype(np.float32) +axes = np.array([2, 4, 5]).astype(np.int64) + +node = onnx.helper.make_node( + 'Unsqueeze', + inputs=['x', 'axes'], + outputs=['y'], +) +y = np.expand_dims(x, axis=2) +y = np.expand_dims(y, axis=4) +y = np.expand_dims(y, axis=5) + +expect(node, inputs=[x, axes], outputs=[y], + name='test_unsqueeze_three_axes') +``` + +
+
+unsqueeze_two_axes + +```python +x = np.random.randn(3, 4, 5).astype(np.float32) +axes = np.array([1, 4]).astype(np.int64) + +node = onnx.helper.make_node( + 'Unsqueeze', + inputs=['x', 'axes'], + outputs=['y'], +) +y = np.expand_dims(x, axis=1) +y = np.expand_dims(y, axis=4) + +expect(node, inputs=[x, axes], outputs=[y], + name='test_unsqueeze_two_axes') +``` + +
+
+unsqueeze_unsorted_axes + +```python +x = np.random.randn(3, 4, 5).astype(np.float32) +axes = np.array([5, 4, 2]).astype(np.int64) + +node = onnx.helper.make_node( + 'Unsqueeze', + inputs=['x', 'axes'], + outputs=['y'], +) +y = np.expand_dims(x, axis=2) +y = np.expand_dims(y, axis=4) +y = np.expand_dims(y, axis=5) + +expect(node, inputs=[x, axes], outputs=[y], + name='test_unsqueeze_unsorted_axes') +``` + +
+ + +### Upsample +There are 1 test cases, listed as following: +
+nearest + +```python +node = onnx.helper.make_node( + 'Upsample', + inputs=['X', 'scales'], + outputs=['Y'], + mode='nearest', +) + +data = np.array([[[ + [1, 2], + [3, 4], +]]], dtype=np.float32) + +scales = np.array([1.0, 1.0, 2.0, 3.0], dtype=np.float32) + +output = np.array([[[ + [1, 1, 1, 2, 2, 2], + [1, 1, 1, 2, 2, 2], + [3, 3, 3, 4, 4, 4], + [3, 3, 3, 4, 4, 4], +]]], dtype=np.float32) + +expect(node, inputs=[data, scales], outputs=[output], + name='test_upsample_nearest', opset_imports=[helper.make_opsetid("", 9)]) +``` + +
+ + +### Where +There are 2 test cases, listed as following: +
+long + +```python +node = onnx.helper.make_node( + 'Where', + inputs=['condition', 'x', 'y'], + outputs=['z'], +) + +condition = np.array([[1, 0], [1, 1]], dtype=bool) +x = np.array([[1, 2], [3, 4]], dtype=np.int64) +y = np.array([[9, 8], [7, 6]], dtype=np.int64) +z = np.where(condition, x, y) # expected output [[1, 8], [3, 4]] +expect(node, inputs=[condition, x, y], outputs=[z], + name='test_where_long_example') +``` + +
+
+where + +```python +node = onnx.helper.make_node( + 'Where', + inputs=['condition', 'x', 'y'], + outputs=['z'], +) + +condition = np.array([[1, 0], [1, 1]], dtype=bool) +x = np.array([[1, 2], [3, 4]], dtype=np.float32) +y = np.array([[9, 8], [7, 6]], dtype=np.float32) +z = np.where(condition, x, y) # expected output [[1, 8], [3, 4]] +expect(node, inputs=[condition, x, y], outputs=[z], + name='test_where_example') +``` + +
+ + +### Xor +There are 2 test cases, listed as following: +
+xor + +```python +node = onnx.helper.make_node( + 'Xor', + inputs=['x', 'y'], + outputs=['xor'], +) + +# 2d +x = (np.random.randn(3, 4) > 0).astype(bool) +y = (np.random.randn(3, 4) > 0).astype(bool) +z = np.logical_xor(x, y) +expect(node, inputs=[x, y], outputs=[z], + name='test_xor2d') + +# 3d +x = (np.random.randn(3, 4, 5) > 0).astype(bool) +y = (np.random.randn(3, 4, 5) > 0).astype(bool) +z = np.logical_xor(x, y) +expect(node, inputs=[x, y], outputs=[z], + name='test_xor3d') + +# 4d +x = (np.random.randn(3, 4, 5, 6) > 0).astype(bool) +y = (np.random.randn(3, 4, 5, 6) > 0).astype(bool) +z = np.logical_xor(x, y) +expect(node, inputs=[x, y], outputs=[z], + name='test_xor4d') +``` + +
+
+xor_broadcast + +```python +node = onnx.helper.make_node( + 'Xor', + inputs=['x', 'y'], + outputs=['xor'], +) + +# 3d vs 1d +x = (np.random.randn(3, 4, 5) > 0).astype(bool) +y = (np.random.randn(5) > 0).astype(bool) +z = np.logical_xor(x, y) +expect(node, inputs=[x, y], outputs=[z], + name='test_xor_bcast3v1d') + +# 3d vs 2d +x = (np.random.randn(3, 4, 5) > 0).astype(bool) +y = (np.random.randn(4, 5) > 0).astype(bool) +z = np.logical_xor(x, y) +expect(node, inputs=[x, y], outputs=[z], + name='test_xor_bcast3v2d') + +# 4d vs 2d +x = (np.random.randn(3, 4, 5, 6) > 0).astype(bool) +y = (np.random.randn(5, 6) > 0).astype(bool) +z = np.logical_xor(x, y) +expect(node, inputs=[x, y], outputs=[z], + name='test_xor_bcast4v2d') + +# 4d vs 3d +x = (np.random.randn(3, 4, 5, 6) > 0).astype(bool) +y = (np.random.randn(4, 5, 6) > 0).astype(bool) +z = np.logical_xor(x, y) +expect(node, inputs=[x, y], outputs=[z], + name='test_xor_bcast4v3d') + +# 4d vs 4d +x = (np.random.randn(1, 4, 1, 6) > 0).astype(bool) +y = (np.random.randn(3, 1, 5, 6) > 0).astype(bool) +z = np.logical_xor(x, y) +expect(node, inputs=[x, y], outputs=[z], + name='test_xor_bcast4v4d') +``` + +
+ + +
+ +## 💔No Cover Common Operators +### ConcatFromSequence (call for test cases) + + +### GlobalLpPool (call for test cases) + + +### GreaterOrEqual (call for test cases) + + +### LessOrEqual (call for test cases) + + +### LpNormalization (call for test cases) + + +### LpPool (call for test cases) + + +### MaxRoiPool (call for test cases) + + +### Multinomial (random generator operator) + + +### Optional (call for test cases) + + +### OptionalGetElement (call for test cases) + + +### RandomNormal (random generator operator) + + +### RandomNormalLike (random generator operator) + + +### RandomUniform (random generator operator) + + +### RandomUniformLike (random generator operator) + + +### SequenceAt (call for test cases) + + +### SequenceConstruct (call for test cases) + + +### SequenceEmpty (call for test cases) + + +### SequenceErase (call for test cases) + + +### SequenceLength (call for test cases) + + +### SplitToSequence (call for test cases) + + +
+ +## 💚Covered Experimental Operators +
+ +## 💔No Cover Experimental Operators +
+ +# Model Test Coverage +## bvlc_alexnet + +bvlc_alexnet has 24 nodes. Of these, 24 are covered by node tests (100.0%) + + +
+nodes + +
+Conv: 4 out of 6 attributes covered + +auto_pad: 0 +dilations: 0 +group: 1 +kernel_shape: 3 +pads: 3 +strides: 2 +
+
+Dropout: 1 out of 1 attributes covered + +seed: 0 +
+
+Gemm: 1 out of 4 attributes covered + +alpha: 0 +beta: 0 +transA: 0 +transB: 1 +
+
+LRN: 4 out of 4 attributes covered + +alpha: 1 +beta: 1 +bias: 1 +size: 1 +
+
+MaxPool: 3 out of 7 attributes covered + +auto_pad: 0 +ceil_mode: 0 +dilations: 0 +kernel_shape: 1 +pads: 2 +storage_order: 0 +strides: 1 +
+
+ + +## densenet121 + +densenet121 has 910 nodes. Of these, 910 are covered by node tests (100.0%) + + +
+nodes + +
+AveragePool: 3 out of 6 attributes covered + +auto_pad: 0 +ceil_mode: 0 +count_include_pad: 0 +kernel_shape: 1 +pads: 1 +strides: 1 +
+
+BatchNormalization: 1 out of 3 attributes covered + +epsilon: 1 +momentum: 0 +training_mode: 0 +
+
+Concat: 1 out of 1 attributes covered + +axis: 1 +
+
+Conv: 4 out of 6 attributes covered + +auto_pad: 0 +dilations: 0 +group: 1 +kernel_shape: 5 +pads: 4 +strides: 3 +
+
+Dropout: 1 out of 1 attributes covered + +seed: 0 +
+
+Gemm: 1 out of 4 attributes covered + +alpha: 0 +beta: 0 +transA: 0 +transB: 1 +
+
+LRN: 4 out of 4 attributes covered + +alpha: 1 +beta: 1 +bias: 1 +size: 1 +
+
+MaxPool: 3 out of 7 attributes covered + +auto_pad: 0 +ceil_mode: 0 +dilations: 0 +kernel_shape: 1 +pads: 3 +storage_order: 0 +strides: 1 +
+
+Unsqueeze: 1 out of 0 attributes covered + +
+
+ + +## inception_v1 + +inception_v1 has 144 nodes. Of these, 144 are covered by node tests (100.0%) + + +
+nodes + +
+AveragePool: 3 out of 6 attributes covered + +auto_pad: 0 +ceil_mode: 0 +count_include_pad: 0 +kernel_shape: 2 +pads: 2 +strides: 2 +
+
+BatchNormalization: 1 out of 3 attributes covered + +epsilon: 1 +momentum: 0 +training_mode: 0 +
+
+Concat: 1 out of 1 attributes covered + +axis: 1 +
+
+Conv: 4 out of 6 attributes covered + +auto_pad: 0 +dilations: 0 +group: 1 +kernel_shape: 5 +pads: 4 +strides: 3 +
+
+Dropout: 1 out of 1 attributes covered + +seed: 0 +
+
+Gemm: 1 out of 4 attributes covered + +alpha: 0 +beta: 0 +transA: 0 +transB: 1 +
+
+LRN: 4 out of 4 attributes covered + +alpha: 1 +beta: 1 +bias: 1 +size: 1 +
+
+MaxPool: 3 out of 7 attributes covered + +auto_pad: 0 +ceil_mode: 0 +dilations: 0 +kernel_shape: 1 +pads: 3 +storage_order: 0 +strides: 2 +
+
+Unsqueeze: 1 out of 0 attributes covered + +
+
+ + +## inception_v2 + +inception_v2 has 509 nodes. Of these, 509 are covered by node tests (100.0%) + + +
+nodes + +
+AveragePool: 3 out of 6 attributes covered + +auto_pad: 0 +ceil_mode: 0 +count_include_pad: 0 +kernel_shape: 3 +pads: 3 +strides: 2 +
+
+BatchNormalization: 1 out of 3 attributes covered + +epsilon: 1 +momentum: 0 +training_mode: 0 +
+
+Concat: 1 out of 1 attributes covered + +axis: 1 +
+
+Conv: 4 out of 6 attributes covered + +auto_pad: 0 +dilations: 0 +group: 1 +kernel_shape: 5 +pads: 4 +strides: 3 +
+
+Dropout: 1 out of 1 attributes covered + +seed: 0 +
+
+Gemm: 1 out of 4 attributes covered + +alpha: 0 +beta: 0 +transA: 0 +transB: 1 +
+
+LRN: 4 out of 4 attributes covered + +alpha: 1 +beta: 1 +bias: 1 +size: 1 +
+
+MaxPool: 3 out of 7 attributes covered + +auto_pad: 0 +ceil_mode: 0 +dilations: 0 +kernel_shape: 1 +pads: 3 +storage_order: 0 +strides: 2 +
+
+Unsqueeze: 1 out of 0 attributes covered + +
+
+ + +## resnet50 + +resnet50 has 176 nodes. Of these, 176 are covered by node tests (100.0%) + + +
+nodes + +
+AveragePool: 3 out of 6 attributes covered + +auto_pad: 0 +ceil_mode: 0 +count_include_pad: 0 +kernel_shape: 3 +pads: 3 +strides: 2 +
+
+BatchNormalization: 1 out of 3 attributes covered + +epsilon: 2 +momentum: 0 +training_mode: 0 +
+
+Concat: 1 out of 1 attributes covered + +axis: 1 +
+
+Conv: 4 out of 6 attributes covered + +auto_pad: 0 +dilations: 0 +group: 1 +kernel_shape: 5 +pads: 4 +strides: 3 +
+
+Dropout: 1 out of 1 attributes covered + +seed: 0 +
+
+Gemm: 1 out of 4 attributes covered + +alpha: 0 +beta: 0 +transA: 0 +transB: 1 +
+
+LRN: 4 out of 4 attributes covered + +alpha: 1 +beta: 1 +bias: 1 +size: 1 +
+
+MaxPool: 3 out of 7 attributes covered + +auto_pad: 0 +ceil_mode: 0 +dilations: 0 +kernel_shape: 1 +pads: 3 +storage_order: 0 +strides: 2 +
+
+Unsqueeze: 1 out of 0 attributes covered + +
+
+ + +## shufflenet + +shufflenet has 203 nodes. Of these, 203 are covered by node tests (100.0%) + + +
+nodes + +
+AveragePool: 3 out of 6 attributes covered + +auto_pad: 0 +ceil_mode: 0 +count_include_pad: 0 +kernel_shape: 3 +pads: 3 +strides: 2 +
+
+BatchNormalization: 1 out of 3 attributes covered + +epsilon: 2 +momentum: 0 +training_mode: 0 +
+
+Concat: 1 out of 1 attributes covered + +axis: 1 +
+
+Conv: 4 out of 6 attributes covered + +auto_pad: 0 +dilations: 0 +group: 6 +kernel_shape: 5 +pads: 4 +strides: 3 +
+
+Dropout: 1 out of 1 attributes covered + +seed: 0 +
+
+Gemm: 1 out of 4 attributes covered + +alpha: 0 +beta: 0 +transA: 0 +transB: 1 +
+
+LRN: 4 out of 4 attributes covered + +alpha: 1 +beta: 1 +bias: 1 +size: 1 +
+
+MaxPool: 3 out of 7 attributes covered + +auto_pad: 0 +ceil_mode: 0 +dilations: 0 +kernel_shape: 1 +pads: 3 +storage_order: 0 +strides: 2 +
+
+Transpose: 1 out of 1 attributes covered + +perm: 1 +
+
+Unsqueeze: 1 out of 0 attributes covered + +
+
+ + +## squeezenet_old + +squeezenet_old has 66 nodes. Of these, 66 are covered by node tests (100.0%) + + +
+nodes + +
+AveragePool: 3 out of 6 attributes covered + +auto_pad: 0 +ceil_mode: 0 +count_include_pad: 0 +kernel_shape: 3 +pads: 3 +strides: 2 +
+
+BatchNormalization: 1 out of 3 attributes covered + +epsilon: 2 +momentum: 0 +training_mode: 0 +
+
+Concat: 1 out of 1 attributes covered + +axis: 1 +
+
+Conv: 4 out of 6 attributes covered + +auto_pad: 0 +dilations: 0 +group: 6 +kernel_shape: 5 +pads: 4 +strides: 3 +
+
+Dropout: 1 out of 1 attributes covered + +seed: 0 +
+
+Gemm: 1 out of 4 attributes covered + +alpha: 0 +beta: 0 +transA: 0 +transB: 1 +
+
+LRN: 4 out of 4 attributes covered + +alpha: 1 +beta: 1 +bias: 1 +size: 1 +
+
+MaxPool: 3 out of 7 attributes covered + +auto_pad: 0 +ceil_mode: 0 +dilations: 0 +kernel_shape: 1 +pads: 3 +storage_order: 0 +strides: 2 +
+
+Transpose: 1 out of 1 attributes covered + +perm: 1 +
+
+Unsqueeze: 1 out of 0 attributes covered + +
+
+ + +## vgg19 + +vgg19 has 46 nodes. Of these, 46 are covered by node tests (100.0%) + + +
+nodes + +
+AveragePool: 3 out of 6 attributes covered + +auto_pad: 0 +ceil_mode: 0 +count_include_pad: 0 +kernel_shape: 3 +pads: 3 +strides: 2 +
+
+BatchNormalization: 1 out of 3 attributes covered + +epsilon: 2 +momentum: 0 +training_mode: 0 +
+
+Concat: 1 out of 1 attributes covered + +axis: 1 +
+
+Conv: 4 out of 6 attributes covered + +auto_pad: 0 +dilations: 0 +group: 6 +kernel_shape: 5 +pads: 4 +strides: 3 +
+
+Dropout: 1 out of 1 attributes covered + +seed: 0 +
+
+Gemm: 1 out of 4 attributes covered + +alpha: 0 +beta: 0 +transA: 0 +transB: 1 +
+
+LRN: 4 out of 4 attributes covered + +alpha: 1 +beta: 1 +bias: 1 +size: 1 +
+
+MaxPool: 3 out of 7 attributes covered + +auto_pad: 0 +ceil_mode: 0 +dilations: 0 +kernel_shape: 2 +pads: 3 +storage_order: 0 +strides: 2 +
+
+Transpose: 1 out of 1 attributes covered + +perm: 1 +
+
+Unsqueeze: 1 out of 0 attributes covered + +
+
+ + +## zfnet512 + +zfnet512 has 22 nodes. Of these, 22 are covered by node tests (100.0%) + + +
+nodes + +
+AveragePool: 3 out of 6 attributes covered + +auto_pad: 0 +ceil_mode: 0 +count_include_pad: 0 +kernel_shape: 3 +pads: 3 +strides: 2 +
+
+BatchNormalization: 1 out of 3 attributes covered + +epsilon: 2 +momentum: 0 +training_mode: 0 +
+
+Concat: 1 out of 1 attributes covered + +axis: 1 +
+
+Conv: 4 out of 6 attributes covered + +auto_pad: 0 +dilations: 0 +group: 6 +kernel_shape: 5 +pads: 4 +strides: 3 +
+
+Dropout: 1 out of 1 attributes covered + +seed: 0 +
+
+Gemm: 1 out of 4 attributes covered + +alpha: 0 +beta: 0 +transA: 0 +transB: 1 +
+
+LRN: 4 out of 4 attributes covered + +alpha: 2 +beta: 1 +bias: 2 +size: 1 +
+
+MaxPool: 3 out of 7 attributes covered + +auto_pad: 0 +ceil_mode: 0 +dilations: 0 +kernel_shape: 2 +pads: 3 +storage_order: 0 +strides: 2 +
+
+Transpose: 1 out of 1 attributes covered + +perm: 1 +
+
+Unsqueeze: 1 out of 0 attributes covered + +
+
+ + +# Overall Test Coverage +## To be filled. diff --git a/_doc/sphinxdoc/source/onnxmd/onnx_docs/TypeAnnotations.md b/_doc/sphinxdoc/source/onnxmd/onnx_docs/TypeAnnotations.md new file mode 100644 index 00000000..6ba83248 --- /dev/null +++ b/_doc/sphinxdoc/source/onnxmd/onnx_docs/TypeAnnotations.md @@ -0,0 +1,65 @@ + + +# Type annotations for ONNX + +At Facebook, we work with community best practices to ensure high code quality, readability and reliability. In line with this, we just added type annotations to our python code to help ONNX developers more easily contribute to the project. + +These type annotations are used by [mypy](https://github.com/python/mypy) within the ONNX CI systems to ensure a continuously high code quality standard. +We also have type annotations for our APIs, which means your tools built on top of the ONNX APIs can use static analysis tools like mypy to ensure they are using the APIs correctly. + +We expect this to have a positive impact on the reliability of ONNX and dependent projects like ONNX converters - we've also found and fixed a few bugs thanks to the addition of type annotations. + +## What is mypy? +Mypy is an opt-in type checker. Annotations are optional and, if present, will be used for static type checking. While it is not advisable to rely too much on mypy to find all errors (for programmers used to a static type system like in C++, it's often confusing that mypy doesn't find some very obvious typing errors), it is still very helpful given the errors it does find. + +## Using the type annotations in dependent projects +Say, for example, you're building a converter for ONNX, which converts between ONNX models and the models of some machine learning framework. If you use mypy for your project, it will automatically detect the type hints in the ONNX code and use them to check that you read from and wrote to the ONNX model correctly. Doing this will notify you about identifier typos or wrong data types when accessing attributes of the ONNX protocol buffer or other ONNX features. + +## For ONNX contributors +If you're contributing to the ONNX repository, you need to add type annotations to your project or CI will fail. Here is how to install it: + +#### Python 3 +If you're using Python 3, you can simply install mypy as an extra dependency of onnx. + +Call from the top level directory of your onnx repository: + + ~/onnx $ pip install -e .[mypy] + +And then run the type checks: + + ~/onnx $ python setup.py typecheck + +#### Python 2 +The mypy type checker needs python 3 to run (even though it can check python 2 code), so if your onnx development environment is set up with python 2, you need to install mypy into your system python 3 packages (i.e. not into your python 2 virtualenv): + + $ pip3 install mypy + +Running then works as it does above for python 3. + + ~/onnx $ python setup.py typecheck + +Since you've installed mypy manually, you won't get updates for it when we change the version of the mypy dependency in setup.py, so if you're seeing a CI error and can't reproduce it locally, check your mypy version. + +### What should I annotate? + +Type annotations are (usually) only needed for function arguments and return types, mypy will infer local variable types automatically. "Usually" means there are a few exceptions, but mypy will report these if you hit them. + +### What do type annotations look like? +We can't use PEP484 annotations, because we have to support python 2. So we're writing our type annotations in comments. Typed code looks like this: + + def myfunc(arg): # type: (int) -> bool + return arg == 2 + + class MyClass(object): + def __init__(self): # type: () -> None + pass + + def myfunc(self, arg): # type: (int) -> bool + return arg == 2 + + # Alternative notation for many parameters + def myfunc( + arg1, # type: int + arg2, # type: int + ): # type: (...) -> bool + return arg1 == arg2 diff --git a/_doc/sphinxdoc/source/onnxmd/onnx_docs/TypeDenotation.md b/_doc/sphinxdoc/source/onnxmd/onnx_docs/TypeDenotation.md new file mode 100644 index 00000000..0929b4f5 --- /dev/null +++ b/_doc/sphinxdoc/source/onnxmd/onnx_docs/TypeDenotation.md @@ -0,0 +1,56 @@ + + +# Type Denotation + +Type Denotation is used to describe semantic information around what the inputs and outputs are. It is stored on the TypeProto message. + +## Motivation + +The motivation of such a mechanism can be illustrated via a simple example. In the the neural network SqueezeNet, it takes in an NCHW image input float[1,3,244,244] and produces a output float[1,1000,1,1]: + +``` +input_in_NCHW -> data_0 -> SqueezeNet() -> output_softmaxout_1 +``` + +In order to run this model the user needs a lot of information. In this case the user needs to know: +* the input is an image +* the image is in the format of NCHW +* the color channels are in the order of bgr +* the pixel data is 8 bit +* the pixel data is normalized as values 0-255 + +This proposal consists of three key components to provide all of this information: +* Type Denotation, +* [Dimension Denotation](DimensionDenotation.md), +* [Model Metadata](MetadataProps.md). + +## Type Denotation Definition + +To begin with, we define a set of semantic types that define what models generally consume as inputs and produce as outputs. + +Specifically, in our first proposal we define the following set of standard denotations: + +0. `TENSOR` describes that a type holds a generic tensor using the standard TypeProto message. +1. `IMAGE` describes that a type holds an image. You can use dimension denotation to learn more about the layout of the image, and also the optional model metadata_props. +2. `AUDIO` describes that a type holds an audio clip. +3. `TEXT` describes that a type holds a block of text. + +Model authors SHOULD add type denotation to inputs and outputs for the model as appropriate. + +## An Example with input IMAGE + +Let's use the same SqueezeNet example from above and show everything to properly annotate the model: + +* First set the TypeProto.denotation =`IMAGE` for the ValueInfoProto `data_0` +* Because it's an image, the model consumer now knows to go look for image metadata on the model +* Then include 3 metadata strings on ModelProto.metadata_props + * `Image.BitmapPixelFormat` = `Bgr8` + * `Image.ColorSpaceGamma` = `SRGB` + * `Image.NominalPixelRange` = `NominalRange_0_255` +* For that same ValueInfoProto, make sure to also use Dimension Denotations to denote NCHW + * TensorShapeProto.Dimension[0].denotation = `DATA_BATCH` + * TensorShapeProto.Dimension[1].denotation = `DATA_CHANNEL` + * TensorShapeProto.Dimension[2].denotation = `DATA_FEATURE` + * TensorShapeProto.Dimension[3].denotation = `DATA_FEATURE` + +Now there is enough information in the model to know everything about how to pass a correct image into the model. diff --git a/_doc/sphinxdoc/source/onnxmd/onnx_docs/VersionConverter.md b/_doc/sphinxdoc/source/onnxmd/onnx_docs/VersionConverter.md new file mode 100644 index 00000000..5a7c2201 --- /dev/null +++ b/_doc/sphinxdoc/source/onnxmd/onnx_docs/VersionConverter.md @@ -0,0 +1,51 @@ + + +# ONNX Version Converter + +ONNX provides a library for converting ONNX models between different +opset versions. The primary motivation is to improve backwards compatibility of ONNX +models without having to strengthen the spec for ONNX backends. This +allows backend developers to offer support for a particular opset version +and for users to write or export models to a particular opset version but +run in an environment with a different opset version. Implementation wise, the library leverages the in-memory representation that is much more convenient to manipulate than the raw protobuf structs, and converters to and from the protobuf format which were developed for the ONNX Optimizer. + +You may be interested in invoking the provided op-specific adapters, or in +implementing new ones (or both). Default adapters only work in the default +domain, but can be generalized to work cross-domain or utilizing new +conversion methods, dependent on the nature of relevant breaking changes. + +## Invoking The Version Converter + +The version converter may be invoked either via C++ or Python. + +The Python API +is described, with example, +[here](PythonAPIOverview.md#converting-version-of-an-onnx-model-within-default-domain-aionnx). + +The C++ API consists of a single function + +``` +ModelProto ConvertVersion( + const ModelProto& mp_in, + const OpSetID& initial_version, + const OpSetID& target_version); +``` + +which accepts an input `ModelProto`, the initial opset version of the model, +and the target opset verison, and which returns a new `ModelProto` which +is the result of apply all relevant adapters between initial_version and +target_version. For a list of available passes, see +[convert.h](/onnx/version_converter/convert.h). + +## Implementing Adapters + +You can implement a new adapter by subclassing `Adapter`, and registering +your new adapter with `VersionConverter::registerAdapter()`. Adapters operate +on an in-memory graph representation defined in [ir.h](/onnx/common/ir.h). +There are a number of examples in the [adapters](/onnx/version_converter/adapters) +directory. Please ensure that all adapters convert from opset version i to i + 1 +or i - 1, i.e. from Version 6 to Version 5 or vice versa, even if the 2 versions +being converted between are Version 1 and Version 6. + +If your adapter applies in the default domain, please consider adding it +to the core ONNX repository diff --git a/_doc/sphinxdoc/source/onnxmd/onnx_docs/Versioning.md b/_doc/sphinxdoc/source/onnxmd/onnx_docs/Versioning.md new file mode 100644 index 00000000..41065c2f --- /dev/null +++ b/_doc/sphinxdoc/source/onnxmd/onnx_docs/Versioning.md @@ -0,0 +1,184 @@ + + +# ONNX Versioning + +This document describes the rules for versioning ONNX. MUST, SHOULD et al are used consistent with [RFC2119](https://tools.ietf.org/html/rfc2119). + +## Versioning Principles + +ONNX defines the versioning policy and mechanism for three classes of entities: + +* The [intermediate representation (IR) specification](IR.md), which is the abstract model for graphs and operators and the concrete format that represents them. These are always versioned atomically and are referred to as the *IR version*. +* Operator specifications that may be referenced by a given ONNX graph. We refer to this as the *operator version*. +* A defined/trained model that defines a specific graph in terms of specific operators. We refer to this as the *model version*. + +The versioning of all three of these entity types is distinct and largely independent. The IR specification evolves at a different (generally slower) rate than the operator specifications. Model versions are entirely independent of the other two versions. + +Specific policies for version management are mandated only for IR version and operator version. For model versioning, they are merely recommendations. For model versioning, ONNX users and systems MAY follow whichever local customs make sense; however, to facilitate easily managing shared collections of ONNX models, they SHOULD adhere to the policies described under model versioning. + +New IR and operator versions are released as part of ONNX _releases_, which have their own versioning scheme. The release versioning scheme is not described as part of the standard itself. It is discussed in the [ONNX release management document](../RELEASE-MANAGEMENT.md). + +### Semantic Versioning or Simple Numbers? + +The ONNX versioning system allows for simple monotonically increasing numbers or [semantic versioning (SemVer)](https://semver.org/). For IR and operator sets, versioning is based on simple numbers. For models, ONNX does not require any scheme, but recommends a set of shared conventions. + +Which versioning scheme is in use by a model is made clear by inspecting the most significant four bytes, which MUST be non-zero when using semantic versioning and MUST be zero when using simple numbers. In other words, when using SemVer, at least one of the MAJOR or MINOR numbers must be non-zero. + +### SemVer, Files and Consumers + +For model and release versioning, ONNX builds on the principles and syntax defined by [SemVer 2.0.0](http://semver.org/spec/v2.0.0.html). Throughout this document, we use the terms *breaking change*, *non-breaking change*, and *patch* consistent with SemVer 2.0.0. + +Because ONNX models are serialized files (not APIs), it's worth making clear the relationship between a serialized model and a piece of software that consumes that model. As a rough approximation, the serialized model plays the role of an API's *callee*, while the consumer of the serialized model plays the role of the API's *caller*. + +The ONNX versioning principles are based on the [robustness principle](https://en.wikipedia.org/wiki/Robustness_principle): "be conservative in what you do, be liberal in what you accept from others". + +1. A producer of a given ONNX model (and the ONNX specification itself) MUST strictly adhere to the rules for breaking vs. non-breaking changes defined in this specification. +2. A consumer of a given ONNX model SHOULD consume an updated ONNX file, provided there are no breaking changes in the new ONNX file's IR version, referenced operator versions, or model version (meaning the MAJOR version numbers have not changed between the two ONNX files). +3. A consumer of a given ONNX model MAY consume an updated ONNX file, provided there are one or more breaking changes in the new ONNX file's IR version, referenced operator versions, or model version. + +### Serializing SemVer version numbers in protobuf + +For efficiency, ONNX serializes the MAJOR, MINOR, and PATCH values as a bit-packed 64-bit integer; the two most significant bytes are the MAJOR component, the next two most significant bytes are the MINOR component, and the least significant four bytes are the PATCH component. + +For example, *1.2.345* is represented as *0x0001000200000159*. + +Pre-release and build metadata are not stored in the model. + +## IR versioning + +The IR format is versioned using simple numbers, which MUST be monotonically increasing. Breaking changes to the format or semantics of the ONNX specification require an increment of the version. Non-breaking changes to the IR format do not require changing the version number. + +NOTE: breaking changes include those that do not alter the serialized binary format, but still break software using libraries that write or read it. For example, changing the spelling of a message property will cause code accessing the property break. + +The IR format adheres to the versioning guidelines defined in the [Updating a Message Type](https://developers.google.com/protocol-buffers/docs/proto3#updating) section of the proto3 specification. + +As a general principle, implementations SHOULD be robust in the face of missing fields. However, to ensure basic interoperation, a subset of message fields will be marked as required for a given IR version and all producers MUST set these fields correctly. Required fields MUST always be marked with the comment: + + // This field MUST be present for this version of the IR. + +For example, the `ModelProto.ir_version` property MUST be present in every model. The ONNX checker (`onnx/checker.py`) will enforce these rules. + +Because the protocol buffer message definitions (.proto / .proto3 files) are expected to be consumed by multiple independent developers, changes to those definitions SHOULD NOT break code that depends on generated language bindings (e.g., changing the type of an existing field). + +## Operator versioning + +The IR can evolve independently from the set of operators. Operators represent both the signature and semantics of a given operation. Operators are abstract interfaces in that they do not imply a specific implementation; rather, they are simply the contract between a model author and the implementations that model may execute on. + +A given operator is identified by a three-tuple: `(domain, op_type, since_version)`, written as `domain.op_type:since_version` in prose (e.g., `com.acme.FastConv:3`). `since_version` is the version of the operator set that introduced the operator. Breaking operator changes include: + +* Adding/removing/renaming an attribute. This even includes the case of adding a new optional attribute, where omitting the attribute would imply a default value yielding semantics identical to the previous operator version. + +* Adding/removing/reordering inputs or outputs. + +* Adding/removing types supported by inputs and outputs, and changing types used by attributes. + +* Supporting new behavior even when the existing parameter signature is otherwise identical (e.g. implicitly supporting tensor broadcasting in the Mean operator). + +The following are not breaking: + +* Clarifications of specification ambiguities to match prevailing + implementation practice. + +Changes to the semantics of an operator or function MUST be introduced in a new operator, which MUST be introduced in a new [operator set](#operator-sets). + +> In practice, this means that BC-breaking changes in the ONNX +> repository require contributors to follow these steps: +> +> 1. Increment the maximum version in `DomainToVersionRange`. +> 2. Copy the old operator schema to an `old.cc` file. +> 3. Update the `SinceVersion` signifier to the new max version from +> step (1). +> 4. Register the new operator in the corresponding `operator_sets` +> header file. +> 5. Add a version adapter to `convert.h` so that the version +> converter can upgrade the old version of the operator to the new +> one. This can be a `CompatibleAdapter` in case operators following +> the old schema are still valid under the new one (which is usually +> true). +> 6. A version adapter to downgrade the new operator to the older version +> can also be added to `convert.h` but it's not mandatory. + +How nodes bind to operator declarations is strictly defined, and are designed to increase model compatibility across ONNX implementations, in the spirit of the conservative clause of the robustness principle. + +How ONNX implementations bind an operator declaration to a specific implementation is outside the scope of this specification. Implementations of ONNX MAY elect to introduce more sophisticated operator declaration/implementation binding modes, in the spirit of the liberal clause of the robustness principle. + +### Operator sets + +ONNX uses operator sets to group together immutable operator specifications. An operator set represents a specific version of a domain, indicated by a pair (domain, version). This represents the set of all operators belonging to the specified domain with the specified version (referred to as the `opset_version`). When the inventory of a given operator set changes either by addition, removal, or a change in semantics of a contained operator, its version MUST increase. + +Models declare which operator sets they require as a list of `(domain, opset_version)` pairs in `ModelProto.opset_import`. The empty string ("") domain indicates the operators defined as part of the ONNX specification; other domains correspond to operator sets of other vendors (meaning they can be used to provide vendor-specific extensions to ONNX). The union of the operator sets specified by a given model MUST have a compatible operator declaration for each node in the model's graph. + +### Example + +This section is not normative and informational only. + +Given the following operator sets: + +OpSet|Operators|Comments +-|-|- +1|{A} | A introduced +2|{A, B} | B introduced +3|{A', B, C} | A updated (to A'), C introduced +4|{B, C'} | A removed, C updated (to C') + +The operators for a given operator set will have the following `since_version` values: + +Operator|OpSet 1|OpSet 2|OpSet 3|OpSet 4 +-|-|-|-|- +A|**1** |1 |**3** |**-** +B|- |**2** |2 |2 +C|- |- |**3** |**4** + +Notes: +- Values that are new or updated from a previous OpSet version are in **bold**. + +## Model versioning + +This section of the specification is not normative. It simply outlines a set of recommended practices. + +Model authors and applications/systems MAY elect to ignore the model versioning mechanism and policy rules. For models that will be shared across developers, teams, or organizations, model authors and applications/systems SHOULD adhere to the following version policies: + +### Signature Changes + +1. Breaking changes to the ModelProto.graph.GraphProto.input or .output MUST increment the MAJOR version of `ModelProto.model_version`. Breaking changes include: + + * Breaking changes to the semantics of an input or output (e.g., changing the required contents of an input tensor from a color image to a black and white image). + * Changing the declared type of an input or output to an incompatible type (e.g., `tensor(int)->tensor(string)`). + * Adding a new input for which there is no meaningful or specified default value. Recall that default values for inputs are specified in the initializer list. + * Removing an existing output for which there is no meaningful or specified default value. + +2. Non-breaking changes to the ModelProto.graph.GraphProto.input or .output MUST increment the MINOR version of `ModelProto.model_version`. Non-breaking changes include: + + * Changing the declared type of an input or output to a compatible/widening type (e.g., `tensor(int32)->tensor(int64)`, `tensor(float16)->tensor(float32)`). + * Adding a new input for which there is a meaningful or specified default value. + * Adding new behavior that is only triggered in the presence of inputs that were not + possible in prior versions of the graph (typically by the presence of a new input + or allowing a previously invalid input value). + +### Accuracy or performance changes + +Changes that impact accuracy or performance significantly but do not change the model's inputs or outputs SHOULD increment the PATCH version of `ModelProto.model_version`. + +## Released Versions + +ONNX version|IR version|Opset version ai.onnx|Opset version ai.onnx.ml|Opset version ai.onnx.training +------------|-------------------|---------------------|------------------------|------------------------------ +1.0|3|1|1|- +1.1|3|5|1|- +1.1.2|3|6|1|- +1.2|3|7|1|- +1.3|3|8|1|- +1.4.1|4|9|1|- +1.5.0|5|10|1|- +1.6.0|6|11|2|- +1.7.0|7|12|2|1 +1.8.0|7|13|2|1 +1.8.1|7|13|2|1 +1.9.0|7|14|2|1 +1.10.0|8|15|2|1 +1.10.1|8|15|2|1 +1.10.2|8|15|2|1 + +A programmatically accessible version of the above table is available [here](../onnx/helper.py). Limited version number +information is also maintained in [version.h](../onnx/common/version.h) and [schema.h](../onnx/defs/schema.h). +Please update all whenever a new version of ONNX is released. diff --git a/_doc/sphinxdoc/source/onnxmd/onnx_docs/images/onnx_hub_arch.svg b/_doc/sphinxdoc/source/onnxmd/onnx_docs/images/onnx_hub_arch.svg new file mode 100644 index 00000000..e79453af --- /dev/null +++ b/_doc/sphinxdoc/source/onnxmd/onnx_docs/images/onnx_hub_arch.svg @@ -0,0 +1 @@ +Git LFS StorageONNX Hub ArchitectureM1 v2M2 v3MN v1M1 v1M1 v2M1 v2onnx/models RepoMANIFEST.jsonM1 v2 PointerM2 v3 PointerMN v1 Pointeronnx/onnxRepoONNX Hub Python ClientLocal MachineLocal Processimport onnxmodel = onnx.hub.load(‘modelN’)Model CacheMN v1 \ No newline at end of file diff --git a/_doc/sphinxdoc/source/onnxmd/onnx_docs/proposals/ArchiveFileFormatProposal.md b/_doc/sphinxdoc/source/onnxmd/onnx_docs/proposals/ArchiveFileFormatProposal.md new file mode 100644 index 00000000..1a731b85 --- /dev/null +++ b/_doc/sphinxdoc/source/onnxmd/onnx_docs/proposals/ArchiveFileFormatProposal.md @@ -0,0 +1,45 @@ + + +# ONNX File Format Proposal + +## Summary + +We propose a new file format for ONNX models that is a specific application of the [zip](https://en.wikipedia.org/wiki/Zip_(file_format)) file format. We would like to address issues with capacity limits as well as (de)serialization inefficiencies[0][1]. We aim to design a file format that is simple, widely applicable, and efficient. By storing Tensor values (i.e. values typically contained in `TensorProto` messages) as files within a zip archive, we avoid these size limitations and—with special constraints—allow for direct memory-mapping of an ONNX file such that weights can be used directly from the memory-mapped region. Using zip as our base file format allows us to create a design that is conceptually simple as well as well-supported on various platforms. + +## Design + +We propose to treat a .zip file as a key-value store, mapping string keys (filenames) to binary data files. For ONNX model serialization, we will have the following entries: + + +* Data files - Files mapping a unique string identifier to a raw binary data file. These files shall be referenced from the appropriate fields within the base `ModelProto` +* `__MODEL_PROTO` - File that contains the `ModelProto` describing the file + + +Note that the order is significant here. We place the model definition file at the end of the archive to allow for the common case of net manipulations while keeping the weights invariant. This way, tools that manipulate the archive do not need to repack or realign all weights when only touching the model file. + +Within the ONNX protobuf definition, we propose the following changes: + + +* Add `optional string external_data` to `TensorProto`. This can be treated as a data field similar to `float_data`, `int_data`, etc in that there must be exactly one of those fields specified. If a `TensorProto` specifies `external_data`, the implementation shall resolve this reference by string key in the containing zip archive. All values of `external_data` must be unique (under down-casing) and conform to the C identifier specification. + + +Raw data files referenced by `TensorProto`s shall conform to the following specification: + + +* The data shall be equivalent to that stored within the `raw_data` field in `TensorProto`. +* Raw data files within the zip archive shall reside on an alignment boundary of 64 bytes. That is, the byte offset within the file of the first byte of a raw data tensor must be divisible by 64. This requirement can be fulfilled by packing bytes into the `extra` field of each local file record in the zip archive. (example: [2]). This constraint facilitates the direct memory-mapping of data files within the archive, and allows for architectures with both strict alignment requirements (e.g. SIMD instructions on aligned data) to operate and give architectures that operate more efficiently on cache line-aligned data to take full advantage. + +## File Extension + +In keeping with other domain-specific zip applications, we propose to use a custom file extension rather than the `.zip` extension. A custom file extension makes it clear to the user that this is not a general zip file, but rather a file that should be emitted by ONNX tools to conform to the spec. + + +## Future-Proofing Considerations + +This file format represents a generic key-value store that is scalable to many entries as well as large values. Further improvements to the format may come in the form of supporting different or multiple model definitions within the same model, or modifying the way in which weight files are stored. Building off of a proven archival format allows us the reliability as well as flexibility of zip. + + + +[0] https://github.com/onnx/onnx/issues/251 +[1] https://stackoverflow.com/questions/34128872/google-protobuf-maximum-size +[2] https://developer.android.com/studio/command-line/zipalign.html implementation https://github.com/aosp-mirror/platform_build/blob/master/tools/zipalign/ZipAlign.cpp diff --git a/_doc/sphinxdoc/source/onnxmd/onnx_docs/proposals/FunctionsProposal.md b/_doc/sphinxdoc/source/onnxmd/onnx_docs/proposals/FunctionsProposal.md new file mode 100644 index 00000000..05565650 --- /dev/null +++ b/_doc/sphinxdoc/source/onnxmd/onnx_docs/proposals/FunctionsProposal.md @@ -0,0 +1,21 @@ + + +## Proposal Adding Function into ONNX + +Motivation: +1. Reduce number of primitive operators in ONNX +To make it easier for hardware vendors to follow ONNX, we want to make it possible to define composite operators in terms of more primitive operators, reducing the number of kernels which must be directly implemented. For example, FC should be declared to be a composition MatMul and Add. + +2. Expose customize function capability for graph optimization. +To provide a mechanism of doing graph optimization, say, kernel fusion (merge a subgraph into one node with generated efficient kernel codes). This will in turn help HW acceleration, since common-patterns of kernel fusion may be pre-defined as common functions in ONNX and no sub-graph (function) finding needed for kernel fusion anymore. For example, subgraph having "Add", "Sigmoid", "Tanh", "Mul" nodes could be merged into one fusion node with generated cuda kernel containing "+", "sigmoidf", "tanhf", "*". + +3. Provide a flexible RNN implementation. +To define a library of RNN cells and allow the user to write a custom one. + +MAJOR CHANGES: +1. FunctionProto added to represent a function. +2. FunctionSetProto added to represent a function set. +3. AttributeProto updated to support function attribute type and allow attribute reference. +4. ModelProto updated to contain customized function set. + +Prototype details can be found [here](https://github.com/linkerzhang/onnx/blob/kezhan/add_function_private/onnx/onnx.in.proto) diff --git a/_doc/sphinxdoc/source/onnxmd/onnx_docs/proposals/NLPinONNXproposal.md b/_doc/sphinxdoc/source/onnxmd/onnx_docs/proposals/NLPinONNXproposal.md new file mode 100644 index 00000000..fae2058f --- /dev/null +++ b/_doc/sphinxdoc/source/onnxmd/onnx_docs/proposals/NLPinONNXproposal.md @@ -0,0 +1,69 @@ + + +## Background + +Modern NLP (Natural Language Processing) is an important domain in which deep learning is applied. In addition, modern NLP networks are often non-trivial to implement and even more difficult to transfer between frameworks. These networks are handled fairly non-uniformly across the landscape of frameworks. The ability for ONNX to interchange these networks can be a very compelling feature. + +NLP networks, including recurrent networks, are often built on dynamic control structures. Standardizing the handling of these structures can lead to better collaboration with backends to expose network semantics and achieve better performance. A tradition has developed within the Computer Vision field for optimizing hardware backends for canonical vision models, such as ResNet-50. There is not really such as tradition in the NLP field, however. Through standardizing the representation of NLP networks, we can give vendors a common representation and push forward the performance of NLP models. + +## Ultimate Goal and Challenges + +We should work toward being able to represent major classes of NLP model architectures. One example of such an architecture is the seq2seq with attention model (e.g. https://arxiv.org/abs/1409.0473). This architecture is used for many use cases, including neural machine translation, speech processing, summarization, dialog systems, image captioning, and syntax parsing, among many others. At the same time, seq2seq with attention is sufficiently complex that supporting it will push forward the state of the art in ONNX, but not so complex that we'd need to define a full programming language. + +seq2seq with attention can roughly be broken down into these constituent parts: + +* An Encoder network + * This network takes a sequence of tokens and yields a sequence of embeddings representing the context found at each time-step + * Major classes of encoders: recurrent network (e.g. LSTM[1]), convolutional[2], attention[3]. + * Requirements from an ONNX representation + * Recurrent network - general recurrent network structures preserving outputs at every timestep. Handling of padding and hidden states for batches with different sequence lengths). + * Convolutional - 1d convolution, position embeddings + * Attention - sinusoid position encodings, layer normalization +* A Decoder network + * This network generates a sequence token by token, parameterized by the context provided from the encoder. + * Yields a probability distribution over possible tokens given previous context and encoder context. + * Major classes of decoders: recurrent network (e.g. LSTM), convolutional (causal, temporal for generation), attention. + * Generation requires dynamic control flow. Often, this is done as a beam search, so this is distinct from regular recurrent networks. + * Model-specific requirements + * Recurrent network - Recurrent network cell that can be used within the context of beam search + * Convolutional - 1d causal convolution (only see previous timesteps) + * Attention - sinusoid position encodings, masking along diagonal +* An Attention mechanism + * This network weights the Encoder contexts based on the Decoder's generation state, and provides a focused Encoder context to the decoder. The Decoder “focuses” on a certain part of the input sequence at each timestep via this mechanism. + * Many classes of attention mechanism: some examples are here https://arxiv.org/pdf/1508.04025.pdf + + +Vanilla seq2seq with attention and non-backtracking beam search does NOT include things such as auxiliary data-structures (e.g. stacks), thus it does not require us to implement the full semantics of a programming language. It is an architecture that we can break down into incremental improvements to ONNX without compromising ONNX's fundamental goal. + +[1] https://arxiv.org/abs/1409.0473 +[2] https://arxiv.org/abs/1705.03122 +[3] https://arxiv.org/abs/1706.03762 + +## Standard Recurrent Network Constructs + +Standard recurrent network architectures such as LSTM or GRU are very common, and we can get very far supporting these. We already have the [LSTM](https://github.com/onnx/onnx/blob/master/docs/Operators.md#LSTM) and [GRU](https://github.com/onnx/onnx/blob/master/docs/Operators.md#GRU) operators, which execute the standard LSTM and GRU[4] operations over a sequence of inputs. These high-level operators are great, since they give backends a semantic view of the computation to be performed, and thus backends can make informed decisions about optimization. Many NLP use cases can get away with using just these operators. + +[4] http://colah.github.io/posts/2015-08-Understanding-LSTMs/ + +## Generic Control Flow + +Once we move beyond the domain of standard LSTM and GRU operations, we need a more generic abstraction onto which we can map NLP architectures. A simple example is how one can implement Multiplicative Integration LSTM (https://arxiv.org/pdf/1606.06630.pdf) in ONNX. We can expose a standard LSTMCell via the proposed Function abstraction (https://github.com/onnx/onnx/issues/481). Building on top of this, we can construct a MI-LSTM by applying the required second-order transformations to the inputs to the LSTMCell. Once we have this aggregated implementation, we can use the generic control flow operators (https://github.com/onnx/onnx/pull/436) to apply this “composite” MI-LSTM cell over a sequence. + +Of course, the dynamic control flow constructs can be used for more general use cases. For example, consider the [beam search](https://en.wikipedia.org/wiki/Beam_search) used often in NLP for sequence generation. This algorithm has several tricky aspects: a (potentially) dynamic stopping condition, a desired maximum trip count (so we don't fall into an infinite loop), loop-carried dependencies, and the desire to preserve the outputs at every time-step, not just the final time-step. Inherently, this is an imperative algorithm that operates on mutable state. The proposed control flow operators in ONNX, however, fulfill all of these requirements, and thus we can represent many instances of sequence generation in ONNX graphs. + +Note that there are more general forms of beam search, such as those including backtracking, but we are not considering these forms for this focused proposal. + + +## End-to-end Example : seq2seq with attention + +We should endeavor to have full support for seq2seq with attention models in ONNX. Facebook is currently working on this internally and creating a pytorch→ONNX→caffe2 pathway. An example of such a model we'd like to represent in ONNX is [fairseq-py](https://github.com/facebookresearch/fairseq-py). We would love to engage with the community and collaborate on anything that will help make this a reality. Additionally, if the community has any other suggestions for prominent NLP models we should be able to represent, we would love to hear your ideas. + +## Further Challenges + +Beyond the constructs used in seq2seq with attention, there are NLP models that exist today that contain more non-trivial features, such as mutable data structures that are manipulated at runtime. Examples of this include back-tracking beam search and parser models such as RNNG (https://arxiv.org/abs/1602.07776). These will present further challenges for ONNX, and the representation of these models will likely remain tied to application code for the time being. We may want to revisit this class of models in the future. + +Another thing we should consider is how to handle preprocessing and postprocessing routines for NLP models. For example, do we defer tokenization, normalization, and index lookup to application code? And how do we, for example, distribute dictionaries that map tokens to indices. Initially this will probably remain out of the scope of ONNX unless there is a good story for standardizing text processing. + +## Conclusion + +We have presented a proposal for a strategy for representing NLP models in ONNX, using seq2seq with attention as a canonical example that covers many use cases. We would like to hear your thoughts about this proposal and to explore opportunities for collaboration with the ONNX community for making ONNX a pleasure to use for NLP. Please feel free to voice your opinions! diff --git a/_doc/sphinxdoc/source/onnxmd/onnx_docs/proposals/ONNXIFIproposal.md b/_doc/sphinxdoc/source/onnxmd/onnx_docs/proposals/ONNXIFIproposal.md new file mode 100644 index 00000000..6980f854 --- /dev/null +++ b/_doc/sphinxdoc/source/onnxmd/onnx_docs/proposals/ONNXIFIproposal.md @@ -0,0 +1,116 @@ + + +# ONNX Interface for Framework Integration: API Proposal + +## Background + +Leading hardware and systems vendors offer highly optimized software to run neural network graphs. These software can deliver order-of-magnitude speedups compared to generic implementations, but their integration with deep learning frameworks and applications is complicated by large variety in vendor-specific interfaces, and subtle incompatibilities with the software stack of high-level applications. + +So far, ONNX format targets the problem of offline conversion of neural network models between different high-level frameworks and vendor-specific libraries through offline translation. In this proposal, we suggest that ONNX ecosystem could be enriched to enable runtime discovery and selection of high-performance graph execution backends, and online (in runtime) conversion of ONNX graph to internal representations of these implementations. + +## Ultimate Goal + +We should strive for consensus on a library API to interface with optimized backends and offload parts of ONNX graphs to these high-performance hardware and software implementation. The API should enable wide interoperability between high-level deep learning frameworks, software implementations of optimized graph runtimes, and existing and upcoming neural network acceleration hardware. + +The standardized API should reduce friction in deploying neural network models for all involved parties: +- Applications would be able to ship only one version of a neural network model (either in ONNX format, or in the format of their deep learning framework, and convert it on the fly to ONNX). +- Deep learning frameworks would be able to integrate with many hardware vendors by using only a single interface. +- Hardware vendors would be able to implement only one interface and get integration with many deep learning frameworks. + +## Design Choices + +- Interface must use only highly portable aspects of C ABI. +- Neural network graphs are passed as serialized ONNX ModelProto messages. To avoid serialization overhead, weights can be passed as raw memory blobs. +- Input and output tensors are allocated by the caller and use NCHW layout. +- Intermediate tensors are allocated by the vendor implementation, and can use any layout. +- Backends (software implementations and hardware accelerators) are discovered, selected, and initialized on-demand in run-time. Multiple backends can be used in the same application simultaneously. +- There is no minimal set of ONNX operators to implement. The implementer and the user (a deep learning framework) of the API decide which operators can and will be offloaded in runtime. +- The proposal includes the minimal functionality to let deep learning frameworks and vendor libraries work together. Several extension mechanisms can be used for more efficient vendor- or platform-specific functionality. + +## Proposed Interface + +We propose a small C-based API, which includes the following functionality: + +* Discover (`onnxGetNumBackends`) and query information (`onnxGetBackendInfo`) about high-performance backends +* Initialize (`onnxInitBackend`) and deinitialize (`onnxReleaseBackend`) high-performance backends +* Query if a backend supports an ONNX operator with particular parameters and input shapes (`onnxGetBackendCompatibility`) +* Convert an ONNX graph to opaque vendor-specific representation of a backend (`onnxInitGraph`) +* Specify memory locations and metadata about graph inputs and outputs (`onnxSetGraphIO`) +* Run an ONNX graph, converted to vendor-specific representation (`onnxRunGraph`) +* Release the vendor-specific representation of a graph and associated resources (`onnxReleaseGraph`) + +## General Use Pattern for Deep Learning Frameworks + +1. The user (deep learning framework) iterates operators in a model graph one-by-one, convert them to ONNX, and calls `onnxGetBackendCompatibility` to check which of the operators can be offloaded to the backend. +2. The user constructs connected subgraphs of operators that can be offloaded to the backend. +3. (Optional) For each subgraph, the user estimates if it is beneficial to offload it to the optimized backend: + + a. The user queries the backend about it high-level performance characteristics using `ONNX_BACKEND_MACS_*` and `ONNX_BACKEND_MEMORY_BANDWIDTH` information queries. These data let the user build a simple roofline model of backend performance. + + b. For every subgraph the user estimates time to do inference using the roofline model. + + c. The user additionally estimates time to transfer subgraph inputs to the backend using `ONNX_BACKEND_CPU_MEMORY_READ_BANDWIDTH` information query and to transfer subgraph outputs from the backend using `ONNX_BACKEND_CPU_MEMORY_WRITE_BANDWIDTH`. + + d. If predicted time to transfer inputs to the backend, do inference, and transfer outputs from the backend exceeds predicted time to do the inference on default engine (e.g. CPU), the user falls back to a different ONNX backend, or to the default engine. + + +4. The user initialized the backend, and offloads the subgraph execution to the ONNX backend by calling `onnxInitGraph`, `onnxSetGraphIO` and `onnxRunGraph` + +## Implementation Notes + +### Backend object + +Backend is a combination of software library and hardware device. The same device (e.g. "NVIDIA Tesla P100 on CUDA index #0" accessed though different software libraries would be seen as different backends. A single software library can expose multiple backends, one per device (e.g. each CUDA GPU in a system is exposed as a separate backend, or CPU, GPU, and DSP on a mobile chipset are exposed as three different backends). + +We recommend that vendors make the backend object reference-counted, and use `uint32_t magic` as the first data field of the object: + +```c +struct MyBackend { + uint32_t magic; + uint64_t referenceCount; + ... +}; + +/* This line won't compile, but gives you an idea of relation between MyBackend structure and onnxBackend type. */ +typedef MyBackend* onnxBackend; +``` + +Magic is an arbitrary 32-bit integer unique for a library implementing the API. It should be used to verify that the backend object passed to `onnxInitGraph` was created by `onnxInitBackend` in the same library. + +### Graph object + +Graph object is a vendor-specific representation of ONNX ModelProto message. Graph is logically related to the backend used to create it, and a typical implementation of a graph object would hold a reference to its backend object. + +We recommend that vendors use `uint32_t magic` as the first data field of the graph object: + +```c +struct MyGraph { + uint32_t magic; + struct MyBackend* backend; + ... +}; + +/* This line won't compile, but gives you an idea of relation between MyGraph structure and onnxGraph type. */ +typedef MyGraph* onnxGraph; +``` + +Magic is an arbitrary 32-bit integer unique for a library implementing the API. It should be used to verify that the backend object passed to `onnxInitGraph` was created by `onnxInitBackend` in the same library. Magic for a graph object should be different from magic of a backend object of the same library. + +### Library initialization + +During one-time library initialization, the implementation of the API would detect `n` supported devices and map them to backend indices in `0...(n-1)` range. The implementation of device discovery and checking required device characteristics is highly vendor- and platform-specific, e.g.: +- A CPU implementation may always expose 1 device. +- A CUDA-based implementation may call `cudaGetDeviceCount` to get the number of CUDA-enabled devices, then + call `cudaGetDeviceProperties` for each device, and map CUDA devices which satisfy the minimum required functionality, such as compute capability, to backend indices. +- An OpenCL-based implementation for a mobile GPU would try to load OpenCL library, call `clGetPlatformIDs` and `clGetPlatformInfo` to find a supported platform, then call `clGetDeviceIDs` and `clGetDeviceInfo` to find a supported GPU device, and map it to the only exposed backend if such device exists, or expose 0 devices otherwise. +- An implementation for hardware neural network accelerators would call vendor-specific driver API to discover accelerator devices installed in the system and map them to backend indices. + +We recommend that library initialization is triggered on the first call to `onnxGetNumBackends`, `onnxGetBackendInfo`, or `onnxInitBackend`. Using a global static C++ object for initialization may hurt portability if library initialization involves loading other shared libraries (DLLs): on Windows `LoadLibrary` function can't be used in initializers of global static objects. + +### onnxGetNumBackends + +Implementation would [initialize the library](#library-initialization), if it wasn't initialized already, and return the number `n` of available backends. + +### onnxGetBackendInfo + +Implementation would [initialize the library](#library-initialization), if it wasn't initialized already, and query information about the backend using vendor- or platform-specific API (e.g. `cudaGetDeviceProperties`, `clGetDeviceInfo`, CPUID instruction). Implementation can cache this information when it is first queried or during initialization, and return the cached value. diff --git a/_doc/sphinxdoc/source/onnxmd/onnx_docs/proposals/SymbolicShapeInfProposal.md b/_doc/sphinxdoc/source/onnxmd/onnx_docs/proposals/SymbolicShapeInfProposal.md new file mode 100644 index 00000000..b669cd6f --- /dev/null +++ b/_doc/sphinxdoc/source/onnxmd/onnx_docs/proposals/SymbolicShapeInfProposal.md @@ -0,0 +1,163 @@ +# Proposal - Symbolic Shape Inference And Partial Data Propagation + +*Note: This proposal was accepted and implemented in ONNX 1.10. Following PRs implemented this proposal: 3518, 3551, 3593, 3580* + +## Introduction +ONNX provides an implementation of shape inference on ONNX graphs. Shape inference is computed using the operator level shape inference functions. The inferred shape of an operator is used to get the shape information without having to launch the model in a session. Such static shape inference can be used to catch obvious errors before runtime, eliminate run-time checks which are otherwise guaranteed to pass, improve static memory planning and improve model visualization experience. For pytorch exporter and compiler-based execution providers like Nuphar, shape inference is required (rank inference is minimum requirement), and they cannot work with unknown shapes. + +This document explains the limitations of shape inference and lays out a proposal for addressing these limitations. + +## Current onnx shape inference limitations (Pre ONNX 1.10) +Today, ONNX shape inference is not guaranteed to be complete. Wherever possible we fall back to rank inference however, there are scenarios when rank inference is not possible either. Here are the various limitations which block the completion of shape inference: + +1. Some dynamic behaviors block the flow of shape inference, and the shape inference stops. For example, reshape to a dynamically computed shape. + +2. Shape inference works only with constants and simple variables. It does not support arithmetic expressions containing variables nor does it support symbol generation. For example, concatenation on tensors of shapes (5, 2) and (7, 2) can be inferred to produce a result of shape (12, 2), but concatenation on tensors of shapes (5, 2) and (N, 2) will simply produce (?, 2), where “?” represents a dimension with neither dim value nor dim param, rather than containing a representation of N+5 or generating a new symbol (M, 2). In such scenarios shape propagation stops. + +3. All operators are not required to have a shape inference implementation. When such an op is encountered the shape inference stops. There are also cases when rank inference is not done as a fallback mechanism. (Note: We are working on an ongoing basis to identify and fix such issues. The current document does not focus on this limitation) + + +## Goals and Non-Goals +Our **goal** is to fix the shape inference gap in scenarios where: + +* Shape computations are done in branches (refer to limitation 1) + +* Symbolic dimensions are present (refer to limitation 2) + +By fixing these gaps we aim to: + +* Unblock pytorch exporter from exporting models when exporting stops because of absence of shape information. + +* Improve static memory planning in the runtimes. + +* Enable pre-allocating output buffers outside of the runtimes so that its lifetime can be managed by the caller itself. + + +### Non-goals +* Add symbolic expressions to ONNX standard: This is not necessary for accomplishing our goals. There are advantages to having this capability, for example this can significantly reduce the number of symbols introduced and it can also provide more deterministic shape calculations in certain special cases. However, the tradeoff is the added complexity. So, at this point we are not considering it. This can be considered in future iterations. + +* Enable data computation and propagation for older operator sets. (details in the proposal section) + +Note: This work will benefit Nuphar as well but right now there is no plan to move Nuphar to use this solution. + + +## Terminology +Shape inference can be broken into 2 parts: + +* Node level shape inference: This refers to operator specific shape inference functions. They are defined with the operator schema itself. + +* Graph-level shape inference: This refers to the higher-level logic which walks through the entire graph, gets the inferred shape from node level shape inference functions and then makes decisions on merging these inferred shapes with existing shapes so that they are available for downstream nodes. + + +## Proposal +Extend current shape inference to allow: +* Symbol generation and propagation + +* Partial data computation and propagation + +* Extend shape op to generate slice of the shape to facilitate simplifying shape computations. + + +## Extend shape inference + +### Symbol generation and propagation +Extend graph level shape inference to maintain a graph level view of symbols and generate new symbols where necessary. This will enable us to continue the shape inference of the downstream nodes. + +Example: + +For an op like “Concat” if its inputs have shapes “[M]” and “[N]” current shape-inference returns “[?]” where “?” is to indicate a dimension with neither dim-value nor dim-param set. Now, suppose the output X of “Concat” is input to a unary-op Op1() whose output Y is then input to another unary-op Op2() whose output is Z, etc. The shape “[?]” is propagated further. We infer that Y and Z have shape “[?]”. However, we do not infer that X, Y, and Z have the same shape because two “?” cannot be considered equal. + +Per the current proposal, “[?]” in inferred shapes will be replaced by a new unique symbol by the graph level shape inference so the downstream nodes can use the symbolic shapes to carry out shape inference. In the current example, “Concat” will produce “[?]” as the shape which will then be replaced by “[K]”, then subsequent shape inference will infer that X, Y, and Z all have the same shape “[K]”. Runtimes can use this information to reuse memory for these tensors. + + +### Partial data computation and propagation +When shape inputs are computed dynamically, shape inference post a reshape node stops. This can be prevented by making this data available to the reshape node during shape inference. We propose computation and propagation of data for operators which are used in shape computation. + +It is called “partial” data computation and propagation because this will only be done for shape computations. It is not meant to be a full-fledged kernel for the operator. For the same reasons data computations will be implemented for a limited set of operators. While we will increase the coverage in the future iterations it is important to note that for some operators like LSTM, convolution ops, pooling ops etc. data propagation function will never be added because such ops are not used in shape computations. + +The following operators will be picked in the first phase. (These operators are generally used for shape computations.) + +| Ops | +| --------| +| Add | +| Sub | +| Mul | +| Cast | +| Concat | +| Gather | +| Reshape | +| Shape | +| Slice | +| Size | +| Squeeze | +| UnSqueeze | + +The OpSchema class will be extended to include an optional “PartialDataPropagationFunction” like the existing TypeAndShapeInferenceFunction. This function will provide data computation for the operators which will then be propagated to the downstream operators by the graph level shape inference. PartialDataPropagationFunction will be called by the graph level shape inference after TypeAndShapeInference runs for the node because the output shape is required for partial data computation. + +A new interface "DataPropagationContext” will be added to allow PartialDataPropagationFunction to access all the information required to propagate shape data for the given node and allow writing of the computed data. + +Example: + +``` +using DataPropagationFunction = std::function + +class OpSchema final { + + public: + . + . + . + + OpSchema& PartialDataPropagationFunction(DataPropagationFunction dataPropagationFunction)  { +   partial_data_propagation_function_ = std::move(dataPropagationFunction); +   return *this; + } + + DataPropagationFunction GetDataPropagationFunction() const { +    return partial_data_propagation_function_ ? partial_data_propagation_function_ : dummyDataPropogator; + } +} + +// Operator schema example +ONNX_OPERATOR_SET_SCHEMA( +    Shape, +    13, +    OpSchema() +        .SetDoc(“”) +        .Input(0, "data", "An input tensor.", "T", . . .) +        .Output(0, "shape", "Shape of the input tensor", "T1", . . .) +        .TypeConstraint("T", OpSchema::all_tensor_types()) +        .TypeConstraint("T1", {"tensor(int64)"}) +        .TypeAndShapeInferenceFunction([](InferenceContext& ctx) { + . . . +        }) + +        .PartialDataPropagationFunction([](DataPropagationContext& ctx) { + TensorShapeProto tp; + // compute output data for shape operator + // add computed data to DataPropagationContext for propagating it downstream +          ctx.addOutputData(0, std::move(tp)); +        })); +``` + +The symbol generation will happen at the graph level shape inference, therefore all the models (older opsets as well as the latest opset versions) can benefit from this enhancement. However, the data computation and propagation are tied to the OpScehma and will happen at node level. To begin with these functions will only be added to the latest op schemas. Older schemas can be extended to support data computation later, on a case by case basis to support some high priority scenarios. What this means is that older opset models will not benefit from shape inference improvements because of this enhancement. + + +## Special Cases +This section considers some edge cases and proposes a solution to handle them. + + +### Broadcasting with symbolic dims +If we have a broadcast between two unknown dimensions “M” and “N” we cannot infer that both M and N should have the same value. The runtime semantics allows for one of the two symbols to have the value 1 and the other to have a value different from 1. So, merging M and N and treating them as the same value is potentially unsound. In this case, a new symbol will be generated for the output shape and the shape inference will continue. + + +### Inferred shape does not match output shape +Inferred and existing shapes can be mismatched. Although failing shape inference in such cases seems like the correct approach it may not always be practical. By default, shape inference will fail when such a case is encountered however callers will have an option to override existing types with inferred types. When this option is enabled, shape inference will continue with the inferred type. + + +### Handling symbolic dimensions with data propagation +When the shape contains symbolic dimensions, we try and propagate them downstream, however in cases where some arithmetic operations are performed on these symbolic dims we create new symbols and propagate them instead. + + +### Output shape is dependent on input data +There are certain nodes like NonZero where the output shape depends on the input data. In this case it is not possible to infer the shape completely hence a new symbolic shape will be created using the inferred rank and shape inference will continue. diff --git a/_doc/sphinxdoc/source/onnxmd/onnx_managing.rst b/_doc/sphinxdoc/source/onnxmd/onnx_managing.rst new file mode 100644 index 00000000..b48df68d --- /dev/null +++ b/_doc/sphinxdoc/source/onnxmd/onnx_managing.rst @@ -0,0 +1,9 @@ + + +Onnx Releases +============= + +.. toctree:: + :maxdepth: 1 + + onnx_docs/ManagingExperimentalOps.md diff --git a/_doc/sphinxdoc/source/onnxmd/onnx_metadata.rst b/_doc/sphinxdoc/source/onnxmd/onnx_metadata.rst new file mode 100644 index 00000000..51fe947f --- /dev/null +++ b/_doc/sphinxdoc/source/onnxmd/onnx_metadata.rst @@ -0,0 +1,9 @@ + + +Metatdata +========= + +.. toctree:: + :maxdepth: 1 + + onnx_docs/MetadataProps.md diff --git a/_doc/sphinxdoc/source/onnxmd/onnx_operators.rst b/_doc/sphinxdoc/source/onnxmd/onnx_operators.rst new file mode 100644 index 00000000..b6b49b9a --- /dev/null +++ b/_doc/sphinxdoc/source/onnxmd/onnx_operators.rst @@ -0,0 +1,9 @@ + + +Onnx Operators +============== + +.. toctree:: + :maxdepth: 1 + + onnx_docs/Operators.md diff --git a/_doc/sphinxdoc/source/onnxmd/onnx_operators_ml.rst b/_doc/sphinxdoc/source/onnxmd/onnx_operators_ml.rst new file mode 100644 index 00000000..b3b95966 --- /dev/null +++ b/_doc/sphinxdoc/source/onnxmd/onnx_operators_ml.rst @@ -0,0 +1,9 @@ + + +Onnx ML Operators +================= + +.. toctree:: + :maxdepth: 1 + + onnx_docs/Operators-ml.md diff --git a/_doc/sphinxdoc/source/onnxmd/onnx_releases.rst b/_doc/sphinxdoc/source/onnxmd/onnx_releases.rst new file mode 100644 index 00000000..a931fbc0 --- /dev/null +++ b/_doc/sphinxdoc/source/onnxmd/onnx_releases.rst @@ -0,0 +1,9 @@ + + +Onnx Releases +============= + +.. toctree:: + :maxdepth: 1 + + onnx_docs/OnnxReleases.md diff --git a/_doc/sphinxdoc/source/onnxmd/onnx_test_coverage.rst b/_doc/sphinxdoc/source/onnxmd/onnx_test_coverage.rst new file mode 100644 index 00000000..d29acd68 --- /dev/null +++ b/_doc/sphinxdoc/source/onnxmd/onnx_test_coverage.rst @@ -0,0 +1,9 @@ + + +Test Coverage (Operators) +========================= + +.. toctree:: + :maxdepth: 1 + + onnx_docs/TestCoverage.md diff --git a/_doc/sphinxdoc/source/onnxmd/onnx_test_coverage_ml.rst b/_doc/sphinxdoc/source/onnxmd/onnx_test_coverage_ml.rst new file mode 100644 index 00000000..8d1737a4 --- /dev/null +++ b/_doc/sphinxdoc/source/onnxmd/onnx_test_coverage_ml.rst @@ -0,0 +1,9 @@ + + +Test Coverage (ML Operators) +============================ + +.. toctree:: + :maxdepth: 1 + + onnx_docs/TestCoverage-ml.md diff --git a/_doc/sphinxdoc/source/onnxmd/onnxruntime_docs/ABI_Dev_Notes.md b/_doc/sphinxdoc/source/onnxmd/onnxruntime_docs/ABI_Dev_Notes.md new file mode 100644 index 00000000..d7f67826 --- /dev/null +++ b/_doc/sphinxdoc/source/onnxmd/onnxruntime_docs/ABI_Dev_Notes.md @@ -0,0 +1,44 @@ +## Global Variables +Global variables may get constructed or destructed inside "DllMain". There are significant limits on what you can safely do in a DLL entry point. See ['DLL General Best Practices'](https://docs.microsoft.com/en-us/windows/desktop/dlls/dynamic-link-library-best-practices). For example, you can't put a ONNX Runtime InferenceSession into a global variable because it has a thread pool inside. + +## Thread Local variables +Onnxruntime must support explicit linking, where the operating system loads the DLL on demand at runtime, instead of process startup time. This is required by our language bindings like C#/Java. + +However, there are some special restrictions on this, If a thread local variable need non-trivial construction, for the threads already exist before onnxruntime.dll is loaded, the variable won't get initialized correctly. So it's better to only access such variables from onnxruntime internal threads, or make these variables function local (Like the magic statics). + + +## No undefined symbols +On Windows, you can't build a DLL with undefined symbols. Every symbol must be get resolved at link time. On Linux, you can. +In order to simplify things, we require every symbol must get resolved at link time. The same rule applies for all the platforms. And this is easier for us to control symbol visibility. + + +## Default visibility and how to export a symbol +On Linux, by default, at linker's view, every symbol is global. It's easy to use but it's also much easier to cause conflicts and core dumps. We have encountered too many such problems in ONNX python binding. Indeed, if you have a well design, for each shared lib, you only need to export **one** function. ONNX Runtime python binding is a good example. See [pybind11 FAQ](https://github.com/pybind/pybind11/blob/master/docs/faq.rst#someclass-declared-with-greater-visibility-than-the-type-of-its-field-someclassmember--wattributes) for more info. + +For controlling the visibility, we use linker version scripts on Linux and def files on Windows. They work similar. That: +1. Only C functions can be exported. +2. All the function names must be explicitly listed in a text file. +3. Don't export any C++ class/struct, or global variable. + +Also, on Linux and Mac operating systems, all the code must be compiled with "-fPIC". +On Windows, we don't use dllexport but we still need dllimport. + +Therefore, our DLLEXPORT macro is like: +``` +#ifdef _WIN32 +// Define ORT_DLL_IMPORT if your program is dynamically linked to Ort. +#ifdef ORT_DLL_IMPORT +#define ORT_EXPORT __declspec(dllimport) +#else +#define ORT_EXPORT +#endif +#else +#define ORT_EXPORT +#endif +``` + +## static initialization order problem +It's well known C++ has [static initialization order problem](https://isocpp.org/wiki/faq/ctors#static-init-order). Dynamic linking can ensure that onnxruntime's static variables are already initialized before any onnxruntime's C API get called. The same thing applies to their destructors. It's good. But on the other side, static linking may have more usage restrictions on some of the APIs. + + + diff --git a/_doc/sphinxdoc/source/onnxmd/onnxruntime_docs/Android_testing.md b/_doc/sphinxdoc/source/onnxmd/onnxruntime_docs/Android_testing.md new file mode 100644 index 00000000..f37525cf --- /dev/null +++ b/_doc/sphinxdoc/source/onnxmd/onnxruntime_docs/Android_testing.md @@ -0,0 +1,81 @@ +# Testing Android Changes using the Emulator + +See [Android build instructions](https://www.onnxruntime.ai/docs/how-to/build.html#android) and information on the locations of the various files referred to here. + +## Install the emulator + +If using Android Studio this is included in the base install. + +If using sdkmanager install the emulator by running + - `sdkmanager[.bat] --install "emulator"` + +The emulator will emulate the Android device not its processor, so you need to build onnxruntime +with an ABI that's valid for the host machine, and install a system image that matches. +For example you can emulate a Pixel 3 device on an Intel 64-bit host, but it will require a binary built against x86_64 +rather than the arm64-v8a ABI of the real device. + +e.g. on Intel 64-bit you would build with `--android_abi x86_64` to create onnxruntime libraries/executables that can be run on the Android emulator + +## Create the device to emulate + +### Android Studio + +Tools->AVD Manager->Create Virtual Device... + +Once created the emulator can be started using the 'play' button in AVD Manager. + +### sdkmanager + +First install a system image. Use `sdkmanager --list` to see the available system images. + +e.g. `sdkmanager --install "system-images;android-27;default;x86_64` + +Create the virtual device using avdmanager[.bat] (which should be in the same directory as sdkmanager[.bat]). + +e.g. `avdmanager create avd -n android27_emulator -k "system-images;android-27;default;x86_64"` + +Run the emulator +e.g. `.../Android/emulator/emulator -avd android27_emulator -partition-size 2048 -no-snapshot -no-audio` + +## Testing running a model on the emulator directly + +Use ADB to copy files and execute commands + +https://developer.android.com/studio/command-line/adb + +ADB is located in the 'platform-tools' folder of the SDK directory. + +Copy onnx_test_runner and the directory of the model to test (in ONNX test directory format) to /data/local/tmp. + +``` +adb push /build///onnx_test_runner /data/local/tmp/ +adb push /build///testdata/transform/gemm_activation_fusion /data/local/tmp/ +``` + +e.g. on Windows that might be +``` +\platform-tools\adb.exe push \build\Windows\Debug\onnx_test_runner /data/local/tmp/testdata +\platform-tools\adb.exe push \build\Windows\Debug\testdata\transform\gemm_activation_fusion /data/local/tmp/ +``` + +You may need to change permissions to make onnx_test_runner executable: +`\platform-tools\adb.exe shell chmod +x /data/local/tmp/onnx_test_runner` + +Run onnx_test_runner with the model directory: +`\platform-tools\adb.exe shell 'cd /data/local/tmp && ./onnx_test_runner gemm_activation_fusion'` + +The output should look something like this: + +``` +D:\Android\platform-tools> .\adb.exe shell 'cd /data/local/tmp && ./onnx_test_runner gemm_activation_fusion' +result: + Models: 1 + Total test cases: 1 + Succeeded: 1 + Not implemented: 0 + Failed: 0 + Stats by Operator type: + Not implemented(0): + Failed: +Failed Test Cases: +``` \ No newline at end of file diff --git a/_doc/sphinxdoc/source/onnxmd/onnxruntime_docs/C_API_Guidelines.md b/_doc/sphinxdoc/source/onnxmd/onnxruntime_docs/C_API_Guidelines.md new file mode 100644 index 00000000..e00ac7b9 --- /dev/null +++ b/_doc/sphinxdoc/source/onnxmd/onnxruntime_docs/C_API_Guidelines.md @@ -0,0 +1,83 @@ +# ORT API Guidelines + +## Introduction + +Our public C API is the main interface of ONNX runtime with our customers. This document endeavors to describe our expectations with respect to the documentation and the quality of the API entry points so we are better equipped to code review new contributions and address existing shortcomings. + +The document is entitled guidelines. However, the expectation is that everyone understands it and adheres to it when implementing a new API or while reviewing contributions from others. + +## Guidelines + +### 1. Public API must be properly documented + +All APIs must have a proper documentation header that includes: + +* API summary includes any limitations, such as types that it operates on. +* Description of each of its arguments and whether it is an in, out or in/out argument. Please, document if the user is responsible for memory deallocation or object destruction and how that can be done. Document that strings are UTF-8 encoded. +* Describe its return value. + +XML format is automatically supported by Visual Studio when one types 3 consecutive slashes. Both C++ and C# compilers can generate XML documentation with /doc switch as described here. The documentation then can be converted to HTML pages using tools such as Sandcastle. We will use XML format to document C#. + +XML format does not support C. We will use Doxygen style to document C API and C++ warappers. + +### 2. Public API must be declared using appropriate macros to ensure that they all have proper calling convention + +Most of our APIs (application programming interfaces) are exported using a pointer table. Such APIs must be declared using ORT_API2_STATUS macro. APIs that exported directly from the shared library must be declared using ORT_API_STATUS macro. Example: OrtSessionOptionsAppendExecutionProvider_CUDA. + +API implementation must be declared using ORT_API_STATUS_IMPL macro. + +All new APIs that are exported via a pointer table must be added at the end of the table to maintain backward compatibility. + +### 3. Public APIs that create/destroy an instance of an object must be declared using an established pattern and signature + +If an API such as CreateSession creates an Ort object such as Session, Session class must be declared using ORT_RUNTIME_CLASS macro. The API must supply an entry point that destroys the instance of such an object. The entry point must be declared using ORT_CLASS_RELEASE and must return void. + +### 4. Public API that may error out must return OrtStatus pointer on error or nullptr on success + +No C++ exceptions must propagate through the C++/C boundaries. All C++ exceptions must be converted to OrtStatus instances at API boundaries. Such functions should return nullptr on success. + +Macros API_IMPL_BEGIN and API_IMPL_END are helpful in this regard. + +Cleanup API that destroys objects or simply deallocates memory must return void. Most of the time such API can never error out. Adding return status creates more uncertainty for the client and does not help in exception scenarios such as try/finally in C#. Returning void helps clients to write cleaner code and preserve original exception if any with its meaningful error message rather than memory deallocation failure. + +This requirement will also help us to create C++ API wrappers that are exception safe. + +Consider logging errors if you must rather than return them to the client. + +Example: on Windows delete operator is implemented on top of HeapFree() which may return an error. However, delete never returns anything and can be relied upon as a no throw primitive for cleanup purposes. + +### 5. Public API must not require calling code to cleanup anything when it errors out + +When API errors out it must leave all its out parameters and buffers untouched, in its original condition. All memory allocations must be cleaned up and no memory leaks result. + +The obvious exception in this rule is the actual OrtStatus that is dynamically allocated and must be released by the client using the corresponding API. + +Some of the client code, notably in C#, attempts to detect which out arguments need a cleanup when an API errors out. The way it is done, out arguments are pre-set to a specific value, such as zero. If the API errors out, the client code attempts to cleanup if the out argument has changed. + +Such a technique is error prone and dangerous, as the client has no way of finding out if the out argument has already been cleaned up by the API as should be the case. It may result in double free. One reason for this is our insufficient documentation. This also results in a convoluted hard to read code with nested try/finally/catch clauses. + +It seems that most of our API is compliant with it. Some API zero out the out arguments right away. It is fine. + +Examples of an API that are compliant with this requirement are: GetBoundOutputNames and GetBoundOutputValues. + +### 6. Public API that allocates memory must take an allocator parameter to use during the allocation + +APIs that require memory allocation to return results, must take the instance of an OrtAllocator to use for such allocations. This serves two purposes: + +* The user may want to supply their own allocator to use. Many of our APIs do that. + +* The API does not have to declare a separate entry point for deallocating memory specifically for its type of allocation as we already have such entry points. OrtAllocatorAlloc/OrtAllocatorFree. + +Consider established patterns when APIs return multiple allocations. + +### 7. Public API must document that all strings they accept, and return are UTF-8 encoded + +All APIs must return and accept strings in UTF-8 encodings. We must be mindful of that when maintaining language bindings. + +### 8. Use appropriate types + +Use types that fall into established patterns. For example, we use int64_t for dimensions internally and in the API everywhere so no casting is required. Use size_t for counts and memory sizes. + +### 9. Adding a new API + +Follow these guidelines and instructions in the source code. "Rules on how to add a new Ort API version" in [onnxruntime_c_api.cc](https://github.com/microsoft/onnxruntime/blob/master/onnxruntime/core/session/onnxruntime_c_api.cc). diff --git a/_doc/sphinxdoc/source/onnxmd/onnxruntime_docs/Coding_Conventions_and_Standards.md b/_doc/sphinxdoc/source/onnxmd/onnxruntime_docs/Coding_Conventions_and_Standards.md new file mode 100644 index 00000000..26eec5de --- /dev/null +++ b/_doc/sphinxdoc/source/onnxmd/onnxruntime_docs/Coding_Conventions_and_Standards.md @@ -0,0 +1,77 @@ +# ONNX Runtime coding conventions and standards + + +## C++ Code Style + +Google style from https://google.github.io/styleguide/cppguide.html with a few minor alterations: + +* Max line length 120 + * Aim for 80, but up to 120 is fine. +* Exceptions + * Allowed to throw fatal errors that are expected to result in a top level handler catching them, logging them and terminating the program. +* Non-const references + * Allowed + * Use a non-const reference for arguments that are modifiable but cannot be nullptr so the API clearly advertises the intent + * Const correctness and usage of smart pointers (shared_ptr and unique_ptr) is expected. A non-const reference equates to “this is a non-null object that you can change but are not being given ownership of”. +* 'using namespace' permitted with limited scope + * Not allowing 'using namespace' at all is overly restrictive. Follow the C++ Core Guidelines: + * [SF.6: Use using namespace directives for transition, for foundation libraries (such as std), or within a local scope (only)](https://github.com/isocpp/CppCoreGuidelines/blob/master/CppCoreGuidelines.md#Rs-using) + * [SF.7: Don't write using namespace at global scope in a header file](https://github.com/isocpp/CppCoreGuidelines/blob/master/CppCoreGuidelines.md#Rs-using-directive) + +Other +* Qualify usages of 'auto' with 'const', '*', '&' and '&&' where applicable to more clearly express the intent +* When adding a new class, disable copy/assignment/move until you have a proven need for these capabilities. If a need arises, enable copy/assignment/move selectively, and when doing so validate that the implementation of the class supports what is being enabled. + * Use ORT_DISALLOW_COPY_ASSIGNMENT_AND_MOVE initially + * See the other ORT_DISALLOW_* macros in https://github.com/microsoft/onnxruntime/blob/master/include/onnxruntime/core/common/common.h +* Don't use else after return. see: [https://llvm.org/docs/CodingStandards.html#don-t-use-else-after-a-return](https://llvm.org/docs/CodingStandards.html#don-t-use-else-after-a-return) +* Don't overuse std::shared\_ptr. Use std::shared\_ptr only if it's not clear when and where the object will be deallocated. See also: [https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#Rf-shared_ptr](https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#Rf-shared_ptr) +* Avoid using the 'long' type, which could be either 32 bits or 64 bits. +* If there is a legitimate need to allocate objects on the heap, prefer using std::make_unique(). References for the reasoning: + * https://github.com/isocpp/CppCoreGuidelines/blob/master/CppCoreGuidelines.md#Rh-make_unique + * https://herbsutter.com/2013/05/29/gotw-89-solution-smart-pointers/ + * https://abseil.io/tips/126 +* Use [SafeInt](https://github.com/dcleblanc/SafeInt) when calculating the size of memory to allocate to protect against overflow errors + * `#include "core/common/safeint.h"` + * search for `SafeInt` in the code for examples + +#### Clang-format + +Clang-format will handle automatically formatting code to these rules. There’s a Visual Studio plugin that can format on save at https://marketplace.visualstudio.com/items?itemName=LLVMExtensions.ClangFormat, or alternatively the latest versions of Visual Studio 2017 include [clang-format support](https://blogs.msdn.microsoft.com/vcblog/2018/03/13/clangformat-support-in-visual-studio-2017-15-7-preview-1/). + +There is a .clang-format file in the root directory that has the max line length override and defaults to the google rules. This should be automatically discovered by the clang-format tools. + +## Code analysis + +Visual Studio Code Analysis with [C++ Core guidelines](https://github.com/isocpp/CppCoreGuidelines/blob/master/CppCoreGuidelines.md) rules enabled is configured to run on build for the onnxruntime_common, onnxruntime_graph and onnxruntime_util libraries. Updating the onnxruntime_framework and onnxruntime_provider libraries to enable Code Analysis and build warning free is pending. + +Code changes should build with no Code Analysis warnings, however this is somewhat difficult to achieve consistently as the Code Analysis implementation is in fairly constant flux. Different minor releases may have less false positives (a build with the latest version may be warning free, and a build with an earlier version may not), or detect additional problems (an earlier version builds warning free and a later version doesn't). + +## Unit Testing and Code Coverage + +There should be unit tests that cover the core functionality of the product, expected edge cases, and expected errors. +Code coverage from these tests should aim at maintaining over 80% coverage. + +All changes should be covered by new or existing unit tests. + +In order to check that all the code you expect to be covered by testing is covered, run code coverage in Visual Studio using 'Analyze Code Coverage' under the Test menu. + +There is a configuration file in onnxruntime\VSCodeCoverage.runsettings that can be used to configure code coverage so that it reports numbers for just the onnxruntime code. Select that file in Visual Studio via the Test menu: 'Test' -> 'Test Settings' -> 'Select Test Settings File'. + +Using 'Show Code Coverage Coloring' will allow you to visually inspect which lines were hit by the tests. See . + +## Python Code Style + +Please adhere to the [PEP8 Style Guide](https://www.python.org/dev/peps/pep-0008/). +A maximum line length of 120 characters is allowed for consistency with the C++ code. + +Code can be validated with [flake8](https://pypi.org/project/flake8/) using the configuration file in the root directory called [.flake8](https://github.com/microsoft/onnxruntime/tree/master/.flake8). + +The [autopep8](https://pypi.org/project/autopep8/) tool can be used to automatically fix a range of PEP8 issues, as can [yapf](https://github.com/google/yapf). There's a yapf configuration file [here](https://github.com/microsoft/onnxruntime/tree/master/onnxruntime/.style.yapf). + +Editors such as PyCharm [(see here)](https://www.jetbrains.com/help/pycharm/code-inspection.html) and Visual Studio Code [(see here)](https://code.visualstudio.com/docs/python/linting#_flake8) can be configured to check for PEP8 issues. + +## Objective-C/C++ Code Style + +Please follow the [Google Objective-C/C++ Style Guide](https://google.github.io/styleguide/objcguide.html). + +Clang-format can be used to format Objective-C/C++ code. The .clang-format file is in the repository root directory. diff --git a/_doc/sphinxdoc/source/onnxmd/onnxruntime_docs/ContribOperators.md b/_doc/sphinxdoc/source/onnxmd/onnxruntime_docs/ContribOperators.md new file mode 100644 index 00000000..3a0171a0 --- /dev/null +++ b/_doc/sphinxdoc/source/onnxmd/onnxruntime_docs/ContribOperators.md @@ -0,0 +1,3174 @@ +## Contrib Operator Schemas +*This file is automatically generated from the registered contrib operator schemas by [this script](https://github.com/microsoft/onnxruntime/blob/master/tools/python/gen_contrib_doc.py). +Do not modify directly.* + +* com.microsoft + * com.microsoft.Attention + * com.microsoft.AttnLSTM + * com.microsoft.BiasDropout + * com.microsoft.BiasGelu + * com.microsoft.BiasSoftmax + * com.microsoft.BifurcationDetector + * com.microsoft.CDist + * com.microsoft.ComplexMul + * com.microsoft.ComplexMulConj + * com.microsoft.ConvTransposeWithDynamicPads + * com.microsoft.CropAndResize + * com.microsoft.DecoderAttention + * com.microsoft.DequantizeLinear + * com.microsoft.DynamicQuantizeLSTM + * com.microsoft.DynamicQuantizeMatMul + * com.microsoft.EmbedLayerNormalization + * com.microsoft.ExpandDims + * com.microsoft.FastGelu + * com.microsoft.FusedConv + * com.microsoft.FusedGemm + * com.microsoft.FusedMatMul + * com.microsoft.GatherND + * com.microsoft.Gelu + * com.microsoft.GridSample + * com.microsoft.Inverse + * com.microsoft.Irfft + * com.microsoft.LongformerAttention + * com.microsoft.MatMulInteger16 + * com.microsoft.MatMulIntegerToFloat + * com.microsoft.MaxpoolWithMask + * com.microsoft.MulInteger + * com.microsoft.MurmurHash3 + * com.microsoft.NGramRepeatBlock + * com.microsoft.NhwcMaxPool + * com.microsoft.Pad + * com.microsoft.QAttention + * com.microsoft.QGemm + * com.microsoft.QLinearAdd + * com.microsoft.QLinearAveragePool + * com.microsoft.QLinearConcat + * com.microsoft.QLinearConv + * com.microsoft.QLinearGlobalAveragePool + * com.microsoft.QLinearLeakyRelu + * com.microsoft.QLinearMul + * com.microsoft.QLinearReduceMean + * com.microsoft.QLinearSigmoid + * com.microsoft.QuantizeLinear + * com.microsoft.Range + * com.microsoft.ReduceSumInteger + * com.microsoft.Rfft + * com.microsoft.SampleOp + * com.microsoft.SkipLayerNormalization + * com.microsoft.SparseToDenseMatMul + * com.microsoft.Tokenizer + * com.microsoft.TorchEmbedding + * com.microsoft.TransposeMatMul + * com.microsoft.Trilu + * com.microsoft.Unique + * com.microsoft.WordConvEmbedding + * experimental com.microsoft.IsAllFinite + * experimental com.microsoft.QEmbedLayerNormalization + +## com.microsoft +### **com.microsoft.Attention** + + Multi-Head Self Attention that can be either unidirectional (like GPT-2) or bidirectional (like BERT). + The mask_index input is optional. Besides raw attention mask with shape (batch_size, past_sequence_length + sequence_length) + or (batch_size, sequence_length, past_sequence_length + sequence_length) with value 0 for masked and 1 otherwise, + we also support other two formats: When input has right-side padding, mask_index is one dimension with shape (batch_size), + where value of each element is the end position, or valid length of actual sequence excluding padding. When input has + left-side padding, mask_index has shape (2 * batch_size), where the values are the exclusive end positions followed by + the inclusive start positions. When unidirectional is 1, and each token only attend to previous tokens. For GPT-2, both past + and present state are optional. Present state could appear in output even when past state is not in input. + +#### Version + +This version of the operator has been available since version 1 of the 'com.microsoft' operator set. + +#### Attributes + +
+
num_heads : int (required)
+
Number of attention heads
+
qkv_hidden_sizes : list of ints
+
Hidden layer sizes of Q, K, V paths in Attention
+
unidirectional : int
+
Whether every token can only attend to previous tokens. Default value is 0.
+
+ +#### Inputs (3 - 6) + +
+
input : T
+
3D input tensor with shape (batch_size, sequence_length, input_hidden_size)
+
weight : T
+
2D input tensor with shape (input_hidden_size, 3 * hidden_size), where hidden_size = num_heads * head_size
+
bias : T
+
1D input tensor with shape (3 * hidden_size)
+
mask_index (optional) : M
+
Attention mask with shape (batch_size, 1, max_sequence_length, max_sequence_length), (batch_size, past_sequence_length + sequence_length)or (batch_size, sequence_length, past_sequence_length + sequence_length), or index with shape (batch_size) or (2 * batch_size).
+
past (optional) : T
+
past state for key and value with shape (2, batch_size, num_heads, past_sequence_length, head_size).
+
extra_add (optional) : T
+
additional add to QxK' with shape (batch_size, num_heads, sequence_length, sequence_length).
+
+ +#### Outputs (1 - 2) + +
+
output : T
+
3D output tensor with shape (batch_size, sequence_length, hidden_size)
+
present (optional) : T
+
present state for key and value with shape (2, batch_size, num_heads, past_sequence_length + sequence_length, head_size)
+
+ +#### Type Constraints + +
+
T : tensor(float), tensor(float16)
+
Constrain input and output types to float tensors.
+
M : tensor(int32)
+
Constrain mask index to integer types
+
+ + +### **com.microsoft.AttnLSTM** + + Computes an one-layer RNN where its RNN Cell is an AttentionWrapper wrapped a LSTM Cell. The RNN layer + contains following basic component: LSTM Cell, Bahdanau Attention Mechanism, AttentionWrapp. + + Activation functions: + + Relu(x) - max(0, x) + + Tanh(x) - (1 - e^{-2x})/(1 + e^{-2x}) + + Sigmoid(x) - 1/(1 + e^{-x}) + + (NOTE: Below are optional) + + Affine(x) - alpha*x + beta + + LeakyRelu(x) - x if x >= 0 else alpha * x + + ThresholdedRelu(x) - x if x >= alpha else 0 + + ScaledTanh(x) - alpha*Tanh(beta*x) + + HardSigmoid(x) - min(max(alpha*x + beta, 0), 1) + + Elu(x) - x if x >= 0 else alpha*(e^x - 1) + + Softsign(x) - x/(1 + |x|) + + Softplus(x) - log(1 + e^x) + + Softmax(x) - exp(x) / sum(exp(x)) + + Bahdanau Attention Mechanism: + `M` - Memory tensor. + + `VALUES` - masked Memory by its real sequence length. + + `MW` - Memory layer weight. + + `KEYS` - Processed memory tensor by the memory layer. + KEYS = M * MW + + `Query` - Query tensor, normally at specific time step in sequence. + + `QW` - Query layer weight in the attention mechanism + + `PQ` - processed query, = `Query` * `QW` + + `V' - attention vector + + `ALIGN` - calculated alignment based on Query and KEYS + ALIGN = softmax(reduce_sum(`V` * Tanh(`KEYS` + `PQ`))) + + `CONTEXT` - context based on `ALIGN` and `VALUES` + CONTEXT = `ALIGN` * `VALUES` + + + LSTM Cell: + `X` - input tensor concat with attention state in the attention wrapper + + `i` - input gate + + `o` - output gate + + `f` - forget gate + + `c` - cell gate + + `t` - time step (t-1 means previous time step) + + `W[iofc]` - W parameter weight matrix for input, output, forget, and cell gates + + `R[iofc]` - R recurrence weight matrix for input, output, forget, and cell gates + + `Wb[iofc]` - W bias vectors for input, output, forget, and cell gates + + `Rb[iofc]` - R bias vectors for input, output, forget, and cell gates + + `P[iof]` - P peephole weight vector for input, output, and forget gates + + `WB[iofc]` - W parameter weight matrix for backward input, output, forget, and cell gates + + `RB[iofc]` - R recurrence weight matrix for backward input, output, forget, and cell gates + + `WBb[iofc]` - W bias vectors for backward input, output, forget, and cell gates + + `RBb[iofc]` - R bias vectors for backward input, output, forget, and cell gates + + `PB[iof]` - P peephole weight vector for backward input, output, and forget gates + + `H` - Hidden state + + `num_directions` - 2 if direction == bidirectional else 1 + + Equations (Default: f=Sigmoid, g=Tanh, h=Tanh): + + - it = f(Xt*(Wi^T) + Ht-1*(Ri^T) + Pi (.) Ct-1 + Wbi + Rbi) + + - ft = f(Xt*(Wf^T) + Ht-1*(Rf^T) + Pf (.) Ct-1 + Wbf + Rbf) + + - ct = g(Xt*(Wc^T) + Ht-1*(Rc^T) + Wbc + Rbc) + + - Ct = ft (.) Ct-1 + it (.) ct + + - ot = f(Xt*(Wo^T) + Ht-1*(Ro^T) + Po (.) Ct + Wbo + Rbo) + + - Ht = ot (.) h(Ct) + + + AttentionWrapp Notations: + `lstm()' - wrapped inner cell. + Ht, Ct = lstm(concat(Xt, ATTNt-1), Ct-1) + + `am()` - attention mechanism the wrapper used. + CONTEXTt, ALIGNt = am(Ht, ALIGNt-1) + + `AW` - attention layer weights, optional. + + `ATTN` - attention state, initial is zero. If `AW` provided, it is the output of the attention layer, + ATTNt = concat(Ht, CONTEXTt) * AW + otherwise, + ATTNt = CONTEXTt + + RNN layer output: + `Y` - if needed is the sequence of Ht from lstm cell. + + `Y_h` - is the last valid H from lstm cell. + + `Y_c` - is the last valid C from lstm cell. + + +#### Version + +This version of the operator has been available since version 1 of the 'com.microsoft' operator set. + +#### Attributes + +
+
activation_alpha : list of floats
+
Optional scaling values used by some activation functions. The values are consumed in the order of activation functions, for example (f, g, h) in LSTM. Default values are the same as of corresponding ONNX operators.For example with LeakyRelu, the default alpha is 0.01.
+
activation_beta : list of floats
+
Optional scaling values used by some activation functions. The values are consumed in the order of activation functions, for example (f, g, h) in LSTM. Default values are the same as of corresponding ONNX operators.
+
activations : list of strings
+
A list of 3 (or 6 if bidirectional) activation functions for input, output, forget, cell, and hidden. The activation functions must be one of the activation functions specified above. Optional: See the equations for default if not specified.
+
clip : float
+
Cell clip threshold. Clipping bounds the elements of a tensor in the range of [-threshold, +threshold] and is applied to the input of activations. No clip if not specified.
+
direction : string
+
Specify if the RNN is forward, reverse, or bidirectional. Must be one of forward (default), reverse, or bidirectional.
+
hidden_size : int
+
Number of neurons in the hidden layer.
+
input_forget : int
+
Couple the input and forget gates if 1, default 0.
+
+ +#### Inputs (3 - 14) + +
+
X : T
+
The input sequences packed (and potentially padded) into one 3-D tensor with the shape of `[seq_length, batch_size, input_size]`
+
W : T
+
The weight tensor for the gates. Concatenation of `W[iofc]` and `WB[iofc]` (if bidirectional) along dimension 0. The tensor has shape `[num_directions, 4*hidden_size, input_size]`.
+
R : T
+
The recurrence weight tensor. Concatenation of `R[iofc]` and `RB[iofc]` (if bidirectional) along dimension 0. This tensor has shape `[num_directions, 4*hidden_size, hidden_size]`.
+
B (optional) : T
+
The bias tensor for input gate. Concatenation of `[Wb[iofc], Rb[iofc]]`, and `[WBb[iofc], RBb[iofc]]` (if bidirectional) along dimension 0. This tensor has shape `[num_directions, 8*hidden_size]`. Optional: If not specified - assumed to be 0.
+
sequence_lens (optional) : T1
+
Optional tensor specifying lengths of the sequences in a batch. If not specified - assumed all sequences in the batch to have length `seq_length`. It has shape `[batch_size]`
+
initial_h (optional) : T
+
Optional initial value of the hidden. If not specified - assumed to be 0. It has shape `[num_directions, batch_size, hidden_size]`.
+
initial_c (optional) : T
+
Optional initial value of the cell. If not specified - assumed to be 0. It has shape `[num_directions, batch_size, hidden_size]`.
+
P (optional) : T
+
The weight tensor for peepholes. Concatenation of `P[iof]` and `PB[iof]` (if bidirectional) along dimension 0. It has shape `[num_directions, 3*hidde_size]`. Optional: If not specified - assumed to be 0.
+
QW (optional) : T
+
The weight tensor of the query layer in the attention mechanism. Should be of shape `[num_directions, am_query_depth(hidden_size of lstm), am_attn_size]`
+
MW (optional) : T
+
The weight tensor of the memory layer in the attention mechanism. Should be of shape `[num_directions, memory_depth, am_attn_size]`
+
V (optional) : T
+
The attention_v tensor in the attention mechanism. Should be of shape `[num_directions, am_attn_size]`
+
M (optional) : T
+
The sequence of the memory (input) for attention mechanism. Should be of `[batch_size, max_memory_step, memory_depth]`
+
memory_seq_lens (optional) : T1
+
The sequence length of the input memory for the attention mechanism. Should be of `[batch_size]`
+
AW (optional) : T
+
The weights of attention layer in the attention wrapper. If exists, should be of shape `[num_directions, memory_depth+hidden_size, aw_attn_size]. Please note that attention mechanism context depth is also memory_depth in the attention mechanism.`
+
+ +#### Outputs (0 - 3) + +
+
Y (optional) : T
+
A tensor that concats all the intermediate output values of the hidden. It has shape `[seq_length, num_directions, batch_size, hidden_size]`
+
Y_h (optional) : T
+
The last output value of the hidden. It has shape `[num_directions, batch_size, hidden_size]`.
+
Y_c (optional) : T
+
The last output value of the cell. It has shape `[num_directions, batch_size, hidden_size]`.
+
+ +#### Type Constraints + +
+
T : tensor(float), tensor(double)
+
Constrain input and output types to float tensors.
+
T1 : tensor(int32)
+
Constrain seq_lens to integral tensors.
+
+ + +### **com.microsoft.BiasDropout** + + output, dropout_mask = Dropout(data + bias, ratio) + residual, Intended to specialize the dropout pattern commonly found in transformer models. + +#### Version + +This version of the operator has been available since version 1 of the 'com.microsoft' operator set. + +#### Attributes + +
+
seed : int
+
(Optional) Seed to the random generator, if not specified we will auto generate one.
+
+ +#### Inputs (2 - 5) + +
+
data : T
+
The input data as Tensor.
+
bias : T
+
The bias input, a vector with the same shape as last dim of data OR same shape with data
+
residual (optional) : T
+
The residual input, must have the same shape as data
+
ratio (optional) : T1
+
The ratio of random dropout, with value in [0, 1). If this input was not set, or if it was set to 0, the output would be a simple copy of the input. If it's non-zero, output will be a random dropout of input, which is typically the case during training.
+
training_mode (optional) : T2
+
If set to true then it indicates dropout is being used for training. It is an optional value hence unless specified explicitly, it is false. If it is false, ratio is ignored and the operation mimics inference mode where nothing will be dropped from the input data and if mask is requested as output it will contain all ones.
+
+ +#### Outputs (1 - 2) + +
+
output : T
+
The output.
+
mask (optional) : T2
+
The output mask of dropout.
+
+ +#### Type Constraints + +
+
T : tensor(float16), tensor(float), tensor(double), tensor(bfloat16)
+
Constrain input and output types to float tensors.
+
T1 : tensor(float16), tensor(float), tensor(double), tensor(bfloat16)
+
Constrain input 'ratio' types to float tensors.
+
T2 : tensor(bool)
+
Constrain output 'mask' types to boolean tensors.
+
+ + +### **com.microsoft.BiasGelu** + + Bias Gelu. + It's an extension of Gelu. It takes the sum of input A and bias input B as the input of Gelu activation. + +#### Version + +This version of the operator has been available since version 1 of the 'com.microsoft' operator set. + +#### Inputs + +
+
A : T
+
The normal input data.
+
B : T
+
The bias input data that is a 1D tensor.
+
+ +#### Outputs + +
+
C : T
+
The output.
+
+ +#### Type Constraints + +
+
T : tensor(float16), tensor(float), tensor(double)
+
Constrain input and output types to float tensors.
+
+ + +### **com.microsoft.BiasSoftmax** + + Y = softmax(scores + bias)) with simple broadcast on bias. Intended to specialize softmax(scores + additive_mask) commonly found in transformer models. + +#### Version + +This version of the operator has been available since version 1 of the 'com.microsoft' operator set. + +#### Attributes + +
+
broadcast_axis : int
+
broadcast bias across input for dimensions broadcast_axis to softmax_axis-1
+
softmax_axis : int
+
apply softmax to elements for dimensions softmax_axis or higher
+
+ +#### Inputs + +
+
data : T
+
The input data as Tensor.
+
bias : T
+
The bias (or mask) as Tensor.
+
+ +#### Outputs + +
+
output : T
+
The output.
+
+ +#### Type Constraints + +
+
T : tensor(float16), tensor(float), tensor(double)
+
Constrain input and output types to float tensors.
+
+ + +### **com.microsoft.BifurcationDetector** + + Component for aggressive decoding. Find the bifurcation index of predicted tokens, between source tokens, + starting from previous suffix match index, and predicted tokens. + Concat predicted tokens, starting from bifurcation index, to the back + of current tokens. This forms the output tokens. + Detect suffix match index in source tokens, between source tokens and output tokens. + Detection is based on finding the appearances of last n-gram in output tokens + in source tokens. + A match is considered found if source tokens contain a single matching n-gram. + Return the index of the start of the n-gram in source tokens. + No matching if found if src tokens contain multiple or zero matching n-grams. Return -1. + +#### Version + +This version of the operator has been available since version 1 of the 'com.microsoft' operator set. + +#### Attributes + +
+
max_ngram_size : int
+
The maximum NGram size for suffix matching.
+
min_ngram_size : int
+
The minimum NGram size for suffix matching.
+
+ +#### Inputs (3 - 4) + +
+
src_tokens : T
+
Encoder input ids.
+
cur_tokens : T
+
Decoder input ids.
+
prev_suffix_match_idx : T
+
Previous suffix match index
+
pred_tokens (optional) : T
+
Predicted token ids from aggressive decoding
+
+ +#### Outputs + +
+
tokens : T
+
Decoder input ids after merging predicted tokens
+
suffix_match_idx : T
+
new suffix match index
+
+ +#### Type Constraints + +
+
T : tensor(int64)
+
Constrain to integer types.
+
+ + +### **com.microsoft.CDist** + +#### Version + +This version of the operator has been available since version 1 of the 'com.microsoft' operator set. + +#### Attributes + +
+
metric : string
+
The distance metric to use. If a string, the distance function can be "braycurtis", "canberra", "chebyshev", "cityblock", "correlation", "cosine", "dice", "euclidean", "hamming", "jaccard", "jensenshannon", "kulsinski", "mahalanobis", "matching", "minkowski", "rogerstanimoto", "russellrao", "seuclidean", "sokalmichener", "sokalsneath", "sqeuclidean", "wminkowski", "yule".
+
+ +#### Inputs + +
+
A : T
+
2D matrix with shape (M,N)
+
B : T
+
2D matrix with shape (K,N)
+
+ +#### Outputs + +
+
C : T
+
A 2D Matrix that represents the distance between each pair of the two collections of inputs.
+
+ +#### Type Constraints + +
+
T : tensor(float), tensor(double)
+
Constrains input to only numeric types.
+
+ + +### **com.microsoft.ComplexMul** + +#### Version + +This version of the operator has been available since version 1 of the 'com.microsoft' operator set. + +#### Inputs + +
+
A : T
+
input_0
+
B : T
+
input_1
+
+ +#### Outputs + +
+
C : T
+
output tensor
+
+ +#### Type Constraints + +
+
T : tensor(float), tensor(double), tensor(float16)
+
Constrain input and output types to float or half tensors.
+
+ + +### **com.microsoft.ComplexMulConj** + +#### Version + +This version of the operator has been available since version 1 of the 'com.microsoft' operator set. + +#### Inputs + +
+
A : T
+
input_0
+
B : T
+
input_1
+
+ +#### Outputs + +
+
C : T
+
output tensor
+
+ +#### Type Constraints + +
+
T : tensor(float), tensor(double), tensor(float16)
+
Constrain input and output types to float or half tensors.
+
+ + +### **com.microsoft.ConvTransposeWithDynamicPads** + +#### Version + +This version of the operator has been available since version 1 of the 'com.microsoft' operator set. + +#### Attributes + +
+
auto_pad : string
+
+
dilations : list of ints
+
+
group : int
+
+
kernel_shape : list of ints
+
+
output_padding : list of ints
+
+
strides : list of ints
+
+
+ +#### Inputs (2 - 4) + +
+
X : T
+
+
W : T
+
+
Pads (optional) : tensor(int64)
+
+
B (optional) : T
+
+
+ +#### Outputs + +
+
Y : T
+
+
+ +#### Type Constraints + +
+
T : tensor(float16), tensor(float), tensor(double)
+
Constrain input and output types to float tensors
+
+ + +### **com.microsoft.CropAndResize** + + Extracts crops from the input image tensor and resizes them using bilinear sampling or nearest neighbor sampling + (possibly with aspect ratio change) to a common output size specified by crop_height and crop_width. + Returns a tensor with crops from the input image at positions defined at the bounding box locations in boxes. + The cropped boxes are all resized (with bilinear or nearest neighbor interpolation) to + a fixed size = [crop_height, crop_width]. The result is a 4-D tensor [num_boxes, crop_height, crop_width, depth]. + The resizing is corner aligned. + +#### Version + +This version of the operator has been available since version 1 of the 'com.microsoft' operator set. + +#### Attributes + +
+
extrapolation_value : float
+
Value used for extrapolation, when applicable. Default is 0.0f.
+
mode : string
+
The pooling method. Two modes are supported: 'bilinear' and 'nearest'. Default is 'bilinear'.
+
+ +#### Inputs + +
+
X : T1
+
Input data tensor from the previous operator; 4-D feature map of shape (N, C, H, W), where N is the batch size, C is the number of channels, and H and W are the height and the width of the data.
+
rois : T1
+
RoIs (Regions of Interest) to pool over; rois is 2-D input of shape (num_rois, 4) given as [[y1, x1, y2, x2], ...]. The RoIs' coordinates are normalized in the coordinate system of the input image. Each coordinate set has a 1:1 correspondence with the 'batch_indices' input.
+
batch_indices : T2
+
1-D tensor of shape (num_rois,) with each element denoting the index of the corresponding image in the batch.
+
crop_size : T2
+
1-D tensor of 2 elements: [crop_height, crop_width]. All cropped image patches are resized to this size. Both crop_height and crop_width need to be positive.
+
+ +#### Outputs + +
+
Y : T1
+
RoI pooled output, 4-D tensor of shape (num_rois, C, crop_height, crop_width). The r-th batch element Y[r-1] is a pooled feature map corresponding to the r-th RoI X[r-1].
+
+ +#### Type Constraints + +
+
T1 : tensor(float16), tensor(float), tensor(double)
+
Constrain types to float tensors.
+
T2 : tensor(int32)
+
Constrain types to int tensors.
+
+ + +### **com.microsoft.DecoderAttention** + + This DecoderAttention supports self attention and cross attention, key and value cache, and key_padding_mask. The attention mask is not support at the moment. + Some boolean parameters are passed by runtime input for generic purpose + +#### Version + +This version of the operator has been available since version 1 of the 'com.microsoft' operator set. + +#### Attributes + +
+
num_heads : int (required)
+
Number of attention heads
+
+ +#### Inputs + +
+
query : T
+
3D input tensor with shape (sequence_length, batch_size, hidden_size), hidden_size = num_heads * head_size
+
key : T
+
3D input tensor with shape (total_sequence_length, batch_size, hidden_size)
+
q_weight : T
+
2D input tensor with shape (hidden_size, hidden_size)
+
kv_weight : T
+
2D input tensor with shape (hidden_size, 2 * hidden_size)
+
bias : T
+
1D input tensor with shape (3 * hidden_size)
+
key_padding_mask (optional) : B
+
2D input tensor with shape (batch_size, total_sequence_length)
+
key_cache (optional) : T
+
input tensor with shape (batch_size, num_heads, sequence_length or total_sequence_length, head_size)
+
value_cache (optional) : T
+
input tensor with shape (batch_size, num_heads, sequence_length or total_sequence_length, head_size)
+
static_kv : B
+
If static_kv = true, cross-attention; else self-attention
+
use_past : B
+
If use_past = true, use cache; else no cache
+
has_layer_state : B
+
If has_layer_state = true, layer_state = {} or [a,b]; else layer_state = None
+
has_key_padding_mask : B
+
has_key_padding_mask or not
+
+ +#### Outputs (1 - 3) + +
+
output : T
+
3D output tensor with shape (sequence_length, batch_size, hidden_size)
+
new_key_cache (optional) : T
+
output tensor with shape (batch_size, num_heads, new sequence_length, head_size)
+
new_value_cache (optional) : T
+
output tensor with shape (batch_size, num_heads, new sequence_length, head_size)
+
+ +#### Type Constraints + +
+
T : tensor(float), tensor(float16)
+
Constrain input and output types to float and float16 tensors.
+
B : tensor(bool)
+
Constrain key_padding_mask to bool tensors.
+
+ + +### **com.microsoft.DequantizeLinear** + + The linear dequantization operator. It consumes a quantized data, a scale, a zero point and computes the full precision data. + The dequantization formula is y = (x - x_zero_point) * x_scale. + Scale and zero point must have same shape. They must be either scalar (per tensor) or 1-D tensor (per 'axis'). + +#### Version + +This version of the operator has been available since version 1 of the 'com.microsoft' operator set. + +#### Attributes + +
+
axis : int
+
The axis along which same quantization parameters are applied. It's optional.If it's not specified, it means per-tensor quantization and input 'x_scale' and 'x_zero_point' must be scalars.If it's specified, it means per 'axis' quantization and input 'x_scale' and 'x_zero_point' must be 1-D tensors.
+
+ +#### Inputs + +
+
x : T1
+
N-D quantized Input tensor to be de-quantized.
+
x_scale : T2
+
Scale for input 'x'. It could be a scalar or a 1-D tensor, which means a per-tensor or per-axis quantization.If it's a 1-D tensor, its number of elements should be equal to the dimension value of 'axis' dimension of input 'x'.
+
x_zero_point : T1
+
Zero point for input 'x'. It could be a scalar or a 1-D tensor, which means a per-tensor or per-axis quantization.If it's a 1-D tensor, its number of elements should be equal to the dimension value of 'axis' dimension of input 'x'.
+
+ +#### Outputs + +
+
y : T2
+
N-D full precision output tensor. It has same shape as input 'x'.
+
+ +#### Type Constraints + +
+
T1 : tensor(int8), tensor(uint8)
+
Constrain 'x' and 'x_zero_point' to 8-bit integer tensors.
+
T2 : tensor(float16), tensor(float)
+
Constrain 'y', 'x_scale' to float tensors.
+
+ + +### **com.microsoft.DynamicQuantizeLSTM** + +#### Version + +This version of the operator has been available since version 1 of the 'com.microsoft' operator set. + +#### Attributes + +
+
activation_alpha : list of floats
+
Optional scaling values used by some activation functions. The values are consumed in the order of activation functions, for example (f, g, h) in LSTM. Default values are the same as of corresponding ONNX operators.For example with LeakyRelu, the default alpha is 0.01.
+
activation_beta : list of floats
+
Optional scaling values used by some activation functions. The values are consumed in the order of activation functions, for example (f, g, h) in LSTM. Default values are the same as of corresponding ONNX operators.
+
activations : list of strings
+
A list of 3 (or 6 if bidirectional) activation functions for input, output, forget, cell, and hidden. The activation functions must be one of the activation functions specified above. Optional: See the equations for default if not specified.
+
clip : float
+
Cell clip threshold. Clipping bounds the elements of a tensor in the range of [-threshold, +threshold] and is applied to the input of activations. No clip if not specified.
+
direction : string
+
Specify if the RNN is forward, reverse, or bidirectional. Must be one of forward (default), reverse, or bidirectional.
+
hidden_size : int
+
Number of neurons in the hidden layer
+
input_forget : int
+
Couple the input and forget gates if 1.
+
+ +#### Inputs + +
+
X : T
+
The input sequences packed (and potentially padded) into one 3-D tensor with the shape of `[seq_length, batch_size, input_size]`.
+
W : T2
+
The weight tensor for the gates. Concatenation of `W[iofc]` and `WB[iofc]` (if bidirectional) along dimension 0. The tensor has shape `[num_directions, input_size, 4*hidden_size]`.
+
R : T2
+
The recurrence weight tensor. Concatenation of `R[iofc]` and `RB[iofc]` (if bidirectional) along dimension 0. This tensor has shape `[num_directions, hidden_size, 4*hidden_size]`.
+
B (optional) : T
+
The bias tensor for input gate. Concatenation of `[Wb[iofc], Rb[iofc]]`, and `[WBb[iofc], RBb[iofc]]` (if bidirectional) along dimension 0. This tensor has shape `[num_directions, 8*hidden_size]`. Optional: If not specified - assumed to be 0.
+
sequence_lens (optional) : T1
+
Optional tensor specifying lengths of the sequences in a batch. If not specified - assumed all sequences in the batch to have length `seq_length`. It has shape `[batch_size]`.
+
initial_h (optional) : T
+
Optional initial value of the hidden. If not specified - assumed to be 0. It has shape `[num_directions, batch_size, hidden_size]`.
+
initial_c (optional) : T
+
Optional initial value of the cell. If not specified - assumed to be 0. It has shape `[num_directions, batch_size, hidden_size]`.
+
P (optional) : T
+
The weight tensor for peepholes. Concatenation of `P[iof]` and `PB[iof]` (if bidirectional) along dimension 0. It has shape `[num_directions, 3*hidde_size]`. Optional: If not specified - assumed to be 0.
+
W_scale : T
+
W's scale. Its size is [num_directions] for per-tensor/layer quantization, or [num_directions, 4*hidden_size] for per-channel quantization on the axis input_size.
+
W_zero_point : T2
+
W's zero point. Its size is [num_directions] for per-tensor/layer quantization, or [num_directions, 4*hidden_size] for per-channel quantization on the axis input_size.
+
R_scale : T
+
R's scale. Its size is [num_directions] for per-tensor/layer quantization, or [num_directions, 4*hidden_size] for per-channel quantization on the axis input_size.
+
R_zero_point : T2
+
R's zero point. Its size is [num_directions] for per-tensor/layer quantization, or [num_directions, 4*hidden_size] for per-channel quantization on the axis input_size.
+
+ +#### Outputs (0 - 3) + +
+
Y (optional) : T
+
A tensor that concats all the intermediate output values of the hidden. It has shape `[seq_length, num_directions, batch_size, hidden_size]`.
+
Y_h (optional) : T
+
The last output value of the hidden. It has shape `[num_directions, batch_size, hidden_size]`.
+
Y_c (optional) : T
+
The last output value of the cell. It has shape `[num_directions, batch_size, hidden_size]`.
+
+ +#### Type Constraints + +
+
T : tensor(float)
+
Constrain input and output types to float tensors.
+
T1 : tensor(int32)
+
Constrain seq_lens to integer tensor.
+
T2 : tensor(uint8), tensor(int8)
+
Constrain weights types to 8 bit tensors.
+
+ + +### **com.microsoft.DynamicQuantizeMatMul** + +#### Version + +This version of the operator has been available since version 1 of the 'com.microsoft' operator set. + +#### Inputs (3 - 5) + +
+
A : T1
+
N-dimensional matrix A
+
B : T2
+
N-dimensional matrix B
+
b_scale : T1
+
Scale of quantized input 'B'. It could be a scalar or a 1-D tensor, which means a per-tensor or per-column quantization. If it's a 1-D tensor, its number of elements should be equal to the number of columns of input 'B'.
+
b_zero_point (optional) : T2
+
Zero point tensor for input 'B'. It's optional and default value is 0. It could be a scalar or a 1-D tensor, which means a per-tensor or per-column quantization. If it's a 1-D tensor, its number of elements should be equal to the number of columns of input 'B'.
+
bias (optional) : T1
+
1D input tensor, whose dimension is same as B's last dimension
+
+ +#### Outputs + +
+
Y : T1
+
Matrix multiply results from A * B
+
+ +#### Type Constraints + +
+
T1 : tensor(float)
+
Constrain input A, b_scale and output Y data type as float tensor.
+
T2 : tensor(int8), tensor(uint8)
+
Constrain input B data type to 8-bit integer tensor.
+
+ + +### **com.microsoft.EmbedLayerNormalization** + + EmbedLayerNormalization is the fusion of embedding layer in BERT model, with optional mask processing. + The embedding layer takes input_ids (word IDs) and segment_ids (sentence IDs) to look up word_embedding, position_embedding, + and segment_emedding; the embeddings are added then applied layer normalization using gamma and beta tensors. + The last input mask is optional. If mask is provided, mask index (that is position of first 0 in mask, or number of words) + will be calculated. + +#### Version + +This version of the operator has been available since version 1 of the 'com.microsoft' operator set. + +#### Attributes + +
+
epsilon : float
+
The epsilon value to use to avoid division by zero.
+
+ +#### Inputs (7 - 9) + +
+
input_ids : T1
+
2D words IDs with shape (batch_size, sequence_length)
+
segment_ids (optional) : T1
+
2D segment IDs with shape (batch_size, sequence_length)
+
word_embedding : T
+
2D with shape (,hidden_size)
+
position_embedding : T
+
2D with shape (, hidden_size)
+
segment_embedding (optional) : T
+
2D with shape (, hidden_size)
+
gamma : T
+
1D gamma tensor for layer normalization with shape (hidden_size)
+
beta : T
+
1D beta tensor for layer normalization with shape (hidden_size)
+
mask (optional) : T1
+
2D attention mask with shape (batch_size, sequence_length)
+
position_ids (optional) : T1
+
2D position ids with shape (batch_size, sequence_length)
+
+ +#### Outputs (2 - 3) + +
+
output : T
+
3D output tensor with shape (batch_size, sequence_length, hidden_size)
+
mask_index : T1
+
1D mask_index tensor with shape (batch_size)
+
embedding_sum (optional) : T
+
sum of word_embedding and position_embedding without layer normalization
+
+ +#### Type Constraints + +
+
T1 : tensor(int32)
+
Constrain input and output integer tensors types
+
T : tensor(float), tensor(float16)
+
Constrain input and output float tensors types.
+
+ + +### **com.microsoft.ExpandDims** + + ExpandDims echo operator. + +#### Version + +This version of the operator has been available since version 1 of the 'com.microsoft' operator set. + +#### Inputs + +
+
X : T
+
input
+
axis : tensor(int32)
+
Specified axis to insert a dimension
+
+ +#### Outputs + +
+
Y : T
+
output
+
+ +#### Type Constraints + +
+
T : tensor(uint8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(int8), tensor(int16), tensor(int32), tensor(int64), tensor(float16), tensor(float), tensor(double), tensor(string), tensor(bool), tensor(complex64), tensor(complex128)
+
Constrain to any tensor type. If the dtype attribute is not provided this must be a valid output type.
+
+ + +### **com.microsoft.FastGelu** + + GELU (Gaussian Error Linear Unit) approximation: Y=0.5*X*(1+tanh(0.797885*X+0.035677*X*X*X)) with an optional input of bias that will be added to X before GELU. + +#### Version + +This version of the operator has been available since version 1 of the 'com.microsoft' operator set. + +#### Inputs (1 - 2) + +
+
X : T
+
input tensor
+
bias (optional) : T
+
bias tensor
+
+ +#### Outputs + +
+
Y : T
+
output tensor
+
+ +#### Type Constraints + +
+
T : tensor(float), tensor(float16), tensor(bfloat16)
+
Constrain input and output types to float or half tensors.
+
+ + +### **com.microsoft.FusedConv** + + The fused convolution operator schema is the same as Conv besides it includes an attribute + activation. + +#### Version + +This version of the operator has been available since version 1 of the 'com.microsoft' operator set. + +#### Attributes + +
+
activation : string
+
+
activation_params : list of floats
+
+
auto_pad : string
+
+
dilations : list of ints
+
+
group : int
+
+
kernel_shape : list of ints
+
+
pads : list of ints
+
+
strides : list of ints
+
+
+ +#### Inputs (2 - 4) + +
+
X : T
+
+
W : T
+
+
B (optional) : T
+
+
Z (optional) : T
+
+
+ +#### Outputs + +
+
Y : T
+
+
+ +#### Type Constraints + +
+
T : tensor(float16), tensor(float), tensor(double)
+
Constrain input and output types to float tensors
+
+ + +### **com.microsoft.FusedGemm** + + The FusedGemm operator schema is the same as Gemm besides it includes attributes + activation and leaky_relu_alpha. + +#### Version + +This version of the operator has been available since version 1 of the 'com.microsoft' operator set. + +#### Attributes + +
+
activation : string
+
+
activation_alpha : float
+
+
activation_beta : float
+
+
activation_gamma : float
+
+
alpha : float
+
Scalar multiplier for the product of input tensors A * B.
+
beta : float
+
Scalar multiplier for input tensor C.
+
transA : int
+
Whether A should be transposed
+
transB : int
+
Whether B should be transposed
+
+ +#### Inputs + +
+
A : T
+
Input tensor A. The shape of A should be (M, K) if transA is 0, or (K, M) if transA is non-zero.
+
B : T
+
Input tensor B. The shape of B should be (K, N) if transB is 0, or (N, K) if transB is non-zero.
+
C : T
+
Input tensor C. The shape of C should be unidirectional broadcastable to (M, N).
+
+ +#### Outputs + +
+
Y : T
+
Output tensor of shape (M, N).
+
+ +#### Type Constraints + +
+
T : tensor(float16), tensor(float), tensor(double), tensor(uint32), tensor(uint64), tensor(int32), tensor(int64)
+
Constrain input and output types to float/int tensors.
+
+ + +### **com.microsoft.FusedMatMul** + + Matrix product that behaves like numpy.matmul: https://docs.scipy.org/doc/numpy-1.13.0/reference/generated/numpy.matmul.html + +#### Version + +This version of the operator has been available since version 1 of the 'com.microsoft' operator set. + +#### Attributes + +
+
alpha : float
+
Scalar multiplier for the product of the input tensors.
+
transA : int
+
Whether A should be transposed on the last two dimensions before doing multiplication
+
transB : int
+
Whether B should be transposed on the last two dimensions before doing multiplication
+
+ +#### Inputs + +
+
A : T
+
N-dimensional matrix A
+
B : T
+
N-dimensional matrix B
+
+ +#### Outputs + +
+
Y : T
+
Matrix multiply results
+
+ +#### Type Constraints + +
+
T : tensor(float16), tensor(float), tensor(double), tensor(bfloat16)
+
Constrain input and output types to float tensors.
+
+ + +### **com.microsoft.GatherND** + + Given `data` tensor of rank r >= 1, and `indices` tensor of rank q >= 1, gather + slices of `data` into an output tensor of rank q - 1 + r - indices[-1]. + Example 1: + data = [[0,1],[2,3]] + indices = [[0,0],[1,1]] + output = [0,3] + Example 2: + data = [[0,1],[2,3]] + indices = [[1],[0]] + output = [[2,3],[0,1]] + Example 3: + data = [[[0,1],[2,3]],[[4,5],[6,7]]] + indices = [[0,1],[1,0]] + output = [[2,3],[4,5]] + Example 4: + data = [[[0,1],[2,3]],[[4,5],[6,7]]] + indices = [[[0,1]],[[1,0]]] + output = [[[2,3]],[[4,5]]] + +#### Version + +This version of the operator has been available since version 1 of the 'com.microsoft' operator set. + +#### Inputs + +
+
data : T
+
Tensor of rank r >= 1.
+
indices : Tind
+
Tensor of rank q >= 1.
+
+ +#### Outputs + +
+
output : T
+
Tensor of rank q-1+r-indices[-1].
+
+ +#### Type Constraints + +
+
T : tensor(uint8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(int8), tensor(int16), tensor(int32), tensor(int64), tensor(float16), tensor(float), tensor(double), tensor(string), tensor(bool), tensor(complex64), tensor(complex128)
+
Constrain input and output types to any tensor type.
+
Tind : tensor(int32), tensor(int64)
+
Constrain indice type to int32 or int64
+
+ + +### **com.microsoft.Gelu** + + Gaussian Error Linear Unit. + A high-performing neural network activation function.The GELU nonlinearity is + the expected transformation of a stochastic regularizer which randomly applies + the identity or zero map to a neuron's input. The GELU nonlinearity weights + inputs by their magnitude, rather than gates inputs by their sign as in ReLUs. + +#### Version + +This version of the operator has been available since version 1 of the 'com.microsoft' operator set. + +#### Inputs + +
+
X : T
+
The input data as Tensor.
+
+ +#### Outputs + +
+
Y : T
+
The output.
+
+ +#### Type Constraints + +
+
T : tensor(float16), tensor(float), tensor(double), tensor(bfloat16)
+
Constrain input and output types to float tensors.
+
+ + +### **com.microsoft.GridSample** + + Given an `input` and a flow-field `grid`, computes the `output` using `input` values and pixel locations from `grid`. + Currently, only spatial (4-D) inputs are supported. For `input` with shape (N, C, H, W) and `grid` with shape (N, H_out, W_out, 2), + the `output` will have shape (N, C, H_out, W_out). + For each output location `output[n, :, h, w]`, the size-2 vector `grid[n, h, w]` specifies `input` pixel locations `x` and `y`, + which are used to interpolate the output value `output[n, :, h, w]`. + The GridSample operator is often used in doing grid generator and sampler in the [Spatial Transformer Networks](https://arxiv.org/abs/1506.02025). + See also in [torch.nn.functional.grid_sample](https://pytorch.org/docs/master/generated/torch.nn.functional.grid_sample.html#torch-nn-functional-grid-sample). + + +#### Version + +This version of the operator has been available since version 1 of the 'com.microsoft' operator set. + +#### Attributes + +
+
align_corners : int
+
If align_corners=1, the extrema (-1 and 1) are considered as referring to the center points of the input's corner pixels. If align_corners=0, they are instead considered as referring to the corner points of the input's corner pixels, making the sampling more resolution agnostic.
+
mode : string
+
Three interpolation modes: bilinear (default), nearest and bicubic.
+
padding_mode : string
+
Support padding modes for outside grid values: `zeros`(default), `border`, `reflection`. zeros: use 0 for out-of-bound grid locations, border: use border values for out-of-bound grid locations, reflection: use values at locations reflected by the border for out-of-bound grid locations.
+
+ +#### Inputs + +
+
X : T1
+
4-D tensor of shape (N, C, H, W), where N is the batch size, C is the numbers of channels, H and W are the height and width of the input data.
+
Grid : T1
+
Input offset, 4-D tensor of shape (N, H_out, W_out, 2), where H_out and W_out are the height and width of grid and output, Grid specifies the sampling pixel locations normalized by the input spatial dimensions. Therefore, it should have most values in the range of [-1, 1]. If grid has values outside the range of [-1, 1], the corresponding outputs will be handled as defined by padding_mode.
+
+ +#### Outputs + +
+
Y : T2
+
4-D tensor of shape (N, C, H_out, W_out).
+
+ +#### Type Constraints + +
+
T1 : tensor(uint8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(int8), tensor(int16), tensor(int32), tensor(int64), tensor(float16), tensor(float), tensor(double), tensor(string), tensor(bool), tensor(complex64), tensor(complex128)
+
Constrain input types to all tensor types.
+
T2 : tensor(float16), tensor(float), tensor(double)
+
Constrain output types to float tensors.
+
+ + +### **com.microsoft.Inverse** + +#### Version + +This version of the operator has been available since version 1 of the 'com.microsoft' operator set. + +#### Inputs + +
+
X : T
+
Input tensor. Every matrix in the batch must be invertible.
+
+ +#### Outputs + +
+
Y : T
+
Output tensor of the same type and shape as the input tensor.
+
+ +#### Type Constraints + +
+
T : tensor(float16), tensor(float), tensor(double)
+
Constrain input and output types to float tensors.
+
+ + +### **com.microsoft.Irfft** + +#### Version + +This version of the operator has been available since version 1 of the 'com.microsoft' operator set. + +#### Attributes + +
+
normalized : int
+
+
onesided : int
+
+
signal_ndim : int (required)
+
+
+ +#### Inputs + +
+
X : T
+
input tensor
+
+ +#### Outputs + +
+
Y : T
+
output tensor
+
+ +#### Type Constraints + +
+
T : tensor(float), tensor(double), tensor(float16)
+
Constrain input and output types to float or half tensors.
+
+ + +### **com.microsoft.LongformerAttention** + + Longformer Self Attention with a local context and a global context. Tokens attend locally: Each token + attends to its W previous tokens and W succeding tokens with W being the window length. A selected few tokens + attend globally to all other tokens. + + The attention mask is of shape (batch_size, sequence_length), where sequence_length is a multiple of 2W after padding. + Mask value < 0 (like -10000.0) means the token is masked, 0 otherwise. + + Global attention flags have value 1 for the tokens attend globally and 0 otherwise. + +#### Version + +This version of the operator has been available since version 1 of the 'com.microsoft' operator set. + +#### Attributes + +
+
num_heads : int (required)
+
Number of attention heads
+
window : int (required)
+
One sided attention windows length W, or half of total window length
+
+ +#### Inputs + +
+
input : T
+
3D input tensor with shape (batch_size, sequence_length, hidden_size), hidden_size = num_heads * head_size
+
weight : T
+
2D input tensor with shape (hidden_size, 3 * hidden_size)
+
bias : T
+
1D input tensor with shape (3 * hidden_size)
+
mask : T
+
Attention mask with shape (batch_size, sequence_length)
+
global_weight : T
+
2D input tensor with shape (hidden_size, 3 * hidden_size)
+
global_bias : T
+
1D input tensor with shape (3 * hidden_size)
+
global : G
+
Global attention flags with shape (batch_size, sequence_length)
+
+ +#### Outputs + +
+
output : T
+
3D output tensor with shape (batch_size, sequence_length, hidden_size)
+
+ +#### Type Constraints + +
+
T : tensor(float), tensor(float16)
+
Constrain input and output types to float tensors.
+
G : tensor(int32)
+
Constrain to integer types
+
+ + +### **com.microsoft.MatMulInteger16** + + Matrix product that behaves like numpy.matmul: https://docs.scipy.org/doc/numpy-1.13.0/reference/generated/numpy.matmul.html. + The production MUST never overflow. The accumulation may overflow if and only if in 32 bits. + +#### Version + +This version of the operator has been available since version 1 of the 'com.microsoft' operator set. + +#### Inputs + +
+
A : T1
+
N-dimensional matrix A
+
B : T2
+
N-dimensional matrix B
+
+ +#### Outputs + +
+
Y : T3
+
Matrix multiply results from A * B
+
+ +#### Type Constraints + +
+
T1 : tensor(int16), tensor(uint16)
+
Constrain input A data types as 16-bit integer tensor
+
T2 : tensor(int16), tensor(uint16)
+
Constrain input B data types as 16-bit integer tensor
+
T3 : tensor(int32), tensor(uint32)
+
Constrain output Y data types as 32-bit integer tensor.T3 must be tensor(uint32) when both T1 and T2 are tensor(uint16),or must be tensor(int32) when either T1 or T2 is tensor(int16).
+
+ + +### **com.microsoft.MatMulIntegerToFloat** + +#### Version + +This version of the operator has been available since version 1 of the 'com.microsoft' operator set. + +#### Inputs (4 - 7) + +
+
A : T1
+
N-dimensional matrix A
+
B : T2
+
N-dimensional matrix B
+
a_scale : T3
+
Scale of quantized input 'A'. It could be a scalar or a 1-D tensor, which means a per-tensor or per-column quantization. If it's a 1-D tensor, its number of elements should be equal to the number of columns of input 'A'.
+
b_scale : T3
+
Scale of quantized input 'B'. It could be a scalar or a 1-D tensor, which means a per-tensor or per-column quantization. If it's a 1-D tensor, its number of elements should be equal to the number of columns of input 'B'.
+
a_zero_point (optional) : T1
+
Zero point tensor for input 'A'. It's optional and default value is 0. It could be a scalar or a 1-D tensor, which means a per-tensor or per-column quantization. If it's a 1-D tensor, its number of elements should be equal to the number of columns of input 'A'.
+
b_zero_point (optional) : T2
+
Zero point tensor for input 'B'. It's optional and default value is 0. It could be a scalar or a 1-D tensor, which means a per-tensor or per-column quantization. If it's a 1-D tensor, its number of elements should be equal to the number of columns of input 'B'.
+
bias (optional) : T3
+
1D input tensor, whose dimension is same as B's last dimension
+
+ +#### Outputs + +
+
Y : T3
+
Matrix multiply results from A * B
+
+ +#### Type Constraints + +
+
T1 : tensor(int8), tensor(uint8)
+
Constrain input A data type to 8-bit integer tensor.
+
T2 : tensor(int8), tensor(uint8)
+
Constrain input B data type to 8-bit integer tensor.
+
T3 : tensor(float)
+
Constrain input a_scale, b_scale and output Y data type as float tensor.
+
+ + +### **com.microsoft.MaxpoolWithMask** + + For internal use. + +#### Version + +This version of the operator has been available since version 1 of the 'com.microsoft' operator set. + +#### Attributes + +
+
auto_pad : string
+
+
kernel_shape : list of ints
+
+
pads : list of ints
+
+
storage_order : int
+
+
strides : list of ints
+
+
+ +#### Inputs + +
+
X : T
+
+
M : tensor(int32)
+
mask
+
+ +#### Outputs + +
+
Y : T
+
+
+ +#### Type Constraints + +
+
T : tensor(float)
+
Constrain input0 and output types to float tensors
+
+ + +### **com.microsoft.MulInteger** + + Performs element-wise binary quantized multiplication (with Numpy-style broadcasting support). + "This operator supports **multidirectional (i.e., Numpy-style) broadcasting**" + The output of this op is the int32 accumulated result of the mul operation + + ``` + C (int32) = (A - A_zero_point) * (B - B_zero_point) + ``` + + +#### Version + +This version of the operator has been available since version 1 of the 'com.microsoft' operator set. + +#### Inputs (3 - 4) + +
+
A : T
+
First operand.
+
A_zero_point (optional) : T
+
Input A zero point. Default value is 0 if it's not specified. It's a scalar, which means a per-tensor/layer quantization.
+
B : T
+
Second operand.
+
B_zero_point (optional) : T
+
Input B zero point. Default value is 0 if it's not specified. It's a scalar, which means a per-tensor/layer quantization.
+
+ +#### Outputs + +
+
C : T1
+
Constrain output to 32 bit tensor
+
+ +#### Type Constraints + +
+
T : tensor(uint8), tensor(int8)
+
Constrain input types to 8 bit signed and unsigned tensors.
+
T1 : tensor(int32)
+
Constrain output types to 32 bit tensors.
+
+ + +### **com.microsoft.MurmurHash3** + + The underlying implementation is MurmurHash3_x86_32 generating low latency 32bits hash suitable for implementing lookup tables, Bloom filters, count min sketch or feature hashing. + +#### Version + +This version of the operator has been available since version 1 of the 'com.microsoft' operator set. + +#### Attributes + +
+
positive : int
+
If value is 1, output type is uint32_t, else int32_t. Default value is 1.
+
seed : int
+
Seed for the hashing algorithm, unsigned 32-bit integer, default to 0.
+
+ +#### Inputs + +
+
X : T1
+
An input tensor to hash.
+
+ +#### Outputs + +
+
Y : T2
+
32-bit hash value.
+
+ +#### Type Constraints + +
+
T1 : tensor(uint32), tensor(int32), tensor(uint64), tensor(int64), tensor(float), tensor(double), tensor(string)
+
Constrain input type to unsigned or signed 32-bit integer tensor, or string tensor. It should be utf-8 encoded if using unicode.
+
T2 : tensor(uint32), tensor(int32)
+
Constrain output type to unsigned and signed 32-bit integer tensor.
+
+ + +### **com.microsoft.NGramRepeatBlock** + + Enforce no repetition of n-grams. Scores are set to `-inf` for tokens that form a repeated n-gram if added to the back of the input_ids. + +#### Version + +This version of the operator has been available since version 1 of the 'com.microsoft' operator set. + +#### Attributes + +
+
ngram_size : int (required)
+
The NGram size.
+
+ +#### Inputs + +
+
input_ids : Tid
+
2D input tensor with shape (batch_size, sequence_length)
+
scores : T
+
2D input tensor with shape (batch_size, vocab_size)
+
+ +#### Outputs + +
+
scores_out : T
+
2D output tensor with shape (batch_size, vocab_size)
+
+ +#### Type Constraints + +
+
Tid : tensor(int64)
+
Constrain indices to integer types
+
T : tensor(float)
+
Constrain scores input and output types to float tensors.
+
+ + +### **com.microsoft.NhwcMaxPool** + +#### Version + +This version of the operator has been available since version 1 of the 'com.microsoft' operator set. + +#### Attributes + +
+
auto_pad : string
+
+
ceil_mode : int
+
+
dilations : list of ints
+
+
kernel_shape : list of ints (required)
+
+
pads : list of ints
+
+
strides : list of ints
+
+
+ +#### Inputs + +
+
x : T
+
+
+ +#### Outputs + +
+
y : T
+
+
+ +#### Type Constraints + +
+
T : tensor(int8), tensor(uint8)
+
+
+ + +### **com.microsoft.Pad** + + Given `data` tensor, pads, mode, and value. + Example: + Insert 0 pads to the beginning of the second dimension. + data = [ + [1.0, 1.2], + [2.3, 3.4], + [4.5, 5.7], + ] + pads = [0, 2, 0, 0] + output = [ + [ + [0.0, 0.0, 1.0, 1.2], + [0.0, 0.0, 2.3, 3.4], + [0.0, 0.0, 4.5, 5.7], + ], + ] + + +#### Version + +This version of the operator has been available since version 1 of the 'com.microsoft' operator set. + +#### Attributes + +
+
mode : string
+
Three modes: `constant`(default) - pads with a given constant value, `reflect` - pads with the reflection of the vector mirrored on the first and last values of the vector along each axis, `edge` - pads with the edge values of array
+
+ +#### Inputs (2 - 3) + +
+
data : T
+
Input tensor.
+
pads : tensor(int64)
+
Tensor of integers indicating the number of padding elements to add or remove (if negative) at the beginning and end of each axis. For 2D input tensor, it is the number of pixels. `pads` should be a 1D tensor of shape [2 * input_rank] or a 2D tensor of shape [1, 2 * input_rank]. `pads` format (1D example) should be as follow [x1_begin, x2_begin,...,x1_end, x2_end,...], where xi_begin is the number of pixels added at the beginning of axis `i` and xi_end, the number of pixels added at the end of axis `i`.
+
value (optional) : T
+
(Optional) A scalar or rank 1 tensor containing a single value to be filled if the mode chosen is `constant` (by default it is 0.0).
+
+ +#### Outputs + +
+
output : T
+
Tensor after padding.
+
+ +#### Type Constraints + +
+
T : tensor(float16), tensor(float), tensor(double)
+
Constrain input and output types to float tensors.
+
+ + +### **com.microsoft.QAttention** + + Quantization of Multi-Head Self Attention. + +#### Version + +This version of the operator has been available since version 1 of the 'com.microsoft' operator set. + +#### Attributes + +
+
num_heads : int (required)
+
Number of attention heads
+
unidirectional : int
+
Whether every token can only attend to previous tokens. Default value is 0.
+
+ +#### Inputs (5 - 9) + +
+
input : T1
+
3D input tensor with shape (batch_size, sequence_length, input_hidden_size)
+
weight : T2
+
2D input tensor with shape (input_hidden_size, 3 * hidden_size), hidden_size = num_heads * head_size
+
bias : T3
+
1D input tensor with shape (3 * hidden_size)
+
input_scale : T3
+
scale of quantized input tensor. It's a scalar, which means a per-tensor/layer quantization.
+
weight_scale : T3
+
scale of weight scale. It's a scalar or a 1D tensor, which means a per-tensor/per-column quantization.Its size should be 3 * hidden_size if it is per-column quantization
+
mask_index (optional) : T4
+
Attention mask index with shape (batch_size)
+
input_zero_point (optional) : T1
+
zero point of quantized input tensor.It's a scalar, which means a per-tensor/layer quantization.
+
weight_zero_point (optional) : T2
+
zero point of quantized weight tensor. It's a scalar or a 1D tensor, which means a per-tensor/per-column quantization.Its size should be 3 * hidden_size if it is per-column quantization
+
past (optional) : T3
+
past state for key and value with shape (2, batch_size, num_heads, past_sequence_length, head_size).
+
+ +#### Outputs (1 - 2) + +
+
output : T3
+
3D output tensor with shape (batch_size, sequence_length, hidden_size)
+
present (optional) : T3
+
present state for key and value with shape (2, batch_size, num_heads, past_sequence_length + sequence_length, head_size)
+
+ +#### Type Constraints + +
+
T1 : tensor(int8), tensor(uint8)
+
Constrain input and output types to int8 tensors.
+
T2 : tensor(int8), tensor(uint8)
+
Constrain input and output types to int8 tensors.
+
T3 : tensor(float), tensor(float16)
+
Constrain input and output types to float tensors.
+
T4 : tensor(int32)
+
Constrain mask index to integer types
+
+ + +### **com.microsoft.QGemm** + + Quantized Gemm + +#### Version + +This version of the operator has been available since version 1 of the 'com.microsoft' operator set. + +#### Attributes + +
+
alpha : float
+
Scalar multiplier for the product of input tensors A * B.
+
transA : int
+
Whether A should be transposed
+
transB : int
+
Whether B should be transposed
+
+ +#### Inputs (6 - 9) + +
+
A : TA
+
Input tensor A. The shape of A should be (M, K) if transA is 0, or (K, M) if transA is non-zero.
+
a_scale : T
+
Scale of quantized input 'A'. It is a scalar,which means a per-tensor quantization.
+
a_zero_point : TA
+
Zero point tensor for input 'A'. It is a scalar.
+
B : TB
+
Input tensor B. The shape of B should be (K, N) if transB is 0, or (N, K) if transB is non-zero.
+
b_scale : T
+
Scale of quantized input 'B'. It could be a scalar or a 1-D tensor, which means a per-tensor or per-column quantization. If it's a 1-D tensor, its number of elements should be equal to the number of columns of input 'B'.
+
b_zero_point : TB
+
Zero point tensor for input 'B'. It's optional and default value is 0. It could be a scalar or a 1-D tensor, which means a per-tensor or per-column quantization. If it's a 1-D tensor, its number of elements should be equal to the number of columns of input 'B'.
+
C (optional) : TC
+
Optional input tensor C. If not specified, the computation is done as if C is a scalar 0. The shape of C should be unidirectional broadcastable to (M, N). Its type is int32_t and must be quantized with zero_point = 0 and scale = alpha / beta * a_scale * b_scale.
+
y_scale (optional) : T
+
Scale of output 'Y'. It is a scalar, which means a per-tensor quantization. It is optional. The output is full precision(float32) if it is not provided. Or the output is quantized.
+
y_zero_point (optional) : TYZ
+
Zero point tensor for output 'Y'. It is a scalar, which means a per-tensor quantization. It is optional. The output is full precision(float32) if it is not provided. Or the output is quantized.
+
+ +#### Outputs + +
+
Y : TY
+
Output tensor of shape (M, N).
+
+ +#### Type Constraints + +
+
T : tensor(float)
+
Constrain scale types to float tensors.
+
TA : tensor(uint8), tensor(int8)
+
Constrain input A and its zero point types to 8 bit tensors.
+
TB : tensor(uint8), tensor(int8)
+
Constrain input B and its zero point types to 8 bit tensors.
+
TC : tensor(int32)
+
Constrain input C to 32 bit integer tensors.
+
TYZ : tensor(uint8), tensor(int8)
+
Constrain output zero point types to 8 bit tensors.
+
TY : tensor(float), tensor(uint8), tensor(int8)
+
Constrain output type to float32 or 8 bit tensors.
+
+ + +### **com.microsoft.QLinearAdd** + + Performs element-wise binary addition on 8 bit data types (with Numpy-style broadcasting support). + + C = (A_scale * (A - A_zero_point) + B_scale * (B - B_zero_point))/C_scale + C_zero_point + +#### Version + +This version of the operator has been available since version 1 of the 'com.microsoft' operator set. + +#### Inputs (7 - 8) + +
+
A : T
+
First operand.
+
A_scale : tensor(float)
+
Input A's scale. It's a scalar, which means a per-tensor/layer quantization.
+
A_zero_point (optional) : T
+
Input A zero point. Default value is 0 if it's not specified. It's a scalar, which means a per-tensor/layer quantization.
+
B : T
+
Second operand.
+
B_scale : tensor(float)
+
Input B's scale. It's a scalar, which means a per-tensor/layer quantization.
+
B_zero_point (optional) : T
+
Input B zero point. Default value is 0 if it's not specified. It's a scalar, which means a per-tensor/layer quantization.
+
C_scale : tensor(float)
+
Output scale. It's a scalar, which means a per-tensor/layer quantization.
+
C_zero_point (optional) : T
+
Output zero point. Default value is 0 if it's not specified. It's a scalar, which means a per-tensor/layer quantization.
+
+ +#### Outputs + +
+
C : T
+
Result, has same element type as two inputs
+
+ +#### Type Constraints + +
+
T : tensor(uint8), tensor(int8)
+
Constrain input and output types to 8 bit signed and unsigned tensors.
+
+ + +### **com.microsoft.QLinearAveragePool** + + QLinearAveragePool consumes an input tensor X and applies average pooling across + the tensor according to kernel sizes, stride sizes, and pad lengths. + average pooling consisting of computing the average on all values of a + subset of the input tensor according to the kernel size and downsampling the + data into the output tensor Y for further processing. The output spatial shape will be following: + ``` + output_spatial_shape[i] = floor((input_spatial_shape[i] + pad_shape[i] - kernel_spatial_shape[i]) / strides_spatial_shape[i] + 1) + ``` + or + ``` + output_spatial_shape[i] = ceil((input_spatial_shape[i] + pad_shape[i] - kernel_spatial_shape[i]) / strides_spatial_shape[i] + 1) + ``` + if ceil_mode is enabled + + ``` + * pad_shape[i] is sum of pads along axis i + ``` + + `auto_pad` is a DEPRECATED attribute. If you are using them currently, the output spatial shape will be following: + ``` + VALID: output_spatial_shape[i] = ceil((input_spatial_shape[i] - kernel_spatial_shape[i] + 1) / strides_spatial_shape[i]) + SAME_UPPER or SAME_LOWER: output_spatial_shape[i] = ceil(input_spatial_shape[i] / strides_spatial_shape[i]) + ``` + And pad shape will be following if `SAME_UPPER` or `SAME_LOWER`: + ``` + pad_shape[i] = (output_spatial_shape[i] - 1) * strides_spatial_shape[i] + kernel_spatial_shape[i] - input_spatial_shape[i] + ``` + + The output of each pooling window is divided by the number of elements (exclude pad when attribute count_include_pad is zero). + + Input and output scales and zero points are used to convert the output to a new quantization range. + Output = Dequantize(Input) -> AveragePool on fp32 data -> Quantize(output) + +#### Version + +This version of the operator has been available since version 1 of the 'com.microsoft' operator set. + +#### Attributes + +
+
auto_pad : string
+
auto_pad must be either NOTSET, SAME_UPPER, SAME_LOWER or VALID. Where default value is NOTSET, which means explicit padding is used. SAME_UPPER or SAME_LOWER mean pad the input so that the output spatial size match the input.In case of odd number add the extra padding at the end for SAME_UPPER and at the beginning for SAME_LOWER. VALID mean no padding.
+
ceil_mode : int
+
Whether to use ceil or floor (default) to compute the output shape.
+
channels_last : int
+
Works on NHWC layout or not? Default not.
+
count_include_pad : int
+
Whether include pad pixels when calculating values for the edges. Default is 0, doesn't count include pad.
+
kernel_shape : list of ints (required)
+
The size of the kernel along each axis.
+
pads : list of ints
+
Padding for the beginning and ending along each spatial axis, it can take any value greater than or equal to 0. The value represent the number of pixels added to the beginning and end part of the corresponding axis. `pads` format should be as follow [x1_begin, x2_begin...x1_end, x2_end,...], where xi_begin the number of pixels added at the beginning of axis `i` and xi_end, the number of pixels added at the end of axis `i`. This attribute cannot be used simultaneously with auto_pad attribute. If not present, the padding defaults to 0 along start and end of each spatial axis.
+
strides : list of ints
+
Stride along each spatial axis. If not present, the stride defaults to 1 along each spatial axis.
+
+ +#### Inputs (4 - 5) + +
+
X : T
+
Input data tensor from the previous operator; dimensions for image case are (N x C x H x W), where N is the batch size, C is the number of channels, and H and W are the height and the width of the data. For non image case, the dimensions are in the form of (N x C x D1 x D2 ... Dn), where N is the batch size. Optionally, if dimension denotation is in effect, the operation expects the input data tensor to arrive with the dimension denotation of [DATA_BATCH, DATA_CHANNEL, DATA_FEATURE, DATA_FEATURE ...].
+
x_scale : tensor(float)
+
Input scale. It's a scalar, which means a per-tensor/layer quantization.
+
x_zero_point (optional) : T
+
Input zero point. Default value is 0 if it's not specified. It's a scalar, which means a per-tensor/layer quantization.
+
y_scale : tensor(float)
+
Output scale. It's a scalar, which means a per-tensor/layer quantization.
+
y_zero_point (optional) : T
+
Output zero point. Default value is 0 if it's not specified. It's a scalar, which means a per-tensor/layer quantization.
+
+ +#### Outputs + +
+
Y : T
+
Output data tensor from average or max pooling across the input tensor. Dimensions will vary based on various kernel, stride, and pad sizes. Floor value of the dimension is used
+
+ +#### Type Constraints + +
+
T : tensor(uint8), tensor(int8)
+
Constrain input and output types to 8 bit tensors.
+
+ + +### **com.microsoft.QLinearConcat** + + Concatenate a list of tensors into a single tensor.All input tensors must have the same shape, except for the dimension size of the axis to concatenate on. + +#### Version + +This version of the operator has been available since version 1 of the 'com.microsoft' operator set. + +#### Attributes + +
+
axis : int (required)
+
Which axis to concat on
+
+ +#### Inputs (3 - ∞) + +
+
Y_scale : TF
+
Y's scale.
+
Y_zero_point : T8
+
Y's zero point.
+
inputs (variadic, heterogeneous) : TV
+
List of tensors/scale/zero_point for concatenation
+
+ +#### Outputs + +
+
Y : T8
+
Concatenated tensor
+
+ +#### Type Constraints + +
+
T8 : tensor(uint8), tensor(int8)
+
Constrain input and output types to 8 bit signed and unsigned tensors.
+
TF : tensor(float)
+
Constrain scale types to any float tensor type.
+
TV : tensor(uint8), tensor(int8), tensor(float)
+
Sequence of (Tensor, Scale, ZeroPoint) tuples. The type is sequence of (T8, TF, T8).
+
+ + +### **com.microsoft.QLinearConv** + +#### Version + +This version of the operator has been available since version 1 of the 'com.microsoft' operator set. + +#### Attributes + +
+
auto_pad : string
+
+
channels_last : int
+
+
dilations : list of ints
+
+
group : int
+
+
kernel_shape : list of ints
+
+
pads : list of ints
+
+
strides : list of ints
+
+
+ +#### Inputs (8 - 9) + +
+
x : T1
+
+
x_scale : tensor(float)
+
+
x_zero_point : T1
+
+
w : T2
+
+
w_scale : tensor(float)
+
+
w_zero_point : T2
+
+
y_scale : tensor(float)
+
+
y_zero_point : T3
+
+
B (optional) : T4
+
+
+ +#### Outputs + +
+
y : T3
+
+
+ +#### Type Constraints + +
+
T1 : tensor(int8), tensor(uint8)
+
+
T2 : tensor(int8), tensor(uint8)
+
+
T3 : tensor(int8), tensor(uint8)
+
+
T4 : tensor(int32)
+
+
+ + +### **com.microsoft.QLinearGlobalAveragePool** + + QLinearGlobalAveragePool consumes an input tensor X and applies Average pooling across + the values in the same channel. This is equivalent to AveragePool with kernel size + equal to the spatial dimension of input tensor. Input is of type uint8_t or int8_t. + +#### Version + +This version of the operator has been available since version 1 of the 'com.microsoft' operator set. + +#### Attributes + +
+
channels_last : int
+
+
+ +#### Inputs + +
+
X : T
+
Input data tensor from the previous operator; According to channels_last, dimensions for image case are (N x C x H x W), or (N x H x W x C) where N is the batch size, C is the number of channels, and H and W are the height and the width of the data. For non image case, the dimensions are in the form of (N x C x D1 x D2 ... Dn), or (N x D1 X D2 ... Dn x C) where N is the batch size.
+
x_scale : tensor(float)
+
Scale of quantized input 'X'. It must be a scalar.
+
x_zero_point : T
+
Zero point tensor for input 'X'. It must be a scalar.
+
y_scale : tensor(float)
+
Scale of quantized output 'Y'. It must be a scalar.
+
y_zero_point : T
+
Zero point tensor for output 'Y'. It must be a scalar.
+
+ +#### Outputs + +
+
Y : T
+
Output data tensor from pooling across the input tensor. The output tensor has the same rank as the input. with the N and C value keep it value, while the otherdimensions are all 1.
+
+ +#### Type Constraints + +
+
T : tensor(uint8), tensor(int8)
+
Constrain input and output types to singed/unsigned int8 tensors.
+
+ + +### **com.microsoft.QLinearLeakyRelu** + + QLinearLeakyRelu takes quantized input data (Tensor), an argument alpha, and quantize parameter for output, + and produces one output data (Tensor) where the function `f(x) = quantize(alpha * dequantize(x)) for dequantize(x) < 0`, + `f(x) = quantize(dequantize(x)) for dequantize(x) >= 0`, is applied to the data tensor elementwise. + +#### Version + +This version of the operator has been available since version 1 of the 'com.microsoft' operator set. + +#### Attributes + +
+
alpha : float
+
Coefficient of leakage.
+
+ +#### Inputs (4 - 5) + +
+
X : T
+
Input tensor
+
X_scale : tensor(float)
+
Input X's scale. It's a scalar, which means a per-tensor/layer quantization.
+
X_zero_point (optional) : T
+
Input X's zero point. Default value is 0 if it's not specified. It's a scalar, which means a per-tensor/layer quantization.
+
Y_scale : tensor(float)
+
Output Y's scale. It's a scalar, which means a per-tensor/layer quantization.
+
Y_zero_point (optional) : T
+
Output Y's zero point. Default value is 0 if it's not specified. It's a scalar, which means a per-tensor/layer quantization.
+
+ +#### Outputs + +
+
Y : T
+
Output tensor
+
+ +#### Type Constraints + +
+
T : tensor(uint8), tensor(int8)
+
Constrain input and output types to 8 bit tensors.
+
+ + +### **com.microsoft.QLinearMul** + + Performs element-wise binary multiplication on 8 bit data types (with Numpy-style broadcasting support). + + C = ((A - A_zero_point) * (B - B_zero_point)) * (A_scale * B_scale)/C_scale + C_zero_point + +#### Version + +This version of the operator has been available since version 1 of the 'com.microsoft' operator set. + +#### Inputs (7 - 8) + +
+
A : T
+
First operand.
+
A_scale : tensor(float)
+
Input A's scale. It's a scalar, which means a per-tensor/layer quantization.
+
A_zero_point (optional) : T
+
Input A zero point. Default value is 0 if it's not specified. It's a scalar, which means a per-tensor/layer quantization.
+
B : T
+
Second operand.
+
B_scale : tensor(float)
+
Input B's scale. It's a scalar, which means a per-tensor/layer quantization.
+
B_zero_point (optional) : T
+
Input B zero point. Default value is 0 if it's not specified. It's a scalar, which means a per-tensor/layer quantization.
+
C_scale : tensor(float)
+
Output scale. It's a scalar, which means a per-tensor/layer quantization.
+
C_zero_point (optional) : T
+
Output zero point. Default value is 0 if it's not specified. It's a scalar, which means a per-tensor/layer quantization.
+
+ +#### Outputs + +
+
C : T
+
Result, has same element type as two inputs
+
+ +#### Type Constraints + +
+
T : tensor(uint8), tensor(int8)
+
Constrain input and output types to 8 bit signed and unsigned tensors.
+
+ + +### **com.microsoft.QLinearReduceMean** + + Computes the mean of the low-precision input tensor's element along the provided axes. + The resulting tensor has the same rank as the input if keepdims equal 1. If keepdims equal 0, + then the resulting tensor have the reduced dimension pruned. The above behavior is similar to numpy, + with the exception that numpy default keepdims to False instead of True. + Input and Output scales and zero points are used to requantize the output in a new range. + This helps to improve accuracy as after ReduceMean operation the range of the output is expected to decrease. + + ``` + "Output = Dequantize(Input) -> ReduceMean on fp32 data -> Quantize(output)", + + ``` + +#### Version + +This version of the operator has been available since version 1 of the 'com.microsoft' operator set. + +#### Attributes + +
+
axes : list of ints (required)
+
A list of integers, along which to reduce. The default is to reduce over all the dimensions of the input tensor.
+
keepdims : int (required)
+
Keep the reduced dimension or not, default 1 mean keep reduced dimension.
+
+ +#### Inputs (4 - 5) + +
+
data : T
+
An input tensor.
+
data_scale : tensor(float)
+
Input scale. It's a scalar, which means a per-tensor/layer quantization.
+
data_zero_point (optional) : T
+
Input zero point. Default value is 0 if it's not specified. It's a scalar, which means a per-tensor/layer quantization.
+
reduced_scale : tensor(float)
+
Output scale. It's a scalar, which means a per-tensor/layer quantization.
+
reduced_zero_point (optional) : T
+
Output zero point. Default value is 0 if it's not specified. It's a scalar, which means a per-tensor/layer quantization.
+
+ +#### Outputs + +
+
reduced : T
+
Reduced output tensor.
+
+ +#### Type Constraints + +
+
T : tensor(uint8), tensor(int8)
+
Constrain input types to 8 bit signed and unsigned tensors.
+
+ + +### **com.microsoft.QLinearSigmoid** + + QLinearSigmoid takes quantized input data (Tensor), and quantize parameter for output, and produces one output data + (Tensor) where the function `f(x) = quantize(Sigmoid(dequantize(x)))`, is applied to the data tensor elementwise. + Wwhere the function `Sigmoid(x) = 1 / (1 + exp(-x))` + +#### Version + +This version of the operator has been available since version 1 of the 'com.microsoft' operator set. + +#### Inputs (4 - 5) + +
+
X : T
+
Input tensor
+
X_scale : tensor(float)
+
Input X's scale. It's a scalar, which means a per-tensor/layer quantization.
+
X_zero_point (optional) : T
+
Input X's zero point. Default value is 0 if it's not specified. It's a scalar, which means a per-tensor/layer quantization.
+
Y_scale : tensor(float)
+
Output Y's scale. It's a scalar, which means a per-tensor/layer quantization.
+
Y_zero_point (optional) : T
+
Output Y's zero point. Default value is 0 if it's not specified. It's a scalar, which means a per-tensor/layer quantization.
+
+ +#### Outputs + +
+
Y : T
+
Output tensor
+
+ +#### Type Constraints + +
+
T : tensor(uint8), tensor(int8)
+
Constrain input and output types to 8 bit tensors.
+
+ + +### **com.microsoft.QuantizeLinear** + + The linear quantization operator. It consumes a full precision data, a scale, a zero point to compute the low precision / quantized tensor. + The quantization formula is y = saturate ((x / y_scale) + y_zero_point).For saturation, it saturates to [0, 255] if it's uint8, or [-128, 127] if it's int8. + For (x / y_scale), it's rounding to nearest ties to even. Refer to https://en.wikipedia.org/wiki/Rounding for details. + Scale and zero point must have same shape. They must be either scalar (per tensor) or 1-D tensor (per 'axis'). + +#### Version + +This version of the operator has been available since version 1 of the 'com.microsoft' operator set. + +#### Attributes + +
+
axis : int
+
The axis along which same quantization parameters are applied. It's optional.If it's not specified, it means per-tensor quantization and input 'x_scale' and 'x_zero_point' must be scalars.If it's specified, it means per 'axis' quantization and input 'x_scale' and 'x_zero_point' must be 1-D tensors.
+
+ +#### Inputs + +
+
x : T1
+
N-D full precision Input tensor to be quantized.
+
y_scale : T1
+
Scale for doing quantization to get 'y'. It could be a scalar or a 1-D tensor,which means a per-tensor or per-axis quantization. If it's a 1-D tensor, its number of elements should be equal to the dimension value of 'axis' dimension of input 'x'.
+
y_zero_point : T2
+
Zero point for doing quantization to get 'y'. It could be a scalar or a 1-D tensor, which means a per-tensoror per-axis quantization. If it's a 1-D tensor, its number of elements should be equal to the dimension value of 'axis' dimension of input 'x'.
+
+ +#### Outputs + +
+
y : T2
+
N-D quantized output tensor. It has same shape as input 'x'.
+
+ +#### Type Constraints + +
+
T1 : tensor(float16), tensor(float)
+
Constrain 'x', 'y_scale' to float tensors.
+
T2 : tensor(int8), tensor(uint8)
+
Constrain 'y_zero_point' and 'y' to 8-bit integer tensors.
+
+ + +### **com.microsoft.Range** + + Creates a sequence of numbers that begins at `start` and extends by increments of `delta` + up to but not including `limit`. + +#### Version + +This version of the operator has been available since version 1 of the 'com.microsoft' operator set. + +#### Inputs (2 - 3) + +
+
start : T
+
Tensor(scalar, or dims=[1]). First entry in the range.
+
limit : T
+
Tensor(scalar, or dims=[1]). Upper limit of sequence, exclusive.
+
delta (optional) : T
+
Tensor(scalar, or dims=[1]). Number that increments start. Defaults to 1.
+
+ +#### Outputs + +
+
Y : T
+
1-D Tensor of the range.
+
+ +#### Type Constraints + +
+
T : tensor(float), tensor(double), tensor(int16), tensor(int32), tensor(int64)
+
Constrain input and output types.
+
+ + +### **com.microsoft.ReduceSumInteger** + + Computes the sum of the low-precision input tensor's element along the provided axes. + The resulting tensor has the same rank as the input if keepdims equal 1. If keepdims equal 0, + then the resulting tensor have the reduced dimension pruned. The above behavior is similar to numpy, + with the exception that numpy default keepdims to False instead of True. + +#### Version + +This version of the operator has been available since version 1 of the 'com.microsoft' operator set. + +#### Attributes + +
+
axes : list of ints (required)
+
A list of integers, along which to reduce. The default is to reduce over all the dimensions of the input tensor.
+
keepdims : int (required)
+
Keep the reduced dimension or not, default 1 mean keep reduced dimension.
+
+ +#### Inputs + +
+
data : T1
+
An input tensor.
+
+ +#### Outputs + +
+
reduced : T2
+
Reduced output tensor.
+
+ +#### Type Constraints + +
+
T1 : tensor(int8), tensor(uint8)
+
Constrain input type to 8-bit integer tensor.
+
T2 : tensor(int32), tensor(uint32)
+
Constrain output data type to 32-bit integer tensor.T2 must be tensor(uint32) when T1 is tensor(uint8),or must be tensor(int32) when T1 is tensor(int8).
+
+ + +### **com.microsoft.Rfft** + +#### Version + +This version of the operator has been available since version 1 of the 'com.microsoft' operator set. + +#### Attributes + +
+
normalized : int
+
+
onesided : int
+
+
signal_ndim : int
+
+
+ +#### Inputs + +
+
X : T
+
input tensor
+
+ +#### Outputs + +
+
Y : T
+
output tensor
+
+ +#### Type Constraints + +
+
T : tensor(float), tensor(double), tensor(float16)
+
Constrain input and output types to float or half tensors.
+
+ + +### **com.microsoft.SampleOp** + + Sample echo operator. + +#### Version + +This version of the operator has been available since version 1 of the 'com.microsoft' operator set. + +#### Inputs + +
+
X : T
+
input
+
+ +#### Outputs + +
+
Y : T
+
output
+
+ +#### Type Constraints + +
+
T : tensor(uint32), tensor(uint64), tensor(int32), tensor(int64), tensor(float16), tensor(float), tensor(double)
+
Constrain to any tensor type. If the dtype attribute is not provided this must be a valid output type.
+
+ + +### **com.microsoft.SkipLayerNormalization** + + Skip and Layer Normalization Fusion + +#### Version + +This version of the operator has been available since version 1 of the 'com.microsoft' operator set. + +#### Attributes + +
+
epsilon : float
+
The epsilon value to use to avoid division by zero.
+
+ +#### Inputs (3 - 5) + +
+
input : T
+
3D input tensor with shape (batch_size, sequence_length, hidden_size)
+
skip : T
+
3D skip tensor with shape (batch_size, sequence_length, hidden_size)
+
gamma : T
+
1D input tensor with shape (hidden_size)
+
beta (optional) : T
+
1D skip tensor with shape (hidden_size
+
bias (optional) : T
+
1D bias tensor with shape (hidden_size
+
+ +#### Outputs (1 - 3) + +
+
output : T
+
3D output tensor with shape (batch_size, sequence_length, hidden_size)
+
mean (optional) : U
+
Saved mean used during training to speed up gradient computation
+
inv_std_var (optional) : U
+
Saved inverse standard variance used during training to speed up gradient computation.
+
+ +#### Type Constraints + +
+
T : tensor(float), tensor(float16)
+
Constrain input and output types to float or half tensors.
+
U : tensor(float)
+
Constrain mean and inv_std_var to float tensors.
+
+ + +### **com.microsoft.SparseToDenseMatMul** + +#### Version + +This version of the operator has been available since version 1 of the 'com.microsoft' operator set. + +#### Attributes + +
+
alpha : float
+
Scalar multiplier for the product of the input tensors.
+
transA : int
+
Whether A should be transposed on the last two dimensions before doing multiplication
+
transB : int
+
Whether B should be transposed on the last two dimensions before doing multiplication
+
+ +#### Inputs + +
+
A : T
+
2-dimensional sparse matrix A. Either COO or CSR format
+
B : T1
+
N-dimensional dense matrix B
+
+ +#### Outputs + +
+
Y : T1
+
Matrix multiply results
+
+ +#### Type Constraints + +
+
T : sparse_tensor(float), sparse_tensor(double), sparse_tensor(int64), sparse_tensor(int32), sparse_tensor(uint64), sparse_tensor(uint32)
+
Constrain input and output types to float tensors.
+
T1 : tensor(float), tensor(double), tensor(int64), tensor(int32), tensor(uint64), tensor(uint32)
+
Constrain input and output types to float tensors.
+
+ + +### **com.microsoft.Tokenizer** + + Tokenizer divides each string in X into a vector of strings along the last axis. Allowed input shapes are [C] and [N, C]. + If the maximum number of tokens found per input string is D, the output shape would be [N, C, D] when input shape is [N, C]. + Similarly, if input shape is [C] then the output should be [C, D]. Tokenizer has two different operation modes. + The first mode is selected when "tokenexp" is not set and "separators" is set. If "tokenexp" is set and "separators" is not set, + the second mode will be used. The first mode breaks each input string into tokens by matching and removing separators. + "separators" is a list of strings which are regular expressions. "tokenexp" is a single regular expression. + Let's assume "separators" is [" "] and consider an example. + If input is + ["Hello World", "I love computer science !"] whose shape is [2], + then the output would be + [["Hello", "World", padvalue, padvalue, padvalue], + ["I", "love", "computer", "science", "!"]] + whose shape is [2, 5] because you can find at most 5 tokens per input string. + Note that the input at most can have two axes, so 3-D and higher dimension are not supported. + If "separators" contains a single empty string, the Tokenizer will enter into character tokenezation mode. This means all strings + will be broken part into individual characters. + For each input string, the second mode searches matches of "tokenexp" and each match will be a token in Y. + The matching of "tokenexp" is conducted greedily (i.e., a match should be as long as possible). + This operator searches for the first match starting from the beginning of the considered string, + and then launches another search starting from the first remained character after the first matched token. + If no match found, this operator will remove the first character from the remained string and do another search. + This procedure will be repeated until reaching the end of the considered string. + Let's consider another example to illustrate the effect of setting "mark" to true. + If input is ["Hello", "World"], + then the corresponding output would be [0x02, "Hello", "World", 0x03]. + This implies that if mark is true, [C]/[N, C] - input's output shape becomes [C, D+2]/[N, C, D+2]. + If tokenizer removes the entire content of [C]-input, it will produce [[]]. + I.e. the output shape should be [C][0] or [N][C][0] if input shape was [N][C]. + If the tokenizer receives empty input of [0] then the output is [0] if empty input + of [N, 0] then [N, 0]. + +#### Version + +This version of the operator has been available since version 1 of the 'com.microsoft' operator set. + +#### Attributes + +
+
mark : int (required)
+
Boolean whether to mark the beginning/end character with start of text character (0x02)/end of text character (0x03).
+
mincharnum : int (required)
+
Minimum number of characters allowed in the output. For example, if mincharnum is 2, tokens such as "A" and "B" would be ignored
+
pad_value : string (required)
+
The string used to pad output tensors when the tokens extracted doesn't match the maximum number of tokens found. If start/end markers are needed, padding will appear outside the markers.
+
separators : list of strings
+
an optional list of strings attribute that contains a list of separators - regular expressions to match separators Two consecutive segments in X connected by a separator would be divided into two tokens. For example, if the input is "Hello World!" and this attribute contains only one space character, the corresponding output would be ["Hello", "World!"]. To achieve character-level tokenization, one should set the 'separators' to [""], which contains an empty string.
+
tokenexp : string
+
An optional string. Token's regular expression in basic POSIX format (pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap09.html#tag_09_03). If set, tokenizer may produce tokens matching the specified pattern. Note that one and only of 'tokenexp' and 'separators' should be set.
+
+ +#### Inputs + +
+
X : T
+
Strings to tokenize
+
+ +#### Outputs + +
+
Y : T
+
Tokenized strings
+
+ +#### Type Constraints + +
+
T : tensor(string)
+
Input/Output is a string tensor
+
+ + +### **com.microsoft.TorchEmbedding** + + Based on Torch operator Embedding, creates a lookup table of embedding vectors of fixed size, + for a dictionary of fixed size. + + +#### Version + +This version of the operator has been available since version 1 of the 'com.microsoft' operator set. + +#### Inputs (2 - 4) + +
+
weight : T
+
The embedding matrix of size N x M. 'N' is equal to the maximum possible index + 1, and 'M' is equal to the embedding size
+
indices : tensor(int64)
+
Long tensor containing the indices to extract from embedding matrix.
+
padding_idx (optional) : tensor(int64)
+
A 0-D scalar tensor. If specified, the entries at `padding_idx` do not contribute to the gradient; therefore, the embedding vector at `padding_idx` is not updated during training, i.e. it remains as a fixed pad.
+
scale_grad_by_freq (optional) : tensor(bool)
+
A 0-D bool tensor. If given, this will scale gradients by the inverse of frequency of the indices (words) in the mini-batch. Default is ``False``
+
+ +#### Outputs + +
+
Y : T
+
Output tensor of the same type as the input tensor. Shape of the output is * x M, where '*' is the shape of input indices, and 'M' is the embedding size.
+
+ +#### Type Constraints + +
+
T : tensor(float16), tensor(float), tensor(double), tensor(bfloat16), tensor(uint8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(int8), tensor(int16), tensor(int32), tensor(int64)
+
Constrain input and output types to all numeric tensors.
+
+ + +### **com.microsoft.TransposeMatMul** + + Duplicate of FusedMatMul. Going forward FusedMatMul should be used. This OP will be supported for backward compatibility. + Matrix product that behaves like numpy.matmul: https://docs.scipy.org/doc/numpy-1.13.0/reference/generated/numpy.matmul.html + +#### Version + +This version of the operator has been available since version 1 of the 'com.microsoft' operator set. + +#### Attributes + +
+
alpha : float
+
Scalar multiplier for the product of the input tensors.
+
transA : int
+
Whether A should be transposed on the last two dimensions before doing multiplication
+
transB : int
+
Whether B should be transposed on the last two dimensions before doing multiplication
+
+ +#### Inputs + +
+
A : T
+
N-dimensional matrix A
+
B : T
+
N-dimensional matrix B
+
+ +#### Outputs + +
+
Y : T
+
Matrix multiply results
+
+ +#### Type Constraints + +
+
T : tensor(float16), tensor(float), tensor(double), tensor(bfloat16)
+
Constrain input and output types to float tensors.
+
+ + +### **com.microsoft.Trilu** + + Returns the upper or lower triangular part of a 2-D matrix, or batches of 2-D matrices. If the attribute "upper" is set to true, + the upper triangular matrix is retained. Lower triangular matrix is retained otherwise. Default value for upper is true. + Trilu takes one input tensor of shape [*, N, M], where * is zero or more batch dimensions. The upper triangular part consists + of the elements on and above the given diagonal (k). The lower triangular part consists of elements on and below the diagonal. + All other elements in the matrix are set to zero. + If k = 0, the triangular part on and above/below the main diagonal is retained. + If upper is set to true, a positive k retains the upper triangular matrix excluding k diagonals above + the main diagonal. A negative k value includes as many diagonals below the main diagonal. + If upper is set to false, a positive k retains the lower triangular matrix including k diagonals above + the main diagonal. A negative k value excludes as many diagonals below the main diagonal. + + +#### Version + +This version of the operator has been available since version 1 of the 'com.microsoft' operator set. + +#### Attributes + +
+
upper : int
+
Boolean. Indicates whether upper or lower part of matrix is retained. Default is true.
+
+ +#### Inputs (1 - 2) + +
+
X : T
+
Input tensor of rank 2 or higher.
+
k (optional) : tensor(int64)
+
A 0-D tensor containing a single value corresponding to the number diagonals above or the main diagonal to exclude or include.Default value is 0 if it's not specified.
+
+ +#### Outputs + +
+
Y : T
+
Output tensor of the same type and shape as the input tensor.
+
+ +#### Type Constraints + +
+
T : tensor(float16), tensor(float), tensor(double), tensor(bfloat16), tensor(uint8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(int8), tensor(int16), tensor(int32), tensor(int64), tensor(bool)
+
Constrain input and output types to all numeric tensors and bool tensors.
+
+ + +### **com.microsoft.Unique** + + Finds all the unique values (deduped list) present in the given input tensor. + This operator returns 3 outputs. + The first output tensor 'uniques' contains all of the unique elements of the input, + sorted in the same order that they occur in the input. + The second output tensor 'idx' is the same size as the input and it contains the index + of each value of the input in 'uniques'. + The third output tensor 'counts' contains the count of each element of 'uniques' in the input. + Example: + input_x = [2, 1, 1, 3, 4, 3] + output_uniques = [2, 1, 3, 4] + output_idx = [0, 1, 1, 2, 3, 2] + output_counts = [1, 2, 2, 1] + + +#### Version + +This version of the operator has been available since version 1 of the 'com.microsoft' operator set. + +#### Inputs + +
+
x : T
+
A 1-D input tensor that is to be processed.
+
+ +#### Outputs + +
+
y : T
+
A 1-D tensor of the same type as 'x' containing all the unique values in 'x' sorted in the same order that they occur in the input 'x'
+
idx : tensor(int64)
+
A 1-D INT64 tensor of the same size as 'x' containing the indices for each value in 'x' in the output 'uniques'
+
counts : tensor(int64)
+
A 1-D INT64 tensor containing the the count of each element of 'uniques' in the input 'x'
+
+ +#### Type Constraints + +
+
T : tensor(uint8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(int8), tensor(int16), tensor(int32), tensor(int64), tensor(float16), tensor(float), tensor(double), tensor(string), tensor(bool), tensor(complex64), tensor(complex128)
+
Input can be of any tensor type.
+
+ + +### **com.microsoft.WordConvEmbedding** + + The WordConvEmbedding takes in a batch of sequence words and embed each word to a vector. + +#### Version + +This version of the operator has been available since version 1 of the 'com.microsoft' operator set. + +#### Attributes + +
+
char_embedding_size : int
+
Integer representing the embedding vector size for each char.If not provide, use the char embedding size of embedding vector.
+
conv_window_size : int
+
This operator applies convolution to word from left to right with window equal to conv_window_size and stride to 1.Take word 'example' for example, with conv_window_size equal to 2, conv is applied to [ex],[xa], [am], [mp]...If not provide, use the first dimension of conv kernal shape.
+
embedding_size : int
+
Integer representing the embedding vector size for each word.If not provide, use the fileter size of conv weight
+
+ +#### Inputs + +
+
Sequence : T
+
Specify batchs of sequence words to embedding
+
W : T1
+
Specify weights of conv
+
B : T1
+
Specify bias of conv
+
C : T1
+
Specify embedding vector of char
+
+ +#### Outputs + +
+
Y : T1
+
output
+
+ +#### Type Constraints + +
+
T : tensor(int32)
+
Constrain to tensor(int32).
+
T1 : tensor(float)
+
Constrain to tensor(float).
+
+ + +### experimental **com.microsoft.IsAllFinite** + + IsAllFinite + +#### Version + +No versioning maintained for experimental ops. +#### Attributes + +
+
isinf_only : int
+
If true, check only for Inf, -Inf.
+
isnan_only : int
+
If true, check only for NaN.
+
+ +#### Inputs (1 - ∞) + +
+
input (variadic) : V
+
Input tensors to check.
+
+ +#### Outputs + +
+
output : T
+
The output scalar. Its value is true if all input tensors are finite. Otherwise, the output value would be false.
+
+ +#### Type Constraints + +
+
V : tensor(float16), tensor(float), tensor(double), tensor(bfloat16)
+
Constrain input and output types to float tensors.
+
T : tensor(bool)
+
Constrain the output to a boolean tensor.
+
+ + +### experimental **com.microsoft.QEmbedLayerNormalization** + + QEmbedLayerNormalization is the quantized fusion of embedding layer in BERT model, with optional mask processing. + The embedding layer takes input_ids (word IDs) and segment_ids (sentence IDs) to look up word_embedding, position_embedding, + and segment_emedding; the embeddings are added then applied layer normalization using gamma and beta tensors. The input_ids + and segment_ids remain int32. All embeddings, gamma, and beta tensors are converted to int8/uint8. The last input mask is optional. + If mask is provided, mask index (that is position of first 0 in mask, or number of words will be calculated. + +#### Version + +No versioning maintained for experimental ops. +#### Attributes + +
+
epsilon : float
+
The epsilon value to use to avoid division by zero.
+
+ +#### Inputs + +
+
input_ids : T1
+
2D words IDs with shape (batch_size, sequence_length)
+
segment_ids (optional) : T1
+
2D segment IDs with shape (batch_size, sequence_length)
+
word_embedding_quant : T2
+
2D with shape (,hidden_size)
+
position_embedding_quant : T2
+
2D with shape (, hidden_size)
+
segment_embedding (optional) : T2
+
2D with shape (, hidden_size)
+
gamma_quant : T2
+
1D gamma tensor for layer normalization with shape (hidden_size)
+
beta_quant : T2
+
1D beta tensor for layer normalization with shape (hidden_size)
+
mask (optional) : T1
+
Mask
+
word_embedding_scale : T
+
Scale for word embeddings
+
position_embedding_scale : T
+
Scale for position embeddings
+
segment_embedding_scale (optional) : T
+
Scale for segment embeddings
+
gamma_scale : T
+
Scale for 1D gamma tensor
+
beta_scale : T
+
Scale for 1D beta tensor
+
word_embedding_zero_point : T2
+
Zero point for word embeddings
+
position_embedding_zero_point : T2
+
Zero point for position embeddings
+
segment_embedding_zero_point (optional) : T2
+
Zero Point for segment embeddings
+
gamma_zero_point : T2
+
Zero Point for 1D gamma tensor
+
beta_zero_point : T2
+
Zero Point for 1D beta tensor
+
+ +#### Outputs + +
+
layernorm_out : T
+
LayerNorm Output
+
mask_index_out : T1
+
Mask Index Output
+
+ +#### Type Constraints + +
+
T1 : tensor(int32)
+
Constrain mask index to integer types
+
T2 : tensor(int8), tensor(uint8)
+
Constrain input and output types to int8 tensors.
+
T : tensor(float)
+
Constrain input and output types to float32 tensors.
+
+ + diff --git a/_doc/sphinxdoc/source/onnxmd/onnxruntime_docs/FAQ.md b/_doc/sphinxdoc/source/onnxmd/onnxruntime_docs/FAQ.md new file mode 100644 index 00000000..c14fd766 --- /dev/null +++ b/_doc/sphinxdoc/source/onnxmd/onnxruntime_docs/FAQ.md @@ -0,0 +1,68 @@ +# FAQ +Here are some commonly raised questions from users of ONNX Runtime and brought up in [Issues](https://github.com/microsoft/onnxruntime/issues). + +## Do the GPU builds support quantized models? +The default CUDA build supports 3 standard quantization operators: QuantizeLinear, DequantizeLinear, and MatMulInteger. The TensorRT EP has limited support for INT8 quantized ops. In general, support of quantized models through ORT is continuing to expand on a model-driven basis. For performance improvements, quantization is not always required, and we suggest trying alternative strategies to [performance tune](./ONNX_Runtime_Perf_Tuning.md) before determining that quantization is necessary. + +## How do I change the severity level of the default logger to something other than the default (WARNING)? +Setting the severity level to VERBOSE is most useful when debugging errors. + +Refer to the API documentation: +* Python - [RunOptions.log_severity_level](https://microsoft.github.io/onnxruntime/python/api_summary.html#onnxruntime.RunOptions.log_severity_level) +``` +import onnxruntime as ort +ort.set_default_logger_severity(0) +``` +* C - [SetSessionLogSeverityLevel](./../include/onnxruntime/core/session/onnxruntime_c_api.h) + +## How do I load and run models that have multiple inputs and outputs using the C/C++ API? +See an example from the 'override initializer' test in [test_inference.cc](./../onnxruntime/test/shared_lib/test_inference.cc) that has 3 inputs and 3 outputs. +``` +std::vector ort_inputs; +ort_inputs.push_back(std::move(label_input_tensor)); +ort_inputs.push_back(std::move(f2_input_tensor)); +ort_inputs.push_back(std::move(f11_input_tensor)); +std::vector input_names = {"Label", "F2", "F1"}; +const char* const output_names[] = {"Label0", "F20", "F11"}; +std::vector ort_outputs = session.Run(Ort::RunOptions{nullptr}, input_names.data(), +ort_inputs.data(), ort_inputs.size(), output_names, countof(output_names)); +``` + +## How do I force single threaded execution mode in ORT? By default, session.run() uses all the computer's cores. + +To limit use to a single thread only: +* If built with OpenMP, set the environment variable OMP_NUM_THREADS to 1. The default inter_op_num_threads in session options is already 1. +* If not built with OpenMP, set the session options intra_op_num_threads to 1. Do not change the default inter_op_num_threads (1). + +It's recommended to build onnxruntime without openmp if you only need single threaded execution. + +This is supported in ONNX Runtime v1.3.0+ + +**Python example:** +``` +#!/usr/bin/python3 +os.environ["OMP_NUM_THREADS"] = "1" +import onnxruntime + +opts = onnxruntime.SessionOptions() +opts.inter_op_num_threads = 1 +opts.execution_mode = onnxruntime.ExecutionMode.ORT_SEQUENTIAL +ort_session = onnxruntime.InferenceSession('/path/to/model.onnx', sess_options=opts) +``` + +**C++ example:** +``` +// initialize enviroment...one enviroment per process +Ort::Env env(ORT_LOGGING_LEVEL_WARNING, "test"); + +// initialize session options if needed +Ort::SessionOptions session_options; +session_options.SetInterOpNumThreads(1); +#ifdef _WIN32 + const wchar_t* model_path = L"squeezenet.onnx"; +#else + const char* model_path = "squeezenet.onnx"; +#endif + +Ort::Session session(env, model_path, session_options); +``` diff --git a/_doc/sphinxdoc/source/onnxmd/onnxruntime_docs/How_To_Update_ONNX_Dev_Notes.md b/_doc/sphinxdoc/source/onnxmd/onnxruntime_docs/How_To_Update_ONNX_Dev_Notes.md new file mode 100644 index 00000000..27f97d17 --- /dev/null +++ b/_doc/sphinxdoc/source/onnxmd/onnxruntime_docs/How_To_Update_ONNX_Dev_Notes.md @@ -0,0 +1,36 @@ +This is a note only for ONNX Runtime developers. + +It's very often, you need to update the ONNX submodule to a newer version in the upstream. Please follow the steps below, don't miss any! + +1. Update the ONNX subfolder +``` +cd cmake/external/onnx +git remote update +git reset --hard +cd .. +git add onnx +``` +(Change the to yours. If you are not sure, use 'origin/master'. Like 'git reset --hard origin/master') + +2. Update [cgmanifests/submodules/cgmanifest.json](/cgmanifests/submodules/cgmanifest.json). +This file should be generated. See [cgmanifests/README](/cgmanifests/README.md) for instructions. + +3. Update [tools/ci_build/github/linux/docker/scripts/install_onnx.sh](/tools/ci_build/github/linux/docker/scripts/install_onnx.sh). +Search 'for version2tag', update the commit hashes. The list should contain every release version from ONNX 1.2, and the latest one in our cmake/external/onnx folder. + +4. If there is any change to `cmake/external/onnx/onnx/*.in.proto`, you need to re-regenerate OnnxMl.cs. Please build onnxruntime on Windows with csharp enabled, then the file will be auto-updated. + +6. If you are updating ONNX from a released tag to a new commit, please tell Changming deploying the new test data along with other test models to our CI build machines. This is to ensure that our tests cover every ONNX opset. + +5. Send you PR, and **manually** queue a build for every packaging pipeline for your branch. + +6. If there is a build failure in stage "Check out of dated documents" in WebAssembly CI pipeline, update ONNX Runtime Web WebGL operator support document: + - Make sure Node.js is installed (see [Prerequisites](../js/README.md#Prerequisites) for instructions). + - Follow step 1 in [js/Build](../js/README.md#Build-2) to install dependencies). + - Follow instructions in [Generate document](../js/README.md#Generating-Document) to update document. Commit changes applied to file `docs/operators.md`. + +7. Usually there would be some unitest failures, because you introduced new test cases. Then you may need to update +- [onnxruntime/test/onnx/main.cc](/onnxruntime/test/onnx/main.cc) +- [onnxruntime/test/providers/cpu/model_tests.cc](/onnxruntime/test/providers/cpu/model_tests.cc) +- [csharp/test/Microsoft.ML.OnnxRuntime.Tests/InferenceTest.cs](/csharp/test/Microsoft.ML.OnnxRuntime.Tests/InferenceTest.cs) +- [onnxruntime/test/testdata/onnx_backend_test_series_filters.jsonc](/onnxruntime/test/testdata/onnx_backend_test_series_filters.jsonc) diff --git a/_doc/sphinxdoc/source/onnxmd/onnxruntime_docs/Model_Test.md b/_doc/sphinxdoc/source/onnxmd/onnxruntime_docs/Model_Test.md new file mode 100644 index 00000000..960900d1 --- /dev/null +++ b/_doc/sphinxdoc/source/onnxmd/onnxruntime_docs/Model_Test.md @@ -0,0 +1,47 @@ +ONNX has a collection of standard tests. This document describes how to run these tests through a C++ program named 'onnx_test_runner' in this repo. You could also run these test through onnxruntime python binding, which would be much easier to setup, but, a bit harder to debug issues. + +# Get the test data +You should have: +1. onnx single node test data +2. onnx model zoo models + +## Install onnx python package +You can get onnx python package from [pypi](https://pypi.org/). However, if you are a onnxruntime developer, you may need to work on a cutting edge ONNX version. In this case, you need to build and install ONNX from source code. + +### Install ONNX from source code +1. (windows) set ONNX_ML=1 + (linux) export ONNX_ML=1 +2. Install protobuf and put protoc into your PATH environment. When you compile protobuf, it's better to only enable the static libraries. +3. run "python setup.py bdist_wheel" and "pip install dist/*.whl" + +## Generate node test data +$ python3 -m onnx.backend.test.cmd_tools generate-data -o +e.g. + python3 -m onnx.backend.test.cmd_tools generate-data -o C:\testdata + + +## Get more models +Download https://onnxruntimetestdata.blob.core.windows.net/models/20190419.zip and unzip it. + + +# Compile onnx_test_runner and run the tests +onnx_test_runner is a C++ program. Its source code is in onnxruntime/test/onnx directory. + +Usage: onnx_test_runner [options...] +Options: + -j [models]: Specifies the number of models to run simultaneously. + -A : Disable memory arena + -c [runs]: Specifies the number of Session::Run() to invoke simultaneously for each model. + -r [repeat]: Specifies the number of times to repeat + -v: verbose + -n [test_case_name]: Specifies a single test case to run. + -e [EXECUTION_PROVIDER]: EXECUTION_PROVIDER could be 'cpu', 'cuda', 'dnnl' or 'tensorrt'. Default: 'cpu'. + -x: Use parallel executor, default (without -x): sequential executor. + -h: help + +e.g. +//run the tests under C:\testdata dir and enable CUDA provider +$ onnx_test_runner -e cuda C:\testdata + +//run the tests sequentially. It would be easier to debug +$ onnx_test_runner -c 1 -j 1 C:\testdata diff --git a/_doc/sphinxdoc/source/onnxmd/onnxruntime_docs/NotesOnThreading.md b/_doc/sphinxdoc/source/onnxmd/onnxruntime_docs/NotesOnThreading.md new file mode 100644 index 00000000..25f504c0 --- /dev/null +++ b/_doc/sphinxdoc/source/onnxmd/onnxruntime_docs/NotesOnThreading.md @@ -0,0 +1,27 @@ +# Notes on Threading in ORT + +This document is intended for ORT developers. + +ORT allows the usage of either OpenMP or non-OpenMP (ORT) threads for execution. Threadpool management +is abstracted behind: (1) ThreadPool class in [threadpool.h](https://github.com/microsoft/onnxruntime/blob/master/include/onnxruntime/core/platform/threadpool.h) and (2) functions in [thread_utils.h](https://github.com/microsoft/onnxruntime/blob/master/onnxruntime/core/util/thread_utils.h). + +When developing an op, please use these abstractions to parallelize your code. These abstractions centralize 2 things. +When OpenMP is enabled, they resort to using OpenMP. When OpenMP is disabled they resort to sequential execution if the threadpool ptr is NULL or schedule the tasks on the threadpool otherwise. + +Examples of these abstractions are: ([threadpool.h](https://github.com/microsoft/onnxruntime/blob/master/include/onnxruntime/core/platform/threadpool.h) has more documentation for these) +* TryParallelFor +* TrySimpleParallelFor +* TryBatchParallelFor +* ShouldParallelize +* DegreeOfParallelism + +These static methods abstract over the different implementation choices. They can run over the ORT thread pool, or run over OpenMP, or run sequentially. + +In addition, ThreadPool::ParallelSection allows a series of loops to +be grouped together in a single parallel section. This allows an +operator to amortize loop entry/exit costs in cases where it is +impractical to refactor code into a single large loop. + +**Please do not write #ifdef pragma omp in operator code**. + +For intra op parallelism ORT users can use either OpenMP or ORT threadpool. The choice of using OpenMP is indicated by building ORT with ```--use_openmp``` switch. For inter op parallelism, however, we always use the ORT threadpool. diff --git a/_doc/sphinxdoc/source/onnxmd/onnxruntime_docs/ONNX_Runtime_Server_Usage.md b/_doc/sphinxdoc/source/onnxmd/onnxruntime_docs/ONNX_Runtime_Server_Usage.md new file mode 100644 index 00000000..a07b506b --- /dev/null +++ b/_doc/sphinxdoc/source/onnxmd/onnxruntime_docs/ONNX_Runtime_Server_Usage.md @@ -0,0 +1,109 @@ +

Note: ONNX Runtime Server has been deprecated.

+ +# How to Use build ONNX Runtime Server for Prediction +ONNX Runtime Server provides an easy way to start an inferencing server for prediction with both HTTP and GRPC endpoints. + +The CLI command to build the server is + +Default CPU: +``` +python3 /onnxruntime/tools/ci_build/build.py --build_dir /onnxruntime/build --config Release --build_server --parallel --cmake_extra_defines ONNXRUNTIME_VERSION=$(cat ./VERSION_NUMBER +``` + +# How to Use ONNX Runtime Server for Prediction + + The CLI command to start the server is shown below: + +``` +$ ./onnxruntime_server +Version: +Commit ID: + +the option '--model_path' is required but missing +Allowed options: + -h [ --help ] Shows a help message and exits + --log_level arg (=info) Logging level. Allowed options (case sensitive): + verbose, info, warning, error, fatal + --model_path arg Path to ONNX model + --address arg (=0.0.0.0) The base HTTP address + --http_port arg (=8001) HTTP port to listen to requests + --num_http_threads arg (=<# of your cpu cores>) Number of http threads + --grpc_port arg (=50051) GRPC port to listen to requests +``` + +**Note**: The only mandatory argument for the program here is `model_path` + +## Start the Server + +To host an ONNX model as an inferencing server, simply run: + +``` +./onnxruntime_server --model_path /// +``` + +## HTTP Endpoint + +The prediction URL for HTTP endpoint is in this format: + +``` +http://:/v1/models//versions/:predict +``` + +**Note**: Since we currently only support one model, the model name and version can be any string length > 0. In the future, model_names and versions will be verified. + +### Request and Response Payload + +The request and response need to be a protobuf message. The Protobuf definition can be found [here](../server/protobuf/predict.proto). + +A protobuf message could have two formats: binary and JSON. Usually the binary payload has better latency, in the meanwhile the JSON format is easy for human readability. + +The HTTP request header field `Content-Type` tells the server how to handle the request and thus it is mandatory for all requests. Requests missing `Content-Type` will be rejected as `400 Bad Request`. + +* For `"Content-Type: application/json"`, the payload will be deserialized as JSON string in UTF-8 format +* For `"Content-Type: application/vnd.google.protobuf"`, `"Content-Type: application/x-protobuf"` or `"Content-Type: application/octet-stream"`, the payload will be consumed as protobuf message directly. + +Clients can control the response type by setting the request with an `Accept` header field and the server will serialize in your desired format. The choices currently available are the same as the `Content-Type` header field. If this field is not set in the request, the server will use the same type as your request. + +### Inferencing + +To send a request to the server, you can use any tool which supports making HTTP requests. Here is an example using `curl`: + +``` +curl -X POST -d "@predict_request_0.json" -H "Content-Type: application/json" http://127.0.0.1:8001/v1/models/mymodel/versions/3:predict +``` + +or + +``` +curl -X POST --data-binary "@predict_request_0.pb" -H "Content-Type: application/octet-stream" -H "Foo: 1234" http://127.0.0.1:8001/v1/models/mymodel/versions/3:predict +``` + +### Interactive tutorial notebook + +A simple Jupyter notebook demonstrating the usage of ONNX Runtime server to host an ONNX model and perform inferencing can be found [here](https://github.com/onnx/tutorials/blob/master/tutorials/OnnxRuntimeServerSSDModel.ipynb). + +## GRPC Endpoint + +If you prefer using the GRPC endpoint, the protobuf could be found [here](../server/protobuf/prediction_service.proto). You could generate your client and make a GRPC call to it. To learn more about how to generate the client code and call to the server, please refer to [the tutorials of GRPC](https://grpc.io/docs/tutorials/). + +## Advanced Topics + +### Number of Worker Threads + +You can change this to optimize server utilization. The default is the number of CPU cores on the host machine. + +### Request ID and Client Request ID + +For easy tracking of requests, we provide the following header fields: + +* `x-ms-request-id`: will be in the response header, no matter the request result. It will be a GUID/uuid with dash, e.g. `72b68108-18a4-493c-ac75-d0abd82f0a11`. If the request headers contain this field, the value will be ignored. +* `x-ms-client-request-id`: a field for clients to tracking their requests. The content will persist in the response headers. + +### rsyslog Support + +If you prefer using an ONNX Runtime Server with [rsyslog](https://www.rsyslog.com/) support([build instruction](https://www.onnxruntime.ai/docs/how-to/build.html#build-onnx-runtime-server-on-linux)), you should be able to see the log in `/var/log/syslog` after the ONNX Runtime Server runs. For detail about how to use rsyslog, please reference [here](https://www.rsyslog.com/category/guides-for-rsyslog/). + +## Report Issues + +If you see any issues or want to ask questions about the server, please feel free to do so in this repo with the version and commit id from the command line. + diff --git a/_doc/sphinxdoc/source/onnxmd/onnxruntime_docs/ORTMobilePackageOperatorTypeSupport.md b/_doc/sphinxdoc/source/onnxmd/onnxruntime_docs/ORTMobilePackageOperatorTypeSupport.md new file mode 100644 index 00000000..7e08e068 --- /dev/null +++ b/_doc/sphinxdoc/source/onnxmd/onnxruntime_docs/ORTMobilePackageOperatorTypeSupport.md @@ -0,0 +1,127 @@ +# ONNX Runtime Mobile Pre-Built Package Operator and Type Support + +## Supported operators and types + +The supported operators and types are based on what is required to support float32 and quantized versions of popular models. The full list of input models used to determine this list is available [here](https://github.com/microsoft/onnxruntime/blob/master/tools/ci_build/github/android/mobile_package.required_operators.readme.txt) + +## Supported data input types + + - float + - int8_t + - uint8_t + +NOTE: Operators used to manipulate dimensions and indices will support int32 and int64. + +## Supported Operators + +|Operator|Opsets| +|--------|------| +|**ai.onnx**|| +|ai.onnx:Abs|12, 13| +|ai.onnx:Add|12, 13| +|ai.onnx:And|12, 13| +|ai.onnx:ArgMax|12, 13| +|ai.onnx:ArgMin|12, 13| +|ai.onnx:AveragePool|12, 13| +|ai.onnx:Cast|12, 13| +|ai.onnx:Ceil|12, 13| +|ai.onnx:Clip|12, 13| +|ai.onnx:Concat|12, 13| +|ai.onnx:ConstantOfShape|12, 13| +|ai.onnx:Conv|12, 13| +|ai.onnx:ConvTranspose|12, 13| +|ai.onnx:Cos|12, 13| +|ai.onnx:CumSum|12, 13| +|ai.onnx:DepthToSpace|12, 13| +|ai.onnx:DequantizeLinear|12, 13| +|ai.onnx:Div|12, 13| +|ai.onnx:DynamicQuantizeLinear|12, 13| +|ai.onnx:Elu|12, 13| +|ai.onnx:Equal|12, 13| +|ai.onnx:Exp|12, 13| +|ai.onnx:Expand|12, 13| +|ai.onnx:Flatten|12, 13| +|ai.onnx:Floor|12, 13| +|ai.onnx:Gather|12, 13| +|ai.onnx:GatherND|12, 13| +|ai.onnx:Gemm|12, 13| +|ai.onnx:GlobalAveragePool|12, 13| +|ai.onnx:Greater|12, 13| +|ai.onnx:GreaterOrEqual|12, 13| +|ai.onnx:Identity|12, 13| +|ai.onnx:If|12, 13| +|ai.onnx:LRN|12, 13| +|ai.onnx:LeakyRelu|12, 13| +|ai.onnx:Less|12, 13| +|ai.onnx:LessOrEqual|12, 13| +|ai.onnx:Log|12, 13| +|ai.onnx:LogSoftmax|12, 13| +|ai.onnx:Loop|12, 13| +|ai.onnx:MatMul|12, 13| +|ai.onnx:MatMulInteger|12, 13| +|ai.onnx:Max|12, 13| +|ai.onnx:MaxPool|12, 13| +|ai.onnx:Mean|12, 13| +|ai.onnx:Min|12, 13| +|ai.onnx:Mul|12, 13| +|ai.onnx:Neg|12, 13| +|ai.onnx:NonMaxSuppression|12, 13| +|ai.onnx:NonZero|12, 13| +|ai.onnx:Not|12, 13| +|ai.onnx:Or|12, 13| +|ai.onnx:PRelu|12, 13| +|ai.onnx:Pad|12, 13| +|ai.onnx:Pow|12, 13| +|ai.onnx:QLinearConv|12, 13| +|ai.onnx:QLinearMatMul|12, 13| +|ai.onnx:QuantizeLinear|12, 13| +|ai.onnx:Range|12, 13| +|ai.onnx:Reciprocal|12, 13| +|ai.onnx:ReduceMax|12, 13| +|ai.onnx:ReduceMean|12, 13| +|ai.onnx:ReduceMin|12, 13| +|ai.onnx:ReduceProd|12, 13| +|ai.onnx:ReduceSum|12, 13| +|ai.onnx:Relu|12, 13| +|ai.onnx:Reshape|12, 13| +|ai.onnx:Resize|12, 13| +|ai.onnx:ReverseSequence|12, 13| +|ai.onnx:Round|12, 13| +|ai.onnx:Scan|12, 13| +|ai.onnx:ScatterND|12, 13| +|ai.onnx:Shape|12, 13| +|ai.onnx:Sigmoid|12, 13| +|ai.onnx:Sin|12, 13| +|ai.onnx:Size|12, 13| +|ai.onnx:Slice|12, 13| +|ai.onnx:Softmax|12, 13| +|ai.onnx:SpaceToDepth|12, 13| +|ai.onnx:Split|12, 13| +|ai.onnx:Sqrt|12, 13| +|ai.onnx:Squeeze|12, 13| +|ai.onnx:Sub|12, 13| +|ai.onnx:Sum|12, 13| +|ai.onnx:Tanh|12, 13| +|ai.onnx:ThresholdedRelu|12, 13| +|ai.onnx:Tile|12, 13| +|ai.onnx:TopK|12, 13| +|ai.onnx:Transpose|12, 13| +|ai.onnx:Unique|12, 13| +|ai.onnx:Unsqueeze|12, 13| +|ai.onnx:Where|12, 13| +||| +|**com.microsoft**|| +|com.microsoft:DynamicQuantizeMatMul|1| +|com.microsoft:FusedConv|1| +|com.microsoft:FusedGemm|1| +|com.microsoft:FusedMatMul|1| +|com.microsoft:MatMulIntegerToFloat|1| +|com.microsoft:NhwcMaxPool|1| +|com.microsoft:QLinearAdd|1| +|com.microsoft:QLinearAveragePool|1| +|com.microsoft:QLinearConv|1| +|com.microsoft:QLinearGlobalAveragePool|1| +|com.microsoft:QLinearLeakyRelu|1| +|com.microsoft:QLinearMul|1| +|com.microsoft:QLinearSigmoid|1| +||| diff --git a/_doc/sphinxdoc/source/onnxmd/onnxruntime_docs/OperatorKernels.md b/_doc/sphinxdoc/source/onnxmd/onnxruntime_docs/OperatorKernels.md new file mode 100644 index 00000000..a7ea7131 --- /dev/null +++ b/_doc/sphinxdoc/source/onnxmd/onnxruntime_docs/OperatorKernels.md @@ -0,0 +1,755 @@ +## Supported Operators and Data Types +*This file is automatically generated from the registered kernels by [this script](https://github.com/microsoft/onnxruntime/blob/master/tools/python/gen_opkernel_doc.py). +Do not modify directly.* + +## Execution Providers + +- [CPUExecutionProvider](#cpuexecutionprovider) +- [CUDAExecutionProvider](#cudaexecutionprovider) + +--------------- + + + +## Operators implemented by CPUExecutionProvider + +| Op Name | Parameters | OpSet Version | Types Supported | +|---------|------------|---------------|-----------------| +|**Operator Domain:** *ai.onnx*|||| +|Abs|*in* X:**T**
*out* Y:**T**|13+|**T** = tensor(double), tensor(float), tensor(int16), tensor(int32), tensor(int64), tensor(int8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(uint8)| +|||[6, 12]|**T** = tensor(double), tensor(float), tensor(int16), tensor(int32), tensor(int64), tensor(int8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(uint8)| +|Acos|*in* input:**T**
*out* output:**T**|7+|**T** = tensor(float)| +|Acosh|*in* input:**T**
*out* output:**T**|9+|**T** = tensor(float)| +|Add|*in* A:**T**
*in* B:**T**
*out* C:**T**|14+|**T** = tensor(double), tensor(float), tensor(int32), tensor(int64)| +|||13|**T** = tensor(double), tensor(float), tensor(int32), tensor(int64)| +|||[7, 12]|**T** = tensor(double), tensor(float), tensor(int32), tensor(int64)| +|Affine|*in* X:**T**
*out* Y:**T**|1+|**T** = tensor(float)| +|And|*in* A:**T**
*in* B:**T**
*out* C:**T1**|7+|**T** = tensor(bool)
**T1** = tensor(bool)| +|ArgMax|*in* data:**T**
*out* reduced:**tensor(int64)**|13+|**T** = tensor(double), tensor(float), tensor(int32)| +|||[11, 12]|**T** = tensor(double), tensor(float), tensor(int32)| +|||[1, 10]|**T** = tensor(float), tensor(int32)| +|ArgMin|*in* data:**T**
*out* reduced:**tensor(int64)**|13+|**T** = tensor(double), tensor(float), tensor(int32)| +|||[11, 12]|**T** = tensor(double), tensor(float), tensor(int32)| +|||[1, 10]|**T** = tensor(float), tensor(int32)| +|Asin|*in* input:**T**
*out* output:**T**|7+|**T** = tensor(float)| +|Asinh|*in* input:**T**
*out* output:**T**|9+|**T** = tensor(float)| +|Atan|*in* input:**T**
*out* output:**T**|7+|**T** = tensor(float)| +|Atanh|*in* input:**T**
*out* output:**T**|9+|**T** = tensor(float)| +|AveragePool|*in* X:**T**
*out* Y:**T**|11+|**T** = tensor(float)| +|||10|**T** = tensor(float)| +|||[7, 9]|**T** = tensor(float)| +|BatchNormalization|*in* X:**T**
*in* scale:**T**
*in* B:**T**
*in* input_mean:**U**
*in* input_var:**U**
*out* Y:**T**
*out* running_mean:**U**
*out* running_var:**U**

or

*in* X:**T**
*in* scale:**T**
*in* B:**T**
*in* mean:**T**
*in* var:**T**
*out* Y:**T**
*out* mean:**T**
*out* var:**T**
*out* saved_mean:**T**
*out* saved_var:**T**

or

*in* X:**T**
*in* scale:**T1**
*in* B:**T1**
*in* input_mean:**T2**
*in* input_var:**T2**
*out* Y:**T**
*out* running_mean:**T2**
*out* running_var:**T2**|15+|**T** = tensor(double), tensor(float)
**T1** = tensor(double), tensor(float)
**T2** = tensor(double), tensor(float)| +|||14|**T** = tensor(double), tensor(float)
**U** = tensor(double), tensor(float)| +|||[9, 13]|**T** = tensor(double), tensor(float)| +|||[7, 8]|**T** = tensor(double), tensor(float)| +|BitShift|*in* X:**T**
*in* Y:**T**
*out* Z:**T**|11+|**T** = tensor(uint32), tensor(uint64), tensor(uint8)| +|Cast|*in* input:**T1**
*out* output:**T2**|13+|**T1** = tensor(bfloat16), tensor(bool), tensor(double), tensor(float), tensor(float16), tensor(int16), tensor(int32), tensor(int64), tensor(int8), tensor(string), tensor(uint16), tensor(uint32), tensor(uint64), tensor(uint8)
**T2** = tensor(bfloat16), tensor(bool), tensor(double), tensor(float), tensor(float16), tensor(int16), tensor(int32), tensor(int64), tensor(int8), tensor(string), tensor(uint16), tensor(uint32), tensor(uint64), tensor(uint8)| +|||[6, 12]|**T1** = tensor(bfloat16), tensor(bool), tensor(double), tensor(float), tensor(float16), tensor(int16), tensor(int32), tensor(int64), tensor(int8), tensor(string), tensor(uint16), tensor(uint32), tensor(uint64), tensor(uint8)
**T2** = tensor(bfloat16), tensor(bool), tensor(double), tensor(float), tensor(float16), tensor(int16), tensor(int32), tensor(int64), tensor(int8), tensor(string), tensor(uint16), tensor(uint32), tensor(uint64), tensor(uint8)| +|Ceil|*in* X:**T**
*out* Y:**T**|13+|**T** = tensor(float)| +|||[6, 12]|**T** = tensor(float)| +|Celu|*in* X:**T**
*out* Y:**T**|12+|**T** = tensor(float)| +|Clip|*in* input:**T**
*in* min:**T**
*in* max:**T**
*out* output:**T**

or

*in* input:**T**
*out* output:**T**|13+|**T** = tensor(double), tensor(float), tensor(int64), tensor(int8), tensor(uint64), tensor(uint8)| +|||12|**T** = tensor(double), tensor(float), tensor(int64), tensor(int8), tensor(uint64), tensor(uint8)| +|||11|**T** = tensor(float)| +|||[6, 10]|**T** = tensor(float)| +|Compress|*in* input:**T**
*in* condition:**T1**
*out* output:**T**|11+|**T** = tensor(bfloat16), tensor(bool), tensor(double), tensor(float), tensor(float16), tensor(int16), tensor(int32), tensor(int64), tensor(int8), tensor(string), tensor(uint16), tensor(uint32), tensor(uint64), tensor(uint8)
**T1** = tensor(bool)| +|||[9, 10]|**T** = tensor(bfloat16), tensor(bool), tensor(double), tensor(float), tensor(float16), tensor(int16), tensor(int32), tensor(int64), tensor(int8), tensor(string), tensor(uint16), tensor(uint32), tensor(uint64), tensor(uint8)
**T1** = tensor(bool)| +|Concat|*in* inputs:**T**
*out* concat_result:**T**|13+|**T** = tensor(bfloat16), tensor(bool), tensor(double), tensor(float), tensor(float16), tensor(int16), tensor(int32), tensor(int64), tensor(int8), tensor(string), tensor(uint16), tensor(uint32), tensor(uint64), tensor(uint8)| +|||[11, 12]|**T** = tensor(bfloat16), tensor(bool), tensor(double), tensor(float), tensor(float16), tensor(int16), tensor(int32), tensor(int64), tensor(int8), tensor(string), tensor(uint16), tensor(uint32), tensor(uint64), tensor(uint8)| +|||[4, 10]|**T** = tensor(bfloat16), tensor(bool), tensor(double), tensor(float), tensor(float16), tensor(int16), tensor(int32), tensor(int64), tensor(int8), tensor(string), tensor(uint16), tensor(uint32), tensor(uint64), tensor(uint8)| +|ConcatFromSequence|*in* input_sequence:**S**
*out* concat_result:**T**|11+|**S** = seq(tensor(bfloat16)), seq(tensor(bool)), seq(tensor(double)), seq(tensor(float)), seq(tensor(float16)), seq(tensor(int16)), seq(tensor(int32)), seq(tensor(int64)), seq(tensor(int8)), seq(tensor(string)), seq(tensor(uint16)), seq(tensor(uint32)), seq(tensor(uint64)), seq(tensor(uint8))| +|ConstantOfShape|*in* input:**T1**
*out* output:**T2**|9+|**T1** = tensor(int64)
**T2** = tensor(bool), tensor(double), tensor(float), tensor(float16), tensor(int16), tensor(int32), tensor(int64), tensor(int8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(uint8)| +|Conv|*in* X:**T**
*in* W:**T**
*in* B:**T**
*out* Y:**T**|11+|**T** = tensor(float)| +|||[1, 10]|**T** = tensor(float)| +|ConvInteger|*in* x:**T1**
*in* w:**T2**
*in* x_zero_point:**T1**
*in* w_zero_point:**T2**
*out* y:**T3**|10+|**T1** = tensor(uint8)
**T2** = tensor(uint8)
**T3** = tensor(int32)| +|ConvTranspose|*in* X:**T**
*in* W:**T**
*in* B:**T**
*out* Y:**T**|11+|**T** = tensor(float)| +|||[1, 10]|**T** = tensor(float)| +|Cos|*in* input:**T**
*out* output:**T**|7+|**T** = tensor(float)| +|Cosh|*in* input:**T**
*out* output:**T**|9+|**T** = tensor(float)| +|Crop|*in* input:**T**
*out* output:**T**|1+|**T** = tensor(float)| +|CumSum|*in* x:**T**
*in* axis:**T2**
*out* y:**T**|14+|**T** = tensor(double), tensor(float), tensor(int32), tensor(int64)
**T2** = tensor(int32), tensor(int64)| +|||[11, 13]|**T** = tensor(double), tensor(float), tensor(int32), tensor(int64)
**T2** = tensor(int32), tensor(int64)| +|DepthToSpace|*in* input:**T**
*out* output:**T**|13+|**T** = tensor(double), tensor(float)| +|||[11, 12]|**T** = tensor(double), tensor(float)| +|||[1, 10]|**T** = tensor(double), tensor(float)| +|DequantizeLinear|*in* x:**T**
*in* x_scale:**tensor(float)**
*in* x_zero_point:**T**
*out* y:**tensor(float)**|13+|**T** = tensor(int32), tensor(int8), tensor(uint8)| +|||[10, 12]|**T** = tensor(int32), tensor(int8), tensor(uint8)| +|Det|*in* X:**T**
*out* Y:**T**|11+|**T** = tensor(float)| +|Div|*in* A:**T**
*in* B:**T**
*out* C:**T**|14+|**T** = tensor(double), tensor(float), tensor(int32), tensor(int64)| +|||13|**T** = tensor(double), tensor(float), tensor(int32), tensor(int64)| +|||[7, 12]|**T** = tensor(double), tensor(float), tensor(int32), tensor(int64)| +|Dropout|*in* data:**T**
*in* ratio:**T1**
*in* training_mode:**T2**
*out* output:**T**
*out* mask:**T2**

or

*in* data:**T**
*out* output:**T**
*out* mask:**T**

or

*in* data:**T**
*out* output:**T**
*out* mask:**T1**|13+|**T** = tensor(double), tensor(float)
**T1** = tensor(double), tensor(float)
**T2** = tensor(bool)| +|||12|**T** = tensor(double), tensor(float)
**T1** = tensor(double), tensor(float)
**T2** = tensor(bool)| +|||[10, 11]|**T** = tensor(double), tensor(float), tensor(float16)
**T1** = tensor(bool)| +|||[7, 9]|**T** = tensor(double), tensor(float), tensor(float16)
**T1** = tensor(bool)| +|DynamicQuantizeLinear|*in* x:**T1**
*out* y:**T2**
*out* y_scale:**tensor(float)**
*out* y_zero_point:**T2**|11+|**T2** = tensor(uint8)| +|DynamicSlice|*in* data:**T**
*in* starts:**Tind**
*in* ends:**Tind**
*in* axes:**Tind**
*out* output:**T**|1+|**T** = tensor(bfloat16), tensor(bool), tensor(double), tensor(float), tensor(float16), tensor(int16), tensor(int32), tensor(int64), tensor(int8), tensor(string), tensor(uint16), tensor(uint32), tensor(uint64), tensor(uint8)
**Tind** = tensor(int32), tensor(int64)| +|Einsum|*in* Inputs:**T**
*out* Output:**T**|12+|**T** = tensor(double), tensor(float), tensor(int32), tensor(int64)| +|Elu|*in* X:**T**
*out* Y:**T**|6+|**T** = tensor(float)| +|Equal|*in* A:**T**
*in* B:**T**
*out* C:**T1**|13+|**T** = tensor(bool), tensor(double), tensor(float), tensor(int32), tensor(int64)
**T1** = tensor(bool)| +|||[11, 12]|**T** = tensor(bool), tensor(double), tensor(float), tensor(int32), tensor(int64)
**T1** = tensor(bool)| +|||[7, 10]|**T** = tensor(bool), tensor(double), tensor(float), tensor(int32), tensor(int64)
**T1** = tensor(bool)| +|Erf|*in* input:**T**
*out* output:**T**|13+|**T** = tensor(float)| +|||[9, 12]|**T** = tensor(float)| +|Exp|*in* input:**T**
*out* output:**T**|13+|**T** = tensor(double), tensor(float)| +|||[6, 12]|**T** = tensor(double), tensor(float)| +|Expand|*in* input:**T**
*in* shape:**tensor(int64)**
*out* output:**T**|13+|**T** = tensor(bool), tensor(double), tensor(float), tensor(float16), tensor(int16), tensor(int32), tensor(int64), tensor(int8), tensor(string), tensor(uint16), tensor(uint32), tensor(uint64), tensor(uint8)| +|||[8, 12]|**T** = tensor(bool), tensor(double), tensor(float), tensor(float16), tensor(int16), tensor(int32), tensor(int64), tensor(int8), tensor(string), tensor(uint16), tensor(uint32), tensor(uint64), tensor(uint8)| +|EyeLike|*in* input:**T1**
*out* output:**T2**|9+|**T1** = tensor(double), tensor(float), tensor(int32), tensor(int64), tensor(uint64)
**T2** = tensor(double), tensor(float), tensor(int32), tensor(int64), tensor(uint64)| +|Flatten|*in* input:**T**
*out* output:**T**|13+|**T** = tensor(bfloat16), tensor(bool), tensor(double), tensor(float), tensor(float16), tensor(int16), tensor(int32), tensor(int64), tensor(int8), tensor(string), tensor(uint16), tensor(uint32), tensor(uint64), tensor(uint8)| +|||[11, 12]|**T** = tensor(bfloat16), tensor(bool), tensor(double), tensor(float), tensor(float16), tensor(int16), tensor(int32), tensor(int64), tensor(int8), tensor(string), tensor(uint16), tensor(uint32), tensor(uint64), tensor(uint8)| +|||[9, 10]|**T** = tensor(bfloat16), tensor(bool), tensor(double), tensor(float), tensor(float16), tensor(int16), tensor(int32), tensor(int64), tensor(int8), tensor(string), tensor(uint16), tensor(uint32), tensor(uint64), tensor(uint8)| +|||[1, 8]|**T** = tensor(bfloat16), tensor(bool), tensor(double), tensor(float), tensor(float16), tensor(int16), tensor(int32), tensor(int64), tensor(int8), tensor(string), tensor(uint16), tensor(uint32), tensor(uint64), tensor(uint8)| +|Floor|*in* X:**T**
*out* Y:**T**|13+|**T** = tensor(float)| +|||[6, 12]|**T** = tensor(float)| +|GRU|*in* X:**T**
*in* W:**T**
*in* R:**T**
*in* B:**T**
*in* sequence_lens:**T1**
*in* initial_h:**T**
*out* Y:**T**
*out* Y_h:**T**|14+|**T** = tensor(double), tensor(float)
**T1** = tensor(int32)| +|||[7, 13]|**T** = tensor(double), tensor(float)
**T1** = tensor(int32)| +|Gather|*in* data:**T**
*in* indices:**Tind**
*out* output:**T**|13+|**T** = tensor(bfloat16), tensor(bool), tensor(double), tensor(float), tensor(float16), tensor(int16), tensor(int32), tensor(int64), tensor(int8), tensor(string), tensor(uint16), tensor(uint32), tensor(uint64), tensor(uint8)
**Tind** = tensor(int32), tensor(int64)| +|||[11, 12]|**T** = tensor(bfloat16), tensor(bool), tensor(double), tensor(float), tensor(float16), tensor(int16), tensor(int32), tensor(int64), tensor(int8), tensor(string), tensor(uint16), tensor(uint32), tensor(uint64), tensor(uint8)
**Tind** = tensor(int32), tensor(int64)| +|||[1, 10]|**T** = tensor(bfloat16), tensor(bool), tensor(double), tensor(float), tensor(float16), tensor(int16), tensor(int32), tensor(int64), tensor(int8), tensor(string), tensor(uint16), tensor(uint32), tensor(uint64), tensor(uint8)
**Tind** = tensor(int32), tensor(int64)| +|GatherElements|*in* data:**T**
*in* indices:**Tind**
*out* output:**T**|13+|**T** = tensor(bfloat16), tensor(bool), tensor(double), tensor(float), tensor(float16), tensor(int16), tensor(int32), tensor(int64), tensor(int8), tensor(string), tensor(uint16), tensor(uint32), tensor(uint64), tensor(uint8)
**Tind** = tensor(int32), tensor(int64)| +|||[11, 12]|**T** = tensor(bfloat16), tensor(bool), tensor(double), tensor(float), tensor(float16), tensor(int16), tensor(int32), tensor(int64), tensor(int8), tensor(string), tensor(uint16), tensor(uint32), tensor(uint64), tensor(uint8)
**Tind** = tensor(int32), tensor(int64)| +|GatherND|*in* data:**T**
*in* indices:**tensor(int64)**
*out* output:**T**|13+|**T** = tensor(bfloat16), tensor(bool), tensor(double), tensor(float), tensor(float16), tensor(int16), tensor(int32), tensor(int64), tensor(int8), tensor(string), tensor(uint16), tensor(uint32), tensor(uint64), tensor(uint8)
**Tind** = tensor(int64)| +|||12|**T** = tensor(bfloat16), tensor(bool), tensor(double), tensor(float), tensor(float16), tensor(int16), tensor(int32), tensor(int64), tensor(int8), tensor(string), tensor(uint16), tensor(uint32), tensor(uint64), tensor(uint8)
**Tind** = tensor(int64)| +|||11|**T** = tensor(bfloat16), tensor(bool), tensor(double), tensor(float), tensor(float16), tensor(int16), tensor(int32), tensor(int64), tensor(int8), tensor(string), tensor(uint16), tensor(uint32), tensor(uint64), tensor(uint8)
**Tind** = tensor(int64)| +|Gemm|*in* A:**T**
*in* B:**T**
*in* C:**T**
*out* Y:**T**|13+|**T** = tensor(double), tensor(float)| +|||[11, 12]|**T** = tensor(double), tensor(float)| +|||[9, 10]|**T** = tensor(double), tensor(float)| +|||[7, 8]|**T** = tensor(double), tensor(float)| +|GlobalAveragePool|*in* X:**T**
*out* Y:**T**|1+|**T** = tensor(float)| +|GlobalLpPool|*in* X:**T**
*out* Y:**T**|2+|**T** = tensor(float)| +|GlobalMaxPool|*in* X:**T**
*out* Y:**T**|1+|**T** = tensor(float)| +|Greater|*in* A:**T**
*in* B:**T**
*out* C:**T1**|13+|**T** = tensor(double), tensor(float), tensor(int32), tensor(int64)
**T1** = tensor(bool)| +|||[9, 12]|**T** = tensor(double), tensor(float), tensor(int32), tensor(int64)
**T1** = tensor(bool)| +|||[7, 8]|**T** = tensor(double), tensor(float)
**T1** = tensor(bool)| +|GreaterOrEqual|*in* A:**T**
*in* B:**T**
*out* C:**T1**|12+|**T** = tensor(double), tensor(float), tensor(int32), tensor(int64)
**T1** = tensor(bool)| +|HardSigmoid|*in* X:**T**
*out* Y:**T**|6+|**T** = tensor(float)| +|Hardmax|*in* input:**T**
*out* output:**T**|13+|**T** = tensor(float)| +|||[11, 12]|**T** = tensor(float)| +|||[1, 10]|**T** = tensor(float)| +|Identity|*in* input:**T**
*out* output:**T**

or

*in* input:**V**
*out* output:**V**|16+|**V** = optional(seq(tensor(bfloat16))), optional(seq(tensor(bool))), optional(seq(tensor(double))), optional(seq(tensor(float))), optional(seq(tensor(float16))), optional(seq(tensor(int16))), optional(seq(tensor(int32))), optional(seq(tensor(int64))), optional(seq(tensor(int8))), optional(seq(tensor(string))), optional(seq(tensor(uint16))), optional(seq(tensor(uint32))), optional(seq(tensor(uint64))), optional(seq(tensor(uint8))), optional(tensor(bfloat16)), optional(tensor(bool)), optional(tensor(double)), optional(tensor(float)), optional(tensor(float16)), optional(tensor(int16)), optional(tensor(int32)), optional(tensor(int64)), optional(tensor(int8)), optional(tensor(string)), optional(tensor(uint16)), optional(tensor(uint32)), optional(tensor(uint64)), optional(tensor(uint8)), seq(tensor(bfloat16)), seq(tensor(bool)), seq(tensor(double)), seq(tensor(float)), seq(tensor(float16)), seq(tensor(int16)), seq(tensor(int32)), seq(tensor(int64)), seq(tensor(int8)), seq(tensor(string)), seq(tensor(uint16)), seq(tensor(uint32)), seq(tensor(uint64)), seq(tensor(uint8)), tensor(bfloat16), tensor(bool), tensor(double), tensor(float), tensor(float16), tensor(int16), tensor(int32), tensor(int64), tensor(int8), tensor(string), tensor(uint16), tensor(uint32), tensor(uint64), tensor(uint8)| +|||[14, 15]|**V** = seq(tensor(bfloat16)), seq(tensor(bool)), seq(tensor(double)), seq(tensor(float)), seq(tensor(float16)), seq(tensor(int16)), seq(tensor(int32)), seq(tensor(int64)), seq(tensor(int8)), seq(tensor(string)), seq(tensor(uint16)), seq(tensor(uint32)), seq(tensor(uint64)), seq(tensor(uint8)), tensor(bfloat16), tensor(bool), tensor(double), tensor(float), tensor(float16), tensor(int16), tensor(int32), tensor(int64), tensor(int8), tensor(string), tensor(uint16), tensor(uint32), tensor(uint64), tensor(uint8)| +|||13|**T** = tensor(bfloat16), tensor(bool), tensor(double), tensor(float), tensor(float16), tensor(int16), tensor(int32), tensor(int64), tensor(int8), tensor(string), tensor(uint16), tensor(uint32), tensor(uint64), tensor(uint8)| +|||[1, 12]|**T** = tensor(bfloat16), tensor(bool), tensor(double), tensor(float), tensor(float16), tensor(int16), tensor(int32), tensor(int64), tensor(int8), tensor(string), tensor(uint16), tensor(uint32), tensor(uint64), tensor(uint8)| +|If|*in* cond:**B**
*out* outputs:**V**|16+|**B** = tensor(bool)
**V** = optional(seq(tensor(bfloat16))), optional(seq(tensor(bool))), optional(seq(tensor(double))), optional(seq(tensor(float))), optional(seq(tensor(float16))), optional(seq(tensor(int16))), optional(seq(tensor(int32))), optional(seq(tensor(int64))), optional(seq(tensor(int8))), optional(seq(tensor(string))), optional(seq(tensor(uint16))), optional(seq(tensor(uint32))), optional(seq(tensor(uint64))), optional(seq(tensor(uint8))), optional(tensor(bfloat16)), optional(tensor(bool)), optional(tensor(double)), optional(tensor(float)), optional(tensor(float16)), optional(tensor(int16)), optional(tensor(int32)), optional(tensor(int64)), optional(tensor(int8)), optional(tensor(string)), optional(tensor(uint16)), optional(tensor(uint32)), optional(tensor(uint64)), optional(tensor(uint8)), seq(tensor(bfloat16)), seq(tensor(bool)), seq(tensor(double)), seq(tensor(float)), seq(tensor(float16)), seq(tensor(int16)), seq(tensor(int32)), seq(tensor(int64)), seq(tensor(int8)), seq(tensor(string)), seq(tensor(uint16)), seq(tensor(uint32)), seq(tensor(uint64)), seq(tensor(uint8)), tensor(bfloat16), tensor(bool), tensor(double), tensor(float), tensor(float16), tensor(int16), tensor(int32), tensor(int64), tensor(int8), tensor(string), tensor(uint16), tensor(uint32), tensor(uint64), tensor(uint8)| +|||[13, 15]|**B** = tensor(bool)
**V** = seq(tensor(bfloat16)), seq(tensor(bool)), seq(tensor(double)), seq(tensor(float)), seq(tensor(float16)), seq(tensor(int16)), seq(tensor(int32)), seq(tensor(int64)), seq(tensor(int8)), seq(tensor(string)), seq(tensor(uint16)), seq(tensor(uint32)), seq(tensor(uint64)), seq(tensor(uint8)), tensor(bfloat16), tensor(bool), tensor(double), tensor(float), tensor(float16), tensor(int16), tensor(int32), tensor(int64), tensor(int8), tensor(string), tensor(uint16), tensor(uint32), tensor(uint64), tensor(uint8)| +|||[11, 12]|**B** = tensor(bool)
**V** = tensor(bfloat16), tensor(bool), tensor(double), tensor(float), tensor(float16), tensor(int16), tensor(int32), tensor(int64), tensor(int8), tensor(string), tensor(uint16), tensor(uint32), tensor(uint64), tensor(uint8)| +|||[1, 10]|**B** = tensor(bool)
**V** = tensor(bfloat16), tensor(bool), tensor(double), tensor(float), tensor(float16), tensor(int16), tensor(int32), tensor(int64), tensor(int8), tensor(string), tensor(uint16), tensor(uint32), tensor(uint64), tensor(uint8)| +|ImageScaler|*in* input:**T**
*out* output:**T**|1+|**T** = tensor(float)| +|InstanceNormalization|*in* input:**T**
*in* scale:**T**
*in* B:**T**
*out* output:**T**|6+|**T** = tensor(float)| +|IsInf|*in* X:**T1**
*out* Y:**T2**|10+|**T1** = tensor(double), tensor(float)
**T2** = tensor(bool)| +|IsNaN|*in* X:**T1**
*out* Y:**T2**|13+|**T1** = tensor(float), tensor(float16)
**T2** = tensor(bool)| +|||[9, 12]|**T1** = tensor(float), tensor(float16)
**T2** = tensor(bool)| +|LRN|*in* X:**T**
*out* Y:**T**|13+|**T** = tensor(float)| +|||[1, 12]|**T** = tensor(float)| +|LSTM|*in* X:**T**
*in* W:**T**
*in* R:**T**
*in* B:**T**
*in* sequence_lens:**T1**
*in* initial_h:**T**
*in* initial_c:**T**
*in* P:**T**
*out* Y:**T**
*out* Y_h:**T**
*out* Y_c:**T**|14+|**T** = tensor(double), tensor(float)
**T1** = tensor(int32)| +|||[7, 13]|**T** = tensor(double), tensor(float)
**T1** = tensor(int32)| +|LayerNormalization|*in* X:**T**
*in* Scale:**T**
*in* B:**T**
*out* Y:**T**
*out* Mean:**U**
*out* InvStdDev:**U**|1+|**T** = tensor(double), tensor(float)| +|LeakyRelu|*in* X:**T**
*out* Y:**T**|6+|**T** = tensor(float)| +|Less|*in* A:**T**
*in* B:**T**
*out* C:**T1**|13+|**T** = tensor(double), tensor(float), tensor(int32), tensor(int64)
**T1** = tensor(bool)| +|||[9, 12]|**T** = tensor(double), tensor(float), tensor(int32), tensor(int64)
**T1** = tensor(bool)| +|||[7, 8]|**T** = tensor(double), tensor(float)
**T1** = tensor(bool)| +|LessOrEqual|*in* A:**T**
*in* B:**T**
*out* C:**T1**|12+|**T** = tensor(double), tensor(float), tensor(int32), tensor(int64)
**T1** = tensor(bool)| +|Log|*in* input:**T**
*out* output:**T**|13+|**T** = tensor(double), tensor(float)| +|||[6, 12]|**T** = tensor(double), tensor(float)| +|LogSoftmax|*in* input:**T**
*out* output:**T**|13+|**T** = tensor(double), tensor(float)| +|||[11, 12]|**T** = tensor(double), tensor(float)| +|||[1, 10]|**T** = tensor(double), tensor(float)| +|Loop|*in* M:**I**
*in* cond:**B**
*in* v_initial:**V**
*out* v_final_and_scan_outputs:**V**|16+|**B** = tensor(bool)
**I** = tensor(int64)
**V** = optional(seq(tensor(bfloat16))), optional(seq(tensor(bool))), optional(seq(tensor(double))), optional(seq(tensor(float))), optional(seq(tensor(float16))), optional(seq(tensor(int16))), optional(seq(tensor(int32))), optional(seq(tensor(int64))), optional(seq(tensor(int8))), optional(seq(tensor(string))), optional(seq(tensor(uint16))), optional(seq(tensor(uint32))), optional(seq(tensor(uint64))), optional(seq(tensor(uint8))), optional(tensor(bfloat16)), optional(tensor(bool)), optional(tensor(double)), optional(tensor(float)), optional(tensor(float16)), optional(tensor(int16)), optional(tensor(int32)), optional(tensor(int64)), optional(tensor(int8)), optional(tensor(string)), optional(tensor(uint16)), optional(tensor(uint32)), optional(tensor(uint64)), optional(tensor(uint8)), seq(tensor(bfloat16)), seq(tensor(bool)), seq(tensor(double)), seq(tensor(float)), seq(tensor(float16)), seq(tensor(int16)), seq(tensor(int32)), seq(tensor(int64)), seq(tensor(int8)), seq(tensor(string)), seq(tensor(uint16)), seq(tensor(uint32)), seq(tensor(uint64)), seq(tensor(uint8)), tensor(bfloat16), tensor(bool), tensor(double), tensor(float), tensor(float16), tensor(int16), tensor(int32), tensor(int64), tensor(int8), tensor(string), tensor(uint16), tensor(uint32), tensor(uint64), tensor(uint8)| +|||[13, 15]|**B** = tensor(bool)
**I** = tensor(int64)
**V** = seq(tensor(bfloat16)), seq(tensor(bool)), seq(tensor(double)), seq(tensor(float)), seq(tensor(float16)), seq(tensor(int16)), seq(tensor(int32)), seq(tensor(int64)), seq(tensor(int8)), seq(tensor(string)), seq(tensor(uint16)), seq(tensor(uint32)), seq(tensor(uint64)), seq(tensor(uint8)), tensor(bfloat16), tensor(bool), tensor(double), tensor(float), tensor(float16), tensor(int16), tensor(int32), tensor(int64), tensor(int8), tensor(string), tensor(uint16), tensor(uint32), tensor(uint64), tensor(uint8)| +|||[11, 12]|**B** = tensor(bool)
**I** = tensor(int64)
**V** = tensor(bfloat16), tensor(bool), tensor(double), tensor(float), tensor(float16), tensor(int16), tensor(int32), tensor(int64), tensor(int8), tensor(string), tensor(uint16), tensor(uint32), tensor(uint64), tensor(uint8)| +|||[1, 10]|**B** = tensor(bool)
**I** = tensor(int64)
**V** = tensor(bfloat16), tensor(bool), tensor(double), tensor(float), tensor(float16), tensor(int16), tensor(int32), tensor(int64), tensor(int8), tensor(string), tensor(uint16), tensor(uint32), tensor(uint64), tensor(uint8)| +|LpNormalization|*in* input:**T**
*out* output:**T**|1+|**T** = tensor(double), tensor(float)| +|LpPool|*in* X:**T**
*out* Y:**T**|11+|**T** = tensor(float)| +|||[2, 10]|**T** = tensor(float)| +|MatMul|*in* A:**T**
*in* B:**T**
*out* Y:**T**|13+|**T** = tensor(double), tensor(float), tensor(int32), tensor(int64), tensor(uint32), tensor(uint64)| +|||[9, 12]|**T** = tensor(double), tensor(float), tensor(int32), tensor(int64), tensor(uint32), tensor(uint64)| +|||[1, 8]|**T** = tensor(double), tensor(float)| +|MatMulInteger|*in* A:**T1**
*in* B:**T2**
*in* a_zero_point:**T1**
*in* b_zero_point:**T2**
*out* Y:**T3**|10+|**T1** = tensor(uint8)
**T2** = tensor(int8), tensor(uint8)
**T3** = tensor(int32)| +|Max|*in* data_0:**T**
*out* max:**T**|13+|**T** = tensor(double), tensor(float), tensor(float16), tensor(int32), tensor(int64), tensor(uint32), tensor(uint64)| +|||12|**T** = tensor(double), tensor(float), tensor(float16), tensor(int32), tensor(int64), tensor(uint32), tensor(uint64)| +|||[8, 11]|**T** = tensor(double), tensor(float)| +|||[6, 7]|**T** = tensor(float)| +|MaxPool|*in* X:**T**
*out* Y:**T**

or

*in* X:**T**
*out* Y:**T**
*out* Indices:**I**|12+|**I** = tensor(int64)
**T** = tensor(double), tensor(float), tensor(int8), tensor(uint8)| +|||[8, 11]|**I** = tensor(int64)
**T** = tensor(double), tensor(float)| +|||[1, 7]|**T** = tensor(float)| +|MaxRoiPool|*in* X:**T**
*in* rois:**T**
*out* Y:**T**|1+|**T** = tensor(float)| +|MaxUnpool|*in* X:**T1**
*in* I:**T2**
*in* output_shape:**T2**
*out* output:**T1**|11+|**T1** = tensor(float)
**T2** = tensor(int64)| +|||[9, 10]|**T1** = tensor(float)
**T2** = tensor(int64)| +|Mean|*in* data_0:**T**
*out* mean:**T**|13+|**T** = tensor(float)| +|||[8, 12]|**T** = tensor(float)| +|||[6, 7]|**T** = tensor(float)| +|MeanVarianceNormalization|*in* X:**T**
*out* Y:**T**

or

*in* input:**T**
*out* output:**T**|13+|**T** = tensor(float)| +|||[9, 12]|**T** = tensor(float)| +|||[1, 8]|**T** = tensor(float)| +|Min|*in* data_0:**T**
*out* min:**T**|13+|**T** = tensor(double), tensor(float), tensor(float16), tensor(int32), tensor(int64), tensor(uint32), tensor(uint64)| +|||12|**T** = tensor(double), tensor(float), tensor(float16), tensor(int32), tensor(int64), tensor(uint32), tensor(uint64)| +|||[8, 11]|**T** = tensor(double), tensor(float)| +|||[6, 7]|**T** = tensor(float)| +|Mod|*in* A:**T**
*in* B:**T**
*out* C:**T**|13+|**T** = tensor(double), tensor(float), tensor(float16), tensor(int16), tensor(int32), tensor(int64), tensor(int8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(uint8)| +|||[10, 12]|**T** = tensor(double), tensor(float), tensor(float16), tensor(int16), tensor(int32), tensor(int64), tensor(int8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(uint8)| +|Mul|*in* A:**T**
*in* B:**T**
*out* C:**T**|14+|**T** = tensor(double), tensor(float), tensor(int32), tensor(int64)| +|||13|**T** = tensor(double), tensor(float), tensor(int32), tensor(int64)| +|||[7, 12]|**T** = tensor(double), tensor(float), tensor(int32), tensor(int64)| +|Multinomial|*in* input:**T1**
*out* output:**T2**|7+|**T1** = tensor(float)
**T2** = tensor(int32), tensor(int64)| +|Neg|*in* X:**T**
*out* Y:**T**|13+|**T** = tensor(double), tensor(float), tensor(int32), tensor(int64), tensor(int8)| +|||[6, 12]|**T** = tensor(double), tensor(float), tensor(int32), tensor(int64), tensor(int8)| +|NonZero|*in* X:**T**
*out* Y:**tensor(int64)**|13+|**T** = tensor(bool), tensor(float), tensor(int32), tensor(int64), tensor(uint8)| +|||[9, 12]|**T** = tensor(bool), tensor(float), tensor(int32), tensor(int64), tensor(uint8)| +|Not|*in* X:**T**
*out* Y:**T**|1+|**T** = tensor(bool)
**T1** = tensor(bool)| +|OneHot|*in* indices:**T1**
*in* depth:**T2**
*in* values:**T3**
*out* output:**T3**|11+|**T1** = tensor(float), tensor(int32), tensor(int64)
**T2** = tensor(float), tensor(int32), tensor(int64)
**T3** = tensor(float), tensor(int32), tensor(int64), tensor(string)| +|||[9, 10]|**T1** = tensor(float), tensor(int32), tensor(int64)
**T2** = tensor(float), tensor(int32), tensor(int64)
**T3** = tensor(float), tensor(int32), tensor(int64), tensor(string)| +|Optional|*in* input:**V**
*out* output:**O**|15+|**O** = optional(seq(tensor(bfloat16))), optional(seq(tensor(bool))), optional(seq(tensor(double))), optional(seq(tensor(float))), optional(seq(tensor(float16))), optional(seq(tensor(int16))), optional(seq(tensor(int32))), optional(seq(tensor(int64))), optional(seq(tensor(int8))), optional(seq(tensor(string))), optional(seq(tensor(uint16))), optional(seq(tensor(uint32))), optional(seq(tensor(uint64))), optional(seq(tensor(uint8))), optional(tensor(bfloat16)), optional(tensor(bool)), optional(tensor(double)), optional(tensor(float)), optional(tensor(float16)), optional(tensor(int16)), optional(tensor(int32)), optional(tensor(int64)), optional(tensor(int8)), optional(tensor(string)), optional(tensor(uint16)), optional(tensor(uint32)), optional(tensor(uint64)), optional(tensor(uint8))
**V** = seq(tensor(bfloat16)), seq(tensor(bool)), seq(tensor(double)), seq(tensor(float)), seq(tensor(float16)), seq(tensor(int16)), seq(tensor(int32)), seq(tensor(int64)), seq(tensor(int8)), seq(tensor(string)), seq(tensor(uint16)), seq(tensor(uint32)), seq(tensor(uint64)), seq(tensor(uint8)), tensor(bfloat16), tensor(bool), tensor(double), tensor(float), tensor(float16), tensor(int16), tensor(int32), tensor(int64), tensor(int8), tensor(string), tensor(uint16), tensor(uint32), tensor(uint64), tensor(uint8)| +|OptionalGetElement|*in* input:**O**
*out* output:**V**|15+|**O** = optional(seq(tensor(bfloat16))), optional(seq(tensor(bool))), optional(seq(tensor(double))), optional(seq(tensor(float))), optional(seq(tensor(float16))), optional(seq(tensor(int16))), optional(seq(tensor(int32))), optional(seq(tensor(int64))), optional(seq(tensor(int8))), optional(seq(tensor(string))), optional(seq(tensor(uint16))), optional(seq(tensor(uint32))), optional(seq(tensor(uint64))), optional(seq(tensor(uint8))), optional(tensor(bfloat16)), optional(tensor(bool)), optional(tensor(double)), optional(tensor(float)), optional(tensor(float16)), optional(tensor(int16)), optional(tensor(int32)), optional(tensor(int64)), optional(tensor(int8)), optional(tensor(string)), optional(tensor(uint16)), optional(tensor(uint32)), optional(tensor(uint64)), optional(tensor(uint8))
**V** = seq(tensor(bfloat16)), seq(tensor(bool)), seq(tensor(double)), seq(tensor(float)), seq(tensor(float16)), seq(tensor(int16)), seq(tensor(int32)), seq(tensor(int64)), seq(tensor(int8)), seq(tensor(string)), seq(tensor(uint16)), seq(tensor(uint32)), seq(tensor(uint64)), seq(tensor(uint8)), tensor(bfloat16), tensor(bool), tensor(double), tensor(float), tensor(float16), tensor(int16), tensor(int32), tensor(int64), tensor(int8), tensor(string), tensor(uint16), tensor(uint32), tensor(uint64), tensor(uint8)| +|OptionalHasElement|*in* input:**O**
*out* output:**B**|15+|**B** = tensor(bool)
**O** = optional(seq(tensor(bfloat16))), optional(seq(tensor(bool))), optional(seq(tensor(double))), optional(seq(tensor(float))), optional(seq(tensor(float16))), optional(seq(tensor(int16))), optional(seq(tensor(int32))), optional(seq(tensor(int64))), optional(seq(tensor(int8))), optional(seq(tensor(string))), optional(seq(tensor(uint16))), optional(seq(tensor(uint32))), optional(seq(tensor(uint64))), optional(seq(tensor(uint8))), optional(tensor(bfloat16)), optional(tensor(bool)), optional(tensor(double)), optional(tensor(float)), optional(tensor(float16)), optional(tensor(int16)), optional(tensor(int32)), optional(tensor(int64)), optional(tensor(int8)), optional(tensor(string)), optional(tensor(uint16)), optional(tensor(uint32)), optional(tensor(uint64)), optional(tensor(uint8))| +|Or|*in* A:**T**
*in* B:**T**
*out* C:**T1**|7+|**T** = tensor(bool)
**T1** = tensor(bool)| +|PRelu|*in* X:**T**
*in* slope:**T**
*out* Y:**T**|9+|**T** = tensor(float)| +|||[7, 8]|**T** = tensor(float)| +|Pad|*in* data:**T**
*in* pads:**tensor(int64)**
*in* constant_value:**T**
*out* output:**T**

or

*in* data:**T**
*out* output:**T**|13+|**T** = tensor(bool), tensor(double), tensor(float), tensor(int32), tensor(int64), tensor(int8), tensor(uint32), tensor(uint64), tensor(uint8)| +|||[11, 12]|**T** = tensor(double), tensor(float), tensor(int32), tensor(int64), tensor(int8), tensor(uint32), tensor(uint64), tensor(uint8)| +|||[2, 10]|**T** = tensor(double), tensor(float)| +|ParametricSoftplus|*in* X:**T**
*out* Y:**T**|1+|**T** = tensor(float)| +|Pow|*in* X:**T**
*in* Y:**T**
*out* Z:**T**

or

*in* X:**T**
*in* Y:**T1**
*out* Z:**T**|15+|**T** = tensor(double), tensor(float), tensor(int32), tensor(int64)
**T1** = tensor(double), tensor(float), tensor(int32), tensor(int64)| +|||[13, 14]|**T** = tensor(double), tensor(float), tensor(int32), tensor(int64)
**T1** = tensor(double), tensor(float), tensor(int32), tensor(int64)| +|||12|**T** = tensor(double), tensor(float), tensor(int32), tensor(int64)
**T1** = tensor(double), tensor(float), tensor(int32), tensor(int64)| +|||[7, 11]|**T** = tensor(double), tensor(float)| +|QLinearConv|*in* x:**T1**
*in* x_scale:**tensor(float)**
*in* x_zero_point:**T1**
*in* w:**T2**
*in* w_scale:**tensor(float)**
*in* w_zero_point:**T2**
*in* y_scale:**tensor(float)**
*in* y_zero_point:**T3**
*in* B:**T4**
*out* y:**T3**|10+|**T1** = tensor(uint8)
**T2** = tensor(int8), tensor(uint8)
**T3** = tensor(uint8)
**T4** = tensor(int32)| +|QLinearMatMul|*in* a:**T1**
*in* a_scale:**tensor(float)**
*in* a_zero_point:**T1**
*in* b:**T2**
*in* b_scale:**tensor(float)**
*in* b_zero_point:**T2**
*in* y_scale:**tensor(float)**
*in* y_zero_point:**T3**
*out* y:**T3**|10+|**T1** = tensor(uint8)
**T2** = tensor(int8), tensor(uint8)
**T3** = tensor(uint8)| +|QuantizeLinear|*in* x:**T1**
*in* y_scale:**tensor(float)**
*in* y_zero_point:**T2**
*out* y:**T2**|13+|**T1** = tensor(float)
**T2** = tensor(int8), tensor(uint8)| +|||[10, 12]|**T1** = tensor(float)
**T2** = tensor(int8), tensor(uint8)| +|RNN|*in* X:**T**
*in* W:**T**
*in* R:**T**
*in* B:**T**
*in* sequence_lens:**T1**
*in* initial_h:**T**
*out* Y:**T**
*out* Y_h:**T**|14+|**T** = tensor(float)
**T1** = tensor(int32)| +|||[7, 13]|**T** = tensor(float)
**T1** = tensor(int32)| +|RandomNormal|*out* output:**T**|1+|**T** = tensor(double), tensor(float)| +|RandomNormalLike|*in* input:**T1**
*out* output:**T2**|1+|**T1** = tensor(bfloat16), tensor(bool), tensor(double), tensor(float), tensor(float16), tensor(int16), tensor(int32), tensor(int64), tensor(int8), tensor(string), tensor(uint16), tensor(uint32), tensor(uint64), tensor(uint8)
**T2** = tensor(double), tensor(float)| +|RandomUniform|*out* output:**T**|1+|**T** = tensor(double), tensor(float)| +|RandomUniformLike|*in* input:**T1**
*out* output:**T2**|1+|**T1** = tensor(bfloat16), tensor(bool), tensor(double), tensor(float), tensor(float16), tensor(int16), tensor(int32), tensor(int64), tensor(int8), tensor(string), tensor(uint16), tensor(uint32), tensor(uint64), tensor(uint8)
**T2** = tensor(double), tensor(float)| +|Range|*in* start:**T**
*in* limit:**T**
*in* delta:**T**
*out* output:**T**|11+|**T** = tensor(double), tensor(float), tensor(int16), tensor(int32), tensor(int64)| +|Reciprocal|*in* X:**T**
*out* Y:**T**|13+|**T** = tensor(double), tensor(float)| +|||[6, 12]|**T** = tensor(double), tensor(float)| +|ReduceL1|*in* data:**T**
*out* reduced:**T**|13+|**T** = tensor(float), tensor(int32)| +|||[11, 12]|**T** = tensor(float), tensor(int32)| +|||[1, 10]|**T** = tensor(float), tensor(int32)| +|ReduceL2|*in* data:**T**
*out* reduced:**T**|13+|**T** = tensor(float), tensor(int32)| +|||[11, 12]|**T** = tensor(float), tensor(int32)| +|||[1, 10]|**T** = tensor(float), tensor(int32)| +|ReduceLogSum|*in* data:**T**
*out* reduced:**T**|13+|**T** = tensor(float), tensor(int32)| +|||[11, 12]|**T** = tensor(float), tensor(int32)| +|||[1, 10]|**T** = tensor(float), tensor(int32)| +|ReduceLogSumExp|*in* data:**T**
*out* reduced:**T**|13+|**T** = tensor(double), tensor(float), tensor(int32)| +|||[11, 12]|**T** = tensor(double), tensor(float), tensor(int32)| +|||[1, 10]|**T** = tensor(double), tensor(float), tensor(int32)| +|ReduceMax|*in* data:**T**
*out* reduced:**T**|13+|**T** = tensor(double), tensor(float), tensor(int32), tensor(int64), tensor(int8), tensor(uint8)| +|||12|**T** = tensor(double), tensor(float), tensor(int32), tensor(int64), tensor(int8), tensor(uint8)| +|||11|**T** = tensor(double), tensor(float), tensor(int32), tensor(int64)| +|||[1, 10]|**T** = tensor(double), tensor(float), tensor(int32), tensor(int64)| +|ReduceMean|*in* data:**T**
*out* reduced:**T**|13+|**T** = tensor(double), tensor(float), tensor(int32)| +|||[11, 12]|**T** = tensor(double), tensor(float), tensor(int32)| +|||[1, 10]|**T** = tensor(double), tensor(float), tensor(int32)| +|ReduceMin|*in* data:**T**
*out* reduced:**T**|13+|**T** = tensor(double), tensor(float), tensor(int32), tensor(int64), tensor(int8), tensor(uint8)| +|||12|**T** = tensor(double), tensor(float), tensor(int32), tensor(int64), tensor(int8), tensor(uint8)| +|||11|**T** = tensor(double), tensor(float), tensor(int32), tensor(int64)| +|||[1, 10]|**T** = tensor(double), tensor(float), tensor(int32), tensor(int64)| +|ReduceProd|*in* data:**T**
*out* reduced:**T**|13+|**T** = tensor(float), tensor(int32), tensor(int64)| +|||[11, 12]|**T** = tensor(float), tensor(int32), tensor(int64)| +|||[1, 10]|**T** = tensor(float), tensor(int32), tensor(int64)| +|ReduceSum|*in* data:**T**
*in* axes:**tensor(int64)**
*out* reduced:**T**

or

*in* data:**T**
*out* reduced:**T**|13+|**T** = tensor(double), tensor(float), tensor(int32), tensor(int64)| +|||[11, 12]|**T** = tensor(double), tensor(float), tensor(int32), tensor(int64)| +|||[1, 10]|**T** = tensor(double), tensor(float), tensor(int32), tensor(int64)| +|ReduceSumSquare|*in* data:**T**
*out* reduced:**T**|13+|**T** = tensor(double), tensor(float), tensor(int32)| +|||[11, 12]|**T** = tensor(double), tensor(float), tensor(int32)| +|||[1, 10]|**T** = tensor(double), tensor(float), tensor(int32)| +|Relu|*in* X:**T**
*out* Y:**T**|14+|**T** = tensor(double), tensor(float), tensor(int32), tensor(int8)| +|||13|**T** = tensor(double), tensor(float)| +|||[6, 12]|**T** = tensor(double), tensor(float)| +|Reshape|*in* data:**T**
*in* shape:**tensor(int64)**
*out* reshaped:**T**

or

*in* data:**T**
*out* reshaped:**T**|14+|**T** = tensor(bfloat16), tensor(bool), tensor(double), tensor(float), tensor(float16), tensor(int16), tensor(int32), tensor(int64), tensor(int8), tensor(string), tensor(uint16), tensor(uint32), tensor(uint64), tensor(uint8)
**shape** = tensor(int64)| +|||13|**T** = tensor(bfloat16), tensor(bool), tensor(double), tensor(float), tensor(float16), tensor(int16), tensor(int32), tensor(int64), tensor(int8), tensor(string), tensor(uint16), tensor(uint32), tensor(uint64), tensor(uint8)
**shape** = tensor(int64)| +|||[5, 12]|**T** = tensor(bfloat16), tensor(bool), tensor(double), tensor(float), tensor(float16), tensor(int16), tensor(int32), tensor(int64), tensor(int8), tensor(string), tensor(uint16), tensor(uint32), tensor(uint64), tensor(uint8)
**shape** = tensor(int64)| +|||[1, 4]|**T** = tensor(bfloat16), tensor(bool), tensor(double), tensor(float), tensor(float16), tensor(int16), tensor(int32), tensor(int64), tensor(int8), tensor(string), tensor(uint16), tensor(uint32), tensor(uint64), tensor(uint8)| +|Resize|*in* X:**T**
*in* scales:**tensor(float)**
*out* Y:**T**

or

*in* X:**T1**
*in* roi:**T2**
*in* scales:**tensor(float)**
*in* sizes:**tensor(int64)**
*out* Y:**T1**|13+|**T1** = tensor(float), tensor(int32), tensor(uint8)| +|||[11, 12]|**T1** = tensor(float), tensor(int32), tensor(uint8)| +|||10|**T** = tensor(float), tensor(int32), tensor(uint8)| +|ReverseSequence|*in* input:**T**
*in* sequence_lens:**tensor(int64)**
*out* Y:**T**|10+|**T** = tensor(bfloat16), tensor(bool), tensor(double), tensor(float), tensor(float16), tensor(int16), tensor(int32), tensor(int64), tensor(int8), tensor(string), tensor(uint16), tensor(uint32), tensor(uint64), tensor(uint8)| +|RoiAlign|*in* X:**T1**
*in* rois:**T1**
*in* batch_indices:**T2**
*out* Y:**T1**|10+|**T** = tensor(double), tensor(float)
**T2** = tensor(int64)| +|Round|*in* X:**T**
*out* Y:**T**|11+|**T** = tensor(double), tensor(float), tensor(float16)| +|Scale|*in* input:**T**
*out* output:**T**|1+|**T** = tensor(float)| +|ScaledTanh|*in* input:**T**
*out* output:**T**|1+|**T** = tensor(float)| +|Scan|*in* initial_state_and_scan_inputs:**V**
*out* final_state_and_scan_outputs:**V**

or

*in* sequence_lens:**I**
*in* initial_state_and_scan_inputs:**V**
*out* final_state_and_scan_outputs:**V**|11+|**I** = tensor(int64)
**V** = tensor(bfloat16), tensor(bool), tensor(double), tensor(float), tensor(float16), tensor(int16), tensor(int32), tensor(int64), tensor(int8), tensor(string), tensor(uint16), tensor(uint32), tensor(uint64), tensor(uint8)| +|||[9, 10]|**I** = tensor(int64)
**V** = tensor(bfloat16), tensor(bool), tensor(double), tensor(float), tensor(float16), tensor(int16), tensor(int32), tensor(int64), tensor(int8), tensor(string), tensor(uint16), tensor(uint32), tensor(uint64), tensor(uint8)| +|||8|**I** = tensor(int64)
**V** = tensor(bfloat16), tensor(bool), tensor(double), tensor(float), tensor(float16), tensor(int16), tensor(int32), tensor(int64), tensor(int8), tensor(string), tensor(uint16), tensor(uint32), tensor(uint64), tensor(uint8)| +|Scatter|*in* data:**T**
*in* indices:**Tind**
*in* updates:**T**
*out* output:**T**|[9, 10]|**T** = tensor(bfloat16), tensor(bool), tensor(double), tensor(float), tensor(float16), tensor(int16), tensor(int32), tensor(int64), tensor(int8), tensor(string), tensor(uint16), tensor(uint32), tensor(uint64), tensor(uint8)
**Tind** = tensor(int32), tensor(int64)| +|ScatterElements|*in* data:**T**
*in* indices:**Tind**
*in* updates:**T**
*out* output:**T**|13+|**T** = tensor(bfloat16), tensor(bool), tensor(double), tensor(float), tensor(float16), tensor(int16), tensor(int32), tensor(int64), tensor(int8), tensor(string), tensor(uint16), tensor(uint32), tensor(uint64), tensor(uint8)
**Tind** = tensor(int32), tensor(int64)| +|||[11, 12]|**T** = tensor(bfloat16), tensor(bool), tensor(double), tensor(float), tensor(float16), tensor(int16), tensor(int32), tensor(int64), tensor(int8), tensor(string), tensor(uint16), tensor(uint32), tensor(uint64), tensor(uint8)
**Tind** = tensor(int32), tensor(int64)| +|ScatterND|*in* data:**T**
*in* indices:**tensor(int64)**
*in* updates:**T**
*out* output:**T**|13+|**T** = tensor(bfloat16), tensor(bool), tensor(double), tensor(float), tensor(float16), tensor(int16), tensor(int32), tensor(int64), tensor(int8), tensor(string), tensor(uint16), tensor(uint32), tensor(uint64), tensor(uint8)| +|||[11, 12]|**T** = tensor(bfloat16), tensor(bool), tensor(double), tensor(float), tensor(float16), tensor(int16), tensor(int32), tensor(int64), tensor(int8), tensor(string), tensor(uint16), tensor(uint32), tensor(uint64), tensor(uint8)| +|Selu|*in* X:**T**
*out* Y:**T**|6+|**T** = tensor(float)| +|SequenceAt|*in* input_sequence:**S**
*in* position:**I**
*out* tensor:**T**|11+|**I** = tensor(int32), tensor(int64)
**S** = seq(tensor(bfloat16)), seq(tensor(bool)), seq(tensor(double)), seq(tensor(float)), seq(tensor(float16)), seq(tensor(int16)), seq(tensor(int32)), seq(tensor(int64)), seq(tensor(int8)), seq(tensor(string)), seq(tensor(uint16)), seq(tensor(uint32)), seq(tensor(uint64)), seq(tensor(uint8))
**T** = tensor(bfloat16), tensor(bool), tensor(double), tensor(float), tensor(float16), tensor(int16), tensor(int32), tensor(int64), tensor(int8), tensor(string), tensor(uint16), tensor(uint32), tensor(uint64), tensor(uint8)| +|SequenceConstruct|*in* inputs:**T**
*out* output_sequence:**S**|11+|**S** = seq(tensor(bfloat16)), seq(tensor(bool)), seq(tensor(double)), seq(tensor(float)), seq(tensor(float16)), seq(tensor(int16)), seq(tensor(int32)), seq(tensor(int64)), seq(tensor(int8)), seq(tensor(string)), seq(tensor(uint16)), seq(tensor(uint32)), seq(tensor(uint64)), seq(tensor(uint8))
**T** = tensor(bfloat16), tensor(bool), tensor(double), tensor(float), tensor(float16), tensor(int16), tensor(int32), tensor(int64), tensor(int8), tensor(string), tensor(uint16), tensor(uint32), tensor(uint64), tensor(uint8)| +|SequenceEmpty|*out* output:**S**|11+|**S** = seq(tensor(bfloat16)), seq(tensor(bool)), seq(tensor(double)), seq(tensor(float)), seq(tensor(float16)), seq(tensor(int16)), seq(tensor(int32)), seq(tensor(int64)), seq(tensor(int8)), seq(tensor(string)), seq(tensor(uint16)), seq(tensor(uint32)), seq(tensor(uint64)), seq(tensor(uint8))| +|SequenceErase|*in* input_sequence:**S**
*in* position:**I**
*out* output_sequence:**S**|11+|**I** = tensor(int32), tensor(int64)
**S** = seq(tensor(bfloat16)), seq(tensor(bool)), seq(tensor(double)), seq(tensor(float)), seq(tensor(float16)), seq(tensor(int16)), seq(tensor(int32)), seq(tensor(int64)), seq(tensor(int8)), seq(tensor(string)), seq(tensor(uint16)), seq(tensor(uint32)), seq(tensor(uint64)), seq(tensor(uint8))| +|SequenceInsert|*in* input_sequence:**S**
*in* tensor:**T**
*in* position:**I**
*out* output_sequence:**S**|11+|**I** = tensor(int32), tensor(int64)
**S** = seq(tensor(bfloat16)), seq(tensor(bool)), seq(tensor(double)), seq(tensor(float)), seq(tensor(float16)), seq(tensor(int16)), seq(tensor(int32)), seq(tensor(int64)), seq(tensor(int8)), seq(tensor(string)), seq(tensor(uint16)), seq(tensor(uint32)), seq(tensor(uint64)), seq(tensor(uint8))| +|SequenceLength|*in* input_sequence:**S**
*out* length:**I**|11+|**I** = tensor(int64)
**S** = seq(tensor(bfloat16)), seq(tensor(bool)), seq(tensor(double)), seq(tensor(float)), seq(tensor(float16)), seq(tensor(int16)), seq(tensor(int32)), seq(tensor(int64)), seq(tensor(int8)), seq(tensor(string)), seq(tensor(uint16)), seq(tensor(uint32)), seq(tensor(uint64)), seq(tensor(uint8))| +|Shape|*in* data:**T**
*out* shape:**T1**|15+|**T** = tensor(bfloat16), tensor(bool), tensor(double), tensor(float), tensor(float16), tensor(int16), tensor(int32), tensor(int64), tensor(int8), tensor(string), tensor(uint16), tensor(uint32), tensor(uint64), tensor(uint8)
**T1** = tensor(int64)| +|||[13, 14]|**T** = tensor(bfloat16), tensor(bool), tensor(double), tensor(float), tensor(float16), tensor(int16), tensor(int32), tensor(int64), tensor(int8), tensor(string), tensor(uint16), tensor(uint32), tensor(uint64), tensor(uint8)
**T1** = tensor(int64)| +|||[1, 12]|**T** = tensor(bfloat16), tensor(bool), tensor(double), tensor(float), tensor(float16), tensor(int16), tensor(int32), tensor(int64), tensor(int8), tensor(string), tensor(uint16), tensor(uint32), tensor(uint64), tensor(uint8)
**T1** = tensor(int64)| +|Shrink|*in* input:**T**
*out* output:**T**|9+|**T** = tensor(bfloat16), tensor(double), tensor(float), tensor(float16), tensor(int16), tensor(int32), tensor(int64), tensor(int8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(uint8)| +|Sigmoid|*in* X:**T**
*out* Y:**T**|13+|**T** = tensor(double), tensor(float)| +|||[6, 12]|**T** = tensor(double), tensor(float)| +|Sign|*in* input:**T**
*out* output:**T**|13+|**T** = tensor(bfloat16), tensor(double), tensor(float), tensor(float16), tensor(int16), tensor(int32), tensor(int64), tensor(int8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(uint8)| +|||[9, 12]|**T** = tensor(bfloat16), tensor(double), tensor(float), tensor(float16), tensor(int16), tensor(int32), tensor(int64), tensor(int8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(uint8)| +|SimplifiedLayerNormalization|*in* X:**T**
*in* scale:**T**
*out* Y:**T**
*out* inv_std_var:**U**|1+|**T** = tensor(double), tensor(float)| +|Sin|*in* input:**T**
*out* output:**T**|7+|**T** = tensor(double), tensor(float)| +|Sinh|*in* input:**T**
*out* output:**T**|9+|**T** = tensor(float)| +|Size|*in* data:**T**
*out* size:**T1**|13+|**T** = tensor(bool), tensor(double), tensor(float), tensor(int16), tensor(int32), tensor(int64), tensor(int8), tensor(string), tensor(uint16), tensor(uint32), tensor(uint64), tensor(uint8)
**T1** = tensor(int64)| +|||[1, 12]|**T** = tensor(bool), tensor(double), tensor(float), tensor(int16), tensor(int32), tensor(int64), tensor(int8), tensor(string), tensor(uint16), tensor(uint32), tensor(uint64), tensor(uint8)
**T1** = tensor(int64)| +|Slice|*in* data:**T**
*in* starts:**Tind**
*in* ends:**Tind**
*in* axes:**Tind**
*in* steps:**Tind**
*out* output:**T**

or

*in* data:**T**
*out* output:**T**|13+|**T** = tensor(bfloat16), tensor(bool), tensor(double), tensor(float), tensor(float16), tensor(int16), tensor(int32), tensor(int64), tensor(int8), tensor(string), tensor(uint16), tensor(uint32), tensor(uint64), tensor(uint8)
**Tind** = tensor(int32), tensor(int64)| +|||[11, 12]|**T** = tensor(bfloat16), tensor(bool), tensor(double), tensor(float), tensor(float16), tensor(int16), tensor(int32), tensor(int64), tensor(int8), tensor(string), tensor(uint16), tensor(uint32), tensor(uint64), tensor(uint8)
**Tind** = tensor(int32), tensor(int64)| +|||10|**T** = tensor(bfloat16), tensor(bool), tensor(double), tensor(float), tensor(float16), tensor(int16), tensor(int32), tensor(int64), tensor(int8), tensor(string), tensor(uint16), tensor(uint32), tensor(uint64), tensor(uint8)
**Tind** = tensor(int32), tensor(int64)| +|||[1, 9]|**T** = tensor(bfloat16), tensor(bool), tensor(double), tensor(float), tensor(float16), tensor(int16), tensor(int32), tensor(int64), tensor(int8), tensor(string), tensor(uint16), tensor(uint32), tensor(uint64), tensor(uint8)| +|Softmax|*in* input:**T**
*out* output:**T**|13+|**T** = tensor(double), tensor(float)| +|||[11, 12]|**T** = tensor(double), tensor(float)| +|||[1, 10]|**T** = tensor(double), tensor(float)| +|Softplus|*in* X:**T**
*out* Y:**T**|1+|**T** = tensor(float)| +|Softsign|*in* input:**T**
*out* output:**T**|1+|**T** = tensor(float)| +|SpaceToDepth|*in* input:**T**
*out* output:**T**|13+|**T** = tensor(double), tensor(float)| +|||[1, 12]|**T** = tensor(double), tensor(float)| +|Split|*in* input:**T**
*in* split:**T**
*out* outputs...:**T**

or

*in* input:**T**
*in* split:**tensor(int64)**
*out* outputs:**T**

or

*in* input:**T**
*out* outputs:**T**|13+|**T** = tensor(float), tensor(int32), tensor(int64), tensor(int8), tensor(string), tensor(uint8)| +|||[11, 12]|**T** = tensor(float), tensor(int32), tensor(int64), tensor(int8), tensor(string), tensor(uint8)| +|||[2, 10]|**T** = tensor(float), tensor(int32), tensor(int64), tensor(int8), tensor(string), tensor(uint8)| +|SplitToSequence|*in* input:**T**
*in* split:**I**
*out* output_sequence:**S**|11+|**I** = tensor(int32), tensor(int64)
**S** = seq(tensor(bfloat16)), seq(tensor(bool)), seq(tensor(double)), seq(tensor(float)), seq(tensor(float16)), seq(tensor(int16)), seq(tensor(int32)), seq(tensor(int64)), seq(tensor(int8)), seq(tensor(string)), seq(tensor(uint16)), seq(tensor(uint32)), seq(tensor(uint64)), seq(tensor(uint8))
**T** = tensor(double), tensor(float), tensor(int32), tensor(int64), tensor(string)| +|Sqrt|*in* X:**T**
*out* Y:**T**|13+|**T** = tensor(double), tensor(float)| +|||[6, 12]|**T** = tensor(double), tensor(float)| +|Squeeze|*in* data:**T**
*in* axes:**tensor(int64)**
*out* squeezed:**T**

or

*in* data:**T**
*out* squeezed:**T**|13+|**T** = tensor(bfloat16), tensor(bool), tensor(double), tensor(float), tensor(float16), tensor(int16), tensor(int32), tensor(int64), tensor(int8), tensor(string), tensor(uint16), tensor(uint32), tensor(uint64), tensor(uint8)| +|||[11, 12]|**T** = tensor(bfloat16), tensor(bool), tensor(double), tensor(float), tensor(float16), tensor(int16), tensor(int32), tensor(int64), tensor(int8), tensor(string), tensor(uint16), tensor(uint32), tensor(uint64), tensor(uint8)| +|||[1, 10]|**T** = tensor(bfloat16), tensor(bool), tensor(double), tensor(float), tensor(float16), tensor(int16), tensor(int32), tensor(int64), tensor(int8), tensor(string), tensor(uint16), tensor(uint32), tensor(uint64), tensor(uint8)| +|StringNormalizer|*in* X:**tensor(string)**
*out* Y:**tensor(string)**|10+|**T** = tensor(string)| +|Sub|*in* A:**T**
*in* B:**T**
*out* C:**T**|14+|**T** = tensor(double), tensor(float), tensor(int32), tensor(int64)| +|||13|**T** = tensor(double), tensor(float), tensor(int32), tensor(int64)| +|||[7, 12]|**T** = tensor(double), tensor(float), tensor(int32), tensor(int64)| +|Sum|*in* data_0:**T**
*out* sum:**T**|13+|**T** = tensor(double), tensor(float)| +|||[8, 12]|**T** = tensor(double), tensor(float)| +|||[6, 7]|**T** = tensor(double), tensor(float)| +|Tan|*in* input:**T**
*out* output:**T**|7+|**T** = tensor(float)| +|Tanh|*in* input:**T**
*out* output:**T**|13+|**T** = tensor(double), tensor(float)| +|||[6, 12]|**T** = tensor(double), tensor(float)| +|TfIdfVectorizer|*in* X:**T**
*out* Y:**T1**|9+|**T** = tensor(int32), tensor(int64), tensor(string)
**T1** = tensor(float)| +|ThresholdedRelu|*in* X:**T**
*out* Y:**T**|10+|**T** = tensor(float)| +|||[1, 9]|**T** = tensor(float)| +|Tile|*in* input:**T**
*in* repeats:**T1**
*out* output:**T**

or

*in* input:**T**
*in* tiles:**T**
*in* axis:**T**
*out* output:**T**|13+|**T** = tensor(bool), tensor(double), tensor(float), tensor(int16), tensor(int32), tensor(int64), tensor(int8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(uint8)
**T1** = tensor(int64)| +|||[6, 12]|**T** = tensor(bool), tensor(double), tensor(float), tensor(int16), tensor(int32), tensor(int64), tensor(int8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(uint8)
**T1** = tensor(int64)| +|TopK|*in* X:**T**
*in* K:**tensor(int64)**
*out* Values:**T**
*out* Indices:**I**

or

*in* X:**T**
*out* Values:**T**
*out* Indices:**I**|11+|**I** = tensor(int64)
**T** = tensor(double), tensor(float), tensor(int32), tensor(int64)| +|||10|**I** = tensor(int64)
**T** = tensor(double), tensor(float)| +|||[1, 9]|**I** = tensor(int64)
**T** = tensor(double), tensor(float)| +|Transpose|*in* data:**T**
*out* transposed:**T**|13+|**T** = tensor(bfloat16), tensor(bool), tensor(double), tensor(float), tensor(float16), tensor(int16), tensor(int32), tensor(int64), tensor(int8), tensor(string), tensor(uint16), tensor(uint32), tensor(uint64), tensor(uint8)| +|||[1, 12]|**T** = tensor(bfloat16), tensor(bool), tensor(double), tensor(float), tensor(float16), tensor(int16), tensor(int32), tensor(int64), tensor(int8), tensor(string), tensor(uint16), tensor(uint32), tensor(uint64), tensor(uint8)| +|Trilu|*in* input:**T**
*in* k:**tensor(int64)**
*out* output:**T**|14+|**T** = tensor(double), tensor(float), tensor(int64)| +|Unique|*in* X:**T**
*out* Y:**T**
*out* indices:**tensor(int64)**
*out* inverse_indices:**tensor(int64)**
*out* counts:**tensor(int64)**|11+|**T** = tensor(float), tensor(int64), tensor(int8), tensor(string)| +|Unsqueeze|*in* data:**T**
*in* axes:**tensor(int64)**
*out* expanded:**T**

or

*in* data:**T**
*out* expanded:**T**|13+|**T** = tensor(bfloat16), tensor(bool), tensor(double), tensor(float), tensor(float16), tensor(int16), tensor(int32), tensor(int64), tensor(int8), tensor(string), tensor(uint16), tensor(uint32), tensor(uint64), tensor(uint8)| +|||[11, 12]|**T** = tensor(bfloat16), tensor(bool), tensor(double), tensor(float), tensor(float16), tensor(int16), tensor(int32), tensor(int64), tensor(int8), tensor(string), tensor(uint16), tensor(uint32), tensor(uint64), tensor(uint8)| +|||[1, 10]|**T** = tensor(bfloat16), tensor(bool), tensor(double), tensor(float), tensor(float16), tensor(int16), tensor(int32), tensor(int64), tensor(int8), tensor(string), tensor(uint16), tensor(uint32), tensor(uint64), tensor(uint8)| +|Upsample|*in* X:**T**
*in* scales:**tensor(float)**
*out* Y:**T**

or

*in* X:**T**
*out* Y:**T**|9|**T** = tensor(float), tensor(int32), tensor(uint8)| +|||[7, 8]|**T** = tensor(float), tensor(int32), tensor(uint8)| +|Where|*in* condition:**B**
*in* X:**T**
*in* Y:**T**
*out* output:**T**|9+|**T** = tensor(double), tensor(float), tensor(int32), tensor(int64), tensor(string), tensor(uint8)| +|Xor|*in* A:**T**
*in* B:**T**
*out* C:**T1**|7+|**T** = tensor(bool)
**T1** = tensor(bool)| +| | +| | +|**Operator Domain:** *ai.onnx.ml*|||| +|ArrayFeatureExtractor|*in* X:**T**
*in* Y:**tensor(int64)**
*out* Z:**T**|1+|**T** = tensor(double), tensor(float), tensor(int32), tensor(int64), tensor(string)| +|Binarizer|*in* X:**T**
*out* Y:**T**|1+|**T** = tensor(float)| +|CastMap|*in* X:**T1**
*out* Y:**T2**|1+|**T1** = map(int64,tensor(float)), map(int64,tensor(string))
**T2** = tensor(float), tensor(int64), tensor(string)| +|CategoryMapper|*in* X:**T1**
*out* Y:**T2**|1+|**T1** = tensor(int64), tensor(string)
**T2** = tensor(int64), tensor(string)| +|DictVectorizer|*in* X:**T1**
*out* Y:**T2**|1+|**T1** = map(int64,tensor(double)), map(int64,tensor(float)), map(int64,tensor(string)), map(string,tensor(double)), map(string,tensor(float)), map(string,tensor(int64))
**T2** = tensor(double), tensor(float), tensor(int64), tensor(string)| +|FeatureVectorizer|*in* X:**T1**
*out* Y:**tensor(float)**|1+|**T1** = tensor(double), tensor(float), tensor(int32), tensor(int64)| +|Imputer|*in* X:**T**
*out* Y:**T**|1+|**T** = tensor(float), tensor(int64)| +|LabelEncoder|*in* X:**T1**
*out* Y:**T2**|2+|**T1** = tensor(float), tensor(int64), tensor(string)
**T2** = tensor(float), tensor(int64), tensor(string)| +|||1|**T1** = tensor(int64), tensor(string)
**T2** = tensor(int64), tensor(string)| +|LinearClassifier|*in* X:**T1**
*out* Y:**T2**
*out* Z:**tensor(float)**|1+|**T1** = tensor(double), tensor(float), tensor(int32), tensor(int64)
**T2** = tensor(int64), tensor(string)| +|LinearRegressor|*in* X:**T**
*out* Y:**tensor(float)**|1+|**T** = tensor(float)| +|Normalizer|*in* X:**T**
*out* Y:**tensor(float)**|1+|**T** = tensor(double), tensor(float), tensor(int32), tensor(int64)| +|OneHotEncoder|*in* X:**T**
*out* Y:**tensor(float)**|1+|**T** = tensor(double), tensor(float), tensor(int64), tensor(string)| +|SVMClassifier|*in* X:**T1**
*out* Y:**T2**
*out* Z:**tensor(float)**|1+|**T1** = tensor(double), tensor(float), tensor(int32), tensor(int64)
**T2** = tensor(int64), tensor(string)| +|SVMRegressor|*in* X:**T**
*out* Y:**tensor(float)**|1+|**T** = tensor(float)| +|Scaler|*in* X:**T**
*out* Y:**tensor(float)**|1+|**T** = tensor(double), tensor(float), tensor(int32), tensor(int64)| +|TreeEnsembleClassifier|*in* X:**T1**
*out* Y:**T2**
*out* Z:**tensor(float)**|1+|**T1** = tensor(double), tensor(float), tensor(int32), tensor(int64)
**T2** = tensor(int64), tensor(string)| +|TreeEnsembleRegressor|*in* X:**T**
*out* Y:**tensor(float)**|1+|**T** = tensor(double), tensor(float)| +|ZipMap|*in* X:**tensor(float)**
*out* Z:**T**|1+|**T** = seq(map(int64,tensor(float))), seq(map(string,tensor(float)))| +| | +| | +|**Operator Domain:** *com.microsoft*|||| +|Attention|*in* input:**T**
*in* weight:**T**
*in* bias:**T**
*in* mask_index:**M**
*in* past:**T**
*in* extra_add:**T**
*out* output:**T**
*out* present:**T**|1+|**T** = tensor(float)| +|AttnLSTM|*in* X:**T**
*in* W:**T**
*in* R:**T**
*in* B:**T**
*in* sequence_lens:**T1**
*in* initial_h:**T**
*in* initial_c:**T**
*in* P:**T**
*in* QW:**T**
*in* MW:**T**
*in* V:**T**
*in* M:**T**
*in* memory_seq_lens:**T1**
*in* AW:**T**
*out* Y:**T**
*out* Y_h:**T**
*out* Y_c:**T**|1+|**T** = tensor(double), tensor(float)
**T1** = tensor(int32)| +|BiasGelu|*in* A:**T**
*in* B:**T**
*out* C:**T**|1+|**T** = tensor(float)| +|BifurcationDetector|*in* src_tokens:**T**
*in* cur_tokens:**T**
*in* prev_suffix_match_idx:**T**
*in* pred_tokens:**T**
*out* tokens:**T**
*out* suffix_match_idx:**T**|1+|**T** = tensor(int64)| +|CDist|*in* A:**T**
*in* B:**T**
*out* C:**T**|1+|**T** = tensor(double), tensor(float)| +|ConvTransposeWithDynamicPads|*in* X:**T**
*in* W:**T**
*in* Pads:**tensor(int64)**
*in* B:**T**
*out* Y:**T**|1+|**T** = tensor(float)| +|CropAndResize|*in* X:**T1**
*in* rois:**T1**
*in* batch_indices:**T2**
*in* crop_size:**T2**
*out* Y:**T1**|1+|**T** = tensor(float)
**T2** = tensor(int32)| +|DequantizeLinear|*in* x:**T1**
*in* x_scale:**T2**
*in* x_zero_point:**T1**
*out* y:**T2**|1+|**T1** = tensor(int8), tensor(uint8)
**T2** = tensor(float)| +|DynamicQuantizeLSTM|*in* X:**T**
*in* W:**T2**
*in* R:**T2**
*in* B:**T**
*in* sequence_lens:**T1**
*in* initial_h:**T**
*in* initial_c:**T**
*in* P:**T**
*in* W_scale:**T**
*in* W_zero_point:**T2**
*in* R_scale:**T**
*in* R_zero_point:**T2**
*out* Y:**T**
*out* Y_h:**T**
*out* Y_c:**T**|1+|**T** = tensor(float)
**T1** = tensor(int32)
**T2** = tensor(int8), tensor(uint8)| +|DynamicQuantizeMatMul|*in* A:**T1**
*in* B:**T2**
*in* b_scale:**T1**
*in* b_zero_point:**T2**
*in* bias:**T1**
*out* Y:**T1**|1+|**T1** = tensor(float)
**T2** = tensor(int8), tensor(uint8)| +|EmbedLayerNormalization|*in* input_ids:**T1**
*in* segment_ids:**T1**
*in* word_embedding:**T**
*in* position_embedding:**T**
*in* segment_embedding:**T**
*in* gamma:**T**
*in* beta:**T**
*in* mask:**T1**
*in* position_ids:**T1**
*out* output:**T**
*out* mask_index:**T1**
*out* embedding_sum:**T**|1+|**T** = tensor(float)| +|ExpandDims|*in* X:**T**
*in* axis:**tensor(int32)**
*out* Y:**T**|1+|**T** = tensor(bfloat16), tensor(bool), tensor(double), tensor(float), tensor(float16), tensor(int16), tensor(int32), tensor(int64), tensor(int8), tensor(string), tensor(uint16), tensor(uint32), tensor(uint64), tensor(uint8)
**axis** = tensor(int32)| +|FastGelu|*in* X:**T**
*in* bias:**T**
*out* Y:**T**|1+|**T** = tensor(float)| +|FusedConv|*in* X:**T**
*in* W:**T**
*in* B:**T**
*in* Z:**T**
*out* Y:**T**|1+|**T** = tensor(float)| +|FusedGemm|*in* A:**T**
*in* B:**T**
*in* C:**T**
*out* Y:**T**|1+|**T** = tensor(float)| +|FusedMatMul|*in* A:**T**
*in* B:**T**
*out* Y:**T**|1+|**T** = tensor(float)| +|GatherND|*in* data:**T**
*in* indices:**Tind**
*out* output:**T**|1+|**T** = tensor(bfloat16), tensor(bool), tensor(double), tensor(float), tensor(float16), tensor(int16), tensor(int32), tensor(int64), tensor(int8), tensor(string), tensor(uint16), tensor(uint32), tensor(uint64), tensor(uint8)
**Tind** = tensor(int32), tensor(int64)| +|Gelu|*in* X:**T**
*out* Y:**T**|1+|**T** = tensor(float)| +|GridSample|*in* X:**T1**
*in* Grid:**T1**
*out* Y:**T2**|1+|**T** = tensor(float)| +|Inverse|*in* X:**T**
*out* Y:**T**|1+|**T** = tensor(double), tensor(float), tensor(float16)| +|MatMulInteger16|*in* A:**T1**
*in* B:**T2**
*out* Y:**T3**|1+|**T1** = tensor(int16)
**T2** = tensor(int16)
**T3** = tensor(int32)| +|MatMulIntegerToFloat|*in* A:**T1**
*in* B:**T2**
*in* a_scale:**T3**
*in* b_scale:**T3**
*in* a_zero_point:**T1**
*in* b_zero_point:**T2**
*in* bias:**T3**
*out* Y:**T3**|1+|**T1** = tensor(uint8)
**T2** = tensor(int8), tensor(uint8)
**T3** = tensor(float)| +|MaxpoolWithMask|*in* X:**T**
*in* M:**tensor(int32)**
*out* Y:**T**|1+|**X** = tensor(float)| +|MurmurHash3|*in* X:**T1**
*out* Y:**T2**|1+|**T1** = tensor(double), tensor(float), tensor(int32), tensor(int64), tensor(string), tensor(uint32), tensor(uint64)
**T2** = tensor(int32), tensor(uint32)| +|NGramRepeatBlock|*in* input_ids:**Tid**
*in* scores:**T**
*out* scores_out:**T**|1+|**T** = tensor(float)
**Tid** = tensor(int64)| +|NhwcMaxPool|*in* x:**T**
*out* y:**T**|1+|**T** = tensor(int8), tensor(uint8)| +|Pad|*in* data:**T**
*in* pads:**tensor(int64)**
*in* value:**T**
*out* output:**T**|1+|**T** = tensor(float)| +|QAttention|*in* input:**T1**
*in* weight:**T2**
*in* bias:**T3**
*in* input_scale:**T3**
*in* weight_scale:**T3**
*in* mask_index:**T4**
*in* input_zero_point:**T1**
*in* weight_zero_point:**T2**
*in* past:**T3**
*out* output:**T3**
*out* present:**T3**|1+|**T1** = tensor(uint8)
**T2** = tensor(int8), tensor(uint8)
**T3** = tensor(float)
**T4** = tensor(int32)| +|QEmbedLayerNormalization|*in* input_ids:**T1**
*in* segment_ids:**T1**
*in* word_embedding_quant:**T2**
*in* position_embedding_quant:**T2**
*in* segment_embedding:**T2**
*in* gamma_quant:**T2**
*in* beta_quant:**T2**
*in* mask:**T1**
*in* word_embedding_scale:**T**
*in* position_embedding_scale:**T**
*in* segment_embedding_scale:**T**
*in* gamma_scale:**T**
*in* beta_scale:**T**
*in* word_embedding_zero_point:**T2**
*in* position_embedding_zero_point:**T2**
*in* segment_embedding_zero_point:**T2**
*in* gamma_zero_point:**T2**
*in* beta_zero_point:**T2**
*out* layernorm_out:**T**
*out* mask_index_out:**T1**|1+|**T** = tensor(float)| +|QGemm|*in* A:**TA**
*in* a_scale:**T**
*in* a_zero_point:**TA**
*in* B:**TB**
*in* b_scale:**T**
*in* b_zero_point:**TB**
*in* C:**TC**
*in* y_scale:**T**
*in* y_zero_point:**TYZ**
*out* Y:**TY**|1+|**T** = tensor(float)
**TA** = tensor(uint8)
**TB** = tensor(int8), tensor(uint8)
**TC** = tensor(int32)
**TY** = tensor(float), tensor(uint8)
**TYZ** = tensor(uint8)| +|QLinearAdd|*in* A:**T**
*in* A_scale:**tensor(float)**
*in* A_zero_point:**T**
*in* B:**T**
*in* B_scale:**tensor(float)**
*in* B_zero_point:**T**
*in* C_scale:**tensor(float)**
*in* C_zero_point:**T**
*out* C:**T**|1+|**T** = tensor(int8), tensor(uint8)| +|QLinearConv|*in* x:**T1**
*in* x_scale:**tensor(float)**
*in* x_zero_point:**T1**
*in* w:**T2**
*in* w_scale:**tensor(float)**
*in* w_zero_point:**T2**
*in* y_scale:**tensor(float)**
*in* y_zero_point:**T3**
*in* B:**T4**
*out* y:**T3**|1+|**T1** = tensor(uint8)
**T2** = tensor(int8), tensor(uint8)
**T3** = tensor(uint8)
**T4** = tensor(int32)| +|QLinearLeakyRelu|*in* X:**T**
*in* X_scale:**tensor(float)**
*in* X_zero_point:**T**
*in* Y_scale:**tensor(float)**
*in* Y_zero_point:**T**
*out* Y:**T**|1+|**T** = tensor(int8), tensor(uint8)| +|QLinearMul|*in* A:**T**
*in* A_scale:**tensor(float)**
*in* A_zero_point:**T**
*in* B:**T**
*in* B_scale:**tensor(float)**
*in* B_zero_point:**T**
*in* C_scale:**tensor(float)**
*in* C_zero_point:**T**
*out* C:**T**|1+|**T** = tensor(int8), tensor(uint8)| +|QLinearSigmoid|*in* X:**T**
*in* X_scale:**tensor(float)**
*in* X_zero_point:**T**
*in* Y_scale:**tensor(float)**
*in* Y_zero_point:**T**
*out* Y:**T**|1+|**T** = tensor(int8), tensor(uint8)| +|QuantizeLinear|*in* x:**T1**
*in* y_scale:**T1**
*in* y_zero_point:**T2**
*out* y:**T2**|1+|**T1** = tensor(float)
**T2** = tensor(int8), tensor(uint8)| +|Range|*in* start:**T**
*in* limit:**T**
*in* delta:**T**
*out* Y:**T**|1+|**T** = tensor(double), tensor(float), tensor(int16), tensor(int32), tensor(int64)| +|SampleOp|*in* X:**T**
*out* Y:**T**|1+|**T** = tensor(float)| +|SkipLayerNormalization|*in* input:**T**
*in* skip:**T**
*in* gamma:**T**
*in* beta:**T**
*in* bias:**T**
*out* output:**T**
*out* mean:**U**
*out* inv_std_var:**U**|1+|**T** = tensor(double), tensor(float)| +|SparseToDenseMatMul|*in* A:**T**
*in* B:**T1**
*out* Y:**T1**|1+|**T** = sparse_tensor(double), sparse_tensor(float), sparse_tensor(int32), sparse_tensor(int64), sparse_tensor(uint32), sparse_tensor(uint64)
**T1** = tensor(double), tensor(float), tensor(int32), tensor(int64), tensor(uint32), tensor(uint64)| +|Tokenizer|*in* X:**T**
*out* Y:**T**|1+|**T** = tensor(string)| +|TransposeMatMul|*in* A:**T**
*in* B:**T**
*out* Y:**T**|1+|**T** = tensor(float)| +|Trilu|*in* X:**T**
*in* k:**tensor(int64)**
*out* Y:**T**|1+|**T** = tensor(double), tensor(float), tensor(int64)| +|Unique|*in* x:**T**
*out* y:**T**
*out* idx:**tensor(int64)**
*out* counts:**tensor(int64)**|1+|**T** = tensor(float)| +|WordConvEmbedding|*in* Sequence:**T**
*in* W:**T1**
*in* B:**T1**
*in* C:**T1**
*out* Y:**T1**|1+|**T** = tensor(int32)
**T1** = tensor(float)| +| | +| | +|**Operator Domain:** *com.microsoft.nchwc*|||| +|AveragePool|*in* X:**T**
*out* Y:**T**|1+|**T** = tensor(float)| +|Conv|*in* X:**T**
*in* W:**T**
*in* B:**T**
*in* Sum:**T**
*out* Y:**T**|1+|**T** = tensor(float)| +|GlobalAveragePool|*in* X:**T**
*out* Y:**T**|1+|**T** = tensor(float)| +|GlobalMaxPool|*in* X:**T**
*out* Y:**T**|1+|**T** = tensor(float)| +|MaxPool|*in* X:**T**
*out* Y:**T**|1+|**T** = tensor(float)| +|ReorderInput|*in* X:**T**
*out* Y:**T**|1+|**T** = tensor(float)| +|ReorderOutput|*in* X:**T**
*out* Y:**T**|1+|**T** = tensor(float)| +|Upsample|*in* X:**T**
*out* Y:**T**|1+|**T** = tensor(float)| +| | +| | + + +
+ +## Operators implemented by CUDAExecutionProvider + +| Op Name | Parameters | OpSet Version | Types Supported | +|---------|------------|---------------|-----------------| +|**Operator Domain:** *ai.onnx*|||| +|Abs|*in* X:**T**
*out* Y:**T**|13+|**T** = tensor(double), tensor(float), tensor(float16), tensor(int16), tensor(int32), tensor(int64), tensor(int8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(uint8)| +|||[6, 12]|**T** = tensor(double), tensor(float), tensor(float16), tensor(int16), tensor(int32), tensor(int64), tensor(int8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(uint8)| +|Add|*in* A:**T**
*in* B:**T**
*out* C:**T**|14+|**T** = tensor(bfloat16), tensor(double), tensor(float), tensor(float16), tensor(int32), tensor(int64), tensor(uint32), tensor(uint64)| +|||13|**T** = tensor(bfloat16), tensor(double), tensor(float), tensor(float16), tensor(int32), tensor(int64), tensor(uint32), tensor(uint64)| +|||[7, 12]|**T** = tensor(double), tensor(float), tensor(float16), tensor(int32), tensor(int64), tensor(uint32), tensor(uint64)| +|Affine|*in* X:**T**
*out* Y:**T**|1+|**T** = tensor(double), tensor(float), tensor(float16)| +|And|*in* A:**T**
*in* B:**T**
*out* C:**T1**|7+|**T** = tensor(bool)
**T1** = tensor(bool)| +|ArgMax|*in* data:**T**
*out* reduced:**tensor(int64)**|11+|**T** = tensor(double), tensor(float), tensor(float16)| +|||[1, 10]|**T** = tensor(double), tensor(float), tensor(float16)| +|ArgMin|*in* data:**T**
*out* reduced:**tensor(int64)**|11+|**T** = tensor(double), tensor(float), tensor(float16)| +|||[1, 10]|**T** = tensor(double), tensor(float), tensor(float16)| +|AveragePool|*in* X:**T**
*out* Y:**T**|11+|**T** = tensor(double), tensor(float), tensor(float16)| +|||10|**I** = tensor(int64)
**T** = tensor(double), tensor(float), tensor(float16)| +|||[7, 9]|**I** = tensor(int64)
**T** = tensor(double), tensor(float), tensor(float16)| +|BatchNormalization|*in* X:**T**
*in* scale:**T**
*in* B:**T**
*in* input_mean:**U**
*in* input_var:**U**
*out* Y:**T**
*out* running_mean:**U**
*out* running_var:**U**

or

*in* X:**T**
*in* scale:**T**
*in* B:**T**
*in* mean:**T**
*in* var:**T**
*out* Y:**T**
*out* mean:**T**
*out* var:**T**
*out* saved_mean:**T**
*out* saved_var:**T**

or

*in* X:**T**
*in* scale:**T1**
*in* B:**T1**
*in* input_mean:**T2**
*in* input_var:**T2**
*out* Y:**T**
*out* running_mean:**T2**
*out* running_var:**T2**|15+|**T** = tensor(double), tensor(float), tensor(float16)
**T1** = tensor(double), tensor(float), tensor(float16)
**T2** = tensor(double), tensor(float), tensor(float16)| +|||14|**T** = tensor(double), tensor(float), tensor(float16)
**U** = tensor(double), tensor(float), tensor(float16)| +|||[9, 13]|**T** = tensor(double), tensor(float), tensor(float16)| +|||[7, 8]|**T** = tensor(double), tensor(float), tensor(float16)| +|Cast|*in* input:**T1**
*out* output:**T2**|13+|**T1** = tensor(bfloat16), tensor(bool), tensor(double), tensor(float), tensor(float16), tensor(int16), tensor(int32), tensor(int64), tensor(int8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(uint8)
**T2** = tensor(bfloat16), tensor(bool), tensor(double), tensor(float), tensor(float16), tensor(int16), tensor(int32), tensor(int64), tensor(int8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(uint8)| +|||[9, 12]|**T1** = tensor(bool), tensor(double), tensor(float), tensor(float16), tensor(int16), tensor(int32), tensor(int64), tensor(int8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(uint8)
**T2** = tensor(bfloat16), tensor(bool), tensor(double), tensor(float), tensor(float16), tensor(int16), tensor(int32), tensor(int64), tensor(int8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(uint8)| +|||[6, 8]|**T1** = tensor(bool), tensor(double), tensor(float), tensor(float16), tensor(int16), tensor(int32), tensor(int64), tensor(int8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(uint8)
**T2** = tensor(bfloat16), tensor(bool), tensor(double), tensor(float), tensor(float16), tensor(int16), tensor(int32), tensor(int64), tensor(int8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(uint8)| +|Ceil|*in* X:**T**
*out* Y:**T**|13+|**T** = tensor(double), tensor(float), tensor(float16)| +|||[6, 12]|**T** = tensor(double), tensor(float), tensor(float16)| +|Clip|*in* input:**T**
*in* min:**T**
*in* max:**T**
*out* output:**T**

or

*in* input:**T**
*out* output:**T**|13+|**T** = tensor(double), tensor(float), tensor(float16), tensor(int64), tensor(int8), tensor(uint64), tensor(uint8)| +|||12|**T** = tensor(double), tensor(float), tensor(float16), tensor(int64), tensor(int8), tensor(uint64), tensor(uint8)| +|||11|**T** = tensor(float)| +|||[6, 10]|**T** = tensor(float)| +|Compress|*in* input:**T**
*in* condition:**T1**
*out* output:**T**|11+|**T** = tensor(bfloat16), tensor(bool), tensor(double), tensor(float), tensor(float16), tensor(int16), tensor(int32), tensor(int64), tensor(int8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(uint8)
**T1** = tensor(bool)| +|||[9, 10]|**T** = tensor(bfloat16), tensor(bool), tensor(double), tensor(float), tensor(float16), tensor(int16), tensor(int32), tensor(int64), tensor(int8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(uint8)
**T1** = tensor(bool)| +|Concat|*in* inputs:**T**
*out* concat_result:**T**|13+|**T** = tensor(bfloat16), tensor(bool), tensor(double), tensor(float), tensor(float16), tensor(int16), tensor(int32), tensor(int64), tensor(int8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(uint8)| +|||[11, 12]|**T** = tensor(bfloat16), tensor(bool), tensor(double), tensor(float), tensor(float16), tensor(int16), tensor(int32), tensor(int64), tensor(int8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(uint8)| +|||[4, 10]|**T** = tensor(bfloat16), tensor(bool), tensor(double), tensor(float), tensor(float16), tensor(int16), tensor(int32), tensor(int64), tensor(int8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(uint8)| +|ConcatFromSequence|*in* input_sequence:**S**
*out* concat_result:**T**|11+|**S** = seq(tensor(bfloat16)), seq(tensor(bool)), seq(tensor(double)), seq(tensor(float)), seq(tensor(float16)), seq(tensor(int16)), seq(tensor(int32)), seq(tensor(int64)), seq(tensor(int8)), seq(tensor(uint16)), seq(tensor(uint32)), seq(tensor(uint64)), seq(tensor(uint8))| +|ConstantOfShape|*in* input:**T1**
*out* output:**T2**|9+|**T1** = tensor(int64)
**T2** = tensor(bfloat16), tensor(bool), tensor(double), tensor(float), tensor(float16), tensor(int16), tensor(int32), tensor(int64), tensor(int8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(uint8)| +|Conv|*in* X:**T**
*in* W:**T**
*in* B:**T**
*out* Y:**T**|11+|**T** = tensor(double), tensor(float), tensor(float16)| +|||[1, 10]|**T** = tensor(double), tensor(float), tensor(float16)| +|ConvTranspose|*in* X:**T**
*in* W:**T**
*in* B:**T**
*out* Y:**T**|11+|**T** = tensor(double), tensor(float), tensor(float16)| +|||[1, 10]|**T** = tensor(double), tensor(float), tensor(float16)| +|Cos|*in* input:**T**
*out* output:**T**|7+|**T** = tensor(double), tensor(float), tensor(float16)| +|Crop|*in* input:**T**
*out* output:**T**|1+|**T** = tensor(double), tensor(float), tensor(float16)| +|CumSum|*in* x:**T**
*in* axis:**T2**
*out* y:**T**|14+|**T** = tensor(double), tensor(float), tensor(float16), tensor(int32), tensor(int64), tensor(uint32), tensor(uint64)
**T2** = tensor(int32), tensor(int64)| +|||[11, 13]|**T** = tensor(double), tensor(float), tensor(int32), tensor(int64), tensor(uint32), tensor(uint64)
**T2** = tensor(int32), tensor(int64)| +|DepthToSpace|*in* input:**T**
*out* output:**T**|13+|**T** = tensor(double), tensor(float), tensor(float16)| +|||[11, 12]|**T** = tensor(double), tensor(float), tensor(float16)| +|||[1, 10]|**T** = tensor(double), tensor(float), tensor(float16)| +|DequantizeLinear|*in* x:**T**
*in* x_scale:**tensor(float)**
*in* x_zero_point:**T**
*out* y:**tensor(float)**|10+|**T** = tensor(int8), tensor(uint8)| +|Div|*in* A:**T**
*in* B:**T**
*out* C:**T**|14+|**T** = tensor(bfloat16), tensor(double), tensor(float), tensor(float16), tensor(int32), tensor(int64), tensor(uint32), tensor(uint64)| +|||13|**T** = tensor(bfloat16), tensor(double), tensor(float), tensor(float16), tensor(int32), tensor(int64), tensor(uint32), tensor(uint64)| +|||[7, 12]|**T** = tensor(double), tensor(float), tensor(float16), tensor(int32), tensor(int64), tensor(uint32), tensor(uint64)| +|Dropout|*in* data:**T**
*in* ratio:**T1**
*in* training_mode:**T2**
*out* output:**T**
*out* mask:**T2**

or

*in* data:**T**
*out* output:**T**
*out* mask:**T**

or

*in* data:**T**
*out* output:**T**
*out* mask:**T1**|13+|**T** = tensor(bfloat16), tensor(double), tensor(float), tensor(float16)
**T1** = tensor(bfloat16), tensor(double), tensor(float), tensor(float16)
**T2** = tensor(bool)| +|||12|**T** = tensor(double), tensor(float), tensor(float16)
**T1** = tensor(double), tensor(float), tensor(float16)
**T2** = tensor(bool)| +|||[10, 11]|**T** = tensor(double), tensor(float), tensor(float16)
**T1** = tensor(bool)| +|||[7, 9]|**T** = tensor(double), tensor(float), tensor(float16)| +|DynamicSlice|*in* data:**T**
*in* starts:**Tind**
*in* ends:**Tind**
*in* axes:**Tind**
*out* output:**T**|1+|**T** = tensor(bfloat16), tensor(bool), tensor(double), tensor(float), tensor(float16), tensor(int16), tensor(int32), tensor(int64), tensor(int8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(uint8)
**Tind** = tensor(int32), tensor(int64)| +|Einsum|*in* Inputs:**T**
*out* Output:**T**|12+|**T** = tensor(double), tensor(float), tensor(float16)| +|Elu|*in* X:**T**
*out* Y:**T**|6+|**T** = tensor(double), tensor(float), tensor(float16)| +|Equal|*in* A:**T**
*in* B:**T**
*out* C:**T1**|13+|**T** = tensor(bool), tensor(double), tensor(float), tensor(float16), tensor(int32), tensor(int64), tensor(uint32), tensor(uint64)
**T1** = tensor(bool)| +|||[11, 12]|**T** = tensor(bool), tensor(double), tensor(float), tensor(float16), tensor(int32), tensor(int64), tensor(uint32), tensor(uint64)| +|||[7, 10]|**T** = tensor(bool), tensor(int32), tensor(int64)| +|Erf|*in* input:**T**
*out* output:**T**|13+|**T** = tensor(double), tensor(float), tensor(float16)| +|||[9, 12]|**T** = tensor(double), tensor(float), tensor(float16)| +|Exp|*in* input:**T**
*out* output:**T**|13+|**T** = tensor(double), tensor(float), tensor(float16)| +|||[6, 12]|**T** = tensor(double), tensor(float), tensor(float16)| +|Expand|*in* input:**T**
*in* shape:**tensor(int64)**
*out* output:**T**|13+|**T** = tensor(bfloat16), tensor(bool), tensor(double), tensor(float), tensor(float16), tensor(int16), tensor(int32), tensor(int64), tensor(int8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(uint8)| +|||[8, 12]|**T** = tensor(bfloat16), tensor(bool), tensor(double), tensor(float), tensor(float16), tensor(int16), tensor(int32), tensor(int64), tensor(int8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(uint8)| +|EyeLike|*in* input:**T1**
*out* output:**T2**|9+|**T1** = tensor(double), tensor(float), tensor(int32), tensor(int64), tensor(uint64)
**T2** = tensor(double), tensor(float), tensor(int32), tensor(int64), tensor(uint64)| +|Flatten|*in* input:**T**
*out* output:**T**|13+|**T** = tensor(bfloat16), tensor(bool), tensor(double), tensor(float), tensor(float16), tensor(int16), tensor(int32), tensor(int64), tensor(int8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(uint8)| +|||[11, 12]|**T** = tensor(bfloat16), tensor(bool), tensor(double), tensor(float), tensor(float16), tensor(int16), tensor(int32), tensor(int64), tensor(int8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(uint8)| +|||[9, 10]|**T** = tensor(bfloat16), tensor(bool), tensor(double), tensor(float), tensor(float16), tensor(int16), tensor(int32), tensor(int64), tensor(int8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(uint8)| +|||[1, 8]|**T** = tensor(bfloat16), tensor(bool), tensor(double), tensor(float), tensor(float16), tensor(int16), tensor(int32), tensor(int64), tensor(int8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(uint8)| +|Floor|*in* X:**T**
*out* Y:**T**|13+|**T** = tensor(double), tensor(float), tensor(float16)| +|||[6, 12]|**T** = tensor(double), tensor(float), tensor(float16)| +|GRU|*in* X:**T**
*in* W:**T**
*in* R:**T**
*in* B:**T**
*in* sequence_lens:**T1**
*in* initial_h:**T**
*out* Y:**T**
*out* Y_h:**T**|14+|**T** = tensor(double), tensor(float), tensor(float16)
**T1** = tensor(int32)| +|||[7, 13]|**T** = tensor(double), tensor(float), tensor(float16)
**T1** = tensor(int32)| +|Gather|*in* data:**T**
*in* indices:**Tind**
*out* output:**T**|13+|**T** = tensor(bfloat16), tensor(bool), tensor(double), tensor(float), tensor(float16), tensor(int16), tensor(int32), tensor(int64), tensor(int8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(uint8)
**Tind** = tensor(int32), tensor(int64)| +|||[11, 12]|**T** = tensor(bfloat16), tensor(bool), tensor(double), tensor(float), tensor(float16), tensor(int16), tensor(int32), tensor(int64), tensor(int8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(uint8)
**Tind** = tensor(int32), tensor(int64)| +|||[1, 10]|**T** = tensor(bfloat16), tensor(bool), tensor(double), tensor(float), tensor(float16), tensor(int16), tensor(int32), tensor(int64), tensor(int8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(uint8)
**Tind** = tensor(int32), tensor(int64)| +|GatherElements|*in* data:**T**
*in* indices:**Tind**
*out* output:**T**|13+|**T** = tensor(bfloat16), tensor(bool), tensor(double), tensor(float), tensor(float16), tensor(int16), tensor(int32), tensor(int64), tensor(int8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(uint8)
**Tind** = tensor(int32), tensor(int64)| +|||[11, 12]|**T** = tensor(bfloat16), tensor(bool), tensor(double), tensor(float), tensor(float16), tensor(int16), tensor(int32), tensor(int64), tensor(int8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(uint8)
**Tind** = tensor(int32), tensor(int64)| +|GatherND|*in* data:**T**
*in* indices:**tensor(int64)**
*out* output:**T**|13+|**T** = tensor(bfloat16), tensor(bool), tensor(double), tensor(float), tensor(float16), tensor(int64)
**Tind** = tensor(int64)| +|||12|**T** = tensor(bool), tensor(double), tensor(float), tensor(float16), tensor(int64)
**Tind** = tensor(int64)| +|Gemm|*in* A:**T**
*in* B:**T**
*in* C:**T**
*out* Y:**T**|13+|**T** = tensor(bfloat16), tensor(double), tensor(float), tensor(float16)| +|||[11, 12]|**T** = tensor(double), tensor(float), tensor(float16)| +|||[9, 10]|**T** = tensor(double), tensor(float), tensor(float16)| +|||[7, 8]|**T** = tensor(double), tensor(float), tensor(float16)| +|GlobalAveragePool|*in* X:**T**
*out* Y:**T**|1+|**T** = tensor(double), tensor(float), tensor(float16)| +|GlobalMaxPool|*in* X:**T**
*out* Y:**T**|1+|**T** = tensor(double), tensor(float), tensor(float16)| +|Greater|*in* A:**T**
*in* B:**T**
*out* C:**T1**|13+|**T** = tensor(double), tensor(float), tensor(float16), tensor(int32), tensor(int64), tensor(uint32), tensor(uint64)
**T1** = tensor(bool)| +|||[9, 12]|**T** = tensor(double), tensor(float), tensor(float16), tensor(int32), tensor(int64), tensor(uint32), tensor(uint64)| +|||[7, 8]|**T** = tensor(double), tensor(float), tensor(float16)| +|GreaterOrEqual|*in* A:**T**
*in* B:**T**
*out* C:**T1**|12+|**T** = tensor(double), tensor(float), tensor(float16), tensor(int32), tensor(int64), tensor(uint32), tensor(uint64)
**T1** = tensor(bool)| +|HardSigmoid|*in* X:**T**
*out* Y:**T**|6+|**T** = tensor(double), tensor(float), tensor(float16)| +|Identity|*in* input:**T**
*out* output:**T**

or

*in* input:**V**
*out* output:**V**|14+|**V** = seq(tensor(bfloat16)), seq(tensor(bool)), seq(tensor(double)), seq(tensor(float)), seq(tensor(float16)), seq(tensor(int16)), seq(tensor(int32)), seq(tensor(int64)), seq(tensor(int8)), seq(tensor(uint16)), seq(tensor(uint32)), seq(tensor(uint64)), seq(tensor(uint8)), tensor(bfloat16), tensor(bool), tensor(double), tensor(float), tensor(float16), tensor(int16), tensor(int32), tensor(int64), tensor(int8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(uint8)| +|||13|**T** = tensor(bfloat16), tensor(bool), tensor(double), tensor(float), tensor(float16), tensor(int16), tensor(int32), tensor(int64), tensor(int8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(uint8)| +|||[1, 12]|**T** = tensor(bfloat16), tensor(bool), tensor(double), tensor(float), tensor(float16), tensor(int16), tensor(int32), tensor(int64), tensor(int8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(uint8)| +|If|*in* cond:**B**
*out* outputs:**V**|13+|**B** = tensor(bool)
**V** = seq(tensor(bfloat16)), seq(tensor(bool)), seq(tensor(double)), seq(tensor(float)), seq(tensor(float16)), seq(tensor(int16)), seq(tensor(int32)), seq(tensor(int64)), seq(tensor(int8)), seq(tensor(string)), seq(tensor(uint16)), seq(tensor(uint32)), seq(tensor(uint64)), seq(tensor(uint8)), tensor(bfloat16), tensor(bool), tensor(double), tensor(float), tensor(float16), tensor(int16), tensor(int32), tensor(int64), tensor(int8), tensor(string), tensor(uint16), tensor(uint32), tensor(uint64), tensor(uint8)| +|||[11, 12]|**B** = tensor(bool)
**V** = tensor(bfloat16), tensor(bool), tensor(double), tensor(float), tensor(float16), tensor(int16), tensor(int32), tensor(int64), tensor(int8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(uint8)| +|||[1, 10]|**B** = tensor(bool)
**V** = tensor(bfloat16), tensor(bool), tensor(double), tensor(float), tensor(float16), tensor(int16), tensor(int32), tensor(int64), tensor(int8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(uint8)| +|ImageScaler|*in* input:**T**
*out* output:**T**|1+|**T** = tensor(double), tensor(float), tensor(float16)| +|InstanceNormalization|*in* input:**T**
*in* scale:**T**
*in* B:**T**
*out* output:**T**|6+|**T** = tensor(double), tensor(float), tensor(float16)| +|LRN|*in* X:**T**
*out* Y:**T**|13+|**T** = tensor(double), tensor(float), tensor(float16)| +|||[1, 12]|**T** = tensor(double), tensor(float), tensor(float16)| +|LSTM|*in* X:**T**
*in* W:**T**
*in* R:**T**
*in* B:**T**
*in* sequence_lens:**T1**
*in* initial_h:**T**
*in* initial_c:**T**
*in* P:**T**
*out* Y:**T**
*out* Y_h:**T**
*out* Y_c:**T**|14+|**T** = tensor(double), tensor(float), tensor(float16)
**T1** = tensor(int32)| +|||[7, 13]|**T** = tensor(double), tensor(float), tensor(float16)
**T1** = tensor(int32)| +|LayerNormalization|*in* X:**T**
*in* Scale:**T**
*in* B:**T**
*out* Y:**T**
*out* Mean:**U**
*out* InvStdDev:**U**|1+|**T** = tensor(bfloat16), tensor(double), tensor(float), tensor(float16)
**U** = tensor(double), tensor(float)| +|LeakyRelu|*in* X:**T**
*out* Y:**T**|6+|**T** = tensor(double), tensor(float), tensor(float16)| +|Less|*in* A:**T**
*in* B:**T**
*out* C:**T1**|13+|**T** = tensor(double), tensor(float), tensor(float16), tensor(int32), tensor(int64), tensor(uint32), tensor(uint64)
**T1** = tensor(bool)| +|||[9, 12]|**T** = tensor(double), tensor(float), tensor(float16), tensor(int32), tensor(int64), tensor(uint32), tensor(uint64)| +|||[7, 8]|**T** = tensor(double), tensor(float), tensor(float16)| +|LessOrEqual|*in* A:**T**
*in* B:**T**
*out* C:**T1**|12+|**T** = tensor(double), tensor(float), tensor(float16), tensor(int32), tensor(int64), tensor(uint32), tensor(uint64)
**T1** = tensor(bool)| +|Log|*in* input:**T**
*out* output:**T**|13+|**T** = tensor(double), tensor(float), tensor(float16)| +|||[6, 12]|**T** = tensor(double), tensor(float), tensor(float16)| +|LogSoftmax|*in* input:**T**
*out* output:**T**|13+|**T** = tensor(double), tensor(float), tensor(float16)| +|||[11, 12]|**T** = tensor(double), tensor(float), tensor(float16)| +|||[1, 10]|**T** = tensor(double), tensor(float), tensor(float16)| +|Loop|*in* M:**I**
*in* cond:**B**
*in* v_initial:**V**
*out* v_final_and_scan_outputs:**V**|13+|**B** = tensor(bool)
**I** = tensor(int64)
**V** = seq(tensor(bfloat16)), seq(tensor(bool)), seq(tensor(double)), seq(tensor(float)), seq(tensor(float16)), seq(tensor(int16)), seq(tensor(int32)), seq(tensor(int64)), seq(tensor(int8)), seq(tensor(string)), seq(tensor(uint16)), seq(tensor(uint32)), seq(tensor(uint64)), seq(tensor(uint8)), tensor(bfloat16), tensor(bool), tensor(double), tensor(float), tensor(float16), tensor(int16), tensor(int32), tensor(int64), tensor(int8), tensor(string), tensor(uint16), tensor(uint32), tensor(uint64), tensor(uint8)| +|||[11, 12]|**B** = tensor(bool)
**I** = tensor(int64)
**V** = tensor(bfloat16), tensor(bool), tensor(double), tensor(float), tensor(float16), tensor(int16), tensor(int32), tensor(int64), tensor(int8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(uint8)| +|||[1, 10]|**B** = tensor(bool)
**I** = tensor(int64)
**V** = tensor(bfloat16), tensor(bool), tensor(double), tensor(float), tensor(float16), tensor(int16), tensor(int32), tensor(int64), tensor(int8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(uint8)| +|MatMul|*in* A:**T**
*in* B:**T**
*out* Y:**T**|13+|**T** = tensor(bfloat16), tensor(double), tensor(float), tensor(float16)| +|||[9, 12]|**T** = tensor(double), tensor(float), tensor(float16)| +|||[1, 8]|**T** = tensor(double), tensor(float), tensor(float16)| +|MatMulInteger|*in* A:**T1**
*in* B:**T2**
*in* a_zero_point:**T1**
*in* b_zero_point:**T2**
*out* Y:**T3**|10+|**T1** = tensor(int8)
**T2** = tensor(int8)
**T3** = tensor(int32)| +|Max|*in* data_0:**T**
*out* max:**T**|13+|**T** = tensor(bfloat16), tensor(double), tensor(float), tensor(float16), tensor(int32), tensor(int64), tensor(uint32), tensor(uint64)| +|||12|**T** = tensor(bfloat16), tensor(double), tensor(float), tensor(float16), tensor(int32), tensor(int64), tensor(uint32), tensor(uint64)| +|||[6, 11]|**T** = tensor(bfloat16), tensor(double), tensor(float), tensor(float16)| +|MaxPool|*in* X:**T**
*out* Y:**T**

or

*in* X:**T**
*out* Y:**T**
*out* Indices:**I**|12+|**T** = tensor(double), tensor(float), tensor(float16), tensor(int8), tensor(uint8)| +|||11|**I** = tensor(int64)
**T** = tensor(double), tensor(float), tensor(float16)| +|||10|**I** = tensor(int64)
**T** = tensor(double), tensor(float), tensor(float16)| +|||[8, 9]|**I** = tensor(int64)
**T** = tensor(double), tensor(float), tensor(float16)| +|||[1, 7]|**I** = tensor(int64)
**T** = tensor(double), tensor(float), tensor(float16)| +|MemcpyFromHost|*in* X:**T**
*out* Y:**T**|1+|**T** = seq(tensor(bfloat16)), seq(tensor(bool)), seq(tensor(double)), seq(tensor(float)), seq(tensor(float16)), seq(tensor(int16)), seq(tensor(int32)), seq(tensor(int64)), seq(tensor(int8)), seq(tensor(uint16)), seq(tensor(uint32)), seq(tensor(uint64)), seq(tensor(uint8)), tensor(bfloat16), tensor(bool), tensor(double), tensor(float), tensor(float16), tensor(int16), tensor(int32), tensor(int64), tensor(int8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(uint8)| +|MemcpyToHost|*in* X:**T**
*out* Y:**T**|1+|**T** = seq(tensor(bfloat16)), seq(tensor(bool)), seq(tensor(double)), seq(tensor(float)), seq(tensor(float16)), seq(tensor(int16)), seq(tensor(int32)), seq(tensor(int64)), seq(tensor(int8)), seq(tensor(uint16)), seq(tensor(uint32)), seq(tensor(uint64)), seq(tensor(uint8)), tensor(bfloat16), tensor(bool), tensor(double), tensor(float), tensor(float16), tensor(int16), tensor(int32), tensor(int64), tensor(int8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(uint8)| +|Min|*in* data_0:**T**
*out* min:**T**|13+|**T** = tensor(bfloat16), tensor(double), tensor(float), tensor(float16), tensor(int32), tensor(int64), tensor(uint32), tensor(uint64)| +|||12|**T** = tensor(bfloat16), tensor(double), tensor(float), tensor(float16), tensor(int32), tensor(int64), tensor(uint32), tensor(uint64)| +|||[6, 11]|**T** = tensor(bfloat16), tensor(double), tensor(float), tensor(float16)| +|Mul|*in* A:**T**
*in* B:**T**
*out* C:**T**|14+|**T** = tensor(bfloat16), tensor(double), tensor(float), tensor(float16), tensor(int32), tensor(int64), tensor(uint32), tensor(uint64)| +|||13|**T** = tensor(bfloat16), tensor(double), tensor(float), tensor(float16), tensor(int32), tensor(int64), tensor(uint32), tensor(uint64)| +|||[7, 12]|**T** = tensor(double), tensor(float), tensor(float16), tensor(int32), tensor(int64), tensor(uint32), tensor(uint64)| +|Neg|*in* X:**T**
*out* Y:**T**|13+|**T** = tensor(double), tensor(float), tensor(float16), tensor(int16), tensor(int32), tensor(int64), tensor(int8)| +|||[6, 12]|**T** = tensor(double), tensor(float), tensor(float16), tensor(int16), tensor(int32), tensor(int64), tensor(int8)| +|NonZero|*in* X:**T**
*out* Y:**tensor(int64)**|13+|**T** = tensor(bool), tensor(float), tensor(int32), tensor(int64), tensor(uint8)| +|||[9, 12]|**T** = tensor(bool), tensor(float), tensor(int32), tensor(int64), tensor(uint8)| +|Not|*in* X:**T**
*out* Y:**T**|1+|**T** = tensor(bool)
**T1** = tensor(bool)| +|OneHot|*in* indices:**T1**
*in* depth:**T2**
*in* values:**T3**
*out* output:**T3**|11+|**T1** = tensor(int32), tensor(int64)
**T2** = tensor(int32), tensor(int64)
**T3** = tensor(float), tensor(float16), tensor(int64)| +|Or|*in* A:**T**
*in* B:**T**
*out* C:**T1**|7+|**T** = tensor(bool)
**T1** = tensor(bool)| +|PRelu|*in* X:**T**
*in* slope:**T**
*out* Y:**T**|9+|**T** = tensor(double), tensor(float), tensor(float16)| +|||[7, 8]|**T** = tensor(double), tensor(float), tensor(float16)| +|Pad|*in* data:**T**
*in* pads:**tensor(int64)**
*in* constant_value:**T**
*out* output:**T**

or

*in* data:**T**
*out* output:**T**|13+|**T** = tensor(bool), tensor(double), tensor(float), tensor(float16)| +|||[11, 12]|**T** = tensor(double), tensor(float), tensor(float16)| +|||[2, 10]|**T** = tensor(double), tensor(float), tensor(float16)| +|ParametricSoftplus|*in* X:**T**
*out* Y:**T**|1+|**T** = tensor(double), tensor(float), tensor(float16)| +|Pow|*in* X:**T**
*in* Y:**T**
*out* Z:**T**

or

*in* X:**T**
*in* Y:**T1**
*out* Z:**T**|15+|**T** = tensor(double), tensor(float), tensor(float16), tensor(int32), tensor(int64)
**T1** = tensor(double), tensor(float), tensor(float16), tensor(int32), tensor(int64)| +|||[13, 14]|**T** = tensor(double), tensor(float), tensor(float16), tensor(int32), tensor(int64)
**T1** = tensor(double), tensor(float), tensor(float16), tensor(int32), tensor(int64)| +|||12|**T** = tensor(double), tensor(float), tensor(float16), tensor(int32), tensor(int64)
**T1** = tensor(double), tensor(float), tensor(float16), tensor(int32), tensor(int64)| +|||[7, 11]|**T** = tensor(double), tensor(float), tensor(float16)| +|QuantizeLinear|*in* x:**T1**
*in* y_scale:**tensor(float)**
*in* y_zero_point:**T2**
*out* y:**T2**|10+|**T1** = tensor(float)
**T2** = tensor(int8), tensor(uint8)| +|RNN|*in* X:**T**
*in* W:**T**
*in* R:**T**
*in* B:**T**
*in* sequence_lens:**T1**
*in* initial_h:**T**
*out* Y:**T**
*out* Y_h:**T**|14+|**T** = tensor(double), tensor(float), tensor(float16)
**T1** = tensor(int32)| +|||[7, 13]|**T** = tensor(double), tensor(float), tensor(float16)
**T1** = tensor(int32)| +|RandomNormal|*out* output:**T**|1+|**T** = tensor(double), tensor(float), tensor(float16)| +|RandomNormalLike|*in* input:**T1**
*out* output:**T2**|1+|**T1** = tensor(bfloat16), tensor(bool), tensor(double), tensor(float), tensor(float16), tensor(int16), tensor(int32), tensor(int64), tensor(int8), tensor(string), tensor(uint16), tensor(uint32), tensor(uint64), tensor(uint8)
**T2** = tensor(double), tensor(float), tensor(float16)| +|RandomUniform|*out* output:**T**|1+|**T** = tensor(double), tensor(float), tensor(float16)| +|RandomUniformLike|*in* input:**T1**
*out* output:**T2**|1+|**T1** = tensor(bfloat16), tensor(bool), tensor(double), tensor(float), tensor(float16), tensor(int16), tensor(int32), tensor(int64), tensor(int8), tensor(string), tensor(uint16), tensor(uint32), tensor(uint64), tensor(uint8)
**T2** = tensor(double), tensor(float), tensor(float16)| +|Range|*in* start:**T**
*in* limit:**T**
*in* delta:**T**
*out* output:**T**|11+|**T** = tensor(double), tensor(float), tensor(int16), tensor(int32), tensor(int64)| +|Reciprocal|*in* X:**T**
*out* Y:**T**|13+|**T** = tensor(double), tensor(float), tensor(float16)| +|||[6, 12]|**T** = tensor(double), tensor(float), tensor(float16)| +|ReduceL1|*in* data:**T**
*out* reduced:**T**|13+|**T** = tensor(double), tensor(float), tensor(float16), tensor(int32)| +|||[11, 12]|**T** = tensor(double), tensor(float), tensor(float16), tensor(int32)| +|||[1, 10]|**T** = tensor(double), tensor(float), tensor(float16), tensor(int32)| +|ReduceL2|*in* data:**T**
*out* reduced:**T**|13+|**T** = tensor(double), tensor(float), tensor(float16), tensor(int32)| +|||[11, 12]|**T** = tensor(double), tensor(float), tensor(float16), tensor(int32)| +|||[1, 10]|**T** = tensor(double), tensor(float), tensor(float16), tensor(int32)| +|ReduceLogSum|*in* data:**T**
*out* reduced:**T**|13+|**T** = tensor(double), tensor(float), tensor(float16)| +|||[11, 12]|**T** = tensor(double), tensor(float), tensor(float16)| +|||[1, 10]|**T** = tensor(double), tensor(float), tensor(float16)| +|ReduceLogSumExp|*in* data:**T**
*out* reduced:**T**|13+|**T** = tensor(double), tensor(float), tensor(float16)| +|||[11, 12]|**T** = tensor(double), tensor(float), tensor(float16)| +|||[1, 10]|**T** = tensor(double), tensor(float), tensor(float16)| +|ReduceMax|*in* data:**T**
*out* reduced:**T**|13+|**T** = tensor(double), tensor(float), tensor(float16), tensor(int32), tensor(int64), tensor(int8), tensor(uint8)| +|||12|**T** = tensor(double), tensor(float), tensor(float16), tensor(int32), tensor(int64), tensor(int8), tensor(uint8)| +|||11|**T** = tensor(double), tensor(float), tensor(float16), tensor(int32), tensor(int64)| +|||[1, 10]|**T** = tensor(double), tensor(float), tensor(float16), tensor(int32), tensor(int64)| +|ReduceMean|*in* data:**T**
*out* reduced:**T**|13+|**T** = tensor(double), tensor(float), tensor(float16), tensor(int32)| +|||[11, 12]|**T** = tensor(double), tensor(float), tensor(float16), tensor(int32)| +|||[1, 10]|**T** = tensor(double), tensor(float), tensor(float16), tensor(int32)| +|ReduceMin|*in* data:**T**
*out* reduced:**T**|14+|**T** = tensor(double), tensor(float), tensor(float16), tensor(int32), tensor(int64), tensor(int8), tensor(uint8)| +|||13|**T** = tensor(double), tensor(float), tensor(float16), tensor(int32), tensor(int64), tensor(int8), tensor(uint8)| +|||12|**T** = tensor(double), tensor(float), tensor(float16), tensor(int32), tensor(int64), tensor(int8), tensor(uint8)| +|||11|**T** = tensor(double), tensor(float), tensor(float16), tensor(int32)| +|||[1, 10]|**T** = tensor(double), tensor(float), tensor(float16), tensor(int32)| +|ReduceProd|*in* data:**T**
*out* reduced:**T**|13+|**T** = tensor(double), tensor(float), tensor(float16), tensor(int32)| +|||[11, 12]|**T** = tensor(double), tensor(float), tensor(float16), tensor(int32)| +|||[1, 10]|**T** = tensor(double), tensor(float), tensor(float16), tensor(int32)| +|ReduceSum|*in* data:**T**
*in* axes:**tensor(int64)**
*out* reduced:**T**

or

*in* data:**T**
*out* reduced:**T**|13+|**T** = tensor(bfloat16), tensor(double), tensor(float), tensor(float16), tensor(int32), tensor(int64)| +|||[11, 12]|**T** = tensor(double), tensor(float), tensor(float16), tensor(int32), tensor(int64)| +|||[1, 10]|**T** = tensor(double), tensor(float), tensor(float16), tensor(int32), tensor(int64)| +|ReduceSumSquare|*in* data:**T**
*out* reduced:**T**|13+|**T** = tensor(double), tensor(float), tensor(float16)| +|||[11, 12]|**T** = tensor(double), tensor(float), tensor(float16)| +|||[1, 10]|**T** = tensor(double), tensor(float), tensor(float16)| +|Relu|*in* X:**T**
*out* Y:**T**|14+|**T** = tensor(bfloat16), tensor(double), tensor(float), tensor(float16)| +|||13|**T** = tensor(bfloat16), tensor(double), tensor(float), tensor(float16)| +|||[6, 12]|**T** = tensor(double), tensor(float), tensor(float16)| +|Reshape|*in* data:**T**
*in* shape:**tensor(int64)**
*out* reshaped:**T**

or

*in* data:**T**
*out* reshaped:**T**|14+|**T** = tensor(bfloat16), tensor(bool), tensor(double), tensor(float), tensor(float16), tensor(int16), tensor(int32), tensor(int64), tensor(int8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(uint8)
**shape** = tensor(int64)| +|||13|**T** = tensor(bfloat16), tensor(bool), tensor(double), tensor(float), tensor(float16), tensor(int16), tensor(int32), tensor(int64), tensor(int8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(uint8)
**shape** = tensor(int64)| +|||[5, 12]|**T** = tensor(bfloat16), tensor(bool), tensor(double), tensor(float), tensor(float16), tensor(int16), tensor(int32), tensor(int64), tensor(int8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(uint8)
**shape** = tensor(int64)| +|||[1, 4]|**T** = tensor(bfloat16), tensor(bool), tensor(double), tensor(float), tensor(float16), tensor(int16), tensor(int32), tensor(int64), tensor(int8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(uint8)| +|Resize|*in* X:**T**
*in* scales:**tensor(float)**
*out* Y:**T**

or

*in* X:**T1**
*in* roi:**T2**
*in* scales:**tensor(float)**
*in* sizes:**tensor(int64)**
*out* Y:**T1**|13+|**T1** = tensor(double), tensor(float), tensor(float16), tensor(int32), tensor(uint8)| +|||[11, 12]|**T1** = tensor(double), tensor(float), tensor(float16), tensor(int32), tensor(uint8)| +|||10|**T** = tensor(double), tensor(float), tensor(float16), tensor(int32), tensor(uint8)| +|ReverseSequence|*in* input:**T**
*in* sequence_lens:**tensor(int64)**
*out* Y:**T**|10+|**T** = tensor(bfloat16), tensor(bool), tensor(double), tensor(float), tensor(float16), tensor(int16), tensor(int32), tensor(int64), tensor(int8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(uint8)| +|RoiAlign|*in* X:**T1**
*in* rois:**T1**
*in* batch_indices:**T2**
*out* Y:**T1**|10+|**T** = tensor(double), tensor(float)
**T2** = tensor(int64)| +|Round|*in* X:**T**
*out* Y:**T**|11+|**T** = tensor(double), tensor(float), tensor(float16)| +|ScaledTanh|*in* input:**T**
*out* output:**T**|1+|**T** = tensor(double), tensor(float), tensor(float16)| +|Scan|*in* initial_state_and_scan_inputs:**V**
*out* final_state_and_scan_outputs:**V**

or

*in* sequence_lens:**I**
*in* initial_state_and_scan_inputs:**V**
*out* final_state_and_scan_outputs:**V**|11+|**I** = tensor(int64)
**V** = tensor(bfloat16), tensor(bool), tensor(double), tensor(float), tensor(float16), tensor(int16), tensor(int32), tensor(int64), tensor(int8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(uint8)| +|||[9, 10]|**I** = tensor(int64)
**V** = tensor(bfloat16), tensor(bool), tensor(double), tensor(float), tensor(float16), tensor(int16), tensor(int32), tensor(int64), tensor(int8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(uint8)| +|||8|**I** = tensor(int64)
**V** = tensor(bfloat16), tensor(bool), tensor(double), tensor(float), tensor(float16), tensor(int16), tensor(int32), tensor(int64), tensor(int8), tensor(string), tensor(uint16), tensor(uint32), tensor(uint64), tensor(uint8)| +|Scatter|*in* data:**T**
*in* indices:**Tind**
*in* updates:**T**
*out* output:**T**|[9, 10]|**T** = tensor(bfloat16), tensor(bool), tensor(double), tensor(float), tensor(float16), tensor(int16), tensor(int32), tensor(int64), tensor(int8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(uint8)
**Tind** = tensor(int32), tensor(int64)| +|ScatterElements|*in* data:**T**
*in* indices:**Tind**
*in* updates:**T**
*out* output:**T**|13+|**T** = tensor(bfloat16), tensor(bool), tensor(double), tensor(float), tensor(float16), tensor(int16), tensor(int32), tensor(int64), tensor(int8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(uint8)
**Tind** = tensor(int32), tensor(int64)| +|||[11, 12]|**T** = tensor(bfloat16), tensor(bool), tensor(double), tensor(float), tensor(float16), tensor(int16), tensor(int32), tensor(int64), tensor(int8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(uint8)
**Tind** = tensor(int32), tensor(int64)| +|ScatterND|*in* data:**T**
*in* indices:**tensor(int64)**
*in* updates:**T**
*out* output:**T**|13+|**T** = tensor(bfloat16), tensor(bool), tensor(double), tensor(float), tensor(float16), tensor(int16), tensor(int32), tensor(int64), tensor(int8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(uint8)| +|||[11, 12]|**T** = tensor(bfloat16), tensor(bool), tensor(double), tensor(float), tensor(float16), tensor(int16), tensor(int32), tensor(int64), tensor(int8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(uint8)| +|Selu|*in* X:**T**
*out* Y:**T**|6+|**T** = tensor(double), tensor(float), tensor(float16)| +|SequenceAt|*in* input_sequence:**S**
*in* position:**I**
*out* tensor:**T**|11+|**I** = tensor(int32), tensor(int64)
**S** = seq(tensor(bfloat16)), seq(tensor(bool)), seq(tensor(double)), seq(tensor(float)), seq(tensor(float16)), seq(tensor(int16)), seq(tensor(int32)), seq(tensor(int64)), seq(tensor(int8)), seq(tensor(uint16)), seq(tensor(uint32)), seq(tensor(uint64)), seq(tensor(uint8))
**T** = tensor(bfloat16), tensor(bool), tensor(double), tensor(float), tensor(float16), tensor(int16), tensor(int32), tensor(int64), tensor(int8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(uint8)| +|SequenceConstruct|*in* inputs:**T**
*out* output_sequence:**S**|11+|**S** = seq(tensor(bfloat16)), seq(tensor(bool)), seq(tensor(double)), seq(tensor(float)), seq(tensor(float16)), seq(tensor(int16)), seq(tensor(int32)), seq(tensor(int64)), seq(tensor(int8)), seq(tensor(uint16)), seq(tensor(uint32)), seq(tensor(uint64)), seq(tensor(uint8))
**T** = tensor(bfloat16), tensor(bool), tensor(double), tensor(float), tensor(float16), tensor(int16), tensor(int32), tensor(int64), tensor(int8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(uint8)| +|SequenceEmpty|*out* output:**S**|11+|**S** = seq(tensor(bfloat16)), seq(tensor(bool)), seq(tensor(double)), seq(tensor(float)), seq(tensor(float16)), seq(tensor(int16)), seq(tensor(int32)), seq(tensor(int64)), seq(tensor(int8)), seq(tensor(uint16)), seq(tensor(uint32)), seq(tensor(uint64)), seq(tensor(uint8))| +|SequenceErase|*in* input_sequence:**S**
*in* position:**I**
*out* output_sequence:**S**|11+|**I** = tensor(int32), tensor(int64)
**S** = seq(tensor(bfloat16)), seq(tensor(bool)), seq(tensor(double)), seq(tensor(float)), seq(tensor(float16)), seq(tensor(int16)), seq(tensor(int32)), seq(tensor(int64)), seq(tensor(int8)), seq(tensor(uint16)), seq(tensor(uint32)), seq(tensor(uint64)), seq(tensor(uint8))| +|SequenceInsert|*in* input_sequence:**S**
*in* tensor:**T**
*in* position:**I**
*out* output_sequence:**S**|11+|**I** = tensor(int32), tensor(int64)
**S** = seq(tensor(bfloat16)), seq(tensor(bool)), seq(tensor(double)), seq(tensor(float)), seq(tensor(float16)), seq(tensor(int16)), seq(tensor(int32)), seq(tensor(int64)), seq(tensor(int8)), seq(tensor(uint16)), seq(tensor(uint32)), seq(tensor(uint64)), seq(tensor(uint8))| +|SequenceLength|*in* input_sequence:**S**
*out* length:**I**|11+|**I** = tensor(int64)
**S** = seq(tensor(bfloat16)), seq(tensor(bool)), seq(tensor(double)), seq(tensor(float)), seq(tensor(float16)), seq(tensor(int16)), seq(tensor(int32)), seq(tensor(int64)), seq(tensor(int8)), seq(tensor(uint16)), seq(tensor(uint32)), seq(tensor(uint64)), seq(tensor(uint8))| +|Shape|*in* data:**T**
*out* shape:**T1**|15+|**T** = tensor(bfloat16), tensor(bool), tensor(double), tensor(float), tensor(float16), tensor(int16), tensor(int32), tensor(int64), tensor(int8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(uint8)
**T1** = tensor(int64)| +|||[13, 14]|**T** = tensor(bfloat16), tensor(bool), tensor(double), tensor(float), tensor(float16), tensor(int16), tensor(int32), tensor(int64), tensor(int8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(uint8)
**T1** = tensor(int64)| +|||[1, 12]|**T** = tensor(bfloat16), tensor(bool), tensor(double), tensor(float), tensor(float16), tensor(int16), tensor(int32), tensor(int64), tensor(int8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(uint8)
**T1** = tensor(int64)| +|Shrink|*in* input:**T**
*out* output:**T**|9+|**T** = tensor(double), tensor(float), tensor(float16), tensor(int16), tensor(int32), tensor(int64), tensor(int8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(uint8)| +|Sigmoid|*in* X:**T**
*out* Y:**T**|13+|**T** = tensor(bfloat16), tensor(double), tensor(float), tensor(float16)| +|||[6, 12]|**T** = tensor(double), tensor(float), tensor(float16)| +|SimplifiedLayerNormalization|*in* X:**T**
*in* scale:**T**
*out* Y:**T**
*out* inv_std_var:**U**|1+|**T** = tensor(double), tensor(float), tensor(float16)
**U** = tensor(double), tensor(float)| +|Sin|*in* input:**T**
*out* output:**T**|7+|**T** = tensor(double), tensor(float), tensor(float16)| +|Size|*in* data:**T**
*out* size:**T1**|13+|**T** = tensor(bfloat16), tensor(bool), tensor(double), tensor(float), tensor(float16), tensor(int16), tensor(int32), tensor(int64), tensor(int8), tensor(string), tensor(uint16), tensor(uint32), tensor(uint64), tensor(uint8)
**T1** = tensor(int64)| +|||[1, 12]|**T** = tensor(bfloat16), tensor(bool), tensor(double), tensor(float), tensor(float16), tensor(int16), tensor(int32), tensor(int64), tensor(int8), tensor(string), tensor(uint16), tensor(uint32), tensor(uint64), tensor(uint8)
**T1** = tensor(int64)| +|Slice|*in* data:**T**
*in* starts:**Tind**
*in* ends:**Tind**
*in* axes:**Tind**
*in* steps:**Tind**
*out* output:**T**

or

*in* data:**T**
*out* output:**T**|13+|**T** = tensor(bfloat16), tensor(bool), tensor(double), tensor(float), tensor(float16), tensor(int16), tensor(int32), tensor(int64), tensor(int8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(uint8)
**Tind** = tensor(float), tensor(int32), tensor(int64)| +|||[11, 12]|**T** = tensor(bfloat16), tensor(bool), tensor(double), tensor(float), tensor(float16), tensor(int16), tensor(int32), tensor(int64), tensor(int8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(uint8)
**Tind** = tensor(float), tensor(int32), tensor(int64)| +|||10|**T** = tensor(bfloat16), tensor(bool), tensor(double), tensor(float), tensor(float16), tensor(int16), tensor(int32), tensor(int64), tensor(int8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(uint8)
**Tind** = tensor(float), tensor(int32), tensor(int64)| +|||[1, 9]|**T** = tensor(bfloat16), tensor(bool), tensor(double), tensor(float), tensor(float16), tensor(int16), tensor(int32), tensor(int64), tensor(int8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(uint8)
**Tind** = tensor(float), tensor(int32), tensor(int64)| +|Softmax|*in* input:**T**
*out* output:**T**|13+|**T** = tensor(bfloat16), tensor(double), tensor(float), tensor(float16)| +|||[11, 12]|**T** = tensor(double), tensor(float), tensor(float16)| +|||[1, 10]|**T** = tensor(double), tensor(float), tensor(float16)| +|Softplus|*in* X:**T**
*out* Y:**T**|1+|**T** = tensor(double), tensor(float), tensor(float16)| +|Softsign|*in* input:**T**
*out* output:**T**|1+|**T** = tensor(double), tensor(float), tensor(float16)| +|SpaceToDepth|*in* input:**T**
*out* output:**T**|13+|**T** = tensor(double), tensor(float), tensor(float16)| +|||[1, 12]|**T** = tensor(double), tensor(float), tensor(float16)| +|Split|*in* input:**T**
*in* split:**T**
*out* outputs...:**T**

or

*in* input:**T**
*in* split:**tensor(int64)**
*out* outputs:**T**

or

*in* input:**T**
*out* outputs:**T**|13+|**T** = tensor(bfloat16), tensor(bool), tensor(double), tensor(float), tensor(float16), tensor(int16), tensor(int32), tensor(int64), tensor(int8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(uint8)| +|||[11, 12]|**T** = tensor(bfloat16), tensor(bool), tensor(double), tensor(float), tensor(float16), tensor(int16), tensor(int32), tensor(int64), tensor(int8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(uint8)| +|||[2, 10]|**T** = tensor(bfloat16), tensor(bool), tensor(double), tensor(float), tensor(float16), tensor(int16), tensor(int32), tensor(int64), tensor(int8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(uint8)| +|Sqrt|*in* X:**T**
*out* Y:**T**|13+|**T** = tensor(double), tensor(float), tensor(float16)| +|||[6, 12]|**T** = tensor(double), tensor(float), tensor(float16)| +|Squeeze|*in* data:**T**
*in* axes:**tensor(int64)**
*out* squeezed:**T**

or

*in* data:**T**
*out* squeezed:**T**|13+|**T** = tensor(bfloat16), tensor(bool), tensor(double), tensor(float), tensor(float16), tensor(int16), tensor(int32), tensor(int64), tensor(int8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(uint8)| +|||[11, 12]|**T** = tensor(bfloat16), tensor(bool), tensor(double), tensor(float), tensor(float16), tensor(int16), tensor(int32), tensor(int64), tensor(int8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(uint8)| +|||[1, 10]|**T** = tensor(bfloat16), tensor(bool), tensor(double), tensor(float), tensor(float16), tensor(int16), tensor(int32), tensor(int64), tensor(int8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(uint8)| +|Sub|*in* A:**T**
*in* B:**T**
*out* C:**T**|14+|**T** = tensor(bfloat16), tensor(double), tensor(float), tensor(float16), tensor(int32), tensor(int64), tensor(uint32), tensor(uint64)| +|||13|**T** = tensor(bfloat16), tensor(double), tensor(float), tensor(float16), tensor(int32), tensor(int64), tensor(uint32), tensor(uint64)| +|||[7, 12]|**T** = tensor(double), tensor(float), tensor(float16), tensor(int32), tensor(int64), tensor(uint32), tensor(uint64)| +|Sum|*in* data_0:**T**
*out* sum:**T**|13+|**T** = tensor(bfloat16), tensor(double), tensor(float), tensor(float16)| +|||[8, 12]|**T** = tensor(bfloat16), tensor(double), tensor(float), tensor(float16)| +|||[6, 7]|**T** = tensor(bfloat16), tensor(double), tensor(float), tensor(float16)| +|Tanh|*in* input:**T**
*out* output:**T**|13+|**T** = tensor(bfloat16), tensor(double), tensor(float), tensor(float16)| +|||[6, 12]|**T** = tensor(double), tensor(float), tensor(float16)| +|ThresholdedRelu|*in* X:**T**
*out* Y:**T**|10+|**T** = tensor(double), tensor(float), tensor(float16)| +|||1+|**T** = tensor(double), tensor(float), tensor(float16)| +|Tile|*in* input:**T**
*in* repeats:**T1**
*out* output:**T**

or

*in* input:**T**
*in* tiles:**T**
*in* axis:**T**
*out* output:**T**|13+|**T** = tensor(double), tensor(float), tensor(float16), tensor(int32), tensor(int64)
**T1** = tensor(int64)| +|||[6, 12]|**T** = tensor(double), tensor(float), tensor(float16), tensor(int32), tensor(int64)
**T1** = tensor(int64)| +|TopK|*in* X:**T**
*in* K:**tensor(int64)**
*out* Values:**T**
*out* Indices:**I**

or

*in* X:**T**
*out* Values:**T**
*out* Indices:**I**|11+|**I** = tensor(int64)
**T** = tensor(bfloat16), tensor(bool), tensor(double), tensor(float), tensor(float16), tensor(int16), tensor(int32), tensor(int64), tensor(int8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(uint8)| +|||10|**I** = tensor(int64)
**T** = tensor(bfloat16), tensor(bool), tensor(double), tensor(float), tensor(float16), tensor(int16), tensor(int32), tensor(int64), tensor(int8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(uint8)| +|||[1, 9]|**T** = tensor(bfloat16), tensor(bool), tensor(double), tensor(float), tensor(float16), tensor(int16), tensor(int32), tensor(int64), tensor(int8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(uint8)| +|Transpose|*in* data:**T**
*out* transposed:**T**|13+|**T** = tensor(bfloat16), tensor(bool), tensor(double), tensor(float), tensor(float16), tensor(int16), tensor(int32), tensor(int64), tensor(int8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(uint8)| +|||[1, 12]|**T** = tensor(bfloat16), tensor(bool), tensor(double), tensor(float), tensor(float16), tensor(int16), tensor(int32), tensor(int64), tensor(int8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(uint8)| +|Trilu|*in* input:**T**
*in* k:**tensor(int64)**
*out* output:**T**|14+|**T** = tensor(bfloat16), tensor(bool), tensor(double), tensor(float), tensor(float16), tensor(int16), tensor(int32), tensor(int64), tensor(int8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(uint8)| +|Unsqueeze|*in* data:**T**
*in* axes:**tensor(int64)**
*out* expanded:**T**

or

*in* data:**T**
*out* expanded:**T**|13+|**T** = tensor(bfloat16), tensor(bool), tensor(double), tensor(float), tensor(float16), tensor(int16), tensor(int32), tensor(int64), tensor(int8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(uint8)| +|||[11, 12]|**T** = tensor(bfloat16), tensor(bool), tensor(double), tensor(float), tensor(float16), tensor(int16), tensor(int32), tensor(int64), tensor(int8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(uint8)| +|||[1, 10]|**T** = tensor(bfloat16), tensor(bool), tensor(double), tensor(float), tensor(float16), tensor(int16), tensor(int32), tensor(int64), tensor(int8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(uint8)| +|Upsample|*in* X:**T**
*in* scales:**tensor(float)**
*out* Y:**T**

or

*in* X:**T**
*out* Y:**T**|9|**T** = tensor(double), tensor(float), tensor(float16), tensor(int32), tensor(uint8)| +|||[7, 8]|**T** = tensor(double), tensor(float), tensor(float16), tensor(int32), tensor(uint8)| +|Where|*in* condition:**B**
*in* X:**T**
*in* Y:**T**
*out* output:**T**|9+|**B** = tensor(bool)
**T** = tensor(double), tensor(float), tensor(float16), tensor(int32), tensor(int64), tensor(uint8)| +|Xor|*in* A:**T**
*in* B:**T**
*out* C:**T1**|7+|**T** = tensor(bool)
**T1** = tensor(bool)| +| | +| | +|**Operator Domain:** *com.microsoft*|||| +|Attention|*in* input:**T**
*in* weight:**T**
*in* bias:**T**
*in* mask_index:**M**
*in* past:**T**
*in* extra_add:**T**
*out* output:**T**
*out* present:**T**|1+|**T** = tensor(float), tensor(float16)| +|BiasDropout|*in* data:**T**
*in* bias:**T**
*in* residual:**T**
*in* ratio:**T1**
*in* training_mode:**T2**
*out* output:**T**
*out* mask:**T2**|1+|**T** = tensor(bfloat16), tensor(double), tensor(float), tensor(float16)
**T1** = tensor(bfloat16), tensor(double), tensor(float), tensor(float16)
**T2** = tensor(bool)| +|BiasGelu|*in* A:**T**
*in* B:**T**
*out* C:**T**|1+|**T** = tensor(double), tensor(float), tensor(float16)| +|BiasSoftmax|*in* data:**T**
*in* bias:**T**
*out* output:**T**|1+|**T** = tensor(double), tensor(float), tensor(float16)| +|ComplexMul|*in* A:**T**
*in* B:**T**
*out* C:**T**|1+|**T** = tensor(float), tensor(float16)| +|ComplexMulConj|*in* A:**T**
*in* B:**T**
*out* C:**T**|1+|**T** = tensor(float), tensor(float16)| +|ConvTransposeWithDynamicPads|*in* X:**T**
*in* W:**T**
*in* Pads:**tensor(int64)**
*in* B:**T**
*out* Y:**T**|1+|**T** = tensor(float)| +|DecoderAttention|*in* query:**T**
*in* key:**T**
*in* q_weight:**T**
*in* kv_weight:**T**
*in* bias:**T**
*in* key_padding_mask:**B**
*in* key_cache:**T**
*in* value_cache:**T**
*in* static_kv:**B**
*in* use_past:**B**
*in* has_layer_state:**B**
*in* has_key_padding_mask:**B**
*out* output:**T**
*out* new_key_cache:**T**
*out* new_value_cache:**T**|1+|**T** = tensor(float), tensor(float16)| +|DequantizeLinear|*in* x:**T1**
*in* x_scale:**T2**
*in* x_zero_point:**T1**
*out* y:**T2**|1+|**T1** = tensor(int8), tensor(uint8)
**T2** = tensor(float16)| +|EmbedLayerNormalization|*in* input_ids:**T1**
*in* segment_ids:**T1**
*in* word_embedding:**T**
*in* position_embedding:**T**
*in* segment_embedding:**T**
*in* gamma:**T**
*in* beta:**T**
*in* mask:**T1**
*in* position_ids:**T1**
*out* output:**T**
*out* mask_index:**T1**
*out* embedding_sum:**T**|1+|**T** = tensor(float), tensor(float16)| +|FastGelu|*in* X:**T**
*in* bias:**T**
*out* Y:**T**|1+|**T** = tensor(bfloat16), tensor(float), tensor(float16)| +|FusedConv|*in* X:**T**
*in* W:**T**
*in* B:**T**
*in* Z:**T**
*out* Y:**T**|1+|**T** = tensor(float)| +|FusedMatMul|*in* A:**T**
*in* B:**T**
*out* Y:**T**|1+|**T** = tensor(bfloat16), tensor(double), tensor(float), tensor(float16)| +|Gelu|*in* X:**T**
*out* Y:**T**|1+|**T** = tensor(double), tensor(float), tensor(float16)| +|GridSample|*in* X:**T1**
*in* Grid:**T1**
*out* Y:**T2**|1+|**T** = tensor(float)| +|Inverse|*in* X:**T**
*out* Y:**T**|1+|**T** = tensor(double), tensor(float), tensor(float16)| +|Irfft|*in* X:**T**
*out* Y:**T**|1+|**T** = tensor(double), tensor(float), tensor(float16)| +|LongformerAttention|*in* input:**T**
*in* weight:**T**
*in* bias:**T**
*in* mask:**T**
*in* global_weight:**T**
*in* global_bias:**T**
*in* global:**G**
*out* output:**T**|1+|**T** = tensor(float), tensor(float16)| +|NGramRepeatBlock|*in* input_ids:**Tid**
*in* scores:**T**
*out* scores_out:**T**|1+|**T** = tensor(float)
**Tid** = tensor(int64)| +|QAttention|*in* input:**T1**
*in* weight:**T2**
*in* bias:**T3**
*in* input_scale:**T3**
*in* weight_scale:**T3**
*in* mask_index:**T4**
*in* input_zero_point:**T1**
*in* weight_zero_point:**T2**
*in* past:**T3**
*out* output:**T3**
*out* present:**T3**|1+|**T1** = tensor(int8)
**T2** = tensor(int8)
**T3** = tensor(float), tensor(float16)
**T4** = tensor(int32)| +|QuantizeLinear|*in* x:**T1**
*in* y_scale:**T1**
*in* y_zero_point:**T2**
*out* y:**T2**|1+|**T1** = tensor(float16)
**T2** = tensor(int8), tensor(uint8)| +|Rfft|*in* X:**T**
*out* Y:**T**|1+|**T** = tensor(double), tensor(float), tensor(float16)| +|SkipLayerNormalization|*in* input:**T**
*in* skip:**T**
*in* gamma:**T**
*in* beta:**T**
*in* bias:**T**
*out* output:**T**
*out* mean:**U**
*out* inv_std_var:**U**|1+|**T** = tensor(float), tensor(float16)| +|TransposeMatMul|*in* A:**T**
*in* B:**T**
*out* Y:**T**|1+|**T** = tensor(bfloat16), tensor(double), tensor(float), tensor(float16)| +|Trilu|*in* X:**T**
*in* k:**tensor(int64)**
*out* Y:**T**|1+|**T** = tensor(bfloat16), tensor(bool), tensor(double), tensor(float), tensor(float16), tensor(int16), tensor(int32), tensor(int64), tensor(int8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(uint8)| +| | +| | diff --git a/_doc/sphinxdoc/source/onnxmd/onnxruntime_docs/PR_Guidelines.md b/_doc/sphinxdoc/source/onnxmd/onnxruntime_docs/PR_Guidelines.md new file mode 100644 index 00000000..90004a3b --- /dev/null +++ b/_doc/sphinxdoc/source/onnxmd/onnxruntime_docs/PR_Guidelines.md @@ -0,0 +1,13 @@ +# Guidelines for creating a good pull request + +1. A PR should describe the change clearly and most importantly it should mention the motivation behind the change. Filling out the PR template should satisfy this guideline. +2. If the PR is fixing a performance issue, mention the improvement and how the measurement was done (for educational purposes). +3. Do not leave comments unresolved. If PR comments have been addressed without making the requested code changes, explicitly mark them resolved with an appropriate comment explaining why you're resolving it. If you intend to resolve it in a follow up PR, create a task and mention why this comment cannot be fixed in this PR. Leaving comments unresolved sets a wrong precedent for other contributors that it's ok to ignore comments. +4. In the interest of time, discuss the PR/comments in person/phone if it's difficult to explain in writing. Document the resolution in the PR for the educational benefit of others. Don't just mark the comment resolved saying 'based on offline discussion'. +5. Add comments, if not obvious, in the PR to help the reviewer navigate your PR faster. If this is a big change, include a short design doc (docs/ folder). +6. Unit tests are mandatory for all PRs (except when the proposed changes are already covered by existing unit tests). +7. Do not use PRs as scratch pads for development as they consume valuable build/CI cycles for every commit. Build and test your changes for at least one environment (windows/linux/mac) before creating a PR. +8. Keep it small. If the feature is big, it's best to split into multiple PRs. Modulo cosmetic changes, a PR with more than 10 files is notoriously hard to review. Be kind to the reviewers. +9. Separate cosmetic changes from functional changes by making them separate PRs. +10. The PR author is responsible for merging the changes once they're approved. +11. If you co-author a PR, seek review from someone else. Do not self-approve PRs. \ No newline at end of file diff --git a/_doc/sphinxdoc/source/onnxmd/onnxruntime_docs/Privacy.md b/_doc/sphinxdoc/source/onnxmd/onnxruntime_docs/Privacy.md new file mode 100644 index 00000000..fcc8468b --- /dev/null +++ b/_doc/sphinxdoc/source/onnxmd/onnxruntime_docs/Privacy.md @@ -0,0 +1,21 @@ +# Privacy + +## Data Collection +The software may collect information about you and your use of the software and send it to Microsoft. Microsoft may use this information to provide services and improve our products and services. You may turn off the telemetry as described in the repository. There are also some features in the software that may enable you and Microsoft to collect data from users of your applications. If you use these features, you must comply with applicable law, including providing appropriate notices to users of your applications together with a copy of Microsoft's privacy statement. Our privacy statement is located at https://go.microsoft.com/fwlink/?LinkID=824704. You can learn more about data collection and use in the help documentation and our privacy statement. Your use of the software operates as your consent to these practices. + +*** + +### Private Builds +No data collection is performed when using your private builds built from source code. + +### Official Builds +ONNX Runtime does not maintain any independent telemetry collection mechanisms outside of what is provided by the platforms it supports. However, where applicable, ONNX Runtime will take advantage of platform-supported telemetry systems to collect trace events with the goal of improving product quality. + +Currently telemetry is only implemented for Windows builds and is turned **ON** by default in the official builds distributed in their respective package management repositories ([see here](../README.md#binaries)). This may be expanded to cover other platforms in the future. Data collection is implemented via 'Platform Telemetry' per vendor platform providers (see [telemetry.h](../onnxruntime/core/platform/telemetry.h)). + +#### Technical Details +The Windows provider uses the [TraceLogging](https://docs.microsoft.com/en-us/windows/win32/tracelogging/trace-logging-about) API for its implementation. This enables ONNX Runtime trace events to be collected by the operating system, and based on user consent, this data may be periodically sent to Microsoft servers following GDPR and privacy regulations for anonymity and data access controls. + +Windows ML and onnxruntime C APIs allow Trace Logging to be turned on/off (see [API pages](../README.md#api-documentation) for details). +For information on how to enable and disable telemetry, see [C API: Telemetry](./C_API.md#telemetry). +There are equivalent APIs in the C#, Python, and Java language bindings as well. diff --git a/_doc/sphinxdoc/source/onnxmd/onnxruntime_docs/Python_Dev_Notes.md b/_doc/sphinxdoc/source/onnxmd/onnxruntime_docs/Python_Dev_Notes.md new file mode 100644 index 00000000..78804bd9 --- /dev/null +++ b/_doc/sphinxdoc/source/onnxmd/onnxruntime_docs/Python_Dev_Notes.md @@ -0,0 +1,18 @@ +# Python Dev Notes + +Each Python version uses a specific compiler version. In most cases, you should use the same compiler version for building python extensions. + +## Which Microsoft Visual C++ compiler to use with a specific Python version ? + +| Visual C++ | CPython | +|-------------|:-----------------------:| +|2015, 2017 | 3.7 | +|2015 | 3.5,3.6 | +|2010 | 3.3,3.4 | +|2008 | 2.6, 2.7, 3.0, 3.1, 3.2 | + +Currently, the official ONNXRuntime Python wheel (v1.3.0 onwards) hosted on PyPi requires [Visual C++ 2019 runtime ](https://support.microsoft.com/en-us/help/2977003/the-latest-supported-visual-c-downloads) installed on the target machine. + +If the Python wheel is built from source using the build toolset provided with Visual Studio 2017, it will work with the Visual C++ 2017 runtime. + +CPython 3.7 is distributed with a VC++ 2017 runtime. Unlike the earlier VC++ version, VC++ 2017 Runtime is binary backward compatible with VC++ 2015. Which means you could build your application with VC++ 2015 then run it with VC++ 2017 runtime. diff --git a/_doc/sphinxdoc/source/onnxmd/onnxruntime_docs/README.txt b/_doc/sphinxdoc/source/onnxmd/onnxruntime_docs/README.txt new file mode 100644 index 00000000..66cc38aa --- /dev/null +++ b/_doc/sphinxdoc/source/onnxmd/onnxruntime_docs/README.txt @@ -0,0 +1,2 @@ +Copied from +https://github.com/microsoft/onnxruntime/tree/master/docs \ No newline at end of file diff --git a/_doc/sphinxdoc/source/onnxmd/onnxruntime_docs/Reduced_Operator_Kernel_build.md b/_doc/sphinxdoc/source/onnxmd/onnxruntime_docs/Reduced_Operator_Kernel_build.md new file mode 100644 index 00000000..02e761e5 --- /dev/null +++ b/_doc/sphinxdoc/source/onnxmd/onnxruntime_docs/Reduced_Operator_Kernel_build.md @@ -0,0 +1,81 @@ +# ONNX Runtime Reduced Operator Kernel build + +In order to reduce the compiled binary size of ONNX Runtime (ORT), the operator kernels included in the build can be reduced to just the kernels required by your model/s. + +A configuration file must be created with details of the kernels that are required. + +Following that, ORT must be manually built, providing the configuration file in the `--include_ops_by_config` parameter. The build process will update the ORT kernel registration source files to exclude the unused kernels. + +See the [build instructions](https://www.onnxruntime.ai/docs/how-to/build.html#build-instructions) for more details on building ORT. + +When building ORT with a reduced set of kernel registrations, `--skip_tests` **MUST** be specified as the kernel reduction will render many of the unit tests invalid. + +NOTE: The operator exclusion logic when building with an operator reduction configuration file will only disable kernel registrations each time it runs. It will NOT re-enable previously disabled kernels. If you wish to change the list of kernels included, it is best to revert the repository to a clean state (e.g. via `git reset --hard`) before building ORT again. + +## Creating a configuration file with the required kernels + +The script in `/tools/python/create_reduced_build_config.py` should be used to create the configuration file. This file can be manually edited as needed. The configuration can be created from either ONNX or ORT format models. + +``` +create_reduced_build_config.py --help +usage: Script to create a reduced build config file from ONNX or ORT format model/s. [-h] [-f {ONNX,ORT}] [-t] model_path_or_dir config_path + +positional arguments: + model_path_or_dir Path to a single model, or a directory that will be recursively searched for models to process. + config_path Path to write configuration file to. + +optional arguments: + -h, --help show this help message and exit + -f {ONNX,ORT}, --format {ONNX,ORT} + Format of model/s to process. (default: ONNX) + -t, --enable_type_reduction + Enable tracking of the specific types that individual operators require. Operator implementations MAY support limiting the type support included + in the build to these types. Only possible with ORT format models. (default: False) +``` + +### Type reduction + +If the configuration file is created using ORT format models, the input/output types that individual operators require can be tracked if `--enable_type_reduction` is specified. This can be used to further reduce the build size if `--enable_reduced_operator_type_support` is specified when building ORT. + +ONNX format models are not guaranteed to include the required per-node type information, so cannot be used with this option. + +## Configuration file format + +The basic format of the operator reduction configuration file is `;;[,op2]...` + +e.g. +``` +#domain;opset;op1,op2... +ai.onnx;12;Add,Cast,Concat,Squeeze +``` + +The opset can match either the opset import for each model, or the initial ONNX opset that the operator version was first available in. If manually editing the configuration file, using the opset import value from the model is simplest. + +e.g. if a model imports opset 12 of ONNX, all ONNX operators in that model can be listed under opset 12 for the 'ai.onnx' domain. + +[Netron](https://netron.app/) can be used to view an ONNX model properties to discover the opset imports. +Additionally, the ONNX operator specs for [DNN](https://github.com/onnx/onnx/blob/master/docs/Operators.md) and [traditional ML](https://github.com/onnx/onnx/blob/master/docs/Operators-ml.md) operators list the individual operator versions. + +### Type reduction format + +If the types an operator implementation supports can be limited to a specific set of types, this is specified in a JSON string immediately after the operator name in the configuration file. + +**It is highly recommended that you first generate the configuration file using ORT format models with type reduction enabled in order to see which operators support type reduction, and how the entry is defined for the individual operators.** + +The required types are generally listed per input and/or output of the operator. The type information is in a map, with 'inputs' and 'outputs' keys. The value for 'inputs' or 'outputs' is a map between the index number of the input/output and the required list of types. + +For example, both the input and output types are relevant to ai.onnx:Cast. Type information for input 0 and output 0 could look like this: + `{"inputs": {"0": ["float", "int32_t"]}, "outputs": {"0": ["float", "int64_t"]}}` + +which is added directly after the operator name in the configuration file. +e.g. + `ai.onnx;12;Add,Cast{"inputs": {"0": ["float", "int32_t"]}, "outputs": {"0": ["float", "int64_t"]}},Concat,Squeeze` + +If, for example, the types of inputs 0 and 1 were important, the entry may look like this (e.g. ai.onnx:Gather): + `{"inputs": {"0": ["float", "int32_t"], "1": ["int32_t"]}}` + +Finally some operators do non-standard things and store their type information under a 'custom' key. +ai.onnx.OneHot is an example of this, where the three input types are combined into a triple. + `{"custom": [["float", "int64_t", "int64_t"], ["int64_t", "std::string", "int64_t"]]}` + +For these reasons, it is best to generate the configuration file first, and manually edit any entries if needed. diff --git a/_doc/sphinxdoc/source/onnxmd/onnxruntime_docs/ReleaseManagement.md b/_doc/sphinxdoc/source/onnxmd/onnxruntime_docs/ReleaseManagement.md new file mode 100644 index 00000000..177f0b97 --- /dev/null +++ b/_doc/sphinxdoc/source/onnxmd/onnxruntime_docs/ReleaseManagement.md @@ -0,0 +1,4 @@ +# Release Management + +Releases are versioned according to +[Versioning](Versioning.md). Official releases of ONNX Runtime are managed by the core ONNX Runtime team and packages will be published at least every 6 months. diff --git a/_doc/sphinxdoc/source/onnxmd/onnxruntime_docs/Roadmap.md b/_doc/sphinxdoc/source/onnxmd/onnxruntime_docs/Roadmap.md new file mode 100644 index 00000000..eda0ffb5 --- /dev/null +++ b/_doc/sphinxdoc/source/onnxmd/onnxruntime_docs/Roadmap.md @@ -0,0 +1,119 @@ +# ONNX Runtime Roadmap +ONNX Runtime is an active, fast-paced project backed by a strong team of Microsoft engineers and data scientists along with a worldwide community of partners and contributors. This roadmap summarizes the pending investments identified by the team to continually grow +ONNX Runtime as a robust, versatile, and high performance inference engine for DNN and traditional ML models. + +## High Level Goals +ONNX Runtime is a runtime accelerator that supports interoperable ML and DNN models based on the [ONNX](https://onnx.ai/) spec. For key technical design objectives and considerations, see [ONNX Runtime Inference High Level Design](./InferenceHighLevelDesign.md). + +We recognize the challenges involved in operationalizing ML models performantly in an agile way, and we understand that high volume production services can be highly performance-sensitive and often need to support a variety of compute targets (we experience these first-hand at Microsoft across our vast array of products and services). + +As such, our investments are directly in support of solving those challenges, focusing on areas such as: +* Platform coverage +* Extensibility and customization +* Performance (latency, memory, throughput, scale, etc) +* Model coverage +* Quality and ease of use - including backwards compatibility of models (older opsets) and APIs + +In addition to our OSS participation, we also internally use this technology in core products at Microsoft, with over 80 models in production providing an average of 2x+ performance improvement. + +## Investments +In support of the high level goals outlined above, the investment areas listed below represent our active and backlog projects, +which are largely driven by community demand and anticipated usage opportunities. We will work through our prioritized backlog as +quickly as possible, and if there are any specific features or enhancements you need, we gladly welcome community contributions for +these efforts or any of the [enhancements suggested on Github](https://github.com/microsoft/onnxruntime/issues?q=is%3Aopen+is%3Aissue+label%3Aenhancement). If you have a specific suggestion or unsupported use case, please let us +know by filing a [Github issue](https://github.com/microsoft/onnxruntime/issues). + +* **Platform coverage** - [Expanded platform compatibility](#expanded-platform-compatibility) +* **Extensibility and customization** - [Accelerators and Execution Providers](#accelerators-and-execution-providers) +* **Performance** - [Continued performance optimizations](#continued-performance-optimizations) +* **Model coverage** - [Expanded model compatibility](#expanded-model-compatibility) +* **Quality and ease of use** - [Increased integration with popular ML products](#increased-integration-with-popular-products) +--- + +### Expanded platform compatibility +ONNX Runtime already supports a wide range of architectures, platforms, and languages, and this will continue to be an active investment area to broaden the availability of the engine for varied usage. +Additionally, we understand that lightweight devices and local applications may have constraints for package size, so there is active awareness to opportunistically minimize binary size. + +#### Architectures +Supported +* X64 +* X86 +* ARM64 +* ARM32 (Limited) + +#### Platforms +Supported +* Windows 7+ +* Linux (various) +* Mac OS X +* Android (Preview) +* iOS (Preview) + + +#### Languages +Supported languages are listed in [API Documentation](../README.md#api-documentation). The core team is not actively working on other language bindings at this time. If there is a missing API, please file a request in [Issues](https://github.com/microsoft/onnxruntime/issues). Community contributions are welcome for other languages. + +### Accelerators and Execution Providers +#### New EPs +To achieve the best performance on a growing set of compute targets across cloud and the intelligent edge, we invest in and partner with hardware partners and community members to add new execution providers. The flexible pluggability of ONNX Runtime is critical to support a broad range of scenarios and compute options. + +Supported EPs are listed [here](../README.md#supported-accelerators). + + +#### CUDA operator coverage +To maximize performance potential, we will be continually adding additional CUDA implementations for supported operators. + +#### Simplify EP contributions +In addition to new execution providers, we aim to make it easy for community partners to contribute in a non-disruptive way. To support this, we are investing in improvements to the execution provider interface for easily registering new execution providers and separating out EPs from the core runtime engine. + +### Continued Performance Optimizations +Performance is a key focus for ONNX Runtime. From latency to memory utilization to CPU usage, we are constantly seeking strategies to deliver the best performance. Although DNNs are rapidly driving research areas for innovation, we acknowledge that in practice, many companies and developers are still using traditional ML frameworks for reasons ranging from expertise to privacy to legality. As such, ONNX Runtime is focused on improvements and support for both DNNs and traditional ML. + +#### Examples of projects the team is working on: +* More quantization support +* Improved multithreading (e.g. smarter work sharding, user supplied thread pools, etc) +* Graph optimizations +* Intelligent graph partitioning to maximize the value of different accelerators + +#### Optimizations for mobile and IoT Edge devices +IoT provides growing opportunity to execute ML workloads on the edge of the network, where the data is collected. However, the devices used for ML execution have different hardware specifications. To support compatibility with this group of devices, we will invest in strategies to optimize ONNX model execution across the breadth of IoT endpoints using different hardware configurations with CPUs, GPUs and custom NN ASICs. + +### Expanded model compatibility +The ONNX spec focuses on ML model interoperability rather than coverage of all operators from all frameworks. +We aim to continuously improve coverage to support popular as well as new state-of-the-art models. + +#### Spec coverage +As more operators are added to the ONNX spec, ONNX Runtime will provide implementations (default CPU and GPU-CUDA) of each to stay in compliance with the latest ONNX spec. + +This includes: +* Sparse Tensor support + +#### Investments in popular converters +We work with the OSS and ONNX community to ensure popular frameworks can export or be converted to ONNX format. +* [PyTorch export](https://pytorch.org/docs/stable/onnx.html) +* [Tensorflow-ONNX](https://github.com/onnx/tensorflow-onnx) +* [Keras-ONNX](https://github.com/onnx/keras-onnx) +* [Sklearn-ONNX](https://github.com/onnx/sklearn-onnx) +* [ONNXMLTools](https://github.com/onnx/onnxmltools/tree/master/onnxmltools/convert) (CoreML, XGBoost, LibSVM, LightGBM, SparkML) +* [ML.NET](https://github.com/dotnet/machinelearning) + +#### Improved error handling +To decrease the risk of model inferencing failures, we will improve the error handling and fallback strategies for missing types or unsupported operators. For EPs that have missing or incorrect implementations for ONNX operators, we aim to fallback or fail as gracefully as possible. + +#### Community-driven feature additions +Focusing on practicality, we take a scenario driven approach to adding additional capabilities to ONNX Runtime. + +### Increased integration with popular products +We understand that data scientists and ML engineers work with many different products and toolsets to bring complex machine learning +algorithms to life through innovative user-facing applications. We want to ensure ONNX Runtime works as seamlessly as possible with +these. If you've identified any integration ideas or opportunities and have questions or need assistance, we encourage use of Github Issues as a discussion forum. + +Some of these products include: +* [AzureML](https://docs.microsoft.com/en-us/azure/machine-learning/service/concept-onnx): simplify the process to train, convert, and deploy ONNX models to Azure +* [Model Interpretability](https://docs.microsoft.com/en-us/azure/machine-learning/service/machine-learning-interpretability-explainability): explainability for ONNX models +* [ML.NET](https://docs.microsoft.com/en-us/dotnet/machine-learning/tutorials/object-detection-onnx): inference ONNX models in .NET +* [PyTorch](https://pytorch.org/docs/stable/onnx.html): improve coverage for exporting trained models to ONNX +* [Windows](https://docs.microsoft.com/en-us/windows/ai/windows-ml/index): run ONNX models on Windows devices using the built-in Windows ML APIs. Windows ML APIs will be included in the ONNX Runtime builds and binaries to enable Windows developers to get OS-independent updates +* [SQL Database Edge](https://docs.microsoft.com/en-us/azure/sql-database-edge/deploy-onnx): predict with ONNX models in SQL Database Edge, an optimized relational database engine geared for IoT and IoT Edge deployments + +Have an idea or feature request? [Contribute](https://github.com/microsoft/onnxruntime/blob/master/CONTRIBUTING.md) or [let us know](https://github.com/microsoft/onnxruntime/blob/master/.github/ISSUE_TEMPLATE/feature_request.md)! diff --git a/_doc/sphinxdoc/source/onnxmd/onnxruntime_docs/Server.md b/_doc/sphinxdoc/source/onnxmd/onnxruntime_docs/Server.md new file mode 100644 index 00000000..0048493d --- /dev/null +++ b/_doc/sphinxdoc/source/onnxmd/onnxruntime_docs/Server.md @@ -0,0 +1,27 @@ +## Build ONNX Runtime Server on Linux + +**Deprecation Note: This feature is deprecated and no longer supported.** + +Read more about ONNX Runtime Server [here](./ONNX_Runtime_Server_Usage.md). + +### Prerequisites + +1. [golang](https://golang.org/doc/install) +2. [grpc](https://github.com/grpc/grpc/blob/master/BUILDING.md). Please be aware that the docs at "[https://grpc.io/docs/quickstart/cpp/](https://grpc.io/docs/quickstart/cpp/)" is outdated, because building with make on UNIX systems is deprecated. +3. [re2](https://github.com/google/re2) +4. cmake +5. gcc and g++ +6. onnxruntime C API binaries. Please get it from [github releases](https://github.com/microsoft/onnxruntime/releases) then extract it to your "/usr" or "/usr/local" folder. + +See [install_server_deps.sh](../tools/ci_build/github/linux/docker/scripts/install_server_deps.sh) for more details. + +### Build Instructions +``` +cd server +mkdir build +cmake -DCMAKE_BUILD_TYPE=Debug .. +make +``` + +ONNX Runtime Server supports sending logs to [rsyslog](https://www.rsyslog.com/) daemon. To enable it, please run the cmake command with an additional parameter: `-Donnxruntime_USE_SYSLOG=1`. + diff --git a/_doc/sphinxdoc/source/onnxmd/onnxruntime_docs/Versioning.md b/_doc/sphinxdoc/source/onnxmd/onnxruntime_docs/Versioning.md new file mode 100644 index 00000000..765923d8 --- /dev/null +++ b/_doc/sphinxdoc/source/onnxmd/onnxruntime_docs/Versioning.md @@ -0,0 +1,68 @@ +# Versioning + +## API +ONNX Runtime follows [Semantic Versioning 2.0](https://semver.org/) for its public API. +Each release has the form MAJOR.MINOR.PATCH, adhering to the definitions from the linked semantic versioning doc. + +## Current stable release version +The version number of the current stable release can be found +[here](../VERSION_NUMBER). + +## Release cadence +See [Release Management](ReleaseManagement.md) + +# Compatibility + +## Backwards compatibility +All versions of ONNX Runtime will support ONNX opsets all the way back to (and including) opset version 7. +In other words, if an ONNX Runtime release implements ONNX opset ver 9, it'll be able to run all +models that are stamped with ONNX opset versions in the range [7-9]. + + +### Version matrix +The following table summarizes the relationship between the ONNX Runtime version and the ONNX opset version implemented in that release. +Please note the backward compatibility notes above. +For more details on ONNX Release versions, see [this page](https://github.com/onnx/onnx/blob/master/docs/Versioning.md). + +| ONNX Runtime release version | ONNX release version | ONNX opset version | ONNX ML opset version | Supported ONNX IR version | [Windows ML Availability](https://docs.microsoft.com/en-us/windows/ai/windows-ml/release-notes/)| +|------------------------------|--------------------|--------------------|----------------------|------------------|------------------| +| 1.10.992 | **1.10** down to 1.2 | 15 | 2 | 7 | Windows AI 1.10+ | +| 1.10.0 | **1.10** down to 1.2 | 15 | 2 | 7 | Windows AI 1.10+ | +| 1.9.0 | **1.10** down to 1.2 | 15 | 2 | 7 | Windows AI 1.9+ | +| 1.8.2 | **1.9** down to 1.2 | 14 | 2 | 7 | Windows AI 1.8+ | +| 1.8.1 | **1.9** down to 1.2 | 14 | 2 | 7 | Windows AI 1.8+ | +| 1.8.0 | **1.9** down to 1.2 | 14 | 2 | 7 | Windows AI 1.8+ | +| 1.7.0 | **1.8** down to 1.2 | 13 | 2 | 7 | Windows AI 1.7+ | +| 1.6.0 | **1.8** down to 1.2 | 13 | 2 | 7 | Windows AI 1.6+ | +| 1.5.3 | **1.7** down to 1.2 | 12 | 2 | 7 | Windows AI 1.5+ | +| 1.5.2 | **1.7** down to 1.2 | 12 | 2 | 7 | Windows AI 1.5+ | +| 1.5.1 | **1.7** down to 1.2 | 12 | 2 | 7 | Windows AI 1.5+ | +| 1.4.0 | **1.7** down to 1.2 | 12 | 2 | 7 | Windows AI 1.4+ | +| 1.3.1 | **1.7** down to 1.2 | 12 | 2 | 7 | Windows AI 1.4+ | +| 1.3.0 | **1.7** down to 1.2 | 12 | 2 | 7 | Windows AI 1.3+ | +| 1.2.0
1.1.2
1.1.1
1.1.0 | **1.6** down to 1.2 | 11 | 2 | 6 | Windows AI 1.3+ | +| 1.0.0 | **1.6** down to 1.2 | 11 | 2 | 6 | Windows AI 1.3+ | +| 0.5.0 | **1.5** down to 1.2 | 10 | 1 | 5 | Windows AI 1.3+ | +| 0.4.0 | **1.5** down to 1.2 | 10 | 1 | 5 | Windows AI 1.3+ | +| 0.3.1
0.3.0 | **1.4** down to 1.2 | 9 | 1 | 3 | Windows 10 2004+ | +| 0.2.1
0.2.0 | **1.3** down to 1.2 | 8 | 1 | 3 | Windows 10 1903+ | +| 0.1.5
0.1.4 | **1.3** down to 1.2 | 8 | 1 | 3 | Windows 10 1809+ | + + +## Tool Compatibility +A variety of tools can be used to create ONNX models. Unless otherwise noted, please use the latest released version of the tools to convert/export the ONNX model. Most tools are backwards compatible and support multiple ONNX versions. Join this with the table above to evaluate ONNX Runtime compatibility. + + +|Tool|Recommended Version|Supported ONNX version(s)| +|---|---|---| +|[PyTorch](https://pytorch.org/)|[Latest stable](https://pytorch.org/get-started/locally/)|1.2-1.6| +|[ONNXMLTools](https://pypi.org/project/onnxmltools/)
CoreML, LightGBM, XGBoost, LibSVM|[Latest stable](https://github.com/onnx/onnxmltools/releases)|1.2-1.6| +|[ONNXMLTools](https://pypi.org/project/onnxmltools/)
SparkML|[Latest stable](https://github.com/onnx/onnxmltools/releases)|1.4-1.5| +|[SKLearn-ONNX](https://pypi.org/project/skl2onnx/)|[Latest stable](https://github.com/onnx/sklearn-onnx/releases)|1.2-1.6| +|[Keras-ONNX](https://pypi.org/project/keras2onnx/)|[Latest stable](https://github.com/onnx/keras-onnx/releases)|1.2-1.6| +|[Tensorflow-ONNX](https://pypi.org/project/tf2onnx/)|[Latest stable](https://github.com/onnx/tensorflow-onnx/releases)|1.2-1.6| +|[WinMLTools](https://docs.microsoft.com/en-us/windows/ai/windows-ml/convert-model-winmltools)|[Latest stable](https://pypi.org/project/winmltools/)|1.2-1.6| +|[Paddle2ONNX](https://pypi.org/project/paddle2onnx/)| [Latest stable](https://github.com/PaddlePaddle/Paddle2ONNX/releases) | 1.6-1.9 | +|[AutoML](https://docs.microsoft.com/en-us/azure/machine-learning/service/concept-automated-ml)|[1.0.39+](https://pypi.org/project/azureml-automl-core)|1.5| +| |[1.0.33](https://pypi.org/project/azureml-automl-core/1.0.33/)|1.4| + diff --git a/_doc/sphinxdoc/source/onnxmd/onnxruntime_docs/WinML_principles.md b/_doc/sphinxdoc/source/onnxmd/onnxruntime_docs/WinML_principles.md new file mode 100644 index 00000000..cf4d84a1 --- /dev/null +++ b/_doc/sphinxdoc/source/onnxmd/onnxruntime_docs/WinML_principles.md @@ -0,0 +1,32 @@ +# Contributing to Windows ML + +Window Machine Learning is a high-performance, reliable API for deploying hardware-accelerated ML inferences on Windows devices. Please visit the [Windows ML documentation](https://docs.microsoft.com/en-us/windows/ai/windows-ml/) to learn more about Windows ML. + + +## Windows ML Base Principles + +**We design and optimize for all Windows devices.** + + Our goal is to provide developers with a platform that enables new experiences that run well on all Windows devices. Our design drives innovation in the DirectX ecosystem through DirectML and gives developers the confidence that their applications will work for all Windows customers. + +**We maintain and curate the Windows ML APIs.** + + The API is designed to ensure consistency of developer’s experience across the Windows platform. We provide long-term servicing and support, and we are committed to ensuring application’s compatibility as we evolve the API. + +**Windows ML is a core component of Windows.** + + The Windows ML code is packaged and distributed with each new release of Windows. To provide consumers with high-quality products, Microsoft is responsible for distributing Windows ML and related binaries as part of Windows or standalone distributable packages. + + +## Open for Community Contributions + +We encourage community contributions to Windows ML to enhance users’ experience on Windows. We use the principles above to guide how we look at and evaluate all contributions. + +Ensure your feature request follows all these principles to help the review process and include information about the customer problem(s) the feature request addresses. + +Note: minor issues or bugs can be addressed more quickly using the [bug/performance issue request](https://github.com/microsoft/onnxruntime/issues/new/choose) rather than feature request. + +## Start your Feature Request + +If you'd like to contribute to Windows ML and engage with the community to get feedback, please review to the contributing [process details](https://github.com/microsoft/onnxruntime/blob/master/CONTRIBUTING.md) and submit a new feature request [here](https://github.com/microsoft/onnxruntime/issues/new/choose). + diff --git a/_doc/sphinxdoc/source/onnxmd/onnxruntime_docs/c_cxx/Doxyfile b/_doc/sphinxdoc/source/onnxmd/onnxruntime_docs/c_cxx/Doxyfile new file mode 100644 index 00000000..18bcf754 --- /dev/null +++ b/_doc/sphinxdoc/source/onnxmd/onnxruntime_docs/c_cxx/Doxyfile @@ -0,0 +1,2683 @@ +# Doxyfile 1.9.2 + +# This file describes the settings to be used by the documentation system +# doxygen (www.doxygen.org) for a project. +# +# All text after a double hash (##) is considered a comment and is placed in +# front of the TAG it is preceding. +# +# All text after a single hash (#) is considered a comment and will be ignored. +# The format is: +# TAG = value [value, ...] +# For lists, items can also be appended using: +# TAG += value [value, ...] +# Values that contain spaces should be placed between quotes (\" \"). + +#--------------------------------------------------------------------------- +# Project related configuration options +#--------------------------------------------------------------------------- + +# This tag specifies the encoding used for all characters in the configuration +# file that follow. The default is UTF-8 which is also the encoding used for all +# text before the first occurrence of this tag. Doxygen uses libiconv (or the +# iconv built into libc) for the transcoding. See +# https://www.gnu.org/software/libiconv/ for the list of possible encodings. +# The default value is: UTF-8. + +DOXYFILE_ENCODING = UTF-8 + +# The PROJECT_NAME tag is a single word (or a sequence of words surrounded by +# double-quotes, unless you are using Doxywizard) that should identify the +# project for which the documentation is generated. This name is used in the +# title of most generated pages and in a few other places. +# The default value is: My Project. + +PROJECT_NAME = OnnxRuntime + +# The PROJECT_NUMBER tag can be used to enter a project or revision number. This +# could be handy for archiving the generated documentation or if some version +# control system is used. + +PROJECT_NUMBER = + +# Using the PROJECT_BRIEF tag one can provide an optional one line description +# for a project that appears at the top of each page and should give viewer a +# quick idea about the purpose of the project. Keep the description short. + +PROJECT_BRIEF = + +# With the PROJECT_LOGO tag one can specify a logo or an icon that is included +# in the documentation. The maximum height of the logo should not exceed 55 +# pixels and the maximum width should not exceed 200 pixels. Doxygen will copy +# the logo to the output directory. + +PROJECT_LOGO = "../images/ONNX_Runtime_logo - Docs.png" + +# The OUTPUT_DIRECTORY tag is used to specify the (relative or absolute) path +# into which the generated documentation will be written. If a relative path is +# entered, it will be relative to the location where doxygen was started. If +# left blank the current directory will be used. + +OUTPUT_DIRECTORY = ../../build/doxygen + +# If the CREATE_SUBDIRS tag is set to YES then doxygen will create 4096 sub- +# directories (in 2 levels) under the output directory of each output format and +# will distribute the generated files over these directories. Enabling this +# option can be useful when feeding doxygen a huge amount of source files, where +# putting all generated files in the same directory would otherwise causes +# performance problems for the file system. +# The default value is: NO. + +CREATE_SUBDIRS = NO + +# If the ALLOW_UNICODE_NAMES tag is set to YES, doxygen will allow non-ASCII +# characters to appear in the names of generated files. If set to NO, non-ASCII +# characters will be escaped, for example _xE3_x81_x84 will be used for Unicode +# U+3044. +# The default value is: NO. + +ALLOW_UNICODE_NAMES = NO + +# The OUTPUT_LANGUAGE tag is used to specify the language in which all +# documentation generated by doxygen is written. Doxygen will use this +# information to generate all constant output in the proper language. +# Possible values are: Afrikaans, Arabic, Armenian, Brazilian, Catalan, Chinese, +# Chinese-Traditional, Croatian, Czech, Danish, Dutch, English (United States), +# Esperanto, Farsi (Persian), Finnish, French, German, Greek, Hungarian, +# Indonesian, Italian, Japanese, Japanese-en (Japanese with English messages), +# Korean, Korean-en (Korean with English messages), Latvian, Lithuanian, +# Macedonian, Norwegian, Persian (Farsi), Polish, Portuguese, Romanian, Russian, +# Serbian, Serbian-Cyrillic, Slovak, Slovene, Spanish, Swedish, Turkish, +# Ukrainian and Vietnamese. +# The default value is: English. + +OUTPUT_LANGUAGE = English + +# If the BRIEF_MEMBER_DESC tag is set to YES, doxygen will include brief member +# descriptions after the members that are listed in the file and class +# documentation (similar to Javadoc). Set to NO to disable this. +# The default value is: YES. + +BRIEF_MEMBER_DESC = YES + +# If the REPEAT_BRIEF tag is set to YES, doxygen will prepend the brief +# description of a member or function before the detailed description +# +# Note: If both HIDE_UNDOC_MEMBERS and BRIEF_MEMBER_DESC are set to NO, the +# brief descriptions will be completely suppressed. +# The default value is: YES. + +REPEAT_BRIEF = YES + +# This tag implements a quasi-intelligent brief description abbreviator that is +# used to form the text in various listings. Each string in this list, if found +# as the leading text of the brief description, will be stripped from the text +# and the result, after processing the whole list, is used as the annotated +# text. Otherwise, the brief description is used as-is. If left blank, the +# following values are used ($name is automatically replaced with the name of +# the entity):The $name class, The $name widget, The $name file, is, provides, +# specifies, contains, represents, a, an and the. + +ABBREVIATE_BRIEF = "The $name class" \ + "The $name widget" \ + "The $name file" \ + is \ + provides \ + specifies \ + contains \ + represents \ + a \ + an \ + the + +# If the ALWAYS_DETAILED_SEC and REPEAT_BRIEF tags are both set to YES then +# doxygen will generate a detailed section even if there is only a brief +# description. +# The default value is: NO. + +ALWAYS_DETAILED_SEC = NO + +# If the INLINE_INHERITED_MEMB tag is set to YES, doxygen will show all +# inherited members of a class in the documentation of that class as if those +# members were ordinary class members. Constructors, destructors and assignment +# operators of the base classes will not be shown. +# The default value is: NO. + +INLINE_INHERITED_MEMB = NO + +# If the FULL_PATH_NAMES tag is set to YES, doxygen will prepend the full path +# before files name in the file list and in the header files. If set to NO the +# shortest path that makes the file name unique will be used +# The default value is: YES. + +FULL_PATH_NAMES = YES + +# The STRIP_FROM_PATH tag can be used to strip a user-defined part of the path. +# Stripping is only done if one of the specified strings matches the left-hand +# part of the path. The tag can be used to show relative paths in the file list. +# If left blank the directory from which doxygen is run is used as the path to +# strip. +# +# Note that you can specify absolute paths here, but also relative paths, which +# will be relative from the directory where doxygen is started. +# This tag requires that the tag FULL_PATH_NAMES is set to YES. + +STRIP_FROM_PATH = + +# The STRIP_FROM_INC_PATH tag can be used to strip a user-defined part of the +# path mentioned in the documentation of a class, which tells the reader which +# header file to include in order to use a class. If left blank only the name of +# the header file containing the class definition is used. Otherwise one should +# specify the list of include paths that are normally passed to the compiler +# using the -I flag. + +STRIP_FROM_INC_PATH = + +# If the SHORT_NAMES tag is set to YES, doxygen will generate much shorter (but +# less readable) file names. This can be useful is your file systems doesn't +# support long names like on DOS, Mac, or CD-ROM. +# The default value is: NO. + +SHORT_NAMES = NO + +# If the JAVADOC_AUTOBRIEF tag is set to YES then doxygen will interpret the +# first line (until the first dot) of a Javadoc-style comment as the brief +# description. If set to NO, the Javadoc-style will behave just like regular Qt- +# style comments (thus requiring an explicit @brief command for a brief +# description.) +# The default value is: NO. + +JAVADOC_AUTOBRIEF = NO + +# If the JAVADOC_BANNER tag is set to YES then doxygen will interpret a line +# such as +# /*************** +# as being the beginning of a Javadoc-style comment "banner". If set to NO, the +# Javadoc-style will behave just like regular comments and it will not be +# interpreted by doxygen. +# The default value is: NO. + +JAVADOC_BANNER = NO + +# If the QT_AUTOBRIEF tag is set to YES then doxygen will interpret the first +# line (until the first dot) of a Qt-style comment as the brief description. If +# set to NO, the Qt-style will behave just like regular Qt-style comments (thus +# requiring an explicit \brief command for a brief description.) +# The default value is: NO. + +QT_AUTOBRIEF = NO + +# The MULTILINE_CPP_IS_BRIEF tag can be set to YES to make doxygen treat a +# multi-line C++ special comment block (i.e. a block of //! or /// comments) as +# a brief description. This used to be the default behavior. The new default is +# to treat a multi-line C++ comment block as a detailed description. Set this +# tag to YES if you prefer the old behavior instead. +# +# Note that setting this tag to YES also means that rational rose comments are +# not recognized any more. +# The default value is: NO. + +MULTILINE_CPP_IS_BRIEF = NO + +# By default Python docstrings are displayed as preformatted text and doxygen's +# special commands cannot be used. By setting PYTHON_DOCSTRING to NO the +# doxygen's special commands can be used and the contents of the docstring +# documentation blocks is shown as doxygen documentation. +# The default value is: YES. + +PYTHON_DOCSTRING = YES + +# If the INHERIT_DOCS tag is set to YES then an undocumented member inherits the +# documentation from any documented member that it re-implements. +# The default value is: YES. + +INHERIT_DOCS = YES + +# If the SEPARATE_MEMBER_PAGES tag is set to YES then doxygen will produce a new +# page for each member. If set to NO, the documentation of a member will be part +# of the file/class/namespace that contains it. +# The default value is: NO. + +SEPARATE_MEMBER_PAGES = NO + +# The TAB_SIZE tag can be used to set the number of spaces in a tab. Doxygen +# uses this value to replace tabs by spaces in code fragments. +# Minimum value: 1, maximum value: 16, default value: 4. + +TAB_SIZE = 4 + +# This tag can be used to specify a number of aliases that act as commands in +# the documentation. An alias has the form: +# name=value +# For example adding +# "sideeffect=@par Side Effects:^^" +# will allow you to put the command \sideeffect (or @sideeffect) in the +# documentation, which will result in a user-defined paragraph with heading +# "Side Effects:". Note that you cannot put \n's in the value part of an alias +# to insert newlines (in the resulting output). You can put ^^ in the value part +# of an alias to insert a newline as if a physical newline was in the original +# file. When you need a literal { or } or , in the value part of an alias you +# have to escape them by means of a backslash (\), this can lead to conflicts +# with the commands \{ and \} for these it is advised to use the version @{ and +# @} or use a double escape (\\{ and \\}) + +ALIASES = + +# Set the OPTIMIZE_OUTPUT_FOR_C tag to YES if your project consists of C sources +# only. Doxygen will then generate output that is more tailored for C. For +# instance, some of the names that are used will be different. The list of all +# members will be omitted, etc. +# The default value is: NO. + +OPTIMIZE_OUTPUT_FOR_C = NO + +# Set the OPTIMIZE_OUTPUT_JAVA tag to YES if your project consists of Java or +# Python sources only. Doxygen will then generate output that is more tailored +# for that language. For instance, namespaces will be presented as packages, +# qualified scopes will look different, etc. +# The default value is: NO. + +OPTIMIZE_OUTPUT_JAVA = NO + +# Set the OPTIMIZE_FOR_FORTRAN tag to YES if your project consists of Fortran +# sources. Doxygen will then generate output that is tailored for Fortran. +# The default value is: NO. + +OPTIMIZE_FOR_FORTRAN = NO + +# Set the OPTIMIZE_OUTPUT_VHDL tag to YES if your project consists of VHDL +# sources. Doxygen will then generate output that is tailored for VHDL. +# The default value is: NO. + +OPTIMIZE_OUTPUT_VHDL = NO + +# Set the OPTIMIZE_OUTPUT_SLICE tag to YES if your project consists of Slice +# sources only. Doxygen will then generate output that is more tailored for that +# language. For instance, namespaces will be presented as modules, types will be +# separated into more groups, etc. +# The default value is: NO. + +OPTIMIZE_OUTPUT_SLICE = NO + +# Doxygen selects the parser to use depending on the extension of the files it +# parses. With this tag you can assign which parser to use for a given +# extension. Doxygen has a built-in mapping, but you can override or extend it +# using this tag. The format is ext=language, where ext is a file extension, and +# language is one of the parsers supported by doxygen: IDL, Java, JavaScript, +# Csharp (C#), C, C++, Lex, D, PHP, md (Markdown), Objective-C, Python, Slice, +# VHDL, Fortran (fixed format Fortran: FortranFixed, free formatted Fortran: +# FortranFree, unknown formatted Fortran: Fortran. In the later case the parser +# tries to guess whether the code is fixed or free formatted code, this is the +# default for Fortran type files). For instance to make doxygen treat .inc files +# as Fortran files (default is PHP), and .f files as C (default is Fortran), +# use: inc=Fortran f=C. +# +# Note: For files without extension you can use no_extension as a placeholder. +# +# Note that for custom extensions you also need to set FILE_PATTERNS otherwise +# the files are not read by doxygen. When specifying no_extension you should add +# * to the FILE_PATTERNS. +# +# Note see also the list of default file extension mappings. + +EXTENSION_MAPPING = + +# If the MARKDOWN_SUPPORT tag is enabled then doxygen pre-processes all comments +# according to the Markdown format, which allows for more readable +# documentation. See https://daringfireball.net/projects/markdown/ for details. +# The output of markdown processing is further processed by doxygen, so you can +# mix doxygen, HTML, and XML commands with Markdown formatting. Disable only in +# case of backward compatibilities issues. +# The default value is: YES. + +MARKDOWN_SUPPORT = YES + +# When the TOC_INCLUDE_HEADINGS tag is set to a non-zero value, all headings up +# to that level are automatically included in the table of contents, even if +# they do not have an id attribute. +# Note: This feature currently applies only to Markdown headings. +# Minimum value: 0, maximum value: 99, default value: 5. +# This tag requires that the tag MARKDOWN_SUPPORT is set to YES. + +TOC_INCLUDE_HEADINGS = 5 + +# When enabled doxygen tries to link words that correspond to documented +# classes, or namespaces to their corresponding documentation. Such a link can +# be prevented in individual cases by putting a % sign in front of the word or +# globally by setting AUTOLINK_SUPPORT to NO. +# The default value is: YES. + +AUTOLINK_SUPPORT = YES + +# If you use STL classes (i.e. std::string, std::vector, etc.) but do not want +# to include (a tag file for) the STL sources as input, then you should set this +# tag to YES in order to let doxygen match functions declarations and +# definitions whose arguments contain STL classes (e.g. func(std::string); +# versus func(std::string) {}). This also make the inheritance and collaboration +# diagrams that involve STL classes more complete and accurate. +# The default value is: NO. + +BUILTIN_STL_SUPPORT = NO + +# If you use Microsoft's C++/CLI language, you should set this option to YES to +# enable parsing support. +# The default value is: NO. + +CPP_CLI_SUPPORT = NO + +# Set the SIP_SUPPORT tag to YES if your project consists of sip (see: +# https://www.riverbankcomputing.com/software/sip/intro) sources only. Doxygen +# will parse them like normal C++ but will assume all classes use public instead +# of private inheritance when no explicit protection keyword is present. +# The default value is: NO. + +SIP_SUPPORT = NO + +# For Microsoft's IDL there are propget and propput attributes to indicate +# getter and setter methods for a property. Setting this option to YES will make +# doxygen to replace the get and set methods by a property in the documentation. +# This will only work if the methods are indeed getting or setting a simple +# type. If this is not the case, or you want to show the methods anyway, you +# should set this option to NO. +# The default value is: YES. + +IDL_PROPERTY_SUPPORT = YES + +# If member grouping is used in the documentation and the DISTRIBUTE_GROUP_DOC +# tag is set to YES then doxygen will reuse the documentation of the first +# member in the group (if any) for the other members of the group. By default +# all members of a group must be documented explicitly. +# The default value is: NO. + +DISTRIBUTE_GROUP_DOC = NO + +# If one adds a struct or class to a group and this option is enabled, then also +# any nested class or struct is added to the same group. By default this option +# is disabled and one has to add nested compounds explicitly via \ingroup. +# The default value is: NO. + +GROUP_NESTED_COMPOUNDS = NO + +# Set the SUBGROUPING tag to YES to allow class member groups of the same type +# (for instance a group of public functions) to be put as a subgroup of that +# type (e.g. under the Public Functions section). Set it to NO to prevent +# subgrouping. Alternatively, this can be done per class using the +# \nosubgrouping command. +# The default value is: YES. + +SUBGROUPING = YES + +# When the INLINE_GROUPED_CLASSES tag is set to YES, classes, structs and unions +# are shown inside the group in which they are included (e.g. using \ingroup) +# instead of on a separate page (for HTML and Man pages) or section (for LaTeX +# and RTF). +# +# Note that this feature does not work in combination with +# SEPARATE_MEMBER_PAGES. +# The default value is: NO. + +INLINE_GROUPED_CLASSES = NO + +# When the INLINE_SIMPLE_STRUCTS tag is set to YES, structs, classes, and unions +# with only public data fields or simple typedef fields will be shown inline in +# the documentation of the scope in which they are defined (i.e. file, +# namespace, or group documentation), provided this scope is documented. If set +# to NO, structs, classes, and unions are shown on a separate page (for HTML and +# Man pages) or section (for LaTeX and RTF). +# The default value is: NO. + +INLINE_SIMPLE_STRUCTS = NO + +# When TYPEDEF_HIDES_STRUCT tag is enabled, a typedef of a struct, union, or +# enum is documented as struct, union, or enum with the name of the typedef. So +# typedef struct TypeS {} TypeT, will appear in the documentation as a struct +# with name TypeT. When disabled the typedef will appear as a member of a file, +# namespace, or class. And the struct will be named TypeS. This can typically be +# useful for C code in case the coding convention dictates that all compound +# types are typedef'ed and only the typedef is referenced, never the tag name. +# The default value is: NO. + +TYPEDEF_HIDES_STRUCT = YES + +# The size of the symbol lookup cache can be set using LOOKUP_CACHE_SIZE. This +# cache is used to resolve symbols given their name and scope. Since this can be +# an expensive process and often the same symbol appears multiple times in the +# code, doxygen keeps a cache of pre-resolved symbols. If the cache is too small +# doxygen will become slower. If the cache is too large, memory is wasted. The +# cache size is given by this formula: 2^(16+LOOKUP_CACHE_SIZE). The valid range +# is 0..9, the default is 0, corresponding to a cache size of 2^16=65536 +# symbols. At the end of a run doxygen will report the cache usage and suggest +# the optimal cache size from a speed point of view. +# Minimum value: 0, maximum value: 9, default value: 0. + +LOOKUP_CACHE_SIZE = 0 + +# The NUM_PROC_THREADS specifies the number threads doxygen is allowed to use +# during processing. When set to 0 doxygen will based this on the number of +# cores available in the system. You can set it explicitly to a value larger +# than 0 to get more control over the balance between CPU load and processing +# speed. At this moment only the input processing can be done using multiple +# threads. Since this is still an experimental feature the default is set to 1, +# which effectively disables parallel processing. Please report any issues you +# encounter. Generating dot graphs in parallel is controlled by the +# DOT_NUM_THREADS setting. +# Minimum value: 0, maximum value: 32, default value: 1. + +NUM_PROC_THREADS = 1 + +#--------------------------------------------------------------------------- +# Build related configuration options +#--------------------------------------------------------------------------- + +# If the EXTRACT_ALL tag is set to YES, doxygen will assume all entities in +# documentation are documented, even if no documentation was available. Private +# class members and static file members will be hidden unless the +# EXTRACT_PRIVATE respectively EXTRACT_STATIC tags are set to YES. +# Note: This will also disable the warnings about undocumented members that are +# normally produced when WARNINGS is set to YES. +# The default value is: NO. + +EXTRACT_ALL = YES + +# If the EXTRACT_PRIVATE tag is set to YES, all private members of a class will +# be included in the documentation. +# The default value is: NO. + +EXTRACT_PRIVATE = NO + +# If the EXTRACT_PRIV_VIRTUAL tag is set to YES, documented private virtual +# methods of a class will be included in the documentation. +# The default value is: NO. + +EXTRACT_PRIV_VIRTUAL = NO + +# If the EXTRACT_PACKAGE tag is set to YES, all members with package or internal +# scope will be included in the documentation. +# The default value is: NO. + +EXTRACT_PACKAGE = NO + +# If the EXTRACT_STATIC tag is set to YES, all static members of a file will be +# included in the documentation. +# The default value is: NO. + +EXTRACT_STATIC = NO + +# If the EXTRACT_LOCAL_CLASSES tag is set to YES, classes (and structs) defined +# locally in source files will be included in the documentation. If set to NO, +# only classes defined in header files are included. Does not have any effect +# for Java sources. +# The default value is: YES. + +EXTRACT_LOCAL_CLASSES = YES + +# This flag is only useful for Objective-C code. If set to YES, local methods, +# which are defined in the implementation section but not in the interface are +# included in the documentation. If set to NO, only methods in the interface are +# included. +# The default value is: NO. + +EXTRACT_LOCAL_METHODS = NO + +# If this flag is set to YES, the members of anonymous namespaces will be +# extracted and appear in the documentation as a namespace called +# 'anonymous_namespace{file}', where file will be replaced with the base name of +# the file that contains the anonymous namespace. By default anonymous namespace +# are hidden. +# The default value is: NO. + +EXTRACT_ANON_NSPACES = NO + +# If this flag is set to YES, the name of an unnamed parameter in a declaration +# will be determined by the corresponding definition. By default unnamed +# parameters remain unnamed in the output. +# The default value is: YES. + +RESOLVE_UNNAMED_PARAMS = YES + +# If the HIDE_UNDOC_MEMBERS tag is set to YES, doxygen will hide all +# undocumented members inside documented classes or files. If set to NO these +# members will be included in the various overviews, but no documentation +# section is generated. This option has no effect if EXTRACT_ALL is enabled. +# The default value is: NO. + +HIDE_UNDOC_MEMBERS = NO + +# If the HIDE_UNDOC_CLASSES tag is set to YES, doxygen will hide all +# undocumented classes that are normally visible in the class hierarchy. If set +# to NO, these classes will be included in the various overviews. This option +# has no effect if EXTRACT_ALL is enabled. +# The default value is: NO. + +HIDE_UNDOC_CLASSES = NO + +# If the HIDE_FRIEND_COMPOUNDS tag is set to YES, doxygen will hide all friend +# declarations. If set to NO, these declarations will be included in the +# documentation. +# The default value is: NO. + +HIDE_FRIEND_COMPOUNDS = NO + +# If the HIDE_IN_BODY_DOCS tag is set to YES, doxygen will hide any +# documentation blocks found inside the body of a function. If set to NO, these +# blocks will be appended to the function's detailed documentation block. +# The default value is: NO. + +HIDE_IN_BODY_DOCS = NO + +# The INTERNAL_DOCS tag determines if documentation that is typed after a +# \internal command is included. If the tag is set to NO then the documentation +# will be excluded. Set it to YES to include the internal documentation. +# The default value is: NO. + +INTERNAL_DOCS = NO + +# With the correct setting of option CASE_SENSE_NAMES doxygen will better be +# able to match the capabilities of the underlying filesystem. In case the +# filesystem is case sensitive (i.e. it supports files in the same directory +# whose names only differ in casing), the option must be set to YES to properly +# deal with such files in case they appear in the input. For filesystems that +# are not case sensitive the option should be be set to NO to properly deal with +# output files written for symbols that only differ in casing, such as for two +# classes, one named CLASS and the other named Class, and to also support +# references to files without having to specify the exact matching casing. On +# Windows (including Cygwin) and MacOS, users should typically set this option +# to NO, whereas on Linux or other Unix flavors it should typically be set to +# YES. +# The default value is: system dependent. + +CASE_SENSE_NAMES = NO + +# If the HIDE_SCOPE_NAMES tag is set to NO then doxygen will show members with +# their full class and namespace scopes in the documentation. If set to YES, the +# scope will be hidden. +# The default value is: NO. + +HIDE_SCOPE_NAMES = NO + +# If the HIDE_COMPOUND_REFERENCE tag is set to NO (default) then doxygen will +# append additional text to a page's title, such as Class Reference. If set to +# YES the compound reference will be hidden. +# The default value is: NO. + +HIDE_COMPOUND_REFERENCE= NO + +# If the SHOW_HEADERFILE tag is set to YES then the documentation for a class +# will show which file needs to be included to use the class. +# The default value is: YES. + +SHOW_HEADERFILE = YES + +# If the SHOW_INCLUDE_FILES tag is set to YES then doxygen will put a list of +# the files that are included by a file in the documentation of that file. +# The default value is: YES. + +SHOW_INCLUDE_FILES = NO + +# If the SHOW_GROUPED_MEMB_INC tag is set to YES then Doxygen will add for each +# grouped member an include statement to the documentation, telling the reader +# which file to include in order to use the member. +# The default value is: NO. + +SHOW_GROUPED_MEMB_INC = NO + +# If the FORCE_LOCAL_INCLUDES tag is set to YES then doxygen will list include +# files with double quotes in the documentation rather than with sharp brackets. +# The default value is: NO. + +FORCE_LOCAL_INCLUDES = NO + +# If the INLINE_INFO tag is set to YES then a tag [inline] is inserted in the +# documentation for inline members. +# The default value is: YES. + +INLINE_INFO = YES + +# If the SORT_MEMBER_DOCS tag is set to YES then doxygen will sort the +# (detailed) documentation of file and class members alphabetically by member +# name. If set to NO, the members will appear in declaration order. +# The default value is: YES. + +SORT_MEMBER_DOCS = YES + +# If the SORT_BRIEF_DOCS tag is set to YES then doxygen will sort the brief +# descriptions of file, namespace and class members alphabetically by member +# name. If set to NO, the members will appear in declaration order. Note that +# this will also influence the order of the classes in the class list. +# The default value is: NO. + +SORT_BRIEF_DOCS = NO + +# If the SORT_MEMBERS_CTORS_1ST tag is set to YES then doxygen will sort the +# (brief and detailed) documentation of class members so that constructors and +# destructors are listed first. If set to NO the constructors will appear in the +# respective orders defined by SORT_BRIEF_DOCS and SORT_MEMBER_DOCS. +# Note: If SORT_BRIEF_DOCS is set to NO this option is ignored for sorting brief +# member documentation. +# Note: If SORT_MEMBER_DOCS is set to NO this option is ignored for sorting +# detailed member documentation. +# The default value is: NO. + +SORT_MEMBERS_CTORS_1ST = NO + +# If the SORT_GROUP_NAMES tag is set to YES then doxygen will sort the hierarchy +# of group names into alphabetical order. If set to NO the group names will +# appear in their defined order. +# The default value is: NO. + +SORT_GROUP_NAMES = NO + +# If the SORT_BY_SCOPE_NAME tag is set to YES, the class list will be sorted by +# fully-qualified names, including namespaces. If set to NO, the class list will +# be sorted only by class name, not including the namespace part. +# Note: This option is not very useful if HIDE_SCOPE_NAMES is set to YES. +# Note: This option applies only to the class list, not to the alphabetical +# list. +# The default value is: NO. + +SORT_BY_SCOPE_NAME = NO + +# If the STRICT_PROTO_MATCHING option is enabled and doxygen fails to do proper +# type resolution of all parameters of a function it will reject a match between +# the prototype and the implementation of a member function even if there is +# only one candidate or it is obvious which candidate to choose by doing a +# simple string match. By disabling STRICT_PROTO_MATCHING doxygen will still +# accept a match between prototype and implementation in such cases. +# The default value is: NO. + +STRICT_PROTO_MATCHING = NO + +# The GENERATE_TODOLIST tag can be used to enable (YES) or disable (NO) the todo +# list. This list is created by putting \todo commands in the documentation. +# The default value is: YES. + +GENERATE_TODOLIST = YES + +# The GENERATE_TESTLIST tag can be used to enable (YES) or disable (NO) the test +# list. This list is created by putting \test commands in the documentation. +# The default value is: YES. + +GENERATE_TESTLIST = YES + +# The GENERATE_BUGLIST tag can be used to enable (YES) or disable (NO) the bug +# list. This list is created by putting \bug commands in the documentation. +# The default value is: YES. + +GENERATE_BUGLIST = YES + +# The GENERATE_DEPRECATEDLIST tag can be used to enable (YES) or disable (NO) +# the deprecated list. This list is created by putting \deprecated commands in +# the documentation. +# The default value is: YES. + +GENERATE_DEPRECATEDLIST= YES + +# The ENABLED_SECTIONS tag can be used to enable conditional documentation +# sections, marked by \if ... \endif and \cond +# ... \endcond blocks. + +ENABLED_SECTIONS = + +# The MAX_INITIALIZER_LINES tag determines the maximum number of lines that the +# initial value of a variable or macro / define can have for it to appear in the +# documentation. If the initializer consists of more lines than specified here +# it will be hidden. Use a value of 0 to hide initializers completely. The +# appearance of the value of individual variables and macros / defines can be +# controlled using \showinitializer or \hideinitializer command in the +# documentation regardless of this setting. +# Minimum value: 0, maximum value: 10000, default value: 30. + +MAX_INITIALIZER_LINES = 30 + +# Set the SHOW_USED_FILES tag to NO to disable the list of files generated at +# the bottom of the documentation of classes and structs. If set to YES, the +# list will mention the files that were used to generate the documentation. +# The default value is: YES. + +SHOW_USED_FILES = NO + +# Set the SHOW_FILES tag to NO to disable the generation of the Files page. This +# will remove the Files entry from the Quick Index and from the Folder Tree View +# (if specified). +# The default value is: YES. + +SHOW_FILES = NO + +# Set the SHOW_NAMESPACES tag to NO to disable the generation of the Namespaces +# page. This will remove the Namespaces entry from the Quick Index and from the +# Folder Tree View (if specified). +# The default value is: YES. + +SHOW_NAMESPACES = YES + +# The FILE_VERSION_FILTER tag can be used to specify a program or script that +# doxygen should invoke to get the current version for each file (typically from +# the version control system). Doxygen will invoke the program by executing (via +# popen()) the command command input-file, where command is the value of the +# FILE_VERSION_FILTER tag, and input-file is the name of an input file provided +# by doxygen. Whatever the program writes to standard output is used as the file +# version. For an example see the documentation. + +FILE_VERSION_FILTER = + +# The LAYOUT_FILE tag can be used to specify a layout file which will be parsed +# by doxygen. The layout file controls the global structure of the generated +# output files in an output format independent way. To create the layout file +# that represents doxygen's defaults, run doxygen with the -l option. You can +# optionally specify a file name after the option, if omitted DoxygenLayout.xml +# will be used as the name of the layout file. See also section "Changing the +# layout of pages" for information. +# +# Note that if you run doxygen from a directory containing a file called +# DoxygenLayout.xml, doxygen will parse it automatically even if the LAYOUT_FILE +# tag is left empty. + +LAYOUT_FILE = + +# The CITE_BIB_FILES tag can be used to specify one or more bib files containing +# the reference definitions. This must be a list of .bib files. The .bib +# extension is automatically appended if omitted. This requires the bibtex tool +# to be installed. See also https://en.wikipedia.org/wiki/BibTeX for more info. +# For LaTeX the style of the bibliography can be controlled using +# LATEX_BIB_STYLE. To use this feature you need bibtex and perl available in the +# search path. See also \cite for info how to create references. + +CITE_BIB_FILES = + +#--------------------------------------------------------------------------- +# Configuration options related to warning and progress messages +#--------------------------------------------------------------------------- + +# The QUIET tag can be used to turn on/off the messages that are generated to +# standard output by doxygen. If QUIET is set to YES this implies that the +# messages are off. +# The default value is: NO. + +QUIET = NO + +# The WARNINGS tag can be used to turn on/off the warning messages that are +# generated to standard error (stderr) by doxygen. If WARNINGS is set to YES +# this implies that the warnings are on. +# +# Tip: Turn warnings on while writing the documentation. +# The default value is: YES. + +WARNINGS = YES + +# If the WARN_IF_UNDOCUMENTED tag is set to YES then doxygen will generate +# warnings for undocumented members. If EXTRACT_ALL is set to YES then this flag +# will automatically be disabled. +# The default value is: YES. + +WARN_IF_UNDOCUMENTED = YES + +# If the WARN_IF_DOC_ERROR tag is set to YES, doxygen will generate warnings for +# potential errors in the documentation, such as documenting some parameters in +# a documented function twice, or documenting parameters that don't exist or +# using markup commands wrongly. +# The default value is: YES. + +WARN_IF_DOC_ERROR = YES + +# If WARN_IF_INCOMPLETE_DOC is set to YES, doxygen will warn about incomplete +# function parameter documentation. If set to NO, doxygen will accept that some +# parameters have no documentation without warning. +# The default value is: YES. + +WARN_IF_INCOMPLETE_DOC = YES + +# This WARN_NO_PARAMDOC option can be enabled to get warnings for functions that +# are documented, but have no documentation for their parameters or return +# value. If set to NO, doxygen will only warn about wrong parameter +# documentation, but not about the absence of documentation. If EXTRACT_ALL is +# set to YES then this flag will automatically be disabled. See also +# WARN_IF_INCOMPLETE_DOC +# The default value is: NO. + +WARN_NO_PARAMDOC = YES + +# If the WARN_AS_ERROR tag is set to YES then doxygen will immediately stop when +# a warning is encountered. If the WARN_AS_ERROR tag is set to FAIL_ON_WARNINGS +# then doxygen will continue running as if WARN_AS_ERROR tag is set to NO, but +# at the end of the doxygen process doxygen will return with a non-zero status. +# Possible values are: NO, YES and FAIL_ON_WARNINGS. +# The default value is: NO. + +WARN_AS_ERROR = FAIL_ON_WARNINGS + +# The WARN_FORMAT tag determines the format of the warning messages that doxygen +# can produce. The string should contain the $file, $line, and $text tags, which +# will be replaced by the file and line number from which the warning originated +# and the warning text. Optionally the format may contain $version, which will +# be replaced by the version of the file (if it could be obtained via +# FILE_VERSION_FILTER) +# The default value is: $file:$line: $text. + +WARN_FORMAT = "$file:$line: $text" + +# The WARN_LOGFILE tag can be used to specify a file to which warning and error +# messages should be written. If left blank the output is written to standard +# error (stderr). + +WARN_LOGFILE = + +#--------------------------------------------------------------------------- +# Configuration options related to the input files +#--------------------------------------------------------------------------- + +# The INPUT tag is used to specify the files and/or directories that contain +# documented source files. You may enter file names like myfile.cpp or +# directories like /usr/src/myproject. Separate the files or directories with +# spaces. See also FILE_PATTERNS and EXTENSION_MAPPING +# Note: If this tag is empty the current directory is searched. + +INPUT = ../../include/onnxruntime/core/session/onnxruntime_c_api.h \ + ../../include/onnxruntime/core/session/onnxruntime_cxx_api.h + +# This tag can be used to specify the character encoding of the source files +# that doxygen parses. Internally doxygen uses the UTF-8 encoding. Doxygen uses +# libiconv (or the iconv built into libc) for the transcoding. See the libiconv +# documentation (see: +# https://www.gnu.org/software/libiconv/) for the list of possible encodings. +# The default value is: UTF-8. + +INPUT_ENCODING = UTF-8 + +# If the value of the INPUT tag contains directories, you can use the +# FILE_PATTERNS tag to specify one or more wildcard patterns (like *.cpp and +# *.h) to filter out the source-files in the directories. +# +# Note that for custom extensions or not directly supported extensions you also +# need to set EXTENSION_MAPPING for the extension otherwise the files are not +# read by doxygen. +# +# Note the list of default checked file patterns might differ from the list of +# default file extension mappings. +# +# If left blank the following patterns are tested:*.c, *.cc, *.cxx, *.cpp, +# *.c++, *.java, *.ii, *.ixx, *.ipp, *.i++, *.inl, *.idl, *.ddl, *.odl, *.h, +# *.hh, *.hxx, *.hpp, *.h++, *.l, *.cs, *.d, *.php, *.php4, *.php5, *.phtml, +# *.inc, *.m, *.markdown, *.md, *.mm, *.dox (to be provided as doxygen C +# comment), *.py, *.pyw, *.f90, *.f95, *.f03, *.f08, *.f18, *.f, *.for, *.vhd, +# *.vhdl, *.ucf, *.qsf and *.ice. + +FILE_PATTERNS = *.c \ + *.cc \ + *.cxx \ + *.cpp \ + *.c++ \ + *.java \ + *.ii \ + *.ixx \ + *.ipp \ + *.i++ \ + *.inl \ + *.idl \ + *.ddl \ + *.odl \ + *.h \ + *.hh \ + *.hxx \ + *.hpp \ + *.h++ \ + *.cs \ + *.d \ + *.php \ + *.php4 \ + *.php5 \ + *.phtml \ + *.inc \ + *.m \ + *.markdown \ + *.md \ + *.mm \ + *.dox \ + *.py \ + *.pyw \ + *.f90 \ + *.f95 \ + *.f03 \ + *.f08 \ + *.f18 \ + *.f \ + *.for \ + *.vhd \ + *.vhdl \ + *.ucf \ + *.qsf \ + *.ice + +# The RECURSIVE tag can be used to specify whether or not subdirectories should +# be searched for input files as well. +# The default value is: NO. + +RECURSIVE = NO + +# The EXCLUDE tag can be used to specify files and/or directories that should be +# excluded from the INPUT source files. This way you can easily exclude a +# subdirectory from a directory tree whose root is specified with the INPUT tag. +# +# Note that relative paths are relative to the directory from which doxygen is +# run. + +EXCLUDE = + +# The EXCLUDE_SYMLINKS tag can be used to select whether or not files or +# directories that are symbolic links (a Unix file system feature) are excluded +# from the input. +# The default value is: NO. + +EXCLUDE_SYMLINKS = NO + +# If the value of the INPUT tag contains directories, you can use the +# EXCLUDE_PATTERNS tag to specify one or more wildcard patterns to exclude +# certain files from those directories. +# +# Note that the wildcards are matched against the file with absolute path, so to +# exclude all test directories for example use the pattern */test/* + +EXCLUDE_PATTERNS = + +# The EXCLUDE_SYMBOLS tag can be used to specify one or more symbol names +# (namespaces, classes, functions, etc.) that should be excluded from the +# output. The symbol name can be a fully qualified name, a word, or if the +# wildcard * is used, a substring. Examples: ANamespace, AClass, +# AClass::ANamespace, ANamespace::*Test +# +# Note that the wildcards are matched against the file with absolute path, so to +# exclude all test directories use the pattern */test/* + +EXCLUDE_SYMBOLS = + +# The EXAMPLE_PATH tag can be used to specify one or more files or directories +# that contain example code fragments that are included (see the \include +# command). + +EXAMPLE_PATH = ../../include/onnxruntime/core/session + +# If the value of the EXAMPLE_PATH tag contains directories, you can use the +# EXAMPLE_PATTERNS tag to specify one or more wildcard pattern (like *.cpp and +# *.h) to filter out the source-files in the directories. If left blank all +# files are included. + +EXAMPLE_PATTERNS = * + +# If the EXAMPLE_RECURSIVE tag is set to YES then subdirectories will be +# searched for input files to be used with the \include or \dontinclude commands +# irrespective of the value of the RECURSIVE tag. +# The default value is: NO. + +EXAMPLE_RECURSIVE = NO + +# The IMAGE_PATH tag can be used to specify one or more files or directories +# that contain images that are to be included in the documentation (see the +# \image command). + +IMAGE_PATH = + +# The INPUT_FILTER tag can be used to specify a program that doxygen should +# invoke to filter for each input file. Doxygen will invoke the filter program +# by executing (via popen()) the command: +# +# +# +# where is the value of the INPUT_FILTER tag, and is the +# name of an input file. Doxygen will then use the output that the filter +# program writes to standard output. If FILTER_PATTERNS is specified, this tag +# will be ignored. +# +# Note that the filter must not add or remove lines; it is applied before the +# code is scanned, but not when the output code is generated. If lines are added +# or removed, the anchors will not be placed correctly. +# +# Note that for custom extensions or not directly supported extensions you also +# need to set EXTENSION_MAPPING for the extension otherwise the files are not +# properly processed by doxygen. + +INPUT_FILTER = + +# The FILTER_PATTERNS tag can be used to specify filters on a per file pattern +# basis. Doxygen will compare the file name with each pattern and apply the +# filter if there is a match. The filters are a list of the form: pattern=filter +# (like *.cpp=my_cpp_filter). See INPUT_FILTER for further information on how +# filters are used. If the FILTER_PATTERNS tag is empty or if none of the +# patterns match the file name, INPUT_FILTER is applied. +# +# Note that for custom extensions or not directly supported extensions you also +# need to set EXTENSION_MAPPING for the extension otherwise the files are not +# properly processed by doxygen. + +FILTER_PATTERNS = + +# If the FILTER_SOURCE_FILES tag is set to YES, the input filter (if set using +# INPUT_FILTER) will also be used to filter the input files that are used for +# producing the source files to browse (i.e. when SOURCE_BROWSER is set to YES). +# The default value is: NO. + +FILTER_SOURCE_FILES = NO + +# The FILTER_SOURCE_PATTERNS tag can be used to specify source filters per file +# pattern. A pattern will override the setting for FILTER_PATTERN (if any) and +# it is also possible to disable source filtering for a specific pattern using +# *.ext= (so without naming a filter). +# This tag requires that the tag FILTER_SOURCE_FILES is set to YES. + +FILTER_SOURCE_PATTERNS = + +# If the USE_MDFILE_AS_MAINPAGE tag refers to the name of a markdown file that +# is part of the input, its contents will be placed on the main page +# (index.html). This can be useful if you have a project on for instance GitHub +# and want to reuse the introduction page also for the doxygen output. + +USE_MDFILE_AS_MAINPAGE = + +#--------------------------------------------------------------------------- +# Configuration options related to source browsing +#--------------------------------------------------------------------------- + +# If the SOURCE_BROWSER tag is set to YES then a list of source files will be +# generated. Documented entities will be cross-referenced with these sources. +# +# Note: To get rid of all source code in the generated output, make sure that +# also VERBATIM_HEADERS is set to NO. +# The default value is: NO. + +SOURCE_BROWSER = NO + +# Setting the INLINE_SOURCES tag to YES will include the body of functions, +# classes and enums directly into the documentation. +# The default value is: NO. + +INLINE_SOURCES = NO + +# Setting the STRIP_CODE_COMMENTS tag to YES will instruct doxygen to hide any +# special comment blocks from generated source code fragments. Normal C, C++ and +# Fortran comments will always remain visible. +# The default value is: YES. + +STRIP_CODE_COMMENTS = YES + +# If the REFERENCED_BY_RELATION tag is set to YES then for each documented +# entity all documented functions referencing it will be listed. +# The default value is: NO. + +REFERENCED_BY_RELATION = NO + +# If the REFERENCES_RELATION tag is set to YES then for each documented function +# all documented entities called/used by that function will be listed. +# The default value is: NO. + +REFERENCES_RELATION = NO + +# If the REFERENCES_LINK_SOURCE tag is set to YES and SOURCE_BROWSER tag is set +# to YES then the hyperlinks from functions in REFERENCES_RELATION and +# REFERENCED_BY_RELATION lists will link to the source code. Otherwise they will +# link to the documentation. +# The default value is: YES. + +REFERENCES_LINK_SOURCE = YES + +# If SOURCE_TOOLTIPS is enabled (the default) then hovering a hyperlink in the +# source code will show a tooltip with additional information such as prototype, +# brief description and links to the definition and documentation. Since this +# will make the HTML file larger and loading of large files a bit slower, you +# can opt to disable this feature. +# The default value is: YES. +# This tag requires that the tag SOURCE_BROWSER is set to YES. + +SOURCE_TOOLTIPS = YES + +# If the USE_HTAGS tag is set to YES then the references to source code will +# point to the HTML generated by the htags(1) tool instead of doxygen built-in +# source browser. The htags tool is part of GNU's global source tagging system +# (see https://www.gnu.org/software/global/global.html). You will need version +# 4.8.6 or higher. +# +# To use it do the following: +# - Install the latest version of global +# - Enable SOURCE_BROWSER and USE_HTAGS in the configuration file +# - Make sure the INPUT points to the root of the source tree +# - Run doxygen as normal +# +# Doxygen will invoke htags (and that will in turn invoke gtags), so these +# tools must be available from the command line (i.e. in the search path). +# +# The result: instead of the source browser generated by doxygen, the links to +# source code will now point to the output of htags. +# The default value is: NO. +# This tag requires that the tag SOURCE_BROWSER is set to YES. + +USE_HTAGS = NO + +# If the VERBATIM_HEADERS tag is set the YES then doxygen will generate a +# verbatim copy of the header file for each class for which an include is +# specified. Set to NO to disable this. +# See also: Section \class. +# The default value is: YES. + +VERBATIM_HEADERS = YES + +# If the CLANG_ASSISTED_PARSING tag is set to YES then doxygen will use the +# clang parser (see: +# http://clang.llvm.org/) for more accurate parsing at the cost of reduced +# performance. This can be particularly helpful with template rich C++ code for +# which doxygen's built-in parser lacks the necessary type information. +# Note: The availability of this option depends on whether or not doxygen was +# generated with the -Duse_libclang=ON option for CMake. +# The default value is: NO. + +CLANG_ASSISTED_PARSING = NO + +# If the CLANG_ASSISTED_PARSING tag is set to YES and the CLANG_ADD_INC_PATHS +# tag is set to YES then doxygen will add the directory of each input to the +# include path. +# The default value is: YES. +# This tag requires that the tag CLANG_ASSISTED_PARSING is set to YES. + +CLANG_ADD_INC_PATHS = YES + +# If clang assisted parsing is enabled you can provide the compiler with command +# line options that you would normally use when invoking the compiler. Note that +# the include paths will already be set by doxygen for the files and directories +# specified with INPUT and INCLUDE_PATH. +# This tag requires that the tag CLANG_ASSISTED_PARSING is set to YES. + +CLANG_OPTIONS = + +# If clang assisted parsing is enabled you can provide the clang parser with the +# path to the directory containing a file called compile_commands.json. This +# file is the compilation database (see: +# http://clang.llvm.org/docs/HowToSetupToolingForLLVM.html) containing the +# options used when the source files were built. This is equivalent to +# specifying the -p option to a clang tool, such as clang-check. These options +# will then be passed to the parser. Any options specified with CLANG_OPTIONS +# will be added as well. +# Note: The availability of this option depends on whether or not doxygen was +# generated with the -Duse_libclang=ON option for CMake. + +CLANG_DATABASE_PATH = + +#--------------------------------------------------------------------------- +# Configuration options related to the alphabetical class index +#--------------------------------------------------------------------------- + +# If the ALPHABETICAL_INDEX tag is set to YES, an alphabetical index of all +# compounds will be generated. Enable this if the project contains a lot of +# classes, structs, unions or interfaces. +# The default value is: YES. + +ALPHABETICAL_INDEX = YES + +# In case all classes in a project start with a common prefix, all classes will +# be put under the same header in the alphabetical index. The IGNORE_PREFIX tag +# can be used to specify a prefix (or a list of prefixes) that should be ignored +# while generating the index headers. +# This tag requires that the tag ALPHABETICAL_INDEX is set to YES. + +IGNORE_PREFIX = + +#--------------------------------------------------------------------------- +# Configuration options related to the HTML output +#--------------------------------------------------------------------------- + +# If the GENERATE_HTML tag is set to YES, doxygen will generate HTML output +# The default value is: YES. + +GENERATE_HTML = YES + +# The HTML_OUTPUT tag is used to specify where the HTML docs will be put. If a +# relative path is entered the value of OUTPUT_DIRECTORY will be put in front of +# it. +# The default directory is: html. +# This tag requires that the tag GENERATE_HTML is set to YES. + +HTML_OUTPUT = html + +# The HTML_FILE_EXTENSION tag can be used to specify the file extension for each +# generated HTML page (for example: .htm, .php, .asp). +# The default value is: .html. +# This tag requires that the tag GENERATE_HTML is set to YES. + +HTML_FILE_EXTENSION = .html + +# The HTML_HEADER tag can be used to specify a user-defined HTML header file for +# each generated HTML page. If the tag is left blank doxygen will generate a +# standard header. +# +# To get valid HTML the header file that includes any scripts and style sheets +# that doxygen needs, which is dependent on the configuration options used (e.g. +# the setting GENERATE_TREEVIEW). It is highly recommended to start with a +# default header using +# doxygen -w html new_header.html new_footer.html new_stylesheet.css +# YourConfigFile +# and then modify the file new_header.html. See also section "Doxygen usage" +# for information on how to generate the default header that doxygen normally +# uses. +# Note: The header is subject to change so you typically have to regenerate the +# default header when upgrading to a newer version of doxygen. For a description +# of the possible markers and block names see the documentation. +# This tag requires that the tag GENERATE_HTML is set to YES. + +HTML_HEADER = doxygen-header.html + +# The HTML_FOOTER tag can be used to specify a user-defined HTML footer for each +# generated HTML page. If the tag is left blank doxygen will generate a standard +# footer. See HTML_HEADER for more information on how to generate a default +# footer and what special commands can be used inside the footer. See also +# section "Doxygen usage" for information on how to generate the default footer +# that doxygen normally uses. +# This tag requires that the tag GENERATE_HTML is set to YES. + +HTML_FOOTER = + +# The HTML_STYLESHEET tag can be used to specify a user-defined cascading style +# sheet that is used by each HTML page. It can be used to fine-tune the look of +# the HTML output. If left blank doxygen will generate a default style sheet. +# See also section "Doxygen usage" for information on how to generate the style +# sheet that doxygen normally uses. +# Note: It is recommended to use HTML_EXTRA_STYLESHEET instead of this tag, as +# it is more robust and this tag (HTML_STYLESHEET) will in the future become +# obsolete. +# This tag requires that the tag GENERATE_HTML is set to YES. + +HTML_STYLESHEET = + +# The HTML_EXTRA_STYLESHEET tag can be used to specify additional user-defined +# cascading style sheets that are included after the standard style sheets +# created by doxygen. Using this option one can overrule certain style aspects. +# This is preferred over using HTML_STYLESHEET since it does not replace the +# standard style sheet and is therefore more robust against future updates. +# Doxygen will copy the style sheet files to the output directory. +# Note: The order of the extra style sheet files is of importance (e.g. the last +# style sheet in the list overrules the setting of the previous ones in the +# list). For an example see the documentation. +# This tag requires that the tag GENERATE_HTML is set to YES. + +HTML_EXTRA_STYLESHEET = + +# The HTML_EXTRA_FILES tag can be used to specify one or more extra images or +# other source files which should be copied to the HTML output directory. Note +# that these files will be copied to the base HTML output directory. Use the +# $relpath^ marker in the HTML_HEADER and/or HTML_FOOTER files to load these +# files. In the HTML_STYLESHEET file, use the file name only. Also note that the +# files will be copied as-is; there are no commands or markers available. +# This tag requires that the tag GENERATE_HTML is set to YES. + +HTML_EXTRA_FILES = + +# The HTML_COLORSTYLE_HUE tag controls the color of the HTML output. Doxygen +# will adjust the colors in the style sheet and background images according to +# this color. Hue is specified as an angle on a color-wheel, see +# https://en.wikipedia.org/wiki/Hue for more information. For instance the value +# 0 represents red, 60 is yellow, 120 is green, 180 is cyan, 240 is blue, 300 +# purple, and 360 is red again. +# Minimum value: 0, maximum value: 359, default value: 220. +# This tag requires that the tag GENERATE_HTML is set to YES. + +HTML_COLORSTYLE_HUE = 220 + +# The HTML_COLORSTYLE_SAT tag controls the purity (or saturation) of the colors +# in the HTML output. For a value of 0 the output will use gray-scales only. A +# value of 255 will produce the most vivid colors. +# Minimum value: 0, maximum value: 255, default value: 100. +# This tag requires that the tag GENERATE_HTML is set to YES. + +HTML_COLORSTYLE_SAT = 100 + +# The HTML_COLORSTYLE_GAMMA tag controls the gamma correction applied to the +# luminance component of the colors in the HTML output. Values below 100 +# gradually make the output lighter, whereas values above 100 make the output +# darker. The value divided by 100 is the actual gamma applied, so 80 represents +# a gamma of 0.8, The value 220 represents a gamma of 2.2, and 100 does not +# change the gamma. +# Minimum value: 40, maximum value: 240, default value: 80. +# This tag requires that the tag GENERATE_HTML is set to YES. + +HTML_COLORSTYLE_GAMMA = 80 + +# If the HTML_TIMESTAMP tag is set to YES then the footer of each generated HTML +# page will contain the date and time when the page was generated. Setting this +# to YES can help to show when doxygen was last run and thus if the +# documentation is up to date. +# The default value is: NO. +# This tag requires that the tag GENERATE_HTML is set to YES. + +HTML_TIMESTAMP = NO + +# If the HTML_DYNAMIC_MENUS tag is set to YES then the generated HTML +# documentation will contain a main index with vertical navigation menus that +# are dynamically created via JavaScript. If disabled, the navigation index will +# consists of multiple levels of tabs that are statically embedded in every HTML +# page. Disable this option to support browsers that do not have JavaScript, +# like the Qt help browser. +# The default value is: YES. +# This tag requires that the tag GENERATE_HTML is set to YES. + +HTML_DYNAMIC_MENUS = YES + +# If the HTML_DYNAMIC_SECTIONS tag is set to YES then the generated HTML +# documentation will contain sections that can be hidden and shown after the +# page has loaded. +# The default value is: NO. +# This tag requires that the tag GENERATE_HTML is set to YES. + +HTML_DYNAMIC_SECTIONS = NO + +# With HTML_INDEX_NUM_ENTRIES one can control the preferred number of entries +# shown in the various tree structured indices initially; the user can expand +# and collapse entries dynamically later on. Doxygen will expand the tree to +# such a level that at most the specified number of entries are visible (unless +# a fully collapsed tree already exceeds this amount). So setting the number of +# entries 1 will produce a full collapsed tree by default. 0 is a special value +# representing an infinite number of entries and will result in a full expanded +# tree by default. +# Minimum value: 0, maximum value: 9999, default value: 100. +# This tag requires that the tag GENERATE_HTML is set to YES. + +HTML_INDEX_NUM_ENTRIES = 100 + +# If the GENERATE_DOCSET tag is set to YES, additional index files will be +# generated that can be used as input for Apple's Xcode 3 integrated development +# environment (see: +# https://developer.apple.com/xcode/), introduced with OSX 10.5 (Leopard). To +# create a documentation set, doxygen will generate a Makefile in the HTML +# output directory. Running make will produce the docset in that directory and +# running make install will install the docset in +# ~/Library/Developer/Shared/Documentation/DocSets so that Xcode will find it at +# startup. See https://developer.apple.com/library/archive/featuredarticles/Doxy +# genXcode/_index.html for more information. +# The default value is: NO. +# This tag requires that the tag GENERATE_HTML is set to YES. + +GENERATE_DOCSET = NO + +# This tag determines the name of the docset feed. A documentation feed provides +# an umbrella under which multiple documentation sets from a single provider +# (such as a company or product suite) can be grouped. +# The default value is: Doxygen generated docs. +# This tag requires that the tag GENERATE_DOCSET is set to YES. + +DOCSET_FEEDNAME = "Doxygen generated docs" + +# This tag specifies a string that should uniquely identify the documentation +# set bundle. This should be a reverse domain-name style string, e.g. +# com.mycompany.MyDocSet. Doxygen will append .docset to the name. +# The default value is: org.doxygen.Project. +# This tag requires that the tag GENERATE_DOCSET is set to YES. + +DOCSET_BUNDLE_ID = org.doxygen.Project + +# The DOCSET_PUBLISHER_ID tag specifies a string that should uniquely identify +# the documentation publisher. This should be a reverse domain-name style +# string, e.g. com.mycompany.MyDocSet.documentation. +# The default value is: org.doxygen.Publisher. +# This tag requires that the tag GENERATE_DOCSET is set to YES. + +DOCSET_PUBLISHER_ID = org.doxygen.Publisher + +# The DOCSET_PUBLISHER_NAME tag identifies the documentation publisher. +# The default value is: Publisher. +# This tag requires that the tag GENERATE_DOCSET is set to YES. + +DOCSET_PUBLISHER_NAME = Publisher + +# If the GENERATE_HTMLHELP tag is set to YES then doxygen generates three +# additional HTML index files: index.hhp, index.hhc, and index.hhk. The +# index.hhp is a project file that can be read by Microsoft's HTML Help Workshop +# on Windows. In the beginning of 2021 Microsoft took the original page, with +# a.o. the download links, offline the HTML help workshop was already many years +# in maintenance mode). You can download the HTML help workshop from the web +# archives at Installation executable (see: +# http://web.archive.org/web/20160201063255/http://download.microsoft.com/downlo +# ad/0/A/9/0A939EF6-E31C-430F-A3DF-DFAE7960D564/htmlhelp.exe). +# +# The HTML Help Workshop contains a compiler that can convert all HTML output +# generated by doxygen into a single compiled HTML file (.chm). Compiled HTML +# files are now used as the Windows 98 help format, and will replace the old +# Windows help format (.hlp) on all Windows platforms in the future. Compressed +# HTML files also contain an index, a table of contents, and you can search for +# words in the documentation. The HTML workshop also contains a viewer for +# compressed HTML files. +# The default value is: NO. +# This tag requires that the tag GENERATE_HTML is set to YES. + +GENERATE_HTMLHELP = NO + +# The CHM_FILE tag can be used to specify the file name of the resulting .chm +# file. You can add a path in front of the file if the result should not be +# written to the html output directory. +# This tag requires that the tag GENERATE_HTMLHELP is set to YES. + +CHM_FILE = + +# The HHC_LOCATION tag can be used to specify the location (absolute path +# including file name) of the HTML help compiler (hhc.exe). If non-empty, +# doxygen will try to run the HTML help compiler on the generated index.hhp. +# The file has to be specified with full path. +# This tag requires that the tag GENERATE_HTMLHELP is set to YES. + +HHC_LOCATION = + +# The GENERATE_CHI flag controls if a separate .chi index file is generated +# (YES) or that it should be included in the main .chm file (NO). +# The default value is: NO. +# This tag requires that the tag GENERATE_HTMLHELP is set to YES. + +GENERATE_CHI = NO + +# The CHM_INDEX_ENCODING is used to encode HtmlHelp index (hhk), content (hhc) +# and project file content. +# This tag requires that the tag GENERATE_HTMLHELP is set to YES. + +CHM_INDEX_ENCODING = + +# The BINARY_TOC flag controls whether a binary table of contents is generated +# (YES) or a normal table of contents (NO) in the .chm file. Furthermore it +# enables the Previous and Next buttons. +# The default value is: NO. +# This tag requires that the tag GENERATE_HTMLHELP is set to YES. + +BINARY_TOC = NO + +# The TOC_EXPAND flag can be set to YES to add extra items for group members to +# the table of contents of the HTML help documentation and to the tree view. +# The default value is: NO. +# This tag requires that the tag GENERATE_HTMLHELP is set to YES. + +TOC_EXPAND = NO + +# If the GENERATE_QHP tag is set to YES and both QHP_NAMESPACE and +# QHP_VIRTUAL_FOLDER are set, an additional index file will be generated that +# can be used as input for Qt's qhelpgenerator to generate a Qt Compressed Help +# (.qch) of the generated HTML documentation. +# The default value is: NO. +# This tag requires that the tag GENERATE_HTML is set to YES. + +GENERATE_QHP = NO + +# If the QHG_LOCATION tag is specified, the QCH_FILE tag can be used to specify +# the file name of the resulting .qch file. The path specified is relative to +# the HTML output folder. +# This tag requires that the tag GENERATE_QHP is set to YES. + +QCH_FILE = + +# The QHP_NAMESPACE tag specifies the namespace to use when generating Qt Help +# Project output. For more information please see Qt Help Project / Namespace +# (see: +# https://doc.qt.io/archives/qt-4.8/qthelpproject.html#namespace). +# The default value is: org.doxygen.Project. +# This tag requires that the tag GENERATE_QHP is set to YES. + +QHP_NAMESPACE = org.doxygen.Project + +# The QHP_VIRTUAL_FOLDER tag specifies the namespace to use when generating Qt +# Help Project output. For more information please see Qt Help Project / Virtual +# Folders (see: +# https://doc.qt.io/archives/qt-4.8/qthelpproject.html#virtual-folders). +# The default value is: doc. +# This tag requires that the tag GENERATE_QHP is set to YES. + +QHP_VIRTUAL_FOLDER = doc + +# If the QHP_CUST_FILTER_NAME tag is set, it specifies the name of a custom +# filter to add. For more information please see Qt Help Project / Custom +# Filters (see: +# https://doc.qt.io/archives/qt-4.8/qthelpproject.html#custom-filters). +# This tag requires that the tag GENERATE_QHP is set to YES. + +QHP_CUST_FILTER_NAME = + +# The QHP_CUST_FILTER_ATTRS tag specifies the list of the attributes of the +# custom filter to add. For more information please see Qt Help Project / Custom +# Filters (see: +# https://doc.qt.io/archives/qt-4.8/qthelpproject.html#custom-filters). +# This tag requires that the tag GENERATE_QHP is set to YES. + +QHP_CUST_FILTER_ATTRS = + +# The QHP_SECT_FILTER_ATTRS tag specifies the list of the attributes this +# project's filter section matches. Qt Help Project / Filter Attributes (see: +# https://doc.qt.io/archives/qt-4.8/qthelpproject.html#filter-attributes). +# This tag requires that the tag GENERATE_QHP is set to YES. + +QHP_SECT_FILTER_ATTRS = + +# The QHG_LOCATION tag can be used to specify the location (absolute path +# including file name) of Qt's qhelpgenerator. If non-empty doxygen will try to +# run qhelpgenerator on the generated .qhp file. +# This tag requires that the tag GENERATE_QHP is set to YES. + +QHG_LOCATION = + +# If the GENERATE_ECLIPSEHELP tag is set to YES, additional index files will be +# generated, together with the HTML files, they form an Eclipse help plugin. To +# install this plugin and make it available under the help contents menu in +# Eclipse, the contents of the directory containing the HTML and XML files needs +# to be copied into the plugins directory of eclipse. The name of the directory +# within the plugins directory should be the same as the ECLIPSE_DOC_ID value. +# After copying Eclipse needs to be restarted before the help appears. +# The default value is: NO. +# This tag requires that the tag GENERATE_HTML is set to YES. + +GENERATE_ECLIPSEHELP = NO + +# A unique identifier for the Eclipse help plugin. When installing the plugin +# the directory name containing the HTML and XML files should also have this +# name. Each documentation set should have its own identifier. +# The default value is: org.doxygen.Project. +# This tag requires that the tag GENERATE_ECLIPSEHELP is set to YES. + +ECLIPSE_DOC_ID = org.doxygen.Project + +# If you want full control over the layout of the generated HTML pages it might +# be necessary to disable the index and replace it with your own. The +# DISABLE_INDEX tag can be used to turn on/off the condensed index (tabs) at top +# of each HTML page. A value of NO enables the index and the value YES disables +# it. Since the tabs in the index contain the same information as the navigation +# tree, you can set this option to YES if you also set GENERATE_TREEVIEW to YES. +# The default value is: NO. +# This tag requires that the tag GENERATE_HTML is set to YES. + +DISABLE_INDEX = NO + +# The GENERATE_TREEVIEW tag is used to specify whether a tree-like index +# structure should be generated to display hierarchical information. If the tag +# value is set to YES, a side panel will be generated containing a tree-like +# index structure (just like the one that is generated for HTML Help). For this +# to work a browser that supports JavaScript, DHTML, CSS and frames is required +# (i.e. any modern browser). Windows users are probably better off using the +# HTML help feature. Via custom style sheets (see HTML_EXTRA_STYLESHEET) one can +# further fine tune the look of the index (see "Fine-tuning the output"). As an +# example, the default style sheet generated by doxygen has an example that +# shows how to put an image at the root of the tree instead of the PROJECT_NAME. +# Since the tree basically has the same information as the tab index, you could +# consider setting DISABLE_INDEX to YES when enabling this option. +# The default value is: NO. +# This tag requires that the tag GENERATE_HTML is set to YES. + +GENERATE_TREEVIEW = YES + +# When both GENERATE_TREEVIEW and DISABLE_INDEX are set to YES, then the +# FULL_SIDEBAR option determines if the side bar is limited to only the treeview +# area (value NO) or if it should extend to the full height of the window (value +# YES). Setting this to YES gives a layout similar to +# https://docs.readthedocs.io with more room for contents, but less room for the +# project logo, title, and description. If either GENERATOR_TREEVIEW or +# DISABLE_INDEX is set to NO, this option has no effect. +# The default value is: NO. +# This tag requires that the tag GENERATE_HTML is set to YES. + +FULL_SIDEBAR = NO + +# The ENUM_VALUES_PER_LINE tag can be used to set the number of enum values that +# doxygen will group on one line in the generated HTML documentation. +# +# Note that a value of 0 will completely suppress the enum values from appearing +# in the overview section. +# Minimum value: 0, maximum value: 20, default value: 4. +# This tag requires that the tag GENERATE_HTML is set to YES. + +ENUM_VALUES_PER_LINE = 4 + +# If the treeview is enabled (see GENERATE_TREEVIEW) then this tag can be used +# to set the initial width (in pixels) of the frame in which the tree is shown. +# Minimum value: 0, maximum value: 1500, default value: 250. +# This tag requires that the tag GENERATE_HTML is set to YES. + +TREEVIEW_WIDTH = 250 + +# If the EXT_LINKS_IN_WINDOW option is set to YES, doxygen will open links to +# external symbols imported via tag files in a separate window. +# The default value is: NO. +# This tag requires that the tag GENERATE_HTML is set to YES. + +EXT_LINKS_IN_WINDOW = NO + +# If the HTML_FORMULA_FORMAT option is set to svg, doxygen will use the pdf2svg +# tool (see https://github.com/dawbarton/pdf2svg) or inkscape (see +# https://inkscape.org) to generate formulas as SVG images instead of PNGs for +# the HTML output. These images will generally look nicer at scaled resolutions. +# Possible values are: png (the default) and svg (looks nicer but requires the +# pdf2svg or inkscape tool). +# The default value is: png. +# This tag requires that the tag GENERATE_HTML is set to YES. + +HTML_FORMULA_FORMAT = png + +# Use this tag to change the font size of LaTeX formulas included as images in +# the HTML documentation. When you change the font size after a successful +# doxygen run you need to manually remove any form_*.png images from the HTML +# output directory to force them to be regenerated. +# Minimum value: 8, maximum value: 50, default value: 10. +# This tag requires that the tag GENERATE_HTML is set to YES. + +FORMULA_FONTSIZE = 10 + +# Use the FORMULA_TRANSPARENT tag to determine whether or not the images +# generated for formulas are transparent PNGs. Transparent PNGs are not +# supported properly for IE 6.0, but are supported on all modern browsers. +# +# Note that when changing this option you need to delete any form_*.png files in +# the HTML output directory before the changes have effect. +# The default value is: YES. +# This tag requires that the tag GENERATE_HTML is set to YES. + +FORMULA_TRANSPARENT = YES + +# The FORMULA_MACROFILE can contain LaTeX \newcommand and \renewcommand commands +# to create new LaTeX commands to be used in formulas as building blocks. See +# the section "Including formulas" for details. + +FORMULA_MACROFILE = + +# Enable the USE_MATHJAX option to render LaTeX formulas using MathJax (see +# https://www.mathjax.org) which uses client side JavaScript for the rendering +# instead of using pre-rendered bitmaps. Use this if you do not have LaTeX +# installed or if you want to formulas look prettier in the HTML output. When +# enabled you may also need to install MathJax separately and configure the path +# to it using the MATHJAX_RELPATH option. +# The default value is: NO. +# This tag requires that the tag GENERATE_HTML is set to YES. + +USE_MATHJAX = NO + +# With MATHJAX_VERSION it is possible to specify the MathJax version to be used. +# Note that the different versions of MathJax have different requirements with +# regards to the different settings, so it is possible that also other MathJax +# settings have to be changed when switching between the different MathJax +# versions. +# Possible values are: MathJax_2 and MathJax_3. +# The default value is: MathJax_2. +# This tag requires that the tag USE_MATHJAX is set to YES. + +MATHJAX_VERSION = MathJax_2 + +# When MathJax is enabled you can set the default output format to be used for +# the MathJax output. For more details about the output format see MathJax +# version 2 (see: +# http://docs.mathjax.org/en/v2.7-latest/output.html) and MathJax version 3 +# (see: +# http://docs.mathjax.org/en/latest/web/components/output.html). +# Possible values are: HTML-CSS (which is slower, but has the best +# compatibility. This is the name for Mathjax version 2, for MathJax version 3 +# this will be translated into chtml), NativeMML (i.e. MathML. Only supported +# for NathJax 2. For MathJax version 3 chtml will be used instead.), chtml (This +# is the name for Mathjax version 3, for MathJax version 2 this will be +# translated into HTML-CSS) and SVG. +# The default value is: HTML-CSS. +# This tag requires that the tag USE_MATHJAX is set to YES. + +MATHJAX_FORMAT = HTML-CSS + +# When MathJax is enabled you need to specify the location relative to the HTML +# output directory using the MATHJAX_RELPATH option. The destination directory +# should contain the MathJax.js script. For instance, if the mathjax directory +# is located at the same level as the HTML output directory, then +# MATHJAX_RELPATH should be ../mathjax. The default value points to the MathJax +# Content Delivery Network so you can quickly see the result without installing +# MathJax. However, it is strongly recommended to install a local copy of +# MathJax from https://www.mathjax.org before deployment. The default value is: +# - in case of MathJax version 2: https://cdn.jsdelivr.net/npm/mathjax@2 +# - in case of MathJax version 3: https://cdn.jsdelivr.net/npm/mathjax@3 +# This tag requires that the tag USE_MATHJAX is set to YES. + +MATHJAX_RELPATH = https://cdn.jsdelivr.net/npm/mathjax@2 + +# The MATHJAX_EXTENSIONS tag can be used to specify one or more MathJax +# extension names that should be enabled during MathJax rendering. For example +# for MathJax version 2 (see +# https://docs.mathjax.org/en/v2.7-latest/tex.html#tex-and-latex-extensions): +# MATHJAX_EXTENSIONS = TeX/AMSmath TeX/AMSsymbols +# For example for MathJax version 3 (see +# http://docs.mathjax.org/en/latest/input/tex/extensions/index.html): +# MATHJAX_EXTENSIONS = ams +# This tag requires that the tag USE_MATHJAX is set to YES. + +MATHJAX_EXTENSIONS = + +# The MATHJAX_CODEFILE tag can be used to specify a file with javascript pieces +# of code that will be used on startup of the MathJax code. See the MathJax site +# (see: +# http://docs.mathjax.org/en/v2.7-latest/output.html) for more details. For an +# example see the documentation. +# This tag requires that the tag USE_MATHJAX is set to YES. + +MATHJAX_CODEFILE = + +# When the SEARCHENGINE tag is enabled doxygen will generate a search box for +# the HTML output. The underlying search engine uses javascript and DHTML and +# should work on any modern browser. Note that when using HTML help +# (GENERATE_HTMLHELP), Qt help (GENERATE_QHP), or docsets (GENERATE_DOCSET) +# there is already a search function so this one should typically be disabled. +# For large projects the javascript based search engine can be slow, then +# enabling SERVER_BASED_SEARCH may provide a better solution. It is possible to +# search using the keyboard; to jump to the search box use + S +# (what the is depends on the OS and browser, but it is typically +# , /