PriorBox layer with explicit normalized sizes
authorDmitry Kurtaev <dmitry.kurtaev+github@gmail.com>
Wed, 24 Jan 2018 11:01:42 +0000 (14:01 +0300)
committerDmitry Kurtaev <dmitry.kurtaev+github@gmail.com>
Wed, 24 Jan 2018 11:01:42 +0000 (14:01 +0300)
modules/dnn/src/layers/prior_box_layer.cpp
modules/dnn/src/tensorflow/tf_importer.cpp

index 53ce454..872a934 100644 (file)
@@ -416,6 +416,11 @@ public:
                 {
                     _boxWidth = _widths[0] * _scales[0];
                     _boxHeight = _heights[0] * _scales[0];
+                    if (_bboxesNormalized)
+                    {
+                        _boxWidth *= _imageWidth;
+                        _boxHeight *= _imageHeight;
+                    }
                 }
                 else
                     _boxWidth = _boxHeight = _minSize * _scales[0];
@@ -463,6 +468,11 @@ public:
                 {
                     _boxWidth = _widths[i] * _scales[i];
                     _boxHeight = _heights[i] * _scales[i];
+                    if (_bboxesNormalized)
+                    {
+                        _boxWidth *= _imageWidth;
+                        _boxHeight *= _imageHeight;
+                    }
                     for (int j = 0; j < _offsetsX.size(); ++j)
                     {
                         float center_x = (w + _offsetsX[j]) * stepX;
index 9a29f0a..7e03b59 100644 (file)
@@ -1411,23 +1411,17 @@ void TFImporter::populateNet(Net dstNet)
                 layerParams.set("clip", getLayerAttr(layer, "clip").b());
             if (hasLayerAttr(layer, "offset"))
                 layerParams.set("offset", getLayerAttr(layer, "offset").f());
-            if (hasLayerAttr(layer, "variance"))
-            {
-                Mat variance = getTensorContent(getLayerAttr(layer, "variance").tensor());
-                layerParams.set("variance",
-                                DictValue::arrayReal<float*>((float*)variance.data, variance.total()));
-            }
-            if (hasLayerAttr(layer, "aspect_ratio"))
-            {
-                Mat aspectRatios = getTensorContent(getLayerAttr(layer, "aspect_ratio").tensor());
-                layerParams.set("aspect_ratio",
-                               DictValue::arrayReal<float*>((float*)aspectRatios.data, aspectRatios.total()));
-            }
-            if (hasLayerAttr(layer, "scales"))
+
+            const std::string paramNames[] = {"variance", "aspect_ratio", "scales",
+                                              "width", "height"};
+            for (int i = 0; i < 5; ++i)
             {
-                Mat scales = getTensorContent(getLayerAttr(layer, "scales").tensor());
-                layerParams.set("scales",
-                               DictValue::arrayReal<float*>((float*)scales.data, scales.total()));
+                if (hasLayerAttr(layer, paramNames[i]))
+                {
+                    Mat values = getTensorContent(getLayerAttr(layer, paramNames[i]).tensor());
+                    layerParams.set(paramNames[i],
+                                    DictValue::arrayReal<float*>((float*)values.data, values.total()));
+                }
             }
             int id = dstNet.addLayer(name, "PriorBox", layerParams);
             layer_id[name] = id;