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

TypeError: __init__() missing 2 required positional arguments: 'mode' and 'k_centers' #58

Open
preniqivjosa opened this issue May 28, 2020 · 1 comment

Comments

@preniqivjosa
Copy link

preniqivjosa commented May 28, 2020

I have trained a model for speaker recognition using VGG in my own data. But I am having a problem with loading the model. I am using this code to load the model:

keras_model = tf.keras.models.load_model(‘model_weights.h5’, custom_objects={'VladPooling': VladPooling})
sess = tf.keras.backend.get_session()

converter = tf.lite.TFLiteConverter.from_session(sess, keras_model.inputs,
keras_model.outputs)
converter.convert()

Using this reference:
tensorflow/tensorflow#26496

However, I am getting this error
TypeError: init() missing 2 required positional arguments: 'mode' and 'k_centers'

I tried different possible options to fix this, but none of them worked for me.
Do you have any suggestion?

@moniGra
Copy link

moniGra commented Jul 24, 2020

You need to update model.py in class VladPooling(keras.engine.Layer): as follows:

# override method from base class to allow loading model from a file
def get_config(self):

   config = super(VladPooling,self).get_config()
    config['mode'] = self.mode
    config['k_centers'] = self.k_centers
    config['g_centers'] = self.g_centers
    return config

But the bad news is that even with successful conversion, the tf lite model of this network is not working:(. I've tried many different ways of generating the lite model, but still got nothing:( (the conversion runs without errors, the lite model is created, but on interpreter.invoke() on this model there is a crash). The issue is reported to tensorflow as a bug here:
https://github.com/tensorflow/tensorflow/issues/35987#issuecomment-643084885

If you know any ways of how to successfully run lite version - please share:)

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

2 participants