Book Image

Production-Ready Applied Deep Learning

By : Tomasz Palczewski, Jaejun (Brandon) Lee, Lenin Mookiah
Book Image

Production-Ready Applied Deep Learning

By: Tomasz Palczewski, Jaejun (Brandon) Lee, Lenin Mookiah

Overview of this book

Machine learning engineers, deep learning specialists, and data engineers encounter various problems when moving deep learning models to a production environment. The main objective of this book is to close the gap between theory and applications by providing a thorough explanation of how to transform various models for deployment and efficiently distribute them with a full understanding of the alternatives. First, you will learn how to construct complex deep learning models in PyTorch and TensorFlow. Next, you will acquire the knowledge you need to transform your models from one framework to the other and learn how to tailor them for specific requirements that deployment environments introduce. The book also provides concrete implementations and associated methodologies that will help you apply the knowledge you gain right away. You will get hands-on experience with commonly used deep learning frameworks and popular cloud services designed for data analytics at scale. Additionally, you will get to grips with the authors’ collective knowledge of deploying hundreds of AI-based services at a large scale. By the end of this book, you will have understood how to convert a model developed for proof of concept into a production-ready application optimized for a particular production setting.
Table of Contents (19 chapters)
1
Part 1 – Building a Minimum Viable Product
6
Part 2 – Building a Fully Featured Product
10
Part 3 – Deployment and Maintenance

Conversion between TensorFlow and ONNX

First, we will look at the conversion between TF and ONNX. We will break down the process into two: converting a TF model into an ONNX model and converting an ONNX model back into a TF model.

Converting a TensorFlow model into an ONNX model

tf2onnx is used to convert a TF model into an ONNX model (https://github.com/onnx/tensorflow-onnx). This library supports both versions of TF (version 1 as well as version 2). Furthermore, conversions to deployment-specific TF formats such as TensorFlow.js and TensorFlow Lite are also available.

To convert a TF model generated using the saved_model module into an ONNX model, you can use the tf2onnx.convert module, as follows:

python -m tf2onnx.convert --saved-model tensorflow_model_path --opset 9 --output model.onnx  

In the preceding command, tensorflow-model-path points to a TF model saved on disk, --output defines where the generated ONNX model will be saved, and --opset sets ONNX...