Ejemplo n.º 1
0
    ReorgLayerImpl(const LayerParams& params)
    {
        setParamsFrom(params);

        reorgStride = params.get<int>("reorg_stride", 2);
        CV_Assert(reorgStride > 0);
    }
 MaxUnpoolLayerImpl(const LayerParams& params)
 {
     setParamsFrom(params);
     poolKernel = Size(params.get<int>("pool_k_w"), params.get<int>("pool_k_h"));
     poolPad = Size(params.get<int>("pool_pad_w"), params.get<int>("pool_pad_h"));
     poolStride = Size(params.get<int>("pool_stride_w"), params.get<int>("pool_stride_h"));
 }
Ejemplo n.º 3
0
 NormalizeBBoxLayerImpl(const LayerParams &params)
 {
     _eps = getParameter<float>(params, "eps", 0, false, 1e-10f);
     _across_spatial = getParameter<bool>(params, "across_spatial");
     _channel_shared = getParameter<bool>(params, "channel_shared");
     setParamsFrom(params);
 }
Ejemplo n.º 4
0
 NormalizeBBoxLayerImpl(const LayerParams& params)
 {
     setParamsFrom(params);
     pnorm = params.get<float>("p", 2);
     epsilon = params.get<float>("eps", 1e-10f);
     acrossSpatial = params.get<bool>("across_spatial", true);
     CV_Assert(pnorm > 0);
 }
 ResizeNearestNeighborLayerImpl(const LayerParams& params)
 {
     setParamsFrom(params);
     CV_Assert(params.has("width"), params.has("height"));
     outWidth = params.get<float>("width");
     outHeight = params.get<float>("height");
     alignCorners = params.get<bool>("align_corners", false);
     if (alignCorners)
         CV_Error(Error::StsNotImplemented, "Nearest neighborhood resize with align_corners=true is not implemented");
 }
Ejemplo n.º 6
0
    CropLayerImpl(const LayerParams& params)
    {
        setParamsFrom(params);
        startAxis = params.get<int>("axis", 2);
        const DictValue *paramOffset = params.ptr("offset");

        if (paramOffset)
        {
            for (int i = 0; i < paramOffset->size(); i++)
                offset.push_back(paramOffset->get<int>(i));
        }
    }
Ejemplo n.º 7
0
 SplitLayerImpl(const LayerParams &params)
 {
     setParamsFrom(params);
     //TODO: maybe "top_count" param is useless because it can be determined by output connections number
     if (params.has("top_count"))
     {
         outputsCount = params.get<int>("top_count");
         CV_Assert(outputsCount >= 0);
     }
     else
     {
         outputsCount = -1;
     }
 }
Ejemplo n.º 8
0
    ReshapeLayerImpl(const LayerParams& params)
    {
        setParamsFrom(params);
        int axis = params.get<int>("axis", 0);
        int numAxes = params.get<int>("num_axes", -1);
        CV_Assert(numAxes >= -1);
        newShapeRange = (numAxes == -1) ? Range(axis, INT_MAX) : Range(axis, axis + numAxes);

        newShapeDesc.clear();
        if (params.has("dim"))
        {
            const DictValue &paramShape = params.get("dim");
            int i, dims = paramShape.size();
            newShapeDesc.resize(dims);
            for (i = 0; i < dims; i++)
                newShapeDesc[i] = paramShape.get<int>(i);
        }
    }
Ejemplo n.º 9
0
    PaddingLayerImpl(const LayerParams &params)
    {
        setParamsFrom(params);
        paddingValue = params.get<float>("value", 0);
        inputDims = params.get<int>("input_dims", -1);
        paddingType = params.get<String>("type", "constant");

        CV_Assert(params.has("paddings"));
        const DictValue& paddingsParam = params.get("paddings");
        CV_Assert((paddingsParam.size() & 1) == 0);

        paddings.resize(paddingsParam.size() / 2);
        for (int i = 0; i < paddings.size(); ++i)
        {
            paddings[i].first = paddingsParam.get<int>(i * 2);  // Pad before.
            paddings[i].second = paddingsParam.get<int>(i * 2 + 1);  // Pad after.
            CV_Assert(paddings[i].first >= 0, paddings[i].second >= 0);
        }
    }
Ejemplo n.º 10
0
    LSTMLayerImpl(const LayerParams& params)
        : numTimeStamps(0), numSamples(0)
    {
        setParamsFrom(params);

        if (!blobs.empty())
        {
            CV_Assert(blobs.size() >= 3);

            blobs[2] = blobs[2].reshape(1, 1);

            const Mat& Wh = blobs[0];
            const Mat& Wx = blobs[1];
            const Mat& bias = blobs[2];
            CV_Assert(Wh.dims == 2 && Wx.dims == 2);
            CV_Assert(Wh.rows == Wx.rows);
            CV_Assert(Wh.rows == 4*Wh.cols);
            CV_Assert(Wh.rows == (int)bias.total());
            CV_Assert(Wh.type() == Wx.type() && Wx.type() == bias.type());

            // Peephole weights.
            if (blobs.size() > 3)
            {
                CV_Assert(blobs.size() == 6);
                const int N = Wh.cols;
                for (int i = 3; i < 6; ++i)
                {
                    CV_Assert(blobs[i].rows == N && blobs[i].cols == N);
                    CV_Assert(blobs[i].type() == bias.type());
                }
            }
        }
        useTimestampDim = params.get<bool>("use_timestamp_dim", true);
        produceCellOutput = params.get<bool>("produce_cell_output", false);
        forgetBias = params.get<float>("forget_bias", 0.0f);
        cellClip = params.get<float>("cell_clip", 0.0f);
        useCellClip = params.get<bool>("use_cell_clip", false);
        usePeephole = params.get<bool>("use_peephole", false);

        allocated = false;
        outTailShape.clear();
    }
Ejemplo n.º 11
0
    PriorBoxLayerImpl(const LayerParams &params)
    {
        setParamsFrom(params);
        _minSize = getParameter<unsigned>(params, "min_size");
        CV_Assert(_minSize > 0);

        _flip = getParameter<bool>(params, "flip");
        _clip = getParameter<bool>(params, "clip");

        _aspectRatios.clear();
        _aspectRatios.push_back(1.);

        getAspectRatios(params);
        getVariance(params);

        _numPriors = _aspectRatios.size();

        _maxSize = -1;
        if (params.has("max_size"))
        {
            _maxSize = params.get("max_size").get<float>(0);
            CV_Assert(_maxSize > _minSize);

            _numPriors += 1;
        }

        if (params.has("step_h") || params.has("step_w")) {
          CV_Assert(!params.has("step"));
          _stepY = getParameter<float>(params, "step_h");
          CV_Assert(_stepY > 0.);
          _stepX = getParameter<float>(params, "step_w");
          CV_Assert(_stepX > 0.);
        } else if (params.has("step")) {
          const float step = getParameter<float>(params, "step");
          CV_Assert(step > 0);
          _stepY = step;
          _stepX = step;
        } else {
          _stepY = 0;
          _stepX = 0;
        }
    }
Ejemplo n.º 12
0
    RegionLayerImpl(const LayerParams& params)
    {
        setParamsFrom(params);
        CV_Assert(blobs.size() == 1);

        thresh = params.get<float>("thresh", 0.2);
        coords = params.get<int>("coords", 4);
        classes = params.get<int>("classes", 0);
        anchors = params.get<int>("anchors", 5);
        classfix = params.get<int>("classfix", 0);
        useSoftmaxTree = params.get<bool>("softmax_tree", false);
        useSoftmax = params.get<bool>("softmax", false);
        nmsThreshold = params.get<float>("nms_threshold", 0.4);

        CV_Assert(nmsThreshold >= 0.);
        CV_Assert(coords == 4);
        CV_Assert(classes >= 1);
        CV_Assert(anchors >= 1);
        CV_Assert(useSoftmaxTree || useSoftmax);
    }
Ejemplo n.º 13
0
    LRNLayerImpl(const LayerParams& params)
    {
        setParamsFrom(params);
        type = -1;
        String nrmType = params.get<String>("norm_region", "ACROSS_CHANNELS");
        if (nrmType == "ACROSS_CHANNELS")
            type = LRNLayer::CHANNEL_NRM;
        else if (nrmType == "WITHIN_CHANNEL")
            type = LRNLayer::SPATIAL_NRM;
        else
            CV_Error(Error::StsBadArg, "Unknown region type \"" + nrmType + "\"");

        size = params.get<int>("local_size", 5);
        if (size % 2 != 1 || size <= 0)
            CV_Error(Error::StsBadArg, "LRN layer supports only positive odd values for local_size");

        alpha = params.get<double>("alpha", 1);
        beta = params.get<double>("beta", 0.75);
        bias = params.get<double>("bias", 1);
        normBySize = params.get<bool>("norm_by_size", true);
    }
Ejemplo n.º 14
0
    PriorBoxLayerImpl(const LayerParams &params)
        : _boxWidth(0), _boxHeight(0)
    {
        setParamsFrom(params);
        _minSize = getParameter<float>(params, "min_size", 0, false, 0);
        _flip = getParameter<bool>(params, "flip", 0, false, true);
        _clip = getParameter<bool>(params, "clip", 0, false, true);
        _bboxesNormalized = getParameter<bool>(params, "normalized_bbox", 0, false, true);

        _scales.clear();
        _aspectRatios.clear();

        getAspectRatios(params);
        getVariance(params);
        getParams("scales", params, &_scales);
        getParams("width", params, &_widths);
        getParams("height", params, &_heights);
        _explicitSizes = !_widths.empty();
        CV_Assert(_widths.size() == _heights.size());

        if (_explicitSizes)
        {
            CV_Assert(_aspectRatios.empty(), !params.has("min_size"), !params.has("max_size"));
            _numPriors = _widths.size();
        }
        else
        {
            CV_Assert(!_aspectRatios.empty(), _minSize > 0);
            _numPriors = _aspectRatios.size() + 1;  // + 1 for an aspect ratio 1.0
        }

        _maxSize = -1;
        if (params.has("max_size"))
        {
            _maxSize = params.get("max_size").get<float>(0);
            CV_Assert(_maxSize > _minSize);

            _numPriors += 1;
        }

        if (params.has("step_h") || params.has("step_w")) {
          CV_Assert(!params.has("step"));
          _stepY = getParameter<float>(params, "step_h");
          CV_Assert(_stepY > 0.);
          _stepX = getParameter<float>(params, "step_w");
          CV_Assert(_stepX > 0.);
        } else if (params.has("step")) {
          const float step = getParameter<float>(params, "step");
          CV_Assert(step > 0);
          _stepY = step;
          _stepX = step;
        } else {
          _stepY = 0;
          _stepX = 0;
        }
        if (params.has("offset_h") || params.has("offset_w"))
        {
            CV_Assert(!params.has("offset"), params.has("offset_h"), params.has("offset_w"));
            getParams("offset_h", params, &_offsetsY);
            getParams("offset_w", params, &_offsetsX);
            CV_Assert(_offsetsX.size() == _offsetsY.size());
            _numPriors *= std::max((size_t)1, 2 * (_offsetsX.size() - 1));
        }
        else
        {
            float offset = getParameter<float>(params, "offset", 0, false, 0.5);
            _offsetsX.assign(1, offset);
            _offsetsY.assign(1, offset);
        }
    }
Ejemplo n.º 15
0
 SoftMaxLayerImpl(const LayerParams& params)
 {
     axisRaw = params.get<int>("axis", 1);
     logSoftMax = params.get<int>("log_softmax", false);
     setParamsFrom(params);
 }
Ejemplo n.º 16
0
 ScaleLayerImpl(const LayerParams& params)
 {
     setParamsFrom(params);
     hasBias = params.get<bool>("bias_term", false);
 }
Ejemplo n.º 17
0
 ShiftLayerImpl(const LayerParams &params)
 {
     setParamsFrom(params);
     CV_Assert(blobs.size() == 1);
 }
Ejemplo n.º 18
0
    PriorBoxLayerImpl(const LayerParams &params)
    {
        setParamsFrom(params);
        _minSize = getParameter<float>(params, "min_size", 0, false, 0);
        _flip = getParameter<bool>(params, "flip", 0, false, true);
        _clip = getParameter<bool>(params, "clip", 0, false, true);
        _bboxesNormalized = getParameter<bool>(params, "normalized_bbox", 0, false, true);

        _aspectRatios.clear();

        getAspectRatios(params);
        getVariance(params);

        _maxSize = -1;
        if (params.has("max_size"))
        {
            _maxSize = params.get("max_size").get<float>(0);
            CV_Assert(_maxSize > _minSize);
        }

        std::vector<float> widths, heights;
        getParams("width", params, &widths);
        getParams("height", params, &heights);
        _explicitSizes = !widths.empty();
        CV_Assert(widths.size() == heights.size());

        if (_explicitSizes)
        {
            CV_Assert(_aspectRatios.empty());
            CV_Assert(!params.has("min_size"));
            CV_Assert(!params.has("max_size"));
            _boxWidths = widths;
            _boxHeights = heights;
        }
        else
        {
            CV_Assert(_minSize > 0);
            _boxWidths.resize(1 + (_maxSize > 0 ? 1 : 0) + _aspectRatios.size());
            _boxHeights.resize(_boxWidths.size());
            _boxWidths[0] = _boxHeights[0] = _minSize;

            int i = 1;
            if (_maxSize > 0)
            {
                // second prior: aspect_ratio = 1, size = sqrt(min_size * max_size)
                _boxWidths[i] = _boxHeights[i] = sqrt(_minSize * _maxSize);
                i += 1;
            }

            // rest of priors
            for (size_t r = 0; r < _aspectRatios.size(); ++r)
            {
                float arSqrt = sqrt(_aspectRatios[r]);
                _boxWidths[i + r] = _minSize * arSqrt;
                _boxHeights[i + r] = _minSize / arSqrt;
            }
        }
        CV_Assert(_boxWidths.size() == _boxHeights.size());
        _numPriors = _boxWidths.size();

        if (params.has("step_h") || params.has("step_w")) {
          CV_Assert(!params.has("step"));
          _stepY = getParameter<float>(params, "step_h");
          CV_Assert(_stepY > 0.);
          _stepX = getParameter<float>(params, "step_w");
          CV_Assert(_stepX > 0.);
        } else if (params.has("step")) {
          const float step = getParameter<float>(params, "step");
          CV_Assert(step > 0);
          _stepY = step;
          _stepX = step;
        } else {
          _stepY = 0;
          _stepX = 0;
        }
        if (params.has("offset_h") || params.has("offset_w"))
        {
            CV_Assert(!params.has("offset"), params.has("offset_h"), params.has("offset_w"));
            getParams("offset_h", params, &_offsetsY);
            getParams("offset_w", params, &_offsetsX);
            CV_Assert(_offsetsX.size() == _offsetsY.size());
            _numPriors *= std::max((size_t)1, 2 * (_offsetsX.size() - 1));
        }
        else
        {
            float offset = getParameter<float>(params, "offset", 0, false, 0.5);
            _offsetsX.assign(1, offset);
            _offsetsY.assign(1, offset);
        }
    }