-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathlenet.h
77 lines (58 loc) · 2.07 KB
/
lenet.h
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
/*
@author : 范文捷
@data : 2016-04-20
@note : 根据Yann Lecun的论文《Gradient-based Learning Applied To Document Recognition》编写
@api :
批量训练
void TrainBatch(LeNet5 *lenet, image *inputs, const char(*resMat)[OUTPUT],uint8 *labels, int batchSize);
训练
void Train(LeNet5 *lenet, image input, const char(*resMat)[OUTPUT],uint8 label);
预测
uint8 Predict(LeNet5 *lenet, image input, const char(*resMat)[OUTPUT], uint8 count);
初始化
void Initial(LeNet5 *lenet);
*/
#pragma once
#define LENGTH_KERNEL 5
#define LENGTH_FEATURE0 32
#define LENGTH_FEATURE1 (LENGTH_FEATURE0 - LENGTH_KERNEL + 1)
#define LENGTH_FEATURE2 (LENGTH_FEATURE1 >> 1)
#define LENGTH_FEATURE3 (LENGTH_FEATURE2 - LENGTH_KERNEL + 1)
#define LENGTH_FEATURE4 (LENGTH_FEATURE3 >> 1)
#define LENGTH_FEATURE5 (LENGTH_FEATURE4 - LENGTH_KERNEL + 1)
#define INPUT 1
#define LAYER1 6
#define LAYER2 6
#define LAYER3 16
#define LAYER4 16
#define LAYER5 120
#define OUTPUT 10
#define ALPHA 0.5
#define PADDING 2
typedef unsigned char uint8;
typedef uint8 image[28][28];
typedef struct LeNet5
{
double weight0_1[INPUT][LAYER1][LENGTH_KERNEL][LENGTH_KERNEL];
double weight2_3[LAYER2][LAYER3][LENGTH_KERNEL][LENGTH_KERNEL];
double weight4_5[LAYER4][LAYER5][LENGTH_KERNEL][LENGTH_KERNEL];
double weight5_6[LAYER5 * LENGTH_FEATURE5 * LENGTH_FEATURE5][OUTPUT];
double bias0_1[LAYER1];
double bias2_3[LAYER3];
double bias4_5[LAYER5];
double bias5_6[OUTPUT];
}LeNet5;
typedef struct Feature
{
double input[INPUT][LENGTH_FEATURE0][LENGTH_FEATURE0];
double layer1[LAYER1][LENGTH_FEATURE1][LENGTH_FEATURE1];
double layer2[LAYER2][LENGTH_FEATURE2][LENGTH_FEATURE2];
double layer3[LAYER3][LENGTH_FEATURE3][LENGTH_FEATURE3];
double layer4[LAYER4][LENGTH_FEATURE4][LENGTH_FEATURE4];
double layer5[LAYER5][LENGTH_FEATURE5][LENGTH_FEATURE5];
double output[OUTPUT];
}Feature;
void TrainBatch(LeNet5 *lenet, image *inputs, uint8 *labels, int batchSize);
void Train(LeNet5 *lenet, image input, uint8 label);
uint8 Predict(LeNet5 *lenet, image input, uint8 count);
void Initial(LeNet5 *lenet);