nvidia.dali.fn.slice#
- nvidia.dali.fn.slice(__data, __anchor=None, __shape=None, /, *, axes=[1, 0], axis_names='WH', bytes_per_sample_hint=[0], dtype=None, end=None, fill_values=[0.0], normalized_anchor=True, normalized_shape=True, out_of_bounds_policy='error', preserve=False, rel_end=None, rel_shape=None, rel_start=None, shape=None, start=None, device=None, name=None)#
提取子张量或切片。
注意
对于通用索引和切片,您可以使用 Python 索引语法。 有关详细信息,请参阅 索引和切片。
可以通过提供切片的起始和结束坐标,或切片的起始坐标和形状来指定切片。 坐标和形状都可以用绝对或相对术语提供。
切片参数可以通过以下命名参数指定
start
:切片起始坐标(绝对)rel_start
:切片起始坐标(相对)end
:切片结束坐标(绝对)rel_end
:切片结束坐标(相对)shape
:切片形状(绝对)rel_shape
:切片形状(相对)
可以通过提供起始和结束坐标或起始和形状来配置切片。 相对参数和绝对参数可以混合使用(例如,
rel_start
可以与shape
一起使用),只要起始和形状或结束是唯一定义的。或者,可以提供两个额外的位置输入,指定
__anchor
和__shape
。 当使用位置输入时,可以使用两个额外的布尔参数normalized_anchor
/normalized_shape
来指定所提供参数的性质。 对 anchor 和 shape 使用位置输入与上面指定的命名参数不兼容。注意
对于 GPU 后端和位置输入
__anchor
和__shape
,CPU 和 GPU 数据节点均被接受,但首选 CPU 输入。 以 GPU 输入形式提供这些参数将导致额外的设备到主机复制及其相关的同步点。 如果可能,请将__anchor
和__shape
作为 CPU 输入提供。切片参数应提供与
axis_names
或axes
参数指定的维度一样多的维度。默认情况下,
nvidia.dali.fn.slice()
运算符对切片参数使用归一化坐标和WH
顺序。此运算符支持体积数据。
- 支持的后端
‘cpu’
‘gpu’
- 参数:
__data¶ (TensorList) – 包含输入数据的批次。
__anchor¶ (1D TensorList of float or int, optional) –
(可选)包含切片起点的归一化或绝对坐标(x0、x1、x2、...)的输入。
整数坐标被解释为绝对坐标,而浮点坐标可以解释为绝对坐标或相对坐标,具体取决于
normalized_anchor
的值。__shape¶ (1D TensorList of float or int, optional) –
(可选)包含切片尺寸的归一化或绝对坐标(s0、s1、s2、...)的输入。
整数坐标被解释为绝对坐标,而浮点坐标可以解释为绝对坐标或相对坐标,具体取决于
normalized_shape
的值。
- 关键字参数:
axes¶ (int 或 list of int 或 TensorList of int, optional, default = [1, 0]) –
用作维度索引的 anchor 和 shape 切片输入的维度顺序。
负值被解释为从后往前计数维度。有效范围:
[-ndim, ndim-1]
,其中 ndim 是输入数据中的维度数。axis_names¶ (layout str, optional, default = ‘WH’) –
用于 anchor 和 shape 切片输入的维度顺序,如布局中所述。
如果提供了值,则
axis_names
的优先级高于axes
。bytes_per_sample_hint¶ (int 或 list of int, optional, default = [0]) –
输出大小提示,以字节/样本为单位。
如果指定,则运算符驻留在 GPU 或页锁定主机内存中的输出将被预分配,以适应此大小的样本批次。
dtype¶ (
nvidia.dali.types.DALIDataType
, optional) –输出数据类型。
支持的类型:
FLOAT
、FLOAT16
和UINT8
。如果未设置,则使用输入类型。
end¶ (int or list of int or TensorList of int, optional) –
切片的结束坐标。
注意:提供命名参数
start
、end
、shape
、rel_start
、rel_end
、rel_shape
与提供位置输入 anchor 和 shape 不兼容。fill_values¶ (float 或 list of float, optional, default = [0.0]) –
确定填充值,并且仅在
out_of_bounds_policy
设置为“pad”时相关。如果提供标量值,它将用于所有通道。 如果提供多个值,则值的数量和通道必须相同(布局中维度
C
的范围)在输出切片中。image_type¶ (
nvidia.dali.types.DALIDataType
) –警告
参数 image_type 不再使用,将在未来的版本中删除。
normalized_anchor¶ (bool, optional, default = True) –
确定 anchor 位置输入应解释为归一化(范围 [0.0, 1.0])还是绝对坐标。
注意
此参数仅在 anchor 数据类型为
float
时相关。 对于整数类型,坐标始终是绝对坐标。normalized_shape¶ (bool, optional, default = True) –
确定 shape 位置输入应解释为归一化(范围 [0.0, 1.0])还是绝对坐标。
注意
此参数仅在 anchor 数据类型为
float
时相关。 对于整数类型,坐标始终是绝对坐标。out_of_bounds_policy¶ (str, optional, default = ‘error’) –
确定在切片输入范围外区域时的策略。
以下是支持值的列表
"error"
(默认值):尝试在输入边界外切片将产生错误。"pad"
:将根据需要使用零或使用fill_values
参数指定的任何其他值填充输入。"trim_to_shape"
:切片窗口将裁剪到输入的边界。
output_dtype¶ (
nvidia.dali.types.DALIDataType
) –preserve¶ (bool, optional, default = False) – 阻止运算符从图中删除,即使其输出未使用。
rel_end¶ (float or list of float or TensorList of float, optional) –
切片的结束相对坐标(范围 [0.0 - 1.0]。
注意:提供命名参数
start
、end
、shape
、rel_start
、rel_end
、rel_shape
与提供位置输入 anchor 和 shape 不兼容。rel_shape¶ (float or list of float or TensorList of float, optional) –
切片的相对形状(范围 [0.0 - 1.0])。
提供命名参数
start
、end
、shape
、rel_start
、rel_end
、rel_shape
与提供位置输入 anchor 和 shape 不兼容。rel_start¶ (float or list of float or TensorList of float, optional) –
切片的起始相对坐标(范围 [0.0 - 1.0])。
注意:提供命名参数
start
、end
、shape
、rel_start
、rel_end
、rel_shape
与提供位置输入 anchor 和 shape 不兼容。shape¶ (int or list of int or TensorList of int, optional) –
切片的形状。
提供命名参数
start
、end
、shape
、rel_start
、rel_end
、rel_shape
与提供位置输入 anchor 和 shape 不兼容。start¶ (int or list of int or TensorList of int, optional) –
切片的起始坐标。
注意:提供命名参数
start
/end
或start
/shape
与提供位置输入 anchor 和 shape 不兼容。