diff --git "a/SPIGA/colab_tutorials/video_demo.ipynb" "b/SPIGA/colab_tutorials/video_demo.ipynb" new file mode 100644--- /dev/null +++ "b/SPIGA/colab_tutorials/video_demo.ipynb" @@ -0,0 +1,215 @@ +{ + "nbformat": 4, + "nbformat_minor": 0, + "metadata": { + "colab": { + "provenance": [], + "authorship_tag": "ABX9TyOF6rc4QkOxYUF0EKnbRAyL" + }, + "kernelspec": { + "name": "python3", + "display_name": "Python 3" + }, + "language_info": { + "name": "python" + }, + "accelerator": "GPU", + "gpuClass": "standard" + }, + "cells": [ + { + "cell_type": "markdown", + "source": [ + "# SPIGA: Shape Preserving Facial Landmarks with Graph Attention Networks.\n", + "\n", + "[![Code](https://badgen.net/badge/github/spiga/black?a&icon=github&label)](https://github.com/andresprados/SPIGA)\n", + "[![Project Page](https://badgen.net/badge/color/Project%20Page/purple?icon=atom&label)](https://bmvc2022.mpi-inf.mpg.de/155/)\n", + "[![arXiv](https://img.shields.io/badge/arXiv-2210.07233-b31b1b.svg)](https://arxiv.org/abs/2210.07233)\n", + "[![PyPI version](https://badge.fury.io/py/spiga.svg)](https://badge.fury.io/py/spiga)\n", + "[![License](https://img.shields.io/badge/License-BSD%203--Clause-blue.svg)](LICENSE)\n", + "[![Open in Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/andresprados/SPIGA/blob/main/colab_tutorials/video_demo.ipynb)\n", + "\n", + "**SPIGA is a face alignment and headpose estimator** that takes advantage of the complementary benefits from CNN and GNN architectures producing plausible face shapes in presence of strong appearance changes. \n" + ], + "metadata": { + "id": "zYVrcsnLp7D0" + } + }, + { + "cell_type": "markdown", + "source": [ + "## Video Analyzer Demo:\n", + "SPIGA provides a general framework for tracking, detecting and extracting features of human faces in images or videos." + ], + "metadata": { + "id": "6VGcBElYwZQM" + } + }, + { + "cell_type": "markdown", + "source": [ + "###Setup the repository:\n" + ], + "metadata": { + "id": "Pxj4tBskykGV" + } + }, + { + "cell_type": "code", + "source": [ + "# Clone and setup the repository\n", + "!git clone https://github.com/andresprados/SPIGA.git\n", + "%cd SPIGA/\n", + "!pip install -e .[demo]" + ], + "metadata": { + "id": "N6Mvu13ZBg92" + }, + "execution_count": null, + "outputs": [] + }, + { + "cell_type": "markdown", + "source": [ + "### Record Webcam Video:" + ], + "metadata": { + "id": "E4u69_ssyxkY" + } + }, + { + "cell_type": "code", + "source": [ + "import colab_tutorials.video_tools.record as vid_util\n", + "\n", + "webcam_video_path = '/content/test.mp4'\n", + "vid_util.record_video(webcam_video_path)" + ], + "metadata": { + "id": "Mck9eHXKYUxd" + }, + "execution_count": null, + "outputs": [] + }, + { + "cell_type": "markdown", + "source": [ + "### Process Video with SPIGA Framework:\n", + "\n" + ], + "metadata": { + "id": "JefR-lla9xEs" + } + }, + { + "cell_type": "code", + "source": [ + "import os\n", + "from spiga.demo.app import video_app\n", + "\n", + "# MP4 input path: Webcam recorded video or uploaded one.\n", + "# video_path = '/content/'\n", + "video_path = webcam_video_path\n", + "output_path= '/content/output' # Processed video storage\n", + "\n", + "# Process video\n", + "video_app(video_path,\n", + " spiga_dataset='wflw', # Choices=['wflw', '300wpublic', '300wprivate', 'merlrav']\n", + " tracker='RetinaSort', # Choices=['RetinaSort', 'RetinaSort_Res50']\n", + " save=True,\n", + " output_path=output_path,\n", + " visualize=False,\n", + " plot=['fps', 'face_id', 'landmarks', 'headpose'])\n", + "\n", + "\n", + "# Convert Opencv video to Colab readable format\n", + "video_name = video_path.split('/')[-1]\n", + "video_output_path = os.path.join(output_path, video_name)\n", + "video_colab_path = os.path.join(output_path, video_name[:-4]+'_colab.mp4')\n", + "!ffmpeg -i '{video_output_path}' '{video_colab_path}'" + ], + "metadata": { + "id": "wffMRr2T8Yvk" + }, + "execution_count": null, + "outputs": [] + }, + { + "cell_type": "markdown", + "source": [ + "### Results Visualization:" + ], + "metadata": { + "id": "v0k3qZ3YDlEw" + } + }, + { + "cell_type": "code", + "source": [ + "import colab_tutorials.video_tools.record as vid_util\n", + "\n", + "# Display video\n", + "vid_util.show_video(video_colab_path)" + ], + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/", + "height": 471 + }, + "id": "I6o6piO-Dju_", + "outputId": "6f520b13-c6e7-4abe-8660-51d32f66524a" + }, + "execution_count": null, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": [ + "" + ], + "text/html": [ + "" + ] + }, + "metadata": {}, + "execution_count": 10 + } + ] + }, + { + "cell_type": "markdown", + "source": [ + "# Citation\n", + "If you like our work dont forget to cite us!\n", + "\n", + "```\n", + "@inproceedings{Prados-Torreblanca_2022_BMVC,\n", + " author = {Andrés Prados-Torreblanca and José M Buenaposada and Luis Baumela},\n", + " title = {Shape Preserving Facial Landmarks with Graph Attention Networks},\n", + " booktitle = {33rd British Machine Vision Conference 2022, {BMVC} 2022, London, UK, November 21-24, 2022},\n", + " publisher = {{BMVA} Press},\n", + " year = {2022},\n", + " url = {https://bmvc2022.mpi-inf.mpg.de/0155.pdf}\n", + "}\n", + "```" + ], + "metadata": { + "id": "ZvuQLJPDGejs" + } + }, + { + "cell_type": "markdown", + "source": [ + "# Related Notebooks\n", + "\n", + "Tutorials | Notebook |\n", + ":---| :---: |\n", + "Image Inference Example | [![Open in Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/andresprados/SPIGA/blob/main/colab_tutorials/image_demo.ipynb) |\n", + "Face Video Analyzer Demo | [![Open in Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/andresprados/SPIGA/blob/main/colab_tutorials/video_demo.ipynb) |" + ], + "metadata": { + "id": "aQ_G5unzGmto" + } + } + ] +} \ No newline at end of file