PriorBoxLayerImpl(const LayerParams ¶ms) { 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; } }
PriorBoxLayerImpl(const LayerParams ¶ms) : _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); } }
PriorBoxLayerImpl(const LayerParams ¶ms) { 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); } }