-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTrain.cpp
More file actions
executable file
·99 lines (80 loc) · 2.06 KB
/
Copy pathTrain.cpp
File metadata and controls
executable file
·99 lines (80 loc) · 2.06 KB
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
//
// Created by root on 2021/2/7.
//
//opencv only used for displaying images
#include <opencv2/opencv.hpp>
#include <opencv2/core.hpp>
#include <opencv2/highgui.hpp>
#include "Net.h"
#include "ModelTrans.h"
#include "FileProcess.h"
using namespace cv;
int main() {
ModelTrans trans;
Net net;
net.Init();
char* fileDirect;
fileDirect = (char*)malloc(sizeof(char)*100);
char ImagePath[100];
char *name;
name = (char*)malloc(sizeof(char)*4);
char *saveImageName;
saveImageName = (char*)malloc(sizeof(char)*20);
printf("[BPNN] TRAIN STARTING...\n");
int train_c = 0;
double E = 0;
while (train_c < LOOP_N)
{
#ifdef TRAIN_HAN
FileReader fileReader("../Han");
#endif
#ifdef TRAIN_LETTER
FileReader fileReader("../Letters_Test");
#endif
E = 0;
while(fileReader.findNext(fileDirect)) {
#ifdef TRAIN_HAN
sprintf(ImagePath, "../Han/%s", fileDirect);
#endif
#ifdef TRAIN_LETTER
sprintf(ImagePath, "../Letters_Test/%s", fileDirect);
//printf("%s\n",fileDirect);
#endif
trans.Init(ImagePath);
memset(name, '\0', 4);
#ifdef TRAIN_HAN
memcpy(name, fileDirect, 3);
#endif
#ifdef TRAIN_LETTER
memcpy(name, fileDirect, 1);
#endif
net.InputSample(trans.channelImage[0], trans.getHeight(), trans.getWidth(), name);
net.Conv();
net.Pool();
net.Train();
#if SAVE_POOL==1
memset(saveImageName,'\0',20);
strcat(saveImageName,name);
strcat(saveImageName,"pool1.jpg");
imwrite(saveImageName,pool1Src);
memset(saveImageName,'\0',20);
strcat(saveImageName,name);
strcat(saveImageName,"pool2.jpg");
imwrite(saveImageName,pool2Src);
#endif
E += net.ek;
}
#ifdef TRAIN_HAN
E /= OUT_N_1;
#endif
#ifdef TRAIN_LETTER
E /= OUT_N_3;
#endif
train_c++;
printf("[BPNN] LOOP %d E %lf\n", train_c, E);
if (E < E_MIN)
break;
}
net.SaveParam();
return 0;
}