-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Fixed OnnxTransformer output column mapping. #5192
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
Changes from all commits
5da0b7b
1815de6
4cbd19f
d363cc7
50c979f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -332,6 +332,60 @@ public void OnnxModelMultiInput() | |
} | ||
} | ||
|
||
[OnnxFact] | ||
public void OnnxModelOutputDifferentOrder() | ||
{ | ||
Comment on lines
+335
to
+337
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe you can refactor both tests into one, as they're very similar. And include an There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'll combine them. I dont think the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I misunderstood what you were saying first. I get it now. The issue with that is that with the subset I dont compare all the columns and with the full column set I do. I just combined the tests and moved the subset pipeline and checking below the full one. |
||
var modelFile = Path.Combine(Directory.GetCurrentDirectory(), "twoinput", "twoinput.onnx"); | ||
|
||
var dataView = ML.Data.LoadFromEnumerable( | ||
new TestDataMulti[] { | ||
new TestDataMulti() | ||
{ | ||
ina = new float[] {1,2,3,4,5}, | ||
inb = new float[] {1,2,3,4,5} | ||
} | ||
}); | ||
// The model returns the output columns in the order outa, outb. We are doing the opposite here, making sure the name mapping is correct. | ||
var onnx = ML.Transforms.ApplyOnnxModel(new[] { "outb", "outa" }, new[] { "ina", "inb" }, modelFile).Fit(dataView).Transform(dataView); | ||
|
||
var outaCol = onnx.Schema["outa"]; | ||
var outbCol = onnx.Schema["outb"]; | ||
using (var curs = onnx.GetRowCursor(outaCol, onnx.Schema["outb"])) | ||
{ | ||
var getScoresa = curs.GetGetter<VBuffer<float>>(outaCol); | ||
var getScoresb = curs.GetGetter<VBuffer<float>>(outbCol); | ||
michaelgsharp marked this conversation as resolved.
Show resolved
Hide resolved
|
||
var buffera = default(VBuffer<float>); | ||
var bufferb = default(VBuffer<float>); | ||
|
||
while (curs.MoveNext()) | ||
{ | ||
getScoresa(ref buffera); | ||
getScoresb(ref bufferb); | ||
Assert.Equal(5, buffera.Length); | ||
Assert.Equal(5, bufferb.Length); | ||
Assert.Equal(0, buffera.GetValues().ToArray().Sum()); | ||
Assert.Equal(30, bufferb.GetValues().ToArray().Sum()); | ||
} | ||
} | ||
|
||
// The model returns the output columns in the order outa, outb. We are doing only a subset, outb, to make sure the mapping works. | ||
onnx = ML.Transforms.ApplyOnnxModel(new[] { "outb" }, new[] { "ina", "inb" }, modelFile).Fit(dataView).Transform(dataView); | ||
|
||
outbCol = onnx.Schema["outb"]; | ||
using (var curs = onnx.GetRowCursor(outbCol)) | ||
{ | ||
var getScoresb = curs.GetGetter<VBuffer<float>>(outbCol); | ||
var bufferb = default(VBuffer<float>); | ||
|
||
while (curs.MoveNext()) | ||
{ | ||
getScoresb(ref bufferb); | ||
Assert.Equal(5, bufferb.Length); | ||
Assert.Equal(30, bufferb.GetValues().ToArray().Sum()); | ||
} | ||
} | ||
} | ||
|
||
[OnnxFact] | ||
public void TestUnknownDimensions() | ||
{ | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: This is mapping the dataview column index to onnx output index.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.