Files
opencv-MIRROR/modules/dnn/src/layers/size_layer.cpp
Abhishek Gola 71a601ea0e Merge pull request #29783 from abhishek-gola:extended_onnx_coverage
Added GridSample BiCubic, Dropout support - #29783

Updated ONNX coverage after this PR: 74.8% 

### 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
- [x] 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
2026-08-27 09:27:22 +03:00

70 lines
2.1 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.
// Copyright (C) 2025, BigVision LLC, all rights reserved.
// Third party copyrights are property of their respective owners.
#include "../precomp.hpp"
#include "layers_common.hpp"
#include <opencv2/dnn/shape_utils.hpp>
namespace cv {
namespace dnn {
class SizeLayerImpl CV_FINAL : public SizeLayer
{
public:
SizeLayerImpl(const LayerParams& params)
{
setParamsFrom(params);
}
virtual bool supportBackend(int backendId) CV_OVERRIDE
{
return backendId == DNN_BACKEND_OPENCV;
}
bool getMemoryShapes(const std::vector<MatShape>& inputs,
const int requiredOutputs,
std::vector<MatShape>& outputs,
std::vector<MatShape>& internals) const CV_OVERRIDE
{
outputs.assign(1, MatShape::scalar());
return false;
}
void getTypes(const std::vector<MatType>& /*inputs*/,
const int requiredOutputs,
const int requiredInternals,
std::vector<MatType>& outputs,
std::vector<MatType>& internals) const CV_OVERRIDE
{
outputs.assign(requiredOutputs, MatType(CV_64S));
internals.assign(requiredInternals, MatType(CV_64S));
}
void forward(InputArrayOfArrays inputs_arr,
OutputArrayOfArrays outputs_arr,
OutputArrayOfArrays /*internals_arr*/) CV_OVERRIDE
{
std::vector<Mat> inputs, outputs;
inputs_arr.getMatVector(inputs);
outputs_arr.getMatVector(outputs);
CV_Assert(inputs.size() == 1);
const Mat& x = inputs[0];
const MatShape xShape = shape(x);
int64_t totalElems = static_cast<int64_t>(total(xShape));
outputs[0].ptr<int64_t>()[0] = totalElems;
}
};
Ptr<SizeLayer> SizeLayer::create(const LayerParams& params)
{
return Ptr<SizeLayer>(new SizeLayerImpl(params));
}
}}