WeidiXie / VGG-Speaker-Recognition

Utterance-level Aggregation For Speaker Recognition In The Wild
362 stars 98 forks source link

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

Open preniqivjosa opened 4 years ago

preniqivjosa commented 4 years ago

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: https://github.com/tensorflow/tensorflow/issues/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 commented 4 years ago

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:)