我是靠谱客的博主 有魅力皮皮虾,这篇文章主要介绍手搓全连接层神经网络识别手写数字,现在分享给大家,希望可以做个参考。

需要对28x28的灰度数字图像进行数字识别。
输入层 28x28个输入节点,分别代表像素点上的灰度大小
输出层10个输出,分别代表0-1的概率

使用sigmoid函数

由于求导过于繁琐,因此这里仅添加了一层隐藏层。

代码如下

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#include<cstdio> #include<cstring> #include<cmath> #include<cstdlib> using namespace std; char file[]="train-images-idx3-ubyte"; char lc; #define gc() (lc=getchar()) //#define gc() (lc=(Cs>=Ms?(fread(buf,Ms,1,stdin),Cs=0,buf[Cs++]):buf[Cs++])) #define sigmoid(x) (1/(1+exp(x))) int read(int&x) { x=0; char c; do c=gc();while((c!=EOF)&&(c<'0'||c>'9')&&(c<'a'||c>'z')&&(c<'A'||c>'Z')); if (lc==EOF) { x=-1; return -1; } while(!((c<'0'||c>'9')&&(c<'a'||c>'z')&&(c<'A'||c>'Z'))) { x=x*10+c-'0'; c=gc(); } return 1; } int n_lay1=28*28; double w1[28*28][20]; double dw1[28*28][20]; double b1[20]; double db1[20]; double x1[28*28]; double sig1[28*28]; int n_lay2=20; double w2[20][10]; double dw2[20][10]; double b2[10]; double db2[10]; double mid[60001][20]; double dmid[20]; double out[60001][10]; double train[60001][28*28]; double label[60001][10]; int train_N; double get_loss(const int &train_n) { double loss=0; for(int i=0;i<train_n;i++) { for(int j=0;j<20;j++) mid[i][j]=b1[j]; for(int j=0;j<28*28;j++) for(int k=0;k<20;k++) { mid[i][k]=mid[i][k]+w1[j][k]*train[i][j]; //printf("%d %lf %lfn",train[i][j],w1[j][k], mid[i][k]); } //puts("mid"); for(int j=0;j<20;j++) mid[i][j]=sigmoid(mid[i][j]);//,printf("%lf, ",mid[i][j]); //puts(""); for(int j=0;j<10;j++) out[i][j]=b2[j]; for(int j=0;j<20;j++) for(int k=<

最后

以上就是有魅力皮皮虾最近收集整理的关于手搓全连接层神经网络识别手写数字的全部内容,更多相关手搓全连接层神经网络识别手写数字内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(64)

评论列表共有 0 条评论

立即
投稿
返回
顶部