-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
58 lines (50 loc) · 1.54 KB
/
main.cpp
File metadata and controls
58 lines (50 loc) · 1.54 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
#include <iostream>
#include <vector>
#include <random>
#include <opencv2/opencv.hpp>
#include "include/util.h"
#include "include/NeuralNet.h"
#include "include/matplotlibcpp.h"
using namespace cv;
namespace plt = matplotlibcpp;
void showImage() {
Mat img = imread("data/road.png");
if(img.empty())
{
std::cout << "Could not read the image: " << std::endl;
std::cin.get(); //wait for any key press
exit(1);
}
namedWindow("Display Image", WINDOW_AUTOSIZE);
imshow("Display Image", img);
waitKey(0);
destroyAllWindows();
}
int main(int argc, char const *argv[])
{
std::vector<std::vector<double>> xTrain, yTrain, xTest;
// std::vector<std::vector<double>> yTest;
std::vector<double> yTest;
std::cout << "Processing training data...\n";
util::process_csv("data/mnist_train.csv", xTrain, yTrain);
std::cout << "Processing test data...\n";
util::process_csv("data/mnist_test.csv", xTest, yTest);
// std::cout << "Creating network...\n";
NeuralNet nn(xTrain[0].size(), {64, 32}, 10);
double accuracy = nn.eval_accuracy(xTest, yTest);
printf("Accuracy before training: %.2f%%\n", accuracy * 100);
std::vector<double> loss, acc;
// showImage();
Tuple tup = nn.train(xTrain, yTrain, xTest, yTest, false);
std::tie(loss, acc) = tup;
std::cout << "Loss: " << Matrix(loss) << std::endl;
std::cout << "Accuracy: " << Matrix(acc) << std::endl;
// std::cout << "Gonna plot now...\n";
// plt::suptitle("Loss and accuracy");
// plt::subplot(2, 1, 1);
// plt::plot(loss);
// plt::subplot(2, 1, 2);
// plt::plot(acc);
// plt::show();
return 0;
}