Identity¶
将给定的输入张量输出到输出张量。当显式指定张量精度时,输入将从一种精度转换为另一种精度。
除了相同类型之间的转换(例如 float32 -> float32),唯一有效的转换是
(float32 | float16 | int32 | bool) -> (float32 | float16 | int32 | bool)
(float32 | float16) -> uint8
uint8 -> (float32 | float16)
输入¶
input: T1 类型的张量。
输出¶
output: T2 类型的张量。
数据类型¶
T1: bool, int4, int8, uint8, int32, float8, float16, float32, bfloat16
T2: bool, int4, int8, uint8, int32, float8, float16, float32, bfloat16
形状信息¶
input 和 output 是形状为 \([a_0,...,a_n]\) 的张量
体积限制¶
input 最多可以有 \(2^{31}-1\) 个元素。
示例¶
Identity 算子 (Identity)
in1 = network.add_input("input1", dtype=trt.float32, shape=(1, 1, 3, 3))
layer = network.add_identity(in1)
network.mark_output(layer.get_output(0))
inputs[in1.name] = np.array(
[
[
[
[1.0, 2.0, 3.0],
[4.0, 5.0, 6.0],
[7.0, 8.0, 9.0],
]
]
]
)
outputs[layer.get_output(0).name] = layer.get_output(0).shape
expected[layer.get_output(0).name] = inputs[in1.name]
具有不同精度的 Identity 算子
in1 = network.add_input("input1", dtype=trt.float32, shape=(1, 1, 3, 3))
layer = network.add_identity(in1)
layer.set_output_type(0, dtype=trt.int32)
layer2 = network.add_identity(layer.get_output(0))
network.mark_output(layer2.get_output(0))
inputs[in1.name] = np.array(
[
[
[
[1.1, 2.4, 3.7],
[4.2, 5.5, 6.8],
[7.3, 8.6, 9.9],
]
]
]
)
outputs[layer2.get_output(0).name] = layer2.get_output(0).shape
expected[layer2.get_output(0).name] = np.array(
[
[
[
[1.0, 2.0, 3.0],
[4.0, 5.0, 6.0],
[7.0, 8.0, 9.0],
]
]
]
)
C++ API¶
有关 C++ IIdentityLayer 算子的更多信息,请参阅 C++ IIdentityLayer 文档。
Python API¶
有关 Python IIdentityLayer 算子的更多信息,请参阅 Python IIdentityLayer 文档。