Skip to content

ONNX outputs don't match model outputs after serialization #2980

Closed
@rogancarr

Description

@rogancarr

When I save a model to ONNX, load, and apply it with ApplyOnnxModel, it adds a zero as a suffix to all columns, including the expected output. This includes input columns, so the resulting IDataView now has double the columns, plus the output. To top it off, it's not clear how to find the output because it's been renamed.

Example:
ML.NET model
Input: Features
Output: Score
Resulting Schema: Features, Score

After Onnx Serialization / Deserialization:
Input: Features
Output: Features0, Score0
Resulting Schema: Features, Features0, Score0

I am not sure if this is by design, but it feels like a bug.

Activity

added
bugSomething isn't working
usabilitySmoothing user interaction or experience
on Mar 15, 2019
jignparm

jignparm commented on Mar 18, 2019

@jignparm
Contributor

What does the model above produce as outputs (try this viewer https://github.com/lutzroeder/netron/releases/tag/v2.9.4) ? The zeros at the end of the names seems odd -- unless those are the names of the model outputs.

The OnnxTransform will generate output all output columns by default, with names, type and shape specified by the model, unless the user specifies explicitly the list of columns they are interested in.

rogancarr

rogancarr commented on Mar 18, 2019

@rogancarr
ContributorAuthor

@jignparm Check out this PR: #2984 . I think the issue is the way we save or load the model.

jignparm

jignparm commented on Mar 21, 2019

@jignparm
Contributor

@rogancarr , looks like the PR is merged.

For issues #2980, #2981 and #2982, the likely reason for the behaviour is the way the model is generated, as you mentioned above, using the function mlContext.Model.ConvertToOnnx(model, data, file);.

The OnnxTransform should honor the type, shape and names as specified by the model. In case there's a discrepancy with the OnnxTransform, that can be tracked in a separate issue.

rogancarr

rogancarr commented on Mar 21, 2019

@rogancarr
ContributorAuthor

@jignparm The PR for tests is merged, but I'm still investigating this particular behavior. I'll post here once I've updated. I do think that it's in the function you call out.

self-assigned this
on Apr 1, 2019
self-assigned this
on Apr 1, 2019
singlis

singlis commented on Apr 5, 2019

@singlis
Member

The "0" is because we are preserving the input column to imitate the behavior of what we would have in ml.net where the original columns are preserved as part of the output. In order to preserve the input, we are passing the input through an identity transform. ONNX can't have multiple inputs/outputs of the same name, so ML.NET generates the new output name by appending a 0 to the name:
image

This is by design. If we want true "end-to-end" symmetry with an imported ONNX model in that we have the same outputs as the original ML.NET model, then we would have to add CopyColumn transforms that rename the column back to the original column.

I feel like this is treading on the doing things automagically so I will add @TomFinley in case he has some thoughts, but from the stance of having an explicit API, then we don't want to do a conversion and this behavior is OK. If the user wants to rename back to the original, they can add a CopyColumn to rename.

4 remaining items

Loading
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

P3Doc bugs, questions, minor issues, etc.bugSomething isn't workingusabilitySmoothing user interaction or experience

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

    Development

    Participants

    @jignparm@singlis@rogancarr@frank-dong-ms-zz

    Issue actions

      ONNX outputs don't match model outputs after serialization · Issue #2980 · dotnet/machinelearning