更新时间:2021-03-18 GMT+08:00
分享

TensorDimension

调用AIModelManager::GetModelIOTensorDim接口可获取模型输入/输出尺寸的信息,主要包含tensor的dim信息,数据类型,内存大小,tensor名字。该数据类型在ai_types.h中定义。
/*
    * 描述Tensor尺寸
    */
    struct TensorDimension
    {
        uint32_t n;  //批量大小Batch
        uint32_t c;  //特征图通道Channels
        uint32_t h;  //特征图高度Height
        uint32_t w;  //特征图宽度Width
        uint32_t data_type;
        uint32_t size;
        std::string  name;
    };
  • 若执行模型转换时,未配置AIPP(AI Preprocessing,用于在AI Core上完成图像预处理)相关参数,则通过AIModelManager::GetModelIOTensorDim接口获取到的模型输入/输出尺寸的信息如下:
    • n、c、h、w就是转换前模型的n、c、h、w。
    • data_type枚举值的定义如下:
      enum DataType
      {
      DT_UNDEFINED = 0; // Used to indicate a DataType field has not been set.
      DT_FLOAT = 1; // float type,数据大小为4字节
      DT_FLOAT16 = 2; // fp16 type,数据大小为2字节
      DT_INT8 = 3; // int8 type,数据大小为1字节
      DT_UINT8 = 4; // uint8 type,数据大小为1字节
      DT_INT16 = 5; // int16 type,数据大小为2字节
      DT_UINT16 = 6; // uint16 type,数据大小为2字节
      DT_INT32 = 7; // int32 type,数据大小为4字节
      DT_INT64 = 8; // int64 type,数据大小为8字节
      DT_UINT32 = 9; // unsigned int32,数据大小为4字节
      DT_UINT64 = 10; // unsigned int64,数据大小为8字节
      DT_BOOL = 11; // bool type,数据大小为1字节
      DT_DOUBLE = 12; // double type,数据大小为8字节
      }
    • size=n*c*h*w*各类型数据的字节数
  • 若执行模型转换时,配置AIPP相关参数,则通过AIModelManager::GetModelIOTensorDim接口获取到的模型输入/输出尺寸的信息如下:
    • n、c、h、w依然是转换前模型的n、c、h、w,并不是在AIPP处配置的h(对应src_image_size_h参数)、w(对应src_image_size_w参数)。
    • data_type值固定为3,表示DT_INT8类型。
    • size的值为AIPP处理后的图片数据的大小,不同输入格式对应的size不同,具体见表1
      表1 size公式

      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

关于模型转换或AIPP的说明,请参见《模型转换指导》

分享:

    相关文档

    相关产品