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

Video transformers - added fixes to enable model load after saving and added HF model & space #1015

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

shivalikasingh95
Copy link
Contributor

Hi, I have updated the video transformers example with links to model & space on Hugging Face hub.

While trying to save and re-load the model, I faced few errors. Have added the fixes for those as well.

@@ -279,6 +293,17 @@ def call(self, inputs, mask=None):
proj_output = self.dense_proj(proj_input)
return self.layernorm_2(proj_input + proj_output)

def get_config(self):
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added to fix loading of model after saving.


"""
Now, we can create a subclassed layer for the Transformer.
"""


@tf.keras.utils.register_keras_serializable(package="Custom", name="TransformerEncoder")
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added this to avoid passing custom_objects dict to tf.keras.models.load_model()

@shivalikasingh95 shivalikasingh95 marked this pull request as ready for review August 4, 2022 22:55
@shivalikasingh95
Copy link
Contributor Author

Hi @fchollet, would be great if you could take a quick look at this PR whenever you find the time. It has minimal suggested changes.

@fchollet
Copy link
Contributor

fchollet commented Oct 2, 2022

Hi, I have updated the video transformers example with links to model & space on Hugging Face hub.

Thanks!

Please remove serialization support, it is not needed for this example and it adds complexity to the code example. If you want to reload a saved model, please use model.save_weights()/load_weights(). You do not need to store the model's architecture in serialized format since you have access to the model's code.

@shivalikasingh95
Copy link
Contributor Author

Hi, I have updated the video transformers example with links to model & space on Hugging Face hub.

Thanks!

Please remove serialization support, it is not needed for this example and it adds complexity to the code example. If you want to reload a saved model, please use model.save_weights()/load_weights(). You do not need to store the model's architecture in serialized format since you have access to the model's code.

Hi @fchollet , makes sense. I had initially added that because I was trying to load the model for inference in a separate script where I didn't have access to the model's code.
But within the context of this example, it makes sense to keep the code simple as we already have access to the model's code.

Have removed the serialization support now. Let me know if you'd like me to fix anything else.

@pcoet
Copy link
Collaborator

pcoet commented Aug 16, 2023

@fchollet Can you have a look at this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants