Generate .engine file from .uff file

I tried this python code to do the generation but failed. Please help.

import uff
import tensorrt as trt
import graphsurgeon as gs

uff_model_path = ‘./model.uff’
TRT_LOGGER = trt.Logger(trt.Logger.WARNING)
trt.init_libnvinfer_plugins(TRT_LOGGER, ‘’)

trt_runtime = trt.Runtime(TRT_LOGGER)

with trt.Builder(TRT_LOGGER) as builder, builder.create_network() as network, trt.UffParser() as parser:
builder.max_workspace_size = 1 << 30
builder.fp16_mode = True
builder.max_batch_size = 1
parser.register_input(‘Placeholder_1’, (1, 416, 416, 3))
parser.parse(uff_model_path, network)

print(‘Building TensorRT engine, this may take a few minutes…’)
trt_engine = builder.build_cuda_engine(network)

with open(“model.engine”, “wb”) as f:

Error message:
2020-08-10 12:51:25.168202: I tensorflow/stream_executor/platform/default/] Successfully opened dynamic library
WARNING:tensorflow:Deprecation warnings have been disabled. Set TF_ENABLE_DEPRECATION_WARNINGS=1 to re-enable them.
[TensorRT] ERROR: UffParser: Validator error: yolov3/yolov3_head/Conv_5/BatchNorm/cond/Switch: Unsupported operation _Switch
Building TensorRT engine, this may take a few minutes…
Segmentation fault (core dumped)


[TensorRT] ERROR: UffParser: Validator error: .../Switch: Unsupported operation _Switch

This error indicates that the switch operation is not supported by the uff parser.
You can find the detail supported operation here:

For YOLO model, you can check our Deepstream sample which demonstrates the conversion from darknet into TensorRT: