Commit 139dd8e9 authored by Yukun Zhu's avatar Yukun Zhu Committed by aquariusjay
Browse files

colab demo update (#6616)

parent 61793e67
...@@ -7,9 +7,36 @@ ...@@ -7,9 +7,36 @@
"id": "KFPcBuVFw61h" "id": "KFPcBuVFw61h"
}, },
"source": [ "source": [
"# DeepLab Demo\n", "# Overview\n",
"\n", "\n",
"This demo will demostrate the steps to run deeplab semantic segmentation model on sample input images." "This demo will demostrate the steps to use the DeepLab model to perform semantic segmentation on a sample input image. Expected outputs are semantic labels overlayed on the sample image.\n",
"\n",
"### What is DeepLab\n",
"Models used in this colab perform semantic segmentation. Semantic segmentation models focus on assigning semantic labels (e.g. sky, person, car) to multiple objects and stuff in a single image."
]
},
{
"cell_type": "markdown",
"metadata": {
"colab_type": "text",
"id": "t3ozFsEEP-u_"
},
"source": [
"# Instructions\n",
"\u003ch3\u003e\u003ca href=\"https://cloud.google.com/tpu/\"\u003e\u003cimg valign=\"middle\" src=\"https://raw.githubusercontent.com/GoogleCloudPlatform/tensorflow-without-a-phd/master/tensorflow-rl-pong/images/tpu-hexagon.png\" width=\"50\"\u003e\u003c/a\u003e \u0026nbsp;\u0026nbsp;Use a free TPU device\u003c/h3\u003e\n",
"\n",
" 1. On the main menu, click Runtime and select **Change runtime type**. Set \"TPU\" as the hardware accelerator.\n",
" 1. Click Runtime again and select **Runtime \u003e Run All** (Watch out: the \"Colab-only auth for this notebook and the TPU\" cell requires user input). You can also run the cells manually with Shift-ENTER."
]
},
{
"cell_type": "markdown",
"metadata": {
"colab_type": "text",
"id": "7cRiapZ1P3wy"
},
"source": [
"## Import Libraries"
] ]
}, },
{ {
...@@ -17,19 +44,12 @@ ...@@ -17,19 +44,12 @@
"execution_count": 0, "execution_count": 0,
"metadata": { "metadata": {
"cellView": "code", "cellView": "code",
"colab": { "colab": {},
"autoexec": {
"startup": false,
"wait_interval": 0
}
},
"colab_type": "code", "colab_type": "code",
"id": "kAbdmRmvq0Je" "id": "kAbdmRmvq0Je"
}, },
"outputs": [], "outputs": [],
"source": [ "source": [
"#@title Imports\n",
"\n",
"import os\n", "import os\n",
"from io import BytesIO\n", "from io import BytesIO\n",
"import tarfile\n", "import tarfile\n",
...@@ -44,25 +64,32 @@ ...@@ -44,25 +64,32 @@
"import tensorflow as tf" "import tensorflow as tf"
] ]
}, },
{
"cell_type": "markdown",
"metadata": {
"colab_type": "text",
"id": "p47cYGGOQE1W"
},
"source": [
"## Import helper methods\n",
"These methods will help us perform the following tasks:\n",
"* Load the latest version of the pretrained DeepLab model\n",
"* Load the colormap from the PASCAL VOC dataset\n",
"* Adds colors to various labels (For example, \"pink\" for people, \"green\" for bicycle and more)\n",
"* Visualize an image, and add an overlay of colors on various regions."
]
},
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 0, "execution_count": 0,
"metadata": { "metadata": {
"cellView": "code", "cellView": "code",
"colab": { "colab": {},
"autoexec": {
"startup": false,
"wait_interval": 0
}
},
"colab_type": "code", "colab_type": "code",
"id": "vN0kU6NJ1Ye5" "id": "vN0kU6NJ1Ye5"
}, },
"outputs": [], "outputs": [],
"source": [ "source": [
"#@title Helper methods\n",
"\n",
"\n",
"class DeepLabModel(object):\n", "class DeepLabModel(object):\n",
" \"\"\"Class to load deeplab model and run inference.\"\"\"\n", " \"\"\"Class to load deeplab model and run inference.\"\"\"\n",
"\n", "\n",
...@@ -202,23 +229,27 @@ ...@@ -202,23 +229,27 @@
"FULL_COLOR_MAP = label_to_color_image(FULL_LABEL_MAP)" "FULL_COLOR_MAP = label_to_color_image(FULL_LABEL_MAP)"
] ]
}, },
{
"cell_type": "markdown",
"metadata": {
"colab_type": "text",
"id": "nGcZzNkASG9A"
},
"source": [
"## Select a pretrained model\n",
"We have trained the DeepLab model using various backbone networks that you can choose form."
]
},
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 0, "execution_count": 0,
"metadata": { "metadata": {
"colab": { "colab": {},
"autoexec": {
"startup": false,
"wait_interval": 0
}
},
"colab_type": "code", "colab_type": "code",
"id": "c4oXKmnjw6i_" "id": "c4oXKmnjw6i_"
}, },
"outputs": [], "outputs": [],
"source": [ "source": [
"#@title Select and download models {display-mode: \"form\"}\n",
"\n",
"MODEL_NAME = 'mobilenetv2_coco_voctrainaug' # @param ['mobilenetv2_coco_voctrainaug', 'mobilenetv2_coco_voctrainval', 'xception_coco_voctrainaug', 'xception_coco_voctrainval']\n", "MODEL_NAME = 'mobilenetv2_coco_voctrainaug' # @param ['mobilenetv2_coco_voctrainaug', 'mobilenetv2_coco_voctrainval', 'xception_coco_voctrainaug', 'xception_coco_voctrainval']\n",
"\n", "\n",
"_DOWNLOAD_URL_PREFIX = 'http://download.tensorflow.org/models/'\n", "_DOWNLOAD_URL_PREFIX = 'http://download.tensorflow.org/models/'\n",
...@@ -269,18 +300,13 @@ ...@@ -269,18 +300,13 @@
"cell_type": "code", "cell_type": "code",
"execution_count": 0, "execution_count": 0,
"metadata": { "metadata": {
"colab": { "cellView": "form",
"autoexec": { "colab": {},
"startup": false,
"wait_interval": 0
}
},
"colab_type": "code", "colab_type": "code",
"id": "edGukUHXyymr" "id": "edGukUHXyymr"
}, },
"outputs": [], "outputs": [],
"source": [ "source": [
"#@title Run on sample images {display-mode: \"form\"}\n",
"\n", "\n",
"SAMPLE_IMAGE = 'image1' # @param ['image1', 'image2', 'image3']\n", "SAMPLE_IMAGE = 'image1' # @param ['image1', 'image2', 'image3']\n",
"IMAGE_URL = '' #@param {type:\"string\"}\n", "IMAGE_URL = '' #@param {type:\"string\"}\n",
...@@ -310,32 +336,27 @@ ...@@ -310,32 +336,27 @@
] ]
}, },
{ {
"cell_type": "code", "cell_type": "markdown",
"execution_count": 0,
"metadata": { "metadata": {
"colab": { "colab_type": "text",
"autoexec": { "id": "aUbVoHScTJYe"
"startup": false,
"wait_interval": 0
}
},
"colab_type": "code",
"id": "7XrFNGsxzSIB"
}, },
"outputs": [],
"source": [ "source": [
"" "## What's next\n",
"\n",
"* Learn about [Cloud TPUs](https://cloud.google.com/tpu/docs) that Google designed and optimized specifically to speed up and scale up ML workloads for training and inference and to enable ML engineers and researchers to iterate more quickly.\n",
"* Explore the range of [Cloud TPU tutorials and Colabs](https://cloud.google.com/tpu/docs/tutorials) to find other examples that can be used when implementing your ML project.\n",
"* [Here's](https://cloud.google.com/tpu/docs/tutorials/deeplab) a direct link to the DeepLab tutorial.\n"
] ]
} }
], ],
"metadata": { "metadata": {
"colab": { "colab": {
"collapsed_sections": [], "collapsed_sections": [],
"default_view": {},
"name": "DeepLab Demo.ipynb", "name": "DeepLab Demo.ipynb",
"provenance": [], "provenance": [],
"version": "0.3.2", "toc_visible": true,
"views": {} "version": "0.3.2"
}, },
"kernelspec": { "kernelspec": {
"display_name": "Python 2", "display_name": "Python 2",
...@@ -345,4 +366,3 @@ ...@@ -345,4 +366,3 @@
"nbformat": 4, "nbformat": 4,
"nbformat_minor": 0 "nbformat_minor": 0
} }
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment