Skip to content

Commit

Permalink
Update colabs to follow TF docs nbfmt formatting (https://www.tensorf…
Browse files Browse the repository at this point in the history
…low.org/community/contribute/docs#notebook_formatting). And reference formatting in CONTRIBUTORS doc.

PiperOrigin-RevId: 331220386
  • Loading branch information
alanchiao authored and tensorflower-gardener committed Sep 11, 2020
1 parent 14b724b commit d80eed6
Show file tree
Hide file tree
Showing 7 changed files with 117 additions and 495 deletions.
2 changes: 2 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ Feedback is welcome.

### Style and Practices
* Please refer to [TensorFlow's style guide](https://www.tensorflow.org/community/contribute/code_style). Don't forget to run pylint.
* For Colab changes, please refer to the [Notebook Formatting section](https://www.tensorflow.org/community/contribute/docs#notebook_formatting) in the TF docs and run nbfmt after
any changes.

Unless agreed upon with the project maintainer in the issue or PR, the following are necessary to
merge a PR.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,38 +1,8 @@
{
"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",
"metadata": {
"colab_type": "text",
"id": "826IBSWMN4rr"
},
"source": [
Expand All @@ -41,12 +11,12 @@
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"cellView": "form",
"colab_type": "code",
"id": "ITj3u97-tNR7",
"colab": {}
"id": "ITj3u97-tNR7"
},
"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 @@ -59,14 +29,11 @@
"# 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",
"metadata": {
"colab_type": "text",
"id": "BYwfpc4wN4rt"
},
"source": [
Expand All @@ -76,30 +43,28 @@
{
"cell_type": "markdown",
"metadata": {
"colab_type": "text",
"id": "IFva_Ed5N4ru"
},
"source": [
"<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>"
"\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"
]
},
{
"cell_type": "markdown",
"metadata": {
"colab_type": "text",
"id": "tidmcl3sN4rv"
},
"source": [
Expand All @@ -114,14 +79,12 @@
"* Define a clustered model.\n",
"* Checkpoint and deserialize a clustered model.\n",
"* Improve the accuracy of the clustered model.\n",
"* For deployment only, you must take steps to see compression benefits.\n",
"\n"
"* For deployment only, you must take steps to see compression benefits.\n"
]
},
{
"cell_type": "markdown",
"metadata": {
"colab_type": "text",
"id": "RRtKxbo8N4rv"
},
"source": [
Expand All @@ -130,12 +93,11 @@
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"colab_type": "code",
"id": "08dJRvOqN4rw",
"scrolled": true,
"colab": {}
"id": "08dJRvOqN4rw"
},
"outputs": [],
"source": [
"! pip install -q tensorflow-model-optimization\n",
"\n",
Expand Down Expand Up @@ -203,14 +165,11 @@
"\n",
"setup_model()\n",
"pretrained_weights = setup_pretrained_weights()"
],
"execution_count": null,
"outputs": []
]
},
{
"cell_type": "markdown",
"metadata": {
"colab_type": "text",
"id": "ARd37qONN4rz"
},
"source": [
Expand All @@ -220,7 +179,6 @@
{
"cell_type": "markdown",
"metadata": {
"colab_type": "text",
"id": "zHB3pkU3N4r0"
},
"source": [
Expand All @@ -230,7 +188,6 @@
{
"cell_type": "markdown",
"metadata": {
"colab_type": "text",
"id": "ig-il1lmN4r1"
},
"source": [
Expand All @@ -244,12 +201,11 @@
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"colab_type": "code",
"id": "29g7OADjN4r1",
"scrolled": true,
"colab": {}
"id": "29g7OADjN4r1"
},
"outputs": [],
"source": [
"import tensorflow_model_optimization as tfmot\n",
"\n",
Expand All @@ -267,25 +223,20 @@
"clustered_model = cluster_weights(model, **clustering_params)\n",
"\n",
"clustered_model.summary()"
],
"execution_count": null,
"outputs": []
]
},
{
"cell_type": "markdown",
"metadata": {
"colab_type": "text",
"id": "zEOHK4OON4r7"
},
"source": [
"### Cluster some layers (sequential and functional models)\n",
"\n"
"### Cluster some layers (sequential and functional models)\n"
]
},
{
"cell_type": "markdown",
"metadata": {
"colab_type": "text",
"id": "ENscQ7ZWN4r8"
},
"source": [
Expand All @@ -301,12 +252,11 @@
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"colab_type": "code",
"id": "IqBdl3uJN4r_",
"scrolled": true,
"colab": {}
"id": "IqBdl3uJN4r_"
},
"outputs": [],
"source": [
"# Create a base model\n",
"base_model = setup_model()\n",
Expand All @@ -327,14 +277,11 @@
")\n",
"\n",
"clustered_model.summary()"
],
"execution_count": null,
"outputs": []
]
},
{
"cell_type": "markdown",
"metadata": {
"colab_type": "text",
"id": "hN0DgpvD5Add"
},
"source": [
Expand All @@ -344,7 +291,6 @@
{
"cell_type": "markdown",
"metadata": {
"colab_type": "text",
"id": "hfji5KWN6XCF"
},
"source": [
Expand All @@ -353,11 +299,11 @@
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"colab_type": "code",
"id": "w7P67mPk6RkQ",
"colab": {}
"id": "w7P67mPk6RkQ"
},
"outputs": [],
"source": [
"# Define the model.\n",
"base_model = setup_model()\n",
Expand All @@ -373,14 +319,11 @@
" loaded_model = tf.keras.models.load_model(keras_model_file)\n",
"\n",
"loaded_model.summary()"
],
"execution_count": null,
"outputs": []
]
},
{
"cell_type": "markdown",
"metadata": {
"colab_type": "text",
"id": "cUv-scK-N4sN"
},
"source": [
Expand All @@ -390,7 +333,6 @@
{
"cell_type": "markdown",
"metadata": {
"colab_type": "text",
"id": "-fZZopDBN4sO"
},
"source": [
Expand All @@ -406,7 +348,6 @@
{
"cell_type": "markdown",
"metadata": {
"colab_type": "text",
"id": "4DXw7YbyN4sP"
},
"source": [
Expand All @@ -416,7 +357,6 @@
{
"cell_type": "markdown",
"metadata": {
"colab_type": "text",
"id": "5Y5zLfPzN4sQ"
},
"source": [
Expand All @@ -426,7 +366,6 @@
{
"cell_type": "markdown",
"metadata": {
"colab_type": "text",
"id": "wX4OrHD9N4sQ"
},
"source": [
Expand All @@ -435,11 +374,11 @@
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"colab_type": "code",
"id": "ZvuiCBsVN4sR",
"colab": {}
"id": "ZvuiCBsVN4sR"
},
"outputs": [],
"source": [
"model = setup_model()\n",
"clustered_model = cluster_weights(model, **clustering_params)\n",
Expand All @@ -465,9 +404,20 @@
" % (get_gzipped_model_size(clustered_model)))\n",
"print(\"Size of gzipped clustered model with stripping: %.2f bytes\" \n",
" % (get_gzipped_model_size(final_model)))"
],
"execution_count": null,
"outputs": []
]
}
],
"metadata": {
"colab": {
"collapsed_sections": [],
"name": "clustering_comprehensive_guide.ipynb",
"toc_visible": true
},
"kernelspec": {
"display_name": "Python 3",
"name": "python3"
}
]
},
"nbformat": 4,
"nbformat_minor": 0
}
Loading

0 comments on commit d80eed6

Please sign in to comment.