Directly on code:
#include <iostream> #include <vector> using namespace std;
int main () {///defines the matrix of the convolution (actually an array, the number of array elements 8*8) int const MAP = 8;
Float A[map*map] = {8, 7, 6, 5, 4, 3, 2, 1, 1, 2, 3, 4, 5, 6, 7, 8, 8, 7, 6, 5, 4, 3, 2, 1, 1-2, 3, 4, 5, 6, 7, 8, 1, 2, 3, 4, 5, 6, 7, 8, 1, 2, 3, 4, 5, 6, 7, 8, 8, 7,
2, 1, 1, 2, 3, 4, 5, 6, 7, 8,};
Defines the convolution kernel matrix (in fact, also an array, the number of array elements 3*3) int const KERNEL = 3; Compute the dimension of the convolution output matrix (actually the open root of the number of output array elements) int const OUTM = map-kernel + 1; The dimension of the convolution matrix-the dimension of the convolution kernel +1, that is, 8-3+1=6//The convolution matrix is the width and height of the convolution, which is the same as the height of the convolution kernel, so that it can be multiplied. int const CONVAW = kernel*kernel;//3*3 =9 int const Convah = map*map;//8*8=64 float A_CONVERT[CONVAH*CONVAW] = {0};//defines a matrix in a convolution process (that is, a matrix that is elongated) fo R (int i = 0; i < Outm i++) {for (int j = 0; J < Outm; J +) {int WH = i * OUTM *
CONVAW + J * CONVAW;
int col1 = i * map + j; A_CONVERT[WH] = A[col1]; The value of the a[0] is assigned to a_convert[0] A_CONVERT[WH + 1] = a[col1 + 1];//assigns the value of A[1 to a_convert[1 at the first cycle) A_
CONVERT[WH + 2] = a[col1 + 2];//The value of a[2 when first cycle is assigned to a_convert[2] int col2 = (i + 1) * map + J; A_CONVERT[WH + 3] = A[col2]; The value of the a[8] is assigned to A_CONVERT[3] A_CONVERT[WH + 4] = a[col2 + 1];//assigns the value of A[9 to a_convert[4 at the first cycle) A_
CONVERT[WH + 5] = a[col2 + 2];//The value of a[10 when first cycle is assigned to a_convert[5] int col3 = (i + 2) * map + J; A_CONVERT[WH + 6] = A[col3]; The value of a[16] is assigned to A_CONVERT[6] A_CONVERT[WH + 7] = a[col3 + 1] in the first cycle; The value of a[17] is assigned to A_CONVERT[7] A_CONVERT[WH + 8] = A[col3 + 2] in the first cycle;
The value of a[18] is assigned to A_CONVERT[8]} vector<int> C in the first cycle;
for (int i = 0; i < OUTM; i++) {int max;
for (int j = 0; J < Outm; J +) {int m = i * OUTM * CONVAW + j * CONVAW;int n;
max = A_convert[m];
for (n = 0; n < convaw n++) {if (a_convert[m + n] > max) {
max = A_convert[m + n];
} c.push_back (max);
}///output original input matrix cout << "original input matrix:" << Endl; for (int i = 0; i < map; i++) {for (int j = 0; J < map; j) {cout << A[i*ma
p+ j] << "";
} cout << Endl;
} cout << Endl;
Output pooling after matrix cout << "pooling after matrix:" << Endl; for (int i = 0; i < Outm. i++) {for (int j = 0; J <outm; J +) {cout << c[i*o
UTM + j] << "";
} cout << Endl;
} cout << Endl;
System ("pause");
return 0; }