Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
160 changes: 80 additions & 80 deletions tensorflow_model_optimization/g3doc/guide/clustering/clustering_comprehensive_guide.ipynb
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,4 +1,33 @@
{
"nbformat": 4,
"nbformat_minor": 0,
"metadata": {
"celltoolbar": "Raw Cell Format",
"colab": {
"name": "clustering_comprehensive_guide.ipynb",
"provenance": [],
"private_outputs": true,
"collapsed_sections": [],
"toc_visible": true
},
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.9"
}
},
"cells": [
{
"cell_type": "markdown",
Expand All @@ -7,19 +36,17 @@
"id": "826IBSWMN4rr"
},
"source": [
"**Copyright 2020 The TensorFlow Authors.**"
"##### Copyright 2020 The TensorFlow Authors."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"cellView": "form",
"colab": {},
"colab_type": "code",
"id": "ITj3u97-tNR7"
"id": "ITj3u97-tNR7",
"colab": {}
},
"outputs": [],
"source": [
"#@title Licensed under the Apache License, Version 2.0 (the \"License\");\n",
"# you may not use this file except in compliance with the License.\n",
Expand All @@ -32,7 +59,9 @@
"# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n",
"# See the License for the specific language governing permissions and\n",
"# limitations under the License."
]
],
"execution_count": null,
"outputs": []
},
{
"cell_type": "markdown",
Expand All @@ -51,20 +80,20 @@
"id": "IFva_Ed5N4ru"
},
"source": [
"\u003ctable class=\"tfo-notebook-buttons\" align=\"left\"\u003e\n",
" \u003ctd\u003e\n",
" \u003ca target=\"_blank\" href=\"https://www.tensorflow.org/model_optimization/guide/clustering/clustering_comprehensive_guide\"\u003e\u003cimg src=\"https://www.tensorflow.org/images/tf_logo_32px.png\" /\u003eView on TensorFlow.org\u003c/a\u003e\n",
" \u003c/td\u003e\n",
" \u003ctd\u003e\n",
" \u003ca target=\"_blank\" href=\"https://colab.research.google.com/github/tensorflow/model-optimization/blob/master/tensorflow_model_optimization/g3doc/guide/clustering/clustering_comprehensive_guide.ipynb\"\u003e\u003cimg src=\"https://www.tensorflow.org/images/colab_logo_32px.png\" /\u003eRun in Google Colab\u003c/a\u003e\n",
" \u003c/td\u003e\n",
" \u003ctd\u003e\n",
" \u003ca target=\"_blank\" href=\"https://github.com/tensorflow/model-optimization/blob/master/tensorflow_model_optimization/g3doc/guide/clustering/clustering_comprehensive_guide.ipynb\"\u003e\u003cimg src=\"https://www.tensorflow.org/images/GitHub-Mark-32px.png\" /\u003eView source on GitHub\u003c/a\u003e\n",
" \u003c/td\u003e\n",
" \u003ctd\u003e\n",
" \u003ca href=\"https://storage.googleapis.com/tensorflow_docs/model-optimization/tensorflow_model_optimization/g3doc/guide/clustering/clustering_comprehensive_guide.ipynb\"\u003e\u003cimg src=\"https://www.tensorflow.org/images/download_logo_32px.png\" /\u003eDownload notebook\u003c/a\u003e\n",
" \u003c/td\u003e\n",
"\u003c/table\u003e"
"<table class=\"tfo-notebook-buttons\" align=\"left\">\n",
" <td>\n",
" <a target=\"_blank\" href=\"https://www.tensorflow.org/model_optimization/guide/clustering/clustering_comprehensive_guide\"><img src=\"https://www.tensorflow.org/images/tf_logo_32px.png\" />View on TensorFlow.org</a>\n",
" </td>\n",
" <td>\n",
" <a target=\"_blank\" href=\"https://colab.research.google.com/github/tensorflow/model-optimization/blob/master/tensorflow_model_optimization/g3doc/guide/clustering/clustering_comprehensive_guide.ipynb\"><img src=\"https://www.tensorflow.org/images/colab_logo_32px.png\" />Run in Google Colab</a>\n",
" </td>\n",
" <td>\n",
" <a target=\"_blank\" href=\"https://github.com/tensorflow/model-optimization/blob/master/tensorflow_model_optimization/g3doc/guide/clustering/clustering_comprehensive_guide.ipynb\"><img src=\"https://www.tensorflow.org/images/GitHub-Mark-32px.png\" />View source on GitHub</a>\n",
" </td>\n",
" <td>\n",
" <a href=\"https://storage.googleapis.com/tensorflow_docs/model-optimization/tensorflow_model_optimization/g3doc/guide/clustering/clustering_comprehensive_guide.ipynb\"><img src=\"https://www.tensorflow.org/images/download_logo_32px.png\" />Download notebook</a>\n",
" </td>\n",
"</table>"
]
},
{
Expand Down Expand Up @@ -101,14 +130,12 @@
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"colab": {},
"colab_type": "code",
"id": "08dJRvOqN4rw",
"scrolled": true
"scrolled": true,
"colab": {}
},
"outputs": [],
"source": [
"! pip install -q tensorflow-model-optimization\n",
"\n",
Expand Down Expand Up @@ -176,7 +203,9 @@
"\n",
"setup_model()\n",
"pretrained_weights = setup_pretrained_weights()"
]
],
"execution_count": null,
"outputs": []
},
{
"cell_type": "markdown",
Expand All @@ -185,7 +214,7 @@
"id": "ARd37qONN4rz"
},
"source": [
"# Define a clustered model\n"
"## Define a clustered model\n"
]
},
{
Expand Down Expand Up @@ -215,14 +244,12 @@
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"colab": {},
"colab_type": "code",
"id": "29g7OADjN4r1",
"scrolled": true
"scrolled": true,
"colab": {}
},
"outputs": [],
"source": [
"import tensorflow_model_optimization as tfmot\n",
"\n",
Expand All @@ -240,7 +267,9 @@
"clustered_model = cluster_weights(model, **clustering_params)\n",
"\n",
"clustered_model.summary()"
]
],
"execution_count": null,
"outputs": []
},
{
"cell_type": "markdown",
Expand Down Expand Up @@ -272,14 +301,12 @@
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"colab": {},
"colab_type": "code",
"id": "IqBdl3uJN4r_",
"scrolled": true
"scrolled": true,
"colab": {}
},
"outputs": [],
"source": [
"# Create a base model\n",
"base_model = setup_model()\n",
Expand All @@ -300,7 +327,9 @@
")\n",
"\n",
"clustered_model.summary()"
]
],
"execution_count": null,
"outputs": []
},
{
"cell_type": "markdown",
Expand All @@ -309,7 +338,7 @@
"id": "hN0DgpvD5Add"
},
"source": [
"# Checkpoint and deserialize a clustered model"
"## Checkpoint and deserialize a clustered model"
]
},
{
Expand All @@ -324,13 +353,11 @@
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"colab": {},
"colab_type": "code",
"id": "w7P67mPk6RkQ"
"id": "w7P67mPk6RkQ",
"colab": {}
},
"outputs": [],
"source": [
"# Define the model.\n",
"base_model = setup_model()\n",
Expand All @@ -346,7 +373,9 @@
" loaded_model = tf.keras.models.load_model(keras_model_file)\n",
"\n",
"loaded_model.summary()"
]
],
"execution_count": null,
"outputs": []
},
{
"cell_type": "markdown",
Expand All @@ -355,7 +384,7 @@
"id": "cUv-scK-N4sN"
},
"source": [
"# Improve the accuracy of the clustered model"
"## Improve the accuracy of the clustered model"
]
},
{
Expand All @@ -381,7 +410,7 @@
"id": "4DXw7YbyN4sP"
},
"source": [
"# Deployment"
"## Deployment"
]
},
{
Expand All @@ -391,7 +420,7 @@
"id": "5Y5zLfPzN4sQ"
},
"source": [
"## Export model with size compression"
"### Export model with size compression"
]
},
{
Expand All @@ -406,13 +435,11 @@
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"colab": {},
"colab_type": "code",
"id": "ZvuiCBsVN4sR"
"id": "ZvuiCBsVN4sR",
"colab": {}
},
"outputs": [],
"source": [
"model = setup_model()\n",
"clustered_model = cluster_weights(model, **clustering_params)\n",
Expand All @@ -438,36 +465,9 @@
" % (get_gzipped_model_size(clustered_model)))\n",
"print(\"Size of gzipped clustered model with stripping: %.2f bytes\" \n",
" % (get_gzipped_model_size(final_model)))"
]
}
],
"metadata": {
"celltoolbar": "Raw Cell Format",
"colab": {
"collapsed_sections": [],
"name": "clustering_comprehensive_guide.ipynb",
"private_outputs": true,
"provenance": [],
"toc_visible": true
},
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.9"
],
"execution_count": null,
"outputs": []
}
},
"nbformat": 4,
"nbformat_minor": 0
]
}