From d0e30beb42fb7be59329a79ee309e0d9c9273f48 Mon Sep 17 00:00:00 2001 From: Sanggyu Lee Date: Wed, 20 Sep 2023 13:25:31 +0900 Subject: [PATCH] [CircleGraph] Support onnx Now, CircleGraph can show onnx. onnx.js, onnx-proto.js and onnx-metadata.json are copied from original netron r5.2.1. To avoid name conflicts with others (e.g. tflite, circle), all occurrences of `$root` are replaced with `onnx_root` from onnx-proto.js. ONE-vscode-DCO-1.0-Signed-off-by: Sanggyu Lee --- media/CircleGraph/external/onnx-metadata.json | 33042 ++++++++++++++++ media/CircleGraph/external/onnx-proto.js | 1737 + media/CircleGraph/external/onnx.js | 1644 + media/CircleGraph/index.html | 2 + media/CircleGraph/index.js | 6 + media/CircleGraph/view.js | 1 + package.json | 3 + src/CircleGraph/CircleGraphCtrl.ts | 7 + 8 files changed, 36442 insertions(+) create mode 100644 media/CircleGraph/external/onnx-metadata.json create mode 100644 media/CircleGraph/external/onnx-proto.js create mode 100644 media/CircleGraph/external/onnx.js diff --git a/media/CircleGraph/external/onnx-metadata.json b/media/CircleGraph/external/onnx-metadata.json new file mode 100644 index 00000000..98ad897c --- /dev/null +++ b/media/CircleGraph/external/onnx-metadata.json @@ -0,0 +1,33042 @@ +[ + { + "name": "Abs", + "module": "ai.onnx", + "version": 1, + "support_level": "common", + "description": "Absolute takes one input data (Tensor) and produces one output data\n(Tensor) where the absolute is, y = abs(x), is applied to\nthe tensor elementwise.\n", + "attributes": [ + { + "name": "consumed_inputs", + "type": "int64[]", + "required": false, + "description": "legacy optimization attribute." + } + ], + "inputs": [ + { + "name": "X", + "type": "T", + "description": "Input tensor" + } + ], + "min_input": 1, + "max_input": 1, + "outputs": [ + { + "name": "Y", + "type": "T", + "description": "Output tensor" + } + ], + "min_output": 1, + "max_output": 1, + "type_constraints": [ + { + "description": "Constrain input and output types to float tensors.", + "type_param_str": "T", + "allowed_type_strs": [ + "tensor(float16)", + "tensor(float)", + "tensor(double)" + ] + } + ], + "examples": [ + { + "summary": "abs", + "code": "node = onnx.helper.make_node(\n 'Abs',\n inputs=['x'],\n outputs=['y'],\n)\nx = np.random.randn(3, 4, 5).astype(np.float32)\ny = abs(x)\n\nexpect(node, inputs=[x], outputs=[y],\n name='test_abs')" + } + ] + }, + { + "name": "Abs", + "module": "ai.onnx", + "version": 6, + "support_level": "common", + "description": "Absolute takes one input data (Tensor) and produces one output data\n(Tensor) where the absolute is, y = abs(x), is applied to\nthe tensor elementwise.\n", + "inputs": [ + { + "name": "X", + "type": "T", + "description": "Input tensor" + } + ], + "min_input": 1, + "max_input": 1, + "outputs": [ + { + "name": "Y", + "type": "T", + "description": "Output tensor" + } + ], + "min_output": 1, + "max_output": 1, + "type_constraints": [ + { + "description": "Constrain input and output types to all numeric tensors.", + "type_param_str": "T", + "allowed_type_strs": [ + "tensor(uint8)", + "tensor(uint16)", + "tensor(uint32)", + "tensor(uint64)", + "tensor(int8)", + "tensor(int16)", + "tensor(int32)", + "tensor(int64)", + "tensor(float16)", + "tensor(float)", + "tensor(double)" + ] + } + ], + "examples": [ + { + "summary": "abs", + "code": "node = onnx.helper.make_node(\n 'Abs',\n inputs=['x'],\n outputs=['y'],\n)\nx = np.random.randn(3, 4, 5).astype(np.float32)\ny = abs(x)\n\nexpect(node, inputs=[x], outputs=[y],\n name='test_abs')" + } + ] + }, + { + "name": "Abs", + "module": "ai.onnx", + "version": 13, + "support_level": "common", + "description": "Absolute takes one input data (Tensor) and produces one output data\n(Tensor) where the absolute is, y = abs(x), is applied to\nthe tensor elementwise.\n", + "inputs": [ + { + "name": "X", + "type": "T", + "description": "Input tensor" + } + ], + "min_input": 1, + "max_input": 1, + "outputs": [ + { + "name": "Y", + "type": "T", + "description": "Output tensor" + } + ], + "min_output": 1, + "max_output": 1, + "type_constraints": [ + { + "description": "Constrain input and output types to all numeric tensors.", + "type_param_str": "T", + "allowed_type_strs": [ + "tensor(uint8)", + "tensor(uint16)", + "tensor(uint32)", + "tensor(uint64)", + "tensor(int8)", + "tensor(int16)", + "tensor(int32)", + "tensor(int64)", + "tensor(float16)", + "tensor(float)", + "tensor(double)", + "tensor(bfloat16)" + ] + } + ], + "examples": [ + { + "summary": "abs", + "code": "node = onnx.helper.make_node(\n 'Abs',\n inputs=['x'],\n outputs=['y'],\n)\nx = np.random.randn(3, 4, 5).astype(np.float32)\ny = abs(x)\n\nexpect(node, inputs=[x], outputs=[y],\n name='test_abs')" + } + ] + }, + { + "name": "Acos", + "module": "ai.onnx", + "version": 7, + "support_level": "common", + "description": "Calculates the arccosine (inverse of cosine) of the given input tensor, element-wise.\n", + "inputs": [ + { + "name": "input", + "type": "T", + "description": "Input tensor" + } + ], + "min_input": 1, + "max_input": 1, + "outputs": [ + { + "name": "output", + "type": "T", + "description": "The arccosine of the input tensor computed element-wise" + } + ], + "min_output": 1, + "max_output": 1, + "type_constraints": [ + { + "description": "Constrain input and output types to float tensors.", + "type_param_str": "T", + "allowed_type_strs": [ + "tensor(float16)", + "tensor(float)", + "tensor(double)" + ] + } + ], + "examples": [ + { + "summary": "acos", + "code": "node = onnx.helper.make_node(\n 'Acos',\n inputs=['x'],\n outputs=['y'],\n)\n\nx = np.array([-0.5, 0, 0.5]).astype(np.float32)\ny = np.arccos(x)\nexpect(node, inputs=[x], outputs=[y],\n name='test_acos_example')\n\nx = np.random.rand(3, 4, 5).astype(np.float32)\ny = np.arccos(x)\nexpect(node, inputs=[x], outputs=[y],\n name='test_acos')" + } + ] + }, + { + "name": "Acosh", + "module": "ai.onnx", + "version": 9, + "support_level": "common", + "description": "Calculates the hyperbolic arccosine of the given input tensor element-wise.\n", + "inputs": [ + { + "name": "input", + "type": "T", + "description": "Input tensor" + } + ], + "min_input": 1, + "max_input": 1, + "outputs": [ + { + "name": "output", + "type": "T", + "description": "The hyperbolic arccosine values of the input tensor computed element-wise" + } + ], + "min_output": 1, + "max_output": 1, + "type_constraints": [ + { + "description": "Constrain input and output types to float tensors.", + "type_param_str": "T", + "allowed_type_strs": [ + "tensor(float16)", + "tensor(float)", + "tensor(double)" + ] + } + ], + "examples": [ + { + "summary": "acosh", + "code": "node = onnx.helper.make_node(\n 'Acosh',\n inputs=['x'],\n outputs=['y'],\n)\n\nx = np.array([10, np.e, 1]).astype(np.float32)\ny = np.arccosh(x) # expected output [2.99322295, 1.65745449, 0.]\nexpect(node, inputs=[x], outputs=[y],\n name='test_acosh_example')\n\nx = np.random.uniform(1.0, 10.0, (3, 4, 5)).astype(np.float32)\ny = np.arccosh(x)\nexpect(node, inputs=[x], outputs=[y],\n name='test_acosh')" + } + ] + }, + { + "name": "Adagrad", + "module": "ai.onnx.preview.training", + "version": 1, + "support_level": "common", + "description": "Compute one iteration of ADAGRAD, a stochastic gradient based optimization\n algorithm. This operator can conduct the optimization of multiple tensor variables.\n\n Let's define the behavior of this operator. As you can imagine, ADAGRAD requires\n some parameters:\n\n - The initial learning-rate \"R\".\n - The update count \"T\". That is, the number of training iterations conducted.\n - A L2-norm regularization coefficient \"norm_coefficient\".\n - A learning-rate decay factor \"decay_factor\".\n - A small constant \"epsilon\" to avoid dividing-by-zero.\n\n At each ADAGRAD iteration, the optimized tensors are moved along a direction\n computed based on their estimated gradient and accumulated squared gradient. Assume\n that only a single tensor \"X\" is updated by this operator. We need the value of \"X\",\n its gradient \"G\", and its accumulated squared gradient \"H\". Therefore, variables in\n this operator's input list are sequentially \"R\", \"T\", \"X\", \"G\", and \"H\". Other\n parameters are given as attributes because they are usually constants. Also, the\n corresponding output tensors are the new value of \"X\" (called \"X_new\"), and then\n the new accumulated squared gradient (called \"H_new\"). Those outputs are computed\n from the given inputs following the pseudo code below.\n\n Let \"+\", \"-\", \"*\", and \"/\" are all element-wise arithmetic operations with\n numpy-style broadcasting support. The pseudo code to compute those outputs is:\n\n // Compute a scalar learning-rate factor. At the first update of X, T is generally\n // 0 (0-based update index) or 1 (1-based update index).\n r = R / (1 + T * decay_factor);\n\n // Add gradient of 0.5 * norm_coefficient * ||X||_2^2, where ||X||_2 is the 2-norm.\n G_regularized = norm_coefficient * X + G;\n\n // Compute new accumulated squared gradient.\n H_new = H + G_regularized * G_regularized;\n\n // Compute the adaptive part of per-coordinate learning rate. Note that Sqrt(...)\n // computes element-wise square-root.\n H_adaptive = Sqrt(H_new) + epsilon\n\n // Compute the new value of \"X\".\n X_new = X - r * G_regularized / H_adaptive;\n\n If one assign this operators to optimize multiple inputs, for example, \"X_1\" and \"X_2\", the same\n pseudo code may be extended to handle all tensors jointly. More specifically, we can view \"X\" as a\n concatenation of \"X_1\" and \"X_2\" (of course, their gradient and accumulate gradient should\n be concatenated too) and then just reuse the entire pseudo code.\n\n Note that ADAGRAD was first proposed in http://jmlr.org/papers/volume12/duchi11a/duchi11a.pdf.\n In that reference paper, this operator is a special case of the Figure 1's composite mirror\n descent update.\n", + "attributes": [ + { + "name": "decay_factor", + "type": "float32", + "required": false, + "description": "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." + }, + { + "name": "epsilon", + "type": "float32", + "required": false, + "default": 9.999999974752427e-07, + "description": "Small scalar to avoid dividing by zero." + }, + { + "name": "norm_coefficient", + "type": "float32", + "required": false, + "description": "Regularization coefficient in 0.5 * norm_coefficient * ||X||_2^2. Default to 0, which means no regularization." + } + ], + "inputs": [ + { + "name": "R", + "type": "T1", + "description": "The initial learning rate." + }, + { + "name": "T", + "type": "T2", + "description": "The update count of \"X\". It should be a scalar." + }, + { + "name": "inputs", + "type": "T3", + "list": true, + "description": "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\"]." + } + ], + "min_input": 3, + "max_input": 2147483647, + "outputs": [ + { + "name": "outputs", + "type": "T3", + "list": true, + "description": "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\"]." + } + ], + "min_output": 1, + "max_output": 2147483647, + "inputs_range": "3 - ∞", + "outputs_range": "1 - ∞", + "type_constraints": [ + { + "description": "Constrain input types to float scalars.", + "type_param_str": "T1", + "allowed_type_strs": [ + "tensor(float)", + "tensor(double)" + ] + }, + { + "description": "Constrain input types to 64-bit integer scalars.", + "type_param_str": "T2", + "allowed_type_strs": [ + "tensor(int64)" + ] + }, + { + "description": "Constrain input and output types to float tensors.", + "type_param_str": "T3", + "allowed_type_strs": [ + "tensor(float)", + "tensor(double)" + ] + } + ], + "examples": [ + { + "summary": "adagrad", + "code": "# Define operator attributes.\nnorm_coefficient = 0.001\nepsilon = 1e-5\ndecay_factor = 0.1\n\n# Create operator.\nnode = onnx.helper.make_node('Adagrad',\n inputs=['R', 'T', 'X', 'G', 'H'],\n outputs=['X_new', 'H_new'],\n norm_coefficient=norm_coefficient,\n epsilon=epsilon,\n decay_factor=decay_factor,\n domain=AI_ONNX_PREVIEW_TRAINING_DOMAIN\n )\n\n# Define operator inputs.\nr = np.array(0.1, dtype=np.float32) # scalar\nt = np.array(0, dtype=np.int64) # scalar\nx = np.array([1.0], dtype=np.float32)\ng = np.array([-1.0], dtype=np.float32)\nh = np.array([2.0], dtype=np.float32)\n\n# Compute expected outputs of Adagrad.\nx_new, h_new = apply_adagrad(r, t, x, g, h,\n norm_coefficient, epsilon, decay_factor)\n\n# Check results.\nexpect(node, inputs=[r, t, x, g, h],\n outputs=[x_new, h_new], name='test_adagrad',\n opset_imports=[onnx.helper.make_opsetid(AI_ONNX_PREVIEW_TRAINING_DOMAIN, 1)])" + }, + { + "summary": "adagrad_multiple", + "code": "# Define operator attributes.\nnorm_coefficient = 0.001\nepsilon = 1e-5\ndecay_factor = 0.1\n\nnode = onnx.helper.make_node('Adagrad',\n inputs=['R', 'T', 'X1', 'X2',\n 'G1', 'G2', 'H1', 'H2'],\n outputs=['X1_new', 'X2_new',\n 'H1_new', 'H2_new'],\n norm_coefficient=norm_coefficient,\n epsilon=epsilon,\n decay_factor=decay_factor,\n domain=AI_ONNX_PREVIEW_TRAINING_DOMAIN\n )\n\n# Define operator inputs.\nr = np.array(0.1, dtype=np.float32) # scalar\nt = np.array(0, dtype=np.int64) # scalar\n\nx1 = np.array([1.0], dtype=np.float32)\ng1 = np.array([-1.0], dtype=np.float32)\nh1 = np.array([2.0], dtype=np.float32)\n\nx2 = np.array([1.0, 2.0], dtype=np.float32)\ng2 = np.array([-1.0, -3.0], dtype=np.float32)\nh2 = np.array([4.0, 1.0], dtype=np.float32)\n\n# Compute expected outputs of Adagrad.\nx1_new, h1_new = apply_adagrad(r, t, x1, g1, h1,\n norm_coefficient, epsilon, decay_factor)\nx2_new, h2_new = apply_adagrad(r, t, x2, g2, h2,\n norm_coefficient, epsilon, decay_factor)\n\n# Check results.\nexpect(node, inputs=[r, t, x1, x2, g1, g2, h1, h2],\n outputs=[x1_new, x2_new, h1_new, h2_new], name='test_adagrad_multiple',\n opset_imports=[onnx.helper.make_opsetid(AI_ONNX_PREVIEW_TRAINING_DOMAIN, 1)])" + } + ] + }, + { + "name": "Adam", + "module": "ai.onnx.preview.training", + "version": 1, + "support_level": "common", + "description": "Compute one iteration of Adam, a stochastic gradient based optimization\n algorithm. This operator can conduct the optimization of multiple tensor variables.\n\n Let's define the behavior of this operator. First of all, Adam requires\n some parameters:\n\n - The learning-rate \"R\".\n - The update count \"T\". That is, the number of training iterations conducted.\n - A L2-norm regularization coefficient \"norm_coefficient\".\n - A small constant \"epsilon\" to avoid dividing-by-zero.\n - Two coefficients, \"alpha\" and \"beta\".\n\n At each Adam iteration, the optimized tensors are moved along a direction\n computed based on their exponentially-averaged historical gradient and\n exponentially-averaged historical squared gradient. Assume that only a tensor\n \"X\" is being optimized. The rest of required information is\n\n - the value of \"X\",\n - \"X\"'s gradient (denoted by \"G\"),\n - \"X\"'s exponentially-averaged historical gradient (denoted by \"V\"), and\n - \"X\"'s exponentially-averaged historical squared gradient (denoted by \"H\").\n\n Some of those parameters are passed into this operator as input tensors and others\n are stored as this operator's attributes. Specifically, this operator's input tensor\n list is [\"R\", \"T\", \"X\", \"G\", \"V\", \"H\"]. That is, \"R\" is the first input, \"T\" is\n the second input, and so on. Other parameters are given as attributes because they\n are constants. Moreover, the corresponding output tensors are\n\n - the new value of \"X\" (called \"X_new\"),\n - the new exponentially-averaged historical gradient (denoted by \"V_new\"), and\n - the new exponentially-averaged historical squared gradient (denoted by \"H_new\").\n\n Those outputs are computed following the pseudo code below.\n\n Let \"+\", \"-\", \"*\", and \"/\" are all element-wise arithmetic operations with\n numpy-style broadcasting support. The pseudo code to compute those outputs is:\n\n // Add gradient of 0.5 * norm_coefficient * ||X||_2^2, where ||X||_2 is the 2-norm.\n G_regularized = norm_coefficient * X + G\n\n // Update exponentially-averaged historical gradient.\n V_new = alpha * V + (1 - alpha) * G_regularized\n\n // Update exponentially-averaged historical squared gradient.\n H_new = beta * H + (1 - beta) * G_regularized * G_regularized\n\n // Compute the element-wise square-root of H_new. V_new will be element-wisely\n // divided by H_sqrt for a better update direction.\n H_sqrt = Sqrt(H_new) + epsilon\n\n // Compute learning-rate. Note that \"alpha**T\"/\"beta**T\" is alpha's/beta's T-th power.\n R_adjusted = T > 0 ? R * Sqrt(1 - beta**T) / (1 - alpha**T) : R\n\n // Compute new value of \"X\".\n X_new = X - R_adjusted * V_new / H_sqrt\n\n // Post-update regularization.\n X_final = (1 - norm_coefficient_post) * X_new\n\n If there are multiple inputs to be optimized, the pseudo code will be applied\n independently to each of them.\n", + "attributes": [ + { + "name": "alpha", + "type": "float32", + "required": false, + "default": 0.8999999761581421, + "description": "Coefficient of previously accumulated gradient in running average. Default to 0.9." + }, + { + "name": "beta", + "type": "float32", + "required": false, + "default": 0.9990000128746033, + "description": "Coefficient of previously accumulated squared-gradient in running average. Default to 0.999." + }, + { + "name": "epsilon", + "type": "float32", + "required": false, + "default": 9.999999974752427e-07, + "description": "Small scalar to avoid dividing by zero." + }, + { + "name": "norm_coefficient", + "type": "float32", + "required": false, + "description": "Regularization coefficient of 0.5 * norm_coefficient * ||X||_2^2. Default to 0, which means no regularization." + }, + { + "name": "norm_coefficient_post", + "type": "float32", + "required": false, + "description": "Regularization coefficient of 0.5 * norm_coefficient * ||X||_2^2. Default to 0, which means no regularization." + } + ], + "inputs": [ + { + "name": "R", + "type": "T1", + "description": "The initial learning rate." + }, + { + "name": "T", + "type": "T2", + "description": "The update count of \"X\". It should be a scalar." + }, + { + "name": "inputs", + "type": "T3", + "list": true, + "description": "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\"]." + } + ], + "min_input": 3, + "max_input": 2147483647, + "outputs": [ + { + "name": "outputs", + "type": "T3", + "list": true, + "description": "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\"]." + } + ], + "min_output": 1, + "max_output": 2147483647, + "inputs_range": "3 - ∞", + "outputs_range": "1 - ∞", + "type_constraints": [ + { + "description": "Constrain input types to float scalars.", + "type_param_str": "T1", + "allowed_type_strs": [ + "tensor(float)", + "tensor(double)" + ] + }, + { + "description": "Constrain input types to 64-bit integer scalars.", + "type_param_str": "T2", + "allowed_type_strs": [ + "tensor(int64)" + ] + }, + { + "description": "Constrain input and output types to float tensors.", + "type_param_str": "T3", + "allowed_type_strs": [ + "tensor(float)", + "tensor(double)" + ] + } + ], + "examples": [ + { + "summary": "adam", + "code": "# Define operator attributes.\nnorm_coefficient = 0.001\nalpha = 0.95\nbeta = 0.1\nepsilon = 1e-7\n\n# Create operator.\nnode = onnx.helper.make_node('Adam',\n inputs=['R', 'T', 'X', 'G', 'V', 'H'],\n outputs=['X_new', 'V_new', 'H_new'],\n norm_coefficient=norm_coefficient,\n alpha=alpha,\n beta=beta,\n epsilon=epsilon,\n domain=AI_ONNX_PREVIEW_TRAINING_DOMAIN\n )\n\n# Define operator inputs.\nr = np.array(0.1, dtype=np.float32) # scalar\nt = np.array(0, dtype=np.int64) # scalar\nx = np.array([1.2, 2.8], dtype=np.float32)\ng = np.array([-0.94, -2.5], dtype=np.float32)\nv = np.array([1.7, 3.6], dtype=np.float32)\nh = np.array([0.1, 0.1], dtype=np.float32)\n\n# Compute expected outputs of Adam.\nx_new, v_new, h_new = apply_adam(r, t, x, g, v, h,\n norm_coefficient, 0.0, alpha, beta,\n epsilon)\n\n# Check results.\nexpect(node, inputs=[r, t, x, g, v, h],\n outputs=[x_new, v_new, h_new], name='test_adam',\n opset_imports=[onnx.helper.make_opsetid(AI_ONNX_PREVIEW_TRAINING_DOMAIN, 1)])" + }, + { + "summary": "adam_multiple", + "code": "# Define operator attributes.\nnorm_coefficient = 0.001\nalpha = 0.95\nbeta = 0.85\nepsilon = 1e-2\n\nnode = onnx.helper.make_node('Adam',\n inputs=['R', 'T', 'X1', 'X2',\n 'G1', 'G2', 'V1', 'V2',\n 'H1', 'H2'],\n outputs=['X1_new', 'X2_new',\n 'V1_new', 'V2_new',\n 'H1_new', 'H2_new'],\n norm_coefficient=norm_coefficient,\n alpha=alpha,\n beta=beta,\n domain=AI_ONNX_PREVIEW_TRAINING_DOMAIN\n )\n\n# Define operator inputs.\nr = np.array(0.1, dtype=np.float32) # scalar\nt = np.array(0, dtype=np.int64) # scalar\n\nx1 = np.array([1.0], dtype=np.float32)\ng1 = np.array([-1.0], dtype=np.float32)\nv1 = np.array([2.0], dtype=np.float32)\nh1 = np.array([0.5], dtype=np.float32)\n\nx2 = np.array([1.0, 2.0], dtype=np.float32)\ng2 = np.array([-1.0, -3.0], dtype=np.float32)\nv2 = np.array([4.0, 1.0], dtype=np.float32)\nh2 = np.array([1.0, 10.0], dtype=np.float32)\n\n# Compute expected outputs of Adam.\nx1_new, v1_new, h1_new = apply_adam(r, t, x1, g1, v1, h1,\n norm_coefficient, 0.0, alpha, beta,\n epsilon)\nx2_new, v2_new, h2_new = apply_adam(r, t, x2, g2, v2, h2,\n norm_coefficient, 0.0, alpha, beta,\n epsilon)\n\n# Check results.\nexpect(node, inputs=[r, t, x1, x2, g1, g2, v1, v2, h1, h2],\n outputs=[x1_new, x2_new, v1_new, v2_new, h1_new, h2_new],\n name='test_adam_multiple',\n opset_imports=[onnx.helper.make_opsetid(AI_ONNX_PREVIEW_TRAINING_DOMAIN, 1)])" + } + ] + }, + { + "name": "Add", + "module": "ai.onnx", + "version": 1, + "support_level": "common", + "description": "Performs element-wise binary addition (with limited broadcast support).\n\nIf necessary the right-hand-side argument will be broadcasted to match the\nshape of left-hand-side argument. When broadcasting is specified, the second\ntensor can either be of element size 1 (including a scalar tensor and any\ntensor with rank equal to or smaller than the first tensor), or having its\nshape as a contiguous subset of the first tensor's shape. The starting of the\nmutually equal shape is specified by the argument \"axis\", and if it is not set,\nsuffix matching is assumed. 1-dim expansion doesn't work yet.\n\nFor example, the following tensor shapes are supported (with broadcast=1):\n\n shape(A) = (2, 3, 4, 5), shape(B) = (,), i.e. B is a scalar tensor\n shape(A) = (2, 3, 4, 5), shape(B) = (1, 1), i.e. B is an 1-element tensor\n shape(A) = (2, 3, 4, 5), shape(B) = (5,)\n shape(A) = (2, 3, 4, 5), shape(B) = (4, 5)\n shape(A) = (2, 3, 4, 5), shape(B) = (3, 4), with axis=1\n shape(A) = (2, 3, 4, 5), shape(B) = (2), with axis=0\n\nAttribute `broadcast=1` needs to be passed to enable broadcasting.\n", + "attributes": [ + { + "name": "axis", + "type": "int64", + "required": false, + "description": "If set, defines the broadcast dimensions. See doc for details." + }, + { + "name": "broadcast", + "type": "int64", + "required": false, + "description": "Pass 1 to enable broadcasting" + }, + { + "name": "consumed_inputs", + "type": "int64[]", + "required": false, + "description": "legacy optimization attribute." + } + ], + "inputs": [ + { + "name": "A", + "type": "T", + "description": "First operand, should share the type with the second operand." + }, + { + "name": "B", + "type": "T", + "description": "Second operand. With broadcasting can be of smaller size than A. If broadcasting is disabled it should be of the same size." + } + ], + "min_input": 2, + "max_input": 2, + "outputs": [ + { + "name": "C", + "type": "T", + "description": "Result, has same dimensions and type as A" + } + ], + "min_output": 1, + "max_output": 1, + "type_constraints": [ + { + "description": "Constrain input and output types to float tensors.", + "type_param_str": "T", + "allowed_type_strs": [ + "tensor(float16)", + "tensor(float)", + "tensor(double)" + ] + } + ], + "examples": [ + { + "summary": "add", + "code": "node = onnx.helper.make_node(\n 'Add',\n inputs=['x', 'y'],\n outputs=['sum'],\n)\n\nx = np.random.randn(3, 4, 5).astype(np.float32)\ny = np.random.randn(3, 4, 5).astype(np.float32)\nexpect(node, inputs=[x, y], outputs=[x + y],\n name='test_add')" + }, + { + "summary": "add_broadcast", + "code": "node = onnx.helper.make_node(\n 'Add',\n inputs=['x', 'y'],\n outputs=['sum'],\n)\n\nx = np.random.randn(3, 4, 5).astype(np.float32)\ny = np.random.randn(5).astype(np.float32)\nexpect(node, inputs=[x, y], outputs=[x + y],\n name='test_add_bcast')" + }, + { + "summary": "add_uint8", + "code": "node = onnx.helper.make_node(\n 'Add',\n inputs=['x', 'y'],\n outputs=['sum'],\n)\n\nx = np.random.randint(24, size=(3, 4, 5), dtype=np.uint8)\ny = np.random.randint(24, size=(3, 4, 5), dtype=np.uint8)\nexpect(node, inputs=[x, y], outputs=[x + y],\n name='test_add_uint8')" + } + ] + }, + { + "name": "Add", + "module": "ai.onnx", + "version": 6, + "support_level": "common", + "description": "Performs element-wise binary addition (with limited broadcast support).\n\nIf necessary the right-hand-side argument will be broadcasted to match the\nshape of left-hand-side argument. When broadcasting is specified, the second\ntensor can either be of element size 1 (including a scalar tensor and any\ntensor with rank equal to or smaller than the first tensor), or having its\nshape as a contiguous subset of the first tensor's shape. The starting of the\nmutually equal shape is specified by the argument \"axis\", and if it is not set,\nsuffix matching is assumed. 1-dim expansion doesn't work yet.\n\nFor example, the following tensor shapes are supported (with broadcast=1):\n\n shape(A) = (2, 3, 4, 5), shape(B) = (,), i.e. B is a scalar tensor\n shape(A) = (2, 3, 4, 5), shape(B) = (1, 1), i.e. B is an 1-element tensor\n shape(A) = (2, 3, 4, 5), shape(B) = (5,)\n shape(A) = (2, 3, 4, 5), shape(B) = (4, 5)\n shape(A) = (2, 3, 4, 5), shape(B) = (3, 4), with axis=1\n shape(A) = (2, 3, 4, 5), shape(B) = (2), with axis=0\n\nAttribute `broadcast=1` needs to be passed to enable broadcasting.\n", + "attributes": [ + { + "name": "axis", + "type": "int64", + "required": false, + "description": "If set, defines the broadcast dimensions. See doc for details." + }, + { + "name": "broadcast", + "type": "int64", + "required": false, + "description": "Pass 1 to enable broadcasting" + } + ], + "inputs": [ + { + "name": "A", + "type": "T", + "description": "First operand, should share the type with the second operand." + }, + { + "name": "B", + "type": "T", + "description": "Second operand. With broadcasting can be of smaller size than A. If broadcasting is disabled it should be of the same size." + } + ], + "min_input": 2, + "max_input": 2, + "outputs": [ + { + "name": "C", + "type": "T", + "description": "Result, has same dimensions and type as A" + } + ], + "min_output": 1, + "max_output": 1, + "type_constraints": [ + { + "description": "Constrain input and output types to high-precision numeric tensors.", + "type_param_str": "T", + "allowed_type_strs": [ + "tensor(uint32)", + "tensor(uint64)", + "tensor(int32)", + "tensor(int64)", + "tensor(float16)", + "tensor(float)", + "tensor(double)" + ] + } + ], + "examples": [ + { + "summary": "add", + "code": "node = onnx.helper.make_node(\n 'Add',\n inputs=['x', 'y'],\n outputs=['sum'],\n)\n\nx = np.random.randn(3, 4, 5).astype(np.float32)\ny = np.random.randn(3, 4, 5).astype(np.float32)\nexpect(node, inputs=[x, y], outputs=[x + y],\n name='test_add')" + }, + { + "summary": "add_broadcast", + "code": "node = onnx.helper.make_node(\n 'Add',\n inputs=['x', 'y'],\n outputs=['sum'],\n)\n\nx = np.random.randn(3, 4, 5).astype(np.float32)\ny = np.random.randn(5).astype(np.float32)\nexpect(node, inputs=[x, y], outputs=[x + y],\n name='test_add_bcast')" + }, + { + "summary": "add_uint8", + "code": "node = onnx.helper.make_node(\n 'Add',\n inputs=['x', 'y'],\n outputs=['sum'],\n)\n\nx = np.random.randint(24, size=(3, 4, 5), dtype=np.uint8)\ny = np.random.randint(24, size=(3, 4, 5), dtype=np.uint8)\nexpect(node, inputs=[x, y], outputs=[x + y],\n name='test_add_uint8')" + } + ] + }, + { + "name": "Add", + "module": "ai.onnx", + "version": 7, + "support_level": "common", + "description": "Performs element-wise binary addition (with Numpy-style broadcasting support).\n\nThis operator supports **multidirectional (i.e., Numpy-style) broadcasting**; for more details please check [the doc](https://github.com/onnx/onnx/blob/master/docs/Broadcasting.md).\n", + "inputs": [ + { + "name": "A", + "type": "T", + "description": "First operand." + }, + { + "name": "B", + "type": "T", + "description": "Second operand." + } + ], + "min_input": 2, + "max_input": 2, + "outputs": [ + { + "name": "C", + "type": "T", + "description": "Result, has same element type as two inputs" + } + ], + "min_output": 1, + "max_output": 1, + "type_constraints": [ + { + "description": "Constrain input and output types to high-precision numeric tensors.", + "type_param_str": "T", + "allowed_type_strs": [ + "tensor(uint32)", + "tensor(uint64)", + "tensor(int32)", + "tensor(int64)", + "tensor(float16)", + "tensor(float)", + "tensor(double)" + ] + } + ], + "examples": [ + { + "summary": "add", + "code": "node = onnx.helper.make_node(\n 'Add',\n inputs=['x', 'y'],\n outputs=['sum'],\n)\n\nx = np.random.randn(3, 4, 5).astype(np.float32)\ny = np.random.randn(3, 4, 5).astype(np.float32)\nexpect(node, inputs=[x, y], outputs=[x + y],\n name='test_add')" + }, + { + "summary": "add_broadcast", + "code": "node = onnx.helper.make_node(\n 'Add',\n inputs=['x', 'y'],\n outputs=['sum'],\n)\n\nx = np.random.randn(3, 4, 5).astype(np.float32)\ny = np.random.randn(5).astype(np.float32)\nexpect(node, inputs=[x, y], outputs=[x + y],\n name='test_add_bcast')" + }, + { + "summary": "add_uint8", + "code": "node = onnx.helper.make_node(\n 'Add',\n inputs=['x', 'y'],\n outputs=['sum'],\n)\n\nx = np.random.randint(24, size=(3, 4, 5), dtype=np.uint8)\ny = np.random.randint(24, size=(3, 4, 5), dtype=np.uint8)\nexpect(node, inputs=[x, y], outputs=[x + y],\n name='test_add_uint8')" + } + ] + }, + { + "name": "Add", + "module": "ai.onnx", + "version": 13, + "support_level": "common", + "description": "Performs element-wise binary addition (with Numpy-style broadcasting support).\n\nThis operator supports **multidirectional (i.e., Numpy-style) broadcasting**; for more details please check [the doc](https://github.com/onnx/onnx/blob/master/docs/Broadcasting.md).\n", + "inputs": [ + { + "name": "A", + "type": "T", + "description": "First operand." + }, + { + "name": "B", + "type": "T", + "description": "Second operand." + } + ], + "min_input": 2, + "max_input": 2, + "outputs": [ + { + "name": "C", + "type": "T", + "description": "Result, has same element type as two inputs" + } + ], + "min_output": 1, + "max_output": 1, + "type_constraints": [ + { + "description": "Constrain input and output types to high-precision numeric tensors.", + "type_param_str": "T", + "allowed_type_strs": [ + "tensor(uint32)", + "tensor(uint64)", + "tensor(int32)", + "tensor(int64)", + "tensor(float16)", + "tensor(float)", + "tensor(double)", + "tensor(bfloat16)" + ] + } + ], + "examples": [ + { + "summary": "add", + "code": "node = onnx.helper.make_node(\n 'Add',\n inputs=['x', 'y'],\n outputs=['sum'],\n)\n\nx = np.random.randn(3, 4, 5).astype(np.float32)\ny = np.random.randn(3, 4, 5).astype(np.float32)\nexpect(node, inputs=[x, y], outputs=[x + y],\n name='test_add')" + }, + { + "summary": "add_broadcast", + "code": "node = onnx.helper.make_node(\n 'Add',\n inputs=['x', 'y'],\n outputs=['sum'],\n)\n\nx = np.random.randn(3, 4, 5).astype(np.float32)\ny = np.random.randn(5).astype(np.float32)\nexpect(node, inputs=[x, y], outputs=[x + y],\n name='test_add_bcast')" + }, + { + "summary": "add_uint8", + "code": "node = onnx.helper.make_node(\n 'Add',\n inputs=['x', 'y'],\n outputs=['sum'],\n)\n\nx = np.random.randint(24, size=(3, 4, 5), dtype=np.uint8)\ny = np.random.randint(24, size=(3, 4, 5), dtype=np.uint8)\nexpect(node, inputs=[x, y], outputs=[x + y],\n name='test_add_uint8')" + } + ] + }, + { + "name": "Add", + "module": "ai.onnx", + "version": 14, + "support_level": "common", + "description": "Performs element-wise binary addition (with Numpy-style broadcasting support).\n\nThis operator supports **multidirectional (i.e., Numpy-style) broadcasting**; for more details please check [the doc](https://github.com/onnx/onnx/blob/master/docs/Broadcasting.md).\n\n(Opset 14 change): Extend supported types to include uint8, int8, uint16, and int16.\n", + "inputs": [ + { + "name": "A", + "type": "T", + "description": "First operand." + }, + { + "name": "B", + "type": "T", + "description": "Second operand." + } + ], + "min_input": 2, + "max_input": 2, + "outputs": [ + { + "name": "C", + "type": "T", + "description": "Result, has same element type as two inputs" + } + ], + "min_output": 1, + "max_output": 1, + "type_constraints": [ + { + "description": "Constrain input and output types to all numeric tensors.", + "type_param_str": "T", + "allowed_type_strs": [ + "tensor(uint8)", + "tensor(uint16)", + "tensor(uint32)", + "tensor(uint64)", + "tensor(int8)", + "tensor(int16)", + "tensor(int32)", + "tensor(int64)", + "tensor(float16)", + "tensor(float)", + "tensor(double)", + "tensor(bfloat16)" + ] + } + ], + "examples": [ + { + "summary": "add", + "code": "node = onnx.helper.make_node(\n 'Add',\n inputs=['x', 'y'],\n outputs=['sum'],\n)\n\nx = np.random.randn(3, 4, 5).astype(np.float32)\ny = np.random.randn(3, 4, 5).astype(np.float32)\nexpect(node, inputs=[x, y], outputs=[x + y],\n name='test_add')" + }, + { + "summary": "add_broadcast", + "code": "node = onnx.helper.make_node(\n 'Add',\n inputs=['x', 'y'],\n outputs=['sum'],\n)\n\nx = np.random.randn(3, 4, 5).astype(np.float32)\ny = np.random.randn(5).astype(np.float32)\nexpect(node, inputs=[x, y], outputs=[x + y],\n name='test_add_bcast')" + }, + { + "summary": "add_uint8", + "code": "node = onnx.helper.make_node(\n 'Add',\n inputs=['x', 'y'],\n outputs=['sum'],\n)\n\nx = np.random.randint(24, size=(3, 4, 5), dtype=np.uint8)\ny = np.random.randint(24, size=(3, 4, 5), dtype=np.uint8)\nexpect(node, inputs=[x, y], outputs=[x + y],\n name='test_add_uint8')" + } + ] + }, + { + "name": "And", + "module": "ai.onnx", + "version": 1, + "support_level": "common", + "description": "Returns the tensor resulted from performing the `and` logical operation\nelementwise on the input tensors `A` and `B`.\n\nIf broadcasting is enabled, the right-hand-side argument will be broadcasted\nto match the shape of left-hand-side argument. See the doc of `Add` for a\ndetailed description of the broadcasting rules.\n", + "attributes": [ + { + "name": "axis", + "type": "int64", + "required": false, + "description": "If set, defines the broadcast dimensions." + }, + { + "name": "broadcast", + "type": "int64", + "required": false, + "description": "Enable broadcasting" + } + ], + "inputs": [ + { + "name": "A", + "type": "T", + "description": "Left input tensor for the logical operator." + }, + { + "name": "B", + "type": "T", + "description": "Right input tensor for the logical operator." + } + ], + "min_input": 2, + "max_input": 2, + "outputs": [ + { + "name": "C", + "type": "T1", + "description": "Result tensor." + } + ], + "min_output": 1, + "max_output": 1, + "type_constraints": [ + { + "description": "Constrains input to boolean tensor.", + "type_param_str": "T", + "allowed_type_strs": [ + "tensor(bool)" + ] + }, + { + "description": "Constrains output to boolean tensor.", + "type_param_str": "T1", + "allowed_type_strs": [ + "tensor(bool)" + ] + } + ], + "examples": [ + { + "summary": "and", + "code": "node = onnx.helper.make_node(\n 'And',\n inputs=['x', 'y'],\n outputs=['and'],\n)\n\n# 2d\nx = (np.random.randn(3, 4) > 0).astype(bool)\ny = (np.random.randn(3, 4) > 0).astype(bool)\nz = np.logical_and(x, y)\nexpect(node, inputs=[x, y], outputs=[z],\n name='test_and2d')\n\n# 3d\nx = (np.random.randn(3, 4, 5) > 0).astype(bool)\ny = (np.random.randn(3, 4, 5) > 0).astype(bool)\nz = np.logical_and(x, y)\nexpect(node, inputs=[x, y], outputs=[z],\n name='test_and3d')\n\n# 4d\nx = (np.random.randn(3, 4, 5, 6) > 0).astype(bool)\ny = (np.random.randn(3, 4, 5, 6) > 0).astype(bool)\nz = np.logical_and(x, y)\nexpect(node, inputs=[x, y], outputs=[z],\n name='test_and4d')" + }, + { + "summary": "and_broadcast", + "code": "node = onnx.helper.make_node(\n 'And',\n inputs=['x', 'y'],\n outputs=['and'],\n)\n\n# 3d vs 1d\nx = (np.random.randn(3, 4, 5) > 0).astype(bool)\ny = (np.random.randn(5) > 0).astype(bool)\nz = np.logical_and(x, y)\nexpect(node, inputs=[x, y], outputs=[z],\n name='test_and_bcast3v1d')\n\n# 3d vs 2d\nx = (np.random.randn(3, 4, 5) > 0).astype(bool)\ny = (np.random.randn(4, 5) > 0).astype(bool)\nz = np.logical_and(x, y)\nexpect(node, inputs=[x, y], outputs=[z],\n name='test_and_bcast3v2d')\n\n# 4d vs 2d\nx = (np.random.randn(3, 4, 5, 6) > 0).astype(bool)\ny = (np.random.randn(5, 6) > 0).astype(bool)\nz = np.logical_and(x, y)\nexpect(node, inputs=[x, y], outputs=[z],\n name='test_and_bcast4v2d')\n\n# 4d vs 3d\nx = (np.random.randn(3, 4, 5, 6) > 0).astype(bool)\ny = (np.random.randn(4, 5, 6) > 0).astype(bool)\nz = np.logical_and(x, y)\nexpect(node, inputs=[x, y], outputs=[z],\n name='test_and_bcast4v3d')\n\n# 4d vs 4d\nx = (np.random.randn(1, 4, 1, 6) > 0).astype(bool)\ny = (np.random.randn(3, 1, 5, 6) > 0).astype(bool)\nz = np.logical_and(x, y)\nexpect(node, inputs=[x, y], outputs=[z],\n name='test_and_bcast4v4d')" + } + ], + "category": "Logic" + }, + { + "name": "And", + "module": "ai.onnx", + "version": 7, + "support_level": "common", + "description": "Returns the tensor resulted from performing the `and` logical operation\nelementwise on the input tensors `A` and `B` (with Numpy-style broadcasting support).\n\nThis operator supports **multidirectional (i.e., Numpy-style) broadcasting**; for more details please check [the doc](https://github.com/onnx/onnx/blob/master/docs/Broadcasting.md).\n", + "inputs": [ + { + "name": "A", + "type": "T", + "description": "First input operand for the logical operator." + }, + { + "name": "B", + "type": "T", + "description": "Second input operand for the logical operator." + } + ], + "min_input": 2, + "max_input": 2, + "outputs": [ + { + "name": "C", + "type": "T1", + "description": "Result tensor." + } + ], + "min_output": 1, + "max_output": 1, + "type_constraints": [ + { + "description": "Constrains input to boolean tensor.", + "type_param_str": "T", + "allowed_type_strs": [ + "tensor(bool)" + ] + }, + { + "description": "Constrains output to boolean tensor.", + "type_param_str": "T1", + "allowed_type_strs": [ + "tensor(bool)" + ] + } + ], + "examples": [ + { + "summary": "and", + "code": "node = onnx.helper.make_node(\n 'And',\n inputs=['x', 'y'],\n outputs=['and'],\n)\n\n# 2d\nx = (np.random.randn(3, 4) > 0).astype(bool)\ny = (np.random.randn(3, 4) > 0).astype(bool)\nz = np.logical_and(x, y)\nexpect(node, inputs=[x, y], outputs=[z],\n name='test_and2d')\n\n# 3d\nx = (np.random.randn(3, 4, 5) > 0).astype(bool)\ny = (np.random.randn(3, 4, 5) > 0).astype(bool)\nz = np.logical_and(x, y)\nexpect(node, inputs=[x, y], outputs=[z],\n name='test_and3d')\n\n# 4d\nx = (np.random.randn(3, 4, 5, 6) > 0).astype(bool)\ny = (np.random.randn(3, 4, 5, 6) > 0).astype(bool)\nz = np.logical_and(x, y)\nexpect(node, inputs=[x, y], outputs=[z],\n name='test_and4d')" + }, + { + "summary": "and_broadcast", + "code": "node = onnx.helper.make_node(\n 'And',\n inputs=['x', 'y'],\n outputs=['and'],\n)\n\n# 3d vs 1d\nx = (np.random.randn(3, 4, 5) > 0).astype(bool)\ny = (np.random.randn(5) > 0).astype(bool)\nz = np.logical_and(x, y)\nexpect(node, inputs=[x, y], outputs=[z],\n name='test_and_bcast3v1d')\n\n# 3d vs 2d\nx = (np.random.randn(3, 4, 5) > 0).astype(bool)\ny = (np.random.randn(4, 5) > 0).astype(bool)\nz = np.logical_and(x, y)\nexpect(node, inputs=[x, y], outputs=[z],\n name='test_and_bcast3v2d')\n\n# 4d vs 2d\nx = (np.random.randn(3, 4, 5, 6) > 0).astype(bool)\ny = (np.random.randn(5, 6) > 0).astype(bool)\nz = np.logical_and(x, y)\nexpect(node, inputs=[x, y], outputs=[z],\n name='test_and_bcast4v2d')\n\n# 4d vs 3d\nx = (np.random.randn(3, 4, 5, 6) > 0).astype(bool)\ny = (np.random.randn(4, 5, 6) > 0).astype(bool)\nz = np.logical_and(x, y)\nexpect(node, inputs=[x, y], outputs=[z],\n name='test_and_bcast4v3d')\n\n# 4d vs 4d\nx = (np.random.randn(1, 4, 1, 6) > 0).astype(bool)\ny = (np.random.randn(3, 1, 5, 6) > 0).astype(bool)\nz = np.logical_and(x, y)\nexpect(node, inputs=[x, y], outputs=[z],\n name='test_and_bcast4v4d')" + } + ], + "category": "Logic" + }, + { + "name": "ArgMax", + "module": "ai.onnx", + "version": 1, + "support_level": "common", + "description": "Computes the indices of the max elements of the input tensor's element along the\nprovided axis. The resulted tensor has the same rank as the input if keepdims equal 1.\nIf keepdims equal 0, then the resulted tensor have the reduced dimension pruned.\nThe type of the output tensor is integer.", + "attributes": [ + { + "name": "axis", + "type": "int64", + "required": false, + "description": "The axis in which to compute the arg indices." + }, + { + "name": "keepdims", + "type": "int64", + "required": false, + "default": 1, + "description": "Keep the reduced dimension or not, default 1 mean keep reduced dimension." + } + ], + "inputs": [ + { + "name": "data", + "type": "T", + "description": "An input tensor." + } + ], + "min_input": 1, + "max_input": 1, + "outputs": [ + { + "name": "reduced", + "type": "tensor(int64)", + "description": "Reduced output tensor with integer data type." + } + ], + "min_output": 1, + "max_output": 1, + "type_constraints": [ + { + "description": "Constrain input and output types to all numeric tensors.", + "type_param_str": "T", + "allowed_type_strs": [ + "tensor(uint8)", + "tensor(uint16)", + "tensor(uint32)", + "tensor(uint64)", + "tensor(int8)", + "tensor(int16)", + "tensor(int32)", + "tensor(int64)", + "tensor(float16)", + "tensor(float)", + "tensor(double)" + ] + } + ], + "examples": [ + { + "summary": "default_axes_keepdims", + "code": "data = np.array([[2, 1], [3, 10]], dtype=np.float32)\nkeepdims = 1\nnode = onnx.helper.make_node(\n 'ArgMax',\n inputs=['data'],\n outputs=['result'],\n keepdims=keepdims)\n\n# result: [[1], [1]]\nresult = argmax_use_numpy(data, keepdims=keepdims)\nexpect(node, inputs=[data], outputs=[result], name='test_argmax_default_axis_example')\n\ndata = np.random.uniform(-10, 10, [2, 3, 4]).astype(np.float32)\n# result's shape: [1, 3, 4]\nresult = argmax_use_numpy(data, keepdims=keepdims)\nexpect(node, inputs=[data], outputs=[result], name='test_argmax_default_axis_random')" + }, + { + "summary": "default_axes_keepdims_select_last_index", + "code": "data = np.array([[2, 2], [3, 10]], dtype=np.float32)\nkeepdims = 1\nnode = onnx.helper.make_node(\n 'ArgMax',\n inputs=['data'],\n outputs=['result'],\n keepdims=keepdims,\n select_last_index=True)\n\n# result: [[1, 1]]\nresult = argmax_use_numpy_select_last_index(data, keepdims=keepdims)\nexpect(node, inputs=[data], outputs=[result], name='test_argmax_default_axis_example_select_last_index')\n\ndata = np.random.uniform(-10, 10, [2, 3, 4]).astype(np.float32)\n# result's shape: [1, 3, 4]\nresult = argmax_use_numpy_select_last_index(data, keepdims=keepdims)\nexpect(node, inputs=[data], outputs=[result], name='test_argmax_default_axis_random_select_last_index')" + }, + { + "summary": "keepdims", + "code": "data = np.array([[2, 1], [3, 10]], dtype=np.float32)\naxis = 1\nkeepdims = 1\nnode = onnx.helper.make_node(\n 'ArgMax',\n inputs=['data'],\n outputs=['result'],\n axis=axis,\n keepdims=keepdims)\n# result: [[0], [1]]\nresult = argmax_use_numpy(data, axis=axis, keepdims=keepdims)\nexpect(node, inputs=[data], outputs=[result], name='test_argmax_keepdims_example')\n\ndata = np.random.uniform(-10, 10, [2, 3, 4]).astype(np.float32)\n# result's shape: [2, 1, 4]\nresult = argmax_use_numpy(data, axis=axis, keepdims=keepdims)\nexpect(node, inputs=[data], outputs=[result], name='test_argmax_keepdims_random')" + }, + { + "summary": "keepdims_select_last_index", + "code": "data = np.array([[2, 2], [3, 10]], dtype=np.float32)\naxis = 1\nkeepdims = 1\nnode = onnx.helper.make_node(\n 'ArgMax',\n inputs=['data'],\n outputs=['result'],\n axis=axis,\n keepdims=keepdims,\n select_last_index=True)\n# result: [[1], [1]]\nresult = argmax_use_numpy_select_last_index(data, axis=axis, keepdims=keepdims)\nexpect(node, inputs=[data], outputs=[result], name='test_argmax_keepdims_example_select_last_index')\n\ndata = np.random.uniform(-10, 10, [2, 3, 4]).astype(np.float32)\n# result's shape: [2, 1, 4]\nresult = argmax_use_numpy_select_last_index(data, axis=axis, keepdims=keepdims)\nexpect(node, inputs=[data], outputs=[result], name='test_argmax_keepdims_random_select_last_index')" + }, + { + "summary": "negative_axis_keepdims", + "code": "data = np.array([[2, 1], [3, 10]], dtype=np.float32)\naxis = -1\nkeepdims = 1\nnode = onnx.helper.make_node(\n 'ArgMax',\n inputs=['data'],\n outputs=['result'],\n axis=axis,\n keepdims=keepdims)\n# result: [[0], [1]]\nresult = argmax_use_numpy(data, axis=axis, keepdims=keepdims)\nexpect(node, inputs=[data], outputs=[result], name='test_argmax_negative_axis_keepdims_example')\n\ndata = np.random.uniform(-10, 10, [2, 3, 4]).astype(np.float32)\n# result's shape: [2, 3, 1]\nresult = argmax_use_numpy(data, axis=axis, keepdims=keepdims)\nexpect(node, inputs=[data], outputs=[result], name='test_argmax_negative_axis_keepdims_random')" + }, + { + "summary": "negative_axis_keepdims_select_last_index", + "code": "data = np.array([[2, 2], [3, 10]], dtype=np.float32)\naxis = -1\nkeepdims = 1\nnode = onnx.helper.make_node(\n 'ArgMax',\n inputs=['data'],\n outputs=['result'],\n axis=axis,\n keepdims=keepdims,\n select_last_index=True)\n# result: [[1], [1]]\nresult = argmax_use_numpy_select_last_index(data, axis=axis, keepdims=keepdims)\nexpect(node, inputs=[data], outputs=[result], name='test_argmax_negative_axis_keepdims_example_select_last_index')\n\ndata = np.random.uniform(-10, 10, [2, 3, 4]).astype(np.float32)\n# result's shape: [2, 3, 1]\nresult = argmax_use_numpy_select_last_index(data, axis=axis, keepdims=keepdims)\nexpect(node, inputs=[data], outputs=[result], name='test_argmax_negative_axis_keepdims_random_select_last_index')" + }, + { + "summary": "no_keepdims", + "code": "data = np.array([[2, 1], [3, 10]], dtype=np.float32)\naxis = 1\nkeepdims = 0\nnode = onnx.helper.make_node(\n 'ArgMax',\n inputs=['data'],\n outputs=['result'],\n axis=axis,\n keepdims=keepdims)\n# result: [[0, 1]]\nresult = argmax_use_numpy(data, axis=axis, keepdims=keepdims)\nexpect(node, inputs=[data], outputs=[result], name='test_argmax_no_keepdims_example')\n\ndata = np.random.uniform(-10, 10, [2, 3, 4]).astype(np.float32)\n# result's shape: [2, 4]\nresult = argmax_use_numpy(data, axis=axis, keepdims=keepdims)\nexpect(node, inputs=[data], outputs=[result], name='test_argmax_no_keepdims_random')" + }, + { + "summary": "no_keepdims_select_last_index", + "code": "data = np.array([[2, 2], [3, 10]], dtype=np.float32)\naxis = 1\nkeepdims = 0\nnode = onnx.helper.make_node(\n 'ArgMax',\n inputs=['data'],\n outputs=['result'],\n axis=axis,\n keepdims=keepdims,\n select_last_index=True)\n# result: [[1, 1]]\nresult = argmax_use_numpy_select_last_index(data, axis=axis, keepdims=keepdims)\nexpect(node, inputs=[data], outputs=[result], name='test_argmax_no_keepdims_example_select_last_index')\n\ndata = np.random.uniform(-10, 10, [2, 3, 4]).astype(np.float32)\n# result's shape: [2, 4]\nresult = argmax_use_numpy_select_last_index(data, axis=axis, keepdims=keepdims)\nexpect(node, inputs=[data], outputs=[result], name='test_argmax_no_keepdims_random_select_last_index')" + } + ] + }, + { + "name": "ArgMax", + "module": "ai.onnx", + "version": 11, + "support_level": "common", + "description": "Computes the indices of the max elements of the input tensor's element along the\nprovided axis. The resulting tensor has the same rank as the input if keepdims equal 1.\nIf keepdims equal 0, then the resulting tensor have the reduced dimension pruned.\nThe type of the output tensor is integer.", + "attributes": [ + { + "name": "axis", + "type": "int64", + "required": false, + "description": "The axis in which to compute the arg indices. Accepted range is [-r, r-1] where r = rank(data)." + }, + { + "name": "keepdims", + "type": "int64", + "required": false, + "default": 1, + "description": "Keep the reduced dimension or not, default 1 mean keep reduced dimension." + } + ], + "inputs": [ + { + "name": "data", + "type": "T", + "description": "An input tensor." + } + ], + "min_input": 1, + "max_input": 1, + "outputs": [ + { + "name": "reduced", + "type": "tensor(int64)", + "description": "Reduced output tensor with integer data type." + } + ], + "min_output": 1, + "max_output": 1, + "type_constraints": [ + { + "description": "Constrain input and output types to all numeric tensors.", + "type_param_str": "T", + "allowed_type_strs": [ + "tensor(uint8)", + "tensor(uint16)", + "tensor(uint32)", + "tensor(uint64)", + "tensor(int8)", + "tensor(int16)", + "tensor(int32)", + "tensor(int64)", + "tensor(float16)", + "tensor(float)", + "tensor(double)" + ] + } + ], + "examples": [ + { + "summary": "default_axes_keepdims", + "code": "data = np.array([[2, 1], [3, 10]], dtype=np.float32)\nkeepdims = 1\nnode = onnx.helper.make_node(\n 'ArgMax',\n inputs=['data'],\n outputs=['result'],\n keepdims=keepdims)\n\n# result: [[1], [1]]\nresult = argmax_use_numpy(data, keepdims=keepdims)\nexpect(node, inputs=[data], outputs=[result], name='test_argmax_default_axis_example')\n\ndata = np.random.uniform(-10, 10, [2, 3, 4]).astype(np.float32)\n# result's shape: [1, 3, 4]\nresult = argmax_use_numpy(data, keepdims=keepdims)\nexpect(node, inputs=[data], outputs=[result], name='test_argmax_default_axis_random')" + }, + { + "summary": "default_axes_keepdims_select_last_index", + "code": "data = np.array([[2, 2], [3, 10]], dtype=np.float32)\nkeepdims = 1\nnode = onnx.helper.make_node(\n 'ArgMax',\n inputs=['data'],\n outputs=['result'],\n keepdims=keepdims,\n select_last_index=True)\n\n# result: [[1, 1]]\nresult = argmax_use_numpy_select_last_index(data, keepdims=keepdims)\nexpect(node, inputs=[data], outputs=[result], name='test_argmax_default_axis_example_select_last_index')\n\ndata = np.random.uniform(-10, 10, [2, 3, 4]).astype(np.float32)\n# result's shape: [1, 3, 4]\nresult = argmax_use_numpy_select_last_index(data, keepdims=keepdims)\nexpect(node, inputs=[data], outputs=[result], name='test_argmax_default_axis_random_select_last_index')" + }, + { + "summary": "keepdims", + "code": "data = np.array([[2, 1], [3, 10]], dtype=np.float32)\naxis = 1\nkeepdims = 1\nnode = onnx.helper.make_node(\n 'ArgMax',\n inputs=['data'],\n outputs=['result'],\n axis=axis,\n keepdims=keepdims)\n# result: [[0], [1]]\nresult = argmax_use_numpy(data, axis=axis, keepdims=keepdims)\nexpect(node, inputs=[data], outputs=[result], name='test_argmax_keepdims_example')\n\ndata = np.random.uniform(-10, 10, [2, 3, 4]).astype(np.float32)\n# result's shape: [2, 1, 4]\nresult = argmax_use_numpy(data, axis=axis, keepdims=keepdims)\nexpect(node, inputs=[data], outputs=[result], name='test_argmax_keepdims_random')" + }, + { + "summary": "keepdims_select_last_index", + "code": "data = np.array([[2, 2], [3, 10]], dtype=np.float32)\naxis = 1\nkeepdims = 1\nnode = onnx.helper.make_node(\n 'ArgMax',\n inputs=['data'],\n outputs=['result'],\n axis=axis,\n keepdims=keepdims,\n select_last_index=True)\n# result: [[1], [1]]\nresult = argmax_use_numpy_select_last_index(data, axis=axis, keepdims=keepdims)\nexpect(node, inputs=[data], outputs=[result], name='test_argmax_keepdims_example_select_last_index')\n\ndata = np.random.uniform(-10, 10, [2, 3, 4]).astype(np.float32)\n# result's shape: [2, 1, 4]\nresult = argmax_use_numpy_select_last_index(data, axis=axis, keepdims=keepdims)\nexpect(node, inputs=[data], outputs=[result], name='test_argmax_keepdims_random_select_last_index')" + }, + { + "summary": "negative_axis_keepdims", + "code": "data = np.array([[2, 1], [3, 10]], dtype=np.float32)\naxis = -1\nkeepdims = 1\nnode = onnx.helper.make_node(\n 'ArgMax',\n inputs=['data'],\n outputs=['result'],\n axis=axis,\n keepdims=keepdims)\n# result: [[0], [1]]\nresult = argmax_use_numpy(data, axis=axis, keepdims=keepdims)\nexpect(node, inputs=[data], outputs=[result], name='test_argmax_negative_axis_keepdims_example')\n\ndata = np.random.uniform(-10, 10, [2, 3, 4]).astype(np.float32)\n# result's shape: [2, 3, 1]\nresult = argmax_use_numpy(data, axis=axis, keepdims=keepdims)\nexpect(node, inputs=[data], outputs=[result], name='test_argmax_negative_axis_keepdims_random')" + }, + { + "summary": "negative_axis_keepdims_select_last_index", + "code": "data = np.array([[2, 2], [3, 10]], dtype=np.float32)\naxis = -1\nkeepdims = 1\nnode = onnx.helper.make_node(\n 'ArgMax',\n inputs=['data'],\n outputs=['result'],\n axis=axis,\n keepdims=keepdims,\n select_last_index=True)\n# result: [[1], [1]]\nresult = argmax_use_numpy_select_last_index(data, axis=axis, keepdims=keepdims)\nexpect(node, inputs=[data], outputs=[result], name='test_argmax_negative_axis_keepdims_example_select_last_index')\n\ndata = np.random.uniform(-10, 10, [2, 3, 4]).astype(np.float32)\n# result's shape: [2, 3, 1]\nresult = argmax_use_numpy_select_last_index(data, axis=axis, keepdims=keepdims)\nexpect(node, inputs=[data], outputs=[result], name='test_argmax_negative_axis_keepdims_random_select_last_index')" + }, + { + "summary": "no_keepdims", + "code": "data = np.array([[2, 1], [3, 10]], dtype=np.float32)\naxis = 1\nkeepdims = 0\nnode = onnx.helper.make_node(\n 'ArgMax',\n inputs=['data'],\n outputs=['result'],\n axis=axis,\n keepdims=keepdims)\n# result: [[0, 1]]\nresult = argmax_use_numpy(data, axis=axis, keepdims=keepdims)\nexpect(node, inputs=[data], outputs=[result], name='test_argmax_no_keepdims_example')\n\ndata = np.random.uniform(-10, 10, [2, 3, 4]).astype(np.float32)\n# result's shape: [2, 4]\nresult = argmax_use_numpy(data, axis=axis, keepdims=keepdims)\nexpect(node, inputs=[data], outputs=[result], name='test_argmax_no_keepdims_random')" + }, + { + "summary": "no_keepdims_select_last_index", + "code": "data = np.array([[2, 2], [3, 10]], dtype=np.float32)\naxis = 1\nkeepdims = 0\nnode = onnx.helper.make_node(\n 'ArgMax',\n inputs=['data'],\n outputs=['result'],\n axis=axis,\n keepdims=keepdims,\n select_last_index=True)\n# result: [[1, 1]]\nresult = argmax_use_numpy_select_last_index(data, axis=axis, keepdims=keepdims)\nexpect(node, inputs=[data], outputs=[result], name='test_argmax_no_keepdims_example_select_last_index')\n\ndata = np.random.uniform(-10, 10, [2, 3, 4]).astype(np.float32)\n# result's shape: [2, 4]\nresult = argmax_use_numpy_select_last_index(data, axis=axis, keepdims=keepdims)\nexpect(node, inputs=[data], outputs=[result], name='test_argmax_no_keepdims_random_select_last_index')" + } + ] + }, + { + "name": "ArgMax", + "module": "ai.onnx", + "version": 12, + "support_level": "common", + "description": "Computes the indices of the max elements of the input tensor's element along the\nprovided axis. The resulting tensor has the same rank as the input if keepdims equal 1.\nIf keepdims equal 0, then the resulting tensor have the reduced dimension pruned.\nIf select_last_index is True (default False), the index of the last occurrence of the max\nis selected if the max appears more than once in the input. Otherwise the index of the\nfirst occurrence is selected.\nThe type of the output tensor is integer.", + "attributes": [ + { + "name": "axis", + "type": "int64", + "required": false, + "description": "The axis in which to compute the arg indices. Accepted range is [-r, r-1] where r = rank(data)." + }, + { + "name": "keepdims", + "type": "int64", + "required": false, + "default": 1, + "description": "Keep the reduced dimension or not, default 1 mean keep reduced dimension." + }, + { + "name": "select_last_index", + "type": "int64", + "required": false, + "description": "Whether to select the last index or the first index if the {name} appears in multiple indices, default is False (first index)." + } + ], + "inputs": [ + { + "name": "data", + "type": "T", + "description": "An input tensor." + } + ], + "min_input": 1, + "max_input": 1, + "outputs": [ + { + "name": "reduced", + "type": "tensor(int64)", + "description": "Reduced output tensor with integer data type." + } + ], + "min_output": 1, + "max_output": 1, + "type_constraints": [ + { + "description": "Constrain input and output types to all numeric tensors.", + "type_param_str": "T", + "allowed_type_strs": [ + "tensor(uint8)", + "tensor(uint16)", + "tensor(uint32)", + "tensor(uint64)", + "tensor(int8)", + "tensor(int16)", + "tensor(int32)", + "tensor(int64)", + "tensor(float16)", + "tensor(float)", + "tensor(double)" + ] + } + ], + "examples": [ + { + "summary": "default_axes_keepdims", + "code": "data = np.array([[2, 1], [3, 10]], dtype=np.float32)\nkeepdims = 1\nnode = onnx.helper.make_node(\n 'ArgMax',\n inputs=['data'],\n outputs=['result'],\n keepdims=keepdims)\n\n# result: [[1], [1]]\nresult = argmax_use_numpy(data, keepdims=keepdims)\nexpect(node, inputs=[data], outputs=[result], name='test_argmax_default_axis_example')\n\ndata = np.random.uniform(-10, 10, [2, 3, 4]).astype(np.float32)\n# result's shape: [1, 3, 4]\nresult = argmax_use_numpy(data, keepdims=keepdims)\nexpect(node, inputs=[data], outputs=[result], name='test_argmax_default_axis_random')" + }, + { + "summary": "default_axes_keepdims_select_last_index", + "code": "data = np.array([[2, 2], [3, 10]], dtype=np.float32)\nkeepdims = 1\nnode = onnx.helper.make_node(\n 'ArgMax',\n inputs=['data'],\n outputs=['result'],\n keepdims=keepdims,\n select_last_index=True)\n\n# result: [[1, 1]]\nresult = argmax_use_numpy_select_last_index(data, keepdims=keepdims)\nexpect(node, inputs=[data], outputs=[result], name='test_argmax_default_axis_example_select_last_index')\n\ndata = np.random.uniform(-10, 10, [2, 3, 4]).astype(np.float32)\n# result's shape: [1, 3, 4]\nresult = argmax_use_numpy_select_last_index(data, keepdims=keepdims)\nexpect(node, inputs=[data], outputs=[result], name='test_argmax_default_axis_random_select_last_index')" + }, + { + "summary": "keepdims", + "code": "data = np.array([[2, 1], [3, 10]], dtype=np.float32)\naxis = 1\nkeepdims = 1\nnode = onnx.helper.make_node(\n 'ArgMax',\n inputs=['data'],\n outputs=['result'],\n axis=axis,\n keepdims=keepdims)\n# result: [[0], [1]]\nresult = argmax_use_numpy(data, axis=axis, keepdims=keepdims)\nexpect(node, inputs=[data], outputs=[result], name='test_argmax_keepdims_example')\n\ndata = np.random.uniform(-10, 10, [2, 3, 4]).astype(np.float32)\n# result's shape: [2, 1, 4]\nresult = argmax_use_numpy(data, axis=axis, keepdims=keepdims)\nexpect(node, inputs=[data], outputs=[result], name='test_argmax_keepdims_random')" + }, + { + "summary": "keepdims_select_last_index", + "code": "data = np.array([[2, 2], [3, 10]], dtype=np.float32)\naxis = 1\nkeepdims = 1\nnode = onnx.helper.make_node(\n 'ArgMax',\n inputs=['data'],\n outputs=['result'],\n axis=axis,\n keepdims=keepdims,\n select_last_index=True)\n# result: [[1], [1]]\nresult = argmax_use_numpy_select_last_index(data, axis=axis, keepdims=keepdims)\nexpect(node, inputs=[data], outputs=[result], name='test_argmax_keepdims_example_select_last_index')\n\ndata = np.random.uniform(-10, 10, [2, 3, 4]).astype(np.float32)\n# result's shape: [2, 1, 4]\nresult = argmax_use_numpy_select_last_index(data, axis=axis, keepdims=keepdims)\nexpect(node, inputs=[data], outputs=[result], name='test_argmax_keepdims_random_select_last_index')" + }, + { + "summary": "negative_axis_keepdims", + "code": "data = np.array([[2, 1], [3, 10]], dtype=np.float32)\naxis = -1\nkeepdims = 1\nnode = onnx.helper.make_node(\n 'ArgMax',\n inputs=['data'],\n outputs=['result'],\n axis=axis,\n keepdims=keepdims)\n# result: [[0], [1]]\nresult = argmax_use_numpy(data, axis=axis, keepdims=keepdims)\nexpect(node, inputs=[data], outputs=[result], name='test_argmax_negative_axis_keepdims_example')\n\ndata = np.random.uniform(-10, 10, [2, 3, 4]).astype(np.float32)\n# result's shape: [2, 3, 1]\nresult = argmax_use_numpy(data, axis=axis, keepdims=keepdims)\nexpect(node, inputs=[data], outputs=[result], name='test_argmax_negative_axis_keepdims_random')" + }, + { + "summary": "negative_axis_keepdims_select_last_index", + "code": "data = np.array([[2, 2], [3, 10]], dtype=np.float32)\naxis = -1\nkeepdims = 1\nnode = onnx.helper.make_node(\n 'ArgMax',\n inputs=['data'],\n outputs=['result'],\n axis=axis,\n keepdims=keepdims,\n select_last_index=True)\n# result: [[1], [1]]\nresult = argmax_use_numpy_select_last_index(data, axis=axis, keepdims=keepdims)\nexpect(node, inputs=[data], outputs=[result], name='test_argmax_negative_axis_keepdims_example_select_last_index')\n\ndata = np.random.uniform(-10, 10, [2, 3, 4]).astype(np.float32)\n# result's shape: [2, 3, 1]\nresult = argmax_use_numpy_select_last_index(data, axis=axis, keepdims=keepdims)\nexpect(node, inputs=[data], outputs=[result], name='test_argmax_negative_axis_keepdims_random_select_last_index')" + }, + { + "summary": "no_keepdims", + "code": "data = np.array([[2, 1], [3, 10]], dtype=np.float32)\naxis = 1\nkeepdims = 0\nnode = onnx.helper.make_node(\n 'ArgMax',\n inputs=['data'],\n outputs=['result'],\n axis=axis,\n keepdims=keepdims)\n# result: [[0, 1]]\nresult = argmax_use_numpy(data, axis=axis, keepdims=keepdims)\nexpect(node, inputs=[data], outputs=[result], name='test_argmax_no_keepdims_example')\n\ndata = np.random.uniform(-10, 10, [2, 3, 4]).astype(np.float32)\n# result's shape: [2, 4]\nresult = argmax_use_numpy(data, axis=axis, keepdims=keepdims)\nexpect(node, inputs=[data], outputs=[result], name='test_argmax_no_keepdims_random')" + }, + { + "summary": "no_keepdims_select_last_index", + "code": "data = np.array([[2, 2], [3, 10]], dtype=np.float32)\naxis = 1\nkeepdims = 0\nnode = onnx.helper.make_node(\n 'ArgMax',\n inputs=['data'],\n outputs=['result'],\n axis=axis,\n keepdims=keepdims,\n select_last_index=True)\n# result: [[1, 1]]\nresult = argmax_use_numpy_select_last_index(data, axis=axis, keepdims=keepdims)\nexpect(node, inputs=[data], outputs=[result], name='test_argmax_no_keepdims_example_select_last_index')\n\ndata = np.random.uniform(-10, 10, [2, 3, 4]).astype(np.float32)\n# result's shape: [2, 4]\nresult = argmax_use_numpy_select_last_index(data, axis=axis, keepdims=keepdims)\nexpect(node, inputs=[data], outputs=[result], name='test_argmax_no_keepdims_random_select_last_index')" + } + ] + }, + { + "name": "ArgMax", + "module": "ai.onnx", + "version": 13, + "support_level": "common", + "description": "Computes the indices of the max elements of the input tensor's element along the\nprovided axis. The resulting tensor has the same rank as the input if keepdims equal 1.\nIf keepdims equal 0, then the resulting tensor have the reduced dimension pruned.\nIf select_last_index is True (default False), the index of the last occurrence of the max\nis selected if the max appears more than once in the input. Otherwise the index of the\nfirst occurrence is selected.\nThe type of the output tensor is integer.", + "attributes": [ + { + "name": "axis", + "type": "int64", + "required": false, + "description": "The axis in which to compute the arg indices. Accepted range is [-r, r-1] where r = rank(data)." + }, + { + "name": "keepdims", + "type": "int64", + "required": false, + "default": 1, + "description": "Keep the reduced dimension or not, default 1 mean keep reduced dimension." + }, + { + "name": "select_last_index", + "type": "int64", + "required": false, + "description": "Whether to select the last index or the first index if the {name} appears in multiple indices, default is False (first index)." + } + ], + "inputs": [ + { + "name": "data", + "type": "T", + "description": "An input tensor." + } + ], + "min_input": 1, + "max_input": 1, + "outputs": [ + { + "name": "reduced", + "type": "tensor(int64)", + "description": "Reduced output tensor with integer data type." + } + ], + "min_output": 1, + "max_output": 1, + "type_constraints": [ + { + "description": "Constrain input and output types to all numeric tensors.", + "type_param_str": "T", + "allowed_type_strs": [ + "tensor(uint8)", + "tensor(uint16)", + "tensor(uint32)", + "tensor(uint64)", + "tensor(int8)", + "tensor(int16)", + "tensor(int32)", + "tensor(int64)", + "tensor(float16)", + "tensor(float)", + "tensor(double)", + "tensor(bfloat16)" + ] + } + ], + "examples": [ + { + "summary": "default_axes_keepdims", + "code": "data = np.array([[2, 1], [3, 10]], dtype=np.float32)\nkeepdims = 1\nnode = onnx.helper.make_node(\n 'ArgMax',\n inputs=['data'],\n outputs=['result'],\n keepdims=keepdims)\n\n# result: [[1], [1]]\nresult = argmax_use_numpy(data, keepdims=keepdims)\nexpect(node, inputs=[data], outputs=[result], name='test_argmax_default_axis_example')\n\ndata = np.random.uniform(-10, 10, [2, 3, 4]).astype(np.float32)\n# result's shape: [1, 3, 4]\nresult = argmax_use_numpy(data, keepdims=keepdims)\nexpect(node, inputs=[data], outputs=[result], name='test_argmax_default_axis_random')" + }, + { + "summary": "default_axes_keepdims_select_last_index", + "code": "data = np.array([[2, 2], [3, 10]], dtype=np.float32)\nkeepdims = 1\nnode = onnx.helper.make_node(\n 'ArgMax',\n inputs=['data'],\n outputs=['result'],\n keepdims=keepdims,\n select_last_index=True)\n\n# result: [[1, 1]]\nresult = argmax_use_numpy_select_last_index(data, keepdims=keepdims)\nexpect(node, inputs=[data], outputs=[result], name='test_argmax_default_axis_example_select_last_index')\n\ndata = np.random.uniform(-10, 10, [2, 3, 4]).astype(np.float32)\n# result's shape: [1, 3, 4]\nresult = argmax_use_numpy_select_last_index(data, keepdims=keepdims)\nexpect(node, inputs=[data], outputs=[result], name='test_argmax_default_axis_random_select_last_index')" + }, + { + "summary": "keepdims", + "code": "data = np.array([[2, 1], [3, 10]], dtype=np.float32)\naxis = 1\nkeepdims = 1\nnode = onnx.helper.make_node(\n 'ArgMax',\n inputs=['data'],\n outputs=['result'],\n axis=axis,\n keepdims=keepdims)\n# result: [[0], [1]]\nresult = argmax_use_numpy(data, axis=axis, keepdims=keepdims)\nexpect(node, inputs=[data], outputs=[result], name='test_argmax_keepdims_example')\n\ndata = np.random.uniform(-10, 10, [2, 3, 4]).astype(np.float32)\n# result's shape: [2, 1, 4]\nresult = argmax_use_numpy(data, axis=axis, keepdims=keepdims)\nexpect(node, inputs=[data], outputs=[result], name='test_argmax_keepdims_random')" + }, + { + "summary": "keepdims_select_last_index", + "code": "data = np.array([[2, 2], [3, 10]], dtype=np.float32)\naxis = 1\nkeepdims = 1\nnode = onnx.helper.make_node(\n 'ArgMax',\n inputs=['data'],\n outputs=['result'],\n axis=axis,\n keepdims=keepdims,\n select_last_index=True)\n# result: [[1], [1]]\nresult = argmax_use_numpy_select_last_index(data, axis=axis, keepdims=keepdims)\nexpect(node, inputs=[data], outputs=[result], name='test_argmax_keepdims_example_select_last_index')\n\ndata = np.random.uniform(-10, 10, [2, 3, 4]).astype(np.float32)\n# result's shape: [2, 1, 4]\nresult = argmax_use_numpy_select_last_index(data, axis=axis, keepdims=keepdims)\nexpect(node, inputs=[data], outputs=[result], name='test_argmax_keepdims_random_select_last_index')" + }, + { + "summary": "negative_axis_keepdims", + "code": "data = np.array([[2, 1], [3, 10]], dtype=np.float32)\naxis = -1\nkeepdims = 1\nnode = onnx.helper.make_node(\n 'ArgMax',\n inputs=['data'],\n outputs=['result'],\n axis=axis,\n keepdims=keepdims)\n# result: [[0], [1]]\nresult = argmax_use_numpy(data, axis=axis, keepdims=keepdims)\nexpect(node, inputs=[data], outputs=[result], name='test_argmax_negative_axis_keepdims_example')\n\ndata = np.random.uniform(-10, 10, [2, 3, 4]).astype(np.float32)\n# result's shape: [2, 3, 1]\nresult = argmax_use_numpy(data, axis=axis, keepdims=keepdims)\nexpect(node, inputs=[data], outputs=[result], name='test_argmax_negative_axis_keepdims_random')" + }, + { + "summary": "negative_axis_keepdims_select_last_index", + "code": "data = np.array([[2, 2], [3, 10]], dtype=np.float32)\naxis = -1\nkeepdims = 1\nnode = onnx.helper.make_node(\n 'ArgMax',\n inputs=['data'],\n outputs=['result'],\n axis=axis,\n keepdims=keepdims,\n select_last_index=True)\n# result: [[1], [1]]\nresult = argmax_use_numpy_select_last_index(data, axis=axis, keepdims=keepdims)\nexpect(node, inputs=[data], outputs=[result], name='test_argmax_negative_axis_keepdims_example_select_last_index')\n\ndata = np.random.uniform(-10, 10, [2, 3, 4]).astype(np.float32)\n# result's shape: [2, 3, 1]\nresult = argmax_use_numpy_select_last_index(data, axis=axis, keepdims=keepdims)\nexpect(node, inputs=[data], outputs=[result], name='test_argmax_negative_axis_keepdims_random_select_last_index')" + }, + { + "summary": "no_keepdims", + "code": "data = np.array([[2, 1], [3, 10]], dtype=np.float32)\naxis = 1\nkeepdims = 0\nnode = onnx.helper.make_node(\n 'ArgMax',\n inputs=['data'],\n outputs=['result'],\n axis=axis,\n keepdims=keepdims)\n# result: [[0, 1]]\nresult = argmax_use_numpy(data, axis=axis, keepdims=keepdims)\nexpect(node, inputs=[data], outputs=[result], name='test_argmax_no_keepdims_example')\n\ndata = np.random.uniform(-10, 10, [2, 3, 4]).astype(np.float32)\n# result's shape: [2, 4]\nresult = argmax_use_numpy(data, axis=axis, keepdims=keepdims)\nexpect(node, inputs=[data], outputs=[result], name='test_argmax_no_keepdims_random')" + }, + { + "summary": "no_keepdims_select_last_index", + "code": "data = np.array([[2, 2], [3, 10]], dtype=np.float32)\naxis = 1\nkeepdims = 0\nnode = onnx.helper.make_node(\n 'ArgMax',\n inputs=['data'],\n outputs=['result'],\n axis=axis,\n keepdims=keepdims,\n select_last_index=True)\n# result: [[1, 1]]\nresult = argmax_use_numpy_select_last_index(data, axis=axis, keepdims=keepdims)\nexpect(node, inputs=[data], outputs=[result], name='test_argmax_no_keepdims_example_select_last_index')\n\ndata = np.random.uniform(-10, 10, [2, 3, 4]).astype(np.float32)\n# result's shape: [2, 4]\nresult = argmax_use_numpy_select_last_index(data, axis=axis, keepdims=keepdims)\nexpect(node, inputs=[data], outputs=[result], name='test_argmax_no_keepdims_random_select_last_index')" + } + ] + }, + { + "name": "ArgMin", + "module": "ai.onnx", + "version": 1, + "support_level": "common", + "description": "Computes the indices of the min elements of the input tensor's element along the\nprovided axis. The resulted tensor has the same rank as the input if keepdims equal 1.\nIf keepdims equal 0, then the resulted tensor have the reduced dimension pruned.\nThe type of the output tensor is integer.", + "attributes": [ + { + "name": "axis", + "type": "int64", + "required": false, + "description": "The axis in which to compute the arg indices." + }, + { + "name": "keepdims", + "type": "int64", + "required": false, + "default": 1, + "description": "Keep the reduced dimension or not, default 1 mean keep reduced dimension." + } + ], + "inputs": [ + { + "name": "data", + "type": "T", + "description": "An input tensor." + } + ], + "min_input": 1, + "max_input": 1, + "outputs": [ + { + "name": "reduced", + "type": "tensor(int64)", + "description": "Reduced output tensor with integer data type." + } + ], + "min_output": 1, + "max_output": 1, + "type_constraints": [ + { + "description": "Constrain input and output types to all numeric tensors.", + "type_param_str": "T", + "allowed_type_strs": [ + "tensor(uint8)", + "tensor(uint16)", + "tensor(uint32)", + "tensor(uint64)", + "tensor(int8)", + "tensor(int16)", + "tensor(int32)", + "tensor(int64)", + "tensor(float16)", + "tensor(float)", + "tensor(double)" + ] + } + ], + "examples": [ + { + "summary": "default_axes_keepdims", + "code": "data = np.array([[2, 1], [3, 10]], dtype=np.float32)\nkeepdims = 1\nnode = onnx.helper.make_node(\n 'ArgMin',\n inputs=['data'],\n outputs=['result'],\n keepdims=keepdims)\n\n# The content of result is : [[0], [0]]\nresult = argmin_use_numpy(data, keepdims=keepdims)\nexpect(node, inputs=[data], outputs=[result], name='test_argmin_default_axis_example')\n\ndata = np.random.uniform(-10, 10, [2, 3, 4]).astype(np.float32)\n# result's shape: [1, 3, 4]\nresult = argmin_use_numpy(data, keepdims=keepdims)\nexpect(node, inputs=[data], outputs=[result], name='test_argmin_default_axis_random')" + }, + { + "summary": "default_axes_keepdims_select_last_index", + "code": "data = np.array([[2, 2], [3, 10]], dtype=np.float32)\nkeepdims = 1\nnode = onnx.helper.make_node(\n 'ArgMin',\n inputs=['data'],\n outputs=['result'],\n keepdims=keepdims,\n select_last_index=True)\n\n# result: [[0, 0]]\nresult = argmin_use_numpy_select_last_index(data, keepdims=keepdims)\nexpect(node, inputs=[data], outputs=[result], name='test_argmin_default_axis_example_select_last_index')\n\ndata = np.random.uniform(-10, 10, [2, 3, 4]).astype(np.float32)\n# result's shape: [1, 3, 4]\nresult = argmin_use_numpy_select_last_index(data, keepdims=keepdims)\nexpect(node, inputs=[data], outputs=[result], name='test_argmin_default_axis_random_select_last_index')" + }, + { + "summary": "keepdims", + "code": "data = np.array([[2, 1], [3, 10]], dtype=np.float32)\naxis = 1\nkeepdims = 1\nnode = onnx.helper.make_node(\n 'ArgMin',\n inputs=['data'],\n outputs=['result'],\n axis=axis,\n keepdims=keepdims)\n# The content of result is : [[1], [0]]\nresult = argmin_use_numpy(data, axis=axis, keepdims=keepdims)\nexpect(node, inputs=[data], outputs=[result], name='test_argmin_keepdims_example')\n\ndata = np.random.uniform(-10, 10, [2, 3, 4]).astype(np.float32)\n# result's shape: [2, 1, 4]\nresult = argmin_use_numpy(data, axis=axis, keepdims=keepdims)\nexpect(node, inputs=[data], outputs=[result], name='test_argmin_keepdims_random')" + }, + { + "summary": "keepdims_select_last_index", + "code": "data = np.array([[2, 2], [3, 10]], dtype=np.float32)\naxis = 1\nkeepdims = 1\nnode = onnx.helper.make_node(\n 'ArgMin',\n inputs=['data'],\n outputs=['result'],\n axis=axis,\n keepdims=keepdims,\n select_last_index=True)\n# result: [[1], [0]]\nresult = argmin_use_numpy_select_last_index(data, axis=axis, keepdims=keepdims)\nexpect(node, inputs=[data], outputs=[result], name='test_argmin_keepdims_example_select_last_index')\n\ndata = np.random.uniform(-10, 10, [2, 3, 4]).astype(np.float32)\n# result's shape: [2, 1, 4]\nresult = argmin_use_numpy_select_last_index(data, axis=axis, keepdims=keepdims)\nexpect(node, inputs=[data], outputs=[result], name='test_argmin_keepdims_random_select_last_index')" + }, + { + "summary": "negative_axis_keepdims", + "code": "data = np.array([[2, 1], [3, 10]], dtype=np.float32)\naxis = -1\nkeepdims = 1\nnode = onnx.helper.make_node(\n 'ArgMin',\n inputs=['data'],\n outputs=['result'],\n axis=axis,\n keepdims=keepdims)\n# The content of result is : [[1], [0]]\nresult = argmin_use_numpy(data, axis=axis, keepdims=keepdims)\nexpect(node, inputs=[data], outputs=[result], name='test_argmin_negative_axis_keepdims_example')\n\ndata = np.random.uniform(-10, 10, [2, 3, 4]).astype(np.float32)\n# result's shape: [2, 3, 1]\nresult = argmin_use_numpy(data, axis=axis, keepdims=keepdims)\nexpect(node, inputs=[data], outputs=[result], name='test_argmin_negative_axis_keepdims_random')" + }, + { + "summary": "negative_axis_keepdims_select_last_index", + "code": "data = np.array([[2, 2], [3, 10]], dtype=np.float32)\naxis = -1\nkeepdims = 1\nnode = onnx.helper.make_node(\n 'ArgMin',\n inputs=['data'],\n outputs=['result'],\n axis=axis,\n keepdims=keepdims,\n select_last_index=True)\n# result: [[1], [0]]\nresult = argmin_use_numpy_select_last_index(data, axis=axis, keepdims=keepdims)\nexpect(node, inputs=[data], outputs=[result], name='test_argmin_negative_axis_keepdims_example_select_last_index')\n\ndata = np.random.uniform(-10, 10, [2, 3, 4]).astype(np.float32)\n# result's shape: [2, 3, 1]\nresult = argmin_use_numpy_select_last_index(data, axis=axis, keepdims=keepdims)\nexpect(node, inputs=[data], outputs=[result], name='test_argmin_negative_axis_keepdims_random_select_last_index')" + }, + { + "summary": "no_keepdims", + "code": "data = np.array([[2, 1], [3, 10]], dtype=np.float32)\naxis = 1\nkeepdims = 0\nnode = onnx.helper.make_node(\n 'ArgMin',\n inputs=['data'],\n outputs=['result'],\n axis=axis,\n keepdims=keepdims)\n# The content of result is : [[1, 0]]\nresult = argmin_use_numpy(data, axis=axis, keepdims=keepdims)\nexpect(node, inputs=[data], outputs=[result], name='test_argmin_no_keepdims_example')\n\ndata = np.random.uniform(-10, 10, [2, 3, 4]).astype(np.float32)\n# result's shape: [2, 4]\nresult = argmin_use_numpy(data, axis=axis, keepdims=keepdims)\nexpect(node, inputs=[data], outputs=[result], name='test_argmin_no_keepdims_random')" + }, + { + "summary": "no_keepdims_select_last_index", + "code": "data = np.array([[2, 2], [3, 10]], dtype=np.float32)\naxis = 1\nkeepdims = 0\nnode = onnx.helper.make_node(\n 'ArgMin',\n inputs=['data'],\n outputs=['result'],\n axis=axis,\n keepdims=keepdims,\n select_last_index=True)\n# result: [[1, 0]]\nresult = argmin_use_numpy_select_last_index(data, axis=axis, keepdims=keepdims)\nexpect(node, inputs=[data], outputs=[result], name='test_argmin_no_keepdims_example_select_last_index')\n\ndata = np.random.uniform(-10, 10, [2, 3, 4]).astype(np.float32)\n# result's shape: [2, 4]\nresult = argmin_use_numpy_select_last_index(data, axis=axis, keepdims=keepdims)\nexpect(node, inputs=[data], outputs=[result], name='test_argmin_no_keepdims_random_select_last_index')" + } + ] + }, + { + "name": "ArgMin", + "module": "ai.onnx", + "version": 11, + "support_level": "common", + "description": "Computes the indices of the min elements of the input tensor's element along the\nprovided axis. The resulting tensor has the same rank as the input if keepdims equal 1.\nIf keepdims equal 0, then the resulting tensor have the reduced dimension pruned.\nThe type of the output tensor is integer.", + "attributes": [ + { + "name": "axis", + "type": "int64", + "required": false, + "description": "The axis in which to compute the arg indices. Accepted range is [-r, r-1] where r = rank(data)." + }, + { + "name": "keepdims", + "type": "int64", + "required": false, + "default": 1, + "description": "Keep the reduced dimension or not, default 1 mean keep reduced dimension." + } + ], + "inputs": [ + { + "name": "data", + "type": "T", + "description": "An input tensor." + } + ], + "min_input": 1, + "max_input": 1, + "outputs": [ + { + "name": "reduced", + "type": "tensor(int64)", + "description": "Reduced output tensor with integer data type." + } + ], + "min_output": 1, + "max_output": 1, + "type_constraints": [ + { + "description": "Constrain input and output types to all numeric tensors.", + "type_param_str": "T", + "allowed_type_strs": [ + "tensor(uint8)", + "tensor(uint16)", + "tensor(uint32)", + "tensor(uint64)", + "tensor(int8)", + "tensor(int16)", + "tensor(int32)", + "tensor(int64)", + "tensor(float16)", + "tensor(float)", + "tensor(double)" + ] + } + ], + "examples": [ + { + "summary": "default_axes_keepdims", + "code": "data = np.array([[2, 1], [3, 10]], dtype=np.float32)\nkeepdims = 1\nnode = onnx.helper.make_node(\n 'ArgMin',\n inputs=['data'],\n outputs=['result'],\n keepdims=keepdims)\n\n# The content of result is : [[0], [0]]\nresult = argmin_use_numpy(data, keepdims=keepdims)\nexpect(node, inputs=[data], outputs=[result], name='test_argmin_default_axis_example')\n\ndata = np.random.uniform(-10, 10, [2, 3, 4]).astype(np.float32)\n# result's shape: [1, 3, 4]\nresult = argmin_use_numpy(data, keepdims=keepdims)\nexpect(node, inputs=[data], outputs=[result], name='test_argmin_default_axis_random')" + }, + { + "summary": "default_axes_keepdims_select_last_index", + "code": "data = np.array([[2, 2], [3, 10]], dtype=np.float32)\nkeepdims = 1\nnode = onnx.helper.make_node(\n 'ArgMin',\n inputs=['data'],\n outputs=['result'],\n keepdims=keepdims,\n select_last_index=True)\n\n# result: [[0, 0]]\nresult = argmin_use_numpy_select_last_index(data, keepdims=keepdims)\nexpect(node, inputs=[data], outputs=[result], name='test_argmin_default_axis_example_select_last_index')\n\ndata = np.random.uniform(-10, 10, [2, 3, 4]).astype(np.float32)\n# result's shape: [1, 3, 4]\nresult = argmin_use_numpy_select_last_index(data, keepdims=keepdims)\nexpect(node, inputs=[data], outputs=[result], name='test_argmin_default_axis_random_select_last_index')" + }, + { + "summary": "keepdims", + "code": "data = np.array([[2, 1], [3, 10]], dtype=np.float32)\naxis = 1\nkeepdims = 1\nnode = onnx.helper.make_node(\n 'ArgMin',\n inputs=['data'],\n outputs=['result'],\n axis=axis,\n keepdims=keepdims)\n# The content of result is : [[1], [0]]\nresult = argmin_use_numpy(data, axis=axis, keepdims=keepdims)\nexpect(node, inputs=[data], outputs=[result], name='test_argmin_keepdims_example')\n\ndata = np.random.uniform(-10, 10, [2, 3, 4]).astype(np.float32)\n# result's shape: [2, 1, 4]\nresult = argmin_use_numpy(data, axis=axis, keepdims=keepdims)\nexpect(node, inputs=[data], outputs=[result], name='test_argmin_keepdims_random')" + }, + { + "summary": "keepdims_select_last_index", + "code": "data = np.array([[2, 2], [3, 10]], dtype=np.float32)\naxis = 1\nkeepdims = 1\nnode = onnx.helper.make_node(\n 'ArgMin',\n inputs=['data'],\n outputs=['result'],\n axis=axis,\n keepdims=keepdims,\n select_last_index=True)\n# result: [[1], [0]]\nresult = argmin_use_numpy_select_last_index(data, axis=axis, keepdims=keepdims)\nexpect(node, inputs=[data], outputs=[result], name='test_argmin_keepdims_example_select_last_index')\n\ndata = np.random.uniform(-10, 10, [2, 3, 4]).astype(np.float32)\n# result's shape: [2, 1, 4]\nresult = argmin_use_numpy_select_last_index(data, axis=axis, keepdims=keepdims)\nexpect(node, inputs=[data], outputs=[result], name='test_argmin_keepdims_random_select_last_index')" + }, + { + "summary": "negative_axis_keepdims", + "code": "data = np.array([[2, 1], [3, 10]], dtype=np.float32)\naxis = -1\nkeepdims = 1\nnode = onnx.helper.make_node(\n 'ArgMin',\n inputs=['data'],\n outputs=['result'],\n axis=axis,\n keepdims=keepdims)\n# The content of result is : [[1], [0]]\nresult = argmin_use_numpy(data, axis=axis, keepdims=keepdims)\nexpect(node, inputs=[data], outputs=[result], name='test_argmin_negative_axis_keepdims_example')\n\ndata = np.random.uniform(-10, 10, [2, 3, 4]).astype(np.float32)\n# result's shape: [2, 3, 1]\nresult = argmin_use_numpy(data, axis=axis, keepdims=keepdims)\nexpect(node, inputs=[data], outputs=[result], name='test_argmin_negative_axis_keepdims_random')" + }, + { + "summary": "negative_axis_keepdims_select_last_index", + "code": "data = np.array([[2, 2], [3, 10]], dtype=np.float32)\naxis = -1\nkeepdims = 1\nnode = onnx.helper.make_node(\n 'ArgMin',\n inputs=['data'],\n outputs=['result'],\n axis=axis,\n keepdims=keepdims,\n select_last_index=True)\n# result: [[1], [0]]\nresult = argmin_use_numpy_select_last_index(data, axis=axis, keepdims=keepdims)\nexpect(node, inputs=[data], outputs=[result], name='test_argmin_negative_axis_keepdims_example_select_last_index')\n\ndata = np.random.uniform(-10, 10, [2, 3, 4]).astype(np.float32)\n# result's shape: [2, 3, 1]\nresult = argmin_use_numpy_select_last_index(data, axis=axis, keepdims=keepdims)\nexpect(node, inputs=[data], outputs=[result], name='test_argmin_negative_axis_keepdims_random_select_last_index')" + }, + { + "summary": "no_keepdims", + "code": "data = np.array([[2, 1], [3, 10]], dtype=np.float32)\naxis = 1\nkeepdims = 0\nnode = onnx.helper.make_node(\n 'ArgMin',\n inputs=['data'],\n outputs=['result'],\n axis=axis,\n keepdims=keepdims)\n# The content of result is : [[1, 0]]\nresult = argmin_use_numpy(data, axis=axis, keepdims=keepdims)\nexpect(node, inputs=[data], outputs=[result], name='test_argmin_no_keepdims_example')\n\ndata = np.random.uniform(-10, 10, [2, 3, 4]).astype(np.float32)\n# result's shape: [2, 4]\nresult = argmin_use_numpy(data, axis=axis, keepdims=keepdims)\nexpect(node, inputs=[data], outputs=[result], name='test_argmin_no_keepdims_random')" + }, + { + "summary": "no_keepdims_select_last_index", + "code": "data = np.array([[2, 2], [3, 10]], dtype=np.float32)\naxis = 1\nkeepdims = 0\nnode = onnx.helper.make_node(\n 'ArgMin',\n inputs=['data'],\n outputs=['result'],\n axis=axis,\n keepdims=keepdims,\n select_last_index=True)\n# result: [[1, 0]]\nresult = argmin_use_numpy_select_last_index(data, axis=axis, keepdims=keepdims)\nexpect(node, inputs=[data], outputs=[result], name='test_argmin_no_keepdims_example_select_last_index')\n\ndata = np.random.uniform(-10, 10, [2, 3, 4]).astype(np.float32)\n# result's shape: [2, 4]\nresult = argmin_use_numpy_select_last_index(data, axis=axis, keepdims=keepdims)\nexpect(node, inputs=[data], outputs=[result], name='test_argmin_no_keepdims_random_select_last_index')" + } + ] + }, + { + "name": "ArgMin", + "module": "ai.onnx", + "version": 12, + "support_level": "common", + "description": "Computes the indices of the min elements of the input tensor's element along the\nprovided axis. The resulting tensor has the same rank as the input if keepdims equal 1.\nIf keepdims equal 0, then the resulting tensor have the reduced dimension pruned.\nIf select_last_index is True (default False), the index of the last occurrence of the min\nis selected if the min appears more than once in the input. Otherwise the index of the\nfirst occurrence is selected.\nThe type of the output tensor is integer.", + "attributes": [ + { + "name": "axis", + "type": "int64", + "required": false, + "description": "The axis in which to compute the arg indices. Accepted range is [-r, r-1] where r = rank(data)." + }, + { + "name": "keepdims", + "type": "int64", + "required": false, + "default": 1, + "description": "Keep the reduced dimension or not, default 1 mean keep reduced dimension." + }, + { + "name": "select_last_index", + "type": "int64", + "required": false, + "description": "Whether to select the last index or the first index if the {name} appears in multiple indices, default is False (first index)." + } + ], + "inputs": [ + { + "name": "data", + "type": "T", + "description": "An input tensor." + } + ], + "min_input": 1, + "max_input": 1, + "outputs": [ + { + "name": "reduced", + "type": "tensor(int64)", + "description": "Reduced output tensor with integer data type." + } + ], + "min_output": 1, + "max_output": 1, + "type_constraints": [ + { + "description": "Constrain input and output types to all numeric tensors.", + "type_param_str": "T", + "allowed_type_strs": [ + "tensor(uint8)", + "tensor(uint16)", + "tensor(uint32)", + "tensor(uint64)", + "tensor(int8)", + "tensor(int16)", + "tensor(int32)", + "tensor(int64)", + "tensor(float16)", + "tensor(float)", + "tensor(double)" + ] + } + ], + "examples": [ + { + "summary": "default_axes_keepdims", + "code": "data = np.array([[2, 1], [3, 10]], dtype=np.float32)\nkeepdims = 1\nnode = onnx.helper.make_node(\n 'ArgMin',\n inputs=['data'],\n outputs=['result'],\n keepdims=keepdims)\n\n# The content of result is : [[0], [0]]\nresult = argmin_use_numpy(data, keepdims=keepdims)\nexpect(node, inputs=[data], outputs=[result], name='test_argmin_default_axis_example')\n\ndata = np.random.uniform(-10, 10, [2, 3, 4]).astype(np.float32)\n# result's shape: [1, 3, 4]\nresult = argmin_use_numpy(data, keepdims=keepdims)\nexpect(node, inputs=[data], outputs=[result], name='test_argmin_default_axis_random')" + }, + { + "summary": "default_axes_keepdims_select_last_index", + "code": "data = np.array([[2, 2], [3, 10]], dtype=np.float32)\nkeepdims = 1\nnode = onnx.helper.make_node(\n 'ArgMin',\n inputs=['data'],\n outputs=['result'],\n keepdims=keepdims,\n select_last_index=True)\n\n# result: [[0, 0]]\nresult = argmin_use_numpy_select_last_index(data, keepdims=keepdims)\nexpect(node, inputs=[data], outputs=[result], name='test_argmin_default_axis_example_select_last_index')\n\ndata = np.random.uniform(-10, 10, [2, 3, 4]).astype(np.float32)\n# result's shape: [1, 3, 4]\nresult = argmin_use_numpy_select_last_index(data, keepdims=keepdims)\nexpect(node, inputs=[data], outputs=[result], name='test_argmin_default_axis_random_select_last_index')" + }, + { + "summary": "keepdims", + "code": "data = np.array([[2, 1], [3, 10]], dtype=np.float32)\naxis = 1\nkeepdims = 1\nnode = onnx.helper.make_node(\n 'ArgMin',\n inputs=['data'],\n outputs=['result'],\n axis=axis,\n keepdims=keepdims)\n# The content of result is : [[1], [0]]\nresult = argmin_use_numpy(data, axis=axis, keepdims=keepdims)\nexpect(node, inputs=[data], outputs=[result], name='test_argmin_keepdims_example')\n\ndata = np.random.uniform(-10, 10, [2, 3, 4]).astype(np.float32)\n# result's shape: [2, 1, 4]\nresult = argmin_use_numpy(data, axis=axis, keepdims=keepdims)\nexpect(node, inputs=[data], outputs=[result], name='test_argmin_keepdims_random')" + }, + { + "summary": "keepdims_select_last_index", + "code": "data = np.array([[2, 2], [3, 10]], dtype=np.float32)\naxis = 1\nkeepdims = 1\nnode = onnx.helper.make_node(\n 'ArgMin',\n inputs=['data'],\n outputs=['result'],\n axis=axis,\n keepdims=keepdims,\n select_last_index=True)\n# result: [[1], [0]]\nresult = argmin_use_numpy_select_last_index(data, axis=axis, keepdims=keepdims)\nexpect(node, inputs=[data], outputs=[result], name='test_argmin_keepdims_example_select_last_index')\n\ndata = np.random.uniform(-10, 10, [2, 3, 4]).astype(np.float32)\n# result's shape: [2, 1, 4]\nresult = argmin_use_numpy_select_last_index(data, axis=axis, keepdims=keepdims)\nexpect(node, inputs=[data], outputs=[result], name='test_argmin_keepdims_random_select_last_index')" + }, + { + "summary": "negative_axis_keepdims", + "code": "data = np.array([[2, 1], [3, 10]], dtype=np.float32)\naxis = -1\nkeepdims = 1\nnode = onnx.helper.make_node(\n 'ArgMin',\n inputs=['data'],\n outputs=['result'],\n axis=axis,\n keepdims=keepdims)\n# The content of result is : [[1], [0]]\nresult = argmin_use_numpy(data, axis=axis, keepdims=keepdims)\nexpect(node, inputs=[data], outputs=[result], name='test_argmin_negative_axis_keepdims_example')\n\ndata = np.random.uniform(-10, 10, [2, 3, 4]).astype(np.float32)\n# result's shape: [2, 3, 1]\nresult = argmin_use_numpy(data, axis=axis, keepdims=keepdims)\nexpect(node, inputs=[data], outputs=[result], name='test_argmin_negative_axis_keepdims_random')" + }, + { + "summary": "negative_axis_keepdims_select_last_index", + "code": "data = np.array([[2, 2], [3, 10]], dtype=np.float32)\naxis = -1\nkeepdims = 1\nnode = onnx.helper.make_node(\n 'ArgMin',\n inputs=['data'],\n outputs=['result'],\n axis=axis,\n keepdims=keepdims,\n select_last_index=True)\n# result: [[1], [0]]\nresult = argmin_use_numpy_select_last_index(data, axis=axis, keepdims=keepdims)\nexpect(node, inputs=[data], outputs=[result], name='test_argmin_negative_axis_keepdims_example_select_last_index')\n\ndata = np.random.uniform(-10, 10, [2, 3, 4]).astype(np.float32)\n# result's shape: [2, 3, 1]\nresult = argmin_use_numpy_select_last_index(data, axis=axis, keepdims=keepdims)\nexpect(node, inputs=[data], outputs=[result], name='test_argmin_negative_axis_keepdims_random_select_last_index')" + }, + { + "summary": "no_keepdims", + "code": "data = np.array([[2, 1], [3, 10]], dtype=np.float32)\naxis = 1\nkeepdims = 0\nnode = onnx.helper.make_node(\n 'ArgMin',\n inputs=['data'],\n outputs=['result'],\n axis=axis,\n keepdims=keepdims)\n# The content of result is : [[1, 0]]\nresult = argmin_use_numpy(data, axis=axis, keepdims=keepdims)\nexpect(node, inputs=[data], outputs=[result], name='test_argmin_no_keepdims_example')\n\ndata = np.random.uniform(-10, 10, [2, 3, 4]).astype(np.float32)\n# result's shape: [2, 4]\nresult = argmin_use_numpy(data, axis=axis, keepdims=keepdims)\nexpect(node, inputs=[data], outputs=[result], name='test_argmin_no_keepdims_random')" + }, + { + "summary": "no_keepdims_select_last_index", + "code": "data = np.array([[2, 2], [3, 10]], dtype=np.float32)\naxis = 1\nkeepdims = 0\nnode = onnx.helper.make_node(\n 'ArgMin',\n inputs=['data'],\n outputs=['result'],\n axis=axis,\n keepdims=keepdims,\n select_last_index=True)\n# result: [[1, 0]]\nresult = argmin_use_numpy_select_last_index(data, axis=axis, keepdims=keepdims)\nexpect(node, inputs=[data], outputs=[result], name='test_argmin_no_keepdims_example_select_last_index')\n\ndata = np.random.uniform(-10, 10, [2, 3, 4]).astype(np.float32)\n# result's shape: [2, 4]\nresult = argmin_use_numpy_select_last_index(data, axis=axis, keepdims=keepdims)\nexpect(node, inputs=[data], outputs=[result], name='test_argmin_no_keepdims_random_select_last_index')" + } + ] + }, + { + "name": "ArgMin", + "module": "ai.onnx", + "version": 13, + "support_level": "common", + "description": "Computes the indices of the min elements of the input tensor's element along the\nprovided axis. The resulting tensor has the same rank as the input if keepdims equal 1.\nIf keepdims equal 0, then the resulting tensor have the reduced dimension pruned.\nIf select_last_index is True (default False), the index of the last occurrence of the min\nis selected if the min appears more than once in the input. Otherwise the index of the\nfirst occurrence is selected.\nThe type of the output tensor is integer.", + "attributes": [ + { + "name": "axis", + "type": "int64", + "required": false, + "description": "The axis in which to compute the arg indices. Accepted range is [-r, r-1] where r = rank(data)." + }, + { + "name": "keepdims", + "type": "int64", + "required": false, + "default": 1, + "description": "Keep the reduced dimension or not, default 1 mean keep reduced dimension." + }, + { + "name": "select_last_index", + "type": "int64", + "required": false, + "description": "Whether to select the last index or the first index if the {name} appears in multiple indices, default is False (first index)." + } + ], + "inputs": [ + { + "name": "data", + "type": "T", + "description": "An input tensor." + } + ], + "min_input": 1, + "max_input": 1, + "outputs": [ + { + "name": "reduced", + "type": "tensor(int64)", + "description": "Reduced output tensor with integer data type." + } + ], + "min_output": 1, + "max_output": 1, + "type_constraints": [ + { + "description": "Constrain input and output types to all numeric tensors.", + "type_param_str": "T", + "allowed_type_strs": [ + "tensor(uint8)", + "tensor(uint16)", + "tensor(uint32)", + "tensor(uint64)", + "tensor(int8)", + "tensor(int16)", + "tensor(int32)", + "tensor(int64)", + "tensor(float16)", + "tensor(float)", + "tensor(double)", + "tensor(bfloat16)" + ] + } + ], + "examples": [ + { + "summary": "default_axes_keepdims", + "code": "data = np.array([[2, 1], [3, 10]], dtype=np.float32)\nkeepdims = 1\nnode = onnx.helper.make_node(\n 'ArgMin',\n inputs=['data'],\n outputs=['result'],\n keepdims=keepdims)\n\n# The content of result is : [[0], [0]]\nresult = argmin_use_numpy(data, keepdims=keepdims)\nexpect(node, inputs=[data], outputs=[result], name='test_argmin_default_axis_example')\n\ndata = np.random.uniform(-10, 10, [2, 3, 4]).astype(np.float32)\n# result's shape: [1, 3, 4]\nresult = argmin_use_numpy(data, keepdims=keepdims)\nexpect(node, inputs=[data], outputs=[result], name='test_argmin_default_axis_random')" + }, + { + "summary": "default_axes_keepdims_select_last_index", + "code": "data = np.array([[2, 2], [3, 10]], dtype=np.float32)\nkeepdims = 1\nnode = onnx.helper.make_node(\n 'ArgMin',\n inputs=['data'],\n outputs=['result'],\n keepdims=keepdims,\n select_last_index=True)\n\n# result: [[0, 0]]\nresult = argmin_use_numpy_select_last_index(data, keepdims=keepdims)\nexpect(node, inputs=[data], outputs=[result], name='test_argmin_default_axis_example_select_last_index')\n\ndata = np.random.uniform(-10, 10, [2, 3, 4]).astype(np.float32)\n# result's shape: [1, 3, 4]\nresult = argmin_use_numpy_select_last_index(data, keepdims=keepdims)\nexpect(node, inputs=[data], outputs=[result], name='test_argmin_default_axis_random_select_last_index')" + }, + { + "summary": "keepdims", + "code": "data = np.array([[2, 1], [3, 10]], dtype=np.float32)\naxis = 1\nkeepdims = 1\nnode = onnx.helper.make_node(\n 'ArgMin',\n inputs=['data'],\n outputs=['result'],\n axis=axis,\n keepdims=keepdims)\n# The content of result is : [[1], [0]]\nresult = argmin_use_numpy(data, axis=axis, keepdims=keepdims)\nexpect(node, inputs=[data], outputs=[result], name='test_argmin_keepdims_example')\n\ndata = np.random.uniform(-10, 10, [2, 3, 4]).astype(np.float32)\n# result's shape: [2, 1, 4]\nresult = argmin_use_numpy(data, axis=axis, keepdims=keepdims)\nexpect(node, inputs=[data], outputs=[result], name='test_argmin_keepdims_random')" + }, + { + "summary": "keepdims_select_last_index", + "code": "data = np.array([[2, 2], [3, 10]], dtype=np.float32)\naxis = 1\nkeepdims = 1\nnode = onnx.helper.make_node(\n 'ArgMin',\n inputs=['data'],\n outputs=['result'],\n axis=axis,\n keepdims=keepdims,\n select_last_index=True)\n# result: [[1], [0]]\nresult = argmin_use_numpy_select_last_index(data, axis=axis, keepdims=keepdims)\nexpect(node, inputs=[data], outputs=[result], name='test_argmin_keepdims_example_select_last_index')\n\ndata = np.random.uniform(-10, 10, [2, 3, 4]).astype(np.float32)\n# result's shape: [2, 1, 4]\nresult = argmin_use_numpy_select_last_index(data, axis=axis, keepdims=keepdims)\nexpect(node, inputs=[data], outputs=[result], name='test_argmin_keepdims_random_select_last_index')" + }, + { + "summary": "negative_axis_keepdims", + "code": "data = np.array([[2, 1], [3, 10]], dtype=np.float32)\naxis = -1\nkeepdims = 1\nnode = onnx.helper.make_node(\n 'ArgMin',\n inputs=['data'],\n outputs=['result'],\n axis=axis,\n keepdims=keepdims)\n# The content of result is : [[1], [0]]\nresult = argmin_use_numpy(data, axis=axis, keepdims=keepdims)\nexpect(node, inputs=[data], outputs=[result], name='test_argmin_negative_axis_keepdims_example')\n\ndata = np.random.uniform(-10, 10, [2, 3, 4]).astype(np.float32)\n# result's shape: [2, 3, 1]\nresult = argmin_use_numpy(data, axis=axis, keepdims=keepdims)\nexpect(node, inputs=[data], outputs=[result], name='test_argmin_negative_axis_keepdims_random')" + }, + { + "summary": "negative_axis_keepdims_select_last_index", + "code": "data = np.array([[2, 2], [3, 10]], dtype=np.float32)\naxis = -1\nkeepdims = 1\nnode = onnx.helper.make_node(\n 'ArgMin',\n inputs=['data'],\n outputs=['result'],\n axis=axis,\n keepdims=keepdims,\n select_last_index=True)\n# result: [[1], [0]]\nresult = argmin_use_numpy_select_last_index(data, axis=axis, keepdims=keepdims)\nexpect(node, inputs=[data], outputs=[result], name='test_argmin_negative_axis_keepdims_example_select_last_index')\n\ndata = np.random.uniform(-10, 10, [2, 3, 4]).astype(np.float32)\n# result's shape: [2, 3, 1]\nresult = argmin_use_numpy_select_last_index(data, axis=axis, keepdims=keepdims)\nexpect(node, inputs=[data], outputs=[result], name='test_argmin_negative_axis_keepdims_random_select_last_index')" + }, + { + "summary": "no_keepdims", + "code": "data = np.array([[2, 1], [3, 10]], dtype=np.float32)\naxis = 1\nkeepdims = 0\nnode = onnx.helper.make_node(\n 'ArgMin',\n inputs=['data'],\n outputs=['result'],\n axis=axis,\n keepdims=keepdims)\n# The content of result is : [[1, 0]]\nresult = argmin_use_numpy(data, axis=axis, keepdims=keepdims)\nexpect(node, inputs=[data], outputs=[result], name='test_argmin_no_keepdims_example')\n\ndata = np.random.uniform(-10, 10, [2, 3, 4]).astype(np.float32)\n# result's shape: [2, 4]\nresult = argmin_use_numpy(data, axis=axis, keepdims=keepdims)\nexpect(node, inputs=[data], outputs=[result], name='test_argmin_no_keepdims_random')" + }, + { + "summary": "no_keepdims_select_last_index", + "code": "data = np.array([[2, 2], [3, 10]], dtype=np.float32)\naxis = 1\nkeepdims = 0\nnode = onnx.helper.make_node(\n 'ArgMin',\n inputs=['data'],\n outputs=['result'],\n axis=axis,\n keepdims=keepdims,\n select_last_index=True)\n# result: [[1, 0]]\nresult = argmin_use_numpy_select_last_index(data, axis=axis, keepdims=keepdims)\nexpect(node, inputs=[data], outputs=[result], name='test_argmin_no_keepdims_example_select_last_index')\n\ndata = np.random.uniform(-10, 10, [2, 3, 4]).astype(np.float32)\n# result's shape: [2, 4]\nresult = argmin_use_numpy_select_last_index(data, axis=axis, keepdims=keepdims)\nexpect(node, inputs=[data], outputs=[result], name='test_argmin_no_keepdims_random_select_last_index')" + } + ] + }, + { + "name": "ArrayFeatureExtractor", + "module": "ai.onnx.ml", + "version": 1, + "support_level": "common", + "description": "Select elements of the input tensor based on the indices passed.
\n The indices are applied to the last axes of the tensor.\n", + "inputs": [ + { + "name": "X", + "type": "T", + "description": "Data to be selected" + }, + { + "name": "Y", + "type": "tensor(int64)", + "description": "The indices, based on 0 as the first index of any dimension." + } + ], + "min_input": 2, + "max_input": 2, + "outputs": [ + { + "name": "Z", + "type": "T", + "description": "Selected output data as an array" + } + ], + "min_output": 1, + "max_output": 1, + "type_constraints": [ + { + "description": "The input must be a tensor of a numeric type or string. The output will be of the same tensor type.", + "type_param_str": "T", + "allowed_type_strs": [ + "tensor(float)", + "tensor(double)", + "tensor(int64)", + "tensor(int32)", + "tensor(string)" + ] + } + ] + }, + { + "name": "Asin", + "module": "ai.onnx", + "version": 7, + "support_level": "common", + "description": "Calculates the arcsine (inverse of sine) of the given input tensor, element-wise.\n", + "inputs": [ + { + "name": "input", + "type": "T", + "description": "Input tensor" + } + ], + "min_input": 1, + "max_input": 1, + "outputs": [ + { + "name": "output", + "type": "T", + "description": "The arcsine of the input tensor computed element-wise" + } + ], + "min_output": 1, + "max_output": 1, + "type_constraints": [ + { + "description": "Constrain input and output types to float tensors.", + "type_param_str": "T", + "allowed_type_strs": [ + "tensor(float16)", + "tensor(float)", + "tensor(double)" + ] + } + ], + "examples": [ + { + "summary": "asin", + "code": "node = onnx.helper.make_node(\n 'Asin',\n inputs=['x'],\n outputs=['y'],\n)\n\nx = np.array([-0.5, 0, 0.5]).astype(np.float32)\ny = np.arcsin(x)\nexpect(node, inputs=[x], outputs=[y],\n name='test_asin_example')\n\nx = np.random.rand(3, 4, 5).astype(np.float32)\ny = np.arcsin(x)\nexpect(node, inputs=[x], outputs=[y],\n name='test_asin')" + } + ] + }, + { + "name": "Asinh", + "module": "ai.onnx", + "version": 9, + "support_level": "common", + "description": "Calculates the hyperbolic arcsine of the given input tensor element-wise.\n", + "inputs": [ + { + "name": "input", + "type": "T", + "description": "Input tensor" + } + ], + "min_input": 1, + "max_input": 1, + "outputs": [ + { + "name": "output", + "type": "T", + "description": "The hyperbolic arcsine values of the input tensor computed element-wise" + } + ], + "min_output": 1, + "max_output": 1, + "type_constraints": [ + { + "description": "Constrain input and output types to float tensors.", + "type_param_str": "T", + "allowed_type_strs": [ + "tensor(float16)", + "tensor(float)", + "tensor(double)" + ] + } + ], + "examples": [ + { + "summary": "asinh", + "code": "node = onnx.helper.make_node(\n 'Asinh',\n inputs=['x'],\n outputs=['y'],\n)\n\nx = np.array([-1, 0, 1]).astype(np.float32)\ny = np.arcsinh(x) # expected output [-0.88137358, 0., 0.88137358]\nexpect(node, inputs=[x], outputs=[y],\n name='test_asinh_example')\n\nx = np.random.randn(3, 4, 5).astype(np.float32)\ny = np.arcsinh(x)\nexpect(node, inputs=[x], outputs=[y],\n name='test_asinh')" + } + ] + }, + { + "name": "Atan", + "module": "ai.onnx", + "version": 7, + "support_level": "common", + "description": "Calculates the arctangent (inverse of tangent) of the given input tensor, element-wise.\n", + "inputs": [ + { + "name": "input", + "type": "T", + "description": "Input tensor" + } + ], + "min_input": 1, + "max_input": 1, + "outputs": [ + { + "name": "output", + "type": "T", + "description": "The arctangent of the input tensor computed element-wise" + } + ], + "min_output": 1, + "max_output": 1, + "type_constraints": [ + { + "description": "Constrain input and output types to float tensors.", + "type_param_str": "T", + "allowed_type_strs": [ + "tensor(float16)", + "tensor(float)", + "tensor(double)" + ] + } + ], + "examples": [ + { + "summary": "atan", + "code": "node = onnx.helper.make_node(\n 'Atan',\n inputs=['x'],\n outputs=['y'],\n)\n\nx = np.array([-1, 0, 1]).astype(np.float32)\ny = np.arctan(x)\nexpect(node, inputs=[x], outputs=[y],\n name='test_atan_example')\n\nx = np.random.randn(3, 4, 5).astype(np.float32)\ny = np.arctan(x)\nexpect(node, inputs=[x], outputs=[y],\n name='test_atan')" + } + ] + }, + { + "name": "Atanh", + "module": "ai.onnx", + "version": 9, + "support_level": "common", + "description": "Calculates the hyperbolic arctangent of the given input tensor element-wise.\n", + "inputs": [ + { + "name": "input", + "type": "T", + "description": "Input tensor" + } + ], + "min_input": 1, + "max_input": 1, + "outputs": [ + { + "name": "output", + "type": "T", + "description": "The hyperbolic arctangent values of the input tensor computed element-wise" + } + ], + "min_output": 1, + "max_output": 1, + "type_constraints": [ + { + "description": "Constrain input and output types to float tensors.", + "type_param_str": "T", + "allowed_type_strs": [ + "tensor(float16)", + "tensor(float)", + "tensor(double)" + ] + } + ], + "examples": [ + { + "summary": "atanh", + "code": "node = onnx.helper.make_node(\n 'Atanh',\n inputs=['x'],\n outputs=['y'],\n)\n\nx = np.array([-0.5, 0, 0.5]).astype(np.float32)\ny = np.arctanh(x) # expected output [-0.54930615, 0., 0.54930615]\nexpect(node, inputs=[x], outputs=[y],\n name='test_atanh_example')\n\nx = np.random.uniform(0.0, 1.0, (3, 4, 5)).astype(np.float32)\ny = np.arctanh(x)\nexpect(node, inputs=[x], outputs=[y],\n name='test_atanh')" + } + ] + }, + { + "name": "AveragePool", + "module": "ai.onnx", + "version": 1, + "support_level": "common", + "description": "AveragePool consumes an input tensor X and applies average pooling across\n the tensor according to kernel sizes, stride sizes, and pad lengths.\n average pooling consisting of computing the average on all values of a\n subset of the input tensor according to the kernel size and downsampling the\n data into the output tensor Y for further processing. The output spatial shape will be following:\n ```\n output_spatial_shape[i] = floor((input_spatial_shape[i] + pad_shape[i] - kernel_spatial_shape[i]) / strides_spatial_shape[i] + 1)\n\n * pad_shape[i] is sum of pads along axis i\n ```\n\n `auto_pad` is a DEPRECATED attribute. If you are using them currently, the output spatial shape will be following:\n ```\n VALID: output_spatial_shape[i] = ceil((input_spatial_shape[i] - kernel_spatial_shape[i] + 1) / strides_spatial_shape[i])\n SAME_UPPER or SAME_LOWER: output_spatial_shape[i] = ceil(input_spatial_shape[i] / strides_spatial_shape[i])\n ```\n And pad shape will be following if `SAME_UPPER` or `SAME_LOWER`:\n ```\n pad_shape[i] = (output_spatial_shape[i] - 1) * strides_spatial_shape[i] + kernel_spatial_shape[i] - input_spatial_shape[i]\n ```\n The output of each pooling window is divided by the number of elements exclude pad.\n ", + "attributes": [ + { + "name": "auto_pad", + "type": "string", + "required": false, + "default": "NOTSET", + "description": "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." + }, + { + "name": "kernel_shape", + "type": "int64[]", + "required": true, + "description": "The size of the kernel along each axis." + }, + { + "name": "pads", + "type": "int64[]", + "required": false, + "description": "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." + }, + { + "name": "strides", + "type": "int64[]", + "required": false, + "description": "Stride along each spatial axis." + } + ], + "inputs": [ + { + "name": "X", + "type": "T", + "description": "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 ...]." + } + ], + "min_input": 1, + "max_input": 1, + "outputs": [ + { + "name": "Y", + "type": "T", + "description": "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" + } + ], + "min_output": 1, + "max_output": 1, + "type_constraints": [ + { + "description": "Constrain input and output types to float tensors.", + "type_param_str": "T", + "allowed_type_strs": [ + "tensor(float16)", + "tensor(float)", + "tensor(double)" + ] + } + ], + "examples": [ + { + "summary": "averagepool_1d_default", + "code": "\"\"\"\ninput_shape: [1, 3, 32]\noutput_shape: [1, 3, 31]\n\"\"\"\nnode = onnx.helper.make_node(\n 'AveragePool',\n inputs=['x'],\n outputs=['y'],\n kernel_shape=[2],\n)\nx = np.random.randn(1, 3, 32).astype(np.float32)\nx_shape = np.shape(x)\nkernel_shape = [2]\nstrides = [1]\nout_shape = get_output_shape('VALID', x_shape[2:], kernel_shape, strides)\npadded = x\ny = pool(padded, x_shape, kernel_shape, strides, out_shape, [0], 'AVG')\n\nexpect(node, inputs=[x], outputs=[y], name='test_averagepool_1d_default')" + }, + { + "summary": "averagepool_2d_ceil", + "code": "\"\"\"\ninput_shape: [1, 1, 4, 4]\noutput_shape: [1, 1, 2, 2]\n\"\"\"\nnode = onnx.helper.make_node(\n 'AveragePool',\n inputs=['x'],\n outputs=['y'],\n kernel_shape=[3, 3],\n strides=[2, 2],\n ceil_mode=True\n)\nx = np.array([[[\n [1, 2, 3, 4],\n [5, 6, 7, 8],\n [9, 10, 11, 12],\n [13, 14, 15, 16],\n]]]).astype(np.float32)\ny = np.array([[[\n [6, 7.5],\n [12, 13.5]]]]).astype(np.float32)\n\nexpect(node, inputs=[x], outputs=[y], name='test_averagepool_2d_ceil')" + }, + { + "summary": "averagepool_2d_default", + "code": "\"\"\"\ninput_shape: [1, 3, 32, 32]\noutput_shape: [1, 3, 31, 31]\n\"\"\"\nnode = onnx.helper.make_node(\n 'AveragePool',\n inputs=['x'],\n outputs=['y'],\n kernel_shape=[2, 2],\n)\nx = np.random.randn(1, 3, 32, 32).astype(np.float32)\nx_shape = np.shape(x)\nkernel_shape = (2, 2)\nstrides = (1, 1)\nout_shape = get_output_shape('VALID', x_shape[2:], kernel_shape, strides)\npadded = x\ny = pool(padded, x_shape, kernel_shape, strides, out_shape, (0, 0), 'AVG')\n\nexpect(node, inputs=[x], outputs=[y], name='test_averagepool_2d_default')" + }, + { + "summary": "averagepool_2d_pads", + "code": "\"\"\"\ninput_shape: [1, 3, 28, 28]\noutput_shape: [1, 3, 30, 30]\npad_shape: [4, 4] -> [2, 2, 2, 2] by axis\n\"\"\"\nnode = onnx.helper.make_node(\n 'AveragePool',\n inputs=['x'],\n outputs=['y'],\n kernel_shape=[3, 3],\n pads=[2, 2, 2, 2]\n)\nx = np.random.randn(1, 3, 28, 28).astype(np.float32)\nx_shape = np.shape(x)\nkernel_shape = (3, 3)\nstrides = (1, 1)\npad_bottom = 2\npad_top = 2\npad_right = 2\npad_left = 2\npad_shape = [pad_top + pad_bottom, pad_left + pad_right]\nout_shape = get_output_shape('VALID', np.add(x_shape[2:], pad_shape), kernel_shape, strides)\npadded = np.pad(x, ((0, 0), (0, 0), (pad_top, pad_bottom), (pad_left, pad_right)), mode='constant',\n constant_values=np.nan)\ny = pool(padded, x_shape, kernel_shape, strides, out_shape, pad_shape, 'AVG')\n\nexpect(node, inputs=[x], outputs=[y], name='test_averagepool_2d_pads')" + }, + { + "summary": "averagepool_2d_pads_count_include_pad", + "code": "\"\"\"\ninput_shape: [1, 3, 28, 28]\noutput_shape: [1, 3, 30, 30]\npad_shape: [4, 4] -> [2, 2, 2, 2] by axis\n\"\"\"\nnode = onnx.helper.make_node(\n 'AveragePool',\n inputs=['x'],\n outputs=['y'],\n kernel_shape=[3, 3],\n pads=[2, 2, 2, 2],\n count_include_pad=1,\n)\nx = np.random.randn(1, 3, 28, 28).astype(np.float32)\nx_shape = np.shape(x)\nkernel_shape = (3, 3)\nstrides = (1, 1)\npad_bottom = 2\npad_top = 2\npad_right = 2\npad_left = 2\npad_shape = [pad_top + pad_bottom, pad_left + pad_right]\nout_shape = get_output_shape('VALID', np.add(x_shape[2:], pad_shape), kernel_shape, strides)\npadded = np.pad(x, ((0, 0), (0, 0), (pad_top, pad_bottom), (pad_left, pad_right)), mode='constant',\n constant_values=0)\ny = pool(padded, x_shape, kernel_shape, strides, out_shape, pad_shape, 'AVG', count_include_pad=1)\n\nexpect(node, inputs=[x], outputs=[y], name='test_averagepool_2d_pads_count_include_pad')" + }, + { + "summary": "averagepool_2d_precomputed_pads", + "code": "\"\"\"\ninput_shape: [1, 1, 5, 5]\noutput_shape: [1, 1, 5, 5]\npad_shape: [4, 4] -> [2, 2, 2, 2] by axis\n\"\"\"\nnode = onnx.helper.make_node(\n 'AveragePool',\n inputs=['x'],\n outputs=['y'],\n kernel_shape=[5, 5],\n pads=[2, 2, 2, 2]\n\n)\nx = np.array([[[\n [1, 2, 3, 4, 5],\n [6, 7, 8, 9, 10],\n [11, 12, 13, 14, 15],\n [16, 17, 18, 19, 20],\n [21, 22, 23, 24, 25],\n]]]).astype(np.float32)\ny = np.array([[[[7, 7.5, 8, 8.5, 9],\n [9.5, 10, 10.5, 11, 11.5],\n [12, 12.5, 13, 13.5, 14],\n [14.5, 15, 15.5, 16, 16.5],\n [17, 17.5, 18, 18.5, 19]]]]).astype(np.float32)\n\nexpect(node, inputs=[x], outputs=[y], name='test_averagepool_2d_precomputed_pads')" + }, + { + "summary": "averagepool_2d_precomputed_pads_count_include_pad", + "code": "\"\"\"\ninput_shape: [1, 1, 5, 5]\noutput_shape: [1, 1, 5, 5]\npad_shape: [4, 4] -> [2, 2, 2, 2] by axis\n\"\"\"\nnode = onnx.helper.make_node(\n 'AveragePool',\n inputs=['x'],\n outputs=['y'],\n kernel_shape=[5, 5],\n pads=[2, 2, 2, 2],\n count_include_pad=1\n)\nx = np.array([[[\n [1, 2, 3, 4, 5],\n [6, 7, 8, 9, 10],\n [11, 12, 13, 14, 15],\n [16, 17, 18, 19, 20],\n [21, 22, 23, 24, 25],\n]]]).astype(np.float32)\ny = np.array([[[[2.5200, 3.6000, 4.8000, 4.0800, 3.2400],\n [4.5600, 6.4000, 8.4000, 7.0400, 5.5200],\n [7.2000, 10.0000, 13.0000, 10.8000, 8.4000],\n [6.9600, 9.6000, 12.4000, 10.2400, 7.9200],\n [6.1200, 8.4000, 10.8000, 8.8800, 6.8400]]]]).astype(np.float32)\n\nexpect(node, inputs=[x], outputs=[y], name='test_averagepool_2d_precomputed_pads_count_include_pad')" + }, + { + "summary": "averagepool_2d_precomputed_same_upper", + "code": "\"\"\"\ninput_shape: [1, 1, 5, 5]\noutput_shape: [1, 1, 3, 3]\npad_shape: [2, 2] -> [1, 1, 1, 1] by axis\n\"\"\"\nnode = onnx.helper.make_node(\n 'AveragePool',\n inputs=['x'],\n outputs=['y'],\n kernel_shape=[3, 3],\n strides=[2, 2],\n auto_pad='SAME_UPPER'\n)\nx = np.array([[[\n [1, 2, 3, 4, 5],\n [6, 7, 8, 9, 10],\n [11, 12, 13, 14, 15],\n [16, 17, 18, 19, 20],\n [21, 22, 23, 24, 25],\n]]]).astype(np.float32)\ny = np.array([[[[4, 5.5, 7],\n [11.5, 13, 14.5],\n [19, 20.5, 22]]]]).astype(np.float32)\n\nexpect(node, inputs=[x], outputs=[y], name='test_averagepool_2d_precomputed_same_upper')" + }, + { + "summary": "averagepool_2d_precomputed_strides", + "code": "\"\"\"\ninput_shape: [1, 1, 5, 5]\noutput_shape: [1, 1, 2, 2]\n\"\"\"\nnode = onnx.helper.make_node(\n 'AveragePool',\n inputs=['x'],\n outputs=['y'],\n kernel_shape=[2, 2],\n strides=[2, 2]\n)\nx = np.array([[[\n [1, 2, 3, 4, 5],\n [6, 7, 8, 9, 10],\n [11, 12, 13, 14, 15],\n [16, 17, 18, 19, 20],\n [21, 22, 23, 24, 25],\n]]]).astype(np.float32)\ny = np.array([[[[4, 6],\n [14, 16]]]]).astype(np.float32)\n\nexpect(node, inputs=[x], outputs=[y], name='test_averagepool_2d_precomputed_strides')" + }, + { + "summary": "averagepool_2d_same_lower", + "code": "\"\"\"\ninput_shape: [1, 3, 32, 32]\noutput_shape: [1, 3, 32, 32]\npad_shape: [1, 1] -> [1, 0, 1, 0] by axis\n\"\"\"\nnode = onnx.helper.make_node(\n 'AveragePool',\n inputs=['x'],\n outputs=['y'],\n kernel_shape=[2, 2],\n auto_pad='SAME_LOWER'\n)\nx = np.random.randn(1, 3, 32, 32).astype(np.float32)\nx_shape = np.shape(x)\nkernel_shape = (2, 2)\nstrides = (1, 1)\nout_shape = get_output_shape('SAME_LOWER', x_shape[2:], kernel_shape, strides)\npad_shape = get_pad_shape('SAME_LOWER', x_shape[2:], kernel_shape, strides, out_shape)\npad_bottom = pad_shape[0] // 2\npad_top = pad_shape[0] - pad_bottom\npad_right = pad_shape[1] // 2\npad_left = pad_shape[1] - pad_right\npadded = np.pad(x, ((0, 0), (0, 0), (pad_top, pad_bottom), (pad_left, pad_right)), mode='constant',\n constant_values=np.nan)\ny = pool(padded, x_shape, kernel_shape, strides, out_shape, pad_shape, 'AVG')\n\nexpect(node, inputs=[x], outputs=[y], name='test_averagepool_2d_same_lower')" + }, + { + "summary": "averagepool_2d_same_upper", + "code": "\"\"\"\ninput_shape: [1, 3, 32, 32]\noutput_shape: [1, 3, 32, 32]\npad_shape: [1, 1] -> [0, 1, 0, 1] by axis\n\"\"\"\nnode = onnx.helper.make_node(\n 'AveragePool',\n inputs=['x'],\n outputs=['y'],\n kernel_shape=[2, 2],\n auto_pad='SAME_UPPER'\n)\nx = np.random.randn(1, 3, 32, 32).astype(np.float32)\nx_shape = np.shape(x)\nkernel_shape = (2, 2)\nstrides = (1, 1)\nout_shape = get_output_shape('SAME_UPPER', x_shape[2:], kernel_shape, strides)\npad_shape = get_pad_shape('SAME_UPPER', x_shape[2:], kernel_shape, strides, out_shape)\npad_top = pad_shape[0] // 2\npad_bottom = pad_shape[0] - pad_top\npad_left = pad_shape[1] // 2\npad_right = pad_shape[1] - pad_left\npadded = np.pad(x, ((0, 0), (0, 0), (pad_top, pad_bottom), (pad_left, pad_right)), mode='constant',\n constant_values=np.nan)\ny = pool(padded, x_shape, kernel_shape, strides, out_shape, pad_shape, 'AVG')\n\nexpect(node, inputs=[x], outputs=[y], name='test_averagepool_2d_same_upper')" + }, + { + "summary": "averagepool_2d_strides", + "code": "\"\"\"\ninput_shape: [1, 3, 32, 32]\noutput_shape: [1, 3, 10, 10]\n\"\"\"\nnode = onnx.helper.make_node(\n 'AveragePool',\n inputs=['x'],\n outputs=['y'],\n kernel_shape=[5, 5],\n strides=[3, 3]\n)\nx = np.random.randn(1, 3, 32, 32).astype(np.float32)\nx_shape = np.shape(x)\nkernel_shape = (5, 5)\nstrides = (3, 3)\nout_shape = get_output_shape('VALID', x_shape[2:], kernel_shape, strides)\npadded = x\ny = pool(padded, x_shape, kernel_shape, strides, out_shape, (0, 0), 'AVG')\n\nexpect(node, inputs=[x], outputs=[y], name='test_averagepool_2d_strides')" + }, + { + "summary": "averagepool_3d_default", + "code": "\"\"\"\ninput_shape: [1, 3, 32, 32, 32]\noutput_shape: [1, 3, 31, 31, 31]\n\"\"\"\nnode = onnx.helper.make_node(\n 'AveragePool',\n inputs=['x'],\n outputs=['y'],\n kernel_shape=[2, 2, 2],\n)\nx = np.random.randn(1, 3, 32, 32, 32).astype(np.float32)\nx_shape = np.shape(x)\nkernel_shape = [2, 2, 2]\nstrides = [1, 1, 1]\nout_shape = get_output_shape('VALID', x_shape[2:], kernel_shape, strides)\npadded = x\ny = pool(padded, x_shape, kernel_shape, strides, out_shape, [0, 0, 0], 'AVG')\n\nexpect(node, inputs=[x], outputs=[y], name='test_averagepool_3d_default')" + } + ], + "category": "Pool" + }, + { + "name": "AveragePool", + "module": "ai.onnx", + "version": 7, + "support_level": "common", + "description": "AveragePool consumes an input tensor X and applies average pooling across\n the tensor according to kernel sizes, stride sizes, and pad lengths.\n average pooling consisting of computing the average on all values of a\n subset of the input tensor according to the kernel size and downsampling the\n data into the output tensor Y for further processing. The output spatial shape will be following:\n ```\n output_spatial_shape[i] = floor((input_spatial_shape[i] + pad_shape[i] - kernel_spatial_shape[i]) / strides_spatial_shape[i] + 1)\n\n * pad_shape[i] is sum of pads along axis i\n ```\n\n `auto_pad` is a DEPRECATED attribute. If you are using them currently, the output spatial shape will be following:\n ```\n VALID: output_spatial_shape[i] = ceil((input_spatial_shape[i] - kernel_spatial_shape[i] + 1) / strides_spatial_shape[i])\n SAME_UPPER or SAME_LOWER: output_spatial_shape[i] = ceil(input_spatial_shape[i] / strides_spatial_shape[i])\n ```\n And pad shape will be following if `SAME_UPPER` or `SAME_LOWER`:\n ```\n pad_shape[i] = (output_spatial_shape[i] - 1) * strides_spatial_shape[i] + kernel_spatial_shape[i] - input_spatial_shape[i]\n ```\n The output of each pooling window is divided by the number of elements (exclude pad when attribute count_include_pad is zero).\n ", + "attributes": [ + { + "name": "auto_pad", + "type": "string", + "required": false, + "default": "NOTSET", + "description": "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." + }, + { + "name": "count_include_pad", + "type": "int64", + "required": false, + "description": "Whether include pad pixels when calculating values for the edges. Default is 0, doesn't count include pad." + }, + { + "name": "kernel_shape", + "type": "int64[]", + "required": true, + "description": "The size of the kernel along each axis." + }, + { + "name": "pads", + "type": "int64[]", + "required": false, + "description": "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." + }, + { + "name": "strides", + "type": "int64[]", + "required": false, + "description": "Stride along each spatial axis." + } + ], + "inputs": [ + { + "name": "X", + "type": "T", + "description": "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 ...]." + } + ], + "min_input": 1, + "max_input": 1, + "outputs": [ + { + "name": "Y", + "type": "T", + "description": "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" + } + ], + "min_output": 1, + "max_output": 1, + "type_constraints": [ + { + "description": "Constrain input and output types to float tensors.", + "type_param_str": "T", + "allowed_type_strs": [ + "tensor(float16)", + "tensor(float)", + "tensor(double)" + ] + } + ], + "examples": [ + { + "summary": "averagepool_1d_default", + "code": "\"\"\"\ninput_shape: [1, 3, 32]\noutput_shape: [1, 3, 31]\n\"\"\"\nnode = onnx.helper.make_node(\n 'AveragePool',\n inputs=['x'],\n outputs=['y'],\n kernel_shape=[2],\n)\nx = np.random.randn(1, 3, 32).astype(np.float32)\nx_shape = np.shape(x)\nkernel_shape = [2]\nstrides = [1]\nout_shape = get_output_shape('VALID', x_shape[2:], kernel_shape, strides)\npadded = x\ny = pool(padded, x_shape, kernel_shape, strides, out_shape, [0], 'AVG')\n\nexpect(node, inputs=[x], outputs=[y], name='test_averagepool_1d_default')" + }, + { + "summary": "averagepool_2d_ceil", + "code": "\"\"\"\ninput_shape: [1, 1, 4, 4]\noutput_shape: [1, 1, 2, 2]\n\"\"\"\nnode = onnx.helper.make_node(\n 'AveragePool',\n inputs=['x'],\n outputs=['y'],\n kernel_shape=[3, 3],\n strides=[2, 2],\n ceil_mode=True\n)\nx = np.array([[[\n [1, 2, 3, 4],\n [5, 6, 7, 8],\n [9, 10, 11, 12],\n [13, 14, 15, 16],\n]]]).astype(np.float32)\ny = np.array([[[\n [6, 7.5],\n [12, 13.5]]]]).astype(np.float32)\n\nexpect(node, inputs=[x], outputs=[y], name='test_averagepool_2d_ceil')" + }, + { + "summary": "averagepool_2d_default", + "code": "\"\"\"\ninput_shape: [1, 3, 32, 32]\noutput_shape: [1, 3, 31, 31]\n\"\"\"\nnode = onnx.helper.make_node(\n 'AveragePool',\n inputs=['x'],\n outputs=['y'],\n kernel_shape=[2, 2],\n)\nx = np.random.randn(1, 3, 32, 32).astype(np.float32)\nx_shape = np.shape(x)\nkernel_shape = (2, 2)\nstrides = (1, 1)\nout_shape = get_output_shape('VALID', x_shape[2:], kernel_shape, strides)\npadded = x\ny = pool(padded, x_shape, kernel_shape, strides, out_shape, (0, 0), 'AVG')\n\nexpect(node, inputs=[x], outputs=[y], name='test_averagepool_2d_default')" + }, + { + "summary": "averagepool_2d_pads", + "code": "\"\"\"\ninput_shape: [1, 3, 28, 28]\noutput_shape: [1, 3, 30, 30]\npad_shape: [4, 4] -> [2, 2, 2, 2] by axis\n\"\"\"\nnode = onnx.helper.make_node(\n 'AveragePool',\n inputs=['x'],\n outputs=['y'],\n kernel_shape=[3, 3],\n pads=[2, 2, 2, 2]\n)\nx = np.random.randn(1, 3, 28, 28).astype(np.float32)\nx_shape = np.shape(x)\nkernel_shape = (3, 3)\nstrides = (1, 1)\npad_bottom = 2\npad_top = 2\npad_right = 2\npad_left = 2\npad_shape = [pad_top + pad_bottom, pad_left + pad_right]\nout_shape = get_output_shape('VALID', np.add(x_shape[2:], pad_shape), kernel_shape, strides)\npadded = np.pad(x, ((0, 0), (0, 0), (pad_top, pad_bottom), (pad_left, pad_right)), mode='constant',\n constant_values=np.nan)\ny = pool(padded, x_shape, kernel_shape, strides, out_shape, pad_shape, 'AVG')\n\nexpect(node, inputs=[x], outputs=[y], name='test_averagepool_2d_pads')" + }, + { + "summary": "averagepool_2d_pads_count_include_pad", + "code": "\"\"\"\ninput_shape: [1, 3, 28, 28]\noutput_shape: [1, 3, 30, 30]\npad_shape: [4, 4] -> [2, 2, 2, 2] by axis\n\"\"\"\nnode = onnx.helper.make_node(\n 'AveragePool',\n inputs=['x'],\n outputs=['y'],\n kernel_shape=[3, 3],\n pads=[2, 2, 2, 2],\n count_include_pad=1,\n)\nx = np.random.randn(1, 3, 28, 28).astype(np.float32)\nx_shape = np.shape(x)\nkernel_shape = (3, 3)\nstrides = (1, 1)\npad_bottom = 2\npad_top = 2\npad_right = 2\npad_left = 2\npad_shape = [pad_top + pad_bottom, pad_left + pad_right]\nout_shape = get_output_shape('VALID', np.add(x_shape[2:], pad_shape), kernel_shape, strides)\npadded = np.pad(x, ((0, 0), (0, 0), (pad_top, pad_bottom), (pad_left, pad_right)), mode='constant',\n constant_values=0)\ny = pool(padded, x_shape, kernel_shape, strides, out_shape, pad_shape, 'AVG', count_include_pad=1)\n\nexpect(node, inputs=[x], outputs=[y], name='test_averagepool_2d_pads_count_include_pad')" + }, + { + "summary": "averagepool_2d_precomputed_pads", + "code": "\"\"\"\ninput_shape: [1, 1, 5, 5]\noutput_shape: [1, 1, 5, 5]\npad_shape: [4, 4] -> [2, 2, 2, 2] by axis\n\"\"\"\nnode = onnx.helper.make_node(\n 'AveragePool',\n inputs=['x'],\n outputs=['y'],\n kernel_shape=[5, 5],\n pads=[2, 2, 2, 2]\n\n)\nx = np.array([[[\n [1, 2, 3, 4, 5],\n [6, 7, 8, 9, 10],\n [11, 12, 13, 14, 15],\n [16, 17, 18, 19, 20],\n [21, 22, 23, 24, 25],\n]]]).astype(np.float32)\ny = np.array([[[[7, 7.5, 8, 8.5, 9],\n [9.5, 10, 10.5, 11, 11.5],\n [12, 12.5, 13, 13.5, 14],\n [14.5, 15, 15.5, 16, 16.5],\n [17, 17.5, 18, 18.5, 19]]]]).astype(np.float32)\n\nexpect(node, inputs=[x], outputs=[y], name='test_averagepool_2d_precomputed_pads')" + }, + { + "summary": "averagepool_2d_precomputed_pads_count_include_pad", + "code": "\"\"\"\ninput_shape: [1, 1, 5, 5]\noutput_shape: [1, 1, 5, 5]\npad_shape: [4, 4] -> [2, 2, 2, 2] by axis\n\"\"\"\nnode = onnx.helper.make_node(\n 'AveragePool',\n inputs=['x'],\n outputs=['y'],\n kernel_shape=[5, 5],\n pads=[2, 2, 2, 2],\n count_include_pad=1\n)\nx = np.array([[[\n [1, 2, 3, 4, 5],\n [6, 7, 8, 9, 10],\n [11, 12, 13, 14, 15],\n [16, 17, 18, 19, 20],\n [21, 22, 23, 24, 25],\n]]]).astype(np.float32)\ny = np.array([[[[2.5200, 3.6000, 4.8000, 4.0800, 3.2400],\n [4.5600, 6.4000, 8.4000, 7.0400, 5.5200],\n [7.2000, 10.0000, 13.0000, 10.8000, 8.4000],\n [6.9600, 9.6000, 12.4000, 10.2400, 7.9200],\n [6.1200, 8.4000, 10.8000, 8.8800, 6.8400]]]]).astype(np.float32)\n\nexpect(node, inputs=[x], outputs=[y], name='test_averagepool_2d_precomputed_pads_count_include_pad')" + }, + { + "summary": "averagepool_2d_precomputed_same_upper", + "code": "\"\"\"\ninput_shape: [1, 1, 5, 5]\noutput_shape: [1, 1, 3, 3]\npad_shape: [2, 2] -> [1, 1, 1, 1] by axis\n\"\"\"\nnode = onnx.helper.make_node(\n 'AveragePool',\n inputs=['x'],\n outputs=['y'],\n kernel_shape=[3, 3],\n strides=[2, 2],\n auto_pad='SAME_UPPER'\n)\nx = np.array([[[\n [1, 2, 3, 4, 5],\n [6, 7, 8, 9, 10],\n [11, 12, 13, 14, 15],\n [16, 17, 18, 19, 20],\n [21, 22, 23, 24, 25],\n]]]).astype(np.float32)\ny = np.array([[[[4, 5.5, 7],\n [11.5, 13, 14.5],\n [19, 20.5, 22]]]]).astype(np.float32)\n\nexpect(node, inputs=[x], outputs=[y], name='test_averagepool_2d_precomputed_same_upper')" + }, + { + "summary": "averagepool_2d_precomputed_strides", + "code": "\"\"\"\ninput_shape: [1, 1, 5, 5]\noutput_shape: [1, 1, 2, 2]\n\"\"\"\nnode = onnx.helper.make_node(\n 'AveragePool',\n inputs=['x'],\n outputs=['y'],\n kernel_shape=[2, 2],\n strides=[2, 2]\n)\nx = np.array([[[\n [1, 2, 3, 4, 5],\n [6, 7, 8, 9, 10],\n [11, 12, 13, 14, 15],\n [16, 17, 18, 19, 20],\n [21, 22, 23, 24, 25],\n]]]).astype(np.float32)\ny = np.array([[[[4, 6],\n [14, 16]]]]).astype(np.float32)\n\nexpect(node, inputs=[x], outputs=[y], name='test_averagepool_2d_precomputed_strides')" + }, + { + "summary": "averagepool_2d_same_lower", + "code": "\"\"\"\ninput_shape: [1, 3, 32, 32]\noutput_shape: [1, 3, 32, 32]\npad_shape: [1, 1] -> [1, 0, 1, 0] by axis\n\"\"\"\nnode = onnx.helper.make_node(\n 'AveragePool',\n inputs=['x'],\n outputs=['y'],\n kernel_shape=[2, 2],\n auto_pad='SAME_LOWER'\n)\nx = np.random.randn(1, 3, 32, 32).astype(np.float32)\nx_shape = np.shape(x)\nkernel_shape = (2, 2)\nstrides = (1, 1)\nout_shape = get_output_shape('SAME_LOWER', x_shape[2:], kernel_shape, strides)\npad_shape = get_pad_shape('SAME_LOWER', x_shape[2:], kernel_shape, strides, out_shape)\npad_bottom = pad_shape[0] // 2\npad_top = pad_shape[0] - pad_bottom\npad_right = pad_shape[1] // 2\npad_left = pad_shape[1] - pad_right\npadded = np.pad(x, ((0, 0), (0, 0), (pad_top, pad_bottom), (pad_left, pad_right)), mode='constant',\n constant_values=np.nan)\ny = pool(padded, x_shape, kernel_shape, strides, out_shape, pad_shape, 'AVG')\n\nexpect(node, inputs=[x], outputs=[y], name='test_averagepool_2d_same_lower')" + }, + { + "summary": "averagepool_2d_same_upper", + "code": "\"\"\"\ninput_shape: [1, 3, 32, 32]\noutput_shape: [1, 3, 32, 32]\npad_shape: [1, 1] -> [0, 1, 0, 1] by axis\n\"\"\"\nnode = onnx.helper.make_node(\n 'AveragePool',\n inputs=['x'],\n outputs=['y'],\n kernel_shape=[2, 2],\n auto_pad='SAME_UPPER'\n)\nx = np.random.randn(1, 3, 32, 32).astype(np.float32)\nx_shape = np.shape(x)\nkernel_shape = (2, 2)\nstrides = (1, 1)\nout_shape = get_output_shape('SAME_UPPER', x_shape[2:], kernel_shape, strides)\npad_shape = get_pad_shape('SAME_UPPER', x_shape[2:], kernel_shape, strides, out_shape)\npad_top = pad_shape[0] // 2\npad_bottom = pad_shape[0] - pad_top\npad_left = pad_shape[1] // 2\npad_right = pad_shape[1] - pad_left\npadded = np.pad(x, ((0, 0), (0, 0), (pad_top, pad_bottom), (pad_left, pad_right)), mode='constant',\n constant_values=np.nan)\ny = pool(padded, x_shape, kernel_shape, strides, out_shape, pad_shape, 'AVG')\n\nexpect(node, inputs=[x], outputs=[y], name='test_averagepool_2d_same_upper')" + }, + { + "summary": "averagepool_2d_strides", + "code": "\"\"\"\ninput_shape: [1, 3, 32, 32]\noutput_shape: [1, 3, 10, 10]\n\"\"\"\nnode = onnx.helper.make_node(\n 'AveragePool',\n inputs=['x'],\n outputs=['y'],\n kernel_shape=[5, 5],\n strides=[3, 3]\n)\nx = np.random.randn(1, 3, 32, 32).astype(np.float32)\nx_shape = np.shape(x)\nkernel_shape = (5, 5)\nstrides = (3, 3)\nout_shape = get_output_shape('VALID', x_shape[2:], kernel_shape, strides)\npadded = x\ny = pool(padded, x_shape, kernel_shape, strides, out_shape, (0, 0), 'AVG')\n\nexpect(node, inputs=[x], outputs=[y], name='test_averagepool_2d_strides')" + }, + { + "summary": "averagepool_3d_default", + "code": "\"\"\"\ninput_shape: [1, 3, 32, 32, 32]\noutput_shape: [1, 3, 31, 31, 31]\n\"\"\"\nnode = onnx.helper.make_node(\n 'AveragePool',\n inputs=['x'],\n outputs=['y'],\n kernel_shape=[2, 2, 2],\n)\nx = np.random.randn(1, 3, 32, 32, 32).astype(np.float32)\nx_shape = np.shape(x)\nkernel_shape = [2, 2, 2]\nstrides = [1, 1, 1]\nout_shape = get_output_shape('VALID', x_shape[2:], kernel_shape, strides)\npadded = x\ny = pool(padded, x_shape, kernel_shape, strides, out_shape, [0, 0, 0], 'AVG')\n\nexpect(node, inputs=[x], outputs=[y], name='test_averagepool_3d_default')" + } + ], + "category": "Pool" + }, + { + "name": "AveragePool", + "module": "ai.onnx", + "version": 10, + "support_level": "common", + "description": "AveragePool consumes an input tensor X and applies average pooling across\n the tensor according to kernel sizes, stride sizes, and pad lengths.\n average pooling consisting of computing the average on all values of a\n subset of the input tensor according to the kernel size and downsampling the\n data into the output tensor Y for further processing. The output spatial shape will be following:\n ```\n output_spatial_shape[i] = floor((input_spatial_shape[i] + pad_shape[i] - kernel_spatial_shape[i]) / strides_spatial_shape[i] + 1)\n ```\n or\n ```\n output_spatial_shape[i] = ceil((input_spatial_shape[i] + pad_shape[i] - kernel_spatial_shape[i]) / strides_spatial_shape[i] + 1)\n ```\n if ceil_mode is enabled\n\n ```\n * pad_shape[i] is sum of pads along axis i\n ```\n\n `auto_pad` is a DEPRECATED attribute. If you are using them currently, the output spatial shape will be following:\n ```\n VALID: output_spatial_shape[i] = ceil((input_spatial_shape[i] - kernel_spatial_shape[i] + 1) / strides_spatial_shape[i])\n SAME_UPPER or SAME_LOWER: output_spatial_shape[i] = ceil(input_spatial_shape[i] / strides_spatial_shape[i])\n ```\n And pad shape will be following if `SAME_UPPER` or `SAME_LOWER`:\n ```\n pad_shape[i] = (output_spatial_shape[i] - 1) * strides_spatial_shape[i] + kernel_spatial_shape[i] - input_spatial_shape[i]\n ```\n The output of each pooling window is divided by the number of elements (exclude pad when attribute count_include_pad is zero).\n ", + "attributes": [ + { + "name": "auto_pad", + "type": "string", + "required": false, + "default": "NOTSET", + "description": "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." + }, + { + "name": "ceil_mode", + "type": "int64", + "required": false, + "description": "Whether to use ceil or floor (default) to compute the output shape." + }, + { + "name": "count_include_pad", + "type": "int64", + "required": false, + "description": "Whether include pad pixels when calculating values for the edges. Default is 0, doesn't count include pad." + }, + { + "name": "kernel_shape", + "type": "int64[]", + "required": true, + "description": "The size of the kernel along each axis." + }, + { + "name": "pads", + "type": "int64[]", + "required": false, + "description": "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." + }, + { + "name": "strides", + "type": "int64[]", + "required": false, + "description": "Stride along each spatial axis." + } + ], + "inputs": [ + { + "name": "X", + "type": "T", + "description": "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 ...]." + } + ], + "min_input": 1, + "max_input": 1, + "outputs": [ + { + "name": "Y", + "type": "T", + "description": "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" + } + ], + "min_output": 1, + "max_output": 1, + "type_constraints": [ + { + "description": "Constrain input and output types to float tensors.", + "type_param_str": "T", + "allowed_type_strs": [ + "tensor(float16)", + "tensor(float)", + "tensor(double)" + ] + } + ], + "examples": [ + { + "summary": "averagepool_1d_default", + "code": "\"\"\"\ninput_shape: [1, 3, 32]\noutput_shape: [1, 3, 31]\n\"\"\"\nnode = onnx.helper.make_node(\n 'AveragePool',\n inputs=['x'],\n outputs=['y'],\n kernel_shape=[2],\n)\nx = np.random.randn(1, 3, 32).astype(np.float32)\nx_shape = np.shape(x)\nkernel_shape = [2]\nstrides = [1]\nout_shape = get_output_shape('VALID', x_shape[2:], kernel_shape, strides)\npadded = x\ny = pool(padded, x_shape, kernel_shape, strides, out_shape, [0], 'AVG')\n\nexpect(node, inputs=[x], outputs=[y], name='test_averagepool_1d_default')" + }, + { + "summary": "averagepool_2d_ceil", + "code": "\"\"\"\ninput_shape: [1, 1, 4, 4]\noutput_shape: [1, 1, 2, 2]\n\"\"\"\nnode = onnx.helper.make_node(\n 'AveragePool',\n inputs=['x'],\n outputs=['y'],\n kernel_shape=[3, 3],\n strides=[2, 2],\n ceil_mode=True\n)\nx = np.array([[[\n [1, 2, 3, 4],\n [5, 6, 7, 8],\n [9, 10, 11, 12],\n [13, 14, 15, 16],\n]]]).astype(np.float32)\ny = np.array([[[\n [6, 7.5],\n [12, 13.5]]]]).astype(np.float32)\n\nexpect(node, inputs=[x], outputs=[y], name='test_averagepool_2d_ceil')" + }, + { + "summary": "averagepool_2d_default", + "code": "\"\"\"\ninput_shape: [1, 3, 32, 32]\noutput_shape: [1, 3, 31, 31]\n\"\"\"\nnode = onnx.helper.make_node(\n 'AveragePool',\n inputs=['x'],\n outputs=['y'],\n kernel_shape=[2, 2],\n)\nx = np.random.randn(1, 3, 32, 32).astype(np.float32)\nx_shape = np.shape(x)\nkernel_shape = (2, 2)\nstrides = (1, 1)\nout_shape = get_output_shape('VALID', x_shape[2:], kernel_shape, strides)\npadded = x\ny = pool(padded, x_shape, kernel_shape, strides, out_shape, (0, 0), 'AVG')\n\nexpect(node, inputs=[x], outputs=[y], name='test_averagepool_2d_default')" + }, + { + "summary": "averagepool_2d_pads", + "code": "\"\"\"\ninput_shape: [1, 3, 28, 28]\noutput_shape: [1, 3, 30, 30]\npad_shape: [4, 4] -> [2, 2, 2, 2] by axis\n\"\"\"\nnode = onnx.helper.make_node(\n 'AveragePool',\n inputs=['x'],\n outputs=['y'],\n kernel_shape=[3, 3],\n pads=[2, 2, 2, 2]\n)\nx = np.random.randn(1, 3, 28, 28).astype(np.float32)\nx_shape = np.shape(x)\nkernel_shape = (3, 3)\nstrides = (1, 1)\npad_bottom = 2\npad_top = 2\npad_right = 2\npad_left = 2\npad_shape = [pad_top + pad_bottom, pad_left + pad_right]\nout_shape = get_output_shape('VALID', np.add(x_shape[2:], pad_shape), kernel_shape, strides)\npadded = np.pad(x, ((0, 0), (0, 0), (pad_top, pad_bottom), (pad_left, pad_right)), mode='constant',\n constant_values=np.nan)\ny = pool(padded, x_shape, kernel_shape, strides, out_shape, pad_shape, 'AVG')\n\nexpect(node, inputs=[x], outputs=[y], name='test_averagepool_2d_pads')" + }, + { + "summary": "averagepool_2d_pads_count_include_pad", + "code": "\"\"\"\ninput_shape: [1, 3, 28, 28]\noutput_shape: [1, 3, 30, 30]\npad_shape: [4, 4] -> [2, 2, 2, 2] by axis\n\"\"\"\nnode = onnx.helper.make_node(\n 'AveragePool',\n inputs=['x'],\n outputs=['y'],\n kernel_shape=[3, 3],\n pads=[2, 2, 2, 2],\n count_include_pad=1,\n)\nx = np.random.randn(1, 3, 28, 28).astype(np.float32)\nx_shape = np.shape(x)\nkernel_shape = (3, 3)\nstrides = (1, 1)\npad_bottom = 2\npad_top = 2\npad_right = 2\npad_left = 2\npad_shape = [pad_top + pad_bottom, pad_left + pad_right]\nout_shape = get_output_shape('VALID', np.add(x_shape[2:], pad_shape), kernel_shape, strides)\npadded = np.pad(x, ((0, 0), (0, 0), (pad_top, pad_bottom), (pad_left, pad_right)), mode='constant',\n constant_values=0)\ny = pool(padded, x_shape, kernel_shape, strides, out_shape, pad_shape, 'AVG', count_include_pad=1)\n\nexpect(node, inputs=[x], outputs=[y], name='test_averagepool_2d_pads_count_include_pad')" + }, + { + "summary": "averagepool_2d_precomputed_pads", + "code": "\"\"\"\ninput_shape: [1, 1, 5, 5]\noutput_shape: [1, 1, 5, 5]\npad_shape: [4, 4] -> [2, 2, 2, 2] by axis\n\"\"\"\nnode = onnx.helper.make_node(\n 'AveragePool',\n inputs=['x'],\n outputs=['y'],\n kernel_shape=[5, 5],\n pads=[2, 2, 2, 2]\n\n)\nx = np.array([[[\n [1, 2, 3, 4, 5],\n [6, 7, 8, 9, 10],\n [11, 12, 13, 14, 15],\n [16, 17, 18, 19, 20],\n [21, 22, 23, 24, 25],\n]]]).astype(np.float32)\ny = np.array([[[[7, 7.5, 8, 8.5, 9],\n [9.5, 10, 10.5, 11, 11.5],\n [12, 12.5, 13, 13.5, 14],\n [14.5, 15, 15.5, 16, 16.5],\n [17, 17.5, 18, 18.5, 19]]]]).astype(np.float32)\n\nexpect(node, inputs=[x], outputs=[y], name='test_averagepool_2d_precomputed_pads')" + }, + { + "summary": "averagepool_2d_precomputed_pads_count_include_pad", + "code": "\"\"\"\ninput_shape: [1, 1, 5, 5]\noutput_shape: [1, 1, 5, 5]\npad_shape: [4, 4] -> [2, 2, 2, 2] by axis\n\"\"\"\nnode = onnx.helper.make_node(\n 'AveragePool',\n inputs=['x'],\n outputs=['y'],\n kernel_shape=[5, 5],\n pads=[2, 2, 2, 2],\n count_include_pad=1\n)\nx = np.array([[[\n [1, 2, 3, 4, 5],\n [6, 7, 8, 9, 10],\n [11, 12, 13, 14, 15],\n [16, 17, 18, 19, 20],\n [21, 22, 23, 24, 25],\n]]]).astype(np.float32)\ny = np.array([[[[2.5200, 3.6000, 4.8000, 4.0800, 3.2400],\n [4.5600, 6.4000, 8.4000, 7.0400, 5.5200],\n [7.2000, 10.0000, 13.0000, 10.8000, 8.4000],\n [6.9600, 9.6000, 12.4000, 10.2400, 7.9200],\n [6.1200, 8.4000, 10.8000, 8.8800, 6.8400]]]]).astype(np.float32)\n\nexpect(node, inputs=[x], outputs=[y], name='test_averagepool_2d_precomputed_pads_count_include_pad')" + }, + { + "summary": "averagepool_2d_precomputed_same_upper", + "code": "\"\"\"\ninput_shape: [1, 1, 5, 5]\noutput_shape: [1, 1, 3, 3]\npad_shape: [2, 2] -> [1, 1, 1, 1] by axis\n\"\"\"\nnode = onnx.helper.make_node(\n 'AveragePool',\n inputs=['x'],\n outputs=['y'],\n kernel_shape=[3, 3],\n strides=[2, 2],\n auto_pad='SAME_UPPER'\n)\nx = np.array([[[\n [1, 2, 3, 4, 5],\n [6, 7, 8, 9, 10],\n [11, 12, 13, 14, 15],\n [16, 17, 18, 19, 20],\n [21, 22, 23, 24, 25],\n]]]).astype(np.float32)\ny = np.array([[[[4, 5.5, 7],\n [11.5, 13, 14.5],\n [19, 20.5, 22]]]]).astype(np.float32)\n\nexpect(node, inputs=[x], outputs=[y], name='test_averagepool_2d_precomputed_same_upper')" + }, + { + "summary": "averagepool_2d_precomputed_strides", + "code": "\"\"\"\ninput_shape: [1, 1, 5, 5]\noutput_shape: [1, 1, 2, 2]\n\"\"\"\nnode = onnx.helper.make_node(\n 'AveragePool',\n inputs=['x'],\n outputs=['y'],\n kernel_shape=[2, 2],\n strides=[2, 2]\n)\nx = np.array([[[\n [1, 2, 3, 4, 5],\n [6, 7, 8, 9, 10],\n [11, 12, 13, 14, 15],\n [16, 17, 18, 19, 20],\n [21, 22, 23, 24, 25],\n]]]).astype(np.float32)\ny = np.array([[[[4, 6],\n [14, 16]]]]).astype(np.float32)\n\nexpect(node, inputs=[x], outputs=[y], name='test_averagepool_2d_precomputed_strides')" + }, + { + "summary": "averagepool_2d_same_lower", + "code": "\"\"\"\ninput_shape: [1, 3, 32, 32]\noutput_shape: [1, 3, 32, 32]\npad_shape: [1, 1] -> [1, 0, 1, 0] by axis\n\"\"\"\nnode = onnx.helper.make_node(\n 'AveragePool',\n inputs=['x'],\n outputs=['y'],\n kernel_shape=[2, 2],\n auto_pad='SAME_LOWER'\n)\nx = np.random.randn(1, 3, 32, 32).astype(np.float32)\nx_shape = np.shape(x)\nkernel_shape = (2, 2)\nstrides = (1, 1)\nout_shape = get_output_shape('SAME_LOWER', x_shape[2:], kernel_shape, strides)\npad_shape = get_pad_shape('SAME_LOWER', x_shape[2:], kernel_shape, strides, out_shape)\npad_bottom = pad_shape[0] // 2\npad_top = pad_shape[0] - pad_bottom\npad_right = pad_shape[1] // 2\npad_left = pad_shape[1] - pad_right\npadded = np.pad(x, ((0, 0), (0, 0), (pad_top, pad_bottom), (pad_left, pad_right)), mode='constant',\n constant_values=np.nan)\ny = pool(padded, x_shape, kernel_shape, strides, out_shape, pad_shape, 'AVG')\n\nexpect(node, inputs=[x], outputs=[y], name='test_averagepool_2d_same_lower')" + }, + { + "summary": "averagepool_2d_same_upper", + "code": "\"\"\"\ninput_shape: [1, 3, 32, 32]\noutput_shape: [1, 3, 32, 32]\npad_shape: [1, 1] -> [0, 1, 0, 1] by axis\n\"\"\"\nnode = onnx.helper.make_node(\n 'AveragePool',\n inputs=['x'],\n outputs=['y'],\n kernel_shape=[2, 2],\n auto_pad='SAME_UPPER'\n)\nx = np.random.randn(1, 3, 32, 32).astype(np.float32)\nx_shape = np.shape(x)\nkernel_shape = (2, 2)\nstrides = (1, 1)\nout_shape = get_output_shape('SAME_UPPER', x_shape[2:], kernel_shape, strides)\npad_shape = get_pad_shape('SAME_UPPER', x_shape[2:], kernel_shape, strides, out_shape)\npad_top = pad_shape[0] // 2\npad_bottom = pad_shape[0] - pad_top\npad_left = pad_shape[1] // 2\npad_right = pad_shape[1] - pad_left\npadded = np.pad(x, ((0, 0), (0, 0), (pad_top, pad_bottom), (pad_left, pad_right)), mode='constant',\n constant_values=np.nan)\ny = pool(padded, x_shape, kernel_shape, strides, out_shape, pad_shape, 'AVG')\n\nexpect(node, inputs=[x], outputs=[y], name='test_averagepool_2d_same_upper')" + }, + { + "summary": "averagepool_2d_strides", + "code": "\"\"\"\ninput_shape: [1, 3, 32, 32]\noutput_shape: [1, 3, 10, 10]\n\"\"\"\nnode = onnx.helper.make_node(\n 'AveragePool',\n inputs=['x'],\n outputs=['y'],\n kernel_shape=[5, 5],\n strides=[3, 3]\n)\nx = np.random.randn(1, 3, 32, 32).astype(np.float32)\nx_shape = np.shape(x)\nkernel_shape = (5, 5)\nstrides = (3, 3)\nout_shape = get_output_shape('VALID', x_shape[2:], kernel_shape, strides)\npadded = x\ny = pool(padded, x_shape, kernel_shape, strides, out_shape, (0, 0), 'AVG')\n\nexpect(node, inputs=[x], outputs=[y], name='test_averagepool_2d_strides')" + }, + { + "summary": "averagepool_3d_default", + "code": "\"\"\"\ninput_shape: [1, 3, 32, 32, 32]\noutput_shape: [1, 3, 31, 31, 31]\n\"\"\"\nnode = onnx.helper.make_node(\n 'AveragePool',\n inputs=['x'],\n outputs=['y'],\n kernel_shape=[2, 2, 2],\n)\nx = np.random.randn(1, 3, 32, 32, 32).astype(np.float32)\nx_shape = np.shape(x)\nkernel_shape = [2, 2, 2]\nstrides = [1, 1, 1]\nout_shape = get_output_shape('VALID', x_shape[2:], kernel_shape, strides)\npadded = x\ny = pool(padded, x_shape, kernel_shape, strides, out_shape, [0, 0, 0], 'AVG')\n\nexpect(node, inputs=[x], outputs=[y], name='test_averagepool_3d_default')" + } + ], + "category": "Pool" + }, + { + "name": "AveragePool", + "module": "ai.onnx", + "version": 11, + "support_level": "common", + "description": "AveragePool consumes an input tensor X and applies average pooling across\n the tensor according to kernel sizes, stride sizes, and pad lengths.\n average pooling consisting of computing the average on all values of a\n subset of the input tensor according to the kernel size and downsampling the\n data into the output tensor Y for further processing. The output spatial shape will be following:\n ```\n output_spatial_shape[i] = floor((input_spatial_shape[i] + pad_shape[i] - kernel_spatial_shape[i]) / strides_spatial_shape[i] + 1)\n ```\n or\n ```\n output_spatial_shape[i] = ceil((input_spatial_shape[i] + pad_shape[i] - kernel_spatial_shape[i]) / strides_spatial_shape[i] + 1)\n ```\n if ceil_mode is enabled\n\n ```\n * pad_shape[i] is sum of pads along axis i\n ```\n\n `auto_pad` is a DEPRECATED attribute. If you are using them currently, the output spatial shape will be following:\n ```\n VALID: output_spatial_shape[i] = ceil((input_spatial_shape[i] - kernel_spatial_shape[i] + 1) / strides_spatial_shape[i])\n SAME_UPPER or SAME_LOWER: output_spatial_shape[i] = ceil(input_spatial_shape[i] / strides_spatial_shape[i])\n ```\n And pad shape will be following if `SAME_UPPER` or `SAME_LOWER`:\n ```\n pad_shape[i] = (output_spatial_shape[i] - 1) * strides_spatial_shape[i] + kernel_spatial_shape[i] - input_spatial_shape[i]\n ```\n The output of each pooling window is divided by the number of elements (exclude pad when attribute count_include_pad is zero).\n ", + "attributes": [ + { + "name": "auto_pad", + "type": "string", + "required": false, + "default": "NOTSET", + "description": "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." + }, + { + "name": "ceil_mode", + "type": "int64", + "required": false, + "description": "Whether to use ceil or floor (default) to compute the output shape." + }, + { + "name": "count_include_pad", + "type": "int64", + "required": false, + "description": "Whether include pad pixels when calculating values for the edges. Default is 0, doesn't count include pad." + }, + { + "name": "kernel_shape", + "type": "int64[]", + "required": true, + "description": "The size of the kernel along each axis." + }, + { + "name": "pads", + "type": "int64[]", + "required": false, + "description": "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." + }, + { + "name": "strides", + "type": "int64[]", + "required": false, + "description": "Stride along each spatial axis. If not present, the stride defaults to 1 along each spatial axis." + } + ], + "inputs": [ + { + "name": "X", + "type": "T", + "description": "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 ...]." + } + ], + "min_input": 1, + "max_input": 1, + "outputs": [ + { + "name": "Y", + "type": "T", + "description": "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" + } + ], + "min_output": 1, + "max_output": 1, + "type_constraints": [ + { + "description": "Constrain input and output types to float tensors.", + "type_param_str": "T", + "allowed_type_strs": [ + "tensor(float16)", + "tensor(float)", + "tensor(double)" + ] + } + ], + "examples": [ + { + "summary": "averagepool_1d_default", + "code": "\"\"\"\ninput_shape: [1, 3, 32]\noutput_shape: [1, 3, 31]\n\"\"\"\nnode = onnx.helper.make_node(\n 'AveragePool',\n inputs=['x'],\n outputs=['y'],\n kernel_shape=[2],\n)\nx = np.random.randn(1, 3, 32).astype(np.float32)\nx_shape = np.shape(x)\nkernel_shape = [2]\nstrides = [1]\nout_shape = get_output_shape('VALID', x_shape[2:], kernel_shape, strides)\npadded = x\ny = pool(padded, x_shape, kernel_shape, strides, out_shape, [0], 'AVG')\n\nexpect(node, inputs=[x], outputs=[y], name='test_averagepool_1d_default')" + }, + { + "summary": "averagepool_2d_ceil", + "code": "\"\"\"\ninput_shape: [1, 1, 4, 4]\noutput_shape: [1, 1, 2, 2]\n\"\"\"\nnode = onnx.helper.make_node(\n 'AveragePool',\n inputs=['x'],\n outputs=['y'],\n kernel_shape=[3, 3],\n strides=[2, 2],\n ceil_mode=True\n)\nx = np.array([[[\n [1, 2, 3, 4],\n [5, 6, 7, 8],\n [9, 10, 11, 12],\n [13, 14, 15, 16],\n]]]).astype(np.float32)\ny = np.array([[[\n [6, 7.5],\n [12, 13.5]]]]).astype(np.float32)\n\nexpect(node, inputs=[x], outputs=[y], name='test_averagepool_2d_ceil')" + }, + { + "summary": "averagepool_2d_default", + "code": "\"\"\"\ninput_shape: [1, 3, 32, 32]\noutput_shape: [1, 3, 31, 31]\n\"\"\"\nnode = onnx.helper.make_node(\n 'AveragePool',\n inputs=['x'],\n outputs=['y'],\n kernel_shape=[2, 2],\n)\nx = np.random.randn(1, 3, 32, 32).astype(np.float32)\nx_shape = np.shape(x)\nkernel_shape = (2, 2)\nstrides = (1, 1)\nout_shape = get_output_shape('VALID', x_shape[2:], kernel_shape, strides)\npadded = x\ny = pool(padded, x_shape, kernel_shape, strides, out_shape, (0, 0), 'AVG')\n\nexpect(node, inputs=[x], outputs=[y], name='test_averagepool_2d_default')" + }, + { + "summary": "averagepool_2d_pads", + "code": "\"\"\"\ninput_shape: [1, 3, 28, 28]\noutput_shape: [1, 3, 30, 30]\npad_shape: [4, 4] -> [2, 2, 2, 2] by axis\n\"\"\"\nnode = onnx.helper.make_node(\n 'AveragePool',\n inputs=['x'],\n outputs=['y'],\n kernel_shape=[3, 3],\n pads=[2, 2, 2, 2]\n)\nx = np.random.randn(1, 3, 28, 28).astype(np.float32)\nx_shape = np.shape(x)\nkernel_shape = (3, 3)\nstrides = (1, 1)\npad_bottom = 2\npad_top = 2\npad_right = 2\npad_left = 2\npad_shape = [pad_top + pad_bottom, pad_left + pad_right]\nout_shape = get_output_shape('VALID', np.add(x_shape[2:], pad_shape), kernel_shape, strides)\npadded = np.pad(x, ((0, 0), (0, 0), (pad_top, pad_bottom), (pad_left, pad_right)), mode='constant',\n constant_values=np.nan)\ny = pool(padded, x_shape, kernel_shape, strides, out_shape, pad_shape, 'AVG')\n\nexpect(node, inputs=[x], outputs=[y], name='test_averagepool_2d_pads')" + }, + { + "summary": "averagepool_2d_pads_count_include_pad", + "code": "\"\"\"\ninput_shape: [1, 3, 28, 28]\noutput_shape: [1, 3, 30, 30]\npad_shape: [4, 4] -> [2, 2, 2, 2] by axis\n\"\"\"\nnode = onnx.helper.make_node(\n 'AveragePool',\n inputs=['x'],\n outputs=['y'],\n kernel_shape=[3, 3],\n pads=[2, 2, 2, 2],\n count_include_pad=1,\n)\nx = np.random.randn(1, 3, 28, 28).astype(np.float32)\nx_shape = np.shape(x)\nkernel_shape = (3, 3)\nstrides = (1, 1)\npad_bottom = 2\npad_top = 2\npad_right = 2\npad_left = 2\npad_shape = [pad_top + pad_bottom, pad_left + pad_right]\nout_shape = get_output_shape('VALID', np.add(x_shape[2:], pad_shape), kernel_shape, strides)\npadded = np.pad(x, ((0, 0), (0, 0), (pad_top, pad_bottom), (pad_left, pad_right)), mode='constant',\n constant_values=0)\ny = pool(padded, x_shape, kernel_shape, strides, out_shape, pad_shape, 'AVG', count_include_pad=1)\n\nexpect(node, inputs=[x], outputs=[y], name='test_averagepool_2d_pads_count_include_pad')" + }, + { + "summary": "averagepool_2d_precomputed_pads", + "code": "\"\"\"\ninput_shape: [1, 1, 5, 5]\noutput_shape: [1, 1, 5, 5]\npad_shape: [4, 4] -> [2, 2, 2, 2] by axis\n\"\"\"\nnode = onnx.helper.make_node(\n 'AveragePool',\n inputs=['x'],\n outputs=['y'],\n kernel_shape=[5, 5],\n pads=[2, 2, 2, 2]\n\n)\nx = np.array([[[\n [1, 2, 3, 4, 5],\n [6, 7, 8, 9, 10],\n [11, 12, 13, 14, 15],\n [16, 17, 18, 19, 20],\n [21, 22, 23, 24, 25],\n]]]).astype(np.float32)\ny = np.array([[[[7, 7.5, 8, 8.5, 9],\n [9.5, 10, 10.5, 11, 11.5],\n [12, 12.5, 13, 13.5, 14],\n [14.5, 15, 15.5, 16, 16.5],\n [17, 17.5, 18, 18.5, 19]]]]).astype(np.float32)\n\nexpect(node, inputs=[x], outputs=[y], name='test_averagepool_2d_precomputed_pads')" + }, + { + "summary": "averagepool_2d_precomputed_pads_count_include_pad", + "code": "\"\"\"\ninput_shape: [1, 1, 5, 5]\noutput_shape: [1, 1, 5, 5]\npad_shape: [4, 4] -> [2, 2, 2, 2] by axis\n\"\"\"\nnode = onnx.helper.make_node(\n 'AveragePool',\n inputs=['x'],\n outputs=['y'],\n kernel_shape=[5, 5],\n pads=[2, 2, 2, 2],\n count_include_pad=1\n)\nx = np.array([[[\n [1, 2, 3, 4, 5],\n [6, 7, 8, 9, 10],\n [11, 12, 13, 14, 15],\n [16, 17, 18, 19, 20],\n [21, 22, 23, 24, 25],\n]]]).astype(np.float32)\ny = np.array([[[[2.5200, 3.6000, 4.8000, 4.0800, 3.2400],\n [4.5600, 6.4000, 8.4000, 7.0400, 5.5200],\n [7.2000, 10.0000, 13.0000, 10.8000, 8.4000],\n [6.9600, 9.6000, 12.4000, 10.2400, 7.9200],\n [6.1200, 8.4000, 10.8000, 8.8800, 6.8400]]]]).astype(np.float32)\n\nexpect(node, inputs=[x], outputs=[y], name='test_averagepool_2d_precomputed_pads_count_include_pad')" + }, + { + "summary": "averagepool_2d_precomputed_same_upper", + "code": "\"\"\"\ninput_shape: [1, 1, 5, 5]\noutput_shape: [1, 1, 3, 3]\npad_shape: [2, 2] -> [1, 1, 1, 1] by axis\n\"\"\"\nnode = onnx.helper.make_node(\n 'AveragePool',\n inputs=['x'],\n outputs=['y'],\n kernel_shape=[3, 3],\n strides=[2, 2],\n auto_pad='SAME_UPPER'\n)\nx = np.array([[[\n [1, 2, 3, 4, 5],\n [6, 7, 8, 9, 10],\n [11, 12, 13, 14, 15],\n [16, 17, 18, 19, 20],\n [21, 22, 23, 24, 25],\n]]]).astype(np.float32)\ny = np.array([[[[4, 5.5, 7],\n [11.5, 13, 14.5],\n [19, 20.5, 22]]]]).astype(np.float32)\n\nexpect(node, inputs=[x], outputs=[y], name='test_averagepool_2d_precomputed_same_upper')" + }, + { + "summary": "averagepool_2d_precomputed_strides", + "code": "\"\"\"\ninput_shape: [1, 1, 5, 5]\noutput_shape: [1, 1, 2, 2]\n\"\"\"\nnode = onnx.helper.make_node(\n 'AveragePool',\n inputs=['x'],\n outputs=['y'],\n kernel_shape=[2, 2],\n strides=[2, 2]\n)\nx = np.array([[[\n [1, 2, 3, 4, 5],\n [6, 7, 8, 9, 10],\n [11, 12, 13, 14, 15],\n [16, 17, 18, 19, 20],\n [21, 22, 23, 24, 25],\n]]]).astype(np.float32)\ny = np.array([[[[4, 6],\n [14, 16]]]]).astype(np.float32)\n\nexpect(node, inputs=[x], outputs=[y], name='test_averagepool_2d_precomputed_strides')" + }, + { + "summary": "averagepool_2d_same_lower", + "code": "\"\"\"\ninput_shape: [1, 3, 32, 32]\noutput_shape: [1, 3, 32, 32]\npad_shape: [1, 1] -> [1, 0, 1, 0] by axis\n\"\"\"\nnode = onnx.helper.make_node(\n 'AveragePool',\n inputs=['x'],\n outputs=['y'],\n kernel_shape=[2, 2],\n auto_pad='SAME_LOWER'\n)\nx = np.random.randn(1, 3, 32, 32).astype(np.float32)\nx_shape = np.shape(x)\nkernel_shape = (2, 2)\nstrides = (1, 1)\nout_shape = get_output_shape('SAME_LOWER', x_shape[2:], kernel_shape, strides)\npad_shape = get_pad_shape('SAME_LOWER', x_shape[2:], kernel_shape, strides, out_shape)\npad_bottom = pad_shape[0] // 2\npad_top = pad_shape[0] - pad_bottom\npad_right = pad_shape[1] // 2\npad_left = pad_shape[1] - pad_right\npadded = np.pad(x, ((0, 0), (0, 0), (pad_top, pad_bottom), (pad_left, pad_right)), mode='constant',\n constant_values=np.nan)\ny = pool(padded, x_shape, kernel_shape, strides, out_shape, pad_shape, 'AVG')\n\nexpect(node, inputs=[x], outputs=[y], name='test_averagepool_2d_same_lower')" + }, + { + "summary": "averagepool_2d_same_upper", + "code": "\"\"\"\ninput_shape: [1, 3, 32, 32]\noutput_shape: [1, 3, 32, 32]\npad_shape: [1, 1] -> [0, 1, 0, 1] by axis\n\"\"\"\nnode = onnx.helper.make_node(\n 'AveragePool',\n inputs=['x'],\n outputs=['y'],\n kernel_shape=[2, 2],\n auto_pad='SAME_UPPER'\n)\nx = np.random.randn(1, 3, 32, 32).astype(np.float32)\nx_shape = np.shape(x)\nkernel_shape = (2, 2)\nstrides = (1, 1)\nout_shape = get_output_shape('SAME_UPPER', x_shape[2:], kernel_shape, strides)\npad_shape = get_pad_shape('SAME_UPPER', x_shape[2:], kernel_shape, strides, out_shape)\npad_top = pad_shape[0] // 2\npad_bottom = pad_shape[0] - pad_top\npad_left = pad_shape[1] // 2\npad_right = pad_shape[1] - pad_left\npadded = np.pad(x, ((0, 0), (0, 0), (pad_top, pad_bottom), (pad_left, pad_right)), mode='constant',\n constant_values=np.nan)\ny = pool(padded, x_shape, kernel_shape, strides, out_shape, pad_shape, 'AVG')\n\nexpect(node, inputs=[x], outputs=[y], name='test_averagepool_2d_same_upper')" + }, + { + "summary": "averagepool_2d_strides", + "code": "\"\"\"\ninput_shape: [1, 3, 32, 32]\noutput_shape: [1, 3, 10, 10]\n\"\"\"\nnode = onnx.helper.make_node(\n 'AveragePool',\n inputs=['x'],\n outputs=['y'],\n kernel_shape=[5, 5],\n strides=[3, 3]\n)\nx = np.random.randn(1, 3, 32, 32).astype(np.float32)\nx_shape = np.shape(x)\nkernel_shape = (5, 5)\nstrides = (3, 3)\nout_shape = get_output_shape('VALID', x_shape[2:], kernel_shape, strides)\npadded = x\ny = pool(padded, x_shape, kernel_shape, strides, out_shape, (0, 0), 'AVG')\n\nexpect(node, inputs=[x], outputs=[y], name='test_averagepool_2d_strides')" + }, + { + "summary": "averagepool_3d_default", + "code": "\"\"\"\ninput_shape: [1, 3, 32, 32, 32]\noutput_shape: [1, 3, 31, 31, 31]\n\"\"\"\nnode = onnx.helper.make_node(\n 'AveragePool',\n inputs=['x'],\n outputs=['y'],\n kernel_shape=[2, 2, 2],\n)\nx = np.random.randn(1, 3, 32, 32, 32).astype(np.float32)\nx_shape = np.shape(x)\nkernel_shape = [2, 2, 2]\nstrides = [1, 1, 1]\nout_shape = get_output_shape('VALID', x_shape[2:], kernel_shape, strides)\npadded = x\ny = pool(padded, x_shape, kernel_shape, strides, out_shape, [0, 0, 0], 'AVG')\n\nexpect(node, inputs=[x], outputs=[y], name='test_averagepool_3d_default')" + } + ], + "category": "Pool" + }, + { + "name": "BatchNormalization", + "module": "ai.onnx", + "version": 1, + "support_level": "common", + "description": "Carries out batch normalization as described in the paper\nhttps://arxiv.org/abs/1502.03167. Depending on the mode it is being run,\nthere are multiple cases for the number of outputs, which we list below:\n\nOutput case #1: Y, mean, var, saved_mean, saved_var (training mode)\nOutput case #2: Y (test mode)\n ", + "attributes": [ + { + "name": "consumed_inputs", + "type": "int64[]", + "required": true, + "description": "legacy optimization attribute." + }, + { + "name": "epsilon", + "type": "float32", + "required": false, + "default": 9.999999747378752e-06, + "description": "The epsilon value to use to avoid division by zero, default is 1e-5f." + }, + { + "name": "is_test", + "type": "int64", + "required": false, + "description": "If set to nonzero, run spatial batch normalization in test mode, default is 0." + }, + { + "name": "momentum", + "type": "float32", + "required": false, + "default": 0.8999999761581421, + "description": "Factor used in computing the running mean and variance.e.g., running_mean = running_mean * momentum + mean * (1 - momentum), default is 0.9f." + }, + { + "name": "spatial", + "type": "int64", + "required": false, + "default": 1, + "description": "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": [ + { + "name": "X", + "type": "T", + "description": "The input 4-dimensional tensor of shape NCHW." + }, + { + "name": "scale", + "type": "T", + "description": "The scale as a 1-dimensional tensor of size C to be applied to the output." + }, + { + "name": "B", + "type": "T", + "description": "The bias as a 1-dimensional tensor of size C to be applied to the output." + }, + { + "name": "mean", + "type": "T", + "description": "The running mean (training) or the estimated mean (testing) as a 1-dimensional tensor of size C." + }, + { + "name": "var", + "type": "T", + "description": "The running variance (training) or the estimated variance (testing) as a 1-dimensional tensor of size C." + } + ], + "min_input": 5, + "max_input": 5, + "outputs": [ + { + "name": "Y", + "type": "T", + "description": "The output 4-dimensional tensor of the same shape as X." + }, + { + "name": "mean", + "type": "T", + "option": "optional", + "description": "The running mean after the BatchNormalization operator. Must be in-place with the input mean. Should not be used for testing." + }, + { + "name": "var", + "type": "T", + "option": "optional", + "description": "The running variance after the BatchNormalization operator. Must be in-place with the input var. Should not be used for testing." + }, + { + "name": "saved_mean", + "type": "T", + "option": "optional", + "description": "Saved mean used during training to speed up gradient computation. Should not be used for testing." + }, + { + "name": "saved_var", + "type": "T", + "option": "optional", + "description": "Saved variance used during training to speed up gradient computation. Should not be used for testing." + } + ], + "min_output": 1, + "max_output": 5, + "outputs_range": "1 - 5", + "type_constraints": [ + { + "description": "Constrain input and output types to float tensors.", + "type_param_str": "T", + "allowed_type_strs": [ + "tensor(float16)", + "tensor(float)", + "tensor(double)" + ] + } + ], + "examples": [ + { + "summary": "batchnormalization", + "code": "# input size: (2, 3, 4, 5)\nx = np.random.randn(2, 3, 4, 5).astype(np.float32)\ns = np.random.randn(3).astype(np.float32)\nbias = np.random.randn(3).astype(np.float32)\nmean = np.random.randn(3).astype(np.float32)\nvar = np.random.rand(3).astype(np.float32)\ny = _batchnorm_test_mode(x, s, bias, mean, var).astype(np.float32)\n\nnode = onnx.helper.make_node(\n 'BatchNormalization',\n inputs=['x', 's', 'bias', 'mean', 'var'],\n outputs=['y'],\n)\n\n# output size: (2, 3, 4, 5)\nexpect(node, inputs=[x, s, bias, mean, var], outputs=[y],\n name='test_batchnorm_example')\n\n# input size: (2, 3, 4, 5)\nx = np.random.randn(2, 3, 4, 5).astype(np.float32)\ns = np.random.randn(3).astype(np.float32)\nbias = np.random.randn(3).astype(np.float32)\nmean = np.random.randn(3).astype(np.float32)\nvar = np.random.rand(3).astype(np.float32)\nepsilon = 1e-2\ny = _batchnorm_test_mode(x, s, bias, mean, var, epsilon).astype(np.float32)\n\nnode = onnx.helper.make_node(\n 'BatchNormalization',\n inputs=['x', 's', 'bias', 'mean', 'var'],\n outputs=['y'],\n epsilon=epsilon,\n)\n\n# output size: (2, 3, 4, 5)\nexpect(node, inputs=[x, s, bias, mean, var], outputs=[y],\n name='test_batchnorm_epsilon')" + }, + { + "summary": "train", + "code": "# input size: (2, 3, 4, 5)\nx = np.random.randn(2, 3, 4, 5).astype(np.float32)\ns = np.random.randn(3).astype(np.float32)\nbias = np.random.randn(3).astype(np.float32)\nmean = np.random.randn(3).astype(np.float32)\nvar = np.random.rand(3).astype(np.float32)\n# using np.bool(1) while generating test data with \"'bool' object has no attribute 'dtype'\"\n# working around by using np.byte(1).astype(bool)\ntraining_mode = 1\ny, output_mean, output_var = _batchnorm_training_mode(x, s, bias, mean, var)\n\nnode = onnx.helper.make_node(\n 'BatchNormalization',\n inputs=['x', 's', 'bias', 'mean', 'var'],\n outputs=['y', 'output_mean', 'output_var'],\n training_mode=training_mode\n)\n\n# output size: (2, 3, 4, 5)\nexpect(node, inputs=[x, s, bias, mean, var],\n outputs=[y, output_mean, output_var],\n name='test_batchnorm_example_training_mode')\n\n# input size: (2, 3, 4, 5)\nx = np.random.randn(2, 3, 4, 5).astype(np.float32)\ns = np.random.randn(3).astype(np.float32)\nbias = np.random.randn(3).astype(np.float32)\nmean = np.random.randn(3).astype(np.float32)\nvar = np.random.rand(3).astype(np.float32)\ntraining_mode = 1\nmomentum = 0.9\nepsilon = 1e-2\ny, output_mean, output_var = _batchnorm_training_mode(x, s, bias, mean, var, momentum,\n epsilon)\n\nnode = onnx.helper.make_node(\n 'BatchNormalization',\n inputs=['x', 's', 'bias', 'mean', 'var'],\n outputs=['y', 'output_mean', 'output_var'],\n epsilon=epsilon,\n training_mode=training_mode\n)\n\n# output size: (2, 3, 4, 5)\nexpect(node, inputs=[x, s, bias, mean, var],\n outputs=[y, output_mean, output_var],\n name='test_batchnorm_epsilon_training_mode')" + } + ], + "category": "Normalization" + }, + { + "name": "BatchNormalization", + "module": "ai.onnx", + "version": 6, + "support_level": "common", + "description": "Carries out batch normalization as described in the paper\nhttps://arxiv.org/abs/1502.03167. Depending on the mode it is being run,\nthere are multiple cases for the number of outputs, which we list below:\n\nOutput case #1: Y, mean, var, saved_mean, saved_var (training mode)\nOutput case #2: Y (test mode)\n", + "attributes": [ + { + "name": "epsilon", + "type": "float32", + "required": false, + "default": 9.999999747378752e-06, + "description": "The epsilon value to use to avoid division by zero, default is 1e-5f." + }, + { + "name": "is_test", + "type": "int64", + "required": false, + "description": "If set to nonzero, run spatial batch normalization in test mode, default is 0." + }, + { + "name": "momentum", + "type": "float32", + "required": false, + "default": 0.8999999761581421, + "description": "Factor used in computing the running mean and variance.e.g., running_mean = running_mean * momentum + mean * (1 - momentum), default is 0.9f." + }, + { + "name": "spatial", + "type": "int64", + "required": false, + "default": 1, + "description": "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": [ + { + "name": "X", + "type": "T", + "description": "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." + }, + { + "name": "scale", + "type": "T", + "description": "The scale as a 1-dimensional tensor of size C to be applied to the output." + }, + { + "name": "B", + "type": "T", + "description": "The bias as a 1-dimensional tensor of size C to be applied to the output." + }, + { + "name": "mean", + "type": "T", + "description": "The running mean (training) or the estimated mean (testing) as a 1-dimensional tensor of size C." + }, + { + "name": "var", + "type": "T", + "description": "The running variance (training) or the estimated variance (testing) as a 1-dimensional tensor of size C." + } + ], + "min_input": 5, + "max_input": 5, + "outputs": [ + { + "name": "Y", + "type": "T", + "description": "The output tensor of the same shape as X." + }, + { + "name": "mean", + "type": "T", + "option": "optional", + "description": "The running mean after the BatchNormalization operator. Must be in-place with the input mean. Should not be used for testing." + }, + { + "name": "var", + "type": "T", + "option": "optional", + "description": "The running variance after the BatchNormalization operator. Must be in-place with the input var. Should not be used for testing." + }, + { + "name": "saved_mean", + "type": "T", + "option": "optional", + "description": "Saved mean used during training to speed up gradient computation. Should not be used for testing." + }, + { + "name": "saved_var", + "type": "T", + "option": "optional", + "description": "Saved variance used during training to speed up gradient computation. Should not be used for testing." + } + ], + "min_output": 1, + "max_output": 5, + "outputs_range": "1 - 5", + "type_constraints": [ + { + "description": "Constrain input and output types to float tensors.", + "type_param_str": "T", + "allowed_type_strs": [ + "tensor(float16)", + "tensor(float)", + "tensor(double)" + ] + } + ], + "examples": [ + { + "summary": "batchnormalization", + "code": "# input size: (2, 3, 4, 5)\nx = np.random.randn(2, 3, 4, 5).astype(np.float32)\ns = np.random.randn(3).astype(np.float32)\nbias = np.random.randn(3).astype(np.float32)\nmean = np.random.randn(3).astype(np.float32)\nvar = np.random.rand(3).astype(np.float32)\ny = _batchnorm_test_mode(x, s, bias, mean, var).astype(np.float32)\n\nnode = onnx.helper.make_node(\n 'BatchNormalization',\n inputs=['x', 's', 'bias', 'mean', 'var'],\n outputs=['y'],\n)\n\n# output size: (2, 3, 4, 5)\nexpect(node, inputs=[x, s, bias, mean, var], outputs=[y],\n name='test_batchnorm_example')\n\n# input size: (2, 3, 4, 5)\nx = np.random.randn(2, 3, 4, 5).astype(np.float32)\ns = np.random.randn(3).astype(np.float32)\nbias = np.random.randn(3).astype(np.float32)\nmean = np.random.randn(3).astype(np.float32)\nvar = np.random.rand(3).astype(np.float32)\nepsilon = 1e-2\ny = _batchnorm_test_mode(x, s, bias, mean, var, epsilon).astype(np.float32)\n\nnode = onnx.helper.make_node(\n 'BatchNormalization',\n inputs=['x', 's', 'bias', 'mean', 'var'],\n outputs=['y'],\n epsilon=epsilon,\n)\n\n# output size: (2, 3, 4, 5)\nexpect(node, inputs=[x, s, bias, mean, var], outputs=[y],\n name='test_batchnorm_epsilon')" + }, + { + "summary": "train", + "code": "# input size: (2, 3, 4, 5)\nx = np.random.randn(2, 3, 4, 5).astype(np.float32)\ns = np.random.randn(3).astype(np.float32)\nbias = np.random.randn(3).astype(np.float32)\nmean = np.random.randn(3).astype(np.float32)\nvar = np.random.rand(3).astype(np.float32)\n# using np.bool(1) while generating test data with \"'bool' object has no attribute 'dtype'\"\n# working around by using np.byte(1).astype(bool)\ntraining_mode = 1\ny, output_mean, output_var = _batchnorm_training_mode(x, s, bias, mean, var)\n\nnode = onnx.helper.make_node(\n 'BatchNormalization',\n inputs=['x', 's', 'bias', 'mean', 'var'],\n outputs=['y', 'output_mean', 'output_var'],\n training_mode=training_mode\n)\n\n# output size: (2, 3, 4, 5)\nexpect(node, inputs=[x, s, bias, mean, var],\n outputs=[y, output_mean, output_var],\n name='test_batchnorm_example_training_mode')\n\n# input size: (2, 3, 4, 5)\nx = np.random.randn(2, 3, 4, 5).astype(np.float32)\ns = np.random.randn(3).astype(np.float32)\nbias = np.random.randn(3).astype(np.float32)\nmean = np.random.randn(3).astype(np.float32)\nvar = np.random.rand(3).astype(np.float32)\ntraining_mode = 1\nmomentum = 0.9\nepsilon = 1e-2\ny, output_mean, output_var = _batchnorm_training_mode(x, s, bias, mean, var, momentum,\n epsilon)\n\nnode = onnx.helper.make_node(\n 'BatchNormalization',\n inputs=['x', 's', 'bias', 'mean', 'var'],\n outputs=['y', 'output_mean', 'output_var'],\n epsilon=epsilon,\n training_mode=training_mode\n)\n\n# output size: (2, 3, 4, 5)\nexpect(node, inputs=[x, s, bias, mean, var],\n outputs=[y, output_mean, output_var],\n name='test_batchnorm_epsilon_training_mode')" + } + ], + "category": "Normalization" + }, + { + "name": "BatchNormalization", + "module": "ai.onnx", + "version": 7, + "support_level": "common", + "description": "Carries out batch normalization as described in the paper\n https://arxiv.org/abs/1502.03167. Depending on the mode it is being run,\n there are multiple cases for the number of outputs, which we list below:\n\n Output case #1: Y, mean, var, saved_mean, saved_var (training mode)\n Output case #2: Y (test mode)\n This operator has **optional** inputs/outputs. See [the doc](https://github.com/onnx/onnx/blob/master/docs/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.\n", + "attributes": [ + { + "name": "epsilon", + "type": "float32", + "required": false, + "default": 9.999999747378752e-06, + "description": "The epsilon value to use to avoid division by zero." + }, + { + "name": "momentum", + "type": "float32", + "required": false, + "default": 0.8999999761581421, + "description": "Factor used in computing the running mean and variance.e.g., running_mean = running_mean * momentum + mean * (1 - momentum)." + }, + { + "name": "spatial", + "type": "int64", + "required": false, + "default": 1, + "description": "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": [ + { + "name": "X", + "type": "T", + "description": "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." + }, + { + "name": "scale", + "type": "T", + "description": "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)" + }, + { + "name": "B", + "type": "T", + "description": "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)" + }, + { + "name": "mean", + "type": "T", + "description": "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)." + }, + { + "name": "var", + "type": "T", + "description": "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)." + } + ], + "min_input": 5, + "max_input": 5, + "outputs": [ + { + "name": "Y", + "type": "T", + "description": "The output tensor of the same shape as X" + }, + { + "name": "mean", + "type": "T", + "option": "optional", + "description": "The running mean after the BatchNormalization operator." + }, + { + "name": "var", + "type": "T", + "option": "optional", + "description": "The running variance after the BatchNormalization operator." + }, + { + "name": "saved_mean", + "type": "T", + "option": "optional", + "description": "Saved mean used during training to speed up gradient computation." + }, + { + "name": "saved_var", + "type": "T", + "option": "optional", + "description": "Saved variance used during training to speed up gradient computation." + } + ], + "min_output": 1, + "max_output": 5, + "outputs_range": "1 - 5", + "type_constraints": [ + { + "description": "Constrain input and output types to float tensors.", + "type_param_str": "T", + "allowed_type_strs": [ + "tensor(float16)", + "tensor(float)", + "tensor(double)" + ] + } + ], + "examples": [ + { + "summary": "batchnormalization", + "code": "# input size: (2, 3, 4, 5)\nx = np.random.randn(2, 3, 4, 5).astype(np.float32)\ns = np.random.randn(3).astype(np.float32)\nbias = np.random.randn(3).astype(np.float32)\nmean = np.random.randn(3).astype(np.float32)\nvar = np.random.rand(3).astype(np.float32)\ny = _batchnorm_test_mode(x, s, bias, mean, var).astype(np.float32)\n\nnode = onnx.helper.make_node(\n 'BatchNormalization',\n inputs=['x', 's', 'bias', 'mean', 'var'],\n outputs=['y'],\n)\n\n# output size: (2, 3, 4, 5)\nexpect(node, inputs=[x, s, bias, mean, var], outputs=[y],\n name='test_batchnorm_example')\n\n# input size: (2, 3, 4, 5)\nx = np.random.randn(2, 3, 4, 5).astype(np.float32)\ns = np.random.randn(3).astype(np.float32)\nbias = np.random.randn(3).astype(np.float32)\nmean = np.random.randn(3).astype(np.float32)\nvar = np.random.rand(3).astype(np.float32)\nepsilon = 1e-2\ny = _batchnorm_test_mode(x, s, bias, mean, var, epsilon).astype(np.float32)\n\nnode = onnx.helper.make_node(\n 'BatchNormalization',\n inputs=['x', 's', 'bias', 'mean', 'var'],\n outputs=['y'],\n epsilon=epsilon,\n)\n\n# output size: (2, 3, 4, 5)\nexpect(node, inputs=[x, s, bias, mean, var], outputs=[y],\n name='test_batchnorm_epsilon')" + }, + { + "summary": "train", + "code": "# input size: (2, 3, 4, 5)\nx = np.random.randn(2, 3, 4, 5).astype(np.float32)\ns = np.random.randn(3).astype(np.float32)\nbias = np.random.randn(3).astype(np.float32)\nmean = np.random.randn(3).astype(np.float32)\nvar = np.random.rand(3).astype(np.float32)\n# using np.bool(1) while generating test data with \"'bool' object has no attribute 'dtype'\"\n# working around by using np.byte(1).astype(bool)\ntraining_mode = 1\ny, output_mean, output_var = _batchnorm_training_mode(x, s, bias, mean, var)\n\nnode = onnx.helper.make_node(\n 'BatchNormalization',\n inputs=['x', 's', 'bias', 'mean', 'var'],\n outputs=['y', 'output_mean', 'output_var'],\n training_mode=training_mode\n)\n\n# output size: (2, 3, 4, 5)\nexpect(node, inputs=[x, s, bias, mean, var],\n outputs=[y, output_mean, output_var],\n name='test_batchnorm_example_training_mode')\n\n# input size: (2, 3, 4, 5)\nx = np.random.randn(2, 3, 4, 5).astype(np.float32)\ns = np.random.randn(3).astype(np.float32)\nbias = np.random.randn(3).astype(np.float32)\nmean = np.random.randn(3).astype(np.float32)\nvar = np.random.rand(3).astype(np.float32)\ntraining_mode = 1\nmomentum = 0.9\nepsilon = 1e-2\ny, output_mean, output_var = _batchnorm_training_mode(x, s, bias, mean, var, momentum,\n epsilon)\n\nnode = onnx.helper.make_node(\n 'BatchNormalization',\n inputs=['x', 's', 'bias', 'mean', 'var'],\n outputs=['y', 'output_mean', 'output_var'],\n epsilon=epsilon,\n training_mode=training_mode\n)\n\n# output size: (2, 3, 4, 5)\nexpect(node, inputs=[x, s, bias, mean, var],\n outputs=[y, output_mean, output_var],\n name='test_batchnorm_epsilon_training_mode')" + } + ], + "category": "Normalization" + }, + { + "name": "BatchNormalization", + "module": "ai.onnx", + "version": 9, + "support_level": "common", + "description": "Carries out batch normalization as described in the paper\nhttps://arxiv.org/abs/1502.03167. Depending on the mode it is being run,\nthere are multiple cases for the number of outputs, which we list below:\n\nOutput case #1: Y, mean, var, saved_mean, saved_var (training mode)\nOutput case #2: Y (test mode)\n\nFor previous (depreciated) non-spatial cases, implementors are suggested\nto flatten the input shape to (N x C*D1*D2 ..*Dn) before a BatchNormalization Op.\nThis operator has **optional** inputs/outputs. See [the doc](https://github.com/onnx/onnx/blob/master/docs/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.\n", + "attributes": [ + { + "name": "epsilon", + "type": "float32", + "required": false, + "default": 9.999999747378752e-06, + "description": "The epsilon value to use to avoid division by zero." + }, + { + "name": "momentum", + "type": "float32", + "required": false, + "default": 0.8999999761581421, + "description": "Factor used in computing the running mean and variance.e.g., running_mean = running_mean * momentum + mean * (1 - momentum)." + } + ], + "inputs": [ + { + "name": "X", + "type": "T", + "description": "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" + }, + { + "name": "scale", + "type": "T", + "description": "Scale tensor of shape (C)." + }, + { + "name": "B", + "type": "T", + "description": "Bias tensor of shape (C)." + }, + { + "name": "mean", + "type": "T", + "description": "running (training) or estimated (testing) mean tensor of shape (C)." + }, + { + "name": "var", + "type": "T", + "description": "running (training) or estimated (testing) variance tensor of shape (C)." + } + ], + "min_input": 5, + "max_input": 5, + "outputs": [ + { + "name": "Y", + "type": "T", + "description": "The output tensor of the same shape as X" + }, + { + "name": "mean", + "type": "T", + "option": "optional", + "description": "The running mean after the BatchNormalization operator." + }, + { + "name": "var", + "type": "T", + "option": "optional", + "description": "The running variance after the BatchNormalization operator." + }, + { + "name": "saved_mean", + "type": "T", + "option": "optional", + "description": "Saved mean used during training to speed up gradient computation." + }, + { + "name": "saved_var", + "type": "T", + "option": "optional", + "description": "Saved variance used during training to speed up gradient computation." + } + ], + "min_output": 1, + "max_output": 5, + "outputs_range": "1 - 5", + "type_constraints": [ + { + "description": "Constrain input and output types to float tensors.", + "type_param_str": "T", + "allowed_type_strs": [ + "tensor(float16)", + "tensor(float)", + "tensor(double)" + ] + } + ], + "examples": [ + { + "summary": "batchnormalization", + "code": "# input size: (2, 3, 4, 5)\nx = np.random.randn(2, 3, 4, 5).astype(np.float32)\ns = np.random.randn(3).astype(np.float32)\nbias = np.random.randn(3).astype(np.float32)\nmean = np.random.randn(3).astype(np.float32)\nvar = np.random.rand(3).astype(np.float32)\ny = _batchnorm_test_mode(x, s, bias, mean, var).astype(np.float32)\n\nnode = onnx.helper.make_node(\n 'BatchNormalization',\n inputs=['x', 's', 'bias', 'mean', 'var'],\n outputs=['y'],\n)\n\n# output size: (2, 3, 4, 5)\nexpect(node, inputs=[x, s, bias, mean, var], outputs=[y],\n name='test_batchnorm_example')\n\n# input size: (2, 3, 4, 5)\nx = np.random.randn(2, 3, 4, 5).astype(np.float32)\ns = np.random.randn(3).astype(np.float32)\nbias = np.random.randn(3).astype(np.float32)\nmean = np.random.randn(3).astype(np.float32)\nvar = np.random.rand(3).astype(np.float32)\nepsilon = 1e-2\ny = _batchnorm_test_mode(x, s, bias, mean, var, epsilon).astype(np.float32)\n\nnode = onnx.helper.make_node(\n 'BatchNormalization',\n inputs=['x', 's', 'bias', 'mean', 'var'],\n outputs=['y'],\n epsilon=epsilon,\n)\n\n# output size: (2, 3, 4, 5)\nexpect(node, inputs=[x, s, bias, mean, var], outputs=[y],\n name='test_batchnorm_epsilon')" + }, + { + "summary": "train", + "code": "# input size: (2, 3, 4, 5)\nx = np.random.randn(2, 3, 4, 5).astype(np.float32)\ns = np.random.randn(3).astype(np.float32)\nbias = np.random.randn(3).astype(np.float32)\nmean = np.random.randn(3).astype(np.float32)\nvar = np.random.rand(3).astype(np.float32)\n# using np.bool(1) while generating test data with \"'bool' object has no attribute 'dtype'\"\n# working around by using np.byte(1).astype(bool)\ntraining_mode = 1\ny, output_mean, output_var = _batchnorm_training_mode(x, s, bias, mean, var)\n\nnode = onnx.helper.make_node(\n 'BatchNormalization',\n inputs=['x', 's', 'bias', 'mean', 'var'],\n outputs=['y', 'output_mean', 'output_var'],\n training_mode=training_mode\n)\n\n# output size: (2, 3, 4, 5)\nexpect(node, inputs=[x, s, bias, mean, var],\n outputs=[y, output_mean, output_var],\n name='test_batchnorm_example_training_mode')\n\n# input size: (2, 3, 4, 5)\nx = np.random.randn(2, 3, 4, 5).astype(np.float32)\ns = np.random.randn(3).astype(np.float32)\nbias = np.random.randn(3).astype(np.float32)\nmean = np.random.randn(3).astype(np.float32)\nvar = np.random.rand(3).astype(np.float32)\ntraining_mode = 1\nmomentum = 0.9\nepsilon = 1e-2\ny, output_mean, output_var = _batchnorm_training_mode(x, s, bias, mean, var, momentum,\n epsilon)\n\nnode = onnx.helper.make_node(\n 'BatchNormalization',\n inputs=['x', 's', 'bias', 'mean', 'var'],\n outputs=['y', 'output_mean', 'output_var'],\n epsilon=epsilon,\n training_mode=training_mode\n)\n\n# output size: (2, 3, 4, 5)\nexpect(node, inputs=[x, s, bias, mean, var],\n outputs=[y, output_mean, output_var],\n name='test_batchnorm_epsilon_training_mode')" + } + ], + "category": "Normalization" + }, + { + "name": "BatchNormalization", + "module": "ai.onnx", + "version": 14, + "support_level": "common", + "description": "Carries out batch normalization as described in the paper\nhttps://arxiv.org/abs/1502.03167. Depending on the mode it is being run,\nThere are five required inputs 'X', 'scale', 'B', 'input_mean' and\n'input_var'.\nNote that 'input_mean' and 'input_var' are expected to be the estimated\nstatistics in inference mode (training_mode=False, default),\nand the running statistics in training mode (training_mode=True).\nThere are multiple cases for the number of outputs, which we list below:\n\nOutput case #1: Y, running_mean, running_var (training_mode=True)\nOutput case #2: Y (training_mode=False)\n\nWhen training_mode=False, extra outputs are invalid.\nThe outputs are updated as follows when training_mode=True:\n```\nrunning_mean = input_mean * momentum + current_mean * (1 - momentum)\nrunning_var = input_var * momentum + current_var * (1 - momentum)\n\nY = (X - current_mean) / sqrt(current_var + epsilon) * scale + B\n\nwhere:\n\ncurrent_mean = ReduceMean(X, axis=all_except_channel_index)\ncurrent_var = ReduceVar(X, axis=all_except_channel_index)\n\nNotice that ReduceVar refers to the population variance, and it equals to\nsum(sqrd(x_i - x_avg)) / N\nwhere N is the population size (this formula does not use sample size N - 1).\n\n```\n\nWhen training_mode=False:\n```\nY = (X - input_mean) / sqrt(input_var + epsilon) * scale + B\n```\n\nFor previous (depreciated) non-spatial cases, implementors are suggested\nto flatten the input shape to (N x C * D1 * D2 * ... * Dn) before a BatchNormalization Op.\nThis operator has **optional** inputs/outputs. See [the doc](https://github.com/onnx/onnx/blob/master/docs/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.\n", + "attributes": [ + { + "name": "epsilon", + "type": "float32", + "required": false, + "default": 9.999999747378752e-06, + "description": "The epsilon value to use to avoid division by zero." + }, + { + "name": "momentum", + "type": "float32", + "required": false, + "default": 0.8999999761581421, + "description": "Factor used in computing the running mean and variance.e.g., running_mean = running_mean * momentum + mean * (1 - momentum)." + }, + { + "name": "training_mode", + "type": "int64", + "required": false, + "description": "If set to true, it indicates BatchNormalization is being used for training, and outputs 1, 2, 3, and 4 would be populated." + } + ], + "inputs": [ + { + "name": "X", + "type": "T", + "description": "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" + }, + { + "name": "scale", + "type": "T", + "description": "Scale tensor of shape (C)." + }, + { + "name": "B", + "type": "T", + "description": "Bias tensor of shape (C)." + }, + { + "name": "input_mean", + "type": "U", + "description": "running (training) or estimated (testing) mean tensor of shape (C)." + }, + { + "name": "input_var", + "type": "U", + "description": "running (training) or estimated (testing) variance tensor of shape (C)." + } + ], + "min_input": 5, + "max_input": 5, + "outputs": [ + { + "name": "Y", + "type": "T", + "description": "The output tensor of the same shape as X" + }, + { + "name": "running_mean", + "type": "U", + "option": "optional", + "description": "The running mean after the BatchNormalization operator." + }, + { + "name": "running_var", + "type": "U", + "option": "optional", + "description": "The running variance after the BatchNormalization operator. This op uses the population size (N) for calculating variance, and not the sample size N-1." + } + ], + "min_output": 1, + "max_output": 3, + "outputs_range": "1 - 3", + "type_constraints": [ + { + "description": "Constrain input and output types to float tensors.", + "type_param_str": "T", + "allowed_type_strs": [ + "tensor(float16)", + "tensor(float)", + "tensor(double)", + "tensor(bfloat16)" + ] + }, + { + "description": "Constrain mean and variance types to float tensors. It allows all float type for U.", + "type_param_str": "U", + "allowed_type_strs": [ + "tensor(float16)", + "tensor(float)", + "tensor(double)", + "tensor(bfloat16)" + ] + } + ], + "examples": [ + { + "summary": "batchnormalization", + "code": "# input size: (2, 3, 4, 5)\nx = np.random.randn(2, 3, 4, 5).astype(np.float32)\ns = np.random.randn(3).astype(np.float32)\nbias = np.random.randn(3).astype(np.float32)\nmean = np.random.randn(3).astype(np.float32)\nvar = np.random.rand(3).astype(np.float32)\ny = _batchnorm_test_mode(x, s, bias, mean, var).astype(np.float32)\n\nnode = onnx.helper.make_node(\n 'BatchNormalization',\n inputs=['x', 's', 'bias', 'mean', 'var'],\n outputs=['y'],\n)\n\n# output size: (2, 3, 4, 5)\nexpect(node, inputs=[x, s, bias, mean, var], outputs=[y],\n name='test_batchnorm_example')\n\n# input size: (2, 3, 4, 5)\nx = np.random.randn(2, 3, 4, 5).astype(np.float32)\ns = np.random.randn(3).astype(np.float32)\nbias = np.random.randn(3).astype(np.float32)\nmean = np.random.randn(3).astype(np.float32)\nvar = np.random.rand(3).astype(np.float32)\nepsilon = 1e-2\ny = _batchnorm_test_mode(x, s, bias, mean, var, epsilon).astype(np.float32)\n\nnode = onnx.helper.make_node(\n 'BatchNormalization',\n inputs=['x', 's', 'bias', 'mean', 'var'],\n outputs=['y'],\n epsilon=epsilon,\n)\n\n# output size: (2, 3, 4, 5)\nexpect(node, inputs=[x, s, bias, mean, var], outputs=[y],\n name='test_batchnorm_epsilon')" + }, + { + "summary": "train", + "code": "# input size: (2, 3, 4, 5)\nx = np.random.randn(2, 3, 4, 5).astype(np.float32)\ns = np.random.randn(3).astype(np.float32)\nbias = np.random.randn(3).astype(np.float32)\nmean = np.random.randn(3).astype(np.float32)\nvar = np.random.rand(3).astype(np.float32)\n# using np.bool(1) while generating test data with \"'bool' object has no attribute 'dtype'\"\n# working around by using np.byte(1).astype(bool)\ntraining_mode = 1\ny, output_mean, output_var = _batchnorm_training_mode(x, s, bias, mean, var)\n\nnode = onnx.helper.make_node(\n 'BatchNormalization',\n inputs=['x', 's', 'bias', 'mean', 'var'],\n outputs=['y', 'output_mean', 'output_var'],\n training_mode=training_mode\n)\n\n# output size: (2, 3, 4, 5)\nexpect(node, inputs=[x, s, bias, mean, var],\n outputs=[y, output_mean, output_var],\n name='test_batchnorm_example_training_mode')\n\n# input size: (2, 3, 4, 5)\nx = np.random.randn(2, 3, 4, 5).astype(np.float32)\ns = np.random.randn(3).astype(np.float32)\nbias = np.random.randn(3).astype(np.float32)\nmean = np.random.randn(3).astype(np.float32)\nvar = np.random.rand(3).astype(np.float32)\ntraining_mode = 1\nmomentum = 0.9\nepsilon = 1e-2\ny, output_mean, output_var = _batchnorm_training_mode(x, s, bias, mean, var, momentum,\n epsilon)\n\nnode = onnx.helper.make_node(\n 'BatchNormalization',\n inputs=['x', 's', 'bias', 'mean', 'var'],\n outputs=['y', 'output_mean', 'output_var'],\n epsilon=epsilon,\n training_mode=training_mode\n)\n\n# output size: (2, 3, 4, 5)\nexpect(node, inputs=[x, s, bias, mean, var],\n outputs=[y, output_mean, output_var],\n name='test_batchnorm_epsilon_training_mode')" + } + ], + "category": "Normalization" + }, + { + "name": "BatchNormalization", + "module": "ai.onnx", + "version": 15, + "support_level": "common", + "description": "Carries out batch normalization as described in the paper\nhttps://arxiv.org/abs/1502.03167. Depending on the mode it is being run,\nThere are five required inputs 'X', 'scale', 'B', 'input_mean' and\n'input_var'.\nNote that 'input_mean' and 'input_var' are expected to be the estimated\nstatistics in inference mode (training_mode=False, default),\nand the running statistics in training mode (training_mode=True).\nThere are multiple cases for the number of outputs, which we list below:\n\nOutput case #1: Y, running_mean, running_var (training_mode=True)\nOutput case #2: Y (training_mode=False)\n\nWhen training_mode=False, extra outputs are invalid.\nThe outputs are updated as follows when training_mode=True:\n```\nrunning_mean = input_mean * momentum + current_mean * (1 - momentum)\nrunning_var = input_var * momentum + current_var * (1 - momentum)\n\nY = (X - current_mean) / sqrt(current_var + epsilon) * scale + B\n\nwhere:\n\ncurrent_mean = ReduceMean(X, axis=all_except_channel_index)\ncurrent_var = ReduceVar(X, axis=all_except_channel_index)\n\nNotice that ReduceVar refers to the population variance, and it equals to\nsum(sqrd(x_i - x_avg)) / N\nwhere N is the population size (this formula does not use sample size N - 1).\n\n```\n\nThe computation of ReduceMean and ReduceVar uses float to avoid overflow for float16 inputs.\n\nWhen training_mode=False:\n```\nY = (X - input_mean) / sqrt(input_var + epsilon) * scale + B\n```\n\nFor previous (depreciated) non-spatial cases, implementors are suggested\nto flatten the input shape to (N x C * D1 * D2 * ... * Dn) before a BatchNormalization Op.\nThis operator has **optional** inputs/outputs. See [the doc](https://github.com/onnx/onnx/blob/master/docs/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.\n", + "attributes": [ + { + "name": "epsilon", + "type": "float32", + "required": false, + "default": 9.999999747378752e-06, + "description": "The epsilon value to use to avoid division by zero." + }, + { + "name": "momentum", + "type": "float32", + "required": false, + "default": 0.8999999761581421, + "description": "Factor used in computing the running mean and variance.e.g., running_mean = running_mean * momentum + mean * (1 - momentum)." + }, + { + "name": "training_mode", + "type": "int64", + "required": false, + "description": "If set to true, it indicates BatchNormalization is being used for training, and outputs 1, 2, 3, and 4 would be populated." + } + ], + "inputs": [ + { + "name": "X", + "type": "T", + "description": "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" + }, + { + "name": "scale", + "type": "T1", + "description": "Scale tensor of shape (C)." + }, + { + "name": "B", + "type": "T1", + "description": "Bias tensor of shape (C)." + }, + { + "name": "input_mean", + "type": "T2", + "description": "running (training) or estimated (testing) mean tensor of shape (C)." + }, + { + "name": "input_var", + "type": "T2", + "description": "running (training) or estimated (testing) variance tensor of shape (C)." + } + ], + "min_input": 5, + "max_input": 5, + "outputs": [ + { + "name": "Y", + "type": "T", + "description": "The output tensor of the same shape as X" + }, + { + "name": "running_mean", + "type": "T2", + "option": "optional", + "description": "The running mean after the BatchNormalization operator." + }, + { + "name": "running_var", + "type": "T2", + "option": "optional", + "description": "The running variance after the BatchNormalization operator. This op uses the population size (N) for calculating variance, and not the sample size N-1." + } + ], + "min_output": 1, + "max_output": 3, + "outputs_range": "1 - 3", + "type_constraints": [ + { + "description": "Constrain input and output types to float tensors.", + "type_param_str": "T", + "allowed_type_strs": [ + "tensor(float16)", + "tensor(float)", + "tensor(double)", + "tensor(bfloat16)" + ] + }, + { + "description": "Constrain scale and bias types to float tensors.", + "type_param_str": "T1", + "allowed_type_strs": [ + "tensor(float16)", + "tensor(float)", + "tensor(double)", + "tensor(bfloat16)" + ] + }, + { + "description": "Constrain mean and variance types to float tensors.", + "type_param_str": "T2", + "allowed_type_strs": [ + "tensor(float16)", + "tensor(float)", + "tensor(double)", + "tensor(bfloat16)" + ] + } + ], + "examples": [ + { + "summary": "batchnormalization", + "code": "# input size: (2, 3, 4, 5)\nx = np.random.randn(2, 3, 4, 5).astype(np.float32)\ns = np.random.randn(3).astype(np.float32)\nbias = np.random.randn(3).astype(np.float32)\nmean = np.random.randn(3).astype(np.float32)\nvar = np.random.rand(3).astype(np.float32)\ny = _batchnorm_test_mode(x, s, bias, mean, var).astype(np.float32)\n\nnode = onnx.helper.make_node(\n 'BatchNormalization',\n inputs=['x', 's', 'bias', 'mean', 'var'],\n outputs=['y'],\n)\n\n# output size: (2, 3, 4, 5)\nexpect(node, inputs=[x, s, bias, mean, var], outputs=[y],\n name='test_batchnorm_example')\n\n# input size: (2, 3, 4, 5)\nx = np.random.randn(2, 3, 4, 5).astype(np.float32)\ns = np.random.randn(3).astype(np.float32)\nbias = np.random.randn(3).astype(np.float32)\nmean = np.random.randn(3).astype(np.float32)\nvar = np.random.rand(3).astype(np.float32)\nepsilon = 1e-2\ny = _batchnorm_test_mode(x, s, bias, mean, var, epsilon).astype(np.float32)\n\nnode = onnx.helper.make_node(\n 'BatchNormalization',\n inputs=['x', 's', 'bias', 'mean', 'var'],\n outputs=['y'],\n epsilon=epsilon,\n)\n\n# output size: (2, 3, 4, 5)\nexpect(node, inputs=[x, s, bias, mean, var], outputs=[y],\n name='test_batchnorm_epsilon')" + }, + { + "summary": "train", + "code": "# input size: (2, 3, 4, 5)\nx = np.random.randn(2, 3, 4, 5).astype(np.float32)\ns = np.random.randn(3).astype(np.float32)\nbias = np.random.randn(3).astype(np.float32)\nmean = np.random.randn(3).astype(np.float32)\nvar = np.random.rand(3).astype(np.float32)\n# using np.bool(1) while generating test data with \"'bool' object has no attribute 'dtype'\"\n# working around by using np.byte(1).astype(bool)\ntraining_mode = 1\ny, output_mean, output_var = _batchnorm_training_mode(x, s, bias, mean, var)\n\nnode = onnx.helper.make_node(\n 'BatchNormalization',\n inputs=['x', 's', 'bias', 'mean', 'var'],\n outputs=['y', 'output_mean', 'output_var'],\n training_mode=training_mode\n)\n\n# output size: (2, 3, 4, 5)\nexpect(node, inputs=[x, s, bias, mean, var],\n outputs=[y, output_mean, output_var],\n name='test_batchnorm_example_training_mode')\n\n# input size: (2, 3, 4, 5)\nx = np.random.randn(2, 3, 4, 5).astype(np.float32)\ns = np.random.randn(3).astype(np.float32)\nbias = np.random.randn(3).astype(np.float32)\nmean = np.random.randn(3).astype(np.float32)\nvar = np.random.rand(3).astype(np.float32)\ntraining_mode = 1\nmomentum = 0.9\nepsilon = 1e-2\ny, output_mean, output_var = _batchnorm_training_mode(x, s, bias, mean, var, momentum,\n epsilon)\n\nnode = onnx.helper.make_node(\n 'BatchNormalization',\n inputs=['x', 's', 'bias', 'mean', 'var'],\n outputs=['y', 'output_mean', 'output_var'],\n epsilon=epsilon,\n training_mode=training_mode\n)\n\n# output size: (2, 3, 4, 5)\nexpect(node, inputs=[x, s, bias, mean, var],\n outputs=[y, output_mean, output_var],\n name='test_batchnorm_epsilon_training_mode')" + } + ], + "category": "Normalization" + }, + { + "name": "Bernoulli", + "module": "ai.onnx", + "version": 15, + "support_level": "common", + "description": "Draws binary random numbers (0 or 1) from a Bernoulli distribution. The input tensor should be a tensor\ncontaining probabilities p (a value in the range [0,1]) to be used for drawing the binary random number,\nwhere an output of 1 is produced with probability p and an output of 0 is produced with probability (1-p).\n\nThis operator is non-deterministic and may not produce the same values in different\nimplementations (even if a seed is specified).\n", + "attributes": [ + { + "name": "dtype", + "type": "int64", + "required": false, + "description": "The data type for the elements of the output tensor. if not specified, we will use the data type of the input tensor." + }, + { + "name": "seed", + "type": "float32", + "required": false, + "description": "(Optional) Seed to the random generator, if not specified we will auto generate one." + } + ], + "inputs": [ + { + "name": "input", + "type": "T1", + "description": "All values in input have to be in the range:[0, 1]." + } + ], + "min_input": 1, + "max_input": 1, + "outputs": [ + { + "name": "output", + "type": "T2", + "description": "The returned output tensor only has values 0 or 1, same shape as input tensor." + } + ], + "min_output": 1, + "max_output": 1, + "type_constraints": [ + { + "description": "Constrain input types to float tensors.", + "type_param_str": "T1", + "allowed_type_strs": [ + "tensor(float16)", + "tensor(float)", + "tensor(double)" + ] + }, + { + "description": "Constrain output types to all numeric tensors and bool tensors.", + "type_param_str": "T2", + "allowed_type_strs": [ + "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)" + ] + } + ], + "examples": [ + { + "summary": "bernoulli_with_dtype", + "code": "node = onnx.helper.make_node(\n 'Bernoulli',\n inputs=['x'],\n outputs=['y'],\n dtype=onnx.TensorProto.DOUBLE,\n)\n\nx = np.random.uniform(0.0, 1.0, 10).astype(np.float32)\ny = bernoulli_reference_implementation(x, np.float64)\nexpect(node, inputs=[x], outputs=[y], name='test_bernoulli_double')" + }, + { + "summary": "bernoulli_with_seed", + "code": "seed = np.float(0)\nnode = onnx.helper.make_node(\n 'Bernoulli',\n inputs=['x'],\n outputs=['y'],\n seed=seed,\n)\n\nx = np.random.uniform(0.0, 1.0, 10).astype(np.float32)\ny = bernoulli_reference_implementation(x, np.float32)\nexpect(node, inputs=[x], outputs=[y], name='test_bernoulli_seed')" + }, + { + "summary": "bernoulli_without_dtype", + "code": "node = onnx.helper.make_node(\n 'Bernoulli',\n inputs=['x'],\n outputs=['y'],\n)\n\nx = np.random.uniform(0.0, 1.0, 10).astype(np.float)\ny = bernoulli_reference_implementation(x, np.float)\nexpect(node, inputs=[x], outputs=[y], name='test_bernoulli')" + } + ] + }, + { + "name": "Binarizer", + "module": "ai.onnx.ml", + "version": 1, + "support_level": "common", + "description": "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.\n", + "attributes": [ + { + "name": "threshold", + "type": "float32", + "required": false, + "description": "Values greater than this are mapped to 1, others to 0." + } + ], + "inputs": [ + { + "name": "X", + "type": "T", + "description": "Data to be binarized" + } + ], + "min_input": 1, + "max_input": 1, + "outputs": [ + { + "name": "Y", + "type": "T", + "description": "Binarized output data" + } + ], + "min_output": 1, + "max_output": 1, + "type_constraints": [ + { + "description": "The input must be a tensor of a numeric type. The output will be of the same tensor type.", + "type_param_str": "T", + "allowed_type_strs": [ + "tensor(float)", + "tensor(double)", + "tensor(int64)", + "tensor(int32)" + ] + } + ] + }, + { + "name": "BitShift", + "module": "ai.onnx", + "version": 11, + "support_level": "common", + "description": "Bitwise shift operator performs element-wise operation. For each input element, if the\n attribute \"direction\" is \"RIGHT\", this operator moves its binary representation toward\n the right side so that the input value is effectively decreased. If the attribute \"direction\"\n is \"LEFT\", bits of binary representation moves toward the left side, which results the\n increase of its actual value. The input X is the tensor to be shifted and another input\n Y specifies the amounts of shifting. For example, if \"direction\" is \"Right\", X is [1, 4],\n and S is [1, 1], the corresponding output Z would be [0, 2]. If \"direction\" is \"LEFT\" with\n X=[1, 2] and S=[1, 2], the corresponding output Y would be [2, 8].\n\n Because this operator supports Numpy-style broadcasting, X's and Y's shapes are\n not necessarily identical.\nThis operator supports **multidirectional (i.e., Numpy-style) broadcasting**; for more details please check [the doc](https://github.com/onnx/onnx/blob/master/docs/Broadcasting.md).", + "attributes": [ + { + "name": "direction", + "type": "string", + "required": true, + "description": "Direction of moving bits. It can be either \"RIGHT\" (for right shift) or \"LEFT\" (for left shift)." + } + ], + "inputs": [ + { + "name": "X", + "type": "T", + "description": "First operand, input to be shifted." + }, + { + "name": "Y", + "type": "T", + "description": "Second operand, amounts of shift." + } + ], + "min_input": 2, + "max_input": 2, + "outputs": [ + { + "name": "Z", + "type": "T", + "description": "Output tensor" + } + ], + "min_output": 1, + "max_output": 1, + "type_constraints": [ + { + "description": "Constrain input and output types to integer tensors.", + "type_param_str": "T", + "allowed_type_strs": [ + "tensor(uint8)", + "tensor(uint16)", + "tensor(uint32)", + "tensor(uint64)" + ] + } + ], + "examples": [ + { + "summary": "left_unit16", + "code": "node = onnx.helper.make_node(\n 'BitShift',\n inputs=['x', 'y'],\n outputs=['z'],\n direction=\"LEFT\"\n)\n\nx = np.array([16, 4, 1]).astype(np.uint16)\ny = np.array([1, 2, 3]).astype(np.uint16)\nz = x << y # expected output [32, 16, 8]\nexpect(node, inputs=[x, y], outputs=[z],\n name='test_bitshift_left_uint16')" + }, + { + "summary": "left_unit32", + "code": "node = onnx.helper.make_node(\n 'BitShift',\n inputs=['x', 'y'],\n outputs=['z'],\n direction=\"LEFT\"\n)\n\nx = np.array([16, 4, 1]).astype(np.uint32)\ny = np.array([1, 2, 3]).astype(np.uint32)\nz = x << y # expected output [32, 16, 8]\nexpect(node, inputs=[x, y], outputs=[z],\n name='test_bitshift_left_uint32')" + }, + { + "summary": "left_unit64", + "code": "node = onnx.helper.make_node(\n 'BitShift',\n inputs=['x', 'y'],\n outputs=['z'],\n direction=\"LEFT\"\n)\n\nx = np.array([16, 4, 1]).astype(np.uint64)\ny = np.array([1, 2, 3]).astype(np.uint64)\nz = x << y # expected output [32, 16, 8]\nexpect(node, inputs=[x, y], outputs=[z],\n name='test_bitshift_left_uint64')" + }, + { + "summary": "left_unit8", + "code": "node = onnx.helper.make_node(\n 'BitShift',\n inputs=['x', 'y'],\n outputs=['z'],\n direction=\"LEFT\"\n)\n\nx = np.array([16, 4, 1]).astype(np.uint8)\ny = np.array([1, 2, 3]).astype(np.uint8)\nz = x << y # expected output [32, 16, 8]\nexpect(node, inputs=[x, y], outputs=[z],\n name='test_bitshift_left_uint8')" + }, + { + "summary": "right_unit16", + "code": "node = onnx.helper.make_node(\n 'BitShift',\n inputs=['x', 'y'],\n outputs=['z'],\n direction=\"RIGHT\"\n)\n\nx = np.array([16, 4, 1]).astype(np.uint16)\ny = np.array([1, 2, 3]).astype(np.uint16)\nz = x >> y # expected output [8, 1, 0]\nexpect(node, inputs=[x, y], outputs=[z],\n name='test_bitshift_right_uint16')" + }, + { + "summary": "right_unit32", + "code": "node = onnx.helper.make_node(\n 'BitShift',\n inputs=['x', 'y'],\n outputs=['z'],\n direction=\"RIGHT\"\n)\n\nx = np.array([16, 4, 1]).astype(np.uint32)\ny = np.array([1, 2, 3]).astype(np.uint32)\nz = x >> y # expected output [8, 1, 0]\nexpect(node, inputs=[x, y], outputs=[z],\n name='test_bitshift_right_uint32')" + }, + { + "summary": "right_unit64", + "code": "node = onnx.helper.make_node(\n 'BitShift',\n inputs=['x', 'y'],\n outputs=['z'],\n direction=\"RIGHT\"\n)\n\nx = np.array([16, 4, 1]).astype(np.uint64)\ny = np.array([1, 2, 3]).astype(np.uint64)\nz = x >> y # expected output [8, 1, 0]\nexpect(node, inputs=[x, y], outputs=[z],\n name='test_bitshift_right_uint64')" + }, + { + "summary": "right_unit8", + "code": "node = onnx.helper.make_node(\n 'BitShift',\n inputs=['x', 'y'],\n outputs=['z'],\n direction=\"RIGHT\"\n)\n\nx = np.array([16, 4, 1]).astype(np.uint8)\ny = np.array([1, 2, 3]).astype(np.uint8)\nz = x >> y # expected output [8, 1, 0]\nexpect(node, inputs=[x, y], outputs=[z],\n name='test_bitshift_right_uint8')" + } + ] + }, + { + "name": "Cast", + "module": "ai.onnx", + "version": 1, + "support_level": "common", + "description": "The operator casts the elements of a given input tensor to a data type\nspecified by the 'to' argument and returns an output tensor of the same size in\nthe converted type. The 'to' argument must be one of the data types specified\nin the 'DataType' enum field in the TensorProto message.\nNOTE: Casting to and from strings is not supported yet.\n", + "attributes": [ + { + "name": "to", + "type": "DataType", + "required": true, + "description": "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": [ + { + "name": "input", + "type": "T1", + "description": "Input tensor to be cast." + } + ], + "min_input": 1, + "max_input": 1, + "outputs": [ + { + "name": "output", + "type": "T2", + "description": "Output tensor with the same shape as input with type specified by the 'to' argument" + } + ], + "min_output": 1, + "max_output": 1, + "type_constraints": [ + { + "description": "Constrain input types. Casting from strings and complex are not supported.", + "type_param_str": "T1", + "allowed_type_strs": [ + "tensor(float16)", + "tensor(float)", + "tensor(double)", + "tensor(int8)", + "tensor(int16)", + "tensor(int32)", + "tensor(int64)", + "tensor(uint8)", + "tensor(uint16)", + "tensor(uint32)", + "tensor(uint64)", + "tensor(bool)" + ] + }, + { + "description": "Constrain output types. Casting to strings and complex are not supported.", + "type_param_str": "T2", + "allowed_type_strs": [ + "tensor(float16)", + "tensor(float)", + "tensor(double)", + "tensor(int8)", + "tensor(int16)", + "tensor(int32)", + "tensor(int64)", + "tensor(uint8)", + "tensor(uint16)", + "tensor(uint32)", + "tensor(uint64)", + "tensor(bool)" + ] + } + ], + "examples": [ + { + "summary": "cast", + "code": "shape = (3, 4)\ntest_cases = [\n ('FLOAT', 'FLOAT16'),\n ('FLOAT', 'DOUBLE'),\n ('FLOAT16', 'FLOAT'),\n ('FLOAT16', 'DOUBLE'),\n ('DOUBLE', 'FLOAT'),\n ('DOUBLE', 'FLOAT16'),\n ('FLOAT', 'STRING'),\n ('STRING', 'FLOAT'),\n ('FLOAT', 'BFLOAT16'),\n ('BFLOAT16', 'FLOAT'),\n]\n\nfor from_type, to_type in test_cases:\n input_type_proto = None\n output_type_proto = None\n if 'BFLOAT16' == from_type or 'BFLOAT16' == to_type:\n np_fp32 = np.array([u'0.47892547', u'0.48033667', u'0.49968487', u'0.81910545',\n u'0.47031248', u'0.816468', u'0.21087195', u'0.7229038',\n u'NaN', u'INF', u'+INF', u'-INF'], dtype=np.float32)\n little_endisan = sys.byteorder == 'little'\n np_uint16_view = np_fp32.view(dtype=np.uint16)\n np_bfp16 = np_uint16_view[1::2] if little_endisan else np_uint16_view[0::2]\n if 'BFLOAT16' == to_type:\n assert from_type == 'FLOAT'\n input = np_fp32.reshape([3, 4])\n output = np_bfp16.reshape([3, 4])\n input_type_proto = onnx.helper.make_tensor_type_proto(int(TensorProto.FLOAT), input.shape)\n output_type_proto = onnx.helper.make_tensor_type_proto(int(TensorProto.BFLOAT16), output.shape)\n else:\n assert to_type == 'FLOAT'\n input = np_bfp16.reshape([3, 4])\n #convert bfloat to FLOAT\n np_fp32_zeros = np.zeros((len(np_bfp16) * 2,), dtype=np.uint16)\n if little_endisan:\n np_fp32_zeros[1::2] = np_bfp16\n else:\n np_fp32_zeros[0::2] = np_bfp16\n np_fp32_from_bfloat = np_fp32_zeros.view(dtype=np.float32)\n output = np_fp32_from_bfloat.reshape([3, 4])\n input_type_proto = onnx.helper.make_tensor_type_proto(int(TensorProto.BFLOAT16), input.shape)\n output_type_proto = onnx.helper.make_tensor_type_proto(int(TensorProto.FLOAT), output.shape)\n elif 'STRING' != from_type:\n input = np.random.random_sample(shape).astype(\n TENSOR_TYPE_TO_NP_TYPE[getattr(TensorProto, from_type)])\n if ('STRING' == to_type):\n # Converting input to str, then give it object dtype for generating script\n ss = []\n for i in input.flatten():\n s = str(i).encode('utf-8')\n su = s.decode('utf-8')\n ss.append(su)\n\n output = np.array(ss).astype(object).reshape([3, 4])\n else:\n output = input.astype(TENSOR_TYPE_TO_NP_TYPE[getattr(TensorProto, to_type)])\n else:\n input = np.array([u'0.47892547', u'0.48033667', u'0.49968487', u'0.81910545',\n u'0.47031248', u'0.816468', u'0.21087195', u'0.7229038',\n u'NaN', u'INF', u'+INF', u'-INF'], dtype=np.dtype(object)).reshape([3, 4])\n output = input.astype(TENSOR_TYPE_TO_NP_TYPE[getattr(TensorProto, to_type)])\n node = onnx.helper.make_node(\n 'Cast',\n inputs=['input'],\n outputs=['output'],\n to=getattr(TensorProto, to_type),\n )\n if input_type_proto and output_type_proto:\n expect(node, inputs=[input], outputs=[output],\n name='test_cast_' + from_type + '_to_' + to_type,\n input_type_protos=[input_type_proto],\n output_type_protos=[output_type_proto])\n else:\n expect(node, inputs=[input], outputs=[output],\n name='test_cast_' + from_type + '_to_' + to_type)" + } + ] + }, + { + "name": "Cast", + "module": "ai.onnx", + "version": 6, + "support_level": "common", + "description": "The operator casts the elements of a given input tensor to a data type\nspecified by the 'to' argument and returns an output tensor of the same size in\nthe converted type. The 'to' argument must be one of the data types specified\nin the 'DataType' enum field in the TensorProto message.\nNOTE: Casting to and from strings is not supported yet.\n", + "attributes": [ + { + "name": "to", + "type": "DataType", + "required": true, + "description": "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": [ + { + "name": "input", + "type": "T1", + "description": "Input tensor to be cast." + } + ], + "min_input": 1, + "max_input": 1, + "outputs": [ + { + "name": "output", + "type": "T2", + "description": "Output tensor with the same shape as input with type specified by the 'to' argument" + } + ], + "min_output": 1, + "max_output": 1, + "type_constraints": [ + { + "description": "Constrain input types. Casting from strings and complex are not supported.", + "type_param_str": "T1", + "allowed_type_strs": [ + "tensor(float16)", + "tensor(float)", + "tensor(double)", + "tensor(int8)", + "tensor(int16)", + "tensor(int32)", + "tensor(int64)", + "tensor(uint8)", + "tensor(uint16)", + "tensor(uint32)", + "tensor(uint64)", + "tensor(bool)" + ] + }, + { + "description": "Constrain output types. Casting to strings and complex are not supported.", + "type_param_str": "T2", + "allowed_type_strs": [ + "tensor(float16)", + "tensor(float)", + "tensor(double)", + "tensor(int8)", + "tensor(int16)", + "tensor(int32)", + "tensor(int64)", + "tensor(uint8)", + "tensor(uint16)", + "tensor(uint32)", + "tensor(uint64)", + "tensor(bool)" + ] + } + ], + "examples": [ + { + "summary": "cast", + "code": "shape = (3, 4)\ntest_cases = [\n ('FLOAT', 'FLOAT16'),\n ('FLOAT', 'DOUBLE'),\n ('FLOAT16', 'FLOAT'),\n ('FLOAT16', 'DOUBLE'),\n ('DOUBLE', 'FLOAT'),\n ('DOUBLE', 'FLOAT16'),\n ('FLOAT', 'STRING'),\n ('STRING', 'FLOAT'),\n ('FLOAT', 'BFLOAT16'),\n ('BFLOAT16', 'FLOAT'),\n]\n\nfor from_type, to_type in test_cases:\n input_type_proto = None\n output_type_proto = None\n if 'BFLOAT16' == from_type or 'BFLOAT16' == to_type:\n np_fp32 = np.array([u'0.47892547', u'0.48033667', u'0.49968487', u'0.81910545',\n u'0.47031248', u'0.816468', u'0.21087195', u'0.7229038',\n u'NaN', u'INF', u'+INF', u'-INF'], dtype=np.float32)\n little_endisan = sys.byteorder == 'little'\n np_uint16_view = np_fp32.view(dtype=np.uint16)\n np_bfp16 = np_uint16_view[1::2] if little_endisan else np_uint16_view[0::2]\n if 'BFLOAT16' == to_type:\n assert from_type == 'FLOAT'\n input = np_fp32.reshape([3, 4])\n output = np_bfp16.reshape([3, 4])\n input_type_proto = onnx.helper.make_tensor_type_proto(int(TensorProto.FLOAT), input.shape)\n output_type_proto = onnx.helper.make_tensor_type_proto(int(TensorProto.BFLOAT16), output.shape)\n else:\n assert to_type == 'FLOAT'\n input = np_bfp16.reshape([3, 4])\n #convert bfloat to FLOAT\n np_fp32_zeros = np.zeros((len(np_bfp16) * 2,), dtype=np.uint16)\n if little_endisan:\n np_fp32_zeros[1::2] = np_bfp16\n else:\n np_fp32_zeros[0::2] = np_bfp16\n np_fp32_from_bfloat = np_fp32_zeros.view(dtype=np.float32)\n output = np_fp32_from_bfloat.reshape([3, 4])\n input_type_proto = onnx.helper.make_tensor_type_proto(int(TensorProto.BFLOAT16), input.shape)\n output_type_proto = onnx.helper.make_tensor_type_proto(int(TensorProto.FLOAT), output.shape)\n elif 'STRING' != from_type:\n input = np.random.random_sample(shape).astype(\n TENSOR_TYPE_TO_NP_TYPE[getattr(TensorProto, from_type)])\n if ('STRING' == to_type):\n # Converting input to str, then give it object dtype for generating script\n ss = []\n for i in input.flatten():\n s = str(i).encode('utf-8')\n su = s.decode('utf-8')\n ss.append(su)\n\n output = np.array(ss).astype(object).reshape([3, 4])\n else:\n output = input.astype(TENSOR_TYPE_TO_NP_TYPE[getattr(TensorProto, to_type)])\n else:\n input = np.array([u'0.47892547', u'0.48033667', u'0.49968487', u'0.81910545',\n u'0.47031248', u'0.816468', u'0.21087195', u'0.7229038',\n u'NaN', u'INF', u'+INF', u'-INF'], dtype=np.dtype(object)).reshape([3, 4])\n output = input.astype(TENSOR_TYPE_TO_NP_TYPE[getattr(TensorProto, to_type)])\n node = onnx.helper.make_node(\n 'Cast',\n inputs=['input'],\n outputs=['output'],\n to=getattr(TensorProto, to_type),\n )\n if input_type_proto and output_type_proto:\n expect(node, inputs=[input], outputs=[output],\n name='test_cast_' + from_type + '_to_' + to_type,\n input_type_protos=[input_type_proto],\n output_type_protos=[output_type_proto])\n else:\n expect(node, inputs=[input], outputs=[output],\n name='test_cast_' + from_type + '_to_' + to_type)" + } + ] + }, + { + "name": "Cast", + "module": "ai.onnx", + "version": 9, + "support_level": "common", + "description": "The operator casts the elements of a given input tensor to a data type\nspecified by the 'to' argument and returns an output tensor of the same size in\nthe converted type. The 'to' argument must be one of the data types specified\nin the 'DataType' enum field in the TensorProto message.\n\nCasting from string tensor in plain (e.g., \"3.14\" and \"1000\") and scientific numeric representations\n(e.g., \"1e-5\" and \"1E8\") to float types is supported. For example, converting string \"100.5\" to an integer may\nresult 100. There are some string literals reserved for special floating-point values;\n\"+INF\" (and \"INF\"), \"-INF\", and \"NaN\" are positive infinity, negative infinity, and not-a-number, respectively.\nAny string which can exactly match \"+INF\" in a case-insensitive way would be mapped to positive infinite. Similarly,\nthis case-insensitive rule is applied to \"INF\" and \"NaN\". When casting from numeric tensors\nto string tensors, plain floating-point representation (such as \"314.15926\") would be used.\nConverting non-numerical-literal string such as \"Hello World!\" is an undefined behavior. Cases\nof converting string representing floating-point arithmetic value, such as \"2.718\", to INT is an undefined behavior.\n\nConversion from a numerical type to any numerical type is always allowed.\nUser must be aware of precision loss and value change caused by range difference between two types.\nFor example, a 64-bit float 3.1415926459 may be round to a 32-bit float 3.141592. Similarly, converting\nan integer 36 to Boolean may produce 1 because we truncate bits which can't be stored in the targeted type.\n", + "attributes": [ + { + "name": "to", + "type": "DataType", + "required": true, + "description": "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": [ + { + "name": "input", + "type": "T1", + "description": "Input tensor to be cast." + } + ], + "min_input": 1, + "max_input": 1, + "outputs": [ + { + "name": "output", + "type": "T2", + "description": "Output tensor with the same shape as input with type specified by the 'to' argument" + } + ], + "min_output": 1, + "max_output": 1, + "type_constraints": [ + { + "description": "Constrain input types. Casting from complex is not supported.", + "type_param_str": "T1", + "allowed_type_strs": [ + "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)" + ] + }, + { + "description": "Constrain output types. Casting to complex is not supported.", + "type_param_str": "T2", + "allowed_type_strs": [ + "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)" + ] + } + ], + "examples": [ + { + "summary": "cast", + "code": "shape = (3, 4)\ntest_cases = [\n ('FLOAT', 'FLOAT16'),\n ('FLOAT', 'DOUBLE'),\n ('FLOAT16', 'FLOAT'),\n ('FLOAT16', 'DOUBLE'),\n ('DOUBLE', 'FLOAT'),\n ('DOUBLE', 'FLOAT16'),\n ('FLOAT', 'STRING'),\n ('STRING', 'FLOAT'),\n ('FLOAT', 'BFLOAT16'),\n ('BFLOAT16', 'FLOAT'),\n]\n\nfor from_type, to_type in test_cases:\n input_type_proto = None\n output_type_proto = None\n if 'BFLOAT16' == from_type or 'BFLOAT16' == to_type:\n np_fp32 = np.array([u'0.47892547', u'0.48033667', u'0.49968487', u'0.81910545',\n u'0.47031248', u'0.816468', u'0.21087195', u'0.7229038',\n u'NaN', u'INF', u'+INF', u'-INF'], dtype=np.float32)\n little_endisan = sys.byteorder == 'little'\n np_uint16_view = np_fp32.view(dtype=np.uint16)\n np_bfp16 = np_uint16_view[1::2] if little_endisan else np_uint16_view[0::2]\n if 'BFLOAT16' == to_type:\n assert from_type == 'FLOAT'\n input = np_fp32.reshape([3, 4])\n output = np_bfp16.reshape([3, 4])\n input_type_proto = onnx.helper.make_tensor_type_proto(int(TensorProto.FLOAT), input.shape)\n output_type_proto = onnx.helper.make_tensor_type_proto(int(TensorProto.BFLOAT16), output.shape)\n else:\n assert to_type == 'FLOAT'\n input = np_bfp16.reshape([3, 4])\n #convert bfloat to FLOAT\n np_fp32_zeros = np.zeros((len(np_bfp16) * 2,), dtype=np.uint16)\n if little_endisan:\n np_fp32_zeros[1::2] = np_bfp16\n else:\n np_fp32_zeros[0::2] = np_bfp16\n np_fp32_from_bfloat = np_fp32_zeros.view(dtype=np.float32)\n output = np_fp32_from_bfloat.reshape([3, 4])\n input_type_proto = onnx.helper.make_tensor_type_proto(int(TensorProto.BFLOAT16), input.shape)\n output_type_proto = onnx.helper.make_tensor_type_proto(int(TensorProto.FLOAT), output.shape)\n elif 'STRING' != from_type:\n input = np.random.random_sample(shape).astype(\n TENSOR_TYPE_TO_NP_TYPE[getattr(TensorProto, from_type)])\n if ('STRING' == to_type):\n # Converting input to str, then give it object dtype for generating script\n ss = []\n for i in input.flatten():\n s = str(i).encode('utf-8')\n su = s.decode('utf-8')\n ss.append(su)\n\n output = np.array(ss).astype(object).reshape([3, 4])\n else:\n output = input.astype(TENSOR_TYPE_TO_NP_TYPE[getattr(TensorProto, to_type)])\n else:\n input = np.array([u'0.47892547', u'0.48033667', u'0.49968487', u'0.81910545',\n u'0.47031248', u'0.816468', u'0.21087195', u'0.7229038',\n u'NaN', u'INF', u'+INF', u'-INF'], dtype=np.dtype(object)).reshape([3, 4])\n output = input.astype(TENSOR_TYPE_TO_NP_TYPE[getattr(TensorProto, to_type)])\n node = onnx.helper.make_node(\n 'Cast',\n inputs=['input'],\n outputs=['output'],\n to=getattr(TensorProto, to_type),\n )\n if input_type_proto and output_type_proto:\n expect(node, inputs=[input], outputs=[output],\n name='test_cast_' + from_type + '_to_' + to_type,\n input_type_protos=[input_type_proto],\n output_type_protos=[output_type_proto])\n else:\n expect(node, inputs=[input], outputs=[output],\n name='test_cast_' + from_type + '_to_' + to_type)" + } + ] + }, + { + "name": "Cast", + "module": "ai.onnx", + "version": 13, + "support_level": "common", + "description": "The operator casts the elements of a given input tensor to a data type\nspecified by the 'to' argument and returns an output tensor of the same size in\nthe converted type. The 'to' argument must be one of the data types specified\nin the 'DataType' enum field in the TensorProto message.\n\nCasting from string tensor in plain (e.g., \"3.14\" and \"1000\") and scientific numeric representations\n(e.g., \"1e-5\" and \"1E8\") to float types is supported. For example, converting string \"100.5\" to an integer may\nresult 100. There are some string literals reserved for special floating-point values;\n\"+INF\" (and \"INF\"), \"-INF\", and \"NaN\" are positive infinity, negative infinity, and not-a-number, respectively.\nAny string which can exactly match \"+INF\" in a case-insensitive way would be mapped to positive infinite. Similarly,\nthis case-insensitive rule is applied to \"INF\" and \"NaN\". When casting from numeric tensors\nto string tensors, plain floating-point representation (such as \"314.15926\") would be used.\nConverting non-numerical-literal string such as \"Hello World!\" is an undefined behavior. Cases\nof converting string representing floating-point arithmetic value, such as \"2.718\", to INT is an undefined behavior.\n\nConversion from a numerical type to any numerical type is always allowed.\nUser must be aware of precision loss and value change caused by range difference between two types.\nFor example, a 64-bit float 3.1415926459 may be round to a 32-bit float 3.141592. Similarly, converting\nan integer 36 to Boolean may produce 1 because we truncate bits which can't be stored in the targeted type.\n", + "attributes": [ + { + "name": "to", + "type": "DataType", + "required": true, + "description": "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": [ + { + "name": "input", + "type": "T1", + "description": "Input tensor to be cast." + } + ], + "min_input": 1, + "max_input": 1, + "outputs": [ + { + "name": "output", + "type": "T2", + "description": "Output tensor with the same shape as input with type specified by the 'to' argument" + } + ], + "min_output": 1, + "max_output": 1, + "type_constraints": [ + { + "description": "Constrain input types. Casting from complex is not supported.", + "type_param_str": "T1", + "allowed_type_strs": [ + "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)" + ] + }, + { + "description": "Constrain output types. Casting to complex is not supported.", + "type_param_str": "T2", + "allowed_type_strs": [ + "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)" + ] + } + ], + "examples": [ + { + "summary": "cast", + "code": "shape = (3, 4)\ntest_cases = [\n ('FLOAT', 'FLOAT16'),\n ('FLOAT', 'DOUBLE'),\n ('FLOAT16', 'FLOAT'),\n ('FLOAT16', 'DOUBLE'),\n ('DOUBLE', 'FLOAT'),\n ('DOUBLE', 'FLOAT16'),\n ('FLOAT', 'STRING'),\n ('STRING', 'FLOAT'),\n ('FLOAT', 'BFLOAT16'),\n ('BFLOAT16', 'FLOAT'),\n]\n\nfor from_type, to_type in test_cases:\n input_type_proto = None\n output_type_proto = None\n if 'BFLOAT16' == from_type or 'BFLOAT16' == to_type:\n np_fp32 = np.array([u'0.47892547', u'0.48033667', u'0.49968487', u'0.81910545',\n u'0.47031248', u'0.816468', u'0.21087195', u'0.7229038',\n u'NaN', u'INF', u'+INF', u'-INF'], dtype=np.float32)\n little_endisan = sys.byteorder == 'little'\n np_uint16_view = np_fp32.view(dtype=np.uint16)\n np_bfp16 = np_uint16_view[1::2] if little_endisan else np_uint16_view[0::2]\n if 'BFLOAT16' == to_type:\n assert from_type == 'FLOAT'\n input = np_fp32.reshape([3, 4])\n output = np_bfp16.reshape([3, 4])\n input_type_proto = onnx.helper.make_tensor_type_proto(int(TensorProto.FLOAT), input.shape)\n output_type_proto = onnx.helper.make_tensor_type_proto(int(TensorProto.BFLOAT16), output.shape)\n else:\n assert to_type == 'FLOAT'\n input = np_bfp16.reshape([3, 4])\n #convert bfloat to FLOAT\n np_fp32_zeros = np.zeros((len(np_bfp16) * 2,), dtype=np.uint16)\n if little_endisan:\n np_fp32_zeros[1::2] = np_bfp16\n else:\n np_fp32_zeros[0::2] = np_bfp16\n np_fp32_from_bfloat = np_fp32_zeros.view(dtype=np.float32)\n output = np_fp32_from_bfloat.reshape([3, 4])\n input_type_proto = onnx.helper.make_tensor_type_proto(int(TensorProto.BFLOAT16), input.shape)\n output_type_proto = onnx.helper.make_tensor_type_proto(int(TensorProto.FLOAT), output.shape)\n elif 'STRING' != from_type:\n input = np.random.random_sample(shape).astype(\n TENSOR_TYPE_TO_NP_TYPE[getattr(TensorProto, from_type)])\n if ('STRING' == to_type):\n # Converting input to str, then give it object dtype for generating script\n ss = []\n for i in input.flatten():\n s = str(i).encode('utf-8')\n su = s.decode('utf-8')\n ss.append(su)\n\n output = np.array(ss).astype(object).reshape([3, 4])\n else:\n output = input.astype(TENSOR_TYPE_TO_NP_TYPE[getattr(TensorProto, to_type)])\n else:\n input = np.array([u'0.47892547', u'0.48033667', u'0.49968487', u'0.81910545',\n u'0.47031248', u'0.816468', u'0.21087195', u'0.7229038',\n u'NaN', u'INF', u'+INF', u'-INF'], dtype=np.dtype(object)).reshape([3, 4])\n output = input.astype(TENSOR_TYPE_TO_NP_TYPE[getattr(TensorProto, to_type)])\n node = onnx.helper.make_node(\n 'Cast',\n inputs=['input'],\n outputs=['output'],\n to=getattr(TensorProto, to_type),\n )\n if input_type_proto and output_type_proto:\n expect(node, inputs=[input], outputs=[output],\n name='test_cast_' + from_type + '_to_' + to_type,\n input_type_protos=[input_type_proto],\n output_type_protos=[output_type_proto])\n else:\n expect(node, inputs=[input], outputs=[output],\n name='test_cast_' + from_type + '_to_' + to_type)" + } + ] + }, + { + "name": "CastLike", + "module": "ai.onnx", + "version": 15, + "support_level": "common", + "description": "The operator casts the elements of a given input tensor (the first input) to\nthe same data type as the elements of the second input tensor.\nSee documentation of the Cast operator for further details.\n", + "inputs": [ + { + "name": "input", + "type": "T1", + "description": "Input tensor to be cast." + }, + { + "name": "target_type", + "type": "T2", + "description": "The (first) input tensor will be cast to produce a tensor of the same type as this (second input) tensor." + } + ], + "min_input": 2, + "max_input": 2, + "outputs": [ + { + "name": "output", + "type": "T2", + "description": "Output tensor produced by casting the first input tensor to have the same type as the second input tensor." + } + ], + "min_output": 1, + "max_output": 1, + "type_constraints": [ + { + "description": "Constrain input types. Casting from complex is not supported.", + "type_param_str": "T1", + "allowed_type_strs": [ + "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)" + ] + }, + { + "description": "Constrain output types. Casting to complex is not supported.", + "type_param_str": "T2", + "allowed_type_strs": [ + "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)" + ] + } + ], + "examples": [ + { + "summary": "castlike", + "code": "shape = (3, 4)\ntest_cases = [\n ('FLOAT', 'FLOAT16'),\n ('FLOAT', 'DOUBLE'),\n ('FLOAT16', 'FLOAT'),\n ('FLOAT16', 'DOUBLE'),\n ('DOUBLE', 'FLOAT'),\n ('DOUBLE', 'FLOAT16'),\n ('FLOAT', 'STRING'),\n ('STRING', 'FLOAT'),\n ('FLOAT', 'BFLOAT16'),\n ('BFLOAT16', 'FLOAT'),\n]\n\nfor from_type, to_type in test_cases:\n input_type_proto = None\n output_type_proto = None\n if 'BFLOAT16' == from_type or 'BFLOAT16' == to_type:\n np_fp32 = np.array([u'0.47892547', u'0.48033667', u'0.49968487', u'0.81910545',\n u'0.47031248', u'0.816468', u'0.21087195', u'0.7229038',\n u'NaN', u'INF', u'+INF', u'-INF'], dtype=np.float32)\n little_endisan = sys.byteorder == 'little'\n np_uint16_view = np_fp32.view(dtype=np.uint16)\n np_bfp16 = np_uint16_view[1::2] if little_endisan else np_uint16_view[0::2]\n if 'BFLOAT16' == to_type:\n assert from_type == 'FLOAT'\n input = np_fp32.reshape([3, 4])\n output = np_bfp16.reshape([3, 4])\n input_type_proto = onnx.helper.make_tensor_type_proto(int(TensorProto.FLOAT), input.shape)\n output_type_proto = onnx.helper.make_tensor_type_proto(int(TensorProto.BFLOAT16), output.shape)\n else:\n assert to_type == 'FLOAT'\n input = np_bfp16.reshape([3, 4])\n #convert bfloat to FLOAT\n np_fp32_zeros = np.zeros((len(np_bfp16) * 2,), dtype=np.uint16)\n if little_endisan:\n np_fp32_zeros[1::2] = np_bfp16\n else:\n np_fp32_zeros[0::2] = np_bfp16\n np_fp32_from_bfloat = np_fp32_zeros.view(dtype=np.float32)\n output = np_fp32_from_bfloat.reshape([3, 4])\n input_type_proto = onnx.helper.make_tensor_type_proto(int(TensorProto.BFLOAT16), input.shape)\n output_type_proto = onnx.helper.make_tensor_type_proto(int(TensorProto.FLOAT), output.shape)\n elif 'STRING' != from_type:\n input = np.random.random_sample(shape).astype(\n TENSOR_TYPE_TO_NP_TYPE[getattr(TensorProto, from_type)])\n if ('STRING' == to_type):\n # Converting input to str, then give it np.object dtype for generating script\n ss = []\n for i in input.flatten():\n s = str(i).encode('utf-8')\n su = s.decode('utf-8')\n ss.append(su)\n\n output = np.array(ss).astype(np.object).reshape([3, 4])\n else:\n output = input.astype(TENSOR_TYPE_TO_NP_TYPE[getattr(TensorProto, to_type)])\n else:\n input = np.array([u'0.47892547', u'0.48033667', u'0.49968487', u'0.81910545',\n u'0.47031248', u'0.816468', u'0.21087195', u'0.7229038',\n u'NaN', u'INF', u'+INF', u'-INF'], dtype=np.dtype(np.object)).reshape([3, 4])\n output = input.astype(TENSOR_TYPE_TO_NP_TYPE[getattr(TensorProto, to_type)])\n like = output.flatten()[0:1]\n node = onnx.helper.make_node(\n 'CastLike',\n inputs=['input', 'like'],\n outputs=['output'],\n )\n if input_type_proto and output_type_proto:\n expect(node, inputs=[input, like], outputs=[output],\n name='test_castlike_' + from_type + '_to_' + to_type,\n input_type_protos=[input_type_proto, output_type_proto],\n output_type_protos=[output_type_proto])\n else:\n expect(node, inputs=[input, like], outputs=[output],\n name='test_castlike_' + from_type + '_to_' + to_type)" + } + ] + }, + { + "name": "CastMap", + "module": "ai.onnx.ml", + "version": 1, + "support_level": "common", + "description": "Converts a map to a tensor.
The map key must be an int64 and the values will be ordered\n in ascending order based on this key.
The operator supports dense packing or sparse packing.\n If using sparse packing, the key cannot exceed the max_map-1 value.\n", + "attributes": [ + { + "name": "cast_to", + "type": "string", + "required": false, + "default": "TO_FLOAT", + "description": "A string indicating the desired element type of the output tensor, one of 'TO_FLOAT', 'TO_STRING', 'TO_INT64'." + }, + { + "name": "map_form", + "type": "string", + "required": false, + "default": "DENSE", + "description": "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'." + }, + { + "name": "max_map", + "type": "int64", + "required": false, + "default": 1, + "description": "If the value of map_form is 'SPARSE,' this attribute indicates the total length of the output tensor." + } + ], + "inputs": [ + { + "name": "X", + "type": "T1", + "description": "The input map that is to be cast to a tensor" + } + ], + "min_input": 1, + "max_input": 1, + "outputs": [ + { + "name": "Y", + "type": "T2", + "description": "A tensor representing the same data as the input map, ordered by their keys" + } + ], + "min_output": 1, + "max_output": 1, + "type_constraints": [ + { + "description": "The input must be an integer map to either string or float.", + "type_param_str": "T1", + "allowed_type_strs": [ + "map(int64, string)", + "map(int64, float)" + ] + }, + { + "description": "The output is a 1-D tensor of string, float, or integer.", + "type_param_str": "T2", + "allowed_type_strs": [ + "tensor(string)", + "tensor(float)", + "tensor(int64)" + ] + } + ] + }, + { + "name": "CategoryMapper", + "module": "ai.onnx.ml", + "version": 1, + "support_level": "common", + "description": "Converts strings to integers and vice versa.
\n Two sequences of equal length are used to map between integers and strings,\n with strings and integers at the same index detailing the mapping.
\n Each operator converts either integers to strings or strings to integers, depending\n on which default value attribute is provided. Only one default value attribute\n should be defined.
\n If the string default value is set, it will convert integers to strings.\n If the int default value is set, it will convert strings to integers.\n", + "attributes": [ + { + "name": "cats_int64s", + "type": "int64[]", + "required": false, + "description": "The integers of the map. This sequence must be the same length as the 'cats_strings' sequence." + }, + { + "name": "cats_strings", + "type": "string[]", + "required": false, + "description": "The strings of the map. This sequence must be the same length as the 'cats_int64s' sequence" + }, + { + "name": "default_int64", + "type": "int64", + "required": false, + "default": -1, + "description": "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." + }, + { + "name": "default_string", + "type": "string", + "required": false, + "default": "_Unused", + "description": "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": [ + { + "name": "X", + "type": "T1", + "description": "Input data" + } + ], + "min_input": 1, + "max_input": 1, + "outputs": [ + { + "name": "Y", + "type": "T2", + "description": "Output data. If strings are input, the output values are integers, and vice versa." + } + ], + "min_output": 1, + "max_output": 1, + "type_constraints": [ + { + "description": "The input must be a tensor of strings or integers, either [N,C] or [C].", + "type_param_str": "T1", + "allowed_type_strs": [ + "tensor(string)", + "tensor(int64)" + ] + }, + { + "description": "The output is a tensor of strings or integers. Its shape will be the same as the input shape.", + "type_param_str": "T2", + "allowed_type_strs": [ + "tensor(string)", + "tensor(int64)" + ] + } + ] + }, + { + "name": "Ceil", + "module": "ai.onnx", + "version": 1, + "support_level": "common", + "description": "Ceil takes one input data (Tensor) and produces one output data\n(Tensor) where the ceil is, y = ceil(x), is applied to\nthe tensor elementwise.\n", + "attributes": [ + { + "name": "consumed_inputs", + "type": "int64[]", + "required": false, + "description": "legacy optimization attribute." + } + ], + "inputs": [ + { + "name": "X", + "type": "T", + "description": "Input tensor" + } + ], + "min_input": 1, + "max_input": 1, + "outputs": [ + { + "name": "Y", + "type": "T", + "description": "Output tensor" + } + ], + "min_output": 1, + "max_output": 1, + "type_constraints": [ + { + "description": "Constrain input and output types to float tensors.", + "type_param_str": "T", + "allowed_type_strs": [ + "tensor(float16)", + "tensor(float)", + "tensor(double)" + ] + } + ], + "examples": [ + { + "summary": "ceil", + "code": "node = onnx.helper.make_node(\n 'Ceil',\n inputs=['x'],\n outputs=['y'],\n)\n\nx = np.array([-1.5, 1.2]).astype(np.float32)\ny = np.ceil(x) # expected output [-1., 2.]\nexpect(node, inputs=[x], outputs=[y],\n name='test_ceil_example')\n\nx = np.random.randn(3, 4, 5).astype(np.float32)\ny = np.ceil(x)\nexpect(node, inputs=[x], outputs=[y],\n name='test_ceil')" + } + ] + }, + { + "name": "Ceil", + "module": "ai.onnx", + "version": 6, + "support_level": "common", + "description": "Ceil takes one input data (Tensor) and produces one output data\n(Tensor) where the ceil is, y = ceil(x), is applied to\nthe tensor elementwise.\n", + "inputs": [ + { + "name": "X", + "type": "T", + "description": "Input tensor" + } + ], + "min_input": 1, + "max_input": 1, + "outputs": [ + { + "name": "Y", + "type": "T", + "description": "Output tensor" + } + ], + "min_output": 1, + "max_output": 1, + "type_constraints": [ + { + "description": "Constrain input and output types to float tensors.", + "type_param_str": "T", + "allowed_type_strs": [ + "tensor(float16)", + "tensor(float)", + "tensor(double)" + ] + } + ], + "examples": [ + { + "summary": "ceil", + "code": "node = onnx.helper.make_node(\n 'Ceil',\n inputs=['x'],\n outputs=['y'],\n)\n\nx = np.array([-1.5, 1.2]).astype(np.float32)\ny = np.ceil(x) # expected output [-1., 2.]\nexpect(node, inputs=[x], outputs=[y],\n name='test_ceil_example')\n\nx = np.random.randn(3, 4, 5).astype(np.float32)\ny = np.ceil(x)\nexpect(node, inputs=[x], outputs=[y],\n name='test_ceil')" + } + ] + }, + { + "name": "Ceil", + "module": "ai.onnx", + "version": 13, + "support_level": "common", + "description": "Ceil takes one input data (Tensor) and produces one output data\n(Tensor) where the ceil is, y = ceil(x), is applied to\nthe tensor elementwise.\n", + "inputs": [ + { + "name": "X", + "type": "T", + "description": "Input tensor" + } + ], + "min_input": 1, + "max_input": 1, + "outputs": [ + { + "name": "Y", + "type": "T", + "description": "Output tensor" + } + ], + "min_output": 1, + "max_output": 1, + "type_constraints": [ + { + "description": "Constrain input and output types to float tensors.", + "type_param_str": "T", + "allowed_type_strs": [ + "tensor(float16)", + "tensor(float)", + "tensor(double)", + "tensor(bfloat16)" + ] + } + ], + "examples": [ + { + "summary": "ceil", + "code": "node = onnx.helper.make_node(\n 'Ceil',\n inputs=['x'],\n outputs=['y'],\n)\n\nx = np.array([-1.5, 1.2]).astype(np.float32)\ny = np.ceil(x) # expected output [-1., 2.]\nexpect(node, inputs=[x], outputs=[y],\n name='test_ceil_example')\n\nx = np.random.randn(3, 4, 5).astype(np.float32)\ny = np.ceil(x)\nexpect(node, inputs=[x], outputs=[y],\n name='test_ceil')" + } + ] + }, + { + "name": "Celu", + "module": "ai.onnx", + "version": 12, + "support_level": "common", + "description": "Continuously Differentiable Exponential Linear Units:\nPerform the linear unit element-wise on the input tensor X\nusing formula:\n\n```\nmax(0,x) + min(0,alpha*(exp(x/alpha)-1))\n```\n", + "attributes": [ + { + "name": "alpha", + "type": "float32", + "required": false, + "default": 1.0, + "description": "The Alpha value in Celu formula which control the shape of the unit. The default value is 1.0." + } + ], + "inputs": [ + { + "name": "X", + "type": "T", + "description": "Input tensor" + } + ], + "min_input": 1, + "max_input": 1, + "outputs": [ + { + "name": "Y", + "type": "T", + "description": "Output tensor" + } + ], + "min_output": 1, + "max_output": 1, + "type_constraints": [ + { + "description": "Constrain input and output types to float32 tensors.", + "type_param_str": "T", + "allowed_type_strs": [ + "tensor(float)" + ] + } + ], + "examples": [ + { + "summary": "celu", + "code": "alpha = 2.0\nnode = onnx.helper.make_node(\n 'Celu',\n inputs=['X'],\n outputs=['Y'],\n alpha=alpha,\n)\n\ninput_data = np.array([[[[0.8439683], [0.5665144], [0.05836735]],\n [[0.02916367], [0.12964272], [0.5060197]],\n [[0.79538304], [0.9411346], [0.9546573]]],\n [[[0.17730942], [0.46192095], [0.26480448]],\n [[0.6746842], [0.01665257], [0.62473077]],\n [[0.9240844], [0.9722341], [0.11965699]]],\n [[[0.41356155], [0.9129373], [0.59330076]],\n [[0.81929934], [0.7862604], [0.11799799]],\n [[0.69248444], [0.54119414], [0.07513223]]]], dtype=np.float32)\n\n# Calculate expected output data\npositive_input = np.maximum(0, input_data)\nnegative_input = np.minimum(0, alpha * (np.exp(input_data / alpha) - 1))\nexpected_output = positive_input + negative_input\n\nexpect(node, inputs=[input_data], outputs=[expected_output],\n name='test_celu')" + } + ] + }, + { + "name": "Clip", + "module": "ai.onnx", + "version": 1, + "support_level": "common", + "description": "Clip operator limits the given input within an interval. The interval is\nspecified with arguments 'min' and 'max'. They default to\nnumeric_limits::lowest() and numeric_limits::max() respectively.\n", + "attributes": [ + { + "name": "consumed_inputs", + "type": "int64[]", + "required": false, + "description": "legacy optimization attribute." + }, + { + "name": "max", + "type": "float32", + "required": false, + "description": "Maximum value, above which element is replaced by max" + }, + { + "name": "min", + "type": "float32", + "required": false, + "description": "Minimum value, under which element is replaced by min" + } + ], + "inputs": [ + { + "name": "input", + "type": "T", + "description": "Input tensor whose elements to be clipped" + } + ], + "min_input": 1, + "max_input": 1, + "outputs": [ + { + "name": "output", + "type": "T", + "description": "Output tensor with clipped input elements" + } + ], + "min_output": 1, + "max_output": 1, + "type_constraints": [ + { + "description": "Constrain input and output types to float tensors.", + "type_param_str": "T", + "allowed_type_strs": [ + "tensor(float16)", + "tensor(float)", + "tensor(double)" + ] + } + ], + "examples": [ + { + "summary": "clip", + "code": "node = onnx.helper.make_node(\n 'Clip',\n inputs=['x', 'min', 'max'],\n outputs=['y'],\n)\n\nx = np.array([-2, 0, 2]).astype(np.float32)\nmin_val = np.float32(-1)\nmax_val = np.float32(1)\ny = np.clip(x, min_val, max_val) # expected output [-1., 0., 1.]\nexpect(node, inputs=[x, min_val, max_val], outputs=[y],\n name='test_clip_example')\n\nx = np.random.randn(3, 4, 5).astype(np.float32)\ny = np.clip(x, min_val, max_val)\nexpect(node, inputs=[x, min_val, max_val], outputs=[y],\n name='test_clip')\nnode = onnx.helper.make_node(\n 'Clip',\n inputs=['x', 'min', 'max'],\n outputs=['y'],\n)\n\nmin_val = np.float32(-5)\nmax_val = np.float32(5)\n\nx = np.array([-1, 0, 1]).astype(np.float32)\ny = np.array([-1, 0, 1]).astype(np.float32)\nexpect(node, inputs=[x, min_val, max_val], outputs=[y],\n name='test_clip_inbounds')\n\nx = np.array([-6, 0, 6]).astype(np.float32)\ny = np.array([-5, 0, 5]).astype(np.float32)\nexpect(node, inputs=[x, min_val, max_val], outputs=[y],\n name='test_clip_outbounds')\n\nx = np.array([-1, 0, 6]).astype(np.float32)\ny = np.array([-1, 0, 5]).astype(np.float32)\nexpect(node, inputs=[x, min_val, max_val], outputs=[y],\n name='test_clip_splitbounds')" + }, + { + "summary": "clip_default", + "code": "node = onnx.helper.make_node(\n 'Clip',\n inputs=['x', 'min'],\n outputs=['y'],\n)\nmin_val = np.float32(0)\nx = np.random.randn(3, 4, 5).astype(np.float32)\ny = np.clip(x, min_val, np.inf)\nexpect(node, inputs=[x, min_val], outputs=[y],\n name='test_clip_default_min')\n\nno_min = \"\" # optional input, not supplied\nnode = onnx.helper.make_node(\n 'Clip',\n inputs=['x', no_min, 'max'],\n outputs=['y'],\n)\nmax_val = np.float32(0)\nx = np.random.randn(3, 4, 5).astype(np.float32)\ny = np.clip(x, -np.inf, max_val)\nexpect(node, inputs=[x, max_val], outputs=[y],\n name='test_clip_default_max')\n\nno_max = \"\" # optional input, not supplied\nnode = onnx.helper.make_node(\n 'Clip',\n inputs=['x', no_min, no_max],\n outputs=['y'],\n)\n\nx = np.array([-1, 0, 1]).astype(np.float32)\ny = np.array([-1, 0, 1]).astype(np.float32)\nexpect(node, inputs=[x], outputs=[y],\n name='test_clip_default_inbounds')" + }, + { + "summary": "clip_default_int8", + "code": "node = onnx.helper.make_node(\n 'Clip',\n inputs=['x', 'min'],\n outputs=['y'],\n)\nmin_val = np.int8(0)\nx = np.random.randn(3, 4, 5).astype(np.int8)\ny = np.clip(x, min_val, np.iinfo(np.int8).max)\nexpect(node, inputs=[x, min_val], outputs=[y],\n name='test_clip_default_int8_min')\n\nno_min = \"\" # optional input, not supplied\nnode = onnx.helper.make_node(\n 'Clip',\n inputs=['x', no_min, 'max'],\n outputs=['y'],\n)\nmax_val = np.int8(0)\nx = np.random.randn(3, 4, 5).astype(np.int8)\ny = np.clip(x, np.iinfo(np.int8).min, max_val)\nexpect(node, inputs=[x, max_val], outputs=[y],\n name='test_clip_default_int8_max')\n\nno_max = \"\" # optional input, not supplied\nnode = onnx.helper.make_node(\n 'Clip',\n inputs=['x', no_min, no_max],\n outputs=['y'],\n)\n\nx = np.array([-1, 0, 1]).astype(np.int8)\ny = np.array([-1, 0, 1]).astype(np.int8)\nexpect(node, inputs=[x], outputs=[y],\n name='test_clip_default_int8_inbounds')" + } + ] + }, + { + "name": "Clip", + "module": "ai.onnx", + "version": 6, + "support_level": "common", + "description": "Clip operator limits the given input within an interval. The interval is\nspecified with arguments 'min' and 'max'. They default to\nnumeric_limits::lowest() and numeric_limits::max() respectively.\n", + "attributes": [ + { + "name": "max", + "type": "float32", + "required": false, + "default": 3.4028234663852886e+38, + "description": "Maximum value, above which element is replaced by max" + }, + { + "name": "min", + "type": "float32", + "required": false, + "default": -3.4028234663852886e+38, + "description": "Minimum value, under which element is replaced by min" + } + ], + "inputs": [ + { + "name": "input", + "type": "T", + "description": "Input tensor whose elements to be clipped" + } + ], + "min_input": 1, + "max_input": 1, + "outputs": [ + { + "name": "output", + "type": "T", + "description": "Output tensor with clipped input elements" + } + ], + "min_output": 1, + "max_output": 1, + "type_constraints": [ + { + "description": "Constrain input and output types to float tensors.", + "type_param_str": "T", + "allowed_type_strs": [ + "tensor(float16)", + "tensor(float)", + "tensor(double)" + ] + } + ], + "examples": [ + { + "summary": "clip", + "code": "node = onnx.helper.make_node(\n 'Clip',\n inputs=['x', 'min', 'max'],\n outputs=['y'],\n)\n\nx = np.array([-2, 0, 2]).astype(np.float32)\nmin_val = np.float32(-1)\nmax_val = np.float32(1)\ny = np.clip(x, min_val, max_val) # expected output [-1., 0., 1.]\nexpect(node, inputs=[x, min_val, max_val], outputs=[y],\n name='test_clip_example')\n\nx = np.random.randn(3, 4, 5).astype(np.float32)\ny = np.clip(x, min_val, max_val)\nexpect(node, inputs=[x, min_val, max_val], outputs=[y],\n name='test_clip')\nnode = onnx.helper.make_node(\n 'Clip',\n inputs=['x', 'min', 'max'],\n outputs=['y'],\n)\n\nmin_val = np.float32(-5)\nmax_val = np.float32(5)\n\nx = np.array([-1, 0, 1]).astype(np.float32)\ny = np.array([-1, 0, 1]).astype(np.float32)\nexpect(node, inputs=[x, min_val, max_val], outputs=[y],\n name='test_clip_inbounds')\n\nx = np.array([-6, 0, 6]).astype(np.float32)\ny = np.array([-5, 0, 5]).astype(np.float32)\nexpect(node, inputs=[x, min_val, max_val], outputs=[y],\n name='test_clip_outbounds')\n\nx = np.array([-1, 0, 6]).astype(np.float32)\ny = np.array([-1, 0, 5]).astype(np.float32)\nexpect(node, inputs=[x, min_val, max_val], outputs=[y],\n name='test_clip_splitbounds')" + }, + { + "summary": "clip_default", + "code": "node = onnx.helper.make_node(\n 'Clip',\n inputs=['x', 'min'],\n outputs=['y'],\n)\nmin_val = np.float32(0)\nx = np.random.randn(3, 4, 5).astype(np.float32)\ny = np.clip(x, min_val, np.inf)\nexpect(node, inputs=[x, min_val], outputs=[y],\n name='test_clip_default_min')\n\nno_min = \"\" # optional input, not supplied\nnode = onnx.helper.make_node(\n 'Clip',\n inputs=['x', no_min, 'max'],\n outputs=['y'],\n)\nmax_val = np.float32(0)\nx = np.random.randn(3, 4, 5).astype(np.float32)\ny = np.clip(x, -np.inf, max_val)\nexpect(node, inputs=[x, max_val], outputs=[y],\n name='test_clip_default_max')\n\nno_max = \"\" # optional input, not supplied\nnode = onnx.helper.make_node(\n 'Clip',\n inputs=['x', no_min, no_max],\n outputs=['y'],\n)\n\nx = np.array([-1, 0, 1]).astype(np.float32)\ny = np.array([-1, 0, 1]).astype(np.float32)\nexpect(node, inputs=[x], outputs=[y],\n name='test_clip_default_inbounds')" + }, + { + "summary": "clip_default_int8", + "code": "node = onnx.helper.make_node(\n 'Clip',\n inputs=['x', 'min'],\n outputs=['y'],\n)\nmin_val = np.int8(0)\nx = np.random.randn(3, 4, 5).astype(np.int8)\ny = np.clip(x, min_val, np.iinfo(np.int8).max)\nexpect(node, inputs=[x, min_val], outputs=[y],\n name='test_clip_default_int8_min')\n\nno_min = \"\" # optional input, not supplied\nnode = onnx.helper.make_node(\n 'Clip',\n inputs=['x', no_min, 'max'],\n outputs=['y'],\n)\nmax_val = np.int8(0)\nx = np.random.randn(3, 4, 5).astype(np.int8)\ny = np.clip(x, np.iinfo(np.int8).min, max_val)\nexpect(node, inputs=[x, max_val], outputs=[y],\n name='test_clip_default_int8_max')\n\nno_max = \"\" # optional input, not supplied\nnode = onnx.helper.make_node(\n 'Clip',\n inputs=['x', no_min, no_max],\n outputs=['y'],\n)\n\nx = np.array([-1, 0, 1]).astype(np.int8)\ny = np.array([-1, 0, 1]).astype(np.int8)\nexpect(node, inputs=[x], outputs=[y],\n name='test_clip_default_int8_inbounds')" + } + ] + }, + { + "name": "Clip", + "module": "ai.onnx", + "version": 11, + "support_level": "common", + "description": "Clip operator limits the given input within an interval. The interval is\nspecified by the inputs 'min' and 'max'. They default to\nnumeric_limits::lowest() and numeric_limits::max(), respectively.\n", + "inputs": [ + { + "name": "input", + "type": "T", + "description": "Input tensor whose elements to be clipped" + }, + { + "name": "min", + "type": "T", + "option": "optional", + "description": "Minimum value, under which element is replaced by min. It must be a scalar(tensor of empty shape)." + }, + { + "name": "max", + "type": "T", + "option": "optional", + "description": "Maximum value, above which element is replaced by max. It must be a scalar(tensor of empty shape)." + } + ], + "min_input": 1, + "max_input": 3, + "outputs": [ + { + "name": "output", + "type": "T", + "description": "Output tensor with clipped input elements" + } + ], + "min_output": 1, + "max_output": 1, + "inputs_range": "1 - 3", + "type_constraints": [ + { + "description": "Constrain input and output types to float tensors.", + "type_param_str": "T", + "allowed_type_strs": [ + "tensor(float16)", + "tensor(float)", + "tensor(double)" + ] + } + ], + "examples": [ + { + "summary": "clip", + "code": "node = onnx.helper.make_node(\n 'Clip',\n inputs=['x', 'min', 'max'],\n outputs=['y'],\n)\n\nx = np.array([-2, 0, 2]).astype(np.float32)\nmin_val = np.float32(-1)\nmax_val = np.float32(1)\ny = np.clip(x, min_val, max_val) # expected output [-1., 0., 1.]\nexpect(node, inputs=[x, min_val, max_val], outputs=[y],\n name='test_clip_example')\n\nx = np.random.randn(3, 4, 5).astype(np.float32)\ny = np.clip(x, min_val, max_val)\nexpect(node, inputs=[x, min_val, max_val], outputs=[y],\n name='test_clip')\nnode = onnx.helper.make_node(\n 'Clip',\n inputs=['x', 'min', 'max'],\n outputs=['y'],\n)\n\nmin_val = np.float32(-5)\nmax_val = np.float32(5)\n\nx = np.array([-1, 0, 1]).astype(np.float32)\ny = np.array([-1, 0, 1]).astype(np.float32)\nexpect(node, inputs=[x, min_val, max_val], outputs=[y],\n name='test_clip_inbounds')\n\nx = np.array([-6, 0, 6]).astype(np.float32)\ny = np.array([-5, 0, 5]).astype(np.float32)\nexpect(node, inputs=[x, min_val, max_val], outputs=[y],\n name='test_clip_outbounds')\n\nx = np.array([-1, 0, 6]).astype(np.float32)\ny = np.array([-1, 0, 5]).astype(np.float32)\nexpect(node, inputs=[x, min_val, max_val], outputs=[y],\n name='test_clip_splitbounds')" + }, + { + "summary": "clip_default", + "code": "node = onnx.helper.make_node(\n 'Clip',\n inputs=['x', 'min'],\n outputs=['y'],\n)\nmin_val = np.float32(0)\nx = np.random.randn(3, 4, 5).astype(np.float32)\ny = np.clip(x, min_val, np.inf)\nexpect(node, inputs=[x, min_val], outputs=[y],\n name='test_clip_default_min')\n\nno_min = \"\" # optional input, not supplied\nnode = onnx.helper.make_node(\n 'Clip',\n inputs=['x', no_min, 'max'],\n outputs=['y'],\n)\nmax_val = np.float32(0)\nx = np.random.randn(3, 4, 5).astype(np.float32)\ny = np.clip(x, -np.inf, max_val)\nexpect(node, inputs=[x, max_val], outputs=[y],\n name='test_clip_default_max')\n\nno_max = \"\" # optional input, not supplied\nnode = onnx.helper.make_node(\n 'Clip',\n inputs=['x', no_min, no_max],\n outputs=['y'],\n)\n\nx = np.array([-1, 0, 1]).astype(np.float32)\ny = np.array([-1, 0, 1]).astype(np.float32)\nexpect(node, inputs=[x], outputs=[y],\n name='test_clip_default_inbounds')" + }, + { + "summary": "clip_default_int8", + "code": "node = onnx.helper.make_node(\n 'Clip',\n inputs=['x', 'min'],\n outputs=['y'],\n)\nmin_val = np.int8(0)\nx = np.random.randn(3, 4, 5).astype(np.int8)\ny = np.clip(x, min_val, np.iinfo(np.int8).max)\nexpect(node, inputs=[x, min_val], outputs=[y],\n name='test_clip_default_int8_min')\n\nno_min = \"\" # optional input, not supplied\nnode = onnx.helper.make_node(\n 'Clip',\n inputs=['x', no_min, 'max'],\n outputs=['y'],\n)\nmax_val = np.int8(0)\nx = np.random.randn(3, 4, 5).astype(np.int8)\ny = np.clip(x, np.iinfo(np.int8).min, max_val)\nexpect(node, inputs=[x, max_val], outputs=[y],\n name='test_clip_default_int8_max')\n\nno_max = \"\" # optional input, not supplied\nnode = onnx.helper.make_node(\n 'Clip',\n inputs=['x', no_min, no_max],\n outputs=['y'],\n)\n\nx = np.array([-1, 0, 1]).astype(np.int8)\ny = np.array([-1, 0, 1]).astype(np.int8)\nexpect(node, inputs=[x], outputs=[y],\n name='test_clip_default_int8_inbounds')" + } + ] + }, + { + "name": "Clip", + "module": "ai.onnx", + "version": 12, + "support_level": "common", + "description": "Clip operator limits the given input within an interval. The interval is\nspecified by the inputs 'min' and 'max'. They default to\nnumeric_limits::lowest() and numeric_limits::max(), respectively.\n", + "inputs": [ + { + "name": "input", + "type": "T", + "description": "Input tensor whose elements to be clipped" + }, + { + "name": "min", + "type": "T", + "option": "optional", + "description": "Minimum value, under which element is replaced by min. It must be a scalar(tensor of empty shape)." + }, + { + "name": "max", + "type": "T", + "option": "optional", + "description": "Maximum value, above which element is replaced by max. It must be a scalar(tensor of empty shape)." + } + ], + "min_input": 1, + "max_input": 3, + "outputs": [ + { + "name": "output", + "type": "T", + "description": "Output tensor with clipped input elements" + } + ], + "min_output": 1, + "max_output": 1, + "inputs_range": "1 - 3", + "type_constraints": [ + { + "description": "Constrain input and output types to all numeric tensors.", + "type_param_str": "T", + "allowed_type_strs": [ + "tensor(uint8)", + "tensor(uint16)", + "tensor(uint32)", + "tensor(uint64)", + "tensor(int8)", + "tensor(int16)", + "tensor(int32)", + "tensor(int64)", + "tensor(float16)", + "tensor(float)", + "tensor(double)" + ] + } + ], + "examples": [ + { + "summary": "clip", + "code": "node = onnx.helper.make_node(\n 'Clip',\n inputs=['x', 'min', 'max'],\n outputs=['y'],\n)\n\nx = np.array([-2, 0, 2]).astype(np.float32)\nmin_val = np.float32(-1)\nmax_val = np.float32(1)\ny = np.clip(x, min_val, max_val) # expected output [-1., 0., 1.]\nexpect(node, inputs=[x, min_val, max_val], outputs=[y],\n name='test_clip_example')\n\nx = np.random.randn(3, 4, 5).astype(np.float32)\ny = np.clip(x, min_val, max_val)\nexpect(node, inputs=[x, min_val, max_val], outputs=[y],\n name='test_clip')\nnode = onnx.helper.make_node(\n 'Clip',\n inputs=['x', 'min', 'max'],\n outputs=['y'],\n)\n\nmin_val = np.float32(-5)\nmax_val = np.float32(5)\n\nx = np.array([-1, 0, 1]).astype(np.float32)\ny = np.array([-1, 0, 1]).astype(np.float32)\nexpect(node, inputs=[x, min_val, max_val], outputs=[y],\n name='test_clip_inbounds')\n\nx = np.array([-6, 0, 6]).astype(np.float32)\ny = np.array([-5, 0, 5]).astype(np.float32)\nexpect(node, inputs=[x, min_val, max_val], outputs=[y],\n name='test_clip_outbounds')\n\nx = np.array([-1, 0, 6]).astype(np.float32)\ny = np.array([-1, 0, 5]).astype(np.float32)\nexpect(node, inputs=[x, min_val, max_val], outputs=[y],\n name='test_clip_splitbounds')" + }, + { + "summary": "clip_default", + "code": "node = onnx.helper.make_node(\n 'Clip',\n inputs=['x', 'min'],\n outputs=['y'],\n)\nmin_val = np.float32(0)\nx = np.random.randn(3, 4, 5).astype(np.float32)\ny = np.clip(x, min_val, np.inf)\nexpect(node, inputs=[x, min_val], outputs=[y],\n name='test_clip_default_min')\n\nno_min = \"\" # optional input, not supplied\nnode = onnx.helper.make_node(\n 'Clip',\n inputs=['x', no_min, 'max'],\n outputs=['y'],\n)\nmax_val = np.float32(0)\nx = np.random.randn(3, 4, 5).astype(np.float32)\ny = np.clip(x, -np.inf, max_val)\nexpect(node, inputs=[x, max_val], outputs=[y],\n name='test_clip_default_max')\n\nno_max = \"\" # optional input, not supplied\nnode = onnx.helper.make_node(\n 'Clip',\n inputs=['x', no_min, no_max],\n outputs=['y'],\n)\n\nx = np.array([-1, 0, 1]).astype(np.float32)\ny = np.array([-1, 0, 1]).astype(np.float32)\nexpect(node, inputs=[x], outputs=[y],\n name='test_clip_default_inbounds')" + }, + { + "summary": "clip_default_int8", + "code": "node = onnx.helper.make_node(\n 'Clip',\n inputs=['x', 'min'],\n outputs=['y'],\n)\nmin_val = np.int8(0)\nx = np.random.randn(3, 4, 5).astype(np.int8)\ny = np.clip(x, min_val, np.iinfo(np.int8).max)\nexpect(node, inputs=[x, min_val], outputs=[y],\n name='test_clip_default_int8_min')\n\nno_min = \"\" # optional input, not supplied\nnode = onnx.helper.make_node(\n 'Clip',\n inputs=['x', no_min, 'max'],\n outputs=['y'],\n)\nmax_val = np.int8(0)\nx = np.random.randn(3, 4, 5).astype(np.int8)\ny = np.clip(x, np.iinfo(np.int8).min, max_val)\nexpect(node, inputs=[x, max_val], outputs=[y],\n name='test_clip_default_int8_max')\n\nno_max = \"\" # optional input, not supplied\nnode = onnx.helper.make_node(\n 'Clip',\n inputs=['x', no_min, no_max],\n outputs=['y'],\n)\n\nx = np.array([-1, 0, 1]).astype(np.int8)\ny = np.array([-1, 0, 1]).astype(np.int8)\nexpect(node, inputs=[x], outputs=[y],\n name='test_clip_default_int8_inbounds')" + } + ] + }, + { + "name": "Clip", + "module": "ai.onnx", + "version": 13, + "support_level": "common", + "description": "Clip operator limits the given input within an interval. The interval is\nspecified by the inputs 'min' and 'max'. They default to\nnumeric_limits::lowest() and numeric_limits::max(), respectively.\n", + "inputs": [ + { + "name": "input", + "type": "T", + "description": "Input tensor whose elements to be clipped" + }, + { + "name": "min", + "type": "T", + "option": "optional", + "description": "Minimum value, under which element is replaced by min. It must be a scalar(tensor of empty shape)." + }, + { + "name": "max", + "type": "T", + "option": "optional", + "description": "Maximum value, above which element is replaced by max. It must be a scalar(tensor of empty shape)." + } + ], + "min_input": 1, + "max_input": 3, + "outputs": [ + { + "name": "output", + "type": "T", + "description": "Output tensor with clipped input elements" + } + ], + "min_output": 1, + "max_output": 1, + "inputs_range": "1 - 3", + "type_constraints": [ + { + "description": "Constrain input and output types to all numeric tensors.", + "type_param_str": "T", + "allowed_type_strs": [ + "tensor(uint8)", + "tensor(uint16)", + "tensor(uint32)", + "tensor(uint64)", + "tensor(int8)", + "tensor(int16)", + "tensor(int32)", + "tensor(int64)", + "tensor(float16)", + "tensor(float)", + "tensor(double)", + "tensor(bfloat16)" + ] + } + ], + "examples": [ + { + "summary": "clip", + "code": "node = onnx.helper.make_node(\n 'Clip',\n inputs=['x', 'min', 'max'],\n outputs=['y'],\n)\n\nx = np.array([-2, 0, 2]).astype(np.float32)\nmin_val = np.float32(-1)\nmax_val = np.float32(1)\ny = np.clip(x, min_val, max_val) # expected output [-1., 0., 1.]\nexpect(node, inputs=[x, min_val, max_val], outputs=[y],\n name='test_clip_example')\n\nx = np.random.randn(3, 4, 5).astype(np.float32)\ny = np.clip(x, min_val, max_val)\nexpect(node, inputs=[x, min_val, max_val], outputs=[y],\n name='test_clip')\nnode = onnx.helper.make_node(\n 'Clip',\n inputs=['x', 'min', 'max'],\n outputs=['y'],\n)\n\nmin_val = np.float32(-5)\nmax_val = np.float32(5)\n\nx = np.array([-1, 0, 1]).astype(np.float32)\ny = np.array([-1, 0, 1]).astype(np.float32)\nexpect(node, inputs=[x, min_val, max_val], outputs=[y],\n name='test_clip_inbounds')\n\nx = np.array([-6, 0, 6]).astype(np.float32)\ny = np.array([-5, 0, 5]).astype(np.float32)\nexpect(node, inputs=[x, min_val, max_val], outputs=[y],\n name='test_clip_outbounds')\n\nx = np.array([-1, 0, 6]).astype(np.float32)\ny = np.array([-1, 0, 5]).astype(np.float32)\nexpect(node, inputs=[x, min_val, max_val], outputs=[y],\n name='test_clip_splitbounds')" + }, + { + "summary": "clip_default", + "code": "node = onnx.helper.make_node(\n 'Clip',\n inputs=['x', 'min'],\n outputs=['y'],\n)\nmin_val = np.float32(0)\nx = np.random.randn(3, 4, 5).astype(np.float32)\ny = np.clip(x, min_val, np.inf)\nexpect(node, inputs=[x, min_val], outputs=[y],\n name='test_clip_default_min')\n\nno_min = \"\" # optional input, not supplied\nnode = onnx.helper.make_node(\n 'Clip',\n inputs=['x', no_min, 'max'],\n outputs=['y'],\n)\nmax_val = np.float32(0)\nx = np.random.randn(3, 4, 5).astype(np.float32)\ny = np.clip(x, -np.inf, max_val)\nexpect(node, inputs=[x, max_val], outputs=[y],\n name='test_clip_default_max')\n\nno_max = \"\" # optional input, not supplied\nnode = onnx.helper.make_node(\n 'Clip',\n inputs=['x', no_min, no_max],\n outputs=['y'],\n)\n\nx = np.array([-1, 0, 1]).astype(np.float32)\ny = np.array([-1, 0, 1]).astype(np.float32)\nexpect(node, inputs=[x], outputs=[y],\n name='test_clip_default_inbounds')" + }, + { + "summary": "clip_default_int8", + "code": "node = onnx.helper.make_node(\n 'Clip',\n inputs=['x', 'min'],\n outputs=['y'],\n)\nmin_val = np.int8(0)\nx = np.random.randn(3, 4, 5).astype(np.int8)\ny = np.clip(x, min_val, np.iinfo(np.int8).max)\nexpect(node, inputs=[x, min_val], outputs=[y],\n name='test_clip_default_int8_min')\n\nno_min = \"\" # optional input, not supplied\nnode = onnx.helper.make_node(\n 'Clip',\n inputs=['x', no_min, 'max'],\n outputs=['y'],\n)\nmax_val = np.int8(0)\nx = np.random.randn(3, 4, 5).astype(np.int8)\ny = np.clip(x, np.iinfo(np.int8).min, max_val)\nexpect(node, inputs=[x, max_val], outputs=[y],\n name='test_clip_default_int8_max')\n\nno_max = \"\" # optional input, not supplied\nnode = onnx.helper.make_node(\n 'Clip',\n inputs=['x', no_min, no_max],\n outputs=['y'],\n)\n\nx = np.array([-1, 0, 1]).astype(np.int8)\ny = np.array([-1, 0, 1]).astype(np.int8)\nexpect(node, inputs=[x], outputs=[y],\n name='test_clip_default_int8_inbounds')" + } + ] + }, + { + "name": "Compress", + "module": "ai.onnx", + "version": 9, + "support_level": "common", + "description": "Selects slices from an input tensor along a given axis where condition evaluates to True for each axis index.\n In case axis is not provided, input is flattened before elements are selected.\n Compress behaves like numpy.compress: https://docs.scipy.org/doc/numpy/reference/generated/numpy.compress.html\n ", + "attributes": [ + { + "name": "axis", + "type": "int64", + "required": false, + "description": "(Optional) Axis along which to take slices. If not specified, input is flattened before elements being selected." + } + ], + "inputs": [ + { + "name": "input", + "type": "T", + "description": "Tensor of rank r >= 1." + }, + { + "name": "condition", + "type": "T1", + "description": "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." + } + ], + "min_input": 2, + "max_input": 2, + "outputs": [ + { + "name": "output", + "type": "T", + "description": "Tensor of rank r if axis is specified. Otherwise output is a Tensor of rank 1." + } + ], + "min_output": 1, + "max_output": 1, + "type_constraints": [ + { + "description": "Constrain input and output types to all tensor types.", + "type_param_str": "T", + "allowed_type_strs": [ + "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)" + ] + }, + { + "description": "Constrains to boolean tensors.", + "type_param_str": "T1", + "allowed_type_strs": [ + "tensor(bool)" + ] + } + ], + "examples": [ + { + "summary": "compress_0", + "code": "node = onnx.helper.make_node(\n 'Compress',\n inputs=['input', 'condition'],\n outputs=['output'],\n axis=0,\n)\ninput = np.array([[1, 2], [3, 4], [5, 6]]).astype(np.float32)\ncondition = np.array([0, 1, 1])\noutput = np.compress(condition, input, axis=0)\n#print(output)\n#[[ 3. 4.]\n# [ 5. 6.]]\n\nexpect(node, inputs=[input, condition.astype(bool)], outputs=[output],\n name='test_compress_0')" + }, + { + "summary": "compress_1", + "code": "node = onnx.helper.make_node(\n 'Compress',\n inputs=['input', 'condition'],\n outputs=['output'],\n axis=1,\n)\ninput = np.array([[1, 2], [3, 4], [5, 6]]).astype(np.float32)\ncondition = np.array([0, 1])\noutput = np.compress(condition, input, axis=1)\n#print(output)\n#[[ 2.]\n# [ 4.]\n# [ 6.]]\n\nexpect(node, inputs=[input, condition.astype(bool)], outputs=[output],\n name='test_compress_1')" + }, + { + "summary": "compress_default_axis", + "code": "node = onnx.helper.make_node(\n 'Compress',\n inputs=['input', 'condition'],\n outputs=['output'],\n)\ninput = np.array([[1, 2], [3, 4], [5, 6]]).astype(np.float32)\ncondition = np.array([0, 1, 0, 0, 1])\noutput = np.compress(condition, input)\n#print(output)\n#[ 2., 5.]\n\nexpect(node, inputs=[input, condition.astype(bool)], outputs=[output],\n name='test_compress_default_axis')" + }, + { + "summary": "compress_negative_axis", + "code": "node = onnx.helper.make_node(\n 'Compress',\n inputs=['input', 'condition'],\n outputs=['output'],\n axis=-1,\n)\ninput = np.array([[1, 2], [3, 4], [5, 6]]).astype(np.float32)\ncondition = np.array([0, 1])\noutput = np.compress(condition, input, axis=-1)\n# print(output)\n#[[ 2.]\n# [ 4.]\n# [ 6.]]\nexpect(node, inputs=[input, condition.astype(bool)], outputs=[output],\n name='test_compress_negative_axis')" + } + ] + }, + { + "name": "Compress", + "module": "ai.onnx", + "version": 11, + "support_level": "common", + "description": "Selects slices from an input tensor along a given axis where condition evaluates to True for each axis index.\n In case axis is not provided, input is flattened before elements are selected.\n Compress behaves like numpy.compress: https://docs.scipy.org/doc/numpy/reference/generated/numpy.compress.html\n ", + "attributes": [ + { + "name": "axis", + "type": "int64", + "required": false, + "description": "(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": [ + { + "name": "input", + "type": "T", + "description": "Tensor of rank r >= 1." + }, + { + "name": "condition", + "type": "T1", + "description": "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." + } + ], + "min_input": 2, + "max_input": 2, + "outputs": [ + { + "name": "output", + "type": "T", + "description": "Tensor of rank r if axis is specified. Otherwise output is a Tensor of rank 1." + } + ], + "min_output": 1, + "max_output": 1, + "type_constraints": [ + { + "description": "Constrain input and output types to all tensor types.", + "type_param_str": "T", + "allowed_type_strs": [ + "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)" + ] + }, + { + "description": "Constrains to boolean tensors.", + "type_param_str": "T1", + "allowed_type_strs": [ + "tensor(bool)" + ] + } + ], + "examples": [ + { + "summary": "compress_0", + "code": "node = onnx.helper.make_node(\n 'Compress',\n inputs=['input', 'condition'],\n outputs=['output'],\n axis=0,\n)\ninput = np.array([[1, 2], [3, 4], [5, 6]]).astype(np.float32)\ncondition = np.array([0, 1, 1])\noutput = np.compress(condition, input, axis=0)\n#print(output)\n#[[ 3. 4.]\n# [ 5. 6.]]\n\nexpect(node, inputs=[input, condition.astype(bool)], outputs=[output],\n name='test_compress_0')" + }, + { + "summary": "compress_1", + "code": "node = onnx.helper.make_node(\n 'Compress',\n inputs=['input', 'condition'],\n outputs=['output'],\n axis=1,\n)\ninput = np.array([[1, 2], [3, 4], [5, 6]]).astype(np.float32)\ncondition = np.array([0, 1])\noutput = np.compress(condition, input, axis=1)\n#print(output)\n#[[ 2.]\n# [ 4.]\n# [ 6.]]\n\nexpect(node, inputs=[input, condition.astype(bool)], outputs=[output],\n name='test_compress_1')" + }, + { + "summary": "compress_default_axis", + "code": "node = onnx.helper.make_node(\n 'Compress',\n inputs=['input', 'condition'],\n outputs=['output'],\n)\ninput = np.array([[1, 2], [3, 4], [5, 6]]).astype(np.float32)\ncondition = np.array([0, 1, 0, 0, 1])\noutput = np.compress(condition, input)\n#print(output)\n#[ 2., 5.]\n\nexpect(node, inputs=[input, condition.astype(bool)], outputs=[output],\n name='test_compress_default_axis')" + }, + { + "summary": "compress_negative_axis", + "code": "node = onnx.helper.make_node(\n 'Compress',\n inputs=['input', 'condition'],\n outputs=['output'],\n axis=-1,\n)\ninput = np.array([[1, 2], [3, 4], [5, 6]]).astype(np.float32)\ncondition = np.array([0, 1])\noutput = np.compress(condition, input, axis=-1)\n# print(output)\n#[[ 2.]\n# [ 4.]\n# [ 6.]]\nexpect(node, inputs=[input, condition.astype(bool)], outputs=[output],\n name='test_compress_negative_axis')" + } + ] + }, + { + "name": "Concat", + "module": "ai.onnx", + "version": 1, + "support_level": "common", + "description": "Concatenate a list of tensors into a single tensor", + "attributes": [ + { + "name": "axis", + "type": "int64", + "required": false, + "description": "Which axis to concat on. Default value is 1." + } + ], + "inputs": [ + { + "name": "inputs", + "type": "T", + "list": true, + "description": "List of tensors for concatenation" + } + ], + "min_input": 1, + "max_input": 2147483647, + "outputs": [ + { + "name": "concat_result", + "type": "T", + "description": "Concatenated tensor" + } + ], + "min_output": 1, + "max_output": 1, + "inputs_range": "1 - ∞", + "type_constraints": [ + { + "description": "Constrain output types to float tensors.", + "type_param_str": "T", + "allowed_type_strs": [ + "tensor(float16)", + "tensor(float)", + "tensor(double)" + ] + } + ], + "examples": [ + { + "summary": "concat", + "code": "test_cases = {\n '1d': ([1, 2],\n [3, 4]),\n '2d': ([[1, 2], [3, 4]],\n [[5, 6], [7, 8]]),\n '3d': ([[[1, 2], [3, 4]], [[5, 6], [7, 8]]],\n [[[9, 10], [11, 12]], [[13, 14], [15, 16]]])\n} # type: Dict[Text, Sequence[Any]]\n\nfor test_case, values_ in test_cases.items():\n values = [np.asarray(v, dtype=np.float32) for v in values_]\n for i in range(len(values[0].shape)):\n in_args = ['value' + str(k) for k in range(len(values))]\n node = onnx.helper.make_node(\n 'Concat',\n inputs=[s for s in in_args],\n outputs=['output'],\n axis=i\n )\n output = np.concatenate(values, i)\n expect(node, inputs=[v for v in values], outputs=[output],\n name='test_concat_' + test_case + '_axis_' + str(i))\n\n for i in range(-len(values[0].shape), 0):\n in_args = ['value' + str(k) for k in range(len(values))]\n node = onnx.helper.make_node(\n 'Concat',\n inputs=[s for s in in_args],\n outputs=['output'],\n axis=i\n )\n output = np.concatenate(values, i)\n expect(node, inputs=[v for v in values], outputs=[output],\n name='test_concat_' + test_case + '_axis_negative_' + str(abs(i)))" + } + ], + "category": "Tensor" + }, + { + "name": "Concat", + "module": "ai.onnx", + "version": 4, + "support_level": "common", + "description": "Concatenate a list of tensors into a single tensor", + "attributes": [ + { + "name": "axis", + "type": "int64", + "required": true, + "description": "Which axis to concat on" + } + ], + "inputs": [ + { + "name": "inputs", + "type": "T", + "list": true, + "description": "List of tensors for concatenation" + } + ], + "min_input": 1, + "max_input": 2147483647, + "outputs": [ + { + "name": "concat_result", + "type": "T", + "description": "Concatenated tensor" + } + ], + "min_output": 1, + "max_output": 1, + "inputs_range": "1 - ∞", + "type_constraints": [ + { + "description": "Constrain output types to any tensor type.", + "type_param_str": "T", + "allowed_type_strs": [ + "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)" + ] + } + ], + "examples": [ + { + "summary": "concat", + "code": "test_cases = {\n '1d': ([1, 2],\n [3, 4]),\n '2d': ([[1, 2], [3, 4]],\n [[5, 6], [7, 8]]),\n '3d': ([[[1, 2], [3, 4]], [[5, 6], [7, 8]]],\n [[[9, 10], [11, 12]], [[13, 14], [15, 16]]])\n} # type: Dict[Text, Sequence[Any]]\n\nfor test_case, values_ in test_cases.items():\n values = [np.asarray(v, dtype=np.float32) for v in values_]\n for i in range(len(values[0].shape)):\n in_args = ['value' + str(k) for k in range(len(values))]\n node = onnx.helper.make_node(\n 'Concat',\n inputs=[s for s in in_args],\n outputs=['output'],\n axis=i\n )\n output = np.concatenate(values, i)\n expect(node, inputs=[v for v in values], outputs=[output],\n name='test_concat_' + test_case + '_axis_' + str(i))\n\n for i in range(-len(values[0].shape), 0):\n in_args = ['value' + str(k) for k in range(len(values))]\n node = onnx.helper.make_node(\n 'Concat',\n inputs=[s for s in in_args],\n outputs=['output'],\n axis=i\n )\n output = np.concatenate(values, i)\n expect(node, inputs=[v for v in values], outputs=[output],\n name='test_concat_' + test_case + '_axis_negative_' + str(abs(i)))" + } + ], + "category": "Tensor" + }, + { + "name": "Concat", + "module": "ai.onnx", + "version": 11, + "support_level": "common", + "description": "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.", + "attributes": [ + { + "name": "axis", + "type": "int64", + "required": true, + "description": "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": [ + { + "name": "inputs", + "type": "T", + "list": true, + "description": "List of tensors for concatenation" + } + ], + "min_input": 1, + "max_input": 2147483647, + "outputs": [ + { + "name": "concat_result", + "type": "T", + "description": "Concatenated tensor" + } + ], + "min_output": 1, + "max_output": 1, + "inputs_range": "1 - ∞", + "type_constraints": [ + { + "description": "Constrain output types to any tensor type.", + "type_param_str": "T", + "allowed_type_strs": [ + "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)" + ] + } + ], + "examples": [ + { + "summary": "concat", + "code": "test_cases = {\n '1d': ([1, 2],\n [3, 4]),\n '2d': ([[1, 2], [3, 4]],\n [[5, 6], [7, 8]]),\n '3d': ([[[1, 2], [3, 4]], [[5, 6], [7, 8]]],\n [[[9, 10], [11, 12]], [[13, 14], [15, 16]]])\n} # type: Dict[Text, Sequence[Any]]\n\nfor test_case, values_ in test_cases.items():\n values = [np.asarray(v, dtype=np.float32) for v in values_]\n for i in range(len(values[0].shape)):\n in_args = ['value' + str(k) for k in range(len(values))]\n node = onnx.helper.make_node(\n 'Concat',\n inputs=[s for s in in_args],\n outputs=['output'],\n axis=i\n )\n output = np.concatenate(values, i)\n expect(node, inputs=[v for v in values], outputs=[output],\n name='test_concat_' + test_case + '_axis_' + str(i))\n\n for i in range(-len(values[0].shape), 0):\n in_args = ['value' + str(k) for k in range(len(values))]\n node = onnx.helper.make_node(\n 'Concat',\n inputs=[s for s in in_args],\n outputs=['output'],\n axis=i\n )\n output = np.concatenate(values, i)\n expect(node, inputs=[v for v in values], outputs=[output],\n name='test_concat_' + test_case + '_axis_negative_' + str(abs(i)))" + } + ], + "category": "Tensor" + }, + { + "name": "Concat", + "module": "ai.onnx", + "version": 13, + "support_level": "common", + "description": "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.", + "attributes": [ + { + "name": "axis", + "type": "int64", + "required": true, + "description": "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": [ + { + "name": "inputs", + "type": "T", + "list": true, + "description": "List of tensors for concatenation" + } + ], + "min_input": 1, + "max_input": 2147483647, + "outputs": [ + { + "name": "concat_result", + "type": "T", + "description": "Concatenated tensor" + } + ], + "min_output": 1, + "max_output": 1, + "inputs_range": "1 - ∞", + "type_constraints": [ + { + "description": "Constrain output types to any tensor type.", + "type_param_str": "T", + "allowed_type_strs": [ + "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)" + ] + } + ], + "examples": [ + { + "summary": "concat", + "code": "test_cases = {\n '1d': ([1, 2],\n [3, 4]),\n '2d': ([[1, 2], [3, 4]],\n [[5, 6], [7, 8]]),\n '3d': ([[[1, 2], [3, 4]], [[5, 6], [7, 8]]],\n [[[9, 10], [11, 12]], [[13, 14], [15, 16]]])\n} # type: Dict[Text, Sequence[Any]]\n\nfor test_case, values_ in test_cases.items():\n values = [np.asarray(v, dtype=np.float32) for v in values_]\n for i in range(len(values[0].shape)):\n in_args = ['value' + str(k) for k in range(len(values))]\n node = onnx.helper.make_node(\n 'Concat',\n inputs=[s for s in in_args],\n outputs=['output'],\n axis=i\n )\n output = np.concatenate(values, i)\n expect(node, inputs=[v for v in values], outputs=[output],\n name='test_concat_' + test_case + '_axis_' + str(i))\n\n for i in range(-len(values[0].shape), 0):\n in_args = ['value' + str(k) for k in range(len(values))]\n node = onnx.helper.make_node(\n 'Concat',\n inputs=[s for s in in_args],\n outputs=['output'],\n axis=i\n )\n output = np.concatenate(values, i)\n expect(node, inputs=[v for v in values], outputs=[output],\n name='test_concat_' + test_case + '_axis_negative_' + str(abs(i)))" + } + ], + "category": "Tensor" + }, + { + "name": "ConcatFromSequence", + "module": "ai.onnx", + "version": 11, + "support_level": "common", + "description": "Concatenate a sequence of tensors into a single tensor.\nAll input tensors must have the same shape, except for the dimension size of the axis to concatenate on.\nBy default 'new_axis' is 0, the behavior is similar to numpy.concatenate.\nWhen 'new_axis' is 1, the behavior is similar to numpy.stack.\n", + "attributes": [ + { + "name": "axis", + "type": "int64", + "required": true, + "description": "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]`. " + }, + { + "name": "new_axis", + "type": "int64", + "required": false, + "description": "Insert and concatenate on a new axis or not, default 0 means do not insert new axis." + } + ], + "inputs": [ + { + "name": "input_sequence", + "type": "S", + "description": "Sequence of tensors for concatenation" + } + ], + "min_input": 1, + "max_input": 1, + "outputs": [ + { + "name": "concat_result", + "type": "T", + "description": "Concatenated tensor" + } + ], + "min_output": 1, + "max_output": 1, + "type_constraints": [ + { + "description": "Constrain input types to any tensor type.", + "type_param_str": "S", + "allowed_type_strs": [ + "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))" + ] + }, + { + "description": "Constrain output types to any tensor type.", + "type_param_str": "T", + "allowed_type_strs": [ + "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)" + ] + } + ] + }, + { + "name": "Constant", + "module": "ai.onnx", + "version": 1, + "support_level": "common", + "description": "A constant tensor.", + "attributes": [ + { + "name": "value", + "type": "tensor", + "required": true, + "description": "The value for the elements of the output tensor." + } + ], + "min_input": 0, + "max_input": 0, + "outputs": [ + { + "name": "output", + "type": "T", + "description": "Output tensor containing the same value of the provided tensor." + } + ], + "min_output": 1, + "max_output": 1, + "type_constraints": [ + { + "description": "Constrain input and output types to float tensors.", + "type_param_str": "T", + "allowed_type_strs": [ + "tensor(float16)", + "tensor(float)", + "tensor(double)" + ] + } + ], + "examples": [ + { + "summary": "constant", + "code": "values = np.random.randn(5, 5).astype(np.float32)\nnode = onnx.helper.make_node(\n 'Constant',\n inputs=[],\n outputs=['values'],\n value=onnx.helper.make_tensor(\n name='const_tensor',\n data_type=onnx.TensorProto.FLOAT,\n dims=values.shape,\n vals=values.flatten().astype(float),\n ),\n)\n\nexpect(node, inputs=[], outputs=[values],\n name='test_constant')" + } + ], + "category": "Constant" + }, + { + "name": "Constant", + "module": "ai.onnx", + "version": 9, + "support_level": "common", + "description": "A constant tensor.", + "attributes": [ + { + "name": "value", + "type": "tensor", + "required": true, + "description": "The value for the elements of the output tensor." + } + ], + "min_input": 0, + "max_input": 0, + "outputs": [ + { + "name": "output", + "type": "T", + "description": "Output tensor containing the same value of the provided tensor." + } + ], + "min_output": 1, + "max_output": 1, + "type_constraints": [ + { + "description": "Constrain input and output types to all tensor types.", + "type_param_str": "T", + "allowed_type_strs": [ + "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)" + ] + } + ], + "examples": [ + { + "summary": "constant", + "code": "values = np.random.randn(5, 5).astype(np.float32)\nnode = onnx.helper.make_node(\n 'Constant',\n inputs=[],\n outputs=['values'],\n value=onnx.helper.make_tensor(\n name='const_tensor',\n data_type=onnx.TensorProto.FLOAT,\n dims=values.shape,\n vals=values.flatten().astype(float),\n ),\n)\n\nexpect(node, inputs=[], outputs=[values],\n name='test_constant')" + } + ], + "category": "Constant" + }, + { + "name": "Constant", + "module": "ai.onnx", + "version": 11, + "support_level": "common", + "description": "A constant tensor. Exactly one of the two attributes, either value or sparse_value,\nmust be specified.\n", + "attributes": [ + { + "name": "sparse_value", + "required": false, + "description": "The value for the elements of the output tensor in sparse format." + }, + { + "name": "value", + "type": "tensor", + "required": false, + "description": "The value for the elements of the output tensor." + } + ], + "min_input": 0, + "max_input": 0, + "outputs": [ + { + "name": "output", + "type": "T", + "description": "Output tensor containing the same value of the provided tensor." + } + ], + "min_output": 1, + "max_output": 1, + "type_constraints": [ + { + "description": "Constrain input and output types to all tensor types.", + "type_param_str": "T", + "allowed_type_strs": [ + "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)" + ] + } + ], + "examples": [ + { + "summary": "constant", + "code": "values = np.random.randn(5, 5).astype(np.float32)\nnode = onnx.helper.make_node(\n 'Constant',\n inputs=[],\n outputs=['values'],\n value=onnx.helper.make_tensor(\n name='const_tensor',\n data_type=onnx.TensorProto.FLOAT,\n dims=values.shape,\n vals=values.flatten().astype(float),\n ),\n)\n\nexpect(node, inputs=[], outputs=[values],\n name='test_constant')" + } + ], + "category": "Constant" + }, + { + "name": "Constant", + "module": "ai.onnx", + "version": 12, + "support_level": "common", + "description": "This operator produces a constant tensor. Exactly one of the provided attributes, either value, sparse_value,\nor value_* must be specified.\n", + "attributes": [ + { + "name": "sparse_value", + "required": false, + "description": "The value for the elements of the output tensor in sparse format." + }, + { + "name": "value", + "type": "tensor", + "required": false, + "description": "The value for the elements of the output tensor." + }, + { + "name": "value_float", + "type": "float32", + "required": false, + "description": "The value for the sole element for the scalar, float32, output tensor." + }, + { + "name": "value_floats", + "type": "float32[]", + "required": false, + "description": "The values for the elements for the 1D, float32, output tensor." + }, + { + "name": "value_int", + "type": "int64", + "required": false, + "description": "The value for the sole element for the scalar, int64, output tensor." + }, + { + "name": "value_ints", + "type": "int64[]", + "required": false, + "description": "The values for the elements for the 1D, int64, output tensor." + }, + { + "name": "value_string", + "type": "string", + "required": false, + "description": "The value for the sole element for the scalar, UTF-8 string, output tensor." + }, + { + "name": "value_strings", + "type": "string[]", + "required": false, + "description": "The values for the elements for the 1D, UTF-8 string, output tensor." + } + ], + "min_input": 0, + "max_input": 0, + "outputs": [ + { + "name": "output", + "type": "T", + "description": "Output tensor containing the same value of the provided tensor." + } + ], + "min_output": 1, + "max_output": 1, + "type_constraints": [ + { + "description": "Constrain input and output types to all tensor types.", + "type_param_str": "T", + "allowed_type_strs": [ + "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)" + ] + } + ], + "examples": [ + { + "summary": "constant", + "code": "values = np.random.randn(5, 5).astype(np.float32)\nnode = onnx.helper.make_node(\n 'Constant',\n inputs=[],\n outputs=['values'],\n value=onnx.helper.make_tensor(\n name='const_tensor',\n data_type=onnx.TensorProto.FLOAT,\n dims=values.shape,\n vals=values.flatten().astype(float),\n ),\n)\n\nexpect(node, inputs=[], outputs=[values],\n name='test_constant')" + } + ], + "category": "Constant" + }, + { + "name": "Constant", + "module": "ai.onnx", + "version": 13, + "support_level": "common", + "description": "This operator produces a constant tensor. Exactly one of the provided attributes, either value, sparse_value,\nor value_* must be specified.\n", + "attributes": [ + { + "name": "sparse_value", + "required": false, + "description": "The value for the elements of the output tensor in sparse format." + }, + { + "name": "value", + "type": "tensor", + "required": false, + "description": "The value for the elements of the output tensor." + }, + { + "name": "value_float", + "type": "float32", + "required": false, + "description": "The value for the sole element for the scalar, float32, output tensor." + }, + { + "name": "value_floats", + "type": "float32[]", + "required": false, + "description": "The values for the elements for the 1D, float32, output tensor." + }, + { + "name": "value_int", + "type": "int64", + "required": false, + "description": "The value for the sole element for the scalar, int64, output tensor." + }, + { + "name": "value_ints", + "type": "int64[]", + "required": false, + "description": "The values for the elements for the 1D, int64, output tensor." + }, + { + "name": "value_string", + "type": "string", + "required": false, + "description": "The value for the sole element for the scalar, UTF-8 string, output tensor." + }, + { + "name": "value_strings", + "type": "string[]", + "required": false, + "description": "The values for the elements for the 1D, UTF-8 string, output tensor." + } + ], + "min_input": 0, + "max_input": 0, + "outputs": [ + { + "name": "output", + "type": "T", + "description": "Output tensor containing the same value of the provided tensor." + } + ], + "min_output": 1, + "max_output": 1, + "type_constraints": [ + { + "description": "Constrain input and output types to all tensor types.", + "type_param_str": "T", + "allowed_type_strs": [ + "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)" + ] + } + ], + "examples": [ + { + "summary": "constant", + "code": "values = np.random.randn(5, 5).astype(np.float32)\nnode = onnx.helper.make_node(\n 'Constant',\n inputs=[],\n outputs=['values'],\n value=onnx.helper.make_tensor(\n name='const_tensor',\n data_type=onnx.TensorProto.FLOAT,\n dims=values.shape,\n vals=values.flatten().astype(float),\n ),\n)\n\nexpect(node, inputs=[], outputs=[values],\n name='test_constant')" + } + ], + "category": "Constant" + }, + { + "name": "ConstantOfShape", + "module": "ai.onnx", + "version": 9, + "support_level": "common", + "description": "Generate a tensor with given value and shape.\n", + "attributes": [ + { + "name": "value", + "type": "tensor", + "required": false, + "description": "(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": [ + { + "name": "input", + "type": "T1", + "description": "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." + } + ], + "min_input": 1, + "max_input": 1, + "outputs": [ + { + "name": "output", + "type": "T2", + "description": "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." + } + ], + "min_output": 1, + "max_output": 1, + "type_constraints": [ + { + "description": "Constrain input types.", + "type_param_str": "T1", + "allowed_type_strs": [ + "tensor(int64)" + ] + }, + { + "description": "Constrain output types to be numerics.", + "type_param_str": "T2", + "allowed_type_strs": [ + "tensor(float16)", + "tensor(float)", + "tensor(double)", + "tensor(int8)", + "tensor(int16)", + "tensor(int32)", + "tensor(int64)", + "tensor(uint8)", + "tensor(uint16)", + "tensor(uint32)", + "tensor(uint64)", + "tensor(bool)" + ] + } + ], + "examples": [ + { + "summary": "float_ones", + "code": "x = np.array([4, 3, 2]).astype(np.int64)\ntensor_value = onnx.helper.make_tensor(\"value\", onnx.TensorProto.FLOAT,\n [1], [1])\nnode = onnx.helper.make_node(\n 'ConstantOfShape',\n inputs=['x'],\n outputs=['y'],\n value=tensor_value,\n)\n\ny = np.ones(x, dtype=np.float32)\nexpect(node, inputs=[x], outputs=[y],\n name='test_constantofshape_float_ones')" + }, + { + "summary": "int32_shape_zero", + "code": "x = np.array([0, ]).astype(np.int64)\ntensor_value = onnx.helper.make_tensor(\"value\", onnx.TensorProto.INT32,\n [1], [0])\nnode = onnx.helper.make_node(\n 'ConstantOfShape',\n inputs=['x'],\n outputs=['y'],\n value=tensor_value,\n)\ny = np.zeros(x, dtype=np.int32)\nexpect(node, inputs=[x], outputs=[y],\n name='test_constantofshape_int_shape_zero')" + }, + { + "summary": "int32_zeros", + "code": "x = np.array([10, 6]).astype(np.int64)\ntensor_value = onnx.helper.make_tensor(\"value\", onnx.TensorProto.INT32,\n [1], [0])\nnode = onnx.helper.make_node(\n 'ConstantOfShape',\n inputs=['x'],\n outputs=['y'],\n value=tensor_value,\n)\ny = np.zeros(x, dtype=np.int32)\nexpect(node, inputs=[x], outputs=[y],\n name='test_constantofshape_int_zeros')" + } + ] + }, + { + "name": "Conv", + "module": "ai.onnx", + "version": 1, + "support_level": "common", + "description": "The convolution operator consumes an input tensor and a filter, and\ncomputes the output.", + "attributes": [ + { + "name": "auto_pad", + "type": "string", + "required": false, + "default": "NOTSET", + "description": "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." + }, + { + "name": "dilations", + "type": "int64[]", + "required": false, + "description": "dilation value along each spatial axis of the filter." + }, + { + "name": "group", + "type": "int64", + "required": false, + "default": 1, + "description": "number of groups input channels and output channels are divided into." + }, + { + "name": "kernel_shape", + "type": "int64[]", + "required": false, + "description": "The shape of the convolution kernel. If not present, should be inferred from input W." + }, + { + "name": "pads", + "type": "int64[]", + "required": false, + "description": "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." + }, + { + "name": "strides", + "type": "int64[]", + "required": false, + "description": "Stride along each spatial axis." + } + ], + "inputs": [ + { + "name": "X", + "type": "T", + "description": "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 ...]." + }, + { + "name": "W", + "type": "T", + "description": "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. " + }, + { + "name": "B", + "type": "T", + "option": "optional", + "description": "Optional 1D bias to be added to the convolution, has size of M." + } + ], + "min_input": 2, + "max_input": 3, + "outputs": [ + { + "name": "Y", + "type": "T", + "description": "Output data tensor that contains the result of the convolution. The output dimensions are functions of the kernel size, stride size, and pad lengths." + } + ], + "min_output": 1, + "max_output": 1, + "inputs_range": "2 - 3", + "type_constraints": [ + { + "description": "Constrain input and output types to float tensors.", + "type_param_str": "T", + "allowed_type_strs": [ + "tensor(float16)", + "tensor(float)", + "tensor(double)" + ] + } + ], + "examples": [ + { + "summary": "conv", + "code": "\nx = np.array([[[[0., 1., 2., 3., 4.], # (1, 1, 5, 5) input tensor\n [5., 6., 7., 8., 9.],\n [10., 11., 12., 13., 14.],\n [15., 16., 17., 18., 19.],\n [20., 21., 22., 23., 24.]]]]).astype(np.float32)\nW = np.array([[[[1., 1., 1.], # (1, 1, 3, 3) tensor for convolution weights\n [1., 1., 1.],\n [1., 1., 1.]]]]).astype(np.float32)\n\n# Convolution with padding\nnode_with_padding = onnx.helper.make_node(\n 'Conv',\n inputs=['x', 'W'],\n outputs=['y'],\n kernel_shape=[3, 3],\n # Default values for other attributes: strides=[1, 1], dilations=[1, 1], groups=1\n pads=[1, 1, 1, 1],\n)\ny_with_padding = np.array([[[[12., 21., 27., 33., 24.], # (1, 1, 5, 5) output tensor\n [33., 54., 63., 72., 51.],\n [63., 99., 108., 117., 81.],\n [93., 144., 153., 162., 111.],\n [72., 111., 117., 123., 84.]]]]).astype(np.float32)\nexpect(node_with_padding, inputs=[x, W], outputs=[y_with_padding],\n name='test_basic_conv_with_padding')\n\n# Convolution without padding\nnode_without_padding = onnx.helper.make_node(\n 'Conv',\n inputs=['x', 'W'],\n outputs=['y'],\n kernel_shape=[3, 3],\n # Default values for other attributes: strides=[1, 1], dilations=[1, 1], groups=1\n pads=[0, 0, 0, 0],\n)\ny_without_padding = np.array([[[[54., 63., 72.], # (1, 1, 3, 3) output tensor\n [99., 108., 117.],\n [144., 153., 162.]]]]).astype(np.float32)\nexpect(node_without_padding, inputs=[x, W], outputs=[y_without_padding],\n name='test_basic_conv_without_padding')" + }, + { + "summary": "conv_with_autopad_same", + "code": "\nx = np.array([[[[0., 1., 2., 3., 4.], # (1, 1, 5, 5) input tensor\n [5., 6., 7., 8., 9.],\n [10., 11., 12., 13., 14.],\n [15., 16., 17., 18., 19.],\n [20., 21., 22., 23., 24.]]]]).astype(np.float32)\nW = np.array([[[[1., 1., 1.], # (1, 1, 3, 3) tensor for convolution weights\n [1., 1., 1.],\n [1., 1., 1.]]]]).astype(np.float32)\n\n# Convolution with auto_pad='SAME_LOWER' and strides=2\nnode = onnx.helper.make_node(\n 'Conv',\n inputs=['x', 'W'],\n outputs=['y'],\n auto_pad='SAME_LOWER',\n kernel_shape=[3, 3],\n strides=[2, 2],\n)\ny = np.array([[[[12., 27., 24.],\n [63., 108., 81.],\n [72., 117., 84.]]]]).astype(np.float32)\nexpect(node, inputs=[x, W], outputs=[y],\n name='test_conv_with_autopad_same')" + }, + { + "summary": "conv_with_strides", + "code": "\nx = np.array([[[[0., 1., 2., 3., 4.], # (1, 1, 7, 5) input tensor\n [5., 6., 7., 8., 9.],\n [10., 11., 12., 13., 14.],\n [15., 16., 17., 18., 19.],\n [20., 21., 22., 23., 24.],\n [25., 26., 27., 28., 29.],\n [30., 31., 32., 33., 34.]]]]).astype(np.float32)\nW = np.array([[[[1., 1., 1.], # (1, 1, 3, 3) tensor for convolution weights\n [1., 1., 1.],\n [1., 1., 1.]]]]).astype(np.float32)\n\n# Convolution with strides=2 and padding\nnode_with_padding = onnx.helper.make_node(\n 'Conv',\n inputs=['x', 'W'],\n outputs=['y'],\n kernel_shape=[3, 3],\n pads=[1, 1, 1, 1],\n strides=[2, 2], # Default values for other attributes: dilations=[1, 1], groups=1\n)\ny_with_padding = np.array([[[[12., 27., 24.], # (1, 1, 4, 3) output tensor\n [63., 108., 81.],\n [123., 198., 141.],\n [112., 177., 124.]]]]).astype(np.float32)\nexpect(node_with_padding, inputs=[x, W], outputs=[y_with_padding],\n name='test_conv_with_strides_padding')\n\n# Convolution with strides=2 and no padding\nnode_without_padding = onnx.helper.make_node(\n 'Conv',\n inputs=['x', 'W'],\n outputs=['y'],\n kernel_shape=[3, 3],\n pads=[0, 0, 0, 0],\n strides=[2, 2], # Default values for other attributes: dilations=[1, 1], groups=1\n)\ny_without_padding = np.array([[[[54., 72.], # (1, 1, 3, 2) output tensor\n [144., 162.],\n [234., 252.]]]]).astype(np.float32)\nexpect(node_without_padding, inputs=[x, W], outputs=[y_without_padding],\n name='test_conv_with_strides_no_padding')\n\n# Convolution with strides=2 and padding only along one dimension (the H dimension in NxCxHxW tensor)\nnode_with_asymmetric_padding = onnx.helper.make_node(\n 'Conv',\n inputs=['x', 'W'],\n outputs=['y'],\n kernel_shape=[3, 3],\n pads=[1, 0, 1, 0],\n strides=[2, 2], # Default values for other attributes: dilations=[1, 1], groups=1\n)\ny_with_asymmetric_padding = np.array([[[[21., 33.], # (1, 1, 4, 2) output tensor\n [99., 117.],\n [189., 207.],\n [171., 183.]]]]).astype(np.float32)\nexpect(node_with_asymmetric_padding, inputs=[x, W], outputs=[y_with_asymmetric_padding],\n name='test_conv_with_strides_and_asymmetric_padding')" + } + ], + "category": "Layer" + }, + { + "name": "Conv", + "module": "ai.onnx", + "version": 11, + "support_level": "common", + "description": "The convolution operator consumes an input tensor and a filter, and\ncomputes the output.", + "attributes": [ + { + "name": "auto_pad", + "type": "string", + "required": false, + "default": "NOTSET", + "description": "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." + }, + { + "name": "dilations", + "type": "int64[]", + "required": false, + "description": "dilation value along each spatial axis of the filter. If not present, the dilation defaults is 1 along each spatial axis." + }, + { + "name": "group", + "type": "int64", + "required": false, + "default": 1, + "description": "number of groups input channels and output channels are divided into." + }, + { + "name": "kernel_shape", + "type": "int64[]", + "required": false, + "description": "The shape of the convolution kernel. If not present, should be inferred from input W." + }, + { + "name": "pads", + "type": "int64[]", + "required": false, + "description": "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." + }, + { + "name": "strides", + "type": "int64[]", + "required": false, + "description": "Stride along each spatial axis. If not present, the stride defaults is 1 along each spatial axis." + } + ], + "inputs": [ + { + "name": "X", + "type": "T", + "description": "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 ...]." + }, + { + "name": "W", + "type": "T", + "description": "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. " + }, + { + "name": "B", + "type": "T", + "option": "optional", + "description": "Optional 1D bias to be added to the convolution, has size of M." + } + ], + "min_input": 2, + "max_input": 3, + "outputs": [ + { + "name": "Y", + "type": "T", + "description": "Output data tensor that contains the result of the convolution. The output dimensions are functions of the kernel size, stride size, and pad lengths." + } + ], + "min_output": 1, + "max_output": 1, + "inputs_range": "2 - 3", + "type_constraints": [ + { + "description": "Constrain input and output types to float tensors.", + "type_param_str": "T", + "allowed_type_strs": [ + "tensor(float16)", + "tensor(float)", + "tensor(double)" + ] + } + ], + "examples": [ + { + "summary": "conv", + "code": "\nx = np.array([[[[0., 1., 2., 3., 4.], # (1, 1, 5, 5) input tensor\n [5., 6., 7., 8., 9.],\n [10., 11., 12., 13., 14.],\n [15., 16., 17., 18., 19.],\n [20., 21., 22., 23., 24.]]]]).astype(np.float32)\nW = np.array([[[[1., 1., 1.], # (1, 1, 3, 3) tensor for convolution weights\n [1., 1., 1.],\n [1., 1., 1.]]]]).astype(np.float32)\n\n# Convolution with padding\nnode_with_padding = onnx.helper.make_node(\n 'Conv',\n inputs=['x', 'W'],\n outputs=['y'],\n kernel_shape=[3, 3],\n # Default values for other attributes: strides=[1, 1], dilations=[1, 1], groups=1\n pads=[1, 1, 1, 1],\n)\ny_with_padding = np.array([[[[12., 21., 27., 33., 24.], # (1, 1, 5, 5) output tensor\n [33., 54., 63., 72., 51.],\n [63., 99., 108., 117., 81.],\n [93., 144., 153., 162., 111.],\n [72., 111., 117., 123., 84.]]]]).astype(np.float32)\nexpect(node_with_padding, inputs=[x, W], outputs=[y_with_padding],\n name='test_basic_conv_with_padding')\n\n# Convolution without padding\nnode_without_padding = onnx.helper.make_node(\n 'Conv',\n inputs=['x', 'W'],\n outputs=['y'],\n kernel_shape=[3, 3],\n # Default values for other attributes: strides=[1, 1], dilations=[1, 1], groups=1\n pads=[0, 0, 0, 0],\n)\ny_without_padding = np.array([[[[54., 63., 72.], # (1, 1, 3, 3) output tensor\n [99., 108., 117.],\n [144., 153., 162.]]]]).astype(np.float32)\nexpect(node_without_padding, inputs=[x, W], outputs=[y_without_padding],\n name='test_basic_conv_without_padding')" + }, + { + "summary": "conv_with_autopad_same", + "code": "\nx = np.array([[[[0., 1., 2., 3., 4.], # (1, 1, 5, 5) input tensor\n [5., 6., 7., 8., 9.],\n [10., 11., 12., 13., 14.],\n [15., 16., 17., 18., 19.],\n [20., 21., 22., 23., 24.]]]]).astype(np.float32)\nW = np.array([[[[1., 1., 1.], # (1, 1, 3, 3) tensor for convolution weights\n [1., 1., 1.],\n [1., 1., 1.]]]]).astype(np.float32)\n\n# Convolution with auto_pad='SAME_LOWER' and strides=2\nnode = onnx.helper.make_node(\n 'Conv',\n inputs=['x', 'W'],\n outputs=['y'],\n auto_pad='SAME_LOWER',\n kernel_shape=[3, 3],\n strides=[2, 2],\n)\ny = np.array([[[[12., 27., 24.],\n [63., 108., 81.],\n [72., 117., 84.]]]]).astype(np.float32)\nexpect(node, inputs=[x, W], outputs=[y],\n name='test_conv_with_autopad_same')" + }, + { + "summary": "conv_with_strides", + "code": "\nx = np.array([[[[0., 1., 2., 3., 4.], # (1, 1, 7, 5) input tensor\n [5., 6., 7., 8., 9.],\n [10., 11., 12., 13., 14.],\n [15., 16., 17., 18., 19.],\n [20., 21., 22., 23., 24.],\n [25., 26., 27., 28., 29.],\n [30., 31., 32., 33., 34.]]]]).astype(np.float32)\nW = np.array([[[[1., 1., 1.], # (1, 1, 3, 3) tensor for convolution weights\n [1., 1., 1.],\n [1., 1., 1.]]]]).astype(np.float32)\n\n# Convolution with strides=2 and padding\nnode_with_padding = onnx.helper.make_node(\n 'Conv',\n inputs=['x', 'W'],\n outputs=['y'],\n kernel_shape=[3, 3],\n pads=[1, 1, 1, 1],\n strides=[2, 2], # Default values for other attributes: dilations=[1, 1], groups=1\n)\ny_with_padding = np.array([[[[12., 27., 24.], # (1, 1, 4, 3) output tensor\n [63., 108., 81.],\n [123., 198., 141.],\n [112., 177., 124.]]]]).astype(np.float32)\nexpect(node_with_padding, inputs=[x, W], outputs=[y_with_padding],\n name='test_conv_with_strides_padding')\n\n# Convolution with strides=2 and no padding\nnode_without_padding = onnx.helper.make_node(\n 'Conv',\n inputs=['x', 'W'],\n outputs=['y'],\n kernel_shape=[3, 3],\n pads=[0, 0, 0, 0],\n strides=[2, 2], # Default values for other attributes: dilations=[1, 1], groups=1\n)\ny_without_padding = np.array([[[[54., 72.], # (1, 1, 3, 2) output tensor\n [144., 162.],\n [234., 252.]]]]).astype(np.float32)\nexpect(node_without_padding, inputs=[x, W], outputs=[y_without_padding],\n name='test_conv_with_strides_no_padding')\n\n# Convolution with strides=2 and padding only along one dimension (the H dimension in NxCxHxW tensor)\nnode_with_asymmetric_padding = onnx.helper.make_node(\n 'Conv',\n inputs=['x', 'W'],\n outputs=['y'],\n kernel_shape=[3, 3],\n pads=[1, 0, 1, 0],\n strides=[2, 2], # Default values for other attributes: dilations=[1, 1], groups=1\n)\ny_with_asymmetric_padding = np.array([[[[21., 33.], # (1, 1, 4, 2) output tensor\n [99., 117.],\n [189., 207.],\n [171., 183.]]]]).astype(np.float32)\nexpect(node_with_asymmetric_padding, inputs=[x, W], outputs=[y_with_asymmetric_padding],\n name='test_conv_with_strides_and_asymmetric_padding')" + } + ], + "category": "Layer" + }, + { + "name": "ConvInteger", + "module": "ai.onnx", + "version": 10, + "support_level": "common", + "description": "The integer convolution operator consumes an input tensor, its zero-point, a filter, and its zero-point,\nand computes the output. The production MUST never overflow. The accumulation may overflow if and only if in 32 bits.\n", + "attributes": [ + { + "name": "auto_pad", + "type": "string", + "required": false, + "default": "NOTSET", + "description": "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." + }, + { + "name": "dilations", + "type": "int64[]", + "required": false, + "description": "dilation value along each spatial axis of the filter. If not present, the dilation defaults to 1 along each axis." + }, + { + "name": "group", + "type": "int64", + "required": false, + "default": 1, + "description": "number of groups input channels and output channels are divided into. default is 1." + }, + { + "name": "kernel_shape", + "type": "int64[]", + "required": false, + "description": "The shape of the convolution kernel. If not present, should be inferred from input 'w'." + }, + { + "name": "pads", + "type": "int64[]", + "required": false, + "description": "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." + }, + { + "name": "strides", + "type": "int64[]", + "required": false, + "description": "Stride along each spatial axis. If not present, the stride defaults to 1 along each axis." + } + ], + "inputs": [ + { + "name": "x", + "type": "T1", + "description": "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 ...]." + }, + { + "name": "w", + "type": "T2", + "description": "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. " + }, + { + "name": "x_zero_point", + "type": "T1", + "option": "optional", + "description": "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." + }, + { + "name": "w_zero_point", + "type": "T2", + "option": "optional", + "description": "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)" + } + ], + "min_input": 2, + "max_input": 4, + "outputs": [ + { + "name": "y", + "type": "T3", + "description": "Output data tensor that contains the result of the convolution. The output dimensions are functions of the kernel size, stride size, and pad lengths." + } + ], + "min_output": 1, + "max_output": 1, + "inputs_range": "2 - 4", + "type_constraints": [ + { + "description": "Constrain input x and its zero point data type to 8-bit integer tensor.", + "type_param_str": "T1", + "allowed_type_strs": [ + "tensor(int8)", + "tensor(uint8)" + ] + }, + { + "description": "Constrain input w and its zero point data type to 8-bit integer tensor.", + "type_param_str": "T2", + "allowed_type_strs": [ + "tensor(int8)", + "tensor(uint8)" + ] + }, + { + "description": "Constrain output y data type to 32-bit integer tensor.", + "type_param_str": "T3", + "allowed_type_strs": [ + "tensor(int32)" + ] + } + ], + "examples": [ + { + "summary": "with_padding", + "code": "\nx = np.array([2, 3, 4, 5, 6, 7, 8, 9, 10]).astype(np.uint8).reshape((1, 1, 3, 3))\nx_zero_point = np.uint8(1)\nw = np.array([1, 1, 1, 1]).astype(np.uint8).reshape((1, 1, 2, 2))\n\ny = 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))\n\n# ConvInteger with padding\nconvinteger_node_with_padding = onnx.helper.make_node('ConvInteger',\n inputs=['x', 'w', 'x_zero_point'],\n outputs=['y'],\n pads=[1, 1, 1, 1],)\n\nexpect(convinteger_node_with_padding, inputs=[x, w, x_zero_point], outputs=[y],\n name='test_convinteger_with_padding')" + }, + { + "summary": "without_padding", + "code": "\nx = np.array([2, 3, 4, 5, 6, 7, 8, 9, 10]).astype(np.uint8).reshape((1, 1, 3, 3))\nx_zero_point = np.uint8(1)\nw = np.array([1, 1, 1, 1]).astype(np.uint8).reshape((1, 1, 2, 2))\n\ny = np.array([12, 16, 24, 28]).astype(np.int32).reshape(1, 1, 2, 2)\n\n# ConvInteger without padding\nconvinteger_node = onnx.helper.make_node('ConvInteger',\n inputs=['x', 'w', 'x_zero_point'],\n outputs=['y'])\n\nexpect(convinteger_node, inputs=[x, w, x_zero_point], outputs=[y],\n name='test_convinteger_without_padding')" + } + ], + "category": "Layer" + }, + { + "name": "ConvTranspose", + "module": "ai.onnx", + "version": 1, + "support_level": "common", + "description": "The convolution transpose operator consumes an input tensor and a filter,\nand computes the output.\n\nIf the pads parameter is provided the shape of the output is calculated via the following equation:\n\n 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]\n\noutput_shape can also be explicitly specified in which case pads values are auto generated using these equations:\n\n total_padding[i] = stride[i] * (input_size[i] - 1) + output_padding[i] + ((kernel_shape[i] - 1) * dilations[i] + 1) - output_shape[i]\n If (auto_pads != SAME_UPPER): pads[start_i] = total_padding[i]/2; pads[end_i] = total_padding[i] - (total_padding[i]/2)\n Else: pads[start_i] = total_padding[i] - (total_padding[i]/2); pads[end_i] = (total_padding[i]/2).\n\n ", + "attributes": [ + { + "name": "auto_pad", + "type": "string", + "required": false, + "default": "NOTSET", + "description": "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." + }, + { + "name": "dilations", + "type": "int64[]", + "required": false, + "description": "dilation value along each spatial axis of the filter." + }, + { + "name": "group", + "type": "int64", + "required": false, + "default": 1, + "description": "number of groups input channels and output channels are divided into." + }, + { + "name": "kernel_shape", + "type": "int64[]", + "required": false, + "description": "The shape of the convolution kernel. If not present, should be inferred from input W." + }, + { + "name": "output_padding", + "type": "int64[]", + "required": false, + "description": "The zero-padding added to one side of the output. This is also called adjs/adjustment in some frameworks." + }, + { + "name": "output_shape", + "type": "int64[]", + "required": false, + "description": "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" + }, + { + "name": "pads", + "type": "int64[]", + "required": false, + "description": "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." + }, + { + "name": "strides", + "type": "int64[]", + "required": false, + "description": "Stride along each spatial axis." + } + ], + "inputs": [ + { + "name": "X", + "type": "T", + "description": "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)" + }, + { + "name": "W", + "type": "T", + "description": "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)" + }, + { + "name": "B", + "type": "T", + "option": "optional", + "description": "Optional 1D bias to be added to the convolution, has size of M." + } + ], + "min_input": 2, + "max_input": 3, + "outputs": [ + { + "name": "Y", + "type": "T", + "description": "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)" + } + ], + "min_output": 1, + "max_output": 1, + "inputs_range": "2 - 3", + "type_constraints": [ + { + "description": "Constrain input and output types to float tensors.", + "type_param_str": "T", + "allowed_type_strs": [ + "tensor(float16)", + "tensor(float)", + "tensor(double)" + ] + } + ], + "examples": [ + { + "summary": "convtranspose", + "code": "x = np.array([[[[0., 1., 2.], # (1, 1, 3, 3)\n [3., 4., 5.],\n [6., 7., 8.]]]]).astype(np.float32)\n\nW = np.array([[[[1., 1., 1.], # (1, 2, 3, 3)\n [1., 1., 1.],\n [1., 1., 1.]],\n [[1., 1., 1.],\n [1., 1., 1.],\n [1., 1., 1.]]]]).astype(np.float32)\n\nnode = onnx.helper.make_node(\"ConvTranspose\", [\"X\", \"W\"], [\"Y\"])\n\ny = np.array([[[[0., 1., 3., 3., 2.], # (1, 2, 5, 5)\n [3., 8., 15., 12., 7.],\n [9., 21., 36., 27., 15.],\n [9., 20., 33., 24., 13.],\n [6., 13., 21., 15., 8.]],\n\n [[0., 1., 3., 3., 2.],\n [3., 8., 15., 12., 7.],\n [9., 21., 36., 27., 15.],\n [9., 20., 33., 24., 13.],\n [6., 13., 21., 15., 8.]]]]).astype(np.float32)\n\nexpect(node, inputs=[x, W], outputs=[y], name='test_convtranspose')" + }, + { + "summary": "convtranspose_1d", + "code": "x = np.array([[[0., 1., 2.]]]).astype(np.float32) # (1, 1, 3)\n\nW = np.array([[[1., 1., 1.], # (1, 2, 3)\n [1., 1., 1.]]]).astype(np.float32)\n\nnode = onnx.helper.make_node(\"ConvTranspose\", [\"X\", \"W\"], [\"Y\"])\n\ny = np.array([[[0., 1., 3., 3., 2.], # (1, 2, 5)\n [0., 1., 3., 3., 2.]]]).astype(np.float32)\n\nexpect(node, inputs=[x, W], outputs=[y], name='test_convtranspose_1d')" + }, + { + "summary": "convtranspose_3d", + "code": "x = np.array([[[[[0., 1., 2., 3., 4.], # (1, 1, 3, 4, 5)\n [5., 6., 7., 8., 9.],\n [10., 11., 12., 13., 14.],\n [15., 16., 17., 18., 19.]],\n [[20., 21., 22., 23., 24.],\n [25., 26., 27., 28., 29.],\n [30., 31., 32., 33., 34.],\n [35., 36., 37., 38., 39.]],\n [[40., 41., 42., 43., 44.],\n [45., 46., 47., 48., 49.],\n [50., 51., 52., 53., 54.],\n [55., 56., 57., 58., 59.]]]]]).astype(np.float32)\n\nW = np.array([[[[[1., 1., 1.], # (1, 2, 3, 3, 3)\n [1., 1., 1.],\n [1., 1., 1.]],\n [[1., 1., 1.],\n [1., 1., 1.],\n [1., 1., 1.]],\n [[1., 1., 1.],\n [1., 1., 1.],\n [1., 1., 1.]]],\n [[[1., 1., 1.],\n [1., 1., 1.],\n [1., 1., 1.]],\n [[1., 1., 1.],\n [1., 1., 1.],\n [1., 1., 1.]],\n [[1., 1., 1.],\n [1., 1., 1.],\n [1., 1., 1.]]]]]).astype(np.float32)\n\nnode = onnx.helper.make_node(\"ConvTranspose\", [\"X\", \"W\"], [\"Y\"])\n\ny = np.array([[[[[0., 1., 3., 6., 9., 7., 4.], # (1, 2, 5, 6, 7)\n [5., 12., 21., 27., 33., 24., 13.],\n [15., 33., 54., 63., 72., 51., 27.],\n [30., 63., 99., 108., 117., 81., 42.],\n [25., 52., 81., 87., 93., 64., 33.],\n [15., 31., 48., 51., 54., 37., 19.]],\n\n [[20., 42., 66., 72., 78., 54., 28.],\n [50., 104., 162., 174., 186., 128., 66.],\n [90., 186., 288., 306., 324., 222., 114.],\n [120., 246., 378., 396., 414., 282., 144.],\n [90., 184., 282., 294., 306., 208., 106.],\n [50., 102., 156., 162., 168., 114., 58.]],\n\n [[60., 123., 189., 198., 207., 141., 72.],\n [135., 276., 423., 441., 459., 312., 159.],\n [225., 459., 702., 729., 756., 513., 261.],\n [270., 549., 837., 864., 891., 603., 306.],\n [195., 396., 603., 621., 639., 432., 219.],\n [105., 213., 324., 333., 342., 231., 117.]],\n\n [[60., 122., 186., 192., 198., 134., 68.],\n [130., 264., 402., 414., 426., 288., 146.],\n [210., 426., 648., 666., 684., 462., 234.],\n [240., 486., 738., 756., 774., 522., 264.],\n [170., 344., 522., 534., 546., 368., 186.],\n [90., 182., 276., 282., 288., 194., 98.]],\n\n [[40., 81., 123., 126., 129., 87., 44.],\n [85., 172., 261., 267., 273., 184., 93.],\n [135., 273., 414., 423., 432., 291., 147.],\n [150., 303., 459., 468., 477., 321., 162.],\n [105., 212., 321., 327., 333., 224., 113.],\n [55., 111., 168., 171., 174., 117., 59.]]],\n\n [[[0., 1., 3., 6., 9., 7., 4.],\n [5., 12., 21., 27., 33., 24., 13.],\n [15., 33., 54., 63., 72., 51., 27.],\n [30., 63., 99., 108., 117., 81., 42.],\n [25., 52., 81., 87., 93., 64., 33.],\n [15., 31., 48., 51., 54., 37., 19.]],\n\n [[20., 42., 66., 72., 78., 54., 28.],\n [50., 104., 162., 174., 186., 128., 66.],\n [90., 186., 288., 306., 324., 222., 114.],\n [120., 246., 378., 396., 414., 282., 144.],\n [90., 184., 282., 294., 306., 208., 106.],\n [50., 102., 156., 162., 168., 114., 58.]],\n\n [[60., 123., 189., 198., 207., 141., 72.],\n [135., 276., 423., 441., 459., 312., 159.],\n [225., 459., 702., 729., 756., 513., 261.],\n [270., 549., 837., 864., 891., 603., 306.],\n [195., 396., 603., 621., 639., 432., 219.],\n [105., 213., 324., 333., 342., 231., 117.]],\n\n [[60., 122., 186., 192., 198., 134., 68.],\n [130., 264., 402., 414., 426., 288., 146.],\n [210., 426., 648., 666., 684., 462., 234.],\n [240., 486., 738., 756., 774., 522., 264.],\n [170., 344., 522., 534., 546., 368., 186.],\n [90., 182., 276., 282., 288., 194., 98.]],\n\n [[40., 81., 123., 126., 129., 87., 44.],\n [85., 172., 261., 267., 273., 184., 93.],\n [135., 273., 414., 423., 432., 291., 147.],\n [150., 303., 459., 468., 477., 321., 162.],\n [105., 212., 321., 327., 333., 224., 113.],\n [55., 111., 168., 171., 174., 117., 59.]]]]]).astype(np.float32)\n\nexpect(node, inputs=[x, W], outputs=[y], name='test_convtranspose_3d')" + }, + { + "summary": "convtranspose_attributes", + "code": "x = np.array([[[[0., 1., 2.], # (1, 1, 3, 3)\n [3., 4., 5.],\n [6., 7., 8.]]]]).astype(np.float32)\n\nW = np.array([[[[1., 1., 1.], # (1, 2, 3, 3)\n [1., 1., 1.],\n [1., 1., 1.]],\n [[1., 1., 1.],\n [1., 1., 1.],\n [1., 1., 1.]]]]).astype(np.float32)\n\ny = np.array([[[[0., 0., 1., 1., 3., 2., 2., 0.], # (1, 2, 10, 8)\n [0., 0., 1., 1., 3., 2., 2., 0.],\n [0., 0., 1., 1., 3., 2., 2., 0.],\n [3., 3., 7., 4., 9., 5., 5., 0.],\n [3., 3., 7., 4., 9., 5., 5., 0.],\n [3., 3., 7., 4., 9., 5., 5., 0.],\n [6., 6., 13., 7., 15., 8., 8., 0.],\n [6., 6., 13., 7., 15., 8., 8., 0.],\n [6., 6., 13., 7., 15., 8., 8., 0.],\n [0., 0., 0., 0., 0., 0., 0., 0.]],\n\n [[0., 0., 1., 1., 3., 2., 2., 0.],\n [0., 0., 1., 1., 3., 2., 2., 0.],\n [0., 0., 1., 1., 3., 2., 2., 0.],\n [3., 3., 7., 4., 9., 5., 5., 0.],\n [3., 3., 7., 4., 9., 5., 5., 0.],\n [3., 3., 7., 4., 9., 5., 5., 0.],\n [6., 6., 13., 7., 15., 8., 8., 0.],\n [6., 6., 13., 7., 15., 8., 8., 0.],\n [6., 6., 13., 7., 15., 8., 8., 0.],\n [0., 0., 0., 0., 0., 0., 0., 0.]]]]).astype(np.float32)\n\nnode = onnx.helper.make_node(\"ConvTranspose\", [\"X\", \"W\"], [\"Y\"],\n strides=[3, 2],\n output_shape=[10, 8])\nexpect(node, inputs=[x, W], outputs=[y], name='test_convtranspose_output_shape')\n\nnode = onnx.helper.make_node(\"ConvTranspose\", [\"X\", \"W\"], [\"Y\"],\n strides=[3, 2],\n output_padding=[1, 1])\nexpect(node, inputs=[x, W], outputs=[y], name='test_convtranspose_pad')\n\nnode = onnx.helper.make_node(\n 'ConvTranspose', ['X', 'W'], ['Y'],\n name='test',\n strides=[3, 2],\n output_shape=[10, 8],\n kernel_shape=[3, 3],\n output_padding=[1, 1]\n)\nexpect(node, inputs=[x, W], outputs=[y],\n name='test_convtranspose_kernel_shape')" + }, + { + "summary": "convtranspose_autopad_same", + "code": "x = np.array([[[[0., 1., 2.], # (1, 1, 3, 3)\n [3., 4., 5.],\n [6., 7., 8.]]]]).astype(np.float32)\n\nW = np.array([[[[1., 1., 1.], # (1, 2, 3, 3)\n [1., 1., 1.],\n [1., 1., 1.]],\n [[1., 1., 1.],\n [1., 1., 1.],\n [1., 1., 1.]]]]).astype(np.float32)\n\nnode = onnx.helper.make_node(\"ConvTranspose\", [\"X\", \"W\"], [\"Y\"], auto_pad=\"SAME_UPPER\", strides=[2, 2])\n\ny = np.array([[[[0., 0., 1., 1., 3., 2.],\n [0., 0., 1., 1., 3., 2.],\n [3., 3., 8., 5., 12., 7.],\n [3., 3., 7., 4., 9., 5.],\n [9., 9., 20., 11., 24., 13.],\n [6., 6., 13., 7., 15., 8.]],\n\n [[0., 0., 1., 1., 3., 2.],\n [0., 0., 1., 1., 3., 2.],\n [3., 3., 8., 5., 12., 7.],\n [3., 3., 7., 4., 9., 5.],\n [9., 9., 20., 11., 24., 13.],\n [6., 6., 13., 7., 15., 8.]]]]).astype(np.float32)\n\nexpect(node, inputs=[x, W], outputs=[y], name='test_convtranspose_autopad_same')" + }, + { + "summary": "convtranspose_dilations", + "code": "x = np.array([[[[3., 8., 1.], # (1, 1, 3, 3)\n [9., 5., 7.],\n [3., 2., 6.]]]]).astype(np.float32)\nW = np.array([[[[7., 2.], # (1, 1, 2, 2)\n [1., 9.]]]]).astype(np.float32)\n\nnode = onnx.helper.make_node(\"ConvTranspose\", [\"X\", \"W\"], [\"Y\"], dilations=[2, 2])\n\ny = np.array([[[[21., 56., 13., 16., 2.], # [1, 1, 5, 5]\n [63., 35., 67., 10., 14.],\n [24., 22., 76., 76., 21.],\n [9., 5., 88., 45., 63.],\n [3., 2., 33., 18., 54.]]]]).astype(np.float32)\n\nexpect(node, inputs=[x, W], outputs=[y], name='test_convtranspose_dilations')" + }, + { + "summary": "convtranspose_pads", + "code": "x = np.array([[[[0., 1., 2.], # (1, 1, 3, 3)\n [3., 4., 5.],\n [6., 7., 8.]]]]).astype(np.float32)\n\nW = np.array([[[[1., 1., 1.], # (1, 2, 3, 3)\n [1., 1., 1.],\n [1., 1., 1.]],\n [[1., 1., 1.],\n [1., 1., 1.],\n [1., 1., 1.]]]]).astype(np.float32)\n\nnode = onnx.helper.make_node(\"ConvTranspose\", [\"X\", \"W\"], [\"Y\"],\n strides=[3, 2],\n pads=[1, 2, 1, 2])\n\ny = np.array([[[[1., 1., 3.], # (1, 2, 7, 3)\n [1., 1., 3.],\n [7., 4., 9.],\n [7., 4., 9.],\n [7., 4., 9.],\n [13., 7., 15.],\n [13., 7., 15.]],\n\n [[1., 1., 3.],\n [1., 1., 3.],\n [7., 4., 9.],\n [7., 4., 9.],\n [7., 4., 9.],\n [13., 7., 15.],\n [13., 7., 15.]]]]).astype(np.float32)\n\nexpect(node, inputs=[x, W], outputs=[y], name='test_convtranspose_pads')" + } + ], + "category": "Layer" + }, + { + "name": "ConvTranspose", + "module": "ai.onnx", + "version": 11, + "support_level": "common", + "description": "The convolution transpose operator consumes an input tensor and a filter,\nand computes the output.\n\nIf the pads parameter is provided the shape of the output is calculated via the following equation:\n\n 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]\n\noutput_shape can also be explicitly specified in which case pads values are auto generated using these equations:\n\n total_padding[i] = stride[i] * (input_size[i] - 1) + output_padding[i] + ((kernel_shape[i] - 1) * dilations[i] + 1) - output_shape[i]\n If (auto_pads == SAME_UPPER): pads[start_i] = total_padding[i]/2; pads[end_i] = total_padding[i] - (total_padding[i]/2)\n Else: pads[start_i] = total_padding[i] - (total_padding[i]/2); pads[end_i] = (total_padding[i]/2).\n\n ", + "attributes": [ + { + "name": "auto_pad", + "type": "string", + "required": false, + "default": "NOTSET", + "description": "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." + }, + { + "name": "dilations", + "type": "int64[]", + "required": false, + "description": "dilation value along each spatial axis of the filter. If not present, the dilation defaults to 1 along each spatial axis." + }, + { + "name": "group", + "type": "int64", + "required": false, + "default": 1, + "description": "number of groups input channels and output channels are divided into." + }, + { + "name": "kernel_shape", + "type": "int64[]", + "required": false, + "description": "The shape of the convolution kernel. If not present, should be inferred from input W." + }, + { + "name": "output_padding", + "type": "int64[]", + "required": false, + "description": "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." + }, + { + "name": "output_shape", + "type": "int64[]", + "required": false, + "description": "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" + }, + { + "name": "pads", + "type": "int64[]", + "required": false, + "description": "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." + }, + { + "name": "strides", + "type": "int64[]", + "required": false, + "description": "Stride along each spatial axis. If not present, the stride defaults to 1 along each spatial axis." + } + ], + "inputs": [ + { + "name": "X", + "type": "T", + "description": "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)" + }, + { + "name": "W", + "type": "T", + "description": "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)" + }, + { + "name": "B", + "type": "T", + "option": "optional", + "description": "Optional 1D bias to be added to the convolution, has size of M." + } + ], + "min_input": 2, + "max_input": 3, + "outputs": [ + { + "name": "Y", + "type": "T", + "description": "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)" + } + ], + "min_output": 1, + "max_output": 1, + "inputs_range": "2 - 3", + "type_constraints": [ + { + "description": "Constrain input and output types to float tensors.", + "type_param_str": "T", + "allowed_type_strs": [ + "tensor(float16)", + "tensor(float)", + "tensor(double)" + ] + } + ], + "examples": [ + { + "summary": "convtranspose", + "code": "x = np.array([[[[0., 1., 2.], # (1, 1, 3, 3)\n [3., 4., 5.],\n [6., 7., 8.]]]]).astype(np.float32)\n\nW = np.array([[[[1., 1., 1.], # (1, 2, 3, 3)\n [1., 1., 1.],\n [1., 1., 1.]],\n [[1., 1., 1.],\n [1., 1., 1.],\n [1., 1., 1.]]]]).astype(np.float32)\n\nnode = onnx.helper.make_node(\"ConvTranspose\", [\"X\", \"W\"], [\"Y\"])\n\ny = np.array([[[[0., 1., 3., 3., 2.], # (1, 2, 5, 5)\n [3., 8., 15., 12., 7.],\n [9., 21., 36., 27., 15.],\n [9., 20., 33., 24., 13.],\n [6., 13., 21., 15., 8.]],\n\n [[0., 1., 3., 3., 2.],\n [3., 8., 15., 12., 7.],\n [9., 21., 36., 27., 15.],\n [9., 20., 33., 24., 13.],\n [6., 13., 21., 15., 8.]]]]).astype(np.float32)\n\nexpect(node, inputs=[x, W], outputs=[y], name='test_convtranspose')" + }, + { + "summary": "convtranspose_1d", + "code": "x = np.array([[[0., 1., 2.]]]).astype(np.float32) # (1, 1, 3)\n\nW = np.array([[[1., 1., 1.], # (1, 2, 3)\n [1., 1., 1.]]]).astype(np.float32)\n\nnode = onnx.helper.make_node(\"ConvTranspose\", [\"X\", \"W\"], [\"Y\"])\n\ny = np.array([[[0., 1., 3., 3., 2.], # (1, 2, 5)\n [0., 1., 3., 3., 2.]]]).astype(np.float32)\n\nexpect(node, inputs=[x, W], outputs=[y], name='test_convtranspose_1d')" + }, + { + "summary": "convtranspose_3d", + "code": "x = np.array([[[[[0., 1., 2., 3., 4.], # (1, 1, 3, 4, 5)\n [5., 6., 7., 8., 9.],\n [10., 11., 12., 13., 14.],\n [15., 16., 17., 18., 19.]],\n [[20., 21., 22., 23., 24.],\n [25., 26., 27., 28., 29.],\n [30., 31., 32., 33., 34.],\n [35., 36., 37., 38., 39.]],\n [[40., 41., 42., 43., 44.],\n [45., 46., 47., 48., 49.],\n [50., 51., 52., 53., 54.],\n [55., 56., 57., 58., 59.]]]]]).astype(np.float32)\n\nW = np.array([[[[[1., 1., 1.], # (1, 2, 3, 3, 3)\n [1., 1., 1.],\n [1., 1., 1.]],\n [[1., 1., 1.],\n [1., 1., 1.],\n [1., 1., 1.]],\n [[1., 1., 1.],\n [1., 1., 1.],\n [1., 1., 1.]]],\n [[[1., 1., 1.],\n [1., 1., 1.],\n [1., 1., 1.]],\n [[1., 1., 1.],\n [1., 1., 1.],\n [1., 1., 1.]],\n [[1., 1., 1.],\n [1., 1., 1.],\n [1., 1., 1.]]]]]).astype(np.float32)\n\nnode = onnx.helper.make_node(\"ConvTranspose\", [\"X\", \"W\"], [\"Y\"])\n\ny = np.array([[[[[0., 1., 3., 6., 9., 7., 4.], # (1, 2, 5, 6, 7)\n [5., 12., 21., 27., 33., 24., 13.],\n [15., 33., 54., 63., 72., 51., 27.],\n [30., 63., 99., 108., 117., 81., 42.],\n [25., 52., 81., 87., 93., 64., 33.],\n [15., 31., 48., 51., 54., 37., 19.]],\n\n [[20., 42., 66., 72., 78., 54., 28.],\n [50., 104., 162., 174., 186., 128., 66.],\n [90., 186., 288., 306., 324., 222., 114.],\n [120., 246., 378., 396., 414., 282., 144.],\n [90., 184., 282., 294., 306., 208., 106.],\n [50., 102., 156., 162., 168., 114., 58.]],\n\n [[60., 123., 189., 198., 207., 141., 72.],\n [135., 276., 423., 441., 459., 312., 159.],\n [225., 459., 702., 729., 756., 513., 261.],\n [270., 549., 837., 864., 891., 603., 306.],\n [195., 396., 603., 621., 639., 432., 219.],\n [105., 213., 324., 333., 342., 231., 117.]],\n\n [[60., 122., 186., 192., 198., 134., 68.],\n [130., 264., 402., 414., 426., 288., 146.],\n [210., 426., 648., 666., 684., 462., 234.],\n [240., 486., 738., 756., 774., 522., 264.],\n [170., 344., 522., 534., 546., 368., 186.],\n [90., 182., 276., 282., 288., 194., 98.]],\n\n [[40., 81., 123., 126., 129., 87., 44.],\n [85., 172., 261., 267., 273., 184., 93.],\n [135., 273., 414., 423., 432., 291., 147.],\n [150., 303., 459., 468., 477., 321., 162.],\n [105., 212., 321., 327., 333., 224., 113.],\n [55., 111., 168., 171., 174., 117., 59.]]],\n\n [[[0., 1., 3., 6., 9., 7., 4.],\n [5., 12., 21., 27., 33., 24., 13.],\n [15., 33., 54., 63., 72., 51., 27.],\n [30., 63., 99., 108., 117., 81., 42.],\n [25., 52., 81., 87., 93., 64., 33.],\n [15., 31., 48., 51., 54., 37., 19.]],\n\n [[20., 42., 66., 72., 78., 54., 28.],\n [50., 104., 162., 174., 186., 128., 66.],\n [90., 186., 288., 306., 324., 222., 114.],\n [120., 246., 378., 396., 414., 282., 144.],\n [90., 184., 282., 294., 306., 208., 106.],\n [50., 102., 156., 162., 168., 114., 58.]],\n\n [[60., 123., 189., 198., 207., 141., 72.],\n [135., 276., 423., 441., 459., 312., 159.],\n [225., 459., 702., 729., 756., 513., 261.],\n [270., 549., 837., 864., 891., 603., 306.],\n [195., 396., 603., 621., 639., 432., 219.],\n [105., 213., 324., 333., 342., 231., 117.]],\n\n [[60., 122., 186., 192., 198., 134., 68.],\n [130., 264., 402., 414., 426., 288., 146.],\n [210., 426., 648., 666., 684., 462., 234.],\n [240., 486., 738., 756., 774., 522., 264.],\n [170., 344., 522., 534., 546., 368., 186.],\n [90., 182., 276., 282., 288., 194., 98.]],\n\n [[40., 81., 123., 126., 129., 87., 44.],\n [85., 172., 261., 267., 273., 184., 93.],\n [135., 273., 414., 423., 432., 291., 147.],\n [150., 303., 459., 468., 477., 321., 162.],\n [105., 212., 321., 327., 333., 224., 113.],\n [55., 111., 168., 171., 174., 117., 59.]]]]]).astype(np.float32)\n\nexpect(node, inputs=[x, W], outputs=[y], name='test_convtranspose_3d')" + }, + { + "summary": "convtranspose_attributes", + "code": "x = np.array([[[[0., 1., 2.], # (1, 1, 3, 3)\n [3., 4., 5.],\n [6., 7., 8.]]]]).astype(np.float32)\n\nW = np.array([[[[1., 1., 1.], # (1, 2, 3, 3)\n [1., 1., 1.],\n [1., 1., 1.]],\n [[1., 1., 1.],\n [1., 1., 1.],\n [1., 1., 1.]]]]).astype(np.float32)\n\ny = np.array([[[[0., 0., 1., 1., 3., 2., 2., 0.], # (1, 2, 10, 8)\n [0., 0., 1., 1., 3., 2., 2., 0.],\n [0., 0., 1., 1., 3., 2., 2., 0.],\n [3., 3., 7., 4., 9., 5., 5., 0.],\n [3., 3., 7., 4., 9., 5., 5., 0.],\n [3., 3., 7., 4., 9., 5., 5., 0.],\n [6., 6., 13., 7., 15., 8., 8., 0.],\n [6., 6., 13., 7., 15., 8., 8., 0.],\n [6., 6., 13., 7., 15., 8., 8., 0.],\n [0., 0., 0., 0., 0., 0., 0., 0.]],\n\n [[0., 0., 1., 1., 3., 2., 2., 0.],\n [0., 0., 1., 1., 3., 2., 2., 0.],\n [0., 0., 1., 1., 3., 2., 2., 0.],\n [3., 3., 7., 4., 9., 5., 5., 0.],\n [3., 3., 7., 4., 9., 5., 5., 0.],\n [3., 3., 7., 4., 9., 5., 5., 0.],\n [6., 6., 13., 7., 15., 8., 8., 0.],\n [6., 6., 13., 7., 15., 8., 8., 0.],\n [6., 6., 13., 7., 15., 8., 8., 0.],\n [0., 0., 0., 0., 0., 0., 0., 0.]]]]).astype(np.float32)\n\nnode = onnx.helper.make_node(\"ConvTranspose\", [\"X\", \"W\"], [\"Y\"],\n strides=[3, 2],\n output_shape=[10, 8])\nexpect(node, inputs=[x, W], outputs=[y], name='test_convtranspose_output_shape')\n\nnode = onnx.helper.make_node(\"ConvTranspose\", [\"X\", \"W\"], [\"Y\"],\n strides=[3, 2],\n output_padding=[1, 1])\nexpect(node, inputs=[x, W], outputs=[y], name='test_convtranspose_pad')\n\nnode = onnx.helper.make_node(\n 'ConvTranspose', ['X', 'W'], ['Y'],\n name='test',\n strides=[3, 2],\n output_shape=[10, 8],\n kernel_shape=[3, 3],\n output_padding=[1, 1]\n)\nexpect(node, inputs=[x, W], outputs=[y],\n name='test_convtranspose_kernel_shape')" + }, + { + "summary": "convtranspose_autopad_same", + "code": "x = np.array([[[[0., 1., 2.], # (1, 1, 3, 3)\n [3., 4., 5.],\n [6., 7., 8.]]]]).astype(np.float32)\n\nW = np.array([[[[1., 1., 1.], # (1, 2, 3, 3)\n [1., 1., 1.],\n [1., 1., 1.]],\n [[1., 1., 1.],\n [1., 1., 1.],\n [1., 1., 1.]]]]).astype(np.float32)\n\nnode = onnx.helper.make_node(\"ConvTranspose\", [\"X\", \"W\"], [\"Y\"], auto_pad=\"SAME_UPPER\", strides=[2, 2])\n\ny = np.array([[[[0., 0., 1., 1., 3., 2.],\n [0., 0., 1., 1., 3., 2.],\n [3., 3., 8., 5., 12., 7.],\n [3., 3., 7., 4., 9., 5.],\n [9., 9., 20., 11., 24., 13.],\n [6., 6., 13., 7., 15., 8.]],\n\n [[0., 0., 1., 1., 3., 2.],\n [0., 0., 1., 1., 3., 2.],\n [3., 3., 8., 5., 12., 7.],\n [3., 3., 7., 4., 9., 5.],\n [9., 9., 20., 11., 24., 13.],\n [6., 6., 13., 7., 15., 8.]]]]).astype(np.float32)\n\nexpect(node, inputs=[x, W], outputs=[y], name='test_convtranspose_autopad_same')" + }, + { + "summary": "convtranspose_dilations", + "code": "x = np.array([[[[3., 8., 1.], # (1, 1, 3, 3)\n [9., 5., 7.],\n [3., 2., 6.]]]]).astype(np.float32)\nW = np.array([[[[7., 2.], # (1, 1, 2, 2)\n [1., 9.]]]]).astype(np.float32)\n\nnode = onnx.helper.make_node(\"ConvTranspose\", [\"X\", \"W\"], [\"Y\"], dilations=[2, 2])\n\ny = np.array([[[[21., 56., 13., 16., 2.], # [1, 1, 5, 5]\n [63., 35., 67., 10., 14.],\n [24., 22., 76., 76., 21.],\n [9., 5., 88., 45., 63.],\n [3., 2., 33., 18., 54.]]]]).astype(np.float32)\n\nexpect(node, inputs=[x, W], outputs=[y], name='test_convtranspose_dilations')" + }, + { + "summary": "convtranspose_pads", + "code": "x = np.array([[[[0., 1., 2.], # (1, 1, 3, 3)\n [3., 4., 5.],\n [6., 7., 8.]]]]).astype(np.float32)\n\nW = np.array([[[[1., 1., 1.], # (1, 2, 3, 3)\n [1., 1., 1.],\n [1., 1., 1.]],\n [[1., 1., 1.],\n [1., 1., 1.],\n [1., 1., 1.]]]]).astype(np.float32)\n\nnode = onnx.helper.make_node(\"ConvTranspose\", [\"X\", \"W\"], [\"Y\"],\n strides=[3, 2],\n pads=[1, 2, 1, 2])\n\ny = np.array([[[[1., 1., 3.], # (1, 2, 7, 3)\n [1., 1., 3.],\n [7., 4., 9.],\n [7., 4., 9.],\n [7., 4., 9.],\n [13., 7., 15.],\n [13., 7., 15.]],\n\n [[1., 1., 3.],\n [1., 1., 3.],\n [7., 4., 9.],\n [7., 4., 9.],\n [7., 4., 9.],\n [13., 7., 15.],\n [13., 7., 15.]]]]).astype(np.float32)\n\nexpect(node, inputs=[x, W], outputs=[y], name='test_convtranspose_pads')" + } + ], + "category": "Layer" + }, + { + "name": "Cos", + "module": "ai.onnx", + "version": 7, + "support_level": "common", + "description": "Calculates the cosine of the given input tensor, element-wise.\n", + "inputs": [ + { + "name": "input", + "type": "T", + "description": "Input tensor" + } + ], + "min_input": 1, + "max_input": 1, + "outputs": [ + { + "name": "output", + "type": "T", + "description": "The cosine of the input tensor computed element-wise" + } + ], + "min_output": 1, + "max_output": 1, + "type_constraints": [ + { + "description": "Constrain input and output types to float tensors.", + "type_param_str": "T", + "allowed_type_strs": [ + "tensor(float16)", + "tensor(float)", + "tensor(double)" + ] + } + ], + "examples": [ + { + "summary": "cos", + "code": "node = onnx.helper.make_node(\n 'Cos',\n inputs=['x'],\n outputs=['y'],\n)\n\nx = np.array([-1, 0, 1]).astype(np.float32)\ny = np.cos(x)\nexpect(node, inputs=[x], outputs=[y],\n name='test_cos_example')\n\nx = np.random.randn(3, 4, 5).astype(np.float32)\ny = np.cos(x)\nexpect(node, inputs=[x], outputs=[y],\n name='test_cos')" + } + ] + }, + { + "name": "Cosh", + "module": "ai.onnx", + "version": 9, + "support_level": "common", + "description": "Calculates the hyperbolic cosine of the given input tensor element-wise.\n", + "inputs": [ + { + "name": "input", + "type": "T", + "description": "Input tensor" + } + ], + "min_input": 1, + "max_input": 1, + "outputs": [ + { + "name": "output", + "type": "T", + "description": "The hyperbolic cosine values of the input tensor computed element-wise" + } + ], + "min_output": 1, + "max_output": 1, + "type_constraints": [ + { + "description": "Constrain input and output types to float tensors.", + "type_param_str": "T", + "allowed_type_strs": [ + "tensor(float16)", + "tensor(float)", + "tensor(double)" + ] + } + ], + "examples": [ + { + "summary": "cosh", + "code": "node = onnx.helper.make_node(\n 'Cosh',\n inputs=['x'],\n outputs=['y'],\n)\n\nx = np.array([-1, 0, 1]).astype(np.float32)\ny = np.cosh(x) # expected output [1.54308069, 1., 1.54308069]\nexpect(node, inputs=[x], outputs=[y],\n name='test_cosh_example')\n\nx = np.random.randn(3, 4, 5).astype(np.float32)\ny = np.cosh(x)\nexpect(node, inputs=[x], outputs=[y],\n name='test_cosh')" + } + ] + }, + { + "name": "CumSum", + "module": "ai.onnx", + "version": 11, + "support_level": "common", + "description": "Performs cumulative sum of the input elements along the given axis.\nBy default, it will do the sum inclusively meaning the first element is copied as is.\nThrough an `exclusive` attribute, this behavior can change to exclude the first element.\nIt can also perform summation in the opposite direction of the axis. For that, set `reverse` attribute to 1.\n\nExample:\n```\ninput_x = [1, 2, 3]\naxis=0\noutput = [1, 3, 6]\nexclusive=1\noutput = [0, 1, 3]\nexclusive=0\nreverse=1\noutput = [6, 5, 3]\nexclusive=1\nreverse=1\noutput = [5, 3, 0]\n```\n ", + "attributes": [ + { + "name": "exclusive", + "type": "int64", + "required": false, + "description": "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." + }, + { + "name": "reverse", + "type": "int64", + "required": false, + "description": "If set to 1 will perform the sums in reverse direction." + } + ], + "inputs": [ + { + "name": "x", + "type": "T", + "description": "An input tensor that is to be processed." + }, + { + "name": "axis", + "type": "T2", + "description": "A 0-D tensor. Must be in the range [-rank(x), rank(x)-1]. Negative value means counting dimensions from the back." + } + ], + "min_input": 2, + "max_input": 2, + "outputs": [ + { + "name": "y", + "type": "T", + "description": "Output tensor of the same type as 'x' with cumulative sums of the x's elements" + } + ], + "min_output": 1, + "max_output": 1, + "type_constraints": [ + { + "description": "Input can be of any tensor type.", + "type_param_str": "T", + "allowed_type_strs": [ + "tensor(uint32)", + "tensor(uint64)", + "tensor(int32)", + "tensor(int64)", + "tensor(float)", + "tensor(double)" + ] + }, + { + "description": "axis tensor can be int32 or int64 only", + "type_param_str": "T2", + "allowed_type_strs": [ + "tensor(int32)", + "tensor(int64)" + ] + } + ], + "examples": [ + { + "summary": "cumsum_1d", + "code": "node = onnx.helper.make_node(\n 'CumSum',\n inputs=['x', 'axis'],\n outputs=['y']\n)\nx = np.array([1., 2., 3., 4., 5.]).astype(np.float64)\naxis = np.int32(0)\ny = np.array([1., 3., 6., 10., 15.]).astype(np.float64)\nexpect(node, inputs=[x, axis], outputs=[y],\n name='test_cumsum_1d')" + }, + { + "summary": "cumsum_1d_exclusive", + "code": "node = onnx.helper.make_node(\n 'CumSum',\n inputs=['x', 'axis'],\n outputs=['y'],\n exclusive=1\n)\nx = np.array([1., 2., 3., 4., 5.]).astype(np.float64)\naxis = np.int32(0)\ny = np.array([0., 1., 3., 6., 10.]).astype(np.float64)\nexpect(node, inputs=[x, axis], outputs=[y],\n name='test_cumsum_1d_exclusive')" + }, + { + "summary": "cumsum_1d_reverse", + "code": "node = onnx.helper.make_node(\n 'CumSum',\n inputs=['x', 'axis'],\n outputs=['y'],\n reverse=1\n)\nx = np.array([1., 2., 3., 4., 5.]).astype(np.float64)\naxis = np.int32(0)\ny = np.array([15., 14., 12., 9., 5.]).astype(np.float64)\nexpect(node, inputs=[x, axis], outputs=[y],\n name='test_cumsum_1d_reverse')" + }, + { + "summary": "cumsum_1d_reverse_exclusive", + "code": "node = onnx.helper.make_node(\n 'CumSum',\n inputs=['x', 'axis'],\n outputs=['y'],\n reverse=1,\n exclusive=1\n)\nx = np.array([1., 2., 3., 4., 5.]).astype(np.float64)\naxis = np.int32(0)\ny = np.array([14., 12., 9., 5., 0.]).astype(np.float64)\nexpect(node, inputs=[x, axis], outputs=[y],\n name='test_cumsum_1d_reverse_exclusive')" + }, + { + "summary": "cumsum_2d_axis_0", + "code": "node = onnx.helper.make_node(\n 'CumSum',\n inputs=['x', 'axis'],\n outputs=['y'],\n)\nx = np.array([1., 2., 3., 4., 5., 6.]).astype(np.float64).reshape((2, 3))\naxis = np.int32(0)\ny = np.array([1., 2., 3., 5., 7., 9.]).astype(np.float64).reshape((2, 3))\nexpect(node, inputs=[x, axis], outputs=[y],\n name='test_cumsum_2d_axis_0')" + }, + { + "summary": "cumsum_2d_axis_1", + "code": "node = onnx.helper.make_node(\n 'CumSum',\n inputs=['x', 'axis'],\n outputs=['y'],\n)\nx = np.array([1., 2., 3., 4., 5., 6.]).astype(np.float64).reshape((2, 3))\naxis = np.int32(1)\ny = np.array([1., 3., 6., 4., 9., 15.]).astype(np.float64).reshape((2, 3))\nexpect(node, inputs=[x, axis], outputs=[y],\n name='test_cumsum_2d_axis_1')" + }, + { + "summary": "cumsum_2d_negative_axis", + "code": "node = onnx.helper.make_node(\n 'CumSum',\n inputs=['x', 'axis'],\n outputs=['y'],\n)\nx = np.array([1., 2., 3., 4., 5., 6.]).astype(np.float64).reshape((2, 3))\naxis = np.int32(-1)\ny = np.array([1., 3., 6., 4., 9., 15.]).astype(np.float64).reshape((2, 3))\nexpect(node, inputs=[x, axis], outputs=[y],\n name='test_cumsum_2d_negative_axis')" + } + ] + }, + { + "name": "CumSum", + "module": "ai.onnx", + "version": 14, + "support_level": "common", + "description": "Performs cumulative sum of the input elements along the given axis.\nBy default, it will do the sum inclusively meaning the first element is copied as is.\nThrough an `exclusive` attribute, this behavior can change to exclude the first element.\nIt can also perform summation in the opposite direction of the axis. For that, set `reverse` attribute to 1.\n\nExample:\n```\ninput_x = [1, 2, 3]\naxis=0\noutput = [1, 3, 6]\nexclusive=1\noutput = [0, 1, 3]\nexclusive=0\nreverse=1\noutput = [6, 5, 3]\nexclusive=1\nreverse=1\noutput = [5, 3, 0]\n```\n ", + "attributes": [ + { + "name": "exclusive", + "type": "int64", + "required": false, + "description": "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." + }, + { + "name": "reverse", + "type": "int64", + "required": false, + "description": "If set to 1 will perform the sums in reverse direction." + } + ], + "inputs": [ + { + "name": "x", + "type": "T", + "description": "An input tensor that is to be processed." + }, + { + "name": "axis", + "type": "T2", + "description": "A 0-D tensor. Must be in the range [-rank(x), rank(x)-1]. Negative value means counting dimensions from the back." + } + ], + "min_input": 2, + "max_input": 2, + "outputs": [ + { + "name": "y", + "type": "T", + "description": "Output tensor of the same type as 'x' with cumulative sums of the x's elements" + } + ], + "min_output": 1, + "max_output": 1, + "type_constraints": [ + { + "description": "Constrain input and output types to high-precision numeric tensors.", + "type_param_str": "T", + "allowed_type_strs": [ + "tensor(uint32)", + "tensor(uint64)", + "tensor(int32)", + "tensor(int64)", + "tensor(float16)", + "tensor(float)", + "tensor(double)", + "tensor(bfloat16)" + ] + }, + { + "description": "axis tensor can be int32 or int64 only", + "type_param_str": "T2", + "allowed_type_strs": [ + "tensor(int32)", + "tensor(int64)" + ] + } + ], + "examples": [ + { + "summary": "cumsum_1d", + "code": "node = onnx.helper.make_node(\n 'CumSum',\n inputs=['x', 'axis'],\n outputs=['y']\n)\nx = np.array([1., 2., 3., 4., 5.]).astype(np.float64)\naxis = np.int32(0)\ny = np.array([1., 3., 6., 10., 15.]).astype(np.float64)\nexpect(node, inputs=[x, axis], outputs=[y],\n name='test_cumsum_1d')" + }, + { + "summary": "cumsum_1d_exclusive", + "code": "node = onnx.helper.make_node(\n 'CumSum',\n inputs=['x', 'axis'],\n outputs=['y'],\n exclusive=1\n)\nx = np.array([1., 2., 3., 4., 5.]).astype(np.float64)\naxis = np.int32(0)\ny = np.array([0., 1., 3., 6., 10.]).astype(np.float64)\nexpect(node, inputs=[x, axis], outputs=[y],\n name='test_cumsum_1d_exclusive')" + }, + { + "summary": "cumsum_1d_reverse", + "code": "node = onnx.helper.make_node(\n 'CumSum',\n inputs=['x', 'axis'],\n outputs=['y'],\n reverse=1\n)\nx = np.array([1., 2., 3., 4., 5.]).astype(np.float64)\naxis = np.int32(0)\ny = np.array([15., 14., 12., 9., 5.]).astype(np.float64)\nexpect(node, inputs=[x, axis], outputs=[y],\n name='test_cumsum_1d_reverse')" + }, + { + "summary": "cumsum_1d_reverse_exclusive", + "code": "node = onnx.helper.make_node(\n 'CumSum',\n inputs=['x', 'axis'],\n outputs=['y'],\n reverse=1,\n exclusive=1\n)\nx = np.array([1., 2., 3., 4., 5.]).astype(np.float64)\naxis = np.int32(0)\ny = np.array([14., 12., 9., 5., 0.]).astype(np.float64)\nexpect(node, inputs=[x, axis], outputs=[y],\n name='test_cumsum_1d_reverse_exclusive')" + }, + { + "summary": "cumsum_2d_axis_0", + "code": "node = onnx.helper.make_node(\n 'CumSum',\n inputs=['x', 'axis'],\n outputs=['y'],\n)\nx = np.array([1., 2., 3., 4., 5., 6.]).astype(np.float64).reshape((2, 3))\naxis = np.int32(0)\ny = np.array([1., 2., 3., 5., 7., 9.]).astype(np.float64).reshape((2, 3))\nexpect(node, inputs=[x, axis], outputs=[y],\n name='test_cumsum_2d_axis_0')" + }, + { + "summary": "cumsum_2d_axis_1", + "code": "node = onnx.helper.make_node(\n 'CumSum',\n inputs=['x', 'axis'],\n outputs=['y'],\n)\nx = np.array([1., 2., 3., 4., 5., 6.]).astype(np.float64).reshape((2, 3))\naxis = np.int32(1)\ny = np.array([1., 3., 6., 4., 9., 15.]).astype(np.float64).reshape((2, 3))\nexpect(node, inputs=[x, axis], outputs=[y],\n name='test_cumsum_2d_axis_1')" + }, + { + "summary": "cumsum_2d_negative_axis", + "code": "node = onnx.helper.make_node(\n 'CumSum',\n inputs=['x', 'axis'],\n outputs=['y'],\n)\nx = np.array([1., 2., 3., 4., 5., 6.]).astype(np.float64).reshape((2, 3))\naxis = np.int32(-1)\ny = np.array([1., 3., 6., 4., 9., 15.]).astype(np.float64).reshape((2, 3))\nexpect(node, inputs=[x, axis], outputs=[y],\n name='test_cumsum_2d_negative_axis')" + } + ] + }, + { + "name": "DepthToSpace", + "module": "ai.onnx", + "version": 1, + "support_level": "common", + "description": "DepthToSpace rearranges (permutes) data from depth into blocks of spatial data.\nThis is the reverse transformation of SpaceToDepth. More specifically, this op outputs a copy of\nthe input tensor where values from the depth dimension are moved in spatial blocks to the height\nand width dimensions.\n", + "attributes": [ + { + "name": "blocksize", + "type": "int64", + "required": true, + "description": "Blocks of [blocksize, blocksize] are moved." + } + ], + "inputs": [ + { + "name": "input", + "type": "T", + "description": "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." + } + ], + "min_input": 1, + "max_input": 1, + "outputs": [ + { + "name": "output", + "type": "T", + "description": "Output tensor of [N, C/(blocksize * blocksize), H * blocksize, W * blocksize]." + } + ], + "min_output": 1, + "max_output": 1, + "type_constraints": [ + { + "description": "Constrain input and output types to all tensor types.", + "type_param_str": "T", + "allowed_type_strs": [ + "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)" + ] + } + ], + "examples": [ + { + "summary": "crd_mode_example", + "code": "node = onnx.helper.make_node(\n 'DepthToSpace',\n inputs=['x'],\n outputs=['y'],\n blocksize=2,\n mode='CRD'\n)\n\n# (1, 8, 2, 3) input tensor\nx = np.array([[[[0., 1., 2.],\n [3., 4., 5.]],\n [[9., 10., 11.],\n [12., 13., 14.]],\n [[18., 19., 20.],\n [21., 22., 23.]],\n [[27., 28., 29.],\n [30., 31., 32.]],\n [[36., 37., 38.],\n [39., 40., 41.]],\n [[45., 46., 47.],\n [48., 49., 50.]],\n [[54., 55., 56.],\n [57., 58., 59.]],\n [[63., 64., 65.],\n [66., 67., 68.]]]]).astype(np.float32)\n\n# (1, 2, 4, 6) output tensor\ny = np.array([[[[0., 9., 1., 10., 2., 11.],\n [18., 27., 19., 28., 20., 29.],\n [3., 12., 4., 13., 5., 14.],\n [21., 30., 22., 31., 23., 32.]],\n [[36., 45., 37., 46., 38., 47.],\n [54., 63., 55., 64., 56., 65.],\n [39., 48., 40., 49., 41., 50.],\n [57., 66., 58., 67., 59., 68.]]]]).astype(np.float32)\nexpect(node, inputs=[x], outputs=[y],\n name='test_depthtospace_crd_mode_example')" + }, + { + "summary": "default_mode_example", + "code": "node = onnx.helper.make_node(\n 'DepthToSpace',\n inputs=['x'],\n outputs=['y'],\n blocksize=2,\n mode='DCR'\n)\n\n# (1, 8, 2, 3) input tensor\nx = np.array([[[[0., 1., 2.],\n [3., 4., 5.]],\n [[9., 10., 11.],\n [12., 13., 14.]],\n [[18., 19., 20.],\n [21., 22., 23.]],\n [[27., 28., 29.],\n [30., 31., 32.]],\n [[36., 37., 38.],\n [39., 40., 41.]],\n [[45., 46., 47.],\n [48., 49., 50.]],\n [[54., 55., 56.],\n [57., 58., 59.]],\n [[63., 64., 65.],\n [66., 67., 68.]]]]).astype(np.float32)\n\n# (1, 2, 4, 6) output tensor\ny = np.array([[[[0., 18., 1., 19., 2., 20.],\n [36., 54., 37., 55., 38., 56.],\n [3., 21., 4., 22., 5., 23.],\n [39., 57., 40., 58., 41., 59.]],\n [[9., 27., 10., 28., 11., 29.],\n [45., 63., 46., 64., 47., 65.],\n [12., 30., 13., 31., 14., 32.],\n [48., 66., 49., 67., 50., 68.]]]]).astype(np.float32)\nexpect(node, inputs=[x], outputs=[y],\n name='test_depthtospace_example')" + } + ] + }, + { + "name": "DepthToSpace", + "module": "ai.onnx", + "version": 11, + "support_level": "common", + "description": "DepthToSpace rearranges (permutes) data from depth into blocks of spatial data.\nThis is the reverse transformation of SpaceToDepth. More specifically, this op outputs a copy of\nthe input tensor where values from the depth dimension are moved in spatial blocks to the height\nand width dimensions. By default, `mode` = `DCR`.\nIn the DCR mode, elements along the depth dimension from the input tensor are rearranged in the\nfollowing order: depth, column, and then row. The output y is computed from the input x as below:\n\nb, c, h, w = x.shape\n\ntmp = np.reshape(x, [b, blocksize, blocksize, c // (blocksize**2), h, w])\n\ntmp = np.transpose(tmp, [0, 3, 4, 1, 5, 2])\n\ny = np.reshape(tmp, [b, c // (blocksize**2), h * blocksize, w * blocksize])\n\n\nIn the CRD mode, elements along the depth dimension from the input tensor are rearranged in the\nfollowing order: column, row, and the depth. The output y is computed from the input x as below:\n\nb, c, h, w = x.shape\n\ntmp = np.reshape(x, [b, c // (blocksize ** 2), blocksize, blocksize, h, w])\n\ntmp = np.transpose(tmp, [0, 1, 4, 2, 5, 3])\n\ny = np.reshape(tmp, [b, c // (blocksize ** 2), h * blocksize, w * blocksize])\n\n", + "attributes": [ + { + "name": "blocksize", + "type": "int64", + "required": true, + "description": "Blocks of [blocksize, blocksize] are moved." + }, + { + "name": "mode", + "type": "string", + "required": false, + "default": "DCR", + "description": "DCR (default) for depth-column-row order re-arrangement. Use CRD for column-row-depth order." + } + ], + "inputs": [ + { + "name": "input", + "type": "T", + "description": "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." + } + ], + "min_input": 1, + "max_input": 1, + "outputs": [ + { + "name": "output", + "type": "T", + "description": "Output tensor of [N, C/(blocksize * blocksize), H * blocksize, W * blocksize]." + } + ], + "min_output": 1, + "max_output": 1, + "type_constraints": [ + { + "description": "Constrain input and output types to all tensor types.", + "type_param_str": "T", + "allowed_type_strs": [ + "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)" + ] + } + ], + "examples": [ + { + "summary": "crd_mode_example", + "code": "node = onnx.helper.make_node(\n 'DepthToSpace',\n inputs=['x'],\n outputs=['y'],\n blocksize=2,\n mode='CRD'\n)\n\n# (1, 8, 2, 3) input tensor\nx = np.array([[[[0., 1., 2.],\n [3., 4., 5.]],\n [[9., 10., 11.],\n [12., 13., 14.]],\n [[18., 19., 20.],\n [21., 22., 23.]],\n [[27., 28., 29.],\n [30., 31., 32.]],\n [[36., 37., 38.],\n [39., 40., 41.]],\n [[45., 46., 47.],\n [48., 49., 50.]],\n [[54., 55., 56.],\n [57., 58., 59.]],\n [[63., 64., 65.],\n [66., 67., 68.]]]]).astype(np.float32)\n\n# (1, 2, 4, 6) output tensor\ny = np.array([[[[0., 9., 1., 10., 2., 11.],\n [18., 27., 19., 28., 20., 29.],\n [3., 12., 4., 13., 5., 14.],\n [21., 30., 22., 31., 23., 32.]],\n [[36., 45., 37., 46., 38., 47.],\n [54., 63., 55., 64., 56., 65.],\n [39., 48., 40., 49., 41., 50.],\n [57., 66., 58., 67., 59., 68.]]]]).astype(np.float32)\nexpect(node, inputs=[x], outputs=[y],\n name='test_depthtospace_crd_mode_example')" + }, + { + "summary": "default_mode_example", + "code": "node = onnx.helper.make_node(\n 'DepthToSpace',\n inputs=['x'],\n outputs=['y'],\n blocksize=2,\n mode='DCR'\n)\n\n# (1, 8, 2, 3) input tensor\nx = np.array([[[[0., 1., 2.],\n [3., 4., 5.]],\n [[9., 10., 11.],\n [12., 13., 14.]],\n [[18., 19., 20.],\n [21., 22., 23.]],\n [[27., 28., 29.],\n [30., 31., 32.]],\n [[36., 37., 38.],\n [39., 40., 41.]],\n [[45., 46., 47.],\n [48., 49., 50.]],\n [[54., 55., 56.],\n [57., 58., 59.]],\n [[63., 64., 65.],\n [66., 67., 68.]]]]).astype(np.float32)\n\n# (1, 2, 4, 6) output tensor\ny = np.array([[[[0., 18., 1., 19., 2., 20.],\n [36., 54., 37., 55., 38., 56.],\n [3., 21., 4., 22., 5., 23.],\n [39., 57., 40., 58., 41., 59.]],\n [[9., 27., 10., 28., 11., 29.],\n [45., 63., 46., 64., 47., 65.],\n [12., 30., 13., 31., 14., 32.],\n [48., 66., 49., 67., 50., 68.]]]]).astype(np.float32)\nexpect(node, inputs=[x], outputs=[y],\n name='test_depthtospace_example')" + } + ] + }, + { + "name": "DepthToSpace", + "module": "ai.onnx", + "version": 13, + "support_level": "common", + "description": "DepthToSpace rearranges (permutes) data from depth into blocks of spatial data.\nThis is the reverse transformation of SpaceToDepth. More specifically, this op outputs a copy of\nthe input tensor where values from the depth dimension are moved in spatial blocks to the height\nand width dimensions. By default, `mode` = `DCR`.\nIn the DCR mode, elements along the depth dimension from the input tensor are rearranged in the\nfollowing order: depth, column, and then row. The output y is computed from the input x as below:\n\nb, c, h, w = x.shape\n\ntmp = np.reshape(x, [b, blocksize, blocksize, c // (blocksize**2), h, w])\n\ntmp = np.transpose(tmp, [0, 3, 4, 1, 5, 2])\n\ny = np.reshape(tmp, [b, c // (blocksize**2), h * blocksize, w * blocksize])\n\n\nIn the CRD mode, elements along the depth dimension from the input tensor are rearranged in the\nfollowing order: column, row, and the depth. The output y is computed from the input x as below:\n\nb, c, h, w = x.shape\n\ntmp = np.reshape(x, [b, c // (blocksize ** 2), blocksize, blocksize, h, w])\n\ntmp = np.transpose(tmp, [0, 1, 4, 2, 5, 3])\n\ny = np.reshape(tmp, [b, c // (blocksize ** 2), h * blocksize, w * blocksize])\n\n", + "attributes": [ + { + "name": "blocksize", + "type": "int64", + "required": true, + "description": "Blocks of [blocksize, blocksize] are moved." + }, + { + "name": "mode", + "type": "string", + "required": false, + "default": "DCR", + "description": "DCR (default) for depth-column-row order re-arrangement. Use CRD for column-row-depth order." + } + ], + "inputs": [ + { + "name": "input", + "type": "T", + "description": "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." + } + ], + "min_input": 1, + "max_input": 1, + "outputs": [ + { + "name": "output", + "type": "T", + "description": "Output tensor of [N, C/(blocksize * blocksize), H * blocksize, W * blocksize]." + } + ], + "min_output": 1, + "max_output": 1, + "type_constraints": [ + { + "description": "Constrain input and output types to all tensor types.", + "type_param_str": "T", + "allowed_type_strs": [ + "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)" + ] + } + ], + "examples": [ + { + "summary": "crd_mode_example", + "code": "node = onnx.helper.make_node(\n 'DepthToSpace',\n inputs=['x'],\n outputs=['y'],\n blocksize=2,\n mode='CRD'\n)\n\n# (1, 8, 2, 3) input tensor\nx = np.array([[[[0., 1., 2.],\n [3., 4., 5.]],\n [[9., 10., 11.],\n [12., 13., 14.]],\n [[18., 19., 20.],\n [21., 22., 23.]],\n [[27., 28., 29.],\n [30., 31., 32.]],\n [[36., 37., 38.],\n [39., 40., 41.]],\n [[45., 46., 47.],\n [48., 49., 50.]],\n [[54., 55., 56.],\n [57., 58., 59.]],\n [[63., 64., 65.],\n [66., 67., 68.]]]]).astype(np.float32)\n\n# (1, 2, 4, 6) output tensor\ny = np.array([[[[0., 9., 1., 10., 2., 11.],\n [18., 27., 19., 28., 20., 29.],\n [3., 12., 4., 13., 5., 14.],\n [21., 30., 22., 31., 23., 32.]],\n [[36., 45., 37., 46., 38., 47.],\n [54., 63., 55., 64., 56., 65.],\n [39., 48., 40., 49., 41., 50.],\n [57., 66., 58., 67., 59., 68.]]]]).astype(np.float32)\nexpect(node, inputs=[x], outputs=[y],\n name='test_depthtospace_crd_mode_example')" + }, + { + "summary": "default_mode_example", + "code": "node = onnx.helper.make_node(\n 'DepthToSpace',\n inputs=['x'],\n outputs=['y'],\n blocksize=2,\n mode='DCR'\n)\n\n# (1, 8, 2, 3) input tensor\nx = np.array([[[[0., 1., 2.],\n [3., 4., 5.]],\n [[9., 10., 11.],\n [12., 13., 14.]],\n [[18., 19., 20.],\n [21., 22., 23.]],\n [[27., 28., 29.],\n [30., 31., 32.]],\n [[36., 37., 38.],\n [39., 40., 41.]],\n [[45., 46., 47.],\n [48., 49., 50.]],\n [[54., 55., 56.],\n [57., 58., 59.]],\n [[63., 64., 65.],\n [66., 67., 68.]]]]).astype(np.float32)\n\n# (1, 2, 4, 6) output tensor\ny = np.array([[[[0., 18., 1., 19., 2., 20.],\n [36., 54., 37., 55., 38., 56.],\n [3., 21., 4., 22., 5., 23.],\n [39., 57., 40., 58., 41., 59.]],\n [[9., 27., 10., 28., 11., 29.],\n [45., 63., 46., 64., 47., 65.],\n [12., 30., 13., 31., 14., 32.],\n [48., 66., 49., 67., 50., 68.]]]]).astype(np.float32)\nexpect(node, inputs=[x], outputs=[y],\n name='test_depthtospace_example')" + } + ] + }, + { + "name": "DequantizeLinear", + "module": "ai.onnx", + "version": 10, + "support_level": "common", + "description": "The linear dequantization operator. It consumes a quantized tensor, a scale, a zero point to compute the full precision tensor.\nThe dequantization formula is y = (x - x_zero_point) * x_scale. 'x_scale' and 'x_zero_point' must have same shape.\n'x_zero_point' and 'x' must have same type. 'x' and 'y' must have same shape. In the case of dequantizing int32,\nthere's no zero point (zero point is supposed to be 0).\n", + "inputs": [ + { + "name": "x", + "type": "T", + "description": "N-D quantized input tensor to be de-quantized." + }, + { + "name": "x_scale", + "type": "tensor(float)", + "description": "Scale for input 'x'. It's a scalar, which means a per-tensor/layer quantization." + }, + { + "name": "x_zero_point", + "type": "T", + "option": "optional", + "description": "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." + } + ], + "min_input": 2, + "max_input": 3, + "outputs": [ + { + "name": "y", + "type": "tensor(float)", + "description": "N-D full precision output tensor. It has same shape as input 'x'." + } + ], + "min_output": 1, + "max_output": 1, + "inputs_range": "2 - 3", + "type_constraints": [ + { + "description": "Constrain 'x_zero_point' and 'x' to 8-bit/32-bit integer tensor.", + "type_param_str": "T", + "allowed_type_strs": [ + "tensor(int8)", + "tensor(uint8)", + "tensor(int32)" + ] + } + ], + "examples": [ + { + "summary": "axis", + "code": "node = onnx.helper.make_node('DequantizeLinear',\n inputs=['x', 'x_scale', 'x_zero_point'],\n outputs=['y'],)\n\n# 1-D tensor zero point and scale of size equal to axis 1 of the input tensor\nx = np.array([[[[3, 89],\n [34, 200],\n [74, 59]],\n\n [[5, 24],\n [24, 87],\n [32, 13]],\n\n [[245, 99],\n [4, 142],\n [121, 102]], ], ], dtype=np.uint8)\nx_scale = np.array([2, 4, 5], dtype=np.float32)\nx_zero_point = np.array([84, 24, 196], dtype=np.uint8)\ny = (x.astype(np.float32) - x_zero_point.reshape(1, 3, 1, 1).astype(np.float32)) * x_scale.reshape(1, 3, 1, 1)\n\nexpect(node, inputs=[x, x_scale, x_zero_point], outputs=[y],\n name='test_dequantizelinear_axis')" + }, + { + "summary": "dequantizelinear", + "code": "node = onnx.helper.make_node('DequantizeLinear',\n inputs=['x', 'x_scale', 'x_zero_point'],\n outputs=['y'],)\n\n# scalar zero point and scale\nx = np.array([0, 3, 128, 255]).astype(np.uint8)\nx_scale = np.float32(2)\nx_zero_point = np.uint8(128)\ny = np.array([-256, -250, 0, 254], dtype=np.float32)\n\nexpect(node, inputs=[x, x_scale, x_zero_point], outputs=[y],\n name='test_dequantizelinear')" + } + ] + }, + { + "name": "DequantizeLinear", + "module": "ai.onnx", + "version": 13, + "support_level": "common", + "description": "The linear dequantization operator. It consumes a quantized tensor, a scale, and a zero point to compute the full precision tensor.\nThe 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\nfor per-tensor / per layer quantization, or a 1-D tensor for per-axis quantizations.\n'x_zero_point' and 'x' must have same type. 'x' and 'y' must have same shape. In the case of dequantizing int32,\nthere's no zero point (zero point is supposed to be 0).\n", + "attributes": [ + { + "name": "axis", + "type": "int64", + "required": false, + "default": 1, + "description": "(Optional) The axis of the dequantizing dimension of the input tensor. Negative value means counting dimensions from the back. Accepted range is [-r, r-1] where r = rank(input). If both x_scale and x_zero_point are scalars, axis is ignored." + } + ], + "inputs": [ + { + "name": "x", + "type": "T", + "description": "N-D quantized input tensor to be de-quantized." + }, + { + "name": "x_scale", + "type": "tensor(float)", + "description": "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." + }, + { + "name": "x_zero_point", + "type": "T", + "option": "optional", + "description": "Zero point for input 'x'. It can be a scalar, which means a per-tensor/layer dequantization, or a 1-D tensor for per-axis dequantization. It's optional. 0 is the default value when it's not specified." + } + ], + "min_input": 2, + "max_input": 3, + "outputs": [ + { + "name": "y", + "type": "tensor(float)", + "description": "N-D full precision output tensor. It has same shape as input 'x'." + } + ], + "min_output": 1, + "max_output": 1, + "inputs_range": "2 - 3", + "type_constraints": [ + { + "description": "Constrain 'x_zero_point' and 'x' to 8-bit/32-bit integer tensor.", + "type_param_str": "T", + "allowed_type_strs": [ + "tensor(int8)", + "tensor(uint8)", + "tensor(int32)" + ] + } + ], + "examples": [ + { + "summary": "axis", + "code": "node = onnx.helper.make_node('DequantizeLinear',\n inputs=['x', 'x_scale', 'x_zero_point'],\n outputs=['y'],)\n\n# 1-D tensor zero point and scale of size equal to axis 1 of the input tensor\nx = np.array([[[[3, 89],\n [34, 200],\n [74, 59]],\n\n [[5, 24],\n [24, 87],\n [32, 13]],\n\n [[245, 99],\n [4, 142],\n [121, 102]], ], ], dtype=np.uint8)\nx_scale = np.array([2, 4, 5], dtype=np.float32)\nx_zero_point = np.array([84, 24, 196], dtype=np.uint8)\ny = (x.astype(np.float32) - x_zero_point.reshape(1, 3, 1, 1).astype(np.float32)) * x_scale.reshape(1, 3, 1, 1)\n\nexpect(node, inputs=[x, x_scale, x_zero_point], outputs=[y],\n name='test_dequantizelinear_axis')" + }, + { + "summary": "dequantizelinear", + "code": "node = onnx.helper.make_node('DequantizeLinear',\n inputs=['x', 'x_scale', 'x_zero_point'],\n outputs=['y'],)\n\n# scalar zero point and scale\nx = np.array([0, 3, 128, 255]).astype(np.uint8)\nx_scale = np.float32(2)\nx_zero_point = np.uint8(128)\ny = np.array([-256, -250, 0, 254], dtype=np.float32)\n\nexpect(node, inputs=[x, x_scale, x_zero_point], outputs=[y],\n name='test_dequantizelinear')" + } + ] + }, + { + "name": "Det", + "module": "ai.onnx", + "version": 11, + "support_level": "common", + "description": "Det calculates determinant of a square matrix or batches of square matrices.\nDet takes one input tensor of shape `[*, M, M]`, where `*` is zero or more batch dimensions,\nand the inner-most 2 dimensions form square matrices.\nThe output is a tensor of shape `[*]`, containing the determinants of all input submatrices.\ne.g., When the input is 2-D, the output is a scalar(shape is empty: `[]`).\n", + "inputs": [ + { + "name": "X", + "type": "T", + "description": "Input tensor" + } + ], + "min_input": 1, + "max_input": 1, + "outputs": [ + { + "name": "Y", + "type": "T", + "description": "Output tensor" + } + ], + "min_output": 1, + "max_output": 1, + "type_constraints": [ + { + "description": "Constrain input and output types to floating-point tensors.", + "type_param_str": "T", + "allowed_type_strs": [ + "tensor(float16)", + "tensor(float)", + "tensor(double)" + ] + } + ], + "examples": [ + { + "summary": "2d", + "code": "node = onnx.helper.make_node(\n 'Det',\n inputs=['x'],\n outputs=['y'],\n)\n\nx = np.arange(4).reshape(2, 2).astype(np.float32)\ny = np.linalg.det(x) # expect -2\nexpect(node, inputs=[x], outputs=[y],\n name='test_det_2d')" + }, + { + "summary": "nd", + "code": "node = onnx.helper.make_node(\n 'Det',\n inputs=['x'],\n outputs=['y'],\n)\n\nx = np.array([[[1, 2], [3, 4]], [[1, 2], [2, 1]], [[1, 3], [3, 1]]]).astype(np.float32)\ny = np.linalg.det(x) # expect array([-2., -3., -8.])\nexpect(node, inputs=[x], outputs=[y],\n name='test_det_nd')" + } + ] + }, + { + "name": "DictVectorizer", + "module": "ai.onnx.ml", + "version": 1, + "support_level": "common", + "description": "Uses an index mapping to convert a dictionary to an array.
\n Given a dictionary, each key is looked up in the vocabulary attribute corresponding to\n the key type. The index into the vocabulary array at which the key is found is then\n used to index the output 1-D tensor 'Y' and insert into it the value found in the dictionary 'X'.
\n The key type of the input map must correspond to the element type of the defined vocabulary attribute.\n Therefore, the output array will be equal in length to the index mapping vector parameter.\n All keys in the input dictionary must be present in the index mapping vector.\n For each item in the input dictionary, insert its value in the output array.\n Any keys not present in the input dictionary, will be zero in the output array.
\n For example: if the ``string_vocabulary`` parameter is set to ``[\"a\", \"c\", \"b\", \"z\"]``,\n then an input of ``{\"a\": 4, \"c\": 8}`` will produce an output of ``[4, 8, 0, 0]``.\n ", + "attributes": [ + { + "name": "int64_vocabulary", + "type": "int64[]", + "required": false, + "description": "An integer vocabulary array.
One and only one of the vocabularies must be defined." + }, + { + "name": "string_vocabulary", + "type": "string[]", + "required": false, + "description": "A string vocabulary array.
One and only one of the vocabularies must be defined." + } + ], + "inputs": [ + { + "name": "X", + "type": "T1", + "description": "A dictionary." + } + ], + "min_input": 1, + "max_input": 1, + "outputs": [ + { + "name": "Y", + "type": "T2", + "description": "A 1-D tensor holding values from the input dictionary." + } + ], + "min_output": 1, + "max_output": 1, + "type_constraints": [ + { + "description": "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.", + "type_param_str": "T1", + "allowed_type_strs": [ + "map(string, int64)", + "map(int64, string)", + "map(int64, float)", + "map(int64, double)", + "map(string, float)", + "map(string, double)" + ] + }, + { + "description": "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.", + "type_param_str": "T2", + "allowed_type_strs": [ + "tensor(int64)", + "tensor(float)", + "tensor(double)", + "tensor(string)" + ] + } + ] + }, + { + "name": "Div", + "module": "ai.onnx", + "version": 1, + "support_level": "common", + "description": "Performs element-wise binary division (with limited broadcast support).\n\nIf necessary the right-hand-side argument will be broadcasted to match the\nshape of left-hand-side argument. When broadcasting is specified, the second\ntensor can either be of element size 1 (including a scalar tensor and any\ntensor with rank equal to or smaller than the first tensor), or having its\nshape as a contiguous subset of the first tensor's shape. The starting of the\nmutually equal shape is specified by the argument \"axis\", and if it is not set,\nsuffix matching is assumed. 1-dim expansion doesn't work yet.\n\nFor example, the following tensor shapes are supported (with broadcast=1):\n\n shape(A) = (2, 3, 4, 5), shape(B) = (,), i.e. B is a scalar tensor\n shape(A) = (2, 3, 4, 5), shape(B) = (1, 1), i.e. B is an 1-element tensor\n shape(A) = (2, 3, 4, 5), shape(B) = (5,)\n shape(A) = (2, 3, 4, 5), shape(B) = (4, 5)\n shape(A) = (2, 3, 4, 5), shape(B) = (3, 4), with axis=1\n shape(A) = (2, 3, 4, 5), shape(B) = (2), with axis=0\n\nAttribute `broadcast=1` needs to be passed to enable broadcasting.\n", + "attributes": [ + { + "name": "axis", + "type": "int64", + "required": false, + "description": "If set, defines the broadcast dimensions. See doc for details." + }, + { + "name": "broadcast", + "type": "int64", + "required": false, + "description": "Pass 1 to enable broadcasting" + }, + { + "name": "consumed_inputs", + "type": "int64[]", + "required": false, + "description": "legacy optimization attribute." + } + ], + "inputs": [ + { + "name": "A", + "type": "T", + "description": "First operand, should share the type with the second operand." + }, + { + "name": "B", + "type": "T", + "description": "Second operand. With broadcasting can be of smaller size than A. If broadcasting is disabled it should be of the same size." + } + ], + "min_input": 2, + "max_input": 2, + "outputs": [ + { + "name": "C", + "type": "T", + "description": "Result, has same dimensions and type as A" + } + ], + "min_output": 1, + "max_output": 1, + "type_constraints": [ + { + "description": "Constrain input and output types to float tensors.", + "type_param_str": "T", + "allowed_type_strs": [ + "tensor(float16)", + "tensor(float)", + "tensor(double)" + ] + } + ], + "examples": [ + { + "summary": "div", + "code": "node = onnx.helper.make_node(\n 'Div',\n inputs=['x', 'y'],\n outputs=['z'],\n)\n\nx = np.array([3, 4]).astype(np.float32)\ny = np.array([1, 2]).astype(np.float32)\nz = x / y # expected output [3., 2.]\nexpect(node, inputs=[x, y], outputs=[z],\n name='test_div_example')\n\nx = np.random.randn(3, 4, 5).astype(np.float32)\ny = np.random.rand(3, 4, 5).astype(np.float32) + 1.0\nz = x / y\nexpect(node, inputs=[x, y], outputs=[z],\n name='test_div')\n\nx = np.random.randint(24, size=(3, 4, 5), dtype=np.uint8)\ny = np.random.randint(24, size=(3, 4, 5), dtype=np.uint8) + 1\nz = x // y\nexpect(node, inputs=[x, y], outputs=[z],\n name='test_div_uint8')" + }, + { + "summary": "div_broadcast", + "code": "node = onnx.helper.make_node(\n 'Div',\n inputs=['x', 'y'],\n outputs=['z'],\n)\n\nx = np.random.randn(3, 4, 5).astype(np.float32)\ny = np.random.rand(5).astype(np.float32) + 1.0\nz = x / y\nexpect(node, inputs=[x, y], outputs=[z],\n name='test_div_bcast')" + } + ] + }, + { + "name": "Div", + "module": "ai.onnx", + "version": 6, + "support_level": "common", + "description": "Performs element-wise binary division (with limited broadcast support).\n\nIf necessary the right-hand-side argument will be broadcasted to match the\nshape of left-hand-side argument. When broadcasting is specified, the second\ntensor can either be of element size 1 (including a scalar tensor and any\ntensor with rank equal to or smaller than the first tensor), or having its\nshape as a contiguous subset of the first tensor's shape. The starting of the\nmutually equal shape is specified by the argument \"axis\", and if it is not set,\nsuffix matching is assumed. 1-dim expansion doesn't work yet.\n\nFor example, the following tensor shapes are supported (with broadcast=1):\n\n shape(A) = (2, 3, 4, 5), shape(B) = (,), i.e. B is a scalar tensor\n shape(A) = (2, 3, 4, 5), shape(B) = (1, 1), i.e. B is an 1-element tensor\n shape(A) = (2, 3, 4, 5), shape(B) = (5,)\n shape(A) = (2, 3, 4, 5), shape(B) = (4, 5)\n shape(A) = (2, 3, 4, 5), shape(B) = (3, 4), with axis=1\n shape(A) = (2, 3, 4, 5), shape(B) = (2), with axis=0\n\nAttribute `broadcast=1` needs to be passed to enable broadcasting.\n", + "attributes": [ + { + "name": "axis", + "type": "int64", + "required": false, + "description": "If set, defines the broadcast dimensions. See doc for details." + }, + { + "name": "broadcast", + "type": "int64", + "required": false, + "description": "Pass 1 to enable broadcasting" + } + ], + "inputs": [ + { + "name": "A", + "type": "T", + "description": "First operand, should share the type with the second operand." + }, + { + "name": "B", + "type": "T", + "description": "Second operand. With broadcasting can be of smaller size than A. If broadcasting is disabled it should be of the same size." + } + ], + "min_input": 2, + "max_input": 2, + "outputs": [ + { + "name": "C", + "type": "T", + "description": "Result, has same dimensions and type as A" + } + ], + "min_output": 1, + "max_output": 1, + "type_constraints": [ + { + "description": "Constrain input and output types to high-precision numeric tensors.", + "type_param_str": "T", + "allowed_type_strs": [ + "tensor(uint32)", + "tensor(uint64)", + "tensor(int32)", + "tensor(int64)", + "tensor(float16)", + "tensor(float)", + "tensor(double)" + ] + } + ], + "examples": [ + { + "summary": "div", + "code": "node = onnx.helper.make_node(\n 'Div',\n inputs=['x', 'y'],\n outputs=['z'],\n)\n\nx = np.array([3, 4]).astype(np.float32)\ny = np.array([1, 2]).astype(np.float32)\nz = x / y # expected output [3., 2.]\nexpect(node, inputs=[x, y], outputs=[z],\n name='test_div_example')\n\nx = np.random.randn(3, 4, 5).astype(np.float32)\ny = np.random.rand(3, 4, 5).astype(np.float32) + 1.0\nz = x / y\nexpect(node, inputs=[x, y], outputs=[z],\n name='test_div')\n\nx = np.random.randint(24, size=(3, 4, 5), dtype=np.uint8)\ny = np.random.randint(24, size=(3, 4, 5), dtype=np.uint8) + 1\nz = x // y\nexpect(node, inputs=[x, y], outputs=[z],\n name='test_div_uint8')" + }, + { + "summary": "div_broadcast", + "code": "node = onnx.helper.make_node(\n 'Div',\n inputs=['x', 'y'],\n outputs=['z'],\n)\n\nx = np.random.randn(3, 4, 5).astype(np.float32)\ny = np.random.rand(5).astype(np.float32) + 1.0\nz = x / y\nexpect(node, inputs=[x, y], outputs=[z],\n name='test_div_bcast')" + } + ] + }, + { + "name": "Div", + "module": "ai.onnx", + "version": 7, + "support_level": "common", + "description": "Performs element-wise binary division (with Numpy-style broadcasting support).\n\nThis operator supports **multidirectional (i.e., Numpy-style) broadcasting**; for more details please check [the doc](https://github.com/onnx/onnx/blob/master/docs/Broadcasting.md).\n", + "inputs": [ + { + "name": "A", + "type": "T", + "description": "First operand." + }, + { + "name": "B", + "type": "T", + "description": "Second operand." + } + ], + "min_input": 2, + "max_input": 2, + "outputs": [ + { + "name": "C", + "type": "T", + "description": "Result, has same element type as two inputs" + } + ], + "min_output": 1, + "max_output": 1, + "type_constraints": [ + { + "description": "Constrain input and output types to high-precision numeric tensors.", + "type_param_str": "T", + "allowed_type_strs": [ + "tensor(uint32)", + "tensor(uint64)", + "tensor(int32)", + "tensor(int64)", + "tensor(float16)", + "tensor(float)", + "tensor(double)" + ] + } + ], + "examples": [ + { + "summary": "div", + "code": "node = onnx.helper.make_node(\n 'Div',\n inputs=['x', 'y'],\n outputs=['z'],\n)\n\nx = np.array([3, 4]).astype(np.float32)\ny = np.array([1, 2]).astype(np.float32)\nz = x / y # expected output [3., 2.]\nexpect(node, inputs=[x, y], outputs=[z],\n name='test_div_example')\n\nx = np.random.randn(3, 4, 5).astype(np.float32)\ny = np.random.rand(3, 4, 5).astype(np.float32) + 1.0\nz = x / y\nexpect(node, inputs=[x, y], outputs=[z],\n name='test_div')\n\nx = np.random.randint(24, size=(3, 4, 5), dtype=np.uint8)\ny = np.random.randint(24, size=(3, 4, 5), dtype=np.uint8) + 1\nz = x // y\nexpect(node, inputs=[x, y], outputs=[z],\n name='test_div_uint8')" + }, + { + "summary": "div_broadcast", + "code": "node = onnx.helper.make_node(\n 'Div',\n inputs=['x', 'y'],\n outputs=['z'],\n)\n\nx = np.random.randn(3, 4, 5).astype(np.float32)\ny = np.random.rand(5).astype(np.float32) + 1.0\nz = x / y\nexpect(node, inputs=[x, y], outputs=[z],\n name='test_div_bcast')" + } + ] + }, + { + "name": "Div", + "module": "ai.onnx", + "version": 13, + "support_level": "common", + "description": "Performs element-wise binary division (with Numpy-style broadcasting support).\n\nThis operator supports **multidirectional (i.e., Numpy-style) broadcasting**; for more details please check [the doc](https://github.com/onnx/onnx/blob/master/docs/Broadcasting.md).\n", + "inputs": [ + { + "name": "A", + "type": "T", + "description": "First operand." + }, + { + "name": "B", + "type": "T", + "description": "Second operand." + } + ], + "min_input": 2, + "max_input": 2, + "outputs": [ + { + "name": "C", + "type": "T", + "description": "Result, has same element type as two inputs" + } + ], + "min_output": 1, + "max_output": 1, + "type_constraints": [ + { + "description": "Constrain input and output types to high-precision numeric tensors.", + "type_param_str": "T", + "allowed_type_strs": [ + "tensor(uint32)", + "tensor(uint64)", + "tensor(int32)", + "tensor(int64)", + "tensor(float16)", + "tensor(float)", + "tensor(double)", + "tensor(bfloat16)" + ] + } + ], + "examples": [ + { + "summary": "div", + "code": "node = onnx.helper.make_node(\n 'Div',\n inputs=['x', 'y'],\n outputs=['z'],\n)\n\nx = np.array([3, 4]).astype(np.float32)\ny = np.array([1, 2]).astype(np.float32)\nz = x / y # expected output [3., 2.]\nexpect(node, inputs=[x, y], outputs=[z],\n name='test_div_example')\n\nx = np.random.randn(3, 4, 5).astype(np.float32)\ny = np.random.rand(3, 4, 5).astype(np.float32) + 1.0\nz = x / y\nexpect(node, inputs=[x, y], outputs=[z],\n name='test_div')\n\nx = np.random.randint(24, size=(3, 4, 5), dtype=np.uint8)\ny = np.random.randint(24, size=(3, 4, 5), dtype=np.uint8) + 1\nz = x // y\nexpect(node, inputs=[x, y], outputs=[z],\n name='test_div_uint8')" + }, + { + "summary": "div_broadcast", + "code": "node = onnx.helper.make_node(\n 'Div',\n inputs=['x', 'y'],\n outputs=['z'],\n)\n\nx = np.random.randn(3, 4, 5).astype(np.float32)\ny = np.random.rand(5).astype(np.float32) + 1.0\nz = x / y\nexpect(node, inputs=[x, y], outputs=[z],\n name='test_div_bcast')" + } + ] + }, + { + "name": "Div", + "module": "ai.onnx", + "version": 14, + "support_level": "common", + "description": "Performs element-wise binary division (with Numpy-style broadcasting support).\n\nThis operator supports **multidirectional (i.e., Numpy-style) broadcasting**; for more details please check [the doc](https://github.com/onnx/onnx/blob/master/docs/Broadcasting.md).\n\n(Opset 14 change): Extend supported types to include uint8, int8, uint16, and int16.\n", + "inputs": [ + { + "name": "A", + "type": "T", + "description": "First operand." + }, + { + "name": "B", + "type": "T", + "description": "Second operand." + } + ], + "min_input": 2, + "max_input": 2, + "outputs": [ + { + "name": "C", + "type": "T", + "description": "Result, has same element type as two inputs" + } + ], + "min_output": 1, + "max_output": 1, + "type_constraints": [ + { + "description": "Constrain input and output types to all numeric tensors.", + "type_param_str": "T", + "allowed_type_strs": [ + "tensor(uint8)", + "tensor(uint16)", + "tensor(uint32)", + "tensor(uint64)", + "tensor(int8)", + "tensor(int16)", + "tensor(int32)", + "tensor(int64)", + "tensor(float16)", + "tensor(float)", + "tensor(double)", + "tensor(bfloat16)" + ] + } + ], + "examples": [ + { + "summary": "div", + "code": "node = onnx.helper.make_node(\n 'Div',\n inputs=['x', 'y'],\n outputs=['z'],\n)\n\nx = np.array([3, 4]).astype(np.float32)\ny = np.array([1, 2]).astype(np.float32)\nz = x / y # expected output [3., 2.]\nexpect(node, inputs=[x, y], outputs=[z],\n name='test_div_example')\n\nx = np.random.randn(3, 4, 5).astype(np.float32)\ny = np.random.rand(3, 4, 5).astype(np.float32) + 1.0\nz = x / y\nexpect(node, inputs=[x, y], outputs=[z],\n name='test_div')\n\nx = np.random.randint(24, size=(3, 4, 5), dtype=np.uint8)\ny = np.random.randint(24, size=(3, 4, 5), dtype=np.uint8) + 1\nz = x // y\nexpect(node, inputs=[x, y], outputs=[z],\n name='test_div_uint8')" + }, + { + "summary": "div_broadcast", + "code": "node = onnx.helper.make_node(\n 'Div',\n inputs=['x', 'y'],\n outputs=['z'],\n)\n\nx = np.random.randn(3, 4, 5).astype(np.float32)\ny = np.random.rand(5).astype(np.float32) + 1.0\nz = x / y\nexpect(node, inputs=[x, y], outputs=[z],\n name='test_div_bcast')" + } + ] + }, + { + "name": "Dropout", + "module": "ai.onnx", + "version": 1, + "support_level": "common", + "description": "Dropout takes one input data (Tensor) and produces two Tensor outputs,\noutput (Tensor) and mask (Tensor). Depending on whether it is in\ntest mode or not, the output Y will either be a random dropout, or a simple\ncopy of the input. Note that our implementation of Dropout does scaling in\nthe training phase, so during testing nothing needs to be done.\n", + "attributes": [ + { + "name": "consumed_inputs", + "type": "int64[]", + "required": false, + "description": "legacy optimization attribute." + }, + { + "name": "is_test", + "type": "int64", + "required": false, + "description": "(int, default 0) if nonzero, run dropout in test mode where the output is simply Y = X." + }, + { + "name": "ratio", + "type": "float32", + "required": false, + "default": 0.5, + "description": "(float, default 0.5) the ratio of random dropout" + } + ], + "inputs": [ + { + "name": "data", + "type": "T", + "description": "The input data as Tensor." + } + ], + "min_input": 1, + "max_input": 1, + "outputs": [ + { + "name": "output", + "type": "T", + "description": "The output." + }, + { + "name": "mask", + "type": "T", + "option": "optional", + "description": "The output mask. If is_test is nonzero, this output is not filled." + } + ], + "min_output": 1, + "max_output": 2, + "outputs_range": "1 - 2", + "type_constraints": [ + { + "description": "Constrain input and output types to float tensors.", + "type_param_str": "T", + "allowed_type_strs": [ + "tensor(float16)", + "tensor(float)", + "tensor(double)" + ] + } + ], + "examples": [ + { + "summary": "default", + "code": "seed = np.int64(0)\nnode = onnx.helper.make_node(\n 'Dropout',\n inputs=['x'],\n outputs=['y'],\n seed=seed\n)\n\nx = np.random.randn(3, 4, 5).astype(np.float32)\ny = dropout(x)\nexpect(node, inputs=[x], outputs=[y], name='test_dropout_default')" + }, + { + "summary": "default_mask", + "code": "seed = np.int64(0)\nnode = onnx.helper.make_node(\n 'Dropout',\n inputs=['x'],\n outputs=['y', 'z'],\n seed=seed\n)\n\nx = np.random.randn(3, 4, 5).astype(np.float32)\ny, z = dropout(x, return_mask=True)\nexpect(node, inputs=[x], outputs=[y, z], name='test_dropout_default_mask')" + }, + { + "summary": "default_mask_ratio", + "code": "seed = np.int64(0)\nnode = onnx.helper.make_node(\n 'Dropout',\n inputs=['x', 'r'],\n outputs=['y', 'z'],\n seed=seed\n)\n\nr = np.float32(0.1)\nx = np.random.randn(3, 4, 5).astype(np.float32)\ny, z = dropout(x, r, return_mask=True)\nexpect(node, inputs=[x, r], outputs=[y, z], name='test_dropout_default_mask_ratio')" + }, + { + "summary": "default_old", + "code": "node = onnx.helper.make_node(\n 'Dropout',\n inputs=['x'],\n outputs=['y'],\n)\n\nx = np.array([-1, 0, 1]).astype(np.float32)\ny = x\nexpect(node, inputs=[x], outputs=[y],\n name='test_dropout_default_old', opset_imports=[helper.make_opsetid(\"\", 11)])" + }, + { + "summary": "default_ratio", + "code": "seed = np.int64(0)\nnode = onnx.helper.make_node(\n 'Dropout',\n inputs=['x', 'r'],\n outputs=['y'],\n seed=seed\n)\n\nr = np.float32(0.1)\nx = np.random.randn(3, 4, 5).astype(np.float32)\ny = dropout(x, r)\nexpect(node, inputs=[x, r], outputs=[y], name='test_dropout_default_ratio')" + }, + { + "summary": "random_old", + "code": "node = onnx.helper.make_node(\n 'Dropout',\n inputs=['x'],\n outputs=['y'],\n ratio=.2,\n)\n\nx = np.random.randn(3, 4, 5).astype(np.float32)\ny = x\nexpect(node, inputs=[x], outputs=[y],\n name='test_dropout_random_old', opset_imports=[helper.make_opsetid(\"\", 11)])" + }, + { + "summary": "training", + "code": "seed = np.int64(0)\nnode = onnx.helper.make_node(\n 'Dropout',\n inputs=['x', 'r', 't'],\n outputs=['y'],\n seed=seed\n)\n\nx = np.random.randn(3, 4, 5).astype(np.float32)\nr = np.float32(0.75)\nt = np.bool_(True)\ny = dropout(x, r, training_mode=t)\nexpect(node, inputs=[x, r, t], outputs=[y], name='test_training_dropout')" + }, + { + "summary": "training_default", + "code": "seed = np.int64(0)\nnode = onnx.helper.make_node(\n 'Dropout',\n inputs=['x', 'r', 't'],\n outputs=['y'],\n seed=seed\n)\n\nx = np.random.randn(3, 4, 5).astype(np.float32)\nr = np.float32(0.5)\nt = np.bool_(True)\ny = dropout(x, r, training_mode=t)\nexpect(node, inputs=[x, r, t], outputs=[y], name='test_training_dropout_default')" + }, + { + "summary": "training_default_ratio_mask", + "code": "seed = np.int64(0)\nnode = onnx.helper.make_node(\n 'Dropout',\n inputs=['x', 'r', 't'],\n outputs=['y', 'z'],\n seed=seed\n)\n\nx = np.random.randn(3, 4, 5).astype(np.float32)\nr = np.float32(0.5)\nt = np.bool_(True)\ny, z = dropout(x, r, training_mode=t, return_mask=True)\nexpect(node, inputs=[x, r, t], outputs=[y, z], name='test_training_dropout_default_mask')" + }, + { + "summary": "training_default_zero_ratio", + "code": "seed = np.int64(0)\nnode = onnx.helper.make_node(\n 'Dropout',\n inputs=['x', 'r', 't'],\n outputs=['y'],\n seed=seed\n)\n\nx = np.random.randn(3, 4, 5).astype(np.float32)\nr = np.float32(0.0)\nt = np.bool_(True)\ny = dropout(x, r, training_mode=t)\nexpect(node, inputs=[x, r, t], outputs=[y], name='test_training_dropout_zero_ratio')" + }, + { + "summary": "training_default_zero_ratio_mask", + "code": "seed = np.int64(0)\nnode = onnx.helper.make_node(\n 'Dropout',\n inputs=['x', 'r', 't'],\n outputs=['y', 'z'],\n seed=seed\n)\n\nx = np.random.randn(3, 4, 5).astype(np.float32)\nr = np.float32(0.0)\nt = np.bool_(True)\ny, z = dropout(x, r, training_mode=t, return_mask=True)\nexpect(node, inputs=[x, r, t], outputs=[y, z], name='test_training_dropout_zero_ratio_mask')" + }, + { + "summary": "training_ratio_mask", + "code": "seed = np.int64(0)\nnode = onnx.helper.make_node(\n 'Dropout',\n inputs=['x', 'r', 't'],\n outputs=['y', 'z'],\n seed=seed\n)\n\nx = np.random.randn(3, 4, 5).astype(np.float32)\nr = np.float32(0.75)\nt = np.bool_(True)\ny, z = dropout(x, r, training_mode=t, return_mask=True)\nexpect(node, inputs=[x, r, t], outputs=[y, z], name='test_training_dropout_mask')" + } + ], + "category": "Dropout" + }, + { + "name": "Dropout", + "module": "ai.onnx", + "version": 6, + "support_level": "common", + "description": "Dropout takes one input data (Tensor) and produces two Tensor outputs,\noutput (Tensor) and mask (Tensor). Depending on whether it is in\ntest mode or not, the output Y will either be a random dropout, or a simple\ncopy of the input. Note that our implementation of Dropout does scaling in\nthe training phase, so during testing nothing needs to be done.\n", + "attributes": [ + { + "name": "is_test", + "type": "int64", + "required": false, + "description": "(int, default 0) if nonzero, run dropout in test mode where the output is simply Y = X." + }, + { + "name": "ratio", + "type": "float32", + "required": false, + "default": 0.5, + "description": "(float, default 0.5) the ratio of random dropout" + } + ], + "inputs": [ + { + "name": "data", + "type": "T", + "description": "The input data as Tensor." + } + ], + "min_input": 1, + "max_input": 1, + "outputs": [ + { + "name": "output", + "type": "T", + "description": "The output." + }, + { + "name": "mask", + "type": "T", + "option": "optional", + "description": "The output mask. If is_test is nonzero, this output is not filled." + } + ], + "min_output": 1, + "max_output": 2, + "outputs_range": "1 - 2", + "type_constraints": [ + { + "description": "Constrain input and output types to float tensors.", + "type_param_str": "T", + "allowed_type_strs": [ + "tensor(float16)", + "tensor(float)", + "tensor(double)" + ] + } + ], + "examples": [ + { + "summary": "default", + "code": "seed = np.int64(0)\nnode = onnx.helper.make_node(\n 'Dropout',\n inputs=['x'],\n outputs=['y'],\n seed=seed\n)\n\nx = np.random.randn(3, 4, 5).astype(np.float32)\ny = dropout(x)\nexpect(node, inputs=[x], outputs=[y], name='test_dropout_default')" + }, + { + "summary": "default_mask", + "code": "seed = np.int64(0)\nnode = onnx.helper.make_node(\n 'Dropout',\n inputs=['x'],\n outputs=['y', 'z'],\n seed=seed\n)\n\nx = np.random.randn(3, 4, 5).astype(np.float32)\ny, z = dropout(x, return_mask=True)\nexpect(node, inputs=[x], outputs=[y, z], name='test_dropout_default_mask')" + }, + { + "summary": "default_mask_ratio", + "code": "seed = np.int64(0)\nnode = onnx.helper.make_node(\n 'Dropout',\n inputs=['x', 'r'],\n outputs=['y', 'z'],\n seed=seed\n)\n\nr = np.float32(0.1)\nx = np.random.randn(3, 4, 5).astype(np.float32)\ny, z = dropout(x, r, return_mask=True)\nexpect(node, inputs=[x, r], outputs=[y, z], name='test_dropout_default_mask_ratio')" + }, + { + "summary": "default_old", + "code": "node = onnx.helper.make_node(\n 'Dropout',\n inputs=['x'],\n outputs=['y'],\n)\n\nx = np.array([-1, 0, 1]).astype(np.float32)\ny = x\nexpect(node, inputs=[x], outputs=[y],\n name='test_dropout_default_old', opset_imports=[helper.make_opsetid(\"\", 11)])" + }, + { + "summary": "default_ratio", + "code": "seed = np.int64(0)\nnode = onnx.helper.make_node(\n 'Dropout',\n inputs=['x', 'r'],\n outputs=['y'],\n seed=seed\n)\n\nr = np.float32(0.1)\nx = np.random.randn(3, 4, 5).astype(np.float32)\ny = dropout(x, r)\nexpect(node, inputs=[x, r], outputs=[y], name='test_dropout_default_ratio')" + }, + { + "summary": "random_old", + "code": "node = onnx.helper.make_node(\n 'Dropout',\n inputs=['x'],\n outputs=['y'],\n ratio=.2,\n)\n\nx = np.random.randn(3, 4, 5).astype(np.float32)\ny = x\nexpect(node, inputs=[x], outputs=[y],\n name='test_dropout_random_old', opset_imports=[helper.make_opsetid(\"\", 11)])" + }, + { + "summary": "training", + "code": "seed = np.int64(0)\nnode = onnx.helper.make_node(\n 'Dropout',\n inputs=['x', 'r', 't'],\n outputs=['y'],\n seed=seed\n)\n\nx = np.random.randn(3, 4, 5).astype(np.float32)\nr = np.float32(0.75)\nt = np.bool_(True)\ny = dropout(x, r, training_mode=t)\nexpect(node, inputs=[x, r, t], outputs=[y], name='test_training_dropout')" + }, + { + "summary": "training_default", + "code": "seed = np.int64(0)\nnode = onnx.helper.make_node(\n 'Dropout',\n inputs=['x', 'r', 't'],\n outputs=['y'],\n seed=seed\n)\n\nx = np.random.randn(3, 4, 5).astype(np.float32)\nr = np.float32(0.5)\nt = np.bool_(True)\ny = dropout(x, r, training_mode=t)\nexpect(node, inputs=[x, r, t], outputs=[y], name='test_training_dropout_default')" + }, + { + "summary": "training_default_ratio_mask", + "code": "seed = np.int64(0)\nnode = onnx.helper.make_node(\n 'Dropout',\n inputs=['x', 'r', 't'],\n outputs=['y', 'z'],\n seed=seed\n)\n\nx = np.random.randn(3, 4, 5).astype(np.float32)\nr = np.float32(0.5)\nt = np.bool_(True)\ny, z = dropout(x, r, training_mode=t, return_mask=True)\nexpect(node, inputs=[x, r, t], outputs=[y, z], name='test_training_dropout_default_mask')" + }, + { + "summary": "training_default_zero_ratio", + "code": "seed = np.int64(0)\nnode = onnx.helper.make_node(\n 'Dropout',\n inputs=['x', 'r', 't'],\n outputs=['y'],\n seed=seed\n)\n\nx = np.random.randn(3, 4, 5).astype(np.float32)\nr = np.float32(0.0)\nt = np.bool_(True)\ny = dropout(x, r, training_mode=t)\nexpect(node, inputs=[x, r, t], outputs=[y], name='test_training_dropout_zero_ratio')" + }, + { + "summary": "training_default_zero_ratio_mask", + "code": "seed = np.int64(0)\nnode = onnx.helper.make_node(\n 'Dropout',\n inputs=['x', 'r', 't'],\n outputs=['y', 'z'],\n seed=seed\n)\n\nx = np.random.randn(3, 4, 5).astype(np.float32)\nr = np.float32(0.0)\nt = np.bool_(True)\ny, z = dropout(x, r, training_mode=t, return_mask=True)\nexpect(node, inputs=[x, r, t], outputs=[y, z], name='test_training_dropout_zero_ratio_mask')" + }, + { + "summary": "training_ratio_mask", + "code": "seed = np.int64(0)\nnode = onnx.helper.make_node(\n 'Dropout',\n inputs=['x', 'r', 't'],\n outputs=['y', 'z'],\n seed=seed\n)\n\nx = np.random.randn(3, 4, 5).astype(np.float32)\nr = np.float32(0.75)\nt = np.bool_(True)\ny, z = dropout(x, r, training_mode=t, return_mask=True)\nexpect(node, inputs=[x, r, t], outputs=[y, z], name='test_training_dropout_mask')" + } + ], + "category": "Dropout" + }, + { + "name": "Dropout", + "module": "ai.onnx", + "version": 7, + "support_level": "common", + "description": "Dropout takes one input data (Tensor) and produces two Tensor outputs,\noutput (Tensor) and mask (Tensor). Depending on whether it is in\ntest mode or not, the output Y will either be a random dropout, or a simple\ncopy of the input. Note that our implementation of Dropout does scaling in\nthe training phase, so during testing nothing needs to be done.\nThis operator has **optional** inputs/outputs. See [the doc](https://github.com/onnx/onnx/blob/master/docs/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.\n", + "attributes": [ + { + "name": "ratio", + "type": "float32", + "required": false, + "default": 0.5, + "description": "The ratio of random dropout" + } + ], + "inputs": [ + { + "name": "data", + "type": "T", + "description": "The input data as Tensor." + } + ], + "min_input": 1, + "max_input": 1, + "outputs": [ + { + "name": "output", + "type": "T", + "description": "The output." + }, + { + "name": "mask", + "type": "T", + "option": "optional", + "description": "The output mask." + } + ], + "min_output": 1, + "max_output": 2, + "outputs_range": "1 - 2", + "type_constraints": [ + { + "description": "Constrain input and output types to float tensors.", + "type_param_str": "T", + "allowed_type_strs": [ + "tensor(float16)", + "tensor(float)", + "tensor(double)" + ] + } + ], + "examples": [ + { + "summary": "default", + "code": "seed = np.int64(0)\nnode = onnx.helper.make_node(\n 'Dropout',\n inputs=['x'],\n outputs=['y'],\n seed=seed\n)\n\nx = np.random.randn(3, 4, 5).astype(np.float32)\ny = dropout(x)\nexpect(node, inputs=[x], outputs=[y], name='test_dropout_default')" + }, + { + "summary": "default_mask", + "code": "seed = np.int64(0)\nnode = onnx.helper.make_node(\n 'Dropout',\n inputs=['x'],\n outputs=['y', 'z'],\n seed=seed\n)\n\nx = np.random.randn(3, 4, 5).astype(np.float32)\ny, z = dropout(x, return_mask=True)\nexpect(node, inputs=[x], outputs=[y, z], name='test_dropout_default_mask')" + }, + { + "summary": "default_mask_ratio", + "code": "seed = np.int64(0)\nnode = onnx.helper.make_node(\n 'Dropout',\n inputs=['x', 'r'],\n outputs=['y', 'z'],\n seed=seed\n)\n\nr = np.float32(0.1)\nx = np.random.randn(3, 4, 5).astype(np.float32)\ny, z = dropout(x, r, return_mask=True)\nexpect(node, inputs=[x, r], outputs=[y, z], name='test_dropout_default_mask_ratio')" + }, + { + "summary": "default_old", + "code": "node = onnx.helper.make_node(\n 'Dropout',\n inputs=['x'],\n outputs=['y'],\n)\n\nx = np.array([-1, 0, 1]).astype(np.float32)\ny = x\nexpect(node, inputs=[x], outputs=[y],\n name='test_dropout_default_old', opset_imports=[helper.make_opsetid(\"\", 11)])" + }, + { + "summary": "default_ratio", + "code": "seed = np.int64(0)\nnode = onnx.helper.make_node(\n 'Dropout',\n inputs=['x', 'r'],\n outputs=['y'],\n seed=seed\n)\n\nr = np.float32(0.1)\nx = np.random.randn(3, 4, 5).astype(np.float32)\ny = dropout(x, r)\nexpect(node, inputs=[x, r], outputs=[y], name='test_dropout_default_ratio')" + }, + { + "summary": "random_old", + "code": "node = onnx.helper.make_node(\n 'Dropout',\n inputs=['x'],\n outputs=['y'],\n ratio=.2,\n)\n\nx = np.random.randn(3, 4, 5).astype(np.float32)\ny = x\nexpect(node, inputs=[x], outputs=[y],\n name='test_dropout_random_old', opset_imports=[helper.make_opsetid(\"\", 11)])" + }, + { + "summary": "training", + "code": "seed = np.int64(0)\nnode = onnx.helper.make_node(\n 'Dropout',\n inputs=['x', 'r', 't'],\n outputs=['y'],\n seed=seed\n)\n\nx = np.random.randn(3, 4, 5).astype(np.float32)\nr = np.float32(0.75)\nt = np.bool_(True)\ny = dropout(x, r, training_mode=t)\nexpect(node, inputs=[x, r, t], outputs=[y], name='test_training_dropout')" + }, + { + "summary": "training_default", + "code": "seed = np.int64(0)\nnode = onnx.helper.make_node(\n 'Dropout',\n inputs=['x', 'r', 't'],\n outputs=['y'],\n seed=seed\n)\n\nx = np.random.randn(3, 4, 5).astype(np.float32)\nr = np.float32(0.5)\nt = np.bool_(True)\ny = dropout(x, r, training_mode=t)\nexpect(node, inputs=[x, r, t], outputs=[y], name='test_training_dropout_default')" + }, + { + "summary": "training_default_ratio_mask", + "code": "seed = np.int64(0)\nnode = onnx.helper.make_node(\n 'Dropout',\n inputs=['x', 'r', 't'],\n outputs=['y', 'z'],\n seed=seed\n)\n\nx = np.random.randn(3, 4, 5).astype(np.float32)\nr = np.float32(0.5)\nt = np.bool_(True)\ny, z = dropout(x, r, training_mode=t, return_mask=True)\nexpect(node, inputs=[x, r, t], outputs=[y, z], name='test_training_dropout_default_mask')" + }, + { + "summary": "training_default_zero_ratio", + "code": "seed = np.int64(0)\nnode = onnx.helper.make_node(\n 'Dropout',\n inputs=['x', 'r', 't'],\n outputs=['y'],\n seed=seed\n)\n\nx = np.random.randn(3, 4, 5).astype(np.float32)\nr = np.float32(0.0)\nt = np.bool_(True)\ny = dropout(x, r, training_mode=t)\nexpect(node, inputs=[x, r, t], outputs=[y], name='test_training_dropout_zero_ratio')" + }, + { + "summary": "training_default_zero_ratio_mask", + "code": "seed = np.int64(0)\nnode = onnx.helper.make_node(\n 'Dropout',\n inputs=['x', 'r', 't'],\n outputs=['y', 'z'],\n seed=seed\n)\n\nx = np.random.randn(3, 4, 5).astype(np.float32)\nr = np.float32(0.0)\nt = np.bool_(True)\ny, z = dropout(x, r, training_mode=t, return_mask=True)\nexpect(node, inputs=[x, r, t], outputs=[y, z], name='test_training_dropout_zero_ratio_mask')" + }, + { + "summary": "training_ratio_mask", + "code": "seed = np.int64(0)\nnode = onnx.helper.make_node(\n 'Dropout',\n inputs=['x', 'r', 't'],\n outputs=['y', 'z'],\n seed=seed\n)\n\nx = np.random.randn(3, 4, 5).astype(np.float32)\nr = np.float32(0.75)\nt = np.bool_(True)\ny, z = dropout(x, r, training_mode=t, return_mask=True)\nexpect(node, inputs=[x, r, t], outputs=[y, z], name='test_training_dropout_mask')" + } + ], + "category": "Dropout" + }, + { + "name": "Dropout", + "module": "ai.onnx", + "version": 10, + "support_level": "common", + "description": "Dropout takes one input floating tensor and produces two tensor outputs,\noutput (floating tensor) and mask (`Tensor`). Depending on whether it is\nin test mode or not, the output Y will either be a random dropout, or a simple\ncopy of the input. Note that our implementation of Dropout does scaling in\nthe training phase, so during testing nothing needs to be done.\nThis operator has **optional** inputs/outputs. See [the doc](https://github.com/onnx/onnx/blob/master/docs/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.\n", + "attributes": [ + { + "name": "ratio", + "type": "float32", + "required": false, + "default": 0.5, + "description": "The ratio of random dropout" + } + ], + "inputs": [ + { + "name": "data", + "type": "T", + "description": "The input data as Tensor." + } + ], + "min_input": 1, + "max_input": 1, + "outputs": [ + { + "name": "output", + "type": "T", + "description": "The output." + }, + { + "name": "mask", + "type": "T1", + "option": "optional", + "description": "The output mask." + } + ], + "min_output": 1, + "max_output": 2, + "outputs_range": "1 - 2", + "type_constraints": [ + { + "description": "Constrain input and output types to float tensors.", + "type_param_str": "T", + "allowed_type_strs": [ + "tensor(float16)", + "tensor(float)", + "tensor(double)" + ] + }, + { + "description": "Constrain output mask types to boolean tensors.", + "type_param_str": "T1", + "allowed_type_strs": [ + "tensor(bool)" + ] + } + ], + "examples": [ + { + "summary": "default", + "code": "seed = np.int64(0)\nnode = onnx.helper.make_node(\n 'Dropout',\n inputs=['x'],\n outputs=['y'],\n seed=seed\n)\n\nx = np.random.randn(3, 4, 5).astype(np.float32)\ny = dropout(x)\nexpect(node, inputs=[x], outputs=[y], name='test_dropout_default')" + }, + { + "summary": "default_mask", + "code": "seed = np.int64(0)\nnode = onnx.helper.make_node(\n 'Dropout',\n inputs=['x'],\n outputs=['y', 'z'],\n seed=seed\n)\n\nx = np.random.randn(3, 4, 5).astype(np.float32)\ny, z = dropout(x, return_mask=True)\nexpect(node, inputs=[x], outputs=[y, z], name='test_dropout_default_mask')" + }, + { + "summary": "default_mask_ratio", + "code": "seed = np.int64(0)\nnode = onnx.helper.make_node(\n 'Dropout',\n inputs=['x', 'r'],\n outputs=['y', 'z'],\n seed=seed\n)\n\nr = np.float32(0.1)\nx = np.random.randn(3, 4, 5).astype(np.float32)\ny, z = dropout(x, r, return_mask=True)\nexpect(node, inputs=[x, r], outputs=[y, z], name='test_dropout_default_mask_ratio')" + }, + { + "summary": "default_old", + "code": "node = onnx.helper.make_node(\n 'Dropout',\n inputs=['x'],\n outputs=['y'],\n)\n\nx = np.array([-1, 0, 1]).astype(np.float32)\ny = x\nexpect(node, inputs=[x], outputs=[y],\n name='test_dropout_default_old', opset_imports=[helper.make_opsetid(\"\", 11)])" + }, + { + "summary": "default_ratio", + "code": "seed = np.int64(0)\nnode = onnx.helper.make_node(\n 'Dropout',\n inputs=['x', 'r'],\n outputs=['y'],\n seed=seed\n)\n\nr = np.float32(0.1)\nx = np.random.randn(3, 4, 5).astype(np.float32)\ny = dropout(x, r)\nexpect(node, inputs=[x, r], outputs=[y], name='test_dropout_default_ratio')" + }, + { + "summary": "random_old", + "code": "node = onnx.helper.make_node(\n 'Dropout',\n inputs=['x'],\n outputs=['y'],\n ratio=.2,\n)\n\nx = np.random.randn(3, 4, 5).astype(np.float32)\ny = x\nexpect(node, inputs=[x], outputs=[y],\n name='test_dropout_random_old', opset_imports=[helper.make_opsetid(\"\", 11)])" + }, + { + "summary": "training", + "code": "seed = np.int64(0)\nnode = onnx.helper.make_node(\n 'Dropout',\n inputs=['x', 'r', 't'],\n outputs=['y'],\n seed=seed\n)\n\nx = np.random.randn(3, 4, 5).astype(np.float32)\nr = np.float32(0.75)\nt = np.bool_(True)\ny = dropout(x, r, training_mode=t)\nexpect(node, inputs=[x, r, t], outputs=[y], name='test_training_dropout')" + }, + { + "summary": "training_default", + "code": "seed = np.int64(0)\nnode = onnx.helper.make_node(\n 'Dropout',\n inputs=['x', 'r', 't'],\n outputs=['y'],\n seed=seed\n)\n\nx = np.random.randn(3, 4, 5).astype(np.float32)\nr = np.float32(0.5)\nt = np.bool_(True)\ny = dropout(x, r, training_mode=t)\nexpect(node, inputs=[x, r, t], outputs=[y], name='test_training_dropout_default')" + }, + { + "summary": "training_default_ratio_mask", + "code": "seed = np.int64(0)\nnode = onnx.helper.make_node(\n 'Dropout',\n inputs=['x', 'r', 't'],\n outputs=['y', 'z'],\n seed=seed\n)\n\nx = np.random.randn(3, 4, 5).astype(np.float32)\nr = np.float32(0.5)\nt = np.bool_(True)\ny, z = dropout(x, r, training_mode=t, return_mask=True)\nexpect(node, inputs=[x, r, t], outputs=[y, z], name='test_training_dropout_default_mask')" + }, + { + "summary": "training_default_zero_ratio", + "code": "seed = np.int64(0)\nnode = onnx.helper.make_node(\n 'Dropout',\n inputs=['x', 'r', 't'],\n outputs=['y'],\n seed=seed\n)\n\nx = np.random.randn(3, 4, 5).astype(np.float32)\nr = np.float32(0.0)\nt = np.bool_(True)\ny = dropout(x, r, training_mode=t)\nexpect(node, inputs=[x, r, t], outputs=[y], name='test_training_dropout_zero_ratio')" + }, + { + "summary": "training_default_zero_ratio_mask", + "code": "seed = np.int64(0)\nnode = onnx.helper.make_node(\n 'Dropout',\n inputs=['x', 'r', 't'],\n outputs=['y', 'z'],\n seed=seed\n)\n\nx = np.random.randn(3, 4, 5).astype(np.float32)\nr = np.float32(0.0)\nt = np.bool_(True)\ny, z = dropout(x, r, training_mode=t, return_mask=True)\nexpect(node, inputs=[x, r, t], outputs=[y, z], name='test_training_dropout_zero_ratio_mask')" + }, + { + "summary": "training_ratio_mask", + "code": "seed = np.int64(0)\nnode = onnx.helper.make_node(\n 'Dropout',\n inputs=['x', 'r', 't'],\n outputs=['y', 'z'],\n seed=seed\n)\n\nx = np.random.randn(3, 4, 5).astype(np.float32)\nr = np.float32(0.75)\nt = np.bool_(True)\ny, z = dropout(x, r, training_mode=t, return_mask=True)\nexpect(node, inputs=[x, r, t], outputs=[y, z], name='test_training_dropout_mask')" + } + ], + "category": "Dropout" + }, + { + "name": "Dropout", + "module": "ai.onnx", + "version": 12, + "support_level": "common", + "description": "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,\noutput (floating-point tensor) and mask (optional `Tensor`). If `training_mode` is true then the output Y will be a random dropout;\nNote that this Dropout scales the masked input data by the following equation, so to convert the trained model into inference mode,\nthe user can simply not pass `training_mode` input or set it to false.\n```\noutput = scale * data * mask,\n```\nwhere\n```\nscale = 1. / (1. - ratio).\n```\nThis operator has **optional** inputs/outputs. See [the doc](https://github.com/onnx/onnx/blob/master/docs/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.\n", + "attributes": [ + { + "name": "seed", + "type": "int64", + "required": false, + "description": "(Optional) Seed to the random generator, if not specified we will auto generate one." + } + ], + "inputs": [ + { + "name": "data", + "type": "T", + "description": "The input data as Tensor." + }, + { + "name": "ratio", + "type": "T1", + "option": "optional", + "description": "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." + }, + { + "name": "training_mode", + "type": "T2", + "option": "optional", + "description": "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." + } + ], + "min_input": 1, + "max_input": 3, + "outputs": [ + { + "name": "output", + "type": "T", + "description": "The output." + }, + { + "name": "mask", + "type": "T2", + "option": "optional", + "description": "The output mask." + } + ], + "min_output": 1, + "max_output": 2, + "inputs_range": "1 - 3", + "outputs_range": "1 - 2", + "type_constraints": [ + { + "description": "Constrain input and output types to float tensors.", + "type_param_str": "T", + "allowed_type_strs": [ + "tensor(float16)", + "tensor(float)", + "tensor(double)" + ] + }, + { + "description": "Constrain input 'ratio' types to float tensors.", + "type_param_str": "T1", + "allowed_type_strs": [ + "tensor(float16)", + "tensor(float)", + "tensor(double)" + ] + }, + { + "description": "Constrain output 'mask' types to boolean tensors.", + "type_param_str": "T2", + "allowed_type_strs": [ + "tensor(bool)" + ] + } + ], + "examples": [ + { + "summary": "default", + "code": "seed = np.int64(0)\nnode = onnx.helper.make_node(\n 'Dropout',\n inputs=['x'],\n outputs=['y'],\n seed=seed\n)\n\nx = np.random.randn(3, 4, 5).astype(np.float32)\ny = dropout(x)\nexpect(node, inputs=[x], outputs=[y], name='test_dropout_default')" + }, + { + "summary": "default_mask", + "code": "seed = np.int64(0)\nnode = onnx.helper.make_node(\n 'Dropout',\n inputs=['x'],\n outputs=['y', 'z'],\n seed=seed\n)\n\nx = np.random.randn(3, 4, 5).astype(np.float32)\ny, z = dropout(x, return_mask=True)\nexpect(node, inputs=[x], outputs=[y, z], name='test_dropout_default_mask')" + }, + { + "summary": "default_mask_ratio", + "code": "seed = np.int64(0)\nnode = onnx.helper.make_node(\n 'Dropout',\n inputs=['x', 'r'],\n outputs=['y', 'z'],\n seed=seed\n)\n\nr = np.float32(0.1)\nx = np.random.randn(3, 4, 5).astype(np.float32)\ny, z = dropout(x, r, return_mask=True)\nexpect(node, inputs=[x, r], outputs=[y, z], name='test_dropout_default_mask_ratio')" + }, + { + "summary": "default_old", + "code": "node = onnx.helper.make_node(\n 'Dropout',\n inputs=['x'],\n outputs=['y'],\n)\n\nx = np.array([-1, 0, 1]).astype(np.float32)\ny = x\nexpect(node, inputs=[x], outputs=[y],\n name='test_dropout_default_old', opset_imports=[helper.make_opsetid(\"\", 11)])" + }, + { + "summary": "default_ratio", + "code": "seed = np.int64(0)\nnode = onnx.helper.make_node(\n 'Dropout',\n inputs=['x', 'r'],\n outputs=['y'],\n seed=seed\n)\n\nr = np.float32(0.1)\nx = np.random.randn(3, 4, 5).astype(np.float32)\ny = dropout(x, r)\nexpect(node, inputs=[x, r], outputs=[y], name='test_dropout_default_ratio')" + }, + { + "summary": "random_old", + "code": "node = onnx.helper.make_node(\n 'Dropout',\n inputs=['x'],\n outputs=['y'],\n ratio=.2,\n)\n\nx = np.random.randn(3, 4, 5).astype(np.float32)\ny = x\nexpect(node, inputs=[x], outputs=[y],\n name='test_dropout_random_old', opset_imports=[helper.make_opsetid(\"\", 11)])" + }, + { + "summary": "training", + "code": "seed = np.int64(0)\nnode = onnx.helper.make_node(\n 'Dropout',\n inputs=['x', 'r', 't'],\n outputs=['y'],\n seed=seed\n)\n\nx = np.random.randn(3, 4, 5).astype(np.float32)\nr = np.float32(0.75)\nt = np.bool_(True)\ny = dropout(x, r, training_mode=t)\nexpect(node, inputs=[x, r, t], outputs=[y], name='test_training_dropout')" + }, + { + "summary": "training_default", + "code": "seed = np.int64(0)\nnode = onnx.helper.make_node(\n 'Dropout',\n inputs=['x', 'r', 't'],\n outputs=['y'],\n seed=seed\n)\n\nx = np.random.randn(3, 4, 5).astype(np.float32)\nr = np.float32(0.5)\nt = np.bool_(True)\ny = dropout(x, r, training_mode=t)\nexpect(node, inputs=[x, r, t], outputs=[y], name='test_training_dropout_default')" + }, + { + "summary": "training_default_ratio_mask", + "code": "seed = np.int64(0)\nnode = onnx.helper.make_node(\n 'Dropout',\n inputs=['x', 'r', 't'],\n outputs=['y', 'z'],\n seed=seed\n)\n\nx = np.random.randn(3, 4, 5).astype(np.float32)\nr = np.float32(0.5)\nt = np.bool_(True)\ny, z = dropout(x, r, training_mode=t, return_mask=True)\nexpect(node, inputs=[x, r, t], outputs=[y, z], name='test_training_dropout_default_mask')" + }, + { + "summary": "training_default_zero_ratio", + "code": "seed = np.int64(0)\nnode = onnx.helper.make_node(\n 'Dropout',\n inputs=['x', 'r', 't'],\n outputs=['y'],\n seed=seed\n)\n\nx = np.random.randn(3, 4, 5).astype(np.float32)\nr = np.float32(0.0)\nt = np.bool_(True)\ny = dropout(x, r, training_mode=t)\nexpect(node, inputs=[x, r, t], outputs=[y], name='test_training_dropout_zero_ratio')" + }, + { + "summary": "training_default_zero_ratio_mask", + "code": "seed = np.int64(0)\nnode = onnx.helper.make_node(\n 'Dropout',\n inputs=['x', 'r', 't'],\n outputs=['y', 'z'],\n seed=seed\n)\n\nx = np.random.randn(3, 4, 5).astype(np.float32)\nr = np.float32(0.0)\nt = np.bool_(True)\ny, z = dropout(x, r, training_mode=t, return_mask=True)\nexpect(node, inputs=[x, r, t], outputs=[y, z], name='test_training_dropout_zero_ratio_mask')" + }, + { + "summary": "training_ratio_mask", + "code": "seed = np.int64(0)\nnode = onnx.helper.make_node(\n 'Dropout',\n inputs=['x', 'r', 't'],\n outputs=['y', 'z'],\n seed=seed\n)\n\nx = np.random.randn(3, 4, 5).astype(np.float32)\nr = np.float32(0.75)\nt = np.bool_(True)\ny, z = dropout(x, r, training_mode=t, return_mask=True)\nexpect(node, inputs=[x, r, t], outputs=[y, z], name='test_training_dropout_mask')" + } + ], + "category": "Dropout" + }, + { + "name": "Dropout", + "module": "ai.onnx", + "version": 13, + "support_level": "common", + "description": "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,\noutput (floating-point tensor) and mask (optional `Tensor`). If `training_mode` is true then the output Y will be a random dropout;\nNote that this Dropout scales the masked input data by the following equation, so to convert the trained model into inference mode,\nthe user can simply not pass `training_mode` input or set it to false.\n```\noutput = scale * data * mask,\n```\nwhere\n```\nscale = 1. / (1. - ratio).\n```\nThis operator has **optional** inputs/outputs. See [the doc](https://github.com/onnx/onnx/blob/master/docs/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.\n", + "attributes": [ + { + "name": "seed", + "type": "int64", + "required": false, + "description": "(Optional) Seed to the random generator, if not specified we will auto generate one." + } + ], + "inputs": [ + { + "name": "data", + "type": "T", + "description": "The input data as Tensor." + }, + { + "name": "ratio", + "type": "T1", + "option": "optional", + "description": "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." + }, + { + "name": "training_mode", + "type": "T2", + "option": "optional", + "description": "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." + } + ], + "min_input": 1, + "max_input": 3, + "outputs": [ + { + "name": "output", + "type": "T", + "description": "The output." + }, + { + "name": "mask", + "type": "T2", + "option": "optional", + "description": "The output mask." + } + ], + "min_output": 1, + "max_output": 2, + "inputs_range": "1 - 3", + "outputs_range": "1 - 2", + "type_constraints": [ + { + "description": "Constrain input and output types to float tensors.", + "type_param_str": "T", + "allowed_type_strs": [ + "tensor(float16)", + "tensor(float)", + "tensor(double)", + "tensor(bfloat16)" + ] + }, + { + "description": "Constrain input 'ratio' types to float tensors.", + "type_param_str": "T1", + "allowed_type_strs": [ + "tensor(float16)", + "tensor(float)", + "tensor(double)" + ] + }, + { + "description": "Constrain output 'mask' types to boolean tensors.", + "type_param_str": "T2", + "allowed_type_strs": [ + "tensor(bool)" + ] + } + ], + "examples": [ + { + "summary": "default", + "code": "seed = np.int64(0)\nnode = onnx.helper.make_node(\n 'Dropout',\n inputs=['x'],\n outputs=['y'],\n seed=seed\n)\n\nx = np.random.randn(3, 4, 5).astype(np.float32)\ny = dropout(x)\nexpect(node, inputs=[x], outputs=[y], name='test_dropout_default')" + }, + { + "summary": "default_mask", + "code": "seed = np.int64(0)\nnode = onnx.helper.make_node(\n 'Dropout',\n inputs=['x'],\n outputs=['y', 'z'],\n seed=seed\n)\n\nx = np.random.randn(3, 4, 5).astype(np.float32)\ny, z = dropout(x, return_mask=True)\nexpect(node, inputs=[x], outputs=[y, z], name='test_dropout_default_mask')" + }, + { + "summary": "default_mask_ratio", + "code": "seed = np.int64(0)\nnode = onnx.helper.make_node(\n 'Dropout',\n inputs=['x', 'r'],\n outputs=['y', 'z'],\n seed=seed\n)\n\nr = np.float32(0.1)\nx = np.random.randn(3, 4, 5).astype(np.float32)\ny, z = dropout(x, r, return_mask=True)\nexpect(node, inputs=[x, r], outputs=[y, z], name='test_dropout_default_mask_ratio')" + }, + { + "summary": "default_old", + "code": "node = onnx.helper.make_node(\n 'Dropout',\n inputs=['x'],\n outputs=['y'],\n)\n\nx = np.array([-1, 0, 1]).astype(np.float32)\ny = x\nexpect(node, inputs=[x], outputs=[y],\n name='test_dropout_default_old', opset_imports=[helper.make_opsetid(\"\", 11)])" + }, + { + "summary": "default_ratio", + "code": "seed = np.int64(0)\nnode = onnx.helper.make_node(\n 'Dropout',\n inputs=['x', 'r'],\n outputs=['y'],\n seed=seed\n)\n\nr = np.float32(0.1)\nx = np.random.randn(3, 4, 5).astype(np.float32)\ny = dropout(x, r)\nexpect(node, inputs=[x, r], outputs=[y], name='test_dropout_default_ratio')" + }, + { + "summary": "random_old", + "code": "node = onnx.helper.make_node(\n 'Dropout',\n inputs=['x'],\n outputs=['y'],\n ratio=.2,\n)\n\nx = np.random.randn(3, 4, 5).astype(np.float32)\ny = x\nexpect(node, inputs=[x], outputs=[y],\n name='test_dropout_random_old', opset_imports=[helper.make_opsetid(\"\", 11)])" + }, + { + "summary": "training", + "code": "seed = np.int64(0)\nnode = onnx.helper.make_node(\n 'Dropout',\n inputs=['x', 'r', 't'],\n outputs=['y'],\n seed=seed\n)\n\nx = np.random.randn(3, 4, 5).astype(np.float32)\nr = np.float32(0.75)\nt = np.bool_(True)\ny = dropout(x, r, training_mode=t)\nexpect(node, inputs=[x, r, t], outputs=[y], name='test_training_dropout')" + }, + { + "summary": "training_default", + "code": "seed = np.int64(0)\nnode = onnx.helper.make_node(\n 'Dropout',\n inputs=['x', 'r', 't'],\n outputs=['y'],\n seed=seed\n)\n\nx = np.random.randn(3, 4, 5).astype(np.float32)\nr = np.float32(0.5)\nt = np.bool_(True)\ny = dropout(x, r, training_mode=t)\nexpect(node, inputs=[x, r, t], outputs=[y], name='test_training_dropout_default')" + }, + { + "summary": "training_default_ratio_mask", + "code": "seed = np.int64(0)\nnode = onnx.helper.make_node(\n 'Dropout',\n inputs=['x', 'r', 't'],\n outputs=['y', 'z'],\n seed=seed\n)\n\nx = np.random.randn(3, 4, 5).astype(np.float32)\nr = np.float32(0.5)\nt = np.bool_(True)\ny, z = dropout(x, r, training_mode=t, return_mask=True)\nexpect(node, inputs=[x, r, t], outputs=[y, z], name='test_training_dropout_default_mask')" + }, + { + "summary": "training_default_zero_ratio", + "code": "seed = np.int64(0)\nnode = onnx.helper.make_node(\n 'Dropout',\n inputs=['x', 'r', 't'],\n outputs=['y'],\n seed=seed\n)\n\nx = np.random.randn(3, 4, 5).astype(np.float32)\nr = np.float32(0.0)\nt = np.bool_(True)\ny = dropout(x, r, training_mode=t)\nexpect(node, inputs=[x, r, t], outputs=[y], name='test_training_dropout_zero_ratio')" + }, + { + "summary": "training_default_zero_ratio_mask", + "code": "seed = np.int64(0)\nnode = onnx.helper.make_node(\n 'Dropout',\n inputs=['x', 'r', 't'],\n outputs=['y', 'z'],\n seed=seed\n)\n\nx = np.random.randn(3, 4, 5).astype(np.float32)\nr = np.float32(0.0)\nt = np.bool_(True)\ny, z = dropout(x, r, training_mode=t, return_mask=True)\nexpect(node, inputs=[x, r, t], outputs=[y, z], name='test_training_dropout_zero_ratio_mask')" + }, + { + "summary": "training_ratio_mask", + "code": "seed = np.int64(0)\nnode = onnx.helper.make_node(\n 'Dropout',\n inputs=['x', 'r', 't'],\n outputs=['y', 'z'],\n seed=seed\n)\n\nx = np.random.randn(3, 4, 5).astype(np.float32)\nr = np.float32(0.75)\nt = np.bool_(True)\ny, z = dropout(x, r, training_mode=t, return_mask=True)\nexpect(node, inputs=[x, r, t], outputs=[y, z], name='test_training_dropout_mask')" + } + ], + "category": "Dropout" + }, + { + "name": "DynamicQuantizeLinear", + "module": "ai.onnx", + "version": 11, + "support_level": "common", + "description": "A Function to fuse calculation for Scale, Zero Point and FP32->8Bit convertion of FP32 Input data.\nOutputs Scale, ZeroPoint and Quantized Input for a given FP32 Input.\nScale is calculated as:\n```\n y_scale = (max(x) - min(x))/(qmax - qmin)\n * where qmax and qmin are max and min values for quantization range .i.e [0, 255] in case of uint8\n * data range is adjusted to include 0.\n```\nZero point is calculated as:\n```\nintermediate_zero_point = qmin - min(x)/y_scale\ny_zero_point = cast(round(saturate(itermediate_zero_point)))\n* where qmax and qmin are max and min values for quantization range .i.e [0, 255] in case of uint8\n* for saturation, it saturates to [0, 255] if it's uint8, or [-127, 127] if it's int8. Right now only uint8 is supported.\n* rounding to nearest ties to even.\n```\nData quantization formula is:\n```\ny = saturate (round (x / y_scale) + y_zero_point)\n* for saturation, it saturates to [0, 255] if it's uint8, or [-127, 127] if it's int8. Right now only uint8 is supported.\n* rounding to nearest ties to even.\n```\n", + "inputs": [ + { + "name": "x", + "type": "T1", + "description": "Input tensor" + } + ], + "min_input": 1, + "max_input": 1, + "outputs": [ + { + "name": "y", + "type": "T2", + "description": "Quantized output tensor" + }, + { + "name": "y_scale", + "type": "tensor(float)", + "description": "Output scale. It's a scalar, which means a per-tensor/layer quantization." + }, + { + "name": "y_zero_point", + "type": "T2", + "description": "Output zero point. It's a scalar, which means a per-tensor/layer quantization." + } + ], + "min_output": 3, + "max_output": 3, + "type_constraints": [ + { + "description": "Constrain 'x' to float tensor.", + "type_param_str": "T1", + "allowed_type_strs": [ + "tensor(float)" + ] + }, + { + "description": "Constrain 'y_zero_point' and 'y' to 8-bit unsigned integer tensor.", + "type_param_str": "T2", + "allowed_type_strs": [ + "tensor(uint8)" + ] + } + ], + "examples": [ + { + "summary": "dynamicquantizelinear", + "code": "node = onnx.helper.make_node('DynamicQuantizeLinear',\n inputs=['x'],\n outputs=['y', 'y_scale', 'y_zero_point'],\n)\n\n# expected scale 0.0196078438 and zero point 153\nX = np.array([0, 2, -3, -2.5, 1.34, 0.5]).astype(np.float32)\nx_min = np.minimum(0, np.min(X))\nx_max = np.maximum(0, np.max(X))\nY_Scale = np.float32((x_max - x_min) / (255 - 0)) # uint8 -> [0, 255]\nY_ZeroPoint = np.clip(round((0 - x_min) / Y_Scale), 0, 255).astype(np.uint8)\nY = np.clip(np.round(X / Y_Scale) + Y_ZeroPoint, 0, 255).astype(np.uint8)\n\nexpect(node, inputs=[X], outputs=[Y, Y_Scale, Y_ZeroPoint],\n name='test_dynamicquantizelinear')\n\n# expected scale 0.0156862754 and zero point 255\nX = np.array([-1.0, -2.1, -1.3, -2.5, -3.34, -4.0]).astype(np.float32)\nx_min = np.minimum(0, np.min(X))\nx_max = np.maximum(0, np.max(X))\nY_Scale = np.float32((x_max - x_min) / (255 - 0)) # uint8 -> [0, 255]\nY_ZeroPoint = np.clip(round((0 - x_min) / Y_Scale), 0, 255).astype(np.uint8)\nY = np.clip(np.round(X / Y_Scale) + Y_ZeroPoint, 0, 255).astype(np.uint8)\n\nexpect(node, inputs=[X], outputs=[Y, Y_Scale, Y_ZeroPoint],\n name='test_dynamicquantizelinear_max_adjusted')\n\nX = np.array([1, 2.1, 1.3, 2.5,\n 3.34, 4.0, 1.5, 2.6,\n 3.9, 4.0, 3.0, 2.345]).astype(np.float32).reshape((3, 4))\n\n# expected scale 0.0156862754 and zero point 0\nx_min = np.minimum(0, np.min(X))\nx_max = np.maximum(0, np.max(X))\nY_Scale = np.float32((x_max - x_min) / (255 - 0)) # uint8 -> [0, 255]\nY_ZeroPoint = np.clip(round((0 - x_min) / Y_Scale), 0, 255).astype(np.uint8)\nY = np.clip(np.round(X / Y_Scale) + Y_ZeroPoint, 0, 255).astype(np.uint8)\n\nexpect(node, inputs=[X], outputs=[Y, Y_Scale, Y_ZeroPoint],\n name='test_dynamicquantizelinear_min_adjusted')" + } + ] + }, + { + "name": "Einsum", + "module": "ai.onnx", + "version": 12, + "support_level": "common", + "description": "An einsum of the form ```term1, term2 -> output-term``` produces an output tensor using the following equation\n\n```output[output-term] = reduce-sum( input1[term1] * input2[term] )```\n\nwhere the reduce-sum performs a summation over all the indices occurring in the input terms (term1, term2)\nthat do not occur in the output-term.\n\nThe Einsum operator evaluates algebraic tensor operations on a sequence of tensors, using the Einstein summation\nconvention. The equation string contains a comma-separated sequence of lower case letters. Each term corresponds to\nan operand tensor, and the characters within the terms correspond to operands dimensions.\n\nThis sequence may be followed by \"->\" to separate the left and right hand side of the equation.\nIf the equation contains \"->\" followed by the right-hand side, the explicit (not classical) form of the Einstein\nsummation is performed, and the right-hand side indices indicate output tensor dimensions. In other cases,\noutput indices are (implicitly) set to the alphabetically sorted sequence of indices appearing exactly once in the\nequation.\n\nWhen a dimension character is repeated in the left-hand side, it represents summation along the dimension.\n\nThe equation may contain ellipsis (\"...\") to enable broadcasting. Ellipsis must indicate a fixed number of dimensions.\nSpecifically, every occurrence of ellipsis in the equation must represent the same number of dimensions.\nThe right-hand side may contain exactly one ellipsis. In implicit mode, the ellipsis dimensions are set to the\nbeginning of the output. The equation string may contain space (U+0020) character.\n", + "attributes": [ + { + "name": "equation", + "type": "string", + "required": true, + "description": "Einsum expression string." + } + ], + "inputs": [ + { + "name": "Inputs", + "type": "T", + "list": true, + "description": "Operands" + } + ], + "min_input": 1, + "max_input": 2147483647, + "outputs": [ + { + "name": "Output", + "type": "T", + "description": "Output tensor" + } + ], + "min_output": 1, + "max_output": 1, + "inputs_range": "1 - ∞", + "type_constraints": [ + { + "description": "Constrain input and output types to all numerical tensor types.", + "type_param_str": "T", + "allowed_type_strs": [ + "tensor(uint8)", + "tensor(uint16)", + "tensor(uint32)", + "tensor(uint64)", + "tensor(int8)", + "tensor(int16)", + "tensor(int32)", + "tensor(int64)", + "tensor(float16)", + "tensor(float)", + "tensor(double)" + ] + } + ], + "examples": [ + { + "summary": "einsum_batch_diagonal", + "code": "Eqn = '...ii ->...i'\nnode = onnx.helper.make_node(\n 'Einsum',\n inputs=['x'],\n outputs=['y'],\n equation=Eqn\n)\n\nX = np.random.randn(3, 5, 5)\nZ = einsum_reference_implementation(Eqn, (X,))\n\nexpect(node, inputs=[X], outputs=[Z], name='test_einsum_batch_diagonal')" + }, + { + "summary": "einsum_batch_matmul", + "code": "Eqn = 'bij, bjk -> bik'\nnode = onnx.helper.make_node(\n 'Einsum',\n inputs=['x', 'y'],\n outputs=['z'],\n equation=Eqn\n)\n\nX = np.random.randn(5, 2, 3)\nY = np.random.randn(5, 3, 4)\nZ = einsum_reference_implementation(Eqn, (X, Y))\n\nexpect(node, inputs=[X, Y], outputs=[Z], name='test_einsum_batch_matmul')" + }, + { + "summary": "einsum_inner_prod", + "code": "Eqn = 'i,i'\nnode = onnx.helper.make_node(\n 'Einsum',\n inputs=['x', 'y'],\n outputs=['z'],\n equation=Eqn\n)\n\nX = np.random.randn(5)\nY = np.random.randn(5)\nZ = einsum_reference_implementation(Eqn, (X, Y))\n\nexpect(node, inputs=[X, Y], outputs=[Z], name='test_einsum_inner_prod')" + }, + { + "summary": "einsum_sum", + "code": "Eqn = 'ij->i'\nnode = onnx.helper.make_node(\n 'Einsum',\n inputs=['x'],\n outputs=['y'],\n equation=Eqn\n)\n\nX = np.random.randn(3, 4)\nZ = einsum_reference_implementation(Eqn, (X,))\n\nexpect(node, inputs=[X], outputs=[Z], name='test_einsum_sum')" + }, + { + "summary": "einsum_transpose", + "code": "Eqn = 'ij->ji'\nnode = onnx.helper.make_node(\n 'Einsum',\n inputs=['x'],\n outputs=['y'],\n equation=Eqn\n)\n\nX = np.random.randn(3, 4)\nY = einsum_reference_implementation(Eqn, (X,))\n\nexpect(node, inputs=[X], outputs=[Y], name='test_einsum_transpose')" + } + ] + }, + { + "name": "Elu", + "module": "ai.onnx", + "version": 1, + "support_level": "common", + "description": "Elu takes one input data (Tensor) and produces one output data\n(Tensor) where the function `f(x) = alpha * (exp(x) - 1.) for x <\n0`, `f(x) = x for x >= 0`., is applied to the tensor elementwise.\n\n", + "attributes": [ + { + "name": "alpha", + "type": "float32", + "required": false, + "default": 1.0, + "description": "Coefficient of ELU default to 1.0." + }, + { + "name": "consumed_inputs", + "type": "int64[]", + "required": false, + "description": "legacy optimization attribute." + } + ], + "inputs": [ + { + "name": "X", + "type": "T", + "description": "1D input tensor" + } + ], + "min_input": 1, + "max_input": 1, + "outputs": [ + { + "name": "Y", + "type": "T", + "description": "1D input tensor" + } + ], + "min_output": 1, + "max_output": 1, + "type_constraints": [ + { + "description": "Constrain input and output types to float tensors.", + "type_param_str": "T", + "allowed_type_strs": [ + "tensor(float16)", + "tensor(float)", + "tensor(double)" + ] + } + ], + "examples": [ + { + "summary": "elu", + "code": "node = onnx.helper.make_node(\n 'Elu',\n inputs=['x'],\n outputs=['y'],\n alpha=2.0\n)\n\nx = np.array([-1, 0, 1]).astype(np.float32)\n# expected output [-1.2642411, 0., 1.]\ny = np.clip(x, 0, np.inf) + (np.exp(np.clip(x, -np.inf, 0)) - 1) * 2.0\nexpect(node, inputs=[x], outputs=[y],\n name='test_elu_example')\n\nx = np.random.randn(3, 4, 5).astype(np.float32)\ny = np.clip(x, 0, np.inf) + (np.exp(np.clip(x, -np.inf, 0)) - 1) * 2.0\nexpect(node, inputs=[x], outputs=[y],\n name='test_elu')" + }, + { + "summary": "elu_default", + "code": "default_alpha = 1.0\nnode = onnx.helper.make_node(\n 'Elu',\n inputs=['x'],\n outputs=['y'],\n)\nx = np.random.randn(3, 4, 5).astype(np.float32)\ny = np.clip(x, 0, np.inf) + (np.exp(np.clip(x, -np.inf, 0)) - 1) * default_alpha\nexpect(node, inputs=[x], outputs=[y],\n name='test_elu_default')" + } + ], + "category": "Activation" + }, + { + "name": "Elu", + "module": "ai.onnx", + "version": 6, + "support_level": "common", + "description": "Elu takes one input data (Tensor) and produces one output data\n(Tensor) where the function `f(x) = alpha * (exp(x) - 1.) for x <\n0`, `f(x) = x for x >= 0`., is applied to the tensor elementwise.\n\n", + "attributes": [ + { + "name": "alpha", + "type": "float32", + "required": false, + "default": 1.0, + "description": "Coefficient of ELU." + } + ], + "inputs": [ + { + "name": "X", + "type": "T", + "description": "1D input tensor" + } + ], + "min_input": 1, + "max_input": 1, + "outputs": [ + { + "name": "Y", + "type": "T", + "description": "1D output tensor" + } + ], + "min_output": 1, + "max_output": 1, + "type_constraints": [ + { + "description": "Constrain input and output types to float tensors.", + "type_param_str": "T", + "allowed_type_strs": [ + "tensor(float16)", + "tensor(float)", + "tensor(double)" + ] + } + ], + "examples": [ + { + "summary": "elu", + "code": "node = onnx.helper.make_node(\n 'Elu',\n inputs=['x'],\n outputs=['y'],\n alpha=2.0\n)\n\nx = np.array([-1, 0, 1]).astype(np.float32)\n# expected output [-1.2642411, 0., 1.]\ny = np.clip(x, 0, np.inf) + (np.exp(np.clip(x, -np.inf, 0)) - 1) * 2.0\nexpect(node, inputs=[x], outputs=[y],\n name='test_elu_example')\n\nx = np.random.randn(3, 4, 5).astype(np.float32)\ny = np.clip(x, 0, np.inf) + (np.exp(np.clip(x, -np.inf, 0)) - 1) * 2.0\nexpect(node, inputs=[x], outputs=[y],\n name='test_elu')" + }, + { + "summary": "elu_default", + "code": "default_alpha = 1.0\nnode = onnx.helper.make_node(\n 'Elu',\n inputs=['x'],\n outputs=['y'],\n)\nx = np.random.randn(3, 4, 5).astype(np.float32)\ny = np.clip(x, 0, np.inf) + (np.exp(np.clip(x, -np.inf, 0)) - 1) * default_alpha\nexpect(node, inputs=[x], outputs=[y],\n name='test_elu_default')" + } + ], + "category": "Activation" + }, + { + "name": "Equal", + "module": "ai.onnx", + "version": 1, + "support_level": "common", + "description": "Returns the tensor resulted from performing the `equal` logical operation\nelementwise on the input tensors `A` and `B`.\n\nIf broadcasting is enabled, the right-hand-side argument will be broadcasted\nto match the shape of left-hand-side argument. See the doc of `Add` for a\ndetailed description of the broadcasting rules.\n", + "attributes": [ + { + "name": "axis", + "type": "int64", + "required": false, + "description": "If set, defines the broadcast dimensions." + }, + { + "name": "broadcast", + "type": "int64", + "required": false, + "description": "Enable broadcasting" + } + ], + "inputs": [ + { + "name": "A", + "type": "T", + "description": "Left input tensor for the logical operator." + }, + { + "name": "B", + "type": "T", + "description": "Right input tensor for the logical operator." + } + ], + "min_input": 2, + "max_input": 2, + "outputs": [ + { + "name": "C", + "type": "T1", + "description": "Result tensor." + } + ], + "min_output": 1, + "max_output": 1, + "type_constraints": [ + { + "description": "Constrains input to integral tensors.", + "type_param_str": "T", + "allowed_type_strs": [ + "tensor(bool)", + "tensor(int32)", + "tensor(int64)" + ] + }, + { + "description": "Constrains output to boolean tensor.", + "type_param_str": "T1", + "allowed_type_strs": [ + "tensor(bool)" + ] + } + ], + "examples": [ + { + "summary": "equal", + "code": "node = onnx.helper.make_node(\n 'Equal',\n inputs=['x', 'y'],\n outputs=['z'],\n)\n\nx = (np.random.randn(3, 4, 5) * 10).astype(np.int32)\ny = (np.random.randn(3, 4, 5) * 10).astype(np.int32)\nz = np.equal(x, y)\nexpect(node, inputs=[x, y], outputs=[z],\n name='test_equal')" + }, + { + "summary": "equal_broadcast", + "code": "node = onnx.helper.make_node(\n 'Equal',\n inputs=['x', 'y'],\n outputs=['z'],\n)\n\nx = (np.random.randn(3, 4, 5) * 10).astype(np.int32)\ny = (np.random.randn(5) * 10).astype(np.int32)\nz = np.equal(x, y)\nexpect(node, inputs=[x, y], outputs=[z],\n name='test_equal_bcast')" + } + ], + "category": "Logic" + }, + { + "name": "Equal", + "module": "ai.onnx", + "version": 7, + "support_level": "common", + "description": "Returns the tensor resulted from performing the `equal` logical operation\nelementwise on the input tensors `A` and `B` (with Numpy-style broadcasting support).\n\nThis operator supports **multidirectional (i.e., Numpy-style) broadcasting**; for more details please check [the doc](https://github.com/onnx/onnx/blob/master/docs/Broadcasting.md).\n", + "inputs": [ + { + "name": "A", + "type": "T", + "description": "First input operand for the logical operator." + }, + { + "name": "B", + "type": "T", + "description": "Second input operand for the logical operator." + } + ], + "min_input": 2, + "max_input": 2, + "outputs": [ + { + "name": "C", + "type": "T1", + "description": "Result tensor." + } + ], + "min_output": 1, + "max_output": 1, + "type_constraints": [ + { + "description": "Constrains input to integral tensors.", + "type_param_str": "T", + "allowed_type_strs": [ + "tensor(bool)", + "tensor(int32)", + "tensor(int64)" + ] + }, + { + "description": "Constrains output to boolean tensor.", + "type_param_str": "T1", + "allowed_type_strs": [ + "tensor(bool)" + ] + } + ], + "examples": [ + { + "summary": "equal", + "code": "node = onnx.helper.make_node(\n 'Equal',\n inputs=['x', 'y'],\n outputs=['z'],\n)\n\nx = (np.random.randn(3, 4, 5) * 10).astype(np.int32)\ny = (np.random.randn(3, 4, 5) * 10).astype(np.int32)\nz = np.equal(x, y)\nexpect(node, inputs=[x, y], outputs=[z],\n name='test_equal')" + }, + { + "summary": "equal_broadcast", + "code": "node = onnx.helper.make_node(\n 'Equal',\n inputs=['x', 'y'],\n outputs=['z'],\n)\n\nx = (np.random.randn(3, 4, 5) * 10).astype(np.int32)\ny = (np.random.randn(5) * 10).astype(np.int32)\nz = np.equal(x, y)\nexpect(node, inputs=[x, y], outputs=[z],\n name='test_equal_bcast')" + } + ], + "category": "Logic" + }, + { + "name": "Equal", + "module": "ai.onnx", + "version": 11, + "support_level": "common", + "description": "Returns the tensor resulted from performing the `equal` logical operation\nelementwise on the input tensors `A` and `B` (with Numpy-style broadcasting support).\n\nThis operator supports **multidirectional (i.e., Numpy-style) broadcasting**; for more details please check [the doc](https://github.com/onnx/onnx/blob/master/docs/Broadcasting.md).\n", + "inputs": [ + { + "name": "A", + "type": "T", + "description": "First input operand for the logical operator." + }, + { + "name": "B", + "type": "T", + "description": "Second input operand for the logical operator." + } + ], + "min_input": 2, + "max_input": 2, + "outputs": [ + { + "name": "C", + "type": "T1", + "description": "Result tensor." + } + ], + "min_output": 1, + "max_output": 1, + "type_constraints": [ + { + "description": "Constrains input types to all numeric tensors.", + "type_param_str": "T", + "allowed_type_strs": [ + "tensor(bool)", + "tensor(uint8)", + "tensor(uint16)", + "tensor(uint32)", + "tensor(uint64)", + "tensor(int8)", + "tensor(int16)", + "tensor(int32)", + "tensor(int64)", + "tensor(float16)", + "tensor(float)", + "tensor(double)" + ] + }, + { + "description": "Constrains output to boolean tensor.", + "type_param_str": "T1", + "allowed_type_strs": [ + "tensor(bool)" + ] + } + ], + "examples": [ + { + "summary": "equal", + "code": "node = onnx.helper.make_node(\n 'Equal',\n inputs=['x', 'y'],\n outputs=['z'],\n)\n\nx = (np.random.randn(3, 4, 5) * 10).astype(np.int32)\ny = (np.random.randn(3, 4, 5) * 10).astype(np.int32)\nz = np.equal(x, y)\nexpect(node, inputs=[x, y], outputs=[z],\n name='test_equal')" + }, + { + "summary": "equal_broadcast", + "code": "node = onnx.helper.make_node(\n 'Equal',\n inputs=['x', 'y'],\n outputs=['z'],\n)\n\nx = (np.random.randn(3, 4, 5) * 10).astype(np.int32)\ny = (np.random.randn(5) * 10).astype(np.int32)\nz = np.equal(x, y)\nexpect(node, inputs=[x, y], outputs=[z],\n name='test_equal_bcast')" + } + ], + "category": "Logic" + }, + { + "name": "Equal", + "module": "ai.onnx", + "version": 13, + "support_level": "common", + "description": "Returns the tensor resulted from performing the `equal` logical operation\nelementwise on the input tensors `A` and `B` (with Numpy-style broadcasting support).\n\nThis operator supports **multidirectional (i.e., Numpy-style) broadcasting**; for more details please check [the doc](https://github.com/onnx/onnx/blob/master/docs/Broadcasting.md).\n", + "inputs": [ + { + "name": "A", + "type": "T", + "description": "First input operand for the logical operator." + }, + { + "name": "B", + "type": "T", + "description": "Second input operand for the logical operator." + } + ], + "min_input": 2, + "max_input": 2, + "outputs": [ + { + "name": "C", + "type": "T1", + "description": "Result tensor." + } + ], + "min_output": 1, + "max_output": 1, + "type_constraints": [ + { + "description": "Constrains input types to all numeric tensors.", + "type_param_str": "T", + "allowed_type_strs": [ + "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)" + ] + }, + { + "description": "Constrains output to boolean tensor.", + "type_param_str": "T1", + "allowed_type_strs": [ + "tensor(bool)" + ] + } + ], + "examples": [ + { + "summary": "equal", + "code": "node = onnx.helper.make_node(\n 'Equal',\n inputs=['x', 'y'],\n outputs=['z'],\n)\n\nx = (np.random.randn(3, 4, 5) * 10).astype(np.int32)\ny = (np.random.randn(3, 4, 5) * 10).astype(np.int32)\nz = np.equal(x, y)\nexpect(node, inputs=[x, y], outputs=[z],\n name='test_equal')" + }, + { + "summary": "equal_broadcast", + "code": "node = onnx.helper.make_node(\n 'Equal',\n inputs=['x', 'y'],\n outputs=['z'],\n)\n\nx = (np.random.randn(3, 4, 5) * 10).astype(np.int32)\ny = (np.random.randn(5) * 10).astype(np.int32)\nz = np.equal(x, y)\nexpect(node, inputs=[x, y], outputs=[z],\n name='test_equal_bcast')" + } + ], + "category": "Logic" + }, + { + "name": "Erf", + "module": "ai.onnx", + "version": 9, + "support_level": "common", + "description": "Computes the error function of the given input tensor element-wise.\n", + "inputs": [ + { + "name": "input", + "type": "T", + "description": "Input tensor" + } + ], + "min_input": 1, + "max_input": 1, + "outputs": [ + { + "name": "output", + "type": "T", + "description": "The error function of the input tensor computed element-wise. It has the same shape and type of the input." + } + ], + "min_output": 1, + "max_output": 1, + "type_constraints": [ + { + "description": "Constrain input and output types to all numeric tensors.", + "type_param_str": "T", + "allowed_type_strs": [ + "tensor(uint8)", + "tensor(uint16)", + "tensor(uint32)", + "tensor(uint64)", + "tensor(int8)", + "tensor(int16)", + "tensor(int32)", + "tensor(int64)", + "tensor(float16)", + "tensor(float)", + "tensor(double)" + ] + } + ], + "examples": [ + { + "summary": "erf", + "code": "node = onnx.helper.make_node(\n 'Erf',\n inputs=['x'],\n outputs=['y'],\n)\n\nx = np.random.randn(1, 3, 32, 32).astype(np.float32)\ny = np.vectorize(math.erf)(x).astype(np.float32)\nexpect(node, inputs=[x], outputs=[y],\n name='test_erf')" + } + ] + }, + { + "name": "Erf", + "module": "ai.onnx", + "version": 13, + "support_level": "common", + "description": "Computes the error function of the given input tensor element-wise.\n", + "inputs": [ + { + "name": "input", + "type": "T", + "description": "Input tensor" + } + ], + "min_input": 1, + "max_input": 1, + "outputs": [ + { + "name": "output", + "type": "T", + "description": "The error function of the input tensor computed element-wise. It has the same shape and type of the input." + } + ], + "min_output": 1, + "max_output": 1, + "type_constraints": [ + { + "description": "Constrain input and output types to all numeric tensors.", + "type_param_str": "T", + "allowed_type_strs": [ + "tensor(uint8)", + "tensor(uint16)", + "tensor(uint32)", + "tensor(uint64)", + "tensor(int8)", + "tensor(int16)", + "tensor(int32)", + "tensor(int64)", + "tensor(float16)", + "tensor(float)", + "tensor(double)", + "tensor(bfloat16)" + ] + } + ], + "examples": [ + { + "summary": "erf", + "code": "node = onnx.helper.make_node(\n 'Erf',\n inputs=['x'],\n outputs=['y'],\n)\n\nx = np.random.randn(1, 3, 32, 32).astype(np.float32)\ny = np.vectorize(math.erf)(x).astype(np.float32)\nexpect(node, inputs=[x], outputs=[y],\n name='test_erf')" + } + ] + }, + { + "name": "Exp", + "module": "ai.onnx", + "version": 1, + "support_level": "common", + "description": "Calculates the exponential of the given input tensor, element-wise.\n", + "attributes": [ + { + "name": "consumed_inputs", + "type": "int64[]", + "required": false, + "description": "legacy optimization attribute." + } + ], + "inputs": [ + { + "name": "input", + "type": "T", + "description": "Input tensor" + } + ], + "min_input": 1, + "max_input": 1, + "outputs": [ + { + "name": "output", + "type": "T", + "description": "The exponential of the input tensor computed element-wise" + } + ], + "min_output": 1, + "max_output": 1, + "type_constraints": [ + { + "description": "Constrain input and output types to float tensors.", + "type_param_str": "T", + "allowed_type_strs": [ + "tensor(float16)", + "tensor(float)", + "tensor(double)" + ] + } + ], + "examples": [ + { + "summary": "exp", + "code": "node = onnx.helper.make_node(\n 'Exp',\n inputs=['x'],\n outputs=['y'],\n)\n\nx = np.array([-1, 0, 1]).astype(np.float32)\ny = np.exp(x) # expected output [0.36787945, 1., 2.71828175]\nexpect(node, inputs=[x], outputs=[y],\n name='test_exp_example')\n\nx = np.random.randn(3, 4, 5).astype(np.float32)\ny = np.exp(x)\nexpect(node, inputs=[x], outputs=[y],\n name='test_exp')" + } + ] + }, + { + "name": "Exp", + "module": "ai.onnx", + "version": 6, + "support_level": "common", + "description": "Calculates the exponential of the given input tensor, element-wise.\n", + "inputs": [ + { + "name": "input", + "type": "T", + "description": "Input tensor" + } + ], + "min_input": 1, + "max_input": 1, + "outputs": [ + { + "name": "output", + "type": "T", + "description": "The exponential of the input tensor computed element-wise" + } + ], + "min_output": 1, + "max_output": 1, + "type_constraints": [ + { + "description": "Constrain input and output types to float tensors.", + "type_param_str": "T", + "allowed_type_strs": [ + "tensor(float16)", + "tensor(float)", + "tensor(double)" + ] + } + ], + "examples": [ + { + "summary": "exp", + "code": "node = onnx.helper.make_node(\n 'Exp',\n inputs=['x'],\n outputs=['y'],\n)\n\nx = np.array([-1, 0, 1]).astype(np.float32)\ny = np.exp(x) # expected output [0.36787945, 1., 2.71828175]\nexpect(node, inputs=[x], outputs=[y],\n name='test_exp_example')\n\nx = np.random.randn(3, 4, 5).astype(np.float32)\ny = np.exp(x)\nexpect(node, inputs=[x], outputs=[y],\n name='test_exp')" + } + ] + }, + { + "name": "Exp", + "module": "ai.onnx", + "version": 13, + "support_level": "common", + "description": "Calculates the exponential of the given input tensor, element-wise.\n", + "inputs": [ + { + "name": "input", + "type": "T", + "description": "Input tensor" + } + ], + "min_input": 1, + "max_input": 1, + "outputs": [ + { + "name": "output", + "type": "T", + "description": "The exponential of the input tensor computed element-wise" + } + ], + "min_output": 1, + "max_output": 1, + "type_constraints": [ + { + "description": "Constrain input and output types to float tensors.", + "type_param_str": "T", + "allowed_type_strs": [ + "tensor(float16)", + "tensor(float)", + "tensor(double)", + "tensor(bfloat16)" + ] + } + ], + "examples": [ + { + "summary": "exp", + "code": "node = onnx.helper.make_node(\n 'Exp',\n inputs=['x'],\n outputs=['y'],\n)\n\nx = np.array([-1, 0, 1]).astype(np.float32)\ny = np.exp(x) # expected output [0.36787945, 1., 2.71828175]\nexpect(node, inputs=[x], outputs=[y],\n name='test_exp_example')\n\nx = np.random.randn(3, 4, 5).astype(np.float32)\ny = np.exp(x)\nexpect(node, inputs=[x], outputs=[y],\n name='test_exp')" + } + ] + }, + { + "name": "Expand", + "module": "ai.onnx", + "version": 8, + "support_level": "common", + "description": "Broadcast the input tensor following the given shape and the broadcast rule.\nThe broadcast rule is similar to numpy.array(input) * numpy.ones(shape):\nDimensions are right alignment;\nTwo corresponding dimension must have the same value, or one of them is equal to 1.\nAlso, this operator is similar to numpy.broadcast_to(input, shape),\nbut the major difference is numpy.broadcast_to() does not allow shape to be smaller than input.size().\nIt is possible that the output.shape is not equal to shape, when some dimensions in shape is equal to 1,\nor the shape.ndim < input.shape.ndim.\n", + "inputs": [ + { + "name": "input", + "type": "T", + "description": "Input tensor" + }, + { + "name": "shape", + "type": "tensor(int64)", + "description": "A 1-D tensor indicates the shape you want to expand to, following the broadcast rule" + } + ], + "min_input": 2, + "max_input": 2, + "outputs": [ + { + "name": "output", + "type": "T", + "description": "Output tensor" + } + ], + "min_output": 1, + "max_output": 1, + "type_constraints": [ + { + "description": "Constrain input and output types to all tensors.", + "type_param_str": "T", + "allowed_type_strs": [ + "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)" + ] + } + ], + "examples": [ + { + "summary": "dim_changed", + "code": "node = onnx.helper.make_node(\n 'Expand',\n inputs=['data', 'new_shape'],\n outputs=['expanded'],\n)\nshape = [3, 1]\ndata = np.reshape(np.arange(1, np.prod(shape) + 1, dtype=np.float32), shape)\n#print(data)\n#[[1.], [2.], [3.]]\nnew_shape = [2, 1, 6]\nexpanded = data * np.ones(new_shape, dtype=np.float32)\n#print(expanded)\n#[[[1., 1., 1., 1., 1., 1.],\n# [2., 2., 2., 2., 2., 2.],\n# [3., 3., 3., 3., 3., 3.]],\n#\n# [[1., 1., 1., 1., 1., 1.],\n# [2., 2., 2., 2., 2., 2.],\n# [3., 3., 3., 3., 3., 3.]]]\nnew_shape = np.array(new_shape, dtype=np.int64)\nexpect(node, inputs=[data, new_shape], outputs=[expanded],\n name='test_expand_dim_changed')" + }, + { + "summary": "dim_unchanged", + "code": "node = onnx.helper.make_node(\n 'Expand',\n inputs=['data', 'new_shape'],\n outputs=['expanded'],\n)\nshape = [3, 1]\nnew_shape = [3, 4]\ndata = np.reshape(np.arange(1, np.prod(shape) + 1, dtype=np.float32), shape)\n#print(data)\n#[[1.], [2.], [3.]]\nexpanded = np.tile(data, 4)\n#print(expanded)\n#[[1., 1., 1., 1.],\n# [2., 2., 2., 2.],\n# [3., 3., 3., 3.]]\nnew_shape = np.array(new_shape, dtype=np.int64)\nexpect(node, inputs=[data, new_shape], outputs=[expanded],\n name='test_expand_dim_unchanged')" + } + ] + }, + { + "name": "Expand", + "module": "ai.onnx", + "version": 13, + "support_level": "common", + "description": "Broadcast the input tensor following the given shape and the broadcast rule.\nThe broadcast rule is similar to numpy.array(input) * numpy.ones(shape):\nDimensions are right alignment;\nTwo corresponding dimension must have the same value, or one of them is equal to 1.\nAlso, this operator is similar to numpy.broadcast_to(input, shape),\nbut the major difference is numpy.broadcast_to() does not allow shape to be smaller than input.size().\nIt is possible that the output.shape is not equal to shape, when some dimensions in shape is equal to 1,\nor the shape.ndim < input.shape.ndim.\n", + "inputs": [ + { + "name": "input", + "type": "T", + "description": "Input tensor" + }, + { + "name": "shape", + "type": "tensor(int64)", + "description": "A 1-D tensor indicates the shape you want to expand to, following the broadcast rule" + } + ], + "min_input": 2, + "max_input": 2, + "outputs": [ + { + "name": "output", + "type": "T", + "description": "Output tensor" + } + ], + "min_output": 1, + "max_output": 1, + "type_constraints": [ + { + "description": "Constrain input and output types to all tensors.", + "type_param_str": "T", + "allowed_type_strs": [ + "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)" + ] + } + ], + "examples": [ + { + "summary": "dim_changed", + "code": "node = onnx.helper.make_node(\n 'Expand',\n inputs=['data', 'new_shape'],\n outputs=['expanded'],\n)\nshape = [3, 1]\ndata = np.reshape(np.arange(1, np.prod(shape) + 1, dtype=np.float32), shape)\n#print(data)\n#[[1.], [2.], [3.]]\nnew_shape = [2, 1, 6]\nexpanded = data * np.ones(new_shape, dtype=np.float32)\n#print(expanded)\n#[[[1., 1., 1., 1., 1., 1.],\n# [2., 2., 2., 2., 2., 2.],\n# [3., 3., 3., 3., 3., 3.]],\n#\n# [[1., 1., 1., 1., 1., 1.],\n# [2., 2., 2., 2., 2., 2.],\n# [3., 3., 3., 3., 3., 3.]]]\nnew_shape = np.array(new_shape, dtype=np.int64)\nexpect(node, inputs=[data, new_shape], outputs=[expanded],\n name='test_expand_dim_changed')" + }, + { + "summary": "dim_unchanged", + "code": "node = onnx.helper.make_node(\n 'Expand',\n inputs=['data', 'new_shape'],\n outputs=['expanded'],\n)\nshape = [3, 1]\nnew_shape = [3, 4]\ndata = np.reshape(np.arange(1, np.prod(shape) + 1, dtype=np.float32), shape)\n#print(data)\n#[[1.], [2.], [3.]]\nexpanded = np.tile(data, 4)\n#print(expanded)\n#[[1., 1., 1., 1.],\n# [2., 2., 2., 2.],\n# [3., 3., 3., 3.]]\nnew_shape = np.array(new_shape, dtype=np.int64)\nexpect(node, inputs=[data, new_shape], outputs=[expanded],\n name='test_expand_dim_unchanged')" + } + ] + }, + { + "name": "EyeLike", + "module": "ai.onnx", + "version": 9, + "support_level": "common", + "description": "Generate a 2D tensor (matrix) with ones on the diagonal and zeros everywhere else. Only 2D\ntensors are supported, i.e. input T1 must be of rank 2. The shape of the output tensor is the\nsame as the input tensor. The data type can be specified by the 'dtype' argument. If\n'dtype' is not specified, then the type of input tensor is used. By default, the main diagonal\nis populated with ones, but attribute 'k' can be used to populate upper or lower diagonals.\nThe 'dtype' argument must be one of the data types specified in the 'DataType' enum field in the\nTensorProto message and be valid as an output type.\n", + "attributes": [ + { + "name": "dtype", + "type": "DataType", + "required": false, + "description": "(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'." + }, + { + "name": "k", + "type": "int64", + "required": false, + "description": "(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": [ + { + "name": "input", + "type": "T1", + "description": "2D input tensor to copy shape, and optionally, type information from." + } + ], + "min_input": 1, + "max_input": 1, + "outputs": [ + { + "name": "output", + "type": "T2", + "description": "Output tensor, same shape as input tensor T1." + } + ], + "min_output": 1, + "max_output": 1, + "type_constraints": [ + { + "description": "Constrain input types. Strings and complex are not supported.", + "type_param_str": "T1", + "allowed_type_strs": [ + "tensor(float16)", + "tensor(float)", + "tensor(double)", + "tensor(int8)", + "tensor(int16)", + "tensor(int32)", + "tensor(int64)", + "tensor(uint8)", + "tensor(uint16)", + "tensor(uint32)", + "tensor(uint64)", + "tensor(bool)" + ] + }, + { + "description": "Constrain output types. Strings and complex are not supported.", + "type_param_str": "T2", + "allowed_type_strs": [ + "tensor(float16)", + "tensor(float)", + "tensor(double)", + "tensor(int8)", + "tensor(int16)", + "tensor(int32)", + "tensor(int64)", + "tensor(uint8)", + "tensor(uint16)", + "tensor(uint32)", + "tensor(uint64)", + "tensor(bool)" + ] + } + ], + "examples": [ + { + "summary": "populate_off_main_diagonal", + "code": "shape = (4, 5)\noff_diagonal_offset = 1\nnode = onnx.helper.make_node(\n 'EyeLike',\n inputs=['x'],\n outputs=['y'],\n k=off_diagonal_offset,\n dtype=onnx.TensorProto.FLOAT,\n)\n\nx = np.random.randint(0, 100, size=shape, dtype=np.int32)\ny = np.eye(shape[0], shape[1], k=off_diagonal_offset, dtype=np.float32)\nexpect(node, inputs=[x], outputs=[y], name='test_eyelike_populate_off_main_diagonal')" + }, + { + "summary": "with_dtype", + "code": "shape = (3, 4)\nnode = onnx.helper.make_node(\n 'EyeLike',\n inputs=['x'],\n outputs=['y'],\n dtype=onnx.TensorProto.DOUBLE,\n)\n\nx = np.random.randint(0, 100, size=shape, dtype=np.int32)\ny = np.eye(shape[0], shape[1], dtype=np.float64)\nexpect(node, inputs=[x], outputs=[y], name='test_eyelike_with_dtype')" + }, + { + "summary": "without_dtype", + "code": "shape = (4, 4)\nnode = onnx.helper.make_node(\n 'EyeLike',\n inputs=['x'],\n outputs=['y'],\n)\n\nx = np.random.randint(0, 100, size=shape, dtype=np.int32)\ny = np.eye(shape[0], shape[1], dtype=np.int32)\nexpect(node, inputs=[x], outputs=[y], name='test_eyelike_without_dtype')" + } + ] + }, + { + "name": "FeatureVectorizer", + "module": "ai.onnx.ml", + "version": 1, + "support_level": "common", + "description": "Concatenates input tensors into one continuous output.
\n All input shapes are 2-D and are concatenated along the second dimention. 1-D tensors are treated as [1,C].\n Inputs are copied to the output maintaining the order of the input arguments.
\n All inputs must be integers or floats, while the output will be all floating point values.\n", + "attributes": [ + { + "name": "inputdimensions", + "type": "int64[]", + "required": false, + "description": "The size of each input in the input list" + } + ], + "inputs": [ + { + "name": "X", + "type": "T1", + "list": true, + "description": "An ordered collection of tensors, all with the same element type." + } + ], + "min_input": 1, + "max_input": 2147483647, + "outputs": [ + { + "name": "Y", + "type": "tensor(float)", + "description": "The output array, elements ordered as the inputs." + } + ], + "min_output": 1, + "max_output": 1, + "inputs_range": "1 - ∞", + "type_constraints": [ + { + "description": "The input type must be a tensor of a numeric type.", + "type_param_str": "T1", + "allowed_type_strs": [ + "tensor(int32)", + "tensor(int64)", + "tensor(float)", + "tensor(double)" + ] + } + ] + }, + { + "name": "Flatten", + "module": "ai.onnx", + "version": 1, + "support_level": "common", + "description": "Flattens the input tensor into a 2D matrix. If input tensor has shape\n(d_0, d_1, ... d_n) then the output will have shape\n(d_0 X d_1 ... d_(axis-1), d_axis X d_(axis+1) ... X dn).\n", + "attributes": [ + { + "name": "axis", + "type": "int64", + "required": false, + "default": 1, + "description": "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": [ + { + "name": "input", + "type": "T", + "description": "A tensor of rank >= axis." + } + ], + "min_input": 1, + "max_input": 1, + "outputs": [ + { + "name": "output", + "type": "T", + "description": "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." + } + ], + "min_output": 1, + "max_output": 1, + "type_constraints": [ + { + "description": "Constrain input and output types to float tensors.", + "type_param_str": "T", + "allowed_type_strs": [ + "tensor(float16)", + "tensor(float)", + "tensor(double)" + ] + } + ], + "examples": [ + { + "summary": "flatten", + "code": "shape = (2, 3, 4, 5)\na = np.random.random_sample(shape).astype(np.float32)\n\nfor i in range(len(shape)):\n node = onnx.helper.make_node(\n 'Flatten',\n inputs=['a'],\n outputs=['b'],\n axis=i,\n )\n\n new_shape = (1, -1) if i == 0 else (np.prod(shape[0:i]).astype(int), -1)\n b = np.reshape(a, new_shape)\n expect(node, inputs=[a], outputs=[b],\n name='test_flatten_axis' + str(i))" + }, + { + "summary": "flatten_negative_axis", + "code": "shape = (2, 3, 4, 5)\na = np.random.random_sample(shape).astype(np.float32)\n\nfor i in range(-len(shape), 0):\n node = onnx.helper.make_node(\n 'Flatten',\n inputs=['a'],\n outputs=['b'],\n axis=i,\n )\n\n new_shape = (np.prod(shape[0:i]).astype(int), -1)\n b = np.reshape(a, new_shape)\n expect(node, inputs=[a], outputs=[b],\n name='test_flatten_negative_axis' + str(abs(i)))" + }, + { + "summary": "flatten_with_default_axis", + "code": "node = onnx.helper.make_node(\n 'Flatten',\n inputs=['a'],\n outputs=['b'], # Default value for axis: axis=1\n)\n\nshape = (5, 4, 3, 2)\na = np.random.random_sample(shape).astype(np.float32)\nnew_shape = (5, 24)\nb = np.reshape(a, new_shape)\nexpect(node, inputs=[a], outputs=[b],\n name='test_flatten_default_axis')" + } + ], + "category": "Shape" + }, + { + "name": "Flatten", + "module": "ai.onnx", + "version": 9, + "support_level": "common", + "description": "Flattens the input tensor into a 2D matrix. If input tensor has shape\n(d_0, d_1, ... d_n) then the output will have shape\n(d_0 X d_1 ... d_(axis-1), d_axis X d_(axis+1) ... X dn).\n", + "attributes": [ + { + "name": "axis", + "type": "int64", + "required": false, + "default": 1, + "description": "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": [ + { + "name": "input", + "type": "T", + "description": "A tensor of rank >= axis." + } + ], + "min_input": 1, + "max_input": 1, + "outputs": [ + { + "name": "output", + "type": "T", + "description": "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." + } + ], + "min_output": 1, + "max_output": 1, + "type_constraints": [ + { + "description": "Constrain input and output to all tensor types.", + "type_param_str": "T", + "allowed_type_strs": [ + "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)" + ] + } + ], + "examples": [ + { + "summary": "flatten", + "code": "shape = (2, 3, 4, 5)\na = np.random.random_sample(shape).astype(np.float32)\n\nfor i in range(len(shape)):\n node = onnx.helper.make_node(\n 'Flatten',\n inputs=['a'],\n outputs=['b'],\n axis=i,\n )\n\n new_shape = (1, -1) if i == 0 else (np.prod(shape[0:i]).astype(int), -1)\n b = np.reshape(a, new_shape)\n expect(node, inputs=[a], outputs=[b],\n name='test_flatten_axis' + str(i))" + }, + { + "summary": "flatten_negative_axis", + "code": "shape = (2, 3, 4, 5)\na = np.random.random_sample(shape).astype(np.float32)\n\nfor i in range(-len(shape), 0):\n node = onnx.helper.make_node(\n 'Flatten',\n inputs=['a'],\n outputs=['b'],\n axis=i,\n )\n\n new_shape = (np.prod(shape[0:i]).astype(int), -1)\n b = np.reshape(a, new_shape)\n expect(node, inputs=[a], outputs=[b],\n name='test_flatten_negative_axis' + str(abs(i)))" + }, + { + "summary": "flatten_with_default_axis", + "code": "node = onnx.helper.make_node(\n 'Flatten',\n inputs=['a'],\n outputs=['b'], # Default value for axis: axis=1\n)\n\nshape = (5, 4, 3, 2)\na = np.random.random_sample(shape).astype(np.float32)\nnew_shape = (5, 24)\nb = np.reshape(a, new_shape)\nexpect(node, inputs=[a], outputs=[b],\n name='test_flatten_default_axis')" + } + ], + "category": "Shape" + }, + { + "name": "Flatten", + "module": "ai.onnx", + "version": 11, + "support_level": "common", + "description": "Flattens the input tensor into a 2D matrix. If input tensor has shape\n(d_0, d_1, ... d_n) then the output will have shape\n(d_0 X d_1 ... d_(axis-1), d_axis X d_(axis+1) ... X dn).\n", + "attributes": [ + { + "name": "axis", + "type": "int64", + "required": false, + "default": 1, + "description": "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": [ + { + "name": "input", + "type": "T", + "description": "A tensor of rank >= axis." + } + ], + "min_input": 1, + "max_input": 1, + "outputs": [ + { + "name": "output", + "type": "T", + "description": "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." + } + ], + "min_output": 1, + "max_output": 1, + "type_constraints": [ + { + "description": "Constrain input and output to all tensor types.", + "type_param_str": "T", + "allowed_type_strs": [ + "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)" + ] + } + ], + "examples": [ + { + "summary": "flatten", + "code": "shape = (2, 3, 4, 5)\na = np.random.random_sample(shape).astype(np.float32)\n\nfor i in range(len(shape)):\n node = onnx.helper.make_node(\n 'Flatten',\n inputs=['a'],\n outputs=['b'],\n axis=i,\n )\n\n new_shape = (1, -1) if i == 0 else (np.prod(shape[0:i]).astype(int), -1)\n b = np.reshape(a, new_shape)\n expect(node, inputs=[a], outputs=[b],\n name='test_flatten_axis' + str(i))" + }, + { + "summary": "flatten_negative_axis", + "code": "shape = (2, 3, 4, 5)\na = np.random.random_sample(shape).astype(np.float32)\n\nfor i in range(-len(shape), 0):\n node = onnx.helper.make_node(\n 'Flatten',\n inputs=['a'],\n outputs=['b'],\n axis=i,\n )\n\n new_shape = (np.prod(shape[0:i]).astype(int), -1)\n b = np.reshape(a, new_shape)\n expect(node, inputs=[a], outputs=[b],\n name='test_flatten_negative_axis' + str(abs(i)))" + }, + { + "summary": "flatten_with_default_axis", + "code": "node = onnx.helper.make_node(\n 'Flatten',\n inputs=['a'],\n outputs=['b'], # Default value for axis: axis=1\n)\n\nshape = (5, 4, 3, 2)\na = np.random.random_sample(shape).astype(np.float32)\nnew_shape = (5, 24)\nb = np.reshape(a, new_shape)\nexpect(node, inputs=[a], outputs=[b],\n name='test_flatten_default_axis')" + } + ], + "category": "Shape" + }, + { + "name": "Flatten", + "module": "ai.onnx", + "version": 13, + "support_level": "common", + "description": "Flattens the input tensor into a 2D matrix. If input tensor has shape\n(d_0, d_1, ... d_n) then the output will have shape\n(d_0 X d_1 ... d_(axis-1), d_axis X d_(axis+1) ... X dn).\n", + "attributes": [ + { + "name": "axis", + "type": "int64", + "required": false, + "default": 1, + "description": "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": [ + { + "name": "input", + "type": "T", + "description": "A tensor of rank >= axis." + } + ], + "min_input": 1, + "max_input": 1, + "outputs": [ + { + "name": "output", + "type": "T", + "description": "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." + } + ], + "min_output": 1, + "max_output": 1, + "type_constraints": [ + { + "description": "Constrain input and output to all tensor types.", + "type_param_str": "T", + "allowed_type_strs": [ + "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)" + ] + } + ], + "examples": [ + { + "summary": "flatten", + "code": "shape = (2, 3, 4, 5)\na = np.random.random_sample(shape).astype(np.float32)\n\nfor i in range(len(shape)):\n node = onnx.helper.make_node(\n 'Flatten',\n inputs=['a'],\n outputs=['b'],\n axis=i,\n )\n\n new_shape = (1, -1) if i == 0 else (np.prod(shape[0:i]).astype(int), -1)\n b = np.reshape(a, new_shape)\n expect(node, inputs=[a], outputs=[b],\n name='test_flatten_axis' + str(i))" + }, + { + "summary": "flatten_negative_axis", + "code": "shape = (2, 3, 4, 5)\na = np.random.random_sample(shape).astype(np.float32)\n\nfor i in range(-len(shape), 0):\n node = onnx.helper.make_node(\n 'Flatten',\n inputs=['a'],\n outputs=['b'],\n axis=i,\n )\n\n new_shape = (np.prod(shape[0:i]).astype(int), -1)\n b = np.reshape(a, new_shape)\n expect(node, inputs=[a], outputs=[b],\n name='test_flatten_negative_axis' + str(abs(i)))" + }, + { + "summary": "flatten_with_default_axis", + "code": "node = onnx.helper.make_node(\n 'Flatten',\n inputs=['a'],\n outputs=['b'], # Default value for axis: axis=1\n)\n\nshape = (5, 4, 3, 2)\na = np.random.random_sample(shape).astype(np.float32)\nnew_shape = (5, 24)\nb = np.reshape(a, new_shape)\nexpect(node, inputs=[a], outputs=[b],\n name='test_flatten_default_axis')" + } + ], + "category": "Shape" + }, + { + "name": "Floor", + "module": "ai.onnx", + "version": 1, + "support_level": "common", + "description": "Floor takes one input data (Tensor) and produces one output data\n(Tensor) where the floor is, y = floor(x), is applied to\nthe tensor elementwise.\n", + "attributes": [ + { + "name": "consumed_inputs", + "type": "int64[]", + "required": false, + "description": "legacy optimization attribute." + } + ], + "inputs": [ + { + "name": "X", + "type": "T", + "description": "Input tensor" + } + ], + "min_input": 1, + "max_input": 1, + "outputs": [ + { + "name": "Y", + "type": "T", + "description": "Output tensor" + } + ], + "min_output": 1, + "max_output": 1, + "type_constraints": [ + { + "description": "Constrain input and output types to float tensors.", + "type_param_str": "T", + "allowed_type_strs": [ + "tensor(float16)", + "tensor(float)", + "tensor(double)" + ] + } + ], + "examples": [ + { + "summary": "floor", + "code": "node = onnx.helper.make_node(\n 'Floor',\n inputs=['x'],\n outputs=['y'],\n)\n\nx = np.array([-1.5, 1.2, 2]).astype(np.float32)\ny = np.floor(x) # expected output [-2., 1., 2.]\nexpect(node, inputs=[x], outputs=[y],\n name='test_floor_example')\n\nx = np.random.randn(3, 4, 5).astype(np.float32)\ny = np.floor(x)\nexpect(node, inputs=[x], outputs=[y],\n name='test_floor')" + } + ] + }, + { + "name": "Floor", + "module": "ai.onnx", + "version": 6, + "support_level": "common", + "description": "Floor takes one input data (Tensor) and produces one output data\n(Tensor) where the floor is, y = floor(x), is applied to\nthe tensor elementwise.\n", + "inputs": [ + { + "name": "X", + "type": "T", + "description": "Input tensor" + } + ], + "min_input": 1, + "max_input": 1, + "outputs": [ + { + "name": "Y", + "type": "T", + "description": "Output tensor" + } + ], + "min_output": 1, + "max_output": 1, + "type_constraints": [ + { + "description": "Constrain input and output types to float tensors.", + "type_param_str": "T", + "allowed_type_strs": [ + "tensor(float16)", + "tensor(float)", + "tensor(double)" + ] + } + ], + "examples": [ + { + "summary": "floor", + "code": "node = onnx.helper.make_node(\n 'Floor',\n inputs=['x'],\n outputs=['y'],\n)\n\nx = np.array([-1.5, 1.2, 2]).astype(np.float32)\ny = np.floor(x) # expected output [-2., 1., 2.]\nexpect(node, inputs=[x], outputs=[y],\n name='test_floor_example')\n\nx = np.random.randn(3, 4, 5).astype(np.float32)\ny = np.floor(x)\nexpect(node, inputs=[x], outputs=[y],\n name='test_floor')" + } + ] + }, + { + "name": "Floor", + "module": "ai.onnx", + "version": 13, + "support_level": "common", + "description": "Floor takes one input data (Tensor) and produces one output data\n(Tensor) where the floor is, y = floor(x), is applied to\nthe tensor elementwise.\n", + "inputs": [ + { + "name": "X", + "type": "T", + "description": "Input tensor" + } + ], + "min_input": 1, + "max_input": 1, + "outputs": [ + { + "name": "Y", + "type": "T", + "description": "Output tensor" + } + ], + "min_output": 1, + "max_output": 1, + "type_constraints": [ + { + "description": "Constrain input and output types to float tensors.", + "type_param_str": "T", + "allowed_type_strs": [ + "tensor(float16)", + "tensor(float)", + "tensor(double)", + "tensor(bfloat16)" + ] + } + ], + "examples": [ + { + "summary": "floor", + "code": "node = onnx.helper.make_node(\n 'Floor',\n inputs=['x'],\n outputs=['y'],\n)\n\nx = np.array([-1.5, 1.2, 2]).astype(np.float32)\ny = np.floor(x) # expected output [-2., 1., 2.]\nexpect(node, inputs=[x], outputs=[y],\n name='test_floor_example')\n\nx = np.random.randn(3, 4, 5).astype(np.float32)\ny = np.floor(x)\nexpect(node, inputs=[x], outputs=[y],\n name='test_floor')" + } + ] + }, + { + "name": "GRU", + "module": "ai.onnx", + "version": 1, + "support_level": "common", + "description": "Computes an one-layer GRU. This operator is usually supported via some custom\nimplementation such as CuDNN.\n\nNotations:\n\n`X` - input tensor\n\n`z` - update gate\n\n`r` - reset gate\n\n`h` - hidden gate\n\n`t` - time step (t-1 means previous time step)\n\n`W[zrh]` - W parameter weight matrix for update, reset, and hidden gates\n\n`R[zrh]` - R recurrence weight matrix for update, reset, and hidden gates\n\n`Wb[zrh]` - W bias vectors for update, reset, and hidden gates\n\n`Rb[zrh]` - R bias vectors for update, reset, and hidden gates\n\n`WB[zrh]` - W parameter weight matrix for backward update, reset, and hidden gates\n\n`RB[zrh]` - R recurrence weight matrix for backward update, reset, and hidden gates\n\n`WBb[zrh]` - W bias vectors for backward update, reset, and hidden gates\n\n`RBb[zrh]` - R bias vectors for backward update, reset, and hidden gates\n\n`H` - Hidden state\n\n`num_directions` - 2 if direction == bidirectional else 1\n\nActivation functions:\n\n Relu(x) - max(0, x)\n\n Tanh(x) - (1 - e^{-2x})/(1 + e^{-2x})\n\n Sigmoid(x) - 1/(1 + e^{-x})\n\n (NOTE: Below are optional)\n\n Affine(x) - alpha*x + beta\n\n LeakyRelu(x) - x if x >= 0 else alpha * x\n\n ThresholdedRelu(x) - x if x >= alpha else 0\n\n ScaledTanh(x) - alpha*Tanh(beta*x)\n\n HardSigmoid(x) - min(max(alpha*x + beta, 0), 1)\n\n Elu(x) - x if x >= 0 else alpha*(e^x - 1)\n\n Softsign(x) - x/(1 + |x|)\n\n Softplus(x) - log(1 + e^x)\n\nEquations (Default: f=Sigmoid, g=Tanh):\n\n - zt = f(Xt*(Wz^T) + Ht-1*Rz + Wbz + Rbz)\n\n - rt = f(Xt*(Wr^T) + Ht-1*Rr + Wbr + Rbr)\n\n - ht = g(Xt*(Wh^T) + (rt (.) Ht-1)*Rh + Rbh + Wbh) # default, when linear_before_reset = 0\n\n - ht = g(Xt*(Wh^T) + (rt (.) (Ht-1*Rh + Rbh) + Wbh) # when linear_before_reset != 0\n\n - Ht = (1 - zt) (.) ht + zt (.) Ht-1\n", + "attributes": [ + { + "name": "activation_alpha", + "type": "float32[]", + "required": false, + "description": "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." + }, + { + "name": "activation_beta", + "type": "float32[]", + "required": false, + "description": "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." + }, + { + "name": "activations", + "type": "string[]", + "required": false, + "description": "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." + }, + { + "name": "clip", + "type": "float32", + "required": false, + "description": "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." + }, + { + "name": "direction", + "type": "string", + "required": false, + "default": "foward", + "description": "Specify if the RNN is forward, reverse, or bidirectional. Must be one of forward (default), reverse, or bidirectional." + }, + { + "name": "hidden_size", + "type": "int64", + "required": false, + "description": "Number of neurons in the hidden layer" + }, + { + "name": "output_sequence", + "type": "int64", + "required": false, + "description": "The sequence output for the hidden is optional if 0. Default 0." + } + ], + "inputs": [ + { + "name": "X", + "type": "T", + "description": "The input sequences packed (and potentially padded) into one 3-D tensor with the shape of `[seq_length, batch_size, input_size]`." + }, + { + "name": "W", + "type": "T", + "description": "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]`." + }, + { + "name": "R", + "type": "T", + "description": "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]`." + }, + { + "name": "B", + "type": "T", + "option": "optional", + "description": "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" + }, + { + "name": "sequence_lens", + "type": "T1", + "option": "optional", + "description": "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]`." + }, + { + "name": "initial_h", + "type": "T", + "option": "optional", + "description": "Optional initial value of the hidden. If not specified - assumed to be 0. It has shape `[num_directions, batch_size, hidden_size]`." + } + ], + "min_input": 3, + "max_input": 6, + "outputs": [ + { + "name": "Y", + "type": "T", + "option": "optional", + "description": "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." + }, + { + "name": "Y_h", + "type": "T", + "description": "The last output value of the hidden. It has shape `[num_directions, batch_size, hidden_size]`." + } + ], + "min_output": 2, + "max_output": 2, + "inputs_range": "3 - 6", + "type_constraints": [ + { + "description": "Constrain input and output types to float tensors.", + "type_param_str": "T", + "allowed_type_strs": [ + "tensor(float16)", + "tensor(float)", + "tensor(double)" + ] + }, + { + "description": "Constrain seq_lens to integer tensor.", + "type_param_str": "T1", + "allowed_type_strs": [ + "tensor(int32)" + ] + } + ], + "examples": [ + { + "summary": "batchwise", + "code": "input = np.array([[[1., 2.]], [[3., 4.]], [[5., 6.]]]).astype(np.float32)\n\ninput_size = 2\nhidden_size = 6\nnumber_of_gates = 3\nweight_scale = 0.2\nlayout = 1\n\nnode = onnx.helper.make_node(\n 'GRU',\n inputs=['X', 'W', 'R'],\n outputs=['Y', 'Y_h'],\n hidden_size=hidden_size,\n layout=layout\n)\n\nW = weight_scale * np.ones((1, number_of_gates * hidden_size, input_size)).astype(np.float32)\nR = weight_scale * np.ones((1, number_of_gates * hidden_size, hidden_size)).astype(np.float32)\n\ngru = GRU_Helper(X=input, W=W, R=R, layout=layout)\nY, Y_h = gru.step()\nexpect(node, inputs=[input, W, R], outputs=[Y.astype(np.float32), Y_h.astype(np.float32)], name='test_gru_batchwise')" + }, + { + "summary": "defaults", + "code": "input = np.array([[[1., 2.], [3., 4.], [5., 6.]]]).astype(np.float32)\n\ninput_size = 2\nhidden_size = 5\nweight_scale = 0.1\nnumber_of_gates = 3\n\nnode = onnx.helper.make_node(\n 'GRU',\n inputs=['X', 'W', 'R'],\n outputs=['', 'Y_h'],\n hidden_size=hidden_size\n)\n\nW = weight_scale * np.ones((1, number_of_gates * hidden_size, input_size)).astype(np.float32)\nR = weight_scale * np.ones((1, number_of_gates * hidden_size, hidden_size)).astype(np.float32)\n\ngru = GRU_Helper(X=input, W=W, R=R)\n_, Y_h = gru.step()\nexpect(node, inputs=[input, W, R], outputs=[Y_h.astype(np.float32)], name='test_gru_defaults')" + }, + { + "summary": "initial_bias", + "code": "input = np.array([[[1., 2., 3.], [4., 5., 6.], [7., 8., 9.]]]).astype(np.float32)\n\ninput_size = 3\nhidden_size = 3\nweight_scale = 0.1\ncustom_bias = 0.1\nnumber_of_gates = 3\n\nnode = onnx.helper.make_node(\n 'GRU',\n inputs=['X', 'W', 'R', 'B'],\n outputs=['', 'Y_h'],\n hidden_size=hidden_size\n)\n\nW = weight_scale * np.ones((1, number_of_gates * hidden_size, input_size)).astype(np.float32)\nR = weight_scale * np.ones((1, number_of_gates * hidden_size, hidden_size)).astype(np.float32)\n\n# Adding custom bias\nW_B = custom_bias * np.ones((1, number_of_gates * hidden_size)).astype(np.float32)\nR_B = np.zeros((1, number_of_gates * hidden_size)).astype(np.float32)\nB = np.concatenate((W_B, R_B), axis=1)\n\ngru = GRU_Helper(X=input, W=W, R=R, B=B)\n_, Y_h = gru.step()\nexpect(node, inputs=[input, W, R, B], outputs=[Y_h.astype(np.float32)], name='test_gru_with_initial_bias')" + }, + { + "summary": "seq_length", + "code": "input = np.array([[[1., 2., 3.], [4., 5., 6.], [7., 8., 9.]],\n [[10., 11., 12.], [13., 14., 15.], [16., 17., 18.]]]).astype(np.float32)\n\ninput_size = 3\nhidden_size = 5\nnumber_of_gates = 3\n\nnode = onnx.helper.make_node(\n 'GRU',\n inputs=['X', 'W', 'R', 'B'],\n outputs=['', 'Y_h'],\n hidden_size=hidden_size\n)\n\nW = np.random.randn(1, number_of_gates * hidden_size, input_size).astype(np.float32)\nR = np.random.randn(1, number_of_gates * hidden_size, hidden_size).astype(np.float32)\n\n# Adding custom bias\nW_B = np.random.randn(1, number_of_gates * hidden_size).astype(np.float32)\nR_B = np.random.randn(1, number_of_gates * hidden_size).astype(np.float32)\nB = np.concatenate((W_B, R_B), axis=1)\n\ngru = GRU_Helper(X=input, W=W, R=R, B=B)\n_, Y_h = gru.step()\nexpect(node, inputs=[input, W, R, B], outputs=[Y_h.astype(np.float32)], name='test_gru_seq_length')" + } + ], + "category": "Layer" + }, + { + "name": "GRU", + "module": "ai.onnx", + "version": 3, + "support_level": "common", + "description": "Computes an one-layer GRU. This operator is usually supported via some custom\nimplementation such as CuDNN.\n\nNotations:\n\n`X` - input tensor\n\n`z` - update gate\n\n`r` - reset gate\n\n`h` - hidden gate\n\n`t` - time step (t-1 means previous time step)\n\n`W[zrh]` - W parameter weight matrix for update, reset, and hidden gates\n\n`R[zrh]` - R recurrence weight matrix for update, reset, and hidden gates\n\n`Wb[zrh]` - W bias vectors for update, reset, and hidden gates\n\n`Rb[zrh]` - R bias vectors for update, reset, and hidden gates\n\n`WB[zrh]` - W parameter weight matrix for backward update, reset, and hidden gates\n\n`RB[zrh]` - R recurrence weight matrix for backward update, reset, and hidden gates\n\n`WBb[zrh]` - W bias vectors for backward update, reset, and hidden gates\n\n`RBb[zrh]` - R bias vectors for backward update, reset, and hidden gates\n\n`H` - Hidden state\n\n`num_directions` - 2 if direction == bidirectional else 1\n\nActivation functions:\n\n Relu(x) - max(0, x)\n\n Tanh(x) - (1 - e^{-2x})/(1 + e^{-2x})\n\n Sigmoid(x) - 1/(1 + e^{-x})\n\n (NOTE: Below are optional)\n\n Affine(x) - alpha*x + beta\n\n LeakyRelu(x) - x if x >= 0 else alpha * x\n\n ThresholdedRelu(x) - x if x >= alpha else 0\n\n ScaledTanh(x) - alpha*Tanh(beta*x)\n\n HardSigmoid(x) - min(max(alpha*x + beta, 0), 1)\n\n Elu(x) - x if x >= 0 else alpha*(e^x - 1)\n\n Softsign(x) - x/(1 + |x|)\n\n Softplus(x) - log(1 + e^x)\n\nEquations (Default: f=Sigmoid, g=Tanh):\n\n - zt = f(Xt*(Wz^T) + Ht-1*Rz + Wbz + Rbz)\n\n - rt = f(Xt*(Wr^T) + Ht-1*Rr + Wbr + Rbr)\n\n - ht = g(Xt*(Wh^T) + (rt (.) Ht-1)*Rh + Rbh + Wbh) # default, when linear_before_reset = 0\n\n - ht = g(Xt*(Wh^T) + (rt (.) (Ht-1*Rh + Rbh) + Wbh) # when linear_before_reset != 0\n\n - Ht = (1 - zt) (.) ht + zt (.) Ht-1\n", + "attributes": [ + { + "name": "activation_alpha", + "type": "float32[]", + "required": false, + "description": "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." + }, + { + "name": "activation_beta", + "type": "float32[]", + "required": false, + "description": "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." + }, + { + "name": "activations", + "type": "string[]", + "required": false, + "description": "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." + }, + { + "name": "clip", + "type": "float32", + "required": false, + "description": "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." + }, + { + "name": "direction", + "type": "string", + "required": false, + "default": "forward", + "description": "Specify if the RNN is forward, reverse, or bidirectional. Must be one of forward (default), reverse, or bidirectional." + }, + { + "name": "hidden_size", + "type": "int64", + "required": false, + "description": "Number of neurons in the hidden layer" + }, + { + "name": "linear_before_reset", + "type": "int64", + "required": false, + "description": "When computing the output of the hidden gate, apply the linear transformation before multiplying by the output of the reset gate." + }, + { + "name": "output_sequence", + "type": "int64", + "required": false, + "description": "The sequence output for the hidden is optional if 0. Default 0." + } + ], + "inputs": [ + { + "name": "X", + "type": "T", + "description": "The input sequences packed (and potentially padded) into one 3-D tensor with the shape of `[seq_length, batch_size, input_size]`." + }, + { + "name": "W", + "type": "T", + "description": "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]`." + }, + { + "name": "R", + "type": "T", + "description": "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]`." + }, + { + "name": "B", + "type": "T", + "option": "optional", + "description": "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" + }, + { + "name": "sequence_lens", + "type": "T1", + "option": "optional", + "description": "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]`." + }, + { + "name": "initial_h", + "type": "T", + "option": "optional", + "description": "Optional initial value of the hidden. If not specified - assumed to be 0. It has shape `[num_directions, batch_size, hidden_size]`." + } + ], + "min_input": 3, + "max_input": 6, + "outputs": [ + { + "name": "Y", + "type": "T", + "option": "optional", + "description": "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." + }, + { + "name": "Y_h", + "type": "T", + "option": "optional", + "description": "The last output value of the hidden. It has shape `[num_directions, batch_size, hidden_size]`." + } + ], + "min_output": 0, + "max_output": 2, + "inputs_range": "3 - 6", + "outputs_range": "0 - 2", + "type_constraints": [ + { + "description": "Constrain input and output types to float tensors.", + "type_param_str": "T", + "allowed_type_strs": [ + "tensor(float16)", + "tensor(float)", + "tensor(double)" + ] + }, + { + "description": "Constrain seq_lens to integer tensor.", + "type_param_str": "T1", + "allowed_type_strs": [ + "tensor(int32)" + ] + } + ], + "examples": [ + { + "summary": "batchwise", + "code": "input = np.array([[[1., 2.]], [[3., 4.]], [[5., 6.]]]).astype(np.float32)\n\ninput_size = 2\nhidden_size = 6\nnumber_of_gates = 3\nweight_scale = 0.2\nlayout = 1\n\nnode = onnx.helper.make_node(\n 'GRU',\n inputs=['X', 'W', 'R'],\n outputs=['Y', 'Y_h'],\n hidden_size=hidden_size,\n layout=layout\n)\n\nW = weight_scale * np.ones((1, number_of_gates * hidden_size, input_size)).astype(np.float32)\nR = weight_scale * np.ones((1, number_of_gates * hidden_size, hidden_size)).astype(np.float32)\n\ngru = GRU_Helper(X=input, W=W, R=R, layout=layout)\nY, Y_h = gru.step()\nexpect(node, inputs=[input, W, R], outputs=[Y.astype(np.float32), Y_h.astype(np.float32)], name='test_gru_batchwise')" + }, + { + "summary": "defaults", + "code": "input = np.array([[[1., 2.], [3., 4.], [5., 6.]]]).astype(np.float32)\n\ninput_size = 2\nhidden_size = 5\nweight_scale = 0.1\nnumber_of_gates = 3\n\nnode = onnx.helper.make_node(\n 'GRU',\n inputs=['X', 'W', 'R'],\n outputs=['', 'Y_h'],\n hidden_size=hidden_size\n)\n\nW = weight_scale * np.ones((1, number_of_gates * hidden_size, input_size)).astype(np.float32)\nR = weight_scale * np.ones((1, number_of_gates * hidden_size, hidden_size)).astype(np.float32)\n\ngru = GRU_Helper(X=input, W=W, R=R)\n_, Y_h = gru.step()\nexpect(node, inputs=[input, W, R], outputs=[Y_h.astype(np.float32)], name='test_gru_defaults')" + }, + { + "summary": "initial_bias", + "code": "input = np.array([[[1., 2., 3.], [4., 5., 6.], [7., 8., 9.]]]).astype(np.float32)\n\ninput_size = 3\nhidden_size = 3\nweight_scale = 0.1\ncustom_bias = 0.1\nnumber_of_gates = 3\n\nnode = onnx.helper.make_node(\n 'GRU',\n inputs=['X', 'W', 'R', 'B'],\n outputs=['', 'Y_h'],\n hidden_size=hidden_size\n)\n\nW = weight_scale * np.ones((1, number_of_gates * hidden_size, input_size)).astype(np.float32)\nR = weight_scale * np.ones((1, number_of_gates * hidden_size, hidden_size)).astype(np.float32)\n\n# Adding custom bias\nW_B = custom_bias * np.ones((1, number_of_gates * hidden_size)).astype(np.float32)\nR_B = np.zeros((1, number_of_gates * hidden_size)).astype(np.float32)\nB = np.concatenate((W_B, R_B), axis=1)\n\ngru = GRU_Helper(X=input, W=W, R=R, B=B)\n_, Y_h = gru.step()\nexpect(node, inputs=[input, W, R, B], outputs=[Y_h.astype(np.float32)], name='test_gru_with_initial_bias')" + }, + { + "summary": "seq_length", + "code": "input = np.array([[[1., 2., 3.], [4., 5., 6.], [7., 8., 9.]],\n [[10., 11., 12.], [13., 14., 15.], [16., 17., 18.]]]).astype(np.float32)\n\ninput_size = 3\nhidden_size = 5\nnumber_of_gates = 3\n\nnode = onnx.helper.make_node(\n 'GRU',\n inputs=['X', 'W', 'R', 'B'],\n outputs=['', 'Y_h'],\n hidden_size=hidden_size\n)\n\nW = np.random.randn(1, number_of_gates * hidden_size, input_size).astype(np.float32)\nR = np.random.randn(1, number_of_gates * hidden_size, hidden_size).astype(np.float32)\n\n# Adding custom bias\nW_B = np.random.randn(1, number_of_gates * hidden_size).astype(np.float32)\nR_B = np.random.randn(1, number_of_gates * hidden_size).astype(np.float32)\nB = np.concatenate((W_B, R_B), axis=1)\n\ngru = GRU_Helper(X=input, W=W, R=R, B=B)\n_, Y_h = gru.step()\nexpect(node, inputs=[input, W, R, B], outputs=[Y_h.astype(np.float32)], name='test_gru_seq_length')" + } + ], + "category": "Layer" + }, + { + "name": "GRU", + "module": "ai.onnx", + "version": 7, + "support_level": "common", + "description": "Computes an one-layer GRU. This operator is usually supported via some custom\nimplementation such as CuDNN.\n\nNotations:\n\n`X` - input tensor\n\n`z` - update gate\n\n`r` - reset gate\n\n`h` - hidden gate\n\n`t` - time step (t-1 means previous time step)\n\n`W[zrh]` - W parameter weight matrix for update, reset, and hidden gates\n\n`R[zrh]` - R recurrence weight matrix for update, reset, and hidden gates\n\n`Wb[zrh]` - W bias vectors for update, reset, and hidden gates\n\n`Rb[zrh]` - R bias vectors for update, reset, and hidden gates\n\n`WB[zrh]` - W parameter weight matrix for backward update, reset, and hidden gates\n\n`RB[zrh]` - R recurrence weight matrix for backward update, reset, and hidden gates\n\n`WBb[zrh]` - W bias vectors for backward update, reset, and hidden gates\n\n`RBb[zrh]` - R bias vectors for backward update, reset, and hidden gates\n\n`H` - Hidden state\n\n`num_directions` - 2 if direction == bidirectional else 1\n\nActivation functions:\n\n Relu(x) - max(0, x)\n\n Tanh(x) - (1 - e^{-2x})/(1 + e^{-2x})\n\n Sigmoid(x) - 1/(1 + e^{-x})\n\n (NOTE: Below are optional)\n\n Affine(x) - alpha*x + beta\n\n LeakyRelu(x) - x if x >= 0 else alpha * x\n\n ThresholdedRelu(x) - x if x >= alpha else 0\n\n ScaledTanh(x) - alpha*Tanh(beta*x)\n\n HardSigmoid(x) - min(max(alpha*x + beta, 0), 1)\n\n Elu(x) - x if x >= 0 else alpha*(e^x - 1)\n\n Softsign(x) - x/(1 + |x|)\n\n Softplus(x) - log(1 + e^x)\n\nEquations (Default: f=Sigmoid, g=Tanh):\n\n - zt = f(Xt*(Wz^T) + Ht-1*(Rz^T) + Wbz + Rbz)\n\n - rt = f(Xt*(Wr^T) + Ht-1*(Rr^T) + Wbr + Rbr)\n\n - ht = g(Xt*(Wh^T) + (rt (.) Ht-1)*(Rh^T) + Rbh + Wbh) # default, when linear_before_reset = 0\n\n - ht = g(Xt*(Wh^T) + (rt (.) (Ht-1*(Rh^T) + Rbh)) + Wbh) # when linear_before_reset != 0\n\n - Ht = (1 - zt) (.) ht + zt (.) Ht-1\nThis operator has **optional** inputs/outputs. See [the doc](https://github.com/onnx/onnx/blob/master/docs/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.\n", + "attributes": [ + { + "name": "activation_alpha", + "type": "float32[]", + "required": false, + "description": "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." + }, + { + "name": "activation_beta", + "type": "float32[]", + "required": false, + "description": "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." + }, + { + "name": "activations", + "type": "string[]", + "required": false, + "description": "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." + }, + { + "name": "clip", + "type": "float32", + "required": false, + "description": "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." + }, + { + "name": "direction", + "type": "string", + "required": false, + "default": "forward", + "description": "Specify if the RNN is forward, reverse, or bidirectional. Must be one of forward (default), reverse, or bidirectional." + }, + { + "name": "hidden_size", + "type": "int64", + "required": false, + "description": "Number of neurons in the hidden layer" + }, + { + "name": "linear_before_reset", + "type": "int64", + "required": false, + "description": "When computing the output of the hidden gate, apply the linear transformation before multiplying by the output of the reset gate." + } + ], + "inputs": [ + { + "name": "X", + "type": "T", + "description": "The input sequences packed (and potentially padded) into one 3-D tensor with the shape of `[seq_length, batch_size, input_size]`." + }, + { + "name": "W", + "type": "T", + "description": "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]`." + }, + { + "name": "R", + "type": "T", + "description": "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]`." + }, + { + "name": "B", + "type": "T", + "option": "optional", + "description": "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" + }, + { + "name": "sequence_lens", + "type": "T1", + "option": "optional", + "description": "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]`." + }, + { + "name": "initial_h", + "type": "T", + "option": "optional", + "description": "Optional initial value of the hidden. If not specified - assumed to be 0. It has shape `[num_directions, batch_size, hidden_size]`." + } + ], + "min_input": 3, + "max_input": 6, + "outputs": [ + { + "name": "Y", + "type": "T", + "option": "optional", + "description": "A tensor that concats all the intermediate output values of the hidden. It has shape `[seq_length, num_directions, batch_size, hidden_size]`. " + }, + { + "name": "Y_h", + "type": "T", + "option": "optional", + "description": "The last output value of the hidden. It has shape `[num_directions, batch_size, hidden_size]`." + } + ], + "min_output": 0, + "max_output": 2, + "inputs_range": "3 - 6", + "outputs_range": "0 - 2", + "type_constraints": [ + { + "description": "Constrain input and output types to float tensors.", + "type_param_str": "T", + "allowed_type_strs": [ + "tensor(float16)", + "tensor(float)", + "tensor(double)" + ] + }, + { + "description": "Constrain seq_lens to integer tensor.", + "type_param_str": "T1", + "allowed_type_strs": [ + "tensor(int32)" + ] + } + ], + "examples": [ + { + "summary": "batchwise", + "code": "input = np.array([[[1., 2.]], [[3., 4.]], [[5., 6.]]]).astype(np.float32)\n\ninput_size = 2\nhidden_size = 6\nnumber_of_gates = 3\nweight_scale = 0.2\nlayout = 1\n\nnode = onnx.helper.make_node(\n 'GRU',\n inputs=['X', 'W', 'R'],\n outputs=['Y', 'Y_h'],\n hidden_size=hidden_size,\n layout=layout\n)\n\nW = weight_scale * np.ones((1, number_of_gates * hidden_size, input_size)).astype(np.float32)\nR = weight_scale * np.ones((1, number_of_gates * hidden_size, hidden_size)).astype(np.float32)\n\ngru = GRU_Helper(X=input, W=W, R=R, layout=layout)\nY, Y_h = gru.step()\nexpect(node, inputs=[input, W, R], outputs=[Y.astype(np.float32), Y_h.astype(np.float32)], name='test_gru_batchwise')" + }, + { + "summary": "defaults", + "code": "input = np.array([[[1., 2.], [3., 4.], [5., 6.]]]).astype(np.float32)\n\ninput_size = 2\nhidden_size = 5\nweight_scale = 0.1\nnumber_of_gates = 3\n\nnode = onnx.helper.make_node(\n 'GRU',\n inputs=['X', 'W', 'R'],\n outputs=['', 'Y_h'],\n hidden_size=hidden_size\n)\n\nW = weight_scale * np.ones((1, number_of_gates * hidden_size, input_size)).astype(np.float32)\nR = weight_scale * np.ones((1, number_of_gates * hidden_size, hidden_size)).astype(np.float32)\n\ngru = GRU_Helper(X=input, W=W, R=R)\n_, Y_h = gru.step()\nexpect(node, inputs=[input, W, R], outputs=[Y_h.astype(np.float32)], name='test_gru_defaults')" + }, + { + "summary": "initial_bias", + "code": "input = np.array([[[1., 2., 3.], [4., 5., 6.], [7., 8., 9.]]]).astype(np.float32)\n\ninput_size = 3\nhidden_size = 3\nweight_scale = 0.1\ncustom_bias = 0.1\nnumber_of_gates = 3\n\nnode = onnx.helper.make_node(\n 'GRU',\n inputs=['X', 'W', 'R', 'B'],\n outputs=['', 'Y_h'],\n hidden_size=hidden_size\n)\n\nW = weight_scale * np.ones((1, number_of_gates * hidden_size, input_size)).astype(np.float32)\nR = weight_scale * np.ones((1, number_of_gates * hidden_size, hidden_size)).astype(np.float32)\n\n# Adding custom bias\nW_B = custom_bias * np.ones((1, number_of_gates * hidden_size)).astype(np.float32)\nR_B = np.zeros((1, number_of_gates * hidden_size)).astype(np.float32)\nB = np.concatenate((W_B, R_B), axis=1)\n\ngru = GRU_Helper(X=input, W=W, R=R, B=B)\n_, Y_h = gru.step()\nexpect(node, inputs=[input, W, R, B], outputs=[Y_h.astype(np.float32)], name='test_gru_with_initial_bias')" + }, + { + "summary": "seq_length", + "code": "input = np.array([[[1., 2., 3.], [4., 5., 6.], [7., 8., 9.]],\n [[10., 11., 12.], [13., 14., 15.], [16., 17., 18.]]]).astype(np.float32)\n\ninput_size = 3\nhidden_size = 5\nnumber_of_gates = 3\n\nnode = onnx.helper.make_node(\n 'GRU',\n inputs=['X', 'W', 'R', 'B'],\n outputs=['', 'Y_h'],\n hidden_size=hidden_size\n)\n\nW = np.random.randn(1, number_of_gates * hidden_size, input_size).astype(np.float32)\nR = np.random.randn(1, number_of_gates * hidden_size, hidden_size).astype(np.float32)\n\n# Adding custom bias\nW_B = np.random.randn(1, number_of_gates * hidden_size).astype(np.float32)\nR_B = np.random.randn(1, number_of_gates * hidden_size).astype(np.float32)\nB = np.concatenate((W_B, R_B), axis=1)\n\ngru = GRU_Helper(X=input, W=W, R=R, B=B)\n_, Y_h = gru.step()\nexpect(node, inputs=[input, W, R, B], outputs=[Y_h.astype(np.float32)], name='test_gru_seq_length')" + } + ], + "category": "Layer" + }, + { + "name": "GRU", + "module": "ai.onnx", + "version": 14, + "support_level": "common", + "description": "Computes an one-layer GRU. This operator is usually supported via some custom\nimplementation such as CuDNN.\n\nNotations:\n\n`X` - input tensor\n\n`z` - update gate\n\n`r` - reset gate\n\n`h` - hidden gate\n\n`t` - time step (t-1 means previous time step)\n\n`W[zrh]` - W parameter weight matrix for update, reset, and hidden gates\n\n`R[zrh]` - R recurrence weight matrix for update, reset, and hidden gates\n\n`Wb[zrh]` - W bias vectors for update, reset, and hidden gates\n\n`Rb[zrh]` - R bias vectors for update, reset, and hidden gates\n\n`WB[zrh]` - W parameter weight matrix for backward update, reset, and hidden gates\n\n`RB[zrh]` - R recurrence weight matrix for backward update, reset, and hidden gates\n\n`WBb[zrh]` - W bias vectors for backward update, reset, and hidden gates\n\n`RBb[zrh]` - R bias vectors for backward update, reset, and hidden gates\n\n`H` - Hidden state\n\n`num_directions` - 2 if direction == bidirectional else 1\n\nActivation functions:\n\n Relu(x) - max(0, x)\n\n Tanh(x) - (1 - e^{-2x})/(1 + e^{-2x})\n\n Sigmoid(x) - 1/(1 + e^{-x})\n\n (NOTE: Below are optional)\n\n Affine(x) - alpha*x + beta\n\n LeakyRelu(x) - x if x >= 0 else alpha * x\n\n ThresholdedRelu(x) - x if x >= alpha else 0\n\n ScaledTanh(x) - alpha*Tanh(beta*x)\n\n HardSigmoid(x) - min(max(alpha*x + beta, 0), 1)\n\n Elu(x) - x if x >= 0 else alpha*(e^x - 1)\n\n Softsign(x) - x/(1 + |x|)\n\n Softplus(x) - log(1 + e^x)\n\nEquations (Default: f=Sigmoid, g=Tanh):\n\n - zt = f(Xt*(Wz^T) + Ht-1*(Rz^T) + Wbz + Rbz)\n\n - rt = f(Xt*(Wr^T) + Ht-1*(Rr^T) + Wbr + Rbr)\n\n - ht = g(Xt*(Wh^T) + (rt (.) Ht-1)*(Rh^T) + Rbh + Wbh) # default, when linear_before_reset = 0\n\n - ht = g(Xt*(Wh^T) + (rt (.) (Ht-1*(Rh^T) + Rbh)) + Wbh) # when linear_before_reset != 0\n\n - Ht = (1 - zt) (.) ht + zt (.) Ht-1\nThis operator has **optional** inputs/outputs. See [the doc](https://github.com/onnx/onnx/blob/master/docs/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.\n", + "attributes": [ + { + "name": "activation_alpha", + "type": "float32[]", + "required": false, + "description": "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." + }, + { + "name": "activation_beta", + "type": "float32[]", + "required": false, + "description": "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." + }, + { + "name": "activations", + "type": "string[]", + "required": false, + "description": "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." + }, + { + "name": "clip", + "type": "float32", + "required": false, + "description": "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." + }, + { + "name": "direction", + "type": "string", + "required": false, + "default": "forward", + "description": "Specify if the RNN is forward, reverse, or bidirectional. Must be one of forward (default), reverse, or bidirectional." + }, + { + "name": "hidden_size", + "type": "int64", + "required": false, + "description": "Number of neurons in the hidden layer" + }, + { + "name": "layout", + "type": "int64", + "required": false, + "description": "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]." + }, + { + "name": "linear_before_reset", + "type": "int64", + "required": false, + "description": "When computing the output of the hidden gate, apply the linear transformation before multiplying by the output of the reset gate." + } + ], + "inputs": [ + { + "name": "X", + "type": "T", + "description": "The input sequences packed (and potentially padded) into one 3-D tensor with the shape of `[seq_length, batch_size, input_size]`." + }, + { + "name": "W", + "type": "T", + "description": "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]`." + }, + { + "name": "R", + "type": "T", + "description": "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]`." + }, + { + "name": "B", + "type": "T", + "option": "optional", + "description": "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" + }, + { + "name": "sequence_lens", + "type": "T1", + "option": "optional", + "description": "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]`." + }, + { + "name": "initial_h", + "type": "T", + "option": "optional", + "description": "Optional initial value of the hidden. If not specified - assumed to be 0. It has shape `[num_directions, batch_size, hidden_size]`." + } + ], + "min_input": 3, + "max_input": 6, + "outputs": [ + { + "name": "Y", + "type": "T", + "option": "optional", + "description": "A tensor that concats all the intermediate output values of the hidden. It has shape `[seq_length, num_directions, batch_size, hidden_size]`. " + }, + { + "name": "Y_h", + "type": "T", + "option": "optional", + "description": "The last output value of the hidden. It has shape `[num_directions, batch_size, hidden_size]`." + } + ], + "min_output": 0, + "max_output": 2, + "inputs_range": "3 - 6", + "outputs_range": "0 - 2", + "type_constraints": [ + { + "description": "Constrain input and output types to float tensors.", + "type_param_str": "T", + "allowed_type_strs": [ + "tensor(float16)", + "tensor(float)", + "tensor(double)" + ] + }, + { + "description": "Constrain seq_lens to integer tensor.", + "type_param_str": "T1", + "allowed_type_strs": [ + "tensor(int32)" + ] + } + ], + "examples": [ + { + "summary": "batchwise", + "code": "input = np.array([[[1., 2.]], [[3., 4.]], [[5., 6.]]]).astype(np.float32)\n\ninput_size = 2\nhidden_size = 6\nnumber_of_gates = 3\nweight_scale = 0.2\nlayout = 1\n\nnode = onnx.helper.make_node(\n 'GRU',\n inputs=['X', 'W', 'R'],\n outputs=['Y', 'Y_h'],\n hidden_size=hidden_size,\n layout=layout\n)\n\nW = weight_scale * np.ones((1, number_of_gates * hidden_size, input_size)).astype(np.float32)\nR = weight_scale * np.ones((1, number_of_gates * hidden_size, hidden_size)).astype(np.float32)\n\ngru = GRU_Helper(X=input, W=W, R=R, layout=layout)\nY, Y_h = gru.step()\nexpect(node, inputs=[input, W, R], outputs=[Y.astype(np.float32), Y_h.astype(np.float32)], name='test_gru_batchwise')" + }, + { + "summary": "defaults", + "code": "input = np.array([[[1., 2.], [3., 4.], [5., 6.]]]).astype(np.float32)\n\ninput_size = 2\nhidden_size = 5\nweight_scale = 0.1\nnumber_of_gates = 3\n\nnode = onnx.helper.make_node(\n 'GRU',\n inputs=['X', 'W', 'R'],\n outputs=['', 'Y_h'],\n hidden_size=hidden_size\n)\n\nW = weight_scale * np.ones((1, number_of_gates * hidden_size, input_size)).astype(np.float32)\nR = weight_scale * np.ones((1, number_of_gates * hidden_size, hidden_size)).astype(np.float32)\n\ngru = GRU_Helper(X=input, W=W, R=R)\n_, Y_h = gru.step()\nexpect(node, inputs=[input, W, R], outputs=[Y_h.astype(np.float32)], name='test_gru_defaults')" + }, + { + "summary": "initial_bias", + "code": "input = np.array([[[1., 2., 3.], [4., 5., 6.], [7., 8., 9.]]]).astype(np.float32)\n\ninput_size = 3\nhidden_size = 3\nweight_scale = 0.1\ncustom_bias = 0.1\nnumber_of_gates = 3\n\nnode = onnx.helper.make_node(\n 'GRU',\n inputs=['X', 'W', 'R', 'B'],\n outputs=['', 'Y_h'],\n hidden_size=hidden_size\n)\n\nW = weight_scale * np.ones((1, number_of_gates * hidden_size, input_size)).astype(np.float32)\nR = weight_scale * np.ones((1, number_of_gates * hidden_size, hidden_size)).astype(np.float32)\n\n# Adding custom bias\nW_B = custom_bias * np.ones((1, number_of_gates * hidden_size)).astype(np.float32)\nR_B = np.zeros((1, number_of_gates * hidden_size)).astype(np.float32)\nB = np.concatenate((W_B, R_B), axis=1)\n\ngru = GRU_Helper(X=input, W=W, R=R, B=B)\n_, Y_h = gru.step()\nexpect(node, inputs=[input, W, R, B], outputs=[Y_h.astype(np.float32)], name='test_gru_with_initial_bias')" + }, + { + "summary": "seq_length", + "code": "input = np.array([[[1., 2., 3.], [4., 5., 6.], [7., 8., 9.]],\n [[10., 11., 12.], [13., 14., 15.], [16., 17., 18.]]]).astype(np.float32)\n\ninput_size = 3\nhidden_size = 5\nnumber_of_gates = 3\n\nnode = onnx.helper.make_node(\n 'GRU',\n inputs=['X', 'W', 'R', 'B'],\n outputs=['', 'Y_h'],\n hidden_size=hidden_size\n)\n\nW = np.random.randn(1, number_of_gates * hidden_size, input_size).astype(np.float32)\nR = np.random.randn(1, number_of_gates * hidden_size, hidden_size).astype(np.float32)\n\n# Adding custom bias\nW_B = np.random.randn(1, number_of_gates * hidden_size).astype(np.float32)\nR_B = np.random.randn(1, number_of_gates * hidden_size).astype(np.float32)\nB = np.concatenate((W_B, R_B), axis=1)\n\ngru = GRU_Helper(X=input, W=W, R=R, B=B)\n_, Y_h = gru.step()\nexpect(node, inputs=[input, W, R, B], outputs=[Y_h.astype(np.float32)], name='test_gru_seq_length')" + } + ], + "category": "Layer" + }, + { + "name": "Gather", + "module": "ai.onnx", + "version": 1, + "support_level": "common", + "description": "Given `data` tensor of rank r >= 1, and `indices` tensor of rank q, gather\nentries of the axis dimension of `data` (by default outer-most one as axis=0) indexed by `indices`, and concatenates\nthem in an output tensor of rank q + (r - 1).\nExample 1:\n```\n data = [\n [1.0, 1.2],\n [2.3, 3.4],\n [4.5, 5.7],\n ]\n indices = [\n [0, 1],\n [1, 2],\n ]\n output = [\n [\n [1.0, 1.2],\n [2.3, 3.4],\n ],\n [\n [2.3, 3.4],\n [4.5, 5.7],\n ],\n ]\n```\nExample 2:\n```\n data = [\n [1.0, 1.2, 1.9],\n [2.3, 3.4, 3.9],\n [4.5, 5.7, 5.9],\n ]\n indices = [\n [0, 2],\n ]\n axis = 1,\n output = [\n [\n [1.0, 1.9],\n [2.3, 3.9],\n [4.5, 5.9],\n ],\n ]\n```\n", + "attributes": [ + { + "name": "axis", + "type": "int64", + "required": false, + "description": "Which axis to gather on. Negative value means counting dimensions from the back. Accepted range is [-r, r-1]" + } + ], + "inputs": [ + { + "name": "data", + "type": "T", + "description": "Tensor of rank r >= 1." + }, + { + "name": "indices", + "type": "Tind", + "description": "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." + } + ], + "min_input": 2, + "max_input": 2, + "outputs": [ + { + "name": "output", + "type": "T", + "description": "Tensor of rank q + (r - 1)." + } + ], + "min_output": 1, + "max_output": 1, + "type_constraints": [ + { + "description": "Constrain input and output types to any tensor type.", + "type_param_str": "T", + "allowed_type_strs": [ + "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)" + ] + }, + { + "description": "Constrain indices to integer types", + "type_param_str": "Tind", + "allowed_type_strs": [ + "tensor(int32)", + "tensor(int64)" + ] + } + ], + "examples": [ + { + "summary": "gather_0", + "code": "node = onnx.helper.make_node(\n 'Gather',\n inputs=['data', 'indices'],\n outputs=['y'],\n axis=0,\n)\ndata = np.random.randn(5, 4, 3, 2).astype(np.float32)\nindices = np.array([0, 1, 3])\ny = np.take(data, indices, axis=0)\n\nexpect(node, inputs=[data, indices.astype(np.int64)], outputs=[y],\n name='test_gather_0')" + }, + { + "summary": "gather_1", + "code": "node = onnx.helper.make_node(\n 'Gather',\n inputs=['data', 'indices'],\n outputs=['y'],\n axis=1,\n)\ndata = np.random.randn(5, 4, 3, 2).astype(np.float32)\nindices = np.array([0, 1, 3])\ny = np.take(data, indices, axis=1)\n\nexpect(node, inputs=[data, indices.astype(np.int64)], outputs=[y],\n name='test_gather_1')" + }, + { + "summary": "gather_2d_indices", + "code": "node = onnx.helper.make_node(\n 'Gather',\n inputs=['data', 'indices'],\n outputs=['y'],\n axis=1,\n)\ndata = np.random.randn(3, 3).astype(np.float32)\nindices = np.array([[0, 2]])\ny = np.take(data, indices, axis=1)\n\nexpect(node, inputs=[data, indices.astype(np.int64)], outputs=[y],\n name='test_gather_2d_indices')" + }, + { + "summary": "gather_negative_indices", + "code": "node = onnx.helper.make_node(\n 'Gather',\n inputs=['data', 'indices'],\n outputs=['y'],\n axis=0,\n)\ndata = np.arange(10).astype(np.float32)\nindices = np.array([0, -9, -10])\ny = np.take(data, indices, axis=0)\n\nexpect(node, inputs=[data, indices.astype(np.int64)], outputs=[y],\n name='test_gather_negative_indices')" + } + ], + "category": "Transform" + }, + { + "name": "Gather", + "module": "ai.onnx", + "version": 11, + "support_level": "common", + "description": "Given `data` tensor of rank r >= 1, and `indices` tensor of rank q, gather\nentries of the axis dimension of `data` (by default outer-most one as axis=0) indexed by `indices`, and concatenates\nthem in an output tensor of rank q + (r - 1).\n\naxis = 0 :\n\nLet\nk = indices[i_{0}, ..., i_{q-1}]\nThen\noutput[i_{0}, ..., i_{q-1}, j_{0}, ..., j_{r-2}] = input[k , j_{0}, ..., j_{r-2}]\n\n```\n data = [\n [1.0, 1.2],\n [2.3, 3.4],\n [4.5, 5.7],\n ]\n indices = [\n [0, 1],\n [1, 2],\n ]\n output = [\n [\n [1.0, 1.2],\n [2.3, 3.4],\n ],\n [\n [2.3, 3.4],\n [4.5, 5.7],\n ],\n ]\n```\naxis = 1 :\n\nLet\nk = indices[i_{0}, ..., i_{q-1}]\nThen\noutput[i_{0}, ..., i_{q-1}, j_{0}, ..., j_{r-2}] = input[j_{0}, k, j_{1}, ..., j_{r-2}]\n\n```\n data = [\n [1.0, 1.2, 1.9],\n [2.3, 3.4, 3.9],\n [4.5, 5.7, 5.9],\n ]\n indices = [\n [0, 2],\n ]\n axis = 1,\n output = [\n [\n [1.0, 1.9],\n [2.3, 3.9],\n [4.5, 5.9],\n ],\n ]\n```\n", + "attributes": [ + { + "name": "axis", + "type": "int64", + "required": false, + "description": "Which axis to gather on. Negative value means counting dimensions from the back. Accepted range is [-r, r-1] where r = rank(data)." + } + ], + "inputs": [ + { + "name": "data", + "type": "T", + "description": "Tensor of rank r >= 1." + }, + { + "name": "indices", + "type": "Tind", + "description": "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." + } + ], + "min_input": 2, + "max_input": 2, + "outputs": [ + { + "name": "output", + "type": "T", + "description": "Tensor of rank q + (r - 1)." + } + ], + "min_output": 1, + "max_output": 1, + "type_constraints": [ + { + "description": "Constrain input and output types to any tensor type.", + "type_param_str": "T", + "allowed_type_strs": [ + "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)" + ] + }, + { + "description": "Constrain indices to integer types", + "type_param_str": "Tind", + "allowed_type_strs": [ + "tensor(int32)", + "tensor(int64)" + ] + } + ], + "examples": [ + { + "summary": "gather_0", + "code": "node = onnx.helper.make_node(\n 'Gather',\n inputs=['data', 'indices'],\n outputs=['y'],\n axis=0,\n)\ndata = np.random.randn(5, 4, 3, 2).astype(np.float32)\nindices = np.array([0, 1, 3])\ny = np.take(data, indices, axis=0)\n\nexpect(node, inputs=[data, indices.astype(np.int64)], outputs=[y],\n name='test_gather_0')" + }, + { + "summary": "gather_1", + "code": "node = onnx.helper.make_node(\n 'Gather',\n inputs=['data', 'indices'],\n outputs=['y'],\n axis=1,\n)\ndata = np.random.randn(5, 4, 3, 2).astype(np.float32)\nindices = np.array([0, 1, 3])\ny = np.take(data, indices, axis=1)\n\nexpect(node, inputs=[data, indices.astype(np.int64)], outputs=[y],\n name='test_gather_1')" + }, + { + "summary": "gather_2d_indices", + "code": "node = onnx.helper.make_node(\n 'Gather',\n inputs=['data', 'indices'],\n outputs=['y'],\n axis=1,\n)\ndata = np.random.randn(3, 3).astype(np.float32)\nindices = np.array([[0, 2]])\ny = np.take(data, indices, axis=1)\n\nexpect(node, inputs=[data, indices.astype(np.int64)], outputs=[y],\n name='test_gather_2d_indices')" + }, + { + "summary": "gather_negative_indices", + "code": "node = onnx.helper.make_node(\n 'Gather',\n inputs=['data', 'indices'],\n outputs=['y'],\n axis=0,\n)\ndata = np.arange(10).astype(np.float32)\nindices = np.array([0, -9, -10])\ny = np.take(data, indices, axis=0)\n\nexpect(node, inputs=[data, indices.astype(np.int64)], outputs=[y],\n name='test_gather_negative_indices')" + } + ], + "category": "Transform" + }, + { + "name": "Gather", + "module": "ai.onnx", + "version": 13, + "support_level": "common", + "description": "Given `data` tensor of rank r >= 1, and `indices` tensor of rank q, gather\nentries of the axis dimension of `data` (by default outer-most one as axis=0) indexed by `indices`, and concatenates\nthem in an output tensor of rank q + (r - 1).\n\naxis = 0 :\n\nLet\nk = indices[i_{0}, ..., i_{q-1}]\nThen\noutput[i_{0}, ..., i_{q-1}, j_{0}, ..., j_{r-2}] = input[k , j_{0}, ..., j_{r-2}]\n\n```\n data = [\n [1.0, 1.2],\n [2.3, 3.4],\n [4.5, 5.7],\n ]\n indices = [\n [0, 1],\n [1, 2],\n ]\n output = [\n [\n [1.0, 1.2],\n [2.3, 3.4],\n ],\n [\n [2.3, 3.4],\n [4.5, 5.7],\n ],\n ]\n```\naxis = 1 :\n\nLet\nk = indices[i_{0}, ..., i_{q-1}]\nThen\noutput[i_{0}, ..., i_{q-1}, j_{0}, ..., j_{r-2}] = input[j_{0}, k, j_{1}, ..., j_{r-2}]\n\n```\n data = [\n [1.0, 1.2, 1.9],\n [2.3, 3.4, 3.9],\n [4.5, 5.7, 5.9],\n ]\n indices = [\n [0, 2],\n ]\n axis = 1,\n output = [\n [[1.0, 1.9]],\n [[2.3, 3.9]],\n [[4.5, 5.9]],\n ]\n```\n", + "attributes": [ + { + "name": "axis", + "type": "int64", + "required": false, + "description": "Which axis to gather on. Negative value means counting dimensions from the back. Accepted range is [-r, r-1] where r = rank(data)." + } + ], + "inputs": [ + { + "name": "data", + "type": "T", + "description": "Tensor of rank r >= 1." + }, + { + "name": "indices", + "type": "Tind", + "description": "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." + } + ], + "min_input": 2, + "max_input": 2, + "outputs": [ + { + "name": "output", + "type": "T", + "description": "Tensor of rank q + (r - 1)." + } + ], + "min_output": 1, + "max_output": 1, + "type_constraints": [ + { + "description": "Constrain input and output types to any tensor type.", + "type_param_str": "T", + "allowed_type_strs": [ + "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)" + ] + }, + { + "description": "Constrain indices to integer types", + "type_param_str": "Tind", + "allowed_type_strs": [ + "tensor(int32)", + "tensor(int64)" + ] + } + ], + "examples": [ + { + "summary": "gather_0", + "code": "node = onnx.helper.make_node(\n 'Gather',\n inputs=['data', 'indices'],\n outputs=['y'],\n axis=0,\n)\ndata = np.random.randn(5, 4, 3, 2).astype(np.float32)\nindices = np.array([0, 1, 3])\ny = np.take(data, indices, axis=0)\n\nexpect(node, inputs=[data, indices.astype(np.int64)], outputs=[y],\n name='test_gather_0')" + }, + { + "summary": "gather_1", + "code": "node = onnx.helper.make_node(\n 'Gather',\n inputs=['data', 'indices'],\n outputs=['y'],\n axis=1,\n)\ndata = np.random.randn(5, 4, 3, 2).astype(np.float32)\nindices = np.array([0, 1, 3])\ny = np.take(data, indices, axis=1)\n\nexpect(node, inputs=[data, indices.astype(np.int64)], outputs=[y],\n name='test_gather_1')" + }, + { + "summary": "gather_2d_indices", + "code": "node = onnx.helper.make_node(\n 'Gather',\n inputs=['data', 'indices'],\n outputs=['y'],\n axis=1,\n)\ndata = np.random.randn(3, 3).astype(np.float32)\nindices = np.array([[0, 2]])\ny = np.take(data, indices, axis=1)\n\nexpect(node, inputs=[data, indices.astype(np.int64)], outputs=[y],\n name='test_gather_2d_indices')" + }, + { + "summary": "gather_negative_indices", + "code": "node = onnx.helper.make_node(\n 'Gather',\n inputs=['data', 'indices'],\n outputs=['y'],\n axis=0,\n)\ndata = np.arange(10).astype(np.float32)\nindices = np.array([0, -9, -10])\ny = np.take(data, indices, axis=0)\n\nexpect(node, inputs=[data, indices.astype(np.int64)], outputs=[y],\n name='test_gather_negative_indices')" + } + ], + "category": "Transform" + }, + { + "name": "GatherElements", + "module": "ai.onnx", + "version": 11, + "support_level": "common", + "description": "GatherElements takes two inputs `data` and `indices` of the same rank r >= 1\nand an optional attribute `axis` that identifies an axis of `data`\n(by default, the outer-most axis, that is axis 0). It is an indexing operation\nthat produces its output by indexing into the input data tensor at index\npositions determined by elements of the `indices` tensor.\nIts output shape is the same as the shape of `indices` and consists of one value\n(gathered from the `data`) for each element in `indices`.\n\nFor instance, in the 3-D case (r = 3), the output produced is determined\nby the following equations:\n```\n out[i][j][k] = input[index[i][j][k]][j][k] if axis = 0,\n out[i][j][k] = input[i][index[i][j][k]][k] if axis = 1,\n out[i][j][k] = input[i][j][index[i][j][k]] if axis = 2,\n```\n\nThis operator is also the inverse of ScatterElements. It is similar to Torch's gather operation.\n\nExample 1:\n```\n data = [\n [1, 2],\n [3, 4],\n ]\n indices = [\n [0, 0],\n [1, 0],\n ]\n axis = 1\n output = [\n [\n [1, 1],\n [4, 3],\n ],\n ]\n```\nExample 2:\n```\n data = [\n [1, 2, 3],\n [4, 5, 6],\n [7, 8, 9],\n ]\n indices = [\n [1, 2, 0],\n [2, 0, 0],\n ]\n axis = 0\n output = [\n [\n [4, 8, 3],\n [7, 2, 3],\n ],\n ]\n```\n", + "attributes": [ + { + "name": "axis", + "type": "int64", + "required": false, + "description": "Which axis to gather on. Negative value means counting dimensions from the back. Accepted range is [-r, r-1] where r = rank(data)." + } + ], + "inputs": [ + { + "name": "data", + "type": "T", + "description": "Tensor of rank r >= 1." + }, + { + "name": "indices", + "type": "Tind", + "description": "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." + } + ], + "min_input": 2, + "max_input": 2, + "outputs": [ + { + "name": "output", + "type": "T", + "description": "Tensor of the same shape as indices." + } + ], + "min_output": 1, + "max_output": 1, + "type_constraints": [ + { + "description": "Constrain input and output types to any tensor type.", + "type_param_str": "T", + "allowed_type_strs": [ + "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)" + ] + }, + { + "description": "Constrain indices to integer types", + "type_param_str": "Tind", + "allowed_type_strs": [ + "tensor(int32)", + "tensor(int64)" + ] + } + ], + "examples": [ + { + "summary": "gather_elements_0", + "code": "axis = 1\nnode = onnx.helper.make_node(\n 'GatherElements',\n inputs=['data', 'indices'],\n outputs=['y'],\n axis=axis,\n)\ndata = np.array([[1, 2],\n [3, 4]], dtype=np.float32)\nindices = np.array([[0, 0],\n [1, 0]], dtype=np.int32)\n\ny = gather_elements(data, indices, axis)\n# print(y) produces\n# [[1, 1],\n# [4, 3]]\n\nexpect(node, inputs=[data, indices.astype(np.int64)], outputs=[y],\n name='test_gather_elements_0')" + }, + { + "summary": "gather_elements_1", + "code": "axis = 0\nnode = onnx.helper.make_node(\n 'GatherElements',\n inputs=['data', 'indices'],\n outputs=['y'],\n axis=axis,\n)\ndata = np.array([[1, 2, 3],\n [4, 5, 6],\n [7, 8, 9]], dtype=np.float32)\nindices = np.array([[1, 2, 0],\n [2, 0, 0]], dtype=np.int32)\n\ny = gather_elements(data, indices, axis)\n# print(y) produces\n# [[4, 8, 3],\n# [7, 2, 3]]\n\nexpect(node, inputs=[data, indices.astype(np.int64)], outputs=[y],\n name='test_gather_elements_1')" + }, + { + "summary": "gather_elements_negative_indices", + "code": "axis = 0\nnode = onnx.helper.make_node(\n 'GatherElements',\n inputs=['data', 'indices'],\n outputs=['y'],\n axis=axis,\n)\ndata = np.array([[1, 2, 3],\n [4, 5, 6],\n [7, 8, 9]], dtype=np.float32)\nindices = np.array([[-1, -2, 0],\n [-2, 0, 0]], dtype=np.int32)\n\ny = gather_elements(data, indices, axis)\n# print(y) produces\n# [[7, 5, 3],\n# [4, 2, 3]]\n\nexpect(node, inputs=[data, indices.astype(np.int64)], outputs=[y],\n name='test_gather_elements_negative_indices')" + } + ] + }, + { + "name": "GatherElements", + "module": "ai.onnx", + "version": 13, + "support_level": "common", + "description": "GatherElements takes two inputs `data` and `indices` of the same rank r >= 1\nand an optional attribute `axis` that identifies an axis of `data`\n(by default, the outer-most axis, that is axis 0). It is an indexing operation\nthat produces its output by indexing into the input data tensor at index\npositions determined by elements of the `indices` tensor.\nIts output shape is the same as the shape of `indices` and consists of one value\n(gathered from the `data`) for each element in `indices`.\n\nFor instance, in the 3-D case (r = 3), the output produced is determined\nby the following equations:\n```\n out[i][j][k] = input[index[i][j][k]][j][k] if axis = 0,\n out[i][j][k] = input[i][index[i][j][k]][k] if axis = 1,\n out[i][j][k] = input[i][j][index[i][j][k]] if axis = 2,\n```\n\nThis operator is also the inverse of ScatterElements. It is similar to Torch's gather operation.\n\nExample 1:\n```\n data = [\n [1, 2],\n [3, 4],\n ]\n indices = [\n [0, 0],\n [1, 0],\n ]\n axis = 1\n output = [\n [1, 1],\n [4, 3],\n ]\n```\nExample 2:\n```\n data = [\n [1, 2, 3],\n [4, 5, 6],\n [7, 8, 9],\n ]\n indices = [\n [1, 2, 0],\n [2, 0, 0],\n ]\n axis = 0\n output = [\n [4, 8, 3],\n [7, 2, 3],\n ]\n```\n", + "attributes": [ + { + "name": "axis", + "type": "int64", + "required": false, + "description": "Which axis to gather on. Negative value means counting dimensions from the back. Accepted range is [-r, r-1] where r = rank(data)." + } + ], + "inputs": [ + { + "name": "data", + "type": "T", + "description": "Tensor of rank r >= 1." + }, + { + "name": "indices", + "type": "Tind", + "description": "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." + } + ], + "min_input": 2, + "max_input": 2, + "outputs": [ + { + "name": "output", + "type": "T", + "description": "Tensor of the same shape as indices." + } + ], + "min_output": 1, + "max_output": 1, + "type_constraints": [ + { + "description": "Constrain input and output types to any tensor type.", + "type_param_str": "T", + "allowed_type_strs": [ + "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)" + ] + }, + { + "description": "Constrain indices to integer types", + "type_param_str": "Tind", + "allowed_type_strs": [ + "tensor(int32)", + "tensor(int64)" + ] + } + ], + "examples": [ + { + "summary": "gather_elements_0", + "code": "axis = 1\nnode = onnx.helper.make_node(\n 'GatherElements',\n inputs=['data', 'indices'],\n outputs=['y'],\n axis=axis,\n)\ndata = np.array([[1, 2],\n [3, 4]], dtype=np.float32)\nindices = np.array([[0, 0],\n [1, 0]], dtype=np.int32)\n\ny = gather_elements(data, indices, axis)\n# print(y) produces\n# [[1, 1],\n# [4, 3]]\n\nexpect(node, inputs=[data, indices.astype(np.int64)], outputs=[y],\n name='test_gather_elements_0')" + }, + { + "summary": "gather_elements_1", + "code": "axis = 0\nnode = onnx.helper.make_node(\n 'GatherElements',\n inputs=['data', 'indices'],\n outputs=['y'],\n axis=axis,\n)\ndata = np.array([[1, 2, 3],\n [4, 5, 6],\n [7, 8, 9]], dtype=np.float32)\nindices = np.array([[1, 2, 0],\n [2, 0, 0]], dtype=np.int32)\n\ny = gather_elements(data, indices, axis)\n# print(y) produces\n# [[4, 8, 3],\n# [7, 2, 3]]\n\nexpect(node, inputs=[data, indices.astype(np.int64)], outputs=[y],\n name='test_gather_elements_1')" + }, + { + "summary": "gather_elements_negative_indices", + "code": "axis = 0\nnode = onnx.helper.make_node(\n 'GatherElements',\n inputs=['data', 'indices'],\n outputs=['y'],\n axis=axis,\n)\ndata = np.array([[1, 2, 3],\n [4, 5, 6],\n [7, 8, 9]], dtype=np.float32)\nindices = np.array([[-1, -2, 0],\n [-2, 0, 0]], dtype=np.int32)\n\ny = gather_elements(data, indices, axis)\n# print(y) produces\n# [[7, 5, 3],\n# [4, 2, 3]]\n\nexpect(node, inputs=[data, indices.astype(np.int64)], outputs=[y],\n name='test_gather_elements_negative_indices')" + } + ] + }, + { + "name": "GatherND", + "module": "ai.onnx", + "version": 11, + "support_level": "common", + "description": "Given `data` tensor of rank `r` >= 1, and `indices` tensor of rank `q` >= 1, this operator gathers\nslices of `data` into an output tensor of rank `q + r - indices_shape[-1] - 1`.\n\n`indices` is an q-dimensional integer tensor, best thought of as a `(q-1)`-dimensional tensor of index-tuples into `data`,\nwhere each element defines a slice of `data`\n\nSome salient points about the inputs' rank and shape:\n\n1) r >= 1 and q >= 1 are to be honored. There is no dependency condition to be met between ranks `r` and `q`\n\n2) The `indices_shape[-1]` should have a value between 1 (inclusive) and rank `r` (inclusive)\n\n3) 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`.\n It is an error if any of the index values are out of bounds.\n\nThe output is computed as follows:\n\nThe output tensor is obtained by mapping each index-tuple in the `indices` tensor to the corresponding slice of the input `data`.\n\n1) If `indices_shape[-1] > r` => error condition\n\n2) If `indices_shape[-1] == r`, since the rank of `indices` is `q`, `indices` can be thought of as a `(q-1)`-dimensional tensor\n containing 1-D tensors of dimension `r`. Let us think of each such `r` ranked tensor as `indices_slice`.\n Each *scalar value* corresponding to `data[indices_slice]` is filled into the corresponding location of the `(q-1)`-dimensional tensor\n to form the `output` tensor (Example 1 below)\n\n3) If `indices_shape[-1] < r`, since the rank of `indices` is `q`, `indices` can be thought of as a `(q-1)`-dimensional tensor\n containing 1-D tensors of dimension `< r`. Let us think of each such tensors as `indices_slice`.\n Each *tensor slice* corresponding to `data[indices_slice , :]` is filled into the corresponding location of the `(q-1)`-dimensional tensor\n to form the `output` tensor (Examples 2, 3, and 4 below)\n\nThis operator is the inverse of `ScatterND`.\n\n`Example 1`\n\n data = [[0,1],[2,3]] # data_shape = [2, 2]\n\n indices = [[0,0],[1,1]] # indices_shape = [2, 2]\n\n output = [0,3] # output_shape = [2]\n\n`Example 2`\n\n data = [[0,1],[2,3]] # data_shape = [2, 2]\n\n indices = [[1],[0]] # indices_shape = [2, 1]\n\n output = [[2,3],[0,1]] # output_shape = [2, 2]\n\n`Example 3`\n\n data = [[[0,1],[2,3]],[[4,5],[6,7]]] # data_shape = [2, 2, 2]\n\n indices = [[0,1],[1,0]] # indices_shape = [2, 2]\n\n output = [[2,3],[4,5]] # output_shape = [2, 2]\n\n`Example 4`\n\n data = [[[0,1],[2,3]],[[4,5],[6,7]]] # data_shape = [2, 2, 2]\n\n indices = [[[0,1]],[[1,0]]] # indices_shape = [2, 1, 2]\n\n output = [[[2,3]],[[4,5]]] # output_shape = [2, 1, 2]\n\n", + "inputs": [ + { + "name": "data", + "type": "T", + "description": "Tensor of rank r >= 1." + }, + { + "name": "indices", + "type": "tensor(int64)", + "description": "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." + } + ], + "min_input": 2, + "max_input": 2, + "outputs": [ + { + "name": "output", + "type": "T", + "description": "Tensor of rank q + r - indices_shape[-1] - 1." + } + ], + "min_output": 1, + "max_output": 1, + "type_constraints": [ + { + "description": "Constrain input and output types to any tensor type.", + "type_param_str": "T", + "allowed_type_strs": [ + "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)" + ] + } + ], + "examples": [ + { + "summary": "float32", + "code": "node = onnx.helper.make_node(\n 'GatherND',\n inputs=['data', 'indices'],\n outputs=['output'],\n)\n\ndata = np.array([[[0, 1], [2, 3]], [[4, 5], [6, 7]]], dtype=np.float32)\nindices = np.array([[[0, 1]], [[1, 0]]], dtype=np.int64)\noutput = gather_nd_impl(data, indices, 0)\nexpected_output = np.array([[[2, 3]], [[4, 5]]], dtype=np.float32)\nassert (np.array_equal(output, expected_output))\nexpect(node, inputs=[data, indices], outputs=[output],\n name='test_gathernd_example_float32')" + }, + { + "summary": "int32", + "code": "node = onnx.helper.make_node(\n 'GatherND',\n inputs=['data', 'indices'],\n outputs=['output'],\n)\n\ndata = np.array([[0, 1], [2, 3]], dtype=np.int32)\nindices = np.array([[0, 0], [1, 1]], dtype=np.int64)\noutput = gather_nd_impl(data, indices, 0)\nexpected_output = np.array([0, 3], dtype=np.int32)\nassert (np.array_equal(output, expected_output))\nexpect(node, inputs=[data, indices], outputs=[output],\n name='test_gathernd_example_int32')" + }, + { + "summary": "int32_batchdim_1", + "code": "node = onnx.helper.make_node(\n 'GatherND',\n inputs=['data', 'indices'],\n outputs=['output'],\n batch_dims=1,\n)\n\ndata = np.array([[[0, 1], [2, 3]], [[4, 5], [6, 7]]], dtype=np.int32)\nindices = np.array([[1], [0]], dtype=np.int64)\noutput = gather_nd_impl(data, indices, 1)\nexpected_output = np.array([[2, 3], [4, 5]], dtype=np.int32)\nassert (np.array_equal(output, expected_output))\nexpect(node, inputs=[data, indices], outputs=[output],\n name='test_gathernd_example_int32_batch_dim1')" + } + ] + }, + { + "name": "GatherND", + "module": "ai.onnx", + "version": 12, + "support_level": "common", + "description": "Given `data` tensor of rank `r` >= 1, `indices` tensor of rank `q` >= 1, and `batch_dims` integer `b`, this operator gathers\nslices of `data` into an output tensor of rank `q + r - indices_shape[-1] - 1 - b`.\n\n`indices` is an q-dimensional integer tensor, best thought of as a `(q-1)`-dimensional tensor of index-tuples into `data`,\nwhere each element defines a slice of `data`\n\n`batch_dims` (denoted as `b`) is an integer indicating the number of batch dimensions, i.e the leading `b` number of dimensions of\n`data` tensor and `indices` are representing the batches, and the gather starts from the `b+1` dimension.\n\nSome salient points about the inputs' rank and shape:\n\n1) r >= 1 and q >= 1 are to be honored. There is no dependency condition to be met between ranks `r` and `q`\n\n2) The first `b` dimensions of the shape of `indices` tensor and `data` tensor must be equal.\n\n3) b < min(q, r) is to be honored.\n\n4) The `indices_shape[-1]` should have a value between 1 (inclusive) and rank `r-b` (inclusive)\n\n5) 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`.\n It is an error if any of the index values are out of bounds.\n\nThe output is computed as follows:\n\nThe output tensor is obtained by mapping each index-tuple in the `indices` tensor to the corresponding slice of the input `data`.\n\n1) If `indices_shape[-1] > r-b` => error condition\n\n2) 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\n 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\n 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]`\n is filled into the corresponding location of the `(q-b-1)`-dimensional tensor to form the `output` tensor (Example 1 below)\n\n3) 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\n containing 1-D tensors of dimension `< r-b`. Let us think of each such tensors as `indices_slice`. Each *tensor slice* corresponding\n to `data[0:b-1, indices_slice , :]` is filled into the corresponding location of the `(q-b-1)`-dimensional tensor\n to form the `output` tensor (Examples 2, 3, 4 and 5 below)\n\nThis operator is the inverse of `ScatterND`.\n\n`Example 1`\n\n batch_dims = 0\n\n data = [[0,1],[2,3]] # data_shape = [2, 2]\n\n indices = [[0,0],[1,1]] # indices_shape = [2, 2]\n\n output = [0,3] # output_shape = [2]\n\n`Example 2`\n\n batch_dims = 0\n\n data = [[0,1],[2,3]] # data_shape = [2, 2]\n\n indices = [[1],[0]] # indices_shape = [2, 1]\n\n output = [[2,3],[0,1]] # output_shape = [2, 2]\n\n`Example 3`\n\n batch_dims = 0\n\n data = [[[0,1],[2,3]],[[4,5],[6,7]]] # data_shape = [2, 2, 2]\n\n indices = [[0,1],[1,0]] # indices_shape = [2, 2]\n\n output = [[2,3],[4,5]] # output_shape = [2, 2]\n\n`Example 4`\n\n batch_dims = 0\n\n data = [[[0,1],[2,3]],[[4,5],[6,7]]] # data_shape = [2, 2, 2]\n\n indices = [[[0,1]],[[1,0]]] # indices_shape = [2, 1, 2]\n\n output = [[[2,3]],[[4,5]]] # output_shape = [2, 1, 2]\n\n`Example 5`\n\n batch_dims = 1\n\n data = [[[0,1],[2,3]],[[4,5],[6,7]]] # data_shape = [2, 2, 2]\n\n indices = [[1],[0]] # indices_shape = [2, 1]\n\n output = [[2,3],[4,5]] # output_shape = [2, 2]\n\n\n", + "attributes": [ + { + "name": "batch_dims", + "type": "int64", + "required": false, + "description": "The number of batch dimensions. The gather of indexing starts from dimension of data[batch_dims:]" + } + ], + "inputs": [ + { + "name": "data", + "type": "T", + "description": "Tensor of rank r >= 1." + }, + { + "name": "indices", + "type": "tensor(int64)", + "description": "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." + } + ], + "min_input": 2, + "max_input": 2, + "outputs": [ + { + "name": "output", + "type": "T", + "description": "Tensor of rank q + r - indices_shape[-1] - 1." + } + ], + "min_output": 1, + "max_output": 1, + "type_constraints": [ + { + "description": "Constrain input and output types to any tensor type.", + "type_param_str": "T", + "allowed_type_strs": [ + "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)" + ] + } + ], + "examples": [ + { + "summary": "float32", + "code": "node = onnx.helper.make_node(\n 'GatherND',\n inputs=['data', 'indices'],\n outputs=['output'],\n)\n\ndata = np.array([[[0, 1], [2, 3]], [[4, 5], [6, 7]]], dtype=np.float32)\nindices = np.array([[[0, 1]], [[1, 0]]], dtype=np.int64)\noutput = gather_nd_impl(data, indices, 0)\nexpected_output = np.array([[[2, 3]], [[4, 5]]], dtype=np.float32)\nassert (np.array_equal(output, expected_output))\nexpect(node, inputs=[data, indices], outputs=[output],\n name='test_gathernd_example_float32')" + }, + { + "summary": "int32", + "code": "node = onnx.helper.make_node(\n 'GatherND',\n inputs=['data', 'indices'],\n outputs=['output'],\n)\n\ndata = np.array([[0, 1], [2, 3]], dtype=np.int32)\nindices = np.array([[0, 0], [1, 1]], dtype=np.int64)\noutput = gather_nd_impl(data, indices, 0)\nexpected_output = np.array([0, 3], dtype=np.int32)\nassert (np.array_equal(output, expected_output))\nexpect(node, inputs=[data, indices], outputs=[output],\n name='test_gathernd_example_int32')" + }, + { + "summary": "int32_batchdim_1", + "code": "node = onnx.helper.make_node(\n 'GatherND',\n inputs=['data', 'indices'],\n outputs=['output'],\n batch_dims=1,\n)\n\ndata = np.array([[[0, 1], [2, 3]], [[4, 5], [6, 7]]], dtype=np.int32)\nindices = np.array([[1], [0]], dtype=np.int64)\noutput = gather_nd_impl(data, indices, 1)\nexpected_output = np.array([[2, 3], [4, 5]], dtype=np.int32)\nassert (np.array_equal(output, expected_output))\nexpect(node, inputs=[data, indices], outputs=[output],\n name='test_gathernd_example_int32_batch_dim1')" + } + ] + }, + { + "name": "GatherND", + "module": "ai.onnx", + "version": 13, + "support_level": "common", + "description": "Given `data` tensor of rank `r` >= 1, `indices` tensor of rank `q` >= 1, and `batch_dims` integer `b`, this operator gathers\nslices of `data` into an output tensor of rank `q + r - indices_shape[-1] - 1 - b`.\n\n`indices` is an q-dimensional integer tensor, best thought of as a `(q-1)`-dimensional tensor of index-tuples into `data`,\nwhere each element defines a slice of `data`\n\n`batch_dims` (denoted as `b`) is an integer indicating the number of batch dimensions, i.e the leading `b` number of dimensions of\n`data` tensor and `indices` are representing the batches, and the gather starts from the `b+1` dimension.\n\nSome salient points about the inputs' rank and shape:\n\n1) r >= 1 and q >= 1 are to be honored. There is no dependency condition to be met between ranks `r` and `q`\n\n2) The first `b` dimensions of the shape of `indices` tensor and `data` tensor must be equal.\n\n3) b < min(q, r) is to be honored.\n\n4) The `indices_shape[-1]` should have a value between 1 (inclusive) and rank `r-b` (inclusive)\n\n5) 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`.\n It is an error if any of the index values are out of bounds.\n\nThe output is computed as follows:\n\nThe output tensor is obtained by mapping each index-tuple in the `indices` tensor to the corresponding slice of the input `data`.\n\n1) If `indices_shape[-1] > r-b` => error condition\n\n2) 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\n 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\n 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]`\n is filled into the corresponding location of the `(q-b-1)`-dimensional tensor to form the `output` tensor (Example 1 below)\n\n3) 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\n containing 1-D tensors of dimension `< r-b`. Let us think of each such tensors as `indices_slice`. Each *tensor slice* corresponding\n to `data[0:b-1, indices_slice , :]` is filled into the corresponding location of the `(q-b-1)`-dimensional tensor\n to form the `output` tensor (Examples 2, 3, 4 and 5 below)\n\nThis operator is the inverse of `ScatterND`.\n\n`Example 1`\n\n batch_dims = 0\n\n data = [[0,1],[2,3]] # data_shape = [2, 2]\n\n indices = [[0,0],[1,1]] # indices_shape = [2, 2]\n\n output = [0,3] # output_shape = [2]\n\n`Example 2`\n\n batch_dims = 0\n\n data = [[0,1],[2,3]] # data_shape = [2, 2]\n\n indices = [[1],[0]] # indices_shape = [2, 1]\n\n output = [[2,3],[0,1]] # output_shape = [2, 2]\n\n`Example 3`\n\n batch_dims = 0\n\n data = [[[0,1],[2,3]],[[4,5],[6,7]]] # data_shape = [2, 2, 2]\n\n indices = [[0,1],[1,0]] # indices_shape = [2, 2]\n\n output = [[2,3],[4,5]] # output_shape = [2, 2]\n\n`Example 4`\n\n batch_dims = 0\n\n data = [[[0,1],[2,3]],[[4,5],[6,7]]] # data_shape = [2, 2, 2]\n\n indices = [[[0,1]],[[1,0]]] # indices_shape = [2, 1, 2]\n\n output = [[[2,3]],[[4,5]]] # output_shape = [2, 1, 2]\n\n`Example 5`\n\n batch_dims = 1\n\n data = [[[0,1],[2,3]],[[4,5],[6,7]]] # data_shape = [2, 2, 2]\n\n indices = [[1],[0]] # indices_shape = [2, 1]\n\n output = [[2,3],[4,5]] # output_shape = [2, 2]\n\n\n", + "attributes": [ + { + "name": "batch_dims", + "type": "int64", + "required": false, + "description": "The number of batch dimensions. The gather of indexing starts from dimension of data[batch_dims:]" + } + ], + "inputs": [ + { + "name": "data", + "type": "T", + "description": "Tensor of rank r >= 1." + }, + { + "name": "indices", + "type": "tensor(int64)", + "description": "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." + } + ], + "min_input": 2, + "max_input": 2, + "outputs": [ + { + "name": "output", + "type": "T", + "description": "Tensor of rank q + r - indices_shape[-1] - 1." + } + ], + "min_output": 1, + "max_output": 1, + "type_constraints": [ + { + "description": "Constrain input and output types to any tensor type.", + "type_param_str": "T", + "allowed_type_strs": [ + "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)" + ] + } + ], + "examples": [ + { + "summary": "float32", + "code": "node = onnx.helper.make_node(\n 'GatherND',\n inputs=['data', 'indices'],\n outputs=['output'],\n)\n\ndata = np.array([[[0, 1], [2, 3]], [[4, 5], [6, 7]]], dtype=np.float32)\nindices = np.array([[[0, 1]], [[1, 0]]], dtype=np.int64)\noutput = gather_nd_impl(data, indices, 0)\nexpected_output = np.array([[[2, 3]], [[4, 5]]], dtype=np.float32)\nassert (np.array_equal(output, expected_output))\nexpect(node, inputs=[data, indices], outputs=[output],\n name='test_gathernd_example_float32')" + }, + { + "summary": "int32", + "code": "node = onnx.helper.make_node(\n 'GatherND',\n inputs=['data', 'indices'],\n outputs=['output'],\n)\n\ndata = np.array([[0, 1], [2, 3]], dtype=np.int32)\nindices = np.array([[0, 0], [1, 1]], dtype=np.int64)\noutput = gather_nd_impl(data, indices, 0)\nexpected_output = np.array([0, 3], dtype=np.int32)\nassert (np.array_equal(output, expected_output))\nexpect(node, inputs=[data, indices], outputs=[output],\n name='test_gathernd_example_int32')" + }, + { + "summary": "int32_batchdim_1", + "code": "node = onnx.helper.make_node(\n 'GatherND',\n inputs=['data', 'indices'],\n outputs=['output'],\n batch_dims=1,\n)\n\ndata = np.array([[[0, 1], [2, 3]], [[4, 5], [6, 7]]], dtype=np.int32)\nindices = np.array([[1], [0]], dtype=np.int64)\noutput = gather_nd_impl(data, indices, 1)\nexpected_output = np.array([[2, 3], [4, 5]], dtype=np.int32)\nassert (np.array_equal(output, expected_output))\nexpect(node, inputs=[data, indices], outputs=[output],\n name='test_gathernd_example_int32_batch_dim1')" + } + ] + }, + { + "name": "Gemm", + "module": "ai.onnx", + "version": 1, + "support_level": "common", + "description": "General Matrix multiplication:\nhttps://en.wikipedia.org/wiki/Basic_Linear_Algebra_Subprograms#Level_3\nCompute Y = alpha * A * B + beta * C, where input tensor A has\ndimension (M X K), input tensor B has dimension (K X N), input tensor C and\noutput tensor Y have dimension (M X N).\nIf attribute broadcast is non-zero, input tensor C will be broadcasted to match\nthe dimension requirement. A will be transposed before doing the computation\nif attribute transA is non-zero, same for B and transB.\n", + "attributes": [ + { + "name": "alpha", + "type": "float32", + "required": false, + "default": 1.0, + "description": "Scalar multiplier for the product of input tensors A * B, the default value is 1.0." + }, + { + "name": "beta", + "type": "float32", + "required": false, + "default": 1.0, + "description": "Scalar multiplier for input tensor C, the default value is 1.0." + }, + { + "name": "broadcast", + "type": "int64", + "required": false, + "description": "Whether C should be broadcasted" + }, + { + "name": "transA", + "type": "int64", + "required": false, + "description": "Whether A should be transposed" + }, + { + "name": "transB", + "type": "int64", + "required": false, + "description": "Whether B should be transposed" + } + ], + "inputs": [ + { + "name": "A", + "type": "T", + "description": "Input tensor A" + }, + { + "name": "B", + "type": "T", + "description": "Input tensor B" + }, + { + "name": "C", + "type": "T", + "description": "Input tensor C, can be inplace." + } + ], + "min_input": 3, + "max_input": 3, + "outputs": [ + { + "name": "Y", + "type": "T", + "description": "Output tensor." + } + ], + "min_output": 1, + "max_output": 1, + "type_constraints": [ + { + "description": "Constrain input and output types to float tensors.", + "type_param_str": "T", + "allowed_type_strs": [ + "tensor(float16)", + "tensor(float)", + "tensor(double)" + ] + } + ], + "examples": [ + { + "summary": "all_attributes", + "code": "node = onnx.helper.make_node(\n 'Gemm',\n inputs=['a', 'b', 'c'],\n outputs=['y'],\n alpha=0.25,\n beta=0.35,\n transA=1,\n transB=1\n)\na = np.random.ranf([4, 3]).astype(np.float32)\nb = np.random.ranf([5, 4]).astype(np.float32)\nc = np.random.ranf([1, 5]).astype(np.float32)\ny = gemm_reference_implementation(a, b, c, transA=1, transB=1, alpha=0.25, beta=0.35)\nexpect(node, inputs=[a, b, c], outputs=[y],\n name='test_gemm_all_attributes')" + }, + { + "summary": "alpha", + "code": "node = onnx.helper.make_node(\n 'Gemm',\n inputs=['a', 'b', 'c'],\n outputs=['y'],\n alpha=0.5\n)\na = np.random.ranf([3, 5]).astype(np.float32)\nb = np.random.ranf([5, 4]).astype(np.float32)\nc = np.zeros([1, 4]).astype(np.float32)\ny = gemm_reference_implementation(a, b, c, alpha=0.5)\nexpect(node, inputs=[a, b, c], outputs=[y],\n name='test_gemm_alpha')" + }, + { + "summary": "beta", + "code": "node = onnx.helper.make_node(\n 'Gemm',\n inputs=['a', 'b', 'c'],\n outputs=['y'],\n beta=0.5\n)\na = np.random.ranf([2, 7]).astype(np.float32)\nb = np.random.ranf([7, 4]).astype(np.float32)\nc = np.random.ranf([1, 4]).astype(np.float32)\ny = gemm_reference_implementation(a, b, c, beta=0.5)\nexpect(node, inputs=[a, b, c], outputs=[y],\n name='test_gemm_beta')" + }, + { + "summary": "default_matrix_bias", + "code": "node = onnx.helper.make_node(\n 'Gemm',\n inputs=['a', 'b', 'c'],\n outputs=['y']\n)\na = np.random.ranf([3, 6]).astype(np.float32)\nb = np.random.ranf([6, 4]).astype(np.float32)\nc = np.random.ranf([3, 4]).astype(np.float32)\ny = gemm_reference_implementation(a, b, c)\nexpect(node, inputs=[a, b, c], outputs=[y],\n name='test_gemm_default_matrix_bias')" + }, + { + "summary": "default_no_bias", + "code": "node = onnx.helper.make_node(\n 'Gemm',\n inputs=['a', 'b'],\n outputs=['y']\n)\na = np.random.ranf([2, 10]).astype(np.float32)\nb = np.random.ranf([10, 3]).astype(np.float32)\ny = gemm_reference_implementation(a, b)\nexpect(node, inputs=[a, b], outputs=[y],\n name='test_gemm_default_no_bias')" + }, + { + "summary": "default_scalar_bias", + "code": "node = onnx.helper.make_node(\n 'Gemm',\n inputs=['a', 'b', 'c'],\n outputs=['y']\n)\na = np.random.ranf([2, 3]).astype(np.float32)\nb = np.random.ranf([3, 4]).astype(np.float32)\nc = np.array(3.14).astype(np.float32)\ny = gemm_reference_implementation(a, b, c)\nexpect(node, inputs=[a, b, c], outputs=[y],\n name='test_gemm_default_scalar_bias')" + }, + { + "summary": "default_single_elem_vector_bias", + "code": "node = onnx.helper.make_node(\n 'Gemm',\n inputs=['a', 'b', 'c'],\n outputs=['y']\n)\na = np.random.ranf([3, 7]).astype(np.float32)\nb = np.random.ranf([7, 3]).astype(np.float32)\nc = np.random.ranf([1]).astype(np.float32)\ny = gemm_reference_implementation(a, b, c)\nexpect(node, inputs=[a, b, c], outputs=[y],\n name='test_gemm_default_single_elem_vector_bias')" + }, + { + "summary": "default_vector_bias", + "code": "node = onnx.helper.make_node(\n 'Gemm',\n inputs=['a', 'b', 'c'],\n outputs=['y']\n)\na = np.random.ranf([2, 7]).astype(np.float32)\nb = np.random.ranf([7, 4]).astype(np.float32)\nc = np.random.ranf([1, 4]).astype(np.float32)\ny = gemm_reference_implementation(a, b, c)\nexpect(node, inputs=[a, b, c], outputs=[y],\n name='test_gemm_default_vector_bias')" + }, + { + "summary": "default_zero_bias", + "code": "node = onnx.helper.make_node(\n 'Gemm',\n inputs=['a', 'b', 'c'],\n outputs=['y']\n)\na = np.random.ranf([3, 5]).astype(np.float32)\nb = np.random.ranf([5, 4]).astype(np.float32)\nc = np.zeros([1, 4]).astype(np.float32)\ny = gemm_reference_implementation(a, b, c)\nexpect(node, inputs=[a, b, c], outputs=[y],\n name='test_gemm_default_zero_bias')" + }, + { + "summary": "transposeA", + "code": "node = onnx.helper.make_node(\n 'Gemm',\n inputs=['a', 'b', 'c'],\n outputs=['y'],\n transA=1\n)\na = np.random.ranf([6, 3]).astype(np.float32)\nb = np.random.ranf([6, 4]).astype(np.float32)\nc = np.zeros([1, 4]).astype(np.float32)\ny = gemm_reference_implementation(a, b, c, transA=1)\nexpect(node, inputs=[a, b, c], outputs=[y],\n name='test_gemm_transposeA')" + }, + { + "summary": "transposeB", + "code": "node = onnx.helper.make_node(\n 'Gemm',\n inputs=['a', 'b', 'c'],\n outputs=['y'],\n transB=1\n)\na = np.random.ranf([3, 6]).astype(np.float32)\nb = np.random.ranf([4, 6]).astype(np.float32)\nc = np.zeros([1, 4]).astype(np.float32)\ny = gemm_reference_implementation(a, b, c, transB=1)\nexpect(node, inputs=[a, b, c], outputs=[y],\n name='test_gemm_transposeB')" + } + ], + "category": "Layer" + }, + { + "name": "Gemm", + "module": "ai.onnx", + "version": 6, + "support_level": "common", + "description": "General Matrix multiplication:\nhttps://en.wikipedia.org/wiki/Basic_Linear_Algebra_Subprograms#Level_3\nCompute Y = alpha * A * B + beta * C, where input tensor A has\ndimension (M X K), input tensor B has dimension (K X N), input tensor C and\noutput tensor Y have dimension (M X N).\nIf attribute broadcast is non-zero, input tensor C will be broadcasted to match\nthe dimension requirement. A will be transposed before doing the computation\nif attribute transA is non-zero, same for B and transB.\n", + "attributes": [ + { + "name": "alpha", + "type": "float32", + "required": false, + "default": 1.0, + "description": "Scalar multiplier for the product of input tensors A * B, the default value is 1.0." + }, + { + "name": "beta", + "type": "float32", + "required": false, + "default": 1.0, + "description": "Scalar multiplier for input tensor C, the default value is 1.0." + }, + { + "name": "broadcast", + "type": "int64", + "required": false, + "description": "Whether C should be broadcasted" + }, + { + "name": "transA", + "type": "int64", + "required": false, + "description": "Whether A should be transposed" + }, + { + "name": "transB", + "type": "int64", + "required": false, + "description": "Whether B should be transposed" + } + ], + "inputs": [ + { + "name": "A", + "type": "T", + "description": "Input tensor A" + }, + { + "name": "B", + "type": "T", + "description": "Input tensor B" + }, + { + "name": "C", + "type": "T", + "description": "Input tensor C" + } + ], + "min_input": 3, + "max_input": 3, + "outputs": [ + { + "name": "Y", + "type": "T", + "description": "Output tensor." + } + ], + "min_output": 1, + "max_output": 1, + "type_constraints": [ + { + "description": "Constrain input and output types to float tensors.", + "type_param_str": "T", + "allowed_type_strs": [ + "tensor(float16)", + "tensor(float)", + "tensor(double)" + ] + } + ], + "examples": [ + { + "summary": "all_attributes", + "code": "node = onnx.helper.make_node(\n 'Gemm',\n inputs=['a', 'b', 'c'],\n outputs=['y'],\n alpha=0.25,\n beta=0.35,\n transA=1,\n transB=1\n)\na = np.random.ranf([4, 3]).astype(np.float32)\nb = np.random.ranf([5, 4]).astype(np.float32)\nc = np.random.ranf([1, 5]).astype(np.float32)\ny = gemm_reference_implementation(a, b, c, transA=1, transB=1, alpha=0.25, beta=0.35)\nexpect(node, inputs=[a, b, c], outputs=[y],\n name='test_gemm_all_attributes')" + }, + { + "summary": "alpha", + "code": "node = onnx.helper.make_node(\n 'Gemm',\n inputs=['a', 'b', 'c'],\n outputs=['y'],\n alpha=0.5\n)\na = np.random.ranf([3, 5]).astype(np.float32)\nb = np.random.ranf([5, 4]).astype(np.float32)\nc = np.zeros([1, 4]).astype(np.float32)\ny = gemm_reference_implementation(a, b, c, alpha=0.5)\nexpect(node, inputs=[a, b, c], outputs=[y],\n name='test_gemm_alpha')" + }, + { + "summary": "beta", + "code": "node = onnx.helper.make_node(\n 'Gemm',\n inputs=['a', 'b', 'c'],\n outputs=['y'],\n beta=0.5\n)\na = np.random.ranf([2, 7]).astype(np.float32)\nb = np.random.ranf([7, 4]).astype(np.float32)\nc = np.random.ranf([1, 4]).astype(np.float32)\ny = gemm_reference_implementation(a, b, c, beta=0.5)\nexpect(node, inputs=[a, b, c], outputs=[y],\n name='test_gemm_beta')" + }, + { + "summary": "default_matrix_bias", + "code": "node = onnx.helper.make_node(\n 'Gemm',\n inputs=['a', 'b', 'c'],\n outputs=['y']\n)\na = np.random.ranf([3, 6]).astype(np.float32)\nb = np.random.ranf([6, 4]).astype(np.float32)\nc = np.random.ranf([3, 4]).astype(np.float32)\ny = gemm_reference_implementation(a, b, c)\nexpect(node, inputs=[a, b, c], outputs=[y],\n name='test_gemm_default_matrix_bias')" + }, + { + "summary": "default_no_bias", + "code": "node = onnx.helper.make_node(\n 'Gemm',\n inputs=['a', 'b'],\n outputs=['y']\n)\na = np.random.ranf([2, 10]).astype(np.float32)\nb = np.random.ranf([10, 3]).astype(np.float32)\ny = gemm_reference_implementation(a, b)\nexpect(node, inputs=[a, b], outputs=[y],\n name='test_gemm_default_no_bias')" + }, + { + "summary": "default_scalar_bias", + "code": "node = onnx.helper.make_node(\n 'Gemm',\n inputs=['a', 'b', 'c'],\n outputs=['y']\n)\na = np.random.ranf([2, 3]).astype(np.float32)\nb = np.random.ranf([3, 4]).astype(np.float32)\nc = np.array(3.14).astype(np.float32)\ny = gemm_reference_implementation(a, b, c)\nexpect(node, inputs=[a, b, c], outputs=[y],\n name='test_gemm_default_scalar_bias')" + }, + { + "summary": "default_single_elem_vector_bias", + "code": "node = onnx.helper.make_node(\n 'Gemm',\n inputs=['a', 'b', 'c'],\n outputs=['y']\n)\na = np.random.ranf([3, 7]).astype(np.float32)\nb = np.random.ranf([7, 3]).astype(np.float32)\nc = np.random.ranf([1]).astype(np.float32)\ny = gemm_reference_implementation(a, b, c)\nexpect(node, inputs=[a, b, c], outputs=[y],\n name='test_gemm_default_single_elem_vector_bias')" + }, + { + "summary": "default_vector_bias", + "code": "node = onnx.helper.make_node(\n 'Gemm',\n inputs=['a', 'b', 'c'],\n outputs=['y']\n)\na = np.random.ranf([2, 7]).astype(np.float32)\nb = np.random.ranf([7, 4]).astype(np.float32)\nc = np.random.ranf([1, 4]).astype(np.float32)\ny = gemm_reference_implementation(a, b, c)\nexpect(node, inputs=[a, b, c], outputs=[y],\n name='test_gemm_default_vector_bias')" + }, + { + "summary": "default_zero_bias", + "code": "node = onnx.helper.make_node(\n 'Gemm',\n inputs=['a', 'b', 'c'],\n outputs=['y']\n)\na = np.random.ranf([3, 5]).astype(np.float32)\nb = np.random.ranf([5, 4]).astype(np.float32)\nc = np.zeros([1, 4]).astype(np.float32)\ny = gemm_reference_implementation(a, b, c)\nexpect(node, inputs=[a, b, c], outputs=[y],\n name='test_gemm_default_zero_bias')" + }, + { + "summary": "transposeA", + "code": "node = onnx.helper.make_node(\n 'Gemm',\n inputs=['a', 'b', 'c'],\n outputs=['y'],\n transA=1\n)\na = np.random.ranf([6, 3]).astype(np.float32)\nb = np.random.ranf([6, 4]).astype(np.float32)\nc = np.zeros([1, 4]).astype(np.float32)\ny = gemm_reference_implementation(a, b, c, transA=1)\nexpect(node, inputs=[a, b, c], outputs=[y],\n name='test_gemm_transposeA')" + }, + { + "summary": "transposeB", + "code": "node = onnx.helper.make_node(\n 'Gemm',\n inputs=['a', 'b', 'c'],\n outputs=['y'],\n transB=1\n)\na = np.random.ranf([3, 6]).astype(np.float32)\nb = np.random.ranf([4, 6]).astype(np.float32)\nc = np.zeros([1, 4]).astype(np.float32)\ny = gemm_reference_implementation(a, b, c, transB=1)\nexpect(node, inputs=[a, b, c], outputs=[y],\n name='test_gemm_transposeB')" + } + ], + "category": "Layer" + }, + { + "name": "Gemm", + "module": "ai.onnx", + "version": 7, + "support_level": "common", + "description": "General Matrix multiplication:\nhttps://en.wikipedia.org/wiki/Basic_Linear_Algebra_Subprograms#Level_3\n\nA' = transpose(A) if transA else A\n\nB' = transpose(B) if transB else B\n\nCompute Y = alpha * A' * B' + beta * C, where input tensor A has shape (M, K) or (K, M),\ninput tensor B has shape (K, N) or (N, K), input tensor C is broadcastable to shape (M, N),\nand output tensor Y has shape (M, N). A will be transposed before doing the\ncomputation if attribute transA is non-zero, same for B and transB.\nThis operator supports **unidirectional broadcasting** (tensor C should be unidirectional broadcastable to tensor A * B); for more details please check [the doc](https://github.com/onnx/onnx/blob/master/docs/Broadcasting.md).", + "attributes": [ + { + "name": "alpha", + "type": "float32", + "required": false, + "default": 1.0, + "description": "Scalar multiplier for the product of input tensors A * B." + }, + { + "name": "beta", + "type": "float32", + "required": false, + "default": 1.0, + "description": "Scalar multiplier for input tensor C." + }, + { + "name": "transA", + "type": "int64", + "required": false, + "description": "Whether A should be transposed" + }, + { + "name": "transB", + "type": "int64", + "required": false, + "description": "Whether B should be transposed" + } + ], + "inputs": [ + { + "name": "A", + "type": "T", + "description": "Input tensor A. The shape of A should be (M, K) if transA is 0, or (K, M) if transA is non-zero." + }, + { + "name": "B", + "type": "T", + "description": "Input tensor B. The shape of B should be (K, N) if transB is 0, or (N, K) if transB is non-zero." + }, + { + "name": "C", + "type": "T", + "description": "Input tensor C. The shape of C should be unidirectional broadcastable to (M, N)." + } + ], + "min_input": 3, + "max_input": 3, + "outputs": [ + { + "name": "Y", + "type": "T", + "description": "Output tensor of shape (M, N)." + } + ], + "min_output": 1, + "max_output": 1, + "type_constraints": [ + { + "description": "Constrain input and output types to float tensors.", + "type_param_str": "T", + "allowed_type_strs": [ + "tensor(float16)", + "tensor(float)", + "tensor(double)" + ] + } + ], + "examples": [ + { + "summary": "all_attributes", + "code": "node = onnx.helper.make_node(\n 'Gemm',\n inputs=['a', 'b', 'c'],\n outputs=['y'],\n alpha=0.25,\n beta=0.35,\n transA=1,\n transB=1\n)\na = np.random.ranf([4, 3]).astype(np.float32)\nb = np.random.ranf([5, 4]).astype(np.float32)\nc = np.random.ranf([1, 5]).astype(np.float32)\ny = gemm_reference_implementation(a, b, c, transA=1, transB=1, alpha=0.25, beta=0.35)\nexpect(node, inputs=[a, b, c], outputs=[y],\n name='test_gemm_all_attributes')" + }, + { + "summary": "alpha", + "code": "node = onnx.helper.make_node(\n 'Gemm',\n inputs=['a', 'b', 'c'],\n outputs=['y'],\n alpha=0.5\n)\na = np.random.ranf([3, 5]).astype(np.float32)\nb = np.random.ranf([5, 4]).astype(np.float32)\nc = np.zeros([1, 4]).astype(np.float32)\ny = gemm_reference_implementation(a, b, c, alpha=0.5)\nexpect(node, inputs=[a, b, c], outputs=[y],\n name='test_gemm_alpha')" + }, + { + "summary": "beta", + "code": "node = onnx.helper.make_node(\n 'Gemm',\n inputs=['a', 'b', 'c'],\n outputs=['y'],\n beta=0.5\n)\na = np.random.ranf([2, 7]).astype(np.float32)\nb = np.random.ranf([7, 4]).astype(np.float32)\nc = np.random.ranf([1, 4]).astype(np.float32)\ny = gemm_reference_implementation(a, b, c, beta=0.5)\nexpect(node, inputs=[a, b, c], outputs=[y],\n name='test_gemm_beta')" + }, + { + "summary": "default_matrix_bias", + "code": "node = onnx.helper.make_node(\n 'Gemm',\n inputs=['a', 'b', 'c'],\n outputs=['y']\n)\na = np.random.ranf([3, 6]).astype(np.float32)\nb = np.random.ranf([6, 4]).astype(np.float32)\nc = np.random.ranf([3, 4]).astype(np.float32)\ny = gemm_reference_implementation(a, b, c)\nexpect(node, inputs=[a, b, c], outputs=[y],\n name='test_gemm_default_matrix_bias')" + }, + { + "summary": "default_no_bias", + "code": "node = onnx.helper.make_node(\n 'Gemm',\n inputs=['a', 'b'],\n outputs=['y']\n)\na = np.random.ranf([2, 10]).astype(np.float32)\nb = np.random.ranf([10, 3]).astype(np.float32)\ny = gemm_reference_implementation(a, b)\nexpect(node, inputs=[a, b], outputs=[y],\n name='test_gemm_default_no_bias')" + }, + { + "summary": "default_scalar_bias", + "code": "node = onnx.helper.make_node(\n 'Gemm',\n inputs=['a', 'b', 'c'],\n outputs=['y']\n)\na = np.random.ranf([2, 3]).astype(np.float32)\nb = np.random.ranf([3, 4]).astype(np.float32)\nc = np.array(3.14).astype(np.float32)\ny = gemm_reference_implementation(a, b, c)\nexpect(node, inputs=[a, b, c], outputs=[y],\n name='test_gemm_default_scalar_bias')" + }, + { + "summary": "default_single_elem_vector_bias", + "code": "node = onnx.helper.make_node(\n 'Gemm',\n inputs=['a', 'b', 'c'],\n outputs=['y']\n)\na = np.random.ranf([3, 7]).astype(np.float32)\nb = np.random.ranf([7, 3]).astype(np.float32)\nc = np.random.ranf([1]).astype(np.float32)\ny = gemm_reference_implementation(a, b, c)\nexpect(node, inputs=[a, b, c], outputs=[y],\n name='test_gemm_default_single_elem_vector_bias')" + }, + { + "summary": "default_vector_bias", + "code": "node = onnx.helper.make_node(\n 'Gemm',\n inputs=['a', 'b', 'c'],\n outputs=['y']\n)\na = np.random.ranf([2, 7]).astype(np.float32)\nb = np.random.ranf([7, 4]).astype(np.float32)\nc = np.random.ranf([1, 4]).astype(np.float32)\ny = gemm_reference_implementation(a, b, c)\nexpect(node, inputs=[a, b, c], outputs=[y],\n name='test_gemm_default_vector_bias')" + }, + { + "summary": "default_zero_bias", + "code": "node = onnx.helper.make_node(\n 'Gemm',\n inputs=['a', 'b', 'c'],\n outputs=['y']\n)\na = np.random.ranf([3, 5]).astype(np.float32)\nb = np.random.ranf([5, 4]).astype(np.float32)\nc = np.zeros([1, 4]).astype(np.float32)\ny = gemm_reference_implementation(a, b, c)\nexpect(node, inputs=[a, b, c], outputs=[y],\n name='test_gemm_default_zero_bias')" + }, + { + "summary": "transposeA", + "code": "node = onnx.helper.make_node(\n 'Gemm',\n inputs=['a', 'b', 'c'],\n outputs=['y'],\n transA=1\n)\na = np.random.ranf([6, 3]).astype(np.float32)\nb = np.random.ranf([6, 4]).astype(np.float32)\nc = np.zeros([1, 4]).astype(np.float32)\ny = gemm_reference_implementation(a, b, c, transA=1)\nexpect(node, inputs=[a, b, c], outputs=[y],\n name='test_gemm_transposeA')" + }, + { + "summary": "transposeB", + "code": "node = onnx.helper.make_node(\n 'Gemm',\n inputs=['a', 'b', 'c'],\n outputs=['y'],\n transB=1\n)\na = np.random.ranf([3, 6]).astype(np.float32)\nb = np.random.ranf([4, 6]).astype(np.float32)\nc = np.zeros([1, 4]).astype(np.float32)\ny = gemm_reference_implementation(a, b, c, transB=1)\nexpect(node, inputs=[a, b, c], outputs=[y],\n name='test_gemm_transposeB')" + } + ], + "category": "Layer" + }, + { + "name": "Gemm", + "module": "ai.onnx", + "version": 9, + "support_level": "common", + "description": "General Matrix multiplication:\nhttps://en.wikipedia.org/wiki/Basic_Linear_Algebra_Subprograms#Level_3\n\nA' = transpose(A) if transA else A\n\nB' = transpose(B) if transB else B\n\nCompute Y = alpha * A' * B' + beta * C, where input tensor A has shape (M, K) or (K, M),\ninput tensor B has shape (K, N) or (N, K), input tensor C is broadcastable to shape (M, N),\nand output tensor Y has shape (M, N). A will be transposed before doing the\ncomputation if attribute transA is non-zero, same for B and transB.\nThis operator supports **unidirectional broadcasting** (tensor C should be unidirectional broadcastable to tensor A * B); for more details please check [the doc](https://github.com/onnx/onnx/blob/master/docs/Broadcasting.md).", + "attributes": [ + { + "name": "alpha", + "type": "float32", + "required": false, + "default": 1.0, + "description": "Scalar multiplier for the product of input tensors A * B." + }, + { + "name": "beta", + "type": "float32", + "required": false, + "default": 1.0, + "description": "Scalar multiplier for input tensor C." + }, + { + "name": "transA", + "type": "int64", + "required": false, + "description": "Whether A should be transposed" + }, + { + "name": "transB", + "type": "int64", + "required": false, + "description": "Whether B should be transposed" + } + ], + "inputs": [ + { + "name": "A", + "type": "T", + "description": "Input tensor A. The shape of A should be (M, K) if transA is 0, or (K, M) if transA is non-zero." + }, + { + "name": "B", + "type": "T", + "description": "Input tensor B. The shape of B should be (K, N) if transB is 0, or (N, K) if transB is non-zero." + }, + { + "name": "C", + "type": "T", + "description": "Input tensor C. The shape of C should be unidirectional broadcastable to (M, N)." + } + ], + "min_input": 3, + "max_input": 3, + "outputs": [ + { + "name": "Y", + "type": "T", + "description": "Output tensor of shape (M, N)." + } + ], + "min_output": 1, + "max_output": 1, + "type_constraints": [ + { + "description": "Constrain input and output types to float/int tensors.", + "type_param_str": "T", + "allowed_type_strs": [ + "tensor(float16)", + "tensor(float)", + "tensor(double)", + "tensor(uint32)", + "tensor(uint64)", + "tensor(int32)", + "tensor(int64)" + ] + } + ], + "examples": [ + { + "summary": "all_attributes", + "code": "node = onnx.helper.make_node(\n 'Gemm',\n inputs=['a', 'b', 'c'],\n outputs=['y'],\n alpha=0.25,\n beta=0.35,\n transA=1,\n transB=1\n)\na = np.random.ranf([4, 3]).astype(np.float32)\nb = np.random.ranf([5, 4]).astype(np.float32)\nc = np.random.ranf([1, 5]).astype(np.float32)\ny = gemm_reference_implementation(a, b, c, transA=1, transB=1, alpha=0.25, beta=0.35)\nexpect(node, inputs=[a, b, c], outputs=[y],\n name='test_gemm_all_attributes')" + }, + { + "summary": "alpha", + "code": "node = onnx.helper.make_node(\n 'Gemm',\n inputs=['a', 'b', 'c'],\n outputs=['y'],\n alpha=0.5\n)\na = np.random.ranf([3, 5]).astype(np.float32)\nb = np.random.ranf([5, 4]).astype(np.float32)\nc = np.zeros([1, 4]).astype(np.float32)\ny = gemm_reference_implementation(a, b, c, alpha=0.5)\nexpect(node, inputs=[a, b, c], outputs=[y],\n name='test_gemm_alpha')" + }, + { + "summary": "beta", + "code": "node = onnx.helper.make_node(\n 'Gemm',\n inputs=['a', 'b', 'c'],\n outputs=['y'],\n beta=0.5\n)\na = np.random.ranf([2, 7]).astype(np.float32)\nb = np.random.ranf([7, 4]).astype(np.float32)\nc = np.random.ranf([1, 4]).astype(np.float32)\ny = gemm_reference_implementation(a, b, c, beta=0.5)\nexpect(node, inputs=[a, b, c], outputs=[y],\n name='test_gemm_beta')" + }, + { + "summary": "default_matrix_bias", + "code": "node = onnx.helper.make_node(\n 'Gemm',\n inputs=['a', 'b', 'c'],\n outputs=['y']\n)\na = np.random.ranf([3, 6]).astype(np.float32)\nb = np.random.ranf([6, 4]).astype(np.float32)\nc = np.random.ranf([3, 4]).astype(np.float32)\ny = gemm_reference_implementation(a, b, c)\nexpect(node, inputs=[a, b, c], outputs=[y],\n name='test_gemm_default_matrix_bias')" + }, + { + "summary": "default_no_bias", + "code": "node = onnx.helper.make_node(\n 'Gemm',\n inputs=['a', 'b'],\n outputs=['y']\n)\na = np.random.ranf([2, 10]).astype(np.float32)\nb = np.random.ranf([10, 3]).astype(np.float32)\ny = gemm_reference_implementation(a, b)\nexpect(node, inputs=[a, b], outputs=[y],\n name='test_gemm_default_no_bias')" + }, + { + "summary": "default_scalar_bias", + "code": "node = onnx.helper.make_node(\n 'Gemm',\n inputs=['a', 'b', 'c'],\n outputs=['y']\n)\na = np.random.ranf([2, 3]).astype(np.float32)\nb = np.random.ranf([3, 4]).astype(np.float32)\nc = np.array(3.14).astype(np.float32)\ny = gemm_reference_implementation(a, b, c)\nexpect(node, inputs=[a, b, c], outputs=[y],\n name='test_gemm_default_scalar_bias')" + }, + { + "summary": "default_single_elem_vector_bias", + "code": "node = onnx.helper.make_node(\n 'Gemm',\n inputs=['a', 'b', 'c'],\n outputs=['y']\n)\na = np.random.ranf([3, 7]).astype(np.float32)\nb = np.random.ranf([7, 3]).astype(np.float32)\nc = np.random.ranf([1]).astype(np.float32)\ny = gemm_reference_implementation(a, b, c)\nexpect(node, inputs=[a, b, c], outputs=[y],\n name='test_gemm_default_single_elem_vector_bias')" + }, + { + "summary": "default_vector_bias", + "code": "node = onnx.helper.make_node(\n 'Gemm',\n inputs=['a', 'b', 'c'],\n outputs=['y']\n)\na = np.random.ranf([2, 7]).astype(np.float32)\nb = np.random.ranf([7, 4]).astype(np.float32)\nc = np.random.ranf([1, 4]).astype(np.float32)\ny = gemm_reference_implementation(a, b, c)\nexpect(node, inputs=[a, b, c], outputs=[y],\n name='test_gemm_default_vector_bias')" + }, + { + "summary": "default_zero_bias", + "code": "node = onnx.helper.make_node(\n 'Gemm',\n inputs=['a', 'b', 'c'],\n outputs=['y']\n)\na = np.random.ranf([3, 5]).astype(np.float32)\nb = np.random.ranf([5, 4]).astype(np.float32)\nc = np.zeros([1, 4]).astype(np.float32)\ny = gemm_reference_implementation(a, b, c)\nexpect(node, inputs=[a, b, c], outputs=[y],\n name='test_gemm_default_zero_bias')" + }, + { + "summary": "transposeA", + "code": "node = onnx.helper.make_node(\n 'Gemm',\n inputs=['a', 'b', 'c'],\n outputs=['y'],\n transA=1\n)\na = np.random.ranf([6, 3]).astype(np.float32)\nb = np.random.ranf([6, 4]).astype(np.float32)\nc = np.zeros([1, 4]).astype(np.float32)\ny = gemm_reference_implementation(a, b, c, transA=1)\nexpect(node, inputs=[a, b, c], outputs=[y],\n name='test_gemm_transposeA')" + }, + { + "summary": "transposeB", + "code": "node = onnx.helper.make_node(\n 'Gemm',\n inputs=['a', 'b', 'c'],\n outputs=['y'],\n transB=1\n)\na = np.random.ranf([3, 6]).astype(np.float32)\nb = np.random.ranf([4, 6]).astype(np.float32)\nc = np.zeros([1, 4]).astype(np.float32)\ny = gemm_reference_implementation(a, b, c, transB=1)\nexpect(node, inputs=[a, b, c], outputs=[y],\n name='test_gemm_transposeB')" + } + ], + "category": "Layer" + }, + { + "name": "Gemm", + "module": "ai.onnx", + "version": 11, + "support_level": "common", + "description": "General Matrix multiplication:\nhttps://en.wikipedia.org/wiki/Basic_Linear_Algebra_Subprograms#Level_3\n\nA' = transpose(A) if transA else A\n\nB' = transpose(B) if transB else B\n\nCompute Y = alpha * A' * B' + beta * C, where input tensor A has shape (M, K) or (K, M),\ninput tensor B has shape (K, N) or (N, K), input tensor C is broadcastable to shape (M, N),\nand output tensor Y has shape (M, N). A will be transposed before doing the\ncomputation if attribute transA is non-zero, same for B and transB.\nThis operator supports **unidirectional broadcasting** (tensor C should be unidirectional broadcastable to tensor A * B); for more details please check [the doc](https://github.com/onnx/onnx/blob/master/docs/Broadcasting.md).\nThis operator has **optional** inputs/outputs. See [the doc](https://github.com/onnx/onnx/blob/master/docs/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.\n", + "attributes": [ + { + "name": "alpha", + "type": "float32", + "required": false, + "default": 1.0, + "description": "Scalar multiplier for the product of input tensors A * B." + }, + { + "name": "beta", + "type": "float32", + "required": false, + "default": 1.0, + "description": "Scalar multiplier for input tensor C." + }, + { + "name": "transA", + "type": "int64", + "required": false, + "description": "Whether A should be transposed" + }, + { + "name": "transB", + "type": "int64", + "required": false, + "description": "Whether B should be transposed" + } + ], + "inputs": [ + { + "name": "A", + "type": "T", + "description": "Input tensor A. The shape of A should be (M, K) if transA is 0, or (K, M) if transA is non-zero." + }, + { + "name": "B", + "type": "T", + "description": "Input tensor B. The shape of B should be (K, N) if transB is 0, or (N, K) if transB is non-zero." + }, + { + "name": "C", + "type": "T", + "option": "optional", + "description": "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)." + } + ], + "min_input": 2, + "max_input": 3, + "outputs": [ + { + "name": "Y", + "type": "T", + "description": "Output tensor of shape (M, N)." + } + ], + "min_output": 1, + "max_output": 1, + "inputs_range": "2 - 3", + "type_constraints": [ + { + "description": "Constrain input and output types to float/int tensors.", + "type_param_str": "T", + "allowed_type_strs": [ + "tensor(float16)", + "tensor(float)", + "tensor(double)", + "tensor(uint32)", + "tensor(uint64)", + "tensor(int32)", + "tensor(int64)" + ] + } + ], + "examples": [ + { + "summary": "all_attributes", + "code": "node = onnx.helper.make_node(\n 'Gemm',\n inputs=['a', 'b', 'c'],\n outputs=['y'],\n alpha=0.25,\n beta=0.35,\n transA=1,\n transB=1\n)\na = np.random.ranf([4, 3]).astype(np.float32)\nb = np.random.ranf([5, 4]).astype(np.float32)\nc = np.random.ranf([1, 5]).astype(np.float32)\ny = gemm_reference_implementation(a, b, c, transA=1, transB=1, alpha=0.25, beta=0.35)\nexpect(node, inputs=[a, b, c], outputs=[y],\n name='test_gemm_all_attributes')" + }, + { + "summary": "alpha", + "code": "node = onnx.helper.make_node(\n 'Gemm',\n inputs=['a', 'b', 'c'],\n outputs=['y'],\n alpha=0.5\n)\na = np.random.ranf([3, 5]).astype(np.float32)\nb = np.random.ranf([5, 4]).astype(np.float32)\nc = np.zeros([1, 4]).astype(np.float32)\ny = gemm_reference_implementation(a, b, c, alpha=0.5)\nexpect(node, inputs=[a, b, c], outputs=[y],\n name='test_gemm_alpha')" + }, + { + "summary": "beta", + "code": "node = onnx.helper.make_node(\n 'Gemm',\n inputs=['a', 'b', 'c'],\n outputs=['y'],\n beta=0.5\n)\na = np.random.ranf([2, 7]).astype(np.float32)\nb = np.random.ranf([7, 4]).astype(np.float32)\nc = np.random.ranf([1, 4]).astype(np.float32)\ny = gemm_reference_implementation(a, b, c, beta=0.5)\nexpect(node, inputs=[a, b, c], outputs=[y],\n name='test_gemm_beta')" + }, + { + "summary": "default_matrix_bias", + "code": "node = onnx.helper.make_node(\n 'Gemm',\n inputs=['a', 'b', 'c'],\n outputs=['y']\n)\na = np.random.ranf([3, 6]).astype(np.float32)\nb = np.random.ranf([6, 4]).astype(np.float32)\nc = np.random.ranf([3, 4]).astype(np.float32)\ny = gemm_reference_implementation(a, b, c)\nexpect(node, inputs=[a, b, c], outputs=[y],\n name='test_gemm_default_matrix_bias')" + }, + { + "summary": "default_no_bias", + "code": "node = onnx.helper.make_node(\n 'Gemm',\n inputs=['a', 'b'],\n outputs=['y']\n)\na = np.random.ranf([2, 10]).astype(np.float32)\nb = np.random.ranf([10, 3]).astype(np.float32)\ny = gemm_reference_implementation(a, b)\nexpect(node, inputs=[a, b], outputs=[y],\n name='test_gemm_default_no_bias')" + }, + { + "summary": "default_scalar_bias", + "code": "node = onnx.helper.make_node(\n 'Gemm',\n inputs=['a', 'b', 'c'],\n outputs=['y']\n)\na = np.random.ranf([2, 3]).astype(np.float32)\nb = np.random.ranf([3, 4]).astype(np.float32)\nc = np.array(3.14).astype(np.float32)\ny = gemm_reference_implementation(a, b, c)\nexpect(node, inputs=[a, b, c], outputs=[y],\n name='test_gemm_default_scalar_bias')" + }, + { + "summary": "default_single_elem_vector_bias", + "code": "node = onnx.helper.make_node(\n 'Gemm',\n inputs=['a', 'b', 'c'],\n outputs=['y']\n)\na = np.random.ranf([3, 7]).astype(np.float32)\nb = np.random.ranf([7, 3]).astype(np.float32)\nc = np.random.ranf([1]).astype(np.float32)\ny = gemm_reference_implementation(a, b, c)\nexpect(node, inputs=[a, b, c], outputs=[y],\n name='test_gemm_default_single_elem_vector_bias')" + }, + { + "summary": "default_vector_bias", + "code": "node = onnx.helper.make_node(\n 'Gemm',\n inputs=['a', 'b', 'c'],\n outputs=['y']\n)\na = np.random.ranf([2, 7]).astype(np.float32)\nb = np.random.ranf([7, 4]).astype(np.float32)\nc = np.random.ranf([1, 4]).astype(np.float32)\ny = gemm_reference_implementation(a, b, c)\nexpect(node, inputs=[a, b, c], outputs=[y],\n name='test_gemm_default_vector_bias')" + }, + { + "summary": "default_zero_bias", + "code": "node = onnx.helper.make_node(\n 'Gemm',\n inputs=['a', 'b', 'c'],\n outputs=['y']\n)\na = np.random.ranf([3, 5]).astype(np.float32)\nb = np.random.ranf([5, 4]).astype(np.float32)\nc = np.zeros([1, 4]).astype(np.float32)\ny = gemm_reference_implementation(a, b, c)\nexpect(node, inputs=[a, b, c], outputs=[y],\n name='test_gemm_default_zero_bias')" + }, + { + "summary": "transposeA", + "code": "node = onnx.helper.make_node(\n 'Gemm',\n inputs=['a', 'b', 'c'],\n outputs=['y'],\n transA=1\n)\na = np.random.ranf([6, 3]).astype(np.float32)\nb = np.random.ranf([6, 4]).astype(np.float32)\nc = np.zeros([1, 4]).astype(np.float32)\ny = gemm_reference_implementation(a, b, c, transA=1)\nexpect(node, inputs=[a, b, c], outputs=[y],\n name='test_gemm_transposeA')" + }, + { + "summary": "transposeB", + "code": "node = onnx.helper.make_node(\n 'Gemm',\n inputs=['a', 'b', 'c'],\n outputs=['y'],\n transB=1\n)\na = np.random.ranf([3, 6]).astype(np.float32)\nb = np.random.ranf([4, 6]).astype(np.float32)\nc = np.zeros([1, 4]).astype(np.float32)\ny = gemm_reference_implementation(a, b, c, transB=1)\nexpect(node, inputs=[a, b, c], outputs=[y],\n name='test_gemm_transposeB')" + } + ], + "category": "Layer" + }, + { + "name": "Gemm", + "module": "ai.onnx", + "version": 13, + "support_level": "common", + "description": "General Matrix multiplication:\nhttps://en.wikipedia.org/wiki/Basic_Linear_Algebra_Subprograms#Level_3\n\nA' = transpose(A) if transA else A\n\nB' = transpose(B) if transB else B\n\nCompute Y = alpha * A' * B' + beta * C, where input tensor A has shape (M, K) or (K, M),\ninput tensor B has shape (K, N) or (N, K), input tensor C is broadcastable to shape (M, N),\nand output tensor Y has shape (M, N). A will be transposed before doing the\ncomputation if attribute transA is non-zero, same for B and transB.\nThis operator supports **unidirectional broadcasting** (tensor C should be unidirectional broadcastable to tensor A * B); for more details please check [the doc](https://github.com/onnx/onnx/blob/master/docs/Broadcasting.md).\nThis operator has **optional** inputs/outputs. See [the doc](https://github.com/onnx/onnx/blob/master/docs/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.\n", + "attributes": [ + { + "name": "alpha", + "type": "float32", + "required": false, + "default": 1.0, + "description": "Scalar multiplier for the product of input tensors A * B." + }, + { + "name": "beta", + "type": "float32", + "required": false, + "default": 1.0, + "description": "Scalar multiplier for input tensor C." + }, + { + "name": "transA", + "type": "int64", + "required": false, + "description": "Whether A should be transposed" + }, + { + "name": "transB", + "type": "int64", + "required": false, + "description": "Whether B should be transposed" + } + ], + "inputs": [ + { + "name": "A", + "type": "T", + "description": "Input tensor A. The shape of A should be (M, K) if transA is 0, or (K, M) if transA is non-zero." + }, + { + "name": "B", + "type": "T", + "description": "Input tensor B. The shape of B should be (K, N) if transB is 0, or (N, K) if transB is non-zero." + }, + { + "name": "C", + "type": "T", + "option": "optional", + "description": "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)." + } + ], + "min_input": 2, + "max_input": 3, + "outputs": [ + { + "name": "Y", + "type": "T", + "description": "Output tensor of shape (M, N)." + } + ], + "min_output": 1, + "max_output": 1, + "inputs_range": "2 - 3", + "type_constraints": [ + { + "description": "Constrain input and output types to float/int tensors.", + "type_param_str": "T", + "allowed_type_strs": [ + "tensor(float16)", + "tensor(float)", + "tensor(double)", + "tensor(uint32)", + "tensor(uint64)", + "tensor(int32)", + "tensor(int64)", + "tensor(bfloat16)" + ] + } + ], + "examples": [ + { + "summary": "all_attributes", + "code": "node = onnx.helper.make_node(\n 'Gemm',\n inputs=['a', 'b', 'c'],\n outputs=['y'],\n alpha=0.25,\n beta=0.35,\n transA=1,\n transB=1\n)\na = np.random.ranf([4, 3]).astype(np.float32)\nb = np.random.ranf([5, 4]).astype(np.float32)\nc = np.random.ranf([1, 5]).astype(np.float32)\ny = gemm_reference_implementation(a, b, c, transA=1, transB=1, alpha=0.25, beta=0.35)\nexpect(node, inputs=[a, b, c], outputs=[y],\n name='test_gemm_all_attributes')" + }, + { + "summary": "alpha", + "code": "node = onnx.helper.make_node(\n 'Gemm',\n inputs=['a', 'b', 'c'],\n outputs=['y'],\n alpha=0.5\n)\na = np.random.ranf([3, 5]).astype(np.float32)\nb = np.random.ranf([5, 4]).astype(np.float32)\nc = np.zeros([1, 4]).astype(np.float32)\ny = gemm_reference_implementation(a, b, c, alpha=0.5)\nexpect(node, inputs=[a, b, c], outputs=[y],\n name='test_gemm_alpha')" + }, + { + "summary": "beta", + "code": "node = onnx.helper.make_node(\n 'Gemm',\n inputs=['a', 'b', 'c'],\n outputs=['y'],\n beta=0.5\n)\na = np.random.ranf([2, 7]).astype(np.float32)\nb = np.random.ranf([7, 4]).astype(np.float32)\nc = np.random.ranf([1, 4]).astype(np.float32)\ny = gemm_reference_implementation(a, b, c, beta=0.5)\nexpect(node, inputs=[a, b, c], outputs=[y],\n name='test_gemm_beta')" + }, + { + "summary": "default_matrix_bias", + "code": "node = onnx.helper.make_node(\n 'Gemm',\n inputs=['a', 'b', 'c'],\n outputs=['y']\n)\na = np.random.ranf([3, 6]).astype(np.float32)\nb = np.random.ranf([6, 4]).astype(np.float32)\nc = np.random.ranf([3, 4]).astype(np.float32)\ny = gemm_reference_implementation(a, b, c)\nexpect(node, inputs=[a, b, c], outputs=[y],\n name='test_gemm_default_matrix_bias')" + }, + { + "summary": "default_no_bias", + "code": "node = onnx.helper.make_node(\n 'Gemm',\n inputs=['a', 'b'],\n outputs=['y']\n)\na = np.random.ranf([2, 10]).astype(np.float32)\nb = np.random.ranf([10, 3]).astype(np.float32)\ny = gemm_reference_implementation(a, b)\nexpect(node, inputs=[a, b], outputs=[y],\n name='test_gemm_default_no_bias')" + }, + { + "summary": "default_scalar_bias", + "code": "node = onnx.helper.make_node(\n 'Gemm',\n inputs=['a', 'b', 'c'],\n outputs=['y']\n)\na = np.random.ranf([2, 3]).astype(np.float32)\nb = np.random.ranf([3, 4]).astype(np.float32)\nc = np.array(3.14).astype(np.float32)\ny = gemm_reference_implementation(a, b, c)\nexpect(node, inputs=[a, b, c], outputs=[y],\n name='test_gemm_default_scalar_bias')" + }, + { + "summary": "default_single_elem_vector_bias", + "code": "node = onnx.helper.make_node(\n 'Gemm',\n inputs=['a', 'b', 'c'],\n outputs=['y']\n)\na = np.random.ranf([3, 7]).astype(np.float32)\nb = np.random.ranf([7, 3]).astype(np.float32)\nc = np.random.ranf([1]).astype(np.float32)\ny = gemm_reference_implementation(a, b, c)\nexpect(node, inputs=[a, b, c], outputs=[y],\n name='test_gemm_default_single_elem_vector_bias')" + }, + { + "summary": "default_vector_bias", + "code": "node = onnx.helper.make_node(\n 'Gemm',\n inputs=['a', 'b', 'c'],\n outputs=['y']\n)\na = np.random.ranf([2, 7]).astype(np.float32)\nb = np.random.ranf([7, 4]).astype(np.float32)\nc = np.random.ranf([1, 4]).astype(np.float32)\ny = gemm_reference_implementation(a, b, c)\nexpect(node, inputs=[a, b, c], outputs=[y],\n name='test_gemm_default_vector_bias')" + }, + { + "summary": "default_zero_bias", + "code": "node = onnx.helper.make_node(\n 'Gemm',\n inputs=['a', 'b', 'c'],\n outputs=['y']\n)\na = np.random.ranf([3, 5]).astype(np.float32)\nb = np.random.ranf([5, 4]).astype(np.float32)\nc = np.zeros([1, 4]).astype(np.float32)\ny = gemm_reference_implementation(a, b, c)\nexpect(node, inputs=[a, b, c], outputs=[y],\n name='test_gemm_default_zero_bias')" + }, + { + "summary": "transposeA", + "code": "node = onnx.helper.make_node(\n 'Gemm',\n inputs=['a', 'b', 'c'],\n outputs=['y'],\n transA=1\n)\na = np.random.ranf([6, 3]).astype(np.float32)\nb = np.random.ranf([6, 4]).astype(np.float32)\nc = np.zeros([1, 4]).astype(np.float32)\ny = gemm_reference_implementation(a, b, c, transA=1)\nexpect(node, inputs=[a, b, c], outputs=[y],\n name='test_gemm_transposeA')" + }, + { + "summary": "transposeB", + "code": "node = onnx.helper.make_node(\n 'Gemm',\n inputs=['a', 'b', 'c'],\n outputs=['y'],\n transB=1\n)\na = np.random.ranf([3, 6]).astype(np.float32)\nb = np.random.ranf([4, 6]).astype(np.float32)\nc = np.zeros([1, 4]).astype(np.float32)\ny = gemm_reference_implementation(a, b, c, transB=1)\nexpect(node, inputs=[a, b, c], outputs=[y],\n name='test_gemm_transposeB')" + } + ], + "category": "Layer" + }, + { + "name": "GlobalAveragePool", + "module": "ai.onnx", + "version": 1, + "support_level": "common", + "description": "GlobalAveragePool consumes an input tensor X and applies average pooling across\n the values in the same channel. This is equivalent to AveragePool with kernel size\n equal to the spatial dimension of input tensor.", + "inputs": [ + { + "name": "X", + "type": "T", + "description": "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." + } + ], + "min_input": 1, + "max_input": 1, + "outputs": [ + { + "name": "Y", + "type": "T", + "description": "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." + } + ], + "min_output": 1, + "max_output": 1, + "type_constraints": [ + { + "description": "Constrain input and output types to float tensors.", + "type_param_str": "T", + "allowed_type_strs": [ + "tensor(float16)", + "tensor(float)", + "tensor(double)" + ] + } + ], + "examples": [ + { + "summary": "globalaveragepool", + "code": "node = onnx.helper.make_node(\n 'GlobalAveragePool',\n inputs=['x'],\n outputs=['y'],\n)\nx = np.random.randn(1, 3, 5, 5).astype(np.float32)\ny = np.mean(x, axis=tuple(range(2, np.ndim(x))), keepdims=True)\nexpect(node, inputs=[x], outputs=[y], name='test_globalaveragepool')" + }, + { + "summary": "globalaveragepool_precomputed", + "code": "\nnode = onnx.helper.make_node(\n 'GlobalAveragePool',\n inputs=['x'],\n outputs=['y'],\n)\nx = np.array([[[\n [1, 2, 3],\n [4, 5, 6],\n [7, 8, 9],\n]]]).astype(np.float32)\ny = np.array([[[[5]]]]).astype(np.float32)\nexpect(node, inputs=[x], outputs=[y], name='test_globalaveragepool_precomputed')" + } + ], + "category": "Pool" + }, + { + "name": "GlobalLpPool", + "module": "ai.onnx", + "version": 1, + "support_level": "common", + "description": "GlobalLpPool consumes an input tensor X and applies lp pool pooling across the\n the values in the same channel. This is equivalent to LpPool with kernel size\n equal to the spatial dimension of input tensor.", + "attributes": [ + { + "name": "p", + "type": "float32", + "required": false, + "default": 2.0, + "description": "p value of the Lp norm used to pool over the input data, default is 2.0." + } + ], + "inputs": [ + { + "name": "X", + "type": "T", + "description": "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." + } + ], + "min_input": 1, + "max_input": 1, + "outputs": [ + { + "name": "Y", + "type": "T", + "description": "Output data tensor from pooling across the input tensor. Dimensions will be N x C x 1 x 1" + } + ], + "min_output": 1, + "max_output": 1, + "type_constraints": [ + { + "description": "Constrain input and output types to float tensors.", + "type_param_str": "T", + "allowed_type_strs": [ + "tensor(float16)", + "tensor(float)", + "tensor(double)" + ] + } + ], + "category": "Pool" + }, + { + "name": "GlobalLpPool", + "module": "ai.onnx", + "version": 2, + "support_level": "common", + "description": "GlobalLpPool consumes an input tensor X and applies lp pool pooling across\n the values in the same channel. This is equivalent to LpPool with kernel size\n equal to the spatial dimension of input tensor.", + "attributes": [ + { + "name": "p", + "type": "int64", + "required": false, + "default": 2, + "description": "p value of the Lp norm used to pool over the input data." + } + ], + "inputs": [ + { + "name": "X", + "type": "T", + "description": "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." + } + ], + "min_input": 1, + "max_input": 1, + "outputs": [ + { + "name": "Y", + "type": "T", + "description": "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." + } + ], + "min_output": 1, + "max_output": 1, + "type_constraints": [ + { + "description": "Constrain input and output types to float tensors.", + "type_param_str": "T", + "allowed_type_strs": [ + "tensor(float16)", + "tensor(float)", + "tensor(double)" + ] + } + ], + "category": "Pool" + }, + { + "name": "GlobalMaxPool", + "module": "ai.onnx", + "version": 1, + "support_level": "common", + "description": "GlobalMaxPool consumes an input tensor X and applies max pooling across\n the values in the same channel. This is equivalent to MaxPool with kernel size\n equal to the spatial dimension of input tensor.", + "inputs": [ + { + "name": "X", + "type": "T", + "description": "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." + } + ], + "min_input": 1, + "max_input": 1, + "outputs": [ + { + "name": "Y", + "type": "T", + "description": "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." + } + ], + "min_output": 1, + "max_output": 1, + "type_constraints": [ + { + "description": "Constrain input and output types to float tensors.", + "type_param_str": "T", + "allowed_type_strs": [ + "tensor(float16)", + "tensor(float)", + "tensor(double)" + ] + } + ], + "examples": [ + { + "summary": "globalmaxpool", + "code": "\nnode = onnx.helper.make_node(\n 'GlobalMaxPool',\n inputs=['x'],\n outputs=['y'],\n)\nx = np.random.randn(1, 3, 5, 5).astype(np.float32)\ny = np.max(x, axis=tuple(range(2, np.ndim(x))), keepdims=True)\nexpect(node, inputs=[x], outputs=[y], name='test_globalmaxpool')" + }, + { + "summary": "globalmaxpool_precomputed", + "code": "\nnode = onnx.helper.make_node(\n 'GlobalMaxPool',\n inputs=['x'],\n outputs=['y'],\n)\nx = np.array([[[\n [1, 2, 3],\n [4, 5, 6],\n [7, 8, 9],\n]]]).astype(np.float32)\ny = np.array([[[[9]]]]).astype(np.float32)\nexpect(node, inputs=[x], outputs=[y], name='test_globalmaxpool_precomputed')" + } + ], + "category": "Pool" + }, + { + "name": "Gradient", + "module": "ai.onnx.preview.training", + "version": 1, + "support_level": "common", + "description": "Gradient operator computes the partial derivatives of a specific tensor w.r.t.\nsome other tensors. This operator is widely used in gradient-based training\nalgorithms. To illustrate its use, let's consider a computation graph,\n\n```\nX -----.\n |\n v\nW --> Conv --> H --> Gemm --> Y\n ^\n |\n Z\n```\n\n, where W and Z are trainable tensors. Note that operators' attributes are\nomitted for the sake of simplicity. Let dY/dW (dY/dZ) be the gradient of\nY with respect to W (Z). The user can compute gradient by inserting Gradient\noperator to form another graph shown below.\n\n```\nW --> Conv --> H --> Gemm --> Y\n| ^ ^\n| | |\n| X Z\n| | |\n| | .----------'\n| | | (W/Z/X is the 1st/2nd/3rd input of Gradient as shown in\n| | | \"xs\" followed by \"zs\")\n| v v\n'---> Gradient(xs=[\"W\", \"Z\"], zs=[\"X\"], y=\"Y\")\n | |\n | '-----------------------------------> dY/dW (1st output of Gradient)\n |\n '---------------------------------------> dY/dZ (2nd output of Gradient)\n```\n\nBy definition, the tensor \"y\" is a function of independent variables in \"xs\"\nand \"zs\". Since we only compute the gradient of \"y\" w.r.t. the differentiable\nvariables in \"xs\", this Gradient only outputs dY/dW and dY/dZ. Note that \"H\"\ncannot appear in \"xs\" and \"zs\". The reason is that \"H\" can be determined by\ntensors \"W\" and \"X\" and therefore \"H\" is not an independent variable.\n\nAll outputs are optional. If needed, for example, user can assign an empty\nstring to the 1st output name of that Gradient to skip the generation of dY/dW.\nNote that the concept of optional outputs can also be found in ONNX's RNN, GRU,\nand LSTM.\n\nGradient operator can compute derivative against intermediate tensors. For\nexample, the gradient of Y with respect to H can be done via\n\n```\nW --> Conv --> H --> Gemm --> Y\n ^ | ^\n | | |\n X | Z\n .-------' |\n | .----------'\n | | (H/Z is the 1st/2nd input of Gradient as shown in \"xs\")\n v v\n Gradient(xs=[\"H\", \"Z\"], y=\"Y\")\n | |\n | '-----------------------------------> dY/dH (1st output of Gradient)\n |\n '---------------------------------------> dY/dZ (2nd output of Gradient)\n```\n\nIt is possible to represent high-order differentiation using Gradient operators.\nFor example, given the following linear model:\n\n```\nW --> Gemm --> Y --> Loss --> O\n ^ ^\n | |\n X L\n```\n\nTo compute the 2nd order derivative of O with respect to W (denoted by\nd^2O/dW^2), one can do\n\n```\nW --> Gemm --> Y --> Loss --> O\n| ^ ^\n| | |\n| X .------------L\n| | | |\n| | | v\n+------+-+> Gradient(xs=[\"X\", \"W\"], zs=[\"L\"], y=\"O\") ---> dO/dX (1st output of Gradient)\n| | | |\n| | | '---> dO/dW (2nd output of Gradient)\n| v v\n'---> Gradient(xs=[\"X\", \"W\"], zs=[\"L\"], y=\"dO/dW\") ---> d(dO/dW)dX (1st output of\n | Gradient)\n |\n |\n '---> d^2O/dW^2 (2nd output of Gradient)\n```\n\nThe tensors named in attributes \"xs\", \"zs\", and \"y\" define the differentiated\ncomputation graph, and the inputs to Gradient node define the values at\nwhich the gradient is computed. We can feed different tensors to the identified\ngraph. For example, one can compute the gradient of Y with respect to H at\na specific value of H, H_1, by providing that value as an input to the Gradient\nnode.\n\n```\nW --> Conv --> H --> Gemm --> Y\n ^ ^\n | |\n X Z\n\n Z_1 (2nd input of Gradient)\n |\n v\nH_1 --> Gradient(xs=[\"H\", \"Z\"], y=\"Y\") ---> dY/dH when H = H_1 and Y = Y_1.\n |\n '------------------------------> dY/dZ (2nd output of Gradient)\n```\n\nWhen the inputs of Gradient are the tensors named in \"xs\" and \"zs\", the\ncomputation can be optimized. More specifically, intermediate variables in\nforward pass can be reused if the gradient is computed via reverse-mode\nauto-differentiation.\n\n", + "attributes": [ + { + "name": "xs", + "type": "string[]", + "required": true, + "description": "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." + }, + { + "name": "y", + "type": "string", + "required": true, + "description": "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\"." + }, + { + "name": "zs", + "type": "string[]", + "required": false, + "description": "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": [ + { + "name": "Inputs", + "type": "T1", + "list": true, + "description": "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\"." + } + ], + "min_input": 1, + "max_input": 2147483647, + "outputs": [ + { + "name": "Outputs", + "type": "T2", + "list": true, + "description": "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\"." + } + ], + "min_output": 1, + "max_output": 2147483647, + "inputs_range": "1 - ∞", + "outputs_range": "1 - ∞", + "type_constraints": [ + { + "description": "Allow outputs to be any kind of tensor.", + "type_param_str": "T1", + "allowed_type_strs": [ + "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)" + ] + }, + { + "description": "Allow inputs to be any kind of floating-point tensor.", + "type_param_str": "T2", + "allowed_type_strs": [ + "tensor(float16)", + "tensor(float)", + "tensor(double)" + ] + } + ], + "examples": [ + { + "summary": "gradient_scalar_add", + "code": "add_node = onnx.helper.make_node('Add',\n ['a', 'b'], ['c'], name='my_add')\ngradient_node = onnx.helper.make_node(\n 'Gradient', ['a', 'b'],\n ['dc_da', 'dc_db'], name='my_gradient',\n domain=AI_ONNX_PREVIEW_TRAINING_DOMAIN,\n xs=['a', 'b'], y='c')\n\na = np.array(1.0).astype(np.float32)\nb = np.array(2.0).astype(np.float32)\nc = a + b\n# dc / da = d(a+b) / da = 1\ndc_da = np.array(1).astype(np.float32)\n# db / db = d(a+b) / db = 1\ndc_db = np.array(1).astype(np.float32)\n\ngraph = onnx.helper.make_graph(\n nodes=[add_node, gradient_node],\n name='GradientOfAdd',\n inputs=[\n onnx.helper.make_tensor_value_info('a', onnx.TensorProto.FLOAT,\n []),\n onnx.helper.make_tensor_value_info('b', onnx.TensorProto.FLOAT,\n [])],\n outputs=[\n onnx.helper.make_tensor_value_info('c', onnx.TensorProto.FLOAT,\n []),\n onnx.helper.make_tensor_value_info('dc_da',\n onnx.TensorProto.FLOAT, []),\n onnx.helper.make_tensor_value_info('dc_db',\n onnx.TensorProto.FLOAT, [])])\nopsets = [\n onnx.helper.make_operatorsetid(ONNX_DOMAIN, 12),\n onnx.helper.make_operatorsetid(AI_ONNX_PREVIEW_TRAINING_DOMAIN, 1)]\nmodel = onnx.helper.make_model(\n graph,\n producer_name='backend-test',\n opset_imports=opsets)\nexpect(model, inputs=[a, b], outputs=[c, dc_da, dc_db],\n name='test_gradient_of_add')" + }, + { + "summary": "gradient_scalar_add_and_mul", + "code": "add_node = onnx.helper.make_node('Add',\n ['a', 'b'], ['c'], name='my_add')\nmul_node = onnx.helper.make_node('Mul',\n ['c', 'a'], ['d'], name='my_mul')\ngradient_node = onnx.helper.make_node(\n 'Gradient', ['a', 'b'],\n ['dd_da', 'dd_db'], name='my_gradient',\n domain=AI_ONNX_PREVIEW_TRAINING_DOMAIN,\n xs=['a', 'b'], y='d')\n\na = np.array(1.0).astype(np.float32)\nb = np.array(2.0).astype(np.float32)\nc = a + b\n# d = a * c = a * (a + b)\nd = a * c\n# dd / da = d(a*a+a*b) / da = 2 * a + b\ndd_da = (2 * a + b).astype(np.float32)\n# dd / db = d(a*a+a*b) / db = a\ndd_db = a\n\ngraph = onnx.helper.make_graph(\n nodes=[add_node, mul_node, gradient_node],\n name='GradientOfTwoOperators',\n inputs=[\n onnx.helper.make_tensor_value_info('a', onnx.TensorProto.FLOAT,\n []),\n onnx.helper.make_tensor_value_info('b', onnx.TensorProto.FLOAT,\n [])],\n outputs=[\n onnx.helper.make_tensor_value_info('d', onnx.TensorProto.FLOAT,\n []),\n onnx.helper.make_tensor_value_info('dd_da',\n onnx.TensorProto.FLOAT, []),\n onnx.helper.make_tensor_value_info('dd_db',\n onnx.TensorProto.FLOAT, [])])\n\nopsets = [\n onnx.helper.make_operatorsetid(ONNX_DOMAIN, 12),\n onnx.helper.make_operatorsetid(AI_ONNX_PREVIEW_TRAINING_DOMAIN, 1)]\nmodel = onnx.helper.make_model(graph,\n producer_name='backend-test',\n opset_imports=opsets)\nexpect(model, inputs=[a, b], outputs=[d, dd_da, dd_db],\n name='test_gradient_of_add_and_mul')" + } + ] + }, + { + "name": "Greater", + "module": "ai.onnx", + "version": 1, + "support_level": "common", + "description": "Returns the tensor resulted from performing the `greater` logical operation\nelementwise on the input tensors `A` and `B`.\n\nIf broadcasting is enabled, the right-hand-side argument will be broadcasted\nto match the shape of left-hand-side argument. See the doc of `Add` for a\ndetailed description of the broadcasting rules.\n", + "attributes": [ + { + "name": "axis", + "type": "int64", + "required": false, + "description": "If set, defines the broadcast dimensions." + }, + { + "name": "broadcast", + "type": "int64", + "required": false, + "description": "Enable broadcasting" + } + ], + "inputs": [ + { + "name": "A", + "type": "T", + "description": "Left input tensor for the logical operator." + }, + { + "name": "B", + "type": "T", + "description": "Right input tensor for the logical operator." + } + ], + "min_input": 2, + "max_input": 2, + "outputs": [ + { + "name": "C", + "type": "T1", + "description": "Result tensor." + } + ], + "min_output": 1, + "max_output": 1, + "type_constraints": [ + { + "description": "Constrains input to float tensors.", + "type_param_str": "T", + "allowed_type_strs": [ + "tensor(float16)", + "tensor(float)", + "tensor(double)" + ] + }, + { + "description": "Constrains output to boolean tensor.", + "type_param_str": "T1", + "allowed_type_strs": [ + "tensor(bool)" + ] + } + ], + "examples": [ + { + "summary": "greater", + "code": "node = onnx.helper.make_node(\n 'Greater',\n inputs=['x', 'y'],\n outputs=['greater'],\n)\n\nx = np.random.randn(3, 4, 5).astype(np.float32)\ny = np.random.randn(3, 4, 5).astype(np.float32)\nz = np.greater(x, y)\nexpect(node, inputs=[x, y], outputs=[z],\n name='test_greater')" + }, + { + "summary": "greater", + "code": "node = onnx.helper.make_node(\n 'GreaterOrEqual',\n inputs=['x', 'y'],\n outputs=['greater_equal'],\n)\n\nx = np.random.randn(3, 4, 5).astype(np.float32)\ny = np.random.randn(3, 4, 5).astype(np.float32)\nz = np.greater_equal(x, y)\nexpect(node, inputs=[x, y], outputs=[z],\n name='test_greater_equal')" + }, + { + "summary": "greater_broadcast", + "code": "node = onnx.helper.make_node(\n 'Greater',\n inputs=['x', 'y'],\n outputs=['greater'],\n)\n\nx = np.random.randn(3, 4, 5).astype(np.float32)\ny = np.random.randn(5).astype(np.float32)\nz = np.greater(x, y)\nexpect(node, inputs=[x, y], outputs=[z],\n name='test_greater_bcast')" + }, + { + "summary": "greater_broadcast", + "code": "node = onnx.helper.make_node(\n 'GreaterOrEqual',\n inputs=['x', 'y'],\n outputs=['greater_equal'],\n)\n\nx = np.random.randn(3, 4, 5).astype(np.float32)\ny = np.random.randn(5).astype(np.float32)\nz = np.greater_equal(x, y)\nexpect(node, inputs=[x, y], outputs=[z],\n name='test_greater_equal_bcast')" + } + ], + "category": "Logic" + }, + { + "name": "Greater", + "module": "ai.onnx", + "version": 7, + "support_level": "common", + "description": "Returns the tensor resulted from performing the `greater` logical operation\nelementwise on the input tensors `A` and `B` (with Numpy-style broadcasting support).\n\nThis operator supports **multidirectional (i.e., Numpy-style) broadcasting**; for more details please check [the doc](https://github.com/onnx/onnx/blob/master/docs/Broadcasting.md).\n", + "inputs": [ + { + "name": "A", + "type": "T", + "description": "First input operand for the logical operator." + }, + { + "name": "B", + "type": "T", + "description": "Second input operand for the logical operator." + } + ], + "min_input": 2, + "max_input": 2, + "outputs": [ + { + "name": "C", + "type": "T1", + "description": "Result tensor." + } + ], + "min_output": 1, + "max_output": 1, + "type_constraints": [ + { + "description": "Constrains input to float tensors.", + "type_param_str": "T", + "allowed_type_strs": [ + "tensor(float16)", + "tensor(float)", + "tensor(double)" + ] + }, + { + "description": "Constrains output to boolean tensor.", + "type_param_str": "T1", + "allowed_type_strs": [ + "tensor(bool)" + ] + } + ], + "examples": [ + { + "summary": "greater", + "code": "node = onnx.helper.make_node(\n 'Greater',\n inputs=['x', 'y'],\n outputs=['greater'],\n)\n\nx = np.random.randn(3, 4, 5).astype(np.float32)\ny = np.random.randn(3, 4, 5).astype(np.float32)\nz = np.greater(x, y)\nexpect(node, inputs=[x, y], outputs=[z],\n name='test_greater')" + }, + { + "summary": "greater", + "code": "node = onnx.helper.make_node(\n 'GreaterOrEqual',\n inputs=['x', 'y'],\n outputs=['greater_equal'],\n)\n\nx = np.random.randn(3, 4, 5).astype(np.float32)\ny = np.random.randn(3, 4, 5).astype(np.float32)\nz = np.greater_equal(x, y)\nexpect(node, inputs=[x, y], outputs=[z],\n name='test_greater_equal')" + }, + { + "summary": "greater_broadcast", + "code": "node = onnx.helper.make_node(\n 'Greater',\n inputs=['x', 'y'],\n outputs=['greater'],\n)\n\nx = np.random.randn(3, 4, 5).astype(np.float32)\ny = np.random.randn(5).astype(np.float32)\nz = np.greater(x, y)\nexpect(node, inputs=[x, y], outputs=[z],\n name='test_greater_bcast')" + }, + { + "summary": "greater_broadcast", + "code": "node = onnx.helper.make_node(\n 'GreaterOrEqual',\n inputs=['x', 'y'],\n outputs=['greater_equal'],\n)\n\nx = np.random.randn(3, 4, 5).astype(np.float32)\ny = np.random.randn(5).astype(np.float32)\nz = np.greater_equal(x, y)\nexpect(node, inputs=[x, y], outputs=[z],\n name='test_greater_equal_bcast')" + } + ], + "category": "Logic" + }, + { + "name": "Greater", + "module": "ai.onnx", + "version": 9, + "support_level": "common", + "description": "Returns the tensor resulted from performing the `greater` logical operation\nelementwise on the input tensors `A` and `B` (with Numpy-style broadcasting support).\n\nThis operator supports **multidirectional (i.e., Numpy-style) broadcasting**; for more details please check [the doc](https://github.com/onnx/onnx/blob/master/docs/Broadcasting.md).\n", + "inputs": [ + { + "name": "A", + "type": "T", + "description": "First input operand for the logical operator." + }, + { + "name": "B", + "type": "T", + "description": "Second input operand for the logical operator." + } + ], + "min_input": 2, + "max_input": 2, + "outputs": [ + { + "name": "C", + "type": "T1", + "description": "Result tensor." + } + ], + "min_output": 1, + "max_output": 1, + "type_constraints": [ + { + "description": "Constrains input types to all numeric tensors.", + "type_param_str": "T", + "allowed_type_strs": [ + "tensor(uint8)", + "tensor(uint16)", + "tensor(uint32)", + "tensor(uint64)", + "tensor(int8)", + "tensor(int16)", + "tensor(int32)", + "tensor(int64)", + "tensor(float16)", + "tensor(float)", + "tensor(double)" + ] + }, + { + "description": "Constrains output to boolean tensor.", + "type_param_str": "T1", + "allowed_type_strs": [ + "tensor(bool)" + ] + } + ], + "examples": [ + { + "summary": "greater", + "code": "node = onnx.helper.make_node(\n 'Greater',\n inputs=['x', 'y'],\n outputs=['greater'],\n)\n\nx = np.random.randn(3, 4, 5).astype(np.float32)\ny = np.random.randn(3, 4, 5).astype(np.float32)\nz = np.greater(x, y)\nexpect(node, inputs=[x, y], outputs=[z],\n name='test_greater')" + }, + { + "summary": "greater", + "code": "node = onnx.helper.make_node(\n 'GreaterOrEqual',\n inputs=['x', 'y'],\n outputs=['greater_equal'],\n)\n\nx = np.random.randn(3, 4, 5).astype(np.float32)\ny = np.random.randn(3, 4, 5).astype(np.float32)\nz = np.greater_equal(x, y)\nexpect(node, inputs=[x, y], outputs=[z],\n name='test_greater_equal')" + }, + { + "summary": "greater_broadcast", + "code": "node = onnx.helper.make_node(\n 'Greater',\n inputs=['x', 'y'],\n outputs=['greater'],\n)\n\nx = np.random.randn(3, 4, 5).astype(np.float32)\ny = np.random.randn(5).astype(np.float32)\nz = np.greater(x, y)\nexpect(node, inputs=[x, y], outputs=[z],\n name='test_greater_bcast')" + }, + { + "summary": "greater_broadcast", + "code": "node = onnx.helper.make_node(\n 'GreaterOrEqual',\n inputs=['x', 'y'],\n outputs=['greater_equal'],\n)\n\nx = np.random.randn(3, 4, 5).astype(np.float32)\ny = np.random.randn(5).astype(np.float32)\nz = np.greater_equal(x, y)\nexpect(node, inputs=[x, y], outputs=[z],\n name='test_greater_equal_bcast')" + } + ], + "category": "Logic" + }, + { + "name": "Greater", + "module": "ai.onnx", + "version": 13, + "support_level": "common", + "description": "Returns the tensor resulted from performing the `greater` logical operation\nelementwise on the input tensors `A` and `B` (with Numpy-style broadcasting support).\n\nThis operator supports **multidirectional (i.e., Numpy-style) broadcasting**; for more details please check [the doc](https://github.com/onnx/onnx/blob/master/docs/Broadcasting.md).\n", + "inputs": [ + { + "name": "A", + "type": "T", + "description": "First input operand for the logical operator." + }, + { + "name": "B", + "type": "T", + "description": "Second input operand for the logical operator." + } + ], + "min_input": 2, + "max_input": 2, + "outputs": [ + { + "name": "C", + "type": "T1", + "description": "Result tensor." + } + ], + "min_output": 1, + "max_output": 1, + "type_constraints": [ + { + "description": "Constrains input types to all numeric tensors.", + "type_param_str": "T", + "allowed_type_strs": [ + "tensor(uint8)", + "tensor(uint16)", + "tensor(uint32)", + "tensor(uint64)", + "tensor(int8)", + "tensor(int16)", + "tensor(int32)", + "tensor(int64)", + "tensor(float16)", + "tensor(float)", + "tensor(double)", + "tensor(bfloat16)" + ] + }, + { + "description": "Constrains output to boolean tensor.", + "type_param_str": "T1", + "allowed_type_strs": [ + "tensor(bool)" + ] + } + ], + "examples": [ + { + "summary": "greater", + "code": "node = onnx.helper.make_node(\n 'Greater',\n inputs=['x', 'y'],\n outputs=['greater'],\n)\n\nx = np.random.randn(3, 4, 5).astype(np.float32)\ny = np.random.randn(3, 4, 5).astype(np.float32)\nz = np.greater(x, y)\nexpect(node, inputs=[x, y], outputs=[z],\n name='test_greater')" + }, + { + "summary": "greater", + "code": "node = onnx.helper.make_node(\n 'GreaterOrEqual',\n inputs=['x', 'y'],\n outputs=['greater_equal'],\n)\n\nx = np.random.randn(3, 4, 5).astype(np.float32)\ny = np.random.randn(3, 4, 5).astype(np.float32)\nz = np.greater_equal(x, y)\nexpect(node, inputs=[x, y], outputs=[z],\n name='test_greater_equal')" + }, + { + "summary": "greater_broadcast", + "code": "node = onnx.helper.make_node(\n 'Greater',\n inputs=['x', 'y'],\n outputs=['greater'],\n)\n\nx = np.random.randn(3, 4, 5).astype(np.float32)\ny = np.random.randn(5).astype(np.float32)\nz = np.greater(x, y)\nexpect(node, inputs=[x, y], outputs=[z],\n name='test_greater_bcast')" + }, + { + "summary": "greater_broadcast", + "code": "node = onnx.helper.make_node(\n 'GreaterOrEqual',\n inputs=['x', 'y'],\n outputs=['greater_equal'],\n)\n\nx = np.random.randn(3, 4, 5).astype(np.float32)\ny = np.random.randn(5).astype(np.float32)\nz = np.greater_equal(x, y)\nexpect(node, inputs=[x, y], outputs=[z],\n name='test_greater_equal_bcast')" + } + ], + "category": "Logic" + }, + { + "name": "GreaterOrEqual", + "module": "ai.onnx", + "version": 12, + "support_level": "common", + "description": "Returns the tensor resulted from performing the `greater_equal` logical operation\nelementwise on the input tensors `A` and `B` (with Numpy-style broadcasting support).\n\nThis operator supports **multidirectional (i.e., Numpy-style) broadcasting**; for more details please check [the doc](https://github.com/onnx/onnx/blob/master/docs/Broadcasting.md).\n", + "inputs": [ + { + "name": "A", + "type": "T", + "description": "First input operand for the logical operator." + }, + { + "name": "B", + "type": "T", + "description": "Second input operand for the logical operator." + } + ], + "min_input": 2, + "max_input": 2, + "outputs": [ + { + "name": "C", + "type": "T1", + "description": "Result tensor." + } + ], + "min_output": 1, + "max_output": 1, + "type_constraints": [ + { + "description": "Constrains input types to all numeric tensors.", + "type_param_str": "T", + "allowed_type_strs": [ + "tensor(uint8)", + "tensor(uint16)", + "tensor(uint32)", + "tensor(uint64)", + "tensor(int8)", + "tensor(int16)", + "tensor(int32)", + "tensor(int64)", + "tensor(float16)", + "tensor(float)", + "tensor(double)" + ] + }, + { + "description": "Constrains output to boolean tensor.", + "type_param_str": "T1", + "allowed_type_strs": [ + "tensor(bool)" + ] + } + ] + }, + { + "name": "HardSigmoid", + "module": "ai.onnx", + "version": 1, + "support_level": "common", + "description": "HardSigmoid takes one input data (Tensor) and produces one output data\n(Tensor) where the HardSigmoid function, y = max(0, min(1, alpha * x + beta)),\nis applied to the tensor elementwise.\n", + "attributes": [ + { + "name": "alpha", + "type": "float32", + "required": false, + "default": 0.20000000298023224, + "description": "Value of alpha default to 0.2" + }, + { + "name": "beta", + "type": "float32", + "required": false, + "default": 0.5, + "description": "Value of beta default to 0.5" + }, + { + "name": "consumed_inputs", + "type": "int64[]", + "required": false, + "description": "legacy optimization attribute." + } + ], + "inputs": [ + { + "name": "X", + "type": "T", + "description": "Input tensor" + } + ], + "min_input": 1, + "max_input": 1, + "outputs": [ + { + "name": "Y", + "type": "T", + "description": "Output tensor" + } + ], + "min_output": 1, + "max_output": 1, + "type_constraints": [ + { + "description": "Constrain input and output types to float tensors.", + "type_param_str": "T", + "allowed_type_strs": [ + "tensor(float16)", + "tensor(float)", + "tensor(double)" + ] + } + ], + "examples": [ + { + "summary": "hardsigmoid", + "code": "node = onnx.helper.make_node(\n 'HardSigmoid',\n inputs=['x'],\n outputs=['y'],\n alpha=0.5,\n beta=0.6\n)\n\nx = np.array([-1, 0, 1]).astype(np.float32)\ny = np.clip(x * 0.5 + 0.6, 0, 1) # expected output [0.1, 0.6, 1.]\nexpect(node, inputs=[x], outputs=[y],\n name='test_hardsigmoid_example')\n\nx = np.random.randn(3, 4, 5).astype(np.float32)\ny = np.clip(x * 0.5 + 0.6, 0, 1)\nexpect(node, inputs=[x], outputs=[y],\n name='test_hardsigmoid')" + }, + { + "summary": "hardsigmoid_default", + "code": "default_alpha = 0.2\ndefault_beta = 0.5\nnode = onnx.helper.make_node(\n 'HardSigmoid',\n inputs=['x'],\n outputs=['y'],\n)\nx = np.random.randn(3, 4, 5).astype(np.float32)\ny = np.clip(x * default_alpha + default_beta, 0, 1)\nexpect(node, inputs=[x], outputs=[y],\n name='test_hardsigmoid_default')" + } + ], + "category": "Activation" + }, + { + "name": "HardSigmoid", + "module": "ai.onnx", + "version": 6, + "support_level": "common", + "description": "HardSigmoid takes one input data (Tensor) and produces one output data\n(Tensor) where the HardSigmoid function, y = max(0, min(1, alpha * x + beta)),\nis applied to the tensor elementwise.\n", + "attributes": [ + { + "name": "alpha", + "type": "float32", + "required": false, + "default": 0.20000000298023224, + "description": "Value of alpha." + }, + { + "name": "beta", + "type": "float32", + "required": false, + "default": 0.5, + "description": "Value of beta." + } + ], + "inputs": [ + { + "name": "X", + "type": "T", + "description": "Input tensor" + } + ], + "min_input": 1, + "max_input": 1, + "outputs": [ + { + "name": "Y", + "type": "T", + "description": "Output tensor" + } + ], + "min_output": 1, + "max_output": 1, + "type_constraints": [ + { + "description": "Constrain input and output types to float tensors.", + "type_param_str": "T", + "allowed_type_strs": [ + "tensor(float16)", + "tensor(float)", + "tensor(double)" + ] + } + ], + "examples": [ + { + "summary": "hardsigmoid", + "code": "node = onnx.helper.make_node(\n 'HardSigmoid',\n inputs=['x'],\n outputs=['y'],\n alpha=0.5,\n beta=0.6\n)\n\nx = np.array([-1, 0, 1]).astype(np.float32)\ny = np.clip(x * 0.5 + 0.6, 0, 1) # expected output [0.1, 0.6, 1.]\nexpect(node, inputs=[x], outputs=[y],\n name='test_hardsigmoid_example')\n\nx = np.random.randn(3, 4, 5).astype(np.float32)\ny = np.clip(x * 0.5 + 0.6, 0, 1)\nexpect(node, inputs=[x], outputs=[y],\n name='test_hardsigmoid')" + }, + { + "summary": "hardsigmoid_default", + "code": "default_alpha = 0.2\ndefault_beta = 0.5\nnode = onnx.helper.make_node(\n 'HardSigmoid',\n inputs=['x'],\n outputs=['y'],\n)\nx = np.random.randn(3, 4, 5).astype(np.float32)\ny = np.clip(x * default_alpha + default_beta, 0, 1)\nexpect(node, inputs=[x], outputs=[y],\n name='test_hardsigmoid_default')" + } + ], + "category": "Activation" + }, + { + "name": "HardSwish", + "module": "ai.onnx", + "version": 14, + "support_level": "common", + "description": "HardSwish takes one input data (Tensor) and produces one output data (Tensor) where\nthe HardSwish function, y = x * max(0, min(1, alpha * x + beta)) = x * HardSigmoid(x),\nwhere alpha = 1/6 and beta = 0.5, is applied to the tensor elementwise.\n", + "inputs": [ + { + "name": "X", + "type": "T", + "description": "Input tensor" + } + ], + "min_input": 1, + "max_input": 1, + "outputs": [ + { + "name": "Y", + "type": "T", + "description": "Output tensor" + } + ], + "min_output": 1, + "max_output": 1, + "type_constraints": [ + { + "description": "Constrain input and output types to float tensors.", + "type_param_str": "T", + "allowed_type_strs": [ + "tensor(float16)", + "tensor(float)", + "tensor(double)" + ] + } + ], + "examples": [ + { + "summary": "hardswish", + "code": "node = onnx.helper.make_node(\n 'HardSwish',\n inputs=['x'],\n outputs=['y'],\n)\nx = np.random.randn(3, 4, 5).astype(np.float32)\ny = hardswish(x)\n\nexpect(node, inputs=[x], outputs=[y],\n name='test_hardswish')" + } + ] + }, + { + "name": "Hardmax", + "module": "ai.onnx", + "version": 1, + "support_level": "common", + "description": "The operator computes the hardmax (1 for the first maximum value, and 0 for all others) values for each layer in the batch\n of the given input. The input is a 2-D tensor (Tensor) of size\n(batch_size x input_feature_dimensions). The output tensor has the same shape\nand contains the hardmax values of the corresponding input.\n\nInput does not need to explicitly be a 2D vector; rather, it will be\ncoerced into one. For an arbitrary n-dimensional tensor\ninput \\in [a_0, a_1, ..., a_{k-1}, a_k, ..., a_{n-1}] and k is\nthe axis provided, then input will be coerced into a 2-dimensional tensor with\ndimensions [a_0 * ... * a_{k-1}, a_k * ... * a_{n-1}]. For the default\ncase where axis=1, this means the input tensor will be coerced into a 2D tensor\nof dimensions [a_0, a_1 * ... * a_{n-1}], where a_0 is often the batch size.\nIn this situation, we must have a_0 = N and a_1 * ... * a_{n-1} = D.\nEach of these dimensions must be matched correctly, or else the operator\nwill throw errors.\n", + "attributes": [ + { + "name": "axis", + "type": "int64", + "required": false, + "default": 1, + "description": "Describes the axis of the inputs when coerced to 2D; defaults to one because the 0th axis most likely describes the batch_size" + } + ], + "inputs": [ + { + "name": "input", + "type": "T", + "description": "The input tensor that's coerced into a 2D matrix of size (NxD) as described above." + } + ], + "min_input": 1, + "max_input": 1, + "outputs": [ + { + "name": "output", + "type": "T", + "description": "The output values with the same shape as input tensor (the original size without coercion)." + } + ], + "min_output": 1, + "max_output": 1, + "type_constraints": [ + { + "description": "Constrain input and output types to float tensors.", + "type_param_str": "T", + "allowed_type_strs": [ + "tensor(float16)", + "tensor(float)", + "tensor(double)" + ] + } + ], + "examples": [ + { + "summary": "hardmax", + "code": "node = onnx.helper.make_node(\n 'Hardmax',\n inputs=['x'],\n outputs=['y'],\n)\n\nx = np.array([[3, 0, 1, 2], [2, 5, 1, 0], [0, 1, 3, 2],\n [0, 1, 2, 3]]).astype(np.float32)\n# expect result:\n# [[1. 0. 0. 0.]\n# [0. 1. 0. 0.]\n# [0. 0. 1. 0.]\n# [0. 0. 0. 1.]]\ny = hardmax(x)\nexpect(node, inputs=[x], outputs=[y],\n name='test_hardmax_example')\n\n# For multiple occurrences of the maximal values, the first occurrence is selected for one-hot output\nx = np.array([[3, 3, 3, 1]]).astype(np.float32)\n# expect result:\n# [[1, 0, 0, 0]]\ny = hardmax(x)\nexpect(node, inputs=[x], outputs=[y],\n name='test_hardmax_one_hot')" + }, + { + "summary": "hardmax_axis", + "code": "x = np.random.randn(3, 4, 5).astype(np.float32)\nnode = onnx.helper.make_node(\n 'Hardmax',\n inputs=['x'],\n outputs=['y'],\n axis=0,\n)\ny = hardmax(x, axis=0)\nexpect(node, inputs=[x], outputs=[y],\n name='test_hardmax_axis_0')\n\nnode = onnx.helper.make_node(\n 'Hardmax',\n inputs=['x'],\n outputs=['y'],\n axis=1,\n)\ny = hardmax(x, axis=1)\nexpect(node, inputs=[x], outputs=[y],\n name='test_hardmax_axis_1')\n\nnode = onnx.helper.make_node(\n 'Hardmax',\n inputs=['x'],\n outputs=['y'],\n axis=2,\n)\ny = hardmax(x, axis=2)\nexpect(node, inputs=[x], outputs=[y],\n name='test_hardmax_axis_2')\n\nnode = onnx.helper.make_node(\n 'Hardmax',\n inputs=['x'],\n outputs=['y'],\n axis=-1,\n)\ny = hardmax(x, axis=-1)\nexpect(node, inputs=[x], outputs=[y],\n name='test_hardmax_negative_axis')\n\n# default axis is -1\nnode = onnx.helper.make_node(\n 'Hardmax',\n inputs=['x'],\n outputs=['y'],\n)\nexpect(node, inputs=[x], outputs=[y],\n name='test_hardmax_default_axis')" + } + ] + }, + { + "name": "Hardmax", + "module": "ai.onnx", + "version": 11, + "support_level": "common", + "description": "The operator computes the hardmax (1 for the first maximum value, and 0 for all others) values for each layer in the batch\n of the given input.\n\nThe input does not need to explicitly be a 2D vector; rather, it will be\ncoerced into one. For an arbitrary n-dimensional tensor\ninput \\in [a_0, a_1, ..., a_{k-1}, a_k, ..., a_{n-1}] and k is\nthe axis provided, then input will be coerced into a 2-dimensional tensor with\ndimensions [a_0 * ... * a_{k-1}, a_k * ... * a_{n-1}]. For the default\ncase where axis=1, this means the input tensor will be coerced into a 2D tensor\nof dimensions [a_0, a_1 * ... * a_{n-1}], where a_0 is often the batch size.\nIn this situation, we must have a_0 = N and a_1 * ... * a_{n-1} = D.\nEach of these dimensions must be matched correctly, or else the operator\nwill throw errors. The output tensor has the same shape\nand contains the hardmax values of the corresponding input.\n", + "attributes": [ + { + "name": "axis", + "type": "int64", + "required": false, + "default": 1, + "description": "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": [ + { + "name": "input", + "type": "T", + "description": "The input tensor that's coerced into a 2D matrix of size (NxD) as described above." + } + ], + "min_input": 1, + "max_input": 1, + "outputs": [ + { + "name": "output", + "type": "T", + "description": "The output values with the same shape as input tensor (the original size without coercion)." + } + ], + "min_output": 1, + "max_output": 1, + "type_constraints": [ + { + "description": "Constrain input and output types to float tensors.", + "type_param_str": "T", + "allowed_type_strs": [ + "tensor(float16)", + "tensor(float)", + "tensor(double)" + ] + } + ], + "examples": [ + { + "summary": "hardmax", + "code": "node = onnx.helper.make_node(\n 'Hardmax',\n inputs=['x'],\n outputs=['y'],\n)\n\nx = np.array([[3, 0, 1, 2], [2, 5, 1, 0], [0, 1, 3, 2],\n [0, 1, 2, 3]]).astype(np.float32)\n# expect result:\n# [[1. 0. 0. 0.]\n# [0. 1. 0. 0.]\n# [0. 0. 1. 0.]\n# [0. 0. 0. 1.]]\ny = hardmax(x)\nexpect(node, inputs=[x], outputs=[y],\n name='test_hardmax_example')\n\n# For multiple occurrences of the maximal values, the first occurrence is selected for one-hot output\nx = np.array([[3, 3, 3, 1]]).astype(np.float32)\n# expect result:\n# [[1, 0, 0, 0]]\ny = hardmax(x)\nexpect(node, inputs=[x], outputs=[y],\n name='test_hardmax_one_hot')" + }, + { + "summary": "hardmax_axis", + "code": "x = np.random.randn(3, 4, 5).astype(np.float32)\nnode = onnx.helper.make_node(\n 'Hardmax',\n inputs=['x'],\n outputs=['y'],\n axis=0,\n)\ny = hardmax(x, axis=0)\nexpect(node, inputs=[x], outputs=[y],\n name='test_hardmax_axis_0')\n\nnode = onnx.helper.make_node(\n 'Hardmax',\n inputs=['x'],\n outputs=['y'],\n axis=1,\n)\ny = hardmax(x, axis=1)\nexpect(node, inputs=[x], outputs=[y],\n name='test_hardmax_axis_1')\n\nnode = onnx.helper.make_node(\n 'Hardmax',\n inputs=['x'],\n outputs=['y'],\n axis=2,\n)\ny = hardmax(x, axis=2)\nexpect(node, inputs=[x], outputs=[y],\n name='test_hardmax_axis_2')\n\nnode = onnx.helper.make_node(\n 'Hardmax',\n inputs=['x'],\n outputs=['y'],\n axis=-1,\n)\ny = hardmax(x, axis=-1)\nexpect(node, inputs=[x], outputs=[y],\n name='test_hardmax_negative_axis')\n\n# default axis is -1\nnode = onnx.helper.make_node(\n 'Hardmax',\n inputs=['x'],\n outputs=['y'],\n)\nexpect(node, inputs=[x], outputs=[y],\n name='test_hardmax_default_axis')" + } + ] + }, + { + "name": "Hardmax", + "module": "ai.onnx", + "version": 13, + "support_level": "common", + "description": "The operator computes the hardmax values for the given input:\n\n Hardmax(element in input, axis) = 1 if the element is the first maximum value along the specified axis, 0 otherwise\n\nThe \"axis\" attribute indicates the dimension along which Hardmax\nwill be performed. The output tensor has the same shape\nand contains the Hardmax values of the corresponding input.\n", + "attributes": [ + { + "name": "axis", + "type": "int64", + "required": false, + "default": -1, + "description": "\nDescribes the dimension Hardmax will be performed on.\nNegative value means counting dimensions\nfrom the back. Accepted range is [-r, r-1] where r = rank(input).\n" + } + ], + "inputs": [ + { + "name": "input", + "type": "T", + "description": "The input tensor of rank >= axis." + } + ], + "min_input": 1, + "max_input": 1, + "outputs": [ + { + "name": "output", + "type": "T", + "description": "The output values with the same shape as the input tensor." + } + ], + "min_output": 1, + "max_output": 1, + "type_constraints": [ + { + "description": "Constrain input and output types to float tensors.", + "type_param_str": "T", + "allowed_type_strs": [ + "tensor(float16)", + "tensor(float)", + "tensor(double)", + "tensor(bfloat16)" + ] + } + ], + "examples": [ + { + "summary": "hardmax", + "code": "node = onnx.helper.make_node(\n 'Hardmax',\n inputs=['x'],\n outputs=['y'],\n)\n\nx = np.array([[3, 0, 1, 2], [2, 5, 1, 0], [0, 1, 3, 2],\n [0, 1, 2, 3]]).astype(np.float32)\n# expect result:\n# [[1. 0. 0. 0.]\n# [0. 1. 0. 0.]\n# [0. 0. 1. 0.]\n# [0. 0. 0. 1.]]\ny = hardmax(x)\nexpect(node, inputs=[x], outputs=[y],\n name='test_hardmax_example')\n\n# For multiple occurrences of the maximal values, the first occurrence is selected for one-hot output\nx = np.array([[3, 3, 3, 1]]).astype(np.float32)\n# expect result:\n# [[1, 0, 0, 0]]\ny = hardmax(x)\nexpect(node, inputs=[x], outputs=[y],\n name='test_hardmax_one_hot')" + }, + { + "summary": "hardmax_axis", + "code": "x = np.random.randn(3, 4, 5).astype(np.float32)\nnode = onnx.helper.make_node(\n 'Hardmax',\n inputs=['x'],\n outputs=['y'],\n axis=0,\n)\ny = hardmax(x, axis=0)\nexpect(node, inputs=[x], outputs=[y],\n name='test_hardmax_axis_0')\n\nnode = onnx.helper.make_node(\n 'Hardmax',\n inputs=['x'],\n outputs=['y'],\n axis=1,\n)\ny = hardmax(x, axis=1)\nexpect(node, inputs=[x], outputs=[y],\n name='test_hardmax_axis_1')\n\nnode = onnx.helper.make_node(\n 'Hardmax',\n inputs=['x'],\n outputs=['y'],\n axis=2,\n)\ny = hardmax(x, axis=2)\nexpect(node, inputs=[x], outputs=[y],\n name='test_hardmax_axis_2')\n\nnode = onnx.helper.make_node(\n 'Hardmax',\n inputs=['x'],\n outputs=['y'],\n axis=-1,\n)\ny = hardmax(x, axis=-1)\nexpect(node, inputs=[x], outputs=[y],\n name='test_hardmax_negative_axis')\n\n# default axis is -1\nnode = onnx.helper.make_node(\n 'Hardmax',\n inputs=['x'],\n outputs=['y'],\n)\nexpect(node, inputs=[x], outputs=[y],\n name='test_hardmax_default_axis')" + } + ] + }, + { + "name": "Identity", + "module": "ai.onnx", + "version": 1, + "support_level": "common", + "description": "Identity operator", + "inputs": [ + { + "name": "input", + "type": "T", + "description": "Input tensor" + } + ], + "min_input": 1, + "max_input": 1, + "outputs": [ + { + "name": "output", + "type": "T", + "description": "Tensor to copy input into." + } + ], + "min_output": 1, + "max_output": 1, + "type_constraints": [ + { + "description": "Constrain input and output types to all tensor types.", + "type_param_str": "T", + "allowed_type_strs": [ + "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)" + ] + } + ], + "examples": [ + { + "summary": "identity", + "code": "node = onnx.helper.make_node(\n 'Identity',\n inputs=['x'],\n outputs=['y'],\n)\n\ndata = np.array([[[\n [1, 2],\n [3, 4],\n]]], dtype=np.float32)\n\nexpect(node, inputs=[data], outputs=[data],\n name='test_identity')" + }, + { + "summary": "identity_opt", + "code": "ten_in_tp = onnx.helper.make_tensor_type_proto(onnx.TensorProto.FLOAT, shape=[5])\nseq_in_tp = onnx.helper.make_sequence_type_proto(ten_in_tp)\nopt_in_tp = onnx.helper.make_optional_type_proto(seq_in_tp)\n\nidentity_node = onnx.helper.make_node(\n 'Identity',\n inputs=['opt_in'],\n outputs=['opt_out']\n)\n\nx = [np.array([1, 2, 3, 4, 5]).astype(np.float32)]\n\nexpect(identity_node, inputs=[x], outputs=[x], name='test_identity_opt',\n opset_imports=[onnx.helper.make_opsetid(\"\", 16)],\n input_type_protos=[opt_in_tp],\n output_type_protos=[opt_in_tp])" + }, + { + "summary": "sequence", + "code": "node = onnx.helper.make_node(\n 'Identity',\n inputs=['x'],\n outputs=['y'],\n)\n\ndata = [\n np.array([[[\n [1, 2],\n [3, 4],\n ]]], dtype=np.float32),\n np.array([[[\n [2, 3],\n [1, 5],\n ]]], dtype=np.float32)]\n\nexpect(node, inputs=[data], outputs=[data], name='test_identity_sequence')" + } + ] + }, + { + "name": "Identity", + "module": "ai.onnx", + "version": 13, + "support_level": "common", + "description": "Identity operator", + "inputs": [ + { + "name": "input", + "type": "T", + "description": "Input tensor" + } + ], + "min_input": 1, + "max_input": 1, + "outputs": [ + { + "name": "output", + "type": "T", + "description": "Tensor to copy input into." + } + ], + "min_output": 1, + "max_output": 1, + "type_constraints": [ + { + "description": "Constrain input and output types to all tensor types.", + "type_param_str": "T", + "allowed_type_strs": [ + "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)" + ] + } + ], + "examples": [ + { + "summary": "identity", + "code": "node = onnx.helper.make_node(\n 'Identity',\n inputs=['x'],\n outputs=['y'],\n)\n\ndata = np.array([[[\n [1, 2],\n [3, 4],\n]]], dtype=np.float32)\n\nexpect(node, inputs=[data], outputs=[data],\n name='test_identity')" + }, + { + "summary": "identity_opt", + "code": "ten_in_tp = onnx.helper.make_tensor_type_proto(onnx.TensorProto.FLOAT, shape=[5])\nseq_in_tp = onnx.helper.make_sequence_type_proto(ten_in_tp)\nopt_in_tp = onnx.helper.make_optional_type_proto(seq_in_tp)\n\nidentity_node = onnx.helper.make_node(\n 'Identity',\n inputs=['opt_in'],\n outputs=['opt_out']\n)\n\nx = [np.array([1, 2, 3, 4, 5]).astype(np.float32)]\n\nexpect(identity_node, inputs=[x], outputs=[x], name='test_identity_opt',\n opset_imports=[onnx.helper.make_opsetid(\"\", 16)],\n input_type_protos=[opt_in_tp],\n output_type_protos=[opt_in_tp])" + }, + { + "summary": "sequence", + "code": "node = onnx.helper.make_node(\n 'Identity',\n inputs=['x'],\n outputs=['y'],\n)\n\ndata = [\n np.array([[[\n [1, 2],\n [3, 4],\n ]]], dtype=np.float32),\n np.array([[[\n [2, 3],\n [1, 5],\n ]]], dtype=np.float32)]\n\nexpect(node, inputs=[data], outputs=[data], name='test_identity_sequence')" + } + ] + }, + { + "name": "Identity", + "module": "ai.onnx", + "version": 14, + "support_level": "common", + "description": "Identity operator", + "inputs": [ + { + "name": "input", + "type": "V", + "description": "Input tensor" + } + ], + "min_input": 1, + "max_input": 1, + "outputs": [ + { + "name": "output", + "type": "V", + "description": "Tensor to copy input into." + } + ], + "min_output": 1, + "max_output": 1, + "type_constraints": [ + { + "description": "Constrain input and output types to all tensor and sequence types.", + "type_param_str": "V", + "allowed_type_strs": [ + "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))" + ] + } + ], + "examples": [ + { + "summary": "identity", + "code": "node = onnx.helper.make_node(\n 'Identity',\n inputs=['x'],\n outputs=['y'],\n)\n\ndata = np.array([[[\n [1, 2],\n [3, 4],\n]]], dtype=np.float32)\n\nexpect(node, inputs=[data], outputs=[data],\n name='test_identity')" + }, + { + "summary": "identity_opt", + "code": "ten_in_tp = onnx.helper.make_tensor_type_proto(onnx.TensorProto.FLOAT, shape=[5])\nseq_in_tp = onnx.helper.make_sequence_type_proto(ten_in_tp)\nopt_in_tp = onnx.helper.make_optional_type_proto(seq_in_tp)\n\nidentity_node = onnx.helper.make_node(\n 'Identity',\n inputs=['opt_in'],\n outputs=['opt_out']\n)\n\nx = [np.array([1, 2, 3, 4, 5]).astype(np.float32)]\n\nexpect(identity_node, inputs=[x], outputs=[x], name='test_identity_opt',\n opset_imports=[onnx.helper.make_opsetid(\"\", 16)],\n input_type_protos=[opt_in_tp],\n output_type_protos=[opt_in_tp])" + }, + { + "summary": "sequence", + "code": "node = onnx.helper.make_node(\n 'Identity',\n inputs=['x'],\n outputs=['y'],\n)\n\ndata = [\n np.array([[[\n [1, 2],\n [3, 4],\n ]]], dtype=np.float32),\n np.array([[[\n [2, 3],\n [1, 5],\n ]]], dtype=np.float32)]\n\nexpect(node, inputs=[data], outputs=[data], name='test_identity_sequence')" + } + ] + }, + { + "name": "Identity", + "module": "ai.onnx", + "version": 16, + "support_level": "common", + "description": "Identity operator", + "inputs": [ + { + "name": "input", + "type": "V", + "description": "Input tensor" + } + ], + "min_input": 1, + "max_input": 1, + "outputs": [ + { + "name": "output", + "type": "V", + "description": "Tensor to copy input into." + } + ], + "min_output": 1, + "max_output": 1, + "type_constraints": [ + { + "description": "Constrain input and output types to all tensor, sequence, and optional types.", + "type_param_str": "V", + "allowed_type_strs": [ + "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))" + ] + } + ], + "examples": [ + { + "summary": "identity", + "code": "node = onnx.helper.make_node(\n 'Identity',\n inputs=['x'],\n outputs=['y'],\n)\n\ndata = np.array([[[\n [1, 2],\n [3, 4],\n]]], dtype=np.float32)\n\nexpect(node, inputs=[data], outputs=[data],\n name='test_identity')" + }, + { + "summary": "identity_opt", + "code": "ten_in_tp = onnx.helper.make_tensor_type_proto(onnx.TensorProto.FLOAT, shape=[5])\nseq_in_tp = onnx.helper.make_sequence_type_proto(ten_in_tp)\nopt_in_tp = onnx.helper.make_optional_type_proto(seq_in_tp)\n\nidentity_node = onnx.helper.make_node(\n 'Identity',\n inputs=['opt_in'],\n outputs=['opt_out']\n)\n\nx = [np.array([1, 2, 3, 4, 5]).astype(np.float32)]\n\nexpect(identity_node, inputs=[x], outputs=[x], name='test_identity_opt',\n opset_imports=[onnx.helper.make_opsetid(\"\", 16)],\n input_type_protos=[opt_in_tp],\n output_type_protos=[opt_in_tp])" + }, + { + "summary": "sequence", + "code": "node = onnx.helper.make_node(\n 'Identity',\n inputs=['x'],\n outputs=['y'],\n)\n\ndata = [\n np.array([[[\n [1, 2],\n [3, 4],\n ]]], dtype=np.float32),\n np.array([[[\n [2, 3],\n [1, 5],\n ]]], dtype=np.float32)]\n\nexpect(node, inputs=[data], outputs=[data], name='test_identity_sequence')" + } + ] + }, + { + "name": "If", + "module": "ai.onnx", + "version": 1, + "support_level": "common", + "description": "If conditional", + "attributes": [ + { + "name": "else_branch", + "type": "graph", + "required": true, + "description": "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." + }, + { + "name": "then_branch", + "type": "graph", + "required": true, + "description": "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": [ + { + "name": "cond", + "type": "B", + "description": "Condition for the if" + } + ], + "min_input": 1, + "max_input": 1, + "outputs": [ + { + "name": "outputs", + "type": "V", + "list": true, + "description": "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." + } + ], + "min_output": 1, + "max_output": 2147483647, + "outputs_range": "1 - ∞", + "type_constraints": [ + { + "description": "All Tensor types", + "type_param_str": "V", + "allowed_type_strs": [ + "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)" + ] + }, + { + "description": "Only bool", + "type_param_str": "B", + "allowed_type_strs": [ + "tensor(bool)" + ] + } + ], + "examples": [ + { + "summary": "if", + "code": "# Given a bool scalar input cond.\n# return constant tensor x if cond is True, otherwise return constant tensor y.\n\nthen_out = onnx.helper.make_tensor_value_info('then_out', onnx.TensorProto.FLOAT, [5])\nelse_out = onnx.helper.make_tensor_value_info('else_out', onnx.TensorProto.FLOAT, [5])\n\nx = np.array([1, 2, 3, 4, 5]).astype(np.float32)\ny = np.array([5, 4, 3, 2, 1]).astype(np.float32)\n\nthen_const_node = onnx.helper.make_node(\n 'Constant',\n inputs=[],\n outputs=['then_out'],\n value=onnx.numpy_helper.from_array(x)\n)\n\nelse_const_node = onnx.helper.make_node(\n 'Constant',\n inputs=[],\n outputs=['else_out'],\n value=onnx.numpy_helper.from_array(y)\n)\n\nthen_body = onnx.helper.make_graph(\n [then_const_node],\n 'then_body',\n [],\n [then_out]\n)\n\nelse_body = onnx.helper.make_graph(\n [else_const_node],\n 'else_body',\n [],\n [else_out]\n)\n\nif_node = onnx.helper.make_node(\n 'If',\n inputs=['cond'],\n outputs=['res'],\n then_branch=then_body,\n else_branch=else_body\n)\n\ncond = np.array(1).astype(bool)\nres = x if cond else y\nexpect(if_node, inputs=[cond], outputs=[res], name='test_if',\n opset_imports=[onnx.helper.make_opsetid(\"\", 11)])" + }, + { + "summary": "if_optional", + "code": "# Given a bool scalar input cond, return an empty optional sequence of\n# tensor if True, return an optional sequence with value x\n# (the input optional sequence) otherwise.\n\nten_in_tp = onnx.helper.make_tensor_type_proto(onnx.TensorProto.FLOAT, shape=[5])\nseq_in_tp = onnx.helper.make_sequence_type_proto(ten_in_tp)\nopt_in_tp = onnx.helper.make_optional_type_proto(seq_in_tp)\n\nthen_out_tensor_tp = onnx.helper.make_tensor_type_proto(onnx.TensorProto.FLOAT, shape=[5])\nthen_out_seq_tp = onnx.helper.make_sequence_type_proto(then_out_tensor_tp)\nthen_out_opt_tp = onnx.helper.make_optional_type_proto(then_out_seq_tp)\nthen_out = onnx.helper.make_value_info('then_out', then_out_opt_tp)\n\nelse_out_tensor_tp = onnx.helper.make_tensor_type_proto(onnx.TensorProto.FLOAT, shape=[5])\nelse_out_seq_tp = onnx.helper.make_sequence_type_proto(else_out_tensor_tp)\nelse_out_opt_tp = onnx.helper.make_optional_type_proto(else_out_seq_tp)\nelse_out = onnx.helper.make_value_info('else_out', else_out_opt_tp)\n\nx = [np.array([1, 2, 3, 4, 5]).astype(np.float32)]\ncond = np.array(0).astype(bool)\nres = compute_if_outputs(x, cond)\n\nopt_empty_in = onnx.helper.make_node(\n 'Optional',\n inputs=[],\n outputs=['optional_empty'],\n type=opt_in_tp\n)\n\nthen_body = onnx.helper.make_graph(\n [opt_empty_in],\n 'then_body',\n [],\n [then_out]\n)\n\nelse_const_node = onnx.helper.make_node(\n 'Constant',\n inputs=[],\n outputs=['x'],\n value=onnx.numpy_helper.from_array(x[0])\n)\n\nelse_seq_node = onnx.helper.make_node(\n 'SequenceConstruct',\n inputs=['x'],\n outputs=['else_seq']\n)\n\nelse_optional_seq_node = onnx.helper.make_node(\n 'Optional',\n inputs=['else_seq'],\n outputs=['else_opt']\n)\n\nelse_body = onnx.helper.make_graph(\n [else_const_node, else_seq_node, else_optional_seq_node],\n 'else_body',\n [],\n [else_out]\n)\n\nif_node = onnx.helper.make_node(\n 'If',\n inputs=['cond'],\n outputs=['sequence'],\n then_branch=then_body,\n else_branch=else_body\n)\n\nexpect(if_node, inputs=[cond], outputs=[res], name='test_if_opt',\n output_type_protos=[else_out_opt_tp],\n opset_imports=[onnx.helper.make_opsetid(\"\", 16)])" + }, + { + "summary": "if_seq", + "code": "# Given a bool scalar input cond.\n# return constant sequence x if cond is True, otherwise return constant sequence y.\n\nthen_out = onnx.helper.make_tensor_sequence_value_info('then_out', onnx.TensorProto.FLOAT, shape=[5])\nelse_out = onnx.helper.make_tensor_sequence_value_info('else_out', onnx.TensorProto.FLOAT, shape=[5])\n\nx = [np.array([1, 2, 3, 4, 5]).astype(np.float32)]\ny = [np.array([5, 4, 3, 2, 1]).astype(np.float32)]\n\nthen_const_node = onnx.helper.make_node(\n 'Constant',\n inputs=[],\n outputs=['x'],\n value=onnx.numpy_helper.from_array(x[0])\n)\n\nthen_seq_node = onnx.helper.make_node(\n 'SequenceConstruct',\n inputs=['x'],\n outputs=['then_out']\n)\n\nelse_const_node = onnx.helper.make_node(\n 'Constant',\n inputs=[],\n outputs=['y'],\n value=onnx.numpy_helper.from_array(y[0])\n)\n\nelse_seq_node = onnx.helper.make_node(\n 'SequenceConstruct',\n inputs=['y'],\n outputs=['else_out']\n)\n\nthen_body = onnx.helper.make_graph(\n [then_const_node, then_seq_node],\n 'then_body',\n [],\n [then_out]\n)\n\nelse_body = onnx.helper.make_graph(\n [else_const_node, else_seq_node],\n 'else_body',\n [],\n [else_out]\n)\n\nif_node = onnx.helper.make_node(\n 'If',\n inputs=['cond'],\n outputs=['res'],\n then_branch=then_body,\n else_branch=else_body\n)\n\ncond = np.array(1).astype(bool)\nres = x if cond else y\nexpect(if_node, inputs=[cond], outputs=[res], name='test_if_seq',\n opset_imports=[onnx.helper.make_opsetid(\"\", 13)])" + } + ] + }, + { + "name": "If", + "module": "ai.onnx", + "version": 11, + "support_level": "common", + "description": "If conditional", + "attributes": [ + { + "name": "else_branch", + "type": "graph", + "required": true, + "description": "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." + }, + { + "name": "then_branch", + "type": "graph", + "required": true, + "description": "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": [ + { + "name": "cond", + "type": "B", + "description": "Condition for the if" + } + ], + "min_input": 1, + "max_input": 1, + "outputs": [ + { + "name": "outputs", + "type": "V", + "list": true, + "description": "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." + } + ], + "min_output": 1, + "max_output": 2147483647, + "outputs_range": "1 - ∞", + "type_constraints": [ + { + "description": "All Tensor types", + "type_param_str": "V", + "allowed_type_strs": [ + "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)" + ] + }, + { + "description": "Only bool", + "type_param_str": "B", + "allowed_type_strs": [ + "tensor(bool)" + ] + } + ], + "examples": [ + { + "summary": "if", + "code": "# Given a bool scalar input cond.\n# return constant tensor x if cond is True, otherwise return constant tensor y.\n\nthen_out = onnx.helper.make_tensor_value_info('then_out', onnx.TensorProto.FLOAT, [5])\nelse_out = onnx.helper.make_tensor_value_info('else_out', onnx.TensorProto.FLOAT, [5])\n\nx = np.array([1, 2, 3, 4, 5]).astype(np.float32)\ny = np.array([5, 4, 3, 2, 1]).astype(np.float32)\n\nthen_const_node = onnx.helper.make_node(\n 'Constant',\n inputs=[],\n outputs=['then_out'],\n value=onnx.numpy_helper.from_array(x)\n)\n\nelse_const_node = onnx.helper.make_node(\n 'Constant',\n inputs=[],\n outputs=['else_out'],\n value=onnx.numpy_helper.from_array(y)\n)\n\nthen_body = onnx.helper.make_graph(\n [then_const_node],\n 'then_body',\n [],\n [then_out]\n)\n\nelse_body = onnx.helper.make_graph(\n [else_const_node],\n 'else_body',\n [],\n [else_out]\n)\n\nif_node = onnx.helper.make_node(\n 'If',\n inputs=['cond'],\n outputs=['res'],\n then_branch=then_body,\n else_branch=else_body\n)\n\ncond = np.array(1).astype(bool)\nres = x if cond else y\nexpect(if_node, inputs=[cond], outputs=[res], name='test_if',\n opset_imports=[onnx.helper.make_opsetid(\"\", 11)])" + }, + { + "summary": "if_optional", + "code": "# Given a bool scalar input cond, return an empty optional sequence of\n# tensor if True, return an optional sequence with value x\n# (the input optional sequence) otherwise.\n\nten_in_tp = onnx.helper.make_tensor_type_proto(onnx.TensorProto.FLOAT, shape=[5])\nseq_in_tp = onnx.helper.make_sequence_type_proto(ten_in_tp)\nopt_in_tp = onnx.helper.make_optional_type_proto(seq_in_tp)\n\nthen_out_tensor_tp = onnx.helper.make_tensor_type_proto(onnx.TensorProto.FLOAT, shape=[5])\nthen_out_seq_tp = onnx.helper.make_sequence_type_proto(then_out_tensor_tp)\nthen_out_opt_tp = onnx.helper.make_optional_type_proto(then_out_seq_tp)\nthen_out = onnx.helper.make_value_info('then_out', then_out_opt_tp)\n\nelse_out_tensor_tp = onnx.helper.make_tensor_type_proto(onnx.TensorProto.FLOAT, shape=[5])\nelse_out_seq_tp = onnx.helper.make_sequence_type_proto(else_out_tensor_tp)\nelse_out_opt_tp = onnx.helper.make_optional_type_proto(else_out_seq_tp)\nelse_out = onnx.helper.make_value_info('else_out', else_out_opt_tp)\n\nx = [np.array([1, 2, 3, 4, 5]).astype(np.float32)]\ncond = np.array(0).astype(bool)\nres = compute_if_outputs(x, cond)\n\nopt_empty_in = onnx.helper.make_node(\n 'Optional',\n inputs=[],\n outputs=['optional_empty'],\n type=opt_in_tp\n)\n\nthen_body = onnx.helper.make_graph(\n [opt_empty_in],\n 'then_body',\n [],\n [then_out]\n)\n\nelse_const_node = onnx.helper.make_node(\n 'Constant',\n inputs=[],\n outputs=['x'],\n value=onnx.numpy_helper.from_array(x[0])\n)\n\nelse_seq_node = onnx.helper.make_node(\n 'SequenceConstruct',\n inputs=['x'],\n outputs=['else_seq']\n)\n\nelse_optional_seq_node = onnx.helper.make_node(\n 'Optional',\n inputs=['else_seq'],\n outputs=['else_opt']\n)\n\nelse_body = onnx.helper.make_graph(\n [else_const_node, else_seq_node, else_optional_seq_node],\n 'else_body',\n [],\n [else_out]\n)\n\nif_node = onnx.helper.make_node(\n 'If',\n inputs=['cond'],\n outputs=['sequence'],\n then_branch=then_body,\n else_branch=else_body\n)\n\nexpect(if_node, inputs=[cond], outputs=[res], name='test_if_opt',\n output_type_protos=[else_out_opt_tp],\n opset_imports=[onnx.helper.make_opsetid(\"\", 16)])" + }, + { + "summary": "if_seq", + "code": "# Given a bool scalar input cond.\n# return constant sequence x if cond is True, otherwise return constant sequence y.\n\nthen_out = onnx.helper.make_tensor_sequence_value_info('then_out', onnx.TensorProto.FLOAT, shape=[5])\nelse_out = onnx.helper.make_tensor_sequence_value_info('else_out', onnx.TensorProto.FLOAT, shape=[5])\n\nx = [np.array([1, 2, 3, 4, 5]).astype(np.float32)]\ny = [np.array([5, 4, 3, 2, 1]).astype(np.float32)]\n\nthen_const_node = onnx.helper.make_node(\n 'Constant',\n inputs=[],\n outputs=['x'],\n value=onnx.numpy_helper.from_array(x[0])\n)\n\nthen_seq_node = onnx.helper.make_node(\n 'SequenceConstruct',\n inputs=['x'],\n outputs=['then_out']\n)\n\nelse_const_node = onnx.helper.make_node(\n 'Constant',\n inputs=[],\n outputs=['y'],\n value=onnx.numpy_helper.from_array(y[0])\n)\n\nelse_seq_node = onnx.helper.make_node(\n 'SequenceConstruct',\n inputs=['y'],\n outputs=['else_out']\n)\n\nthen_body = onnx.helper.make_graph(\n [then_const_node, then_seq_node],\n 'then_body',\n [],\n [then_out]\n)\n\nelse_body = onnx.helper.make_graph(\n [else_const_node, else_seq_node],\n 'else_body',\n [],\n [else_out]\n)\n\nif_node = onnx.helper.make_node(\n 'If',\n inputs=['cond'],\n outputs=['res'],\n then_branch=then_body,\n else_branch=else_body\n)\n\ncond = np.array(1).astype(bool)\nres = x if cond else y\nexpect(if_node, inputs=[cond], outputs=[res], name='test_if_seq',\n opset_imports=[onnx.helper.make_opsetid(\"\", 13)])" + } + ] + }, + { + "name": "If", + "module": "ai.onnx", + "version": 13, + "support_level": "common", + "description": "If conditional", + "attributes": [ + { + "name": "else_branch", + "type": "graph", + "required": true, + "description": "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." + }, + { + "name": "then_branch", + "type": "graph", + "required": true, + "description": "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": [ + { + "name": "cond", + "type": "B", + "description": "Condition for the if" + } + ], + "min_input": 1, + "max_input": 1, + "outputs": [ + { + "name": "outputs", + "type": "V", + "list": true, + "description": "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." + } + ], + "min_output": 1, + "max_output": 2147483647, + "outputs_range": "1 - ∞", + "type_constraints": [ + { + "description": "All Tensor and Sequence types", + "type_param_str": "V", + "allowed_type_strs": [ + "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))" + ] + }, + { + "description": "Only bool", + "type_param_str": "B", + "allowed_type_strs": [ + "tensor(bool)" + ] + } + ], + "examples": [ + { + "summary": "if", + "code": "# Given a bool scalar input cond.\n# return constant tensor x if cond is True, otherwise return constant tensor y.\n\nthen_out = onnx.helper.make_tensor_value_info('then_out', onnx.TensorProto.FLOAT, [5])\nelse_out = onnx.helper.make_tensor_value_info('else_out', onnx.TensorProto.FLOAT, [5])\n\nx = np.array([1, 2, 3, 4, 5]).astype(np.float32)\ny = np.array([5, 4, 3, 2, 1]).astype(np.float32)\n\nthen_const_node = onnx.helper.make_node(\n 'Constant',\n inputs=[],\n outputs=['then_out'],\n value=onnx.numpy_helper.from_array(x)\n)\n\nelse_const_node = onnx.helper.make_node(\n 'Constant',\n inputs=[],\n outputs=['else_out'],\n value=onnx.numpy_helper.from_array(y)\n)\n\nthen_body = onnx.helper.make_graph(\n [then_const_node],\n 'then_body',\n [],\n [then_out]\n)\n\nelse_body = onnx.helper.make_graph(\n [else_const_node],\n 'else_body',\n [],\n [else_out]\n)\n\nif_node = onnx.helper.make_node(\n 'If',\n inputs=['cond'],\n outputs=['res'],\n then_branch=then_body,\n else_branch=else_body\n)\n\ncond = np.array(1).astype(bool)\nres = x if cond else y\nexpect(if_node, inputs=[cond], outputs=[res], name='test_if',\n opset_imports=[onnx.helper.make_opsetid(\"\", 11)])" + }, + { + "summary": "if_optional", + "code": "# Given a bool scalar input cond, return an empty optional sequence of\n# tensor if True, return an optional sequence with value x\n# (the input optional sequence) otherwise.\n\nten_in_tp = onnx.helper.make_tensor_type_proto(onnx.TensorProto.FLOAT, shape=[5])\nseq_in_tp = onnx.helper.make_sequence_type_proto(ten_in_tp)\nopt_in_tp = onnx.helper.make_optional_type_proto(seq_in_tp)\n\nthen_out_tensor_tp = onnx.helper.make_tensor_type_proto(onnx.TensorProto.FLOAT, shape=[5])\nthen_out_seq_tp = onnx.helper.make_sequence_type_proto(then_out_tensor_tp)\nthen_out_opt_tp = onnx.helper.make_optional_type_proto(then_out_seq_tp)\nthen_out = onnx.helper.make_value_info('then_out', then_out_opt_tp)\n\nelse_out_tensor_tp = onnx.helper.make_tensor_type_proto(onnx.TensorProto.FLOAT, shape=[5])\nelse_out_seq_tp = onnx.helper.make_sequence_type_proto(else_out_tensor_tp)\nelse_out_opt_tp = onnx.helper.make_optional_type_proto(else_out_seq_tp)\nelse_out = onnx.helper.make_value_info('else_out', else_out_opt_tp)\n\nx = [np.array([1, 2, 3, 4, 5]).astype(np.float32)]\ncond = np.array(0).astype(bool)\nres = compute_if_outputs(x, cond)\n\nopt_empty_in = onnx.helper.make_node(\n 'Optional',\n inputs=[],\n outputs=['optional_empty'],\n type=opt_in_tp\n)\n\nthen_body = onnx.helper.make_graph(\n [opt_empty_in],\n 'then_body',\n [],\n [then_out]\n)\n\nelse_const_node = onnx.helper.make_node(\n 'Constant',\n inputs=[],\n outputs=['x'],\n value=onnx.numpy_helper.from_array(x[0])\n)\n\nelse_seq_node = onnx.helper.make_node(\n 'SequenceConstruct',\n inputs=['x'],\n outputs=['else_seq']\n)\n\nelse_optional_seq_node = onnx.helper.make_node(\n 'Optional',\n inputs=['else_seq'],\n outputs=['else_opt']\n)\n\nelse_body = onnx.helper.make_graph(\n [else_const_node, else_seq_node, else_optional_seq_node],\n 'else_body',\n [],\n [else_out]\n)\n\nif_node = onnx.helper.make_node(\n 'If',\n inputs=['cond'],\n outputs=['sequence'],\n then_branch=then_body,\n else_branch=else_body\n)\n\nexpect(if_node, inputs=[cond], outputs=[res], name='test_if_opt',\n output_type_protos=[else_out_opt_tp],\n opset_imports=[onnx.helper.make_opsetid(\"\", 16)])" + }, + { + "summary": "if_seq", + "code": "# Given a bool scalar input cond.\n# return constant sequence x if cond is True, otherwise return constant sequence y.\n\nthen_out = onnx.helper.make_tensor_sequence_value_info('then_out', onnx.TensorProto.FLOAT, shape=[5])\nelse_out = onnx.helper.make_tensor_sequence_value_info('else_out', onnx.TensorProto.FLOAT, shape=[5])\n\nx = [np.array([1, 2, 3, 4, 5]).astype(np.float32)]\ny = [np.array([5, 4, 3, 2, 1]).astype(np.float32)]\n\nthen_const_node = onnx.helper.make_node(\n 'Constant',\n inputs=[],\n outputs=['x'],\n value=onnx.numpy_helper.from_array(x[0])\n)\n\nthen_seq_node = onnx.helper.make_node(\n 'SequenceConstruct',\n inputs=['x'],\n outputs=['then_out']\n)\n\nelse_const_node = onnx.helper.make_node(\n 'Constant',\n inputs=[],\n outputs=['y'],\n value=onnx.numpy_helper.from_array(y[0])\n)\n\nelse_seq_node = onnx.helper.make_node(\n 'SequenceConstruct',\n inputs=['y'],\n outputs=['else_out']\n)\n\nthen_body = onnx.helper.make_graph(\n [then_const_node, then_seq_node],\n 'then_body',\n [],\n [then_out]\n)\n\nelse_body = onnx.helper.make_graph(\n [else_const_node, else_seq_node],\n 'else_body',\n [],\n [else_out]\n)\n\nif_node = onnx.helper.make_node(\n 'If',\n inputs=['cond'],\n outputs=['res'],\n then_branch=then_body,\n else_branch=else_body\n)\n\ncond = np.array(1).astype(bool)\nres = x if cond else y\nexpect(if_node, inputs=[cond], outputs=[res], name='test_if_seq',\n opset_imports=[onnx.helper.make_opsetid(\"\", 13)])" + } + ] + }, + { + "name": "If", + "module": "ai.onnx", + "version": 16, + "support_level": "common", + "description": "If conditional", + "attributes": [ + { + "name": "else_branch", + "type": "graph", + "required": true, + "description": "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." + }, + { + "name": "then_branch", + "type": "graph", + "required": true, + "description": "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": [ + { + "name": "cond", + "type": "B", + "description": "Condition for the if" + } + ], + "min_input": 1, + "max_input": 1, + "outputs": [ + { + "name": "outputs", + "type": "V", + "list": true, + "description": "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." + } + ], + "min_output": 1, + "max_output": 2147483647, + "outputs_range": "1 - ∞", + "type_constraints": [ + { + "description": "All Tensor, Sequence, and optional types", + "type_param_str": "V", + "allowed_type_strs": [ + "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))" + ] + }, + { + "description": "Only bool", + "type_param_str": "B", + "allowed_type_strs": [ + "tensor(bool)" + ] + } + ], + "examples": [ + { + "summary": "if", + "code": "# Given a bool scalar input cond.\n# return constant tensor x if cond is True, otherwise return constant tensor y.\n\nthen_out = onnx.helper.make_tensor_value_info('then_out', onnx.TensorProto.FLOAT, [5])\nelse_out = onnx.helper.make_tensor_value_info('else_out', onnx.TensorProto.FLOAT, [5])\n\nx = np.array([1, 2, 3, 4, 5]).astype(np.float32)\ny = np.array([5, 4, 3, 2, 1]).astype(np.float32)\n\nthen_const_node = onnx.helper.make_node(\n 'Constant',\n inputs=[],\n outputs=['then_out'],\n value=onnx.numpy_helper.from_array(x)\n)\n\nelse_const_node = onnx.helper.make_node(\n 'Constant',\n inputs=[],\n outputs=['else_out'],\n value=onnx.numpy_helper.from_array(y)\n)\n\nthen_body = onnx.helper.make_graph(\n [then_const_node],\n 'then_body',\n [],\n [then_out]\n)\n\nelse_body = onnx.helper.make_graph(\n [else_const_node],\n 'else_body',\n [],\n [else_out]\n)\n\nif_node = onnx.helper.make_node(\n 'If',\n inputs=['cond'],\n outputs=['res'],\n then_branch=then_body,\n else_branch=else_body\n)\n\ncond = np.array(1).astype(bool)\nres = x if cond else y\nexpect(if_node, inputs=[cond], outputs=[res], name='test_if',\n opset_imports=[onnx.helper.make_opsetid(\"\", 11)])" + }, + { + "summary": "if_optional", + "code": "# Given a bool scalar input cond, return an empty optional sequence of\n# tensor if True, return an optional sequence with value x\n# (the input optional sequence) otherwise.\n\nten_in_tp = onnx.helper.make_tensor_type_proto(onnx.TensorProto.FLOAT, shape=[5])\nseq_in_tp = onnx.helper.make_sequence_type_proto(ten_in_tp)\nopt_in_tp = onnx.helper.make_optional_type_proto(seq_in_tp)\n\nthen_out_tensor_tp = onnx.helper.make_tensor_type_proto(onnx.TensorProto.FLOAT, shape=[5])\nthen_out_seq_tp = onnx.helper.make_sequence_type_proto(then_out_tensor_tp)\nthen_out_opt_tp = onnx.helper.make_optional_type_proto(then_out_seq_tp)\nthen_out = onnx.helper.make_value_info('then_out', then_out_opt_tp)\n\nelse_out_tensor_tp = onnx.helper.make_tensor_type_proto(onnx.TensorProto.FLOAT, shape=[5])\nelse_out_seq_tp = onnx.helper.make_sequence_type_proto(else_out_tensor_tp)\nelse_out_opt_tp = onnx.helper.make_optional_type_proto(else_out_seq_tp)\nelse_out = onnx.helper.make_value_info('else_out', else_out_opt_tp)\n\nx = [np.array([1, 2, 3, 4, 5]).astype(np.float32)]\ncond = np.array(0).astype(bool)\nres = compute_if_outputs(x, cond)\n\nopt_empty_in = onnx.helper.make_node(\n 'Optional',\n inputs=[],\n outputs=['optional_empty'],\n type=opt_in_tp\n)\n\nthen_body = onnx.helper.make_graph(\n [opt_empty_in],\n 'then_body',\n [],\n [then_out]\n)\n\nelse_const_node = onnx.helper.make_node(\n 'Constant',\n inputs=[],\n outputs=['x'],\n value=onnx.numpy_helper.from_array(x[0])\n)\n\nelse_seq_node = onnx.helper.make_node(\n 'SequenceConstruct',\n inputs=['x'],\n outputs=['else_seq']\n)\n\nelse_optional_seq_node = onnx.helper.make_node(\n 'Optional',\n inputs=['else_seq'],\n outputs=['else_opt']\n)\n\nelse_body = onnx.helper.make_graph(\n [else_const_node, else_seq_node, else_optional_seq_node],\n 'else_body',\n [],\n [else_out]\n)\n\nif_node = onnx.helper.make_node(\n 'If',\n inputs=['cond'],\n outputs=['sequence'],\n then_branch=then_body,\n else_branch=else_body\n)\n\nexpect(if_node, inputs=[cond], outputs=[res], name='test_if_opt',\n output_type_protos=[else_out_opt_tp],\n opset_imports=[onnx.helper.make_opsetid(\"\", 16)])" + }, + { + "summary": "if_seq", + "code": "# Given a bool scalar input cond.\n# return constant sequence x if cond is True, otherwise return constant sequence y.\n\nthen_out = onnx.helper.make_tensor_sequence_value_info('then_out', onnx.TensorProto.FLOAT, shape=[5])\nelse_out = onnx.helper.make_tensor_sequence_value_info('else_out', onnx.TensorProto.FLOAT, shape=[5])\n\nx = [np.array([1, 2, 3, 4, 5]).astype(np.float32)]\ny = [np.array([5, 4, 3, 2, 1]).astype(np.float32)]\n\nthen_const_node = onnx.helper.make_node(\n 'Constant',\n inputs=[],\n outputs=['x'],\n value=onnx.numpy_helper.from_array(x[0])\n)\n\nthen_seq_node = onnx.helper.make_node(\n 'SequenceConstruct',\n inputs=['x'],\n outputs=['then_out']\n)\n\nelse_const_node = onnx.helper.make_node(\n 'Constant',\n inputs=[],\n outputs=['y'],\n value=onnx.numpy_helper.from_array(y[0])\n)\n\nelse_seq_node = onnx.helper.make_node(\n 'SequenceConstruct',\n inputs=['y'],\n outputs=['else_out']\n)\n\nthen_body = onnx.helper.make_graph(\n [then_const_node, then_seq_node],\n 'then_body',\n [],\n [then_out]\n)\n\nelse_body = onnx.helper.make_graph(\n [else_const_node, else_seq_node],\n 'else_body',\n [],\n [else_out]\n)\n\nif_node = onnx.helper.make_node(\n 'If',\n inputs=['cond'],\n outputs=['res'],\n then_branch=then_body,\n else_branch=else_body\n)\n\ncond = np.array(1).astype(bool)\nres = x if cond else y\nexpect(if_node, inputs=[cond], outputs=[res], name='test_if_seq',\n opset_imports=[onnx.helper.make_opsetid(\"\", 13)])" + } + ] + }, + { + "name": "Imputer", + "module": "ai.onnx.ml", + "version": 1, + "support_level": "common", + "description": "Replaces inputs that equal one value with another, leaving all other elements alone.
\n This operator is typically used to replace missing values in situations where they have a canonical\n representation, such as -1, 0, NaN, or some extreme value.
\n One and only one of imputed_value_floats or imputed_value_int64s should be defined -- floats if the input tensor\n holds floats, integers if the input tensor holds integers. The imputed values must all fit within the\n width of the tensor element type. One and only one of the replaced_value_float or replaced_value_int64 should be defined,\n which one depends on whether floats or integers are being processed.
\n 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.\n", + "attributes": [ + { + "name": "imputed_value_floats", + "type": "float32[]", + "required": false, + "description": "Value(s) to change to" + }, + { + "name": "imputed_value_int64s", + "type": "int64[]", + "required": false, + "description": "Value(s) to change to." + }, + { + "name": "replaced_value_float", + "type": "float32", + "required": false, + "description": "A value that needs replacing." + }, + { + "name": "replaced_value_int64", + "type": "int64", + "required": false, + "description": "A value that needs replacing." + } + ], + "inputs": [ + { + "name": "X", + "type": "T", + "description": "Data to be processed." + } + ], + "min_input": 1, + "max_input": 1, + "outputs": [ + { + "name": "Y", + "type": "T", + "description": "Imputed output data" + } + ], + "min_output": 1, + "max_output": 1, + "type_constraints": [ + { + "description": "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.", + "type_param_str": "T", + "allowed_type_strs": [ + "tensor(float)", + "tensor(double)", + "tensor(int64)", + "tensor(int32)" + ] + } + ] + }, + { + "name": "InstanceNormalization", + "module": "ai.onnx", + "version": 1, + "support_level": "common", + "description": "Carries out instance normalization as described in the paper\nhttps://arxiv.org/abs/1607.08022.\n\ny = scale * (x - mean) / sqrt(variance + epsilon) + B,\nwhere mean and variance are computed per instance per channel.\n\n", + "attributes": [ + { + "name": "consumed_inputs", + "type": "int64[]", + "required": false, + "description": "legacy optimization attribute." + }, + { + "name": "epsilon", + "type": "float32", + "required": false, + "default": 9.999999747378752e-06, + "description": "The epsilon value to use to avoid division by zero, default is 1e-5f." + } + ], + "inputs": [ + { + "name": "input", + "type": "T", + "description": "The input 4-dimensional tensor of shape NCHW." + }, + { + "name": "scale", + "type": "T", + "description": "The input 1-dimensional scale tensor of size C." + }, + { + "name": "B", + "type": "T", + "description": "The input 1-dimensional bias tensor of size C." + } + ], + "min_input": 3, + "max_input": 3, + "outputs": [ + { + "name": "output", + "type": "T", + "description": "The output 4-dimensional tensor of the same shape as input." + } + ], + "min_output": 1, + "max_output": 1, + "type_constraints": [ + { + "description": "Constrain input and output types to float tensors.", + "type_param_str": "T", + "allowed_type_strs": [ + "tensor(float16)", + "tensor(float)", + "tensor(double)" + ] + } + ], + "examples": [ + { + "summary": "instancenormalization", + "code": "def _instancenorm_test_mode(x, s, bias, epsilon=1e-5): # type: ignore\n dims_x = len(x.shape)\n axis = tuple(range(2, dims_x))\n mean = np.mean(x, axis=axis, keepdims=True)\n var = np.var(x, axis=axis, keepdims=True)\n dim_ones = (1,) * (dims_x - 2)\n s = s.reshape(-1, *dim_ones)\n bias = bias.reshape(-1, *dim_ones)\n return s * (x - mean) / np.sqrt(var + epsilon) + bias\n\n# input size: (1, 2, 1, 3)\nx = np.array([[[[-1, 0, 1]], [[2, 3, 4]]]]).astype(np.float32)\ns = np.array([1.0, 1.5]).astype(np.float32)\nbias = np.array([0, 1]).astype(np.float32)\ny = _instancenorm_test_mode(x, s, bias).astype(np.float32)\n\nnode = onnx.helper.make_node(\n 'InstanceNormalization',\n inputs=['x', 's', 'bias'],\n outputs=['y'],\n)\n\n# output size: (1, 2, 1, 3)\nexpect(node, inputs=[x, s, bias], outputs=[y],\n name='test_instancenorm_example')\n\n# input size: (2, 3, 4, 5)\nx = np.random.randn(2, 3, 4, 5).astype(np.float32)\ns = np.random.randn(3).astype(np.float32)\nbias = np.random.randn(3).astype(np.float32)\nepsilon = 1e-2\ny = _instancenorm_test_mode(x, s, bias, epsilon).astype(np.float32)\n\nnode = onnx.helper.make_node(\n 'InstanceNormalization',\n inputs=['x', 's', 'bias'],\n outputs=['y'],\n epsilon=epsilon,\n)\n\n# output size: (2, 3, 4, 5)\nexpect(node, inputs=[x, s, bias], outputs=[y],\n name='test_instancenorm_epsilon')" + } + ], + "category": "Normalization" + }, + { + "name": "InstanceNormalization", + "module": "ai.onnx", + "version": 6, + "support_level": "common", + "description": "Carries out instance normalization as described in the paper\nhttps://arxiv.org/abs/1607.08022.\n\ny = scale * (x - mean) / sqrt(variance + epsilon) + B,\nwhere mean and variance are computed per instance per channel.\n\n", + "attributes": [ + { + "name": "epsilon", + "type": "float32", + "required": false, + "default": 9.999999747378752e-06, + "description": "The epsilon value to use to avoid division by zero." + } + ], + "inputs": [ + { + "name": "input", + "type": "T", + "description": "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." + }, + { + "name": "scale", + "type": "T", + "description": "The input 1-dimensional scale tensor of size C." + }, + { + "name": "B", + "type": "T", + "description": "The input 1-dimensional bias tensor of size C." + } + ], + "min_input": 3, + "max_input": 3, + "outputs": [ + { + "name": "output", + "type": "T", + "description": "The output tensor of the same shape as input." + } + ], + "min_output": 1, + "max_output": 1, + "type_constraints": [ + { + "description": "Constrain input and output types to float tensors.", + "type_param_str": "T", + "allowed_type_strs": [ + "tensor(float16)", + "tensor(float)", + "tensor(double)" + ] + } + ], + "examples": [ + { + "summary": "instancenormalization", + "code": "def _instancenorm_test_mode(x, s, bias, epsilon=1e-5): # type: ignore\n dims_x = len(x.shape)\n axis = tuple(range(2, dims_x))\n mean = np.mean(x, axis=axis, keepdims=True)\n var = np.var(x, axis=axis, keepdims=True)\n dim_ones = (1,) * (dims_x - 2)\n s = s.reshape(-1, *dim_ones)\n bias = bias.reshape(-1, *dim_ones)\n return s * (x - mean) / np.sqrt(var + epsilon) + bias\n\n# input size: (1, 2, 1, 3)\nx = np.array([[[[-1, 0, 1]], [[2, 3, 4]]]]).astype(np.float32)\ns = np.array([1.0, 1.5]).astype(np.float32)\nbias = np.array([0, 1]).astype(np.float32)\ny = _instancenorm_test_mode(x, s, bias).astype(np.float32)\n\nnode = onnx.helper.make_node(\n 'InstanceNormalization',\n inputs=['x', 's', 'bias'],\n outputs=['y'],\n)\n\n# output size: (1, 2, 1, 3)\nexpect(node, inputs=[x, s, bias], outputs=[y],\n name='test_instancenorm_example')\n\n# input size: (2, 3, 4, 5)\nx = np.random.randn(2, 3, 4, 5).astype(np.float32)\ns = np.random.randn(3).astype(np.float32)\nbias = np.random.randn(3).astype(np.float32)\nepsilon = 1e-2\ny = _instancenorm_test_mode(x, s, bias, epsilon).astype(np.float32)\n\nnode = onnx.helper.make_node(\n 'InstanceNormalization',\n inputs=['x', 's', 'bias'],\n outputs=['y'],\n epsilon=epsilon,\n)\n\n# output size: (2, 3, 4, 5)\nexpect(node, inputs=[x, s, bias], outputs=[y],\n name='test_instancenorm_epsilon')" + } + ], + "category": "Normalization" + }, + { + "name": "IsInf", + "module": "ai.onnx", + "version": 10, + "support_level": "common", + "description": "Map infinity to true and other values to false.", + "attributes": [ + { + "name": "detect_negative", + "type": "int64", + "required": false, + "default": 1, + "description": "(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." + }, + { + "name": "detect_positive", + "type": "int64", + "required": false, + "default": 1, + "description": "(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": [ + { + "name": "X", + "type": "T1", + "description": "input" + } + ], + "min_input": 1, + "max_input": 1, + "outputs": [ + { + "name": "Y", + "type": "T2", + "description": "output" + } + ], + "min_output": 1, + "max_output": 1, + "type_constraints": [ + { + "description": "Constrain input types to float tensors.", + "type_param_str": "T1", + "allowed_type_strs": [ + "tensor(float)", + "tensor(double)" + ] + }, + { + "description": "Constrain output types to boolean tensors.", + "type_param_str": "T2", + "allowed_type_strs": [ + "tensor(bool)" + ] + } + ], + "examples": [ + { + "summary": "infinity", + "code": "node = onnx.helper.make_node('IsInf',\n inputs=['x'],\n outputs=['y'],\n )\n\nx = np.array([-1.2, np.nan, np.inf, 2.8, np.NINF, np.inf],\n dtype=np.float32)\ny = np.isinf(x)\nexpect(node, inputs=[x], outputs=[y], name='test_isinf')" + }, + { + "summary": "negative_infinity_only", + "code": "node = onnx.helper.make_node('IsInf',\n inputs=['x'],\n outputs=['y'],\n detect_positive=0\n )\n\nx = np.array([-1.7, np.nan, np.inf, -3.6, np.NINF, np.inf],\n dtype=np.float32)\ny = np.isneginf(x)\nexpect(node, inputs=[x], outputs=[y], name='test_isinf_negative')" + }, + { + "summary": "positive_infinity_only", + "code": "node = onnx.helper.make_node('IsInf',\n inputs=['x'],\n outputs=['y'],\n detect_negative=0\n )\n\nx = np.array([-1.7, np.nan, np.inf, 3.6, np.NINF, np.inf],\n dtype=np.float32)\ny = np.isposinf(x)\nexpect(node, inputs=[x], outputs=[y], name='test_isinf_positive')" + } + ] + }, + { + "name": "IsNaN", + "module": "ai.onnx", + "version": 9, + "support_level": "common", + "description": "Returns which elements of the input are NaN.", + "inputs": [ + { + "name": "X", + "type": "T1", + "description": "input" + } + ], + "min_input": 1, + "max_input": 1, + "outputs": [ + { + "name": "Y", + "type": "T2", + "description": "output" + } + ], + "min_output": 1, + "max_output": 1, + "type_constraints": [ + { + "description": "Constrain input types to float tensors.", + "type_param_str": "T1", + "allowed_type_strs": [ + "tensor(float16)", + "tensor(float)", + "tensor(double)" + ] + }, + { + "description": "Constrain output types to boolean tensors.", + "type_param_str": "T2", + "allowed_type_strs": [ + "tensor(bool)" + ] + } + ], + "examples": [ + { + "summary": "isnan", + "code": "node = onnx.helper.make_node(\n 'IsNaN',\n inputs=['x'],\n outputs=['y'],\n)\n\nx = np.array([3.0, np.nan, 4.0, np.nan], dtype=np.float32)\ny = np.isnan(x)\nexpect(node, inputs=[x], outputs=[y], name='test_isnan')" + } + ] + }, + { + "name": "IsNaN", + "module": "ai.onnx", + "version": 13, + "support_level": "common", + "description": "Returns which elements of the input are NaN.", + "inputs": [ + { + "name": "X", + "type": "T1", + "description": "input" + } + ], + "min_input": 1, + "max_input": 1, + "outputs": [ + { + "name": "Y", + "type": "T2", + "description": "output" + } + ], + "min_output": 1, + "max_output": 1, + "type_constraints": [ + { + "description": "Constrain input types to float tensors.", + "type_param_str": "T1", + "allowed_type_strs": [ + "tensor(float16)", + "tensor(float)", + "tensor(double)", + "tensor(bfloat16)" + ] + }, + { + "description": "Constrain output types to boolean tensors.", + "type_param_str": "T2", + "allowed_type_strs": [ + "tensor(bool)" + ] + } + ], + "examples": [ + { + "summary": "isnan", + "code": "node = onnx.helper.make_node(\n 'IsNaN',\n inputs=['x'],\n outputs=['y'],\n)\n\nx = np.array([3.0, np.nan, 4.0, np.nan], dtype=np.float32)\ny = np.isnan(x)\nexpect(node, inputs=[x], outputs=[y], name='test_isnan')" + } + ] + }, + { + "name": "LRN", + "module": "ai.onnx", + "version": 1, + "support_level": "common", + "description": "Local Response Normalization proposed in the [AlexNet paper](https://papers.nips.cc/paper/4824-imagenet-classification-with-deep-convolutional-neural-networks.pdf).\nIt normalizes over local input regions.\nThe local region is defined across the channels. For an element X[n, c, d1, ..., dk] in a tensor\nof shape (N x C x D1 x D2, ..., Dk), its region is\n{X[n, i, d1, ..., dk] | max(0, c - floor((size - 1) / 2)) <= i <= min(C - 1, c + ceil((size - 1) / 2))}.\n\nsquare_sum[n, c, d1, ..., dk] = sum(X[n, i, d1, ..., dk] ^ 2),\nwhere max(0, c - floor((size - 1) / 2)) <= i <= min(C - 1, c + ceil((size - 1) / 2)).\n\nY[n, c, d1, ..., dk] = X[n, c, d1, ..., dk] / (bias + alpha / size * square_sum[n, c, d1, ..., dk] ) ^ beta\n", + "attributes": [ + { + "name": "alpha", + "type": "float32", + "required": false, + "default": 9.999999747378752e-05, + "description": "Scaling parameter." + }, + { + "name": "beta", + "type": "float32", + "required": false, + "default": 0.75, + "description": "The exponent." + }, + { + "name": "bias", + "type": "float32", + "required": false, + "default": 1.0, + "description": "" + }, + { + "name": "size", + "type": "int64", + "required": true, + "description": "The number of channels to sum over" + } + ], + "inputs": [ + { + "name": "X", + "type": "T", + "description": "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 ...]." + } + ], + "min_input": 1, + "max_input": 1, + "outputs": [ + { + "name": "Y", + "type": "T", + "description": "Output tensor, which has the shape and type as input tensor" + } + ], + "min_output": 1, + "max_output": 1, + "type_constraints": [ + { + "description": "Constrain input and output types to float tensors.", + "type_param_str": "T", + "allowed_type_strs": [ + "tensor(float16)", + "tensor(float)", + "tensor(double)" + ] + } + ], + "examples": [ + { + "summary": "default", + "code": "alpha = 0.0001\nbeta = 0.75\nbias = 1.0\nnsize = 3\nnode = onnx.helper.make_node(\n 'LRN',\n inputs=['x'],\n outputs=['y'],\n size=3\n)\nx = np.random.randn(5, 5, 5, 5).astype(np.float32)\nsquare_sum = np.zeros((5, 5, 5, 5)).astype(np.float32)\nfor n, c, h, w in np.ndindex(x.shape):\n square_sum[n, c, h, w] = sum(x[n,\n max(0, c - int(math.floor((nsize - 1) / 2))):min(5, c + int(math.ceil((nsize - 1) / 2)) + 1),\n h,\n w] ** 2)\ny = x / ((bias + (alpha / nsize) * square_sum) ** beta)\nexpect(node, inputs=[x], outputs=[y],\n name='test_lrn_default')" + }, + { + "summary": "lrn", + "code": "alpha = 0.0002\nbeta = 0.5\nbias = 2.0\nnsize = 3\nnode = onnx.helper.make_node(\n 'LRN',\n inputs=['x'],\n outputs=['y'],\n alpha=alpha,\n beta=beta,\n bias=bias,\n size=nsize\n)\nx = np.random.randn(5, 5, 5, 5).astype(np.float32)\nsquare_sum = np.zeros((5, 5, 5, 5)).astype(np.float32)\nfor n, c, h, w in np.ndindex(x.shape):\n square_sum[n, c, h, w] = sum(x[n,\n max(0, c - int(math.floor((nsize - 1) / 2))):min(5, c + int(math.ceil((nsize - 1) / 2)) + 1),\n h,\n w] ** 2)\ny = x / ((bias + (alpha / nsize) * square_sum) ** beta)\nexpect(node, inputs=[x], outputs=[y],\n name='test_lrn')" + } + ], + "category": "Normalization" + }, + { + "name": "LRN", + "module": "ai.onnx", + "version": 13, + "support_level": "common", + "description": "Local Response Normalization proposed in the [AlexNet paper](https://papers.nips.cc/paper/4824-imagenet-classification-with-deep-convolutional-neural-networks.pdf).\nIt normalizes over local input regions.\nThe local region is defined across the channels. For an element X[n, c, d1, ..., dk] in a tensor\nof shape (N x C x D1 x D2, ..., Dk), its region is\n{X[n, i, d1, ..., dk] | max(0, c - floor((size - 1) / 2)) <= i <= min(C - 1, c + ceil((size - 1) / 2))}.\n\nsquare_sum[n, c, d1, ..., dk] = sum(X[n, i, d1, ..., dk] ^ 2),\nwhere max(0, c - floor((size - 1) / 2)) <= i <= min(C - 1, c + ceil((size - 1) / 2)).\n\nY[n, c, d1, ..., dk] = X[n, c, d1, ..., dk] / (bias + alpha / size * square_sum[n, c, d1, ..., dk] ) ^ beta\n", + "attributes": [ + { + "name": "alpha", + "type": "float32", + "required": false, + "default": 9.999999747378752e-05, + "description": "Scaling parameter." + }, + { + "name": "beta", + "type": "float32", + "required": false, + "default": 0.75, + "description": "The exponent." + }, + { + "name": "bias", + "type": "float32", + "required": false, + "default": 1.0, + "description": "" + }, + { + "name": "size", + "type": "int64", + "required": true, + "description": "The number of channels to sum over" + } + ], + "inputs": [ + { + "name": "X", + "type": "T", + "description": "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 ...]." + } + ], + "min_input": 1, + "max_input": 1, + "outputs": [ + { + "name": "Y", + "type": "T", + "description": "Output tensor, which has the shape and type as input tensor" + } + ], + "min_output": 1, + "max_output": 1, + "type_constraints": [ + { + "description": "Constrain input and output types to float tensors.", + "type_param_str": "T", + "allowed_type_strs": [ + "tensor(float16)", + "tensor(float)", + "tensor(double)", + "tensor(bfloat16)" + ] + } + ], + "examples": [ + { + "summary": "default", + "code": "alpha = 0.0001\nbeta = 0.75\nbias = 1.0\nnsize = 3\nnode = onnx.helper.make_node(\n 'LRN',\n inputs=['x'],\n outputs=['y'],\n size=3\n)\nx = np.random.randn(5, 5, 5, 5).astype(np.float32)\nsquare_sum = np.zeros((5, 5, 5, 5)).astype(np.float32)\nfor n, c, h, w in np.ndindex(x.shape):\n square_sum[n, c, h, w] = sum(x[n,\n max(0, c - int(math.floor((nsize - 1) / 2))):min(5, c + int(math.ceil((nsize - 1) / 2)) + 1),\n h,\n w] ** 2)\ny = x / ((bias + (alpha / nsize) * square_sum) ** beta)\nexpect(node, inputs=[x], outputs=[y],\n name='test_lrn_default')" + }, + { + "summary": "lrn", + "code": "alpha = 0.0002\nbeta = 0.5\nbias = 2.0\nnsize = 3\nnode = onnx.helper.make_node(\n 'LRN',\n inputs=['x'],\n outputs=['y'],\n alpha=alpha,\n beta=beta,\n bias=bias,\n size=nsize\n)\nx = np.random.randn(5, 5, 5, 5).astype(np.float32)\nsquare_sum = np.zeros((5, 5, 5, 5)).astype(np.float32)\nfor n, c, h, w in np.ndindex(x.shape):\n square_sum[n, c, h, w] = sum(x[n,\n max(0, c - int(math.floor((nsize - 1) / 2))):min(5, c + int(math.ceil((nsize - 1) / 2)) + 1),\n h,\n w] ** 2)\ny = x / ((bias + (alpha / nsize) * square_sum) ** beta)\nexpect(node, inputs=[x], outputs=[y],\n name='test_lrn')" + } + ], + "category": "Normalization" + }, + { + "name": "LSTM", + "module": "ai.onnx", + "version": 1, + "support_level": "common", + "description": "Computes an one-layer LSTM. This operator is usually supported via some\ncustom implementation such as CuDNN.\n\nNotations:\n\n`X` - input tensor\n\n`i` - input gate\n\n`o` - output gate\n\n`f` - forget gate\n\n`c` - cell gate\n\n`t` - time step (t-1 means previous time step)\n\n`W[iofc]` - W parameter weight matrix for input, output, forget, and cell gates\n\n`R[iofc]` - R recurrence weight matrix for input, output, forget, and cell gates\n\n`Wb[iofc]` - W bias vectors for input, output, forget, and cell gates\n\n`Rb[iofc]` - R bias vectors for input, output, forget, and cell gates\n\n`P[iof]` - P peephole weight vector for input, output, and forget gates\n\n`WB[iofc]` - W parameter weight matrix for backward input, output, forget, and cell gates\n\n`RB[iofc]` - R recurrence weight matrix for backward input, output, forget, and cell gates\n\n`WBb[iofc]` - W bias vectors for backward input, output, forget, and cell gates\n\n`RBb[iofc]` - R bias vectors for backward input, output, forget, and cell gates\n\n`PB[iof]` - P peephole weight vector for backward input, output, and forget gates\n\n`H` - Hidden state\n\n`num_directions` - 2 if direction == bidirectional else 1\n\nActivation functions:\n\n Relu(x) - max(0, x)\n\n Tanh(x) - (1 - e^{-2x})/(1 + e^{-2x})\n\n Sigmoid(x) - 1/(1 + e^{-x})\n\n (NOTE: Below are optional)\n\n Affine(x) - alpha*x + beta\n\n LeakyRelu(x) - x if x >= 0 else alpha * x\n\n ThresholdedRelu(x) - x if x >= alpha else 0\n\n ScaledTanh(x) - alpha*Tanh(beta*x)\n\n HardSigmoid(x) - min(max(alpha*x + beta, 0), 1)\n\n Elu(x) - x if x >= 0 else alpha*(e^x - 1)\n\n Softsign(x) - x/(1 + |x|)\n\n Softplus(x) - log(1 + e^x)\n\nEquations (Default: f=Sigmoid, g=Tanh, h=Tanh):\n\n - it = f(Xt*(Wi^T) + Ht-1*Ri + Pi (.) Ct-1 + Wbi + Rbi)\n\n - ft = f(Xt*(Wf^T) + Ht-1*Rf + Pf (.) Ct-1 + Wbf + Rbf)\n\n - ct = g(Xt*(Wc^T) + Ht-1*Rc + Wbc + Rbc)\n\n - Ct = ft (.) Ct-1 + it (.) ct\n\n - ot = f(Xt*(Wo^T) + Ht-1*Ro + Po (.) Ct + Wbo + Rbo)\n\n - Ht = ot (.) h(Ct)\n", + "attributes": [ + { + "name": "activation_alpha", + "type": "float32[]", + "required": false, + "description": "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." + }, + { + "name": "activation_beta", + "type": "float32[]", + "required": false, + "description": "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." + }, + { + "name": "activations", + "type": "string[]", + "required": false, + "description": "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." + }, + { + "name": "clip", + "type": "float32", + "required": false, + "description": "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." + }, + { + "name": "direction", + "type": "string", + "required": false, + "default": "forward", + "description": "Specify if the RNN is forward, reverse, or bidirectional. Must be one of forward (default), reverse, or bidirectional." + }, + { + "name": "hidden_size", + "type": "int64", + "required": false, + "description": "Number of neurons in the hidden layer" + }, + { + "name": "input_forget", + "type": "int64", + "required": false, + "description": "Couple the input and forget gates if 1, default 0." + }, + { + "name": "output_sequence", + "type": "int64", + "required": false, + "description": "The sequence output for the hidden is optional if 0. Default 0." + } + ], + "inputs": [ + { + "name": "X", + "type": "T", + "description": "The input sequences packed (and potentially padded) into one 3-D tensor with the shape of `[seq_length, batch_size, input_size]`." + }, + { + "name": "W", + "type": "T", + "description": "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]`." + }, + { + "name": "R", + "type": "T", + "description": "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]`." + }, + { + "name": "B", + "type": "T", + "option": "optional", + "description": "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." + }, + { + "name": "sequence_lens", + "type": "T1", + "option": "optional", + "description": "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]`." + }, + { + "name": "initial_h", + "type": "T", + "option": "optional", + "description": "Optional initial value of the hidden. If not specified - assumed to be 0. It has shape `[num_directions, batch_size, hidden_size]`." + }, + { + "name": "initial_c", + "type": "T", + "option": "optional", + "description": "Optional initial value of the cell. If not specified - assumed to be 0. It has shape `[num_directions, batch_size, hidden_size]`." + }, + { + "name": "P", + "type": "T", + "option": "optional", + "description": "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." + } + ], + "min_input": 3, + "max_input": 8, + "outputs": [ + { + "name": "Y", + "type": "T", + "option": "optional", + "description": "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." + }, + { + "name": "Y_h", + "type": "T", + "option": "optional", + "description": "The last output value of the hidden. It has shape `[num_directions, batch_size, hidden_size]`." + }, + { + "name": "Y_c", + "type": "T", + "option": "optional", + "description": "The last output value of the cell. It has shape `[num_directions, batch_size, hidden_size]`." + } + ], + "min_output": 0, + "max_output": 3, + "inputs_range": "3 - 8", + "outputs_range": "0 - 3", + "type_constraints": [ + { + "description": "Constrain input and output types to float tensors.", + "type_param_str": "T", + "allowed_type_strs": [ + "tensor(float16)", + "tensor(float)", + "tensor(double)" + ] + }, + { + "description": "Constrain seq_lens to integer tensor.", + "type_param_str": "T1", + "allowed_type_strs": [ + "tensor(int32)" + ] + } + ], + "examples": [ + { + "summary": "batchwise", + "code": "input = np.array([[[1., 2.]], [[3., 4.]], [[5., 6.]]]).astype(np.float32)\n\ninput_size = 2\nhidden_size = 7\nweight_scale = 0.3\nnumber_of_gates = 4\nlayout = 1\n\nnode = onnx.helper.make_node(\n 'LSTM',\n inputs=['X', 'W', 'R'],\n outputs=['Y', 'Y_h'],\n hidden_size=hidden_size,\n layout=layout\n)\n\nW = weight_scale * np.ones((1, number_of_gates * hidden_size, input_size)).astype(np.float32)\nR = weight_scale * np.ones((1, number_of_gates * hidden_size, hidden_size)).astype(np.float32)\n\nlstm = LSTM_Helper(X=input, W=W, R=R, layout=layout)\nY, Y_h = lstm.step()\nexpect(node, inputs=[input, W, R], outputs=[Y.astype(np.float32), Y_h.astype(np.float32)], name='test_lstm_batchwise')" + }, + { + "summary": "defaults", + "code": "input = np.array([[[1., 2.], [3., 4.], [5., 6.]]]).astype(np.float32)\n\ninput_size = 2\nhidden_size = 3\nweight_scale = 0.1\nnumber_of_gates = 4\n\nnode = onnx.helper.make_node(\n 'LSTM',\n inputs=['X', 'W', 'R'],\n outputs=['', 'Y_h'],\n hidden_size=hidden_size\n)\n\nW = weight_scale * np.ones((1, number_of_gates * hidden_size, input_size)).astype(np.float32)\nR = weight_scale * np.ones((1, number_of_gates * hidden_size, hidden_size)).astype(np.float32)\n\nlstm = LSTM_Helper(X=input, W=W, R=R)\n_, Y_h = lstm.step()\nexpect(node, inputs=[input, W, R], outputs=[Y_h.astype(np.float32)], name='test_lstm_defaults')" + }, + { + "summary": "initial_bias", + "code": "input = np.array([[[1., 2., 3.], [4., 5., 6.], [7., 8., 9.]]]).astype(np.float32)\n\ninput_size = 3\nhidden_size = 4\nweight_scale = 0.1\ncustom_bias = 0.1\nnumber_of_gates = 4\n\nnode = onnx.helper.make_node(\n 'LSTM',\n inputs=['X', 'W', 'R', 'B'],\n outputs=['', 'Y_h'],\n hidden_size=hidden_size\n)\n\nW = weight_scale * np.ones((1, number_of_gates * hidden_size, input_size)).astype(np.float32)\nR = weight_scale * np.ones((1, number_of_gates * hidden_size, hidden_size)).astype(np.float32)\n\n# Adding custom bias\nW_B = custom_bias * np.ones((1, number_of_gates * hidden_size)).astype(np.float32)\nR_B = np.zeros((1, number_of_gates * hidden_size)).astype(np.float32)\nB = np.concatenate((W_B, R_B), 1)\n\nlstm = LSTM_Helper(X=input, W=W, R=R, B=B)\n_, Y_h = lstm.step()\nexpect(node, inputs=[input, W, R, B], outputs=[Y_h.astype(np.float32)], name='test_lstm_with_initial_bias')" + }, + { + "summary": "peepholes", + "code": "input = np.array([[[1., 2., 3., 4.], [5., 6., 7., 8.]]]).astype(np.float32)\n\ninput_size = 4\nhidden_size = 3\nweight_scale = 0.1\nnumber_of_gates = 4\nnumber_of_peepholes = 3\n\nnode = onnx.helper.make_node(\n 'LSTM',\n inputs=['X', 'W', 'R', 'B', 'sequence_lens', 'initial_h', 'initial_c', 'P'],\n outputs=['', 'Y_h'],\n hidden_size=hidden_size\n)\n\n# Initializing Inputs\nW = weight_scale * np.ones((1, number_of_gates * hidden_size, input_size)).astype(np.float32)\nR = weight_scale * np.ones((1, number_of_gates * hidden_size, hidden_size)).astype(np.float32)\nB = np.zeros((1, 2 * number_of_gates * hidden_size)).astype(np.float32)\nseq_lens = np.repeat(input.shape[0], input.shape[1]).astype(np.int32)\ninit_h = np.zeros((1, input.shape[1], hidden_size)).astype(np.float32)\ninit_c = np.zeros((1, input.shape[1], hidden_size)).astype(np.float32)\nP = weight_scale * np.ones((1, number_of_peepholes * hidden_size)).astype(np.float32)\n\nlstm = LSTM_Helper(X=input, W=W, R=R, B=B, P=P, initial_c=init_c, initial_h=init_h)\n_, Y_h = lstm.step()\nexpect(node, inputs=[input, W, R, B, seq_lens, init_h, init_c, P], outputs=[Y_h.astype(np.float32)],\n name='test_lstm_with_peepholes')" + } + ], + "category": "Layer" + }, + { + "name": "LSTM", + "module": "ai.onnx", + "version": 7, + "support_level": "common", + "description": "Computes an one-layer LSTM. This operator is usually supported via some\ncustom implementation such as CuDNN.\n\nNotations:\n\n`X` - input tensor\n\n`i` - input gate\n\n`o` - output gate\n\n`f` - forget gate\n\n`c` - cell gate\n\n`t` - time step (t-1 means previous time step)\n\n`W[iofc]` - W parameter weight matrix for input, output, forget, and cell gates\n\n`R[iofc]` - R recurrence weight matrix for input, output, forget, and cell gates\n\n`Wb[iofc]` - W bias vectors for input, output, forget, and cell gates\n\n`Rb[iofc]` - R bias vectors for input, output, forget, and cell gates\n\n`P[iof]` - P peephole weight vector for input, output, and forget gates\n\n`WB[iofc]` - W parameter weight matrix for backward input, output, forget, and cell gates\n\n`RB[iofc]` - R recurrence weight matrix for backward input, output, forget, and cell gates\n\n`WBb[iofc]` - W bias vectors for backward input, output, forget, and cell gates\n\n`RBb[iofc]` - R bias vectors for backward input, output, forget, and cell gates\n\n`PB[iof]` - P peephole weight vector for backward input, output, and forget gates\n\n`H` - Hidden state\n\n`num_directions` - 2 if direction == bidirectional else 1\n\nActivation functions:\n\n Relu(x) - max(0, x)\n\n Tanh(x) - (1 - e^{-2x})/(1 + e^{-2x})\n\n Sigmoid(x) - 1/(1 + e^{-x})\n\n (NOTE: Below are optional)\n\n Affine(x) - alpha*x + beta\n\n LeakyRelu(x) - x if x >= 0 else alpha * x\n\n ThresholdedRelu(x) - x if x >= alpha else 0\n\n ScaledTanh(x) - alpha*Tanh(beta*x)\n\n HardSigmoid(x) - min(max(alpha*x + beta, 0), 1)\n\n Elu(x) - x if x >= 0 else alpha*(e^x - 1)\n\n Softsign(x) - x/(1 + |x|)\n\n Softplus(x) - log(1 + e^x)\n\nEquations (Default: f=Sigmoid, g=Tanh, h=Tanh):\n\n - it = f(Xt*(Wi^T) + Ht-1*(Ri^T) + Pi (.) Ct-1 + Wbi + Rbi)\n\n - ft = f(Xt*(Wf^T) + Ht-1*(Rf^T) + Pf (.) Ct-1 + Wbf + Rbf)\n\n - ct = g(Xt*(Wc^T) + Ht-1*(Rc^T) + Wbc + Rbc)\n\n - Ct = ft (.) Ct-1 + it (.) ct\n\n - ot = f(Xt*(Wo^T) + Ht-1*(Ro^T) + Po (.) Ct + Wbo + Rbo)\n\n - Ht = ot (.) h(Ct)\nThis operator has **optional** inputs/outputs. See [the doc](https://github.com/onnx/onnx/blob/master/docs/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.\n", + "attributes": [ + { + "name": "activation_alpha", + "type": "float32[]", + "required": false, + "description": "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." + }, + { + "name": "activation_beta", + "type": "float32[]", + "required": false, + "description": "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." + }, + { + "name": "activations", + "type": "string[]", + "required": false, + "description": "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." + }, + { + "name": "clip", + "type": "float32", + "required": false, + "description": "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." + }, + { + "name": "direction", + "type": "string", + "required": false, + "default": "forward", + "description": "Specify if the RNN is forward, reverse, or bidirectional. Must be one of forward (default), reverse, or bidirectional." + }, + { + "name": "hidden_size", + "type": "int64", + "required": false, + "description": "Number of neurons in the hidden layer" + }, + { + "name": "input_forget", + "type": "int64", + "required": false, + "description": "Couple the input and forget gates if 1." + } + ], + "inputs": [ + { + "name": "X", + "type": "T", + "description": "The input sequences packed (and potentially padded) into one 3-D tensor with the shape of `[seq_length, batch_size, input_size]`." + }, + { + "name": "W", + "type": "T", + "description": "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]`." + }, + { + "name": "R", + "type": "T", + "description": "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]`." + }, + { + "name": "B", + "type": "T", + "option": "optional", + "description": "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." + }, + { + "name": "sequence_lens", + "type": "T1", + "option": "optional", + "description": "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]`." + }, + { + "name": "initial_h", + "type": "T", + "option": "optional", + "description": "Optional initial value of the hidden. If not specified - assumed to be 0. It has shape `[num_directions, batch_size, hidden_size]`." + }, + { + "name": "initial_c", + "type": "T", + "option": "optional", + "description": "Optional initial value of the cell. If not specified - assumed to be 0. It has shape `[num_directions, batch_size, hidden_size]`." + }, + { + "name": "P", + "type": "T", + "option": "optional", + "description": "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." + } + ], + "min_input": 3, + "max_input": 8, + "outputs": [ + { + "name": "Y", + "type": "T", + "option": "optional", + "description": "A tensor that concats all the intermediate output values of the hidden. It has shape `[seq_length, num_directions, batch_size, hidden_size]`. " + }, + { + "name": "Y_h", + "type": "T", + "option": "optional", + "description": "The last output value of the hidden. It has shape `[num_directions, batch_size, hidden_size]`." + }, + { + "name": "Y_c", + "type": "T", + "option": "optional", + "description": "The last output value of the cell. It has shape `[num_directions, batch_size, hidden_size]`." + } + ], + "min_output": 0, + "max_output": 3, + "inputs_range": "3 - 8", + "outputs_range": "0 - 3", + "type_constraints": [ + { + "description": "Constrain input and output types to float tensors.", + "type_param_str": "T", + "allowed_type_strs": [ + "tensor(float16)", + "tensor(float)", + "tensor(double)" + ] + }, + { + "description": "Constrain seq_lens to integer tensor.", + "type_param_str": "T1", + "allowed_type_strs": [ + "tensor(int32)" + ] + } + ], + "examples": [ + { + "summary": "batchwise", + "code": "input = np.array([[[1., 2.]], [[3., 4.]], [[5., 6.]]]).astype(np.float32)\n\ninput_size = 2\nhidden_size = 7\nweight_scale = 0.3\nnumber_of_gates = 4\nlayout = 1\n\nnode = onnx.helper.make_node(\n 'LSTM',\n inputs=['X', 'W', 'R'],\n outputs=['Y', 'Y_h'],\n hidden_size=hidden_size,\n layout=layout\n)\n\nW = weight_scale * np.ones((1, number_of_gates * hidden_size, input_size)).astype(np.float32)\nR = weight_scale * np.ones((1, number_of_gates * hidden_size, hidden_size)).astype(np.float32)\n\nlstm = LSTM_Helper(X=input, W=W, R=R, layout=layout)\nY, Y_h = lstm.step()\nexpect(node, inputs=[input, W, R], outputs=[Y.astype(np.float32), Y_h.astype(np.float32)], name='test_lstm_batchwise')" + }, + { + "summary": "defaults", + "code": "input = np.array([[[1., 2.], [3., 4.], [5., 6.]]]).astype(np.float32)\n\ninput_size = 2\nhidden_size = 3\nweight_scale = 0.1\nnumber_of_gates = 4\n\nnode = onnx.helper.make_node(\n 'LSTM',\n inputs=['X', 'W', 'R'],\n outputs=['', 'Y_h'],\n hidden_size=hidden_size\n)\n\nW = weight_scale * np.ones((1, number_of_gates * hidden_size, input_size)).astype(np.float32)\nR = weight_scale * np.ones((1, number_of_gates * hidden_size, hidden_size)).astype(np.float32)\n\nlstm = LSTM_Helper(X=input, W=W, R=R)\n_, Y_h = lstm.step()\nexpect(node, inputs=[input, W, R], outputs=[Y_h.astype(np.float32)], name='test_lstm_defaults')" + }, + { + "summary": "initial_bias", + "code": "input = np.array([[[1., 2., 3.], [4., 5., 6.], [7., 8., 9.]]]).astype(np.float32)\n\ninput_size = 3\nhidden_size = 4\nweight_scale = 0.1\ncustom_bias = 0.1\nnumber_of_gates = 4\n\nnode = onnx.helper.make_node(\n 'LSTM',\n inputs=['X', 'W', 'R', 'B'],\n outputs=['', 'Y_h'],\n hidden_size=hidden_size\n)\n\nW = weight_scale * np.ones((1, number_of_gates * hidden_size, input_size)).astype(np.float32)\nR = weight_scale * np.ones((1, number_of_gates * hidden_size, hidden_size)).astype(np.float32)\n\n# Adding custom bias\nW_B = custom_bias * np.ones((1, number_of_gates * hidden_size)).astype(np.float32)\nR_B = np.zeros((1, number_of_gates * hidden_size)).astype(np.float32)\nB = np.concatenate((W_B, R_B), 1)\n\nlstm = LSTM_Helper(X=input, W=W, R=R, B=B)\n_, Y_h = lstm.step()\nexpect(node, inputs=[input, W, R, B], outputs=[Y_h.astype(np.float32)], name='test_lstm_with_initial_bias')" + }, + { + "summary": "peepholes", + "code": "input = np.array([[[1., 2., 3., 4.], [5., 6., 7., 8.]]]).astype(np.float32)\n\ninput_size = 4\nhidden_size = 3\nweight_scale = 0.1\nnumber_of_gates = 4\nnumber_of_peepholes = 3\n\nnode = onnx.helper.make_node(\n 'LSTM',\n inputs=['X', 'W', 'R', 'B', 'sequence_lens', 'initial_h', 'initial_c', 'P'],\n outputs=['', 'Y_h'],\n hidden_size=hidden_size\n)\n\n# Initializing Inputs\nW = weight_scale * np.ones((1, number_of_gates * hidden_size, input_size)).astype(np.float32)\nR = weight_scale * np.ones((1, number_of_gates * hidden_size, hidden_size)).astype(np.float32)\nB = np.zeros((1, 2 * number_of_gates * hidden_size)).astype(np.float32)\nseq_lens = np.repeat(input.shape[0], input.shape[1]).astype(np.int32)\ninit_h = np.zeros((1, input.shape[1], hidden_size)).astype(np.float32)\ninit_c = np.zeros((1, input.shape[1], hidden_size)).astype(np.float32)\nP = weight_scale * np.ones((1, number_of_peepholes * hidden_size)).astype(np.float32)\n\nlstm = LSTM_Helper(X=input, W=W, R=R, B=B, P=P, initial_c=init_c, initial_h=init_h)\n_, Y_h = lstm.step()\nexpect(node, inputs=[input, W, R, B, seq_lens, init_h, init_c, P], outputs=[Y_h.astype(np.float32)],\n name='test_lstm_with_peepholes')" + } + ], + "category": "Layer" + }, + { + "name": "LSTM", + "module": "ai.onnx", + "version": 14, + "support_level": "common", + "description": "Computes an one-layer LSTM. This operator is usually supported via some\ncustom implementation such as CuDNN.\n\nNotations:\n\n`X` - input tensor\n\n`i` - input gate\n\n`o` - output gate\n\n`f` - forget gate\n\n`c` - cell gate\n\n`t` - time step (t-1 means previous time step)\n\n`W[iofc]` - W parameter weight matrix for input, output, forget, and cell gates\n\n`R[iofc]` - R recurrence weight matrix for input, output, forget, and cell gates\n\n`Wb[iofc]` - W bias vectors for input, output, forget, and cell gates\n\n`Rb[iofc]` - R bias vectors for input, output, forget, and cell gates\n\n`P[iof]` - P peephole weight vector for input, output, and forget gates\n\n`WB[iofc]` - W parameter weight matrix for backward input, output, forget, and cell gates\n\n`RB[iofc]` - R recurrence weight matrix for backward input, output, forget, and cell gates\n\n`WBb[iofc]` - W bias vectors for backward input, output, forget, and cell gates\n\n`RBb[iofc]` - R bias vectors for backward input, output, forget, and cell gates\n\n`PB[iof]` - P peephole weight vector for backward input, output, and forget gates\n\n`H` - Hidden state\n\n`num_directions` - 2 if direction == bidirectional else 1\n\nActivation functions:\n\n Relu(x) - max(0, x)\n\n Tanh(x) - (1 - e^{-2x})/(1 + e^{-2x})\n\n Sigmoid(x) - 1/(1 + e^{-x})\n\n (NOTE: Below are optional)\n\n Affine(x) - alpha*x + beta\n\n LeakyRelu(x) - x if x >= 0 else alpha * x\n\n ThresholdedRelu(x) - x if x >= alpha else 0\n\n ScaledTanh(x) - alpha*Tanh(beta*x)\n\n HardSigmoid(x) - min(max(alpha*x + beta, 0), 1)\n\n Elu(x) - x if x >= 0 else alpha*(e^x - 1)\n\n Softsign(x) - x/(1 + |x|)\n\n Softplus(x) - log(1 + e^x)\n\nEquations (Default: f=Sigmoid, g=Tanh, h=Tanh):\n\n - it = f(Xt*(Wi^T) + Ht-1*(Ri^T) + Pi (.) Ct-1 + Wbi + Rbi)\n\n - ft = f(Xt*(Wf^T) + Ht-1*(Rf^T) + Pf (.) Ct-1 + Wbf + Rbf)\n\n - ct = g(Xt*(Wc^T) + Ht-1*(Rc^T) + Wbc + Rbc)\n\n - Ct = ft (.) Ct-1 + it (.) ct\n\n - ot = f(Xt*(Wo^T) + Ht-1*(Ro^T) + Po (.) Ct + Wbo + Rbo)\n\n - Ht = ot (.) h(Ct)\nThis operator has **optional** inputs/outputs. See [the doc](https://github.com/onnx/onnx/blob/master/docs/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.\n", + "attributes": [ + { + "name": "activation_alpha", + "type": "float32[]", + "required": false, + "description": "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." + }, + { + "name": "activation_beta", + "type": "float32[]", + "required": false, + "description": "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." + }, + { + "name": "activations", + "type": "string[]", + "required": false, + "description": "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." + }, + { + "name": "clip", + "type": "float32", + "required": false, + "description": "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." + }, + { + "name": "direction", + "type": "string", + "required": false, + "default": "forward", + "description": "Specify if the RNN is forward, reverse, or bidirectional. Must be one of forward (default), reverse, or bidirectional." + }, + { + "name": "hidden_size", + "type": "int64", + "required": false, + "description": "Number of neurons in the hidden layer" + }, + { + "name": "input_forget", + "type": "int64", + "required": false, + "description": "Couple the input and forget gates if 1." + }, + { + "name": "layout", + "type": "int64", + "required": false, + "description": "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 = [num_directions, batch_size, hidden_size]." + } + ], + "inputs": [ + { + "name": "X", + "type": "T", + "description": "The input sequences packed (and potentially padded) into one 3-D tensor with the shape of `[seq_length, batch_size, input_size]`." + }, + { + "name": "W", + "type": "T", + "description": "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]`." + }, + { + "name": "R", + "type": "T", + "description": "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]`." + }, + { + "name": "B", + "type": "T", + "option": "optional", + "description": "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." + }, + { + "name": "sequence_lens", + "type": "T1", + "option": "optional", + "description": "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]`." + }, + { + "name": "initial_h", + "type": "T", + "option": "optional", + "description": "Optional initial value of the hidden. If not specified - assumed to be 0. It has shape `[num_directions, batch_size, hidden_size]`." + }, + { + "name": "initial_c", + "type": "T", + "option": "optional", + "description": "Optional initial value of the cell. If not specified - assumed to be 0. It has shape `[num_directions, batch_size, hidden_size]`." + }, + { + "name": "P", + "type": "T", + "option": "optional", + "description": "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." + } + ], + "min_input": 3, + "max_input": 8, + "outputs": [ + { + "name": "Y", + "type": "T", + "option": "optional", + "description": "A tensor that concats all the intermediate output values of the hidden. It has shape `[seq_length, num_directions, batch_size, hidden_size]`. " + }, + { + "name": "Y_h", + "type": "T", + "option": "optional", + "description": "The last output value of the hidden. It has shape `[num_directions, batch_size, hidden_size]`." + }, + { + "name": "Y_c", + "type": "T", + "option": "optional", + "description": "The last output value of the cell. It has shape `[num_directions, batch_size, hidden_size]`." + } + ], + "min_output": 0, + "max_output": 3, + "inputs_range": "3 - 8", + "outputs_range": "0 - 3", + "type_constraints": [ + { + "description": "Constrain input and output types to float tensors.", + "type_param_str": "T", + "allowed_type_strs": [ + "tensor(float16)", + "tensor(float)", + "tensor(double)" + ] + }, + { + "description": "Constrain seq_lens to integer tensor.", + "type_param_str": "T1", + "allowed_type_strs": [ + "tensor(int32)" + ] + } + ], + "examples": [ + { + "summary": "batchwise", + "code": "input = np.array([[[1., 2.]], [[3., 4.]], [[5., 6.]]]).astype(np.float32)\n\ninput_size = 2\nhidden_size = 7\nweight_scale = 0.3\nnumber_of_gates = 4\nlayout = 1\n\nnode = onnx.helper.make_node(\n 'LSTM',\n inputs=['X', 'W', 'R'],\n outputs=['Y', 'Y_h'],\n hidden_size=hidden_size,\n layout=layout\n)\n\nW = weight_scale * np.ones((1, number_of_gates * hidden_size, input_size)).astype(np.float32)\nR = weight_scale * np.ones((1, number_of_gates * hidden_size, hidden_size)).astype(np.float32)\n\nlstm = LSTM_Helper(X=input, W=W, R=R, layout=layout)\nY, Y_h = lstm.step()\nexpect(node, inputs=[input, W, R], outputs=[Y.astype(np.float32), Y_h.astype(np.float32)], name='test_lstm_batchwise')" + }, + { + "summary": "defaults", + "code": "input = np.array([[[1., 2.], [3., 4.], [5., 6.]]]).astype(np.float32)\n\ninput_size = 2\nhidden_size = 3\nweight_scale = 0.1\nnumber_of_gates = 4\n\nnode = onnx.helper.make_node(\n 'LSTM',\n inputs=['X', 'W', 'R'],\n outputs=['', 'Y_h'],\n hidden_size=hidden_size\n)\n\nW = weight_scale * np.ones((1, number_of_gates * hidden_size, input_size)).astype(np.float32)\nR = weight_scale * np.ones((1, number_of_gates * hidden_size, hidden_size)).astype(np.float32)\n\nlstm = LSTM_Helper(X=input, W=W, R=R)\n_, Y_h = lstm.step()\nexpect(node, inputs=[input, W, R], outputs=[Y_h.astype(np.float32)], name='test_lstm_defaults')" + }, + { + "summary": "initial_bias", + "code": "input = np.array([[[1., 2., 3.], [4., 5., 6.], [7., 8., 9.]]]).astype(np.float32)\n\ninput_size = 3\nhidden_size = 4\nweight_scale = 0.1\ncustom_bias = 0.1\nnumber_of_gates = 4\n\nnode = onnx.helper.make_node(\n 'LSTM',\n inputs=['X', 'W', 'R', 'B'],\n outputs=['', 'Y_h'],\n hidden_size=hidden_size\n)\n\nW = weight_scale * np.ones((1, number_of_gates * hidden_size, input_size)).astype(np.float32)\nR = weight_scale * np.ones((1, number_of_gates * hidden_size, hidden_size)).astype(np.float32)\n\n# Adding custom bias\nW_B = custom_bias * np.ones((1, number_of_gates * hidden_size)).astype(np.float32)\nR_B = np.zeros((1, number_of_gates * hidden_size)).astype(np.float32)\nB = np.concatenate((W_B, R_B), 1)\n\nlstm = LSTM_Helper(X=input, W=W, R=R, B=B)\n_, Y_h = lstm.step()\nexpect(node, inputs=[input, W, R, B], outputs=[Y_h.astype(np.float32)], name='test_lstm_with_initial_bias')" + }, + { + "summary": "peepholes", + "code": "input = np.array([[[1., 2., 3., 4.], [5., 6., 7., 8.]]]).astype(np.float32)\n\ninput_size = 4\nhidden_size = 3\nweight_scale = 0.1\nnumber_of_gates = 4\nnumber_of_peepholes = 3\n\nnode = onnx.helper.make_node(\n 'LSTM',\n inputs=['X', 'W', 'R', 'B', 'sequence_lens', 'initial_h', 'initial_c', 'P'],\n outputs=['', 'Y_h'],\n hidden_size=hidden_size\n)\n\n# Initializing Inputs\nW = weight_scale * np.ones((1, number_of_gates * hidden_size, input_size)).astype(np.float32)\nR = weight_scale * np.ones((1, number_of_gates * hidden_size, hidden_size)).astype(np.float32)\nB = np.zeros((1, 2 * number_of_gates * hidden_size)).astype(np.float32)\nseq_lens = np.repeat(input.shape[0], input.shape[1]).astype(np.int32)\ninit_h = np.zeros((1, input.shape[1], hidden_size)).astype(np.float32)\ninit_c = np.zeros((1, input.shape[1], hidden_size)).astype(np.float32)\nP = weight_scale * np.ones((1, number_of_peepholes * hidden_size)).astype(np.float32)\n\nlstm = LSTM_Helper(X=input, W=W, R=R, B=B, P=P, initial_c=init_c, initial_h=init_h)\n_, Y_h = lstm.step()\nexpect(node, inputs=[input, W, R, B, seq_lens, init_h, init_c, P], outputs=[Y_h.astype(np.float32)],\n name='test_lstm_with_peepholes')" + } + ], + "category": "Layer" + }, + { + "name": "LabelEncoder", + "module": "ai.onnx.ml", + "version": 1, + "support_level": "common", + "description": "Converts strings to integers and vice versa.
\n If the string default value is set, it will convert integers to strings.\n If the int default value is set, it will convert strings to integers.
\n Each operator converts either integers to strings or strings to integers, depending\n on which default value attribute is provided. Only one default value attribute\n should be defined.
\n When converting from integers to strings, the string is fetched from the\n 'classes_strings' list, by simple indexing.
\n When converting from strings to integers, the string is looked up in the list\n and the index at which it is found is used as the converted value.\n", + "attributes": [ + { + "name": "classes_strings", + "type": "string[]", + "required": false, + "description": "A list of labels." + }, + { + "name": "default_int64", + "type": "int64", + "required": false, + "default": -1, + "description": "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." + }, + { + "name": "default_string", + "type": "string", + "required": false, + "default": "_Unused", + "description": "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": [ + { + "name": "X", + "type": "T1", + "description": "Input data." + } + ], + "min_input": 1, + "max_input": 1, + "outputs": [ + { + "name": "Y", + "type": "T2", + "description": "Output data. If strings are input, the output values are integers, and vice versa." + } + ], + "min_output": 1, + "max_output": 1, + "type_constraints": [ + { + "description": "The input type must be a tensor of integers or strings, of any shape.", + "type_param_str": "T1", + "allowed_type_strs": [ + "tensor(string)", + "tensor(int64)" + ] + }, + { + "description": "The output type will be a tensor of strings or integers, and will have the same shape as the input.", + "type_param_str": "T2", + "allowed_type_strs": [ + "tensor(string)", + "tensor(int64)" + ] + } + ] + }, + { + "name": "LabelEncoder", + "module": "ai.onnx.ml", + "version": 2, + "support_level": "common", + "description": "Maps each element in the input tensor to another value.
\n The mapping is determined by the two parallel attributes, 'keys_*' and\n 'values_*' attribute. The i-th value in the specified 'keys_*' attribute\n would be mapped to the i-th value in the specified 'values_*' attribute. It\n implies that input's element type and the element type of the specified\n 'keys_*' should be identical while the output type is identical to the\n specified 'values_*' attribute. If an input element can not be found in the\n specified 'keys_*' attribute, the 'default_*' that matches the specified\n 'values_*' attribute may be used as its output value.
\n Let's consider an example which maps a string tensor to an integer tensor.\n Assume and 'keys_strings' is [\"Amy\", \"Sally\"], 'values_int64s' is [5, 6],\n and 'default_int64' is '-1'. The input [\"Dori\", \"Amy\", \"Amy\", \"Sally\",\n \"Sally\"] would be mapped to [-1, 5, 5, 6, 6].
\n Since this operator is an one-to-one mapping, its input and output shapes\n are the same. Notice that only one of 'keys_*'/'values_*' can be set.
\n For key look-up, bit-wise comparison is used so even a float NaN can be\n mapped to a value in 'values_*' attribute.
\n", + "attributes": [ + { + "name": "default_float", + "type": "float32", + "required": false, + "description": "A float." + }, + { + "name": "default_int64", + "type": "int64", + "required": false, + "default": -1, + "description": "An integer." + }, + { + "name": "default_string", + "type": "string", + "required": false, + "default": "_Unused", + "description": "A string." + }, + { + "name": "keys_floats", + "type": "float32[]", + "required": false, + "description": "A list of floats." + }, + { + "name": "keys_int64s", + "type": "int64[]", + "required": false, + "description": "A list of ints." + }, + { + "name": "keys_strings", + "type": "string[]", + "required": false, + "description": "A list of strings. One and only one of 'keys_*'s should be set." + }, + { + "name": "values_floats", + "type": "float32[]", + "required": false, + "description": "A list of floats." + }, + { + "name": "values_int64s", + "type": "int64[]", + "required": false, + "description": "A list of ints." + }, + { + "name": "values_strings", + "type": "string[]", + "required": false, + "description": "A list of strings. One and only one of 'value_*'s should be set." + } + ], + "inputs": [ + { + "name": "X", + "type": "T1", + "description": "Input data. It can be either tensor or scalar." + } + ], + "min_input": 1, + "max_input": 1, + "outputs": [ + { + "name": "Y", + "type": "T2", + "description": "Output data." + } + ], + "min_output": 1, + "max_output": 1, + "type_constraints": [ + { + "description": "The input type is a tensor of any shape.", + "type_param_str": "T1", + "allowed_type_strs": [ + "tensor(string)", + "tensor(int64)", + "tensor(float)" + ] + }, + { + "description": "Output type is determined by the specified 'values_*' attribute.", + "type_param_str": "T2", + "allowed_type_strs": [ + "tensor(string)", + "tensor(int64)", + "tensor(float)" + ] + } + ] + }, + { + "name": "LeakyRelu", + "module": "ai.onnx", + "version": 1, + "support_level": "common", + "description": "LeakyRelu takes input data (Tensor) and an argument alpha, and produces one\noutput data (Tensor) where the function `f(x) = alpha * x for x < 0`,\n`f(x) = x for x >= 0`, is applied to the data tensor elementwise.\n", + "attributes": [ + { + "name": "alpha", + "type": "float32", + "required": false, + "default": 0.009999999776482582, + "description": "Coefficient of leakage default to 0.01." + }, + { + "name": "consumed_inputs", + "type": "int64[]", + "required": false, + "description": "legacy optimization attribute." + } + ], + "inputs": [ + { + "name": "X", + "type": "T", + "description": "Input tensor" + } + ], + "min_input": 1, + "max_input": 1, + "outputs": [ + { + "name": "Y", + "type": "T", + "description": "Output tensor" + } + ], + "min_output": 1, + "max_output": 1, + "type_constraints": [ + { + "description": "Constrain input and output types to float tensors.", + "type_param_str": "T", + "allowed_type_strs": [ + "tensor(float16)", + "tensor(float)", + "tensor(double)" + ] + } + ], + "examples": [ + { + "summary": "leakyrelu", + "code": "node = onnx.helper.make_node(\n 'LeakyRelu',\n inputs=['x'],\n outputs=['y'],\n alpha=0.1\n)\n\nx = np.array([-1, 0, 1]).astype(np.float32)\n# expected output [-0.1, 0., 1.]\ny = np.clip(x, 0, np.inf) + np.clip(x, -np.inf, 0) * 0.1\nexpect(node, inputs=[x], outputs=[y],\n name='test_leakyrelu_example')\n\nx = np.random.randn(3, 4, 5).astype(np.float32)\ny = np.clip(x, 0, np.inf) + np.clip(x, -np.inf, 0) * 0.1\nexpect(node, inputs=[x], outputs=[y],\n name='test_leakyrelu')" + }, + { + "summary": "leakyrelu_default", + "code": "default_alpha = 0.01\nnode = onnx.helper.make_node(\n 'LeakyRelu',\n inputs=['x'],\n outputs=['y'],\n)\nx = np.random.randn(3, 4, 5).astype(np.float32)\ny = np.clip(x, 0, np.inf) + np.clip(x, -np.inf, 0) * default_alpha\nexpect(node, inputs=[x], outputs=[y],\n name='test_leakyrelu_default')" + } + ], + "category": "Activation" + }, + { + "name": "LeakyRelu", + "module": "ai.onnx", + "version": 6, + "support_level": "common", + "description": "LeakyRelu takes input data (Tensor) and an argument alpha, and produces one\noutput data (Tensor) where the function `f(x) = alpha * x for x < 0`,\n`f(x) = x for x >= 0`, is applied to the data tensor elementwise.\n", + "attributes": [ + { + "name": "alpha", + "type": "float32", + "required": false, + "default": 0.009999999776482582, + "description": "Coefficient of leakage." + } + ], + "inputs": [ + { + "name": "X", + "type": "T", + "description": "Input tensor" + } + ], + "min_input": 1, + "max_input": 1, + "outputs": [ + { + "name": "Y", + "type": "T", + "description": "Output tensor" + } + ], + "min_output": 1, + "max_output": 1, + "type_constraints": [ + { + "description": "Constrain input and output types to float tensors.", + "type_param_str": "T", + "allowed_type_strs": [ + "tensor(float16)", + "tensor(float)", + "tensor(double)" + ] + } + ], + "examples": [ + { + "summary": "leakyrelu", + "code": "node = onnx.helper.make_node(\n 'LeakyRelu',\n inputs=['x'],\n outputs=['y'],\n alpha=0.1\n)\n\nx = np.array([-1, 0, 1]).astype(np.float32)\n# expected output [-0.1, 0., 1.]\ny = np.clip(x, 0, np.inf) + np.clip(x, -np.inf, 0) * 0.1\nexpect(node, inputs=[x], outputs=[y],\n name='test_leakyrelu_example')\n\nx = np.random.randn(3, 4, 5).astype(np.float32)\ny = np.clip(x, 0, np.inf) + np.clip(x, -np.inf, 0) * 0.1\nexpect(node, inputs=[x], outputs=[y],\n name='test_leakyrelu')" + }, + { + "summary": "leakyrelu_default", + "code": "default_alpha = 0.01\nnode = onnx.helper.make_node(\n 'LeakyRelu',\n inputs=['x'],\n outputs=['y'],\n)\nx = np.random.randn(3, 4, 5).astype(np.float32)\ny = np.clip(x, 0, np.inf) + np.clip(x, -np.inf, 0) * default_alpha\nexpect(node, inputs=[x], outputs=[y],\n name='test_leakyrelu_default')" + } + ], + "category": "Activation" + }, + { + "name": "Less", + "module": "ai.onnx", + "version": 1, + "support_level": "common", + "description": "Returns the tensor resulted from performing the `less` logical operation\nelementwise on the input tensors `A` and `B`.\n\nIf broadcasting is enabled, the right-hand-side argument will be broadcasted\nto match the shape of left-hand-side argument. See the doc of `Add` for a\ndetailed description of the broadcasting rules.\n", + "attributes": [ + { + "name": "axis", + "type": "int64", + "required": false, + "description": "If set, defines the broadcast dimensions." + }, + { + "name": "broadcast", + "type": "int64", + "required": false, + "description": "Enable broadcasting" + } + ], + "inputs": [ + { + "name": "A", + "type": "T", + "description": "Left input tensor for the logical operator." + }, + { + "name": "B", + "type": "T", + "description": "Right input tensor for the logical operator." + } + ], + "min_input": 2, + "max_input": 2, + "outputs": [ + { + "name": "C", + "type": "T1", + "description": "Result tensor." + } + ], + "min_output": 1, + "max_output": 1, + "type_constraints": [ + { + "description": "Constrains input to float tensors.", + "type_param_str": "T", + "allowed_type_strs": [ + "tensor(float16)", + "tensor(float)", + "tensor(double)" + ] + }, + { + "description": "Constrains output to boolean tensor.", + "type_param_str": "T1", + "allowed_type_strs": [ + "tensor(bool)" + ] + } + ], + "examples": [ + { + "summary": "less", + "code": "node = onnx.helper.make_node(\n 'Less',\n inputs=['x', 'y'],\n outputs=['less'],\n)\n\nx = np.random.randn(3, 4, 5).astype(np.float32)\ny = np.random.randn(3, 4, 5).astype(np.float32)\nz = np.less(x, y)\nexpect(node, inputs=[x, y], outputs=[z],\n name='test_less')" + }, + { + "summary": "less", + "code": "node = onnx.helper.make_node(\n 'LessOrEqual',\n inputs=['x', 'y'],\n outputs=['less_equal'],\n)\n\nx = np.random.randn(3, 4, 5).astype(np.float32)\ny = np.random.randn(3, 4, 5).astype(np.float32)\nz = np.less_equal(x, y)\nexpect(node, inputs=[x, y], outputs=[z],\n name='test_less_equal')" + }, + { + "summary": "less_broadcast", + "code": "node = onnx.helper.make_node(\n 'Less',\n inputs=['x', 'y'],\n outputs=['less'],\n)\n\nx = np.random.randn(3, 4, 5).astype(np.float32)\ny = np.random.randn(5).astype(np.float32)\nz = np.less(x, y)\nexpect(node, inputs=[x, y], outputs=[z],\n name='test_less_bcast')" + }, + { + "summary": "less_broadcast", + "code": "node = onnx.helper.make_node(\n 'LessOrEqual',\n inputs=['x', 'y'],\n outputs=['less_equal'],\n)\n\nx = np.random.randn(3, 4, 5).astype(np.float32)\ny = np.random.randn(5).astype(np.float32)\nz = np.less_equal(x, y)\nexpect(node, inputs=[x, y], outputs=[z],\n name='test_less_equal_bcast')" + } + ], + "category": "Logic" + }, + { + "name": "Less", + "module": "ai.onnx", + "version": 7, + "support_level": "common", + "description": "Returns the tensor resulted from performing the `less` logical operation\nelementwise on the input tensors `A` and `B` (with Numpy-style broadcasting support).\n\nThis operator supports **multidirectional (i.e., Numpy-style) broadcasting**; for more details please check [the doc](https://github.com/onnx/onnx/blob/master/docs/Broadcasting.md).\n", + "inputs": [ + { + "name": "A", + "type": "T", + "description": "First input operand for the logical operator." + }, + { + "name": "B", + "type": "T", + "description": "Second input operand for the logical operator." + } + ], + "min_input": 2, + "max_input": 2, + "outputs": [ + { + "name": "C", + "type": "T1", + "description": "Result tensor." + } + ], + "min_output": 1, + "max_output": 1, + "type_constraints": [ + { + "description": "Constrains input to float tensors.", + "type_param_str": "T", + "allowed_type_strs": [ + "tensor(float16)", + "tensor(float)", + "tensor(double)" + ] + }, + { + "description": "Constrains output to boolean tensor.", + "type_param_str": "T1", + "allowed_type_strs": [ + "tensor(bool)" + ] + } + ], + "examples": [ + { + "summary": "less", + "code": "node = onnx.helper.make_node(\n 'Less',\n inputs=['x', 'y'],\n outputs=['less'],\n)\n\nx = np.random.randn(3, 4, 5).astype(np.float32)\ny = np.random.randn(3, 4, 5).astype(np.float32)\nz = np.less(x, y)\nexpect(node, inputs=[x, y], outputs=[z],\n name='test_less')" + }, + { + "summary": "less", + "code": "node = onnx.helper.make_node(\n 'LessOrEqual',\n inputs=['x', 'y'],\n outputs=['less_equal'],\n)\n\nx = np.random.randn(3, 4, 5).astype(np.float32)\ny = np.random.randn(3, 4, 5).astype(np.float32)\nz = np.less_equal(x, y)\nexpect(node, inputs=[x, y], outputs=[z],\n name='test_less_equal')" + }, + { + "summary": "less_broadcast", + "code": "node = onnx.helper.make_node(\n 'Less',\n inputs=['x', 'y'],\n outputs=['less'],\n)\n\nx = np.random.randn(3, 4, 5).astype(np.float32)\ny = np.random.randn(5).astype(np.float32)\nz = np.less(x, y)\nexpect(node, inputs=[x, y], outputs=[z],\n name='test_less_bcast')" + }, + { + "summary": "less_broadcast", + "code": "node = onnx.helper.make_node(\n 'LessOrEqual',\n inputs=['x', 'y'],\n outputs=['less_equal'],\n)\n\nx = np.random.randn(3, 4, 5).astype(np.float32)\ny = np.random.randn(5).astype(np.float32)\nz = np.less_equal(x, y)\nexpect(node, inputs=[x, y], outputs=[z],\n name='test_less_equal_bcast')" + } + ], + "category": "Logic" + }, + { + "name": "Less", + "module": "ai.onnx", + "version": 9, + "support_level": "common", + "description": "Returns the tensor resulted from performing the `less` logical operation\nelementwise on the input tensors `A` and `B` (with Numpy-style broadcasting support).\n\nThis operator supports **multidirectional (i.e., Numpy-style) broadcasting**; for more details please check [the doc](https://github.com/onnx/onnx/blob/master/docs/Broadcasting.md).\n", + "inputs": [ + { + "name": "A", + "type": "T", + "description": "First input operand for the logical operator." + }, + { + "name": "B", + "type": "T", + "description": "Second input operand for the logical operator." + } + ], + "min_input": 2, + "max_input": 2, + "outputs": [ + { + "name": "C", + "type": "T1", + "description": "Result tensor." + } + ], + "min_output": 1, + "max_output": 1, + "type_constraints": [ + { + "description": "Constrains input types to all numeric tensors.", + "type_param_str": "T", + "allowed_type_strs": [ + "tensor(uint8)", + "tensor(uint16)", + "tensor(uint32)", + "tensor(uint64)", + "tensor(int8)", + "tensor(int16)", + "tensor(int32)", + "tensor(int64)", + "tensor(float16)", + "tensor(float)", + "tensor(double)" + ] + }, + { + "description": "Constrains output to boolean tensor.", + "type_param_str": "T1", + "allowed_type_strs": [ + "tensor(bool)" + ] + } + ], + "examples": [ + { + "summary": "less", + "code": "node = onnx.helper.make_node(\n 'Less',\n inputs=['x', 'y'],\n outputs=['less'],\n)\n\nx = np.random.randn(3, 4, 5).astype(np.float32)\ny = np.random.randn(3, 4, 5).astype(np.float32)\nz = np.less(x, y)\nexpect(node, inputs=[x, y], outputs=[z],\n name='test_less')" + }, + { + "summary": "less", + "code": "node = onnx.helper.make_node(\n 'LessOrEqual',\n inputs=['x', 'y'],\n outputs=['less_equal'],\n)\n\nx = np.random.randn(3, 4, 5).astype(np.float32)\ny = np.random.randn(3, 4, 5).astype(np.float32)\nz = np.less_equal(x, y)\nexpect(node, inputs=[x, y], outputs=[z],\n name='test_less_equal')" + }, + { + "summary": "less_broadcast", + "code": "node = onnx.helper.make_node(\n 'Less',\n inputs=['x', 'y'],\n outputs=['less'],\n)\n\nx = np.random.randn(3, 4, 5).astype(np.float32)\ny = np.random.randn(5).astype(np.float32)\nz = np.less(x, y)\nexpect(node, inputs=[x, y], outputs=[z],\n name='test_less_bcast')" + }, + { + "summary": "less_broadcast", + "code": "node = onnx.helper.make_node(\n 'LessOrEqual',\n inputs=['x', 'y'],\n outputs=['less_equal'],\n)\n\nx = np.random.randn(3, 4, 5).astype(np.float32)\ny = np.random.randn(5).astype(np.float32)\nz = np.less_equal(x, y)\nexpect(node, inputs=[x, y], outputs=[z],\n name='test_less_equal_bcast')" + } + ], + "category": "Logic" + }, + { + "name": "Less", + "module": "ai.onnx", + "version": 13, + "support_level": "common", + "description": "Returns the tensor resulted from performing the `less` logical operation\nelementwise on the input tensors `A` and `B` (with Numpy-style broadcasting support).\n\nThis operator supports **multidirectional (i.e., Numpy-style) broadcasting**; for more details please check [the doc](https://github.com/onnx/onnx/blob/master/docs/Broadcasting.md).\n", + "inputs": [ + { + "name": "A", + "type": "T", + "description": "First input operand for the logical operator." + }, + { + "name": "B", + "type": "T", + "description": "Second input operand for the logical operator." + } + ], + "min_input": 2, + "max_input": 2, + "outputs": [ + { + "name": "C", + "type": "T1", + "description": "Result tensor." + } + ], + "min_output": 1, + "max_output": 1, + "type_constraints": [ + { + "description": "Constrains input types to all numeric tensors.", + "type_param_str": "T", + "allowed_type_strs": [ + "tensor(uint8)", + "tensor(uint16)", + "tensor(uint32)", + "tensor(uint64)", + "tensor(int8)", + "tensor(int16)", + "tensor(int32)", + "tensor(int64)", + "tensor(float16)", + "tensor(float)", + "tensor(double)", + "tensor(bfloat16)" + ] + }, + { + "description": "Constrains output to boolean tensor.", + "type_param_str": "T1", + "allowed_type_strs": [ + "tensor(bool)" + ] + } + ], + "examples": [ + { + "summary": "less", + "code": "node = onnx.helper.make_node(\n 'Less',\n inputs=['x', 'y'],\n outputs=['less'],\n)\n\nx = np.random.randn(3, 4, 5).astype(np.float32)\ny = np.random.randn(3, 4, 5).astype(np.float32)\nz = np.less(x, y)\nexpect(node, inputs=[x, y], outputs=[z],\n name='test_less')" + }, + { + "summary": "less", + "code": "node = onnx.helper.make_node(\n 'LessOrEqual',\n inputs=['x', 'y'],\n outputs=['less_equal'],\n)\n\nx = np.random.randn(3, 4, 5).astype(np.float32)\ny = np.random.randn(3, 4, 5).astype(np.float32)\nz = np.less_equal(x, y)\nexpect(node, inputs=[x, y], outputs=[z],\n name='test_less_equal')" + }, + { + "summary": "less_broadcast", + "code": "node = onnx.helper.make_node(\n 'Less',\n inputs=['x', 'y'],\n outputs=['less'],\n)\n\nx = np.random.randn(3, 4, 5).astype(np.float32)\ny = np.random.randn(5).astype(np.float32)\nz = np.less(x, y)\nexpect(node, inputs=[x, y], outputs=[z],\n name='test_less_bcast')" + }, + { + "summary": "less_broadcast", + "code": "node = onnx.helper.make_node(\n 'LessOrEqual',\n inputs=['x', 'y'],\n outputs=['less_equal'],\n)\n\nx = np.random.randn(3, 4, 5).astype(np.float32)\ny = np.random.randn(5).astype(np.float32)\nz = np.less_equal(x, y)\nexpect(node, inputs=[x, y], outputs=[z],\n name='test_less_equal_bcast')" + } + ], + "category": "Logic" + }, + { + "name": "LessOrEqual", + "module": "ai.onnx", + "version": 12, + "support_level": "common", + "description": "Returns the tensor resulted from performing the `less_equal` logical operation\nelementwise on the input tensors `A` and `B` (with Numpy-style broadcasting support).\n\nThis operator supports **multidirectional (i.e., Numpy-style) broadcasting**; for more details please check [the doc](https://github.com/onnx/onnx/blob/master/docs/Broadcasting.md).\n", + "inputs": [ + { + "name": "A", + "type": "T", + "description": "First input operand for the logical operator." + }, + { + "name": "B", + "type": "T", + "description": "Second input operand for the logical operator." + } + ], + "min_input": 2, + "max_input": 2, + "outputs": [ + { + "name": "C", + "type": "T1", + "description": "Result tensor." + } + ], + "min_output": 1, + "max_output": 1, + "type_constraints": [ + { + "description": "Constrains input types to all numeric tensors.", + "type_param_str": "T", + "allowed_type_strs": [ + "tensor(uint8)", + "tensor(uint16)", + "tensor(uint32)", + "tensor(uint64)", + "tensor(int8)", + "tensor(int16)", + "tensor(int32)", + "tensor(int64)", + "tensor(float16)", + "tensor(float)", + "tensor(double)" + ] + }, + { + "description": "Constrains output to boolean tensor.", + "type_param_str": "T1", + "allowed_type_strs": [ + "tensor(bool)" + ] + } + ] + }, + { + "name": "LinearClassifier", + "module": "ai.onnx.ml", + "version": 1, + "support_level": "common", + "description": "Linear classifier\n", + "attributes": [ + { + "name": "classlabels_ints", + "type": "int64[]", + "required": false, + "description": "Class labels when using integer labels. One and only one 'classlabels' attribute must be defined." + }, + { + "name": "classlabels_strings", + "type": "string[]", + "required": false, + "description": "Class labels when using string labels. One and only one 'classlabels' attribute must be defined." + }, + { + "name": "coefficients", + "type": "float32[]", + "required": true, + "description": "A collection of weights of the model(s)." + }, + { + "name": "intercepts", + "type": "float32[]", + "required": false, + "description": "A collection of intercepts." + }, + { + "name": "multi_class", + "type": "int64", + "required": false, + "description": "Indicates whether to do OvR or multinomial (0=OvR is the default)." + }, + { + "name": "post_transform", + "type": "string", + "required": false, + "default": "NONE", + "description": "Indicates the transform to apply to the scores vector.
One of 'NONE,' 'SOFTMAX,' 'LOGISTIC,' 'SOFTMAX_ZERO,' or 'PROBIT'" + } + ], + "inputs": [ + { + "name": "X", + "type": "T1", + "description": "Data to be classified." + } + ], + "min_input": 1, + "max_input": 1, + "outputs": [ + { + "name": "Y", + "type": "T2", + "description": "Classification outputs (one class per example)." + }, + { + "name": "Z", + "type": "tensor(float)", + "description": "Classification scores ([N,E] - one score for each class and example" + } + ], + "min_output": 2, + "max_output": 2, + "type_constraints": [ + { + "description": "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]", + "type_param_str": "T1", + "allowed_type_strs": [ + "tensor(float)", + "tensor(double)", + "tensor(int64)", + "tensor(int32)" + ] + }, + { + "description": "The output will be a tensor of strings or integers.", + "type_param_str": "T2", + "allowed_type_strs": [ + "tensor(string)", + "tensor(int64)" + ] + } + ] + }, + { + "name": "LinearRegressor", + "module": "ai.onnx.ml", + "version": 1, + "support_level": "common", + "description": "Generalized linear regression evaluation.
\n If targets is set to 1 (default) then univariate regression is performed.
\n If targets is set to M then M sets of coefficients must be passed in as a sequence\n and M results will be output for each input n in N.
\n The coefficients array is of length n, and the coefficients for each target are contiguous.\n Intercepts are optional but if provided must match the number of targets.\n", + "attributes": [ + { + "name": "coefficients", + "type": "float32[]", + "required": false, + "description": "Weights of the model(s)." + }, + { + "name": "intercepts", + "type": "float32[]", + "required": false, + "description": "Weights of the intercepts, if used." + }, + { + "name": "post_transform", + "type": "string", + "required": false, + "default": "NONE", + "description": "Indicates the transform to apply to the regression output vector.
One of 'NONE,' 'SOFTMAX,' 'LOGISTIC,' 'SOFTMAX_ZERO,' or 'PROBIT'" + }, + { + "name": "targets", + "type": "int64", + "required": false, + "default": 1, + "description": "The total number of regression targets, 1 if not defined." + } + ], + "inputs": [ + { + "name": "X", + "type": "T", + "description": "Data to be regressed." + } + ], + "min_input": 1, + "max_input": 1, + "outputs": [ + { + "name": "Y", + "type": "tensor(float)", + "description": "Regression outputs (one per target, per example)." + } + ], + "min_output": 1, + "max_output": 1, + "type_constraints": [ + { + "description": "The input must be a tensor of a numeric type.", + "type_param_str": "T", + "allowed_type_strs": [ + "tensor(float)", + "tensor(double)", + "tensor(int64)", + "tensor(int32)" + ] + } + ] + }, + { + "name": "Log", + "module": "ai.onnx", + "version": 1, + "support_level": "common", + "description": "Calculates the natural log of the given input tensor, element-wise.\n", + "attributes": [ + { + "name": "consumed_inputs", + "type": "int64[]", + "required": false, + "description": "legacy optimization attribute." + } + ], + "inputs": [ + { + "name": "input", + "type": "T", + "description": "Input tensor" + } + ], + "min_input": 1, + "max_input": 1, + "outputs": [ + { + "name": "output", + "type": "T", + "description": "The natural log of the input tensor computed element-wise" + } + ], + "min_output": 1, + "max_output": 1, + "type_constraints": [ + { + "description": "Constrain input and output types to float tensors.", + "type_param_str": "T", + "allowed_type_strs": [ + "tensor(float16)", + "tensor(float)", + "tensor(double)" + ] + } + ], + "examples": [ + { + "summary": "log", + "code": "node = onnx.helper.make_node(\n 'Log',\n inputs=['x'],\n outputs=['y'],\n)\n\nx = np.array([1, 10]).astype(np.float32)\ny = np.log(x) # expected output [0., 2.30258512]\nexpect(node, inputs=[x], outputs=[y],\n name='test_log_example')\n\nx = np.exp(np.random.randn(3, 4, 5).astype(np.float32))\ny = np.log(x)\nexpect(node, inputs=[x], outputs=[y],\n name='test_log')" + } + ] + }, + { + "name": "Log", + "module": "ai.onnx", + "version": 6, + "support_level": "common", + "description": "Calculates the natural log of the given input tensor, element-wise.\n", + "inputs": [ + { + "name": "input", + "type": "T", + "description": "Input tensor" + } + ], + "min_input": 1, + "max_input": 1, + "outputs": [ + { + "name": "output", + "type": "T", + "description": "The natural log of the input tensor computed element-wise" + } + ], + "min_output": 1, + "max_output": 1, + "type_constraints": [ + { + "description": "Constrain input and output types to float tensors.", + "type_param_str": "T", + "allowed_type_strs": [ + "tensor(float16)", + "tensor(float)", + "tensor(double)" + ] + } + ], + "examples": [ + { + "summary": "log", + "code": "node = onnx.helper.make_node(\n 'Log',\n inputs=['x'],\n outputs=['y'],\n)\n\nx = np.array([1, 10]).astype(np.float32)\ny = np.log(x) # expected output [0., 2.30258512]\nexpect(node, inputs=[x], outputs=[y],\n name='test_log_example')\n\nx = np.exp(np.random.randn(3, 4, 5).astype(np.float32))\ny = np.log(x)\nexpect(node, inputs=[x], outputs=[y],\n name='test_log')" + } + ] + }, + { + "name": "Log", + "module": "ai.onnx", + "version": 13, + "support_level": "common", + "description": "Calculates the natural log of the given input tensor, element-wise.\n", + "inputs": [ + { + "name": "input", + "type": "T", + "description": "Input tensor" + } + ], + "min_input": 1, + "max_input": 1, + "outputs": [ + { + "name": "output", + "type": "T", + "description": "The natural log of the input tensor computed element-wise" + } + ], + "min_output": 1, + "max_output": 1, + "type_constraints": [ + { + "description": "Constrain input and output types to float tensors.", + "type_param_str": "T", + "allowed_type_strs": [ + "tensor(float16)", + "tensor(float)", + "tensor(double)", + "tensor(bfloat16)" + ] + } + ], + "examples": [ + { + "summary": "log", + "code": "node = onnx.helper.make_node(\n 'Log',\n inputs=['x'],\n outputs=['y'],\n)\n\nx = np.array([1, 10]).astype(np.float32)\ny = np.log(x) # expected output [0., 2.30258512]\nexpect(node, inputs=[x], outputs=[y],\n name='test_log_example')\n\nx = np.exp(np.random.randn(3, 4, 5).astype(np.float32))\ny = np.log(x)\nexpect(node, inputs=[x], outputs=[y],\n name='test_log')" + } + ] + }, + { + "name": "LogSoftmax", + "module": "ai.onnx", + "version": 1, + "support_level": "common", + "description": "The operator computes the logsoftmax (log of softmax) values for each layer in the batch\n of the given input. The input is a 2-D tensor (Tensor) of size\n(batch_size x input_feature_dimensions). The output tensor has the same shape\nand contains the logsoftmax values of the corresponding input.\n\nInput does not need to explicitly be a 2D vector; rather, it will be\ncoerced into one. For an arbitrary n-dimensional tensor\ninput \\in [a_0, a_1, ..., a_{k-1}, a_k, ..., a_{n-1}] and k is\nthe axis provided, then input will be coerced into a 2-dimensional tensor with\ndimensions [a_0 * ... * a_{k-1}, a_k * ... * a_{n-1}]. For the default\ncase where axis=1, this means the input tensor will be coerced into a 2D tensor\nof dimensions [a_0, a_1 * ... * a_{n-1}], where a_0 is often the batch size.\nIn this situation, we must have a_0 = N and a_1 * ... * a_{n-1} = D.\nEach of these dimensions must be matched correctly, or else the operator\nwill throw errors.\n", + "attributes": [ + { + "name": "axis", + "type": "int64", + "required": false, + "default": 1, + "description": "Describes the axis of the inputs when coerced to 2D; defaults to one because the 0th axis most likely describes the batch_size" + } + ], + "inputs": [ + { + "name": "input", + "type": "T", + "description": "The input tensor that's coerced into a 2D matrix of size (NxD) as described above." + } + ], + "min_input": 1, + "max_input": 1, + "outputs": [ + { + "name": "output", + "type": "T", + "description": "The output values with the same shape as input tensor (the original size without coercion)." + } + ], + "min_output": 1, + "max_output": 1, + "type_constraints": [ + { + "description": "Constrain input and output types to float tensors.", + "type_param_str": "T", + "allowed_type_strs": [ + "tensor(float16)", + "tensor(float)", + "tensor(double)" + ] + } + ], + "examples": [ + { + "summary": "logsoftmax", + "code": "node = onnx.helper.make_node(\n 'LogSoftmax',\n inputs=['x'],\n outputs=['y'],\n)\nx = np.array([[-1, 0, 1]]).astype(np.float32)\n# expected output\n# [[-2.4076061 -1.407606 -0.407606 ]]\ny = logsoftmax(x)\nexpect(node, inputs=[x], outputs=[y],\n name='test_logsoftmax_example_1')" + }, + { + "summary": "logsoftmax_axis", + "code": "x = np.array([[0, 1, 2, 3], [10000, 10001, 10002, 10003]]\n ).astype(np.float32)\n# expected output\n# [[-3.4401896 -2.4401896 -1.4401896 -0.44018966]\n# [-3.4401896 -2.4401896 -1.4401896 -0.44018966]]\ny = logsoftmax(x)\n\nnode = onnx.helper.make_node(\n 'LogSoftmax',\n inputs=['x'],\n outputs=['y'],\n)\nexpect(node, inputs=[x], outputs=[y],\n name='test_logsoftmax_large_number')\n\nx = np.abs(np.random.randn(3, 4, 5).astype(np.float32))\nnode = onnx.helper.make_node(\n 'LogSoftmax',\n inputs=['x'],\n outputs=['y'],\n axis=0,\n)\ny = logsoftmax(x, axis=0)\nexpect(node, inputs=[x], outputs=[y],\n name='test_logsoftmax_axis_0')\n\nnode = onnx.helper.make_node(\n 'LogSoftmax',\n inputs=['x'],\n outputs=['y'],\n axis=1,\n)\ny = logsoftmax(x, axis=1)\nexpect(node, inputs=[x], outputs=[y],\n name='test_logsoftmax_axis_1')\n\nnode = onnx.helper.make_node(\n 'LogSoftmax',\n inputs=['x'],\n outputs=['y'],\n axis=2,\n)\ny = logsoftmax(x, axis=2)\nexpect(node, inputs=[x], outputs=[y],\n name='test_logsoftmax_axis_2')\n\nnode = onnx.helper.make_node(\n 'LogSoftmax',\n inputs=['x'],\n outputs=['y'],\n axis=-1,\n)\ny = logsoftmax(x, axis=-1)\nexpect(node, inputs=[x], outputs=[y],\n name='test_logsoftmax_negative_axis')\n\n# default axis is -1\nnode = onnx.helper.make_node(\n 'LogSoftmax',\n inputs=['x'],\n outputs=['y'],\n)\nexpect(node, inputs=[x], outputs=[y],\n name='test_logsoftmax_default_axis')" + } + ], + "category": "Activation" + }, + { + "name": "LogSoftmax", + "module": "ai.onnx", + "version": 11, + "support_level": "common", + "description": "The operator computes the logsoftmax (log of softmax) values for each layer in the batch\n of the given input.\n\nThe input does not need to explicitly be a 2D vector; rather, it will be\ncoerced into one. For an arbitrary n-dimensional tensor\ninput \\in [a_0, a_1, ..., a_{k-1}, a_k, ..., a_{n-1}] and k is\nthe axis provided, then input will be coerced into a 2-dimensional tensor with\ndimensions [a_0 * ... * a_{k-1}, a_k * ... * a_{n-1}]. For the default\ncase where axis=1, this means the input tensor will be coerced into a 2D tensor\nof dimensions [a_0, a_1 * ... * a_{n-1}], where a_0 is often the batch size.\nIn this situation, we must have a_0 = N and a_1 * ... * a_{n-1} = D.\nEach of these dimensions must be matched correctly, or else the operator\nwill throw errors. The output tensor has the same shape\nand contains the logsoftmax values of the corresponding input.\n", + "attributes": [ + { + "name": "axis", + "type": "int64", + "required": false, + "default": 1, + "description": "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": [ + { + "name": "input", + "type": "T", + "description": "The input tensor that's coerced into a 2D matrix of size (NxD) as described above." + } + ], + "min_input": 1, + "max_input": 1, + "outputs": [ + { + "name": "output", + "type": "T", + "description": "The output values with the same shape as input tensor (the original size without coercion)." + } + ], + "min_output": 1, + "max_output": 1, + "type_constraints": [ + { + "description": "Constrain input and output types to float tensors.", + "type_param_str": "T", + "allowed_type_strs": [ + "tensor(float16)", + "tensor(float)", + "tensor(double)" + ] + } + ], + "examples": [ + { + "summary": "logsoftmax", + "code": "node = onnx.helper.make_node(\n 'LogSoftmax',\n inputs=['x'],\n outputs=['y'],\n)\nx = np.array([[-1, 0, 1]]).astype(np.float32)\n# expected output\n# [[-2.4076061 -1.407606 -0.407606 ]]\ny = logsoftmax(x)\nexpect(node, inputs=[x], outputs=[y],\n name='test_logsoftmax_example_1')" + }, + { + "summary": "logsoftmax_axis", + "code": "x = np.array([[0, 1, 2, 3], [10000, 10001, 10002, 10003]]\n ).astype(np.float32)\n# expected output\n# [[-3.4401896 -2.4401896 -1.4401896 -0.44018966]\n# [-3.4401896 -2.4401896 -1.4401896 -0.44018966]]\ny = logsoftmax(x)\n\nnode = onnx.helper.make_node(\n 'LogSoftmax',\n inputs=['x'],\n outputs=['y'],\n)\nexpect(node, inputs=[x], outputs=[y],\n name='test_logsoftmax_large_number')\n\nx = np.abs(np.random.randn(3, 4, 5).astype(np.float32))\nnode = onnx.helper.make_node(\n 'LogSoftmax',\n inputs=['x'],\n outputs=['y'],\n axis=0,\n)\ny = logsoftmax(x, axis=0)\nexpect(node, inputs=[x], outputs=[y],\n name='test_logsoftmax_axis_0')\n\nnode = onnx.helper.make_node(\n 'LogSoftmax',\n inputs=['x'],\n outputs=['y'],\n axis=1,\n)\ny = logsoftmax(x, axis=1)\nexpect(node, inputs=[x], outputs=[y],\n name='test_logsoftmax_axis_1')\n\nnode = onnx.helper.make_node(\n 'LogSoftmax',\n inputs=['x'],\n outputs=['y'],\n axis=2,\n)\ny = logsoftmax(x, axis=2)\nexpect(node, inputs=[x], outputs=[y],\n name='test_logsoftmax_axis_2')\n\nnode = onnx.helper.make_node(\n 'LogSoftmax',\n inputs=['x'],\n outputs=['y'],\n axis=-1,\n)\ny = logsoftmax(x, axis=-1)\nexpect(node, inputs=[x], outputs=[y],\n name='test_logsoftmax_negative_axis')\n\n# default axis is -1\nnode = onnx.helper.make_node(\n 'LogSoftmax',\n inputs=['x'],\n outputs=['y'],\n)\nexpect(node, inputs=[x], outputs=[y],\n name='test_logsoftmax_default_axis')" + } + ], + "category": "Activation" + }, + { + "name": "LogSoftmax", + "module": "ai.onnx", + "version": 13, + "support_level": "common", + "description": "The operator computes the log of softmax values for the given input:\n\n LogSoftmax(input, axis) = Log(Softmax(input, axis=axis))\n\nThe \"axis\" attribute indicates the dimension along which LogSoftmax\nwill be performed. The output tensor has the same shape\nand contains the LogSoftmax values of the corresponding input.\n", + "attributes": [ + { + "name": "axis", + "type": "int64", + "required": false, + "default": -1, + "description": "\nDescribes the dimension LogSoftmax will be performed on.\nNegative value means counting dimensions\nfrom the back. Accepted range is [-r, r-1] where r = rank(input).\n" + } + ], + "inputs": [ + { + "name": "input", + "type": "T", + "description": "The input tensor of rank >= axis." + } + ], + "min_input": 1, + "max_input": 1, + "outputs": [ + { + "name": "output", + "type": "T", + "description": "The output values with the same shape as the input tensor." + } + ], + "min_output": 1, + "max_output": 1, + "type_constraints": [ + { + "description": "Constrain input and output types to float tensors.", + "type_param_str": "T", + "allowed_type_strs": [ + "tensor(float16)", + "tensor(float)", + "tensor(double)", + "tensor(bfloat16)" + ] + } + ], + "examples": [ + { + "summary": "logsoftmax", + "code": "node = onnx.helper.make_node(\n 'LogSoftmax',\n inputs=['x'],\n outputs=['y'],\n)\nx = np.array([[-1, 0, 1]]).astype(np.float32)\n# expected output\n# [[-2.4076061 -1.407606 -0.407606 ]]\ny = logsoftmax(x)\nexpect(node, inputs=[x], outputs=[y],\n name='test_logsoftmax_example_1')" + }, + { + "summary": "logsoftmax_axis", + "code": "x = np.array([[0, 1, 2, 3], [10000, 10001, 10002, 10003]]\n ).astype(np.float32)\n# expected output\n# [[-3.4401896 -2.4401896 -1.4401896 -0.44018966]\n# [-3.4401896 -2.4401896 -1.4401896 -0.44018966]]\ny = logsoftmax(x)\n\nnode = onnx.helper.make_node(\n 'LogSoftmax',\n inputs=['x'],\n outputs=['y'],\n)\nexpect(node, inputs=[x], outputs=[y],\n name='test_logsoftmax_large_number')\n\nx = np.abs(np.random.randn(3, 4, 5).astype(np.float32))\nnode = onnx.helper.make_node(\n 'LogSoftmax',\n inputs=['x'],\n outputs=['y'],\n axis=0,\n)\ny = logsoftmax(x, axis=0)\nexpect(node, inputs=[x], outputs=[y],\n name='test_logsoftmax_axis_0')\n\nnode = onnx.helper.make_node(\n 'LogSoftmax',\n inputs=['x'],\n outputs=['y'],\n axis=1,\n)\ny = logsoftmax(x, axis=1)\nexpect(node, inputs=[x], outputs=[y],\n name='test_logsoftmax_axis_1')\n\nnode = onnx.helper.make_node(\n 'LogSoftmax',\n inputs=['x'],\n outputs=['y'],\n axis=2,\n)\ny = logsoftmax(x, axis=2)\nexpect(node, inputs=[x], outputs=[y],\n name='test_logsoftmax_axis_2')\n\nnode = onnx.helper.make_node(\n 'LogSoftmax',\n inputs=['x'],\n outputs=['y'],\n axis=-1,\n)\ny = logsoftmax(x, axis=-1)\nexpect(node, inputs=[x], outputs=[y],\n name='test_logsoftmax_negative_axis')\n\n# default axis is -1\nnode = onnx.helper.make_node(\n 'LogSoftmax',\n inputs=['x'],\n outputs=['y'],\n)\nexpect(node, inputs=[x], outputs=[y],\n name='test_logsoftmax_default_axis')" + } + ], + "category": "Activation" + }, + { + "name": "Loop", + "module": "ai.onnx", + "version": 1, + "support_level": "common", + "description": "Generic Looping construct. This loop has multiple termination conditions:\n\n1) Trip count. Iteration count specified at runtime. Set by\n specifying the input M. Optional. Set to empty string to omit.\n Note that a static trip count (specified at graph construction time) can be\n specified by passing in a constant node for input M.\n2) Loop termination condition. This is an input to the op that determines\n whether to run the first iteration and also a loop-carried dependency for\n the body graph. The body graph must yield a value for the condition variable,\n whether this input is provided or not.\n\nThis table summarizes the operating modes of this operator with equivalent\nC-style code:\n\n Operator inputs defined as (max_trip_count, condition_var).\n\n input (\"\", \"\"):\n for (int i=0; ; ++i) {\n cond = ... // Note this value is ignored, but is required in the body\n }\n\n input (\"\", cond) // Note this is analogous to a while loop\n bool cond = ...;\n for (int i=0; cond; ++i) {\n cond = ...;\n }\n\n input (\"\", 1) // Note this is analogous to a do-while loop\n bool cond = true\n for (int i=0; cond; ++i) {\n cond = ...;\n }\n\n input (trip_count, \"\") // Note this is analogous to a for loop\n int trip_count = ...\n for (int i=0; i < trip_count; ++i) {\n cond = ...; // ignored\n }\n\n input (trip_count, cond)\n int trip_count = ...;\n bool cond = ...;\n for (int i=0; i < trip_count && cond; ++i) {\n cond = ...;\n }\n\n\n*Sample usage - cond as well as trip count*\n\n graph predict-net {\n %a = Constant[value = ]()\n %b = Constant[value = ]()\n %keepgoing = Constant[value = ]()\n %max_trip_count = Constant[value = ]()\n %keepgoing_out, %b_out, %user_defined_vals = Loop[body = ](%max_trip_count, %keepgoing, %b)\n return\n }\n\n graph body-net (\n %i[INT32, scalar]\n %keepgoing[BOOL, scalar]\n %b[INT32, scalar]\n ) {\n %my_local = Add(%a, %b)\n %b_out = Sub(%a, %b)\n %keepgoing_out = Greater(%my_local, %b_out)\n %user_defined_vals = Add(%b, %b)\n return %keepgoing_out, %b_out, %user_defined_vals\n }\n\n*Sample equivalent C code*\n\n {\n /* User-defined code (enclosing scope) */\n int a = 3, b = 6;\n bool keepgoing = true; // Analogous to input cond\n /* End user-defined code */\n\n /* Implicitly-defined code */\n const int max_trip_count = 10; // Analogous to input M\n int user_defined_vals[]; // Imagine this is resizable\n /* End implicitly-defined code */\n for (int i=0; i < max_trip_count && keepgoing; ++i) {\n /* User-defined code (loop body) */\n int my_local = a + b; // Reading values in the enclosing scope is fine\n b = a - b; // writes fine if we specify b as a loop-carried dependency\n keepgoing = my_local > b; // keepgoing is a loop-carried dependency\n user_defined_vals[i] = b + b;\n /* End user-defined code */\n }\n // my_local = 123; // Can't do this. my_local was defined in the the body\n\n // These below values are live-out from the loop and therefore accessible\n b_out; user_defined_vals; keepgoing_out;\n }\n\nThere are several things of note in this code snippet:\n\n1) Values from the enclosing scope (i.e. variable a here) are in scope and can\n be referenced in the inputs of the loop.\n2) Any variables which you wish to make available in the enclosing scope (i.e.\n the variables b and keepgoing) must be declared as either loop-carried\n dependencies (both at the op inputs and output and at the body net input and\n output) or scan_outputs.\n3) Values created in the body cannot be accessed in the enclosing scope.\n\nNote that the semantics of this op support \"diagonal\" or \"wavefront\" execution.\n(See Step 3 here for an example:\nhttps://devblogs.nvidia.com/optimizing-recurrent-neural-networks-cudnn-5/).\nFrontends should emit multi-layer RNNs as a series of While operators (with\ntime being the inner looping dimension), with each successive layer consuming\nthe scan_outputs from the previous layer, possibly going through several\npoint-wise operators (e.g. dropout, residual connections, linear layer).\n", + "attributes": [ + { + "name": "body", + "type": "graph", + "required": true, + "description": "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": [ + { + "name": "M", + "type": "I", + "option": "optional", + "description": "A maximum trip-count for the loop specified at runtime. Optional. Pass empty string to skip." + }, + { + "name": "cond", + "type": "B", + "option": "optional", + "description": "A boolean termination condition. Optional. Pass empty string to skip." + }, + { + "name": "v_initial", + "type": "V", + "list": true, + "description": "The initial values of any loop-carried dependencies (values that change across loop iterations)" + } + ], + "min_input": 3, + "max_input": 2147483647, + "outputs": [ + { + "name": "v_final_and_scan_outputs", + "type": "V", + "list": true, + "description": "Final N loop carried dependency values then K scan_outputs" + } + ], + "min_output": 1, + "max_output": 2147483647, + "inputs_range": "3 - ∞", + "outputs_range": "1 - ∞", + "type_constraints": [ + { + "description": "All Tensor types", + "type_param_str": "V", + "allowed_type_strs": [ + "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)" + ] + }, + { + "description": "tensor of int64, which should be a scalar.", + "type_param_str": "I", + "allowed_type_strs": [ + "tensor(int64)" + ] + }, + { + "description": "tensor of bool, which should be a scalar.", + "type_param_str": "B", + "allowed_type_strs": [ + "tensor(bool)" + ] + } + ], + "examples": [ + { + "summary": "loop_11", + "code": "# Given a tensor x of values [x1, ..., xN], and initial tensor y\n# sum up its elements using a scan\n# returning the final state (y+x1+x2+...+xN) as well the scan_output\n# [y+x1, y+x1+x2, ..., y+x1+x2+...+xN]\n\ny_in = onnx.helper.make_tensor_value_info('y_in', onnx.TensorProto.FLOAT, [1])\ny_out = onnx.helper.make_tensor_value_info('y_out', onnx.TensorProto.FLOAT, [1])\nscan_out = onnx.helper.make_tensor_value_info('scan_out', onnx.TensorProto.FLOAT, [1])\ncond_in = onnx.helper.make_tensor_value_info('cond_in', onnx.TensorProto.BOOL, [])\ncond_out = onnx.helper.make_tensor_value_info('cond_out', onnx.TensorProto.BOOL, [])\niter_count = onnx.helper.make_tensor_value_info('iter_count', onnx.TensorProto.INT64, [])\n\nx = np.array([1, 2, 3, 4, 5]).astype(np.float32)\ny = np.array([-2]).astype(np.float32)\n\nx_const_node = onnx.helper.make_node(\n 'Constant',\n inputs=[],\n outputs=['x'],\n value=onnx.helper.make_tensor(\n name='const_tensor_x',\n data_type=onnx.TensorProto.FLOAT,\n dims=x.shape,\n vals=x.flatten().astype(float),\n )\n)\n\none_const_node = onnx.helper.make_node(\n 'Constant',\n inputs=[],\n outputs=['one'],\n value=onnx.helper.make_tensor(\n name='const_tensor_one',\n data_type=onnx.TensorProto.INT64,\n dims=(),\n vals=[1]\n )\n)\n\ni_add_node = onnx.helper.make_node(\n 'Add',\n inputs=['iter_count', 'one'],\n outputs=['end']\n)\n\nstart_unsqueeze_node = onnx.helper.make_node(\n 'Unsqueeze',\n inputs=['iter_count'],\n outputs=['slice_start'],\n axes=[0]\n)\n\nend_unsqueeze_node = onnx.helper.make_node(\n 'Unsqueeze',\n inputs=['end'],\n outputs=['slice_end'],\n axes=[0]\n)\n\nslice_node = onnx.helper.make_node(\n 'Slice',\n inputs=['x', 'slice_start', 'slice_end'],\n outputs=['slice_out']\n)\n\ny_add_node = onnx.helper.make_node(\n 'Add',\n inputs=['y_in', 'slice_out'],\n outputs=['y_out']\n)\n\nidentity_node = onnx.helper.make_node(\n 'Identity',\n inputs=['cond_in'],\n outputs=['cond_out']\n)\n\nscan_identity_node = onnx.helper.make_node(\n 'Identity',\n inputs=['y_out'],\n outputs=['scan_out']\n)\n\nloop_body = onnx.helper.make_graph(\n [identity_node, x_const_node, one_const_node, i_add_node,\n start_unsqueeze_node, end_unsqueeze_node, slice_node, y_add_node,\n scan_identity_node],\n 'loop_body',\n [iter_count, cond_in, y_in],\n [cond_out, y_out, scan_out]\n)\n\nnode = onnx.helper.make_node(\n 'Loop',\n inputs=['trip_count', 'cond', 'y'],\n outputs=['res_y', 'res_scan'],\n body=loop_body\n)\n\ntrip_count = np.array(5).astype(np.int64)\nres_y = np.array([13]).astype(np.float32)\ncond = np.array(1).astype(bool)\nres_scan = np.array([-1, 1, 4, 8, 13]).astype(np.float32).reshape((5, 1))\nexpect(node, inputs=[trip_count, cond, y], outputs=[res_y, res_scan],\n name='test_loop11', opset_imports=[onnx.helper.make_opsetid(\"\", 11)])" + }, + { + "summary": "loop_13", + "code": "# Given a tensor x of values [x1, ..., xN],\n# Return a sequence of tensors of\n# [[x1], [x1, x2], ..., [x1, ..., xN]]\n\nseq_in = onnx.helper.make_tensor_sequence_value_info('seq_in', onnx.TensorProto.FLOAT, None)\nseq_out = onnx.helper.make_tensor_sequence_value_info('seq_out', onnx.TensorProto.FLOAT, None)\ncond_in = onnx.helper.make_tensor_value_info('cond_in', onnx.TensorProto.BOOL, [])\ncond_out = onnx.helper.make_tensor_value_info('cond_out', onnx.TensorProto.BOOL, [])\niter_count = onnx.helper.make_tensor_value_info('iter_count', onnx.TensorProto.INT64, [])\n\nx = np.array([1, 2, 3, 4, 5]).astype(np.float32)\n\nx_const_node = onnx.helper.make_node(\n 'Constant',\n inputs=[],\n outputs=['x'],\n value=onnx.helper.make_tensor(\n name='const_tensor_x',\n data_type=onnx.TensorProto.FLOAT,\n dims=x.shape,\n vals=x.flatten().astype(float),\n )\n)\n\none_const_node = onnx.helper.make_node(\n 'Constant',\n inputs=[],\n outputs=['one'],\n value=onnx.helper.make_tensor(\n name='const_tensor_one',\n data_type=onnx.TensorProto.INT64,\n dims=(),\n vals=[1]\n )\n)\n\nzero_const_node = onnx.helper.make_node(\n 'Constant',\n inputs=[],\n outputs=['slice_start'],\n value=onnx.helper.make_tensor(\n name='const_tensor_zero',\n data_type=onnx.TensorProto.INT64,\n dims=(1,),\n vals=[0]\n )\n)\n\naxes_node = onnx.helper.make_node(\n 'Constant',\n inputs=[],\n outputs=['axes'],\n value=onnx.helper.make_tensor(\n name='const_tensor_axes',\n data_type=onnx.TensorProto.INT64,\n dims=(),\n vals=[0]\n )\n)\n\nadd_node = onnx.helper.make_node(\n 'Add',\n inputs=['iter_count', 'one'],\n outputs=['end']\n)\n\nend_unsqueeze_node = onnx.helper.make_node(\n 'Unsqueeze',\n inputs=['end', 'axes'],\n outputs=['slice_end']\n)\n\nslice_node = onnx.helper.make_node(\n 'Slice',\n inputs=['x', 'slice_start', 'slice_end'],\n outputs=['slice_out']\n)\n\ninsert_node = onnx.helper.make_node(\n 'SequenceInsert',\n inputs=['seq_in', 'slice_out'],\n outputs=['seq_out']\n)\n\nidentity_node = onnx.helper.make_node(\n 'Identity',\n inputs=['cond_in'],\n outputs=['cond_out']\n)\n\nloop_body = onnx.helper.make_graph(\n [identity_node, x_const_node, one_const_node, zero_const_node, add_node,\n axes_node, end_unsqueeze_node, slice_node, insert_node],\n 'loop_body',\n [iter_count, cond_in, seq_in],\n [cond_out, seq_out]\n)\n\nnode = onnx.helper.make_node(\n 'Loop',\n inputs=['trip_count', 'cond', 'seq_empty'],\n outputs=['seq_res'],\n body=loop_body\n)\n\ntrip_count = np.array(5).astype(np.int64)\nseq_empty = [] # type: List[Any]\nseq_res = [x[:int(i)] for i in x]\ncond = np.array(1).astype(bool)\nexpect(node, inputs=[trip_count, cond, seq_empty], outputs=[seq_res],\n name='test_loop13_seq', opset_imports=[onnx.helper.make_opsetid(\"\", 13)],\n input_type_protos=[onnx.helper.make_tensor_type_proto(onnx.TensorProto.INT64, trip_count.shape),\n onnx.helper.make_tensor_type_proto(onnx.TensorProto.BOOL, cond.shape),\n onnx.helper.make_sequence_type_proto(\n onnx.helper.make_tensor_type_proto(onnx.TensorProto.FLOAT, []))])" + }, + { + "summary": "loop_16_none", + "code": "# Given a tensor x of values [x1, ..., xN], and an initial optional sequence of tensors s1,\n# Return a concatenated sequence of tensors of\n# [s1, [x1], [x1, x2], ..., [x1, ..., xN]]\n\nten_in_tp = onnx.helper.make_tensor_type_proto(onnx.TensorProto.FLOAT, None)\nseq_in_tp = onnx.helper.make_sequence_type_proto(ten_in_tp)\nopt_in_tp = onnx.helper.make_optional_type_proto(seq_in_tp)\nopt_in = onnx.helper.make_value_info('opt_seq_in', opt_in_tp)\nseq_out = onnx.helper.make_tensor_sequence_value_info('seq_out', onnx.TensorProto.FLOAT, None)\ncond_in = onnx.helper.make_tensor_value_info('cond_in', onnx.TensorProto.BOOL, [])\ncond_out = onnx.helper.make_tensor_value_info('cond_out', onnx.TensorProto.BOOL, [])\niter_count = onnx.helper.make_tensor_value_info('iter_count', onnx.TensorProto.INT64, [])\n\nx = np.array([1, 2, 3, 4, 5]).astype(np.float32)\n\noptional_has_elem_node = onnx.helper.make_node(\n 'OptionalHasElement',\n inputs=['opt_seq_in'],\n outputs=['optional_has_elem']\n)\n\noptional_is_none = onnx.helper.make_node(\n 'Not',\n inputs=['optional_has_elem'],\n outputs=['optional_is_none']\n)\n\noptional_get_elem = onnx.helper.make_node(\n 'OptionalGetElement',\n inputs=['opt_seq_in'],\n outputs=['seq_in']\n)\n\nseq_empty_in = onnx.helper.make_node(\n 'SequenceEmpty',\n inputs=[],\n outputs=['seq_empty']\n)\n\nthen_seq_out = onnx.helper.make_tensor_sequence_value_info('seq_out', onnx.TensorProto.FLOAT, None)\nthen_body = onnx.helper.make_graph(\n [seq_empty_in],\n 'then_body',\n [],\n [then_seq_out]\n)\n\nelse_seq_out = onnx.helper.make_tensor_sequence_value_info('seq_out', onnx.TensorProto.FLOAT, None)\nelse_body = onnx.helper.make_graph(\n [optional_get_elem],\n 'else_body',\n [opt_in],\n [else_seq_out]\n)\n\nif_node = onnx.helper.make_node(\n 'If',\n inputs=['optional_is_none'],\n outputs=['sequence'],\n then_branch=then_body,\n else_branch=else_body\n)\n\nx_const_node = onnx.helper.make_node(\n 'Constant',\n inputs=[],\n outputs=['x'],\n value=onnx.helper.make_tensor(\n name='const_tensor_x',\n data_type=onnx.TensorProto.FLOAT,\n dims=x.shape,\n vals=x.flatten().astype(float),\n )\n)\n\none_const_node = onnx.helper.make_node(\n 'Constant',\n inputs=[],\n outputs=['one'],\n value=onnx.helper.make_tensor(\n name='const_tensor_one',\n data_type=onnx.TensorProto.INT64,\n dims=(),\n vals=[1]\n )\n)\n\nzero_const_node = onnx.helper.make_node(\n 'Constant',\n inputs=[],\n outputs=['slice_start'],\n value=onnx.helper.make_tensor(\n name='const_tensor_zero',\n data_type=onnx.TensorProto.INT64,\n dims=(1,),\n vals=[0]\n )\n)\n\naxes_node = onnx.helper.make_node(\n 'Constant',\n inputs=[],\n outputs=['axes'],\n value=onnx.helper.make_tensor(\n name='const_tensor_axes',\n data_type=onnx.TensorProto.INT64,\n dims=(),\n vals=[0]\n )\n)\n\nadd_node = onnx.helper.make_node(\n 'Add',\n inputs=['iter_count', 'one'],\n outputs=['end']\n)\n\nend_unsqueeze_node = onnx.helper.make_node(\n 'Unsqueeze',\n inputs=['end', 'axes'],\n outputs=['slice_end']\n)\n\nslice_node = onnx.helper.make_node(\n 'Slice',\n inputs=['x', 'slice_start', 'slice_end'],\n outputs=['slice_out']\n)\n\ninsert_node = onnx.helper.make_node(\n 'SequenceInsert',\n inputs=['sequence', 'slice_out'],\n outputs=['seq_out']\n)\n\nidentity_node = onnx.helper.make_node(\n 'Identity',\n inputs=['cond_in'],\n outputs=['cond_out']\n)\n\nloop_body = onnx.helper.make_graph(\n [identity_node, optional_has_elem_node, optional_is_none, if_node, x_const_node, one_const_node,\n zero_const_node, add_node, axes_node, end_unsqueeze_node, slice_node, insert_node],\n 'loop_body',\n [iter_count, cond_in, opt_in],\n [cond_out, seq_out]\n)\n\nnode = onnx.helper.make_node(\n 'Loop',\n inputs=['trip_count', 'cond', 'opt_seq'],\n outputs=['seq_res'],\n body=loop_body\n)\n\ntrip_count = np.array(5).astype(np.int64)\ncond = np.array(1).astype(bool)\nseq_empty = [] # type: List[Any]\nseq_res = compute_loop_outputs(x, seq_empty, trip_count)\nexpect(node, inputs=[trip_count, cond, seq_empty], outputs=[seq_res],\n name='test_loop16_seq_none', opset_imports=[onnx.helper.make_opsetid(\"\", 16)],\n input_type_protos=[onnx.helper.make_tensor_type_proto(onnx.TensorProto.INT64, trip_count.shape),\n onnx.helper.make_tensor_type_proto(onnx.TensorProto.BOOL, cond.shape),\n opt_in_tp])" + } + ] + }, + { + "name": "Loop", + "module": "ai.onnx", + "version": 11, + "support_level": "common", + "description": "Generic Looping construct. This loop has multiple termination conditions:\n\n1) Trip count. Iteration count specified at runtime. Set by\n specifying the input M. Optional. Set to empty string to omit.\n Note that a static trip count (specified at graph construction time) can be\n specified by passing in a constant node for input M.\n2) Loop termination condition. This is an input to the op that determines\n whether to run the first iteration and also a loop-carried dependency for\n the body graph. The body graph must yield a value for the condition variable,\n whether this input is provided or not.\n\nThis table summarizes the operating modes of this operator with equivalent\nC-style code:\n\n Operator inputs defined as (max_trip_count, condition_var).\n\n input (\"\", \"\"):\n for (int i=0; ; ++i) {\n cond = ... // Note this value is ignored, but is required in the body\n }\n\n input (\"\", cond) // Note this is analogous to a while loop\n bool cond = ...;\n for (int i=0; cond; ++i) {\n cond = ...;\n }\n\n input (\"\", 1) // Note this is analogous to a do-while loop\n bool cond = true\n for (int i=0; cond; ++i) {\n cond = ...;\n }\n\n input (trip_count, \"\") // Note this is analogous to a for loop\n int trip_count = ...\n for (int i=0; i < trip_count; ++i) {\n cond = ...; // ignored\n }\n\n input (trip_count, cond)\n int trip_count = ...;\n bool cond = ...;\n for (int i=0; i < trip_count && cond; ++i) {\n cond = ...;\n }\n\n\n*Sample usage - cond as well as trip count*\n\n graph predict-net {\n %a = Constant[value = ]()\n %b = Constant[value = ]()\n %keepgoing = Constant[value = ]()\n %max_trip_count = Constant[value = ]()\n %keepgoing_out, %b_out, %user_defined_vals = Loop[body = ](%max_trip_count, %keepgoing, %b)\n return\n }\n\n graph body-net (\n %i[INT32, scalar] // iteration number\n %keepgoing_in[BOOL, scalar] // incoming loop-termination-condition; not used\n %b_in[INT32, scalar] // incoming value of loop-carried-dependency b\n ) {\n %my_local = Add(%a, %b_in)\n %b_out = Sub(%a, %b_in) // outgoing value of loop-carried-dependency b\n %keepgoing_out = Greater(%my_local, %b_out) // outgoing loop-termination-condition\n %user_defined_val = Add(%b_in, %b_in) // scan-output value to be accumulated\n return %keepgoing_out, %b_out, %user_defined_val\n }\n\n*Sample equivalent C code*\n\n {\n /* User-defined code (enclosing scope) */\n int a = 3, b = 6;\n bool keepgoing = true; // Analogous to input cond\n /* End user-defined code */\n\n /* Implicitly-defined code */\n const int max_trip_count = 10; // Analogous to input M\n int user_defined_vals[]; // Imagine this is resizable\n /* End implicitly-defined code */\n /* initialize loop-carried variables and scan-output variables */\n bool keepgoing_out = keepgoing\n int b_out = b\n\n for (int i=0; i < max_trip_count && keepgoing_out; ++i) {\n /* Implicitly-defined code: bind actual parameter values\n to formal parameter variables of loop-body */\n bool keepgoing_in = keepgoing_out;\n bool b_in = b_out;\n\n /* User-defined code (loop body) */\n int my_local = a + b_in; // Reading value \"a\" from the enclosing scope is fine\n b_out = a - b_in;\n keepgoing_out = my_local > b_out;\n user_defined_val = b_in + b_in; // b_in and b_out are different variables\n /* End user-defined code */\n\n /* Implicitly defined-code */\n user_defined_vals[i] = user_defined_val // accumulate scan-output values\n }\n // int t = my_local; // Can't do this. my_local is not accessible here.\n\n // The values below are bound to the output variables of the loop and therefore accessible\n // b_out; user_defined_vals; keepgoing_out;\n }\n\nThere are several things of note in this code snippet:\n\n1) Values from the enclosing scope (i.e. variable \"a\" here) are in scope and can\n be referenced in the inputs of the loop.\n2) Any values computed in the loop body that needs to be used in a subsequent\n iteration or after the loop are modelled using a pair of variables in the loop-body,\n consisting of an input variable (eg., b_in) and an output variable (eg., b_out).\n These are referred to as loop-carried dependences. The loop operation node\n supplies the input value of the input variable for the first iteration, and\n returns the output value of the output variable produced by the final\n iteration.\n3) Scan_output variables are used to implicitly concatenate values computed across\n all the iterations. In the above example, the value of user_defined_val computed\n over all iterations are concatenated and returned as the value of user_defined_vals\n after the loop.\n4) Values created in the body cannot be accessed in the enclosing scope,\n except using the mechanism described above.\n\nNote that the semantics of this op support \"diagonal\" or \"wavefront\" execution.\n(See Step 3 here for an example:\nhttps://devblogs.nvidia.com/optimizing-recurrent-neural-networks-cudnn-5/).\nFrontends should emit multi-layer RNNs as a series of While operators (with\ntime being the inner looping dimension), with each successive layer consuming\nthe scan_outputs from the previous layer, possibly going through several\npoint-wise operators (e.g. dropout, residual connections, linear layer).\n", + "attributes": [ + { + "name": "body", + "type": "graph", + "required": true, + "description": "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": [ + { + "name": "M", + "type": "I", + "option": "optional", + "description": "A maximum trip-count for the loop specified at runtime. Optional. Pass empty string to skip." + }, + { + "name": "cond", + "type": "B", + "option": "optional", + "description": "A boolean termination condition. Optional. Pass empty string to skip." + }, + { + "name": "v_initial", + "type": "V", + "list": true, + "description": "The initial values of any loop-carried dependencies (values that change across loop iterations)" + } + ], + "min_input": 2, + "max_input": 2147483647, + "outputs": [ + { + "name": "v_final_and_scan_outputs", + "type": "V", + "list": true, + "description": "Final N loop carried dependency values then K scan_outputs" + } + ], + "min_output": 1, + "max_output": 2147483647, + "inputs_range": "2 - ∞", + "outputs_range": "1 - ∞", + "type_constraints": [ + { + "description": "All Tensor types", + "type_param_str": "V", + "allowed_type_strs": [ + "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)" + ] + }, + { + "description": "tensor of int64, which should be a scalar.", + "type_param_str": "I", + "allowed_type_strs": [ + "tensor(int64)" + ] + }, + { + "description": "tensor of bool, which should be a scalar.", + "type_param_str": "B", + "allowed_type_strs": [ + "tensor(bool)" + ] + } + ], + "examples": [ + { + "summary": "loop_11", + "code": "# Given a tensor x of values [x1, ..., xN], and initial tensor y\n# sum up its elements using a scan\n# returning the final state (y+x1+x2+...+xN) as well the scan_output\n# [y+x1, y+x1+x2, ..., y+x1+x2+...+xN]\n\ny_in = onnx.helper.make_tensor_value_info('y_in', onnx.TensorProto.FLOAT, [1])\ny_out = onnx.helper.make_tensor_value_info('y_out', onnx.TensorProto.FLOAT, [1])\nscan_out = onnx.helper.make_tensor_value_info('scan_out', onnx.TensorProto.FLOAT, [1])\ncond_in = onnx.helper.make_tensor_value_info('cond_in', onnx.TensorProto.BOOL, [])\ncond_out = onnx.helper.make_tensor_value_info('cond_out', onnx.TensorProto.BOOL, [])\niter_count = onnx.helper.make_tensor_value_info('iter_count', onnx.TensorProto.INT64, [])\n\nx = np.array([1, 2, 3, 4, 5]).astype(np.float32)\ny = np.array([-2]).astype(np.float32)\n\nx_const_node = onnx.helper.make_node(\n 'Constant',\n inputs=[],\n outputs=['x'],\n value=onnx.helper.make_tensor(\n name='const_tensor_x',\n data_type=onnx.TensorProto.FLOAT,\n dims=x.shape,\n vals=x.flatten().astype(float),\n )\n)\n\none_const_node = onnx.helper.make_node(\n 'Constant',\n inputs=[],\n outputs=['one'],\n value=onnx.helper.make_tensor(\n name='const_tensor_one',\n data_type=onnx.TensorProto.INT64,\n dims=(),\n vals=[1]\n )\n)\n\ni_add_node = onnx.helper.make_node(\n 'Add',\n inputs=['iter_count', 'one'],\n outputs=['end']\n)\n\nstart_unsqueeze_node = onnx.helper.make_node(\n 'Unsqueeze',\n inputs=['iter_count'],\n outputs=['slice_start'],\n axes=[0]\n)\n\nend_unsqueeze_node = onnx.helper.make_node(\n 'Unsqueeze',\n inputs=['end'],\n outputs=['slice_end'],\n axes=[0]\n)\n\nslice_node = onnx.helper.make_node(\n 'Slice',\n inputs=['x', 'slice_start', 'slice_end'],\n outputs=['slice_out']\n)\n\ny_add_node = onnx.helper.make_node(\n 'Add',\n inputs=['y_in', 'slice_out'],\n outputs=['y_out']\n)\n\nidentity_node = onnx.helper.make_node(\n 'Identity',\n inputs=['cond_in'],\n outputs=['cond_out']\n)\n\nscan_identity_node = onnx.helper.make_node(\n 'Identity',\n inputs=['y_out'],\n outputs=['scan_out']\n)\n\nloop_body = onnx.helper.make_graph(\n [identity_node, x_const_node, one_const_node, i_add_node,\n start_unsqueeze_node, end_unsqueeze_node, slice_node, y_add_node,\n scan_identity_node],\n 'loop_body',\n [iter_count, cond_in, y_in],\n [cond_out, y_out, scan_out]\n)\n\nnode = onnx.helper.make_node(\n 'Loop',\n inputs=['trip_count', 'cond', 'y'],\n outputs=['res_y', 'res_scan'],\n body=loop_body\n)\n\ntrip_count = np.array(5).astype(np.int64)\nres_y = np.array([13]).astype(np.float32)\ncond = np.array(1).astype(bool)\nres_scan = np.array([-1, 1, 4, 8, 13]).astype(np.float32).reshape((5, 1))\nexpect(node, inputs=[trip_count, cond, y], outputs=[res_y, res_scan],\n name='test_loop11', opset_imports=[onnx.helper.make_opsetid(\"\", 11)])" + }, + { + "summary": "loop_13", + "code": "# Given a tensor x of values [x1, ..., xN],\n# Return a sequence of tensors of\n# [[x1], [x1, x2], ..., [x1, ..., xN]]\n\nseq_in = onnx.helper.make_tensor_sequence_value_info('seq_in', onnx.TensorProto.FLOAT, None)\nseq_out = onnx.helper.make_tensor_sequence_value_info('seq_out', onnx.TensorProto.FLOAT, None)\ncond_in = onnx.helper.make_tensor_value_info('cond_in', onnx.TensorProto.BOOL, [])\ncond_out = onnx.helper.make_tensor_value_info('cond_out', onnx.TensorProto.BOOL, [])\niter_count = onnx.helper.make_tensor_value_info('iter_count', onnx.TensorProto.INT64, [])\n\nx = np.array([1, 2, 3, 4, 5]).astype(np.float32)\n\nx_const_node = onnx.helper.make_node(\n 'Constant',\n inputs=[],\n outputs=['x'],\n value=onnx.helper.make_tensor(\n name='const_tensor_x',\n data_type=onnx.TensorProto.FLOAT,\n dims=x.shape,\n vals=x.flatten().astype(float),\n )\n)\n\none_const_node = onnx.helper.make_node(\n 'Constant',\n inputs=[],\n outputs=['one'],\n value=onnx.helper.make_tensor(\n name='const_tensor_one',\n data_type=onnx.TensorProto.INT64,\n dims=(),\n vals=[1]\n )\n)\n\nzero_const_node = onnx.helper.make_node(\n 'Constant',\n inputs=[],\n outputs=['slice_start'],\n value=onnx.helper.make_tensor(\n name='const_tensor_zero',\n data_type=onnx.TensorProto.INT64,\n dims=(1,),\n vals=[0]\n )\n)\n\naxes_node = onnx.helper.make_node(\n 'Constant',\n inputs=[],\n outputs=['axes'],\n value=onnx.helper.make_tensor(\n name='const_tensor_axes',\n data_type=onnx.TensorProto.INT64,\n dims=(),\n vals=[0]\n )\n)\n\nadd_node = onnx.helper.make_node(\n 'Add',\n inputs=['iter_count', 'one'],\n outputs=['end']\n)\n\nend_unsqueeze_node = onnx.helper.make_node(\n 'Unsqueeze',\n inputs=['end', 'axes'],\n outputs=['slice_end']\n)\n\nslice_node = onnx.helper.make_node(\n 'Slice',\n inputs=['x', 'slice_start', 'slice_end'],\n outputs=['slice_out']\n)\n\ninsert_node = onnx.helper.make_node(\n 'SequenceInsert',\n inputs=['seq_in', 'slice_out'],\n outputs=['seq_out']\n)\n\nidentity_node = onnx.helper.make_node(\n 'Identity',\n inputs=['cond_in'],\n outputs=['cond_out']\n)\n\nloop_body = onnx.helper.make_graph(\n [identity_node, x_const_node, one_const_node, zero_const_node, add_node,\n axes_node, end_unsqueeze_node, slice_node, insert_node],\n 'loop_body',\n [iter_count, cond_in, seq_in],\n [cond_out, seq_out]\n)\n\nnode = onnx.helper.make_node(\n 'Loop',\n inputs=['trip_count', 'cond', 'seq_empty'],\n outputs=['seq_res'],\n body=loop_body\n)\n\ntrip_count = np.array(5).astype(np.int64)\nseq_empty = [] # type: List[Any]\nseq_res = [x[:int(i)] for i in x]\ncond = np.array(1).astype(bool)\nexpect(node, inputs=[trip_count, cond, seq_empty], outputs=[seq_res],\n name='test_loop13_seq', opset_imports=[onnx.helper.make_opsetid(\"\", 13)],\n input_type_protos=[onnx.helper.make_tensor_type_proto(onnx.TensorProto.INT64, trip_count.shape),\n onnx.helper.make_tensor_type_proto(onnx.TensorProto.BOOL, cond.shape),\n onnx.helper.make_sequence_type_proto(\n onnx.helper.make_tensor_type_proto(onnx.TensorProto.FLOAT, []))])" + }, + { + "summary": "loop_16_none", + "code": "# Given a tensor x of values [x1, ..., xN], and an initial optional sequence of tensors s1,\n# Return a concatenated sequence of tensors of\n# [s1, [x1], [x1, x2], ..., [x1, ..., xN]]\n\nten_in_tp = onnx.helper.make_tensor_type_proto(onnx.TensorProto.FLOAT, None)\nseq_in_tp = onnx.helper.make_sequence_type_proto(ten_in_tp)\nopt_in_tp = onnx.helper.make_optional_type_proto(seq_in_tp)\nopt_in = onnx.helper.make_value_info('opt_seq_in', opt_in_tp)\nseq_out = onnx.helper.make_tensor_sequence_value_info('seq_out', onnx.TensorProto.FLOAT, None)\ncond_in = onnx.helper.make_tensor_value_info('cond_in', onnx.TensorProto.BOOL, [])\ncond_out = onnx.helper.make_tensor_value_info('cond_out', onnx.TensorProto.BOOL, [])\niter_count = onnx.helper.make_tensor_value_info('iter_count', onnx.TensorProto.INT64, [])\n\nx = np.array([1, 2, 3, 4, 5]).astype(np.float32)\n\noptional_has_elem_node = onnx.helper.make_node(\n 'OptionalHasElement',\n inputs=['opt_seq_in'],\n outputs=['optional_has_elem']\n)\n\noptional_is_none = onnx.helper.make_node(\n 'Not',\n inputs=['optional_has_elem'],\n outputs=['optional_is_none']\n)\n\noptional_get_elem = onnx.helper.make_node(\n 'OptionalGetElement',\n inputs=['opt_seq_in'],\n outputs=['seq_in']\n)\n\nseq_empty_in = onnx.helper.make_node(\n 'SequenceEmpty',\n inputs=[],\n outputs=['seq_empty']\n)\n\nthen_seq_out = onnx.helper.make_tensor_sequence_value_info('seq_out', onnx.TensorProto.FLOAT, None)\nthen_body = onnx.helper.make_graph(\n [seq_empty_in],\n 'then_body',\n [],\n [then_seq_out]\n)\n\nelse_seq_out = onnx.helper.make_tensor_sequence_value_info('seq_out', onnx.TensorProto.FLOAT, None)\nelse_body = onnx.helper.make_graph(\n [optional_get_elem],\n 'else_body',\n [opt_in],\n [else_seq_out]\n)\n\nif_node = onnx.helper.make_node(\n 'If',\n inputs=['optional_is_none'],\n outputs=['sequence'],\n then_branch=then_body,\n else_branch=else_body\n)\n\nx_const_node = onnx.helper.make_node(\n 'Constant',\n inputs=[],\n outputs=['x'],\n value=onnx.helper.make_tensor(\n name='const_tensor_x',\n data_type=onnx.TensorProto.FLOAT,\n dims=x.shape,\n vals=x.flatten().astype(float),\n )\n)\n\none_const_node = onnx.helper.make_node(\n 'Constant',\n inputs=[],\n outputs=['one'],\n value=onnx.helper.make_tensor(\n name='const_tensor_one',\n data_type=onnx.TensorProto.INT64,\n dims=(),\n vals=[1]\n )\n)\n\nzero_const_node = onnx.helper.make_node(\n 'Constant',\n inputs=[],\n outputs=['slice_start'],\n value=onnx.helper.make_tensor(\n name='const_tensor_zero',\n data_type=onnx.TensorProto.INT64,\n dims=(1,),\n vals=[0]\n )\n)\n\naxes_node = onnx.helper.make_node(\n 'Constant',\n inputs=[],\n outputs=['axes'],\n value=onnx.helper.make_tensor(\n name='const_tensor_axes',\n data_type=onnx.TensorProto.INT64,\n dims=(),\n vals=[0]\n )\n)\n\nadd_node = onnx.helper.make_node(\n 'Add',\n inputs=['iter_count', 'one'],\n outputs=['end']\n)\n\nend_unsqueeze_node = onnx.helper.make_node(\n 'Unsqueeze',\n inputs=['end', 'axes'],\n outputs=['slice_end']\n)\n\nslice_node = onnx.helper.make_node(\n 'Slice',\n inputs=['x', 'slice_start', 'slice_end'],\n outputs=['slice_out']\n)\n\ninsert_node = onnx.helper.make_node(\n 'SequenceInsert',\n inputs=['sequence', 'slice_out'],\n outputs=['seq_out']\n)\n\nidentity_node = onnx.helper.make_node(\n 'Identity',\n inputs=['cond_in'],\n outputs=['cond_out']\n)\n\nloop_body = onnx.helper.make_graph(\n [identity_node, optional_has_elem_node, optional_is_none, if_node, x_const_node, one_const_node,\n zero_const_node, add_node, axes_node, end_unsqueeze_node, slice_node, insert_node],\n 'loop_body',\n [iter_count, cond_in, opt_in],\n [cond_out, seq_out]\n)\n\nnode = onnx.helper.make_node(\n 'Loop',\n inputs=['trip_count', 'cond', 'opt_seq'],\n outputs=['seq_res'],\n body=loop_body\n)\n\ntrip_count = np.array(5).astype(np.int64)\ncond = np.array(1).astype(bool)\nseq_empty = [] # type: List[Any]\nseq_res = compute_loop_outputs(x, seq_empty, trip_count)\nexpect(node, inputs=[trip_count, cond, seq_empty], outputs=[seq_res],\n name='test_loop16_seq_none', opset_imports=[onnx.helper.make_opsetid(\"\", 16)],\n input_type_protos=[onnx.helper.make_tensor_type_proto(onnx.TensorProto.INT64, trip_count.shape),\n onnx.helper.make_tensor_type_proto(onnx.TensorProto.BOOL, cond.shape),\n opt_in_tp])" + } + ] + }, + { + "name": "Loop", + "module": "ai.onnx", + "version": 13, + "support_level": "common", + "description": "Generic Looping construct. This loop has multiple termination conditions:\n\n1) Trip count. Iteration count specified at runtime. Set by\n specifying the input M. Optional. Set to empty string to omit.\n Note that a static trip count (specified at graph construction time) can be\n specified by passing in a constant node for input M.\n2) Loop termination condition. This is an input to the op that determines\n whether to run the first iteration and also a loop-carried dependency for\n the body graph. The body graph must yield a value for the condition variable,\n whether this input is provided or not.\n\nThis table summarizes the operating modes of this operator with equivalent\nC-style code:\n\n Operator inputs defined as (max_trip_count, condition_var).\n\n input (\"\", \"\"):\n for (int i=0; ; ++i) {\n cond = ... // Note this value is ignored, but is required in the body\n }\n\n input (\"\", cond) // Note this is analogous to a while loop\n bool cond = ...;\n for (int i=0; cond; ++i) {\n cond = ...;\n }\n\n input (\"\", 1) // Note this is analogous to a do-while loop\n bool cond = true\n for (int i=0; cond; ++i) {\n cond = ...;\n }\n\n input (trip_count, \"\") // Note this is analogous to a for loop\n int trip_count = ...\n for (int i=0; i < trip_count; ++i) {\n cond = ...; // ignored\n }\n\n input (trip_count, cond)\n int trip_count = ...;\n bool cond = ...;\n for (int i=0; i < trip_count && cond; ++i) {\n cond = ...;\n }\n\n\n*Sample usage - cond as well as trip count*\n\n graph predict-net {\n %a = Constant[value = ]()\n %b = Constant[value = ]()\n %keepgoing = Constant[value = ]()\n %max_trip_count = Constant[value = ]()\n %keepgoing_out, %b_out, %user_defined_vals = Loop[body = ](%max_trip_count, %keepgoing, %b)\n return\n }\n\n graph body-net (\n %i[INT32, scalar] // iteration number\n %keepgoing_in[BOOL, scalar] // incoming loop-termination-condition; not used\n %b_in[INT32, scalar] // incoming value of loop-carried-dependency b\n ) {\n %my_local = Add(%a, %b_in)\n %b_out = Sub(%a, %b_in) // outgoing value of loop-carried-dependency b\n %keepgoing_out = Greater(%my_local, %b_out) // outgoing loop-termination-condition\n %user_defined_val = Add(%b_in, %b_in) // scan-output value to be accumulated\n return %keepgoing_out, %b_out, %user_defined_val\n }\n\n*Sample equivalent C code*\n\n {\n /* User-defined code (enclosing scope) */\n int a = 3, b = 6;\n bool keepgoing = true; // Analogous to input cond\n /* End user-defined code */\n\n /* Implicitly-defined code */\n const int max_trip_count = 10; // Analogous to input M\n int user_defined_vals[]; // Imagine this is resizable\n /* End implicitly-defined code */\n /* initialize loop-carried variables and scan-output variables */\n bool keepgoing_out = keepgoing\n int b_out = b\n\n for (int i=0; i < max_trip_count && keepgoing_out; ++i) {\n /* Implicitly-defined code: bind actual parameter values\n to formal parameter variables of loop-body */\n bool keepgoing_in = keepgoing_out;\n bool b_in = b_out;\n\n /* User-defined code (loop body) */\n int my_local = a + b_in; // Reading value \"a\" from the enclosing scope is fine\n b_out = a - b_in;\n keepgoing_out = my_local > b_out;\n user_defined_val = b_in + b_in; // b_in and b_out are different variables\n /* End user-defined code */\n\n /* Implicitly defined-code */\n user_defined_vals[i] = user_defined_val // accumulate scan-output values\n }\n // int t = my_local; // Can't do this. my_local is not accessible here.\n\n // The values below are bound to the output variables of the loop and therefore accessible\n // b_out; user_defined_vals; keepgoing_out;\n }\n\nThere are several things of note in this code snippet:\n\n1) Values from the enclosing scope (i.e. variable \"a\" here) are in scope and can\n be referenced in the inputs of the loop.\n2) Any values computed in the loop body that needs to be used in a subsequent\n iteration or after the loop are modelled using a pair of variables in the loop-body,\n consisting of an input variable (eg., b_in) and an output variable (eg., b_out).\n These are referred to as loop-carried dependences. The loop operation node\n supplies the input value of the input variable for the first iteration, and\n returns the output value of the output variable produced by the final\n iteration.\n3) Scan_output variables are used to implicitly concatenate values computed across\n all the iterations. In the above example, the value of user_defined_val computed\n over all iterations are concatenated and returned as the value of user_defined_vals\n after the loop.\n4) Values created in the body cannot be accessed in the enclosing scope,\n except using the mechanism described above.\n\nNote that the semantics of this op support \"diagonal\" or \"wavefront\" execution.\n(See Step 3 here for an example:\nhttps://devblogs.nvidia.com/optimizing-recurrent-neural-networks-cudnn-5/).\nFrontends should emit multi-layer RNNs as a series of While operators (with\ntime being the inner looping dimension), with each successive layer consuming\nthe scan_outputs from the previous layer, possibly going through several\npoint-wise operators (e.g. dropout, residual connections, linear layer).\n\nThe 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.\n", + "attributes": [ + { + "name": "body", + "type": "graph", + "required": true, + "description": "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": [ + { + "name": "M", + "type": "I", + "option": "optional", + "description": "A maximum trip-count for the loop specified at runtime. Optional. Pass empty string to skip." + }, + { + "name": "cond", + "type": "B", + "option": "optional", + "description": "A boolean termination condition. Optional. Pass empty string to skip." + }, + { + "name": "v_initial", + "type": "V", + "list": true, + "description": "The initial values of any loop-carried dependencies (values that change across loop iterations)" + } + ], + "min_input": 2, + "max_input": 2147483647, + "outputs": [ + { + "name": "v_final_and_scan_outputs", + "type": "V", + "list": true, + "description": "Final N loop carried dependency values then K scan_outputs. Scan outputs must be Tensors." + } + ], + "min_output": 1, + "max_output": 2147483647, + "inputs_range": "2 - ∞", + "outputs_range": "1 - ∞", + "type_constraints": [ + { + "description": "All Tensor and Sequence types", + "type_param_str": "V", + "allowed_type_strs": [ + "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))" + ] + }, + { + "description": "tensor of int64, which should be a scalar.", + "type_param_str": "I", + "allowed_type_strs": [ + "tensor(int64)" + ] + }, + { + "description": "tensor of bool, which should be a scalar.", + "type_param_str": "B", + "allowed_type_strs": [ + "tensor(bool)" + ] + } + ], + "examples": [ + { + "summary": "loop_11", + "code": "# Given a tensor x of values [x1, ..., xN], and initial tensor y\n# sum up its elements using a scan\n# returning the final state (y+x1+x2+...+xN) as well the scan_output\n# [y+x1, y+x1+x2, ..., y+x1+x2+...+xN]\n\ny_in = onnx.helper.make_tensor_value_info('y_in', onnx.TensorProto.FLOAT, [1])\ny_out = onnx.helper.make_tensor_value_info('y_out', onnx.TensorProto.FLOAT, [1])\nscan_out = onnx.helper.make_tensor_value_info('scan_out', onnx.TensorProto.FLOAT, [1])\ncond_in = onnx.helper.make_tensor_value_info('cond_in', onnx.TensorProto.BOOL, [])\ncond_out = onnx.helper.make_tensor_value_info('cond_out', onnx.TensorProto.BOOL, [])\niter_count = onnx.helper.make_tensor_value_info('iter_count', onnx.TensorProto.INT64, [])\n\nx = np.array([1, 2, 3, 4, 5]).astype(np.float32)\ny = np.array([-2]).astype(np.float32)\n\nx_const_node = onnx.helper.make_node(\n 'Constant',\n inputs=[],\n outputs=['x'],\n value=onnx.helper.make_tensor(\n name='const_tensor_x',\n data_type=onnx.TensorProto.FLOAT,\n dims=x.shape,\n vals=x.flatten().astype(float),\n )\n)\n\none_const_node = onnx.helper.make_node(\n 'Constant',\n inputs=[],\n outputs=['one'],\n value=onnx.helper.make_tensor(\n name='const_tensor_one',\n data_type=onnx.TensorProto.INT64,\n dims=(),\n vals=[1]\n )\n)\n\ni_add_node = onnx.helper.make_node(\n 'Add',\n inputs=['iter_count', 'one'],\n outputs=['end']\n)\n\nstart_unsqueeze_node = onnx.helper.make_node(\n 'Unsqueeze',\n inputs=['iter_count'],\n outputs=['slice_start'],\n axes=[0]\n)\n\nend_unsqueeze_node = onnx.helper.make_node(\n 'Unsqueeze',\n inputs=['end'],\n outputs=['slice_end'],\n axes=[0]\n)\n\nslice_node = onnx.helper.make_node(\n 'Slice',\n inputs=['x', 'slice_start', 'slice_end'],\n outputs=['slice_out']\n)\n\ny_add_node = onnx.helper.make_node(\n 'Add',\n inputs=['y_in', 'slice_out'],\n outputs=['y_out']\n)\n\nidentity_node = onnx.helper.make_node(\n 'Identity',\n inputs=['cond_in'],\n outputs=['cond_out']\n)\n\nscan_identity_node = onnx.helper.make_node(\n 'Identity',\n inputs=['y_out'],\n outputs=['scan_out']\n)\n\nloop_body = onnx.helper.make_graph(\n [identity_node, x_const_node, one_const_node, i_add_node,\n start_unsqueeze_node, end_unsqueeze_node, slice_node, y_add_node,\n scan_identity_node],\n 'loop_body',\n [iter_count, cond_in, y_in],\n [cond_out, y_out, scan_out]\n)\n\nnode = onnx.helper.make_node(\n 'Loop',\n inputs=['trip_count', 'cond', 'y'],\n outputs=['res_y', 'res_scan'],\n body=loop_body\n)\n\ntrip_count = np.array(5).astype(np.int64)\nres_y = np.array([13]).astype(np.float32)\ncond = np.array(1).astype(bool)\nres_scan = np.array([-1, 1, 4, 8, 13]).astype(np.float32).reshape((5, 1))\nexpect(node, inputs=[trip_count, cond, y], outputs=[res_y, res_scan],\n name='test_loop11', opset_imports=[onnx.helper.make_opsetid(\"\", 11)])" + }, + { + "summary": "loop_13", + "code": "# Given a tensor x of values [x1, ..., xN],\n# Return a sequence of tensors of\n# [[x1], [x1, x2], ..., [x1, ..., xN]]\n\nseq_in = onnx.helper.make_tensor_sequence_value_info('seq_in', onnx.TensorProto.FLOAT, None)\nseq_out = onnx.helper.make_tensor_sequence_value_info('seq_out', onnx.TensorProto.FLOAT, None)\ncond_in = onnx.helper.make_tensor_value_info('cond_in', onnx.TensorProto.BOOL, [])\ncond_out = onnx.helper.make_tensor_value_info('cond_out', onnx.TensorProto.BOOL, [])\niter_count = onnx.helper.make_tensor_value_info('iter_count', onnx.TensorProto.INT64, [])\n\nx = np.array([1, 2, 3, 4, 5]).astype(np.float32)\n\nx_const_node = onnx.helper.make_node(\n 'Constant',\n inputs=[],\n outputs=['x'],\n value=onnx.helper.make_tensor(\n name='const_tensor_x',\n data_type=onnx.TensorProto.FLOAT,\n dims=x.shape,\n vals=x.flatten().astype(float),\n )\n)\n\none_const_node = onnx.helper.make_node(\n 'Constant',\n inputs=[],\n outputs=['one'],\n value=onnx.helper.make_tensor(\n name='const_tensor_one',\n data_type=onnx.TensorProto.INT64,\n dims=(),\n vals=[1]\n )\n)\n\nzero_const_node = onnx.helper.make_node(\n 'Constant',\n inputs=[],\n outputs=['slice_start'],\n value=onnx.helper.make_tensor(\n name='const_tensor_zero',\n data_type=onnx.TensorProto.INT64,\n dims=(1,),\n vals=[0]\n )\n)\n\naxes_node = onnx.helper.make_node(\n 'Constant',\n inputs=[],\n outputs=['axes'],\n value=onnx.helper.make_tensor(\n name='const_tensor_axes',\n data_type=onnx.TensorProto.INT64,\n dims=(),\n vals=[0]\n )\n)\n\nadd_node = onnx.helper.make_node(\n 'Add',\n inputs=['iter_count', 'one'],\n outputs=['end']\n)\n\nend_unsqueeze_node = onnx.helper.make_node(\n 'Unsqueeze',\n inputs=['end', 'axes'],\n outputs=['slice_end']\n)\n\nslice_node = onnx.helper.make_node(\n 'Slice',\n inputs=['x', 'slice_start', 'slice_end'],\n outputs=['slice_out']\n)\n\ninsert_node = onnx.helper.make_node(\n 'SequenceInsert',\n inputs=['seq_in', 'slice_out'],\n outputs=['seq_out']\n)\n\nidentity_node = onnx.helper.make_node(\n 'Identity',\n inputs=['cond_in'],\n outputs=['cond_out']\n)\n\nloop_body = onnx.helper.make_graph(\n [identity_node, x_const_node, one_const_node, zero_const_node, add_node,\n axes_node, end_unsqueeze_node, slice_node, insert_node],\n 'loop_body',\n [iter_count, cond_in, seq_in],\n [cond_out, seq_out]\n)\n\nnode = onnx.helper.make_node(\n 'Loop',\n inputs=['trip_count', 'cond', 'seq_empty'],\n outputs=['seq_res'],\n body=loop_body\n)\n\ntrip_count = np.array(5).astype(np.int64)\nseq_empty = [] # type: List[Any]\nseq_res = [x[:int(i)] for i in x]\ncond = np.array(1).astype(bool)\nexpect(node, inputs=[trip_count, cond, seq_empty], outputs=[seq_res],\n name='test_loop13_seq', opset_imports=[onnx.helper.make_opsetid(\"\", 13)],\n input_type_protos=[onnx.helper.make_tensor_type_proto(onnx.TensorProto.INT64, trip_count.shape),\n onnx.helper.make_tensor_type_proto(onnx.TensorProto.BOOL, cond.shape),\n onnx.helper.make_sequence_type_proto(\n onnx.helper.make_tensor_type_proto(onnx.TensorProto.FLOAT, []))])" + }, + { + "summary": "loop_16_none", + "code": "# Given a tensor x of values [x1, ..., xN], and an initial optional sequence of tensors s1,\n# Return a concatenated sequence of tensors of\n# [s1, [x1], [x1, x2], ..., [x1, ..., xN]]\n\nten_in_tp = onnx.helper.make_tensor_type_proto(onnx.TensorProto.FLOAT, None)\nseq_in_tp = onnx.helper.make_sequence_type_proto(ten_in_tp)\nopt_in_tp = onnx.helper.make_optional_type_proto(seq_in_tp)\nopt_in = onnx.helper.make_value_info('opt_seq_in', opt_in_tp)\nseq_out = onnx.helper.make_tensor_sequence_value_info('seq_out', onnx.TensorProto.FLOAT, None)\ncond_in = onnx.helper.make_tensor_value_info('cond_in', onnx.TensorProto.BOOL, [])\ncond_out = onnx.helper.make_tensor_value_info('cond_out', onnx.TensorProto.BOOL, [])\niter_count = onnx.helper.make_tensor_value_info('iter_count', onnx.TensorProto.INT64, [])\n\nx = np.array([1, 2, 3, 4, 5]).astype(np.float32)\n\noptional_has_elem_node = onnx.helper.make_node(\n 'OptionalHasElement',\n inputs=['opt_seq_in'],\n outputs=['optional_has_elem']\n)\n\noptional_is_none = onnx.helper.make_node(\n 'Not',\n inputs=['optional_has_elem'],\n outputs=['optional_is_none']\n)\n\noptional_get_elem = onnx.helper.make_node(\n 'OptionalGetElement',\n inputs=['opt_seq_in'],\n outputs=['seq_in']\n)\n\nseq_empty_in = onnx.helper.make_node(\n 'SequenceEmpty',\n inputs=[],\n outputs=['seq_empty']\n)\n\nthen_seq_out = onnx.helper.make_tensor_sequence_value_info('seq_out', onnx.TensorProto.FLOAT, None)\nthen_body = onnx.helper.make_graph(\n [seq_empty_in],\n 'then_body',\n [],\n [then_seq_out]\n)\n\nelse_seq_out = onnx.helper.make_tensor_sequence_value_info('seq_out', onnx.TensorProto.FLOAT, None)\nelse_body = onnx.helper.make_graph(\n [optional_get_elem],\n 'else_body',\n [opt_in],\n [else_seq_out]\n)\n\nif_node = onnx.helper.make_node(\n 'If',\n inputs=['optional_is_none'],\n outputs=['sequence'],\n then_branch=then_body,\n else_branch=else_body\n)\n\nx_const_node = onnx.helper.make_node(\n 'Constant',\n inputs=[],\n outputs=['x'],\n value=onnx.helper.make_tensor(\n name='const_tensor_x',\n data_type=onnx.TensorProto.FLOAT,\n dims=x.shape,\n vals=x.flatten().astype(float),\n )\n)\n\none_const_node = onnx.helper.make_node(\n 'Constant',\n inputs=[],\n outputs=['one'],\n value=onnx.helper.make_tensor(\n name='const_tensor_one',\n data_type=onnx.TensorProto.INT64,\n dims=(),\n vals=[1]\n )\n)\n\nzero_const_node = onnx.helper.make_node(\n 'Constant',\n inputs=[],\n outputs=['slice_start'],\n value=onnx.helper.make_tensor(\n name='const_tensor_zero',\n data_type=onnx.TensorProto.INT64,\n dims=(1,),\n vals=[0]\n )\n)\n\naxes_node = onnx.helper.make_node(\n 'Constant',\n inputs=[],\n outputs=['axes'],\n value=onnx.helper.make_tensor(\n name='const_tensor_axes',\n data_type=onnx.TensorProto.INT64,\n dims=(),\n vals=[0]\n )\n)\n\nadd_node = onnx.helper.make_node(\n 'Add',\n inputs=['iter_count', 'one'],\n outputs=['end']\n)\n\nend_unsqueeze_node = onnx.helper.make_node(\n 'Unsqueeze',\n inputs=['end', 'axes'],\n outputs=['slice_end']\n)\n\nslice_node = onnx.helper.make_node(\n 'Slice',\n inputs=['x', 'slice_start', 'slice_end'],\n outputs=['slice_out']\n)\n\ninsert_node = onnx.helper.make_node(\n 'SequenceInsert',\n inputs=['sequence', 'slice_out'],\n outputs=['seq_out']\n)\n\nidentity_node = onnx.helper.make_node(\n 'Identity',\n inputs=['cond_in'],\n outputs=['cond_out']\n)\n\nloop_body = onnx.helper.make_graph(\n [identity_node, optional_has_elem_node, optional_is_none, if_node, x_const_node, one_const_node,\n zero_const_node, add_node, axes_node, end_unsqueeze_node, slice_node, insert_node],\n 'loop_body',\n [iter_count, cond_in, opt_in],\n [cond_out, seq_out]\n)\n\nnode = onnx.helper.make_node(\n 'Loop',\n inputs=['trip_count', 'cond', 'opt_seq'],\n outputs=['seq_res'],\n body=loop_body\n)\n\ntrip_count = np.array(5).astype(np.int64)\ncond = np.array(1).astype(bool)\nseq_empty = [] # type: List[Any]\nseq_res = compute_loop_outputs(x, seq_empty, trip_count)\nexpect(node, inputs=[trip_count, cond, seq_empty], outputs=[seq_res],\n name='test_loop16_seq_none', opset_imports=[onnx.helper.make_opsetid(\"\", 16)],\n input_type_protos=[onnx.helper.make_tensor_type_proto(onnx.TensorProto.INT64, trip_count.shape),\n onnx.helper.make_tensor_type_proto(onnx.TensorProto.BOOL, cond.shape),\n opt_in_tp])" + } + ] + }, + { + "name": "Loop", + "module": "ai.onnx", + "version": 16, + "support_level": "common", + "description": "Generic Looping construct. This loop has multiple termination conditions:\n\n1) Trip count. Iteration count specified at runtime. Set by\n specifying the input M. Optional. Set to empty string to omit.\n Note that a static trip count (specified at graph construction time) can be\n specified by passing in a constant node for input M.\n2) Loop termination condition. This is an input to the op that determines\n whether to run the first iteration and also a loop-carried dependency for\n the body graph. The body graph must yield a value for the condition variable,\n whether this input is provided or not.\n\nThis table summarizes the operating modes of this operator with equivalent\nC-style code:\n\n Operator inputs defined as (max_trip_count, condition_var).\n\n input (\"\", \"\"):\n for (int i=0; ; ++i) {\n cond = ... // Note this value is ignored, but is required in the body\n }\n\n input (\"\", cond) // Note this is analogous to a while loop\n bool cond = ...;\n for (int i=0; cond; ++i) {\n cond = ...;\n }\n\n input (\"\", 1) // Note this is analogous to a do-while loop\n bool cond = true\n for (int i=0; cond; ++i) {\n cond = ...;\n }\n\n input (trip_count, \"\") // Note this is analogous to a for loop\n int trip_count = ...\n for (int i=0; i < trip_count; ++i) {\n cond = ...; // ignored\n }\n\n input (trip_count, cond)\n int trip_count = ...;\n bool cond = ...;\n for (int i=0; i < trip_count && cond; ++i) {\n cond = ...;\n }\n\n\n*Sample usage - cond as well as trip count*\n\n graph predict-net {\n %a = Constant[value = ]()\n %b = Constant[value = ]()\n %keepgoing = Constant[value = ]()\n %max_trip_count = Constant[value = ]()\n %keepgoing_out, %b_out, %user_defined_vals = Loop[body = ](%max_trip_count, %keepgoing, %b)\n return\n }\n\n graph body-net (\n %i[INT32, scalar] // iteration number\n %keepgoing_in[BOOL, scalar] // incoming loop-termination-condition; not used\n %b_in[INT32, scalar] // incoming value of loop-carried-dependency b\n ) {\n %my_local = Add(%a, %b_in)\n %b_out = Sub(%a, %b_in) // outgoing value of loop-carried-dependency b\n %keepgoing_out = Greater(%my_local, %b_out) // outgoing loop-termination-condition\n %user_defined_val = Add(%b_in, %b_in) // scan-output value to be accumulated\n return %keepgoing_out, %b_out, %user_defined_val\n }\n\n*Sample equivalent C code*\n\n {\n /* User-defined code (enclosing scope) */\n int a = 3, b = 6;\n bool keepgoing = true; // Analogous to input cond\n /* End user-defined code */\n\n /* Implicitly-defined code */\n const int max_trip_count = 10; // Analogous to input M\n int user_defined_vals[]; // Imagine this is resizable\n /* End implicitly-defined code */\n /* initialize loop-carried variables and scan-output variables */\n bool keepgoing_out = keepgoing\n int b_out = b\n\n for (int i=0; i < max_trip_count && keepgoing_out; ++i) {\n /* Implicitly-defined code: bind actual parameter values\n to formal parameter variables of loop-body */\n bool keepgoing_in = keepgoing_out;\n bool b_in = b_out;\n\n /* User-defined code (loop body) */\n int my_local = a + b_in; // Reading value \"a\" from the enclosing scope is fine\n b_out = a - b_in;\n keepgoing_out = my_local > b_out;\n user_defined_val = b_in + b_in; // b_in and b_out are different variables\n /* End user-defined code */\n\n /* Implicitly defined-code */\n user_defined_vals[i] = user_defined_val // accumulate scan-output values\n }\n // int t = my_local; // Can't do this. my_local is not accessible here.\n\n // The values below are bound to the output variables of the loop and therefore accessible\n // b_out; user_defined_vals; keepgoing_out;\n }\n\nThere are several things of note in this code snippet:\n\n1) Values from the enclosing scope (i.e. variable \"a\" here) are in scope and can\n be referenced in the inputs of the loop.\n2) Any values computed in the loop body that needs to be used in a subsequent\n iteration or after the loop are modelled using a pair of variables in the loop-body,\n consisting of an input variable (eg., b_in) and an output variable (eg., b_out).\n These are referred to as loop-carried dependences. The loop operation node\n supplies the input value of the input variable for the first iteration, and\n returns the output value of the output variable produced by the final\n iteration.\n3) Scan_output variables are used to implicitly concatenate values computed across\n all the iterations. In the above example, the value of user_defined_val computed\n over all iterations are concatenated and returned as the value of user_defined_vals\n after the loop.\n4) Values created in the body cannot be accessed in the enclosing scope,\n except using the mechanism described above.\n\nNote that the semantics of this op support \"diagonal\" or \"wavefront\" execution.\n(See Step 3 here for an example:\nhttps://devblogs.nvidia.com/optimizing-recurrent-neural-networks-cudnn-5/).\nFrontends should emit multi-layer RNNs as a series of While operators (with\ntime being the inner looping dimension), with each successive layer consuming\nthe scan_outputs from the previous layer, possibly going through several\npoint-wise operators (e.g. dropout, residual connections, linear layer).\n\nThe 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.\n", + "attributes": [ + { + "name": "body", + "type": "graph", + "required": true, + "description": "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": [ + { + "name": "M", + "type": "I", + "option": "optional", + "description": "A maximum trip-count for the loop specified at runtime. Optional. Pass empty string to skip." + }, + { + "name": "cond", + "type": "B", + "option": "optional", + "description": "A boolean termination condition. Optional. Pass empty string to skip." + }, + { + "name": "v_initial", + "type": "V", + "list": true, + "description": "The initial values of any loop-carried dependencies (values that change across loop iterations)" + } + ], + "min_input": 2, + "max_input": 2147483647, + "outputs": [ + { + "name": "v_final_and_scan_outputs", + "type": "V", + "list": true, + "description": "Final N loop carried dependency values then K scan_outputs. Scan outputs must be Tensors." + } + ], + "min_output": 1, + "max_output": 2147483647, + "inputs_range": "2 - ∞", + "outputs_range": "1 - ∞", + "type_constraints": [ + { + "description": "All Tensor and Sequence types", + "type_param_str": "V", + "allowed_type_strs": [ + "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))" + ] + }, + { + "description": "tensor of int64, which should be a scalar.", + "type_param_str": "I", + "allowed_type_strs": [ + "tensor(int64)" + ] + }, + { + "description": "tensor of bool, which should be a scalar.", + "type_param_str": "B", + "allowed_type_strs": [ + "tensor(bool)" + ] + } + ], + "examples": [ + { + "summary": "loop_11", + "code": "# Given a tensor x of values [x1, ..., xN], and initial tensor y\n# sum up its elements using a scan\n# returning the final state (y+x1+x2+...+xN) as well the scan_output\n# [y+x1, y+x1+x2, ..., y+x1+x2+...+xN]\n\ny_in = onnx.helper.make_tensor_value_info('y_in', onnx.TensorProto.FLOAT, [1])\ny_out = onnx.helper.make_tensor_value_info('y_out', onnx.TensorProto.FLOAT, [1])\nscan_out = onnx.helper.make_tensor_value_info('scan_out', onnx.TensorProto.FLOAT, [1])\ncond_in = onnx.helper.make_tensor_value_info('cond_in', onnx.TensorProto.BOOL, [])\ncond_out = onnx.helper.make_tensor_value_info('cond_out', onnx.TensorProto.BOOL, [])\niter_count = onnx.helper.make_tensor_value_info('iter_count', onnx.TensorProto.INT64, [])\n\nx = np.array([1, 2, 3, 4, 5]).astype(np.float32)\ny = np.array([-2]).astype(np.float32)\n\nx_const_node = onnx.helper.make_node(\n 'Constant',\n inputs=[],\n outputs=['x'],\n value=onnx.helper.make_tensor(\n name='const_tensor_x',\n data_type=onnx.TensorProto.FLOAT,\n dims=x.shape,\n vals=x.flatten().astype(float),\n )\n)\n\none_const_node = onnx.helper.make_node(\n 'Constant',\n inputs=[],\n outputs=['one'],\n value=onnx.helper.make_tensor(\n name='const_tensor_one',\n data_type=onnx.TensorProto.INT64,\n dims=(),\n vals=[1]\n )\n)\n\ni_add_node = onnx.helper.make_node(\n 'Add',\n inputs=['iter_count', 'one'],\n outputs=['end']\n)\n\nstart_unsqueeze_node = onnx.helper.make_node(\n 'Unsqueeze',\n inputs=['iter_count'],\n outputs=['slice_start'],\n axes=[0]\n)\n\nend_unsqueeze_node = onnx.helper.make_node(\n 'Unsqueeze',\n inputs=['end'],\n outputs=['slice_end'],\n axes=[0]\n)\n\nslice_node = onnx.helper.make_node(\n 'Slice',\n inputs=['x', 'slice_start', 'slice_end'],\n outputs=['slice_out']\n)\n\ny_add_node = onnx.helper.make_node(\n 'Add',\n inputs=['y_in', 'slice_out'],\n outputs=['y_out']\n)\n\nidentity_node = onnx.helper.make_node(\n 'Identity',\n inputs=['cond_in'],\n outputs=['cond_out']\n)\n\nscan_identity_node = onnx.helper.make_node(\n 'Identity',\n inputs=['y_out'],\n outputs=['scan_out']\n)\n\nloop_body = onnx.helper.make_graph(\n [identity_node, x_const_node, one_const_node, i_add_node,\n start_unsqueeze_node, end_unsqueeze_node, slice_node, y_add_node,\n scan_identity_node],\n 'loop_body',\n [iter_count, cond_in, y_in],\n [cond_out, y_out, scan_out]\n)\n\nnode = onnx.helper.make_node(\n 'Loop',\n inputs=['trip_count', 'cond', 'y'],\n outputs=['res_y', 'res_scan'],\n body=loop_body\n)\n\ntrip_count = np.array(5).astype(np.int64)\nres_y = np.array([13]).astype(np.float32)\ncond = np.array(1).astype(bool)\nres_scan = np.array([-1, 1, 4, 8, 13]).astype(np.float32).reshape((5, 1))\nexpect(node, inputs=[trip_count, cond, y], outputs=[res_y, res_scan],\n name='test_loop11', opset_imports=[onnx.helper.make_opsetid(\"\", 11)])" + }, + { + "summary": "loop_13", + "code": "# Given a tensor x of values [x1, ..., xN],\n# Return a sequence of tensors of\n# [[x1], [x1, x2], ..., [x1, ..., xN]]\n\nseq_in = onnx.helper.make_tensor_sequence_value_info('seq_in', onnx.TensorProto.FLOAT, None)\nseq_out = onnx.helper.make_tensor_sequence_value_info('seq_out', onnx.TensorProto.FLOAT, None)\ncond_in = onnx.helper.make_tensor_value_info('cond_in', onnx.TensorProto.BOOL, [])\ncond_out = onnx.helper.make_tensor_value_info('cond_out', onnx.TensorProto.BOOL, [])\niter_count = onnx.helper.make_tensor_value_info('iter_count', onnx.TensorProto.INT64, [])\n\nx = np.array([1, 2, 3, 4, 5]).astype(np.float32)\n\nx_const_node = onnx.helper.make_node(\n 'Constant',\n inputs=[],\n outputs=['x'],\n value=onnx.helper.make_tensor(\n name='const_tensor_x',\n data_type=onnx.TensorProto.FLOAT,\n dims=x.shape,\n vals=x.flatten().astype(float),\n )\n)\n\none_const_node = onnx.helper.make_node(\n 'Constant',\n inputs=[],\n outputs=['one'],\n value=onnx.helper.make_tensor(\n name='const_tensor_one',\n data_type=onnx.TensorProto.INT64,\n dims=(),\n vals=[1]\n )\n)\n\nzero_const_node = onnx.helper.make_node(\n 'Constant',\n inputs=[],\n outputs=['slice_start'],\n value=onnx.helper.make_tensor(\n name='const_tensor_zero',\n data_type=onnx.TensorProto.INT64,\n dims=(1,),\n vals=[0]\n )\n)\n\naxes_node = onnx.helper.make_node(\n 'Constant',\n inputs=[],\n outputs=['axes'],\n value=onnx.helper.make_tensor(\n name='const_tensor_axes',\n data_type=onnx.TensorProto.INT64,\n dims=(),\n vals=[0]\n )\n)\n\nadd_node = onnx.helper.make_node(\n 'Add',\n inputs=['iter_count', 'one'],\n outputs=['end']\n)\n\nend_unsqueeze_node = onnx.helper.make_node(\n 'Unsqueeze',\n inputs=['end', 'axes'],\n outputs=['slice_end']\n)\n\nslice_node = onnx.helper.make_node(\n 'Slice',\n inputs=['x', 'slice_start', 'slice_end'],\n outputs=['slice_out']\n)\n\ninsert_node = onnx.helper.make_node(\n 'SequenceInsert',\n inputs=['seq_in', 'slice_out'],\n outputs=['seq_out']\n)\n\nidentity_node = onnx.helper.make_node(\n 'Identity',\n inputs=['cond_in'],\n outputs=['cond_out']\n)\n\nloop_body = onnx.helper.make_graph(\n [identity_node, x_const_node, one_const_node, zero_const_node, add_node,\n axes_node, end_unsqueeze_node, slice_node, insert_node],\n 'loop_body',\n [iter_count, cond_in, seq_in],\n [cond_out, seq_out]\n)\n\nnode = onnx.helper.make_node(\n 'Loop',\n inputs=['trip_count', 'cond', 'seq_empty'],\n outputs=['seq_res'],\n body=loop_body\n)\n\ntrip_count = np.array(5).astype(np.int64)\nseq_empty = [] # type: List[Any]\nseq_res = [x[:int(i)] for i in x]\ncond = np.array(1).astype(bool)\nexpect(node, inputs=[trip_count, cond, seq_empty], outputs=[seq_res],\n name='test_loop13_seq', opset_imports=[onnx.helper.make_opsetid(\"\", 13)],\n input_type_protos=[onnx.helper.make_tensor_type_proto(onnx.TensorProto.INT64, trip_count.shape),\n onnx.helper.make_tensor_type_proto(onnx.TensorProto.BOOL, cond.shape),\n onnx.helper.make_sequence_type_proto(\n onnx.helper.make_tensor_type_proto(onnx.TensorProto.FLOAT, []))])" + }, + { + "summary": "loop_16_none", + "code": "# Given a tensor x of values [x1, ..., xN], and an initial optional sequence of tensors s1,\n# Return a concatenated sequence of tensors of\n# [s1, [x1], [x1, x2], ..., [x1, ..., xN]]\n\nten_in_tp = onnx.helper.make_tensor_type_proto(onnx.TensorProto.FLOAT, None)\nseq_in_tp = onnx.helper.make_sequence_type_proto(ten_in_tp)\nopt_in_tp = onnx.helper.make_optional_type_proto(seq_in_tp)\nopt_in = onnx.helper.make_value_info('opt_seq_in', opt_in_tp)\nseq_out = onnx.helper.make_tensor_sequence_value_info('seq_out', onnx.TensorProto.FLOAT, None)\ncond_in = onnx.helper.make_tensor_value_info('cond_in', onnx.TensorProto.BOOL, [])\ncond_out = onnx.helper.make_tensor_value_info('cond_out', onnx.TensorProto.BOOL, [])\niter_count = onnx.helper.make_tensor_value_info('iter_count', onnx.TensorProto.INT64, [])\n\nx = np.array([1, 2, 3, 4, 5]).astype(np.float32)\n\noptional_has_elem_node = onnx.helper.make_node(\n 'OptionalHasElement',\n inputs=['opt_seq_in'],\n outputs=['optional_has_elem']\n)\n\noptional_is_none = onnx.helper.make_node(\n 'Not',\n inputs=['optional_has_elem'],\n outputs=['optional_is_none']\n)\n\noptional_get_elem = onnx.helper.make_node(\n 'OptionalGetElement',\n inputs=['opt_seq_in'],\n outputs=['seq_in']\n)\n\nseq_empty_in = onnx.helper.make_node(\n 'SequenceEmpty',\n inputs=[],\n outputs=['seq_empty']\n)\n\nthen_seq_out = onnx.helper.make_tensor_sequence_value_info('seq_out', onnx.TensorProto.FLOAT, None)\nthen_body = onnx.helper.make_graph(\n [seq_empty_in],\n 'then_body',\n [],\n [then_seq_out]\n)\n\nelse_seq_out = onnx.helper.make_tensor_sequence_value_info('seq_out', onnx.TensorProto.FLOAT, None)\nelse_body = onnx.helper.make_graph(\n [optional_get_elem],\n 'else_body',\n [opt_in],\n [else_seq_out]\n)\n\nif_node = onnx.helper.make_node(\n 'If',\n inputs=['optional_is_none'],\n outputs=['sequence'],\n then_branch=then_body,\n else_branch=else_body\n)\n\nx_const_node = onnx.helper.make_node(\n 'Constant',\n inputs=[],\n outputs=['x'],\n value=onnx.helper.make_tensor(\n name='const_tensor_x',\n data_type=onnx.TensorProto.FLOAT,\n dims=x.shape,\n vals=x.flatten().astype(float),\n )\n)\n\none_const_node = onnx.helper.make_node(\n 'Constant',\n inputs=[],\n outputs=['one'],\n value=onnx.helper.make_tensor(\n name='const_tensor_one',\n data_type=onnx.TensorProto.INT64,\n dims=(),\n vals=[1]\n )\n)\n\nzero_const_node = onnx.helper.make_node(\n 'Constant',\n inputs=[],\n outputs=['slice_start'],\n value=onnx.helper.make_tensor(\n name='const_tensor_zero',\n data_type=onnx.TensorProto.INT64,\n dims=(1,),\n vals=[0]\n )\n)\n\naxes_node = onnx.helper.make_node(\n 'Constant',\n inputs=[],\n outputs=['axes'],\n value=onnx.helper.make_tensor(\n name='const_tensor_axes',\n data_type=onnx.TensorProto.INT64,\n dims=(),\n vals=[0]\n )\n)\n\nadd_node = onnx.helper.make_node(\n 'Add',\n inputs=['iter_count', 'one'],\n outputs=['end']\n)\n\nend_unsqueeze_node = onnx.helper.make_node(\n 'Unsqueeze',\n inputs=['end', 'axes'],\n outputs=['slice_end']\n)\n\nslice_node = onnx.helper.make_node(\n 'Slice',\n inputs=['x', 'slice_start', 'slice_end'],\n outputs=['slice_out']\n)\n\ninsert_node = onnx.helper.make_node(\n 'SequenceInsert',\n inputs=['sequence', 'slice_out'],\n outputs=['seq_out']\n)\n\nidentity_node = onnx.helper.make_node(\n 'Identity',\n inputs=['cond_in'],\n outputs=['cond_out']\n)\n\nloop_body = onnx.helper.make_graph(\n [identity_node, optional_has_elem_node, optional_is_none, if_node, x_const_node, one_const_node,\n zero_const_node, add_node, axes_node, end_unsqueeze_node, slice_node, insert_node],\n 'loop_body',\n [iter_count, cond_in, opt_in],\n [cond_out, seq_out]\n)\n\nnode = onnx.helper.make_node(\n 'Loop',\n inputs=['trip_count', 'cond', 'opt_seq'],\n outputs=['seq_res'],\n body=loop_body\n)\n\ntrip_count = np.array(5).astype(np.int64)\ncond = np.array(1).astype(bool)\nseq_empty = [] # type: List[Any]\nseq_res = compute_loop_outputs(x, seq_empty, trip_count)\nexpect(node, inputs=[trip_count, cond, seq_empty], outputs=[seq_res],\n name='test_loop16_seq_none', opset_imports=[onnx.helper.make_opsetid(\"\", 16)],\n input_type_protos=[onnx.helper.make_tensor_type_proto(onnx.TensorProto.INT64, trip_count.shape),\n onnx.helper.make_tensor_type_proto(onnx.TensorProto.BOOL, cond.shape),\n opt_in_tp])" + } + ] + }, + { + "name": "LpNormalization", + "module": "ai.onnx", + "version": 1, + "support_level": "common", + "description": "Given a matrix, apply Lp-normalization along the provided axis.\n", + "attributes": [ + { + "name": "axis", + "type": "int64", + "required": false, + "default": -1, + "description": "The axis on which to apply normalization, -1 mean last axis." + }, + { + "name": "p", + "type": "int64", + "required": false, + "default": 2, + "description": "The order of the normalization, only 1 or 2 are supported." + } + ], + "inputs": [ + { + "name": "input", + "type": "T", + "description": "Input matrix" + } + ], + "min_input": 1, + "max_input": 1, + "outputs": [ + { + "name": "output", + "type": "T", + "description": "Matrix after normalization" + } + ], + "min_output": 1, + "max_output": 1, + "type_constraints": [ + { + "description": "Constrain input and output types to float tensors.", + "type_param_str": "T", + "allowed_type_strs": [ + "tensor(float16)", + "tensor(float)", + "tensor(double)" + ] + } + ], + "category": "Normalization" + }, + { + "name": "LpPool", + "module": "ai.onnx", + "version": 1, + "support_level": "common", + "description": "LpPool consumes an input tensor X and applies Lp pooling across the\n the tensor according to kernel sizes, stride sizes, and pad lengths.\n Lp pooling consisting of computing the Lp norm on all values of a subset\n of the input tensor according to the kernel size and downsampling the\n data into the output tensor Y for further processing.", + "attributes": [ + { + "name": "auto_pad", + "type": "string", + "required": false, + "default": "NOTSET", + "description": "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." + }, + { + "name": "kernel_shape", + "type": "int64[]", + "required": false, + "description": "The size of the kernel along each axis." + }, + { + "name": "p", + "type": "float32", + "required": false, + "default": 2.0, + "description": "p value of the Lp norm used to pool over the input data, default is 2.0." + }, + { + "name": "pads", + "type": "int64[]", + "required": false, + "description": "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." + }, + { + "name": "strides", + "type": "int64[]", + "required": false, + "description": "Stride along each axis." + } + ], + "inputs": [ + { + "name": "X", + "type": "T", + "description": "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." + } + ], + "min_input": 1, + "max_input": 1, + "outputs": [ + { + "name": "Y", + "type": "T", + "description": "Output data tensor from Lp pooling across the input tensor. Dimensions will vary based on various kernel, stride, and pad sizes." + } + ], + "min_output": 1, + "max_output": 1, + "type_constraints": [ + { + "description": "Constrain input and output types to float tensors.", + "type_param_str": "T", + "allowed_type_strs": [ + "tensor(float16)", + "tensor(float)", + "tensor(double)" + ] + } + ], + "category": "Pool" + }, + { + "name": "LpPool", + "module": "ai.onnx", + "version": 2, + "support_level": "common", + "description": "LpPool consumes an input tensor X and applies Lp pooling across\n the tensor according to kernel sizes, stride sizes, and pad lengths.\n Lp pooling consisting of computing the Lp norm on all values of a subset\n of the input tensor according to the kernel size and downsampling the\n data into the output tensor Y for further processing.", + "attributes": [ + { + "name": "auto_pad", + "type": "string", + "required": false, + "default": "NOTSET", + "description": "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." + }, + { + "name": "kernel_shape", + "type": "int64[]", + "required": true, + "description": "The size of the kernel along each axis." + }, + { + "name": "p", + "type": "int64", + "required": false, + "default": 2, + "description": "p value of the Lp norm used to pool over the input data." + }, + { + "name": "pads", + "type": "int64[]", + "required": false, + "description": "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." + }, + { + "name": "strides", + "type": "int64[]", + "required": false, + "description": "Stride along each spatial axis." + } + ], + "inputs": [ + { + "name": "X", + "type": "T", + "description": "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." + } + ], + "min_input": 1, + "max_input": 1, + "outputs": [ + { + "name": "Y", + "type": "T", + "description": "Output data tensor from Lp pooling across the input tensor. Dimensions will vary based on various kernel, stride, and pad sizes." + } + ], + "min_output": 1, + "max_output": 1, + "type_constraints": [ + { + "description": "Constrain input and output types to float tensors.", + "type_param_str": "T", + "allowed_type_strs": [ + "tensor(float16)", + "tensor(float)", + "tensor(double)" + ] + } + ], + "category": "Pool" + }, + { + "name": "LpPool", + "module": "ai.onnx", + "version": 11, + "support_level": "common", + "description": "LpPool consumes an input tensor X and applies Lp pooling across\n the tensor according to kernel sizes, stride sizes, and pad lengths.\n Lp pooling consisting of computing the Lp norm on all values of a subset\n of the input tensor according to the kernel size and downsampling the\n data into the output tensor Y for further processing.", + "attributes": [ + { + "name": "auto_pad", + "type": "string", + "required": false, + "default": "NOTSET", + "description": "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." + }, + { + "name": "kernel_shape", + "type": "int64[]", + "required": true, + "description": "The size of the kernel along each axis." + }, + { + "name": "p", + "type": "int64", + "required": false, + "default": 2, + "description": "p value of the Lp norm used to pool over the input data." + }, + { + "name": "pads", + "type": "int64[]", + "required": false, + "description": "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." + }, + { + "name": "strides", + "type": "int64[]", + "required": false, + "description": "Stride along each spatial axis. If not present, the stride defaults to 1 along each spatial axis." + } + ], + "inputs": [ + { + "name": "X", + "type": "T", + "description": "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." + } + ], + "min_input": 1, + "max_input": 1, + "outputs": [ + { + "name": "Y", + "type": "T", + "description": "Output data tensor from Lp pooling across the input tensor. Dimensions will vary based on various kernel, stride, and pad sizes." + } + ], + "min_output": 1, + "max_output": 1, + "type_constraints": [ + { + "description": "Constrain input and output types to float tensors.", + "type_param_str": "T", + "allowed_type_strs": [ + "tensor(float16)", + "tensor(float)", + "tensor(double)" + ] + } + ], + "category": "Pool" + }, + { + "name": "MatMul", + "module": "ai.onnx", + "version": 1, + "support_level": "common", + "description": "Matrix product that behaves like numpy.matmul: https://docs.scipy.org/doc/numpy-1.13.0/reference/generated/numpy.matmul.html\n", + "inputs": [ + { + "name": "A", + "type": "T", + "description": "N-dimensional matrix A" + }, + { + "name": "B", + "type": "T", + "description": "N-dimensional matrix B" + } + ], + "min_input": 2, + "max_input": 2, + "outputs": [ + { + "name": "Y", + "type": "T", + "description": "Matrix multiply results from A * B" + } + ], + "min_output": 1, + "max_output": 1, + "type_constraints": [ + { + "description": "Constrain input and output types to float tensors.", + "type_param_str": "T", + "allowed_type_strs": [ + "tensor(float16)", + "tensor(float)", + "tensor(double)" + ] + } + ], + "examples": [ + { + "summary": "matmul", + "code": "node = onnx.helper.make_node(\n 'MatMul',\n inputs=['a', 'b'],\n outputs=['c'],\n)\n\n# 2d\na = np.random.randn(3, 4).astype(np.float32)\nb = np.random.randn(4, 3).astype(np.float32)\nc = np.matmul(a, b)\nexpect(node, inputs=[a, b], outputs=[c],\n name='test_matmul_2d')\n\n# 3d\na = np.random.randn(2, 3, 4).astype(np.float32)\nb = np.random.randn(2, 4, 3).astype(np.float32)\nc = np.matmul(a, b)\nexpect(node, inputs=[a, b], outputs=[c],\n name='test_matmul_3d')\n\n# 4d\na = np.random.randn(1, 2, 3, 4).astype(np.float32)\nb = np.random.randn(1, 2, 4, 3).astype(np.float32)\nc = np.matmul(a, b)\nexpect(node, inputs=[a, b], outputs=[c],\n name='test_matmul_4d')" + } + ] + }, + { + "name": "MatMul", + "module": "ai.onnx", + "version": 9, + "support_level": "common", + "description": "Matrix product that behaves like numpy.matmul: https://docs.scipy.org/doc/numpy-1.13.0/reference/generated/numpy.matmul.html\n", + "inputs": [ + { + "name": "A", + "type": "T", + "description": "N-dimensional matrix A" + }, + { + "name": "B", + "type": "T", + "description": "N-dimensional matrix B" + } + ], + "min_input": 2, + "max_input": 2, + "outputs": [ + { + "name": "Y", + "type": "T", + "description": "Matrix multiply results from A * B" + } + ], + "min_output": 1, + "max_output": 1, + "type_constraints": [ + { + "description": "Constrain input and output types to float/int tensors.", + "type_param_str": "T", + "allowed_type_strs": [ + "tensor(float16)", + "tensor(float)", + "tensor(double)", + "tensor(uint32)", + "tensor(uint64)", + "tensor(int32)", + "tensor(int64)" + ] + } + ], + "examples": [ + { + "summary": "matmul", + "code": "node = onnx.helper.make_node(\n 'MatMul',\n inputs=['a', 'b'],\n outputs=['c'],\n)\n\n# 2d\na = np.random.randn(3, 4).astype(np.float32)\nb = np.random.randn(4, 3).astype(np.float32)\nc = np.matmul(a, b)\nexpect(node, inputs=[a, b], outputs=[c],\n name='test_matmul_2d')\n\n# 3d\na = np.random.randn(2, 3, 4).astype(np.float32)\nb = np.random.randn(2, 4, 3).astype(np.float32)\nc = np.matmul(a, b)\nexpect(node, inputs=[a, b], outputs=[c],\n name='test_matmul_3d')\n\n# 4d\na = np.random.randn(1, 2, 3, 4).astype(np.float32)\nb = np.random.randn(1, 2, 4, 3).astype(np.float32)\nc = np.matmul(a, b)\nexpect(node, inputs=[a, b], outputs=[c],\n name='test_matmul_4d')" + } + ] + }, + { + "name": "MatMul", + "module": "ai.onnx", + "version": 13, + "support_level": "common", + "description": "Matrix product that behaves like numpy.matmul: https://docs.scipy.org/doc/numpy-1.13.0/reference/generated/numpy.matmul.html\n", + "inputs": [ + { + "name": "A", + "type": "T", + "description": "N-dimensional matrix A" + }, + { + "name": "B", + "type": "T", + "description": "N-dimensional matrix B" + } + ], + "min_input": 2, + "max_input": 2, + "outputs": [ + { + "name": "Y", + "type": "T", + "description": "Matrix multiply results from A * B" + } + ], + "min_output": 1, + "max_output": 1, + "type_constraints": [ + { + "description": "Constrain input and output types to float/int tensors.", + "type_param_str": "T", + "allowed_type_strs": [ + "tensor(float16)", + "tensor(float)", + "tensor(double)", + "tensor(uint32)", + "tensor(uint64)", + "tensor(int32)", + "tensor(int64)", + "tensor(bfloat16)" + ] + } + ], + "examples": [ + { + "summary": "matmul", + "code": "node = onnx.helper.make_node(\n 'MatMul',\n inputs=['a', 'b'],\n outputs=['c'],\n)\n\n# 2d\na = np.random.randn(3, 4).astype(np.float32)\nb = np.random.randn(4, 3).astype(np.float32)\nc = np.matmul(a, b)\nexpect(node, inputs=[a, b], outputs=[c],\n name='test_matmul_2d')\n\n# 3d\na = np.random.randn(2, 3, 4).astype(np.float32)\nb = np.random.randn(2, 4, 3).astype(np.float32)\nc = np.matmul(a, b)\nexpect(node, inputs=[a, b], outputs=[c],\n name='test_matmul_3d')\n\n# 4d\na = np.random.randn(1, 2, 3, 4).astype(np.float32)\nb = np.random.randn(1, 2, 4, 3).astype(np.float32)\nc = np.matmul(a, b)\nexpect(node, inputs=[a, b], outputs=[c],\n name='test_matmul_4d')" + } + ] + }, + { + "name": "MatMulInteger", + "module": "ai.onnx", + "version": 10, + "support_level": "common", + "description": "Matrix product that behaves like numpy.matmul: https://docs.scipy.org/doc/numpy-1.13.0/reference/generated/numpy.matmul.html.\nThe production MUST never overflow. The accumulation may overflow if and only if in 32 bits.\n", + "inputs": [ + { + "name": "A", + "type": "T1", + "description": "N-dimensional matrix A" + }, + { + "name": "B", + "type": "T2", + "description": "N-dimensional matrix B" + }, + { + "name": "a_zero_point", + "type": "T1", + "option": "optional", + "description": "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]. " + }, + { + "name": "b_zero_point", + "type": "T2", + "option": "optional", + "description": "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]. " + } + ], + "min_input": 2, + "max_input": 4, + "outputs": [ + { + "name": "Y", + "type": "T3", + "description": "Matrix multiply results from A * B" + } + ], + "min_output": 1, + "max_output": 1, + "inputs_range": "2 - 4", + "type_constraints": [ + { + "description": "Constrain input A data type to 8-bit integer tensor.", + "type_param_str": "T1", + "allowed_type_strs": [ + "tensor(int8)", + "tensor(uint8)" + ] + }, + { + "description": "Constrain input B data type to 8-bit integer tensor.", + "type_param_str": "T2", + "allowed_type_strs": [ + "tensor(int8)", + "tensor(uint8)" + ] + }, + { + "description": "Constrain output Y data type as 32-bit integer tensor.", + "type_param_str": "T3", + "allowed_type_strs": [ + "tensor(int32)" + ] + } + ], + "examples": [ + { + "summary": "matmulinteger", + "code": "node = onnx.helper.make_node('MatMulInteger',\n inputs=['A', 'B', 'a_zero_point', 'b_zero_point'],\n outputs=['Y'],)\n\nA = np.array([[11, 7, 3],\n [10, 6, 2],\n [9, 5, 1],\n [8, 4, 0], ], dtype=np.uint8)\n\na_zero_point = np.array([12], dtype=np.uint8)\n\nB = np.array([[1, 4],\n [2, 5],\n [3, 6], ], dtype=np.uint8)\n\nb_zero_point = np.array([0], dtype=np.uint8)\n\noutput = np.array([[-38, -83],\n [-44, -98],\n [-50, -113],\n [-56, -128], ], dtype=np.int32)\n\nexpect(node, inputs=[A, B, a_zero_point, b_zero_point], outputs=[output],\n name='test_matmulinteger')" + } + ] + }, + { + "name": "Max", + "module": "ai.onnx", + "version": 1, + "support_level": "common", + "description": "Element-wise max of each of the input tensors. All inputs and outputs must\nhave the same shape and data type.\n", + "attributes": [ + { + "name": "consumed_inputs", + "type": "int64[]", + "required": false, + "description": "legacy optimization attribute." + } + ], + "inputs": [ + { + "name": "data_0", + "type": "T", + "list": true, + "description": "List of tensors for Max." + } + ], + "min_input": 1, + "max_input": 2147483647, + "outputs": [ + { + "name": "max", + "type": "T", + "description": "Output tensor. Same dimension as inputs." + } + ], + "min_output": 1, + "max_output": 1, + "inputs_range": "1 - ∞", + "type_constraints": [ + { + "description": "Constrain input and output types to float tensors.", + "type_param_str": "T", + "allowed_type_strs": [ + "tensor(float16)", + "tensor(float)", + "tensor(double)" + ] + } + ], + "examples": [ + { + "summary": "max", + "code": "data_0 = np.array([3, 2, 1]).astype(np.float32)\ndata_1 = np.array([1, 4, 4]).astype(np.float32)\ndata_2 = np.array([2, 5, 3]).astype(np.float32)\nresult = np.array([3, 5, 4]).astype(np.float32)\nnode = onnx.helper.make_node(\n 'Max',\n inputs=['data_0', 'data_1', 'data_2'],\n outputs=['result'],\n)\nexpect(node, inputs=[data_0, data_1, data_2], outputs=[result],\n name='test_max_example')\n\nnode = onnx.helper.make_node(\n 'Max',\n inputs=['data_0'],\n outputs=['result'],\n)\nexpect(node, inputs=[data_0], outputs=[data_0],\n name='test_max_one_input')\n\nresult = np.maximum(data_0, data_1)\nnode = onnx.helper.make_node(\n 'Max',\n inputs=['data_0', 'data_1'],\n outputs=['result'],\n)\nexpect(node, inputs=[data_0, data_1], outputs=[result],\n name='test_max_two_inputs')" + }, + { + "summary": "max_all_numeric_types", + "code": "for op_dtype in all_numeric_dtypes:\n data_0 = np.array([3, 2, 1]).astype(op_dtype)\n data_1 = np.array([1, 4, 4]).astype(op_dtype)\n result = np.array([3, 4, 4]).astype(op_dtype)\n node = onnx.helper.make_node(\n 'Max',\n inputs=['data_0', 'data_1'],\n outputs=['result'],\n )\n expect(node, inputs=[data_0, data_1], outputs=[result],\n name='test_max_{0}'.format(np.dtype(op_dtype).name))" + } + ] + }, + { + "name": "Max", + "module": "ai.onnx", + "version": 6, + "support_level": "common", + "description": "Element-wise max of each of the input tensors. All inputs and outputs must\nhave the same shape and data type.\n", + "inputs": [ + { + "name": "data_0", + "type": "T", + "list": true, + "description": "List of tensors for Max." + } + ], + "min_input": 1, + "max_input": 2147483647, + "outputs": [ + { + "name": "max", + "type": "T", + "description": "Output tensor. Same dimension as inputs." + } + ], + "min_output": 1, + "max_output": 1, + "inputs_range": "1 - ∞", + "type_constraints": [ + { + "description": "Constrain input and output types to float tensors.", + "type_param_str": "T", + "allowed_type_strs": [ + "tensor(float16)", + "tensor(float)", + "tensor(double)" + ] + } + ], + "examples": [ + { + "summary": "max", + "code": "data_0 = np.array([3, 2, 1]).astype(np.float32)\ndata_1 = np.array([1, 4, 4]).astype(np.float32)\ndata_2 = np.array([2, 5, 3]).astype(np.float32)\nresult = np.array([3, 5, 4]).astype(np.float32)\nnode = onnx.helper.make_node(\n 'Max',\n inputs=['data_0', 'data_1', 'data_2'],\n outputs=['result'],\n)\nexpect(node, inputs=[data_0, data_1, data_2], outputs=[result],\n name='test_max_example')\n\nnode = onnx.helper.make_node(\n 'Max',\n inputs=['data_0'],\n outputs=['result'],\n)\nexpect(node, inputs=[data_0], outputs=[data_0],\n name='test_max_one_input')\n\nresult = np.maximum(data_0, data_1)\nnode = onnx.helper.make_node(\n 'Max',\n inputs=['data_0', 'data_1'],\n outputs=['result'],\n)\nexpect(node, inputs=[data_0, data_1], outputs=[result],\n name='test_max_two_inputs')" + }, + { + "summary": "max_all_numeric_types", + "code": "for op_dtype in all_numeric_dtypes:\n data_0 = np.array([3, 2, 1]).astype(op_dtype)\n data_1 = np.array([1, 4, 4]).astype(op_dtype)\n result = np.array([3, 4, 4]).astype(op_dtype)\n node = onnx.helper.make_node(\n 'Max',\n inputs=['data_0', 'data_1'],\n outputs=['result'],\n )\n expect(node, inputs=[data_0, data_1], outputs=[result],\n name='test_max_{0}'.format(np.dtype(op_dtype).name))" + } + ] + }, + { + "name": "Max", + "module": "ai.onnx", + "version": 8, + "support_level": "common", + "description": "Element-wise max of each of the input tensors (with Numpy-style broadcasting support).\nAll inputs and outputs must have the same data type.\nThis operator supports **multidirectional (i.e., Numpy-style) broadcasting**; for more details please check [the doc](https://github.com/onnx/onnx/blob/master/docs/Broadcasting.md).\n", + "inputs": [ + { + "name": "data_0", + "type": "T", + "list": true, + "description": "List of tensors for max." + } + ], + "min_input": 1, + "max_input": 2147483647, + "outputs": [ + { + "name": "max", + "type": "T", + "description": "Output tensor." + } + ], + "min_output": 1, + "max_output": 1, + "inputs_range": "1 - ∞", + "type_constraints": [ + { + "description": "Constrain input and output types to float tensors.", + "type_param_str": "T", + "allowed_type_strs": [ + "tensor(float16)", + "tensor(float)", + "tensor(double)" + ] + } + ], + "examples": [ + { + "summary": "max", + "code": "data_0 = np.array([3, 2, 1]).astype(np.float32)\ndata_1 = np.array([1, 4, 4]).astype(np.float32)\ndata_2 = np.array([2, 5, 3]).astype(np.float32)\nresult = np.array([3, 5, 4]).astype(np.float32)\nnode = onnx.helper.make_node(\n 'Max',\n inputs=['data_0', 'data_1', 'data_2'],\n outputs=['result'],\n)\nexpect(node, inputs=[data_0, data_1, data_2], outputs=[result],\n name='test_max_example')\n\nnode = onnx.helper.make_node(\n 'Max',\n inputs=['data_0'],\n outputs=['result'],\n)\nexpect(node, inputs=[data_0], outputs=[data_0],\n name='test_max_one_input')\n\nresult = np.maximum(data_0, data_1)\nnode = onnx.helper.make_node(\n 'Max',\n inputs=['data_0', 'data_1'],\n outputs=['result'],\n)\nexpect(node, inputs=[data_0, data_1], outputs=[result],\n name='test_max_two_inputs')" + }, + { + "summary": "max_all_numeric_types", + "code": "for op_dtype in all_numeric_dtypes:\n data_0 = np.array([3, 2, 1]).astype(op_dtype)\n data_1 = np.array([1, 4, 4]).astype(op_dtype)\n result = np.array([3, 4, 4]).astype(op_dtype)\n node = onnx.helper.make_node(\n 'Max',\n inputs=['data_0', 'data_1'],\n outputs=['result'],\n )\n expect(node, inputs=[data_0, data_1], outputs=[result],\n name='test_max_{0}'.format(np.dtype(op_dtype).name))" + } + ] + }, + { + "name": "Max", + "module": "ai.onnx", + "version": 12, + "support_level": "common", + "description": "Element-wise max of each of the input tensors (with Numpy-style broadcasting support).\nAll inputs and outputs must have the same data type.\nThis operator supports **multidirectional (i.e., Numpy-style) broadcasting**; for more details please check [the doc](https://github.com/onnx/onnx/blob/master/docs/Broadcasting.md).\n", + "inputs": [ + { + "name": "data_0", + "type": "T", + "list": true, + "description": "List of tensors for max." + } + ], + "min_input": 1, + "max_input": 2147483647, + "outputs": [ + { + "name": "max", + "type": "T", + "description": "Output tensor." + } + ], + "min_output": 1, + "max_output": 1, + "inputs_range": "1 - ∞", + "type_constraints": [ + { + "description": "Constrain input and output types to numeric tensors.", + "type_param_str": "T", + "allowed_type_strs": [ + "tensor(uint8)", + "tensor(uint16)", + "tensor(uint32)", + "tensor(uint64)", + "tensor(int8)", + "tensor(int16)", + "tensor(int32)", + "tensor(int64)", + "tensor(float16)", + "tensor(float)", + "tensor(double)" + ] + } + ], + "examples": [ + { + "summary": "max", + "code": "data_0 = np.array([3, 2, 1]).astype(np.float32)\ndata_1 = np.array([1, 4, 4]).astype(np.float32)\ndata_2 = np.array([2, 5, 3]).astype(np.float32)\nresult = np.array([3, 5, 4]).astype(np.float32)\nnode = onnx.helper.make_node(\n 'Max',\n inputs=['data_0', 'data_1', 'data_2'],\n outputs=['result'],\n)\nexpect(node, inputs=[data_0, data_1, data_2], outputs=[result],\n name='test_max_example')\n\nnode = onnx.helper.make_node(\n 'Max',\n inputs=['data_0'],\n outputs=['result'],\n)\nexpect(node, inputs=[data_0], outputs=[data_0],\n name='test_max_one_input')\n\nresult = np.maximum(data_0, data_1)\nnode = onnx.helper.make_node(\n 'Max',\n inputs=['data_0', 'data_1'],\n outputs=['result'],\n)\nexpect(node, inputs=[data_0, data_1], outputs=[result],\n name='test_max_two_inputs')" + }, + { + "summary": "max_all_numeric_types", + "code": "for op_dtype in all_numeric_dtypes:\n data_0 = np.array([3, 2, 1]).astype(op_dtype)\n data_1 = np.array([1, 4, 4]).astype(op_dtype)\n result = np.array([3, 4, 4]).astype(op_dtype)\n node = onnx.helper.make_node(\n 'Max',\n inputs=['data_0', 'data_1'],\n outputs=['result'],\n )\n expect(node, inputs=[data_0, data_1], outputs=[result],\n name='test_max_{0}'.format(np.dtype(op_dtype).name))" + } + ] + }, + { + "name": "Max", + "module": "ai.onnx", + "version": 13, + "support_level": "common", + "description": "Element-wise max of each of the input tensors (with Numpy-style broadcasting support).\nAll inputs and outputs must have the same data type.\nThis operator supports **multidirectional (i.e., Numpy-style) broadcasting**; for more details please check [the doc](https://github.com/onnx/onnx/blob/master/docs/Broadcasting.md).\n", + "inputs": [ + { + "name": "data_0", + "type": "T", + "list": true, + "description": "List of tensors for max." + } + ], + "min_input": 1, + "max_input": 2147483647, + "outputs": [ + { + "name": "max", + "type": "T", + "description": "Output tensor." + } + ], + "min_output": 1, + "max_output": 1, + "inputs_range": "1 - ∞", + "type_constraints": [ + { + "description": "Constrain input and output types to numeric tensors.", + "type_param_str": "T", + "allowed_type_strs": [ + "tensor(uint8)", + "tensor(uint16)", + "tensor(uint32)", + "tensor(uint64)", + "tensor(int8)", + "tensor(int16)", + "tensor(int32)", + "tensor(int64)", + "tensor(float16)", + "tensor(float)", + "tensor(double)", + "tensor(bfloat16)" + ] + } + ], + "examples": [ + { + "summary": "max", + "code": "data_0 = np.array([3, 2, 1]).astype(np.float32)\ndata_1 = np.array([1, 4, 4]).astype(np.float32)\ndata_2 = np.array([2, 5, 3]).astype(np.float32)\nresult = np.array([3, 5, 4]).astype(np.float32)\nnode = onnx.helper.make_node(\n 'Max',\n inputs=['data_0', 'data_1', 'data_2'],\n outputs=['result'],\n)\nexpect(node, inputs=[data_0, data_1, data_2], outputs=[result],\n name='test_max_example')\n\nnode = onnx.helper.make_node(\n 'Max',\n inputs=['data_0'],\n outputs=['result'],\n)\nexpect(node, inputs=[data_0], outputs=[data_0],\n name='test_max_one_input')\n\nresult = np.maximum(data_0, data_1)\nnode = onnx.helper.make_node(\n 'Max',\n inputs=['data_0', 'data_1'],\n outputs=['result'],\n)\nexpect(node, inputs=[data_0, data_1], outputs=[result],\n name='test_max_two_inputs')" + }, + { + "summary": "max_all_numeric_types", + "code": "for op_dtype in all_numeric_dtypes:\n data_0 = np.array([3, 2, 1]).astype(op_dtype)\n data_1 = np.array([1, 4, 4]).astype(op_dtype)\n result = np.array([3, 4, 4]).astype(op_dtype)\n node = onnx.helper.make_node(\n 'Max',\n inputs=['data_0', 'data_1'],\n outputs=['result'],\n )\n expect(node, inputs=[data_0, data_1], outputs=[result],\n name='test_max_{0}'.format(np.dtype(op_dtype).name))" + } + ] + }, + { + "name": "MaxPool", + "module": "ai.onnx", + "version": 1, + "support_level": "common", + "description": "MaxPool consumes an input tensor X and applies max pooling across\n the tensor according to kernel sizes, stride sizes, and pad lengths.\n max pooling consisting of computing the max on all values of a\n subset of the input tensor according to the kernel size and downsampling the\n data into the output tensor Y for further processing. The output spatial shape will be following:\n ```\n output_spatial_shape[i] = floor((input_spatial_shape[i] + pad_shape[i] - kernel_spatial_shape[i]) / strides_spatial_shape[i] + 1)\n\n * pad_shape[i] is sum of pads along axis i\n ```\n\n `auto_pad` is a DEPRECATED attribute. If you are using them currently, the output spatial shape will be following:\n ```\n VALID: output_spatial_shape[i] = ceil((input_spatial_shape[i] - kernel_spatial_shape[i] + 1) / strides_spatial_shape[i])\n SAME_UPPER or SAME_LOWER: output_spatial_shape[i] = ceil(input_spatial_shape[i] / strides_spatial_shape[i])\n ```\n And pad shape will be following if `SAME_UPPER` or `SAME_LOWER`:\n ```\n pad_shape[i] = (output_spatial_shape[i] - 1) * strides_spatial_shape[i] + kernel_spatial_shape[i] - input_spatial_shape[i]\n ```\n The output of each pooling window is maximum number of elements exclude pad.\n ", + "attributes": [ + { + "name": "auto_pad", + "type": "string", + "required": false, + "default": "NOTSET", + "description": "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." + }, + { + "name": "kernel_shape", + "type": "int64[]", + "required": true, + "description": "The size of the kernel along each axis." + }, + { + "name": "pads", + "type": "int64[]", + "required": false, + "description": "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." + }, + { + "name": "strides", + "type": "int64[]", + "required": false, + "description": "Stride along each spatial axis." + } + ], + "inputs": [ + { + "name": "X", + "type": "T", + "description": "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 ...]." + } + ], + "min_input": 1, + "max_input": 1, + "outputs": [ + { + "name": "Y", + "type": "T", + "description": "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" + } + ], + "min_output": 1, + "max_output": 1, + "type_constraints": [ + { + "description": "Constrain input and output types to float tensors.", + "type_param_str": "T", + "allowed_type_strs": [ + "tensor(float16)", + "tensor(float)", + "tensor(double)" + ] + } + ], + "examples": [ + { + "summary": "maxpool_1d_default", + "code": "\"\"\"\ninput_shape: [1, 3, 32]\noutput_shape: [1, 3, 31]\n\"\"\"\nnode = onnx.helper.make_node(\n 'MaxPool',\n inputs=['x'],\n outputs=['y'],\n kernel_shape=[2],\n)\nx = np.random.randn(1, 3, 32).astype(np.float32)\nx_shape = np.shape(x)\nkernel_shape = [2]\nstrides = [1]\nout_shape = get_output_shape('VALID', x_shape[2:], kernel_shape, strides)\npadded = x\ny = pool(padded, x_shape, kernel_shape, strides, out_shape, [0], 'MAX')\n\nexpect(node, inputs=[x], outputs=[y], name='test_maxpool_1d_default')" + }, + { + "summary": "maxpool_2d_ceil", + "code": "\"\"\"\ninput_shape: [1, 1, 4, 4]\noutput_shape: [1, 1, 2, 2]\n\"\"\"\nnode = onnx.helper.make_node(\n 'MaxPool',\n inputs=['x'],\n outputs=['y'],\n kernel_shape=[3, 3],\n strides=[2, 2],\n ceil_mode=True\n)\nx = np.array([[[\n [1, 2, 3, 4],\n [5, 6, 7, 8],\n [9, 10, 11, 12],\n [13, 14, 15, 16],\n]]]).astype(np.float32)\ny = np.array([[[\n [11, 12],\n [15, 16]]]]).astype(np.float32)\n\nexpect(node, inputs=[x], outputs=[y], name='test_maxpool_2d_ceil')" + }, + { + "summary": "maxpool_2d_default", + "code": "\"\"\"\ninput_shape: [1, 3, 32, 32]\noutput_shape: [1, 3, 31, 31]\n\"\"\"\nnode = onnx.helper.make_node(\n 'MaxPool',\n inputs=['x'],\n outputs=['y'],\n kernel_shape=[2, 2],\n)\nx = np.random.randn(1, 3, 32, 32).astype(np.float32)\nx_shape = np.shape(x)\nkernel_shape = (2, 2)\nstrides = (1, 1)\nout_shape = get_output_shape('VALID', x_shape[2:], kernel_shape, strides)\npadded = x\ny = pool(padded, x_shape, kernel_shape, strides, out_shape, (0, 0), 'MAX')\n\nexpect(node, inputs=[x], outputs=[y], name='test_maxpool_2d_default')" + }, + { + "summary": "maxpool_2d_dilations", + "code": "\"\"\"\ninput_shape: [1, 1, 4, 4]\noutput_shape: [1, 1, 2, 2]\n\"\"\"\nnode = onnx.helper.make_node(\n 'MaxPool',\n inputs=['x'],\n outputs=['y'],\n kernel_shape=[2, 2],\n strides=[1, 1],\n dilations=[2, 2]\n)\nx = np.array([[[\n [1, 2, 3, 4],\n [5, 6, 7, 8],\n [9, 10, 11, 12],\n [13, 14, 15, 16],\n]]]).astype(np.float32)\ny = np.array([[[\n [11, 12],\n [15, 16]]]]).astype(np.float32)\n\nexpect(node, inputs=[x], outputs=[y], name='test_maxpool_2d_dilations')" + }, + { + "summary": "maxpool_2d_pads", + "code": "\"\"\"\ninput_shape: [1, 3, 28, 28]\noutput_shape: [1, 3, 30, 30]\npad_shape: [4, 4] -> [2, 2, 2, 2] by axis\n\"\"\"\nnode = onnx.helper.make_node(\n 'MaxPool',\n inputs=['x'],\n outputs=['y'],\n kernel_shape=[3, 3],\n pads=[2, 2, 2, 2]\n)\nx = np.random.randn(1, 3, 28, 28).astype(np.float32)\nx_shape = np.shape(x)\nkernel_shape = (3, 3)\nstrides = (1, 1)\npad_bottom = pad_top = pad_right = pad_left = 2\npad_shape = [pad_top + pad_bottom, pad_left + pad_right]\nout_shape = get_output_shape('VALID', np.add(x_shape[2:], pad_shape), kernel_shape, strides)\npadded = np.pad(x, ((0, 0), (0, 0), (pad_top, pad_bottom), (pad_left, pad_right)), mode='constant',\n constant_values=np.nan)\ny = pool(padded, x_shape, kernel_shape, strides, out_shape, pad_shape, 'MAX')\n\nexpect(node, inputs=[x], outputs=[y], name='test_maxpool_2d_pads')" + }, + { + "summary": "maxpool_2d_precomputed_pads", + "code": "\"\"\"\ninput_shape: [1, 1, 5, 5]\noutput_shape: [1, 1, 5, 5]\npad_shape: [4, 4] -> [2, 2, 2, 2] by axis\n\"\"\"\nnode = onnx.helper.make_node(\n 'MaxPool',\n inputs=['x'],\n outputs=['y'],\n kernel_shape=[5, 5],\n pads=[2, 2, 2, 2]\n\n)\nx = np.array([[[\n [1, 2, 3, 4, 5],\n [6, 7, 8, 9, 10],\n [11, 12, 13, 14, 15],\n [16, 17, 18, 19, 20],\n [21, 22, 23, 24, 25],\n]]]).astype(np.float32)\ny = np.array([[[\n [13, 14, 15, 15, 15],\n [18, 19, 20, 20, 20],\n [23, 24, 25, 25, 25],\n [23, 24, 25, 25, 25],\n [23, 24, 25, 25, 25]]]]).astype(np.float32)\n\nexpect(node, inputs=[x], outputs=[y], name='test_maxpool_2d_precomputed_pads')" + }, + { + "summary": "maxpool_2d_precomputed_same_upper", + "code": "\"\"\"\ninput_shape: [1, 1, 5, 5]\noutput_shape: [1, 1, 3, 3]\npad_shape: [2, 2] -> [1, 1, 1, 1] by axis\n\"\"\"\nnode = onnx.helper.make_node(\n 'MaxPool',\n inputs=['x'],\n outputs=['y'],\n kernel_shape=[3, 3],\n strides=[2, 2],\n auto_pad='SAME_UPPER'\n)\nx = np.array([[[\n [1, 2, 3, 4, 5],\n [6, 7, 8, 9, 10],\n [11, 12, 13, 14, 15],\n [16, 17, 18, 19, 20],\n [21, 22, 23, 24, 25],\n]]]).astype(np.float32)\ny = np.array([[[[7, 9, 10],\n [17, 19, 20],\n [22, 24, 25]]]]).astype(np.float32)\n\nexpect(node, inputs=[x], outputs=[y], name='test_maxpool_2d_precomputed_same_upper')" + }, + { + "summary": "maxpool_2d_precomputed_strides", + "code": "\"\"\"\ninput_shape: [1, 1, 5, 5]\noutput_shape: [1, 1, 2, 2]\n\"\"\"\nnode = onnx.helper.make_node(\n 'MaxPool',\n inputs=['x'],\n outputs=['y'],\n kernel_shape=[2, 2],\n strides=[2, 2]\n)\nx = np.array([[[\n [1, 2, 3, 4, 5],\n [6, 7, 8, 9, 10],\n [11, 12, 13, 14, 15],\n [16, 17, 18, 19, 20],\n [21, 22, 23, 24, 25],\n]]]).astype(np.float32)\ny = np.array([[[[7, 9],\n [17, 19]]]]).astype(np.float32)\n\nexpect(node, inputs=[x], outputs=[y], name='test_maxpool_2d_precomputed_strides')" + }, + { + "summary": "maxpool_2d_same_lower", + "code": "\"\"\"\ninput_shape: [1, 3, 32, 32]\noutput_shape: [1, 3, 32, 32]\npad_shape: [1, 1] -> [1, 0, 1, 0] by axis\n\"\"\"\nnode = onnx.helper.make_node(\n 'MaxPool',\n inputs=['x'],\n outputs=['y'],\n kernel_shape=[2, 2],\n auto_pad='SAME_LOWER'\n)\nx = np.random.randn(1, 3, 32, 32).astype(np.float32)\nx_shape = np.shape(x)\nkernel_shape = (2, 2)\nstrides = (1, 1)\nout_shape = get_output_shape('SAME_LOWER', x_shape[2:], kernel_shape, strides)\npad_shape = get_pad_shape('SAME_LOWER', x_shape[2:], kernel_shape, strides, out_shape)\npad_bottom = pad_shape[0] // 2\npad_top = pad_shape[0] - pad_bottom\npad_right = pad_shape[1] // 2\npad_left = pad_shape[1] - pad_right\npadded = np.pad(x, ((0, 0), (0, 0), (pad_top, pad_bottom), (pad_left, pad_right)), mode='constant',\n constant_values=np.nan)\ny = pool(padded, x_shape, kernel_shape, strides, out_shape, pad_shape, 'MAX')\n\nexpect(node, inputs=[x], outputs=[y], name='test_maxpool_2d_same_lower')" + }, + { + "summary": "maxpool_2d_same_upper", + "code": "\"\"\"\ninput_shape: [1, 3, 32, 32]\noutput_shape: [1, 3, 32, 32]\npad_shape: [1, 1] -> [0, 1, 0, 1] by axis\n\"\"\"\nnode = onnx.helper.make_node(\n 'MaxPool',\n inputs=['x'],\n outputs=['y'],\n kernel_shape=[2, 2],\n auto_pad='SAME_UPPER'\n)\nx = np.random.randn(1, 3, 32, 32).astype(np.float32)\nx_shape = np.shape(x)\nkernel_shape = (2, 2)\nstrides = (1, 1)\nout_shape = get_output_shape('SAME_UPPER', x_shape[2:], kernel_shape, strides)\npad_shape = get_pad_shape('SAME_UPPER', x_shape[2:], kernel_shape, strides, out_shape)\npad_top = pad_shape[0] // 2\npad_bottom = pad_shape[0] - pad_top\npad_left = pad_shape[1] // 2\npad_right = pad_shape[1] - pad_left\npadded = np.pad(x, ((0, 0), (0, 0), (pad_top, pad_bottom), (pad_left, pad_right)), mode='constant',\n constant_values=np.nan)\ny = pool(padded, x_shape, kernel_shape, strides, out_shape, pad_shape, 'MAX')\n\nexpect(node, inputs=[x], outputs=[y], name='test_maxpool_2d_same_upper')" + }, + { + "summary": "maxpool_2d_strides", + "code": "\"\"\"\ninput_shape: [1, 3, 32, 32]\noutput_shape: [1, 3, 10, 10]\n\"\"\"\nnode = onnx.helper.make_node(\n 'MaxPool',\n inputs=['x'],\n outputs=['y'],\n kernel_shape=[5, 5],\n strides=[3, 3]\n)\nx = np.random.randn(1, 3, 32, 32).astype(np.float32)\nx_shape = np.shape(x)\nkernel_shape = (5, 5)\nstrides = (3, 3)\nout_shape = get_output_shape('VALID', x_shape[2:], kernel_shape, strides)\npadded = x\ny = pool(padded, x_shape, kernel_shape, strides, out_shape, (0, 0), 'MAX')\n\nexpect(node, inputs=[x], outputs=[y], name='test_maxpool_2d_strides')" + }, + { + "summary": "maxpool_2d_uint8", + "code": "\"\"\"\ninput_shape: [1, 1, 5, 5]\noutput_shape: [1, 1, 5, 5]\npad_shape: [4, 4] -> [2, 2, 2, 2] by axis\n\"\"\"\nnode = onnx.helper.make_node(\n 'MaxPool',\n inputs=['x'],\n outputs=['y'],\n kernel_shape=[5, 5],\n pads=[2, 2, 2, 2]\n)\nx = np.array([[[\n [1, 2, 3, 4, 5],\n [6, 7, 8, 9, 10],\n [11, 12, 13, 14, 15],\n [16, 17, 18, 19, 20],\n [21, 22, 23, 24, 25],\n]]]).astype(np.uint8)\ny = np.array([[[\n [13, 14, 15, 15, 15],\n [18, 19, 20, 20, 20],\n [23, 24, 25, 25, 25],\n [23, 24, 25, 25, 25],\n [23, 24, 25, 25, 25]]]]).astype(np.uint8)\n\nexpect(node, inputs=[x], outputs=[y], name='test_maxpool_2d_uint8')" + }, + { + "summary": "maxpool_3d_default", + "code": "\"\"\"\ninput_shape: [1, 3, 32, 32, 32]\noutput_shape: [1, 3, 31, 31, 31]\n\"\"\"\nnode = onnx.helper.make_node(\n 'MaxPool',\n inputs=['x'],\n outputs=['y'],\n kernel_shape=[2, 2, 2],\n)\nx = np.random.randn(1, 3, 32, 32, 32).astype(np.float32)\nx_shape = np.shape(x)\nkernel_shape = [2, 2, 2]\nstrides = [1, 1, 1]\nout_shape = get_output_shape('VALID', x_shape[2:], kernel_shape, strides)\npadded = x\ny = pool(padded, x_shape, kernel_shape, strides, out_shape, [0, 0, 0], 'MAX')\n\nexpect(node, inputs=[x], outputs=[y], name='test_maxpool_3d_default')" + }, + { + "summary": "maxpool_with_argmax_2d_precomputed_pads", + "code": "\"\"\"\ninput_shape: [1, 1, 5, 5]\noutput_shape: [1, 1, 5, 5]\npad_shape: [4, 4] -> [2, 2, 2, 2] by axis\n\"\"\"\nnode = onnx.helper.make_node(\n 'MaxPool',\n inputs=['x'],\n outputs=['y', 'z'],\n kernel_shape=[5, 5],\n pads=[2, 2, 2, 2]\n)\nx = np.array([[[\n [1, 2, 3, 4, 5],\n [6, 7, 8, 9, 10],\n [11, 12, 13, 14, 15],\n [16, 17, 18, 19, 20],\n [21, 22, 23, 24, 25],\n]]]).astype(np.float32)\ny = np.array([[[\n [13, 14, 15, 15, 15],\n [18, 19, 20, 20, 20],\n [23, 24, 25, 25, 25],\n [23, 24, 25, 25, 25],\n [23, 24, 25, 25, 25]]]]).astype(np.float32)\nz = np.array([[[\n [12, 13, 14, 14, 14],\n [17, 18, 19, 19, 19],\n [22, 23, 24, 24, 24],\n [22, 23, 24, 24, 24],\n [22, 23, 24, 24, 24]]]]).astype(np.int64)\n\nexpect(node, inputs=[x], outputs=[y, z], name='test_maxpool_with_argmax_2d_precomputed_pads')" + }, + { + "summary": "maxpool_with_argmax_2d_precomputed_strides", + "code": "\"\"\"\ninput_shape: [1, 1, 5, 5]\noutput_shape: [1, 1, 2, 2]\n\"\"\"\nnode = onnx.helper.make_node(\n 'MaxPool',\n inputs=['x'],\n outputs=['y', 'z'],\n kernel_shape=[2, 2],\n strides=[2, 2],\n storage_order=1\n)\nx = np.array([[[\n [1, 2, 3, 4, 5],\n [6, 7, 8, 9, 10],\n [11, 12, 13, 14, 15],\n [16, 17, 18, 19, 20],\n [21, 22, 23, 24, 25],\n]]]).astype(np.float32)\ny = np.array([[[[7, 9],\n [17, 19]]]]).astype(np.float32)\nz = np.array([[[[6, 16],\n [8, 18]]]]).astype(np.int64)\n\nexpect(node, inputs=[x], outputs=[y, z], name='test_maxpool_with_argmax_2d_precomputed_strides')" + } + ], + "category": "Pool" + }, + { + "name": "MaxPool", + "module": "ai.onnx", + "version": 8, + "support_level": "common", + "description": "MaxPool consumes an input tensor X and applies max pooling across\n the tensor according to kernel sizes, stride sizes, and pad lengths.\n max pooling consisting of computing the max on all values of a\n subset of the input tensor according to the kernel size and downsampling the\n data into the output tensor Y for further processing. The output spatial shape will be following:\n ```\n output_spatial_shape[i] = floor((input_spatial_shape[i] + pad_shape[i] - kernel_spatial_shape[i]) / strides_spatial_shape[i] + 1)\n\n * pad_shape[i] is sum of pads along axis i\n ```\n\n `auto_pad` is a DEPRECATED attribute. If you are using them currently, the output spatial shape will be following:\n ```\n VALID: output_spatial_shape[i] = ceil((input_spatial_shape[i] - kernel_spatial_shape[i] + 1) / strides_spatial_shape[i])\n SAME_UPPER or SAME_LOWER: output_spatial_shape[i] = ceil(input_spatial_shape[i] / strides_spatial_shape[i])\n ```\n And pad shape will be following if `SAME_UPPER` or `SAME_LOWER`:\n ```\n pad_shape[i] = (output_spatial_shape[i] - 1) * strides_spatial_shape[i] + kernel_spatial_shape[i] - input_spatial_shape[i]\n ```\n The output of each pooling window is maximum number of elements exclude pad.\n ", + "attributes": [ + { + "name": "auto_pad", + "type": "string", + "required": false, + "default": "NOTSET", + "description": "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." + }, + { + "name": "kernel_shape", + "type": "int64[]", + "required": true, + "description": "The size of the kernel along each axis." + }, + { + "name": "pads", + "type": "int64[]", + "required": false, + "description": "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." + }, + { + "name": "storage_order", + "type": "int64", + "required": false, + "description": "The storage order of the tensor. 0 is row major, and 1 is column major." + }, + { + "name": "strides", + "type": "int64[]", + "required": false, + "description": "Stride along each spatial axis." + } + ], + "inputs": [ + { + "name": "X", + "type": "T", + "description": "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 ...]." + } + ], + "min_input": 1, + "max_input": 1, + "outputs": [ + { + "name": "Y", + "type": "T", + "description": "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" + }, + { + "name": "Indices", + "type": "I", + "option": "optional", + "description": "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)." + } + ], + "min_output": 1, + "max_output": 2, + "outputs_range": "1 - 2", + "type_constraints": [ + { + "description": "Constrain input and output types to float tensors.", + "type_param_str": "T", + "allowed_type_strs": [ + "tensor(float16)", + "tensor(float)", + "tensor(double)" + ] + }, + { + "description": "Constrain index tensor to int64", + "type_param_str": "I", + "allowed_type_strs": [ + "tensor(int64)" + ] + } + ], + "examples": [ + { + "summary": "maxpool_1d_default", + "code": "\"\"\"\ninput_shape: [1, 3, 32]\noutput_shape: [1, 3, 31]\n\"\"\"\nnode = onnx.helper.make_node(\n 'MaxPool',\n inputs=['x'],\n outputs=['y'],\n kernel_shape=[2],\n)\nx = np.random.randn(1, 3, 32).astype(np.float32)\nx_shape = np.shape(x)\nkernel_shape = [2]\nstrides = [1]\nout_shape = get_output_shape('VALID', x_shape[2:], kernel_shape, strides)\npadded = x\ny = pool(padded, x_shape, kernel_shape, strides, out_shape, [0], 'MAX')\n\nexpect(node, inputs=[x], outputs=[y], name='test_maxpool_1d_default')" + }, + { + "summary": "maxpool_2d_ceil", + "code": "\"\"\"\ninput_shape: [1, 1, 4, 4]\noutput_shape: [1, 1, 2, 2]\n\"\"\"\nnode = onnx.helper.make_node(\n 'MaxPool',\n inputs=['x'],\n outputs=['y'],\n kernel_shape=[3, 3],\n strides=[2, 2],\n ceil_mode=True\n)\nx = np.array([[[\n [1, 2, 3, 4],\n [5, 6, 7, 8],\n [9, 10, 11, 12],\n [13, 14, 15, 16],\n]]]).astype(np.float32)\ny = np.array([[[\n [11, 12],\n [15, 16]]]]).astype(np.float32)\n\nexpect(node, inputs=[x], outputs=[y], name='test_maxpool_2d_ceil')" + }, + { + "summary": "maxpool_2d_default", + "code": "\"\"\"\ninput_shape: [1, 3, 32, 32]\noutput_shape: [1, 3, 31, 31]\n\"\"\"\nnode = onnx.helper.make_node(\n 'MaxPool',\n inputs=['x'],\n outputs=['y'],\n kernel_shape=[2, 2],\n)\nx = np.random.randn(1, 3, 32, 32).astype(np.float32)\nx_shape = np.shape(x)\nkernel_shape = (2, 2)\nstrides = (1, 1)\nout_shape = get_output_shape('VALID', x_shape[2:], kernel_shape, strides)\npadded = x\ny = pool(padded, x_shape, kernel_shape, strides, out_shape, (0, 0), 'MAX')\n\nexpect(node, inputs=[x], outputs=[y], name='test_maxpool_2d_default')" + }, + { + "summary": "maxpool_2d_dilations", + "code": "\"\"\"\ninput_shape: [1, 1, 4, 4]\noutput_shape: [1, 1, 2, 2]\n\"\"\"\nnode = onnx.helper.make_node(\n 'MaxPool',\n inputs=['x'],\n outputs=['y'],\n kernel_shape=[2, 2],\n strides=[1, 1],\n dilations=[2, 2]\n)\nx = np.array([[[\n [1, 2, 3, 4],\n [5, 6, 7, 8],\n [9, 10, 11, 12],\n [13, 14, 15, 16],\n]]]).astype(np.float32)\ny = np.array([[[\n [11, 12],\n [15, 16]]]]).astype(np.float32)\n\nexpect(node, inputs=[x], outputs=[y], name='test_maxpool_2d_dilations')" + }, + { + "summary": "maxpool_2d_pads", + "code": "\"\"\"\ninput_shape: [1, 3, 28, 28]\noutput_shape: [1, 3, 30, 30]\npad_shape: [4, 4] -> [2, 2, 2, 2] by axis\n\"\"\"\nnode = onnx.helper.make_node(\n 'MaxPool',\n inputs=['x'],\n outputs=['y'],\n kernel_shape=[3, 3],\n pads=[2, 2, 2, 2]\n)\nx = np.random.randn(1, 3, 28, 28).astype(np.float32)\nx_shape = np.shape(x)\nkernel_shape = (3, 3)\nstrides = (1, 1)\npad_bottom = pad_top = pad_right = pad_left = 2\npad_shape = [pad_top + pad_bottom, pad_left + pad_right]\nout_shape = get_output_shape('VALID', np.add(x_shape[2:], pad_shape), kernel_shape, strides)\npadded = np.pad(x, ((0, 0), (0, 0), (pad_top, pad_bottom), (pad_left, pad_right)), mode='constant',\n constant_values=np.nan)\ny = pool(padded, x_shape, kernel_shape, strides, out_shape, pad_shape, 'MAX')\n\nexpect(node, inputs=[x], outputs=[y], name='test_maxpool_2d_pads')" + }, + { + "summary": "maxpool_2d_precomputed_pads", + "code": "\"\"\"\ninput_shape: [1, 1, 5, 5]\noutput_shape: [1, 1, 5, 5]\npad_shape: [4, 4] -> [2, 2, 2, 2] by axis\n\"\"\"\nnode = onnx.helper.make_node(\n 'MaxPool',\n inputs=['x'],\n outputs=['y'],\n kernel_shape=[5, 5],\n pads=[2, 2, 2, 2]\n\n)\nx = np.array([[[\n [1, 2, 3, 4, 5],\n [6, 7, 8, 9, 10],\n [11, 12, 13, 14, 15],\n [16, 17, 18, 19, 20],\n [21, 22, 23, 24, 25],\n]]]).astype(np.float32)\ny = np.array([[[\n [13, 14, 15, 15, 15],\n [18, 19, 20, 20, 20],\n [23, 24, 25, 25, 25],\n [23, 24, 25, 25, 25],\n [23, 24, 25, 25, 25]]]]).astype(np.float32)\n\nexpect(node, inputs=[x], outputs=[y], name='test_maxpool_2d_precomputed_pads')" + }, + { + "summary": "maxpool_2d_precomputed_same_upper", + "code": "\"\"\"\ninput_shape: [1, 1, 5, 5]\noutput_shape: [1, 1, 3, 3]\npad_shape: [2, 2] -> [1, 1, 1, 1] by axis\n\"\"\"\nnode = onnx.helper.make_node(\n 'MaxPool',\n inputs=['x'],\n outputs=['y'],\n kernel_shape=[3, 3],\n strides=[2, 2],\n auto_pad='SAME_UPPER'\n)\nx = np.array([[[\n [1, 2, 3, 4, 5],\n [6, 7, 8, 9, 10],\n [11, 12, 13, 14, 15],\n [16, 17, 18, 19, 20],\n [21, 22, 23, 24, 25],\n]]]).astype(np.float32)\ny = np.array([[[[7, 9, 10],\n [17, 19, 20],\n [22, 24, 25]]]]).astype(np.float32)\n\nexpect(node, inputs=[x], outputs=[y], name='test_maxpool_2d_precomputed_same_upper')" + }, + { + "summary": "maxpool_2d_precomputed_strides", + "code": "\"\"\"\ninput_shape: [1, 1, 5, 5]\noutput_shape: [1, 1, 2, 2]\n\"\"\"\nnode = onnx.helper.make_node(\n 'MaxPool',\n inputs=['x'],\n outputs=['y'],\n kernel_shape=[2, 2],\n strides=[2, 2]\n)\nx = np.array([[[\n [1, 2, 3, 4, 5],\n [6, 7, 8, 9, 10],\n [11, 12, 13, 14, 15],\n [16, 17, 18, 19, 20],\n [21, 22, 23, 24, 25],\n]]]).astype(np.float32)\ny = np.array([[[[7, 9],\n [17, 19]]]]).astype(np.float32)\n\nexpect(node, inputs=[x], outputs=[y], name='test_maxpool_2d_precomputed_strides')" + }, + { + "summary": "maxpool_2d_same_lower", + "code": "\"\"\"\ninput_shape: [1, 3, 32, 32]\noutput_shape: [1, 3, 32, 32]\npad_shape: [1, 1] -> [1, 0, 1, 0] by axis\n\"\"\"\nnode = onnx.helper.make_node(\n 'MaxPool',\n inputs=['x'],\n outputs=['y'],\n kernel_shape=[2, 2],\n auto_pad='SAME_LOWER'\n)\nx = np.random.randn(1, 3, 32, 32).astype(np.float32)\nx_shape = np.shape(x)\nkernel_shape = (2, 2)\nstrides = (1, 1)\nout_shape = get_output_shape('SAME_LOWER', x_shape[2:], kernel_shape, strides)\npad_shape = get_pad_shape('SAME_LOWER', x_shape[2:], kernel_shape, strides, out_shape)\npad_bottom = pad_shape[0] // 2\npad_top = pad_shape[0] - pad_bottom\npad_right = pad_shape[1] // 2\npad_left = pad_shape[1] - pad_right\npadded = np.pad(x, ((0, 0), (0, 0), (pad_top, pad_bottom), (pad_left, pad_right)), mode='constant',\n constant_values=np.nan)\ny = pool(padded, x_shape, kernel_shape, strides, out_shape, pad_shape, 'MAX')\n\nexpect(node, inputs=[x], outputs=[y], name='test_maxpool_2d_same_lower')" + }, + { + "summary": "maxpool_2d_same_upper", + "code": "\"\"\"\ninput_shape: [1, 3, 32, 32]\noutput_shape: [1, 3, 32, 32]\npad_shape: [1, 1] -> [0, 1, 0, 1] by axis\n\"\"\"\nnode = onnx.helper.make_node(\n 'MaxPool',\n inputs=['x'],\n outputs=['y'],\n kernel_shape=[2, 2],\n auto_pad='SAME_UPPER'\n)\nx = np.random.randn(1, 3, 32, 32).astype(np.float32)\nx_shape = np.shape(x)\nkernel_shape = (2, 2)\nstrides = (1, 1)\nout_shape = get_output_shape('SAME_UPPER', x_shape[2:], kernel_shape, strides)\npad_shape = get_pad_shape('SAME_UPPER', x_shape[2:], kernel_shape, strides, out_shape)\npad_top = pad_shape[0] // 2\npad_bottom = pad_shape[0] - pad_top\npad_left = pad_shape[1] // 2\npad_right = pad_shape[1] - pad_left\npadded = np.pad(x, ((0, 0), (0, 0), (pad_top, pad_bottom), (pad_left, pad_right)), mode='constant',\n constant_values=np.nan)\ny = pool(padded, x_shape, kernel_shape, strides, out_shape, pad_shape, 'MAX')\n\nexpect(node, inputs=[x], outputs=[y], name='test_maxpool_2d_same_upper')" + }, + { + "summary": "maxpool_2d_strides", + "code": "\"\"\"\ninput_shape: [1, 3, 32, 32]\noutput_shape: [1, 3, 10, 10]\n\"\"\"\nnode = onnx.helper.make_node(\n 'MaxPool',\n inputs=['x'],\n outputs=['y'],\n kernel_shape=[5, 5],\n strides=[3, 3]\n)\nx = np.random.randn(1, 3, 32, 32).astype(np.float32)\nx_shape = np.shape(x)\nkernel_shape = (5, 5)\nstrides = (3, 3)\nout_shape = get_output_shape('VALID', x_shape[2:], kernel_shape, strides)\npadded = x\ny = pool(padded, x_shape, kernel_shape, strides, out_shape, (0, 0), 'MAX')\n\nexpect(node, inputs=[x], outputs=[y], name='test_maxpool_2d_strides')" + }, + { + "summary": "maxpool_2d_uint8", + "code": "\"\"\"\ninput_shape: [1, 1, 5, 5]\noutput_shape: [1, 1, 5, 5]\npad_shape: [4, 4] -> [2, 2, 2, 2] by axis\n\"\"\"\nnode = onnx.helper.make_node(\n 'MaxPool',\n inputs=['x'],\n outputs=['y'],\n kernel_shape=[5, 5],\n pads=[2, 2, 2, 2]\n)\nx = np.array([[[\n [1, 2, 3, 4, 5],\n [6, 7, 8, 9, 10],\n [11, 12, 13, 14, 15],\n [16, 17, 18, 19, 20],\n [21, 22, 23, 24, 25],\n]]]).astype(np.uint8)\ny = np.array([[[\n [13, 14, 15, 15, 15],\n [18, 19, 20, 20, 20],\n [23, 24, 25, 25, 25],\n [23, 24, 25, 25, 25],\n [23, 24, 25, 25, 25]]]]).astype(np.uint8)\n\nexpect(node, inputs=[x], outputs=[y], name='test_maxpool_2d_uint8')" + }, + { + "summary": "maxpool_3d_default", + "code": "\"\"\"\ninput_shape: [1, 3, 32, 32, 32]\noutput_shape: [1, 3, 31, 31, 31]\n\"\"\"\nnode = onnx.helper.make_node(\n 'MaxPool',\n inputs=['x'],\n outputs=['y'],\n kernel_shape=[2, 2, 2],\n)\nx = np.random.randn(1, 3, 32, 32, 32).astype(np.float32)\nx_shape = np.shape(x)\nkernel_shape = [2, 2, 2]\nstrides = [1, 1, 1]\nout_shape = get_output_shape('VALID', x_shape[2:], kernel_shape, strides)\npadded = x\ny = pool(padded, x_shape, kernel_shape, strides, out_shape, [0, 0, 0], 'MAX')\n\nexpect(node, inputs=[x], outputs=[y], name='test_maxpool_3d_default')" + }, + { + "summary": "maxpool_with_argmax_2d_precomputed_pads", + "code": "\"\"\"\ninput_shape: [1, 1, 5, 5]\noutput_shape: [1, 1, 5, 5]\npad_shape: [4, 4] -> [2, 2, 2, 2] by axis\n\"\"\"\nnode = onnx.helper.make_node(\n 'MaxPool',\n inputs=['x'],\n outputs=['y', 'z'],\n kernel_shape=[5, 5],\n pads=[2, 2, 2, 2]\n)\nx = np.array([[[\n [1, 2, 3, 4, 5],\n [6, 7, 8, 9, 10],\n [11, 12, 13, 14, 15],\n [16, 17, 18, 19, 20],\n [21, 22, 23, 24, 25],\n]]]).astype(np.float32)\ny = np.array([[[\n [13, 14, 15, 15, 15],\n [18, 19, 20, 20, 20],\n [23, 24, 25, 25, 25],\n [23, 24, 25, 25, 25],\n [23, 24, 25, 25, 25]]]]).astype(np.float32)\nz = np.array([[[\n [12, 13, 14, 14, 14],\n [17, 18, 19, 19, 19],\n [22, 23, 24, 24, 24],\n [22, 23, 24, 24, 24],\n [22, 23, 24, 24, 24]]]]).astype(np.int64)\n\nexpect(node, inputs=[x], outputs=[y, z], name='test_maxpool_with_argmax_2d_precomputed_pads')" + }, + { + "summary": "maxpool_with_argmax_2d_precomputed_strides", + "code": "\"\"\"\ninput_shape: [1, 1, 5, 5]\noutput_shape: [1, 1, 2, 2]\n\"\"\"\nnode = onnx.helper.make_node(\n 'MaxPool',\n inputs=['x'],\n outputs=['y', 'z'],\n kernel_shape=[2, 2],\n strides=[2, 2],\n storage_order=1\n)\nx = np.array([[[\n [1, 2, 3, 4, 5],\n [6, 7, 8, 9, 10],\n [11, 12, 13, 14, 15],\n [16, 17, 18, 19, 20],\n [21, 22, 23, 24, 25],\n]]]).astype(np.float32)\ny = np.array([[[[7, 9],\n [17, 19]]]]).astype(np.float32)\nz = np.array([[[[6, 16],\n [8, 18]]]]).astype(np.int64)\n\nexpect(node, inputs=[x], outputs=[y, z], name='test_maxpool_with_argmax_2d_precomputed_strides')" + } + ], + "category": "Pool" + }, + { + "name": "MaxPool", + "module": "ai.onnx", + "version": 10, + "support_level": "common", + "description": "MaxPool consumes an input tensor X and applies max pooling across\n the tensor according to kernel sizes, stride sizes, and pad lengths.\n max pooling consisting of computing the max on all values of a\n subset of the input tensor according to the kernel size and downsampling the\n data into the output tensor Y for further processing. The output spatial shape will be following:\n ```\n 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)\n ```\n or\n ```\n 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)\n ```\n if ceil_mode is enabled\n\n ```\n * pad_shape[i] is sum of pads along axis i\n ```\n\n `auto_pad` is a DEPRECATED attribute. If you are using them currently, the output spatial shape will be following:\n ```\n VALID: output_spatial_shape[i] = ceil((input_spatial_shape[i] - ((kernel_spatial_shape[i] - 1) * dilations[i] + 1) + 1) / strides_spatial_shape[i])\n SAME_UPPER or SAME_LOWER: output_spatial_shape[i] = ceil(input_spatial_shape[i] / strides_spatial_shape[i])\n ```\n And pad shape will be following if `SAME_UPPER` or `SAME_LOWER`:\n ```\n pad_shape[i] = (output_spatial_shape[i] - 1) * strides_spatial_shape[i] + ((kernel_spatial_shape[i] - 1) * dilations[i] + 1) - input_spatial_shape[i]\n ```\n The output of each pooling window is maximum number of elements exclude pad.\n ", + "attributes": [ + { + "name": "auto_pad", + "type": "string", + "required": false, + "default": "NOTSET", + "description": "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." + }, + { + "name": "ceil_mode", + "type": "int64", + "required": false, + "description": "Whether to use ceil or floor (default) to compute the output shape." + }, + { + "name": "dilations", + "type": "int64[]", + "required": false, + "description": "Dilation value along each spatial axis of filter." + }, + { + "name": "kernel_shape", + "type": "int64[]", + "required": true, + "description": "The size of the kernel along each axis." + }, + { + "name": "pads", + "type": "int64[]", + "required": false, + "description": "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." + }, + { + "name": "storage_order", + "type": "int64", + "required": false, + "description": "The storage order of the tensor. 0 is row major, and 1 is column major." + }, + { + "name": "strides", + "type": "int64[]", + "required": false, + "description": "Stride along each spatial axis." + } + ], + "inputs": [ + { + "name": "X", + "type": "T", + "description": "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 ...]." + } + ], + "min_input": 1, + "max_input": 1, + "outputs": [ + { + "name": "Y", + "type": "T", + "description": "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" + }, + { + "name": "Indices", + "type": "I", + "option": "optional", + "description": "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)." + } + ], + "min_output": 1, + "max_output": 2, + "outputs_range": "1 - 2", + "type_constraints": [ + { + "description": "Constrain input and output types to float tensors.", + "type_param_str": "T", + "allowed_type_strs": [ + "tensor(float16)", + "tensor(float)", + "tensor(double)" + ] + }, + { + "description": "Constrain index tensor to int64", + "type_param_str": "I", + "allowed_type_strs": [ + "tensor(int64)" + ] + } + ], + "examples": [ + { + "summary": "maxpool_1d_default", + "code": "\"\"\"\ninput_shape: [1, 3, 32]\noutput_shape: [1, 3, 31]\n\"\"\"\nnode = onnx.helper.make_node(\n 'MaxPool',\n inputs=['x'],\n outputs=['y'],\n kernel_shape=[2],\n)\nx = np.random.randn(1, 3, 32).astype(np.float32)\nx_shape = np.shape(x)\nkernel_shape = [2]\nstrides = [1]\nout_shape = get_output_shape('VALID', x_shape[2:], kernel_shape, strides)\npadded = x\ny = pool(padded, x_shape, kernel_shape, strides, out_shape, [0], 'MAX')\n\nexpect(node, inputs=[x], outputs=[y], name='test_maxpool_1d_default')" + }, + { + "summary": "maxpool_2d_ceil", + "code": "\"\"\"\ninput_shape: [1, 1, 4, 4]\noutput_shape: [1, 1, 2, 2]\n\"\"\"\nnode = onnx.helper.make_node(\n 'MaxPool',\n inputs=['x'],\n outputs=['y'],\n kernel_shape=[3, 3],\n strides=[2, 2],\n ceil_mode=True\n)\nx = np.array([[[\n [1, 2, 3, 4],\n [5, 6, 7, 8],\n [9, 10, 11, 12],\n [13, 14, 15, 16],\n]]]).astype(np.float32)\ny = np.array([[[\n [11, 12],\n [15, 16]]]]).astype(np.float32)\n\nexpect(node, inputs=[x], outputs=[y], name='test_maxpool_2d_ceil')" + }, + { + "summary": "maxpool_2d_default", + "code": "\"\"\"\ninput_shape: [1, 3, 32, 32]\noutput_shape: [1, 3, 31, 31]\n\"\"\"\nnode = onnx.helper.make_node(\n 'MaxPool',\n inputs=['x'],\n outputs=['y'],\n kernel_shape=[2, 2],\n)\nx = np.random.randn(1, 3, 32, 32).astype(np.float32)\nx_shape = np.shape(x)\nkernel_shape = (2, 2)\nstrides = (1, 1)\nout_shape = get_output_shape('VALID', x_shape[2:], kernel_shape, strides)\npadded = x\ny = pool(padded, x_shape, kernel_shape, strides, out_shape, (0, 0), 'MAX')\n\nexpect(node, inputs=[x], outputs=[y], name='test_maxpool_2d_default')" + }, + { + "summary": "maxpool_2d_dilations", + "code": "\"\"\"\ninput_shape: [1, 1, 4, 4]\noutput_shape: [1, 1, 2, 2]\n\"\"\"\nnode = onnx.helper.make_node(\n 'MaxPool',\n inputs=['x'],\n outputs=['y'],\n kernel_shape=[2, 2],\n strides=[1, 1],\n dilations=[2, 2]\n)\nx = np.array([[[\n [1, 2, 3, 4],\n [5, 6, 7, 8],\n [9, 10, 11, 12],\n [13, 14, 15, 16],\n]]]).astype(np.float32)\ny = np.array([[[\n [11, 12],\n [15, 16]]]]).astype(np.float32)\n\nexpect(node, inputs=[x], outputs=[y], name='test_maxpool_2d_dilations')" + }, + { + "summary": "maxpool_2d_pads", + "code": "\"\"\"\ninput_shape: [1, 3, 28, 28]\noutput_shape: [1, 3, 30, 30]\npad_shape: [4, 4] -> [2, 2, 2, 2] by axis\n\"\"\"\nnode = onnx.helper.make_node(\n 'MaxPool',\n inputs=['x'],\n outputs=['y'],\n kernel_shape=[3, 3],\n pads=[2, 2, 2, 2]\n)\nx = np.random.randn(1, 3, 28, 28).astype(np.float32)\nx_shape = np.shape(x)\nkernel_shape = (3, 3)\nstrides = (1, 1)\npad_bottom = pad_top = pad_right = pad_left = 2\npad_shape = [pad_top + pad_bottom, pad_left + pad_right]\nout_shape = get_output_shape('VALID', np.add(x_shape[2:], pad_shape), kernel_shape, strides)\npadded = np.pad(x, ((0, 0), (0, 0), (pad_top, pad_bottom), (pad_left, pad_right)), mode='constant',\n constant_values=np.nan)\ny = pool(padded, x_shape, kernel_shape, strides, out_shape, pad_shape, 'MAX')\n\nexpect(node, inputs=[x], outputs=[y], name='test_maxpool_2d_pads')" + }, + { + "summary": "maxpool_2d_precomputed_pads", + "code": "\"\"\"\ninput_shape: [1, 1, 5, 5]\noutput_shape: [1, 1, 5, 5]\npad_shape: [4, 4] -> [2, 2, 2, 2] by axis\n\"\"\"\nnode = onnx.helper.make_node(\n 'MaxPool',\n inputs=['x'],\n outputs=['y'],\n kernel_shape=[5, 5],\n pads=[2, 2, 2, 2]\n\n)\nx = np.array([[[\n [1, 2, 3, 4, 5],\n [6, 7, 8, 9, 10],\n [11, 12, 13, 14, 15],\n [16, 17, 18, 19, 20],\n [21, 22, 23, 24, 25],\n]]]).astype(np.float32)\ny = np.array([[[\n [13, 14, 15, 15, 15],\n [18, 19, 20, 20, 20],\n [23, 24, 25, 25, 25],\n [23, 24, 25, 25, 25],\n [23, 24, 25, 25, 25]]]]).astype(np.float32)\n\nexpect(node, inputs=[x], outputs=[y], name='test_maxpool_2d_precomputed_pads')" + }, + { + "summary": "maxpool_2d_precomputed_same_upper", + "code": "\"\"\"\ninput_shape: [1, 1, 5, 5]\noutput_shape: [1, 1, 3, 3]\npad_shape: [2, 2] -> [1, 1, 1, 1] by axis\n\"\"\"\nnode = onnx.helper.make_node(\n 'MaxPool',\n inputs=['x'],\n outputs=['y'],\n kernel_shape=[3, 3],\n strides=[2, 2],\n auto_pad='SAME_UPPER'\n)\nx = np.array([[[\n [1, 2, 3, 4, 5],\n [6, 7, 8, 9, 10],\n [11, 12, 13, 14, 15],\n [16, 17, 18, 19, 20],\n [21, 22, 23, 24, 25],\n]]]).astype(np.float32)\ny = np.array([[[[7, 9, 10],\n [17, 19, 20],\n [22, 24, 25]]]]).astype(np.float32)\n\nexpect(node, inputs=[x], outputs=[y], name='test_maxpool_2d_precomputed_same_upper')" + }, + { + "summary": "maxpool_2d_precomputed_strides", + "code": "\"\"\"\ninput_shape: [1, 1, 5, 5]\noutput_shape: [1, 1, 2, 2]\n\"\"\"\nnode = onnx.helper.make_node(\n 'MaxPool',\n inputs=['x'],\n outputs=['y'],\n kernel_shape=[2, 2],\n strides=[2, 2]\n)\nx = np.array([[[\n [1, 2, 3, 4, 5],\n [6, 7, 8, 9, 10],\n [11, 12, 13, 14, 15],\n [16, 17, 18, 19, 20],\n [21, 22, 23, 24, 25],\n]]]).astype(np.float32)\ny = np.array([[[[7, 9],\n [17, 19]]]]).astype(np.float32)\n\nexpect(node, inputs=[x], outputs=[y], name='test_maxpool_2d_precomputed_strides')" + }, + { + "summary": "maxpool_2d_same_lower", + "code": "\"\"\"\ninput_shape: [1, 3, 32, 32]\noutput_shape: [1, 3, 32, 32]\npad_shape: [1, 1] -> [1, 0, 1, 0] by axis\n\"\"\"\nnode = onnx.helper.make_node(\n 'MaxPool',\n inputs=['x'],\n outputs=['y'],\n kernel_shape=[2, 2],\n auto_pad='SAME_LOWER'\n)\nx = np.random.randn(1, 3, 32, 32).astype(np.float32)\nx_shape = np.shape(x)\nkernel_shape = (2, 2)\nstrides = (1, 1)\nout_shape = get_output_shape('SAME_LOWER', x_shape[2:], kernel_shape, strides)\npad_shape = get_pad_shape('SAME_LOWER', x_shape[2:], kernel_shape, strides, out_shape)\npad_bottom = pad_shape[0] // 2\npad_top = pad_shape[0] - pad_bottom\npad_right = pad_shape[1] // 2\npad_left = pad_shape[1] - pad_right\npadded = np.pad(x, ((0, 0), (0, 0), (pad_top, pad_bottom), (pad_left, pad_right)), mode='constant',\n constant_values=np.nan)\ny = pool(padded, x_shape, kernel_shape, strides, out_shape, pad_shape, 'MAX')\n\nexpect(node, inputs=[x], outputs=[y], name='test_maxpool_2d_same_lower')" + }, + { + "summary": "maxpool_2d_same_upper", + "code": "\"\"\"\ninput_shape: [1, 3, 32, 32]\noutput_shape: [1, 3, 32, 32]\npad_shape: [1, 1] -> [0, 1, 0, 1] by axis\n\"\"\"\nnode = onnx.helper.make_node(\n 'MaxPool',\n inputs=['x'],\n outputs=['y'],\n kernel_shape=[2, 2],\n auto_pad='SAME_UPPER'\n)\nx = np.random.randn(1, 3, 32, 32).astype(np.float32)\nx_shape = np.shape(x)\nkernel_shape = (2, 2)\nstrides = (1, 1)\nout_shape = get_output_shape('SAME_UPPER', x_shape[2:], kernel_shape, strides)\npad_shape = get_pad_shape('SAME_UPPER', x_shape[2:], kernel_shape, strides, out_shape)\npad_top = pad_shape[0] // 2\npad_bottom = pad_shape[0] - pad_top\npad_left = pad_shape[1] // 2\npad_right = pad_shape[1] - pad_left\npadded = np.pad(x, ((0, 0), (0, 0), (pad_top, pad_bottom), (pad_left, pad_right)), mode='constant',\n constant_values=np.nan)\ny = pool(padded, x_shape, kernel_shape, strides, out_shape, pad_shape, 'MAX')\n\nexpect(node, inputs=[x], outputs=[y], name='test_maxpool_2d_same_upper')" + }, + { + "summary": "maxpool_2d_strides", + "code": "\"\"\"\ninput_shape: [1, 3, 32, 32]\noutput_shape: [1, 3, 10, 10]\n\"\"\"\nnode = onnx.helper.make_node(\n 'MaxPool',\n inputs=['x'],\n outputs=['y'],\n kernel_shape=[5, 5],\n strides=[3, 3]\n)\nx = np.random.randn(1, 3, 32, 32).astype(np.float32)\nx_shape = np.shape(x)\nkernel_shape = (5, 5)\nstrides = (3, 3)\nout_shape = get_output_shape('VALID', x_shape[2:], kernel_shape, strides)\npadded = x\ny = pool(padded, x_shape, kernel_shape, strides, out_shape, (0, 0), 'MAX')\n\nexpect(node, inputs=[x], outputs=[y], name='test_maxpool_2d_strides')" + }, + { + "summary": "maxpool_2d_uint8", + "code": "\"\"\"\ninput_shape: [1, 1, 5, 5]\noutput_shape: [1, 1, 5, 5]\npad_shape: [4, 4] -> [2, 2, 2, 2] by axis\n\"\"\"\nnode = onnx.helper.make_node(\n 'MaxPool',\n inputs=['x'],\n outputs=['y'],\n kernel_shape=[5, 5],\n pads=[2, 2, 2, 2]\n)\nx = np.array([[[\n [1, 2, 3, 4, 5],\n [6, 7, 8, 9, 10],\n [11, 12, 13, 14, 15],\n [16, 17, 18, 19, 20],\n [21, 22, 23, 24, 25],\n]]]).astype(np.uint8)\ny = np.array([[[\n [13, 14, 15, 15, 15],\n [18, 19, 20, 20, 20],\n [23, 24, 25, 25, 25],\n [23, 24, 25, 25, 25],\n [23, 24, 25, 25, 25]]]]).astype(np.uint8)\n\nexpect(node, inputs=[x], outputs=[y], name='test_maxpool_2d_uint8')" + }, + { + "summary": "maxpool_3d_default", + "code": "\"\"\"\ninput_shape: [1, 3, 32, 32, 32]\noutput_shape: [1, 3, 31, 31, 31]\n\"\"\"\nnode = onnx.helper.make_node(\n 'MaxPool',\n inputs=['x'],\n outputs=['y'],\n kernel_shape=[2, 2, 2],\n)\nx = np.random.randn(1, 3, 32, 32, 32).astype(np.float32)\nx_shape = np.shape(x)\nkernel_shape = [2, 2, 2]\nstrides = [1, 1, 1]\nout_shape = get_output_shape('VALID', x_shape[2:], kernel_shape, strides)\npadded = x\ny = pool(padded, x_shape, kernel_shape, strides, out_shape, [0, 0, 0], 'MAX')\n\nexpect(node, inputs=[x], outputs=[y], name='test_maxpool_3d_default')" + }, + { + "summary": "maxpool_with_argmax_2d_precomputed_pads", + "code": "\"\"\"\ninput_shape: [1, 1, 5, 5]\noutput_shape: [1, 1, 5, 5]\npad_shape: [4, 4] -> [2, 2, 2, 2] by axis\n\"\"\"\nnode = onnx.helper.make_node(\n 'MaxPool',\n inputs=['x'],\n outputs=['y', 'z'],\n kernel_shape=[5, 5],\n pads=[2, 2, 2, 2]\n)\nx = np.array([[[\n [1, 2, 3, 4, 5],\n [6, 7, 8, 9, 10],\n [11, 12, 13, 14, 15],\n [16, 17, 18, 19, 20],\n [21, 22, 23, 24, 25],\n]]]).astype(np.float32)\ny = np.array([[[\n [13, 14, 15, 15, 15],\n [18, 19, 20, 20, 20],\n [23, 24, 25, 25, 25],\n [23, 24, 25, 25, 25],\n [23, 24, 25, 25, 25]]]]).astype(np.float32)\nz = np.array([[[\n [12, 13, 14, 14, 14],\n [17, 18, 19, 19, 19],\n [22, 23, 24, 24, 24],\n [22, 23, 24, 24, 24],\n [22, 23, 24, 24, 24]]]]).astype(np.int64)\n\nexpect(node, inputs=[x], outputs=[y, z], name='test_maxpool_with_argmax_2d_precomputed_pads')" + }, + { + "summary": "maxpool_with_argmax_2d_precomputed_strides", + "code": "\"\"\"\ninput_shape: [1, 1, 5, 5]\noutput_shape: [1, 1, 2, 2]\n\"\"\"\nnode = onnx.helper.make_node(\n 'MaxPool',\n inputs=['x'],\n outputs=['y', 'z'],\n kernel_shape=[2, 2],\n strides=[2, 2],\n storage_order=1\n)\nx = np.array([[[\n [1, 2, 3, 4, 5],\n [6, 7, 8, 9, 10],\n [11, 12, 13, 14, 15],\n [16, 17, 18, 19, 20],\n [21, 22, 23, 24, 25],\n]]]).astype(np.float32)\ny = np.array([[[[7, 9],\n [17, 19]]]]).astype(np.float32)\nz = np.array([[[[6, 16],\n [8, 18]]]]).astype(np.int64)\n\nexpect(node, inputs=[x], outputs=[y, z], name='test_maxpool_with_argmax_2d_precomputed_strides')" + } + ], + "category": "Pool" + }, + { + "name": "MaxPool", + "module": "ai.onnx", + "version": 11, + "support_level": "common", + "description": "MaxPool consumes an input tensor X and applies max pooling across\n the tensor according to kernel sizes, stride sizes, and pad lengths.\n max pooling consisting of computing the max on all values of a\n subset of the input tensor according to the kernel size and downsampling the\n data into the output tensor Y for further processing. The output spatial shape will be following:\n ```\n 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)\n ```\n or\n ```\n 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)\n ```\n if ceil_mode is enabled\n\n ```\n * pad_shape[i] is sum of pads along axis i\n ```\n\n `auto_pad` is a DEPRECATED attribute. If you are using them currently, the output spatial shape will be following:\n ```\n VALID: output_spatial_shape[i] = ceil((input_spatial_shape[i] - ((kernel_spatial_shape[i] - 1) * dilations[i] + 1) + 1) / strides_spatial_shape[i])\n SAME_UPPER or SAME_LOWER: output_spatial_shape[i] = ceil(input_spatial_shape[i] / strides_spatial_shape[i])\n ```\n And pad shape will be following if `SAME_UPPER` or `SAME_LOWER`:\n ```\n pad_shape[i] = (output_spatial_shape[i] - 1) * strides_spatial_shape[i] + ((kernel_spatial_shape[i] - 1) * dilations[i] + 1) - input_spatial_shape[i]\n ```\n The output of each pooling window is maximum number of elements exclude pad.\n ", + "attributes": [ + { + "name": "auto_pad", + "type": "string", + "required": false, + "default": "NOTSET", + "description": "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." + }, + { + "name": "ceil_mode", + "type": "int64", + "required": false, + "description": "Whether to use ceil or floor (default) to compute the output shape." + }, + { + "name": "dilations", + "type": "int64[]", + "required": false, + "description": "Dilation value along each spatial axis of filter. If not present, the dilation defaults to 1 along each spatial axis." + }, + { + "name": "kernel_shape", + "type": "int64[]", + "required": true, + "description": "The size of the kernel along each axis." + }, + { + "name": "pads", + "type": "int64[]", + "required": false, + "description": "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." + }, + { + "name": "storage_order", + "type": "int64", + "required": false, + "description": "The storage order of the tensor. 0 is row major, and 1 is column major." + }, + { + "name": "strides", + "type": "int64[]", + "required": false, + "description": "Stride along each spatial axis. If not present, the stride defaults to 1 along each spatial axis." + } + ], + "inputs": [ + { + "name": "X", + "type": "T", + "description": "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 ...]." + } + ], + "min_input": 1, + "max_input": 1, + "outputs": [ + { + "name": "Y", + "type": "T", + "description": "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" + }, + { + "name": "Indices", + "type": "I", + "option": "optional", + "description": "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)." + } + ], + "min_output": 1, + "max_output": 2, + "outputs_range": "1 - 2", + "type_constraints": [ + { + "description": "Constrain input and output types to float tensors.", + "type_param_str": "T", + "allowed_type_strs": [ + "tensor(float16)", + "tensor(float)", + "tensor(double)" + ] + }, + { + "description": "Constrain index tensor to int64", + "type_param_str": "I", + "allowed_type_strs": [ + "tensor(int64)" + ] + } + ], + "examples": [ + { + "summary": "maxpool_1d_default", + "code": "\"\"\"\ninput_shape: [1, 3, 32]\noutput_shape: [1, 3, 31]\n\"\"\"\nnode = onnx.helper.make_node(\n 'MaxPool',\n inputs=['x'],\n outputs=['y'],\n kernel_shape=[2],\n)\nx = np.random.randn(1, 3, 32).astype(np.float32)\nx_shape = np.shape(x)\nkernel_shape = [2]\nstrides = [1]\nout_shape = get_output_shape('VALID', x_shape[2:], kernel_shape, strides)\npadded = x\ny = pool(padded, x_shape, kernel_shape, strides, out_shape, [0], 'MAX')\n\nexpect(node, inputs=[x], outputs=[y], name='test_maxpool_1d_default')" + }, + { + "summary": "maxpool_2d_ceil", + "code": "\"\"\"\ninput_shape: [1, 1, 4, 4]\noutput_shape: [1, 1, 2, 2]\n\"\"\"\nnode = onnx.helper.make_node(\n 'MaxPool',\n inputs=['x'],\n outputs=['y'],\n kernel_shape=[3, 3],\n strides=[2, 2],\n ceil_mode=True\n)\nx = np.array([[[\n [1, 2, 3, 4],\n [5, 6, 7, 8],\n [9, 10, 11, 12],\n [13, 14, 15, 16],\n]]]).astype(np.float32)\ny = np.array([[[\n [11, 12],\n [15, 16]]]]).astype(np.float32)\n\nexpect(node, inputs=[x], outputs=[y], name='test_maxpool_2d_ceil')" + }, + { + "summary": "maxpool_2d_default", + "code": "\"\"\"\ninput_shape: [1, 3, 32, 32]\noutput_shape: [1, 3, 31, 31]\n\"\"\"\nnode = onnx.helper.make_node(\n 'MaxPool',\n inputs=['x'],\n outputs=['y'],\n kernel_shape=[2, 2],\n)\nx = np.random.randn(1, 3, 32, 32).astype(np.float32)\nx_shape = np.shape(x)\nkernel_shape = (2, 2)\nstrides = (1, 1)\nout_shape = get_output_shape('VALID', x_shape[2:], kernel_shape, strides)\npadded = x\ny = pool(padded, x_shape, kernel_shape, strides, out_shape, (0, 0), 'MAX')\n\nexpect(node, inputs=[x], outputs=[y], name='test_maxpool_2d_default')" + }, + { + "summary": "maxpool_2d_dilations", + "code": "\"\"\"\ninput_shape: [1, 1, 4, 4]\noutput_shape: [1, 1, 2, 2]\n\"\"\"\nnode = onnx.helper.make_node(\n 'MaxPool',\n inputs=['x'],\n outputs=['y'],\n kernel_shape=[2, 2],\n strides=[1, 1],\n dilations=[2, 2]\n)\nx = np.array([[[\n [1, 2, 3, 4],\n [5, 6, 7, 8],\n [9, 10, 11, 12],\n [13, 14, 15, 16],\n]]]).astype(np.float32)\ny = np.array([[[\n [11, 12],\n [15, 16]]]]).astype(np.float32)\n\nexpect(node, inputs=[x], outputs=[y], name='test_maxpool_2d_dilations')" + }, + { + "summary": "maxpool_2d_pads", + "code": "\"\"\"\ninput_shape: [1, 3, 28, 28]\noutput_shape: [1, 3, 30, 30]\npad_shape: [4, 4] -> [2, 2, 2, 2] by axis\n\"\"\"\nnode = onnx.helper.make_node(\n 'MaxPool',\n inputs=['x'],\n outputs=['y'],\n kernel_shape=[3, 3],\n pads=[2, 2, 2, 2]\n)\nx = np.random.randn(1, 3, 28, 28).astype(np.float32)\nx_shape = np.shape(x)\nkernel_shape = (3, 3)\nstrides = (1, 1)\npad_bottom = pad_top = pad_right = pad_left = 2\npad_shape = [pad_top + pad_bottom, pad_left + pad_right]\nout_shape = get_output_shape('VALID', np.add(x_shape[2:], pad_shape), kernel_shape, strides)\npadded = np.pad(x, ((0, 0), (0, 0), (pad_top, pad_bottom), (pad_left, pad_right)), mode='constant',\n constant_values=np.nan)\ny = pool(padded, x_shape, kernel_shape, strides, out_shape, pad_shape, 'MAX')\n\nexpect(node, inputs=[x], outputs=[y], name='test_maxpool_2d_pads')" + }, + { + "summary": "maxpool_2d_precomputed_pads", + "code": "\"\"\"\ninput_shape: [1, 1, 5, 5]\noutput_shape: [1, 1, 5, 5]\npad_shape: [4, 4] -> [2, 2, 2, 2] by axis\n\"\"\"\nnode = onnx.helper.make_node(\n 'MaxPool',\n inputs=['x'],\n outputs=['y'],\n kernel_shape=[5, 5],\n pads=[2, 2, 2, 2]\n\n)\nx = np.array([[[\n [1, 2, 3, 4, 5],\n [6, 7, 8, 9, 10],\n [11, 12, 13, 14, 15],\n [16, 17, 18, 19, 20],\n [21, 22, 23, 24, 25],\n]]]).astype(np.float32)\ny = np.array([[[\n [13, 14, 15, 15, 15],\n [18, 19, 20, 20, 20],\n [23, 24, 25, 25, 25],\n [23, 24, 25, 25, 25],\n [23, 24, 25, 25, 25]]]]).astype(np.float32)\n\nexpect(node, inputs=[x], outputs=[y], name='test_maxpool_2d_precomputed_pads')" + }, + { + "summary": "maxpool_2d_precomputed_same_upper", + "code": "\"\"\"\ninput_shape: [1, 1, 5, 5]\noutput_shape: [1, 1, 3, 3]\npad_shape: [2, 2] -> [1, 1, 1, 1] by axis\n\"\"\"\nnode = onnx.helper.make_node(\n 'MaxPool',\n inputs=['x'],\n outputs=['y'],\n kernel_shape=[3, 3],\n strides=[2, 2],\n auto_pad='SAME_UPPER'\n)\nx = np.array([[[\n [1, 2, 3, 4, 5],\n [6, 7, 8, 9, 10],\n [11, 12, 13, 14, 15],\n [16, 17, 18, 19, 20],\n [21, 22, 23, 24, 25],\n]]]).astype(np.float32)\ny = np.array([[[[7, 9, 10],\n [17, 19, 20],\n [22, 24, 25]]]]).astype(np.float32)\n\nexpect(node, inputs=[x], outputs=[y], name='test_maxpool_2d_precomputed_same_upper')" + }, + { + "summary": "maxpool_2d_precomputed_strides", + "code": "\"\"\"\ninput_shape: [1, 1, 5, 5]\noutput_shape: [1, 1, 2, 2]\n\"\"\"\nnode = onnx.helper.make_node(\n 'MaxPool',\n inputs=['x'],\n outputs=['y'],\n kernel_shape=[2, 2],\n strides=[2, 2]\n)\nx = np.array([[[\n [1, 2, 3, 4, 5],\n [6, 7, 8, 9, 10],\n [11, 12, 13, 14, 15],\n [16, 17, 18, 19, 20],\n [21, 22, 23, 24, 25],\n]]]).astype(np.float32)\ny = np.array([[[[7, 9],\n [17, 19]]]]).astype(np.float32)\n\nexpect(node, inputs=[x], outputs=[y], name='test_maxpool_2d_precomputed_strides')" + }, + { + "summary": "maxpool_2d_same_lower", + "code": "\"\"\"\ninput_shape: [1, 3, 32, 32]\noutput_shape: [1, 3, 32, 32]\npad_shape: [1, 1] -> [1, 0, 1, 0] by axis\n\"\"\"\nnode = onnx.helper.make_node(\n 'MaxPool',\n inputs=['x'],\n outputs=['y'],\n kernel_shape=[2, 2],\n auto_pad='SAME_LOWER'\n)\nx = np.random.randn(1, 3, 32, 32).astype(np.float32)\nx_shape = np.shape(x)\nkernel_shape = (2, 2)\nstrides = (1, 1)\nout_shape = get_output_shape('SAME_LOWER', x_shape[2:], kernel_shape, strides)\npad_shape = get_pad_shape('SAME_LOWER', x_shape[2:], kernel_shape, strides, out_shape)\npad_bottom = pad_shape[0] // 2\npad_top = pad_shape[0] - pad_bottom\npad_right = pad_shape[1] // 2\npad_left = pad_shape[1] - pad_right\npadded = np.pad(x, ((0, 0), (0, 0), (pad_top, pad_bottom), (pad_left, pad_right)), mode='constant',\n constant_values=np.nan)\ny = pool(padded, x_shape, kernel_shape, strides, out_shape, pad_shape, 'MAX')\n\nexpect(node, inputs=[x], outputs=[y], name='test_maxpool_2d_same_lower')" + }, + { + "summary": "maxpool_2d_same_upper", + "code": "\"\"\"\ninput_shape: [1, 3, 32, 32]\noutput_shape: [1, 3, 32, 32]\npad_shape: [1, 1] -> [0, 1, 0, 1] by axis\n\"\"\"\nnode = onnx.helper.make_node(\n 'MaxPool',\n inputs=['x'],\n outputs=['y'],\n kernel_shape=[2, 2],\n auto_pad='SAME_UPPER'\n)\nx = np.random.randn(1, 3, 32, 32).astype(np.float32)\nx_shape = np.shape(x)\nkernel_shape = (2, 2)\nstrides = (1, 1)\nout_shape = get_output_shape('SAME_UPPER', x_shape[2:], kernel_shape, strides)\npad_shape = get_pad_shape('SAME_UPPER', x_shape[2:], kernel_shape, strides, out_shape)\npad_top = pad_shape[0] // 2\npad_bottom = pad_shape[0] - pad_top\npad_left = pad_shape[1] // 2\npad_right = pad_shape[1] - pad_left\npadded = np.pad(x, ((0, 0), (0, 0), (pad_top, pad_bottom), (pad_left, pad_right)), mode='constant',\n constant_values=np.nan)\ny = pool(padded, x_shape, kernel_shape, strides, out_shape, pad_shape, 'MAX')\n\nexpect(node, inputs=[x], outputs=[y], name='test_maxpool_2d_same_upper')" + }, + { + "summary": "maxpool_2d_strides", + "code": "\"\"\"\ninput_shape: [1, 3, 32, 32]\noutput_shape: [1, 3, 10, 10]\n\"\"\"\nnode = onnx.helper.make_node(\n 'MaxPool',\n inputs=['x'],\n outputs=['y'],\n kernel_shape=[5, 5],\n strides=[3, 3]\n)\nx = np.random.randn(1, 3, 32, 32).astype(np.float32)\nx_shape = np.shape(x)\nkernel_shape = (5, 5)\nstrides = (3, 3)\nout_shape = get_output_shape('VALID', x_shape[2:], kernel_shape, strides)\npadded = x\ny = pool(padded, x_shape, kernel_shape, strides, out_shape, (0, 0), 'MAX')\n\nexpect(node, inputs=[x], outputs=[y], name='test_maxpool_2d_strides')" + }, + { + "summary": "maxpool_2d_uint8", + "code": "\"\"\"\ninput_shape: [1, 1, 5, 5]\noutput_shape: [1, 1, 5, 5]\npad_shape: [4, 4] -> [2, 2, 2, 2] by axis\n\"\"\"\nnode = onnx.helper.make_node(\n 'MaxPool',\n inputs=['x'],\n outputs=['y'],\n kernel_shape=[5, 5],\n pads=[2, 2, 2, 2]\n)\nx = np.array([[[\n [1, 2, 3, 4, 5],\n [6, 7, 8, 9, 10],\n [11, 12, 13, 14, 15],\n [16, 17, 18, 19, 20],\n [21, 22, 23, 24, 25],\n]]]).astype(np.uint8)\ny = np.array([[[\n [13, 14, 15, 15, 15],\n [18, 19, 20, 20, 20],\n [23, 24, 25, 25, 25],\n [23, 24, 25, 25, 25],\n [23, 24, 25, 25, 25]]]]).astype(np.uint8)\n\nexpect(node, inputs=[x], outputs=[y], name='test_maxpool_2d_uint8')" + }, + { + "summary": "maxpool_3d_default", + "code": "\"\"\"\ninput_shape: [1, 3, 32, 32, 32]\noutput_shape: [1, 3, 31, 31, 31]\n\"\"\"\nnode = onnx.helper.make_node(\n 'MaxPool',\n inputs=['x'],\n outputs=['y'],\n kernel_shape=[2, 2, 2],\n)\nx = np.random.randn(1, 3, 32, 32, 32).astype(np.float32)\nx_shape = np.shape(x)\nkernel_shape = [2, 2, 2]\nstrides = [1, 1, 1]\nout_shape = get_output_shape('VALID', x_shape[2:], kernel_shape, strides)\npadded = x\ny = pool(padded, x_shape, kernel_shape, strides, out_shape, [0, 0, 0], 'MAX')\n\nexpect(node, inputs=[x], outputs=[y], name='test_maxpool_3d_default')" + }, + { + "summary": "maxpool_with_argmax_2d_precomputed_pads", + "code": "\"\"\"\ninput_shape: [1, 1, 5, 5]\noutput_shape: [1, 1, 5, 5]\npad_shape: [4, 4] -> [2, 2, 2, 2] by axis\n\"\"\"\nnode = onnx.helper.make_node(\n 'MaxPool',\n inputs=['x'],\n outputs=['y', 'z'],\n kernel_shape=[5, 5],\n pads=[2, 2, 2, 2]\n)\nx = np.array([[[\n [1, 2, 3, 4, 5],\n [6, 7, 8, 9, 10],\n [11, 12, 13, 14, 15],\n [16, 17, 18, 19, 20],\n [21, 22, 23, 24, 25],\n]]]).astype(np.float32)\ny = np.array([[[\n [13, 14, 15, 15, 15],\n [18, 19, 20, 20, 20],\n [23, 24, 25, 25, 25],\n [23, 24, 25, 25, 25],\n [23, 24, 25, 25, 25]]]]).astype(np.float32)\nz = np.array([[[\n [12, 13, 14, 14, 14],\n [17, 18, 19, 19, 19],\n [22, 23, 24, 24, 24],\n [22, 23, 24, 24, 24],\n [22, 23, 24, 24, 24]]]]).astype(np.int64)\n\nexpect(node, inputs=[x], outputs=[y, z], name='test_maxpool_with_argmax_2d_precomputed_pads')" + }, + { + "summary": "maxpool_with_argmax_2d_precomputed_strides", + "code": "\"\"\"\ninput_shape: [1, 1, 5, 5]\noutput_shape: [1, 1, 2, 2]\n\"\"\"\nnode = onnx.helper.make_node(\n 'MaxPool',\n inputs=['x'],\n outputs=['y', 'z'],\n kernel_shape=[2, 2],\n strides=[2, 2],\n storage_order=1\n)\nx = np.array([[[\n [1, 2, 3, 4, 5],\n [6, 7, 8, 9, 10],\n [11, 12, 13, 14, 15],\n [16, 17, 18, 19, 20],\n [21, 22, 23, 24, 25],\n]]]).astype(np.float32)\ny = np.array([[[[7, 9],\n [17, 19]]]]).astype(np.float32)\nz = np.array([[[[6, 16],\n [8, 18]]]]).astype(np.int64)\n\nexpect(node, inputs=[x], outputs=[y, z], name='test_maxpool_with_argmax_2d_precomputed_strides')" + } + ], + "category": "Pool" + }, + { + "name": "MaxPool", + "module": "ai.onnx", + "version": 12, + "support_level": "common", + "description": "MaxPool consumes an input tensor X and applies max pooling across\n the tensor according to kernel sizes, stride sizes, and pad lengths.\n max pooling consisting of computing the max on all values of a\n subset of the input tensor according to the kernel size and downsampling the\n data into the output tensor Y for further processing. The output spatial shape will be following:\n ```\n 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)\n ```\n or\n ```\n 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)\n ```\n if ceil_mode is enabled\n\n ```\n * pad_shape[i] is sum of pads along axis i\n ```\n\n `auto_pad` is a DEPRECATED attribute. If you are using them currently, the output spatial shape will be following:\n ```\n VALID: output_spatial_shape[i] = ceil((input_spatial_shape[i] - ((kernel_spatial_shape[i] - 1) * dilations[i] + 1) + 1) / strides_spatial_shape[i])\n SAME_UPPER or SAME_LOWER: output_spatial_shape[i] = ceil(input_spatial_shape[i] / strides_spatial_shape[i])\n ```\n And pad shape will be following if `SAME_UPPER` or `SAME_LOWER`:\n ```\n pad_shape[i] = (output_spatial_shape[i] - 1) * strides_spatial_shape[i] + ((kernel_spatial_shape[i] - 1) * dilations[i] + 1) - input_spatial_shape[i]\n ```\n The output of each pooling window is maximum number of elements exclude pad. \n ", + "attributes": [ + { + "name": "auto_pad", + "type": "string", + "required": false, + "default": "NOTSET", + "description": "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." + }, + { + "name": "ceil_mode", + "type": "int64", + "required": false, + "description": "Whether to use ceil or floor (default) to compute the output shape." + }, + { + "name": "dilations", + "type": "int64[]", + "required": false, + "description": "Dilation value along each spatial axis of filter. If not present, the dilation defaults to 1 along each spatial axis." + }, + { + "name": "kernel_shape", + "type": "int64[]", + "required": true, + "description": "The size of the kernel along each axis." + }, + { + "name": "pads", + "type": "int64[]", + "required": false, + "description": "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." + }, + { + "name": "storage_order", + "type": "int64", + "required": false, + "description": "The storage order of the tensor. 0 is row major, and 1 is column major." + }, + { + "name": "strides", + "type": "int64[]", + "required": false, + "description": "Stride along each spatial axis. If not present, the stride defaults to 1 along each spatial axis." + } + ], + "inputs": [ + { + "name": "X", + "type": "T", + "description": "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 ...]." + } + ], + "min_input": 1, + "max_input": 1, + "outputs": [ + { + "name": "Y", + "type": "T", + "description": "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" + }, + { + "name": "Indices", + "type": "I", + "option": "optional", + "description": "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)." + } + ], + "min_output": 1, + "max_output": 2, + "outputs_range": "1 - 2", + "type_constraints": [ + { + "description": "Constrain input and output types to float and 8 bit tensors.", + "type_param_str": "T", + "allowed_type_strs": [ + "tensor(float16)", + "tensor(float)", + "tensor(double)", + "tensor(int8)", + "tensor(uint8)" + ] + }, + { + "description": "Constrain index tensor to int64", + "type_param_str": "I", + "allowed_type_strs": [ + "tensor(int64)" + ] + } + ], + "examples": [ + { + "summary": "maxpool_1d_default", + "code": "\"\"\"\ninput_shape: [1, 3, 32]\noutput_shape: [1, 3, 31]\n\"\"\"\nnode = onnx.helper.make_node(\n 'MaxPool',\n inputs=['x'],\n outputs=['y'],\n kernel_shape=[2],\n)\nx = np.random.randn(1, 3, 32).astype(np.float32)\nx_shape = np.shape(x)\nkernel_shape = [2]\nstrides = [1]\nout_shape = get_output_shape('VALID', x_shape[2:], kernel_shape, strides)\npadded = x\ny = pool(padded, x_shape, kernel_shape, strides, out_shape, [0], 'MAX')\n\nexpect(node, inputs=[x], outputs=[y], name='test_maxpool_1d_default')" + }, + { + "summary": "maxpool_2d_ceil", + "code": "\"\"\"\ninput_shape: [1, 1, 4, 4]\noutput_shape: [1, 1, 2, 2]\n\"\"\"\nnode = onnx.helper.make_node(\n 'MaxPool',\n inputs=['x'],\n outputs=['y'],\n kernel_shape=[3, 3],\n strides=[2, 2],\n ceil_mode=True\n)\nx = np.array([[[\n [1, 2, 3, 4],\n [5, 6, 7, 8],\n [9, 10, 11, 12],\n [13, 14, 15, 16],\n]]]).astype(np.float32)\ny = np.array([[[\n [11, 12],\n [15, 16]]]]).astype(np.float32)\n\nexpect(node, inputs=[x], outputs=[y], name='test_maxpool_2d_ceil')" + }, + { + "summary": "maxpool_2d_default", + "code": "\"\"\"\ninput_shape: [1, 3, 32, 32]\noutput_shape: [1, 3, 31, 31]\n\"\"\"\nnode = onnx.helper.make_node(\n 'MaxPool',\n inputs=['x'],\n outputs=['y'],\n kernel_shape=[2, 2],\n)\nx = np.random.randn(1, 3, 32, 32).astype(np.float32)\nx_shape = np.shape(x)\nkernel_shape = (2, 2)\nstrides = (1, 1)\nout_shape = get_output_shape('VALID', x_shape[2:], kernel_shape, strides)\npadded = x\ny = pool(padded, x_shape, kernel_shape, strides, out_shape, (0, 0), 'MAX')\n\nexpect(node, inputs=[x], outputs=[y], name='test_maxpool_2d_default')" + }, + { + "summary": "maxpool_2d_dilations", + "code": "\"\"\"\ninput_shape: [1, 1, 4, 4]\noutput_shape: [1, 1, 2, 2]\n\"\"\"\nnode = onnx.helper.make_node(\n 'MaxPool',\n inputs=['x'],\n outputs=['y'],\n kernel_shape=[2, 2],\n strides=[1, 1],\n dilations=[2, 2]\n)\nx = np.array([[[\n [1, 2, 3, 4],\n [5, 6, 7, 8],\n [9, 10, 11, 12],\n [13, 14, 15, 16],\n]]]).astype(np.float32)\ny = np.array([[[\n [11, 12],\n [15, 16]]]]).astype(np.float32)\n\nexpect(node, inputs=[x], outputs=[y], name='test_maxpool_2d_dilations')" + }, + { + "summary": "maxpool_2d_pads", + "code": "\"\"\"\ninput_shape: [1, 3, 28, 28]\noutput_shape: [1, 3, 30, 30]\npad_shape: [4, 4] -> [2, 2, 2, 2] by axis\n\"\"\"\nnode = onnx.helper.make_node(\n 'MaxPool',\n inputs=['x'],\n outputs=['y'],\n kernel_shape=[3, 3],\n pads=[2, 2, 2, 2]\n)\nx = np.random.randn(1, 3, 28, 28).astype(np.float32)\nx_shape = np.shape(x)\nkernel_shape = (3, 3)\nstrides = (1, 1)\npad_bottom = pad_top = pad_right = pad_left = 2\npad_shape = [pad_top + pad_bottom, pad_left + pad_right]\nout_shape = get_output_shape('VALID', np.add(x_shape[2:], pad_shape), kernel_shape, strides)\npadded = np.pad(x, ((0, 0), (0, 0), (pad_top, pad_bottom), (pad_left, pad_right)), mode='constant',\n constant_values=np.nan)\ny = pool(padded, x_shape, kernel_shape, strides, out_shape, pad_shape, 'MAX')\n\nexpect(node, inputs=[x], outputs=[y], name='test_maxpool_2d_pads')" + }, + { + "summary": "maxpool_2d_precomputed_pads", + "code": "\"\"\"\ninput_shape: [1, 1, 5, 5]\noutput_shape: [1, 1, 5, 5]\npad_shape: [4, 4] -> [2, 2, 2, 2] by axis\n\"\"\"\nnode = onnx.helper.make_node(\n 'MaxPool',\n inputs=['x'],\n outputs=['y'],\n kernel_shape=[5, 5],\n pads=[2, 2, 2, 2]\n\n)\nx = np.array([[[\n [1, 2, 3, 4, 5],\n [6, 7, 8, 9, 10],\n [11, 12, 13, 14, 15],\n [16, 17, 18, 19, 20],\n [21, 22, 23, 24, 25],\n]]]).astype(np.float32)\ny = np.array([[[\n [13, 14, 15, 15, 15],\n [18, 19, 20, 20, 20],\n [23, 24, 25, 25, 25],\n [23, 24, 25, 25, 25],\n [23, 24, 25, 25, 25]]]]).astype(np.float32)\n\nexpect(node, inputs=[x], outputs=[y], name='test_maxpool_2d_precomputed_pads')" + }, + { + "summary": "maxpool_2d_precomputed_same_upper", + "code": "\"\"\"\ninput_shape: [1, 1, 5, 5]\noutput_shape: [1, 1, 3, 3]\npad_shape: [2, 2] -> [1, 1, 1, 1] by axis\n\"\"\"\nnode = onnx.helper.make_node(\n 'MaxPool',\n inputs=['x'],\n outputs=['y'],\n kernel_shape=[3, 3],\n strides=[2, 2],\n auto_pad='SAME_UPPER'\n)\nx = np.array([[[\n [1, 2, 3, 4, 5],\n [6, 7, 8, 9, 10],\n [11, 12, 13, 14, 15],\n [16, 17, 18, 19, 20],\n [21, 22, 23, 24, 25],\n]]]).astype(np.float32)\ny = np.array([[[[7, 9, 10],\n [17, 19, 20],\n [22, 24, 25]]]]).astype(np.float32)\n\nexpect(node, inputs=[x], outputs=[y], name='test_maxpool_2d_precomputed_same_upper')" + }, + { + "summary": "maxpool_2d_precomputed_strides", + "code": "\"\"\"\ninput_shape: [1, 1, 5, 5]\noutput_shape: [1, 1, 2, 2]\n\"\"\"\nnode = onnx.helper.make_node(\n 'MaxPool',\n inputs=['x'],\n outputs=['y'],\n kernel_shape=[2, 2],\n strides=[2, 2]\n)\nx = np.array([[[\n [1, 2, 3, 4, 5],\n [6, 7, 8, 9, 10],\n [11, 12, 13, 14, 15],\n [16, 17, 18, 19, 20],\n [21, 22, 23, 24, 25],\n]]]).astype(np.float32)\ny = np.array([[[[7, 9],\n [17, 19]]]]).astype(np.float32)\n\nexpect(node, inputs=[x], outputs=[y], name='test_maxpool_2d_precomputed_strides')" + }, + { + "summary": "maxpool_2d_same_lower", + "code": "\"\"\"\ninput_shape: [1, 3, 32, 32]\noutput_shape: [1, 3, 32, 32]\npad_shape: [1, 1] -> [1, 0, 1, 0] by axis\n\"\"\"\nnode = onnx.helper.make_node(\n 'MaxPool',\n inputs=['x'],\n outputs=['y'],\n kernel_shape=[2, 2],\n auto_pad='SAME_LOWER'\n)\nx = np.random.randn(1, 3, 32, 32).astype(np.float32)\nx_shape = np.shape(x)\nkernel_shape = (2, 2)\nstrides = (1, 1)\nout_shape = get_output_shape('SAME_LOWER', x_shape[2:], kernel_shape, strides)\npad_shape = get_pad_shape('SAME_LOWER', x_shape[2:], kernel_shape, strides, out_shape)\npad_bottom = pad_shape[0] // 2\npad_top = pad_shape[0] - pad_bottom\npad_right = pad_shape[1] // 2\npad_left = pad_shape[1] - pad_right\npadded = np.pad(x, ((0, 0), (0, 0), (pad_top, pad_bottom), (pad_left, pad_right)), mode='constant',\n constant_values=np.nan)\ny = pool(padded, x_shape, kernel_shape, strides, out_shape, pad_shape, 'MAX')\n\nexpect(node, inputs=[x], outputs=[y], name='test_maxpool_2d_same_lower')" + }, + { + "summary": "maxpool_2d_same_upper", + "code": "\"\"\"\ninput_shape: [1, 3, 32, 32]\noutput_shape: [1, 3, 32, 32]\npad_shape: [1, 1] -> [0, 1, 0, 1] by axis\n\"\"\"\nnode = onnx.helper.make_node(\n 'MaxPool',\n inputs=['x'],\n outputs=['y'],\n kernel_shape=[2, 2],\n auto_pad='SAME_UPPER'\n)\nx = np.random.randn(1, 3, 32, 32).astype(np.float32)\nx_shape = np.shape(x)\nkernel_shape = (2, 2)\nstrides = (1, 1)\nout_shape = get_output_shape('SAME_UPPER', x_shape[2:], kernel_shape, strides)\npad_shape = get_pad_shape('SAME_UPPER', x_shape[2:], kernel_shape, strides, out_shape)\npad_top = pad_shape[0] // 2\npad_bottom = pad_shape[0] - pad_top\npad_left = pad_shape[1] // 2\npad_right = pad_shape[1] - pad_left\npadded = np.pad(x, ((0, 0), (0, 0), (pad_top, pad_bottom), (pad_left, pad_right)), mode='constant',\n constant_values=np.nan)\ny = pool(padded, x_shape, kernel_shape, strides, out_shape, pad_shape, 'MAX')\n\nexpect(node, inputs=[x], outputs=[y], name='test_maxpool_2d_same_upper')" + }, + { + "summary": "maxpool_2d_strides", + "code": "\"\"\"\ninput_shape: [1, 3, 32, 32]\noutput_shape: [1, 3, 10, 10]\n\"\"\"\nnode = onnx.helper.make_node(\n 'MaxPool',\n inputs=['x'],\n outputs=['y'],\n kernel_shape=[5, 5],\n strides=[3, 3]\n)\nx = np.random.randn(1, 3, 32, 32).astype(np.float32)\nx_shape = np.shape(x)\nkernel_shape = (5, 5)\nstrides = (3, 3)\nout_shape = get_output_shape('VALID', x_shape[2:], kernel_shape, strides)\npadded = x\ny = pool(padded, x_shape, kernel_shape, strides, out_shape, (0, 0), 'MAX')\n\nexpect(node, inputs=[x], outputs=[y], name='test_maxpool_2d_strides')" + }, + { + "summary": "maxpool_2d_uint8", + "code": "\"\"\"\ninput_shape: [1, 1, 5, 5]\noutput_shape: [1, 1, 5, 5]\npad_shape: [4, 4] -> [2, 2, 2, 2] by axis\n\"\"\"\nnode = onnx.helper.make_node(\n 'MaxPool',\n inputs=['x'],\n outputs=['y'],\n kernel_shape=[5, 5],\n pads=[2, 2, 2, 2]\n)\nx = np.array([[[\n [1, 2, 3, 4, 5],\n [6, 7, 8, 9, 10],\n [11, 12, 13, 14, 15],\n [16, 17, 18, 19, 20],\n [21, 22, 23, 24, 25],\n]]]).astype(np.uint8)\ny = np.array([[[\n [13, 14, 15, 15, 15],\n [18, 19, 20, 20, 20],\n [23, 24, 25, 25, 25],\n [23, 24, 25, 25, 25],\n [23, 24, 25, 25, 25]]]]).astype(np.uint8)\n\nexpect(node, inputs=[x], outputs=[y], name='test_maxpool_2d_uint8')" + }, + { + "summary": "maxpool_3d_default", + "code": "\"\"\"\ninput_shape: [1, 3, 32, 32, 32]\noutput_shape: [1, 3, 31, 31, 31]\n\"\"\"\nnode = onnx.helper.make_node(\n 'MaxPool',\n inputs=['x'],\n outputs=['y'],\n kernel_shape=[2, 2, 2],\n)\nx = np.random.randn(1, 3, 32, 32, 32).astype(np.float32)\nx_shape = np.shape(x)\nkernel_shape = [2, 2, 2]\nstrides = [1, 1, 1]\nout_shape = get_output_shape('VALID', x_shape[2:], kernel_shape, strides)\npadded = x\ny = pool(padded, x_shape, kernel_shape, strides, out_shape, [0, 0, 0], 'MAX')\n\nexpect(node, inputs=[x], outputs=[y], name='test_maxpool_3d_default')" + }, + { + "summary": "maxpool_with_argmax_2d_precomputed_pads", + "code": "\"\"\"\ninput_shape: [1, 1, 5, 5]\noutput_shape: [1, 1, 5, 5]\npad_shape: [4, 4] -> [2, 2, 2, 2] by axis\n\"\"\"\nnode = onnx.helper.make_node(\n 'MaxPool',\n inputs=['x'],\n outputs=['y', 'z'],\n kernel_shape=[5, 5],\n pads=[2, 2, 2, 2]\n)\nx = np.array([[[\n [1, 2, 3, 4, 5],\n [6, 7, 8, 9, 10],\n [11, 12, 13, 14, 15],\n [16, 17, 18, 19, 20],\n [21, 22, 23, 24, 25],\n]]]).astype(np.float32)\ny = np.array([[[\n [13, 14, 15, 15, 15],\n [18, 19, 20, 20, 20],\n [23, 24, 25, 25, 25],\n [23, 24, 25, 25, 25],\n [23, 24, 25, 25, 25]]]]).astype(np.float32)\nz = np.array([[[\n [12, 13, 14, 14, 14],\n [17, 18, 19, 19, 19],\n [22, 23, 24, 24, 24],\n [22, 23, 24, 24, 24],\n [22, 23, 24, 24, 24]]]]).astype(np.int64)\n\nexpect(node, inputs=[x], outputs=[y, z], name='test_maxpool_with_argmax_2d_precomputed_pads')" + }, + { + "summary": "maxpool_with_argmax_2d_precomputed_strides", + "code": "\"\"\"\ninput_shape: [1, 1, 5, 5]\noutput_shape: [1, 1, 2, 2]\n\"\"\"\nnode = onnx.helper.make_node(\n 'MaxPool',\n inputs=['x'],\n outputs=['y', 'z'],\n kernel_shape=[2, 2],\n strides=[2, 2],\n storage_order=1\n)\nx = np.array([[[\n [1, 2, 3, 4, 5],\n [6, 7, 8, 9, 10],\n [11, 12, 13, 14, 15],\n [16, 17, 18, 19, 20],\n [21, 22, 23, 24, 25],\n]]]).astype(np.float32)\ny = np.array([[[[7, 9],\n [17, 19]]]]).astype(np.float32)\nz = np.array([[[[6, 16],\n [8, 18]]]]).astype(np.int64)\n\nexpect(node, inputs=[x], outputs=[y, z], name='test_maxpool_with_argmax_2d_precomputed_strides')" + } + ], + "category": "Pool" + }, + { + "name": "MaxRoiPool", + "module": "ai.onnx", + "version": 1, + "support_level": "common", + "description": "ROI max pool consumes an input tensor X and region of interests (RoIs) to\n apply max pooling across each RoI, to produce output 4-D tensor of shape\n (num_rois, channels, pooled_shape[0], pooled_shape[1]).", + "attributes": [ + { + "name": "pooled_shape", + "type": "int64[]", + "required": true, + "description": "ROI pool output shape (height, width)." + }, + { + "name": "spatial_scale", + "type": "float32", + "required": false, + "default": 1.0, + "description": "Multiplicative spatial scale factor to translate ROI coordinates from their input scale to the scale used when pooling." + } + ], + "inputs": [ + { + "name": "X", + "type": "T", + "description": "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." + }, + { + "name": "rois", + "type": "T", + "description": "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], ...]." + } + ], + "min_input": 2, + "max_input": 2, + "outputs": [ + { + "name": "Y", + "type": "T", + "description": "RoI pooled output 4-D tensor of shape (num_rois, channels, pooled_shape[0], pooled_shape[1])." + } + ], + "min_output": 1, + "max_output": 1, + "type_constraints": [ + { + "description": "Constrain input and output types to float tensors.", + "type_param_str": "T", + "allowed_type_strs": [ + "tensor(float16)", + "tensor(float)", + "tensor(double)" + ] + } + ], + "category": "Pool" + }, + { + "name": "MaxUnpool", + "module": "ai.onnx", + "version": 9, + "support_level": "common", + "description": "MaxUnpool essentially computes the partial inverse of the MaxPool op.\n The input information to this op is typically the the output information from a MaxPool op. The first\n input tensor X is the tensor that needs to be unpooled, which is typically the pooled tensor (first output)\n from MaxPool. The second input tensor, I, contains the indices to the (locally maximal) elements corrsponding\n to the elements in the first input tensor X. Input tensor I is typically the second output of the MaxPool op.\n The third (optional) input is a tensor that specifies the output size of the unpooling operation.\n\nMaxUnpool is intended to do 'partial' inverse of the MaxPool op. 'Partial' because all the non-maximal\n values from the original input to MaxPool are set to zero in the output of the MaxUnpool op. Pooling\n the result of an unpooling operation should give back the original input to the unpooling op.\n\nMaxUnpool can produce the same output size for several input sizes, which makes unpooling op ambiguous.\n The third input argument, output_size, is meant to disambiguate the op and produce output tensor of\n known/predictable size.\n\nIn addition to the inputs, MaxUnpool takes three attributes, namely kernel_shape, strides, and pads,\n which define the exact unpooling op. The attributes typically have the same values as the corrsponding\n pooling op that the unpooling op is trying to invert.\n", + "attributes": [ + { + "name": "kernel_shape", + "type": "int64[]", + "required": true, + "description": "The size of the kernel along each axis." + }, + { + "name": "pads", + "type": "int64[]", + "required": false, + "description": "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." + }, + { + "name": "strides", + "type": "int64[]", + "required": false, + "description": "Stride along each spatial axis." + } + ], + "inputs": [ + { + "name": "X", + "type": "T1", + "description": "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 ...]." + }, + { + "name": "I", + "type": "T2", + "description": "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)." + }, + { + "name": "output_shape", + "type": "T2", + "option": "optional", + "description": "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." + } + ], + "min_input": 2, + "max_input": 3, + "outputs": [ + { + "name": "output", + "type": "T1", + "description": "Output data tensor that contains the result of the unpooling." + } + ], + "min_output": 1, + "max_output": 1, + "inputs_range": "2 - 3", + "type_constraints": [ + { + "description": "Constrain input and output types to float tensors.", + "type_param_str": "T1", + "allowed_type_strs": [ + "tensor(float16)", + "tensor(float)", + "tensor(double)" + ] + }, + { + "description": "Constrain index tensor to int64", + "type_param_str": "T2", + "allowed_type_strs": [ + "tensor(int64)" + ] + } + ], + "examples": [ + { + "summary": "with_output_shape", + "code": "node = onnx.helper.make_node(\n 'MaxUnpool',\n inputs=['xT', 'xI', 'output_shape'],\n outputs=['y'],\n kernel_shape=[2, 2],\n strides=[2, 2]\n)\nxT = np.array([[[[5, 6],\n [7, 8]]]], dtype=np.float32)\nxI = np.array([[[[5, 7],\n [13, 15]]]], dtype=np.int64)\noutput_shape = np.array((1, 1, 5, 5), dtype=np.int64)\ny = np.array([[[[0, 0, 0, 0, 0],\n [0, 5, 0, 6, 0],\n [0, 0, 0, 0, 0],\n [0, 7, 0, 8, 0],\n [0, 0, 0, 0, 0]]]], dtype=np.float32)\nexpect(node, inputs=[xT, xI, output_shape], outputs=[y], name='test_maxunpool_export_with_output_shape')" + }, + { + "summary": "without_output_shape", + "code": "node = onnx.helper.make_node(\n 'MaxUnpool',\n inputs=['xT', 'xI'],\n outputs=['y'],\n kernel_shape=[2, 2],\n strides=[2, 2]\n)\nxT = np.array([[[[1, 2],\n [3, 4]]]], dtype=np.float32)\nxI = np.array([[[[5, 7],\n [13, 15]]]], dtype=np.int64)\ny = np.array([[[[0, 0, 0, 0],\n [0, 1, 0, 2],\n [0, 0, 0, 0],\n [0, 3, 0, 4]]]], dtype=np.float32)\nexpect(node, inputs=[xT, xI], outputs=[y], name='test_maxunpool_export_without_output_shape')" + } + ] + }, + { + "name": "MaxUnpool", + "module": "ai.onnx", + "version": 11, + "support_level": "common", + "description": "MaxUnpool essentially computes the partial inverse of the MaxPool op.\n The input information to this op is typically the the output information from a MaxPool op. The first\n input tensor X is the tensor that needs to be unpooled, which is typically the pooled tensor (first output)\n from MaxPool. The second input tensor, I, contains the indices to the (locally maximal) elements corrsponding\n to the elements in the first input tensor X. Input tensor I is typically the second output of the MaxPool op.\n The third (optional) input is a tensor that specifies the output size of the unpooling operation.\n\nMaxUnpool is intended to do 'partial' inverse of the MaxPool op. 'Partial' because all the non-maximal\n values from the original input to MaxPool are set to zero in the output of the MaxUnpool op. Pooling\n the result of an unpooling operation should give back the original input to the unpooling op.\n\nMaxUnpool can produce the same output size for several input sizes, which makes unpooling op ambiguous.\n The third input argument, output_size, is meant to disambiguate the op and produce output tensor of\n known/predictable size.\n\nIn addition to the inputs, MaxUnpool takes three attributes, namely kernel_shape, strides, and pads,\n which define the exact unpooling op. The attributes typically have the same values as the corrsponding\n pooling op that the unpooling op is trying to invert.\n", + "attributes": [ + { + "name": "kernel_shape", + "type": "int64[]", + "required": true, + "description": "The size of the kernel along each axis." + }, + { + "name": "pads", + "type": "int64[]", + "required": false, + "description": "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." + }, + { + "name": "strides", + "type": "int64[]", + "required": false, + "description": "Stride along each spatial axis. If not present, the stride defaults to 1 along each spatial axis." + } + ], + "inputs": [ + { + "name": "X", + "type": "T1", + "description": "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 ...]." + }, + { + "name": "I", + "type": "T2", + "description": "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)." + }, + { + "name": "output_shape", + "type": "T2", + "option": "optional", + "description": "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." + } + ], + "min_input": 2, + "max_input": 3, + "outputs": [ + { + "name": "output", + "type": "T1", + "description": "Output data tensor that contains the result of the unpooling." + } + ], + "min_output": 1, + "max_output": 1, + "inputs_range": "2 - 3", + "type_constraints": [ + { + "description": "Constrain input and output types to float tensors.", + "type_param_str": "T1", + "allowed_type_strs": [ + "tensor(float16)", + "tensor(float)", + "tensor(double)" + ] + }, + { + "description": "Constrain index tensor to int64", + "type_param_str": "T2", + "allowed_type_strs": [ + "tensor(int64)" + ] + } + ], + "examples": [ + { + "summary": "with_output_shape", + "code": "node = onnx.helper.make_node(\n 'MaxUnpool',\n inputs=['xT', 'xI', 'output_shape'],\n outputs=['y'],\n kernel_shape=[2, 2],\n strides=[2, 2]\n)\nxT = np.array([[[[5, 6],\n [7, 8]]]], dtype=np.float32)\nxI = np.array([[[[5, 7],\n [13, 15]]]], dtype=np.int64)\noutput_shape = np.array((1, 1, 5, 5), dtype=np.int64)\ny = np.array([[[[0, 0, 0, 0, 0],\n [0, 5, 0, 6, 0],\n [0, 0, 0, 0, 0],\n [0, 7, 0, 8, 0],\n [0, 0, 0, 0, 0]]]], dtype=np.float32)\nexpect(node, inputs=[xT, xI, output_shape], outputs=[y], name='test_maxunpool_export_with_output_shape')" + }, + { + "summary": "without_output_shape", + "code": "node = onnx.helper.make_node(\n 'MaxUnpool',\n inputs=['xT', 'xI'],\n outputs=['y'],\n kernel_shape=[2, 2],\n strides=[2, 2]\n)\nxT = np.array([[[[1, 2],\n [3, 4]]]], dtype=np.float32)\nxI = np.array([[[[5, 7],\n [13, 15]]]], dtype=np.int64)\ny = np.array([[[[0, 0, 0, 0],\n [0, 1, 0, 2],\n [0, 0, 0, 0],\n [0, 3, 0, 4]]]], dtype=np.float32)\nexpect(node, inputs=[xT, xI], outputs=[y], name='test_maxunpool_export_without_output_shape')" + } + ] + }, + { + "name": "Mean", + "module": "ai.onnx", + "version": 1, + "support_level": "common", + "description": "Element-wise mean of each of the input tensors. All inputs and outputs must\nhave the same shape and data type.\n", + "attributes": [ + { + "name": "consumed_inputs", + "type": "int64[]", + "required": false, + "description": "legacy optimization attribute." + } + ], + "inputs": [ + { + "name": "data_0", + "type": "T", + "list": true, + "description": "List of tensors for Mean." + } + ], + "min_input": 1, + "max_input": 2147483647, + "outputs": [ + { + "name": "mean", + "type": "T", + "description": "Output tensor. Same dimension as inputs." + } + ], + "min_output": 1, + "max_output": 1, + "inputs_range": "1 - ∞", + "type_constraints": [ + { + "description": "Constrain input and output types to float tensors.", + "type_param_str": "T", + "allowed_type_strs": [ + "tensor(float16)", + "tensor(float)", + "tensor(double)" + ] + } + ], + "examples": [ + { + "summary": "mean", + "code": "data_0 = np.array([3, 0, 2]).astype(np.float32)\ndata_1 = np.array([1, 3, 4]).astype(np.float32)\ndata_2 = np.array([2, 6, 6]).astype(np.float32)\nresult = np.array([2, 3, 4]).astype(np.float32)\nnode = onnx.helper.make_node(\n 'Mean',\n inputs=['data_0', 'data_1', 'data_2'],\n outputs=['result'],\n)\nexpect(node, inputs=[data_0, data_1, data_2], outputs=[result],\n name='test_mean_example')\n\nnode = onnx.helper.make_node(\n 'Mean',\n inputs=['data_0'],\n outputs=['result'],\n)\nexpect(node, inputs=[data_0], outputs=[data_0],\n name='test_mean_one_input')\n\nresult = np.divide(np.add(data_0, data_1), 2.)\nnode = onnx.helper.make_node(\n 'Mean',\n inputs=['data_0', 'data_1'],\n outputs=['result'],\n)\nexpect(node, inputs=[data_0, data_1], outputs=[result],\n name='test_mean_two_inputs')" + } + ] + }, + { + "name": "Mean", + "module": "ai.onnx", + "version": 6, + "support_level": "common", + "description": "Element-wise mean of each of the input tensors. All inputs and outputs must\nhave the same shape and data type.\n", + "inputs": [ + { + "name": "data_0", + "type": "T", + "list": true, + "description": "List of tensors for Mean." + } + ], + "min_input": 1, + "max_input": 2147483647, + "outputs": [ + { + "name": "mean", + "type": "T", + "description": "Output tensor. Same dimension as inputs." + } + ], + "min_output": 1, + "max_output": 1, + "inputs_range": "1 - ∞", + "type_constraints": [ + { + "description": "Constrain input and output types to float tensors.", + "type_param_str": "T", + "allowed_type_strs": [ + "tensor(float16)", + "tensor(float)", + "tensor(double)" + ] + } + ], + "examples": [ + { + "summary": "mean", + "code": "data_0 = np.array([3, 0, 2]).astype(np.float32)\ndata_1 = np.array([1, 3, 4]).astype(np.float32)\ndata_2 = np.array([2, 6, 6]).astype(np.float32)\nresult = np.array([2, 3, 4]).astype(np.float32)\nnode = onnx.helper.make_node(\n 'Mean',\n inputs=['data_0', 'data_1', 'data_2'],\n outputs=['result'],\n)\nexpect(node, inputs=[data_0, data_1, data_2], outputs=[result],\n name='test_mean_example')\n\nnode = onnx.helper.make_node(\n 'Mean',\n inputs=['data_0'],\n outputs=['result'],\n)\nexpect(node, inputs=[data_0], outputs=[data_0],\n name='test_mean_one_input')\n\nresult = np.divide(np.add(data_0, data_1), 2.)\nnode = onnx.helper.make_node(\n 'Mean',\n inputs=['data_0', 'data_1'],\n outputs=['result'],\n)\nexpect(node, inputs=[data_0, data_1], outputs=[result],\n name='test_mean_two_inputs')" + } + ] + }, + { + "name": "Mean", + "module": "ai.onnx", + "version": 8, + "support_level": "common", + "description": "Element-wise mean of each of the input tensors (with Numpy-style broadcasting support).\nAll inputs and outputs must have the same data type.\nThis operator supports **multidirectional (i.e., Numpy-style) broadcasting**; for more details please check [the doc](https://github.com/onnx/onnx/blob/master/docs/Broadcasting.md).\n", + "inputs": [ + { + "name": "data_0", + "type": "T", + "list": true, + "description": "List of tensors for mean." + } + ], + "min_input": 1, + "max_input": 2147483647, + "outputs": [ + { + "name": "mean", + "type": "T", + "description": "Output tensor." + } + ], + "min_output": 1, + "max_output": 1, + "inputs_range": "1 - ∞", + "type_constraints": [ + { + "description": "Constrain input and output types to float tensors.", + "type_param_str": "T", + "allowed_type_strs": [ + "tensor(float16)", + "tensor(float)", + "tensor(double)" + ] + } + ], + "examples": [ + { + "summary": "mean", + "code": "data_0 = np.array([3, 0, 2]).astype(np.float32)\ndata_1 = np.array([1, 3, 4]).astype(np.float32)\ndata_2 = np.array([2, 6, 6]).astype(np.float32)\nresult = np.array([2, 3, 4]).astype(np.float32)\nnode = onnx.helper.make_node(\n 'Mean',\n inputs=['data_0', 'data_1', 'data_2'],\n outputs=['result'],\n)\nexpect(node, inputs=[data_0, data_1, data_2], outputs=[result],\n name='test_mean_example')\n\nnode = onnx.helper.make_node(\n 'Mean',\n inputs=['data_0'],\n outputs=['result'],\n)\nexpect(node, inputs=[data_0], outputs=[data_0],\n name='test_mean_one_input')\n\nresult = np.divide(np.add(data_0, data_1), 2.)\nnode = onnx.helper.make_node(\n 'Mean',\n inputs=['data_0', 'data_1'],\n outputs=['result'],\n)\nexpect(node, inputs=[data_0, data_1], outputs=[result],\n name='test_mean_two_inputs')" + } + ] + }, + { + "name": "Mean", + "module": "ai.onnx", + "version": 13, + "support_level": "common", + "description": "Element-wise mean of each of the input tensors (with Numpy-style broadcasting support).\nAll inputs and outputs must have the same data type.\nThis operator supports **multidirectional (i.e., Numpy-style) broadcasting**; for more details please check [the doc](https://github.com/onnx/onnx/blob/master/docs/Broadcasting.md).\n", + "inputs": [ + { + "name": "data_0", + "type": "T", + "list": true, + "description": "List of tensors for mean." + } + ], + "min_input": 1, + "max_input": 2147483647, + "outputs": [ + { + "name": "mean", + "type": "T", + "description": "Output tensor." + } + ], + "min_output": 1, + "max_output": 1, + "inputs_range": "1 - ∞", + "type_constraints": [ + { + "description": "Constrain input and output types to float tensors.", + "type_param_str": "T", + "allowed_type_strs": [ + "tensor(float16)", + "tensor(float)", + "tensor(double)", + "tensor(bfloat16)" + ] + } + ], + "examples": [ + { + "summary": "mean", + "code": "data_0 = np.array([3, 0, 2]).astype(np.float32)\ndata_1 = np.array([1, 3, 4]).astype(np.float32)\ndata_2 = np.array([2, 6, 6]).astype(np.float32)\nresult = np.array([2, 3, 4]).astype(np.float32)\nnode = onnx.helper.make_node(\n 'Mean',\n inputs=['data_0', 'data_1', 'data_2'],\n outputs=['result'],\n)\nexpect(node, inputs=[data_0, data_1, data_2], outputs=[result],\n name='test_mean_example')\n\nnode = onnx.helper.make_node(\n 'Mean',\n inputs=['data_0'],\n outputs=['result'],\n)\nexpect(node, inputs=[data_0], outputs=[data_0],\n name='test_mean_one_input')\n\nresult = np.divide(np.add(data_0, data_1), 2.)\nnode = onnx.helper.make_node(\n 'Mean',\n inputs=['data_0', 'data_1'],\n outputs=['result'],\n)\nexpect(node, inputs=[data_0, data_1], outputs=[result],\n name='test_mean_two_inputs')" + } + ] + }, + { + "name": "MeanVarianceNormalization", + "module": "ai.onnx", + "version": 9, + "support_level": "common", + "description": "A MeanVarianceNormalization Function: Perform mean variance normalization\n on the input tensor X using formula:
``` (X-EX)/sqrt(E(X-EX)^2) ```\n", + "attributes": [ + { + "name": "axes", + "type": "int64[]", + "required": false, + "description": "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": [ + { + "name": "X", + "type": "T", + "description": "Input tensor" + } + ], + "min_input": 1, + "max_input": 1, + "outputs": [ + { + "name": "Y", + "type": "T", + "description": "Output tensor" + } + ], + "min_output": 1, + "max_output": 1, + "type_constraints": [ + { + "description": "Constrain input and output types to all numeric tensors.", + "type_param_str": "T", + "allowed_type_strs": [ + "tensor(float16)", + "tensor(float)", + "tensor(double)" + ] + } + ], + "examples": [ + { + "summary": "meanvariancenormalization", + "code": "node = onnx.helper.make_node(\n 'MeanVarianceNormalization',\n inputs=['X'],\n outputs=['Y']\n)\n\ninput_data = np.array([[[[0.8439683], [0.5665144], [0.05836735]],\n [[0.02916367], [0.12964272], [0.5060197]],\n [[0.79538304], [0.9411346], [0.9546573]]],\n [[[0.17730942], [0.46192095], [0.26480448]],\n [[0.6746842], [0.01665257], [0.62473077]],\n [[0.9240844], [0.9722341], [0.11965699]]],\n [[[0.41356155], [0.9129373], [0.59330076]],\n [[0.81929934], [0.7862604], [0.11799799]],\n [[0.69248444], [0.54119414], [0.07513223]]]], dtype=np.float32)\n\n# Calculate expected output data\ndata_mean = np.mean(input_data, axis=(0, 2, 3), keepdims=1)\ndata_mean_squared = np.power(data_mean, 2)\ndata_squared = np.power(input_data, 2)\ndata_squared_mean = np.mean(data_squared, axis=(0, 2, 3), keepdims=1)\nstd = np.sqrt(data_squared_mean - data_mean_squared)\nexpected_output = (input_data - data_mean) / (std + 1e-9)\n\nexpect(node, inputs=[input_data], outputs=[expected_output],\n name='test_mvn')" + } + ] + }, + { + "name": "MeanVarianceNormalization", + "module": "ai.onnx", + "version": 13, + "support_level": "common", + "description": "A MeanVarianceNormalization Function: Perform mean variance normalization\n on the input tensor X using formula:
``` (X-EX)/sqrt(E(X-EX)^2) ```\n", + "attributes": [ + { + "name": "axes", + "type": "int64[]", + "required": false, + "description": "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": [ + { + "name": "X", + "type": "T", + "description": "Input tensor" + } + ], + "min_input": 1, + "max_input": 1, + "outputs": [ + { + "name": "Y", + "type": "T", + "description": "Output tensor" + } + ], + "min_output": 1, + "max_output": 1, + "type_constraints": [ + { + "description": "Constrain input and output types to all numeric tensors.", + "type_param_str": "T", + "allowed_type_strs": [ + "tensor(float16)", + "tensor(float)", + "tensor(double)", + "tensor(bfloat16)" + ] + } + ], + "examples": [ + { + "summary": "meanvariancenormalization", + "code": "node = onnx.helper.make_node(\n 'MeanVarianceNormalization',\n inputs=['X'],\n outputs=['Y']\n)\n\ninput_data = np.array([[[[0.8439683], [0.5665144], [0.05836735]],\n [[0.02916367], [0.12964272], [0.5060197]],\n [[0.79538304], [0.9411346], [0.9546573]]],\n [[[0.17730942], [0.46192095], [0.26480448]],\n [[0.6746842], [0.01665257], [0.62473077]],\n [[0.9240844], [0.9722341], [0.11965699]]],\n [[[0.41356155], [0.9129373], [0.59330076]],\n [[0.81929934], [0.7862604], [0.11799799]],\n [[0.69248444], [0.54119414], [0.07513223]]]], dtype=np.float32)\n\n# Calculate expected output data\ndata_mean = np.mean(input_data, axis=(0, 2, 3), keepdims=1)\ndata_mean_squared = np.power(data_mean, 2)\ndata_squared = np.power(input_data, 2)\ndata_squared_mean = np.mean(data_squared, axis=(0, 2, 3), keepdims=1)\nstd = np.sqrt(data_squared_mean - data_mean_squared)\nexpected_output = (input_data - data_mean) / (std + 1e-9)\n\nexpect(node, inputs=[input_data], outputs=[expected_output],\n name='test_mvn')" + } + ] + }, + { + "name": "Min", + "module": "ai.onnx", + "version": 1, + "support_level": "common", + "description": "Element-wise min of each of the input tensors. All inputs and outputs must\nhave the same shape and data type.\n", + "attributes": [ + { + "name": "consumed_inputs", + "type": "int64[]", + "required": false, + "description": "legacy optimization attribute." + } + ], + "inputs": [ + { + "name": "data_0", + "type": "T", + "list": true, + "description": "List of tensors for Min" + } + ], + "min_input": 1, + "max_input": 2147483647, + "outputs": [ + { + "name": "min", + "type": "T", + "description": "Output tensor. Same dimension as inputs." + } + ], + "min_output": 1, + "max_output": 1, + "inputs_range": "1 - ∞", + "type_constraints": [ + { + "description": "Constrain input and output types to float tensors.", + "type_param_str": "T", + "allowed_type_strs": [ + "tensor(float16)", + "tensor(float)", + "tensor(double)" + ] + } + ], + "examples": [ + { + "summary": "min", + "code": "data_0 = np.array([3, 2, 1]).astype(np.float32)\ndata_1 = np.array([1, 4, 4]).astype(np.float32)\ndata_2 = np.array([2, 5, 0]).astype(np.float32)\nresult = np.array([1, 2, 0]).astype(np.float32)\nnode = onnx.helper.make_node(\n 'Min',\n inputs=['data_0', 'data_1', 'data_2'],\n outputs=['result'],\n)\nexpect(node, inputs=[data_0, data_1, data_2], outputs=[result],\n name='test_min_example')\n\nnode = onnx.helper.make_node(\n 'Min',\n inputs=['data_0'],\n outputs=['result'],\n)\nexpect(node, inputs=[data_0], outputs=[data_0],\n name='test_min_one_input')\n\nresult = np.minimum(data_0, data_1)\nnode = onnx.helper.make_node(\n 'Min',\n inputs=['data_0', 'data_1'],\n outputs=['result'],\n)\nexpect(node, inputs=[data_0, data_1], outputs=[result],\n name='test_min_two_inputs')" + }, + { + "summary": "min_all_numeric_types", + "code": "for op_dtype in all_numeric_dtypes:\n data_0 = np.array([3, 2, 1]).astype(op_dtype)\n data_1 = np.array([1, 4, 4]).astype(op_dtype)\n result = np.array([1, 2, 1]).astype(op_dtype)\n node = onnx.helper.make_node(\n 'Min',\n inputs=['data_0', 'data_1'],\n outputs=['result'],\n )\n expect(node, inputs=[data_0, data_1], outputs=[result],\n name='test_min_{0}'.format(np.dtype(op_dtype).name))" + } + ] + }, + { + "name": "Min", + "module": "ai.onnx", + "version": 6, + "support_level": "common", + "description": "Element-wise min of each of the input tensors. All inputs and outputs must\nhave the same shape and data type.\n", + "inputs": [ + { + "name": "data_0", + "type": "T", + "list": true, + "description": "List of tensors for Min" + } + ], + "min_input": 1, + "max_input": 2147483647, + "outputs": [ + { + "name": "min", + "type": "T", + "description": "Output tensor. Same dimension as inputs." + } + ], + "min_output": 1, + "max_output": 1, + "inputs_range": "1 - ∞", + "type_constraints": [ + { + "description": "Constrain input and output types to float tensors.", + "type_param_str": "T", + "allowed_type_strs": [ + "tensor(float16)", + "tensor(float)", + "tensor(double)" + ] + } + ], + "examples": [ + { + "summary": "min", + "code": "data_0 = np.array([3, 2, 1]).astype(np.float32)\ndata_1 = np.array([1, 4, 4]).astype(np.float32)\ndata_2 = np.array([2, 5, 0]).astype(np.float32)\nresult = np.array([1, 2, 0]).astype(np.float32)\nnode = onnx.helper.make_node(\n 'Min',\n inputs=['data_0', 'data_1', 'data_2'],\n outputs=['result'],\n)\nexpect(node, inputs=[data_0, data_1, data_2], outputs=[result],\n name='test_min_example')\n\nnode = onnx.helper.make_node(\n 'Min',\n inputs=['data_0'],\n outputs=['result'],\n)\nexpect(node, inputs=[data_0], outputs=[data_0],\n name='test_min_one_input')\n\nresult = np.minimum(data_0, data_1)\nnode = onnx.helper.make_node(\n 'Min',\n inputs=['data_0', 'data_1'],\n outputs=['result'],\n)\nexpect(node, inputs=[data_0, data_1], outputs=[result],\n name='test_min_two_inputs')" + }, + { + "summary": "min_all_numeric_types", + "code": "for op_dtype in all_numeric_dtypes:\n data_0 = np.array([3, 2, 1]).astype(op_dtype)\n data_1 = np.array([1, 4, 4]).astype(op_dtype)\n result = np.array([1, 2, 1]).astype(op_dtype)\n node = onnx.helper.make_node(\n 'Min',\n inputs=['data_0', 'data_1'],\n outputs=['result'],\n )\n expect(node, inputs=[data_0, data_1], outputs=[result],\n name='test_min_{0}'.format(np.dtype(op_dtype).name))" + } + ] + }, + { + "name": "Min", + "module": "ai.onnx", + "version": 8, + "support_level": "common", + "description": "Element-wise min of each of the input tensors (with Numpy-style broadcasting support).\nAll inputs and outputs must have the same data type.\nThis operator supports **multidirectional (i.e., Numpy-style) broadcasting**; for more details please check [the doc](https://github.com/onnx/onnx/blob/master/docs/Broadcasting.md).\n", + "inputs": [ + { + "name": "data_0", + "type": "T", + "list": true, + "description": "List of tensors for min." + } + ], + "min_input": 1, + "max_input": 2147483647, + "outputs": [ + { + "name": "min", + "type": "T", + "description": "Output tensor." + } + ], + "min_output": 1, + "max_output": 1, + "inputs_range": "1 - ∞", + "type_constraints": [ + { + "description": "Constrain input and output types to float tensors.", + "type_param_str": "T", + "allowed_type_strs": [ + "tensor(float16)", + "tensor(float)", + "tensor(double)" + ] + } + ], + "examples": [ + { + "summary": "min", + "code": "data_0 = np.array([3, 2, 1]).astype(np.float32)\ndata_1 = np.array([1, 4, 4]).astype(np.float32)\ndata_2 = np.array([2, 5, 0]).astype(np.float32)\nresult = np.array([1, 2, 0]).astype(np.float32)\nnode = onnx.helper.make_node(\n 'Min',\n inputs=['data_0', 'data_1', 'data_2'],\n outputs=['result'],\n)\nexpect(node, inputs=[data_0, data_1, data_2], outputs=[result],\n name='test_min_example')\n\nnode = onnx.helper.make_node(\n 'Min',\n inputs=['data_0'],\n outputs=['result'],\n)\nexpect(node, inputs=[data_0], outputs=[data_0],\n name='test_min_one_input')\n\nresult = np.minimum(data_0, data_1)\nnode = onnx.helper.make_node(\n 'Min',\n inputs=['data_0', 'data_1'],\n outputs=['result'],\n)\nexpect(node, inputs=[data_0, data_1], outputs=[result],\n name='test_min_two_inputs')" + }, + { + "summary": "min_all_numeric_types", + "code": "for op_dtype in all_numeric_dtypes:\n data_0 = np.array([3, 2, 1]).astype(op_dtype)\n data_1 = np.array([1, 4, 4]).astype(op_dtype)\n result = np.array([1, 2, 1]).astype(op_dtype)\n node = onnx.helper.make_node(\n 'Min',\n inputs=['data_0', 'data_1'],\n outputs=['result'],\n )\n expect(node, inputs=[data_0, data_1], outputs=[result],\n name='test_min_{0}'.format(np.dtype(op_dtype).name))" + } + ] + }, + { + "name": "Min", + "module": "ai.onnx", + "version": 12, + "support_level": "common", + "description": "Element-wise min of each of the input tensors (with Numpy-style broadcasting support).\nAll inputs and outputs must have the same data type.\nThis operator supports **multidirectional (i.e., Numpy-style) broadcasting**; for more details please check [the doc](https://github.com/onnx/onnx/blob/master/docs/Broadcasting.md).\n", + "inputs": [ + { + "name": "data_0", + "type": "T", + "list": true, + "description": "List of tensors for min." + } + ], + "min_input": 1, + "max_input": 2147483647, + "outputs": [ + { + "name": "min", + "type": "T", + "description": "Output tensor." + } + ], + "min_output": 1, + "max_output": 1, + "inputs_range": "1 - ∞", + "type_constraints": [ + { + "description": "Constrain input and output types to numeric tensors.", + "type_param_str": "T", + "allowed_type_strs": [ + "tensor(uint8)", + "tensor(uint16)", + "tensor(uint32)", + "tensor(uint64)", + "tensor(int8)", + "tensor(int16)", + "tensor(int32)", + "tensor(int64)", + "tensor(float16)", + "tensor(float)", + "tensor(double)" + ] + } + ], + "examples": [ + { + "summary": "min", + "code": "data_0 = np.array([3, 2, 1]).astype(np.float32)\ndata_1 = np.array([1, 4, 4]).astype(np.float32)\ndata_2 = np.array([2, 5, 0]).astype(np.float32)\nresult = np.array([1, 2, 0]).astype(np.float32)\nnode = onnx.helper.make_node(\n 'Min',\n inputs=['data_0', 'data_1', 'data_2'],\n outputs=['result'],\n)\nexpect(node, inputs=[data_0, data_1, data_2], outputs=[result],\n name='test_min_example')\n\nnode = onnx.helper.make_node(\n 'Min',\n inputs=['data_0'],\n outputs=['result'],\n)\nexpect(node, inputs=[data_0], outputs=[data_0],\n name='test_min_one_input')\n\nresult = np.minimum(data_0, data_1)\nnode = onnx.helper.make_node(\n 'Min',\n inputs=['data_0', 'data_1'],\n outputs=['result'],\n)\nexpect(node, inputs=[data_0, data_1], outputs=[result],\n name='test_min_two_inputs')" + }, + { + "summary": "min_all_numeric_types", + "code": "for op_dtype in all_numeric_dtypes:\n data_0 = np.array([3, 2, 1]).astype(op_dtype)\n data_1 = np.array([1, 4, 4]).astype(op_dtype)\n result = np.array([1, 2, 1]).astype(op_dtype)\n node = onnx.helper.make_node(\n 'Min',\n inputs=['data_0', 'data_1'],\n outputs=['result'],\n )\n expect(node, inputs=[data_0, data_1], outputs=[result],\n name='test_min_{0}'.format(np.dtype(op_dtype).name))" + } + ] + }, + { + "name": "Min", + "module": "ai.onnx", + "version": 13, + "support_level": "common", + "description": "Element-wise min of each of the input tensors (with Numpy-style broadcasting support).\nAll inputs and outputs must have the same data type.\nThis operator supports **multidirectional (i.e., Numpy-style) broadcasting**; for more details please check [the doc](https://github.com/onnx/onnx/blob/master/docs/Broadcasting.md).\n", + "inputs": [ + { + "name": "data_0", + "type": "T", + "list": true, + "description": "List of tensors for min." + } + ], + "min_input": 1, + "max_input": 2147483647, + "outputs": [ + { + "name": "min", + "type": "T", + "description": "Output tensor." + } + ], + "min_output": 1, + "max_output": 1, + "inputs_range": "1 - ∞", + "type_constraints": [ + { + "description": "Constrain input and output types to numeric tensors.", + "type_param_str": "T", + "allowed_type_strs": [ + "tensor(uint8)", + "tensor(uint16)", + "tensor(uint32)", + "tensor(uint64)", + "tensor(int8)", + "tensor(int16)", + "tensor(int32)", + "tensor(int64)", + "tensor(float16)", + "tensor(float)", + "tensor(double)", + "tensor(bfloat16)" + ] + } + ], + "examples": [ + { + "summary": "min", + "code": "data_0 = np.array([3, 2, 1]).astype(np.float32)\ndata_1 = np.array([1, 4, 4]).astype(np.float32)\ndata_2 = np.array([2, 5, 0]).astype(np.float32)\nresult = np.array([1, 2, 0]).astype(np.float32)\nnode = onnx.helper.make_node(\n 'Min',\n inputs=['data_0', 'data_1', 'data_2'],\n outputs=['result'],\n)\nexpect(node, inputs=[data_0, data_1, data_2], outputs=[result],\n name='test_min_example')\n\nnode = onnx.helper.make_node(\n 'Min',\n inputs=['data_0'],\n outputs=['result'],\n)\nexpect(node, inputs=[data_0], outputs=[data_0],\n name='test_min_one_input')\n\nresult = np.minimum(data_0, data_1)\nnode = onnx.helper.make_node(\n 'Min',\n inputs=['data_0', 'data_1'],\n outputs=['result'],\n)\nexpect(node, inputs=[data_0, data_1], outputs=[result],\n name='test_min_two_inputs')" + }, + { + "summary": "min_all_numeric_types", + "code": "for op_dtype in all_numeric_dtypes:\n data_0 = np.array([3, 2, 1]).astype(op_dtype)\n data_1 = np.array([1, 4, 4]).astype(op_dtype)\n result = np.array([1, 2, 1]).astype(op_dtype)\n node = onnx.helper.make_node(\n 'Min',\n inputs=['data_0', 'data_1'],\n outputs=['result'],\n )\n expect(node, inputs=[data_0, data_1], outputs=[result],\n name='test_min_{0}'.format(np.dtype(op_dtype).name))" + } + ] + }, + { + "name": "Mod", + "module": "ai.onnx", + "version": 10, + "support_level": "common", + "description": "Performs element-wise binary modulus (with Numpy-style broadcasting support).\n The sign of the remainder is the same as that of the Divisor.\n\n 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\n (in contrast to integer mod). To force a behavior like numpy.fmod() an 'fmod' Attribute is provided.\n This attribute is set to 0 by default causing the behavior to be like integer mod.\n Setting this attribute to 1 causes the remainder to be calculated similar to that of numpy.fmod().\n\n If the input type is floating point, then `fmod` attribute must be set to 1.\n\n In case of dividend being zero, the results will be platform dependent.\n\n This operator supports **multidirectional (i.e., Numpy-style) broadcasting**; for more details please check [the doc](https://github.com/onnx/onnx/blob/master/docs/Broadcasting.md).\n", + "attributes": [ + { + "name": "fmod", + "type": "int64", + "required": false, + "description": "Whether the operator should behave like fmod (default=0 meaning it will do integer mods); Set this to 1 to force fmod treatment" + } + ], + "inputs": [ + { + "name": "A", + "type": "T", + "description": "Dividend tensor" + }, + { + "name": "B", + "type": "T", + "description": "Divisor tensor" + } + ], + "min_input": 2, + "max_input": 2, + "outputs": [ + { + "name": "C", + "type": "T", + "description": "Remainder tensor" + } + ], + "min_output": 1, + "max_output": 1, + "type_constraints": [ + { + "description": "Constrain input and output types to high-precision numeric tensors.", + "type_param_str": "T", + "allowed_type_strs": [ + "tensor(uint8)", + "tensor(uint16)", + "tensor(uint32)", + "tensor(uint64)", + "tensor(int8)", + "tensor(int16)", + "tensor(int32)", + "tensor(int64)", + "tensor(float16)", + "tensor(float)", + "tensor(double)" + ] + } + ], + "examples": [ + { + "summary": "mod_broadcast", + "code": "node = onnx.helper.make_node(\n 'Mod',\n inputs=['x', 'y'],\n outputs=['z'],\n)\n\nx = np.arange(0, 30).reshape([3, 2, 5]).astype(np.int32)\ny = np.array([7]).astype(np.int32)\nz = np.mod(x, y)\n# array([[[0, 1, 2, 3, 4],\n# [5, 6, 0, 1, 2]],\n\n# [[3, 4, 5, 6, 0],\n# [1, 2, 3, 4, 5]],\n\n# [[6, 0, 1, 2, 3],\n# [4, 5, 6, 0, 1]]], dtype=int32)\nexpect(node, inputs=[x, y], outputs=[z],\n name='test_mod_broadcast')" + }, + { + "summary": "mod_int64_fmod", + "code": "node = onnx.helper.make_node(\n 'Mod',\n inputs=['x', 'y'],\n outputs=['z'],\n fmod=1\n)\n\nx = np.array([-4, 7, 5, 4, -7, 8]).astype(np.int64)\ny = np.array([2, -3, 8, -2, 3, 5]).astype(np.int64)\nz = np.fmod(x, y) # expected output [ 0, 1, 5, 0, -1, 3]\nexpect(node, inputs=[x, y], outputs=[z],\n name='test_mod_int64_fmod')" + }, + { + "summary": "mod_mixed_sign_float16", + "code": "node = onnx.helper.make_node(\n 'Mod',\n inputs=['x', 'y'],\n outputs=['z'],\n fmod=1\n)\n\nx = np.array([-4.3, 7.2, 5.0, 4.3, -7.2, 8.0]).astype(np.float16)\ny = np.array([2.1, -3.4, 8.0, -2.1, 3.4, 5.0]).astype(np.float16)\nz = np.fmod(x, y) # expected output [-0.10156, 0.3984 , 5. , 0.10156, -0.3984 , 3.]\nexpect(node, inputs=[x, y], outputs=[z],\n name='test_mod_mixed_sign_float16')" + }, + { + "summary": "mod_mixed_sign_float32", + "code": "node = onnx.helper.make_node(\n 'Mod',\n inputs=['x', 'y'],\n outputs=['z'],\n fmod=1\n)\n\nx = np.array([-4.3, 7.2, 5.0, 4.3, -7.2, 8.0]).astype(np.float32)\ny = np.array([2.1, -3.4, 8.0, -2.1, 3.4, 5.0]).astype(np.float32)\nz = np.fmod(x, y) # expected output [-0.10000038, 0.39999962, 5. , 0.10000038, -0.39999962, 3.]\nexpect(node, inputs=[x, y], outputs=[z],\n name='test_mod_mixed_sign_float32')" + }, + { + "summary": "mod_mixed_sign_float64", + "code": "node = onnx.helper.make_node(\n 'Mod',\n inputs=['x', 'y'],\n outputs=['z'],\n fmod=1\n)\n\nx = np.array([-4.3, 7.2, 5.0, 4.3, -7.2, 8.0]).astype(np.float64)\ny = np.array([2.1, -3.4, 8.0, -2.1, 3.4, 5.0]).astype(np.float64)\nz = np.fmod(x, y) # expected output [-0.1, 0.4, 5. , 0.1, -0.4, 3.]\nexpect(node, inputs=[x, y], outputs=[z],\n name='test_mod_mixed_sign_float64')" + }, + { + "summary": "mod_mixed_sign_int16", + "code": "node = onnx.helper.make_node(\n 'Mod',\n inputs=['x', 'y'],\n outputs=['z'],\n)\n\nx = np.array([-4, 7, 5, 4, -7, 8]).astype(np.int16)\ny = np.array([2, -3, 8, -2, 3, 5]).astype(np.int16)\nz = np.mod(x, y) # expected output [ 0, -2, 5, 0, 2, 3]\nexpect(node, inputs=[x, y], outputs=[z],\n name='test_mod_mixed_sign_int16')" + }, + { + "summary": "mod_mixed_sign_int32", + "code": "node = onnx.helper.make_node(\n 'Mod',\n inputs=['x', 'y'],\n outputs=['z'],\n)\n\nx = np.array([-4, 7, 5, 4, -7, 8]).astype(np.int32)\ny = np.array([2, -3, 8, -2, 3, 5]).astype(np.int32)\nz = np.mod(x, y) # expected output [ 0, -2, 5, 0, 2, 3]\nexpect(node, inputs=[x, y], outputs=[z],\n name='test_mod_mixed_sign_int32')" + }, + { + "summary": "mod_mixed_sign_int64", + "code": "node = onnx.helper.make_node(\n 'Mod',\n inputs=['x', 'y'],\n outputs=['z'],\n)\n\nx = np.array([-4, 7, 5, 4, -7, 8]).astype(np.int64)\ny = np.array([2, -3, 8, -2, 3, 5]).astype(np.int64)\nz = np.mod(x, y) # expected output [ 0, -2, 5, 0, 2, 3]\nexpect(node, inputs=[x, y], outputs=[z],\n name='test_mod_mixed_sign_int64')" + }, + { + "summary": "mod_mixed_sign_int8", + "code": "node = onnx.helper.make_node(\n 'Mod',\n inputs=['x', 'y'],\n outputs=['z'],\n)\n\nx = np.array([-4, 7, 5, 4, -7, 8]).astype(np.int8)\ny = np.array([2, -3, 8, -2, 3, 5]).astype(np.int8)\nz = np.mod(x, y) # expected output [ 0, -2, 5, 0, 2, 3]\nexpect(node, inputs=[x, y], outputs=[z],\n name='test_mod_mixed_sign_int8')" + }, + { + "summary": "mod_uint16", + "code": "node = onnx.helper.make_node(\n 'Mod',\n inputs=['x', 'y'],\n outputs=['z'],\n)\n\nx = np.array([4, 7, 5]).astype(np.uint16)\ny = np.array([2, 3, 8]).astype(np.uint16)\nz = np.mod(x, y) # expected output [0, 1, 5]\nexpect(node, inputs=[x, y], outputs=[z],\n name='test_mod_uint16')" + }, + { + "summary": "mod_uint32", + "code": "node = onnx.helper.make_node(\n 'Mod',\n inputs=['x', 'y'],\n outputs=['z'],\n)\n\nx = np.array([4, 7, 5]).astype(np.uint32)\ny = np.array([2, 3, 8]).astype(np.uint32)\nz = np.mod(x, y) # expected output [0, 1, 5]\nexpect(node, inputs=[x, y], outputs=[z],\n name='test_mod_uint32')" + }, + { + "summary": "mod_uint64", + "code": "node = onnx.helper.make_node(\n 'Mod',\n inputs=['x', 'y'],\n outputs=['z'],\n)\n\nx = np.array([4, 7, 5]).astype(np.uint64)\ny = np.array([2, 3, 8]).astype(np.uint64)\nz = np.mod(x, y) # expected output [0, 1, 5]\nexpect(node, inputs=[x, y], outputs=[z],\n name='test_mod_uint64')" + }, + { + "summary": "mod_uint8", + "code": "node = onnx.helper.make_node(\n 'Mod',\n inputs=['x', 'y'],\n outputs=['z'],\n)\n\nx = np.array([4, 7, 5]).astype(np.uint8)\ny = np.array([2, 3, 8]).astype(np.uint8)\nz = np.mod(x, y) # expected output [0, 1, 5]\nexpect(node, inputs=[x, y], outputs=[z],\n name='test_mod_uint8')" + } + ] + }, + { + "name": "Mod", + "module": "ai.onnx", + "version": 13, + "support_level": "common", + "description": "Performs element-wise binary modulus (with Numpy-style broadcasting support).\n The sign of the remainder is the same as that of the Divisor.\n\n 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\n (in contrast to integer mod). To force a behavior like numpy.fmod() an 'fmod' Attribute is provided.\n This attribute is set to 0 by default causing the behavior to be like integer mod.\n Setting this attribute to 1 causes the remainder to be calculated similar to that of numpy.fmod().\n\n If the input type is floating point, then `fmod` attribute must be set to 1.\n\n In case of dividend being zero, the results will be platform dependent.\n\n This operator supports **multidirectional (i.e., Numpy-style) broadcasting**; for more details please check [the doc](https://github.com/onnx/onnx/blob/master/docs/Broadcasting.md).\n", + "attributes": [ + { + "name": "fmod", + "type": "int64", + "required": false, + "description": "Whether the operator should behave like fmod (default=0 meaning it will do integer mods); Set this to 1 to force fmod treatment" + } + ], + "inputs": [ + { + "name": "A", + "type": "T", + "description": "Dividend tensor" + }, + { + "name": "B", + "type": "T", + "description": "Divisor tensor" + } + ], + "min_input": 2, + "max_input": 2, + "outputs": [ + { + "name": "C", + "type": "T", + "description": "Remainder tensor" + } + ], + "min_output": 1, + "max_output": 1, + "type_constraints": [ + { + "description": "Constrain input and output types to high-precision numeric tensors.", + "type_param_str": "T", + "allowed_type_strs": [ + "tensor(uint8)", + "tensor(uint16)", + "tensor(uint32)", + "tensor(uint64)", + "tensor(int8)", + "tensor(int16)", + "tensor(int32)", + "tensor(int64)", + "tensor(float16)", + "tensor(float)", + "tensor(double)", + "tensor(bfloat16)" + ] + } + ], + "examples": [ + { + "summary": "mod_broadcast", + "code": "node = onnx.helper.make_node(\n 'Mod',\n inputs=['x', 'y'],\n outputs=['z'],\n)\n\nx = np.arange(0, 30).reshape([3, 2, 5]).astype(np.int32)\ny = np.array([7]).astype(np.int32)\nz = np.mod(x, y)\n# array([[[0, 1, 2, 3, 4],\n# [5, 6, 0, 1, 2]],\n\n# [[3, 4, 5, 6, 0],\n# [1, 2, 3, 4, 5]],\n\n# [[6, 0, 1, 2, 3],\n# [4, 5, 6, 0, 1]]], dtype=int32)\nexpect(node, inputs=[x, y], outputs=[z],\n name='test_mod_broadcast')" + }, + { + "summary": "mod_int64_fmod", + "code": "node = onnx.helper.make_node(\n 'Mod',\n inputs=['x', 'y'],\n outputs=['z'],\n fmod=1\n)\n\nx = np.array([-4, 7, 5, 4, -7, 8]).astype(np.int64)\ny = np.array([2, -3, 8, -2, 3, 5]).astype(np.int64)\nz = np.fmod(x, y) # expected output [ 0, 1, 5, 0, -1, 3]\nexpect(node, inputs=[x, y], outputs=[z],\n name='test_mod_int64_fmod')" + }, + { + "summary": "mod_mixed_sign_float16", + "code": "node = onnx.helper.make_node(\n 'Mod',\n inputs=['x', 'y'],\n outputs=['z'],\n fmod=1\n)\n\nx = np.array([-4.3, 7.2, 5.0, 4.3, -7.2, 8.0]).astype(np.float16)\ny = np.array([2.1, -3.4, 8.0, -2.1, 3.4, 5.0]).astype(np.float16)\nz = np.fmod(x, y) # expected output [-0.10156, 0.3984 , 5. , 0.10156, -0.3984 , 3.]\nexpect(node, inputs=[x, y], outputs=[z],\n name='test_mod_mixed_sign_float16')" + }, + { + "summary": "mod_mixed_sign_float32", + "code": "node = onnx.helper.make_node(\n 'Mod',\n inputs=['x', 'y'],\n outputs=['z'],\n fmod=1\n)\n\nx = np.array([-4.3, 7.2, 5.0, 4.3, -7.2, 8.0]).astype(np.float32)\ny = np.array([2.1, -3.4, 8.0, -2.1, 3.4, 5.0]).astype(np.float32)\nz = np.fmod(x, y) # expected output [-0.10000038, 0.39999962, 5. , 0.10000038, -0.39999962, 3.]\nexpect(node, inputs=[x, y], outputs=[z],\n name='test_mod_mixed_sign_float32')" + }, + { + "summary": "mod_mixed_sign_float64", + "code": "node = onnx.helper.make_node(\n 'Mod',\n inputs=['x', 'y'],\n outputs=['z'],\n fmod=1\n)\n\nx = np.array([-4.3, 7.2, 5.0, 4.3, -7.2, 8.0]).astype(np.float64)\ny = np.array([2.1, -3.4, 8.0, -2.1, 3.4, 5.0]).astype(np.float64)\nz = np.fmod(x, y) # expected output [-0.1, 0.4, 5. , 0.1, -0.4, 3.]\nexpect(node, inputs=[x, y], outputs=[z],\n name='test_mod_mixed_sign_float64')" + }, + { + "summary": "mod_mixed_sign_int16", + "code": "node = onnx.helper.make_node(\n 'Mod',\n inputs=['x', 'y'],\n outputs=['z'],\n)\n\nx = np.array([-4, 7, 5, 4, -7, 8]).astype(np.int16)\ny = np.array([2, -3, 8, -2, 3, 5]).astype(np.int16)\nz = np.mod(x, y) # expected output [ 0, -2, 5, 0, 2, 3]\nexpect(node, inputs=[x, y], outputs=[z],\n name='test_mod_mixed_sign_int16')" + }, + { + "summary": "mod_mixed_sign_int32", + "code": "node = onnx.helper.make_node(\n 'Mod',\n inputs=['x', 'y'],\n outputs=['z'],\n)\n\nx = np.array([-4, 7, 5, 4, -7, 8]).astype(np.int32)\ny = np.array([2, -3, 8, -2, 3, 5]).astype(np.int32)\nz = np.mod(x, y) # expected output [ 0, -2, 5, 0, 2, 3]\nexpect(node, inputs=[x, y], outputs=[z],\n name='test_mod_mixed_sign_int32')" + }, + { + "summary": "mod_mixed_sign_int64", + "code": "node = onnx.helper.make_node(\n 'Mod',\n inputs=['x', 'y'],\n outputs=['z'],\n)\n\nx = np.array([-4, 7, 5, 4, -7, 8]).astype(np.int64)\ny = np.array([2, -3, 8, -2, 3, 5]).astype(np.int64)\nz = np.mod(x, y) # expected output [ 0, -2, 5, 0, 2, 3]\nexpect(node, inputs=[x, y], outputs=[z],\n name='test_mod_mixed_sign_int64')" + }, + { + "summary": "mod_mixed_sign_int8", + "code": "node = onnx.helper.make_node(\n 'Mod',\n inputs=['x', 'y'],\n outputs=['z'],\n)\n\nx = np.array([-4, 7, 5, 4, -7, 8]).astype(np.int8)\ny = np.array([2, -3, 8, -2, 3, 5]).astype(np.int8)\nz = np.mod(x, y) # expected output [ 0, -2, 5, 0, 2, 3]\nexpect(node, inputs=[x, y], outputs=[z],\n name='test_mod_mixed_sign_int8')" + }, + { + "summary": "mod_uint16", + "code": "node = onnx.helper.make_node(\n 'Mod',\n inputs=['x', 'y'],\n outputs=['z'],\n)\n\nx = np.array([4, 7, 5]).astype(np.uint16)\ny = np.array([2, 3, 8]).astype(np.uint16)\nz = np.mod(x, y) # expected output [0, 1, 5]\nexpect(node, inputs=[x, y], outputs=[z],\n name='test_mod_uint16')" + }, + { + "summary": "mod_uint32", + "code": "node = onnx.helper.make_node(\n 'Mod',\n inputs=['x', 'y'],\n outputs=['z'],\n)\n\nx = np.array([4, 7, 5]).astype(np.uint32)\ny = np.array([2, 3, 8]).astype(np.uint32)\nz = np.mod(x, y) # expected output [0, 1, 5]\nexpect(node, inputs=[x, y], outputs=[z],\n name='test_mod_uint32')" + }, + { + "summary": "mod_uint64", + "code": "node = onnx.helper.make_node(\n 'Mod',\n inputs=['x', 'y'],\n outputs=['z'],\n)\n\nx = np.array([4, 7, 5]).astype(np.uint64)\ny = np.array([2, 3, 8]).astype(np.uint64)\nz = np.mod(x, y) # expected output [0, 1, 5]\nexpect(node, inputs=[x, y], outputs=[z],\n name='test_mod_uint64')" + }, + { + "summary": "mod_uint8", + "code": "node = onnx.helper.make_node(\n 'Mod',\n inputs=['x', 'y'],\n outputs=['z'],\n)\n\nx = np.array([4, 7, 5]).astype(np.uint8)\ny = np.array([2, 3, 8]).astype(np.uint8)\nz = np.mod(x, y) # expected output [0, 1, 5]\nexpect(node, inputs=[x, y], outputs=[z],\n name='test_mod_uint8')" + } + ] + }, + { + "name": "Momentum", + "module": "ai.onnx.preview.training", + "version": 1, + "support_level": "common", + "description": "Compute one iteration of stochastic gradient update with momentum.\n This operator can conduct the optimization of multiple tensor variables.\n\n Let's define the behavior of this operator. As you can imagine, SG with momentum requires\n several parameters:\n\n - The learning-rate \"R\".\n - The update count \"T\". That is, the number of conducted training iterations. It should\n be zero in the first training iteration.\n - A L2-norm regularization coefficient \"norm_coefficient\".\n - A decay coefficient of previous accumulated gradient (i.e., momentum) \"alpha\".\n - The scaling coefficient of current gradient \"beta\".\n - An attribute to choose either standard momentum or Nesterov's momentum \"mode\" should\n be used.\n\n For the sake of simplicity, assume that there is only one tensor (called \"X\") to be optimized.\n Other necessary inputs are \"X\"'s gradient (called \"G\") and \"X\"'s momentum (called \"V\"). This\n Momentum operator maps all these inputs to the new value of \"X\" (called \"X_new\") and its new\n momentum (called \"V_new\").\n\n This operator supports two different momentum algorithms. Set the attribute \"mode\" to\n \"nesterov\" if Nesterov's momentum is desired. Otherwise, set the attribute \"model\" to\n \"standard\" to use standard momentum. Computation details are described subsequently.\n\n Let \"+\", \"-\", \"*\", and \"/\" are all element-wise operations with numpy-style broadcasting.\n\n Pseudo code for SG with standard momentum:\n\n // Add gradient of 0.5 * norm_coefficient * ||X||^2, where ||X|| is the sum of squared\n // values of all elements in X.\n G_regularized = norm_coefficient * X + G\n\n // In the first training iteration, beta should always be 1.\n beta_adjusted = T > 0 ? beta : 1\n\n // Compute the current momentum based on previous momentum and the current gradient.\n V_new = alpha * V + beta_adjusted * G_regularized\n\n // Update X.\n X_new = X - R * V_new\n\n Pseudo code for SG with Nesterov's momentum:\n\n // Add gradient of 0.5 * norm_coefficient * ||X||^2, where ||X|| is the sum of squared\n // values of all elements in X.\n G_regularized = norm_coefficient * X + G;\n\n // In the first training iteration, beta should always be 1.\n beta_adjusted = T > 0 ? beta : 1\n\n // Compute the current momentum based on previous momentum and the current gradient.\n V_new = alpha * V + beta_adjusted * G_regularized;\n\n // Compute final update direction and then update X.\n X_new = X - R * (G_regularized + alpha * V_new)\n\n If one assign this operators to optimize multiple inputs, for example, \"X_1\" and \"X_2\". The same\n pseudo code would be extended to handle all tensors jointly. More specifically, we can view \"X\" as a\n concatenation of \"X_1\" and \"X_2\" (of course, their gradient and accumulate gradient should\n be concatenated too) and then our pseudo code becomes applicable.\n", + "attributes": [ + { + "name": "alpha", + "type": "float32", + "required": true, + "description": "The decay factor of momentum. It should be a scalar." + }, + { + "name": "beta", + "type": "float32", + "required": true, + "description": "The coefficient of gradient in computing new momentum. It should be a scalar." + }, + { + "name": "mode", + "type": "string", + "required": true, + "description": "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" + }, + { + "name": "norm_coefficient", + "type": "float32", + "required": true, + "description": "Coefficient of 0.5 * norm_coefficient * ||X||^2." + } + ], + "inputs": [ + { + "name": "R", + "type": "T1", + "description": "The learning rate." + }, + { + "name": "T", + "type": "T2", + "description": "Update count of \"X\". It should be a scalar." + }, + { + "name": "inputs", + "type": "T3", + "list": true, + "description": "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\"]." + } + ], + "min_input": 3, + "max_input": 2147483647, + "outputs": [ + { + "name": "outputs", + "type": "T3", + "list": true, + "description": "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\"]." + } + ], + "min_output": 1, + "max_output": 2147483647, + "inputs_range": "3 - ∞", + "outputs_range": "1 - ∞", + "type_constraints": [ + { + "description": "Constrain input types to float scalars.", + "type_param_str": "T1", + "allowed_type_strs": [ + "tensor(float)", + "tensor(double)" + ] + }, + { + "description": "Constrain input types to 64-bit integer scalars.", + "type_param_str": "T2", + "allowed_type_strs": [ + "tensor(int64)" + ] + }, + { + "description": "Constrain input types to float tensors.", + "type_param_str": "T3", + "allowed_type_strs": [ + "tensor(float)", + "tensor(double)" + ] + } + ], + "examples": [ + { + "summary": "momentum", + "code": "# Define operator attributes.\nnorm_coefficient = 0.001\nalpha = 0.95\nbeta = 0.1\n\n# Create operator.\nnode = onnx.helper.make_node('Momentum',\n inputs=['R', 'T', 'X', 'G', 'V'],\n outputs=['X_new', 'V_new'],\n norm_coefficient=norm_coefficient,\n alpha=alpha,\n beta=beta,\n mode='standard',\n domain=AI_ONNX_PREVIEW_TRAINING_DOMAIN\n )\n\n# Define operator inputs.\nr = np.array(0.1, dtype=np.float32) # scalar\nt = np.array(0, dtype=np.int64) # scalar\nx = np.array([1.2, 2.8], dtype=np.float32)\ng = np.array([-0.94, -2.5], dtype=np.float32)\nv = np.array([1.7, 3.6], dtype=np.float32)\n\n# Compute expected outputs of Momentum.\nx_new, v_new = apply_momentum(r, t, x, g, v,\n norm_coefficient, alpha, beta)\n\n# Check results.\nexpect(node, inputs=[r, t, x, g, v],\n outputs=[x_new, v_new], name='test_momentum',\n opset_imports=[onnx.helper.make_opsetid(AI_ONNX_PREVIEW_TRAINING_DOMAIN, 1)])" + }, + { + "summary": "momentum_multiple", + "code": "# Define operator attributes.\nnorm_coefficient = 0.001\nalpha = 0.95\nbeta = 0.85\n\nnode = onnx.helper.make_node('Momentum',\n inputs=['R', 'T', 'X1', 'X2',\n 'G1', 'G2', 'H1', 'H2'],\n outputs=['X1_new', 'X2_new',\n 'V1_new', 'V2_new'],\n norm_coefficient=norm_coefficient,\n alpha=alpha,\n beta=beta,\n mode='standard',\n domain=AI_ONNX_PREVIEW_TRAINING_DOMAIN\n )\n\n# Define operator inputs.\nr = np.array(0.1, dtype=np.float32) # scalar\nt = np.array(0, dtype=np.int64) # scalar\n\nx1 = np.array([1.0], dtype=np.float32)\ng1 = np.array([-1.0], dtype=np.float32)\nv1 = np.array([2.0], dtype=np.float32)\n\nx2 = np.array([1.0, 2.0], dtype=np.float32)\ng2 = np.array([-1.0, -3.0], dtype=np.float32)\nv2 = np.array([4.0, 1.0], dtype=np.float32)\n\n# Compute expected outputs of Momentum.\nx1_new, v1_new = apply_momentum(r, t, x1, g1, v1,\n norm_coefficient, alpha, beta)\nx2_new, v2_new = apply_momentum(r, t, x2, g2, v2,\n norm_coefficient, alpha, beta)\n\n# Check results.\nexpect(node, inputs=[r, t, x1, x2, g1, g2, v1, v2],\n outputs=[x1_new, x2_new, v1_new, v2_new], name='test_momentum_multiple',\n opset_imports=[onnx.helper.make_opsetid(AI_ONNX_PREVIEW_TRAINING_DOMAIN, 1)])" + }, + { + "summary": "nesterov_momentum", + "code": "# Define operator attributes.\nnorm_coefficient = 0.01\nalpha = 0.95\nbeta = 1.0\n\n# Create operator.\nnode = onnx.helper.make_node('Momentum',\n inputs=['R', 'T', 'X', 'G', 'V'],\n outputs=['X_new', 'V_new'],\n norm_coefficient=norm_coefficient,\n alpha=alpha,\n beta=beta,\n mode='nesterov',\n domain=AI_ONNX_PREVIEW_TRAINING_DOMAIN\n )\n\n# Define operator inputs.\nr = np.array(0.1, dtype=np.float32) # scalar\nt = np.array(0, dtype=np.int64) # scalar\nx = np.array([1.2, 2.8], dtype=np.float32)\ng = np.array([-0.94, -2.5], dtype=np.float32)\nv = np.array([1.7, 3.6], dtype=np.float32)\n\n# Compute expected outputs of Momentum.\nx_new, v_new = apply_nesterov(r, t, x, g, v,\n norm_coefficient, alpha, beta)\n\n# Check results.\nexpect(node, inputs=[r, t, x, g, v],\n outputs=[x_new, v_new], name='test_nesterov_momentum',\n opset_imports=[onnx.helper.make_opsetid(AI_ONNX_PREVIEW_TRAINING_DOMAIN, 1)])" + } + ] + }, + { + "name": "Mul", + "module": "ai.onnx", + "version": 1, + "support_level": "common", + "description": "Performs element-wise binary multiplication (with limited broadcast support).\n\nIf necessary the right-hand-side argument will be broadcasted to match the\nshape of left-hand-side argument. When broadcasting is specified, the second\ntensor can either be of element size 1 (including a scalar tensor and any\ntensor with rank equal to or smaller than the first tensor), or having its\nshape as a contiguous subset of the first tensor's shape. The starting of the\nmutually equal shape is specified by the argument \"axis\", and if it is not set,\nsuffix matching is assumed. 1-dim expansion doesn't work yet.\n\nFor example, the following tensor shapes are supported (with broadcast=1):\n\n shape(A) = (2, 3, 4, 5), shape(B) = (,), i.e. B is a scalar tensor\n shape(A) = (2, 3, 4, 5), shape(B) = (1, 1), i.e. B is an 1-element tensor\n shape(A) = (2, 3, 4, 5), shape(B) = (5,)\n shape(A) = (2, 3, 4, 5), shape(B) = (4, 5)\n shape(A) = (2, 3, 4, 5), shape(B) = (3, 4), with axis=1\n shape(A) = (2, 3, 4, 5), shape(B) = (2), with axis=0\n\nAttribute `broadcast=1` needs to be passed to enable broadcasting.\n", + "attributes": [ + { + "name": "axis", + "type": "int64", + "required": false, + "description": "If set, defines the broadcast dimensions. See doc for details." + }, + { + "name": "broadcast", + "type": "int64", + "required": false, + "description": "Pass 1 to enable broadcasting" + }, + { + "name": "consumed_inputs", + "type": "int64[]", + "required": false, + "description": "legacy optimization attribute." + } + ], + "inputs": [ + { + "name": "A", + "type": "T", + "description": "First operand, should share the type with the second operand." + }, + { + "name": "B", + "type": "T", + "description": "Second operand. With broadcasting can be of smaller size than A. If broadcasting is disabled it should be of the same size." + } + ], + "min_input": 2, + "max_input": 2, + "outputs": [ + { + "name": "C", + "type": "T", + "description": "Result, has same dimensions and type as A" + } + ], + "min_output": 1, + "max_output": 1, + "type_constraints": [ + { + "description": "Constrain input and output types to float tensors.", + "type_param_str": "T", + "allowed_type_strs": [ + "tensor(float16)", + "tensor(float)", + "tensor(double)" + ] + } + ], + "examples": [ + { + "summary": "mul", + "code": "node = onnx.helper.make_node(\n 'Mul',\n inputs=['x', 'y'],\n outputs=['z'],\n)\n\nx = np.array([1, 2, 3]).astype(np.float32)\ny = np.array([4, 5, 6]).astype(np.float32)\nz = x * y # expected output [4., 10., 18.]\nexpect(node, inputs=[x, y], outputs=[z],\n name='test_mul_example')\n\nx = np.random.randn(3, 4, 5).astype(np.float32)\ny = np.random.randn(3, 4, 5).astype(np.float32)\nz = x * y\nexpect(node, inputs=[x, y], outputs=[z],\n name='test_mul')\n\nx = np.random.randint(4, size=(3, 4, 5), dtype=np.uint8)\ny = np.random.randint(24, size=(3, 4, 5), dtype=np.uint8)\nz = x * y\nexpect(node, inputs=[x, y], outputs=[z],\n name='test_mul_uint8')" + }, + { + "summary": "mul_broadcast", + "code": "node = onnx.helper.make_node(\n 'Mul',\n inputs=['x', 'y'],\n outputs=['z'],\n)\n\nx = np.random.randn(3, 4, 5).astype(np.float32)\ny = np.random.randn(5).astype(np.float32)\nz = x * y\nexpect(node, inputs=[x, y], outputs=[z],\n name='test_mul_bcast')" + } + ] + }, + { + "name": "Mul", + "module": "ai.onnx", + "version": 6, + "support_level": "common", + "description": "Performs element-wise binary multiplication (with limited broadcast support).\n\nIf necessary the right-hand-side argument will be broadcasted to match the\nshape of left-hand-side argument. When broadcasting is specified, the second\ntensor can either be of element size 1 (including a scalar tensor and any\ntensor with rank equal to or smaller than the first tensor), or having its\nshape as a contiguous subset of the first tensor's shape. The starting of the\nmutually equal shape is specified by the argument \"axis\", and if it is not set,\nsuffix matching is assumed. 1-dim expansion doesn't work yet.\n\nFor example, the following tensor shapes are supported (with broadcast=1):\n\n shape(A) = (2, 3, 4, 5), shape(B) = (,), i.e. B is a scalar tensor\n shape(A) = (2, 3, 4, 5), shape(B) = (1, 1), i.e. B is an 1-element tensor\n shape(A) = (2, 3, 4, 5), shape(B) = (5,)\n shape(A) = (2, 3, 4, 5), shape(B) = (4, 5)\n shape(A) = (2, 3, 4, 5), shape(B) = (3, 4), with axis=1\n shape(A) = (2, 3, 4, 5), shape(B) = (2), with axis=0\n\nAttribute `broadcast=1` needs to be passed to enable broadcasting.\n", + "attributes": [ + { + "name": "axis", + "type": "int64", + "required": false, + "description": "If set, defines the broadcast dimensions. See doc for details." + }, + { + "name": "broadcast", + "type": "int64", + "required": false, + "description": "Pass 1 to enable broadcasting" + } + ], + "inputs": [ + { + "name": "A", + "type": "T", + "description": "First operand, should share the type with the second operand." + }, + { + "name": "B", + "type": "T", + "description": "Second operand. With broadcasting can be of smaller size than A. If broadcasting is disabled it should be of the same size." + } + ], + "min_input": 2, + "max_input": 2, + "outputs": [ + { + "name": "C", + "type": "T", + "description": "Result, has same dimensions and type as A" + } + ], + "min_output": 1, + "max_output": 1, + "type_constraints": [ + { + "description": "Constrain input and output types to high-precision numeric tensors.", + "type_param_str": "T", + "allowed_type_strs": [ + "tensor(uint32)", + "tensor(uint64)", + "tensor(int32)", + "tensor(int64)", + "tensor(float16)", + "tensor(float)", + "tensor(double)" + ] + } + ], + "examples": [ + { + "summary": "mul", + "code": "node = onnx.helper.make_node(\n 'Mul',\n inputs=['x', 'y'],\n outputs=['z'],\n)\n\nx = np.array([1, 2, 3]).astype(np.float32)\ny = np.array([4, 5, 6]).astype(np.float32)\nz = x * y # expected output [4., 10., 18.]\nexpect(node, inputs=[x, y], outputs=[z],\n name='test_mul_example')\n\nx = np.random.randn(3, 4, 5).astype(np.float32)\ny = np.random.randn(3, 4, 5).astype(np.float32)\nz = x * y\nexpect(node, inputs=[x, y], outputs=[z],\n name='test_mul')\n\nx = np.random.randint(4, size=(3, 4, 5), dtype=np.uint8)\ny = np.random.randint(24, size=(3, 4, 5), dtype=np.uint8)\nz = x * y\nexpect(node, inputs=[x, y], outputs=[z],\n name='test_mul_uint8')" + }, + { + "summary": "mul_broadcast", + "code": "node = onnx.helper.make_node(\n 'Mul',\n inputs=['x', 'y'],\n outputs=['z'],\n)\n\nx = np.random.randn(3, 4, 5).astype(np.float32)\ny = np.random.randn(5).astype(np.float32)\nz = x * y\nexpect(node, inputs=[x, y], outputs=[z],\n name='test_mul_bcast')" + } + ] + }, + { + "name": "Mul", + "module": "ai.onnx", + "version": 7, + "support_level": "common", + "description": "Performs element-wise binary multiplication (with Numpy-style broadcasting support).\n\nThis operator supports **multidirectional (i.e., Numpy-style) broadcasting**; for more details please check [the doc](https://github.com/onnx/onnx/blob/master/docs/Broadcasting.md).\n", + "inputs": [ + { + "name": "A", + "type": "T", + "description": "First operand." + }, + { + "name": "B", + "type": "T", + "description": "Second operand." + } + ], + "min_input": 2, + "max_input": 2, + "outputs": [ + { + "name": "C", + "type": "T", + "description": "Result, has same element type as two inputs" + } + ], + "min_output": 1, + "max_output": 1, + "type_constraints": [ + { + "description": "Constrain input and output types to high-precision numeric tensors.", + "type_param_str": "T", + "allowed_type_strs": [ + "tensor(uint32)", + "tensor(uint64)", + "tensor(int32)", + "tensor(int64)", + "tensor(float16)", + "tensor(float)", + "tensor(double)" + ] + } + ], + "examples": [ + { + "summary": "mul", + "code": "node = onnx.helper.make_node(\n 'Mul',\n inputs=['x', 'y'],\n outputs=['z'],\n)\n\nx = np.array([1, 2, 3]).astype(np.float32)\ny = np.array([4, 5, 6]).astype(np.float32)\nz = x * y # expected output [4., 10., 18.]\nexpect(node, inputs=[x, y], outputs=[z],\n name='test_mul_example')\n\nx = np.random.randn(3, 4, 5).astype(np.float32)\ny = np.random.randn(3, 4, 5).astype(np.float32)\nz = x * y\nexpect(node, inputs=[x, y], outputs=[z],\n name='test_mul')\n\nx = np.random.randint(4, size=(3, 4, 5), dtype=np.uint8)\ny = np.random.randint(24, size=(3, 4, 5), dtype=np.uint8)\nz = x * y\nexpect(node, inputs=[x, y], outputs=[z],\n name='test_mul_uint8')" + }, + { + "summary": "mul_broadcast", + "code": "node = onnx.helper.make_node(\n 'Mul',\n inputs=['x', 'y'],\n outputs=['z'],\n)\n\nx = np.random.randn(3, 4, 5).astype(np.float32)\ny = np.random.randn(5).astype(np.float32)\nz = x * y\nexpect(node, inputs=[x, y], outputs=[z],\n name='test_mul_bcast')" + } + ] + }, + { + "name": "Mul", + "module": "ai.onnx", + "version": 13, + "support_level": "common", + "description": "Performs element-wise binary multiplication (with Numpy-style broadcasting support).\n\nThis operator supports **multidirectional (i.e., Numpy-style) broadcasting**; for more details please check [the doc](https://github.com/onnx/onnx/blob/master/docs/Broadcasting.md).\n", + "inputs": [ + { + "name": "A", + "type": "T", + "description": "First operand." + }, + { + "name": "B", + "type": "T", + "description": "Second operand." + } + ], + "min_input": 2, + "max_input": 2, + "outputs": [ + { + "name": "C", + "type": "T", + "description": "Result, has same element type as two inputs" + } + ], + "min_output": 1, + "max_output": 1, + "type_constraints": [ + { + "description": "Constrain input and output types to high-precision numeric tensors.", + "type_param_str": "T", + "allowed_type_strs": [ + "tensor(uint32)", + "tensor(uint64)", + "tensor(int32)", + "tensor(int64)", + "tensor(float16)", + "tensor(float)", + "tensor(double)", + "tensor(bfloat16)" + ] + } + ], + "examples": [ + { + "summary": "mul", + "code": "node = onnx.helper.make_node(\n 'Mul',\n inputs=['x', 'y'],\n outputs=['z'],\n)\n\nx = np.array([1, 2, 3]).astype(np.float32)\ny = np.array([4, 5, 6]).astype(np.float32)\nz = x * y # expected output [4., 10., 18.]\nexpect(node, inputs=[x, y], outputs=[z],\n name='test_mul_example')\n\nx = np.random.randn(3, 4, 5).astype(np.float32)\ny = np.random.randn(3, 4, 5).astype(np.float32)\nz = x * y\nexpect(node, inputs=[x, y], outputs=[z],\n name='test_mul')\n\nx = np.random.randint(4, size=(3, 4, 5), dtype=np.uint8)\ny = np.random.randint(24, size=(3, 4, 5), dtype=np.uint8)\nz = x * y\nexpect(node, inputs=[x, y], outputs=[z],\n name='test_mul_uint8')" + }, + { + "summary": "mul_broadcast", + "code": "node = onnx.helper.make_node(\n 'Mul',\n inputs=['x', 'y'],\n outputs=['z'],\n)\n\nx = np.random.randn(3, 4, 5).astype(np.float32)\ny = np.random.randn(5).astype(np.float32)\nz = x * y\nexpect(node, inputs=[x, y], outputs=[z],\n name='test_mul_bcast')" + } + ] + }, + { + "name": "Mul", + "module": "ai.onnx", + "version": 14, + "support_level": "common", + "description": "Performs element-wise binary multiplication (with Numpy-style broadcasting support).\n\nThis operator supports **multidirectional (i.e., Numpy-style) broadcasting**; for more details please check [the doc](https://github.com/onnx/onnx/blob/master/docs/Broadcasting.md).\n\n(Opset 14 change): Extend supported types to include uint8, int8, uint16, and int16.\n", + "inputs": [ + { + "name": "A", + "type": "T", + "description": "First operand." + }, + { + "name": "B", + "type": "T", + "description": "Second operand." + } + ], + "min_input": 2, + "max_input": 2, + "outputs": [ + { + "name": "C", + "type": "T", + "description": "Result, has same element type as two inputs" + } + ], + "min_output": 1, + "max_output": 1, + "type_constraints": [ + { + "description": "Constrain input and output types to all numeric tensors.", + "type_param_str": "T", + "allowed_type_strs": [ + "tensor(uint8)", + "tensor(uint16)", + "tensor(uint32)", + "tensor(uint64)", + "tensor(int8)", + "tensor(int16)", + "tensor(int32)", + "tensor(int64)", + "tensor(float16)", + "tensor(float)", + "tensor(double)", + "tensor(bfloat16)" + ] + } + ], + "examples": [ + { + "summary": "mul", + "code": "node = onnx.helper.make_node(\n 'Mul',\n inputs=['x', 'y'],\n outputs=['z'],\n)\n\nx = np.array([1, 2, 3]).astype(np.float32)\ny = np.array([4, 5, 6]).astype(np.float32)\nz = x * y # expected output [4., 10., 18.]\nexpect(node, inputs=[x, y], outputs=[z],\n name='test_mul_example')\n\nx = np.random.randn(3, 4, 5).astype(np.float32)\ny = np.random.randn(3, 4, 5).astype(np.float32)\nz = x * y\nexpect(node, inputs=[x, y], outputs=[z],\n name='test_mul')\n\nx = np.random.randint(4, size=(3, 4, 5), dtype=np.uint8)\ny = np.random.randint(24, size=(3, 4, 5), dtype=np.uint8)\nz = x * y\nexpect(node, inputs=[x, y], outputs=[z],\n name='test_mul_uint8')" + }, + { + "summary": "mul_broadcast", + "code": "node = onnx.helper.make_node(\n 'Mul',\n inputs=['x', 'y'],\n outputs=['z'],\n)\n\nx = np.random.randn(3, 4, 5).astype(np.float32)\ny = np.random.randn(5).astype(np.float32)\nz = x * y\nexpect(node, inputs=[x, y], outputs=[z],\n name='test_mul_bcast')" + } + ] + }, + { + "name": "Multinomial", + "module": "ai.onnx", + "version": 7, + "support_level": "common", + "description": "Generate a tensor of samples from a multinomial distribution according to the probabilities\nof each of the possible outcomes.\n", + "attributes": [ + { + "name": "dtype", + "type": "int64", + "required": false, + "default": 6, + "description": "(Optional) The data type for the elements of the output tensor, if not specified, we will use int32." + }, + { + "name": "sample_size", + "type": "int64", + "required": false, + "default": 1, + "description": "Number of times to sample." + }, + { + "name": "seed", + "type": "float32", + "required": false, + "description": "(Optional) Seed to the random generator, if not specified we will auto generate one." + } + ], + "inputs": [ + { + "name": "input", + "type": "T1", + "description": "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." + } + ], + "min_input": 1, + "max_input": 1, + "outputs": [ + { + "name": "output", + "type": "T2", + "description": "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." + } + ], + "min_output": 1, + "max_output": 1, + "type_constraints": [ + { + "description": "Constrain input types to float tensors.", + "type_param_str": "T1", + "allowed_type_strs": [ + "tensor(float16)", + "tensor(float)", + "tensor(double)" + ] + }, + { + "description": "Constrain output types to integral tensors.", + "type_param_str": "T2", + "allowed_type_strs": [ + "tensor(int32)", + "tensor(int64)" + ] + } + ] + }, + { + "name": "Neg", + "module": "ai.onnx", + "version": 1, + "support_level": "common", + "description": "Neg takes one input data (Tensor) and produces one output data\n(Tensor) where each element flipped sign, y = -x, is applied to\nthe tensor elementwise.\n", + "attributes": [ + { + "name": "consumed_inputs", + "type": "int64[]", + "required": false, + "description": "legacy optimization attribute." + } + ], + "inputs": [ + { + "name": "X", + "type": "T", + "description": "Input tensor" + } + ], + "min_input": 1, + "max_input": 1, + "outputs": [ + { + "name": "Y", + "type": "T", + "description": "Output tensor" + } + ], + "min_output": 1, + "max_output": 1, + "type_constraints": [ + { + "description": "Constrain input and output types to float tensors.", + "type_param_str": "T", + "allowed_type_strs": [ + "tensor(float16)", + "tensor(float)", + "tensor(double)" + ] + } + ], + "examples": [ + { + "summary": "neg", + "code": "node = onnx.helper.make_node(\n 'Neg',\n inputs=['x'],\n outputs=['y'],\n)\n\nx = np.array([-4, 2]).astype(np.float32)\ny = np.negative(x) # expected output [4., -2.],\nexpect(node, inputs=[x], outputs=[y],\n name='test_neg_example')\n\nx = np.random.randn(3, 4, 5).astype(np.float32)\ny = np.negative(x)\nexpect(node, inputs=[x], outputs=[y],\n name='test_neg')" + } + ] + }, + { + "name": "Neg", + "module": "ai.onnx", + "version": 6, + "support_level": "common", + "description": "Neg takes one input data (Tensor) and produces one output data\n(Tensor) where each element flipped sign, y = -x, is applied to\nthe tensor elementwise.\n", + "inputs": [ + { + "name": "X", + "type": "T", + "description": "Input tensor" + } + ], + "min_input": 1, + "max_input": 1, + "outputs": [ + { + "name": "Y", + "type": "T", + "description": "Output tensor" + } + ], + "min_output": 1, + "max_output": 1, + "type_constraints": [ + { + "description": "Constrain input and output types to signed numeric tensors.", + "type_param_str": "T", + "allowed_type_strs": [ + "tensor(float)", + "tensor(int32)", + "tensor(int8)", + "tensor(int16)", + "tensor(int64)", + "tensor(float16)", + "tensor(double)" + ] + } + ], + "examples": [ + { + "summary": "neg", + "code": "node = onnx.helper.make_node(\n 'Neg',\n inputs=['x'],\n outputs=['y'],\n)\n\nx = np.array([-4, 2]).astype(np.float32)\ny = np.negative(x) # expected output [4., -2.],\nexpect(node, inputs=[x], outputs=[y],\n name='test_neg_example')\n\nx = np.random.randn(3, 4, 5).astype(np.float32)\ny = np.negative(x)\nexpect(node, inputs=[x], outputs=[y],\n name='test_neg')" + } + ] + }, + { + "name": "Neg", + "module": "ai.onnx", + "version": 13, + "support_level": "common", + "description": "Neg takes one input data (Tensor) and produces one output data\n(Tensor) where each element flipped sign, y = -x, is applied to\nthe tensor elementwise.\n", + "inputs": [ + { + "name": "X", + "type": "T", + "description": "Input tensor" + } + ], + "min_input": 1, + "max_input": 1, + "outputs": [ + { + "name": "Y", + "type": "T", + "description": "Output tensor" + } + ], + "min_output": 1, + "max_output": 1, + "type_constraints": [ + { + "description": "Constrain input and output types to signed numeric tensors.", + "type_param_str": "T", + "allowed_type_strs": [ + "tensor(float)", + "tensor(int32)", + "tensor(int8)", + "tensor(int16)", + "tensor(int64)", + "tensor(float16)", + "tensor(double)", + "tensor(bfloat16)" + ] + } + ], + "examples": [ + { + "summary": "neg", + "code": "node = onnx.helper.make_node(\n 'Neg',\n inputs=['x'],\n outputs=['y'],\n)\n\nx = np.array([-4, 2]).astype(np.float32)\ny = np.negative(x) # expected output [4., -2.],\nexpect(node, inputs=[x], outputs=[y],\n name='test_neg_example')\n\nx = np.random.randn(3, 4, 5).astype(np.float32)\ny = np.negative(x)\nexpect(node, inputs=[x], outputs=[y],\n name='test_neg')" + } + ] + }, + { + "name": "NegativeLogLikelihoodLoss", + "module": "ai.onnx", + "version": 12, + "support_level": "common", + "description": "A NegativeLogLikelihoodLoss operator computes (weighted) negative log likelihood loss.\nIts \"input\" tensor has the shape of (N, C, d1, d2, ..., dk) where k >= 0.\nThe \"input\" tensor contains log-probabilities for input[n, :, d_1, d_2,..., d_k] being in a class of [0, C).\nThe operator's \"target\" input tensor has the shape of (N, d1, d2, ..., dk). It encodes class labels (one of C classes)\nor it may contain a special value (indicated by an attribute ignore_index) for N x d1 x d2 x ... x dk samples.\nThe 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:\n loss[n][d_1][d_2]...[d_k] = -input[n][c][d_1][d_2]...[d_k].\nWhen an optional \"weight\" is provided, the sample loss is calculated as:\n loss[n][d_1][d_2]...[d_k] = -input[n][c][d_1][d_2]...[d_k] * weight[c].\nloss is zero for the case when target-value equals ignore_index.\n\n loss[n][d_1][d_2]...[d_k] = 0, when target[n][d_1][d_2]...[d_k] = ignore_index\nIf \"reduction\" attribute is set to \"none\", the operator's output will be the above loss with shape (N, d1, d2, ..., dk).\nIf \"reduction\" attribute is set to \"mean\" (the default attribute value), the output loss is (weight) averaged:\n mean(loss), if \"weight\" is not provided,\nor if weight is provided,\n sum(loss) / sum(weight[target[n][d_1][d_2]...[d_k]]]), for all samples.\nIf \"reduction\" attribute is set to \"sum\", the output is a scalar:\n sum(loss).\nSee also https://pytorch.org/docs/stable/nn.html#torch.nn.NLLLoss.\nExample 1:\n // negative log likelihood loss, \"none\" reduction\n N, C, d1 = 2, 3, 2\n input = [[[1.0, 2.0], [2.0, 2.0], [3.0, 2.0]],\n [[0.0, 1.0], [2.0, 2.0], [1.0, 2]]]\n target = [[2, 1], [0, 2]]\n loss = np.zeros((N, d1))\n for n in range(N):\n for d_1 in range(d1):\n c = target[n][d_1]\n loss[n][d_1] = -input[n][c][d_1]\n // print(loss)\n // [[-3. -2.]\n // [-0. -2.]]\nExample 2:\n // weighted negative log likelihood loss, sum reduction\n N, C, d1 = 2, 3, 2\n input = [[[1.0, 2.0], [2.0, 2.0], [3.0, 2.0]],\n [[0.0, 1.0], [2.0, 2.0], [1.0, 2]]]\n target = [[2, 1], [0, 2]]\n weight = [0.2, 0.3, 0.1]\n loss = np.zeros((N, d1))\n for n in range(N):\n for d_1 in range(d1):\n c = target[n][d_1]\n loss[n][d_1] = -input[n][c][d_1] * weight[c]\n loss = np.sum(loss)\n // print(loss)\n // -1.1\nExample 3:\n // weighted negative log likelihood loss, mean reduction\n N, C, d1 = 2, 3, 2\n input = [[[1.0, 2.0], [2.0, 2.0], [3.0, 2.0]],\n [[0.0, 1.0], [2.0, 2.0], [1.0, 2]]]\n target = [[2, 1], [0, 2]]\n weight = [0.2, 0.3, 0.1]\n loss = np.zeros((N, d1))\n weight_total = 0\n for n in range(N):\n for d_1 in range(d1):\n c = target[n][d_1]\n loss[n][d_1] = -input[n][c][d_1] * weight[c]\n weight_total = weight_total + weight[c]\n loss = np.sum(loss) / weight_total\n // print(loss)\n // -1.57\n", + "attributes": [ + { + "name": "ignore_index", + "type": "int64", + "required": false, + "description": "Specifies a target value that is ignored and does not contribute to the input gradient. It's an optional value." + }, + { + "name": "reduction", + "type": "string", + "required": false, + "default": "mean", + "description": "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": [ + { + "name": "input", + "type": "T", + "description": "Input tensor of shape (N, C) or (N, C, d1, d2, ..., dk)." + }, + { + "name": "target", + "type": "Tind", + "description": "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." + }, + { + "name": "weight", + "type": "T", + "option": "optional", + "description": "Optional rescaling weight tensor. If given, it has to be a tensor of size C. Otherwise, it is treated as if having all ones." + } + ], + "min_input": 2, + "max_input": 3, + "outputs": [ + { + "name": "loss", + "type": "T", + "description": "The negative log likelihood loss" + } + ], + "min_output": 1, + "max_output": 1, + "inputs_range": "2 - 3", + "type_constraints": [ + { + "description": "Constrain input, weight, and output types to floating-point tensors.", + "type_param_str": "T", + "allowed_type_strs": [ + "tensor(float16)", + "tensor(float)", + "tensor(double)" + ] + }, + { + "description": "Constrain target to integer types", + "type_param_str": "Tind", + "allowed_type_strs": [ + "tensor(int32)", + "tensor(int64)" + ] + } + ], + "examples": [ + { + "summary": "input_shape_is_NC", + "code": "reduction = 'none'\nnode = onnx.helper.make_node(\n 'NegativeLogLikelihoodLoss',\n inputs=['input', 'target'],\n outputs=['loss'],\n reduction=reduction\n)\n\nN, C = 3, 5\nnp.random.seed(0)\ninput = np.random.rand(N, C).astype(np.float32)\ntarget = np.random.randint(0, high=C, size=(N, )).astype(np.int64)\n\nnegative_log_likelihood_loss = compute_negative_log_likelihood_loss(input, target, weight=None, reduction=reduction)\n\nexpect(node, inputs=[input, target], outputs=[negative_log_likelihood_loss],\n name='test_nllloss_NC')" + }, + { + "summary": "input_shape_is_NCd1", + "code": "reduction = 'mean'\nnode = onnx.helper.make_node(\n 'NegativeLogLikelihoodLoss',\n inputs=['input', 'target'],\n outputs=['loss'],\n reduction=reduction\n)\n\nN, C, d1 = 3, 5, 2\nnp.random.seed(0)\ninput = np.random.rand(N, C, d1).astype(np.float32)\ntarget = np.random.randint(0, high=C, size=(N, d1)).astype(np.int64)\n\nnegative_log_likelihood_loss = compute_negative_log_likelihood_loss(input, target, weight=None, reduction=reduction)\n\nexpect(node, inputs=[input, target], outputs=[negative_log_likelihood_loss],\n name='test_nllloss_NCd1')" + }, + { + "summary": "input_shape_is_NCd1_ii", + "code": "reduction = 'mean'\nignore_index = np.int64(1)\nnode = onnx.helper.make_node(\n 'NegativeLogLikelihoodLoss',\n inputs=['input', 'target'],\n outputs=['loss'],\n reduction=reduction,\n ignore_index=ignore_index\n)\n\nN, C, d1 = 3, 5, 2\nnp.random.seed(0)\ninput = np.random.rand(N, C, d1).astype(np.float32)\ntarget = np.random.randint(0, high=C, size=(N, d1)).astype(np.int64)\ntarget[0][0] = np.int64(1)\n\nnegative_log_likelihood_loss = compute_negative_log_likelihood_loss(input, target, weight=None, reduction=reduction, ignore_index=ignore_index)\n\nexpect(node, inputs=[input, target], outputs=[negative_log_likelihood_loss],\n name='test_nllloss_NCd1_ii')" + }, + { + "summary": "input_shape_is_NCd1_mean_weight_negative_ii", + "code": "reduction = 'mean'\nignore_index = np.int64(-1)\n\nnode = onnx.helper.make_node(\n 'NegativeLogLikelihoodLoss',\n inputs=['input', 'target', 'weight'],\n outputs=['loss'],\n reduction=reduction,\n ignore_index=ignore_index)\n\nN, C, dim1 = 3, 5, 6\nnp.random.seed(0)\ninput = np.random.rand(N, C, dim1).astype(np.float32)\ntarget = np.random.randint(0, high=C, size=(N, dim1)).astype(np.int64)\ntarget[0][0] = -1\nweight = np.random.rand(C).astype(np.float32)\n\nnegative_log_likelihood_loss = compute_negative_log_likelihood_loss(input,\n target,\n weight=weight,\n reduction=reduction,\n ignore_index=ignore_index)\n\nexpect(node, inputs=[input, target, weight], outputs=[negative_log_likelihood_loss],\n name='test_nllloss_NCd1_mean_weight_negative_ii')" + }, + { + "summary": "input_shape_is_NCd1_weight", + "code": "reduction = 'mean'\nnode = onnx.helper.make_node(\n 'NegativeLogLikelihoodLoss',\n inputs=['input', 'target', 'weight'],\n outputs=['loss'],\n reduction=reduction\n)\n\nN, C, d1 = 3, 5, 2\nnp.random.seed(0)\ninput = np.random.rand(N, C, d1).astype(np.float32)\ntarget = np.random.randint(0, high=C, size=(N, d1)).astype(np.int64)\nweight = np.random.rand(C).astype(np.float32)\n\nnegative_log_likelihood_loss = compute_negative_log_likelihood_loss(input, target, weight=weight, reduction=reduction)\n\nexpect(node, inputs=[input, target, weight], outputs=[negative_log_likelihood_loss],\n name='test_nllloss_NCd1_weight')" + }, + { + "summary": "input_shape_is_NCd1_weight_ii", + "code": "reduction = 'mean'\nignore_index = np.int64(1)\nnode = onnx.helper.make_node(\n 'NegativeLogLikelihoodLoss',\n inputs=['input', 'target', 'weight'],\n outputs=['loss'],\n reduction=reduction,\n ignore_index=ignore_index\n)\n\nN, C, d1 = 3, 5, 2\nnp.random.seed(0)\ninput = np.random.rand(N, C, d1).astype(np.float32)\ntarget = np.random.randint(0, high=C, size=(N, d1)).astype(np.int64)\ntarget[0][0] = np.int64(1)\nweight = np.random.rand(C).astype(np.float32)\n\nnegative_log_likelihood_loss = compute_negative_log_likelihood_loss(input, target, weight=weight, reduction=reduction, ignore_index=ignore_index)\n\nexpect(node, inputs=[input, target, weight], outputs=[negative_log_likelihood_loss],\n name='test_nllloss_NCd1_weight_ii')" + }, + { + "summary": "input_shape_is_NCd1d2", + "code": "reduction = 'none'\nnode = onnx.helper.make_node(\n 'NegativeLogLikelihoodLoss',\n inputs=['input', 'target'],\n outputs=['loss'],\n reduction=reduction\n)\n\nN, C, dim1, dim2 = 3, 5, 6, 6\nnp.random.seed(0)\ninput = np.random.rand(N, C, dim1, dim2).astype(np.float32)\ntarget = np.random.randint(0, high=C, size=(N, dim1, dim2)).astype(np.int64)\n\nnegative_log_likelihood_loss = compute_negative_log_likelihood_loss(input, target, weight=None, reduction=reduction)\n\nexpect(node, inputs=[input, target], outputs=[negative_log_likelihood_loss],\n name='test_nllloss_NCd1d2')" + }, + { + "summary": "input_shape_is_NCd1d2_no_weight_reduction_mean_ii", + "code": "reduction = 'mean'\nignore_index = np.int64(1)\nnode = onnx.helper.make_node(\n 'NegativeLogLikelihoodLoss',\n inputs=['input', 'target'],\n outputs=['loss'],\n reduction=reduction,\n ignore_index=ignore_index\n)\n\nN, C, dim1, dim2 = 3, 5, 6, 6\nnp.random.seed(0)\ninput = np.random.rand(N, C, dim1, dim2).astype(np.float32)\ntarget = np.random.randint(0, high=C, size=(N, dim1, dim2)).astype(np.int64)\ntarget[0][0][0] = np.int64(1)\n\nnegative_log_likelihood_loss = compute_negative_log_likelihood_loss(input, target, reduction=reduction, ignore_index=ignore_index)\n\nexpect(node, inputs=[input, target], outputs=[negative_log_likelihood_loss],\n name='test_nllloss_NCd1d2_no_weight_reduction_mean_ii')" + }, + { + "summary": "input_shape_is_NCd1d2_reduction_mean", + "code": "reduction = 'mean'\nnode = onnx.helper.make_node(\n 'NegativeLogLikelihoodLoss',\n inputs=['input', 'target'],\n outputs=['loss'],\n reduction=reduction\n)\n\nN, C, dim1, dim2 = 3, 5, 6, 6\nnp.random.seed(0)\ninput = np.random.rand(N, C, dim1, dim2).astype(np.float32)\ntarget = np.random.randint(0, high=C, size=(N, dim1, dim2)).astype(np.int64)\n\nnegative_log_likelihood_loss = compute_negative_log_likelihood_loss(input, target, weight=None, reduction=reduction)\n\nexpect(node, inputs=[input, target], outputs=[negative_log_likelihood_loss],\n name='test_nllloss_NCd1d2_reduction_mean')" + }, + { + "summary": "input_shape_is_NCd1d2_reduction_sum", + "code": "reduction = 'sum'\nnode = onnx.helper.make_node(\n 'NegativeLogLikelihoodLoss',\n inputs=['input', 'target'],\n outputs=['loss'],\n reduction=reduction\n)\n\nN, C, dim1, dim2 = 3, 5, 6, 6\nnp.random.seed(0)\ninput = np.random.rand(N, C, dim1, dim2).astype(np.float32)\ntarget = np.random.randint(0, high=C, size=(N, dim1, dim2))\n\nnegative_log_likelihood_loss = compute_negative_log_likelihood_loss(input, target, weight=None, reduction=reduction)\n\nexpect(node, inputs=[input, target], outputs=[negative_log_likelihood_loss],\n name='test_nllloss_NCd1d2_reduction_sum')" + }, + { + "summary": "input_shape_is_NCd1d2_with_weight", + "code": "reduction = 'none'\nnode = onnx.helper.make_node(\n 'NegativeLogLikelihoodLoss',\n inputs=['input', 'target', 'weight'],\n outputs=['loss'],\n reduction=reduction\n)\n\nN, C, dim1, dim2 = 3, 5, 6, 6\nnp.random.seed(0)\ninput = np.random.rand(N, C, dim1, dim2).astype(np.float32)\ntarget = np.random.randint(0, high=C, size=(N, dim1, dim2)).astype(np.int64)\nweight = np.random.rand(C).astype(np.float32)\n\nnegative_log_likelihood_loss = compute_negative_log_likelihood_loss(input, target, weight=weight, reduction=reduction)\n\nexpect(node, inputs=[input, target, weight], outputs=[negative_log_likelihood_loss],\n name='test_nllloss_NCd1d2_with_weight')" + }, + { + "summary": "input_shape_is_NCd1d2_with_weight_reduction_mean", + "code": "reduction = 'mean'\nnode = onnx.helper.make_node(\n 'NegativeLogLikelihoodLoss',\n inputs=['input', 'target', 'weight'],\n outputs=['loss'],\n reduction=reduction\n)\n\nN, C, dim1, dim2 = 3, 5, 6, 6\nnp.random.seed(0)\ninput = np.random.rand(N, C, dim1, dim2).astype(np.float32)\ntarget = np.random.randint(0, high=C, size=(N, dim1, dim2)).astype(np.int64)\nweight = np.random.rand(C).astype(np.float32)\n\nnegative_log_likelihood_loss = compute_negative_log_likelihood_loss(input, target, weight=weight, reduction=reduction)\n\nexpect(node, inputs=[input, target, weight], outputs=[negative_log_likelihood_loss],\n name='test_nllloss_NCd1d2_with_weight_reduction_mean')" + }, + { + "summary": "input_shape_is_NCd1d2_with_weight_reduction_sum", + "code": "reduction = 'sum'\nnode = onnx.helper.make_node(\n 'NegativeLogLikelihoodLoss',\n inputs=['input', 'target', 'weight'],\n outputs=['loss'],\n reduction=reduction\n)\n\nN, C, dim1, dim2 = 3, 5, 6, 6\nnp.random.seed(0)\ninput = np.random.rand(N, C, dim1, dim2).astype(np.float32)\ntarget = np.random.randint(0, high=C, size=(N, dim1, dim2)).astype(np.int64)\nweight = np.random.rand(C).astype(np.float32)\n\nnegative_log_likelihood_loss = compute_negative_log_likelihood_loss(input, target, weight=weight, reduction=reduction)\n\nexpect(node, inputs=[input, target, weight], outputs=[negative_log_likelihood_loss],\n name='test_nllloss_NCd1d2_with_weight_reduction_sum')" + }, + { + "summary": "input_shape_is_NCd1d2_with_weight_reduction_sum_ii", + "code": "reduction = 'sum'\nignore_index = np.int64(0)\nnode = onnx.helper.make_node(\n 'NegativeLogLikelihoodLoss',\n inputs=['input', 'target', 'weight'],\n outputs=['loss'],\n reduction=reduction,\n ignore_index=ignore_index\n)\n\nN, C, dim1, dim2 = 3, 5, 6, 6\nnp.random.seed(0)\ninput = np.random.rand(N, C, dim1, dim2).astype(np.float32)\ntarget = np.random.randint(0, high=C, size=(N, dim1, dim2)).astype(np.int64)\ntarget[0][0][0] = np.int64(0)\nweight = np.random.rand(C).astype(np.float32)\n\nnegative_log_likelihood_loss = compute_negative_log_likelihood_loss(input, target, weight=weight, reduction=reduction, ignore_index=ignore_index)\n\nexpect(node, inputs=[input, target, weight], outputs=[negative_log_likelihood_loss],\n name='test_nllloss_NCd1d2_with_weight_reduction_sum_ii')" + }, + { + "summary": "input_shape_is_NCd1d2d3_none_no_weight_negative_ii", + "code": "reduction = 'none'\nignore_index = np.int64(-5)\n\nnode = onnx.helper.make_node(\n 'NegativeLogLikelihoodLoss',\n inputs=['input', 'target'],\n outputs=['loss'],\n reduction=reduction,\n ignore_index=ignore_index)\n\nN, C, dim1, dim2, dim3 = 3, 5, 6, 6, 5\nnp.random.seed(0)\ninput = np.random.rand(N, C, dim1, dim2, dim3).astype(np.float32)\ntarget = np.random.randint(0, high=C, size=(N, dim1, dim2, dim3)).astype(np.int64)\ntarget[0][0][0][0] = -5\n\nnegative_log_likelihood_loss = compute_negative_log_likelihood_loss(input,\n target,\n reduction=reduction,\n ignore_index=ignore_index)\n\nexpect(node, inputs=[input, target], outputs=[negative_log_likelihood_loss],\n name='test_nllloss_NCd1d2d3_none_no_weight_negative_ii')" + }, + { + "summary": "input_shape_is_NCd1d2d3_sum_weight_high_ii", + "code": "reduction = 'sum'\nignore_index = np.int64(10)\n\nnode = onnx.helper.make_node(\n 'NegativeLogLikelihoodLoss',\n inputs=['input', 'target', 'weight'],\n outputs=['loss'],\n reduction=reduction,\n ignore_index=ignore_index)\n\nN, C = 3, 5\nnp.random.seed(0)\ninput = np.random.rand(N, C).astype(np.float32)\ntarget = np.random.randint(0, high=C, size=(N))\ntarget[0] = 10\nweight = np.random.rand(C).astype(np.float32)\n\nnegative_log_likelihood_loss = compute_negative_log_likelihood_loss(input,\n target,\n weight=weight,\n reduction=reduction,\n ignore_index=ignore_index)\n\nexpect(node, inputs=[input, target, weight], outputs=[negative_log_likelihood_loss],\n name='test_nllloss_NCd1d2d3_sum_weight_high_ii')" + }, + { + "summary": "input_shape_is_NCd1d2d3d4d5_mean_weight", + "code": "reduction = 'mean'\n\nnode = onnx.helper.make_node(\n 'NegativeLogLikelihoodLoss',\n inputs=['input', 'target', 'weight'],\n outputs=['loss'],\n reduction=reduction)\n\nN, C, dim1, dim2, dim3, dim4, dim5 = 3, 5, 6, 6, 5, 3, 4\nnp.random.seed(0)\ninput = np.random.rand(N, C, dim1, dim2, dim3, dim4, dim5).astype(np.float32)\ntarget = np.random.randint(0, high=C, size=(N, dim1, dim2, dim3, dim4, dim5)).astype(np.int64)\nweight = np.random.rand(C).astype(np.float32)\n\nnegative_log_likelihood_loss = compute_negative_log_likelihood_loss(input,\n target,\n weight=weight,\n reduction=reduction)\n\nexpect(node, inputs=[input, target, weight], outputs=[negative_log_likelihood_loss],\n name='test_nllloss_NCd1d2d3d4d5_mean_weight')" + }, + { + "summary": "input_shape_is_NCd1d2d3d4d5_none_no_weight", + "code": "reduction = 'none'\n\nnode = onnx.helper.make_node(\n 'NegativeLogLikelihoodLoss',\n inputs=['input', 'target'],\n outputs=['loss'],\n reduction=reduction)\n\nN, C, dim1, dim2, dim3, dim4, dim5 = 3, 5, 6, 6, 5, 3, 4\nnp.random.seed(0)\ninput = np.random.rand(N, C, dim1, dim2, dim3, dim4, dim5).astype(np.float32)\ntarget = np.random.randint(0, high=C, size=(N, dim1, dim2, dim3, dim4, dim5)).astype(np.int64)\n\nnegative_log_likelihood_loss = compute_negative_log_likelihood_loss(input,\n target,\n reduction=reduction)\n\nexpect(node, inputs=[input, target], outputs=[negative_log_likelihood_loss],\n name='test_nllloss_NCd1d2d3d4d5_none_no_weight')" + } + ] + }, + { + "name": "NegativeLogLikelihoodLoss", + "module": "ai.onnx", + "version": 13, + "support_level": "common", + "description": "A NegativeLogLikelihoodLoss operator computes (weighted) negative log likelihood loss.\nIts \"input\" tensor has the shape of (N, C, d1, d2, ..., dk) where k >= 0.\nThe \"input\" tensor contains log-probabilities for input[n, :, d_1, d_2,..., d_k] being in a class of [0, C).\nThe operator's \"target\" input tensor has the shape of (N, d1, d2, ..., dk). It encodes class labels (one of C classes)\nor it may contain a special value (indicated by an attribute ignore_index) for N x d1 x d2 x ... x dk samples.\nThe 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:\n\n loss[n][d_1][d_2]...[d_k] = -input[n][c][d_1][d_2]...[d_k].\n\nWhen an optional \"weight\" is provided, the sample loss is calculated as:\n\n loss[n][d_1][d_2]...[d_k] = -input[n][c][d_1][d_2]...[d_k] * weight[c].\n\nloss is zero for the case when target-value equals ignore_index.\n\n loss[n][d_1][d_2]...[d_k] = 0, when target[n][d_1][d_2]...[d_k] = ignore_index\n\nIf \"reduction\" attribute is set to \"none\", the operator's output will be the above loss with shape (N, d1, d2, ..., dk).\nIf \"reduction\" attribute is set to \"mean\" (the default attribute value), the output loss is (weight) averaged:\n\n mean(loss), if \"weight\" is not provided,\n\nor if weight is provided,\n\n sum(loss) / sum(weight[target[n][d_1][d_2]...[d_k]]]), for all samples.\n\nIf \"reduction\" attribute is set to \"sum\", the output is a scalar:\n sum(loss).\n\nSee also https://pytorch.org/docs/stable/nn.html#torch.nn.NLLLoss.\n\nExample 1:\n\n // negative log likelihood loss, \"none\" reduction\n N, C, d1 = 2, 3, 2\n input = [[[1.0, 2.0], [2.0, 2.0], [3.0, 2.0]],\n [[0.0, 1.0], [2.0, 2.0], [1.0, 2]]]\n target = [[2, 1], [0, 2]]\n\n loss = np.zeros((N, d1))\n for n in range(N):\n for d_1 in range(d1):\n c = target[n][d_1]\n loss[n][d_1] = -input[n][c][d_1]\n\n // print(loss)\n // [[-3. -2.]\n // [-0. -2.]]\n\nExample 2:\n\n // weighted negative log likelihood loss, sum reduction\n N, C, d1 = 2, 3, 2\n input = [[[1.0, 2.0], [2.0, 2.0], [3.0, 2.0]],\n [[0.0, 1.0], [2.0, 2.0], [1.0, 2]]]\n target = [[2, 1], [0, 2]]\n weight = [0.2, 0.3, 0.1]\n loss = np.zeros((N, d1))\n for n in range(N):\n for d_1 in range(d1):\n c = target[n][d_1]\n loss[n][d_1] = -input[n][c][d_1] * weight[c]\n\n loss = np.sum(loss)\n // print(loss)\n // -1.1\n\nExample 3:\n\n // weighted negative log likelihood loss, mean reduction\n N, C, d1 = 2, 3, 2\n input = [[[1.0, 2.0], [2.0, 2.0], [3.0, 2.0]],\n [[0.0, 1.0], [2.0, 2.0], [1.0, 2]]]\n target = [[2, 1], [0, 2]]\n weight = [0.2, 0.3, 0.1]\n loss = np.zeros((N, d1))\n weight_total = 0\n for n in range(N):\n for d_1 in range(d1):\n c = target[n][d_1]\n loss[n][d_1] = -input[n][c][d_1] * weight[c]\n weight_total = weight_total + weight[c]\n\n loss = np.sum(loss) / weight_total\n // print(loss)\n // -1.57\n", + "attributes": [ + { + "name": "ignore_index", + "type": "int64", + "required": false, + "description": "Specifies a target value that is ignored and does not contribute to the input gradient. It's an optional value." + }, + { + "name": "reduction", + "type": "string", + "required": false, + "default": "mean", + "description": "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": [ + { + "name": "input", + "type": "T", + "description": "Input tensor of shape (N, C) or (N, C, d1, d2, ..., dk)." + }, + { + "name": "target", + "type": "Tind", + "description": "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." + }, + { + "name": "weight", + "type": "T", + "option": "optional", + "description": "Optional rescaling weight tensor. If given, it has to be a tensor of size C. Otherwise, it is treated as if having all ones." + } + ], + "min_input": 2, + "max_input": 3, + "outputs": [ + { + "name": "loss", + "type": "T", + "description": "The negative log likelihood loss" + } + ], + "min_output": 1, + "max_output": 1, + "inputs_range": "2 - 3", + "type_constraints": [ + { + "description": "Constrain input, weight, and output types to floating-point tensors.", + "type_param_str": "T", + "allowed_type_strs": [ + "tensor(float16)", + "tensor(float)", + "tensor(double)" + ] + }, + { + "description": "Constrain target to integer types", + "type_param_str": "Tind", + "allowed_type_strs": [ + "tensor(int32)", + "tensor(int64)" + ] + } + ], + "examples": [ + { + "summary": "input_shape_is_NC", + "code": "reduction = 'none'\nnode = onnx.helper.make_node(\n 'NegativeLogLikelihoodLoss',\n inputs=['input', 'target'],\n outputs=['loss'],\n reduction=reduction\n)\n\nN, C = 3, 5\nnp.random.seed(0)\ninput = np.random.rand(N, C).astype(np.float32)\ntarget = np.random.randint(0, high=C, size=(N, )).astype(np.int64)\n\nnegative_log_likelihood_loss = compute_negative_log_likelihood_loss(input, target, weight=None, reduction=reduction)\n\nexpect(node, inputs=[input, target], outputs=[negative_log_likelihood_loss],\n name='test_nllloss_NC')" + }, + { + "summary": "input_shape_is_NCd1", + "code": "reduction = 'mean'\nnode = onnx.helper.make_node(\n 'NegativeLogLikelihoodLoss',\n inputs=['input', 'target'],\n outputs=['loss'],\n reduction=reduction\n)\n\nN, C, d1 = 3, 5, 2\nnp.random.seed(0)\ninput = np.random.rand(N, C, d1).astype(np.float32)\ntarget = np.random.randint(0, high=C, size=(N, d1)).astype(np.int64)\n\nnegative_log_likelihood_loss = compute_negative_log_likelihood_loss(input, target, weight=None, reduction=reduction)\n\nexpect(node, inputs=[input, target], outputs=[negative_log_likelihood_loss],\n name='test_nllloss_NCd1')" + }, + { + "summary": "input_shape_is_NCd1_ii", + "code": "reduction = 'mean'\nignore_index = np.int64(1)\nnode = onnx.helper.make_node(\n 'NegativeLogLikelihoodLoss',\n inputs=['input', 'target'],\n outputs=['loss'],\n reduction=reduction,\n ignore_index=ignore_index\n)\n\nN, C, d1 = 3, 5, 2\nnp.random.seed(0)\ninput = np.random.rand(N, C, d1).astype(np.float32)\ntarget = np.random.randint(0, high=C, size=(N, d1)).astype(np.int64)\ntarget[0][0] = np.int64(1)\n\nnegative_log_likelihood_loss = compute_negative_log_likelihood_loss(input, target, weight=None, reduction=reduction, ignore_index=ignore_index)\n\nexpect(node, inputs=[input, target], outputs=[negative_log_likelihood_loss],\n name='test_nllloss_NCd1_ii')" + }, + { + "summary": "input_shape_is_NCd1_mean_weight_negative_ii", + "code": "reduction = 'mean'\nignore_index = np.int64(-1)\n\nnode = onnx.helper.make_node(\n 'NegativeLogLikelihoodLoss',\n inputs=['input', 'target', 'weight'],\n outputs=['loss'],\n reduction=reduction,\n ignore_index=ignore_index)\n\nN, C, dim1 = 3, 5, 6\nnp.random.seed(0)\ninput = np.random.rand(N, C, dim1).astype(np.float32)\ntarget = np.random.randint(0, high=C, size=(N, dim1)).astype(np.int64)\ntarget[0][0] = -1\nweight = np.random.rand(C).astype(np.float32)\n\nnegative_log_likelihood_loss = compute_negative_log_likelihood_loss(input,\n target,\n weight=weight,\n reduction=reduction,\n ignore_index=ignore_index)\n\nexpect(node, inputs=[input, target, weight], outputs=[negative_log_likelihood_loss],\n name='test_nllloss_NCd1_mean_weight_negative_ii')" + }, + { + "summary": "input_shape_is_NCd1_weight", + "code": "reduction = 'mean'\nnode = onnx.helper.make_node(\n 'NegativeLogLikelihoodLoss',\n inputs=['input', 'target', 'weight'],\n outputs=['loss'],\n reduction=reduction\n)\n\nN, C, d1 = 3, 5, 2\nnp.random.seed(0)\ninput = np.random.rand(N, C, d1).astype(np.float32)\ntarget = np.random.randint(0, high=C, size=(N, d1)).astype(np.int64)\nweight = np.random.rand(C).astype(np.float32)\n\nnegative_log_likelihood_loss = compute_negative_log_likelihood_loss(input, target, weight=weight, reduction=reduction)\n\nexpect(node, inputs=[input, target, weight], outputs=[negative_log_likelihood_loss],\n name='test_nllloss_NCd1_weight')" + }, + { + "summary": "input_shape_is_NCd1_weight_ii", + "code": "reduction = 'mean'\nignore_index = np.int64(1)\nnode = onnx.helper.make_node(\n 'NegativeLogLikelihoodLoss',\n inputs=['input', 'target', 'weight'],\n outputs=['loss'],\n reduction=reduction,\n ignore_index=ignore_index\n)\n\nN, C, d1 = 3, 5, 2\nnp.random.seed(0)\ninput = np.random.rand(N, C, d1).astype(np.float32)\ntarget = np.random.randint(0, high=C, size=(N, d1)).astype(np.int64)\ntarget[0][0] = np.int64(1)\nweight = np.random.rand(C).astype(np.float32)\n\nnegative_log_likelihood_loss = compute_negative_log_likelihood_loss(input, target, weight=weight, reduction=reduction, ignore_index=ignore_index)\n\nexpect(node, inputs=[input, target, weight], outputs=[negative_log_likelihood_loss],\n name='test_nllloss_NCd1_weight_ii')" + }, + { + "summary": "input_shape_is_NCd1d2", + "code": "reduction = 'none'\nnode = onnx.helper.make_node(\n 'NegativeLogLikelihoodLoss',\n inputs=['input', 'target'],\n outputs=['loss'],\n reduction=reduction\n)\n\nN, C, dim1, dim2 = 3, 5, 6, 6\nnp.random.seed(0)\ninput = np.random.rand(N, C, dim1, dim2).astype(np.float32)\ntarget = np.random.randint(0, high=C, size=(N, dim1, dim2)).astype(np.int64)\n\nnegative_log_likelihood_loss = compute_negative_log_likelihood_loss(input, target, weight=None, reduction=reduction)\n\nexpect(node, inputs=[input, target], outputs=[negative_log_likelihood_loss],\n name='test_nllloss_NCd1d2')" + }, + { + "summary": "input_shape_is_NCd1d2_no_weight_reduction_mean_ii", + "code": "reduction = 'mean'\nignore_index = np.int64(1)\nnode = onnx.helper.make_node(\n 'NegativeLogLikelihoodLoss',\n inputs=['input', 'target'],\n outputs=['loss'],\n reduction=reduction,\n ignore_index=ignore_index\n)\n\nN, C, dim1, dim2 = 3, 5, 6, 6\nnp.random.seed(0)\ninput = np.random.rand(N, C, dim1, dim2).astype(np.float32)\ntarget = np.random.randint(0, high=C, size=(N, dim1, dim2)).astype(np.int64)\ntarget[0][0][0] = np.int64(1)\n\nnegative_log_likelihood_loss = compute_negative_log_likelihood_loss(input, target, reduction=reduction, ignore_index=ignore_index)\n\nexpect(node, inputs=[input, target], outputs=[negative_log_likelihood_loss],\n name='test_nllloss_NCd1d2_no_weight_reduction_mean_ii')" + }, + { + "summary": "input_shape_is_NCd1d2_reduction_mean", + "code": "reduction = 'mean'\nnode = onnx.helper.make_node(\n 'NegativeLogLikelihoodLoss',\n inputs=['input', 'target'],\n outputs=['loss'],\n reduction=reduction\n)\n\nN, C, dim1, dim2 = 3, 5, 6, 6\nnp.random.seed(0)\ninput = np.random.rand(N, C, dim1, dim2).astype(np.float32)\ntarget = np.random.randint(0, high=C, size=(N, dim1, dim2)).astype(np.int64)\n\nnegative_log_likelihood_loss = compute_negative_log_likelihood_loss(input, target, weight=None, reduction=reduction)\n\nexpect(node, inputs=[input, target], outputs=[negative_log_likelihood_loss],\n name='test_nllloss_NCd1d2_reduction_mean')" + }, + { + "summary": "input_shape_is_NCd1d2_reduction_sum", + "code": "reduction = 'sum'\nnode = onnx.helper.make_node(\n 'NegativeLogLikelihoodLoss',\n inputs=['input', 'target'],\n outputs=['loss'],\n reduction=reduction\n)\n\nN, C, dim1, dim2 = 3, 5, 6, 6\nnp.random.seed(0)\ninput = np.random.rand(N, C, dim1, dim2).astype(np.float32)\ntarget = np.random.randint(0, high=C, size=(N, dim1, dim2))\n\nnegative_log_likelihood_loss = compute_negative_log_likelihood_loss(input, target, weight=None, reduction=reduction)\n\nexpect(node, inputs=[input, target], outputs=[negative_log_likelihood_loss],\n name='test_nllloss_NCd1d2_reduction_sum')" + }, + { + "summary": "input_shape_is_NCd1d2_with_weight", + "code": "reduction = 'none'\nnode = onnx.helper.make_node(\n 'NegativeLogLikelihoodLoss',\n inputs=['input', 'target', 'weight'],\n outputs=['loss'],\n reduction=reduction\n)\n\nN, C, dim1, dim2 = 3, 5, 6, 6\nnp.random.seed(0)\ninput = np.random.rand(N, C, dim1, dim2).astype(np.float32)\ntarget = np.random.randint(0, high=C, size=(N, dim1, dim2)).astype(np.int64)\nweight = np.random.rand(C).astype(np.float32)\n\nnegative_log_likelihood_loss = compute_negative_log_likelihood_loss(input, target, weight=weight, reduction=reduction)\n\nexpect(node, inputs=[input, target, weight], outputs=[negative_log_likelihood_loss],\n name='test_nllloss_NCd1d2_with_weight')" + }, + { + "summary": "input_shape_is_NCd1d2_with_weight_reduction_mean", + "code": "reduction = 'mean'\nnode = onnx.helper.make_node(\n 'NegativeLogLikelihoodLoss',\n inputs=['input', 'target', 'weight'],\n outputs=['loss'],\n reduction=reduction\n)\n\nN, C, dim1, dim2 = 3, 5, 6, 6\nnp.random.seed(0)\ninput = np.random.rand(N, C, dim1, dim2).astype(np.float32)\ntarget = np.random.randint(0, high=C, size=(N, dim1, dim2)).astype(np.int64)\nweight = np.random.rand(C).astype(np.float32)\n\nnegative_log_likelihood_loss = compute_negative_log_likelihood_loss(input, target, weight=weight, reduction=reduction)\n\nexpect(node, inputs=[input, target, weight], outputs=[negative_log_likelihood_loss],\n name='test_nllloss_NCd1d2_with_weight_reduction_mean')" + }, + { + "summary": "input_shape_is_NCd1d2_with_weight_reduction_sum", + "code": "reduction = 'sum'\nnode = onnx.helper.make_node(\n 'NegativeLogLikelihoodLoss',\n inputs=['input', 'target', 'weight'],\n outputs=['loss'],\n reduction=reduction\n)\n\nN, C, dim1, dim2 = 3, 5, 6, 6\nnp.random.seed(0)\ninput = np.random.rand(N, C, dim1, dim2).astype(np.float32)\ntarget = np.random.randint(0, high=C, size=(N, dim1, dim2)).astype(np.int64)\nweight = np.random.rand(C).astype(np.float32)\n\nnegative_log_likelihood_loss = compute_negative_log_likelihood_loss(input, target, weight=weight, reduction=reduction)\n\nexpect(node, inputs=[input, target, weight], outputs=[negative_log_likelihood_loss],\n name='test_nllloss_NCd1d2_with_weight_reduction_sum')" + }, + { + "summary": "input_shape_is_NCd1d2_with_weight_reduction_sum_ii", + "code": "reduction = 'sum'\nignore_index = np.int64(0)\nnode = onnx.helper.make_node(\n 'NegativeLogLikelihoodLoss',\n inputs=['input', 'target', 'weight'],\n outputs=['loss'],\n reduction=reduction,\n ignore_index=ignore_index\n)\n\nN, C, dim1, dim2 = 3, 5, 6, 6\nnp.random.seed(0)\ninput = np.random.rand(N, C, dim1, dim2).astype(np.float32)\ntarget = np.random.randint(0, high=C, size=(N, dim1, dim2)).astype(np.int64)\ntarget[0][0][0] = np.int64(0)\nweight = np.random.rand(C).astype(np.float32)\n\nnegative_log_likelihood_loss = compute_negative_log_likelihood_loss(input, target, weight=weight, reduction=reduction, ignore_index=ignore_index)\n\nexpect(node, inputs=[input, target, weight], outputs=[negative_log_likelihood_loss],\n name='test_nllloss_NCd1d2_with_weight_reduction_sum_ii')" + }, + { + "summary": "input_shape_is_NCd1d2d3_none_no_weight_negative_ii", + "code": "reduction = 'none'\nignore_index = np.int64(-5)\n\nnode = onnx.helper.make_node(\n 'NegativeLogLikelihoodLoss',\n inputs=['input', 'target'],\n outputs=['loss'],\n reduction=reduction,\n ignore_index=ignore_index)\n\nN, C, dim1, dim2, dim3 = 3, 5, 6, 6, 5\nnp.random.seed(0)\ninput = np.random.rand(N, C, dim1, dim2, dim3).astype(np.float32)\ntarget = np.random.randint(0, high=C, size=(N, dim1, dim2, dim3)).astype(np.int64)\ntarget[0][0][0][0] = -5\n\nnegative_log_likelihood_loss = compute_negative_log_likelihood_loss(input,\n target,\n reduction=reduction,\n ignore_index=ignore_index)\n\nexpect(node, inputs=[input, target], outputs=[negative_log_likelihood_loss],\n name='test_nllloss_NCd1d2d3_none_no_weight_negative_ii')" + }, + { + "summary": "input_shape_is_NCd1d2d3_sum_weight_high_ii", + "code": "reduction = 'sum'\nignore_index = np.int64(10)\n\nnode = onnx.helper.make_node(\n 'NegativeLogLikelihoodLoss',\n inputs=['input', 'target', 'weight'],\n outputs=['loss'],\n reduction=reduction,\n ignore_index=ignore_index)\n\nN, C = 3, 5\nnp.random.seed(0)\ninput = np.random.rand(N, C).astype(np.float32)\ntarget = np.random.randint(0, high=C, size=(N))\ntarget[0] = 10\nweight = np.random.rand(C).astype(np.float32)\n\nnegative_log_likelihood_loss = compute_negative_log_likelihood_loss(input,\n target,\n weight=weight,\n reduction=reduction,\n ignore_index=ignore_index)\n\nexpect(node, inputs=[input, target, weight], outputs=[negative_log_likelihood_loss],\n name='test_nllloss_NCd1d2d3_sum_weight_high_ii')" + }, + { + "summary": "input_shape_is_NCd1d2d3d4d5_mean_weight", + "code": "reduction = 'mean'\n\nnode = onnx.helper.make_node(\n 'NegativeLogLikelihoodLoss',\n inputs=['input', 'target', 'weight'],\n outputs=['loss'],\n reduction=reduction)\n\nN, C, dim1, dim2, dim3, dim4, dim5 = 3, 5, 6, 6, 5, 3, 4\nnp.random.seed(0)\ninput = np.random.rand(N, C, dim1, dim2, dim3, dim4, dim5).astype(np.float32)\ntarget = np.random.randint(0, high=C, size=(N, dim1, dim2, dim3, dim4, dim5)).astype(np.int64)\nweight = np.random.rand(C).astype(np.float32)\n\nnegative_log_likelihood_loss = compute_negative_log_likelihood_loss(input,\n target,\n weight=weight,\n reduction=reduction)\n\nexpect(node, inputs=[input, target, weight], outputs=[negative_log_likelihood_loss],\n name='test_nllloss_NCd1d2d3d4d5_mean_weight')" + }, + { + "summary": "input_shape_is_NCd1d2d3d4d5_none_no_weight", + "code": "reduction = 'none'\n\nnode = onnx.helper.make_node(\n 'NegativeLogLikelihoodLoss',\n inputs=['input', 'target'],\n outputs=['loss'],\n reduction=reduction)\n\nN, C, dim1, dim2, dim3, dim4, dim5 = 3, 5, 6, 6, 5, 3, 4\nnp.random.seed(0)\ninput = np.random.rand(N, C, dim1, dim2, dim3, dim4, dim5).astype(np.float32)\ntarget = np.random.randint(0, high=C, size=(N, dim1, dim2, dim3, dim4, dim5)).astype(np.int64)\n\nnegative_log_likelihood_loss = compute_negative_log_likelihood_loss(input,\n target,\n reduction=reduction)\n\nexpect(node, inputs=[input, target], outputs=[negative_log_likelihood_loss],\n name='test_nllloss_NCd1d2d3d4d5_none_no_weight')" + } + ] + }, + { + "name": "NonMaxSuppression", + "module": "ai.onnx", + "version": 10, + "support_level": "common", + "description": "Filter out boxes that have high intersection-over-union (IOU) overlap with previously selected boxes.\nBounding boxes with score less than score_threshold are removed. Bounding box format is indicated by attribute center_point_box.\nNote that this algorithm is agnostic to where the origin is in the coordinate system and more generally is invariant to\northogonal transformations and translations of the coordinate system; thus translating or reflections of the coordinate system\nresult in the same boxes being selected by the algorithm.\nThe selected_indices output is a set of integers indexing into the input collection of bounding boxes representing the selected boxes.\nThe bounding box coordinates corresponding to the selected indices can then be obtained using the Gather or GatherND operation.\n", + "attributes": [ + { + "name": "center_point_box", + "type": "int64", + "required": false, + "description": "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": [ + { + "name": "boxes", + "type": "tensor(float)", + "description": "An input tensor with shape [num_batches, spatial_dimension, 4]. The single box data format is indicated by center_point_box." + }, + { + "name": "scores", + "type": "tensor(float)", + "description": "An input tensor with shape [num_batches, num_classes, spatial_dimension]" + }, + { + "name": "max_output_boxes_per_class", + "type": "tensor(int64)", + "option": "optional", + "description": "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." + }, + { + "name": "iou_threshold", + "type": "tensor(float)", + "option": "optional", + "description": "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." + }, + { + "name": "score_threshold", + "type": "tensor(float)", + "option": "optional", + "description": "Float representing the threshold for deciding when to remove boxes based on score. It is a scalar." + } + ], + "min_input": 2, + "max_input": 5, + "outputs": [ + { + "name": "selected_indices", + "type": "tensor(int64)", + "description": "selected indices from the boxes tensor. [num_selected_indices, 3], the selected index format is [batch_index, class_index, box_index]." + } + ], + "min_output": 1, + "max_output": 1, + "inputs_range": "2 - 5", + "examples": [ + { + "summary": "nonmaxsuppression_center_point_box_format", + "code": "node = onnx.helper.make_node(\n 'NonMaxSuppression',\n inputs=['boxes', 'scores', 'max_output_boxes_per_class', 'iou_threshold', 'score_threshold'],\n outputs=['selected_indices'],\n center_point_box=1\n)\nboxes = np.array([[\n [0.5, 0.5, 1.0, 1.0],\n [0.5, 0.6, 1.0, 1.0],\n [0.5, 0.4, 1.0, 1.0],\n [0.5, 10.5, 1.0, 1.0],\n [0.5, 10.6, 1.0, 1.0],\n [0.5, 100.5, 1.0, 1.0]\n]]).astype(np.float32)\nscores = np.array([[[0.9, 0.75, 0.6, 0.95, 0.5, 0.3]]]).astype(np.float32)\nmax_output_boxes_per_class = np.array([3]).astype(np.int64)\niou_threshold = np.array([0.5]).astype(np.float32)\nscore_threshold = np.array([0.0]).astype(np.float32)\nselected_indices = np.array([[0, 0, 3], [0, 0, 0], [0, 0, 5]]).astype(np.int64)\n\nexpect(node, inputs=[boxes, scores, max_output_boxes_per_class, iou_threshold, score_threshold], outputs=[selected_indices], name='test_nonmaxsuppression_center_point_box_format')" + }, + { + "summary": "nonmaxsuppression_flipped_coordinates", + "code": "node = onnx.helper.make_node(\n 'NonMaxSuppression',\n inputs=['boxes', 'scores', 'max_output_boxes_per_class', 'iou_threshold', 'score_threshold'],\n outputs=['selected_indices']\n)\nboxes = np.array([[\n [1.0, 1.0, 0.0, 0.0],\n [0.0, 0.1, 1.0, 1.1],\n [0.0, 0.9, 1.0, -0.1],\n [0.0, 10.0, 1.0, 11.0],\n [1.0, 10.1, 0.0, 11.1],\n [1.0, 101.0, 0.0, 100.0]\n]]).astype(np.float32)\nscores = np.array([[[0.9, 0.75, 0.6, 0.95, 0.5, 0.3]]]).astype(np.float32)\nmax_output_boxes_per_class = np.array([3]).astype(np.int64)\niou_threshold = np.array([0.5]).astype(np.float32)\nscore_threshold = np.array([0.0]).astype(np.float32)\nselected_indices = np.array([[0, 0, 3], [0, 0, 0], [0, 0, 5]]).astype(np.int64)\n\nexpect(node, inputs=[boxes, scores, max_output_boxes_per_class, iou_threshold, score_threshold], outputs=[selected_indices], name='test_nonmaxsuppression_flipped_coordinates')" + }, + { + "summary": "nonmaxsuppression_identical_boxes", + "code": "node = onnx.helper.make_node(\n 'NonMaxSuppression',\n inputs=['boxes', 'scores', 'max_output_boxes_per_class', 'iou_threshold', 'score_threshold'],\n outputs=['selected_indices']\n)\nboxes = np.array([[\n [0.0, 0.0, 1.0, 1.0],\n [0.0, 0.0, 1.0, 1.0],\n [0.0, 0.0, 1.0, 1.0],\n [0.0, 0.0, 1.0, 1.0],\n [0.0, 0.0, 1.0, 1.0],\n\n [0.0, 0.0, 1.0, 1.0],\n [0.0, 0.0, 1.0, 1.0],\n [0.0, 0.0, 1.0, 1.0],\n [0.0, 0.0, 1.0, 1.0],\n [0.0, 0.0, 1.0, 1.0]\n]]).astype(np.float32)\nscores = 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)\nmax_output_boxes_per_class = np.array([3]).astype(np.int64)\niou_threshold = np.array([0.5]).astype(np.float32)\nscore_threshold = np.array([0.0]).astype(np.float32)\nselected_indices = np.array([[0, 0, 0]]).astype(np.int64)\n\nexpect(node, inputs=[boxes, scores, max_output_boxes_per_class, iou_threshold, score_threshold], outputs=[selected_indices], name='test_nonmaxsuppression_identical_boxes')" + }, + { + "summary": "nonmaxsuppression_limit_output_size", + "code": "node = onnx.helper.make_node(\n 'NonMaxSuppression',\n inputs=['boxes', 'scores', 'max_output_boxes_per_class', 'iou_threshold', 'score_threshold'],\n outputs=['selected_indices']\n)\nboxes = np.array([[\n [0.0, 0.0, 1.0, 1.0],\n [0.0, 0.1, 1.0, 1.1],\n [0.0, -0.1, 1.0, 0.9],\n [0.0, 10.0, 1.0, 11.0],\n [0.0, 10.1, 1.0, 11.1],\n [0.0, 100.0, 1.0, 101.0]\n]]).astype(np.float32)\nscores = np.array([[[0.9, 0.75, 0.6, 0.95, 0.5, 0.3]]]).astype(np.float32)\nmax_output_boxes_per_class = np.array([2]).astype(np.int64)\niou_threshold = np.array([0.5]).astype(np.float32)\nscore_threshold = np.array([0.0]).astype(np.float32)\nselected_indices = np.array([[0, 0, 3], [0, 0, 0]]).astype(np.int64)\n\nexpect(node, inputs=[boxes, scores, max_output_boxes_per_class, iou_threshold, score_threshold], outputs=[selected_indices], name='test_nonmaxsuppression_limit_output_size')" + }, + { + "summary": "nonmaxsuppression_single_box", + "code": "node = onnx.helper.make_node(\n 'NonMaxSuppression',\n inputs=['boxes', 'scores', 'max_output_boxes_per_class', 'iou_threshold', 'score_threshold'],\n outputs=['selected_indices']\n)\nboxes = np.array([[\n [0.0, 0.0, 1.0, 1.0]\n]]).astype(np.float32)\nscores = np.array([[[0.9]]]).astype(np.float32)\nmax_output_boxes_per_class = np.array([3]).astype(np.int64)\niou_threshold = np.array([0.5]).astype(np.float32)\nscore_threshold = np.array([0.0]).astype(np.float32)\nselected_indices = np.array([[0, 0, 0]]).astype(np.int64)\n\nexpect(node, inputs=[boxes, scores, max_output_boxes_per_class, iou_threshold, score_threshold], outputs=[selected_indices], name='test_nonmaxsuppression_single_box')" + }, + { + "summary": "nonmaxsuppression_suppress_by_IOU", + "code": "node = onnx.helper.make_node(\n 'NonMaxSuppression',\n inputs=['boxes', 'scores', 'max_output_boxes_per_class', 'iou_threshold', 'score_threshold'],\n outputs=['selected_indices']\n)\nboxes = np.array([[\n [0.0, 0.0, 1.0, 1.0],\n [0.0, 0.1, 1.0, 1.1],\n [0.0, -0.1, 1.0, 0.9],\n [0.0, 10.0, 1.0, 11.0],\n [0.0, 10.1, 1.0, 11.1],\n [0.0, 100.0, 1.0, 101.0]\n]]).astype(np.float32)\nscores = np.array([[[0.9, 0.75, 0.6, 0.95, 0.5, 0.3]]]).astype(np.float32)\nmax_output_boxes_per_class = np.array([3]).astype(np.int64)\niou_threshold = np.array([0.5]).astype(np.float32)\nscore_threshold = np.array([0.0]).astype(np.float32)\nselected_indices = np.array([[0, 0, 3], [0, 0, 0], [0, 0, 5]]).astype(np.int64)\n\nexpect(node, inputs=[boxes, scores, max_output_boxes_per_class, iou_threshold, score_threshold], outputs=[selected_indices], name='test_nonmaxsuppression_suppress_by_IOU')" + }, + { + "summary": "nonmaxsuppression_suppress_by_IOU_and_scores", + "code": "node = onnx.helper.make_node(\n 'NonMaxSuppression',\n inputs=['boxes', 'scores', 'max_output_boxes_per_class', 'iou_threshold', 'score_threshold'],\n outputs=['selected_indices']\n)\nboxes = np.array([[\n [0.0, 0.0, 1.0, 1.0],\n [0.0, 0.1, 1.0, 1.1],\n [0.0, -0.1, 1.0, 0.9],\n [0.0, 10.0, 1.0, 11.0],\n [0.0, 10.1, 1.0, 11.1],\n [0.0, 100.0, 1.0, 101.0]\n]]).astype(np.float32)\nscores = np.array([[[0.9, 0.75, 0.6, 0.95, 0.5, 0.3]]]).astype(np.float32)\nmax_output_boxes_per_class = np.array([3]).astype(np.int64)\niou_threshold = np.array([0.5]).astype(np.float32)\nscore_threshold = np.array([0.4]).astype(np.float32)\nselected_indices = np.array([[0, 0, 3], [0, 0, 0]]).astype(np.int64)\n\nexpect(node, inputs=[boxes, scores, max_output_boxes_per_class, iou_threshold, score_threshold], outputs=[selected_indices], name='test_nonmaxsuppression_suppress_by_IOU_and_scores')" + }, + { + "summary": "nonmaxsuppression_two_batches", + "code": "node = onnx.helper.make_node(\n 'NonMaxSuppression',\n inputs=['boxes', 'scores', 'max_output_boxes_per_class', 'iou_threshold', 'score_threshold'],\n outputs=['selected_indices']\n)\nboxes = np.array([[[0.0, 0.0, 1.0, 1.0],\n [0.0, 0.1, 1.0, 1.1],\n [0.0, -0.1, 1.0, 0.9],\n [0.0, 10.0, 1.0, 11.0],\n [0.0, 10.1, 1.0, 11.1],\n [0.0, 100.0, 1.0, 101.0]],\n [[0.0, 0.0, 1.0, 1.0],\n [0.0, 0.1, 1.0, 1.1],\n [0.0, -0.1, 1.0, 0.9],\n [0.0, 10.0, 1.0, 11.0],\n [0.0, 10.1, 1.0, 11.1],\n [0.0, 100.0, 1.0, 101.0]]]).astype(np.float32)\nscores = np.array([[[0.9, 0.75, 0.6, 0.95, 0.5, 0.3]],\n [[0.9, 0.75, 0.6, 0.95, 0.5, 0.3]]]).astype(np.float32)\nmax_output_boxes_per_class = np.array([2]).astype(np.int64)\niou_threshold = np.array([0.5]).astype(np.float32)\nscore_threshold = np.array([0.0]).astype(np.float32)\nselected_indices = np.array([[0, 0, 3], [0, 0, 0], [1, 0, 3], [1, 0, 0]]).astype(np.int64)\n\nexpect(node, inputs=[boxes, scores, max_output_boxes_per_class, iou_threshold, score_threshold], outputs=[selected_indices], name='test_nonmaxsuppression_two_batches')" + }, + { + "summary": "nonmaxsuppression_two_classes", + "code": "node = onnx.helper.make_node(\n 'NonMaxSuppression',\n inputs=['boxes', 'scores', 'max_output_boxes_per_class', 'iou_threshold', 'score_threshold'],\n outputs=['selected_indices']\n)\nboxes = np.array([[\n [0.0, 0.0, 1.0, 1.0],\n [0.0, 0.1, 1.0, 1.1],\n [0.0, -0.1, 1.0, 0.9],\n [0.0, 10.0, 1.0, 11.0],\n [0.0, 10.1, 1.0, 11.1],\n [0.0, 100.0, 1.0, 101.0]\n]]).astype(np.float32)\nscores = np.array([[[0.9, 0.75, 0.6, 0.95, 0.5, 0.3],\n [0.9, 0.75, 0.6, 0.95, 0.5, 0.3]]]).astype(np.float32)\nmax_output_boxes_per_class = np.array([2]).astype(np.int64)\niou_threshold = np.array([0.5]).astype(np.float32)\nscore_threshold = np.array([0.0]).astype(np.float32)\nselected_indices = np.array([[0, 0, 3], [0, 0, 0], [0, 1, 3], [0, 1, 0]]).astype(np.int64)\n\nexpect(node, inputs=[boxes, scores, max_output_boxes_per_class, iou_threshold, score_threshold], outputs=[selected_indices], name='test_nonmaxsuppression_two_classes')" + } + ] + }, + { + "name": "NonMaxSuppression", + "module": "ai.onnx", + "version": 11, + "support_level": "common", + "description": "Filter out boxes that have high intersection-over-union (IOU) overlap with previously selected boxes.\nBounding boxes with score less than score_threshold are removed. Bounding box format is indicated by attribute center_point_box.\nNote that this algorithm is agnostic to where the origin is in the coordinate system and more generally is invariant to\northogonal transformations and translations of the coordinate system; thus translating or reflections of the coordinate system\nresult in the same boxes being selected by the algorithm.\nThe selected_indices output is a set of integers indexing into the input collection of bounding boxes representing the selected boxes.\nThe bounding box coordinates corresponding to the selected indices can then be obtained using the Gather or GatherND operation.\n", + "attributes": [ + { + "name": "center_point_box", + "type": "int64", + "required": false, + "description": "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": [ + { + "name": "boxes", + "type": "tensor(float)", + "description": "An input tensor with shape [num_batches, spatial_dimension, 4]. The single box data format is indicated by center_point_box." + }, + { + "name": "scores", + "type": "tensor(float)", + "description": "An input tensor with shape [num_batches, num_classes, spatial_dimension]" + }, + { + "name": "max_output_boxes_per_class", + "type": "tensor(int64)", + "option": "optional", + "description": "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." + }, + { + "name": "iou_threshold", + "type": "tensor(float)", + "option": "optional", + "description": "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." + }, + { + "name": "score_threshold", + "type": "tensor(float)", + "option": "optional", + "description": "Float representing the threshold for deciding when to remove boxes based on score. It is a scalar." + } + ], + "min_input": 2, + "max_input": 5, + "outputs": [ + { + "name": "selected_indices", + "type": "tensor(int64)", + "description": "selected indices from the boxes tensor. [num_selected_indices, 3], the selected index format is [batch_index, class_index, box_index]." + } + ], + "min_output": 1, + "max_output": 1, + "inputs_range": "2 - 5", + "examples": [ + { + "summary": "nonmaxsuppression_center_point_box_format", + "code": "node = onnx.helper.make_node(\n 'NonMaxSuppression',\n inputs=['boxes', 'scores', 'max_output_boxes_per_class', 'iou_threshold', 'score_threshold'],\n outputs=['selected_indices'],\n center_point_box=1\n)\nboxes = np.array([[\n [0.5, 0.5, 1.0, 1.0],\n [0.5, 0.6, 1.0, 1.0],\n [0.5, 0.4, 1.0, 1.0],\n [0.5, 10.5, 1.0, 1.0],\n [0.5, 10.6, 1.0, 1.0],\n [0.5, 100.5, 1.0, 1.0]\n]]).astype(np.float32)\nscores = np.array([[[0.9, 0.75, 0.6, 0.95, 0.5, 0.3]]]).astype(np.float32)\nmax_output_boxes_per_class = np.array([3]).astype(np.int64)\niou_threshold = np.array([0.5]).astype(np.float32)\nscore_threshold = np.array([0.0]).astype(np.float32)\nselected_indices = np.array([[0, 0, 3], [0, 0, 0], [0, 0, 5]]).astype(np.int64)\n\nexpect(node, inputs=[boxes, scores, max_output_boxes_per_class, iou_threshold, score_threshold], outputs=[selected_indices], name='test_nonmaxsuppression_center_point_box_format')" + }, + { + "summary": "nonmaxsuppression_flipped_coordinates", + "code": "node = onnx.helper.make_node(\n 'NonMaxSuppression',\n inputs=['boxes', 'scores', 'max_output_boxes_per_class', 'iou_threshold', 'score_threshold'],\n outputs=['selected_indices']\n)\nboxes = np.array([[\n [1.0, 1.0, 0.0, 0.0],\n [0.0, 0.1, 1.0, 1.1],\n [0.0, 0.9, 1.0, -0.1],\n [0.0, 10.0, 1.0, 11.0],\n [1.0, 10.1, 0.0, 11.1],\n [1.0, 101.0, 0.0, 100.0]\n]]).astype(np.float32)\nscores = np.array([[[0.9, 0.75, 0.6, 0.95, 0.5, 0.3]]]).astype(np.float32)\nmax_output_boxes_per_class = np.array([3]).astype(np.int64)\niou_threshold = np.array([0.5]).astype(np.float32)\nscore_threshold = np.array([0.0]).astype(np.float32)\nselected_indices = np.array([[0, 0, 3], [0, 0, 0], [0, 0, 5]]).astype(np.int64)\n\nexpect(node, inputs=[boxes, scores, max_output_boxes_per_class, iou_threshold, score_threshold], outputs=[selected_indices], name='test_nonmaxsuppression_flipped_coordinates')" + }, + { + "summary": "nonmaxsuppression_identical_boxes", + "code": "node = onnx.helper.make_node(\n 'NonMaxSuppression',\n inputs=['boxes', 'scores', 'max_output_boxes_per_class', 'iou_threshold', 'score_threshold'],\n outputs=['selected_indices']\n)\nboxes = np.array([[\n [0.0, 0.0, 1.0, 1.0],\n [0.0, 0.0, 1.0, 1.0],\n [0.0, 0.0, 1.0, 1.0],\n [0.0, 0.0, 1.0, 1.0],\n [0.0, 0.0, 1.0, 1.0],\n\n [0.0, 0.0, 1.0, 1.0],\n [0.0, 0.0, 1.0, 1.0],\n [0.0, 0.0, 1.0, 1.0],\n [0.0, 0.0, 1.0, 1.0],\n [0.0, 0.0, 1.0, 1.0]\n]]).astype(np.float32)\nscores = 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)\nmax_output_boxes_per_class = np.array([3]).astype(np.int64)\niou_threshold = np.array([0.5]).astype(np.float32)\nscore_threshold = np.array([0.0]).astype(np.float32)\nselected_indices = np.array([[0, 0, 0]]).astype(np.int64)\n\nexpect(node, inputs=[boxes, scores, max_output_boxes_per_class, iou_threshold, score_threshold], outputs=[selected_indices], name='test_nonmaxsuppression_identical_boxes')" + }, + { + "summary": "nonmaxsuppression_limit_output_size", + "code": "node = onnx.helper.make_node(\n 'NonMaxSuppression',\n inputs=['boxes', 'scores', 'max_output_boxes_per_class', 'iou_threshold', 'score_threshold'],\n outputs=['selected_indices']\n)\nboxes = np.array([[\n [0.0, 0.0, 1.0, 1.0],\n [0.0, 0.1, 1.0, 1.1],\n [0.0, -0.1, 1.0, 0.9],\n [0.0, 10.0, 1.0, 11.0],\n [0.0, 10.1, 1.0, 11.1],\n [0.0, 100.0, 1.0, 101.0]\n]]).astype(np.float32)\nscores = np.array([[[0.9, 0.75, 0.6, 0.95, 0.5, 0.3]]]).astype(np.float32)\nmax_output_boxes_per_class = np.array([2]).astype(np.int64)\niou_threshold = np.array([0.5]).astype(np.float32)\nscore_threshold = np.array([0.0]).astype(np.float32)\nselected_indices = np.array([[0, 0, 3], [0, 0, 0]]).astype(np.int64)\n\nexpect(node, inputs=[boxes, scores, max_output_boxes_per_class, iou_threshold, score_threshold], outputs=[selected_indices], name='test_nonmaxsuppression_limit_output_size')" + }, + { + "summary": "nonmaxsuppression_single_box", + "code": "node = onnx.helper.make_node(\n 'NonMaxSuppression',\n inputs=['boxes', 'scores', 'max_output_boxes_per_class', 'iou_threshold', 'score_threshold'],\n outputs=['selected_indices']\n)\nboxes = np.array([[\n [0.0, 0.0, 1.0, 1.0]\n]]).astype(np.float32)\nscores = np.array([[[0.9]]]).astype(np.float32)\nmax_output_boxes_per_class = np.array([3]).astype(np.int64)\niou_threshold = np.array([0.5]).astype(np.float32)\nscore_threshold = np.array([0.0]).astype(np.float32)\nselected_indices = np.array([[0, 0, 0]]).astype(np.int64)\n\nexpect(node, inputs=[boxes, scores, max_output_boxes_per_class, iou_threshold, score_threshold], outputs=[selected_indices], name='test_nonmaxsuppression_single_box')" + }, + { + "summary": "nonmaxsuppression_suppress_by_IOU", + "code": "node = onnx.helper.make_node(\n 'NonMaxSuppression',\n inputs=['boxes', 'scores', 'max_output_boxes_per_class', 'iou_threshold', 'score_threshold'],\n outputs=['selected_indices']\n)\nboxes = np.array([[\n [0.0, 0.0, 1.0, 1.0],\n [0.0, 0.1, 1.0, 1.1],\n [0.0, -0.1, 1.0, 0.9],\n [0.0, 10.0, 1.0, 11.0],\n [0.0, 10.1, 1.0, 11.1],\n [0.0, 100.0, 1.0, 101.0]\n]]).astype(np.float32)\nscores = np.array([[[0.9, 0.75, 0.6, 0.95, 0.5, 0.3]]]).astype(np.float32)\nmax_output_boxes_per_class = np.array([3]).astype(np.int64)\niou_threshold = np.array([0.5]).astype(np.float32)\nscore_threshold = np.array([0.0]).astype(np.float32)\nselected_indices = np.array([[0, 0, 3], [0, 0, 0], [0, 0, 5]]).astype(np.int64)\n\nexpect(node, inputs=[boxes, scores, max_output_boxes_per_class, iou_threshold, score_threshold], outputs=[selected_indices], name='test_nonmaxsuppression_suppress_by_IOU')" + }, + { + "summary": "nonmaxsuppression_suppress_by_IOU_and_scores", + "code": "node = onnx.helper.make_node(\n 'NonMaxSuppression',\n inputs=['boxes', 'scores', 'max_output_boxes_per_class', 'iou_threshold', 'score_threshold'],\n outputs=['selected_indices']\n)\nboxes = np.array([[\n [0.0, 0.0, 1.0, 1.0],\n [0.0, 0.1, 1.0, 1.1],\n [0.0, -0.1, 1.0, 0.9],\n [0.0, 10.0, 1.0, 11.0],\n [0.0, 10.1, 1.0, 11.1],\n [0.0, 100.0, 1.0, 101.0]\n]]).astype(np.float32)\nscores = np.array([[[0.9, 0.75, 0.6, 0.95, 0.5, 0.3]]]).astype(np.float32)\nmax_output_boxes_per_class = np.array([3]).astype(np.int64)\niou_threshold = np.array([0.5]).astype(np.float32)\nscore_threshold = np.array([0.4]).astype(np.float32)\nselected_indices = np.array([[0, 0, 3], [0, 0, 0]]).astype(np.int64)\n\nexpect(node, inputs=[boxes, scores, max_output_boxes_per_class, iou_threshold, score_threshold], outputs=[selected_indices], name='test_nonmaxsuppression_suppress_by_IOU_and_scores')" + }, + { + "summary": "nonmaxsuppression_two_batches", + "code": "node = onnx.helper.make_node(\n 'NonMaxSuppression',\n inputs=['boxes', 'scores', 'max_output_boxes_per_class', 'iou_threshold', 'score_threshold'],\n outputs=['selected_indices']\n)\nboxes = np.array([[[0.0, 0.0, 1.0, 1.0],\n [0.0, 0.1, 1.0, 1.1],\n [0.0, -0.1, 1.0, 0.9],\n [0.0, 10.0, 1.0, 11.0],\n [0.0, 10.1, 1.0, 11.1],\n [0.0, 100.0, 1.0, 101.0]],\n [[0.0, 0.0, 1.0, 1.0],\n [0.0, 0.1, 1.0, 1.1],\n [0.0, -0.1, 1.0, 0.9],\n [0.0, 10.0, 1.0, 11.0],\n [0.0, 10.1, 1.0, 11.1],\n [0.0, 100.0, 1.0, 101.0]]]).astype(np.float32)\nscores = np.array([[[0.9, 0.75, 0.6, 0.95, 0.5, 0.3]],\n [[0.9, 0.75, 0.6, 0.95, 0.5, 0.3]]]).astype(np.float32)\nmax_output_boxes_per_class = np.array([2]).astype(np.int64)\niou_threshold = np.array([0.5]).astype(np.float32)\nscore_threshold = np.array([0.0]).astype(np.float32)\nselected_indices = np.array([[0, 0, 3], [0, 0, 0], [1, 0, 3], [1, 0, 0]]).astype(np.int64)\n\nexpect(node, inputs=[boxes, scores, max_output_boxes_per_class, iou_threshold, score_threshold], outputs=[selected_indices], name='test_nonmaxsuppression_two_batches')" + }, + { + "summary": "nonmaxsuppression_two_classes", + "code": "node = onnx.helper.make_node(\n 'NonMaxSuppression',\n inputs=['boxes', 'scores', 'max_output_boxes_per_class', 'iou_threshold', 'score_threshold'],\n outputs=['selected_indices']\n)\nboxes = np.array([[\n [0.0, 0.0, 1.0, 1.0],\n [0.0, 0.1, 1.0, 1.1],\n [0.0, -0.1, 1.0, 0.9],\n [0.0, 10.0, 1.0, 11.0],\n [0.0, 10.1, 1.0, 11.1],\n [0.0, 100.0, 1.0, 101.0]\n]]).astype(np.float32)\nscores = np.array([[[0.9, 0.75, 0.6, 0.95, 0.5, 0.3],\n [0.9, 0.75, 0.6, 0.95, 0.5, 0.3]]]).astype(np.float32)\nmax_output_boxes_per_class = np.array([2]).astype(np.int64)\niou_threshold = np.array([0.5]).astype(np.float32)\nscore_threshold = np.array([0.0]).astype(np.float32)\nselected_indices = np.array([[0, 0, 3], [0, 0, 0], [0, 1, 3], [0, 1, 0]]).astype(np.int64)\n\nexpect(node, inputs=[boxes, scores, max_output_boxes_per_class, iou_threshold, score_threshold], outputs=[selected_indices], name='test_nonmaxsuppression_two_classes')" + } + ] + }, + { + "name": "NonZero", + "module": "ai.onnx", + "version": 9, + "support_level": "common", + "description": "Returns the indices of the elements that are non-zero\n (in row-major order - by dimension).\n NonZero behaves similar to numpy.nonzero:\n https://docs.scipy.org/doc/numpy/reference/generated/numpy.nonzero.html\n", + "inputs": [ + { + "name": "X", + "type": "T", + "description": "input" + } + ], + "min_input": 1, + "max_input": 1, + "outputs": [ + { + "name": "Y", + "type": "tensor(int64)", + "description": "output" + } + ], + "min_output": 1, + "max_output": 1, + "type_constraints": [ + { + "description": "Constrain to all tensor types.", + "type_param_str": "T", + "allowed_type_strs": [ + "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)" + ] + } + ], + "examples": [ + { + "summary": "nonzero", + "code": "node = onnx.helper.make_node(\n 'NonZero',\n inputs=['condition'],\n outputs=['result'],\n)\n\ncondition = np.array([[1, 0], [1, 1]], dtype=bool)\nresult = np.array(np.nonzero(condition), dtype=np.int64) # expected output [[0, 1, 1], [0, 0, 1]]\nexpect(node, inputs=[condition], outputs=[result],\n name='test_nonzero_example')" + } + ] + }, + { + "name": "NonZero", + "module": "ai.onnx", + "version": 13, + "support_level": "common", + "description": "Returns the indices of the elements that are non-zero\n (in row-major order - by dimension).\n NonZero behaves similar to numpy.nonzero:\n https://docs.scipy.org/doc/numpy/reference/generated/numpy.nonzero.html\n", + "inputs": [ + { + "name": "X", + "type": "T", + "description": "input" + } + ], + "min_input": 1, + "max_input": 1, + "outputs": [ + { + "name": "Y", + "type": "tensor(int64)", + "description": "output" + } + ], + "min_output": 1, + "max_output": 1, + "type_constraints": [ + { + "description": "Constrain to all tensor types.", + "type_param_str": "T", + "allowed_type_strs": [ + "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)" + ] + } + ], + "examples": [ + { + "summary": "nonzero", + "code": "node = onnx.helper.make_node(\n 'NonZero',\n inputs=['condition'],\n outputs=['result'],\n)\n\ncondition = np.array([[1, 0], [1, 1]], dtype=bool)\nresult = np.array(np.nonzero(condition), dtype=np.int64) # expected output [[0, 1, 1], [0, 0, 1]]\nexpect(node, inputs=[condition], outputs=[result],\n name='test_nonzero_example')" + } + ] + }, + { + "name": "Normalizer", + "module": "ai.onnx.ml", + "version": 1, + "support_level": "common", + "description": "Normalize the input. There are three normalization modes, which have the corresponding formulas,\n defined using element-wise infix operators '/' and '^' and tensor-wide functions 'max' and 'sum':
\n
\n Max: Y = X / max(X)
\n L1: Y = X / sum(X)
\n L2: Y = sqrt(X^2 / sum(X^2)}
\n In all modes, if the divisor is zero, Y == X.\n
\n For batches, that is, [N,C] tensors, normalization is done along the C axis. In other words, each row\n of the batch is normalized independently.\n", + "attributes": [ + { + "name": "norm", + "type": "string", + "required": false, + "default": "MAX", + "description": "One of 'MAX,' 'L1,' 'L2'" + } + ], + "inputs": [ + { + "name": "X", + "type": "T", + "description": "Data to be encoded, a tensor of shape [N,C] or [C]" + } + ], + "min_input": 1, + "max_input": 1, + "outputs": [ + { + "name": "Y", + "type": "tensor(float)", + "description": "Encoded output data" + } + ], + "min_output": 1, + "max_output": 1, + "type_constraints": [ + { + "description": "The input must be a tensor of a numeric type.", + "type_param_str": "T", + "allowed_type_strs": [ + "tensor(float)", + "tensor(double)", + "tensor(int64)", + "tensor(int32)" + ] + } + ] + }, + { + "name": "Not", + "module": "ai.onnx", + "version": 1, + "support_level": "common", + "description": "Returns the negation of the input tensor element-wise.\n", + "inputs": [ + { + "name": "X", + "type": "T", + "description": "Input tensor" + } + ], + "min_input": 1, + "max_input": 1, + "outputs": [ + { + "name": "Y", + "type": "T", + "description": "Output tensor" + } + ], + "min_output": 1, + "max_output": 1, + "type_constraints": [ + { + "description": "Constrains input/output to boolean tensors.", + "type_param_str": "T", + "allowed_type_strs": [ + "tensor(bool)" + ] + } + ], + "examples": [ + { + "summary": "not", + "code": "node = onnx.helper.make_node(\n 'Not',\n inputs=['x'],\n outputs=['not'],\n)\n\n# 2d\nx = (np.random.randn(3, 4) > 0).astype(bool)\nexpect(node, inputs=[x], outputs=[np.logical_not(x)],\n name='test_not_2d')\n\n# 3d\nx = (np.random.randn(3, 4, 5) > 0).astype(bool)\nexpect(node, inputs=[x], outputs=[np.logical_not(x)],\n name='test_not_3d')\n\n# 4d\nx = (np.random.randn(3, 4, 5, 6) > 0).astype(bool)\nexpect(node, inputs=[x], outputs=[np.logical_not(x)],\n name='test_not_4d')" + } + ], + "category": "Logic" + }, + { + "name": "OneHot", + "module": "ai.onnx", + "version": 9, + "support_level": "common", + "description": "Produces a one-hot tensor based on inputs.\n The locations represented by the index values in the 'indices' input tensor will have 'on_value'\n and the other locations will have 'off_value' in the output tensor, where 'on_value' and 'off_value'\n are specified as part of required input argument 'values', which is a two-element tensor of format\n [off_value, on_value]. The rank of the output tensor will be one greater than the rank of the\n input tensor. The additional dimension is for one-hot representation. The additional dimension will\n be inserted at the position specified by 'axis'. If 'axis' is not specified then then additional\n dimension will be inserted as the innermost dimension, i.e. axis=-1. The size of the additional\n dimension is specified by required scalar input 'depth'. The type of the output tensor is the same\n as the type of the 'values' input. Any entries in the 'indices' input tensor with values outside\n the range [0, depth) will result in one-hot representation with all 'off_value' values in the\n output tensor.\n", + "attributes": [ + { + "name": "axis", + "type": "int64", + "required": false, + "default": -1, + "description": "(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": [ + { + "name": "indices", + "type": "T1", + "description": "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." + }, + { + "name": "depth", + "type": "T2", + "description": "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." + }, + { + "name": "values", + "type": "T3", + "description": "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. " + } + ], + "min_input": 3, + "max_input": 3, + "outputs": [ + { + "name": "output", + "type": "T3", + "description": "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." + } + ], + "min_output": 1, + "max_output": 1, + "type_constraints": [ + { + "description": "Constrains input to only numeric types.", + "type_param_str": "T1", + "allowed_type_strs": [ + "tensor(uint8)", + "tensor(uint16)", + "tensor(uint32)", + "tensor(uint64)", + "tensor(int8)", + "tensor(int16)", + "tensor(int32)", + "tensor(int64)", + "tensor(float16)", + "tensor(float)", + "tensor(double)" + ] + }, + { + "description": "Constrains input to only numeric types.", + "type_param_str": "T2", + "allowed_type_strs": [ + "tensor(uint8)", + "tensor(uint16)", + "tensor(uint32)", + "tensor(uint64)", + "tensor(int8)", + "tensor(int16)", + "tensor(int32)", + "tensor(int64)", + "tensor(float16)", + "tensor(float)", + "tensor(double)" + ] + }, + { + "description": "Constrain to any tensor type.", + "type_param_str": "T3", + "allowed_type_strs": [ + "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)" + ] + } + ], + "examples": [ + { + "summary": "with_axis", + "code": "axisValue = 1\non_value = 3\noff_value = 1\noutput_type = np.float32\nnode = onnx.helper.make_node(\n 'OneHot',\n inputs=['indices', 'depth', 'values'],\n outputs=['y'],\n axis=axisValue\n)\nindices = np.array([[1, 9],\n [2, 4]], dtype=np.float32)\ndepth = np.array([10], dtype=np.float32)\nvalues = np.array([off_value, on_value], dtype=output_type)\ny = one_hot(indices, depth, axis=axisValue, dtype=output_type)\ny = y * (on_value - off_value) + off_value\nexpect(node, inputs=[indices, depth, values], outputs=[y], name='test_onehot_with_axis')" + }, + { + "summary": "with_negative_axis", + "code": "axisValue = -2\non_value = 3\noff_value = 1\noutput_type = np.float32\nnode = onnx.helper.make_node(\n 'OneHot',\n inputs=['indices', 'depth', 'values'],\n outputs=['y'],\n axis=axisValue\n)\nindices = np.array([[1, 9],\n [2, 4]], dtype=np.float32)\ndepth = np.array([10], dtype=np.float32)\nvalues = np.array([off_value, on_value], dtype=output_type)\ny = one_hot(indices, depth, axis=axisValue, dtype=output_type)\ny = y * (on_value - off_value) + off_value\nexpect(node, inputs=[indices, depth, values], outputs=[y], name='test_onehot_with_negative_axis')" + }, + { + "summary": "with_negative_indices", + "code": "axisValue = 1\non_value = 3\noff_value = 1\noutput_type = np.float32\nnode = onnx.helper.make_node(\n 'OneHot',\n inputs=['indices', 'depth', 'values'],\n outputs=['y'],\n axis=axisValue\n)\nindices = np.array([0, -7, -8], dtype=np.int64)\n\ndepth = np.array([10], dtype=np.float32)\nvalues = np.array([off_value, on_value], dtype=output_type)\ny = one_hot(indices, depth, axis=axisValue, dtype=output_type)\ny = y * (on_value - off_value) + off_value\nexpect(node, inputs=[indices, depth, values], outputs=[y], name='test_onehot_negative_indices')" + }, + { + "summary": "without_axis", + "code": "on_value = 5\noff_value = 2\noutput_type = np.int32\nnode = onnx.helper.make_node(\n 'OneHot',\n inputs=['indices', 'depth', 'values'],\n outputs=['y']\n)\nindices = np.array([0, 7, 8], dtype=np.int64)\ndepth = np.float32(12)\nvalues = np.array([off_value, on_value], dtype=output_type)\ny = one_hot(indices, depth, dtype=output_type)\ny = y * (on_value - off_value) + off_value\nexpect(node, inputs=[indices, depth, values], outputs=[y], name='test_onehot_without_axis')" + } + ] + }, + { + "name": "OneHot", + "module": "ai.onnx", + "version": 11, + "support_level": "common", + "description": "Produces a one-hot tensor based on inputs.\n The locations represented by the index values in the 'indices' input tensor will have 'on_value'\n and the other locations will have 'off_value' in the output tensor, where 'on_value' and 'off_value'\n are specified as part of required input argument 'values', which is a two-element tensor of format\n [off_value, on_value]. The rank of the output tensor will be one greater than the rank of the\n input tensor. The additional dimension is for one-hot representation. The additional dimension will\n be inserted at the position specified by 'axis'. If 'axis' is not specified then then additional\n dimension will be inserted as the innermost dimension, i.e. axis=-1. The size of the additional\n dimension is specified by required scalar input 'depth'. The type of the output tensor is the same\n as the type of the 'values' input. Any entries in the 'indices' input tensor with values outside\n the range [-depth, depth-1] will result in one-hot representation with all 'off_value' values in the\n output tensor.\n\n when axis = 0:\n output[input[i, j, k], i, j, k] = 1 for all i, j, k and 0 otherwise.\n\n when axis = -1:\n output[i, j, k, input[i, j, k]] = 1 for all i, j, k and 0 otherwise.\n\n", + "attributes": [ + { + "name": "axis", + "type": "int64", + "required": false, + "default": -1, + "description": "(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": [ + { + "name": "indices", + "type": "T1", + "description": "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." + }, + { + "name": "depth", + "type": "T2", + "description": "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." + }, + { + "name": "values", + "type": "T3", + "description": "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. " + } + ], + "min_input": 3, + "max_input": 3, + "outputs": [ + { + "name": "output", + "type": "T3", + "description": "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." + } + ], + "min_output": 1, + "max_output": 1, + "type_constraints": [ + { + "description": "Constrains input to only numeric types.", + "type_param_str": "T1", + "allowed_type_strs": [ + "tensor(uint8)", + "tensor(uint16)", + "tensor(uint32)", + "tensor(uint64)", + "tensor(int8)", + "tensor(int16)", + "tensor(int32)", + "tensor(int64)", + "tensor(float16)", + "tensor(float)", + "tensor(double)" + ] + }, + { + "description": "Constrains input to only numeric types.", + "type_param_str": "T2", + "allowed_type_strs": [ + "tensor(uint8)", + "tensor(uint16)", + "tensor(uint32)", + "tensor(uint64)", + "tensor(int8)", + "tensor(int16)", + "tensor(int32)", + "tensor(int64)", + "tensor(float16)", + "tensor(float)", + "tensor(double)" + ] + }, + { + "description": "Constrain to any tensor type.", + "type_param_str": "T3", + "allowed_type_strs": [ + "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)" + ] + } + ], + "examples": [ + { + "summary": "with_axis", + "code": "axisValue = 1\non_value = 3\noff_value = 1\noutput_type = np.float32\nnode = onnx.helper.make_node(\n 'OneHot',\n inputs=['indices', 'depth', 'values'],\n outputs=['y'],\n axis=axisValue\n)\nindices = np.array([[1, 9],\n [2, 4]], dtype=np.float32)\ndepth = np.array([10], dtype=np.float32)\nvalues = np.array([off_value, on_value], dtype=output_type)\ny = one_hot(indices, depth, axis=axisValue, dtype=output_type)\ny = y * (on_value - off_value) + off_value\nexpect(node, inputs=[indices, depth, values], outputs=[y], name='test_onehot_with_axis')" + }, + { + "summary": "with_negative_axis", + "code": "axisValue = -2\non_value = 3\noff_value = 1\noutput_type = np.float32\nnode = onnx.helper.make_node(\n 'OneHot',\n inputs=['indices', 'depth', 'values'],\n outputs=['y'],\n axis=axisValue\n)\nindices = np.array([[1, 9],\n [2, 4]], dtype=np.float32)\ndepth = np.array([10], dtype=np.float32)\nvalues = np.array([off_value, on_value], dtype=output_type)\ny = one_hot(indices, depth, axis=axisValue, dtype=output_type)\ny = y * (on_value - off_value) + off_value\nexpect(node, inputs=[indices, depth, values], outputs=[y], name='test_onehot_with_negative_axis')" + }, + { + "summary": "with_negative_indices", + "code": "axisValue = 1\non_value = 3\noff_value = 1\noutput_type = np.float32\nnode = onnx.helper.make_node(\n 'OneHot',\n inputs=['indices', 'depth', 'values'],\n outputs=['y'],\n axis=axisValue\n)\nindices = np.array([0, -7, -8], dtype=np.int64)\n\ndepth = np.array([10], dtype=np.float32)\nvalues = np.array([off_value, on_value], dtype=output_type)\ny = one_hot(indices, depth, axis=axisValue, dtype=output_type)\ny = y * (on_value - off_value) + off_value\nexpect(node, inputs=[indices, depth, values], outputs=[y], name='test_onehot_negative_indices')" + }, + { + "summary": "without_axis", + "code": "on_value = 5\noff_value = 2\noutput_type = np.int32\nnode = onnx.helper.make_node(\n 'OneHot',\n inputs=['indices', 'depth', 'values'],\n outputs=['y']\n)\nindices = np.array([0, 7, 8], dtype=np.int64)\ndepth = np.float32(12)\nvalues = np.array([off_value, on_value], dtype=output_type)\ny = one_hot(indices, depth, dtype=output_type)\ny = y * (on_value - off_value) + off_value\nexpect(node, inputs=[indices, depth, values], outputs=[y], name='test_onehot_without_axis')" + } + ] + }, + { + "name": "OneHotEncoder", + "module": "ai.onnx.ml", + "version": 1, + "support_level": "common", + "description": "Replace each input element with an array of ones and zeros, where a single\n one is placed at the index of the category that was passed in. The total category count\n will determine the size of the extra dimension of the output array Y.
\n For example, if we pass a tensor with a single value of 4, and a category count of 8,\n the output will be a tensor with ``[0,0,0,0,1,0,0,0]``.
\n This operator assumes every input feature is from the same set of categories.
\n If the input is a tensor of float, int32, or double, the data will be cast\n to integers and the cats_int64s category list will be used for the lookups.\n", + "attributes": [ + { + "name": "cats_int64s", + "type": "int64[]", + "required": false, + "description": "List of categories, ints.
One and only one of the 'cats_*' attributes must be defined." + }, + { + "name": "cats_strings", + "type": "string[]", + "required": false, + "description": "List of categories, strings.
One and only one of the 'cats_*' attributes must be defined." + }, + { + "name": "zeros", + "type": "int64", + "required": false, + "default": 1, + "description": "If true and category is not present, will return all zeros; if false and a category if not found, the operator will fail." + } + ], + "inputs": [ + { + "name": "X", + "type": "T", + "description": "Data to be encoded." + } + ], + "min_input": 1, + "max_input": 1, + "outputs": [ + { + "name": "Y", + "type": "tensor(float)", + "description": "Encoded output data, having one more dimension than X." + } + ], + "min_output": 1, + "max_output": 1, + "type_constraints": [ + { + "description": "The input must be a tensor of a numeric type.", + "type_param_str": "T", + "allowed_type_strs": [ + "tensor(string)", + "tensor(int64)", + "tensor(int32)", + "tensor(float)", + "tensor(double)" + ] + } + ] + }, + { + "name": "Optional", + "module": "ai.onnx", + "version": 15, + "support_level": "common", + "description": "Constructs an optional-type value containing either an empty optional of a certain type specified by the attribute,\nor a non-empty value containing the input element.\n", + "attributes": [ + { + "name": "type", + "required": false, + "description": "Type of the element in the optional output" + } + ], + "inputs": [ + { + "name": "input", + "type": "V", + "option": "optional", + "description": "The input element." + } + ], + "min_input": 0, + "max_input": 1, + "outputs": [ + { + "name": "output", + "type": "O", + "description": "The optional output enclosing the input element." + } + ], + "min_output": 1, + "max_output": 1, + "inputs_range": "0 - 1", + "type_constraints": [ + { + "description": "Constrains input type to all tensor and sequence types.", + "type_param_str": "V", + "allowed_type_strs": [ + "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))" + ] + }, + { + "description": "Constrains output type to all optional tensor or optional sequence types.", + "type_param_str": "O", + "allowed_type_strs": [ + "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))" + ] + } + ] + }, + { + "name": "OptionalGetElement", + "module": "ai.onnx", + "version": 15, + "support_level": "common", + "description": "Outputs the element in the optional-type input. It is an error if the input value does not have an element\nand the behavior is undefined in this case.\n", + "inputs": [ + { + "name": "input", + "type": "O", + "description": "The optional input." + } + ], + "min_input": 1, + "max_input": 1, + "outputs": [ + { + "name": "output", + "type": "V", + "description": "Output element in the optional input." + } + ], + "min_output": 1, + "max_output": 1, + "type_constraints": [ + { + "description": "Constrains input type to optional tensor and optional sequence types.", + "type_param_str": "O", + "allowed_type_strs": [ + "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))" + ] + }, + { + "description": "Constrain output type to all tensor or sequence types.", + "type_param_str": "V", + "allowed_type_strs": [ + "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))" + ] + } + ] + }, + { + "name": "OptionalHasElement", + "module": "ai.onnx", + "version": 15, + "support_level": "common", + "description": "Returns true if the optional-type input contains an element. If it is an empty optional-type, this op returns false.\n", + "inputs": [ + { + "name": "input", + "type": "O", + "description": "The optional input." + } + ], + "min_input": 1, + "max_input": 1, + "outputs": [ + { + "name": "output", + "type": "B", + "description": "A scalar boolean tensor. If true, it indicates that optional-type input contains an element. Otherwise, it is empty." + } + ], + "min_output": 1, + "max_output": 1, + "type_constraints": [ + { + "description": "Constrains input type to optional tensor and optional sequence types.", + "type_param_str": "O", + "allowed_type_strs": [ + "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))" + ] + }, + { + "description": "Constrains output to a boolean tensor.", + "type_param_str": "B", + "allowed_type_strs": [ + "tensor(bool)" + ] + } + ], + "examples": [ + { + "summary": "empty", + "code": "optional = None\ntensor_type_proto = onnx.helper.make_tensor_type_proto(elem_type=onnx.TensorProto.INT32, shape=[])\ninput_type_proto = onnx.helper.make_optional_type_proto(tensor_type_proto)\nnode = onnx.helper.make_node(\n 'OptionalHasElement',\n inputs=['optional_input'],\n outputs=['output']\n)\noutput = optional_has_element_reference_implementation(optional)\nexpect(node, inputs=[optional], outputs=[output],\n input_type_protos=[input_type_proto],\n name='test_optional_has_element_empty')" + }, + { + "summary": "get_element_sequence", + "code": "optional = [np.array([1, 2, 3, 4]).astype(np.int32)]\ntensor_type_proto = onnx.helper.make_tensor_type_proto(elem_type=onnx.TensorProto.INT32, shape=[4, ])\nseq_type_proto = onnx.helper.make_sequence_type_proto(tensor_type_proto)\ninput_type_proto = onnx.helper.make_optional_type_proto(seq_type_proto)\n\nnode = onnx.helper.make_node(\n 'OptionalGetElement',\n inputs=['optional_input'],\n outputs=['output']\n)\noutput = optional_get_element_reference_implementation(optional)\nexpect(node, inputs=[optional], outputs=[output],\n input_type_protos=[input_type_proto],\n name='test_optional_get_element_sequence')" + }, + { + "summary": "get_element_tensor", + "code": "optional = np.array([1, 2, 3, 4]).astype(np.float32)\ntensor_type_proto = onnx.helper.make_tensor_type_proto(elem_type=onnx.TensorProto.FLOAT, shape=[4, ])\ninput_type_proto = onnx.helper.make_optional_type_proto(tensor_type_proto)\n\nnode = onnx.helper.make_node(\n 'OptionalGetElement',\n inputs=['optional_input'],\n outputs=['output']\n)\noutput = optional_get_element_reference_implementation(optional)\nexpect(node, inputs=[optional], outputs=[output],\n input_type_protos=[input_type_proto],\n name='test_optional_get_element')" + }, + { + "summary": "optionalhaselement", + "code": "optional = np.array([1, 2, 3, 4]).astype(np.float32)\ntensor_type_proto = onnx.helper.make_tensor_type_proto(elem_type=onnx.TensorProto.FLOAT, shape=[4, ])\ninput_type_proto = onnx.helper.make_optional_type_proto(tensor_type_proto)\nnode = onnx.helper.make_node(\n 'OptionalHasElement',\n inputs=['optional_input'],\n outputs=['output']\n)\noutput = optional_has_element_reference_implementation(optional)\nexpect(node, inputs=[optional], outputs=[output],\n input_type_protos=[input_type_proto],\n name='test_optional_has_element')" + } + ] + }, + { + "name": "Or", + "module": "ai.onnx", + "version": 1, + "support_level": "common", + "description": "Returns the tensor resulted from performing the `or` logical operation\nelementwise on the input tensors `A` and `B`.\n\nIf broadcasting is enabled, the right-hand-side argument will be broadcasted\nto match the shape of left-hand-side argument. See the doc of `Add` for a\ndetailed description of the broadcasting rules.\n", + "attributes": [ + { + "name": "axis", + "type": "int64", + "required": false, + "description": "If set, defines the broadcast dimensions." + }, + { + "name": "broadcast", + "type": "int64", + "required": false, + "description": "Enable broadcasting" + } + ], + "inputs": [ + { + "name": "A", + "type": "T", + "description": "Left input tensor for the logical operator." + }, + { + "name": "B", + "type": "T", + "description": "Right input tensor for the logical operator." + } + ], + "min_input": 2, + "max_input": 2, + "outputs": [ + { + "name": "C", + "type": "T1", + "description": "Result tensor." + } + ], + "min_output": 1, + "max_output": 1, + "type_constraints": [ + { + "description": "Constrains input to boolean tensor.", + "type_param_str": "T", + "allowed_type_strs": [ + "tensor(bool)" + ] + }, + { + "description": "Constrains output to boolean tensor.", + "type_param_str": "T1", + "allowed_type_strs": [ + "tensor(bool)" + ] + } + ], + "examples": [ + { + "summary": "or", + "code": "node = onnx.helper.make_node(\n 'Or',\n inputs=['x', 'y'],\n outputs=['or'],\n)\n\n# 2d\nx = (np.random.randn(3, 4) > 0).astype(bool)\ny = (np.random.randn(3, 4) > 0).astype(bool)\nz = np.logical_or(x, y)\nexpect(node, inputs=[x, y], outputs=[z],\n name='test_or2d')\n\n# 3d\nx = (np.random.randn(3, 4, 5) > 0).astype(bool)\ny = (np.random.randn(3, 4, 5) > 0).astype(bool)\nz = np.logical_or(x, y)\nexpect(node, inputs=[x, y], outputs=[z],\n name='test_or3d')\n\n# 4d\nx = (np.random.randn(3, 4, 5, 6) > 0).astype(bool)\ny = (np.random.randn(3, 4, 5, 6) > 0).astype(bool)\nz = np.logical_or(x, y)\nexpect(node, inputs=[x, y], outputs=[z],\n name='test_or4d')" + }, + { + "summary": "or_broadcast", + "code": "node = onnx.helper.make_node(\n 'Or',\n inputs=['x', 'y'],\n outputs=['or'],\n)\n\n# 3d vs 1d\nx = (np.random.randn(3, 4, 5) > 0).astype(bool)\ny = (np.random.randn(5) > 0).astype(bool)\nz = np.logical_or(x, y)\nexpect(node, inputs=[x, y], outputs=[z],\n name='test_or_bcast3v1d')\n\n# 3d vs 2d\nx = (np.random.randn(3, 4, 5) > 0).astype(bool)\ny = (np.random.randn(4, 5) > 0).astype(bool)\nz = np.logical_or(x, y)\nexpect(node, inputs=[x, y], outputs=[z],\n name='test_or_bcast3v2d')\n\n# 4d vs 2d\nx = (np.random.randn(3, 4, 5, 6) > 0).astype(bool)\ny = (np.random.randn(5, 6) > 0).astype(bool)\nz = np.logical_or(x, y)\nexpect(node, inputs=[x, y], outputs=[z],\n name='test_or_bcast4v2d')\n\n# 4d vs 3d\nx = (np.random.randn(3, 4, 5, 6) > 0).astype(bool)\ny = (np.random.randn(4, 5, 6) > 0).astype(bool)\nz = np.logical_or(x, y)\nexpect(node, inputs=[x, y], outputs=[z],\n name='test_or_bcast4v3d')\n\n# 4d vs 4d\nx = (np.random.randn(1, 4, 1, 6) > 0).astype(bool)\ny = (np.random.randn(3, 1, 5, 6) > 0).astype(bool)\nz = np.logical_or(x, y)\nexpect(node, inputs=[x, y], outputs=[z],\n name='test_or_bcast4v4d')" + } + ], + "category": "Logic" + }, + { + "name": "Or", + "module": "ai.onnx", + "version": 7, + "support_level": "common", + "description": "Returns the tensor resulted from performing the `or` logical operation\nelementwise on the input tensors `A` and `B` (with Numpy-style broadcasting support).\n\nThis operator supports **multidirectional (i.e., Numpy-style) broadcasting**; for more details please check [the doc](https://github.com/onnx/onnx/blob/master/docs/Broadcasting.md).\n", + "inputs": [ + { + "name": "A", + "type": "T", + "description": "First input operand for the logical operator." + }, + { + "name": "B", + "type": "T", + "description": "Second input operand for the logical operator." + } + ], + "min_input": 2, + "max_input": 2, + "outputs": [ + { + "name": "C", + "type": "T1", + "description": "Result tensor." + } + ], + "min_output": 1, + "max_output": 1, + "type_constraints": [ + { + "description": "Constrains input to boolean tensor.", + "type_param_str": "T", + "allowed_type_strs": [ + "tensor(bool)" + ] + }, + { + "description": "Constrains output to boolean tensor.", + "type_param_str": "T1", + "allowed_type_strs": [ + "tensor(bool)" + ] + } + ], + "examples": [ + { + "summary": "or", + "code": "node = onnx.helper.make_node(\n 'Or',\n inputs=['x', 'y'],\n outputs=['or'],\n)\n\n# 2d\nx = (np.random.randn(3, 4) > 0).astype(bool)\ny = (np.random.randn(3, 4) > 0).astype(bool)\nz = np.logical_or(x, y)\nexpect(node, inputs=[x, y], outputs=[z],\n name='test_or2d')\n\n# 3d\nx = (np.random.randn(3, 4, 5) > 0).astype(bool)\ny = (np.random.randn(3, 4, 5) > 0).astype(bool)\nz = np.logical_or(x, y)\nexpect(node, inputs=[x, y], outputs=[z],\n name='test_or3d')\n\n# 4d\nx = (np.random.randn(3, 4, 5, 6) > 0).astype(bool)\ny = (np.random.randn(3, 4, 5, 6) > 0).astype(bool)\nz = np.logical_or(x, y)\nexpect(node, inputs=[x, y], outputs=[z],\n name='test_or4d')" + }, + { + "summary": "or_broadcast", + "code": "node = onnx.helper.make_node(\n 'Or',\n inputs=['x', 'y'],\n outputs=['or'],\n)\n\n# 3d vs 1d\nx = (np.random.randn(3, 4, 5) > 0).astype(bool)\ny = (np.random.randn(5) > 0).astype(bool)\nz = np.logical_or(x, y)\nexpect(node, inputs=[x, y], outputs=[z],\n name='test_or_bcast3v1d')\n\n# 3d vs 2d\nx = (np.random.randn(3, 4, 5) > 0).astype(bool)\ny = (np.random.randn(4, 5) > 0).astype(bool)\nz = np.logical_or(x, y)\nexpect(node, inputs=[x, y], outputs=[z],\n name='test_or_bcast3v2d')\n\n# 4d vs 2d\nx = (np.random.randn(3, 4, 5, 6) > 0).astype(bool)\ny = (np.random.randn(5, 6) > 0).astype(bool)\nz = np.logical_or(x, y)\nexpect(node, inputs=[x, y], outputs=[z],\n name='test_or_bcast4v2d')\n\n# 4d vs 3d\nx = (np.random.randn(3, 4, 5, 6) > 0).astype(bool)\ny = (np.random.randn(4, 5, 6) > 0).astype(bool)\nz = np.logical_or(x, y)\nexpect(node, inputs=[x, y], outputs=[z],\n name='test_or_bcast4v3d')\n\n# 4d vs 4d\nx = (np.random.randn(1, 4, 1, 6) > 0).astype(bool)\ny = (np.random.randn(3, 1, 5, 6) > 0).astype(bool)\nz = np.logical_or(x, y)\nexpect(node, inputs=[x, y], outputs=[z],\n name='test_or_bcast4v4d')" + } + ], + "category": "Logic" + }, + { + "name": "PRelu", + "module": "ai.onnx", + "version": 1, + "support_level": "common", + "description": "PRelu takes input data (Tensor) and slope tensor as input, and produces one\noutput data (Tensor) where the function `f(x) = slope * x for x < 0`,\n`f(x) = x for x >= 0`., is applied to the data tensor elementwise.\n\n", + "attributes": [ + { + "name": "consumed_inputs", + "type": "int64[]", + "required": false, + "description": "legacy optimization attribute." + } + ], + "inputs": [ + { + "name": "X", + "type": "T", + "description": "Input tensor" + }, + { + "name": "slope", + "type": "T", + "description": "Slope tensor. If `Slope` is of size 1, the value is sharedacross different channels" + } + ], + "min_input": 2, + "max_input": 2, + "outputs": [ + { + "name": "Y", + "type": "T", + "description": "Output tensor" + } + ], + "min_output": 1, + "max_output": 1, + "type_constraints": [ + { + "description": "Constrain input and output types to float tensors.", + "type_param_str": "T", + "allowed_type_strs": [ + "tensor(float16)", + "tensor(float)", + "tensor(double)" + ] + } + ], + "examples": [ + { + "summary": "prelu", + "code": "node = onnx.helper.make_node(\n 'PRelu',\n inputs=['x', 'slope'],\n outputs=['y'],\n)\n\nx = np.random.randn(3, 4, 5).astype(np.float32)\nslope = np.random.randn(3, 4, 5).astype(np.float32)\ny = np.clip(x, 0, np.inf) + np.clip(x, -np.inf, 0) * slope\n\nexpect(node, inputs=[x, slope], outputs=[y],\n name='test_prelu_example')" + }, + { + "summary": "prelu_broadcast", + "code": "node = onnx.helper.make_node(\n 'PRelu',\n inputs=['x', 'slope'],\n outputs=['y'],\n)\n\nx = np.random.randn(3, 4, 5).astype(np.float32)\nslope = np.random.randn(5).astype(np.float32)\ny = np.clip(x, 0, np.inf) + np.clip(x, -np.inf, 0) * slope\n\nexpect(node, inputs=[x, slope], outputs=[y],\n name='test_prelu_broadcast')" + } + ], + "category": "Activation" + }, + { + "name": "PRelu", + "module": "ai.onnx", + "version": 6, + "support_level": "common", + "description": "PRelu takes input data (Tensor) and slope tensor as input, and produces one\noutput data (Tensor) where the function `f(x) = slope * x for x < 0`,\n`f(x) = x for x >= 0`., is applied to the data tensor elementwise.\n\n", + "inputs": [ + { + "name": "X", + "type": "T", + "description": "Input tensor" + }, + { + "name": "slope", + "type": "T", + "description": "Slope tensor. If `Slope` is of size 1, the value is sharedacross different channels" + } + ], + "min_input": 2, + "max_input": 2, + "outputs": [ + { + "name": "Y", + "type": "T", + "description": "Output tensor" + } + ], + "min_output": 1, + "max_output": 1, + "type_constraints": [ + { + "description": "Constrain input and output types to float tensors.", + "type_param_str": "T", + "allowed_type_strs": [ + "tensor(float16)", + "tensor(float)", + "tensor(double)" + ] + } + ], + "examples": [ + { + "summary": "prelu", + "code": "node = onnx.helper.make_node(\n 'PRelu',\n inputs=['x', 'slope'],\n outputs=['y'],\n)\n\nx = np.random.randn(3, 4, 5).astype(np.float32)\nslope = np.random.randn(3, 4, 5).astype(np.float32)\ny = np.clip(x, 0, np.inf) + np.clip(x, -np.inf, 0) * slope\n\nexpect(node, inputs=[x, slope], outputs=[y],\n name='test_prelu_example')" + }, + { + "summary": "prelu_broadcast", + "code": "node = onnx.helper.make_node(\n 'PRelu',\n inputs=['x', 'slope'],\n outputs=['y'],\n)\n\nx = np.random.randn(3, 4, 5).astype(np.float32)\nslope = np.random.randn(5).astype(np.float32)\ny = np.clip(x, 0, np.inf) + np.clip(x, -np.inf, 0) * slope\n\nexpect(node, inputs=[x, slope], outputs=[y],\n name='test_prelu_broadcast')" + } + ], + "category": "Activation" + }, + { + "name": "PRelu", + "module": "ai.onnx", + "version": 7, + "support_level": "common", + "description": "PRelu takes input data (Tensor) and slope tensor as input, and produces one\noutput data (Tensor) where the function `f(x) = slope * x for x < 0`,\n`f(x) = x for x >= 0`., is applied to the data tensor elementwise.\nThis operator supports **unidirectional broadcasting** (tensor slope should be unidirectional broadcastable to input tensor X); for more details please check [the doc](https://github.com/onnx/onnx/blob/master/docs/Broadcasting.md).", + "inputs": [ + { + "name": "X", + "type": "T", + "description": "Input tensor" + }, + { + "name": "slope", + "type": "T", + "description": "Slope tensor. The shape of slope can be smaller then first input X; if so, its shape must be unidirectional broadcastable to X" + } + ], + "min_input": 2, + "max_input": 2, + "outputs": [ + { + "name": "Y", + "type": "T", + "description": "Output tensor (same size as X)" + } + ], + "min_output": 1, + "max_output": 1, + "type_constraints": [ + { + "description": "Constrain input and output types to float tensors.", + "type_param_str": "T", + "allowed_type_strs": [ + "tensor(float16)", + "tensor(float)", + "tensor(double)" + ] + } + ], + "examples": [ + { + "summary": "prelu", + "code": "node = onnx.helper.make_node(\n 'PRelu',\n inputs=['x', 'slope'],\n outputs=['y'],\n)\n\nx = np.random.randn(3, 4, 5).astype(np.float32)\nslope = np.random.randn(3, 4, 5).astype(np.float32)\ny = np.clip(x, 0, np.inf) + np.clip(x, -np.inf, 0) * slope\n\nexpect(node, inputs=[x, slope], outputs=[y],\n name='test_prelu_example')" + }, + { + "summary": "prelu_broadcast", + "code": "node = onnx.helper.make_node(\n 'PRelu',\n inputs=['x', 'slope'],\n outputs=['y'],\n)\n\nx = np.random.randn(3, 4, 5).astype(np.float32)\nslope = np.random.randn(5).astype(np.float32)\ny = np.clip(x, 0, np.inf) + np.clip(x, -np.inf, 0) * slope\n\nexpect(node, inputs=[x, slope], outputs=[y],\n name='test_prelu_broadcast')" + } + ], + "category": "Activation" + }, + { + "name": "PRelu", + "module": "ai.onnx", + "version": 9, + "support_level": "common", + "description": "PRelu takes input data (Tensor) and slope tensor as input, and produces one\noutput data (Tensor) where the function `f(x) = slope * x for x < 0`,\n`f(x) = x for x >= 0`., is applied to the data tensor elementwise.\nThis operator supports **unidirectional broadcasting** (tensor slope should be unidirectional broadcastable to input tensor X); for more details please check [the doc](https://github.com/onnx/onnx/blob/master/docs/Broadcasting.md).", + "inputs": [ + { + "name": "X", + "type": "T", + "description": "Input tensor" + }, + { + "name": "slope", + "type": "T", + "description": "Slope tensor. The shape of slope can be smaller then first input X; if so, its shape must be unidirectional broadcastable to X" + } + ], + "min_input": 2, + "max_input": 2, + "outputs": [ + { + "name": "Y", + "type": "T", + "description": "Output tensor (same size as X)" + } + ], + "min_output": 1, + "max_output": 1, + "type_constraints": [ + { + "description": "Constrain input and output types to float/int tensors.", + "type_param_str": "T", + "allowed_type_strs": [ + "tensor(float16)", + "tensor(float)", + "tensor(double)", + "tensor(uint32)", + "tensor(uint64)", + "tensor(int32)", + "tensor(int64)" + ] + } + ], + "examples": [ + { + "summary": "prelu", + "code": "node = onnx.helper.make_node(\n 'PRelu',\n inputs=['x', 'slope'],\n outputs=['y'],\n)\n\nx = np.random.randn(3, 4, 5).astype(np.float32)\nslope = np.random.randn(3, 4, 5).astype(np.float32)\ny = np.clip(x, 0, np.inf) + np.clip(x, -np.inf, 0) * slope\n\nexpect(node, inputs=[x, slope], outputs=[y],\n name='test_prelu_example')" + }, + { + "summary": "prelu_broadcast", + "code": "node = onnx.helper.make_node(\n 'PRelu',\n inputs=['x', 'slope'],\n outputs=['y'],\n)\n\nx = np.random.randn(3, 4, 5).astype(np.float32)\nslope = np.random.randn(5).astype(np.float32)\ny = np.clip(x, 0, np.inf) + np.clip(x, -np.inf, 0) * slope\n\nexpect(node, inputs=[x, slope], outputs=[y],\n name='test_prelu_broadcast')" + } + ], + "category": "Activation" + }, + { + "name": "Pad", + "module": "ai.onnx", + "version": 1, + "support_level": "common", + "description": "Given `data` tensor, paddings, mode, and value.\nExample:\n Insert 0 paddings to the beginning of the second dimension.\n data = [\n [1.0, 1.2],\n [2.3, 3.4],\n [4.5, 5.7],\n ]\n paddings = [0, 0, 2, 0]\n output = [\n [\n [0.0, 0.0, 1.0, 1.2],\n [0.0, 0.0, 2.3, 3.4],\n [0.0, 0.0, 4.5, 5.7],\n ],\n ]\n", + "attributes": [ + { + "name": "mode", + "type": "string", + "required": false, + "default": "constant", + "description": "Three modes: constant(default), reflect, edge" + }, + { + "name": "paddings", + "type": "int64[]", + "required": true, + "description": "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`." + }, + { + "name": "value", + "type": "float32", + "required": false, + "description": "One float, indicates the value to be filled, default is 0" + } + ], + "inputs": [ + { + "name": "data", + "type": "T", + "description": "Input tensor." + } + ], + "min_input": 1, + "max_input": 1, + "outputs": [ + { + "name": "output", + "type": "T", + "description": "Tensor after padding." + } + ], + "min_output": 1, + "max_output": 1, + "type_constraints": [ + { + "description": "Constrain input and output types to float tensors.", + "type_param_str": "T", + "allowed_type_strs": [ + "tensor(float16)", + "tensor(float)", + "tensor(double)" + ] + } + ], + "examples": [ + { + "summary": "constant_pad", + "code": "node = onnx.helper.make_node(\n 'Pad',\n inputs=['x', 'pads', 'value'],\n outputs=['y'],\n mode='constant'\n)\nx = np.random.randn(1, 3, 4, 5).astype(np.float32)\npads = np.array([0, 0, 1, 3, 0, 0, 2, 4]).astype(np.int64) # pad order [x1_begin, x2_begin, ..., x1_end, x2_end, ...]\nvalue = np.float32(1.2)\ny = pad_impl(\n x,\n pads,\n 'constant',\n 1.2\n)\n\nexpect(node, inputs=[x, pads, value], outputs=[y],\n name='test_constant_pad')" + }, + { + "summary": "reflection_and_edge_pad", + "code": "for mode in ['edge', 'reflect']:\n node = onnx.helper.make_node(\n 'Pad',\n inputs=['x', 'pads'],\n outputs=['y'],\n mode=mode\n )\n x = np.random.randn(1, 3, 4, 5).astype(np.int32)\n pads = np.array([0, 0, 1, 1, 0, 0, 1, 1]).astype(np.int64) # pad order [x1_begin, x2_begin, ..., x1_end, x2_end, ...]\n y = pad_impl(\n x,\n pads,\n mode\n )\n\n expect(node, inputs=[x, pads], outputs=[y],\n name='test_{}_pad'.format(mode))" + } + ], + "category": "Tensor" + }, + { + "name": "Pad", + "module": "ai.onnx", + "version": 2, + "support_level": "common", + "description": "Given `data` tensor, pads, mode, and value.\nExample:\n Insert 0 pads to the beginning of the second dimension.\n data = [\n [1.0, 1.2],\n [2.3, 3.4],\n [4.5, 5.7],\n ]\n pads = [0, 2, 0, 0]\n output = [\n [\n [0.0, 0.0, 1.0, 1.2],\n [0.0, 0.0, 2.3, 3.4],\n [0.0, 0.0, 4.5, 5.7],\n ],\n ]\n", + "attributes": [ + { + "name": "mode", + "type": "string", + "required": false, + "default": "constant", + "description": "Three modes: constant(default), reflect, edge" + }, + { + "name": "pads", + "type": "int64[]", + "required": true, + "description": "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`." + }, + { + "name": "value", + "type": "float32", + "required": false, + "description": "One float, indicates the value to be filled." + } + ], + "inputs": [ + { + "name": "data", + "type": "T", + "description": "Input tensor." + } + ], + "min_input": 1, + "max_input": 1, + "outputs": [ + { + "name": "output", + "type": "T", + "description": "Tensor after padding." + } + ], + "min_output": 1, + "max_output": 1, + "type_constraints": [ + { + "description": "Constrain input and output types to float tensors.", + "type_param_str": "T", + "allowed_type_strs": [ + "tensor(float16)", + "tensor(float)", + "tensor(double)" + ] + } + ], + "examples": [ + { + "summary": "constant_pad", + "code": "node = onnx.helper.make_node(\n 'Pad',\n inputs=['x', 'pads', 'value'],\n outputs=['y'],\n mode='constant'\n)\nx = np.random.randn(1, 3, 4, 5).astype(np.float32)\npads = np.array([0, 0, 1, 3, 0, 0, 2, 4]).astype(np.int64) # pad order [x1_begin, x2_begin, ..., x1_end, x2_end, ...]\nvalue = np.float32(1.2)\ny = pad_impl(\n x,\n pads,\n 'constant',\n 1.2\n)\n\nexpect(node, inputs=[x, pads, value], outputs=[y],\n name='test_constant_pad')" + }, + { + "summary": "reflection_and_edge_pad", + "code": "for mode in ['edge', 'reflect']:\n node = onnx.helper.make_node(\n 'Pad',\n inputs=['x', 'pads'],\n outputs=['y'],\n mode=mode\n )\n x = np.random.randn(1, 3, 4, 5).astype(np.int32)\n pads = np.array([0, 0, 1, 1, 0, 0, 1, 1]).astype(np.int64) # pad order [x1_begin, x2_begin, ..., x1_end, x2_end, ...]\n y = pad_impl(\n x,\n pads,\n mode\n )\n\n expect(node, inputs=[x, pads], outputs=[y],\n name='test_{}_pad'.format(mode))" + } + ], + "category": "Tensor" + }, + { + "name": "Pad", + "module": "ai.onnx", + "version": 11, + "support_level": "common", + "description": "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`,\na padded tensor (`output`) is generated.\n\nThe three supported `modes` are (similar to corresponding modes supported by `numpy.pad`):\n\n1) `constant`(default) - pads with a given constant value as specified by `constant_value` (which defaults to 0)\n\n2) `reflect` - pads with the reflection of the vector mirrored on the first and last values of the vector along each axis\n\n3) `edge` - pads with the edge values of array\n\n\nExample 1 (`constant` mode):\n Insert 0 pads to the beginning of the second dimension.\n\n data =\n [\n [1.0, 1.2],\n [2.3, 3.4],\n [4.5, 5.7],\n ]\n\n pads = [0, 2, 0, 0]\n\n mode = 'constant'\n\n constant_value = 0.0\n\n output =\n [\n [0.0, 0.0, 1.0, 1.2],\n [0.0, 0.0, 2.3, 3.4],\n [0.0, 0.0, 4.5, 5.7],\n ]\n\n\nExample 2 (`reflect` mode):\n data =\n [\n [1.0, 1.2],\n [2.3, 3.4],\n [4.5, 5.7],\n ]\n\n pads = [0, 2, 0, 0]\n\n mode = 'reflect'\n\n output =\n [\n [1.0, 1.2, 1.0, 1.2],\n [2.3, 3.4, 2.3, 3.4],\n [4.5, 5.7, 4.5, 5.7],\n ]\n\n\nExample 3 (`edge` mode):\n data =\n [\n [1.0, 1.2],\n [2.3, 3.4],\n [4.5, 5.7],\n ]\n\n pads = [0, 2, 0, 0]\n\n mode = 'edge'\n\n output =\n [\n [1.0, 1.0, 1.0, 1.2],\n [2.3, 2.3, 2.3, 3.4],\n [4.5, 4.5, 4.5, 5.7],\n ]\n\n", + "attributes": [ + { + "name": "mode", + "type": "string", + "required": false, + "default": "constant", + "description": "Supported modes: `constant`(default), `reflect`, `edge`" + } + ], + "inputs": [ + { + "name": "data", + "type": "T", + "description": "Input tensor." + }, + { + "name": "pads", + "type": "tensor(int64)", + "description": "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`." + }, + { + "name": "constant_value", + "type": "T", + "option": "optional", + "description": "(Optional) A scalar value to be used if the mode chosen is `constant` (by default it is 0)." + } + ], + "min_input": 2, + "max_input": 3, + "outputs": [ + { + "name": "output", + "type": "T", + "description": "Tensor after padding." + } + ], + "min_output": 1, + "max_output": 1, + "inputs_range": "2 - 3", + "type_constraints": [ + { + "description": "Constrains input and output to only numeric types.", + "type_param_str": "T", + "allowed_type_strs": [ + "tensor(uint8)", + "tensor(uint16)", + "tensor(uint32)", + "tensor(uint64)", + "tensor(int8)", + "tensor(int16)", + "tensor(int32)", + "tensor(int64)", + "tensor(float16)", + "tensor(float)", + "tensor(double)" + ] + } + ], + "examples": [ + { + "summary": "constant_pad", + "code": "node = onnx.helper.make_node(\n 'Pad',\n inputs=['x', 'pads', 'value'],\n outputs=['y'],\n mode='constant'\n)\nx = np.random.randn(1, 3, 4, 5).astype(np.float32)\npads = np.array([0, 0, 1, 3, 0, 0, 2, 4]).astype(np.int64) # pad order [x1_begin, x2_begin, ..., x1_end, x2_end, ...]\nvalue = np.float32(1.2)\ny = pad_impl(\n x,\n pads,\n 'constant',\n 1.2\n)\n\nexpect(node, inputs=[x, pads, value], outputs=[y],\n name='test_constant_pad')" + }, + { + "summary": "reflection_and_edge_pad", + "code": "for mode in ['edge', 'reflect']:\n node = onnx.helper.make_node(\n 'Pad',\n inputs=['x', 'pads'],\n outputs=['y'],\n mode=mode\n )\n x = np.random.randn(1, 3, 4, 5).astype(np.int32)\n pads = np.array([0, 0, 1, 1, 0, 0, 1, 1]).astype(np.int64) # pad order [x1_begin, x2_begin, ..., x1_end, x2_end, ...]\n y = pad_impl(\n x,\n pads,\n mode\n )\n\n expect(node, inputs=[x, pads], outputs=[y],\n name='test_{}_pad'.format(mode))" + } + ], + "category": "Tensor" + }, + { + "name": "Pad", + "module": "ai.onnx", + "version": 13, + "support_level": "common", + "description": "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`,\na padded tensor (`output`) is generated.\n\nThe three supported `modes` are (similar to corresponding modes supported by `numpy.pad`):\n\n1) `constant`(default) - pads with a given constant value as specified by `constant_value` (which defaults to 0, empty string, or False)\n\n2) `reflect` - pads with the reflection of the vector mirrored on the first and last values of the vector along each axis\n\n3) `edge` - pads with the edge values of array\n\n\nExample 1 (`constant` mode):\n Insert 0 pads to the beginning of the second dimension.\n\n data =\n [\n [1.0, 1.2],\n [2.3, 3.4],\n [4.5, 5.7],\n ]\n\n pads = [0, 2, 0, 0]\n\n mode = 'constant'\n\n constant_value = 0.0\n\n output =\n [\n [0.0, 0.0, 1.0, 1.2],\n [0.0, 0.0, 2.3, 3.4],\n [0.0, 0.0, 4.5, 5.7],\n ]\n\n\nExample 2 (`reflect` mode):\n data =\n [\n [1.0, 1.2],\n [2.3, 3.4],\n [4.5, 5.7],\n ]\n\n pads = [0, 2, 0, 0]\n\n mode = 'reflect'\n\n output =\n [\n [1.0, 1.2, 1.0, 1.2],\n [2.3, 3.4, 2.3, 3.4],\n [4.5, 5.7, 4.5, 5.7],\n ]\n\n\nExample 3 (`edge` mode):\n data =\n [\n [1.0, 1.2],\n [2.3, 3.4],\n [4.5, 5.7],\n ]\n\n pads = [0, 2, 0, 0]\n\n mode = 'edge'\n\n output =\n [\n [1.0, 1.0, 1.0, 1.2],\n [2.3, 2.3, 2.3, 3.4],\n [4.5, 4.5, 4.5, 5.7],\n ]\n\n", + "attributes": [ + { + "name": "mode", + "type": "string", + "required": false, + "default": "constant", + "description": "Supported modes: `constant`(default), `reflect`, `edge`" + } + ], + "inputs": [ + { + "name": "data", + "type": "T", + "description": "Input tensor." + }, + { + "name": "pads", + "type": "tensor(int64)", + "description": "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`." + }, + { + "name": "constant_value", + "type": "T", + "option": "optional", + "description": "(Optional) A scalar value to be used if the mode chosen is `constant` (by default it is 0, empty string or False)." + } + ], + "min_input": 2, + "max_input": 3, + "outputs": [ + { + "name": "output", + "type": "T", + "description": "Tensor after padding." + } + ], + "min_output": 1, + "max_output": 1, + "inputs_range": "2 - 3", + "type_constraints": [ + { + "description": "Constrain input and output types to all tensor types.", + "type_param_str": "T", + "allowed_type_strs": [ + "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)" + ] + } + ], + "examples": [ + { + "summary": "constant_pad", + "code": "node = onnx.helper.make_node(\n 'Pad',\n inputs=['x', 'pads', 'value'],\n outputs=['y'],\n mode='constant'\n)\nx = np.random.randn(1, 3, 4, 5).astype(np.float32)\npads = np.array([0, 0, 1, 3, 0, 0, 2, 4]).astype(np.int64) # pad order [x1_begin, x2_begin, ..., x1_end, x2_end, ...]\nvalue = np.float32(1.2)\ny = pad_impl(\n x,\n pads,\n 'constant',\n 1.2\n)\n\nexpect(node, inputs=[x, pads, value], outputs=[y],\n name='test_constant_pad')" + }, + { + "summary": "reflection_and_edge_pad", + "code": "for mode in ['edge', 'reflect']:\n node = onnx.helper.make_node(\n 'Pad',\n inputs=['x', 'pads'],\n outputs=['y'],\n mode=mode\n )\n x = np.random.randn(1, 3, 4, 5).astype(np.int32)\n pads = np.array([0, 0, 1, 1, 0, 0, 1, 1]).astype(np.int64) # pad order [x1_begin, x2_begin, ..., x1_end, x2_end, ...]\n y = pad_impl(\n x,\n pads,\n mode\n )\n\n expect(node, inputs=[x, pads], outputs=[y],\n name='test_{}_pad'.format(mode))" + } + ], + "category": "Tensor" + }, + { + "name": "Pow", + "module": "ai.onnx", + "version": 1, + "support_level": "common", + "description": "Pow takes input data (Tensor) and exponent Tensor, and\nproduces one output data (Tensor) where the function `f(x) = x^exponent`,\nis applied to the data tensor elementwise.\n\nIf necessary the right-hand-side argument will be broadcasted to match the\nshape of left-hand-side argument. When broadcasting is specified, the second\ntensor can either be of element size 1 (including a scalar tensor and any\ntensor with rank equal to or smaller than the first tensor), or having its\nshape as a contiguous subset of the first tensor's shape. The starting of the\nmutually equal shape is specified by the argument \"axis\", and if it is not set,\nsuffix matching is assumed. 1-dim expansion doesn't work yet.\n\nFor example, the following tensor shapes are supported (with broadcast=1):\n\n shape(A) = (2, 3, 4, 5), shape(B) = (,), i.e. B is a scalar tensor\n shape(A) = (2, 3, 4, 5), shape(B) = (1, 1), i.e. B is an 1-element tensor\n shape(A) = (2, 3, 4, 5), shape(B) = (5,)\n shape(A) = (2, 3, 4, 5), shape(B) = (4, 5)\n shape(A) = (2, 3, 4, 5), shape(B) = (3, 4), with axis=1\n shape(A) = (2, 3, 4, 5), shape(B) = (2), with axis=0\n\nAttribute `broadcast=1` needs to be passed to enable broadcasting.\n", + "attributes": [ + { + "name": "axis", + "type": "int64", + "required": false, + "description": "If set, defines the broadcast dimensions. See doc for details." + }, + { + "name": "broadcast", + "type": "int64", + "required": false, + "description": "Pass 1 to enable broadcasting" + } + ], + "inputs": [ + { + "name": "X", + "type": "T", + "description": "Input tensor of any shape, base of the exponent." + }, + { + "name": "Y", + "type": "T", + "description": "Input tensor of any shape broadcastable to X shape, the exponent component." + } + ], + "min_input": 2, + "max_input": 2, + "outputs": [ + { + "name": "Z", + "type": "T", + "description": "Output tensor (same size as X)" + } + ], + "min_output": 1, + "max_output": 1, + "type_constraints": [ + { + "description": "Constrain input and output types to float tensors.", + "type_param_str": "T", + "allowed_type_strs": [ + "tensor(float16)", + "tensor(float)", + "tensor(double)" + ] + } + ], + "examples": [ + { + "summary": "pow", + "code": "node = onnx.helper.make_node(\n 'Pow',\n inputs=['x', 'y'],\n outputs=['z'],\n)\n\nx = np.array([1, 2, 3]).astype(np.float32)\ny = np.array([4, 5, 6]).astype(np.float32)\nz = pow(x, y) # expected output [1., 32., 729.]\nexpect(node, inputs=[x, y], outputs=[z],\n name='test_pow_example')\n\nx = np.arange(60).reshape(3, 4, 5).astype(np.float32)\ny = np.random.randn(3, 4, 5).astype(np.float32)\nz = pow(x, y)\nexpect(node, inputs=[x, y], outputs=[z],\n name='test_pow')" + }, + { + "summary": "pow_broadcast", + "code": "node = onnx.helper.make_node(\n 'Pow',\n inputs=['x', 'y'],\n outputs=['z'],\n)\n\nx = np.array([1, 2, 3]).astype(np.float32)\ny = np.array(2).astype(np.float32)\nz = pow(x, y) # expected output [1., 4., 9.]\nexpect(node, inputs=[x, y], outputs=[z],\n name='test_pow_bcast_scalar')\n\nnode = onnx.helper.make_node(\n 'Pow',\n inputs=['x', 'y'],\n outputs=['z'],\n)\nx = np.array([[1, 2, 3], [4, 5, 6]]).astype(np.float32)\ny = np.array([1, 2, 3]).astype(np.float32)\n# expected output [[1, 4, 27], [4, 25, 216]]\nz = pow(x, y)\nexpect(node, inputs=[x, y], outputs=[z],\n name='test_pow_bcast_array')" + }, + { + "summary": "types", + "code": "node = onnx.helper.make_node(\n 'Pow',\n inputs=['x', 'y'],\n outputs=['z'],\n)\n\nx = np.array([1, 2, 3]).astype(np.float32)\ny = np.array([4, 5, 6]).astype(np.int64)\nz = pow(x, y) # expected output [1., 32., 729.]\nexpect(node, inputs=[x, y], outputs=[z],\n name='test_pow_types_float32_int64')\n\nx = np.array([1, 2, 3]).astype(np.int64)\ny = np.array([4, 5, 6]).astype(np.float32)\nz = pow(x, y) # expected output [1, 32, 729]\nexpect(node, inputs=[x, y], outputs=[z],\n name='test_pow_types_int64_float32')\n\nx = np.array([1, 2, 3]).astype(np.float32)\ny = np.array([4, 5, 6]).astype(np.int32)\nz = pow(x, y) # expected output [1., 32., 729.]\nexpect(node, inputs=[x, y], outputs=[z],\n name='test_pow_types_float32_int32')\n\nx = np.array([1, 2, 3]).astype(np.int32)\ny = np.array([4, 5, 6]).astype(np.float32)\nz = pow(x, y) # expected output [1, 32, 729]\nexpect(node, inputs=[x, y], outputs=[z],\n name='test_pow_types_int32_float32')\n\nx = np.array([1, 2, 3]).astype(np.float32)\ny = np.array([4, 5, 6]).astype(np.uint64)\nz = pow(x, y) # expected output [1., 32., 729.]\nexpect(node, inputs=[x, y], outputs=[z],\n name='test_pow_types_float32_uint64')\n\nx = np.array([1, 2, 3]).astype(np.float32)\ny = np.array([4, 5, 6]).astype(np.uint32)\nz = pow(x, y) # expected output [1., 32., 729.]\nexpect(node, inputs=[x, y], outputs=[z],\n name='test_pow_types_float32_uint32')\n\nx = np.array([1, 2, 3]).astype(np.int64)\ny = np.array([4, 5, 6]).astype(np.int64)\nz = pow(x, y) # expected output [1, 32, 729]\nexpect(node, inputs=[x, y], outputs=[z],\n name='test_pow_types_int64_int64')\n\nx = np.array([1, 2, 3]).astype(np.int32)\ny = np.array([4, 5, 6]).astype(np.int32)\nz = pow(x, y) # expected output [1, 32, 729]\nexpect(node, inputs=[x, y], outputs=[z],\n name='test_pow_types_int32_int32')" + } + ] + }, + { + "name": "Pow", + "module": "ai.onnx", + "version": 7, + "support_level": "common", + "description": "Pow takes input data (Tensor) and exponent Tensor, and\nproduces one output data (Tensor) where the function `f(x) = x^exponent`,\nis applied to the data tensor elementwise.\nThis operator supports **multidirectional (i.e., Numpy-style) broadcasting**; for more details please check [the doc](https://github.com/onnx/onnx/blob/master/docs/Broadcasting.md).", + "inputs": [ + { + "name": "X", + "type": "T", + "description": "First operand, base of the exponent." + }, + { + "name": "Y", + "type": "T", + "description": "Second operand, power of the exponent." + } + ], + "min_input": 2, + "max_input": 2, + "outputs": [ + { + "name": "Z", + "type": "T", + "description": "Output tensor." + } + ], + "min_output": 1, + "max_output": 1, + "type_constraints": [ + { + "description": "Constrain input and output types to float tensors.", + "type_param_str": "T", + "allowed_type_strs": [ + "tensor(float16)", + "tensor(float)", + "tensor(double)" + ] + } + ], + "examples": [ + { + "summary": "pow", + "code": "node = onnx.helper.make_node(\n 'Pow',\n inputs=['x', 'y'],\n outputs=['z'],\n)\n\nx = np.array([1, 2, 3]).astype(np.float32)\ny = np.array([4, 5, 6]).astype(np.float32)\nz = pow(x, y) # expected output [1., 32., 729.]\nexpect(node, inputs=[x, y], outputs=[z],\n name='test_pow_example')\n\nx = np.arange(60).reshape(3, 4, 5).astype(np.float32)\ny = np.random.randn(3, 4, 5).astype(np.float32)\nz = pow(x, y)\nexpect(node, inputs=[x, y], outputs=[z],\n name='test_pow')" + }, + { + "summary": "pow_broadcast", + "code": "node = onnx.helper.make_node(\n 'Pow',\n inputs=['x', 'y'],\n outputs=['z'],\n)\n\nx = np.array([1, 2, 3]).astype(np.float32)\ny = np.array(2).astype(np.float32)\nz = pow(x, y) # expected output [1., 4., 9.]\nexpect(node, inputs=[x, y], outputs=[z],\n name='test_pow_bcast_scalar')\n\nnode = onnx.helper.make_node(\n 'Pow',\n inputs=['x', 'y'],\n outputs=['z'],\n)\nx = np.array([[1, 2, 3], [4, 5, 6]]).astype(np.float32)\ny = np.array([1, 2, 3]).astype(np.float32)\n# expected output [[1, 4, 27], [4, 25, 216]]\nz = pow(x, y)\nexpect(node, inputs=[x, y], outputs=[z],\n name='test_pow_bcast_array')" + }, + { + "summary": "types", + "code": "node = onnx.helper.make_node(\n 'Pow',\n inputs=['x', 'y'],\n outputs=['z'],\n)\n\nx = np.array([1, 2, 3]).astype(np.float32)\ny = np.array([4, 5, 6]).astype(np.int64)\nz = pow(x, y) # expected output [1., 32., 729.]\nexpect(node, inputs=[x, y], outputs=[z],\n name='test_pow_types_float32_int64')\n\nx = np.array([1, 2, 3]).astype(np.int64)\ny = np.array([4, 5, 6]).astype(np.float32)\nz = pow(x, y) # expected output [1, 32, 729]\nexpect(node, inputs=[x, y], outputs=[z],\n name='test_pow_types_int64_float32')\n\nx = np.array([1, 2, 3]).astype(np.float32)\ny = np.array([4, 5, 6]).astype(np.int32)\nz = pow(x, y) # expected output [1., 32., 729.]\nexpect(node, inputs=[x, y], outputs=[z],\n name='test_pow_types_float32_int32')\n\nx = np.array([1, 2, 3]).astype(np.int32)\ny = np.array([4, 5, 6]).astype(np.float32)\nz = pow(x, y) # expected output [1, 32, 729]\nexpect(node, inputs=[x, y], outputs=[z],\n name='test_pow_types_int32_float32')\n\nx = np.array([1, 2, 3]).astype(np.float32)\ny = np.array([4, 5, 6]).astype(np.uint64)\nz = pow(x, y) # expected output [1., 32., 729.]\nexpect(node, inputs=[x, y], outputs=[z],\n name='test_pow_types_float32_uint64')\n\nx = np.array([1, 2, 3]).astype(np.float32)\ny = np.array([4, 5, 6]).astype(np.uint32)\nz = pow(x, y) # expected output [1., 32., 729.]\nexpect(node, inputs=[x, y], outputs=[z],\n name='test_pow_types_float32_uint32')\n\nx = np.array([1, 2, 3]).astype(np.int64)\ny = np.array([4, 5, 6]).astype(np.int64)\nz = pow(x, y) # expected output [1, 32, 729]\nexpect(node, inputs=[x, y], outputs=[z],\n name='test_pow_types_int64_int64')\n\nx = np.array([1, 2, 3]).astype(np.int32)\ny = np.array([4, 5, 6]).astype(np.int32)\nz = pow(x, y) # expected output [1, 32, 729]\nexpect(node, inputs=[x, y], outputs=[z],\n name='test_pow_types_int32_int32')" + } + ] + }, + { + "name": "Pow", + "module": "ai.onnx", + "version": 12, + "support_level": "common", + "description": "Pow takes input data (Tensor) and exponent Tensor, and\nproduces one output data (Tensor) where the function `f(x) = x^exponent`,\nis applied to the data tensor elementwise.\nThis operator supports **multidirectional (i.e., Numpy-style) broadcasting**; for more details please check [the doc](https://github.com/onnx/onnx/blob/master/docs/Broadcasting.md).", + "inputs": [ + { + "name": "X", + "type": "T", + "description": "First operand, base of the exponent." + }, + { + "name": "Y", + "type": "T1", + "description": "Second operand, power of the exponent." + } + ], + "min_input": 2, + "max_input": 2, + "outputs": [ + { + "name": "Z", + "type": "T", + "description": "Output tensor." + } + ], + "min_output": 1, + "max_output": 1, + "type_constraints": [ + { + "description": "Constrain input X and output types to float/int tensors.", + "type_param_str": "T", + "allowed_type_strs": [ + "tensor(int32)", + "tensor(int64)", + "tensor(float16)", + "tensor(float)", + "tensor(double)" + ] + }, + { + "description": "Constrain input Y types to float/int tensors.", + "type_param_str": "T1", + "allowed_type_strs": [ + "tensor(uint8)", + "tensor(uint16)", + "tensor(uint32)", + "tensor(uint64)", + "tensor(int8)", + "tensor(int16)", + "tensor(int32)", + "tensor(int64)", + "tensor(float16)", + "tensor(float)", + "tensor(double)" + ] + } + ], + "examples": [ + { + "summary": "pow", + "code": "node = onnx.helper.make_node(\n 'Pow',\n inputs=['x', 'y'],\n outputs=['z'],\n)\n\nx = np.array([1, 2, 3]).astype(np.float32)\ny = np.array([4, 5, 6]).astype(np.float32)\nz = pow(x, y) # expected output [1., 32., 729.]\nexpect(node, inputs=[x, y], outputs=[z],\n name='test_pow_example')\n\nx = np.arange(60).reshape(3, 4, 5).astype(np.float32)\ny = np.random.randn(3, 4, 5).astype(np.float32)\nz = pow(x, y)\nexpect(node, inputs=[x, y], outputs=[z],\n name='test_pow')" + }, + { + "summary": "pow_broadcast", + "code": "node = onnx.helper.make_node(\n 'Pow',\n inputs=['x', 'y'],\n outputs=['z'],\n)\n\nx = np.array([1, 2, 3]).astype(np.float32)\ny = np.array(2).astype(np.float32)\nz = pow(x, y) # expected output [1., 4., 9.]\nexpect(node, inputs=[x, y], outputs=[z],\n name='test_pow_bcast_scalar')\n\nnode = onnx.helper.make_node(\n 'Pow',\n inputs=['x', 'y'],\n outputs=['z'],\n)\nx = np.array([[1, 2, 3], [4, 5, 6]]).astype(np.float32)\ny = np.array([1, 2, 3]).astype(np.float32)\n# expected output [[1, 4, 27], [4, 25, 216]]\nz = pow(x, y)\nexpect(node, inputs=[x, y], outputs=[z],\n name='test_pow_bcast_array')" + }, + { + "summary": "types", + "code": "node = onnx.helper.make_node(\n 'Pow',\n inputs=['x', 'y'],\n outputs=['z'],\n)\n\nx = np.array([1, 2, 3]).astype(np.float32)\ny = np.array([4, 5, 6]).astype(np.int64)\nz = pow(x, y) # expected output [1., 32., 729.]\nexpect(node, inputs=[x, y], outputs=[z],\n name='test_pow_types_float32_int64')\n\nx = np.array([1, 2, 3]).astype(np.int64)\ny = np.array([4, 5, 6]).astype(np.float32)\nz = pow(x, y) # expected output [1, 32, 729]\nexpect(node, inputs=[x, y], outputs=[z],\n name='test_pow_types_int64_float32')\n\nx = np.array([1, 2, 3]).astype(np.float32)\ny = np.array([4, 5, 6]).astype(np.int32)\nz = pow(x, y) # expected output [1., 32., 729.]\nexpect(node, inputs=[x, y], outputs=[z],\n name='test_pow_types_float32_int32')\n\nx = np.array([1, 2, 3]).astype(np.int32)\ny = np.array([4, 5, 6]).astype(np.float32)\nz = pow(x, y) # expected output [1, 32, 729]\nexpect(node, inputs=[x, y], outputs=[z],\n name='test_pow_types_int32_float32')\n\nx = np.array([1, 2, 3]).astype(np.float32)\ny = np.array([4, 5, 6]).astype(np.uint64)\nz = pow(x, y) # expected output [1., 32., 729.]\nexpect(node, inputs=[x, y], outputs=[z],\n name='test_pow_types_float32_uint64')\n\nx = np.array([1, 2, 3]).astype(np.float32)\ny = np.array([4, 5, 6]).astype(np.uint32)\nz = pow(x, y) # expected output [1., 32., 729.]\nexpect(node, inputs=[x, y], outputs=[z],\n name='test_pow_types_float32_uint32')\n\nx = np.array([1, 2, 3]).astype(np.int64)\ny = np.array([4, 5, 6]).astype(np.int64)\nz = pow(x, y) # expected output [1, 32, 729]\nexpect(node, inputs=[x, y], outputs=[z],\n name='test_pow_types_int64_int64')\n\nx = np.array([1, 2, 3]).astype(np.int32)\ny = np.array([4, 5, 6]).astype(np.int32)\nz = pow(x, y) # expected output [1, 32, 729]\nexpect(node, inputs=[x, y], outputs=[z],\n name='test_pow_types_int32_int32')" + } + ] + }, + { + "name": "Pow", + "module": "ai.onnx", + "version": 13, + "support_level": "common", + "description": "Pow takes input data (Tensor) and exponent Tensor, and\nproduces one output data (Tensor) where the function `f(x) = x^exponent`,\nis applied to the data tensor elementwise.\nThis operator supports **multidirectional (i.e., Numpy-style) broadcasting**; for more details please check [the doc](https://github.com/onnx/onnx/blob/master/docs/Broadcasting.md).", + "inputs": [ + { + "name": "X", + "type": "T", + "description": "First operand, base of the exponent." + }, + { + "name": "Y", + "type": "T1", + "description": "Second operand, power of the exponent." + } + ], + "min_input": 2, + "max_input": 2, + "outputs": [ + { + "name": "Z", + "type": "T", + "description": "Output tensor" + } + ], + "min_output": 1, + "max_output": 1, + "type_constraints": [ + { + "description": "Constrain input X and output types to float/int tensors.", + "type_param_str": "T", + "allowed_type_strs": [ + "tensor(int32)", + "tensor(int64)", + "tensor(float16)", + "tensor(float)", + "tensor(double)", + "tensor(bfloat16)" + ] + }, + { + "description": "Constrain input Y types to float/int tensors.", + "type_param_str": "T1", + "allowed_type_strs": [ + "tensor(uint8)", + "tensor(uint16)", + "tensor(uint32)", + "tensor(uint64)", + "tensor(int8)", + "tensor(int16)", + "tensor(int32)", + "tensor(int64)", + "tensor(float16)", + "tensor(float)", + "tensor(double)" + ] + } + ], + "examples": [ + { + "summary": "pow", + "code": "node = onnx.helper.make_node(\n 'Pow',\n inputs=['x', 'y'],\n outputs=['z'],\n)\n\nx = np.array([1, 2, 3]).astype(np.float32)\ny = np.array([4, 5, 6]).astype(np.float32)\nz = pow(x, y) # expected output [1., 32., 729.]\nexpect(node, inputs=[x, y], outputs=[z],\n name='test_pow_example')\n\nx = np.arange(60).reshape(3, 4, 5).astype(np.float32)\ny = np.random.randn(3, 4, 5).astype(np.float32)\nz = pow(x, y)\nexpect(node, inputs=[x, y], outputs=[z],\n name='test_pow')" + }, + { + "summary": "pow_broadcast", + "code": "node = onnx.helper.make_node(\n 'Pow',\n inputs=['x', 'y'],\n outputs=['z'],\n)\n\nx = np.array([1, 2, 3]).astype(np.float32)\ny = np.array(2).astype(np.float32)\nz = pow(x, y) # expected output [1., 4., 9.]\nexpect(node, inputs=[x, y], outputs=[z],\n name='test_pow_bcast_scalar')\n\nnode = onnx.helper.make_node(\n 'Pow',\n inputs=['x', 'y'],\n outputs=['z'],\n)\nx = np.array([[1, 2, 3], [4, 5, 6]]).astype(np.float32)\ny = np.array([1, 2, 3]).astype(np.float32)\n# expected output [[1, 4, 27], [4, 25, 216]]\nz = pow(x, y)\nexpect(node, inputs=[x, y], outputs=[z],\n name='test_pow_bcast_array')" + }, + { + "summary": "types", + "code": "node = onnx.helper.make_node(\n 'Pow',\n inputs=['x', 'y'],\n outputs=['z'],\n)\n\nx = np.array([1, 2, 3]).astype(np.float32)\ny = np.array([4, 5, 6]).astype(np.int64)\nz = pow(x, y) # expected output [1., 32., 729.]\nexpect(node, inputs=[x, y], outputs=[z],\n name='test_pow_types_float32_int64')\n\nx = np.array([1, 2, 3]).astype(np.int64)\ny = np.array([4, 5, 6]).astype(np.float32)\nz = pow(x, y) # expected output [1, 32, 729]\nexpect(node, inputs=[x, y], outputs=[z],\n name='test_pow_types_int64_float32')\n\nx = np.array([1, 2, 3]).astype(np.float32)\ny = np.array([4, 5, 6]).astype(np.int32)\nz = pow(x, y) # expected output [1., 32., 729.]\nexpect(node, inputs=[x, y], outputs=[z],\n name='test_pow_types_float32_int32')\n\nx = np.array([1, 2, 3]).astype(np.int32)\ny = np.array([4, 5, 6]).astype(np.float32)\nz = pow(x, y) # expected output [1, 32, 729]\nexpect(node, inputs=[x, y], outputs=[z],\n name='test_pow_types_int32_float32')\n\nx = np.array([1, 2, 3]).astype(np.float32)\ny = np.array([4, 5, 6]).astype(np.uint64)\nz = pow(x, y) # expected output [1., 32., 729.]\nexpect(node, inputs=[x, y], outputs=[z],\n name='test_pow_types_float32_uint64')\n\nx = np.array([1, 2, 3]).astype(np.float32)\ny = np.array([4, 5, 6]).astype(np.uint32)\nz = pow(x, y) # expected output [1., 32., 729.]\nexpect(node, inputs=[x, y], outputs=[z],\n name='test_pow_types_float32_uint32')\n\nx = np.array([1, 2, 3]).astype(np.int64)\ny = np.array([4, 5, 6]).astype(np.int64)\nz = pow(x, y) # expected output [1, 32, 729]\nexpect(node, inputs=[x, y], outputs=[z],\n name='test_pow_types_int64_int64')\n\nx = np.array([1, 2, 3]).astype(np.int32)\ny = np.array([4, 5, 6]).astype(np.int32)\nz = pow(x, y) # expected output [1, 32, 729]\nexpect(node, inputs=[x, y], outputs=[z],\n name='test_pow_types_int32_int32')" + } + ] + }, + { + "name": "Pow", + "module": "ai.onnx", + "version": 15, + "support_level": "common", + "description": "Pow takes input data (Tensor) and exponent Tensor, and\nproduces one output data (Tensor) where the function `f(x) = x^exponent`,\nis applied to the data tensor elementwise.\nThis operator supports **multidirectional (i.e., Numpy-style) broadcasting**; for more details please check [the doc](https://github.com/onnx/onnx/blob/master/docs/Broadcasting.md).", + "inputs": [ + { + "name": "X", + "type": "T", + "description": "First operand, base of the exponent." + }, + { + "name": "Y", + "type": "T1", + "description": "Second operand, power of the exponent." + } + ], + "min_input": 2, + "max_input": 2, + "outputs": [ + { + "name": "Z", + "type": "T", + "description": "Output tensor" + } + ], + "min_output": 1, + "max_output": 1, + "type_constraints": [ + { + "description": "Constrain input X and output types to float/int tensors.", + "type_param_str": "T", + "allowed_type_strs": [ + "tensor(int32)", + "tensor(int64)", + "tensor(float16)", + "tensor(float)", + "tensor(double)", + "tensor(bfloat16)" + ] + }, + { + "description": "Constrain input Y types to float/int tensors.", + "type_param_str": "T1", + "allowed_type_strs": [ + "tensor(uint8)", + "tensor(uint16)", + "tensor(uint32)", + "tensor(uint64)", + "tensor(int8)", + "tensor(int16)", + "tensor(int32)", + "tensor(int64)", + "tensor(float16)", + "tensor(float)", + "tensor(double)", + "tensor(bfloat16)" + ] + } + ], + "examples": [ + { + "summary": "pow", + "code": "node = onnx.helper.make_node(\n 'Pow',\n inputs=['x', 'y'],\n outputs=['z'],\n)\n\nx = np.array([1, 2, 3]).astype(np.float32)\ny = np.array([4, 5, 6]).astype(np.float32)\nz = pow(x, y) # expected output [1., 32., 729.]\nexpect(node, inputs=[x, y], outputs=[z],\n name='test_pow_example')\n\nx = np.arange(60).reshape(3, 4, 5).astype(np.float32)\ny = np.random.randn(3, 4, 5).astype(np.float32)\nz = pow(x, y)\nexpect(node, inputs=[x, y], outputs=[z],\n name='test_pow')" + }, + { + "summary": "pow_broadcast", + "code": "node = onnx.helper.make_node(\n 'Pow',\n inputs=['x', 'y'],\n outputs=['z'],\n)\n\nx = np.array([1, 2, 3]).astype(np.float32)\ny = np.array(2).astype(np.float32)\nz = pow(x, y) # expected output [1., 4., 9.]\nexpect(node, inputs=[x, y], outputs=[z],\n name='test_pow_bcast_scalar')\n\nnode = onnx.helper.make_node(\n 'Pow',\n inputs=['x', 'y'],\n outputs=['z'],\n)\nx = np.array([[1, 2, 3], [4, 5, 6]]).astype(np.float32)\ny = np.array([1, 2, 3]).astype(np.float32)\n# expected output [[1, 4, 27], [4, 25, 216]]\nz = pow(x, y)\nexpect(node, inputs=[x, y], outputs=[z],\n name='test_pow_bcast_array')" + }, + { + "summary": "types", + "code": "node = onnx.helper.make_node(\n 'Pow',\n inputs=['x', 'y'],\n outputs=['z'],\n)\n\nx = np.array([1, 2, 3]).astype(np.float32)\ny = np.array([4, 5, 6]).astype(np.int64)\nz = pow(x, y) # expected output [1., 32., 729.]\nexpect(node, inputs=[x, y], outputs=[z],\n name='test_pow_types_float32_int64')\n\nx = np.array([1, 2, 3]).astype(np.int64)\ny = np.array([4, 5, 6]).astype(np.float32)\nz = pow(x, y) # expected output [1, 32, 729]\nexpect(node, inputs=[x, y], outputs=[z],\n name='test_pow_types_int64_float32')\n\nx = np.array([1, 2, 3]).astype(np.float32)\ny = np.array([4, 5, 6]).astype(np.int32)\nz = pow(x, y) # expected output [1., 32., 729.]\nexpect(node, inputs=[x, y], outputs=[z],\n name='test_pow_types_float32_int32')\n\nx = np.array([1, 2, 3]).astype(np.int32)\ny = np.array([4, 5, 6]).astype(np.float32)\nz = pow(x, y) # expected output [1, 32, 729]\nexpect(node, inputs=[x, y], outputs=[z],\n name='test_pow_types_int32_float32')\n\nx = np.array([1, 2, 3]).astype(np.float32)\ny = np.array([4, 5, 6]).astype(np.uint64)\nz = pow(x, y) # expected output [1., 32., 729.]\nexpect(node, inputs=[x, y], outputs=[z],\n name='test_pow_types_float32_uint64')\n\nx = np.array([1, 2, 3]).astype(np.float32)\ny = np.array([4, 5, 6]).astype(np.uint32)\nz = pow(x, y) # expected output [1., 32., 729.]\nexpect(node, inputs=[x, y], outputs=[z],\n name='test_pow_types_float32_uint32')\n\nx = np.array([1, 2, 3]).astype(np.int64)\ny = np.array([4, 5, 6]).astype(np.int64)\nz = pow(x, y) # expected output [1, 32, 729]\nexpect(node, inputs=[x, y], outputs=[z],\n name='test_pow_types_int64_int64')\n\nx = np.array([1, 2, 3]).astype(np.int32)\ny = np.array([4, 5, 6]).astype(np.int32)\nz = pow(x, y) # expected output [1, 32, 729]\nexpect(node, inputs=[x, y], outputs=[z],\n name='test_pow_types_int32_int32')" + } + ] + }, + { + "name": "QLinearConv", + "module": "ai.onnx", + "version": 10, + "support_level": "common", + "description": "The convolution operator consumes a quantized input tensor, its scale and zero point,\na quantized filter, its scale and zero point, and output's scale and zero point,\nand computes the quantized output. Each scale and zero-point pair must have same shape.\nIt means they must be either scalars (per tensor) or 1-D tensors (per output channel).\nEach input or output and its related zero point must have same type.\nWhen bias is present it must be quantized using scale = input scale * weight scale and\nzero point as 0.\n", + "attributes": [ + { + "name": "auto_pad", + "type": "string", + "required": false, + "default": "NOTSET", + "description": "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." + }, + { + "name": "dilations", + "type": "int64[]", + "required": false, + "description": "dilation value along each spatial axis of the filter. If not present, the dilation defaults to 1 along each spatial axis." + }, + { + "name": "group", + "type": "int64", + "required": false, + "default": 1, + "description": "number of groups input channels and output channels are divided into. default is 1." + }, + { + "name": "kernel_shape", + "type": "int64[]", + "required": false, + "description": "The shape of the convolution kernel. If not present, should be inferred from input 'w'." + }, + { + "name": "pads", + "type": "int64[]", + "required": false, + "description": "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." + }, + { + "name": "strides", + "type": "int64[]", + "required": false, + "description": "Stride along each spatial axis. If not present, the stride defaults to 1 along each spatial axis." + } + ], + "inputs": [ + { + "name": "x", + "type": "T1", + "description": "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 ...]." + }, + { + "name": "x_scale", + "type": "tensor(float)", + "description": "Scale tensor for input 'x'. It's a scalar, which means a per-tensor/layer quantization." + }, + { + "name": "x_zero_point", + "type": "T1", + "description": "Zero point tensor for input 'x'. It's a scalar, which means a per-tensor/layer quantization." + }, + { + "name": "w", + "type": "T2", + "description": "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. " + }, + { + "name": "w_scale", + "type": "tensor(float)", + "description": "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)." + }, + { + "name": "w_zero_point", + "type": "T2", + "description": "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)." + }, + { + "name": "y_scale", + "type": "tensor(float)", + "description": "Scale tensor for output 'y'. It's a scalar, which means a per-tensor/layer quantization." + }, + { + "name": "y_zero_point", + "type": "T3", + "description": "Zero point tensor for output 'y'. It's a scalar, which means a per-tensor/layer quantization." + }, + { + "name": "B", + "type": "T4", + "option": "optional", + "description": "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" + } + ], + "min_input": 8, + "max_input": 9, + "outputs": [ + { + "name": "y", + "type": "T3", + "description": "Output data tensor that contains the result of the convolution. The output dimensions are functions of the kernel size, stride size, and pad lengths." + } + ], + "min_output": 1, + "max_output": 1, + "inputs_range": "8 - 9", + "type_constraints": [ + { + "description": "Constrain input type to 8-bit integer tensor.", + "type_param_str": "T1", + "allowed_type_strs": [ + "tensor(int8)", + "tensor(uint8)" + ] + }, + { + "description": "Constrain filter type to 8-bit integer tensor.", + "type_param_str": "T2", + "allowed_type_strs": [ + "tensor(int8)", + "tensor(uint8)" + ] + }, + { + "description": "Constrain output type to 8-bit integer tensor.", + "type_param_str": "T3", + "allowed_type_strs": [ + "tensor(int8)", + "tensor(uint8)" + ] + }, + { + "description": "Constrain bias type to 32-bit integer tensor.", + "type_param_str": "T4", + "allowed_type_strs": [ + "tensor(int32)" + ] + } + ], + "examples": [ + { + "summary": "qlinearconv", + "code": "node = onnx.helper.make_node('QLinearConv',\n inputs=['x', 'x_scale', 'x_zero_point', 'w', 'w_scale', 'w_zero_point', 'y_scale', 'y_zero_point'],\n outputs=['y'],)\n\nx = np.array([[255, 174, 162, 25, 203, 168, 58],\n [15, 59, 237, 95, 129, 0, 64],\n [56, 242, 153, 221, 168, 12, 166],\n [232, 178, 186, 195, 237, 162, 237],\n [188, 39, 124, 77, 80, 102, 43],\n [127, 230, 21, 83, 41, 40, 134],\n [255, 154, 92, 141, 42, 148, 247], ], dtype=np.uint8).reshape((1, 1, 7, 7))\n\nx_scale = np.float32(0.00369204697)\nx_zero_point = np.uint8(132)\n\nw = np.array([0], dtype=np.uint8).reshape((1, 1, 1, 1))\n\nw_scale = np.array([0.00172794575], dtype=np.float32)\nw_zero_point = np.array([255], dtype=np.uint8)\n\ny_scale = np.float32(0.00162681262)\ny_zero_point = np.uint8(123)\n\noutput = np.array([[0, 81, 93, 230, 52, 87, 197],\n [240, 196, 18, 160, 126, 255, 191],\n [199, 13, 102, 34, 87, 243, 89],\n [23, 77, 69, 60, 18, 93, 18],\n [67, 216, 131, 178, 175, 153, 212],\n [128, 25, 234, 172, 214, 215, 121],\n [0, 101, 163, 114, 213, 107, 8], ], dtype=np.uint8).reshape((1, 1, 7, 7))\n\nexpect(node, inputs=[x, x_scale, x_zero_point, w, w_scale, w_zero_point, y_scale, y_zero_point], outputs=[output],\n name='test_qlinearconv')" + } + ] + }, + { + "name": "QLinearMatMul", + "module": "ai.onnx", + "version": 10, + "support_level": "common", + "description": "Matrix product that behaves like numpy.matmul: https://docs.scipy.org/doc/numpy-1.13.0/reference/generated/numpy.matmul.html.\nIt consumes two quantized input tensors, their scales and zero points, scale and zero point of output, \nand computes the quantized output. The quantization formula is y = saturate((x / y_scale) + y_zero_point). \nFor (x / y_scale), it is rounding to nearest ties to even. Refer to https://en.wikipedia.org/wiki/Rounding for details. \nScale and zero point must have same shape. They must be either scalar (per tensor) or N-D tensor \n(per row for 'a' and per column for 'b'). Scalar refers to per tensor quantization whereas N-D refers to per row \nor per column quantization. If the input is 2D of shape [M, K] then zero point and scale tensor may be \nan 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] \nfor per column quantization. If the input is N-D tensor with shape [D1, D2, M, K] then zero point and scale tensor may \nhave shape [D1, D2, M, 1] for per row quantization and shape [D1, D2, 1, K] for per column quantization.\nProduction must never overflow, and accumulation may overflow if and only if in 32 bits.\n", + "inputs": [ + { + "name": "a", + "type": "T1", + "description": "N-dimensional quantized matrix a" + }, + { + "name": "a_scale", + "type": "tensor(float)", + "description": "scale of quantized input a" + }, + { + "name": "a_zero_point", + "type": "T1", + "description": "zero point of quantized input a" + }, + { + "name": "b", + "type": "T2", + "description": "N-dimensional quantized matrix b" + }, + { + "name": "b_scale", + "type": "tensor(float)", + "description": "scale of quantized input b" + }, + { + "name": "b_zero_point", + "type": "T2", + "description": "zero point of quantized input b" + }, + { + "name": "y_scale", + "type": "tensor(float)", + "description": "scale of quantized output y" + }, + { + "name": "y_zero_point", + "type": "T3", + "description": "zero point of quantized output y" + } + ], + "min_input": 8, + "max_input": 8, + "outputs": [ + { + "name": "y", + "type": "T3", + "description": "Quantized matrix multiply results from a * b" + } + ], + "min_output": 1, + "max_output": 1, + "type_constraints": [ + { + "description": "Constrain input a and its zero point data type to 8-bit integer tensor.", + "type_param_str": "T1", + "allowed_type_strs": [ + "tensor(int8)", + "tensor(uint8)" + ] + }, + { + "description": "Constrain input b and its zero point data type to 8-bit integer tensor.", + "type_param_str": "T2", + "allowed_type_strs": [ + "tensor(int8)", + "tensor(uint8)" + ] + }, + { + "description": "Constrain output y and its zero point data type to 8-bit integer tensor.", + "type_param_str": "T3", + "allowed_type_strs": [ + "tensor(int8)", + "tensor(uint8)" + ] + } + ], + "examples": [ + { + "summary": "qlinearmatmul", + "code": "node = onnx.helper.make_node('QLinearMatMul',\n inputs=['a', 'a_scale', 'a_zero_point', 'b', 'b_scale', 'b_zero_point', 'y_scale', 'y_zero_point'],\n outputs=['y'],)\n\n#2D\na = np.array([[208, 236, 0, 238],\n [3, 214, 255, 29], ], dtype=np.uint8)\n\na_scale = np.array([0.0066], dtype=np.float32)\na_zero_point = np.array([113], dtype=np.uint8)\n\nb = np.array([[152, 51, 244],\n [60, 26, 255],\n [0, 127, 246],\n [127, 254, 247]], dtype=np.uint8)\n\nb_scale = np.array([0.00705], dtype=np.float32)\nb_zero_point = np.array([114], dtype=np.uint8)\n\ny_scale = np.array([0.0107], dtype=np.float32)\ny_zero_point = np.array([118], dtype=np.uint8)\n\noutput = np.array([[168, 115, 255],\n [1, 66, 151], ], dtype=np.uint8)\n\nexpect(node, inputs=[a, a_scale, a_zero_point, b, b_scale, b_zero_point, y_scale, y_zero_point], outputs=[output],\n name='test_qlinearmatmul_2D')\n\n#3D\na = np.array([[[208, 236, 0, 238],\n [3, 214, 255, 29]],\n [[208, 236, 0, 238],\n [3, 214, 255, 29]]], dtype=np.uint8)\n\na_scale = np.array([0.0066], dtype=np.float32)\na_zero_point = np.array([113], dtype=np.uint8)\n\nb = np.array([[[152, 51, 244],\n [60, 26, 255],\n [0, 127, 246],\n [127, 254, 247]],\n [[152, 51, 244],\n [60, 26, 255],\n [0, 127, 246],\n [127, 254, 247]]], dtype=np.uint8)\n\nb_scale = np.array([0.00705], dtype=np.float32)\nb_zero_point = np.array([114], dtype=np.uint8)\n\ny_scale = np.array([0.0107], dtype=np.float32)\ny_zero_point = np.array([118], dtype=np.uint8)\n\noutput = np.array([[[168, 115, 255],\n [1, 66, 151]],\n [[168, 115, 255],\n [1, 66, 151]]], dtype=np.uint8)\n\nexpect(node, inputs=[a, a_scale, a_zero_point, b, b_scale, b_zero_point, y_scale, y_zero_point], outputs=[output],\n name='test_qlinearmatmul_3D')" + } + ] + }, + { + "name": "QuantizeLinear", + "module": "ai.onnx", + "version": 10, + "support_level": "common", + "description": "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.\nThe 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.\nFor (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.\n", + "inputs": [ + { + "name": "x", + "type": "T1", + "description": "N-D full precision Input tensor to be quantized." + }, + { + "name": "y_scale", + "type": "tensor(float)", + "description": "Scale for doing quantization to get 'y'. It's a scalar, which means a per-tensor/layer quantization." + }, + { + "name": "y_zero_point", + "type": "T2", + "option": "optional", + "description": "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." + } + ], + "min_input": 2, + "max_input": 3, + "outputs": [ + { + "name": "y", + "type": "T2", + "description": "N-D quantized output tensor. It has same shape as input 'x'." + } + ], + "min_output": 1, + "max_output": 1, + "inputs_range": "2 - 3", + "type_constraints": [ + { + "description": "Constrain 'x' to float or int32 tensor.", + "type_param_str": "T1", + "allowed_type_strs": [ + "tensor(float)", + "tensor(int32)" + ] + }, + { + "description": "Constrain 'y_zero_point' and 'y' to 8-bit integer tensor.", + "type_param_str": "T2", + "allowed_type_strs": [ + "tensor(int8)", + "tensor(uint8)" + ] + } + ], + "examples": [ + { + "summary": "axis", + "code": "node = onnx.helper.make_node('QuantizeLinear',\n inputs=['x', 'y_scale', 'y_zero_point'],\n outputs=['y'],)\n\nx = np.array([[[[-162, 10],\n [-100, 232],\n [-20, -50]],\n\n [[-76, 0],\n [0, 252],\n [32, -44]],\n\n [[245, -485],\n [-960, -270],\n [-375, -470]], ], ], dtype=np.float32)\ny_scale = np.array([2, 4, 5], dtype=np.float32)\ny_zero_point = np.array([84, 24, 196], dtype=np.uint8)\ny = (x / y_scale.reshape(1, 3, 1, 1) + y_zero_point.reshape(1, 3, 1, 1)).astype(np.uint8)\n\nexpect(node, inputs=[x, y_scale, y_zero_point], outputs=[y],\n name='test_quantizelinear_axis')" + }, + { + "summary": "quantizelinear", + "code": "node = onnx.helper.make_node('QuantizeLinear',\n inputs=['x', 'y_scale', 'y_zero_point'],\n outputs=['y'],)\n\nx = np.array([0, 2, 3, 1000, -254, -1000]).astype(np.float32)\ny_scale = np.float32(2)\ny_zero_point = np.uint8(128)\ny = np.array([128, 129, 130, 255, 1, 0]).astype(np.uint8)\n\nexpect(node, inputs=[x, y_scale, y_zero_point], outputs=[y],\n name='test_quantizelinear')" + } + ] + }, + { + "name": "QuantizeLinear", + "module": "ai.onnx", + "version": 13, + "support_level": "common", + "description": "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 can be a scalar\n(per-tensor/layer quantization), or a 1-D tensor for per-axis quantization. The quantization formula is y = saturate ((x / y_scale) + y_zero_point).\nFor saturation, it saturates to [0, 255] if it's uint8, or [-128, 127] if it's int8.\nFor (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.\n", + "attributes": [ + { + "name": "axis", + "type": "int64", + "required": false, + "default": 1, + "description": "(Optional) The axis of the quantization dimension of the input tensor. Negative value means counting dimensions from the back. Accepted range is [-r, r-1] where r = rank(input). If both y_scale and y_zero_point are scalars, axis is ignored." + } + ], + "inputs": [ + { + "name": "x", + "type": "T1", + "description": "N-D full precision Input tensor to be quantized." + }, + { + "name": "y_scale", + "type": "tensor(float)", + "description": "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." + }, + { + "name": "y_zero_point", + "type": "T2", + "option": "optional", + "description": "Zero point for doing quantization to get 'y'. It can be a scalar, which means a per-tensor/layer quantization, or a 1-D tensor for per-axis quantization. Default value is uint8 typed 0 if it's not specified." + } + ], + "min_input": 2, + "max_input": 3, + "outputs": [ + { + "name": "y", + "type": "T2", + "description": "N-D quantized output tensor. It has same shape as input 'x'." + } + ], + "min_output": 1, + "max_output": 1, + "inputs_range": "2 - 3", + "type_constraints": [ + { + "description": "Constrain 'x' to float or int32 tensor.", + "type_param_str": "T1", + "allowed_type_strs": [ + "tensor(float)", + "tensor(int32)" + ] + }, + { + "description": "Constrain 'y_zero_point' and 'y' to 8-bit integer tensor.", + "type_param_str": "T2", + "allowed_type_strs": [ + "tensor(int8)", + "tensor(uint8)" + ] + } + ], + "examples": [ + { + "summary": "axis", + "code": "node = onnx.helper.make_node('QuantizeLinear',\n inputs=['x', 'y_scale', 'y_zero_point'],\n outputs=['y'],)\n\nx = np.array([[[[-162, 10],\n [-100, 232],\n [-20, -50]],\n\n [[-76, 0],\n [0, 252],\n [32, -44]],\n\n [[245, -485],\n [-960, -270],\n [-375, -470]], ], ], dtype=np.float32)\ny_scale = np.array([2, 4, 5], dtype=np.float32)\ny_zero_point = np.array([84, 24, 196], dtype=np.uint8)\ny = (x / y_scale.reshape(1, 3, 1, 1) + y_zero_point.reshape(1, 3, 1, 1)).astype(np.uint8)\n\nexpect(node, inputs=[x, y_scale, y_zero_point], outputs=[y],\n name='test_quantizelinear_axis')" + }, + { + "summary": "quantizelinear", + "code": "node = onnx.helper.make_node('QuantizeLinear',\n inputs=['x', 'y_scale', 'y_zero_point'],\n outputs=['y'],)\n\nx = np.array([0, 2, 3, 1000, -254, -1000]).astype(np.float32)\ny_scale = np.float32(2)\ny_zero_point = np.uint8(128)\ny = np.array([128, 129, 130, 255, 1, 0]).astype(np.uint8)\n\nexpect(node, inputs=[x, y_scale, y_zero_point], outputs=[y],\n name='test_quantizelinear')" + } + ] + }, + { + "name": "RNN", + "module": "ai.onnx", + "version": 1, + "support_level": "common", + "description": "Computes an one-layer simple RNN. This operator is usually supported\nvia some custom implementation such as CuDNN.\n\nNotations:\n\n`X` - input tensor\n\n`i` - input gate\n\n`t` - time step (t-1 means previous time step)\n\n`Wi` - W parameter weight matrix for input gate\n\n`Ri` - R recurrence weight matrix for input gate\n\n`Wbi` - W parameter bias vector for input gate\n\n`Rbi` - R parameter bias vector for input gate\n\n`WBi` - W parameter weight matrix for backward input gate\n\n`RBi` - R recurrence weight matrix for backward input gate\n\n`WBbi` - WR bias vectors for backward input gate\n\n`RBbi` - RR bias vectors for backward input gate\n\n`H` - Hidden state\n\n`num_directions` - 2 if direction == bidirectional else 1\n\nActivation functions:\n\n Relu(x) - max(0, x)\n\n Tanh(x) - (1 - e^{-2x})/(1 + e^{-2x})\n\n Sigmoid(x) - 1/(1 + e^{-x})\n\n (NOTE: Below are optional)\n\n Affine(x) - alpha*x + beta\n\n LeakyRelu(x) - x if x >= 0 else alpha * x\n\n ThresholdedRelu(x) - x if x >= alpha else 0\n\n ScaledTanh(x) - alpha*Tanh(beta*x)\n\n HardSigmoid(x) - min(max(alpha*x + beta, 0), 1)\n\n Elu(x) - x if x >= 0 else alpha*(e^x - 1)\n\n Softsign(x) - x/(1 + |x|)\n\n Softplus(x) - log(1 + e^x)\n\nEquations (Default: f=Tanh):\n\n - Ht = f(Xt*(Wi^T) + Ht-1*Ri + Wbi + Rbi)\n", + "attributes": [ + { + "name": "activation_alpha", + "type": "float32[]", + "required": false, + "description": "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." + }, + { + "name": "activation_beta", + "type": "float32[]", + "required": false, + "description": "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." + }, + { + "name": "activations", + "type": "string[]", + "required": false, + "description": "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." + }, + { + "name": "clip", + "type": "float32", + "required": false, + "description": "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." + }, + { + "name": "direction", + "type": "string", + "required": false, + "default": "forward", + "description": "Specify if the RNN is forward, reverse, or bidirectional. Must be one of forward (default), reverse, or bidirectional." + }, + { + "name": "hidden_size", + "type": "int64", + "required": false, + "description": "Number of neurons in the hidden layer" + }, + { + "name": "output_sequence", + "type": "int64", + "required": false, + "description": "The sequence output for the hidden is optional if 0. Default 0." + } + ], + "inputs": [ + { + "name": "X", + "type": "T", + "description": "The input sequences packed (and potentially padded) into one 3-D tensor with the shape of `[seq_length, batch_size, input_size]`." + }, + { + "name": "W", + "type": "T", + "description": "The weight tensor for input gate. Concatenation of `Wi` and `WBi` (if bidirectional). The tensor has shape `[num_directions, hidden_size, input_size]`." + }, + { + "name": "R", + "type": "T", + "description": "The recurrence weight tensor. Concatenation of `Ri` and `RBi` (if bidirectional). The tensor has shape `[num_directions, hidden_size, hidden_size]`." + }, + { + "name": "B", + "type": "T", + "option": "optional", + "description": "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." + }, + { + "name": "sequence_lens", + "type": "T1", + "option": "optional", + "description": "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]`." + }, + { + "name": "initial_h", + "type": "T", + "option": "optional", + "description": "Optional initial value of the hidden. If not specified - assumed to be 0. It has shape `[num_directions, batch_size, hidden_size]`." + } + ], + "min_input": 3, + "max_input": 6, + "outputs": [ + { + "name": "Y", + "type": "T", + "option": "optional", + "description": "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." + }, + { + "name": "Y_h", + "type": "T", + "option": "optional", + "description": "The last output value of the hidden. It has shape `[num_directions, batch_size, hidden_size]`." + } + ], + "min_output": 0, + "max_output": 2, + "inputs_range": "3 - 6", + "outputs_range": "0 - 2", + "type_constraints": [ + { + "description": "Constrain input and output types to float tensors.", + "type_param_str": "T", + "allowed_type_strs": [ + "tensor(float16)", + "tensor(float)", + "tensor(double)" + ] + }, + { + "description": "Constrain seq_lens to integer tensor.", + "type_param_str": "T1", + "allowed_type_strs": [ + "tensor(int32)" + ] + } + ], + "examples": [ + { + "summary": "batchwise", + "code": "input = np.array([[[1., 2.]], [[3., 4.]], [[5., 6.]]]).astype(np.float32)\n\ninput_size = 2\nhidden_size = 4\nweight_scale = 0.5\nlayout = 1\n\nnode = onnx.helper.make_node(\n 'RNN',\n inputs=['X', 'W', 'R'],\n outputs=['Y', 'Y_h'],\n hidden_size=hidden_size,\n layout=layout\n)\n\nW = weight_scale * np.ones((1, hidden_size, input_size)).astype(np.float32)\nR = weight_scale * np.ones((1, hidden_size, hidden_size)).astype(np.float32)\n\nrnn = RNN_Helper(X=input, W=W, R=R, layout=layout)\nY, Y_h = rnn.step()\nexpect(node, inputs=[input, W, R], outputs=[Y.astype(np.float32), Y_h.astype(np.float32)], name='test_simple_rnn_batchwise')" + }, + { + "summary": "defaults", + "code": "input = np.array([[[1., 2.], [3., 4.], [5., 6.]]]).astype(np.float32)\n\ninput_size = 2\nhidden_size = 4\nweight_scale = 0.1\n\nnode = onnx.helper.make_node(\n 'RNN',\n inputs=['X', 'W', 'R'],\n outputs=['', 'Y_h'],\n hidden_size=hidden_size\n)\n\nW = weight_scale * np.ones((1, hidden_size, input_size)).astype(np.float32)\nR = weight_scale * np.ones((1, hidden_size, hidden_size)).astype(np.float32)\n\nrnn = RNN_Helper(X=input, W=W, R=R)\n_, Y_h = rnn.step()\nexpect(node, inputs=[input, W, R], outputs=[Y_h.astype(np.float32)], name='test_simple_rnn_defaults')" + }, + { + "summary": "initial_bias", + "code": "input = np.array([[[1., 2., 3.], [4., 5., 6.], [7., 8., 9.]]]).astype(np.float32)\n\ninput_size = 3\nhidden_size = 5\ncustom_bias = 0.1\nweight_scale = 0.1\n\nnode = onnx.helper.make_node(\n 'RNN',\n inputs=['X', 'W', 'R', 'B'],\n outputs=['', 'Y_h'],\n hidden_size=hidden_size\n)\n\nW = weight_scale * np.ones((1, hidden_size, input_size)).astype(np.float32)\nR = weight_scale * np.ones((1, hidden_size, hidden_size)).astype(np.float32)\n\n# Adding custom bias\nW_B = custom_bias * np.ones((1, hidden_size)).astype(np.float32)\nR_B = np.zeros((1, hidden_size)).astype(np.float32)\nB = np.concatenate((W_B, R_B), axis=1)\n\nrnn = RNN_Helper(X=input, W=W, R=R, B=B)\n_, Y_h = rnn.step()\nexpect(node, inputs=[input, W, R, B], outputs=[Y_h.astype(np.float32)],\n name='test_simple_rnn_with_initial_bias')" + }, + { + "summary": "seq_length", + "code": "input = np.array([[[1., 2., 3.], [4., 5., 6.], [7., 8., 9.]],\n [[10., 11., 12.], [13., 14., 15.], [16., 17., 18.]]]).astype(np.float32)\n\ninput_size = 3\nhidden_size = 5\n\nnode = onnx.helper.make_node(\n 'RNN',\n inputs=['X', 'W', 'R', 'B'],\n outputs=['', 'Y_h'],\n hidden_size=hidden_size\n)\n\nW = np.random.randn(1, hidden_size, input_size).astype(np.float32)\nR = np.random.randn(1, hidden_size, hidden_size).astype(np.float32)\n\n# Adding custom bias\nW_B = np.random.randn(1, hidden_size).astype(np.float32)\nR_B = np.random.randn(1, hidden_size).astype(np.float32)\nB = np.concatenate((W_B, R_B), axis=1)\n\nrnn = RNN_Helper(X=input, W=W, R=R, B=B)\n_, Y_h = rnn.step()\nexpect(node, inputs=[input, W, R, B], outputs=[Y_h.astype(np.float32)], name='test_rnn_seq_length')" + } + ], + "category": "Layer" + }, + { + "name": "RNN", + "module": "ai.onnx", + "version": 7, + "support_level": "common", + "description": "Computes an one-layer simple RNN. This operator is usually supported\nvia some custom implementation such as CuDNN.\n\nNotations:\n\n`X` - input tensor\n\n`i` - input gate\n\n`t` - time step (t-1 means previous time step)\n\n`Wi` - W parameter weight matrix for input gate\n\n`Ri` - R recurrence weight matrix for input gate\n\n`Wbi` - W parameter bias vector for input gate\n\n`Rbi` - R parameter bias vector for input gate\n\n`WBi` - W parameter weight matrix for backward input gate\n\n`RBi` - R recurrence weight matrix for backward input gate\n\n`WBbi` - WR bias vectors for backward input gate\n\n`RBbi` - RR bias vectors for backward input gate\n\n`H` - Hidden state\n\n`num_directions` - 2 if direction == bidirectional else 1\n\nActivation functions:\n\n Relu(x) - max(0, x)\n\n Tanh(x) - (1 - e^{-2x})/(1 + e^{-2x})\n\n Sigmoid(x) - 1/(1 + e^{-x})\n\n (NOTE: Below are optional)\n\n Affine(x) - alpha*x + beta\n\n LeakyRelu(x) - x if x >= 0 else alpha * x\n\n ThresholdedRelu(x) - x if x >= alpha else 0\n\n ScaledTanh(x) - alpha*Tanh(beta*x)\n\n HardSigmoid(x) - min(max(alpha*x + beta, 0), 1)\n\n Elu(x) - x if x >= 0 else alpha*(e^x - 1)\n\n Softsign(x) - x/(1 + |x|)\n\n Softplus(x) - log(1 + e^x)\n\nEquations (Default: f=Tanh):\n\n - Ht = f(Xt*(Wi^T) + Ht-1*(Ri^T) + Wbi + Rbi)\nThis operator has **optional** inputs/outputs. See [the doc](https://github.com/onnx/onnx/blob/master/docs/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.\n", + "attributes": [ + { + "name": "activation_alpha", + "type": "float32[]", + "required": false, + "description": "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." + }, + { + "name": "activation_beta", + "type": "float32[]", + "required": false, + "description": "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." + }, + { + "name": "activations", + "type": "string[]", + "required": false, + "description": "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." + }, + { + "name": "clip", + "type": "float32", + "required": false, + "description": "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." + }, + { + "name": "direction", + "type": "string", + "required": false, + "default": "forward", + "description": "Specify if the RNN is forward, reverse, or bidirectional. Must be one of forward (default), reverse, or bidirectional." + }, + { + "name": "hidden_size", + "type": "int64", + "required": false, + "description": "Number of neurons in the hidden layer" + } + ], + "inputs": [ + { + "name": "X", + "type": "T", + "description": "The input sequences packed (and potentially padded) into one 3-D tensor with the shape of `[seq_length, batch_size, input_size]`." + }, + { + "name": "W", + "type": "T", + "description": "The weight tensor for input gate. Concatenation of `Wi` and `WBi` (if bidirectional). The tensor has shape `[num_directions, hidden_size, input_size]`." + }, + { + "name": "R", + "type": "T", + "description": "The recurrence weight tensor. Concatenation of `Ri` and `RBi` (if bidirectional). The tensor has shape `[num_directions, hidden_size, hidden_size]`." + }, + { + "name": "B", + "type": "T", + "option": "optional", + "description": "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." + }, + { + "name": "sequence_lens", + "type": "T1", + "option": "optional", + "description": "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]`." + }, + { + "name": "initial_h", + "type": "T", + "option": "optional", + "description": "Optional initial value of the hidden. If not specified - assumed to be 0. It has shape `[num_directions, batch_size, hidden_size]`." + } + ], + "min_input": 3, + "max_input": 6, + "outputs": [ + { + "name": "Y", + "type": "T", + "option": "optional", + "description": "A tensor that concats all the intermediate output values of the hidden. It has shape `[seq_length, num_directions, batch_size, hidden_size]`. " + }, + { + "name": "Y_h", + "type": "T", + "option": "optional", + "description": "The last output value of the hidden. It has shape `[num_directions, batch_size, hidden_size]`." + } + ], + "min_output": 0, + "max_output": 2, + "inputs_range": "3 - 6", + "outputs_range": "0 - 2", + "type_constraints": [ + { + "description": "Constrain input and output types to float tensors.", + "type_param_str": "T", + "allowed_type_strs": [ + "tensor(float16)", + "tensor(float)", + "tensor(double)" + ] + }, + { + "description": "Constrain seq_lens to integer tensor.", + "type_param_str": "T1", + "allowed_type_strs": [ + "tensor(int32)" + ] + } + ], + "examples": [ + { + "summary": "batchwise", + "code": "input = np.array([[[1., 2.]], [[3., 4.]], [[5., 6.]]]).astype(np.float32)\n\ninput_size = 2\nhidden_size = 4\nweight_scale = 0.5\nlayout = 1\n\nnode = onnx.helper.make_node(\n 'RNN',\n inputs=['X', 'W', 'R'],\n outputs=['Y', 'Y_h'],\n hidden_size=hidden_size,\n layout=layout\n)\n\nW = weight_scale * np.ones((1, hidden_size, input_size)).astype(np.float32)\nR = weight_scale * np.ones((1, hidden_size, hidden_size)).astype(np.float32)\n\nrnn = RNN_Helper(X=input, W=W, R=R, layout=layout)\nY, Y_h = rnn.step()\nexpect(node, inputs=[input, W, R], outputs=[Y.astype(np.float32), Y_h.astype(np.float32)], name='test_simple_rnn_batchwise')" + }, + { + "summary": "defaults", + "code": "input = np.array([[[1., 2.], [3., 4.], [5., 6.]]]).astype(np.float32)\n\ninput_size = 2\nhidden_size = 4\nweight_scale = 0.1\n\nnode = onnx.helper.make_node(\n 'RNN',\n inputs=['X', 'W', 'R'],\n outputs=['', 'Y_h'],\n hidden_size=hidden_size\n)\n\nW = weight_scale * np.ones((1, hidden_size, input_size)).astype(np.float32)\nR = weight_scale * np.ones((1, hidden_size, hidden_size)).astype(np.float32)\n\nrnn = RNN_Helper(X=input, W=W, R=R)\n_, Y_h = rnn.step()\nexpect(node, inputs=[input, W, R], outputs=[Y_h.astype(np.float32)], name='test_simple_rnn_defaults')" + }, + { + "summary": "initial_bias", + "code": "input = np.array([[[1., 2., 3.], [4., 5., 6.], [7., 8., 9.]]]).astype(np.float32)\n\ninput_size = 3\nhidden_size = 5\ncustom_bias = 0.1\nweight_scale = 0.1\n\nnode = onnx.helper.make_node(\n 'RNN',\n inputs=['X', 'W', 'R', 'B'],\n outputs=['', 'Y_h'],\n hidden_size=hidden_size\n)\n\nW = weight_scale * np.ones((1, hidden_size, input_size)).astype(np.float32)\nR = weight_scale * np.ones((1, hidden_size, hidden_size)).astype(np.float32)\n\n# Adding custom bias\nW_B = custom_bias * np.ones((1, hidden_size)).astype(np.float32)\nR_B = np.zeros((1, hidden_size)).astype(np.float32)\nB = np.concatenate((W_B, R_B), axis=1)\n\nrnn = RNN_Helper(X=input, W=W, R=R, B=B)\n_, Y_h = rnn.step()\nexpect(node, inputs=[input, W, R, B], outputs=[Y_h.astype(np.float32)],\n name='test_simple_rnn_with_initial_bias')" + }, + { + "summary": "seq_length", + "code": "input = np.array([[[1., 2., 3.], [4., 5., 6.], [7., 8., 9.]],\n [[10., 11., 12.], [13., 14., 15.], [16., 17., 18.]]]).astype(np.float32)\n\ninput_size = 3\nhidden_size = 5\n\nnode = onnx.helper.make_node(\n 'RNN',\n inputs=['X', 'W', 'R', 'B'],\n outputs=['', 'Y_h'],\n hidden_size=hidden_size\n)\n\nW = np.random.randn(1, hidden_size, input_size).astype(np.float32)\nR = np.random.randn(1, hidden_size, hidden_size).astype(np.float32)\n\n# Adding custom bias\nW_B = np.random.randn(1, hidden_size).astype(np.float32)\nR_B = np.random.randn(1, hidden_size).astype(np.float32)\nB = np.concatenate((W_B, R_B), axis=1)\n\nrnn = RNN_Helper(X=input, W=W, R=R, B=B)\n_, Y_h = rnn.step()\nexpect(node, inputs=[input, W, R, B], outputs=[Y_h.astype(np.float32)], name='test_rnn_seq_length')" + } + ], + "category": "Layer" + }, + { + "name": "RNN", + "module": "ai.onnx", + "version": 14, + "support_level": "common", + "description": "Computes an one-layer simple RNN. This operator is usually supported\nvia some custom implementation such as CuDNN.\n\nNotations:\n\n`X` - input tensor\n\n`i` - input gate\n\n`t` - time step (t-1 means previous time step)\n\n`Wi` - W parameter weight matrix for input gate\n\n`Ri` - R recurrence weight matrix for input gate\n\n`Wbi` - W parameter bias vector for input gate\n\n`Rbi` - R parameter bias vector for input gate\n\n`WBi` - W parameter weight matrix for backward input gate\n\n`RBi` - R recurrence weight matrix for backward input gate\n\n`WBbi` - WR bias vectors for backward input gate\n\n`RBbi` - RR bias vectors for backward input gate\n\n`H` - Hidden state\n\n`num_directions` - 2 if direction == bidirectional else 1\n\nActivation functions:\n\n Relu(x) - max(0, x)\n\n Tanh(x) - (1 - e^{-2x})/(1 + e^{-2x})\n\n Sigmoid(x) - 1/(1 + e^{-x})\n\n (NOTE: Below are optional)\n\n Affine(x) - alpha*x + beta\n\n LeakyRelu(x) - x if x >= 0 else alpha * x\n\n ThresholdedRelu(x) - x if x >= alpha else 0\n\n ScaledTanh(x) - alpha*Tanh(beta*x)\n\n HardSigmoid(x) - min(max(alpha*x + beta, 0), 1)\n\n Elu(x) - x if x >= 0 else alpha*(e^x - 1)\n\n Softsign(x) - x/(1 + |x|)\n\n Softplus(x) - log(1 + e^x)\n\nEquations (Default: f=Tanh):\n\n - Ht = f(Xt*(Wi^T) + Ht-1*(Ri^T) + Wbi + Rbi)\nThis operator has **optional** inputs/outputs. See [the doc](https://github.com/onnx/onnx/blob/master/docs/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.\n", + "attributes": [ + { + "name": "activation_alpha", + "type": "float32[]", + "required": false, + "description": "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." + }, + { + "name": "activation_beta", + "type": "float32[]", + "required": false, + "description": "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." + }, + { + "name": "activations", + "type": "string[]", + "required": false, + "description": "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." + }, + { + "name": "clip", + "type": "float32", + "required": false, + "description": "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." + }, + { + "name": "direction", + "type": "string", + "required": false, + "default": "forward", + "description": "Specify if the RNN is forward, reverse, or bidirectional. Must be one of forward (default), reverse, or bidirectional." + }, + { + "name": "hidden_size", + "type": "int64", + "required": false, + "description": "Number of neurons in the hidden layer" + }, + { + "name": "layout", + "type": "int64", + "required": false, + "description": "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": [ + { + "name": "X", + "type": "T", + "description": "The input sequences packed (and potentially padded) into one 3-D tensor with the shape of `[seq_length, batch_size, input_size]`." + }, + { + "name": "W", + "type": "T", + "description": "The weight tensor for input gate. Concatenation of `Wi` and `WBi` (if bidirectional). The tensor has shape `[num_directions, hidden_size, input_size]`." + }, + { + "name": "R", + "type": "T", + "description": "The recurrence weight tensor. Concatenation of `Ri` and `RBi` (if bidirectional). The tensor has shape `[num_directions, hidden_size, hidden_size]`." + }, + { + "name": "B", + "type": "T", + "option": "optional", + "description": "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." + }, + { + "name": "sequence_lens", + "type": "T1", + "option": "optional", + "description": "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]`." + }, + { + "name": "initial_h", + "type": "T", + "option": "optional", + "description": "Optional initial value of the hidden. If not specified - assumed to be 0. It has shape `[num_directions, batch_size, hidden_size]`." + } + ], + "min_input": 3, + "max_input": 6, + "outputs": [ + { + "name": "Y", + "type": "T", + "option": "optional", + "description": "A tensor that concats all the intermediate output values of the hidden. It has shape `[seq_length, num_directions, batch_size, hidden_size]`. " + }, + { + "name": "Y_h", + "type": "T", + "option": "optional", + "description": "The last output value of the hidden. It has shape `[num_directions, batch_size, hidden_size]`." + } + ], + "min_output": 0, + "max_output": 2, + "inputs_range": "3 - 6", + "outputs_range": "0 - 2", + "type_constraints": [ + { + "description": "Constrain input and output types to float tensors.", + "type_param_str": "T", + "allowed_type_strs": [ + "tensor(float16)", + "tensor(float)", + "tensor(double)" + ] + }, + { + "description": "Constrain seq_lens to integer tensor.", + "type_param_str": "T1", + "allowed_type_strs": [ + "tensor(int32)" + ] + } + ], + "examples": [ + { + "summary": "batchwise", + "code": "input = np.array([[[1., 2.]], [[3., 4.]], [[5., 6.]]]).astype(np.float32)\n\ninput_size = 2\nhidden_size = 4\nweight_scale = 0.5\nlayout = 1\n\nnode = onnx.helper.make_node(\n 'RNN',\n inputs=['X', 'W', 'R'],\n outputs=['Y', 'Y_h'],\n hidden_size=hidden_size,\n layout=layout\n)\n\nW = weight_scale * np.ones((1, hidden_size, input_size)).astype(np.float32)\nR = weight_scale * np.ones((1, hidden_size, hidden_size)).astype(np.float32)\n\nrnn = RNN_Helper(X=input, W=W, R=R, layout=layout)\nY, Y_h = rnn.step()\nexpect(node, inputs=[input, W, R], outputs=[Y.astype(np.float32), Y_h.astype(np.float32)], name='test_simple_rnn_batchwise')" + }, + { + "summary": "defaults", + "code": "input = np.array([[[1., 2.], [3., 4.], [5., 6.]]]).astype(np.float32)\n\ninput_size = 2\nhidden_size = 4\nweight_scale = 0.1\n\nnode = onnx.helper.make_node(\n 'RNN',\n inputs=['X', 'W', 'R'],\n outputs=['', 'Y_h'],\n hidden_size=hidden_size\n)\n\nW = weight_scale * np.ones((1, hidden_size, input_size)).astype(np.float32)\nR = weight_scale * np.ones((1, hidden_size, hidden_size)).astype(np.float32)\n\nrnn = RNN_Helper(X=input, W=W, R=R)\n_, Y_h = rnn.step()\nexpect(node, inputs=[input, W, R], outputs=[Y_h.astype(np.float32)], name='test_simple_rnn_defaults')" + }, + { + "summary": "initial_bias", + "code": "input = np.array([[[1., 2., 3.], [4., 5., 6.], [7., 8., 9.]]]).astype(np.float32)\n\ninput_size = 3\nhidden_size = 5\ncustom_bias = 0.1\nweight_scale = 0.1\n\nnode = onnx.helper.make_node(\n 'RNN',\n inputs=['X', 'W', 'R', 'B'],\n outputs=['', 'Y_h'],\n hidden_size=hidden_size\n)\n\nW = weight_scale * np.ones((1, hidden_size, input_size)).astype(np.float32)\nR = weight_scale * np.ones((1, hidden_size, hidden_size)).astype(np.float32)\n\n# Adding custom bias\nW_B = custom_bias * np.ones((1, hidden_size)).astype(np.float32)\nR_B = np.zeros((1, hidden_size)).astype(np.float32)\nB = np.concatenate((W_B, R_B), axis=1)\n\nrnn = RNN_Helper(X=input, W=W, R=R, B=B)\n_, Y_h = rnn.step()\nexpect(node, inputs=[input, W, R, B], outputs=[Y_h.astype(np.float32)],\n name='test_simple_rnn_with_initial_bias')" + }, + { + "summary": "seq_length", + "code": "input = np.array([[[1., 2., 3.], [4., 5., 6.], [7., 8., 9.]],\n [[10., 11., 12.], [13., 14., 15.], [16., 17., 18.]]]).astype(np.float32)\n\ninput_size = 3\nhidden_size = 5\n\nnode = onnx.helper.make_node(\n 'RNN',\n inputs=['X', 'W', 'R', 'B'],\n outputs=['', 'Y_h'],\n hidden_size=hidden_size\n)\n\nW = np.random.randn(1, hidden_size, input_size).astype(np.float32)\nR = np.random.randn(1, hidden_size, hidden_size).astype(np.float32)\n\n# Adding custom bias\nW_B = np.random.randn(1, hidden_size).astype(np.float32)\nR_B = np.random.randn(1, hidden_size).astype(np.float32)\nB = np.concatenate((W_B, R_B), axis=1)\n\nrnn = RNN_Helper(X=input, W=W, R=R, B=B)\n_, Y_h = rnn.step()\nexpect(node, inputs=[input, W, R, B], outputs=[Y_h.astype(np.float32)], name='test_rnn_seq_length')" + } + ], + "category": "Layer" + }, + { + "name": "RandomNormal", + "module": "ai.onnx", + "version": 1, + "support_level": "common", + "description": "Generate a tensor with random values drawn from a normal distribution. The shape\nof the tensor is specified by the `shape` argument and the parameter of the normal distribution\nspecified by `mean` and `scale`.\n\nThe data type is specified by the 'dtype' argument. The 'dtype' argument must\nbe one of the data types specified in the 'DataType' enum field in the\nTensorProto message.\n", + "attributes": [ + { + "name": "dtype", + "type": "DataType", + "required": false, + "default": 1, + "description": "The data type for the elements of the output tensor. Default is TensorProto::FLOAT." + }, + { + "name": "mean", + "type": "float32", + "required": false, + "description": "The mean of the normal distribution." + }, + { + "name": "scale", + "type": "float32", + "required": false, + "default": 1.0, + "description": "The standard deviation of the normal distribution." + }, + { + "name": "seed", + "type": "float32", + "required": false, + "description": "(Optional) Seed to the random generator, if not specified we will auto generate one." + }, + { + "name": "shape", + "type": "int64[]", + "required": true, + "description": "The shape of the output tensor." + } + ], + "min_input": 0, + "max_input": 0, + "outputs": [ + { + "name": "output", + "type": "T", + "description": "Output tensor of random values drawn from normal distribution" + } + ], + "min_output": 1, + "max_output": 1, + "type_constraints": [ + { + "description": "Constrain output types to float tensors.", + "type_param_str": "T", + "allowed_type_strs": [ + "tensor(float16)", + "tensor(float)", + "tensor(double)" + ] + } + ] + }, + { + "name": "RandomNormalLike", + "module": "ai.onnx", + "version": 1, + "support_level": "common", + "description": "Generate a tensor with random values drawn from a normal distribution.\nThe shape of the output tensor is copied from the shape of the input tensor,\nand the parameters of the normal distribution are specified by `mean` and `scale`.\n\nThe data type is specified by the 'dtype' argument, or copied from the input tensor if not provided.\nThe 'dtype' argument must be one of the data types specified in the 'DataType' enum field in the\nTensorProto message, and be valid as an output type.\n", + "attributes": [ + { + "name": "dtype", + "type": "int64", + "required": false, + "description": "(Optional) The data type for the elements of the output tensor, if not specified, we will use the data type of the input tensor." + }, + { + "name": "mean", + "type": "float32", + "required": false, + "description": "The mean of the normal distribution." + }, + { + "name": "scale", + "type": "float32", + "required": false, + "default": 1.0, + "description": "The standard deviation of the normal distribution." + }, + { + "name": "seed", + "type": "float32", + "required": false, + "description": "(Optional) Seed to the random generator, if not specified we will auto generate one." + } + ], + "inputs": [ + { + "name": "input", + "type": "T1", + "description": "Input tensor to copy shape and optionally type information from." + } + ], + "min_input": 1, + "max_input": 1, + "outputs": [ + { + "name": "output", + "type": "T2", + "description": "Output tensor of random values drawn from normal distribution" + } + ], + "min_output": 1, + "max_output": 1, + "type_constraints": [ + { + "description": "Constrain to any tensor type. If the dtype attribute is not provided this must be a valid output type.", + "type_param_str": "T1", + "allowed_type_strs": [ + "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)" + ] + }, + { + "description": "Constrain output types to float tensors.", + "type_param_str": "T2", + "allowed_type_strs": [ + "tensor(float16)", + "tensor(float)", + "tensor(double)" + ] + } + ] + }, + { + "name": "RandomUniform", + "module": "ai.onnx", + "version": 1, + "support_level": "common", + "description": "Generate a tensor with random values drawn from a uniform distribution. The shape\nof the tensor is specified by the `shape` argument and the range by `low` and `high`.\n\nThe data type is specified by the 'dtype' argument. The 'dtype' argument must\nbe one of the data types specified in the 'DataType' enum field in the\nTensorProto message.\n", + "attributes": [ + { + "name": "dtype", + "type": "int64", + "required": false, + "default": 1, + "description": "The data type for the elements of the output tensor. If not specified, default is TensorProto::FLOAT." + }, + { + "name": "high", + "type": "float32", + "required": false, + "default": 1.0, + "description": "Upper boundary of the output values." + }, + { + "name": "low", + "type": "float32", + "required": false, + "description": "Lower boundary of the output values." + }, + { + "name": "seed", + "type": "float32", + "required": false, + "description": "(Optional) Seed to the random generator, if not specified we will auto generate one." + }, + { + "name": "shape", + "type": "int64[]", + "required": true, + "description": "The shape of the output tensor." + } + ], + "min_input": 0, + "max_input": 0, + "outputs": [ + { + "name": "output", + "type": "T", + "description": "Output tensor of random values drawn from uniform distribution" + } + ], + "min_output": 1, + "max_output": 1, + "type_constraints": [ + { + "description": "Constrain output types to float tensors.", + "type_param_str": "T", + "allowed_type_strs": [ + "tensor(float16)", + "tensor(float)", + "tensor(double)" + ] + } + ] + }, + { + "name": "RandomUniformLike", + "module": "ai.onnx", + "version": 1, + "support_level": "common", + "description": "Generate a tensor with random values drawn from a uniform distribution.\nThe shape of the output tensor is copied from the shape of the input tensor,\nand the parameters of the uniform distribution are specified by `low` and `high`.\n\nThe data type is specified by the 'dtype' argument, or copied from the input tensor if not provided.\nThe 'dtype' argument must be one of the data types specified in the 'DataType' enum field in the\nTensorProto message and be valid as an output type.\n", + "attributes": [ + { + "name": "dtype", + "type": "int64", + "required": false, + "description": "(Optional) The data type for the elements of the output tensor, if not specified, we will use the data type of the input tensor." + }, + { + "name": "high", + "type": "float32", + "required": false, + "default": 1.0, + "description": "Upper boundary of the output values." + }, + { + "name": "low", + "type": "float32", + "required": false, + "description": "Lower boundary of the output values." + }, + { + "name": "seed", + "type": "float32", + "required": false, + "description": "(Optional) Seed to the random generator, if not specified we will auto generate one." + } + ], + "inputs": [ + { + "name": "input", + "type": "T1", + "description": "Input tensor to copy shape and optionally type information from." + } + ], + "min_input": 1, + "max_input": 1, + "outputs": [ + { + "name": "output", + "type": "T2", + "description": "Output tensor of random values drawn from uniform distribution" + } + ], + "min_output": 1, + "max_output": 1, + "type_constraints": [ + { + "description": "Constrain to any tensor type. If the dtype attribute is not provided this must be a valid output type.", + "type_param_str": "T1", + "allowed_type_strs": [ + "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)" + ] + }, + { + "description": "Constrain output types to float tensors.", + "type_param_str": "T2", + "allowed_type_strs": [ + "tensor(float16)", + "tensor(float)", + "tensor(double)" + ] + } + ] + }, + { + "name": "Range", + "module": "ai.onnx", + "version": 11, + "support_level": "common", + "description": "Generate a tensor containing a sequence of numbers that begin at `start` and extends by increments of `delta`\nup to `limit` (exclusive).\n\nThe number of elements in the output of range is computed as below-\n\n`number_of_elements = max( ceil( (limit - start) / delta ) , 0 )`\n\nThe pseudocode determining the contents of the output is shown below-\n\n`for(int i=0; i) and produces one output data\n(Tensor) where the reciprocal is, y = 1/x, is applied to\nthe tensor elementwise.\n", + "attributes": [ + { + "name": "consumed_inputs", + "type": "int64[]", + "required": false, + "description": "legacy optimization attribute." + } + ], + "inputs": [ + { + "name": "X", + "type": "T", + "description": "Input tensor" + } + ], + "min_input": 1, + "max_input": 1, + "outputs": [ + { + "name": "Y", + "type": "T", + "description": "Output tensor" + } + ], + "min_output": 1, + "max_output": 1, + "type_constraints": [ + { + "description": "Constrain input and output types to float tensors.", + "type_param_str": "T", + "allowed_type_strs": [ + "tensor(float16)", + "tensor(float)", + "tensor(double)" + ] + } + ], + "examples": [ + { + "summary": "reciprocal", + "code": "node = onnx.helper.make_node(\n 'Reciprocal',\n inputs=['x'],\n outputs=['y'],\n)\n\nx = np.array([-4, 2]).astype(np.float32)\ny = np.reciprocal(x) # expected output [-0.25, 0.5],\nexpect(node, inputs=[x], outputs=[y],\n name='test_reciprocal_example')\n\nx = np.random.rand(3, 4, 5).astype(np.float32) + 0.5\ny = np.reciprocal(x)\nexpect(node, inputs=[x], outputs=[y],\n name='test_reciprocal')" + } + ] + }, + { + "name": "Reciprocal", + "module": "ai.onnx", + "version": 6, + "support_level": "common", + "description": "Reciprocal takes one input data (Tensor) and produces one output data\n(Tensor) where the reciprocal is, y = 1/x, is applied to\nthe tensor elementwise.\n", + "inputs": [ + { + "name": "X", + "type": "T", + "description": "Input tensor" + } + ], + "min_input": 1, + "max_input": 1, + "outputs": [ + { + "name": "Y", + "type": "T", + "description": "Output tensor" + } + ], + "min_output": 1, + "max_output": 1, + "type_constraints": [ + { + "description": "Constrain input and output types to float tensors.", + "type_param_str": "T", + "allowed_type_strs": [ + "tensor(float16)", + "tensor(float)", + "tensor(double)" + ] + } + ], + "examples": [ + { + "summary": "reciprocal", + "code": "node = onnx.helper.make_node(\n 'Reciprocal',\n inputs=['x'],\n outputs=['y'],\n)\n\nx = np.array([-4, 2]).astype(np.float32)\ny = np.reciprocal(x) # expected output [-0.25, 0.5],\nexpect(node, inputs=[x], outputs=[y],\n name='test_reciprocal_example')\n\nx = np.random.rand(3, 4, 5).astype(np.float32) + 0.5\ny = np.reciprocal(x)\nexpect(node, inputs=[x], outputs=[y],\n name='test_reciprocal')" + } + ] + }, + { + "name": "Reciprocal", + "module": "ai.onnx", + "version": 13, + "support_level": "common", + "description": "Reciprocal takes one input data (Tensor) and produces one output data\n(Tensor) where the reciprocal is, y = 1/x, is applied to\nthe tensor elementwise.\n", + "inputs": [ + { + "name": "X", + "type": "T", + "description": "Input tensor" + } + ], + "min_input": 1, + "max_input": 1, + "outputs": [ + { + "name": "Y", + "type": "T", + "description": "Output tensor" + } + ], + "min_output": 1, + "max_output": 1, + "type_constraints": [ + { + "description": "Constrain input and output types to float tensors.", + "type_param_str": "T", + "allowed_type_strs": [ + "tensor(float16)", + "tensor(float)", + "tensor(double)", + "tensor(bfloat16)" + ] + } + ], + "examples": [ + { + "summary": "reciprocal", + "code": "node = onnx.helper.make_node(\n 'Reciprocal',\n inputs=['x'],\n outputs=['y'],\n)\n\nx = np.array([-4, 2]).astype(np.float32)\ny = np.reciprocal(x) # expected output [-0.25, 0.5],\nexpect(node, inputs=[x], outputs=[y],\n name='test_reciprocal_example')\n\nx = np.random.rand(3, 4, 5).astype(np.float32) + 0.5\ny = np.reciprocal(x)\nexpect(node, inputs=[x], outputs=[y],\n name='test_reciprocal')" + } + ] + }, + { + "name": "ReduceL1", + "module": "ai.onnx", + "version": 1, + "support_level": "common", + "description": "Computes the L1 norm of the input tensor's element along the provided axes. The resulted\ntensor has the same rank as the input if keepdims equal 1. If keepdims equal 0, then\nthe resulted tensor have the reduced dimension pruned.\n\nThe above behavior is similar to numpy, with the exception that numpy default keepdims to\nFalse instead of True.", + "attributes": [ + { + "name": "axes", + "type": "int64[]", + "required": false, + "description": "A list of integers, along which to reduce. The default is to reduce over all the dimensions of the input tensor." + }, + { + "name": "keepdims", + "type": "int64", + "required": false, + "default": 1, + "description": "Keep the reduced dimension or not, default 1 mean keep reduced dimension." + } + ], + "inputs": [ + { + "name": "data", + "type": "T", + "description": "An input tensor." + } + ], + "min_input": 1, + "max_input": 1, + "outputs": [ + { + "name": "reduced", + "type": "T", + "description": "Reduced output tensor." + } + ], + "min_output": 1, + "max_output": 1, + "type_constraints": [ + { + "description": "Constrain input and output types to high-precision numeric tensors.", + "type_param_str": "T", + "allowed_type_strs": [ + "tensor(uint32)", + "tensor(uint64)", + "tensor(int32)", + "tensor(int64)", + "tensor(float16)", + "tensor(float)", + "tensor(double)" + ] + } + ], + "examples": [ + { + "summary": "default_axes_keepdims", + "code": "shape = [3, 2, 2]\naxes = None\nkeepdims = 1\n\nnode = onnx.helper.make_node(\n 'ReduceL1',\n inputs=['data'],\n outputs=['reduced'],\n keepdims=keepdims\n)\n\ndata = np.reshape(np.arange(1, np.prod(shape) + 1, dtype=np.float32), shape)\n#print(data)\n#[[[1., 2.], [3., 4.]], [[5., 6.], [7., 8.]], [[9., 10.], [11., 12.]]]\n\nreduced = np.sum(a=np.abs(data), axis=axes, keepdims=keepdims == 1)\n#print(reduced)\n#[[[78.]]]\n\nexpect(node, inputs=[data], outputs=[reduced],\n name='test_reduce_l1_default_axes_keepdims_example')\n\nnp.random.seed(0)\ndata = np.random.uniform(-10, 10, shape).astype(np.float32)\nreduced = np.sum(a=np.abs(data), axis=axes, keepdims=keepdims == 1)\n\nexpect(node, inputs=[data], outputs=[reduced],\n name='test_reduce_l1_default_axes_keepdims_random')" + }, + { + "summary": "do_not_keepdims", + "code": "shape = [3, 2, 2]\naxes = [2]\nkeepdims = 0\n\nnode = onnx.helper.make_node(\n 'ReduceL1',\n inputs=['data'],\n outputs=['reduced'],\n axes=axes,\n keepdims=keepdims\n)\n\ndata = np.reshape(np.arange(1, np.prod(shape) + 1, dtype=np.float32), shape)\n#print(data)\n#[[[1., 2.], [3., 4.]], [[5., 6.], [7., 8.]], [[9., 10.], [11., 12.]]]\n\nreduced = np.sum(a=np.abs(data), axis=tuple(axes), keepdims=keepdims == 1)\n#print(reduced)\n#[[3., 7.], [11., 15.], [19., 23.]]\n\nexpect(node, inputs=[data], outputs=[reduced],\n name='test_reduce_l1_do_not_keepdims_example')\n\nnp.random.seed(0)\ndata = np.random.uniform(-10, 10, shape).astype(np.float32)\nreduced = np.sum(a=np.abs(data), axis=tuple(axes), keepdims=keepdims == 1)\n\nexpect(node, inputs=[data], outputs=[reduced],\n name='test_reduce_l1_do_not_keepdims_random')" + }, + { + "summary": "keepdims", + "code": "shape = [3, 2, 2]\naxes = [2]\nkeepdims = 1\n\nnode = onnx.helper.make_node(\n 'ReduceL1',\n inputs=['data'],\n outputs=['reduced'],\n axes=axes,\n keepdims=keepdims\n)\n\ndata = np.reshape(np.arange(1, np.prod(shape) + 1, dtype=np.float32), shape)\n#print(data)\n#[[[1., 2.], [3., 4.]], [[5., 6.], [7., 8.]], [[9., 10.], [11., 12.]]]\n\nreduced = np.sum(a=np.abs(data), axis=tuple(axes), keepdims=keepdims == 1)\n#print(reduced)\n#[[[3.], [7.]], [[11.], [15.]], [[19.], [23.]]]\n\nexpect(node, inputs=[data], outputs=[reduced],\n name='test_reduce_l1_keep_dims_example')\n\nnp.random.seed(0)\ndata = np.random.uniform(-10, 10, shape).astype(np.float32)\nreduced = np.sum(a=np.abs(data), axis=tuple(axes), keepdims=keepdims == 1)\n\nexpect(node, inputs=[data], outputs=[reduced],\n name='test_reduce_l1_keep_dims_random')" + }, + { + "summary": "negative_axes_keepdims", + "code": "shape = [3, 2, 2]\naxes = [-1]\nkeepdims = 1\n\nnode = onnx.helper.make_node(\n 'ReduceL1',\n inputs=['data'],\n outputs=['reduced'],\n axes=axes,\n keepdims=keepdims\n)\n\ndata = np.reshape(np.arange(1, np.prod(shape) + 1, dtype=np.float32), shape)\n# print(data)\n#[[[1., 2.], [3., 4.]], [[5., 6.], [7., 8.]], [[9., 10.], [11., 12.]]]\n\nreduced = np.sum(a=np.abs(data), axis=tuple(axes), keepdims=keepdims == 1)\n# print(reduced)\n#[[[3.], [7.]], [[11.], [15.]], [[19.], [23.]]]\n\nexpect(node, inputs=[data], outputs=[reduced],\n name='test_reduce_l1_negative_axes_keep_dims_example')\n\nnp.random.seed(0)\ndata = np.random.uniform(-10, 10, shape).astype(np.float32)\nreduced = np.sum(a=np.abs(data), axis=tuple(axes), keepdims=keepdims == 1)\n\nexpect(node, inputs=[data], outputs=[reduced],\n name='test_reduce_l1_negative_axes_keep_dims_random')" + } + ] + }, + { + "name": "ReduceL1", + "module": "ai.onnx", + "version": 11, + "support_level": "common", + "description": "Computes the L1 norm of the input tensor's element along the provided axes. The resulted\ntensor has the same rank as the input if keepdims equal 1. If keepdims equal 0, then\nthe resulted tensor have the reduced dimension pruned.\n\nThe above behavior is similar to numpy, with the exception that numpy default keepdims to\nFalse instead of True.", + "attributes": [ + { + "name": "axes", + "type": "int64[]", + "required": false, + "description": "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)." + }, + { + "name": "keepdims", + "type": "int64", + "required": false, + "default": 1, + "description": "Keep the reduced dimension or not, default 1 mean keep reduced dimension." + } + ], + "inputs": [ + { + "name": "data", + "type": "T", + "description": "An input tensor." + } + ], + "min_input": 1, + "max_input": 1, + "outputs": [ + { + "name": "reduced", + "type": "T", + "description": "Reduced output tensor." + } + ], + "min_output": 1, + "max_output": 1, + "type_constraints": [ + { + "description": "Constrain input and output types to high-precision numeric tensors.", + "type_param_str": "T", + "allowed_type_strs": [ + "tensor(uint32)", + "tensor(uint64)", + "tensor(int32)", + "tensor(int64)", + "tensor(float16)", + "tensor(float)", + "tensor(double)" + ] + } + ], + "examples": [ + { + "summary": "default_axes_keepdims", + "code": "shape = [3, 2, 2]\naxes = None\nkeepdims = 1\n\nnode = onnx.helper.make_node(\n 'ReduceL1',\n inputs=['data'],\n outputs=['reduced'],\n keepdims=keepdims\n)\n\ndata = np.reshape(np.arange(1, np.prod(shape) + 1, dtype=np.float32), shape)\n#print(data)\n#[[[1., 2.], [3., 4.]], [[5., 6.], [7., 8.]], [[9., 10.], [11., 12.]]]\n\nreduced = np.sum(a=np.abs(data), axis=axes, keepdims=keepdims == 1)\n#print(reduced)\n#[[[78.]]]\n\nexpect(node, inputs=[data], outputs=[reduced],\n name='test_reduce_l1_default_axes_keepdims_example')\n\nnp.random.seed(0)\ndata = np.random.uniform(-10, 10, shape).astype(np.float32)\nreduced = np.sum(a=np.abs(data), axis=axes, keepdims=keepdims == 1)\n\nexpect(node, inputs=[data], outputs=[reduced],\n name='test_reduce_l1_default_axes_keepdims_random')" + }, + { + "summary": "do_not_keepdims", + "code": "shape = [3, 2, 2]\naxes = [2]\nkeepdims = 0\n\nnode = onnx.helper.make_node(\n 'ReduceL1',\n inputs=['data'],\n outputs=['reduced'],\n axes=axes,\n keepdims=keepdims\n)\n\ndata = np.reshape(np.arange(1, np.prod(shape) + 1, dtype=np.float32), shape)\n#print(data)\n#[[[1., 2.], [3., 4.]], [[5., 6.], [7., 8.]], [[9., 10.], [11., 12.]]]\n\nreduced = np.sum(a=np.abs(data), axis=tuple(axes), keepdims=keepdims == 1)\n#print(reduced)\n#[[3., 7.], [11., 15.], [19., 23.]]\n\nexpect(node, inputs=[data], outputs=[reduced],\n name='test_reduce_l1_do_not_keepdims_example')\n\nnp.random.seed(0)\ndata = np.random.uniform(-10, 10, shape).astype(np.float32)\nreduced = np.sum(a=np.abs(data), axis=tuple(axes), keepdims=keepdims == 1)\n\nexpect(node, inputs=[data], outputs=[reduced],\n name='test_reduce_l1_do_not_keepdims_random')" + }, + { + "summary": "keepdims", + "code": "shape = [3, 2, 2]\naxes = [2]\nkeepdims = 1\n\nnode = onnx.helper.make_node(\n 'ReduceL1',\n inputs=['data'],\n outputs=['reduced'],\n axes=axes,\n keepdims=keepdims\n)\n\ndata = np.reshape(np.arange(1, np.prod(shape) + 1, dtype=np.float32), shape)\n#print(data)\n#[[[1., 2.], [3., 4.]], [[5., 6.], [7., 8.]], [[9., 10.], [11., 12.]]]\n\nreduced = np.sum(a=np.abs(data), axis=tuple(axes), keepdims=keepdims == 1)\n#print(reduced)\n#[[[3.], [7.]], [[11.], [15.]], [[19.], [23.]]]\n\nexpect(node, inputs=[data], outputs=[reduced],\n name='test_reduce_l1_keep_dims_example')\n\nnp.random.seed(0)\ndata = np.random.uniform(-10, 10, shape).astype(np.float32)\nreduced = np.sum(a=np.abs(data), axis=tuple(axes), keepdims=keepdims == 1)\n\nexpect(node, inputs=[data], outputs=[reduced],\n name='test_reduce_l1_keep_dims_random')" + }, + { + "summary": "negative_axes_keepdims", + "code": "shape = [3, 2, 2]\naxes = [-1]\nkeepdims = 1\n\nnode = onnx.helper.make_node(\n 'ReduceL1',\n inputs=['data'],\n outputs=['reduced'],\n axes=axes,\n keepdims=keepdims\n)\n\ndata = np.reshape(np.arange(1, np.prod(shape) + 1, dtype=np.float32), shape)\n# print(data)\n#[[[1., 2.], [3., 4.]], [[5., 6.], [7., 8.]], [[9., 10.], [11., 12.]]]\n\nreduced = np.sum(a=np.abs(data), axis=tuple(axes), keepdims=keepdims == 1)\n# print(reduced)\n#[[[3.], [7.]], [[11.], [15.]], [[19.], [23.]]]\n\nexpect(node, inputs=[data], outputs=[reduced],\n name='test_reduce_l1_negative_axes_keep_dims_example')\n\nnp.random.seed(0)\ndata = np.random.uniform(-10, 10, shape).astype(np.float32)\nreduced = np.sum(a=np.abs(data), axis=tuple(axes), keepdims=keepdims == 1)\n\nexpect(node, inputs=[data], outputs=[reduced],\n name='test_reduce_l1_negative_axes_keep_dims_random')" + } + ] + }, + { + "name": "ReduceL1", + "module": "ai.onnx", + "version": 13, + "support_level": "common", + "description": "Computes the L1 norm of the input tensor's element along the provided axes. The resulted\ntensor has the same rank as the input if keepdims equal 1. If keepdims equal 0, then\nthe resulted tensor have the reduced dimension pruned.\n\nThe above behavior is similar to numpy, with the exception that numpy default keepdims to\nFalse instead of True.", + "attributes": [ + { + "name": "axes", + "type": "int64[]", + "required": false, + "description": "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)." + }, + { + "name": "keepdims", + "type": "int64", + "required": false, + "default": 1, + "description": "Keep the reduced dimension or not, default 1 mean keep reduced dimension." + } + ], + "inputs": [ + { + "name": "data", + "type": "T", + "description": "An input tensor." + } + ], + "min_input": 1, + "max_input": 1, + "outputs": [ + { + "name": "reduced", + "type": "T", + "description": "Reduced output tensor." + } + ], + "min_output": 1, + "max_output": 1, + "type_constraints": [ + { + "description": "Constrain input and output types to high-precision numeric tensors.", + "type_param_str": "T", + "allowed_type_strs": [ + "tensor(uint32)", + "tensor(uint64)", + "tensor(int32)", + "tensor(int64)", + "tensor(float16)", + "tensor(float)", + "tensor(double)", + "tensor(bfloat16)" + ] + } + ], + "examples": [ + { + "summary": "default_axes_keepdims", + "code": "shape = [3, 2, 2]\naxes = None\nkeepdims = 1\n\nnode = onnx.helper.make_node(\n 'ReduceL1',\n inputs=['data'],\n outputs=['reduced'],\n keepdims=keepdims\n)\n\ndata = np.reshape(np.arange(1, np.prod(shape) + 1, dtype=np.float32), shape)\n#print(data)\n#[[[1., 2.], [3., 4.]], [[5., 6.], [7., 8.]], [[9., 10.], [11., 12.]]]\n\nreduced = np.sum(a=np.abs(data), axis=axes, keepdims=keepdims == 1)\n#print(reduced)\n#[[[78.]]]\n\nexpect(node, inputs=[data], outputs=[reduced],\n name='test_reduce_l1_default_axes_keepdims_example')\n\nnp.random.seed(0)\ndata = np.random.uniform(-10, 10, shape).astype(np.float32)\nreduced = np.sum(a=np.abs(data), axis=axes, keepdims=keepdims == 1)\n\nexpect(node, inputs=[data], outputs=[reduced],\n name='test_reduce_l1_default_axes_keepdims_random')" + }, + { + "summary": "do_not_keepdims", + "code": "shape = [3, 2, 2]\naxes = [2]\nkeepdims = 0\n\nnode = onnx.helper.make_node(\n 'ReduceL1',\n inputs=['data'],\n outputs=['reduced'],\n axes=axes,\n keepdims=keepdims\n)\n\ndata = np.reshape(np.arange(1, np.prod(shape) + 1, dtype=np.float32), shape)\n#print(data)\n#[[[1., 2.], [3., 4.]], [[5., 6.], [7., 8.]], [[9., 10.], [11., 12.]]]\n\nreduced = np.sum(a=np.abs(data), axis=tuple(axes), keepdims=keepdims == 1)\n#print(reduced)\n#[[3., 7.], [11., 15.], [19., 23.]]\n\nexpect(node, inputs=[data], outputs=[reduced],\n name='test_reduce_l1_do_not_keepdims_example')\n\nnp.random.seed(0)\ndata = np.random.uniform(-10, 10, shape).astype(np.float32)\nreduced = np.sum(a=np.abs(data), axis=tuple(axes), keepdims=keepdims == 1)\n\nexpect(node, inputs=[data], outputs=[reduced],\n name='test_reduce_l1_do_not_keepdims_random')" + }, + { + "summary": "keepdims", + "code": "shape = [3, 2, 2]\naxes = [2]\nkeepdims = 1\n\nnode = onnx.helper.make_node(\n 'ReduceL1',\n inputs=['data'],\n outputs=['reduced'],\n axes=axes,\n keepdims=keepdims\n)\n\ndata = np.reshape(np.arange(1, np.prod(shape) + 1, dtype=np.float32), shape)\n#print(data)\n#[[[1., 2.], [3., 4.]], [[5., 6.], [7., 8.]], [[9., 10.], [11., 12.]]]\n\nreduced = np.sum(a=np.abs(data), axis=tuple(axes), keepdims=keepdims == 1)\n#print(reduced)\n#[[[3.], [7.]], [[11.], [15.]], [[19.], [23.]]]\n\nexpect(node, inputs=[data], outputs=[reduced],\n name='test_reduce_l1_keep_dims_example')\n\nnp.random.seed(0)\ndata = np.random.uniform(-10, 10, shape).astype(np.float32)\nreduced = np.sum(a=np.abs(data), axis=tuple(axes), keepdims=keepdims == 1)\n\nexpect(node, inputs=[data], outputs=[reduced],\n name='test_reduce_l1_keep_dims_random')" + }, + { + "summary": "negative_axes_keepdims", + "code": "shape = [3, 2, 2]\naxes = [-1]\nkeepdims = 1\n\nnode = onnx.helper.make_node(\n 'ReduceL1',\n inputs=['data'],\n outputs=['reduced'],\n axes=axes,\n keepdims=keepdims\n)\n\ndata = np.reshape(np.arange(1, np.prod(shape) + 1, dtype=np.float32), shape)\n# print(data)\n#[[[1., 2.], [3., 4.]], [[5., 6.], [7., 8.]], [[9., 10.], [11., 12.]]]\n\nreduced = np.sum(a=np.abs(data), axis=tuple(axes), keepdims=keepdims == 1)\n# print(reduced)\n#[[[3.], [7.]], [[11.], [15.]], [[19.], [23.]]]\n\nexpect(node, inputs=[data], outputs=[reduced],\n name='test_reduce_l1_negative_axes_keep_dims_example')\n\nnp.random.seed(0)\ndata = np.random.uniform(-10, 10, shape).astype(np.float32)\nreduced = np.sum(a=np.abs(data), axis=tuple(axes), keepdims=keepdims == 1)\n\nexpect(node, inputs=[data], outputs=[reduced],\n name='test_reduce_l1_negative_axes_keep_dims_random')" + } + ] + }, + { + "name": "ReduceL2", + "module": "ai.onnx", + "version": 1, + "support_level": "common", + "description": "Computes the L2 norm of the input tensor's element along the provided axes. The resulted\ntensor has the same rank as the input if keepdims equal 1. If keepdims equal 0, then\nthe resulted tensor have the reduced dimension pruned.\n\nThe above behavior is similar to numpy, with the exception that numpy default keepdims to\nFalse instead of True.", + "attributes": [ + { + "name": "axes", + "type": "int64[]", + "required": false, + "description": "A list of integers, along which to reduce. The default is to reduce over all the dimensions of the input tensor." + }, + { + "name": "keepdims", + "type": "int64", + "required": false, + "default": 1, + "description": "Keep the reduced dimension or not, default 1 mean keep reduced dimension." + } + ], + "inputs": [ + { + "name": "data", + "type": "T", + "description": "An input tensor." + } + ], + "min_input": 1, + "max_input": 1, + "outputs": [ + { + "name": "reduced", + "type": "T", + "description": "Reduced output tensor." + } + ], + "min_output": 1, + "max_output": 1, + "type_constraints": [ + { + "description": "Constrain input and output types to high-precision numeric tensors.", + "type_param_str": "T", + "allowed_type_strs": [ + "tensor(uint32)", + "tensor(uint64)", + "tensor(int32)", + "tensor(int64)", + "tensor(float16)", + "tensor(float)", + "tensor(double)" + ] + } + ], + "examples": [ + { + "summary": "default_axes_keepdims", + "code": "shape = [3, 2, 2]\naxes = None\nkeepdims = 1\n\nnode = onnx.helper.make_node(\n 'ReduceL2',\n inputs=['data'],\n outputs=['reduced'],\n keepdims=keepdims\n)\n\ndata = np.reshape(np.arange(1, np.prod(shape) + 1, dtype=np.float32), shape)\n#print(data)\n#[[[1., 2.], [3., 4.]], [[5., 6.], [7., 8.]], [[9., 10.], [11., 12.]]]\n\nreduced = np.sqrt(np.sum(\n a=np.square(data), axis=axes, keepdims=keepdims == 1))\n#print(reduced)\n#[[[25.49509757]]]\n\nexpect(node, inputs=[data], outputs=[reduced],\n name='test_reduce_l2_default_axes_keepdims_example')\n\nnp.random.seed(0)\ndata = np.random.uniform(-10, 10, shape).astype(np.float32)\nreduced = np.sqrt(np.sum(\n a=np.square(data), axis=axes, keepdims=keepdims == 1))\n\nexpect(node, inputs=[data], outputs=[reduced],\n name='test_reduce_l2_default_axes_keepdims_random')" + }, + { + "summary": "do_not_keepdims", + "code": "shape = [3, 2, 2]\naxes = [2]\nkeepdims = 0\n\nnode = onnx.helper.make_node(\n 'ReduceL2',\n inputs=['data'],\n outputs=['reduced'],\n axes=axes,\n keepdims=keepdims\n)\n\ndata = np.reshape(np.arange(1, np.prod(shape) + 1, dtype=np.float32), shape)\n#print(data)\n#[[[1., 2.], [3., 4.]], [[5., 6.], [7., 8.]], [[9., 10.], [11., 12.]]]\n\nreduced = np.sqrt(np.sum(\n a=np.square(data), axis=tuple(axes), keepdims=keepdims == 1))\n#print(reduced)\n#[[2.23606798, 5.],\n# [7.81024968, 10.63014581],\n# [13.45362405, 16.2788206]]\n\nexpect(node, inputs=[data], outputs=[reduced],\n name='test_reduce_l2_do_not_keepdims_example')\n\nnp.random.seed(0)\ndata = np.random.uniform(-10, 10, shape).astype(np.float32)\nreduced = np.sqrt(np.sum(\n a=np.square(data), axis=tuple(axes), keepdims=keepdims == 1))\n\nexpect(node, inputs=[data], outputs=[reduced],\n name='test_reduce_l2_do_not_keepdims_random')" + }, + { + "summary": "keepdims", + "code": "shape = [3, 2, 2]\naxes = [2]\nkeepdims = 1\n\nnode = onnx.helper.make_node(\n 'ReduceL2',\n inputs=['data'],\n outputs=['reduced'],\n axes=axes,\n keepdims=keepdims\n)\n\ndata = np.reshape(np.arange(1, np.prod(shape) + 1, dtype=np.float32), shape)\n#print(data)\n#[[[1., 2.], [3., 4.]], [[5., 6.], [7., 8.]], [[9., 10.], [11., 12.]]]\n\nreduced = np.sqrt(np.sum(\n a=np.square(data), axis=tuple(axes), keepdims=keepdims == 1))\n#print(reduced)\n#[[[2.23606798], [5.]]\n# [[7.81024968], [10.63014581]]\n# [[13.45362405], [16.2788206 ]]]\n\nexpect(node, inputs=[data], outputs=[reduced],\n name='test_reduce_l2_keep_dims_example')\n\nnp.random.seed(0)\ndata = np.random.uniform(-10, 10, shape).astype(np.float32)\nreduced = np.sqrt(np.sum(\n a=np.square(data), axis=tuple(axes), keepdims=keepdims == 1))\n\nexpect(node, inputs=[data], outputs=[reduced], name='test_reduce_l2_keep_dims_random')" + }, + { + "summary": "negative_axes_keepdims", + "code": "shape = [3, 2, 2]\naxes = [-1]\nkeepdims = 1\n\nnode = onnx.helper.make_node(\n 'ReduceL2',\n inputs=['data'],\n outputs=['reduced'],\n axes=axes,\n keepdims=keepdims\n)\n\ndata = np.reshape(np.arange(1, np.prod(shape) + 1, dtype=np.float32), shape)\n# print(data)\n#[[[1., 2.], [3., 4.]], [[5., 6.], [7., 8.]], [[9., 10.], [11., 12.]]]\n\nreduced = np.sqrt(np.sum(\n a=np.square(data), axis=tuple(axes), keepdims=keepdims == 1))\n# print(reduced)\n#[[[2.23606798], [5.]]\n# [[7.81024968], [10.63014581]]\n# [[13.45362405], [16.2788206 ]]]\n\nexpect(node, inputs=[data], outputs=[reduced],\n name='test_reduce_l2_negative_axes_keep_dims_example')\n\nnp.random.seed(0)\ndata = np.random.uniform(-10, 10, shape).astype(np.float32)\nreduced = np.sqrt(np.sum(\n a=np.square(data), axis=tuple(axes), keepdims=keepdims == 1))\n\nexpect(node, inputs=[data], outputs=[reduced],\n name='test_reduce_l2_negative_axes_keep_dims_random')" + } + ] + }, + { + "name": "ReduceL2", + "module": "ai.onnx", + "version": 11, + "support_level": "common", + "description": "Computes the L2 norm of the input tensor's element along the provided axes. The resulted\ntensor has the same rank as the input if keepdims equal 1. If keepdims equal 0, then\nthe resulted tensor have the reduced dimension pruned.\n\nThe above behavior is similar to numpy, with the exception that numpy default keepdims to\nFalse instead of True.", + "attributes": [ + { + "name": "axes", + "type": "int64[]", + "required": false, + "description": "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)." + }, + { + "name": "keepdims", + "type": "int64", + "required": false, + "default": 1, + "description": "Keep the reduced dimension or not, default 1 mean keep reduced dimension." + } + ], + "inputs": [ + { + "name": "data", + "type": "T", + "description": "An input tensor." + } + ], + "min_input": 1, + "max_input": 1, + "outputs": [ + { + "name": "reduced", + "type": "T", + "description": "Reduced output tensor." + } + ], + "min_output": 1, + "max_output": 1, + "type_constraints": [ + { + "description": "Constrain input and output types to high-precision numeric tensors.", + "type_param_str": "T", + "allowed_type_strs": [ + "tensor(uint32)", + "tensor(uint64)", + "tensor(int32)", + "tensor(int64)", + "tensor(float16)", + "tensor(float)", + "tensor(double)" + ] + } + ], + "examples": [ + { + "summary": "default_axes_keepdims", + "code": "shape = [3, 2, 2]\naxes = None\nkeepdims = 1\n\nnode = onnx.helper.make_node(\n 'ReduceL2',\n inputs=['data'],\n outputs=['reduced'],\n keepdims=keepdims\n)\n\ndata = np.reshape(np.arange(1, np.prod(shape) + 1, dtype=np.float32), shape)\n#print(data)\n#[[[1., 2.], [3., 4.]], [[5., 6.], [7., 8.]], [[9., 10.], [11., 12.]]]\n\nreduced = np.sqrt(np.sum(\n a=np.square(data), axis=axes, keepdims=keepdims == 1))\n#print(reduced)\n#[[[25.49509757]]]\n\nexpect(node, inputs=[data], outputs=[reduced],\n name='test_reduce_l2_default_axes_keepdims_example')\n\nnp.random.seed(0)\ndata = np.random.uniform(-10, 10, shape).astype(np.float32)\nreduced = np.sqrt(np.sum(\n a=np.square(data), axis=axes, keepdims=keepdims == 1))\n\nexpect(node, inputs=[data], outputs=[reduced],\n name='test_reduce_l2_default_axes_keepdims_random')" + }, + { + "summary": "do_not_keepdims", + "code": "shape = [3, 2, 2]\naxes = [2]\nkeepdims = 0\n\nnode = onnx.helper.make_node(\n 'ReduceL2',\n inputs=['data'],\n outputs=['reduced'],\n axes=axes,\n keepdims=keepdims\n)\n\ndata = np.reshape(np.arange(1, np.prod(shape) + 1, dtype=np.float32), shape)\n#print(data)\n#[[[1., 2.], [3., 4.]], [[5., 6.], [7., 8.]], [[9., 10.], [11., 12.]]]\n\nreduced = np.sqrt(np.sum(\n a=np.square(data), axis=tuple(axes), keepdims=keepdims == 1))\n#print(reduced)\n#[[2.23606798, 5.],\n# [7.81024968, 10.63014581],\n# [13.45362405, 16.2788206]]\n\nexpect(node, inputs=[data], outputs=[reduced],\n name='test_reduce_l2_do_not_keepdims_example')\n\nnp.random.seed(0)\ndata = np.random.uniform(-10, 10, shape).astype(np.float32)\nreduced = np.sqrt(np.sum(\n a=np.square(data), axis=tuple(axes), keepdims=keepdims == 1))\n\nexpect(node, inputs=[data], outputs=[reduced],\n name='test_reduce_l2_do_not_keepdims_random')" + }, + { + "summary": "keepdims", + "code": "shape = [3, 2, 2]\naxes = [2]\nkeepdims = 1\n\nnode = onnx.helper.make_node(\n 'ReduceL2',\n inputs=['data'],\n outputs=['reduced'],\n axes=axes,\n keepdims=keepdims\n)\n\ndata = np.reshape(np.arange(1, np.prod(shape) + 1, dtype=np.float32), shape)\n#print(data)\n#[[[1., 2.], [3., 4.]], [[5., 6.], [7., 8.]], [[9., 10.], [11., 12.]]]\n\nreduced = np.sqrt(np.sum(\n a=np.square(data), axis=tuple(axes), keepdims=keepdims == 1))\n#print(reduced)\n#[[[2.23606798], [5.]]\n# [[7.81024968], [10.63014581]]\n# [[13.45362405], [16.2788206 ]]]\n\nexpect(node, inputs=[data], outputs=[reduced],\n name='test_reduce_l2_keep_dims_example')\n\nnp.random.seed(0)\ndata = np.random.uniform(-10, 10, shape).astype(np.float32)\nreduced = np.sqrt(np.sum(\n a=np.square(data), axis=tuple(axes), keepdims=keepdims == 1))\n\nexpect(node, inputs=[data], outputs=[reduced], name='test_reduce_l2_keep_dims_random')" + }, + { + "summary": "negative_axes_keepdims", + "code": "shape = [3, 2, 2]\naxes = [-1]\nkeepdims = 1\n\nnode = onnx.helper.make_node(\n 'ReduceL2',\n inputs=['data'],\n outputs=['reduced'],\n axes=axes,\n keepdims=keepdims\n)\n\ndata = np.reshape(np.arange(1, np.prod(shape) + 1, dtype=np.float32), shape)\n# print(data)\n#[[[1., 2.], [3., 4.]], [[5., 6.], [7., 8.]], [[9., 10.], [11., 12.]]]\n\nreduced = np.sqrt(np.sum(\n a=np.square(data), axis=tuple(axes), keepdims=keepdims == 1))\n# print(reduced)\n#[[[2.23606798], [5.]]\n# [[7.81024968], [10.63014581]]\n# [[13.45362405], [16.2788206 ]]]\n\nexpect(node, inputs=[data], outputs=[reduced],\n name='test_reduce_l2_negative_axes_keep_dims_example')\n\nnp.random.seed(0)\ndata = np.random.uniform(-10, 10, shape).astype(np.float32)\nreduced = np.sqrt(np.sum(\n a=np.square(data), axis=tuple(axes), keepdims=keepdims == 1))\n\nexpect(node, inputs=[data], outputs=[reduced],\n name='test_reduce_l2_negative_axes_keep_dims_random')" + } + ] + }, + { + "name": "ReduceL2", + "module": "ai.onnx", + "version": 13, + "support_level": "common", + "description": "Computes the L2 norm of the input tensor's element along the provided axes. The resulted\ntensor has the same rank as the input if keepdims equal 1. If keepdims equal 0, then\nthe resulted tensor have the reduced dimension pruned.\n\nThe above behavior is similar to numpy, with the exception that numpy default keepdims to\nFalse instead of True.", + "attributes": [ + { + "name": "axes", + "type": "int64[]", + "required": false, + "description": "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)." + }, + { + "name": "keepdims", + "type": "int64", + "required": false, + "default": 1, + "description": "Keep the reduced dimension or not, default 1 mean keep reduced dimension." + } + ], + "inputs": [ + { + "name": "data", + "type": "T", + "description": "An input tensor." + } + ], + "min_input": 1, + "max_input": 1, + "outputs": [ + { + "name": "reduced", + "type": "T", + "description": "Reduced output tensor." + } + ], + "min_output": 1, + "max_output": 1, + "type_constraints": [ + { + "description": "Constrain input and output types to high-precision numeric tensors.", + "type_param_str": "T", + "allowed_type_strs": [ + "tensor(uint32)", + "tensor(uint64)", + "tensor(int32)", + "tensor(int64)", + "tensor(float16)", + "tensor(float)", + "tensor(double)", + "tensor(bfloat16)" + ] + } + ], + "examples": [ + { + "summary": "default_axes_keepdims", + "code": "shape = [3, 2, 2]\naxes = None\nkeepdims = 1\n\nnode = onnx.helper.make_node(\n 'ReduceL2',\n inputs=['data'],\n outputs=['reduced'],\n keepdims=keepdims\n)\n\ndata = np.reshape(np.arange(1, np.prod(shape) + 1, dtype=np.float32), shape)\n#print(data)\n#[[[1., 2.], [3., 4.]], [[5., 6.], [7., 8.]], [[9., 10.], [11., 12.]]]\n\nreduced = np.sqrt(np.sum(\n a=np.square(data), axis=axes, keepdims=keepdims == 1))\n#print(reduced)\n#[[[25.49509757]]]\n\nexpect(node, inputs=[data], outputs=[reduced],\n name='test_reduce_l2_default_axes_keepdims_example')\n\nnp.random.seed(0)\ndata = np.random.uniform(-10, 10, shape).astype(np.float32)\nreduced = np.sqrt(np.sum(\n a=np.square(data), axis=axes, keepdims=keepdims == 1))\n\nexpect(node, inputs=[data], outputs=[reduced],\n name='test_reduce_l2_default_axes_keepdims_random')" + }, + { + "summary": "do_not_keepdims", + "code": "shape = [3, 2, 2]\naxes = [2]\nkeepdims = 0\n\nnode = onnx.helper.make_node(\n 'ReduceL2',\n inputs=['data'],\n outputs=['reduced'],\n axes=axes,\n keepdims=keepdims\n)\n\ndata = np.reshape(np.arange(1, np.prod(shape) + 1, dtype=np.float32), shape)\n#print(data)\n#[[[1., 2.], [3., 4.]], [[5., 6.], [7., 8.]], [[9., 10.], [11., 12.]]]\n\nreduced = np.sqrt(np.sum(\n a=np.square(data), axis=tuple(axes), keepdims=keepdims == 1))\n#print(reduced)\n#[[2.23606798, 5.],\n# [7.81024968, 10.63014581],\n# [13.45362405, 16.2788206]]\n\nexpect(node, inputs=[data], outputs=[reduced],\n name='test_reduce_l2_do_not_keepdims_example')\n\nnp.random.seed(0)\ndata = np.random.uniform(-10, 10, shape).astype(np.float32)\nreduced = np.sqrt(np.sum(\n a=np.square(data), axis=tuple(axes), keepdims=keepdims == 1))\n\nexpect(node, inputs=[data], outputs=[reduced],\n name='test_reduce_l2_do_not_keepdims_random')" + }, + { + "summary": "keepdims", + "code": "shape = [3, 2, 2]\naxes = [2]\nkeepdims = 1\n\nnode = onnx.helper.make_node(\n 'ReduceL2',\n inputs=['data'],\n outputs=['reduced'],\n axes=axes,\n keepdims=keepdims\n)\n\ndata = np.reshape(np.arange(1, np.prod(shape) + 1, dtype=np.float32), shape)\n#print(data)\n#[[[1., 2.], [3., 4.]], [[5., 6.], [7., 8.]], [[9., 10.], [11., 12.]]]\n\nreduced = np.sqrt(np.sum(\n a=np.square(data), axis=tuple(axes), keepdims=keepdims == 1))\n#print(reduced)\n#[[[2.23606798], [5.]]\n# [[7.81024968], [10.63014581]]\n# [[13.45362405], [16.2788206 ]]]\n\nexpect(node, inputs=[data], outputs=[reduced],\n name='test_reduce_l2_keep_dims_example')\n\nnp.random.seed(0)\ndata = np.random.uniform(-10, 10, shape).astype(np.float32)\nreduced = np.sqrt(np.sum(\n a=np.square(data), axis=tuple(axes), keepdims=keepdims == 1))\n\nexpect(node, inputs=[data], outputs=[reduced], name='test_reduce_l2_keep_dims_random')" + }, + { + "summary": "negative_axes_keepdims", + "code": "shape = [3, 2, 2]\naxes = [-1]\nkeepdims = 1\n\nnode = onnx.helper.make_node(\n 'ReduceL2',\n inputs=['data'],\n outputs=['reduced'],\n axes=axes,\n keepdims=keepdims\n)\n\ndata = np.reshape(np.arange(1, np.prod(shape) + 1, dtype=np.float32), shape)\n# print(data)\n#[[[1., 2.], [3., 4.]], [[5., 6.], [7., 8.]], [[9., 10.], [11., 12.]]]\n\nreduced = np.sqrt(np.sum(\n a=np.square(data), axis=tuple(axes), keepdims=keepdims == 1))\n# print(reduced)\n#[[[2.23606798], [5.]]\n# [[7.81024968], [10.63014581]]\n# [[13.45362405], [16.2788206 ]]]\n\nexpect(node, inputs=[data], outputs=[reduced],\n name='test_reduce_l2_negative_axes_keep_dims_example')\n\nnp.random.seed(0)\ndata = np.random.uniform(-10, 10, shape).astype(np.float32)\nreduced = np.sqrt(np.sum(\n a=np.square(data), axis=tuple(axes), keepdims=keepdims == 1))\n\nexpect(node, inputs=[data], outputs=[reduced],\n name='test_reduce_l2_negative_axes_keep_dims_random')" + } + ] + }, + { + "name": "ReduceLogSum", + "module": "ai.onnx", + "version": 1, + "support_level": "common", + "description": "Computes the log sum of the input tensor's element along the provided axes. The resulted\ntensor has the same rank as the input if keepdims equal 1. If keepdims equal 0, then\nthe resulted tensor have the reduced dimension pruned.\n\nThe above behavior is similar to numpy, with the exception that numpy default keepdims to\nFalse instead of True.", + "attributes": [ + { + "name": "axes", + "type": "int64[]", + "required": false, + "description": "A list of integers, along which to reduce. The default is to reduce over all the dimensions of the input tensor." + }, + { + "name": "keepdims", + "type": "int64", + "required": false, + "default": 1, + "description": "Keep the reduced dimension or not, default 1 mean keep reduced dimension." + } + ], + "inputs": [ + { + "name": "data", + "type": "T", + "description": "An input tensor." + } + ], + "min_input": 1, + "max_input": 1, + "outputs": [ + { + "name": "reduced", + "type": "T", + "description": "Reduced output tensor." + } + ], + "min_output": 1, + "max_output": 1, + "type_constraints": [ + { + "description": "Constrain input and output types to high-precision numeric tensors.", + "type_param_str": "T", + "allowed_type_strs": [ + "tensor(uint32)", + "tensor(uint64)", + "tensor(int32)", + "tensor(int64)", + "tensor(float16)", + "tensor(float)", + "tensor(double)" + ] + } + ], + "examples": [ + { + "summary": "keepdims", + "code": "node = onnx.helper.make_node(\n 'ReduceLogSum',\n inputs=['data'],\n outputs=[\"reduced\"]\n)\ndata = np.random.ranf([3, 4, 5]).astype(np.float32)\nreduced = np.log(np.sum(data, keepdims=True))\nexpect(node, inputs=[data], outputs=[reduced],\n name='test_reduce_log_sum_default')" + }, + { + "summary": "negative_axes_keepdims", + "code": "node = onnx.helper.make_node(\n 'ReduceLogSum',\n inputs=['data'],\n outputs=[\"reduced\"],\n axes=[-2]\n)\ndata = np.random.ranf([3, 4, 5]).astype(np.float32)\nreduced = np.log(np.sum(data, axis=(-2), keepdims=True))\n# print(reduced)\nexpect(node, inputs=[data], outputs=[reduced],\n name='test_reduce_log_sum_negative_axes')" + }, + { + "summary": "nokeepdims", + "code": "node = onnx.helper.make_node(\n 'ReduceLogSum',\n inputs=['data'],\n outputs=[\"reduced\"],\n axes=[2, 1],\n keepdims=0\n)\ndata = np.random.ranf([3, 4, 5]).astype(np.float32)\nreduced = np.log(np.sum(data, axis=(2, 1), keepdims=False))\nexpect(node, inputs=[data], outputs=[reduced],\n name='test_reduce_log_sum_desc_axes')\n\nnode = onnx.helper.make_node(\n 'ReduceLogSum',\n inputs=['data'],\n outputs=[\"reduced\"],\n axes=[0, 1],\n keepdims=0\n)\ndata = np.random.ranf([3, 4, 5]).astype(np.float32)\nreduced = np.log(np.sum(data, axis=(0, 1), keepdims=False))\nexpect(node, inputs=[data], outputs=[reduced],\n name='test_reduce_log_sum_asc_axes')" + } + ] + }, + { + "name": "ReduceLogSum", + "module": "ai.onnx", + "version": 11, + "support_level": "common", + "description": "Computes the log sum of the input tensor's element along the provided axes. The resulted\ntensor has the same rank as the input if keepdims equal 1. If keepdims equal 0, then\nthe resulted tensor have the reduced dimension pruned.\n\nThe above behavior is similar to numpy, with the exception that numpy default keepdims to\nFalse instead of True.", + "attributes": [ + { + "name": "axes", + "type": "int64[]", + "required": false, + "description": "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)." + }, + { + "name": "keepdims", + "type": "int64", + "required": false, + "default": 1, + "description": "Keep the reduced dimension or not, default 1 mean keep reduced dimension." + } + ], + "inputs": [ + { + "name": "data", + "type": "T", + "description": "An input tensor." + } + ], + "min_input": 1, + "max_input": 1, + "outputs": [ + { + "name": "reduced", + "type": "T", + "description": "Reduced output tensor." + } + ], + "min_output": 1, + "max_output": 1, + "type_constraints": [ + { + "description": "Constrain input and output types to high-precision numeric tensors.", + "type_param_str": "T", + "allowed_type_strs": [ + "tensor(uint32)", + "tensor(uint64)", + "tensor(int32)", + "tensor(int64)", + "tensor(float16)", + "tensor(float)", + "tensor(double)" + ] + } + ], + "examples": [ + { + "summary": "keepdims", + "code": "node = onnx.helper.make_node(\n 'ReduceLogSum',\n inputs=['data'],\n outputs=[\"reduced\"]\n)\ndata = np.random.ranf([3, 4, 5]).astype(np.float32)\nreduced = np.log(np.sum(data, keepdims=True))\nexpect(node, inputs=[data], outputs=[reduced],\n name='test_reduce_log_sum_default')" + }, + { + "summary": "negative_axes_keepdims", + "code": "node = onnx.helper.make_node(\n 'ReduceLogSum',\n inputs=['data'],\n outputs=[\"reduced\"],\n axes=[-2]\n)\ndata = np.random.ranf([3, 4, 5]).astype(np.float32)\nreduced = np.log(np.sum(data, axis=(-2), keepdims=True))\n# print(reduced)\nexpect(node, inputs=[data], outputs=[reduced],\n name='test_reduce_log_sum_negative_axes')" + }, + { + "summary": "nokeepdims", + "code": "node = onnx.helper.make_node(\n 'ReduceLogSum',\n inputs=['data'],\n outputs=[\"reduced\"],\n axes=[2, 1],\n keepdims=0\n)\ndata = np.random.ranf([3, 4, 5]).astype(np.float32)\nreduced = np.log(np.sum(data, axis=(2, 1), keepdims=False))\nexpect(node, inputs=[data], outputs=[reduced],\n name='test_reduce_log_sum_desc_axes')\n\nnode = onnx.helper.make_node(\n 'ReduceLogSum',\n inputs=['data'],\n outputs=[\"reduced\"],\n axes=[0, 1],\n keepdims=0\n)\ndata = np.random.ranf([3, 4, 5]).astype(np.float32)\nreduced = np.log(np.sum(data, axis=(0, 1), keepdims=False))\nexpect(node, inputs=[data], outputs=[reduced],\n name='test_reduce_log_sum_asc_axes')" + } + ] + }, + { + "name": "ReduceLogSum", + "module": "ai.onnx", + "version": 13, + "support_level": "common", + "description": "Computes the log sum of the input tensor's element along the provided axes. The resulted\ntensor has the same rank as the input if keepdims equal 1. If keepdims equal 0, then\nthe resulted tensor have the reduced dimension pruned.\n\nThe above behavior is similar to numpy, with the exception that numpy default keepdims to\nFalse instead of True.", + "attributes": [ + { + "name": "axes", + "type": "int64[]", + "required": false, + "description": "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)." + }, + { + "name": "keepdims", + "type": "int64", + "required": false, + "default": 1, + "description": "Keep the reduced dimension or not, default 1 mean keep reduced dimension." + } + ], + "inputs": [ + { + "name": "data", + "type": "T", + "description": "An input tensor." + } + ], + "min_input": 1, + "max_input": 1, + "outputs": [ + { + "name": "reduced", + "type": "T", + "description": "Reduced output tensor." + } + ], + "min_output": 1, + "max_output": 1, + "type_constraints": [ + { + "description": "Constrain input and output types to high-precision numeric tensors.", + "type_param_str": "T", + "allowed_type_strs": [ + "tensor(uint32)", + "tensor(uint64)", + "tensor(int32)", + "tensor(int64)", + "tensor(float16)", + "tensor(float)", + "tensor(double)", + "tensor(bfloat16)" + ] + } + ], + "examples": [ + { + "summary": "keepdims", + "code": "node = onnx.helper.make_node(\n 'ReduceLogSum',\n inputs=['data'],\n outputs=[\"reduced\"]\n)\ndata = np.random.ranf([3, 4, 5]).astype(np.float32)\nreduced = np.log(np.sum(data, keepdims=True))\nexpect(node, inputs=[data], outputs=[reduced],\n name='test_reduce_log_sum_default')" + }, + { + "summary": "negative_axes_keepdims", + "code": "node = onnx.helper.make_node(\n 'ReduceLogSum',\n inputs=['data'],\n outputs=[\"reduced\"],\n axes=[-2]\n)\ndata = np.random.ranf([3, 4, 5]).astype(np.float32)\nreduced = np.log(np.sum(data, axis=(-2), keepdims=True))\n# print(reduced)\nexpect(node, inputs=[data], outputs=[reduced],\n name='test_reduce_log_sum_negative_axes')" + }, + { + "summary": "nokeepdims", + "code": "node = onnx.helper.make_node(\n 'ReduceLogSum',\n inputs=['data'],\n outputs=[\"reduced\"],\n axes=[2, 1],\n keepdims=0\n)\ndata = np.random.ranf([3, 4, 5]).astype(np.float32)\nreduced = np.log(np.sum(data, axis=(2, 1), keepdims=False))\nexpect(node, inputs=[data], outputs=[reduced],\n name='test_reduce_log_sum_desc_axes')\n\nnode = onnx.helper.make_node(\n 'ReduceLogSum',\n inputs=['data'],\n outputs=[\"reduced\"],\n axes=[0, 1],\n keepdims=0\n)\ndata = np.random.ranf([3, 4, 5]).astype(np.float32)\nreduced = np.log(np.sum(data, axis=(0, 1), keepdims=False))\nexpect(node, inputs=[data], outputs=[reduced],\n name='test_reduce_log_sum_asc_axes')" + } + ] + }, + { + "name": "ReduceLogSumExp", + "module": "ai.onnx", + "version": 1, + "support_level": "common", + "description": "Computes the log sum exponent of the input tensor's element along the provided axes. The resulted\ntensor has the same rank as the input if keepdims equal 1. If keepdims equal 0, then\nthe resulted tensor have the reduced dimension pruned.\n\nThe above behavior is similar to numpy, with the exception that numpy default keepdims to\nFalse instead of True.", + "attributes": [ + { + "name": "axes", + "type": "int64[]", + "required": false, + "description": "A list of integers, along which to reduce. The default is to reduce over all the dimensions of the input tensor." + }, + { + "name": "keepdims", + "type": "int64", + "required": false, + "default": 1, + "description": "Keep the reduced dimension or not, default 1 mean keep reduced dimension." + } + ], + "inputs": [ + { + "name": "data", + "type": "T", + "description": "An input tensor." + } + ], + "min_input": 1, + "max_input": 1, + "outputs": [ + { + "name": "reduced", + "type": "T", + "description": "Reduced output tensor." + } + ], + "min_output": 1, + "max_output": 1, + "type_constraints": [ + { + "description": "Constrain input and output types to high-precision numeric tensors.", + "type_param_str": "T", + "allowed_type_strs": [ + "tensor(uint32)", + "tensor(uint64)", + "tensor(int32)", + "tensor(int64)", + "tensor(float16)", + "tensor(float)", + "tensor(double)" + ] + } + ], + "examples": [ + { + "summary": "default_axes_keepdims", + "code": "shape = [3, 2, 2]\naxes = None\nkeepdims = 1\n\nnode = onnx.helper.make_node(\n 'ReduceLogSumExp',\n inputs=['data'],\n outputs=['reduced'],\n keepdims=keepdims\n)\n\ndata = np.array(\n [[[5, 1], [20, 2]], [[30, 1], [40, 2]], [[55, 1], [60, 2]]],\n dtype=np.double)\nreduced = np.log(np.sum(np.exp(data),\n axis=axes,\n keepdims=keepdims == 1))\n# print(reduced)\n# [[[60.00671387]]]\n\nexpect(node, inputs=[data], outputs=[reduced],\n name='test_reduce_log_sum_exp_default_axes_keepdims_example')\n\nnp.random.seed(0)\ndata = np.random.uniform(-10, 10, shape).astype(np.double)\nreduced = np.log(np.sum(np.exp(data),\n axis=axes,\n keepdims=keepdims == 1))\nexpect(node, inputs=[data], outputs=[reduced],\n name='test_reduce_log_sum_exp_default_axes_keepdims_random')" + }, + { + "summary": "do_not_keepdims", + "code": "shape = [3, 2, 2]\naxes = [1]\nkeepdims = 0\nnode = onnx.helper.make_node(\n 'ReduceLogSumExp',\n inputs=['data'],\n outputs=['reduced'],\n axes=axes,\n keepdims=keepdims\n)\n\ndata = np.array(\n [[[5, 1], [20, 2]], [[30, 1], [40, 2]], [[55, 1], [60, 2]]],\n dtype=np.double)\nreduced = np.log(np.sum(\n np.exp(data), axis=tuple(axes), keepdims=keepdims == 1))\n# print(reduced)\n#[[20., 2.31326175]\n# [40.00004578, 2.31326175]\n# [60.00671387, 2.31326175]]\n\nexpect(node, inputs=[data], outputs=[reduced],\n name='test_reduce_log_sum_exp_do_not_keepdims_example')\n\nnp.random.seed(0)\ndata = np.random.uniform(-10, 10, shape).astype(np.double)\nreduced = np.log(np.sum(\n np.exp(data), axis=tuple(axes), keepdims=keepdims == 1))\n\nexpect(node, inputs=[data], outputs=[reduced],\n name='test_reduce_log_sum_exp_do_not_keepdims_random')" + }, + { + "summary": "keepdims", + "code": "shape = [3, 2, 2]\naxes = [1]\nkeepdims = 1\nnode = onnx.helper.make_node(\n 'ReduceLogSumExp',\n inputs=['data'],\n outputs=['reduced'],\n axes=axes,\n keepdims=keepdims\n)\n\ndata = np.array(\n [[[5, 1], [20, 2]], [[30, 1], [40, 2]], [[55, 1], [60, 2]]],\n dtype=np.double)\nreduced = np.log(np.sum(np.exp(data),\n axis=tuple(axes),\n keepdims=keepdims == 1))\n# print(reduced)\n# [[[20., 2.31326175]]\n# [[40.00004578, 2.31326175]]\n# [[60.00671387, 2.31326175]]]\n\nexpect(node, inputs=[data], outputs=[reduced],\n name='test_reduce_log_sum_exp_keepdims_example')\n\nnp.random.seed(0)\ndata = np.random.uniform(-10, 10, shape).astype(np.double)\nreduced = np.log(np.sum(np.exp(data),\n axis=tuple(axes),\n keepdims=keepdims == 1))\n\nexpect(node, inputs=[data], outputs=[reduced],\n name='test_reduce_log_sum_exp_keepdims_random')" + }, + { + "summary": "negative_axes_keepdims", + "code": "shape = [3, 2, 2]\naxes = [-2]\nkeepdims = 1\nnode = onnx.helper.make_node(\n 'ReduceLogSumExp',\n inputs=['data'],\n outputs=['reduced'],\n axes=axes,\n keepdims=keepdims\n)\n\ndata = np.array(\n [[[5, 1], [20, 2]], [[30, 1], [40, 2]], [[55, 1], [60, 2]]],\n dtype=np.double)\nreduced = np.log(np.sum(np.exp(data),\n axis=tuple(axes),\n keepdims=keepdims == 1))\n# print(reduced)\n# [[[20., 2.31326175]]\n# [[40.00004578, 2.31326175]]\n# [[60.00671387, 2.31326175]]]\n\nexpect(node, inputs=[data], outputs=[reduced],\n name='test_reduce_log_sum_exp_negative_axes_keepdims_example')\n\nnp.random.seed(0)\ndata = np.random.uniform(-10, 10, shape).astype(np.double)\nreduced = np.log(np.sum(np.exp(data),\n axis=tuple(axes),\n keepdims=keepdims == 1))\n\nexpect(node, inputs=[data], outputs=[reduced],\n name='test_reduce_log_sum_exp_negative_axes_keepdims_random')" + } + ] + }, + { + "name": "ReduceLogSumExp", + "module": "ai.onnx", + "version": 11, + "support_level": "common", + "description": "Computes the log sum exponent of the input tensor's element along the provided axes. The resulted\ntensor has the same rank as the input if keepdims equal 1. If keepdims equal 0, then\nthe resulted tensor have the reduced dimension pruned.\n\nThe above behavior is similar to numpy, with the exception that numpy default keepdims to\nFalse instead of True.", + "attributes": [ + { + "name": "axes", + "type": "int64[]", + "required": false, + "description": "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)." + }, + { + "name": "keepdims", + "type": "int64", + "required": false, + "default": 1, + "description": "Keep the reduced dimension or not, default 1 mean keep reduced dimension." + } + ], + "inputs": [ + { + "name": "data", + "type": "T", + "description": "An input tensor." + } + ], + "min_input": 1, + "max_input": 1, + "outputs": [ + { + "name": "reduced", + "type": "T", + "description": "Reduced output tensor." + } + ], + "min_output": 1, + "max_output": 1, + "type_constraints": [ + { + "description": "Constrain input and output types to high-precision numeric tensors.", + "type_param_str": "T", + "allowed_type_strs": [ + "tensor(uint32)", + "tensor(uint64)", + "tensor(int32)", + "tensor(int64)", + "tensor(float16)", + "tensor(float)", + "tensor(double)" + ] + } + ], + "examples": [ + { + "summary": "default_axes_keepdims", + "code": "shape = [3, 2, 2]\naxes = None\nkeepdims = 1\n\nnode = onnx.helper.make_node(\n 'ReduceLogSumExp',\n inputs=['data'],\n outputs=['reduced'],\n keepdims=keepdims\n)\n\ndata = np.array(\n [[[5, 1], [20, 2]], [[30, 1], [40, 2]], [[55, 1], [60, 2]]],\n dtype=np.double)\nreduced = np.log(np.sum(np.exp(data),\n axis=axes,\n keepdims=keepdims == 1))\n# print(reduced)\n# [[[60.00671387]]]\n\nexpect(node, inputs=[data], outputs=[reduced],\n name='test_reduce_log_sum_exp_default_axes_keepdims_example')\n\nnp.random.seed(0)\ndata = np.random.uniform(-10, 10, shape).astype(np.double)\nreduced = np.log(np.sum(np.exp(data),\n axis=axes,\n keepdims=keepdims == 1))\nexpect(node, inputs=[data], outputs=[reduced],\n name='test_reduce_log_sum_exp_default_axes_keepdims_random')" + }, + { + "summary": "do_not_keepdims", + "code": "shape = [3, 2, 2]\naxes = [1]\nkeepdims = 0\nnode = onnx.helper.make_node(\n 'ReduceLogSumExp',\n inputs=['data'],\n outputs=['reduced'],\n axes=axes,\n keepdims=keepdims\n)\n\ndata = np.array(\n [[[5, 1], [20, 2]], [[30, 1], [40, 2]], [[55, 1], [60, 2]]],\n dtype=np.double)\nreduced = np.log(np.sum(\n np.exp(data), axis=tuple(axes), keepdims=keepdims == 1))\n# print(reduced)\n#[[20., 2.31326175]\n# [40.00004578, 2.31326175]\n# [60.00671387, 2.31326175]]\n\nexpect(node, inputs=[data], outputs=[reduced],\n name='test_reduce_log_sum_exp_do_not_keepdims_example')\n\nnp.random.seed(0)\ndata = np.random.uniform(-10, 10, shape).astype(np.double)\nreduced = np.log(np.sum(\n np.exp(data), axis=tuple(axes), keepdims=keepdims == 1))\n\nexpect(node, inputs=[data], outputs=[reduced],\n name='test_reduce_log_sum_exp_do_not_keepdims_random')" + }, + { + "summary": "keepdims", + "code": "shape = [3, 2, 2]\naxes = [1]\nkeepdims = 1\nnode = onnx.helper.make_node(\n 'ReduceLogSumExp',\n inputs=['data'],\n outputs=['reduced'],\n axes=axes,\n keepdims=keepdims\n)\n\ndata = np.array(\n [[[5, 1], [20, 2]], [[30, 1], [40, 2]], [[55, 1], [60, 2]]],\n dtype=np.double)\nreduced = np.log(np.sum(np.exp(data),\n axis=tuple(axes),\n keepdims=keepdims == 1))\n# print(reduced)\n# [[[20., 2.31326175]]\n# [[40.00004578, 2.31326175]]\n# [[60.00671387, 2.31326175]]]\n\nexpect(node, inputs=[data], outputs=[reduced],\n name='test_reduce_log_sum_exp_keepdims_example')\n\nnp.random.seed(0)\ndata = np.random.uniform(-10, 10, shape).astype(np.double)\nreduced = np.log(np.sum(np.exp(data),\n axis=tuple(axes),\n keepdims=keepdims == 1))\n\nexpect(node, inputs=[data], outputs=[reduced],\n name='test_reduce_log_sum_exp_keepdims_random')" + }, + { + "summary": "negative_axes_keepdims", + "code": "shape = [3, 2, 2]\naxes = [-2]\nkeepdims = 1\nnode = onnx.helper.make_node(\n 'ReduceLogSumExp',\n inputs=['data'],\n outputs=['reduced'],\n axes=axes,\n keepdims=keepdims\n)\n\ndata = np.array(\n [[[5, 1], [20, 2]], [[30, 1], [40, 2]], [[55, 1], [60, 2]]],\n dtype=np.double)\nreduced = np.log(np.sum(np.exp(data),\n axis=tuple(axes),\n keepdims=keepdims == 1))\n# print(reduced)\n# [[[20., 2.31326175]]\n# [[40.00004578, 2.31326175]]\n# [[60.00671387, 2.31326175]]]\n\nexpect(node, inputs=[data], outputs=[reduced],\n name='test_reduce_log_sum_exp_negative_axes_keepdims_example')\n\nnp.random.seed(0)\ndata = np.random.uniform(-10, 10, shape).astype(np.double)\nreduced = np.log(np.sum(np.exp(data),\n axis=tuple(axes),\n keepdims=keepdims == 1))\n\nexpect(node, inputs=[data], outputs=[reduced],\n name='test_reduce_log_sum_exp_negative_axes_keepdims_random')" + } + ] + }, + { + "name": "ReduceLogSumExp", + "module": "ai.onnx", + "version": 13, + "support_level": "common", + "description": "Computes the log sum exponent of the input tensor's element along the provided axes. The resulted\ntensor has the same rank as the input if keepdims equal 1. If keepdims equal 0, then\nthe resulted tensor have the reduced dimension pruned.\n\nThe above behavior is similar to numpy, with the exception that numpy default keepdims to\nFalse instead of True.", + "attributes": [ + { + "name": "axes", + "type": "int64[]", + "required": false, + "description": "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)." + }, + { + "name": "keepdims", + "type": "int64", + "required": false, + "default": 1, + "description": "Keep the reduced dimension or not, default 1 mean keep reduced dimension." + } + ], + "inputs": [ + { + "name": "data", + "type": "T", + "description": "An input tensor." + } + ], + "min_input": 1, + "max_input": 1, + "outputs": [ + { + "name": "reduced", + "type": "T", + "description": "Reduced output tensor." + } + ], + "min_output": 1, + "max_output": 1, + "type_constraints": [ + { + "description": "Constrain input and output types to high-precision numeric tensors.", + "type_param_str": "T", + "allowed_type_strs": [ + "tensor(uint32)", + "tensor(uint64)", + "tensor(int32)", + "tensor(int64)", + "tensor(float16)", + "tensor(float)", + "tensor(double)", + "tensor(bfloat16)" + ] + } + ], + "examples": [ + { + "summary": "default_axes_keepdims", + "code": "shape = [3, 2, 2]\naxes = None\nkeepdims = 1\n\nnode = onnx.helper.make_node(\n 'ReduceLogSumExp',\n inputs=['data'],\n outputs=['reduced'],\n keepdims=keepdims\n)\n\ndata = np.array(\n [[[5, 1], [20, 2]], [[30, 1], [40, 2]], [[55, 1], [60, 2]]],\n dtype=np.double)\nreduced = np.log(np.sum(np.exp(data),\n axis=axes,\n keepdims=keepdims == 1))\n# print(reduced)\n# [[[60.00671387]]]\n\nexpect(node, inputs=[data], outputs=[reduced],\n name='test_reduce_log_sum_exp_default_axes_keepdims_example')\n\nnp.random.seed(0)\ndata = np.random.uniform(-10, 10, shape).astype(np.double)\nreduced = np.log(np.sum(np.exp(data),\n axis=axes,\n keepdims=keepdims == 1))\nexpect(node, inputs=[data], outputs=[reduced],\n name='test_reduce_log_sum_exp_default_axes_keepdims_random')" + }, + { + "summary": "do_not_keepdims", + "code": "shape = [3, 2, 2]\naxes = [1]\nkeepdims = 0\nnode = onnx.helper.make_node(\n 'ReduceLogSumExp',\n inputs=['data'],\n outputs=['reduced'],\n axes=axes,\n keepdims=keepdims\n)\n\ndata = np.array(\n [[[5, 1], [20, 2]], [[30, 1], [40, 2]], [[55, 1], [60, 2]]],\n dtype=np.double)\nreduced = np.log(np.sum(\n np.exp(data), axis=tuple(axes), keepdims=keepdims == 1))\n# print(reduced)\n#[[20., 2.31326175]\n# [40.00004578, 2.31326175]\n# [60.00671387, 2.31326175]]\n\nexpect(node, inputs=[data], outputs=[reduced],\n name='test_reduce_log_sum_exp_do_not_keepdims_example')\n\nnp.random.seed(0)\ndata = np.random.uniform(-10, 10, shape).astype(np.double)\nreduced = np.log(np.sum(\n np.exp(data), axis=tuple(axes), keepdims=keepdims == 1))\n\nexpect(node, inputs=[data], outputs=[reduced],\n name='test_reduce_log_sum_exp_do_not_keepdims_random')" + }, + { + "summary": "keepdims", + "code": "shape = [3, 2, 2]\naxes = [1]\nkeepdims = 1\nnode = onnx.helper.make_node(\n 'ReduceLogSumExp',\n inputs=['data'],\n outputs=['reduced'],\n axes=axes,\n keepdims=keepdims\n)\n\ndata = np.array(\n [[[5, 1], [20, 2]], [[30, 1], [40, 2]], [[55, 1], [60, 2]]],\n dtype=np.double)\nreduced = np.log(np.sum(np.exp(data),\n axis=tuple(axes),\n keepdims=keepdims == 1))\n# print(reduced)\n# [[[20., 2.31326175]]\n# [[40.00004578, 2.31326175]]\n# [[60.00671387, 2.31326175]]]\n\nexpect(node, inputs=[data], outputs=[reduced],\n name='test_reduce_log_sum_exp_keepdims_example')\n\nnp.random.seed(0)\ndata = np.random.uniform(-10, 10, shape).astype(np.double)\nreduced = np.log(np.sum(np.exp(data),\n axis=tuple(axes),\n keepdims=keepdims == 1))\n\nexpect(node, inputs=[data], outputs=[reduced],\n name='test_reduce_log_sum_exp_keepdims_random')" + }, + { + "summary": "negative_axes_keepdims", + "code": "shape = [3, 2, 2]\naxes = [-2]\nkeepdims = 1\nnode = onnx.helper.make_node(\n 'ReduceLogSumExp',\n inputs=['data'],\n outputs=['reduced'],\n axes=axes,\n keepdims=keepdims\n)\n\ndata = np.array(\n [[[5, 1], [20, 2]], [[30, 1], [40, 2]], [[55, 1], [60, 2]]],\n dtype=np.double)\nreduced = np.log(np.sum(np.exp(data),\n axis=tuple(axes),\n keepdims=keepdims == 1))\n# print(reduced)\n# [[[20., 2.31326175]]\n# [[40.00004578, 2.31326175]]\n# [[60.00671387, 2.31326175]]]\n\nexpect(node, inputs=[data], outputs=[reduced],\n name='test_reduce_log_sum_exp_negative_axes_keepdims_example')\n\nnp.random.seed(0)\ndata = np.random.uniform(-10, 10, shape).astype(np.double)\nreduced = np.log(np.sum(np.exp(data),\n axis=tuple(axes),\n keepdims=keepdims == 1))\n\nexpect(node, inputs=[data], outputs=[reduced],\n name='test_reduce_log_sum_exp_negative_axes_keepdims_random')" + } + ] + }, + { + "name": "ReduceMax", + "module": "ai.onnx", + "version": 1, + "support_level": "common", + "description": "Computes the max of the input tensor's element along the provided axes. The resulted\ntensor has the same rank as the input if keepdims equal 1. If keepdims equal 0, then\nthe resulted tensor have the reduced dimension pruned.\n\nThe above behavior is similar to numpy, with the exception that numpy default keepdims to\nFalse instead of True.", + "attributes": [ + { + "name": "axes", + "type": "int64[]", + "required": false, + "description": "A list of integers, along which to reduce. The default is to reduce over all the dimensions of the input tensor." + }, + { + "name": "keepdims", + "type": "int64", + "required": false, + "default": 1, + "description": "Keep the reduced dimension or not, default 1 mean keep reduced dimension." + } + ], + "inputs": [ + { + "name": "data", + "type": "T", + "description": "An input tensor." + } + ], + "min_input": 1, + "max_input": 1, + "outputs": [ + { + "name": "reduced", + "type": "T", + "description": "Reduced output tensor." + } + ], + "min_output": 1, + "max_output": 1, + "type_constraints": [ + { + "description": "Constrain input and output types to high-precision numeric tensors.", + "type_param_str": "T", + "allowed_type_strs": [ + "tensor(uint32)", + "tensor(uint64)", + "tensor(int32)", + "tensor(int64)", + "tensor(float16)", + "tensor(float)", + "tensor(double)" + ] + } + ], + "examples": [ + { + "summary": "default_axes_keepdims", + "code": "shape = [3, 2, 2]\naxes = None\nkeepdims = 1\nnode = onnx.helper.make_node(\n 'ReduceMax',\n inputs=['data'],\n outputs=['reduced'],\n keepdims=keepdims)\n\ndata = np.array([[[5, 1], [20, 2]], [[30, 1], [40, 2]], [[55, 1], [60, 2]]], dtype=np.float32)\nreduced = np.maximum.reduce(data, axis=axes, keepdims=keepdims == 1)\n#print(reduced)\n[[[60.]]]\n\nexpect(node, inputs=[data], outputs=[reduced], name='test_reduce_max_default_axes_keepdim_example')\n\nnp.random.seed(0)\ndata = np.random.uniform(-10, 10, shape).astype(np.float32)\nreduced = np.maximum.reduce(data, axis=axes, keepdims=keepdims == 1)\n\nexpect(node, inputs=[data], outputs=[reduced], name='test_reduce_max_default_axes_keepdims_random')" + }, + { + "summary": "do_not_keepdims", + "code": "shape = [3, 2, 2]\naxes = [1]\nkeepdims = 0\n\nnode = onnx.helper.make_node(\n 'ReduceMax',\n inputs=['data'],\n outputs=['reduced'],\n axes=axes,\n keepdims=keepdims)\n\ndata = np.array([[[5, 1], [20, 2]], [[30, 1], [40, 2]], [[55, 1], [60, 2]]], dtype=np.float32)\nreduced = np.maximum.reduce(data, axis=tuple(axes), keepdims=keepdims == 1)\n#print(reduced)\n#[[20., 2.]\n# [40., 2.]\n# [60., 2.]]\n\nexpect(node, inputs=[data], outputs=[reduced], name='test_reduce_max_do_not_keepdims_example')\n\nnp.random.seed(0)\ndata = np.random.uniform(-10, 10, shape).astype(np.float32)\nreduced = np.maximum.reduce(data, axis=tuple(axes), keepdims=keepdims == 1)\n\nexpect(node, inputs=[data], outputs=[reduced], name='test_reduce_max_do_not_keepdims_random')" + }, + { + "summary": "keepdims", + "code": "shape = [3, 2, 2]\naxes = [1]\nkeepdims = 1\n\nnode = onnx.helper.make_node(\n 'ReduceMax',\n inputs=['data'],\n outputs=['reduced'],\n axes=axes,\n keepdims=keepdims)\n\ndata = np.array([[[5, 1], [20, 2]], [[30, 1], [40, 2]], [[55, 1], [60, 2]]], dtype=np.float32)\nreduced = np.maximum.reduce(data, axis=tuple(axes), keepdims=keepdims == 1)\n#print(reduced)\n#[[[20., 2.]]\n# [[40., 2.]]\n# [[60., 2.]]]\n\nexpect(node, inputs=[data], outputs=[reduced], name='test_reduce_max_keepdims_example')\n\nnp.random.seed(0)\ndata = np.random.uniform(-10, 10, shape).astype(np.float32)\nreduced = np.maximum.reduce(data, axis=tuple(axes), keepdims=keepdims == 1)\n\nexpect(node, inputs=[data], outputs=[reduced], name='test_reduce_max_keepdims_random')" + }, + { + "summary": "negative_axes_keepdims", + "code": "shape = [3, 2, 2]\naxes = [-2]\nkeepdims = 1\n\nnode = onnx.helper.make_node(\n 'ReduceMax',\n inputs=['data'],\n outputs=['reduced'],\n axes=axes,\n keepdims=keepdims)\n\ndata = np.array([[[5, 1], [20, 2]], [[30, 1], [40, 2]], [[55, 1], [60, 2]]], dtype=np.float32)\nreduced = np.maximum.reduce(data, axis=tuple(axes), keepdims=keepdims == 1)\n# print(reduced)\n#[[[20., 2.]]\n# [[40., 2.]]\n# [[60., 2.]]]\n\nexpect(node, inputs=[data], outputs=[reduced], name='test_reduce_max_negative_axes_keepdims_example')\n\nnp.random.seed(0)\ndata = np.random.uniform(-10, 10, shape).astype(np.float32)\nreduced = np.maximum.reduce(data, axis=tuple(axes), keepdims=keepdims == 1)\n\nexpect(node, inputs=[data], outputs=[reduced], name='test_reduce_max_negative_axes_keepdims_random')" + } + ] + }, + { + "name": "ReduceMax", + "module": "ai.onnx", + "version": 11, + "support_level": "common", + "description": "Computes the max of the input tensor's element along the provided axes. The resulted\ntensor has the same rank as the input if keepdims equal 1. If keepdims equal 0, then\nthe resulted tensor have the reduced dimension pruned.\n\nThe above behavior is similar to numpy, with the exception that numpy default keepdims to\nFalse instead of True.", + "attributes": [ + { + "name": "axes", + "type": "int64[]", + "required": false, + "description": "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)." + }, + { + "name": "keepdims", + "type": "int64", + "required": false, + "default": 1, + "description": "Keep the reduced dimension or not, default 1 mean keep reduced dimension." + } + ], + "inputs": [ + { + "name": "data", + "type": "T", + "description": "An input tensor." + } + ], + "min_input": 1, + "max_input": 1, + "outputs": [ + { + "name": "reduced", + "type": "T", + "description": "Reduced output tensor." + } + ], + "min_output": 1, + "max_output": 1, + "type_constraints": [ + { + "description": "Constrain input and output types to high-precision numeric tensors.", + "type_param_str": "T", + "allowed_type_strs": [ + "tensor(uint32)", + "tensor(uint64)", + "tensor(int32)", + "tensor(int64)", + "tensor(float16)", + "tensor(float)", + "tensor(double)" + ] + } + ], + "examples": [ + { + "summary": "default_axes_keepdims", + "code": "shape = [3, 2, 2]\naxes = None\nkeepdims = 1\nnode = onnx.helper.make_node(\n 'ReduceMax',\n inputs=['data'],\n outputs=['reduced'],\n keepdims=keepdims)\n\ndata = np.array([[[5, 1], [20, 2]], [[30, 1], [40, 2]], [[55, 1], [60, 2]]], dtype=np.float32)\nreduced = np.maximum.reduce(data, axis=axes, keepdims=keepdims == 1)\n#print(reduced)\n[[[60.]]]\n\nexpect(node, inputs=[data], outputs=[reduced], name='test_reduce_max_default_axes_keepdim_example')\n\nnp.random.seed(0)\ndata = np.random.uniform(-10, 10, shape).astype(np.float32)\nreduced = np.maximum.reduce(data, axis=axes, keepdims=keepdims == 1)\n\nexpect(node, inputs=[data], outputs=[reduced], name='test_reduce_max_default_axes_keepdims_random')" + }, + { + "summary": "do_not_keepdims", + "code": "shape = [3, 2, 2]\naxes = [1]\nkeepdims = 0\n\nnode = onnx.helper.make_node(\n 'ReduceMax',\n inputs=['data'],\n outputs=['reduced'],\n axes=axes,\n keepdims=keepdims)\n\ndata = np.array([[[5, 1], [20, 2]], [[30, 1], [40, 2]], [[55, 1], [60, 2]]], dtype=np.float32)\nreduced = np.maximum.reduce(data, axis=tuple(axes), keepdims=keepdims == 1)\n#print(reduced)\n#[[20., 2.]\n# [40., 2.]\n# [60., 2.]]\n\nexpect(node, inputs=[data], outputs=[reduced], name='test_reduce_max_do_not_keepdims_example')\n\nnp.random.seed(0)\ndata = np.random.uniform(-10, 10, shape).astype(np.float32)\nreduced = np.maximum.reduce(data, axis=tuple(axes), keepdims=keepdims == 1)\n\nexpect(node, inputs=[data], outputs=[reduced], name='test_reduce_max_do_not_keepdims_random')" + }, + { + "summary": "keepdims", + "code": "shape = [3, 2, 2]\naxes = [1]\nkeepdims = 1\n\nnode = onnx.helper.make_node(\n 'ReduceMax',\n inputs=['data'],\n outputs=['reduced'],\n axes=axes,\n keepdims=keepdims)\n\ndata = np.array([[[5, 1], [20, 2]], [[30, 1], [40, 2]], [[55, 1], [60, 2]]], dtype=np.float32)\nreduced = np.maximum.reduce(data, axis=tuple(axes), keepdims=keepdims == 1)\n#print(reduced)\n#[[[20., 2.]]\n# [[40., 2.]]\n# [[60., 2.]]]\n\nexpect(node, inputs=[data], outputs=[reduced], name='test_reduce_max_keepdims_example')\n\nnp.random.seed(0)\ndata = np.random.uniform(-10, 10, shape).astype(np.float32)\nreduced = np.maximum.reduce(data, axis=tuple(axes), keepdims=keepdims == 1)\n\nexpect(node, inputs=[data], outputs=[reduced], name='test_reduce_max_keepdims_random')" + }, + { + "summary": "negative_axes_keepdims", + "code": "shape = [3, 2, 2]\naxes = [-2]\nkeepdims = 1\n\nnode = onnx.helper.make_node(\n 'ReduceMax',\n inputs=['data'],\n outputs=['reduced'],\n axes=axes,\n keepdims=keepdims)\n\ndata = np.array([[[5, 1], [20, 2]], [[30, 1], [40, 2]], [[55, 1], [60, 2]]], dtype=np.float32)\nreduced = np.maximum.reduce(data, axis=tuple(axes), keepdims=keepdims == 1)\n# print(reduced)\n#[[[20., 2.]]\n# [[40., 2.]]\n# [[60., 2.]]]\n\nexpect(node, inputs=[data], outputs=[reduced], name='test_reduce_max_negative_axes_keepdims_example')\n\nnp.random.seed(0)\ndata = np.random.uniform(-10, 10, shape).astype(np.float32)\nreduced = np.maximum.reduce(data, axis=tuple(axes), keepdims=keepdims == 1)\n\nexpect(node, inputs=[data], outputs=[reduced], name='test_reduce_max_negative_axes_keepdims_random')" + } + ] + }, + { + "name": "ReduceMax", + "module": "ai.onnx", + "version": 12, + "support_level": "common", + "description": "Computes the max of the input tensor's element along the provided axes. The resulted\ntensor has the same rank as the input if keepdims equal 1. If keepdims equal 0, then\nthe resulted tensor have the reduced dimension pruned.\n\nThe above behavior is similar to numpy, with the exception that numpy default keepdims to\nFalse instead of True.", + "attributes": [ + { + "name": "axes", + "type": "int64[]", + "required": false, + "description": "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)." + }, + { + "name": "keepdims", + "type": "int64", + "required": false, + "default": 1, + "description": "Keep the reduced dimension or not, default 1 mean keep reduced dimension." + } + ], + "inputs": [ + { + "name": "data", + "type": "T", + "description": "An input tensor." + } + ], + "min_input": 1, + "max_input": 1, + "outputs": [ + { + "name": "reduced", + "type": "T", + "description": "Reduced output tensor." + } + ], + "min_output": 1, + "max_output": 1, + "type_constraints": [ + { + "description": "Constrain input and output types to high-precision and 8 bit numeric tensors.", + "type_param_str": "T", + "allowed_type_strs": [ + "tensor(uint32)", + "tensor(uint64)", + "tensor(int32)", + "tensor(int64)", + "tensor(float16)", + "tensor(float)", + "tensor(double)", + "tensor(uint8)", + "tensor(int8)" + ] + } + ], + "examples": [ + { + "summary": "default_axes_keepdims", + "code": "shape = [3, 2, 2]\naxes = None\nkeepdims = 1\nnode = onnx.helper.make_node(\n 'ReduceMax',\n inputs=['data'],\n outputs=['reduced'],\n keepdims=keepdims)\n\ndata = np.array([[[5, 1], [20, 2]], [[30, 1], [40, 2]], [[55, 1], [60, 2]]], dtype=np.float32)\nreduced = np.maximum.reduce(data, axis=axes, keepdims=keepdims == 1)\n#print(reduced)\n[[[60.]]]\n\nexpect(node, inputs=[data], outputs=[reduced], name='test_reduce_max_default_axes_keepdim_example')\n\nnp.random.seed(0)\ndata = np.random.uniform(-10, 10, shape).astype(np.float32)\nreduced = np.maximum.reduce(data, axis=axes, keepdims=keepdims == 1)\n\nexpect(node, inputs=[data], outputs=[reduced], name='test_reduce_max_default_axes_keepdims_random')" + }, + { + "summary": "do_not_keepdims", + "code": "shape = [3, 2, 2]\naxes = [1]\nkeepdims = 0\n\nnode = onnx.helper.make_node(\n 'ReduceMax',\n inputs=['data'],\n outputs=['reduced'],\n axes=axes,\n keepdims=keepdims)\n\ndata = np.array([[[5, 1], [20, 2]], [[30, 1], [40, 2]], [[55, 1], [60, 2]]], dtype=np.float32)\nreduced = np.maximum.reduce(data, axis=tuple(axes), keepdims=keepdims == 1)\n#print(reduced)\n#[[20., 2.]\n# [40., 2.]\n# [60., 2.]]\n\nexpect(node, inputs=[data], outputs=[reduced], name='test_reduce_max_do_not_keepdims_example')\n\nnp.random.seed(0)\ndata = np.random.uniform(-10, 10, shape).astype(np.float32)\nreduced = np.maximum.reduce(data, axis=tuple(axes), keepdims=keepdims == 1)\n\nexpect(node, inputs=[data], outputs=[reduced], name='test_reduce_max_do_not_keepdims_random')" + }, + { + "summary": "keepdims", + "code": "shape = [3, 2, 2]\naxes = [1]\nkeepdims = 1\n\nnode = onnx.helper.make_node(\n 'ReduceMax',\n inputs=['data'],\n outputs=['reduced'],\n axes=axes,\n keepdims=keepdims)\n\ndata = np.array([[[5, 1], [20, 2]], [[30, 1], [40, 2]], [[55, 1], [60, 2]]], dtype=np.float32)\nreduced = np.maximum.reduce(data, axis=tuple(axes), keepdims=keepdims == 1)\n#print(reduced)\n#[[[20., 2.]]\n# [[40., 2.]]\n# [[60., 2.]]]\n\nexpect(node, inputs=[data], outputs=[reduced], name='test_reduce_max_keepdims_example')\n\nnp.random.seed(0)\ndata = np.random.uniform(-10, 10, shape).astype(np.float32)\nreduced = np.maximum.reduce(data, axis=tuple(axes), keepdims=keepdims == 1)\n\nexpect(node, inputs=[data], outputs=[reduced], name='test_reduce_max_keepdims_random')" + }, + { + "summary": "negative_axes_keepdims", + "code": "shape = [3, 2, 2]\naxes = [-2]\nkeepdims = 1\n\nnode = onnx.helper.make_node(\n 'ReduceMax',\n inputs=['data'],\n outputs=['reduced'],\n axes=axes,\n keepdims=keepdims)\n\ndata = np.array([[[5, 1], [20, 2]], [[30, 1], [40, 2]], [[55, 1], [60, 2]]], dtype=np.float32)\nreduced = np.maximum.reduce(data, axis=tuple(axes), keepdims=keepdims == 1)\n# print(reduced)\n#[[[20., 2.]]\n# [[40., 2.]]\n# [[60., 2.]]]\n\nexpect(node, inputs=[data], outputs=[reduced], name='test_reduce_max_negative_axes_keepdims_example')\n\nnp.random.seed(0)\ndata = np.random.uniform(-10, 10, shape).astype(np.float32)\nreduced = np.maximum.reduce(data, axis=tuple(axes), keepdims=keepdims == 1)\n\nexpect(node, inputs=[data], outputs=[reduced], name='test_reduce_max_negative_axes_keepdims_random')" + } + ] + }, + { + "name": "ReduceMax", + "module": "ai.onnx", + "version": 13, + "support_level": "common", + "description": "Computes the max of the input tensor's element along the provided axes. The resulted\ntensor has the same rank as the input if keepdims equal 1. If keepdims equal 0, then\nthe resulted tensor have the reduced dimension pruned.\n\nThe above behavior is similar to numpy, with the exception that numpy default keepdims to\nFalse instead of True.", + "attributes": [ + { + "name": "axes", + "type": "int64[]", + "required": false, + "description": "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)." + }, + { + "name": "keepdims", + "type": "int64", + "required": false, + "default": 1, + "description": "Keep the reduced dimension or not, default 1 mean keep reduced dimension." + } + ], + "inputs": [ + { + "name": "data", + "type": "T", + "description": "An input tensor." + } + ], + "min_input": 1, + "max_input": 1, + "outputs": [ + { + "name": "reduced", + "type": "T", + "description": "Reduced output tensor." + } + ], + "min_output": 1, + "max_output": 1, + "type_constraints": [ + { + "description": "Constrain input and output types to high-precision and 8 bit numeric tensors.", + "type_param_str": "T", + "allowed_type_strs": [ + "tensor(uint32)", + "tensor(uint64)", + "tensor(int32)", + "tensor(int64)", + "tensor(float16)", + "tensor(float)", + "tensor(double)", + "tensor(bfloat16)", + "tensor(uint8)", + "tensor(int8)" + ] + } + ], + "examples": [ + { + "summary": "default_axes_keepdims", + "code": "shape = [3, 2, 2]\naxes = None\nkeepdims = 1\nnode = onnx.helper.make_node(\n 'ReduceMax',\n inputs=['data'],\n outputs=['reduced'],\n keepdims=keepdims)\n\ndata = np.array([[[5, 1], [20, 2]], [[30, 1], [40, 2]], [[55, 1], [60, 2]]], dtype=np.float32)\nreduced = np.maximum.reduce(data, axis=axes, keepdims=keepdims == 1)\n#print(reduced)\n[[[60.]]]\n\nexpect(node, inputs=[data], outputs=[reduced], name='test_reduce_max_default_axes_keepdim_example')\n\nnp.random.seed(0)\ndata = np.random.uniform(-10, 10, shape).astype(np.float32)\nreduced = np.maximum.reduce(data, axis=axes, keepdims=keepdims == 1)\n\nexpect(node, inputs=[data], outputs=[reduced], name='test_reduce_max_default_axes_keepdims_random')" + }, + { + "summary": "do_not_keepdims", + "code": "shape = [3, 2, 2]\naxes = [1]\nkeepdims = 0\n\nnode = onnx.helper.make_node(\n 'ReduceMax',\n inputs=['data'],\n outputs=['reduced'],\n axes=axes,\n keepdims=keepdims)\n\ndata = np.array([[[5, 1], [20, 2]], [[30, 1], [40, 2]], [[55, 1], [60, 2]]], dtype=np.float32)\nreduced = np.maximum.reduce(data, axis=tuple(axes), keepdims=keepdims == 1)\n#print(reduced)\n#[[20., 2.]\n# [40., 2.]\n# [60., 2.]]\n\nexpect(node, inputs=[data], outputs=[reduced], name='test_reduce_max_do_not_keepdims_example')\n\nnp.random.seed(0)\ndata = np.random.uniform(-10, 10, shape).astype(np.float32)\nreduced = np.maximum.reduce(data, axis=tuple(axes), keepdims=keepdims == 1)\n\nexpect(node, inputs=[data], outputs=[reduced], name='test_reduce_max_do_not_keepdims_random')" + }, + { + "summary": "keepdims", + "code": "shape = [3, 2, 2]\naxes = [1]\nkeepdims = 1\n\nnode = onnx.helper.make_node(\n 'ReduceMax',\n inputs=['data'],\n outputs=['reduced'],\n axes=axes,\n keepdims=keepdims)\n\ndata = np.array([[[5, 1], [20, 2]], [[30, 1], [40, 2]], [[55, 1], [60, 2]]], dtype=np.float32)\nreduced = np.maximum.reduce(data, axis=tuple(axes), keepdims=keepdims == 1)\n#print(reduced)\n#[[[20., 2.]]\n# [[40., 2.]]\n# [[60., 2.]]]\n\nexpect(node, inputs=[data], outputs=[reduced], name='test_reduce_max_keepdims_example')\n\nnp.random.seed(0)\ndata = np.random.uniform(-10, 10, shape).astype(np.float32)\nreduced = np.maximum.reduce(data, axis=tuple(axes), keepdims=keepdims == 1)\n\nexpect(node, inputs=[data], outputs=[reduced], name='test_reduce_max_keepdims_random')" + }, + { + "summary": "negative_axes_keepdims", + "code": "shape = [3, 2, 2]\naxes = [-2]\nkeepdims = 1\n\nnode = onnx.helper.make_node(\n 'ReduceMax',\n inputs=['data'],\n outputs=['reduced'],\n axes=axes,\n keepdims=keepdims)\n\ndata = np.array([[[5, 1], [20, 2]], [[30, 1], [40, 2]], [[55, 1], [60, 2]]], dtype=np.float32)\nreduced = np.maximum.reduce(data, axis=tuple(axes), keepdims=keepdims == 1)\n# print(reduced)\n#[[[20., 2.]]\n# [[40., 2.]]\n# [[60., 2.]]]\n\nexpect(node, inputs=[data], outputs=[reduced], name='test_reduce_max_negative_axes_keepdims_example')\n\nnp.random.seed(0)\ndata = np.random.uniform(-10, 10, shape).astype(np.float32)\nreduced = np.maximum.reduce(data, axis=tuple(axes), keepdims=keepdims == 1)\n\nexpect(node, inputs=[data], outputs=[reduced], name='test_reduce_max_negative_axes_keepdims_random')" + } + ] + }, + { + "name": "ReduceMean", + "module": "ai.onnx", + "version": 1, + "support_level": "common", + "description": "Computes the mean of the input tensor's element along the provided axes. The resulted\ntensor has the same rank as the input if keepdims equal 1. If keepdims equal 0, then\nthe resulted tensor have the reduced dimension pruned.\n\nThe above behavior is similar to numpy, with the exception that numpy default keepdims to\nFalse instead of True.", + "attributes": [ + { + "name": "axes", + "type": "int64[]", + "required": false, + "description": "A list of integers, along which to reduce. The default is to reduce over all the dimensions of the input tensor." + }, + { + "name": "keepdims", + "type": "int64", + "required": false, + "default": 1, + "description": "Keep the reduced dimension or not, default 1 mean keep reduced dimension." + } + ], + "inputs": [ + { + "name": "data", + "type": "T", + "description": "An input tensor." + } + ], + "min_input": 1, + "max_input": 1, + "outputs": [ + { + "name": "reduced", + "type": "T", + "description": "Reduced output tensor." + } + ], + "min_output": 1, + "max_output": 1, + "type_constraints": [ + { + "description": "Constrain input and output types to high-precision numeric tensors.", + "type_param_str": "T", + "allowed_type_strs": [ + "tensor(uint32)", + "tensor(uint64)", + "tensor(int32)", + "tensor(int64)", + "tensor(float16)", + "tensor(float)", + "tensor(double)" + ] + } + ], + "examples": [ + { + "summary": "default_axes_keepdims", + "code": "shape = [3, 2, 2]\naxes = None\nkeepdims = 1\n\nnode = onnx.helper.make_node(\n 'ReduceMean',\n inputs=['data'],\n outputs=['reduced'],\n keepdims=keepdims)\n\ndata = np.array([[[5, 1], [20, 2]], [[30, 1], [40, 2]], [[55, 1], [60, 2]]], dtype=np.float32)\nreduced = np.mean(data, axis=axes, keepdims=keepdims == 1)\n#print(reduced)\n#[[[18.25]]]\n\nexpect(node, inputs=[data], outputs=[reduced], name='test_reduce_mean_default_axes_keepdims_example')\n\nnp.random.seed(0)\ndata = np.random.uniform(-10, 10, shape).astype(np.float32)\nreduced = np.mean(data, axis=axes, keepdims=keepdims == 1)\n\nexpect(node, inputs=[data], outputs=[reduced], name='test_reduce_mean_default_axes_keepdims_random')" + }, + { + "summary": "do_not_keepdims", + "code": "shape = [3, 2, 2]\naxes = [1]\nkeepdims = 0\n\nnode = onnx.helper.make_node(\n 'ReduceMean',\n inputs=['data'],\n outputs=['reduced'],\n axes=axes,\n keepdims=keepdims)\n\ndata = np.array([[[5, 1], [20, 2]], [[30, 1], [40, 2]], [[55, 1], [60, 2]]], dtype=np.float32)\nreduced = np.mean(data, axis=tuple(axes), keepdims=keepdims == 1)\n#print(reduced)\n#[[12.5, 1.5]\n# [35., 1.5]\n# [57.5, 1.5]]\n\nexpect(node, inputs=[data], outputs=[reduced], name='test_reduce_mean_do_not_keepdims_example')\n\nnp.random.seed(0)\ndata = np.random.uniform(-10, 10, shape).astype(np.float32)\nreduced = np.mean(data, axis=tuple(axes), keepdims=keepdims == 1)\n\nexpect(node, inputs=[data], outputs=[reduced], name='test_reduce_mean_do_not_keepdims_random')" + }, + { + "summary": "keepdims", + "code": "shape = [3, 2, 2]\naxes = [1]\nkeepdims = 1\n\nnode = onnx.helper.make_node(\n 'ReduceMean',\n inputs=['data'],\n outputs=['reduced'],\n axes=axes,\n keepdims=keepdims)\n\ndata = np.array([[[5, 1], [20, 2]], [[30, 1], [40, 2]], [[55, 1], [60, 2]]], dtype=np.float32)\nreduced = np.mean(data, axis=tuple(axes), keepdims=keepdims == 1)\n#print(reduced)\n#[[[12.5, 1.5]]\n# [[35., 1.5]]\n# [[57.5, 1.5]]]\n\nexpect(node, inputs=[data], outputs=[reduced], name='test_reduce_mean_keepdims_example')\n\nnp.random.seed(0)\ndata = np.random.uniform(-10, 10, shape).astype(np.float32)\nreduced = np.mean(data, axis=tuple(axes), keepdims=keepdims == 1)\n\nexpect(node, inputs=[data], outputs=[reduced], name='test_reduce_mean_keepdims_random')" + }, + { + "summary": "negative_axes_keepdims", + "code": "shape = [3, 2, 2]\naxes = [-2]\nkeepdims = 1\n\nnode = onnx.helper.make_node(\n 'ReduceMean',\n inputs=['data'],\n outputs=['reduced'],\n axes=axes,\n keepdims=keepdims)\n\ndata = np.array([[[5, 1], [20, 2]], [[30, 1], [40, 2]], [[55, 1], [60, 2]]], dtype=np.float32)\nreduced = np.mean(data, axis=tuple(axes), keepdims=keepdims == 1)\n# print(reduced)\n# [[[12.5, 1.5]]\n# [[35., 1.5]]\n# [[57.5, 1.5]]]\n\nexpect(node, inputs=[data], outputs=[reduced], name='test_reduce_mean_negative_axes_keepdims_example')\n\nnp.random.seed(0)\ndata = np.random.uniform(-10, 10, shape).astype(np.float32)\nreduced = np.mean(data, axis=tuple(axes), keepdims=keepdims == 1)\n\nexpect(node, inputs=[data], outputs=[reduced], name='test_reduce_mean_negative_axes_keepdims_random')" + } + ] + }, + { + "name": "ReduceMean", + "module": "ai.onnx", + "version": 11, + "support_level": "common", + "description": "Computes the mean of the input tensor's element along the provided axes. The resulted\ntensor has the same rank as the input if keepdims equal 1. If keepdims equal 0, then\nthe resulted tensor have the reduced dimension pruned.\n\nThe above behavior is similar to numpy, with the exception that numpy default keepdims to\nFalse instead of True.", + "attributes": [ + { + "name": "axes", + "type": "int64[]", + "required": false, + "description": "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)." + }, + { + "name": "keepdims", + "type": "int64", + "required": false, + "default": 1, + "description": "Keep the reduced dimension or not, default 1 mean keep reduced dimension." + } + ], + "inputs": [ + { + "name": "data", + "type": "T", + "description": "An input tensor." + } + ], + "min_input": 1, + "max_input": 1, + "outputs": [ + { + "name": "reduced", + "type": "T", + "description": "Reduced output tensor." + } + ], + "min_output": 1, + "max_output": 1, + "type_constraints": [ + { + "description": "Constrain input and output types to high-precision numeric tensors.", + "type_param_str": "T", + "allowed_type_strs": [ + "tensor(uint32)", + "tensor(uint64)", + "tensor(int32)", + "tensor(int64)", + "tensor(float16)", + "tensor(float)", + "tensor(double)" + ] + } + ], + "examples": [ + { + "summary": "default_axes_keepdims", + "code": "shape = [3, 2, 2]\naxes = None\nkeepdims = 1\n\nnode = onnx.helper.make_node(\n 'ReduceMean',\n inputs=['data'],\n outputs=['reduced'],\n keepdims=keepdims)\n\ndata = np.array([[[5, 1], [20, 2]], [[30, 1], [40, 2]], [[55, 1], [60, 2]]], dtype=np.float32)\nreduced = np.mean(data, axis=axes, keepdims=keepdims == 1)\n#print(reduced)\n#[[[18.25]]]\n\nexpect(node, inputs=[data], outputs=[reduced], name='test_reduce_mean_default_axes_keepdims_example')\n\nnp.random.seed(0)\ndata = np.random.uniform(-10, 10, shape).astype(np.float32)\nreduced = np.mean(data, axis=axes, keepdims=keepdims == 1)\n\nexpect(node, inputs=[data], outputs=[reduced], name='test_reduce_mean_default_axes_keepdims_random')" + }, + { + "summary": "do_not_keepdims", + "code": "shape = [3, 2, 2]\naxes = [1]\nkeepdims = 0\n\nnode = onnx.helper.make_node(\n 'ReduceMean',\n inputs=['data'],\n outputs=['reduced'],\n axes=axes,\n keepdims=keepdims)\n\ndata = np.array([[[5, 1], [20, 2]], [[30, 1], [40, 2]], [[55, 1], [60, 2]]], dtype=np.float32)\nreduced = np.mean(data, axis=tuple(axes), keepdims=keepdims == 1)\n#print(reduced)\n#[[12.5, 1.5]\n# [35., 1.5]\n# [57.5, 1.5]]\n\nexpect(node, inputs=[data], outputs=[reduced], name='test_reduce_mean_do_not_keepdims_example')\n\nnp.random.seed(0)\ndata = np.random.uniform(-10, 10, shape).astype(np.float32)\nreduced = np.mean(data, axis=tuple(axes), keepdims=keepdims == 1)\n\nexpect(node, inputs=[data], outputs=[reduced], name='test_reduce_mean_do_not_keepdims_random')" + }, + { + "summary": "keepdims", + "code": "shape = [3, 2, 2]\naxes = [1]\nkeepdims = 1\n\nnode = onnx.helper.make_node(\n 'ReduceMean',\n inputs=['data'],\n outputs=['reduced'],\n axes=axes,\n keepdims=keepdims)\n\ndata = np.array([[[5, 1], [20, 2]], [[30, 1], [40, 2]], [[55, 1], [60, 2]]], dtype=np.float32)\nreduced = np.mean(data, axis=tuple(axes), keepdims=keepdims == 1)\n#print(reduced)\n#[[[12.5, 1.5]]\n# [[35., 1.5]]\n# [[57.5, 1.5]]]\n\nexpect(node, inputs=[data], outputs=[reduced], name='test_reduce_mean_keepdims_example')\n\nnp.random.seed(0)\ndata = np.random.uniform(-10, 10, shape).astype(np.float32)\nreduced = np.mean(data, axis=tuple(axes), keepdims=keepdims == 1)\n\nexpect(node, inputs=[data], outputs=[reduced], name='test_reduce_mean_keepdims_random')" + }, + { + "summary": "negative_axes_keepdims", + "code": "shape = [3, 2, 2]\naxes = [-2]\nkeepdims = 1\n\nnode = onnx.helper.make_node(\n 'ReduceMean',\n inputs=['data'],\n outputs=['reduced'],\n axes=axes,\n keepdims=keepdims)\n\ndata = np.array([[[5, 1], [20, 2]], [[30, 1], [40, 2]], [[55, 1], [60, 2]]], dtype=np.float32)\nreduced = np.mean(data, axis=tuple(axes), keepdims=keepdims == 1)\n# print(reduced)\n# [[[12.5, 1.5]]\n# [[35., 1.5]]\n# [[57.5, 1.5]]]\n\nexpect(node, inputs=[data], outputs=[reduced], name='test_reduce_mean_negative_axes_keepdims_example')\n\nnp.random.seed(0)\ndata = np.random.uniform(-10, 10, shape).astype(np.float32)\nreduced = np.mean(data, axis=tuple(axes), keepdims=keepdims == 1)\n\nexpect(node, inputs=[data], outputs=[reduced], name='test_reduce_mean_negative_axes_keepdims_random')" + } + ] + }, + { + "name": "ReduceMean", + "module": "ai.onnx", + "version": 13, + "support_level": "common", + "description": "Computes the mean of the input tensor's element along the provided axes. The resulted\ntensor has the same rank as the input if keepdims equal 1. If keepdims equal 0, then\nthe resulted tensor have the reduced dimension pruned.\n\nThe above behavior is similar to numpy, with the exception that numpy default keepdims to\nFalse instead of True.", + "attributes": [ + { + "name": "axes", + "type": "int64[]", + "required": false, + "description": "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)." + }, + { + "name": "keepdims", + "type": "int64", + "required": false, + "default": 1, + "description": "Keep the reduced dimension or not, default 1 mean keep reduced dimension." + } + ], + "inputs": [ + { + "name": "data", + "type": "T", + "description": "An input tensor." + } + ], + "min_input": 1, + "max_input": 1, + "outputs": [ + { + "name": "reduced", + "type": "T", + "description": "Reduced output tensor." + } + ], + "min_output": 1, + "max_output": 1, + "type_constraints": [ + { + "description": "Constrain input and output types to high-precision numeric tensors.", + "type_param_str": "T", + "allowed_type_strs": [ + "tensor(uint32)", + "tensor(uint64)", + "tensor(int32)", + "tensor(int64)", + "tensor(float16)", + "tensor(float)", + "tensor(double)", + "tensor(bfloat16)" + ] + } + ], + "examples": [ + { + "summary": "default_axes_keepdims", + "code": "shape = [3, 2, 2]\naxes = None\nkeepdims = 1\n\nnode = onnx.helper.make_node(\n 'ReduceMean',\n inputs=['data'],\n outputs=['reduced'],\n keepdims=keepdims)\n\ndata = np.array([[[5, 1], [20, 2]], [[30, 1], [40, 2]], [[55, 1], [60, 2]]], dtype=np.float32)\nreduced = np.mean(data, axis=axes, keepdims=keepdims == 1)\n#print(reduced)\n#[[[18.25]]]\n\nexpect(node, inputs=[data], outputs=[reduced], name='test_reduce_mean_default_axes_keepdims_example')\n\nnp.random.seed(0)\ndata = np.random.uniform(-10, 10, shape).astype(np.float32)\nreduced = np.mean(data, axis=axes, keepdims=keepdims == 1)\n\nexpect(node, inputs=[data], outputs=[reduced], name='test_reduce_mean_default_axes_keepdims_random')" + }, + { + "summary": "do_not_keepdims", + "code": "shape = [3, 2, 2]\naxes = [1]\nkeepdims = 0\n\nnode = onnx.helper.make_node(\n 'ReduceMean',\n inputs=['data'],\n outputs=['reduced'],\n axes=axes,\n keepdims=keepdims)\n\ndata = np.array([[[5, 1], [20, 2]], [[30, 1], [40, 2]], [[55, 1], [60, 2]]], dtype=np.float32)\nreduced = np.mean(data, axis=tuple(axes), keepdims=keepdims == 1)\n#print(reduced)\n#[[12.5, 1.5]\n# [35., 1.5]\n# [57.5, 1.5]]\n\nexpect(node, inputs=[data], outputs=[reduced], name='test_reduce_mean_do_not_keepdims_example')\n\nnp.random.seed(0)\ndata = np.random.uniform(-10, 10, shape).astype(np.float32)\nreduced = np.mean(data, axis=tuple(axes), keepdims=keepdims == 1)\n\nexpect(node, inputs=[data], outputs=[reduced], name='test_reduce_mean_do_not_keepdims_random')" + }, + { + "summary": "keepdims", + "code": "shape = [3, 2, 2]\naxes = [1]\nkeepdims = 1\n\nnode = onnx.helper.make_node(\n 'ReduceMean',\n inputs=['data'],\n outputs=['reduced'],\n axes=axes,\n keepdims=keepdims)\n\ndata = np.array([[[5, 1], [20, 2]], [[30, 1], [40, 2]], [[55, 1], [60, 2]]], dtype=np.float32)\nreduced = np.mean(data, axis=tuple(axes), keepdims=keepdims == 1)\n#print(reduced)\n#[[[12.5, 1.5]]\n# [[35., 1.5]]\n# [[57.5, 1.5]]]\n\nexpect(node, inputs=[data], outputs=[reduced], name='test_reduce_mean_keepdims_example')\n\nnp.random.seed(0)\ndata = np.random.uniform(-10, 10, shape).astype(np.float32)\nreduced = np.mean(data, axis=tuple(axes), keepdims=keepdims == 1)\n\nexpect(node, inputs=[data], outputs=[reduced], name='test_reduce_mean_keepdims_random')" + }, + { + "summary": "negative_axes_keepdims", + "code": "shape = [3, 2, 2]\naxes = [-2]\nkeepdims = 1\n\nnode = onnx.helper.make_node(\n 'ReduceMean',\n inputs=['data'],\n outputs=['reduced'],\n axes=axes,\n keepdims=keepdims)\n\ndata = np.array([[[5, 1], [20, 2]], [[30, 1], [40, 2]], [[55, 1], [60, 2]]], dtype=np.float32)\nreduced = np.mean(data, axis=tuple(axes), keepdims=keepdims == 1)\n# print(reduced)\n# [[[12.5, 1.5]]\n# [[35., 1.5]]\n# [[57.5, 1.5]]]\n\nexpect(node, inputs=[data], outputs=[reduced], name='test_reduce_mean_negative_axes_keepdims_example')\n\nnp.random.seed(0)\ndata = np.random.uniform(-10, 10, shape).astype(np.float32)\nreduced = np.mean(data, axis=tuple(axes), keepdims=keepdims == 1)\n\nexpect(node, inputs=[data], outputs=[reduced], name='test_reduce_mean_negative_axes_keepdims_random')" + } + ] + }, + { + "name": "ReduceMin", + "module": "ai.onnx", + "version": 1, + "support_level": "common", + "description": "Computes the min of the input tensor's element along the provided axes. The resulted\ntensor has the same rank as the input if keepdims equal 1. If keepdims equal 0, then\nthe resulted tensor have the reduced dimension pruned.\n\nThe above behavior is similar to numpy, with the exception that numpy default keepdims to\nFalse instead of True.", + "attributes": [ + { + "name": "axes", + "type": "int64[]", + "required": false, + "description": "A list of integers, along which to reduce. The default is to reduce over all the dimensions of the input tensor." + }, + { + "name": "keepdims", + "type": "int64", + "required": false, + "default": 1, + "description": "Keep the reduced dimension or not, default 1 mean keep reduced dimension." + } + ], + "inputs": [ + { + "name": "data", + "type": "T", + "description": "An input tensor." + } + ], + "min_input": 1, + "max_input": 1, + "outputs": [ + { + "name": "reduced", + "type": "T", + "description": "Reduced output tensor." + } + ], + "min_output": 1, + "max_output": 1, + "type_constraints": [ + { + "description": "Constrain input and output types to high-precision numeric tensors.", + "type_param_str": "T", + "allowed_type_strs": [ + "tensor(uint32)", + "tensor(uint64)", + "tensor(int32)", + "tensor(int64)", + "tensor(float16)", + "tensor(float)", + "tensor(double)" + ] + } + ], + "examples": [ + { + "summary": "default_axes_keepdims", + "code": "shape = [3, 2, 2]\naxes = None\nkeepdims = 1\n\nnode = onnx.helper.make_node(\n 'ReduceMin',\n inputs=['data'],\n outputs=['reduced'],\n keepdims=keepdims)\n\ndata = np.array([[[5, 1], [20, 2]], [[30, 1], [40, 2]], [[55, 1], [60, 2]]], dtype=np.float32)\nreduced = np.minimum.reduce(data, axis=axes, keepdims=keepdims == 1)\n#print(reduced)\n#[[[1.]]]\n\nexpect(node, inputs=[data], outputs=[reduced], name='test_reduce_min_default_axes_keepdims_example')\n\nnp.random.seed(0)\ndata = np.random.uniform(-10, 10, shape).astype(np.float32)\nreduced = np.minimum.reduce(data, axis=axes, keepdims=keepdims == 1)\n\nexpect(node, inputs=[data], outputs=[reduced], name='test_reduce_min_default_axes_keepdims_random')" + }, + { + "summary": "do_not_keepdims", + "code": "shape = [3, 2, 2]\naxes = [1]\nkeepdims = 0\n\nnode = onnx.helper.make_node(\n 'ReduceMin',\n inputs=['data'],\n outputs=['reduced'],\n axes=axes,\n keepdims=keepdims)\n\ndata = np.array([[[5, 1], [20, 2]], [[30, 1], [40, 2]], [[55, 1], [60, 2]]], dtype=np.float32)\nreduced = np.minimum.reduce(data, axis=tuple(axes), keepdims=keepdims == 1)\n#print(reduced)\n#[[5., 1.]\n# [30., 1.]\n# [55., 1.]]\n\nexpect(node, inputs=[data], outputs=[reduced], name='test_reduce_min_do_not_keepdims_example')\n\nnp.random.seed(0)\ndata = np.random.uniform(-10, 10, shape).astype(np.float32)\nreduced = np.minimum.reduce(data, axis=tuple(axes), keepdims=keepdims == 1)\n\nexpect(node, inputs=[data], outputs=[reduced], name='test_reduce_min_do_not_keepdims_random')" + }, + { + "summary": "keepdims", + "code": "shape = [3, 2, 2]\naxes = [1]\nkeepdims = 1\n\nnode = onnx.helper.make_node(\n 'ReduceMin', inputs=['data'],\n outputs=['reduced'],\n axes=axes,\n keepdims=keepdims)\n\ndata = np.array([[[5, 1], [20, 2]], [[30, 1], [40, 2]], [[55, 1], [60, 2]]], dtype=np.float32)\nreduced = np.minimum.reduce(data, axis=tuple(axes), keepdims=keepdims == 1)\n#print(reduced)\n#[[[5., 1.]]\n# [[30., 1.]]\n# [[55., 1.]]]\n\nexpect(node, inputs=[data], outputs=[reduced], name='test_reduce_min_keepdims_example')\n\nnp.random.seed(0)\ndata = np.random.uniform(-10, 10, shape).astype(np.float32)\nreduced = np.minimum.reduce(data, axis=tuple(axes), keepdims=keepdims == 1)\n\nexpect(node, inputs=[data], outputs=[reduced], name='test_reduce_min_keepdims_random')" + }, + { + "summary": "negative_axes_keepdims", + "code": "shape = [3, 2, 2]\naxes = [-2]\nkeepdims = 1\n\nnode = onnx.helper.make_node(\n 'ReduceMin', inputs=['data'],\n outputs=['reduced'],\n axes=axes,\n keepdims=keepdims)\n\ndata = np.array([[[5, 1], [20, 2]], [[30, 1], [40, 2]], [[55, 1], [60, 2]]], dtype=np.float32)\nreduced = np.minimum.reduce(data, axis=tuple(axes), keepdims=keepdims == 1)\n# print(reduced)\n#[[[5., 1.]]\n# [[30., 1.]]\n# [[55., 1.]]]\n\nexpect(node, inputs=[data], outputs=[reduced], name='test_reduce_min_negative_axes_keepdims_example')\n\nnp.random.seed(0)\ndata = np.random.uniform(-10, 10, shape).astype(np.float32)\nreduced = np.minimum.reduce(data, axis=tuple(axes), keepdims=keepdims == 1)\n\nexpect(node, inputs=[data], outputs=[reduced], name='test_reduce_min_negative_axes_keepdims_random')" + } + ] + }, + { + "name": "ReduceMin", + "module": "ai.onnx", + "version": 11, + "support_level": "common", + "description": "Computes the min of the input tensor's element along the provided axes. The resulted\ntensor has the same rank as the input if keepdims equal 1. If keepdims equal 0, then\nthe resulted tensor have the reduced dimension pruned.\n\nThe above behavior is similar to numpy, with the exception that numpy default keepdims to\nFalse instead of True.", + "attributes": [ + { + "name": "axes", + "type": "int64[]", + "required": false, + "description": "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)." + }, + { + "name": "keepdims", + "type": "int64", + "required": false, + "default": 1, + "description": "Keep the reduced dimension or not, default 1 mean keep reduced dimension." + } + ], + "inputs": [ + { + "name": "data", + "type": "T", + "description": "An input tensor." + } + ], + "min_input": 1, + "max_input": 1, + "outputs": [ + { + "name": "reduced", + "type": "T", + "description": "Reduced output tensor." + } + ], + "min_output": 1, + "max_output": 1, + "type_constraints": [ + { + "description": "Constrain input and output types to high-precision numeric tensors.", + "type_param_str": "T", + "allowed_type_strs": [ + "tensor(uint32)", + "tensor(uint64)", + "tensor(int32)", + "tensor(int64)", + "tensor(float16)", + "tensor(float)", + "tensor(double)" + ] + } + ], + "examples": [ + { + "summary": "default_axes_keepdims", + "code": "shape = [3, 2, 2]\naxes = None\nkeepdims = 1\n\nnode = onnx.helper.make_node(\n 'ReduceMin',\n inputs=['data'],\n outputs=['reduced'],\n keepdims=keepdims)\n\ndata = np.array([[[5, 1], [20, 2]], [[30, 1], [40, 2]], [[55, 1], [60, 2]]], dtype=np.float32)\nreduced = np.minimum.reduce(data, axis=axes, keepdims=keepdims == 1)\n#print(reduced)\n#[[[1.]]]\n\nexpect(node, inputs=[data], outputs=[reduced], name='test_reduce_min_default_axes_keepdims_example')\n\nnp.random.seed(0)\ndata = np.random.uniform(-10, 10, shape).astype(np.float32)\nreduced = np.minimum.reduce(data, axis=axes, keepdims=keepdims == 1)\n\nexpect(node, inputs=[data], outputs=[reduced], name='test_reduce_min_default_axes_keepdims_random')" + }, + { + "summary": "do_not_keepdims", + "code": "shape = [3, 2, 2]\naxes = [1]\nkeepdims = 0\n\nnode = onnx.helper.make_node(\n 'ReduceMin',\n inputs=['data'],\n outputs=['reduced'],\n axes=axes,\n keepdims=keepdims)\n\ndata = np.array([[[5, 1], [20, 2]], [[30, 1], [40, 2]], [[55, 1], [60, 2]]], dtype=np.float32)\nreduced = np.minimum.reduce(data, axis=tuple(axes), keepdims=keepdims == 1)\n#print(reduced)\n#[[5., 1.]\n# [30., 1.]\n# [55., 1.]]\n\nexpect(node, inputs=[data], outputs=[reduced], name='test_reduce_min_do_not_keepdims_example')\n\nnp.random.seed(0)\ndata = np.random.uniform(-10, 10, shape).astype(np.float32)\nreduced = np.minimum.reduce(data, axis=tuple(axes), keepdims=keepdims == 1)\n\nexpect(node, inputs=[data], outputs=[reduced], name='test_reduce_min_do_not_keepdims_random')" + }, + { + "summary": "keepdims", + "code": "shape = [3, 2, 2]\naxes = [1]\nkeepdims = 1\n\nnode = onnx.helper.make_node(\n 'ReduceMin', inputs=['data'],\n outputs=['reduced'],\n axes=axes,\n keepdims=keepdims)\n\ndata = np.array([[[5, 1], [20, 2]], [[30, 1], [40, 2]], [[55, 1], [60, 2]]], dtype=np.float32)\nreduced = np.minimum.reduce(data, axis=tuple(axes), keepdims=keepdims == 1)\n#print(reduced)\n#[[[5., 1.]]\n# [[30., 1.]]\n# [[55., 1.]]]\n\nexpect(node, inputs=[data], outputs=[reduced], name='test_reduce_min_keepdims_example')\n\nnp.random.seed(0)\ndata = np.random.uniform(-10, 10, shape).astype(np.float32)\nreduced = np.minimum.reduce(data, axis=tuple(axes), keepdims=keepdims == 1)\n\nexpect(node, inputs=[data], outputs=[reduced], name='test_reduce_min_keepdims_random')" + }, + { + "summary": "negative_axes_keepdims", + "code": "shape = [3, 2, 2]\naxes = [-2]\nkeepdims = 1\n\nnode = onnx.helper.make_node(\n 'ReduceMin', inputs=['data'],\n outputs=['reduced'],\n axes=axes,\n keepdims=keepdims)\n\ndata = np.array([[[5, 1], [20, 2]], [[30, 1], [40, 2]], [[55, 1], [60, 2]]], dtype=np.float32)\nreduced = np.minimum.reduce(data, axis=tuple(axes), keepdims=keepdims == 1)\n# print(reduced)\n#[[[5., 1.]]\n# [[30., 1.]]\n# [[55., 1.]]]\n\nexpect(node, inputs=[data], outputs=[reduced], name='test_reduce_min_negative_axes_keepdims_example')\n\nnp.random.seed(0)\ndata = np.random.uniform(-10, 10, shape).astype(np.float32)\nreduced = np.minimum.reduce(data, axis=tuple(axes), keepdims=keepdims == 1)\n\nexpect(node, inputs=[data], outputs=[reduced], name='test_reduce_min_negative_axes_keepdims_random')" + } + ] + }, + { + "name": "ReduceMin", + "module": "ai.onnx", + "version": 12, + "support_level": "common", + "description": "Computes the min of the input tensor's element along the provided axes. The resulted\ntensor has the same rank as the input if keepdims equal 1. If keepdims equal 0, then\nthe resulted tensor have the reduced dimension pruned.\n\nThe above behavior is similar to numpy, with the exception that numpy default keepdims to\nFalse instead of True.", + "attributes": [ + { + "name": "axes", + "type": "int64[]", + "required": false, + "description": "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)." + }, + { + "name": "keepdims", + "type": "int64", + "required": false, + "default": 1, + "description": "Keep the reduced dimension or not, default 1 mean keep reduced dimension." + } + ], + "inputs": [ + { + "name": "data", + "type": "T", + "description": "An input tensor." + } + ], + "min_input": 1, + "max_input": 1, + "outputs": [ + { + "name": "reduced", + "type": "T", + "description": "Reduced output tensor." + } + ], + "min_output": 1, + "max_output": 1, + "type_constraints": [ + { + "description": "Constrain input and output types to high-precision and 8 bit numeric tensors.", + "type_param_str": "T", + "allowed_type_strs": [ + "tensor(uint32)", + "tensor(uint64)", + "tensor(int32)", + "tensor(int64)", + "tensor(float16)", + "tensor(float)", + "tensor(double)", + "tensor(uint8)", + "tensor(int8)" + ] + } + ], + "examples": [ + { + "summary": "default_axes_keepdims", + "code": "shape = [3, 2, 2]\naxes = None\nkeepdims = 1\n\nnode = onnx.helper.make_node(\n 'ReduceMin',\n inputs=['data'],\n outputs=['reduced'],\n keepdims=keepdims)\n\ndata = np.array([[[5, 1], [20, 2]], [[30, 1], [40, 2]], [[55, 1], [60, 2]]], dtype=np.float32)\nreduced = np.minimum.reduce(data, axis=axes, keepdims=keepdims == 1)\n#print(reduced)\n#[[[1.]]]\n\nexpect(node, inputs=[data], outputs=[reduced], name='test_reduce_min_default_axes_keepdims_example')\n\nnp.random.seed(0)\ndata = np.random.uniform(-10, 10, shape).astype(np.float32)\nreduced = np.minimum.reduce(data, axis=axes, keepdims=keepdims == 1)\n\nexpect(node, inputs=[data], outputs=[reduced], name='test_reduce_min_default_axes_keepdims_random')" + }, + { + "summary": "do_not_keepdims", + "code": "shape = [3, 2, 2]\naxes = [1]\nkeepdims = 0\n\nnode = onnx.helper.make_node(\n 'ReduceMin',\n inputs=['data'],\n outputs=['reduced'],\n axes=axes,\n keepdims=keepdims)\n\ndata = np.array([[[5, 1], [20, 2]], [[30, 1], [40, 2]], [[55, 1], [60, 2]]], dtype=np.float32)\nreduced = np.minimum.reduce(data, axis=tuple(axes), keepdims=keepdims == 1)\n#print(reduced)\n#[[5., 1.]\n# [30., 1.]\n# [55., 1.]]\n\nexpect(node, inputs=[data], outputs=[reduced], name='test_reduce_min_do_not_keepdims_example')\n\nnp.random.seed(0)\ndata = np.random.uniform(-10, 10, shape).astype(np.float32)\nreduced = np.minimum.reduce(data, axis=tuple(axes), keepdims=keepdims == 1)\n\nexpect(node, inputs=[data], outputs=[reduced], name='test_reduce_min_do_not_keepdims_random')" + }, + { + "summary": "keepdims", + "code": "shape = [3, 2, 2]\naxes = [1]\nkeepdims = 1\n\nnode = onnx.helper.make_node(\n 'ReduceMin', inputs=['data'],\n outputs=['reduced'],\n axes=axes,\n keepdims=keepdims)\n\ndata = np.array([[[5, 1], [20, 2]], [[30, 1], [40, 2]], [[55, 1], [60, 2]]], dtype=np.float32)\nreduced = np.minimum.reduce(data, axis=tuple(axes), keepdims=keepdims == 1)\n#print(reduced)\n#[[[5., 1.]]\n# [[30., 1.]]\n# [[55., 1.]]]\n\nexpect(node, inputs=[data], outputs=[reduced], name='test_reduce_min_keepdims_example')\n\nnp.random.seed(0)\ndata = np.random.uniform(-10, 10, shape).astype(np.float32)\nreduced = np.minimum.reduce(data, axis=tuple(axes), keepdims=keepdims == 1)\n\nexpect(node, inputs=[data], outputs=[reduced], name='test_reduce_min_keepdims_random')" + }, + { + "summary": "negative_axes_keepdims", + "code": "shape = [3, 2, 2]\naxes = [-2]\nkeepdims = 1\n\nnode = onnx.helper.make_node(\n 'ReduceMin', inputs=['data'],\n outputs=['reduced'],\n axes=axes,\n keepdims=keepdims)\n\ndata = np.array([[[5, 1], [20, 2]], [[30, 1], [40, 2]], [[55, 1], [60, 2]]], dtype=np.float32)\nreduced = np.minimum.reduce(data, axis=tuple(axes), keepdims=keepdims == 1)\n# print(reduced)\n#[[[5., 1.]]\n# [[30., 1.]]\n# [[55., 1.]]]\n\nexpect(node, inputs=[data], outputs=[reduced], name='test_reduce_min_negative_axes_keepdims_example')\n\nnp.random.seed(0)\ndata = np.random.uniform(-10, 10, shape).astype(np.float32)\nreduced = np.minimum.reduce(data, axis=tuple(axes), keepdims=keepdims == 1)\n\nexpect(node, inputs=[data], outputs=[reduced], name='test_reduce_min_negative_axes_keepdims_random')" + } + ] + }, + { + "name": "ReduceMin", + "module": "ai.onnx", + "version": 13, + "support_level": "common", + "description": "Computes the min of the input tensor's element along the provided axes. The resulted\ntensor has the same rank as the input if keepdims equal 1. If keepdims equal 0, then\nthe resulted tensor have the reduced dimension pruned.\n\nThe above behavior is similar to numpy, with the exception that numpy default keepdims to\nFalse instead of True.", + "attributes": [ + { + "name": "axes", + "type": "int64[]", + "required": false, + "description": "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)." + }, + { + "name": "keepdims", + "type": "int64", + "required": false, + "default": 1, + "description": "Keep the reduced dimension or not, default 1 mean keep reduced dimension." + } + ], + "inputs": [ + { + "name": "data", + "type": "T", + "description": "An input tensor." + } + ], + "min_input": 1, + "max_input": 1, + "outputs": [ + { + "name": "reduced", + "type": "T", + "description": "Reduced output tensor." + } + ], + "min_output": 1, + "max_output": 1, + "type_constraints": [ + { + "description": "Constrain input and output types to high-precision and 8 bit numeric tensors.", + "type_param_str": "T", + "allowed_type_strs": [ + "tensor(uint32)", + "tensor(uint64)", + "tensor(int32)", + "tensor(int64)", + "tensor(float16)", + "tensor(float)", + "tensor(double)", + "tensor(bfloat16)", + "tensor(uint8)", + "tensor(int8)" + ] + } + ], + "examples": [ + { + "summary": "default_axes_keepdims", + "code": "shape = [3, 2, 2]\naxes = None\nkeepdims = 1\n\nnode = onnx.helper.make_node(\n 'ReduceMin',\n inputs=['data'],\n outputs=['reduced'],\n keepdims=keepdims)\n\ndata = np.array([[[5, 1], [20, 2]], [[30, 1], [40, 2]], [[55, 1], [60, 2]]], dtype=np.float32)\nreduced = np.minimum.reduce(data, axis=axes, keepdims=keepdims == 1)\n#print(reduced)\n#[[[1.]]]\n\nexpect(node, inputs=[data], outputs=[reduced], name='test_reduce_min_default_axes_keepdims_example')\n\nnp.random.seed(0)\ndata = np.random.uniform(-10, 10, shape).astype(np.float32)\nreduced = np.minimum.reduce(data, axis=axes, keepdims=keepdims == 1)\n\nexpect(node, inputs=[data], outputs=[reduced], name='test_reduce_min_default_axes_keepdims_random')" + }, + { + "summary": "do_not_keepdims", + "code": "shape = [3, 2, 2]\naxes = [1]\nkeepdims = 0\n\nnode = onnx.helper.make_node(\n 'ReduceMin',\n inputs=['data'],\n outputs=['reduced'],\n axes=axes,\n keepdims=keepdims)\n\ndata = np.array([[[5, 1], [20, 2]], [[30, 1], [40, 2]], [[55, 1], [60, 2]]], dtype=np.float32)\nreduced = np.minimum.reduce(data, axis=tuple(axes), keepdims=keepdims == 1)\n#print(reduced)\n#[[5., 1.]\n# [30., 1.]\n# [55., 1.]]\n\nexpect(node, inputs=[data], outputs=[reduced], name='test_reduce_min_do_not_keepdims_example')\n\nnp.random.seed(0)\ndata = np.random.uniform(-10, 10, shape).astype(np.float32)\nreduced = np.minimum.reduce(data, axis=tuple(axes), keepdims=keepdims == 1)\n\nexpect(node, inputs=[data], outputs=[reduced], name='test_reduce_min_do_not_keepdims_random')" + }, + { + "summary": "keepdims", + "code": "shape = [3, 2, 2]\naxes = [1]\nkeepdims = 1\n\nnode = onnx.helper.make_node(\n 'ReduceMin', inputs=['data'],\n outputs=['reduced'],\n axes=axes,\n keepdims=keepdims)\n\ndata = np.array([[[5, 1], [20, 2]], [[30, 1], [40, 2]], [[55, 1], [60, 2]]], dtype=np.float32)\nreduced = np.minimum.reduce(data, axis=tuple(axes), keepdims=keepdims == 1)\n#print(reduced)\n#[[[5., 1.]]\n# [[30., 1.]]\n# [[55., 1.]]]\n\nexpect(node, inputs=[data], outputs=[reduced], name='test_reduce_min_keepdims_example')\n\nnp.random.seed(0)\ndata = np.random.uniform(-10, 10, shape).astype(np.float32)\nreduced = np.minimum.reduce(data, axis=tuple(axes), keepdims=keepdims == 1)\n\nexpect(node, inputs=[data], outputs=[reduced], name='test_reduce_min_keepdims_random')" + }, + { + "summary": "negative_axes_keepdims", + "code": "shape = [3, 2, 2]\naxes = [-2]\nkeepdims = 1\n\nnode = onnx.helper.make_node(\n 'ReduceMin', inputs=['data'],\n outputs=['reduced'],\n axes=axes,\n keepdims=keepdims)\n\ndata = np.array([[[5, 1], [20, 2]], [[30, 1], [40, 2]], [[55, 1], [60, 2]]], dtype=np.float32)\nreduced = np.minimum.reduce(data, axis=tuple(axes), keepdims=keepdims == 1)\n# print(reduced)\n#[[[5., 1.]]\n# [[30., 1.]]\n# [[55., 1.]]]\n\nexpect(node, inputs=[data], outputs=[reduced], name='test_reduce_min_negative_axes_keepdims_example')\n\nnp.random.seed(0)\ndata = np.random.uniform(-10, 10, shape).astype(np.float32)\nreduced = np.minimum.reduce(data, axis=tuple(axes), keepdims=keepdims == 1)\n\nexpect(node, inputs=[data], outputs=[reduced], name='test_reduce_min_negative_axes_keepdims_random')" + } + ] + }, + { + "name": "ReduceProd", + "module": "ai.onnx", + "version": 1, + "support_level": "common", + "description": "Computes the product of the input tensor's element along the provided axes. The resulted\ntensor has the same rank as the input if keepdims equal 1. If keepdims equal 0, then\nthe resulted tensor have the reduced dimension pruned.\n\nThe above behavior is similar to numpy, with the exception that numpy default keepdims to\nFalse instead of True.", + "attributes": [ + { + "name": "axes", + "type": "int64[]", + "required": false, + "description": "A list of integers, along which to reduce. The default is to reduce over all the dimensions of the input tensor." + }, + { + "name": "keepdims", + "type": "int64", + "required": false, + "default": 1, + "description": "Keep the reduced dimension or not, default 1 mean keep reduced dimension." + } + ], + "inputs": [ + { + "name": "data", + "type": "T", + "description": "An input tensor." + } + ], + "min_input": 1, + "max_input": 1, + "outputs": [ + { + "name": "reduced", + "type": "T", + "description": "Reduced output tensor." + } + ], + "min_output": 1, + "max_output": 1, + "type_constraints": [ + { + "description": "Constrain input and output types to high-precision numeric tensors.", + "type_param_str": "T", + "allowed_type_strs": [ + "tensor(uint32)", + "tensor(uint64)", + "tensor(int32)", + "tensor(int64)", + "tensor(float16)", + "tensor(float)", + "tensor(double)" + ] + } + ], + "examples": [ + { + "summary": "default_axes_keepdims", + "code": "shape = [3, 2, 2]\naxes = None\nkeepdims = 1\n\nnode = onnx.helper.make_node(\n 'ReduceProd',\n inputs=['data'],\n outputs=['reduced'],\n keepdims=keepdims)\n\ndata = np.array([[[1, 2], [3, 4]], [[5, 6], [7, 8]], [[9, 10], [11, 12]]], dtype=np.float32)\nreduced = np.prod(data, axis=axes, keepdims=keepdims == 1)\n#print(reduced)\n#[[[4.790016e+08]]]\n\nexpect(node, inputs=[data], outputs=[reduced], name='test_reduce_prod_default_axes_keepdims_example')\n\nnp.random.seed(0)\ndata = np.random.uniform(-10, 10, shape).astype(np.float32)\nreduced = np.prod(data, axis=axes, keepdims=keepdims == 1)\nexpect(node, inputs=[data], outputs=[reduced], name='test_reduce_prod_default_axes_keepdims_random')" + }, + { + "summary": "do_not_keepdims", + "code": "shape = [3, 2, 2]\naxes = [1]\nkeepdims = 0\n\nnode = onnx.helper.make_node(\n 'ReduceProd',\n inputs=['data'],\n outputs=['reduced'],\n axes=axes,\n keepdims=keepdims)\n\ndata = np.array([[[1, 2], [3, 4]], [[5, 6], [7, 8]], [[9, 10], [11, 12]]], dtype=np.float32)\nreduced = np.prod(data, axis=tuple(axes), keepdims=keepdims == 1)\n#print(reduced)\n#[[3., 8.]\n# [35., 48.]\n# [99., 120.]]\n\nexpect(node, inputs=[data], outputs=[reduced], name='test_reduce_prod_do_not_keepdims_example')\n\nnp.random.seed(0)\ndata = np.random.uniform(-10, 10, shape).astype(np.float32)\nreduced = np.prod(data, axis=tuple(axes), keepdims=keepdims == 1)\nexpect(node, inputs=[data], outputs=[reduced], name='test_reduce_prod_do_not_keepdims_random')" + }, + { + "summary": "keepdims", + "code": "shape = [3, 2, 2]\naxes = [1]\nkeepdims = 1\n\nnode = onnx.helper.make_node(\n 'ReduceProd',\n inputs=['data'],\n outputs=['reduced'],\n axes=axes,\n keepdims=keepdims)\n\ndata = np.array([[[1, 2], [3, 4]], [[5, 6], [7, 8]], [[9, 10], [11, 12]]], dtype=np.float32)\nreduced = np.prod(data, axis=tuple(axes), keepdims=keepdims == 1)\n#print(reduced)\n#[[[3., 8.]]\n# [[35., 48.]]\n# [[99., 120.]]]\n\nexpect(node, inputs=[data], outputs=[reduced], name='test_reduce_prod_keepdims_example')\n\nnp.random.seed(0)\ndata = np.random.uniform(-10, 10, shape).astype(np.float32)\nreduced = np.prod(data, axis=tuple(axes), keepdims=keepdims == 1)\nexpect(node, inputs=[data], outputs=[reduced], name='test_reduce_prod_keepdims_random')" + }, + { + "summary": "negative_axes_keepdims", + "code": "shape = [3, 2, 2]\naxes = [-2]\nkeepdims = 1\n\nnode = onnx.helper.make_node(\n 'ReduceProd',\n inputs=['data'],\n outputs=['reduced'],\n axes=axes,\n keepdims=keepdims)\n\ndata = np.array([[[1, 2], [3, 4]], [[5, 6], [7, 8]], [[9, 10], [11, 12]]], dtype=np.float32)\nreduced = np.prod(data, axis=tuple(axes), keepdims=keepdims == 1)\n# print(reduced)\n#[[[3., 8.]]\n# [[35., 48.]]\n# [[99., 120.]]]\n\nexpect(node, inputs=[data], outputs=[reduced], name='test_reduce_prod_negative_axes_keepdims_example')\n\nnp.random.seed(0)\ndata = np.random.uniform(-10, 10, shape).astype(np.float32)\nreduced = np.prod(data, axis=tuple(axes), keepdims=keepdims == 1)\nexpect(node, inputs=[data], outputs=[reduced], name='test_reduce_prod_negative_axes_keepdims_random')" + } + ] + }, + { + "name": "ReduceProd", + "module": "ai.onnx", + "version": 11, + "support_level": "common", + "description": "Computes the product of the input tensor's element along the provided axes. The resulted\ntensor has the same rank as the input if keepdims equal 1. If keepdims equal 0, then\nthe resulted tensor have the reduced dimension pruned.\n\nThe above behavior is similar to numpy, with the exception that numpy default keepdims to\nFalse instead of True.", + "attributes": [ + { + "name": "axes", + "type": "int64[]", + "required": false, + "description": "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)." + }, + { + "name": "keepdims", + "type": "int64", + "required": false, + "default": 1, + "description": "Keep the reduced dimension or not, default 1 mean keep reduced dimension." + } + ], + "inputs": [ + { + "name": "data", + "type": "T", + "description": "An input tensor." + } + ], + "min_input": 1, + "max_input": 1, + "outputs": [ + { + "name": "reduced", + "type": "T", + "description": "Reduced output tensor." + } + ], + "min_output": 1, + "max_output": 1, + "type_constraints": [ + { + "description": "Constrain input and output types to high-precision numeric tensors.", + "type_param_str": "T", + "allowed_type_strs": [ + "tensor(uint32)", + "tensor(uint64)", + "tensor(int32)", + "tensor(int64)", + "tensor(float16)", + "tensor(float)", + "tensor(double)" + ] + } + ], + "examples": [ + { + "summary": "default_axes_keepdims", + "code": "shape = [3, 2, 2]\naxes = None\nkeepdims = 1\n\nnode = onnx.helper.make_node(\n 'ReduceProd',\n inputs=['data'],\n outputs=['reduced'],\n keepdims=keepdims)\n\ndata = np.array([[[1, 2], [3, 4]], [[5, 6], [7, 8]], [[9, 10], [11, 12]]], dtype=np.float32)\nreduced = np.prod(data, axis=axes, keepdims=keepdims == 1)\n#print(reduced)\n#[[[4.790016e+08]]]\n\nexpect(node, inputs=[data], outputs=[reduced], name='test_reduce_prod_default_axes_keepdims_example')\n\nnp.random.seed(0)\ndata = np.random.uniform(-10, 10, shape).astype(np.float32)\nreduced = np.prod(data, axis=axes, keepdims=keepdims == 1)\nexpect(node, inputs=[data], outputs=[reduced], name='test_reduce_prod_default_axes_keepdims_random')" + }, + { + "summary": "do_not_keepdims", + "code": "shape = [3, 2, 2]\naxes = [1]\nkeepdims = 0\n\nnode = onnx.helper.make_node(\n 'ReduceProd',\n inputs=['data'],\n outputs=['reduced'],\n axes=axes,\n keepdims=keepdims)\n\ndata = np.array([[[1, 2], [3, 4]], [[5, 6], [7, 8]], [[9, 10], [11, 12]]], dtype=np.float32)\nreduced = np.prod(data, axis=tuple(axes), keepdims=keepdims == 1)\n#print(reduced)\n#[[3., 8.]\n# [35., 48.]\n# [99., 120.]]\n\nexpect(node, inputs=[data], outputs=[reduced], name='test_reduce_prod_do_not_keepdims_example')\n\nnp.random.seed(0)\ndata = np.random.uniform(-10, 10, shape).astype(np.float32)\nreduced = np.prod(data, axis=tuple(axes), keepdims=keepdims == 1)\nexpect(node, inputs=[data], outputs=[reduced], name='test_reduce_prod_do_not_keepdims_random')" + }, + { + "summary": "keepdims", + "code": "shape = [3, 2, 2]\naxes = [1]\nkeepdims = 1\n\nnode = onnx.helper.make_node(\n 'ReduceProd',\n inputs=['data'],\n outputs=['reduced'],\n axes=axes,\n keepdims=keepdims)\n\ndata = np.array([[[1, 2], [3, 4]], [[5, 6], [7, 8]], [[9, 10], [11, 12]]], dtype=np.float32)\nreduced = np.prod(data, axis=tuple(axes), keepdims=keepdims == 1)\n#print(reduced)\n#[[[3., 8.]]\n# [[35., 48.]]\n# [[99., 120.]]]\n\nexpect(node, inputs=[data], outputs=[reduced], name='test_reduce_prod_keepdims_example')\n\nnp.random.seed(0)\ndata = np.random.uniform(-10, 10, shape).astype(np.float32)\nreduced = np.prod(data, axis=tuple(axes), keepdims=keepdims == 1)\nexpect(node, inputs=[data], outputs=[reduced], name='test_reduce_prod_keepdims_random')" + }, + { + "summary": "negative_axes_keepdims", + "code": "shape = [3, 2, 2]\naxes = [-2]\nkeepdims = 1\n\nnode = onnx.helper.make_node(\n 'ReduceProd',\n inputs=['data'],\n outputs=['reduced'],\n axes=axes,\n keepdims=keepdims)\n\ndata = np.array([[[1, 2], [3, 4]], [[5, 6], [7, 8]], [[9, 10], [11, 12]]], dtype=np.float32)\nreduced = np.prod(data, axis=tuple(axes), keepdims=keepdims == 1)\n# print(reduced)\n#[[[3., 8.]]\n# [[35., 48.]]\n# [[99., 120.]]]\n\nexpect(node, inputs=[data], outputs=[reduced], name='test_reduce_prod_negative_axes_keepdims_example')\n\nnp.random.seed(0)\ndata = np.random.uniform(-10, 10, shape).astype(np.float32)\nreduced = np.prod(data, axis=tuple(axes), keepdims=keepdims == 1)\nexpect(node, inputs=[data], outputs=[reduced], name='test_reduce_prod_negative_axes_keepdims_random')" + } + ] + }, + { + "name": "ReduceProd", + "module": "ai.onnx", + "version": 13, + "support_level": "common", + "description": "Computes the product of the input tensor's element along the provided axes. The resulted\ntensor has the same rank as the input if keepdims equal 1. If keepdims equal 0, then\nthe resulted tensor have the reduced dimension pruned.\n\nThe above behavior is similar to numpy, with the exception that numpy default keepdims to\nFalse instead of True.", + "attributes": [ + { + "name": "axes", + "type": "int64[]", + "required": false, + "description": "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)." + }, + { + "name": "keepdims", + "type": "int64", + "required": false, + "default": 1, + "description": "Keep the reduced dimension or not, default 1 mean keep reduced dimension." + } + ], + "inputs": [ + { + "name": "data", + "type": "T", + "description": "An input tensor." + } + ], + "min_input": 1, + "max_input": 1, + "outputs": [ + { + "name": "reduced", + "type": "T", + "description": "Reduced output tensor." + } + ], + "min_output": 1, + "max_output": 1, + "type_constraints": [ + { + "description": "Constrain input and output types to high-precision numeric tensors.", + "type_param_str": "T", + "allowed_type_strs": [ + "tensor(uint32)", + "tensor(uint64)", + "tensor(int32)", + "tensor(int64)", + "tensor(float16)", + "tensor(float)", + "tensor(double)", + "tensor(bfloat16)" + ] + } + ], + "examples": [ + { + "summary": "default_axes_keepdims", + "code": "shape = [3, 2, 2]\naxes = None\nkeepdims = 1\n\nnode = onnx.helper.make_node(\n 'ReduceProd',\n inputs=['data'],\n outputs=['reduced'],\n keepdims=keepdims)\n\ndata = np.array([[[1, 2], [3, 4]], [[5, 6], [7, 8]], [[9, 10], [11, 12]]], dtype=np.float32)\nreduced = np.prod(data, axis=axes, keepdims=keepdims == 1)\n#print(reduced)\n#[[[4.790016e+08]]]\n\nexpect(node, inputs=[data], outputs=[reduced], name='test_reduce_prod_default_axes_keepdims_example')\n\nnp.random.seed(0)\ndata = np.random.uniform(-10, 10, shape).astype(np.float32)\nreduced = np.prod(data, axis=axes, keepdims=keepdims == 1)\nexpect(node, inputs=[data], outputs=[reduced], name='test_reduce_prod_default_axes_keepdims_random')" + }, + { + "summary": "do_not_keepdims", + "code": "shape = [3, 2, 2]\naxes = [1]\nkeepdims = 0\n\nnode = onnx.helper.make_node(\n 'ReduceProd',\n inputs=['data'],\n outputs=['reduced'],\n axes=axes,\n keepdims=keepdims)\n\ndata = np.array([[[1, 2], [3, 4]], [[5, 6], [7, 8]], [[9, 10], [11, 12]]], dtype=np.float32)\nreduced = np.prod(data, axis=tuple(axes), keepdims=keepdims == 1)\n#print(reduced)\n#[[3., 8.]\n# [35., 48.]\n# [99., 120.]]\n\nexpect(node, inputs=[data], outputs=[reduced], name='test_reduce_prod_do_not_keepdims_example')\n\nnp.random.seed(0)\ndata = np.random.uniform(-10, 10, shape).astype(np.float32)\nreduced = np.prod(data, axis=tuple(axes), keepdims=keepdims == 1)\nexpect(node, inputs=[data], outputs=[reduced], name='test_reduce_prod_do_not_keepdims_random')" + }, + { + "summary": "keepdims", + "code": "shape = [3, 2, 2]\naxes = [1]\nkeepdims = 1\n\nnode = onnx.helper.make_node(\n 'ReduceProd',\n inputs=['data'],\n outputs=['reduced'],\n axes=axes,\n keepdims=keepdims)\n\ndata = np.array([[[1, 2], [3, 4]], [[5, 6], [7, 8]], [[9, 10], [11, 12]]], dtype=np.float32)\nreduced = np.prod(data, axis=tuple(axes), keepdims=keepdims == 1)\n#print(reduced)\n#[[[3., 8.]]\n# [[35., 48.]]\n# [[99., 120.]]]\n\nexpect(node, inputs=[data], outputs=[reduced], name='test_reduce_prod_keepdims_example')\n\nnp.random.seed(0)\ndata = np.random.uniform(-10, 10, shape).astype(np.float32)\nreduced = np.prod(data, axis=tuple(axes), keepdims=keepdims == 1)\nexpect(node, inputs=[data], outputs=[reduced], name='test_reduce_prod_keepdims_random')" + }, + { + "summary": "negative_axes_keepdims", + "code": "shape = [3, 2, 2]\naxes = [-2]\nkeepdims = 1\n\nnode = onnx.helper.make_node(\n 'ReduceProd',\n inputs=['data'],\n outputs=['reduced'],\n axes=axes,\n keepdims=keepdims)\n\ndata = np.array([[[1, 2], [3, 4]], [[5, 6], [7, 8]], [[9, 10], [11, 12]]], dtype=np.float32)\nreduced = np.prod(data, axis=tuple(axes), keepdims=keepdims == 1)\n# print(reduced)\n#[[[3., 8.]]\n# [[35., 48.]]\n# [[99., 120.]]]\n\nexpect(node, inputs=[data], outputs=[reduced], name='test_reduce_prod_negative_axes_keepdims_example')\n\nnp.random.seed(0)\ndata = np.random.uniform(-10, 10, shape).astype(np.float32)\nreduced = np.prod(data, axis=tuple(axes), keepdims=keepdims == 1)\nexpect(node, inputs=[data], outputs=[reduced], name='test_reduce_prod_negative_axes_keepdims_random')" + } + ] + }, + { + "name": "ReduceSum", + "module": "ai.onnx", + "version": 1, + "support_level": "common", + "description": "Computes the sum of the input tensor's element along the provided axes. The resulted\ntensor has the same rank as the input if keepdims equal 1. If keepdims equal 0, then\nthe resulted tensor have the reduced dimension pruned.\n\nThe above behavior is similar to numpy, with the exception that numpy default keepdims to\nFalse instead of True.", + "attributes": [ + { + "name": "axes", + "type": "int64[]", + "required": false, + "description": "A list of integers, along which to reduce. The default is to reduce over all the dimensions of the input tensor." + }, + { + "name": "keepdims", + "type": "int64", + "required": false, + "default": 1, + "description": "Keep the reduced dimension or not, default 1 mean keep reduced dimension." + } + ], + "inputs": [ + { + "name": "data", + "type": "T", + "description": "An input tensor." + } + ], + "min_input": 1, + "max_input": 1, + "outputs": [ + { + "name": "reduced", + "type": "T", + "description": "Reduced output tensor." + } + ], + "min_output": 1, + "max_output": 1, + "type_constraints": [ + { + "description": "Constrain input and output types to high-precision numeric tensors.", + "type_param_str": "T", + "allowed_type_strs": [ + "tensor(uint32)", + "tensor(uint64)", + "tensor(int32)", + "tensor(int64)", + "tensor(float16)", + "tensor(float)", + "tensor(double)" + ] + } + ], + "examples": [ + { + "summary": "default_axes_keepdims", + "code": "shape = [3, 2, 2]\naxes = np.array([], dtype=np.int64)\nkeepdims = 1\n\nnode = onnx.helper.make_node(\n 'ReduceSum',\n inputs=['data', 'axes'],\n outputs=['reduced'],\n keepdims=keepdims)\n\ndata = np.array([[[1, 2], [3, 4]], [[5, 6], [7, 8]], [[9, 10], [11, 12]]], dtype=np.float32)\nreduced = np.sum(data, axis=None, keepdims=keepdims == 1)\n#print(reduced)\n#[[[78.]]]\n\nexpect(node, inputs=[data, axes], outputs=[reduced], name='test_reduce_sum_default_axes_keepdims_example')\n\nnp.random.seed(0)\ndata = np.random.uniform(-10, 10, shape).astype(np.float32)\nreduced = np.sum(data, axis=None, keepdims=keepdims == 1)\n\nexpect(node, inputs=[data, axes], outputs=[reduced], name='test_reduce_sum_default_axes_keepdims_random')" + }, + { + "summary": "do_not_keepdims", + "code": "shape = [3, 2, 2]\naxes = np.array([1], dtype=np.int64)\nkeepdims = 0\n\nnode = onnx.helper.make_node(\n 'ReduceSum',\n inputs=['data', 'axes'],\n outputs=['reduced'],\n keepdims=keepdims)\n\ndata = np.array([[[1, 2], [3, 4]], [[5, 6], [7, 8]], [[9, 10], [11, 12]]], dtype=np.float32)\nreduced = np.sum(data, axis=tuple(axes.tolist()), keepdims=keepdims == 1)\n#print(reduced)\n#[[4., 6.]\n# [12., 14.]\n# [20., 22.]]\n\nexpect(node, inputs=[data, axes], outputs=[reduced], name='test_reduce_sum_do_not_keepdims_example')\n\nnp.random.seed(0)\ndata = np.random.uniform(-10, 10, shape).astype(np.float32)\nreduced = np.sum(data, axis=tuple(axes.tolist()), keepdims=keepdims == 1)\n\nexpect(node, inputs=[data, axes], outputs=[reduced], name='test_reduce_sum_do_not_keepdims_random')" + }, + { + "summary": "empty_axes_input_noop", + "code": "shape = [3, 2, 2]\nkeepdims = 1\n\nnode = onnx.helper.make_node(\n 'ReduceSum',\n inputs=['data', 'axes'],\n outputs=['reduced'],\n keepdims=keepdims,\n noop_with_empty_axes=True)\n\ndata = np.array([[[1, 2], [3, 4]], [[5, 6], [7, 8]], [[9, 10], [11, 12]]], dtype=np.float32)\naxes = np.array([], dtype=np.int64)\nreduced = np.array(data)\n#print(reduced)\n#[[[1, 2], [3, 4]], [[5, 6], [7, 8]], [[9, 10], [11, 12]]]\n\nexpect(node, inputs=[data, axes], outputs=[reduced],\n name='test_reduce_sum_empty_axes_input_noop_example')\n\nnp.random.seed(0)\ndata = np.random.uniform(-10, 10, shape).astype(np.float32)\nreduced = np.array(data)\n\nexpect(node, inputs=[data, axes], outputs=[reduced], name='test_reduce_sum_negative_axes_keepdims_random')" + }, + { + "summary": "keepdims", + "code": "shape = [3, 2, 2]\naxes = np.array([1], dtype=np.int64)\nkeepdims = 1\n\nnode = onnx.helper.make_node(\n 'ReduceSum',\n inputs=['data', 'axes'],\n outputs=['reduced'],\n keepdims=keepdims)\n\ndata = np.array([[[1, 2], [3, 4]], [[5, 6], [7, 8]], [[9, 10], [11, 12]]], dtype=np.float32)\nreduced = np.sum(data, axis=tuple(axes.tolist()), keepdims=keepdims == 1)\n#print(reduced)\n#[[[4., 6.]]\n# [[12., 14.]]\n# [[20., 22.]]]\n\nexpect(node, inputs=[data, axes], outputs=[reduced], name='test_reduce_sum_keepdims_example')\n\nnp.random.seed(0)\ndata = np.random.uniform(-10, 10, shape).astype(np.float32)\nreduced = np.sum(data, axis=tuple(axes.tolist()), keepdims=keepdims == 1)\n\nexpect(node, inputs=[data, axes], outputs=[reduced], name='test_reduce_sum_keepdims_random')" + }, + { + "summary": "negative_axes_keepdims", + "code": "shape = [3, 2, 2]\naxes = np.array([-2], dtype=np.int64)\nkeepdims = 1\n\nnode = onnx.helper.make_node(\n 'ReduceSum',\n inputs=['data', 'axes'],\n outputs=['reduced'],\n keepdims=keepdims)\n\ndata = np.array([[[1, 2], [3, 4]], [[5, 6], [7, 8]], [[9, 10], [11, 12]]], dtype=np.float32)\nreduced = np.sum(data, axis=tuple(axes.tolist()), keepdims=keepdims == 1)\n# print(reduced)\n#[[[4., 6.]]\n# [[12., 14.]]\n# [[20., 22.]]]\n\nexpect(node, inputs=[data, axes], outputs=[reduced],\n name='test_reduce_sum_negative_axes_keepdims_example')\n\nnp.random.seed(0)\ndata = np.random.uniform(-10, 10, shape).astype(np.float32)\nreduced = np.sum(data, axis=tuple(\n axes.tolist()), keepdims=keepdims == 1)\n\nexpect(node, inputs=[data, axes], outputs=[reduced],\n name='test_reduce_sum_negative_axes_keepdims_random')" + } + ] + }, + { + "name": "ReduceSum", + "module": "ai.onnx", + "version": 11, + "support_level": "common", + "description": "Computes the sum of the input tensor's element along the provided axes. The resulted\ntensor has the same rank as the input if keepdims equal 1. If keepdims equal 0, then\nthe resulted tensor have the reduced dimension pruned.\n\nThe above behavior is similar to numpy, with the exception that numpy default keepdims to\nFalse instead of True.", + "attributes": [ + { + "name": "axes", + "type": "int64[]", + "required": false, + "description": "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)." + }, + { + "name": "keepdims", + "type": "int64", + "required": false, + "default": 1, + "description": "Keep the reduced dimension or not, default 1 mean keep reduced dimension." + } + ], + "inputs": [ + { + "name": "data", + "type": "T", + "description": "An input tensor." + } + ], + "min_input": 1, + "max_input": 1, + "outputs": [ + { + "name": "reduced", + "type": "T", + "description": "Reduced output tensor." + } + ], + "min_output": 1, + "max_output": 1, + "type_constraints": [ + { + "description": "Constrain input and output types to high-precision numeric tensors.", + "type_param_str": "T", + "allowed_type_strs": [ + "tensor(uint32)", + "tensor(uint64)", + "tensor(int32)", + "tensor(int64)", + "tensor(float16)", + "tensor(float)", + "tensor(double)" + ] + } + ], + "examples": [ + { + "summary": "default_axes_keepdims", + "code": "shape = [3, 2, 2]\naxes = np.array([], dtype=np.int64)\nkeepdims = 1\n\nnode = onnx.helper.make_node(\n 'ReduceSum',\n inputs=['data', 'axes'],\n outputs=['reduced'],\n keepdims=keepdims)\n\ndata = np.array([[[1, 2], [3, 4]], [[5, 6], [7, 8]], [[9, 10], [11, 12]]], dtype=np.float32)\nreduced = np.sum(data, axis=None, keepdims=keepdims == 1)\n#print(reduced)\n#[[[78.]]]\n\nexpect(node, inputs=[data, axes], outputs=[reduced], name='test_reduce_sum_default_axes_keepdims_example')\n\nnp.random.seed(0)\ndata = np.random.uniform(-10, 10, shape).astype(np.float32)\nreduced = np.sum(data, axis=None, keepdims=keepdims == 1)\n\nexpect(node, inputs=[data, axes], outputs=[reduced], name='test_reduce_sum_default_axes_keepdims_random')" + }, + { + "summary": "do_not_keepdims", + "code": "shape = [3, 2, 2]\naxes = np.array([1], dtype=np.int64)\nkeepdims = 0\n\nnode = onnx.helper.make_node(\n 'ReduceSum',\n inputs=['data', 'axes'],\n outputs=['reduced'],\n keepdims=keepdims)\n\ndata = np.array([[[1, 2], [3, 4]], [[5, 6], [7, 8]], [[9, 10], [11, 12]]], dtype=np.float32)\nreduced = np.sum(data, axis=tuple(axes.tolist()), keepdims=keepdims == 1)\n#print(reduced)\n#[[4., 6.]\n# [12., 14.]\n# [20., 22.]]\n\nexpect(node, inputs=[data, axes], outputs=[reduced], name='test_reduce_sum_do_not_keepdims_example')\n\nnp.random.seed(0)\ndata = np.random.uniform(-10, 10, shape).astype(np.float32)\nreduced = np.sum(data, axis=tuple(axes.tolist()), keepdims=keepdims == 1)\n\nexpect(node, inputs=[data, axes], outputs=[reduced], name='test_reduce_sum_do_not_keepdims_random')" + }, + { + "summary": "empty_axes_input_noop", + "code": "shape = [3, 2, 2]\nkeepdims = 1\n\nnode = onnx.helper.make_node(\n 'ReduceSum',\n inputs=['data', 'axes'],\n outputs=['reduced'],\n keepdims=keepdims,\n noop_with_empty_axes=True)\n\ndata = np.array([[[1, 2], [3, 4]], [[5, 6], [7, 8]], [[9, 10], [11, 12]]], dtype=np.float32)\naxes = np.array([], dtype=np.int64)\nreduced = np.array(data)\n#print(reduced)\n#[[[1, 2], [3, 4]], [[5, 6], [7, 8]], [[9, 10], [11, 12]]]\n\nexpect(node, inputs=[data, axes], outputs=[reduced],\n name='test_reduce_sum_empty_axes_input_noop_example')\n\nnp.random.seed(0)\ndata = np.random.uniform(-10, 10, shape).astype(np.float32)\nreduced = np.array(data)\n\nexpect(node, inputs=[data, axes], outputs=[reduced], name='test_reduce_sum_negative_axes_keepdims_random')" + }, + { + "summary": "keepdims", + "code": "shape = [3, 2, 2]\naxes = np.array([1], dtype=np.int64)\nkeepdims = 1\n\nnode = onnx.helper.make_node(\n 'ReduceSum',\n inputs=['data', 'axes'],\n outputs=['reduced'],\n keepdims=keepdims)\n\ndata = np.array([[[1, 2], [3, 4]], [[5, 6], [7, 8]], [[9, 10], [11, 12]]], dtype=np.float32)\nreduced = np.sum(data, axis=tuple(axes.tolist()), keepdims=keepdims == 1)\n#print(reduced)\n#[[[4., 6.]]\n# [[12., 14.]]\n# [[20., 22.]]]\n\nexpect(node, inputs=[data, axes], outputs=[reduced], name='test_reduce_sum_keepdims_example')\n\nnp.random.seed(0)\ndata = np.random.uniform(-10, 10, shape).astype(np.float32)\nreduced = np.sum(data, axis=tuple(axes.tolist()), keepdims=keepdims == 1)\n\nexpect(node, inputs=[data, axes], outputs=[reduced], name='test_reduce_sum_keepdims_random')" + }, + { + "summary": "negative_axes_keepdims", + "code": "shape = [3, 2, 2]\naxes = np.array([-2], dtype=np.int64)\nkeepdims = 1\n\nnode = onnx.helper.make_node(\n 'ReduceSum',\n inputs=['data', 'axes'],\n outputs=['reduced'],\n keepdims=keepdims)\n\ndata = np.array([[[1, 2], [3, 4]], [[5, 6], [7, 8]], [[9, 10], [11, 12]]], dtype=np.float32)\nreduced = np.sum(data, axis=tuple(axes.tolist()), keepdims=keepdims == 1)\n# print(reduced)\n#[[[4., 6.]]\n# [[12., 14.]]\n# [[20., 22.]]]\n\nexpect(node, inputs=[data, axes], outputs=[reduced],\n name='test_reduce_sum_negative_axes_keepdims_example')\n\nnp.random.seed(0)\ndata = np.random.uniform(-10, 10, shape).astype(np.float32)\nreduced = np.sum(data, axis=tuple(\n axes.tolist()), keepdims=keepdims == 1)\n\nexpect(node, inputs=[data, axes], outputs=[reduced],\n name='test_reduce_sum_negative_axes_keepdims_random')" + } + ] + }, + { + "name": "ReduceSum", + "module": "ai.onnx", + "version": 13, + "support_level": "common", + "description": "Computes the sum of the input tensor's element along the provided axes. The resulted\ntensor has the same rank as the input if keepdims equal 1. If keepdims equal 0, then\nthe resulted tensor have the reduced dimension pruned.\n\nThe above behavior is similar to numpy, with the exception that numpy default keepdims to\nFalse instead of True.", + "attributes": [ + { + "name": "keepdims", + "type": "int64", + "required": false, + "default": 1, + "description": "Keep the reduced dimension or not, default 1 mean keep reduced dimension." + }, + { + "name": "noop_with_empty_axes", + "type": "int64", + "required": false, + "description": "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": [ + { + "name": "data", + "type": "T", + "description": "An input tensor." + }, + { + "name": "axes", + "type": "tensor(int64)", + "option": "optional", + "description": "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)." + } + ], + "min_input": 1, + "max_input": 2, + "outputs": [ + { + "name": "reduced", + "type": "T", + "description": "Reduced output tensor." + } + ], + "min_output": 1, + "max_output": 1, + "inputs_range": "1 - 2", + "type_constraints": [ + { + "description": "Constrain input and output types to high-precision numeric tensors.", + "type_param_str": "T", + "allowed_type_strs": [ + "tensor(uint32)", + "tensor(uint64)", + "tensor(int32)", + "tensor(int64)", + "tensor(float16)", + "tensor(float)", + "tensor(double)", + "tensor(bfloat16)" + ] + } + ], + "examples": [ + { + "summary": "default_axes_keepdims", + "code": "shape = [3, 2, 2]\naxes = np.array([], dtype=np.int64)\nkeepdims = 1\n\nnode = onnx.helper.make_node(\n 'ReduceSum',\n inputs=['data', 'axes'],\n outputs=['reduced'],\n keepdims=keepdims)\n\ndata = np.array([[[1, 2], [3, 4]], [[5, 6], [7, 8]], [[9, 10], [11, 12]]], dtype=np.float32)\nreduced = np.sum(data, axis=None, keepdims=keepdims == 1)\n#print(reduced)\n#[[[78.]]]\n\nexpect(node, inputs=[data, axes], outputs=[reduced], name='test_reduce_sum_default_axes_keepdims_example')\n\nnp.random.seed(0)\ndata = np.random.uniform(-10, 10, shape).astype(np.float32)\nreduced = np.sum(data, axis=None, keepdims=keepdims == 1)\n\nexpect(node, inputs=[data, axes], outputs=[reduced], name='test_reduce_sum_default_axes_keepdims_random')" + }, + { + "summary": "do_not_keepdims", + "code": "shape = [3, 2, 2]\naxes = np.array([1], dtype=np.int64)\nkeepdims = 0\n\nnode = onnx.helper.make_node(\n 'ReduceSum',\n inputs=['data', 'axes'],\n outputs=['reduced'],\n keepdims=keepdims)\n\ndata = np.array([[[1, 2], [3, 4]], [[5, 6], [7, 8]], [[9, 10], [11, 12]]], dtype=np.float32)\nreduced = np.sum(data, axis=tuple(axes.tolist()), keepdims=keepdims == 1)\n#print(reduced)\n#[[4., 6.]\n# [12., 14.]\n# [20., 22.]]\n\nexpect(node, inputs=[data, axes], outputs=[reduced], name='test_reduce_sum_do_not_keepdims_example')\n\nnp.random.seed(0)\ndata = np.random.uniform(-10, 10, shape).astype(np.float32)\nreduced = np.sum(data, axis=tuple(axes.tolist()), keepdims=keepdims == 1)\n\nexpect(node, inputs=[data, axes], outputs=[reduced], name='test_reduce_sum_do_not_keepdims_random')" + }, + { + "summary": "empty_axes_input_noop", + "code": "shape = [3, 2, 2]\nkeepdims = 1\n\nnode = onnx.helper.make_node(\n 'ReduceSum',\n inputs=['data', 'axes'],\n outputs=['reduced'],\n keepdims=keepdims,\n noop_with_empty_axes=True)\n\ndata = np.array([[[1, 2], [3, 4]], [[5, 6], [7, 8]], [[9, 10], [11, 12]]], dtype=np.float32)\naxes = np.array([], dtype=np.int64)\nreduced = np.array(data)\n#print(reduced)\n#[[[1, 2], [3, 4]], [[5, 6], [7, 8]], [[9, 10], [11, 12]]]\n\nexpect(node, inputs=[data, axes], outputs=[reduced],\n name='test_reduce_sum_empty_axes_input_noop_example')\n\nnp.random.seed(0)\ndata = np.random.uniform(-10, 10, shape).astype(np.float32)\nreduced = np.array(data)\n\nexpect(node, inputs=[data, axes], outputs=[reduced], name='test_reduce_sum_negative_axes_keepdims_random')" + }, + { + "summary": "keepdims", + "code": "shape = [3, 2, 2]\naxes = np.array([1], dtype=np.int64)\nkeepdims = 1\n\nnode = onnx.helper.make_node(\n 'ReduceSum',\n inputs=['data', 'axes'],\n outputs=['reduced'],\n keepdims=keepdims)\n\ndata = np.array([[[1, 2], [3, 4]], [[5, 6], [7, 8]], [[9, 10], [11, 12]]], dtype=np.float32)\nreduced = np.sum(data, axis=tuple(axes.tolist()), keepdims=keepdims == 1)\n#print(reduced)\n#[[[4., 6.]]\n# [[12., 14.]]\n# [[20., 22.]]]\n\nexpect(node, inputs=[data, axes], outputs=[reduced], name='test_reduce_sum_keepdims_example')\n\nnp.random.seed(0)\ndata = np.random.uniform(-10, 10, shape).astype(np.float32)\nreduced = np.sum(data, axis=tuple(axes.tolist()), keepdims=keepdims == 1)\n\nexpect(node, inputs=[data, axes], outputs=[reduced], name='test_reduce_sum_keepdims_random')" + }, + { + "summary": "negative_axes_keepdims", + "code": "shape = [3, 2, 2]\naxes = np.array([-2], dtype=np.int64)\nkeepdims = 1\n\nnode = onnx.helper.make_node(\n 'ReduceSum',\n inputs=['data', 'axes'],\n outputs=['reduced'],\n keepdims=keepdims)\n\ndata = np.array([[[1, 2], [3, 4]], [[5, 6], [7, 8]], [[9, 10], [11, 12]]], dtype=np.float32)\nreduced = np.sum(data, axis=tuple(axes.tolist()), keepdims=keepdims == 1)\n# print(reduced)\n#[[[4., 6.]]\n# [[12., 14.]]\n# [[20., 22.]]]\n\nexpect(node, inputs=[data, axes], outputs=[reduced],\n name='test_reduce_sum_negative_axes_keepdims_example')\n\nnp.random.seed(0)\ndata = np.random.uniform(-10, 10, shape).astype(np.float32)\nreduced = np.sum(data, axis=tuple(\n axes.tolist()), keepdims=keepdims == 1)\n\nexpect(node, inputs=[data, axes], outputs=[reduced],\n name='test_reduce_sum_negative_axes_keepdims_random')" + } + ] + }, + { + "name": "ReduceSumSquare", + "module": "ai.onnx", + "version": 1, + "support_level": "common", + "description": "Computes the sum square of the input tensor's element along the provided axes. The resulted\ntensor has the same rank as the input if keepdims equal 1. If keepdims equal 0, then\nthe resulted tensor have the reduced dimension pruned.\n\nThe above behavior is similar to numpy, with the exception that numpy default keepdims to\nFalse instead of True.", + "attributes": [ + { + "name": "axes", + "type": "int64[]", + "required": false, + "description": "A list of integers, along which to reduce. The default is to reduce over all the dimensions of the input tensor." + }, + { + "name": "keepdims", + "type": "int64", + "required": false, + "default": 1, + "description": "Keep the reduced dimension or not, default 1 mean keep reduced dimension." + } + ], + "inputs": [ + { + "name": "data", + "type": "T", + "description": "An input tensor." + } + ], + "min_input": 1, + "max_input": 1, + "outputs": [ + { + "name": "reduced", + "type": "T", + "description": "Reduced output tensor." + } + ], + "min_output": 1, + "max_output": 1, + "type_constraints": [ + { + "description": "Constrain input and output types to high-precision numeric tensors.", + "type_param_str": "T", + "allowed_type_strs": [ + "tensor(uint32)", + "tensor(uint64)", + "tensor(int32)", + "tensor(int64)", + "tensor(float16)", + "tensor(float)", + "tensor(double)" + ] + } + ], + "examples": [ + { + "summary": "default_axes_keepdims", + "code": "shape = [3, 2, 2]\naxes = None\nkeepdims = 1\n\nnode = onnx.helper.make_node(\n 'ReduceSumSquare',\n inputs=['data'],\n outputs=['reduced'],\n keepdims=keepdims)\n\ndata = np.array([[[1, 2], [3, 4]], [[5, 6], [7, 8]], [[9, 10], [11, 12]]], dtype=np.float32)\nreduced = np.sum(np.square(data), axis=axes, keepdims=keepdims == 1)\n#print(reduced)\n#[[[650.]]]\n\nexpect(node, inputs=[data], outputs=[reduced], name='test_reduce_sum_square_default_axes_keepdims_example')\n\nnp.random.seed(0)\ndata = np.random.uniform(-10, 10, shape).astype(np.float32)\nreduced = np.sum(np.square(data), axis=axes, keepdims=keepdims == 1)\n\nexpect(node, inputs=[data], outputs=[reduced], name='test_reduce_sum_square_default_axes_keepdims_random')" + }, + { + "summary": "do_not_keepdims", + "code": "shape = [3, 2, 2]\naxes = [1]\nkeepdims = 0\n\nnode = onnx.helper.make_node(\n 'ReduceSumSquare',\n inputs=['data'],\n outputs=['reduced'],\n axes=axes,\n keepdims=keepdims)\n\ndata = np.array([[[1, 2], [3, 4]], [[5, 6], [7, 8]], [[9, 10], [11, 12]]], dtype=np.float32)\nreduced = np.sum(np.square(data), axis=tuple(axes), keepdims=keepdims == 1)\n#print(reduced)\n#[[10., 20.]\n# [74., 100.]\n# [202., 244.]]\n\nexpect(node, inputs=[data], outputs=[reduced], name='test_reduce_sum_square_do_not_keepdims_example')\n\nnp.random.seed(0)\ndata = np.random.uniform(-10, 10, shape).astype(np.float32)\nreduced = np.sum(np.square(data), axis=tuple(axes), keepdims=keepdims == 1)\n\nexpect(node, inputs=[data], outputs=[reduced], name='test_reduce_sum_square_do_not_keepdims_random')" + }, + { + "summary": "keepdims", + "code": "shape = [3, 2, 2]\naxes = [1]\nkeepdims = 1\n\nnode = onnx.helper.make_node(\n 'ReduceSumSquare',\n inputs=['data'],\n outputs=['reduced'],\n axes=axes,\n keepdims=keepdims)\n\ndata = np.array([[[1, 2], [3, 4]], [[5, 6], [7, 8]], [[9, 10], [11, 12]]], dtype=np.float32)\nreduced = np.sum(np.square(data), axis=tuple(axes), keepdims=keepdims == 1)\n#print(reduced)\n#[[[10., 20.]]\n# [[74., 100.]]\n# [[202., 244.]]]\n\nexpect(node, inputs=[data], outputs=[reduced], name='test_reduce_sum_square_keepdims_example')\n\nnp.random.seed(0)\ndata = np.random.uniform(-10, 10, shape).astype(np.float32)\nreduced = np.sum(np.square(data), axis=tuple(axes), keepdims=keepdims == 1)\n\nexpect(node, inputs=[data], outputs=[reduced], name='test_reduce_sum_square_keepdims_random')" + }, + { + "summary": "negative_axes_keepdims", + "code": "shape = [3, 2, 2]\naxes = [-2]\nkeepdims = 1\n\nnode = onnx.helper.make_node(\n 'ReduceSumSquare',\n inputs=['data'],\n outputs=['reduced'],\n axes=axes,\n keepdims=keepdims)\n\ndata = np.array([[[1, 2], [3, 4]], [[5, 6], [7, 8]], [[9, 10], [11, 12]]], dtype=np.float32)\nreduced = np.sum(np.square(data), axis=tuple(axes), keepdims=keepdims == 1)\n# print(reduced)\n#[[[10., 20.s]]\n# [[74., 100.]]\n# [[202., 244.]]]\n\nexpect(node, inputs=[data], outputs=[reduced], name='test_reduce_sum_square_negative_axes_keepdims_example')\n\nnp.random.seed(0)\ndata = np.random.uniform(-10, 10, shape).astype(np.float32)\nreduced = np.sum(np.square(data), axis=tuple(axes), keepdims=keepdims == 1)\n\nexpect(node, inputs=[data], outputs=[reduced], name='test_reduce_sum_square_negative_axes_keepdims_random')" + } + ] + }, + { + "name": "ReduceSumSquare", + "module": "ai.onnx", + "version": 11, + "support_level": "common", + "description": "Computes the sum square of the input tensor's element along the provided axes. The resulted\ntensor has the same rank as the input if keepdims equal 1. If keepdims equal 0, then\nthe resulted tensor have the reduced dimension pruned.\n\nThe above behavior is similar to numpy, with the exception that numpy default keepdims to\nFalse instead of True.", + "attributes": [ + { + "name": "axes", + "type": "int64[]", + "required": false, + "description": "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)." + }, + { + "name": "keepdims", + "type": "int64", + "required": false, + "default": 1, + "description": "Keep the reduced dimension or not, default 1 mean keep reduced dimension." + } + ], + "inputs": [ + { + "name": "data", + "type": "T", + "description": "An input tensor." + } + ], + "min_input": 1, + "max_input": 1, + "outputs": [ + { + "name": "reduced", + "type": "T", + "description": "Reduced output tensor." + } + ], + "min_output": 1, + "max_output": 1, + "type_constraints": [ + { + "description": "Constrain input and output types to high-precision numeric tensors.", + "type_param_str": "T", + "allowed_type_strs": [ + "tensor(uint32)", + "tensor(uint64)", + "tensor(int32)", + "tensor(int64)", + "tensor(float16)", + "tensor(float)", + "tensor(double)" + ] + } + ], + "examples": [ + { + "summary": "default_axes_keepdims", + "code": "shape = [3, 2, 2]\naxes = None\nkeepdims = 1\n\nnode = onnx.helper.make_node(\n 'ReduceSumSquare',\n inputs=['data'],\n outputs=['reduced'],\n keepdims=keepdims)\n\ndata = np.array([[[1, 2], [3, 4]], [[5, 6], [7, 8]], [[9, 10], [11, 12]]], dtype=np.float32)\nreduced = np.sum(np.square(data), axis=axes, keepdims=keepdims == 1)\n#print(reduced)\n#[[[650.]]]\n\nexpect(node, inputs=[data], outputs=[reduced], name='test_reduce_sum_square_default_axes_keepdims_example')\n\nnp.random.seed(0)\ndata = np.random.uniform(-10, 10, shape).astype(np.float32)\nreduced = np.sum(np.square(data), axis=axes, keepdims=keepdims == 1)\n\nexpect(node, inputs=[data], outputs=[reduced], name='test_reduce_sum_square_default_axes_keepdims_random')" + }, + { + "summary": "do_not_keepdims", + "code": "shape = [3, 2, 2]\naxes = [1]\nkeepdims = 0\n\nnode = onnx.helper.make_node(\n 'ReduceSumSquare',\n inputs=['data'],\n outputs=['reduced'],\n axes=axes,\n keepdims=keepdims)\n\ndata = np.array([[[1, 2], [3, 4]], [[5, 6], [7, 8]], [[9, 10], [11, 12]]], dtype=np.float32)\nreduced = np.sum(np.square(data), axis=tuple(axes), keepdims=keepdims == 1)\n#print(reduced)\n#[[10., 20.]\n# [74., 100.]\n# [202., 244.]]\n\nexpect(node, inputs=[data], outputs=[reduced], name='test_reduce_sum_square_do_not_keepdims_example')\n\nnp.random.seed(0)\ndata = np.random.uniform(-10, 10, shape).astype(np.float32)\nreduced = np.sum(np.square(data), axis=tuple(axes), keepdims=keepdims == 1)\n\nexpect(node, inputs=[data], outputs=[reduced], name='test_reduce_sum_square_do_not_keepdims_random')" + }, + { + "summary": "keepdims", + "code": "shape = [3, 2, 2]\naxes = [1]\nkeepdims = 1\n\nnode = onnx.helper.make_node(\n 'ReduceSumSquare',\n inputs=['data'],\n outputs=['reduced'],\n axes=axes,\n keepdims=keepdims)\n\ndata = np.array([[[1, 2], [3, 4]], [[5, 6], [7, 8]], [[9, 10], [11, 12]]], dtype=np.float32)\nreduced = np.sum(np.square(data), axis=tuple(axes), keepdims=keepdims == 1)\n#print(reduced)\n#[[[10., 20.]]\n# [[74., 100.]]\n# [[202., 244.]]]\n\nexpect(node, inputs=[data], outputs=[reduced], name='test_reduce_sum_square_keepdims_example')\n\nnp.random.seed(0)\ndata = np.random.uniform(-10, 10, shape).astype(np.float32)\nreduced = np.sum(np.square(data), axis=tuple(axes), keepdims=keepdims == 1)\n\nexpect(node, inputs=[data], outputs=[reduced], name='test_reduce_sum_square_keepdims_random')" + }, + { + "summary": "negative_axes_keepdims", + "code": "shape = [3, 2, 2]\naxes = [-2]\nkeepdims = 1\n\nnode = onnx.helper.make_node(\n 'ReduceSumSquare',\n inputs=['data'],\n outputs=['reduced'],\n axes=axes,\n keepdims=keepdims)\n\ndata = np.array([[[1, 2], [3, 4]], [[5, 6], [7, 8]], [[9, 10], [11, 12]]], dtype=np.float32)\nreduced = np.sum(np.square(data), axis=tuple(axes), keepdims=keepdims == 1)\n# print(reduced)\n#[[[10., 20.s]]\n# [[74., 100.]]\n# [[202., 244.]]]\n\nexpect(node, inputs=[data], outputs=[reduced], name='test_reduce_sum_square_negative_axes_keepdims_example')\n\nnp.random.seed(0)\ndata = np.random.uniform(-10, 10, shape).astype(np.float32)\nreduced = np.sum(np.square(data), axis=tuple(axes), keepdims=keepdims == 1)\n\nexpect(node, inputs=[data], outputs=[reduced], name='test_reduce_sum_square_negative_axes_keepdims_random')" + } + ] + }, + { + "name": "ReduceSumSquare", + "module": "ai.onnx", + "version": 13, + "support_level": "common", + "description": "Computes the sum square of the input tensor's element along the provided axes. The resulted\ntensor has the same rank as the input if keepdims equal 1. If keepdims equal 0, then\nthe resulted tensor have the reduced dimension pruned.\n\nThe above behavior is similar to numpy, with the exception that numpy default keepdims to\nFalse instead of True.", + "attributes": [ + { + "name": "axes", + "type": "int64[]", + "required": false, + "description": "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)." + }, + { + "name": "keepdims", + "type": "int64", + "required": false, + "default": 1, + "description": "Keep the reduced dimension or not, default 1 mean keep reduced dimension." + } + ], + "inputs": [ + { + "name": "data", + "type": "T", + "description": "An input tensor." + } + ], + "min_input": 1, + "max_input": 1, + "outputs": [ + { + "name": "reduced", + "type": "T", + "description": "Reduced output tensor." + } + ], + "min_output": 1, + "max_output": 1, + "type_constraints": [ + { + "description": "Constrain input and output types to high-precision numeric tensors.", + "type_param_str": "T", + "allowed_type_strs": [ + "tensor(uint32)", + "tensor(uint64)", + "tensor(int32)", + "tensor(int64)", + "tensor(float16)", + "tensor(float)", + "tensor(double)", + "tensor(bfloat16)" + ] + } + ], + "examples": [ + { + "summary": "default_axes_keepdims", + "code": "shape = [3, 2, 2]\naxes = None\nkeepdims = 1\n\nnode = onnx.helper.make_node(\n 'ReduceSumSquare',\n inputs=['data'],\n outputs=['reduced'],\n keepdims=keepdims)\n\ndata = np.array([[[1, 2], [3, 4]], [[5, 6], [7, 8]], [[9, 10], [11, 12]]], dtype=np.float32)\nreduced = np.sum(np.square(data), axis=axes, keepdims=keepdims == 1)\n#print(reduced)\n#[[[650.]]]\n\nexpect(node, inputs=[data], outputs=[reduced], name='test_reduce_sum_square_default_axes_keepdims_example')\n\nnp.random.seed(0)\ndata = np.random.uniform(-10, 10, shape).astype(np.float32)\nreduced = np.sum(np.square(data), axis=axes, keepdims=keepdims == 1)\n\nexpect(node, inputs=[data], outputs=[reduced], name='test_reduce_sum_square_default_axes_keepdims_random')" + }, + { + "summary": "do_not_keepdims", + "code": "shape = [3, 2, 2]\naxes = [1]\nkeepdims = 0\n\nnode = onnx.helper.make_node(\n 'ReduceSumSquare',\n inputs=['data'],\n outputs=['reduced'],\n axes=axes,\n keepdims=keepdims)\n\ndata = np.array([[[1, 2], [3, 4]], [[5, 6], [7, 8]], [[9, 10], [11, 12]]], dtype=np.float32)\nreduced = np.sum(np.square(data), axis=tuple(axes), keepdims=keepdims == 1)\n#print(reduced)\n#[[10., 20.]\n# [74., 100.]\n# [202., 244.]]\n\nexpect(node, inputs=[data], outputs=[reduced], name='test_reduce_sum_square_do_not_keepdims_example')\n\nnp.random.seed(0)\ndata = np.random.uniform(-10, 10, shape).astype(np.float32)\nreduced = np.sum(np.square(data), axis=tuple(axes), keepdims=keepdims == 1)\n\nexpect(node, inputs=[data], outputs=[reduced], name='test_reduce_sum_square_do_not_keepdims_random')" + }, + { + "summary": "keepdims", + "code": "shape = [3, 2, 2]\naxes = [1]\nkeepdims = 1\n\nnode = onnx.helper.make_node(\n 'ReduceSumSquare',\n inputs=['data'],\n outputs=['reduced'],\n axes=axes,\n keepdims=keepdims)\n\ndata = np.array([[[1, 2], [3, 4]], [[5, 6], [7, 8]], [[9, 10], [11, 12]]], dtype=np.float32)\nreduced = np.sum(np.square(data), axis=tuple(axes), keepdims=keepdims == 1)\n#print(reduced)\n#[[[10., 20.]]\n# [[74., 100.]]\n# [[202., 244.]]]\n\nexpect(node, inputs=[data], outputs=[reduced], name='test_reduce_sum_square_keepdims_example')\n\nnp.random.seed(0)\ndata = np.random.uniform(-10, 10, shape).astype(np.float32)\nreduced = np.sum(np.square(data), axis=tuple(axes), keepdims=keepdims == 1)\n\nexpect(node, inputs=[data], outputs=[reduced], name='test_reduce_sum_square_keepdims_random')" + }, + { + "summary": "negative_axes_keepdims", + "code": "shape = [3, 2, 2]\naxes = [-2]\nkeepdims = 1\n\nnode = onnx.helper.make_node(\n 'ReduceSumSquare',\n inputs=['data'],\n outputs=['reduced'],\n axes=axes,\n keepdims=keepdims)\n\ndata = np.array([[[1, 2], [3, 4]], [[5, 6], [7, 8]], [[9, 10], [11, 12]]], dtype=np.float32)\nreduced = np.sum(np.square(data), axis=tuple(axes), keepdims=keepdims == 1)\n# print(reduced)\n#[[[10., 20.s]]\n# [[74., 100.]]\n# [[202., 244.]]]\n\nexpect(node, inputs=[data], outputs=[reduced], name='test_reduce_sum_square_negative_axes_keepdims_example')\n\nnp.random.seed(0)\ndata = np.random.uniform(-10, 10, shape).astype(np.float32)\nreduced = np.sum(np.square(data), axis=tuple(axes), keepdims=keepdims == 1)\n\nexpect(node, inputs=[data], outputs=[reduced], name='test_reduce_sum_square_negative_axes_keepdims_random')" + } + ] + }, + { + "name": "Relu", + "module": "ai.onnx", + "version": 1, + "support_level": "common", + "description": "Relu takes one input data (Tensor) and produces one output data\n(Tensor) where the rectified linear function, y = max(0, x), is applied to\nthe tensor elementwise.\n", + "attributes": [ + { + "name": "consumed_inputs", + "type": "int64[]", + "required": false, + "description": "legacy optimization attribute." + } + ], + "inputs": [ + { + "name": "X", + "type": "T", + "description": "Input tensor" + } + ], + "min_input": 1, + "max_input": 1, + "outputs": [ + { + "name": "Y", + "type": "T", + "description": "Output tensor" + } + ], + "min_output": 1, + "max_output": 1, + "type_constraints": [ + { + "description": "Constrain input and output types to float tensors.", + "type_param_str": "T", + "allowed_type_strs": [ + "tensor(float16)", + "tensor(float)", + "tensor(double)" + ] + } + ], + "examples": [ + { + "summary": "relu", + "code": "node = onnx.helper.make_node(\n 'Relu',\n inputs=['x'],\n outputs=['y'],\n)\nx = np.random.randn(3, 4, 5).astype(np.float32)\ny = np.clip(x, 0, np.inf)\n\nexpect(node, inputs=[x], outputs=[y],\n name='test_relu')" + } + ], + "category": "Activation" + }, + { + "name": "Relu", + "module": "ai.onnx", + "version": 6, + "support_level": "common", + "description": "Relu takes one input data (Tensor) and produces one output data\n(Tensor) where the rectified linear function, y = max(0, x), is applied to\nthe tensor elementwise.\n", + "inputs": [ + { + "name": "X", + "type": "T", + "description": "Input tensor" + } + ], + "min_input": 1, + "max_input": 1, + "outputs": [ + { + "name": "Y", + "type": "T", + "description": "Output tensor" + } + ], + "min_output": 1, + "max_output": 1, + "type_constraints": [ + { + "description": "Constrain input and output types to float tensors.", + "type_param_str": "T", + "allowed_type_strs": [ + "tensor(float16)", + "tensor(float)", + "tensor(double)" + ] + } + ], + "examples": [ + { + "summary": "relu", + "code": "node = onnx.helper.make_node(\n 'Relu',\n inputs=['x'],\n outputs=['y'],\n)\nx = np.random.randn(3, 4, 5).astype(np.float32)\ny = np.clip(x, 0, np.inf)\n\nexpect(node, inputs=[x], outputs=[y],\n name='test_relu')" + } + ], + "category": "Activation" + }, + { + "name": "Relu", + "module": "ai.onnx", + "version": 13, + "support_level": "common", + "description": "Relu takes one input data (Tensor) and produces one output data\n(Tensor) where the rectified linear function, y = max(0, x), is applied to\nthe tensor elementwise.\n", + "inputs": [ + { + "name": "X", + "type": "T", + "description": "Input tensor" + } + ], + "min_input": 1, + "max_input": 1, + "outputs": [ + { + "name": "Y", + "type": "T", + "description": "Output tensor" + } + ], + "min_output": 1, + "max_output": 1, + "type_constraints": [ + { + "description": "Constrain input and output types to float tensors.", + "type_param_str": "T", + "allowed_type_strs": [ + "tensor(float16)", + "tensor(float)", + "tensor(double)", + "tensor(bfloat16)" + ] + } + ], + "examples": [ + { + "summary": "relu", + "code": "node = onnx.helper.make_node(\n 'Relu',\n inputs=['x'],\n outputs=['y'],\n)\nx = np.random.randn(3, 4, 5).astype(np.float32)\ny = np.clip(x, 0, np.inf)\n\nexpect(node, inputs=[x], outputs=[y],\n name='test_relu')" + } + ], + "category": "Activation" + }, + { + "name": "Relu", + "module": "ai.onnx", + "version": 14, + "support_level": "common", + "description": "Relu takes one input data (Tensor) and produces one output data\n(Tensor) where the rectified linear function, y = max(0, x), is applied to\nthe tensor elementwise.\n", + "inputs": [ + { + "name": "X", + "type": "T", + "description": "Input tensor" + } + ], + "min_input": 1, + "max_input": 1, + "outputs": [ + { + "name": "Y", + "type": "T", + "description": "Output tensor" + } + ], + "min_output": 1, + "max_output": 1, + "type_constraints": [ + { + "description": "Constrain input and output types to signed numeric tensors.", + "type_param_str": "T", + "allowed_type_strs": [ + "tensor(float)", + "tensor(int32)", + "tensor(int8)", + "tensor(int16)", + "tensor(int64)", + "tensor(float16)", + "tensor(double)", + "tensor(bfloat16)" + ] + } + ], + "examples": [ + { + "summary": "relu", + "code": "node = onnx.helper.make_node(\n 'Relu',\n inputs=['x'],\n outputs=['y'],\n)\nx = np.random.randn(3, 4, 5).astype(np.float32)\ny = np.clip(x, 0, np.inf)\n\nexpect(node, inputs=[x], outputs=[y],\n name='test_relu')" + } + ], + "category": "Activation" + }, + { + "name": "Reshape", + "module": "ai.onnx", + "version": 1, + "support_level": "common", + "description": "Reshape the input tensor similar to numpy.reshape.\nIt takes a tensor as input and an argument `shape`. It outputs the reshaped tensor.\nAt most one dimension of the new shape can be -1. In this case, the value is\ninferred from the size of the tensor and the remaining dimensions. A dimension\ncould also be 0, in which case the actual dimension value is unchanged (i.e. taken\nfrom the input tensor).", + "attributes": [ + { + "name": "consumed_inputs", + "type": "int64[]", + "required": false, + "description": "legacy optimization attribute." + }, + { + "name": "shape", + "type": "int64[]", + "required": false, + "description": "New shape" + } + ], + "inputs": [ + { + "name": "data", + "type": "T", + "description": "An input tensor." + } + ], + "min_input": 1, + "max_input": 1, + "outputs": [ + { + "name": "reshaped", + "type": "T", + "description": "Reshaped data." + } + ], + "min_output": 1, + "max_output": 1, + "type_constraints": [ + { + "description": "Constrain input and output types to float tensors.", + "type_param_str": "T", + "allowed_type_strs": [ + "tensor(float16)", + "tensor(float)", + "tensor(double)" + ] + } + ], + "examples": [ + { + "summary": "allowzero", + "code": "original_shape = [0, 3, 4]\ntest_cases = {\n 'allowzero_reordered': np.array([3, 4, 0], dtype=np.int64),\n}\ndata = np.random.random_sample(original_shape).astype(np.float32)\n\nfor test_name, shape in test_cases.items():\n node = onnx.helper.make_node(\n 'Reshape',\n inputs=['data', 'shape'],\n outputs=['reshaped'],\n allowzero=1, # if allowzero=1, final shape = (3, 4, 0)\n # if allowzero=0, final shape = (3, 4, 4)\n )\n\n reshaped = reshape_reference_implementation(data, shape, allowzero=1)\n\n expect(node, inputs=[data, shape], outputs=[reshaped],\n name='test_reshape_' + test_name)" + }, + { + "summary": "reshape", + "code": "original_shape = [2, 3, 4]\ntest_cases = {\n 'reordered_all_dims': np.array([4, 2, 3], dtype=np.int64),\n 'reordered_last_dims': np.array([2, 4, 3], dtype=np.int64),\n 'reduced_dims': np.array([2, 12], dtype=np.int64),\n 'extended_dims': np.array([2, 3, 2, 2], dtype=np.int64),\n 'one_dim': np.array([24], dtype=np.int64),\n 'negative_dim': np.array([2, -1, 2], dtype=np.int64),\n 'negative_extended_dims': np.array([-1, 2, 3, 4], dtype=np.int64),\n 'zero_dim': np.array([2, 0, 4, 1], dtype=np.int64),\n 'zero_and_negative_dim': np.array([2, 0, 1, -1], dtype=np.int64),\n}\ndata = np.random.random_sample(original_shape).astype(np.float32)\n\nfor test_name, shape in test_cases.items():\n node = onnx.helper.make_node(\n 'Reshape',\n inputs=['data', 'shape'],\n outputs=['reshaped'],\n )\n\n reshaped = reshape_reference_implementation(data, shape)\n\n expect(node, inputs=[data, shape], outputs=[reshaped],\n name='test_reshape_' + test_name)" + } + ], + "category": "Shape" + }, + { + "name": "Reshape", + "module": "ai.onnx", + "version": 5, + "support_level": "common", + "description": "Reshape the input tensor similar to numpy.reshape.\nFirst input is the data tensor, second input is a shape tensor which specifies the output shape. It outputs the reshaped tensor.\nAt most one dimension of the new shape can be -1. In this case, the value is\ninferred from the size of the tensor and the remaining dimensions. A dimension\ncould also be 0, in which case the actual dimension value is unchanged (i.e. taken\nfrom the input tensor).", + "inputs": [ + { + "name": "data", + "type": "T", + "description": "An input tensor." + }, + { + "name": "shape", + "type": "tensor(int64)", + "description": "Specified shape for output." + } + ], + "min_input": 2, + "max_input": 2, + "outputs": [ + { + "name": "reshaped", + "type": "T", + "description": "Reshaped data." + } + ], + "min_output": 1, + "max_output": 1, + "type_constraints": [ + { + "description": "Constrain input and output types to all tensor types.", + "type_param_str": "T", + "allowed_type_strs": [ + "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)" + ] + } + ], + "examples": [ + { + "summary": "allowzero", + "code": "original_shape = [0, 3, 4]\ntest_cases = {\n 'allowzero_reordered': np.array([3, 4, 0], dtype=np.int64),\n}\ndata = np.random.random_sample(original_shape).astype(np.float32)\n\nfor test_name, shape in test_cases.items():\n node = onnx.helper.make_node(\n 'Reshape',\n inputs=['data', 'shape'],\n outputs=['reshaped'],\n allowzero=1, # if allowzero=1, final shape = (3, 4, 0)\n # if allowzero=0, final shape = (3, 4, 4)\n )\n\n reshaped = reshape_reference_implementation(data, shape, allowzero=1)\n\n expect(node, inputs=[data, shape], outputs=[reshaped],\n name='test_reshape_' + test_name)" + }, + { + "summary": "reshape", + "code": "original_shape = [2, 3, 4]\ntest_cases = {\n 'reordered_all_dims': np.array([4, 2, 3], dtype=np.int64),\n 'reordered_last_dims': np.array([2, 4, 3], dtype=np.int64),\n 'reduced_dims': np.array([2, 12], dtype=np.int64),\n 'extended_dims': np.array([2, 3, 2, 2], dtype=np.int64),\n 'one_dim': np.array([24], dtype=np.int64),\n 'negative_dim': np.array([2, -1, 2], dtype=np.int64),\n 'negative_extended_dims': np.array([-1, 2, 3, 4], dtype=np.int64),\n 'zero_dim': np.array([2, 0, 4, 1], dtype=np.int64),\n 'zero_and_negative_dim': np.array([2, 0, 1, -1], dtype=np.int64),\n}\ndata = np.random.random_sample(original_shape).astype(np.float32)\n\nfor test_name, shape in test_cases.items():\n node = onnx.helper.make_node(\n 'Reshape',\n inputs=['data', 'shape'],\n outputs=['reshaped'],\n )\n\n reshaped = reshape_reference_implementation(data, shape)\n\n expect(node, inputs=[data, shape], outputs=[reshaped],\n name='test_reshape_' + test_name)" + } + ], + "category": "Shape" + }, + { + "name": "Reshape", + "module": "ai.onnx", + "version": 13, + "support_level": "common", + "description": "Reshape the input tensor similar to numpy.reshape.\nFirst input is the data tensor, second input is a shape tensor which specifies the output shape. It outputs the reshaped tensor.\nAt most one dimension of the new shape can be -1. In this case, the value is\ninferred from the size of the tensor and the remaining dimensions. A dimension\ncould also be 0, in which case the actual dimension value is unchanged (i.e. taken\nfrom the input tensor).", + "inputs": [ + { + "name": "data", + "type": "T", + "description": "An input tensor." + }, + { + "name": "shape", + "type": "tensor(int64)", + "description": "Specified shape for output." + } + ], + "min_input": 2, + "max_input": 2, + "outputs": [ + { + "name": "reshaped", + "type": "T", + "description": "Reshaped data." + } + ], + "min_output": 1, + "max_output": 1, + "type_constraints": [ + { + "description": "Constrain input and output types to all tensor types.", + "type_param_str": "T", + "allowed_type_strs": [ + "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)" + ] + } + ], + "examples": [ + { + "summary": "allowzero", + "code": "original_shape = [0, 3, 4]\ntest_cases = {\n 'allowzero_reordered': np.array([3, 4, 0], dtype=np.int64),\n}\ndata = np.random.random_sample(original_shape).astype(np.float32)\n\nfor test_name, shape in test_cases.items():\n node = onnx.helper.make_node(\n 'Reshape',\n inputs=['data', 'shape'],\n outputs=['reshaped'],\n allowzero=1, # if allowzero=1, final shape = (3, 4, 0)\n # if allowzero=0, final shape = (3, 4, 4)\n )\n\n reshaped = reshape_reference_implementation(data, shape, allowzero=1)\n\n expect(node, inputs=[data, shape], outputs=[reshaped],\n name='test_reshape_' + test_name)" + }, + { + "summary": "reshape", + "code": "original_shape = [2, 3, 4]\ntest_cases = {\n 'reordered_all_dims': np.array([4, 2, 3], dtype=np.int64),\n 'reordered_last_dims': np.array([2, 4, 3], dtype=np.int64),\n 'reduced_dims': np.array([2, 12], dtype=np.int64),\n 'extended_dims': np.array([2, 3, 2, 2], dtype=np.int64),\n 'one_dim': np.array([24], dtype=np.int64),\n 'negative_dim': np.array([2, -1, 2], dtype=np.int64),\n 'negative_extended_dims': np.array([-1, 2, 3, 4], dtype=np.int64),\n 'zero_dim': np.array([2, 0, 4, 1], dtype=np.int64),\n 'zero_and_negative_dim': np.array([2, 0, 1, -1], dtype=np.int64),\n}\ndata = np.random.random_sample(original_shape).astype(np.float32)\n\nfor test_name, shape in test_cases.items():\n node = onnx.helper.make_node(\n 'Reshape',\n inputs=['data', 'shape'],\n outputs=['reshaped'],\n )\n\n reshaped = reshape_reference_implementation(data, shape)\n\n expect(node, inputs=[data, shape], outputs=[reshaped],\n name='test_reshape_' + test_name)" + } + ], + "category": "Shape" + }, + { + "name": "Reshape", + "module": "ai.onnx", + "version": 14, + "support_level": "common", + "description": "Reshape the input tensor similar to numpy.reshape.\nFirst input is the data tensor, second input is a shape tensor which specifies the output shape. It outputs the reshaped tensor.\nAt most one dimension of the new shape can be -1. In this case, the value is\ninferred from the size of the tensor and the remaining dimensions. A dimension\ncould also be 0, in which case the actual dimension value is unchanged (i.e. taken\nfrom the input tensor). If 'allowzero' is set, and the new shape includes 0, the\ndimension will be set explicitly to zero (i.e. not taken from input tensor)", + "attributes": [ + { + "name": "allowzero", + "type": "int64", + "required": false, + "description": "(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": [ + { + "name": "data", + "type": "T", + "description": "An input tensor." + }, + { + "name": "shape", + "type": "tensor(int64)", + "description": "Specified shape for output." + } + ], + "min_input": 2, + "max_input": 2, + "outputs": [ + { + "name": "reshaped", + "type": "T", + "description": "Reshaped data." + } + ], + "min_output": 1, + "max_output": 1, + "type_constraints": [ + { + "description": "Constrain input and output types to all tensor types.", + "type_param_str": "T", + "allowed_type_strs": [ + "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)" + ] + } + ], + "examples": [ + { + "summary": "allowzero", + "code": "original_shape = [0, 3, 4]\ntest_cases = {\n 'allowzero_reordered': np.array([3, 4, 0], dtype=np.int64),\n}\ndata = np.random.random_sample(original_shape).astype(np.float32)\n\nfor test_name, shape in test_cases.items():\n node = onnx.helper.make_node(\n 'Reshape',\n inputs=['data', 'shape'],\n outputs=['reshaped'],\n allowzero=1, # if allowzero=1, final shape = (3, 4, 0)\n # if allowzero=0, final shape = (3, 4, 4)\n )\n\n reshaped = reshape_reference_implementation(data, shape, allowzero=1)\n\n expect(node, inputs=[data, shape], outputs=[reshaped],\n name='test_reshape_' + test_name)" + }, + { + "summary": "reshape", + "code": "original_shape = [2, 3, 4]\ntest_cases = {\n 'reordered_all_dims': np.array([4, 2, 3], dtype=np.int64),\n 'reordered_last_dims': np.array([2, 4, 3], dtype=np.int64),\n 'reduced_dims': np.array([2, 12], dtype=np.int64),\n 'extended_dims': np.array([2, 3, 2, 2], dtype=np.int64),\n 'one_dim': np.array([24], dtype=np.int64),\n 'negative_dim': np.array([2, -1, 2], dtype=np.int64),\n 'negative_extended_dims': np.array([-1, 2, 3, 4], dtype=np.int64),\n 'zero_dim': np.array([2, 0, 4, 1], dtype=np.int64),\n 'zero_and_negative_dim': np.array([2, 0, 1, -1], dtype=np.int64),\n}\ndata = np.random.random_sample(original_shape).astype(np.float32)\n\nfor test_name, shape in test_cases.items():\n node = onnx.helper.make_node(\n 'Reshape',\n inputs=['data', 'shape'],\n outputs=['reshaped'],\n )\n\n reshaped = reshape_reference_implementation(data, shape)\n\n expect(node, inputs=[data, shape], outputs=[reshaped],\n name='test_reshape_' + test_name)" + } + ], + "category": "Shape" + }, + { + "name": "Resize", + "module": "ai.onnx", + "version": 10, + "support_level": "common", + "description": "Resize the input tensor.\nEach dimension value of the output tensor is:\n output_dimension = floor(input_dimension * scale).\n", + "attributes": [ + { + "name": "mode", + "type": "string", + "required": false, + "default": "nearest", + "description": "Two interpolation modes: nearest (default), and linear (including bilinear, trilinear, etc)" + } + ], + "inputs": [ + { + "name": "X", + "type": "T", + "description": "N-D tensor" + }, + { + "name": "scales", + "type": "tensor(float)", + "description": "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'." + } + ], + "min_input": 2, + "max_input": 2, + "outputs": [ + { + "name": "Y", + "type": "T", + "description": "N-D tensor after resizing" + } + ], + "min_output": 1, + "max_output": 1, + "type_constraints": [ + { + "description": "Constrain input 'X' and output 'Y' to all tensor types.", + "type_param_str": "T", + "allowed_type_strs": [ + "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)" + ] + } + ], + "examples": [ + { + "summary": "resize_downsample_scales_cubic", + "code": "node = onnx.helper.make_node(\n 'Resize',\n inputs=['X', '', 'scales'],\n outputs=['Y'],\n mode='cubic',\n)\n\ndata = np.array([[[\n [1, 2, 3, 4],\n [5, 6, 7, 8],\n [9, 10, 11, 12],\n [13, 14, 15, 16],\n]]], dtype=np.float32)\n\nscales = np.array([1.0, 1.0, 0.8, 0.8], dtype=np.float32)\n\n# [[[[ 1.47119141 2.78125 4.08251953]\n# [ 6.71142578 8.02148438 9.32275391]\n# [11.91650391 13.2265625 14.52783203]]]]\noutput = interpolate_nd(\n data, cubic_coeffs, scale_factors=scales).astype(np.float32)\n\nexpect(node, inputs=[data, scales], outputs=[output],\n name='test_resize_downsample_scales_cubic')" + }, + { + "summary": "resize_downsample_scales_cubic_A_n0p5_exclude_outside", + "code": "node = onnx.helper.make_node(\n 'Resize',\n inputs=['X', '', 'scales'],\n outputs=['Y'],\n mode='cubic',\n cubic_coeff_a=-0.5,\n exclude_outside=True\n)\n\ndata = np.array([[[\n [1, 2, 3, 4],\n [5, 6, 7, 8],\n [9, 10, 11, 12],\n [13, 14, 15, 16],\n]]], dtype=np.float32)\n\nscales = np.array([1.0, 1.0, 0.8, 0.8], dtype=np.float32)\n\n# [[[[ 1.36812675 2.6695014 4.0133367 ]\n# [ 6.57362535 7.875 9.2188353 ]\n# [11.94896657 13.25034122 14.59417652]]]]\noutput = interpolate_nd(data, lambda x: cubic_coeffs(x, A=-0.5), scale_factors=scales,\n exclude_outside=True).astype(np.float32)\n\nexpect(node, inputs=[data, scales], outputs=[output],\n name='test_resize_downsample_scales_cubic_A_n0p5_exclude_outside')" + }, + { + "summary": "resize_downsample_scales_cubic_align_corners", + "code": "node = onnx.helper.make_node(\n 'Resize',\n inputs=['X', '', 'scales'],\n outputs=['Y'],\n mode='cubic',\n coordinate_transformation_mode='align_corners'\n)\n\ndata = np.array([[[\n [1, 2, 3, 4],\n [5, 6, 7, 8],\n [9, 10, 11, 12],\n [13, 14, 15, 16],\n]]], dtype=np.float32)\n\nscales = np.array([1.0, 1.0, 0.8, 0.8], dtype=np.float32)\n\n# [[[[ 1. 2.39519159 3.79038317]\n# [ 6.58076634 7.97595793 9.37114951]\n# [12.16153268 13.55672427 14.95191585]]]]\noutput = interpolate_nd(\n data, cubic_coeffs, scale_factors=scales, coordinate_transformation_mode='align_corners').astype(np.float32)\n\nexpect(node, inputs=[data, scales], outputs=[output],\n name='test_resize_downsample_scales_cubic_align_corners')" + }, + { + "summary": "resize_downsample_scales_linear", + "code": "node = onnx.helper.make_node(\n 'Resize',\n inputs=['X', '', 'scales'],\n outputs=['Y'],\n mode='linear',\n)\n\ndata = np.array([[[\n [1, 2, 3, 4],\n [5, 6, 7, 8],\n]]], dtype=np.float32)\n\nscales = np.array([1.0, 1.0, 0.6, 0.6], dtype=np.float32)\n\n# [[[[2.6666665 4.3333331]]]]\noutput = interpolate_nd(\n data, linear_coeffs, scale_factors=scales).astype(np.float32)\n\nexpect(node, inputs=[data, scales], outputs=[output],\n name='test_resize_downsample_scales_linear')" + }, + { + "summary": "resize_downsample_scales_linear_align_corners", + "code": "node = onnx.helper.make_node(\n 'Resize',\n inputs=['X', '', 'scales'],\n outputs=['Y'],\n mode='linear',\n coordinate_transformation_mode='align_corners'\n)\n\ndata = np.array([[[\n [1, 2, 3, 4],\n [5, 6, 7, 8],\n]]], dtype=np.float32)\n\nscales = np.array([1.0, 1.0, 0.6, 0.6], dtype=np.float32)\n\n# [[[[1. 3.142857]]]]\noutput = interpolate_nd(\n data, linear_coeffs, scale_factors=scales, coordinate_transformation_mode='align_corners').astype(np.float32)\n\nexpect(node, inputs=[data, scales], outputs=[output],\n name='test_resize_downsample_scales_linear_align_corners')" + }, + { + "summary": "resize_downsample_scales_nearest", + "code": "node = onnx.helper.make_node(\n 'Resize',\n inputs=['X', '', 'scales'],\n outputs=['Y'],\n mode='nearest',\n)\n\ndata = np.array([[[\n [1, 2, 3, 4],\n [5, 6, 7, 8],\n]]], dtype=np.float32)\n\nscales = np.array([1.0, 1.0, 0.6, 0.6], dtype=np.float32)\n\n# [[[[1. 3.]]]]\noutput = interpolate_nd(\n data, nearest_coeffs, scale_factors=scales).astype(np.float32)\n\nexpect(node, inputs=[data, scales], outputs=[output],\n name='test_resize_downsample_scales_nearest')" + }, + { + "summary": "resize_downsample_sizes_cubic", + "code": "node = onnx.helper.make_node(\n 'Resize',\n inputs=['X', '', '', 'sizes'],\n outputs=['Y'],\n mode='cubic',\n)\n\ndata = np.array([[[\n [1, 2, 3, 4],\n [5, 6, 7, 8],\n [9, 10, 11, 12],\n [13, 14, 15, 16],\n]]], dtype=np.float32)\n\nsizes = np.array([1, 1, 3, 3], dtype=np.int64)\n\n# [[[[ 1.63078704 3.00462963 4.37847222]\n# [ 7.12615741 8.5 9.87384259]\n# [12.62152778 13.99537037 15.36921296]]]]\noutput = interpolate_nd(\n data, cubic_coeffs, output_size=sizes).astype(np.float32)\n\nexpect(node, inputs=[data, sizes], outputs=[output],\n name='test_resize_downsample_sizes_cubic')" + }, + { + "summary": "resize_downsample_sizes_linear_pytorch_half_pixel", + "code": "node = onnx.helper.make_node(\n 'Resize',\n inputs=['X', '', '', 'sizes'],\n outputs=['Y'],\n mode='linear',\n coordinate_transformation_mode='pytorch_half_pixel'\n)\n\ndata = np.array([[[\n [1, 2, 3, 4],\n [5, 6, 7, 8],\n [9, 10, 11, 12],\n [13, 14, 15, 16],\n]]], dtype=np.float32)\n\nsizes = np.array([1, 1, 3, 1], dtype=np.int64)\n\n# [[[[ 1.6666666]\n# [ 7. ]\n# [12.333333 ]]]]\noutput = interpolate_nd(\n data, linear_coeffs, output_size=sizes, coordinate_transformation_mode='pytorch_half_pixel').astype(np.float32)\n\nexpect(node, inputs=[data, sizes], outputs=[output],\n name='test_resize_downsample_sizes_linear_pytorch_half_pixel')" + }, + { + "summary": "resize_downsample_sizes_nearest", + "code": "node = onnx.helper.make_node(\n 'Resize',\n inputs=['X', '', '', 'sizes'],\n outputs=['Y'],\n mode='nearest',\n)\n\ndata = np.array([[[\n [1, 2, 3, 4],\n [5, 6, 7, 8],\n]]], dtype=np.float32)\n\nsizes = np.array([1, 1, 1, 3], dtype=np.int64)\n\n# [[[[1. 3.]]]]\noutput = interpolate_nd(\n data, nearest_coeffs, output_size=sizes).astype(np.float32)\n\nexpect(node, inputs=[data, sizes], outputs=[output],\n name='test_resize_downsample_sizes_nearest')" + }, + { + "summary": "resize_tf_crop_and_resize", + "code": "node = onnx.helper.make_node(\n 'Resize',\n inputs=['X', 'roi', '', 'sizes'],\n outputs=['Y'],\n mode='linear',\n coordinate_transformation_mode='tf_crop_and_resize'\n)\n\ndata = np.array([[[\n [1, 2, 3, 4],\n [5, 6, 7, 8],\n [9, 10, 11, 12],\n [13, 14, 15, 16],\n]]], dtype=np.float32)\n\n# Note: for some rois, the result may be different with that of TF for inaccurate floating point\nroi = np.array([0, 0, 0.4, 0.6, 1, 1, 0.6, 0.8], dtype=np.float32)\nsizes = np.array([1, 1, 3, 3], dtype=np.int64)\n\n# [[[[ 7.6000004 7.9 8.2 ]\n# [ 8.8 9.1 9.400001 ]\n# [10. 10.3 10.6 ]]]]\noutput = interpolate_nd(data, linear_coeffs, output_size=sizes, roi=roi,\n coordinate_transformation_mode='tf_crop_and_resize').astype(np.float32)\n\nexpect(node, inputs=[data, roi, sizes], outputs=[output],\n name='test_resize_tf_crop_and_resize')" + }, + { + "summary": "resize_tf_crop_and_resize_extrapolation_value", + "code": "node = onnx.helper.make_node(\n 'Resize',\n inputs=['X', 'roi', '', 'sizes'],\n outputs=['Y'],\n mode='linear',\n coordinate_transformation_mode='tf_crop_and_resize',\n extrapolation_value=10.0\n)\n\ndata = np.array([[[\n [1, 2, 3, 4],\n [5, 6, 7, 8],\n [9, 10, 11, 12],\n [13, 14, 15, 16],\n]]], dtype=np.float32)\n\n# Note: for some rois, the result may be different with that of TF for inaccurate floating point\nroi = np.array([0, 0, 0.4, 0.6, 1, 1, 1.2, 1.7], dtype=np.float32)\nsizes = np.array([1, 1, 3, 3], dtype=np.int64)\n\n# [[[[ 7.6000004 10. 10. ]\n# [12.400001 10. 10. ]\n# [10. 10. 10. ]]]]\noutput = interpolate_nd(data, linear_coeffs, output_size=sizes, roi=roi,\n coordinate_transformation_mode='tf_crop_and_resize', extrapolation_value=10.0).astype(np.float32)\n\nexpect(node, inputs=[data, roi, sizes], outputs=[output],\n name='test_resize_tf_crop_and_resize')" + }, + { + "summary": "resize_upsample_scales_cubic", + "code": "node = onnx.helper.make_node(\n 'Resize',\n inputs=['X', '', 'scales'],\n outputs=['Y'],\n mode='cubic',\n)\n\ndata = np.array([[[\n [1, 2, 3, 4],\n [5, 6, 7, 8],\n [9, 10, 11, 12],\n [13, 14, 15, 16],\n]]], dtype=np.float32)\n\nscales = np.array([1.0, 1.0, 2.0, 2.0], dtype=np.float32)\n\n# [[[[ 0.47265625 0.76953125 1.24609375 1.875 2.28125\n# 2.91015625 3.38671875 3.68359375]\n# [ 1.66015625 1.95703125 2.43359375 3.0625 3.46875\n# 4.09765625 4.57421875 4.87109375]\n# [ 3.56640625 3.86328125 4.33984375 4.96875 5.375\n# 6.00390625 6.48046875 6.77734375]\n# [ 6.08203125 6.37890625 6.85546875 7.484375 7.890625\n# 8.51953125 8.99609375 9.29296875]\n# [ 7.70703125 8.00390625 8.48046875 9.109375 9.515625\n# 10.14453125 10.62109375 10.91796875]\n# [10.22265625 10.51953125 10.99609375 11.625 12.03125\n# 12.66015625 13.13671875 13.43359375]\n# [12.12890625 12.42578125 12.90234375 13.53125 13.9375\n# 14.56640625 15.04296875 15.33984375]\n# [13.31640625 13.61328125 14.08984375 14.71875 15.125\n# 15.75390625 16.23046875 16.52734375]]]]\noutput = interpolate_nd(\n data, cubic_coeffs, scale_factors=scales).astype(np.float32)\n\nexpect(node, inputs=[data, scales], outputs=[output],\n name='test_resize_upsample_scales_cubic')" + }, + { + "summary": "resize_upsample_scales_cubic_A_n0p5_exclude_outside", + "code": "node = onnx.helper.make_node(\n 'Resize',\n inputs=['X', '', 'scales'],\n outputs=['Y'],\n mode='cubic',\n cubic_coeff_a=-0.5,\n exclude_outside=True\n)\n\ndata = np.array([[[\n [1, 2, 3, 4],\n [5, 6, 7, 8],\n [9, 10, 11, 12],\n [13, 14, 15, 16],\n]]], dtype=np.float32)\n\nscales = np.array([1.0, 1.0, 2.0, 2.0], dtype=np.float32)\n\n# [[[[ 0.55882353 0.81494204 1.35698249 1.89705882 2.39705882\n# 2.93713516 3.47917561 3.73529412]\n# [ 1.58329755 1.83941606 2.38145651 2.92153285 3.42153285\n# 3.96160918 4.50364964 4.75976814]\n# [ 3.75145936 4.00757787 4.54961832 5.08969466 5.58969466\n# 6.12977099 6.67181144 6.92792995]\n# [ 5.91176471 6.16788321 6.70992366 7.25 7.75\n# 8.29007634 8.83211679 9.08823529]\n# [ 7.91176471 8.16788321 8.70992366 9.25 9.75\n# 10.29007634 10.83211679 11.08823529]\n# [10.07207005 10.32818856 10.87022901 11.41030534 11.91030534\n# 12.45038168 12.99242213 13.24854064]\n# [12.24023186 12.49635036 13.03839082 13.57846715 14.07846715\n# 14.61854349 15.16058394 15.41670245]\n# [13.26470588 13.52082439 14.06286484 14.60294118 15.10294118\n# 15.64301751 16.18505796 16.44117647]]]]\noutput = interpolate_nd(data, lambda x: cubic_coeffs(x, A=-0.5), scale_factors=scales,\n exclude_outside=True).astype(np.float32)\n\nexpect(node, inputs=[data, scales], outputs=[output],\n name='test_resize_upsample_scales_cubic_A_n0p5_exclude_outside')" + }, + { + "summary": "resize_upsample_scales_cubic_align_corners", + "code": "node = onnx.helper.make_node(\n 'Resize',\n inputs=['X', '', 'scales'],\n outputs=['Y'],\n mode='cubic',\n coordinate_transformation_mode='align_corners'\n)\n\ndata = np.array([[[\n [1, 2, 3, 4],\n [5, 6, 7, 8],\n [9, 10, 11, 12],\n [13, 14, 15, 16],\n]]], dtype=np.float32)\n\nscales = np.array([1.0, 1.0, 2.0, 2.0], dtype=np.float32)\n\n# [[[[ 1. 1.34110787 1.80029155 2.32944606 2.67055394\n# 3.19970845 3.65889213 4. ]\n# [ 2.36443149 2.70553936 3.16472303 3.69387755 4.03498542\n# 4.56413994 5.02332362 5.36443149]\n# [ 4.20116618 4.54227405 5.00145773 5.53061224 5.87172012\n# 6.40087464 6.86005831 7.20116618]\n# [ 6.31778426 6.65889213 7.1180758 7.64723032 7.98833819\n# 8.51749271 8.97667638 9.31778426]\n# [ 7.68221574 8.02332362 8.48250729 9.01166181 9.35276968\n# 9.8819242 10.34110787 10.68221574]\n# [ 9.79883382 10.13994169 10.59912536 11.12827988 11.46938776\n# 11.99854227 12.45772595 12.79883382]\n# [11.63556851 11.97667638 12.43586006 12.96501458 13.30612245\n# 13.83527697 14.29446064 14.63556851]\n# [13. 13.34110787 13.80029155 14.32944606 14.67055394\n# 15.19970845 15.65889213 16. ]]]]\noutput = interpolate_nd(\n data, cubic_coeffs, scale_factors=scales, coordinate_transformation_mode='align_corners').astype(np.float32)\n\nexpect(node, inputs=[data, scales], outputs=[output],\n name='test_resize_upsample_scales_cubic_align_corners')" + }, + { + "summary": "resize_upsample_scales_cubic_asymmetric", + "code": "node = onnx.helper.make_node(\n 'Resize',\n inputs=['X', '', 'scales'],\n outputs=['Y'],\n mode='cubic',\n coordinate_transformation_mode='asymmetric'\n)\n\ndata = np.array([[[\n [1, 2, 3, 4],\n [5, 6, 7, 8],\n [9, 10, 11, 12],\n [13, 14, 15, 16],\n]]], dtype=np.float32)\n\nscales = np.array([1.0, 1.0, 2.0, 2.0], dtype=np.float32)\n\n# [[[[ 1. 1.40625 2. 2.5 3. 3.59375 4.\n# 4.09375]\n# [ 2.625 3.03125 3.625 4.125 4.625 5.21875 5.625\n# 5.71875]\n# [ 5. 5.40625 6. 6.5 7. 7.59375 8.\n# 8.09375]\n# [ 7. 7.40625 8. 8.5 9. 9.59375 10.\n# 10.09375]\n# [ 9. 9.40625 10. 10.5 11. 11.59375 12.\n# 12.09375]\n# [11.375 11.78125 12.375 12.875 13.375 13.96875 14.375\n# 14.46875]\n# [13. 13.40625 14. 14.5 15. 15.59375 16.\n# 16.09375]\n# [13.375 13.78125 14.375 14.875 15.375 15.96875 16.375\n# 16.46875]]]]\noutput = interpolate_nd(data, lambda x: cubic_coeffs(x, A=-0.75), scale_factors=scales,\n coordinate_transformation_mode='asymmetric').astype(np.float32)\n\nexpect(node, inputs=[data, scales], outputs=[output],\n name='test_resize_upsample_scales_cubic_asymmetric')" + }, + { + "summary": "resize_upsample_scales_linear", + "code": "node = onnx.helper.make_node(\n 'Resize',\n inputs=['X', '', 'scales'],\n outputs=['Y'],\n mode='linear',\n)\n\ndata = np.array([[[\n [1, 2],\n [3, 4],\n]]], dtype=np.float32)\n\nscales = np.array([1.0, 1.0, 2.0, 2.0], dtype=np.float32)\n\n# [[[[1. 1.25 1.75 2. ]\n# [1.5 1.75 2.25 2.5 ]\n# [2.5 2.75 3.25 3.5 ]\n# [3. 3.25 3.75 4. ]]]]\noutput = interpolate_nd(\n data, linear_coeffs, scale_factors=scales).astype(np.float32)\n\nexpect(node, inputs=[data, scales], outputs=[output],\n name='test_resize_upsample_scales_linear')" + }, + { + "summary": "resize_upsample_scales_linear_align_corners", + "code": "node = onnx.helper.make_node(\n 'Resize',\n inputs=['X', '', 'scales'],\n outputs=['Y'],\n mode='linear',\n coordinate_transformation_mode='align_corners'\n)\n\ndata = np.array([[[\n [1, 2],\n [3, 4],\n]]], dtype=np.float32)\n\nscales = np.array([1.0, 1.0, 2.0, 2.0], dtype=np.float32)\n\n# [[[[1. 1.33333333 1.66666667 2. ]\n# [1.66666667 2. 2.33333333 2.66666667]\n# [2.33333333 2.66666667 3. 3.33333333]\n# [3. 3.33333333 3.66666667 4. ]]]]\noutput = interpolate_nd(\n data, linear_coeffs, scale_factors=scales, coordinate_transformation_mode='align_corners').astype(np.float32)\n\nexpect(node, inputs=[data, scales], outputs=[output],\n name='test_resize_upsample_scales_linear_align_corners')" + }, + { + "summary": "resize_upsample_scales_nearest", + "code": "node = onnx.helper.make_node(\n 'Resize',\n inputs=['X', '', 'scales'],\n outputs=['Y'],\n mode='nearest',\n)\n\ndata = np.array([[[\n [1, 2],\n [3, 4],\n]]], dtype=np.float32)\n\nscales = np.array([1.0, 1.0, 2.0, 3.0], dtype=np.float32)\n\n# [[[[1. 1. 1. 2. 2. 2.]\n# [1. 1. 1. 2. 2. 2.]\n# [3. 3. 3. 4. 4. 4.]\n# [3. 3. 3. 4. 4. 4.]]]]\noutput = interpolate_nd(\n data, nearest_coeffs, scale_factors=scales).astype(np.float32)\n\nexpect(node, inputs=[data, scales], outputs=[output],\n name='test_resize_upsample_scales_nearest')" + }, + { + "summary": "resize_upsample_sizes_cubic", + "code": "node = onnx.helper.make_node(\n 'Resize',\n inputs=['X', '', '', 'sizes'],\n outputs=['Y'],\n mode='cubic',\n)\n\ndata = np.array([[[\n [1, 2, 3, 4],\n [5, 6, 7, 8],\n [9, 10, 11, 12],\n [13, 14, 15, 16],\n]]], dtype=np.float32)\n\nsizes = np.array([1, 1, 9, 10], dtype=np.int64)\n\n# [[[[ 0.45507922 0.64057922 0.97157922 1.42257922 1.90732922\n# 2.22332922 2.70807922 3.15907922 3.49007922 3.67557922]\n# [ 1.39437963 1.57987963 1.91087963 2.36187963 2.84662963\n# 3.16262963 3.64737963 4.09837963 4.42937963 4.61487963]\n# [ 2.95130693 3.13680693 3.46780693 3.91880693 4.40355693\n# 4.71955693 5.20430693 5.65530693 5.98630693 6.17180693]\n# [ 5.20525069 5.39075069 5.72175069 6.17275069 6.65750069\n# 6.97350069 7.45825069 7.90925069 8.24025069 8.42575069]\n# [ 6.88975 7.07525 7.40625 7.85725 8.342\n# 8.658 9.14275 9.59375 9.92475 10.11025 ]\n# [ 8.57424931 8.75974931 9.09074931 9.54174931 10.02649931\n# 10.34249931 10.82724931 11.27824931 11.60924931 11.79474931]\n# [10.82819307 11.01369307 11.34469307 11.79569307 12.28044307\n# 12.59644307 13.08119307 13.53219307 13.86319307 14.04869307]\n# [12.38512037 12.57062037 12.90162037 13.35262037 13.83737037\n# 14.15337037 14.63812037 15.08912037 15.42012037 15.60562037]\n# [13.32442078 13.50992078 13.84092078 14.29192078 14.77667078\n# 15.09267078 15.57742078 16.02842078 16.35942078 16.54492078]]]]\noutput = interpolate_nd(\n data, cubic_coeffs, output_size=sizes).astype(np.float32)\n\nexpect(node, inputs=[data, sizes], outputs=[output],\n name='test_resize_upsample_sizes_cubic')" + }, + { + "summary": "resize_upsample_sizes_nearest", + "code": "node = onnx.helper.make_node(\n 'Resize',\n inputs=['X', '', '', 'sizes'],\n outputs=['Y'],\n mode='nearest',\n)\n\ndata = np.array([[[\n [1, 2],\n [3, 4],\n]]], dtype=np.float32)\n\nsizes = np.array([1, 1, 7, 8], dtype=np.int64)\n\n# [[[[1. 1. 1. 1. 2. 2. 2. 2.]\n# [1. 1. 1. 1. 2. 2. 2. 2.]\n# [1. 1. 1. 1. 2. 2. 2. 2.]\n# [1. 1. 1. 1. 2. 2. 2. 2.]\n# [3. 3. 3. 3. 4. 4. 4. 4.]\n# [3. 3. 3. 3. 4. 4. 4. 4.]\n# [3. 3. 3. 3. 4. 4. 4. 4.]]]]\noutput = interpolate_nd(\n data, nearest_coeffs, output_size=sizes).astype(np.float32)\n\nexpect(node, inputs=[data, sizes], outputs=[output],\n name='test_resize_upsample_sizes_nearest')" + }, + { + "summary": "resize_upsample_sizes_nearest_ceil_half_pixel", + "code": "node = onnx.helper.make_node(\n 'Resize',\n inputs=['X', '', '', 'sizes'],\n outputs=['Y'],\n mode='nearest',\n coordinate_transformation_mode='half_pixel',\n nearest_mode='ceil'\n)\n\ndata = np.array([[[\n [1, 2, 3, 4],\n [5, 6, 7, 8],\n [9, 10, 11, 12],\n [13, 14, 15, 16],\n]]], dtype=np.float32)\n\nsizes = np.array([1, 1, 8, 8], dtype=np.int64)\n\n# [[[[ 1. 2. 2. 3. 3. 4. 4. 4.]\n# [ 5. 6. 6. 7. 7. 8. 8. 8.]\n# [ 5. 6. 6. 7. 7. 8. 8. 8.]\n# [ 9. 10. 10. 11. 11. 12. 12. 12.]\n# [ 9. 10. 10. 11. 11. 12. 12. 12.]\n# [13. 14. 14. 15. 15. 16. 16. 16.]\n# [13. 14. 14. 15. 15. 16. 16. 16.]\n# [13. 14. 14. 15. 15. 16. 16. 16.]]]]\noutput = interpolate_nd(\n data, lambda x: nearest_coeffs(x, mode='ceil'), output_size=sizes).astype(np.float32)\n\nexpect(node, inputs=[data, sizes], outputs=[output],\n name='test_resize_upsample_sizes_nearest_ceil_half_pixel')" + }, + { + "summary": "resize_upsample_sizes_nearest_floor_align_corners", + "code": "node = onnx.helper.make_node(\n 'Resize',\n inputs=['X', '', '', 'sizes'],\n outputs=['Y'],\n mode='nearest',\n coordinate_transformation_mode='align_corners',\n nearest_mode='floor'\n)\n\ndata = np.array([[[\n [1, 2, 3, 4],\n [5, 6, 7, 8],\n [9, 10, 11, 12],\n [13, 14, 15, 16],\n]]], dtype=np.float32)\n\nsizes = np.array([1, 1, 8, 8], dtype=np.int64)\n\n# [[[[ 1. 1. 1. 2. 2. 3. 3. 4.]\n# [ 1. 1. 1. 2. 2. 3. 3. 4.]\n# [ 1. 1. 1. 2. 2. 3. 3. 4.]\n# [ 5. 5. 5. 6. 6. 7. 7. 8.]\n# [ 5. 5. 5. 6. 6. 7. 7. 8.]\n# [ 9. 9. 9. 10. 10. 11. 11. 12.]\n# [ 9. 9. 9. 10. 10. 11. 11. 12.]\n# [13. 13. 13. 14. 14. 15. 15. 16.]]]]\noutput = interpolate_nd(\n data, lambda x: nearest_coeffs(x, mode='floor'), output_size=sizes, coordinate_transformation_mode='align_corners').astype(np.float32)\n\nexpect(node, inputs=[data, sizes], outputs=[output],\n name='test_resize_upsample_sizes_nearest_floor_align_corners')" + }, + { + "summary": "resize_upsample_sizes_nearest_round_prefer_ceil_asymmetric", + "code": "node = onnx.helper.make_node(\n 'Resize',\n inputs=['X', '', '', 'sizes'],\n outputs=['Y'],\n mode='nearest',\n coordinate_transformation_mode='asymmetric',\n nearest_mode='round_prefer_ceil'\n)\n\ndata = np.array([[[\n [1, 2, 3, 4],\n [5, 6, 7, 8],\n [9, 10, 11, 12],\n [13, 14, 15, 16],\n]]], dtype=np.float32)\n\nsizes = np.array([1, 1, 8, 8], dtype=np.int64)\n\n# [[[[ 1. 2. 2. 3. 3. 4. 4. 4.]\n# [ 5. 6. 6. 7. 7. 8. 8. 8.]\n# [ 5. 6. 6. 7. 7. 8. 8. 8.]\n# [ 9. 10. 10. 11. 11. 12. 12. 12.]\n# [ 9. 10. 10. 11. 11. 12. 12. 12.]\n# [13. 14. 14. 15. 15. 16. 16. 16.]\n# [13. 14. 14. 15. 15. 16. 16. 16.]\n# [13. 14. 14. 15. 15. 16. 16. 16.]]]]\noutput = interpolate_nd(\n data, lambda x: nearest_coeffs(x, mode='round_prefer_ceil'),\n output_size=sizes, coordinate_transformation_mode='asymmetric').astype(np.float32)\n\nexpect(node, inputs=[data, sizes], outputs=[output],\n name='test_resize_upsample_sizes_nearest_round_prefer_ceil_asymmetric')" + } + ] + }, + { + "name": "Resize", + "module": "ai.onnx", + "version": 11, + "support_level": "common", + "description": "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.\nEach dimension value of the output tensor is:\n output_dimension = floor(input_dimension * (roi_end - roi_start) * scale) if input \\\"sizes\\\" is not specified.\n", + "attributes": [ + { + "name": "coordinate_transformation_mode", + "type": "string", + "required": false, + "default": "half_pixel", + "description": "\nThis attribute describes how to transform the coordinate in the resized tensor to the coordinate in the original tensor.
\n\nThe coordinate of each dimension is transformed individually. Let's describe a case using axis x as an example.\nDenote 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,
\n\nif coordinate_transformation_mode is \"half_pixel\",
\nx_original = (x_resized + 0.5) / scale - 0.5,
\n\nif coordinate_transformation_mode is \"pytorch_half_pixel\",
\nx_original = length_resized > 1 ? (x_resized + 0.5) / scale - 0.5 : 0,
\n\nif coordinate_transformation_mode is \"align_corners\",
\nx_original = x_resized * (length_original - 1) / (length_resized - 1),
\n\nif coordinate_transformation_mode is \"asymmetric\",
\nx_original = x_resized / scale,
\n\nif coordinate_transformation_mode is \"tf_half_pixel_for_nn\",
\nx_original = (x_resized + 0.5) / scale,
\n\nif coordinate_transformation_mode is \"tf_crop_and_resize\",
\nx_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)." + }, + { + "name": "cubic_coeff_a", + "type": "float32", + "required": false, + "default": -0.75, + "description": "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\"." + }, + { + "name": "exclude_outside", + "type": "int64", + "required": false, + "description": "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." + }, + { + "name": "extrapolation_value", + "type": "float32", + "required": false, + "description": "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." + }, + { + "name": "mode", + "type": "string", + "required": false, + "default": "nearest", + "description": "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)." + }, + { + "name": "nearest_mode", + "type": "string", + "required": false, + "default": "round_prefer_floor", + "description": "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": [ + { + "name": "X", + "type": "T1", + "description": "N-D tensor" + }, + { + "name": "roi", + "type": "T2", + "description": "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\"" + }, + { + "name": "scales", + "type": "tensor(float)", + "description": "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." + }, + { + "name": "sizes", + "type": "tensor(int64)", + "option": "optional", + "description": "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." + } + ], + "min_input": 3, + "max_input": 4, + "outputs": [ + { + "name": "Y", + "type": "T1", + "description": "N-D tensor after resizing" + } + ], + "min_output": 1, + "max_output": 1, + "inputs_range": "3 - 4", + "type_constraints": [ + { + "description": "Constrain input 'X' and output 'Y' to all tensor types.", + "type_param_str": "T1", + "allowed_type_strs": [ + "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)" + ] + }, + { + "description": "Constrain roi type to float or double.", + "type_param_str": "T2", + "allowed_type_strs": [ + "tensor(float16)", + "tensor(float)", + "tensor(double)" + ] + } + ], + "examples": [ + { + "summary": "resize_downsample_scales_cubic", + "code": "node = onnx.helper.make_node(\n 'Resize',\n inputs=['X', '', 'scales'],\n outputs=['Y'],\n mode='cubic',\n)\n\ndata = np.array([[[\n [1, 2, 3, 4],\n [5, 6, 7, 8],\n [9, 10, 11, 12],\n [13, 14, 15, 16],\n]]], dtype=np.float32)\n\nscales = np.array([1.0, 1.0, 0.8, 0.8], dtype=np.float32)\n\n# [[[[ 1.47119141 2.78125 4.08251953]\n# [ 6.71142578 8.02148438 9.32275391]\n# [11.91650391 13.2265625 14.52783203]]]]\noutput = interpolate_nd(\n data, cubic_coeffs, scale_factors=scales).astype(np.float32)\n\nexpect(node, inputs=[data, scales], outputs=[output],\n name='test_resize_downsample_scales_cubic')" + }, + { + "summary": "resize_downsample_scales_cubic_A_n0p5_exclude_outside", + "code": "node = onnx.helper.make_node(\n 'Resize',\n inputs=['X', '', 'scales'],\n outputs=['Y'],\n mode='cubic',\n cubic_coeff_a=-0.5,\n exclude_outside=True\n)\n\ndata = np.array([[[\n [1, 2, 3, 4],\n [5, 6, 7, 8],\n [9, 10, 11, 12],\n [13, 14, 15, 16],\n]]], dtype=np.float32)\n\nscales = np.array([1.0, 1.0, 0.8, 0.8], dtype=np.float32)\n\n# [[[[ 1.36812675 2.6695014 4.0133367 ]\n# [ 6.57362535 7.875 9.2188353 ]\n# [11.94896657 13.25034122 14.59417652]]]]\noutput = interpolate_nd(data, lambda x: cubic_coeffs(x, A=-0.5), scale_factors=scales,\n exclude_outside=True).astype(np.float32)\n\nexpect(node, inputs=[data, scales], outputs=[output],\n name='test_resize_downsample_scales_cubic_A_n0p5_exclude_outside')" + }, + { + "summary": "resize_downsample_scales_cubic_align_corners", + "code": "node = onnx.helper.make_node(\n 'Resize',\n inputs=['X', '', 'scales'],\n outputs=['Y'],\n mode='cubic',\n coordinate_transformation_mode='align_corners'\n)\n\ndata = np.array([[[\n [1, 2, 3, 4],\n [5, 6, 7, 8],\n [9, 10, 11, 12],\n [13, 14, 15, 16],\n]]], dtype=np.float32)\n\nscales = np.array([1.0, 1.0, 0.8, 0.8], dtype=np.float32)\n\n# [[[[ 1. 2.39519159 3.79038317]\n# [ 6.58076634 7.97595793 9.37114951]\n# [12.16153268 13.55672427 14.95191585]]]]\noutput = interpolate_nd(\n data, cubic_coeffs, scale_factors=scales, coordinate_transformation_mode='align_corners').astype(np.float32)\n\nexpect(node, inputs=[data, scales], outputs=[output],\n name='test_resize_downsample_scales_cubic_align_corners')" + }, + { + "summary": "resize_downsample_scales_linear", + "code": "node = onnx.helper.make_node(\n 'Resize',\n inputs=['X', '', 'scales'],\n outputs=['Y'],\n mode='linear',\n)\n\ndata = np.array([[[\n [1, 2, 3, 4],\n [5, 6, 7, 8],\n]]], dtype=np.float32)\n\nscales = np.array([1.0, 1.0, 0.6, 0.6], dtype=np.float32)\n\n# [[[[2.6666665 4.3333331]]]]\noutput = interpolate_nd(\n data, linear_coeffs, scale_factors=scales).astype(np.float32)\n\nexpect(node, inputs=[data, scales], outputs=[output],\n name='test_resize_downsample_scales_linear')" + }, + { + "summary": "resize_downsample_scales_linear_align_corners", + "code": "node = onnx.helper.make_node(\n 'Resize',\n inputs=['X', '', 'scales'],\n outputs=['Y'],\n mode='linear',\n coordinate_transformation_mode='align_corners'\n)\n\ndata = np.array([[[\n [1, 2, 3, 4],\n [5, 6, 7, 8],\n]]], dtype=np.float32)\n\nscales = np.array([1.0, 1.0, 0.6, 0.6], dtype=np.float32)\n\n# [[[[1. 3.142857]]]]\noutput = interpolate_nd(\n data, linear_coeffs, scale_factors=scales, coordinate_transformation_mode='align_corners').astype(np.float32)\n\nexpect(node, inputs=[data, scales], outputs=[output],\n name='test_resize_downsample_scales_linear_align_corners')" + }, + { + "summary": "resize_downsample_scales_nearest", + "code": "node = onnx.helper.make_node(\n 'Resize',\n inputs=['X', '', 'scales'],\n outputs=['Y'],\n mode='nearest',\n)\n\ndata = np.array([[[\n [1, 2, 3, 4],\n [5, 6, 7, 8],\n]]], dtype=np.float32)\n\nscales = np.array([1.0, 1.0, 0.6, 0.6], dtype=np.float32)\n\n# [[[[1. 3.]]]]\noutput = interpolate_nd(\n data, nearest_coeffs, scale_factors=scales).astype(np.float32)\n\nexpect(node, inputs=[data, scales], outputs=[output],\n name='test_resize_downsample_scales_nearest')" + }, + { + "summary": "resize_downsample_sizes_cubic", + "code": "node = onnx.helper.make_node(\n 'Resize',\n inputs=['X', '', '', 'sizes'],\n outputs=['Y'],\n mode='cubic',\n)\n\ndata = np.array([[[\n [1, 2, 3, 4],\n [5, 6, 7, 8],\n [9, 10, 11, 12],\n [13, 14, 15, 16],\n]]], dtype=np.float32)\n\nsizes = np.array([1, 1, 3, 3], dtype=np.int64)\n\n# [[[[ 1.63078704 3.00462963 4.37847222]\n# [ 7.12615741 8.5 9.87384259]\n# [12.62152778 13.99537037 15.36921296]]]]\noutput = interpolate_nd(\n data, cubic_coeffs, output_size=sizes).astype(np.float32)\n\nexpect(node, inputs=[data, sizes], outputs=[output],\n name='test_resize_downsample_sizes_cubic')" + }, + { + "summary": "resize_downsample_sizes_linear_pytorch_half_pixel", + "code": "node = onnx.helper.make_node(\n 'Resize',\n inputs=['X', '', '', 'sizes'],\n outputs=['Y'],\n mode='linear',\n coordinate_transformation_mode='pytorch_half_pixel'\n)\n\ndata = np.array([[[\n [1, 2, 3, 4],\n [5, 6, 7, 8],\n [9, 10, 11, 12],\n [13, 14, 15, 16],\n]]], dtype=np.float32)\n\nsizes = np.array([1, 1, 3, 1], dtype=np.int64)\n\n# [[[[ 1.6666666]\n# [ 7. ]\n# [12.333333 ]]]]\noutput = interpolate_nd(\n data, linear_coeffs, output_size=sizes, coordinate_transformation_mode='pytorch_half_pixel').astype(np.float32)\n\nexpect(node, inputs=[data, sizes], outputs=[output],\n name='test_resize_downsample_sizes_linear_pytorch_half_pixel')" + }, + { + "summary": "resize_downsample_sizes_nearest", + "code": "node = onnx.helper.make_node(\n 'Resize',\n inputs=['X', '', '', 'sizes'],\n outputs=['Y'],\n mode='nearest',\n)\n\ndata = np.array([[[\n [1, 2, 3, 4],\n [5, 6, 7, 8],\n]]], dtype=np.float32)\n\nsizes = np.array([1, 1, 1, 3], dtype=np.int64)\n\n# [[[[1. 3.]]]]\noutput = interpolate_nd(\n data, nearest_coeffs, output_size=sizes).astype(np.float32)\n\nexpect(node, inputs=[data, sizes], outputs=[output],\n name='test_resize_downsample_sizes_nearest')" + }, + { + "summary": "resize_tf_crop_and_resize", + "code": "node = onnx.helper.make_node(\n 'Resize',\n inputs=['X', 'roi', '', 'sizes'],\n outputs=['Y'],\n mode='linear',\n coordinate_transformation_mode='tf_crop_and_resize'\n)\n\ndata = np.array([[[\n [1, 2, 3, 4],\n [5, 6, 7, 8],\n [9, 10, 11, 12],\n [13, 14, 15, 16],\n]]], dtype=np.float32)\n\n# Note: for some rois, the result may be different with that of TF for inaccurate floating point\nroi = np.array([0, 0, 0.4, 0.6, 1, 1, 0.6, 0.8], dtype=np.float32)\nsizes = np.array([1, 1, 3, 3], dtype=np.int64)\n\n# [[[[ 7.6000004 7.9 8.2 ]\n# [ 8.8 9.1 9.400001 ]\n# [10. 10.3 10.6 ]]]]\noutput = interpolate_nd(data, linear_coeffs, output_size=sizes, roi=roi,\n coordinate_transformation_mode='tf_crop_and_resize').astype(np.float32)\n\nexpect(node, inputs=[data, roi, sizes], outputs=[output],\n name='test_resize_tf_crop_and_resize')" + }, + { + "summary": "resize_tf_crop_and_resize_extrapolation_value", + "code": "node = onnx.helper.make_node(\n 'Resize',\n inputs=['X', 'roi', '', 'sizes'],\n outputs=['Y'],\n mode='linear',\n coordinate_transformation_mode='tf_crop_and_resize',\n extrapolation_value=10.0\n)\n\ndata = np.array([[[\n [1, 2, 3, 4],\n [5, 6, 7, 8],\n [9, 10, 11, 12],\n [13, 14, 15, 16],\n]]], dtype=np.float32)\n\n# Note: for some rois, the result may be different with that of TF for inaccurate floating point\nroi = np.array([0, 0, 0.4, 0.6, 1, 1, 1.2, 1.7], dtype=np.float32)\nsizes = np.array([1, 1, 3, 3], dtype=np.int64)\n\n# [[[[ 7.6000004 10. 10. ]\n# [12.400001 10. 10. ]\n# [10. 10. 10. ]]]]\noutput = interpolate_nd(data, linear_coeffs, output_size=sizes, roi=roi,\n coordinate_transformation_mode='tf_crop_and_resize', extrapolation_value=10.0).astype(np.float32)\n\nexpect(node, inputs=[data, roi, sizes], outputs=[output],\n name='test_resize_tf_crop_and_resize')" + }, + { + "summary": "resize_upsample_scales_cubic", + "code": "node = onnx.helper.make_node(\n 'Resize',\n inputs=['X', '', 'scales'],\n outputs=['Y'],\n mode='cubic',\n)\n\ndata = np.array([[[\n [1, 2, 3, 4],\n [5, 6, 7, 8],\n [9, 10, 11, 12],\n [13, 14, 15, 16],\n]]], dtype=np.float32)\n\nscales = np.array([1.0, 1.0, 2.0, 2.0], dtype=np.float32)\n\n# [[[[ 0.47265625 0.76953125 1.24609375 1.875 2.28125\n# 2.91015625 3.38671875 3.68359375]\n# [ 1.66015625 1.95703125 2.43359375 3.0625 3.46875\n# 4.09765625 4.57421875 4.87109375]\n# [ 3.56640625 3.86328125 4.33984375 4.96875 5.375\n# 6.00390625 6.48046875 6.77734375]\n# [ 6.08203125 6.37890625 6.85546875 7.484375 7.890625\n# 8.51953125 8.99609375 9.29296875]\n# [ 7.70703125 8.00390625 8.48046875 9.109375 9.515625\n# 10.14453125 10.62109375 10.91796875]\n# [10.22265625 10.51953125 10.99609375 11.625 12.03125\n# 12.66015625 13.13671875 13.43359375]\n# [12.12890625 12.42578125 12.90234375 13.53125 13.9375\n# 14.56640625 15.04296875 15.33984375]\n# [13.31640625 13.61328125 14.08984375 14.71875 15.125\n# 15.75390625 16.23046875 16.52734375]]]]\noutput = interpolate_nd(\n data, cubic_coeffs, scale_factors=scales).astype(np.float32)\n\nexpect(node, inputs=[data, scales], outputs=[output],\n name='test_resize_upsample_scales_cubic')" + }, + { + "summary": "resize_upsample_scales_cubic_A_n0p5_exclude_outside", + "code": "node = onnx.helper.make_node(\n 'Resize',\n inputs=['X', '', 'scales'],\n outputs=['Y'],\n mode='cubic',\n cubic_coeff_a=-0.5,\n exclude_outside=True\n)\n\ndata = np.array([[[\n [1, 2, 3, 4],\n [5, 6, 7, 8],\n [9, 10, 11, 12],\n [13, 14, 15, 16],\n]]], dtype=np.float32)\n\nscales = np.array([1.0, 1.0, 2.0, 2.0], dtype=np.float32)\n\n# [[[[ 0.55882353 0.81494204 1.35698249 1.89705882 2.39705882\n# 2.93713516 3.47917561 3.73529412]\n# [ 1.58329755 1.83941606 2.38145651 2.92153285 3.42153285\n# 3.96160918 4.50364964 4.75976814]\n# [ 3.75145936 4.00757787 4.54961832 5.08969466 5.58969466\n# 6.12977099 6.67181144 6.92792995]\n# [ 5.91176471 6.16788321 6.70992366 7.25 7.75\n# 8.29007634 8.83211679 9.08823529]\n# [ 7.91176471 8.16788321 8.70992366 9.25 9.75\n# 10.29007634 10.83211679 11.08823529]\n# [10.07207005 10.32818856 10.87022901 11.41030534 11.91030534\n# 12.45038168 12.99242213 13.24854064]\n# [12.24023186 12.49635036 13.03839082 13.57846715 14.07846715\n# 14.61854349 15.16058394 15.41670245]\n# [13.26470588 13.52082439 14.06286484 14.60294118 15.10294118\n# 15.64301751 16.18505796 16.44117647]]]]\noutput = interpolate_nd(data, lambda x: cubic_coeffs(x, A=-0.5), scale_factors=scales,\n exclude_outside=True).astype(np.float32)\n\nexpect(node, inputs=[data, scales], outputs=[output],\n name='test_resize_upsample_scales_cubic_A_n0p5_exclude_outside')" + }, + { + "summary": "resize_upsample_scales_cubic_align_corners", + "code": "node = onnx.helper.make_node(\n 'Resize',\n inputs=['X', '', 'scales'],\n outputs=['Y'],\n mode='cubic',\n coordinate_transformation_mode='align_corners'\n)\n\ndata = np.array([[[\n [1, 2, 3, 4],\n [5, 6, 7, 8],\n [9, 10, 11, 12],\n [13, 14, 15, 16],\n]]], dtype=np.float32)\n\nscales = np.array([1.0, 1.0, 2.0, 2.0], dtype=np.float32)\n\n# [[[[ 1. 1.34110787 1.80029155 2.32944606 2.67055394\n# 3.19970845 3.65889213 4. ]\n# [ 2.36443149 2.70553936 3.16472303 3.69387755 4.03498542\n# 4.56413994 5.02332362 5.36443149]\n# [ 4.20116618 4.54227405 5.00145773 5.53061224 5.87172012\n# 6.40087464 6.86005831 7.20116618]\n# [ 6.31778426 6.65889213 7.1180758 7.64723032 7.98833819\n# 8.51749271 8.97667638 9.31778426]\n# [ 7.68221574 8.02332362 8.48250729 9.01166181 9.35276968\n# 9.8819242 10.34110787 10.68221574]\n# [ 9.79883382 10.13994169 10.59912536 11.12827988 11.46938776\n# 11.99854227 12.45772595 12.79883382]\n# [11.63556851 11.97667638 12.43586006 12.96501458 13.30612245\n# 13.83527697 14.29446064 14.63556851]\n# [13. 13.34110787 13.80029155 14.32944606 14.67055394\n# 15.19970845 15.65889213 16. ]]]]\noutput = interpolate_nd(\n data, cubic_coeffs, scale_factors=scales, coordinate_transformation_mode='align_corners').astype(np.float32)\n\nexpect(node, inputs=[data, scales], outputs=[output],\n name='test_resize_upsample_scales_cubic_align_corners')" + }, + { + "summary": "resize_upsample_scales_cubic_asymmetric", + "code": "node = onnx.helper.make_node(\n 'Resize',\n inputs=['X', '', 'scales'],\n outputs=['Y'],\n mode='cubic',\n coordinate_transformation_mode='asymmetric'\n)\n\ndata = np.array([[[\n [1, 2, 3, 4],\n [5, 6, 7, 8],\n [9, 10, 11, 12],\n [13, 14, 15, 16],\n]]], dtype=np.float32)\n\nscales = np.array([1.0, 1.0, 2.0, 2.0], dtype=np.float32)\n\n# [[[[ 1. 1.40625 2. 2.5 3. 3.59375 4.\n# 4.09375]\n# [ 2.625 3.03125 3.625 4.125 4.625 5.21875 5.625\n# 5.71875]\n# [ 5. 5.40625 6. 6.5 7. 7.59375 8.\n# 8.09375]\n# [ 7. 7.40625 8. 8.5 9. 9.59375 10.\n# 10.09375]\n# [ 9. 9.40625 10. 10.5 11. 11.59375 12.\n# 12.09375]\n# [11.375 11.78125 12.375 12.875 13.375 13.96875 14.375\n# 14.46875]\n# [13. 13.40625 14. 14.5 15. 15.59375 16.\n# 16.09375]\n# [13.375 13.78125 14.375 14.875 15.375 15.96875 16.375\n# 16.46875]]]]\noutput = interpolate_nd(data, lambda x: cubic_coeffs(x, A=-0.75), scale_factors=scales,\n coordinate_transformation_mode='asymmetric').astype(np.float32)\n\nexpect(node, inputs=[data, scales], outputs=[output],\n name='test_resize_upsample_scales_cubic_asymmetric')" + }, + { + "summary": "resize_upsample_scales_linear", + "code": "node = onnx.helper.make_node(\n 'Resize',\n inputs=['X', '', 'scales'],\n outputs=['Y'],\n mode='linear',\n)\n\ndata = np.array([[[\n [1, 2],\n [3, 4],\n]]], dtype=np.float32)\n\nscales = np.array([1.0, 1.0, 2.0, 2.0], dtype=np.float32)\n\n# [[[[1. 1.25 1.75 2. ]\n# [1.5 1.75 2.25 2.5 ]\n# [2.5 2.75 3.25 3.5 ]\n# [3. 3.25 3.75 4. ]]]]\noutput = interpolate_nd(\n data, linear_coeffs, scale_factors=scales).astype(np.float32)\n\nexpect(node, inputs=[data, scales], outputs=[output],\n name='test_resize_upsample_scales_linear')" + }, + { + "summary": "resize_upsample_scales_linear_align_corners", + "code": "node = onnx.helper.make_node(\n 'Resize',\n inputs=['X', '', 'scales'],\n outputs=['Y'],\n mode='linear',\n coordinate_transformation_mode='align_corners'\n)\n\ndata = np.array([[[\n [1, 2],\n [3, 4],\n]]], dtype=np.float32)\n\nscales = np.array([1.0, 1.0, 2.0, 2.0], dtype=np.float32)\n\n# [[[[1. 1.33333333 1.66666667 2. ]\n# [1.66666667 2. 2.33333333 2.66666667]\n# [2.33333333 2.66666667 3. 3.33333333]\n# [3. 3.33333333 3.66666667 4. ]]]]\noutput = interpolate_nd(\n data, linear_coeffs, scale_factors=scales, coordinate_transformation_mode='align_corners').astype(np.float32)\n\nexpect(node, inputs=[data, scales], outputs=[output],\n name='test_resize_upsample_scales_linear_align_corners')" + }, + { + "summary": "resize_upsample_scales_nearest", + "code": "node = onnx.helper.make_node(\n 'Resize',\n inputs=['X', '', 'scales'],\n outputs=['Y'],\n mode='nearest',\n)\n\ndata = np.array([[[\n [1, 2],\n [3, 4],\n]]], dtype=np.float32)\n\nscales = np.array([1.0, 1.0, 2.0, 3.0], dtype=np.float32)\n\n# [[[[1. 1. 1. 2. 2. 2.]\n# [1. 1. 1. 2. 2. 2.]\n# [3. 3. 3. 4. 4. 4.]\n# [3. 3. 3. 4. 4. 4.]]]]\noutput = interpolate_nd(\n data, nearest_coeffs, scale_factors=scales).astype(np.float32)\n\nexpect(node, inputs=[data, scales], outputs=[output],\n name='test_resize_upsample_scales_nearest')" + }, + { + "summary": "resize_upsample_sizes_cubic", + "code": "node = onnx.helper.make_node(\n 'Resize',\n inputs=['X', '', '', 'sizes'],\n outputs=['Y'],\n mode='cubic',\n)\n\ndata = np.array([[[\n [1, 2, 3, 4],\n [5, 6, 7, 8],\n [9, 10, 11, 12],\n [13, 14, 15, 16],\n]]], dtype=np.float32)\n\nsizes = np.array([1, 1, 9, 10], dtype=np.int64)\n\n# [[[[ 0.45507922 0.64057922 0.97157922 1.42257922 1.90732922\n# 2.22332922 2.70807922 3.15907922 3.49007922 3.67557922]\n# [ 1.39437963 1.57987963 1.91087963 2.36187963 2.84662963\n# 3.16262963 3.64737963 4.09837963 4.42937963 4.61487963]\n# [ 2.95130693 3.13680693 3.46780693 3.91880693 4.40355693\n# 4.71955693 5.20430693 5.65530693 5.98630693 6.17180693]\n# [ 5.20525069 5.39075069 5.72175069 6.17275069 6.65750069\n# 6.97350069 7.45825069 7.90925069 8.24025069 8.42575069]\n# [ 6.88975 7.07525 7.40625 7.85725 8.342\n# 8.658 9.14275 9.59375 9.92475 10.11025 ]\n# [ 8.57424931 8.75974931 9.09074931 9.54174931 10.02649931\n# 10.34249931 10.82724931 11.27824931 11.60924931 11.79474931]\n# [10.82819307 11.01369307 11.34469307 11.79569307 12.28044307\n# 12.59644307 13.08119307 13.53219307 13.86319307 14.04869307]\n# [12.38512037 12.57062037 12.90162037 13.35262037 13.83737037\n# 14.15337037 14.63812037 15.08912037 15.42012037 15.60562037]\n# [13.32442078 13.50992078 13.84092078 14.29192078 14.77667078\n# 15.09267078 15.57742078 16.02842078 16.35942078 16.54492078]]]]\noutput = interpolate_nd(\n data, cubic_coeffs, output_size=sizes).astype(np.float32)\n\nexpect(node, inputs=[data, sizes], outputs=[output],\n name='test_resize_upsample_sizes_cubic')" + }, + { + "summary": "resize_upsample_sizes_nearest", + "code": "node = onnx.helper.make_node(\n 'Resize',\n inputs=['X', '', '', 'sizes'],\n outputs=['Y'],\n mode='nearest',\n)\n\ndata = np.array([[[\n [1, 2],\n [3, 4],\n]]], dtype=np.float32)\n\nsizes = np.array([1, 1, 7, 8], dtype=np.int64)\n\n# [[[[1. 1. 1. 1. 2. 2. 2. 2.]\n# [1. 1. 1. 1. 2. 2. 2. 2.]\n# [1. 1. 1. 1. 2. 2. 2. 2.]\n# [1. 1. 1. 1. 2. 2. 2. 2.]\n# [3. 3. 3. 3. 4. 4. 4. 4.]\n# [3. 3. 3. 3. 4. 4. 4. 4.]\n# [3. 3. 3. 3. 4. 4. 4. 4.]]]]\noutput = interpolate_nd(\n data, nearest_coeffs, output_size=sizes).astype(np.float32)\n\nexpect(node, inputs=[data, sizes], outputs=[output],\n name='test_resize_upsample_sizes_nearest')" + }, + { + "summary": "resize_upsample_sizes_nearest_ceil_half_pixel", + "code": "node = onnx.helper.make_node(\n 'Resize',\n inputs=['X', '', '', 'sizes'],\n outputs=['Y'],\n mode='nearest',\n coordinate_transformation_mode='half_pixel',\n nearest_mode='ceil'\n)\n\ndata = np.array([[[\n [1, 2, 3, 4],\n [5, 6, 7, 8],\n [9, 10, 11, 12],\n [13, 14, 15, 16],\n]]], dtype=np.float32)\n\nsizes = np.array([1, 1, 8, 8], dtype=np.int64)\n\n# [[[[ 1. 2. 2. 3. 3. 4. 4. 4.]\n# [ 5. 6. 6. 7. 7. 8. 8. 8.]\n# [ 5. 6. 6. 7. 7. 8. 8. 8.]\n# [ 9. 10. 10. 11. 11. 12. 12. 12.]\n# [ 9. 10. 10. 11. 11. 12. 12. 12.]\n# [13. 14. 14. 15. 15. 16. 16. 16.]\n# [13. 14. 14. 15. 15. 16. 16. 16.]\n# [13. 14. 14. 15. 15. 16. 16. 16.]]]]\noutput = interpolate_nd(\n data, lambda x: nearest_coeffs(x, mode='ceil'), output_size=sizes).astype(np.float32)\n\nexpect(node, inputs=[data, sizes], outputs=[output],\n name='test_resize_upsample_sizes_nearest_ceil_half_pixel')" + }, + { + "summary": "resize_upsample_sizes_nearest_floor_align_corners", + "code": "node = onnx.helper.make_node(\n 'Resize',\n inputs=['X', '', '', 'sizes'],\n outputs=['Y'],\n mode='nearest',\n coordinate_transformation_mode='align_corners',\n nearest_mode='floor'\n)\n\ndata = np.array([[[\n [1, 2, 3, 4],\n [5, 6, 7, 8],\n [9, 10, 11, 12],\n [13, 14, 15, 16],\n]]], dtype=np.float32)\n\nsizes = np.array([1, 1, 8, 8], dtype=np.int64)\n\n# [[[[ 1. 1. 1. 2. 2. 3. 3. 4.]\n# [ 1. 1. 1. 2. 2. 3. 3. 4.]\n# [ 1. 1. 1. 2. 2. 3. 3. 4.]\n# [ 5. 5. 5. 6. 6. 7. 7. 8.]\n# [ 5. 5. 5. 6. 6. 7. 7. 8.]\n# [ 9. 9. 9. 10. 10. 11. 11. 12.]\n# [ 9. 9. 9. 10. 10. 11. 11. 12.]\n# [13. 13. 13. 14. 14. 15. 15. 16.]]]]\noutput = interpolate_nd(\n data, lambda x: nearest_coeffs(x, mode='floor'), output_size=sizes, coordinate_transformation_mode='align_corners').astype(np.float32)\n\nexpect(node, inputs=[data, sizes], outputs=[output],\n name='test_resize_upsample_sizes_nearest_floor_align_corners')" + }, + { + "summary": "resize_upsample_sizes_nearest_round_prefer_ceil_asymmetric", + "code": "node = onnx.helper.make_node(\n 'Resize',\n inputs=['X', '', '', 'sizes'],\n outputs=['Y'],\n mode='nearest',\n coordinate_transformation_mode='asymmetric',\n nearest_mode='round_prefer_ceil'\n)\n\ndata = np.array([[[\n [1, 2, 3, 4],\n [5, 6, 7, 8],\n [9, 10, 11, 12],\n [13, 14, 15, 16],\n]]], dtype=np.float32)\n\nsizes = np.array([1, 1, 8, 8], dtype=np.int64)\n\n# [[[[ 1. 2. 2. 3. 3. 4. 4. 4.]\n# [ 5. 6. 6. 7. 7. 8. 8. 8.]\n# [ 5. 6. 6. 7. 7. 8. 8. 8.]\n# [ 9. 10. 10. 11. 11. 12. 12. 12.]\n# [ 9. 10. 10. 11. 11. 12. 12. 12.]\n# [13. 14. 14. 15. 15. 16. 16. 16.]\n# [13. 14. 14. 15. 15. 16. 16. 16.]\n# [13. 14. 14. 15. 15. 16. 16. 16.]]]]\noutput = interpolate_nd(\n data, lambda x: nearest_coeffs(x, mode='round_prefer_ceil'),\n output_size=sizes, coordinate_transformation_mode='asymmetric').astype(np.float32)\n\nexpect(node, inputs=[data, sizes], outputs=[output],\n name='test_resize_upsample_sizes_nearest_round_prefer_ceil_asymmetric')" + } + ] + }, + { + "name": "Resize", + "module": "ai.onnx", + "version": 13, + "support_level": "common", + "description": "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.\nEach dimension value of the output tensor is:\n output_dimension = floor(input_dimension * (roi_end - roi_start) * scale) if input \\\"sizes\\\" is not specified.\n", + "attributes": [ + { + "name": "coordinate_transformation_mode", + "type": "string", + "required": false, + "default": "half_pixel", + "description": "\nThis attribute describes how to transform the coordinate in the resized tensor to the coordinate in the original tensor.
\n\nThe coordinate of each dimension is transformed individually. Let's describe a case using axis x as an example.\nDenote 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,
\n\nif coordinate_transformation_mode is \"half_pixel\",
\nx_original = (x_resized + 0.5) / scale - 0.5,
\n\nif coordinate_transformation_mode is \"pytorch_half_pixel\",
\nx_original = length_resized > 1 ? (x_resized + 0.5) / scale - 0.5 : 0,
\n\nif coordinate_transformation_mode is \"align_corners\",
\nx_original = x_resized * (length_original - 1) / (length_resized - 1),
\n\nif coordinate_transformation_mode is \"asymmetric\",
\nx_original = x_resized / scale,
\n\nif coordinate_transformation_mode is \"tf_crop_and_resize\",
\nx_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)." + }, + { + "name": "cubic_coeff_a", + "type": "float32", + "required": false, + "default": -0.75, + "description": "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\"." + }, + { + "name": "exclude_outside", + "type": "int64", + "required": false, + "description": "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." + }, + { + "name": "extrapolation_value", + "type": "float32", + "required": false, + "description": "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." + }, + { + "name": "mode", + "type": "string", + "required": false, + "default": "nearest", + "description": "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)." + }, + { + "name": "nearest_mode", + "type": "string", + "required": false, + "default": "round_prefer_floor", + "description": "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": [ + { + "name": "X", + "type": "T1", + "description": "N-D tensor" + }, + { + "name": "roi", + "type": "T2", + "option": "optional", + "description": "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\"" + }, + { + "name": "scales", + "type": "tensor(float)", + "option": "optional", + "description": "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." + }, + { + "name": "sizes", + "type": "tensor(int64)", + "option": "optional", + "description": "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." + } + ], + "min_input": 1, + "max_input": 4, + "outputs": [ + { + "name": "Y", + "type": "T1", + "description": "N-D tensor after resizing" + } + ], + "min_output": 1, + "max_output": 1, + "inputs_range": "1 - 4", + "type_constraints": [ + { + "description": "Constrain input 'X' and output 'Y' to all tensor types.", + "type_param_str": "T1", + "allowed_type_strs": [ + "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)" + ] + }, + { + "description": "Constrain roi type to float or double.", + "type_param_str": "T2", + "allowed_type_strs": [ + "tensor(float16)", + "tensor(float)", + "tensor(double)" + ] + } + ], + "examples": [ + { + "summary": "resize_downsample_scales_cubic", + "code": "node = onnx.helper.make_node(\n 'Resize',\n inputs=['X', '', 'scales'],\n outputs=['Y'],\n mode='cubic',\n)\n\ndata = np.array([[[\n [1, 2, 3, 4],\n [5, 6, 7, 8],\n [9, 10, 11, 12],\n [13, 14, 15, 16],\n]]], dtype=np.float32)\n\nscales = np.array([1.0, 1.0, 0.8, 0.8], dtype=np.float32)\n\n# [[[[ 1.47119141 2.78125 4.08251953]\n# [ 6.71142578 8.02148438 9.32275391]\n# [11.91650391 13.2265625 14.52783203]]]]\noutput = interpolate_nd(\n data, cubic_coeffs, scale_factors=scales).astype(np.float32)\n\nexpect(node, inputs=[data, scales], outputs=[output],\n name='test_resize_downsample_scales_cubic')" + }, + { + "summary": "resize_downsample_scales_cubic_A_n0p5_exclude_outside", + "code": "node = onnx.helper.make_node(\n 'Resize',\n inputs=['X', '', 'scales'],\n outputs=['Y'],\n mode='cubic',\n cubic_coeff_a=-0.5,\n exclude_outside=True\n)\n\ndata = np.array([[[\n [1, 2, 3, 4],\n [5, 6, 7, 8],\n [9, 10, 11, 12],\n [13, 14, 15, 16],\n]]], dtype=np.float32)\n\nscales = np.array([1.0, 1.0, 0.8, 0.8], dtype=np.float32)\n\n# [[[[ 1.36812675 2.6695014 4.0133367 ]\n# [ 6.57362535 7.875 9.2188353 ]\n# [11.94896657 13.25034122 14.59417652]]]]\noutput = interpolate_nd(data, lambda x: cubic_coeffs(x, A=-0.5), scale_factors=scales,\n exclude_outside=True).astype(np.float32)\n\nexpect(node, inputs=[data, scales], outputs=[output],\n name='test_resize_downsample_scales_cubic_A_n0p5_exclude_outside')" + }, + { + "summary": "resize_downsample_scales_cubic_align_corners", + "code": "node = onnx.helper.make_node(\n 'Resize',\n inputs=['X', '', 'scales'],\n outputs=['Y'],\n mode='cubic',\n coordinate_transformation_mode='align_corners'\n)\n\ndata = np.array([[[\n [1, 2, 3, 4],\n [5, 6, 7, 8],\n [9, 10, 11, 12],\n [13, 14, 15, 16],\n]]], dtype=np.float32)\n\nscales = np.array([1.0, 1.0, 0.8, 0.8], dtype=np.float32)\n\n# [[[[ 1. 2.39519159 3.79038317]\n# [ 6.58076634 7.97595793 9.37114951]\n# [12.16153268 13.55672427 14.95191585]]]]\noutput = interpolate_nd(\n data, cubic_coeffs, scale_factors=scales, coordinate_transformation_mode='align_corners').astype(np.float32)\n\nexpect(node, inputs=[data, scales], outputs=[output],\n name='test_resize_downsample_scales_cubic_align_corners')" + }, + { + "summary": "resize_downsample_scales_linear", + "code": "node = onnx.helper.make_node(\n 'Resize',\n inputs=['X', '', 'scales'],\n outputs=['Y'],\n mode='linear',\n)\n\ndata = np.array([[[\n [1, 2, 3, 4],\n [5, 6, 7, 8],\n]]], dtype=np.float32)\n\nscales = np.array([1.0, 1.0, 0.6, 0.6], dtype=np.float32)\n\n# [[[[2.6666665 4.3333331]]]]\noutput = interpolate_nd(\n data, linear_coeffs, scale_factors=scales).astype(np.float32)\n\nexpect(node, inputs=[data, scales], outputs=[output],\n name='test_resize_downsample_scales_linear')" + }, + { + "summary": "resize_downsample_scales_linear_align_corners", + "code": "node = onnx.helper.make_node(\n 'Resize',\n inputs=['X', '', 'scales'],\n outputs=['Y'],\n mode='linear',\n coordinate_transformation_mode='align_corners'\n)\n\ndata = np.array([[[\n [1, 2, 3, 4],\n [5, 6, 7, 8],\n]]], dtype=np.float32)\n\nscales = np.array([1.0, 1.0, 0.6, 0.6], dtype=np.float32)\n\n# [[[[1. 3.142857]]]]\noutput = interpolate_nd(\n data, linear_coeffs, scale_factors=scales, coordinate_transformation_mode='align_corners').astype(np.float32)\n\nexpect(node, inputs=[data, scales], outputs=[output],\n name='test_resize_downsample_scales_linear_align_corners')" + }, + { + "summary": "resize_downsample_scales_nearest", + "code": "node = onnx.helper.make_node(\n 'Resize',\n inputs=['X', '', 'scales'],\n outputs=['Y'],\n mode='nearest',\n)\n\ndata = np.array([[[\n [1, 2, 3, 4],\n [5, 6, 7, 8],\n]]], dtype=np.float32)\n\nscales = np.array([1.0, 1.0, 0.6, 0.6], dtype=np.float32)\n\n# [[[[1. 3.]]]]\noutput = interpolate_nd(\n data, nearest_coeffs, scale_factors=scales).astype(np.float32)\n\nexpect(node, inputs=[data, scales], outputs=[output],\n name='test_resize_downsample_scales_nearest')" + }, + { + "summary": "resize_downsample_sizes_cubic", + "code": "node = onnx.helper.make_node(\n 'Resize',\n inputs=['X', '', '', 'sizes'],\n outputs=['Y'],\n mode='cubic',\n)\n\ndata = np.array([[[\n [1, 2, 3, 4],\n [5, 6, 7, 8],\n [9, 10, 11, 12],\n [13, 14, 15, 16],\n]]], dtype=np.float32)\n\nsizes = np.array([1, 1, 3, 3], dtype=np.int64)\n\n# [[[[ 1.63078704 3.00462963 4.37847222]\n# [ 7.12615741 8.5 9.87384259]\n# [12.62152778 13.99537037 15.36921296]]]]\noutput = interpolate_nd(\n data, cubic_coeffs, output_size=sizes).astype(np.float32)\n\nexpect(node, inputs=[data, sizes], outputs=[output],\n name='test_resize_downsample_sizes_cubic')" + }, + { + "summary": "resize_downsample_sizes_linear_pytorch_half_pixel", + "code": "node = onnx.helper.make_node(\n 'Resize',\n inputs=['X', '', '', 'sizes'],\n outputs=['Y'],\n mode='linear',\n coordinate_transformation_mode='pytorch_half_pixel'\n)\n\ndata = np.array([[[\n [1, 2, 3, 4],\n [5, 6, 7, 8],\n [9, 10, 11, 12],\n [13, 14, 15, 16],\n]]], dtype=np.float32)\n\nsizes = np.array([1, 1, 3, 1], dtype=np.int64)\n\n# [[[[ 1.6666666]\n# [ 7. ]\n# [12.333333 ]]]]\noutput = interpolate_nd(\n data, linear_coeffs, output_size=sizes, coordinate_transformation_mode='pytorch_half_pixel').astype(np.float32)\n\nexpect(node, inputs=[data, sizes], outputs=[output],\n name='test_resize_downsample_sizes_linear_pytorch_half_pixel')" + }, + { + "summary": "resize_downsample_sizes_nearest", + "code": "node = onnx.helper.make_node(\n 'Resize',\n inputs=['X', '', '', 'sizes'],\n outputs=['Y'],\n mode='nearest',\n)\n\ndata = np.array([[[\n [1, 2, 3, 4],\n [5, 6, 7, 8],\n]]], dtype=np.float32)\n\nsizes = np.array([1, 1, 1, 3], dtype=np.int64)\n\n# [[[[1. 3.]]]]\noutput = interpolate_nd(\n data, nearest_coeffs, output_size=sizes).astype(np.float32)\n\nexpect(node, inputs=[data, sizes], outputs=[output],\n name='test_resize_downsample_sizes_nearest')" + }, + { + "summary": "resize_tf_crop_and_resize", + "code": "node = onnx.helper.make_node(\n 'Resize',\n inputs=['X', 'roi', '', 'sizes'],\n outputs=['Y'],\n mode='linear',\n coordinate_transformation_mode='tf_crop_and_resize'\n)\n\ndata = np.array([[[\n [1, 2, 3, 4],\n [5, 6, 7, 8],\n [9, 10, 11, 12],\n [13, 14, 15, 16],\n]]], dtype=np.float32)\n\n# Note: for some rois, the result may be different with that of TF for inaccurate floating point\nroi = np.array([0, 0, 0.4, 0.6, 1, 1, 0.6, 0.8], dtype=np.float32)\nsizes = np.array([1, 1, 3, 3], dtype=np.int64)\n\n# [[[[ 7.6000004 7.9 8.2 ]\n# [ 8.8 9.1 9.400001 ]\n# [10. 10.3 10.6 ]]]]\noutput = interpolate_nd(data, linear_coeffs, output_size=sizes, roi=roi,\n coordinate_transformation_mode='tf_crop_and_resize').astype(np.float32)\n\nexpect(node, inputs=[data, roi, sizes], outputs=[output],\n name='test_resize_tf_crop_and_resize')" + }, + { + "summary": "resize_tf_crop_and_resize_extrapolation_value", + "code": "node = onnx.helper.make_node(\n 'Resize',\n inputs=['X', 'roi', '', 'sizes'],\n outputs=['Y'],\n mode='linear',\n coordinate_transformation_mode='tf_crop_and_resize',\n extrapolation_value=10.0\n)\n\ndata = np.array([[[\n [1, 2, 3, 4],\n [5, 6, 7, 8],\n [9, 10, 11, 12],\n [13, 14, 15, 16],\n]]], dtype=np.float32)\n\n# Note: for some rois, the result may be different with that of TF for inaccurate floating point\nroi = np.array([0, 0, 0.4, 0.6, 1, 1, 1.2, 1.7], dtype=np.float32)\nsizes = np.array([1, 1, 3, 3], dtype=np.int64)\n\n# [[[[ 7.6000004 10. 10. ]\n# [12.400001 10. 10. ]\n# [10. 10. 10. ]]]]\noutput = interpolate_nd(data, linear_coeffs, output_size=sizes, roi=roi,\n coordinate_transformation_mode='tf_crop_and_resize', extrapolation_value=10.0).astype(np.float32)\n\nexpect(node, inputs=[data, roi, sizes], outputs=[output],\n name='test_resize_tf_crop_and_resize')" + }, + { + "summary": "resize_upsample_scales_cubic", + "code": "node = onnx.helper.make_node(\n 'Resize',\n inputs=['X', '', 'scales'],\n outputs=['Y'],\n mode='cubic',\n)\n\ndata = np.array([[[\n [1, 2, 3, 4],\n [5, 6, 7, 8],\n [9, 10, 11, 12],\n [13, 14, 15, 16],\n]]], dtype=np.float32)\n\nscales = np.array([1.0, 1.0, 2.0, 2.0], dtype=np.float32)\n\n# [[[[ 0.47265625 0.76953125 1.24609375 1.875 2.28125\n# 2.91015625 3.38671875 3.68359375]\n# [ 1.66015625 1.95703125 2.43359375 3.0625 3.46875\n# 4.09765625 4.57421875 4.87109375]\n# [ 3.56640625 3.86328125 4.33984375 4.96875 5.375\n# 6.00390625 6.48046875 6.77734375]\n# [ 6.08203125 6.37890625 6.85546875 7.484375 7.890625\n# 8.51953125 8.99609375 9.29296875]\n# [ 7.70703125 8.00390625 8.48046875 9.109375 9.515625\n# 10.14453125 10.62109375 10.91796875]\n# [10.22265625 10.51953125 10.99609375 11.625 12.03125\n# 12.66015625 13.13671875 13.43359375]\n# [12.12890625 12.42578125 12.90234375 13.53125 13.9375\n# 14.56640625 15.04296875 15.33984375]\n# [13.31640625 13.61328125 14.08984375 14.71875 15.125\n# 15.75390625 16.23046875 16.52734375]]]]\noutput = interpolate_nd(\n data, cubic_coeffs, scale_factors=scales).astype(np.float32)\n\nexpect(node, inputs=[data, scales], outputs=[output],\n name='test_resize_upsample_scales_cubic')" + }, + { + "summary": "resize_upsample_scales_cubic_A_n0p5_exclude_outside", + "code": "node = onnx.helper.make_node(\n 'Resize',\n inputs=['X', '', 'scales'],\n outputs=['Y'],\n mode='cubic',\n cubic_coeff_a=-0.5,\n exclude_outside=True\n)\n\ndata = np.array([[[\n [1, 2, 3, 4],\n [5, 6, 7, 8],\n [9, 10, 11, 12],\n [13, 14, 15, 16],\n]]], dtype=np.float32)\n\nscales = np.array([1.0, 1.0, 2.0, 2.0], dtype=np.float32)\n\n# [[[[ 0.55882353 0.81494204 1.35698249 1.89705882 2.39705882\n# 2.93713516 3.47917561 3.73529412]\n# [ 1.58329755 1.83941606 2.38145651 2.92153285 3.42153285\n# 3.96160918 4.50364964 4.75976814]\n# [ 3.75145936 4.00757787 4.54961832 5.08969466 5.58969466\n# 6.12977099 6.67181144 6.92792995]\n# [ 5.91176471 6.16788321 6.70992366 7.25 7.75\n# 8.29007634 8.83211679 9.08823529]\n# [ 7.91176471 8.16788321 8.70992366 9.25 9.75\n# 10.29007634 10.83211679 11.08823529]\n# [10.07207005 10.32818856 10.87022901 11.41030534 11.91030534\n# 12.45038168 12.99242213 13.24854064]\n# [12.24023186 12.49635036 13.03839082 13.57846715 14.07846715\n# 14.61854349 15.16058394 15.41670245]\n# [13.26470588 13.52082439 14.06286484 14.60294118 15.10294118\n# 15.64301751 16.18505796 16.44117647]]]]\noutput = interpolate_nd(data, lambda x: cubic_coeffs(x, A=-0.5), scale_factors=scales,\n exclude_outside=True).astype(np.float32)\n\nexpect(node, inputs=[data, scales], outputs=[output],\n name='test_resize_upsample_scales_cubic_A_n0p5_exclude_outside')" + }, + { + "summary": "resize_upsample_scales_cubic_align_corners", + "code": "node = onnx.helper.make_node(\n 'Resize',\n inputs=['X', '', 'scales'],\n outputs=['Y'],\n mode='cubic',\n coordinate_transformation_mode='align_corners'\n)\n\ndata = np.array([[[\n [1, 2, 3, 4],\n [5, 6, 7, 8],\n [9, 10, 11, 12],\n [13, 14, 15, 16],\n]]], dtype=np.float32)\n\nscales = np.array([1.0, 1.0, 2.0, 2.0], dtype=np.float32)\n\n# [[[[ 1. 1.34110787 1.80029155 2.32944606 2.67055394\n# 3.19970845 3.65889213 4. ]\n# [ 2.36443149 2.70553936 3.16472303 3.69387755 4.03498542\n# 4.56413994 5.02332362 5.36443149]\n# [ 4.20116618 4.54227405 5.00145773 5.53061224 5.87172012\n# 6.40087464 6.86005831 7.20116618]\n# [ 6.31778426 6.65889213 7.1180758 7.64723032 7.98833819\n# 8.51749271 8.97667638 9.31778426]\n# [ 7.68221574 8.02332362 8.48250729 9.01166181 9.35276968\n# 9.8819242 10.34110787 10.68221574]\n# [ 9.79883382 10.13994169 10.59912536 11.12827988 11.46938776\n# 11.99854227 12.45772595 12.79883382]\n# [11.63556851 11.97667638 12.43586006 12.96501458 13.30612245\n# 13.83527697 14.29446064 14.63556851]\n# [13. 13.34110787 13.80029155 14.32944606 14.67055394\n# 15.19970845 15.65889213 16. ]]]]\noutput = interpolate_nd(\n data, cubic_coeffs, scale_factors=scales, coordinate_transformation_mode='align_corners').astype(np.float32)\n\nexpect(node, inputs=[data, scales], outputs=[output],\n name='test_resize_upsample_scales_cubic_align_corners')" + }, + { + "summary": "resize_upsample_scales_cubic_asymmetric", + "code": "node = onnx.helper.make_node(\n 'Resize',\n inputs=['X', '', 'scales'],\n outputs=['Y'],\n mode='cubic',\n coordinate_transformation_mode='asymmetric'\n)\n\ndata = np.array([[[\n [1, 2, 3, 4],\n [5, 6, 7, 8],\n [9, 10, 11, 12],\n [13, 14, 15, 16],\n]]], dtype=np.float32)\n\nscales = np.array([1.0, 1.0, 2.0, 2.0], dtype=np.float32)\n\n# [[[[ 1. 1.40625 2. 2.5 3. 3.59375 4.\n# 4.09375]\n# [ 2.625 3.03125 3.625 4.125 4.625 5.21875 5.625\n# 5.71875]\n# [ 5. 5.40625 6. 6.5 7. 7.59375 8.\n# 8.09375]\n# [ 7. 7.40625 8. 8.5 9. 9.59375 10.\n# 10.09375]\n# [ 9. 9.40625 10. 10.5 11. 11.59375 12.\n# 12.09375]\n# [11.375 11.78125 12.375 12.875 13.375 13.96875 14.375\n# 14.46875]\n# [13. 13.40625 14. 14.5 15. 15.59375 16.\n# 16.09375]\n# [13.375 13.78125 14.375 14.875 15.375 15.96875 16.375\n# 16.46875]]]]\noutput = interpolate_nd(data, lambda x: cubic_coeffs(x, A=-0.75), scale_factors=scales,\n coordinate_transformation_mode='asymmetric').astype(np.float32)\n\nexpect(node, inputs=[data, scales], outputs=[output],\n name='test_resize_upsample_scales_cubic_asymmetric')" + }, + { + "summary": "resize_upsample_scales_linear", + "code": "node = onnx.helper.make_node(\n 'Resize',\n inputs=['X', '', 'scales'],\n outputs=['Y'],\n mode='linear',\n)\n\ndata = np.array([[[\n [1, 2],\n [3, 4],\n]]], dtype=np.float32)\n\nscales = np.array([1.0, 1.0, 2.0, 2.0], dtype=np.float32)\n\n# [[[[1. 1.25 1.75 2. ]\n# [1.5 1.75 2.25 2.5 ]\n# [2.5 2.75 3.25 3.5 ]\n# [3. 3.25 3.75 4. ]]]]\noutput = interpolate_nd(\n data, linear_coeffs, scale_factors=scales).astype(np.float32)\n\nexpect(node, inputs=[data, scales], outputs=[output],\n name='test_resize_upsample_scales_linear')" + }, + { + "summary": "resize_upsample_scales_linear_align_corners", + "code": "node = onnx.helper.make_node(\n 'Resize',\n inputs=['X', '', 'scales'],\n outputs=['Y'],\n mode='linear',\n coordinate_transformation_mode='align_corners'\n)\n\ndata = np.array([[[\n [1, 2],\n [3, 4],\n]]], dtype=np.float32)\n\nscales = np.array([1.0, 1.0, 2.0, 2.0], dtype=np.float32)\n\n# [[[[1. 1.33333333 1.66666667 2. ]\n# [1.66666667 2. 2.33333333 2.66666667]\n# [2.33333333 2.66666667 3. 3.33333333]\n# [3. 3.33333333 3.66666667 4. ]]]]\noutput = interpolate_nd(\n data, linear_coeffs, scale_factors=scales, coordinate_transformation_mode='align_corners').astype(np.float32)\n\nexpect(node, inputs=[data, scales], outputs=[output],\n name='test_resize_upsample_scales_linear_align_corners')" + }, + { + "summary": "resize_upsample_scales_nearest", + "code": "node = onnx.helper.make_node(\n 'Resize',\n inputs=['X', '', 'scales'],\n outputs=['Y'],\n mode='nearest',\n)\n\ndata = np.array([[[\n [1, 2],\n [3, 4],\n]]], dtype=np.float32)\n\nscales = np.array([1.0, 1.0, 2.0, 3.0], dtype=np.float32)\n\n# [[[[1. 1. 1. 2. 2. 2.]\n# [1. 1. 1. 2. 2. 2.]\n# [3. 3. 3. 4. 4. 4.]\n# [3. 3. 3. 4. 4. 4.]]]]\noutput = interpolate_nd(\n data, nearest_coeffs, scale_factors=scales).astype(np.float32)\n\nexpect(node, inputs=[data, scales], outputs=[output],\n name='test_resize_upsample_scales_nearest')" + }, + { + "summary": "resize_upsample_sizes_cubic", + "code": "node = onnx.helper.make_node(\n 'Resize',\n inputs=['X', '', '', 'sizes'],\n outputs=['Y'],\n mode='cubic',\n)\n\ndata = np.array([[[\n [1, 2, 3, 4],\n [5, 6, 7, 8],\n [9, 10, 11, 12],\n [13, 14, 15, 16],\n]]], dtype=np.float32)\n\nsizes = np.array([1, 1, 9, 10], dtype=np.int64)\n\n# [[[[ 0.45507922 0.64057922 0.97157922 1.42257922 1.90732922\n# 2.22332922 2.70807922 3.15907922 3.49007922 3.67557922]\n# [ 1.39437963 1.57987963 1.91087963 2.36187963 2.84662963\n# 3.16262963 3.64737963 4.09837963 4.42937963 4.61487963]\n# [ 2.95130693 3.13680693 3.46780693 3.91880693 4.40355693\n# 4.71955693 5.20430693 5.65530693 5.98630693 6.17180693]\n# [ 5.20525069 5.39075069 5.72175069 6.17275069 6.65750069\n# 6.97350069 7.45825069 7.90925069 8.24025069 8.42575069]\n# [ 6.88975 7.07525 7.40625 7.85725 8.342\n# 8.658 9.14275 9.59375 9.92475 10.11025 ]\n# [ 8.57424931 8.75974931 9.09074931 9.54174931 10.02649931\n# 10.34249931 10.82724931 11.27824931 11.60924931 11.79474931]\n# [10.82819307 11.01369307 11.34469307 11.79569307 12.28044307\n# 12.59644307 13.08119307 13.53219307 13.86319307 14.04869307]\n# [12.38512037 12.57062037 12.90162037 13.35262037 13.83737037\n# 14.15337037 14.63812037 15.08912037 15.42012037 15.60562037]\n# [13.32442078 13.50992078 13.84092078 14.29192078 14.77667078\n# 15.09267078 15.57742078 16.02842078 16.35942078 16.54492078]]]]\noutput = interpolate_nd(\n data, cubic_coeffs, output_size=sizes).astype(np.float32)\n\nexpect(node, inputs=[data, sizes], outputs=[output],\n name='test_resize_upsample_sizes_cubic')" + }, + { + "summary": "resize_upsample_sizes_nearest", + "code": "node = onnx.helper.make_node(\n 'Resize',\n inputs=['X', '', '', 'sizes'],\n outputs=['Y'],\n mode='nearest',\n)\n\ndata = np.array([[[\n [1, 2],\n [3, 4],\n]]], dtype=np.float32)\n\nsizes = np.array([1, 1, 7, 8], dtype=np.int64)\n\n# [[[[1. 1. 1. 1. 2. 2. 2. 2.]\n# [1. 1. 1. 1. 2. 2. 2. 2.]\n# [1. 1. 1. 1. 2. 2. 2. 2.]\n# [1. 1. 1. 1. 2. 2. 2. 2.]\n# [3. 3. 3. 3. 4. 4. 4. 4.]\n# [3. 3. 3. 3. 4. 4. 4. 4.]\n# [3. 3. 3. 3. 4. 4. 4. 4.]]]]\noutput = interpolate_nd(\n data, nearest_coeffs, output_size=sizes).astype(np.float32)\n\nexpect(node, inputs=[data, sizes], outputs=[output],\n name='test_resize_upsample_sizes_nearest')" + }, + { + "summary": "resize_upsample_sizes_nearest_ceil_half_pixel", + "code": "node = onnx.helper.make_node(\n 'Resize',\n inputs=['X', '', '', 'sizes'],\n outputs=['Y'],\n mode='nearest',\n coordinate_transformation_mode='half_pixel',\n nearest_mode='ceil'\n)\n\ndata = np.array([[[\n [1, 2, 3, 4],\n [5, 6, 7, 8],\n [9, 10, 11, 12],\n [13, 14, 15, 16],\n]]], dtype=np.float32)\n\nsizes = np.array([1, 1, 8, 8], dtype=np.int64)\n\n# [[[[ 1. 2. 2. 3. 3. 4. 4. 4.]\n# [ 5. 6. 6. 7. 7. 8. 8. 8.]\n# [ 5. 6. 6. 7. 7. 8. 8. 8.]\n# [ 9. 10. 10. 11. 11. 12. 12. 12.]\n# [ 9. 10. 10. 11. 11. 12. 12. 12.]\n# [13. 14. 14. 15. 15. 16. 16. 16.]\n# [13. 14. 14. 15. 15. 16. 16. 16.]\n# [13. 14. 14. 15. 15. 16. 16. 16.]]]]\noutput = interpolate_nd(\n data, lambda x: nearest_coeffs(x, mode='ceil'), output_size=sizes).astype(np.float32)\n\nexpect(node, inputs=[data, sizes], outputs=[output],\n name='test_resize_upsample_sizes_nearest_ceil_half_pixel')" + }, + { + "summary": "resize_upsample_sizes_nearest_floor_align_corners", + "code": "node = onnx.helper.make_node(\n 'Resize',\n inputs=['X', '', '', 'sizes'],\n outputs=['Y'],\n mode='nearest',\n coordinate_transformation_mode='align_corners',\n nearest_mode='floor'\n)\n\ndata = np.array([[[\n [1, 2, 3, 4],\n [5, 6, 7, 8],\n [9, 10, 11, 12],\n [13, 14, 15, 16],\n]]], dtype=np.float32)\n\nsizes = np.array([1, 1, 8, 8], dtype=np.int64)\n\n# [[[[ 1. 1. 1. 2. 2. 3. 3. 4.]\n# [ 1. 1. 1. 2. 2. 3. 3. 4.]\n# [ 1. 1. 1. 2. 2. 3. 3. 4.]\n# [ 5. 5. 5. 6. 6. 7. 7. 8.]\n# [ 5. 5. 5. 6. 6. 7. 7. 8.]\n# [ 9. 9. 9. 10. 10. 11. 11. 12.]\n# [ 9. 9. 9. 10. 10. 11. 11. 12.]\n# [13. 13. 13. 14. 14. 15. 15. 16.]]]]\noutput = interpolate_nd(\n data, lambda x: nearest_coeffs(x, mode='floor'), output_size=sizes, coordinate_transformation_mode='align_corners').astype(np.float32)\n\nexpect(node, inputs=[data, sizes], outputs=[output],\n name='test_resize_upsample_sizes_nearest_floor_align_corners')" + }, + { + "summary": "resize_upsample_sizes_nearest_round_prefer_ceil_asymmetric", + "code": "node = onnx.helper.make_node(\n 'Resize',\n inputs=['X', '', '', 'sizes'],\n outputs=['Y'],\n mode='nearest',\n coordinate_transformation_mode='asymmetric',\n nearest_mode='round_prefer_ceil'\n)\n\ndata = np.array([[[\n [1, 2, 3, 4],\n [5, 6, 7, 8],\n [9, 10, 11, 12],\n [13, 14, 15, 16],\n]]], dtype=np.float32)\n\nsizes = np.array([1, 1, 8, 8], dtype=np.int64)\n\n# [[[[ 1. 2. 2. 3. 3. 4. 4. 4.]\n# [ 5. 6. 6. 7. 7. 8. 8. 8.]\n# [ 5. 6. 6. 7. 7. 8. 8. 8.]\n# [ 9. 10. 10. 11. 11. 12. 12. 12.]\n# [ 9. 10. 10. 11. 11. 12. 12. 12.]\n# [13. 14. 14. 15. 15. 16. 16. 16.]\n# [13. 14. 14. 15. 15. 16. 16. 16.]\n# [13. 14. 14. 15. 15. 16. 16. 16.]]]]\noutput = interpolate_nd(\n data, lambda x: nearest_coeffs(x, mode='round_prefer_ceil'),\n output_size=sizes, coordinate_transformation_mode='asymmetric').astype(np.float32)\n\nexpect(node, inputs=[data, sizes], outputs=[output],\n name='test_resize_upsample_sizes_nearest_round_prefer_ceil_asymmetric')" + } + ] + }, + { + "name": "ReverseSequence", + "module": "ai.onnx", + "version": 10, + "support_level": "common", + "description": "Reverse batch of sequences having different lengths specified by `sequence_lens`.\n\nFor each slice i iterating on batch axis, the operator reverses the first sequence_lens[i] elements on time axis,\nand copies elements whose index's beyond sequence_lens[i] to the output. So the output slice i contains reversed\nsequences on the first sequence_lens[i] elements, then have original values copied for the other elements.\n\nExample 1:\n input = [[0.0, 4.0, 8.0, 12.0],\n [1.0, 5.0, 9.0, 13.0],\n [2.0, 6.0, 10.0, 14.0],\n [3.0, 7.0, 11.0, 15.0]]\n sequence_lens = [4, 3, 2, 1]\n time_axis = 0\n batch_axis = 1\n\n output = [[3.0, 6.0, 9.0, 12.0],\n [2.0, 5.0, 8.0, 13.0],\n [1.0, 4.0, 10.0, 14.0],\n [0.0, 7.0, 11.0, 15.0]]\n\nExample 2:\n input = [[0.0, 1.0, 2.0, 3.0 ],\n [4.0, 5.0, 6.0, 7.0 ],\n [8.0, 9.0, 10.0, 11.0],\n [12.0, 13.0, 14.0, 15.0]]\n sequence_lens = [1, 2, 3, 4]\n time_axis = 1\n batch_axis = 0\n\n output = [[0.0, 1.0, 2.0, 3.0 ],\n [5.0, 4.0, 6.0, 7.0 ],\n [10.0, 9.0, 8.0, 11.0],\n [15.0, 14.0, 13.0, 12.0]]\n", + "attributes": [ + { + "name": "batch_axis", + "type": "int64", + "required": false, + "default": 1, + "description": "(Optional) Specify which axis is batch axis. Must be one of 1 (default), or 0." + }, + { + "name": "time_axis", + "type": "int64", + "required": false, + "description": "(Optional) Specify which axis is time axis. Must be one of 0 (default), or 1." + } + ], + "inputs": [ + { + "name": "input", + "type": "T", + "description": "Tensor of rank r >= 2." + }, + { + "name": "sequence_lens", + "type": "tensor(int64)", + "description": "Tensor specifying lengths of the sequences in a batch. It has shape `[batch_size]`." + } + ], + "min_input": 2, + "max_input": 2, + "outputs": [ + { + "name": "Y", + "type": "T", + "description": "Tensor with same shape of input." + } + ], + "min_output": 1, + "max_output": 1, + "type_constraints": [ + { + "description": "Input and output types can be of any tensor type.", + "type_param_str": "T", + "allowed_type_strs": [ + "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)" + ] + } + ], + "examples": [ + { + "summary": "reversesequence_batch", + "code": "node = onnx.helper.make_node(\n 'ReverseSequence',\n inputs=['x', 'sequence_lens'],\n outputs=['y'],\n time_axis=1,\n batch_axis=0,\n)\nx = np.array([[0.0, 1.0, 2.0, 3.0],\n [4.0, 5.0, 6.0, 7.0],\n [8.0, 9.0, 10.0, 11.0],\n [12.0, 13.0, 14.0, 15.0]], dtype=np.float32)\nsequence_lens = np.array([1, 2, 3, 4], dtype=np.int64)\n\ny = np.array([[0.0, 1.0, 2.0, 3.0],\n [5.0, 4.0, 6.0, 7.0],\n [10.0, 9.0, 8.0, 11.0],\n [15.0, 14.0, 13.0, 12.0]], dtype=np.float32)\n\nexpect(node, inputs=[x, sequence_lens], outputs=[y],\n name='test_reversesequence_batch')" + }, + { + "summary": "reversesequence_time", + "code": "node = onnx.helper.make_node(\n 'ReverseSequence',\n inputs=['x', 'sequence_lens'],\n outputs=['y'],\n time_axis=0,\n batch_axis=1,\n)\nx = np.array([[0.0, 4.0, 8.0, 12.0],\n [1.0, 5.0, 9.0, 13.0],\n [2.0, 6.0, 10.0, 14.0],\n [3.0, 7.0, 11.0, 15.0]], dtype=np.float32)\nsequence_lens = np.array([4, 3, 2, 1], dtype=np.int64)\n\ny = np.array([[3.0, 6.0, 9.0, 12.0],\n [2.0, 5.0, 8.0, 13.0],\n [1.0, 4.0, 10.0, 14.0],\n [0.0, 7.0, 11.0, 15.0]], dtype=np.float32)\n\nexpect(node, inputs=[x, sequence_lens], outputs=[y],\n name='test_reversesequence_time')" + } + ] + }, + { + "name": "RoiAlign", + "module": "ai.onnx", + "version": 10, + "support_level": "common", + "description": "Region of Interest (RoI) align operation described in the\n[Mask R-CNN paper](https://arxiv.org/abs/1703.06870).\nRoiAlign consumes an input tensor X and region of interests (rois)\nto apply pooling across each RoI; it produces a 4-D tensor of shape\n(num_rois, C, output_height, output_width).\n\nRoiAlign is proposed to avoid the misalignment by removing\nquantizations while converting from original image into feature\nmap and from feature map into RoI feature; in each ROI bin,\nthe value of the sampled locations are computed directly\nthrough bilinear interpolation.\n", + "attributes": [ + { + "name": "mode", + "type": "string", + "required": false, + "default": "avg", + "description": "The pooling method. Two modes are supported: 'avg' and 'max'. Default is 'avg'." + }, + { + "name": "output_height", + "type": "int64", + "required": false, + "default": 1, + "description": "default 1; Pooled output Y's height." + }, + { + "name": "output_width", + "type": "int64", + "required": false, + "default": 1, + "description": "default 1; Pooled output Y's width." + }, + { + "name": "sampling_ratio", + "type": "int64", + "required": false, + "description": "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." + }, + { + "name": "spatial_scale", + "type": "float32", + "required": false, + "default": 1.0, + "description": "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": [ + { + "name": "X", + "type": "T1", + "description": "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." + }, + { + "name": "rois", + "type": "T1", + "description": "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." + }, + { + "name": "batch_indices", + "type": "T2", + "description": "1-D tensor of shape (num_rois,) with each element denoting the index of the corresponding image in the batch." + } + ], + "min_input": 3, + "max_input": 3, + "outputs": [ + { + "name": "Y", + "type": "T1", + "description": "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]." + } + ], + "min_output": 1, + "max_output": 1, + "type_constraints": [ + { + "description": "Constrain types to float tensors.", + "type_param_str": "T1", + "allowed_type_strs": [ + "tensor(float16)", + "tensor(float)", + "tensor(double)" + ] + }, + { + "description": "Constrain types to int tensors.", + "type_param_str": "T2", + "allowed_type_strs": [ + "tensor(int64)" + ] + } + ], + "examples": [ + { + "summary": "roialign_aligned_false", + "code": "node = onnx.helper.make_node(\n \"RoiAlign\",\n inputs=[\"X\", \"rois\", \"batch_indices\"],\n outputs=[\"Y\"],\n spatial_scale=1.0,\n output_height=5,\n output_width=5,\n sampling_ratio=2,\n coordinate_transformation_mode=\"output_half_pixel\",\n)\n\nX, batch_indices, rois = get_roi_align_input_values()\n# (num_rois, C, output_height, output_width)\nY = np.array(\n [\n [\n [\n [0.4664, 0.4466, 0.3405, 0.5688, 0.6068],\n [0.3714, 0.4296, 0.3835, 0.5562, 0.3510],\n [0.2768, 0.4883, 0.5222, 0.5528, 0.4171],\n [0.4713, 0.4844, 0.6904, 0.4920, 0.8774],\n [0.6239, 0.7125, 0.6289, 0.3355, 0.3495],\n ]\n ],\n [\n [\n [0.3022, 0.4305, 0.4696, 0.3978, 0.5423],\n [0.3656, 0.7050, 0.5165, 0.3172, 0.7015],\n [0.2912, 0.5059, 0.6476, 0.6235, 0.8299],\n [0.5916, 0.7389, 0.7048, 0.8372, 0.8893],\n [0.6227, 0.6153, 0.7097, 0.6154, 0.4585],\n ]\n ],\n [\n [\n [0.2384, 0.3379, 0.3717, 0.6100, 0.7601],\n [0.3767, 0.3785, 0.7147, 0.9243, 0.9727],\n [0.5749, 0.5826, 0.5709, 0.7619, 0.8770],\n [0.5355, 0.2566, 0.2141, 0.2796, 0.3600],\n [0.4365, 0.3504, 0.2887, 0.3661, 0.2349],\n ]\n ],\n ],\n dtype=np.float32,\n)\n\nexpect(node, inputs=[X, rois, batch_indices], outputs=[Y], name=\"test_roialign_aligned_false\")" + }, + { + "summary": "roialign_aligned_true", + "code": "node = onnx.helper.make_node(\n \"RoiAlign\",\n inputs=[\"X\", \"rois\", \"batch_indices\"],\n outputs=[\"Y\"],\n spatial_scale=1.0,\n output_height=5,\n output_width=5,\n sampling_ratio=2,\n coordinate_transformation_mode=\"half_pixel\",\n)\n\nX, batch_indices, rois = get_roi_align_input_values()\n# (num_rois, C, output_height, output_width)\nY = np.array(\n [\n [\n [\n [0.5178, 0.3434, 0.3229, 0.4474, 0.6344],\n [0.4031, 0.5366, 0.4428, 0.4861, 0.4023],\n [0.2512, 0.4002, 0.5155, 0.6954, 0.3465],\n [0.3350, 0.4601, 0.5881, 0.3439, 0.6849],\n [0.4932, 0.7141, 0.8217, 0.4719, 0.4039],\n ]\n ],\n [\n [\n [0.3070, 0.2187, 0.3337, 0.4880, 0.4870],\n [0.1871, 0.4914, 0.5561, 0.4192, 0.3686],\n [0.1433, 0.4608, 0.5971, 0.5310, 0.4982],\n [0.2788, 0.4386, 0.6022, 0.7000, 0.7524],\n [0.5774, 0.7024, 0.7251, 0.7338, 0.8163],\n ]\n ],\n [\n [\n [0.2393, 0.4075, 0.3379, 0.2525, 0.4743],\n [0.3671, 0.2702, 0.4105, 0.6419, 0.8308],\n [0.5556, 0.4543, 0.5564, 0.7502, 0.9300],\n [0.6626, 0.5617, 0.4813, 0.4954, 0.6663],\n [0.6636, 0.3721, 0.2056, 0.1928, 0.2478],\n ]\n ],\n ],\n dtype=np.float32,\n)\n\nexpect(node, inputs=[X, rois, batch_indices], outputs=[Y], name=\"test_roialign_aligned_true\")" + } + ] + }, + { + "name": "RoiAlign", + "module": "ai.onnx", + "version": 16, + "support_level": "common", + "description": "Region of Interest (RoI) align operation described in the\n[Mask R-CNN paper](https://arxiv.org/abs/1703.06870).\nRoiAlign consumes an input tensor X and region of interests (rois)\nto apply pooling across each RoI; it produces a 4-D tensor of shape\n(num_rois, C, output_height, output_width).\n\nRoiAlign is proposed to avoid the misalignment by removing\nquantizations while converting from original image into feature\nmap and from feature map into RoI feature; in each ROI bin,\nthe value of the sampled locations are computed directly\nthrough bilinear interpolation.\n", + "attributes": [ + { + "name": "coordinate_transformation_mode", + "type": "string", + "required": false, + "default": "half_pixel", + "description": "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)." + }, + { + "name": "mode", + "type": "string", + "required": false, + "default": "avg", + "description": "The pooling method. Two modes are supported: 'avg' and 'max'. Default is 'avg'." + }, + { + "name": "output_height", + "type": "int64", + "required": false, + "default": 1, + "description": "default 1; Pooled output Y's height." + }, + { + "name": "output_width", + "type": "int64", + "required": false, + "default": 1, + "description": "default 1; Pooled output Y's width." + }, + { + "name": "sampling_ratio", + "type": "int64", + "required": false, + "description": "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." + }, + { + "name": "spatial_scale", + "type": "float32", + "required": false, + "default": 1.0, + "description": "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": [ + { + "name": "X", + "type": "T1", + "description": "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." + }, + { + "name": "rois", + "type": "T1", + "description": "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." + }, + { + "name": "batch_indices", + "type": "T2", + "description": "1-D tensor of shape (num_rois,) with each element denoting the index of the corresponding image in the batch." + } + ], + "min_input": 3, + "max_input": 3, + "outputs": [ + { + "name": "Y", + "type": "T1", + "description": "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]." + } + ], + "min_output": 1, + "max_output": 1, + "type_constraints": [ + { + "description": "Constrain types to float tensors.", + "type_param_str": "T1", + "allowed_type_strs": [ + "tensor(float16)", + "tensor(float)", + "tensor(double)" + ] + }, + { + "description": "Constrain types to int tensors.", + "type_param_str": "T2", + "allowed_type_strs": [ + "tensor(int64)" + ] + } + ], + "examples": [ + { + "summary": "roialign_aligned_false", + "code": "node = onnx.helper.make_node(\n \"RoiAlign\",\n inputs=[\"X\", \"rois\", \"batch_indices\"],\n outputs=[\"Y\"],\n spatial_scale=1.0,\n output_height=5,\n output_width=5,\n sampling_ratio=2,\n coordinate_transformation_mode=\"output_half_pixel\",\n)\n\nX, batch_indices, rois = get_roi_align_input_values()\n# (num_rois, C, output_height, output_width)\nY = np.array(\n [\n [\n [\n [0.4664, 0.4466, 0.3405, 0.5688, 0.6068],\n [0.3714, 0.4296, 0.3835, 0.5562, 0.3510],\n [0.2768, 0.4883, 0.5222, 0.5528, 0.4171],\n [0.4713, 0.4844, 0.6904, 0.4920, 0.8774],\n [0.6239, 0.7125, 0.6289, 0.3355, 0.3495],\n ]\n ],\n [\n [\n [0.3022, 0.4305, 0.4696, 0.3978, 0.5423],\n [0.3656, 0.7050, 0.5165, 0.3172, 0.7015],\n [0.2912, 0.5059, 0.6476, 0.6235, 0.8299],\n [0.5916, 0.7389, 0.7048, 0.8372, 0.8893],\n [0.6227, 0.6153, 0.7097, 0.6154, 0.4585],\n ]\n ],\n [\n [\n [0.2384, 0.3379, 0.3717, 0.6100, 0.7601],\n [0.3767, 0.3785, 0.7147, 0.9243, 0.9727],\n [0.5749, 0.5826, 0.5709, 0.7619, 0.8770],\n [0.5355, 0.2566, 0.2141, 0.2796, 0.3600],\n [0.4365, 0.3504, 0.2887, 0.3661, 0.2349],\n ]\n ],\n ],\n dtype=np.float32,\n)\n\nexpect(node, inputs=[X, rois, batch_indices], outputs=[Y], name=\"test_roialign_aligned_false\")" + }, + { + "summary": "roialign_aligned_true", + "code": "node = onnx.helper.make_node(\n \"RoiAlign\",\n inputs=[\"X\", \"rois\", \"batch_indices\"],\n outputs=[\"Y\"],\n spatial_scale=1.0,\n output_height=5,\n output_width=5,\n sampling_ratio=2,\n coordinate_transformation_mode=\"half_pixel\",\n)\n\nX, batch_indices, rois = get_roi_align_input_values()\n# (num_rois, C, output_height, output_width)\nY = np.array(\n [\n [\n [\n [0.5178, 0.3434, 0.3229, 0.4474, 0.6344],\n [0.4031, 0.5366, 0.4428, 0.4861, 0.4023],\n [0.2512, 0.4002, 0.5155, 0.6954, 0.3465],\n [0.3350, 0.4601, 0.5881, 0.3439, 0.6849],\n [0.4932, 0.7141, 0.8217, 0.4719, 0.4039],\n ]\n ],\n [\n [\n [0.3070, 0.2187, 0.3337, 0.4880, 0.4870],\n [0.1871, 0.4914, 0.5561, 0.4192, 0.3686],\n [0.1433, 0.4608, 0.5971, 0.5310, 0.4982],\n [0.2788, 0.4386, 0.6022, 0.7000, 0.7524],\n [0.5774, 0.7024, 0.7251, 0.7338, 0.8163],\n ]\n ],\n [\n [\n [0.2393, 0.4075, 0.3379, 0.2525, 0.4743],\n [0.3671, 0.2702, 0.4105, 0.6419, 0.8308],\n [0.5556, 0.4543, 0.5564, 0.7502, 0.9300],\n [0.6626, 0.5617, 0.4813, 0.4954, 0.6663],\n [0.6636, 0.3721, 0.2056, 0.1928, 0.2478],\n ]\n ],\n ],\n dtype=np.float32,\n)\n\nexpect(node, inputs=[X, rois, batch_indices], outputs=[Y], name=\"test_roialign_aligned_true\")" + } + ] + }, + { + "name": "Round", + "module": "ai.onnx", + "version": 11, + "support_level": "common", + "description": "Round takes one input Tensor and rounds the values, element-wise, meaning\nit finds the nearest integer for each value.\nIn case of halfs, the rule is to round them to the nearest even integer.\nThe output tensor has the same shape and type as the input.\n\nExamples:\n```\nround([0.9]) = [1.0]\nround([2.5]) = [2.0]\nround([2.3]) = [2.0]\nround([1.5]) = [2.0]\nround([-4.5]) = [-4.0]\n```\n", + "inputs": [ + { + "name": "X", + "type": "T", + "description": "Input tensor" + } + ], + "min_input": 1, + "max_input": 1, + "outputs": [ + { + "name": "Y", + "type": "T", + "description": "Output tensor" + } + ], + "min_output": 1, + "max_output": 1, + "type_constraints": [ + { + "description": "Constrain input and output types to float tensors.", + "type_param_str": "T", + "allowed_type_strs": [ + "tensor(float16)", + "tensor(float)", + "tensor(double)" + ] + } + ], + "examples": [ + { + "summary": "round", + "code": "node = onnx.helper.make_node(\n 'Round',\n inputs=['x'],\n outputs=['y'],\n)\n\nx = np.array([0.1, 0.5, 0.9, 1.2, 1.5,\n 1.8, 2.3, 2.5, 2.7, -1.1,\n -1.5, -1.9, -2.2, -2.5, -2.8]).astype(np.float32)\ny = np.array([0., 0., 1., 1., 2.,\n 2., 2., 2., 3., -1.,\n -2., -2., -2., -2., -3.]).astype(np.float32) # expected output\nexpect(node, inputs=[x], outputs=[y],\n name='test_round')" + } + ] + }, + { + "name": "SVMClassifier", + "module": "ai.onnx.ml", + "version": 1, + "support_level": "common", + "description": "Support Vector Machine classifier\n", + "attributes": [ + { + "name": "classlabels_ints", + "type": "int64[]", + "required": false, + "description": "Class labels if using integer labels.
One and only one of the 'classlabels_*' attributes must be defined." + }, + { + "name": "classlabels_strings", + "type": "string[]", + "required": false, + "description": "Class labels if using string labels.
One and only one of the 'classlabels_*' attributes must be defined." + }, + { + "name": "coefficients", + "type": "float32[]", + "required": false, + "description": "" + }, + { + "name": "kernel_params", + "type": "float32[]", + "required": false, + "description": "List of 3 elements containing gamma, coef0, and degree, in that order. Zero if unused for the kernel." + }, + { + "name": "kernel_type", + "type": "string", + "required": false, + "default": "LINEAR", + "description": "The kernel type, one of 'LINEAR,' 'POLY,' 'RBF,' 'SIGMOID'." + }, + { + "name": "post_transform", + "type": "string", + "required": false, + "default": "NONE", + "description": "Indicates the transform to apply to the score.
One of 'NONE,' 'SOFTMAX,' 'LOGISTIC,' 'SOFTMAX_ZERO,' or 'PROBIT'" + }, + { + "name": "prob_a", + "type": "float32[]", + "required": false, + "description": "First set of probability coefficients." + }, + { + "name": "prob_b", + "type": "float32[]", + "required": false, + "description": "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." + }, + { + "name": "rho", + "type": "float32[]", + "required": false, + "description": "" + }, + { + "name": "support_vectors", + "type": "float32[]", + "required": false, + "description": "" + }, + { + "name": "vectors_per_class", + "type": "int64[]", + "required": false, + "description": "" + } + ], + "inputs": [ + { + "name": "X", + "type": "T1", + "description": "Data to be classified." + } + ], + "min_input": 1, + "max_input": 1, + "outputs": [ + { + "name": "Y", + "type": "T2", + "description": "Classification outputs (one class per example)." + }, + { + "name": "Z", + "type": "tensor(float)", + "description": "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." + } + ], + "min_output": 2, + "max_output": 2, + "type_constraints": [ + { + "description": "The input must be a tensor of a numeric type, either [C] or [N,C].", + "type_param_str": "T1", + "allowed_type_strs": [ + "tensor(float)", + "tensor(double)", + "tensor(int64)", + "tensor(int32)" + ] + }, + { + "description": "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.", + "type_param_str": "T2", + "allowed_type_strs": [ + "tensor(string)", + "tensor(int64)" + ] + } + ] + }, + { + "name": "SVMRegressor", + "module": "ai.onnx.ml", + "version": 1, + "support_level": "common", + "description": "Support Vector Machine regression prediction and one-class SVM anomaly detection.\n", + "attributes": [ + { + "name": "coefficients", + "type": "float32[]", + "required": false, + "description": "Support vector coefficients." + }, + { + "name": "kernel_params", + "type": "float32[]", + "required": false, + "description": "List of 3 elements containing gamma, coef0, and degree, in that order. Zero if unused for the kernel." + }, + { + "name": "kernel_type", + "type": "string", + "required": false, + "default": "LINEAR", + "description": "The kernel type, one of 'LINEAR,' 'POLY,' 'RBF,' 'SIGMOID'." + }, + { + "name": "n_supports", + "type": "int64", + "required": false, + "description": "The number of support vectors." + }, + { + "name": "one_class", + "type": "int64", + "required": false, + "description": "Flag indicating whether the regression is a one-class SVM or not." + }, + { + "name": "post_transform", + "type": "string", + "required": false, + "default": "NONE", + "description": "Indicates the transform to apply to the score.
One of 'NONE,' 'SOFTMAX,' 'LOGISTIC,' 'SOFTMAX_ZERO,' or 'PROBIT.'" + }, + { + "name": "rho", + "type": "float32[]", + "required": false, + "description": "" + }, + { + "name": "support_vectors", + "type": "float32[]", + "required": false, + "description": "Chosen support vectors" + } + ], + "inputs": [ + { + "name": "X", + "type": "T", + "description": "Data to be regressed." + } + ], + "min_input": 1, + "max_input": 1, + "outputs": [ + { + "name": "Y", + "type": "tensor(float)", + "description": "Regression outputs (one score per target per example)." + } + ], + "min_output": 1, + "max_output": 1, + "type_constraints": [ + { + "description": "The input type must be a tensor of a numeric type, either [C] or [N,C].", + "type_param_str": "T", + "allowed_type_strs": [ + "tensor(float)", + "tensor(double)", + "tensor(int64)", + "tensor(int32)" + ] + } + ] + }, + { + "name": "Scaler", + "module": "ai.onnx.ml", + "version": 1, + "support_level": "common", + "description": "Rescale input data, for example to standardize features by removing the mean and scaling to unit variance.\n", + "attributes": [ + { + "name": "offset", + "type": "float32[]", + "required": false, + "description": "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." + }, + { + "name": "scale", + "type": "float32[]", + "required": false, + "description": "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": [ + { + "name": "X", + "type": "T", + "description": "Data to be scaled." + } + ], + "min_input": 1, + "max_input": 1, + "outputs": [ + { + "name": "Y", + "type": "tensor(float)", + "description": "Scaled output data." + } + ], + "min_output": 1, + "max_output": 1, + "type_constraints": [ + { + "description": "The input must be a tensor of a numeric type.", + "type_param_str": "T", + "allowed_type_strs": [ + "tensor(float)", + "tensor(double)", + "tensor(int64)", + "tensor(int32)" + ] + } + ] + }, + { + "name": "Scan", + "module": "ai.onnx", + "version": 8, + "support_level": "common", + "description": "Scan can be used to iterate over one or more scan_input tensors,\nconstructing zero or more scan_output tensors. It combines ideas from general recurrences,\nfunctional programming constructs such as scan, fold, map, and zip and is intended to enable\ngeneralizations of RNN-like constructs for sequence-to-sequence processing.\nOther tensors (referred to as state_variables here) can be used to carry a state\nwhen iterating from one element to another (similar to hidden-state in RNNs, also referred\nto as loop-carried dependences in the context of loops). All these tensors are required to\nhave the same shape in each iteration of the loop (a restriction imposed to enable efficient\nmemory allocation). Many common usages involve a single scan_input tensor (where functionality\nsimilar to scan, fold and map can be obtained). When more than one scan_input is used,\na behavior similar to zip is obtained.\n\nThe attribute body must be a graph, specifying the computation to be performed in\nevery iteration. It takes as input the current values of the state_variables and\nthe current iterated element of the scan_inputs. It must return the (updated) values\nof the state_variables and zero or more scan_output_element tensors. The values of the\nscan_output_element tensors are concatenated over all the iterations to produce the\nscan_output values of the scan construct (similar to the concatenated intermediate\nhidden-state values of RNN-like constructs).\n\nThe scan operation returns the final values of the state_variables as well as the\nscan_outputs.\n\nThe operation supports batching, and the batch-axis is required to be 0.\nWhen multiple scan_input tensors are used, they must all have the same batch-size,\nand they must all have the same maximum-sequence-length (the dimensionality of the\nsequence axis or scan axis). The sequence axis or scan axis is required to be 1.\n\nThe operation has an optional sequence_lens input (of shape [BATCH_SIZE]) to\nallow variable length sequences of length <= the maximum-sequence-length. If this\ninput is not specified, all sequences are assumed to be of length equal to\nmaximum-sequence-length. For variable length input sequences, the scan_outputs\nwill consist of a sequence of same length as the input, padded to the\nmaximum-sequence-length.\n\nThe optional attribute directions can be used to scan a sequence in the reverse direction.\nIf this attribute is omitted, all sequences are scanned in the forward direction.\nA bidirectional scan be performed by specifying the same tensor input twice in the\nscan_inputs, once with a forward direction, and once with a backward direction.\n\nNote that because of the ONNX restriction that only the last parameter of an operator can\nbe variadic, the initial-states and scan-inputs are listed together as one input parameter.\nSimilarly, the final-states and scan-outputs are listed together as one output parameter.\nThe attribute num_scan_inputs indicates the number M of scan-inputs.\n\nThe behavior of\n\n Scan <\n num_scan_inputs = m,\n body = loop-body\n > (sequence_lengths, init_1, ..., init_n, scan_1, ..., scan_m)\n\nis equivalent to the following pseudo-code:\n\n // T.shape[0] denotes the batch-size of T\n // The batch-size of scan_1, ..., scan_m are all required to be equal\n batch_size = scan_1.shape[0];\n\n // scan_i.shape[1] denotes the (max) sequence-length of scan_i\n // scan_i.shape[1] is required to be equal to scan_j.shape[1] for all i,j.\n max_sequence_length = scan_1.shape[1];\n\n for (int batch = 0; batch < batch_size; ++batch) {\n // initialize state-variables\n st_1 = init_1; ... st_n = init_n;\n // initialize scan-output variables: [] denotes an empty tensor\n scan_out_1 = []; ...; scan_out_k = [];\n // identify number of iterations:\n N = (sequence_lengths specified) ? sequence_lengths[batch] : max_sequence_length;\n\n // execute loop\n for (int t = 0; t < N; ++t) {\n // generate the scan-input elements: the notation T[t] indicates the sub-tensor\n // of rank one less than T obtained by indexing T at position t along axis k.\n si_1 = (scan_1[batch])[t];\n ... ;\n si_m = (scan_m[batch])[t];\n // execute loop-body\n st_1, ..., st_n, so_1, ..., so_k = loop-body(st_1, ..., st_n, si_1, ..., si_m)\n // accumulate the scan-output elements\n scan_out_1 = Concat(scan_out_1, so_1); ... ; scan_out_k = Concat(scan_out_k, so_k);\n }\n // accumulate the outputs for this batch:\n bst_1[batch] = st_1; ..., bst_n[batch] = st_n;\n // Note scan-outputs will have size max_sequence_length, but only first N values will be meaningful.\n // The remaining values have an undefined value.\n b_scan_out_1[batch] = scan_out_1; ...; b_scan_out_k[batch] = scan_out_k;\n }\n return bst_1, ..., bst_n, b_scan_out_1, ..., b_scan_out_k;\n\n\n\n*Sample usage: Encoding RNN using a Scan*\n\nThe following example shows how a simple RNN over an input tensor %X, with weight tensor %Wi,\nrecurrence weight tensor %Ri, bias tensors %Wbi and %Rbi, and initial hidden-state %H_0 can\nbe encoded as a ScanLoop. Note that the loop-body is a nested graph, and it directly computes\n%Wi, %Ri, %Wbi, and %Rbi (typically constants or initializers in the body graph). If these\nvalues are computed in the outer graph, they need to be passed in as extra state_variables.\n\n graph rnn-encoding {\n %H_0 = ...\n %X = ...\n %Y_h, %Y = Scan[body = , num_scan_inputs=1](\"\", %H_0, %X)\n return %Y, %Y_h\n }\n\n graph rnn-cell-1 (\n %H_tminus1[FLOAT, tensor]\n %X_t[FLOAT, tensor]\n ) {\n %Wi = ...\n %Ri = ...\n %Wbi = ...\n %Rbi = ...\n %t1 = X_t * (Wi^T)\n %t2 = H_tminus1*(Ri^T)\n %t3 = Add(%t1, %t2)\n %t4 = Add(%t3, %Wbi)\n %t5 = Add(%t4, %Rbi)\n %Ht = Tanh(%t5)\n %Accumulate = Identity(%Ht)\n return %Ht, %Accumulate\n }\n\n", + "attributes": [ + { + "name": "body", + "type": "graph", + "required": true, + "description": "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." + }, + { + "name": "directions", + "type": "int64[]", + "required": false, + "description": "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." + }, + { + "name": "num_scan_inputs", + "type": "int64", + "required": true, + "description": "An attribute specifying the number of scan_inputs M. " + } + ], + "inputs": [ + { + "name": "sequence_lens", + "type": "I", + "option": "optional", + "description": "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)." + }, + { + "name": "initial_state_and_scan_inputs", + "type": "V", + "list": true, + "description": "Initial values of the loop's N state variables followed by M scan_inputs" + } + ], + "min_input": 2, + "max_input": 2147483647, + "outputs": [ + { + "name": "final_state_and_scan_outputs", + "type": "V", + "list": true, + "description": "Final values of the loop's N state variables followed by K scan_outputs" + } + ], + "min_output": 1, + "max_output": 2147483647, + "inputs_range": "2 - ∞", + "outputs_range": "1 - ∞", + "type_constraints": [ + { + "description": "Int64 tensor", + "type_param_str": "I", + "allowed_type_strs": [ + "tensor(int64)" + ] + }, + { + "description": "All Tensor types", + "type_param_str": "V", + "allowed_type_strs": [ + "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)" + ] + } + ], + "examples": [ + { + "summary": "scan_8", + "code": "# Given an input sequence [x1, ..., xN], sum up its elements using a scan\n# returning the final state (x1+x2+...+xN) as well the scan_output\n# [x1, x1+x2, ..., x1+x2+...+xN]\n#\n# create graph to represent scan body\nsum_in = onnx.helper.make_tensor_value_info('sum_in', onnx.TensorProto.FLOAT, [2])\nnext = onnx.helper.make_tensor_value_info('next', onnx.TensorProto.FLOAT, [2])\nsum_out = onnx.helper.make_tensor_value_info('sum_out', onnx.TensorProto.FLOAT, [2])\nscan_out = onnx.helper.make_tensor_value_info('scan_out', onnx.TensorProto.FLOAT, [2])\nadd_node = onnx.helper.make_node(\n 'Add',\n inputs=['sum_in', 'next'],\n outputs=['sum_out']\n)\nid_node = onnx.helper.make_node(\n 'Identity',\n inputs=['sum_out'],\n outputs=['scan_out']\n)\nscan_body = onnx.helper.make_graph(\n [add_node, id_node],\n 'scan_body',\n [sum_in, next],\n [sum_out, scan_out]\n)\n# create scan op node\nno_sequence_lens = '' # optional input, not supplied\nnode = onnx.helper.make_node(\n 'Scan',\n inputs=[no_sequence_lens, 'initial', 'x'],\n outputs=['y', 'z'],\n num_scan_inputs=1,\n body=scan_body\n)\n# create inputs for batch-size 1, sequence-length 3, inner dimension 2\ninitial = np.array([0, 0]).astype(np.float32).reshape((1, 2))\nx = np.array([1, 2, 3, 4, 5, 6]).astype(np.float32).reshape((1, 3, 2))\n# final state computed = [1 + 3 + 5, 2 + 4 + 6]\ny = np.array([9, 12]).astype(np.float32).reshape((1, 2))\n# scan-output computed\nz = np.array([1, 2, 4, 6, 9, 12]).astype(np.float32).reshape((1, 3, 2))\n\nexpect(node, inputs=[initial, x], outputs=[y, z],\n name='test_scan_sum', opset_imports=[onnx.helper.make_opsetid(\"\", 8)])" + }, + { + "summary": "scan_9", + "code": "# Given an input sequence [x1, ..., xN], sum up its elements using a scan\n# returning the final state (x1+x2+...+xN) as well the scan_output\n# [x1, x1+x2, ..., x1+x2+...+xN]\n#\n# create graph to represent scan body\nsum_in = onnx.helper.make_tensor_value_info('sum_in', onnx.TensorProto.FLOAT, [2])\nnext = onnx.helper.make_tensor_value_info('next', onnx.TensorProto.FLOAT, [2])\nsum_out = onnx.helper.make_tensor_value_info('sum_out', onnx.TensorProto.FLOAT, [2])\nscan_out = onnx.helper.make_tensor_value_info('scan_out', onnx.TensorProto.FLOAT, [2])\nadd_node = onnx.helper.make_node(\n 'Add',\n inputs=['sum_in', 'next'],\n outputs=['sum_out']\n)\nid_node = onnx.helper.make_node(\n 'Identity',\n inputs=['sum_out'],\n outputs=['scan_out']\n)\nscan_body = onnx.helper.make_graph(\n [add_node, id_node],\n 'scan_body',\n [sum_in, next],\n [sum_out, scan_out]\n)\n# create scan op node\nnode = onnx.helper.make_node(\n 'Scan',\n inputs=['initial', 'x'],\n outputs=['y', 'z'],\n num_scan_inputs=1,\n body=scan_body\n)\n# create inputs for sequence-length 3, inner dimension 2\ninitial = np.array([0, 0]).astype(np.float32).reshape((2,))\nx = np.array([1, 2, 3, 4, 5, 6]).astype(np.float32).reshape((3, 2))\n# final state computed = [1 + 3 + 5, 2 + 4 + 6]\ny = np.array([9, 12]).astype(np.float32).reshape((2,))\n# scan-output computed\nz = np.array([1, 2, 4, 6, 9, 12]).astype(np.float32).reshape((3, 2))\n\nexpect(node, inputs=[initial, x], outputs=[y, z],\n name='test_scan9_sum', opset_imports=[onnx.helper.make_opsetid(\"\", 9)])" + } + ] + }, + { + "name": "Scan", + "module": "ai.onnx", + "version": 9, + "support_level": "common", + "description": "Scan can be used to iterate over one or more scan_input tensors,\nconstructing zero or more scan_output tensors. It combines ideas from general recurrences,\nfunctional programming constructs such as scan, fold, map, and zip and is intended to enable\ngeneralizations of RNN-like constructs for sequence-to-sequence processing.\nOther tensors (referred to as state_variables here) can be used to carry a state\nwhen iterating from one element to another (similar to hidden-state in RNNs, also referred\nto as loop-carried dependences in the context of loops).\nMany common usages involve a single scan_input tensor (where functionality\nsimilar to scan, fold and map can be obtained). When more than one scan_input is used,\na behavior similar to zip is obtained.\n\nThe attribute body must be a graph, specifying the computation to be performed in\nevery iteration. It takes as input the current values of the state_variables and\nthe current iterated element of the scan_inputs. It must return the (updated) values\nof the state_variables and zero or more scan_output_element tensors. The values of the\nscan_output_element tensors are concatenated over all the iterations to produce the\nscan_output values of the scan construct (similar to the concatenated intermediate\nhidden-state values of RNN-like constructs). All the output tensors (state_variables as\nwell as scan_output_element tensors) are required to have the same shape in each iteration\nof the loop (a restriction imposed to enable efficient memory allocation).\n\nNote that the iterated element passed to the body subgraph does not have a sequence\naxis. It will have a rank one less than the rank of the corresponding scan_input.\n\nThe scan operation returns the final values of the state_variables as well as the\nscan_outputs.\n\nThe optional attribute scan_input_directions specifies the direction (forward or backward)\nfor each scan input. If this attribute is omitted, all sequences are scanned in the forward\ndirection. A bidirectional scan may be performed by specifying the same tensor input twice\nin the scan_inputs, once with a forward direction, and once with a backward direction.\n\nThe scan_output of the operation is produced by concatenating the scan_output_element\nvalues produced by the body in each iteration. The optional attribute scan_output_directions\nspecifies the direction in which scan_output is constructed (by appending or prepending the\nscan_output_element to scan_output in each iteration) for each scan_output. If this attribute\nis omitted, the scan_output_element is appended to the scan_output in each iteration.\n\nThe optional attribute scan_input_axes specifies the axis to be scanned for each scan_input.\nIf omitted, every scan_input will be scanned in axis 0. For example, if axis 0 is the\nbatch axis and axis 1 is the time axis (to be scanned), specify an axis value of 1.\nNote that scanning a non-zero axis may be less efficient than scanning axis zero.\n\nThe optional attribute scan_output_axes specifies the axis along which the scan_outputs\nare accumulated for each scan_output. For example, if axis 1 is the time axis (to be\nscanned) for both inputs and outputs, specify a scan_input axis and scan_output axis\nvalue of 1.\n\nNote that because of the ONNX restriction that only the last parameter of an operator can\nbe variadic, the initial-states and scan-inputs are listed together as one input parameter.\nSimilarly, the final-states and scan-outputs are listed together as one output parameter.\nThe attribute num_scan_inputs indicates the number M of scan-inputs.\n\nThe behavior of\n\n Scan <\n num_scan_inputs = m,\n body = loop-body,\n scan_input_axes = [axis_1, ..., axis_m]\n > (init_1, ..., init_n, scan_1, ..., scan_m)\n\nis equivalent to the following pseudo-code:\n\n // scan_i.shape[axis_i] denotes the (max) sequence-length of scan_i\n // scan_i.shape[axis_i] is required to be equal to scan_j.shape[axis_j] for all i,j.\n sequence_length = scan_1.shape[axis_1];\n\n // initialize state-variables\n st_1 = init_1; ... st_n = init_n;\n // initialize scan-output variables: [] denotes an empty tensor\n scan_out_1 = []; ...; scan_out_k = [];\n // identify number of iterations:\n\n // execute loop\n for (int t = 0; t < sequence_length; ++t) {\n // generate the scan-input elements: the notation T[t] indicates the sub-tensor\n // of rank one less than T obtained by indexing T at position t along axis k.\n si_1 = scan_1[t];\n ... ;\n si_m = scan_m[t];\n // execute loop-body\n st_1, ..., st_n, so_1, ..., so_k = loop-body(st_1, ..., st_n, si_1, ..., si_m)\n // accumulate the scan-output elements\n scan_out_1 = Concat(scan_out_1, so_1); ... ; scan_out_k = Concat(scan_out_k, so_k);\n }\n\n return st_1, ..., st_n, scan_out_1, ..., scan_out_k;\n\n*Sample usage: Encoding RNN using a Scan*\n\nThe following example shows how a simple RNN over an input tensor %X, with weight tensor %Wi,\nrecurrence weight tensor %Ri, bias tensors %Wbi and %Rbi, and initial hidden-state %H_0 can\nbe encoded as a ScanLoop. Note that the loop-body is a nested graph, and it directly computes\n%Wi, %Ri, %Wbi, and %Rbi (typically constants or initializers in the body graph). If these\nvalues are computed in the outer graph, they need to be passed in as extra state_variables.\n\n graph rnn-encoding {\n %H_0 = ...\n %X = ...\n %Y_h, %Y = Scan[body = , num_scan_inputs=1](%H_0, %X)\n return %Y, %Y_h\n }\n\n graph rnn-cell-1 (\n %H_tminus1[FLOAT, tensor]\n %X_t[FLOAT, tensor]\n ) {\n %Wi = ...\n %Ri = ...\n %Wbi = ...\n %Rbi = ...\n %t1 = X_t * (Wi^T)\n %t2 = H_tminus1*(Ri^T)\n %t3 = Add(%t1, %t2)\n %t4 = Add(%t3, %Wbi)\n %t5 = Add(%t4, %Rbi)\n %Ht = Tanh(%t5)\n %Accumulate = Identity(%Ht)\n return %Ht, %Accumulate\n }\n\n", + "attributes": [ + { + "name": "body", + "type": "graph", + "required": true, + "description": "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." + }, + { + "name": "num_scan_inputs", + "type": "int64", + "required": true, + "description": "An attribute specifying the number of scan_inputs M. " + }, + { + "name": "scan_input_axes", + "type": "int64[]", + "required": false, + "description": "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." + }, + { + "name": "scan_input_directions", + "type": "int64[]", + "required": false, + "description": "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." + }, + { + "name": "scan_output_axes", + "type": "int64[]", + "required": false, + "description": "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." + }, + { + "name": "scan_output_directions", + "type": "int64[]", + "required": false, + "description": "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": [ + { + "name": "initial_state_and_scan_inputs", + "type": "V", + "list": true, + "description": "Initial values of the loop's N state variables followed by M scan_inputs" + } + ], + "min_input": 1, + "max_input": 2147483647, + "outputs": [ + { + "name": "final_state_and_scan_outputs", + "type": "V", + "list": true, + "description": "Final values of the loop's N state variables followed by K scan_outputs" + } + ], + "min_output": 1, + "max_output": 2147483647, + "inputs_range": "1 - ∞", + "outputs_range": "1 - ∞", + "type_constraints": [ + { + "description": "Int64 tensor", + "type_param_str": "I", + "allowed_type_strs": [ + "tensor(int64)" + ] + }, + { + "description": "All Tensor types", + "type_param_str": "V", + "allowed_type_strs": [ + "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)" + ] + } + ], + "examples": [ + { + "summary": "scan_8", + "code": "# Given an input sequence [x1, ..., xN], sum up its elements using a scan\n# returning the final state (x1+x2+...+xN) as well the scan_output\n# [x1, x1+x2, ..., x1+x2+...+xN]\n#\n# create graph to represent scan body\nsum_in = onnx.helper.make_tensor_value_info('sum_in', onnx.TensorProto.FLOAT, [2])\nnext = onnx.helper.make_tensor_value_info('next', onnx.TensorProto.FLOAT, [2])\nsum_out = onnx.helper.make_tensor_value_info('sum_out', onnx.TensorProto.FLOAT, [2])\nscan_out = onnx.helper.make_tensor_value_info('scan_out', onnx.TensorProto.FLOAT, [2])\nadd_node = onnx.helper.make_node(\n 'Add',\n inputs=['sum_in', 'next'],\n outputs=['sum_out']\n)\nid_node = onnx.helper.make_node(\n 'Identity',\n inputs=['sum_out'],\n outputs=['scan_out']\n)\nscan_body = onnx.helper.make_graph(\n [add_node, id_node],\n 'scan_body',\n [sum_in, next],\n [sum_out, scan_out]\n)\n# create scan op node\nno_sequence_lens = '' # optional input, not supplied\nnode = onnx.helper.make_node(\n 'Scan',\n inputs=[no_sequence_lens, 'initial', 'x'],\n outputs=['y', 'z'],\n num_scan_inputs=1,\n body=scan_body\n)\n# create inputs for batch-size 1, sequence-length 3, inner dimension 2\ninitial = np.array([0, 0]).astype(np.float32).reshape((1, 2))\nx = np.array([1, 2, 3, 4, 5, 6]).astype(np.float32).reshape((1, 3, 2))\n# final state computed = [1 + 3 + 5, 2 + 4 + 6]\ny = np.array([9, 12]).astype(np.float32).reshape((1, 2))\n# scan-output computed\nz = np.array([1, 2, 4, 6, 9, 12]).astype(np.float32).reshape((1, 3, 2))\n\nexpect(node, inputs=[initial, x], outputs=[y, z],\n name='test_scan_sum', opset_imports=[onnx.helper.make_opsetid(\"\", 8)])" + }, + { + "summary": "scan_9", + "code": "# Given an input sequence [x1, ..., xN], sum up its elements using a scan\n# returning the final state (x1+x2+...+xN) as well the scan_output\n# [x1, x1+x2, ..., x1+x2+...+xN]\n#\n# create graph to represent scan body\nsum_in = onnx.helper.make_tensor_value_info('sum_in', onnx.TensorProto.FLOAT, [2])\nnext = onnx.helper.make_tensor_value_info('next', onnx.TensorProto.FLOAT, [2])\nsum_out = onnx.helper.make_tensor_value_info('sum_out', onnx.TensorProto.FLOAT, [2])\nscan_out = onnx.helper.make_tensor_value_info('scan_out', onnx.TensorProto.FLOAT, [2])\nadd_node = onnx.helper.make_node(\n 'Add',\n inputs=['sum_in', 'next'],\n outputs=['sum_out']\n)\nid_node = onnx.helper.make_node(\n 'Identity',\n inputs=['sum_out'],\n outputs=['scan_out']\n)\nscan_body = onnx.helper.make_graph(\n [add_node, id_node],\n 'scan_body',\n [sum_in, next],\n [sum_out, scan_out]\n)\n# create scan op node\nnode = onnx.helper.make_node(\n 'Scan',\n inputs=['initial', 'x'],\n outputs=['y', 'z'],\n num_scan_inputs=1,\n body=scan_body\n)\n# create inputs for sequence-length 3, inner dimension 2\ninitial = np.array([0, 0]).astype(np.float32).reshape((2,))\nx = np.array([1, 2, 3, 4, 5, 6]).astype(np.float32).reshape((3, 2))\n# final state computed = [1 + 3 + 5, 2 + 4 + 6]\ny = np.array([9, 12]).astype(np.float32).reshape((2,))\n# scan-output computed\nz = np.array([1, 2, 4, 6, 9, 12]).astype(np.float32).reshape((3, 2))\n\nexpect(node, inputs=[initial, x], outputs=[y, z],\n name='test_scan9_sum', opset_imports=[onnx.helper.make_opsetid(\"\", 9)])" + } + ] + }, + { + "name": "Scan", + "module": "ai.onnx", + "version": 11, + "support_level": "common", + "description": "Scan can be used to iterate over one or more scan_input tensors,\nconstructing zero or more scan_output tensors. It combines ideas from general recurrences,\nfunctional programming constructs such as scan, fold, map, and zip and is intended to enable\ngeneralizations of RNN-like constructs for sequence-to-sequence processing.\nOther tensors (referred to as state_variables here) can be used to carry a state\nwhen iterating from one element to another (similar to hidden-state in RNNs, also referred\nto as loop-carried dependences in the context of loops).\nMany common usages involve a single scan_input tensor (where functionality\nsimilar to scan, fold and map can be obtained). When more than one scan_input is used,\na behavior similar to zip is obtained.\n\nThe attribute body must be a graph, specifying the computation to be performed in\nevery iteration. It takes as input the current values of the state_variables and\nthe current iterated element of the scan_inputs. It must return the (updated) values\nof the state_variables and zero or more scan_output_element tensors. The values of the\nscan_output_element tensors are concatenated over all the iterations to produce the\nscan_output values of the scan construct (similar to the concatenated intermediate\nhidden-state values of RNN-like constructs). All the output tensors (state_variables as\nwell as scan_output_element tensors) are required to have the same shape in each iteration\nof the loop (a restriction imposed to enable efficient memory allocation).\n\nNote that the iterated element passed to the body subgraph does not have a sequence\naxis. It will have a rank one less than the rank of the corresponding scan_input.\n\nThe scan operation returns the final values of the state_variables as well as the\nscan_outputs.\n\nThe optional attribute scan_input_directions specifies the direction (forward or backward)\nfor each scan input. If this attribute is omitted, all sequences are scanned in the forward\ndirection. A bidirectional scan may be performed by specifying the same tensor input twice\nin the scan_inputs, once with a forward direction, and once with a backward direction.\n\nThe scan_output of the operation is produced by concatenating the scan_output_element\nvalues produced by the body in each iteration. The optional attribute scan_output_directions\nspecifies the direction in which scan_output is constructed (by appending or prepending the\nscan_output_element to scan_output in each iteration) for each scan_output. If this attribute\nis omitted, the scan_output_element is appended to the scan_output in each iteration.\n\nThe optional attribute scan_input_axes specifies the axis to be scanned for each scan_input.\nIf omitted, every scan_input will be scanned in axis 0. For example, if axis 0 is the\nbatch axis and axis 1 is the time axis (to be scanned), specify an axis value of 1.\nNote that scanning a non-zero axis may be less efficient than scanning axis zero.\n\nThe optional attribute scan_output_axes specifies the axis along which the scan_outputs\nare accumulated for each scan_output. For example, if axis 1 is the time axis (to be\nscanned) for both inputs and outputs, specify a scan_input axis and scan_output axis\nvalue of 1.\n\nNote that because of the ONNX restriction that only the last parameter of an operator can\nbe variadic, the initial-states and scan-inputs are listed together as one input parameter.\nSimilarly, the final-states and scan-outputs are listed together as one output parameter.\nThe attribute num_scan_inputs indicates the number M of scan-inputs.\n\nThe behavior of\n\n Scan <\n num_scan_inputs = m,\n body = loop-body,\n scan_input_axes = [axis_1, ..., axis_m]\n > (init_1, ..., init_n, scan_1, ..., scan_m)\n\nis equivalent to the following pseudo-code:\n\n // scan_i.shape[axis_i] denotes the (max) sequence-length of scan_i\n // scan_i.shape[axis_i] is required to be equal to scan_j.shape[axis_j] for all i,j.\n sequence_length = scan_1.shape[axis_1];\n\n // initialize state-variables\n st_1 = init_1; ... st_n = init_n;\n // initialize scan-output variables: [] denotes an empty tensor\n scan_out_1 = []; ...; scan_out_k = [];\n // identify number of iterations:\n\n // execute loop\n for (int t = 0; t < sequence_length; ++t) {\n // generate the scan-input elements: the notation T[t] indicates the sub-tensor\n // of rank one less than T obtained by indexing T at position t along axis k.\n si_1 = scan_1[t];\n ... ;\n si_m = scan_m[t];\n // execute loop-body\n st_1, ..., st_n, so_1, ..., so_k = loop-body(st_1, ..., st_n, si_1, ..., si_m)\n // accumulate the scan-output elements\n scan_out_1 = Concat(scan_out_1, so_1); ... ; scan_out_k = Concat(scan_out_k, so_k);\n }\n\n return st_1, ..., st_n, scan_out_1, ..., scan_out_k;\n\n*Sample usage: Encoding RNN using a Scan*\n\nThe following example shows how a simple RNN over an input tensor %X, with weight tensor %Wi,\nrecurrence weight tensor %Ri, bias tensors %Wbi and %Rbi, and initial hidden-state %H_0 can\nbe encoded as a ScanLoop. Note that the loop-body is a nested graph, and it directly computes\n%Wi, %Ri, %Wbi, and %Rbi (typically constants or initializers in the body graph). If these\nvalues are computed in the outer graph, they need to be passed in as extra state_variables.\n\n graph rnn-encoding {\n %H_0 = ...\n %X = ...\n %Y_h, %Y = Scan[body = , num_scan_inputs=1](%H_0, %X)\n return %Y, %Y_h\n }\n\n graph rnn-cell-1 (\n %H_tminus1[FLOAT, tensor]\n %X_t[FLOAT, tensor]\n ) {\n %Wi = ...\n %Ri = ...\n %Wbi = ...\n %Rbi = ...\n %t1 = X_t * (Wi^T)\n %t2 = H_tminus1*(Ri^T)\n %t3 = Add(%t1, %t2)\n %t4 = Add(%t3, %Wbi)\n %t5 = Add(%t4, %Rbi)\n %Ht = Tanh(%t5)\n %Accumulate = Identity(%Ht)\n return %Ht, %Accumulate\n }\n\n", + "attributes": [ + { + "name": "body", + "type": "graph", + "required": true, + "description": "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." + }, + { + "name": "num_scan_inputs", + "type": "int64", + "required": true, + "description": "An attribute specifying the number of scan_inputs M. " + }, + { + "name": "scan_input_axes", + "type": "int64[]", + "required": false, + "description": "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)." + }, + { + "name": "scan_input_directions", + "type": "int64[]", + "required": false, + "description": "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." + }, + { + "name": "scan_output_axes", + "type": "int64[]", + "required": false, + "description": "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]." + }, + { + "name": "scan_output_directions", + "type": "int64[]", + "required": false, + "description": "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": [ + { + "name": "initial_state_and_scan_inputs", + "type": "V", + "list": true, + "description": "Initial values of the loop's N state variables followed by M scan_inputs" + } + ], + "min_input": 1, + "max_input": 2147483647, + "outputs": [ + { + "name": "final_state_and_scan_outputs", + "type": "V", + "list": true, + "description": "Final values of the loop's N state variables followed by K scan_outputs" + } + ], + "min_output": 1, + "max_output": 2147483647, + "inputs_range": "1 - ∞", + "outputs_range": "1 - ∞", + "type_constraints": [ + { + "description": "Int64 tensor", + "type_param_str": "I", + "allowed_type_strs": [ + "tensor(int64)" + ] + }, + { + "description": "All Tensor types", + "type_param_str": "V", + "allowed_type_strs": [ + "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)" + ] + } + ], + "examples": [ + { + "summary": "scan_8", + "code": "# Given an input sequence [x1, ..., xN], sum up its elements using a scan\n# returning the final state (x1+x2+...+xN) as well the scan_output\n# [x1, x1+x2, ..., x1+x2+...+xN]\n#\n# create graph to represent scan body\nsum_in = onnx.helper.make_tensor_value_info('sum_in', onnx.TensorProto.FLOAT, [2])\nnext = onnx.helper.make_tensor_value_info('next', onnx.TensorProto.FLOAT, [2])\nsum_out = onnx.helper.make_tensor_value_info('sum_out', onnx.TensorProto.FLOAT, [2])\nscan_out = onnx.helper.make_tensor_value_info('scan_out', onnx.TensorProto.FLOAT, [2])\nadd_node = onnx.helper.make_node(\n 'Add',\n inputs=['sum_in', 'next'],\n outputs=['sum_out']\n)\nid_node = onnx.helper.make_node(\n 'Identity',\n inputs=['sum_out'],\n outputs=['scan_out']\n)\nscan_body = onnx.helper.make_graph(\n [add_node, id_node],\n 'scan_body',\n [sum_in, next],\n [sum_out, scan_out]\n)\n# create scan op node\nno_sequence_lens = '' # optional input, not supplied\nnode = onnx.helper.make_node(\n 'Scan',\n inputs=[no_sequence_lens, 'initial', 'x'],\n outputs=['y', 'z'],\n num_scan_inputs=1,\n body=scan_body\n)\n# create inputs for batch-size 1, sequence-length 3, inner dimension 2\ninitial = np.array([0, 0]).astype(np.float32).reshape((1, 2))\nx = np.array([1, 2, 3, 4, 5, 6]).astype(np.float32).reshape((1, 3, 2))\n# final state computed = [1 + 3 + 5, 2 + 4 + 6]\ny = np.array([9, 12]).astype(np.float32).reshape((1, 2))\n# scan-output computed\nz = np.array([1, 2, 4, 6, 9, 12]).astype(np.float32).reshape((1, 3, 2))\n\nexpect(node, inputs=[initial, x], outputs=[y, z],\n name='test_scan_sum', opset_imports=[onnx.helper.make_opsetid(\"\", 8)])" + }, + { + "summary": "scan_9", + "code": "# Given an input sequence [x1, ..., xN], sum up its elements using a scan\n# returning the final state (x1+x2+...+xN) as well the scan_output\n# [x1, x1+x2, ..., x1+x2+...+xN]\n#\n# create graph to represent scan body\nsum_in = onnx.helper.make_tensor_value_info('sum_in', onnx.TensorProto.FLOAT, [2])\nnext = onnx.helper.make_tensor_value_info('next', onnx.TensorProto.FLOAT, [2])\nsum_out = onnx.helper.make_tensor_value_info('sum_out', onnx.TensorProto.FLOAT, [2])\nscan_out = onnx.helper.make_tensor_value_info('scan_out', onnx.TensorProto.FLOAT, [2])\nadd_node = onnx.helper.make_node(\n 'Add',\n inputs=['sum_in', 'next'],\n outputs=['sum_out']\n)\nid_node = onnx.helper.make_node(\n 'Identity',\n inputs=['sum_out'],\n outputs=['scan_out']\n)\nscan_body = onnx.helper.make_graph(\n [add_node, id_node],\n 'scan_body',\n [sum_in, next],\n [sum_out, scan_out]\n)\n# create scan op node\nnode = onnx.helper.make_node(\n 'Scan',\n inputs=['initial', 'x'],\n outputs=['y', 'z'],\n num_scan_inputs=1,\n body=scan_body\n)\n# create inputs for sequence-length 3, inner dimension 2\ninitial = np.array([0, 0]).astype(np.float32).reshape((2,))\nx = np.array([1, 2, 3, 4, 5, 6]).astype(np.float32).reshape((3, 2))\n# final state computed = [1 + 3 + 5, 2 + 4 + 6]\ny = np.array([9, 12]).astype(np.float32).reshape((2,))\n# scan-output computed\nz = np.array([1, 2, 4, 6, 9, 12]).astype(np.float32).reshape((3, 2))\n\nexpect(node, inputs=[initial, x], outputs=[y, z],\n name='test_scan9_sum', opset_imports=[onnx.helper.make_opsetid(\"\", 9)])" + } + ] + }, + { + "name": "Scatter", + "module": "ai.onnx", + "version": 9, + "support_level": "common", + "description": "Given `data`, `updates` and `indices` input tensors of rank r >= 1, write the values provided by `updates`\ninto the first input, `data`, along `axis` dimension of `data` (by default outer-most one as axis=0) at corresponding `indices`.\nFor each entry in `updates`, the target index in `data` is specified by corresponding entry in `indices`\nfor dimension = axis, and index in source for dimension != axis. For instance, in a 2-D tensor case,\ndata[indices[i][j]][j] = updates[i][j] if axis = 0, or data[i][indices[i][j]] = updates[i][j] if axis = 1,\nwhere i and j are loop counters from 0 up to the respective size in `updates` - 1.\nExample 1:\n data = [\n [0.0, 0.0, 0.0],\n [0.0, 0.0, 0.0],\n [0.0, 0.0, 0.0],\n ]\n indices = [\n [1, 0, 2],\n [0, 2, 1],\n ]\n updates = [\n [1.0, 1.1, 1.2],\n [2.0, 2.1, 2.2],\n ]\n output = [\n [2.0, 1.1, 0.0]\n [1.0, 0.0, 2.2]\n [0.0, 2.1, 1.2]\n ]\nExample 2:\n data = [[1.0, 2.0, 3.0, 4.0, 5.0]]\n indices = [[1, 3]]\n updates = [[1.1, 2.1]]\n axis = 1\n output = [[1.0, 1.1, 3.0, 2.1, 5.0]]\n", + "attributes": [ + { + "name": "axis", + "type": "int64", + "required": false, + "description": "Which axis to scatter on. Negative value means counting dimensions from the back. Accepted range is [-r, r-1]" + } + ], + "inputs": [ + { + "name": "data", + "type": "T", + "description": "Tensor of rank r >= 1." + }, + { + "name": "indices", + "type": "Tind", + "description": "Tensor of int32/int64 indices, of r >= 1 (same rank as input)." + }, + { + "name": "updates", + "type": "T", + "description": "Tensor of rank r >=1 (same rank and shape as indices)" + } + ], + "min_input": 3, + "max_input": 3, + "outputs": [ + { + "name": "output", + "type": "T", + "description": "Tensor of rank r >= 1 (same rank as input)." + } + ], + "min_output": 1, + "max_output": 1, + "type_constraints": [ + { + "description": "Input and output types can be of any tensor type.", + "type_param_str": "T", + "allowed_type_strs": [ + "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)" + ] + }, + { + "description": "Constrain indices to integer types", + "type_param_str": "Tind", + "allowed_type_strs": [ + "tensor(int32)", + "tensor(int64)" + ] + } + ], + "examples": [ + { + "summary": "scatter_with_axis", + "code": "axis = 1\nnode = onnx.helper.make_node(\n 'Scatter',\n inputs=['data', 'indices', 'updates'],\n outputs=['y'],\n axis=axis,\n)\ndata = np.array([[1.0, 2.0, 3.0, 4.0, 5.0]], dtype=np.float32)\nindices = np.array([[1, 3]], dtype=np.int64)\nupdates = np.array([[1.1, 2.1]], dtype=np.float32)\n\ny = scatter(data, indices, updates, axis=axis)\n# print(y) produces\n# [[1.0, 1.1, 3.0, 2.1, 5.0]]\n\nexpect(node, inputs=[data, indices, updates], outputs=[y],\n name='test_scatter_with_axis', opset_imports=[helper.make_opsetid(\"\", 10)])" + }, + { + "summary": "scatter_without_axis", + "code": "node = onnx.helper.make_node(\n 'Scatter',\n inputs=['data', 'indices', 'updates'],\n outputs=['y'],\n)\ndata = np.zeros((3, 3), dtype=np.float32)\nindices = np.array([[1, 0, 2], [0, 2, 1]], dtype=np.int64)\nupdates = np.array([[1.0, 1.1, 1.2], [2.0, 2.1, 2.2]], dtype=np.float32)\n\ny = scatter(data, indices, updates)\n# print(y) produces\n# [[2.0, 1.1, 0.0],\n# [1.0, 0.0, 2.2],\n# [0.0, 2.1, 1.2]]\n\nexpect(node, inputs=[data, indices, updates], outputs=[y],\n name='test_scatter_without_axis', opset_imports=[helper.make_opsetid(\"\", 10)])" + } + ] + }, + { + "name": "Scatter", + "module": "ai.onnx", + "version": 11, + "support_level": "common", + "description": "This operator is deprecated. Please use ScatterElements, which provides the same functionality.\n\nScatter takes three inputs `data`, `updates`, and `indices` of the same\nrank r >= 1 and an optional attribute axis that identifies an axis of `data`\n(by default, the outer-most axis, that is axis 0). The output of the operation\nis produced by creating a copy of the input `data`, and then updating its value\nto values specified by `updates` at specific index positions specified by\n`indices`. Its output shape is the same as the shape of `data`.\n\nFor each entry in `updates`, the target index in `data` is obtained by combining\nthe corresponding entry in `indices` with the index of the entry itself: the\nindex-value for dimension = axis is obtained from the value of the corresponding\nentry in `indices` and the index-value for dimension != axis is obtained from the\nindex of the entry itself.\n\nFor instance, in a 2-D tensor case, the update corresponding to the [i][j] entry\nis performed as below:\n```\n output[indices[i][j]][j] = updates[i][j] if axis = 0,\n output[i][indices[i][j]] = updates[i][j] if axis = 1,\n```\n\nThis operator is the inverse of GatherElements. It is similar to Torch's Scatter operation.\n\nExample 1:\n```\n data = [\n [0.0, 0.0, 0.0],\n [0.0, 0.0, 0.0],\n [0.0, 0.0, 0.0],\n ]\n indices = [\n [1, 0, 2],\n [0, 2, 1],\n ]\n updates = [\n [1.0, 1.1, 1.2],\n [2.0, 2.1, 2.2],\n ]\n output = [\n [2.0, 1.1, 0.0]\n [1.0, 0.0, 2.2]\n [0.0, 2.1, 1.2]\n ]\n```\nExample 2:\n```\n data = [[1.0, 2.0, 3.0, 4.0, 5.0]]\n indices = [[1, 3]]\n updates = [[1.1, 2.1]]\n axis = 1\n output = [[1.0, 1.1, 3.0, 2.1, 5.0]]\n```\n", + "attributes": [ + { + "name": "axis", + "type": "int64", + "required": false, + "description": "Which axis to scatter on. Negative value means counting dimensions from the back. Accepted range is [-r, r-1] where r = rank(data)." + } + ], + "inputs": [ + { + "name": "data", + "type": "T", + "description": "Tensor of rank r >= 1." + }, + { + "name": "indices", + "type": "Tind", + "description": "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." + }, + { + "name": "updates", + "type": "T", + "description": "Tensor of rank r >=1 (same rank and shape as indices)" + } + ], + "min_input": 3, + "max_input": 3, + "outputs": [ + { + "name": "output", + "type": "T", + "description": "Tensor of rank r >= 1 (same rank as input)." + } + ], + "min_output": 1, + "max_output": 1, + "type_constraints": [ + { + "description": "Input and output types can be of any tensor type.", + "type_param_str": "T", + "allowed_type_strs": [ + "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)" + ] + }, + { + "description": "Constrain indices to integer types", + "type_param_str": "Tind", + "allowed_type_strs": [ + "tensor(int32)", + "tensor(int64)" + ] + } + ], + "examples": [ + { + "summary": "scatter_with_axis", + "code": "axis = 1\nnode = onnx.helper.make_node(\n 'Scatter',\n inputs=['data', 'indices', 'updates'],\n outputs=['y'],\n axis=axis,\n)\ndata = np.array([[1.0, 2.0, 3.0, 4.0, 5.0]], dtype=np.float32)\nindices = np.array([[1, 3]], dtype=np.int64)\nupdates = np.array([[1.1, 2.1]], dtype=np.float32)\n\ny = scatter(data, indices, updates, axis=axis)\n# print(y) produces\n# [[1.0, 1.1, 3.0, 2.1, 5.0]]\n\nexpect(node, inputs=[data, indices, updates], outputs=[y],\n name='test_scatter_with_axis', opset_imports=[helper.make_opsetid(\"\", 10)])" + }, + { + "summary": "scatter_without_axis", + "code": "node = onnx.helper.make_node(\n 'Scatter',\n inputs=['data', 'indices', 'updates'],\n outputs=['y'],\n)\ndata = np.zeros((3, 3), dtype=np.float32)\nindices = np.array([[1, 0, 2], [0, 2, 1]], dtype=np.int64)\nupdates = np.array([[1.0, 1.1, 1.2], [2.0, 2.1, 2.2]], dtype=np.float32)\n\ny = scatter(data, indices, updates)\n# print(y) produces\n# [[2.0, 1.1, 0.0],\n# [1.0, 0.0, 2.2],\n# [0.0, 2.1, 1.2]]\n\nexpect(node, inputs=[data, indices, updates], outputs=[y],\n name='test_scatter_without_axis', opset_imports=[helper.make_opsetid(\"\", 10)])" + } + ] + }, + { + "name": "ScatterElements", + "module": "ai.onnx", + "version": 11, + "support_level": "common", + "description": "ScatterElements takes three inputs `data`, `updates`, and `indices` of the same\nrank r >= 1 and an optional attribute axis that identifies an axis of `data`\n(by default, the outer-most axis, that is axis 0). The output of the operation\nis produced by creating a copy of the input `data`, and then updating its value\nto values specified by `updates` at specific index positions specified by\n`indices`. Its output shape is the same as the shape of `data`.\n\nFor each entry in `updates`, the target index in `data` is obtained by combining\nthe corresponding entry in `indices` with the index of the entry itself: the\nindex-value for dimension = axis is obtained from the value of the corresponding\nentry in `indices` and the index-value for dimension != axis is obtained from the\nindex of the entry itself.\n\nFor instance, in a 2-D tensor case, the update corresponding to the [i][j] entry\nis performed as below:\n```\n output[indices[i][j]][j] = updates[i][j] if axis = 0,\n output[i][indices[i][j]] = updates[i][j] if axis = 1,\n```\n\nThis operator is the inverse of GatherElements. It is similar to Torch's Scatter operation.\n\nExample 1:\n```\n data = [\n [0.0, 0.0, 0.0],\n [0.0, 0.0, 0.0],\n [0.0, 0.0, 0.0],\n ]\n indices = [\n [1, 0, 2],\n [0, 2, 1],\n ]\n updates = [\n [1.0, 1.1, 1.2],\n [2.0, 2.1, 2.2],\n ]\n output = [\n [2.0, 1.1, 0.0]\n [1.0, 0.0, 2.2]\n [0.0, 2.1, 1.2]\n ]\n```\nExample 2:\n```\n data = [[1.0, 2.0, 3.0, 4.0, 5.0]]\n indices = [[1, 3]]\n updates = [[1.1, 2.1]]\n axis = 1\n output = [[1.0, 1.1, 3.0, 2.1, 5.0]]\n```\n", + "attributes": [ + { + "name": "axis", + "type": "int64", + "required": false, + "description": "Which axis to scatter on. Negative value means counting dimensions from the back. Accepted range is [-r, r-1] where r = rank(data)." + } + ], + "inputs": [ + { + "name": "data", + "type": "T", + "description": "Tensor of rank r >= 1." + }, + { + "name": "indices", + "type": "Tind", + "description": "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." + }, + { + "name": "updates", + "type": "T", + "description": "Tensor of rank r >=1 (same rank and shape as indices)" + } + ], + "min_input": 3, + "max_input": 3, + "outputs": [ + { + "name": "output", + "type": "T", + "description": "Tensor of rank r >= 1 (same rank as input)." + } + ], + "min_output": 1, + "max_output": 1, + "type_constraints": [ + { + "description": "Input and output types can be of any tensor type.", + "type_param_str": "T", + "allowed_type_strs": [ + "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)" + ] + }, + { + "description": "Constrain indices to integer types", + "type_param_str": "Tind", + "allowed_type_strs": [ + "tensor(int32)", + "tensor(int64)" + ] + } + ], + "examples": [ + { + "summary": "scatter_elements_with_axis", + "code": "axis = 1\nnode = onnx.helper.make_node(\n 'ScatterElements',\n inputs=['data', 'indices', 'updates'],\n outputs=['y'],\n axis=axis,\n)\ndata = np.array([[1.0, 2.0, 3.0, 4.0, 5.0]], dtype=np.float32)\nindices = np.array([[1, 3]], dtype=np.int64)\nupdates = np.array([[1.1, 2.1]], dtype=np.float32)\n\ny = scatter_elements(data, indices, updates, axis)\n# print(y) produces\n# [[1.0, 1.1, 3.0, 2.1, 5.0]]\n\nexpect(node, inputs=[data, indices, updates], outputs=[y],\n name='test_scatter_elements_with_axis')" + }, + { + "summary": "scatter_elements_with_duplicate_indices", + "code": "axis = 1\nnode = onnx.helper.make_node(\n 'ScatterElements',\n inputs=['data', 'indices', 'updates'],\n outputs=['y'],\n axis=axis,\n reduction='add',\n)\ndata = np.array([[1.0, 2.0, 3.0, 4.0, 5.0]], dtype=np.float32)\nindices = np.array([[1, 1]], dtype=np.int64)\nupdates = np.array([[1.1, 2.1]], dtype=np.float32)\n\ny = scatter_elements(data, indices, updates, axis, reduction='add')\n# print(y) produces\n# [[1.0, 5.2, 3.0, 4.0, 5.0]]\n\nexpect(node, inputs=[data, indices, updates], outputs=[y],\n name='test_scatter_elements_with_duplicate_indices')" + }, + { + "summary": "scatter_elements_with_negative_indices", + "code": "axis = 1\nnode = onnx.helper.make_node(\n 'ScatterElements',\n inputs=['data', 'indices', 'updates'],\n outputs=['y'],\n axis=axis,\n)\ndata = np.array([[1.0, 2.0, 3.0, 4.0, 5.0]], dtype=np.float32)\nindices = np.array([[1, -3]], dtype=np.int64)\nupdates = np.array([[1.1, 2.1]], dtype=np.float32)\n\ny = scatter_elements(data, indices, updates, axis)\n# print(y) produces\n# [[1.0, 1.1, 2.1, 4.0, 5.0]]\n\nexpect(node, inputs=[data, indices, updates], outputs=[y],\n name='test_scatter_elements_with_negative_indices')" + }, + { + "summary": "scatter_elements_without_axis", + "code": "node = onnx.helper.make_node(\n 'ScatterElements',\n inputs=['data', 'indices', 'updates'],\n outputs=['y'],\n)\ndata = np.zeros((3, 3), dtype=np.float32)\nindices = np.array([[1, 0, 2], [0, 2, 1]], dtype=np.int64)\nupdates = np.array([[1.0, 1.1, 1.2], [2.0, 2.1, 2.2]], dtype=np.float32)\n\ny = scatter_elements(data, indices, updates)\n# print(y) produces\n# [[2.0, 1.1, 0.0],\n# [1.0, 0.0, 2.2],\n# [0.0, 2.1, 1.2]]\n\nexpect(node, inputs=[data, indices, updates], outputs=[y],\n name='test_scatter_elements_without_axis')" + } + ] + }, + { + "name": "ScatterElements", + "module": "ai.onnx", + "version": 13, + "support_level": "common", + "description": "ScatterElements takes three inputs `data`, `updates`, and `indices` of the same\nrank r >= 1 and an optional attribute axis that identifies an axis of `data`\n(by default, the outer-most axis, that is axis 0). The output of the operation\nis produced by creating a copy of the input `data`, and then updating its value\nto values specified by `updates` at specific index positions specified by\n`indices`. Its output shape is the same as the shape of `data`.\n\nFor each entry in `updates`, the target index in `data` is obtained by combining\nthe corresponding entry in `indices` with the index of the entry itself: the\nindex-value for dimension = axis is obtained from the value of the corresponding\nentry in `indices` and the index-value for dimension != axis is obtained from the\nindex of the entry itself.\n\nFor instance, in a 2-D tensor case, the update corresponding to the [i][j] entry\nis performed as below:\n```\n output[indices[i][j]][j] = updates[i][j] if axis = 0,\n output[i][indices[i][j]] = updates[i][j] if axis = 1,\n```\n\nThis operator is the inverse of GatherElements. It is similar to Torch's Scatter operation.\n\nExample 1:\n```\n data = [\n [0.0, 0.0, 0.0],\n [0.0, 0.0, 0.0],\n [0.0, 0.0, 0.0],\n ]\n indices = [\n [1, 0, 2],\n [0, 2, 1],\n ]\n updates = [\n [1.0, 1.1, 1.2],\n [2.0, 2.1, 2.2],\n ]\n output = [\n [2.0, 1.1, 0.0]\n [1.0, 0.0, 2.2]\n [0.0, 2.1, 1.2]\n ]\n```\nExample 2:\n```\n data = [[1.0, 2.0, 3.0, 4.0, 5.0]]\n indices = [[1, 3]]\n updates = [[1.1, 2.1]]\n axis = 1\n output = [[1.0, 1.1, 3.0, 2.1, 5.0]]\n```\n", + "attributes": [ + { + "name": "axis", + "type": "int64", + "required": false, + "description": "Which axis to scatter on. Negative value means counting dimensions from the back. Accepted range is [-r, r-1] where r = rank(data)." + } + ], + "inputs": [ + { + "name": "data", + "type": "T", + "description": "Tensor of rank r >= 1." + }, + { + "name": "indices", + "type": "Tind", + "description": "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." + }, + { + "name": "updates", + "type": "T", + "description": "Tensor of rank r >=1 (same rank and shape as indices)" + } + ], + "min_input": 3, + "max_input": 3, + "outputs": [ + { + "name": "output", + "type": "T", + "description": "Tensor of rank r >= 1 (same rank as input)." + } + ], + "min_output": 1, + "max_output": 1, + "type_constraints": [ + { + "description": "Input and output types can be of any tensor type.", + "type_param_str": "T", + "allowed_type_strs": [ + "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)" + ] + }, + { + "description": "Constrain indices to integer types", + "type_param_str": "Tind", + "allowed_type_strs": [ + "tensor(int32)", + "tensor(int64)" + ] + } + ], + "examples": [ + { + "summary": "scatter_elements_with_axis", + "code": "axis = 1\nnode = onnx.helper.make_node(\n 'ScatterElements',\n inputs=['data', 'indices', 'updates'],\n outputs=['y'],\n axis=axis,\n)\ndata = np.array([[1.0, 2.0, 3.0, 4.0, 5.0]], dtype=np.float32)\nindices = np.array([[1, 3]], dtype=np.int64)\nupdates = np.array([[1.1, 2.1]], dtype=np.float32)\n\ny = scatter_elements(data, indices, updates, axis)\n# print(y) produces\n# [[1.0, 1.1, 3.0, 2.1, 5.0]]\n\nexpect(node, inputs=[data, indices, updates], outputs=[y],\n name='test_scatter_elements_with_axis')" + }, + { + "summary": "scatter_elements_with_duplicate_indices", + "code": "axis = 1\nnode = onnx.helper.make_node(\n 'ScatterElements',\n inputs=['data', 'indices', 'updates'],\n outputs=['y'],\n axis=axis,\n reduction='add',\n)\ndata = np.array([[1.0, 2.0, 3.0, 4.0, 5.0]], dtype=np.float32)\nindices = np.array([[1, 1]], dtype=np.int64)\nupdates = np.array([[1.1, 2.1]], dtype=np.float32)\n\ny = scatter_elements(data, indices, updates, axis, reduction='add')\n# print(y) produces\n# [[1.0, 5.2, 3.0, 4.0, 5.0]]\n\nexpect(node, inputs=[data, indices, updates], outputs=[y],\n name='test_scatter_elements_with_duplicate_indices')" + }, + { + "summary": "scatter_elements_with_negative_indices", + "code": "axis = 1\nnode = onnx.helper.make_node(\n 'ScatterElements',\n inputs=['data', 'indices', 'updates'],\n outputs=['y'],\n axis=axis,\n)\ndata = np.array([[1.0, 2.0, 3.0, 4.0, 5.0]], dtype=np.float32)\nindices = np.array([[1, -3]], dtype=np.int64)\nupdates = np.array([[1.1, 2.1]], dtype=np.float32)\n\ny = scatter_elements(data, indices, updates, axis)\n# print(y) produces\n# [[1.0, 1.1, 2.1, 4.0, 5.0]]\n\nexpect(node, inputs=[data, indices, updates], outputs=[y],\n name='test_scatter_elements_with_negative_indices')" + }, + { + "summary": "scatter_elements_without_axis", + "code": "node = onnx.helper.make_node(\n 'ScatterElements',\n inputs=['data', 'indices', 'updates'],\n outputs=['y'],\n)\ndata = np.zeros((3, 3), dtype=np.float32)\nindices = np.array([[1, 0, 2], [0, 2, 1]], dtype=np.int64)\nupdates = np.array([[1.0, 1.1, 1.2], [2.0, 2.1, 2.2]], dtype=np.float32)\n\ny = scatter_elements(data, indices, updates)\n# print(y) produces\n# [[2.0, 1.1, 0.0],\n# [1.0, 0.0, 2.2],\n# [0.0, 2.1, 1.2]]\n\nexpect(node, inputs=[data, indices, updates], outputs=[y],\n name='test_scatter_elements_without_axis')" + } + ] + }, + { + "name": "ScatterElements", + "module": "ai.onnx", + "version": 16, + "support_level": "common", + "description": "ScatterElements takes three inputs `data`, `updates`, and `indices` of the same\nrank r >= 1 and an optional attribute axis that identifies an axis of `data`\n(by default, the outer-most axis, that is axis 0). The output of the operation\nis produced by creating a copy of the input `data`, and then updating its value\nto values specified by `updates` at specific index positions specified by\n`indices`. Its output shape is the same as the shape of `data`.\n\nFor each entry in `updates`, the target index in `data` is obtained by combining\nthe corresponding entry in `indices` with the index of the entry itself: the\nindex-value for dimension = axis is obtained from the value of the corresponding\nentry in `indices` and the index-value for dimension != axis is obtained from the\nindex of the entry itself.\n\n`reduction` allows specification of an optional reduction operation, which is applied to all values in `updates`\ntensor into `output` at the specified `indices`.\nIn cases where `reduction` is set to \"none\", indices should not have duplicate entries: that is, if idx1 != idx2, \nthen indices[idx1] != indices[idx2]. For instance, in a 2-D tensor case, the update \ncorresponding to the [i][j] entry is performed as below:\n```\n output[indices[i][j]][j] = updates[i][j] if axis = 0,\n output[i][indices[i][j]] = updates[i][j] if axis = 1,\n```\nWhen `reduction` is set to \"add\", the update corresponding to the [i][j] entry is performed as below:\n```\n output[indices[i][j]][j] += updates[i][j] if axis = 0,\n output[i][indices[i][j]] += updates[i][j] if axis = 1,\n```\nWhen `reduction` is set to \"mul\", the update corresponding to the [i][j] entry is performed as below:\n```\n output[indices[i][j]][j] *= updates[i][j] if axis = 0,\n output[i][indices[i][j]] *= updates[i][j] if axis = 1,\n```\n\nThis operator is the inverse of GatherElements. It is similar to Torch's Scatter operation.\n\nExample 1:\n```\n data = [\n [0.0, 0.0, 0.0],\n [0.0, 0.0, 0.0],\n [0.0, 0.0, 0.0],\n ]\n indices = [\n [1, 0, 2],\n [0, 2, 1],\n ]\n updates = [\n [1.0, 1.1, 1.2],\n [2.0, 2.1, 2.2],\n ]\n output = [\n [2.0, 1.1, 0.0]\n [1.0, 0.0, 2.2]\n [0.0, 2.1, 1.2]\n ]\n```\nExample 2:\n```\n data = [[1.0, 2.0, 3.0, 4.0, 5.0]]\n indices = [[1, 3]]\n updates = [[1.1, 2.1]]\n axis = 1\n output = [[1.0, 1.1, 3.0, 2.1, 5.0]]\n```\n", + "attributes": [ + { + "name": "axis", + "type": "int64", + "required": false, + "description": "Which axis to scatter on. Negative value means counting dimensions from the back. Accepted range is [-r, r-1] where r = rank(data)." + }, + { + "name": "reduction", + "type": "string", + "required": false, + "default": "none", + "description": "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": [ + { + "name": "data", + "type": "T", + "description": "Tensor of rank r >= 1." + }, + { + "name": "indices", + "type": "Tind", + "description": "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." + }, + { + "name": "updates", + "type": "T", + "description": "Tensor of rank r >=1 (same rank and shape as indices)" + } + ], + "min_input": 3, + "max_input": 3, + "outputs": [ + { + "name": "output", + "type": "T", + "description": "Tensor of rank r >= 1 (same rank as input)." + } + ], + "min_output": 1, + "max_output": 1, + "type_constraints": [ + { + "description": "Input and output types can be of any tensor type.", + "type_param_str": "T", + "allowed_type_strs": [ + "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)" + ] + }, + { + "description": "Constrain indices to integer types", + "type_param_str": "Tind", + "allowed_type_strs": [ + "tensor(int32)", + "tensor(int64)" + ] + } + ], + "examples": [ + { + "summary": "scatter_elements_with_axis", + "code": "axis = 1\nnode = onnx.helper.make_node(\n 'ScatterElements',\n inputs=['data', 'indices', 'updates'],\n outputs=['y'],\n axis=axis,\n)\ndata = np.array([[1.0, 2.0, 3.0, 4.0, 5.0]], dtype=np.float32)\nindices = np.array([[1, 3]], dtype=np.int64)\nupdates = np.array([[1.1, 2.1]], dtype=np.float32)\n\ny = scatter_elements(data, indices, updates, axis)\n# print(y) produces\n# [[1.0, 1.1, 3.0, 2.1, 5.0]]\n\nexpect(node, inputs=[data, indices, updates], outputs=[y],\n name='test_scatter_elements_with_axis')" + }, + { + "summary": "scatter_elements_with_duplicate_indices", + "code": "axis = 1\nnode = onnx.helper.make_node(\n 'ScatterElements',\n inputs=['data', 'indices', 'updates'],\n outputs=['y'],\n axis=axis,\n reduction='add',\n)\ndata = np.array([[1.0, 2.0, 3.0, 4.0, 5.0]], dtype=np.float32)\nindices = np.array([[1, 1]], dtype=np.int64)\nupdates = np.array([[1.1, 2.1]], dtype=np.float32)\n\ny = scatter_elements(data, indices, updates, axis, reduction='add')\n# print(y) produces\n# [[1.0, 5.2, 3.0, 4.0, 5.0]]\n\nexpect(node, inputs=[data, indices, updates], outputs=[y],\n name='test_scatter_elements_with_duplicate_indices')" + }, + { + "summary": "scatter_elements_with_negative_indices", + "code": "axis = 1\nnode = onnx.helper.make_node(\n 'ScatterElements',\n inputs=['data', 'indices', 'updates'],\n outputs=['y'],\n axis=axis,\n)\ndata = np.array([[1.0, 2.0, 3.0, 4.0, 5.0]], dtype=np.float32)\nindices = np.array([[1, -3]], dtype=np.int64)\nupdates = np.array([[1.1, 2.1]], dtype=np.float32)\n\ny = scatter_elements(data, indices, updates, axis)\n# print(y) produces\n# [[1.0, 1.1, 2.1, 4.0, 5.0]]\n\nexpect(node, inputs=[data, indices, updates], outputs=[y],\n name='test_scatter_elements_with_negative_indices')" + }, + { + "summary": "scatter_elements_without_axis", + "code": "node = onnx.helper.make_node(\n 'ScatterElements',\n inputs=['data', 'indices', 'updates'],\n outputs=['y'],\n)\ndata = np.zeros((3, 3), dtype=np.float32)\nindices = np.array([[1, 0, 2], [0, 2, 1]], dtype=np.int64)\nupdates = np.array([[1.0, 1.1, 1.2], [2.0, 2.1, 2.2]], dtype=np.float32)\n\ny = scatter_elements(data, indices, updates)\n# print(y) produces\n# [[2.0, 1.1, 0.0],\n# [1.0, 0.0, 2.2],\n# [0.0, 2.1, 1.2]]\n\nexpect(node, inputs=[data, indices, updates], outputs=[y],\n name='test_scatter_elements_without_axis')" + } + ] + }, + { + "name": "ScatterND", + "module": "ai.onnx", + "version": 11, + "support_level": "common", + "description": "ScatterND takes three inputs `data` tensor of rank r >= 1, `indices` tensor of rank q >= 1,\nand `updates` tensor of rank q + r - indices.shape[-1] - 1. The output of the operation\nis produced by creating a copy of the input `data`, and then updating its value to values\nspecified by `updates` at specific index positions specified by `indices`. Its output shape\nis the same as the shape of `data`. Note that `indices` should not have duplicate entries.\nThat is, two or more `updates` for the same index-location is not supported.\n\n`indices` is an integer tensor. Let k denote indices.shape[-1], the last dimension in the shape of `indices`.\n `indices` is treated as a (q-1)-dimensional tensor of k-tuples, where each k-tuple is a partial-index into `data`.\nHence, k can be a value at most the rank of `data`. When k equals rank(data), each update entry specifies an\nupdate to a single element of the tensor. When k is less than rank(data) each update entry specifies an\nupdate to a slice of the tensor.\n\n`updates` is treated as a (q-1)-dimensional tensor of replacement-slice-values. Thus, the\nfirst (q-1) dimensions of updates.shape must match the first (q-1) dimensions of indices.shape.\nThe remaining dimensions of `updates` correspond to the dimensions of the\nreplacement-slice-values. Each replacement-slice-value is a (r-k) dimensional tensor,\ncorresponding to the trailing (r-k) dimensions of `data`. Thus, the shape of `updates`\nmust equal indices.shape[0:q-1] ++ data.shape[k:r-1], where ++ denotes the concatenation\nof shapes.\n\nThe `output` is calculated via the following equation:\n\n output = np.copy(data)\n update_indices = indices.shape[:-1]\n for idx in np.ndindex(update_indices):\n output[indices[idx]] = updates[idx]\n\nThe order of iteration in the above loop is not specified.\nIn particular, indices should not have duplicate entries: that is, if idx1 != idx2, then indices[idx1] != indices[idx2].\nThis ensures that the output value does not depend on the iteration order.\n\nThis operator is the inverse of GatherND.\n\nExample 1:\n```\n data = [1, 2, 3, 4, 5, 6, 7, 8]\n indices = [[4], [3], [1], [7]]\n updates = [9, 10, 11, 12]\n output = [1, 11, 3, 10, 9, 6, 7, 12]\n```\n\nExample 2:\n```\n data = [[[1, 2, 3, 4], [5, 6, 7, 8], [8, 7, 6, 5], [4, 3, 2, 1]],\n [[1, 2, 3, 4], [5, 6, 7, 8], [8, 7, 6, 5], [4, 3, 2, 1]],\n [[8, 7, 6, 5], [4, 3, 2, 1], [1, 2, 3, 4], [5, 6, 7, 8]],\n [[8, 7, 6, 5], [4, 3, 2, 1], [1, 2, 3, 4], [5, 6, 7, 8]]]\n indices = [[0], [2]]\n updates = [[[5, 5, 5, 5], [6, 6, 6, 6], [7, 7, 7, 7], [8, 8, 8, 8]],\n [[1, 1, 1, 1], [2, 2, 2, 2], [3, 3, 3, 3], [4, 4, 4, 4]]]\n output = [[[5, 5, 5, 5], [6, 6, 6, 6], [7, 7, 7, 7], [8, 8, 8, 8]],\n [[1, 2, 3, 4], [5, 6, 7, 8], [8, 7, 6, 5], [4, 3, 2, 1]],\n [[1, 1, 1, 1], [2, 2, 2, 2], [3, 3, 3, 3], [4, 4, 4, 4]],\n [[8, 7, 6, 5], [4, 3, 2, 1], [1, 2, 3, 4], [5, 6, 7, 8]]]\n```\n", + "inputs": [ + { + "name": "data", + "type": "T", + "description": "Tensor of rank r >= 1." + }, + { + "name": "indices", + "type": "tensor(int64)", + "description": "Tensor of rank q >= 1." + }, + { + "name": "updates", + "type": "T", + "description": "Tensor of rank q + r - indices_shape[-1] - 1." + } + ], + "min_input": 3, + "max_input": 3, + "outputs": [ + { + "name": "output", + "type": "T", + "description": "Tensor of rank r >= 1." + } + ], + "min_output": 1, + "max_output": 1, + "type_constraints": [ + { + "description": "Constrain input and output types to any tensor type.", + "type_param_str": "T", + "allowed_type_strs": [ + "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)" + ] + } + ], + "examples": [ + { + "summary": "scatternd", + "code": "node = onnx.helper.make_node(\n 'ScatterND',\n inputs=['data', 'indices', 'updates'],\n outputs=['y'],\n)\ndata = np.array(\n [[[1, 2, 3, 4], [5, 6, 7, 8], [8, 7, 6, 5], [4, 3, 2, 1]],\n [[1, 2, 3, 4], [5, 6, 7, 8], [8, 7, 6, 5], [4, 3, 2, 1]],\n [[8, 7, 6, 5], [4, 3, 2, 1], [1, 2, 3, 4], [5, 6, 7, 8]],\n [[8, 7, 6, 5], [4, 3, 2, 1], [1, 2, 3, 4], [5, 6, 7, 8]]], dtype=np.float32)\nindices = np.array([[0], [2]], dtype=np.int64)\nupdates = np.array(\n [[[5, 5, 5, 5], [6, 6, 6, 6], [7, 7, 7, 7], [8, 8, 8, 8]],\n [[1, 1, 1, 1], [2, 2, 2, 2], [3, 3, 3, 3], [4, 4, 4, 4]]], dtype=np.float32)\n# Expecting output as np.array(\n# [[[5, 5, 5, 5], [6, 6, 6, 6], [7, 7, 7, 7], [8, 8, 8, 8]],\n# [[1, 2, 3, 4], [5, 6, 7, 8], [8, 7, 6, 5], [4, 3, 2, 1]],\n# [[1, 1, 1, 1], [2, 2, 2, 2], [3, 3, 3, 3], [4, 4, 4, 4]],\n# [[8, 7, 6, 5], [4, 3, 2, 1], [1, 2, 3, 4], [5, 6, 7, 8]]], dtype=np.float32)\noutput = scatter_nd_impl(data, indices, updates)\nexpect(node, inputs=[data, indices, updates], outputs=[output],\n name='test_scatternd')" + }, + { + "summary": "scatternd_add", + "code": "node = onnx.helper.make_node(\n 'ScatterND',\n inputs=['data', 'indices', 'updates'],\n outputs=['y'],\n reduction='add',\n)\ndata = np.array(\n [[[1, 2, 3, 4], [5, 6, 7, 8], [8, 7, 6, 5], [4, 3, 2, 1]],\n [[1, 2, 3, 4], [5, 6, 7, 8], [8, 7, 6, 5], [4, 3, 2, 1]],\n [[8, 7, 6, 5], [4, 3, 2, 1], [1, 2, 3, 4], [5, 6, 7, 8]],\n [[8, 7, 6, 5], [4, 3, 2, 1], [1, 2, 3, 4], [5, 6, 7, 8]]], dtype=np.float32)\nindices = np.array([[0], [0]], dtype=np.int64)\nupdates = np.array(\n [[[5, 5, 5, 5], [6, 6, 6, 6], [7, 7, 7, 7], [8, 8, 8, 8]],\n [[1, 1, 1, 1], [2, 2, 2, 2], [3, 3, 3, 3], [4, 4, 4, 4]]], dtype=np.float32)\n# Expecting output as np.array(\n# [[[7, 8, 9, 10], [13, 14, 15, 16], [18, 17, 16, 15], [16, 15, 14, 13]],\n# [[1, 2, 3, 4], [5, 6, 7, 8], [8, 7, 6, 5], [4, 3, 2, 1]],\n# [[1, 1, 1, 1], [2, 2, 2, 2], [3, 3, 3, 3], [4, 4, 4, 4]],\n# [[8, 7, 6, 5], [4, 3, 2, 1], [1, 2, 3, 4], [5, 6, 7, 8]]], dtype=np.float32)\noutput = scatter_nd_impl(data, indices, updates, reduction='add')\nexpect(node, inputs=[data, indices, updates], outputs=[output],\n name='test_scatternd_add')" + }, + { + "summary": "scatternd_multiply", + "code": "node = onnx.helper.make_node(\n 'ScatterND',\n inputs=['data', 'indices', 'updates'],\n outputs=['y'],\n reduction='mul',\n)\ndata = np.array(\n [[[1, 2, 3, 4], [5, 6, 7, 8], [8, 7, 6, 5], [4, 3, 2, 1]],\n [[1, 2, 3, 4], [5, 6, 7, 8], [8, 7, 6, 5], [4, 3, 2, 1]],\n [[8, 7, 6, 5], [4, 3, 2, 1], [1, 2, 3, 4], [5, 6, 7, 8]],\n [[8, 7, 6, 5], [4, 3, 2, 1], [1, 2, 3, 4], [5, 6, 7, 8]]], dtype=np.float32)\nindices = np.array([[0], [0]], dtype=np.int64)\nupdates = np.array(\n [[[5, 5, 5, 5], [6, 6, 6, 6], [7, 7, 7, 7], [8, 8, 8, 8]],\n [[1, 1, 1, 1], [2, 2, 2, 2], [3, 3, 3, 3], [4, 4, 4, 4]]], dtype=np.float32)\n# Expecting output as np.array(\n# [[[5, 10, 15, 20], [60, 72, 84, 96], [168, 147, 126, 105], [128, 96, 64, 32]],\n# [[1, 2, 3, 4], [5, 6, 7, 8], [8, 7, 6, 5], [4, 3, 2, 1]],\n# [[1, 1, 1, 1], [2, 2, 2, 2], [3, 3, 3, 3], [4, 4, 4, 4]],\n# [[8, 7, 6, 5], [4, 3, 2, 1], [1, 2, 3, 4], [5, 6, 7, 8]]], dtype=np.float32)\noutput = scatter_nd_impl(data, indices, updates, reduction='mul')\nexpect(node, inputs=[data, indices, updates], outputs=[output],\n name='test_scatternd_multiply')" + } + ] + }, + { + "name": "ScatterND", + "module": "ai.onnx", + "version": 13, + "support_level": "common", + "description": "ScatterND takes three inputs `data` tensor of rank r >= 1, `indices` tensor of rank q >= 1,\nand `updates` tensor of rank q + r - indices.shape[-1] - 1. The output of the operation\nis produced by creating a copy of the input `data`, and then updating its value to values\nspecified by `updates` at specific index positions specified by `indices`. Its output shape\nis the same as the shape of `data`. Note that `indices` should not have duplicate entries.\nThat is, two or more `updates` for the same index-location is not supported.\n\n`indices` is an integer tensor. Let k denote indices.shape[-1], the last dimension in the shape of `indices`.\n `indices` is treated as a (q-1)-dimensional tensor of k-tuples, where each k-tuple is a partial-index into `data`.\nHence, k can be a value at most the rank of `data`. When k equals rank(data), each update entry specifies an\nupdate to a single element of the tensor. When k is less than rank(data) each update entry specifies an\nupdate to a slice of the tensor.\n\n`updates` is treated as a (q-1)-dimensional tensor of replacement-slice-values. Thus, the\nfirst (q-1) dimensions of updates.shape must match the first (q-1) dimensions of indices.shape.\nThe remaining dimensions of `updates` correspond to the dimensions of the\nreplacement-slice-values. Each replacement-slice-value is a (r-k) dimensional tensor,\ncorresponding to the trailing (r-k) dimensions of `data`. Thus, the shape of `updates`\nmust equal indices.shape[0:q-1] ++ data.shape[k:r-1], where ++ denotes the concatenation\nof shapes.\n\nThe `output` is calculated via the following equation:\n\n output = np.copy(data)\n update_indices = indices.shape[:-1]\n for idx in np.ndindex(update_indices):\n output[indices[idx]] = updates[idx]\n\nThe order of iteration in the above loop is not specified.\nIn particular, indices should not have duplicate entries: that is, if idx1 != idx2, then indices[idx1] != indices[idx2].\nThis ensures that the output value does not depend on the iteration order.\n\nThis operator is the inverse of GatherND.\n\nExample 1:\n```\n data = [1, 2, 3, 4, 5, 6, 7, 8]\n indices = [[4], [3], [1], [7]]\n updates = [9, 10, 11, 12]\n output = [1, 11, 3, 10, 9, 6, 7, 12]\n```\n\nExample 2:\n```\n data = [[[1, 2, 3, 4], [5, 6, 7, 8], [8, 7, 6, 5], [4, 3, 2, 1]],\n [[1, 2, 3, 4], [5, 6, 7, 8], [8, 7, 6, 5], [4, 3, 2, 1]],\n [[8, 7, 6, 5], [4, 3, 2, 1], [1, 2, 3, 4], [5, 6, 7, 8]],\n [[8, 7, 6, 5], [4, 3, 2, 1], [1, 2, 3, 4], [5, 6, 7, 8]]]\n indices = [[0], [2]]\n updates = [[[5, 5, 5, 5], [6, 6, 6, 6], [7, 7, 7, 7], [8, 8, 8, 8]],\n [[1, 1, 1, 1], [2, 2, 2, 2], [3, 3, 3, 3], [4, 4, 4, 4]]]\n output = [[[5, 5, 5, 5], [6, 6, 6, 6], [7, 7, 7, 7], [8, 8, 8, 8]],\n [[1, 2, 3, 4], [5, 6, 7, 8], [8, 7, 6, 5], [4, 3, 2, 1]],\n [[1, 1, 1, 1], [2, 2, 2, 2], [3, 3, 3, 3], [4, 4, 4, 4]],\n [[8, 7, 6, 5], [4, 3, 2, 1], [1, 2, 3, 4], [5, 6, 7, 8]]]\n```\n", + "inputs": [ + { + "name": "data", + "type": "T", + "description": "Tensor of rank r >= 1." + }, + { + "name": "indices", + "type": "tensor(int64)", + "description": "Tensor of rank q >= 1." + }, + { + "name": "updates", + "type": "T", + "description": "Tensor of rank q + r - indices_shape[-1] - 1." + } + ], + "min_input": 3, + "max_input": 3, + "outputs": [ + { + "name": "output", + "type": "T", + "description": "Tensor of rank r >= 1." + } + ], + "min_output": 1, + "max_output": 1, + "type_constraints": [ + { + "description": "Constrain input and output types to any tensor type.", + "type_param_str": "T", + "allowed_type_strs": [ + "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)" + ] + } + ], + "examples": [ + { + "summary": "scatternd", + "code": "node = onnx.helper.make_node(\n 'ScatterND',\n inputs=['data', 'indices', 'updates'],\n outputs=['y'],\n)\ndata = np.array(\n [[[1, 2, 3, 4], [5, 6, 7, 8], [8, 7, 6, 5], [4, 3, 2, 1]],\n [[1, 2, 3, 4], [5, 6, 7, 8], [8, 7, 6, 5], [4, 3, 2, 1]],\n [[8, 7, 6, 5], [4, 3, 2, 1], [1, 2, 3, 4], [5, 6, 7, 8]],\n [[8, 7, 6, 5], [4, 3, 2, 1], [1, 2, 3, 4], [5, 6, 7, 8]]], dtype=np.float32)\nindices = np.array([[0], [2]], dtype=np.int64)\nupdates = np.array(\n [[[5, 5, 5, 5], [6, 6, 6, 6], [7, 7, 7, 7], [8, 8, 8, 8]],\n [[1, 1, 1, 1], [2, 2, 2, 2], [3, 3, 3, 3], [4, 4, 4, 4]]], dtype=np.float32)\n# Expecting output as np.array(\n# [[[5, 5, 5, 5], [6, 6, 6, 6], [7, 7, 7, 7], [8, 8, 8, 8]],\n# [[1, 2, 3, 4], [5, 6, 7, 8], [8, 7, 6, 5], [4, 3, 2, 1]],\n# [[1, 1, 1, 1], [2, 2, 2, 2], [3, 3, 3, 3], [4, 4, 4, 4]],\n# [[8, 7, 6, 5], [4, 3, 2, 1], [1, 2, 3, 4], [5, 6, 7, 8]]], dtype=np.float32)\noutput = scatter_nd_impl(data, indices, updates)\nexpect(node, inputs=[data, indices, updates], outputs=[output],\n name='test_scatternd')" + }, + { + "summary": "scatternd_add", + "code": "node = onnx.helper.make_node(\n 'ScatterND',\n inputs=['data', 'indices', 'updates'],\n outputs=['y'],\n reduction='add',\n)\ndata = np.array(\n [[[1, 2, 3, 4], [5, 6, 7, 8], [8, 7, 6, 5], [4, 3, 2, 1]],\n [[1, 2, 3, 4], [5, 6, 7, 8], [8, 7, 6, 5], [4, 3, 2, 1]],\n [[8, 7, 6, 5], [4, 3, 2, 1], [1, 2, 3, 4], [5, 6, 7, 8]],\n [[8, 7, 6, 5], [4, 3, 2, 1], [1, 2, 3, 4], [5, 6, 7, 8]]], dtype=np.float32)\nindices = np.array([[0], [0]], dtype=np.int64)\nupdates = np.array(\n [[[5, 5, 5, 5], [6, 6, 6, 6], [7, 7, 7, 7], [8, 8, 8, 8]],\n [[1, 1, 1, 1], [2, 2, 2, 2], [3, 3, 3, 3], [4, 4, 4, 4]]], dtype=np.float32)\n# Expecting output as np.array(\n# [[[7, 8, 9, 10], [13, 14, 15, 16], [18, 17, 16, 15], [16, 15, 14, 13]],\n# [[1, 2, 3, 4], [5, 6, 7, 8], [8, 7, 6, 5], [4, 3, 2, 1]],\n# [[1, 1, 1, 1], [2, 2, 2, 2], [3, 3, 3, 3], [4, 4, 4, 4]],\n# [[8, 7, 6, 5], [4, 3, 2, 1], [1, 2, 3, 4], [5, 6, 7, 8]]], dtype=np.float32)\noutput = scatter_nd_impl(data, indices, updates, reduction='add')\nexpect(node, inputs=[data, indices, updates], outputs=[output],\n name='test_scatternd_add')" + }, + { + "summary": "scatternd_multiply", + "code": "node = onnx.helper.make_node(\n 'ScatterND',\n inputs=['data', 'indices', 'updates'],\n outputs=['y'],\n reduction='mul',\n)\ndata = np.array(\n [[[1, 2, 3, 4], [5, 6, 7, 8], [8, 7, 6, 5], [4, 3, 2, 1]],\n [[1, 2, 3, 4], [5, 6, 7, 8], [8, 7, 6, 5], [4, 3, 2, 1]],\n [[8, 7, 6, 5], [4, 3, 2, 1], [1, 2, 3, 4], [5, 6, 7, 8]],\n [[8, 7, 6, 5], [4, 3, 2, 1], [1, 2, 3, 4], [5, 6, 7, 8]]], dtype=np.float32)\nindices = np.array([[0], [0]], dtype=np.int64)\nupdates = np.array(\n [[[5, 5, 5, 5], [6, 6, 6, 6], [7, 7, 7, 7], [8, 8, 8, 8]],\n [[1, 1, 1, 1], [2, 2, 2, 2], [3, 3, 3, 3], [4, 4, 4, 4]]], dtype=np.float32)\n# Expecting output as np.array(\n# [[[5, 10, 15, 20], [60, 72, 84, 96], [168, 147, 126, 105], [128, 96, 64, 32]],\n# [[1, 2, 3, 4], [5, 6, 7, 8], [8, 7, 6, 5], [4, 3, 2, 1]],\n# [[1, 1, 1, 1], [2, 2, 2, 2], [3, 3, 3, 3], [4, 4, 4, 4]],\n# [[8, 7, 6, 5], [4, 3, 2, 1], [1, 2, 3, 4], [5, 6, 7, 8]]], dtype=np.float32)\noutput = scatter_nd_impl(data, indices, updates, reduction='mul')\nexpect(node, inputs=[data, indices, updates], outputs=[output],\n name='test_scatternd_multiply')" + } + ] + }, + { + "name": "ScatterND", + "module": "ai.onnx", + "version": 16, + "support_level": "common", + "description": "ScatterND takes three inputs `data` tensor of rank r >= 1, `indices` tensor of rank q >= 1,\nand `updates` tensor of rank q + r - indices.shape[-1] - 1. The output of the operation\nis produced by creating a copy of the input `data`, and then updating its value to values\nspecified by `updates` at specific index positions specified by `indices`. Its output shape\nis the same as the shape of `data`. Note that `indices` should not have duplicate entries.\nThat is, two or more `updates` for the same index-location is not supported.\n\n`indices` is an integer tensor. Let k denote indices.shape[-1], the last dimension in the shape of `indices`.\n `indices` is treated as a (q-1)-dimensional tensor of k-tuples, where each k-tuple is a partial-index into `data`.\nHence, k can be a value at most the rank of `data`. When k equals rank(data), each update entry specifies an\nupdate to a single element of the tensor. When k is less than rank(data) each update entry specifies an\nupdate to a slice of the tensor.\n\n`updates` is treated as a (q-1)-dimensional tensor of replacement-slice-values. Thus, the\nfirst (q-1) dimensions of updates.shape must match the first (q-1) dimensions of indices.shape.\nThe remaining dimensions of `updates` correspond to the dimensions of the\nreplacement-slice-values. Each replacement-slice-value is a (r-k) dimensional tensor,\ncorresponding to the trailing (r-k) dimensions of `data`. Thus, the shape of `updates`\nmust equal indices.shape[0:q-1] ++ data.shape[k:r-1], where ++ denotes the concatenation\nof shapes.\n\nThe `output` is calculated via the following equation:\n\n output = np.copy(data)\n update_indices = indices.shape[:-1]\n for idx in np.ndindex(update_indices):\n output[indices[idx]] = updates[idx]\n\nThe order of iteration in the above loop is not specified.\nIn particular, indices should not have duplicate entries: that is, if idx1 != idx2, then indices[idx1] != indices[idx2].\nThis ensures that the output value does not depend on the iteration order.\n\n`reduction` allows specification of an optional reduction operation, which is applied to all values in `updates`\ntensor into `output` at the specified `indices`.\nIn cases where `reduction` is set to \"none\", indices should not have duplicate entries: that is, if idx1 != idx2, \nthen indices[idx1] != indices[idx2]. This ensures that the output value does not depend on the iteration order.\nWhen `reduction` is set to \"add\", `output` is calculated as follows:\n\n output = np.copy(data)\n update_indices = indices.shape[:-1]\n for idx in np.ndindex(update_indices):\n output[indices[idx]] += updates[idx]\n\nWhen `reduction` is set to \"mul\", `output` is calculated as follows:\n\n output = np.copy(data)\n update_indices = indices.shape[:-1]\n for idx in np.ndindex(update_indices):\n output[indices[idx]] *= updates[idx]\n\nThis operator is the inverse of GatherND.\n\nExample 1:\n```\n data = [1, 2, 3, 4, 5, 6, 7, 8]\n indices = [[4], [3], [1], [7]]\n updates = [9, 10, 11, 12]\n output = [1, 11, 3, 10, 9, 6, 7, 12]\n```\n\nExample 2:\n```\n data = [[[1, 2, 3, 4], [5, 6, 7, 8], [8, 7, 6, 5], [4, 3, 2, 1]],\n [[1, 2, 3, 4], [5, 6, 7, 8], [8, 7, 6, 5], [4, 3, 2, 1]],\n [[8, 7, 6, 5], [4, 3, 2, 1], [1, 2, 3, 4], [5, 6, 7, 8]],\n [[8, 7, 6, 5], [4, 3, 2, 1], [1, 2, 3, 4], [5, 6, 7, 8]]]\n indices = [[0], [2]]\n updates = [[[5, 5, 5, 5], [6, 6, 6, 6], [7, 7, 7, 7], [8, 8, 8, 8]],\n [[1, 1, 1, 1], [2, 2, 2, 2], [3, 3, 3, 3], [4, 4, 4, 4]]]\n output = [[[5, 5, 5, 5], [6, 6, 6, 6], [7, 7, 7, 7], [8, 8, 8, 8]],\n [[1, 2, 3, 4], [5, 6, 7, 8], [8, 7, 6, 5], [4, 3, 2, 1]],\n [[1, 1, 1, 1], [2, 2, 2, 2], [3, 3, 3, 3], [4, 4, 4, 4]],\n [[8, 7, 6, 5], [4, 3, 2, 1], [1, 2, 3, 4], [5, 6, 7, 8]]]\n```\n", + "attributes": [ + { + "name": "reduction", + "type": "string", + "required": false, + "default": "none", + "description": "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": [ + { + "name": "data", + "type": "T", + "description": "Tensor of rank r >= 1." + }, + { + "name": "indices", + "type": "tensor(int64)", + "description": "Tensor of rank q >= 1." + }, + { + "name": "updates", + "type": "T", + "description": "Tensor of rank q + r - indices_shape[-1] - 1." + } + ], + "min_input": 3, + "max_input": 3, + "outputs": [ + { + "name": "output", + "type": "T", + "description": "Tensor of rank r >= 1." + } + ], + "min_output": 1, + "max_output": 1, + "type_constraints": [ + { + "description": "Constrain input and output types to any tensor type.", + "type_param_str": "T", + "allowed_type_strs": [ + "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)" + ] + } + ], + "examples": [ + { + "summary": "scatternd", + "code": "node = onnx.helper.make_node(\n 'ScatterND',\n inputs=['data', 'indices', 'updates'],\n outputs=['y'],\n)\ndata = np.array(\n [[[1, 2, 3, 4], [5, 6, 7, 8], [8, 7, 6, 5], [4, 3, 2, 1]],\n [[1, 2, 3, 4], [5, 6, 7, 8], [8, 7, 6, 5], [4, 3, 2, 1]],\n [[8, 7, 6, 5], [4, 3, 2, 1], [1, 2, 3, 4], [5, 6, 7, 8]],\n [[8, 7, 6, 5], [4, 3, 2, 1], [1, 2, 3, 4], [5, 6, 7, 8]]], dtype=np.float32)\nindices = np.array([[0], [2]], dtype=np.int64)\nupdates = np.array(\n [[[5, 5, 5, 5], [6, 6, 6, 6], [7, 7, 7, 7], [8, 8, 8, 8]],\n [[1, 1, 1, 1], [2, 2, 2, 2], [3, 3, 3, 3], [4, 4, 4, 4]]], dtype=np.float32)\n# Expecting output as np.array(\n# [[[5, 5, 5, 5], [6, 6, 6, 6], [7, 7, 7, 7], [8, 8, 8, 8]],\n# [[1, 2, 3, 4], [5, 6, 7, 8], [8, 7, 6, 5], [4, 3, 2, 1]],\n# [[1, 1, 1, 1], [2, 2, 2, 2], [3, 3, 3, 3], [4, 4, 4, 4]],\n# [[8, 7, 6, 5], [4, 3, 2, 1], [1, 2, 3, 4], [5, 6, 7, 8]]], dtype=np.float32)\noutput = scatter_nd_impl(data, indices, updates)\nexpect(node, inputs=[data, indices, updates], outputs=[output],\n name='test_scatternd')" + }, + { + "summary": "scatternd_add", + "code": "node = onnx.helper.make_node(\n 'ScatterND',\n inputs=['data', 'indices', 'updates'],\n outputs=['y'],\n reduction='add',\n)\ndata = np.array(\n [[[1, 2, 3, 4], [5, 6, 7, 8], [8, 7, 6, 5], [4, 3, 2, 1]],\n [[1, 2, 3, 4], [5, 6, 7, 8], [8, 7, 6, 5], [4, 3, 2, 1]],\n [[8, 7, 6, 5], [4, 3, 2, 1], [1, 2, 3, 4], [5, 6, 7, 8]],\n [[8, 7, 6, 5], [4, 3, 2, 1], [1, 2, 3, 4], [5, 6, 7, 8]]], dtype=np.float32)\nindices = np.array([[0], [0]], dtype=np.int64)\nupdates = np.array(\n [[[5, 5, 5, 5], [6, 6, 6, 6], [7, 7, 7, 7], [8, 8, 8, 8]],\n [[1, 1, 1, 1], [2, 2, 2, 2], [3, 3, 3, 3], [4, 4, 4, 4]]], dtype=np.float32)\n# Expecting output as np.array(\n# [[[7, 8, 9, 10], [13, 14, 15, 16], [18, 17, 16, 15], [16, 15, 14, 13]],\n# [[1, 2, 3, 4], [5, 6, 7, 8], [8, 7, 6, 5], [4, 3, 2, 1]],\n# [[1, 1, 1, 1], [2, 2, 2, 2], [3, 3, 3, 3], [4, 4, 4, 4]],\n# [[8, 7, 6, 5], [4, 3, 2, 1], [1, 2, 3, 4], [5, 6, 7, 8]]], dtype=np.float32)\noutput = scatter_nd_impl(data, indices, updates, reduction='add')\nexpect(node, inputs=[data, indices, updates], outputs=[output],\n name='test_scatternd_add')" + }, + { + "summary": "scatternd_multiply", + "code": "node = onnx.helper.make_node(\n 'ScatterND',\n inputs=['data', 'indices', 'updates'],\n outputs=['y'],\n reduction='mul',\n)\ndata = np.array(\n [[[1, 2, 3, 4], [5, 6, 7, 8], [8, 7, 6, 5], [4, 3, 2, 1]],\n [[1, 2, 3, 4], [5, 6, 7, 8], [8, 7, 6, 5], [4, 3, 2, 1]],\n [[8, 7, 6, 5], [4, 3, 2, 1], [1, 2, 3, 4], [5, 6, 7, 8]],\n [[8, 7, 6, 5], [4, 3, 2, 1], [1, 2, 3, 4], [5, 6, 7, 8]]], dtype=np.float32)\nindices = np.array([[0], [0]], dtype=np.int64)\nupdates = np.array(\n [[[5, 5, 5, 5], [6, 6, 6, 6], [7, 7, 7, 7], [8, 8, 8, 8]],\n [[1, 1, 1, 1], [2, 2, 2, 2], [3, 3, 3, 3], [4, 4, 4, 4]]], dtype=np.float32)\n# Expecting output as np.array(\n# [[[5, 10, 15, 20], [60, 72, 84, 96], [168, 147, 126, 105], [128, 96, 64, 32]],\n# [[1, 2, 3, 4], [5, 6, 7, 8], [8, 7, 6, 5], [4, 3, 2, 1]],\n# [[1, 1, 1, 1], [2, 2, 2, 2], [3, 3, 3, 3], [4, 4, 4, 4]],\n# [[8, 7, 6, 5], [4, 3, 2, 1], [1, 2, 3, 4], [5, 6, 7, 8]]], dtype=np.float32)\noutput = scatter_nd_impl(data, indices, updates, reduction='mul')\nexpect(node, inputs=[data, indices, updates], outputs=[output],\n name='test_scatternd_multiply')" + } + ] + }, + { + "name": "Selu", + "module": "ai.onnx", + "version": 1, + "support_level": "common", + "description": "Selu takes one input data (Tensor) and produces one output data\n(Tensor) where the scaled exponential linear unit function,\n`y = gamma * (alpha * e^x - alpha) for x <= 0`, `y = gamma * x for x > 0`,\nis applied to the tensor elementwise.\n", + "attributes": [ + { + "name": "alpha", + "type": "float32", + "required": false, + "default": 1.673200011253357, + "description": "Coefficient of SELU default to 1.6732." + }, + { + "name": "consumed_inputs", + "type": "int64[]", + "required": false, + "description": "legacy optimization attribute." + }, + { + "name": "gamma", + "type": "float32", + "required": false, + "default": 1.0506999492645264, + "description": "Coefficient of SELU default to 1.0507." + } + ], + "inputs": [ + { + "name": "X", + "type": "T", + "description": "Input tensor" + } + ], + "min_input": 1, + "max_input": 1, + "outputs": [ + { + "name": "Y", + "type": "T", + "description": "Output tensor" + } + ], + "min_output": 1, + "max_output": 1, + "type_constraints": [ + { + "description": "Constrain input and output types to float tensors.", + "type_param_str": "T", + "allowed_type_strs": [ + "tensor(float16)", + "tensor(float)", + "tensor(double)" + ] + } + ], + "examples": [ + { + "summary": "selu", + "code": "node = onnx.helper.make_node(\n 'Selu',\n inputs=['x'],\n outputs=['y'],\n alpha=2.0,\n gamma=3.0\n)\n\nx = np.array([-1, 0, 1]).astype(np.float32)\n# expected output [-3.79272318, 0., 3.]\ny = np.clip(x, 0, np.inf) * 3.0 + (np.exp(np.clip(x, -np.inf, 0)) - 1) * 2.0 * 3.0\nexpect(node, inputs=[x], outputs=[y],\n name='test_selu_example')\n\nx = np.random.randn(3, 4, 5).astype(np.float32)\ny = np.clip(x, 0, np.inf) * 3.0 + (np.exp(np.clip(x, -np.inf, 0)) - 1) * 2.0 * 3.0\nexpect(node, inputs=[x], outputs=[y],\n name='test_selu')" + }, + { + "summary": "selu_default", + "code": "default_alpha = 1.67326319217681884765625\ndefault_gamma = 1.05070102214813232421875\nnode = onnx.helper.make_node(\n 'Selu',\n inputs=['x'],\n outputs=['y'],\n)\nx = np.random.randn(3, 4, 5).astype(np.float32)\ny = np.clip(x, 0, np.inf) * default_gamma + \\\n (np.exp(np.clip(x, -np.inf, 0)) - 1) * default_alpha * default_gamma\nexpect(node, inputs=[x], outputs=[y],\n name='test_selu_default')" + } + ], + "category": "Activation" + }, + { + "name": "Selu", + "module": "ai.onnx", + "version": 6, + "support_level": "common", + "description": "Selu takes one input data (Tensor) and produces one output data\n(Tensor) where the scaled exponential linear unit function,\n`y = gamma * (alpha * e^x - alpha) for x <= 0`, `y = gamma * x for x > 0`,\nis applied to the tensor elementwise.\n", + "attributes": [ + { + "name": "alpha", + "type": "float32", + "required": false, + "default": 1.6732631921768188, + "description": "Coefficient of SELU default to 1.67326319217681884765625 (i.e., float32 approximation of 1.6732632423543772848170429916717)." + }, + { + "name": "gamma", + "type": "float32", + "required": false, + "default": 1.0507010221481323, + "description": "Coefficient of SELU default to 1.05070102214813232421875 (i.e., float32 approximation of 1.0507009873554804934193349852946)." + } + ], + "inputs": [ + { + "name": "X", + "type": "T", + "description": "Input tensor" + } + ], + "min_input": 1, + "max_input": 1, + "outputs": [ + { + "name": "Y", + "type": "T", + "description": "Output tensor" + } + ], + "min_output": 1, + "max_output": 1, + "type_constraints": [ + { + "description": "Constrain input and output types to float tensors.", + "type_param_str": "T", + "allowed_type_strs": [ + "tensor(float16)", + "tensor(float)", + "tensor(double)" + ] + } + ], + "examples": [ + { + "summary": "selu", + "code": "node = onnx.helper.make_node(\n 'Selu',\n inputs=['x'],\n outputs=['y'],\n alpha=2.0,\n gamma=3.0\n)\n\nx = np.array([-1, 0, 1]).astype(np.float32)\n# expected output [-3.79272318, 0., 3.]\ny = np.clip(x, 0, np.inf) * 3.0 + (np.exp(np.clip(x, -np.inf, 0)) - 1) * 2.0 * 3.0\nexpect(node, inputs=[x], outputs=[y],\n name='test_selu_example')\n\nx = np.random.randn(3, 4, 5).astype(np.float32)\ny = np.clip(x, 0, np.inf) * 3.0 + (np.exp(np.clip(x, -np.inf, 0)) - 1) * 2.0 * 3.0\nexpect(node, inputs=[x], outputs=[y],\n name='test_selu')" + }, + { + "summary": "selu_default", + "code": "default_alpha = 1.67326319217681884765625\ndefault_gamma = 1.05070102214813232421875\nnode = onnx.helper.make_node(\n 'Selu',\n inputs=['x'],\n outputs=['y'],\n)\nx = np.random.randn(3, 4, 5).astype(np.float32)\ny = np.clip(x, 0, np.inf) * default_gamma + \\\n (np.exp(np.clip(x, -np.inf, 0)) - 1) * default_alpha * default_gamma\nexpect(node, inputs=[x], outputs=[y],\n name='test_selu_default')" + } + ], + "category": "Activation" + }, + { + "name": "SequenceAt", + "module": "ai.onnx", + "version": 11, + "support_level": "common", + "description": "Outputs a tensor copy from the tensor at 'position' in 'input_sequence'.\nAccepted range for 'position' is in `[-n, n - 1]`, where `n` is the number of tensors in 'input_sequence'.\nNegative value means counting positions from the back.\n", + "inputs": [ + { + "name": "input_sequence", + "type": "S", + "description": "Input sequence." + }, + { + "name": "position", + "type": "I", + "description": "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)." + } + ], + "min_input": 2, + "max_input": 2, + "outputs": [ + { + "name": "tensor", + "type": "T", + "description": "Output tensor at the specified position in the input sequence." + } + ], + "min_output": 1, + "max_output": 1, + "type_constraints": [ + { + "description": "Constrain to any tensor type.", + "type_param_str": "S", + "allowed_type_strs": [ + "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))" + ] + }, + { + "description": "Constrain to any tensor type.", + "type_param_str": "T", + "allowed_type_strs": [ + "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)" + ] + }, + { + "description": "Constrain position to integral tensor. It must be a scalar(tensor of empty shape).", + "type_param_str": "I", + "allowed_type_strs": [ + "tensor(int32)", + "tensor(int64)" + ] + } + ] + }, + { + "name": "SequenceConstruct", + "module": "ai.onnx", + "version": 11, + "support_level": "common", + "description": "Construct a tensor sequence containing 'inputs' tensors.\nAll tensors in 'inputs' must have the same data type.\n", + "inputs": [ + { + "name": "inputs", + "type": "T", + "list": true, + "description": "Tensors." + } + ], + "min_input": 1, + "max_input": 2147483647, + "outputs": [ + { + "name": "output_sequence", + "type": "S", + "description": "Sequence enclosing the input tensors." + } + ], + "min_output": 1, + "max_output": 1, + "inputs_range": "1 - ∞", + "type_constraints": [ + { + "description": "Constrain input types to any tensor type.", + "type_param_str": "T", + "allowed_type_strs": [ + "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)" + ] + }, + { + "description": "Constrain output types to any tensor type.", + "type_param_str": "S", + "allowed_type_strs": [ + "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))" + ] + } + ] + }, + { + "name": "SequenceEmpty", + "module": "ai.onnx", + "version": 11, + "support_level": "common", + "description": "Construct an empty tensor sequence, with given data type.\n", + "attributes": [ + { + "name": "dtype", + "type": "int64", + "required": false, + "description": "(Optional) The data type of the tensors in the output sequence. The default type is 'float'." + } + ], + "min_input": 0, + "max_input": 0, + "outputs": [ + { + "name": "output", + "type": "S", + "description": "Empty sequence." + } + ], + "min_output": 1, + "max_output": 1, + "type_constraints": [ + { + "description": "Constrain output types to any tensor type.", + "type_param_str": "S", + "allowed_type_strs": [ + "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))" + ] + } + ] + }, + { + "name": "SequenceErase", + "module": "ai.onnx", + "version": 11, + "support_level": "common", + "description": "Outputs a tensor sequence that removes the tensor at 'position' from 'input_sequence'.\nAccepted range for 'position' is in `[-n, n - 1]`, where `n` is the number of tensors in 'input_sequence'.\nNegative value means counting positions from the back.\n'position' is optional, by default it erases the last tensor from 'input_sequence'.\n", + "inputs": [ + { + "name": "input_sequence", + "type": "S", + "description": "Input sequence." + }, + { + "name": "position", + "type": "I", + "option": "optional", + "description": "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)." + } + ], + "min_input": 1, + "max_input": 2, + "outputs": [ + { + "name": "output_sequence", + "type": "S", + "description": "Output sequence that has the tensor at the specified position removed." + } + ], + "min_output": 1, + "max_output": 1, + "inputs_range": "1 - 2", + "type_constraints": [ + { + "description": "Constrain to any tensor type.", + "type_param_str": "S", + "allowed_type_strs": [ + "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))" + ] + }, + { + "description": "Constrain position to integral tensor. It must be a scalar(tensor of empty shape).", + "type_param_str": "I", + "allowed_type_strs": [ + "tensor(int32)", + "tensor(int64)" + ] + } + ] + }, + { + "name": "SequenceInsert", + "module": "ai.onnx", + "version": 11, + "support_level": "common", + "description": "Outputs a tensor sequence that inserts 'tensor' into 'input_sequence' at 'position'.\n'tensor' must have the same data type as 'input_sequence'.\nAccepted range for 'position' is in `[-n, n]`, where `n` is the number of tensors in 'input_sequence'.\nNegative value means counting positions from the back.\n'position' is optional, by default it inserts 'tensor' to the back of 'input_sequence'.\n", + "inputs": [ + { + "name": "input_sequence", + "type": "S", + "description": "Input sequence." + }, + { + "name": "tensor", + "type": "T", + "description": "Input tensor to be inserted into the input sequence." + }, + { + "name": "position", + "type": "I", + "option": "optional", + "description": "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)." + } + ], + "min_input": 2, + "max_input": 3, + "outputs": [ + { + "name": "output_sequence", + "type": "S", + "description": "Output sequence that contains the inserted tensor at given position." + } + ], + "min_output": 1, + "max_output": 1, + "inputs_range": "2 - 3", + "type_constraints": [ + { + "description": "Constrain to any tensor type.", + "type_param_str": "T", + "allowed_type_strs": [ + "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)" + ] + }, + { + "description": "Constrain to any tensor type.", + "type_param_str": "S", + "allowed_type_strs": [ + "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))" + ] + }, + { + "description": "Constrain position to integral tensor. It must be a scalar(tensor of empty shape).", + "type_param_str": "I", + "allowed_type_strs": [ + "tensor(int32)", + "tensor(int64)" + ] + } + ], + "examples": [ + { + "summary": "sequenceinsert", + "code": "test_cases = {\n 'at_back': [np.array([10, 11, 12]).astype(np.int64)],\n 'at_front': [np.array([-2, -1, 0]), np.array([0]).astype(np.int64)]\n}\nsequence = [np.array([1, 2, 3, 4]).astype(np.int64), np.array([5, 6, 7]).astype(np.int64), np.array([8, 9]).astype(np.int64)]\n\nfor test_name, test_inputs in test_cases.items():\n tensor = test_inputs[0].astype(np.int64)\n\n if len(test_inputs) > 1:\n node = onnx.helper.make_node(\n 'SequenceInsert',\n inputs=['sequence', 'tensor', 'position'],\n outputs=['output_sequence']\n )\n position = test_inputs[1]\n inserted = sequence_insert_reference_implementation(sequence, tensor, position)\n expect(node, inputs=[sequence, tensor, position], outputs=[inserted],\n name='test_sequence_insert_' + test_name)\n else:\n node = onnx.helper.make_node(\n 'SequenceInsert',\n inputs=['sequence', 'tensor'],\n outputs=['output_sequence']\n )\n inserted = sequence_insert_reference_implementation(sequence, tensor)\n expect(node, inputs=[sequence, tensor], outputs=[inserted],\n name='test_sequence_insert_' + test_name)" + } + ] + }, + { + "name": "SequenceLength", + "module": "ai.onnx", + "version": 11, + "support_level": "common", + "description": "Produces a scalar(tensor of empty shape) containing the number of tensors in 'input_sequence'.\n", + "inputs": [ + { + "name": "input_sequence", + "type": "S", + "description": "Input sequence." + } + ], + "min_input": 1, + "max_input": 1, + "outputs": [ + { + "name": "length", + "type": "I", + "description": "Length of input sequence. It must be a scalar(tensor of empty shape)." + } + ], + "min_output": 1, + "max_output": 1, + "type_constraints": [ + { + "description": "Constrain to any tensor type.", + "type_param_str": "S", + "allowed_type_strs": [ + "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))" + ] + }, + { + "description": "Constrain output to integral tensor. It must be a scalar(tensor of empty shape).", + "type_param_str": "I", + "allowed_type_strs": [ + "tensor(int64)" + ] + } + ] + }, + { + "name": "Shape", + "module": "ai.onnx", + "version": 1, + "support_level": "common", + "description": "Takes a tensor as input and outputs an 1D int64 tensor containing the shape of the input tensor.\n", + "inputs": [ + { + "name": "data", + "type": "T", + "description": "An input tensor." + } + ], + "min_input": 1, + "max_input": 1, + "outputs": [ + { + "name": "shape", + "type": "T1", + "description": "Shape of the input tensor" + } + ], + "min_output": 1, + "max_output": 1, + "type_constraints": [ + { + "description": "Input tensor can be of arbitrary type.", + "type_param_str": "T", + "allowed_type_strs": [ + "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)" + ] + }, + { + "description": "Constrain output to int64 tensor.", + "type_param_str": "T1", + "allowed_type_strs": [ + "tensor(int64)" + ] + } + ], + "examples": [ + { + "summary": "shape", + "code": "x = np.array([\n [1, 2, 3],\n [4, 5, 6],\n]).astype(np.float32)\ntest_shape('_example', x) # preserve names of original test cases\n\nx = np.random.randn(3, 4, 5).astype(np.float32)\n\ntest_shape('', x) # preserve names of original test cases\n\ntest_shape('_start_1', x, start=1)\n\ntest_shape('_end_1', x, end=1)\n\ntest_shape('_start_negative_1', x, start=-1)\n\ntest_shape('_end_negative_1', x, end=-1)\n\ntest_shape('_start_1_end_negative_1', x, start=1, end=-1)\n\ntest_shape('_start_1_end_2', x, start=1, end=2)\n\ntest_shape('_clip_start', x, start=-10)\n\ntest_shape('_clip_end', x, end=10)" + } + ] + }, + { + "name": "Shape", + "module": "ai.onnx", + "version": 13, + "support_level": "common", + "description": "Takes a tensor as input and outputs an 1D int64 tensor containing the shape of the input tensor.\n", + "inputs": [ + { + "name": "data", + "type": "T", + "description": "An input tensor." + } + ], + "min_input": 1, + "max_input": 1, + "outputs": [ + { + "name": "shape", + "type": "T1", + "description": "Shape of the input tensor" + } + ], + "min_output": 1, + "max_output": 1, + "type_constraints": [ + { + "description": "Input tensor can be of arbitrary type.", + "type_param_str": "T", + "allowed_type_strs": [ + "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)" + ] + }, + { + "description": "Constrain output to int64 tensor.", + "type_param_str": "T1", + "allowed_type_strs": [ + "tensor(int64)" + ] + } + ], + "examples": [ + { + "summary": "shape", + "code": "x = np.array([\n [1, 2, 3],\n [4, 5, 6],\n]).astype(np.float32)\ntest_shape('_example', x) # preserve names of original test cases\n\nx = np.random.randn(3, 4, 5).astype(np.float32)\n\ntest_shape('', x) # preserve names of original test cases\n\ntest_shape('_start_1', x, start=1)\n\ntest_shape('_end_1', x, end=1)\n\ntest_shape('_start_negative_1', x, start=-1)\n\ntest_shape('_end_negative_1', x, end=-1)\n\ntest_shape('_start_1_end_negative_1', x, start=1, end=-1)\n\ntest_shape('_start_1_end_2', x, start=1, end=2)\n\ntest_shape('_clip_start', x, start=-10)\n\ntest_shape('_clip_end', x, end=10)" + } + ] + }, + { + "name": "Shape", + "module": "ai.onnx", + "version": 15, + "support_level": "common", + "description": "Takes a tensor as input and outputs an 1D int64 tensor containing the shape of the input tensor.\nOptional attributes start and end can be used to compute a slice of the input tensor's shape.\nIf start axis is omitted, the slice starts from axis 0.\nThe end axis, if specified, is exclusive (and the returned value will not include the size of that axis).\nIf the end axis is omitted, the axes upto the last one will be included.\nNegative axes indicate counting back from the last axis.\nNote that axes will be clipped to the range [0, r-1], where r is the\nrank of the input tensor if they are out-of-range (after adding r in the case of\nnegative axis). Thus, specifying any end value > r is equivalent to specifying an end\nvalue of r, and specifying any start value < -r is equivalent to specifying a start\nvalue of 0.\n\nFor example:\nInput tensor with shape: [2, 3, 4] \nNo attributes specified.\nOutput: [2, 3, 4] \n\nInput tensor with shape: [2, 3, 4] \nstart: -1\nOutput: [4] \n\nInput tensor with shape: [2, 3, 4] \nend: -1\nOutput: [2, 3]\n\nInput tensor with shape: [2, 3, 4] \nstart: 1\nend: 2\nOutput: [3] \n", + "attributes": [ + { + "name": "end", + "type": "int64", + "required": false, + "description": "(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." + }, + { + "name": "start", + "type": "int64", + "required": false, + "description": "(Optional) Starting axis for slicing the shape. Default value is 0.Negative value means counting dimensions from the back." + } + ], + "inputs": [ + { + "name": "data", + "type": "T", + "description": "An input tensor." + } + ], + "min_input": 1, + "max_input": 1, + "outputs": [ + { + "name": "shape", + "type": "T1", + "description": "Shape of the input tensor" + } + ], + "min_output": 1, + "max_output": 1, + "type_constraints": [ + { + "description": "Input tensor can be of arbitrary type.", + "type_param_str": "T", + "allowed_type_strs": [ + "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)" + ] + }, + { + "description": "Constrain output to int64 tensor.", + "type_param_str": "T1", + "allowed_type_strs": [ + "tensor(int64)" + ] + } + ], + "examples": [ + { + "summary": "shape", + "code": "x = np.array([\n [1, 2, 3],\n [4, 5, 6],\n]).astype(np.float32)\ntest_shape('_example', x) # preserve names of original test cases\n\nx = np.random.randn(3, 4, 5).astype(np.float32)\n\ntest_shape('', x) # preserve names of original test cases\n\ntest_shape('_start_1', x, start=1)\n\ntest_shape('_end_1', x, end=1)\n\ntest_shape('_start_negative_1', x, start=-1)\n\ntest_shape('_end_negative_1', x, end=-1)\n\ntest_shape('_start_1_end_negative_1', x, start=1, end=-1)\n\ntest_shape('_start_1_end_2', x, start=1, end=2)\n\ntest_shape('_clip_start', x, start=-10)\n\ntest_shape('_clip_end', x, end=10)" + } + ] + }, + { + "name": "Shrink", + "module": "ai.onnx", + "version": 9, + "support_level": "common", + "description": "Shrink takes one input data (Tensor) and produces one Tensor output,\nhaving same datatype and shape with input. It has two attributes, lambd and\nbias. The formula of this operator is: If x < -lambd, y = x + bias;\nIf x > lambd, y = x - bias; Otherwise, y = 0.\n", + "attributes": [ + { + "name": "bias", + "type": "float32", + "required": false, + "description": "The bias value added to output. Default is 0." + }, + { + "name": "lambd", + "type": "float32", + "required": false, + "default": 0.5, + "description": "The lambd value for the Shrink formulation. Default is 0.5." + } + ], + "inputs": [ + { + "name": "input", + "type": "T", + "description": "The input data as Tensor." + } + ], + "min_input": 1, + "max_input": 1, + "outputs": [ + { + "name": "output", + "type": "T", + "description": "The output." + } + ], + "min_output": 1, + "max_output": 1, + "type_constraints": [ + { + "description": "Constrains input to only numeric types.", + "type_param_str": "T", + "allowed_type_strs": [ + "tensor(uint8)", + "tensor(uint16)", + "tensor(uint32)", + "tensor(uint64)", + "tensor(int8)", + "tensor(int16)", + "tensor(int32)", + "tensor(int64)", + "tensor(float16)", + "tensor(float)", + "tensor(double)" + ] + } + ], + "examples": [ + { + "summary": "hard_shrink", + "code": "node = onnx.helper.make_node(\n 'Shrink',\n inputs=['x'],\n outputs=['y'],\n lambd=1.5,\n)\nX = np.arange(-2.0, 2.1, dtype=np.float32)\nY = np.array([-2, 0, 0, 0, 2], dtype=np.float32)\nexpect(node, inputs=[X], outputs=[Y],\n name='test_shrink_hard')" + }, + { + "summary": "soft_shrink", + "code": "node = onnx.helper.make_node(\n 'Shrink',\n inputs=['x'],\n outputs=['y'],\n lambd=1.5,\n bias=1.5,\n)\nX = np.arange(-2.0, 2.1, dtype=np.float32)\nY = np.array([-0.5, 0, 0, 0, 0.5], dtype=np.float32)\nexpect(node, inputs=[X], outputs=[Y],\n name='test_shrink_soft')" + } + ] + }, + { + "name": "Sigmoid", + "module": "ai.onnx", + "version": 1, + "support_level": "common", + "description": "Sigmoid takes one input data (Tensor) and produces one output data\n(Tensor) where the sigmoid function, y = 1 / (1 + exp(-x)), is applied to the\ntensor elementwise.\n", + "attributes": [ + { + "name": "consumed_inputs", + "type": "int64[]", + "required": false, + "description": "legacy optimization attribute." + } + ], + "inputs": [ + { + "name": "X", + "type": "T", + "description": "Input tensor" + } + ], + "min_input": 1, + "max_input": 1, + "outputs": [ + { + "name": "Y", + "type": "T", + "description": "Output tensor" + } + ], + "min_output": 1, + "max_output": 1, + "type_constraints": [ + { + "description": "Constrain input and output types to float tensors.", + "type_param_str": "T", + "allowed_type_strs": [ + "tensor(float16)", + "tensor(float)", + "tensor(double)" + ] + } + ], + "examples": [ + { + "summary": "sigmoid", + "code": "node = onnx.helper.make_node(\n 'Sigmoid',\n inputs=['x'],\n outputs=['y'],\n)\n\nx = np.array([-1, 0, 1]).astype(np.float32)\ny = 1.0 / (1.0 + np.exp(np.negative(x))) # expected output [0.26894143, 0.5, 0.7310586]\nexpect(node, inputs=[x], outputs=[y],\n name='test_sigmoid_example')\n\nx = np.random.randn(3, 4, 5).astype(np.float32)\ny = 1.0 / (1.0 + np.exp(np.negative(x)))\nexpect(node, inputs=[x], outputs=[y],\n name='test_sigmoid')" + } + ], + "category": "Activation" + }, + { + "name": "Sigmoid", + "module": "ai.onnx", + "version": 6, + "support_level": "common", + "description": "Sigmoid takes one input data (Tensor) and produces one output data\n(Tensor) where the sigmoid function, y = 1 / (1 + exp(-x)), is applied to the\ntensor elementwise.\n", + "inputs": [ + { + "name": "X", + "type": "T", + "description": "Input tensor" + } + ], + "min_input": 1, + "max_input": 1, + "outputs": [ + { + "name": "Y", + "type": "T", + "description": "Output tensor" + } + ], + "min_output": 1, + "max_output": 1, + "type_constraints": [ + { + "description": "Constrain input and output types to float tensors.", + "type_param_str": "T", + "allowed_type_strs": [ + "tensor(float16)", + "tensor(float)", + "tensor(double)" + ] + } + ], + "examples": [ + { + "summary": "sigmoid", + "code": "node = onnx.helper.make_node(\n 'Sigmoid',\n inputs=['x'],\n outputs=['y'],\n)\n\nx = np.array([-1, 0, 1]).astype(np.float32)\ny = 1.0 / (1.0 + np.exp(np.negative(x))) # expected output [0.26894143, 0.5, 0.7310586]\nexpect(node, inputs=[x], outputs=[y],\n name='test_sigmoid_example')\n\nx = np.random.randn(3, 4, 5).astype(np.float32)\ny = 1.0 / (1.0 + np.exp(np.negative(x)))\nexpect(node, inputs=[x], outputs=[y],\n name='test_sigmoid')" + } + ], + "category": "Activation" + }, + { + "name": "Sigmoid", + "module": "ai.onnx", + "version": 13, + "support_level": "common", + "description": "Sigmoid takes one input data (Tensor) and produces one output data\n(Tensor) where the sigmoid function, y = 1 / (1 + exp(-x)), is applied to the\ntensor elementwise.\n", + "inputs": [ + { + "name": "X", + "type": "T", + "description": "Input tensor" + } + ], + "min_input": 1, + "max_input": 1, + "outputs": [ + { + "name": "Y", + "type": "T", + "description": "Output tensor" + } + ], + "min_output": 1, + "max_output": 1, + "type_constraints": [ + { + "description": "Constrain input and output types to float tensors.", + "type_param_str": "T", + "allowed_type_strs": [ + "tensor(float16)", + "tensor(float)", + "tensor(double)", + "tensor(bfloat16)" + ] + } + ], + "examples": [ + { + "summary": "sigmoid", + "code": "node = onnx.helper.make_node(\n 'Sigmoid',\n inputs=['x'],\n outputs=['y'],\n)\n\nx = np.array([-1, 0, 1]).astype(np.float32)\ny = 1.0 / (1.0 + np.exp(np.negative(x))) # expected output [0.26894143, 0.5, 0.7310586]\nexpect(node, inputs=[x], outputs=[y],\n name='test_sigmoid_example')\n\nx = np.random.randn(3, 4, 5).astype(np.float32)\ny = 1.0 / (1.0 + np.exp(np.negative(x)))\nexpect(node, inputs=[x], outputs=[y],\n name='test_sigmoid')" + } + ], + "category": "Activation" + }, + { + "name": "Sign", + "module": "ai.onnx", + "version": 9, + "support_level": "common", + "description": "Calculate the sign of the given input tensor element-wise.\nIf input > 0, output 1. if input < 0, output -1. if input == 0, output 0.\n", + "inputs": [ + { + "name": "input", + "type": "T", + "description": "Input tensor" + } + ], + "min_input": 1, + "max_input": 1, + "outputs": [ + { + "name": "output", + "type": "T", + "description": "The sign of the input tensor computed element-wise. It has the same shape and type of the input." + } + ], + "min_output": 1, + "max_output": 1, + "type_constraints": [ + { + "description": "Constrain input and output types to all numeric tensors.", + "type_param_str": "T", + "allowed_type_strs": [ + "tensor(uint8)", + "tensor(uint16)", + "tensor(uint32)", + "tensor(uint64)", + "tensor(int8)", + "tensor(int16)", + "tensor(int32)", + "tensor(int64)", + "tensor(float16)", + "tensor(float)", + "tensor(double)" + ] + } + ], + "examples": [ + { + "summary": "sign", + "code": "node = onnx.helper.make_node(\n 'Sign',\n inputs=['x'],\n outputs=['y'],\n)\n\nx = np.array(range(-5, 6)).astype(np.float32)\ny = np.sign(x)\nexpect(node, inputs=[x], outputs=[y],\n name='test_sign')" + } + ] + }, + { + "name": "Sign", + "module": "ai.onnx", + "version": 13, + "support_level": "common", + "description": "Calculate the sign of the given input tensor element-wise.\nIf input > 0, output 1. if input < 0, output -1. if input == 0, output 0.\n", + "inputs": [ + { + "name": "input", + "type": "T", + "description": "Input tensor" + } + ], + "min_input": 1, + "max_input": 1, + "outputs": [ + { + "name": "output", + "type": "T", + "description": "The sign of the input tensor computed element-wise. It has the same shape and type of the input." + } + ], + "min_output": 1, + "max_output": 1, + "type_constraints": [ + { + "description": "Constrain input and output types to all numeric tensors.", + "type_param_str": "T", + "allowed_type_strs": [ + "tensor(uint8)", + "tensor(uint16)", + "tensor(uint32)", + "tensor(uint64)", + "tensor(int8)", + "tensor(int16)", + "tensor(int32)", + "tensor(int64)", + "tensor(float16)", + "tensor(float)", + "tensor(double)", + "tensor(bfloat16)" + ] + } + ], + "examples": [ + { + "summary": "sign", + "code": "node = onnx.helper.make_node(\n 'Sign',\n inputs=['x'],\n outputs=['y'],\n)\n\nx = np.array(range(-5, 6)).astype(np.float32)\ny = np.sign(x)\nexpect(node, inputs=[x], outputs=[y],\n name='test_sign')" + } + ] + }, + { + "name": "Sin", + "module": "ai.onnx", + "version": 7, + "support_level": "common", + "description": "Calculates the sine of the given input tensor, element-wise.\n", + "inputs": [ + { + "name": "input", + "type": "T", + "description": "Input tensor" + } + ], + "min_input": 1, + "max_input": 1, + "outputs": [ + { + "name": "output", + "type": "T", + "description": "The sine of the input tensor computed element-wise" + } + ], + "min_output": 1, + "max_output": 1, + "type_constraints": [ + { + "description": "Constrain input and output types to float tensors.", + "type_param_str": "T", + "allowed_type_strs": [ + "tensor(float16)", + "tensor(float)", + "tensor(double)" + ] + } + ], + "examples": [ + { + "summary": "sin", + "code": "node = onnx.helper.make_node(\n 'Sin',\n inputs=['x'],\n outputs=['y'],\n)\n\nx = np.array([-1, 0, 1]).astype(np.float32)\ny = np.sin(x)\nexpect(node, inputs=[x], outputs=[y],\n name='test_sin_example')\n\nx = np.random.randn(3, 4, 5).astype(np.float32)\ny = np.sin(x)\nexpect(node, inputs=[x], outputs=[y],\n name='test_sin')" + } + ] + }, + { + "name": "Sinh", + "module": "ai.onnx", + "version": 9, + "support_level": "common", + "description": "Calculates the hyperbolic sine of the given input tensor element-wise.\n", + "inputs": [ + { + "name": "input", + "type": "T", + "description": "Input tensor" + } + ], + "min_input": 1, + "max_input": 1, + "outputs": [ + { + "name": "output", + "type": "T", + "description": "The hyperbolic sine values of the input tensor computed element-wise" + } + ], + "min_output": 1, + "max_output": 1, + "type_constraints": [ + { + "description": "Constrain input and output types to float tensors.", + "type_param_str": "T", + "allowed_type_strs": [ + "tensor(float16)", + "tensor(float)", + "tensor(double)" + ] + } + ], + "examples": [ + { + "summary": "sinh", + "code": "node = onnx.helper.make_node(\n 'Sinh',\n inputs=['x'],\n outputs=['y'],\n)\n\nx = np.array([-1, 0, 1]).astype(np.float32)\ny = np.sinh(x) # expected output [-1.17520118, 0., 1.17520118]\nexpect(node, inputs=[x], outputs=[y],\n name='test_sinh_example')\n\nx = np.random.randn(3, 4, 5).astype(np.float32)\ny = np.sinh(x)\nexpect(node, inputs=[x], outputs=[y],\n name='test_sinh')" + } + ] + }, + { + "name": "Size", + "module": "ai.onnx", + "version": 1, + "support_level": "common", + "description": "Takes a tensor as input and outputs a int64 scalar that equals to the total number of elements of the input tensor.\n", + "inputs": [ + { + "name": "data", + "type": "T", + "description": "An input tensor." + } + ], + "min_input": 1, + "max_input": 1, + "outputs": [ + { + "name": "size", + "type": "T1", + "description": "Total number of elements of the input tensor" + } + ], + "min_output": 1, + "max_output": 1, + "type_constraints": [ + { + "description": "Input tensor can be of arbitrary type.", + "type_param_str": "T", + "allowed_type_strs": [ + "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)" + ] + }, + { + "description": "Constrain output to int64 tensor, which should be a scalar though.", + "type_param_str": "T1", + "allowed_type_strs": [ + "tensor(int64)" + ] + } + ], + "examples": [ + { + "summary": "size", + "code": "node = onnx.helper.make_node(\n 'Size',\n inputs=['x'],\n outputs=['y'],\n)\n\nx = np.array([\n [1, 2, 3],\n [4, 5, 6],\n]).astype(np.float32)\ny = np.array(6).astype(np.int64)\n\nexpect(node, inputs=[x], outputs=[y],\n name='test_size_example')\n\nx = np.random.randn(3, 4, 5).astype(np.float32)\ny = np.array(x.size).astype(np.int64)\n\nexpect(node, inputs=[x], outputs=[y],\n name='test_size')" + } + ] + }, + { + "name": "Size", + "module": "ai.onnx", + "version": 13, + "support_level": "common", + "description": "Takes a tensor as input and outputs a int64 scalar that equals to the total number of elements of the input tensor.\n", + "inputs": [ + { + "name": "data", + "type": "T", + "description": "An input tensor." + } + ], + "min_input": 1, + "max_input": 1, + "outputs": [ + { + "name": "size", + "type": "T1", + "description": "Total number of elements of the input tensor" + } + ], + "min_output": 1, + "max_output": 1, + "type_constraints": [ + { + "description": "Input tensor can be of arbitrary type.", + "type_param_str": "T", + "allowed_type_strs": [ + "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)" + ] + }, + { + "description": "Constrain output to int64 tensor, which should be a scalar though.", + "type_param_str": "T1", + "allowed_type_strs": [ + "tensor(int64)" + ] + } + ], + "examples": [ + { + "summary": "size", + "code": "node = onnx.helper.make_node(\n 'Size',\n inputs=['x'],\n outputs=['y'],\n)\n\nx = np.array([\n [1, 2, 3],\n [4, 5, 6],\n]).astype(np.float32)\ny = np.array(6).astype(np.int64)\n\nexpect(node, inputs=[x], outputs=[y],\n name='test_size_example')\n\nx = np.random.randn(3, 4, 5).astype(np.float32)\ny = np.array(x.size).astype(np.int64)\n\nexpect(node, inputs=[x], outputs=[y],\n name='test_size')" + } + ] + }, + { + "name": "Slice", + "module": "ai.onnx", + "version": 1, + "support_level": "common", + "description": "Produces a slice of the input tensor along multiple axes. Similar to numpy:\nhttps://docs.scipy.org/doc/numpy/reference/arrays.indexing.html\nSlices uses `axes`, `starts` and `ends` attributes to specify the start and end\ndimension for each axis in the list of axes, it uses this information to\nslice the input `data` tensor. If a negative value is passed for any of the\nstart or end indices, it represent number of elements before the end of that\ndimension. If the value passed to start or end is larger than the `n` (the\nnumber of elements in this dimension), it represents `n`. For slicing to the\nend of a dimension with unknown size, it is recommended to pass in `INT_MAX`.\nIf `axes` are omitted, they are set to `[0, ..., ndim-1]`.\nExample 1:\n data = [\n [1, 2, 3, 4],\n [5, 6, 7, 8],\n ]\n axes = [0, 1]\n starts = [1, 0]\n ends = [2, 3]\n result = [\n [5, 6, 7],\n ]\nExample 2:\n data = [\n [1, 2, 3, 4],\n [5, 6, 7, 8],\n ]\n starts = [0, 1]\n ends = [-1, 1000]\n result = [\n [2, 3, 4],\n ]\n", + "attributes": [ + { + "name": "axes", + "type": "int64[]", + "required": false, + "description": "Axes that `starts` and `ends` apply to. It's optional. If not present, will be treated as [0, 1, ..., len(`starts`) - 1]." + }, + { + "name": "ends", + "type": "int64[]", + "required": true, + "description": "Ending indices (exclusive) of corresponding axis in axes`" + }, + { + "name": "starts", + "type": "int64[]", + "required": true, + "description": "Starting indices of corresponding axis in `axes`" + } + ], + "inputs": [ + { + "name": "data", + "type": "T", + "description": "Tensor of data to extract slices from." + } + ], + "min_input": 1, + "max_input": 1, + "outputs": [ + { + "name": "output", + "type": "T", + "description": "Sliced data tensor." + } + ], + "min_output": 1, + "max_output": 1, + "type_constraints": [ + { + "description": "Constrain input and output types to all tensor types.", + "type_param_str": "T", + "allowed_type_strs": [ + "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)" + ] + } + ], + "examples": [ + { + "summary": "slice", + "code": "node = onnx.helper.make_node(\n 'Slice',\n inputs=['x', 'starts', 'ends', 'axes', 'steps'],\n outputs=['y'],\n)\n\nx = np.random.randn(20, 10, 5).astype(np.float32)\ny = x[0:3, 0:10]\nstarts = np.array([0, 0], dtype=np.int64)\nends = np.array([3, 10], dtype=np.int64)\naxes = np.array([0, 1], dtype=np.int64)\nsteps = np.array([1, 1], dtype=np.int64)\n\nexpect(node, inputs=[x, starts, ends, axes, steps], outputs=[y],\n name='test_slice')" + }, + { + "summary": "slice_default_axes", + "code": "node = onnx.helper.make_node(\n 'Slice',\n inputs=['x', 'starts', 'ends'],\n outputs=['y'],\n)\n\nx = np.random.randn(20, 10, 5).astype(np.float32)\nstarts = np.array([0, 0, 3], dtype=np.int64)\nends = np.array([20, 10, 4], dtype=np.int64)\ny = x[:, :, 3:4]\n\nexpect(node, inputs=[x, starts, ends], outputs=[y],\n name='test_slice_default_axes')" + }, + { + "summary": "slice_default_steps", + "code": "node = onnx.helper.make_node(\n 'Slice',\n inputs=['x', 'starts', 'ends', 'axes'],\n outputs=['y'],\n)\n\nx = np.random.randn(20, 10, 5).astype(np.float32)\nstarts = np.array([0, 0, 3], dtype=np.int64)\nends = np.array([20, 10, 4], dtype=np.int64)\naxes = np.array([0, 1, 2], dtype=np.int64)\ny = x[:, :, 3:4]\n\nexpect(node, inputs=[x, starts, ends, axes], outputs=[y],\n name='test_slice_default_steps')" + }, + { + "summary": "slice_end_out_of_bounds", + "code": "node = onnx.helper.make_node(\n 'Slice',\n inputs=['x', 'starts', 'ends', 'axes', 'steps'],\n outputs=['y'],\n)\n\nx = np.random.randn(20, 10, 5).astype(np.float32)\nstarts = np.array([1], dtype=np.int64)\nends = np.array([1000], dtype=np.int64)\naxes = np.array([1], dtype=np.int64)\nsteps = np.array([1], dtype=np.int64)\ny = x[:, 1:1000]\n\nexpect(node, inputs=[x, starts, ends, axes, steps], outputs=[y],\n name='test_slice_end_out_of_bounds')" + }, + { + "summary": "slice_neg", + "code": "node = onnx.helper.make_node(\n 'Slice',\n inputs=['x', 'starts', 'ends', 'axes', 'steps'],\n outputs=['y'],\n)\n\nx = np.random.randn(20, 10, 5).astype(np.float32)\nstarts = np.array([0], dtype=np.int64)\nends = np.array([-1], dtype=np.int64)\naxes = np.array([1], dtype=np.int64)\nsteps = np.array([1], dtype=np.int64)\ny = x[:, 0:-1]\n\nexpect(node, inputs=[x, starts, ends, axes, steps], outputs=[y],\n name='test_slice_neg')" + }, + { + "summary": "slice_neg_steps", + "code": "node = onnx.helper.make_node(\n 'Slice',\n inputs=['x', 'starts', 'ends', 'axes', 'steps'],\n outputs=['y'],\n)\n\nx = np.random.randn(20, 10, 5).astype(np.float32)\nstarts = np.array([20, 10, 4], dtype=np.int64)\nends = np.array([0, 0, 1], dtype=np.int64)\naxes = np.array([0, 1, 2], dtype=np.int64)\nsteps = np.array([-1, -3, -2]).astype(np.int64)\ny = x[20:0:-1, 10:0:-3, 4:1:-2]\n\nexpect(node, inputs=[x, starts, ends, axes, steps], outputs=[y],\n name='test_slice_neg_steps')" + }, + { + "summary": "slice_negative_axes", + "code": "node = onnx.helper.make_node(\n 'Slice',\n inputs=['x', 'starts', 'ends', 'axes'],\n outputs=['y'],\n)\n\nx = np.random.randn(20, 10, 5).astype(np.float32)\nstarts = np.array([0, 0, 3], dtype=np.int64)\nends = np.array([20, 10, 4], dtype=np.int64)\naxes = np.array([0, -2, -1], dtype=np.int64)\ny = x[:, :, 3:4]\n\nexpect(node, inputs=[x, starts, ends, axes], outputs=[y],\n name='test_slice_negative_axes')" + }, + { + "summary": "slice_start_out_of_bounds", + "code": "node = onnx.helper.make_node(\n 'Slice',\n inputs=['x', 'starts', 'ends', 'axes', 'steps'],\n outputs=['y'],\n)\n\nx = np.random.randn(20, 10, 5).astype(np.float32)\nstarts = np.array([1000], dtype=np.int64)\nends = np.array([1000], dtype=np.int64)\naxes = np.array([1], dtype=np.int64)\nsteps = np.array([1], dtype=np.int64)\ny = x[:, 1000:1000]\n\nexpect(node, inputs=[x, starts, ends, axes, steps], outputs=[y],\n name='test_slice_start_out_of_bounds')" + } + ], + "category": "Tensor" + }, + { + "name": "Slice", + "module": "ai.onnx", + "version": 10, + "support_level": "common", + "description": "Produces a slice of the input tensor along multiple axes. Similar to numpy:\nhttps://docs.scipy.org/doc/numpy/reference/arrays.indexing.html\nSlices uses `starts`, `ends`, `axes` and `steps` inputs to specify the start and end\ndimension and step for each axis in the list of axes, it uses this information to\nslice the input `data` tensor. If a negative value is passed for any of the\nstart or end indices, it represent number of elements before the end of that\ndimension. If the value passed to start or end is larger than the `n` (the\nnumber of elements in this dimension), it represents `n`. For slicing to the\nend of a dimension with unknown size, it is recommended to pass in `INT_MAX`.\nIf a negative value is passed for step, it represents slicing backward.\nIf `axes` are omitted, they are set to `[0, ..., ndim-1]`.\nIf `steps` are omitted, they are set to `[1, ..., 1]` of length `len(starts)`\nExample 1:\n data = [\n [1, 2, 3, 4],\n [5, 6, 7, 8],\n ]\n axes = [0, 1]\n starts = [1, 0]\n ends = [2, 3]\n steps = [1, 2]\n result = [\n [5, 7],\n ]\nExample 2:\n data = [\n [1, 2, 3, 4],\n [5, 6, 7, 8],\n ]\n starts = [0, 1]\n ends = [-1, 1000]\n result = [\n [2, 3, 4],\n ]\n", + "inputs": [ + { + "name": "data", + "type": "T", + "description": "Tensor of data to extract slices from." + }, + { + "name": "starts", + "type": "Tind", + "description": "1-D tensor of starting indices of corresponding axis in `axes`" + }, + { + "name": "ends", + "type": "Tind", + "description": "1-D tensor of ending indices (exclusive) of corresponding axis in `axes`" + }, + { + "name": "axes", + "type": "Tind", + "option": "optional", + "description": "1-D tensor of axes that `starts` and `ends` apply to." + }, + { + "name": "steps", + "type": "Tind", + "option": "optional", + "description": "1-D tensor of slice step of corresponding axis in `axes`. Default to 1. " + } + ], + "min_input": 3, + "max_input": 5, + "outputs": [ + { + "name": "output", + "type": "T", + "description": "Sliced data tensor." + } + ], + "min_output": 1, + "max_output": 1, + "inputs_range": "3 - 5", + "type_constraints": [ + { + "description": "Constrain input and output types to all tensor types.", + "type_param_str": "T", + "allowed_type_strs": [ + "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)" + ] + }, + { + "description": "Constrain indices to integer types", + "type_param_str": "Tind", + "allowed_type_strs": [ + "tensor(int32)", + "tensor(int64)" + ] + } + ], + "examples": [ + { + "summary": "slice", + "code": "node = onnx.helper.make_node(\n 'Slice',\n inputs=['x', 'starts', 'ends', 'axes', 'steps'],\n outputs=['y'],\n)\n\nx = np.random.randn(20, 10, 5).astype(np.float32)\ny = x[0:3, 0:10]\nstarts = np.array([0, 0], dtype=np.int64)\nends = np.array([3, 10], dtype=np.int64)\naxes = np.array([0, 1], dtype=np.int64)\nsteps = np.array([1, 1], dtype=np.int64)\n\nexpect(node, inputs=[x, starts, ends, axes, steps], outputs=[y],\n name='test_slice')" + }, + { + "summary": "slice_default_axes", + "code": "node = onnx.helper.make_node(\n 'Slice',\n inputs=['x', 'starts', 'ends'],\n outputs=['y'],\n)\n\nx = np.random.randn(20, 10, 5).astype(np.float32)\nstarts = np.array([0, 0, 3], dtype=np.int64)\nends = np.array([20, 10, 4], dtype=np.int64)\ny = x[:, :, 3:4]\n\nexpect(node, inputs=[x, starts, ends], outputs=[y],\n name='test_slice_default_axes')" + }, + { + "summary": "slice_default_steps", + "code": "node = onnx.helper.make_node(\n 'Slice',\n inputs=['x', 'starts', 'ends', 'axes'],\n outputs=['y'],\n)\n\nx = np.random.randn(20, 10, 5).astype(np.float32)\nstarts = np.array([0, 0, 3], dtype=np.int64)\nends = np.array([20, 10, 4], dtype=np.int64)\naxes = np.array([0, 1, 2], dtype=np.int64)\ny = x[:, :, 3:4]\n\nexpect(node, inputs=[x, starts, ends, axes], outputs=[y],\n name='test_slice_default_steps')" + }, + { + "summary": "slice_end_out_of_bounds", + "code": "node = onnx.helper.make_node(\n 'Slice',\n inputs=['x', 'starts', 'ends', 'axes', 'steps'],\n outputs=['y'],\n)\n\nx = np.random.randn(20, 10, 5).astype(np.float32)\nstarts = np.array([1], dtype=np.int64)\nends = np.array([1000], dtype=np.int64)\naxes = np.array([1], dtype=np.int64)\nsteps = np.array([1], dtype=np.int64)\ny = x[:, 1:1000]\n\nexpect(node, inputs=[x, starts, ends, axes, steps], outputs=[y],\n name='test_slice_end_out_of_bounds')" + }, + { + "summary": "slice_neg", + "code": "node = onnx.helper.make_node(\n 'Slice',\n inputs=['x', 'starts', 'ends', 'axes', 'steps'],\n outputs=['y'],\n)\n\nx = np.random.randn(20, 10, 5).astype(np.float32)\nstarts = np.array([0], dtype=np.int64)\nends = np.array([-1], dtype=np.int64)\naxes = np.array([1], dtype=np.int64)\nsteps = np.array([1], dtype=np.int64)\ny = x[:, 0:-1]\n\nexpect(node, inputs=[x, starts, ends, axes, steps], outputs=[y],\n name='test_slice_neg')" + }, + { + "summary": "slice_neg_steps", + "code": "node = onnx.helper.make_node(\n 'Slice',\n inputs=['x', 'starts', 'ends', 'axes', 'steps'],\n outputs=['y'],\n)\n\nx = np.random.randn(20, 10, 5).astype(np.float32)\nstarts = np.array([20, 10, 4], dtype=np.int64)\nends = np.array([0, 0, 1], dtype=np.int64)\naxes = np.array([0, 1, 2], dtype=np.int64)\nsteps = np.array([-1, -3, -2]).astype(np.int64)\ny = x[20:0:-1, 10:0:-3, 4:1:-2]\n\nexpect(node, inputs=[x, starts, ends, axes, steps], outputs=[y],\n name='test_slice_neg_steps')" + }, + { + "summary": "slice_negative_axes", + "code": "node = onnx.helper.make_node(\n 'Slice',\n inputs=['x', 'starts', 'ends', 'axes'],\n outputs=['y'],\n)\n\nx = np.random.randn(20, 10, 5).astype(np.float32)\nstarts = np.array([0, 0, 3], dtype=np.int64)\nends = np.array([20, 10, 4], dtype=np.int64)\naxes = np.array([0, -2, -1], dtype=np.int64)\ny = x[:, :, 3:4]\n\nexpect(node, inputs=[x, starts, ends, axes], outputs=[y],\n name='test_slice_negative_axes')" + }, + { + "summary": "slice_start_out_of_bounds", + "code": "node = onnx.helper.make_node(\n 'Slice',\n inputs=['x', 'starts', 'ends', 'axes', 'steps'],\n outputs=['y'],\n)\n\nx = np.random.randn(20, 10, 5).astype(np.float32)\nstarts = np.array([1000], dtype=np.int64)\nends = np.array([1000], dtype=np.int64)\naxes = np.array([1], dtype=np.int64)\nsteps = np.array([1], dtype=np.int64)\ny = x[:, 1000:1000]\n\nexpect(node, inputs=[x, starts, ends, axes, steps], outputs=[y],\n name='test_slice_start_out_of_bounds')" + } + ], + "category": "Tensor" + }, + { + "name": "Slice", + "module": "ai.onnx", + "version": 11, + "support_level": "common", + "description": "Produces a slice of the input tensor along multiple axes. Similar to numpy:\nhttps://docs.scipy.org/doc/numpy/reference/arrays.indexing.html\nSlices uses `starts`, `ends`, `axes` and `steps` inputs to specify the start and end\ndimension and step for each axis in the list of axes, it uses this information to\nslice the input `data` tensor. If a negative value is passed for any of the\nstart or end indices, it represents number of elements before the end of that\ndimension. If the value passed to start or end is larger than the `n` (the\nnumber of elements in this dimension), it represents `n`. For slicing to the\nend of a dimension with unknown size, it is recommended to pass in `INT_MAX`\nwhen sclicing forward and 'INT_MIN' when slicing backward.\nIf a negative value is passed for step, it represents slicing backward.\nHowever step value cannot be 0.\nIf `axes` are omitted, they are set to `[0, ..., ndim-1]`.\nIf `steps` are omitted, they are set to `[1, ..., 1]` of length `len(starts)`\nExample 1:\n data = [\n [1, 2, 3, 4],\n [5, 6, 7, 8],\n ]\n axes = [0, 1]\n starts = [1, 0]\n ends = [2, 3]\n steps = [1, 2]\n result = [\n [5, 7],\n ]\nExample 2:\n data = [\n [1, 2, 3, 4],\n [5, 6, 7, 8],\n ]\n starts = [0, 1]\n ends = [-1, 1000]\n result = [\n [2, 3, 4],\n ]\n", + "inputs": [ + { + "name": "data", + "type": "T", + "description": "Tensor of data to extract slices from." + }, + { + "name": "starts", + "type": "Tind", + "description": "1-D tensor of starting indices of corresponding axis in `axes`" + }, + { + "name": "ends", + "type": "Tind", + "description": "1-D tensor of ending indices (exclusive) of corresponding axis in `axes`" + }, + { + "name": "axes", + "type": "Tind", + "option": "optional", + "description": "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)." + }, + { + "name": "steps", + "type": "Tind", + "option": "optional", + "description": "1-D tensor of slice step of corresponding axis in `axes`. Negative value means slicing backward. 'steps' cannot be 0. Defaults to 1." + } + ], + "min_input": 3, + "max_input": 5, + "outputs": [ + { + "name": "output", + "type": "T", + "description": "Sliced data tensor." + } + ], + "min_output": 1, + "max_output": 1, + "inputs_range": "3 - 5", + "type_constraints": [ + { + "description": "Constrain input and output types to all tensor types.", + "type_param_str": "T", + "allowed_type_strs": [ + "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)" + ] + }, + { + "description": "Constrain indices to integer types", + "type_param_str": "Tind", + "allowed_type_strs": [ + "tensor(int32)", + "tensor(int64)" + ] + } + ], + "examples": [ + { + "summary": "slice", + "code": "node = onnx.helper.make_node(\n 'Slice',\n inputs=['x', 'starts', 'ends', 'axes', 'steps'],\n outputs=['y'],\n)\n\nx = np.random.randn(20, 10, 5).astype(np.float32)\ny = x[0:3, 0:10]\nstarts = np.array([0, 0], dtype=np.int64)\nends = np.array([3, 10], dtype=np.int64)\naxes = np.array([0, 1], dtype=np.int64)\nsteps = np.array([1, 1], dtype=np.int64)\n\nexpect(node, inputs=[x, starts, ends, axes, steps], outputs=[y],\n name='test_slice')" + }, + { + "summary": "slice_default_axes", + "code": "node = onnx.helper.make_node(\n 'Slice',\n inputs=['x', 'starts', 'ends'],\n outputs=['y'],\n)\n\nx = np.random.randn(20, 10, 5).astype(np.float32)\nstarts = np.array([0, 0, 3], dtype=np.int64)\nends = np.array([20, 10, 4], dtype=np.int64)\ny = x[:, :, 3:4]\n\nexpect(node, inputs=[x, starts, ends], outputs=[y],\n name='test_slice_default_axes')" + }, + { + "summary": "slice_default_steps", + "code": "node = onnx.helper.make_node(\n 'Slice',\n inputs=['x', 'starts', 'ends', 'axes'],\n outputs=['y'],\n)\n\nx = np.random.randn(20, 10, 5).astype(np.float32)\nstarts = np.array([0, 0, 3], dtype=np.int64)\nends = np.array([20, 10, 4], dtype=np.int64)\naxes = np.array([0, 1, 2], dtype=np.int64)\ny = x[:, :, 3:4]\n\nexpect(node, inputs=[x, starts, ends, axes], outputs=[y],\n name='test_slice_default_steps')" + }, + { + "summary": "slice_end_out_of_bounds", + "code": "node = onnx.helper.make_node(\n 'Slice',\n inputs=['x', 'starts', 'ends', 'axes', 'steps'],\n outputs=['y'],\n)\n\nx = np.random.randn(20, 10, 5).astype(np.float32)\nstarts = np.array([1], dtype=np.int64)\nends = np.array([1000], dtype=np.int64)\naxes = np.array([1], dtype=np.int64)\nsteps = np.array([1], dtype=np.int64)\ny = x[:, 1:1000]\n\nexpect(node, inputs=[x, starts, ends, axes, steps], outputs=[y],\n name='test_slice_end_out_of_bounds')" + }, + { + "summary": "slice_neg", + "code": "node = onnx.helper.make_node(\n 'Slice',\n inputs=['x', 'starts', 'ends', 'axes', 'steps'],\n outputs=['y'],\n)\n\nx = np.random.randn(20, 10, 5).astype(np.float32)\nstarts = np.array([0], dtype=np.int64)\nends = np.array([-1], dtype=np.int64)\naxes = np.array([1], dtype=np.int64)\nsteps = np.array([1], dtype=np.int64)\ny = x[:, 0:-1]\n\nexpect(node, inputs=[x, starts, ends, axes, steps], outputs=[y],\n name='test_slice_neg')" + }, + { + "summary": "slice_neg_steps", + "code": "node = onnx.helper.make_node(\n 'Slice',\n inputs=['x', 'starts', 'ends', 'axes', 'steps'],\n outputs=['y'],\n)\n\nx = np.random.randn(20, 10, 5).astype(np.float32)\nstarts = np.array([20, 10, 4], dtype=np.int64)\nends = np.array([0, 0, 1], dtype=np.int64)\naxes = np.array([0, 1, 2], dtype=np.int64)\nsteps = np.array([-1, -3, -2]).astype(np.int64)\ny = x[20:0:-1, 10:0:-3, 4:1:-2]\n\nexpect(node, inputs=[x, starts, ends, axes, steps], outputs=[y],\n name='test_slice_neg_steps')" + }, + { + "summary": "slice_negative_axes", + "code": "node = onnx.helper.make_node(\n 'Slice',\n inputs=['x', 'starts', 'ends', 'axes'],\n outputs=['y'],\n)\n\nx = np.random.randn(20, 10, 5).astype(np.float32)\nstarts = np.array([0, 0, 3], dtype=np.int64)\nends = np.array([20, 10, 4], dtype=np.int64)\naxes = np.array([0, -2, -1], dtype=np.int64)\ny = x[:, :, 3:4]\n\nexpect(node, inputs=[x, starts, ends, axes], outputs=[y],\n name='test_slice_negative_axes')" + }, + { + "summary": "slice_start_out_of_bounds", + "code": "node = onnx.helper.make_node(\n 'Slice',\n inputs=['x', 'starts', 'ends', 'axes', 'steps'],\n outputs=['y'],\n)\n\nx = np.random.randn(20, 10, 5).astype(np.float32)\nstarts = np.array([1000], dtype=np.int64)\nends = np.array([1000], dtype=np.int64)\naxes = np.array([1], dtype=np.int64)\nsteps = np.array([1], dtype=np.int64)\ny = x[:, 1000:1000]\n\nexpect(node, inputs=[x, starts, ends, axes, steps], outputs=[y],\n name='test_slice_start_out_of_bounds')" + } + ], + "category": "Tensor" + }, + { + "name": "Slice", + "module": "ai.onnx", + "version": 13, + "support_level": "common", + "description": "Produces a slice of the input tensor along multiple axes. Similar to numpy:\nhttps://docs.scipy.org/doc/numpy/reference/arrays.indexing.html\nSlices uses `starts`, `ends`, `axes` and `steps` inputs to specify the start and end\ndimension and step for each axis in the list of axes, it uses this information to\nslice the input `data` tensor. If a negative value is passed for any of the\nstart or end indices, it represents number of elements before the end of that\ndimension. If the value passed to start or end is larger than the `n` (the\nnumber of elements in this dimension), it represents `n`. For slicing to the\nend of a dimension with unknown size, it is recommended to pass in `INT_MAX`\nwhen sclicing forward and 'INT_MIN' when slicing backward.\nIf a negative value is passed for step, it represents slicing backward.\nHowever step value cannot be 0.\nIf `axes` are omitted, they are set to `[0, ..., ndim-1]`.\nIf `steps` are omitted, they are set to `[1, ..., 1]` of length `len(starts)`\nExample 1:\n data = [\n [1, 2, 3, 4],\n [5, 6, 7, 8],\n ]\n axes = [0, 1]\n starts = [1, 0]\n ends = [2, 3]\n steps = [1, 2]\n result = [\n [5, 7],\n ]\nExample 2:\n data = [\n [1, 2, 3, 4],\n [5, 6, 7, 8],\n ]\n starts = [0, 1]\n ends = [-1, 1000]\n result = [\n [2, 3, 4],\n ]\n", + "inputs": [ + { + "name": "data", + "type": "T", + "description": "Tensor of data to extract slices from." + }, + { + "name": "starts", + "type": "Tind", + "description": "1-D tensor of starting indices of corresponding axis in `axes`" + }, + { + "name": "ends", + "type": "Tind", + "description": "1-D tensor of ending indices (exclusive) of corresponding axis in `axes`" + }, + { + "name": "axes", + "type": "Tind", + "option": "optional", + "description": "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)." + }, + { + "name": "steps", + "type": "Tind", + "option": "optional", + "description": "1-D tensor of slice step of corresponding axis in `axes`. Negative value means slicing backward. 'steps' cannot be 0. Defaults to 1." + } + ], + "min_input": 3, + "max_input": 5, + "outputs": [ + { + "name": "output", + "type": "T", + "description": "Sliced data tensor." + } + ], + "min_output": 1, + "max_output": 1, + "inputs_range": "3 - 5", + "type_constraints": [ + { + "description": "Constrain input and output types to all tensor types.", + "type_param_str": "T", + "allowed_type_strs": [ + "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)" + ] + }, + { + "description": "Constrain indices to integer types", + "type_param_str": "Tind", + "allowed_type_strs": [ + "tensor(int32)", + "tensor(int64)" + ] + } + ], + "examples": [ + { + "summary": "slice", + "code": "node = onnx.helper.make_node(\n 'Slice',\n inputs=['x', 'starts', 'ends', 'axes', 'steps'],\n outputs=['y'],\n)\n\nx = np.random.randn(20, 10, 5).astype(np.float32)\ny = x[0:3, 0:10]\nstarts = np.array([0, 0], dtype=np.int64)\nends = np.array([3, 10], dtype=np.int64)\naxes = np.array([0, 1], dtype=np.int64)\nsteps = np.array([1, 1], dtype=np.int64)\n\nexpect(node, inputs=[x, starts, ends, axes, steps], outputs=[y],\n name='test_slice')" + }, + { + "summary": "slice_default_axes", + "code": "node = onnx.helper.make_node(\n 'Slice',\n inputs=['x', 'starts', 'ends'],\n outputs=['y'],\n)\n\nx = np.random.randn(20, 10, 5).astype(np.float32)\nstarts = np.array([0, 0, 3], dtype=np.int64)\nends = np.array([20, 10, 4], dtype=np.int64)\ny = x[:, :, 3:4]\n\nexpect(node, inputs=[x, starts, ends], outputs=[y],\n name='test_slice_default_axes')" + }, + { + "summary": "slice_default_steps", + "code": "node = onnx.helper.make_node(\n 'Slice',\n inputs=['x', 'starts', 'ends', 'axes'],\n outputs=['y'],\n)\n\nx = np.random.randn(20, 10, 5).astype(np.float32)\nstarts = np.array([0, 0, 3], dtype=np.int64)\nends = np.array([20, 10, 4], dtype=np.int64)\naxes = np.array([0, 1, 2], dtype=np.int64)\ny = x[:, :, 3:4]\n\nexpect(node, inputs=[x, starts, ends, axes], outputs=[y],\n name='test_slice_default_steps')" + }, + { + "summary": "slice_end_out_of_bounds", + "code": "node = onnx.helper.make_node(\n 'Slice',\n inputs=['x', 'starts', 'ends', 'axes', 'steps'],\n outputs=['y'],\n)\n\nx = np.random.randn(20, 10, 5).astype(np.float32)\nstarts = np.array([1], dtype=np.int64)\nends = np.array([1000], dtype=np.int64)\naxes = np.array([1], dtype=np.int64)\nsteps = np.array([1], dtype=np.int64)\ny = x[:, 1:1000]\n\nexpect(node, inputs=[x, starts, ends, axes, steps], outputs=[y],\n name='test_slice_end_out_of_bounds')" + }, + { + "summary": "slice_neg", + "code": "node = onnx.helper.make_node(\n 'Slice',\n inputs=['x', 'starts', 'ends', 'axes', 'steps'],\n outputs=['y'],\n)\n\nx = np.random.randn(20, 10, 5).astype(np.float32)\nstarts = np.array([0], dtype=np.int64)\nends = np.array([-1], dtype=np.int64)\naxes = np.array([1], dtype=np.int64)\nsteps = np.array([1], dtype=np.int64)\ny = x[:, 0:-1]\n\nexpect(node, inputs=[x, starts, ends, axes, steps], outputs=[y],\n name='test_slice_neg')" + }, + { + "summary": "slice_neg_steps", + "code": "node = onnx.helper.make_node(\n 'Slice',\n inputs=['x', 'starts', 'ends', 'axes', 'steps'],\n outputs=['y'],\n)\n\nx = np.random.randn(20, 10, 5).astype(np.float32)\nstarts = np.array([20, 10, 4], dtype=np.int64)\nends = np.array([0, 0, 1], dtype=np.int64)\naxes = np.array([0, 1, 2], dtype=np.int64)\nsteps = np.array([-1, -3, -2]).astype(np.int64)\ny = x[20:0:-1, 10:0:-3, 4:1:-2]\n\nexpect(node, inputs=[x, starts, ends, axes, steps], outputs=[y],\n name='test_slice_neg_steps')" + }, + { + "summary": "slice_negative_axes", + "code": "node = onnx.helper.make_node(\n 'Slice',\n inputs=['x', 'starts', 'ends', 'axes'],\n outputs=['y'],\n)\n\nx = np.random.randn(20, 10, 5).astype(np.float32)\nstarts = np.array([0, 0, 3], dtype=np.int64)\nends = np.array([20, 10, 4], dtype=np.int64)\naxes = np.array([0, -2, -1], dtype=np.int64)\ny = x[:, :, 3:4]\n\nexpect(node, inputs=[x, starts, ends, axes], outputs=[y],\n name='test_slice_negative_axes')" + }, + { + "summary": "slice_start_out_of_bounds", + "code": "node = onnx.helper.make_node(\n 'Slice',\n inputs=['x', 'starts', 'ends', 'axes', 'steps'],\n outputs=['y'],\n)\n\nx = np.random.randn(20, 10, 5).astype(np.float32)\nstarts = np.array([1000], dtype=np.int64)\nends = np.array([1000], dtype=np.int64)\naxes = np.array([1], dtype=np.int64)\nsteps = np.array([1], dtype=np.int64)\ny = x[:, 1000:1000]\n\nexpect(node, inputs=[x, starts, ends, axes, steps], outputs=[y],\n name='test_slice_start_out_of_bounds')" + } + ], + "category": "Tensor" + }, + { + "name": "Softmax", + "module": "ai.onnx", + "version": 1, + "support_level": "common", + "description": "The operator computes the softmax (normalized exponential) values for each layer in the batch\n of the given input. The input is a 2-D tensor (Tensor) of size\n(batch_size x input_feature_dimensions). The output tensor has the same shape\nand contains the softmax values of the corresponding input.\n\nInput does not need to explicitly be a 2D vector; rather, it will be\ncoerced into one. For an arbitrary n-dimensional tensor\ninput \\in [a_0, a_1, ..., a_{k-1}, a_k, ..., a_{n-1}] and k is\nthe axis provided, then input will be coerced into a 2-dimensional tensor with\ndimensions [a_0 * ... * a_{k-1}, a_k * ... * a_{n-1}]. For the default\ncase where axis=1, this means the input tensor will be coerced into a 2D tensor\nof dimensions [a_0, a_1 * ... * a_{n-1}], where a_0 is often the batch size.\nIn this situation, we must have a_0 = N and a_1 * ... * a_{n-1} = D.\nEach of these dimensions must be matched correctly, or else the operator\nwill throw errors.\n", + "attributes": [ + { + "name": "axis", + "type": "int64", + "required": false, + "default": 1, + "description": "Describes the axis of the inputs when coerced to 2D; defaults to one because the 0th axis most likely describes the batch_size" + } + ], + "inputs": [ + { + "name": "input", + "type": "T", + "description": "The input tensor that's coerced into a 2D matrix of size (NxD) as described above." + } + ], + "min_input": 1, + "max_input": 1, + "outputs": [ + { + "name": "output", + "type": "T", + "description": "The output values with the same shape as input tensor (the original size without coercion)." + } + ], + "min_output": 1, + "max_output": 1, + "type_constraints": [ + { + "description": "Constrain input and output types to float tensors.", + "type_param_str": "T", + "allowed_type_strs": [ + "tensor(float16)", + "tensor(float)", + "tensor(double)" + ] + } + ], + "examples": [ + { + "summary": "softmax", + "code": "node = onnx.helper.make_node(\n 'Softmax',\n inputs=['x'],\n outputs=['y'],\n)\nx = np.array([[-1, 0, 1]]).astype(np.float32)\n# expected output [[0.09003058, 0.24472848, 0.66524094]]\ny = softmax(x, axis=1)\nexpect(node, inputs=[x], outputs=[y],\n name='test_softmax_example')" + }, + { + "summary": "softmax_axis", + "code": "x = np.array([[0, 1, 2, 3], [10000, 10001, 10002, 10003]]\n ).astype(np.float32)\n# expected output\n# [[0.032058604 0.08714432 0.23688284 0.6439143 ]\n# [0.032058604 0.08714432 0.23688284 0.6439143 ]]\ny = softmax(x)\n\nnode = onnx.helper.make_node(\n 'Softmax',\n inputs=['x'],\n outputs=['y'],\n)\nexpect(node, inputs=[x], outputs=[y],\n name='test_softmax_large_number')\n\nx = np.abs(np.random.randn(3, 4, 5).astype(np.float32))\nnode = onnx.helper.make_node(\n 'Softmax',\n inputs=['x'],\n outputs=['y'],\n axis=0,\n)\ny = softmax(x, axis=0)\nexpect(node, inputs=[x], outputs=[y],\n name='test_softmax_axis_0')\n\nnode = onnx.helper.make_node(\n 'Softmax',\n inputs=['x'],\n outputs=['y'],\n axis=1,\n)\ny = softmax(x, axis=1)\nexpect(node, inputs=[x], outputs=[y],\n name='test_softmax_axis_1')\n\nnode = onnx.helper.make_node(\n 'Softmax',\n inputs=['x'],\n outputs=['y'],\n axis=2,\n)\ny = softmax(x, axis=2)\nexpect(node, inputs=[x], outputs=[y],\n name='test_softmax_axis_2')\n\nnode = onnx.helper.make_node(\n 'Softmax',\n inputs=['x'],\n outputs=['y'],\n axis=-1,\n)\ny = softmax(x, axis=-1)\nexpect(node, inputs=[x], outputs=[y],\n name='test_softmax_negative_axis')\n\n# default axis is -1\nnode = onnx.helper.make_node(\n 'Softmax',\n inputs=['x'],\n outputs=['y'],\n)\nexpect(node, inputs=[x], outputs=[y],\n name='test_softmax_default_axis')" + } + ], + "category": "Activation" + }, + { + "name": "Softmax", + "module": "ai.onnx", + "version": 11, + "support_level": "common", + "description": "The operator computes the softmax (normalized exponential) values for each layer in the batch\n of the given input.\n\nThe input does not need to explicitly be a 2D vector; rather, it will be\ncoerced into one. For an arbitrary n-dimensional tensor\ninput \\in [a_0, a_1, ..., a_{k-1}, a_k, ..., a_{n-1}] and k is\nthe axis provided, then input will be coerced into a 2-dimensional tensor with\ndimensions [a_0 * ... * a_{k-1}, a_k * ... * a_{n-1}]. For the default\ncase where axis=1, this means the input tensor will be coerced into a 2D tensor\nof dimensions [a_0, a_1 * ... * a_{n-1}], where a_0 is often the batch size.\nIn this situation, we must have a_0 = N and a_1 * ... * a_{n-1} = D.\nEach of these dimensions must be matched correctly, or else the operator\nwill throw errors. The output tensor has the same shape\nand contains the softmax values of the corresponding input.\n", + "attributes": [ + { + "name": "axis", + "type": "int64", + "required": false, + "default": 1, + "description": "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": [ + { + "name": "input", + "type": "T", + "description": "The input tensor that's coerced into a 2D matrix of size (NxD) as described above." + } + ], + "min_input": 1, + "max_input": 1, + "outputs": [ + { + "name": "output", + "type": "T", + "description": "The output values with the same shape as input tensor (the original size without coercion)." + } + ], + "min_output": 1, + "max_output": 1, + "type_constraints": [ + { + "description": "Constrain input and output types to float tensors.", + "type_param_str": "T", + "allowed_type_strs": [ + "tensor(float16)", + "tensor(float)", + "tensor(double)" + ] + } + ], + "examples": [ + { + "summary": "softmax", + "code": "node = onnx.helper.make_node(\n 'Softmax',\n inputs=['x'],\n outputs=['y'],\n)\nx = np.array([[-1, 0, 1]]).astype(np.float32)\n# expected output [[0.09003058, 0.24472848, 0.66524094]]\ny = softmax(x, axis=1)\nexpect(node, inputs=[x], outputs=[y],\n name='test_softmax_example')" + }, + { + "summary": "softmax_axis", + "code": "x = np.array([[0, 1, 2, 3], [10000, 10001, 10002, 10003]]\n ).astype(np.float32)\n# expected output\n# [[0.032058604 0.08714432 0.23688284 0.6439143 ]\n# [0.032058604 0.08714432 0.23688284 0.6439143 ]]\ny = softmax(x)\n\nnode = onnx.helper.make_node(\n 'Softmax',\n inputs=['x'],\n outputs=['y'],\n)\nexpect(node, inputs=[x], outputs=[y],\n name='test_softmax_large_number')\n\nx = np.abs(np.random.randn(3, 4, 5).astype(np.float32))\nnode = onnx.helper.make_node(\n 'Softmax',\n inputs=['x'],\n outputs=['y'],\n axis=0,\n)\ny = softmax(x, axis=0)\nexpect(node, inputs=[x], outputs=[y],\n name='test_softmax_axis_0')\n\nnode = onnx.helper.make_node(\n 'Softmax',\n inputs=['x'],\n outputs=['y'],\n axis=1,\n)\ny = softmax(x, axis=1)\nexpect(node, inputs=[x], outputs=[y],\n name='test_softmax_axis_1')\n\nnode = onnx.helper.make_node(\n 'Softmax',\n inputs=['x'],\n outputs=['y'],\n axis=2,\n)\ny = softmax(x, axis=2)\nexpect(node, inputs=[x], outputs=[y],\n name='test_softmax_axis_2')\n\nnode = onnx.helper.make_node(\n 'Softmax',\n inputs=['x'],\n outputs=['y'],\n axis=-1,\n)\ny = softmax(x, axis=-1)\nexpect(node, inputs=[x], outputs=[y],\n name='test_softmax_negative_axis')\n\n# default axis is -1\nnode = onnx.helper.make_node(\n 'Softmax',\n inputs=['x'],\n outputs=['y'],\n)\nexpect(node, inputs=[x], outputs=[y],\n name='test_softmax_default_axis')" + } + ], + "category": "Activation" + }, + { + "name": "Softmax", + "module": "ai.onnx", + "version": 13, + "support_level": "common", + "description": "The operator computes the normalized exponential values for the given input:\n\n Softmax(input, axis) = Exp(input) / ReduceSum(Exp(input), axis=axis, keepdims=1) \n\nThe \"axis\" attribute indicates the dimension along which Softmax\nwill be performed. The output tensor has the same shape\nand contains the Softmax values of the corresponding input.\n", + "attributes": [ + { + "name": "axis", + "type": "int64", + "required": false, + "default": -1, + "description": "\nDescribes the dimension Softmax will be performed on.\nNegative value means counting dimensions\nfrom the back. Accepted range is [-r, r-1] where r = rank(input).\n" + } + ], + "inputs": [ + { + "name": "input", + "type": "T", + "description": "The input tensor of rank >= axis." + } + ], + "min_input": 1, + "max_input": 1, + "outputs": [ + { + "name": "output", + "type": "T", + "description": "The output values with the same shape as the input tensor." + } + ], + "min_output": 1, + "max_output": 1, + "type_constraints": [ + { + "description": "Constrain input and output types to float tensors.", + "type_param_str": "T", + "allowed_type_strs": [ + "tensor(float16)", + "tensor(float)", + "tensor(double)", + "tensor(bfloat16)" + ] + } + ], + "examples": [ + { + "summary": "softmax", + "code": "node = onnx.helper.make_node(\n 'Softmax',\n inputs=['x'],\n outputs=['y'],\n)\nx = np.array([[-1, 0, 1]]).astype(np.float32)\n# expected output [[0.09003058, 0.24472848, 0.66524094]]\ny = softmax(x, axis=1)\nexpect(node, inputs=[x], outputs=[y],\n name='test_softmax_example')" + }, + { + "summary": "softmax_axis", + "code": "x = np.array([[0, 1, 2, 3], [10000, 10001, 10002, 10003]]\n ).astype(np.float32)\n# expected output\n# [[0.032058604 0.08714432 0.23688284 0.6439143 ]\n# [0.032058604 0.08714432 0.23688284 0.6439143 ]]\ny = softmax(x)\n\nnode = onnx.helper.make_node(\n 'Softmax',\n inputs=['x'],\n outputs=['y'],\n)\nexpect(node, inputs=[x], outputs=[y],\n name='test_softmax_large_number')\n\nx = np.abs(np.random.randn(3, 4, 5).astype(np.float32))\nnode = onnx.helper.make_node(\n 'Softmax',\n inputs=['x'],\n outputs=['y'],\n axis=0,\n)\ny = softmax(x, axis=0)\nexpect(node, inputs=[x], outputs=[y],\n name='test_softmax_axis_0')\n\nnode = onnx.helper.make_node(\n 'Softmax',\n inputs=['x'],\n outputs=['y'],\n axis=1,\n)\ny = softmax(x, axis=1)\nexpect(node, inputs=[x], outputs=[y],\n name='test_softmax_axis_1')\n\nnode = onnx.helper.make_node(\n 'Softmax',\n inputs=['x'],\n outputs=['y'],\n axis=2,\n)\ny = softmax(x, axis=2)\nexpect(node, inputs=[x], outputs=[y],\n name='test_softmax_axis_2')\n\nnode = onnx.helper.make_node(\n 'Softmax',\n inputs=['x'],\n outputs=['y'],\n axis=-1,\n)\ny = softmax(x, axis=-1)\nexpect(node, inputs=[x], outputs=[y],\n name='test_softmax_negative_axis')\n\n# default axis is -1\nnode = onnx.helper.make_node(\n 'Softmax',\n inputs=['x'],\n outputs=['y'],\n)\nexpect(node, inputs=[x], outputs=[y],\n name='test_softmax_default_axis')" + } + ], + "category": "Activation" + }, + { + "name": "SoftmaxCrossEntropyLoss", + "module": "ai.onnx", + "version": 12, + "support_level": "common", + "description": "Loss function that measures the softmax cross entropy\nbetween 'scores' and 'labels'.\nThis operator first computes a loss tensor whose shape is identical to the labels input.\nIf 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).\nIf the input is N-D tensor with shape (N, C, D1, D2, ..., Dk),\nthe 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.\nAfter L is available, this operator can optionally do a reduction operator.\n\nshape(scores): (N, C) where C is the number of classes, or (N, C, D1, D2,..., Dk),\n with K >= 1 in case of K-dimensional loss.\nshape(labels): (N) where each value is 0 <= labels[i] <= C-1, or (N, D1, D2,..., Dk),\n with K >= 1 in case of K-dimensional loss.\n\nThe loss for one sample, l_i, can caculated as follows:\n l[i][d1][d2]...[dk] = -y[i][c][d1][d2]..[dk], where i is the index of classes.\nor\n l[i][d1][d2]...[dk] = -y[i][c][d1][d2]..[dk] * weights[c], if 'weights' is provided.\n\nloss is zero for the case when label-value equals ignore_index.\n l[i][d1][d2]...[dk] = 0, when labels[n][d1][d2]...[dk] = ignore_index\n\nwhere:\n p = Softmax(scores)\n y = Log(p)\n c = labels[i][d1][d2]...[dk]\n\nFinally, L is optionally reduced:\nIf reduction = 'none', the output is L with shape (N, D1, D2, ..., Dk).\nIf reduction = 'sum', the output is scalar: Sum(L).\nIf reduction = 'mean', the output is scalar: ReduceMean(L), or if weight is provided: ReduceSum(L) / ReduceSum(W),\nwhere tensor W is of shape (N, D1, D2, ..., Dk) and W[n][d1][d2]...[dk] = weights[labels[i][d1][d2]...[dk]].\n", + "attributes": [ + { + "name": "ignore_index", + "type": "int64", + "required": false, + "description": "Specifies a target value that is ignored and does not contribute to the input gradient. It's an optional value." + }, + { + "name": "reduction", + "type": "string", + "required": false, + "default": "mean", + "description": "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": [ + { + "name": "scores", + "type": "T", + "description": "The predicted outputs with shape [batch_size, class_size], or [batch_size, class_size, D1, D2 , ..., Dk], where K is the number of dimensions." + }, + { + "name": "labels", + "type": "Tind", + "description": "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." + }, + { + "name": "weights", + "type": "T", + "option": "optional", + "description": "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." + } + ], + "min_input": 2, + "max_input": 3, + "outputs": [ + { + "name": "output", + "type": "T", + "description": "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." + }, + { + "name": "log_prob", + "type": "T", + "option": "optional", + "description": "Log probability tensor. If the output of softmax is prob, its value is log(prob)." + } + ], + "min_output": 1, + "max_output": 2, + "inputs_range": "2 - 3", + "outputs_range": "1 - 2", + "type_constraints": [ + { + "description": "Constrain input and output types to float tensors.", + "type_param_str": "T", + "allowed_type_strs": [ + "tensor(float16)", + "tensor(float)", + "tensor(double)" + ] + }, + { + "description": "Constrain target to integer types", + "type_param_str": "Tind", + "allowed_type_strs": [ + "tensor(int32)", + "tensor(int64)" + ] + } + ], + "examples": [ + { + "summary": "input_shape_is_NCd1_mean_weight_negative_ii", + "code": "reduction = 'mean'\nignore_index = np.int64(-1)\n\nnode = onnx.helper.make_node('SoftmaxCrossEntropyLoss',\n inputs=['x', 'y', 'w'],\n outputs=['z'],\n reduction=reduction,\n ignore_index=ignore_index)\n\nN, C, dim1 = 3, 5, 6\nnp.random.seed(0)\nx = np.random.rand(N, C, dim1).astype(np.float32)\nlabels = np.random.randint(0, high=C, size=(N, dim1)).astype(np.int64)\nlabels[0][0] = -1\nweight = np.random.rand(C).astype(np.float32)\n\nsce = softmaxcrossentropy(x,\n labels,\n weight=weight,\n reduction=reduction,\n ignore_index=ignore_index)\n\nexpect(node, inputs=[x, labels, weight], outputs=[sce], name='test_sce_NCd1_mean_weight_negative_ii')" + }, + { + "summary": "input_shape_is_NCd1_mean_weight_negative_ii_log_prob", + "code": "reduction = 'mean'\nignore_index = np.int64(-1)\n\nnode = onnx.helper.make_node('SoftmaxCrossEntropyLoss',\n inputs=['x', 'y', 'w'],\n outputs=['z', 'log_prob'],\n reduction=reduction,\n ignore_index=ignore_index)\n\nN, C, dim1 = 3, 5, 6\nnp.random.seed(0)\nx = np.random.rand(N, C, dim1).astype(np.float32)\nlabels = np.random.randint(0, high=C, size=(N, dim1)).astype(np.int64)\nlabels[0][0] = -1\nweight = np.random.rand(C).astype(np.float32)\n\nloss, log_prob = softmaxcrossentropy(x,\n labels,\n weight=weight,\n reduction=reduction,\n ignore_index=ignore_index,\n get_log_prob=True)\n\nexpect(node, inputs=[x, labels, weight], outputs=[loss, log_prob], name='test_sce_NCd1_mean_weight_negative_ii_log_prob')" + }, + { + "summary": "input_shape_is_NCd1d2d3_none_no_weight_negative_ii", + "code": "reduction = 'none'\nignore_index = np.int64(-5)\n\nnode = onnx.helper.make_node('SoftmaxCrossEntropyLoss',\n inputs=['x', 'y'],\n outputs=['z'],\n reduction=reduction,\n ignore_index=ignore_index)\n\nN, C, dim1, dim2, dim3 = 3, 5, 6, 6, 5\nnp.random.seed(0)\nx = np.random.rand(N, C, dim1, dim2, dim3).astype(np.float32)\nlabels = np.random.randint(0, high=C, size=(N, dim1, dim2, dim3)).astype(np.int64)\nlabels[0][0][0][0] = -5\n\nsce = softmaxcrossentropy(x,\n labels,\n reduction=reduction,\n ignore_index=ignore_index)\n\nexpect(node, inputs=[x, labels], outputs=[sce], name='test_sce_NCd1d2d3_none_no_weight_negative_ii')" + }, + { + "summary": "input_shape_is_NCd1d2d3_none_no_weight_negative_ii_log_prob", + "code": "reduction = 'none'\nignore_index = np.int64(-5)\n\nnode = onnx.helper.make_node('SoftmaxCrossEntropyLoss',\n inputs=['x', 'y'],\n outputs=['z', 'log_prob'],\n reduction=reduction,\n ignore_index=ignore_index)\n\nN, C, dim1, dim2, dim3 = 3, 5, 6, 6, 5\nnp.random.seed(0)\nx = np.random.rand(N, C, dim1, dim2, dim3).astype(np.float32)\nlabels = np.random.randint(0, high=C, size=(N, dim1, dim2, dim3)).astype(np.int64)\nlabels[0][0][0][0] = -5\n\nloss, log_prob = softmaxcrossentropy(x,\n labels,\n reduction=reduction,\n ignore_index=ignore_index,\n get_log_prob=True)\n\nexpect(node, inputs=[x, labels], outputs=[loss, log_prob], name='test_sce_NCd1d2d3_none_no_weight_negative_ii_log_prob')" + }, + { + "summary": "input_shape_is_NCd1d2d3_sum_weight_high_ii", + "code": "reduction = 'sum'\nignore_index = np.int64(10)\n\nnode = onnx.helper.make_node('SoftmaxCrossEntropyLoss',\n inputs=['x', 'y', 'w'],\n outputs=['z'],\n reduction=reduction,\n ignore_index=ignore_index)\n\nN, C = 3, 5\nnp.random.seed(0)\nx = np.random.rand(N, C).astype(np.float32)\nlabels = np.random.randint(0, high=C, size=(N)).astype(np.int64)\nlabels[0] = 10\nweight = np.random.rand(C).astype(np.float32)\n\nsce = softmaxcrossentropy(x,\n labels,\n weight=weight,\n reduction=reduction,\n ignore_index=ignore_index)\n\nexpect(node, inputs=[x, labels, weight], outputs=[sce], name='test_sce_NCd1d2d3_sum_weight_high_ii')" + }, + { + "summary": "input_shape_is_NCd1d2d3_sum_weight_high_ii_log_prob", + "code": "reduction = 'sum'\nignore_index = np.int64(10)\n\nnode = onnx.helper.make_node('SoftmaxCrossEntropyLoss',\n inputs=['x', 'y', 'w'],\n outputs=['z', 'log_prob'],\n reduction=reduction,\n ignore_index=ignore_index)\n\nN, C = 3, 5\nnp.random.seed(0)\nx = np.random.rand(N, C).astype(np.float32)\nlabels = np.random.randint(0, high=C, size=(N)).astype(np.int64)\nlabels[0] = 10\nweight = np.random.rand(C).astype(np.float32)\n\nloss, log_prob = softmaxcrossentropy(x,\n labels,\n weight=weight,\n reduction=reduction,\n ignore_index=ignore_index,\n get_log_prob=True)\n\nexpect(node, inputs=[x, labels, weight], outputs=[loss, log_prob], name='test_sce_NCd1d2d3_sum_weight_high_ii_log_prob')" + }, + { + "summary": "input_shape_is_NCd1d2d3d4d5_mean_weight", + "code": "reduction = 'mean'\n\nnode = onnx.helper.make_node('SoftmaxCrossEntropyLoss',\n inputs=['x', 'y', 'w'],\n outputs=['z'],\n reduction=reduction)\n\nN, C, dim1, dim2, dim3, dim4, dim5 = 3, 5, 6, 6, 5, 3, 4\nnp.random.seed(0)\nx = np.random.rand(N, C, dim1, dim2, dim3, dim4, dim5).astype(np.float32)\nlabels = np.random.randint(0, high=C, size=(N, dim1, dim2, dim3, dim4, dim5)).astype(np.int64)\nweight = np.random.rand(C).astype(np.float32)\n\nsce = softmaxcrossentropy(x,\n labels,\n weight=weight,\n reduction=reduction)\n\nexpect(node, inputs=[x, labels, weight], outputs=[sce], name='test_sce_NCd1d2d3d4d5_mean_weight')" + }, + { + "summary": "input_shape_is_NCd1d2d3d4d5_mean_weight_log_prob", + "code": "reduction = 'mean'\n\nnode = onnx.helper.make_node('SoftmaxCrossEntropyLoss',\n inputs=['x', 'y', 'w'],\n outputs=['z', 'log_prob'],\n reduction=reduction)\n\nN, C, dim1, dim2, dim3, dim4, dim5 = 3, 5, 6, 6, 5, 3, 4\nnp.random.seed(0)\nx = np.random.rand(N, C, dim1, dim2, dim3, dim4, dim5).astype(np.float32)\nlabels = np.random.randint(0, high=C, size=(N, dim1, dim2, dim3, dim4, dim5)).astype(np.int64)\nweight = np.random.rand(C).astype(np.float32)\n\nloss, log_prob = softmaxcrossentropy(x,\n labels,\n weight=weight,\n reduction=reduction,\n get_log_prob=True)\n\nexpect(node, inputs=[x, labels, weight], outputs=[loss, log_prob], name='test_sce_NCd1d2d3d4d5_mean_weight_log_prob')" + }, + { + "summary": "input_shape_is_NCd1d2d3d4d5_none_no_weight", + "code": "reduction = 'none'\n\nnode = onnx.helper.make_node('SoftmaxCrossEntropyLoss',\n inputs=['x', 'y'],\n outputs=['z'],\n reduction=reduction)\n\nN, C, dim1, dim2, dim3, dim4, dim5 = 3, 5, 6, 6, 5, 3, 4\nnp.random.seed(0)\nx = np.random.rand(N, C, dim1, dim2, dim3, dim4, dim5).astype(np.float32)\nlabels = np.random.randint(0, high=C, size=(N, dim1, dim2, dim3, dim4, dim5)).astype(np.int64)\n\nsce = softmaxcrossentropy(x,\n labels,\n reduction=reduction)\n\nexpect(node, inputs=[x, labels], outputs=[sce], name='test_sce_NCd1d2d3d4d5_none_no_weight')" + }, + { + "summary": "input_shape_is_NCd1d2d3d4d5_none_no_weight_log_prob", + "code": "reduction = 'none'\n\nnode = onnx.helper.make_node('SoftmaxCrossEntropyLoss',\n inputs=['x', 'y'],\n outputs=['z', 'log_prob'],\n reduction=reduction)\n\nN, C, dim1, dim2, dim3, dim4, dim5 = 3, 5, 6, 6, 5, 3, 4\nnp.random.seed(0)\nx = np.random.rand(N, C, dim1, dim2, dim3, dim4, dim5).astype(np.float32)\nlabels = np.random.randint(0, high=C, size=(N, dim1, dim2, dim3, dim4, dim5)).astype(np.int64)\n\nloss, log_prob = softmaxcrossentropy(x,\n labels,\n reduction=reduction,\n get_log_prob=True)\n\nexpect(node, inputs=[x, labels], outputs=[loss, log_prob], name='test_sce_NCd1d2d3d4d5_none_no_weight_log_prob')" + }, + { + "summary": "softmaxcrossentropy_mean", + "code": "# Define operator attributes.\nreduction = 'mean'\n\n# Create operator.\nnode = onnx.helper.make_node('SoftmaxCrossEntropyLoss',\n inputs=['x', 'y'],\n outputs=['z'],\n reduction=reduction)\n\n# Define operator inputs.\nnp.random.seed(0)\nx = np.random.rand(3, 5).astype(np.float32)\nlabels = np.random.randint(0, high=5, size=(3, )).astype(np.int64)\n\n# Compute SoftmaxCrossEntropyLoss\nsce = softmaxcrossentropy(x, labels)\n\n# Check results\nexpect(node, inputs=[x, labels], outputs=[sce], name='test_sce_mean')" + }, + { + "summary": "softmaxcrossentropy_mean_3d", + "code": "# Define operator attributes.\nreduction = 'mean'\n\n# Create operator.\nnode = onnx.helper.make_node('SoftmaxCrossEntropyLoss',\n inputs=['x', 'y'],\n outputs=['z'],\n reduction=reduction)\n\n# Define operator inputs.\nnp.random.seed(0)\nx = np.random.rand(3, 5, 2).astype(np.float32)\ny = np.random.randint(0, high=5, size=(3, 2)).astype(np.int64)\n\n# Compute SoftmaxCrossEntropyLoss\nsce = softmaxcrossentropy(x, y)\n\n# Check results\nexpect(node, inputs=[x, y], outputs=[sce], name='test_sce_mean_3d')" + }, + { + "summary": "softmaxcrossentropy_mean_3d_log_prob", + "code": "# Define operator attributes.\nreduction = 'mean'\n\n# Create operator.\nnode = onnx.helper.make_node('SoftmaxCrossEntropyLoss',\n inputs=['x', 'y'],\n outputs=['z', 'log_prob'],\n reduction=reduction)\n\n# Define operator inputs.\nnp.random.seed(0)\nx = np.random.rand(3, 5, 2).astype(np.float32)\ny = np.random.randint(0, high=5, size=(3, 2)).astype(np.int64)\n\n# Compute SoftmaxCrossEntropyLoss\nloss, log_prob = softmaxcrossentropy(x, y, get_log_prob=True)\n\n# Check results\nexpect(node, inputs=[x, y], outputs=[loss, log_prob], name='test_sce_mean_3d_log_prob')" + }, + { + "summary": "softmaxcrossentropy_mean_log_prob", + "code": "# Define operator attributes.\nreduction = 'mean'\n\n# Create operator.\nnode = onnx.helper.make_node('SoftmaxCrossEntropyLoss',\n inputs=['x', 'y'],\n outputs=['z', 'log_prob'],\n reduction=reduction)\n\n# Define operator inputs.\nnp.random.seed(0)\nx = np.random.rand(3, 5).astype(np.float32)\nlabels = np.random.randint(0, high=5, size=(3, )).astype(np.int64)\n\n# Compute SoftmaxCrossEntropyLoss\nloss, log_prob = softmaxcrossentropy(x, labels, get_log_prob=True)\n\n# Check results\nexpect(node, inputs=[x, labels], outputs=[loss, log_prob], name='test_sce_mean_log_prob')" + }, + { + "summary": "softmaxcrossentropy_mean_no_weights_ii", + "code": "# Define operator attributes.\nreduction = 'mean'\nignore_index = np.int64(2)\n\n# Create operator.\nnode = onnx.helper.make_node('SoftmaxCrossEntropyLoss',\n inputs=['x', 'y'],\n outputs=['z'],\n reduction=reduction,\n ignore_index=ignore_index)\n\n# Define operator inputs.\nnp.random.seed(0)\nx = np.random.rand(3, 5).astype(np.float32)\nlabels = np.random.randint(0, high=5, size=(3, )).astype(np.int64)\nlabels[0] = np.int64(2)\n\n# Compute SoftmaxCrossEntropyLoss\nsce = softmaxcrossentropy(x, labels, ignore_index=ignore_index)\n\n# Check results\nexpect(node, inputs=[x, labels], outputs=[sce], name='test_sce_mean_no_weight_ii')" + }, + { + "summary": "softmaxcrossentropy_mean_no_weights_ii_3d", + "code": "# Define operator attributes.\nreduction = 'mean'\nignore_index = np.int64(2)\n\n# Create operator.\nnode = onnx.helper.make_node('SoftmaxCrossEntropyLoss',\n inputs=['x', 'y'],\n outputs=['z'],\n reduction=reduction,\n ignore_index=ignore_index)\n\n# Define operator inputs.\nnp.random.seed(0)\nx = np.random.rand(3, 5, 2).astype(np.float32)\nlabels = np.random.randint(0, high=5, size=(3, 2)).astype(np.int64)\nlabels[0][0] = np.int64(2)\n\n# Compute SoftmaxCrossEntropyLoss\nsce = softmaxcrossentropy(x, labels, ignore_index=ignore_index)\n\n# Check results\nexpect(node, inputs=[x, labels], outputs=[sce], name='test_sce_mean_no_weight_ii_3d')" + }, + { + "summary": "softmaxcrossentropy_mean_no_weights_ii_3d_log_prob", + "code": "# Define operator attributes.\nreduction = 'mean'\nignore_index = np.int64(2)\n\n# Create operator.\nnode = onnx.helper.make_node('SoftmaxCrossEntropyLoss',\n inputs=['x', 'y'],\n outputs=['z', 'log_prob'],\n reduction=reduction,\n ignore_index=ignore_index)\n\n# Define operator inputs.\nnp.random.seed(0)\nx = np.random.rand(3, 5, 2).astype(np.float32)\nlabels = np.random.randint(0, high=5, size=(3, 2)).astype(np.int64)\nlabels[0][0] = np.int64(2)\n\n# Compute SoftmaxCrossEntropyLoss\nloss, log_prob = softmaxcrossentropy(x, labels, ignore_index=ignore_index, get_log_prob=True)\n\n# Check results\nexpect(node, inputs=[x, labels], outputs=[loss, log_prob], name='test_sce_mean_no_weight_ii_3d_log_prob')" + }, + { + "summary": "softmaxcrossentropy_mean_no_weights_ii_4d", + "code": "# Define operator attributes.\nreduction = 'mean'\nignore_index = np.int64(2)\n\n# Create operator.\nnode = onnx.helper.make_node('SoftmaxCrossEntropyLoss',\n inputs=['x', 'y'],\n outputs=['z'],\n reduction=reduction,\n ignore_index=ignore_index)\n\n# Define operator inputs.\nnp.random.seed(0)\nx = np.random.rand(3, 5, 2, 7).astype(np.float32)\nlabels = np.random.randint(0, high=5, size=(3, 2, 7)).astype(np.int64)\nlabels[0][0][0] = np.int64(2)\n\n# Compute SoftmaxCrossEntropyLoss\nsce = softmaxcrossentropy(x, labels, reduction=reduction, ignore_index=ignore_index)\n\n# Check results\nexpect(node, inputs=[x, labels], outputs=[sce], name='test_sce_mean_no_weight_ii_4d')" + }, + { + "summary": "softmaxcrossentropy_mean_no_weights_ii_4d_log_prob", + "code": "# Define operator attributes.\nreduction = 'mean'\nignore_index = np.int64(2)\n\n# Create operator.\nnode = onnx.helper.make_node('SoftmaxCrossEntropyLoss',\n inputs=['x', 'y'],\n outputs=['z', 'log_prob'],\n reduction=reduction,\n ignore_index=ignore_index)\n\n# Define operator inputs.\nnp.random.seed(0)\nx = np.random.rand(3, 5, 2, 7).astype(np.float32)\nlabels = np.random.randint(0, high=5, size=(3, 2, 7)).astype(np.int64)\nlabels[0][0][0] = np.int64(2)\n\n# Compute SoftmaxCrossEntropyLoss\nloss, log_prob = softmaxcrossentropy(x, labels, reduction=reduction, ignore_index=ignore_index, get_log_prob=True)\n\n# Check results\nexpect(node, inputs=[x, labels], outputs=[loss, log_prob], name='test_sce_mean_no_weight_ii_4d_log_prob')" + }, + { + "summary": "softmaxcrossentropy_mean_no_weights_ii_log_prob", + "code": "# Define operator attributes.\nreduction = 'mean'\nignore_index = np.int64(2)\n\n# Create operator.\nnode = onnx.helper.make_node('SoftmaxCrossEntropyLoss',\n inputs=['x', 'y'],\n outputs=['z', 'log_prob'],\n reduction=reduction,\n ignore_index=ignore_index)\n\n# Define operator inputs.\nnp.random.seed(0)\nx = np.random.rand(3, 5).astype(np.float32)\nlabels = np.random.randint(0, high=5, size=(3, )).astype(np.int64)\nlabels[0] = np.int64(2)\n\n# Compute SoftmaxCrossEntropyLoss\nloss, log_prob = softmaxcrossentropy(x, labels, ignore_index=ignore_index, get_log_prob=True)\n\n# Check results\nexpect(node, inputs=[x, labels], outputs=[loss, log_prob], name='test_sce_mean_no_weight_ii_log_prob')" + }, + { + "summary": "softmaxcrossentropy_mean_weights", + "code": "# Define operator attributes.\nreduction = 'mean'\n\n# Create operator.\nnode = onnx.helper.make_node('SoftmaxCrossEntropyLoss',\n inputs=['x', 'y', 'w'],\n outputs=['z'],\n reduction=reduction)\n\n# Define operator inputs.\nnp.random.seed(0)\nx = np.random.rand(3, 5).astype(np.float32)\nlabels = np.random.randint(0, high=5, size=(3, )).astype(np.int64)\nweights = np.array([0.9, 0.7, 0.8, 0.9, 0.9], dtype=np.float32)\n\n# Compute SoftmaxCrossEntropyLoss\nsce = softmaxcrossentropy(x, labels, weight=weights)\n\n# Check results\nexpect(node, inputs=[x, labels, weights], outputs=[sce], name='test_sce_mean_weight')" + }, + { + "summary": "softmaxcrossentropy_mean_weights_ii", + "code": "# Define operator attributes.\nreduction = 'mean'\nignore_index = np.int64(0)\n\n# Create operator.\nnode = onnx.helper.make_node('SoftmaxCrossEntropyLoss',\n inputs=['x', 'y', 'w'],\n outputs=['z'],\n reduction=reduction,\n ignore_index=ignore_index)\n\n# Define operator inputs.\nnp.random.seed(0)\nx = np.random.rand(3, 5).astype(np.float32)\nlabels = np.random.randint(0, high=5, size=(3, )).astype(np.int64)\nlabels[0] = np.int64(0)\nweights = np.array([0.9, 0.7, 0.8, 0.9, 0.9], dtype=np.float32)\n\n# Compute SoftmaxCrossEntropyLoss\nsce = softmaxcrossentropy(x, labels, weight=weights, ignore_index=ignore_index)\n\n# Check results\nexpect(node, inputs=[x, labels, weights], outputs=[sce], name='test_sce_mean_weight_ii')" + }, + { + "summary": "softmaxcrossentropy_mean_weights_ii_3d", + "code": "# Define operator attributes.\nreduction = 'mean'\nignore_index = np.int64(1)\n\n# Create operator.\nnode = onnx.helper.make_node('SoftmaxCrossEntropyLoss',\n inputs=['x', 'y', 'w'],\n outputs=['z'],\n reduction=reduction,\n ignore_index=ignore_index)\n\n# Define operator inputs.\nnp.random.seed(0)\nx = np.random.rand(3, 5, 2).astype(np.float32)\nlabels = np.random.randint(0, high=5, size=(3, 2)).astype(np.int64)\nlabels[0][0] = np.int64(1)\nweights = np.array([0.2, 0.3, 0.6, 0.1, 0.5], dtype=np.float32)\n\n# Compute SoftmaxCrossEntropyLoss\nsce = softmaxcrossentropy(x, labels, weight=weights, ignore_index=ignore_index)\n\n# Check results\nexpect(node, inputs=[x, labels, weights], outputs=[sce], name='test_sce_mean_weight_ii_3d')" + }, + { + "summary": "softmaxcrossentropy_mean_weights_ii_3d_log_prob", + "code": "# Define operator attributes.\nreduction = 'mean'\nignore_index = np.int64(1)\n\n# Create operator.\nnode = onnx.helper.make_node('SoftmaxCrossEntropyLoss',\n inputs=['x', 'y', 'w'],\n outputs=['z', 'log_prob'],\n reduction=reduction,\n ignore_index=ignore_index)\n\n# Define operator inputs.\nnp.random.seed(0)\nx = np.random.rand(3, 5, 2).astype(np.float32)\nlabels = np.random.randint(0, high=5, size=(3, 2)).astype(np.int64)\nlabels[0][0] = np.int64(1)\nweights = np.array([0.2, 0.3, 0.6, 0.1, 0.5], dtype=np.float32)\n\n# Compute SoftmaxCrossEntropyLoss\nloss, log_prob = softmaxcrossentropy(x, labels, weight=weights, ignore_index=ignore_index, get_log_prob=True)\n\n# Check results\nexpect(node, inputs=[x, labels, weights], outputs=[loss, log_prob], name='test_sce_mean_weight_ii_3d_log_prob')" + }, + { + "summary": "softmaxcrossentropy_mean_weights_ii_4d", + "code": "# Define operator attributes.\nreduction = 'mean'\nignore_index = np.int64(2)\n\n# Create operator.\nnode = onnx.helper.make_node('SoftmaxCrossEntropyLoss',\n inputs=['x', 'y', 'w'],\n outputs=['z'],\n reduction=reduction,\n ignore_index=ignore_index)\n\n# Define operator inputs.\nnp.random.seed(0)\nx = np.random.rand(3, 5, 2, 7).astype(np.float32)\nlabels = np.random.randint(0, high=5, size=(3, 2, 7)).astype(np.int64)\nlabels[0][0][0] = np.int64(2)\nweights = np.array([0.2, 0.3, 0.6, 0.1, 0.5], dtype=np.float32)\n\n# Compute SoftmaxCrossEntropyLoss\nsce = softmaxcrossentropy(x, labels, reduction=reduction, weight=weights, ignore_index=ignore_index)\n\n# Check results\nexpect(node, inputs=[x, labels, weights], outputs=[sce], name='test_sce_mean_weight_ii_4d')" + }, + { + "summary": "softmaxcrossentropy_mean_weights_ii_4d_log_prob", + "code": "# Define operator attributes.\nreduction = 'mean'\nignore_index = np.int64(2)\n\n# Create operator.\nnode = onnx.helper.make_node('SoftmaxCrossEntropyLoss',\n inputs=['x', 'y', 'w'],\n outputs=['z', 'log_prob'],\n reduction=reduction,\n ignore_index=ignore_index)\n\n# Define operator inputs.\nnp.random.seed(0)\nx = np.random.rand(3, 5, 2, 7).astype(np.float32)\nlabels = np.random.randint(0, high=5, size=(3, 2, 7)).astype(np.int64)\nlabels[0][0][0] = np.int64(2)\nweights = np.array([0.2, 0.3, 0.6, 0.1, 0.5], dtype=np.float32)\n\n# Compute SoftmaxCrossEntropyLoss\nloss, log_prob = softmaxcrossentropy(x, labels, reduction=reduction, weight=weights, ignore_index=ignore_index, get_log_prob=True)\n\n# Check results\nexpect(node, inputs=[x, labels, weights], outputs=[loss, log_prob], name='test_sce_mean_weight_ii_4d_log_prob')" + }, + { + "summary": "softmaxcrossentropy_mean_weights_ii_log_prob", + "code": "# Define operator attributes.\nreduction = 'mean'\nignore_index = np.int64(0)\n\n# Create operator.\nnode = onnx.helper.make_node('SoftmaxCrossEntropyLoss',\n inputs=['x', 'y', 'w'],\n outputs=['z', 'log_prob'],\n reduction=reduction,\n ignore_index=ignore_index)\n\n# Define operator inputs.\nnp.random.seed(0)\nx = np.random.rand(3, 5).astype(np.float32)\nlabels = np.random.randint(0, high=5, size=(3, )).astype(np.int64)\nlabels[0] = np.int64(0)\nweights = np.array([0.9, 0.7, 0.8, 0.9, 0.9], dtype=np.float32)\n\n# Compute SoftmaxCrossEntropyLoss\nloss, log_prob = softmaxcrossentropy(x, labels, weight=weights, ignore_index=ignore_index, get_log_prob=True)\n\n# Check results\nexpect(node, inputs=[x, labels, weights], outputs=[loss, log_prob], name='test_sce_mean_weight_ii_log_prob')" + }, + { + "summary": "softmaxcrossentropy_mean_weights_log_prob", + "code": "# Define operator attributes.\nreduction = 'mean'\n\n# Create operator.\nnode = onnx.helper.make_node('SoftmaxCrossEntropyLoss',\n inputs=['x', 'y', 'w'],\n outputs=['z', 'log_prob'],\n reduction=reduction)\n\n# Define operator inputs.\nnp.random.seed(0)\nx = np.random.rand(3, 5).astype(np.float32)\nlabels = np.random.randint(0, high=5, size=(3, )).astype(np.int64)\nweights = np.array([0.9, 0.7, 0.8, 0.9, 0.9], dtype=np.float32)\n\n# Compute SoftmaxCrossEntropyLoss\nloss, log_prob = softmaxcrossentropy(x, labels, weight=weights, get_log_prob=True)\n\n# Check results\nexpect(node, inputs=[x, labels, weights], outputs=[loss, log_prob], name='test_sce_mean_weight_log_prob')" + }, + { + "summary": "softmaxcrossentropy_none", + "code": "# Define operator attributes.\nreduction = 'none'\n\n# Create operator.\nnode = onnx.helper.make_node('SoftmaxCrossEntropyLoss',\n inputs=['x', 'y'],\n outputs=['z'],\n reduction=reduction)\n\n# Define operator inputs.\nnp.random.seed(0)\nx = np.random.rand(3, 5).astype(np.float32)\nlabels = np.random.randint(0, high=5, size=(3, )).astype(np.int64)\n\n# Compute SoftmaxCrossEntropyLoss\nsce = softmaxcrossentropy(x, labels, reduction='none')\n\n# Check results\nexpect(node, inputs=[x, labels], outputs=[sce], name='test_sce_none')" + }, + { + "summary": "softmaxcrossentropy_none_log_prob", + "code": "# Define operator attributes.\nreduction = 'none'\n\n# Create operator.\nnode = onnx.helper.make_node('SoftmaxCrossEntropyLoss',\n inputs=['x', 'y'],\n outputs=['z', 'log_prob'],\n reduction=reduction)\n\n# Define operator inputs.\nnp.random.seed(0)\nx = np.random.rand(3, 5).astype(np.float32)\nlabels = np.random.randint(0, high=5, size=(3, )).astype(np.int64)\n\n# Compute SoftmaxCrossEntropyLoss\nloss, log_prob = softmaxcrossentropy(x, labels, reduction='none', get_log_prob=True)\n\n# Check results\nexpect(node, inputs=[x, labels], outputs=[loss, log_prob], name='test_sce_none_log_prob')" + }, + { + "summary": "softmaxcrossentropy_none_weights", + "code": "# Define operator attributes.\nreduction = 'none'\n\n# Create operator.\nnode = onnx.helper.make_node('SoftmaxCrossEntropyLoss',\n inputs=['x', 'y', 'w'],\n outputs=['z'],\n reduction=reduction)\n\n# Define operator inputs.\nnp.random.seed(0)\nx = np.random.rand(3, 5).astype(np.float32)\nlabels = np.random.randint(0, high=5, size=(3, )).astype(np.int64)\nweights = np.array([0.9, 0.7, 0.8, 0.9, 0.9], dtype=np.float32)\n\n# Compute SoftmaxCrossEntropyLoss\nsce = softmaxcrossentropy(x, labels, weight=weights, reduction='none')\n\n# Check results\nexpect(node, inputs=[x, labels, weights], outputs=[sce], name='test_sce_none_weights')" + }, + { + "summary": "softmaxcrossentropy_none_weights_log_prob", + "code": "# Define operator attributes.\nreduction = 'none'\n\n# Create operator.\nnode = onnx.helper.make_node('SoftmaxCrossEntropyLoss',\n inputs=['x', 'y', 'w'],\n outputs=['z', 'log_prob'],\n reduction=reduction)\n\n# Define operator inputs.\nnp.random.seed(0)\nx = np.random.rand(3, 5).astype(np.float32)\nlabels = np.random.randint(0, high=5, size=(3, )).astype(np.int64)\nweights = np.array([0.9, 0.7, 0.8, 0.9, 0.9], dtype=np.float32)\n\n# Compute SoftmaxCrossEntropyLoss\nloss, log_prob = softmaxcrossentropy(x, labels, weight=weights, reduction='none', get_log_prob=True)\n\n# Check results\nexpect(node, inputs=[x, labels, weights], outputs=[loss, log_prob], name='test_sce_none_weights_log_prob')" + }, + { + "summary": "softmaxcrossentropy_sum", + "code": "# Define operator attributes.\nreduction = 'sum'\n\n# Create operator.\nnode = onnx.helper.make_node('SoftmaxCrossEntropyLoss',\n inputs=['x', 'y'],\n outputs=['z'],\n reduction=reduction)\n\n# Define operator inputs.\nnp.random.seed(0)\nx = np.random.rand(3, 5).astype(np.float32)\nlabels = np.random.randint(0, high=5, size=(3, )).astype(np.int64)\n\n# Compute SoftmaxCrossEntropyLoss\nsce = softmaxcrossentropy(x, labels, reduction='sum')\n\n# Check results\nexpect(node, inputs=[x, labels], outputs=[sce], name='test_sce_sum')" + }, + { + "summary": "softmaxcrossentropy_sum_log_prob", + "code": "# Define operator attributes.\nreduction = 'sum'\n\n# Create operator.\nnode = onnx.helper.make_node('SoftmaxCrossEntropyLoss',\n inputs=['x', 'y'],\n outputs=['z', 'log_prob'],\n reduction=reduction)\n\n# Define operator inputs.\nnp.random.seed(0)\nx = np.random.rand(3, 5).astype(np.float32)\nlabels = np.random.randint(0, high=5, size=(3, )).astype(np.int64)\n\n# Compute SoftmaxCrossEntropyLoss\nloss, log_prob = softmaxcrossentropy(x, labels, reduction='sum', get_log_prob=True)\n\n# Check results\nexpect(node, inputs=[x, labels], outputs=[loss, log_prob], name='test_sce_sum_log_prob')" + } + ] + }, + { + "name": "SoftmaxCrossEntropyLoss", + "module": "ai.onnx", + "version": 13, + "support_level": "common", + "description": "Loss function that measures the softmax cross entropy\nbetween 'scores' and 'labels'.\nThis operator first computes a loss tensor whose shape is identical to the labels input.\nIf 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).\nIf the input is N-D tensor with shape (N, C, D1, D2, ..., Dk),\nthe 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.\nAfter L is available, this operator can optionally do a reduction operator.\n\nshape(scores): (N, C) where C is the number of classes, or (N, C, D1, D2,..., Dk),\n with K >= 1 in case of K-dimensional loss.\nshape(labels): (N) where each value is 0 <= labels[i] <= C-1, or (N, D1, D2,..., Dk),\n with K >= 1 in case of K-dimensional loss.\n\nThe loss for one sample, l_i, can caculated as follows:\n l[i][d1][d2]...[dk] = -y[i][c][d1][d2]..[dk], where i is the index of classes.\nor\n l[i][d1][d2]...[dk] = -y[i][c][d1][d2]..[dk] * weights[c], if 'weights' is provided.\n\nloss is zero for the case when label-value equals ignore_index.\n l[i][d1][d2]...[dk] = 0, when labels[n][d1][d2]...[dk] = ignore_index\n\nwhere:\n p = Softmax(scores)\n y = Log(p)\n c = labels[i][d1][d2]...[dk]\n\nFinally, L is optionally reduced:\nIf reduction = 'none', the output is L with shape (N, D1, D2, ..., Dk).\nIf reduction = 'sum', the output is scalar: Sum(L).\nIf reduction = 'mean', the output is scalar: ReduceMean(L), or if weight is provided: ReduceSum(L) / ReduceSum(W),\nwhere tensor W is of shape (N, D1, D2, ..., Dk) and W[n][d1][d2]...[dk] = weights[labels[i][d1][d2]...[dk]].\n", + "attributes": [ + { + "name": "ignore_index", + "type": "int64", + "required": false, + "description": "Specifies a target value that is ignored and does not contribute to the input gradient. It's an optional value." + }, + { + "name": "reduction", + "type": "string", + "required": false, + "default": "mean", + "description": "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": [ + { + "name": "scores", + "type": "T", + "description": "The predicted outputs with shape [batch_size, class_size], or [batch_size, class_size, D1, D2 , ..., Dk], where K is the number of dimensions." + }, + { + "name": "labels", + "type": "Tind", + "description": "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." + }, + { + "name": "weights", + "type": "T", + "option": "optional", + "description": "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." + } + ], + "min_input": 2, + "max_input": 3, + "outputs": [ + { + "name": "output", + "type": "T", + "description": "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." + }, + { + "name": "log_prob", + "type": "T", + "option": "optional", + "description": "Log probability tensor. If the output of softmax is prob, its value is log(prob)." + } + ], + "min_output": 1, + "max_output": 2, + "inputs_range": "2 - 3", + "outputs_range": "1 - 2", + "type_constraints": [ + { + "description": "Constrain input and output types to float tensors.", + "type_param_str": "T", + "allowed_type_strs": [ + "tensor(float16)", + "tensor(float)", + "tensor(double)", + "tensor(bfloat16)" + ] + }, + { + "description": "Constrain target to integer types", + "type_param_str": "Tind", + "allowed_type_strs": [ + "tensor(int32)", + "tensor(int64)" + ] + } + ], + "examples": [ + { + "summary": "input_shape_is_NCd1_mean_weight_negative_ii", + "code": "reduction = 'mean'\nignore_index = np.int64(-1)\n\nnode = onnx.helper.make_node('SoftmaxCrossEntropyLoss',\n inputs=['x', 'y', 'w'],\n outputs=['z'],\n reduction=reduction,\n ignore_index=ignore_index)\n\nN, C, dim1 = 3, 5, 6\nnp.random.seed(0)\nx = np.random.rand(N, C, dim1).astype(np.float32)\nlabels = np.random.randint(0, high=C, size=(N, dim1)).astype(np.int64)\nlabels[0][0] = -1\nweight = np.random.rand(C).astype(np.float32)\n\nsce = softmaxcrossentropy(x,\n labels,\n weight=weight,\n reduction=reduction,\n ignore_index=ignore_index)\n\nexpect(node, inputs=[x, labels, weight], outputs=[sce], name='test_sce_NCd1_mean_weight_negative_ii')" + }, + { + "summary": "input_shape_is_NCd1_mean_weight_negative_ii_log_prob", + "code": "reduction = 'mean'\nignore_index = np.int64(-1)\n\nnode = onnx.helper.make_node('SoftmaxCrossEntropyLoss',\n inputs=['x', 'y', 'w'],\n outputs=['z', 'log_prob'],\n reduction=reduction,\n ignore_index=ignore_index)\n\nN, C, dim1 = 3, 5, 6\nnp.random.seed(0)\nx = np.random.rand(N, C, dim1).astype(np.float32)\nlabels = np.random.randint(0, high=C, size=(N, dim1)).astype(np.int64)\nlabels[0][0] = -1\nweight = np.random.rand(C).astype(np.float32)\n\nloss, log_prob = softmaxcrossentropy(x,\n labels,\n weight=weight,\n reduction=reduction,\n ignore_index=ignore_index,\n get_log_prob=True)\n\nexpect(node, inputs=[x, labels, weight], outputs=[loss, log_prob], name='test_sce_NCd1_mean_weight_negative_ii_log_prob')" + }, + { + "summary": "input_shape_is_NCd1d2d3_none_no_weight_negative_ii", + "code": "reduction = 'none'\nignore_index = np.int64(-5)\n\nnode = onnx.helper.make_node('SoftmaxCrossEntropyLoss',\n inputs=['x', 'y'],\n outputs=['z'],\n reduction=reduction,\n ignore_index=ignore_index)\n\nN, C, dim1, dim2, dim3 = 3, 5, 6, 6, 5\nnp.random.seed(0)\nx = np.random.rand(N, C, dim1, dim2, dim3).astype(np.float32)\nlabels = np.random.randint(0, high=C, size=(N, dim1, dim2, dim3)).astype(np.int64)\nlabels[0][0][0][0] = -5\n\nsce = softmaxcrossentropy(x,\n labels,\n reduction=reduction,\n ignore_index=ignore_index)\n\nexpect(node, inputs=[x, labels], outputs=[sce], name='test_sce_NCd1d2d3_none_no_weight_negative_ii')" + }, + { + "summary": "input_shape_is_NCd1d2d3_none_no_weight_negative_ii_log_prob", + "code": "reduction = 'none'\nignore_index = np.int64(-5)\n\nnode = onnx.helper.make_node('SoftmaxCrossEntropyLoss',\n inputs=['x', 'y'],\n outputs=['z', 'log_prob'],\n reduction=reduction,\n ignore_index=ignore_index)\n\nN, C, dim1, dim2, dim3 = 3, 5, 6, 6, 5\nnp.random.seed(0)\nx = np.random.rand(N, C, dim1, dim2, dim3).astype(np.float32)\nlabels = np.random.randint(0, high=C, size=(N, dim1, dim2, dim3)).astype(np.int64)\nlabels[0][0][0][0] = -5\n\nloss, log_prob = softmaxcrossentropy(x,\n labels,\n reduction=reduction,\n ignore_index=ignore_index,\n get_log_prob=True)\n\nexpect(node, inputs=[x, labels], outputs=[loss, log_prob], name='test_sce_NCd1d2d3_none_no_weight_negative_ii_log_prob')" + }, + { + "summary": "input_shape_is_NCd1d2d3_sum_weight_high_ii", + "code": "reduction = 'sum'\nignore_index = np.int64(10)\n\nnode = onnx.helper.make_node('SoftmaxCrossEntropyLoss',\n inputs=['x', 'y', 'w'],\n outputs=['z'],\n reduction=reduction,\n ignore_index=ignore_index)\n\nN, C = 3, 5\nnp.random.seed(0)\nx = np.random.rand(N, C).astype(np.float32)\nlabels = np.random.randint(0, high=C, size=(N)).astype(np.int64)\nlabels[0] = 10\nweight = np.random.rand(C).astype(np.float32)\n\nsce = softmaxcrossentropy(x,\n labels,\n weight=weight,\n reduction=reduction,\n ignore_index=ignore_index)\n\nexpect(node, inputs=[x, labels, weight], outputs=[sce], name='test_sce_NCd1d2d3_sum_weight_high_ii')" + }, + { + "summary": "input_shape_is_NCd1d2d3_sum_weight_high_ii_log_prob", + "code": "reduction = 'sum'\nignore_index = np.int64(10)\n\nnode = onnx.helper.make_node('SoftmaxCrossEntropyLoss',\n inputs=['x', 'y', 'w'],\n outputs=['z', 'log_prob'],\n reduction=reduction,\n ignore_index=ignore_index)\n\nN, C = 3, 5\nnp.random.seed(0)\nx = np.random.rand(N, C).astype(np.float32)\nlabels = np.random.randint(0, high=C, size=(N)).astype(np.int64)\nlabels[0] = 10\nweight = np.random.rand(C).astype(np.float32)\n\nloss, log_prob = softmaxcrossentropy(x,\n labels,\n weight=weight,\n reduction=reduction,\n ignore_index=ignore_index,\n get_log_prob=True)\n\nexpect(node, inputs=[x, labels, weight], outputs=[loss, log_prob], name='test_sce_NCd1d2d3_sum_weight_high_ii_log_prob')" + }, + { + "summary": "input_shape_is_NCd1d2d3d4d5_mean_weight", + "code": "reduction = 'mean'\n\nnode = onnx.helper.make_node('SoftmaxCrossEntropyLoss',\n inputs=['x', 'y', 'w'],\n outputs=['z'],\n reduction=reduction)\n\nN, C, dim1, dim2, dim3, dim4, dim5 = 3, 5, 6, 6, 5, 3, 4\nnp.random.seed(0)\nx = np.random.rand(N, C, dim1, dim2, dim3, dim4, dim5).astype(np.float32)\nlabels = np.random.randint(0, high=C, size=(N, dim1, dim2, dim3, dim4, dim5)).astype(np.int64)\nweight = np.random.rand(C).astype(np.float32)\n\nsce = softmaxcrossentropy(x,\n labels,\n weight=weight,\n reduction=reduction)\n\nexpect(node, inputs=[x, labels, weight], outputs=[sce], name='test_sce_NCd1d2d3d4d5_mean_weight')" + }, + { + "summary": "input_shape_is_NCd1d2d3d4d5_mean_weight_log_prob", + "code": "reduction = 'mean'\n\nnode = onnx.helper.make_node('SoftmaxCrossEntropyLoss',\n inputs=['x', 'y', 'w'],\n outputs=['z', 'log_prob'],\n reduction=reduction)\n\nN, C, dim1, dim2, dim3, dim4, dim5 = 3, 5, 6, 6, 5, 3, 4\nnp.random.seed(0)\nx = np.random.rand(N, C, dim1, dim2, dim3, dim4, dim5).astype(np.float32)\nlabels = np.random.randint(0, high=C, size=(N, dim1, dim2, dim3, dim4, dim5)).astype(np.int64)\nweight = np.random.rand(C).astype(np.float32)\n\nloss, log_prob = softmaxcrossentropy(x,\n labels,\n weight=weight,\n reduction=reduction,\n get_log_prob=True)\n\nexpect(node, inputs=[x, labels, weight], outputs=[loss, log_prob], name='test_sce_NCd1d2d3d4d5_mean_weight_log_prob')" + }, + { + "summary": "input_shape_is_NCd1d2d3d4d5_none_no_weight", + "code": "reduction = 'none'\n\nnode = onnx.helper.make_node('SoftmaxCrossEntropyLoss',\n inputs=['x', 'y'],\n outputs=['z'],\n reduction=reduction)\n\nN, C, dim1, dim2, dim3, dim4, dim5 = 3, 5, 6, 6, 5, 3, 4\nnp.random.seed(0)\nx = np.random.rand(N, C, dim1, dim2, dim3, dim4, dim5).astype(np.float32)\nlabels = np.random.randint(0, high=C, size=(N, dim1, dim2, dim3, dim4, dim5)).astype(np.int64)\n\nsce = softmaxcrossentropy(x,\n labels,\n reduction=reduction)\n\nexpect(node, inputs=[x, labels], outputs=[sce], name='test_sce_NCd1d2d3d4d5_none_no_weight')" + }, + { + "summary": "input_shape_is_NCd1d2d3d4d5_none_no_weight_log_prob", + "code": "reduction = 'none'\n\nnode = onnx.helper.make_node('SoftmaxCrossEntropyLoss',\n inputs=['x', 'y'],\n outputs=['z', 'log_prob'],\n reduction=reduction)\n\nN, C, dim1, dim2, dim3, dim4, dim5 = 3, 5, 6, 6, 5, 3, 4\nnp.random.seed(0)\nx = np.random.rand(N, C, dim1, dim2, dim3, dim4, dim5).astype(np.float32)\nlabels = np.random.randint(0, high=C, size=(N, dim1, dim2, dim3, dim4, dim5)).astype(np.int64)\n\nloss, log_prob = softmaxcrossentropy(x,\n labels,\n reduction=reduction,\n get_log_prob=True)\n\nexpect(node, inputs=[x, labels], outputs=[loss, log_prob], name='test_sce_NCd1d2d3d4d5_none_no_weight_log_prob')" + }, + { + "summary": "softmaxcrossentropy_mean", + "code": "# Define operator attributes.\nreduction = 'mean'\n\n# Create operator.\nnode = onnx.helper.make_node('SoftmaxCrossEntropyLoss',\n inputs=['x', 'y'],\n outputs=['z'],\n reduction=reduction)\n\n# Define operator inputs.\nnp.random.seed(0)\nx = np.random.rand(3, 5).astype(np.float32)\nlabels = np.random.randint(0, high=5, size=(3, )).astype(np.int64)\n\n# Compute SoftmaxCrossEntropyLoss\nsce = softmaxcrossentropy(x, labels)\n\n# Check results\nexpect(node, inputs=[x, labels], outputs=[sce], name='test_sce_mean')" + }, + { + "summary": "softmaxcrossentropy_mean_3d", + "code": "# Define operator attributes.\nreduction = 'mean'\n\n# Create operator.\nnode = onnx.helper.make_node('SoftmaxCrossEntropyLoss',\n inputs=['x', 'y'],\n outputs=['z'],\n reduction=reduction)\n\n# Define operator inputs.\nnp.random.seed(0)\nx = np.random.rand(3, 5, 2).astype(np.float32)\ny = np.random.randint(0, high=5, size=(3, 2)).astype(np.int64)\n\n# Compute SoftmaxCrossEntropyLoss\nsce = softmaxcrossentropy(x, y)\n\n# Check results\nexpect(node, inputs=[x, y], outputs=[sce], name='test_sce_mean_3d')" + }, + { + "summary": "softmaxcrossentropy_mean_3d_log_prob", + "code": "# Define operator attributes.\nreduction = 'mean'\n\n# Create operator.\nnode = onnx.helper.make_node('SoftmaxCrossEntropyLoss',\n inputs=['x', 'y'],\n outputs=['z', 'log_prob'],\n reduction=reduction)\n\n# Define operator inputs.\nnp.random.seed(0)\nx = np.random.rand(3, 5, 2).astype(np.float32)\ny = np.random.randint(0, high=5, size=(3, 2)).astype(np.int64)\n\n# Compute SoftmaxCrossEntropyLoss\nloss, log_prob = softmaxcrossentropy(x, y, get_log_prob=True)\n\n# Check results\nexpect(node, inputs=[x, y], outputs=[loss, log_prob], name='test_sce_mean_3d_log_prob')" + }, + { + "summary": "softmaxcrossentropy_mean_log_prob", + "code": "# Define operator attributes.\nreduction = 'mean'\n\n# Create operator.\nnode = onnx.helper.make_node('SoftmaxCrossEntropyLoss',\n inputs=['x', 'y'],\n outputs=['z', 'log_prob'],\n reduction=reduction)\n\n# Define operator inputs.\nnp.random.seed(0)\nx = np.random.rand(3, 5).astype(np.float32)\nlabels = np.random.randint(0, high=5, size=(3, )).astype(np.int64)\n\n# Compute SoftmaxCrossEntropyLoss\nloss, log_prob = softmaxcrossentropy(x, labels, get_log_prob=True)\n\n# Check results\nexpect(node, inputs=[x, labels], outputs=[loss, log_prob], name='test_sce_mean_log_prob')" + }, + { + "summary": "softmaxcrossentropy_mean_no_weights_ii", + "code": "# Define operator attributes.\nreduction = 'mean'\nignore_index = np.int64(2)\n\n# Create operator.\nnode = onnx.helper.make_node('SoftmaxCrossEntropyLoss',\n inputs=['x', 'y'],\n outputs=['z'],\n reduction=reduction,\n ignore_index=ignore_index)\n\n# Define operator inputs.\nnp.random.seed(0)\nx = np.random.rand(3, 5).astype(np.float32)\nlabels = np.random.randint(0, high=5, size=(3, )).astype(np.int64)\nlabels[0] = np.int64(2)\n\n# Compute SoftmaxCrossEntropyLoss\nsce = softmaxcrossentropy(x, labels, ignore_index=ignore_index)\n\n# Check results\nexpect(node, inputs=[x, labels], outputs=[sce], name='test_sce_mean_no_weight_ii')" + }, + { + "summary": "softmaxcrossentropy_mean_no_weights_ii_3d", + "code": "# Define operator attributes.\nreduction = 'mean'\nignore_index = np.int64(2)\n\n# Create operator.\nnode = onnx.helper.make_node('SoftmaxCrossEntropyLoss',\n inputs=['x', 'y'],\n outputs=['z'],\n reduction=reduction,\n ignore_index=ignore_index)\n\n# Define operator inputs.\nnp.random.seed(0)\nx = np.random.rand(3, 5, 2).astype(np.float32)\nlabels = np.random.randint(0, high=5, size=(3, 2)).astype(np.int64)\nlabels[0][0] = np.int64(2)\n\n# Compute SoftmaxCrossEntropyLoss\nsce = softmaxcrossentropy(x, labels, ignore_index=ignore_index)\n\n# Check results\nexpect(node, inputs=[x, labels], outputs=[sce], name='test_sce_mean_no_weight_ii_3d')" + }, + { + "summary": "softmaxcrossentropy_mean_no_weights_ii_3d_log_prob", + "code": "# Define operator attributes.\nreduction = 'mean'\nignore_index = np.int64(2)\n\n# Create operator.\nnode = onnx.helper.make_node('SoftmaxCrossEntropyLoss',\n inputs=['x', 'y'],\n outputs=['z', 'log_prob'],\n reduction=reduction,\n ignore_index=ignore_index)\n\n# Define operator inputs.\nnp.random.seed(0)\nx = np.random.rand(3, 5, 2).astype(np.float32)\nlabels = np.random.randint(0, high=5, size=(3, 2)).astype(np.int64)\nlabels[0][0] = np.int64(2)\n\n# Compute SoftmaxCrossEntropyLoss\nloss, log_prob = softmaxcrossentropy(x, labels, ignore_index=ignore_index, get_log_prob=True)\n\n# Check results\nexpect(node, inputs=[x, labels], outputs=[loss, log_prob], name='test_sce_mean_no_weight_ii_3d_log_prob')" + }, + { + "summary": "softmaxcrossentropy_mean_no_weights_ii_4d", + "code": "# Define operator attributes.\nreduction = 'mean'\nignore_index = np.int64(2)\n\n# Create operator.\nnode = onnx.helper.make_node('SoftmaxCrossEntropyLoss',\n inputs=['x', 'y'],\n outputs=['z'],\n reduction=reduction,\n ignore_index=ignore_index)\n\n# Define operator inputs.\nnp.random.seed(0)\nx = np.random.rand(3, 5, 2, 7).astype(np.float32)\nlabels = np.random.randint(0, high=5, size=(3, 2, 7)).astype(np.int64)\nlabels[0][0][0] = np.int64(2)\n\n# Compute SoftmaxCrossEntropyLoss\nsce = softmaxcrossentropy(x, labels, reduction=reduction, ignore_index=ignore_index)\n\n# Check results\nexpect(node, inputs=[x, labels], outputs=[sce], name='test_sce_mean_no_weight_ii_4d')" + }, + { + "summary": "softmaxcrossentropy_mean_no_weights_ii_4d_log_prob", + "code": "# Define operator attributes.\nreduction = 'mean'\nignore_index = np.int64(2)\n\n# Create operator.\nnode = onnx.helper.make_node('SoftmaxCrossEntropyLoss',\n inputs=['x', 'y'],\n outputs=['z', 'log_prob'],\n reduction=reduction,\n ignore_index=ignore_index)\n\n# Define operator inputs.\nnp.random.seed(0)\nx = np.random.rand(3, 5, 2, 7).astype(np.float32)\nlabels = np.random.randint(0, high=5, size=(3, 2, 7)).astype(np.int64)\nlabels[0][0][0] = np.int64(2)\n\n# Compute SoftmaxCrossEntropyLoss\nloss, log_prob = softmaxcrossentropy(x, labels, reduction=reduction, ignore_index=ignore_index, get_log_prob=True)\n\n# Check results\nexpect(node, inputs=[x, labels], outputs=[loss, log_prob], name='test_sce_mean_no_weight_ii_4d_log_prob')" + }, + { + "summary": "softmaxcrossentropy_mean_no_weights_ii_log_prob", + "code": "# Define operator attributes.\nreduction = 'mean'\nignore_index = np.int64(2)\n\n# Create operator.\nnode = onnx.helper.make_node('SoftmaxCrossEntropyLoss',\n inputs=['x', 'y'],\n outputs=['z', 'log_prob'],\n reduction=reduction,\n ignore_index=ignore_index)\n\n# Define operator inputs.\nnp.random.seed(0)\nx = np.random.rand(3, 5).astype(np.float32)\nlabels = np.random.randint(0, high=5, size=(3, )).astype(np.int64)\nlabels[0] = np.int64(2)\n\n# Compute SoftmaxCrossEntropyLoss\nloss, log_prob = softmaxcrossentropy(x, labels, ignore_index=ignore_index, get_log_prob=True)\n\n# Check results\nexpect(node, inputs=[x, labels], outputs=[loss, log_prob], name='test_sce_mean_no_weight_ii_log_prob')" + }, + { + "summary": "softmaxcrossentropy_mean_weights", + "code": "# Define operator attributes.\nreduction = 'mean'\n\n# Create operator.\nnode = onnx.helper.make_node('SoftmaxCrossEntropyLoss',\n inputs=['x', 'y', 'w'],\n outputs=['z'],\n reduction=reduction)\n\n# Define operator inputs.\nnp.random.seed(0)\nx = np.random.rand(3, 5).astype(np.float32)\nlabels = np.random.randint(0, high=5, size=(3, )).astype(np.int64)\nweights = np.array([0.9, 0.7, 0.8, 0.9, 0.9], dtype=np.float32)\n\n# Compute SoftmaxCrossEntropyLoss\nsce = softmaxcrossentropy(x, labels, weight=weights)\n\n# Check results\nexpect(node, inputs=[x, labels, weights], outputs=[sce], name='test_sce_mean_weight')" + }, + { + "summary": "softmaxcrossentropy_mean_weights_ii", + "code": "# Define operator attributes.\nreduction = 'mean'\nignore_index = np.int64(0)\n\n# Create operator.\nnode = onnx.helper.make_node('SoftmaxCrossEntropyLoss',\n inputs=['x', 'y', 'w'],\n outputs=['z'],\n reduction=reduction,\n ignore_index=ignore_index)\n\n# Define operator inputs.\nnp.random.seed(0)\nx = np.random.rand(3, 5).astype(np.float32)\nlabels = np.random.randint(0, high=5, size=(3, )).astype(np.int64)\nlabels[0] = np.int64(0)\nweights = np.array([0.9, 0.7, 0.8, 0.9, 0.9], dtype=np.float32)\n\n# Compute SoftmaxCrossEntropyLoss\nsce = softmaxcrossentropy(x, labels, weight=weights, ignore_index=ignore_index)\n\n# Check results\nexpect(node, inputs=[x, labels, weights], outputs=[sce], name='test_sce_mean_weight_ii')" + }, + { + "summary": "softmaxcrossentropy_mean_weights_ii_3d", + "code": "# Define operator attributes.\nreduction = 'mean'\nignore_index = np.int64(1)\n\n# Create operator.\nnode = onnx.helper.make_node('SoftmaxCrossEntropyLoss',\n inputs=['x', 'y', 'w'],\n outputs=['z'],\n reduction=reduction,\n ignore_index=ignore_index)\n\n# Define operator inputs.\nnp.random.seed(0)\nx = np.random.rand(3, 5, 2).astype(np.float32)\nlabels = np.random.randint(0, high=5, size=(3, 2)).astype(np.int64)\nlabels[0][0] = np.int64(1)\nweights = np.array([0.2, 0.3, 0.6, 0.1, 0.5], dtype=np.float32)\n\n# Compute SoftmaxCrossEntropyLoss\nsce = softmaxcrossentropy(x, labels, weight=weights, ignore_index=ignore_index)\n\n# Check results\nexpect(node, inputs=[x, labels, weights], outputs=[sce], name='test_sce_mean_weight_ii_3d')" + }, + { + "summary": "softmaxcrossentropy_mean_weights_ii_3d_log_prob", + "code": "# Define operator attributes.\nreduction = 'mean'\nignore_index = np.int64(1)\n\n# Create operator.\nnode = onnx.helper.make_node('SoftmaxCrossEntropyLoss',\n inputs=['x', 'y', 'w'],\n outputs=['z', 'log_prob'],\n reduction=reduction,\n ignore_index=ignore_index)\n\n# Define operator inputs.\nnp.random.seed(0)\nx = np.random.rand(3, 5, 2).astype(np.float32)\nlabels = np.random.randint(0, high=5, size=(3, 2)).astype(np.int64)\nlabels[0][0] = np.int64(1)\nweights = np.array([0.2, 0.3, 0.6, 0.1, 0.5], dtype=np.float32)\n\n# Compute SoftmaxCrossEntropyLoss\nloss, log_prob = softmaxcrossentropy(x, labels, weight=weights, ignore_index=ignore_index, get_log_prob=True)\n\n# Check results\nexpect(node, inputs=[x, labels, weights], outputs=[loss, log_prob], name='test_sce_mean_weight_ii_3d_log_prob')" + }, + { + "summary": "softmaxcrossentropy_mean_weights_ii_4d", + "code": "# Define operator attributes.\nreduction = 'mean'\nignore_index = np.int64(2)\n\n# Create operator.\nnode = onnx.helper.make_node('SoftmaxCrossEntropyLoss',\n inputs=['x', 'y', 'w'],\n outputs=['z'],\n reduction=reduction,\n ignore_index=ignore_index)\n\n# Define operator inputs.\nnp.random.seed(0)\nx = np.random.rand(3, 5, 2, 7).astype(np.float32)\nlabels = np.random.randint(0, high=5, size=(3, 2, 7)).astype(np.int64)\nlabels[0][0][0] = np.int64(2)\nweights = np.array([0.2, 0.3, 0.6, 0.1, 0.5], dtype=np.float32)\n\n# Compute SoftmaxCrossEntropyLoss\nsce = softmaxcrossentropy(x, labels, reduction=reduction, weight=weights, ignore_index=ignore_index)\n\n# Check results\nexpect(node, inputs=[x, labels, weights], outputs=[sce], name='test_sce_mean_weight_ii_4d')" + }, + { + "summary": "softmaxcrossentropy_mean_weights_ii_4d_log_prob", + "code": "# Define operator attributes.\nreduction = 'mean'\nignore_index = np.int64(2)\n\n# Create operator.\nnode = onnx.helper.make_node('SoftmaxCrossEntropyLoss',\n inputs=['x', 'y', 'w'],\n outputs=['z', 'log_prob'],\n reduction=reduction,\n ignore_index=ignore_index)\n\n# Define operator inputs.\nnp.random.seed(0)\nx = np.random.rand(3, 5, 2, 7).astype(np.float32)\nlabels = np.random.randint(0, high=5, size=(3, 2, 7)).astype(np.int64)\nlabels[0][0][0] = np.int64(2)\nweights = np.array([0.2, 0.3, 0.6, 0.1, 0.5], dtype=np.float32)\n\n# Compute SoftmaxCrossEntropyLoss\nloss, log_prob = softmaxcrossentropy(x, labels, reduction=reduction, weight=weights, ignore_index=ignore_index, get_log_prob=True)\n\n# Check results\nexpect(node, inputs=[x, labels, weights], outputs=[loss, log_prob], name='test_sce_mean_weight_ii_4d_log_prob')" + }, + { + "summary": "softmaxcrossentropy_mean_weights_ii_log_prob", + "code": "# Define operator attributes.\nreduction = 'mean'\nignore_index = np.int64(0)\n\n# Create operator.\nnode = onnx.helper.make_node('SoftmaxCrossEntropyLoss',\n inputs=['x', 'y', 'w'],\n outputs=['z', 'log_prob'],\n reduction=reduction,\n ignore_index=ignore_index)\n\n# Define operator inputs.\nnp.random.seed(0)\nx = np.random.rand(3, 5).astype(np.float32)\nlabels = np.random.randint(0, high=5, size=(3, )).astype(np.int64)\nlabels[0] = np.int64(0)\nweights = np.array([0.9, 0.7, 0.8, 0.9, 0.9], dtype=np.float32)\n\n# Compute SoftmaxCrossEntropyLoss\nloss, log_prob = softmaxcrossentropy(x, labels, weight=weights, ignore_index=ignore_index, get_log_prob=True)\n\n# Check results\nexpect(node, inputs=[x, labels, weights], outputs=[loss, log_prob], name='test_sce_mean_weight_ii_log_prob')" + }, + { + "summary": "softmaxcrossentropy_mean_weights_log_prob", + "code": "# Define operator attributes.\nreduction = 'mean'\n\n# Create operator.\nnode = onnx.helper.make_node('SoftmaxCrossEntropyLoss',\n inputs=['x', 'y', 'w'],\n outputs=['z', 'log_prob'],\n reduction=reduction)\n\n# Define operator inputs.\nnp.random.seed(0)\nx = np.random.rand(3, 5).astype(np.float32)\nlabels = np.random.randint(0, high=5, size=(3, )).astype(np.int64)\nweights = np.array([0.9, 0.7, 0.8, 0.9, 0.9], dtype=np.float32)\n\n# Compute SoftmaxCrossEntropyLoss\nloss, log_prob = softmaxcrossentropy(x, labels, weight=weights, get_log_prob=True)\n\n# Check results\nexpect(node, inputs=[x, labels, weights], outputs=[loss, log_prob], name='test_sce_mean_weight_log_prob')" + }, + { + "summary": "softmaxcrossentropy_none", + "code": "# Define operator attributes.\nreduction = 'none'\n\n# Create operator.\nnode = onnx.helper.make_node('SoftmaxCrossEntropyLoss',\n inputs=['x', 'y'],\n outputs=['z'],\n reduction=reduction)\n\n# Define operator inputs.\nnp.random.seed(0)\nx = np.random.rand(3, 5).astype(np.float32)\nlabels = np.random.randint(0, high=5, size=(3, )).astype(np.int64)\n\n# Compute SoftmaxCrossEntropyLoss\nsce = softmaxcrossentropy(x, labels, reduction='none')\n\n# Check results\nexpect(node, inputs=[x, labels], outputs=[sce], name='test_sce_none')" + }, + { + "summary": "softmaxcrossentropy_none_log_prob", + "code": "# Define operator attributes.\nreduction = 'none'\n\n# Create operator.\nnode = onnx.helper.make_node('SoftmaxCrossEntropyLoss',\n inputs=['x', 'y'],\n outputs=['z', 'log_prob'],\n reduction=reduction)\n\n# Define operator inputs.\nnp.random.seed(0)\nx = np.random.rand(3, 5).astype(np.float32)\nlabels = np.random.randint(0, high=5, size=(3, )).astype(np.int64)\n\n# Compute SoftmaxCrossEntropyLoss\nloss, log_prob = softmaxcrossentropy(x, labels, reduction='none', get_log_prob=True)\n\n# Check results\nexpect(node, inputs=[x, labels], outputs=[loss, log_prob], name='test_sce_none_log_prob')" + }, + { + "summary": "softmaxcrossentropy_none_weights", + "code": "# Define operator attributes.\nreduction = 'none'\n\n# Create operator.\nnode = onnx.helper.make_node('SoftmaxCrossEntropyLoss',\n inputs=['x', 'y', 'w'],\n outputs=['z'],\n reduction=reduction)\n\n# Define operator inputs.\nnp.random.seed(0)\nx = np.random.rand(3, 5).astype(np.float32)\nlabels = np.random.randint(0, high=5, size=(3, )).astype(np.int64)\nweights = np.array([0.9, 0.7, 0.8, 0.9, 0.9], dtype=np.float32)\n\n# Compute SoftmaxCrossEntropyLoss\nsce = softmaxcrossentropy(x, labels, weight=weights, reduction='none')\n\n# Check results\nexpect(node, inputs=[x, labels, weights], outputs=[sce], name='test_sce_none_weights')" + }, + { + "summary": "softmaxcrossentropy_none_weights_log_prob", + "code": "# Define operator attributes.\nreduction = 'none'\n\n# Create operator.\nnode = onnx.helper.make_node('SoftmaxCrossEntropyLoss',\n inputs=['x', 'y', 'w'],\n outputs=['z', 'log_prob'],\n reduction=reduction)\n\n# Define operator inputs.\nnp.random.seed(0)\nx = np.random.rand(3, 5).astype(np.float32)\nlabels = np.random.randint(0, high=5, size=(3, )).astype(np.int64)\nweights = np.array([0.9, 0.7, 0.8, 0.9, 0.9], dtype=np.float32)\n\n# Compute SoftmaxCrossEntropyLoss\nloss, log_prob = softmaxcrossentropy(x, labels, weight=weights, reduction='none', get_log_prob=True)\n\n# Check results\nexpect(node, inputs=[x, labels, weights], outputs=[loss, log_prob], name='test_sce_none_weights_log_prob')" + }, + { + "summary": "softmaxcrossentropy_sum", + "code": "# Define operator attributes.\nreduction = 'sum'\n\n# Create operator.\nnode = onnx.helper.make_node('SoftmaxCrossEntropyLoss',\n inputs=['x', 'y'],\n outputs=['z'],\n reduction=reduction)\n\n# Define operator inputs.\nnp.random.seed(0)\nx = np.random.rand(3, 5).astype(np.float32)\nlabels = np.random.randint(0, high=5, size=(3, )).astype(np.int64)\n\n# Compute SoftmaxCrossEntropyLoss\nsce = softmaxcrossentropy(x, labels, reduction='sum')\n\n# Check results\nexpect(node, inputs=[x, labels], outputs=[sce], name='test_sce_sum')" + }, + { + "summary": "softmaxcrossentropy_sum_log_prob", + "code": "# Define operator attributes.\nreduction = 'sum'\n\n# Create operator.\nnode = onnx.helper.make_node('SoftmaxCrossEntropyLoss',\n inputs=['x', 'y'],\n outputs=['z', 'log_prob'],\n reduction=reduction)\n\n# Define operator inputs.\nnp.random.seed(0)\nx = np.random.rand(3, 5).astype(np.float32)\nlabels = np.random.randint(0, high=5, size=(3, )).astype(np.int64)\n\n# Compute SoftmaxCrossEntropyLoss\nloss, log_prob = softmaxcrossentropy(x, labels, reduction='sum', get_log_prob=True)\n\n# Check results\nexpect(node, inputs=[x, labels], outputs=[loss, log_prob], name='test_sce_sum_log_prob')" + } + ] + }, + { + "name": "Softplus", + "module": "ai.onnx", + "version": 1, + "support_level": "common", + "description": "Softplus takes one input data (Tensor) and produces one output data\n(Tensor) where the softplus function, y = ln(exp(x) + 1), is applied to\nthe tensor elementwise.\n", + "inputs": [ + { + "name": "X", + "type": "T", + "description": "1D input tensor" + } + ], + "min_input": 1, + "max_input": 1, + "outputs": [ + { + "name": "Y", + "type": "T", + "description": "1D input tensor" + } + ], + "min_output": 1, + "max_output": 1, + "type_constraints": [ + { + "description": "Constrain input and output types to float tensors.", + "type_param_str": "T", + "allowed_type_strs": [ + "tensor(float16)", + "tensor(float)", + "tensor(double)" + ] + } + ], + "examples": [ + { + "summary": "softplus", + "code": "node = onnx.helper.make_node(\n 'Softplus',\n inputs=['x'],\n outputs=['y'],\n)\n\nx = np.array([-1, 0, 1]).astype(np.float32)\ny = np.log(np.exp(x) + 1) # expected output [0.31326166, 0.69314718, 1.31326163]\nexpect(node, inputs=[x], outputs=[y],\n name='test_softplus_example')\n\nx = np.random.randn(3, 4, 5).astype(np.float32)\ny = np.log(np.exp(x) + 1)\nexpect(node, inputs=[x], outputs=[y],\n name='test_softplus')" + } + ], + "category": "Activation" + }, + { + "name": "Softsign", + "module": "ai.onnx", + "version": 1, + "support_level": "common", + "description": "Calculates the softsign (x/(1+|x|)) of the given input tensor element-wise.\n", + "inputs": [ + { + "name": "input", + "type": "T", + "description": "Input tensor" + } + ], + "min_input": 1, + "max_input": 1, + "outputs": [ + { + "name": "output", + "type": "T", + "description": "The softsign (x/(1+|x|)) values of the input tensor computed element-wise" + } + ], + "min_output": 1, + "max_output": 1, + "type_constraints": [ + { + "description": "Constrain input and output types to float tensors.", + "type_param_str": "T", + "allowed_type_strs": [ + "tensor(float16)", + "tensor(float)", + "tensor(double)" + ] + } + ], + "examples": [ + { + "summary": "softsign", + "code": "node = onnx.helper.make_node(\n 'Softsign',\n inputs=['x'],\n outputs=['y'],\n)\n\nx = np.array([-1, 0, 1]).astype(np.float32)\ny = np.array([-0.5, 0, 0.5]).astype(np.float32)\nexpect(node, inputs=[x], outputs=[y],\n name='test_softsign_example')\n\nx = np.random.randn(3, 4, 5).astype(np.float32)\ny = x / (1 + np.abs(x))\nexpect(node, inputs=[x], outputs=[y],\n name='test_softsign')" + } + ], + "category": "Activation" + }, + { + "name": "SpaceToDepth", + "module": "ai.onnx", + "version": 1, + "support_level": "common", + "description": "SpaceToDepth rearranges blocks of spatial data into depth. More specifically,\nthis op outputs a copy of the input tensor where values from the height and width dimensions\nare moved to the depth dimension.\n", + "attributes": [ + { + "name": "blocksize", + "type": "int64", + "required": true, + "description": "Blocks of [blocksize, blocksize] are moved." + } + ], + "inputs": [ + { + "name": "input", + "type": "T", + "description": "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." + } + ], + "min_input": 1, + "max_input": 1, + "outputs": [ + { + "name": "output", + "type": "T", + "description": "Output tensor of [N, C * blocksize * blocksize, H/blocksize, W/blocksize]." + } + ], + "min_output": 1, + "max_output": 1, + "type_constraints": [ + { + "description": "Constrain input and output types to all tensor types.", + "type_param_str": "T", + "allowed_type_strs": [ + "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)" + ] + } + ] + }, + { + "name": "SpaceToDepth", + "module": "ai.onnx", + "version": 13, + "support_level": "common", + "description": "SpaceToDepth rearranges blocks of spatial data into depth. More specifically,\nthis op outputs a copy of the input tensor where values from the height and width dimensions\nare moved to the depth dimension.\n", + "attributes": [ + { + "name": "blocksize", + "type": "int64", + "required": true, + "description": "Blocks of [blocksize, blocksize] are moved." + } + ], + "inputs": [ + { + "name": "input", + "type": "T", + "description": "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." + } + ], + "min_input": 1, + "max_input": 1, + "outputs": [ + { + "name": "output", + "type": "T", + "description": "Output tensor of [N, C * blocksize * blocksize, H/blocksize, W/blocksize]." + } + ], + "min_output": 1, + "max_output": 1, + "type_constraints": [ + { + "description": "Constrain input and output types to all tensor types.", + "type_param_str": "T", + "allowed_type_strs": [ + "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)" + ] + } + ] + }, + { + "name": "Split", + "module": "ai.onnx", + "version": 1, + "support_level": "common", + "description": "Split a tensor into a list of tensors, along the specified\n'axis'. The lengths of the split can be specified using argument 'axis' or\noptional second input blob to the operator. Otherwise, the tensor is split\nto equal sized parts.\n", + "attributes": [ + { + "name": "axis", + "type": "int64", + "required": false, + "description": "Which axis to split on" + }, + { + "name": "split", + "type": "int64[]", + "required": false, + "description": "length of each output" + } + ], + "inputs": [ + { + "name": "input", + "type": "T", + "description": "The tensor to split" + }, + { + "name": "split", + "type": "T", + "option": "optional", + "description": "Optional list of output lengths (see also arg 'split')" + } + ], + "min_input": 1, + "max_input": 2, + "outputs": [ + { + "name": "outputs...", + "type": "T", + "list": true, + "description": "One or more outputs forming list of tensors after splitting" + } + ], + "min_output": 1, + "max_output": 2147483647, + "inputs_range": "1 - 2", + "outputs_range": "1 - ∞", + "type_constraints": [ + { + "description": "Constrain input types to float tensors.", + "type_param_str": "T", + "allowed_type_strs": [ + "tensor(float16)", + "tensor(float)", + "tensor(double)" + ] + } + ], + "examples": [ + { + "summary": "1d", + "code": "input = np.array([1., 2., 3., 4., 5., 6.]).astype(np.float32)\n\nnode = onnx.helper.make_node(\n 'Split',\n inputs=['input'],\n outputs=['output_1', 'output_2', 'output_3'],\n axis=0\n)\n\nexpected_outputs = [np.array([1., 2.]).astype(np.float32), np.array([3., 4.]).astype(np.float32), np.array([5., 6.]).astype(np.float32)]\nexpect(node, inputs=[input], outputs=[y for y in expected_outputs], name='test_split_equal_parts_1d')\n\nsplit = np.array([2, 4]).astype(np.int64)\nnode = onnx.helper.make_node(\n 'Split',\n inputs=['input', 'split'],\n outputs=['output_1', 'output_2'],\n axis=0,\n)\n\nexpected_outputs = [np.array([1., 2.]).astype(np.float32), np.array([3., 4., 5., 6.]).astype(np.float32)]\nexpect(node, inputs=[input, split], outputs=[y for y in expected_outputs], name='test_split_variable_parts_1d')" + }, + { + "summary": "2d", + "code": "input = np.array([[1., 2., 3., 4., 5., 6.],\n [7., 8., 9., 10., 11., 12.]]).astype(np.float32)\n\nnode = onnx.helper.make_node(\n 'Split',\n inputs=['input'],\n outputs=['output_1', 'output_2'],\n axis=1\n)\n\nexpected_outputs = [np.array([[1., 2., 3.], [7., 8., 9.]]).astype(np.float32),\n np.array([[4., 5., 6.], [10., 11., 12.]]).astype(np.float32)]\n\nexpect(node, inputs=[input], outputs=[y for y in expected_outputs], name='test_split_equal_parts_2d')\n\nsplit = np.array([2, 4]).astype(np.int64)\nnode = onnx.helper.make_node(\n 'Split',\n inputs=['input', 'split'],\n outputs=['output_1', 'output_2'],\n axis=1,\n)\n\nexpected_outputs = [np.array([[1., 2.], [7., 8.]]).astype(np.float32),\n np.array([[3., 4., 5., 6.], [9., 10., 11., 12.]]).astype(np.float32)]\n\nexpect(node, inputs=[input, split], outputs=[y for y in expected_outputs], name='test_split_variable_parts_2d')" + }, + { + "summary": "default_values", + "code": "input = np.array([1., 2., 3., 4., 5., 6.]).astype(np.float32)\n\n# If axis is not specified, split is applied on default axis 0\nnode = onnx.helper.make_node(\n 'Split',\n inputs=['input'],\n outputs=['output_1', 'output_2', 'output_3']\n)\n\nexpected_outputs = [np.array([1., 2.]).astype(np.float32), np.array([3., 4.]).astype(np.float32), np.array([5., 6.]).astype(np.float32)]\nexpect(node, inputs=[input], outputs=[y for y in expected_outputs], name='test_split_equal_parts_default_axis')\n\nsplit = np.array([2, 4]).astype(np.int64)\nnode = onnx.helper.make_node(\n 'Split',\n inputs=['input', 'split'],\n outputs=['output_1', 'output_2']\n)\n\nexpected_outputs = [np.array([1., 2.]).astype(np.float32), np.array([3., 4., 5., 6.]).astype(np.float32)]\nexpect(node, inputs=[input, split], outputs=[y for y in expected_outputs], name='test_split_variable_parts_default_axis')" + }, + { + "summary": "zero_size_splits", + "code": "input = np.array([]).astype(np.float32)\n\n# Split emtpy tensor to tensors of size zero\nsplit = np.array([0, 0, 0]).astype(np.int64)\nnode = onnx.helper.make_node(\n 'Split',\n inputs=['input', 'split'],\n outputs=['output_1', 'output_2', 'output_3']\n)\n\nexpected_outputs = [np.array([]).astype(np.float32), np.array([]).astype(np.float32), np.array([]).astype(np.float32)]\nexpect(node, inputs=[input, split], outputs=[y for y in expected_outputs], name='test_split_zero_size_splits')" + } + ], + "category": "Tensor" + }, + { + "name": "Split", + "module": "ai.onnx", + "version": 2, + "support_level": "common", + "description": "Split a tensor into a list of tensors, along the specified\n'axis'. Lengths of the parts can be specified using argument 'split'.\nOtherwise, the tensor is split to equal sized parts.\n", + "attributes": [ + { + "name": "axis", + "type": "int64", + "required": false, + "description": "Which axis to split on. " + }, + { + "name": "split", + "type": "int64[]", + "required": false, + "description": "length of each output" + } + ], + "inputs": [ + { + "name": "input", + "type": "T", + "description": "The tensor to split" + } + ], + "min_input": 1, + "max_input": 1, + "outputs": [ + { + "name": "outputs", + "type": "T", + "list": true, + "description": "One or more outputs forming list of tensors after splitting" + } + ], + "min_output": 1, + "max_output": 2147483647, + "outputs_range": "1 - ∞", + "type_constraints": [ + { + "description": "Constrain input and output types to all tensor types.", + "type_param_str": "T", + "allowed_type_strs": [ + "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)" + ] + } + ], + "examples": [ + { + "summary": "1d", + "code": "input = np.array([1., 2., 3., 4., 5., 6.]).astype(np.float32)\n\nnode = onnx.helper.make_node(\n 'Split',\n inputs=['input'],\n outputs=['output_1', 'output_2', 'output_3'],\n axis=0\n)\n\nexpected_outputs = [np.array([1., 2.]).astype(np.float32), np.array([3., 4.]).astype(np.float32), np.array([5., 6.]).astype(np.float32)]\nexpect(node, inputs=[input], outputs=[y for y in expected_outputs], name='test_split_equal_parts_1d')\n\nsplit = np.array([2, 4]).astype(np.int64)\nnode = onnx.helper.make_node(\n 'Split',\n inputs=['input', 'split'],\n outputs=['output_1', 'output_2'],\n axis=0,\n)\n\nexpected_outputs = [np.array([1., 2.]).astype(np.float32), np.array([3., 4., 5., 6.]).astype(np.float32)]\nexpect(node, inputs=[input, split], outputs=[y for y in expected_outputs], name='test_split_variable_parts_1d')" + }, + { + "summary": "2d", + "code": "input = np.array([[1., 2., 3., 4., 5., 6.],\n [7., 8., 9., 10., 11., 12.]]).astype(np.float32)\n\nnode = onnx.helper.make_node(\n 'Split',\n inputs=['input'],\n outputs=['output_1', 'output_2'],\n axis=1\n)\n\nexpected_outputs = [np.array([[1., 2., 3.], [7., 8., 9.]]).astype(np.float32),\n np.array([[4., 5., 6.], [10., 11., 12.]]).astype(np.float32)]\n\nexpect(node, inputs=[input], outputs=[y for y in expected_outputs], name='test_split_equal_parts_2d')\n\nsplit = np.array([2, 4]).astype(np.int64)\nnode = onnx.helper.make_node(\n 'Split',\n inputs=['input', 'split'],\n outputs=['output_1', 'output_2'],\n axis=1,\n)\n\nexpected_outputs = [np.array([[1., 2.], [7., 8.]]).astype(np.float32),\n np.array([[3., 4., 5., 6.], [9., 10., 11., 12.]]).astype(np.float32)]\n\nexpect(node, inputs=[input, split], outputs=[y for y in expected_outputs], name='test_split_variable_parts_2d')" + }, + { + "summary": "default_values", + "code": "input = np.array([1., 2., 3., 4., 5., 6.]).astype(np.float32)\n\n# If axis is not specified, split is applied on default axis 0\nnode = onnx.helper.make_node(\n 'Split',\n inputs=['input'],\n outputs=['output_1', 'output_2', 'output_3']\n)\n\nexpected_outputs = [np.array([1., 2.]).astype(np.float32), np.array([3., 4.]).astype(np.float32), np.array([5., 6.]).astype(np.float32)]\nexpect(node, inputs=[input], outputs=[y for y in expected_outputs], name='test_split_equal_parts_default_axis')\n\nsplit = np.array([2, 4]).astype(np.int64)\nnode = onnx.helper.make_node(\n 'Split',\n inputs=['input', 'split'],\n outputs=['output_1', 'output_2']\n)\n\nexpected_outputs = [np.array([1., 2.]).astype(np.float32), np.array([3., 4., 5., 6.]).astype(np.float32)]\nexpect(node, inputs=[input, split], outputs=[y for y in expected_outputs], name='test_split_variable_parts_default_axis')" + }, + { + "summary": "zero_size_splits", + "code": "input = np.array([]).astype(np.float32)\n\n# Split emtpy tensor to tensors of size zero\nsplit = np.array([0, 0, 0]).astype(np.int64)\nnode = onnx.helper.make_node(\n 'Split',\n inputs=['input', 'split'],\n outputs=['output_1', 'output_2', 'output_3']\n)\n\nexpected_outputs = [np.array([]).astype(np.float32), np.array([]).astype(np.float32), np.array([]).astype(np.float32)]\nexpect(node, inputs=[input, split], outputs=[y for y in expected_outputs], name='test_split_zero_size_splits')" + } + ], + "category": "Tensor" + }, + { + "name": "Split", + "module": "ai.onnx", + "version": 11, + "support_level": "common", + "description": "Split a tensor into a list of tensors, along the specified\n'axis'. Lengths of the parts can be specified using argument 'split'.\nOtherwise, the tensor is split to equal sized parts.\n", + "attributes": [ + { + "name": "axis", + "type": "int64", + "required": false, + "description": "Which axis to split on. A negative value means counting dimensions from the back. Accepted range is [-rank, rank-1] where r = rank(input)." + }, + { + "name": "split", + "type": "int64[]", + "required": false, + "description": "length of each output. Values should be >= 0." + } + ], + "inputs": [ + { + "name": "input", + "type": "T", + "description": "The tensor to split" + } + ], + "min_input": 1, + "max_input": 1, + "outputs": [ + { + "name": "outputs", + "type": "T", + "list": true, + "description": "One or more outputs forming list of tensors after splitting" + } + ], + "min_output": 1, + "max_output": 2147483647, + "outputs_range": "1 - ∞", + "type_constraints": [ + { + "description": "Constrain input and output types to all tensor types.", + "type_param_str": "T", + "allowed_type_strs": [ + "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)" + ] + } + ], + "examples": [ + { + "summary": "1d", + "code": "input = np.array([1., 2., 3., 4., 5., 6.]).astype(np.float32)\n\nnode = onnx.helper.make_node(\n 'Split',\n inputs=['input'],\n outputs=['output_1', 'output_2', 'output_3'],\n axis=0\n)\n\nexpected_outputs = [np.array([1., 2.]).astype(np.float32), np.array([3., 4.]).astype(np.float32), np.array([5., 6.]).astype(np.float32)]\nexpect(node, inputs=[input], outputs=[y for y in expected_outputs], name='test_split_equal_parts_1d')\n\nsplit = np.array([2, 4]).astype(np.int64)\nnode = onnx.helper.make_node(\n 'Split',\n inputs=['input', 'split'],\n outputs=['output_1', 'output_2'],\n axis=0,\n)\n\nexpected_outputs = [np.array([1., 2.]).astype(np.float32), np.array([3., 4., 5., 6.]).astype(np.float32)]\nexpect(node, inputs=[input, split], outputs=[y for y in expected_outputs], name='test_split_variable_parts_1d')" + }, + { + "summary": "2d", + "code": "input = np.array([[1., 2., 3., 4., 5., 6.],\n [7., 8., 9., 10., 11., 12.]]).astype(np.float32)\n\nnode = onnx.helper.make_node(\n 'Split',\n inputs=['input'],\n outputs=['output_1', 'output_2'],\n axis=1\n)\n\nexpected_outputs = [np.array([[1., 2., 3.], [7., 8., 9.]]).astype(np.float32),\n np.array([[4., 5., 6.], [10., 11., 12.]]).astype(np.float32)]\n\nexpect(node, inputs=[input], outputs=[y for y in expected_outputs], name='test_split_equal_parts_2d')\n\nsplit = np.array([2, 4]).astype(np.int64)\nnode = onnx.helper.make_node(\n 'Split',\n inputs=['input', 'split'],\n outputs=['output_1', 'output_2'],\n axis=1,\n)\n\nexpected_outputs = [np.array([[1., 2.], [7., 8.]]).astype(np.float32),\n np.array([[3., 4., 5., 6.], [9., 10., 11., 12.]]).astype(np.float32)]\n\nexpect(node, inputs=[input, split], outputs=[y for y in expected_outputs], name='test_split_variable_parts_2d')" + }, + { + "summary": "default_values", + "code": "input = np.array([1., 2., 3., 4., 5., 6.]).astype(np.float32)\n\n# If axis is not specified, split is applied on default axis 0\nnode = onnx.helper.make_node(\n 'Split',\n inputs=['input'],\n outputs=['output_1', 'output_2', 'output_3']\n)\n\nexpected_outputs = [np.array([1., 2.]).astype(np.float32), np.array([3., 4.]).astype(np.float32), np.array([5., 6.]).astype(np.float32)]\nexpect(node, inputs=[input], outputs=[y for y in expected_outputs], name='test_split_equal_parts_default_axis')\n\nsplit = np.array([2, 4]).astype(np.int64)\nnode = onnx.helper.make_node(\n 'Split',\n inputs=['input', 'split'],\n outputs=['output_1', 'output_2']\n)\n\nexpected_outputs = [np.array([1., 2.]).astype(np.float32), np.array([3., 4., 5., 6.]).astype(np.float32)]\nexpect(node, inputs=[input, split], outputs=[y for y in expected_outputs], name='test_split_variable_parts_default_axis')" + }, + { + "summary": "zero_size_splits", + "code": "input = np.array([]).astype(np.float32)\n\n# Split emtpy tensor to tensors of size zero\nsplit = np.array([0, 0, 0]).astype(np.int64)\nnode = onnx.helper.make_node(\n 'Split',\n inputs=['input', 'split'],\n outputs=['output_1', 'output_2', 'output_3']\n)\n\nexpected_outputs = [np.array([]).astype(np.float32), np.array([]).astype(np.float32), np.array([]).astype(np.float32)]\nexpect(node, inputs=[input, split], outputs=[y for y in expected_outputs], name='test_split_zero_size_splits')" + } + ], + "category": "Tensor" + }, + { + "name": "Split", + "module": "ai.onnx", + "version": 13, + "support_level": "common", + "description": "Split a tensor into a list of tensors, along the specified\n'axis'. Lengths of the parts can be specified using input 'split'.\nOtherwise, the tensor is split to equal sized parts.\n", + "attributes": [ + { + "name": "axis", + "type": "int64", + "required": false, + "description": "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": [ + { + "name": "input", + "type": "T", + "description": "The tensor to split" + }, + { + "name": "split", + "type": "tensor(int64)", + "option": "optional", + "description": "Optional length of each output. Values should be >= 0.Sum of the values must be equal to the dim value at 'axis' specified." + } + ], + "min_input": 1, + "max_input": 2, + "outputs": [ + { + "name": "outputs", + "type": "T", + "list": true, + "description": "One or more outputs forming list of tensors after splitting" + } + ], + "min_output": 1, + "max_output": 2147483647, + "inputs_range": "1 - 2", + "outputs_range": "1 - ∞", + "type_constraints": [ + { + "description": "Constrain input and output types to all tensor types.", + "type_param_str": "T", + "allowed_type_strs": [ + "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)" + ] + } + ], + "examples": [ + { + "summary": "1d", + "code": "input = np.array([1., 2., 3., 4., 5., 6.]).astype(np.float32)\n\nnode = onnx.helper.make_node(\n 'Split',\n inputs=['input'],\n outputs=['output_1', 'output_2', 'output_3'],\n axis=0\n)\n\nexpected_outputs = [np.array([1., 2.]).astype(np.float32), np.array([3., 4.]).astype(np.float32), np.array([5., 6.]).astype(np.float32)]\nexpect(node, inputs=[input], outputs=[y for y in expected_outputs], name='test_split_equal_parts_1d')\n\nsplit = np.array([2, 4]).astype(np.int64)\nnode = onnx.helper.make_node(\n 'Split',\n inputs=['input', 'split'],\n outputs=['output_1', 'output_2'],\n axis=0,\n)\n\nexpected_outputs = [np.array([1., 2.]).astype(np.float32), np.array([3., 4., 5., 6.]).astype(np.float32)]\nexpect(node, inputs=[input, split], outputs=[y for y in expected_outputs], name='test_split_variable_parts_1d')" + }, + { + "summary": "2d", + "code": "input = np.array([[1., 2., 3., 4., 5., 6.],\n [7., 8., 9., 10., 11., 12.]]).astype(np.float32)\n\nnode = onnx.helper.make_node(\n 'Split',\n inputs=['input'],\n outputs=['output_1', 'output_2'],\n axis=1\n)\n\nexpected_outputs = [np.array([[1., 2., 3.], [7., 8., 9.]]).astype(np.float32),\n np.array([[4., 5., 6.], [10., 11., 12.]]).astype(np.float32)]\n\nexpect(node, inputs=[input], outputs=[y for y in expected_outputs], name='test_split_equal_parts_2d')\n\nsplit = np.array([2, 4]).astype(np.int64)\nnode = onnx.helper.make_node(\n 'Split',\n inputs=['input', 'split'],\n outputs=['output_1', 'output_2'],\n axis=1,\n)\n\nexpected_outputs = [np.array([[1., 2.], [7., 8.]]).astype(np.float32),\n np.array([[3., 4., 5., 6.], [9., 10., 11., 12.]]).astype(np.float32)]\n\nexpect(node, inputs=[input, split], outputs=[y for y in expected_outputs], name='test_split_variable_parts_2d')" + }, + { + "summary": "default_values", + "code": "input = np.array([1., 2., 3., 4., 5., 6.]).astype(np.float32)\n\n# If axis is not specified, split is applied on default axis 0\nnode = onnx.helper.make_node(\n 'Split',\n inputs=['input'],\n outputs=['output_1', 'output_2', 'output_3']\n)\n\nexpected_outputs = [np.array([1., 2.]).astype(np.float32), np.array([3., 4.]).astype(np.float32), np.array([5., 6.]).astype(np.float32)]\nexpect(node, inputs=[input], outputs=[y for y in expected_outputs], name='test_split_equal_parts_default_axis')\n\nsplit = np.array([2, 4]).astype(np.int64)\nnode = onnx.helper.make_node(\n 'Split',\n inputs=['input', 'split'],\n outputs=['output_1', 'output_2']\n)\n\nexpected_outputs = [np.array([1., 2.]).astype(np.float32), np.array([3., 4., 5., 6.]).astype(np.float32)]\nexpect(node, inputs=[input, split], outputs=[y for y in expected_outputs], name='test_split_variable_parts_default_axis')" + }, + { + "summary": "zero_size_splits", + "code": "input = np.array([]).astype(np.float32)\n\n# Split emtpy tensor to tensors of size zero\nsplit = np.array([0, 0, 0]).astype(np.int64)\nnode = onnx.helper.make_node(\n 'Split',\n inputs=['input', 'split'],\n outputs=['output_1', 'output_2', 'output_3']\n)\n\nexpected_outputs = [np.array([]).astype(np.float32), np.array([]).astype(np.float32), np.array([]).astype(np.float32)]\nexpect(node, inputs=[input, split], outputs=[y for y in expected_outputs], name='test_split_zero_size_splits')" + } + ], + "category": "Tensor" + }, + { + "name": "SplitToSequence", + "module": "ai.onnx", + "version": 11, + "support_level": "common", + "description": "Split a tensor into a sequence of tensors, along the specified\n'axis'. Lengths of the parts can be specified using argument 'split'.\n'split' must contain only positive numbers.\n'split' is either a scalar (tensor of empty shape), or a 1-D tensor.\nIf 'split' is a scalar, then 'input' will be split into equally sized chunks(if possible).\nLast chunk will be smaller if the 'input' size along the given axis 'axis' is not divisible\nby 'split'.\nOtherwise, the tensor is split into 'size(split)' chunks, with lengths of the parts on 'axis'\nspecified in 'split'. In this scenario, the sum of entries in 'split' must be equal to the\ndimension size of input tensor on 'axis'.\n", + "attributes": [ + { + "name": "axis", + "type": "int64", + "required": false, + "description": "Which axis to split on. A negative value means counting dimensions from the back. Accepted range is [-rank, rank-1]." + }, + { + "name": "keepdims", + "type": "int64", + "required": false, + "default": 1, + "description": "Keep the split dimension or not. Default 1, which means we keep split dimension. If input 'split' is specified, this attribute is ignored." + } + ], + "inputs": [ + { + "name": "input", + "type": "T", + "description": "The tensor to split" + }, + { + "name": "split", + "type": "I", + "option": "optional", + "description": "Length of each output. It can be either a scalar(tensor of empty shape), or a 1-D tensor. All values must be >= 0. " + } + ], + "min_input": 1, + "max_input": 2, + "outputs": [ + { + "name": "output_sequence", + "type": "S", + "description": "One or more outputs forming a sequence of tensors after splitting" + } + ], + "min_output": 1, + "max_output": 1, + "inputs_range": "1 - 2", + "type_constraints": [ + { + "description": "Constrain input types to all tensor types.", + "type_param_str": "T", + "allowed_type_strs": [ + "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)" + ] + }, + { + "description": "Constrain split size to integral tensor.", + "type_param_str": "I", + "allowed_type_strs": [ + "tensor(int32)", + "tensor(int64)" + ] + }, + { + "description": "Constrain output types to all tensor types.", + "type_param_str": "S", + "allowed_type_strs": [ + "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))" + ] + } + ] + }, + { + "name": "Sqrt", + "module": "ai.onnx", + "version": 1, + "support_level": "common", + "description": "Square root takes one input data (Tensor) and produces one output data\n(Tensor) where the square root is, y = x^0.5, is applied to\nthe tensor elementwise. If x is negative, then it will return NaN.\n", + "attributes": [ + { + "name": "consumed_inputs", + "type": "int64[]", + "required": false, + "description": "legacy optimization attribute." + } + ], + "inputs": [ + { + "name": "X", + "type": "T", + "description": "Input tensor" + } + ], + "min_input": 1, + "max_input": 1, + "outputs": [ + { + "name": "Y", + "type": "T", + "description": "Output tensor" + } + ], + "min_output": 1, + "max_output": 1, + "type_constraints": [ + { + "description": "Constrain input and output types to float tensors.", + "type_param_str": "T", + "allowed_type_strs": [ + "tensor(float16)", + "tensor(float)", + "tensor(double)" + ] + } + ], + "examples": [ + { + "summary": "sqrt", + "code": "node = onnx.helper.make_node(\n 'Sqrt',\n inputs=['x'],\n outputs=['y'],\n)\n\nx = np.array([1, 4, 9]).astype(np.float32)\ny = np.sqrt(x) # expected output [1., 2., 3.]\nexpect(node, inputs=[x], outputs=[y],\n name='test_sqrt_example')\n\nx = np.abs(np.random.randn(3, 4, 5).astype(np.float32))\ny = np.sqrt(x)\nexpect(node, inputs=[x], outputs=[y],\n name='test_sqrt')" + } + ] + }, + { + "name": "Sqrt", + "module": "ai.onnx", + "version": 6, + "support_level": "common", + "description": "Square root takes one input data (Tensor) and produces one output data\n(Tensor) where the square root is, y = x^0.5, is applied to\nthe tensor elementwise. If x is negative, then it will return NaN.\n", + "inputs": [ + { + "name": "X", + "type": "T", + "description": "Input tensor" + } + ], + "min_input": 1, + "max_input": 1, + "outputs": [ + { + "name": "Y", + "type": "T", + "description": "Output tensor" + } + ], + "min_output": 1, + "max_output": 1, + "type_constraints": [ + { + "description": "Constrain input and output types to float tensors.", + "type_param_str": "T", + "allowed_type_strs": [ + "tensor(float16)", + "tensor(float)", + "tensor(double)" + ] + } + ], + "examples": [ + { + "summary": "sqrt", + "code": "node = onnx.helper.make_node(\n 'Sqrt',\n inputs=['x'],\n outputs=['y'],\n)\n\nx = np.array([1, 4, 9]).astype(np.float32)\ny = np.sqrt(x) # expected output [1., 2., 3.]\nexpect(node, inputs=[x], outputs=[y],\n name='test_sqrt_example')\n\nx = np.abs(np.random.randn(3, 4, 5).astype(np.float32))\ny = np.sqrt(x)\nexpect(node, inputs=[x], outputs=[y],\n name='test_sqrt')" + } + ] + }, + { + "name": "Sqrt", + "module": "ai.onnx", + "version": 13, + "support_level": "common", + "description": "Square root takes one input data (Tensor) and produces one output data\n(Tensor) where the square root is, y = x^0.5, is applied to\nthe tensor elementwise. If x is negative, then it will return NaN.\n", + "inputs": [ + { + "name": "X", + "type": "T", + "description": "Input tensor" + } + ], + "min_input": 1, + "max_input": 1, + "outputs": [ + { + "name": "Y", + "type": "T", + "description": "Output tensor" + } + ], + "min_output": 1, + "max_output": 1, + "type_constraints": [ + { + "description": "Constrain input and output types to float tensors.", + "type_param_str": "T", + "allowed_type_strs": [ + "tensor(float16)", + "tensor(float)", + "tensor(double)", + "tensor(bfloat16)" + ] + } + ], + "examples": [ + { + "summary": "sqrt", + "code": "node = onnx.helper.make_node(\n 'Sqrt',\n inputs=['x'],\n outputs=['y'],\n)\n\nx = np.array([1, 4, 9]).astype(np.float32)\ny = np.sqrt(x) # expected output [1., 2., 3.]\nexpect(node, inputs=[x], outputs=[y],\n name='test_sqrt_example')\n\nx = np.abs(np.random.randn(3, 4, 5).astype(np.float32))\ny = np.sqrt(x)\nexpect(node, inputs=[x], outputs=[y],\n name='test_sqrt')" + } + ] + }, + { + "name": "Squeeze", + "module": "ai.onnx", + "version": 1, + "support_level": "common", + "description": "Remove single-dimensional entries from the shape of a tensor.\nTakes a parameter `axes` with a list of axes to squeeze.\nIf `axes` is not provided, all the single dimensions will be removed from\nthe shape. If an axis is selected with shape entry not equal to one, an error is raised.\n", + "attributes": [ + { + "name": "axes", + "type": "int64[]", + "required": false, + "description": "List of non-negative integers, indicate the dimensions to squeeze." + } + ], + "inputs": [ + { + "name": "data", + "type": "T", + "description": "Tensors with at least max(dims) dimensions." + } + ], + "min_input": 1, + "max_input": 1, + "outputs": [ + { + "name": "squeezed", + "type": "T", + "description": "Reshaped tensor with same data as input." + } + ], + "min_output": 1, + "max_output": 1, + "type_constraints": [ + { + "description": "Constrain input and output types to all tensor types.", + "type_param_str": "T", + "allowed_type_strs": [ + "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)" + ] + } + ], + "examples": [ + { + "summary": "squeeze", + "code": "node = onnx.helper.make_node(\n 'Squeeze',\n inputs=['x', 'axes'],\n outputs=['y'],\n)\nx = np.random.randn(1, 3, 4, 5).astype(np.float32)\naxes = np.array([0], dtype=np.int64)\ny = np.squeeze(x, axis=0)\n\nexpect(node, inputs=[x, axes], outputs=[y],\n name='test_squeeze')" + }, + { + "summary": "squeeze_negative_axes", + "code": "node = onnx.helper.make_node(\n 'Squeeze',\n inputs=['x', 'axes'],\n outputs=['y'],\n)\nx = np.random.randn(1, 3, 1, 5).astype(np.float32)\naxes = np.array([-2], dtype=np.int64)\ny = np.squeeze(x, axis=-2)\nexpect(node, inputs=[x, axes], outputs=[y],\n name='test_squeeze_negative_axes')" + } + ], + "category": "Transform" + }, + { + "name": "Squeeze", + "module": "ai.onnx", + "version": 11, + "support_level": "common", + "description": "Remove single-dimensional entries from the shape of a tensor.\nTakes a parameter `axes` with a list of axes to squeeze.\nIf `axes` is not provided, all the single dimensions will be removed from\nthe shape. If an axis is selected with shape entry not equal to one, an error is raised.\n", + "attributes": [ + { + "name": "axes", + "type": "int64[]", + "required": false, + "description": "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": [ + { + "name": "data", + "type": "T", + "description": "Tensors with at least max(dims) dimensions." + } + ], + "min_input": 1, + "max_input": 1, + "outputs": [ + { + "name": "squeezed", + "type": "T", + "description": "Reshaped tensor with same data as input." + } + ], + "min_output": 1, + "max_output": 1, + "type_constraints": [ + { + "description": "Constrain input and output types to all tensor types.", + "type_param_str": "T", + "allowed_type_strs": [ + "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)" + ] + } + ], + "examples": [ + { + "summary": "squeeze", + "code": "node = onnx.helper.make_node(\n 'Squeeze',\n inputs=['x', 'axes'],\n outputs=['y'],\n)\nx = np.random.randn(1, 3, 4, 5).astype(np.float32)\naxes = np.array([0], dtype=np.int64)\ny = np.squeeze(x, axis=0)\n\nexpect(node, inputs=[x, axes], outputs=[y],\n name='test_squeeze')" + }, + { + "summary": "squeeze_negative_axes", + "code": "node = onnx.helper.make_node(\n 'Squeeze',\n inputs=['x', 'axes'],\n outputs=['y'],\n)\nx = np.random.randn(1, 3, 1, 5).astype(np.float32)\naxes = np.array([-2], dtype=np.int64)\ny = np.squeeze(x, axis=-2)\nexpect(node, inputs=[x, axes], outputs=[y],\n name='test_squeeze_negative_axes')" + } + ], + "category": "Transform" + }, + { + "name": "Squeeze", + "module": "ai.onnx", + "version": 13, + "support_level": "common", + "description": "Remove single-dimensional entries from the shape of a tensor.\nTakes an input `axes` with a list of axes to squeeze.\nIf `axes` is not provided, all the single dimensions will be removed from\nthe shape. If an axis is selected with shape entry not equal to one, an error is raised.\n", + "inputs": [ + { + "name": "data", + "type": "T", + "description": "Tensors with at least max(dims) dimensions." + }, + { + "name": "axes", + "type": "tensor(int64)", + "option": "optional", + "description": "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)." + } + ], + "min_input": 1, + "max_input": 2, + "outputs": [ + { + "name": "squeezed", + "type": "T", + "description": "Reshaped tensor with same data as input." + } + ], + "min_output": 1, + "max_output": 1, + "inputs_range": "1 - 2", + "type_constraints": [ + { + "description": "Constrain input and output types to all tensor types.", + "type_param_str": "T", + "allowed_type_strs": [ + "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)" + ] + } + ], + "examples": [ + { + "summary": "squeeze", + "code": "node = onnx.helper.make_node(\n 'Squeeze',\n inputs=['x', 'axes'],\n outputs=['y'],\n)\nx = np.random.randn(1, 3, 4, 5).astype(np.float32)\naxes = np.array([0], dtype=np.int64)\ny = np.squeeze(x, axis=0)\n\nexpect(node, inputs=[x, axes], outputs=[y],\n name='test_squeeze')" + }, + { + "summary": "squeeze_negative_axes", + "code": "node = onnx.helper.make_node(\n 'Squeeze',\n inputs=['x', 'axes'],\n outputs=['y'],\n)\nx = np.random.randn(1, 3, 1, 5).astype(np.float32)\naxes = np.array([-2], dtype=np.int64)\ny = np.squeeze(x, axis=-2)\nexpect(node, inputs=[x, axes], outputs=[y],\n name='test_squeeze_negative_axes')" + } + ], + "category": "Transform" + }, + { + "name": "StringNormalizer", + "module": "ai.onnx", + "version": 10, + "support_level": "common", + "description": "StringNormalization performs string operations for basic cleaning.\nThis operator has only one input (denoted by X) and only one output\n(denoted by Y). This operator first examines the elements in the X,\nand removes elements specified in \"stopwords\" attribute.\nAfter removing stop words, the intermediate result can be further lowercased,\nuppercased, or just returned depending the \"case_change_action\" attribute.\nThis operator only accepts [C]- and [1, C]-tensor.\nIf all elements in X are dropped, the output will be the empty value of string tensor with shape [1]\nif input shape is [C] and shape [1, 1] if input shape is [1, C].\n", + "attributes": [ + { + "name": "case_change_action", + "type": "string", + "required": false, + "default": "NONE", + "description": "string enum that cases output to be lowercased/uppercases/unchanged. Valid values are \"LOWER\", \"UPPER\", \"NONE\". Default is \"NONE\"" + }, + { + "name": "is_case_sensitive", + "type": "int64", + "required": false, + "description": "Boolean. Whether the identification of stop words in X is case-sensitive. Default is false" + }, + { + "name": "locale", + "type": "string", + "required": false, + "description": "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." + }, + { + "name": "stopwords", + "type": "string[]", + "required": false, + "description": "List of stop words. If not set, no word would be removed from X." + } + ], + "inputs": [ + { + "name": "X", + "type": "tensor(string)", + "description": "UTF-8 strings to normalize" + } + ], + "min_input": 1, + "max_input": 1, + "outputs": [ + { + "name": "Y", + "type": "tensor(string)", + "description": "UTF-8 Normalized strings" + } + ], + "min_output": 1, + "max_output": 1, + "examples": [ + { + "summary": "monday_casesensintive_lower", + "code": "input = np.array([u'monday', u'tuesday', u'wednesday', u'thursday']).astype(object)\noutput = np.array([u'tuesday', u'wednesday', u'thursday']).astype(object)\nstopwords = [u'monday']\n\nnode = onnx.helper.make_node(\n 'StringNormalizer',\n inputs=['x'],\n outputs=['y'],\n case_change_action='LOWER',\n is_case_sensitive=1,\n stopwords=stopwords\n)\nexpect(node, inputs=[input], outputs=[output], name='test_strnormalizer_export_monday_casesensintive_lower')" + }, + { + "summary": "monday_casesensintive_nochangecase", + "code": "input = np.array([u'monday', u'tuesday', u'wednesday', u'thursday']).astype(object)\noutput = np.array([u'tuesday', u'wednesday', u'thursday']).astype(object)\nstopwords = [u'monday']\n\nnode = onnx.helper.make_node(\n 'StringNormalizer',\n inputs=['x'],\n outputs=['y'],\n is_case_sensitive=1,\n stopwords=stopwords\n)\nexpect(node, inputs=[input], outputs=[output], name='test_strnormalizer_export_monday_casesensintive_nochangecase')" + }, + { + "summary": "monday_casesensintive_upper", + "code": "input = np.array([u'monday', u'tuesday', u'wednesday', u'thursday']).astype(object)\noutput = np.array([u'TUESDAY', u'WEDNESDAY', u'THURSDAY']).astype(object)\nstopwords = [u'monday']\n\nnode = onnx.helper.make_node(\n 'StringNormalizer',\n inputs=['x'],\n outputs=['y'],\n case_change_action='UPPER',\n is_case_sensitive=1,\n stopwords=stopwords\n)\nexpect(node, inputs=[input], outputs=[output], name='test_strnormalizer_export_monday_casesensintive_upper')" + }, + { + "summary": "monday_empty_output", + "code": "input = np.array([u'monday', u'monday']).astype(object)\noutput = np.array([u'']).astype(object)\nstopwords = [u'monday']\n\nnode = onnx.helper.make_node(\n 'StringNormalizer',\n inputs=['x'],\n outputs=['y'],\n case_change_action='UPPER',\n is_case_sensitive=1,\n stopwords=stopwords\n)\nexpect(node, inputs=[input], outputs=[output], name='test_strnormalizer_export_monday_empty_output')" + }, + { + "summary": "monday_insensintive_upper_twodim", + "code": "input = np.array([u'Monday', u'tuesday', u'wednesday', u'Monday', u'tuesday', u'wednesday']).astype(object).reshape([1, 6])\n\n# It does upper case cecedille, accented E\n# and german umlaut but fails\n# with german eszett\noutput = np.array([u'TUESDAY', u'WEDNESDAY', u'TUESDAY', u'WEDNESDAY']).astype(object).reshape([1, 4])\nstopwords = [u'monday']\n\nnode = onnx.helper.make_node(\n 'StringNormalizer',\n inputs=['x'],\n outputs=['y'],\n case_change_action='UPPER',\n stopwords=stopwords\n)\nexpect(node, inputs=[input], outputs=[output], name='test_strnormalizer_export_monday_insensintive_upper_twodim')" + }, + { + "summary": "nostopwords_nochangecase", + "code": "input = np.array([u'monday', u'tuesday']).astype(object)\noutput = input\n\n# No stopwords. This is a NOOP\nnode = onnx.helper.make_node(\n 'StringNormalizer',\n inputs=['x'],\n outputs=['y'],\n is_case_sensitive=1,\n)\nexpect(node, inputs=[input], outputs=[output], name='test_strnormalizer_nostopwords_nochangecase')" + } + ] + }, + { + "name": "Sub", + "module": "ai.onnx", + "version": 1, + "support_level": "common", + "description": "Performs element-wise binary subtraction (with limited broadcast support).\n\nIf necessary the right-hand-side argument will be broadcasted to match the\nshape of left-hand-side argument. When broadcasting is specified, the second\ntensor can either be of element size 1 (including a scalar tensor and any\ntensor with rank equal to or smaller than the first tensor), or having its\nshape as a contiguous subset of the first tensor's shape. The starting of the\nmutually equal shape is specified by the argument \"axis\", and if it is not set,\nsuffix matching is assumed. 1-dim expansion doesn't work yet.\n\nFor example, the following tensor shapes are supported (with broadcast=1):\n\n shape(A) = (2, 3, 4, 5), shape(B) = (,), i.e. B is a scalar tensor\n shape(A) = (2, 3, 4, 5), shape(B) = (1, 1), i.e. B is an 1-element tensor\n shape(A) = (2, 3, 4, 5), shape(B) = (5,)\n shape(A) = (2, 3, 4, 5), shape(B) = (4, 5)\n shape(A) = (2, 3, 4, 5), shape(B) = (3, 4), with axis=1\n shape(A) = (2, 3, 4, 5), shape(B) = (2), with axis=0\n\nAttribute `broadcast=1` needs to be passed to enable broadcasting.\n", + "attributes": [ + { + "name": "axis", + "type": "int64", + "required": false, + "description": "If set, defines the broadcast dimensions. See doc for details." + }, + { + "name": "broadcast", + "type": "int64", + "required": false, + "description": "Pass 1 to enable broadcasting" + }, + { + "name": "consumed_inputs", + "type": "int64[]", + "required": false, + "description": "legacy optimization attribute." + } + ], + "inputs": [ + { + "name": "A", + "type": "T", + "description": "First operand, should share the type with the second operand." + }, + { + "name": "B", + "type": "T", + "description": "Second operand. With broadcasting can be of smaller size than A. If broadcasting is disabled it should be of the same size." + } + ], + "min_input": 2, + "max_input": 2, + "outputs": [ + { + "name": "C", + "type": "T", + "description": "Result, has same dimensions and type as A" + } + ], + "min_output": 1, + "max_output": 1, + "type_constraints": [ + { + "description": "Constrain input and output types to float tensors.", + "type_param_str": "T", + "allowed_type_strs": [ + "tensor(float16)", + "tensor(float)", + "tensor(double)" + ] + } + ], + "examples": [ + { + "summary": "sub", + "code": "node = onnx.helper.make_node(\n 'Sub',\n inputs=['x', 'y'],\n outputs=['z'],\n)\n\nx = np.array([1, 2, 3]).astype(np.float32)\ny = np.array([3, 2, 1]).astype(np.float32)\nz = x - y # expected output [-2., 0., 2.]\nexpect(node, inputs=[x, y], outputs=[z],\n name='test_sub_example')\n\nx = np.random.randn(3, 4, 5).astype(np.float32)\ny = np.random.randn(3, 4, 5).astype(np.float32)\nz = x - y\nexpect(node, inputs=[x, y], outputs=[z],\n name='test_sub')\n\nx = np.random.randint(12, 24, size=(3, 4, 5), dtype=np.uint8)\ny = np.random.randint(12, size=(3, 4, 5), dtype=np.uint8)\nz = x - y\nexpect(node, inputs=[x, y], outputs=[z],\n name='test_sub_uint8')" + }, + { + "summary": "sub_broadcast", + "code": "node = onnx.helper.make_node(\n 'Sub',\n inputs=['x', 'y'],\n outputs=['z'],\n)\n\nx = np.random.randn(3, 4, 5).astype(np.float32)\ny = np.random.randn(5).astype(np.float32)\nz = x - y\nexpect(node, inputs=[x, y], outputs=[z],\n name='test_sub_bcast')" + } + ] + }, + { + "name": "Sub", + "module": "ai.onnx", + "version": 6, + "support_level": "common", + "description": "Performs element-wise binary subtraction (with limited broadcast support).\n\nIf necessary the right-hand-side argument will be broadcasted to match the\nshape of left-hand-side argument. When broadcasting is specified, the second\ntensor can either be of element size 1 (including a scalar tensor and any\ntensor with rank equal to or smaller than the first tensor), or having its\nshape as a contiguous subset of the first tensor's shape. The starting of the\nmutually equal shape is specified by the argument \"axis\", and if it is not set,\nsuffix matching is assumed. 1-dim expansion doesn't work yet.\n\nFor example, the following tensor shapes are supported (with broadcast=1):\n\n shape(A) = (2, 3, 4, 5), shape(B) = (,), i.e. B is a scalar tensor\n shape(A) = (2, 3, 4, 5), shape(B) = (1, 1), i.e. B is an 1-element tensor\n shape(A) = (2, 3, 4, 5), shape(B) = (5,)\n shape(A) = (2, 3, 4, 5), shape(B) = (4, 5)\n shape(A) = (2, 3, 4, 5), shape(B) = (3, 4), with axis=1\n shape(A) = (2, 3, 4, 5), shape(B) = (2), with axis=0\n\nAttribute `broadcast=1` needs to be passed to enable broadcasting.\n", + "attributes": [ + { + "name": "axis", + "type": "int64", + "required": false, + "description": "If set, defines the broadcast dimensions. See doc for details." + }, + { + "name": "broadcast", + "type": "int64", + "required": false, + "description": "Pass 1 to enable broadcasting" + } + ], + "inputs": [ + { + "name": "A", + "type": "T", + "description": "First operand, should share the type with the second operand." + }, + { + "name": "B", + "type": "T", + "description": "Second operand. With broadcasting can be of smaller size than A. If broadcasting is disabled it should be of the same size." + } + ], + "min_input": 2, + "max_input": 2, + "outputs": [ + { + "name": "C", + "type": "T", + "description": "Result, has same dimensions and type as A" + } + ], + "min_output": 1, + "max_output": 1, + "type_constraints": [ + { + "description": "Constrain input and output types to high-precision numeric tensors.", + "type_param_str": "T", + "allowed_type_strs": [ + "tensor(uint32)", + "tensor(uint64)", + "tensor(int32)", + "tensor(int64)", + "tensor(float16)", + "tensor(float)", + "tensor(double)" + ] + } + ], + "examples": [ + { + "summary": "sub", + "code": "node = onnx.helper.make_node(\n 'Sub',\n inputs=['x', 'y'],\n outputs=['z'],\n)\n\nx = np.array([1, 2, 3]).astype(np.float32)\ny = np.array([3, 2, 1]).astype(np.float32)\nz = x - y # expected output [-2., 0., 2.]\nexpect(node, inputs=[x, y], outputs=[z],\n name='test_sub_example')\n\nx = np.random.randn(3, 4, 5).astype(np.float32)\ny = np.random.randn(3, 4, 5).astype(np.float32)\nz = x - y\nexpect(node, inputs=[x, y], outputs=[z],\n name='test_sub')\n\nx = np.random.randint(12, 24, size=(3, 4, 5), dtype=np.uint8)\ny = np.random.randint(12, size=(3, 4, 5), dtype=np.uint8)\nz = x - y\nexpect(node, inputs=[x, y], outputs=[z],\n name='test_sub_uint8')" + }, + { + "summary": "sub_broadcast", + "code": "node = onnx.helper.make_node(\n 'Sub',\n inputs=['x', 'y'],\n outputs=['z'],\n)\n\nx = np.random.randn(3, 4, 5).astype(np.float32)\ny = np.random.randn(5).astype(np.float32)\nz = x - y\nexpect(node, inputs=[x, y], outputs=[z],\n name='test_sub_bcast')" + } + ] + }, + { + "name": "Sub", + "module": "ai.onnx", + "version": 7, + "support_level": "common", + "description": "Performs element-wise binary subtraction (with Numpy-style broadcasting support).\n\nThis operator supports **multidirectional (i.e., Numpy-style) broadcasting**; for more details please check [the doc](https://github.com/onnx/onnx/blob/master/docs/Broadcasting.md).\n", + "inputs": [ + { + "name": "A", + "type": "T", + "description": "First operand." + }, + { + "name": "B", + "type": "T", + "description": "Second operand." + } + ], + "min_input": 2, + "max_input": 2, + "outputs": [ + { + "name": "C", + "type": "T", + "description": "Result, has same element type as two inputs" + } + ], + "min_output": 1, + "max_output": 1, + "type_constraints": [ + { + "description": "Constrain input and output types to high-precision numeric tensors.", + "type_param_str": "T", + "allowed_type_strs": [ + "tensor(uint32)", + "tensor(uint64)", + "tensor(int32)", + "tensor(int64)", + "tensor(float16)", + "tensor(float)", + "tensor(double)" + ] + } + ], + "examples": [ + { + "summary": "sub", + "code": "node = onnx.helper.make_node(\n 'Sub',\n inputs=['x', 'y'],\n outputs=['z'],\n)\n\nx = np.array([1, 2, 3]).astype(np.float32)\ny = np.array([3, 2, 1]).astype(np.float32)\nz = x - y # expected output [-2., 0., 2.]\nexpect(node, inputs=[x, y], outputs=[z],\n name='test_sub_example')\n\nx = np.random.randn(3, 4, 5).astype(np.float32)\ny = np.random.randn(3, 4, 5).astype(np.float32)\nz = x - y\nexpect(node, inputs=[x, y], outputs=[z],\n name='test_sub')\n\nx = np.random.randint(12, 24, size=(3, 4, 5), dtype=np.uint8)\ny = np.random.randint(12, size=(3, 4, 5), dtype=np.uint8)\nz = x - y\nexpect(node, inputs=[x, y], outputs=[z],\n name='test_sub_uint8')" + }, + { + "summary": "sub_broadcast", + "code": "node = onnx.helper.make_node(\n 'Sub',\n inputs=['x', 'y'],\n outputs=['z'],\n)\n\nx = np.random.randn(3, 4, 5).astype(np.float32)\ny = np.random.randn(5).astype(np.float32)\nz = x - y\nexpect(node, inputs=[x, y], outputs=[z],\n name='test_sub_bcast')" + } + ] + }, + { + "name": "Sub", + "module": "ai.onnx", + "version": 13, + "support_level": "common", + "description": "Performs element-wise binary subtraction (with Numpy-style broadcasting support).\n\nThis operator supports **multidirectional (i.e., Numpy-style) broadcasting**; for more details please check [the doc](https://github.com/onnx/onnx/blob/master/docs/Broadcasting.md).\n", + "inputs": [ + { + "name": "A", + "type": "T", + "description": "First operand." + }, + { + "name": "B", + "type": "T", + "description": "Second operand." + } + ], + "min_input": 2, + "max_input": 2, + "outputs": [ + { + "name": "C", + "type": "T", + "description": "Result, has same element type as two inputs" + } + ], + "min_output": 1, + "max_output": 1, + "type_constraints": [ + { + "description": "Constrain input and output types to high-precision numeric tensors.", + "type_param_str": "T", + "allowed_type_strs": [ + "tensor(uint32)", + "tensor(uint64)", + "tensor(int32)", + "tensor(int64)", + "tensor(float16)", + "tensor(float)", + "tensor(double)", + "tensor(bfloat16)" + ] + } + ], + "examples": [ + { + "summary": "sub", + "code": "node = onnx.helper.make_node(\n 'Sub',\n inputs=['x', 'y'],\n outputs=['z'],\n)\n\nx = np.array([1, 2, 3]).astype(np.float32)\ny = np.array([3, 2, 1]).astype(np.float32)\nz = x - y # expected output [-2., 0., 2.]\nexpect(node, inputs=[x, y], outputs=[z],\n name='test_sub_example')\n\nx = np.random.randn(3, 4, 5).astype(np.float32)\ny = np.random.randn(3, 4, 5).astype(np.float32)\nz = x - y\nexpect(node, inputs=[x, y], outputs=[z],\n name='test_sub')\n\nx = np.random.randint(12, 24, size=(3, 4, 5), dtype=np.uint8)\ny = np.random.randint(12, size=(3, 4, 5), dtype=np.uint8)\nz = x - y\nexpect(node, inputs=[x, y], outputs=[z],\n name='test_sub_uint8')" + }, + { + "summary": "sub_broadcast", + "code": "node = onnx.helper.make_node(\n 'Sub',\n inputs=['x', 'y'],\n outputs=['z'],\n)\n\nx = np.random.randn(3, 4, 5).astype(np.float32)\ny = np.random.randn(5).astype(np.float32)\nz = x - y\nexpect(node, inputs=[x, y], outputs=[z],\n name='test_sub_bcast')" + } + ] + }, + { + "name": "Sub", + "module": "ai.onnx", + "version": 14, + "support_level": "common", + "description": "Performs element-wise binary subtraction (with Numpy-style broadcasting support).\n\nThis operator supports **multidirectional (i.e., Numpy-style) broadcasting**; for more details please check [the doc](https://github.com/onnx/onnx/blob/master/docs/Broadcasting.md).\n\n(Opset 14 change): Extend supported types to include uint8, int8, uint16, and int16.\n", + "inputs": [ + { + "name": "A", + "type": "T", + "description": "First operand." + }, + { + "name": "B", + "type": "T", + "description": "Second operand." + } + ], + "min_input": 2, + "max_input": 2, + "outputs": [ + { + "name": "C", + "type": "T", + "description": "Result, has same element type as two inputs" + } + ], + "min_output": 1, + "max_output": 1, + "type_constraints": [ + { + "description": "Constrain input and output types to all numeric tensors.", + "type_param_str": "T", + "allowed_type_strs": [ + "tensor(uint8)", + "tensor(uint16)", + "tensor(uint32)", + "tensor(uint64)", + "tensor(int8)", + "tensor(int16)", + "tensor(int32)", + "tensor(int64)", + "tensor(float16)", + "tensor(float)", + "tensor(double)", + "tensor(bfloat16)" + ] + } + ], + "examples": [ + { + "summary": "sub", + "code": "node = onnx.helper.make_node(\n 'Sub',\n inputs=['x', 'y'],\n outputs=['z'],\n)\n\nx = np.array([1, 2, 3]).astype(np.float32)\ny = np.array([3, 2, 1]).astype(np.float32)\nz = x - y # expected output [-2., 0., 2.]\nexpect(node, inputs=[x, y], outputs=[z],\n name='test_sub_example')\n\nx = np.random.randn(3, 4, 5).astype(np.float32)\ny = np.random.randn(3, 4, 5).astype(np.float32)\nz = x - y\nexpect(node, inputs=[x, y], outputs=[z],\n name='test_sub')\n\nx = np.random.randint(12, 24, size=(3, 4, 5), dtype=np.uint8)\ny = np.random.randint(12, size=(3, 4, 5), dtype=np.uint8)\nz = x - y\nexpect(node, inputs=[x, y], outputs=[z],\n name='test_sub_uint8')" + }, + { + "summary": "sub_broadcast", + "code": "node = onnx.helper.make_node(\n 'Sub',\n inputs=['x', 'y'],\n outputs=['z'],\n)\n\nx = np.random.randn(3, 4, 5).astype(np.float32)\ny = np.random.randn(5).astype(np.float32)\nz = x - y\nexpect(node, inputs=[x, y], outputs=[z],\n name='test_sub_bcast')" + } + ] + }, + { + "name": "Sum", + "module": "ai.onnx", + "version": 1, + "support_level": "common", + "description": "Element-wise sum of each of the input tensors. All inputs and outputs must\nhave the same shape and data type.\n", + "attributes": [ + { + "name": "consumed_inputs", + "type": "int64[]", + "required": false, + "description": "legacy optimization attribute." + } + ], + "inputs": [ + { + "name": "data_0", + "type": "T", + "list": true, + "description": "List of tensors for Sum." + } + ], + "min_input": 1, + "max_input": 2147483647, + "outputs": [ + { + "name": "sum", + "type": "T", + "description": "Output tensor. Same dimension as inputs." + } + ], + "min_output": 1, + "max_output": 1, + "inputs_range": "1 - ∞", + "type_constraints": [ + { + "description": "Constrain input and output types to float tensors.", + "type_param_str": "T", + "allowed_type_strs": [ + "tensor(float16)", + "tensor(float)", + "tensor(double)" + ] + } + ], + "examples": [ + { + "summary": "sum", + "code": "data_0 = np.array([3, 0, 2]).astype(np.float32)\ndata_1 = np.array([1, 3, 4]).astype(np.float32)\ndata_2 = np.array([2, 6, 6]).astype(np.float32)\nresult = np.array([6, 9, 12]).astype(np.float32)\nnode = onnx.helper.make_node(\n 'Sum',\n inputs=['data_0', 'data_1', 'data_2'],\n outputs=['result'],\n)\nexpect(node, inputs=[data_0, data_1, data_2], outputs=[result],\n name='test_sum_example')\n\nnode = onnx.helper.make_node(\n 'Sum',\n inputs=['data_0'],\n outputs=['result'],\n)\nexpect(node, inputs=[data_0], outputs=[data_0],\n name='test_sum_one_input')\n\nresult = np.add(data_0, data_1)\nnode = onnx.helper.make_node(\n 'Sum',\n inputs=['data_0', 'data_1'],\n outputs=['result'],\n)\nexpect(node, inputs=[data_0, data_1], outputs=[result],\n name='test_sum_two_inputs')" + } + ] + }, + { + "name": "Sum", + "module": "ai.onnx", + "version": 6, + "support_level": "common", + "description": "Element-wise sum of each of the input tensors. All inputs and outputs must\nhave the same shape and data type.\n", + "inputs": [ + { + "name": "data_0", + "type": "T", + "list": true, + "description": "List of tensors for Sum." + } + ], + "min_input": 1, + "max_input": 2147483647, + "outputs": [ + { + "name": "sum", + "type": "T", + "description": "Output tensor. Same dimension as inputs." + } + ], + "min_output": 1, + "max_output": 1, + "inputs_range": "1 - ∞", + "type_constraints": [ + { + "description": "Constrain input and output types to float tensors.", + "type_param_str": "T", + "allowed_type_strs": [ + "tensor(float16)", + "tensor(float)", + "tensor(double)" + ] + } + ], + "examples": [ + { + "summary": "sum", + "code": "data_0 = np.array([3, 0, 2]).astype(np.float32)\ndata_1 = np.array([1, 3, 4]).astype(np.float32)\ndata_2 = np.array([2, 6, 6]).astype(np.float32)\nresult = np.array([6, 9, 12]).astype(np.float32)\nnode = onnx.helper.make_node(\n 'Sum',\n inputs=['data_0', 'data_1', 'data_2'],\n outputs=['result'],\n)\nexpect(node, inputs=[data_0, data_1, data_2], outputs=[result],\n name='test_sum_example')\n\nnode = onnx.helper.make_node(\n 'Sum',\n inputs=['data_0'],\n outputs=['result'],\n)\nexpect(node, inputs=[data_0], outputs=[data_0],\n name='test_sum_one_input')\n\nresult = np.add(data_0, data_1)\nnode = onnx.helper.make_node(\n 'Sum',\n inputs=['data_0', 'data_1'],\n outputs=['result'],\n)\nexpect(node, inputs=[data_0, data_1], outputs=[result],\n name='test_sum_two_inputs')" + } + ] + }, + { + "name": "Sum", + "module": "ai.onnx", + "version": 8, + "support_level": "common", + "description": "Element-wise sum of each of the input tensors (with Numpy-style broadcasting support).\nAll inputs and outputs must have the same data type.\nThis operator supports **multidirectional (i.e., Numpy-style) broadcasting**; for more details please check [the doc](https://github.com/onnx/onnx/blob/master/docs/Broadcasting.md).\n", + "inputs": [ + { + "name": "data_0", + "type": "T", + "list": true, + "description": "List of tensors for sum." + } + ], + "min_input": 1, + "max_input": 2147483647, + "outputs": [ + { + "name": "sum", + "type": "T", + "description": "Output tensor." + } + ], + "min_output": 1, + "max_output": 1, + "inputs_range": "1 - ∞", + "type_constraints": [ + { + "description": "Constrain input and output types to float tensors.", + "type_param_str": "T", + "allowed_type_strs": [ + "tensor(float16)", + "tensor(float)", + "tensor(double)" + ] + } + ], + "examples": [ + { + "summary": "sum", + "code": "data_0 = np.array([3, 0, 2]).astype(np.float32)\ndata_1 = np.array([1, 3, 4]).astype(np.float32)\ndata_2 = np.array([2, 6, 6]).astype(np.float32)\nresult = np.array([6, 9, 12]).astype(np.float32)\nnode = onnx.helper.make_node(\n 'Sum',\n inputs=['data_0', 'data_1', 'data_2'],\n outputs=['result'],\n)\nexpect(node, inputs=[data_0, data_1, data_2], outputs=[result],\n name='test_sum_example')\n\nnode = onnx.helper.make_node(\n 'Sum',\n inputs=['data_0'],\n outputs=['result'],\n)\nexpect(node, inputs=[data_0], outputs=[data_0],\n name='test_sum_one_input')\n\nresult = np.add(data_0, data_1)\nnode = onnx.helper.make_node(\n 'Sum',\n inputs=['data_0', 'data_1'],\n outputs=['result'],\n)\nexpect(node, inputs=[data_0, data_1], outputs=[result],\n name='test_sum_two_inputs')" + } + ] + }, + { + "name": "Sum", + "module": "ai.onnx", + "version": 13, + "support_level": "common", + "description": "Element-wise sum of each of the input tensors (with Numpy-style broadcasting support).\nAll inputs and outputs must have the same data type.\nThis operator supports **multidirectional (i.e., Numpy-style) broadcasting**; for more details please check [the doc](https://github.com/onnx/onnx/blob/master/docs/Broadcasting.md).\n", + "inputs": [ + { + "name": "data_0", + "type": "T", + "list": true, + "description": "List of tensors for sum." + } + ], + "min_input": 1, + "max_input": 2147483647, + "outputs": [ + { + "name": "sum", + "type": "T", + "description": "Output tensor." + } + ], + "min_output": 1, + "max_output": 1, + "inputs_range": "1 - ∞", + "type_constraints": [ + { + "description": "Constrain input and output types to float tensors.", + "type_param_str": "T", + "allowed_type_strs": [ + "tensor(float16)", + "tensor(float)", + "tensor(double)", + "tensor(bfloat16)" + ] + } + ], + "examples": [ + { + "summary": "sum", + "code": "data_0 = np.array([3, 0, 2]).astype(np.float32)\ndata_1 = np.array([1, 3, 4]).astype(np.float32)\ndata_2 = np.array([2, 6, 6]).astype(np.float32)\nresult = np.array([6, 9, 12]).astype(np.float32)\nnode = onnx.helper.make_node(\n 'Sum',\n inputs=['data_0', 'data_1', 'data_2'],\n outputs=['result'],\n)\nexpect(node, inputs=[data_0, data_1, data_2], outputs=[result],\n name='test_sum_example')\n\nnode = onnx.helper.make_node(\n 'Sum',\n inputs=['data_0'],\n outputs=['result'],\n)\nexpect(node, inputs=[data_0], outputs=[data_0],\n name='test_sum_one_input')\n\nresult = np.add(data_0, data_1)\nnode = onnx.helper.make_node(\n 'Sum',\n inputs=['data_0', 'data_1'],\n outputs=['result'],\n)\nexpect(node, inputs=[data_0, data_1], outputs=[result],\n name='test_sum_two_inputs')" + } + ] + }, + { + "name": "Tan", + "module": "ai.onnx", + "version": 7, + "support_level": "common", + "description": "Calculates the tangent of the given input tensor, element-wise.\n", + "inputs": [ + { + "name": "input", + "type": "T", + "description": "Input tensor" + } + ], + "min_input": 1, + "max_input": 1, + "outputs": [ + { + "name": "output", + "type": "T", + "description": "The tangent of the input tensor computed element-wise" + } + ], + "min_output": 1, + "max_output": 1, + "type_constraints": [ + { + "description": "Constrain input and output types to float tensors.", + "type_param_str": "T", + "allowed_type_strs": [ + "tensor(float16)", + "tensor(float)", + "tensor(double)" + ] + } + ], + "examples": [ + { + "summary": "tan", + "code": "node = onnx.helper.make_node(\n 'Tan',\n inputs=['x'],\n outputs=['y'],\n)\n\nx = np.array([-1, 0, 1]).astype(np.float32)\ny = np.tan(x)\nexpect(node, inputs=[x], outputs=[y],\n name='test_tan_example')\n\nx = np.random.randn(3, 4, 5).astype(np.float32)\ny = np.tan(x)\nexpect(node, inputs=[x], outputs=[y],\n name='test_tan')" + } + ] + }, + { + "name": "Tanh", + "module": "ai.onnx", + "version": 1, + "support_level": "common", + "description": "Calculates the hyperbolic tangent of the given input tensor element-wise.\n", + "attributes": [ + { + "name": "consumed_inputs", + "type": "int64[]", + "required": false, + "description": "legacy optimization attribute." + } + ], + "inputs": [ + { + "name": "input", + "type": "T", + "description": "1-D input tensor" + } + ], + "min_input": 1, + "max_input": 1, + "outputs": [ + { + "name": "output", + "type": "T", + "description": "The hyperbolic tangent values of the input tensor computed element-wise" + } + ], + "min_output": 1, + "max_output": 1, + "type_constraints": [ + { + "description": "Constrain input and output types to float tensors.", + "type_param_str": "T", + "allowed_type_strs": [ + "tensor(float16)", + "tensor(float)", + "tensor(double)" + ] + } + ], + "examples": [ + { + "summary": "tanh", + "code": "node = onnx.helper.make_node(\n 'Tanh',\n inputs=['x'],\n outputs=['y'],\n)\n\nx = np.array([-1, 0, 1]).astype(np.float32)\ny = np.tanh(x) # expected output [-0.76159418, 0., 0.76159418]\nexpect(node, inputs=[x], outputs=[y],\n name='test_tanh_example')\n\nx = np.random.randn(3, 4, 5).astype(np.float32)\ny = np.tanh(x)\nexpect(node, inputs=[x], outputs=[y],\n name='test_tanh')" + } + ], + "category": "Activation" + }, + { + "name": "Tanh", + "module": "ai.onnx", + "version": 6, + "support_level": "common", + "description": "Calculates the hyperbolic tangent of the given input tensor element-wise.\n", + "inputs": [ + { + "name": "input", + "type": "T", + "description": "Input tensor" + } + ], + "min_input": 1, + "max_input": 1, + "outputs": [ + { + "name": "output", + "type": "T", + "description": "The hyperbolic tangent values of the input tensor computed element-wise" + } + ], + "min_output": 1, + "max_output": 1, + "type_constraints": [ + { + "description": "Constrain input and output types to float tensors.", + "type_param_str": "T", + "allowed_type_strs": [ + "tensor(float16)", + "tensor(float)", + "tensor(double)" + ] + } + ], + "examples": [ + { + "summary": "tanh", + "code": "node = onnx.helper.make_node(\n 'Tanh',\n inputs=['x'],\n outputs=['y'],\n)\n\nx = np.array([-1, 0, 1]).astype(np.float32)\ny = np.tanh(x) # expected output [-0.76159418, 0., 0.76159418]\nexpect(node, inputs=[x], outputs=[y],\n name='test_tanh_example')\n\nx = np.random.randn(3, 4, 5).astype(np.float32)\ny = np.tanh(x)\nexpect(node, inputs=[x], outputs=[y],\n name='test_tanh')" + } + ], + "category": "Activation" + }, + { + "name": "Tanh", + "module": "ai.onnx", + "version": 13, + "support_level": "common", + "description": "Calculates the hyperbolic tangent of the given input tensor element-wise.\n", + "inputs": [ + { + "name": "input", + "type": "T", + "description": "Input tensor" + } + ], + "min_input": 1, + "max_input": 1, + "outputs": [ + { + "name": "output", + "type": "T", + "description": "The hyperbolic tangent values of the input tensor computed element-wise" + } + ], + "min_output": 1, + "max_output": 1, + "type_constraints": [ + { + "description": "Constrain input and output types to float tensors.", + "type_param_str": "T", + "allowed_type_strs": [ + "tensor(float16)", + "tensor(float)", + "tensor(double)", + "tensor(bfloat16)" + ] + } + ], + "examples": [ + { + "summary": "tanh", + "code": "node = onnx.helper.make_node(\n 'Tanh',\n inputs=['x'],\n outputs=['y'],\n)\n\nx = np.array([-1, 0, 1]).astype(np.float32)\ny = np.tanh(x) # expected output [-0.76159418, 0., 0.76159418]\nexpect(node, inputs=[x], outputs=[y],\n name='test_tanh_example')\n\nx = np.random.randn(3, 4, 5).astype(np.float32)\ny = np.tanh(x)\nexpect(node, inputs=[x], outputs=[y],\n name='test_tanh')" + } + ], + "category": "Activation" + }, + { + "name": "TfIdfVectorizer", + "module": "ai.onnx", + "version": 9, + "support_level": "common", + "description": "This transform extracts n-grams from the input sequence and save them as a vector. Input can\nbe either a 1-D or 2-D tensor. For 1-D input, output is the n-gram representation of that input.\nFor 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.\nMore specifically, if input shape is [C], the corresponding output shape would be [max(ngram_indexes) + 1].\nIf input shape is [N, C], this operator produces a [N, max(ngram_indexes) + 1]-tensor.\n\nIn contrast to standard n-gram extraction, here, the indexes of extracting an n-gram from the original\nsequence are not necessarily consecutive numbers. The discontinuity between indexes are controlled by the number of skips.\nIf the number of skips is 2, we should skip two tokens when scanning through the original sequence.\nLet's consider an example. Assume that input sequence is [94, 17, 36, 12, 28] and the number of skips is 2.\nThe associated 2-grams are [94, 12] and [17, 28] respectively indexed by [0, 3] and [1, 4].\nIf the number of skips becomes 0, the 2-grams generated are [94, 17], [17, 36], [36, 12], [12, 28]\nindexed by [0, 1], [1, 2], [2, 3], [3, 4], respectively.\n\nThe output vector (denoted by Y) stores the count of each n-gram;\nY[ngram_indexes[i]] indicates the times that the i-th n-gram is found. The attribute ngram_indexes is used to determine the mapping\nbetween index i and the corresponding n-gram's output coordinate. If pool_int64s is [94, 17, 17, 36], ngram_indexes is [1, 0],\nngram_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],\nrespectively. An n-gram which cannot be found in pool_strings/pool_int64s should be ignored and has no effect on the output.\nNote that we may consider all skips up to S when generating the n-grams.\n\nThe 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\nthe 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\",\nthis operator first computes the counts of all n-grams and then scale them by the associated values in the weights attribute.\n\nOnly one of pool_strings and pool_int64s can be set. If pool_int64s is set, the input should be an integer tensor.\nIf pool_strings is set, the input must be a string tensor.\n", + "attributes": [ + { + "name": "max_gram_length", + "type": "int64", + "required": true, + "description": "Maximum n-gram length. If this value is 3, 3-grams will be used to generate the output." + }, + { + "name": "max_skip_count", + "type": "int64", + "required": true, + "description": "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" + }, + { + "name": "min_gram_length", + "type": "int64", + "required": true, + "description": "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." + }, + { + "name": "mode", + "type": "string", + "required": true, + "description": "The weighting criteria. It can be one of \"TF\" (term frequency), \"IDF\" (inverse document frequency), and \"TFIDF\" (the combination of TF and IDF)" + }, + { + "name": "ngram_counts", + "type": "int64[]", + "required": true, + "description": "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." + }, + { + "name": "ngram_indexes", + "type": "int64[]", + "required": true, + "description": "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." + }, + { + "name": "pool_int64s", + "type": "int64[]", + "required": false, + "description": "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." + }, + { + "name": "pool_strings", + "type": "string[]", + "required": false, + "description": "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." + }, + { + "name": "weights", + "type": "float32[]", + "required": false, + "description": "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": [ + { + "name": "X", + "type": "T", + "description": "Input for n-gram extraction" + } + ], + "min_input": 1, + "max_input": 1, + "outputs": [ + { + "name": "Y", + "type": "T1", + "description": "Ngram results" + } + ], + "min_output": 1, + "max_output": 1, + "type_constraints": [ + { + "description": "Input is ether string UTF-8 or int32/int64", + "type_param_str": "T", + "allowed_type_strs": [ + "tensor(string)", + "tensor(int32)", + "tensor(int64)" + ] + }, + { + "description": "1-D tensor of floats", + "type_param_str": "T1", + "allowed_type_strs": [ + "tensor(float)" + ] + } + ], + "examples": [ + { + "summary": "tf_batch_onlybigrams_skip0", + "code": "input = np.array([[1, 1, 3, 3, 3, 7], [8, 6, 7, 5, 6, 8]]).astype(np.int32)\noutput = np.array([[0., 0., 0., 0., 0., 0., 0.], [0., 0., 0., 0., 1., 0., 1.]]).astype(np.float32)\n\nngram_counts = np.array([0, 4]).astype(np.int64)\nngram_indexes = np.array([0, 1, 2, 3, 4, 5, 6]).astype(np.int64)\npool_int64s = np.array([2, 3, 5, 4, # unigrams\n 5, 6, 7, 8, 6, 7]).astype(np.int64) # bigrams\n\nhelper = TfIdfVectorizerHelper(\n mode='TF',\n min_gram_length=2,\n max_gram_length=2,\n max_skip_count=0,\n ngram_counts=ngram_counts,\n ngram_indexes=ngram_indexes,\n pool_int64s=pool_int64s\n)\nnode = helper.make_node_noweights()\nexpect(node, inputs=[input], outputs=[output], name='test_tfidfvectorizer_tf_batch_onlybigrams_skip0')" + }, + { + "summary": "tf_batch_onlybigrams_skip5", + "code": "input = np.array([[1, 1, 3, 3, 3, 7], [8, 6, 7, 5, 6, 8]]).astype(np.int32)\noutput = np.array([[0., 0., 0., 0., 0., 0., 0.], [0., 0., 0., 0., 1., 1., 1.]]).astype(np.float32)\n\nngram_counts = np.array([0, 4]).astype(np.int64)\nngram_indexes = np.array([0, 1, 2, 3, 4, 5, 6]).astype(np.int64)\npool_int64s = np.array([2, 3, 5, 4, # unigrams\n 5, 6, 7, 8, 6, 7]).astype(np.int64) # bigrams\n\nhelper = TfIdfVectorizerHelper(\n mode='TF',\n min_gram_length=2,\n max_gram_length=2,\n max_skip_count=5,\n ngram_counts=ngram_counts,\n ngram_indexes=ngram_indexes,\n pool_int64s=pool_int64s\n)\nnode = helper.make_node_noweights()\nexpect(node, inputs=[input], outputs=[output], name='test_tfidfvectorizer_tf_batch_onlybigrams_skip5')" + }, + { + "summary": "tf_batch_uniandbigrams_skip5", + "code": "input = np.array([[1, 1, 3, 3, 3, 7], [8, 6, 7, 5, 6, 8]]).astype(np.int32)\noutput = np.array([[0., 3., 0., 0., 0., 0., 0.], [0., 0., 1., 0., 1., 1., 1.]]).astype(np.float32)\n\nngram_counts = np.array([0, 4]).astype(np.int64)\nngram_indexes = np.array([0, 1, 2, 3, 4, 5, 6]).astype(np.int64)\npool_int64s = np.array([2, 3, 5, 4, # unigrams\n 5, 6, 7, 8, 6, 7]).astype(np.int64) # bigrams\n\nhelper = TfIdfVectorizerHelper(\n mode='TF',\n min_gram_length=1,\n max_gram_length=2,\n max_skip_count=5,\n ngram_counts=ngram_counts,\n ngram_indexes=ngram_indexes,\n pool_int64s=pool_int64s\n)\nnode = helper.make_node_noweights()\nexpect(node, inputs=[input], outputs=[output], name='test_tfidfvectorizer_tf_batch_uniandbigrams_skip5')" + }, + { + "summary": "tf_only_bigrams_skip0", + "code": "input = np.array([1, 1, 3, 3, 3, 7, 8, 6, 7, 5, 6, 8]).astype(np.int32)\noutput = np.array([0., 0., 0., 0., 1., 1., 1.]).astype(np.float32)\n\nngram_counts = np.array([0, 4]).astype(np.int64)\nngram_indexes = np.array([0, 1, 2, 3, 4, 5, 6]).astype(np.int64)\npool_int64s = np.array([2, 3, 5, 4, # unigrams\n 5, 6, 7, 8, 6, 7]).astype(np.int64) # bigrams\n\nhelper = TfIdfVectorizerHelper(\n mode='TF',\n min_gram_length=2,\n max_gram_length=2,\n max_skip_count=0,\n ngram_counts=ngram_counts,\n ngram_indexes=ngram_indexes,\n pool_int64s=pool_int64s\n)\nnode = helper.make_node_noweights()\nexpect(node, inputs=[input], outputs=[output], name='test_tfidfvectorizer_tf_only_bigrams_skip0')" + }, + { + "summary": "tf_onlybigrams_levelempty", + "code": "input = np.array([1, 1, 3, 3, 3, 7, 8, 6, 7, 5, 6, 8]).astype(np.int32)\noutput = np.array([1., 1., 1.]).astype(np.float32)\n\nngram_counts = np.array([0, 0]).astype(np.int64)\nngram_indexes = np.array([0, 1, 2]).astype(np.int64)\npool_int64s = np.array([ # unigrams none\n 5, 6, 7, 8, 6, 7]).astype(np.int64) # bigrams\n\nhelper = TfIdfVectorizerHelper(\n mode='TF',\n min_gram_length=2,\n max_gram_length=2,\n max_skip_count=0,\n ngram_counts=ngram_counts,\n ngram_indexes=ngram_indexes,\n pool_int64s=pool_int64s\n)\nnode = helper.make_node_noweights()\nexpect(node, inputs=[input], outputs=[output], name='test_tfidfvectorizer_tf_onlybigrams_levelempty')" + }, + { + "summary": "tf_onlybigrams_skip5", + "code": "input = np.array([1, 1, 3, 3, 3, 7, 8, 6, 7, 5, 6, 8]).astype(np.int32)\noutput = np.array([0., 0., 0., 0., 1., 3., 1.]).astype(np.float32)\n\nngram_counts = np.array([0, 4]).astype(np.int64)\nngram_indexes = np.array([0, 1, 2, 3, 4, 5, 6]).astype(np.int64)\npool_int64s = np.array([2, 3, 5, 4, # unigrams\n 5, 6, 7, 8, 6, 7]).astype(np.int64) # bigrams\n\nhelper = TfIdfVectorizerHelper(\n mode='TF',\n min_gram_length=2,\n max_gram_length=2,\n max_skip_count=5,\n ngram_counts=ngram_counts,\n ngram_indexes=ngram_indexes,\n pool_int64s=pool_int64s\n)\nnode = helper.make_node_noweights()\nexpect(node, inputs=[input], outputs=[output], name='test_tfidfvectorizer_tf_onlybigrams_skip5')" + }, + { + "summary": "tf_uniandbigrams_skip5", + "code": "input = np.array([1, 1, 3, 3, 3, 7, 8, 6, 7, 5, 6, 8]).astype(np.int32)\noutput = np.array([0., 3., 1., 0., 1., 3., 1.]).astype(np.float32)\n\nngram_counts = np.array([0, 4]).astype(np.int64)\nngram_indexes = np.array([0, 1, 2, 3, 4, 5, 6]).astype(np.int64)\npool_int64s = np.array([2, 3, 5, 4, # unigrams\n 5, 6, 7, 8, 6, 7]).astype(np.int64) # bigrams\n\nhelper = TfIdfVectorizerHelper(\n mode='TF',\n min_gram_length=1,\n max_gram_length=2,\n max_skip_count=5,\n ngram_counts=ngram_counts,\n ngram_indexes=ngram_indexes,\n pool_int64s=pool_int64s\n)\nnode = helper.make_node_noweights()\nexpect(node, inputs=[input], outputs=[output], name='test_tfidfvectorizer_tf_uniandbigrams_skip5')" + } + ] + }, + { + "name": "ThresholdedRelu", + "module": "ai.onnx", + "version": 10, + "support_level": "common", + "description": "ThresholdedRelu takes one input data (Tensor) and produces one output data\n(Tensor) where the rectified linear function, y = x for x > alpha, y = 0 otherwise,\nis applied to the tensor elementwise.\n", + "attributes": [ + { + "name": "alpha", + "type": "float32", + "required": false, + "default": 1.0, + "description": "Threshold value" + } + ], + "inputs": [ + { + "name": "X", + "type": "T", + "description": "Input tensor" + } + ], + "min_input": 1, + "max_input": 1, + "outputs": [ + { + "name": "Y", + "type": "T", + "description": "Output tensor" + } + ], + "min_output": 1, + "max_output": 1, + "type_constraints": [ + { + "description": "Constrain input and output types to float tensors.", + "type_param_str": "T", + "allowed_type_strs": [ + "tensor(float16)", + "tensor(float)", + "tensor(double)" + ] + } + ], + "examples": [ + { + "summary": "default", + "code": "default_alpha = 1.0\nnode = onnx.helper.make_node(\n 'ThresholdedRelu',\n inputs=['x'],\n outputs=['y']\n)\nx = np.random.randn(3, 4, 5).astype(np.float32)\ny = np.clip(x, default_alpha, np.inf)\ny[y == default_alpha] = 0\n\nexpect(node, inputs=[x], outputs=[y],\n name='test_thresholdedrelu_default')" + }, + { + "summary": "thresholdedrelu", + "code": "alpha = 2.0\nnode = onnx.helper.make_node(\n 'ThresholdedRelu',\n inputs=['x'],\n outputs=['y'],\n alpha=alpha\n)\n\nx = np.array([-1.5, 0., 1.2, 2.0, 2.2]).astype(np.float32)\ny = np.clip(x, alpha, np.inf) # expected output [0., 0., 0., 0., 2.2]\ny[y == alpha] = 0\n\nexpect(node, inputs=[x], outputs=[y],\n name='test_thresholdedrelu_example')\n\nx = np.random.randn(3, 4, 5).astype(np.float32)\ny = np.clip(x, alpha, np.inf)\ny[y == alpha] = 0\n\nexpect(node, inputs=[x], outputs=[y],\n name='test_thresholdedrelu')" + } + ], + "category": "Activation" + }, + { + "name": "Tile", + "module": "ai.onnx", + "version": 1, + "support_level": "common", + "description": "Repeat the elements of a tensor along an axis.", + "inputs": [ + { + "name": "input", + "type": "T", + "description": "Input tensor of any shape." + }, + { + "name": "tiles", + "type": "T", + "description": "Number of repeated copies to make of the input tensor." + }, + { + "name": "axis", + "type": "T", + "description": "Axis along which to repeat." + } + ], + "min_input": 3, + "max_input": 3, + "outputs": [ + { + "name": "output", + "type": "T", + "description": "Output tensor of same shape and type as input." + } + ], + "min_output": 1, + "max_output": 1, + "type_constraints": [ + { + "description": "Constrain input types to float tensors.", + "type_param_str": "T", + "allowed_type_strs": [ + "tensor(float16)", + "tensor(float)", + "tensor(double)" + ] + }, + { + "description": "Constrain tiles and axis's type to int64 tensors.", + "type_param_str": "T1", + "allowed_type_strs": [ + "tensor(int64)" + ] + } + ], + "examples": [ + { + "summary": "tile", + "code": "node = onnx.helper.make_node(\n 'Tile',\n inputs=['x', 'y'],\n outputs=['z']\n)\n\nx = np.random.rand(2, 3, 4, 5).astype(np.float32)\n\nrepeats = np.random.randint(low=1, high=10, size=(np.ndim(x),)).astype(np.int64)\n\nz = np.tile(x, repeats)\n\nexpect(node,\n inputs=[x, repeats],\n outputs=[z],\n name='test_tile')" + }, + { + "summary": "tile_precomputed", + "code": "node = onnx.helper.make_node(\n 'Tile',\n inputs=['x', 'y'],\n outputs=['z']\n)\n\nx = np.array([\n [0, 1],\n [2, 3]\n], dtype=np.float32)\n\nrepeats = np.array([2, 2], dtype=np.int64)\n\nz = np.array([\n [0, 1, 0, 1],\n [2, 3, 2, 3],\n [0, 1, 0, 1],\n [2, 3, 2, 3]\n], dtype=np.float32)\n\nexpect(node,\n inputs=[x, repeats],\n outputs=[z],\n name='test_tile_precomputed')" + } + ], + "category": "Shape" + }, + { + "name": "Tile", + "module": "ai.onnx", + "version": 6, + "support_level": "common", + "description": "Constructs a tensor by tiling a given tensor.\nThis is the same as function `tile` in Numpy, but no broadcast.\nFor example A = [[1, 2], [3, 4]], B = [1, 2], tile(A, B) = [[1, 2, 1, 2], [3, 4, 3, 4]]\n", + "inputs": [ + { + "name": "input", + "type": "T", + "description": "Input tensor of any shape." + }, + { + "name": "repeats", + "type": "T1", + "description": "1D int64 tensor of the same length as input's dimension number, includes numbers of repeated copies along input's dimensions." + } + ], + "min_input": 2, + "max_input": 2, + "outputs": [ + { + "name": "output", + "type": "T", + "description": "Output tensor of the same dimension and type as tensor input. output_dim[i] = input_dim[i] * repeats[i]" + } + ], + "min_output": 1, + "max_output": 1, + "type_constraints": [ + { + "description": "Constrain input and output types to all tensor types.", + "type_param_str": "T", + "allowed_type_strs": [ + "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)" + ] + }, + { + "description": "Constrain repeat's type to int64 tensors.", + "type_param_str": "T1", + "allowed_type_strs": [ + "tensor(int64)" + ] + } + ], + "examples": [ + { + "summary": "tile", + "code": "node = onnx.helper.make_node(\n 'Tile',\n inputs=['x', 'y'],\n outputs=['z']\n)\n\nx = np.random.rand(2, 3, 4, 5).astype(np.float32)\n\nrepeats = np.random.randint(low=1, high=10, size=(np.ndim(x),)).astype(np.int64)\n\nz = np.tile(x, repeats)\n\nexpect(node,\n inputs=[x, repeats],\n outputs=[z],\n name='test_tile')" + }, + { + "summary": "tile_precomputed", + "code": "node = onnx.helper.make_node(\n 'Tile',\n inputs=['x', 'y'],\n outputs=['z']\n)\n\nx = np.array([\n [0, 1],\n [2, 3]\n], dtype=np.float32)\n\nrepeats = np.array([2, 2], dtype=np.int64)\n\nz = np.array([\n [0, 1, 0, 1],\n [2, 3, 2, 3],\n [0, 1, 0, 1],\n [2, 3, 2, 3]\n], dtype=np.float32)\n\nexpect(node,\n inputs=[x, repeats],\n outputs=[z],\n name='test_tile_precomputed')" + } + ], + "category": "Shape" + }, + { + "name": "Tile", + "module": "ai.onnx", + "version": 13, + "support_level": "common", + "description": "Constructs a tensor by tiling a given tensor.\nThis is the same as function `tile` in Numpy, but no broadcast.\nFor example A = [[1, 2], [3, 4]], B = [1, 2], tile(A, B) = [[1, 2, 1, 2], [3, 4, 3, 4]]\n", + "inputs": [ + { + "name": "input", + "type": "T", + "description": "Input tensor of any shape." + }, + { + "name": "repeats", + "type": "T1", + "description": "1D int64 tensor of the same length as input's dimension number, includes numbers of repeated copies along input's dimensions." + } + ], + "min_input": 2, + "max_input": 2, + "outputs": [ + { + "name": "output", + "type": "T", + "description": "Output tensor of the same dimension and type as tensor input. output_dim[i] = input_dim[i] * repeats[i]" + } + ], + "min_output": 1, + "max_output": 1, + "type_constraints": [ + { + "description": "Constrain input and output types to all tensor types.", + "type_param_str": "T", + "allowed_type_strs": [ + "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)" + ] + }, + { + "description": "Constrain repeat's type to int64 tensors.", + "type_param_str": "T1", + "allowed_type_strs": [ + "tensor(int64)" + ] + } + ], + "examples": [ + { + "summary": "tile", + "code": "node = onnx.helper.make_node(\n 'Tile',\n inputs=['x', 'y'],\n outputs=['z']\n)\n\nx = np.random.rand(2, 3, 4, 5).astype(np.float32)\n\nrepeats = np.random.randint(low=1, high=10, size=(np.ndim(x),)).astype(np.int64)\n\nz = np.tile(x, repeats)\n\nexpect(node,\n inputs=[x, repeats],\n outputs=[z],\n name='test_tile')" + }, + { + "summary": "tile_precomputed", + "code": "node = onnx.helper.make_node(\n 'Tile',\n inputs=['x', 'y'],\n outputs=['z']\n)\n\nx = np.array([\n [0, 1],\n [2, 3]\n], dtype=np.float32)\n\nrepeats = np.array([2, 2], dtype=np.int64)\n\nz = np.array([\n [0, 1, 0, 1],\n [2, 3, 2, 3],\n [0, 1, 0, 1],\n [2, 3, 2, 3]\n], dtype=np.float32)\n\nexpect(node,\n inputs=[x, repeats],\n outputs=[z],\n name='test_tile_precomputed')" + } + ], + "category": "Shape" + }, + { + "name": "TopK", + "module": "ai.onnx", + "version": 1, + "support_level": "common", + "description": "Retrieve the top-K elements along a specified axis. Given an input tensor of\nshape [a_1, a_2, ..., a_n, r] and integer argument k, return two outputs:\n -Value tensor of shape [a_1, a_2, ..., a_{axis-1}, k, a_{axis+1}, ... a_n]\n which contains the values of the top k elements along the specified axis\n -Index tensor of shape [a_1, a_2, ..., a_{axis-1}, k, a_{axis+1}, ... a_n] which\n contains the indices of the top k elements (original indices from the input\n tensor).\nGiven two equivalent values, this operator uses the indices along the axis as\n a tiebreaker. That is, the element with the lower index will appear first.\n", + "attributes": [ + { + "name": "axis", + "type": "int64", + "required": false, + "default": -1, + "description": "Dimension on which to do the sort." + }, + { + "name": "k", + "type": "int64", + "required": true, + "description": "Number of top elements to retrieve" + } + ], + "inputs": [ + { + "name": "X", + "type": "T", + "description": "Tensor of shape [a_1, a_2, ..., a_n, r]" + } + ], + "min_input": 1, + "max_input": 1, + "outputs": [ + { + "name": "Values", + "type": "T", + "description": "Tensor of shape [a_1, a_2, ..., a_{axis-1}, k, a_{axis+1}, ... a_n] containing top K values from the input tensor" + }, + { + "name": "Indices", + "type": "I", + "description": "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." + } + ], + "min_output": 2, + "max_output": 2, + "type_constraints": [ + { + "description": "Constrain input and output types to float tensors.", + "type_param_str": "T", + "allowed_type_strs": [ + "tensor(float16)", + "tensor(float)", + "tensor(double)" + ] + }, + { + "description": "Constrain index tensor to int64", + "type_param_str": "I", + "allowed_type_strs": [ + "tensor(int64)" + ] + } + ], + "examples": [ + { + "summary": "top_k", + "code": "axis = 1\nlargest = 1\n\nk = 3\nnode = onnx.helper.make_node(\n 'TopK',\n inputs=['x', 'k'],\n outputs=['values', 'indices'],\n axis=axis\n)\nX = np.array([\n [0, 1, 2, 3],\n [4, 5, 6, 7],\n [8, 9, 10, 11],\n], dtype=np.float32)\nK = np.array([k], dtype=np.int64)\nvalues_ref, indices_ref = topk_sorted_implementation(X, k, axis, largest)\n\n#print(values_ref)\n#[[ 3. 2. 1.]\n# [ 7. 6. 5.]\n# [11. 10. 9.]]\n#print(indices_ref)\n#[[3 2 1]\n# [3 2 1]\n# [3 2 1]]\n\nexpect(node, inputs=[X, K], outputs=[values_ref, indices_ref],\n name='test_top_k')" + }, + { + "summary": "top_k_negative_axis", + "code": "axis = -1\nlargest = 1\n\nk = 3\nnode = onnx.helper.make_node(\n 'TopK',\n inputs=['x', 'k'],\n outputs=['values', 'indices'],\n axis=axis\n)\nX = np.array([\n [0, 1, 2, 3],\n [4, 5, 6, 7],\n [8, 9, 10, 11],\n], dtype=np.float32)\nK = np.array([k], dtype=np.int64)\nvalues_ref, indices_ref = topk_sorted_implementation(X, k, axis, largest)\n\n# print(values_ref)\n#[[ 3. 2. 1.]\n# [ 7. 6. 5.]\n# [11. 10. 9.]]\n# print(indices_ref)\n#[[3 2 1]\n# [3 2 1]\n# [3 2 1]]\n\nexpect(node, inputs=[X, K], outputs=[values_ref, indices_ref],\n name='test_top_k_negative_axis')" + }, + { + "summary": "top_k_smallest", + "code": "axis = 1\nlargest = 0\nsorted = 1\nk = 3\n\nnode = onnx.helper.make_node(\n 'TopK',\n inputs=['x', 'k'],\n outputs=['values', 'indices'],\n axis=axis,\n largest=largest,\n sorted=sorted\n)\n\nX = np.array([\n [0, 1, 2, 3],\n [4, 5, 6, 7],\n [11, 10, 9, 8],\n], dtype=np.float32)\nK = np.array([k], dtype=np.int64)\nvalues_ref, indices_ref = topk_sorted_implementation(X, k, axis, largest)\n\n#print(values_ref)\n#[[ 0. 1. 2.]\n# [ 4. 5. 6.]\n# [ 8. 9. 10.]]\n#print(indices_ref)\n#[[0 1 2]\n# [0 1 2]\n# [3 2 1]]\n\nexpect(node, inputs=[X, K], outputs=[values_ref, indices_ref],\n name='test_top_k_smallest')" + } + ] + }, + { + "name": "TopK", + "module": "ai.onnx", + "version": 10, + "support_level": "common", + "description": "Retrieve the top-K elements along a specified axis. Given an input tensor of\nshape [a_1, a_2, ..., a_n, r] and integer argument k, return two outputs:\n -Value tensor of shape [a_1, a_2, ..., a_{axis-1}, k, a_{axis+1}, ... a_n]\n which contains the values of the top k elements along the specified axis\n -Index tensor of shape [a_1, a_2, ..., a_{axis-1}, k, a_{axis+1}, ... a_n] which\n contains the indices of the top k elements (original indices from the input\n tensor).\n\nGiven two equivalent values, this operator uses the indices along the axis as\n a tiebreaker. That is, the element with the lower index will appear first.\n", + "attributes": [ + { + "name": "axis", + "type": "int64", + "required": false, + "default": -1, + "description": "Dimension on which to do the sort." + } + ], + "inputs": [ + { + "name": "X", + "type": "T", + "description": "Tensor of shape [a_1, a_2, ..., a_n, r]" + }, + { + "name": "K", + "type": "tensor(int64)", + "description": "A 1-D tensor containing a single positive value corresponding to the number of top elements to retrieve" + } + ], + "min_input": 2, + "max_input": 2, + "outputs": [ + { + "name": "Values", + "type": "T", + "description": "Tensor of shape [a_1, a_2, ..., a_{axis-1}, k, a_{axis+1}, ... a_n] containing top K values from the input tensor" + }, + { + "name": "Indices", + "type": "I", + "description": "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." + } + ], + "min_output": 2, + "max_output": 2, + "type_constraints": [ + { + "description": "Constrain input and output types to float tensors.", + "type_param_str": "T", + "allowed_type_strs": [ + "tensor(float16)", + "tensor(float)", + "tensor(double)" + ] + }, + { + "description": "Constrain index tensor to int64", + "type_param_str": "I", + "allowed_type_strs": [ + "tensor(int64)" + ] + } + ], + "examples": [ + { + "summary": "top_k", + "code": "axis = 1\nlargest = 1\n\nk = 3\nnode = onnx.helper.make_node(\n 'TopK',\n inputs=['x', 'k'],\n outputs=['values', 'indices'],\n axis=axis\n)\nX = np.array([\n [0, 1, 2, 3],\n [4, 5, 6, 7],\n [8, 9, 10, 11],\n], dtype=np.float32)\nK = np.array([k], dtype=np.int64)\nvalues_ref, indices_ref = topk_sorted_implementation(X, k, axis, largest)\n\n#print(values_ref)\n#[[ 3. 2. 1.]\n# [ 7. 6. 5.]\n# [11. 10. 9.]]\n#print(indices_ref)\n#[[3 2 1]\n# [3 2 1]\n# [3 2 1]]\n\nexpect(node, inputs=[X, K], outputs=[values_ref, indices_ref],\n name='test_top_k')" + }, + { + "summary": "top_k_negative_axis", + "code": "axis = -1\nlargest = 1\n\nk = 3\nnode = onnx.helper.make_node(\n 'TopK',\n inputs=['x', 'k'],\n outputs=['values', 'indices'],\n axis=axis\n)\nX = np.array([\n [0, 1, 2, 3],\n [4, 5, 6, 7],\n [8, 9, 10, 11],\n], dtype=np.float32)\nK = np.array([k], dtype=np.int64)\nvalues_ref, indices_ref = topk_sorted_implementation(X, k, axis, largest)\n\n# print(values_ref)\n#[[ 3. 2. 1.]\n# [ 7. 6. 5.]\n# [11. 10. 9.]]\n# print(indices_ref)\n#[[3 2 1]\n# [3 2 1]\n# [3 2 1]]\n\nexpect(node, inputs=[X, K], outputs=[values_ref, indices_ref],\n name='test_top_k_negative_axis')" + }, + { + "summary": "top_k_smallest", + "code": "axis = 1\nlargest = 0\nsorted = 1\nk = 3\n\nnode = onnx.helper.make_node(\n 'TopK',\n inputs=['x', 'k'],\n outputs=['values', 'indices'],\n axis=axis,\n largest=largest,\n sorted=sorted\n)\n\nX = np.array([\n [0, 1, 2, 3],\n [4, 5, 6, 7],\n [11, 10, 9, 8],\n], dtype=np.float32)\nK = np.array([k], dtype=np.int64)\nvalues_ref, indices_ref = topk_sorted_implementation(X, k, axis, largest)\n\n#print(values_ref)\n#[[ 0. 1. 2.]\n# [ 4. 5. 6.]\n# [ 8. 9. 10.]]\n#print(indices_ref)\n#[[0 1 2]\n# [0 1 2]\n# [3 2 1]]\n\nexpect(node, inputs=[X, K], outputs=[values_ref, indices_ref],\n name='test_top_k_smallest')" + } + ] + }, + { + "name": "TopK", + "module": "ai.onnx", + "version": 11, + "support_level": "common", + "description": "Retrieve the top-K largest or smallest elements along a specified axis. Given an input tensor of\nshape [a_1, a_2, ..., a_n, r] and integer argument k, return two outputs:\n -Value tensor of shape [a_1, a_2, ..., a_{axis-1}, k, a_{axis+1}, ... a_n]\n which contains the values of the top k elements along the specified axis\n -Index tensor of shape [a_1, a_2, ..., a_{axis-1}, k, a_{axis+1}, ... a_n] which\n contains the indices of the top k elements (original indices from the input\n tensor).\n\nIf \"largest\" is 1 (the default value) then the k largest elements are returned.\nIf \"sorted\" is 1 (the default value) then the resulting k elements will be sorted.\nIf \"sorted\" is 0, order of returned 'Values' and 'Indices' are undefined.\n\nGiven two equivalent values, this operator uses the indices along the axis as\n a tiebreaker. That is, the element with the lower index will appear first.\n", + "attributes": [ + { + "name": "axis", + "type": "int64", + "required": false, + "default": -1, + "description": "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)." + }, + { + "name": "largest", + "type": "int64", + "required": false, + "default": 1, + "description": "Whether to return the top-K largest or smallest elements." + }, + { + "name": "sorted", + "type": "int64", + "required": false, + "default": 1, + "description": "Whether to return the elements in sorted order." + } + ], + "inputs": [ + { + "name": "X", + "type": "T", + "description": "Tensor of shape [a_1, a_2, ..., a_n, r]" + }, + { + "name": "K", + "type": "tensor(int64)", + "description": "A 1-D tensor containing a single positive value corresponding to the number of top elements to retrieve" + } + ], + "min_input": 2, + "max_input": 2, + "outputs": [ + { + "name": "Values", + "type": "T", + "description": "Tensor of shape [a_1, a_2, ..., a_{axis-1}, k, a_{axis+1}, ... a_n] containing top K values from the input tensor" + }, + { + "name": "Indices", + "type": "I", + "description": "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." + } + ], + "min_output": 2, + "max_output": 2, + "type_constraints": [ + { + "description": "Constrain input and output types to numeric tensors.", + "type_param_str": "T", + "allowed_type_strs": [ + "tensor(uint8)", + "tensor(uint16)", + "tensor(uint32)", + "tensor(uint64)", + "tensor(int8)", + "tensor(int16)", + "tensor(int32)", + "tensor(int64)", + "tensor(float16)", + "tensor(float)", + "tensor(double)" + ] + }, + { + "description": "Constrain index tensor to int64", + "type_param_str": "I", + "allowed_type_strs": [ + "tensor(int64)" + ] + } + ], + "examples": [ + { + "summary": "top_k", + "code": "axis = 1\nlargest = 1\n\nk = 3\nnode = onnx.helper.make_node(\n 'TopK',\n inputs=['x', 'k'],\n outputs=['values', 'indices'],\n axis=axis\n)\nX = np.array([\n [0, 1, 2, 3],\n [4, 5, 6, 7],\n [8, 9, 10, 11],\n], dtype=np.float32)\nK = np.array([k], dtype=np.int64)\nvalues_ref, indices_ref = topk_sorted_implementation(X, k, axis, largest)\n\n#print(values_ref)\n#[[ 3. 2. 1.]\n# [ 7. 6. 5.]\n# [11. 10. 9.]]\n#print(indices_ref)\n#[[3 2 1]\n# [3 2 1]\n# [3 2 1]]\n\nexpect(node, inputs=[X, K], outputs=[values_ref, indices_ref],\n name='test_top_k')" + }, + { + "summary": "top_k_negative_axis", + "code": "axis = -1\nlargest = 1\n\nk = 3\nnode = onnx.helper.make_node(\n 'TopK',\n inputs=['x', 'k'],\n outputs=['values', 'indices'],\n axis=axis\n)\nX = np.array([\n [0, 1, 2, 3],\n [4, 5, 6, 7],\n [8, 9, 10, 11],\n], dtype=np.float32)\nK = np.array([k], dtype=np.int64)\nvalues_ref, indices_ref = topk_sorted_implementation(X, k, axis, largest)\n\n# print(values_ref)\n#[[ 3. 2. 1.]\n# [ 7. 6. 5.]\n# [11. 10. 9.]]\n# print(indices_ref)\n#[[3 2 1]\n# [3 2 1]\n# [3 2 1]]\n\nexpect(node, inputs=[X, K], outputs=[values_ref, indices_ref],\n name='test_top_k_negative_axis')" + }, + { + "summary": "top_k_smallest", + "code": "axis = 1\nlargest = 0\nsorted = 1\nk = 3\n\nnode = onnx.helper.make_node(\n 'TopK',\n inputs=['x', 'k'],\n outputs=['values', 'indices'],\n axis=axis,\n largest=largest,\n sorted=sorted\n)\n\nX = np.array([\n [0, 1, 2, 3],\n [4, 5, 6, 7],\n [11, 10, 9, 8],\n], dtype=np.float32)\nK = np.array([k], dtype=np.int64)\nvalues_ref, indices_ref = topk_sorted_implementation(X, k, axis, largest)\n\n#print(values_ref)\n#[[ 0. 1. 2.]\n# [ 4. 5. 6.]\n# [ 8. 9. 10.]]\n#print(indices_ref)\n#[[0 1 2]\n# [0 1 2]\n# [3 2 1]]\n\nexpect(node, inputs=[X, K], outputs=[values_ref, indices_ref],\n name='test_top_k_smallest')" + } + ] + }, + { + "name": "Transpose", + "module": "ai.onnx", + "version": 1, + "support_level": "common", + "description": "Transpose the input tensor similar to numpy.transpose. For example, when\nperm=(1, 0, 2), given an input tensor of shape (1, 2, 3), the output shape\nwill be (2, 1, 3).\n", + "attributes": [ + { + "name": "perm", + "type": "int64[]", + "required": false, + "description": "A list of integers. By default, reverse the dimensions, otherwise permute the axes according to the values given." + } + ], + "inputs": [ + { + "name": "data", + "type": "T", + "description": "An input tensor." + } + ], + "min_input": 1, + "max_input": 1, + "outputs": [ + { + "name": "transposed", + "type": "T", + "description": "Transposed output." + } + ], + "min_output": 1, + "max_output": 1, + "type_constraints": [ + { + "description": "Constrain input and output types to all tensor types.", + "type_param_str": "T", + "allowed_type_strs": [ + "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)" + ] + } + ], + "examples": [ + { + "summary": "all_permutations", + "code": "shape = (2, 3, 4)\ndata = np.random.random_sample(shape).astype(np.float32)\npermutations = list(itertools.permutations(np.arange(len(shape))))\n\nfor i in range(len(permutations)):\n node = onnx.helper.make_node(\n 'Transpose',\n inputs=['data'],\n outputs=['transposed'],\n perm=permutations[i]\n )\n transposed = np.transpose(data, permutations[i])\n expect(node, inputs=[data], outputs=[transposed],\n name='test_transpose_all_permutations_' + str(i))" + }, + { + "summary": "default", + "code": "shape = (2, 3, 4)\ndata = np.random.random_sample(shape).astype(np.float32)\n\nnode = onnx.helper.make_node(\n 'Transpose',\n inputs=['data'],\n outputs=['transposed']\n)\n\ntransposed = np.transpose(data)\nexpect(node, inputs=[data], outputs=[transposed],\n name='test_transpose_default')" + } + ], + "category": "Transform" + }, + { + "name": "Transpose", + "module": "ai.onnx", + "version": 13, + "support_level": "common", + "description": "Transpose the input tensor similar to numpy.transpose. For example, when\nperm=(1, 0, 2), given an input tensor of shape (1, 2, 3), the output shape\nwill be (2, 1, 3).\n", + "attributes": [ + { + "name": "perm", + "type": "int64[]", + "required": false, + "description": "A list of integers. By default, reverse the dimensions, otherwise permute the axes according to the values given." + } + ], + "inputs": [ + { + "name": "data", + "type": "T", + "description": "An input tensor." + } + ], + "min_input": 1, + "max_input": 1, + "outputs": [ + { + "name": "transposed", + "type": "T", + "description": "Transposed output." + } + ], + "min_output": 1, + "max_output": 1, + "type_constraints": [ + { + "description": "Constrain input and output types to all tensor types.", + "type_param_str": "T", + "allowed_type_strs": [ + "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)" + ] + } + ], + "examples": [ + { + "summary": "all_permutations", + "code": "shape = (2, 3, 4)\ndata = np.random.random_sample(shape).astype(np.float32)\npermutations = list(itertools.permutations(np.arange(len(shape))))\n\nfor i in range(len(permutations)):\n node = onnx.helper.make_node(\n 'Transpose',\n inputs=['data'],\n outputs=['transposed'],\n perm=permutations[i]\n )\n transposed = np.transpose(data, permutations[i])\n expect(node, inputs=[data], outputs=[transposed],\n name='test_transpose_all_permutations_' + str(i))" + }, + { + "summary": "default", + "code": "shape = (2, 3, 4)\ndata = np.random.random_sample(shape).astype(np.float32)\n\nnode = onnx.helper.make_node(\n 'Transpose',\n inputs=['data'],\n outputs=['transposed']\n)\n\ntransposed = np.transpose(data)\nexpect(node, inputs=[data], outputs=[transposed],\n name='test_transpose_default')" + } + ], + "category": "Transform" + }, + { + "name": "TreeEnsembleClassifier", + "module": "ai.onnx.ml", + "version": 1, + "support_level": "common", + "description": "Tree Ensemble classifier. Returns the top class for each of N inputs.
\n The attributes named 'nodes_X' form a sequence of tuples, associated by\n index into the sequences, which must all be of equal length. These tuples\n define the nodes.
\n Similarly, all fields prefixed with 'class_' are tuples of votes at the leaves.\n A leaf may have multiple votes, where each vote is weighted by\n the associated class_weights index.
\n One and only one of classlabels_strings or classlabels_int64s\n will be defined. The class_ids are indices into this list.\n", + "attributes": [ + { + "name": "base_values", + "type": "float32[]", + "required": false, + "description": "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)" + }, + { + "name": "class_ids", + "type": "int64[]", + "required": false, + "description": "The index of the class list that each weight is for." + }, + { + "name": "class_nodeids", + "type": "int64[]", + "required": false, + "description": "node id that this weight is for." + }, + { + "name": "class_treeids", + "type": "int64[]", + "required": false, + "description": "The id of the tree that this node is in." + }, + { + "name": "class_weights", + "type": "float32[]", + "required": false, + "description": "The weight for the class in class_id." + }, + { + "name": "classlabels_int64s", + "type": "int64[]", + "required": false, + "description": "Class labels if using integer labels.
One and only one of the 'classlabels_*' attributes must be defined." + }, + { + "name": "classlabels_strings", + "type": "string[]", + "required": false, + "description": "Class labels if using string labels.
One and only one of the 'classlabels_*' attributes must be defined." + }, + { + "name": "nodes_falsenodeids", + "type": "int64[]", + "required": false, + "description": "Child node if expression is false." + }, + { + "name": "nodes_featureids", + "type": "int64[]", + "required": false, + "description": "Feature id for each node." + }, + { + "name": "nodes_hitrates", + "type": "float32[]", + "required": false, + "description": "Popularity of each node, used for performance and may be omitted." + }, + { + "name": "nodes_missing_value_tracks_true", + "type": "int64[]", + "required": false, + "description": "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." + }, + { + "name": "nodes_modes", + "type": "string[]", + "required": false, + "description": "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'" + }, + { + "name": "nodes_nodeids", + "type": "int64[]", + "required": false, + "description": "Node id for each node. Ids may restart at zero for each tree, but it not required to." + }, + { + "name": "nodes_treeids", + "type": "int64[]", + "required": false, + "description": "Tree id for each node." + }, + { + "name": "nodes_truenodeids", + "type": "int64[]", + "required": false, + "description": "Child node if expression is true." + }, + { + "name": "nodes_values", + "type": "float32[]", + "required": false, + "description": "Thresholds to do the splitting on for each node." + }, + { + "name": "post_transform", + "type": "string", + "required": false, + "default": "NONE", + "description": "Indicates the transform to apply to the score.
One of 'NONE,' 'SOFTMAX,' 'LOGISTIC,' 'SOFTMAX_ZERO,' or 'PROBIT.'" + } + ], + "inputs": [ + { + "name": "X", + "type": "T1", + "description": "Input of shape [N,F]" + } + ], + "min_input": 1, + "max_input": 1, + "outputs": [ + { + "name": "Y", + "type": "T2", + "description": "N, Top class for each point" + }, + { + "name": "Z", + "type": "tensor(float)", + "description": "The class score for each class, for each point, a tensor of shape [N,E]." + } + ], + "min_output": 2, + "max_output": 2, + "type_constraints": [ + { + "description": "The input type must be a tensor of a numeric type.", + "type_param_str": "T1", + "allowed_type_strs": [ + "tensor(float)", + "tensor(double)", + "tensor(int64)", + "tensor(int32)" + ] + }, + { + "description": "The output type will be a tensor of strings or integers, depending on which of the the classlabels_* attributes is used.", + "type_param_str": "T2", + "allowed_type_strs": [ + "tensor(string)", + "tensor(int64)" + ] + } + ] + }, + { + "name": "TreeEnsembleRegressor", + "module": "ai.onnx.ml", + "version": 1, + "support_level": "common", + "description": "Tree Ensemble regressor. Returns the regressed values for each input in N.
\n All args with nodes_ are fields of a tuple of tree nodes, and\n it is assumed they are the same length, and an index i will decode the\n tuple across these inputs. Each node id can appear only once\n for each tree id.
\n All fields prefixed with target_ are tuples of votes at the leaves.
\n A leaf may have multiple votes, where each vote is weighted by\n the associated target_weights index.
\n All trees must have their node ids start at 0 and increment by 1.
\n Mode enum is BRANCH_LEQ, BRANCH_LT, BRANCH_GTE, BRANCH_GT, BRANCH_EQ, BRANCH_NEQ, LEAF\n", + "attributes": [ + { + "name": "aggregate_function", + "type": "string", + "required": false, + "default": "SUM", + "description": "Defines how to aggregate leaf values within a target.
One of 'AVERAGE,' 'SUM,' 'MIN,' 'MAX.'" + }, + { + "name": "base_values", + "type": "float32[]", + "required": false, + "description": "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)" + }, + { + "name": "n_targets", + "type": "int64", + "required": false, + "description": "The total number of targets." + }, + { + "name": "nodes_falsenodeids", + "type": "int64[]", + "required": false, + "description": "Child node if expression is false" + }, + { + "name": "nodes_featureids", + "type": "int64[]", + "required": false, + "description": "Feature id for each node." + }, + { + "name": "nodes_hitrates", + "type": "float32[]", + "required": false, + "description": "Popularity of each node, used for performance and may be omitted." + }, + { + "name": "nodes_missing_value_tracks_true", + "type": "int64[]", + "required": false, + "description": "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." + }, + { + "name": "nodes_modes", + "type": "string[]", + "required": false, + "description": "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'" + }, + { + "name": "nodes_nodeids", + "type": "int64[]", + "required": false, + "description": "Node id for each node. Node ids must restart at zero for each tree and increase sequentially." + }, + { + "name": "nodes_treeids", + "type": "int64[]", + "required": false, + "description": "Tree id for each node." + }, + { + "name": "nodes_truenodeids", + "type": "int64[]", + "required": false, + "description": "Child node if expression is true" + }, + { + "name": "nodes_values", + "type": "float32[]", + "required": false, + "description": "Thresholds to do the splitting on for each node." + }, + { + "name": "post_transform", + "type": "string", + "required": false, + "default": "NONE", + "description": "Indicates the transform to apply to the score.
One of 'NONE,' 'SOFTMAX,' 'LOGISTIC,' 'SOFTMAX_ZERO,' or 'PROBIT'" + }, + { + "name": "target_ids", + "type": "int64[]", + "required": false, + "description": "The index of the target that each weight is for" + }, + { + "name": "target_nodeids", + "type": "int64[]", + "required": false, + "description": "The node id of each weight" + }, + { + "name": "target_treeids", + "type": "int64[]", + "required": false, + "description": "The id of the tree that each node is in." + }, + { + "name": "target_weights", + "type": "float32[]", + "required": false, + "description": "The weight for each target" + } + ], + "inputs": [ + { + "name": "X", + "type": "T", + "description": "Input of shape [N,F]" + } + ], + "min_input": 1, + "max_input": 1, + "outputs": [ + { + "name": "Y", + "type": "tensor(float)", + "description": "N classes" + } + ], + "min_output": 1, + "max_output": 1, + "type_constraints": [ + { + "description": "The input type must be a tensor of a numeric type.", + "type_param_str": "T", + "allowed_type_strs": [ + "tensor(float)", + "tensor(double)", + "tensor(int64)", + "tensor(int32)" + ] + } + ] + }, + { + "name": "Trilu", + "module": "ai.onnx", + "version": 14, + "support_level": "common", + "description": "Given a 2-D matrix or batches of 2-D matrices, returns the upper or lower triangular part of the tensor(s).\nThe attribute \"upper\" determines whether the upper or lower part is retained. If set to true,\nthe upper triangular matrix is retained. Lower triangular matrix is retained otherwise.\nDefault value for the \"upper\" attribute is true.\nTrilu takes one input tensor of shape [*, N, M], where * is zero or more batch dimensions. The upper triangular part consists\nof the elements on and above the given diagonal (k). The lower triangular part consists of elements on and below the diagonal.\nAll other elements in the matrix are set to zero.\nIf k = 0, the triangular part on and above/below the main diagonal is retained.\nIf upper is set to true, a positive k retains the upper triangular matrix excluding the main diagonal and (k-1) diagonals above it.\nA negative k value retains the main diagonal and |k| diagonals below it.\nIf upper is set to false, a positive k retains the lower triangular matrix including the main diagonal and k diagonals above it.\nA negative k value excludes the main diagonal and (|k|-1) diagonals below it.\n", + "attributes": [ + { + "name": "upper", + "type": "int64", + "required": false, + "default": 1, + "description": "Boolean. Indicates whether upper or lower part of matrix is retained. Default is true." + } + ], + "inputs": [ + { + "name": "input", + "type": "T", + "description": "Input tensor of rank 2 or higher." + }, + { + "name": "k", + "type": "tensor(int64)", + "option": "optional", + "description": "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." + } + ], + "min_input": 1, + "max_input": 2, + "outputs": [ + { + "name": "output", + "type": "T", + "description": "Output tensor of the same type and shape as the input tensor." + } + ], + "min_output": 1, + "max_output": 1, + "inputs_range": "1 - 2", + "type_constraints": [ + { + "description": "Constrain input and output types to all tensor types.", + "type_param_str": "T", + "allowed_type_strs": [ + "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)" + ] + } + ], + "examples": [ + { + "summary": "tril", + "code": "node = onnx.helper.make_node(\n 'Trilu',\n inputs=['x'],\n outputs=['y'],\n upper=0,\n)\n\nx = np.random.randint(10, size=(4, 5)).astype(np.int64)\n# X:\n# [[4, 7, 3, 7, 9],\n# [1, 2, 8, 6, 9],\n# [9, 4, 1, 8, 7],\n# [4, 3, 4, 2, 4]]\n# expect result:\n# [[4, 0, 0, 0, 0],\n# [1, 2, 0, 0, 0],\n# [9, 4, 1, 0, 0],\n# [4, 3, 4, 2, 0]]\ny = tril_reference_implementation(x)\nexpect(node, inputs=[x], outputs=[y], name='test_tril')" + }, + { + "summary": "tril_neg", + "code": "node = onnx.helper.make_node(\n 'Trilu',\n inputs=['x', 'k'],\n outputs=['y'],\n upper=0,\n)\n\nx = np.random.randint(10, size=(4, 5)).astype(np.int64)\nk = np.array(-1).astype(np.int64)\n# X:\n# [[4, 7, 3, 7, 9],\n# [1, 2, 8, 6, 9],\n# [9, 4, 1, 8, 7],\n# [4, 3, 4, 2, 4]]\n# expect result:\n# [[0, 0, 0, 0, 0],\n# [1, 0, 0, 0, 0],\n# [9, 4, 0, 0, 0],\n# [4, 3, 4, 0, 0]]\ny = tril_reference_implementation(x, int(k))\nexpect(node, inputs=[x, k], outputs=[y], name='test_tril_neg')" + }, + { + "summary": "tril_one_row", + "code": "node = onnx.helper.make_node(\n 'Trilu',\n inputs=['x'],\n outputs=['y'],\n upper=0,\n)\n\nx = np.random.randint(10, size=(3, 1, 5)).astype(np.int64)\n# X:\n# [[[6, 2, 4, 1, 6]],\n#\n# [[8, 3, 8, 7, 0]],\n#\n# [[2, 2, 9, 5, 9]]]\n# expect result:\n# [[[6, 0, 0, 0, 0]],\n#\n# [[8, 0, 0, 0, 0]],\n#\n# [[2, 0, 0, 0, 0]]]\ny = tril_reference_implementation(x)\nexpect(node, inputs=[x], outputs=[y], name='test_tril_one_row_neg')" + }, + { + "summary": "tril_out_neg", + "code": "node = onnx.helper.make_node(\n 'Trilu',\n inputs=['x', 'k'],\n outputs=['y'],\n upper=0,\n)\n\nx = np.random.randint(10, size=(4, 5)).astype(np.int64)\nk = np.array(-7).astype(np.int64)\n# X:\n# [[4, 7, 3, 7, 9],\n# [1, 2, 8, 6, 9],\n# [9, 4, 1, 8, 7],\n# [4, 3, 4, 2, 4]]\n# expect result:\n# [[0, 0, 0, 0, 0],\n# [0, 0, 0, 0, 0],\n# [0, 0, 0, 0, 0],\n# [0, 0, 0, 0, 0]]\ny = tril_reference_implementation(x, int(k))\nexpect(node, inputs=[x, k], outputs=[y], name='test_tril_out_neg')" + }, + { + "summary": "tril_out_pos", + "code": "node = onnx.helper.make_node(\n 'Trilu',\n inputs=['x', 'k'],\n outputs=['y'],\n upper=0,\n)\nx = np.random.randint(10, size=(4, 5)).astype(np.int64)\nk = np.array(6).astype(np.int64)\n# X:\n# [[4, 7, 3, 7, 9],\n# [1, 2, 8, 6, 9],\n# [9, 4, 1, 8, 7],\n# [4, 3, 4, 2, 4]]\n# expect result:\n# [[4, 7, 3, 7, 9],\n# [1, 2, 8, 6, 9],\n# [9, 4, 1, 8, 7],\n# [4, 3, 4, 2, 4]]\ny = tril_reference_implementation(x, int(k))\nexpect(node, inputs=[x, k], outputs=[y], name='test_tril_out_pos')" + }, + { + "summary": "tril_pos", + "code": "node = onnx.helper.make_node(\n 'Trilu',\n inputs=['x', 'k'],\n outputs=['y'],\n upper=0,\n)\n\nx = np.random.randint(10, size=(4, 5)).astype(np.int64)\nk = np.array(2).astype(np.int64)\n# X:\n# [[4, 7, 3, 7, 9],\n# [1, 2, 8, 6, 9],\n# [9, 4, 1, 8, 7],\n# [4, 3, 4, 2, 4]]\n# expect result:\n# [[4, 7, 3, 0, 0],\n# [1, 2, 8, 6, 0],\n# [9, 4, 1, 8, 7],\n# [4, 3, 4, 2, 4]]\ny = tril_reference_implementation(x, int(k))\nexpect(node, inputs=[x, k], outputs=[y], name='test_tril_pos')" + }, + { + "summary": "tril_square", + "code": "node = onnx.helper.make_node(\n 'Trilu',\n inputs=['x'],\n outputs=['y'],\n upper=0,\n)\n\nx = np.random.randint(10, size=(2, 3, 3)).astype(np.int64)\n# X:\n# [[[0, 4, 3],\n# [2, 0, 9],\n# [8, 2, 5]],\n#\n# [[2, 7, 2],\n# [2, 6, 0],\n# [2, 6, 5]]]\n# expect result:\n# [[[0, 0, 0],\n# [2, 0, 0],\n# [8, 2, 5]],\n#\n# [[2, 0, 0],\n# [2, 6, 0],\n# [2, 6, 5]]]\ny = tril_reference_implementation(x)\nexpect(node, inputs=[x], outputs=[y], name='test_tril_square')" + }, + { + "summary": "tril_square_neg", + "code": "node = onnx.helper.make_node(\n 'Trilu',\n inputs=['x', 'k'],\n outputs=['y'],\n upper=0,\n)\n\nx = np.random.randint(10, size=(2, 3, 3)).astype(np.int64)\nk = np.array(-1).astype(np.int64)\n# X:\n# [[[0, 4, 3],\n# [2, 0, 9],\n# [8, 2, 5]],\n#\n# [[2, 7, 2],\n# [2, 6, 0],\n# [2, 6, 5]]]\n# expect result:\n# [[[0, 0, 0],\n# [2, 0, 0],\n# [8, 2, 0]],\n#\n# [[0, 0, 0],\n# [2, 0, 0],\n# [2, 6, 0]]]\ny = tril_reference_implementation(x, int(k))\nexpect(node, inputs=[x, k], outputs=[y], name='test_tril_square_neg')" + }, + { + "summary": "tril_zero", + "code": "node = onnx.helper.make_node(\n 'Trilu',\n inputs=['x', 'k'],\n outputs=['y'],\n upper=0,\n)\n\nx = np.random.randint(10, size=(3, 0, 5)).astype(np.int64)\nk = np.array(6).astype(np.int64)\n# X:\n# []\n# expect result:\n# []\ny = tril_reference_implementation(x, int(k))\nexpect(node, inputs=[x, k], outputs=[y], name='test_tril_zero')" + }, + { + "summary": "triu", + "code": "node = onnx.helper.make_node(\n 'Trilu',\n inputs=['x'],\n outputs=['y'],\n)\n\nx = np.random.randint(10, size=(4, 5)).astype(np.int64)\n# X:\n# [[4, 7, 3, 7, 9],\n# [1, 2, 8, 6, 9],\n# [9, 4, 0, 8, 7],\n# [4, 3, 4, 2, 4]]\n# expect result:\n# [[4, 7, 3, 7, 9],\n# [0, 2, 8, 6, 9],\n# [0, 0, 0, 8, 7],\n# [0, 0, 0, 2, 4]]\ny = triu_reference_implementation(x)\nexpect(node, inputs=[x], outputs=[y], name='test_triu')" + }, + { + "summary": "triu_neg", + "code": "node = onnx.helper.make_node(\n 'Trilu',\n inputs=['x', 'k'],\n outputs=['y'],\n)\n\nx = np.random.randint(10, size=(4, 5)).astype(np.int64)\nk = np.array(-1).astype(np.int64)\n# X:\n# [[4, 7, 3, 7, 9],\n# [1, 2, 8, 6, 9],\n# [9, 4, 0, 8, 7],\n# [4, 3, 4, 2, 4]]\n# expect result:\n# [[4, 7, 3, 7, 9],\n# [1, 2, 8, 6, 9],\n# [0, 4, 0, 8, 7],\n# [0, 0, 4, 2, 4]]\ny = triu_reference_implementation(x, int(k))\nexpect(node, inputs=[x, k], outputs=[y], name='test_triu_neg')" + }, + { + "summary": "triu_one_row", + "code": "node = onnx.helper.make_node(\n 'Trilu',\n inputs=['x', 'k'],\n outputs=['y'],\n)\n\nx = np.random.randint(10, size=(3, 1, 5)).astype(np.int64)\nk = np.array(1).astype(np.int64)\n# X:\n# [[[1, 4, 9, 7, 1]],\n#\n# [[9, 2, 8, 8, 4]],\n#\n# [[3, 9, 7, 4, 2]]]\n# expect result:\n# [[[0, 4, 9, 7, 1]],\n#\n# [[0, 2, 8, 8, 4]],\n#\n# [[0, 9, 7, 4, 2]]]\ny = triu_reference_implementation(x, int(k))\nexpect(node, inputs=[x, k], outputs=[y], name='test_triu_one_row')" + }, + { + "summary": "triu_out_neg_out", + "code": "node = onnx.helper.make_node(\n 'Trilu',\n inputs=['x', 'k'],\n outputs=['y'],\n)\n\nx = np.random.randint(10, size=(4, 5)).astype(np.int64)\nk = np.array(-7).astype(np.int64)\n# X:\n# [[4, 7, 3, 7, 9],\n# [1, 2, 8, 6, 9],\n# [9, 4, 0, 8, 7],\n# [4, 3, 4, 2, 4]]\n# expect result:\n# [[4, 7, 3, 7, 9],\n# [1, 2, 8, 6, 9],\n# [9, 4, 0, 8, 7],\n# [4, 3, 4, 2, 4]]\ny = triu_reference_implementation(x, int(k))\nexpect(node, inputs=[x, k], outputs=[y], name='test_triu_out_neg_out')" + }, + { + "summary": "triu_out_pos", + "code": "node = onnx.helper.make_node(\n 'Trilu',\n inputs=['x', 'k'],\n outputs=['y'],\n)\n\nx = np.random.randint(10, size=(4, 5)).astype(np.int64)\nk = np.array(6).astype(np.int64)\n# X:\n# [[4, 7, 3, 7, 9],\n# [1, 2, 8, 6, 9],\n# [9, 4, 0, 8, 7],\n# [4, 3, 4, 2, 4]]\n# expect result:\n# [[0, 0, 0, 0, 0],\n# [0, 0, 0, 0, 0],\n# [0, 0, 0, 0, 0],\n# [0, 0, 0, 0, 0]]\ny = triu_reference_implementation(x, int(k))\nexpect(node, inputs=[x, k], outputs=[y], name='test_triu_out_pos')" + }, + { + "summary": "triu_pos", + "code": "node = onnx.helper.make_node(\n 'Trilu',\n inputs=['x', 'k'],\n outputs=['y'],\n)\n\nx = np.random.randint(10, size=(4, 5)).astype(np.int64)\nk = np.array(2).astype(np.int64)\n# X:\n# [[4, 7, 3, 7, 9],\n# [1, 2, 8, 6, 9],\n# [9, 4, 0, 8, 7],\n# [4, 3, 4, 2, 4]]\n# expect result:\n# [[0, 0, 3, 7, 9],\n# [0, 0, 0, 6, 9],\n# [0, 0, 0, 0, 7],\n# [0, 0, 0, 0, 0]]\ny = triu_reference_implementation(x, int(k))\nexpect(node, inputs=[x, k], outputs=[y], name='test_triu_pos')" + }, + { + "summary": "triu_square", + "code": "node = onnx.helper.make_node(\n 'Trilu',\n inputs=['x'],\n outputs=['y'],\n)\n\nx = np.random.randint(10, size=(2, 3, 3)).astype(np.int64)\ny = triu_reference_implementation(x)\n# X:\n# [[[4, 6, 9],\n# [7, 5, 4],\n# [8, 1, 2]],\n#\n# [[1, 4, 9],\n# [9, 6, 3],\n# [8, 9, 8]]]\n# expect result:\n# [[[4, 6, 9],\n# [0, 5, 4],\n# [0, 0, 2]],\n#\n# [[1, 4, 9],\n# [0, 6, 3],\n# [0, 0, 8]]]\nexpect(node, inputs=[x], outputs=[y], name='test_triu_square')" + }, + { + "summary": "triu_square_neg", + "code": "node = onnx.helper.make_node(\n 'Trilu',\n inputs=['x', 'k'],\n outputs=['y'],\n)\n\nx = np.random.randint(10, size=(2, 3, 3)).astype(np.int64)\nk = np.array(-1).astype(np.int64)\n# X:\n# [[[4, 6, 9],\n# [7, 5, 4],\n# [8, 1, 2]],\n#\n# [[1, 4, 9],\n# [9, 6, 3],\n# [8, 9, 8]]]\n# expect result:\n# [[[4, 6, 9],\n# [7, 5, 4],\n# [0, 1, 2]],\n#\n# [[1, 4, 9],\n# [9, 6, 3],\n# [0, 9, 8]]]\ny = triu_reference_implementation(x, int(k))\nexpect(node, inputs=[x, k], outputs=[y], name='test_triu_square_neg')" + }, + { + "summary": "triu_zero", + "code": "node = onnx.helper.make_node(\n 'Trilu',\n inputs=['x', 'k'],\n outputs=['y'],\n)\n\nx = np.random.randint(10, size=(0, 5)).astype(np.int64)\nk = np.array(6).astype(np.int64)\n# X:\n# []\n# expect result:\n# []\ny = triu_reference_implementation(x, int(k))\nexpect(node, inputs=[x, k], outputs=[y], name='test_triu_zero')" + } + ] + }, + { + "name": "Unique", + "module": "ai.onnx", + "version": 11, + "support_level": "common", + "description": "Find the unique elements of a tensor. When an optional attribute 'axis' is provided, unique subtensors sliced along the 'axis' are returned.\nOtherwise the input tensor is flattened and unique values of the flattened tensor are returned.\n\nThis operator returns the unique values or sliced unique subtensors of the input tensor and three optional outputs.\nThe first output tensor 'Y' contains all unique values or subtensors of the input.\nThe second optional output tensor 'indices' contains indices of 'Y' elements' first occurance in 'X'..\nThe third optional output tensor 'inverse_indices' contains, for elements of 'X', its corresponding indices in 'Y'. \".\nThe fourth optional output tensor 'counts' contains the count of each element of 'Y' in the input.\n\nOutputs are either sorted in ascending order or optionally in the order of the first occurrence of the values in the input.\n\nhttps://docs.scipy.org/doc/numpy/reference/generated/numpy.unique.html\n\nExample 1:\n input_X = [2, 1, 1, 3, 4, 3]\n attribute_sorted = 0\n attribute_axis = None\n output_Y = [2, 1, 3, 4]\n output_indices = [0, 1, 3, 4]\n output_inverse_indices = [0, 1, 1, 2, 3, 2]\n output_counts = [1, 2, 2, 1]\n\nExample 2:\n input_X = [[1, 3], [2, 3]]\n attribute_sorted = 1\n attribute_axis = None\n output_Y = [1, 2, 3]\n output_indices = [0, 2, 1]\n output_inverse_indices = [0, 2, 1, 2]\n output_counts = [1, 1, 2]\n\nExample 3:\n input_X = [[1, 0, 0], [1, 0, 0], [2, 3, 4]]\n attribute_sorted = 1\n attribute_axis = 0\n output_Y = [[1, 0, 0], [2, 3, 4]]\n output_indices = [0, 2]\n output_inverse_indices = [0, 0, 1]\n output_counts = [2, 1]\n\nExample 4:\n input_x = [[[1., 1.], [0., 1.], [2., 1.], [0., 1.]],\n [[1., 1.], [0., 1.], [2., 1.], [0., 1.]]]\n attribute_sorted = 1\n attribute_axis = 1\n\n intermediate data are presented below for better understanding:\n\n there are 4 subtensors sliced along axis 1 of input_x (shape = (2, 4, 2)):\n A: [[1, 1], [1, 1]],\n [[0, 1], [0, 1]],\n [[2, 1], [2, 1]],\n [[0, 1], [0, 1]].\n\n there are 3 unique subtensors:\n [[1, 1], [1, 1]],\n [[0, 1], [0, 1]],\n [[2, 1], [2, 1]].\n\n sorted unique subtensors:\n B: [[0, 1], [0, 1]],\n [[1, 1], [1, 1]],\n [[2, 1], [2, 1]].\n\n output_Y is constructed from B:\n [[[0. 1.], [1. 1.], [2. 1.]],\n [[0. 1.], [1. 1.], [2. 1.]]]\n\n output_indices is to map from B to A:\n [1, 0, 2]\n\n output_inverse_indices is to map from A to B:\n [1, 0, 2, 0]\n\n output_counts = [2 1 1]\n", + "attributes": [ + { + "name": "axis", + "type": "int64", + "required": false, + "description": "(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)." + }, + { + "name": "sorted", + "type": "int64", + "required": false, + "default": 1, + "description": "(Optional) Whether to sort the unique elements in ascending order before returning as output. Must be one of 0, or 1 (default)." + } + ], + "inputs": [ + { + "name": "X", + "type": "T", + "description": "A N-D input tensor that is to be processed." + } + ], + "min_input": 1, + "max_input": 1, + "outputs": [ + { + "name": "Y", + "type": "T", + "description": "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'" + }, + { + "name": "indices", + "type": "tensor(int64)", + "option": "optional", + "description": "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. " + }, + { + "name": "inverse_indices", + "type": "tensor(int64)", + "option": "optional", + "description": "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'. " + }, + { + "name": "counts", + "type": "tensor(int64)", + "option": "optional", + "description": "A 1-D INT64 tensor containing the count of each element of 'Y' in input 'X'" + } + ], + "min_output": 1, + "max_output": 4, + "outputs_range": "1 - 4", + "type_constraints": [ + { + "description": "Input can be of any tensor type.", + "type_param_str": "T", + "allowed_type_strs": [ + "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)" + ] + } + ], + "examples": [ + { + "summary": "not_sorted_without_axis", + "code": "node_not_sorted = onnx.helper.make_node(\n 'Unique',\n inputs=['X'],\n outputs=['Y', 'indices', 'inverse_indices', 'counts'],\n sorted=0\n)\n# numpy unique does not retain original order (it sorts the output unique values)\n# https://github.com/numpy/numpy/issues/8621\n# we need to recover unsorted output and indices\nx = np.array([2.0, 1.0, 1.0, 3.0, 4.0, 3.0], dtype=np.float32)\ny, indices, inverse_indices, counts = np.unique(x, True, True, True)\n\n# prepare index mapping from sorted to unsorted\nargsorted_indices = np.argsort(indices)\ninverse_indices_map = {i: si for i, si in zip(argsorted_indices, np.arange(len(argsorted_indices)))}\n\nindices = indices[argsorted_indices]\ny = np.take(x, indices, axis=0)\ninverse_indices = np.asarray([inverse_indices_map[i] for i in inverse_indices], dtype=np.int64)\ncounts = counts[argsorted_indices]\nindices, inverse_indices, counts = specify_int64(indices, inverse_indices, counts)\n# print(y)\n# [2.0, 1.0, 3.0, 4.0]\n# print(indices)\n# [0 1 3 4]\n# print(inverse_indices)\n# [0, 1, 1, 2, 3, 2]\n# print(counts)\n# [1, 2, 2, 1]\n\nexpect(node_not_sorted, inputs=[x], outputs=[y, indices, inverse_indices, counts], name='test_unique_not_sorted_without_axis')" + }, + { + "summary": "sorted_with_axis", + "code": "node_sorted = onnx.helper.make_node(\n 'Unique',\n inputs=['X'],\n outputs=['Y', 'indices', 'inverse_indices', 'counts'],\n sorted=1,\n axis=0\n)\n\nx = np.array([[1, 0, 0], [1, 0, 0], [2, 3, 4]], dtype=np.float32)\ny, indices, inverse_indices, counts = np.unique(x, True, True, True, axis=0)\nindices, inverse_indices, counts = specify_int64(indices, inverse_indices, counts)\n# print(y)\n# [[1. 0. 0.]\n# [2. 3. 4.]]\n# print(indices)\n# [0 2]\n# print(inverse_indices)\n# [0 0 1]\n# print(counts)\n# [2 1]\n\nexpect(node_sorted, inputs=[x], outputs=[y, indices, inverse_indices, counts], name='test_unique_sorted_with_axis')" + }, + { + "summary": "sorted_with_axis_3d", + "code": "node_sorted = onnx.helper.make_node(\n 'Unique',\n inputs=['X'],\n outputs=['Y', 'indices', 'inverse_indices', 'counts'],\n sorted=1,\n axis=1\n)\n\nx = np.array([[[1., 1.], [0., 1.], [2., 1.], [0., 1.]],\n [[1., 1.], [0., 1.], [2., 1.], [0., 1.]]], dtype=np.float32)\ny, indices, inverse_indices, counts = np.unique(x, True, True, True, axis=1)\nindices, inverse_indices, counts = specify_int64(indices, inverse_indices, counts)\n# print(y)\n# [[[0. 1.]\n# [1. 1.]\n# [2. 1.]]\n# [[0. 1.]\n# [1. 1.]\n# [2. 1.]]]\n# print(indices)\n# [1 0 2]\n# print(inverse_indices)\n# [1 0 2 0]\n# print(counts)\n# [2 1 1]\nexpect(node_sorted, inputs=[x], outputs=[y, indices, inverse_indices, counts], name='test_unique_sorted_with_axis_3d')" + }, + { + "summary": "sorted_with_negative_axis", + "code": "node_sorted = onnx.helper.make_node(\n 'Unique',\n inputs=['X'],\n outputs=['Y', 'indices', 'inverse_indices', 'counts'],\n sorted=1,\n axis=-1\n)\n\nx = np.array([[1, 0, 0], [1, 0, 0], [2, 3, 3]], dtype=np.float32)\ny, indices, inverse_indices, counts = np.unique(x, True, True, True, axis=-1)\nindices, inverse_indices, counts = specify_int64(indices, inverse_indices, counts)\n# print(y)\n# [[0. 1.]\n# [0. 1.]\n# [3. 2.]]\n# print(indices)\n# [1 0]\n# print(inverse_indices)\n# [1 0 0]\n# print(counts)\n# [2 1]\n\nexpect(node_sorted, inputs=[x], outputs=[y, indices, inverse_indices, counts], name='test_unique_sorted_with_negative_axis')" + }, + { + "summary": "sorted_without_axis", + "code": "node_sorted = onnx.helper.make_node(\n 'Unique',\n inputs=['X'],\n outputs=['Y', 'indices', 'inverse_indices', 'counts']\n)\n\nx = np.array([2.0, 1.0, 1.0, 3.0, 4.0, 3.0], dtype=np.float32)\ny, indices, inverse_indices, counts = np.unique(x, True, True, True)\nindices, inverse_indices, counts = specify_int64(indices, inverse_indices, counts)\nexpect(node_sorted, inputs=[x], outputs=[y, indices, inverse_indices, counts], name='test_unique_sorted_without_axis')" + } + ] + }, + { + "name": "Unsqueeze", + "module": "ai.onnx", + "version": 1, + "support_level": "common", + "description": "Insert single-dimensional entries to the shape of a tensor.\nTakes one required argument `axes`, a list of dimensions that will be inserted.\nDimension indices in `axes` are as seen in the output tensor. For example:\n Given a tensor such that tensor with shape [3, 4, 5], then\n Unsqueeze(tensor, axes=[0, 4]) has shape [1, 3, 4, 5, 1]\n", + "attributes": [ + { + "name": "axes", + "type": "int64[]", + "required": true, + "description": "List of non-negative integers, indicate the dimensions to be inserted" + } + ], + "inputs": [ + { + "name": "data", + "type": "T", + "description": "Original tensor" + } + ], + "min_input": 1, + "max_input": 1, + "outputs": [ + { + "name": "expanded", + "type": "T", + "description": "Reshaped tensor with same data as input." + } + ], + "min_output": 1, + "max_output": 1, + "type_constraints": [ + { + "description": "Constrain input and output types to all tensor types.", + "type_param_str": "T", + "allowed_type_strs": [ + "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)" + ] + } + ], + "examples": [ + { + "summary": "unsqueeze_negative_axes", + "code": "node = onnx.helper.make_node(\n 'Unsqueeze',\n inputs=['x', 'axes'],\n outputs=['y'],\n)\nx = np.random.randn(1, 3, 1, 5).astype(np.float32)\naxes = np.array([-2]).astype(np.int64)\ny = np.expand_dims(x, axis=-2)\nexpect(node, inputs=[x, axes], outputs=[y],\n name='test_unsqueeze_negative_axes')" + }, + { + "summary": "unsqueeze_one_axis", + "code": "x = np.random.randn(3, 4, 5).astype(np.float32)\n\nfor i in range(x.ndim):\n axes = np.array([i]).astype(np.int64)\n node = onnx.helper.make_node(\n 'Unsqueeze',\n inputs=['x', 'axes'],\n outputs=['y'],\n )\n y = np.expand_dims(x, axis=i)\n\n expect(node, inputs=[x, axes], outputs=[y],\n name='test_unsqueeze_axis_' + str(i))" + }, + { + "summary": "unsqueeze_three_axes", + "code": "x = np.random.randn(3, 4, 5).astype(np.float32)\naxes = np.array([2, 4, 5]).astype(np.int64)\n\nnode = onnx.helper.make_node(\n 'Unsqueeze',\n inputs=['x', 'axes'],\n outputs=['y'],\n)\ny = np.expand_dims(x, axis=2)\ny = np.expand_dims(y, axis=4)\ny = np.expand_dims(y, axis=5)\n\nexpect(node, inputs=[x, axes], outputs=[y],\n name='test_unsqueeze_three_axes')" + }, + { + "summary": "unsqueeze_two_axes", + "code": "x = np.random.randn(3, 4, 5).astype(np.float32)\naxes = np.array([1, 4]).astype(np.int64)\n\nnode = onnx.helper.make_node(\n 'Unsqueeze',\n inputs=['x', 'axes'],\n outputs=['y'],\n)\ny = np.expand_dims(x, axis=1)\ny = np.expand_dims(y, axis=4)\n\nexpect(node, inputs=[x, axes], outputs=[y],\n name='test_unsqueeze_two_axes')" + }, + { + "summary": "unsqueeze_unsorted_axes", + "code": "x = np.random.randn(3, 4, 5).astype(np.float32)\naxes = np.array([5, 4, 2]).astype(np.int64)\n\nnode = onnx.helper.make_node(\n 'Unsqueeze',\n inputs=['x', 'axes'],\n outputs=['y'],\n)\ny = np.expand_dims(x, axis=2)\ny = np.expand_dims(y, axis=4)\ny = np.expand_dims(y, axis=5)\n\nexpect(node, inputs=[x, axes], outputs=[y],\n name='test_unsqueeze_unsorted_axes')" + } + ], + "category": "Transform" + }, + { + "name": "Unsqueeze", + "module": "ai.onnx", + "version": 11, + "support_level": "common", + "description": "Insert single-dimensional entries to the shape of an input tensor (`data`).\nTakes 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`).\n\nFor example:\n Given an input tensor (`data`) of shape [3, 4, 5], then\n Unsqueeze(data, axes=[0, 4]) outputs a tensor (`expanded`) containing same data as `data` but with shape [1, 3, 4, 5, 1].\n\nThe attribute `axes` should not contain any duplicate entries. It is an error if it contains duplicates.\nThe rank of the output tensor (`output_rank`) is the rank of the input tensor (`data`) plus the number of values in `axes`.\nEach value in `axes` should be within the (inclusive) range [-output_rank , output_rank - 1].\nThe order of values in `axes` does not matter and can come in any order.\n\n", + "attributes": [ + { + "name": "axes", + "type": "int64[]", + "required": true, + "description": "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": [ + { + "name": "data", + "type": "T", + "description": "Original tensor" + } + ], + "min_input": 1, + "max_input": 1, + "outputs": [ + { + "name": "expanded", + "type": "T", + "description": "Reshaped tensor with same data as input." + } + ], + "min_output": 1, + "max_output": 1, + "type_constraints": [ + { + "description": "Constrain input and output types to all tensor types.", + "type_param_str": "T", + "allowed_type_strs": [ + "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)" + ] + } + ], + "examples": [ + { + "summary": "unsqueeze_negative_axes", + "code": "node = onnx.helper.make_node(\n 'Unsqueeze',\n inputs=['x', 'axes'],\n outputs=['y'],\n)\nx = np.random.randn(1, 3, 1, 5).astype(np.float32)\naxes = np.array([-2]).astype(np.int64)\ny = np.expand_dims(x, axis=-2)\nexpect(node, inputs=[x, axes], outputs=[y],\n name='test_unsqueeze_negative_axes')" + }, + { + "summary": "unsqueeze_one_axis", + "code": "x = np.random.randn(3, 4, 5).astype(np.float32)\n\nfor i in range(x.ndim):\n axes = np.array([i]).astype(np.int64)\n node = onnx.helper.make_node(\n 'Unsqueeze',\n inputs=['x', 'axes'],\n outputs=['y'],\n )\n y = np.expand_dims(x, axis=i)\n\n expect(node, inputs=[x, axes], outputs=[y],\n name='test_unsqueeze_axis_' + str(i))" + }, + { + "summary": "unsqueeze_three_axes", + "code": "x = np.random.randn(3, 4, 5).astype(np.float32)\naxes = np.array([2, 4, 5]).astype(np.int64)\n\nnode = onnx.helper.make_node(\n 'Unsqueeze',\n inputs=['x', 'axes'],\n outputs=['y'],\n)\ny = np.expand_dims(x, axis=2)\ny = np.expand_dims(y, axis=4)\ny = np.expand_dims(y, axis=5)\n\nexpect(node, inputs=[x, axes], outputs=[y],\n name='test_unsqueeze_three_axes')" + }, + { + "summary": "unsqueeze_two_axes", + "code": "x = np.random.randn(3, 4, 5).astype(np.float32)\naxes = np.array([1, 4]).astype(np.int64)\n\nnode = onnx.helper.make_node(\n 'Unsqueeze',\n inputs=['x', 'axes'],\n outputs=['y'],\n)\ny = np.expand_dims(x, axis=1)\ny = np.expand_dims(y, axis=4)\n\nexpect(node, inputs=[x, axes], outputs=[y],\n name='test_unsqueeze_two_axes')" + }, + { + "summary": "unsqueeze_unsorted_axes", + "code": "x = np.random.randn(3, 4, 5).astype(np.float32)\naxes = np.array([5, 4, 2]).astype(np.int64)\n\nnode = onnx.helper.make_node(\n 'Unsqueeze',\n inputs=['x', 'axes'],\n outputs=['y'],\n)\ny = np.expand_dims(x, axis=2)\ny = np.expand_dims(y, axis=4)\ny = np.expand_dims(y, axis=5)\n\nexpect(node, inputs=[x, axes], outputs=[y],\n name='test_unsqueeze_unsorted_axes')" + } + ], + "category": "Transform" + }, + { + "name": "Unsqueeze", + "module": "ai.onnx", + "version": 13, + "support_level": "common", + "description": "Insert single-dimensional entries to the shape of an input tensor (`data`).\nTakes 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`).\n\nFor example:\n Given an input tensor (`data`) of shape [3, 4, 5], then\n Unsqueeze(data, axes=[0, 4]) outputs a tensor (`expanded`) containing same data as `data` but with shape [1, 3, 4, 5, 1].\n\nThe input `axes` should not contain any duplicate entries. It is an error if it contains duplicates.\nThe rank of the output tensor (`output_rank`) is the rank of the input tensor (`data`) plus the number of values in `axes`.\nEach value in `axes` should be within the (inclusive) range [-output_rank , output_rank - 1].\nThe order of values in `axes` does not matter and can come in any order.\n\n", + "inputs": [ + { + "name": "data", + "type": "T", + "description": "Original tensor" + }, + { + "name": "axes", + "type": "tensor(int64)", + "description": "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)." + } + ], + "min_input": 2, + "max_input": 2, + "outputs": [ + { + "name": "expanded", + "type": "T", + "description": "Reshaped tensor with same data as input." + } + ], + "min_output": 1, + "max_output": 1, + "type_constraints": [ + { + "description": "Constrain input and output types to all tensor types.", + "type_param_str": "T", + "allowed_type_strs": [ + "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)" + ] + } + ], + "examples": [ + { + "summary": "unsqueeze_negative_axes", + "code": "node = onnx.helper.make_node(\n 'Unsqueeze',\n inputs=['x', 'axes'],\n outputs=['y'],\n)\nx = np.random.randn(1, 3, 1, 5).astype(np.float32)\naxes = np.array([-2]).astype(np.int64)\ny = np.expand_dims(x, axis=-2)\nexpect(node, inputs=[x, axes], outputs=[y],\n name='test_unsqueeze_negative_axes')" + }, + { + "summary": "unsqueeze_one_axis", + "code": "x = np.random.randn(3, 4, 5).astype(np.float32)\n\nfor i in range(x.ndim):\n axes = np.array([i]).astype(np.int64)\n node = onnx.helper.make_node(\n 'Unsqueeze',\n inputs=['x', 'axes'],\n outputs=['y'],\n )\n y = np.expand_dims(x, axis=i)\n\n expect(node, inputs=[x, axes], outputs=[y],\n name='test_unsqueeze_axis_' + str(i))" + }, + { + "summary": "unsqueeze_three_axes", + "code": "x = np.random.randn(3, 4, 5).astype(np.float32)\naxes = np.array([2, 4, 5]).astype(np.int64)\n\nnode = onnx.helper.make_node(\n 'Unsqueeze',\n inputs=['x', 'axes'],\n outputs=['y'],\n)\ny = np.expand_dims(x, axis=2)\ny = np.expand_dims(y, axis=4)\ny = np.expand_dims(y, axis=5)\n\nexpect(node, inputs=[x, axes], outputs=[y],\n name='test_unsqueeze_three_axes')" + }, + { + "summary": "unsqueeze_two_axes", + "code": "x = np.random.randn(3, 4, 5).astype(np.float32)\naxes = np.array([1, 4]).astype(np.int64)\n\nnode = onnx.helper.make_node(\n 'Unsqueeze',\n inputs=['x', 'axes'],\n outputs=['y'],\n)\ny = np.expand_dims(x, axis=1)\ny = np.expand_dims(y, axis=4)\n\nexpect(node, inputs=[x, axes], outputs=[y],\n name='test_unsqueeze_two_axes')" + }, + { + "summary": "unsqueeze_unsorted_axes", + "code": "x = np.random.randn(3, 4, 5).astype(np.float32)\naxes = np.array([5, 4, 2]).astype(np.int64)\n\nnode = onnx.helper.make_node(\n 'Unsqueeze',\n inputs=['x', 'axes'],\n outputs=['y'],\n)\ny = np.expand_dims(x, axis=2)\ny = np.expand_dims(y, axis=4)\ny = np.expand_dims(y, axis=5)\n\nexpect(node, inputs=[x, axes], outputs=[y],\n name='test_unsqueeze_unsorted_axes')" + } + ], + "category": "Transform" + }, + { + "name": "Upsample", + "module": "ai.onnx", + "version": 1, + "support_level": "experimental", + "description": "Upsample the input tensor.\nThe width and height of the output tensor are:\n output_width = floor(input_width * width_scale),\n output_height = floor(input_height * height_scale).\nExample:\n Given `data` tensor, width_scale, height_scale, mode,\n Upsample the input 4-D tensor in nearest mode:\n data = [[[\n [1, 2],\n [3, 4]\n ]]]\n width_scale = 2\n height_scale = 2\n mode = \"nearest\"\n output = [[[\n [1, 1, 2, 2],\n [1, 1, 2, 2],\n [3, 3, 4, 4],\n [3, 3, 4, 4]\n ]]]\n", + "attributes": [ + { + "name": "height_scale", + "type": "float32", + "required": true, + "description": "The scale along height dimension. It takes value greater than or equal to 1." + }, + { + "name": "mode", + "type": "string", + "required": false, + "default": "nearest", + "description": "Two interpolation modes: nearest(default), bilinear" + }, + { + "name": "width_scale", + "type": "float32", + "required": true, + "description": "The scale along width dimension. It takes value greater than or equal to 1." + } + ], + "inputs": [ + { + "name": "X", + "type": "T", + "description": "4-D tensor, [N,C,H,W]" + } + ], + "min_input": 1, + "max_input": 1, + "outputs": [ + { + "name": "Y", + "type": "T", + "description": "4-D tensor after resizing, [N,C,H,W]" + } + ], + "min_output": 1, + "max_output": 1, + "type_constraints": [ + { + "description": "Constrain output types to bool, int32, int64, float16, float, double tensors.", + "type_param_str": "T", + "allowed_type_strs": [ + "tensor(bool)", + "tensor(int32)", + "tensor(int64)", + "tensor(float16)", + "tensor(float)", + "tensor(double)" + ] + } + ], + "examples": [ + { + "summary": "nearest", + "code": "node = onnx.helper.make_node(\n 'Upsample',\n inputs=['X', 'scales'],\n outputs=['Y'],\n mode='nearest',\n)\n\ndata = np.array([[[\n [1, 2],\n [3, 4],\n]]], dtype=np.float32)\n\nscales = np.array([1.0, 1.0, 2.0, 3.0], dtype=np.float32)\n\noutput = np.array([[[\n [1, 1, 1, 2, 2, 2],\n [1, 1, 1, 2, 2, 2],\n [3, 3, 3, 4, 4, 4],\n [3, 3, 3, 4, 4, 4],\n]]], dtype=np.float32)\n\nexpect(node, inputs=[data, scales], outputs=[output],\n name='test_upsample_nearest', opset_imports=[helper.make_opsetid(\"\", 9)])" + } + ], + "category": "Data" + }, + { + "name": "Upsample", + "module": "ai.onnx", + "version": 7, + "support_level": "common", + "description": "Upsample the input tensor.\nEach dimension value of the output tensor is:\n output_dimension = floor(input_dimension * scale).\n", + "attributes": [ + { + "name": "mode", + "type": "string", + "required": false, + "default": "nearest", + "description": "Two interpolation modes: nearest (default), and linear (including bilinear, trilinear, etc)" + }, + { + "name": "scales", + "type": "float32[]", + "required": true, + "description": "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": [ + { + "name": "X", + "type": "T", + "description": "N-D tensor" + } + ], + "min_input": 1, + "max_input": 1, + "outputs": [ + { + "name": "Y", + "type": "T", + "description": "N-D tensor after resizing" + } + ], + "min_output": 1, + "max_output": 1, + "type_constraints": [ + { + "description": "Constrain input and output types to all tensor types.", + "type_param_str": "T", + "allowed_type_strs": [ + "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)" + ] + } + ], + "examples": [ + { + "summary": "nearest", + "code": "node = onnx.helper.make_node(\n 'Upsample',\n inputs=['X', 'scales'],\n outputs=['Y'],\n mode='nearest',\n)\n\ndata = np.array([[[\n [1, 2],\n [3, 4],\n]]], dtype=np.float32)\n\nscales = np.array([1.0, 1.0, 2.0, 3.0], dtype=np.float32)\n\noutput = np.array([[[\n [1, 1, 1, 2, 2, 2],\n [1, 1, 1, 2, 2, 2],\n [3, 3, 3, 4, 4, 4],\n [3, 3, 3, 4, 4, 4],\n]]], dtype=np.float32)\n\nexpect(node, inputs=[data, scales], outputs=[output],\n name='test_upsample_nearest', opset_imports=[helper.make_opsetid(\"\", 9)])" + } + ], + "category": "Data" + }, + { + "name": "Upsample", + "module": "ai.onnx", + "version": 9, + "support_level": "common", + "description": "Upsample the input tensor.\nEach dimension value of the output tensor is:\n output_dimension = floor(input_dimension * scale).\n", + "attributes": [ + { + "name": "mode", + "type": "string", + "required": false, + "default": "nearest", + "description": "Two interpolation modes: nearest (default), and linear (including bilinear, trilinear, etc)" + } + ], + "inputs": [ + { + "name": "X", + "type": "T", + "description": "N-D tensor" + }, + { + "name": "scales", + "type": "tensor(float)", + "description": "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'." + } + ], + "min_input": 2, + "max_input": 2, + "outputs": [ + { + "name": "Y", + "type": "T", + "description": "N-D tensor after resizing" + } + ], + "min_output": 1, + "max_output": 1, + "type_constraints": [ + { + "description": "Constrain input 'X' and output 'Y' to all tensor types.", + "type_param_str": "T", + "allowed_type_strs": [ + "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)" + ] + } + ], + "examples": [ + { + "summary": "nearest", + "code": "node = onnx.helper.make_node(\n 'Upsample',\n inputs=['X', 'scales'],\n outputs=['Y'],\n mode='nearest',\n)\n\ndata = np.array([[[\n [1, 2],\n [3, 4],\n]]], dtype=np.float32)\n\nscales = np.array([1.0, 1.0, 2.0, 3.0], dtype=np.float32)\n\noutput = np.array([[[\n [1, 1, 1, 2, 2, 2],\n [1, 1, 1, 2, 2, 2],\n [3, 3, 3, 4, 4, 4],\n [3, 3, 3, 4, 4, 4],\n]]], dtype=np.float32)\n\nexpect(node, inputs=[data, scales], outputs=[output],\n name='test_upsample_nearest', opset_imports=[helper.make_opsetid(\"\", 9)])" + } + ], + "category": "Data" + }, + { + "name": "Upsample", + "module": "ai.onnx", + "version": 10, + "support_level": "common", + "description": "Upsample the input tensor.\nEach dimension value of the output tensor is:\n output_dimension = floor(input_dimension * scale).\n", + "attributes": [ + { + "name": "mode", + "type": "string", + "required": false, + "default": "nearest", + "description": "Two interpolation modes: nearest (default), and linear (including bilinear, trilinear, etc)" + } + ], + "inputs": [ + { + "name": "X", + "type": "T", + "description": "N-D tensor" + }, + { + "name": "scales", + "type": "tensor(float)", + "description": "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'." + } + ], + "min_input": 2, + "max_input": 2, + "outputs": [ + { + "name": "Y", + "type": "T", + "description": "N-D tensor after resizing" + } + ], + "min_output": 1, + "max_output": 1, + "type_constraints": [ + { + "description": "Constrain input 'X' and output 'Y' to all tensor types.", + "type_param_str": "T", + "allowed_type_strs": [ + "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)" + ] + } + ], + "examples": [ + { + "summary": "nearest", + "code": "node = onnx.helper.make_node(\n 'Upsample',\n inputs=['X', 'scales'],\n outputs=['Y'],\n mode='nearest',\n)\n\ndata = np.array([[[\n [1, 2],\n [3, 4],\n]]], dtype=np.float32)\n\nscales = np.array([1.0, 1.0, 2.0, 3.0], dtype=np.float32)\n\noutput = np.array([[[\n [1, 1, 1, 2, 2, 2],\n [1, 1, 1, 2, 2, 2],\n [3, 3, 3, 4, 4, 4],\n [3, 3, 3, 4, 4, 4],\n]]], dtype=np.float32)\n\nexpect(node, inputs=[data, scales], outputs=[output],\n name='test_upsample_nearest', opset_imports=[helper.make_opsetid(\"\", 9)])" + } + ], + "category": "Data" + }, + { + "name": "Where", + "module": "ai.onnx", + "version": 9, + "support_level": "common", + "description": "Return elements, either from X or Y, depending on condition\n (with Numpy-style broadcasting support).\n Where behaves like numpy.where with three parameters:\n https://docs.scipy.org/doc/numpy/reference/generated/numpy.where.html\n", + "inputs": [ + { + "name": "condition", + "type": "B", + "description": "When True (nonzero), yield X, otherwise yield Y" + }, + { + "name": "X", + "type": "T", + "description": "values selected at indices where condition is True" + }, + { + "name": "Y", + "type": "T", + "description": "values selected at indices where condition is False" + } + ], + "min_input": 3, + "max_input": 3, + "outputs": [ + { + "name": "output", + "type": "T", + "description": "Tensor of shape equal to the broadcasted shape of condition, X, and Y." + } + ], + "min_output": 1, + "max_output": 1, + "type_constraints": [ + { + "description": "Constrain to boolean tensors.", + "type_param_str": "B", + "allowed_type_strs": [ + "tensor(bool)" + ] + }, + { + "description": "Constrain input and output types to all tensor types.", + "type_param_str": "T", + "allowed_type_strs": [ + "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)" + ] + } + ], + "examples": [ + { + "summary": "long", + "code": "node = onnx.helper.make_node(\n 'Where',\n inputs=['condition', 'x', 'y'],\n outputs=['z'],\n)\n\ncondition = np.array([[1, 0], [1, 1]], dtype=bool)\nx = np.array([[1, 2], [3, 4]], dtype=np.int64)\ny = np.array([[9, 8], [7, 6]], dtype=np.int64)\nz = np.where(condition, x, y) # expected output [[1, 8], [3, 4]]\nexpect(node, inputs=[condition, x, y], outputs=[z],\n name='test_where_long_example')" + }, + { + "summary": "where", + "code": "node = onnx.helper.make_node(\n 'Where',\n inputs=['condition', 'x', 'y'],\n outputs=['z'],\n)\n\ncondition = np.array([[1, 0], [1, 1]], dtype=bool)\nx = np.array([[1, 2], [3, 4]], dtype=np.float32)\ny = np.array([[9, 8], [7, 6]], dtype=np.float32)\nz = np.where(condition, x, y) # expected output [[1, 8], [3, 4]]\nexpect(node, inputs=[condition, x, y], outputs=[z],\n name='test_where_example')" + } + ] + }, + { + "name": "Xor", + "module": "ai.onnx", + "version": 1, + "support_level": "common", + "description": "Returns the tensor resulted from performing the `xor` logical operation\nelementwise on the input tensors `A` and `B`.\n\nIf broadcasting is enabled, the right-hand-side argument will be broadcasted\nto match the shape of left-hand-side argument. See the doc of `Add` for a\ndetailed description of the broadcasting rules.\n", + "attributes": [ + { + "name": "axis", + "type": "int64", + "required": false, + "description": "If set, defines the broadcast dimensions." + }, + { + "name": "broadcast", + "type": "int64", + "required": false, + "description": "Enable broadcasting" + } + ], + "inputs": [ + { + "name": "A", + "type": "T", + "description": "Left input tensor for the logical operator." + }, + { + "name": "B", + "type": "T", + "description": "Right input tensor for the logical operator." + } + ], + "min_input": 2, + "max_input": 2, + "outputs": [ + { + "name": "C", + "type": "T1", + "description": "Result tensor." + } + ], + "min_output": 1, + "max_output": 1, + "type_constraints": [ + { + "description": "Constrains input to boolean tensor.", + "type_param_str": "T", + "allowed_type_strs": [ + "tensor(bool)" + ] + }, + { + "description": "Constrains output to boolean tensor.", + "type_param_str": "T1", + "allowed_type_strs": [ + "tensor(bool)" + ] + } + ], + "examples": [ + { + "summary": "xor", + "code": "node = onnx.helper.make_node(\n 'Xor',\n inputs=['x', 'y'],\n outputs=['xor'],\n)\n\n# 2d\nx = (np.random.randn(3, 4) > 0).astype(bool)\ny = (np.random.randn(3, 4) > 0).astype(bool)\nz = np.logical_xor(x, y)\nexpect(node, inputs=[x, y], outputs=[z],\n name='test_xor2d')\n\n# 3d\nx = (np.random.randn(3, 4, 5) > 0).astype(bool)\ny = (np.random.randn(3, 4, 5) > 0).astype(bool)\nz = np.logical_xor(x, y)\nexpect(node, inputs=[x, y], outputs=[z],\n name='test_xor3d')\n\n# 4d\nx = (np.random.randn(3, 4, 5, 6) > 0).astype(bool)\ny = (np.random.randn(3, 4, 5, 6) > 0).astype(bool)\nz = np.logical_xor(x, y)\nexpect(node, inputs=[x, y], outputs=[z],\n name='test_xor4d')" + }, + { + "summary": "xor_broadcast", + "code": "node = onnx.helper.make_node(\n 'Xor',\n inputs=['x', 'y'],\n outputs=['xor'],\n)\n\n# 3d vs 1d\nx = (np.random.randn(3, 4, 5) > 0).astype(bool)\ny = (np.random.randn(5) > 0).astype(bool)\nz = np.logical_xor(x, y)\nexpect(node, inputs=[x, y], outputs=[z],\n name='test_xor_bcast3v1d')\n\n# 3d vs 2d\nx = (np.random.randn(3, 4, 5) > 0).astype(bool)\ny = (np.random.randn(4, 5) > 0).astype(bool)\nz = np.logical_xor(x, y)\nexpect(node, inputs=[x, y], outputs=[z],\n name='test_xor_bcast3v2d')\n\n# 4d vs 2d\nx = (np.random.randn(3, 4, 5, 6) > 0).astype(bool)\ny = (np.random.randn(5, 6) > 0).astype(bool)\nz = np.logical_xor(x, y)\nexpect(node, inputs=[x, y], outputs=[z],\n name='test_xor_bcast4v2d')\n\n# 4d vs 3d\nx = (np.random.randn(3, 4, 5, 6) > 0).astype(bool)\ny = (np.random.randn(4, 5, 6) > 0).astype(bool)\nz = np.logical_xor(x, y)\nexpect(node, inputs=[x, y], outputs=[z],\n name='test_xor_bcast4v3d')\n\n# 4d vs 4d\nx = (np.random.randn(1, 4, 1, 6) > 0).astype(bool)\ny = (np.random.randn(3, 1, 5, 6) > 0).astype(bool)\nz = np.logical_xor(x, y)\nexpect(node, inputs=[x, y], outputs=[z],\n name='test_xor_bcast4v4d')" + } + ], + "category": "Logic" + }, + { + "name": "Xor", + "module": "ai.onnx", + "version": 7, + "support_level": "common", + "description": "Returns the tensor resulted from performing the `xor` logical operation\nelementwise on the input tensors `A` and `B` (with Numpy-style broadcasting support).\n\nThis operator supports **multidirectional (i.e., Numpy-style) broadcasting**; for more details please check [the doc](https://github.com/onnx/onnx/blob/master/docs/Broadcasting.md).\n", + "inputs": [ + { + "name": "A", + "type": "T", + "description": "First input operand for the logical operator." + }, + { + "name": "B", + "type": "T", + "description": "Second input operand for the logical operator." + } + ], + "min_input": 2, + "max_input": 2, + "outputs": [ + { + "name": "C", + "type": "T1", + "description": "Result tensor." + } + ], + "min_output": 1, + "max_output": 1, + "type_constraints": [ + { + "description": "Constrains input to boolean tensor.", + "type_param_str": "T", + "allowed_type_strs": [ + "tensor(bool)" + ] + }, + { + "description": "Constrains output to boolean tensor.", + "type_param_str": "T1", + "allowed_type_strs": [ + "tensor(bool)" + ] + } + ], + "examples": [ + { + "summary": "xor", + "code": "node = onnx.helper.make_node(\n 'Xor',\n inputs=['x', 'y'],\n outputs=['xor'],\n)\n\n# 2d\nx = (np.random.randn(3, 4) > 0).astype(bool)\ny = (np.random.randn(3, 4) > 0).astype(bool)\nz = np.logical_xor(x, y)\nexpect(node, inputs=[x, y], outputs=[z],\n name='test_xor2d')\n\n# 3d\nx = (np.random.randn(3, 4, 5) > 0).astype(bool)\ny = (np.random.randn(3, 4, 5) > 0).astype(bool)\nz = np.logical_xor(x, y)\nexpect(node, inputs=[x, y], outputs=[z],\n name='test_xor3d')\n\n# 4d\nx = (np.random.randn(3, 4, 5, 6) > 0).astype(bool)\ny = (np.random.randn(3, 4, 5, 6) > 0).astype(bool)\nz = np.logical_xor(x, y)\nexpect(node, inputs=[x, y], outputs=[z],\n name='test_xor4d')" + }, + { + "summary": "xor_broadcast", + "code": "node = onnx.helper.make_node(\n 'Xor',\n inputs=['x', 'y'],\n outputs=['xor'],\n)\n\n# 3d vs 1d\nx = (np.random.randn(3, 4, 5) > 0).astype(bool)\ny = (np.random.randn(5) > 0).astype(bool)\nz = np.logical_xor(x, y)\nexpect(node, inputs=[x, y], outputs=[z],\n name='test_xor_bcast3v1d')\n\n# 3d vs 2d\nx = (np.random.randn(3, 4, 5) > 0).astype(bool)\ny = (np.random.randn(4, 5) > 0).astype(bool)\nz = np.logical_xor(x, y)\nexpect(node, inputs=[x, y], outputs=[z],\n name='test_xor_bcast3v2d')\n\n# 4d vs 2d\nx = (np.random.randn(3, 4, 5, 6) > 0).astype(bool)\ny = (np.random.randn(5, 6) > 0).astype(bool)\nz = np.logical_xor(x, y)\nexpect(node, inputs=[x, y], outputs=[z],\n name='test_xor_bcast4v2d')\n\n# 4d vs 3d\nx = (np.random.randn(3, 4, 5, 6) > 0).astype(bool)\ny = (np.random.randn(4, 5, 6) > 0).astype(bool)\nz = np.logical_xor(x, y)\nexpect(node, inputs=[x, y], outputs=[z],\n name='test_xor_bcast4v3d')\n\n# 4d vs 4d\nx = (np.random.randn(1, 4, 1, 6) > 0).astype(bool)\ny = (np.random.randn(3, 1, 5, 6) > 0).astype(bool)\nz = np.logical_xor(x, y)\nexpect(node, inputs=[x, y], outputs=[z],\n name='test_xor_bcast4v4d')" + } + ], + "category": "Logic" + }, + { + "name": "ZipMap", + "module": "ai.onnx.ml", + "version": 1, + "support_level": "common", + "description": "Creates a map from the input and the attributes.
\n The values are provided by the input tensor, while the keys are specified by the attributes.\n Must provide keys in either classlabels_strings or classlabels_int64s (but not both).
\n The columns of the tensor correspond one-by-one to the keys specified by the attributes. There must be as many columns as keys.
\n", + "attributes": [ + { + "name": "classlabels_int64s", + "type": "int64[]", + "required": false, + "description": "The keys when using int keys.
One and only one of the 'classlabels_*' attributes must be defined." + }, + { + "name": "classlabels_strings", + "type": "string[]", + "required": false, + "description": "The keys when using string keys.
One and only one of the 'classlabels_*' attributes must be defined." + } + ], + "inputs": [ + { + "name": "X", + "type": "tensor(float)", + "description": "The input values" + } + ], + "min_input": 1, + "max_input": 1, + "outputs": [ + { + "name": "Z", + "type": "T", + "description": "The output map" + } + ], + "min_output": 1, + "max_output": 1, + "type_constraints": [ + { + "description": "The output will be a sequence of string or integer maps to float.", + "type_param_str": "T", + "allowed_type_strs": [ + "seq(map(string, float))", + "seq(map(int64, float))" + ] + } + ] + } +] diff --git a/media/CircleGraph/external/onnx-proto.js b/media/CircleGraph/external/onnx-proto.js new file mode 100644 index 00000000..6d5255f4 --- /dev/null +++ b/media/CircleGraph/external/onnx-proto.js @@ -0,0 +1,1737 @@ +var onnx_root = protobuf.get('onnx'); + +onnx_root.onnx = {}; + +onnx_root.onnx.Version = { + "_START_VERSION": 0, + "IR_VERSION_2017_10_10": 1, + "IR_VERSION_2017_10_30": 2, + "IR_VERSION_2017_11_3": 3, + "IR_VERSION_2019_1_22": 4, + "IR_VERSION_2019_3_18": 5, + "IR_VERSION_2019_9_19": 6, + "IR_VERSION_2020_5_8": 7, + "IR_VERSION": 8 +}; + +onnx_root.onnx.AttributeProto = class AttributeProto { + + constructor() { + this.floats = []; + this.ints = []; + this.strings = []; + this.tensors = []; + this.graphs = []; + this.sparse_tensors = []; + this.type_protos = []; + } + + static decode(reader, length) { + const message = new onnx_root.onnx.AttributeProto(); + const end = length !== undefined ? reader.position + length : reader.length; + while (reader.position < end) { + const tag = reader.uint32(); + switch (tag >>> 3) { + case 1: + message.name = reader.string(); + break; + case 21: + message.ref_attr_name = reader.string(); + break; + case 13: + message.doc_string = reader.string(); + break; + case 20: + message.type = reader.int32(); + break; + case 2: + message.f = reader.float(); + break; + case 3: + message.i = reader.int64(); + break; + case 4: + message.s = reader.bytes(); + break; + case 5: + message.t = onnx_root.onnx.TensorProto.decode(reader, reader.uint32()); + break; + case 6: + message.g = onnx_root.onnx.GraphProto.decode(reader, reader.uint32()); + break; + case 22: + message.sparse_tensor = onnx_root.onnx.SparseTensorProto.decode(reader, reader.uint32()); + break; + case 14: + message.tp = onnx_root.onnx.TypeProto.decode(reader, reader.uint32()); + break; + case 7: + message.floats = reader.floats(message.floats, tag); + break; + case 8: + message.ints = reader.array(message.ints, () => reader.int64(), tag); + break; + case 9: + message.strings.push(reader.bytes()); + break; + case 10: + message.tensors.push(onnx_root.onnx.TensorProto.decode(reader, reader.uint32())); + break; + case 11: + message.graphs.push(onnx_root.onnx.GraphProto.decode(reader, reader.uint32())); + break; + case 23: + message.sparse_tensors.push(onnx_root.onnx.SparseTensorProto.decode(reader, reader.uint32())); + break; + case 15: + message.type_protos.push(onnx_root.onnx.TypeProto.decode(reader, reader.uint32())); + break; + default: + reader.skipType(tag & 7); + break; + } + } + return message; + } + + static decodeText(reader) { + const message = new onnx_root.onnx.AttributeProto(); + reader.start(); + while (!reader.end()) { + const tag = reader.tag(); + switch (tag) { + case "name": + message.name = reader.string(); + break; + case "ref_attr_name": + message.ref_attr_name = reader.string(); + break; + case "doc_string": + message.doc_string = reader.string(); + break; + case "type": + message.type = reader.enum(onnx_root.onnx.AttributeProto.AttributeType); + break; + case "f": + message.f = reader.float(); + break; + case "i": + message.i = reader.int64(); + break; + case "s": + message.s = reader.bytes(); + break; + case "t": + message.t = onnx_root.onnx.TensorProto.decodeText(reader); + break; + case "g": + message.g = onnx_root.onnx.GraphProto.decodeText(reader); + break; + case "sparse_tensor": + message.sparse_tensor = onnx_root.onnx.SparseTensorProto.decodeText(reader); + break; + case "tp": + message.tp = onnx_root.onnx.TypeProto.decodeText(reader); + break; + case "floats": + reader.array(message.floats, () => reader.float()); + break; + case "ints": + reader.array(message.ints, () => reader.int64()); + break; + case "strings": + reader.array(message.strings, () => reader.bytes()); + break; + case "tensors": + message.tensors.push(onnx_root.onnx.TensorProto.decodeText(reader)); + break; + case "graphs": + message.graphs.push(onnx_root.onnx.GraphProto.decodeText(reader)); + break; + case "sparse_tensors": + message.sparse_tensors.push(onnx_root.onnx.SparseTensorProto.decodeText(reader)); + break; + case "type_protos": + message.type_protos.push(onnx_root.onnx.TypeProto.decodeText(reader)); + break; + default: + reader.field(tag, message); + break; + } + } + return message; + } +}; + +onnx_root.onnx.AttributeProto.prototype.name = ""; +onnx_root.onnx.AttributeProto.prototype.ref_attr_name = ""; +onnx_root.onnx.AttributeProto.prototype.doc_string = ""; +onnx_root.onnx.AttributeProto.prototype.type = 0; +onnx_root.onnx.AttributeProto.prototype.f = 0; +onnx_root.onnx.AttributeProto.prototype.i = protobuf.Int64.create(0); +onnx_root.onnx.AttributeProto.prototype.s = new Uint8Array([]); +onnx_root.onnx.AttributeProto.prototype.t = null; +onnx_root.onnx.AttributeProto.prototype.g = null; +onnx_root.onnx.AttributeProto.prototype.sparse_tensor = null; +onnx_root.onnx.AttributeProto.prototype.tp = null; + +onnx_root.onnx.AttributeProto.AttributeType = { + "UNDEFINED": 0, + "FLOAT": 1, + "INT": 2, + "STRING": 3, + "TENSOR": 4, + "GRAPH": 5, + "SPARSE_TENSOR": 11, + "TYPE_PROTO": 13, + "FLOATS": 6, + "INTS": 7, + "STRINGS": 8, + "TENSORS": 9, + "GRAPHS": 10, + "SPARSE_TENSORS": 12, + "TYPE_PROTOS": 14 +}; + +onnx_root.onnx.ValueInfoProto = class ValueInfoProto { + + constructor() { + } + + static decode(reader, length) { + const message = new onnx_root.onnx.ValueInfoProto(); + const end = length !== undefined ? reader.position + length : reader.length; + while (reader.position < end) { + const tag = reader.uint32(); + switch (tag >>> 3) { + case 1: + message.name = reader.string(); + break; + case 2: + message.type = onnx_root.onnx.TypeProto.decode(reader, reader.uint32()); + break; + case 3: + message.doc_string = reader.string(); + break; + default: + reader.skipType(tag & 7); + break; + } + } + return message; + } + + static decodeText(reader) { + const message = new onnx_root.onnx.ValueInfoProto(); + reader.start(); + while (!reader.end()) { + const tag = reader.tag(); + switch (tag) { + case "name": + message.name = reader.string(); + break; + case "type": + message.type = onnx_root.onnx.TypeProto.decodeText(reader); + break; + case "doc_string": + message.doc_string = reader.string(); + break; + default: + reader.field(tag, message); + break; + } + } + return message; + } +}; + +onnx_root.onnx.ValueInfoProto.prototype.name = ""; +onnx_root.onnx.ValueInfoProto.prototype.type = null; +onnx_root.onnx.ValueInfoProto.prototype.doc_string = ""; + +onnx_root.onnx.NodeProto = class NodeProto { + + constructor() { + this.input = []; + this.output = []; + this.attribute = []; + } + + static decode(reader, length) { + const message = new onnx_root.onnx.NodeProto(); + const end = length !== undefined ? reader.position + length : reader.length; + while (reader.position < end) { + const tag = reader.uint32(); + switch (tag >>> 3) { + case 1: + message.input.push(reader.string()); + break; + case 2: + message.output.push(reader.string()); + break; + case 3: + message.name = reader.string(); + break; + case 4: + message.op_type = reader.string(); + break; + case 7: + message.domain = reader.string(); + break; + case 5: + message.attribute.push(onnx_root.onnx.AttributeProto.decode(reader, reader.uint32())); + break; + case 6: + message.doc_string = reader.string(); + break; + default: + reader.skipType(tag & 7); + break; + } + } + return message; + } + + static decodeText(reader) { + const message = new onnx_root.onnx.NodeProto(); + reader.start(); + while (!reader.end()) { + const tag = reader.tag(); + switch (tag) { + case "input": + reader.array(message.input, () => reader.string()); + break; + case "output": + reader.array(message.output, () => reader.string()); + break; + case "name": + message.name = reader.string(); + break; + case "op_type": + message.op_type = reader.string(); + break; + case "domain": + message.domain = reader.string(); + break; + case "attribute": + message.attribute.push(onnx_root.onnx.AttributeProto.decodeText(reader)); + break; + case "doc_string": + message.doc_string = reader.string(); + break; + default: + reader.field(tag, message); + break; + } + } + return message; + } +}; + +onnx_root.onnx.NodeProto.prototype.name = ""; +onnx_root.onnx.NodeProto.prototype.op_type = ""; +onnx_root.onnx.NodeProto.prototype.domain = ""; +onnx_root.onnx.NodeProto.prototype.doc_string = ""; + +onnx_root.onnx.TrainingInfoProto = class TrainingInfoProto { + + constructor() { + this.initialization_binding = []; + this.update_binding = []; + } + + static decode(reader, length) { + const message = new onnx_root.onnx.TrainingInfoProto(); + const end = length !== undefined ? reader.position + length : reader.length; + while (reader.position < end) { + const tag = reader.uint32(); + switch (tag >>> 3) { + case 1: + message.initialization = onnx_root.onnx.GraphProto.decode(reader, reader.uint32()); + break; + case 2: + message.algorithm = onnx_root.onnx.GraphProto.decode(reader, reader.uint32()); + break; + case 3: + message.initialization_binding.push(onnx_root.onnx.StringStringEntryProto.decode(reader, reader.uint32())); + break; + case 4: + message.update_binding.push(onnx_root.onnx.StringStringEntryProto.decode(reader, reader.uint32())); + break; + default: + reader.skipType(tag & 7); + break; + } + } + return message; + } + + static decodeText(reader) { + const message = new onnx_root.onnx.TrainingInfoProto(); + reader.start(); + while (!reader.end()) { + const tag = reader.tag(); + switch (tag) { + case "initialization": + message.initialization = onnx_root.onnx.GraphProto.decodeText(reader); + break; + case "algorithm": + message.algorithm = onnx_root.onnx.GraphProto.decodeText(reader); + break; + case "initialization_binding": + message.initialization_binding.push(onnx_root.onnx.StringStringEntryProto.decodeText(reader)); + break; + case "update_binding": + message.update_binding.push(onnx_root.onnx.StringStringEntryProto.decodeText(reader)); + break; + default: + reader.field(tag, message); + break; + } + } + return message; + } +}; + +onnx_root.onnx.TrainingInfoProto.prototype.initialization = null; +onnx_root.onnx.TrainingInfoProto.prototype.algorithm = null; + +onnx_root.onnx.ModelProto = class ModelProto { + + constructor() { + this.opset_import = []; + this.metadata_props = []; + this.training_info = []; + this.functions = []; + } + + static decode(reader, length) { + const message = new onnx_root.onnx.ModelProto(); + const end = length !== undefined ? reader.position + length : reader.length; + while (reader.position < end) { + const tag = reader.uint32(); + switch (tag >>> 3) { + case 1: + message.ir_version = reader.int64(); + break; + case 8: + message.opset_import.push(onnx_root.onnx.OperatorSetIdProto.decode(reader, reader.uint32())); + break; + case 2: + message.producer_name = reader.string(); + break; + case 3: + message.producer_version = reader.string(); + break; + case 4: + message.domain = reader.string(); + break; + case 5: + message.model_version = reader.int64(); + break; + case 6: + message.doc_string = reader.string(); + break; + case 7: + message.graph = onnx_root.onnx.GraphProto.decode(reader, reader.uint32()); + break; + case 14: + message.metadata_props.push(onnx_root.onnx.StringStringEntryProto.decode(reader, reader.uint32())); + break; + case 20: + message.training_info.push(onnx_root.onnx.TrainingInfoProto.decode(reader, reader.uint32())); + break; + case 25: + message.functions.push(onnx_root.onnx.FunctionProto.decode(reader, reader.uint32())); + break; + default: + reader.skipType(tag & 7); + break; + } + } + return message; + } + + static decodeText(reader) { + const message = new onnx_root.onnx.ModelProto(); + reader.start(); + while (!reader.end()) { + const tag = reader.tag(); + switch (tag) { + case "ir_version": + message.ir_version = reader.int64(); + break; + case "opset_import": + message.opset_import.push(onnx_root.onnx.OperatorSetIdProto.decodeText(reader)); + break; + case "producer_name": + message.producer_name = reader.string(); + break; + case "producer_version": + message.producer_version = reader.string(); + break; + case "domain": + message.domain = reader.string(); + break; + case "model_version": + message.model_version = reader.int64(); + break; + case "doc_string": + message.doc_string = reader.string(); + break; + case "graph": + message.graph = onnx_root.onnx.GraphProto.decodeText(reader); + break; + case "metadata_props": + message.metadata_props.push(onnx_root.onnx.StringStringEntryProto.decodeText(reader)); + break; + case "training_info": + message.training_info.push(onnx_root.onnx.TrainingInfoProto.decodeText(reader)); + break; + case "functions": + message.functions.push(onnx_root.onnx.FunctionProto.decodeText(reader)); + break; + default: + reader.field(tag, message); + break; + } + } + return message; + } +}; + +onnx_root.onnx.ModelProto.prototype.ir_version = protobuf.Int64.create(0); +onnx_root.onnx.ModelProto.prototype.producer_name = ""; +onnx_root.onnx.ModelProto.prototype.producer_version = ""; +onnx_root.onnx.ModelProto.prototype.domain = ""; +onnx_root.onnx.ModelProto.prototype.model_version = protobuf.Int64.create(0); +onnx_root.onnx.ModelProto.prototype.doc_string = ""; +onnx_root.onnx.ModelProto.prototype.graph = null; + +onnx_root.onnx.StringStringEntryProto = class StringStringEntryProto { + + constructor() { + } + + static decode(reader, length) { + const message = new onnx_root.onnx.StringStringEntryProto(); + const end = length !== undefined ? reader.position + length : reader.length; + while (reader.position < end) { + const tag = reader.uint32(); + switch (tag >>> 3) { + case 1: + message.key = reader.string(); + break; + case 2: + message.value = reader.string(); + break; + default: + reader.skipType(tag & 7); + break; + } + } + return message; + } + + static decodeText(reader) { + const message = new onnx_root.onnx.StringStringEntryProto(); + reader.start(); + while (!reader.end()) { + const tag = reader.tag(); + switch (tag) { + case "key": + message.key = reader.string(); + break; + case "value": + message.value = reader.string(); + break; + default: + reader.field(tag, message); + break; + } + } + return message; + } +}; + +onnx_root.onnx.StringStringEntryProto.prototype.key = ""; +onnx_root.onnx.StringStringEntryProto.prototype.value = ""; + +onnx_root.onnx.TensorAnnotation = class TensorAnnotation { + + constructor() { + this.quant_parameter_tensor_names = []; + } + + static decode(reader, length) { + const message = new onnx_root.onnx.TensorAnnotation(); + const end = length !== undefined ? reader.position + length : reader.length; + while (reader.position < end) { + const tag = reader.uint32(); + switch (tag >>> 3) { + case 1: + message.tensor_name = reader.string(); + break; + case 2: + message.quant_parameter_tensor_names.push(onnx_root.onnx.StringStringEntryProto.decode(reader, reader.uint32())); + break; + default: + reader.skipType(tag & 7); + break; + } + } + return message; + } + + static decodeText(reader) { + const message = new onnx_root.onnx.TensorAnnotation(); + reader.start(); + while (!reader.end()) { + const tag = reader.tag(); + switch (tag) { + case "tensor_name": + message.tensor_name = reader.string(); + break; + case "quant_parameter_tensor_names": + message.quant_parameter_tensor_names.push(onnx_root.onnx.StringStringEntryProto.decodeText(reader)); + break; + default: + reader.field(tag, message); + break; + } + } + return message; + } +}; + +onnx_root.onnx.TensorAnnotation.prototype.tensor_name = ""; + +onnx_root.onnx.GraphProto = class GraphProto { + + constructor() { + this.node = []; + this.initializer = []; + this.sparse_initializer = []; + this.input = []; + this.output = []; + this.value_info = []; + this.quantization_annotation = []; + } + + static decode(reader, length) { + const message = new onnx_root.onnx.GraphProto(); + const end = length !== undefined ? reader.position + length : reader.length; + while (reader.position < end) { + const tag = reader.uint32(); + switch (tag >>> 3) { + case 1: + message.node.push(onnx_root.onnx.NodeProto.decode(reader, reader.uint32())); + break; + case 2: + message.name = reader.string(); + break; + case 5: + message.initializer.push(onnx_root.onnx.TensorProto.decode(reader, reader.uint32())); + break; + case 15: + message.sparse_initializer.push(onnx_root.onnx.SparseTensorProto.decode(reader, reader.uint32())); + break; + case 10: + message.doc_string = reader.string(); + break; + case 11: + message.input.push(onnx_root.onnx.ValueInfoProto.decode(reader, reader.uint32())); + break; + case 12: + message.output.push(onnx_root.onnx.ValueInfoProto.decode(reader, reader.uint32())); + break; + case 13: + message.value_info.push(onnx_root.onnx.ValueInfoProto.decode(reader, reader.uint32())); + break; + case 14: + message.quantization_annotation.push(onnx_root.onnx.TensorAnnotation.decode(reader, reader.uint32())); + break; + default: + reader.skipType(tag & 7); + break; + } + } + return message; + } + + static decodeText(reader) { + const message = new onnx_root.onnx.GraphProto(); + reader.start(); + while (!reader.end()) { + const tag = reader.tag(); + switch (tag) { + case "node": + message.node.push(onnx_root.onnx.NodeProto.decodeText(reader)); + break; + case "name": + message.name = reader.string(); + break; + case "initializer": + message.initializer.push(onnx_root.onnx.TensorProto.decodeText(reader)); + break; + case "sparse_initializer": + message.sparse_initializer.push(onnx_root.onnx.SparseTensorProto.decodeText(reader)); + break; + case "doc_string": + message.doc_string = reader.string(); + break; + case "input": + message.input.push(onnx_root.onnx.ValueInfoProto.decodeText(reader)); + break; + case "output": + message.output.push(onnx_root.onnx.ValueInfoProto.decodeText(reader)); + break; + case "value_info": + message.value_info.push(onnx_root.onnx.ValueInfoProto.decodeText(reader)); + break; + case "quantization_annotation": + message.quantization_annotation.push(onnx_root.onnx.TensorAnnotation.decodeText(reader)); + break; + default: + reader.field(tag, message); + break; + } + } + return message; + } +}; + +onnx_root.onnx.GraphProto.prototype.name = ""; +onnx_root.onnx.GraphProto.prototype.doc_string = ""; + +onnx_root.onnx.TensorProto = class TensorProto { + + constructor() { + this.dims = []; + this.float_data = []; + this.int32_data = []; + this.string_data = []; + this.int64_data = []; + this.external_data = []; + this.double_data = []; + this.uint64_data = []; + } + + static decode(reader, length) { + const message = new onnx_root.onnx.TensorProto(); + const end = length !== undefined ? reader.position + length : reader.length; + while (reader.position < end) { + const tag = reader.uint32(); + switch (tag >>> 3) { + case 1: + message.dims = reader.array(message.dims, () => reader.int64(), tag); + break; + case 2: + message.data_type = reader.int32(); + break; + case 3: + message.segment = onnx_root.onnx.TensorProto.Segment.decode(reader, reader.uint32()); + break; + case 4: + message.float_data = reader.floats(message.float_data, tag); + break; + case 5: + message.int32_data = reader.array(message.int32_data, () => reader.int32(), tag); + break; + case 6: + message.string_data.push(reader.bytes()); + break; + case 7: + message.int64_data = reader.array(message.int64_data, () => reader.int64(), tag); + break; + case 8: + message.name = reader.string(); + break; + case 12: + message.doc_string = reader.string(); + break; + case 9: + message.raw_data = reader.bytes(); + break; + case 13: + message.external_data.push(onnx_root.onnx.StringStringEntryProto.decode(reader, reader.uint32())); + break; + case 14: + message.data_location = reader.int32(); + break; + case 10: + message.double_data = reader.doubles(message.double_data, tag); + break; + case 11: + message.uint64_data = reader.array(message.uint64_data, () => reader.uint64(), tag); + break; + default: + reader.skipType(tag & 7); + break; + } + } + return message; + } + + static decodeText(reader) { + const message = new onnx_root.onnx.TensorProto(); + reader.start(); + while (!reader.end()) { + const tag = reader.tag(); + switch (tag) { + case "dims": + reader.array(message.dims, () => reader.int64()); + break; + case "data_type": + message.data_type = reader.int32(); + break; + case "segment": + message.segment = onnx_root.onnx.TensorProto.Segment.decodeText(reader); + break; + case "float_data": + reader.array(message.float_data, () => reader.float()); + break; + case "int32_data": + reader.array(message.int32_data, () => reader.int32()); + break; + case "string_data": + reader.array(message.string_data, () => reader.bytes()); + break; + case "int64_data": + reader.array(message.int64_data, () => reader.int64()); + break; + case "name": + message.name = reader.string(); + break; + case "doc_string": + message.doc_string = reader.string(); + break; + case "raw_data": + message.raw_data = reader.bytes(); + break; + case "external_data": + message.external_data.push(onnx_root.onnx.StringStringEntryProto.decodeText(reader)); + break; + case "data_location": + message.data_location = reader.enum(onnx_root.onnx.TensorProto.DataLocation); + break; + case "double_data": + reader.array(message.double_data, () => reader.double()); + break; + case "uint64_data": + reader.array(message.uint64_data, () => reader.uint64()); + break; + default: + reader.field(tag, message); + break; + } + } + return message; + } +}; + +onnx_root.onnx.TensorProto.prototype.data_type = 0; +onnx_root.onnx.TensorProto.prototype.segment = null; +onnx_root.onnx.TensorProto.prototype.name = ""; +onnx_root.onnx.TensorProto.prototype.doc_string = ""; +onnx_root.onnx.TensorProto.prototype.raw_data = new Uint8Array([]); +onnx_root.onnx.TensorProto.prototype.data_location = 0; + +onnx_root.onnx.TensorProto.DataType = { + "UNDEFINED": 0, + "FLOAT": 1, + "UINT8": 2, + "INT8": 3, + "UINT16": 4, + "INT16": 5, + "INT32": 6, + "INT64": 7, + "STRING": 8, + "BOOL": 9, + "FLOAT16": 10, + "DOUBLE": 11, + "UINT32": 12, + "UINT64": 13, + "COMPLEX64": 14, + "COMPLEX128": 15, + "BFLOAT16": 16 +}; + +onnx_root.onnx.TensorProto.Segment = class Segment { + + constructor() { + } + + static decode(reader, length) { + const message = new onnx_root.onnx.TensorProto.Segment(); + const end = length !== undefined ? reader.position + length : reader.length; + while (reader.position < end) { + const tag = reader.uint32(); + switch (tag >>> 3) { + case 1: + message.begin = reader.int64(); + break; + case 2: + message.end = reader.int64(); + break; + default: + reader.skipType(tag & 7); + break; + } + } + return message; + } + + static decodeText(reader) { + const message = new onnx_root.onnx.TensorProto.Segment(); + reader.start(); + while (!reader.end()) { + const tag = reader.tag(); + switch (tag) { + case "begin": + message.begin = reader.int64(); + break; + case "end": + message.end = reader.int64(); + break; + default: + reader.field(tag, message); + break; + } + } + return message; + } +}; + +onnx_root.onnx.TensorProto.Segment.prototype.begin = protobuf.Int64.create(0); +onnx_root.onnx.TensorProto.Segment.prototype.end = protobuf.Int64.create(0); + +onnx_root.onnx.TensorProto.DataLocation = { + "DEFAULT": 0, + "EXTERNAL": 1 +}; + +onnx_root.onnx.SparseTensorProto = class SparseTensorProto { + + constructor() { + this.dims = []; + } + + static decode(reader, length) { + const message = new onnx_root.onnx.SparseTensorProto(); + const end = length !== undefined ? reader.position + length : reader.length; + while (reader.position < end) { + const tag = reader.uint32(); + switch (tag >>> 3) { + case 1: + message.values = onnx_root.onnx.TensorProto.decode(reader, reader.uint32()); + break; + case 2: + message.indices = onnx_root.onnx.TensorProto.decode(reader, reader.uint32()); + break; + case 3: + message.dims = reader.array(message.dims, () => reader.int64(), tag); + break; + default: + reader.skipType(tag & 7); + break; + } + } + return message; + } + + static decodeText(reader) { + const message = new onnx_root.onnx.SparseTensorProto(); + reader.start(); + while (!reader.end()) { + const tag = reader.tag(); + switch (tag) { + case "values": + message.values = onnx_root.onnx.TensorProto.decodeText(reader); + break; + case "indices": + message.indices = onnx_root.onnx.TensorProto.decodeText(reader); + break; + case "dims": + reader.array(message.dims, () => reader.int64()); + break; + default: + reader.field(tag, message); + break; + } + } + return message; + } +}; + +onnx_root.onnx.SparseTensorProto.prototype.values = null; +onnx_root.onnx.SparseTensorProto.prototype.indices = null; + +onnx_root.onnx.TensorShapeProto = class TensorShapeProto { + + constructor() { + this.dim = []; + } + + static decode(reader, length) { + const message = new onnx_root.onnx.TensorShapeProto(); + const end = length !== undefined ? reader.position + length : reader.length; + while (reader.position < end) { + const tag = reader.uint32(); + switch (tag >>> 3) { + case 1: + message.dim.push(onnx_root.onnx.TensorShapeProto.Dimension.decode(reader, reader.uint32())); + break; + default: + reader.skipType(tag & 7); + break; + } + } + return message; + } + + static decodeText(reader) { + const message = new onnx_root.onnx.TensorShapeProto(); + reader.start(); + while (!reader.end()) { + const tag = reader.tag(); + switch (tag) { + case "dim": + message.dim.push(onnx_root.onnx.TensorShapeProto.Dimension.decodeText(reader)); + break; + default: + reader.field(tag, message); + break; + } + } + return message; + } +}; + +onnx_root.onnx.TensorShapeProto.Dimension = class Dimension { + + constructor() { + } + + get value() { + onnx_root.onnx.TensorShapeProto.Dimension.valueSet = onnx_root.onnx.TensorShapeProto.Dimension.valueSet || new Set([ "dim_value", "dim_param"]); + return Object.keys(this).find((key) => onnx_root.onnx.TensorShapeProto.Dimension.valueSet.has(key) && this[key] != null); + } + + static decode(reader, length) { + const message = new onnx_root.onnx.TensorShapeProto.Dimension(); + const end = length !== undefined ? reader.position + length : reader.length; + while (reader.position < end) { + const tag = reader.uint32(); + switch (tag >>> 3) { + case 1: + message.dim_value = reader.int64(); + break; + case 2: + message.dim_param = reader.string(); + break; + case 3: + message.denotation = reader.string(); + break; + default: + reader.skipType(tag & 7); + break; + } + } + return message; + } + + static decodeText(reader) { + const message = new onnx_root.onnx.TensorShapeProto.Dimension(); + reader.start(); + while (!reader.end()) { + const tag = reader.tag(); + switch (tag) { + case "dim_value": + message.dim_value = reader.int64(); + break; + case "dim_param": + message.dim_param = reader.string(); + break; + case "denotation": + message.denotation = reader.string(); + break; + default: + reader.field(tag, message); + break; + } + } + return message; + } +}; + +onnx_root.onnx.TensorShapeProto.Dimension.prototype.denotation = ""; + +onnx_root.onnx.TypeProto = class TypeProto { + + constructor() { + } + + get value() { + onnx_root.onnx.TypeProto.valueSet = onnx_root.onnx.TypeProto.valueSet || new Set([ "tensor_type", "sequence_type", "map_type", "optional_type", "sparse_tensor_type", "opaque_type"]); + return Object.keys(this).find((key) => onnx_root.onnx.TypeProto.valueSet.has(key) && this[key] != null); + } + + static decode(reader, length) { + const message = new onnx_root.onnx.TypeProto(); + const end = length !== undefined ? reader.position + length : reader.length; + while (reader.position < end) { + const tag = reader.uint32(); + switch (tag >>> 3) { + case 1: + message.tensor_type = onnx_root.onnx.TypeProto.Tensor.decode(reader, reader.uint32()); + break; + case 4: + message.sequence_type = onnx_root.onnx.TypeProto.Sequence.decode(reader, reader.uint32()); + break; + case 5: + message.map_type = onnx_root.onnx.TypeProto.Map.decode(reader, reader.uint32()); + break; + case 9: + message.optional_type = onnx_root.onnx.TypeProto.Optional.decode(reader, reader.uint32()); + break; + case 8: + message.sparse_tensor_type = onnx_root.onnx.TypeProto.SparseTensor.decode(reader, reader.uint32()); + break; + case 7: + message.opaque_type = onnx_root.onnx.TypeProto.Opaque.decode(reader, reader.uint32()); + break; + case 6: + message.denotation = reader.string(); + break; + default: + reader.skipType(tag & 7); + break; + } + } + return message; + } + + static decodeText(reader) { + const message = new onnx_root.onnx.TypeProto(); + reader.start(); + while (!reader.end()) { + const tag = reader.tag(); + switch (tag) { + case "tensor_type": + message.tensor_type = onnx_root.onnx.TypeProto.Tensor.decodeText(reader); + break; + case "sequence_type": + message.sequence_type = onnx_root.onnx.TypeProto.Sequence.decodeText(reader); + break; + case "map_type": + message.map_type = onnx_root.onnx.TypeProto.Map.decodeText(reader); + break; + case "optional_type": + message.optional_type = onnx_root.onnx.TypeProto.Optional.decodeText(reader); + break; + case "sparse_tensor_type": + message.sparse_tensor_type = onnx_root.onnx.TypeProto.SparseTensor.decodeText(reader); + break; + case "opaque_type": + message.opaque_type = onnx_root.onnx.TypeProto.Opaque.decodeText(reader); + break; + case "denotation": + message.denotation = reader.string(); + break; + default: + reader.field(tag, message); + break; + } + } + return message; + } +}; + +onnx_root.onnx.TypeProto.prototype.denotation = ""; + +onnx_root.onnx.TypeProto.Tensor = class Tensor { + + constructor() { + } + + static decode(reader, length) { + const message = new onnx_root.onnx.TypeProto.Tensor(); + const end = length !== undefined ? reader.position + length : reader.length; + while (reader.position < end) { + const tag = reader.uint32(); + switch (tag >>> 3) { + case 1: + message.elem_type = reader.int32(); + break; + case 2: + message.shape = onnx_root.onnx.TensorShapeProto.decode(reader, reader.uint32()); + break; + default: + reader.skipType(tag & 7); + break; + } + } + return message; + } + + static decodeText(reader) { + const message = new onnx_root.onnx.TypeProto.Tensor(); + reader.start(); + while (!reader.end()) { + const tag = reader.tag(); + switch (tag) { + case "elem_type": + message.elem_type = reader.int32(); + break; + case "shape": + message.shape = onnx_root.onnx.TensorShapeProto.decodeText(reader); + break; + default: + reader.field(tag, message); + break; + } + } + return message; + } +}; + +onnx_root.onnx.TypeProto.Tensor.prototype.elem_type = 0; +onnx_root.onnx.TypeProto.Tensor.prototype.shape = null; + +onnx_root.onnx.TypeProto.Sequence = class Sequence { + + constructor() { + } + + static decode(reader, length) { + const message = new onnx_root.onnx.TypeProto.Sequence(); + const end = length !== undefined ? reader.position + length : reader.length; + while (reader.position < end) { + const tag = reader.uint32(); + switch (tag >>> 3) { + case 1: + message.elem_type = onnx_root.onnx.TypeProto.decode(reader, reader.uint32()); + break; + default: + reader.skipType(tag & 7); + break; + } + } + return message; + } + + static decodeText(reader) { + const message = new onnx_root.onnx.TypeProto.Sequence(); + reader.start(); + while (!reader.end()) { + const tag = reader.tag(); + switch (tag) { + case "elem_type": + message.elem_type = onnx_root.onnx.TypeProto.decodeText(reader); + break; + default: + reader.field(tag, message); + break; + } + } + return message; + } +}; + +onnx_root.onnx.TypeProto.Sequence.prototype.elem_type = null; + +onnx_root.onnx.TypeProto.Map = class Map { + + constructor() { + } + + static decode(reader, length) { + const message = new onnx_root.onnx.TypeProto.Map(); + const end = length !== undefined ? reader.position + length : reader.length; + while (reader.position < end) { + const tag = reader.uint32(); + switch (tag >>> 3) { + case 1: + message.key_type = reader.int32(); + break; + case 2: + message.value_type = onnx_root.onnx.TypeProto.decode(reader, reader.uint32()); + break; + default: + reader.skipType(tag & 7); + break; + } + } + return message; + } + + static decodeText(reader) { + const message = new onnx_root.onnx.TypeProto.Map(); + reader.start(); + while (!reader.end()) { + const tag = reader.tag(); + switch (tag) { + case "key_type": + message.key_type = reader.int32(); + break; + case "value_type": + message.value_type = onnx_root.onnx.TypeProto.decodeText(reader); + break; + default: + reader.field(tag, message); + break; + } + } + return message; + } +}; + +onnx_root.onnx.TypeProto.Map.prototype.key_type = 0; +onnx_root.onnx.TypeProto.Map.prototype.value_type = null; + +onnx_root.onnx.TypeProto.Optional = class Optional { + + constructor() { + } + + static decode(reader, length) { + const message = new onnx_root.onnx.TypeProto.Optional(); + const end = length !== undefined ? reader.position + length : reader.length; + while (reader.position < end) { + const tag = reader.uint32(); + switch (tag >>> 3) { + case 1: + message.elem_type = onnx_root.onnx.TypeProto.decode(reader, reader.uint32()); + break; + default: + reader.skipType(tag & 7); + break; + } + } + return message; + } + + static decodeText(reader) { + const message = new onnx_root.onnx.TypeProto.Optional(); + reader.start(); + while (!reader.end()) { + const tag = reader.tag(); + switch (tag) { + case "elem_type": + message.elem_type = onnx_root.onnx.TypeProto.decodeText(reader); + break; + default: + reader.field(tag, message); + break; + } + } + return message; + } +}; + +onnx_root.onnx.TypeProto.Optional.prototype.elem_type = null; + +onnx_root.onnx.TypeProto.SparseTensor = class SparseTensor { + + constructor() { + } + + static decode(reader, length) { + const message = new onnx_root.onnx.TypeProto.SparseTensor(); + const end = length !== undefined ? reader.position + length : reader.length; + while (reader.position < end) { + const tag = reader.uint32(); + switch (tag >>> 3) { + case 1: + message.elem_type = reader.int32(); + break; + case 2: + message.shape = onnx_root.onnx.TensorShapeProto.decode(reader, reader.uint32()); + break; + default: + reader.skipType(tag & 7); + break; + } + } + return message; + } + + static decodeText(reader) { + const message = new onnx_root.onnx.TypeProto.SparseTensor(); + reader.start(); + while (!reader.end()) { + const tag = reader.tag(); + switch (tag) { + case "elem_type": + message.elem_type = reader.int32(); + break; + case "shape": + message.shape = onnx_root.onnx.TensorShapeProto.decodeText(reader); + break; + default: + reader.field(tag, message); + break; + } + } + return message; + } +}; + +onnx_root.onnx.TypeProto.SparseTensor.prototype.elem_type = 0; +onnx_root.onnx.TypeProto.SparseTensor.prototype.shape = null; + +onnx_root.onnx.TypeProto.Opaque = class Opaque { + + constructor() { + } + + static decode(reader, length) { + const message = new onnx_root.onnx.TypeProto.Opaque(); + const end = length !== undefined ? reader.position + length : reader.length; + while (reader.position < end) { + const tag = reader.uint32(); + switch (tag >>> 3) { + case 1: + message.domain = reader.string(); + break; + case 2: + message.name = reader.string(); + break; + default: + reader.skipType(tag & 7); + break; + } + } + return message; + } + + static decodeText(reader) { + const message = new onnx_root.onnx.TypeProto.Opaque(); + reader.start(); + while (!reader.end()) { + const tag = reader.tag(); + switch (tag) { + case "domain": + message.domain = reader.string(); + break; + case "name": + message.name = reader.string(); + break; + default: + reader.field(tag, message); + break; + } + } + return message; + } +}; + +onnx_root.onnx.TypeProto.Opaque.prototype.domain = ""; +onnx_root.onnx.TypeProto.Opaque.prototype.name = ""; + +onnx_root.onnx.OperatorSetIdProto = class OperatorSetIdProto { + + constructor() { + } + + static decode(reader, length) { + const message = new onnx_root.onnx.OperatorSetIdProto(); + const end = length !== undefined ? reader.position + length : reader.length; + while (reader.position < end) { + const tag = reader.uint32(); + switch (tag >>> 3) { + case 1: + message.domain = reader.string(); + break; + case 2: + message.version = reader.int64(); + break; + default: + reader.skipType(tag & 7); + break; + } + } + return message; + } + + static decodeText(reader) { + const message = new onnx_root.onnx.OperatorSetIdProto(); + reader.start(); + while (!reader.end()) { + const tag = reader.tag(); + switch (tag) { + case "domain": + message.domain = reader.string(); + break; + case "version": + message.version = reader.int64(); + break; + default: + reader.field(tag, message); + break; + } + } + return message; + } +}; + +onnx_root.onnx.OperatorSetIdProto.prototype.domain = ""; +onnx_root.onnx.OperatorSetIdProto.prototype.version = protobuf.Int64.create(0); + +onnx_root.onnx.OperatorStatus = { + "EXPERIMENTAL": 0, + "STABLE": 1 +}; + +onnx_root.onnx.FunctionProto = class FunctionProto { + + constructor() { + this.input = []; + this.output = []; + this.attribute = []; + this.node = []; + this.opset_import = []; + } + + static decode(reader, length) { + const message = new onnx_root.onnx.FunctionProto(); + const end = length !== undefined ? reader.position + length : reader.length; + while (reader.position < end) { + const tag = reader.uint32(); + switch (tag >>> 3) { + case 1: + message.name = reader.string(); + break; + case 4: + message.input.push(reader.string()); + break; + case 5: + message.output.push(reader.string()); + break; + case 6: + message.attribute.push(reader.string()); + break; + case 7: + message.node.push(onnx_root.onnx.NodeProto.decode(reader, reader.uint32())); + break; + case 8: + message.doc_string = reader.string(); + break; + case 9: + message.opset_import.push(onnx_root.onnx.OperatorSetIdProto.decode(reader, reader.uint32())); + break; + case 10: + message.domain = reader.string(); + break; + default: + reader.skipType(tag & 7); + break; + } + } + return message; + } + + static decodeText(reader) { + const message = new onnx_root.onnx.FunctionProto(); + reader.start(); + while (!reader.end()) { + const tag = reader.tag(); + switch (tag) { + case "name": + message.name = reader.string(); + break; + case "input": + reader.array(message.input, () => reader.string()); + break; + case "output": + reader.array(message.output, () => reader.string()); + break; + case "attribute": + reader.array(message.attribute, () => reader.string()); + break; + case "node": + message.node.push(onnx_root.onnx.NodeProto.decodeText(reader)); + break; + case "doc_string": + message.doc_string = reader.string(); + break; + case "opset_import": + message.opset_import.push(onnx_root.onnx.OperatorSetIdProto.decodeText(reader)); + break; + case "domain": + message.domain = reader.string(); + break; + default: + reader.field(tag, message); + break; + } + } + return message; + } +}; + +onnx_root.onnx.FunctionProto.prototype.name = ""; +onnx_root.onnx.FunctionProto.prototype.doc_string = ""; +onnx_root.onnx.FunctionProto.prototype.domain = ""; + +onnx_root.onnx.OperatorProto = class OperatorProto { + + constructor() { + } + + static decode(reader, length) { + const message = new onnx_root.onnx.OperatorProto(); + const end = length !== undefined ? reader.position + length : reader.length; + while (reader.position < end) { + const tag = reader.uint32(); + switch (tag >>> 3) { + case 1: + message.op_type = reader.string(); + break; + case 2: + message.since_version = reader.int64(); + break; + case 3: + message.status = reader.int32(); + break; + case 10: + message.doc_string = reader.string(); + break; + default: + reader.skipType(tag & 7); + break; + } + } + return message; + } + + static decodeText(reader) { + const message = new onnx_root.onnx.OperatorProto(); + reader.start(); + while (!reader.end()) { + const tag = reader.tag(); + switch (tag) { + case "op_type": + message.op_type = reader.string(); + break; + case "since_version": + message.since_version = reader.int64(); + break; + case "status": + message.status = reader.enum(onnx_root.onnx.OperatorStatus); + break; + case "doc_string": + message.doc_string = reader.string(); + break; + default: + reader.field(tag, message); + break; + } + } + return message; + } +}; + +onnx_root.onnx.OperatorProto.prototype.op_type = ""; +onnx_root.onnx.OperatorProto.prototype.since_version = protobuf.Int64.create(0); +onnx_root.onnx.OperatorProto.prototype.status = 0; +onnx_root.onnx.OperatorProto.prototype.doc_string = ""; + +onnx_root.onnx.OperatorSetProto = class OperatorSetProto { + + constructor() { + this.operator = []; + this.functions = []; + } + + static decode(reader, length) { + const message = new onnx_root.onnx.OperatorSetProto(); + const end = length !== undefined ? reader.position + length : reader.length; + while (reader.position < end) { + const tag = reader.uint32(); + switch (tag >>> 3) { + case 1: + message.magic = reader.string(); + break; + case 2: + message.ir_version = reader.int64(); + break; + case 3: + message.ir_version_prerelease = reader.string(); + break; + case 7: + message.ir_build_metadata = reader.string(); + break; + case 4: + message.domain = reader.string(); + break; + case 5: + message.opset_version = reader.int64(); + break; + case 6: + message.doc_string = reader.string(); + break; + case 8: + message.operator.push(onnx_root.onnx.OperatorProto.decode(reader, reader.uint32())); + break; + case 9: + message.functions.push(onnx_root.onnx.FunctionProto.decode(reader, reader.uint32())); + break; + default: + reader.skipType(tag & 7); + break; + } + } + return message; + } + + static decodeText(reader) { + const message = new onnx_root.onnx.OperatorSetProto(); + reader.start(); + while (!reader.end()) { + const tag = reader.tag(); + switch (tag) { + case "magic": + message.magic = reader.string(); + break; + case "ir_version": + message.ir_version = reader.int64(); + break; + case "ir_version_prerelease": + message.ir_version_prerelease = reader.string(); + break; + case "ir_build_metadata": + message.ir_build_metadata = reader.string(); + break; + case "domain": + message.domain = reader.string(); + break; + case "opset_version": + message.opset_version = reader.int64(); + break; + case "doc_string": + message.doc_string = reader.string(); + break; + case "operator": + message.operator.push(onnx_root.onnx.OperatorProto.decodeText(reader)); + break; + case "functions": + message.functions.push(onnx_root.onnx.FunctionProto.decodeText(reader)); + break; + default: + reader.field(tag, message); + break; + } + } + return message; + } +}; + +onnx_root.onnx.OperatorSetProto.prototype.magic = ""; +onnx_root.onnx.OperatorSetProto.prototype.ir_version = protobuf.Int64.create(0); +onnx_root.onnx.OperatorSetProto.prototype.ir_version_prerelease = ""; +onnx_root.onnx.OperatorSetProto.prototype.ir_build_metadata = ""; +onnx_root.onnx.OperatorSetProto.prototype.domain = ""; +onnx_root.onnx.OperatorSetProto.prototype.opset_version = protobuf.Int64.create(0); +onnx_root.onnx.OperatorSetProto.prototype.doc_string = ""; diff --git a/media/CircleGraph/external/onnx.js b/media/CircleGraph/external/onnx.js new file mode 100644 index 00000000..c02bdb59 --- /dev/null +++ b/media/CircleGraph/external/onnx.js @@ -0,0 +1,1644 @@ +/* jshint esversion: 6 */ + +var onnx = onnx || {}; +var protobuf = protobuf || require('./protobuf'); +var flatbuffers = flatbuffers || require('./flatbuffers'); + +onnx.ModelFactory = class { + + match(context) { + const identifier = context.identifier; + const extension = identifier.split('.').pop().toLowerCase(); + if (identifier.endsWith('saved_model.pb') || identifier.endsWith('predict_net.pb') || identifier.endsWith('init_net.pb')) { + return undefined; + } + if (identifier.endsWith('predict_net.pbtxt') || identifier.endsWith('predict_net.prototxt') || + identifier.endsWith('init_net.pbtxt') || identifier.endsWith('init_net.prototxt')) { + return undefined; + } + let tags = context.tags('pb'); + if (tags.size > 0) { + if (tags.size === 1 && tags.get(1) === 2) { + const tags = context.tags('pb+'); + const match = (tags, schema) => { + for (const pair of schema) { + const key = pair[0]; + const inner = pair[1]; + if (tags[key] === undefined) { + continue; + } + else if (inner === false) { + return false; + } + if (Array.isArray(inner)) { + const value = tags[key]; + if (typeof value !== 'object' || !match(value, inner)) { + return false; + } + } + else if (inner !== tags[key]) { + return false; + } + } + return true; + }; + // mediapipe.BoxDetectorIndex + if (match(tags, [[1,[[1,[[1,[[1,5],[2,5],[3,5],[4,5],[6,0],[7,5],[8,5],[10,5],[11,0],[12,0]]],[2,5],[3,[]]]],[2,false],[3,false],[4,false],[5,false]]],[2,false],[3,false]] )) { + return undefined; + } + // third_party.tensorflow.python.keras.protobuf.SavedMetadata + if (match(tags, [[1,[[1,[[1,0],[2,0]]],[2,0],[3,2],[4,2],[5,2]]]])) { + return undefined; + } + } + if (Array.from(tags.keys()).every((tag) => tag <= 100) && + Array.from(tags.values()).every((type) => type < 5)) { + // TensorProto + if (tags.get(1) === 0 && tags.get(2) === 0 && tags.get(9) === 2) { + const schema = [[1,0],[2,0],[4,2],[5,2],[7,2],[8,2],[9,2]]; + if (schema.every((pair) => !tags.has(pair[0]) || tags.get(pair[0]) === pair[1])) { + return 'onnx.pb.TensorProto'; + } + } + // GraphProto + if (tags.get(1) === 2) { + const schema = [[1,2],[2,2],[3,2],[4,2],[5,2],[6,0],[7,0],[8,2],[9,2],[10,2],[11,2],[12,2],[13,2],[14,2]]; + if (schema.every((pair) => !tags.has(pair[0]) || tags.get(pair[0]) === pair[1])) { + const decode = (buffer, value) => { + const reader = protobuf.BinaryReader.open(buffer); + const length = reader.length; + while (reader.position < length) { + const tag = reader.uint32(); + const number = tag >>> 3; + const type = tag & 7; + if (value === number) { + return type === 2 ? reader.bytes() : null; + } + else { + reader.skipType(type); + } + } + return null; + }; + const stream = context.stream; + const buffer = stream.peek(); + const nodeBuffer = decode(buffer, 1); + if (nodeBuffer) { + const nameBuffer = decode(nodeBuffer, 4); + if (nameBuffer && nameBuffer.every((c) => c > 0x20 && c < 0x7f)) { + return 'onnx.pb.GraphProto'; + } + } + } + } + // ModelProto + if (tags.get(7) === 2) { + const schema = [[1,0],[2,2],[3,2],[4,2][5,0],[6,2],[7,2],[8,2],[14,2],[20,2]]; + if (schema.every((pair) => !tags.has(pair[0]) || tags.get(pair[0]) === pair[1])) { + return 'onnx.pb.ModelProto'; + } + } + } + } + const stream = context.stream; + if (stream.length > 5) { + const buffer = stream.peek(Math.min(stream.length, 32)); + if (buffer[0] === 0x08 && buffer[1] < 0x0A && buffer[2] === 0x12) { + const producers = [ + 'backend-test', 'BrainwaveCompiler', + 'CNTK', + 'keras2onnx', 'Kneron', 'kneron_formatter', 'kneron_kl530_test_case', + 'darknet to ONNX example', + 'htshinichi', + 'MATLAB Deep Learning Toolbox Converter for ONNX Model Format', 'ML.NET', 'MVTec Software', + 'onnx-caffe2', 'onnx-example', 'onnx.quantize', 'onnx.utils.extract_model', 'OnnxMLTools', 'onnx_test', 'onnxruntime-tools', 'onnxruntime.transformers', + 'PaddlePaddle', 'pytorch', + 'sclblonnx', 'skl2onnx', + 'Tencent YouTu', 'tf2onnx', 'tflite2onnx', + 'WinMLTools' + ]; + if (producers.some((producer) => Array.from(producer).every((ch, index) => index + 4 < buffer.length && ch.charCodeAt(0) === buffer[index + 4]))) { + return 'onnx.pb.ModelProto'; + } + } + } + tags = context.tags('pbtxt'); + if (tags.has('ir_version')) { + return 'onnx.pbtxt.ModelProto'; + } + if (tags.has('graph') && extension !== 'model') { + return 'onnx.pbtxt.ModelProto'; + } + if (context.tags('flatbuffers').get('file_identifier') === 'ORTM') { + return 'onnx.flatbuffers'; + } + return undefined; + } + + open(context, match) { + const open = (model, format) => { + return onnx.Metadata.open(context).then((metadata) => { + return new onnx.Model(metadata, model, format); + }); + }; + switch (match) { + case 'onnx.pbtxt.ModelProto': + return context.require('./onnx-proto').then(() => { + try { + onnx.proto = protobuf.get('onnx').onnx; + const stream = context.stream; + const reader = protobuf.TextReader.open(stream); + const model = onnx.proto.ModelProto.decodeText(reader); + const format = 'ONNX' + (model.ir_version ? ' v' + model.ir_version.toString() : ''); + return open(model, format); + } + catch (error) { + const message = error && error.message ? error.message : error.toString(); + throw new onnx.Error('File text format is not onnx.ModelProto (' + message.replace(/\.$/, '') + ').'); + } + }); + case 'onnx.pb.TensorProto': + return context.require('./onnx-proto').then(() => { + // TensorProto + // input_0.pb, output_0.pb + try { + onnx.proto = protobuf.get('onnx').onnx; + const stream = context.stream; + const reader = protobuf.BinaryReader.open(stream); + const tensor = onnx.proto.TensorProto.decode(reader); + tensor.name = tensor.name || context.identifier; + const model = new onnx.proto.ModelProto(); + model.graph = new onnx.proto.GraphProto(); + model.graph.initializer = [ tensor ]; + model.graph.value_info = [ new onnx.proto.ValueInfoProto() ]; + model.graph.value_info[0].name = tensor.name; + model.graph.node = [ new onnx.proto.NodeProto() ]; + model.graph.node[0].op_type = 'Constant'; + model.graph.node[0].attribute = [ new onnx.proto.AttributeProto() ]; + model.graph.node[0].attribute[0].name = 'value'; + model.graph.node[0].attribute[0].t = tensor; + const format = 'ONNX Tensor'; + return open(model, format); + } + catch (error) { + const message = error && error.message ? error.message : error.toString(); + throw new onnx.Error('File format is not onnx.TensorProto (' + message.replace(/\.$/, '') + ').'); + } + }); + case 'onnx.pb.GraphProto': + return context.require('./onnx-proto').then(() => { + // GraphProto + try { + onnx.proto = protobuf.get('onnx').onnx; + const stream = context.stream; + const reader = protobuf.BinaryReader.open(stream); + const model = new onnx.proto.ModelProto(); + model.graph = onnx.proto.GraphProto.decode(reader); + const format = 'ONNX'; + return open(model, format); + } + catch (error) { + const message = error && error.message ? error.message : error.toString(); + throw new onnx.Error('File format is not onnx.GraphProto (' + message.replace(/\.$/, '') + ').'); + } + }); + case 'onnx.pb.ModelProto': + return context.require('./onnx-proto').then(() => { + // ModelProto + try { + onnx.proto = protobuf.get('onnx').onnx; + const stream = context.stream; + const reader = protobuf.BinaryReader.open(stream); + const model = onnx.proto.ModelProto.decode(reader); + const format = 'ONNX' + (model.ir_version ? ' v' + model.ir_version.toString() : ''); + return open(model, format); + } + catch (error) { + const message = error && error.message ? error.message : error.toString(); + throw new onnx.Error('File format is not onnx.ModelProto (' + message.replace(/\.$/, '') + ').'); + } + }); + case 'onnx.flatbuffers': { + return context.require('./ort-schema').then((/* schema */) => { + try { + onnx.schema = flatbuffers.get('ort').onnxruntime.experimental.fbs; + const stream = context.stream; + const reader = flatbuffers.BinaryReader.open(stream); + const session = onnx.schema.InferenceSession.create(reader); + const model = session.model; + const graph = model.graph; + graph.node = graph.nodes; + graph.doc_string = model.graph_doc_string; + graph.value_info = graph.node_args; + graph.input = graph.inputs.map((input) => { + return { name: input }; + }); + graph.output = graph.outputs.map((output) => { + return { name: output }; + }); + graph.initializer = graph.initializers.map((tensor) => { + tensor.data_location = onnx.DataLocation.DEFAULT; + return tensor; + }); + graph.sparse_initializer = graph.sparse_initializers.map((tensor) => { + tensor.values.data_location = onnx.DataLocation.DEFAULT; + tensor.indices.data_location = onnx.DataLocation.DEFAULT; + return tensor; + }); + delete graph.nodes; + delete graph.node_args; + delete graph.inputs; + delete graph.outputs; + delete graph.initializers; + delete graph.sparse_initializers; + delete model.graph_doc_string; + for (const node of graph.node) { + node.input = node.inputs; + node.output = node.outputs; + node.attribute = node.attributes; + delete node.inputs; + delete node.outputs; + delete node.attributes; + } + const format = 'ONNX Runtime' + (model.ir_version ? ' v' + model.ir_version.toString() : ''); + return open(model, format); + } + catch (error) { + const message = error && error.message ? error.message : error.toString(); + throw new onnx.Error('File format is not ort.Model (' + message.replace(/\.$/, '') + ').'); + } + }); + } + default: { + throw new onnx.Error("Unknown ONNX format '" + match + "'."); + } + } + } +}; + +onnx.Model = class { + + constructor(metadata, model, format) { + this._graphs = []; + this._format = format; + this._producerName = model.producer_name; + this._producerVersion = model.producer_version; + this._domain = model.domain; + this._modelVersion = model.model_version; + this._description = model.doc_string; + this._metadata = []; + this._imports = null; + + const imports = new Map(); + if (model.opset_import && model.opset_import.length > 0) { + for (const opset_import of model.opset_import) { + const domain = opset_import.domain || 'ai.onnx'; + const version = opset_import.version ? opset_import.version.toNumber() : 0; + if (!imports.has(domain) || imports.get(domain) > version) { + imports.set(domain, version); + } + } + this._imports = Array.from(imports).map((pair) => pair[0] + ' v' + pair[1].toString()); + } + if (imports.size == 0) { + imports.set('ai.onnx', 1); + imports.set('ai.onnx.ml', 1); + } + + let imageFormat = ''; + if (model.metadata_props) { + const imageMetadata = {}; + for (const metadata_prop of model.metadata_props) { + switch (metadata_prop.key) { + case 'author': + this._author = metadata_prop.value; + break; + case 'company': + this._company = metadata_prop.value; + break; + case 'converted_from': + this._converted_from = metadata_prop.value; + break; + case 'license': + this._license = metadata_prop.value; + break; + case 'license_url': + this._licenseUrl = metadata_prop.value; + break; + case 'Image.BitmapPixelFormat': + case 'Image.ColorSpaceGamma': + case 'Image.NominalPixelRange': + imageMetadata[metadata_prop.key] = metadata_prop.value; + break; + default: + this._metadata.push({ name: metadata_prop.key, value: metadata_prop.value}); + break; + } + } + imageFormat = [ imageMetadata['Image.BitmapPixelFormat'], imageMetadata['Image.ColorSpaceGamma'], imageMetadata['Image.NominalPixelRange'] ].filter((item) => item); + } + this._graphs = []; + if (model && model.graph) { + let key = 1000; + const context = {}; + context.metadata = new onnx.GraphMetadata(metadata, imports); + context.imageFormat = imageFormat; + for (const func of model.functions || []) { + context.metadata.add(new onnx.Function(context, func)); + } + context.graphs = new Map(); + context.graph = function(graph) { + graph.key = graph.key || (key++).toString(); + if (!this.graphs.has(graph.key)) { + this.graphs.set(graph.key, new onnx.Graph(this, graph)); + } + return this.graphs.get(graph.key); + }; + const graphs = [ model.graph ]; + while (graphs.length > 0) { + const graph = graphs.shift(); + this._graphs.push(context.graph(graph)); + for (const node of graph.node || []) { + for (const attribute of node.attribute || []) { + if (attribute.g) { + graphs.push(attribute.g); + } + else if (attribute.graphs && attribute.graphs.length > 0) { + graphs.push(...attribute.graphs); + } + } + } + } + } + } + + get format() { + return this._format; + } + + get imports() { + return this._imports; + } + + get producer() { + const producer = []; + if (this._producerName) { + producer.push(this._producerName); + } + if (this._producerVersion && this._producerVersion.length > 0) { + producer.push(this._producerVersion); + } + if (producer.length > 0) { + return producer.join(' '); + } + return null; + } + + get domain() { + return this._domain || null; + } + + get description() { + return this._description || null; + } + + get author() { + return this._author || null; + } + + get company() { + return this._company || null; + } + + get source() { + return this._converted_from || null; + } + + get license() { + const license = []; + if (this._license && this._license.length > 0) { + license.push(this._license); + } + if (this._licenseUrl && this._licenseUrl.length > 0) { + license.push('' + this._licenseUrl + ''); + } + if (license.length > 0) { + return license; + } + return null; + } + + get metadata() { + return this._metadata; + } + + get graphs() { + return this._graphs; + } +}; + +onnx.Graph = class { + + constructor(context, graph) { + this._node = ''; + this._description = ''; + this._nodes = []; + this._inputs = []; + this._outputs = []; + this._name = graph.name || null; + this._description = graph.doc_string || ''; + + const tensors = onnx.Utility.createTensors(graph.node); + + for (const initializer of graph.initializer) { + const tensor = tensors.map(initializer.name); + tensor.initializer = new onnx.Tensor(initializer, 'Initializer'); + } + for (const sparse_initializer of graph.sparse_initializer) { + const tensor = tensors.map(sparse_initializer.values.name); + tensor.initializer = new onnx.Tensor(sparse_initializer, 'Sparse Initializer'); + } + for (const tensor_annotation of graph.quantization_annotation || []) { + const tensor = tensors.map(tensor_annotation.tensor_name); + const annotation = {}; + for (const pair of tensor_annotation.quant_parameter_tensor_names) { + annotation[pair.key] = pair.value; + } + tensor.annotation = annotation; + } + for (const valueInfo of graph.value_info) { + const tensor = tensors.map(valueInfo.name); + tensor.type = onnx.Utility.formatType(valueInfo.type, context.imageFormat); + tensor.description = valueInfo.doc_string; + } + graph.input = graph.input.map((valueInfo) => { + const tensor = tensors.map(valueInfo.name); + tensor.type = onnx.Utility.formatType(valueInfo.type, context.imageFormat); + tensor.description = valueInfo.doc_string; + return tensor; + }); + graph.output = graph.output.map((valueInfo) => { + const tensor = tensors.map(valueInfo.name); + tensor.type = onnx.Utility.formatType(valueInfo.type, context.imageFormat); + tensor.description = valueInfo.doc_string; + return tensor; + }); + new onnx.Inference(graph.node, graph.output); + const args = new Map(); + args.map = function(name) { + if (!this.has(name)) { + const tensor = tensors.map(name); + const type = tensor.initializer ? tensor.initializer.type : tensor.type || null; + this.set(name, new onnx.Argument(name, type, tensor.initializer, tensor.annotation, tensor.description)); + } + return this.get(name); + }; + this._nodes = onnx.Utility.createNodes(context, graph.node, graph.input, graph.output, tensors, args); + for (const input of graph.input) { + const argument = args.map(input.name); + if (!argument.initializer) { + this._inputs.push(new onnx.Parameter(input.name, [ argument ])); + } + } + for (const output of graph.output) { + const argument = args.map(output.name); + if (!argument.initializer) { + this._outputs.push(new onnx.Parameter(output.name, [ argument ])); + } + } + } + + get name() { + return this._name; + } + + get description() { + return this._description; + } + + get groups() { + return false; + } + + get inputs() { + return this._inputs; + } + + get outputs() { + return this._outputs; + } + + get nodes() { + return this._nodes; + } + + toString() { + return 'graph(' + this.name + ')'; + } +}; + +onnx.Parameter = class { + + constructor(name, args) { + this._name = name; + this._arguments = args; + } + + get name() { + return this._name; + } + + get visible() { + return true; + } + + get arguments() { + return this._arguments; + } +}; + +onnx.Argument = class { + + constructor(name, type, initializer, annotation, description) { + if (typeof name !== 'string') { + throw new onnx.Error("Invalid argument identifier '" + JSON.stringify(name) + "'."); + } + this._name = name; + this._type = type || null; + this._initializer = initializer || null; + this._annotation = annotation; + this._description = description || ''; + } + + get name() { + return this._name; + } + + get type() { + return this._type; + } + + get description() { + return this._description; + } + + get quantization() { + if (this._annotation) { + return Object.keys(this._annotation).map((key) => key + ': ' + this._annotation[key]).join(', '); + } + return null; + } + + get initializer() { + return this._initializer; + } +}; + +onnx.Node = class { + + constructor(context, op_type, domain, name, description, attributes, inputs, outputs) { + this._type = context.metadata.type(op_type, domain) || { name: op_type, module: domain }; + if (this.type.module !== domain && !(this._type instanceof onnx.Function)) { + this._type = Object.assign({}, this.type); + this._type.name = op_type; + this._type.module = domain; + } + this._name = name || ''; + this._description = description || ''; + this._inputs = inputs; + this._outputs = outputs; + this._attributes = (attributes || []).map((attribute) => new onnx.Attribute(context, op_type, domain, attribute)); + } + + get type() { + return this._type; + } + + get name() { + return this._name; + } + + get description() { + return this._description; + } + + get group() { + return null; + } + + get attributes() { + return this._attributes; + } + + get inputs() { + return this._inputs; + } + + get outputs() { + return this._outputs; + } +}; + +onnx.Attribute = class { + + constructor(context, op_type, domain, attribute) { + this._name = attribute.name; + this._description = attribute.doc_string || ''; + this._type = null; + this._value = null; + switch (attribute.type) { + case onnx.AttributeType.FLOAT: + this._value = attribute.f; + this._type = 'float32'; + break; + case onnx.AttributeType.INT: + this._value = attribute.i; + this._type = 'int64'; + break; + case onnx.AttributeType.STRING: + switch (op_type) { + case 'Int8GivenTensorFill': + this._value = Array.from(attribute.s); + break; + default: + this._value = onnx.Utility.decodeText(attribute.s); + break; + } + this._type = 'string'; + break; + case onnx.AttributeType.TENSOR: + this._value = new onnx.Tensor(attribute.t); + this._type = 'tensor'; + break; + case onnx.AttributeType.GRAPH: + this._value = context.graph(attribute.g); + this._type = 'graph'; + break; + case onnx.AttributeType.FLOATS: + this._value = attribute.floats; + this._type = 'float32[]'; + break; + case onnx.AttributeType.INTS: + this._value = attribute.ints; + this._type = 'int64[]'; + break; + case onnx.AttributeType.STRINGS: + this._value = attribute.strings.map((s) => onnx.Utility.decodeText(s)); + this._type = 'string[]'; + break; + case onnx.AttributeType.TENSORS: + this._value = attribute.tensors.map((tensor) => new onnx.Tensor(tensor)); + this._type = 'tensor[]'; + break; + case onnx.AttributeType.GRAPHS: + this._value = attribute.graphs.map((graph) => context.graph(graph)); + this._type = 'graph[]'; + break; + case onnx.AttributeType.SPARSE_TENSOR: + this._value = new onnx.Tensor(attribute.sparse_tensor); + this._type = 'tensor'; + break; + case onnx.AttributeType.SPARSE_TENSORS: + this._value = attribute.sparse_tensors.map((tensor) => new onnx.Tensor(tensor)); + this._type = 'tensor[]'; + break; + case onnx.AttributeType.TYPE_PROTO: + this._value = onnx.Utility.formatType(attribute.tp, context.imageFormat); + this._type = 'type'; + break; + case onnx.AttributeType.TYPE_PROTOS: + this._value = attribute.type_protos.map((type) => onnx.Utility.formatType(type, context.imageFormat)); + this._type = 'type[]'; + break; + default: + throw new onnx.Error("Unknown attribute type '" + attribute.type + "'."); + } + + const metadata = context.metadata.attribute(op_type, domain, attribute.name); + if (metadata) { + if (Object.prototype.hasOwnProperty.call(metadata, 'default') && this._value == metadata.default) { + this._visible = false; + } + if (metadata.type === 'DataType') { + this._type = metadata.type; + const value = this._value ? parseInt(this._value.toString(), 10) : this._value; + this._value = Number.isInteger(value) ? onnx.Utility.formatDataType(value) : value; + } + } + } + + get name() { + return this._name; + } + + get type() { + return this._type; + } + + get value() { + return this._value; + } + + get description() { + return this._description; + } + + get visible() { + return this._visible == false ? false : true; + } +}; + +onnx.Tensor = class { + + constructor(tensor, kind) { + this._kind = kind || null; + const data = (tensor) => { + let data = undefined; + if (tensor.data_location === onnx.DataLocation.DEFAULT) { + switch (tensor.data_type) { + case onnx.DataType.FLOAT16: + if (tensor.int32_data && tensor.int32_data.length > 0) { + const buffer = new Uint8Array(tensor.int32_data.length << 1); + const view = new DataView(buffer.buffer, buffer.byteOffset, buffer.byteLength); + const array = tensor.int32_data; + for (let i = 0; i < array.length; i++) { + view.setUint16(i << 1, array[i], true); + } + data = { + type: tensor.data_type, + buffer: buffer + }; + } + break; + case onnx.DataType.FLOAT: + data = new Float32Array(tensor.float_data); + break; + case onnx.DataType.DOUBLE: + data = new Float64Array(tensor.double_data); + break; + case onnx.DataType.BOOL: + data = new Array(tensor.int32_data.size); + for (let i = 0; i < data.length; i++) { + data[i] = data[i] === 0 ? false : true; + } + break; + case onnx.DataType.INT8: + data = new Int8Array(tensor.int32_data); + break; + case onnx.DataType.UINT8: + data = new Uint8Array(tensor.int32_data); + break; + case onnx.DataType.INT16: + data = new Int32Array(tensor.int32_data); + break; + case onnx.DataType.UINT16: + data = new Int32Array(tensor.int32_data); + break; + case onnx.DataType.INT32: + data = new Int32Array(tensor.int32_data); + break; + case onnx.DataType.UINT32: + case onnx.DataType.UINT64: + data = tensor.uint64_data; + break; + case onnx.DataType.INT64: + data = tensor.int64_data; + break; + } + if (data && (Array.isArray(data) || ArrayBuffer.isView(data)) && data.length === 0) { + data = undefined; + } + if (!data && tensor.raw_data && tensor.raw_data.length > 0) { + data = { + type: tensor.data_type, + buffer: tensor.raw_data + }; + } + } + return data; + }; + const location = (tensor) => { + return onnx.Utility.formatLocation(tensor.data_location); + }; + if ((onnx.proto && tensor instanceof onnx.proto.SparseTensorProto) || + (onnx.schema && tensor instanceof onnx.schema.SparseTensor)) { + this._name = tensor.values.name || ''; + this._type = new onnx.TensorType(tensor.values.data_type, new onnx.TensorShape(tensor.dims.map((dim) => dim)), null); + this._location = Array.from(new Set([ location(tensor.values), location(tensor.indices) ])).join(':'); + this._values = data(tensor.values); + this._indices = data(tensor.indices); + } + else { + this._name = tensor.name || ''; + this._type = new onnx.TensorType(tensor.data_type, new onnx.TensorShape(tensor.dims.map((dim) => dim)), null); + this._location = location(tensor); + this._values = data(tensor); + } + } + + get name() { + return this._name; + } + + get kind() { + return this._kind; + } + + get type() { + return this._type; + } + + get state() { + return this._context().state || null; + } + + get value() { + const context = this._context(); + if (context.state) { + return null; + } + context.limit = Number.MAX_SAFE_INTEGER; + return this._decode(context, 0); + } + + toString() { + const context = this._context(); + if (context.state) { + return ''; + } + context.limit = 10000; + const value = this._decode(context, 0); + return onnx.Tensor._stringify(value, '', ' '); + } + + _context() { + const context = {}; + context.state = null; + if (this._sparse) { + context.state = 'Sparse data not implemented.'; + return context; + } + if (this._location !== 'default') { + context.state = "Data '" + this._location + "' location not implemented."; + return context; + } + const decode = (data) => { + if (!data || Array.isArray(data) || ArrayBuffer.isView(data)) { + return data; + } + const buffer = data.buffer; + const view = new DataView(buffer.buffer, buffer.byteOffset, buffer.byteLength); + const type = data.type; + data = undefined; + switch (type) { + case onnx.DataType.BOOL: + data = new Array(buffer.length); + for (let i = 0; i < buffer.length; i++) { + data[i] = view.getUint8(i) === 0 ? false : true; + } + break; + case onnx.DataType.FLOAT16: + data = new Float32Array(buffer.length >> 1); + for (let i = 0; i < data.length; i++) { + data[i] = view.getFloat16(i << 1, true); + } + break; + case onnx.DataType.FLOAT: + data = new Float32Array(buffer.length >> 2); + for (let i = 0; i < data.length; i++) { + data[i] = view.getFloat32(i << 2, true); + } + break; + case onnx.DataType.DOUBLE: + data = new Float64Array(buffer.length >> 3); + for (let i = 0; i < data.length; i++) { + data[i] = view.getFloat64(i << 3, true); + } + break; + case onnx.DataType.INT8: + data = new Int8Array(buffer.length); + for (let i = 0; i < data.length; i++) { + data[i] = view.getInt8(i, true); + } + break; + case onnx.DataType.UINT8: + data = new Uint8Array(buffer.length); + for (let i = 0; i < data.length; i++) { + data[i] = view.getUint8(i, true); + } + break; + case onnx.DataType.INT16: + data = new Int16Array(buffer.length >> 1); + for (let i = 0; i < data.length; i++) { + data[i] = view.getInt16(i << 1, true); + } + break; + case onnx.DataType.UINT16: + data = new Uint16Array(buffer.length >> 1); + for (let i = 0; i < data.length; i++) { + data[i] = view.getUint16(i << 1, true); + } + break; + case onnx.DataType.INT32: + data = new Int32Array(buffer.length >> 2); + for (let i = 0; i < data.length; i++) { + data[i] = view.getInt32(i << 2, true); + } + break; + case onnx.DataType.UINT32: + data = new Uint32Array(buffer.length >> 2); + for (let i = 0; i < data.length; i++) { + data[i] = view.getUint32(i << 2, true); + } + break; + case onnx.DataType.INT64: + data = new Array(buffer.length >> 3); + for (let i = 0; i < data.length; i++) { + data[i] = view.getInt64(i << 3, true); + } + break; + case onnx.DataType.UINT64: + data = new Array(buffer.length >> 3); + for (let i = 0; i < data.length; i++) { + data[i] = view.getUint64(i << 3, true); + } + break; + } + return data; + }; + this._values = decode(this._values); + if (!this._values) { + context.state = 'Tensor data is empty.'; + return context; + } + this._indices = decode(this._indices); + context.values = this._values; + context.indices = this._indices; + context.index = 0; + context.dataType = this.type.dataType; + context.shape = this.type.shape.dimensions; + context.data = function() { + if (!this._data) { + if (this.indices && this.values && this.indices.length === this.values.length) { + const size = context.shape.reduce((a, b) => a * b, 1); + const indices = this.indices; + const values = this.values; + const array = new values.constructor(size); + switch (this.dataType) { + case 'boolean': + array.fill(false); + break; + case 'int64': + case 'uint64': + break; + } + if (indices.length > 0) { + if (Object.prototype.hasOwnProperty.call(indices[0], 'low')) { + for (let i = 0; i < indices.length; i++) { + const index = indices[i]; + array[index.high === 0 ? index.low : index.toNumber()] = values[i]; + } + } + else { + for (let i = 0; i < indices.length; i++) { + array[indices[i]] = values[i]; + } + } + } + this._data = array; + } + else { + this._data = this.values; + } + } + return this._data; + }; + return context; + } + + _decode(context, dimension) { + const shape = context.shape.length !== 0 ? context.shape : [ 1 ]; + const results = []; + const size = shape[dimension]; + const data = context.data(); + if (dimension == shape.length - 1) { + for (let i = 0; i < size; i++) { + if (context.index > context.limit) { + results.push('...'); + return results; + } + results.push(data[context.index++]); + } + } + else { + for (let j = 0; j < size; j++) { + if (context.index > context.limit) { + results.push('...'); + return results; + } + results.push(this._decode(context, dimension + 1)); + } + } + if (context.shape.length == 0) { + return results[0]; + } + return results; + } + + static _stringify(value, indentation, indent) { + if (Array.isArray(value)) { + const result = []; + result.push(indentation + '['); + const items = value.map((item) => onnx.Tensor._stringify(item, indentation + indent, indent)); + if (items.length > 0) { + result.push(items.join(',\n')); + } + result.push(indentation + ']'); + return result.join('\n'); + } + if (typeof value == 'string') { + return indentation + value; + } + if (value == Infinity) { + return indentation + 'Infinity'; + } + if (value == -Infinity) { + return indentation + '-Infinity'; + } + if (isNaN(value)) { + return indentation + 'NaN'; + } + return indentation + value.toString(); + } +}; + +onnx.TensorType = class { + + constructor(dataType, shape, denotation) { + this._dataType = onnx.Utility.formatDataType(dataType); + this._shape = shape; + this._denotation = denotation || null; + } + + get dataType() { + return this._dataType; + } + + get shape() { + return this._shape; + } + + get denotation() { + return this._denotation; + } + + toString() { + return this.dataType + this._shape.toString(); + } +}; + +onnx.TensorShape = class { + + constructor(dimensions) { + this._dimensions = dimensions; + } + + get dimensions() { + return this._dimensions; + } + + toString() { + if (!this._dimensions || this._dimensions.length == 0) { + return ''; + } + return '[' + this._dimensions.join(',') + ']'; + } +}; + +onnx.SequenceType = class { + + constructor(elementType, denotation) { + this._elementType = elementType; + this._denotation = denotation; + } + + get elementType() { + return this._elementType; + } + + get dennotation() { + return this._dennotation; + } + + toString() { + return 'sequence<' + this._elementType.toString() + '>'; + } +}; + +onnx.MapType = class { + + constructor(keyType, valueType, denotation) { + this._keyType = onnx.Utility.formatDataType(keyType); + this._valueType = valueType; + this._denotation = denotation; + } + + get keyType() { + return this._keyType; + } + + get valueType() { + return this._valueType; + } + + get denotation() { + return this._denotation; + } + + toString() { + return 'map<' + this._keyType + ',' + this._valueType.toString() + '>'; + } +}; + +onnx.OpaqueType = class { + + constructor(domain, name) { + this._domain = domain; + this._name = name; + } + + toString() { + const name = (this._domain ? (this._domain + '.') : '') + this._name; + return 'opaque<' + name + '>'; + } +}; + +onnx.Function = class { + + constructor(context, func) { + this._name = func.name; + this._domain = func.domain; + this._description = func.doc_string; + this._inputs = []; + this._outputs = []; + this._attributes = func.attribute.map((attribtue) => { return { name: attribtue }; }); + const tensors = onnx.Utility.createTensors(func.node); + func.input = func.input.map((input) => tensors.map(input)); + func.output = func.output.map((output) => tensors.map(output)); + const args = new Map(); + args.map = function(name) { + if (!this.has(name)) { + const tensor = tensors.map(name); + const type = tensor.initializer ? tensor.initializer.type : tensor.type || null; + this.set(name, new onnx.Argument(name, type, tensor.initializer, tensor.annotation, tensor.description)); + } + return this.get(name); + }; + this._nodes = onnx.Utility.createNodes(context, func.node, func.input, func.output, tensors, args); + for (const input of func.input) { + const argument = args.map(input.name); + if (!argument.initializer) { + this._inputs.push(new onnx.Parameter(input.name, [ argument ])); + } + } + for (const output of func.output) { + const argument = args.map(output.name); + if (!argument.initializer) { + this._outputs.push(new onnx.Parameter(output.name, [ argument ])); + } + } + } + + get type() { + return 'function'; + } + + get name() { + return this._name; + } + + get module() { + return this._domain; + } + + get description() { + return this._description; + } + + get inputs() { + return this._inputs; + } + + get outputs() { + return this._outputs; + } + + get attributes() { + return this._attributes; + } + + get nodes() { + return this._nodes; + } +}; + +onnx.GraphMetadata = class { + + constructor(metadata, imports) { + this._metadata = metadata; + this._imports = imports; + this._cache = new Map(); + this._attributes = new Map(); + this._functions = new Map(); + } + + add(func) { + if (!this._functions.has(func.module)) { + this._functions.set(func.module, new Map()); + } + const map = this._functions.get(func.module); + if (map.has(func.name)) { + throw new onnx.Error("Duplicate function identifier '" + func.module + '.' + func.name + "'."); + } + map.set(func.name, func); + } + + type(name, domain) { + domain = domain || 'ai.onnx'; + const key = domain + ':' + name; + if (!this._cache.has(key)) { + let value = this._metadata.type(name, domain, this._imports); + if (!value) { + if (this._functions.has(domain)) { + const map = this._functions.get(domain); + if (map.has(name)) { + value = map.get(name); + } + } + } + this._cache.set(key, value); + } + return this._cache.get(key); + } + + attribute(type, domain, name) { + const key = domain + ':' + type + ':' + name; + if (!this._attributes.has(key)) { + const schema = this.type(type, domain); + if (schema && schema.attributes && schema.attributes.length > 0) { + for (const attribute of schema.attributes) { + this._attributes.set(key, attribute); + } + } + if (!this._attributes.has(key)) { + this._attributes.set(key, null); + } + } + return this._attributes.get(key); + } +}; + +onnx.Metadata = class { + + static open(context) { + if (onnx.Metadata._metadata) { + return Promise.resolve(onnx.Metadata._metadata); + } + return context.request('onnx-metadata.json', 'utf-8', null).then((data) => { + onnx.Metadata._metadata = new onnx.Metadata(data); + return onnx.Metadata._metadata; + }).catch(() => { + onnx.Metadata._metadata = new onnx.Metadata(null); + return onnx.Metadata._metadata; + }); + } + + constructor(data) { + this._map = new Map(); + if (data) { + const metadata = JSON.parse(data); + for (const item of metadata) { + if (!this._map.has(item.module)) { + this._map.set(item.module, new Map()); + } + const map = this._map.get(item.module); + if (!map.has(item.name)) { + map.set(item.name, []); + } + map.get(item.name).push(item); + } + } + } + + type(name, domain, imports) { + domain = domain || 'ai.onnx'; + let current = null; + if (this._map.has(domain)) { + const map = this._map.get(domain); + if (map.has(name)) { + for (const metadata of map.get(name)) { + const matchVersion = current ? current.version : -1; + const importVersion = imports.get(metadata.module) || 0; + if (importVersion >= metadata.version && matchVersion < metadata.version) { + current = metadata; + } + } + } + } + return current; + } +}; + +onnx.Inference = class { + + constructor(nodes, outputs) { + this._outputs = new Map(); + + for (const node of nodes) { + for (const output of node.output) { + this._outputs.set(output.name, node); + } + } + + for (const output of outputs) { + this._infer(output.name); + } + } + + _infer(output) { + if (this._outputs.has(output)) { + let hasInputShapes = true; + const node = this._outputs.get(output); + for (const input of node.input) { + if (!input.type) { + this._infer(input); + if (!input.type) { + hasInputShapes = false; + break; + } + } + } + if (hasInputShapes) { + // continue + } + } + } +}; + +onnx.DataLocation = { + DEFAULT: 0, + EXTERNAL: 1 +}; + +onnx.DataType = { + UNDEFINED: 0, + FLOAT: 1, + UINT8: 2, + INT8: 3, + UINT16: 4, + INT16: 5, + INT32: 6, + INT64: 7, + STRING: 8, + BOOL: 9, + FLOAT16: 10, + DOUBLE: 11, + UINT32: 12, + UINT64: 13, + COMPLEX64: 14, + COMPLEX128: 15, + BFLOAT16: 16 +}; + +onnx.AttributeType = { + UNDEFINED: 0, + FLOAT: 1, + INT: 2, + STRING: 3, + TENSOR: 4, + GRAPH: 5, + FLOATS: 6, + INTS: 7, + STRINGS: 8, + TENSORS: 9, + GRAPHS: 10, + SPARSE_TENSOR: 11, + SPARSE_TENSORS: 12, + TYPE_PROTO: 13, + TYPE_PROTOS: 14 +}; + +onnx.Utility = class { + + static decodeText(value) { + if (typeof value === 'string') { + return value; + } + onnx.Utility._utf8Decoder = onnx.Utility._utf8Decoder || new TextDecoder('utf-8'); + return onnx.Utility._utf8Decoder.decode(value); + } + + static formatDataType(value) { + if (!onnx.Utility._dataTypes) { + onnx.Utility._dataTypes = new Map([ + [ onnx.DataType.UNDEFINED, 'UNDEFINED' ], + [ onnx.DataType.FLOAT, 'float32' ], + [ onnx.DataType.UINT8, 'uint8' ], + [ onnx.DataType.INT8, 'int8' ], + [ onnx.DataType.UINT16, 'uint16' ], + [ onnx.DataType.INT16, 'int16' ], + [ onnx.DataType.INT32, 'int32' ], + [ onnx.DataType.INT64, 'int64' ], + [ onnx.DataType.STRING, 'string' ], + [ onnx.DataType.BOOL, 'boolean' ], + [ onnx.DataType.FLOAT16, 'float16' ], + [ onnx.DataType.DOUBLE, 'float64' ], + [ onnx.DataType.UINT32, 'uint32' ], + [ onnx.DataType.UINT64, 'uint64' ], + [ onnx.DataType.COMPLEX64, 'complex64' ], + [ onnx.DataType.COMPLEX128, 'complex128' ], + [ onnx.DataType.BFLOAT16, 'bfloat16' ] + ]); + } + if (onnx.Utility._dataTypes.has(value)) { + return onnx.Utility._dataTypes.get(value); + } + return onnx.Utility._dataTypes.get(onnx.DataType.UNDEFINED); + } + + static formatType(type, imageFormat) { + if (!type) { + return null; + } + let denotation = ''; + switch (type.denotation) { + case 'TENSOR': + denotation = 'Tensor'; + break; + case 'IMAGE': + denotation = 'Image' + (imageFormat ? '(' + imageFormat.join(',') + ')' : ''); + break; + case 'AUDIO': + denotation = 'Audio'; + break; + case 'TEXT': + denotation = 'Text'; + break; + } + switch (type.value) { + case 'tensor_type': { + const tensor_type = type.tensor_type; + let shape = []; + if (tensor_type.shape && tensor_type.shape.dim) { + shape = tensor_type.shape.dim.map((dim) => dim.dim_param ? dim.dim_param : dim.dim_value); + } + return new onnx.TensorType(tensor_type.elem_type, new onnx.TensorShape(shape), denotation); + } + case 'sparse_tensor_type': { + const tensor_type = type.sparse_tensor_type; + let shape = []; + if (tensor_type.shape && tensor_type.shape.dim) { + shape = tensor_type.shape.dim.map((dim) => dim.dim_param ? dim.dim_param : dim.dim_value); + } + return new onnx.TensorType(tensor_type.elem_type, new onnx.TensorShape(shape), denotation); + } + case 'map_type': { + return new onnx.MapType(type.map_type.key_type, onnx.Utility.formatType(type.map_type.value_type, imageFormat), denotation); + } + case 'sequence_type': { + return new onnx.SequenceType(onnx.Utility.formatType(type.sequence_type.elem_type, imageFormat), denotation); + } + case 'opaque_type': { + return new onnx.OpaqueType(type.opaque_type.domain, type.opaque_type.name); + } + } + return null; + } + + static formatLocation(location) { + if (!onnx.Utility._dataLocations) { + onnx.Utility._dataLocations = new Map(Object.keys(onnx.DataLocation).map((key) => [ onnx.DataLocation[key], key.toLowerCase() ])); + } + return onnx.Utility._dataLocations.get(location); + } + + static attributeType(attribute) { + if (attribute.type) { + return attribute.type; + } + if (attribute.ints && attribute.ints.length > 0) { + return onnx.AttributeType.INTS; + } + else if (attribute.floats && attribute.floats.length > 0) { + return onnx.AttributeType.FLOATS; + } + else if (attribute.strings && attribute.strings.length > 0) { + return onnx.AttributeType.STRINGS; + } + else if (attribute.graphs && attribute.graphs.length > 0) { + return onnx.AttributeType.GRAPHS; + } + else if (attribute.s && attribute.s.length > 0) { + return onnx.AttributeType.STRING; + } + else if (Object.prototype.hasOwnProperty.call(attribute, 'f')) { + return onnx.AttributeType.FLOAT; + } + else if (Object.prototype.hasOwnProperty.call(attribute, 'i')) { + return onnx.AttributeType.INT; + } + else if (Object.prototype.hasOwnProperty.call(attribute, 't')) { + return onnx.AttributeType.TENSOR; + } + else if (Object.prototype.hasOwnProperty.call(attribute, 'g')) { + return onnx.AttributeType.GRAPH; + } + else if (Object.prototype.hasOwnProperty.call(attribute, 'sparse_tensor')) { + return onnx.AttributeType.SPARSE_TENSOR; + } + return onnx.AttributeType.UNDEFINED; + } + + static createTensors(nodes) { + const tensors = new Map(); + tensors.map = function(name) { + if (!this.has(name)) { + this.set(name, { name: name }); + } + return this.get(name); + }; + for (const node of nodes) { + node.input = node.input.map((name) => tensors.map(name)); + node.output = node.output.map((name) => tensors.map(name)); + node.param = {}; + for (const attribute of node.attribute) { + attribute.type = onnx.Utility.attributeType(attribute); + } + } + return tensors; + } + + static createNodes(context, nodes, inputs, outputs, tensors, args) { + const inputMap = new Map(); + const outputMap = new Map(); + for (const node of nodes) { + node.input.every((input) => inputMap.set(input.name, (inputMap.get(input) || 0) + 1)); + node.output.every((output) => outputMap.set(output.name, (outputMap.get(output) || 0) + 1)); + } + inputs.every((input) => inputMap.delete(input.name)); + outputs.every((output) => outputMap.delete(output.name)); + nodes = nodes.filter((node) => { + const constant = node && + node.op_type === 'Constant' && + node.attribute.length === 1 && node.attribute[0] && + node.input.length === 0 && + node.output.length === 1 && node.output[0] && inputMap.get(node.output[0].name) === 1 && outputMap.get(node.output[0].name) === 1; + const attribute = constant ? node.attribute[0] : null; + if (attribute && attribute.name === 'value' && attribute.type === onnx.AttributeType.TENSOR && attribute.t) { + const tensor = tensors.map(node.output[0].name); + tensor.initializer = new onnx.Tensor(attribute.t, 'Constant'); + return false; + } + else if (attribute && attribute.name === 'sparse_value' && attribute.type === onnx.AttributeType.SPARSE_TENSOR && attribute.sparse_tensor) { + const tensor = tensors.map(node.output[0].name); + tensor.initializer = new onnx.Tensor(attribute.sparse_tensor, 'Sparse Constant'); + return false; + } + return true; + }); + return nodes.map((node) => { + const schema = context.metadata.type(node.op_type, node.domain); + const inputs = []; + node.input = node.input || []; + for (let i = 0; i < node.input.length; ) { + const input = schema && schema.inputs && i < schema.inputs.length ? schema.inputs[i] : { name: i.toString() }; + const count = input.list ? node.input.length - i : 1; + const list = node.input.slice(i, i + count).map((input) => args.map(input.name)); + inputs.push(new onnx.Parameter(input.name, list)); + i += count; + } + const outputs = []; + node.output = node.output || []; + for (let i = 0; i < node.output.length; ) { + const output = schema && schema.outputs && i < schema.outputs.length ? schema.outputs[i] : { name: i.toString() }; + const count = output.list ? node.output.length - i : 1; + const list = node.output.slice(i, i + count).map((output) => args.map(output.name)); + outputs.push(new onnx.Parameter(output.name, list)); + i += count; + } + return new onnx.Node(context, node.op_type, node.domain, node.name, node.doc_string, node.attribute, inputs, outputs); + }); + } +}; + +onnx.Error = class extends Error { + + constructor(message) { + super(message); + this.name = 'Error loading ONNX model.'; + } +}; + +if (typeof module !== 'undefined' && typeof module.exports === 'object') { + module.exports.ModelFactory = onnx.ModelFactory; +} diff --git a/media/CircleGraph/index.html b/media/CircleGraph/index.html index 648b5c87..bf624a64 100644 --- a/media/CircleGraph/index.html +++ b/media/CircleGraph/index.html @@ -71,6 +71,8 @@ + +