Last active
December 10, 2019 12:35
-
-
Save raytroop/d2414bbb537a8f8baceaaee4fa6717e8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// image convolution (3x3 conv) | |
int WIDTH = 1024; | |
int HEIGHT = 1024; | |
float input[(WIDTH + 2) * (HEIGHT + 2)]; | |
float output[WIDTH * HEIGHT]; | |
float weights[] = {1.0 / 9, 1.0 / 9, 1.0 / 9, | |
1.0 / 9, 1.0 / 9, 1.0 / 9, | |
1.0 / 9, 1.0 / 9, 1.0 / 9}; | |
for (int j = 0; j < HEIGHT; j++) | |
{ | |
for (int i = 0; i < WIDTH; i++) | |
{ | |
float tmp = 0.f; | |
for (int jj = 0; jj < 3; jj++) | |
for (int ii = 0; ii < 3; ii++) | |
tmp += input[(j + jj) * (WIDTH + 2) + (i + ii)] * weights[jj * 3 + ii]; | |
output[j * WIDTH + i] = tmp; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int WIDTH = 1024; | |
int HEIGHT = 1024; | |
int STRIDE = 2; | |
float input[(WIDTH + 2) * (HEIGHT + 2)]; | |
float output[(WIDTH / STRIDE) * (HEIGHT / STRIDE)]; | |
float weights[] = {1.0 / 9, 1.0 / 9, 1.0 / 9, | |
1.0 / 9, 1.0 / 9, 1.0 / 9, | |
1.0 / 9, 1.0 / 9, 1.0 / 9}; | |
for (int j = 0; j < HEIGHT; j += STRIDE) | |
{ | |
for (int i = 0; i < WIDTH; i += STRIDE) | |
{ | |
float tmp = 0.f; | |
for (int jj = 0; jj < 3; jj++) | |
for (int ii = 0; ii < 3; ii++) | |
tmp += input[(j + jj) * (WIDTH + 2) + (i + ii)] * weights[jj * 3 + ii]; | |
output[(j / STRIDE) * (WIDTH / STRIDE) + (i / STRIDE)] = tmp; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment