-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmnist.cpp
36 lines (34 loc) · 1.46 KB
/
mnist.cpp
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
#include <stdlib.h>
//#include <type_traits>
#include <memory>
#include "../../include/neural_network.h"
#include "../../include/metrics/missclassified.hpp"
#include "../../third_party/mnist/include/mnist/get_data.h"
typedef std::shared_ptr<Layer> s_Layer;
using std::make_shared;
int main(int argc, char** argv) {
//if ((argc != 2) and (argc != 5))
//throw std::invalid_argument("Must have one or four arguemnts");
Mnist data = Mnist();
srand((unsigned int)time(0));
Init* init = new Glorot();
s_Layer l1 = make_shared<Input>(Features(data.get_x_train().cols()));
s_Layer d1 = make_shared<Dense>(Features(1024), l1, init);
s_Layer r1 = make_shared<Relu>(d1);
s_Layer drop1 = make_shared<Dropout>(0.5, r1);
s_Layer d2 = make_shared<Dense>(Features(1024), drop1, init);
s_Layer r2 = make_shared<Relu>(d2);
s_Layer drop2 = make_shared<Dropout>(0.5, r2);
s_Layer d3 = make_shared<Dense>(Features(10), drop2, init);
s_Layer s1 = make_shared<Softmax>(d3);
std::shared_ptr<Loss> loss =
std::make_shared<CrossEntropy>(CrossEntropy("GPU"));
NeuralNetwork n1(s1, loss, "GPU");
std::shared_ptr<GradientDescent> sgd =
std::make_shared<Momentum>(LearningRate(0.001), MomentumRate(0.75));
std::vector<Metric*> metrics;
Metric* val = new Missclassified(&n1);
metrics.push_back(val);
n1.train(data.get_x_train(), data.get_y_train(), sgd, Epochs(10),
Patience(10), BatchSize(32), metrics);
}