Tensor RT学习笔记(四)

简介:

构建阶段:
在构建阶段,TensorRT采用网络定义,执行优化并生成推理引擎。
构建阶段可能需要相当长的时间,尤其是在嵌入式平台上运行时。 因此,典型的应用程序将构建一次引擎,然后将其序列化以备后用。
构建阶段在层图上执行以下优化::

  • 消除其输出不使用卷积,偏差和ReLU操作融合的图层
  • 具有足够相似参数和相同源张量的操作聚合(例如,GoogleNet v5初始模块中的1x1卷积)
  • 通过将层输出指向正确的最终目的地来合并连接层。

此外,构建阶段还在虚拟数据上运行图层以从其内核目录中选择最快的,并在适当的情况下执行加权预格式化和内存优化。
执行阶段:
在执行阶段,运行以下任务:

  • 运行时执行优化的引擎。
  • 引擎使用GPU上的输入和输出缓冲区运行推理任务。

命令行包装器( Command Line Wrapper):
样本目录中包含一个名为giexec的TensorRT命令行包装器。 它对基于随机数据的网络进行基准测试和从这些模型生成序列化引擎非常有用。
命令行参数如下所示:

Mandatory params :
--deploy = <file> Caffe deploy file
--output = <name> Output blob name(can be specified
    multiple times)
    Optional params :
--model = <file> Caffe model file(default = no model,
    random weights
    used)
    --batch = N Set batch size(default = 1)
    --device = N Set cuda device to N(default = 0)
    --iterations = N Run N iterations(default = 10)
    --avgRuns = N Set avgRuns to N - perf is measured as an
    average of
    avgRuns(default = 10)
    --workspace = N Set workspace size in megabytes(default =
        16)
    --half2 Run in paired fp16 mode(default = false)
    --int8 Run in int8 mode(default = false)
    --verbose Use verbose logging(default = false)
    --hostTime Measure host time rather than GPU time
    (default =
        false)
    --engine = <file> Generate a serialized GIE engine
    --calib = <file> Read INT8 calibration cache file

例如:

giexec --deploy=mnist.prototxt --model=mnist.caffemodel --
output=prob

如果没有提供模型,则生成随机权重。
TensorRT Lite:
包含在Python API中的是一个高度抽象的界面,称为TensorRT Lite。 TensorRT Lite API在构建引擎和执行推理时处理几乎所有事情,因此用户只需创建引擎并开始处理数据即可。
TensorRT Lite API位于tensorrt.lite中,包含一个名为Engine的类。 引擎构造函数接受模型定义以及输入和输出图层,并构建围绕它的完整引擎以进行推理。
在内部,Lite引擎为您创建记录器,TensorRT引擎,运行时和上下文,然后为引擎分配GPU内存。
自定义记录器,插件,校准器和分析器等功能可以从构造函数传递。
timg

目录
相关文章
|
存储 PyTorch 算法框架/工具
Tensor to img && imge to tensor (pytorch的tensor转换)
Tensor to img && imge to tensor (pytorch的tensor转换)
|
1天前
|
存储 PyTorch 算法框架/工具
torch.Storage()是什么?和torch.Tensor()有什么区别?
torch.Storage()是什么?和torch.Tensor()有什么区别?
7 1
|
API 数据格式
TensorFlow2._:model.summary() Output Shape为multiple解决方法
TensorFlow2._:model.summary() Output Shape为multiple解决方法
193 0
TensorFlow2._:model.summary() Output Shape为multiple解决方法
torch.argmax(dim=1)用法
)torch.argmax(input, dim=None, keepdim=False)返回指定维度最大值的序号;
545 0
|
并行计算 Python
TypeError: can‘t convert CUDA tensor to numpy. Use Tensor.cpu() to copy the tensor to host memory
运行程序,出现报错信息 TypeError: can't convert CUDA tensor to numpy. Use Tensor.cpu() to copy the tensor to host memory first.。
249 0
|
PyTorch 算法框架/工具 异构计算
Pytorch出现RuntimeError: Input type (torch.cuda.FloatTensor) and weight type (torch.FloatTensor)
这个问题的主要原因是输入的数据类型与网络参数的类型不符。
194 0
|
PyTorch 算法框架/工具
torch.split 的用法
这将返回一个元组,包含 3 个大小分别为 (6, 2)、(6, 2) 和 (6, 4) 的张量。 需要注意的是,当给定的拆分大小不等于张量在指定维度上的大小时,torch.split() 会引发一个异常。
374 0
怎么将[tensor([[ 1, 2]]), tensor([[5, 6]]), tensor([[9, 10]])] 合并成 tensor([[1,2],[3,4],[5,6]])
可以先使用 torch.cat() 函数将列表中的张量在第0维(行)上进行拼接,然后再使用 .view() 函数将形状调整为需要的形状。
129 0
|
PyTorch 算法框架/工具
pytorch报错 RuntimeError: The size of tensor a (25) must match the size of tensor b (50) at non-singleton dimension 1 怎么解决?
这个错误提示表明,在进行某个操作时,张量a和b在第1个非单例维(即除了1以外的维度)上的大小不一致。例如,如果a是一个形状为(5, 5)的张量,而b是一个形状为(5, 10)的张量,则在第二个维度上的大小不匹配。
3118 0
torch中如何将tensor([[1, 2, 3]]) 和 tensor([4]) 合并成 tensor([[1,2,3,4]])
可以使用 torch.cat() 方法将两个张量沿着指定的维度进行拼接
387 0