// 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 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& inputs, const int requiredOutputs, std::vector& outputs, std::vector& internals) const CV_OVERRIDE { outputs.assign(1, MatShape::scalar()); return false; } void getTypes(const std::vector& /*inputs*/, const int requiredOutputs, const int requiredInternals, std::vector& outputs, std::vector& 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 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(total(xShape)); outputs[0].ptr()[0] = totalElems; } }; Ptr SizeLayer::create(const LayerParams& params) { return Ptr(new SizeLayerImpl(params)); } }}