Skip to main content

CLI to convert TensorFlow models to TensorRT engines

Project description

keras2trt

Keras2TRT is a cli tool that is capable of converting keras saved_models to TensorRT engine. Currently supported conversions are:

  • Keras to ONNX
  • ONNX to TensorRT
  • Keras to TensorRT

NOTE: The CLI is tested converting image segmentation, classification and detection models.

Requirements

The following packages need to be installed to use the cli.

pip install nvidia-pyindex==1.0.9 \
&& pip install nvidia-tensorrt==8.4.2.4

NOTE: nvidia-tensorrt==8.4.2.4 is compatible with nvcr.io/nvidia/tritonserver:22.08-py3 docker image.

Installation

pip install keras2trt

Usage

Usage: keras2trt [OPTIONS] COMMAND [ARGS]...

Options:
  --install-completion [bash|zsh|fish|powershell|pwsh]
                                  Install completion for the specified shell.
  --show-completion [bash|zsh|fish|powershell|pwsh]
                                  Show completion for the specified shell, to
                                  copy it or customize the installation.
  --help                          Show this message and exit.

Commands:
  keras2onnx
  keras2trt
  onnx2trt
  version

keras2onnx

Usage: keras2trt keras2onnx [OPTIONS]

  Convert Keras model to ONNX model.

  - if --save-path does not have a suffix, ".onnx" suffix will be added to the
  saved ONNX model.

Options:
  --opset INTEGER     ONNX model opset.  [default: 15]
  --keras-model PATH  Path to the Keras model.  [required]
  --save-path PATH    Path to save the TensorRT engine.  [required]
  --help              Show this message and exit.

Example

keras2trt keras2onnx --keras-model models/inceptionv3 --opset 13 --save-path models/tf2onnx

Model path is a keras saved_model directory.

models/inceptionv3
├── assets
├── keras_metadata.pb
├── saved_model.pb
└── variables
    ├── variables.data-00000-of-00001
    └── variables.index

keras2trt

Usage: keras2trt keras2trt [OPTIONS]

  Convert Keras model to tensorrt engine.

  - If --save-path does not have a suffix, ".engine" suffix will be added to
  the saved TensorRT engine.

  - All min_shape, opt_shape, and max_shape need to be set for dynamic batch
  size.

  - If none of the shape arguments is set, the batch size will be set as 1.

Options:
  --opset INTEGER     ONNX model opset.  [default: 15]
  --in-shape TEXT     Model input shape.
  --min-shape TEXT    Minimum input shape for dynamic batch.
  --opt-shape TEXT    Optimal input shape for dynamic batch.
  --max-shape TEXT    Maximum input shape for dynamic batch.
  --keras-model PATH  Path to the Keras model.  [required]
  --save-path PATH    Path to save the TensorRT engine.  [required]
  --help              Show this message and exit.

Example

keras2trt keras2trt --opset 17 --in-shape "(1,256,256,3)" --keras-model models/inceptionv3 --save-path models/keras2trt.trt

keras2trt keras2trt --opset 15 --min-shape "(5,256,256,3)" --opt-shape "(15,256,256,3)" --max-shape "(30,256,256,3)" --keras-model models/inceptionv3 --save-path models/keras2trt

Model path is a keras saved_model directory.

models/inceptionv3
├── assets
├── keras_metadata.pb
├── saved_model.pb
└── variables
    ├── variables.data-00000-of-00001
    └── variables.index

onnx2trt

Usage: keras2trt onnx2trt [OPTIONS]

  Convert ONNX model to tensorrt engine.

  - If --save-path does not have a suffix, ".engine" suffix will be added to
  the saved TensorRT engine.

  - All min_shape, opt_shape, and max_shape need to be set for dynamic batch
  size.

  - If none of the shape arguments is set, the batch size will be set as 1.

Options:
  --in-shape TEXT    Model input shape.
  --min-shape TEXT   Minimum input shape for dynamic batch.
  --opt-shape TEXT   Optimal input shape for dynamic batch.
  --max-shape TEXT   Maximum input shape for dynamic batch.
  --onnx-model PATH  Path to the ONNX model.  [required]
  --save-path PATH   Path to save the TensorRT engine.  [required]
  --help             Show this message and exit.

Example

keras2trt onnx2trt --in-shape "(1,256,256,3)" --onnx-model models/tf2onnx.onnx --save-path models/onnx2trt

keras2trt onnx2trt --min-shape "(5,256,256,3)" --opt-shape "(15,256,256,3)" --max-shape "(30,256,256,3)" --onnx-model models/tf2onnx.onnx --save-path models/onnx2trt

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

keras2trt-0.5.0.tar.gz (6.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

keras2trt-0.5.0-py3-none-any.whl (6.6 kB view details)

Uploaded Python 3

File details

Details for the file keras2trt-0.5.0.tar.gz.

File metadata

  • Download URL: keras2trt-0.5.0.tar.gz
  • Upload date:
  • Size: 6.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.3.1 CPython/3.9.12 Linux/5.15.79.1-microsoft-standard-WSL2

File hashes

Hashes for keras2trt-0.5.0.tar.gz
Algorithm Hash digest
SHA256 3f857de19c869a27656e9b1e4e4e3758a20f3bb95b2a20e3b816a01f05939283
MD5 92ae1533664dc4f14832cfbd9ec92dd8
BLAKE2b-256 9a60c200e39d66913b827c7cc0628212bbc0d8929a2b6e451b07f59b7f131ca3

See more details on using hashes here.

File details

Details for the file keras2trt-0.5.0-py3-none-any.whl.

File metadata

  • Download URL: keras2trt-0.5.0-py3-none-any.whl
  • Upload date:
  • Size: 6.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.3.1 CPython/3.9.12 Linux/5.15.79.1-microsoft-standard-WSL2

File hashes

Hashes for keras2trt-0.5.0-py3-none-any.whl
Algorithm Hash digest
SHA256 3e90043a453379a6db27a30ecf67644016bd5858f32b622278fa4cf49e89ec20
MD5 04970db9a19243b0844e5bb4265011db
BLAKE2b-256 8e9433fa6488e058935238a6c53d618065313a302e08460da9214fc83787a0ec

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page