mexopencv  3.4.1
MEX interface for OpenCV library
Net_.cpp
Go to the documentation of this file.
1 
8 #include "mexopencv.hpp"
9 #include "opencv2/dnn.hpp"
10 using namespace std;
11 using namespace cv;
12 using namespace cv::dnn;
13 
14 // Persistent objects
15 namespace {
17 int last_id = 0;
20 
23  ("Default", cv::dnn::DNN_BACKEND_DEFAULT)
24  ("Halide", cv::dnn::DNN_BACKEND_HALIDE)
25  ("InferenceEngine", cv::dnn::DNN_BACKEND_INFERENCE_ENGINE);
26 
30  ("OpenCL", cv::dnn::DNN_TARGET_OPENCL);
31 
35  (cv::dnn::DNN_TARGET_OPENCL, "OpenCL");
36 
43 MatND MxArrayToBlob(const MxArray& arr)
44 {
45  MatND blob(arr.toMatND(CV_32F));
46  if (blob.dims < 4) {
47  //HACK: add trailing singleton dimensions (up to 4D)
48  // (needed because in MATLAB, size(zeros(2,10,1,1)) is [2 10],
49  // but some dnn methods expect blobs to have ndims==4)
50  int sz[4] = {1, 1, 1, 1};
51  std::copy(blob.size.p, blob.size.p + blob.dims, sz);
52  blob = blob.reshape(0, 4, sz);
53  }
54  return blob;
55 }
56 
66 {
67  if (arr.isChar())
68  return Net::LayerId(arr.toString());
69  else if (arr.isFloat())
70  return Net::LayerId(arr.toDouble());
71  else
72  return Net::LayerId(arr.toInt());
73 }
74 
83 {
84  const mwSize n = arr.numel();
86  v.reserve(n);
87  if (arr.isNumeric()) {
88  if (arr.isFloat()) {
89  vector<double> nums(arr.toVector<double>());
90  v.assign(nums.begin(), nums.end());
91  }
92  else {
93  vector<int> nums(arr.toVector<int>());
94  v.assign(nums.begin(), nums.end());
95  }
96  }
97  else if (arr.isCell())
98  for (mwIndex i = 0; i < n; ++i)
99  v.push_back(MxArrayToLayerId(arr.at<MxArray>(i)));
100  else
101  mexErrMsgIdAndTxt("mexopencv:error",
102  "MxArray unable to convert to vector<cv::dnn::Net::LayerId>");
103  return v;
104 }
105 
115 {
116  CV_Assert(arr.isStruct() && arr.numel()==1);
117  LayerParams params;
118  if (arr.isField("dict")) {
119  MxArray dict(arr.at("dict"));
120  CV_Assert(dict.isStruct() && dict.numel()==1);
121  for (int i = 0; i < dict.nfields(); ++i) {
122  string key(dict.fieldname(i));
123  const MxArray val(dict.at(key));
124  if (val.isChar()) {
125  if (val.numel() == 1)
126  params.set(key, val.toString());
127  else {
128  vector<string> v(val.toVector<string>());
129  params.set(key, DictValue::arrayString(v.begin(), v.size()));
130  }
131  }
132  else if (val.isFloat()) {
133  if (val.numel() == 1)
134  params.set(key, val.toDouble());
135  else {
136  vector<double> v(val.toVector<double>());
137  params.set(key, DictValue::arrayReal(v.begin(), v.size()));
138  }
139  }
140  else {
141  if (val.numel() == 1)
142  params.set(key, val.toInt());
143  else {
144  vector<int> v(val.toVector<int>());
145  params.set(key, DictValue::arrayInt(v.begin(), v.size()));
146  }
147  }
148  }
149  }
150  if (arr.isField("blobs")) {
151  vector<MxArray> blobs(arr.at("blobs").toVector<MxArray>());
152  params.blobs.reserve(blobs.size());
153  for (vector<MxArray>::const_iterator it = blobs.begin(); it != blobs.end(); ++it)
154  params.blobs.push_back(MxArrayToBlob(*it));
155  }
156  if (arr.isField("name")) params.name = arr.at("name").toString();
157  if (arr.isField("type")) params.type = arr.at("type").toString();
158  return params;
159 }
160 
166 {
167  const char *fields[] = {"blobs", "name", "type"};
168  MxArray s = MxArray::Struct(fields, 3);
169  s.set("blobs", layer->blobs);
170  s.set("name", layer->name);
171  s.set("type", layer->type);
172  s.set("preferableTarget", TargetsInvMap[layer->preferableTarget]);
173  return s;
174 }
175 
181 {
182  const char *fields[] = {"blobs", "name", "type"};
183  MxArray s = MxArray::Struct(fields, 3, 1, layers.size());
184  for (mwIndex i = 0; i < layers.size(); ++i) {
185  s.set("blobs", layers[i]->blobs, i);
186  s.set("name", layers[i]->name, i);
187  s.set("type", layers[i]->type, i);
188  s.set("preferableTarget", TargetsInvMap[layers[i]->preferableTarget], i);
189  }
190  return s;
191 }
192 
198 {
200  if (arr.isNull())
201  mexErrMsgIdAndTxt("mexopencv:error", "Allocation error");
202  arr.set(0, i);
203  return arr;
204 }
205 
216 Ptr<Net> readNetFrom(const string &type,
219 {
220  ptrdiff_t len = std::distance(first, last);
221  Net net;
222  if (type == "Caffe") {
223  nargchk(len==1 || len==2);
224  string prototxt(first->toString()); ++first;
225  string caffeModel(len==2 ? first->toString() : string());
226  net = readNetFromCaffe(prototxt, caffeModel);
227  }
228  else if (type == "Tensorflow") {
229  nargchk(len==1 || len==2);
230  string model(first->toString()); ++first;
231  string config(len==2 ? first->toString() : string());
232  net = readNetFromTensorflow(model, config);
233  }
234  else if (type == "Torch") {
235  nargchk(len==1 || len==2);
236  string filename(first->toString()); ++first;
237  bool isBinary = (len==2 ? first->toBool() : true);
238  net = readNetFromTorch(filename, isBinary);
239  }
240  else if (type == "Darknet") {
241  nargchk(len==1 || len==2);
242  string cfgFile(first->toString()); ++first;
243  string darknetModel(len==2 ? first->toString() : string());
244  net = readNetFromDarknet(cfgFile, darknetModel);
245  }
246  else
247  mexErrMsgIdAndTxt("mexopencv:error",
248  "Unrecognized network type %s", type.c_str());
249  return makePtr<Net>(net);
250 }
251 }
252 
260 void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
261 {
262  // Check the number of arguments
263  nargchk(nrhs>=2 && nlhs<=2);
264 
265  // Argument vector
266  vector<MxArray> rhs(prhs, prhs+nrhs);
267  int id = rhs[0].toInt();
268  string method(rhs[1].toString());
269 
270  // Constructor is called. Create a new object from argument
271  if (method == "new") {
272  nargchk(nrhs>=2 && nlhs<=1);
273  obj_[++last_id] = (nrhs > 2) ?
274  readNetFrom(rhs[2].toString(), rhs.begin() + 3, rhs.end()) :
275  makePtr<Net>();
276  plhs[0] = MxArray(last_id);
277  mexLock();
278  return;
279  }
280  // static method calls
281  else if (method == "readTorchBlob") {
282  nargchk(nrhs>=3 && (nrhs%2)==1 && nlhs<=1);
283  bool isBinary = true;
284  for (int i=3; i<nrhs; i+=2) {
285  string key(rhs[i].toString());
286  if (key == "IsBinary")
287  isBinary = rhs[i+1].toBool();
288  else
289  mexErrMsgIdAndTxt("mexopencv:error",
290  "Unrecognized option %s", key.c_str());
291  }
292  string filename(rhs[2].toString());
293  MatND blob = readTorchBlob(filename, isBinary);
294  plhs[0] = MxArray(blob);
295  return;
296  }
297  else if (method == "blobFromImages") {
298  nargchk(nrhs>=3 && (nrhs%2)==1 && nlhs<=1);
299  double scalefactor = 1.0;
300  Size size;
301  Scalar mean;
302  bool swapRB = true;
303  bool crop = true;
304  for (int i=3; i<nrhs; i+=2) {
305  string key(rhs[i].toString());
306  if (key == "ScaleFactor")
307  scalefactor = rhs[i+1].toDouble();
308  else if (key == "Size")
309  size = rhs[i+1].toSize();
310  else if (key == "Mean")
311  mean = rhs[i+1].toScalar();
312  else if (key == "SwapRB")
313  swapRB = rhs[i+1].toBool();
314  else if (key == "Crop")
315  crop = rhs[i+1].toBool();
316  else
317  mexErrMsgIdAndTxt("mexopencv:error",
318  "Unrecognized option %s", key.c_str());
319  }
320  MatND blob;
321  if (rhs[2].isCell()) {
322  //vector<Mat> images(rhs[2].toVector<Mat>());
323  vector<Mat> images;
324  {
325  vector<MxArray> arr(rhs[2].toVector<MxArray>());
326  images.reserve(arr.size());
327  for (vector<MxArray>::const_iterator it = arr.begin(); it != arr.end(); ++it)
328  images.push_back(it->toMat(CV_32F));
329  }
330  blob = blobFromImages(images, scalefactor, size, mean, swapRB, crop);
331  }
332  else {
333  Mat image(rhs[2].toMat(CV_32F));
334  blob = blobFromImage(image, scalefactor, size, mean, swapRB, crop);
335  }
336  plhs[0] = MxArray(blob);
337  return;
338  }
339  else if (method == "imagesFromBlob") {
340  nargchk(nrhs==3 && nlhs<=1);
341  MatND blob(MxArrayToBlob(rhs[2]));
342  vector<Mat> images;
343  imagesFromBlob(blob, images);
344  plhs[0] = MxArray(images);
345  return;
346  }
347  else if (method == "shrinkCaffeModel") {
348  nargchk(nrhs>=4 && (nrhs%2)==0 && nlhs==0);
349  vector<string> layersTypes;
350  for (int i=4; i<nrhs; i+=2) {
351  string key(rhs[i].toString());
352  if (key == "LayersTypes")
353  layersTypes = rhs[i+1].toVector<string>();
354  else
355  mexErrMsgIdAndTxt("mexopencv:error",
356  "Unrecognized option %s", key.c_str());
357  }
358  string src(rhs[2].toString()),
359  dst(rhs[3].toString());
360  shrinkCaffeModel(src, dst,
361  vector<String>(layersTypes.begin(), layersTypes.end()));
362  return;
363  }
364  else if (method == "NMSBoxes") {
365  nargchk(nrhs>=6 && (nrhs%2)==0 && nlhs<=1);
366  float eta = 1.0f;
367  int top_k = 0;
368  for (int i=6; i<nrhs; i+=2) {
369  string key(rhs[i].toString());
370  if (key == "Eta")
371  eta = rhs[i+1].toFloat();
372  else if (key == "TopK")
373  top_k = rhs[i+1].toInt();
374  else
375  mexErrMsgIdAndTxt("mexopencv:error",
376  "Unrecognized option %s", key.c_str());
377  }
378  vector<Rect> bboxes(rhs[2].toVector<Rect>());
379  vector<float> scores(rhs[3].toVector<float>());
380  float score_threshold = rhs[4].toFloat();
381  float nms_threshold = rhs[5].toFloat();
382  vector<int> indices;
383  NMSBoxes(bboxes, scores, score_threshold, nms_threshold, indices,
384  eta, top_k);
385  plhs[0] = MxArray(indices);
386  return;
387  }
388 
389  // Big operation switch
390  Ptr<Net> obj = obj_[id];
391  if (obj.empty())
392  mexErrMsgIdAndTxt("mexopencv:error", "Object not found id=%d", id);
393  if (method == "delete") {
394  nargchk(nrhs==2 && nlhs==0);
395  obj_.erase(id);
396  mexUnlock();
397  }
398  else if (method == "empty") {
399  nargchk(nrhs==2 && nlhs<=1);
400  plhs[0] = MxArray(obj->empty());
401  }
402  else if (method == "addLayer") {
403  nargchk(nrhs==5 && nlhs<=1);
404  string name(rhs[2].toString()),
405  type(rhs[3].toString());
406  LayerParams params(MxArrayToLayerParams(rhs[4]));
407  int lid = obj->addLayer(name, type, params);
408  plhs[0] = MxArray(lid);
409  }
410  else if (method == "addLayerToPrev") {
411  nargchk(nrhs==5 && nlhs<=1);
412  string name(rhs[2].toString()),
413  type(rhs[3].toString());
414  LayerParams params(MxArrayToLayerParams(rhs[4]));
415  int lid = obj->addLayerToPrev(name, type, params);
416  plhs[0] = MxArray(lid);
417  }
418  else if (method == "getLayerId") {
419  nargchk(nrhs==3 && nlhs<=1);
420  string layer(rhs[2].toString());
421  int lid = obj->getLayerId(layer);
422  plhs[0] = MxArray(lid);
423  }
424  else if (method == "getLayerNames") {
425  nargchk(nrhs==2 && nlhs<=1);
426  plhs[0] = MxArray(obj->getLayerNames());
427  }
428  else if (method == "getLayer") {
429  nargchk(nrhs==3 && nlhs<=1);
430  Ptr<Layer> layer = obj->getLayer(MxArrayToLayerId(rhs[2]));
431  plhs[0] = toStruct(layer);
432  }
433  else if (method == "getLayerInputs") {
434  nargchk(nrhs==3 && nlhs<=1);
435  vector<Ptr<Layer> > layers = obj->getLayerInputs(MxArrayToLayerId(rhs[2]));
436  plhs[0] = toStruct(layers);
437  }
438  else if (method == "deleteLayer") {
439  nargchk(nrhs==3 && nlhs==0);
440  obj->deleteLayer(MxArrayToLayerId(rhs[2]));
441  }
442  else if (method == "connect") {
443  nargchk((nrhs==4 || nrhs==6) && nlhs==0);
444  if (nrhs == 4) {
445  string outPin(rhs[2].toString()),
446  inpPin(rhs[3].toString());
447  obj->connect(outPin, inpPin);
448  }
449  else {
450  int outLayerId(rhs[2].toInt()),
451  outNum(rhs[3].toInt()),
452  inpLayerId(rhs[4].toInt()),
453  inpNum(rhs[5].toInt());
454  obj->connect(outLayerId, outNum, inpLayerId, inpNum);
455  }
456  }
457  else if (method == "setInputsNames") {
458  nargchk(nrhs==3 && nlhs==0);
459  vector<string> inputBlobNames(rhs[2].toVector<string>());
460  obj->setInputsNames(
461  vector<String>(inputBlobNames.begin(), inputBlobNames.end()));
462  }
463  else if (method == "forward") {
464  nargchk((nrhs==2 || nrhs==3) && nlhs<=1);
465  if (nrhs == 2 || rhs[2].isChar()) {
466  string outputName;
467  if (nrhs == 3)
468  outputName = rhs[2].toString();
469  MatND outputBlob = obj->forward(outputName);
470  plhs[0] = MxArray(outputBlob);
471  }
472  else {
473  vector<string> outBlobNames(rhs[2].toVector<string>());
474  vector<MatND> outputBlobs;
475  obj->forward(outputBlobs,
476  vector<String>(outBlobNames.begin(), outBlobNames.end()));
477  plhs[0] = MxArray(outputBlobs);
478  }
479  }
480  else if (method == "forwardAndRetrieve") {
481  nargchk((nrhs==2 || nrhs==3) && nlhs<=1);
482  if (nrhs == 2 || rhs[2].isChar()) {
483  string outputName;
484  if (nrhs == 3)
485  outputName = rhs[2].toString();
486  vector<MatND> outputBlobs;
487  obj->forward(outputBlobs, outputName);
488  plhs[0] = MxArray(outputBlobs);
489  }
490  else {
491  vector<string> outBlobNames(rhs[2].toVector<string>());
492  vector<vector<MatND> > outputBlobs;
493  obj->forward(outputBlobs,
494  vector<String>(outBlobNames.begin(), outBlobNames.end()));
495  plhs[0] = MxArray(outputBlobs);
496  }
497  }
498  else if (method == "setHalideScheduler") {
499  nargchk(nrhs==3 && nlhs==0);
500  obj->setHalideScheduler(rhs[2].toString());
501  }
502  else if (method == "setPreferableBackend") {
503  nargchk(nrhs==3 && nlhs==0);
504  obj->setPreferableBackend(BackendsMap[rhs[2].toString()]);
505  }
506  else if (method == "setPreferableTarget") {
507  nargchk(nrhs==3 && nlhs==0);
508  obj->setPreferableTarget(TargetsMap[rhs[2].toString()]);
509  }
510  else if (method == "setInput") {
511  nargchk((nrhs==3 || nrhs==4) && nlhs==0);
512  MatND blob(MxArrayToBlob(rhs[2]));
513  if (nrhs > 3)
514  obj->setInput(blob, rhs[3].toString());
515  else
516  obj->setInput(blob);
517  }
518  else if (method == "setParam") {
519  nargchk(nrhs==5 && nlhs==0);
520  Net::LayerId layer(MxArrayToLayerId(rhs[2]));
521  int numParam = rhs[3].toInt();
522  MatND blob(MxArrayToBlob(rhs[4]));
523  obj->setParam(layer, numParam, blob);
524  }
525  else if (method == "getParam") {
526  nargchk((nrhs==3 || nrhs==4) && nlhs<=1);
527  Net::LayerId layer(MxArrayToLayerId(rhs[2]));
528  int numParam = (nrhs > 3) ? rhs[3].toInt() : 0;
529  CV_Assert(numParam >= 0);
530  MatND blob = obj->getParam(layer, numParam);
531  plhs[0] = MxArray(blob);
532  }
533  else if (method == "appendParam") {
534  //TODO: ad-hoc method I added to enable adding to blobs array, rather
535  // than setting existing one (needed by dnn_colorization.m demo)
536  nargchk(nrhs==4 && nlhs==0);
537  Ptr<Layer> layer = obj->getLayer(MxArrayToLayerId(rhs[2]));
538  if (!layer.empty()) {
539  MatND blob(MxArrayToBlob(rhs[3]));
540  layer->blobs.push_back(blob);
541  }
542  }
543  else if (method == "getUnconnectedOutLayers") {
544  nargchk(nrhs==2 && nlhs<=1);
545  plhs[0] = MxArray(obj->getUnconnectedOutLayers());
546  }
547  else if (method == "getLayerTypes") {
548  nargchk(nrhs==2 && nlhs<=1);
549  vector<String> layersTypes;
550  obj->getLayerTypes(layersTypes);
551  plhs[0] = MxArray(layersTypes);
552  }
553  else if (method == "getLayersCount") {
554  nargchk(nrhs==3 && nlhs<=1);
555  string layerType(rhs[2].toString());
556  int count = obj->getLayersCount(layerType);
557  plhs[0] = MxArray(count);
558  }
559  else if (method == "enableFusion") {
560  nargchk(nrhs==3 && nlhs==0);
561  obj->enableFusion(rhs[2].toBool());
562  }
563  else if (method == "getPerfProfile") {
564  nargchk(nrhs==2 && nlhs<=2);
565  vector<double> timings;
566  int64 total = obj->getPerfProfile(timings);
567  plhs[0] = MxArray(timings);
568  if (nlhs > 1)
569  plhs[1] = toMxArray(total);
570  }
571  //TODO:
572  //else if (method == "getLayerShapes") {}
573  //else if (method == "getLayersShapes") {}
574  //else if (method == "getFLOPS") {}
575  //else if (method == "getMemoryConsumption") {}
576  else
577  mexErrMsgIdAndTxt("mexopencv:error",
578  "Unrecognized operation %s",method.c_str());
579 }
Mat readTorchBlob(const String &filename, bool isBinary=true)
Ptr< Net > readNetFrom(const string &type, vector< MxArray >::const_iterator first, vector< MxArray >::const_iterator last)
Create an instance of Net using options in arguments.
Definition: Net_.cpp:216
int toInt() const
Convert MxArray to int.
Definition: MxArray.cpp:489
const ConstMap< int, string > TargetsInvMap
Computation target devices for option processing.
Definition: Net_.cpp:33
MxArray toMxArray(int64_t i)
MxArray constructor from 64-bit integer.
Definition: Net_.cpp:197
int addLayer(const String &name, const String &type, LayerParams &params)
std::vector< Mat > blobs
T copy(T... args)
#define CV_Assert(...)
Scalar mean(InputArray src, InputArray mask=noArray())
T distance(T... args)
mwSize numel() const
Number of elements in an array.
Definition: MxArray.hpp:546
T at(mwIndex index) const
Template for numeric array element accessor.
Definition: MxArray.hpp:1250
void getLayerTypes(std::vector< String > &layersTypes) const
LIBMWMEX_API_EXTERN_C void mexLock(void)
Lock a MEX-function so that it cannot be cleared from memory.
Net::LayerId MxArrayToLayerId(const MxArray &arr)
Convert MxArray to cv::dnn::Net::LayerId.
Definition: Net_.cpp:65
std::string toString() const
Convert MxArray to std::string.
Definition: MxArray.cpp:517
void NMSBoxes(const std::vector< Rect > &bboxes, const std::vector< float > &scores, const float score_threshold, const float nms_threshold, std::vector< int > &indices, const float eta=1.f, const int top_k=0)
void setPreferableBackend(int backendId)
void connect(String outPin, String inpPin)
STL namespace.
bool isChar() const
Determine whether input is string array.
Definition: MxArray.hpp:614
Mat blobFromImages(InputArrayOfArrays images, double scalefactor=1.0, Size size=Size(), const Scalar &mean=Scalar(), bool swapRB=true, bool crop=true)
void setPreferableTarget(int targetId)
LayerParams MxArrayToLayerParams(const MxArray &arr)
Convert MxArray to cv::dnn::LayerParams.
Definition: Net_.cpp:114
MxArray toStruct(const vector< Ptr< Layer > > &layers)
Convert std::vector<cv::Ptr<cv::dnn::Layer>> to struct array.
Definition: Net_.cpp:180
const ConstMap< string, int > BackendsMap
Computation backends for option processing.
Definition: Net_.cpp:22
T end(T... args)
struct mxArray_tag mxArray
Forward declaration for mxArray.
Definition: matrix.h:259
void set(mwIndex index, const T &value)
Template for numeric array element write accessor.
Definition: MxArray.hpp:1310
void setInputsNames(const std::vector< String > &inputBlobNames)
STL class.
Mat getParam(LayerId layer, int numParam=0)
Net readNetFromCaffe(const String &prototxt, const String &caffeModel=String())
bool isFloat() const
Determine whether array represents data as floating-point numbers, both single and double precision...
Definition: MxArray.hpp:738
STL class.
Net readNetFromTorch(const String &model, bool isBinary=true)
void setInput(InputArray blob, const String &name="")
int getLayersCount(const String &layerType) const
T push_back(T... args)
std::vector< Ptr< Layer > > getLayerInputs(LayerId layerId)
void setParam(LayerId layer, int numParam, const Mat &blob)
#define CV_32F
uint32_t v
Mat blobFromImage(InputArray image, double scalefactor=1.0, const Size &size=Size(), const Scalar &mean=Scalar(), bool swapRB=true, bool crop=true)
int64 getPerfProfile(std::vector< double > &timings)
Net readNetFromTensorflow(const String &model, const String &config=String())
bool isNumeric() const
Determine whether array is numeric.
Definition: MxArray.hpp:695
LIBMWMEX_API_EXTERN_C void mexErrMsgIdAndTxt(const char *identifier, const char *err_msg,...)
Issue formatted error message with corresponding error identifier and return to MATLAB prompt...
void enableFusion(bool fusion)
vector< Net::LayerId > MxArrayToVectorLayerId(const MxArray &arr)
Convert MxArray to std::vector<cv::dnn::Net::LayerId>
Definition: Net_.cpp:82
#define mxCreateNumericMatrix
Definition: matrix.h:1516
DNN_BACKEND_DEFAULT
bool isCell() const
Determine whether input is cell array.
Definition: MxArray.hpp:610
LIBMWMEX_API_EXTERN_C void mexUnlock(void)
Unlock a locked MEX-function so that it can be cleared from memory.
int last_id
Last object id to allocate.
Definition: Net_.cpp:17
bool isField(const std::string &fieldName) const
Determine whether a struct array has a specified field.
Definition: MxArray.hpp:743
mxArray object wrapper for data conversion and manipulation.
Definition: MxArray.hpp:123
void nargchk(bool cond)
Alias for input/output arguments number check.
Definition: mexopencv.hpp:181
std::vector< String > getLayerNames() const
DNN_BACKEND_HALIDE
static MxArray Struct(const char **fields=NULL, int nfields=0, mwSize m=1, mwSize n=1)
Create a new struct array.
Definition: MxArray.hpp:312
T count(T... args)
bool isStruct() const
Determine whether input is structure array.
Definition: MxArray.hpp:708
void shrinkCaffeModel(const String &src, const String &dst, const std::vector< String > &layersTypes=std::vector< String >())
T size(T... args)
std::vector< T > toVector() const
Convert MxArray to std::vector<T> of primitive types.
Definition: MxArray.hpp:1151
STL class.
bool empty() const
cv::MatND toMatND(int depth=CV_USRTYPE1, bool transpose=true) const
Convert MxArray to a single-channel cv::Mat.
Definition: MxArray.cpp:605
Global constant definitions.
T begin(T... args)
void setHalideScheduler(const String &scheduler)
void deleteLayer(LayerId layer)
bool empty() const
T c_str(T... args)
const ConstMap< string, int > TargetsMap
Computation target devices for option processing.
Definition: Net_.cpp:28
void imagesFromBlob(const cv::Mat &blob_, OutputArrayOfArrays images_)
Ptr< Layer > getLayer(LayerId layerId)
int addLayerToPrev(const String &name, const String &type, LayerParams &params)
Mat forward(const String &outputName=String())
double toDouble() const
Convert MxArray to double.
Definition: MxArray.cpp:496
int getLayerId(const String &layer)
DNN_BACKEND_INFERENCE_ENGINE
Net readNetFromDarknet(const String &cfgFile, const String &darknetModel=String())
bool isNull() const
Determine whether the array is initialized or not.
Definition: MxArray.hpp:606
Identifies a numeric mxArray whose data is stored as the type specified in the MATLAB Primitive Types...
Definition: matrix.h:305
int type() const
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
Main entry called from Matlab.
Definition: Net_.cpp:260
std::map wrapper with one-line initialization and lookup method.
Definition: MxArray.hpp:927
map< int, Ptr< Net > > obj_
Object container.
Definition: Net_.cpp:19
MatND MxArrayToBlob(const MxArray &arr)
Create 4-dimensional blob from MATLAB array.
Definition: Net_.cpp:43
cv::Mat toMat() const
size_t size() const
T reserve(T... args)
std::vector< int > getUnconnectedOutLayers() const
Identifies an mxArray with no imaginary components.
Definition: matrix.h:325