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

Bug: MDense state restore crash with missing argument #191

Open
tarepan opened this issue Jun 14, 2022 · 0 comments
Open

Bug: MDense state restore crash with missing argument #191

tarepan opened this issue Jun 14, 2022 · 0 comments

Comments

@tarepan
Copy link

tarepan commented Jun 14, 2022

Summary

Broken MDense.get_config crash model loading in Python.
Estimated cause is wrong attribute name.
With hacking, it can be fixed.

Phenomena

I tried to resume training from saved checkpoint using keras.models.load_model.
When load the model state from checkpoint, MDense loading raise below error.

Traceback (most recent call last):
  File "training_tf2/train_lpcnet.py", line 112, in <module>
    model = keras.models.load_model(args.resume_model, custom_objects=custom_objs)
...
  File "/usr/local/lib/python3.7/dist-packages/keras/engine/base_layer.py", line 796, in from_config
    return cls(**config)
TypeError: __init__() missing 1 required positional argument: 'outputs'

Estimated cause

The error says that default .from_config crash with missing positional argument outputs of MDense.__init__.

As error suggested, during serialization, outputs is not exported, instead, units is exported.

def get_config(self):
config = {
'units': self.units,

This will cause above error.

How to Fix

I patch like below, and the bug disappear.

    @classmethod
    def from_config(cls, config):
        units = config.pop("units", None)
        if units is not None:
            # Hack for old broken checkpoints
            return cls(outputs=units, **config)
        else:
            return cls(**config)

I do not know backward compatibility policy of this repository, so this is just an idea.

Thanks for your great LPCNet library, I love this! I am happy if this help this repo.

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

No branches or pull requests

1 participant