ARTICLE DETAIL

资讯详情

深耕郑州网站建设与运营推广的一线实战洞察。

CANN/GE AIPP配置示例

CANN/GE AIPP配置示例 AIPP配置示例【免费下载链接】geGEGraph Engine是面向昇腾的图编译器和执行器提供了计算图优化、多流并行、内存复用和模型下沉等技术手段加速模型执行效率减少模型内存占用。 GE 提供对 PyTorch、TensorFlow 前端的友好接入能力并同时支持 onnx、pb 等主流模型格式的解析与编译。项目地址: https://gitcode.com/cann/ge静态AIPP配置示例AIPP配置文件支持定义多组AIPP配置对不同的模型输入进行不同的AIPP处理配置多组AIPP参数时将一组AIPP配置放到一个aipp_op配置项里如果模型只有一个输入则只需要配置第一组aipp_op即可。如下示例以网络模型为多输入时进行说明[!NOTE]说明静态AIPP动态shape场景模型转换时通过--insert_op_conf参数设置了静态AIPP又通过--input_shape设置了动态shape则 如果模型只有一个输入该场景不支持如果模型有多个输入则必须对不同的输入节点进行设置比如一个输入节点设置静态AIPP另一个节点设置动态shape。如果模型转换时用户设置了--dynamic_image_size动态分辨率参数即输入图片的宽和高不确定同时又通过--insert_op_conf参数设置了静态AIPP功能该场景下AIPP配置文件中不能开启Crop和Padding功能并且需要将配置文件中的src_image_size_w和src_image_size_h取值设置为0。使用related_input_rank参数标识对模型第几个输入进行AIPP处理如下配置定义了两组AIPP参数分别对模型第一个和第二个输入进行AIPP处理aipp_op { aipp_mode : static related_input_rank : 0 # 标识对第1个输入进行AIPP处理 src_image_size_w : 608 src_image_size_h : 608 crop : false input_format : YUV420SP_U8 csc_switch : true rbuv_swap_switch : false matrix_r0c0 : 298 matrix_r0c1 : 0 matrix_r0c2 : 409 matrix_r1c0 : 298 matrix_r1c1 : -100 matrix_r1c2 : -208 matrix_r2c0 : 298 matrix_r2c1 : 516 matrix_r2c2 : 0 input_bias_0 : 16 input_bias_1 : 128 input_bias_2 : 128 mean_chn_0 : 104 mean_chn_1 : 117 mean_chn_2 : 123 } aipp_op { aipp_mode : static related_input_rank : 1 # 标识对第2个输入进行AIPP处理 src_image_size_w : 608 src_image_size_h : 608 crop : false input_format : YUV420SP_U8 csc_switch : true rbuv_swap_switch : false matrix_r0c0 : 298 matrix_r0c1 : 0 matrix_r0c2 : 409 matrix_r1c0 : 298 matrix_r1c1 : -100 matrix_r1c2 : -208 matrix_r2c0 : 298 matrix_r2c1 : 516 matrix_r2c2 : 0 input_bias_0 : 16 input_bias_1 : 128 input_bias_2 : 128 mean_chn_0 : 104 mean_chn_1 : 117 mean_chn_2 : 123 }使用related_input_name参数标识对模型第几个输入进行AIPP处理此处需要填写为模型输入的nameinput对应的值或者模型首层节点的输出top参数对应的取值该参数只适用于Caffe网络模型且不能与related_input_rank参数同时使用如果同时配置related_input_name优先级高于related_input_rank。如下配置定义了两组AIPP参数分别对模型第一个和第二个输入进行AIPP处理aipp_op { aipp_mode : static related_input_name : data # 标识对第1个输入进行AIPP处理 src_image_size_w : 608 src_image_size_h : 608 crop : false input_format : YUV420SP_U8 csc_switch : true rbuv_swap_switch : false matrix_r0c0 : 298 matrix_r0c1 : 0 matrix_r0c2 : 409 matrix_r1c0 : 298 matrix_r1c1 : -100 matrix_r1c2 : -208 matrix_r2c0 : 298 matrix_r2c1 : 516 matrix_r2c2 : 0 input_bias_0 : 16 input_bias_1 : 128 input_bias_2 : 128 mean_chn_0 : 104 mean_chn_1 : 117 mean_chn_2 : 123 } aipp_op { aipp_mode : static related_input_name : im_info # 标识对第2个输入进行AIPP处理 src_image_size_w : 608 src_image_size_h : 608 crop : false input_format : YUV420SP_U8 csc_switch : true rbuv_swap_switch : false matrix_r0c0 : 298 matrix_r0c1 : 0 matrix_r0c2 : 409 matrix_r1c0 : 298 matrix_r1c1 : -100 matrix_r1c2 : -208 matrix_r2c0 : 298 matrix_r2c1 : 516 matrix_r2c2 : 0 input_bias_0 : 16 input_bias_1 : 128 input_bias_2 : 128 mean_chn_0 : 104 mean_chn_1 : 117 mean_chn_2 : 123 }动态AIPP配置示例AIPP配置文件支持定义多组AIPP配置对不同的模型输入进行不同的AIPP处理配置多组AIPP参数时将一组AIPP配置放到一个aipp_op配置项里如果模型只有一个输入则只需要配置第一组aipp_op即可。如下示例以网络模型为多输入时进行说明。配置示例[!NOTE]说明如果模型转换时用户设置了--dynamic_batch_size动态Batch档位参数同时又通过--insert_op_conf参数配置了动态AIPP功能 实际推理时调用aclmdlSetInputAIPP接口设置动态AIPP相关参数值时需确保batch_size要设置为最大Batch数。接口详细说明请参见aclmdlSetInputAIPP。如果模型转换时用户设置了--dynamic_image_size动态分辨率参数同时又通过--insert_op_conf参数配置了动态AIPP功能 实际推理时调用aclmdlSetInputAIPP接口设置动态AIPP相关参数值时不能开启Crop和Padding功能。该场景下还需要确保通过aclmdlSetInputAIPP接口设置的宽和高与aclmdlSetDynamicHWSize接口设置的宽、高相等都必须设置成动态分辨率最大档位的宽、高。接口详细说明请参见模型执行章节。如果模型转换时用户设置了--input_shape动态shape范围参数同时又通过--insert_op_conf参数配置了AIPP功能则AIPP输出的宽和高要在--input_shape所设置的范围内。动态AIPP场景下用户无需手动配置csc_switch、rbuv_swap_switch等参数根据如下配置文件配置好相关参数后模型转换时ATC会为动态AIPP新增一个模型输入以下简称AippData。实际推理时需要调用aclmdlSetInputAIPP接口设置动态AIPP相关参数值然后传给上述新增的AippDataAippData根据传入的参数值构造的结构体为动态AIPP的参数输入结构该结构体无需用户手动处理。接口详细说明请参见aclmdlSetInputAIPP。aipp_op { aipp_mode: dynamic related_input_rank: 0 # 标识对第1个输入进行AIPP处理 max_src_image_size: 752640 # 输入图像最大的size参数必填 } aipp_op { aipp_mode: dynamic related_input_rank: 1 # 标识对第2个输入进行AIPP处理 max_src_image_size: 752640 # 输入图像最大的size参数必填 }动态AIPP的参数输入结构根据配置示例配置好动态AIPP文件后模型推理时为动态AIPP新增模型输入AippData传入参数值后自动形成的结构体如下该结构体无需用户手动处理typedef struct tagAippDynamicBatchPara { int8_t cropSwitch; //crop switch int8_t scfSwitch; //resize switch int8_t paddingSwitch; // 0: unable padding, // 1: padding config value,sfr_filling_hblank_ch0 ~ sfr_filling_hblank_ch2 // 2: padding source picture data, single row/column copy // 3: padding source picture data, block copy // 4: padding source picture data, mirror copy int8_t rotateSwitch; //rotate switch, 0: non-rotate, 1: rotate 90°clockwise, 2: rotate 180°clockwise, 3: rotate 270° clockwise int8_t reserve[4]; int32_t cropStartPosW; //the start horizontal position of cropping int32_t cropStartPosH; //the start vertical position of cropping int32_t cropSizeW; //crop width int32_t cropSizeH; //crop height int32_t scfInputSizeW; //input width of scf int32_t scfInputSizeH; //input height of scf int32_t scfOutputSizeW; //output width of scf int32_t scfOutputSizeH; //output height of scf int32_t paddingSizeTop; //top padding size int32_t paddingSizeBottom; //bottom padding size int32_t paddingSizeLeft; //left padding size int32_t paddingSizeRight; //right padding size int16_t dtcPixelMeanChn0; //mean value of channel 0 int16_t dtcPixelMeanChn1; //mean value of channel 1 int16_t dtcPixelMeanChn2; //mean value of channel 2 int16_t dtcPixelMeanChn3; //mean value of channel 3 uint16_t dtcPixelMinChn0; //min value of channel 0 uint16_t dtcPixelMinChn1; //min value of channel 1 uint16_t dtcPixelMinChn2; //min value of channel 2 uint16_t dtcPixelMinChn3; //min value of channel 3 uint16_t dtcPixelVarReciChn0; //sfr_dtc_pixel_variance_reci_ch0 uint16_t dtcPixelVarReciChn1; //sfr_dtc_pixel_variance_reci_ch1 uint16_t dtcPixelVarReciChn2; //sfr_dtc_pixel_variance_reci_ch2 uint16_t dtcPixelVarReciChn3; //sfr_dtc_pixel_variance_reci_ch3 int8_t reserve1[16]; //32B assign, for ub copy }kAippDynamicBatchPara; typedef struct tagAippDynamicPara { uint8_t inputFormat; //input format: YUV420SP_U8/XRGB8888_U8/RGB888_U8 //uint8_t outDataType; //output data type: CC_DATA_HALF,CC_DATA_INT8, CC_DATA_UINT8 int8_t cscSwitch; //csc switch int8_t rbuvSwapSwitch; //rb/uv swap switch int8_t axSwapSwitch; //RGBA-ARGB, YUVA-AYUV swap switch int8_t batchNum; //batch parameter number int8_t reserve1[3]; int32_t srcImageSizeW; //source image width int32_t srcImageSizeH; //source image height int16_t cscMatrixR0C0; //csc_matrix_r0_c0 int16_t cscMatrixR0C1; //csc_matrix_r0_c1 int16_t cscMatrixR0C2; //csc_matrix_r0_c2 int16_t cscMatrixR1C0; //csc_matrix_r1_c0 int16_t cscMatrixR1C1; //csc_matrix_r1_c1 int16_t cscMatrixR1C2; //csc_matrix_r1_c2 int16_t cscMatrixR2C0; //csc_matrix_r2_c0 int16_t cscMatrixR2C1; //csc_matrix_r2_c1 int16_t cscMatrixR2C2; //csc_matrix_r2_c2 int16_t reserve2[3]; uint8_t cscOutputBiasR0; //output bias for RGB to YUV, element of row 0, unsigned number uint8_t cscOutputBiasR1; //output bias for RGB to YUV, element of row 1, unsigned number uint8_t cscOutputBiasR2; //output bias for RGB to YUV, element of row 2, unsigned number uint8_t cscInputBiasR0; //input bias for YUV to RGB, element of row 0, unsigned number uint8_t cscInputBiasR1; //input bias for YUV to RGB, element of row 1, unsigned number uint8_t cscInputBiasR2; //input bias for YUV to RGB, element of row 2, unsigned number uint8_t reserve3[2]; int8_t reserve4[16]; //32B assign, for ub copy kAippDynamicBatchPara aippBatchPara; //allow transfer several batch para. } kAippDynamicPara;【免费下载链接】geGEGraph Engine是面向昇腾的图编译器和执行器提供了计算图优化、多流并行、内存复用和模型下沉等技术手段加速模型执行效率减少模型内存占用。 GE 提供对 PyTorch、TensorFlow 前端的友好接入能力并同时支持 onnx、pb 等主流模型格式的解析与编译。项目地址: https://gitcode.com/cann/ge创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考
返回列表