Commit 8b4871a2 authored by Dmitry Kurtaev's avatar Dmitry Kurtaev Committed by Vadim Pisarevsky

Use only absolute prior boxes explicit sizes. Remove scales attributes. (#10874)

* Use only absolute prior boxes explicit sizes. Remove scales attributes.

* Simplified PriorBox layer forward pass
parent 88b689bc
This diff is collapsed.
......@@ -45,14 +45,12 @@
__kernel void prior_box(const int nthreads,
const Dtype stepX,
const Dtype stepY,
const Dtype _minSize,
const Dtype _maxSize,
__global const Dtype* _offsetsX,
__global const Dtype* _offsetsY,
const int offsetsX_size,
__global const Dtype* _aspectRatios,
const int aspectRatios_size,
__global const Dtype* scales,
__global const Dtype* _widths,
__global const Dtype* _heights,
const int widths_size,
__global Dtype* dst,
const int _layerHeight,
const int _layerWidth,
......@@ -64,57 +62,19 @@ __kernel void prior_box(const int nthreads,
int w = index % _layerWidth;
int h = index / _layerWidth;
__global Dtype* outputPtr;
int aspect_count = (_maxSize > 0) ? 1 : 0;
outputPtr = dst + index * 4 * offsetsX_size * (1 + aspect_count + aspectRatios_size);
outputPtr = dst + index * 4 * offsetsX_size * widths_size;
Dtype _boxWidth, _boxHeight;
Dtype4 vec;
_boxWidth = _boxHeight = _minSize * scales[0];
for (int i = 0; i < offsetsX_size; ++i)
{
float center_x = (w + _offsetsX[i]) * stepX;
float center_y = (h + _offsetsY[i]) * stepY;
vec.x = (center_x - _boxWidth * 0.5f) / imgWidth; // xmin
vec.y = (center_y - _boxHeight * 0.5f) / imgHeight; // ymin
vec.z = (center_x + _boxWidth * 0.5f) / imgWidth; // xmax
vec.w = (center_y + _boxHeight * 0.5f) / imgHeight; // ymax
vstore4(vec, 0, outputPtr);
outputPtr += 4;
}
if (_maxSize > 0)
{
_boxWidth = _boxHeight = native_sqrt(_minSize * _maxSize) * scales[1];
for (int i = 0; i < offsetsX_size; ++i)
{
float center_x = (w + _offsetsX[i]) * stepX;
float center_y = (h + _offsetsY[i]) * stepY;
vec.x = (center_x - _boxWidth * 0.5f) / imgWidth; // xmin
vec.y = (center_y - _boxHeight * 0.5f) / imgHeight; // ymin
vec.z = (center_x + _boxWidth * 0.5f) / imgWidth; // xmax
vec.w = (center_y + _boxHeight * 0.5f) / imgHeight; // ymax
vstore4(vec, 0, outputPtr);
outputPtr += 4;
}
}
for (int r = 0; r < aspectRatios_size; ++r)
for (int i = 0; i < widths_size; ++i)
{
float ar = native_sqrt(_aspectRatios[r]);
float scale = scales[(_maxSize > 0 ? 2 : 1) + r];
_boxWidth = _minSize * ar * scale;
_boxHeight = _minSize / ar * scale;
for (int i = 0; i < offsetsX_size; ++i)
_boxWidth = _widths[i];
_boxHeight = _heights[i];
for (int j = 0; j < offsetsX_size; ++j)
{
float center_x = (w + _offsetsX[i]) * stepX;
float center_y = (h + _offsetsY[i]) * stepY;
float center_x = (w + _offsetsX[j]) * stepX;
float center_y = (h + _offsetsY[j]) * stepY;
vec.x = (center_x - _boxWidth * 0.5f) / imgWidth; // xmin
vec.y = (center_y - _boxHeight * 0.5f) / imgHeight; // ymin
......
......@@ -26,6 +26,8 @@ parser.add_argument('--max_scale', default=0.95, type=float, help='Hyper-paramet
parser.add_argument('--num_layers', default=6, type=int, help='Hyper-parameter of ssd_anchor_generator from config file.')
parser.add_argument('--aspect_ratios', default=[1.0, 2.0, 0.5, 3.0, 0.333], type=float, nargs='+',
help='Hyper-parameter of ssd_anchor_generator from config file.')
parser.add_argument('--image_width', default=300, type=int, help='Training images width.')
parser.add_argument('--image_height', default=300, type=int, help='Training images height.')
args = parser.parse_args()
# Nodes that should be kept.
......@@ -192,7 +194,6 @@ for i in range(args.num_layers):
text_format.Merge('b: false', priorBox.attr["flip"])
text_format.Merge('b: false', priorBox.attr["clip"])
text_format.Merge('b: true', priorBox.attr["normalized_bbox"])
if i == 0:
widths = [args.min_scale * 0.5, args.min_scale * sqrt(2.0), args.min_scale * sqrt(0.5)]
......@@ -203,6 +204,8 @@ for i in range(args.num_layers):
widths += [sqrt(scales[i] * scales[i + 1])]
heights += [sqrt(scales[i] * scales[i + 1])]
widths = [w * args.image_width for w in widths]
heights = [h * args.image_height for h in heights]
text_format.Merge(tensorMsg(widths), priorBox.attr["width"])
text_format.Merge(tensorMsg(heights), priorBox.attr["height"])
text_format.Merge(tensorMsg([0.1, 0.1, 0.2, 0.2]), priorBox.attr["variance"])
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment