ConvertToTensor

Function Usage

Converts the Image class on the DVPP to the Tensor class on the device, or converts the Image class on the host to the Tensor class on the host. The data type of the Tensor class object after conversion is uint8.

  • If the conversion fails, an empty tensor instance is returned.
  • If the tensor class fails to be constructed due to insufficient memory or unidentified processor, an exception occurs.
  • If withStride is set to true, the Tensor object retains the padding information of the Image object. To reduce memory copy and improve operating efficiency, the returned Tensor object and Image object share the data memory. In this scenario, the data memory of the Image object and that of the Tensor object affect each other. For example, after the Image object is released, the data in the corresponding Tensor object becomes invalid memory data.
  • If ConvertToTensor() is an API without parameters, the returned Tensor object retains the padding information of the Image object and has the batch dimension (NHWC, where N = 1).

Prototype

1
2
Tensor Image::ConvertToTensor(bool withStride, bool formatNHWC);
Tensor Image::ConvertToTensor();

Parameters

Parameter

Input/Output

Description

withStride

Input

Boolean type. It specifies whether to retain the padding information.

  • If true is passed, the padding information is reserved and the data memory is shared with the Image object.
  • If false is passed, the padding information is not retained and the data memory is not shared with the Image object.

formatNHWC

Input

Boolean type. It specifies whether the converted tensor has the batch dimension.

  • If true is passed, the batch dimension exists in the returned tensor.
  • If false is passed, the batch dimension does not exist in the returned tensor.

Response Parameters

Data Structure

Description

Tensor

Tensor class. For details, see Tensor.