-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmodel.h
84 lines (64 loc) · 4.93 KB
/
model.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
78
79
80
81
82
83
84
#pragma once
#include <vector>
#include <string>
#include <fstream>
#include "layer.h"
enum model_type { classification, regression, general_adversarial, res_net };
enum activation_function { linear, sigmoid, rectified_linear, softmax};
class model {
public:
double learning_rate;
model();
model(int _model_type);
model(int _model_type, double _learning_rate);
model(int _model_type, double _learning_rate, double _decay_rate, double _sgd_mass);
void add_dense_layer(int _inputs, int _neurons, int _activation_function);
void add_convolutional_layer(int _input_size, int _input_channels, int _kernals, int _kernal_size, int _padding, int _stride, int _activation_function);
void add_pooling_layer(int _input_size, int _input_channels, int _kernal_size, int _padding, int _stride);
void forward(std::vector<std::vector<std::vector<std::vector<double>>>>& batched_inputs, int starting_layer, int ending_layer);
void forward(std::vector<std::vector<double>>& batched_inputs, int starting_layer, int ending_layer);
void forward(std::vector<std::vector<std::vector<std::vector<double>>>>& batched_inputs);
void forward(std::vector<std::vector<double>>& batched_inputs);
std::vector<std::vector<double>> dense_layer_output(int layer_index);
std::vector<std::vector<std::vector<std::vector<double>>>> convolutional_layer_output(int layer_index);
double loss(std::vector<std::vector<std::vector<std::vector<double>>>>& batched_targets);
double loss(std::vector<std::vector<double>>& batched_targets);
double loss(std::vector<int>& batched_targets);
void backward(std::vector<std::vector<std::vector<std::vector<double>>>>& batched_inputs, std::vector<std::vector<std::vector<std::vector<double>>>>& batched_targets, int starting_layer, int ending_layer);
void backward(std::vector<std::vector<std::vector<std::vector<double>>>>& batched_inputs, std::vector<std::vector<double>>& batched_targets, int starting_layer, int ending_layer);
void backward(std::vector<std::vector<std::vector<std::vector<double>>>>& batched_inputs, std::vector<int>& batched_targets, int starting_layer, int ending_layer);
void backward(std::vector<std::vector<double>>& batched_inputs, std::vector<std::vector<std::vector<std::vector<double>>>>& batched_targets, int starting_layer, int ending_layer);
void backward(std::vector<std::vector<double>>& batched_inputs, std::vector<std::vector<double>>& batched_targets, int starting_layer, int ending_layer);
void backward(std::vector<std::vector<double>>& batched_inputs, std::vector<int>& batched_targets, int starting_layer, int ending_layer);
void backward(std::vector<std::vector<std::vector<std::vector<double>>>>& batched_inputs, std::vector<std::vector<std::vector<std::vector<double>>>>& batched_targets);
void backward(std::vector<std::vector<std::vector<std::vector<double>>>>& batched_inputs, std::vector<std::vector<double>>& batched_targets);
void backward(std::vector<std::vector<std::vector<std::vector<double>>>>& batched_inputs, std::vector<int>& batched_targets);
void backward(std::vector<std::vector<double>>& batched_inputs, std::vector<std::vector<std::vector<std::vector<double>>>>& batched_targets);
void backward(std::vector<std::vector<double>>& batched_inputs, std::vector<std::vector<double>>& batched_targets);
void backward(std::vector<std::vector<double>>& batched_inputs, std::vector<int>& batched_targets);
void update_parameters();
void update_parameters(int starting_layer, int ending_layer);
void train(std::vector<std::vector<std::vector<std::vector<double>>>>& batched_inputs, std::vector<std::vector<std::vector<std::vector<double>>>>& batched_targets);
void train(std::vector<std::vector<std::vector<std::vector<double>>>>& batched_inputs, std::vector<std::vector<double>>& batched_targets);
void train(std::vector<std::vector<std::vector<std::vector<double>>>>& batched_inputs, std::vector<int>& batched_targets);
void train(std::vector<std::vector<double>>& batched_inputs, std::vector<std::vector<std::vector<std::vector<double>>>>& batched_targets);
void train(std::vector<std::vector<double>>& batched_inputs, std::vector<std::vector<double>>& batched_targets);
void train(std::vector<std::vector<double>>& batched_inputs, std::vector<int>& batched_targets);
void decay_learning_rate();
void save_model(const std::string& file_name);
void load_model(const std::string& file_name);
~model();
private:
int type;
int layer_count;
int step;
double starting_learning_rate;
double decay_rate;
double sgd_mass;
std::vector<int> activation_functions;
std::vector<layer*> layers;
void init_model(int _model_type, double _learning_rate, double _decay_rate, double _sgd_mass);
void write_dense_layer(std::ofstream& file, int layer_idx);
void write_convolutional_layer(std::ofstream& file, int layer_idx);
void write_pooling_layer(std::ofstream& file, int layer_idx);
};