From 9beac91da45964e0212915f240d663334a92ca51 Mon Sep 17 00:00:00 2001 From: Jing Jin <8752427+jinjingforever@users.noreply.github.com> Date: Thu, 9 May 2024 10:48:58 -0700 Subject: [PATCH] Add quick start colab example --- example_colabs/quick_start.ipynb | 142 +++++++++++++++++++++++++++++++ 1 file changed, 142 insertions(+) create mode 100644 example_colabs/quick_start.ipynb diff --git a/example_colabs/quick_start.ipynb b/example_colabs/quick_start.ipynb new file mode 100644 index 00000000..29a35763 --- /dev/null +++ b/example_colabs/quick_start.ipynb @@ -0,0 +1,142 @@ +{ + "nbformat": 4, + "nbformat_minor": 0, + "metadata": { + "colab": { + "provenance": [], + "collapsed_sections": [ + "vCM_sxQsg2nj", + "nSHa2LHCg7Gz", + "tNzvaoFHhBJR", + "Q3aMYkE6HMPM" + ], + "private_outputs": true + }, + "kernelspec": { + "name": "python3", + "display_name": "Python 3" + }, + "language_info": { + "name": "python" + } + }, + "cells": [ + { + "cell_type": "markdown", + "source": [ + "# Google AI Edge Model Explorer [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/google-ai-edge/model-explorer/blob/main/example_colabs/quick_start.ipynb)\n", + "A visualization tool that lets you analyze ML models and graphs, accelerating deployment to on-device targets. [Learn more](https://ai.google.dev/edge/model-explorer).\n", + "\n", + "**Key Features**\n", + "\n", + "* Visualize large models effortlessly\n", + "* Find model conversion issues\n", + "* Identify optimization targets\n", + "* Easy to use intuitive UI\n", + "\n", + "Follow the [installation instructions](https://github.com/google-ai-edge/model-explorer/wiki/5.-Run-in-Colab-Notebook) to add it to your own Colab.\n", + "\n", + "Want to run Model Explorer locally? [Get Started here](https://github.com/google-ai-edge/model-explorer/wiki/1.-Installation)" + ], + "metadata": { + "id": "Earrbj1HNaVk" + } + }, + { + "cell_type": "markdown", + "source": [ + "# Download a copy of the EfficientDet TFLite model" + ], + "metadata": { + "id": "vCM_sxQsg2nj" + } + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "SmUNdu2jhU1z" + }, + "outputs": [], + "source": [ + "import os\n", + "import tempfile\n", + "import urllib.request\n", + "import torch\n", + "import torchvision\n", + "\n", + "tmp_path = tempfile.mkdtemp()\n", + "model_path = os.path.join(tmp_path, 'model.tflite')\n", + "urllib.request.urlretrieve(\"https://storage.googleapis.com/tfweb/model-graph-vis-v2-test-models/efficientdet.tflite\", model_path)" + ] + }, + { + "cell_type": "markdown", + "source": [ + "# Install Model Explorer using pip" + ], + "metadata": { + "id": "nSHa2LHCg7Gz" + } + }, + { + "cell_type": "code", + "source": [ + "!pip install --no-deps model-explorer-adapter ai-edge-model-explorer" + ], + "metadata": { + "id": "XqnjhEVqkSvU" + }, + "execution_count": null, + "outputs": [] + }, + { + "cell_type": "markdown", + "source": [ + "# Visualize the downloaded EfficientDet model" + ], + "metadata": { + "id": "tNzvaoFHhBJR" + } + }, + { + "cell_type": "code", + "source": [ + "import model_explorer\n", + "\n", + "model_explorer.visualize(model_path)" + ], + "metadata": { + "id": "_qycf3tbmP_S" + }, + "execution_count": null, + "outputs": [] + }, + { + "cell_type": "markdown", + "source": [ + "# Visualize a PyTorch model\n", + "\n" + ], + "metadata": { + "id": "Q3aMYkE6HMPM" + } + }, + { + "cell_type": "code", + "source": [ + "# Get mobilnet v2 pytorch model as an example.\n", + "model = torchvision.models.mobilenet_v2().eval()\n", + "inputs = (torch.rand([1, 3, 224, 224]),)\n", + "\n", + "# Visualize\n", + "model_explorer.visualize_pytorch('mobilenet', model, inputs)" + ], + "metadata": { + "id": "sZJkEgdsHSH9" + }, + "execution_count": null, + "outputs": [] + } + ] +} \ No newline at end of file