本文整理汇总了Python中tensorrt.__version__方法的典型用法代码示例。如果您正苦于以下问题:Python tensorrt.__version__方法的具体用法?Python tensorrt.__version__怎么用?Python tensorrt.__version__使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tensorrt
的用法示例。
在下文中一共展示了tensorrt.__version__方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: build_engine
# 需要导入模块: import tensorrt [as 别名]
# 或者: from tensorrt import __version__ [as 别名]
def build_engine(onnx, verbose=False):
"""Build TensorRT engine from the ONNX model."""
TRT_LOGGER = trt.Logger(trt.Logger.VERBOSE) if verbose else trt.Logger()
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 # 1GB
builder.max_batch_size = MAX_BATCH
builder.fp16_mode = FP16_MODE
with open(onnx, 'rb') as model:
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
if trt.__version__[0] >= '7':
# set input to batch size 1
shape = list(network.get_input(0).shape)
shape[0] = 1
network.get_input(0).shape = shape
return builder.build_cuda_engine(network)
示例2: _load_plugins
# 需要导入模块: import tensorrt [as 别名]
# 或者: from tensorrt import __version__ [as 别名]
def _load_plugins(self):
if trt.__version__[0] < '7':
ctypes.CDLL("ssd/libflattenconcat.so")
trt.init_libnvinfer_plugins(self.trt_logger, '')
示例3: main
# 需要导入模块: import tensorrt [as 别名]
# 或者: from tensorrt import __version__ [as 别名]
def main():
parser = argparse.ArgumentParser()
parser.add_argument('model', type=str, choices=list(MODEL_SPECS.keys()))
args = parser.parse_args()
# initialize
if trt.__version__[0] < '7':
ctypes.CDLL(LIB_FILE)
TRT_LOGGER = trt.Logger(trt.Logger.INFO)
trt.init_libnvinfer_plugins(TRT_LOGGER, '')
# compile the model into TensorRT engine
model = args.model
spec = MODEL_SPECS[model]
dynamic_graph = add_plugin(
gs.DynamicGraph(spec['input_pb']),
model,
spec)
_ = uff.from_tensorflow(
dynamic_graph.as_graph_def(),
output_nodes=['NMS'],
output_filename=spec['tmp_uff'],
text=True,
debug_mode=DEBUG_UFF)
with trt.Builder(TRT_LOGGER) as builder, builder.create_network() as network, trt.UffParser() as parser:
builder.max_workspace_size = 1 << 28
builder.max_batch_size = 1
builder.fp16_mode = True
parser.register_input('Input', INPUT_DIMS)
parser.register_output('MarkOutput_0')
parser.parse(spec['tmp_uff'], network)
engine = builder.build_cuda_engine(network)
buf = engine.serialize()
with open(spec['output_bin'], 'wb') as f:
f.write(buf)
示例4: build_engine
# 需要导入模块: import tensorrt [as 别名]
# 或者: from tensorrt import __version__ [as 别名]
def build_engine(onnx_file_path, engine_file_path, verbose=False):
"""Takes an ONNX file and creates a TensorRT engine."""
TRT_LOGGER = trt.Logger(trt.Logger.VERBOSE) if verbose else trt.Logger()
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 << 28
builder.max_batch_size = 1
builder.fp16_mode = True
#builder.strict_type_constraints = True
# Parse model file
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
if trt.__version__[0] >= '7':
# The actual yolov3.onnx is generated with batch size 64.
# Reshape input to batch size 1
shape = list(network.get_input(0).shape)
shape[0] = 1
network.get_input(0).shape = shape
print('Completed parsing of ONNX file')
print('Building an engine; this may take a while...')
engine = builder.build_cuda_engine(network)
print('Completed creating engine')
with open(engine_file_path, 'wb') as f:
f.write(engine.serialize())
return engine
示例5: infer_with_trt
# 需要导入模块: import tensorrt [as 别名]
# 或者: from tensorrt import __version__ [as 别名]
def infer_with_trt(img, model):
"""Inference the image with TensorRT engine."""
import pycuda.autoinit
import pycuda.driver as cuda
import tensorrt as trt
TRT_LOGGER = trt.Logger(trt.Logger.INFO)
with open(model, 'rb') as f, trt.Runtime(TRT_LOGGER) as runtime:
engine = runtime.deserialize_cuda_engine(f.read())
assert len(engine) == 2, 'ERROR: bad number of bindings'
host_input, cuda_input, host_output, cuda_output = init_trt_buffers(
cuda, trt, engine)
stream = cuda.Stream()
context = engine.create_execution_context()
context.set_binding_shape(0, (1, 224, 224, 3))
np.copyto(host_input, img.ravel())
cuda.memcpy_htod_async(cuda_input, host_input, stream)
if trt.__version__[0] >= '7':
context.execute_async_v2(bindings=[int(cuda_input), int(cuda_output)],
stream_handle=stream.handle)
else:
context.execute_async(bindings=[int(cuda_input), int(cuda_output)],
stream_handle=stream.handle)
cuda.memcpy_dtoh_async(host_output, cuda_output, stream)
stream.synchronize()
return host_output
示例6: __init__
# 需要导入模块: import tensorrt [as 别名]
# 或者: from tensorrt import __version__ [as 别名]
def __init__(self, model, input_shape, category_num=80):
"""Initialize TensorRT plugins, engine and conetxt."""
self.model = model
self.input_shape = input_shape
h, w = input_shape
# filters count
filters = (category_num + 5) * 3
if 'tiny' in model:
self.output_shapes = [(1, filters, h // 32, w // 32),
(1, filters, h // 16, w // 16)]
else:
self.output_shapes = [(1, filters, h // 32, w // 32),
(1, filters, h // 16, w // 16),
(1, filters, h // 8, w // 8)]
if 'tiny' in model:
postprocessor_args = {
# A list of 2 three-dimensional tuples for the Tiny YOLO masks
'yolo_masks': [(3, 4, 5), (0, 1, 2)],
# A list of 6 two-dimensional tuples for the Tiny YOLO anchors
'yolo_anchors': [(10, 14), (23, 27), (37, 58),
(81, 82), (135, 169), (344, 319)],
# Threshold for non-max suppression algorithm, float
# value between 0 and 1
'nms_threshold': 0.5,
'yolo_input_resolution': input_shape,
'category_num': category_num
}
else:
postprocessor_args = {
# A list of 3 three-dimensional tuples for the YOLO masks
'yolo_masks': [(6, 7, 8), (3, 4, 5), (0, 1, 2)],
# A list of 9 two-dimensional tuples for the YOLO anchors
'yolo_anchors': [(10, 13), (16, 30), (33, 23),
(30, 61), (62, 45), (59, 119),
(116, 90), (156, 198), (373, 326)],
# Threshold for non-max suppression algorithm, float
# value between 0 and 1
# between 0 and 1
'nms_threshold': 0.5,
'yolo_input_resolution': input_shape,
'category_num': category_num
}
self.postprocessor = PostprocessYOLO(**postprocessor_args)
self.trt_logger = trt.Logger(trt.Logger.INFO)
self.engine = self._load_engine()
self.context = self._create_context()
self.inputs, self.outputs, self.bindings, self.stream = \
allocate_buffers(self.engine)
self.inference_fn = do_inference if trt.__version__[0] < '7' \
else do_inference_v2