Skip to content

Instantly share code, notes, and snippets.

@nateraw
Last active December 3, 2021 07:28
Show Gist options
  • Save nateraw/7416f898ea3981015b7992c57acc3759 to your computer and use it in GitHub Desktop.
Save nateraw/7416f898ea3981015b7992c57acc3759 to your computer and use it in GitHub Desktop.
timm-push-and-save-example.ipynb
Display the source blob
Display the rendered blob
Raw
{
"nbformat": 4,
"nbformat_minor": 0,
"metadata": {
"colab": {
"name": "timm-push-and-save-example.ipynb",
"provenance": [],
"collapsed_sections": [],
"authorship_tag": "ABX9TyOcqMJCJqhcV3cXob4oUnx1",
"include_colab_link": true
},
"kernelspec": {
"name": "python3",
"display_name": "Python 3"
},
"language_info": {
"name": "python"
}
},
"cells": [
{
"cell_type": "markdown",
"metadata": {
"id": "view-in-github",
"colab_type": "text"
},
"source": [
"<a href=\"https://colab.research.google.com/gist/nateraw/7416f898ea3981015b7992c57acc3759/timm-push-and-save-example.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>"
]
},
{
"cell_type": "code",
"metadata": {
"id": "lLQ9QcPQoWDN"
},
"source": [
"%%capture\n",
"\n",
"# Install timm save and push branch + huggingface_hub package\n",
"! pip install git+https://github.com/rwightman/pytorch-image-models.git\n",
"! pip install huggingface-hub\n",
"\n",
"# Install Git LFS, which is required for huggingface_hub\n",
"! apt install git-lfs\n",
"\n",
"# Add credential helper - used by huggingface_hub package\n",
"! git config --global credential.helper store"
],
"execution_count": 1,
"outputs": []
},
{
"cell_type": "code",
"metadata": {
"id": "piOyQPRqohrm",
"colab": {
"base_uri": "https://localhost:8080/"
},
"outputId": "0fbff826-02db-4ca7-ef4b-95445db2021f"
},
"source": [
"# Log into Hugging Face Hub from CLI\n",
"! huggingface-cli login"
],
"execution_count": 2,
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": [
"\n",
" _| _| _| _| _|_|_| _|_|_| _|_|_| _| _| _|_|_| _|_|_|_| _|_| _|_|_| _|_|_|_|\n",
" _| _| _| _| _| _| _| _|_| _| _| _| _| _| _| _|\n",
" _|_|_|_| _| _| _| _|_| _| _|_| _| _| _| _| _| _|_| _|_|_| _|_|_|_| _| _|_|_|\n",
" _| _| _| _| _| _| _| _| _| _| _|_| _| _| _| _| _| _| _|\n",
" _| _| _|_| _|_|_| _|_|_| _|_|_| _| _| _|_|_| _| _| _| _|_|_| _|_|_|_|\n",
"\n",
" To login, `huggingface_hub` now requires a token generated from https://huggingface.co/settings/token.\n",
" (Deprecated, will be removed in v0.3.0) To login with username and password instead, interrupt with Ctrl+C.\n",
" \n",
"Token: \n",
"Login successful\n",
"Your token has been saved to /root/.huggingface/token\n"
]
}
]
},
{
"cell_type": "code",
"metadata": {
"id": "cN0GSfBioVO0"
},
"source": [
"import timm\n",
"\n",
"# Build a model 🔧\n",
"model = timm.create_model('resnet18', pretrained=True, num_classes=4)\n",
"\n",
"# Push it to the 🤗 hub \n",
"timm.models.hub.push_to_hf_hub(model, 'resnet18-random-classifier-new', model_config=dict(labels=['a', 'b', 'c', 'd']))\n",
"\n",
"# Load from hub 🔥\n",
"model_reloaded = timm.create_model('hf_hub:nateraw/resnet18-random-classifier-new')"
],
"execution_count": null,
"outputs": []
}
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment