#include"TrainStepTwoEngine.h"#include<opencv2/opencv.hpp>#include"myutils.h"#include"myqueue.h"usingnamespaceai_matrix;TrainStepTwoEngine::TrainStepTwoEngine(){}TrainStepTwoEngine::~TrainStepTwoEngine(){}APP_ERRORTrainStepTwoEngine::Init(){bUseEngine_=MyUtils::getins()->ChkIsHaveTarget("NUM");if(!bUseEngine_){LogWarn<<"engineId_:"<<engineId_<<" not use engine";returnAPP_ERR_OK;}strPort0_=engineName_+"_"+std::to_string(engineId_)+"_0";modelConfig_=MyYaml::GetIns()->GetModelConfig("TrainStepTwoEngine");//读取模型信息
APP_ERRORret=ReadModelInfo();if(ret!=APP_ERR_OK){LogError<<"Failed to read model info, ret = "<<ret;returnret;}ret=InitModel();if(ret!=APP_ERR_OK){LogError<<"Failed to read model info, ret = "<<ret;returnret;}LogInfo<<"AclTrainStepTwoEngine Init ok";returnAPP_ERR_OK;}APP_ERRORTrainStepTwoEngine::InitModel(){modelinfo.yolov5ClearityModelParam.uiClassNum=class_num;modelinfo.yolov5ClearityModelParam.uiClearNum=clear_num;modelinfo.yolov5ClearityModelParam.uiDetSize=det_size;modelinfo.yolov5ClearityModelParam.fScoreThreshold=score_threshold;modelinfo.yolov5ClearityModelParam.fNmsThreshold=nms_threshold;modelinfo.modelCommonInfo.uiModelWidth=model_width;modelinfo.modelCommonInfo.uiModelHeight=model_height;modelinfo.modelCommonInfo.uiInputSize=input_size;modelinfo.modelCommonInfo.uiOutputSize=output_size;modelinfo.modelCommonInfo.uiChannel=INPUT_CHANNEL;modelinfo.modelCommonInfo.uiBatchSize=batch_size;modelinfo.modelCommonInfo.strInputBlobName=INPUT_BLOB_NAME;modelinfo.modelCommonInfo.strOutputBlobName=OUTPUT_BLOB_NAME;stringstrModelName="";intnRet=yolov5model.YoloV5ClearityInferenceInit(&modelinfo,strModelName,modelConfig_.strOmPath);if(nRet!=0){LogInfo<<"YoloV5ClassifyInferenceInit nRet:"<<nRet;returnAPP_ERR_COMM_READ_FAIL;}returnAPP_ERR_OK;}APP_ERRORTrainStepTwoEngine::ReadModelInfo(){charszAbsPath[PATH_MAX];// Get the absolute path of model file
if(realpath(modelConfig_.strOmPath.c_str(),szAbsPath)==nullptr){LogError<<"Failed to get the real path of "<<modelConfig_.strOmPath.c_str();returnAPP_ERR_COMM_NO_EXIST;}// Check the validity of model path
intiFolderExist=access(szAbsPath,R_OK);if(iFolderExist==-1){LogError<<"ModelPath "<<szAbsPath<<" doesn't exist or read failed!";returnAPP_ERR_COMM_NO_EXIST;}//读取模型参数信息文件
Json::ValuejvModelInfo;if(!MyUtils::getins()->ReadJsonInfo(jvModelInfo,modelConfig_.strModelInfoPath)){LogError<<"ModelInfoPath:"<<modelConfig_.strModelInfoPath<<" doesn't exist or read failed!";returnAPP_ERR_COMM_NO_EXIST;}model_width=jvModelInfo["model_width"].asInt();model_height=jvModelInfo["model_height"].asInt();clear_num=jvModelInfo["clear"].isArray()?jvModelInfo["clear"].size():0;class_num=jvModelInfo["class"].isArray()?jvModelInfo["class"].size():0;input_size=GET_INPUT_SIZE(model_width,model_height);output_size=GET_OUTPUT_SIZE(model_width,model_height,clear_num,class_num);det_size=clear_num+class_num+5;score_threshold=modelConfig_.fScoreThreshold;nms_threshold=modelConfig_.fNMSTreshold;returnAPP_ERR_OK;}APP_ERRORTrainStepTwoEngine::DeInit(){if(!bUseEngine_){LogWarn<<"engineId_:"<<engineId_<<" not use engine";returnAPP_ERR_OK;}yolov5model.YoloV5ClearityInferenceDeinit();LogInfo<<"TrainStepTwoEngine DeInit ok";returnAPP_ERR_OK;}/**
* push数据到队列,队列满时则休眠一段时间再push
* inParam : const std::string strPort push的端口
: const