mirror of
https://github.com/opencv/opencv_contrib.git
synced 2025-10-24 03:03:35 +08:00
refactored DNN (#1102)
* the first commit in the merged dnn: convert some public API from Blob's to Mat's * temporarily or permantently removed OpenCL optimizations, which are not always stable nor usually very efficient; we'll likely use Halide instead * got rid of Blob and BlobShape completely; use cv::Mat and std::vector<int> instead * fixed a few compile errors * got rid of separate .hpp files with layer declarations; instead, put everything into the respective .cpp files * normalized all the layers' constructors; we concentrate on loading deep networks layers from files instead of constructing them from scratch, so we retained only SomeLayer::SomeLayer(const LayerParams& params); constructors * fixed sample compilation * suppress doxygen warnings * trying to fix python bindings generation for DNN module * temporarily disable python bindings while we refactor the module * fix win32/win64 compile errors; remove trailing whitespaces * fix win32/win64 compile errors; remove trailing whitespaces
This commit is contained in:
@@ -1,66 +1,5 @@
|
||||
#ifdef HAVE_OPENCV_DNN
|
||||
typedef dnn::DictValue LayerId;
|
||||
typedef std::vector<cv::dnn::Blob> vector_Blob;
|
||||
|
||||
template<>
|
||||
bool pyopencv_to(PyObject *o, dnn::Blob &blob, const char *name);
|
||||
|
||||
template<> struct pyopencvVecConverter<dnn::Blob>
|
||||
{
|
||||
static bool to(PyObject* obj, std::vector<dnn::Blob>& value, const ArgInfo info)
|
||||
{
|
||||
if (PyArray_Check(obj))
|
||||
{
|
||||
value.resize(1);
|
||||
return pyopencv_to(obj, value[0], info.name);
|
||||
}
|
||||
|
||||
return pyopencv_to_generic_vec(obj, value, info);
|
||||
}
|
||||
|
||||
static PyObject* from(const std::vector<dnn::Blob>& value)
|
||||
{
|
||||
return pyopencv_from_generic_vec(value);
|
||||
}
|
||||
};
|
||||
|
||||
template<>
|
||||
bool pyopencv_to(PyObject *o, std::vector<dnn::Blob> &blobs, const char *name) //required for Layer::blobs RW
|
||||
{
|
||||
return pyopencvVecConverter<dnn::Blob>::to(o, blobs, ArgInfo(name, false));
|
||||
}
|
||||
|
||||
template<>
|
||||
bool pyopencv_to(PyObject *o, dnn::Blob &blob, const char *name)
|
||||
{
|
||||
Mat &dst = blob.matRef();
|
||||
if (!pyopencv_to(o, dst, name))
|
||||
return false;
|
||||
|
||||
if (PyArray_Check(o)) //try fix channels
|
||||
{
|
||||
PyArrayObject* oarr = (PyArrayObject*) o;
|
||||
|
||||
if (PyArray_NDIM(oarr) == dst.dims)
|
||||
return true;
|
||||
|
||||
int ndims = PyArray_NDIM(oarr);
|
||||
std::vector<int> shape(ndims);
|
||||
const npy_intp* _sizes = PyArray_DIMS(oarr);
|
||||
for (int i = 0; i < ndims; i++)
|
||||
shape[i] = (int)_sizes[i];
|
||||
|
||||
dst = dst.reshape(1, ndims, &shape[0]);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
template<>
|
||||
PyObject *pyopencv_from(const dnn::Blob &blob)
|
||||
{
|
||||
return pyopencv_from(blob.matRefConst());
|
||||
}
|
||||
|
||||
template<>
|
||||
bool pyopencv_to(PyObject *o, dnn::DictValue &dv, const char *name)
|
||||
@@ -87,22 +26,4 @@ bool pyopencv_to(PyObject *o, dnn::DictValue &dv, const char *name)
|
||||
return false;
|
||||
}
|
||||
|
||||
template<>
|
||||
bool pyopencv_to(PyObject *o, dnn::BlobShape &shape, const char *name)
|
||||
{
|
||||
std::vector<int> data;
|
||||
if (!pyopencv_to_generic_vec(o, data, ArgInfo(name, false)))
|
||||
return false;
|
||||
|
||||
shape = data.size() ? dnn::BlobShape((int)data.size(), &data[0]) : dnn::BlobShape::empty();
|
||||
return true;
|
||||
}
|
||||
|
||||
template<>
|
||||
PyObject *pyopencv_from(const dnn::BlobShape &shape)
|
||||
{
|
||||
std::vector<int> data(shape.ptr(), shape.ptr() + shape.dims());
|
||||
return pyopencv_from_generic_vec(data);
|
||||
}
|
||||
|
||||
#endif
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user