mirror of
https://github.com/opencv/opencv.git
synced 2026-07-30 07:43:03 +04:00
Add new layer forward interface
Add layer forward interface with InputArrayOfArrays and OutputArrayOfArrays parameters, it allows UMat buffer to be processed and transferred in the layers. Signed-off-by: Li Peng <peng.li@intel.com>
This commit is contained in:
@@ -258,12 +258,18 @@ public:
|
||||
};
|
||||
|
||||
#ifdef HAVE_OPENCL
|
||||
bool forward_ocl(std::vector<Mat*> &input, std::vector<Mat> &output)
|
||||
bool forward_ocl(InputArrayOfArrays inps, OutputArrayOfArrays outs, InputArrayOfArrays internals)
|
||||
{
|
||||
int axisCan = clamp(axis, input[0]->dims);
|
||||
int numOutput = blobs[0].size[0];
|
||||
int innerSize = blobs[0].size[1];
|
||||
int outerSize = input[0]->total(0, axisCan);
|
||||
std::vector<UMat> inputs;
|
||||
std::vector<UMat> outputs;
|
||||
|
||||
inps.getUMatVector(inputs);
|
||||
outs.getUMatVector(outputs);
|
||||
|
||||
int axisCan = clamp(axis, inputs[0].dims);
|
||||
int numOutput = umat_blobs[0].size[0];
|
||||
int innerSize = umat_blobs[0].size[1];
|
||||
int outerSize = total(shape(inputs[0]), 0, axisCan);
|
||||
bool ret = true;
|
||||
|
||||
if (innerProductOp.empty())
|
||||
@@ -278,11 +284,10 @@ public:
|
||||
}
|
||||
|
||||
UMat biasOnesMat = UMat::ones(outerSize, 1, umat_blobs[0].type());
|
||||
for (size_t i = 0; i < input.size(); i++)
|
||||
for (size_t i = 0; i < inputs.size(); i++)
|
||||
{
|
||||
UMat srcMat, dstMat;
|
||||
srcMat = input[i]->reshape(1, outerSize).getUMat(ACCESS_READ);
|
||||
dstMat = output[i].reshape(1, outerSize).getUMat(ACCESS_WRITE);
|
||||
UMat& srcMat = inputs[i];
|
||||
UMat& dstMat = outputs[i];
|
||||
dstMat.setTo(0.0f);
|
||||
|
||||
if (!innerProductOp->Forward(srcMat, umat_blobs[0], (bias) ? umat_blobs[1] : UMat(), dstMat))
|
||||
@@ -301,11 +306,15 @@ public:
|
||||
if (ret) return true;
|
||||
|
||||
UMat& weights = umat_blobs[0];
|
||||
for (size_t i = 0; i < input.size(); i++)
|
||||
for (size_t i = 0; i < inputs.size(); i++)
|
||||
{
|
||||
MatShape inshape, outshape;
|
||||
inshape = shape(outerSize, innerSize);
|
||||
outshape = shape(outerSize, numOutput);
|
||||
|
||||
UMat srcMat, dstMat;
|
||||
srcMat = input[i]->reshape(1, outerSize).getUMat(ACCESS_READ);
|
||||
dstMat = output[i].reshape(1, outerSize).getUMat(ACCESS_WRITE);
|
||||
srcMat = inputs[i].reshape(1, inshape.size(), &inshape[0]);
|
||||
dstMat = outputs[i].reshape(1, outshape.size(), &outshape[0]);
|
||||
|
||||
cv::gemm(srcMat, weights, 1, noArray(), 0, dstMat, GEMM_2_T);
|
||||
|
||||
@@ -320,14 +329,22 @@ public:
|
||||
}
|
||||
#endif
|
||||
|
||||
void forward(std::vector<Mat*> &input, std::vector<Mat> &output, std::vector<Mat> &)
|
||||
void forward(InputArrayOfArrays inputs_arr, OutputArrayOfArrays outputs_arr, OutputArrayOfArrays internals_arr)
|
||||
{
|
||||
CV_TRACE_FUNCTION();
|
||||
CV_TRACE_ARG_VALUE(name, "name", name.c_str());
|
||||
|
||||
CV_OCL_RUN((preferableTarget == DNN_TARGET_OPENCL) &&
|
||||
OCL_PERFORMANCE_CHECK(ocl::Device::getDefault().isIntel()),
|
||||
forward_ocl(input, output))
|
||||
forward_ocl(inputs_arr, outputs_arr, internals_arr))
|
||||
|
||||
Layer::forward_fallback(inputs_arr, outputs_arr, internals_arr);
|
||||
}
|
||||
|
||||
void forward(std::vector<Mat*> &input, std::vector<Mat> &output, std::vector<Mat> &)
|
||||
{
|
||||
CV_TRACE_FUNCTION();
|
||||
CV_TRACE_ARG_VALUE(name, "name", name.c_str());
|
||||
|
||||
int axisCan = clamp(axis, input[0]->dims);
|
||||
int outerSize = input[0]->total(0, axisCan);
|
||||
|
||||
Reference in New Issue
Block a user