41 const auto layer_width =
static_cast<int>(src1.
shape()[0]);
42 const auto layer_height =
static_cast<int>(src1.
shape()[1]);
44 int img_width =
info.img_size().x;
45 int img_height =
info.img_size().y;
46 if(img_width == 0 || img_height == 0)
48 img_width =
static_cast<int>(src2.
shape()[0]);
49 img_height =
static_cast<int>(src2.
shape()[1]);
52 float step_x =
info.steps()[0];
53 float step_y =
info.steps()[1];
54 if(step_x == 0.f || step_y == 0.f)
56 step_x =
static_cast<float>(img_width) / layer_width;
57 step_x =
static_cast<float>(img_height) / layer_height;
61 const int num_priors =
info.aspect_ratios().size() *
info.min_sizes().size() +
info.max_sizes().size();
62 const int total_elements = layer_width * layer_height * num_priors * 4;
67 for(
int y = 0; y < layer_height; ++y)
69 for(
int x = 0; x < layer_width; ++x)
71 const float center_x = (x +
info.offset()) * step_x;
72 const float center_y = (y +
info.offset()) * step_y;
75 for(
unsigned int i = 0; i <
info.min_sizes().size(); ++i)
77 const float min_size =
info.min_sizes().at(i);
79 box_height = min_size;
81 result[idx++] = (center_x - box_width / 2.f) / img_width;
82 result[idx++] = (center_y - box_height / 2.f) / img_height;
83 result[idx++] = (center_x + box_width / 2.f) / img_width;
84 result[idx++] = (center_y + box_height / 2.f) / img_height;
86 if(!
info.max_sizes().empty())
88 const float max_size =
info.max_sizes().at(i);
89 box_width = sqrt(min_size * max_size);
90 box_height = box_width;
93 result[idx++] = (center_x - box_width / 2.f) / img_width;
94 result[idx++] = (center_y - box_height / 2.f) / img_height;
95 result[idx++] = (center_x + box_width / 2.f) / img_width;
96 result[idx++] = (center_y + box_height / 2.f) / img_height;
100 for(
auto ar :
info.aspect_ratios())
102 if(fabs(ar - 1.) < 1e-6)
107 box_width = min_size * sqrt(ar);
108 box_height = min_size / sqrt(ar);
111 result[idx++] = (center_x - box_width / 2.f) / img_width;
112 result[idx++] = (center_y - box_height / 2.f) / img_height;
113 result[idx++] = (center_x + box_width / 2.f) / img_width;
114 result[idx++] = (center_y + box_height / 2.f) / img_height;
123 for(
int i = 0; i < total_elements; ++i)
125 result[i] = std::min<T>(std::max<T>(result[i], 0.f), 1.f);
130 if(
info.variances().size() == 1)
132 std::fill_n(result.
data() + idx, total_elements,
info.variances().at(0));
136 for(
int h = 0; h < layer_height; ++h)
138 for(
int w = 0;
w < layer_width; ++
w)
140 for(
int i = 0; i < num_priors; ++i)
142 for(
int j = 0; j < 4; ++j)
144 result[idx++] =
info.variances().at(j);