Run TF-TRT graph through TF C++ API

I want to use TF-TRT Python API to optimize the graph,
and then use TF C++ API for deployment on NVIDIA Xavier.
Is TF C++ API capable of running TF-TRT optimized graph?

Also, what is the preferred way of deploying TRT optimized model on Jetson?
According to item 8.1 of
“Note: The UFF Parser which is used to parse a network in UFF format will be deprecated in a future release. The recommended method of importing TensorFlow models to TensorRT is using TensorFlow with TensorRT (TF-TRT).”
While item 7.2 says to use TRT C++ API with UFF as an intermediate format.


You can convert the model to TRT using TF-TRT and serialize it to a .plan file. Then deserialize the .plan file using the C++ API.


Thanks for the links but still did not understand either.
Until Now, I had TF and TRT on my workstation with Tesla v-100
The workflow was:

  1. Build model and parse to UFF on workstation
  1. Convert to engine and the serialize on one xavier TRT C++ API
  ICudaEngine *engine = builder->buildCudaEngine(*network);
  IHostMemory *serializedEngine = engine->serialize(); 
  planFile.write((char *)serializedEngine->data(), serializedEngine->size()); 
  1. Deploy and deserialize on multiple Xavier TRT C++ API
IRuntime* runtime = createInferRuntime(gLogger);
ICudaEngine* engine = runtime->deserializeCudaEngine(modelData, modelSize, nullptr);

Now if I use the TF-TRT api on my workstation with

  1. Is the model serialized?

  2. Can I deserialize on Xavier directly with TRT C++ API?
    you write :
    Note: Serialized engines are not portable across platforms or TensorRT versions. Engines are specific to the exact GPU model they were built on (in addition to platforms and the TensorRT version).

  3. If not can you please indicate the steps?
    a. how/where to build the engine?
    b. how/where to serailize?

I’m a little bit confused here …

states that “This feature requires that your entire model converts to TensorRT”.
What about nets that don’t convert entirely, like SSD+Mobilenet?
Can I just load and run TF-TRT optimized graph through TF C++ API in a standard way (I know that I need to build TF C++ API from source on Xavier).

Can I just load and run TF-TRT optimized graph through TF C++ API in a standard way

Could you answer this question? Is there C++ sample code to run TF-TRT ?


Would that be possible to have samples for C++ like requested above?

Also, when we do following builds of TensorFlow,

  • bazel build --config=tensorrt //
  • bazel build --config=tensorrt //tensorflow/tools/lib_package:libtensorflow

Are the generated C/C++ libraries have TensorRT support as well or it is only the pip package?

Thanks in advance!

We are working on a C++ sample for TF-TRT.
Please stay tuned.

It will be published soon at

1 Like

Thanks for the update!


want to ask the same question " Can I just load and run TF-TRT optimized graph through TF C++ API in a standard way ?" and any update on C++ sample for TF-TRT?

1 Like

Is this example already online?
Actually, I ask this because my model did not work with pure TensorRT 5 like on the jetson nano, and I wanted to try with tensorflow.

It has been 6 months since this post and there is still no C++ example in the TF-TRT repository. Is this ever going to happen?


Yeah I am starting to look into TF-TRT too, I was able to convert/build an object detection (od api2) model, but I cant see any clear c++ sample for infering it.