feat 添加缺锡模型

dev_lsy
liusiyang 2 weeks ago
parent 456b56e8d4
commit 11d7e22d64

@ -154,6 +154,7 @@ public:
private: private:
public: public:
std::shared_ptr<AIModel_Base> Defect; std::shared_ptr<AIModel_Base> Defect;
std::shared_ptr<AIModel_Base> Defect_QueXi;
std::shared_ptr<AIModel_Base> Class; std::shared_ptr<AIModel_Base> Class;
std::shared_ptr<AIModel_Base> Pin_Loc; std::shared_ptr<AIModel_Base> Pin_Loc;

@ -43,11 +43,22 @@ int AIFactory::InitALLAIModle(GPU_Config gupconfig)
AIModel_Base::AIModelRun_Config edge_config; AIModel_Base::AIModelRun_Config edge_config;
edge_config.gpuconfig.copy(gupconfig); edge_config.gpuconfig.copy(gupconfig);
edge_config.strPath = "/home/aidlux/BOE/UseModel_ZB/KK/Defect.engine"; edge_config.strPath = "/home/aidlux/BOE/UseModel_ZB/KK/Defect.engine";
edge_config.strName = "CA_Det"; edge_config.strName = "Det";
edge_config.inputType = AIModel_Base::Input_CHW; edge_config.inputType = AIModel_Base::Input_CHW;
edge_config.Stream_num = 2; edge_config.Stream_num = 2;
Defect->Init(edge_config); Defect->Init(edge_config);
} }
if (!Defect_QueXi)
{
Defect_QueXi = AIModel_Base::GetInstance();
AIModel_Base::AIModelRun_Config edge_config;
edge_config.gpuconfig.copy(gupconfig);
edge_config.strPath = "/home/aidlux/BOE/UseModel_ZB/KK/QueXi.engine";
edge_config.strName = "QueXi_Det";
edge_config.inputType = AIModel_Base::Input_CHW;
edge_config.Stream_num = 2;
Defect_QueXi->Init(edge_config);
}
if (!Class) if (!Class)
{ {
Class = AIModel_Base::GetInstance(); Class = AIModel_Base::GetInstance();
@ -55,7 +66,7 @@ int AIFactory::InitALLAIModle(GPU_Config gupconfig)
jbl_config.gpuconfig.copy(gupconfig); jbl_config.gpuconfig.copy(gupconfig);
jbl_config.strPath = "/home/aidlux/BOE/UseModel_ZB/KK/Class.engine"; jbl_config.strPath = "/home/aidlux/BOE/UseModel_ZB/KK/Class.engine";
jbl_config.inputType = AIModel_Base::Input_CHW; jbl_config.inputType = AIModel_Base::Input_CHW;
jbl_config.strName = "CA_Class"; jbl_config.strName = "Class";
jbl_config.IsClass = true; jbl_config.IsClass = true;
Class->Init(jbl_config); Class->Init(jbl_config);
} }
@ -65,7 +76,7 @@ int AIFactory::InitALLAIModle(GPU_Config gupconfig)
AIModel_Base::AIModelRun_Config edge_config; AIModel_Base::AIModelRun_Config edge_config;
edge_config.gpuconfig.copy(gupconfig); edge_config.gpuconfig.copy(gupconfig);
edge_config.strPath = "/home/aidlux/BOE/UseModel_ZB/KK/PinLoc.engine"; edge_config.strPath = "/home/aidlux/BOE/UseModel_ZB/KK/PinLoc.engine";
edge_config.strName = "TA_Det"; edge_config.strName = "Pin_Loc";
edge_config.inputType = AIModel_Base::Input_CHW; edge_config.inputType = AIModel_Base::Input_CHW;
edge_config.Stream_num = 2; edge_config.Stream_num = 2;
Pin_Loc->Init(edge_config); Pin_Loc->Init(edge_config);
@ -76,7 +87,7 @@ int AIFactory::InitALLAIModle(GPU_Config gupconfig)
AIModel_Base::AIModelRun_Config edge_config; AIModel_Base::AIModelRun_Config edge_config;
edge_config.gpuconfig.copy(gupconfig); edge_config.gpuconfig.copy(gupconfig);
edge_config.strPath = "/home/aidlux/BOE/UseModel_ZB/KK/AlignOuter.engine"; edge_config.strPath = "/home/aidlux/BOE/UseModel_ZB/KK/AlignOuter.engine";
edge_config.strName = "Align"; edge_config.strName = "Align_Outer";
edge_config.inputType = AIModel_Base::Input_CHW; edge_config.inputType = AIModel_Base::Input_CHW;
Align_Outer->Init(edge_config); Align_Outer->Init(edge_config);
} }
@ -86,7 +97,7 @@ int AIFactory::InitALLAIModle(GPU_Config gupconfig)
AIModel_Base::AIModelRun_Config edge_config; AIModel_Base::AIModelRun_Config edge_config;
edge_config.gpuconfig.copy(gupconfig); edge_config.gpuconfig.copy(gupconfig);
edge_config.strPath = "/home/aidlux/BOE/UseModel_ZB/KK/AlignInner.engine"; edge_config.strPath = "/home/aidlux/BOE/UseModel_ZB/KK/AlignInner.engine";
edge_config.strName = "Mark"; edge_config.strName = "Align_Inner";
edge_config.inputType = AIModel_Base::Input_CHW; edge_config.inputType = AIModel_Base::Input_CHW;
Align_Inner->Init(edge_config); Align_Inner->Init(edge_config);
} }

@ -1297,12 +1297,10 @@ int ImgCheckAnalysisy::ConfigCheck(cv::Mat img)
int ImgCheckAnalysisy::AI_Detect_Thread(const cv::Mat &img, cv::Mat &ResultImg) int ImgCheckAnalysisy::AI_Detect_Thread(const cv::Mat &img, cv::Mat &ResultImg)
{ {
std::shared_ptr<AIModel_Base> pAIDet; // 依次使用多个检测模型,各模型输出 mask 取并集作为最终 outmask
// printf("=====>>>>AI_Detect_Thread m_strCurDetChannel %s \n", m_strCurDetChannel.c_str()); std::vector<std::shared_ptr<AIModel_Base>> pAIDetList;
{ pAIDetList.push_back(AI_Factory->Defect);
// printf("=====>>>>AI_Detect_Thread USE CA %s \n", m_strCurDetChannel.c_str()); pAIDetList.push_back(AI_Factory->Defect_QueXi);
pAIDet = AI_Factory->Defect;
}
std::string strBaseLog = "AI_Detect"; std::string strBaseLog = "AI_Detect";
@ -1318,8 +1316,8 @@ int ImgCheckAnalysisy::AI_Detect_Thread(const cv::Mat &img, cv::Mat &ResultImg)
cutRoi.width = img.cols - 0; cutRoi.width = img.cols - 0;
cutRoi.height = img.rows - 0; cutRoi.height = img.rows - 0;
int deal_image_width = pAIDet->input_0.width; int deal_image_width = pAIDetList[0]->input_0.width;
int deal_image_height = pAIDet->input_0.height; int deal_image_height = pAIDetList[0]->input_0.height;
int re = CheckUtil::cutSmallImg(img, SmallRoiList, cutRoi, deal_image_width, deal_image_height, 0, 0); int re = CheckUtil::cutSmallImg(img, SmallRoiList, cutRoi, deal_image_width, deal_image_height, 0, 0);
@ -1355,60 +1353,81 @@ int ImgCheckAnalysisy::AI_Detect_Thread(const cv::Mat &img, cv::Mat &ResultImg)
ResultImg = cv::Mat::zeros(img.size(), CV_8UC1); ResultImg = cv::Mat::zeros(img.size(), CV_8UC1);
const int totalTasks = SmallRoiList.size(); const int totalTasks = SmallRoiList.size();
int submitted = 0;
int completed = 0;
// std::string str_Root = m_strRootPath + pDetConfig->strProductID + "_" + pDetConfig->strchannel + "_"; // std::string str_Root = m_strRootPath + pDetConfig->strProductID + "_" + pDetConfig->strchannel + "_";
t2 = CheckUtil::getcurTime(); t2 = CheckUtil::getcurTime();
while (completed < totalTasks)
// 依次用多个模型做检测,所有模型输出的 mask 取并集作为最终 outmask
for (size_t m = 0; m < pAIDetList.size(); m++)
{ {
// 如果任务还没提交完,且当前处理任务数 < 2提交新任务 std::shared_ptr<AIModel_Base> pAIDet = pAIDetList[m];
if (submitted < totalTasks && runner->GetProcessingCount() < 10) int submitted = 0;
int completed = 0;
while (completed < totalTasks)
{ {
// 如果任务还没提交完,且当前处理任务数 < 10提交新任务
if (submitted < totalTasks && runner->GetProcessingCount() < 10)
{
std::shared_ptr<AIMulThreadRunBase::AITask> task = std::make_shared<AIMulThreadRunBase::AITask>(); std::shared_ptr<AIMulThreadRunBase::AITask> task = std::make_shared<AIMulThreadRunBase::AITask>();
task->id = completed; task->id = submitted;
task->roi = SmallRoiList.at(submitted); task->roi = SmallRoiList.at(submitted);
task->input = img(SmallRoiList.at(submitted)).clone(); task->input = img(SmallRoiList.at(submitted)).clone();
task->output = std::make_shared<cv::Mat>(); task->output = std::make_shared<cv::Mat>();
task->engine = pAIDet; task->engine = pAIDet;
runner->SubmitTask(task);
submitted++;
}
// 尝试取结果
std::shared_ptr<AIMulThreadRunBase::AITask> result;
if (runner->PopResult(result))
{
{ runner->SubmitTask(task);
std::lock_guard<std::mutex> lock(mtx_AIMaskImgBLobQueue); submitted++;
m_AIMaskImgBLobQueue.push(result);
} }
cv::Mat &outimg = *(result->output); // 尝试取结果
if (!outimg.empty()) std::shared_ptr<AIMulThreadRunBase::AITask> result;
if (runner->PopResult(result))
{ {
outimg.copyTo(ResultImg(result->roi), outimg);
{
std::lock_guard<std::mutex> lock(mtx_AIMaskImgBLobQueue);
m_AIMaskImgBLobQueue.push(result);
}
cv::Mat &outimg = *(result->output);
if (!outimg.empty())
{
// 多个模型的结果取并集
cv::Mat roiMat = ResultImg(result->roi);
cv::bitwise_or(roiMat, outimg, roiMat);
}
// 同一 roi 的多个模型结果取并集后存入 AI_Qx_MaskList
bool bFind = false;
for (auto &item : m_pImageAllResult->AI_Qx_MaskList)
{
if (item->roi == result->roi)
{
cv::bitwise_or(item->AI_mask, outimg, item->AI_mask);
bFind = true;
break;
}
}
if (!bFind)
{
std::shared_ptr<ImageAllResult::AI_Det_MaskImg> temAIresult = std::make_shared<ImageAllResult::AI_Det_MaskImg>();
temAIresult->roi = result->roi;
temAIresult->AI_inImg = result->input;
temAIresult->AI_mask = outimg.clone();
m_pImageAllResult->AI_Qx_MaskList.push_back(temAIresult);
}
completed++;
} }
else
{ {
std::shared_ptr<ImageAllResult::AI_Det_MaskImg> temAIresult = std::make_shared<ImageAllResult::AI_Det_MaskImg>(); std::this_thread::sleep_for(std::chrono::milliseconds(1));
temAIresult->roi = result->roi;
temAIresult->AI_inImg = result->input;
temAIresult->AI_mask = outimg;
m_pImageAllResult->AI_Qx_MaskList.push_back(temAIresult);
} }
completed++;
}
else
{
std::this_thread::sleep_for(std::chrono::milliseconds(1));
} }
} }
t3 = CheckUtil::getcurTime(); t3 = CheckUtil::getcurTime();
float mean_AI = (t3 - t2) / SmallRoiList.size(); float mean_AI = (t3 - t2) / (SmallRoiList.size() * pAIDetList.size());
m_pdetlog->AddCheckstr(PrintLevel_1, DET_LOG_LEVEL_3, strBaseLog, " AI Run Time: sum %ld pre %ld Run %ld mean One Small Img %f", t3 - t1, t2 - t1, t3 - t2, mean_AI); m_pdetlog->AddCheckstr(PrintLevel_1, DET_LOG_LEVEL_3, strBaseLog, " AI Run Time: sum %ld pre %ld Run %ld mean One Small Img %f", t3 - t1, t2 - t1, t3 - t2, mean_AI);
m_pdetlog->AddCheckstr(PrintLevel_0, DET_LOG_LEVEL_3, strBaseLog, "AI_Detect End"); m_pdetlog->AddCheckstr(PrintLevel_0, DET_LOG_LEVEL_3, strBaseLog, "AI_Detect End");

Loading…
Cancel
Save