mirror of
https://github.com/opencv/opencv.git
synced 2025-07-30 01:06:38 +08:00

Added bool support to dnn #25605 Added bool support to dnn pipeline (CPU, OpenVINO and CUDA pipelines). Added bool support to these layers(CPU and OpenVINO): - Equal, Greater, GreaterOrEqual, Less, LessOrEqual - Not - And, Or, Xor - Where Enabled all the conformance tests for these layers. ### Pull Request Readiness Checklist See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request - [x] I agree to contribute to the project under Apache 2 License. - [x] To the best of my knowledge, the proposed patch is not based on a code under GPL or another license that is incompatible with OpenCV - [x] The PR is proposed to the proper branch - [ ] There is a reference to the original bug report and related work - [x] There is accuracy test, performance test and test data in opencv_extra repository, if applicable Patch to opencv_extra has the same branch name. - [x] The feature is well documented and sample code can be built with the project CMake
84 lines
2.6 KiB
C++
84 lines
2.6 KiB
C++
// 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.
|
|
|
|
#include "../precomp.hpp"
|
|
#include "layers_common.hpp"
|
|
#include "../op_inf_engine.hpp"
|
|
#include "../ie_ngraph.hpp"
|
|
|
|
|
|
namespace cv { namespace dnn {
|
|
|
|
class NotLayerImpl CV_FINAL : public NotLayer
|
|
{
|
|
public:
|
|
NotLayerImpl(const LayerParams& params)
|
|
{
|
|
setParamsFrom(params);
|
|
}
|
|
|
|
virtual bool supportBackend(int backendId) CV_OVERRIDE
|
|
{
|
|
return backendId == DNN_BACKEND_OPENCV ||
|
|
backendId == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH;
|
|
}
|
|
|
|
virtual bool getMemoryShapes(const std::vector<MatShape> &inputs,
|
|
const int requiredOutputs,
|
|
std::vector<MatShape> &outputs,
|
|
std::vector<MatShape> &internals) const CV_OVERRIDE
|
|
{
|
|
CV_CheckEQ(inputs.size(), (size_t)1, "");
|
|
outputs.assign(1, inputs[0]);
|
|
return true;
|
|
}
|
|
|
|
virtual void getTypes(const std::vector<MatType>& inputs,
|
|
const int requiredOutputs,
|
|
const int requiredInternals,
|
|
std::vector<MatType>& outputs,
|
|
std::vector<MatType>& internals) const CV_OVERRIDE
|
|
{
|
|
CV_CheckTypeEQ(inputs[0], CV_Bool, "");
|
|
outputs.assign(1, CV_Bool);
|
|
}
|
|
|
|
void forward(InputArrayOfArrays inputs_arr, OutputArrayOfArrays outputs_arr, OutputArrayOfArrays internals_arr) CV_OVERRIDE
|
|
{
|
|
CV_TRACE_FUNCTION();
|
|
CV_TRACE_ARG_VALUE(name, "name", name.c_str());
|
|
|
|
std::vector<Mat> inputs, outputs;
|
|
inputs_arr.getMatVector(inputs);
|
|
outputs_arr.getMatVector(outputs);
|
|
|
|
CV_CheckTypeEQ(inputs[0].type(), CV_Bool, "");
|
|
CV_CheckTypeEQ(outputs[0].type(), CV_Bool, "");
|
|
|
|
bool* input = inputs[0].ptr<bool>();
|
|
bool* output = outputs[0].ptr<bool>();
|
|
int size = inputs[0].total();
|
|
|
|
for (int i = 0; i < size; ++i)
|
|
output[i] = !input[i];
|
|
}
|
|
|
|
#ifdef HAVE_DNN_NGRAPH
|
|
virtual Ptr<BackendNode> initNgraph(const std::vector<Ptr<BackendWrapper> >& inputs,
|
|
const std::vector<Ptr<BackendNode> >& nodes) CV_OVERRIDE
|
|
{
|
|
auto node = std::make_shared<ov::op::v1::LogicalNot>(nodes[0].dynamicCast<InfEngineNgraphNode>()->node);
|
|
return Ptr<BackendNode>(new InfEngineNgraphNode(node));
|
|
}
|
|
#endif // HAVE_DNN_NGRAPH
|
|
|
|
};
|
|
|
|
Ptr<NotLayer> NotLayer::create(const LayerParams& params)
|
|
{
|
|
return makePtr<NotLayerImpl>(params);
|
|
}
|
|
|
|
}} // namespace cv::dnn
|