Putting Keras on 🤗 Hub for Collaborative Training and Reproducibility

Merve Noyan
3 min readApr 22, 2022


Reproducibility, experiment tracking and collaborative training are couple of problems in open-source machine learning. At Hugging Face, we are challenging these issues to enable collaborative training, versioning models and hosting open-source machine learning demos on Hugging Face Hub. Thanks to recent Keras integration, you can easily:

  • Push and save a model to Hugging Face Hub and let others pull easily,
  • Version your models,
  • Reproduce your experiments with automatically generated model card and hosted TensorBoard instance,
  • Load model with only one line of code,
  • Easily load your models for demonstration on Spaces.

Pushing Your Model to the Hugging Face Hub

After your training is done, you can call push_to_hub_keras() to push your model to Hugging Face Hub.

which will generate a model card that includes your model’s hyperparameters, metrics of your model in a JSON, plot of your model and couple of sections related to the usage purpose of your model, biases the training data might have and limitations about putting your model to production. The tags are written to model card and are used for others to find your models easily. The repository will host your tensorboard traces like below.

Your tensorboard traces will look like this 🙌🏻
Your model history, hyperparameters and plot are included in the card 🃏

You can see the example hosted model with model card and tensorboard traces here.

Your model is saved with tf.keras.models.save_model(). You can pass the rest of the arguments in **model_save_kwargs. This saves your model as SavedModel with weights and graph, which is a format that you can later convert to other model formats in TensorFlow Extended to later use your model in browsers, edge devices, REST/gRPC APIs.

Loading Your Model and Building A Demo

After your model is pushed, you can simply load your model with from_pretrained_keras(). You can also load a Keras model that you’ve liked on the Hub like below.

To demonstrate your model’s capabilities, you can simply load your model with from_pretrained_keras(), write an inference function in an app.py file, then create a Spaces repository and drag and drop your app.py file and your application will be ready.

You can simply drag and drop your app.py file and your Space will be built! ✨

We’ve organized a sprint to train the Keras examples, host them on Hugging Face Hub and build interactive demos for reproducibility. If you liked a Keras example, simply look at the bottom of the example and you can find redirections to model and Space repositories.

Find the awesome tutorial here: https://keras.io/examples/vision/probing_vits/

The Keras examples are all hosted in this page, see the model repositories and Spaces applications.

Where was this model during Game of Thrones! 🥲

We’ve written two guides to build Streamlit and Gradio demos easily host them on the Hugging Face Hub.

Thanks a lot for reading. 🤗. I’d love to hear your experience and feature requests for Keras at merve@hf.co. We’re planning a second round of the Keras sprint (and more community events!), if you’d like to be informed, feel free to join to our Discord channel 👾.



Merve Noyan

machine learning engineer & data scientist