|
| 1 | +// This file is part of OpenCV project. |
| 2 | +// It is subject to the license terms in the LICENSE file found in the top-level directory |
| 3 | +// of this distribution and at http://opencv.org/license.html. |
| 4 | + |
| 5 | +// Copyright (C) 2018, Intel Corporation, all rights reserved. |
| 6 | +// Third party copyrights are property of their respective owners. |
| 7 | + |
| 8 | +#include "../precomp.hpp" |
| 9 | +#include "layers_common.hpp" |
| 10 | + |
| 11 | +#ifdef HAVE_OPENCL |
| 12 | +#include "opencl_kernels_dnn.hpp" |
| 13 | +#endif |
| 14 | + |
| 15 | +namespace cv { namespace dnn { |
| 16 | + |
| 17 | +class ConstLayerImpl CV_FINAL : public ConstLayer |
| 18 | +{ |
| 19 | +public: |
| 20 | + ConstLayerImpl(const LayerParams& params) |
| 21 | + { |
| 22 | + setParamsFrom(params); |
| 23 | + CV_Assert(blobs.size() == 1); |
| 24 | + } |
| 25 | + |
| 26 | + virtual bool getMemoryShapes(const std::vector<MatShape> &inputs, |
| 27 | + const int requiredOutputs, |
| 28 | + std::vector<MatShape> &outputs, |
| 29 | + std::vector<MatShape> &internals) const CV_OVERRIDE |
| 30 | + { |
| 31 | + CV_Assert(inputs.empty()); |
| 32 | + outputs.assign(1, shape(blobs[0])); |
| 33 | + return false; |
| 34 | + } |
| 35 | + |
| 36 | +#ifdef HAVE_OPENCL |
| 37 | + bool forward_ocl(InputArrayOfArrays inps, OutputArrayOfArrays outs, OutputArrayOfArrays internals) |
| 38 | + { |
| 39 | + std::vector<UMat> outputs; |
| 40 | + outs.getUMatVector(outputs); |
| 41 | + if (outs.depth() == CV_16S) |
| 42 | + convertFp16(blobs[0], outputs[0]); |
| 43 | + else |
| 44 | + blobs[0].copyTo(outputs[0]); |
| 45 | + return true; |
| 46 | + } |
| 47 | +#endif |
| 48 | + |
| 49 | + void forward(InputArrayOfArrays inputs_arr, OutputArrayOfArrays outputs_arr, OutputArrayOfArrays internals_arr) CV_OVERRIDE |
| 50 | + { |
| 51 | + CV_TRACE_FUNCTION(); |
| 52 | + CV_TRACE_ARG_VALUE(name, "name", name.c_str()); |
| 53 | + |
| 54 | + CV_OCL_RUN(IS_DNN_OPENCL_TARGET(preferableTarget), |
| 55 | + forward_ocl(inputs_arr, outputs_arr, internals_arr)) |
| 56 | + |
| 57 | + std::vector<Mat> outputs; |
| 58 | + outputs_arr.getMatVector(outputs); |
| 59 | + blobs[0].copyTo(outputs[0]); |
| 60 | + } |
| 61 | +}; |
| 62 | + |
| 63 | +Ptr<Layer> ConstLayer::create(const LayerParams& params) |
| 64 | +{ |
| 65 | + return Ptr<Layer>(new ConstLayerImpl(params)); |
| 66 | +} |
| 67 | + |
| 68 | +}} // namespace cv::dnn |
0 commit comments