-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbinds.cpp
74 lines (73 loc) · 3.27 KB
/
binds.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
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
#include "conv_layer.hpp"
#include "cross_entropy.hpp"
#include "dense_layer.hpp"
#include "max_pool.hpp"
#include "mnist.hpp"
#include "relu.hpp"
#include "softmax.hpp"
#include <algorithm>
#include <eigen3/Eigen/Dense>
#include <fstream>
#include <iostream>
#include <math.h>
#include <pybind11/eigen.h>
#include <pybind11/pybind11.h>
#include <pybind11/stl.h>
#include <stdlib.h>
#include <vector>
using namespace std;
using Eigen::MatrixXd;
namespace py = pybind11;
PYBIND11_MODULE(my_project, m) {
py::class_<Conv_Layer>(m, "Conv_Layer")
.def(py::init<int, int, int, int, int, int>(), "Convolutional Layer",
py::arg("height"), py::arg("width"), py::arg("depth"),
py::arg("filter_size"), py::arg("stride"), py::arg("num_filters"))
.def("feed_forward", &Conv_Layer::feed_forward)
.def("back_propagation", &Conv_Layer::back_propagation)
.def("update_weights", &Conv_Layer::update_weights)
.def("save_filters", &Conv_Layer::save_filters)
.def("load_filters", &Conv_Layer::load_filters)
.def_readwrite("gradients", &Conv_Layer::gradients)
.def_readwrite("filters", &Conv_Layer::filters)
.def_readwrite("output", &Conv_Layer::output);
py::class_<Cross_Entropy>(m, "Cross_Entropy")
.def(py::init<int>(), "Cross Entropy Layer")
.def("feed_forward", &Cross_Entropy::feed_forward)
.def("back_propagation", &Cross_Entropy::back_propagation)
.def_readwrite("loss", &Cross_Entropy::loss)
.def_readwrite("gradients", &Cross_Entropy::gradients)
.def_readwrite("predicted", &Cross_Entropy::predicted)
.def_readwrite("actual", &Cross_Entropy::actual);
py::class_<Dense_Layer>(m, "Dense_Layer")
.def(py::init<int, int, int, int>(), "Dense Layer", py::arg("height"),
py::arg("width"), py::arg("depth"), py::arg("num_outputs"))
.def("feed_forward", &Dense_Layer::feed_forward)
.def("back_propagation", &Dense_Layer::back_propagation)
.def("update_weights", &Dense_Layer::update_weights)
.def("save_weights", &Dense_Layer::save_weights)
.def("load_weights", &Dense_Layer::load_weights)
.def_readwrite("gradients", &Dense_Layer::gradients)
.def_readwrite("output", &Dense_Layer::output);
py::class_<Max_Pool>(m, "Max_Pool")
.def(py::init<int, int, int, int, int>(), "Max Pool Layer",
py::arg("height"), py::arg("width"), py::arg("depth"),
py::arg("filter_size"), py::arg("stride"))
.def("feed_forward", &Max_Pool::feed_forward)
.def("back_propagation", &Max_Pool::back_propagation)
.def_readwrite("gradients", &Max_Pool::gradients)
.def_readwrite("output", &Max_Pool::output);
py::class_<ReLU>(m, "ReLU")
.def(py::init<int, int, int>(), "ReLU Layer", py::arg("height"),
py::arg("width"), py::arg("depth"))
.def("feed_forward", &ReLU::feed_forward)
.def("back_propagation", &ReLU::back_propagation)
.def_readwrite("gradients", &ReLU::gradients)
.def_readwrite("output", &ReLU::output);
py::class_<Softmax>(m, "Softmax")
.def(py::init<int>(), "Softmax Layer")
.def("feed_forward", &Softmax::feed_forward)
.def("back_propagation", &Softmax::back_propagation)
.def_readwrite("gradients", &Softmax::gradients)
.def_readwrite("output", &Softmax::output);
}