| 19 | #include <string.h> |
| 20 | |
| 21 | void LRN_AcrossChannel( const float* src, float *dst, const vector<int> dim, const int local_size, |
| 22 | const float alpha, const float beta) |
| 23 | { |
| 24 | int batch = 1;//dim[0]; |
| 25 | int channels = dim[1]; |
| 26 | int height = dim[2]; |
| 27 | int width = dim[3]; |
| 28 | int dst_cnt = 0; |
| 29 | int N = batch*channels*height*width; |
| 30 | |
| 31 | float a_by_n = alpha / (static_cast<float>(local_size)); |
| 32 | int half_size = local_size / 2; |
| 33 | int channel_size = height * width; |
| 34 | int batch_size = channels * channel_size; |
| 35 | |
| 36 | //vector<float> dst; dst.reserve(N); |
| 37 | |
| 38 | // Square the input |
| 39 | vector<float> sq; sq.reserve(N); |
| 40 | for(int i=0; i<N; ++i) |
| 41 | sq.push_back(src[i]*src[i]); |
| 42 | |
| 43 | // Do sliding window (1 + a/n * x.sum()) ^ b |
| 44 | for(int b=0; b<batch; ++b) { |
| 45 | for(int c=0; c<channels; ++c) { |
| 46 | for(int h=0; h<height; ++h) { |
| 47 | for(int w=0; w<width; ++w) { |
| 48 | // For each output pixel, iterate over the sliding window |
| 49 | int start_c = max(0, c-half_size); |
| 50 | int end_c = min(channels-1, c+half_size); |
| 51 | float sum = 0.0f; |
| 52 | for(int kc=start_c; kc<=end_c; ++kc) { |
| 53 | int ind = b*batch_size + kc*channel_size + h*width + w; |
| 54 | float val= sq[ind]; |
| 55 | sum += val; |
| 56 | } |
| 57 | float tmp = 1.0f + a_by_n * sum; |
| 58 | float tmp2= powf(tmp, beta); |
| 59 | float res = src[b*batch_size + c*channel_size + h*width + w] / tmp2; |
| 60 | //dst.push_back(res); |
| 61 | dst[dst_cnt++] = res; |
| 62 | } |
| 63 | } |
| 64 | } |
| 65 | } |
| 66 | |
| 67 | //return dst; |
| 68 | } |
| 69 | |
| 70 | |
| 71 | void Frcnn_LRN(const float *src, float *dst,const vector<int> dim, const int local_size=3, |
no test coverage detected