Skip to content
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

Python converter bugfix #4037

Merged
merged 3 commits into from
Oct 9, 2020
Merged

Python converter bugfix #4037

merged 3 commits into from
Oct 9, 2020

Conversation

patlevin
Copy link
Contributor

@patlevin patlevin commented Oct 8, 2020

Motivation

The Python converter code supports writing boolean weights, but not reading them. This causes problems when reading TFJS models from Python.

Furthermore, the Python converter fails to read scalar string weights. Numeric scalar weights are read just fine, but string scalars cause an error.

Implementation

np.bool has been added to the list of supported input dtypes.

The deserialization code for string arrays has been fixed so the size calculation always returns a valid int.

Details

Scalars are stored in the weight manifest with an empty shape ([]), which is technically correct to reflect the nature of a scalar.
The string deserialization uses np.prod() to calculate the total number of items. Unfortunately, np.prod() returns 1.0 when given an empty iterable (see numpy docs under Notes).

This value cannot be used with range() later, which leads to an error in situations where a weight manifest contains string scalars (e.g. model SSD OpenImages v4).


This change is Reviewable

@google-cla google-cla bot added the cla: yes label Oct 8, 2020
Copy link
Collaborator

@pyu10055 pyu10055 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the great contribution!

Reviewable status: :shipit: complete! 1 of 1 approvals obtained

@pyu10055 pyu10055 merged commit 77c4ef1 into tensorflow:master Oct 9, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants