I am trying to follow the instructions here: https://docs.nvidia.com/deeplearning/sdk/tensorrt-developer-guide/index.html#import_tf_python
I have converted my frozen tensorflow graph (pre-trained keras mobilenetv2) to uff using:
$ python /usr/lib/python3.6/dist-packages/uff/bin/convert_to_uff.py -o model.uff frozen_graph.pb
It outputs the information about the input and output nodes. I copied those names down and use them in the builder code.
In my jupyter notebook I have the following code:
import tensorrt as trt
model_file = 'model.uff'
TRT_LOGGER = trt.Logger(trt.Logger.WARNING)
with trt.Builder(TRT_LOGGER) as builder, builder.create_network() as network, trt.UffParser() as parser:
parser.register_input("input_2", (-1, 224, 224, 3))
parser.register_output("Logits/Softmax")
parser.parse(model_file, network)
However, whenever I try and run this code my kernel restarts. It won’t ever run. Any ideas?
My pb file, uff file, and notebook file can be found here: GitHub - stonepreston/tf-to-trt-help
Also, why arent the tensorRT samples available on the nano? They arent in /usr/lib/python3.6/dist-packages/tensorrt? Where can I find them?
Edit: So i moved everything under the with and added a few more lines to construct the engine. However it looks like the engine is not being constructed correctly.
import tensorrt as trt
model_file = 'model.uff'
TRT_LOGGER = trt.Logger(trt.Logger.WARNING)
with trt.Builder(TRT_LOGGER) as builder, builder.create_network() as network, trt.UffParser() as parser:
parser.register_input("input_2", (-1, 224, 224, 3))
parser.register_output("Logits/Softmax")
parser.parse(model_file, network)
builder.max_batch_size = max_batch_size
builder.max_workspace_size = 1 << 20
engine = builder.build_cuda_engine(network)
with open(“sample.engine”, “wb”) as f:
f.write(engine.serialize())
I get the error ‘NoneType’ objects has no attribute ‘serialize’ with the engine object.