26 #if defined(DATA_TYPE) && defined(WIDTH) && defined(HEIGHT) && defined(LAYER_WIDTH) && defined(LAYER_HEIGHT) && defined(OFFSET) && defined(STEP_X) && defined(STEP_Y) && defined(NUM_PRIORS) && defined(VARIANCE_0) && defined(VARIANCE_1) && defined(VARIANCE_2) && defined(VARIANCE_3)
43 inline void calculate_xy_min_max_nchw(
Image *out,
int idx,
float center_x,
float center_y,
float box_width,
float box_height)
45 float xmin = (center_x - box_width / 2.f) / WIDTH;
46 float ymin = (center_y - box_height / 2.f) / HEIGHT;
47 float xmax = (center_x + box_width / 2.f) / WIDTH;
48 float ymax = (center_y + box_height / 2.f) / HEIGHT;
51 xmin =
clamp(xmin, 0.f, 1.f);
52 ymin =
clamp(ymin, 0.f, 1.f);
53 xmax =
clamp(xmax, 0.f, 1.f);
54 ymax =
clamp(ymax, 0.f, 1.f);
55 #endif // defined(CLIP)
58 vstore4((
VEC_DATA_TYPE(DATA_TYPE, 4))(xmin, ymin, xmax, ymax), 0, ((__global DATA_TYPE *)
offset(out, idx + 0, 0)));
75 inline int calculate_min_nchw(
Image *out, __global
float *max, __global
float *aspect_ratios,
int max_size,
int aspect_ratios_size,
float min_size,
int min_idx,
int idx)
77 const float center_x = ((float)(get_global_id(0) % LAYER_WIDTH) + OFFSET) * STEP_X;
78 const float center_y = ((float)(get_global_id(0) / LAYER_WIDTH) + OFFSET) * STEP_Y;
80 float box_width = min_size;
81 float box_height = min_size;
82 calculate_xy_min_max_nchw(out, idx, center_x, center_y, box_width, box_height);
87 box_width = sqrt(min_size * max[min_idx]);
88 box_height = box_width;
89 calculate_xy_min_max_nchw(out, idx, center_x, center_y, box_width, box_height);
92 for(
unsigned int i = 0; i < aspect_ratios_size; ++i)
94 if(fabs(aspect_ratios[i] - 1.f) < 1e-6f)
98 box_width = min_size * sqrt(aspect_ratios[i]);
99 box_height = min_size * rsqrt(aspect_ratios[i]);
101 calculate_xy_min_max_nchw(out, idx, center_x, center_y, box_width, box_height);
122 __kernel
void prior_box_layer_nchw(
IMAGE_DECLARATION(output), __global
float *min, __global
float *max, __global
float *aspect_ratios,
unsigned int min_size,
unsigned int max_size,
123 unsigned int aspect_ratios_size)
128 for(
unsigned int i = 0; i < min_size; ++i)
130 idx = calculate_min_nchw(&out, max, aspect_ratios, max_size, aspect_ratios_size, min[i], i, idx);
134 for(
int i = 0; i < (NUM_PRIORS * 4); i += 4)
136 vstore4((
VEC_DATA_TYPE(DATA_TYPE, 4))(VARIANCE_0, VARIANCE_1, VARIANCE_2, VARIANCE_3), 0, ((__global DATA_TYPE *)
offset(&out, i, 1)));