INetworkDefinition¶
- class tensorrt.INetworkDefinition¶
表示 TensorRT 网络,Builder 可以从中构建 Engine
- 变量:
num_layers –
int
网络中的层数。num_inputs –
int
网络的输入数量。num_outputs –
int
网络的输出数量。name –
str
网络的名称。这用于将其与构建的引擎关联。名称长度必须最多为 128 个字符。TensorRT 不使用此字符串,只是将其存储为引擎的一部分,以便在运行时检索。默认情况下,将生成构建器唯一的名称。has_implicit_batch_dimension –
bool
[已弃用] 在 TensorRT 10.0 中已弃用。由于已删除隐式批处理维度支持,因此始终为 false。error_recorder –
IErrorRecorder
应用程序实现的 TensorRT 对象错误报告接口。
- 标志:
- int:
为此网络设置的
NetworkDefinitionCreationFlag
的位集。
- __del__(self: tensorrt.tensorrt.INetworkDefinition) None ¶
- __exit__(exc_type, exc_value, traceback)¶
上下文管理器已弃用,不起作用。当引用计数达到 0 时,对象会自动释放。
- __getitem__(self: tensorrt.tensorrt.INetworkDefinition, arg0: int) tensorrt.tensorrt.ILayer ¶
- __init__(*args, **kwargs)¶
- __len__(self: tensorrt.tensorrt.INetworkDefinition) int ¶
- add_activation(self: tensorrt.tensorrt.INetworkDefinition, input: tensorrt.tensorrt.ITensor, type: tensorrt.tensorrt.ActivationType) tensorrt.tensorrt.IActivationLayer ¶
向网络添加激活层。有关更多信息,请参见
IActivationLayer
。- 参数:
input – 层的输入张量。
type – 要应用的激活函数类型。
- 返回值:
新的激活层,如果无法创建,则为
None
。
- add_assertion(self: tensorrt.tensorrt.INetworkDefinition, condition: tensorrt.tensorrt.ITensor, message: str) tensorrt.tensorrt.IAssertionLayer ¶
添加断言层。有关更多信息,请参见
IAssertionLayer
。- 参数:
condition – 层的条件张量。
message – 断言失败时要打印的消息。
- 返回值:
新的断言层,如果无法创建,则为
None
。
- add_cast(self: tensorrt.tensorrt.INetworkDefinition, input: tensorrt.tensorrt.ITensor, to_type: tensorrt.tensorrt.DataType) tensorrt.tensorrt.ICastLayer ¶
添加类型转换层。有关更多信息,请参见
ICastLayer
。- 参数:
input – 层的输入张量。
to_type – 输出张量应转换为的数据类型。
- 返回值:
新的类型转换层,如果无法创建,则为
None
。
- add_concatenation(self: tensorrt.tensorrt.INetworkDefinition, inputs: List[tensorrt.tensorrt.ITensor]) tensorrt.tensorrt.IConcatenationLayer ¶
向网络添加连接层。请注意,除了通道维度外,所有张量必须具有相同的维度。有关更多信息,请参见
IConcatenationLayer
。- 参数:
inputs – 层的输入张量。
- 返回值:
新的连接层,如果无法创建,则为
None
。
- add_constant(self: tensorrt.tensorrt.INetworkDefinition, shape: tensorrt.tensorrt.Dims, weights: tensorrt.tensorrt.Weights) tensorrt.tensorrt.IConstantLayer ¶
向网络添加常量层。有关更多信息,请参见
IConstantLayer
。- 参数:
shape – 常量的形状。
weights – 常数值,表示为权重。
- 返回值:
新的常量层,如果无法创建,则为
None
。
- add_convolution_nd(self: tensorrt.tensorrt.INetworkDefinition, input: tensorrt.tensorrt.ITensor, num_output_maps: int, kernel_shape: tensorrt.tensorrt.Dims, kernel: tensorrt.tensorrt.Weights, bias: tensorrt.tensorrt.Weights = None) tensorrt.tensorrt.IConvolutionLayer ¶
向网络添加多维卷积层。有关更多信息,请参见
IConvolutionLayer
。- 参数:
input – 卷积的输入张量。
num_output_maps – 卷积的输出特征图的数量。
kernel_shape – 卷积核的维度。
kernel – 卷积的内核权重。
bias – 卷积的可选偏置权重。
- 返回值:
新的卷积层,如果无法创建,则为
None
。
- add_cumulative(self: tensorrt.tensorrt.INetworkDefinition, input: tensorrt.tensorrt.ITensor, axis: tensorrt.tensorrt.ITensor, op: tensorrt.tensorrt.CumulativeOperation, exclusive: bool, reverse: bool) tensorrt.tensorrt.ICumulativeLayer ¶
向网络添加累积层。有关更多信息,请参见
ICumulativeLayer
。- 参数:
input – 层的输入张量。
axis – 应用累积运算的轴张量。目前,它必须是构建时常量 0 维形状张量。
op – 要执行的缩减运算。
exclusive – 布尔值,指定是互斥累积还是包含累积。
reverse – 布尔值,指定是否应向后应用累积。
- 返回值:
新的累积层,如果无法创建,则为
None
。
- add_deconvolution_nd(self: tensorrt.tensorrt.INetworkDefinition, input: tensorrt.tensorrt.ITensor, num_output_maps: int, kernel_shape: tensorrt.tensorrt.Dims, kernel: tensorrt.tensorrt.Weights, bias: tensorrt.tensorrt.Weights = None) tensorrt.tensorrt.IDeconvolutionLayer ¶
向网络添加多维反卷积层。有关更多信息,请参见
IDeconvolutionLayer
。- 参数:
input – 层的输入张量。
num_output_maps – 输出特征图的数量。
kernel_shape – 卷积核的维度。
kernel – 卷积的内核权重。
bias – 卷积的可选偏置权重。
- 返回值:
新的反卷积层,如果无法创建,则为
None
。
- add_dequantize(*args, **kwargs)¶
重载函数。
add_dequantize(self: tensorrt.tensorrt.INetworkDefinition, input: tensorrt.tensorrt.ITensor, scale: tensorrt.tensorrt.ITensor) -> tensorrt.tensorrt.IDequantizeLayer
向网络添加反量化层。有关更多信息,请参见
IDequantizeLayer
。- 参数 input:
要量化的张量。
- 参数 scale:
具有比例系数的张量。
- 参数 output_type:
输出张量的数据类型。指定 output_type 是可选的(默认值为 tensorrt.float32)。
- 返回值:
新的反量化层,如果无法创建,则为
None
。
add_dequantize(self: tensorrt.tensorrt.INetworkDefinition, input: tensorrt.tensorrt.ITensor, scale: tensorrt.tensorrt.ITensor, output_type: tensorrt.tensorrt.DataType) -> tensorrt.tensorrt.IDequantizeLayer
向网络添加反量化层。有关更多信息,请参见
IDequantizeLayer
。- 参数 input:
要量化的张量。
- 参数 scale:
具有比例系数的张量。
- 参数 output_type:
输出张量的数据类型。指定 output_type 是可选的(默认值为 tensorrt.float32)。
- 返回值:
新的反量化层,如果无法创建,则为
None
。
- add_dynamic_quantize(self: tensorrt.tensorrt.INetworkDefinition, input: tensorrt.tensorrt.ITensor, axis: int, block_size: int, output_type: tensorrt.tensorrt.DataType, scale_type: tensorrt.tensorrt.DataType) tensorrt.tensorrt.IDynamicQuantizeLayer ¶
向网络添加动态量化层。有关更多信息,请参见
IDynamicQuantizeLayer
。- 参数:
input – 要量化的张量。
axis – 被切片成块的轴。
block_size – 使用共享比例因子量化的元素数量。
output_type – 量化输出张量的数据类型。
scale_type – 用于量化输入数据的比例因子数据类型。
- 返回值:
新的 DynamicQuantization 层,如果无法创建,则为
None
。
- add_einsum(self: tensorrt.tensorrt.INetworkDefinition, inputs: List[tensorrt.tensorrt.ITensor], equation: str) tensorrt.tensorrt.IEinsumLayer ¶
向网络添加 Einsum 层。有关更多信息,请参见
IEinsumLayer
。- 参数:
inputs – 层的输入张量。
equation – 层的 Einsum 方程。
- 返回值:
新的 Einsum 层,如果无法创建,则为
None
。
- add_elementwise(self: tensorrt.tensorrt.INetworkDefinition, input1: tensorrt.tensorrt.ITensor, input2: tensorrt.tensorrt.ITensor, op: tensorrt.tensorrt.ElementWiseOperation) tensorrt.tensorrt.IElementWiseLayer ¶
向网络添加逐元素层。有关更多信息,请参见
IElementWiseLayer
。- 参数:
input1 – 层的第一个输入张量。
input2 – 层的第二个输入张量。
op – 该层应用的二元运算。
输入张量必须具有相同的维度数。对于每个维度,它们的长度必须匹配,或者其中一个的长度必须为 1。在后一种情况下,张量会沿该轴广播。
输出张量具有与输入相同的维度数。对于每个维度,其长度是相应输入维度的长度的最大值。
- 返回值:
新的逐元素层,如果无法创建,则为
None
。
- add_fill(*args, **kwargs)¶
重载函数。
add_fill(self: tensorrt.tensorrt.INetworkDefinition, shape: tensorrt.tensorrt.Dims, op: tensorrt.tensorrt.FillOperation) -> tensorrt.tensorrt.IFillLayer
添加填充层。有关更多信息,请参见
IFillLayer
。- 参数 dimensions:
输出张量维度。
- 参数 op:
该层应用的填充运算。
- 参数 output_type:
输出张量的数据类型。指定 output_type 是可选的(默认值为 tensorrt.float32)。
- 返回值:
新的填充层,如果无法创建,则为
None
。
add_fill(self: tensorrt.tensorrt.INetworkDefinition, shape: tensorrt.tensorrt.Dims, op: tensorrt.tensorrt.FillOperation, output_type: tensorrt.tensorrt.DataType) -> tensorrt.tensorrt.IFillLayer
添加填充层。有关更多信息,请参见
IFillLayer
。- 参数 dimensions:
输出张量维度。
- 参数 op:
该层应用的填充运算。
- 参数 output_type:
输出张量的数据类型。指定 output_type 是可选的(默认值为 tensorrt.float32)。
- 返回值:
新的填充层,如果无法创建,则为
None
。
- add_gather(self: tensorrt.tensorrt.INetworkDefinition, input: tensorrt.tensorrt.ITensor, indices: tensorrt.tensorrt.ITensor, axis: int) tensorrt.tensorrt.IGatherLayer ¶
向网络添加一个 gather 层。 更多信息请参考
IGatherLayer
。- 参数:
input – 从中收集值的张量。
indices – 从中获取索引以填充输出张量的张量。
axis – 要在其上收集的数据张量中的非批处理维度轴。
- 返回值:
新的 gather 层,或者如果无法创建,则返回
None
。
- add_gather_v2(self: tensorrt.tensorrt.INetworkDefinition, input: tensorrt.tensorrt.ITensor, indices: tensorrt.tensorrt.ITensor, mode: tensorrt.tensorrt.GatherMode) tensorrt.tensorrt.IGatherLayer ¶
向网络添加一个 gather 层。 更多信息请参考
IGatherLayer
。- 参数:
input – 从中收集值的张量。
indices – 从中获取索引以填充输出张量的张量。
mode – gather 模式。
- 返回值:
新的 gather 层,或者如果无法创建,则返回
None
。
- add_grid_sample(self: tensorrt.tensorrt.INetworkDefinition, input: tensorrt.tensorrt.ITensor, grid: tensorrt.tensorrt.ITensor) tensorrt.tensorrt.IGridSampleLayer ¶
为 4d 形状的输入张量创建一个具有 trt.InterpolationMode.LINEAR、未对齐角点和 trt.SampleMode.FILL 的 GridSample 层。 更多信息请参考
IGridSampleLayer
。- 参数:
input – 层的输入张量。
grid – 图层的网格张量。
- 变量:
interpolation_mode – class:InterpolationMode 图层中使用的插值模式。 默认为 LINEAR。
align_corners – class:bool 图层中使用的对齐模式。 默认为 False。
padding_mode –
SampleMode
图层中使用的填充模式。 默认为 FILL。
- 返回值:
新的 grid sample 层,或者如果无法创建,则返回
None
。
- add_identity(self: tensorrt.tensorrt.INetworkDefinition, input: tensorrt.tensorrt.ITensor) tensorrt.tensorrt.IIdentityLayer ¶
添加一个 identity 层。 更多信息请参考
IIdentityLayer
。- 参数:
input – 层的输入张量。
- 返回值:
新的 identity 层,或者如果无法创建,则返回
None
。
- add_if_conditional(self: tensorrt.tensorrt.INetworkDefinition) tensorrt.tensorrt.IIfConditional ¶
向网络添加一个 if-conditional,它提供了一种指定子图的方法,这些子图将使用延迟评估有条件地执行。 更多信息请参考
IIfConditional
。- 返回值:
新的 if-condtional,或者如果无法创建,则返回
None
。
- add_input(self: tensorrt.tensorrt.INetworkDefinition, name: str, dtype: tensorrt.tensorrt.DataType, shape: tensorrt.tensorrt.Dims) tensorrt.tensorrt.ITensor ¶
向网络添加一个输入。
- 参数:
name – 张量的名称。 每个输入和输出张量都必须具有唯一的名称。
dtype – 张量的数据类型。
shape – 张量的维度。 总体积必须小于 2^31 个元素。
- 返回值:
新添加的 Tensor。
- add_loop(self: tensorrt.tensorrt.INetworkDefinition) tensorrt.tensorrt.ILoop ¶
向网络添加一个循环,它提供了一种指定循环子图的方法。 更多信息请参考
ILoop
。- 返回值:
新的 loop 层,或者如果无法创建,则返回
None
。
- add_lrn(self: tensorrt.tensorrt.INetworkDefinition, input: tensorrt.tensorrt.ITensor, window: int, alpha: float, beta: float, k: float) tensorrt.tensorrt.ILRNLayer ¶
向网络添加一个 LRN 层。 更多信息请参考
ILRNLayer
。- 参数:
input – 层的输入张量。
window – 窗口的大小。
alpha – LRN 计算的 alpha 值。
beta – LRN 计算的 beta 值。
k – LRN 计算的 k 值。
- 返回值:
新的 LRN 层,或者如果无法创建,则返回
None
。
- add_matrix_multiply(self: tensorrt.tensorrt.INetworkDefinition, input0: tensorrt.tensorrt.ITensor, op0: tensorrt.tensorrt.MatrixOperation, input1: tensorrt.tensorrt.ITensor, op1: tensorrt.tensorrt.MatrixOperation) tensorrt.tensorrt.IMatrixMultiplyLayer ¶
向网络添加一个矩阵乘法层。 更多信息请参考
IMatrixMultiplyLayer
。- 参数:
input0 – 第一个输入张量(通常为 A)。
op0 – 是否将 input0 视为矩阵、转置矩阵或向量。
input1 – 第二个输入张量(通常为 B)。
op1 – 是否将 input1 视为矩阵、转置矩阵或向量。
- 返回值:
新的矩阵乘法层,或者如果无法创建,则返回
None
。
- add_nms(self: tensorrt.tensorrt.INetworkDefinition, boxes: tensorrt.tensorrt.ITensor, scores: tensorrt.tensorrt.ITensor, max_output_boxes_per_class: tensorrt.tensorrt.ITensor) tensorrt.tensorrt.INMSLayer ¶
向网络添加一个非极大值抑制层。 更多信息请参考
INMSLayer
。- 参数:
boxes – 图层的输入 boxes 张量。
scores – 图层的输入 scores 张量。
max_output_boxes_per_class – 图层的 maxOutputBoxesPerClass 张量。
- 变量:
bounding_box_format –
BoundingBoxFormat
图层使用的边界框格式。 默认为 CORNER_PAIRS。topk_box_limit –
int
每个批次项的最大过滤框数,用于选择。 对于 SM 5.3 和 6.2 设备,默认为 2000,否则为 5000。 TopK 框限制必须小于或等于 {SM 5.3 和 6.2 设备为 2000,否则为 5000}。
- 返回值:
新的 NMS 层,或者如果无法创建,则返回
None
。
- add_non_zero(self: tensorrt.tensorrt.INetworkDefinition, input: tensorrt.tensorrt.ITensor) tensorrt.tensorrt.INonZeroLayer ¶
向网络添加一个 NonZero 层。 更多信息请参考
INonZeroLayer
。- 参数:
input – 层的输入张量。
- 返回值:
新的 NonZero 层,或者如果无法创建,则返回
None
。
- add_normalization(self: tensorrt.tensorrt.INetworkDefinition, input: tensorrt.tensorrt.ITensor, scale: tensorrt.tensorrt.ITensor, bias: tensorrt.tensorrt.ITensor, axesMask: int) tensorrt.tensorrt.INormalizationLayer ¶
向网络添加一个 Normalization 层。 更多信息请参考
Normalization
。- 参数:
input – 层的输入张量。
scale – 用于缩放归一化输出的 scale 张量。
bias – 用于缩放归一化输出的 bias 张量。
axesMask – 在其上执行均值计算的轴。 位掩码轴中位置 i 的位对应于结果的显式维度 i。 例如,最低有效位对应于第一个显式维度,而下一个最低有效位对应于第二个显式维度。
- 返回值:
新的 Normalization 层,或者如果无法创建,则返回
None
。
- add_one_hot(self: tensorrt.tensorrt.INetworkDefinition, indices: tensorrt.tensorrt.ITensor, values: tensorrt.tensorrt.ITensor, depth: tensorrt.tensorrt.ITensor, axis: int) tensorrt.tensorrt.IOneHotLayer ¶
向网络添加一个 OneHot 层。 更多信息请参考
IOneHotLayer
。- 参数:
indices – 从中获取索引以填充输出张量的张量。
values – 用于获取 off(冷)值和 on(热)值的张量
depth – 用于获取 one-hot 编码的深度(类数)的张量
axis – 将 one-hot 编码附加到的轴
- 返回值:
新的 OneHot 层,或者如果无法创建,则返回
None
。
- add_padding_nd(self: tensorrt.tensorrt.INetworkDefinition, input: tensorrt.tensorrt.ITensor, pre_padding: tensorrt.tensorrt.Dims, post_padding: tensorrt.tensorrt.Dims) tensorrt.tensorrt.IPaddingLayer ¶
向网络添加一个多维 padding 层。 更多信息请参考
IPaddingLayer
。- 参数:
input – 层的输入张量。
pre_padding – 应用于张量开始处的 padding。
post_padding – 应用于张量结尾处的 padding。
- 返回值:
新的 padding 层,或者如果无法创建,则返回
None
。
- add_parametric_relu(self: tensorrt.tensorrt.INetworkDefinition, input: tensorrt.tensorrt.ITensor, slopes: tensorrt.tensorrt.ITensor) tensorrt.tensorrt.IParametricReLULayer ¶
添加一个 parametric ReLU 层。 更多信息请参考
IParametricReLULayer
。- 参数:
input – 层的输入张量。
slopes – slopes 张量(输入元素与 slopes 相乘,其中输入为负数)。
- 返回值:
新的 parametric ReLU 层,或者如果无法创建,则返回
None
。
- add_plugin(*args, **kwargs)¶
重载函数。
add_plugin(self: tensorrt.tensorrt.INetworkDefinition, tuple: tuple) -> tensorrt.tensorrt.IPluginV3Layer
add_plugin(self: tensorrt.tensorrt.INetworkDefinition, func: function) -> tensorrt.tensorrt.IPluginV3Layer
- add_plugin_v2(self: tensorrt.tensorrt.INetworkDefinition, inputs: List[tensorrt.tensorrt.ITensor], plugin: tensorrt.tensorrt.IPluginV2) tensorrt.tensorrt.IPluginV2Layer ¶
使用
IPluginV2
接口向网络添加一个插件层。 更多信息请参考IPluginV2
。- 参数:
inputs – 层的输入张量。
plugin – 图层插件。
- 返回值:
新的插件层,或者如果无法创建,则返回
None
。
- add_plugin_v3(self: tensorrt.tensorrt.INetworkDefinition, inputs: List[tensorrt.tensorrt.ITensor], shape_inputs: List[tensorrt.tensorrt.ITensor], plugin: tensorrt.tensorrt.IPluginV3) tensorrt.tensorrt.IPluginV3Layer ¶
使用
IPluginV3
接口向网络添加一个插件层。 更多信息请参考IPluginV3
。- 参数:
inputs – 层的输入张量。
shape_inputs – 图层的形状输入张量。
plugin – 图层插件。
- 返回值:
新的插件层,或者如果无法创建,则返回
None
。
- add_pooling_nd(self: tensorrt.tensorrt.INetworkDefinition, input: tensorrt.tensorrt.ITensor, type: tensorrt.tensorrt.PoolingType, window_size: tensorrt.tensorrt.Dims) tensorrt.tensorrt.IPoolingLayer ¶
向网络添加一个多维池化层。 有关更多信息,请参见
IPoolingLayer
。- 参数:
input – 层的输入张量。
type – 要应用的池化类型。
window_size – 池化窗口的大小。
- 返回值:
新的池化层,或者如果无法创建,则为
None
。
- add_quantize(*args, **kwargs)¶
重载函数。
add_quantize(self: tensorrt.tensorrt.INetworkDefinition, input: tensorrt.tensorrt.ITensor, scale: tensorrt.tensorrt.ITensor) -> tensorrt.tensorrt.IQuantizeLayer
向网络添加量化层。 有关更多信息,请参见
IQuantizeLayer
。- 参数 input:
要量化的张量。
- 参数 scale:
具有比例系数的张量。
- 参数 output_type:
输出张量的数据类型。 指定 output_type 是可选的(默认值为 tensorrt.int8)。
- 返回值:
新的量化层,或者如果无法创建,则为
None
。
add_quantize(self: tensorrt.tensorrt.INetworkDefinition, input: tensorrt.tensorrt.ITensor, scale: tensorrt.tensorrt.ITensor, output_type: tensorrt.tensorrt.DataType) -> tensorrt.tensorrt.IQuantizeLayer
向网络添加量化层。 有关更多信息,请参见
IQuantizeLayer
。- 参数 input:
要量化的张量。
- 参数 scale:
具有比例系数的张量。
- 参数 output_type:
输出张量的数据类型。 指定 output_type 是可选的(默认值为 tensorrt.int8)。
- 返回值:
新的量化层,或者如果无法创建,则为
None
。
- add_ragged_softmax(self: tensorrt.tensorrt.INetworkDefinition, input: tensorrt.tensorrt.ITensor, bounds: tensorrt.tensorrt.ITensor) tensorrt.tensorrt.IRaggedSoftMaxLayer ¶
向网络添加一个参差不齐的 softmax 层。 有关更多信息,请参见
IRaggedSoftMaxLayer
。- 参数:
input – ZxS 输入张量。
bounds – Zx1 边界张量。
- 返回值:
新的参差不齐的 softmax 层,或者如果无法创建,则为
None
。
- add_reduce(self: tensorrt.tensorrt.INetworkDefinition, input: tensorrt.tensorrt.ITensor, op: tensorrt.tensorrt.ReduceOperation, axes: int, keep_dims: bool) tensorrt.tensorrt.IReduceLayer ¶
向网络添加一个 reduce 层。 有关更多信息,请参见
IReduceLayer
。- 参数:
input – 层的输入张量。
op – 要执行的缩减运算。
axes – 缩减维度。 位掩码 axes 中位置 i 的位对应于结果的显式维度 i。 例如,最低有效位对应于第一个显式维度,而下一个最低有效位对应于第二个显式维度。
keep_dims – 指定是否在图层输出中保留缩减维度的布尔值。
- 返回值:
新的 reduce 层,或者如果无法创建,则为
None
。
- add_resize(self: tensorrt.tensorrt.INetworkDefinition, input: tensorrt.tensorrt.ITensor) tensorrt.tensorrt.IResizeLayer ¶
添加一个 resize 层。 有关更多信息,请参见
IResizeLayer
。- 参数:
input – 层的输入张量。
- 返回值:
新的 resize 层,或者如果无法创建,则为
None
。
- add_reverse_sequence(self: tensorrt.tensorrt.INetworkDefinition, input: tensorrt.tensorrt.ITensor, sequence_lens: tensorrt.tensorrt.ITensor) tensorrt.tensorrt.IReverseSequenceLayer ¶
向网络添加 ReverseSequence 层。 有关更多信息,请参见
IReverseSequenceLayer
。- 参数:
input – 层的输入张量。
sequence_lens – 1D 张量,指定批次中要反转的序列的长度。
sequence_lens
的长度必须等于batch_axis
指定的input
中维度的尺寸。
- 返回值:
新的 ReverseSequence 层,或者如果无法创建,则为
None
。
- add_scale(self: tensorrt.tensorrt.INetworkDefinition, input: tensorrt.tensorrt.ITensor, mode: tensorrt.tensorrt.ScaleMode, shift: tensorrt.tensorrt.Weights = None, scale: tensorrt.tensorrt.Weights = None, power: tensorrt.tensorrt.Weights = None) tensorrt.tensorrt.IScaleLayer ¶
向网络添加一个 scale 层。 有关更多信息,请参见
IScaleLayer
。- 参数:
input – 图层的输入张量。 此张量至少需要具有 3 个维度。
mode – 缩放模式。
shift – shift 值。
scale – scale 值。
power – power 值。
如果权重可用,则权重的大小取决于 ScaleMode。 对于 UNIFORM,权重的数量等于 1。 对于 CHANNEL,权重的数量等于通道维度。 对于 ELEMENTWISE,权重的数量等于输入的体积。
- 返回值:
新的 scale 层,或者如果无法创建,则为
None
。
- add_scale_nd(self: tensorrt.tensorrt.INetworkDefinition, input: tensorrt.tensorrt.ITensor, mode: tensorrt.tensorrt.ScaleMode, shift: tensorrt.tensorrt.Weights = None, scale: tensorrt.tensorrt.Weights = None, power: tensorrt.tensorrt.Weights = None, channel_axis: int) tensorrt.tensorrt.IScaleLayer ¶
向网络添加一个多维 scale 层。 有关更多信息,请参见
IScaleLayer
。- 参数:
input – 图层的输入张量。 此张量至少需要具有 3 个维度。
mode – 缩放模式。
shift – shift 值。
scale – scale 值。
power – power 值。
channel_axis – 通道维度轴。
如果权重可用,则权重的大小取决于 ScaleMode。 对于 UNIFORM,权重的数量等于 1。 对于 CHANNEL,权重的数量等于通道维度。 对于 ELEMENTWISE,权重的数量等于输入的体积。
- 返回值:
新的 scale 层,或者如果无法创建,则为
None
。
- add_scatter(self: tensorrt.tensorrt.INetworkDefinition, data: tensorrt.tensorrt.ITensor, indices: tensorrt.tensorrt.ITensor, updates: tensorrt.tensorrt.ITensor, mode: tensorrt.tensorrt.ScatterMode) tensorrt.tensorrt.IScatterLayer ¶
向网络添加一个 scatter 层。 有关更多信息,请参见
IScatterLayer
。- 参数:
data – 从中获取默认值的张量。
indices – 从中获取索引以填充输出张量的张量。
updates – 从中获取值以填充输出张量的张量。
mode – 操作模式,请参阅 IScatterLayer 以获取更多信息
- 返回值:
新的 Scatter 层,或者如果无法创建,则为
None
。
- add_select(self: tensorrt.tensorrt.INetworkDefinition, condition: tensorrt.tensorrt.ITensor, then_input: tensorrt.tensorrt.ITensor, else_input: tensorrt.tensorrt.ITensor) tensorrt.tensorrt.ISelectLayer ¶
添加一个 select 层。 有关更多信息,请参见
ISelectLayer
。- 参数:
condition – 层的条件张量。
then_input – 图层的 then 输入张量。
else_input – 图层的 else 输入张量。
- 返回值:
新的 select 层,或者如果无法创建,则为
None
。
- add_shape(self: tensorrt.tensorrt.INetworkDefinition, input: tensorrt.tensorrt.ITensor) tensorrt.tensorrt.IShapeLayer ¶
向网络添加一个 shape 层。 有关更多信息,请参见
IShapeLayer
。- 参数:
input – 层的输入张量。
- 返回值:
新的 shape 层,或者如果无法创建,则为
None
。
- add_shuffle(self: tensorrt.tensorrt.INetworkDefinition, input: tensorrt.tensorrt.ITensor) tensorrt.tensorrt.IShuffleLayer ¶
向网络添加一个 shuffle 层。 有关更多信息,请参见
IShuffleLayer
。- 参数:
input – 层的输入张量。
- 返回值:
新的 shuffle 层,或者如果无法创建,则为
None
。
- add_slice(self: tensorrt.tensorrt.INetworkDefinition, input: tensorrt.tensorrt.ITensor, start: tensorrt.tensorrt.Dims, shape: tensorrt.tensorrt.Dims, stride: tensorrt.tensorrt.Dims) tensorrt.tensorrt.ISliceLayer ¶
向网络添加一个 slice 层。 有关更多信息,请参见
ISliceLayer
。- 参数:
input – 层的输入张量。
start – 起始偏移量。
shape – 输出形状。
stride – 切片步幅。 允许正步幅值、负步幅值、零步幅值以及它们在不同维度上的组合。
- 返回值:
新的 slice 层,或者如果无法创建,则为
None
。
- add_softmax(self: tensorrt.tensorrt.INetworkDefinition, input: tensorrt.tensorrt.ITensor) tensorrt.tensorrt.ISoftMaxLayer ¶
向网络添加一个 softmax 层。 有关更多信息,请参见
ISoftMaxLayer
。- 参数:
input – 层的输入张量。
- 返回值:
新的 softmax 层,或者如果无法创建,则为
None
。
- add_squeeze(self: tensorrt.tensorrt.INetworkDefinition, input: tensorrt.tensorrt.ITensor, axes: tensorrt.tensorrt.ITensor) tensorrt.tensorrt.ISqueezeLayer ¶
向网络添加 Squeeze 层。 有关更多信息,请参见
ISqueezeLayer
。- 参数:
input – 层的输入张量。
axes – 包含要移除的轴的张量。 必须可解析为常量 Int32 或 Int64 1D 形状张量。
- 返回值:
新的 Squeeze 层,或者如果无法创建,则为
None
。
- add_topk(self: tensorrt.tensorrt.INetworkDefinition, input: tensorrt.tensorrt.ITensor, op: tensorrt.tensorrt.TopKOperation, k: int, axes: int) tensorrt.tensorrt.ITopKLayer ¶
向网络添加 TopK 层。 有关更多信息,请参见
ITopKLayer
。TopK 层有两个相同维度的输出。 第一个包含数据值,第二个包含这些值的索引位置。 输出值已排序,对于操作
TopKOperation.MAX
,值从大到小排序,对于操作TopKOperation.MIN
,值从小到大排序。目前仅支持 K 值高达 3840。
- 参数:
input – 层的输入张量。
op – 要执行的操作。
k – 要保留的元素数量。
axes – 缩减维度。 位掩码 axes 中位置 i 的位对应于结果的显式维度 i。 例如,最低有效位对应于第一个显式维度,而下一个最低有效位对应于第二个显式维度。 目前,axes 必须精确指定一个维度,并且它必须是最后四个维度之一。
- 返回值:
新的 TopK 层,或者如果无法创建,则为
None
。
- add_unary(self: tensorrt.tensorrt.INetworkDefinition, input: tensorrt.tensorrt.ITensor, op: tensorrt.tensorrt.UnaryOperation) tensorrt.tensorrt.IUnaryLayer ¶
向网络添加一元层。 更多信息请参考
IUnaryLayer
。- 参数:
input – 层的输入张量。
op – 要应用的操作。
- 返回值:
新的单unary层,或者如果无法创建,则为
None
。
- add_unsqueeze(self: tensorrt.tensorrt.INetworkDefinition, input: tensorrt.tensorrt.ITensor, axes: tensorrt.tensorrt.ITensor) tensorrt.tensorrt.IUnsqueezeLayer ¶
向网络添加一个 Unsqueeze 层。 更多信息请参考
IUnsqueezeLayer
。- 参数:
input – 层的输入张量。
axes – 包含要添加轴的张量。 必须可解析为常量 Int32 或 Int64 一维形状张量。
- 返回值:
新的 Unsqueeze 层,或者如果无法创建,则为
None
。
- are_weights_marked_refittable(self: tensorrt.tensorrt.INetworkDefinition, name: str) bool ¶
权重是否已标记为可重新拟合。
- 参数:
name – 要检查的权重的名称。
- property builder¶
从中创建此 INetworkDefinition 的构建器。
更多信息请参考
IBuilder
。
- get_flag(self: tensorrt.tensorrt.INetworkDefinition, flag: tensorrt.NetworkDefinitionCreationFlag) bool ¶
如果设置了指定的
NetworkDefinitionCreationFlag
,则返回 true。- 参数:
flag –
NetworkDefinitionCreationFlag
。- 返回值:
标志是否已设置。
- get_input(self: tensorrt.tensorrt.INetworkDefinition, index: int) tensorrt.tensorrt.ITensor ¶
获取给定索引指定的输入张量。
- 参数:
index – 输入张量的索引。
- 返回值:
张量,或者如果超出范围,则为
None
。
- get_layer(self: tensorrt.tensorrt.INetworkDefinition, index: int) tensorrt.tensorrt.ILayer ¶
获取给定索引指定的层。
- 参数:
index – 层的索引。
- 返回值:
层,或者如果超出范围,则为
None
。
- get_output(self: tensorrt.tensorrt.INetworkDefinition, index: int) tensorrt.tensorrt.ITensor ¶
获取给定索引指定的输出张量。
- 参数:
index – 输出张量的索引。
- 返回值:
张量,或者如果超出范围,则为
None
。
- is_debug_tensor(self: tensorrt.tensorrt.INetworkDefinition, tensor: tensorrt.tensorrt.ITensor) bool ¶
检查张量是否标记为调试张量。
- 参数:
tensor – 要检查的张量。
- mark_debug(self: tensorrt.tensorrt.INetworkDefinition, tensor: tensorrt.tensorrt.ITensor) bool ¶
将张量标记为网络中的调试张量。
- 参数:
tensor – 要标记为调试张量的张量。
- 返回值:
成功时返回 True,否则返回 False。
- mark_output(self: tensorrt.tensorrt.INetworkDefinition, tensor: tensorrt.tensorrt.ITensor) None ¶
将张量标记为输出。
- 参数:
tensor – 要标记的张量。
- mark_output_for_shapes(self: tensorrt.tensorrt.INetworkDefinition, tensor: tensorrt.tensorrt.ITensor) bool ¶
使张量的值能够被
IExecutionContext.get_shape_binding()
计算。- 参数:
tensor – 要取消标记为输出张量的张量。 该张量必须为
int32
类型,且维度不超过一维。- 返回值:
成功返回
True
,如果张量已标记为输出,则返回False
。
- mark_weights_refittable(self: tensorrt.tensorrt.INetworkDefinition, name: str) bool ¶
将权重标记为可重新拟合。
- 参数:
name – 要标记的权重。
- remove_tensor(self: tensorrt.tensorrt.INetworkDefinition, tensor: tensorrt.tensorrt.ITensor) None ¶
从网络中移除张量。
- 参数:
tensor – 要移除的张量
移除作为层输入或输出的张量是非法的。 如果使用此类张量调用此方法,则会在日志中发出警告,并且该调用将被忽略。
- set_weights_name(self: tensorrt.tensorrt.INetworkDefinition, weights: tensorrt.tensorrt.Weights, name: str) bool ¶
将名称与给定权重的当前所有用法关联起来。
必须在权重在网络中使用后设置名称。 查找是关联的。 该名称适用于具有匹配类型、值指针和计数的所有权重。 如果网络中存在具有匹配值指针但类型或计数不同的权重,则会发出错误消息,拒绝该名称,并返回 false。 如果该名称已用于其他权重,则返回 false。 None 会导致权重变为未命名,即清除任何先前的名称。
- 参数:
weights – 要命名的权重。
name – 要与权重关联的名称。
- 返回值:
成功时返回 true。
- unmark_debug(self: tensorrt.tensorrt.INetworkDefinition, tensor: tensorrt.tensorrt.ITensor) bool ¶
取消将张量标记为网络中的调试张量。
- 参数:
tensor – 要取消标记为调试张量的张量。
- 返回值:
成功时返回 True,否则返回 False。
- unmark_output(self: tensorrt.tensorrt.INetworkDefinition, tensor: tensorrt.tensorrt.ITensor) None ¶
取消将张量标记为网络输出。
- 参数:
tensor – 要取消标记为输出张量的张量。
- unmark_output_for_shapes(self: tensorrt.tensorrt.INetworkDefinition, tensor: tensorrt.tensorrt.ITensor) bool ¶
撤消
mark_output_for_shapes()
的操作。- 参数:
tensor – 要取消标记为输出张量的张量。
- 返回值:
成功返回
True
,如果张量未标记为输出,则返回False
。
- unmark_weights_refittable(self: tensorrt.tensorrt.INetworkDefinition, name: str) bool ¶
取消将权重标记为可重新拟合。
- 参数:
name – 要取消标记的权重。