Skip to content

Converting an h5 model to ONNX using convert_keras introduces transpose node, but model produces wrong results. #719

@luludak

Description

@luludak

I converted MobileNetV2 and InceptionV3, represented in h5 format to ONNX using convert_keras (). The model had been previously converted from PyTorch with input dimension (1, 3, 224, 224) (NCHW).
As a result, I noticed that the convert_keras(...) changed the dimension to (1, 224, 224, 3) (attempting to change it to NHWC) and a Transpose([0, 3, 1, 2]) node is introduced. However, this node does not work properly, as I receive wrong results.

I wrote a script that restored model inputs to the initial model and changes Transpose to do [0, 1, 2, 3] and the model worked in the same way as the original. I believe this has something to do with the converter mishandling the common dimensions of tensors internally.

Image

In InceptionV3 the effect is even worse, because Gather and Unsqueeze nodes in the start of the model have also different axes order, which have also to be rectified. Once again, when resetting them to the original model dimensions, there was no problem in the model.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions