Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save nateraw/91dcb961e231276b2023c0aea56776c9 to your computer and use it in GitHub Desktop.
Save nateraw/91dcb961e231276b2023c0aea56776c9 to your computer and use it in GitHub Desktop.
video-classification-pipeline-transformers.ipynb
Display the source blob
Display the rendered blob
Raw
{
"nbformat": 4,
"nbformat_minor": 0,
"metadata": {
"colab": {
"provenance": [],
"authorship_tag": "ABX9TyM9NSA5ttaEF4FeOYmn86nH",
"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/91dcb961e231276b2023c0aea56776c9/video-classification-pipeline-transformers.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "rp9ru2SfNMxA"
},
"outputs": [],
"source": [
"%%capture\n",
"! pip install git+https://github.com/huggingface/transformers@main#egg=transformers[video]"
]
},
{
"cell_type": "markdown",
"source": [
"You can also load many other models from the Hub. Check them out [here](https://huggingface.co/models?pipeline_tag=video-classification)."
],
"metadata": {
"id": "BQZo0NyDPdcG"
}
},
{
"cell_type": "code",
"source": [
"from transformers import pipeline\n",
"\n",
"# 🤗 Load the pipeline\n",
"pipe = pipeline('video-classification')"
],
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "CREbsTxgNSMT",
"outputId": "0b42fb3f-9e61-497e-f383-bf8717b919e2"
},
"execution_count": 5,
"outputs": [
{
"output_type": "stream",
"name": "stderr",
"text": [
"No model was supplied, defaulted to MCG-NJU/videomae-base-finetuned-kinetics and revision 4800870 (https://huggingface.co/MCG-NJU/videomae-base-finetuned-kinetics).\n",
"Using a pipeline without specifying a model name and revision in production is not recommended.\n",
"/usr/local/lib/python3.8/dist-packages/transformers/models/videomae/feature_extraction_videomae.py:28: FutureWarning: The class VideoMAEFeatureExtractor is deprecated and will be removed in version 5 of Transformers. Please use VideoMAEImageProcessor instead.\n",
" warnings.warn(\n"
]
}
]
},
{
"cell_type": "code",
"source": [
"# 🔥 Predict on video URLs or files\n",
"pipe('https://huggingface.co/datasets/nateraw/video-demo/resolve/main/archery.mp4')"
],
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "vabAytKIPQnk",
"outputId": "4319a10a-7b01-43c5-9a56-4e035f9bd0fb"
},
"execution_count": 6,
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": [
"[{'score': 0.6418353319168091, 'label': 'archery'},\n",
" {'score': 0.002652964321896434, 'label': 'riding unicycle'},\n",
" {'score': 0.0025830131489783525, 'label': 'golf driving'},\n",
" {'score': 0.002545428927987814, 'label': 'throwing ball'},\n",
" {'score': 0.0023797592148184776, 'label': 'tobogganing'}]"
]
},
"metadata": {},
"execution_count": 6
}
]
}
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment