timm
  • 🌍GET STARTED
    • Home
    • Quickstart
    • Installation
  • 🌍TUTORIALS
    • Using Pretrained Models as Feature Extractors
    • Training With The Official Training Script
    • Share and Load Models from the BOINC AI Hub
  • 🌍MODEL PAGES
    • Model Summaries
    • Results
    • Adversarial Inception v3
    • AdvProp (EfficientNet)
    • Big Transfer (BiT)
    • CSP-DarkNet
    • CSP-ResNet
    • CSP-ResNeXt
    • DenseNet
    • Deep Layer Aggregation
    • Dual Path NetwORK(DPN)
    • ECA-ResNet
    • EfficientNet
    • EfficientNet (Knapsack Pruned)
    • Ensemble Adversarial Inception ResNet v2
    • ESE-VoVNet
    • FBNet
    • (Gluon) Inception v3
    • (Gluon) ResNet
    • (Gluon) ResNeXt
    • (Gluon) SENet
    • (Gluon) SE-ResNeXt
    • (Gluon) Xception
    • HRNet
    • Instagram ResNeXt WSL
    • Inception ResNet v2
    • Inception v3
    • Inception v4
    • (Legacy) SE-ResNet
    • (Legacy) SE-ResNeXt
    • (Legacy) SENet
    • MixNet
    • MnasNet
    • MobileNet v2
    • MobileNet v3
    • NASNet
    • Noisy Student (EfficientNet)
    • PNASNet
    • RegNetX
    • RegNetY
    • Res2Net
    • Res2NeXt
    • ResNeSt
    • ResNet
    • ResNet-D
    • ResNeXt
    • RexNet
    • SE-ResNet
    • SelecSLS
    • SE-ResNeXt
    • SK-ResNet
    • SK-ResNeXt
    • SPNASNet
    • SSL ResNet
    • SWSL ResNet
    • SWSL ResNeXt
    • (Tensorflow) EfficientNet
    • (Tensorflow) EfficientNet CondConv
    • (Tensorflow) EfficientNet Lite
    • (Tensorflow) MobileNet v3
    • (Tensorflow) MixNet
    • (Tensorflow) MobileNet v3
    • TResNet
    • Wide ResNet
    • Xception
  • 🌍REFERENCE
    • Models
    • Data
    • Optimizers
    • Learning Rate Schedulers
Powered by GitBook
On this page
  • Sharing and Loading Models From the Hugging Face Hub
  • Authenticating
  • Sharing a Model
  • Loading a Model
  1. TUTORIALS

Share and Load Models from the BOINC AI Hub

Sharing and Loading Models From the Hugging Face Hub

The timm library has a built-in integration with the BOINC AI Hub, making it easy to share and load models from the 🌍 Hub.

In this short guide, we’ll see how to:

  1. Share a timm model on the Hub

  2. How to load that model back from the Hub

Authenticating

First, you’ll need to make sure you have the huggingface_hub package installed.

Copied

pip install huggingface_hub

Then, you’ll need to authenticate yourself. You can do this by running the following command:

Copied

huggingface-cli login

Or, if you’re using a notebook, you can use the notebook_login helper:

Copied

>>> from huggingface_hub import notebook_login
>>> notebook_login()

Sharing a Model

Copied

>>> import timm
>>> model = timm.create_model('resnet18', pretrained=True, num_classes=4)

Here is where you would normally train or fine-tune the model. We’ll skip that for the sake of this tutorial.

Let’s pretend we’ve now fine-tuned the model. The next step would be to push it to the Hub! We can do this with the timm.models.hub.push_to_hf_hub function.

Copied

>>> model_cfg = dict(labels=['a', 'b', 'c', 'd'])
>>> timm.models.hub.push_to_hf_hub(model, 'resnet18-random', model_config=model_cfg)

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

Copied

>>> model_reloaded = timm.create_model('hf_hub:nateraw/resnet18-random', pretrained=True)
PreviousTraining With The Official Training ScriptNextMODEL PAGES

Last updated 1 year ago

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’ll use , which is the model we just pushed to the Hub.

🌍
nateraw/resnet18-random