Constructor of the Tensor class.
1 | Tensor::Tensor(); // Default constructor. When the construction fails, the "std::runtime_error" exception occurs. |
1 | Tensor::Tensor(const Tensor &other); // Supports copy constructor. |
1 2 | Tensor::Tensor(const std::vector<uint32_t> &shape, const MxBase::TensorDType &dataType, const int32_t &deviceId = -1); // No memory is transferred. It can be used together with Malloc to allocate memory, and the allocated memory does not need to be managed or destroyed by a user. When the construction fails, the "std::runtime_error" exception occurs. |
1 2 | Tensor::Tensor(void* usrData,const std::vector<uint32_t> &shape, const MxBase::TensorDType &dataType, const int32_t &deviceId = -1); // If the user-constructed memory is transferred, users need to allocate and destroy the memory. When the construction fails, the "std::runtime_error" exception occurs. |
1 | Tensor::Tensor(const std::vector<uint32_t> &shape, const MxBase::TensorDType &dataType, const int32_t &deviceId, bool isDvpp); |
1 | Tensor::Tensor(void *usrData, const std::vector<uint32_t> &shape, const MxBase::TensorDType &dataType,const int32_t &deviceId, const bool isDvpp, const bool isBorrowed); |
1 | Tensor::Tensor(const Tensor &tensor, const Rect &rect); // Copy constructor with a reference rectangle, which can be used to construct the ROI (supports only by Atlas inference products). |
Parameter |
Input/Output |
Description |
|---|---|---|
other |
Input |
Other initialized tensors. |
usrData |
Input |
Input memory constructed by the user. The memory is allocated and managed by the user. |
shape |
Input |
Shape of a tensor. |
dataType |
Input |
Tensor data type. For details, see TensorDType. |
deviceId |
Input |
ID of the device where the tensor is located. The default value is -1, indicating that the tensor is on the host.
|
isDvpp |
Input |
Whether to allocate the DVPP memory. If deviceId is set to -1, the host memory is allocated. In this case, this parameter is invalid. If the user pointer usrData is passed and isDvpp is set to true, ensure that the pointed memory of usrData exists on the device. Otherwise, risks and exceptions will occur in subsequent services. |
isBorrowed |
Input |
Specifies whether to release the usrData pointed memory by a tensor. If isBorrowed is set to false, the tensor releases the usrData pointed memory. If isBorrowed is set to true, the user manages the usrData pointed memory. NOTICE:
Delegates tensors to manage the memory. Only the memory that needs to be manually released is supported. Otherwise, the memory may be repeatedly released. |
rect |
Input |
Coordinates (x0, y0, x1, y1) of the reference rectangle of the image, left-closed, right-open. NOTICE:
If the Tensor(const Tensor &tensor, const Rect &rect) method is used for construction, the requirements are as follows:
|
tensor |
Input |
Other initialized tensors. |