|
1 | 1 | { |
| 2 | + "nbformat": 4, |
| 3 | + "nbformat_minor": 0, |
| 4 | + "metadata": { |
| 5 | + "celltoolbar": "Raw Cell Format", |
| 6 | + "colab": { |
| 7 | + "name": "clustering_comprehensive_guide.ipynb", |
| 8 | + "provenance": [], |
| 9 | + "private_outputs": true, |
| 10 | + "collapsed_sections": [], |
| 11 | + "toc_visible": true |
| 12 | + }, |
| 13 | + "kernelspec": { |
| 14 | + "display_name": "Python 3", |
| 15 | + "language": "python", |
| 16 | + "name": "python3" |
| 17 | + }, |
| 18 | + "language_info": { |
| 19 | + "codemirror_mode": { |
| 20 | + "name": "ipython", |
| 21 | + "version": 3 |
| 22 | + }, |
| 23 | + "file_extension": ".py", |
| 24 | + "mimetype": "text/x-python", |
| 25 | + "name": "python", |
| 26 | + "nbconvert_exporter": "python", |
| 27 | + "pygments_lexer": "ipython3", |
| 28 | + "version": "3.6.9" |
| 29 | + } |
| 30 | + }, |
2 | 31 | "cells": [ |
3 | 32 | { |
4 | 33 | "cell_type": "markdown", |
|
7 | 36 | "id": "826IBSWMN4rr" |
8 | 37 | }, |
9 | 38 | "source": [ |
10 | | - "**Copyright 2020 The TensorFlow Authors.**" |
| 39 | + "##### Copyright 2020 The TensorFlow Authors." |
11 | 40 | ] |
12 | 41 | }, |
13 | 42 | { |
14 | 43 | "cell_type": "code", |
15 | | - "execution_count": null, |
16 | 44 | "metadata": { |
17 | 45 | "cellView": "form", |
18 | | - "colab": {}, |
19 | 46 | "colab_type": "code", |
20 | | - "id": "ITj3u97-tNR7" |
| 47 | + "id": "ITj3u97-tNR7", |
| 48 | + "colab": {} |
21 | 49 | }, |
22 | | - "outputs": [], |
23 | 50 | "source": [ |
24 | 51 | "#@title Licensed under the Apache License, Version 2.0 (the \"License\");\n", |
25 | 52 | "# you may not use this file except in compliance with the License.\n", |
|
32 | 59 | "# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n", |
33 | 60 | "# See the License for the specific language governing permissions and\n", |
34 | 61 | "# limitations under the License." |
35 | | - ] |
| 62 | + ], |
| 63 | + "execution_count": null, |
| 64 | + "outputs": [] |
36 | 65 | }, |
37 | 66 | { |
38 | 67 | "cell_type": "markdown", |
|
51 | 80 | "id": "IFva_Ed5N4ru" |
52 | 81 | }, |
53 | 82 | "source": [ |
54 | | - "\u003ctable class=\"tfo-notebook-buttons\" align=\"left\"\u003e\n", |
55 | | - " \u003ctd\u003e\n", |
56 | | - " \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", |
57 | | - " \u003c/td\u003e\n", |
58 | | - " \u003ctd\u003e\n", |
59 | | - " \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", |
60 | | - " \u003c/td\u003e\n", |
61 | | - " \u003ctd\u003e\n", |
62 | | - " \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", |
63 | | - " \u003c/td\u003e\n", |
64 | | - " \u003ctd\u003e\n", |
65 | | - " \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", |
66 | | - " \u003c/td\u003e\n", |
67 | | - "\u003c/table\u003e" |
| 83 | + "<table class=\"tfo-notebook-buttons\" align=\"left\">\n", |
| 84 | + " <td>\n", |
| 85 | + " <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", |
| 86 | + " </td>\n", |
| 87 | + " <td>\n", |
| 88 | + " <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", |
| 89 | + " </td>\n", |
| 90 | + " <td>\n", |
| 91 | + " <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", |
| 92 | + " </td>\n", |
| 93 | + " <td>\n", |
| 94 | + " <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", |
| 95 | + " </td>\n", |
| 96 | + "</table>" |
68 | 97 | ] |
69 | 98 | }, |
70 | 99 | { |
|
101 | 130 | }, |
102 | 131 | { |
103 | 132 | "cell_type": "code", |
104 | | - "execution_count": null, |
105 | 133 | "metadata": { |
106 | | - "colab": {}, |
107 | 134 | "colab_type": "code", |
108 | 135 | "id": "08dJRvOqN4rw", |
109 | | - "scrolled": true |
| 136 | + "scrolled": true, |
| 137 | + "colab": {} |
110 | 138 | }, |
111 | | - "outputs": [], |
112 | 139 | "source": [ |
113 | 140 | "! pip install -q tensorflow-model-optimization\n", |
114 | 141 | "\n", |
|
176 | 203 | "\n", |
177 | 204 | "setup_model()\n", |
178 | 205 | "pretrained_weights = setup_pretrained_weights()" |
179 | | - ] |
| 206 | + ], |
| 207 | + "execution_count": null, |
| 208 | + "outputs": [] |
180 | 209 | }, |
181 | 210 | { |
182 | 211 | "cell_type": "markdown", |
|
185 | 214 | "id": "ARd37qONN4rz" |
186 | 215 | }, |
187 | 216 | "source": [ |
188 | | - "# Define a clustered model\n" |
| 217 | + "## Define a clustered model\n" |
189 | 218 | ] |
190 | 219 | }, |
191 | 220 | { |
|
215 | 244 | }, |
216 | 245 | { |
217 | 246 | "cell_type": "code", |
218 | | - "execution_count": null, |
219 | 247 | "metadata": { |
220 | | - "colab": {}, |
221 | 248 | "colab_type": "code", |
222 | 249 | "id": "29g7OADjN4r1", |
223 | | - "scrolled": true |
| 250 | + "scrolled": true, |
| 251 | + "colab": {} |
224 | 252 | }, |
225 | | - "outputs": [], |
226 | 253 | "source": [ |
227 | 254 | "import tensorflow_model_optimization as tfmot\n", |
228 | 255 | "\n", |
|
240 | 267 | "clustered_model = cluster_weights(model, **clustering_params)\n", |
241 | 268 | "\n", |
242 | 269 | "clustered_model.summary()" |
243 | | - ] |
| 270 | + ], |
| 271 | + "execution_count": null, |
| 272 | + "outputs": [] |
244 | 273 | }, |
245 | 274 | { |
246 | 275 | "cell_type": "markdown", |
|
272 | 301 | }, |
273 | 302 | { |
274 | 303 | "cell_type": "code", |
275 | | - "execution_count": null, |
276 | 304 | "metadata": { |
277 | | - "colab": {}, |
278 | 305 | "colab_type": "code", |
279 | 306 | "id": "IqBdl3uJN4r_", |
280 | | - "scrolled": true |
| 307 | + "scrolled": true, |
| 308 | + "colab": {} |
281 | 309 | }, |
282 | | - "outputs": [], |
283 | 310 | "source": [ |
284 | 311 | "# Create a base model\n", |
285 | 312 | "base_model = setup_model()\n", |
|
300 | 327 | ")\n", |
301 | 328 | "\n", |
302 | 329 | "clustered_model.summary()" |
303 | | - ] |
| 330 | + ], |
| 331 | + "execution_count": null, |
| 332 | + "outputs": [] |
304 | 333 | }, |
305 | 334 | { |
306 | 335 | "cell_type": "markdown", |
|
309 | 338 | "id": "hN0DgpvD5Add" |
310 | 339 | }, |
311 | 340 | "source": [ |
312 | | - "# Checkpoint and deserialize a clustered model" |
| 341 | + "## Checkpoint and deserialize a clustered model" |
313 | 342 | ] |
314 | 343 | }, |
315 | 344 | { |
|
324 | 353 | }, |
325 | 354 | { |
326 | 355 | "cell_type": "code", |
327 | | - "execution_count": null, |
328 | 356 | "metadata": { |
329 | | - "colab": {}, |
330 | 357 | "colab_type": "code", |
331 | | - "id": "w7P67mPk6RkQ" |
| 358 | + "id": "w7P67mPk6RkQ", |
| 359 | + "colab": {} |
332 | 360 | }, |
333 | | - "outputs": [], |
334 | 361 | "source": [ |
335 | 362 | "# Define the model.\n", |
336 | 363 | "base_model = setup_model()\n", |
|
346 | 373 | " loaded_model = tf.keras.models.load_model(keras_model_file)\n", |
347 | 374 | "\n", |
348 | 375 | "loaded_model.summary()" |
349 | | - ] |
| 376 | + ], |
| 377 | + "execution_count": null, |
| 378 | + "outputs": [] |
350 | 379 | }, |
351 | 380 | { |
352 | 381 | "cell_type": "markdown", |
|
355 | 384 | "id": "cUv-scK-N4sN" |
356 | 385 | }, |
357 | 386 | "source": [ |
358 | | - "# Improve the accuracy of the clustered model" |
| 387 | + "## Improve the accuracy of the clustered model" |
359 | 388 | ] |
360 | 389 | }, |
361 | 390 | { |
|
381 | 410 | "id": "4DXw7YbyN4sP" |
382 | 411 | }, |
383 | 412 | "source": [ |
384 | | - "# Deployment" |
| 413 | + "## Deployment" |
385 | 414 | ] |
386 | 415 | }, |
387 | 416 | { |
|
391 | 420 | "id": "5Y5zLfPzN4sQ" |
392 | 421 | }, |
393 | 422 | "source": [ |
394 | | - "## Export model with size compression" |
| 423 | + "### Export model with size compression" |
395 | 424 | ] |
396 | 425 | }, |
397 | 426 | { |
|
406 | 435 | }, |
407 | 436 | { |
408 | 437 | "cell_type": "code", |
409 | | - "execution_count": null, |
410 | 438 | "metadata": { |
411 | | - "colab": {}, |
412 | 439 | "colab_type": "code", |
413 | | - "id": "ZvuiCBsVN4sR" |
| 440 | + "id": "ZvuiCBsVN4sR", |
| 441 | + "colab": {} |
414 | 442 | }, |
415 | | - "outputs": [], |
416 | 443 | "source": [ |
417 | 444 | "model = setup_model()\n", |
418 | 445 | "clustered_model = cluster_weights(model, **clustering_params)\n", |
|
438 | 465 | " % (get_gzipped_model_size(clustered_model)))\n", |
439 | 466 | "print(\"Size of gzipped clustered model with stripping: %.2f bytes\" \n", |
440 | 467 | " % (get_gzipped_model_size(final_model)))" |
441 | | - ] |
442 | | - } |
443 | | - ], |
444 | | - "metadata": { |
445 | | - "celltoolbar": "Raw Cell Format", |
446 | | - "colab": { |
447 | | - "collapsed_sections": [], |
448 | | - "name": "clustering_comprehensive_guide.ipynb", |
449 | | - "private_outputs": true, |
450 | | - "provenance": [], |
451 | | - "toc_visible": true |
452 | | - }, |
453 | | - "kernelspec": { |
454 | | - "display_name": "Python 3", |
455 | | - "language": "python", |
456 | | - "name": "python3" |
457 | | - }, |
458 | | - "language_info": { |
459 | | - "codemirror_mode": { |
460 | | - "name": "ipython", |
461 | | - "version": 3 |
462 | | - }, |
463 | | - "file_extension": ".py", |
464 | | - "mimetype": "text/x-python", |
465 | | - "name": "python", |
466 | | - "nbconvert_exporter": "python", |
467 | | - "pygments_lexer": "ipython3", |
468 | | - "version": "3.6.9" |
| 468 | + ], |
| 469 | + "execution_count": null, |
| 470 | + "outputs": [] |
469 | 471 | } |
470 | | - }, |
471 | | - "nbformat": 4, |
472 | | - "nbformat_minor": 0 |
| 472 | + ] |
473 | 473 | } |
0 commit comments