-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInputLayer.cpp
More file actions
107 lines (96 loc) · 3.02 KB
/
Copy pathInputLayer.cpp
File metadata and controls
107 lines (96 loc) · 3.02 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
100
101
102
103
104
105
106
107
#include "DeepLearning.h"
// vector<Array> trainData;
// vector<Array> testData;
// vector<int> shuffle;
// int numTrainData;
// int numTestData;
// int inpWidth;
// int inpHeight;
// Array output;
InputLayer::InputLayer(ifstream* fpTrain, ifstream* fpTest, int train, int test, int depth, int height, int width){
numTrainData = train;
numTestData = test;
outDepth = depth;
outHeight = height;
outWidth = width;
ran.resize(numTrainData);
for(int i = 0;i < batchSize;i++){
ThirdArray tmp(outDepth,outHeight,outWidth);
output.push_back(tmp);
}
for(int i = 0;i < train;i++){
GetPicture(fpTrain);
ThirdArray dat(depth,height,width);
for(int j = 0;j < depth;j++){
for(int k = 0;k < height;k++){
for(int l = 0;l < width;l++){
dat.thiArr[j].arr[k][l] = (double)pic[k][l] / 256.0;
}
}
}
trainData.push_back(dat);
}
if(!quiet){
printf("Training Data Successfully loaded...\n");
fprintf(fpResult, "Training Data Successfully loaded...\n");
fflush(fpResult);
}
for(int i = 0;i < test;i++){
GetPicture(fpTest);
ThirdArray dat(depth,height,width);
for(int j = 0;j < depth;j++){
for(int k = 0;k < height;k++){
for(int l = 0;l < width;l++){
dat.thiArr[j].arr[k][l] = (double)pic[k][l] / 256.0;
}
}
}
testData.push_back(dat);
}
if(trainData.size() != train){
printf("Error number of picture loaded.\n");
fprintf(fpResult, "Testing Data Successfully loaded...\n");
fflush(fpResult);
}
if(testData.size() != test){
printf("Error number of picture loaded.\n");
fprintf(fpResult, "Testing Data Successfully loaded...\n");
fflush(fpResult);
}
if(!quiet){
printf("Testing Data Successfully loaded...\n");
fprintf(fpResult, "Testing Data Successfully loaded...\n");
fflush(fpResult);
}
}
void InputLayer::InitShuffle(void){
for(int i = 0;i < numTrainData;i++){
ran[i] = i;
}
srand(time(NULL));
for(int i = 0;i < numTrainData;i++){
int pla = rand()%(numTrainData - i) + i;
int temp = ran[pla];
ran[pla] = ran[i];
ran[i] = temp;
}
}
void InputLayer::StartTest(int begin){
for(int i = 0;i < batchSize;i++){
if(begin + i > TestData){
fprintf(fpDebug,"Unable to load batch data for testing.\n");
exit(0);
}
output[i] = testData[begin + i];
}
}
void InputLayer::forward(int begin){
for(int i = 0;i < batchSize;i++){
if(begin + i > TrainData){
fprintf(fpDebug,"Unable to load batch data for training.\n");
exit(0);
}
int tar = ran[begin + i];
output[i] = trainData[tar];
}
}