def Classifier(input_shape):
model = TFMPNetModel.from_pretrained('microsoft/mpnet-base')
layer = model.layers[0]
inputs = keras.Input(shape=input_shape, dtype='int32')
input_masks = keras.Input(shape=input_shape, dtype='int32')
embeddings = layer([inputs, input_masks])[0][:,0,:]
X = keras.layers.Dense(32,activation='elu',kernel_regularizer=keras.regularizers.l2(0.0001))(embeddings)
X = keras.layers.BatchNormalization(momentum=0.99, epsilon=0.001, center=True, scale=True)(X)
X = keras.layers.Dense(3,activation='tanh',kernel_regularizer=keras.regularizers.l2(0.0001))(X)
X = keras.layers.Activation('softmax')(X)
# Create Model instance which converts sentence_indices into X.
model = keras.Model(inputs=[inputs,input_masks], outputs=[X])
return model
When i save and try to load the model i get is this error
model = tf.keras.models.load_model('/content/drive/MyDrive/mylatestModel')
ValueError Traceback (most recent call last) in <cell line: 4>() 2 3 ----> 4 model = tf.keras.models.load_model('/content/drive/MyDrive/mylatestModel')
2 frames
/usr/local/lib/python3.10/dist-packages/keras/src/saving/legacy/serialization.py in class_and_config_for_serialized_keras_object(config, module_objects, custom_objects, printable_module_name)
363 )
364 if cls is None:
--> 365 raise ValueError(
366 f"Unknown {printable_module_name}: '{class_name}'. "
367 "Please ensure you are using a keras.utils.custom_object_scope "
ValueError: Unknown layer: 'Custom>TFMPNetMainLayer'. Please ensure you are using a keras.utils.custom_object_scope and that this object is included in the scope. See https://www.tensorflow.org/guide/keras/save_and_serialize#registering_the_custom_object for details.
I tired by providing a custom object scope during model loading but it did not work though.
with custom_object_scope ({'Custom>TFMPNetMainLayer':TFMPNetMainLayer}): model = tf.keras.models.load_model('model_path')