用C语言实现卷积神经网络卷积层
小胖皮 2019-05-19 05:18:50 #include<stdio.h>
void main()
{
int a[100][100],x,y;
printf("please input w*w numbers:\n");
int w;
scanf("%d",&w);
for(x=0;x<w;x++)
for(y=0;y<w;y++)
{
printf("a[%d][%d]=",x,y);
scanf("%4d",&a[x][y]);
} printf("-------------------------------------------------------------------------\n");
printf("input:\n");
for(x=0;x<w;x++)
{
for(y=0;y<w;y++)
printf("%4d",a[x][y]);
printf("\n");
} printf("-------------------------------------------------------------------------\n");
int b[100][100],t,h;
printf("please input r*r numbers:\n");
int r;
scanf("%d",&r);
for(t=0;t<r;t++)
for(h=0;h<r;h++)
{
printf("b[%d][%d]=",t,h);
scanf("%4d",&b[t][h]);
} printf("-------------------------------------------------------------------------\n");
printf("filter:\n");
for(t=0;t<r;t++)
{
for(h=0;h<r;h++)
printf("%4d",b[t][h]);
printf("\n");
} printf("-------------------------------------------------------------------------\n");
int c[100][100],m,n,i,j,z=-1,s,d,f,g,cc,q=-1,v; printf("output:\n");
for(i=0;i<w-r+1;i++)
for(j=0;j<w-r+1;j++)
{
z=z+1;
cc=0;
v=z%(w-r+1);
if(z%(w-r+1)==0)
q=q+1;
for(f=0,s=f+v;f<r;s++,f++)
{
for(g=0,d=g+q;g<r;d++,g++)
cc=cc+a[s][d]*b[f][g];
}
c[i][j]=cc;
}
for(m=0;m<w-r+1;m++)
{
for(n=0;n<w-r+1;n++)
printf("%4d",c[m][n]);
printf("\n");
}
}