Coul not interpret seralized object

hELLO EVERYONE i have this ValueError: could not interpret serialized object when a try to load a model with custom objects. This error comes from this class:

@tf.keras.saving.register_keras_serializable(package=“MyLayers”)
class SimilarityMatrix(tf.keras.layers.Layer):

def __init__(self,dims, **kwargs):
    self.dims_length , self.dims_width = dims[1] , dims[0]
    super(SimilarityMatrix, self).__init__(**kwargs)

def build(self, input_shape):
    
    # Create a trainable weight variable for this layer.
    self._m = self.add_weight(name='M', 
                                shape=(self.dims_length,self.dims_width),
                                initializer='uniform',
                                trainable=True)
    super(SimilarityMatrix, self).build(input_shape)  # Be sure to call this at the end

def call(self, y): 
    xf, xs = y
    sim1=tf.matmul(xf, self._m)
    transposed = tf.reshape(K.transpose(xs),(-1, 100, 1))
    sim2=tf.matmul(sim1, transposed)
    return sim2

def compute_output_shape(self, input_shape):
    return (1)

def get_config(self):

    base_config = super().get_config()
    config={
        'dims_length': self.dims_length, 
        'dims_width': self.dims_width
    }
    #print(config)
    return {**base_config , **config}

@classmethod
def from_config(cls, config):
    #simm_config = config.pop("dims_length", "dims_width")
    #simm_config= config.pop("dims_width")
    #simm_config = config
    
    #dims = tf.keras.saving.deserialize_keras_object(simm_config)
    
    dims_length = config.pop("dims_length")
    dims_width = config.pop("dims_width")
    return cls(dims=(dims_length, dims_width), **config)
    #return cls(dims,**config)

And the error is raised after running :

model = tf.keras.models.load_model(saveloc ,custom_objects={“SimilarityMatrix”: SimilarityMatrix} )

Prepare your input data for prediction

input_data = df_test.explain.iloc[2] # Make sure it’s in the right format

Perform predictions

predictions = model.predict(input_data)

Hi @Sebastian_Fuentes

Welcome to the TensorFlow Forum!

Please share the error log which you are getting while executing the above code along with few other details like which Tensorflow/Keras version you are using and how you are saving the model. Please share the standalone code (if it is shareable) to replicate the error and understand the underlying issue.

You can refer to this Tensorflow Save, serialize, and export models doc to understand how you can save the model with defined custom objects in .keras and other format and the techniques on how to load back the model for use. Thank you.

Dealing with the challenge of interpreting a serialized object can be quite tricky in programming. I’ve been there! If you’re navigating the complexities of coding while working on your bachelor thesis, consider seeking support from a reliable bachelor thesis writing service Modified by the moderator . It’s all about finding that balance between practical problem-solving and academic pursuits. Any fellow coders here with tips to share.