Updated on 2022-03-13 GMT+08:00

TensorDimension

The AIModelManager::GetModelIOTensorDim API can be called to obtain the information about the model input/output size, including the tensor dimension information, data type, buffer size, and tensor name. This data type is defined in ai_types.h.
/*
* Describe the dimensions of a tensor.
    */
    struct TensorDimension
    {
        uint32_t n; // Batch size
        uint32_t c; // Feature map channels
        uint32_t h; // Feature map height
        uint32_t w; // Feature map width
        uint32_t data_type;
        uint32_t size;
        std::string  name;
    };
  • If the parameters related to AIPP are not configured during model conversion, the information about the model input/output dimensions obtained by calling AIModelManager::GetModelIOTensorDim is as follows:
    • n, c, h, and w are those before model conversion.
    • The enumerated value of data_type is defined as follows:
      enum DataType
      {
      DT_UNDEFINED = 0; // Used to indicate a DataType field has not been set.
      DT_FLOAT = 1; // float type, 4 bytes
      DT_FLOAT16 = 2; // fp16 type, 2 bytes
      DT_INT8 = 3; // int8 type, 1 byte
      DT_UINT8 = 4; // uint8 type, 1 byte
      DT_INT16 = 5; // int16 type, 2 bytes
      DT_UINT16 = 6; // uint16 type, 2 bytes
      DT_INT32 = 7; // int32 type, 4 bytes
      DT_INT64 = 8; // int64 type, 8 bytes
      DT_UINT32 = 9; // unsigned int32, 4 bytes
      DT_UINT64 = 10; // unsigned int64, 8 bytes
      DT_BOOL = 11; // boolean type, 1 byte
      DT_DOUBLE = 12; // double type, 8 bytes
      }
    • size = n*c*h*w*Number of bytes of each data type
  • If AIPP parameters are set during model conversion, the information about the model input/output size obtained by AIModelManager::GetModelIOTensorDim is as follows:
    • n, c, h, and w are those before model conversion, instead of h (corresponding to the src_image_size_h parameter) and w (corresponding to the src_image_size_w parameter) configured in AIPP.
    • The value of data_type is fixed at 3, indicating the DT_INT8 type.
    • The parameter size indicates the size of the picture data processed by AIPP. The size varies according to the input format. For details, see Table 1.
      Table 1 Size formula

      input_format

      size

      YUV400_U8

      n * src_image_size_w * src_image_size_h

      YUV420SP_U8

      n * src_image_size_w * src_image_size_h * 1.5

      XRGB8888_U8

      n * src_image_size_w * src_image_size_h * 4

      RGB888_U8

      n * src_image_size_w * src_image_size_h * 3

For details about model conversion or AIPP, see Model Conversion Guide.