MCPcopy Create free account
hub / github.com/ARM-software/ComputeLibrary / roi_align_1x1

Function roi_align_1x1

tests/validation/reference/ROIAlignLayer.cpp:44–108  ·  view source on GitHub ↗

Average pooling over an aligned window */

Source from the content-addressed store, hash-verified

42{
43/** Average pooling over an aligned window */
44inline float roi_align_1x1(const float *input,
45 TensorShape input_shape,
46 float region_start_x,
47 float bin_size_x,
48 int grid_size_x,
49 float region_end_x,
50 float region_start_y,
51 float bin_size_y,
52 int grid_size_y,
53 float region_end_y,
54 int pz)
55{
56 if ((region_end_x <= region_start_x) || (region_end_y <= region_start_y))
57 {
58 return 0;
59 }
60 else
61 {
62 float avg = 0;
63 // Iterate through the aligned pooling region
64 for (int iy = 0; iy < grid_size_y; ++iy)
65 {
66 for (int ix = 0; ix < grid_size_x; ++ix)
67 {
68 // Align the window in the middle of every bin
69 float y = region_start_y + (iy + 0.5) * bin_size_y / float(grid_size_y);
70 float x = region_start_x + (ix + 0.5) * bin_size_x / float(grid_size_x);
71
72 // Interpolation in the [0,0] [0,1] [1,0] [1,1] square
73 const int y_low = y;
74 const int x_low = x;
75 const int y_high = y_low + 1;
76 const int x_high = x_low + 1;
77
78 const float ly = y - y_low;
79 const float lx = x - x_low;
80 const float hy = 1. - ly;
81 const float hx = 1. - lx;
82
83 const float w1 = hy * hx;
84 const float w2 = hy * lx;
85 const float w3 = ly * hx;
86 const float w4 = ly * lx;
87
88 const size_t idx1 = coord2index(input_shape, Coordinates(x_low, y_low, pz));
89 float data1 = input[idx1];
90
91 const size_t idx2 = coord2index(input_shape, Coordinates(x_high, y_low, pz));
92 float data2 = input[idx2];
93
94 const size_t idx3 = coord2index(input_shape, Coordinates(x_low, y_high, pz));
95 float data3 = input[idx3];
96
97 const size_t idx4 = coord2index(input_shape, Coordinates(x_high, y_high, pz));
98 float data4 = input[idx4];
99
100 avg += w1 * data1 + w2 * data2 + w3 * data3 + w4 * data4;
101 }

Callers 1

roi_align_layerFunction · 0.70

Calls 2

coord2indexFunction · 0.85
CoordinatesClass · 0.50

Tested by

no test coverage detected