2019-03-29 21:42:58 +08:00
|
|
|
// This file is part of OpenCV project.
|
|
|
|
// It is subject to the license terms in the LICENSE file found in the top-level directory
|
|
|
|
// of this distribution and at http://opencv.org/license.html.
|
|
|
|
|
2019-03-31 16:51:09 +08:00
|
|
|
#include "test_precomp.hpp"
|
|
|
|
#include "test_common.impl.hpp" // shared with perf tests
|
2024-02-29 16:42:19 +08:00
|
|
|
#include <opencv2/dnn/shape_utils.hpp>
|
|
|
|
|
|
|
|
namespace opencv_test {
|
|
|
|
void runLayer(cv::Ptr<cv::dnn::Layer> layer, std::vector<cv::Mat> &inpBlobs, std::vector<cv::Mat> &outBlobs)
|
|
|
|
{
|
|
|
|
size_t ninputs = inpBlobs.size();
|
|
|
|
std::vector<cv::Mat> inp(ninputs), outp, intp;
|
|
|
|
std::vector<cv::dnn::MatShape> inputs, outputs, internals;
|
2024-05-15 15:50:03 +08:00
|
|
|
std::vector<cv::dnn::MatType> inputs_types, outputs_types, internals_types;
|
2024-02-29 16:42:19 +08:00
|
|
|
|
|
|
|
for (size_t i = 0; i < ninputs; i++)
|
|
|
|
{
|
|
|
|
inp[i] = inpBlobs[i].clone();
|
|
|
|
inputs.push_back(cv::dnn::shape(inp[i]));
|
2024-05-15 15:50:03 +08:00
|
|
|
inputs_types.push_back(cv::dnn::MatType(inp[i].type()));
|
2024-02-29 16:42:19 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
layer->getMemoryShapes(inputs, 0, outputs, internals);
|
2024-05-15 15:50:03 +08:00
|
|
|
layer->getTypes(inputs_types, outputs.size(), internals.size(), outputs_types, internals_types);
|
2024-02-29 16:42:19 +08:00
|
|
|
for (size_t i = 0; i < outputs.size(); i++)
|
|
|
|
{
|
2024-05-15 15:50:03 +08:00
|
|
|
outp.push_back(cv::Mat(outputs[i], outputs_types[i]));
|
2024-02-29 16:42:19 +08:00
|
|
|
}
|
|
|
|
for (size_t i = 0; i < internals.size(); i++)
|
|
|
|
{
|
2024-05-15 15:50:03 +08:00
|
|
|
intp.push_back(cv::Mat(internals[i], internals_types[i]));
|
2024-02-29 16:42:19 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
layer->finalize(inp, outp);
|
|
|
|
layer->forward(inp, outp, intp);
|
|
|
|
|
|
|
|
size_t noutputs = outp.size();
|
|
|
|
outBlobs.resize(noutputs);
|
|
|
|
for (size_t i = 0; i < noutputs; i++)
|
|
|
|
outBlobs[i] = outp[i];
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|