Skip to content

Onnx Export change to allow for multiple rows #4783

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 6, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions src/Microsoft.ML.OnnxConverter/OnnxUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -375,8 +375,13 @@ public static ModelArgs GetModelArgs(DataViewType type, string colName,
dimsLocal.Add(vec.Dimensions[i]);
}
}
//batch size.
dimsLocal?.Insert(0, 1);
// Set batch size to -1. The ONNX docs, https://github.com/onnx/onnx/blob/master/docs/IR.md#static-tensor-shapes, state that if
// dim_param is used instead of dim_value, that the size of the dimension "is not statically constrained to a particular number"
// "This is useful for declaring the interfaces that care about the number of dimensions, but not the exact size of each dimension"
// This file, https://github.com/onnx/onnx/blob/master/onnx/tools/update_model_dims.py, explains that if the dim value is negative
// than it treats that as a dim_param instead of a dim_value. This allows ML.NET to run 1 row at a time in a streaming fassion,
// but allows the ONNX model the flexiblity to be run in batch mode if that is desired.
dimsLocal?.Insert(0, -1);

return new ModelArgs(name, dataType, dimsLocal, dimsParamLocal);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -503,7 +503,7 @@
"shape": {
"dim": [
{
"dimValue": "1"
"dimValue": "-1"
},
{
"dimValue": "1"
Expand All @@ -521,7 +521,7 @@
"shape": {
"dim": [
{
"dimValue": "1"
"dimValue": "-1"
},
{
"dimValue": "1"
Expand All @@ -541,7 +541,7 @@
"shape": {
"dim": [
{
"dimValue": "1"
"dimValue": "-1"
},
{
"dimValue": "1"
Expand All @@ -559,7 +559,7 @@
"shape": {
"dim": [
{
"dimValue": "1"
"dimValue": "-1"
},
{
"dimValue": "1"
Expand All @@ -577,7 +577,7 @@
"shape": {
"dim": [
{
"dimValue": "1"
"dimValue": "-1"
},
{
"dimValue": "1"
Expand All @@ -597,7 +597,7 @@
"shape": {
"dim": [
{
"dimValue": "1"
"dimValue": "-1"
},
{
"dimValue": "1"
Expand All @@ -615,7 +615,7 @@
"shape": {
"dim": [
{
"dimValue": "1"
"dimValue": "-1"
},
{
"dimValue": "10"
Expand All @@ -633,7 +633,7 @@
"shape": {
"dim": [
{
"dimValue": "1"
"dimValue": "-1"
},
{
"dimValue": "10"
Expand All @@ -651,7 +651,7 @@
"shape": {
"dim": [
{
"dimValue": "1"
"dimValue": "-1"
},
{
"dimValue": "11"
Expand All @@ -669,7 +669,7 @@
"shape": {
"dim": [
{
"dimValue": "1"
"dimValue": "-1"
},
{
"dimValue": "11"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,7 @@
"shape": {
"dim": [
{
"dimValue": "1"
"dimValue": "-1"
},
{
"dimValue": "11"
Expand All @@ -414,7 +414,7 @@
"shape": {
"dim": [
{
"dimValue": "1"
"dimValue": "-1"
},
{
"dimValue": "1"
Expand All @@ -434,7 +434,7 @@
"shape": {
"dim": [
{
"dimValue": "1"
"dimValue": "-1"
},
{
"dimValue": "11"
Expand All @@ -452,7 +452,7 @@
"shape": {
"dim": [
{
"dimValue": "1"
"dimValue": "-1"
},
{
"dimValue": "1"
Expand All @@ -470,7 +470,7 @@
"shape": {
"dim": [
{
"dimValue": "1"
"dimValue": "-1"
},
{
"dimValue": "1"
Expand All @@ -490,7 +490,7 @@
"shape": {
"dim": [
{
"dimValue": "1"
"dimValue": "-1"
},
{
"dimValue": "11"
Expand All @@ -508,7 +508,7 @@
"shape": {
"dim": [
{
"dimValue": "1"
"dimValue": "-1"
},
{
"dimValue": "1"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@
"shape": {
"dim": [
{
"dimValue": "1"
"dimValue": "-1"
},
{
"dimValue": "11"
Expand All @@ -158,7 +158,7 @@
"shape": {
"dim": [
{
"dimValue": "1"
"dimValue": "-1"
},
{
"dimValue": "1"
Expand All @@ -178,7 +178,7 @@
"shape": {
"dim": [
{
"dimValue": "1"
"dimValue": "-1"
},
{
"dimValue": "11"
Expand All @@ -196,7 +196,7 @@
"shape": {
"dim": [
{
"dimValue": "1"
"dimValue": "-1"
},
{
"dimValue": "1"
Expand All @@ -214,7 +214,7 @@
"shape": {
"dim": [
{
"dimValue": "1"
"dimValue": "-1"
},
{
"dimValue": "1"
Expand All @@ -234,7 +234,7 @@
"shape": {
"dim": [
{
"dimValue": "1"
"dimValue": "-1"
},
{
"dimValue": "11"
Expand All @@ -252,7 +252,7 @@
"shape": {
"dim": [
{
"dimValue": "1"
"dimValue": "-1"
},
{
"dimValue": "1"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -829,7 +829,7 @@
"shape": {
"dim": [
{
"dimValue": "1"
"dimValue": "-1"
},
{
"dimValue": "8"
Expand All @@ -847,7 +847,7 @@
"shape": {
"dim": [
{
"dimValue": "1"
"dimValue": "-1"
},
{
"dimValue": "1"
Expand All @@ -867,7 +867,7 @@
"shape": {
"dim": [
{
"dimValue": "1"
"dimValue": "-1"
},
{
"dimValue": "1"
Expand All @@ -885,7 +885,7 @@
"shape": {
"dim": [
{
"dimValue": "1"
"dimValue": "-1"
},
{
"dimValue": "1"
Expand All @@ -903,7 +903,7 @@
"shape": {
"dim": [
{
"dimValue": "1"
"dimValue": "-1"
},
{
"dimValue": "1"
Expand All @@ -923,7 +923,7 @@
"shape": {
"dim": [
{
"dimValue": "1"
"dimValue": "-1"
},
{
"dimValue": "1"
Expand All @@ -941,7 +941,7 @@
"shape": {
"dim": [
{
"dimValue": "1"
"dimValue": "-1"
},
{
"dimValue": "9"
Expand All @@ -959,7 +959,7 @@
"shape": {
"dim": [
{
"dimValue": "1"
"dimValue": "-1"
},
{
"dimValue": "17"
Expand Down
Loading