Skip to content

Commit 051ff17

Browse files
authored
Fixed output schema of OnnxTransformer (#4849)
* Fixed output schema of OnnxTransformer * Fixed column names of other failing tests * Fixed bad change in TextNormalizingOnnxConversionTest * Removed obsolete comments and fixed pipeline based on CR comments
1 parent 9f27612 commit 051ff17

23 files changed

+273
-305
lines changed

src/Microsoft.ML.OnnxConverter/SaveOnnxCommand.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ internal static ModelProto ConvertTransformListToOnnxModel(OnnxContextImpl ctx,
201201
ch.Check(variableName != null, "The targeted pipeline can not be fully converted into a well-defined ONNX model. " +
202202
"Please check if all steps in that pipeline are convertible to ONNX " +
203203
"and all necessary variables are not dropped (via command line arguments).");
204-
var trueVariableName = ctx.AddIntermediateVariable(null, idataviewColumnName + ".onnx", true);
204+
var trueVariableName = ctx.AddIntermediateVariable(null, idataviewColumnName + ".output", true);
205205
ctx.CreateNode("Identity", variableName, trueVariableName, ctx.GetNodeName("Identity"), "");
206206
ctx.AddOutputVariable(outputData.Schema[i].Type, trueVariableName);
207207
}

src/Microsoft.ML.OnnxTransformer/OnnxTransform.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -410,9 +410,14 @@ public Mapper(OnnxTransformer parent, DataViewSchema inputSchema) :
410410

411411
protected override DataViewSchema.DetachedColumn[] GetOutputColumnsCore()
412412
{
413+
var stdSuffix = ".output";
413414
var info = new DataViewSchema.DetachedColumn[_parent.Outputs.Length];
414415
for (int i = 0; i < _parent.Outputs.Length; i++)
415-
info[i] = new DataViewSchema.DetachedColumn(_parent.Outputs[i], _parent.OutputTypes[i], null);
416+
{
417+
var onnxOutputName = _parent.Outputs[i];
418+
var columnName = onnxOutputName.EndsWith(stdSuffix) ? onnxOutputName.Replace(stdSuffix, "") : onnxOutputName;
419+
info[i] = new DataViewSchema.DetachedColumn(columnName, _parent.OutputTypes[i], null);
420+
}
416421
return info;
417422
}
418423

test/BaselineOutput/Common/Onnx/BinaryClassification/BreastCancer/ExcludeVariablesInOnnxConversion.txt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -450,7 +450,7 @@
450450
"PredictedLabel"
451451
],
452452
"output": [
453-
"PredictedLabel.onnx"
453+
"PredictedLabel.output"
454454
],
455455
"name": "Identity",
456456
"opType": "Identity"
@@ -460,7 +460,7 @@
460460
"Score"
461461
],
462462
"output": [
463-
"Score.onnx"
463+
"Score.output"
464464
],
465465
"name": "Identity0",
466466
"opType": "Identity"
@@ -470,7 +470,7 @@
470470
"Probability"
471471
],
472472
"output": [
473-
"Probability.onnx"
473+
"Probability.output"
474474
],
475475
"name": "Identity1",
476476
"opType": "Identity"
@@ -533,7 +533,7 @@
533533
],
534534
"output": [
535535
{
536-
"name": "PredictedLabel.onnx",
536+
"name": "PredictedLabel.output",
537537
"type": {
538538
"tensorType": {
539539
"elemType": 9,
@@ -551,7 +551,7 @@
551551
}
552552
},
553553
{
554-
"name": "Score.onnx",
554+
"name": "Score.output",
555555
"type": {
556556
"tensorType": {
557557
"elemType": 1,
@@ -569,7 +569,7 @@
569569
}
570570
},
571571
{
572-
"name": "Probability.onnx",
572+
"name": "Probability.output",
573573
"type": {
574574
"tensorType": {
575575
"elemType": 1,

test/BaselineOutput/Common/Onnx/BinaryClassification/BreastCancer/LightGbmBinaryClassificationOnnxConversionTest.txt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,7 @@
360360
"FeatureVector0"
361361
],
362362
"output": [
363-
"FeatureVector.onnx"
363+
"FeatureVector.output"
364364
],
365365
"name": "Identity",
366366
"opType": "Identity"
@@ -370,7 +370,7 @@
370370
"Target"
371371
],
372372
"output": [
373-
"Target.onnx"
373+
"Target.output"
374374
],
375375
"name": "Identity0",
376376
"opType": "Identity"
@@ -380,7 +380,7 @@
380380
"Score"
381381
],
382382
"output": [
383-
"Score.onnx"
383+
"Score.output"
384384
],
385385
"name": "Identity1",
386386
"opType": "Identity"
@@ -427,7 +427,7 @@
427427
],
428428
"output": [
429429
{
430-
"name": "FeatureVector.onnx",
430+
"name": "FeatureVector.output",
431431
"type": {
432432
"tensorType": {
433433
"elemType": 1,
@@ -445,7 +445,7 @@
445445
}
446446
},
447447
{
448-
"name": "Target.onnx",
448+
"name": "Target.output",
449449
"type": {
450450
"tensorType": {
451451
"elemType": 1,
@@ -463,7 +463,7 @@
463463
}
464464
},
465465
{
466-
"name": "Score.onnx",
466+
"name": "Score.output",
467467
"type": {
468468
"tensorType": {
469469
"elemType": 1,

test/BaselineOutput/Common/Onnx/BinaryClassification/BreastCancer/LogisticRegressionSaveModelToOnnxTest.txt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@
104104
"FeatureVector0"
105105
],
106106
"output": [
107-
"FeatureVector.onnx"
107+
"FeatureVector.output"
108108
],
109109
"name": "Identity",
110110
"opType": "Identity"
@@ -114,7 +114,7 @@
114114
"Target"
115115
],
116116
"output": [
117-
"Target.onnx"
117+
"Target.output"
118118
],
119119
"name": "Identity0",
120120
"opType": "Identity"
@@ -124,7 +124,7 @@
124124
"Score"
125125
],
126126
"output": [
127-
"Score.onnx"
127+
"Score.output"
128128
],
129129
"name": "Identity1",
130130
"opType": "Identity"
@@ -171,7 +171,7 @@
171171
],
172172
"output": [
173173
{
174-
"name": "FeatureVector.onnx",
174+
"name": "FeatureVector.output",
175175
"type": {
176176
"tensorType": {
177177
"elemType": 1,
@@ -189,7 +189,7 @@
189189
}
190190
},
191191
{
192-
"name": "Target.onnx",
192+
"name": "Target.output",
193193
"type": {
194194
"tensorType": {
195195
"elemType": 1,
@@ -207,7 +207,7 @@
207207
}
208208
},
209209
{
210-
"name": "Score.onnx",
210+
"name": "Score.output",
211211
"type": {
212212
"tensorType": {
213213
"elemType": 1,

test/BaselineOutput/Common/Onnx/BinaryClassification/BreastCancer/ModelWithLessIO.txt

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -677,27 +677,27 @@
677677
"floats": [
678678
-0.9850374,
679679
-1,
680-
-0.428571433,
680+
-0.42857143,
681681
0.05882353,
682682
0.9655172,
683-
0.478260875,
684-
7.006492E-45,
683+
0.47826087,
684+
7E-45,
685685
0.9354839,
686686
-0.837172,
687-
-0.896625638,
687+
-0.89662564,
688688
-0.3455931,
689-
0.223126009,
689+
0.22312601,
690690
0.8040303,
691691
0.60825175,
692692
-0.06932944,
693-
-0.402043074,
693+
-0.40204307,
694694
-0.7417274,
695-
-0.408434927,
695+
-0.40843493,
696696
0.7105746,
697697
0.1875386,
698698
0.7631735,
699-
0.706173241,
700-
0.625906467,
699+
0.70617324,
700+
0.62590647,
701701
-0.35968104
702702
],
703703
"type": "FLOATS"
@@ -776,7 +776,7 @@
776776
"PredictedLabel"
777777
],
778778
"output": [
779-
"PredictedLabel.onnx"
779+
"PredictedLabel.output"
780780
],
781781
"name": "Identity",
782782
"opType": "Identity"
@@ -786,7 +786,7 @@
786786
"Score"
787787
],
788788
"output": [
789-
"Score.onnx"
789+
"Score.output"
790790
],
791791
"name": "Identity0",
792792
"opType": "Identity"
@@ -796,7 +796,7 @@
796796
"Probability"
797797
],
798798
"output": [
799-
"Probability.onnx"
799+
"Probability.output"
800800
],
801801
"name": "Identity1",
802802
"opType": "Identity"
@@ -859,7 +859,7 @@
859859
],
860860
"output": [
861861
{
862-
"name": "PredictedLabel.onnx",
862+
"name": "PredictedLabel.output",
863863
"type": {
864864
"tensorType": {
865865
"elemType": 9,
@@ -877,7 +877,7 @@
877877
}
878878
},
879879
{
880-
"name": "Score.onnx",
880+
"name": "Score.output",
881881
"type": {
882882
"tensorType": {
883883
"elemType": 1,
@@ -895,7 +895,7 @@
895895
}
896896
},
897897
{
898-
"name": "Probability.onnx",
898+
"name": "Probability.output",
899899
"type": {
900900
"tensorType": {
901901
"elemType": 1,

0 commit comments

Comments
 (0)