{ValueError: Unknown layer: MovinetClassifier. Please ensure this object is passed to the `custom_objects` argument)

56 Views Asked by At

I am trying to create a video classification model using MoViNet Classifiers (https://www.tensorflow.org/tutorials/video/transfer_learning_with_movinet),and i have tried saving this model using model.save, tf.saved_model.save etc. but at the time of loading this file it gives error {ValueError: Unknown layer: MovinetClassifier. Please ensure this object is passed to the custom_objects argument. See https://www.tensorflow.org/guide/keras/save_and_serialize#registering_the_custom_object for details. } I have also tried the methods present in the link in error still no leads, anybody have any idea on how to save this model & load it to perform predictions using MoViNet model on video data .

Expecting any way to create MoViNet Video classifiaction model, save & load it

1

There are 1 best solutions below

0
On

Save your model using model.save('path_to_my_model').

Import the MovinetClassifier class in your script where you're loading the model. This is crucial because TensorFlow needs to recognize this custom class.

Load your model with the MovinetClassifier class specified in custom_objects. Use this code:

from tensorflow.keras.models import load_model

from your_movinet_module import MovinetClassifier

model = load_model('path_to_my_model', custom_objects={'MovinetClassifier': MovinetClassifier})

Make sure you have the same environment and dependencies as when you saved the model, especially the same TensorFlow version.