def build_engine():
            """Takes an ONNX file and creates a TensorRT engine to run inference with"""
            with trt.Builder(TRT_LOGGER) as builder, \
                builder.create_network(EXPLICIT_BATCH) as network, \
                trt.OnnxParser(network, TRT_LOGGER) as parser:
                builder.max_workspace_size = 1 << 30
                builder.max_batch_size = 1
                # Parse model file
                if not os.path.exists(onnx_file_path):
                    print(
                        'ONNX file {} not found, please run yolov3_to_onnx.py first to generate it.'
                        .format(onnx_file_path))
                    exit(0)
                print('Loading ONNX file from path {}...'.format(
                    onnx_file_path))
                with open(onnx_file_path, 'rb') as model:
                    print('Beginning ONNX file parsing')
                    if not parser.parse(model.read()):
                        print('ERROR: Failed to parse the ONNX file.')
                        for error in range(parser.num_errors):
                            print(parser.get_error(error))
                        return None

                network.get_input(0).shape = input_shape
                #network.get_output(0).shape = [1, 19, 512, 1024]
                print('Completed parsing of ONNX file')
                print(
                    'Building an engine from file {}; this may take a while...'.
                    format(onnx_file_path))
                engine = builder.build_cuda_engine(network)
                print("Completed creating Engine")

                if engine_file_path != "":
                    with open(engine_file_path, "wb") as f:
                        f.write(engine.serialize())
                    print("Save trt model in {}".format(engine_file_path))
                return engine
Takes an ONNX file and creates a TensorRT engine to run inference with
deploy/python/infer_onnx_trt.py