|
# Sharing and Loading Models From the Hugging Face Hub |
|
|
|
The `timm` library has a built-in integration with the Hugging Face Hub, making it easy to share and load models from the 🤗 Hub. |
|
|
|
In this short guide, we |
|
1. Share a `timm` model on the Hub |
|
2. How to load that model back from the Hub |
|
|
|
## Authenticating |
|
|
|
First, you |
|
|
|
```bash |
|
pip install huggingface_hub |
|
``` |
|
|
|
Then, you |
|
|
|
```bash |
|
huggingface-cli login |
|
``` |
|
|
|
Or, if you |
|
|
|
```py |
|
>>> from huggingface_hub import notebook_login |
|
>>> notebook_login() |
|
``` |
|
|
|
## Sharing a Model |
|
|
|
```py |
|
>>> import timm |
|
>>> model = timm.create_model( |
|
``` |
|
|
|
Here is where you would normally train or fine-tune the model. We |
|
|
|
Let |
|
|
|
```py |
|
>>> model_cfg = dict(label_names=[ |
|
>>> timm.models.push_to_hf_hub(model, |
|
``` |
|
|
|
Running the above would push the model to `<your-username>/resnet18-random` on the Hub. You can now share this model with your friends, or use it in your own code! |
|
|
|
## Loading a Model |
|
|
|
Loading a model from the Hub is as simple as calling `timm.create_model` with the `pretrained` argument set to the name of the model you want to load. In this case, we |
|
|
|
```py |
|
>>> model_reloaded = timm.create_model( |
|
``` |
|
|