46#include <opencv2/core/utils/filesystem.hpp>
62 void set(cv::FileNode
const & item, std::string
const & zf, cv::FileNode
const & node)
64 std::string k = item.name();
68 case cv::FileNode::INT: v = std::to_string((
int)item);
break;
69 case cv::FileNode::REAL: v = std::to_string((
float)item);
break;
70 case cv::FileNode::STRING: v = (std::string)item;
break;
73 LFATAL(
"Invalid global zoo parameter " << k <<
" type " << item.type() <<
" in " << zf);
75 LFATAL(
"Invalid zoo parameter " << k <<
" type " << item.type() <<
" in " << zf <<
" node " << node.name());
79 for (
auto & p : params) if (p.first == k) { p.second = v;
return; }
80 params.emplace_back(std::make_pair(k, v));
85 std::string pget(cv::FileNode & item, std::string
const & subname)
87 std::string
const v = (std::string)item[subname];
88 if (v.empty() ==
false)
return v;
89 for (
auto const & p : params) if (p.first == subname) return p.second;
95 void unset(std::string
const & name)
97 for (
auto itr = params.begin(); itr != params.end(); ++itr)
98 if (itr->first == name) { params.erase(itr);
return; }
102 std::vector<std::pair<std::string , std::string >> params;
108 jevois::
Component(instance), itsTpre(
"PreProc"), itsTnet(
"Network"), itsTpost(
"PstProc")
114 itsAccelerators[
"OpenCV"] = 1;
115 itsAccelerators[
"ORT"] = 1;
116 itsAccelerators[
"Python"] = 1;
117#ifdef JEVOIS_PLATFORM_PRO
118 itsAccelerators[
"VPUX"] = 1;
120 itsAccelerators[
"NPUX"] = 1;
123 itsAccelerators[
"NPU"] <<
" JeVois-Pro NPUs, " <<
124 itsAccelerators[
"SPU"] <<
" Hailo8 SPUs, " <<
125 itsAccelerators[
"TPU"] <<
" Coral TPUs, " <<
126 itsAccelerators[
"VPU"] <<
" Myriad-X VPUs.");
132 preproc::freeze(doit);
133 nettype::freeze(doit);
134 postproc::freeze(doit);
136 if (itsPreProcessor) itsPreProcessor->freeze(doit);
137 if (itsNetwork) itsNetwork->freeze(doit);
138 if (itsPostProcessor) itsPostProcessor->freeze(doit);
166 return pp->latestRecognitions();
168 LFATAL(
"Cannot get recognition results if post-processor is not of type Classify");
175 return pp->latestDetections();
178 return pp->latestDetections();
180 LFATAL(
"Cannot get detection results if post-processor is not of type Detect or Pose");
187 return pp->latestDetectionsOBB();
189 LFATAL(
"Cannot get detection results if post-processor is not of type DetectOBB");
196 return pp->latestSkeletons();
198 LFATAL(
"Cannot get pose skeleton results if post-processor is not of type Pose");
205 if (itsNetFut.valid())
208 if (itsNetFut.wait_for(std::chrono::seconds(5)) == std::future_status::timeout)
209 LERROR(
"Still waiting for network to finish running...");
213 try { itsNetFut.get(); }
catch (...) { }
223 if (val != filter::get()) itsZooChanged =
true;
231 if (val.empty() ==
false && val != zooroot::get()) itsZooChanged =
true;
239 statsfile::set(
"benchmark.html");
240 statsfile::freeze(
true);
244 statsfile::freeze(
false);
253 if (val != extramodels::get()) itsZooChanged =
true;
260 itsZooChanged =
false;
263 std::vector<std::string> pipes;
265 LINFO(
"Found a total of " << pipes.size() <<
" valid pipelines.");
268 if (pipes.empty())
LFATAL(
"No pipeline available with zoo file " << val <<
" and filter " << filter::strget());
272 pipes[0], pipes, pipe::def().category());
273 pipe::changeParameterDef(newdef);
280void jevois::dnn::Pipeline::scanZoo(std::filesystem::path
const & zoofile, std::string
const & filt,
281 std::vector<std::string> & pipes, std::string
const & indent)
283 LINFO(indent <<
"Scanning model zoo file " << zoofile <<
" with filter [" << filt <<
"]...");
284 int ntot = 0, ngood = 0;
285 bool skipextra = (extramodels::get() ==
false);
287 bool has_vpu =
false;
288 auto itr = itsAccelerators.find(
"VPU");
289 if (itr != itsAccelerators.end() && itr->second > 0) has_vpu =
true;
292 cv::FileStorage fs(zoofile, cv::FileStorage::READ);
293 if (fs.isOpened() ==
false)
LFATAL(
"Could not open zoo file " << zoofile);
294 cv::FileNode fn = fs.root();
297 for (cv::FileNodeIterator fit = fn.begin(); fit != fn.end(); ++fit)
299 cv::FileNode item = *fit;
302 if (item.name() ==
"include")
307 else if (item.name() ==
"includedir")
310 for (
auto const & dent : std::filesystem::recursive_directory_iterator(dir))
311 if (dent.is_regular_file())
313 std::filesystem::path
const path = dent.path();
314 std::filesystem::path
const ext = path.extension();
315 if (ext ==
".yml" || ext ==
".yaml") scanZoo(path, filt, pipes, indent +
" ");
319 else if (item.name() ==
"unset")
321 ph.unset((std::string)item);
324 else if (! item.isMap())
326 ph.set(item, zoofile, item);
334 std::string
const isextrastr = ph.pget(item,
"extramodel");
335 if (isextrastr.empty() ==
false)
338 if (isextra)
continue;
350 std::string typ = ph.pget(item,
"nettype");
354 std::string backend = ph.pget(item,
"backend");
355 std::string target = ph.pget(item,
"target");
357 if (backend ==
"InferenceEngine")
359 if (target ==
"Myriad")
361 if (has_vpu) typ =
"VPU";
362#ifdef JEVOIS_PLATFORM_PRO
368 else if (target ==
"CPU") typ =
"VPUX";
370 else if (backend ==
"TimVX" && target ==
"NPU") typ =
"NPUX";
374 bool has_accel =
false;
375 itr = itsAccelerators.find(typ);
376 if (itr != itsAccelerators.end() && itr->second > 0) has_accel =
true;
379 if ((filt ==
"All" || typ == filt) && has_accel)
381 std::string
const postproc = ph.pget(item,
"postproc");
382 pipes.emplace_back(typ +
':' + postproc +
':' + item.name());
388 LINFO(indent <<
"Found " << ntot <<
" pipelines, " << ngood <<
" passed the filter.");
396 itsShowDataPeek =
false;
397 itsDataPeekOutIdx = 0;
398 itsDataPeekFreeze =
false;
399 itsDataPeekStr.clear();
402 if (val.empty())
return;
403 itsPipeThrew =
false;
412 if (selectPipe(z, tok) ==
false)
413 LFATAL(
"Could not find pipeline entry [" << val <<
"] in zoo file " << z <<
" and its includes");
419bool jevois::dnn::Pipeline::selectPipe(std::string
const & zoofile, std::vector<std::string>
const & tok)
422 processing::freeze(
false);
423 processing::set(jevois::dnn::pipeline::Processing::Async);
426 bool has_vpu =
false;
427 auto itr = itsAccelerators.find(
"VPU");
428 if (itr != itsAccelerators.end() && itr->second > 0) has_vpu =
true;
429 bool vpu_emu =
false;
432 itsPreStats.clear(); itsNetStats.clear(); itsPstStats.clear();
433 itsStatsWarmup =
true;
439 cv::FileStorage fs(zoofile, cv::FileStorage::READ);
440 if (fs.isOpened() ==
false)
LFATAL(
"Could not open zoo file " << zoofile);
444 cv::FileNode fn = fs.root(), node;
446 for (cv::FileNodeIterator fit = fn.begin(); fit != fn.end(); ++fit)
448 cv::FileNode item = *fit;
451 if (item.name() ==
"include")
457 else if (item.name() ==
"includedir")
460 for (
auto const & dent : std::filesystem::recursive_directory_iterator(dir))
461 if (dent.is_regular_file())
463 std::filesystem::path
const path = dent.path();
464 std::filesystem::path
const ext = path.extension();
465 if (ext ==
".yml" || ext ==
".yaml")
if (selectPipe(path, tok))
return true;
470 else if (item.name() ==
"unset")
472 ph.unset((std::string)item);
475 else if (! item.isMap())
477 ph.set(item, zoofile, node);
482 if (item.name() != tok.back())
continue;
483 if (tok.size() == 1) { node = item;
break; }
487 std::string postproc = ph.pget(item,
"postproc");
488 if (postproc != tok[1] && postproc::strget() != tok[1])
continue;
490 std::string nettype = ph.pget(item,
"nettype");
491 std::string backend = ph.pget(item,
"backend");
492 std::string target = ph.pget(item,
"target");
496 if (nettype ==
"OpenCV" && backend ==
"InferenceEngine" && target ==
"Myriad")
497 { node = item;
break; }
499 else if (tok[0] ==
"VPUX")
501 if (nettype ==
"OpenCV" && backend ==
"InferenceEngine")
503 if (target ==
"Myriad" && has_vpu ==
false) { vpu_emu =
true; node = item;
break; }
504 else if (target ==
"CPU") { node = item;
break; }
507 else if (tok[0] ==
"NPUX")
509 if (nettype ==
"OpenCV" && backend ==
"TimVX" && target ==
"NPU")
510 { node = item;
break; }
514 if (nettype == tok[0])
515 { node = item;
break; }
521 if (node.empty())
return false;
525 itsPreProcessor.reset(); removeSubComponent(
"preproc",
false);
526 itsNetwork.reset(); removeSubComponent(
"network",
false);
527 itsPostProcessor.reset(); removeSubComponent(
"postproc",
false);
530 for (cv::FileNodeIterator fit = node.begin(); fit != node.end(); ++fit)
531 ph.set(*fit, zoofile, node);
533 for (
auto const & pp : ph.params)
535 if (vpu_emu && pp.first ==
"target") setZooParam(pp.first,
"CPU", zoofile, node);
536 else setZooParam(pp.first, pp.second, zoofile, node);
545 if (processing::get() != jevois::dnn::pipeline::Processing::Sync)
547 LERROR(
"Network of type Python cannot run Async if pre- or post- processor are also Python "
548 "-- FORCING Sync processing");
549 processing::set(jevois::dnn::pipeline::Processing::Sync);
551 processing::freeze(
true);
555 itsSettings = std::move(ph.params);
561std::vector<std::pair<std::string , std::string >>
const &
563{
return itsSettings; }
566void jevois::dnn::Pipeline::setZooParam(std::string
const & k, std::string
const & v,
567 std::string
const & zf, cv::FileNode
const & node)
570 if (k ==
"extramodel")
return;
574 bool hasparam =
false;
575 try { getParamStringUnique(k); hasparam =
true; }
catch (...) { }
579 LINFO(
"Setting ["<<k<<
"] to ["<<v<<
']');
581 try { setParamStringUnique(k, v); }
582 catch (std::exception
const & e)
583 {
LFATAL(
"While parsing [" << node.name() <<
"] in model zoo file " << zf <<
": " << e.what()); }
585 {
LFATAL(
"While parsing [" << node.name() <<
"] in model zoo file " << zf <<
": unknown error"); }
587 else if (paramwarn::get())
588 engine()->
reportError(
"WARNING: Unused parameter [" + k +
"] in " + zf +
" node [" + node.name() +
"]");
594 itsPreProcessor.reset(); removeSubComponent(
"preproc",
false);
598 case jevois::dnn::pipeline::PreProc::Blob:
599 itsPreProcessor = addSubComponent<jevois::dnn::PreProcessorBlob>(
"preproc");
602 case jevois::dnn::pipeline::PreProc::Python:
603 itsPreProcessor = addSubComponent<jevois::dnn::PreProcessorPython>(
"preproc");
607 if (itsPreProcessor)
LINFO(
"Instantiated pre-processor of type " << itsPreProcessor->className());
608 else LINFO(
"No pre-processor");
616 itsNetwork.reset(); removeSubComponent(
"network",
false);
620 case jevois::dnn::pipeline::NetType::OpenCV:
621 itsNetwork = addSubComponent<jevois::dnn::NetworkOpenCV>(
"network");
626 case jevois::dnn::pipeline::NetType::ORT:
627 itsNetwork = addSubComponent<jevois::dnn::NetworkONNX>(
"network");
630 case jevois::dnn::pipeline::NetType::NPU:
631#ifdef JEVOIS_PLATFORM
632 itsNetwork = addSubComponent<jevois::dnn::NetworkNPU>(
"network");
634 LFATAL(
"NPU network is only supported on JeVois-Pro Platform");
638 case jevois::dnn::pipeline::NetType::SPU:
639 itsNetwork = addSubComponent<jevois::dnn::NetworkHailo>(
"network");
642 case jevois::dnn::pipeline::NetType::TPU:
643 itsNetwork = addSubComponent<jevois::dnn::NetworkTPU>(
"network");
647 case jevois::dnn::pipeline::NetType::Python:
648 itsNetwork = addSubComponent<jevois::dnn::NetworkPython>(
"network");
652 if (itsNetwork)
LINFO(
"Instantiated network of type " << itsNetwork->className());
653 else LINFO(
"No network");
658 itsInputAttrs.clear();
660 itsNetInfo.emplace_back(
"* Input Tensors");
661 itsNetInfo.emplace_back(
"Initializing network...");
662 itsNetInfo.emplace_back(
"* Network");
663 itsNetInfo.emplace_back(
"Initializing network...");
664 itsNetInfo.emplace_back(
"* Output Tensors");
665 itsNetInfo.emplace_back(
"Initializing network...");
666 itsAsyncNetInfo = itsNetInfo;
667 itsAsyncNetworkTime =
"Network: -";
668 itsAsyncNetworkSecs = 0.0;
676 itsPostProcessor.reset(); removeSubComponent(
"postproc",
false);
680 case jevois::dnn::pipeline::PostProc::Classify:
681 itsPostProcessor = addSubComponent<jevois::dnn::PostProcessorClassify>(
"postproc");
683 case jevois::dnn::pipeline::PostProc::Detect:
684 itsPostProcessor = addSubComponent<jevois::dnn::PostProcessorDetect>(
"postproc");
686 case jevois::dnn::pipeline::PostProc::DetectOBB:
687 itsPostProcessor = addSubComponent<jevois::dnn::PostProcessorDetectOBB>(
"postproc");
689 case jevois::dnn::pipeline::PostProc::Segment:
690 itsPostProcessor = addSubComponent<jevois::dnn::PostProcessorSegment>(
"postproc");
692 case jevois::dnn::pipeline::PostProc::YuNet:
693 itsPostProcessor = addSubComponent<jevois::dnn::PostProcessorYuNet>(
"postproc");
695 case jevois::dnn::pipeline::PostProc::Pose:
696 itsPostProcessor = addSubComponent<jevois::dnn::PostProcessorPose>(
"postproc");
698 case jevois::dnn::pipeline::PostProc::Python:
699 itsPostProcessor = addSubComponent<jevois::dnn::PostProcessorPython>(
"postproc");
701 case jevois::dnn::pipeline::PostProc::Stub:
702 itsPostProcessor = addSubComponent<jevois::dnn::PostProcessorStub>(
"postproc");
706 if (itsPostProcessor)
LINFO(
"Instantiated post-processor of type " << itsPostProcessor->className());
707 else LINFO(
"No post-processor");
713 return itsPreProcessor && itsNetwork && itsNetwork->ready() && itsPostProcessor;
719 if (itsNetFut.valid() && itsNetFut.wait_for(std::chrono::milliseconds(2)) == std::future_status::ready)
721 itsOuts = itsNetFut.get();
723 std::swap(itsNetInfo, itsAsyncNetInfo);
724 itsProcTimes[1] = itsAsyncNetworkTime;
725 itsProcSecs[1] = itsAsyncNetworkSecs;
736 if (itsZooChanged) zoo::set(zoo::get());
740 if (itsPipeThrew)
return;
742 bool const ovl = overlay::get();
744 bool refresh_data_peek =
false;
748 if (helper && idle ==
false)
751 ImGui::SetNextWindowPos(ImVec2(24, 159), ImGuiCond_FirstUseEver);
752 ImGui::SetNextWindowSize(ImVec2(464, 877), ImGuiCond_FirstUseEver);
755 ImGui::Begin((instanceName() +
':' + getParamStringUnique(
"pipe")).c_str());
772 if (helper) helper->
itext(instanceName() +
':' + getParamStringUnique(
"pipe"));
780 if (ready() ==
false)
782 char const * msg = itsNetwork ?
"Loading network..." :
"No network selected...";
793 if (idle ==
false) ImGui::TextUnformatted(msg);
794 if (ovl) helper->
itext(msg);
798 itsProcTimes = {
"PreProc: -",
"Network: -",
"PstProc: -" };
799 itsProcSecs = { 0.0, 0.0, 0.0 };
804 switch (processing::get())
807 case jevois::dnn::pipeline::Processing::Sync:
813 if (itsInputAttrs.empty()) itsInputAttrs = itsNetwork->inputShapes();
814 itsBlobs = itsPreProcessor->process(inimg, itsInputAttrs);
815 itsProcTimes[0] = itsTpre.stop(&itsProcSecs[0]);
816 itsPreProcessor->sendreport(mod, outimg, helper, ovl, idle);
821 itsOuts = itsNetwork->process(itsBlobs, itsNetInfo);
822 itsProcTimes[1] = itsTnet.stop(&itsProcSecs[1]);
825 showInfo(itsNetInfo, mod, outimg, helper, ovl, idle);
829 itsPostProcessor->process(itsOuts, itsPreProcessor.get());
830 itsProcTimes[2] = itsTpost.stop(&itsProcSecs[2]);
831 itsPostProcessor->report(mod, outimg, helper, ovl, idle);
832 refresh_data_peek =
true;
837 case jevois::dnn::pipeline::Processing::Async:
844 bool needpost = checkAsyncNetComplete();
847 if (itsNetFut.valid() ==
false)
851 if (itsInputAttrs.empty()) itsInputAttrs = itsNetwork->inputShapes();
852 itsBlobs = itsPreProcessor->process(inimg, itsInputAttrs);
853 itsProcTimes[0] = itsTpre.stop(&itsProcSecs[0]);
860 std::vector<cv::Mat> outs = itsNetwork->process(itsBlobs, itsAsyncNetInfo);
861 itsAsyncNetworkTime = itsTnet.stop(&itsAsyncNetworkSecs);
868 std::vector<cv::Mat> outscopy;
869 for (cv::Mat
const & m : outs) outscopy.emplace_back(m.clone());
875 itsPreProcessor->sendreport(mod, outimg, helper, ovl, idle);
878 showInfo(itsNetInfo, mod, outimg, helper, ovl, idle);
881 if (needpost && itsOuts.empty() ==
false)
884 itsPostProcessor->process(itsOuts, itsPreProcessor.get());
885 itsProcTimes[2] = itsTpost.stop(&itsProcSecs[2]);
886 refresh_data_peek =
true;
890 itsPostProcessor->report(mod, outimg, helper, ovl, idle);
896 itsSecsSum += itsProcSecs[0] + itsProcSecs[1] + itsProcSecs[2];
897 if (++itsSecsSumNum == 20) { itsSecsAvg = itsSecsSum / itsSecsSumNum; itsSecsSum = 0.0; itsSecsSumNum = 0; }
900 if (statsfile::get().empty() ==
false && itsOuts.empty() ==
false)
902 static std::vector<std::string> pipelines;
903 static bool statswritten =
false;
904 static bool write_separator =
false;
905 static size_t benchpipe = 0;
906 size_t constexpr numwarmup = 25;
907 size_t constexpr numbench = 100;
909 if (benchmark::get())
912 if (helper && ImGui::Begin(
"Benchmarking in progress"))
914 ImGui::TextUnformatted(pipe::strget().c_str());
915 if (itsStatsWarmup) ImGui::Text(
"Warmup %zu / %zu", itsPreStats.size(), numwarmup);
916 else ImGui::Text(
"Iteration %zu / %zu", itsPreStats.size(), numbench);
921 if (pipelines.empty())
925 std::string pipes = pipe::def().validValuesString();
926 size_t const idx = pipes.find(
'[');
927 pipes = pipes.substr(idx + 1, pipes.length() - idx - 2);
930 statswritten =
false;
931 pipe::set(pipelines[benchpipe]);
932 processing::freeze(
false);
933 processing::set(jevois::dnn::pipeline::Processing::Sync);
940 std::string oldaccel = pipelines[benchpipe].substr(0, pipelines[benchpipe].find(
':'));
942 statswritten =
false;
943 if (benchpipe >= pipelines.size())
946 benchmark::set(
false);
947 LINFO(
"Benchmark complete.");
951 if (oldaccel != pipelines[benchpipe].substr(0, pipelines[benchpipe].find(
':'))) write_separator =
true;
952 pipe::set(pipelines[benchpipe]);
953 processing::freeze(
false);
954 processing::set(jevois::dnn::pipeline::Processing::Sync);
959 else pipelines.clear();
961 itsPreStats.push_back(itsProcSecs[0]);
962 itsNetStats.push_back(itsProcSecs[1]);
963 itsPstStats.push_back(itsProcSecs[2]);
966 if (itsStatsWarmup && itsPreStats.size() == numwarmup)
967 { itsStatsWarmup =
false; itsPreStats.clear(); itsNetStats.clear(); itsPstStats.clear(); }
969 if (itsPreStats.size() == numbench)
972 std::vector<double> tot;
973 for (
size_t i = 0; i < itsPreStats.size(); ++i)
974 tot.emplace_back(itsPreStats[i] + itsNetStats[i] + itsPstStats[i]);
978 std::ofstream ofs(fn, std::ios_base::app);
983 ofs <<
"<tr><td colspan=8></td></tr><tr><td colspan=8></td></tr>" << std::endl;
984 write_separator =
false;
987 ofs <<
"<tr><td class=jvpipe>" << pipe::get() <<
" </td>";
989 std::vector<std::string> insizes;
990 for (cv::Mat
const & m : itsBlobs)
992 ofs <<
"<td class=jvnetin>" <<
jevois::join(insizes,
", ") <<
"</td>";
994 std::vector<std::string> outsizes;
995 for (cv::Mat
const & m : itsOuts)
997 ofs <<
"<td class=jvnetout>" <<
jevois::join(outsizes,
", ") <<
"</td>";
1007 for (
double t : tot) avg += t;
1009 if (avg) avg = 1.0 / avg;
1010 ofs <<
"<td class=jvfps>" << std::fixed << std::showpoint << std::setprecision(1) <<
1011 avg <<
" fps</td></tr>" << std::endl;
1014 itsPreStats.clear();
1015 itsNetStats.clear();
1016 itsPstStats.clear();
1017 LINFO(
"Network stats appended to " << fn);
1018 statswritten =
true;
1026 itsPipeThrew =
true;
1046 if (ImGui::CollapsingHeader(
"Processing Times", ImGuiTreeNodeFlags_DefaultOpen))
1048 for (std::string
const & s : itsProcTimes) ImGui::TextUnformatted(s.c_str());
1049 ImGui::Text(
"OVERALL: %s/inference", total.c_str());
1054 if (ImGui::Button(
"Peek output data")) itsShowDataPeek =
true;
1060 showDataPeekWindow(helper, refresh_data_peek);
1065 for (std::string
const & s : itsProcTimes) helper->
itext(s);
1066 helper->
itext(
"OVERALL: " + total +
"/inference");
1070 (void)refresh_data_peek;
1076 for (std::string
const & s : itsProcTimes)
1093 for (std::string
const & s : info)
1097 if (helper && idle ==
false)
1101 show = ImGui::CollapsingHeader(s.c_str() + 2, ImGuiTreeNodeFlags_DefaultOpen);
1106 else ImGui::TextUnformatted(s.c_str());
1110 (void)idle; (void)show; (void)helper;
1126 if (itsShowDataPeek ==
false)
return;
1129 ImGui::SetNextWindowPos(ImVec2(100, 50), ImGuiCond_FirstUseEver);
1130 ImGui::SetNextWindowSize(ImVec2(900, 600), ImGuiCond_FirstUseEver);
1133 ImGui::PushStyleColor(ImGuiCol_WindowBg, 0xf0ffe0e0);
1136 ImGui::Begin(
"DNN Output Peek", &itsShowDataPeek, ImGuiWindowFlags_HorizontalScrollbar);
1139 std::vector<std::string> outspecs;
1140 for (
size_t i = 0; cv::Mat
const & out : itsOuts)
1142 if (helper->
combo(
"##dataPeekOutSelect", outspecs, itsDataPeekOutIdx)) itsDataPeekFreeze =
false;
1144 ImGui::SameLine(); ImGui::TextUnformatted(
" "); ImGui::SameLine();
1149 if ( (itsDataPeekFreeze && itsDataPeekStr.empty() ==
false) || refresh ==
false)
1150 ImGui::TextUnformatted(itsDataPeekStr.c_str());
1154 cv::Mat
const & out = itsOuts[itsDataPeekOutIdx];
1155 std::vector<int> newsz;
1156 cv::MatSize
const & ms = out.size;
int const nd = ms.dims();
1157 for (
int i = 0; i < nd; ++i)
if (ms[i] > 1) newsz.emplace_back(ms[i]);
1158 cv::Mat
const out2(newsz, out.type(), out.data);
1162 std::ostringstream oss;
1163 if (newsz.size() > 3)
1164 throw "too many dims";
1165 else if (newsz.size() == 3)
1167 cv::Range ranges[3];
1168 ranges[2] = cv::Range::all();
1169 ranges[1] = cv::Range::all();
1170 for (
int i = 0; i < newsz[0]; ++i)
1172 oss <<
"-------------------------------------------------------------------------------\n";
1173 oss <<
"Third dimension index = " << i <<
":\n";
1174 oss <<
"-------------------------------------------------------------------------------\n\n";
1175 ranges[0] = cv::Range(i, i+1);
1176 cv::Mat slice = out2(ranges);
1177 cv::Mat slice2d(cv::Size(newsz[2], newsz[1]), slice.type(), slice.data);
1178 oss << slice2d <<
"\n\n";
1184 itsDataPeekStr = oss.str();
1186 catch (...) { itsDataPeekStr =
"Sorry, cannot display this type of tensor..."; }
1188 ImGui::TextUnformatted(itsDataPeekStr.c_str());
1190 if (out2.total() > 10000)
1192 helper->
reportError(
"Large data peek - Freezing data display\n"
1193 "Click the Freeze button to refresh once");
1194 itsDataPeekFreeze =
true;
1200 ImGui::PopStyleColor();
#define JEVOIS_SHARE_PATH
Base path for shared files (e.g., neural network weights, etc)
A component of a model hierarchy.
void clearErrors()
Clear all errors currently displayed in the JeVois-Pro GUI.
void reportError(std::string const &err)
Helper class to assist modules in creating graphical and GUI elements.
bool combo(std::string const &name, std::vector< std::string > const &items, int &selected_index)
Helper to draw a combobox from a vector of strings.
void reportAndIgnoreException(std::string const &prefix="")
Report current exception in a modal dialog, then ignore it.
void reportError(std::string const &err)
Report an error in an overlay window.
void itext(char const *txt, ImU32 const &col=IM_COL32_BLACK_TRANS, int line=-1)
Draw some overlay text on top of an image.
bool toggleButton(char const *name, bool *val)
Helper to draw a toggle button.
A raw image as coming from a V4L2 Camera and/or being sent out to a USB Gadget.
Base class for a module that supports standardized serial messages.
Wrapper around an OpenCV DNN neural network.
Wrapper around an DNN neural network invoked through python.
std::vector< ObjDetectOBB > const & latestDetectionsOBB() const
Get the latest oriented bounded box (OBB) detection results, use with caution, not thread-safe.
bool checkAsyncNetComplete()
void showInfo(std::vector< std::string > const &info, jevois::StdModule *mod, jevois::RawImage *outimg, jevois::OptGUIhelper *helper, bool ovl, bool idle)
void preUninit() override
Called before all sub-Components are uninit()ed.
void showDataPeekWindow(jevois::GUIhelper *helper, bool refresh)
std::vector< ObjReco > const & latestRecognitions() const
Get the latest recognition results, use with caution, not thread-safe.
void process(jevois::RawImage const &inimg, jevois::StdModule *mod, jevois::RawImage *outimg, jevois::OptGUIhelper *helper, bool idle=false)
Process an input image, send results to serial/image/gui.
void onParamChange(pipeline::zooroot const ¶m, std::string const &val) override
virtual ~Pipeline()
Destructor.
bool ready() const
Returns true when all three of preproc, net, and postproc are ready.
std::vector< std::pair< std::string, std::string > > const & zooSettings() const
Get access to the settings that were loaded from the zoo.
Pipeline(std::string const &instance)
Constructor.
void freeze(bool doit)
Freeze/unfreeze parameters that users should not change while running.
std::vector< PoseSkeleton > const & latestSkeletons() const
Get the latest skeletons, use with caution, not thread-safe.
std::vector< ObjDetect > const & latestDetections() const
Get the latest detection results, use with caution, not thread-safe.
void postInit() override
Called after all sub-Components are init()ed.
Post-Processor for neural network pipeline.
Post-Processor for neural network pipeline for oriented bounding box (OBB) object detection.
Post-Processor for neural network pipeline.
Post-Processor for neural network pipeline, for human/animal/other pose detection (skeleton)
Post-Processor for neural network pipeline.
Pre-Processor for neural network pipeline written in python.
#define LFATAL(msg)
Convenience macro for users to print out console or syslog messages, FATAL level.
std::string warnAndIgnoreException(std::string const &prefix="")
Convenience function to catch an exception, issue some LERROR (depending on type),...
#define LERROR(msg)
Convenience macro for users to print out console or syslog messages, ERROR level.
#define LINFO(msg)
Convenience macro for users to print out console or syslog messages, INFO level.
std::string shapestr(cv::Mat const &m)
Get a string of the form: "nD AxBxC... TYPE" from an n-dimensional cv::Mat with data type TYPE.
void writeText(RawImage &img, std::string const &txt, int x, int y, unsigned int col, Font font=Font6x10)
Write some text in an image.
void paramStringToVal(std::string const &valstring, T &result)
Machine-readable conversion from string to T, for use in jevois::Parameter.
std::future< std::invoke_result_t< std::decay_t< Function >, std::decay_t< Args >... > > async(Function &&f, Args &&... args)
Async execution using a thread pool.
std::string secs2str(double secs)
Report a duration given in seconds with variable units (ns, us, ms, or s), with precision of 2 decima...
std::string join(std::vector< T > const &tokens, std::string const &delimiter)
Concatenate a vector of tokens into a string.
std::filesystem::path absolutePath(std::filesystem::path const &root, std::filesystem::path const &path)
Compute an absolute path from two paths.
bool stringStartsWith(std::string const &str, std::string const &prefix)
Return true if str starts with prefix (including if both strings are equal)
std::vector< std::string > split(std::string const &input, std::string const ®ex="\\s+")
Split string into vector of tokens using a regex to specify what to split on; default regex splits by...
std::string replaceAll(std::string const &str, std::string const &from, std::string const &to)
Replace all instances of 'from' with 'to'.
unsigned short constexpr White
YUYV color value.
Main namespace for all JeVois classes and functions.
size_t getNumInstalledVPUs()
Get the number of Myriad-X VPUs present on this system.
size_t getNumInstalledNPUs()
Get the number of JeVois-Pro NPUs present on this system.
size_t getNumInstalledTPUs()
Get the number of Coral TPUs present on this system.
size_t getNumInstalledSPUs()
Get the number of Hailo8 SPUs present on this system.