Skip to content

Commit

Permalink
Add quick start colab example
Browse files Browse the repository at this point in the history
  • Loading branch information
jinjingforever authored May 9, 2024
1 parent c4e4502 commit 9beac91
Showing 1 changed file with 142 additions and 0 deletions.
142 changes: 142 additions & 0 deletions example_colabs/quick_start.ipynb
Original file line number Diff line number Diff line change
@@ -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": []
}
]
}

0 comments on commit 9beac91

Please sign in to comment.