Package Installation

Learn to install the Python dependencies to export PyTorch models into other formats.

This lesson will illustrate how to install Python dependencies in our virtual environment.

We’ll need the following Python packages to export our models into:

  • ONNX models
  • TensorFlow models in SavedModel format
  • TFLite models

PyTorch

We can easily install the stable version of PyTorch as follows:

pip install torch

TensorFlow

To install TensorFlow, use the following command:

pip install tensorflow

ONNX

The onnx package is useful for verifying the underlying protocol buffer (protobuf) of our model. Install it as follows:

pip install onnx

ONNXRuntime

For inference using the ONNX model, we’ll need the onnxruntime package. Run the following command to install it:

pip install onnxruntime

ONNX-TensorFlow

We cannot directly convert the ONNX model into a TFLite model. The onnx-tensorflow is one of the TensorFlow converter projects. It provides the TensorFlow backend for ONNX.

Install it as follows:

git clone https://github.com/onnx/onnx-tensorflow.git && cd onnx-tensorflow
pip install -e .

Get hands-on with 1200+ tech skills courses.