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

Fix _weight_name() for layers with multiple '/' #544

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

Acrobot
Copy link

@Acrobot Acrobot commented Sep 15, 2020

The _weight_name() method fails to recognise models with weights that have multiple weights with parts, such as 'quantize_annotate_3/conv1d_26/kernel:0' and 'quantize_annotate_3/conv1d_27/kernel:0'. In such case, since the names are inserted into a dict, the kernel:0 part for conv1d_26 will clash with kernel:0 for conv1d_27 and instead of having 2 weight sets, we will have only one. By doing the partitioning on '/' and taking the part after the first '/', such situations can be avoided while still removing the layer name from TF variable name.

The _weight_name() method fails to recognise models with weights that have multiple weights with parts, such as 'quantize_annotate_3/conv1d_26/kernel:0' and 'quantize_annotate_3/conv1d_27/kernel:0'. In such case, since the names are inserted into a dict, the kernel:0 part for conv1d_26 will clash with kernel:0 for conv1d_27 and instead of having 2 weight sets, we will have only one. By doing the partitioning on '/' and taking the part after the first '/', such situations can be avoided while still removing the layer name from TF variable name.
@googlebot googlebot added the cla: yes PR contributor has signed CLA label Sep 15, 2020
@github-actions github-actions bot added the technique:qat Regarding tfmot.quantization.keras (for quantization-aware training) APIs and docs label Sep 15, 2020
Copy link

@alanchiao alanchiao left a comment

Choose a reason for hiding this comment

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

Thanks for making this fix Andrzej. Left some comments.

@nutsiepully

@@ -424,7 +424,7 @@ def _weight_name(name):
Returns:
Extracted weight name.
"""
return name.split('/')[-1]

Choose a reason for hiding this comment

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

Could you add a unit test for this change so we don't make the same mistake going forward?

@Acrobot
Copy link
Author

Acrobot commented Sep 27, 2020

Changed the comment, however I am not sure how to build the repo in a way that the unit tests execute and I'm not familiar with tf.test, so @alanchiao, would you mind adding the unit test for this change?

Copy link
Contributor

@nutsiepully nutsiepully left a comment

Choose a reason for hiding this comment

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

Thanks.

@Acrobot
Copy link
Author

Acrobot commented Apr 20, 2021

Small ping :)

@alanchiao alanchiao requested a review from Xhark April 20, 2021 22:42
@alanchiao
Copy link

Removing myself and adding @Xhark for visibility giving that I've moved on.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla: yes PR contributor has signed CLA technique:qat Regarding tfmot.quantization.keras (for quantization-aware training) APIs and docs
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants