{"id":15632709,"url":"https://github.com/sayakpaul/adventures-in-tensorflow-lite","last_synced_at":"2025-09-20T20:31:42.599Z","repository":{"id":40083182,"uuid":"259780923","full_name":"sayakpaul/Adventures-in-TensorFlow-Lite","owner":"sayakpaul","description":"This repository contains notebooks that show the usage of TensorFlow Lite for quantizing deep neural networks.","archived":false,"fork":false,"pushed_at":"2023-01-23T13:21:12.000Z","size":51528,"stargazers_count":172,"open_issues_count":2,"forks_count":34,"subscribers_count":12,"default_branch":"master","last_synced_at":"2024-12-28T03:39:03.806Z","etag":null,"topics":["inference","model-optimization","model-quantization","on-device-ml","post-training-quantization","pruning","quantization-aware-training","tensorflow-2","tensorflow-lite","tf-hub","tf-lite-model"],"latest_commit_sha":null,"homepage":"","language":"Jupyter Notebook","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/sayakpaul.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-04-29T00:07:54.000Z","updated_at":"2024-12-10T17:37:46.000Z","dependencies_parsed_at":"2023-02-12T23:32:07.352Z","dependency_job_id":null,"html_url":"https://github.com/sayakpaul/Adventures-in-TensorFlow-Lite","commit_stats":null,"previous_names":[],"tags_count":14,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sayakpaul%2FAdventures-in-TensorFlow-Lite","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sayakpaul%2FAdventures-in-TensorFlow-Lite/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sayakpaul%2FAdventures-in-TensorFlow-Lite/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sayakpaul%2FAdventures-in-TensorFlow-Lite/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sayakpaul","download_url":"https://codeload.github.com/sayakpaul/Adventures-in-TensorFlow-Lite/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":233686179,"owners_count":18714103,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["inference","model-optimization","model-quantization","on-device-ml","post-training-quantization","pruning","quantization-aware-training","tensorflow-2","tensorflow-lite","tf-hub","tf-lite-model"],"created_at":"2024-10-03T10:45:02.992Z","updated_at":"2025-09-20T20:31:35.328Z","avatar_url":"https://github.com/sayakpaul.png","language":"Jupyter Notebook","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Adventures-in-TensorFlow-Lite\nThis repository contains notebooks that show the usage of TensorFlow Lite (TF Lite) for quantizing deep neural networks in TensorFlow 2. ***It is currently under active development so, there might be some inconsistencies in the description below***. \n\n\u003cbr\u003e\u003cdiv align=\"center\"\u003e\n  \u003cimg src=\"https://i.ibb.co/mbT8CZX/tensorflow-lite-logo-social-1.png\"\u003e\u003c/img\u003e \u003cimg src=\"https://i.ibb.co/ZXtwJjV/Webp-net-resizeimage.png\"\u003e\u003c/img\u003e\n\u003c/div\u003e\u003cbr\u003e\n\n## About the notebooks\n- `A_tale_of_quantization.ipynb`: A comprehensive notebook showing different ways to quantize a model in `tf.keras` (with fine-tuning). It includes both **quantization-aware training** as well as **post-training quantization**. This notebook is accompanied by [this report](https://bit.ly/3dlCRSI) that has some additional details and performance considerations. The notebook is best referred with this report. \n- `Custom_Image_Classification_EdgeTPU.ipynb`: It shows how to use post-training quantization with a representative dataset to calibrate the dynamic ranges of activations. It also shows how to quantize the model in a way that is compatible with an Edge TPU USB Accelerator. \n- `DeepLabV3/DeepLab_TFLite_*.ipynb`: These notebooks show how to convert several DeepLabV3 based segmentation models (trained on the PASCAL VOC 2012, ADE20k, and CityScapes datasets) to TF Lite and run inference with them.\n- `ESRGAN_TFLite.ipynb`: Shows how to run inference with this ESRGAN module from TF Hub, convert it to TF Lite, run inference with the model. A bonus includes running inference with a distilled version of the main model (only 33 KB).\n- `Magenta_arbitrary_style_transfer_model_conversion.ipynb`: Shows to how apply apply different post-training quantization schemes to the [arbitrary style transfer model provided by Magenta](https://github.com/magenta/magenta/tree/f3b66aa1354cd933f0e9757a567cc9a3d2d03297/magenta/models/arbitrary_image_stylization). This generates image stylization models that produce higher-quality images than [these ones](https://tfhub.dev/google/magenta/arbitrary-image-stylization-v1-256/2). Inference notebook is available here - `Style_Transfer_Demo_InceptionV3.ipynb`. Additionally, in this notebook you can find how to run inference with the same TF Lite models but with dynamic shape support: `Style_Transfer_Demo_InceptionV3_Dynamic_Shape.ipynb`. \n- `Model_Pruning_in_Deep_Learning_with_tfmot.ipynb`: Shows how to use the pruning APIs of TensorFlow Model Optimization toolkit along with TF Lite.\n- `Selfie2Anime_TFLite(50_Checkpoints).ipynb`: Shows how to convert the [UGATIT model](https://github.com/taki0112/UGATIT) (also known as Selfie2Anime GAN) to TF Lite. Inference notebook is available [here](https://github.com/margaretmz/selfie2anime-e2e-tutorial/blob/master/ml/Selfie2Anime_Model_Conversion_50_Epochs.ipynb). Here's a multi-part tutorial of this project - [Part I](https://bit.ly/selfie2anime-1), [Part II](https://bit.ly/selfie2anime-2), [Part III](https://bit.ly/selfie2anime-3). This was jointly done with [Margaret](https://twitter.com/margaretmz). \n- `Semantic_Segmentation_+_Background_Removal_+_Style_Transfer.ipynb`: Presents a demo on how to use multiple TF Lite models to run segmentation, remove background, and apply stylization. \n- `Style_Transfer_Demo.ipynb` \u0026 `Style_Transfer_Demo_InceptionV3.ipynb`: Present interactive image stylization demos. \n- `TUNIT_Conversion_to_TF_Lite.ipynb`: Shows the PyTorch -\u003e TF Lite model conversion worflow (this is currently buggy).\n- `CartoonGAN_TFLite.ipynb`: Shows to how to convert the CartoonGAN model (proposed [here](https://bit.ly/cartoon-gan)) to a TF Lite model. Includes how to run inference as well. Here's the [official TensorFlow blog](https://github.com/SystemErrorWang/White-box-Cartoonization) in case you are interested to know more. \n- `EAST_TFLite.ipynb`: Shows how to convert the famous [EAST](https://arxiv.org/abs/1704.03155) model for text detection to TensorFlow Lite. \n- `Boundless_TFLite.ipynb`: Shows how to convert the famous [Boundless](https://arxiv.org/pdf/1908.07007.pdf) model for image extrapolation to TensorFlow Lite. \n\n## References\n- [Post-training quantization](https://www.tensorflow.org/lite/performance/post_training_quantization)\n- [Quantization aware training with TensorFlow Model Optimization Toolkit](https://blog.tensorflow.org/2020/04/quantization-aware-training-with-tensorflow-model-optimization-toolkit.html)\n\n## Accompanying materials\n- [Doing more with TF Lite](http://bit.ly/tfl-pune)\n- [Model optimization 101](http://bit.ly/mo-101)\n- [A few good stuff in TF Lite](http://bit.ly/stuff-tflite)\n- [A Tale of Model Quantization in TF Lite](https://bit.ly/3dlCRSI)\n- [Plunging into Model Pruning in Deep Learning](https://bit.ly/2AJ67W4)\n- [Optimizing MobileDet for Mobile Deployments](https://sayak.dev/mobiledet-optimization/)\n- [Peer Bonus Experiences: Building tiny models for the ML community with TensorFlow](https://opensource.googleblog.com/2020/10/peer-bonus-experiences-building-tiny.html)\n- [A Battle of Text Detectors for Mobile Deployments: CRAFT vs. EAST](https://sayak.dev/optimizing-text-detectors/)\n\n## Find the models on TF Hub\n\nhttps://tfhub.dev/s?publisher=sayakpaul\n\n![](https://i.ibb.co/zJSFjPs/Screen-Shot-2020-07-11-at-3-14-52-PM.png)\n\n## Other notable repositories covering similar things\n* [tulasiram58827/ocr_tflite](https://github.com/tulasiram58827/ocr_tflite)\n* [tulasiram58827/TTS_TFLite](https://github.com/tulasiram58827/TTS_TFLite)\n\n\n## Acknowledgements\n- [Arun Venkatesan](https://www.linkedin.com/in/arun-venkatesan-9317796/)\n- [Khanh LeViet](https://www.linkedin.com/in/lvgk/)\n- [Pulkit Bhuwalka](https://www.linkedin.com/in/pulkitbhuwalka/)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsayakpaul%2Fadventures-in-tensorflow-lite","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsayakpaul%2Fadventures-in-tensorflow-lite","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsayakpaul%2Fadventures-in-tensorflow-lite/lists"}