Unable to convert Keras model to TensorRT runtime

I’m trying to convert a Keras YoloV3 model (i.e. https://github.com/qqwweee/keras-yolo3) to a format that can be loaded with DeepStream’s nvinfer element.

I’ve seen the samples at https://github.com/NVIDIA-AI-IOT/deepstream_reference_apps as well as https://docs.nvidia.com/deeplearning/sdk/tensorrt-sample-support-guide/index.html#yolov3_onnx, so I know that it is technically possible, but I haven’t yet been successful with the conversion.

I’ve tried permutations of freezing the graph, converting to UFF/ONNX, using https://github.com/onnx/tensorflow-onnx, but every time there was a different error.

What I’d like to know is: what the best approach is to go from a Keras model to inference in DeepStream?


It’s recommended to use UFF interface rather than ONNX since UFF is our format specified for TensorFlow.
Once having a UFF model, there is a sample in deepstream package for the UFF based model:

To enable YOLO, it is required some plugin implementation since some non-supported layers inside.
We have an plugin implementation for YOLO in deepstream_reference_apps and you can integrate it directly into your application.


Solution 1:
Can you refer to https://github.com/NVIDIA-AI-IOT/deepstream_reference_apps/tree/master/yolo to deloy yoloV3 detection? It does not use uff/onnx/caffe parser but use tensorRT API directly to build network.

Solution 2:

  1. Using tensorflow’s graph_utils, graph_io API to convert keras model to .pb.
    If the model is trained in NHWC, we should make sure NCHW architecture could consume the pretrained weights. Generally, most layers could work well directly in NHWC -> NCHW conversion except Reshape, Flatten, Dense and Softmax applied to feature map.

  2. Converting .pb to .uff using uff converter
    And map all the tf nodes which are not supported by TensorRT directly to plugin node.
    Refer to sources/objectDetector_FasterRCNN

1 Like

Thanks for the quick answers! Is there a process to figure out which layers in a model are supported by uff and what I need custom plugins for?

TensorRT provides convert-to-uff tool which will return error and which custom plugins need to implement.


You can also refer to tensorRT sample sampleUffSSD “README.md” and “config.py”

Thank you both for your help!