28 dataroot::freeze(doit);
31 backend::freeze(doit);
33 intensors::freeze(doit);
34 outtensors::freeze(doit);
54 if (itsNet.empty() ==
false) itsNet = cv::dnn::Net();
59 if (config::get().empty())
LINFO(
"Loading " << m <<
" ...");
else LINFO(
"Loading " << m <<
" / " << c <<
" ...");
62 itsNet = cv::dnn::readNet(m, c);
64 switch(backend::get())
67 case network::Backend::OpenCV: itsNet.setPreferableBackend(cv::dnn::DNN_BACKEND_OPENCV);
break;
68 case network::Backend::InferenceEngine: itsNet.setPreferableBackend(cv::dnn::DNN_BACKEND_INFERENCE_ENGINE);
break;
69 case network::Backend::TimVX: itsNet.setPreferableBackend(cv::dnn::DNN_BACKEND_TIMVX);
break;
71 case network::Backend::Default: itsNet.setPreferableBackend(cv::dnn::DNN_BACKEND_DEFAULT);
break;
77 case network::Target::CPU: itsNet.setPreferableTarget(cv::dnn::DNN_TARGET_CPU);
break;
79 case network::Target::OpenCL: itsNet.setPreferableTarget(cv::dnn::DNN_TARGET_OPENCL);
break;
80 case network::Target::OpenCL_FP16: itsNet.setPreferableTarget(cv::dnn::DNN_TARGET_OPENCL_FP16);
break;
81 case network::Target::Myriad: itsNet.setPreferableTarget(cv::dnn::DNN_TARGET_MYRIAD);
break;
82 case network::Target::NPU: itsNet.setPreferableTarget(cv::dnn::DNN_TARGET_NPU);
break;
85 LINFO(
"Backend: " << backend::get() <<
", Target: " << target::get());
88 itsOutNames = itsNet.getUnconnectedOutLayersNames();
90 for (
auto const & s : itsOutNames)
LINFO(
"Output layer " << i++ <<
": " << s);
95 std::vector<std::string> & info)
97 if (blobs.size() != 1)
LFATAL(
"Expecting exactly one input blob");
99 if (itsNet.empty())
LFATAL(
"Internal inconsistency");
101 itsNet.setInput(blobs[0]);
102 std::vector<cv::Mat> outs;
103 itsNet.forward(outs, itsOutNames);
106 if (itsFLOPS.empty())
108 std::vector<cv::dnn::MatShape> inshapes;
109 for (
size_t i = 0; i < blobs.size(); ++i)
111 cv::dnn::MatShape s; cv::MatSize
const & ms = blobs[i].size;
112 for (
int k = 0; k < ms.dims(); ++k) s.emplace_back(ms[k]);
113 inshapes.emplace_back(s);
118 info.emplace_back(
"Forward Network: " + itsFLOPS);
std::vector< cv::Mat > doprocess(std::vector< cv::Mat > const &blobs, std::vector< std::string > &info) override
Process input blobs and obtain output blobs.
virtual std::vector< vsi_nn_tensor_attr_t > outputShapes() override
Get shapes of all output tensors.
virtual std::vector< vsi_nn_tensor_attr_t > inputShapes() override
Get shapes of all input tensors.
void load() override
Load from disk.
virtual ~NetworkOpenCV()
Destructor.
void freeze(bool doit) override
Freeze/unfreeze parameters that users should not change while running.
void waitBeforeDestroy()
If network is currently loading, wait until that is done before destroying.
virtual void freeze(bool doit)
Freeze/unfreeze parameters that users should not change while running.
#define LFATAL(msg)
Convenience macro for users to print out console or syslog messages, FATAL level.
#define LINFO(msg)
Convenience macro for users to print out console or syslog messages, INFO level.
std::vector< vsi_nn_tensor_attr_t > parseTensorSpecs(std::string const &specs)
Parse tensor specification.
std::string num2str(double n)
Report a number with variable multipliers (K, M, G, T, P, E, Z, Y), with precision of 2 decimal point...
std::filesystem::path absolutePath(std::filesystem::path const &root, std::filesystem::path const &path)
Compute an absolute path from two paths.