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

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

Open
wfong443 opened this issue Jul 5, 2019 · 0 comments
Open

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

wfong443 opened this issue Jul 5, 2019 · 0 comments

Comments

@wfong443
Copy link

wfong443 commented Jul 5, 2019

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

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant