Skip to content
This repository was archived by the owner on Mar 17, 2022. It is now read-only.
This repository was archived by the owner on Mar 17, 2022. It is now read-only.

Failure example.ipynb conversion of keras model to pytorch #17

Description

@wfong443

Probably related to issue #8. Running the code in the notebook example.ipynb showed differences between the keras and pytorch model.

The issue is that the Keras Flatten function does a permutation (see https://github.com/keras-team/keras/blob/master/keras/layers/core.py#L507) of the input data when the data_format is set to 'channel_first' which unnecessary since the data is provided in channel_first format. Essentially, Flatten permutes the data into the incorrect format which leads to the observed differences.

The fix is to specify the data format to prevent the permutation:
model.add(Flatten(data_format='channels_last'))
This creates an instance of Flatten that will not permute the data. See attached file.
example.ipynb.zip

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions