昇腾 AscendCL C++应用开发 获取模型的信息
flyfish
举例说明 程序在香橙派 AIpro 下获取到的模型信息
从ACLLite代码里看一些类型,因为获取模型信息的时候,会获取到数字,所以要看数字代表的意思,所有要看常量的名字
数据类型
# data format
ACL_FORMAT_UNDEFINED = -1
ACL_FORMAT_NCHW = 0
ACL_FORMAT_NHWC = 1
ACL_FORMAT_ND = 2
ACL_FORMAT_NC1HWC0 = 3
ACL_FORMAT_FRACTAL_Z = 4
ACL_DT_UNDEFINED = -1
ACL_FLOAT = 0
ACL_FLOAT16 = 1
ACL_INT8 = 2
ACL_INT32 = 3
ACL_UINT8 = 4
ACL_INT16 = 6
ACL_UINT16 = 7
ACL_UINT32 = 8
ACL_INT64 = 9
ACL_UINT64 = 10
ACL_DOUBLE = 11
ACL_BOOL = 12
acl_dtype = {
"dt_undefined": -1,
"float": 0,
"float16": 1,
"int8": 2,
"int32": 3,
"uint8": 4,
"int16": 6,
"uint16": 7,
"uint32": 8,
"int64": 9,
"double": 11,
"bool": 12
}
代码
aclError test()
{
std::cout << "AclmdlCreateDesc: start." << std::endl;
aclError ret = aclInit(nullptr);
int32_t deviceId_ = 0;
ret = aclrtSetDevice(deviceId_);
const char *modelPath = "../model/yolov5s.om";
uint32_t modelId = 0;
ret = aclmdlLoadFromFile(modelPath, &modelId);
std::cout << "Model Id = " << modelId << "." << std::endl;
aclmdlDesc *modelDesc = aclmdlCreateDesc();
ret = aclmdlGetDesc(modelDesc, modelId);
std::cout << "Function aclmdlGetNumInputs = " << aclmdlGetNumInputs(modelDesc) << "." << std::endl;
std::cout << "Function aclmdlGetNumOutputs = " << aclmdlGetNumOutputs(modelDesc) << "." << std::endl;
std::cout << "Function aclmdlGetInputSizeByIndex = " << aclmdlGetInputSizeByIndex(modelDesc, 0) << "." << std::endl;
std::cout << "Function aclmdlGetOutputSizeByIndex = " << aclmdlGetOutputSizeByIndex(modelDesc, 0) << "." << std::endl;
std::cout << "Function aclmdlGetInputNameByIndex = " << aclmdlGetInputNameByIndex(modelDesc, 0) << "." << std::endl;
std::cout << "Function aclmdlGetOutputNameByIndex = " << aclmdlGetOutputNameByIndex(modelDesc, 0) << "." << std::endl;
std::cout << "Function aclmdlGetInputFormat = " << aclmdlGetInputFormat(modelDesc, 0) << "." << std::endl;
std::cout << "Function aclmdlGetOutputFormat = " << aclmdlGetOutputFormat(modelDesc, 0) << "." << std::endl;
std::cout << "Function aclmdlGetInputDataType = " << aclmdlGetInputDataType(modelDesc, 0) << "." << std::endl;
std::cout << "Function aclmdlGetOutputDataType = " << aclmdlGetOutputDataType(modelDesc, 0) << "." << std::endl;
ret = aclmdlDestroyDesc(modelDesc);
aclmdlUnload(modelId);
ret = aclrtResetDevice(deviceId_);
aclFinalize();
std::cout << "AclmdlCreateDesc: end." << std::endl;
return ret;
}
在main函数中 调用test函数
解释
Function aclmdlGetInputSizeByIndex = 1228800.//640*640*3
Function aclmdlGetOutputSizeByIndex = 8568000.
Function aclmdlGetInputFormat = 1.//ACL_FORMAT_NHWC
Function aclmdlGetOutputFormat = 2.//ACL_FORMAT_ND
Function aclmdlGetInputDataType = 4.//uint8
Function aclmdlGetOutputDataType = 0.//float
8568000这个数说明下
8568000 = 25200 * 85 *4
25200个检测框,每个检测框包含85个预测值,每个预测值占4个字节
85 = 5 + 80
5个基础值:x, y, width, height, 和 objectness score。
80是类别概率
输出是float类型,float占4个字节